{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the GNU General Public License version 2. Note that NO WARRANTY is provided.\n * See \"LICENSE_GPLv2.txt\" for details.\n *\n * @TAG(NICTA_GPL)\n *)\n\ntheory Noninterference_Base_Refinement\nimports Noninterference_Base\n        Noninterference_Base_Alternatives\nbegin\n\n(* we assume the same initial state for both systems *)\nlocale noninterference_refinement = \n   abs?: complete_unwinding_system A s0 dom uwr policy out schedDomain +\n   conc?: noninterference_system C s0 dom uwr policy out schedDomain\n   for A :: \"('a,'s,'e) data_type\"\n   and s0 :: \"'s\"\n   and dom :: \"'e \\<Rightarrow> 's \\<Rightarrow> 'd\"      \n   and uwr :: \"'d \\<Rightarrow> ('s \\<times> 's) set\"\n   and policy :: \"('d \\<times> 'd) set\" \n   and out :: \"'d \\<Rightarrow> 's \\<Rightarrow> 'p\"     \n   and schedDomain :: \"'d\" \n   and C :: \"('c,'s,'e) data_type\" +\n   assumes refines: \"refines C A\"\n\ncontext noninterference_refinement begin\n\nlemma reachable:\n  \"conc.reachable s \\<Longrightarrow> abs.reachable s\"\n  apply(simp add: conc.reachable_def abs.reachable_def)\n  using refines by (fastforce simp: refines_def)\n  \n\nlemma Step:\n  \"conc.Step a \\<subseteq> abs.Step a\"\n  apply(simp add: conc.Step_def abs.Step_def)\n  using refines by(fastforce simp: refines_def)\n\nlemma confidentiality_u_refinement_closed:\n  \"abs.confidentiality_u \\<Longrightarrow> conc.confidentiality_u\"\n  apply(simp add: abs.confidentiality_u_def)  \n  apply(subst conc.confidentiality_u_def)\n  apply(blast intro: subsetD[OF Step] reachable)\n  done\n\nlemma confidentiality_u_weak_refinement_closed:\n  \"abs.confidentiality_u_weak \\<Longrightarrow> conc.confidentiality_u_weak\"\n  apply(simp add: abs.confidentiality_u_weak_def)  \n  apply(subst conc.confidentiality_u_weak_def)\n  apply(blast intro: subsetD[OF Step] reachable)\n  done\n\nlemma integrity_u_refinement_closed:\n  \"abs.integrity_u \\<Longrightarrow> conc.integrity_u\"\n  apply(simp add: abs.integrity_u_def)  \n  apply(subst conc.integrity_u_def)\n  apply(blast intro: subsetD[OF Step] reachable)\n  done\n\n\nlemma xources_subset:\n  \"abs.confidentiality_u \\<Longrightarrow> abs.xources as s u \\<subseteq> conc.xources as s u\"\n  apply(induct as arbitrary: s u)  \n   apply(simp add: abs.xources.xources_Nil conc.xources.xources_Nil)\n  apply(simp add: abs.xources.xources_Cons conc.xources.xources_Cons)\n  apply(rule conjI)\n   apply(rule subsetI)\n   apply(rule UnI1)\n   apply(blast dest: subsetD[OF Step])\n  apply(rule subsetI)\n  apply(rule UnI2)\n  apply(blast dest: subsetD[OF Step])\n  done\n\n\nlemma uwr_equiv:\n  \"abs.uwr_equiv s as t bs u \\<Longrightarrow> conc.uwr_equiv s as t bs u\"\n  apply(insert refines)\n  apply(fastforce simp: abs.uwr_equiv_def conc.uwr_equiv_def simp: refines_def dest: subsetD)\n  done\n\nlemma xNonleakage_gen_refinement_closed:\n  \"abs.xNonleakage_gen \\<Longrightarrow> conc.xNonleakage_gen\"\n  apply(frule abs.xNonleakage_gen_confidentiality_u)\n  apply(frule xources_subset)  \n  apply(clarsimp simp: abs.xNonleakage_gen_def conc.xNonleakage_gen_def)\n  apply(drule (1) sameFor_subset_dom[OF _ xources_subset])\n  apply(blast dest: reachable uwr_equiv)\n  done\n\nend\n\n\nlocale complete_noninterference_refinement = noninterference_refinement A s0 dom uwr policy out schedDomain C \n   for A :: \"('a,'s,'e) data_type\"\n   and s0 :: \"'s\"\n   and dom :: \"'e \\<Rightarrow> 's \\<Rightarrow> 'd\"      \n   and uwr :: \"'d \\<Rightarrow> ('s \\<times> 's) set\"\n   and policy :: \"('d \\<times> 'd) set\" \n   and out :: \"'d \\<Rightarrow> 's \\<Rightarrow> 'p\"     \n   and schedDomain :: \"'d\" \n   and C :: \"('c,'s,'e) data_type\" +\n   assumes Step_C: \"Step_system C s0\"\n\nsublocale complete_noninterference_refinement \\<subseteq> conc: complete_unwinding_system C s0 dom uwr policy out schedDomain\n  apply(unfold_locales)\n    using Step_C apply(fastforce simp: Step_system_def)\n   using Step_C apply(fastforce simp: Step_system_def)\n  apply(rule policy_refl)\n  done\n\ncontext complete_noninterference_refinement begin\nlemma Noninfluence_strong_uwr_refinement_closed:\n  \"abs.Noninfluence_strong_uwr \\<Longrightarrow>\n    conc.Noninfluence_strong_uwr\"\n  apply(frule abs.Noninfluence_strong_uwr_confidentiality_u_weak)\n  apply(drule abs.Noninfluence_strong_uwr_integrity_u)\n  apply(drule confidentiality_u_weak_refinement_closed)\n  apply(drule integrity_u_refinement_closed)\n  apply(blast intro: conc.Noninfluence_strong_uwr)\n  done\n\nlemma Nonleakage_gen_refinement_closed:\n  \"abs.Nonleakage_gen \\<Longrightarrow>\n    conc.Nonleakage_gen\"\n  apply(simp add: abs.Nonleakage_gen_equiv_confidentiality_u conc.Nonleakage_gen_equiv_confidentiality_u)\n  apply(erule confidentiality_u_refinement_closed)\n  done\n\nlemma Noninfluence_strong_quasi_refinement_closed:\n  \"\\<lbrakk>abs.confidentiality_u_weak; abs.integrity_u;\n        output_consistent\\<rbrakk> \\<Longrightarrow>\n    conc.Noninfluence_strong\"\n  apply(rule conc.Noninfluence_strong)\n    apply(erule confidentiality_u_weak_refinement_closed)\n   apply assumption\n  apply(erule integrity_u_refinement_closed)\n  done\n\nlemma Noninfluence_strong_uwr_quasi_refinement_closed:\n  \"\\<lbrakk>abs.Noninfluence_strong_uwr;\n        output_consistent\\<rbrakk> \\<Longrightarrow>\n    conc.Noninfluence_strong\"\n  apply(rule conc.Noninfluence_strong)\n    apply(rule confidentiality_u_weak_refinement_closed)\n    apply(erule abs.Noninfluence_strong_uwr_confidentiality_u_weak)\n   apply assumption\n  apply(rule integrity_u_refinement_closed)\n  apply(erule abs.Noninfluence_strong_uwr_integrity_u)\n  done\n  \nend\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/l4v/proof/infoflow/Noninterference_Base_Refinement.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.679178699175393, "lm_q2_score": 0.44167300566462553, "lm_q1q2_score": 0.29997489744818634}}
{"text": "section {* ICTAC 2016 tutorial. Taipei, 24/10/2016 *}\n\ntheory ictac16_tutorial\n  imports \"../theories/utp_designs\"\nbegin\n\nsubsection {* Laws of programming *}\n\ntheorem cond_shadow: \"(P \\<triangleleft> b \\<triangleright> (Q \\<triangleleft> b \\<triangleright> R)) = (P \\<triangleleft> b \\<triangleright> R)\" oops\n\ntheorem seqr_assoc: \"(P ;; (Q ;; R)) = ((P ;; Q) ;; R)\" oops\n\ntheorem seqr_left_unit: \"(II ;; P) = P\" oops\n\ntheorem seqr_left_zero: \"(false ;; P) = false\" oops\n\ntheorem cond_seq_left_distr:\n  assumes \"out\\<alpha> \\<sharp> b\"\n  shows \"((P \\<triangleleft> b \\<triangleright> Q) ;; R) = ((P ;; R) \\<triangleleft> b \\<triangleright> (Q ;; R))\"\n  using assms by (rel_simp, blast+)\n\ntheorem assign_twice:\n  assumes \"vwb_lens x\" \"x \\<sharp> f\"\n  shows \"(x := e ;; x := f) = (x := f)\"\n  using assms by rel_auto\n\ntheorem assign_commute:\n  assumes \"x \\<bowtie> y\" \"x \\<sharp> f\" \"y \\<sharp> e\"\n  shows \"(x := e ;; y := f) = (y := f ;; x := e)\"\n  using assms by (rel_auto, simp_all add: lens_indep_comm)\n\nsubsection {* Design laws *}\n\ntheorem design_false_pre: \"(false \\<turnstile> P) = true\" by rel_auto\n\ntheorem design_true_left_zero: \"(true ;; (P \\<turnstile> Q)) = true\"\nproof -\n  have \"(true ;; (P \\<turnstile> Q)) = (\\<^bold>\\<exists> ok\\<^sub>0 \\<bullet> true\\<lbrakk>\\<guillemotleft>ok\\<^sub>0\\<guillemotright>/$ok\\<acute>\\<rbrakk> ;; (P \\<turnstile> Q)\\<lbrakk>\\<guillemotleft>ok\\<^sub>0\\<guillemotright>/$ok\\<rbrakk>)\"\n    by (subst seqr_middle[of ok], simp_all)\n  also have \"... = ((true\\<lbrakk>false/$ok\\<acute>\\<rbrakk> ;; (P \\<turnstile> Q)\\<lbrakk>false/$ok\\<rbrakk>) \\<or> (true\\<lbrakk>true/$ok\\<acute>\\<rbrakk> ;; (P \\<turnstile> Q)\\<lbrakk>true/$ok\\<rbrakk>))\"\n    by (simp add: disj_comm false_alt_def true_alt_def)\n  also have \"... = ((true\\<lbrakk>false/$ok\\<acute>\\<rbrakk> ;; true\\<^sub>h) \\<or> (true ;; ((P \\<turnstile> Q)\\<lbrakk>true/$ok\\<rbrakk>)))\"\n    by (subst_tac, rel_auto)\n  also have \"... = true\"\n    by (subst_tac, simp add: precond_right_unit unrest)\n  finally show ?thesis .\nqed\n\ntheorem rdesign_left_unit:\n  fixes P Q :: \"'\\<alpha> hrel_des\"\n  shows \"II\\<^sub>D ;; (P \\<turnstile>\\<^sub>r Q) = (P \\<turnstile>\\<^sub>r Q)\"\nproof -\n  -- {* We first expand out the definition of the design identity *}\n  have \"II\\<^sub>D ;; (P \\<turnstile>\\<^sub>r Q) = (true \\<turnstile>\\<^sub>r II) ;; (P \\<turnstile>\\<^sub>r Q)\"\n    by (simp add: skip_d_def)\n  -- {* Next, we apply the design composition law above in a subproof *}\n  also have \"... = (true \\<and> \\<not> (II ;; (\\<not> P))) \\<turnstile>\\<^sub>r (II ;; Q)\"\n  proof -\n    -- {* The assumption of identity is $\\true$ so it is easy to discharge the proviso *}\n    have \"out\\<alpha> \\<sharp> true\"\n      by unrest_tac\n    -- {* From this we can apply the composition law *}\n    thus ?thesis\n      using rdesign_composition_cond by blast\n  qed\n  -- {* Simplification then allows us to remove extraneous terms *}\n  also have \"... = (\\<not> (\\<not> P)) \\<turnstile>\\<^sub>r Q\"\n    by simp\n  -- {* Finally, we can show the thesis *}\n  finally show ?thesis by simp\nqed\n\nsubsection {* Program example *}\n\nalphabet my_state =\n  x :: int\n  y :: int\n  z :: int\n\nlemma \"(x := 1 ;; x := (&x + 1)) = (x := 2)\"\n  oops\n\nlemma \"($x\\<acute> >\\<^sub>u $x \\<and> $y\\<acute> <\\<^sub>u $y) \\<sqsubseteq> x, y := &x + 1, &y\"\n  oops\n\nlemma \"(x := 1 ;; (y := 7 \\<triangleleft> $x >\\<^sub>u 0 \\<triangleright> y := 8)) = ((x,y) := (1,7))\"\n  oops\n\n(* Need following law:  *)\ntheorem ndesign_composition_wp: \"((p1 \\<turnstile>\\<^sub>n Q1) ;; (p2 \\<turnstile>\\<^sub>n Q2)) = ((p1 \\<and> Q1 wp p2) \\<turnstile>\\<^sub>n (Q1 ;; Q2))\"\n  oops\n\nlemma violate_precond:\n  \"(true \\<turnstile>\\<^sub>n x := 1) ;; ((&x >\\<^sub>u 1) \\<turnstile>\\<^sub>n y := 2) = \\<bottom>\\<^sub>D\"\n  apply (subst ndesign_composition_wp)\n  apply (simp)\n  apply (wp_tac)\n  apply (subst_tac)\n  apply (rel_auto)\ndone\nend", "meta": {"author": "isabelle-utp", "repo": "utp-main", "sha": "27bdf3aee6d4fc00c8fe4d53283d0101857e0d41", "save_path": "github-repos/isabelle/isabelle-utp-utp-main", "path": "github-repos/isabelle/isabelle-utp-utp-main/utp-main-27bdf3aee6d4fc00c8fe4d53283d0101857e0d41/tutorial/ictac16_tutorial.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5813031051514762, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.29973145808773144}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory WhileLoopRules\n  imports\n    Empty_Fail\n    NonDetMonad_Total\n    NonDetMonad_Sat\nbegin\n\nsection \"Well-ordered measures\"\n\n(* A version of \"measure\" that takes any wellorder, instead of being fixed to \"nat\". *)\ndefinition measure' :: \"('a \\<Rightarrow> 'b::wellorder) => ('a \\<times> 'a) set\" where\n  \"measure' = (\\<lambda>f. {(a, b). f a < f b})\"\n\nlemma in_measure'[simp, code_unfold]:\n  \"((x,y) \\<in> measure' f) = (f x < f y)\"\n  by (simp add:measure'_def)\n\nlemma wf_measure'[iff]:\n  \"wf (measure' f)\"\n  apply (clarsimp simp: measure'_def)\n  apply (insert wf_inv_image [OF wellorder_class.wf, where f=f])\n  apply (clarsimp simp: inv_image_def)\n  done\n\nlemma wf_wellorder_measure:\n  \"wf {(a, b). (M a :: 'a :: wellorder) < M b}\"\n  apply (subgoal_tac \"wf (inv_image ({(a, b). a < b}) M)\")\n   apply (clarsimp simp: inv_image_def)\n  apply (rule wf_inv_image)\n  apply (rule wellorder_class.wf)\n  done\n\n\nsection \"whileLoop lemmas\"\n\ntext \\<open>\n  The following @{const whileLoop} definitions with additional\n  invariant/variant annotations allow the user to annotate\n  @{const whileLoop} terms with information that can be used\n  by automated tools.\n\\<close>\ndefinition whileLoop_inv ::\n  \"('a \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow> ('a \\<Rightarrow> ('b, 'a) nondet_monad) \\<Rightarrow> 'a \\<Rightarrow> ('a \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow>\n   (('a \\<times> 'b) \\<times> 'a \\<times> 'b) set \\<Rightarrow> ('b, 'a) nondet_monad\" where\n  \"whileLoop_inv C B x I R \\<equiv> whileLoop C B x\"\n\ndefinition whileLoopE_inv ::\n  \"('a \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow> ('a \\<Rightarrow> ('b, 'c + 'a) nondet_monad) \\<Rightarrow> 'a \\<Rightarrow> ('a \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow>\n   (('a \\<times> 'b) \\<times> 'a \\<times> 'b) set \\<Rightarrow> ('b, 'c + 'a) nondet_monad\" where\n  \"whileLoopE_inv C B x I R \\<equiv> whileLoopE C B x\"\n\nlemma whileLoop_add_inv:\n  \"whileLoop B C = (\\<lambda>x. whileLoop_inv B C x I (measure' M))\"\n  by (clarsimp simp: whileLoop_inv_def)\n\nlemma whileLoopE_add_inv:\n  \"whileLoopE B C = (\\<lambda>x. whileLoopE_inv B C x I (measure' M))\"\n  by (clarsimp simp: whileLoopE_inv_def)\n\nsubsection \"Simple base rules\"\n\nlemma whileLoop_terminates_unfold:\n  \"\\<lbrakk> whileLoop_terminates C B r s; (r', s') \\<in> fst (B r s); C r s \\<rbrakk> \\<Longrightarrow>\n   whileLoop_terminates C B r' s'\"\n  by (force elim!: whileLoop_terminates.cases)\n\nlemma snd_whileLoop_first_step: \"\\<lbrakk> \\<not> snd (whileLoop C B r s); C r s \\<rbrakk> \\<Longrightarrow> \\<not> snd (B r s)\"\n  apply (subst (asm) whileLoop_unroll)\n  apply (clarsimp simp: bind_def condition_def)\n  done\n\nlemma snd_whileLoopE_first_step: \"\\<lbrakk> \\<not> snd (whileLoopE C B r s); C r s \\<rbrakk> \\<Longrightarrow> \\<not> snd (B r s)\"\n  apply (subgoal_tac \"\\<lbrakk> \\<not> snd (whileLoopE C B r s); C r s \\<rbrakk> \\<Longrightarrow> \\<not> snd ((lift B (Inr r)) s)\")\n   apply (clarsimp simp: lift_def)\n  apply (unfold whileLoopE_def)\n  apply (erule snd_whileLoop_first_step)\n  apply clarsimp\n  done\n\nlemma snd_whileLoop_unfold:\n  \"\\<lbrakk> \\<not> snd (whileLoop C B r s); C r s; (r', s') \\<in> fst (B r s) \\<rbrakk> \\<Longrightarrow> \\<not> snd (whileLoop C B r' s')\"\n  apply (clarsimp simp: whileLoop_def)\n  apply (auto elim: whileLoop_results.cases whileLoop_terminates.cases\n              intro: whileLoop_results.intros whileLoop_terminates.intros)\n  done\n\nlemma snd_whileLoopE_unfold:\n  \"\\<lbrakk> \\<not> snd (whileLoopE C B r s); (Inr r', s') \\<in> fst (B r s); C r s \\<rbrakk> \\<Longrightarrow> \\<not> snd (whileLoopE C B r' s')\"\n  unfolding whileLoopE_def\n  by (fastforce simp: lift_def dest: snd_whileLoop_unfold)\n\nlemma whileLoop_results_cong [cong]:\n  assumes C:  \"\\<And>r s. C r s = C' r s\"\n  and B:\"\\<And>(r :: 'r) (s :: 's). C' r s \\<Longrightarrow> B r s = B' r s\"\n  shows \"whileLoop_results C B = whileLoop_results C' B'\"\nproof -\n  {\n    fix x y C B C' B'\n    have  \"\\<lbrakk> (x, y) \\<in> whileLoop_results C B;\n             \\<And>(r :: 'r) (s :: 's). C r s = C' r s; \\<And>r s. C' r s \\<Longrightarrow> B r s = B' r s \\<rbrakk>\n           \\<Longrightarrow> (x, y) \\<in> whileLoop_results C' B'\"\n      by (induct rule: whileLoop_results.induct) (auto intro: whileLoop_results.intros)\n  }\n\n  thus ?thesis\n    apply -\n    apply (rule set_eqI, rule iffI; clarsimp split: prod.splits)\n     apply (clarsimp simp: C B)\n    apply (clarsimp simp: C [symmetric] B [symmetric])\n    done\nqed\n\nlemma whileLoop_terminates_cong [cong]:\n  assumes r: \"r = r'\"\n  and s: \"s = s'\"\n  and C: \"\\<And>r s. C r s = C' r s\"\n  and B: \"\\<And>r s. C' r s \\<Longrightarrow> B r s = B' r s\"\n  shows \"whileLoop_terminates C B r s = whileLoop_terminates C' B' r' s'\"\nproof (rule iffI)\n  assume T: \"whileLoop_terminates C B r s\"\n  show \"whileLoop_terminates C' B' r' s'\"\n    apply (insert T r s)\n    apply (induct arbitrary: r' s' rule: whileLoop_terminates.induct)\n     apply (clarsimp simp: C)\n     apply (erule whileLoop_terminates.intros)\n    apply (clarsimp simp: C B split: prod.splits)\n    apply (rule whileLoop_terminates.intros, assumption)\n    apply (clarsimp simp: C B split: prod.splits)\n    done\nnext\n  assume T: \"whileLoop_terminates C' B' r' s'\"\n  show \"whileLoop_terminates C B r s\"\n    apply (insert T r s)\n    apply (induct arbitrary: r s rule: whileLoop_terminates.induct)\n     apply (rule whileLoop_terminates.intros)\n     apply (clarsimp simp: C)\n    apply (rule whileLoop_terminates.intros, fastforce simp: C)\n    apply (clarsimp simp: C B split: prod.splits)\n    done\nqed\n\nlemma whileLoop_cong[cong]:\n  \"\\<lbrakk> \\<And>r s. C r s = C' r s; \\<And>r s. C r s \\<Longrightarrow> B r s = B' r s \\<rbrakk> \\<Longrightarrow> whileLoop C B = whileLoop C' B'\"\n  by (clarsimp simp: whileLoop_def)\n\nlemma whileLoopE_cong[cong]:\n  \"\\<lbrakk> \\<And>r s. C r s = C' r s ; \\<And>r s. C r s \\<Longrightarrow> B r s = B' r s \\<rbrakk> \\<Longrightarrow> whileLoopE C B = whileLoopE C' B'\"\n  unfolding whileLoopE_def\n  by (rule whileLoop_cong[THEN arg_cong]; clarsimp simp: lift_def throwError_def split: sum.splits)\n\nlemma whileLoop_terminates_wf:\n  \"wf {(x, y). C (fst y) (snd y) \\<and> x \\<in> fst (B (fst y) (snd y)) \\<and> whileLoop_terminates C B (fst y) (snd y)}\"\n  apply (rule wfI[where A=\"UNIV\" and B=\"{(r, s). whileLoop_terminates C B r s}\"]; clarsimp)\n  apply (erule whileLoop_terminates.induct; blast)\n  done\n\nsubsection \"Basic induction helper lemmas\"\n\nlemma whileLoop_results_induct_lemma1:\n  \"\\<lbrakk> (a, b) \\<in> whileLoop_results C B; b = Some (x, y) \\<rbrakk> \\<Longrightarrow> \\<not> C x y\"\n  by (induct rule: whileLoop_results.induct) auto\n\nlemma whileLoop_results_induct_lemma1':\n  \"\\<lbrakk> (a, b) \\<in> whileLoop_results C B; a \\<noteq> b \\<rbrakk> \\<Longrightarrow> \\<exists>x. a = Some x \\<and> C (fst x) (snd x)\"\n  by (induct rule: whileLoop_results.induct) auto\n\nlemma whileLoop_results_induct_lemma2 [consumes 1]:\n  \"\\<lbrakk> (a, b) \\<in> whileLoop_results C B;\n     a = Some (x :: 'a \\<times> 'b); b = Some y;\n     P x; \\<And>s t. \\<lbrakk> P s; t \\<in> fst (B (fst s) (snd s)); C (fst s) (snd s) \\<rbrakk> \\<Longrightarrow> P t \\<rbrakk> \\<Longrightarrow> P y\"\n  apply (induct arbitrary: x y rule: whileLoop_results.induct)\n    apply simp\n   apply simp\n  apply atomize\n  apply fastforce\n  done\n\nlemma whileLoop_results_induct_lemma3 [consumes 1]:\n  assumes result: \"(Some (r, s), Some (r', s')) \\<in> whileLoop_results C B\"\n  and inv_start: \"I r s\"\n  and inv_step: \"\\<And>r s r' s'. \\<lbrakk> I r s; C r s; (r', s') \\<in> fst (B r s) \\<rbrakk> \\<Longrightarrow> I r' s'\"\n  shows \"I r' s'\"\n  apply (rule whileLoop_results_induct_lemma2 [where P=\"case_prod I\" and y=\"(r', s')\" and x=\"(r, s)\",\n                                               simplified case_prod_unfold, simplified])\n      apply (rule result)\n     apply simp\n    apply simp\n   apply fact\n  apply (erule (1) inv_step)\n  apply clarsimp\n  done\n\nsubsection \"Inductive reasoning about whileLoop results\"\n\nlemma in_whileLoop_induct[consumes 1]:\n  assumes in_whileLoop: \"(r', s') \\<in> fst (whileLoop C B r s)\"\n  and init_I: \"\\<And> r s. \\<not> C r s \\<Longrightarrow> I r s r s\"\n  and step: \"\\<And>r s r' s' r'' s''. \\<lbrakk> C r s; (r', s') \\<in> fst (B r s);\n                                   (r'', s'') \\<in> fst (whileLoop C B r' s');\n                                   I r' s' r'' s'' \\<rbrakk> \\<Longrightarrow> I r s r'' s''\"\n  shows \"I r s r' s'\"\nproof cases\n  assume \"C r s\"\n\n  {\n    obtain a where a_def: \"a = Some (r, s)\"\n      by blast\n    obtain b where b_def: \"b = Some (r', s')\"\n      by blast\n\n    have \"\\<lbrakk> (a, b) \\<in> whileLoop_results C B; \\<exists>x. a = Some x;  \\<exists>x. b = Some x \\<rbrakk>\n          \\<Longrightarrow> I (fst (the a)) (snd (the a)) (fst (the b)) (snd (the b))\"\n      by (induct rule: whileLoop_results.induct)\n         (auto simp: init_I whileLoop_def intro: step)\n\n    hence \"(Some (r, s), Some (r', s')) \\<in> whileLoop_results C B \\<Longrightarrow> I r s r' s'\"\n      by (clarsimp simp: a_def b_def)\n   }\n\n   thus ?thesis\n     using in_whileLoop\n     by (clarsimp simp: whileLoop_def)\nnext\n  assume \"\\<not> C r s\"\n\n  hence \"r' = r \\<and> s' = s\"\n    using in_whileLoop\n    by (subst (asm) whileLoop_unroll, clarsimp simp: condition_def return_def)\n\n  thus ?thesis\n    by (metis init_I \\<open>\\<not> C r s\\<close>)\nqed\n\nlemma snd_whileLoop_induct [consumes 1]:\n  assumes induct: \"snd (whileLoop C B r s)\"\n  and terminates: \"\\<not> whileLoop_terminates C B r s \\<Longrightarrow> I r s\"\n  and init: \"\\<And> r s. \\<lbrakk> snd (B r s); C r s \\<rbrakk> \\<Longrightarrow> I r s\"\n  and step: \"\\<And>r s r' s' r'' s''. \\<lbrakk> C r s; (r', s') \\<in> fst (B r s); snd (whileLoop C B r' s');\n                                   I r' s' \\<rbrakk> \\<Longrightarrow> I r s\"\n  shows \"I r s\"\n  apply (insert init induct)\n  apply atomize\n  apply (unfold whileLoop_def)\n  apply clarsimp\n  apply (erule disjE)\n   apply (erule rev_mp)\n   apply (induct \"Some (r, s)\" \"None :: ('a \\<times> 'b) option\" arbitrary: r s rule: whileLoop_results.induct)\n    apply clarsimp\n   apply clarsimp\n   apply (erule (1) step)\n    apply (clarsimp simp: whileLoop_def)\n   apply clarsimp\n  apply (metis terminates)\n  done\n\nlemma whileLoop_terminatesE_induct [consumes 1]:\n  assumes induct: \"whileLoop_terminatesE C B r s\"\n  and init: \"\\<And>r s. \\<not> C r s \\<Longrightarrow> I r s\"\n  and step: \"\\<And>r s r' s'. \\<lbrakk> C r s; \\<forall>(v', s') \\<in> fst (B r s). case v' of Inl _ \\<Rightarrow> True | Inr r' \\<Rightarrow> I r' s' \\<rbrakk> \\<Longrightarrow> I r s\"\n  shows \"I r s\"\n  apply (insert induct)\n  apply (clarsimp simp: whileLoop_terminatesE_def)\n  apply (subgoal_tac \"(\\<lambda>r s. case (Inr r) of Inl x \\<Rightarrow> True | Inr x \\<Rightarrow> I x s) r s\")\n   apply simp\n  apply (induction rule: whileLoop_terminates.induct)\n   apply (clarsimp split: sum.splits elim!: init)\n  apply (clarsimp split: sum.splits)\n  apply (rule step)\n   apply simp\n  apply (force simp: lift_def split: sum.splits)\n  done\n\nsubsection \"Direct reasoning about whileLoop components\"\n\nlemma fst_whileLoop_cond_false:\n  assumes loop_result: \"(r', s') \\<in> fst (whileLoop C B r s)\"\n  shows \"\\<not> C r' s'\"\n  using loop_result\n  by (rule in_whileLoop_induct, auto)\n\nlemma snd_whileLoop:\n  assumes init_I: \"I r s\"\n      and cond_I: \"C r s\"\n      and non_term:  \"\\<And>r. \\<lbrace> \\<lambda>s. I r s \\<and> C r s \\<and> \\<not> snd (B r s) \\<rbrace> B r \\<exists>\\<lbrace> \\<lambda>r' s'. C r' s' \\<and> I r' s' \\<rbrace>\"\n  shows \"snd (whileLoop C B r s)\"\n  apply (clarsimp simp: whileLoop_def)\n  apply (rotate_tac)\n  apply (insert init_I cond_I)\n  apply (induct rule: whileLoop_terminates.induct)\n   apply clarsimp\n  apply (cut_tac r=r in non_term)\n  apply (clarsimp simp: exs_valid_def)\n   apply (subst (asm) (2) whileLoop_results.simps)\n   apply clarsimp\n  apply (insert whileLoop_results.simps)\n  apply fast\n  done\n\nlemma whileLoop_terminates_inv:\n  assumes init_I: \"I r s\"\n  assumes inv: \"\\<And>r s. \\<lbrace>\\<lambda>s'. I r s' \\<and> C r s' \\<and> s' = s \\<rbrace> B r \\<lbrace> \\<lambda>r' s'. I r' s' \\<and> ((r', s'), (r, s)) \\<in> R \\<rbrace>\"\n  assumes wf_R: \"wf R\"\n  shows \"whileLoop_terminates C B r s\"\n  apply (insert init_I)\n  using wf_R\n  apply (induction \"(r, s)\" arbitrary: r s)\n  apply atomize\n  apply (subst whileLoop_terminates_simps)\n  apply clarsimp\n  apply (erule use_valid)\n  apply (rule hoare_strengthen_post, rule inv)\n   apply force\n  apply force\n  done\n\nlemma not_snd_whileLoop:\n  assumes init_I: \"I r s\"\n      and inv_holds: \"\\<And>r s. \\<lbrace>\\<lambda>s'. I r s' \\<and> C r s' \\<and> s' = s \\<rbrace> B r \\<lbrace> \\<lambda>r' s'. I r' s' \\<and> ((r', s'), (r, s)) \\<in> R \\<rbrace>!\"\n      and wf_R: \"wf R\"\n  shows \"\\<not> snd (whileLoop C B r s)\"\nproof -\n  {\n    fix x y\n    have \"\\<lbrakk> (x, y) \\<in> whileLoop_results C B; x = Some (r, s); y = None \\<rbrakk> \\<Longrightarrow> False\"\n      apply (insert init_I)\n      apply (induct arbitrary: r s rule: whileLoop_results.inducts)\n        apply simp\n       apply simp\n       apply (insert snd_validNF [OF inv_holds])[1]\n       apply blast\n      apply (drule use_validNF [OF _ inv_holds])\n       apply simp\n      apply clarsimp\n      done\n  }\n\n  also have \"whileLoop_terminates C B r s\"\n    apply (rule whileLoop_terminates_inv [where I=I, OF init_I _ wf_R])\n    apply (insert inv_holds)\n    apply (clarsimp simp: validNF_def)\n    done\n\n  ultimately show ?thesis\n    by (clarsimp simp: whileLoop_def, blast)\nqed\n\nlemma valid_whileLoop:\n  assumes first_step: \"\\<And>s. P r s \\<Longrightarrow> I r s\"\n      and inv_step: \"\\<And>r. \\<lbrace> \\<lambda>s. I r s \\<and> C r s \\<rbrace> B r \\<lbrace> I \\<rbrace>\"\n      and final_step: \"\\<And>r s. \\<lbrakk> I r s; \\<not> C r s \\<rbrakk> \\<Longrightarrow> Q r s\"\n  shows \"\\<lbrace> P r \\<rbrace> whileLoop C B r \\<lbrace> Q \\<rbrace>\"\nproof -\n  {\n    fix r' s' s\n    assume inv: \"I r s\"\n    assume step: \"(r', s') \\<in> fst (whileLoop C B r s)\"\n\n    have \"I r' s'\"\n      using step inv\n      apply (induct rule: in_whileLoop_induct)\n       apply simp\n      apply (drule use_valid, rule inv_step, auto)\n      done\n  }\n\n  thus ?thesis\n    apply (clarsimp simp: valid_def)\n    apply (drule first_step)\n    apply (rule final_step, simp)\n    apply (metis fst_whileLoop_cond_false)\n    done\nqed\n\nlemma whileLoop_wp:\n  \"\\<lbrakk> \\<And>r. \\<lbrace> \\<lambda>s. I r s \\<and> C r s \\<rbrace> B r \\<lbrace> I \\<rbrace>;\n     \\<And>r s. \\<lbrakk> I r s; \\<not> C r s \\<rbrakk> \\<Longrightarrow> Q r s \\<rbrakk> \\<Longrightarrow>\n  \\<lbrace> I r \\<rbrace> whileLoop C B r \\<lbrace> Q \\<rbrace>\"\n  by (rule valid_whileLoop)\n\nlemma whileLoop_wp_inv [wp]:\n  \"\\<lbrakk> \\<And>r. \\<lbrace>\\<lambda>s. I r s \\<and> C r s\\<rbrace> B r \\<lbrace>I\\<rbrace>; \\<And>r s. \\<lbrakk>I r s; \\<not> C r s\\<rbrakk> \\<Longrightarrow> Q r s \\<rbrakk>\n   \\<Longrightarrow> \\<lbrace> I r \\<rbrace> whileLoop_inv C B r I M \\<lbrace> Q \\<rbrace>\"\n  apply (clarsimp simp: whileLoop_inv_def)\n  apply (rule valid_whileLoop [where P=I and I=I], auto)\n  done\n\nlemma validE_whileLoopE:\n  \"\\<lbrakk>\\<And>s. P r s \\<Longrightarrow> I r s;\n    \\<And>r. \\<lbrace> \\<lambda>s. I r s \\<and> C r s \\<rbrace> B r \\<lbrace> I \\<rbrace>,\\<lbrace> A \\<rbrace>;\n    \\<And>r s. \\<lbrakk> I r s; \\<not> C r s \\<rbrakk> \\<Longrightarrow> Q r s\\<rbrakk> \\<Longrightarrow>\n   \\<lbrace> P r \\<rbrace> whileLoopE C B r \\<lbrace> Q \\<rbrace>,\\<lbrace> A \\<rbrace>\"\n  apply (clarsimp simp: whileLoopE_def validE_def)\n  apply (rule valid_whileLoop [where I=\"\\<lambda>r s. (case r of Inl x \\<Rightarrow> A x s | Inr x \\<Rightarrow> I x s)\"\n                                 and Q=\"\\<lambda>r s. (case r of Inl x \\<Rightarrow> A x s | Inr x \\<Rightarrow> Q x s)\"])\n    apply atomize\n    apply (clarsimp simp: valid_def lift_def split: sum.splits)\n   apply (clarsimp simp: valid_def lift_def split: sum.splits)\n  apply (clarsimp split: sum.splits)\n  done\n\nlemma whileLoopE_wp:\n  \"\\<lbrakk> \\<And>r. \\<lbrace> \\<lambda>s. I r s \\<and> C r s \\<rbrace> B r \\<lbrace> I \\<rbrace>, \\<lbrace> A \\<rbrace>;\n     \\<And>r s. \\<lbrakk> I r s; \\<not> C r s \\<rbrakk> \\<Longrightarrow> Q r s \\<rbrakk> \\<Longrightarrow>\n  \\<lbrace> I r \\<rbrace> whileLoopE C B r \\<lbrace> Q \\<rbrace>, \\<lbrace> A \\<rbrace>\"\n  by (rule validE_whileLoopE)\n\nlemma exs_valid_whileLoop:\n assumes init_T: \"\\<And>s. P s \\<Longrightarrow> T r s\"\n    and iter_I: \"\\<And>r s0. \\<lbrace>\\<lambda>s. T r s \\<and> C r s \\<and> s = s0\\<rbrace> B r \\<exists>\\<lbrace>\\<lambda>r' s'. T r' s' \\<and> ((r', s'),(r, s0)) \\<in> R\\<rbrace>\"\n    and wf_R: \"wf R\"\n    and final_I: \"\\<And>r s. \\<lbrakk> T r s; \\<not> C r s  \\<rbrakk> \\<Longrightarrow> Q r s\"\n shows \"\\<lbrace> P \\<rbrace> whileLoop C B r \\<exists>\\<lbrace> Q \\<rbrace>\"\nproof (clarsimp simp: exs_valid_def Bex_def)\n  fix s\n  assume \"P s\"\n\n  {\n    fix x\n    have \"T (fst x) (snd x) \\<Longrightarrow> \\<exists>r' s'. (r', s') \\<in> fst (whileLoop C B (fst x) (snd x)) \\<and> T r' s'\"\n      using wf_R\n      apply induction\n      apply atomize\n      apply (case_tac \"C (fst x) (snd x)\")\n       apply (subst whileLoop_unroll)\n       apply (clarsimp simp: condition_def bind_def' split: prod.splits)\n       apply (cut_tac ?s0.0=b and r=a in iter_I)\n       apply (clarsimp simp: exs_valid_def)\n       apply blast\n      apply (subst whileLoop_unroll)\n      apply (clarsimp simp: condition_def bind_def' return_def)\n      done\n  }\n\n  thus \"\\<exists>r' s'. (r', s') \\<in> fst (whileLoop C B r s) \\<and> Q r' s'\"\n    by (metis \\<open>P s\\<close> fst_conv init_T snd_conv final_I fst_whileLoop_cond_false)\nqed\n\nlemma empty_fail_whileLoop[empty_fail_cond, intro!, wp]:\n  assumes body_empty_fail: \"\\<And>r. empty_fail (B r)\"\n  shows \"empty_fail (whileLoop C B r)\"\nproof -\n  {\n    fix s A\n    assume empty: \"fst (whileLoop C B r s) = {}\"\n\n    have cond_true: \"\\<And>x s. fst (whileLoop C B x s) = {} \\<Longrightarrow> C x s\"\n      apply (subst (asm) whileLoop_unroll)\n      apply (clarsimp simp: condition_def return_def split: if_split_asm)\n      done\n\n    have  \"snd (whileLoop C B r s)\"\n      apply (rule snd_whileLoop [where I=\"\\<lambda>x s. fst (whileLoop C B x s) = {}\"])\n        apply fact\n       apply (rule cond_true, fact)\n      apply (clarsimp simp: exs_valid_def)\n      apply (case_tac \"fst (B r s) = {}\")\n       apply (metis empty_failD [OF body_empty_fail])\n      apply (subst (asm) whileLoop_unroll)\n      apply (fastforce simp: condition_def bind_def split_def cond_true)\n      done\n   }\n\n  thus ?thesis\n    by (clarsimp simp: empty_fail_def)\nqed\n\nlemma empty_fail_whileLoopE[empty_fail_cond, intro!, wp]:\n  assumes \"\\<And>r. empty_fail (B r)\"\n  shows \"empty_fail (whileLoopE C B r)\"\n  by (clarsimp simp: whileLoopE_def assms)\n\nlemma empty_fail_whileM[empty_fail_cond, intro!, wp]:\n  \"\\<lbrakk> empty_fail C; empty_fail B \\<rbrakk> \\<Longrightarrow> empty_fail (whileM C B)\"\n  unfolding whileM_def\n  by (wpsimp wp: empty_fail_whileLoop empty_fail_bind)\n\nlemma whileLoop_results_bisim:\n  assumes base: \"(a, b) \\<in> whileLoop_results C B\"\n  and vars1: \"Q = (case a of Some (r, s) \\<Rightarrow> Some (rt r, st s) | _ \\<Rightarrow> None)\"\n  and vars2: \"R = (case b of Some (r, s) \\<Rightarrow> Some (rt r, st s) | _ \\<Rightarrow> None)\"\n  and inv_init: \"case a of Some (r, s) \\<Rightarrow> I r s | _ \\<Rightarrow> True\"\n  and inv_step: \"\\<And>r s r' s'. \\<lbrakk> I r s; C r s; (r', s') \\<in> fst (B r s) \\<rbrakk> \\<Longrightarrow> I r' s'\"\n  and cond_match: \"\\<And>r s. I r s \\<Longrightarrow> C r s = C' (rt r) (st s)\"\n  and fail_step: \"\\<And>r s. \\<lbrakk>C r s; snd (B r s); I r s\\<rbrakk>\n                         \\<Longrightarrow> (Some (rt r, st s), None) \\<in> whileLoop_results C' B'\"\n  and refine: \"\\<And>r s r' s'. \\<lbrakk> I r s; C r s; (r', s') \\<in>  fst (B r s) \\<rbrakk>\n                            \\<Longrightarrow> (rt r', st s') \\<in> fst (B' (rt r) (st s))\"\n  shows \"(Q, R) \\<in> whileLoop_results C' B'\"\n  apply (subst vars1)\n  apply (subst vars2)\n  apply (insert base inv_init)\n  apply (induct rule: whileLoop_results.induct)\n    apply clarsimp\n    apply (subst (asm) cond_match)\n     apply (clarsimp simp: option.splits)\n    apply (clarsimp simp: option.splits)\n   apply (clarsimp simp: option.splits)\n   apply (metis fail_step)\n  apply (case_tac z)\n   apply (clarsimp simp: option.splits)\n   apply (metis cond_match inv_step refine whileLoop_results.intros(3))\n  apply (clarsimp simp: option.splits)\n  apply (metis cond_match inv_step refine whileLoop_results.intros(3))\n  done\n\nlemma whileLoop_terminates_liftE:\n  \"whileLoop_terminatesE C (\\<lambda>r. liftE (B r)) r s = whileLoop_terminates C B r s\"\n  apply (subst eq_sym_conv)\n  apply (clarsimp simp: whileLoop_terminatesE_def)\n  apply (rule iffI)\n   apply (erule whileLoop_terminates.induct)\n    apply (rule whileLoop_terminates.intros)\n    apply clarsimp\n   apply (clarsimp simp: split_def)\n   apply (rule whileLoop_terminates.intros(2))\n    apply clarsimp\n   apply (clarsimp simp: liftE_def in_bind return_def lift_def[abs_def]\n                          bind_def lift_def throwError_def o_def\n                   split: sum.splits\n                   cong: sum.case_cong)\n   apply (drule (1) bspec)\n   apply clarsimp\n  apply (subgoal_tac\n         \"case Inr r of\n            Inl _ \\<Rightarrow> True\n          | Inr r \\<Rightarrow> whileLoop_terminates\n                       (\\<lambda>r s. (\\<lambda>r s. case r of Inl _ \\<Rightarrow> False | Inr v \\<Rightarrow> C v s) (Inr r) s)\n                       (\\<lambda>r. lift (\\<lambda>r. liftE (B r)) (Inr r) >>= (\\<lambda>x. return (projr x))) r s\")\n   apply (clarsimp simp: liftE_def lift_def)\n  apply (erule whileLoop_terminates.induct)\n   apply (clarsimp simp: liftE_def lift_def split: sum.splits)\n   apply (erule whileLoop_terminates.intros)\n  apply (clarsimp simp: liftE_def split: sum.splits)\n  apply (clarsimp simp: bind_def return_def split_def lift_def)\n  apply (erule whileLoop_terminates.intros)\n  apply force\n  done\n\nlemma snd_X_return[simp]:\n  \"snd ((A >>= (\\<lambda>a. return (X a))) s) = snd (A s)\"\n  by (clarsimp simp: return_def bind_def split_def)\n\nlemma whileLoopE_liftE:\n  \"whileLoopE C (\\<lambda>r. liftE (B r)) r = liftE (whileLoop C B r)\"\n  apply (rule ext)\n  apply (clarsimp simp: whileLoopE_def)\n  apply (rule prod_eqI)\n   apply (rule set_eqI, rule iffI)\n    apply clarsimp\n    apply (clarsimp simp: in_bind whileLoop_def liftE_def)\n    apply (rule_tac x=\"b\" in exI)\n    apply (rule_tac x=\"projr a\" in exI)\n    apply (rule conjI)\n     apply (erule whileLoop_results_bisim[where rt=projr\n                                            and st=\"\\<lambda>x. x\"\n                                            and I=\"\\<lambda>r s. case r of Inr x \\<Rightarrow> True | _ \\<Rightarrow> False\"],\n            auto intro: whileLoop_results.intros simp: bind_def return_def lift_def split: sum.splits)[1]\n    apply (drule whileLoop_results_induct_lemma2[where P=\"\\<lambda>(r, s). case r of Inr x \\<Rightarrow> True | _ \\<Rightarrow> False\"])\n        apply (rule refl)\n       apply (rule refl)\n      apply clarsimp\n     apply (clarsimp simp: return_def bind_def lift_def split: sum.splits)\n    apply (clarsimp simp: return_def bind_def lift_def split: sum.splits)\n   apply (clarsimp simp: in_bind whileLoop_def liftE_def)\n   apply (erule whileLoop_results_bisim[where rt=Inr and st=\"\\<lambda>x. x\" and I=\"\\<lambda>r s. True\"],\n          auto intro: whileLoop_results.intros intro!: bexI simp: bind_def return_def lift_def\n               split: sum.splits)[1]\n  apply (rule iffI)\n   apply (clarsimp simp: whileLoop_def liftE_def del: notI)\n   apply (erule disjE)\n    apply (erule whileLoop_results_bisim[where rt=projr\n                                           and st=\"\\<lambda>x. x\"\n                                           and I=\"\\<lambda>r s. case r of Inr x \\<Rightarrow> True | _ \\<Rightarrow> False\"],\n           auto intro: whileLoop_results.intros simp: bind_def return_def lift_def split: sum.splits)[1]\n   apply (subst (asm) whileLoop_terminates_liftE [symmetric])\n   apply (fastforce simp: whileLoop_def liftE_def whileLoop_terminatesE_def)\n  apply (clarsimp simp: whileLoop_def liftE_def del: notI)\n  apply (subst (asm) whileLoop_terminates_liftE [symmetric])\n  apply (clarsimp simp: whileLoop_def liftE_def whileLoop_terminatesE_def)\n  apply (erule disjE)\n   apply (erule whileLoop_results_bisim [where rt=Inr and st=\"\\<lambda>x. x\" and I=\"\\<lambda>r s. True\"])\n         apply (clarsimp split: option.splits)\n        apply (clarsimp split: option.splits)\n       apply (clarsimp split: option.splits)\n      apply (auto intro: whileLoop_results.intros intro!: bexI simp: bind_def return_def lift_def\n                  split: sum.splits)\n  done\n\nlemma validNF_whileLoop:\n  assumes pre: \"\\<And>s. P r s \\<Longrightarrow> I r s\"\n  and inv: \"\\<And>r s. \\<lbrace>\\<lambda>s'. I r s' \\<and> C r s' \\<and> s' = s \\<rbrace> B r \\<lbrace> \\<lambda>r' s'. I r' s' \\<and> ((r', s'), (r, s)) \\<in> R \\<rbrace>!\"\n  and wf: \"wf R\"\n  and post_cond: \"\\<And>r s. \\<lbrakk>I r s; \\<not> C r s\\<rbrakk> \\<Longrightarrow> Q r s\"\n  shows \"\\<lbrace>P r\\<rbrace> whileLoop C B r \\<lbrace>Q\\<rbrace>!\"\n  apply rule\n   apply (rule valid_whileLoop)\n     apply fact\n    apply (insert inv, clarsimp simp: validNF_def valid_def split: prod.splits, force)[1]\n   apply (metis post_cond)\n  apply (unfold no_fail_def)\n  apply (intro allI impI)\n  apply (rule not_snd_whileLoop [where I=I and R=R])\n    apply (auto intro: assms)\n  done\n\nlemma validNF_whileLoop_inv [wp]:\n  assumes inv: \"\\<And>r s. \\<lbrace>\\<lambda>s'. I r s' \\<and> C r s' \\<and> s' = s \\<rbrace> B r \\<lbrace> \\<lambda>r' s'. I r' s' \\<and> ((r', s'), (r, s)) \\<in> R \\<rbrace>!\"\n  and wf: \"wf R\"\n  and post_cond: \"\\<And>r s. \\<lbrakk>I r s; \\<not> C r s\\<rbrakk> \\<Longrightarrow> Q r s\"\n  shows \"\\<lbrace>I r\\<rbrace> whileLoop_inv C B r I R \\<lbrace>Q\\<rbrace>!\"\n  apply (clarsimp simp: whileLoop_inv_def)\n  apply (rule validNF_whileLoop [where I=I and R=R])\n     apply simp\n    apply (rule inv)\n   apply (rule wf)\n  apply (metis post_cond)\n  done\n\nlemma validNF_whileLoop_inv_measure [wp]:\n  assumes inv: \"\\<And>r s. \\<lbrace>\\<lambda>s'. I r s' \\<and> C r s' \\<and> s' = s \\<rbrace> B r \\<lbrace> \\<lambda>r' s'. I r' s' \\<and> M r' s' < M r s \\<rbrace>!\"\n  and post_cond: \"\\<And>r s. \\<lbrakk>I r s; \\<not> C r s\\<rbrakk> \\<Longrightarrow> Q r s\"\n  shows \"\\<lbrace>I r\\<rbrace> whileLoop_inv C B r I (measure' (\\<lambda>(r, s). M r s)) \\<lbrace>Q\\<rbrace>!\"\n  apply (clarsimp simp: whileLoop_inv_def)\n    apply (rule validNF_whileLoop[where R=\"measure' (\\<lambda>(r, s). M r s)\" and I=I])\n     apply simp\n    apply clarsimp\n    apply (rule inv)\n   apply simp\n  apply (metis post_cond)\n  done\n\nlemma validNF_whileLoop_inv_measure_twosteps:\n  assumes inv: \"\\<And>r s. \\<lbrace>\\<lambda>s'. I r s' \\<and> C r s' \\<rbrace> B r \\<lbrace> \\<lambda>r' s'. I r' s' \\<rbrace>!\"\n  assumes measure: \"\\<And>r m. \\<lbrace>\\<lambda>s. I r s \\<and> C r s \\<and> M r s = m \\<rbrace> B r \\<lbrace> \\<lambda>r' s'. M r' s' < m \\<rbrace>\"\n  and post_cond: \"\\<And>r s. \\<lbrakk>I r s; \\<not> C r s\\<rbrakk> \\<Longrightarrow> Q r s\"\n  shows \"\\<lbrace>I r\\<rbrace> whileLoop_inv C B r I (measure' (\\<lambda>(r, s). M r s)) \\<lbrace>Q\\<rbrace>!\"\n  apply (rule validNF_whileLoop_inv_measure)\n   apply (rule validNF_weaken_pre)\n    apply (rule validNF_post_comb_conj_L)\n     apply (rule inv)\n    apply (rule measure)\n   apply fast\n  apply (metis post_cond)\n  done\n\nlemma wf_custom_measure:\n  \"\\<lbrakk> \\<And>a b. (a, b) \\<in> R \\<Longrightarrow> f a < (f :: 'a \\<Rightarrow> nat) b \\<rbrakk> \\<Longrightarrow>  wf R\"\n  by (metis in_measure wf_def wf_measure)\n\nlemma validNF_whileLoopE:\n  assumes pre: \"\\<And>s. P r s \\<Longrightarrow> I r s\"\n  and inv: \"\\<And>r s. \\<lbrace>\\<lambda>s'. I r s' \\<and> C r s' \\<and> s' = s \\<rbrace> B r \\<lbrace> \\<lambda>r' s'. I r' s' \\<and> ((r', s'), (r, s)) \\<in> R \\<rbrace>,\\<lbrace> E \\<rbrace>!\"\n  and wf: \"wf R\"\n  and post_cond: \"\\<And>r s. \\<lbrakk>I r s; \\<not> C r s\\<rbrakk> \\<Longrightarrow> Q r s\"\n  shows \"\\<lbrace> P r \\<rbrace> whileLoopE C B r \\<lbrace> Q \\<rbrace>,\\<lbrace> E \\<rbrace>!\"\n  apply (unfold validE_NF_alt_def whileLoopE_def)\n  apply (rule validNF_whileLoop [where\n                I=\"\\<lambda>r s. case r of Inl x \\<Rightarrow> E x s | Inr x \\<Rightarrow> I x s\" and\n                R=\"{((r', s'), (r, s)). \\<exists>x x'. r' = Inl x' \\<and> r = Inr x} \\<union>\n                   {((r', s'), (r, s)). \\<exists>x x'. r' = Inr x' \\<and> r = Inr x \\<and> ((x', s'),(x, s)) \\<in> R}\"])\n     apply (simp add: pre)\n    apply (insert inv)[1]\n    apply (fastforce simp: lift_def validNF_def valid_def validE_NF_def throwError_def no_fail_def\n                           return_def validE_def\n                     split: sum.splits prod.splits)\n   apply (rule wf_Un)\n     apply (rule wf_custom_measure [where f=\"\\<lambda>(r, s). case r of Inl _ \\<Rightarrow> 0 | _ \\<Rightarrow> 1\"])\n     apply clarsimp\n    apply (insert wf_inv_image [OF wf, where f=\"\\<lambda>(r, s). (projr r, s)\"])\n    apply (drule wf_Int1 [where r'=\"{((r', s'),(r, s)). (\\<exists>x. r = Inr x) \\<and> (\\<exists>x. r' = Inr x)}\"])\n    apply (erule wf_subset)\n    apply (fastforce simp: inv_image_def split: prod.splits sum.splits)\n   apply fastforce\n  apply (fastforce split: sum.splits intro: post_cond)\n  done\n\nlemma validNF_whileLoopE_inv [wp]:\n  assumes inv: \"\\<And>r s. \\<lbrace>\\<lambda>s'. I r s' \\<and> C r s' \\<and> s' = s \\<rbrace> B r \\<lbrace> \\<lambda>r' s'. I r' s' \\<and> ((r', s'), (r, s)) \\<in> R \\<rbrace>,\\<lbrace> E \\<rbrace>!\"\n  and wf_R: \"wf R\"\n  and post_cond: \"\\<And>r s. \\<lbrakk>I r s; \\<not> C r s\\<rbrakk> \\<Longrightarrow> Q r s\"\n  shows \"\\<lbrace>I r\\<rbrace> whileLoopE_inv C B r I R \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>!\"\n  apply (clarsimp simp: whileLoopE_inv_def)\n  apply (metis validNF_whileLoopE [OF _ inv] post_cond wf_R)\n  done\n\nlemma validNF_whileLoopE_inv_measure [wp]:\n  assumes inv: \"\\<And>r s. \\<lbrace>\\<lambda>s'. I r s' \\<and> C r s' \\<and> s' = s \\<rbrace> B r \\<lbrace> \\<lambda>r' s'. I r' s' \\<and> M r' s' < M r s \\<rbrace>, \\<lbrace> E \\<rbrace>!\"\n  and post_cond: \"\\<And>r s. \\<lbrakk>I r s; \\<not> C r s\\<rbrakk> \\<Longrightarrow> Q r s\"\n  shows \"\\<lbrace>I r\\<rbrace> whileLoopE_inv C B r I (measure' (\\<lambda>(r, s). M r s)) \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>!\"\n  apply (rule validNF_whileLoopE_inv)\n    apply clarsimp\n    apply (rule inv)\n   apply clarsimp\n  apply (metis post_cond)\n  done\n\nlemma validNF_whileLoopE_inv_measure_twosteps:\n  assumes inv: \"\\<And>r. \\<lbrace>\\<lambda>s'. I r s' \\<and> C r s' \\<rbrace> B r \\<lbrace> \\<lambda>r' s'. I r' s' \\<rbrace>, \\<lbrace> E \\<rbrace>!\"\n  assumes measure: \"\\<And>r m. \\<lbrace>\\<lambda>s. I r s \\<and> C r s \\<and> M r s = m \\<rbrace> B r \\<lbrace> \\<lambda>r' s'. M r' s' < m \\<rbrace>, \\<lbrace> \\<lambda>_ _. True \\<rbrace>\"\n  and post_cond: \"\\<And>r s. \\<lbrakk>I r s; \\<not> C r s\\<rbrakk> \\<Longrightarrow> Q r s\"\n  shows \"\\<lbrace>I r\\<rbrace> whileLoopE_inv C B r I (measure' (\\<lambda>(r, s). M r s)) \\<lbrace>Q\\<rbrace>, \\<lbrace>E\\<rbrace>!\"\n  apply (rule validNF_whileLoopE_inv_measure)\n   apply (rule validE_NF_weaken_pre)\n    apply (rule validE_NF_post_comb_conj_L)\n     apply (rule inv)\n    apply (rule measure)\n   apply fast\n  apply (metis post_cond)\n  done\n\nlemma whileLoopE_wp_inv [wp]:\n  \"\\<lbrakk> \\<And>r. \\<lbrace>\\<lambda>s. I r s \\<and> C r s\\<rbrace> B r \\<lbrace>I\\<rbrace>,\\<lbrace>E\\<rbrace>; \\<And>r s. \\<lbrakk>I r s; \\<not> C r s\\<rbrakk> \\<Longrightarrow> Q r s \\<rbrakk>\n      \\<Longrightarrow> \\<lbrace> I r \\<rbrace> whileLoopE_inv C B r I M \\<lbrace> Q \\<rbrace>,\\<lbrace> E \\<rbrace>\"\n  apply (clarsimp simp: whileLoopE_inv_def)\n  apply (rule validE_whileLoopE [where I=I], auto)\n  done\n\nsubsection \"Stronger whileLoop rules\"\n\nlemma whileLoop_rule_strong:\n  assumes init_U: \"\\<lbrace> \\<lambda>s'. s' = s \\<rbrace> whileLoop C B r \\<lbrace> \\<lambda>r s. (r, s) \\<in> fst Q \\<rbrace>\"\n  and path_exists: \"\\<And>r'' s''. \\<lbrakk> (r'', s'') \\<in> fst Q \\<rbrakk> \\<Longrightarrow> \\<lbrace> \\<lambda>s'. s' = s \\<rbrace> whileLoop C B r \\<exists>\\<lbrace> \\<lambda>r s. r = r'' \\<and> s = s'' \\<rbrace>\"\n  and loop_fail: \"snd Q \\<Longrightarrow> snd (whileLoop C B r s)\"\n  and loop_nofail: \"\\<not> snd Q \\<Longrightarrow> \\<lbrace> \\<lambda>s'. s' = s \\<rbrace> whileLoop C B r \\<lbrace> \\<lambda>_ _. True \\<rbrace>!\"\n  shows \"whileLoop C B r s = Q\"\n  using assms\n  apply atomize\n  apply (clarsimp simp: valid_def exs_valid_def validNF_def no_fail_def)\n  apply rule\n    apply blast\n   apply blast\n  apply blast\n  done\n\nlemma whileLoop_rule_strong_no_fail:\n  assumes init_U: \"\\<lbrace> \\<lambda>s'. s' = s \\<rbrace> whileLoop C B r \\<lbrace> \\<lambda>r s. (r, s) \\<in> fst Q \\<rbrace>!\"\n  and path_exists: \"\\<And>r'' s''. \\<lbrakk> (r'', s'') \\<in> fst Q \\<rbrakk> \\<Longrightarrow> \\<lbrace> \\<lambda>s'. s' = s \\<rbrace> whileLoop C B r \\<exists>\\<lbrace> \\<lambda>r s. r = r'' \\<and> s = s'' \\<rbrace>\"\n  and loop_no_fail: \"\\<not> snd Q\"\n  shows \"whileLoop C B r s = Q\"\n  apply (rule whileLoop_rule_strong)\n     apply (metis init_U validNF_valid)\n    apply (metis path_exists)\n   apply (metis loop_no_fail)\n  apply (metis (lifting, no_types) init_U validNF_chain)\n  done\n\nsubsection \"Miscellaneous rules\"\n\n(* Failure of one whileLoop implies the failure of another whileloop\n * which will only ever fail more. *)\nlemma snd_whileLoop_subset:\n    assumes a_fails: \"snd (whileLoop C A r s)\"\n    and b_success_step:\n        \"\\<And>r s r' s'. \\<lbrakk> C r s; (r', s') \\<in> fst (A r s); \\<not> snd (B r s) \\<rbrakk>\n             \\<Longrightarrow> (r', s') \\<in> fst (B r s)\"\n    and b_fail_step: \"\\<And>r s. \\<lbrakk> C r s; snd (A r s) \\<rbrakk> \\<Longrightarrow> snd (B r s) \"\n   shows \"snd (whileLoop C B r s)\"\n  apply (insert a_fails)\n  apply (induct rule: snd_whileLoop_induct)\n    apply (unfold whileLoop_def snd_conv)[1]\n    apply (rule disjCI, simp)\n    apply rotate_tac\n    apply (induct rule: whileLoop_terminates.induct)\n     apply (subst (asm) whileLoop_terminates.simps)\n     apply simp\n    apply (subst (asm) (3) whileLoop_terminates.simps, clarsimp)\n    apply (subst whileLoop_results.simps, clarsimp)\n    apply (rule classical)\n    apply (frule b_success_step, assumption, simp)\n    apply (drule (1) bspec)\n    apply clarsimp\n   apply (frule (1) b_fail_step)\n   apply (metis snd_whileLoop_first_step)\n  apply (metis b_success_step snd_whileLoop_first_step snd_whileLoop_unfold)\n  done\n\n\nsubsection \"Some rules for whileM\"\n\nlemma whileM_wp_gen:\n  assumes termin:\"\\<And>s. I False s \\<Longrightarrow> Q s\"\n  assumes [wp]: \"\\<lbrace>I'\\<rbrace> C \\<lbrace>I\\<rbrace>\"\n  assumes [wp]: \"\\<lbrace>I True\\<rbrace> f \\<lbrace>\\<lambda>_. I'\\<rbrace>\"\n  shows \"\\<lbrace>I'\\<rbrace> whileM C f \\<lbrace>\\<lambda>_. Q\\<rbrace>\"\n  unfolding whileM_def\n  using termin\n  by (wpsimp wp: whileLoop_wp[where I=I])\n\nlemma whileM_inv:\n  \"\\<lbrakk>f \\<lbrace>Q\\<rbrace>; P \\<lbrace>Q\\<rbrace>\\<rbrakk> \\<Longrightarrow> whileM P f \\<lbrace>Q\\<rbrace>\"\n  by (fastforce intro: whileM_wp_gen)\n\nlemmas whileM_post_inv\n  = hoare_strengthen_post[where R=\"\\<lambda>_. Q\" for Q, OF whileM_inv[where P=C for C], rotated -1]\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/lib/Monads/WhileLoopRules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5156199157230157, "lm_q2_score": 0.5813030906443133, "lm_q1q2_score": 0.29973145060754935}}
{"text": "header {* \\isaheader{Slicing guarantees IFC Noninterference} *}\n\ntheory NonInterferenceIntra imports \n  \"../Slicing/StaticIntra/Slice\" \n  \"../Slicing/Basic/CFGExit_wf\"\nbegin\n\nsection {* Assumptions of this Approach *}\n\ntext {*\nClassical IFC noninterference, a special case of a noninterference\ndefinition using partial equivalence relations (per)\n\\cite{SabelfeldS:01}, partitions the variables (i.e.\\ locations) into\nsecurity levels. Usually, only levels for secret or high, written\n@{text H}, and public or low, written @{text L}, variables are\nused. Basically, a program that is noninterferent has to fulfil one\nbasic property: executing the program in two different initial states\nthat may differ in the values of their @{text H}-variables yields two\nfinal states that again only differ in the values of their \n@{text H}-variables; thus the values of the @{text H}-variables did not\ninfluence those of the @{text L}-variables.\n\nEvery per-based approach makes certain\nassumptions: (i) all \\mbox{@{text H}-variables} are defined at the\nbeginning of the program, (ii) all @{text L}-variables are observed (or\nused in our terms) at the end and (iii) every variable is either\n@{text H} or @{text L}. This security label is fixed for a variable\nand can not be altered during a program run. Thus, we have to extend \nthe prerequisites of the slicing framework in \\cite{Wasserrab:08} accordingly\nin a new locale:\n\n*}\n\nlocale NonInterferenceIntraGraph = \n  BackwardSlice sourcenode targetnode kind valid_edge Entry Def Use state_val \n  backward_slice +\n  CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use state_val Exit\n  for sourcenode :: \"'edge \\<Rightarrow> 'node\" and targetnode :: \"'edge \\<Rightarrow> 'node\"\n  and kind :: \"'edge \\<Rightarrow> 'state edge_kind\" and valid_edge :: \"'edge \\<Rightarrow> bool\"\n  and Entry :: \"'node\" (\"'('_Entry'_')\") and Def :: \"'node \\<Rightarrow> 'var set\"\n  and Use :: \"'node \\<Rightarrow> 'var set\" and state_val :: \"'state \\<Rightarrow> 'var \\<Rightarrow> 'val\"\n  and backward_slice :: \"'node set \\<Rightarrow> 'node set\" \n  and Exit :: \"'node\" (\"'('_Exit'_')\") +\n  fixes H :: \"'var set\"\n  fixes L :: \"'var set\"\n  fixes High :: \"'node\"  (\"'('_High'_')\")\n  fixes Low :: \"'node\"   (\"'('_Low'_')\")\n  assumes Entry_edge_Exit_or_High:\n  \"\\<lbrakk>valid_edge a; sourcenode a = (_Entry_)\\<rbrakk> \n    \\<Longrightarrow> targetnode a = (_Exit_) \\<or> targetnode a = (_High_)\"\n  and High_target_Entry_edge:\n  \"\\<exists>a. valid_edge a \\<and> sourcenode a = (_Entry_) \\<and> targetnode a = (_High_) \\<and>\n       kind a = (\\<lambda>s. True)\\<^sub>\\<surd>\"\n  and Entry_predecessor_of_High:\n  \"\\<lbrakk>valid_edge a; targetnode a = (_High_)\\<rbrakk> \\<Longrightarrow> sourcenode a = (_Entry_)\"\n  and Exit_edge_Entry_or_Low: \"\\<lbrakk>valid_edge a; targetnode a = (_Exit_)\\<rbrakk> \n    \\<Longrightarrow> sourcenode a = (_Entry_) \\<or> sourcenode a = (_Low_)\"\n  and Low_source_Exit_edge:\n  \"\\<exists>a. valid_edge a \\<and> sourcenode a = (_Low_) \\<and> targetnode a = (_Exit_) \\<and> \n       kind a = (\\<lambda>s. True)\\<^sub>\\<surd>\"\n  and Exit_successor_of_Low:\n  \"\\<lbrakk>valid_edge a; sourcenode a = (_Low_)\\<rbrakk> \\<Longrightarrow> targetnode a = (_Exit_)\"\n  and DefHigh: \"Def (_High_) = H\" \n  and UseHigh: \"Use (_High_) = H\"\n  and UseLow: \"Use (_Low_) = L\"\n  and HighLowDistinct: \"H \\<inter> L = {}\"\n  and HighLowUNIV: \"H \\<union> L = UNIV\"\n\nbegin\n\nlemma Low_neq_Exit: assumes \"L \\<noteq> {}\" shows \"(_Low_) \\<noteq> (_Exit_)\"\nproof\n  assume \"(_Low_) = (_Exit_)\"\n  have \"Use (_Exit_) = {}\" by fastforce\n  with UseLow `L \\<noteq> {}` `(_Low_) = (_Exit_)` show False by simp\nqed\n\nlemma Entry_path_High_path:\n  assumes \"(_Entry_) -as\\<rightarrow>* n\" and \"inner_node n\"\n  obtains a' as' where \"as = a'#as'\" and \"(_High_) -as'\\<rightarrow>* n\" \n  and \"kind a' = (\\<lambda>s. True)\\<^sub>\\<surd>\"\nproof(atomize_elim)\n  from `(_Entry_) -as\\<rightarrow>* n` `inner_node n`\n  show \"\\<exists>a' as'. as = a'#as' \\<and> (_High_) -as'\\<rightarrow>* n \\<and> kind a' = (\\<lambda>s. True)\\<^sub>\\<surd>\"\n  proof(induct n'\\<equiv>\"(_Entry_)\" as n rule:path.induct)\n    case (Cons_path n'' as n' a)\n    from `n'' -as\\<rightarrow>* n'` `inner_node n'` have \"n'' \\<noteq> (_Exit_)\" \n      by(fastforce simp:inner_node_def)\n    with `valid_edge a` `targetnode a = n''` `sourcenode a = (_Entry_)`\n    have \"n'' = (_High_)\" by -(drule Entry_edge_Exit_or_High,auto)\n    from High_target_Entry_edge\n    obtain a' where \"valid_edge a'\" and \"sourcenode a' = (_Entry_)\"\n      and \"targetnode a' = (_High_)\" and \"kind a' = (\\<lambda>s. True)\\<^sub>\\<surd>\"\n      by blast\n    with `valid_edge a` `sourcenode a = (_Entry_)` `targetnode a = n''`\n      `n'' = (_High_)`\n    have \"a = a'\" by(auto dest:edge_det)\n    with `n'' -as\\<rightarrow>* n'` `n'' = (_High_)` `kind a' = (\\<lambda>s. True)\\<^sub>\\<surd>` show ?case by blast\n  qed fastforce\nqed\n\n\n\nlemma Exit_path_Low_path:\n  assumes \"n -as\\<rightarrow>* (_Exit_)\" and \"inner_node n\"\n  obtains a' as' where \"as = as'@[a']\" and \"n -as'\\<rightarrow>* (_Low_)\"\n  and \"kind a' = (\\<lambda>s. True)\\<^sub>\\<surd>\"\nproof(atomize_elim)\n  from `n -as\\<rightarrow>* (_Exit_)`\n  show \"\\<exists>as' a'. as = as'@[a'] \\<and> n -as'\\<rightarrow>* (_Low_) \\<and> kind a' = (\\<lambda>s. True)\\<^sub>\\<surd>\"\n  proof(induct as rule:rev_induct)\n    case Nil\n    with `inner_node n` show ?case by fastforce\n  next\n    case (snoc a' as')\n    from `n -as'@[a']\\<rightarrow>* (_Exit_)`\n    have \"n -as'\\<rightarrow>* sourcenode a'\" and \"valid_edge a'\" and \"targetnode a' = (_Exit_)\"\n      by(auto elim:path_split_snoc)\n    { assume \"sourcenode a' = (_Entry_)\"\n      with `n -as'\\<rightarrow>* sourcenode a'` have \"n = (_Entry_)\"\n        by(blast intro!:path_Entry_target)\n      with `inner_node n` have False by(simp add:inner_node_def) }\n    with `valid_edge a'` `targetnode a' = (_Exit_)` have \"sourcenode a' = (_Low_)\"\n      by(blast dest!:Exit_edge_Entry_or_Low)\n    from Low_source_Exit_edge\n    obtain ax where \"valid_edge ax\" and \"sourcenode ax = (_Low_)\"\n      and \"targetnode ax = (_Exit_)\" and \"kind ax = (\\<lambda>s. True)\\<^sub>\\<surd>\"\n      by blast\n    with `valid_edge a'` `targetnode a' = (_Exit_)` `sourcenode a' = (_Low_)`\n    have \"a' = ax\" by(fastforce intro:edge_det)\n    with `n -as'\\<rightarrow>* sourcenode a'` `sourcenode a' = (_Low_)` `kind ax = (\\<lambda>s. True)\\<^sub>\\<surd>`\n    show ?case by blast\n  qed\nqed\n\n\nlemma not_Low_High: \"V \\<notin> L \\<Longrightarrow> V \\<in> H\"\n  using HighLowUNIV\n  by fastforce\n\nlemma not_High_Low: \"V \\<notin> H \\<Longrightarrow> V \\<in> L\"\n  using HighLowUNIV\n  by fastforce\n\n\nsection {* Low Equivalence *}\n\ntext {*\nIn classical noninterference, an external observer can only see public values,\nin our case the @{text L}-variables. If two states agree in the values of all \n@{text L}-variables, these states are indistinguishable for him. \n\\emph{Low equivalence} groups those states in an equivalence class using \nthe relation @{text \"\\<approx>\\<^sub>L\"}:\n*}\n\ndefinition lowEquivalence :: \"'state \\<Rightarrow> 'state \\<Rightarrow> bool\" (infixl \"\\<approx>\\<^sub>L\" 50)\n  where \"s \\<approx>\\<^sub>L s' \\<equiv> \\<forall>V \\<in> L. state_val s V = state_val s' V\"\n\ntext {* The following lemmas connect low equivalent states with\nrelevant variables as necessary in the correctness proof for slicing. *}\n\nlemma relevant_vars_Entry:\n  assumes \"V \\<in> rv S (_Entry_)\" and \"(_High_) \\<notin> backward_slice S\"\n  shows \"V \\<in> L\"\nproof -\n  from `V \\<in> rv S (_Entry_)` obtain as n' where \"(_Entry_) -as\\<rightarrow>* n'\"\n    and \"n' \\<in> backward_slice S\" and \"V \\<in> Use n'\"\n    and \"\\<forall>nx \\<in> set(sourcenodes as). V \\<notin> Def nx\" by(erule rvE)\n  from `(_Entry_) -as\\<rightarrow>* n'` have \"valid_node n'\" by(rule path_valid_node)\n  thus ?thesis\n  proof(cases n' rule:valid_node_cases)\n    case Entry\n    with `V \\<in> Use n'` have False by(simp add:Entry_empty)\n    thus ?thesis by simp\n  next\n    case Exit\n    with `V \\<in> Use n'` have False by(simp add:Exit_empty)\n    thus ?thesis by simp\n  next\n    case inner\n    with `(_Entry_) -as\\<rightarrow>* n'` obtain a' as' where \"as = a'#as'\"\n      and \"(_High_) -as'\\<rightarrow>* n'\" by -(erule Entry_path_High_path)\n    from `(_Entry_) -as\\<rightarrow>* n'` `as = a'#as'`\n    have \"sourcenode a' = (_Entry_)\" by(fastforce elim:path.cases)\n    show ?thesis\n    proof(cases \"as' = []\")\n      case True\n      with `(_High_) -as'\\<rightarrow>* n'` have \"n' = (_High_)\" by fastforce\n      with `n' \\<in> backward_slice S` `(_High_) \\<notin> backward_slice S`\n      have False by simp\n      thus ?thesis by simp\n    next\n      case False\n      with `(_High_) -as'\\<rightarrow>* n'` have \"hd (sourcenodes as') = (_High_)\"\n        by(rule path_sourcenode)\n      from False have \"hd (sourcenodes as') \\<in> set (sourcenodes as')\"\n        by(fastforce intro:hd_in_set simp:sourcenodes_def)\n      with `as = a'#as'` have \"hd (sourcenodes as') \\<in> set (sourcenodes as)\"\n        by(simp add:sourcenodes_def)\n      with `hd (sourcenodes as') = (_High_)` `\\<forall>nx \\<in> set(sourcenodes as). V \\<notin> Def nx`\n      have \"V \\<notin> Def (_High_)\" by fastforce\n      hence \"V \\<notin> H\" by(simp add:DefHigh)\n      thus ?thesis by(rule not_High_Low)\n    qed\n  qed\nqed\n\n\n\nlemma lowEquivalence_relevant_nodes_Entry:\n  assumes \"s \\<approx>\\<^sub>L s'\" and \"(_High_) \\<notin> backward_slice S\"\n  shows \"\\<forall>V \\<in> rv S (_Entry_). state_val s V = state_val s' V\"\nproof\n  fix V assume \"V \\<in> rv S (_Entry_)\"\n  with `(_High_) \\<notin> backward_slice S` have \"V \\<in> L\" by -(rule relevant_vars_Entry)\n  with `s \\<approx>\\<^sub>L s'` show \"state_val s V = state_val s' V\" by(simp add:lowEquivalence_def)\nqed\n\n\n\nlemma rv_Low_Use_Low:\n  assumes \"(_Low_) \\<in> S\"\n  shows \"\\<lbrakk>n -as\\<rightarrow>* (_Low_); n -as'\\<rightarrow>* (_Low_);\n    \\<forall>V \\<in> rv S n. state_val s V = state_val s' V;\n    preds (slice_kinds S as) s; preds (slice_kinds S as') s'\\<rbrakk>\n  \\<Longrightarrow> \\<forall>V \\<in> Use (_Low_). state_val (transfers (slice_kinds S as) s) V =\n                       state_val (transfers (slice_kinds S as') s') V\"\nproof(induct n as n\\<equiv>\"(_Low_)\" arbitrary:as' s s' rule:path.induct)\n  case empty_path\n  { fix V assume \"V \\<in> Use (_Low_)\"\n    moreover\n    from `valid_node (_Low_)` have \"(_Low_) -[]\\<rightarrow>* (_Low_)\"\n      by(fastforce intro:path.empty_path)\n    moreover\n    from `valid_node (_Low_)` `(_Low_) \\<in> S` have \"(_Low_) \\<in> backward_slice S\"\n      by(fastforce intro:refl)\n    ultimately have \"V \\<in> rv S (_Low_)\"\n      by(fastforce intro:rvI simp:sourcenodes_def) }\n  hence \"\\<forall>V \\<in> Use (_Low_). V \\<in> rv S (_Low_)\" by simp\n  show ?case\n  proof(cases \"L = {}\")\n    case True with UseLow show ?thesis by simp\n  next\n    case False\n    from `(_Low_) -as'\\<rightarrow>* (_Low_)` have \"as' = []\"\n    proof(induct n\\<equiv>\"(_Low_)\" as' n'\\<equiv>\"(_Low_)\" rule:path.induct)\n      case (Cons_path n'' as a)\n      from `valid_edge a` `sourcenode a = (_Low_)`\n      have \"targetnode a = (_Exit_)\" by -(rule Exit_successor_of_Low,simp+)\n      with `targetnode a = n''` `n'' -as\\<rightarrow>* (_Low_)`\n      have \"(_Low_) = (_Exit_)\" by -(rule path_Exit_source,fastforce)\n      with False have False by -(drule Low_neq_Exit,simp)\n      thus ?case by simp\n    qed simp\n    with `\\<forall>V \\<in> Use (_Low_). V \\<in> rv S (_Low_)` \n      `\\<forall>V\\<in>rv S (_Low_). state_val s V = state_val s' V`\n    show ?thesis by(auto simp:slice_kinds_def)\n  qed\nnext\n  case (Cons_path n'' as a n)\n  note IH = `\\<And>as' s s'. \\<lbrakk>n'' -as'\\<rightarrow>* (_Low_);\n    \\<forall>V\\<in>rv S n''. state_val s V = state_val s' V;\n   preds (slice_kinds S as) s; preds (slice_kinds S as') s'\\<rbrakk>\n  \\<Longrightarrow> \\<forall>V\\<in>Use (_Low_). state_val (transfers (slice_kinds S as) s) V =\n                     state_val (transfers (slice_kinds S as') s') V`\n  show ?case\n  proof(cases \"L = {}\")\n    case True with UseLow show ?thesis by simp\n  next\n    case False\n    show ?thesis\n    proof(cases as')\n      case Nil\n      with `n -as'\\<rightarrow>* (_Low_)` have \"n = (_Low_)\" by fastforce\n      with `valid_edge a` `sourcenode a = n` have \"targetnode a = (_Exit_)\"\n        by -(rule Exit_successor_of_Low,simp+)\n      from Low_source_Exit_edge obtain ax where \"valid_edge ax\"\n        and \"sourcenode ax = (_Low_)\" and \"targetnode ax = (_Exit_)\"\n        and \"kind ax = (\\<lambda>s. True)\\<^sub>\\<surd>\" by blast\n      from `valid_edge a` `sourcenode a = n` `n = (_Low_)` `targetnode a = (_Exit_)`\n        `valid_edge ax` `sourcenode ax = (_Low_)` `targetnode ax = (_Exit_)`\n      have \"a = ax\" by(fastforce dest:edge_det)\n      with `kind ax = (\\<lambda>s. True)\\<^sub>\\<surd>` have \"kind a = (\\<lambda>s. True)\\<^sub>\\<surd>\" by simp\n      with `targetnode a = (_Exit_)` `targetnode a = n''` `n'' -as\\<rightarrow>* (_Low_)`\n      have \"(_Low_) = (_Exit_)\" by -(rule path_Exit_source,auto)\n      with False have False by -(drule Low_neq_Exit,simp)\n      thus ?thesis by simp\n    next\n      case (Cons ax asx)\n      with `n -as'\\<rightarrow>* (_Low_)` have \"n = sourcenode ax\" and \"valid_edge ax\" \n        and \"targetnode ax -asx\\<rightarrow>* (_Low_)\" by(auto elim:path_split_Cons)\n      show ?thesis\n      proof(cases \"targetnode ax = n''\")\n        case True\n        with `targetnode ax -asx\\<rightarrow>* (_Low_)` have \"n'' -asx\\<rightarrow>* (_Low_)\" by simp\n        from `valid_edge ax` `valid_edge a` `n = sourcenode ax` `sourcenode a = n`\n          True `targetnode a = n''` have \"ax = a\" by(fastforce intro:edge_det)\n        from `preds (slice_kinds S (a#as)) s` \n        have preds1:\"preds (slice_kinds S as) (transfer (slice_kind S a) s)\"\n          by(simp add:slice_kinds_def)\n        from `preds (slice_kinds S as') s'` Cons `ax = a`\n        have preds2:\"preds (slice_kinds S asx) \n          (transfer (slice_kind S a) s')\"\n          by(simp add:slice_kinds_def)\n        from `valid_edge a` `sourcenode a = n` `targetnode a = n''`\n          `preds (slice_kinds S (a#as)) s` `preds (slice_kinds S as') s'`\n          `ax = a` Cons `\\<forall>V\\<in>rv S n. state_val s V = state_val s' V`\n        have \"\\<forall>V\\<in>rv S n''. state_val (transfer (slice_kind S a) s) V =\n                                 state_val (transfer (slice_kind S a) s') V\"\n          by -(rule rv_edge_slice_kinds,auto)\n        from IH[OF `n'' -asx\\<rightarrow>* (_Low_)` this preds1 preds2] \n          Cons `ax = a` show ?thesis by(simp add:slice_kinds_def)\n      next\n        case False\n        with `valid_edge a` `valid_edge ax` `sourcenode a = n` `n = sourcenode ax`\n          `targetnode a = n''` `preds (slice_kinds S (a#as)) s`\n          `preds (slice_kinds S as') s'` Cons\n          `\\<forall>V\\<in>rv S n. state_val s V = state_val s' V`\n        have False by -(rule rv_branching_edges_slice_kinds_False,auto)\n        thus ?thesis by simp\n      qed\n    qed\n  qed\nqed\n\n\nsection {* The Correctness Proofs *}\n\ntext {*\nIn the following, we present two correctness proofs that slicing guarantees\nIFC noninterference. In both theorems, \n@{text \"(_High_) \\<notin> backward_slice S\"}, where @{text \"(_Low_) \\<in> S\"},\nmakes sure that no high variable (which are all defined in @{text \"(_High_)\"}) \ncan influence a low variable (which are all used in @{text \"(_Low_)\"}).\n\nFirst, a theorem regarding \n@{text \"(_Entry_) -as\\<rightarrow>* (_Exit_)\"} paths in the control flow graph (CFG),\nwhich agree to a complete program execution: *}\n\nlemma nonInterference_path_to_Low:\n  assumes \"s \\<approx>\\<^sub>L s'\" and \"(_High_) \\<notin> backward_slice S\" and \"(_Low_) \\<in> S\"\n  and \"(_Entry_) -as\\<rightarrow>* (_Low_)\" and \"preds (kinds as) s\"\n  and \"(_Entry_) -as'\\<rightarrow>* (_Low_)\" and \"preds (kinds as') s'\"\n  shows \"transfers (kinds as) s \\<approx>\\<^sub>L transfers (kinds as') s'\"\nproof -\n  from `(_Entry_) -as\\<rightarrow>* (_Low_)` `preds (kinds as) s` `(_Low_) \\<in> S`\n  obtain asx where \"preds (slice_kinds S asx) s\"\n    and \"\\<forall>V \\<in> Use (_Low_). state_val(transfers (slice_kinds S asx) s) V = \n                           state_val(transfers (kinds as) s) V\"\n    and \"slice_edges S as = slice_edges S asx\"\n    and \"(_Entry_) -asx\\<rightarrow>* (_Low_)\" by(erule fundamental_property_of_static_slicing)\n  from `(_Entry_) -as'\\<rightarrow>* (_Low_)` `preds (kinds as') s'` `(_Low_) \\<in> S`\n  obtain asx' where \"preds (slice_kinds S asx') s'\"\n    and \"\\<forall>V \\<in> Use (_Low_). state_val (transfers (slice_kinds S asx') s') V = \n                           state_val (transfers (kinds as') s') V\"\n    and \"slice_edges S as' = slice_edges S asx'\"\n    and \"(_Entry_) -asx'\\<rightarrow>* (_Low_)\" by(erule fundamental_property_of_static_slicing)\n  from `s \\<approx>\\<^sub>L s'` `(_High_) \\<notin> backward_slice S`\n  have \"\\<forall>V \\<in> rv S (_Entry_). state_val s V = state_val s' V\" \n    by(rule lowEquivalence_relevant_nodes_Entry)\n  with `(_Entry_) -asx\\<rightarrow>* (_Low_)` `(_Entry_) -asx'\\<rightarrow>* (_Low_)` `(_Low_) \\<in> S`\n    `preds (slice_kinds S asx) s` `preds (slice_kinds S asx') s'`\n  have \"\\<forall>V \\<in> Use (_Low_). state_val (transfers (slice_kinds S asx) s) V =\n                          state_val (transfers (slice_kinds S asx') s') V\"\n    by -(rule rv_Low_Use_Low,auto)\n  with `\\<forall>V \\<in> Use (_Low_). state_val(transfers (slice_kinds S asx) s) V = \n                          state_val(transfers (kinds as) s) V`\n    `\\<forall>V \\<in> Use (_Low_). state_val (transfers (slice_kinds S asx') s') V = \n                       state_val (transfers (kinds as') s') V`\n  show ?thesis by(auto simp:lowEquivalence_def UseLow)\nqed\n\n\ntheorem nonInterference_path:\n  assumes \"s \\<approx>\\<^sub>L s'\" and \"(_High_) \\<notin> backward_slice S\" and \"(_Low_) \\<in> S\"\n  and \"(_Entry_) -as\\<rightarrow>* (_Exit_)\" and \"preds (kinds as) s\"\n  and \"(_Entry_) -as'\\<rightarrow>* (_Exit_)\" and \"preds (kinds as') s'\"\n  shows \"transfers (kinds as) s \\<approx>\\<^sub>L transfers (kinds as') s'\"\nproof -\n  from `(_Entry_) -as\\<rightarrow>* (_Exit_)` obtain x xs where \"as = x#xs\"\n    and \"(_Entry_) = sourcenode x\" and \"valid_edge x\" \n    and \"targetnode x -xs\\<rightarrow>* (_Exit_)\"\n    apply(cases \"as = []\")\n     apply(simp,drule empty_path_nodes,drule Entry_noteq_Exit,simp)\n    by(erule path_split_Cons)\n  from `valid_edge x` have \"valid_node (targetnode x)\" by simp\n  hence \"inner_node (targetnode x)\"\n  proof(cases rule:valid_node_cases)\n    case Entry\n    with `valid_edge x` have False by(rule Entry_target)\n    thus ?thesis by simp\n  next\n    case Exit\n    with `targetnode x -xs\\<rightarrow>* (_Exit_)` have \"xs = []\"\n      by -(rule path_Exit_source,simp)\n    from Entry_Exit_edge obtain z where \"valid_edge z\"\n      and \"sourcenode z = (_Entry_)\" and \"targetnode z = (_Exit_)\"\n      and \"kind z = (\\<lambda>s. False)\\<^sub>\\<surd>\" by blast\n    from `valid_edge x` `valid_edge z` `(_Entry_) = sourcenode x` \n      `sourcenode z = (_Entry_)` Exit `targetnode z = (_Exit_)`\n    have \"x = z\" by(fastforce intro:edge_det)\n    with `preds (kinds as) s` `as = x#xs` `xs = []` `kind z = (\\<lambda>s. False)\\<^sub>\\<surd>` \n    have False by(simp add:kinds_def)\n    thus ?thesis by simp\n  qed simp\n  with `targetnode x -xs\\<rightarrow>* (_Exit_)` obtain x' xs' where \"xs = xs'@[x']\"\n    and \"targetnode x -xs'\\<rightarrow>* (_Low_)\" and \"kind x' = (\\<lambda>s. True)\\<^sub>\\<surd>\"\n    by(fastforce elim:Exit_path_Low_path)\n  with `(_Entry_) = sourcenode x` `valid_edge x`\n  have \"(_Entry_) -x#xs'\\<rightarrow>* (_Low_)\" by(fastforce intro:Cons_path)\n  from `as = x#xs` `xs = xs'@[x']` have \"as = (x#xs')@[x']\" by simp\n  with `preds (kinds as) s` have \"preds (kinds (x#xs')) s\"\n    by(simp add:kinds_def preds_split)\n  from `(_Entry_) -as'\\<rightarrow>* (_Exit_)` obtain y ys where \"as' = y#ys\"\n    and \"(_Entry_) = sourcenode y\" and \"valid_edge y\" \n    and \"targetnode y -ys\\<rightarrow>* (_Exit_)\"\n    apply(cases \"as' = []\")\n     apply(simp,drule empty_path_nodes,drule Entry_noteq_Exit,simp)\n    by(erule path_split_Cons)\n  from `valid_edge y` have \"valid_node (targetnode y)\" by simp\n  hence \"inner_node (targetnode y)\"\n  proof(cases rule:valid_node_cases)\n    case Entry\n    with `valid_edge y` have False by(rule Entry_target)\n    thus ?thesis by simp\n  next\n    case Exit\n    with `targetnode y -ys\\<rightarrow>* (_Exit_)` have \"ys = []\"\n      by -(rule path_Exit_source,simp)\n    from Entry_Exit_edge obtain z where \"valid_edge z\"\n      and \"sourcenode z = (_Entry_)\" and \"targetnode z = (_Exit_)\"\n      and \"kind z = (\\<lambda>s. False)\\<^sub>\\<surd>\" by blast\n    from `valid_edge y` `valid_edge z` `(_Entry_) = sourcenode y` \n      `sourcenode z = (_Entry_)` Exit `targetnode z = (_Exit_)`\n    have \"y = z\" by(fastforce intro:edge_det)\n    with `preds (kinds as') s'` `as' = y#ys` `ys = []` `kind z = (\\<lambda>s. False)\\<^sub>\\<surd>` \n    have False by(simp add:kinds_def)\n    thus ?thesis by simp\n  qed simp\n  with `targetnode y -ys\\<rightarrow>* (_Exit_)` obtain y' ys' where \"ys = ys'@[y']\"\n    and \"targetnode y -ys'\\<rightarrow>* (_Low_)\" and \"kind y' = (\\<lambda>s. True)\\<^sub>\\<surd>\"\n    by(fastforce elim:Exit_path_Low_path)\n  with `(_Entry_) = sourcenode y` `valid_edge y`\n  have \"(_Entry_) -y#ys'\\<rightarrow>* (_Low_)\" by(fastforce intro:Cons_path)\n  from `as' = y#ys` `ys = ys'@[y']` have \"as' = (y#ys')@[y']\" by simp\n  with `preds (kinds as') s'` have \"preds (kinds (y#ys')) s'\"\n    by(simp add:kinds_def preds_split)\n  from `s \\<approx>\\<^sub>L s'` `(_High_) \\<notin> backward_slice S` `(_Low_) \\<in> S`\n    `(_Entry_) -x#xs'\\<rightarrow>* (_Low_)` `preds (kinds (x#xs')) s`\n    `(_Entry_) -y#ys'\\<rightarrow>* (_Low_)` `preds (kinds (y#ys')) s'`\n  have \"transfers (kinds (x#xs')) s \\<approx>\\<^sub>L transfers (kinds (y#ys')) s'\"\n    by(rule nonInterference_path_to_Low)\n  with `as = x#xs` `xs = xs'@[x']` `kind x' = (\\<lambda>s. True)\\<^sub>\\<surd>`\n    `as' = y#ys` `ys = ys'@[y']` `kind y' = (\\<lambda>s. True)\\<^sub>\\<surd>`\n  show ?thesis by(simp add:kinds_def transfers_split)\nqed\n\n\nend\n\ntext {* The second theorem assumes that we have a operational semantics,\nwhose evaluations are written @{text \"\\<langle>c,s\\<rangle> \\<Rightarrow> \\<langle>c',s'\\<rangle>\"} and which conforms \nto the CFG. The correctness theorem then states that if no high variable\ninfluenced a low variable and the initial states were low equivalent, the\nreulting states are again low equivalent: *}\n\n\nlocale NonInterferenceIntra = \n  NonInterferenceIntraGraph sourcenode targetnode kind valid_edge Entry \n    Def Use state_val backward_slice Exit H L High Low +\n  BackwardSlice_wf sourcenode targetnode kind valid_edge Entry Def Use state_val \n    backward_slice sem identifies\n  for sourcenode :: \"'edge \\<Rightarrow> 'node\" and targetnode :: \"'edge \\<Rightarrow> 'node\"\n  and kind :: \"'edge \\<Rightarrow> 'state edge_kind\" and valid_edge :: \"'edge \\<Rightarrow> bool\"\n  and Entry :: \"'node\" (\"'('_Entry'_')\") and Def :: \"'node \\<Rightarrow> 'var set\"\n  and Use :: \"'node \\<Rightarrow> 'var set\" and state_val :: \"'state \\<Rightarrow> 'var \\<Rightarrow> 'val\"\n  and backward_slice :: \"'node set \\<Rightarrow> 'node set\"\n  and sem :: \"'com \\<Rightarrow> 'state \\<Rightarrow> 'com \\<Rightarrow> 'state \\<Rightarrow> bool\" \n    (\"((1\\<langle>_,/_\\<rangle>) \\<Rightarrow>/ (1\\<langle>_,/_\\<rangle>))\" [0,0,0,0] 81)\n  and identifies :: \"'node \\<Rightarrow> 'com \\<Rightarrow> bool\" (\"_ \\<triangleq> _\" [51, 0] 80)\n  and Exit :: \"'node\" (\"'('_Exit'_')\")\n  and H :: \"'var set\" and L :: \"'var set\" \n  and High :: \"'node\"  (\"'('_High'_')\") and Low :: \"'node\"   (\"'('_Low'_')\") +\n  fixes final :: \"'com \\<Rightarrow> bool\"\n  assumes final_edge_Low: \"\\<lbrakk>final c; n \\<triangleq> c\\<rbrakk> \n  \\<Longrightarrow> \\<exists>a. valid_edge a \\<and> sourcenode a = n \\<and> targetnode a = (_Low_) \\<and> kind a = \\<Up>id\"\nbegin\n\ntext{* The following theorem needs the explicit edge from @{text \"(_High_)\"}\n  to @{text n}. An approach using a @{text \"init\"} predicate for initial statements,\n  being reachable from @{text \"(_High_)\"} via a @{text \"(\\<lambda>s. True)\\<^sub>\\<surd>\"} edge,\n  does not work as the same statement could be identified by several nodes, some\n  initial, some not. E.g., in the program \\texttt{while (True) Skip;;Skip}\n  two nodes identify this inital statement: the initial node and the node\n  within the loop (because of loop unrolling).*}\n\ntheorem nonInterference:\n  assumes \"s\\<^sub>1 \\<approx>\\<^sub>L s\\<^sub>2\" and \"(_High_) \\<notin> backward_slice S\" and \"(_Low_) \\<in> S\"\n  and \"valid_edge a\" and \"sourcenode a = (_High_)\" and \"targetnode a = n\" \n  and \"kind a = (\\<lambda>s. True)\\<^sub>\\<surd>\" and \"n \\<triangleq> c\" and \"final c'\"\n  and \"\\<langle>c,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>c',s\\<^sub>1'\\<rangle>\" and \"\\<langle>c,s\\<^sub>2\\<rangle> \\<Rightarrow> \\<langle>c',s\\<^sub>2'\\<rangle>\"\n  shows \"s\\<^sub>1' \\<approx>\\<^sub>L s\\<^sub>2'\"\nproof -\n  from High_target_Entry_edge obtain ax where \"valid_edge ax\"\n    and \"sourcenode ax = (_Entry_)\" and \"targetnode ax = (_High_)\"\n    and \"kind ax = (\\<lambda>s. True)\\<^sub>\\<surd>\" by blast\n  from `n \\<triangleq> c` `\\<langle>c,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>c',s\\<^sub>1'\\<rangle>`\n  obtain n\\<^sub>1 as\\<^sub>1 where \"n -as\\<^sub>1\\<rightarrow>* n\\<^sub>1\" and \"transfers (kinds as\\<^sub>1) s\\<^sub>1 = s\\<^sub>1'\"\n    and \"preds (kinds as\\<^sub>1) s\\<^sub>1\" and \"n\\<^sub>1 \\<triangleq> c'\"\n    by(fastforce dest:fundamental_property)\n  from `n -as\\<^sub>1\\<rightarrow>* n\\<^sub>1` `valid_edge a` `sourcenode a = (_High_)` `targetnode a = n`\n  have \"(_High_) -a#as\\<^sub>1\\<rightarrow>* n\\<^sub>1\" by(rule Cons_path)\n  from `final c'` `n\\<^sub>1 \\<triangleq> c'`\n  obtain a\\<^sub>1 where \"valid_edge a\\<^sub>1\" and \"sourcenode a\\<^sub>1 = n\\<^sub>1\" \n    and \"targetnode a\\<^sub>1 = (_Low_)\" and \"kind a\\<^sub>1 = \\<Up>id\" by(fastforce dest:final_edge_Low)\n  hence \"n\\<^sub>1 -[a\\<^sub>1]\\<rightarrow>* (_Low_)\" by(fastforce intro:path_edge)\n  with `(_High_) -a#as\\<^sub>1\\<rightarrow>* n\\<^sub>1` have \"(_High_) -(a#as\\<^sub>1)@[a\\<^sub>1]\\<rightarrow>* (_Low_)\"\n    by(rule path_Append)\n  with `valid_edge ax` `sourcenode ax = (_Entry_)` `targetnode ax = (_High_)`\n  have \"(_Entry_) -ax#((a#as\\<^sub>1)@[a\\<^sub>1])\\<rightarrow>* (_Low_)\" by -(rule Cons_path)\n  from `kind ax = (\\<lambda>s. True)\\<^sub>\\<surd>` `kind a = (\\<lambda>s. True)\\<^sub>\\<surd>` `preds (kinds as\\<^sub>1) s\\<^sub>1`\n    `kind a\\<^sub>1 = \\<Up>id` have \"preds (kinds (ax#((a#as\\<^sub>1)@[a\\<^sub>1]))) s\\<^sub>1\"\n    by (simp add:kinds_def preds_split)\n  from `n \\<triangleq> c` `\\<langle>c,s\\<^sub>2\\<rangle> \\<Rightarrow> \\<langle>c',s\\<^sub>2'\\<rangle>`\n  obtain n\\<^sub>2 as\\<^sub>2 where \"n -as\\<^sub>2\\<rightarrow>* n\\<^sub>2\" and \"transfers (kinds as\\<^sub>2) s\\<^sub>2 = s\\<^sub>2'\"\n    and \"preds (kinds as\\<^sub>2) s\\<^sub>2\" and \"n\\<^sub>2 \\<triangleq> c'\"\n    by(fastforce dest:fundamental_property)\n  from `n -as\\<^sub>2\\<rightarrow>* n\\<^sub>2` `valid_edge a` `sourcenode a = (_High_)` `targetnode a = n`\n  have \"(_High_) -a#as\\<^sub>2\\<rightarrow>* n\\<^sub>2\" by(rule Cons_path)\n  from `final c'` `n\\<^sub>2 \\<triangleq> c'`\n  obtain a\\<^sub>2 where \"valid_edge a\\<^sub>2\" and \"sourcenode a\\<^sub>2 = n\\<^sub>2\" \n    and \"targetnode a\\<^sub>2 = (_Low_)\" and \"kind a\\<^sub>2 = \\<Up>id\" by(fastforce dest:final_edge_Low)\n  hence \"n\\<^sub>2 -[a\\<^sub>2]\\<rightarrow>* (_Low_)\" by(fastforce intro:path_edge)\n  with `(_High_) -a#as\\<^sub>2\\<rightarrow>* n\\<^sub>2` have \"(_High_) -(a#as\\<^sub>2)@[a\\<^sub>2]\\<rightarrow>* (_Low_)\"\n    by(rule path_Append)\n  with `valid_edge ax` `sourcenode ax = (_Entry_)` `targetnode ax = (_High_)`\n  have \"(_Entry_) -ax#((a#as\\<^sub>2)@[a\\<^sub>2])\\<rightarrow>* (_Low_)\" by -(rule Cons_path)\n  from `kind ax = (\\<lambda>s. True)\\<^sub>\\<surd>` `kind a = (\\<lambda>s. True)\\<^sub>\\<surd>` `preds (kinds as\\<^sub>2) s\\<^sub>2`\n    `kind a\\<^sub>2 = \\<Up>id` have \"preds (kinds (ax#((a#as\\<^sub>2)@[a\\<^sub>2]))) s\\<^sub>2\"\n    by (simp add:kinds_def preds_split)\n  from `s\\<^sub>1 \\<approx>\\<^sub>L s\\<^sub>2` `(_High_) \\<notin> backward_slice S` `(_Low_) \\<in> S`\n    `(_Entry_) -ax#((a#as\\<^sub>1)@[a\\<^sub>1])\\<rightarrow>* (_Low_)` `preds (kinds (ax#((a#as\\<^sub>1)@[a\\<^sub>1]))) s\\<^sub>1`\n    `(_Entry_) -ax#((a#as\\<^sub>2)@[a\\<^sub>2])\\<rightarrow>* (_Low_)` `preds (kinds (ax#((a#as\\<^sub>2)@[a\\<^sub>2]))) s\\<^sub>2`\n  have \"transfers (kinds (ax#((a#as\\<^sub>1)@[a\\<^sub>1]))) s\\<^sub>1 \\<approx>\\<^sub>L \n        transfers (kinds (ax#((a#as\\<^sub>2)@[a\\<^sub>2]))) s\\<^sub>2\"\n    by(rule nonInterference_path_to_Low)\n  with `kind ax = (\\<lambda>s. True)\\<^sub>\\<surd>` `kind a = (\\<lambda>s. True)\\<^sub>\\<surd>` `kind a\\<^sub>1 = \\<Up>id` `kind a\\<^sub>2 = \\<Up>id`\n    `transfers (kinds as\\<^sub>1) s\\<^sub>1 = s\\<^sub>1'` `transfers (kinds as\\<^sub>2) s\\<^sub>2 = s\\<^sub>2'`\n  show ?thesis by(simp add:kinds_def transfers_split)\nqed\n\n\nend\n\nend\n\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/InformationFlowSlicing/NonInterferenceIntra.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6187804478040617, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.29972492545628154}}
{"text": "(*  Title:      HOL/HOLCF/IOA/RefMappings.thy\n    Author:     Olaf Müller\n*)\n\nsection \\<open>Refinement Mappings in HOLCF/IOA\\<close>\n\ntheory RefMappings\nimports Traces\nbegin\n\ndefault_sort type\n\ndefinition move :: \"('a, 's) ioa \\<Rightarrow> ('a, 's) pairs \\<Rightarrow> 's \\<Rightarrow> 'a \\<Rightarrow> 's \\<Rightarrow> bool\"\n  where \"move ioa ex s a t \\<longleftrightarrow>\n    is_exec_frag ioa (s, ex) \\<and> Finite ex \\<and>\n    laststate (s, ex) = t \\<and>\n    mk_trace ioa \\<cdot> ex = (if a \\<in> ext ioa then a \\<leadsto> nil else nil)\"\n\ndefinition is_ref_map :: \"('s1 \\<Rightarrow> 's2) \\<Rightarrow> ('a, 's1) ioa \\<Rightarrow> ('a, 's2) ioa \\<Rightarrow> bool\"\n  where \"is_ref_map f C A \\<longleftrightarrow>\n   ((\\<forall>s \\<in> starts_of C. f s \\<in> starts_of A) \\<and>\n     (\\<forall>s t a. reachable C s \\<and> s \\<midarrow>a\\<midarrow>C\\<rightarrow> t \\<longrightarrow> (\\<exists>ex. move A ex (f s) a (f t))))\"\n\ndefinition is_weak_ref_map :: \"('s1 \\<Rightarrow> 's2) \\<Rightarrow> ('a, 's1) ioa \\<Rightarrow> ('a, 's2) ioa \\<Rightarrow> bool\"\n  where \"is_weak_ref_map f C A \\<longleftrightarrow>\n    ((\\<forall>s \\<in> starts_of C. f s \\<in> starts_of A) \\<and>\n      (\\<forall>s t a. reachable C s \\<and> s \\<midarrow>a\\<midarrow>C\\<rightarrow> t \\<longrightarrow>\n        (if a \\<in> ext C then (f s) \\<midarrow>a\\<midarrow>A\\<rightarrow> (f t) else f s = f t)))\"\n\n\nsubsection \\<open>Transitions and moves\\<close>\n\nlemma transition_is_ex: \"s \\<midarrow>a\\<midarrow>A\\<rightarrow> t \\<Longrightarrow> \\<exists>ex. move A ex s a t\"\n  apply (rule_tac x = \" (a, t) \\<leadsto> nil\" in exI)\n  apply (simp add: move_def)\n  done\n\nlemma nothing_is_ex: \"a \\<notin> ext A \\<and> s = t \\<Longrightarrow> \\<exists>ex. move A ex s a t\"\n  apply (rule_tac x = \"nil\" in exI)\n  apply (simp add: move_def)\n  done\n\nlemma ei_transitions_are_ex:\n  \"s \\<midarrow>a\\<midarrow>A\\<rightarrow> s' \\<and> s' \\<midarrow>a'\\<midarrow>A\\<rightarrow> s'' \\<and> a' \\<notin> ext A \\<Longrightarrow> \\<exists>ex. move A ex s a s''\"\n  apply (rule_tac x = \" (a,s') \\<leadsto> (a',s'') \\<leadsto>nil\" in exI)\n  apply (simp add: move_def)\n  done\n\nlemma eii_transitions_are_ex:\n  \"s1 \\<midarrow>a1\\<midarrow>A\\<rightarrow> s2 \\<and> s2 \\<midarrow>a2\\<midarrow>A\\<rightarrow> s3 \\<and> s3 \\<midarrow>a3\\<midarrow>A\\<rightarrow> s4 \\<and> a2 \\<notin> ext A \\<and> a3 \\<notin> ext A \\<Longrightarrow>\n    \\<exists>ex. move A ex s1 a1 s4\"\n  apply (rule_tac x = \"(a1, s2) \\<leadsto> (a2, s3) \\<leadsto> (a3, s4) \\<leadsto> nil\" in exI)\n  apply (simp add: move_def)\n  done\n\n\nsubsection \\<open>\\<open>weak_ref_map\\<close> and \\<open>ref_map\\<close>\\<close>\n\nlemma weak_ref_map2ref_map: \"ext C = ext A \\<Longrightarrow> is_weak_ref_map f C A \\<Longrightarrow> is_ref_map f C A\"\n  apply (unfold is_weak_ref_map_def is_ref_map_def)\n  apply auto\n  apply (case_tac \"a \\<in> ext A\")\n  apply (auto intro: transition_is_ex nothing_is_ex)\n  done\n\nlemma imp_conj_lemma: \"(P \\<Longrightarrow> Q \\<longrightarrow> R) \\<Longrightarrow> P \\<and> Q \\<longrightarrow> R\"\n  by blast\n\ndeclare if_split [split del]\ndeclare if_weak_cong [cong del]\n\nlemma rename_through_pmap:\n  \"is_weak_ref_map f C A \\<Longrightarrow> is_weak_ref_map f (rename C g) (rename A g)\"\n  apply (simp add: is_weak_ref_map_def)\n  apply (rule conjI)\n  text \\<open>1: start states\\<close>\n  apply (simp add: rename_def rename_set_def starts_of_def)\n  text \\<open>1: start states\\<close>\n  apply (rule allI)+\n  apply (rule imp_conj_lemma)\n  apply (simp (no_asm) add: rename_def rename_set_def)\n  apply (simp add: externals_def asig_inputs_def asig_outputs_def asig_of_def trans_of_def)\n  apply safe\n  apply (simplesubst if_split)\n   apply (rule conjI)\n   apply (rule impI)\n   apply (erule disjE)\n   apply (erule exE)\n  apply (erule conjE)\n  text \\<open>\\<open>x\\<close> is input\\<close>\n   apply (drule sym)\n   apply (drule sym)\n  apply simp\n  apply hypsubst+\n  apply (frule reachable_rename)\n  apply simp\n  text \\<open>\\<open>x\\<close> is output\\<close>\n   apply (erule exE)\n  apply (erule conjE)\n   apply (drule sym)\n   apply (drule sym)\n  apply simp\n  apply hypsubst+\n  apply (frule reachable_rename)\n  apply simp\n  text \\<open>\\<open>x\\<close> is internal\\<close>\n  apply (frule reachable_rename)\n  apply auto\n  done\n\ndeclare if_split [split]\ndeclare if_weak_cong [cong]\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/HOLCF/IOA/RefMappings.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6187804337438501, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.29972491864579504}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory ExtraSpecs\n\nimports\n  \"CLib.TypHeapLib\"\n\nbegin\n\ndefinition\n  \"simple_simpl_refines \\<Gamma> com com'\n    = (\\<forall>s. (\\<exists>ft. \\<Gamma> \\<turnstile> \\<langle>com', Normal s\\<rangle> \\<Rightarrow> Fault ft)\n        \\<or> ((\\<forall>xs. \\<Gamma> \\<turnstile> \\<langle>com, Normal s\\<rangle> \\<Rightarrow> xs \\<longrightarrow> \\<Gamma> \\<turnstile> \\<langle>com', Normal s\\<rangle> \\<Rightarrow> xs)\n            \\<and> (\\<not> terminates \\<Gamma> com (Normal s) \\<longrightarrow> \\<not> terminates \\<Gamma> com' (Normal s))))\"\n\nlemma simple_simpl_refines_no_fault_execD:\n  \"\\<Gamma> \\<turnstile> \\<langle>com,Normal s\\<rangle> \\<Rightarrow> xs\n    \\<Longrightarrow> simple_simpl_refines \\<Gamma> com com'\n    \\<Longrightarrow> (\\<forall>ft. \\<not> \\<Gamma> \\<turnstile> \\<langle>com',Normal s\\<rangle> \\<Rightarrow> Fault ft)\n    \\<Longrightarrow> \\<Gamma> \\<turnstile> \\<langle>com', Normal s\\<rangle> \\<Rightarrow> xs\"\n  by (auto simp add: simple_simpl_refines_def)\n\nlemma simple_simpl_refines_no_fault_terminatesD:\n  \"simple_simpl_refines \\<Gamma> com com'\n    \\<Longrightarrow> (\\<forall>ft. \\<not> \\<Gamma> \\<turnstile> \\<langle>com',Normal s\\<rangle> \\<Rightarrow> Fault ft)\n    \\<Longrightarrow> \\<not> terminates \\<Gamma> com (Normal s) \\<longrightarrow> \\<not> terminates \\<Gamma> com' (Normal s)\"\n  by (auto simp add: simple_simpl_refines_def)\n\nlemma simple_simpl_refines_refl:\n  \"simple_simpl_refines \\<Gamma> com com\"\n  by (auto simp add: simple_simpl_refines_def)\n\nlemma simple_simpl_refines_from_def_eq:\n  \"body \\<equiv> body' \\<Longrightarrow> simple_simpl_refines \\<Gamma> body' body\"\n  (* these are flipped, because the \"implementation\" is on the rhs of\n     definitional equalities, but the lhs of refinement thms. *)\n  by (simp add: simple_simpl_refines_def)\n\nlemma simple_simpl_refines_trans:\n  \"simple_simpl_refines \\<Gamma> com com' \\<Longrightarrow> simple_simpl_refines \\<Gamma> com' com''\n    \\<Longrightarrow> simple_simpl_refines \\<Gamma> com com''\"\n  by (simp add: simple_simpl_refines_def, metis)\n\nlemma simple_simpl_refines_drop_Guard:\n  \"simple_simpl_refines \\<Gamma> com (Guard F G com)\"\n  apply (clarsimp simp add: simple_simpl_refines_def)\n  apply (case_tac \"s \\<in> G\")\n  apply (auto intro: exec.Guard exec.GuardFault\n              elim!: terminates_Normal_elim_cases)\n  done\n\nlemma simple_simpl_refines_guarded_Basic_guarded_spec_body:\n  \"(\\<forall>s s'. (s, s') \\<in> R \\<longrightarrow> (s \\<in> G \\<and> (s, f s) \\<in> R))\n    \\<Longrightarrow> simple_simpl_refines \\<Gamma> (Guard F' G (Basic f)) (guarded_spec_body F R)\"\n  apply (simp add: guarded_spec_body_def simple_simpl_refines_def)\n  apply (intro allI, drule_tac x=s in spec)\n  apply (erule impCE)\n   apply (rule disjI1)\n   apply (fastforce intro: exec.GuardFault)\n  apply (rule disjI2)\n  apply (auto intro!: exec.Guard terminates.Guard\n               intro: exec.GuardFault exec.Spec terminates.Basic image_eqI[rotated]\n              elim!: exec_Normal_elim_cases terminates_Normal_elim_cases)\n  done\n\nlemmas simple_simpl_refines_Basic_guarded_spec_body\n    = simple_simpl_refines_trans[OF\n        simple_simpl_refines_drop_Guard[where G=UNIV]\n        simple_simpl_refines_guarded_Basic_guarded_spec_body\n        ]\n\nML \\<open>\nstructure Get_Body_Refines = struct\n\nfun get ctxt name = let\n    fun pget sfx = try (Proof_Context.get_thm ctxt o suffix sfx) name\n    val eqv = pget \"_body_refines\"\n    val def = pget \"_body_def\"\n  in case (eqv, def) of\n      (SOME eqvt, _) => eqvt\n    | (_, SOME deft) => (deft RS @{thm simple_simpl_refines_from_def_eq})\n    | _ => raise THM (\"Get_Body_Refines.get: \"\n          ^ \"no body_def or body_refines: \" ^ name, 1, [])\n  end\n\nend\n\\<close>\n\nend\n", "meta": {"author": "NICTA", "repo": "l4v", "sha": "3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b", "save_path": "github-repos/isabelle/NICTA-l4v", "path": "github-repos/isabelle/NICTA-l4v/l4v-3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b/tools/asmrefine/ExtraSpecs.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6187804196836383, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.29972491183530847}}
{"text": "(******\nType system for Yul language\nCopyright (C) 2020  Ximeng Li, Ning Han\n\nThis library is free software; you can redistribute it and/or\nmodify it under the terms of the GNU Library General Public\nLicense as published by the Free Software Foundation; either\nversion 2 of the License, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\nLibrary General Public License for more details.\n******)\n\ntheory \"Typing\"\n\nimports Main LMap Syntax  \n\nbegin\n\nfun in_range :: \"int \\<Rightarrow> type_name \\<Rightarrow> bool\" where\n  \"in_range i S256 = (-(2^255) \\<le> i \\<and> i < 2^255)\" | \n  \"in_range i U256 = (0 \\<le> i \\<and> i < 2^256)\" | \n  \"in_range i S128 = (-(2^127) \\<le> i \\<and> i < 2^127)\" | \n  \"in_range i U128 = (0 \\<le> i \\<and> i < 2^128)\" | \n  \"in_range i S64 = (-(2^63) \\<le> i \\<and> i < 2^63)\" | \n  \"in_range i U64 = (0 \\<le> i \\<and> i < 2^64)\" | \n  \"in_range i S32 = (-(2^31) \\<le> i \\<and> i < 2^31)\" | \n  \"in_range i U32 = (0 \\<le> i \\<and> i < 2^32)\" | \n  \"in_range i S8 = (-(2^7) \\<le> i \\<and> i < 2^7)\" | \n  \"in_range i U8 = (0 \\<le> i \\<and> i < 2^8)\" | \n  \"in_range i Address160 = (0 \\<le> i \\<and> i < 2^160)\" | \n  \"in_range i _ = False\"\n\n(* the types for variables *)\ndatatype vtype = VType type_name \n\n(* the types for expressions *)\ndatatype etype = DataType \"type_name list\" | StmtType \n\n(* the types for functions *) \ndatatype ftype = FType \"type_name list\" \"type_name list\" \n\n(* typing environments for variables *)\ntype_synonym type_env = \"vtype list_map\" \n\n(* typing environments for functions *)\ntype_synonym ftype_env = \"ftype list_map\"\n\n(* result of typing an expression *)\ndatatype expr_type_res = ETypable etype type_env | EUntypable\n  \n\nvalue \"{1::nat, 2, 3} \\<inter> {4, 5} = {}\"\nvalue \"{1::int, 2} \\<inter> {2, 3}\"\n\nvalue \"sum_list [1::nat,2,3]\"\n\nfun size_of_expr :: \"expr \\<Rightarrow> nat\" and \n    size_of_es :: \"expr list \\<Rightarrow> nat\" and \n    size_of_blk :: \"block \\<Rightarrow> nat\" \n    where \n  \"size_of_expr (EFunCall f es) = 1 + size_of_es es\" | \n  \"size_of_expr (EId x) = 1\" | \n  \"size_of_expr (EImLit lit) = 1\" | \n  \"size_of_expr (ELit lit) = 1\" | \n  \"size_of_expr (EFunDef f pts rts blk) = 1 + size_of_blk blk\" |\n  \"size_of_expr (EVarDecl txs e) = 2 + (length txs) + size_of_expr e\" |\n  \"size_of_expr (EEmptyVarDecl txs) = 1\" | \n  \"size_of_expr (EAssg xs e) = 2 + (length xs) + size_of_expr e\" | \n  \"size_of_expr (EIf e blk) = 1 + size_of_expr e + size_of_blk blk\" |\n  \"size_of_expr (ECond e blk) = 1 + size_of_expr e + size_of_blk blk\" |\n  \"size_of_expr (ESwitch e cases blk_opt) = \n    2 + size_of_expr e + sum_list (map (size_of_blk \\<circ> snd) cases) + \n    (case blk_opt of (Some blk0) \\<Rightarrow> size_of_blk blk0 | _ \\<Rightarrow> 0)\n    \" | \n  \"size_of_expr (EFor blk1 e blk2 blk) =\n    1 + size_of_blk blk1 + size_of_expr e + size_of_blk blk2 + size_of_blk blk\n    \" | \n  \"size_of_expr (ERetId xt) = 1\" |\n  \"size_of_expr (EImFunCall f es) = 1 + size_of_es es\" | \n  \"size_of_expr (EList es) = size_of_es es\" | \n  \"size_of_expr EStop = 1\" | \n  \"size_of_expr EGasJump = 1\" | \n  \"size_of_expr EGasJumpDest = 1\" | \n  \"size_of_expr EGasPush = 1\" | \n  \"size_of_expr EGasPop = 1\" | \n  \"size_of_expr EGasSwap = 1\" | \n\n  \"size_of_blk (Blk es) = 1 + size_of_es es\" | \n\n  \"size_of_es es = 1 + sum_list (map size_of_expr es)\"\n\n\ndefinition builtin_fte :: ftype_env where \n  \"\n  builtin_fte = \n    [(b_land_id, FType [Bool, Bool] [Bool]),  \n    (b_lor_id, FType [Bool, Bool] [Bool]), \n    (b_lxor_id, FType [Bool, Bool] [Bool]), \n    (b_lnot_id, FType [Bool] [Bool]),\n    (b_add_id, FType [U256, U256] [U256]),\n    (b_sub_id, FType [U256, U256] [U256]),\n    (b_mul_id, FType [U256, U256] [U256]),\n    (b_div_id, FType [U256, U256] [U256]),\n    (b_sdiv_id, FType [S256, S256] [S256]),\n    (b_mod_id, FType [U256, U256] [U256]),\n    (b_smod_id, FType [S256, S256] [S256]),\n    (b_exp_id, FType [U256, U256] [U256]),\n    (b_addmod_id, FType [U256, U256, U256] [U256]),\n    (b_mulmod_id, FType [U256, U256, U256] [U256]),\n    (b_lt_id, FType [U256, U256] [Bool]), \n    (b_slt_id, FType [S256, S256] [Bool]), \n    (b_gt_id, FType [U256, U256] [Bool]), \n    (b_sgt_id, FType [S256, S256] [Bool]),\n    (b_eq_id, FType [U256, U256] [Bool]),\n    (b_iszero_id, FType [U256] [Bool]),\n    (b_not_id, FType [U256] [U256]),\n    (b_and_id, FType [U256, U256] [U256]),\n    (b_or_id, FType [U256, U256] [U256]),\n    (b_xor_id, FType [U256, U256] [U256]),\n    (b_shl_id, FType [U256, U256] [U256]),\n    (b_shr_id, FType [U256, U256] [U256]),\n    (b_sar_id, FType [U256, S256] [U256]),\n\n    (b_mstore_id, FType [U256, U256] []),\n    (b_mstore8_id, FType [U256, U256] []),\n    (b_mload_id, FType [U256] [U256]),\n    (b_sstore_id, FType [U256, U256] []),\n    (b_sload_id, FType [U256] [U256]),\n    (b_msize_id, FType [] [U256]),\n\n    (b_call_id, FType [U256, U256, U256, U256, U256, U256, U256] [U256]),\n    (b_callcode_id, FType [U256, U256, U256, U256, U256, U256, U256] [U256]),\n    (b_delegatecall_id, FType [U256, U256, U256, U256, U256, U256] [U256]),\n    (b_return_id, FType [U256, U256] []),\n    (b_revert_id, FType [U256, U256] []),\n    (b_selfdestruct_id, FType [U256] []),\n    (b_log0_id, FType [U256, U256] []),\n    (b_log1_id, FType [U256, U256, U256] []),\n    (b_log2_id, FType [U256, U256, U256, U256] []),\n    (b_log3_id, FType [U256, U256, U256, U256, U256] []),\n    (b_log4_id, FType [U256, U256, U256, U256, U256, U256] []),\n    (b_stop_id, FType [] []), \n    (b_invalid_id, FType [] []), \n\n    (b_coinbase_id, FType [] [U256]),\n    (b_difficulty_id, FType [] [U256]),\n    (b_gaslimit_id, FType [] [U256]),\n    (b_number_id, FType [] [U256]),\n    (b_timestamp_id, FType [] [U256]),\n    (b_origin_id, FType [] [U256]),\n    (b_gasprice_id, FType [] [U256]),\n    (b_gas_id, FType [] [U256]),\n    (b_balance_id, FType [U256] [U256]),\n    (b_address_id, FType [] [U256]), \n    (b_caller_id, FType [] [U256]),\n    (b_callvalue_id, FType [] [U256]),\n    (b_calldatasize_id, FType [] [U256]),\n    (b_calldatacopy_id, FType [] [U256]),\n    (b_calldataload_id, FType [U256] [U256]),\n\n    (b_keccak256_id, FType [U256, U256] [U256])\n    ]\n  \"\n\n(* helper lemma supporting the termination proof for the typing function *)\nlemma in_lst_impl_sz_lt [simp]: \n  \"\\<lbrakk> a \\<in> set es \\<rbrakk> \\<Longrightarrow> size_of_expr a < Suc (sum_list (map size_of_expr es))\"\nproof(induction es arbitrary: a)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons a es)\n  fix a es aa\n  assume H_IH: \"\\<And>a. a \\<in> set es \\<Longrightarrow>\n                     size_of_expr a < Suc (sum_list (map size_of_expr es))\"\n  assume H_in: \"aa \\<in> set (a # es)\"  \n  hence H_or: \"aa = a \\<or> aa \\<in> set es\" by auto\n  thus \"size_of_expr aa < Suc (sum_list (map size_of_expr (a # es)))\"\n  proof\n    assume \"aa = a\" thus ?thesis by simp\n  next \n    assume \"aa \\<in> set es\" thus ?thesis using H_IH by fastforce\n  qed\nqed\n\n(* helper lemma supporting the termination proof for the typing function *)\nlemma in_cases_impl_sz_lt: \n  \"\\<lbrakk> ((lit :L tn), b) \\<in> set cases \\<rbrakk> \n   \\<Longrightarrow> size_of_blk b < Suc (sum_list (map (size_of_blk \\<circ> snd) cases))\"\nproof(induction cases arbitrary: lit tn b)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons a cases)\n  fix a cases lit tn b\n  assume H_IH: \n    \"\\<And>lit tn b.\n           (lit :L tn, b) \\<in> set cases \\<Longrightarrow>\n           size_of_blk b < Suc (sum_list (map (size_of_blk \\<circ> snd) cases))\"\n  assume H_case_in_cases: \"(lit :L tn, b) \\<in> set (a # cases)\"\n  hence H_or: \"((lit :L tn), b) = a \\<or> (lit :L tn, b) \\<in> set cases\" by auto\n  thus \"size_of_blk b < Suc (sum_list (map (size_of_blk \\<circ> snd) (a # cases)))\"\n  proof\n    assume \"((lit :L tn), b) = a\" \n    thus ?thesis by auto\n  next\n    assume \"(lit :L tn, b) \\<in> set cases\" \n    thus ?thesis using H_IH by fastforce\n  qed\nqed\n\n(* obtain information about the types for the user-defined functions for the code *)\nfun get_a_func_types :: \"expr list \\<Rightarrow> ftype_env option\" where \n  \"get_a_func_types [] = Some []\" |\n  \"get_a_func_types ((EFunDef f ptl rtl e) # es') = (\n      case (get_a_func_types es') of \n        (Some te) \\<Rightarrow> \n          (case (lm_get te f) of \n            (Some tp) \\<Rightarrow> None \n           | _ \\<Rightarrow> (Some (te @ [(f, FType (map snd ptl) (map snd rtl))])))\n      | _ \\<Rightarrow> None\n    )\" | \n  \"get_a_func_types (_ # es') = get_a_func_types es'\"\n\ndefinition get_a_func_types_blk :: \"block \\<Rightarrow> ftype_env option\" where \n  \"get_a_func_types_blk blk = (\n    case blk of (Blk es) \\<Rightarrow> get_a_func_types es\n   )\"\n\nfun ret_or_lit :: \"expr \\<Rightarrow> bool\" where\n  \"ret_or_lit (ERetId (x, t)) = True\" | \n  \"ret_or_lit (EImLit l) = True\" | \n  \"ret_or_lit _ = False\" \n\nfun not_elist :: \"expr \\<Rightarrow> bool\" where \n  \"not_elist (EList _) = False\" | \n  \"not_elist _ = True\" \n\n(*\n  - The typing of blocks and expressions takes as parameters\n    the type environment for the variables that can be used in the current scope, \n    the set of variables that additionally exist in outer scopes statically, and \n    the type environment for the functions in scope. \n  - The variables additionally existing in outer scopes statically \n    are those declared in outer scopes of the immediately surrounding function definition. \n    These variables cannot be used in the function defined, nor can they be re-declared. \n*)\nfunction (sequential) \n    type_es :: \"type_env \\<Rightarrow> id0 set \\<Rightarrow> ftype_env \\<Rightarrow> expr list \\<Rightarrow> (bool\\<times>type_env)\" and \n    type_b :: \"type_env \\<Rightarrow> id0 set \\<Rightarrow> ftype_env \\<Rightarrow> block \\<Rightarrow> bool\" and\n    type_e :: \"type_env \\<Rightarrow> id0 set \\<Rightarrow> ftype_env \\<Rightarrow> expr \\<Rightarrow> expr_type_res\"\nwhere \n  \"type_es vte xs fte es = \n    foldl (\\<lambda>acc e. \n            (if (fst acc) then \n              (case type_e (snd acc) xs fte e of \n                (ETypable StmtType vte') \\<Rightarrow> (True, vte') | _ \\<Rightarrow> (False, (snd acc))) \n             else \n              acc)) \n          (True, vte) es\" |\n\n  \"type_b vte xs fte (Blk es) = (case (type_es vte xs fte es) of (b, vte') \\<Rightarrow> b)\" |\n  \n  \"type_e vte xs fte (EId x) = \n    (case (lm_get vte x) of Some (VType tn) \\<Rightarrow> ETypable (DataType [tn]) vte | _ \\<Rightarrow> EUntypable)\" |\n\n  \"type_e vte xs fte (EImLit lit) = (\n     case lit of \n      (TL :L tn) \\<Rightarrow> (if tn = Bool then ETypable (DataType [Bool]) vte else EUntypable)\n    | (FL :L tn) \\<Rightarrow> (if tn = Bool then ETypable (DataType [Bool]) vte else EUntypable)\n    | ((NL i) :L tn) \\<Rightarrow> (if (in_range i tn) then (ETypable (DataType [tn]) vte) else EUntypable)\n    | ((SL ws) :L _) \\<Rightarrow> EUntypable\n  )\n     \" |\n  \"type_e vte xs fte (ELit lit) = (\n     case lit of \n      (TL :L tn) \\<Rightarrow> (if tn = Bool then ETypable (DataType [Bool]) vte else EUntypable)\n    | (FL :L tn) \\<Rightarrow> (if tn = Bool then ETypable (DataType [Bool]) vte else EUntypable)\n    | ((NL i) :L tn) \\<Rightarrow> (if (in_range i tn) then (ETypable (DataType [tn]) vte) else EUntypable)\n    | ((SL ws) :L _) \\<Rightarrow> EUntypable\n  )\" |\n  \n  \"type_e vte xs fte (EFunCall f es) = (\n    case (lm_get (fte @ builtin_fte) f) of\n      Some (FType ptl rtl) \\<Rightarrow> (\n        if length ptl = length es then\n          (let es_no_elist = (foldl (\\<lambda>acc e. (acc \\<and> (not_elist e))) True es) in \n           let es_pts = zip es ptl in \n           \\<comment> \\<open> type-check the arguments \\<close>\n           let es_res =   \n            (foldl (\\<lambda>acc (e, t). \n              (if acc then type_e vte xs fte e = ETypable (DataType [t]) vte else False))\n              True es_pts) in\n           (if es_no_elist \\<and> es_res then \n             (if length rtl = 0 then \n                ETypable StmtType vte\n              else ETypable (DataType rtl) vte)\n            else \n              EUntypable\n           )) \n        else \n          EUntypable\n      )\n    | _ \\<Rightarrow> EUntypable\n    )\" |\n  \\<comment> \\<open> that f is not in the domain of fte cannot be checked here. this is because the type of\n       f might be previously added to fte due to the existence of the function def in a block \\<close>\n  \"type_e vte xs fte (EFunDef f pl rl blk) = (\n    if (f \\<notin> lm_dom builtin_fte \\<and> distinct (pl @ rl)) then\n      (\n      let vte1' = (zip (map fst pl) (map (\\<lambda>(x,tn). (VType tn)) pl)) ;\n          vte2' = (zip (map fst rl) (map (\\<lambda>(x,tn). (VType tn)) rl)) in \n      (\\<comment> \\<open>ids already in the scope cannot be used as formal parameters or return variables\\<close>\n        case (get_a_func_types_blk blk) of \n          Some fte' \\<Rightarrow> (\n            if (lm_dom vte \\<union> xs) \\<inter> (lm_dom vte1' \\<union> lm_dom vte2') = {}\n                \\<and> (lm_dom builtin_fte \\<union> lm_dom fte \\<union> {f}) \\<inter> lm_dom fte' = {} \n                \\<and> (type_b (vte1' @ vte2') (xs \\<union> lm_dom vte) \n                          (fte @ fte' @ [(f, FType (map snd pl) (map snd rl))]) blk) \n            then \n              ETypable StmtType vte\n            else \n              EUntypable\n          ) \n        | _ \\<Rightarrow> EUntypable\n      ))\n    else \n      EUntypable)\n  \" |\n  \"type_e vte xs fte (EVarDecl txs e) = (\n    if (foldl (\\<lambda>acc tx. acc \\<and> (lm_get vte (fst tx)) = None \\<and> ((fst tx) \\<notin> xs) \n                            \\<and> lm_get fte (fst tx) = None) \n              True txs) \n        \\<and> distinct (map fst txs) \n    then (\n      case (type_e vte xs fte e) of \n        (ETypable (DataType tns) vte') \\<Rightarrow> \n         (if length txs = length tns then (\n            let txs_tns = zip txs tns in (\n            if (foldl (\\<lambda>acc ((x, tn1), tn2). acc \\<and> tn1 = tn2) True txs_tns) then (\n              let vte'' = vte @ ((zip (map fst txs) (map ((\\<lambda>tn. (VType tn)) \\<circ> snd) txs)))\n              in (ETypable StmtType vte'')\n            ) else EUntypable\n            )\n          ) else \n            EUntypable)\n      | _ \\<Rightarrow> EUntypable\n    ) \n    else \n      EUntypable\n   )\n  \" | \n  \"type_e vte xs fte (EEmptyVarDecl txs) = (\n    if (foldl (\\<lambda>acc tx. acc \\<and> (lm_get vte (fst tx)) = None \\<and> ((fst tx) \\<notin> xs) \n                            \\<and> lm_get fte (fst tx) = None) \n              True txs) \n        \\<and> distinct (map fst txs) \n    then (\n      let vte' = vte @ (zip (map fst txs) (map (\\<lambda>(x, tn). (VType tn)) txs)) in \n        ETypable StmtType vte'\n    )\n    else \n      EUntypable\n  )\n  \" | \n  \"type_e vte xs0 fte (EAssg xs e) = (\n    case (type_e vte xs0 fte e) of\n      (ETypable (DataType tns) vte') \\<Rightarrow> (\n        if length xs = length tns then\n          let xs_tns = zip xs tns in (\n            if (foldl (\\<lambda>acc (x, tn). acc \\<and> (lm_get vte x = Some (VType tn))) True xs_tns)\n                \\<and> distinct xs\n            then\n              ETypable StmtType vte\n            else \n              EUntypable\n          )\n        else \n          EUntypable\n        )\n    | _ \\<Rightarrow> EUntypable\n  )\n  \" | \n  \"type_e vte xs fte (EIf e blk) = (\n    case (type_e vte xs fte e) of \n      (ETypable (DataType [Bool]) vte') \\<Rightarrow> (\n        if not_elist e then (\n          case (get_a_func_types_blk blk) of \n            Some fte' \\<Rightarrow> \n              (if (lm_dom builtin_fte \\<union> lm_dom fte) \\<inter> lm_dom fte' = {} \n                   \\<and> type_b vte xs (fte @ fte') blk \n               then (ETypable StmtType vte) \n               else EUntypable)\n          | _ \\<Rightarrow> EUntypable\n        ) else\n          EUntypable\n      ) \n    | _ \\<Rightarrow> EUntypable\n    )\n  \" |\n\n  \"type_e vte xs fte (ECond e blk) = (\n    case (type_e vte xs fte e) of \n      (ETypable (DataType [Bool]) vte') \\<Rightarrow> (\n        if not_elist e then (\n          case (get_a_func_types_blk blk) of \n            Some fte' \\<Rightarrow> \n              (if (lm_dom builtin_fte \\<union> lm_dom fte) \\<inter> lm_dom fte' = {}\n                  \\<and> type_b vte xs (fte @ fte') blk then \n                (ETypable StmtType vte) \n               else \n                EUntypable)\n          | _ \\<Rightarrow> EUntypable\n        ) else \n          EUntypable\n      )\n    | _ \\<Rightarrow> EUntypable\n    )\n  \" |\n\n  \"type_e vte xs fte (ESwitch e cases blk_opt) = (\n    case (type_e vte xs fte e) of \n      (ETypable (DataType [tn]) _) \\<Rightarrow> (\n        if not_elist e then (\n          if (foldl \n              (\\<lambda>acc (lit, blk). \n                (case (lit) of \n                  (Literal lkind tn') \\<Rightarrow> \n                    acc \\<and> tn = tn' \\<and> (\n                      case (get_a_func_types_blk blk) of \n                        Some fte' \\<Rightarrow> \n                          (lm_dom builtin_fte \\<union> lm_dom fte) \\<inter> lm_dom fte' = {} \n                           \\<and> type_b vte xs (fte @ fte') blk\n                      | _ \\<Rightarrow> False\n                    ))) True cases) \n          then \n            (\n              case blk_opt of \n                Some blk \\<Rightarrow> (\n                  case (get_a_func_types_blk blk) of \n                    Some fte' \\<Rightarrow> (\n                      if (lm_dom builtin_fte \\<union> lm_dom fte) \\<inter> lm_dom fte' = {} \n                          \\<and> type_b vte xs (fte @ fte') blk then \n                        ETypable StmtType vte\n                      else \n                        EUntypable)\n                  | _ \\<Rightarrow> EUntypable\n                )\n              | None \\<Rightarrow> (ETypable StmtType vte)\n            )\n          else \n            EUntypable\n        ) else \n          EUntypable\n      )\n   |  _ \\<Rightarrow> EUntypable\n   )\n  \" |\n  \"type_e vte xs fte (EFor blk1 e blk2 blk) = (\n    case blk1 of \n      (Blk es1) \\<Rightarrow> (\n        case get_a_func_types es1 of \\<comment> \\<open>forbit function definition inside the init block\\<close>\n          Some [] \\<Rightarrow> (\n          \\<comment> \\<open> variables in the outer scope can all be used in blk1 \\<close>\n          case (type_es vte xs fte es1) of\n            (True, vte') \\<Rightarrow> (\n            case (type_e vte' xs fte e) of\n               ETypable (DataType [Bool]) vte'' \\<Rightarrow> (\n                if not_elist e then (\n                \\<comment> \\<open>variables declared in one of blk and blk2 cannot be used in the other, \n                    but can be declared in the other\\<close>\n                case (get_a_func_types_blk blk2, get_a_func_types_blk blk) of \n                  (Some fte2', Some fte') \\<Rightarrow> (\n                    if (lm_dom builtin_fte \\<union> lm_dom fte) \\<inter> lm_dom fte2' = {} \n                        \\<and> type_b vte' xs (fte @ fte2') blk2 \n                        \\<and> (lm_dom builtin_fte \\<union> lm_dom fte) \\<inter> lm_dom fte' = {}\n                        \\<and> type_b vte' xs (fte @ fte') blk then\n                      ETypable StmtType vte\n                    else \n                      EUntypable)\n                | _ \\<Rightarrow> EUntypable\n                ) else \n                  EUntypable\n               )\n            | _ \\<Rightarrow> EUntypable\n            )\n          | _ \\<Rightarrow> EUntypable \n          )\n        | _ \\<Rightarrow> EUntypable\n      )\n   )\n  \" | \n  \"type_e vte xs fte (ERetId xt) = ETypable (DataType [snd xt]) vte\" |\n  \"type_e vte xs fte (EImFunCall f es) = (\n    case (lm_get (fte @ builtin_fte) f) of \n      Some (FType ptl rtl) \\<Rightarrow> (\n        if length ptl = length es then\n          (let es_no_elist = (foldl (\\<lambda>acc e. (acc \\<and> (not_elist e))) True es) in \n           let es_pts = zip es ptl in \n           \\<comment> \\<open> type-check the arguments \\<close>\n           let es_res =   \n            (foldl (\\<lambda>acc (e, t). \n              (if acc then type_e vte xs fte e = ETypable (DataType [t]) vte else False))\n              True es_pts) in\n           (if es_no_elist \\<and> es_res then \n             (if length rtl = 0 then \n                ETypable StmtType vte\n              else ETypable (DataType rtl) vte)\n            else \n              EUntypable\n           )) \n        else \n          EUntypable\n      )\n    | _ \\<Rightarrow> EUntypable\n    )\" |\n  \"type_e vte xs fte (EList es) = (\n      let es_ret_lit = (foldl (\\<lambda>acc e. acc \\<and> ret_or_lit e) True es) in (\n      if es_ret_lit then (\n        foldl (\\<lambda>acc e. (\n                case acc of (ETypable (DataType tns) _) \\<Rightarrow> (\n                  case type_e vte xs fte e of \n                    (ETypable (DataType [tn]) _) \\<Rightarrow> ETypable (DataType (tns @ [tn])) vte \n                  | _ \\<Rightarrow> EUntypable) \n                | _ \\<Rightarrow> EUntypable))\n        (ETypable (DataType []) vte) es\n      ) else \n        EUntypable\n      )\n  )\" |\n  \"type_e vte xs fte STOP = ETypable StmtType vte\" |\n  \"type_e vte xs fte EGasJump = ETypable StmtType vte\" |\n  \"type_e vte xs fte EGasPush = ETypable StmtType vte\" |\n  \"type_e vte xs fte EGasJumpDest = ETypable StmtType vte\" |\n  \"type_e vte xs fte EGasPop = ETypable StmtType vte\" |\n  \"type_e vte xs fte EGasSwap = ETypable StmtType vte\"\n\n  by pat_completeness auto\n\ntermination proof-\n  show ?thesis\n  apply(relation  \n  \"measure \n    (\\<lambda>x. (case x of \n           (Inl (_::type_env, xs:: id0 set, fte::ftype_env, es::expr list)) \\<Rightarrow> size_of_es es\n         | (Inr (Inl (vte::type_env, xs:: id0 set, fte::ftype_env, blk::block))) \\<Rightarrow> size_of_blk blk\n         | (Inr (Inr (vte::type_env, xs:: id0 set, fte::ftype_env, e::expr))) \\<Rightarrow> size_of_expr e\n         ))\n  \")\n  apply auto \n      apply (simp add: less_SucI set_zip_leftD)\n        using in_cases_impl_sz_lt apply fastforce\n        by (simp add: less_SucI set_zip_leftD) \nqed\n\nend\n", "meta": {"author": "lixm", "repo": "yul-smallstep", "sha": "f71786f5158e335f7caa3311a4928c3ac97912ee", "save_path": "github-repos/isabelle/lixm-yul-smallstep", "path": "github-repos/isabelle/lixm-yul-smallstep/yul-smallstep-f71786f5158e335f7caa3311a4928c3ac97912ee/Typing.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.709019146082187, "lm_q2_score": 0.4225046348141882, "lm_q1q2_score": 0.29956387539172197}}
{"text": "theory TickTock_ExtChoice\n  imports TickTock_Core TickTock_Basic_Ops\nbegin\n\nsubsection {* External Choice *}\n\ndefinition ExtChoiceTT :: \"'e ttobs list set \\<Rightarrow> 'e ttobs list set \\<Rightarrow> 'e ttobs list set\" (infixl \"\\<box>\\<^sub>C\" 57) where\n  \"P \\<box>\\<^sub>C Q = {t. \\<exists> \\<rho>\\<in>tocks(UNIV). \\<exists> \\<sigma> \\<tau>. \n    \\<rho> @ \\<sigma> \\<in> P \\<and> \\<rho> @ \\<tau> \\<in> Q \\<and>\n    (\\<forall>\\<rho>'\\<in>tocks(UNIV). \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n    (\\<forall>\\<rho>'\\<in>tocks(UNIV). \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n    (\\<forall> X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists> Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall> e. (e \\<in> X = (e \\<in> Y)) \\<or> (e = Tock)))) \\<and>\n    (\\<forall> X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists> Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall> e. (e \\<in> X = (e \\<in> Y)) \\<or> (e = Tock)))) \\<and>\n    (t = \\<rho> @ \\<sigma> \\<or> t = \\<rho> @ \\<tau>)}\"\n\ndefinition initially_stable :: \"'e ttprocess \\<Rightarrow> bool\" where\n  \"initially_stable P = (\\<exists> t\\<in>P. \\<exists> X t'. t = [X]\\<^sub>R # t')\"\n\nlemma left_unstable_ExtChoice_def:\n  assumes P_wf: \"\\<forall>x\\<in>P. ttWF x\" and Q_wf: \"\\<forall>x\\<in>Q. ttWF x\"\n  assumes TT0_P: \"TT0 P\" and TT0_Q: \"TT0 Q\" and TT1_Q: \"TT1 Q\"\n  shows \"\\<not> initially_stable P \\<Longrightarrow> P \\<box>\\<^sub>C Q = P \\<union> {t\\<in>Q. \\<nexists>t' X. t = [X]\\<^sub>R # t'}\"\n  unfolding initially_stable_def ExtChoiceTT_def\nproof auto\n  fix \\<rho> \\<sigma> \\<tau> t' :: \"'a tttrace\" and X\n  assume assm1: \"\\<forall>t\\<in>P. \\<forall>X t'. t \\<noteq> [X]\\<^sub>R # t'\"\n  assume assm2: \"\\<rho> \\<in> tocks UNIV\"\n  assume assm3: \"[X]\\<^sub>R # t' \\<notin> P\"\n  assume assm4: \"\\<rho> @ \\<sigma> \\<in> P\"\n  assume assm5: \"[X]\\<^sub>R # t' \\<in> Q\"\n  assume assm6: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n  assume assm7: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C [X]\\<^sub>R # t' \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n  assume assm8: \"\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume assm9: \"\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume assm10: \"\\<rho> @ \\<tau> = [X]\\<^sub>R # t'\"\n\n  have \"t' = [] \\<or> (\\<exists> t''. t' = [Tock]\\<^sub>E # t'')\"\n    using assm5 Q_wf by (cases t' rule:ttWF.cases, simp_all add: notin_tocks, (metis ttWF.simps)+)\n  then show False\n  proof auto\n    assume case_assm: \"t' = []\"\n    then have \"\\<rho> = [] \\<and> \\<sigma> = [[X]\\<^sub>R]\"\n      by (metis Cons_eq_append_conv append_Cons assm1 assm10 assm4 assm9)\n    then show False\n      using assm3 assm4 case_assm by auto\n  next\n    fix t''\n    assume case_assm: \"t' = [Tock]\\<^sub>E # t''\"\n    then obtain \\<rho>' where \"\\<rho> = [X]\\<^sub>R # [Tock]\\<^sub>E # \\<rho>'\"\n      using assm7 tt_prefix_split by (erule_tac x=\"[[X]\\<^sub>R, [Tock]\\<^sub>E]\" in ballE, fastforce, meson subset_UNIV tocks.simps)\n    then show False\n      using assm1 assm4 by auto\n  qed\nnext\n  fix x :: \"'a tttrace\"\n  assume assm1: \"\\<forall>t\\<in>P. \\<forall>X t'. t \\<noteq> [X]\\<^sub>R # t'\"\n  assume assm2: \"x \\<in> P\"\n\n  have 1: \"[] \\<in> Q\"\n    by (simp add: TT0_Q TT0_TT1_empty TT1_Q)\n  have 2: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C x \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C []\"\n    by (metis append_Cons assm1 assm2 tocks.cases tt_prefix_decompose tt_prefix_refl)\n  have 3: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C [] \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C []\"\n    by blast\n  have 4: \"\\<forall>X. x = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. [] = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n    by (simp add: assm1 assm2)\n  have 5: \"\\<forall>X. [] = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. x = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n    by blast\n  show \"\\<exists>\\<rho>\\<in>tocks UNIV. \\<exists>\\<sigma>. \\<rho> @ \\<sigma> \\<in> P \\<and> (\\<exists>\\<tau>. \\<rho> @ \\<tau> \\<in> Q \\<and>\n      (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n      (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n      (\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n      (\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and> (x = \\<rho> @ \\<sigma> \\<or> x = \\<rho> @ \\<tau>))\"\n    using 1 2 3 4 5 by (rule_tac x=\"[]\" in bexI, auto, insert assm2 tocks.empty_in_tocks, blast+)\nnext\n  fix x\n  assume assm1: \"\\<forall>t\\<in>P. \\<forall>X t'. t \\<noteq> [X]\\<^sub>R # t'\"\n  assume assm2: \"x \\<in> Q\"\n  assume assm3: \"\\<forall>t' X. x \\<noteq> [X]\\<^sub>R # t'\"\n\n  obtain y where y_in_P: \"y \\<in> P\"\n    using TT0_P TT0_def by auto\n  have 1: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C y \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C []\"\n    by (metis y_in_P append_Cons assm1 tocks.simps tt_prefix.simps(1) tt_prefix_split)\n  have 2: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C x \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C []\"\n    by (metis append_Cons assm3 split_tocks_longest tocks.simps)\n  have 3: \"\\<forall>X. y = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. x = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n    using assm1 y_in_P by blast\n  have 4: \"\\<forall>X. x = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. y = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n    by (simp add: assm3)\n  show \"\\<exists>\\<rho>\\<in>tocks UNIV. \\<exists>\\<sigma>. \\<rho> @ \\<sigma> \\<in> P \\<and> (\\<exists>\\<tau>. \\<rho> @ \\<tau> \\<in> Q \\<and>\n      (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n      (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n      (\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n      (\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and> (x = \\<rho> @ \\<sigma> \\<or> x = \\<rho> @ \\<tau>))\"\n    using y_in_P 1 2 3 4 by (rule_tac x=\"[]\" in bexI, auto, insert assm2, blast, meson tocks.simps)\nqed\n\nlemma ExtChoiceTT_wf: \"\\<forall> t\\<in>P. ttWF t \\<Longrightarrow> \\<forall> t\\<in>Q. ttWF t \\<Longrightarrow> \\<forall> t\\<in>P \\<box>\\<^sub>C Q. ttWF t\"\n  unfolding ExtChoiceTT_def by auto\n\nlemma TT0_ExtChoice:\n  assumes \"TT P\" \"TT Q\"\n  shows \"TT0 (P \\<box>\\<^sub>C Q)\"\n  unfolding TT0_def apply auto\n  unfolding ExtChoiceTT_def apply auto\n  using TT_empty assms(1) assms(2) tocks.empty_in_tocks by fastforce\n\nlemma TT1_ExtChoice:\n  assumes \"TT P\" \"TT Q\"\n  shows \"TT1 (P \\<box>\\<^sub>C Q)\"\n  unfolding TT1_def\nproof auto\n  fix \\<rho> \\<sigma> :: \"'a ttobs list\"\n  assume assm1: \"\\<rho> \\<lesssim>\\<^sub>C \\<sigma>\"\n  assume assm2: \"\\<sigma> \\<in> P \\<box>\\<^sub>C Q\"\n  obtain \\<rho>2 where \\<rho>2_assms: \"\\<rho>2 \\<le>\\<^sub>C \\<sigma>\" \"\\<rho> \\<subseteq>\\<^sub>C \\<rho>2\"\n    using assm1 tt_prefix_subset_imp_tt_subset_tt_prefix by auto\n  from assm2 obtain \\<sigma>' s t where assm2_assms:\n    \"\\<sigma>'\\<in>tocks UNIV\"\n    \"\\<sigma>' @ s \\<in> P\"\n    \"\\<sigma>' @ t \\<in> Q\"\n    \"(\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<sigma>' @ s \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<sigma>')\"\n    \"(\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<sigma>' @ t \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<sigma>')\"\n    \"\\<forall>X. s = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. t = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n    \"\\<forall>X. t = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. s = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n    \"\\<sigma> = \\<sigma>' @ t \\<or> \\<sigma> = \\<sigma>' @ s\"\n    unfolding ExtChoiceTT_def by blast\n  from assm2_assms(8) have \"\\<rho>2 \\<in> P \\<box>\\<^sub>C Q\"\n  proof (auto)\n    assume case_assm: \"\\<sigma> = \\<sigma>' @ s\"\n    then have \\<sigma>_in_P: \"\\<sigma> \\<in> P\"\n      using assm2_assms(2) by blast\n    have \\<rho>2_in_P: \"\\<rho>2 \\<in> P\"\n      using TT1_def TT_TT1 \\<rho>2_assms(1) \\<sigma>_in_P assms(1) tt_prefix_imp_prefix_subset by blast\n    have \"\\<rho>2 \\<le>\\<^sub>C \\<sigma>' \\<or> (\\<exists> \\<rho>2'. \\<rho>2 = \\<sigma>' @ \\<rho>2' \\<and> \\<rho>2' \\<le>\\<^sub>C s)\"\n      using \\<rho>2_assms(1) case_assm tt_prefix_append_split by blast\n    then show \"\\<rho>2 \\<in> P \\<box>\\<^sub>C Q\"\n    proof auto\n      assume case_assm2: \"\\<rho>2 \\<le>\\<^sub>C \\<sigma>'\"\n      have \\<rho>2_in_Q: \"\\<rho>2 \\<in> Q\"\n        by (meson TT1_def TT_TT1 assm2_assms(3) assms(2) case_assm2 tt_prefix_concat tt_prefix_imp_prefix_subset)\n      obtain \\<rho>' where \\<rho>'_assms: \"\\<rho>' \\<in> tocks UNIV\" \"\\<rho>2 = \\<rho>' \\<or> (\\<exists>Y. \\<rho>2 = \\<rho>' @ [[Y]\\<^sub>R])\"\n        using case_assm2 assm2_assms(1) tt_prefix_tocks by blast\n      then show \"\\<rho>2 \\<in> P \\<box>\\<^sub>C Q\"\n      proof auto\n        assume case_assm3: \"\\<rho>2 = \\<rho>'\"\n        then show \"\\<rho>' \\<in> P \\<box>\\<^sub>C Q\"\n          using \\<rho>2_in_P \\<rho>2_in_Q case_assm3 \\<rho>'_assms(1) unfolding ExtChoiceTT_def apply auto\n          apply (rule_tac x=\"\\<rho>'\" in bexI, auto)\n          apply (rule_tac x=\"[]\" in exI, auto)\n          apply (rule_tac x=\"[]\" in exI, auto)\n          done\n      next\n        fix Y\n        assume case_assm3: \"\\<rho>2 = \\<rho>' @ [[Y]\\<^sub>R]\"\n        then show \"\\<rho>' @ [[Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n          using \\<rho>2_in_P \\<rho>2_in_Q \\<rho>'_assms(1) unfolding ExtChoiceTT_def apply auto\n          apply (rule_tac x=\"\\<rho>'\" in bexI, auto)\n          apply (rule_tac x=\"[[Y]\\<^sub>R]\" in exI, auto)\n          apply (rule_tac x=\"[[Y]\\<^sub>R]\" in exI, auto)\n          by (metis butlast_append butlast_snoc tt_prefix_concat tt_prefix_decompose end_refusal_notin_tocks)\n      qed\n    next\n      fix \\<rho>2'\n      assume case_assm2: \"\\<rho>2' \\<le>\\<^sub>C s\"\n      assume case_assm3: \"\\<rho>2 = \\<sigma>' @ \\<rho>2'\"\n      have in_P: \"\\<sigma>' @ \\<rho>2' \\<in> P\"\n        using TT1_def TT_TT1 \\<rho>2_assms(1) assm2_assms(2) assms(1) case_assm case_assm3 tt_prefix_imp_prefix_subset by blast\n      show \"\\<sigma>' @ \\<rho>2' \\<in> P \\<box>\\<^sub>C Q\"\n      proof (cases \"\\<exists>X. \\<rho>2' = [[X]\\<^sub>R]\", auto)\n        fix X\n        assume case_assm4: \"\\<rho>2' = [[X]\\<^sub>R]\"\n        then have case_assm5: \"s = [[X]\\<^sub>R]\"\n          using case_assm2\n        proof -\n          have \"ttWF s\"\n            using TT_wf assm2_assms(1) assm2_assms(2) assms(1) tocks_append_wf2 by fastforce\n          then show \"\\<rho>2' = [[X]\\<^sub>R] \\<Longrightarrow> \\<rho>2' \\<le>\\<^sub>C s \\<Longrightarrow> s = [[X]\\<^sub>R]\"\n            apply (cases s rule:ttWF.cases, auto, insert assm2_assms(1) assm2_assms(4))\n            apply (erule_tac x=\"\\<sigma>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\" in ballE, auto simp add: tt_prefix_same_front)\n            using tt_prefix_antisym tt_prefix_concat apply blast\n            apply (induct \\<sigma>', auto simp add: tocks.tock_insert_in_tocks)\n            by (metis append_Cons subset_UNIV tocks.empty_in_tocks tocks.tock_insert_in_tocks tocks_append_tocks)\n        qed\n        thm assm2_assms\n        then obtain Y where \"t = [[Y]\\<^sub>R]\" \"\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock\"\n          using assm2_assms(6) by auto\n        then have \"\\<sigma>' @ [[{e\\<in>X. e \\<noteq> Tock}]\\<^sub>R] \\<in> Q\"\n        proof -\n          assume \"t = [[Y]\\<^sub>R]\"\n          then have \"\\<sigma>' @ [[Y]\\<^sub>R] \\<in> Q\"\n            using assm2_assms(3) by auto\n          also assume \"\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock\"\n          then have \"\\<sigma>' @ [[{e\\<in>X. e \\<noteq> Tock}]\\<^sub>R] \\<lesssim>\\<^sub>C \\<sigma>' @ [[Y]\\<^sub>R]\"\n            using tt_prefix_subset_same_front[where r=\\<sigma>'] by auto\n          then show \"\\<sigma>' @ [[{e\\<in>X. e \\<noteq> Tock}]\\<^sub>R] \\<in> Q\"\n            using calculation TT1_def TT_TT1 assms(2) by blast\n        qed\n        then show \"\\<sigma>' @ [[X]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n          unfolding ExtChoiceTT_def apply auto\n          apply (rule_tac x=\"\\<sigma>'\" in bexI, simp_all add: assm2_assms(1))\n          apply (rule_tac x=\"[[X]\\<^sub>R]\" in exI, insert in_P case_assm4, simp)\n          apply (rule_tac x=\"[[{e\\<in>X. e \\<noteq> Tock}]\\<^sub>R]\" in exI, insert assm2_assms(4) case_assm5, auto)\n          by (metis (no_types, lifting) butlast_append butlast_snoc tt_prefix_concat tt_prefix_decompose end_refusal_notin_tocks)\n      next\n        have \\<sigma>'_in_Q: \"\\<sigma>' \\<in> Q\"\n          using TT1_def TT_TT1 assm2_assms(3) assms(2) tt_prefix_concat tt_prefix_imp_prefix_subset by blast\n        then show \"\\<forall>X. \\<rho>2' \\<noteq> [[X]\\<^sub>R] \\<Longrightarrow> \\<sigma>' @ \\<rho>2' \\<in> P \\<box>\\<^sub>C Q\"\n           unfolding ExtChoiceTT_def apply auto\n           apply (rule_tac x=\"\\<sigma>'\" in bexI, simp_all add: assm2_assms(1))\n           apply (rule_tac x=\"\\<rho>2'\" in exI, simp add: in_P)\n           apply (rule_tac x=\"[]\" in exI, auto)\n           using \\<rho>2_assms(1) assm2_assms(4) case_assm case_assm3 tt_prefix_trans by blast\n       qed\n     qed\n   next\n    assume case_assm: \"\\<sigma> = \\<sigma>' @ t\"\n    then have \\<sigma>_in_Q: \"\\<sigma> \\<in> Q\"\n      using assm2_assms(3) by blast\n    have \\<rho>2_in_Q: \"\\<rho>2 \\<in> Q\"\n      using TT1_def TT_TT1 \\<rho>2_assms(1) \\<sigma>_in_Q assms(2) tt_prefix_imp_prefix_subset by blast\n    have \"\\<rho>2 \\<le>\\<^sub>C \\<sigma>' \\<or> (\\<exists> \\<rho>2'. \\<rho>2 = \\<sigma>' @ \\<rho>2' \\<and> \\<rho>2' \\<le>\\<^sub>C t)\"\n      using \\<rho>2_assms(1) case_assm tt_prefix_append_split by blast\n    then show \"\\<rho>2 \\<in> P \\<box>\\<^sub>C Q\"\n    proof auto\n      assume case_assm2: \"\\<rho>2 \\<le>\\<^sub>C \\<sigma>'\"\n      have \\<rho>2_in_P: \"\\<rho>2 \\<in> P\"\n        by (meson TT1_def TT_TT1 assm2_assms(2) assms(1) case_assm2 tt_prefix_concat tt_prefix_imp_prefix_subset)\n      obtain \\<rho>' where \\<rho>'_assms: \"\\<rho>' \\<in> tocks UNIV\" \"\\<rho>2 = \\<rho>' \\<or> (\\<exists>Y. \\<rho>2 = \\<rho>' @ [[Y]\\<^sub>R])\"\n        using case_assm2 assm2_assms(1) tt_prefix_tocks by blast\n      then show \"\\<rho>2 \\<in> P \\<box>\\<^sub>C Q\"\n      proof auto\n        assume case_assm3: \"\\<rho>2 = \\<rho>'\"\n        then show \"\\<rho>' \\<in> P \\<box>\\<^sub>C Q\"\n          using \\<rho>2_in_P \\<rho>2_in_Q case_assm3 \\<rho>'_assms(1) unfolding ExtChoiceTT_def apply auto\n          apply (rule_tac x=\"\\<rho>'\" in bexI, auto)\n          apply (rule_tac x=\"[]\" in exI, auto)\n          apply (rule_tac x=\"[]\" in exI, auto)\n          done\n      next\n        fix Y\n        assume case_assm3: \"\\<rho>2 = \\<rho>' @ [[Y]\\<^sub>R]\"\n        then show \"\\<rho>' @ [[Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n          using \\<rho>2_in_P \\<rho>2_in_Q \\<rho>'_assms(1) unfolding ExtChoiceTT_def apply auto\n          apply (rule_tac x=\"\\<rho>'\" in bexI, auto)\n          apply (rule_tac x=\"[[Y]\\<^sub>R]\" in exI, auto)\n          apply (rule_tac x=\"[[Y]\\<^sub>R]\" in exI, auto)\n          by (metis butlast_append butlast_snoc tt_prefix_concat tt_prefix_decompose end_refusal_notin_tocks)\n      qed\n    next\n      fix \\<rho>2'\n      assume case_assm2: \"\\<rho>2' \\<le>\\<^sub>C t\"\n      assume case_assm3: \"\\<rho>2 = \\<sigma>' @ \\<rho>2'\"\n      have in_Q: \"\\<sigma>' @ \\<rho>2' \\<in> Q\"\n        using \\<rho>2_in_Q case_assm3 by blast\n      show \"\\<sigma>' @ \\<rho>2' \\<in> P \\<box>\\<^sub>C Q\"\n      proof (cases \"\\<exists>X. \\<rho>2' = [[X]\\<^sub>R]\", auto)\n        fix X\n        assume case_assm4: \"\\<rho>2' = [[X]\\<^sub>R]\"\n        then have case_assm5: \"t = [[X]\\<^sub>R]\"\n          using case_assm2\n        proof -\n          have \"ttWF t\"\n            using TT_wf assm2_assms(1) assm2_assms(3) assms(2) tocks_append_wf2 by fastforce\n          then show \"\\<rho>2' = [[X]\\<^sub>R] \\<Longrightarrow> \\<rho>2' \\<le>\\<^sub>C t \\<Longrightarrow> t = [[X]\\<^sub>R]\"\n            apply (cases t rule:ttWF.cases, auto, insert assm2_assms(1) assm2_assms(5))\n            apply (erule_tac x=\"\\<sigma>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\" in ballE, auto simp add: tt_prefix_same_front)\n            using tt_prefix_antisym tt_prefix_concat apply blast\n            apply (induct \\<sigma>', auto simp add: tocks.tock_insert_in_tocks)\n            by (metis append_Cons subset_UNIV tocks.empty_in_tocks tocks.tock_insert_in_tocks tocks_append_tocks)\n        qed\n        then obtain Y where \"s = [[Y]\\<^sub>R]\" \"\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock\"\n          using assm2_assms(7) by auto\n        then have \"\\<sigma>' @ [[{e\\<in>X. e \\<noteq> Tock}]\\<^sub>R] \\<in> P\"\n        proof -\n          assume \"s = [[Y]\\<^sub>R]\"\n          then have \"\\<sigma>' @ [[Y]\\<^sub>R] \\<in> P\"\n            using assm2_assms(2) by auto\n          also assume \"\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock\"\n          then have \"\\<sigma>' @ [[{e\\<in>X. e \\<noteq> Tock}]\\<^sub>R] \\<lesssim>\\<^sub>C \\<sigma>' @ [[Y]\\<^sub>R]\"\n            using tt_prefix_subset_same_front[where r=\\<sigma>'] by auto\n          then show \"\\<sigma>' @ [[{e\\<in>X. e \\<noteq> Tock}]\\<^sub>R] \\<in> P\"\n            using calculation TT1_def TT_TT1 assms(1) by blast\n        qed\n        then show \"\\<sigma>' @ [[X]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n          unfolding ExtChoiceTT_def apply auto\n          apply (rule_tac x=\"\\<sigma>'\" in bexI, simp_all add: assm2_assms(1))\n          apply (rule_tac x=\"[[{e\\<in>X. e \\<noteq> Tock}]\\<^sub>R]\" in exI, insert assm2_assms(4) case_assm5, auto)\n          apply (rule_tac x=\"[[X]\\<^sub>R]\" in exI, insert in_Q case_assm4 assm2_assms(5), auto)\n          by (metis (no_types, lifting) butlast_append butlast_snoc tt_prefix_concat tt_prefix_decompose end_refusal_notin_tocks)\n      next\n        have \\<sigma>'_in_P: \"\\<sigma>' \\<in> P\"\n          using TT1_def TT_TT1 assm2_assms(2) assms(1) tt_prefix_concat tt_prefix_imp_prefix_subset by blast\n        then show \"\\<forall>X. \\<rho>2' \\<noteq> [[X]\\<^sub>R] \\<Longrightarrow> \\<sigma>' @ \\<rho>2' \\<in> P \\<box>\\<^sub>C Q\"\n           unfolding ExtChoiceTT_def apply auto\n           apply (rule_tac x=\"\\<sigma>'\" in bexI, simp_all add: assm2_assms(1))\n           apply (rule_tac x=\"[]\" in exI, auto)\n           apply (rule_tac x=\"\\<rho>2'\" in exI, simp add: in_Q)\n           using \\<rho>2_assms(1) assm2_assms(5) case_assm case_assm3 tt_prefix_trans by blast\n       qed\n     qed\n   qed\n   then obtain \\<rho>2' s2 t2 where \\<rho>2_split:\n     \"\\<rho>2'\\<in>tocks UNIV\"\n     \"\\<rho>2' @ s2 \\<in> P\"\n     \"\\<rho>2' @ t2 \\<in> Q\"\n     \"(\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho>2' @ s2 \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>2')\"\n     \"(\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho>2' @ t2 \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>2')\"\n     \"\\<forall>X. s2 = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. t2 = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n     \"\\<forall>X. t2 = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. s2 = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n     \"\\<rho>2 = \\<rho>2' @ t2 \\<or> \\<rho>2 = \\<rho>2' @ s2\"\n    unfolding ExtChoiceTT_def by blast\n  then show \"\\<rho> \\<in>  P \\<box>\\<^sub>C Q\"\n  proof auto\n    assume case_assm: \"\\<rho>2 = \\<rho>2' @ t2\"\n    have \\<rho>_wf: \"ttWF \\<rho>\"\n      using TT1_def TT_TT1 TT_wf \\<rho>2_assms(2) \\<rho>2_split(3) assms(2) case_assm tt_subset_imp_prefix_subset by blast\n    then obtain \\<rho>' \\<rho>'' where \\<rho>'_\\<rho>''_assms:\n      \"\\<rho> = \\<rho>' @ \\<rho>''\"\n      \"\\<rho>' \\<in> tocks UNIV\"\n      \"\\<forall>t\\<in>tocks UNIV. t \\<le>\\<^sub>C \\<rho>' @ \\<rho>'' \\<longrightarrow> t \\<le>\\<^sub>C \\<rho>'\"\n      by (metis split_tocks_longest)\n    then have \\<rho>'_\\<rho>''_tt_subset: \"\\<rho>' \\<subseteq>\\<^sub>C \\<rho>2' \\<and> \\<rho>'' \\<subseteq>\\<^sub>C t2\"\n      using TT_wf \\<rho>_wf \\<rho>2_assms(2) \\<rho>2_split(1) \\<rho>2_split(3) \\<rho>2_split(5) assms(2) case_assm tt_subset_longest_tocks by blast\n    then have \\<rho>'_in_P_Q: \"\\<rho>' \\<in> P \\<and> \\<rho>' \\<in> Q\"\n      by (meson TT_TT1 TT_defs(3) \\<rho>2_split(2) \\<rho>2_split(3) assms(1) assms(2) tt_prefix_concat tt_prefix_subset_tt_prefix_trans tt_subset_imp_prefix_subset)\n    show \"\\<rho> \\<in> P \\<box>\\<^sub>C Q\"\n    proof (cases \"\\<exists> X. t2 = [[X]\\<^sub>R]\")\n      assume case_assm2: \"\\<exists> X. t2 = [[X]\\<^sub>R]\"\n      then obtain X where t2_def: \"t2 = [[X]\\<^sub>R]\"\n        by auto\n      then have \"\\<exists> Y. Y \\<subseteq> X \\<and> \\<rho>'' = [[Y]\\<^sub>R]\"\n        using \\<rho>'_\\<rho>''_tt_subset apply (simp, induct \\<rho>'' t2 rule:tt_subset.induct, simp_all)\n        using tt_subset_same_length by force\n      then obtain Y where Y_assms: \"Y \\<subseteq> X \\<and> \\<rho>'' = [[Y]\\<^sub>R]\"\n        by auto\n      then obtain Z where Z_assms: \"s2 = [[Z]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Z) \\<or> e = Tock)\"\n        using t2_def \\<rho>2_split(7) by blast\n      then have \"{e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<subseteq> Z\"\n        using Y_assms by blast\n      then have 1: \"\\<rho>' @ [[{e. e \\<in> Y \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<subseteq>\\<^sub>C \\<rho>2' @ [[Z]\\<^sub>R]\"\n        by (simp add: \\<rho>'_\\<rho>''_tt_subset tt_subset_combine)\n      have 2: \"\\<rho>' @ [[Y]\\<^sub>R] \\<subseteq>\\<^sub>C \\<rho>2' @ [[X]\\<^sub>R]\"\n        using Y_assms \\<rho>'_\\<rho>''_assms(1) \\<rho>2_assms(2) case_assm t2_def by blast\n      have 3: \"\\<rho>' @ [[{e. e \\<in> Y \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> P\"\n        using \"1\" TT1_def TT_TT1 Z_assms \\<rho>2_split(2) assms(1) tt_subset_imp_prefix_subset by blast\n      have 4: \"\\<rho>' @ [[Y]\\<^sub>R] \\<in> Q\"\n        using \"2\" TT1_def TT_TT1 \\<rho>2_split(3) assms(2) tt_subset_imp_prefix_subset t2_def by blast\n      then show \"\\<rho> \\<in> P \\<box>\\<^sub>C Q\"\n        unfolding ExtChoiceTT_def apply auto\n        apply (rule_tac x=\"\\<rho>'\" in bexI, auto simp add: \\<rho>'_\\<rho>''_assms)\n        apply (rule_tac x=\"[[{e. e \\<in> Y \\<and> e \\<noteq> Tock}]\\<^sub>R]\" in exI, auto simp add: 3)\n        apply (rule_tac x=\"[[Y]\\<^sub>R]\" in exI, auto simp add: 4 Y_assms)\n        apply (metis (no_types, lifting) butlast_append butlast_snoc tt_prefix_concat tt_prefix_decompose end_refusal_notin_tocks)\n        by (simp add: Y_assms \\<rho>'_\\<rho>''_assms(3))\n    next\n      assume \"\\<nexists>X. t2 = [[X]\\<^sub>R]\"\n      then have \"\\<nexists>X. \\<rho>'' = [[X]\\<^sub>R]\"\n        using \\<rho>'_\\<rho>''_tt_subset by (auto, cases t2 rule:ttWF.cases, auto)\n      then show \"\\<rho> \\<in> P \\<box>\\<^sub>C Q\"\n        unfolding ExtChoiceTT_def apply auto\n        apply (rule_tac x=\"\\<rho>'\" in bexI, auto simp add: \\<rho>'_\\<rho>''_assms)\n        apply (rule_tac x=\"[]\" in exI, auto simp add: \\<rho>'_in_P_Q)\n        apply (rule_tac x=\"\\<rho>''\" in exI, auto)\n        using TT1_def TT_TT1 \\<rho>'_\\<rho>''_assms(1) \\<rho>2_assms(2) \\<rho>2_split(3) assms(2) case_assm tt_subset_imp_prefix_subset apply blast\n        using \\<rho>'_\\<rho>''_assms(3) by blast\n    qed\n  next\n    assume case_assm: \"\\<rho>2 = \\<rho>2' @ s2\"\n    have \\<rho>_wf: \"ttWF \\<rho>\"\n      by (metis TT_def ExtChoiceTT_wf assm1 assm2 assms(1) assms(2) tt_prefix_subset_ttWF)\n    then obtain \\<rho>' \\<rho>'' where \\<rho>'_\\<rho>''_assms:\n      \"\\<rho> = \\<rho>' @ \\<rho>''\"\n      \"\\<rho>' \\<in> tocks UNIV\"\n      \"\\<forall>t\\<in>tocks UNIV. t \\<le>\\<^sub>C \\<rho>' @ \\<rho>'' \\<longrightarrow> t \\<le>\\<^sub>C \\<rho>'\"\n      by (metis split_tocks_longest)\n    then have \\<rho>'_\\<rho>''_tt_subset: \"\\<rho>' \\<subseteq>\\<^sub>C \\<rho>2' \\<and> \\<rho>'' \\<subseteq>\\<^sub>C s2\"\n      using TT_wf \\<rho>2_assms(2) \\<rho>2_split(1) \\<rho>2_split(2) \\<rho>2_split(4) \\<rho>_wf assms(1) case_assm tt_subset_longest_tocks by blast\n    then have \\<rho>'_in_P_Q: \"\\<rho>' \\<in> P \\<and> \\<rho>' \\<in> Q\"\n      by (meson TT_TT1 TT_defs(3) \\<rho>2_split(2) \\<rho>2_split(3) assms(1) assms(2) tt_prefix_concat tt_prefix_subset_tt_prefix_trans tt_subset_imp_prefix_subset)\n    show \"\\<rho> \\<in> P \\<box>\\<^sub>C Q\"\n    proof (cases \"\\<exists> X. s2 = [[X]\\<^sub>R]\")\n      assume case_assm2: \"\\<exists> X. s2 = [[X]\\<^sub>R]\"\n      then obtain X where s2_def: \"s2 = [[X]\\<^sub>R]\"\n        by auto\n      then have \"\\<exists> Y. Y \\<subseteq> X \\<and> \\<rho>'' = [[Y]\\<^sub>R]\"\n        using \\<rho>'_\\<rho>''_tt_subset apply (simp, induct \\<rho>'' s2 rule:tt_subset.induct, simp_all)\n        using tt_subset_same_length by force\n      then obtain Y where Y_assms: \"Y \\<subseteq> X \\<and> \\<rho>'' = [[Y]\\<^sub>R]\"\n        by auto\n      then obtain Z where Z_assms: \"t2 = [[Z]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Z) \\<or> e = Tock)\"\n        using s2_def \\<rho>2_split(6) by blast\n      then have \"{e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<subseteq> Z\"\n        using Y_assms by blast\n      then have 1: \"\\<rho>' @ [[{e. e \\<in> Y \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<subseteq>\\<^sub>C \\<rho>2' @ [[Z]\\<^sub>R]\"\n        by (simp add: \\<rho>'_\\<rho>''_tt_subset tt_subset_combine)\n      have 2: \"\\<rho>' @ [[Y]\\<^sub>R] \\<subseteq>\\<^sub>C \\<rho>2' @ [[X]\\<^sub>R]\"\n        using Y_assms \\<rho>'_\\<rho>''_assms(1) \\<rho>2_assms(2) case_assm s2_def by blast\n      have 3: \"\\<rho>' @ [[{e. e \\<in> Y \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> Q\"\n        using \"1\" TT1_def TT_TT1 Z_assms \\<rho>2_split(3) assms(2) tt_subset_imp_prefix_subset by blast\n      have 4: \"\\<rho>' @ [[Y]\\<^sub>R] \\<in> P\"\n        using \"2\" TT1_def TT_TT1 \\<rho>2_split(2) assms(1) tt_subset_imp_prefix_subset s2_def by blast\n      then show \"\\<rho> \\<in> P \\<box>\\<^sub>C Q\"\n        unfolding ExtChoiceTT_def apply auto\n        apply (rule_tac x=\"\\<rho>'\" in bexI, auto simp add: \\<rho>'_\\<rho>''_assms)\n        apply (rule_tac x=\"[[Y]\\<^sub>R]\" in exI, auto simp add: 4 Y_assms)\n        apply (rule_tac x=\"[[{e. e \\<in> Y \\<and> e \\<noteq> Tock}]\\<^sub>R]\" in exI, auto simp add: 3)\n        using Y_assms \\<rho>'_\\<rho>''_assms(3) apply blast\n        by (metis (no_types, lifting) butlast_append butlast_snoc tt_prefix_concat tt_prefix_decompose end_refusal_notin_tocks)\n    next\n      assume \"\\<nexists>X. s2 = [[X]\\<^sub>R]\"\n      then have \"\\<nexists>X. \\<rho>'' = [[X]\\<^sub>R]\"\n        using \\<rho>'_\\<rho>''_tt_subset by (auto, cases s2 rule:ttWF.cases, auto)\n      then show \"\\<rho> \\<in> P \\<box>\\<^sub>C Q\"\n        unfolding ExtChoiceTT_def apply auto\n        apply (rule_tac x=\"\\<rho>'\" in bexI, auto simp add: \\<rho>'_\\<rho>''_assms)\n        apply (rule_tac x=\"\\<rho>''\" in exI, auto)\n        using TT1_def TT_TT1 \\<rho>'_\\<rho>''_assms(1) \\<rho>2_assms(2) \\<rho>2_split(2) assms(1) case_assm tt_subset_imp_prefix_subset apply blast\n        apply (rule_tac x=\"[]\" in exI, auto simp add: \\<rho>'_in_P_Q)\n        using \\<rho>'_\\<rho>''_assms(3) by blast\n    qed\n  qed\nqed\n\nlemma TT2w_ExtChoice:\n  assumes \"TT P\" \"TT Q\"\n  shows \"TT2w (P \\<box>\\<^sub>C Q)\"\n  unfolding TT2w_def\nproof auto\n  fix \\<rho> :: \"'a ttobs list\"\n  fix X Y :: \"'a ttevent set\"\n  assume assm1: \"\\<rho> @ [[X]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n  assume assm2: \"Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q} = {}\"\n  from assm1 have \"ttWF \\<rho>\"\n    by (metis TT_def ExtChoiceTT_wf assms(1) assms(2) tt_prefix_concat tt_prefix_imp_prefix_subset tt_prefix_subset_ttWF)\n  then obtain \\<rho>' \\<rho>'' where \\<rho>_split: \"\\<rho>'\\<in>tocks UNIV \\<and> \\<rho> = \\<rho>' @ \\<rho>'' \\<and> (\\<forall>t'\\<in>tocks UNIV. t' \\<le>\\<^sub>C \\<rho> \\<longrightarrow> t' \\<le>\\<^sub>C \\<rho>')\"\n    using split_tocks_longest by blast\n  have \\<rho>'_in_P_Q: \"\\<rho>' \\<in> P \\<and> \\<rho>' \\<in> Q\"\n    using assm1 unfolding ExtChoiceTT_def apply auto\n    apply (metis TT1_def TT_TT1 \\<rho>_split assms(1) tt_prefix_concat tt_prefix_imp_prefix_subset)\n    apply (metis TT1_def TT_TT1 \\<rho>_split append.assoc assms(2) tt_prefix_concat tt_prefix_imp_prefix_subset)\n    apply (metis TT1_def TT_TT1 \\<rho>_split append.assoc assms(1) tt_prefix_concat tt_prefix_imp_prefix_subset)\n    by (metis TT1_def TT_TT1 \\<rho>_split assms(2) tt_prefix_concat tt_prefix_imp_prefix_subset)\n  have set1: \"{e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q} = {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P} \\<union> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q}\"\n  proof auto\n    fix x :: \"'a ttevent\"\n    assume \"\\<rho> @ [[x]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\"\n    then have \"\\<rho> @ [[x]\\<^sub>E] \\<in> P \\<or> \\<rho> @ [[x]\\<^sub>E] \\<in> Q\"\n      unfolding ExtChoiceTT_def by auto\n    then show \"\\<rho> @ [[x]\\<^sub>E] \\<notin> Q \\<Longrightarrow> \\<rho> @ [[x]\\<^sub>E] \\<in> P\"\n      by auto\n  next\n    fix x :: \"'a ttevent\"\n    assume \"x \\<noteq> Tock\" \"\\<rho> @ [[x]\\<^sub>E] \\<in> P\"\n    then show \"\\<rho> @ [[x]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\"\n      unfolding ExtChoiceTT_def apply auto\n      apply (rule_tac x=\"\\<rho>'\" in bexI, simp_all add: \\<rho>_split)\n      apply (rule_tac x=\"\\<rho>'' @ [[x]\\<^sub>E]\" in exI, simp_all)\n      apply (rule_tac x=\"[]\" in exI, simp add: \\<rho>'_in_P_Q)\n      apply (auto, case_tac \"\\<rho>''' \\<le>\\<^sub>C \\<rho>' @ \\<rho>''\")\n      using \\<rho>_split apply blast\n      by (metis append.assoc append_Cons append_Nil tt_prefix_notfront_is_whole ttevent.exhaust end_event_notin_tocks mid_tick_notin_tocks)\n  next\n    fix x :: \"'a ttevent\"\n    assume \"x \\<noteq> Tock\" \"\\<rho> @ [[x]\\<^sub>E] \\<in> Q\"\n    then show \"\\<rho> @ [[x]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\"\n      unfolding ExtChoiceTT_def apply auto\n      apply (rule_tac x=\"\\<rho>'\" in bexI, simp_all add: \\<rho>_split)\n      apply (rule_tac x=\"[]\" in exI, simp add: \\<rho>'_in_P_Q)\n      apply (auto, case_tac \"\\<rho>''' \\<le>\\<^sub>C \\<rho>' @ \\<rho>''\")\n      using \\<rho>_split apply blast\n      by (metis append.assoc append_Cons append_Nil tt_prefix_notfront_is_whole ttevent.exhaust end_event_notin_tocks mid_tick_notin_tocks)\n  qed\n  have set2: \"{e. e = Tock \\<and> \\<rho>'' = [] \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q} = \n    {e. e = Tock \\<and> \\<rho>'' = [] \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} \\<inter> {e. e = Tock \\<and> \\<rho>'' = [] \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q}\"\n  proof auto\n    assume case_assms: \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\" \"\\<rho>'' = []\"\n    then have \"\\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\"\n      by (simp add: \\<rho>_split)\n    then obtain r s t where rst_assms: \n      \"r \\<in> tocks UNIV\"\n      \"r @ s \\<in> P\"\n      \"r @ t \\<in> Q\"\n      \"\\<forall>x\\<in>tocks UNIV. x \\<le>\\<^sub>C r @ s \\<longrightarrow> x \\<le>\\<^sub>C r\"\n      \"\\<forall>x\\<in>tocks UNIV. x \\<le>\\<^sub>C r @ t \\<longrightarrow> x \\<le>\\<^sub>C r\"\n      \"(\\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] = r @ s \\<or> \\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] = r @ t)\"\n      unfolding ExtChoiceTT_def by auto\n    have in_tocks: \"\\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> tocks UNIV\"\n      by (simp add: \\<rho>_split tocks.empty_in_tocks tocks.tock_insert_in_tocks tocks_append_tocks)\n    then have r_def: \"r = \\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n      using tt_prefix_refl rst_assms(4) rst_assms(5) rst_assms(6) self_extension_tt_prefix by fastforce\n    then have \"r \\<in> P \\<and> r \\<in> Q\"\n      by (smt TT1_def TT_TT1 rst_assms assms(1) assms(2) tt_prefix_concat tt_prefix_imp_prefix_subset in_tocks rst_assms(4))\n    then show \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P\"\n      by (simp add: r_def \\<rho>_split case_assms(2))\n  next\n    assume case_assms: \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\" \"\\<rho>'' = []\"\n    then have \"\\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\"\n      by (simp add: \\<rho>_split)\n    then obtain r s t where rst_assms: \n      \"r \\<in> tocks UNIV\"\n      \"r @ s \\<in> P\"\n      \"r @ t \\<in> Q\"\n      \"\\<forall>x\\<in>tocks UNIV. x \\<le>\\<^sub>C r @ s \\<longrightarrow> x \\<le>\\<^sub>C r\"\n      \"\\<forall>x\\<in>tocks UNIV. x \\<le>\\<^sub>C r @ t \\<longrightarrow> x \\<le>\\<^sub>C r\"\n      \"(\\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] = r @ s \\<or> \\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] = r @ t)\"\n      unfolding ExtChoiceTT_def by auto\n    have in_tocks: \"\\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> tocks UNIV\"\n      by (simp add: \\<rho>_split tocks.empty_in_tocks tocks.tock_insert_in_tocks tocks_append_tocks)\n    then have r_def: \"r = \\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n      using tt_prefix_refl rst_assms(4) rst_assms(5) rst_assms(6) self_extension_tt_prefix by fastforce\n    then have \"r \\<in> P \\<and> r \\<in> Q\"\n      by (smt TT1_def TT_TT1 rst_assms assms(1) assms(2) tt_prefix_concat tt_prefix_imp_prefix_subset in_tocks rst_assms(4))\n    then show \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> Q\"\n      by (simp add: r_def \\<rho>_split case_assms(2))\n  next\n    assume case_assms: \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P\" \"\\<rho>'' = []\" \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> Q\"\n    then have \"\\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<and> \\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> Q\"\n      by (simp add: \\<rho>_split)\n    also have \"\\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> tocks UNIV\"\n      by (simp add: \\<rho>_split tocks.empty_in_tocks tocks.tock_insert_in_tocks tocks_append_tocks)\n    then show \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\"\n      unfolding ExtChoiceTT_def apply auto\n      apply (rule_tac x=\"\\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\" in bexI, simp_all)\n      apply (rule_tac x=\"[]\" in exI, simp_all add: calculation)\n      apply (rule_tac x=\"[]\" in exI, simp_all add: calculation)\n      by (simp add: \\<rho>_split case_assms(2))\n  qed\n  have set3: \"{e. e = Tock \\<and> \\<rho>'' \\<noteq> [] \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q} = \n    {e. e = Tock \\<and> \\<rho>'' \\<noteq> [] \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} \\<union> {e. e = Tock \\<and> \\<rho>'' \\<noteq> [] \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q}\"\n  proof auto\n    assume \"\\<rho>'' \\<noteq> []\" \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\"\n    then show \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<notin> Q \\<Longrightarrow> \\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P\"\n      unfolding ExtChoiceTT_def by auto\n  next\n    assume \\<rho>''_nonempty: \"\\<rho>'' \\<noteq> []\"\n    assume in_P: \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P\"\n    have full_notin_tocks: \"\\<rho>' @ \\<rho>'' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<notin> tocks UNIV\"\n        by (metis \\<rho>''_nonempty \\<rho>_split append.assoc tt_prefix_refl nontocks_append_tocks self_extension_tt_prefix tocks.empty_in_tocks tocks.tock_insert_in_tocks top_greatest)\n    have \"\\<forall>x\\<in>tocks UNIV. x \\<le>\\<^sub>C \\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<longrightarrow> x \\<le>\\<^sub>C \\<rho>'\"\n    proof (auto simp add: \\<rho>_split)\n      fix x :: \"'a ttobs list\"\n      assume x_in_tocks: \"x \\<in> tocks UNIV\"\n      assume \"x \\<le>\\<^sub>C \\<rho>' @ \\<rho>'' @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n      also have \"\\<And> y. x \\<le>\\<^sub>C y @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<Longrightarrow> x \\<le>\\<^sub>C y \\<or> x = y @ [[X]\\<^sub>R] \\<or> x = y @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n      proof -\n        fix y\n        show \"x \\<le>\\<^sub>C y @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<Longrightarrow> x \\<le>\\<^sub>C y \\<or> x = y @ [[X]\\<^sub>R] \\<or> x = y @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n          using tt_prefix.elims(2) tt_prefix_antisym by (induct x y rule:tt_prefix.induct, auto, fastforce)\n      qed\n      then have \"x \\<le>\\<^sub>C \\<rho>' @ \\<rho>'' \\<or> x = \\<rho>' @ \\<rho>'' @ [[X]\\<^sub>R] \\<or> x = \\<rho>' @ \\<rho>'' @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n        using calculation by force\n      then show \"x \\<le>\\<^sub>C \\<rho>'\"\n        apply auto\n        apply (simp add: \\<rho>_split x_in_tocks)\n        apply (metis append_assoc end_refusal_notin_tocks x_in_tocks)\n        using full_notin_tocks x_in_tocks by blast\n    qed\n    then show \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\"\n      unfolding ExtChoiceTT_def apply auto\n      apply (rule_tac x=\"\\<rho>'\" in bexI, auto simp add: \\<rho>_split)\n      apply (rule_tac x=\"\\<rho>'' @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\" in exI, insert \\<rho>_split in_P, auto)\n      apply (rule_tac x=\"[]\" in exI, auto simp add: \\<rho>'_in_P_Q)\n      done\n  next\n    assume \\<rho>''_nonempty: \"\\<rho>'' \\<noteq> []\"\n    assume in_Q: \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> Q\"\n    have full_notin_tocks: \"\\<rho>' @ \\<rho>'' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<notin> tocks UNIV\"\n        by (metis \\<rho>''_nonempty \\<rho>_split append.assoc tt_prefix_refl nontocks_append_tocks self_extension_tt_prefix tocks.empty_in_tocks tocks.tock_insert_in_tocks top_greatest)\n    have \"\\<forall>x\\<in>tocks UNIV. x \\<le>\\<^sub>C \\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<longrightarrow> x \\<le>\\<^sub>C \\<rho>'\"\n    proof (auto simp add: \\<rho>_split)\n      fix x :: \"'a ttobs list\"\n      assume x_in_tocks: \"x \\<in> tocks UNIV\"\n      assume \"x \\<le>\\<^sub>C \\<rho>' @ \\<rho>'' @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n      also have \"\\<And> y. x \\<le>\\<^sub>C y @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<Longrightarrow> x \\<le>\\<^sub>C y \\<or> x = y @ [[X]\\<^sub>R] \\<or> x = y @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n      proof -\n        fix y\n        show \"x \\<le>\\<^sub>C y @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<Longrightarrow> x \\<le>\\<^sub>C y \\<or> x = y @ [[X]\\<^sub>R] \\<or> x = y @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n          using tt_prefix.elims(2) tt_prefix_antisym by (induct x y rule:tt_prefix.induct, auto, fastforce)\n      qed\n      then have \"x \\<le>\\<^sub>C \\<rho>' @ \\<rho>'' \\<or> x = \\<rho>' @ \\<rho>'' @ [[X]\\<^sub>R] \\<or> x = \\<rho>' @ \\<rho>'' @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n        using calculation by force\n      then show \"x \\<le>\\<^sub>C \\<rho>'\"\n        apply auto\n        apply (simp add: \\<rho>_split x_in_tocks)\n        apply (metis append_assoc end_refusal_notin_tocks x_in_tocks)\n        using full_notin_tocks x_in_tocks by blast\n    qed\n    then show \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\"\n      unfolding ExtChoiceTT_def apply auto\n      apply (rule_tac x=\"\\<rho>'\" in bexI, auto simp add: \\<rho>_split)\n      apply (rule_tac x=\"[]\" in exI, auto simp add: \\<rho>'_in_P_Q)\n      apply (insert \\<rho>_split in_Q, auto)\n      done\n  qed\n  thm set1 set2 set3\n  have in_P_or_Q: \"\\<rho> @ [[X]\\<^sub>R] \\<in> P \\<or> \\<rho> @ [[X]\\<^sub>R] \\<in> Q\"\n    using assm1 unfolding ExtChoiceTT_def by auto\n  show \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n  proof (cases \"\\<rho>'' \\<noteq> []\", auto)\n    assume case_assm: \"\\<rho>'' \\<noteq> []\"\n    have \"{e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q}\n      = {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} \\<union> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q}\"\n      (is \"?lhs = ?rhs\")\n    proof -\n      have \"?lhs = {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q} \\<union> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q}\"\n        by auto\n      also have \"... = {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P} \\<union> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q} \\<union> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q}\"\n        using set1 by auto\n      also have \"... = {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P} \\<union> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q} \\<union> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} \\<union> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q}\"\n        using set3 case_assm by auto\n      also have \"... = ?rhs\"\n        by auto\n      then show \"?lhs = ?rhs\"\n        using calculation by auto\n    qed\n    then have \n      \"(Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P})\n        \\<union> (Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q}) = {}\"\n      using assm2 inf_sup_distrib1 by auto\n    then have \"Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {}\n      \\<and> Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {}\"\n      by auto\n    then have \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<or> \\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> Q\"\n      using TT2w_def TT_def assms(1) assms(2) in_P_or_Q by auto\n    then show \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n      unfolding ExtChoiceTT_def apply auto\n      apply (rule_tac x=\"\\<rho>'\" in bexI, auto simp add: \\<rho>_split)\n      apply (rule_tac x=\"\\<rho>'' @ [[X \\<union> Y]\\<^sub>R]\" in exI, auto)\n      apply (rule_tac x=\"[]\" in exI, auto simp add: \\<rho>_split \\<rho>'_in_P_Q case_assm)\n      apply (metis \\<rho>_split append.assoc tt_prefix_notfront_is_whole end_refusal_notin_tocks)\n      apply (rule_tac x=\"\\<rho>'\" in bexI, auto simp add: \\<rho>_split)\n      apply (rule_tac x=\"[]\" in exI, auto simp add: \\<rho>_split \\<rho>'_in_P_Q case_assm)\n      apply (metis \\<rho>_split append.assoc tt_prefix_notfront_is_whole end_refusal_notin_tocks)\n      done\n  next\n    assume case_assm: \"\\<rho>'' = []\"\n    have \"\\<rho> @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<lesssim>\\<^sub>C \\<rho> @ [[X]\\<^sub>R]\"\n      by (induct \\<rho>, auto, case_tac a, auto)\n    then have \"\\<rho> @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n      using TT1_ExtChoice TT1_def assm1 assms(1) assms(2) by blast\n    then have \"\\<rho>' @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n      by (simp add: \\<rho>_split case_assm)\n    then have in_P_and_Q: \"\\<rho>' @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> P \\<and> \\<rho>' @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> Q\"\n      unfolding ExtChoiceTT_def\n    proof auto\n      fix \\<rho> \\<sigma> \\<tau> :: \"'a ttobs list\"\n      assume case_assm1: \"\\<rho> \\<in> tocks UNIV\"\n      assume case_assm2: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n      assume case_assm3: \"\\<rho>' @ [[{e \\<in> X. e \\<noteq> Tock}]\\<^sub>R] = \\<rho> @ \\<sigma>\"\n      assume case_assm4: \"\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n      assume case_assm5: \"\\<rho> @ \\<tau> \\<in> Q\"\n      have \\<rho>_def: \"\\<rho> = \\<rho>'\"\n        by (metis (no_types, lifting) \\<rho>_split butlast_append butlast_snoc case_assm1 case_assm2 case_assm3 tt_prefix_antisym tt_prefix_concat end_refusal_notin_tocks)\n      then have \\<sigma>_def: \"\\<sigma> = [[{e \\<in> X. e \\<noteq> Tock}]\\<^sub>R]\"\n        using case_assm3 by blast\n      obtain Y where Y_assms: \"\\<tau> = [[Y]\\<^sub>R]\" \"\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock\"\n        using case_assm4 by (erule_tac x=\"{e. e \\<in> X \\<and> e \\<noteq> Tock}\" in allE, simp add: \\<sigma>_def, auto)\n      then have \"\\<rho>' @ [[{e \\<in> X. e \\<noteq> Tock}]\\<^sub>R] \\<lesssim>\\<^sub>C \\<rho>' @ [[Y]\\<^sub>R]\"\n        by (induct \\<rho>', auto, case_tac a, auto)\n      then have \"\\<rho>' @ [[{e \\<in> X. e \\<noteq> Tock}]\\<^sub>R] \\<in> Q\"\n        using TT1_def TT_TT1 Y_assms(1) \\<rho>_def assms(2) case_assm5 by blast\n      then show \"\\<rho> @ \\<sigma> \\<in> Q\"\n        by (simp add: case_assm3)\n    next\n      fix \\<rho> \\<sigma> \\<tau> :: \"'a ttobs list\"\n      assume case_assm1: \"\\<rho> \\<in> tocks UNIV\"\n      assume case_assm2: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n      assume case_assm3: \"\\<rho>' @ [[{e \\<in> X. e \\<noteq> Tock}]\\<^sub>R] = \\<rho> @ \\<tau>\"\n      assume case_assm4: \"\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n      assume case_assm5: \"\\<rho> @ \\<sigma> \\<in> P\"\n      have \\<rho>_def: \"\\<rho> = \\<rho>'\"\n        by (metis (no_types, lifting) \\<rho>_split butlast_append butlast_snoc case_assm1 case_assm2 case_assm3 tt_prefix_antisym tt_prefix_concat end_refusal_notin_tocks)\n      then have \\<sigma>_def: \"\\<tau> = [[{e \\<in> X. e \\<noteq> Tock}]\\<^sub>R]\"\n        using case_assm3 by blast\n      obtain Y where Y_assms: \"\\<sigma> = [[Y]\\<^sub>R]\" \"\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock\"\n        using case_assm4 by (erule_tac x=\"{e. e \\<in> X \\<and> e \\<noteq> Tock}\" in allE, simp add: \\<sigma>_def, auto)\n      then have \"\\<rho>' @ [[{e \\<in> X. e \\<noteq> Tock}]\\<^sub>R] \\<lesssim>\\<^sub>C \\<rho>' @ [[Y]\\<^sub>R]\"\n        by (induct \\<rho>', auto, case_tac a, auto)\n      then have \"\\<rho>' @ [[{e \\<in> X. e \\<noteq> Tock}]\\<^sub>R] \\<in> P\"\n        using TT1_def TT_TT1 Y_assms(1) \\<rho>_def assms(1) case_assm5 by blast\n      then show \"\\<rho> @ \\<tau> \\<in> P\"\n        by (simp add: case_assm3)\n    qed\n    have notocks_assm2: \"{e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock}]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {} \n        \\<and> {e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock}]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {}\"\n      using set1 assm2 by blast\n    have TT2w_P_Q: \"TT2w P \\<and> TT2w Q\"\n      by (simp add: TT_TT2w assms(1) assms(2))\n    then have notock_X_Y_in_P_Q: \"\\<rho> @ [[{e. e \\<in> X \\<union> Y \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> P \\<and> \\<rho> @ [[{e. e \\<in> X \\<union> Y \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> Q\"\n      unfolding TT2w_def\n    proof auto\n      assume \"\\<forall>\\<rho> X Y. \\<rho> @ [[X]\\<^sub>R] \\<in> P \\<and> \n          Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {} \\<longrightarrow>\n            \\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P\"\n      then have \"\\<rho> @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock} \\<union> {e. e \\<in> Y \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> P\"\n        using in_P_and_Q notocks_assm2 case_assm \\<rho>_split by auto\n      also have \"\\<rho> @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock} \\<union> {e. e \\<in> Y \\<and> e \\<noteq> Tock}]\\<^sub>R] = \\<rho> @ [[{e. (e \\<in> X \\<or> e \\<in> Y) \\<and> e \\<noteq> Tock}]\\<^sub>R]\"\n        by auto\n      then show \"\\<rho> @ [[{e. (e \\<in> X \\<or> e \\<in> Y) \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> P\"\n        using calculation by auto\n    next\n      assume \"\\<forall>\\<rho> X Y. \\<rho> @ [[X]\\<^sub>R] \\<in> Q \\<and> \n          Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {} \\<longrightarrow>\n            \\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> Q\"\n      then have \"\\<rho> @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock} \\<union> {e. e \\<in> Y \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> Q\"\n        using in_P_and_Q notocks_assm2 case_assm \\<rho>_split by auto\n      also have \"\\<rho> @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock} \\<union> {e. e \\<in> Y \\<and> e \\<noteq> Tock}]\\<^sub>R] = \\<rho> @ [[{e. (e \\<in> X \\<or> e \\<in> Y) \\<and> e \\<noteq> Tock}]\\<^sub>R]\"\n        by auto\n      then show \"\\<rho> @ [[{e. (e \\<in> X \\<or> e \\<in> Y) \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> Q\"\n        using calculation by auto\n    qed\n    have in_P_or_Q: \"\\<rho> @ [[X]\\<^sub>R] \\<in> P \\<or> \\<rho> @ [[X]\\<^sub>R] \\<in> Q\"\n      using assm1 unfolding ExtChoiceTT_def by auto\n    show \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n    proof (cases \"Tock \\<in> Y\")\n      assume case_assm2: \"Tock \\<in> Y\"\n      have assm2_nontock_P: \"{e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P} = {}\"\n        using assm2 set1 by auto\n      have assm2_nontock_Q: \"{e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q} = {}\"\n        using assm2 set1 by auto\n      have \"{e. e \\<in> Y \\<and> e = Tock} \\<inter> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q} = {}\"\n        using assm2 by auto\n      then have \"Tock \\<notin> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q}\"\n        using case_assm2 by auto\n      then have \"Tock \\<notin> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} \\<inter> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q}\"\n        using set2 case_assm by auto\n      then have \"({e. e \\<in> Y \\<and> e = Tock} \\<inter> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {} \\<and> {e. e \\<in> Y \\<and> e = Tock} \\<inter> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {})\n        \\<or> (\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<and> {e. e \\<in> Y \\<and> e = Tock} \\<inter> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {})\n        \\<or> ({e. e \\<in> Y \\<and> e = Tock} \\<inter> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {} \\<and> \\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> Q)\"\n        by auto\n      then have \"(Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {} \\<and> Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {})\n        \\<or> (\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<and> Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {})\n        \\<or> (Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {} \\<and> \\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> Q)\"\n        using assm2_nontock_P assm2_nontock_Q by (safe, blast+)\n      then show \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n      proof safe\n        assume case_assm3: \"Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {}\"\n        assume case_assm4: \"Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {}\"\n        show \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n          using in_P_or_Q\n        proof auto\n          assume case_assm5: \"\\<rho> @ [[X]\\<^sub>R] \\<in> P\"\n          then have \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P\"\n            using TT2w_P_Q case_assm3 unfolding TT2w_def by auto\n          also have \"\\<rho> @ [[{e \\<in> X \\<union> Y. e \\<noteq> Tock}]\\<^sub>R] \\<in> Q\"\n            using notock_X_Y_in_P_Q by auto\n          then show \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n            unfolding ExtChoiceTT_def using calculation apply auto\n            apply (rule_tac x=\"\\<rho>'\" in bexI, simp_all add: \\<rho>_split case_assm)\n            apply (rule_tac x=\"[[X \\<union> Y]\\<^sub>R]\" in exI, simp_all)\n            apply (rule_tac x=\"[[{e \\<in> X \\<union> Y. e \\<noteq> Tock}]\\<^sub>R]\" in exI, auto)\n            using tt_prefix_notfront_is_whole end_refusal_notin_tocks by blast+\n        next\n          assume case_assm5: \"\\<rho> @ [[X]\\<^sub>R] \\<in> Q\"\n          then have \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> Q\"\n            using TT2w_P_Q case_assm4 unfolding TT2w_def by auto\n          also have \"\\<rho> @ [[{e \\<in> X \\<union> Y. e \\<noteq> Tock}]\\<^sub>R] \\<in> P\"\n            using notock_X_Y_in_P_Q by auto\n          then show \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n            unfolding ExtChoiceTT_def using calculation apply auto\n            apply (rule_tac x=\"\\<rho>'\" in bexI, simp_all add: \\<rho>_split case_assm)\n            apply (rule_tac x=\"[[{e \\<in> X \\<union> Y. e \\<noteq> Tock}]\\<^sub>R]\" in exI, auto)\n            apply (rule_tac x=\"[[X \\<union> Y]\\<^sub>R]\" in exI, simp_all)\n            using tt_prefix_notfront_is_whole end_refusal_notin_tocks by blast+\n        qed\n      next\n        assume case_assm3: \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P\"\n        assume case_assm4: \"Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {}\"\n        have TT1_P: \"TT1 P\"\n          by (simp add: TT_TT1 assms(1))\n        have \"\\<rho> @ [[X]\\<^sub>R] \\<lesssim>\\<^sub>C \\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n          using tt_prefix_subset_same_front by fastforce\n        then have in_P: \"\\<rho> @ [[X]\\<^sub>R] \\<in> P\"\n          using TT1_P case_assm3 unfolding TT1_def by auto \n        have ttWFx_P: \"ttWFx P\"\n          by (simp add: TT_ttWFx assms(1))\n        then have \"Tock \\<notin> X\"\n          using ttWFx_def ttWFx_end_tock \\<rho>'_in_P_Q \\<rho>_split case_assm case_assm3 by force\n        then have in_Q: \"\\<rho> @ [[X]\\<^sub>R] \\<in> Q\"\n          using assm1 unfolding ExtChoiceTT_def\n        proof auto\n          fix r s t :: \"'a ttobs list\"\n          assume 1: \"r \\<in> tocks UNIV\"\n          assume 2: \"r @ s \\<in> P\"\n          assume 3: \"r @ t \\<in> Q\"\n          assume 4: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C r @ s \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C r\"\n          assume 5: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C r @ t \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C r\"\n          assume 6: \"\\<forall>X. s = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. t = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n          assume 7: \"\\<forall>X. t = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. s = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n          assume 8: \"\\<rho> @ [[X]\\<^sub>R] = r @ s\"\n          assume 9: \"Tock \\<notin> X\"\n          have r_is_\\<rho>: \"r = \\<rho>\"\n            by (metis \"1\" \"4\" \"8\" \\<rho>_split append.right_neutral butlast_append butlast_snoc case_assm tt_prefix_antisym tt_prefix_concat end_refusal_notin_tocks)\n          then have \"s = [[X]\\<^sub>R]\"\n            using \"8\" by blast\n          then obtain Y where Y_assms: \"t = [[Y]\\<^sub>R]\" \"\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock\"\n            using \"6\" by auto\n          then have \"\\<rho> @ [[Y]\\<^sub>R] \\<in> Q\"\n            using \"3\" r_is_\\<rho> by blast\n          also have \"\\<rho> @ [[X]\\<^sub>R] \\<lesssim>\\<^sub>C \\<rho> @ [[Y]\\<^sub>R]\"\n            by (metis \"9\" Y_assms(2) tt_prefix_subset.simps(2) tt_prefix_subset_refl tt_prefix_subset_same_front subsetI)\n          then have \"\\<rho> @ [[X]\\<^sub>R] \\<in> Q\"\n            using TT1_def TT_TT1 assms(2) calculation by blast\n          then show \"r @ s \\<in> Q\"\n            using \"8\" by auto\n        qed\n        then have \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> Q\"\n          using TT2w_P_Q TT2w_def case_assm4 by blast\n        then show \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n          unfolding ExtChoiceTT_def using notock_X_Y_in_P_Q apply auto\n          apply (rule_tac x=\"\\<rho>'\" in bexI, simp_all add: \\<rho>_split case_assm)\n          apply (rule_tac x=\"[[{e \\<in> X \\<union> Y. e \\<noteq> Tock}]\\<^sub>R]\" in exI, auto)\n          apply (rule_tac x=\"[[X \\<union> Y]\\<^sub>R]\" in exI, simp_all)\n          using tt_prefix_notfront_is_whole end_refusal_notin_tocks by blast+\n      next\n        assume case_assm3: \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> Q\"\n        assume case_assm4: \"Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {}\"\n        have TT1_P: \"TT1 Q\"\n          by (simp add: TT_TT1 assms(2))\n        have \"\\<rho> @ [[X]\\<^sub>R] \\<lesssim>\\<^sub>C \\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n          using tt_prefix_subset_same_front by fastforce\n        then have in_P: \"\\<rho> @ [[X]\\<^sub>R] \\<in> Q\"\n          using TT1_P case_assm3 unfolding TT1_def by auto \n        have ttWFx_P: \"ttWFx Q\"\n          by (simp add: TT_ttWFx assms(2))\n        then have \"Tock \\<notin> X\"\n          using ttWFx_def ttWFx_end_tock \\<rho>'_in_P_Q \\<rho>_split case_assm case_assm3 by force\n        then have in_P: \"\\<rho> @ [[X]\\<^sub>R] \\<in> P\"\n          using assm1 unfolding ExtChoiceTT_def\n        proof auto\n          fix r s t :: \"'a ttobs list\"\n          assume 1: \"r \\<in> tocks UNIV\"\n          assume 2: \"r @ s \\<in> P\"\n          assume 3: \"r @ t \\<in> Q\"\n          assume 4: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C r @ s \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C r\"\n          assume 5: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C r @ t \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C r\"\n          assume 6: \"\\<forall>X. s = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. t = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n          assume 7: \"\\<forall>X. t = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. s = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n          assume 8: \"\\<rho> @ [[X]\\<^sub>R] = r @ t\"\n          assume 9: \"Tock \\<notin> X\"\n          have r_is_\\<rho>: \"r = \\<rho>\"\n            by (metis \"1\" \"5\" \"8\" \\<rho>_split append.right_neutral butlast_append butlast_snoc case_assm tt_prefix_antisym tt_prefix_concat end_refusal_notin_tocks)\n          then have \"t = [[X]\\<^sub>R]\"\n            using \"8\" by blast\n          then obtain Y where Y_assms: \"s = [[Y]\\<^sub>R]\" \"\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock\"\n            using \"7\" by auto\n          then have \"\\<rho> @ [[Y]\\<^sub>R] \\<in> P\"\n            using \"2\" r_is_\\<rho> by blast\n          also have \"\\<rho> @ [[X]\\<^sub>R] \\<lesssim>\\<^sub>C \\<rho> @ [[Y]\\<^sub>R]\"\n            by (metis \"9\" Y_assms(2) tt_prefix_subset.simps(2) tt_prefix_subset_refl tt_prefix_subset_same_front subsetI)\n          then have \"\\<rho> @ [[X]\\<^sub>R] \\<in> P\"\n            using TT1_def TT_TT1 assms(1) calculation by blast\n          then show \"r @ t \\<in> P\"\n            using \"8\" by auto\n        qed\n        then have \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P\"\n          using TT2w_P_Q TT2w_def case_assm4 by blast\n        then show \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n          unfolding ExtChoiceTT_def using notock_X_Y_in_P_Q apply auto\n          apply (rule_tac x=\"\\<rho>'\" in bexI, simp_all add: \\<rho>_split case_assm)\n          apply (rule_tac x=\"[[X \\<union> Y]\\<^sub>R]\" in exI, simp_all)\n          apply (rule_tac x=\"[[{e \\<in> X \\<union> Y. e \\<noteq> Tock}]\\<^sub>R]\" in exI, auto)\n          using tt_prefix_notfront_is_whole end_refusal_notin_tocks by blast+\n      qed\n    next\n      assume case_assm2: \"Tock \\<notin> Y\"\n      then have \"Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q}\n        = {e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q}\"\n        by auto\n      also have \"... = {e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q}\"\n        by auto\n      also have \"... = {e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> ({e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P} \\<union> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q})\"\n        using set1 by auto\n      also have \"... = ({e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P}) \\<union> ({e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q})\"\n        by auto\n      also have \"... = ({e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P}) \n        \\<union> ({e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q})\"\n        by auto\n      also have \"... = (Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P}) \n        \\<union> (Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q})\"\n        using case_assm2 by auto\n      then have assm2_expand: \"Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {}\n          \\<and> Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {}\"\n        using calculation assm2 by auto\n      show \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n        using in_P_or_Q\n      proof auto\n        assume  case_assm3: \"\\<rho> @ [[X]\\<^sub>R] \\<in> P\"\n        have \"TT2w P\"\n          by (simp add: TT2w_P_Q)\n        then have \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P\"\n          unfolding TT2w_def using case_assm3 assm2_expand by auto\n        then show  \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n          unfolding ExtChoiceTT_def using notock_X_Y_in_P_Q apply auto\n          apply (rule_tac x=\"\\<rho>'\" in bexI, simp_all add: \\<rho>_split case_assm)\n          apply (rule_tac x=\"[[X \\<union> Y]\\<^sub>R]\" in exI, simp_all)\n          apply (rule_tac x=\"[[{e \\<in> X \\<union> Y. e \\<noteq> Tock}]\\<^sub>R]\" in exI, auto)\n          using tt_prefix_notfront_is_whole end_refusal_notin_tocks by blast+\n      next\n        assume  case_assm3: \"\\<rho> @ [[X]\\<^sub>R] \\<in> Q\"\n        have \"TT2w Q\"\n          by (simp add: TT2w_P_Q)\n        then have \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> Q\"\n          unfolding TT2w_def using case_assm3 assm2_expand by auto\n        then show  \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n          unfolding ExtChoiceTT_def using notock_X_Y_in_P_Q apply auto\n          apply (rule_tac x=\"\\<rho>'\" in bexI, simp_all add: \\<rho>_split case_assm)\n          apply (rule_tac x=\"[[{e \\<in> X \\<union> Y. e \\<noteq> Tock}]\\<^sub>R]\" in exI, auto)\n          apply (rule_tac x=\"[[X \\<union> Y]\\<^sub>R]\" in exI, simp_all)\n          using tt_prefix_notfront_is_whole end_refusal_notin_tocks by blast+\n      qed\n    qed\n  qed\nqed\n\nlemma TT2_ExtChoice:\n  assumes \"TT P\" \"TT Q\" \"TT2 P\" \"TT2 Q\"\n  shows \"TT2 (P \\<box>\\<^sub>C Q)\"\n  unfolding TT2_def\nproof auto\n  fix \\<rho> \\<sigma> X Y\n  assume assm1: \"\\<rho> @ [X]\\<^sub>R # \\<sigma> \\<in> P \\<box>\\<^sub>C Q\"\n  assume assm2: \"Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q} = {}\"\n  from assm1 have \\<rho>_\\<sigma>_wf: \"ttWF (\\<rho> @ [X]\\<^sub>R # \\<sigma>)\"\n    by (metis TT_def ExtChoiceTT_wf assms(1) assms(2))\n  then obtain \\<rho>' \\<rho>'' where \\<rho>_\\<sigma>_split: \"\\<rho>'\\<in>tocks UNIV \\<and> \\<rho> @ [X]\\<^sub>R # \\<sigma> = \\<rho>' @ \\<rho>'' \\<and> (\\<forall>t'\\<in>tocks UNIV. t' \\<le>\\<^sub>C \\<rho> @ [X]\\<^sub>R # \\<sigma> \\<longrightarrow> t' \\<le>\\<^sub>C \\<rho>')\"\n    using split_tocks_longest by blast\n  then have \\<rho>'_\\<rho>''_wf: \"ttWF (\\<rho>' @ \\<rho>'')\"\n    using \\<rho>_\\<sigma>_wf by auto  \n  have \\<rho>'_in_P_Q: \"\\<rho>' \\<in> P \\<and> \\<rho>' \\<in> Q\"\n    using assm1 unfolding ExtChoiceTT_def apply auto\n    apply (metis TT1_def TT_TT1 \\<rho>_\\<sigma>_split assms(1) tt_prefix_concat tt_prefix_imp_prefix_subset)\n    apply (metis TT1_def TT_TT1 \\<rho>_\\<sigma>_split assms(2) tt_prefix_concat tt_prefix_imp_prefix_subset)\n    apply (metis TT1_def TT_TT1 \\<rho>_\\<sigma>_split assms(1) tt_prefix_concat tt_prefix_imp_prefix_subset)\n    by (metis TT1_def TT_TT1 \\<rho>_\\<sigma>_split assms(2) tt_prefix_concat tt_prefix_imp_prefix_subset)\n  have \\<rho>'_cases: \"\\<rho>' \\<le>\\<^sub>C \\<rho> \\<or> (\\<exists> \\<sigma>'. \\<rho>' = \\<rho> @ [X]\\<^sub>R # \\<sigma>' \\<and> \\<sigma>' \\<le>\\<^sub>C \\<sigma> \\<and> \\<sigma>' \\<noteq> [])\"\n    using \\<rho>_\\<sigma>_split \\<rho>'_\\<rho>''_wf \\<rho>_\\<sigma>_wf apply -\n  proof (induct \\<rho> \\<rho>' rule:ttWF2.induct, auto simp add: notin_tocks tt_prefix_concat)\n    fix \\<rho> \\<sigma>' :: \"'a ttobs list\"\n    fix Y\n    assume \"[Y]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>' \\<in> tocks UNIV\"\n    then have 1: \"\\<sigma>' \\<in> tocks UNIV\"\n      using tocks.cases by auto\n    assume \"\\<forall>t'\\<in>tocks UNIV. t' \\<le>\\<^sub>C [Y]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>' @ \\<rho>'' \\<longrightarrow> t' \\<le>\\<^sub>C [Y]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>'\"\n    then have 2: \"\\<forall>t'\\<in>tocks UNIV. t' \\<le>\\<^sub>C \\<sigma>' @ \\<rho>'' \\<longrightarrow> t' \\<le>\\<^sub>C \\<sigma>'\"\n      using tocks.simps by (auto, erule_tac x=\"[Y]\\<^sub>R # [Tock]\\<^sub>E # t'\" in ballE, auto, blast)\n    assume \"\\<sigma>' \\<in> tocks UNIV \\<and> (\\<forall>t'\\<in>tocks UNIV. t' \\<le>\\<^sub>C \\<sigma>' @ \\<rho>'' \\<longrightarrow> t' \\<le>\\<^sub>C \\<sigma>') \\<Longrightarrow> \\<sigma>' \\<le>\\<^sub>C \\<rho>\"\n    then show \"\\<sigma>' \\<le>\\<^sub>C \\<rho>\"\n      using 1 2 by blast\n  next\n    fix Xa \\<rho> \\<sigma>'\n    assume \"[Xa]\\<^sub>R # [Tick]\\<^sub>E # \\<rho> @ [X]\\<^sub>R # \\<sigma> = \\<sigma>' @ \\<rho>''\" \"ttWF (\\<sigma>' @ \\<rho>'')\"\n    then have \"ttWF ([Xa]\\<^sub>R # [Tick]\\<^sub>E # \\<rho> @ [X]\\<^sub>R # \\<sigma>)\"\n      by auto\n    then show \"\\<sigma>' \\<le>\\<^sub>C [Xa]\\<^sub>R # [Tick]\\<^sub>E # \\<rho>\"\n      by auto\n  next\n    fix Xa e \\<rho> \\<sigma>'\n    assume \"[Xa]\\<^sub>R # [Event e]\\<^sub>E # \\<rho> @ [X]\\<^sub>R # \\<sigma> = \\<sigma>' @ \\<rho>''\" \"ttWF (\\<sigma>' @ \\<rho>'')\"\n    then have \"ttWF ([Xa]\\<^sub>R # [Event e]\\<^sub>E # \\<rho> @ [X]\\<^sub>R # \\<sigma>)\"\n      by auto\n    then show \"\\<sigma>' \\<le>\\<^sub>C [Xa]\\<^sub>R # [Event e]\\<^sub>E # \\<rho>\"\n      by auto\n  next\n    fix Xa Y \\<rho> \\<sigma>'\n    assume \"[Xa]\\<^sub>R # [Y]\\<^sub>R # \\<rho> @ [X]\\<^sub>R # \\<sigma> = \\<sigma>' @ \\<rho>''\" \"ttWF (\\<sigma>' @ \\<rho>'')\"\n    then have \"ttWF ([Xa]\\<^sub>R # [Y]\\<^sub>R # \\<rho> @ [X]\\<^sub>R # \\<sigma>)\"\n      by auto\n    then show \"\\<sigma>' \\<le>\\<^sub>C [Xa]\\<^sub>R # [Y]\\<^sub>R # \\<rho>\"\n      by auto\n  next\n    fix x \\<rho> \\<sigma>'\n    assume \"[Tick]\\<^sub>E # x # \\<rho> @ [X]\\<^sub>R # \\<sigma> = \\<sigma>' @ \\<rho>''\" \"ttWF (\\<sigma>' @ \\<rho>'')\"\n    then have \"ttWF ([Tick]\\<^sub>E # x # \\<rho> @ [X]\\<^sub>R # \\<sigma>)\"\n      by auto\n    then show \"\\<sigma>' \\<le>\\<^sub>C [Tick]\\<^sub>E # x # \\<rho>\"\n      by auto\n  next\n    fix \\<rho> \\<sigma>'\n    assume \"[Tock]\\<^sub>E # \\<rho> @ [X]\\<^sub>R # \\<sigma> = \\<sigma>' @ \\<rho>''\" \"ttWF (\\<sigma>' @ \\<rho>'')\"\n    then have \"ttWF ([Tock]\\<^sub>E # \\<rho> @ [X]\\<^sub>R # \\<sigma>)\"\n      by auto\n    then show \"\\<sigma>' \\<le>\\<^sub>C [Tock]\\<^sub>E # \\<rho>\"\n      by auto\n  qed\n  then show \"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma> \\<in> P \\<box>\\<^sub>C Q\"\n  proof auto\n    assume case_assms: \"\\<rho>' \\<le>\\<^sub>C \\<rho>\"\n    then obtain \\<rho>2 where \\<rho>2_def: \"\\<rho> = \\<rho>' @ \\<rho>2\"\n      using tt_prefix_decompose by blast\n    have set1: \"{e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q} = {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P} \\<union> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q}\"\n    proof auto\n      fix x :: \"'a ttevent\"\n      assume \"\\<rho> @ [[x]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\"\n      then have \"\\<rho> @ [[x]\\<^sub>E] \\<in> P \\<or> \\<rho> @ [[x]\\<^sub>E] \\<in> Q\"\n        unfolding ExtChoiceTT_def by auto\n      then show \"\\<rho> @ [[x]\\<^sub>E] \\<notin> Q \\<Longrightarrow> \\<rho> @ [[x]\\<^sub>E] \\<in> P\"\n        by auto\n    next\n      fix x :: \"'a ttevent\"\n      assume \"x \\<noteq> Tock\" \"\\<rho> @ [[x]\\<^sub>E] \\<in> P\"\n      then show \"\\<rho> @ [[x]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\"\n        unfolding ExtChoiceTT_def apply auto\n        apply (rule_tac x=\"\\<rho>'\" in bexI, simp_all add: \\<rho>_\\<sigma>_split)\n        apply (rule_tac x=\"\\<rho>2 @ [[x]\\<^sub>E]\" in exI, simp_all add: \\<rho>2_def)\n        apply (rule_tac x=\"[]\" in exI, simp add: \\<rho>'_in_P_Q)\n        by (metis \\<rho>2_def \\<rho>_\\<sigma>_split append.assoc tt_prefix_concat tt_prefix_trans tocks_tt_prefix_end_event)\n    next\n      fix x :: \"'a ttevent\"\n      assume \"x \\<noteq> Tock\" \"\\<rho> @ [[x]\\<^sub>E] \\<in> Q\"\n      then show \"\\<rho> @ [[x]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\"\n        unfolding ExtChoiceTT_def apply auto\n        apply (rule_tac x=\"\\<rho>'\" in bexI, simp_all add: \\<rho>_\\<sigma>_split)\n        apply (rule_tac x=\"[]\" in exI, simp add: \\<rho>'_in_P_Q)\n        apply (rule_tac x=\"\\<rho>2 @ [[x]\\<^sub>E]\" in exI, simp_all add: \\<rho>2_def)\n        by (metis \\<rho>2_def \\<rho>_\\<sigma>_split append.assoc tt_prefix_concat tt_prefix_trans tocks_tt_prefix_end_event)\n    qed\n    have set2: \"{e. e = Tock \\<and> \\<rho>2 = [] \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q} = \n      {e. e = Tock \\<and> \\<rho>2 = [] \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} \\<inter> {e. e = Tock \\<and> \\<rho>2 = [] \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q}\"\n    proof auto\n      assume case_assms: \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\" \"\\<rho>2 = []\"\n      then have \"\\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\"\n        using \\<rho>2_def \\<rho>_\\<sigma>_split by auto\n      then obtain r s t where rst_assms: \n        \"r \\<in> tocks UNIV\"\n        \"r @ s \\<in> P\"\n        \"r @ t \\<in> Q\"\n        \"\\<forall>x\\<in>tocks UNIV. x \\<le>\\<^sub>C r @ s \\<longrightarrow> x \\<le>\\<^sub>C r\"\n        \"\\<forall>x\\<in>tocks UNIV. x \\<le>\\<^sub>C r @ t \\<longrightarrow> x \\<le>\\<^sub>C r\"\n        \"(\\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] = r @ s \\<or> \\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] = r @ t)\"\n        unfolding ExtChoiceTT_def by auto\n      have in_tocks: \"\\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> tocks UNIV\"\n        by (simp add: \\<rho>_\\<sigma>_split tocks.empty_in_tocks tocks.tock_insert_in_tocks tocks_append_tocks)\n      then have r_def: \"r = \\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n        using tt_prefix_refl rst_assms(4) rst_assms(5) rst_assms(6) self_extension_tt_prefix by fastforce\n      then have \"r \\<in> P \\<and> r \\<in> Q\"\n        by (smt TT1_def TT_TT1 rst_assms assms(1) assms(2) tt_prefix_concat tt_prefix_imp_prefix_subset in_tocks rst_assms(4))\n      then show \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P\"\n        by (simp add: \\<rho>2_def case_assms(2) r_def)\n    next\n      assume case_assms: \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\" \"\\<rho>2 = []\"\n      then have \"\\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\"\n        using \\<rho>2_def \\<rho>_\\<sigma>_split by auto\n      then obtain r s t where rst_assms: \n        \"r \\<in> tocks UNIV\"\n        \"r @ s \\<in> P\"\n        \"r @ t \\<in> Q\"\n        \"\\<forall>x\\<in>tocks UNIV. x \\<le>\\<^sub>C r @ s \\<longrightarrow> x \\<le>\\<^sub>C r\"\n        \"\\<forall>x\\<in>tocks UNIV. x \\<le>\\<^sub>C r @ t \\<longrightarrow> x \\<le>\\<^sub>C r\"\n        \"(\\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] = r @ s \\<or> \\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] = r @ t)\"\n        unfolding ExtChoiceTT_def by auto\n      have in_tocks: \"\\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> tocks UNIV\"\n        by (simp add: \\<rho>_\\<sigma>_split tocks.empty_in_tocks tocks.tock_insert_in_tocks tocks_append_tocks)\n      then have r_def: \"r = \\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n        using tt_prefix_refl rst_assms(4) rst_assms(5) rst_assms(6) self_extension_tt_prefix by fastforce\n      then have \"r \\<in> P \\<and> r \\<in> Q\"\n        by (smt TT1_def TT_TT1 rst_assms assms(1) assms(2) tt_prefix_concat tt_prefix_imp_prefix_subset in_tocks rst_assms(4))\n      then show \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> Q\"\n        by (simp add: \\<rho>2_def case_assms(2) r_def)\n    next\n      assume case_assms: \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P\" \"\\<rho>2 = []\" \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> Q\"\n      then have \"\\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<and> \\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> Q\"\n        using \\<rho>2_def \\<rho>_\\<sigma>_split by auto\n      also have \"\\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> tocks UNIV\"\n        by (simp add: \\<rho>_\\<sigma>_split tocks.empty_in_tocks tocks.tock_insert_in_tocks tocks_append_tocks)\n      then show \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\"\n        unfolding ExtChoiceTT_def apply auto\n        apply (rule_tac x=\"\\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\" in bexI, simp_all)\n        apply (rule_tac x=\"[]\" in exI, simp_all add: calculation)\n        apply (rule_tac x=\"[]\" in exI, simp_all add: calculation)\n        using \\<rho>2_def \\<rho>_\\<sigma>_split case_assms(2) by auto\n    qed\n    have set3: \"{e. e = Tock \\<and> \\<rho>2 \\<noteq> [] \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q} =\n      {e. e = Tock \\<and> \\<rho>2 \\<noteq> [] \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} \\<union> {e. e = Tock \\<and> \\<rho>2 \\<noteq> [] \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q}\"\n    proof auto\n      assume \"\\<rho>2 \\<noteq> []\" \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\"\n      then show \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<notin> Q \\<Longrightarrow> \\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P\"\n        unfolding ExtChoiceTT_def by auto\n    next\n      assume \\<rho>2_nonempty: \"\\<rho>2 \\<noteq> []\"\n      assume in_P: \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P\"\n      have \\<rho>2_notin_tocks: \"\\<rho>2 \\<notin> tocks UNIV\"\n      proof auto\n        assume \"\\<rho>2 \\<in> tocks UNIV\"\n        then have \"\\<rho>' @ \\<rho>2 \\<in> tocks UNIV\"\n          using \\<rho>_\\<sigma>_split tocks_append_tocks by blast\n        then have \"\\<rho>' @ \\<rho>2 \\<le>\\<^sub>C \\<rho>'\"\n          using \\<rho>2_def \\<rho>_\\<sigma>_split tt_prefix_concat by blast\n        then have \"\\<rho>2 = []\"\n          using self_extension_tt_prefix by blast\n        then show \"False\"\n          using \\<rho>2_nonempty by auto\n      qed\n      have full_notin_tocks: \"\\<rho>' @ \\<rho>2 @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<notin> tocks UNIV\"\n        using \\<rho>2_notin_tocks \\<rho>_\\<sigma>_split tocks_append_nontocks tocks_mid_refusal_front_in_tocks by blast\n      have \"\\<forall>x\\<in>tocks UNIV. x \\<le>\\<^sub>C \\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<longrightarrow> x \\<le>\\<^sub>C \\<rho>'\"\n      proof (auto simp add: \\<rho>2_def \\<rho>_\\<sigma>_split)\n        fix x :: \"'a ttobs list\"\n        assume x_in_tocks: \"x \\<in> tocks UNIV\"\n        assume \"x \\<le>\\<^sub>C \\<rho>' @ \\<rho>2 @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n        also have \"\\<And> y. x \\<le>\\<^sub>C y @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<Longrightarrow> x \\<le>\\<^sub>C y \\<or> x = y @ [[X]\\<^sub>R] \\<or> x = y @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n        proof -\n          fix y\n          show \"x \\<le>\\<^sub>C y @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<Longrightarrow> x \\<le>\\<^sub>C y \\<or> x = y @ [[X]\\<^sub>R] \\<or> x = y @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n            using tt_prefix.elims(2) tt_prefix_antisym by (induct x y rule:tt_prefix.induct, auto, fastforce)\n        qed\n        then have \"x \\<le>\\<^sub>C \\<rho>' @ \\<rho>2 \\<or> x = \\<rho>' @ \\<rho>2 @ [[X]\\<^sub>R] \\<or> x = \\<rho>' @ \\<rho>2 @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n          using calculation by force\n        then show \"x \\<le>\\<^sub>C \\<rho>'\"\n          apply (auto simp add: \\<rho>2_def \\<rho>_\\<sigma>_split x_in_tocks)\n          using \\<rho>2_def \\<rho>_\\<sigma>_split tt_prefix_concat tt_prefix_trans x_in_tocks apply blast\n          apply (metis append_assoc end_refusal_notin_tocks x_in_tocks)\n          using full_notin_tocks x_in_tocks by blast\n      qed\n      then show \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\"\n        unfolding ExtChoiceTT_def apply auto\n        apply (rule_tac x=\"\\<rho>'\" in bexI, auto simp add: \\<rho>_\\<sigma>_split)\n        apply (rule_tac x=\"\\<rho>2 @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\" in exI, insert \\<rho>2_def \\<rho>_\\<sigma>_split in_P, auto)\n        apply (rule_tac x=\"[]\" in exI, auto simp add: \\<rho>'_in_P_Q)\n        done\n    next\n      assume \\<rho>2_nonempty: \"\\<rho>2 \\<noteq> []\"\n      assume in_Q: \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> Q\"\n      have \\<rho>2_notin_tocks: \"\\<rho>2 \\<notin> tocks UNIV\"\n      proof auto\n        assume \"\\<rho>2 \\<in> tocks UNIV\"\n        then have \"\\<rho>' @ \\<rho>2 \\<in> tocks UNIV\"\n          using \\<rho>_\\<sigma>_split tocks_append_tocks by blast\n        then have \"\\<rho>' @ \\<rho>2 \\<le>\\<^sub>C \\<rho>'\"\n          using \\<rho>2_def \\<rho>_\\<sigma>_split tt_prefix_concat by blast\n        then have \"\\<rho>2 = []\"\n          using self_extension_tt_prefix by blast\n        then show \"False\"\n          using \\<rho>2_nonempty by auto\n      qed\n      then have full_notin_tocks: \"\\<rho>' @ \\<rho>'' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<notin> tocks UNIV\"\n        by (metis \\<rho>2_def \\<rho>_\\<sigma>_split append.assoc tocks_append_nontocks tocks_mid_refusal_front_in_tocks)\n      have \"\\<forall>x\\<in>tocks UNIV. x \\<le>\\<^sub>C \\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<longrightarrow> x \\<le>\\<^sub>C \\<rho>'\"\n      proof (auto simp add: \\<rho>_\\<sigma>_split \\<rho>2_def)\n        fix x :: \"'a ttobs list\"\n        assume x_in_tocks: \"x \\<in> tocks UNIV\"\n        assume \"x \\<le>\\<^sub>C \\<rho>' @ \\<rho>2 @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n        also have \"\\<And> y. x \\<le>\\<^sub>C y @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<Longrightarrow> x \\<le>\\<^sub>C y \\<or> x = y @ [[X]\\<^sub>R] \\<or> x = y @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n        proof -\n          fix y\n          show \"x \\<le>\\<^sub>C y @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<Longrightarrow> x \\<le>\\<^sub>C y \\<or> x = y @ [[X]\\<^sub>R] \\<or> x = y @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n            using tt_prefix.elims(2) tt_prefix_antisym by (induct x y rule:tt_prefix.induct, auto, fastforce)\n        qed\n        then have \"x \\<le>\\<^sub>C \\<rho>' @ \\<rho>2 \\<or> x = \\<rho>' @ \\<rho>2 @ [[X]\\<^sub>R] \\<or> x = \\<rho>' @ \\<rho>2 @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n          using calculation by force\n        then show \"x \\<le>\\<^sub>C \\<rho>'\"\n          apply auto\n          using \\<rho>2_def \\<rho>_\\<sigma>_split tt_prefix_concat tt_prefix_trans x_in_tocks apply blast\n          apply (metis append_assoc end_refusal_notin_tocks x_in_tocks)\n          using \\<rho>2_notin_tocks \\<rho>_\\<sigma>_split tocks_append_nontocks tocks_mid_refusal_front_in_tocks x_in_tocks by blast\n      qed\n      then show \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q\"\n        unfolding ExtChoiceTT_def apply auto\n        apply (rule_tac x=\"\\<rho>'\" in bexI, auto simp add: \\<rho>_\\<sigma>_split)\n        apply (rule_tac x=\"[]\" in exI, auto simp add: \\<rho>2_def \\<rho>'_in_P_Q)\n        apply (insert \\<rho>2_def \\<rho>_\\<sigma>_split in_Q, auto)\n        done\n    qed\n    thm set1 set2 set3\n    have in_P_or_Q: \"\\<rho> @ [X]\\<^sub>R # \\<sigma> \\<in> P \\<or> \\<rho> @ [X]\\<^sub>R # \\<sigma> \\<in> Q\"\n      using assm1 unfolding ExtChoiceTT_def by auto\n    show \"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma> \\<in> P \\<box>\\<^sub>C Q\"\n    proof (cases \"\\<rho>2 \\<noteq> []\", auto)\n      assume case_assm: \"\\<rho>2 \\<noteq> []\"\n      have full_pretocks: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<rho>2 @ [X \\<union> Y]\\<^sub>R # \\<sigma> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n      proof -\n        have \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<rho>2 @ [X]\\<^sub>R # \\<sigma> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n          by (simp add: \\<rho>2_def \\<rho>_\\<sigma>_split)\n        also have \"\\<rho>2 @ [X]\\<^sub>R # \\<sigma> \\<subseteq>\\<^sub>C \\<rho>2 @ [X \\<union> Y]\\<^sub>R # \\<sigma>\"\n          by (simp add: tt_subset_combine tt_subset_refl)\n        then show ?thesis\n          using calculation tt_subset_longest_tocks3 by blast\n      qed\n      have \"{e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q}\n        = {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} \\<union> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q}\"\n        (is \"?lhs = ?rhs\")\n      proof -\n        have \"?lhs = {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q} \\<union> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q}\"\n          by auto\n        also have \"... = {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P} \\<union> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q} \\<union> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q}\"\n          using set1 by auto\n        also have \"... = {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P} \\<union> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q} \\<union> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} \\<union> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q}\"\n          using set3 case_assm by auto\n        also have \"... = ?rhs\"\n          by auto\n        then show \"?lhs = ?rhs\"\n          using calculation by auto\n      qed\n      then have \n        \"(Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P})\n          \\<union> (Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q}) = {}\"\n        using assm2 inf_sup_distrib1 by auto\n      then have \"Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {}\n        \\<and> Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {}\"\n        by auto\n      then have \"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma> \\<in> P \\<or> \\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma> \\<in> Q\"\n        using assms(3) assms(4) in_P_or_Q unfolding TT2_def by auto\n      then show \"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma> \\<in> P \\<box>\\<^sub>C Q\"\n        unfolding ExtChoiceTT_def apply auto\n        apply (rule_tac x=\"\\<rho>'\" in bexI, auto simp add: \\<rho>2_def \\<rho>_\\<sigma>_split)\n        apply (rule_tac x=\"\\<rho>2 @ [[X \\<union> Y]\\<^sub>R] @ \\<sigma>\" in exI, auto)\n        apply (rule_tac x=\"[]\" in exI, auto simp add: \\<rho>2_def \\<rho>_\\<sigma>_split \\<rho>'_in_P_Q case_assm full_pretocks)\n        apply (metis Cons_eq_append_conv Nil_is_append_conv case_assm list.simps(3))\n        apply (rule_tac x=\"\\<rho>'\" in bexI, auto simp add: \\<rho>2_def \\<rho>_\\<sigma>_split)\n        apply (rule_tac x=\"[]\" in exI, auto simp add: \\<rho>2_def \\<rho>_\\<sigma>_split \\<rho>'_in_P_Q case_assm full_pretocks)\n        apply (metis Cons_eq_append_conv Nil_is_append_conv case_assm list.simps(3))\n        done\n    next\n      assume case_assm: \"\\<rho>2 = []\"\n      show \"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma> \\<in> P \\<box>\\<^sub>C Q\"\n      proof (cases \"\\<sigma> \\<noteq> []\", auto)\n        assume case_assm2: \"\\<sigma> \\<noteq> []\"\n        have \\<sigma>_Tock_start: \"\\<exists> \\<sigma>'. \\<sigma> = [Tock]\\<^sub>E # \\<sigma>'\"\n          using assm1 case_assm2 apply (cases \\<sigma> rule:ttWF.cases, auto)\n          using \\<rho>'_\\<rho>''_wf \\<rho>2_def \\<rho>_\\<sigma>_split case_assm tocks_append_wf2 by force+\n        then have False\n          using \\<rho>_\\<sigma>_split \\<rho>2_def case_assm\n        proof auto\n          fix \\<sigma>'\n          assume \"\\<forall>t'\\<in>tocks UNIV. t' \\<le>\\<^sub>C \\<rho>' @ [X]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>' \\<longrightarrow> t' \\<le>\\<^sub>C \\<rho>'\" \"\\<rho>' \\<in> tocks UNIV\"\n          then have \"\\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<le>\\<^sub>C \\<rho>'\"\n            by (erule_tac x=\"\\<rho>' @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\" in ballE, auto simp add: tt_prefix_same_front tocks.intros tocks_append_tocks)\n          then show False\n            using self_extension_tt_prefix by blast\n          qed\n          then show \"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma> \\<in> P \\<box>\\<^sub>C Q\"\n            by simp\n        next\n          assume case_assm2: \"\\<sigma> = []\"  \n          have \"\\<rho> @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<lesssim>\\<^sub>C \\<rho> @ [[X]\\<^sub>R]\"\n            by (induct \\<rho>, auto, case_tac a, auto)\n          then have \"\\<rho> @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n            using TT1_ExtChoice TT1_def assm1 assms(1) assms(2) case_assm2 by blast\n          then have \"\\<rho>' @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n            using \\<rho>2_def \\<rho>_\\<sigma>_split case_assm by auto\n          then have in_P_and_Q: \"\\<rho>' @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> P \\<and> \\<rho>' @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> Q\"\n            unfolding ExtChoiceTT_def\n          proof auto\n            fix \\<rho> \\<sigma> \\<tau> :: \"'a ttobs list\"\n            assume case_assm1: \"\\<rho> \\<in> tocks UNIV\"\n            assume case_assm2: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n            assume case_assm3: \"\\<rho>' @ [[{e \\<in> X. e \\<noteq> Tock}]\\<^sub>R] = \\<rho> @ \\<sigma>\"\n            assume case_assm4: \"\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n            assume case_assm5: \"\\<rho> @ \\<tau> \\<in> Q\"\n            have \\<rho>_def: \"\\<rho> = \\<rho>'\"\n              by (metis (no_types, lifting) \\<rho>_\\<sigma>_split butlast_append butlast_snoc case_assm1 case_assm2 case_assm3 tt_prefix_antisym tt_prefix_concat end_refusal_notin_tocks)\n            then have \\<sigma>_def: \"\\<sigma> = [[{e \\<in> X. e \\<noteq> Tock}]\\<^sub>R]\"\n              using case_assm3 by blast\n            obtain Y where Y_assms: \"\\<tau> = [[Y]\\<^sub>R]\" \"\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock\"\n              using case_assm4 by (erule_tac x=\"{e. e \\<in> X \\<and> e \\<noteq> Tock}\" in allE, simp add: \\<sigma>_def, auto)\n            then have \"\\<rho>' @ [[{e \\<in> X. e \\<noteq> Tock}]\\<^sub>R] \\<lesssim>\\<^sub>C \\<rho>' @ [[Y]\\<^sub>R]\"\n              by (induct \\<rho>', auto, case_tac a, auto)\n            then have \"\\<rho>' @ [[{e \\<in> X. e \\<noteq> Tock}]\\<^sub>R] \\<in> Q\"\n              using TT1_def TT_TT1 Y_assms(1) \\<rho>_def assms(2) case_assm5 by blast\n            then show \"\\<rho> @ \\<sigma> \\<in> Q\"\n              by (simp add: case_assm3)\n          next\n            fix \\<rho> \\<sigma> \\<tau> :: \"'a ttobs list\"\n            assume case_assm1: \"\\<rho> \\<in> tocks UNIV\"\n            assume case_assm2: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n            assume case_assm3: \"\\<rho>' @ [[{e \\<in> X. e \\<noteq> Tock}]\\<^sub>R] = \\<rho> @ \\<tau>\"\n            assume case_assm4: \"\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n            assume case_assm5: \"\\<rho> @ \\<sigma> \\<in> P\"\n            have \\<rho>_def: \"\\<rho> = \\<rho>'\"\n              by (metis (no_types, lifting) \\<rho>_\\<sigma>_split butlast_append butlast_snoc case_assm1 case_assm2 case_assm3 tt_prefix_antisym tt_prefix_concat end_refusal_notin_tocks)\n            then have \\<sigma>_def: \"\\<tau> = [[{e \\<in> X. e \\<noteq> Tock}]\\<^sub>R]\"\n              using case_assm3 by blast\n            obtain Y where Y_assms: \"\\<sigma> = [[Y]\\<^sub>R]\" \"\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock\"\n              using case_assm4 by (erule_tac x=\"{e. e \\<in> X \\<and> e \\<noteq> Tock}\" in allE, simp add: \\<sigma>_def, auto)\n            then have \"\\<rho>' @ [[{e \\<in> X. e \\<noteq> Tock}]\\<^sub>R] \\<lesssim>\\<^sub>C \\<rho>' @ [[Y]\\<^sub>R]\"\n              by (induct \\<rho>', auto, case_tac a, auto)\n            then have \"\\<rho>' @ [[{e \\<in> X. e \\<noteq> Tock}]\\<^sub>R] \\<in> P\"\n              using TT1_def TT_TT1 Y_assms(1) \\<rho>_def assms(1) case_assm5 by blast\n            then show \"\\<rho> @ \\<tau> \\<in> P\"\n              by (simp add: case_assm3)\n          qed\n          have notocks_assm2: \"{e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock}]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {} \n              \\<and> {e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock}]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {}\"\n            using set1 assm2 by blast\n          have TT2w_P_Q: \"TT2w P \\<and> TT2w Q\"\n            by (simp add: TT_TT2w assms(1) assms(2))\n          then have notock_X_Y_in_P_Q: \"\\<rho> @ [[{e. e \\<in> X \\<union> Y \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> P \\<and> \\<rho> @ [[{e. e \\<in> X \\<union> Y \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> Q\"\n            unfolding TT2w_def\n          proof auto\n            assume \"\\<forall>\\<rho> X Y. \\<rho> @ [[X]\\<^sub>R] \\<in> P \\<and> \n                Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {} \\<longrightarrow>\n                  \\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P\"\n            then have \"\\<rho> @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock} \\<union> {e. e \\<in> Y \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> P\"\n              using \\<rho>2_def case_assm in_P_and_Q notocks_assm2 by auto\n            also have \"\\<rho> @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock} \\<union> {e. e \\<in> Y \\<and> e \\<noteq> Tock}]\\<^sub>R] = \\<rho> @ [[{e. (e \\<in> X \\<or> e \\<in> Y) \\<and> e \\<noteq> Tock}]\\<^sub>R]\"\n              by auto\n            then show \"\\<rho> @ [[{e. (e \\<in> X \\<or> e \\<in> Y) \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> P\"\n              using calculation by auto\n          next\n            assume \"\\<forall>\\<rho> X Y. \\<rho> @ [[X]\\<^sub>R] \\<in> Q \\<and> \n                Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {} \\<longrightarrow>\n                  \\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> Q\"\n            then have \"\\<rho> @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock} \\<union> {e. e \\<in> Y \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> Q\"\n              using \\<rho>2_def case_assm in_P_and_Q notocks_assm2 by auto\n            also have \"\\<rho> @ [[{e. e \\<in> X \\<and> e \\<noteq> Tock} \\<union> {e. e \\<in> Y \\<and> e \\<noteq> Tock}]\\<^sub>R] = \\<rho> @ [[{e. (e \\<in> X \\<or> e \\<in> Y) \\<and> e \\<noteq> Tock}]\\<^sub>R]\"\n              by auto\n            then show \"\\<rho> @ [[{e. (e \\<in> X \\<or> e \\<in> Y) \\<and> e \\<noteq> Tock}]\\<^sub>R] \\<in> Q\"\n              using calculation by auto\n          qed\n          show \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n          proof (cases \"Tock \\<in> Y\")\n            assume case_assm3: \"Tock \\<in> Y\"\n            have assm2_nontock_P: \"{e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P} = {}\"\n              using assm2 set1 by auto\n            have assm2_nontock_Q: \"{e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q} = {}\"\n              using assm2 set1 by auto\n            have \"{e. e \\<in> Y \\<and> e = Tock} \\<inter> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q} = {}\"\n              using assm2 by auto\n            then have \"Tock \\<notin> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q}\"\n              using case_assm3 by auto\n            then have \"Tock \\<notin> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} \\<inter> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q}\"\n              using set2 case_assm by auto\n            then have \"({e. e \\<in> Y \\<and> e = Tock} \\<inter> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {} \\<and> {e. e \\<in> Y \\<and> e = Tock} \\<inter> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {})\n              \\<or> (\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<and> {e. e \\<in> Y \\<and> e = Tock} \\<inter> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {})\n              \\<or> ({e. e \\<in> Y \\<and> e = Tock} \\<inter> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {} \\<and> \\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> Q)\"\n              by auto\n            then have \"(Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {} \\<and> Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {})\n              \\<or> (\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<and> Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {})\n              \\<or> (Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {} \\<and> \\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> Q)\"\n              using assm2_nontock_P assm2_nontock_Q by (safe, blast+)\n            then show \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n            proof safe\n              assume case_assm4: \"Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {}\"\n              assume case_assm5: \"Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {}\"\n              show \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n                using in_P_or_Q case_assm case_assm2 \\<rho>2_def\n              proof auto\n                assume case_assm6: \"\\<rho>' @ [[X]\\<^sub>R] \\<in> P\"\n                then have \"\\<rho>' @ [[X \\<union> Y]\\<^sub>R] \\<in> P\"\n                  using TT2w_P_Q case_assm4 \\<rho>2_def case_assm unfolding TT2w_def by auto\n                also have \"\\<rho>' @ [[{e \\<in> X \\<union> Y. e \\<noteq> Tock}]\\<^sub>R] \\<in> Q\"\n                  using notock_X_Y_in_P_Q \\<rho>2_def case_assm by auto\n                then show \"\\<rho>' @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n                  unfolding ExtChoiceTT_def using calculation apply auto\n                apply (rule_tac x=\"\\<rho>'\" in bexI, simp_all add: \\<rho>_\\<sigma>_split case_assm)\n                apply (rule_tac x=\"[[X \\<union> Y]\\<^sub>R]\" in exI, simp_all)\n                apply (rule_tac x=\"[[{e \\<in> X \\<union> Y. e \\<noteq> Tock}]\\<^sub>R]\" in exI, auto)\n                using tt_prefix_notfront_is_whole end_refusal_notin_tocks by blast+\n              next\n                assume case_assm6: \"\\<rho>' @ [[X]\\<^sub>R] \\<in> Q\"\n                then have \"\\<rho>' @ [[X \\<union> Y]\\<^sub>R] \\<in> Q\"\n                  using TT2w_P_Q case_assm5 \\<rho>2_def case_assm unfolding TT2w_def by auto\n                also have \"\\<rho>' @ [[{e \\<in> X \\<union> Y. e \\<noteq> Tock}]\\<^sub>R] \\<in> P\"\n                  using notock_X_Y_in_P_Q \\<rho>2_def case_assm by auto\n                then show \"\\<rho>' @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n                  unfolding ExtChoiceTT_def using calculation apply auto\n                  apply (rule_tac x=\"\\<rho>'\" in bexI, simp_all add: \\<rho>_\\<sigma>_split case_assm)\n                  apply (rule_tac x=\"[[{e \\<in> X \\<union> Y. e \\<noteq> Tock}]\\<^sub>R]\" in exI, auto)\n                  apply (rule_tac x=\"[[X \\<union> Y]\\<^sub>R]\" in exI, simp_all)\n                  using tt_prefix_notfront_is_whole end_refusal_notin_tocks by blast+\n              qed\n            next\n              assume case_assm3: \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P\"\n              assume case_assm4: \"Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {}\"\n              have TT1_P: \"TT1 P\"\n                by (simp add: TT_TT1 assms(1))\n              have \"\\<rho> @ [[X]\\<^sub>R] \\<lesssim>\\<^sub>C \\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n                using tt_prefix_subset_same_front by fastforce\n              then have in_P: \"\\<rho> @ [[X]\\<^sub>R] \\<in> P\"\n                using TT1_P case_assm3 unfolding TT1_def by auto \n              have ttWFx_P: \"ttWFx P\"\n                by (simp add: TT_ttWFx assms(1))\n              then have \"Tock \\<notin> X\"\n                using ttWFx_any_cons_end_tock case_assm3 by blast\n              then have in_Q: \"\\<rho> @ [[X]\\<^sub>R] \\<in> Q\"\n                using assm1 case_assm2 unfolding ExtChoiceTT_def\n              proof auto\n                fix r s t :: \"'a ttobs list\"\n                assume 1: \"r \\<in> tocks UNIV\"\n                assume 2: \"r @ s \\<in> P\"\n                assume 3: \"r @ t \\<in> Q\"\n                assume 4: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C r @ s \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C r\"\n                assume 5: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C r @ t \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C r\"\n                assume 6: \"\\<forall>X. s = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. t = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n                assume 7: \"\\<forall>X. t = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. s = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n                assume 8: \"\\<rho> @ [[X]\\<^sub>R] = r @ s\"\n                assume 9: \"Tock \\<notin> X\"\n                have r_is_\\<rho>: \"r = \\<rho>\"\n                  by (metis \"1\" \"4\" \"8\" \\<rho>2_def \\<rho>_\\<sigma>_split append_Nil2 case_assm case_assm2 tt_prefix_antisym tt_prefix_concat)\n                then have \"s = [[X]\\<^sub>R]\"\n                  using \"8\" by blast\n                then obtain Y where Y_assms: \"t = [[Y]\\<^sub>R]\" \"\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock\"\n                  using \"6\" by auto\n                then have \"\\<rho> @ [[Y]\\<^sub>R] \\<in> Q\"\n                  using \"3\" r_is_\\<rho> by blast\n                also have \"\\<rho> @ [[X]\\<^sub>R] \\<lesssim>\\<^sub>C \\<rho> @ [[Y]\\<^sub>R]\"\n                  by (metis \"9\" Y_assms(2) tt_prefix_subset.simps(2) tt_prefix_subset_refl tt_prefix_subset_same_front subsetI)\n                then have \"\\<rho> @ [[X]\\<^sub>R] \\<in> Q\"\n                  using TT1_def TT_TT1 assms(2) calculation by blast\n                then show \"r @ s \\<in> Q\"\n                  using \"8\" by auto\n              qed\n              then have \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> Q\"\n                using TT2w_P_Q TT2w_def case_assm4 by blast\n              then show \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n                unfolding ExtChoiceTT_def using notock_X_Y_in_P_Q apply auto\n                apply (rule_tac x=\"\\<rho>'\" in bexI, simp_all add: \\<rho>_\\<sigma>_split case_assm)\n                apply (rule_tac x=\"[[{e \\<in> X \\<union> Y. e \\<noteq> Tock}]\\<^sub>R]\" in exI, auto simp add: \\<rho>2_def case_assm)\n                apply (rule_tac x=\"[[X \\<union> Y]\\<^sub>R]\" in exI, simp_all)\n                using tt_prefix_notfront_is_whole end_refusal_notin_tocks by blast+\n            next\n              assume case_assm4: \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> Q\"\n              assume case_assm5: \"Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {}\"\n              have TT1_Q: \"TT1 Q\"\n                by (simp add: TT_TT1 assms(2))\n              have \"\\<rho> @ [[X]\\<^sub>R] \\<lesssim>\\<^sub>C \\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\"\n                using tt_prefix_subset_same_front by fastforce\n              then have in_Q: \"\\<rho> @ [[X]\\<^sub>R] \\<in> Q\"\n                using TT1_Q TT1_def case_assm4 by blast\n              have ttWFx_Q: \"ttWFx Q\"\n                by (simp add: TT_ttWFx assms(2))\n              then have \"Tock \\<notin> X\"\n                using ttWFx_any_cons_end_tock case_assm4 by blast\n              then have in_P: \"\\<rho> @ [[X]\\<^sub>R] \\<in> P\"\n                using assm1 case_assm2 unfolding ExtChoiceTT_def\n              proof auto\n                fix r s t :: \"'a ttobs list\"\n                assume 1: \"r \\<in> tocks UNIV\"\n                assume 2: \"r @ s \\<in> P\"\n                assume 3: \"r @ t \\<in> Q\"\n                assume 4: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C r @ s \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C r\"\n                assume 5: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C r @ t \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C r\"\n                assume 6: \"\\<forall>X. s = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. t = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n                assume 7: \"\\<forall>X. t = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. s = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n                assume 8: \"\\<rho> @ [[X]\\<^sub>R] = r @ t\"\n                assume 9: \"Tock \\<notin> X\"\n                have r_is_\\<rho>: \"r = \\<rho>\"\n                  by (metis \"1\" \"5\" \"8\" \\<rho>2_def \\<rho>_\\<sigma>_split append_Nil2 case_assm case_assm2 tt_prefix_antisym tt_prefix_concat)\n              then have \"t = [[X]\\<^sub>R]\"\n                using \"8\" by blast\n              then obtain Y where Y_assms: \"s = [[Y]\\<^sub>R]\" \"\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock\"\n                using \"7\" by auto\n              then have \"\\<rho> @ [[Y]\\<^sub>R] \\<in> P\"\n                using \"2\" r_is_\\<rho> by blast\n              also have \"\\<rho> @ [[X]\\<^sub>R] \\<lesssim>\\<^sub>C \\<rho> @ [[Y]\\<^sub>R]\"\n                by (metis \"9\" Y_assms(2) tt_prefix_subset.simps(2) tt_prefix_subset_refl tt_prefix_subset_same_front subsetI)\n              then have \"\\<rho> @ [[X]\\<^sub>R] \\<in> P\"\n                using TT1_def TT_TT1 assms(1) calculation by blast\n              then show \"r @ t \\<in> P\"\n                using \"8\" by auto\n            qed\n            then have \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P\"\n              using TT2w_P_Q TT2w_def case_assm5 by blast\n            then show \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n              unfolding ExtChoiceTT_def using notock_X_Y_in_P_Q apply auto\n              apply (rule_tac x=\"\\<rho>'\" in bexI, simp_all add: \\<rho>_\\<sigma>_split case_assm)\n              apply (rule_tac x=\"[[X \\<union> Y]\\<^sub>R]\" in exI, simp_all add: \\<rho>2_def case_assm)\n              apply (rule_tac x=\"[[{e \\<in> X \\<union> Y. e \\<noteq> Tock}]\\<^sub>R]\" in exI, auto)\n              using tt_prefix_notfront_is_whole end_refusal_notin_tocks by blast+\n          qed\n        next\n          assume case_assm3: \"Tock \\<notin> Y\"\n          then have \"Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q}\n            = {e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q}\"\n            by auto\n          also have \"... = {e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q}\"\n            by auto\n          also have \"... = {e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> ({e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P} \\<union> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q})\"\n            using set1 by auto\n          also have \"... = ({e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P}) \\<union> ({e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q})\"\n            by auto\n          also have \"... = ({e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P}) \n            \\<union> ({e. e \\<in> Y \\<and> e \\<noteq> Tock} \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q})\"\n            by auto\n          also have \"... = (Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P}) \n            \\<union> (Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q})\"\n            using case_assm3 by auto\n          then have assm2_expand: \"Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {}\n              \\<and> Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {}\"\n            using calculation assm2 by auto\n          show \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n            using in_P_or_Q case_assm2\n          proof auto\n            assume  case_assm4: \"\\<rho> @ [[X]\\<^sub>R] \\<in> P\"\n            have \"TT2w P\"\n              by (simp add: TT2w_P_Q)\n            then have \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P\"\n              unfolding TT2w_def using case_assm4 assm2_expand by auto\n            then show  \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n              unfolding ExtChoiceTT_def using notock_X_Y_in_P_Q apply auto\n              apply (rule_tac x=\"\\<rho>'\" in bexI, simp_all add: \\<rho>_\\<sigma>_split case_assm)\n              apply (rule_tac x=\"[[X \\<union> Y]\\<^sub>R]\" in exI, simp_all add: \\<rho>2_def case_assm)\n              apply (rule_tac x=\"[[{e \\<in> X \\<union> Y. e \\<noteq> Tock}]\\<^sub>R]\" in exI, auto)\n              using tt_prefix_notfront_is_whole end_refusal_notin_tocks by blast+\n          next\n            assume  case_assm4: \"\\<rho> @ [[X]\\<^sub>R] \\<in> Q\"\n            have \"TT2w Q\"\n              by (simp add: TT2w_P_Q)\n            then have \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> Q\"\n              unfolding TT2w_def using case_assm4 assm2_expand by auto\n            then show  \"\\<rho> @ [[X \\<union> Y]\\<^sub>R] \\<in> P \\<box>\\<^sub>C Q\"\n              unfolding ExtChoiceTT_def using notock_X_Y_in_P_Q apply auto\n              apply (rule_tac x=\"\\<rho>'\" in bexI, simp_all add: \\<rho>_\\<sigma>_split case_assm)\n              apply (rule_tac x=\"[[{e \\<in> X \\<union> Y. e \\<noteq> Tock}]\\<^sub>R]\" in exI, auto simp add: \\<rho>2_def case_assm)\n              apply (rule_tac x=\"[[X \\<union> Y]\\<^sub>R]\" in exI, simp_all)\n              using tt_prefix_notfront_is_whole end_refusal_notin_tocks by blast+\n          qed\n        qed\n      qed\n    qed\n  next\n    fix \\<sigma>'\n    assume case_assms: \"\\<rho>' = \\<rho> @ [X]\\<^sub>R # \\<sigma>'\" \"\\<sigma>' \\<noteq> []\" \"\\<sigma>' \\<le>\\<^sub>C \\<sigma>\"\n    have \\<rho>_Tock_in_tocks: \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> tocks UNIV\"\n      by (metis \\<rho>_\\<sigma>_split case_assms(1) tocks.empty_in_tocks tocks.tock_insert_in_tocks tocks_append_tocks tocks_mid_refusal tocks_mid_refusal_front_in_tocks)\n    obtain \\<sigma>'' where \\<sigma>'_Tock_start: \"\\<sigma>' = [Tock]\\<^sub>E # \\<sigma>''\"\n      using case_assms apply (cases \\<sigma>' rule:ttWF.cases, auto)\n      using TT_TTwf TTwf_cons_end_not_refusal_refusal \\<rho>'_in_P_Q assms(1) apply blast\n      using TT_TTwf TTwf_no_ill_Tock \\<rho>'_in_P_Q assms(1) apply blast\n      using \\<rho>'_\\<rho>''_wf \\<rho>_Tock_in_tocks tocks_append_wf2 tocks_mid_refusal_front_in_tocks apply fastforce\n      using \\<rho>'_\\<rho>''_wf \\<rho>_\\<sigma>_split ttWF.simps(13) ttWF_prefix_is_ttWF tocks_append_wf2 tocks_mid_refusal_front_in_tocks apply blast\n      using \\<rho>'_\\<rho>''_wf \\<rho>_\\<sigma>_split ttWF.simps(12) ttWF_prefix_is_ttWF tocks_append_wf2 tocks_mid_refusal_front_in_tocks apply (blast, blast)\n      using \\<rho>'_\\<rho>''_wf \\<rho>_\\<sigma>_split ttWF.simps(13) ttWF_prefix_is_ttWF tocks_append_wf2 tocks_mid_refusal_front_in_tocks apply blast+\n      done\n    then obtain \\<sigma>''' where \\<sigma>'''_def: \"\\<sigma> = [Tock]\\<^sub>E # \\<sigma>'' @ \\<sigma>'''\"\n      using case_assms(3) tt_prefix_decompose by fastforce\n    then have \"\\<rho> @ [X]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>'' @ \\<sigma>''' \\<in> P \\<box>\\<^sub>C Q\"\n      using assm1 by blast\n    then have \\<rho>_Tock_in_P_Q: \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P \\<and> \\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> Q\"\n      unfolding ExtChoiceTT_def\n    proof auto\n      fix \\<rho>' \\<sigma> \\<tau>\n      assume 1: \"\\<rho>' @ \\<sigma> \\<in> P\"\n      assume 2: \"\\<rho>' @ \\<tau> \\<in> Q\"\n      assume 3: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n      assume 4: \"\\<rho> @ [X]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>'' @ \\<sigma>''' = \\<rho>' @ \\<sigma>\"\n      have \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<le>\\<^sub>C \\<rho>'\"\n        using 3 4 apply (erule_tac x=\"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\" in ballE, simp_all add: \\<rho>_Tock_in_tocks)\n        by (metis \\<rho>_Tock_in_tocks tt_prefix.simps(1) tt_prefix.simps(2) tt_prefix_same_front)\n      then show \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P\"\n        by (meson \"1\" TT1_def TT_TT1 assms(1) tt_prefix_concat tt_prefix_imp_prefix_subset)\n    next\n      fix \\<rho>' \\<sigma> \\<tau>\n      assume 1: \"\\<rho>' @ \\<sigma> \\<in> P\"\n      assume 2: \"\\<rho>' @ \\<tau> \\<in> Q\"\n      assume 3: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n      assume 4: \"\\<rho> @ [X]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>'' @ \\<sigma>''' = \\<rho>' @ \\<sigma>\"\n      have \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<le>\\<^sub>C \\<rho>'\"\n        using 3 4 apply (erule_tac x=\"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\" in ballE, simp_all add: \\<rho>_Tock_in_tocks)\n        by (metis \\<rho>_Tock_in_tocks tt_prefix.simps(1) tt_prefix.simps(2) tt_prefix_same_front)\n      then show \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> Q\"\n        by (meson \"2\" TT1_def TT_TT1 assms(2) tt_prefix_concat tt_prefix_imp_prefix_subset)\n    next\n      fix \\<rho>' \\<sigma> \\<tau>\n      assume 1: \"\\<rho>' @ \\<sigma> \\<in> P\"\n      assume 2: \"\\<rho>' @ \\<tau> \\<in> Q\"\n      assume 3: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n      assume 4: \"\\<rho> @ [X]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>'' @ \\<sigma>''' = \\<rho>' @ \\<tau>\"\n      have \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<le>\\<^sub>C \\<rho>'\"\n        using 3 4 apply (erule_tac x=\"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\" in ballE, simp_all add: \\<rho>_Tock_in_tocks)\n        by (metis \\<rho>_Tock_in_tocks tt_prefix.simps(1) tt_prefix.simps(2) tt_prefix_same_front)\n      then show \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> Q\"\n        by (meson \"2\" TT1_def TT_TT1 assms(2) tt_prefix_concat tt_prefix_imp_prefix_subset)\n    next\n      fix \\<rho>' \\<sigma> \\<tau>\n      assume 1: \"\\<rho>' @ \\<sigma> \\<in> P\"\n      assume 2: \"\\<rho>' @ \\<tau> \\<in> Q\"\n      assume 3: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n      assume 4: \"\\<rho> @ [X]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>'' @ \\<sigma>''' = \\<rho>' @ \\<tau>\"\n      have \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<le>\\<^sub>C \\<rho>'\"\n        using 3 4 apply (erule_tac x=\"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\" in ballE, simp_all add: \\<rho>_Tock_in_tocks)\n        by (metis \\<rho>_Tock_in_tocks tt_prefix.simps(1) tt_prefix.simps(2) tt_prefix_same_front)\n      then show \"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E] \\<in> P\"\n        by (meson \"1\" TT1_def TT_TT1 assms(1) tt_prefix_concat tt_prefix_imp_prefix_subset)\n    qed\n    then have set1: \"{e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q} =\n        {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} \\<union> {e. e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q}\"\n      unfolding ExtChoiceTT_def apply auto\n      apply (rule_tac x=\"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\" in bexI, simp_all add: \\<rho>_Tock_in_tocks)\n      apply (rule_tac x=\"[]\" in exI, simp, rule_tac x=\"[]\" in exI, simp)\n      apply (rule_tac x=\"\\<rho> @ [[X]\\<^sub>R, [Tock]\\<^sub>E]\" in bexI, simp_all add: \\<rho>_Tock_in_tocks)\n      apply (rule_tac x=\"[]\" in exI, simp, rule_tac x=\"[]\" in exI, simp)\n      done\n    have set2: \"{e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q} =\n        {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P} \\<union> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q}\"\n      unfolding ExtChoiceTT_def apply auto\n      apply (rule_tac x=\"\\<rho>\" in bexI, rule_tac x=\"[[x]\\<^sub>E]\" in exI, simp, rule_tac x=\"[]\" in exI, simp)\n      apply (metis TT1_def TT_TT1 \\<rho>'_in_P_Q assms(2) case_assms(1) tt_prefix_concat tt_prefix_imp_prefix_subset tocks_tt_prefix_end_event)\n      using \\<rho>_\\<sigma>_split case_assms(1) tocks_mid_refusal_front_in_tocks apply blast\n      apply (rule_tac x=\"\\<rho>\" in bexI, rule_tac x=\"[]\" in exI, simp)\n      apply (metis TT1_def TT_TT1 \\<rho>'_in_P_Q assms(1) case_assms(1) tt_prefix_concat tt_prefix_imp_prefix_subset tocks_tt_prefix_end_event)\n      by (metis \\<rho>_\\<sigma>_split case_assms(1) tocks_mid_refusal_front_in_tocks)\n    have \"{e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P \\<box>\\<^sub>C Q} =\n        {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} \\<union> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q}\"\n      using set1 set2 by blast\n    then have set3: \"Y \\<inter> ({e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} \\<union> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q}) = {}\"\n      using assm2 by auto\n    have P_assm2: \"Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> P \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> P} = {}\"\n      using set3 by blast\n    have Q_assm2: \"Y \\<inter> {e. e \\<noteq> Tock \\<and> \\<rho> @ [[e]\\<^sub>E] \\<in> Q \\<or> e = Tock \\<and> \\<rho> @ [[X]\\<^sub>R, [e]\\<^sub>E] \\<in> Q} = {}\"\n      using set3 by blast\n    have \\<rho>'_subset: \"\\<rho> @ [X]\\<^sub>R # \\<sigma>' \\<subseteq>\\<^sub>C \\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma>'\"\n      by (metis tt_subset.simps(2) tt_subset_combine tt_subset_refl inf_sup_absorb inf_sup_ord(2))\n    have A: \"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma>' \\<in> tocks UNIV\"\n      by (metis \\<rho>'_subset \\<rho>_\\<sigma>_split case_assms(1) tocks_tt_subset2)\n    have \\<rho>_X_\\<sigma>'_longest_pretocks: \"\\<forall>t'\\<in>tocks UNIV. t' \\<le>\\<^sub>C \\<rho> @ [X]\\<^sub>R # \\<sigma> \\<longrightarrow> t' \\<le>\\<^sub>C \\<rho> @ [X]\\<^sub>R # \\<sigma>'\"\n      by (metis \\<rho>_\\<sigma>_split case_assms(1))\n    then have B: \"\\<forall>t'\\<in>tocks UNIV. t' \\<le>\\<^sub>C \\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma> \\<longrightarrow> t' \\<le>\\<^sub>C \\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma>'\"\n      using \\<rho>'_subset \\<sigma>'''_def \\<sigma>'_Tock_start tt_subset_longest_tocks4[where ?s1.0=\"\\<rho> @ [X]\\<^sub>R # \\<sigma>'\", where s1'=\"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma>'\"] by auto\n    have \"\\<rho> @ [X]\\<^sub>R # \\<sigma> \\<in> P \\<or> \\<rho> @ [X]\\<^sub>R # \\<sigma> \\<in> Q\"\n      using assm1 unfolding ExtChoiceTT_def by auto\n    then show \"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma> \\<in> P \\<box>\\<^sub>C Q\"\n    proof auto\n      assume in_P: \"\\<rho> @ [X]\\<^sub>R # \\<sigma> \\<in> P\"\n      have 1: \"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma> \\<in> P\"\n        using assms(3) P_assm2 in_P unfolding TT2_def by force\n      have 2: \"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma>' \\<in> Q\"\n        using assms(4) Q_assm2 \\<rho>'_in_P_Q case_assms unfolding TT2_def by force\n      show \"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma> \\<in> P \\<box>\\<^sub>C Q\"\n      proof (cases \"\\<exists> Z. \\<sigma>''' = [[Z]\\<^sub>R]\", auto)\n        fix Z\n        assume \\<sigma>'''_is_ref: \"\\<sigma>''' = [[Z]\\<^sub>R]\"\n        then have \"\\<exists> W. \\<rho> @ [X]\\<^sub>R # \\<sigma>' @ [[W]\\<^sub>R] \\<in> Q \\<and> (\\<forall>e. (e \\<in> W) = (e \\<in> Z) \\<or> e = Tock)\"\n          using assm1 in_P \\<sigma>'''_def \\<sigma>'_Tock_start unfolding ExtChoiceTT_def\n        proof auto\n          fix \\<rho>' \\<sigma>'''' \\<tau> :: \"'a ttobs list\"\n          assume 1: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma>'''' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n          assume 2: \"\\<rho> @ [X]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>'' @ [[Z]\\<^sub>R] = \\<rho>' @ \\<sigma>''''\"\n          assume 3: \"\\<rho>' \\<in> tocks UNIV\"\n          assume 4: \"\\<forall>X. \\<sigma>'''' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n          assume 5: \"\\<rho>' @ \\<tau> \\<in> Q\"\n          have \"\\<rho> @ [X]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>'' \\<le>\\<^sub>C \\<rho>'\"\n            by (metis 1 2 \\<rho>_\\<sigma>_split \\<sigma>'''_def \\<sigma>'''_is_ref \\<sigma>'_Tock_start case_assms(1) tt_prefix_concat)\n          then have \\<rho>'_def: \"\\<rho>' = \\<rho> @ [X]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>''\"\n            using \"2\" \"3\" \\<rho>_X_\\<sigma>'_longest_pretocks \\<sigma>'''_def \\<sigma>'''_is_ref \\<sigma>'_Tock_start tt_prefix_antisym tt_prefix_concat by fastforce\n          then have \"\\<sigma>'''' = [[Z]\\<^sub>R]\"\n            using \"2\" by auto\n          then show \"\\<exists>W. \\<rho> @ [X]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>'' @ [[W]\\<^sub>R] \\<in> Q \\<and> (\\<forall>e. (e \\<in> W) = (e \\<in> Z) \\<or> e = Tock)\"\n            using 4 5 \\<rho>'_def by auto\n        next\n          fix \\<rho>' \\<sigma>'''' \\<tau> :: \"'a ttobs list\"\n          assume 1: \"\\<rho>' @ \\<tau> \\<in> Q\" \"\\<rho> @ [X]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>'' @ [[Z]\\<^sub>R] = \\<rho>' @ \\<tau>\"\n          then show \"\\<exists>W. \\<rho> @ [X]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>'' @ [[W]\\<^sub>R] \\<in> Q \\<and> (\\<forall>e. (e \\<in> W) = (e \\<in> Z) \\<or> e = Tock)\"\n            by force\n        qed\n        then obtain W where \"\\<rho> @ [X]\\<^sub>R # \\<sigma>' @ [[W]\\<^sub>R] \\<in> Q \\<and> (\\<forall>e. (e \\<in> W) = (e \\<in> Z) \\<or> e = Tock)\"\n          by blast\n        then have C: \"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma>' @ [[W]\\<^sub>R] \\<in> Q \\<and> (\\<forall>e. (e \\<in> W) = (e \\<in> Z) \\<or> e = Tock)\"\n          using assms(4) Q_assm2 unfolding TT2_def by auto\n        have D: \"\\<forall> t\\<in>tocks UNIV. t \\<le>\\<^sub>C \\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma>' @ [[W]\\<^sub>R] \\<longrightarrow> t \\<le>\\<^sub>C \\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma>'\"\n          using tt_prefix_notfront_is_whole end_refusal_notin_tocks by force\n        show \"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma> \\<in> P \\<box>\\<^sub>C Q\"\n          unfolding ExtChoiceTT_def using in_P \\<sigma>'''_is_ref \\<sigma>'''_def \\<sigma>'_Tock_start \\<rho>_\\<sigma>_split case_assms 1 2 A B C D apply auto\n          by (rule_tac x=\"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma>'\" in bexI, auto, rule_tac x=\"\\<sigma>'''\" in exI, auto, rule_tac x=\"[[W]\\<^sub>R]\" in exI, blast)\n      next\n        show \"\\<forall>Z. \\<sigma>''' \\<noteq> [[Z]\\<^sub>R] \\<Longrightarrow> \\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma> \\<in> P \\<box>\\<^sub>C Q\"\n          unfolding ExtChoiceTT_def using in_P \\<sigma>'''_def \\<sigma>'_Tock_start \\<rho>_\\<sigma>_split case_assms 1 2 A B apply auto\n          by (rule_tac x=\"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma>'\" in bexI, auto, rule_tac x=\"\\<sigma>'''\" in exI, auto, rule_tac x=\"[]\" in exI, auto)\n      qed\n    next\n      assume in_Q: \"\\<rho> @ [X]\\<^sub>R # \\<sigma> \\<in> Q\"\n      have 1: \"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma> \\<in> Q\"\n        using assms(4) Q_assm2 in_Q unfolding TT2_def by force\n      have 2: \"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma>' \\<in> P\"\n        using assms(3) P_assm2 \\<rho>'_in_P_Q case_assms unfolding TT2_def by force\n      show \"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma> \\<in> P \\<box>\\<^sub>C Q\"\n      proof (cases \"\\<exists> Z. \\<sigma>''' = [[Z]\\<^sub>R]\", auto)\n        fix Z\n        assume \\<sigma>'''_is_ref: \"\\<sigma>''' = [[Z]\\<^sub>R]\"\n        then have \"\\<exists> W. \\<rho> @ [X]\\<^sub>R # \\<sigma>' @ [[W]\\<^sub>R] \\<in> P \\<and> (\\<forall>e. (e \\<in> W) = (e \\<in> Z) \\<or> e = Tock)\"\n          using assm1 in_Q \\<sigma>'''_def \\<sigma>'_Tock_start unfolding ExtChoiceTT_def\n        proof auto\n          fix \\<rho>' \\<sigma>'''' \\<tau> :: \"'a ttobs list\"\n          assume 1: \"\\<rho>' @ \\<sigma>'''' \\<in> P\" \"\\<rho> @ [X]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>'' @ [[Z]\\<^sub>R] = \\<rho>' @ \\<sigma>''''\"\n          then show \"\\<exists>W. \\<rho> @ [X]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>'' @ [[W]\\<^sub>R] \\<in> P \\<and> (\\<forall>e. (e \\<in> W) = (e \\<in> Z) \\<or> e = Tock)\"\n            by force\n        next\n          fix \\<rho>' \\<sigma>'''' \\<tau> :: \"'a ttobs list\"\n          assume 1: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n          assume 2: \"\\<rho> @ [X]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>'' @ [[Z]\\<^sub>R] = \\<rho>' @ \\<tau>\"\n          assume 3: \"\\<rho>' \\<in> tocks UNIV\"\n          assume 4: \"\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma>'''' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n          assume 5: \"\\<rho>' @ \\<sigma>'''' \\<in> P\"\n          have \"\\<rho> @ [X]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>'' \\<le>\\<^sub>C \\<rho>'\"\n            by (metis 1 2 \\<rho>_\\<sigma>_split \\<sigma>'''_def \\<sigma>'''_is_ref \\<sigma>'_Tock_start case_assms(1) tt_prefix_concat)\n          then have \\<rho>'_def: \"\\<rho>' = \\<rho> @ [X]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>''\"\n            using \"2\" \"3\" \\<rho>_X_\\<sigma>'_longest_pretocks \\<sigma>'''_def \\<sigma>'''_is_ref \\<sigma>'_Tock_start tt_prefix_antisym tt_prefix_concat by fastforce\n          then have \"\\<tau> = [[Z]\\<^sub>R]\"\n            using \"2\" by auto\n          then show \"\\<exists>W. \\<rho> @ [X]\\<^sub>R # [Tock]\\<^sub>E # \\<sigma>'' @ [[W]\\<^sub>R] \\<in> P \\<and> (\\<forall>e. (e \\<in> W) = (e \\<in> Z) \\<or> e = Tock)\"\n            using 4 5 \\<rho>'_def by auto\n        qed\n        then obtain W where \"\\<rho> @ [X]\\<^sub>R # \\<sigma>' @ [[W]\\<^sub>R] \\<in> P \\<and> (\\<forall>e. (e \\<in> W) = (e \\<in> Z) \\<or> e = Tock)\"\n          by blast\n        then have C: \"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma>' @ [[W]\\<^sub>R] \\<in> P \\<and> (\\<forall>e. (e \\<in> W) = (e \\<in> Z) \\<or> e = Tock)\"\n          using assms(3) P_assm2 unfolding TT2_def by auto\n        have D: \"\\<forall> t\\<in>tocks UNIV. t \\<le>\\<^sub>C \\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma>' @ [[W]\\<^sub>R] \\<longrightarrow> t \\<le>\\<^sub>C \\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma>'\"\n          using tt_prefix_notfront_is_whole end_refusal_notin_tocks by force\n        show \"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma> \\<in> P \\<box>\\<^sub>C Q\"\n          unfolding ExtChoiceTT_def using in_Q \\<sigma>'''_is_ref \\<sigma>'''_def \\<sigma>'_Tock_start \\<rho>_\\<sigma>_split case_assms 1 2 A B C D apply auto\n          by (rule_tac x=\"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma>'\" in bexI, auto, rule_tac x=\"[[W]\\<^sub>R]\" in exI, auto)\n      next\n        show \"\\<forall>Z. \\<sigma>''' \\<noteq> [[Z]\\<^sub>R] \\<Longrightarrow> \\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma> \\<in> P \\<box>\\<^sub>C Q\"\n          unfolding ExtChoiceTT_def using in_Q \\<sigma>'''_def \\<sigma>'_Tock_start \\<rho>_\\<sigma>_split case_assms 1 2 A B apply auto\n          by (rule_tac x=\"\\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma>'\" in bexI, auto, rule_tac x=\"[]\" in exI, auto)\n      qed\n    qed\n  qed\nqed\n\nlemma ttWFx_ExtChoice: \n  assumes \"ttWFx P\" \"ttWFx Q\"\n  shows \"ttWFx (P \\<box>\\<^sub>C Q)\"\n  using assms unfolding ttWFx_def ExtChoiceTT_def by auto\n\nlemma TT3w_ExtChoice:\n  assumes \"TT3w P\" \"TT3w Q\"\n  shows \"TT3w (P \\<box>\\<^sub>C Q)\"\n  unfolding TT3w_def ExtChoiceTT_def\nproof auto\n  fix \\<rho>' \\<sigma> \\<tau> :: \"'a ttobs list\"\n  assume assm1: \"\\<rho>' \\<in> tocks UNIV\"\n  assume assm2: \"\\<rho>' @ \\<sigma> \\<in> P\"\n  assume assm3: \"\\<rho>' @ \\<tau> \\<in> Q\"\n  assume assm4: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n  assume assm5: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n  assume assm6: \"\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume assm7: \"\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  have 1: \"add_Tick_refusal_trace \\<rho>' \\<in> tocks UNIV\"\n    using TT3w_def TT3w_tocks assm1 by blast\n  have 2: \"add_Tick_refusal_trace \\<rho>' @ add_Tick_refusal_trace \\<sigma> \\<in> P\"\n    using assms(1) assm2 unfolding TT3w_def by (erule_tac x=\"\\<rho>' @ \\<sigma>\" in allE, auto simp add: add_Tick_refusal_trace_concat)\n  have 3: \"add_Tick_refusal_trace \\<rho>' @ add_Tick_refusal_trace \\<tau> \\<in> Q\"\n    using assms(2) assm3 unfolding TT3w_def by (erule_tac x=\"\\<rho>' @ \\<tau>\" in allE, auto simp add: add_Tick_refusal_trace_concat)\n  have 4: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C add_Tick_refusal_trace \\<rho>' @ add_Tick_refusal_trace \\<sigma> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C add_Tick_refusal_trace \\<rho>'\"\n  proof auto\n    fix \\<rho>''\n    assume assms2: \"\\<rho>'' \\<in> tocks UNIV\" \"\\<rho>'' \\<le>\\<^sub>C add_Tick_refusal_trace \\<rho>' @ add_Tick_refusal_trace \\<sigma>\"\n    then obtain \\<rho>''' where \\<rho>'''_assms: \"\\<rho>''' \\<subseteq>\\<^sub>C \\<rho>'' \\<and> \\<rho>''' \\<le>\\<^sub>C \\<rho>' @ \\<sigma>\"\n      by (metis add_Tick_refusal_trace_concat add_Tick_refusal_trace_tt_subset tt_prefix_tt_subset)\n    then have \"\\<rho>''' \\<in> tocks UNIV\"\n      using assms2(1) tocks_tt_subset1 by blast\n    then have \"\\<rho>''' \\<le>\\<^sub>C \\<rho>'\"\n      using \\<rho>'''_assms assm4 by blast\n    then show \"\\<rho>'' \\<le>\\<^sub>C add_Tick_refusal_trace \\<rho>'\"\n      by (smt \\<rho>'''_assms add_Tick_refusal_trace_concat add_Tick_refusal_trace_tt_subset append_eq_append_conv assms2(2) tt_prefix_concat tt_prefix_split tt_subset_same_length)\n  qed\n  have 5: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C add_Tick_refusal_trace \\<rho>' @ add_Tick_refusal_trace \\<tau> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C add_Tick_refusal_trace \\<rho>'\"\n  proof auto\n    fix \\<rho>''\n    assume assms2: \"\\<rho>'' \\<in> tocks UNIV\" \"\\<rho>'' \\<le>\\<^sub>C add_Tick_refusal_trace \\<rho>' @ add_Tick_refusal_trace \\<tau>\"\n    then obtain \\<rho>''' where \\<rho>'''_assms: \"\\<rho>''' \\<subseteq>\\<^sub>C \\<rho>'' \\<and> \\<rho>''' \\<le>\\<^sub>C \\<rho>' @ \\<tau>\"\n      by (metis add_Tick_refusal_trace_concat add_Tick_refusal_trace_tt_subset tt_prefix_tt_subset)\n    then have \"\\<rho>''' \\<in> tocks UNIV\"\n      using assms2(1) tocks_tt_subset1 by blast\n    then have \"\\<rho>''' \\<le>\\<^sub>C \\<rho>'\"\n      using \\<rho>'''_assms assm5 by blast\n    then show \"\\<rho>'' \\<le>\\<^sub>C add_Tick_refusal_trace \\<rho>'\"\n      by (smt \\<rho>'''_assms add_Tick_refusal_trace_concat add_Tick_refusal_trace_tt_subset append_eq_append_conv assms2(2) tt_prefix_concat tt_prefix_split tt_subset_same_length)\n  qed\n  have 6: \"\\<forall>X. add_Tick_refusal_trace \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. add_Tick_refusal_trace \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  proof auto\n    fix X\n    assume \"add_Tick_refusal_trace \\<sigma> = [[X]\\<^sub>R]\"\n    then obtain X' where X'_assms: \"\\<sigma> = [[X']\\<^sub>R] \\<and> X = X' \\<union> {Tick}\"\n      apply (cases \\<sigma> rule:add_Tick_refusal_trace.cases, simp_all)\n      using add_Tick_refusal_trace.elims by blast\n    then obtain Y' where Y'_assms: \"\\<tau> = [[Y']\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X') = (e \\<in> Y') \\<or> e = Tock)\"\n      using assm6 by blast\n    then show \"\\<exists>Y. add_Tick_refusal_trace \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock)\"\n      using X'_assms by (rule_tac x=\"Y' \\<union> {Tick}\" in exI, auto)\n  qed\n  have 7: \"\\<forall>X. add_Tick_refusal_trace \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. add_Tick_refusal_trace \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  proof auto\n    fix X\n    assume \"add_Tick_refusal_trace \\<tau> = [[X]\\<^sub>R]\"\n    then obtain X' where X'_assms: \"\\<tau> = [[X']\\<^sub>R] \\<and> X = X' \\<union> {Tick}\"\n      apply (cases \\<tau> rule:add_Tick_refusal_trace.cases, simp_all)\n      using add_Tick_refusal_trace.elims by blast\n    then obtain Y' where Y'_assms: \"\\<sigma> = [[Y']\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X') = (e \\<in> Y') \\<or> e = Tock)\"\n      using assm7 by blast\n    then show \"\\<exists>Y. add_Tick_refusal_trace \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock)\"\n      using X'_assms by (rule_tac x=\"Y' \\<union> {Tick}\" in exI, auto)\n  qed\n  show \"\\<exists>\\<rho>\\<in>tocks UNIV.\n    \\<exists>\\<sigma>'. \\<rho> @ \\<sigma>' \\<in> P \\<and>\n      (\\<exists>\\<tau>. \\<rho> @ \\<tau> \\<in> Q \\<and>\n        (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma>' \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n        (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n        (\\<forall>X. \\<sigma>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n        (\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n        (add_Tick_refusal_trace (\\<rho>' @ \\<sigma>) = \\<rho> @ \\<sigma>' \\<or> add_Tick_refusal_trace (\\<rho>' @ \\<sigma>) = \\<rho> @ \\<tau>))\"\n    using 1 2 3 4 5 6 7 apply (rule_tac x=\"add_Tick_refusal_trace \\<rho>'\" in bexI, auto)\n    apply (rule_tac x=\"add_Tick_refusal_trace \\<sigma>\" in exI, auto)\n    apply (rule_tac x=\"add_Tick_refusal_trace \\<tau>\" in exI, auto)\n    by (simp add: add_Tick_refusal_trace_concat)\nnext\n  fix \\<rho>' \\<sigma> \\<tau> :: \"'a ttobs list\"\n  assume assm1: \"\\<rho>' \\<in> tocks UNIV\"\n  assume assm2: \"\\<rho>' @ \\<sigma> \\<in> P\"\n  assume assm3: \"\\<rho>' @ \\<tau> \\<in> Q\"\n  assume assm4: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n  assume assm5: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n  assume assm6: \"\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume assm7: \"\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  have 1: \"add_Tick_refusal_trace \\<rho>' \\<in> tocks UNIV\"\n    using TT3w_def TT3w_tocks assm1 by blast\n  have 2: \"add_Tick_refusal_trace \\<rho>' @ add_Tick_refusal_trace \\<sigma> \\<in> P\"\n    using assms(1) assm2 unfolding TT3w_def by (erule_tac x=\"\\<rho>' @ \\<sigma>\" in allE, auto simp add: add_Tick_refusal_trace_concat)\n  have 3: \"add_Tick_refusal_trace \\<rho>' @ add_Tick_refusal_trace \\<tau> \\<in> Q\"\n    using assms(2) assm3 unfolding TT3w_def by (erule_tac x=\"\\<rho>' @ \\<tau>\" in allE, auto simp add: add_Tick_refusal_trace_concat)\n  have 4: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C add_Tick_refusal_trace \\<rho>' @ add_Tick_refusal_trace \\<sigma> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C add_Tick_refusal_trace \\<rho>'\"\n  proof auto\n    fix \\<rho>''\n    assume assms2: \"\\<rho>'' \\<in> tocks UNIV\" \"\\<rho>'' \\<le>\\<^sub>C add_Tick_refusal_trace \\<rho>' @ add_Tick_refusal_trace \\<sigma>\"\n    then obtain \\<rho>''' where \\<rho>'''_assms: \"\\<rho>''' \\<subseteq>\\<^sub>C \\<rho>'' \\<and> \\<rho>''' \\<le>\\<^sub>C \\<rho>' @ \\<sigma>\"\n      by (metis add_Tick_refusal_trace_concat add_Tick_refusal_trace_tt_subset tt_prefix_tt_subset)\n    then have \"\\<rho>''' \\<in> tocks UNIV\"\n      using assms2(1) tocks_tt_subset1 by blast\n    then have \"\\<rho>''' \\<le>\\<^sub>C \\<rho>'\"\n      using \\<rho>'''_assms assm4 by blast\n    then show \"\\<rho>'' \\<le>\\<^sub>C add_Tick_refusal_trace \\<rho>'\"\n      by (smt \\<rho>'''_assms add_Tick_refusal_trace_concat add_Tick_refusal_trace_tt_subset append_eq_append_conv assms2(2) tt_prefix_concat tt_prefix_split tt_subset_same_length)\n  qed\n  have 5: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C add_Tick_refusal_trace \\<rho>' @ add_Tick_refusal_trace \\<tau> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C add_Tick_refusal_trace \\<rho>'\"\n  proof auto\n    fix \\<rho>''\n    assume assms2: \"\\<rho>'' \\<in> tocks UNIV\" \"\\<rho>'' \\<le>\\<^sub>C add_Tick_refusal_trace \\<rho>' @ add_Tick_refusal_trace \\<tau>\"\n    then obtain \\<rho>''' where \\<rho>'''_assms: \"\\<rho>''' \\<subseteq>\\<^sub>C \\<rho>'' \\<and> \\<rho>''' \\<le>\\<^sub>C \\<rho>' @ \\<tau>\"\n      by (metis add_Tick_refusal_trace_concat add_Tick_refusal_trace_tt_subset tt_prefix_tt_subset)\n    then have \"\\<rho>''' \\<in> tocks UNIV\"\n      using assms2(1) tocks_tt_subset1 by blast\n    then have \"\\<rho>''' \\<le>\\<^sub>C \\<rho>'\"\n      using \\<rho>'''_assms assm5 by blast\n    then show \"\\<rho>'' \\<le>\\<^sub>C add_Tick_refusal_trace \\<rho>'\"\n      by (smt \\<rho>'''_assms add_Tick_refusal_trace_concat add_Tick_refusal_trace_tt_subset append_eq_append_conv assms2(2) tt_prefix_concat tt_prefix_split tt_subset_same_length)\n  qed\n  have 6: \"\\<forall>X. add_Tick_refusal_trace \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. add_Tick_refusal_trace \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  proof auto\n    fix X\n    assume \"add_Tick_refusal_trace \\<sigma> = [[X]\\<^sub>R]\"\n    then obtain X' where X'_assms: \"\\<sigma> = [[X']\\<^sub>R] \\<and> X = X' \\<union> {Tick}\"\n      apply (cases \\<sigma> rule:add_Tick_refusal_trace.cases, simp_all)\n      using add_Tick_refusal_trace.elims by blast\n    then obtain Y' where Y'_assms: \"\\<tau> = [[Y']\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X') = (e \\<in> Y') \\<or> e = Tock)\"\n      using assm6 by blast\n    then show \"\\<exists>Y. add_Tick_refusal_trace \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock)\"\n      using X'_assms by (rule_tac x=\"Y' \\<union> {Tick}\" in exI, auto)\n  qed\n  have 7: \"\\<forall>X. add_Tick_refusal_trace \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. add_Tick_refusal_trace \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  proof auto\n    fix X\n    assume \"add_Tick_refusal_trace \\<tau> = [[X]\\<^sub>R]\"\n    then obtain X' where X'_assms: \"\\<tau> = [[X']\\<^sub>R] \\<and> X = X' \\<union> {Tick}\"\n      apply (cases \\<tau> rule:add_Tick_refusal_trace.cases, simp_all)\n      using add_Tick_refusal_trace.elims by blast\n    then obtain Y' where Y'_assms: \"\\<sigma> = [[Y']\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X') = (e \\<in> Y') \\<or> e = Tock)\"\n      using assm7 by blast\n    then show \"\\<exists>Y. add_Tick_refusal_trace \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock)\"\n      using X'_assms by (rule_tac x=\"Y' \\<union> {Tick}\" in exI, auto)\n  qed\n  show \"\\<exists>\\<rho>\\<in>tocks UNIV.\n    \\<exists>\\<sigma>. \\<rho> @ \\<sigma> \\<in> P \\<and>\n      (\\<exists>\\<tau>'. \\<rho> @ \\<tau>' \\<in> Q \\<and>\n        (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n        (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau>' \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n        (\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n        (\\<forall>X. \\<tau>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n        (add_Tick_refusal_trace (\\<rho>' @ \\<tau>) = \\<rho> @ \\<sigma> \\<or> add_Tick_refusal_trace (\\<rho>' @ \\<tau>) = \\<rho> @ \\<tau>'))\"\n    using 1 2 3 4 5 6 7 apply (rule_tac x=\"add_Tick_refusal_trace \\<rho>'\" in bexI, auto)\n    apply (rule_tac x=\"add_Tick_refusal_trace \\<sigma>\" in exI, auto)\n    apply (rule_tac x=\"add_Tick_refusal_trace \\<tau>\" in exI, auto)\n    by (simp add: add_Tick_refusal_trace_concat)\nqed\n\nlemma TT3_ExtChoice: \n  assumes \"TT P\" \"TT Q\" \"TT3 P\" \"TT3 Q\"\n  shows \"TT3 (P \\<box>\\<^sub>C Q)\"\nproof -\n  have \"TT1 (P \\<box>\\<^sub>C Q)\"\n    by (simp add: TT1_ExtChoice assms)\n  then show ?thesis\n    using TT1_TT3w_equiv_TT3 TT3w_ExtChoice TT_def assms by blast\nqed\n\nlemma TT_ExtChoice:\n  assumes \"TT P\" \"TT Q\"\n  shows \"TT (P \\<box>\\<^sub>C Q)\"\n  unfolding TT_def apply auto\n  apply (metis TT_def ExtChoiceTT_wf assms(1) assms(2))\n  apply (simp add: TT0_ExtChoice assms(1) assms(2))\n  apply (simp add: TT1_ExtChoice assms(1) assms(2))\n  apply (simp add: TT2w_ExtChoice assms(1) assms(2))\n  apply  (simp add: ttWFx_ExtChoice TT_ttWFx assms(1) assms(2))\n  done\n\nlemma ExtChoice_comm: \"P \\<box>\\<^sub>C Q = Q \\<box>\\<^sub>C P\"\n  unfolding ExtChoiceTT_def by auto\n\nlemma ExtChoice_union_dist: \"P \\<box>\\<^sub>C (Q \\<union> R) = (P \\<box>\\<^sub>C Q) \\<union> (P \\<box>\\<^sub>C R)\"\n  unfolding ExtChoiceTT_def by (safe, blast+)\n\nlemma ExtChoice_subset_union: \"P \\<box>\\<^sub>C Q \\<subseteq> P \\<union> Q\"\n  unfolding ExtChoiceTT_def by auto\n\nlemma ExtChoice_assoc: \"P \\<box>\\<^sub>C (Q \\<box>\\<^sub>C R) = (P \\<box>\\<^sub>C Q) \\<box>\\<^sub>C R\"\n  unfolding ExtChoiceTT_def\nproof (safe, simp_all)\n  fix \\<rho> \\<sigma> \\<tau> \\<rho>' \\<sigma>' \\<tau>' :: \"'a tttrace\"\n  assume in_P: \"\\<rho> @ \\<sigma> \\<in> P\" and in_Q: \"\\<rho>' @ \\<sigma>' \\<in> Q\" and in_R: \"\\<rho>' @ \\<tau>' \\<in> R\"\n  assume \\<rho>_in_tocks: \"\\<rho> \\<in> tocks UNIV\" and \\<rho>'_in_tocks: \"\\<rho>' \\<in> tocks UNIV\"\n  assume \\<rho>_longest_\\<sigma>: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<rho>_longest_\\<tau>: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<rho>'_longest_\\<sigma>': \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n  assume \\<rho>'_longest_\\<tau>': \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n  assume \\<sigma>_refusal: \"\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<tau>_refusal: \"\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<sigma>'_refusal: \"\\<forall>X. \\<sigma>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<tau>'_refusal: \"\\<forall>X. \\<tau>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<rho>_\\<tau>_eq_\\<rho>'_\\<sigma>': \"\\<rho> @ \\<tau> = \\<rho>' @ \\<sigma>'\"\n  have \\<rho>_eq_\\<rho>': \"\\<rho> = \\<rho>'\"\n    by (metis \\<rho>'_in_tocks \\<rho>'_longest_\\<sigma>' \\<rho>_\\<tau>_eq_\\<rho>'_\\<sigma>' \\<rho>_in_tocks \\<rho>_longest_\\<tau> tt_prefix_antisym tt_prefix_concat)\n  show \"\\<exists>\\<rho>'\\<in>tocks UNIV.\n          \\<exists>\\<sigma>'. (\\<exists>\\<rho>\\<in>tocks UNIV.\n                   \\<exists>\\<sigma>. \\<rho> @ \\<sigma> \\<in> P \\<and>\n                       (\\<exists>\\<tau>. \\<rho> @ \\<tau> \\<in> Q \\<and>\n                            (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                            (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                            (\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                            (\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                            (\\<rho>' @ \\<sigma>' = \\<rho> @ \\<sigma> \\<or> \\<rho>' @ \\<sigma>' = \\<rho> @ \\<tau>))) \\<and>\n               (\\<exists>\\<tau>. \\<rho>' @ \\<tau> \\<in> R \\<and>\n                    (\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>') \\<and>\n                    (\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>') \\<and>\n                    (\\<forall>X. \\<sigma>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                    (\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                    (\\<rho> @ \\<sigma> = \\<rho>' @ \\<sigma>' \\<or> \\<rho> @ \\<sigma> = \\<rho>' @ \\<tau>))\"\n    apply (rule_tac x=\"\\<rho>\" in bexI, auto simp add: \\<rho>_in_tocks)\n    apply (rule_tac x=\"\\<sigma>\" in exI, auto)\n    apply (rule_tac x=\"\\<rho>\" in bexI, auto simp add: \\<rho>_in_tocks)\n    apply (rule_tac x=\"\\<sigma>\" in exI, auto simp add: in_P)\n    apply (rule_tac x=\"\\<tau>\" in exI, auto simp add: in_Q \\<rho>_\\<tau>_eq_\\<rho>'_\\<sigma>' \\<rho>_longest_\\<sigma> \\<rho>_longest_\\<tau> \\<sigma>_refusal \\<tau>_refusal)\n    apply (rule_tac x=\"\\<tau>'\" in exI, auto simp add: in_R \\<rho>_eq_\\<rho>' \\<rho>'_longest_\\<tau>')\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<sigma>' \\<rho>_eq_\\<rho>' \\<sigma>'_refusal \\<sigma>_refusal apply fastforce\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<sigma>' \\<rho>_eq_\\<rho>' \\<tau>'_refusal \\<tau>_refusal by fastforce\nnext\n  fix \\<rho> \\<sigma> \\<tau> \\<rho>' \\<sigma>' \\<tau>' :: \"'a tttrace\"\n  assume in_P: \"\\<rho> @ \\<sigma> \\<in> P\" and in_Q: \"\\<rho>' @ \\<sigma>' \\<in> Q\" and in_R: \"\\<rho>' @ \\<tau>' \\<in> R\"\n  assume \\<rho>_in_tocks: \"\\<rho> \\<in> tocks UNIV\" and \\<rho>'_in_tocks: \"\\<rho>' \\<in> tocks UNIV\"\n  assume \\<rho>_longest_\\<sigma>: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<rho>_longest_\\<tau>: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<rho>'_longest_\\<sigma>': \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n  assume \\<rho>'_longest_\\<tau>': \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n  assume \\<sigma>_refusal: \"\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<tau>_refusal: \"\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<sigma>'_refusal: \"\\<forall>X. \\<sigma>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<tau>'_refusal: \"\\<forall>X. \\<tau>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>': \"\\<rho> @ \\<tau> = \\<rho>' @ \\<tau>'\"\n  have \\<rho>_eq_\\<rho>': \"\\<rho> = \\<rho>'\"\n    by (metis \\<rho>'_in_tocks \\<rho>'_longest_\\<tau>' \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_in_tocks \\<rho>_longest_\\<tau> tt_prefix_antisym tt_prefix_concat)\n  show \"\\<exists>\\<rho>'\\<in>tocks UNIV.\n          \\<exists>\\<sigma>'. (\\<exists>\\<rho>\\<in>tocks UNIV.\n                   \\<exists>\\<sigma>. \\<rho> @ \\<sigma> \\<in> P \\<and>\n                       (\\<exists>\\<tau>. \\<rho> @ \\<tau> \\<in> Q \\<and>\n                            (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                            (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                            (\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                            (\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                            (\\<rho>' @ \\<sigma>' = \\<rho> @ \\<sigma> \\<or> \\<rho>' @ \\<sigma>' = \\<rho> @ \\<tau>))) \\<and>\n               (\\<exists>\\<tau>. \\<rho>' @ \\<tau> \\<in> R \\<and>\n                    (\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>') \\<and>\n                    (\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>') \\<and>\n                    (\\<forall>X. \\<sigma>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                    (\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                    (\\<rho> @ \\<sigma> = \\<rho>' @ \\<sigma>' \\<or> \\<rho> @ \\<sigma> = \\<rho>' @ \\<tau>))\"\n    apply (rule_tac x=\"\\<rho>\" in bexI, auto simp add: \\<rho>_in_tocks)\n    apply (rule_tac x=\"\\<sigma>\" in exI, auto)\n    apply (rule_tac x=\"\\<rho>\" in bexI, auto simp add: \\<rho>_in_tocks)\n    apply (rule_tac x=\"\\<sigma>\" in exI, auto simp add: in_P)\n    apply (rule_tac x=\"\\<sigma>'\" in exI, auto simp add: in_Q \\<rho>_eq_\\<rho>' \\<rho>'_longest_\\<sigma>')\n    using \\<rho>_eq_\\<rho>' \\<rho>_longest_\\<sigma> apply blast\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<sigma>_refusal \\<tau>'_refusal apply fastforce\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<sigma>'_refusal \\<tau>_refusal apply fastforce\n    apply (rule_tac x=\"\\<tau>'\" in exI, auto simp add: in_R \\<rho>_eq_\\<rho>' \\<rho>'_longest_\\<tau>')\n    using \\<rho>_eq_\\<rho>' \\<rho>_longest_\\<sigma> apply blast\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<sigma>_refusal apply blast\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<tau>_refusal by blast\nnext\n  fix \\<rho> \\<sigma> \\<tau> \\<rho>' \\<sigma>' \\<tau>' :: \"'a tttrace\"\n  assume in_P: \"\\<rho> @ \\<sigma> \\<in> P\" and in_Q: \"\\<rho>' @ \\<sigma>' \\<in> Q\" and in_R: \"\\<rho>' @ \\<tau>' \\<in> R\"\n  assume \\<rho>_in_tocks: \"\\<rho> \\<in> tocks UNIV\" and \\<rho>'_in_tocks: \"\\<rho>' \\<in> tocks UNIV\"\n  assume \\<rho>_longest_\\<sigma>: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<rho>_longest_\\<tau>: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<rho>'_longest_\\<sigma>': \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n  assume \\<rho>'_longest_\\<tau>': \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n  assume \\<sigma>_refusal: \"\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<tau>_refusal: \"\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<sigma>'_refusal: \"\\<forall>X. \\<sigma>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<tau>'_refusal: \"\\<forall>X. \\<tau>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>': \"\\<rho> @ \\<tau> = \\<rho>' @ \\<sigma>'\"\n  have \\<rho>_eq_\\<rho>': \"\\<rho> = \\<rho>'\"\n    by (metis \\<rho>'_in_tocks \\<rho>'_longest_\\<sigma>' \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_in_tocks \\<rho>_longest_\\<tau> tt_prefix_antisym tt_prefix_concat)\n  show \"\\<exists>\\<rho>\\<in>tocks UNIV.\n          \\<exists>\\<sigma>. (\\<exists>\\<rho>'\\<in>tocks UNIV.\n                  \\<exists>\\<sigma>'. \\<rho>' @ \\<sigma>' \\<in> P \\<and>\n                       (\\<exists>\\<tau>. \\<rho>' @ \\<tau> \\<in> Q \\<and>\n                            (\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>') \\<and>\n                            (\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>') \\<and>\n                            (\\<forall>X. \\<sigma>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                            (\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                            (\\<rho> @ \\<sigma> = \\<rho>' @ \\<sigma>' \\<or> \\<rho> @ \\<sigma> = \\<rho>' @ \\<tau>))) \\<and>\n              (\\<exists>\\<tau>. \\<rho> @ \\<tau> \\<in> R \\<and>\n                   (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                   (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                   (\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                   (\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                   (\\<rho>' @ \\<sigma>' = \\<rho> @ \\<sigma> \\<or> \\<rho>' @ \\<sigma>' = \\<rho> @ \\<tau>))\"\n    apply (rule_tac x=\"\\<rho>\" in bexI, auto simp add: \\<rho>_in_tocks)\n    apply (rule_tac x=\"\\<sigma>'\" in exI, auto)\n    apply (rule_tac x=\"\\<rho>\" in bexI, auto simp add: \\<rho>_in_tocks)\n    apply (rule_tac x=\"\\<sigma>\" in exI, auto simp add: in_P)\n    apply (rule_tac x=\"\\<sigma>'\" in exI, auto simp add: in_Q \\<rho>_eq_\\<rho>' \\<rho>'_longest_\\<sigma>')\n    using \\<rho>_eq_\\<rho>' \\<rho>_longest_\\<sigma> apply blast\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<sigma>_refusal apply blast\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<tau>_refusal apply blast\n    apply (rule_tac x=\"\\<tau>'\" in exI, auto simp add: in_R \\<rho>_eq_\\<rho>' \\<rho>'_longest_\\<tau>')\n    using \\<sigma>'_refusal apply blast\n    using \\<tau>'_refusal by blast\nnext\n  fix \\<rho> \\<sigma> \\<tau> \\<rho>' \\<sigma>' \\<tau>' :: \"'a tttrace\"\n  assume in_P: \"\\<rho> @ \\<sigma> \\<in> P\" and in_Q: \"\\<rho>' @ \\<sigma>' \\<in> Q\" and in_R: \"\\<rho>' @ \\<tau>' \\<in> R\"\n  assume \\<rho>_in_tocks: \"\\<rho> \\<in> tocks UNIV\" and \\<rho>'_in_tocks: \"\\<rho>' \\<in> tocks UNIV\"\n  assume \\<rho>_longest_\\<sigma>: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<rho>_longest_\\<tau>: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<rho>'_longest_\\<sigma>': \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n  assume \\<rho>'_longest_\\<tau>': \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n  assume \\<sigma>_refusal: \"\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<tau>_refusal: \"\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<sigma>'_refusal: \"\\<forall>X. \\<sigma>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<tau>'_refusal: \"\\<forall>X. \\<tau>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>': \"\\<rho> @ \\<tau> = \\<rho>' @ \\<tau>'\"\n  have \\<rho>_eq_\\<rho>': \"\\<rho> = \\<rho>'\"\n    by (metis \\<rho>'_in_tocks \\<rho>'_longest_\\<tau>' \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_in_tocks \\<rho>_longest_\\<tau> tt_prefix_antisym tt_prefix_concat)\n  show \"\\<exists>\\<rho>\\<in>tocks UNIV.\n          \\<exists>\\<sigma>. (\\<exists>\\<rho>'\\<in>tocks UNIV.\n                  \\<exists>\\<sigma>'. \\<rho>' @ \\<sigma>' \\<in> P \\<and>\n                       (\\<exists>\\<tau>. \\<rho>' @ \\<tau> \\<in> Q \\<and>\n                            (\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>') \\<and>\n                            (\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>') \\<and>\n                            (\\<forall>X. \\<sigma>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                            (\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                            (\\<rho> @ \\<sigma> = \\<rho>' @ \\<sigma>' \\<or> \\<rho> @ \\<sigma> = \\<rho>' @ \\<tau>))) \\<and>\n              (\\<exists>\\<tau>. \\<rho> @ \\<tau> \\<in> R \\<and>\n                   (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                   (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                   (\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                   (\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                   (\\<rho>' @ \\<tau>' = \\<rho> @ \\<sigma> \\<or> \\<rho>' @ \\<tau>' = \\<rho> @ \\<tau>))\"\n    apply (rule_tac x=\"\\<rho>\" in bexI, auto simp add: \\<rho>_in_tocks)\n    apply (rule_tac x=\"\\<sigma>\" in exI, auto)\n    apply (rule_tac x=\"\\<rho>\" in bexI, auto simp add: \\<rho>_in_tocks)\n    apply (rule_tac x=\"\\<sigma>\" in exI, auto simp add: in_P)\n    apply (rule_tac x=\"\\<sigma>'\" in exI, auto simp add: in_Q \\<rho>_eq_\\<rho>' \\<rho>'_longest_\\<sigma>')\n    using \\<rho>_eq_\\<rho>' \\<rho>_longest_\\<sigma> apply blast\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<sigma>_refusal \\<tau>'_refusal apply fastforce\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<sigma>'_refusal \\<tau>_refusal apply fastforce\n    apply (rule_tac x=\"\\<tau>'\" in exI, auto simp add: in_R \\<rho>_eq_\\<rho>' \\<rho>'_longest_\\<tau>')\n    using \\<rho>_eq_\\<rho>' \\<rho>_longest_\\<sigma> apply blast\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<sigma>_refusal apply blast\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<tau>_refusal by blast\nnext\n  fix \\<rho> \\<sigma> \\<tau> \\<rho>' \\<sigma>' \\<tau>' :: \"'a tttrace\"\n  assume in_P: \"\\<rho>' @ \\<sigma>' \\<in> P\" and in_Q: \"\\<rho>' @ \\<tau>' \\<in> Q\" and in_R: \"\\<rho> @ \\<tau> \\<in> R\"\n  assume \\<rho>_in_tocks: \"\\<rho> \\<in> tocks UNIV\" and \\<rho>'_in_tocks: \"\\<rho>' \\<in> tocks UNIV\"\n  assume \\<rho>_longest_\\<sigma>: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<rho>_longest_\\<tau>: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<rho>'_longest_\\<sigma>': \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n  assume \\<rho>'_longest_\\<tau>': \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n  assume \\<sigma>_refusal: \"\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<tau>_refusal: \"\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<sigma>'_refusal: \"\\<forall>X. \\<sigma>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<tau>'_refusal: \"\\<forall>X. \\<tau>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>': \"\\<rho> @ \\<sigma> = \\<rho>' @ \\<sigma>'\"\n  have \\<rho>_eq_\\<rho>': \"\\<rho> = \\<rho>'\"\n    by (metis \\<rho>'_in_tocks \\<rho>'_longest_\\<sigma>' \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_in_tocks \\<rho>_longest_\\<sigma> tt_prefix_antisym tt_prefix_concat)\n  show \"\\<exists>\\<rho>\\<in>tocks UNIV.\n          \\<exists>\\<sigma>. \\<rho> @ \\<sigma> \\<in> P \\<and>\n              (\\<exists>\\<tau>. (\\<exists>\\<rho>'\\<in>tocks UNIV.\n                       \\<exists>\\<sigma>. \\<rho>' @ \\<sigma> \\<in> Q \\<and>\n                           (\\<exists>\\<tau>'. \\<rho>' @ \\<tau>' \\<in> R \\<and>\n                                 (\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>') \\<and>\n                                 (\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>') \\<and>\n                                 (\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                                 (\\<forall>X. \\<tau>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                                 (\\<rho> @ \\<tau> = \\<rho>' @ \\<sigma> \\<or> \\<rho> @ \\<tau> = \\<rho>' @ \\<tau>'))) \\<and>\n                   (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                   (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                   (\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                   (\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                   (\\<rho>' @ \\<sigma>' = \\<rho> @ \\<sigma> \\<or> \\<rho>' @ \\<sigma>' = \\<rho> @ \\<tau>))\"\n    apply (rule_tac x=\"\\<rho>'\" in bexI, auto simp add: \\<rho>'_in_tocks)\n    apply (rule_tac x=\"\\<sigma>'\" in exI, auto simp add: in_P)\n    apply (rule_tac x=\"\\<tau>'\" in exI, auto)\n    apply (rule_tac x=\"\\<rho>\" in bexI, auto simp add: \\<rho>_in_tocks)\n    apply (rule_tac x=\"\\<tau>'\" in exI, auto simp add: in_Q \\<rho>_eq_\\<rho>' \\<rho>'_longest_\\<sigma>')\n    apply (rule_tac x=\"\\<tau>\" in exI, auto simp add: \\<rho>'_longest_\\<tau>')\n    using \\<rho>_eq_\\<rho>' in_R apply blast\n    using \\<rho>_eq_\\<rho>' \\<rho>_longest_\\<tau> apply blast\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<sigma>_refusal \\<tau>'_refusal apply fastforce\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<sigma>'_refusal \\<tau>_refusal apply fastforce\n    using \\<sigma>'_refusal apply blast\n    using \\<tau>'_refusal by blast\nnext\n  fix \\<rho> \\<sigma> \\<tau> \\<rho>' \\<sigma>' \\<tau>' :: \"'a tttrace\"\n  assume in_P: \"\\<rho>' @ \\<sigma>' \\<in> P\" and in_Q: \"\\<rho>' @ \\<tau>' \\<in> Q\" and in_R: \"\\<rho> @ \\<tau> \\<in> R\"\n  assume \\<rho>_in_tocks: \"\\<rho> \\<in> tocks UNIV\" and \\<rho>'_in_tocks: \"\\<rho>' \\<in> tocks UNIV\"\n  assume \\<rho>_longest_\\<sigma>: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<rho>_longest_\\<tau>: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<rho>'_longest_\\<sigma>': \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n  assume \\<rho>'_longest_\\<tau>': \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n  assume \\<sigma>_refusal: \"\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<tau>_refusal: \"\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<sigma>'_refusal: \"\\<forall>X. \\<sigma>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<tau>'_refusal: \"\\<forall>X. \\<tau>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>': \"\\<rho> @ \\<sigma> = \\<rho>' @ \\<sigma>'\"\n  have \\<rho>_eq_\\<rho>': \"\\<rho> = \\<rho>'\"\n    by (metis \\<rho>'_in_tocks \\<rho>'_longest_\\<sigma>' \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_in_tocks \\<rho>_longest_\\<sigma> tt_prefix_antisym tt_prefix_concat)\n  show \"\\<exists>\\<rho>'\\<in>tocks UNIV.\n          \\<exists>\\<sigma>. \\<rho>' @ \\<sigma> \\<in> P \\<and>\n              (\\<exists>\\<tau>'. (\\<exists>\\<rho>\\<in>tocks UNIV.\n                        \\<exists>\\<sigma>. \\<rho> @ \\<sigma> \\<in> Q \\<and>\n                            (\\<exists>\\<tau>. \\<rho> @ \\<tau> \\<in> R \\<and>\n                                 (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                                 (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                                 (\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                                 (\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                                 (\\<rho>' @ \\<tau>' = \\<rho> @ \\<sigma> \\<or> \\<rho>' @ \\<tau>' = \\<rho> @ \\<tau>))) \\<and>\n                    (\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>') \\<and>\n                    (\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>') \\<and>\n                    (\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                    (\\<forall>X. \\<tau>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                    (\\<rho> @ \\<tau> = \\<rho>' @ \\<sigma> \\<or> \\<rho> @ \\<tau> = \\<rho>' @ \\<tau>'))\"\n    apply (rule_tac x=\"\\<rho>'\" in bexI, auto simp add: \\<rho>'_in_tocks)\n    apply (rule_tac x=\"\\<sigma>'\" in exI, auto simp add: in_P)\n    apply (rule_tac x=\"\\<tau>\" in exI, auto)\n    apply (rule_tac x=\"\\<rho>\" in bexI, auto simp add: \\<rho>_in_tocks)\n    apply (rule_tac x=\"\\<tau>'\" in exI, auto simp add: in_Q \\<rho>_eq_\\<rho>' \\<rho>'_longest_\\<sigma>')\n    apply (rule_tac x=\"\\<tau>\" in exI, auto simp add: \\<rho>'_longest_\\<tau>')\n    using \\<rho>_eq_\\<rho>' in_R apply blast\n    using \\<rho>_eq_\\<rho>' \\<rho>_longest_\\<tau> apply blast\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<sigma>_refusal \\<tau>'_refusal apply fastforce\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<sigma>'_refusal \\<tau>_refusal apply fastforce\n    using \\<rho>_eq_\\<rho>' \\<rho>_longest_\\<tau> apply blast\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<sigma>_refusal apply blast\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<tau>_refusal by blast\nnext\n  fix \\<rho> \\<sigma> \\<tau> \\<rho>' \\<sigma>' \\<tau>' :: \"'a tttrace\"\n  assume in_P: \"\\<rho>' @ \\<sigma>' \\<in> P\" and in_Q: \"\\<rho>' @ \\<tau>' \\<in> Q\" and in_R: \"\\<rho> @ \\<tau> \\<in> R\"\n  assume \\<rho>_in_tocks: \"\\<rho> \\<in> tocks UNIV\" and \\<rho>'_in_tocks: \"\\<rho>' \\<in> tocks UNIV\"\n  assume \\<rho>_longest_\\<sigma>: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<rho>_longest_\\<tau>: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<rho>'_longest_\\<sigma>': \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n  assume \\<rho>'_longest_\\<tau>': \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n  assume \\<sigma>_refusal: \"\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<tau>_refusal: \"\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<sigma>'_refusal: \"\\<forall>X. \\<sigma>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<tau>'_refusal: \"\\<forall>X. \\<tau>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>': \"\\<rho> @ \\<sigma> = \\<rho>' @ \\<tau>'\"\n  have \\<rho>_eq_\\<rho>': \"\\<rho> = \\<rho>'\"\n    by (metis \\<rho>'_in_tocks \\<rho>'_longest_\\<tau>' \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_in_tocks \\<rho>_longest_\\<sigma> tt_prefix_antisym tt_prefix_concat)\n  show \"\\<exists>\\<rho>\\<in>tocks UNIV.\n          \\<exists>\\<sigma>. \\<rho> @ \\<sigma> \\<in> P \\<and>\n              (\\<exists>\\<tau>. (\\<exists>\\<rho>'\\<in>tocks UNIV.\n                       \\<exists>\\<sigma>. \\<rho>' @ \\<sigma> \\<in> Q \\<and>\n                           (\\<exists>\\<tau>'. \\<rho>' @ \\<tau>' \\<in> R \\<and>\n                                 (\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>') \\<and>\n                                 (\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>') \\<and>\n                                 (\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                                 (\\<forall>X. \\<tau>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                                 (\\<rho> @ \\<tau> = \\<rho>' @ \\<sigma> \\<or> \\<rho> @ \\<tau> = \\<rho>' @ \\<tau>'))) \\<and>\n                   (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                   (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                   (\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                   (\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                   (\\<rho>' @ \\<tau>' = \\<rho> @ \\<sigma> \\<or> \\<rho>' @ \\<tau>' = \\<rho> @ \\<tau>))\"\n    apply (rule_tac x=\"\\<rho>'\" in bexI, auto simp add: \\<rho>'_in_tocks)\n    apply (rule_tac x=\"\\<sigma>'\" in exI, auto simp add: in_P)\n    apply (rule_tac x=\"\\<tau>'\" in exI, auto)\n    apply (rule_tac x=\"\\<rho>\" in bexI, auto simp add: \\<rho>_in_tocks)\n    apply (rule_tac x=\"\\<tau>'\" in exI, auto simp add: in_Q \\<rho>_eq_\\<rho>' \\<rho>'_longest_\\<sigma>')\n    apply (rule_tac x=\"\\<tau>\" in exI, auto simp add: \\<rho>'_longest_\\<tau>')\n    using \\<rho>_eq_\\<rho>' in_R apply blast\n    using \\<rho>_eq_\\<rho>' \\<rho>_longest_\\<tau> apply blast\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<sigma>_refusal \\<tau>'_refusal apply fastforce\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<sigma>'_refusal \\<tau>_refusal apply fastforce\n    using \\<sigma>'_refusal apply blast\n    using \\<tau>'_refusal by blast\nnext\n  fix \\<rho> \\<sigma> \\<tau> \\<rho>' \\<sigma>' \\<tau>' :: \"'a tttrace\"\n  assume in_P: \"\\<rho>' @ \\<sigma>' \\<in> P\" and in_Q: \"\\<rho>' @ \\<tau>' \\<in> Q\" and in_R: \"\\<rho> @ \\<tau> \\<in> R\"\n  assume \\<rho>_in_tocks: \"\\<rho> \\<in> tocks UNIV\" and \\<rho>'_in_tocks: \"\\<rho>' \\<in> tocks UNIV\"\n  assume \\<rho>_longest_\\<sigma>: \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<rho>_longest_\\<tau>: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<rho>'_longest_\\<sigma>': \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n  assume \\<rho>'_longest_\\<tau>': \"\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>'\"\n  assume \\<sigma>_refusal: \"\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<tau>_refusal: \"\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<sigma>'_refusal: \"\\<forall>X. \\<sigma>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<tau>'_refusal: \"\\<forall>X. \\<tau>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>': \"\\<rho> @ \\<sigma> = \\<rho>' @ \\<tau>'\"\n  have \\<rho>_eq_\\<rho>': \"\\<rho> = \\<rho>'\"\n    by (metis \\<rho>'_in_tocks \\<rho>'_longest_\\<tau>' \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_in_tocks \\<rho>_longest_\\<sigma> tt_prefix_antisym tt_prefix_concat)\n  show \"\\<exists>\\<rho>'\\<in>tocks UNIV.\n          \\<exists>\\<sigma>. \\<rho>' @ \\<sigma> \\<in> P \\<and>\n              (\\<exists>\\<tau>'. (\\<exists>\\<rho>\\<in>tocks UNIV.\n                        \\<exists>\\<sigma>. \\<rho> @ \\<sigma> \\<in> Q \\<and>\n                            (\\<exists>\\<tau>. \\<rho> @ \\<tau> \\<in> R \\<and>\n                                 (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                                 (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                                 (\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                                 (\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                                 (\\<rho>' @ \\<tau>' = \\<rho> @ \\<sigma> \\<or> \\<rho>' @ \\<tau>' = \\<rho> @ \\<tau>))) \\<and>\n                    (\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<sigma> \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>') \\<and>\n                    (\\<forall>\\<rho>''\\<in>tocks UNIV. \\<rho>'' \\<le>\\<^sub>C \\<rho>' @ \\<tau>' \\<longrightarrow> \\<rho>'' \\<le>\\<^sub>C \\<rho>') \\<and>\n                    (\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                    (\\<forall>X. \\<tau>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                    (\\<rho> @ \\<tau> = \\<rho>' @ \\<sigma> \\<or> \\<rho> @ \\<tau> = \\<rho>' @ \\<tau>'))\"\n    apply (rule_tac x=\"\\<rho>'\" in bexI, auto simp add: \\<rho>'_in_tocks)\n    apply (rule_tac x=\"\\<sigma>'\" in exI, auto simp add: in_P)\n    apply (rule_tac x=\"\\<tau>\" in exI, auto)\n    apply (rule_tac x=\"\\<rho>\" in bexI, auto simp add: \\<rho>_in_tocks)\n    apply (rule_tac x=\"\\<tau>'\" in exI, auto simp add: in_Q \\<rho>_eq_\\<rho>' \\<rho>'_longest_\\<sigma>')\n    apply (rule_tac x=\"\\<tau>\" in exI, auto simp add: \\<rho>'_longest_\\<tau>')\n    using \\<rho>_eq_\\<rho>' in_R apply blast\n    using \\<rho>_eq_\\<rho>' \\<rho>_longest_\\<tau> apply blast\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<sigma>_refusal \\<tau>'_refusal apply fastforce\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<sigma>'_refusal \\<tau>_refusal apply fastforce\n    using \\<rho>_eq_\\<rho>' \\<rho>_longest_\\<tau> apply blast\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<sigma>'_refusal \\<sigma>_refusal apply fastforce\n    using \\<rho>_\\<tau>_eq_\\<rho>'_\\<tau>' \\<rho>_eq_\\<rho>' \\<tau>'_refusal \\<tau>_refusal by fastforce\nqed\n\nlemma ExtChoice_idempotent: \"P \\<box>\\<^sub>C P = P\"\n  unfolding ExtChoiceTT_def\nproof auto\n  fix x\n  assume assm: \"x \\<in> P\"\n  have \"\\<exists>s. \\<exists>t\\<in>tocks UNIV. x = t @ s \\<and> (\\<forall>t'\\<in>tocks UNIV. t' \\<le>\\<^sub>C x \\<longrightarrow> t' \\<le>\\<^sub>C t)\"\n    using split_tocks_longest by blast\n  then obtain s t where \"t\\<in>tocks UNIV \\<and> x = t @ s \\<and> (\\<forall>t'\\<in>tocks UNIV. t' \\<le>\\<^sub>C x \\<longrightarrow> t' \\<le>\\<^sub>C t)\"\n    by auto\n  then show \"\\<exists>\\<rho>\\<in>tocks UNIV.\n            \\<exists>\\<sigma>. \\<rho> @ \\<sigma> \\<in> P \\<and>\n                (\\<exists>\\<tau>. \\<rho> @ \\<tau> \\<in> P \\<and>\n                     (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                     (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                     (\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                     (\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                     (x = \\<rho> @ \\<sigma> \\<or> x = \\<rho> @ \\<tau>))\"\n    by (rule_tac x=t in bexI, auto, rule_tac x=s in exI, auto, insert assm, blast, rule_tac x=s in exI, auto)\nqed\n\nlemma ExtChoice_left_unit:\n  assumes \"TT1 P\" \"\\<forall>x\\<in>P. ttWF x\"\n  shows \"P \\<box>\\<^sub>C STOP\\<^sub>C = P\"\n  unfolding ExtChoiceTT_def StopTT_def\nproof auto\n  fix \\<rho> \\<sigma> \\<tau> :: \"'a tttrace\"\n  assume case_assms: \"\\<rho> \\<in> tocks UNIV\" \"\\<rho> @ \\<sigma> \\<in> P\" \"\\<rho> @ \\<tau> \\<in> tocks {x. x \\<noteq> Tock}\" \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n  then have \"\\<tau> = []\"\n    using self_extension_tt_prefix tocks_subset tt_prefix_refl by blast\n  then show \"\\<rho> @ \\<tau> \\<in> P\"\n    using TT1_TT1w TT1w_prefix_concat_in assms case_assms(2) by auto\nnext\n  fix \\<rho> \\<sigma> \\<tau> s :: \"'a tttrace\"\n  fix X\n  assume case_assms: \"\\<rho> \\<in> tocks UNIV\" \"\\<rho> @ \\<sigma> \\<in> P\" \"s \\<in> tocks {x. x \\<noteq> Tock}\" \"\\<rho> @ \\<tau> = s @ [[X]\\<^sub>R]\" \"Tock \\<notin> X\"\n    \"\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n    \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C s @ [[X]\\<^sub>R] \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n  then have \\<rho>_\\<tau>_def: \"\\<rho> = s \\<and> \\<tau> = [[X]\\<^sub>R]\"\n    by (metis end_refusal_notin_tocks same_append_eq tocks_subset top_greatest tt_prefix_antisym tt_prefix_concat tt_prefix_notfront_is_whole)\n  then obtain Y where Y_assms: \"\\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock)\"\n    using case_assms(6) by blast\n  then have \"s @ [[Y]\\<^sub>R] \\<in> P\"\n    using \\<rho>_\\<tau>_def case_assms(2) by blast\n  then have \"s @ [[X]\\<^sub>R] \\<lesssim>\\<^sub>C s @ [[Y]\\<^sub>R] \\<Longrightarrow> s @ [[X]\\<^sub>R] \\<in> P\"\n    using TT1_def assms by blast\n  then show \"s @ [[X]\\<^sub>R] \\<in> P\"\n    by (metis Y_assms case_assms(5) subsetI tt_prefix_common_concat tt_prefix_subset.simps(2) tt_prefix_subset_refl)\nnext\n  fix x\n  assume case_assm: \"x \\<in> P\"\n  then obtain s t where \"t\\<in>tocks {x. x \\<noteq> Tock} \\<and> x = t @ s \\<and> (\\<forall>t'\\<in>tocks UNIV. t' \\<le>\\<^sub>C x \\<longrightarrow> t' \\<le>\\<^sub>C t)\"\n    by (metis assms(2) ttWF_split_tocks_longest)\n  then show \"\\<exists>\\<rho>\\<in>tocks UNIV.\\<exists>\\<sigma>. \\<rho> @ \\<sigma> \\<in> P \\<and>\n      (\\<exists>\\<tau>. (\\<exists>s\\<in>tocks {x. x \\<noteq> Tock}. \\<rho> @ \\<tau> = s \\<or> (\\<exists>X. \\<rho> @ \\<tau> = s @ [[X]\\<^sub>R] \\<and> Tock \\<notin> X)) \\<and>\n            (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n            (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n            (\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n            (\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and> \n            (x = \\<rho> @ \\<sigma> \\<or> x = \\<rho> @ \\<tau>))\"\n    apply (rule_tac x=t in bexI, auto)\n    apply (rule_tac x=s in exI, auto)\n    using case_assm apply blast\n    apply (rule_tac x=\"case s of [[X]\\<^sub>R] \\<Rightarrow> [[{x\\<in>X. x \\<noteq> Tock}]\\<^sub>R] | _ \\<Rightarrow> []\" in exI, auto)\n    apply (rule_tac x=\"t\" in bexI, auto)\n    apply (cases s rule:ttWF.cases, auto)\n    apply (cases s rule:ttWF.cases, auto)\n    using end_refusal_notin_tocks tt_prefix_notfront_is_whole apply blast\n    apply (cases s rule:ttWF.cases, auto)\n    using tocks_subset by blast\nqed\n\nlemma ExtChoice_right_unit:\n  assumes \"TT1 P\" \"\\<forall>x\\<in>P. ttWF x\"\n  shows \"STOP\\<^sub>C \\<box>\\<^sub>C P = P\"\n  by (simp add: ExtChoice_comm ExtChoice_left_unit assms)\n\nlemma ExtChoice_Union_dist1:\n  \"X \\<noteq> {} \\<Longrightarrow> P \\<box>\\<^sub>C \\<Union>X = \\<Union>{R. \\<exists>Q. Q \\<in> X \\<and> R = P \\<box>\\<^sub>C Q}\"\n  unfolding ExtChoiceTT_def by auto\n\nlemma ExtChoice_Union_dist2:\n  \"X \\<noteq> {} \\<Longrightarrow> \\<Union>X \\<box>\\<^sub>C Q = \\<Union>{R. \\<exists>P. P \\<in> X \\<and> R = P \\<box>\\<^sub>C Q}\"\n  unfolding ExtChoiceTT_def by auto\n\nlemma ExtChoice_mono1: \n  \"P \\<sqsubseteq>\\<^sub>C Q \\<Longrightarrow> P \\<box>\\<^sub>C R \\<sqsubseteq>\\<^sub>C Q \\<box>\\<^sub>C R\"\n  unfolding RefinesTT_def ExtChoiceTT_def by auto\n\nlemma ExtChoice_mono2: \n  \"P \\<sqsubseteq>\\<^sub>C Q \\<Longrightarrow> R \\<box>\\<^sub>C P \\<sqsubseteq>\\<^sub>C R \\<box>\\<^sub>C Q\"\n  unfolding RefinesTT_def ExtChoiceTT_def by auto\n\n\nsubsection \\<open>Replicated External Choice\\<close>\n\ndefinition ReplicatedExtChoiceTT :: \"'e ttprocess set \\<Rightarrow> 'e ttprocess\" where\n  \"ReplicatedExtChoiceTT Ps = Finite_Set.fold (\\<box>\\<^sub>C) STOP\\<^sub>C Ps\"\n\nabbreviation(input) \"ReplicatedExtChoiceTT'_pat X P f \\<equiv> ReplicatedExtChoiceTT { P e |e. f e \\<in> X}\"\nabbreviation(input) \"ReplicatedExtChoiceTT' X P \\<equiv> ReplicatedExtChoiceTT { P e |e. e \\<in> X}\"\n\nsyntax\n  \"_replicated_ext_choice\" :: \"('e \\<Rightarrow> pttrn) \\<Rightarrow> logic \\<Rightarrow> logic \\<Rightarrow> logic\" (\"(\\<box>\\<^sub>R (_) \\<in> _ \\<bullet> _)\" [1,0,0] 56)\n\ntranslations\n  \"_replicated_ext_choice (f e) X  P\" \\<rightleftharpoons> \"CONST ReplicatedExtChoiceTT'_pat X (\\<lambda>e. P) f\"\n  \"_replicated_ext_choice e X P\" \\<rightleftharpoons> \"CONST ReplicatedExtChoiceTT' X (\\<lambda>e. P)\"\n\nterm \"(\\<box>\\<^sub>R (Event e) \\<in> X \\<bullet> P e) \\<box>\\<^sub>C Q\"\nterm \"(\\<box>\\<^sub>R e \\<in> X \\<bullet> P e) \\<box>\\<^sub>C Q\"\n\nlemma ExtChoice_comp_fun_commute: \"comp_fun_commute (\\<box>\\<^sub>C)\"\n  unfolding comp_fun_commute_def by (auto,rule_tac ext, auto, (metis ExtChoice_assoc ExtChoice_comm)+)\n\nlemma ReplicatedExtChoice_empty:\n  \"ReplicatedExtChoiceTT {} = STOP\\<^sub>C\"\n  unfolding ReplicatedExtChoiceTT_def by auto\n\nlemma ReplicatedExtChoice_singleton:\n  assumes \"TT1 P\" \"\\<forall>x\\<in>P. ttWF x\"\n  shows \"ReplicatedExtChoiceTT {P} = P\"\n    unfolding ReplicatedExtChoiceTT_def apply (subst Finite_Set.comp_fun_commute.fold_insert)\n    by (simp_all add: ExtChoice_comp_fun_commute ExtChoice_left_unit assms)\n\nlemma ReplicatedExtChoice_insert_notin:\n  \"finite Ps \\<Longrightarrow> P \\<notin> Ps \\<Longrightarrow> ReplicatedExtChoiceTT (insert P Ps) = P \\<box>\\<^sub>C (ReplicatedExtChoiceTT Ps)\"\n  unfolding ReplicatedExtChoiceTT_def \n  by (subst Finite_Set.comp_fun_commute.fold_insert, simp_all add: ExtChoice_comp_fun_commute)\n\nlemma ReplicatedExtChoice_insert_idemp:\n  \"finite Ps \\<Longrightarrow> P \\<in> Ps \\<Longrightarrow> ReplicatedExtChoiceTT (insert P Ps) = P \\<box>\\<^sub>C (ReplicatedExtChoiceTT Ps)\"\nproof -\n  assume assms: \"finite Ps\" \"P \\<in> Ps\"\n  have \"insert P Ps = insert P {x\\<in>Ps. x \\<noteq> P}\"\n    by auto\n  then have \"ReplicatedExtChoiceTT (insert P Ps) = ReplicatedExtChoiceTT (insert P {x\\<in>Ps. x \\<noteq> P})\"\n    by simp\n  also have \"... = P \\<box>\\<^sub>C (ReplicatedExtChoiceTT {x\\<in>Ps. x \\<noteq> P})\"\n    by (simp add: ReplicatedExtChoice_insert_notin assms(1))\n  also have \"... = (P \\<box>\\<^sub>C P) \\<box>\\<^sub>C (ReplicatedExtChoiceTT {x\\<in>Ps. x \\<noteq> P})\"\n    by (simp add: ExtChoice_idempotent)\n  also have \"... = P \\<box>\\<^sub>C (ReplicatedExtChoiceTT Ps)\"\n    by (smt ExtChoice_assoc ExtChoice_idempotent assms(2) calculation insert_absorb)\n  then show ?thesis\n    using calculation by auto\nqed\n\nlemma ReplicatedExtChoice_insert:\n  \"finite Ps \\<Longrightarrow> ReplicatedExtChoiceTT (insert P Ps) = P \\<box>\\<^sub>C (ReplicatedExtChoiceTT Ps)\"\n  by (cases \"P \\<in> Ps\", simp_all add: ReplicatedExtChoice_insert_idemp ReplicatedExtChoice_insert_notin)\n    \nlemma ReplicatedExtChoice_pair: \n  assumes \"TT1 P\" \"\\<forall>x\\<in>P. ttWF x\"\n  shows \"ReplicatedExtChoiceTT {P, Q} = P \\<box>\\<^sub>C Q\"\nproof -\n  have \"ReplicatedExtChoiceTT {P, Q} = P \\<box>\\<^sub>C (ReplicatedExtChoiceTT {Q})\"\n    by (simp add: ReplicatedExtChoice_insert)\n  also have \"... = P \\<box>\\<^sub>C Q\"\n    by (smt ExtChoice_assoc ExtChoice_comm ReplicatedExtChoice_insert ReplicatedExtChoice_singleton assms finite.emptyI)\n  then show ?thesis \n    using calculation by auto\nqed\n\nlemma ReplicatedExtChoice_induct:\n  \"finite Ps \\<Longrightarrow> \n  (\\<And>P. P \\<in> Ps \\<Longrightarrow> Pred P) \\<Longrightarrow>\n  Pred (ReplicatedExtChoiceTT {}) \\<Longrightarrow>\n  (\\<And>P Ps'. finite Ps' \\<Longrightarrow> Pred P \\<Longrightarrow> Pred (ReplicatedExtChoiceTT Ps') \\<Longrightarrow> Pred (ReplicatedExtChoiceTT (insert P Ps'))) \\<Longrightarrow>\n  Pred (ReplicatedExtChoiceTT Ps)\"\n  by (rule finite_subset_induct[where F=Ps, where P=\"\\<lambda>x. Pred (ReplicatedExtChoiceTT x)\", where A=\"{P. Pred P}\"], auto)\n\nlemma ReplicatedExtChoice_wf:\n  assumes \"\\<And>P. P\\<in>Ps \\<Longrightarrow> \\<forall>x\\<in>P. ttWF x\" \"finite Ps\"\n  shows \"\\<forall>x\\<in>ReplicatedExtChoiceTT Ps. ttWF x\"\nproof (insert assms, rule ReplicatedExtChoice_induct, auto)\n  fix x :: \"'a tttrace\"\n  show \"x \\<in> ReplicatedExtChoiceTT {} \\<Longrightarrow> ttWF x\"\n    using ReplicatedExtChoice_empty StopTT_wf by blast\nnext\n  fix Ps' :: \"'a ttprocess set\"\n  fix P :: \"'a ttprocess\"\n  fix x :: \"'a tttrace\"\n  assume case_assms: \"\\<forall>x\\<in>P. ttWF x\" \"\\<forall>x\\<in>ReplicatedExtChoiceTT Ps'. ttWF x\" \"finite Ps'\"\n  assume \"x \\<in> ReplicatedExtChoiceTT (insert P Ps')\"\n  then have \"x \\<in> P \\<box>\\<^sub>C ReplicatedExtChoiceTT Ps'\"\n    by (simp add: ReplicatedExtChoice_insert case_assms(3))\n  then show \"ttWF x\"\n    using ExtChoiceTT_wf case_assms(1) case_assms(2) by blast\nqed\n\nlemma TT_ReplicatedExternalChoice:\n  assumes \"\\<And>P. P\\<in>Ps \\<Longrightarrow> TT P \\<and> TT2 P \\<and> TT3 P\" \"finite Ps\"\n  shows \"TT (ReplicatedExtChoiceTT Ps) \\<and> TT2 (ReplicatedExtChoiceTT Ps) \\<and> TT3 (ReplicatedExtChoiceTT Ps)\"\nproof (insert assms, rule ReplicatedExtChoice_induct, auto)\n  show \"TT (ReplicatedExtChoiceTT {})\"\n    by (simp add: ReplicatedExtChoice_empty TT_Stop)\nnext\n  show \"TT2 (ReplicatedExtChoiceTT {})\"\n    by (simp add: ReplicatedExtChoice_empty TT2_Stop)\nnext\n  show \"TT3 (ReplicatedExtChoiceTT {})\"\n    by (simp add: ReplicatedExtChoice_empty TT3_Stop)\nnext\n  fix P :: \"'a ttprocess\" and Ps' :: \"'a ttprocess set\"\n  show \"TT P \\<Longrightarrow> TT (ReplicatedExtChoiceTT Ps') \\<Longrightarrow> TT (ReplicatedExtChoiceTT (insert P Ps'))\"\n    by (metis ReplicatedExtChoiceTT_def ReplicatedExtChoice_insert TT_ExtChoice finite_insert fold_infinite)\nnext\n  fix P :: \"'a ttprocess\" and Ps' :: \"'a ttprocess set\"\n  show \"TT P \\<Longrightarrow> TT (ReplicatedExtChoiceTT Ps') \\<Longrightarrow> TT2 P \\<Longrightarrow> TT2 (ReplicatedExtChoiceTT Ps') \\<Longrightarrow>\n      TT2 (ReplicatedExtChoiceTT (insert P Ps'))\"\n    by (metis ReplicatedExtChoiceTT_def ReplicatedExtChoice_insert TT2_ExtChoice finite_insert fold_infinite)\nnext\n  fix P :: \"'a ttprocess\" and Ps' :: \"'a ttprocess set\"\n  show \"TT P \\<Longrightarrow> TT (ReplicatedExtChoiceTT Ps') \\<Longrightarrow> TT3 P \\<Longrightarrow> TT3 (ReplicatedExtChoiceTT Ps') \\<Longrightarrow>\n      TT3 (ReplicatedExtChoiceTT (insert P Ps'))\"\n    by (metis ReplicatedExtChoiceTT_def ReplicatedExtChoice_insert TT3_ExtChoice finite_insert fold_infinite)\nqed\n\nend\n", "meta": {"author": "UoY-RoboStar", "repo": "tick-tock-CSP", "sha": "7186d2e7f70116589850112a7353bc521372c913", "save_path": "github-repos/isabelle/UoY-RoboStar-tick-tock-CSP", "path": "github-repos/isabelle/UoY-RoboStar-tick-tock-CSP/tick-tock-CSP-7186d2e7f70116589850112a7353bc521372c913/TickTock/TickTock_ExtChoice.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6723316860482762, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.2995436234774605}}
{"text": "theory Alternative_Semantics\nimports Semantics\nbegin\n  \ncontext begin\n  \n(* the first thing (I think) we have to do is alter the Seq rule / merge it with NoMatch.\n Its properties make it hard to work with\\<dots> *)\nprivate inductive iptables_bigstep_ns :: \"'a ruleset \\<Rightarrow> ('a, 'p) matcher \\<Rightarrow> 'p \\<Rightarrow> 'a rule list \\<Rightarrow> state \\<Rightarrow> state \\<Rightarrow> bool\"\n  (\"_,_,_\\<turnstile> \\<langle>_, _\\<rangle> \\<Rightarrow>\\<^sub>s _\"  [60,60,60,20,98,98] 89)\n  for \\<Gamma> and \\<gamma> and p where\nskip:    \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[], t\\<rangle> \\<Rightarrow>\\<^sub>s t\" |\naccept:  \"matches \\<gamma> m p \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>Rule m Accept # rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s Decision FinalAllow\" |\ndrop:    \"matches \\<gamma> m p \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>Rule m Drop # rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s Decision FinalDeny\" |\nreject:  \"matches \\<gamma> m p \\<Longrightarrow>  \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>Rule m Reject # rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s Decision FinalDeny\" |\nlog:     \"matches \\<gamma> m p \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s t \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>Rule m Log # rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s t\" |\nempty:   \"matches \\<gamma> m p \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s t \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>Rule m Empty # rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s t\" |\nnms:     \"\\<not> matches \\<gamma> m p \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s t \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>Rule m a # rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s t\" |\n(*decision: \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, Decision X\\<rangle> \\<Rightarrow>\\<^sub>s Decision X\" |*)\ncall_return:  \"\\<lbrakk> matches \\<gamma> m p; \\<Gamma> chain = Some (rs\\<^sub>1 @ Rule m' Return # rs\\<^sub>2);\n                 matches \\<gamma> m' p; \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs\\<^sub>1, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s Undecided; \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rrs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s t \\<rbrakk> \\<Longrightarrow>\n               \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>Rule m (Call chain) # rrs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s t\" |\ncall_result:  \"\\<lbrakk> matches \\<gamma> m p; \\<Gamma> chain = Some rs; \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s Decision X \\<rbrakk> \\<Longrightarrow>\n               \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>Rule m (Call chain) # rrs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s Decision X\" |\ncall_no_result:  \"\\<lbrakk> matches \\<gamma> m p; \\<Gamma> chain = Some rs; \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s Undecided;\n                    \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rrs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s t \\<rbrakk> \\<Longrightarrow>\n               \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>Rule m (Call chain) # rrs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s t\"\n\nprivate lemma a: \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow>\\<^sub>s t \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow> t\"\n  apply(induction rule: iptables_bigstep_ns.induct; (simp add: iptables_bigstep.intros;fail)?)\n  apply (meson iptables_bigstep.decision iptables_bigstep.accept seq_cons)\n  apply (meson iptables_bigstep.decision iptables_bigstep.drop seq_cons)\n  apply (meson iptables_bigstep.decision iptables_bigstep.reject seq_cons)\n  apply (meson iptables_bigstep.log seq_cons)\n  apply (meson iptables_bigstep.empty seq_cons)\n  apply (meson nomatch seq_cons)\n  subgoal using iptables_bigstep.call_return seq_cons by fastforce\n  apply (meson iptables_bigstep.decision iptables_bigstep.call_result seq_cons)\n  apply (meson iptables_bigstep.call_result seq'_cons)\n  done\n\nprivate lemma empty_rs_stateD: assumes \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[], s\\<rangle> \\<Rightarrow>\\<^sub>s t\" shows \"t = s\"\n  using assms by(cases rule: iptables_bigstep_ns.cases)\nprivate lemma decided: \"\\<lbrakk>\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs\\<^sub>1, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s Decision X\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs\\<^sub>1@rs\\<^sub>2, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s Decision X\"\nproof(induction rs\\<^sub>1)\n  case Nil\n  then show ?case by (fast dest: empty_rs_stateD)\nnext\n  case (Cons a rs\\<^sub>1)\n  from Cons.prems show ?case \n    by(cases rule: iptables_bigstep_ns.cases; simp add: Cons.IH iptables_bigstep_ns.intros)\nqed\n  \nprivate lemma decided_determ: \"\\<lbrakk>\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs\\<^sub>1, s\\<rangle> \\<Rightarrow>\\<^sub>s t; s = Decision X\\<rbrakk> \\<Longrightarrow> t = Decision X\"\n  by(induction rule: iptables_bigstep_ns.induct; (simp add: iptables_bigstep_ns.intros;fail)?)\n\nprivate lemma seq_ns:\n  \"\\<lbrakk>\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs\\<^sub>1, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s t; \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs\\<^sub>2, t\\<rangle> \\<Rightarrow>\\<^sub>s t'\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs\\<^sub>1@rs\\<^sub>2, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s t'\"\nproof (cases t, goal_cases)\n  case 1\n  from 1(1,2) show ?case unfolding 1 proof(induction rs\\<^sub>1)\n    case (Cons a rs\\<^sub>3)\n    then show ?case\n      apply -\n      apply(rule iptables_bigstep_ns.cases[OF Cons.prems(1)]; simp add: iptables_bigstep_ns.intros)\n    done\n  qed simp\nnext\n  case (2 X)\n  hence \"t' = Decision X\" by (simp add: decided_determ)\n  from 2(1) show ?case by (simp add: \"2\"(3) \\<open>t' = Decision X\\<close> decided)\nqed\n      \nprivate lemma b: \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow> t \\<Longrightarrow> s = Undecided \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow>\\<^sub>s t\"\n  apply(induction rule: iptables_bigstep.induct; (simp add: iptables_bigstep_ns.intros;fail)?)\n   apply (metis decided decision seq_ns seq_progress skipD state.exhaust)\n  apply(metis call_no_result iptables_bigstep_ns.call_result iptables_bigstep_ns.skip state.exhaust)\n  done\n    \nprivate inductive iptables_bigstep_nz :: \"'a ruleset \\<Rightarrow> ('a, 'p) matcher \\<Rightarrow> 'p \\<Rightarrow> 'a rule list \\<Rightarrow> state \\<Rightarrow> bool\"\n  (\"_,_,_\\<turnstile> _ \\<Rightarrow>\\<^sub>z _\"  [60,60,60,20,98] 89)\n  for \\<Gamma> and \\<gamma> and p where\nskip:    \"\\<Gamma>,\\<gamma>,p \\<turnstile> []  \\<Rightarrow>\\<^sub>z Undecided\" |\naccept:  \"matches \\<gamma> m p \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> Rule m Accept # rs \\<Rightarrow>\\<^sub>z Decision FinalAllow\" |\ndrop:    \"matches \\<gamma> m p \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> Rule m Drop # rs \\<Rightarrow>\\<^sub>z Decision FinalDeny\" |\nreject:  \"matches \\<gamma> m p \\<Longrightarrow>  \\<Gamma>,\\<gamma>,p\\<turnstile> Rule m Reject # rs \\<Rightarrow>\\<^sub>z Decision FinalDeny\" |\nlog:     \"matches \\<gamma> m p \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>z t \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> Rule m Log # rs \\<Rightarrow>\\<^sub>z t\" |\nempty:   \"matches \\<gamma> m p \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>z t \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> Rule m Empty # rs \\<Rightarrow>\\<^sub>z t\" |\nnms:     \"\\<not> matches \\<gamma> m p \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>z t \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> Rule m a # rs \\<Rightarrow>\\<^sub>z t\" |\ncall_return:  \"\\<lbrakk> matches \\<gamma> m p; \\<Gamma> chain = Some (rs\\<^sub>1 @ Rule m' Return # rs\\<^sub>2);\n                 matches \\<gamma> m' p; \\<Gamma>,\\<gamma>,p\\<turnstile> rs\\<^sub>1 \\<Rightarrow>\\<^sub>z Undecided; \\<Gamma>,\\<gamma>,p\\<turnstile> rrs \\<Rightarrow>\\<^sub>z t \\<rbrakk> \\<Longrightarrow>\n               \\<Gamma>,\\<gamma>,p\\<turnstile> Rule m (Call chain) # rrs \\<Rightarrow>\\<^sub>z t\" |\ncall_result:  \"\\<lbrakk> matches \\<gamma> m p; \\<Gamma> chain = Some rs; \\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>z Decision X \\<rbrakk> \\<Longrightarrow>\n               \\<Gamma>,\\<gamma>,p\\<turnstile> Rule m (Call chain) # rrs \\<Rightarrow>\\<^sub>z Decision X\" |\ncall_no_result:  \"\\<lbrakk> matches \\<gamma> m p; \\<Gamma> chain = Some rs; \\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>z Undecided;\n                    \\<Gamma>,\\<gamma>,p\\<turnstile> rrs \\<Rightarrow>\\<^sub>z t \\<rbrakk> \\<Longrightarrow>\n               \\<Gamma>,\\<gamma>,p\\<turnstile> Rule m (Call chain) # rrs \\<Rightarrow>\\<^sub>z t\"\n\nprivate lemma c: \"\\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>z t \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>s t\"\n  by(induction rule: iptables_bigstep_nz.induct; simp add: iptables_bigstep_ns.intros)\n    \nprivate lemma d: \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow>\\<^sub>s t \\<Longrightarrow> s = Undecided \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>z t\"\n  by(induction rule: iptables_bigstep_ns.induct; simp add: iptables_bigstep_nz.intros)\n    \ninductive iptables_bigstep_r :: \"'a ruleset \\<Rightarrow> ('a, 'p) matcher \\<Rightarrow> 'p \\<Rightarrow> 'a rule list \\<Rightarrow> state \\<Rightarrow> bool\"\n  (\"_,_,_\\<turnstile> _ \\<Rightarrow>\\<^sub>r _\"  [60,60,60,20,98] 89)\n  for \\<Gamma> and \\<gamma> and p where\nskip:    \"\\<Gamma>,\\<gamma>,p \\<turnstile> []  \\<Rightarrow>\\<^sub>r Undecided\" |\naccept:  \"matches \\<gamma> m p \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> Rule m Accept # rs \\<Rightarrow>\\<^sub>r Decision FinalAllow\" |\ndrop:    \"matches \\<gamma> m p \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> Rule m Drop # rs \\<Rightarrow>\\<^sub>r Decision FinalDeny\" |\nreject:  \"matches \\<gamma> m p \\<Longrightarrow>  \\<Gamma>,\\<gamma>,p\\<turnstile> Rule m Reject # rs \\<Rightarrow>\\<^sub>r Decision FinalDeny\" |\nreturn:  \"matches \\<gamma> m p \\<Longrightarrow>  \\<Gamma>,\\<gamma>,p\\<turnstile> Rule m Return # rs \\<Rightarrow>\\<^sub>r Undecided\" |\nlog:     \"\\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>r t \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> Rule m Log # rs \\<Rightarrow>\\<^sub>r t\" |\nempty:   \"\\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>r t \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> Rule m Empty # rs \\<Rightarrow>\\<^sub>r t\" |\nnms:     \"\\<not> matches \\<gamma> m p \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>r t \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> Rule m a # rs \\<Rightarrow>\\<^sub>r t\" |\ncall_result:  \"\\<lbrakk> matches \\<gamma> m p; \\<Gamma> chain = Some rs; \\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>r Decision X \\<rbrakk> \\<Longrightarrow>\n               \\<Gamma>,\\<gamma>,p\\<turnstile> Rule m (Call chain) # rrs \\<Rightarrow>\\<^sub>r Decision X\" |\ncall_no_result:  \"\\<lbrakk> \\<Gamma> chain = Some rs; \\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>r Undecided;\n                    \\<Gamma>,\\<gamma>,p\\<turnstile> rrs \\<Rightarrow>\\<^sub>r t \\<rbrakk> \\<Longrightarrow>\n               \\<Gamma>,\\<gamma>,p\\<turnstile> Rule m (Call chain) # rrs \\<Rightarrow>\\<^sub>r t\"\n\nprivate lemma returning:  \"\\<lbrakk>\\<Gamma>,\\<gamma>,p\\<turnstile> rs\\<^sub>1 \\<Rightarrow>\\<^sub>r Undecided; matches \\<gamma> m' p\\<rbrakk>\n    \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> rs\\<^sub>1 @ Rule m' Return # rs\\<^sub>2 \\<Rightarrow>\\<^sub>r Undecided\"\nproof(induction rs\\<^sub>1)\n  case Nil\n  then show ?case by (simp add: return)\nnext\n  case (Cons a rs\\<^sub>3)\n  then show ?case by - (rule iptables_bigstep_r.cases[OF Cons.prems(1)]; simp add: iptables_bigstep_r.intros)\nqed\n \nprivate lemma e: \"\\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>z t \\<Longrightarrow> s = Undecided \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>r t\"\n  by(induction rule: iptables_bigstep_nz.induct; simp add: iptables_bigstep_r.intros returning)\n    \n\ndefinition \"no_call_to c rs \\<equiv> (\\<forall>r \\<in> set rs. case get_action r of Call c' \\<Rightarrow> c \\<noteq> c' | _ \\<Rightarrow> True)\"\ndefinition \"all_chains p \\<Gamma> rs \\<equiv> (p rs \\<and> (\\<forall>l rs. \\<Gamma> l = Some rs \\<longrightarrow> p rs))\"\nprivate lemma all_chains_no_call_upd: \"all_chains (no_call_to c) \\<Gamma> rs \\<Longrightarrow> (\\<Gamma>(c \\<mapsto> x)),\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>z t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>z t\"\nproof (rule iffI, goal_cases)\n  case 1\n  from 1(2,1) show ?case \n    by(induction rule: iptables_bigstep_nz.induct; \n      (simp add: iptables_bigstep_nz.intros no_call_to_def all_chains_def split: if_splits;fail)?)\nnext\n  case 2\n  from 2(2,1) show ?case \n    by(induction rule: iptables_bigstep_nz.induct; \n      (simp add: iptables_bigstep_nz.intros no_call_to_def all_chains_def split:  action.splits;fail)?)\nqed\n\nlemma updated_call: \"\\<Gamma>(c \\<mapsto> rs),\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>z t \\<Longrightarrow> matches \\<gamma> m p \\<Longrightarrow> \\<Gamma>(c \\<mapsto> rs),\\<gamma>,p\\<turnstile> [Rule m (Call c)] \\<Rightarrow>\\<^sub>z t\"\n  by(cases t; simp add: iptables_bigstep_nz.call_no_result iptables_bigstep_nz.call_result iptables_bigstep_nz.skip)\n    \nprivate lemma shows\n      log_nz:     \"\\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>z t \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> Rule m Log # rs \\<Rightarrow>\\<^sub>z t\"\nand empty_nz:   \"\\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>z t \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> Rule m Empty # rs \\<Rightarrow>\\<^sub>z t\"\n  by (meson iptables_bigstep_nz.log iptables_bigstep_nz.empty iptables_bigstep_nz.nms)+\n    \nprivate lemma nz_empty_rs_stateD: assumes \"\\<Gamma>,\\<gamma>,p\\<turnstile> [] \\<Rightarrow>\\<^sub>z t\" shows \"t = Undecided\"\n  using assms by(cases rule: iptables_bigstep_nz.cases)\n    \nprivate lemma upd_callD: \"\\<Gamma>(c \\<mapsto> rs),\\<gamma>,p\\<turnstile> [Rule m (Call c)] \\<Rightarrow>\\<^sub>z t \\<Longrightarrow> matches \\<gamma> m p \n  \\<Longrightarrow> (\\<Gamma>(c \\<mapsto> rs),\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>z t \\<or> (\\<exists>rs\\<^sub>1 rs\\<^sub>2 m'. rs = rs\\<^sub>1 @ Rule m' Return # rs\\<^sub>2 \\<and> matches \\<gamma> m' p \\<and> \\<Gamma>(c \\<mapsto> rs),\\<gamma>,p\\<turnstile> rs\\<^sub>1 \\<Rightarrow>\\<^sub>z Undecided \\<and> t = Undecided))\"\n  by(subst (asm) iptables_bigstep_nz.simps) (auto dest!: nz_empty_rs_stateD)\n    \nprivate lemma partial_fun_upd: \"(f(x \\<mapsto> y)) x = Some y\" by(fact fun_upd_same)\n \nlemma f: \"\\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>r t \\<Longrightarrow> matches \\<gamma> m p \\<Longrightarrow> all_chains (no_call_to c) \\<Gamma> rs \\<Longrightarrow> \n  (\\<Gamma>(c \\<mapsto> rs)),\\<gamma>,p\\<turnstile> [Rule m (Call c)] \\<Rightarrow>\\<^sub>z t\"\nproof(induction rule: iptables_bigstep_r.induct; (simp add: iptables_bigstep_nz.intros;fail)?)\n  case (return m rs)\n  then show ?case by (metis append_Nil fun_upd_same iptables_bigstep_nz.call_return iptables_bigstep_nz.skip)\nnext\n  case (log rs t mx)\n  have ac: \"all_chains (no_call_to c) \\<Gamma> rs\"\n    using log(4) by(simp add: all_chains_def no_call_to_def)\n  have *: \"\\<Gamma>(c \\<mapsto> Rule mx Log # rs\\<^sub>1 @ Rule m' Return # rs\\<^sub>2),\\<gamma>,p\\<turnstile> [Rule m (Call c)] \\<Rightarrow>\\<^sub>z Undecided\"\n    if \"rs = rs\\<^sub>1 @ Rule m' Return # rs\\<^sub>2\" \"matches \\<gamma> m' p\" \n       \"\\<Gamma>(c \\<mapsto> rs\\<^sub>1 @ Rule m' Return # rs\\<^sub>2),\\<gamma>,p\\<turnstile> rs\\<^sub>1 \\<Rightarrow>\\<^sub>z Undecided\"\n    for rs\\<^sub>1 rs\\<^sub>2 m'\n  proof -\n    have ac2: \"all_chains (no_call_to c) \\<Gamma> rs\\<^sub>1\" using log(4) that\n      by(simp add: all_chains_def no_call_to_def)\n    hence \"\\<Gamma>(c \\<mapsto> Rule mx Log # rs\\<^sub>1 @ Rule m' Return # rs\\<^sub>2),\\<gamma>,p\\<turnstile> rs\\<^sub>1 \\<Rightarrow>\\<^sub>z Undecided\"\n      using that(3) unfolding that by(simp add: all_chains_no_call_upd)\n        hence \"\\<Gamma>(c \\<mapsto> Rule mx Log # rs\\<^sub>1 @ Rule m' Return # rs\\<^sub>2),\\<gamma>,p\\<turnstile> Rule mx Log # rs\\<^sub>1 \\<Rightarrow>\\<^sub>z Undecided\"\n      by (simp add: log_nz)\n    thus ?thesis using that(1,2)\n      by(elim iptables_bigstep_nz.call_return[where rs\\<^sub>2=rs\\<^sub>2, OF \\<open>matches \\<gamma> m p\\<close>, rotated]; simp add: iptables_bigstep_nz.skip)\n  qed\n  from log(2)[OF log(3) ac] show ?case\n    apply -\n    apply(drule upd_callD[OF _ \\<open>matches \\<gamma> m p\\<close>])\n    apply(erule disjE)\n    subgoal\n      apply(rule updated_call[OF _ \\<open>matches \\<gamma> m p\\<close>])\n      apply(rule log_nz)\n      apply(simp add: ac all_chains_no_call_upd)\n      done\n    using * by blast\nnext\n  case (empty rs t mx) text\\<open>analogous\\<close> (*<*)\n  have ac: \"all_chains (no_call_to c) \\<Gamma> rs\"\n    using empty(4) by(simp add: all_chains_def no_call_to_def)\n  have *: \"\\<Gamma>(c \\<mapsto> Rule mx Empty # rs\\<^sub>1 @ Rule m' Return # rs\\<^sub>2),\\<gamma>,p\\<turnstile> [Rule m (Call c)] \\<Rightarrow>\\<^sub>z Undecided\"\n    if \"rs = rs\\<^sub>1 @ Rule m' Return # rs\\<^sub>2\" \"matches \\<gamma> m' p\" \n       \"\\<Gamma>(c \\<mapsto> rs\\<^sub>1 @ Rule m' Return # rs\\<^sub>2),\\<gamma>,p\\<turnstile> rs\\<^sub>1 \\<Rightarrow>\\<^sub>z Undecided\"\n    for rs\\<^sub>1 rs\\<^sub>2 m'\n  proof -\n    have ac2: \"all_chains (no_call_to c) \\<Gamma> rs\\<^sub>1\" using empty(4) that\n      by(simp add: all_chains_def no_call_to_def)\n    hence \"\\<Gamma>(c \\<mapsto> Rule mx Empty # rs\\<^sub>1 @ Rule m' Return # rs\\<^sub>2),\\<gamma>,p\\<turnstile> rs\\<^sub>1 \\<Rightarrow>\\<^sub>z Undecided\"\n      using that(3) unfolding that by(simp add: all_chains_no_call_upd)\n        hence \"\\<Gamma>(c \\<mapsto> Rule mx Empty # rs\\<^sub>1 @ Rule m' Return # rs\\<^sub>2),\\<gamma>,p\\<turnstile> Rule mx Empty # rs\\<^sub>1 \\<Rightarrow>\\<^sub>z Undecided\"\n      by (simp add: empty_nz)\n    thus ?thesis using that(1,2)\n      by(elim iptables_bigstep_nz.call_return[where rs\\<^sub>2=rs\\<^sub>2, OF \\<open>matches \\<gamma> m p\\<close>, rotated]; simp add: iptables_bigstep_nz.skip)\n  qed\n  from empty(2)[OF empty(3) ac] show ?case\n    apply -\n    apply(drule upd_callD[OF _ \\<open>matches \\<gamma> m p\\<close>])\n    apply(erule disjE)\n    subgoal\n      apply(rule updated_call[OF _ \\<open>matches \\<gamma> m p\\<close>])\n      apply(rule empty_nz)\n      apply(simp add: ac all_chains_no_call_upd)\n      done\n    using * by blast\n    (*>*)\nnext\n  case (nms m' rs t a)\n  have ac: \"all_chains (no_call_to c) \\<Gamma> rs\" using nms(5) by(simp add: all_chains_def no_call_to_def)\n  from nms.IH[OF nms(4) ac] show ?case\n    apply -\n    apply(drule upd_callD[OF _ \\<open>matches \\<gamma> m p\\<close>])\n    apply(erule disjE)\n    subgoal\n      apply(rule updated_call[OF _ \\<open>matches \\<gamma> m p\\<close>])\n      apply(rule iptables_bigstep_nz.nms[OF \\<open>\\<not> matches \\<gamma> m' p\\<close>])\n      apply(simp add: ac all_chains_no_call_upd)\n      done\n    apply safe\n    subgoal for rs\\<^sub>1 rs\\<^sub>2 r\n      apply(subgoal_tac \"all_chains (no_call_to c) \\<Gamma> rs\\<^sub>1\") (* Ich kann auch anders. *)\n       apply(subst (asm) all_chains_no_call_upd, assumption)\n       apply(subst (asm) all_chains_no_call_upd[symmetric], assumption)\n       apply(drule iptables_bigstep_nz.nms[where a=a, OF \\<open>\\<not> matches \\<gamma> m' p\\<close>])\n       apply(erule (1) iptables_bigstep_nz.call_return[where rs\\<^sub>2=rs\\<^sub>2, OF \\<open>matches \\<gamma> m p\\<close>, rotated])\n        apply(insert ac; simp add: all_chains_def no_call_to_def iptables_bigstep_nz.skip)+\n      done\n    done\nnext\n  case (call_result m' c' rs X rrs)\n  have acrs: \"all_chains (no_call_to c) \\<Gamma> rs\" using call_result(2,6) by(simp add: all_chains_def no_call_to_def)\n  have cc: \"c \\<noteq> c'\" (* okay, this one is a bit nifty\\<dots> *) using call_result(6) by(simp add: all_chains_def no_call_to_def)\n  have \"\\<Gamma>(c \\<mapsto> rs),\\<gamma>,p\\<turnstile> [Rule m (Call c)] \\<Rightarrow>\\<^sub>z Decision X\" using call_result.IH call_result.prems(1) acrs by blast\n  then show ?case\n    apply -\n    apply(drule upd_callD[OF _ \\<open>matches \\<gamma> m p\\<close>])\n    apply(erule disjE)\n    subgoal\n      apply(rule updated_call[OF _ \\<open>matches \\<gamma> m p\\<close>])\n      apply(rule iptables_bigstep_nz.call_result[where rs=rs, OF \\<open>matches \\<gamma> m' p\\<close> ])\n      apply(simp add: cc[symmetric] call_result(2);fail)\n      apply(simp add: acrs all_chains_no_call_upd;fail)\n      done\n    apply safe (* oh. Didn't expect that. :) *)\n  done\nnext\n  case (call_no_result c' rs rrs t m')\n  have acrs: \"all_chains (no_call_to c) \\<Gamma> rs\" using call_no_result(1,7) by(simp add: all_chains_def no_call_to_def)\n  have acrrs: \"all_chains (no_call_to c) \\<Gamma> rrs\" using call_no_result(7) by(simp add: all_chains_def no_call_to_def)\n  have acrs1: \"all_chains (no_call_to c) \\<Gamma> rs\\<^sub>1\" if \"rs = rs\\<^sub>1 @ rs\\<^sub>2\" for rs\\<^sub>1 rs\\<^sub>2\n    using acrs that by(simp add: all_chains_def no_call_to_def)\n  have acrrs1: \"all_chains (no_call_to c) \\<Gamma> rs\\<^sub>1\" if \"rrs = rs\\<^sub>1 @ rs\\<^sub>2\" for rs\\<^sub>1 rs\\<^sub>2\n    using acrrs that by(simp add: all_chains_def no_call_to_def)\n  have cc: \"c \\<noteq> c'\" (* okay, this one is a bit nifty\\<dots> *) using call_no_result(7) by(simp add: all_chains_def no_call_to_def)\n  have *: \"\\<Gamma>(c \\<mapsto> rs),\\<gamma>,p\\<turnstile> [Rule m (Call c)] \\<Rightarrow>\\<^sub>z Undecided\" using call_no_result.IH call_no_result.prems(1) acrs by blast\n  have **: \"\\<Gamma>(c \\<mapsto> rrs),\\<gamma>,p\\<turnstile> [Rule m (Call c)] \\<Rightarrow>\\<^sub>z t\" by (simp add: acrrs call_no_result.IH(2) call_no_result.prems(1))\n  show ?case proof(cases \\<open>matches \\<gamma> m' p\\<close>)\n    case True\n    from call_no_result(5)[OF \\<open>matches \\<gamma> m p\\<close> acrrs] * show ?thesis\n      apply -\n      apply(drule upd_callD[OF _ \\<open>matches \\<gamma> m p\\<close>])+\n      apply(elim disjE) (* 4 sg *)\n      apply safe\n      subgoal\n        apply(rule updated_call[OF _ \\<open>matches \\<gamma> m p\\<close>])\n        apply(rule iptables_bigstep_nz.call_no_result[where rs=rs, OF \\<open>matches \\<gamma> m' p\\<close> ])\n        apply(simp add: cc[symmetric] call_no_result(1);fail)\n         apply(simp add: acrs all_chains_no_call_upd;fail)\n        apply(simp add: acrrs all_chains_no_call_upd)\n        done\n      subgoal for rs\\<^sub>1 rs\\<^sub>2 r\n        apply(rule updated_call[OF _ \\<open>matches \\<gamma> m p\\<close>])\n        apply(rule call_return[OF \\<open>matches \\<gamma> m' p\\<close>])\n           apply(simp add: cc[symmetric] call_no_result(1);fail)\n          apply(simp;fail)\n         apply(simp add: acrs1 all_chains_no_call_upd;fail)\n        apply(simp add: acrrs all_chains_no_call_upd)\n        done\n      subgoal for rs\\<^sub>1 rs\\<^sub>2 r\n        apply(rule call_return[where rs\\<^sub>1=\"Rule m' (Call c') # rs\\<^sub>1\", OF \\<open>matches \\<gamma> m p\\<close>])\n           apply(simp;fail)\n          apply(simp;fail)\n        apply(rule iptables_bigstep_nz.call_no_result[OF \\<open>matches \\<gamma> m' p\\<close>])\n           apply(simp add: cc[symmetric] call_no_result(1);fail)\n          apply (meson acrs all_chains_no_call_upd)\n         apply(subst all_chains_no_call_upd; simp add: acrrs1 all_chains_no_call_upd; fail)\n        apply (simp add: iptables_bigstep_nz.skip;fail)\n        done\n      subgoal for rrs\\<^sub>1 rs\\<^sub>1 rrs\\<^sub>2 rs\\<^sub>2 rr r\n         apply(rule call_return[where rs\\<^sub>1=\"Rule m' (Call c') # rrs\\<^sub>1\", OF \\<open>matches \\<gamma> m p\\<close>])\n           apply(simp;fail)\n          apply(simp;fail)\n         apply(rule call_return[OF \\<open>matches \\<gamma> m' p\\<close>])\n            apply(simp add: cc[symmetric] call_no_result(1);fail)\n           apply blast\n          apply (meson acrs1 all_chains_no_call_upd)\n         apply(subst all_chains_no_call_upd; simp add: acrrs1 all_chains_no_call_upd; fail)\n        apply (simp add: iptables_bigstep_nz.skip;fail)\n        done\n      done\n  next\n    case False\n    from iptables_bigstep_nz.nms[OF False] ** show ?thesis \n      apply -\n      apply(drule upd_callD[OF _ \\<open>matches \\<gamma> m p\\<close>])+\n      apply(elim disjE)\n      subgoal\n        apply(rule updated_call[OF _ \\<open>matches \\<gamma> m p\\<close>])\n        apply(rule iptables_bigstep_nz.nms[OF False])\n        apply(simp add: acrrs all_chains_no_call_upd)\n        done\n      apply safe\n      subgoal for rs\\<^sub>1 rs\\<^sub>2 r\n        apply(rule call_return[where rs\\<^sub>1=\"Rule m' (Call c') # rs\\<^sub>1\", OF \\<open>matches \\<gamma> m p\\<close>])\n           apply(simp;fail)\n          apply(simp;fail)\n         apply(rule iptables_bigstep_nz.nms[OF False])\n         apply(subst all_chains_no_call_upd; simp add: acrrs1 all_chains_no_call_upd; fail)\n        apply(simp add: iptables_bigstep_nz.skip;fail)\n        done\n      done\n  qed\nqed\n  \nlemma r_skip_inv: \"\\<Gamma>,\\<gamma>,p\\<turnstile> [] \\<Rightarrow>\\<^sub>r t \\<Longrightarrow> t = Undecided\"\n  by(subst (asm) iptables_bigstep_r.simps) auto\n  \n(* why did I do all this? essentially, because I thought this should be derivable: *)\n\n\n(* we can make the same formulation for the original semantics if we tread a bit more carefully *)\nlemma call_eq: \"\\<Gamma> c = Some rs \\<Longrightarrow> matches \\<gamma> m p \\<Longrightarrow> \\<forall>r \\<in> set rs. get_action r \\<noteq> Return  \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule m (Call c)],s\\<rangle> \\<Rightarrow> t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs,s\\<rangle> \\<Rightarrow> t\"\n  apply(rule iffI)\n  subgoal\n    apply(subst (asm) iptables_bigstep.simps)\n    apply (auto)\n     apply (simp add: decision)\n    apply(erule rules_singleton_rev_E; simp; metis callD in_set_conv_decomp rule.sel(2) skipD)\n  done\n  by (metis decision iptables_bigstep.call_result iptables_bigstep_deterministic state.exhaust)\n  \ntheorem r_eq_orig: \"\\<lbrakk>all_chains (no_call_to c) \\<Gamma> rs; \\<Gamma> c = Some rs\\<rbrakk> \\<Longrightarrow>\n   \\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>r t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule MatchAny (Call c)], Undecided\\<rangle> \\<Rightarrow> t\"\n  apply(rule iffI)\n  subgoal\n    apply(drule f[where m=MatchAny, THEN c, THEN a])\n      apply(simp;fail)\n     apply(simp;fail)\n    apply (metis fun_upd_triv)\n    done  \n  subgoal\n    apply(subst r_call_eq[where m=MatchAny, symmetric])\n      apply(simp;fail)\n     apply(simp;fail)\n    apply(erule b[THEN d, THEN e, OF _ refl refl refl])\n    done\n  done\n    \nlemma r_no_call: \"\\<Gamma>,\\<gamma>,p\\<turnstile> Rule MatchAny (Call c)#rs \\<Rightarrow>\\<^sub>r t \\<Longrightarrow> \\<Gamma> c = None \\<Longrightarrow> False\"\n  by(subst (asm) iptables_bigstep_r.simps) simp\n    \nlemma no_call: \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow> t \\<Longrightarrow> rs = [Rule MatchAny (Call c)] \\<Longrightarrow> s = Undecided \\<Longrightarrow> \\<Gamma> c = None \\<Longrightarrow> False\"\n  by (meson b d e r_no_call)\n  (*by(induction rule: iptables_bigstep.induct; clarsimp) (metis list_app_singletonE skipD)*)\n\nprivate corollary r_eq_orig': assumes \"\\<forall>rs \\<in> ran \\<Gamma>. no_call_to c rs\"\n  shows \"\\<Gamma>,\\<gamma>,p\\<turnstile> [Rule MatchAny (Call c)] \\<Rightarrow>\\<^sub>r t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule MatchAny (Call c)], Undecided\\<rangle> \\<Rightarrow> t\"\n(* if you really like symmetry *)\nproof -\n  show ?thesis proof (cases \"\\<Gamma> c\")\n    fix rs\n    assume \"\\<Gamma> c = Some rs\"\n    moreover hence \"all_chains (no_call_to c) \\<Gamma> rs\" using assms by (simp add: all_chains_def ranI)\n    ultimately show ?thesis by(simp add: r_call_eq r_eq_orig)\n  next\n    assume \"\\<Gamma> c = None\" thus ?thesis using r_no_call no_call by metis\n  qed\nqed\n  \n(* btw, we can still formulate a seq rules, but we have to tread a bit more carefully *)\nlemma r_tail: assumes \"\\<Gamma>,\\<gamma>,p\\<turnstile> rs1 \\<Rightarrow>\\<^sub>r Decision X\" shows \"\\<Gamma>,\\<gamma>,p\\<turnstile> rs1 @ rs2 \\<Rightarrow>\\<^sub>r Decision X\"\nproof -\n  have \"\\<Gamma>,\\<gamma>,p\\<turnstile> rs1 \\<Rightarrow>\\<^sub>r t \\<Longrightarrow> t = Decision X \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> rs1 @ rs2 \\<Rightarrow>\\<^sub>r Decision X\" for t\n    by(induction rule: iptables_bigstep_r.induct; simp add: iptables_bigstep_r.intros)\n  thus ?thesis using assms by blast\nqed\nlemma r_seq: \"\\<Gamma>,\\<gamma>,p\\<turnstile> rs1 \\<Rightarrow>\\<^sub>r Undecided \\<Longrightarrow> \\<forall>r \\<in> set rs1. \\<not>(get_action r = Return \\<and> matches \\<gamma> (get_match r) p)\n   \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> rs2 \\<Rightarrow>\\<^sub>r t \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> rs1 @ rs2 \\<Rightarrow>\\<^sub>r t\"\nproof(induction rs1)\n  case Nil\n  then show ?case by simp\nnext\n  case (Cons r rs1)\n  have p2: \"\\<forall>r\\<in>set rs1. \\<not> (get_action r = Return \\<and> matches \\<gamma> (get_match r) p)\" \n           \"\\<not>(get_action r = Return \\<and> matches \\<gamma> (get_match r) p)\"\n    by (simp_all add: Cons.prems(2))\n  from Cons.prems(1) p2(2) Cons.IH[OF _ p2(1) Cons.prems(3)] show ?case \n    by(cases rule: iptables_bigstep_r.cases; simp add: iptables_bigstep_r.intros)\nqed\n\nlemma r_appendD: \"\\<Gamma>,\\<gamma>,p\\<turnstile> rs1 @ rs2 \\<Rightarrow>\\<^sub>r t \\<Longrightarrow> \\<exists>s. \\<Gamma>,\\<gamma>,p\\<turnstile> rs1 \\<Rightarrow>\\<^sub>r s\"\n  proof(induction rs1)\n    case (Cons r rs1)\n    from Cons.prems Cons.IH show ?case by(cases rule: iptables_bigstep_r.cases) (auto intro: iptables_bigstep_r.intros)\n  qed (meson iptables_bigstep_r.skip)\n\ncorollary iptables_bigstep_r_eq: assumes \"\\<forall>rs \\<in> ran \\<Gamma>. no_call_to c rs\" \"A = Accept \\<or> A = Drop\"\n  shows \"\\<Gamma>,\\<gamma>,p\\<turnstile> [Rule MatchAny (Call c), Rule MatchAny A] \\<Rightarrow>\\<^sub>r t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule MatchAny (Call c), Rule MatchAny A], Undecided\\<rangle> \\<Rightarrow> t\"\n(* if you really like the way we do our analyses *)\nproof -\n  show ?thesis proof (cases \"\\<Gamma> c\")\n    fix rs\n    assume \"\\<Gamma> c = Some rs\"\n    moreover hence \"all_chains (no_call_to c) \\<Gamma> rs\" using assms by (simp add: all_chains_def ranI)\n    show ?thesis\n      (* if this proof breaks, don't fix it. say 'meh' and re-prove this as a corollary of r_eq_orig''' with a stronger assumption *)\n      apply(rule iffI[rotated])\n       apply(erule seqE_cons)\n       apply(subst (asm) r_eq_orig'[symmetric])\n        apply (simp add: assms(1);fail)\n       apply (meson assms(1) b d e r_eq_orig' seq'_cons) (* holy shi\\<dots> *)\n      apply(frule r_appendD[of _ _ _ \"[Rule MatchAny (Call c)]\" \"[Rule MatchAny A]\", simplified])\n      apply(subst (asm) r_eq_orig')\n        apply (simp add: assms(1);fail)\n        apply(clarsimp)\n      apply(subst (asm) r_eq_orig'[symmetric])\n       apply (simp add: assms(1);fail)\n      apply(subst (asm)(2) iptables_bigstep_r.simps)\n      apply(subst (asm)(1) iptables_bigstep_r.simps)\n      apply auto\n         apply (metis append_Cons append_Nil assms(1) decision matches.simps(4) r_call_eq r_eq_orig' seq)\n        apply (metis \\<open>all_chains (no_call_to c) \\<Gamma> rs\\<close> calculation iptables_bigstep_deterministic option.inject r_eq_orig state.distinct(1))\n      subgoal using \\<open>all_chains (no_call_to c) \\<Gamma> rs\\<close> calculation iptables_bigstep_deterministic r_eq_orig by fastforce\n      apply(subst (asm) r_eq_orig[rotated])\n        apply(assumption)\n      subgoal using \\<open>all_chains (no_call_to c) \\<Gamma> rs\\<close> calculation by simp\n      apply(erule seq'_cons)\n      apply(subst (asm)(1) iptables_bigstep_r.simps)  \n      apply(insert assms(2); auto simp add: iptables_bigstep.intros)\n      done        \n  next\n    assume \"\\<Gamma> c = None\" thus ?thesis using r_no_call no_call by (metis seqE_cons)\n  qed\nqed\n\n(* now, you don't like that no_call_to assumption? this one's for you: *)\nlemma ex_no_call: \"finite S \\<Longrightarrow> \\<exists>c. \\<forall>(rs :: 'a rule list) \\<in> S. no_call_to c rs\"\n(* If you want, you can put in \\<open>ran \\<Gamma>\\<close> for S. *)\nproof -\n  assume fS: \\<open>finite S\\<close>\n  def called_c \\<equiv> \"\\<lambda>rs :: 'a rule list. {c. \\<exists>m. Rule m (Call c) \\<in> set rs}\"\n  def called_c' \\<equiv> \"\\<lambda>rs :: 'a rule list. set [c. r \\<leftarrow> rs, c \\<leftarrow> (case get_action r of Call c \\<Rightarrow> [c] | _ \\<Rightarrow> [])]\"\n  have cc: \"called_c' rs = called_c rs\" for rs\n    unfolding called_c'_def called_c_def\n    by(induction rs; simp add: Un_def) (auto; metis rule.collapse)      \n  have f: \"finite (called_c rs)\" for rs unfolding cc[symmetric] called_c'_def by blast\n  have ncc: \"no_call_to c rs \\<longleftrightarrow> c \\<notin> called_c rs\" for c rs \n    by(induction rs; auto simp add: no_call_to_def called_c_def split: action.splits) (metis rule.collapse)\n  have isu: \"infinite (UNIV :: string set)\" by (simp add: infinite_UNIV_listI)\n  have ff: \"finite (\\<Union>rs \\<in> S. called_c rs)\" using f fS by simp\n  then obtain c where ne: \"c \\<notin> (\\<Union>rs \\<in> S. called_c rs)\"\n    by (blast dest: ex_new_if_finite[OF isu])\n  thus ?thesis by(intro exI[where x=c]) (simp add: ncc)\n  (* stupid way of proving something, once again\\<dots> *)\nqed\n\nprivate lemma ex_no_call': \"finite (dom \\<Gamma>) \\<Longrightarrow> \\<exists>c. \\<Gamma> c = None \\<and> (\\<forall>(rs :: 'a rule list) \\<in> (ran \\<Gamma>). no_call_to c rs)\"\n(* I want a corollary, and I need something a tad stronger\\<dots> *)\nproof -\n  have *: \"finite S \\<Longrightarrow> (dom M) = S \\<Longrightarrow> \\<exists>m. M = map_of m\" for M S\n  proof(induction arbitrary: M rule: finite.induct)\n    case emptyI\n    then show ?case by(intro exI[where x=Nil]) simp\n  next\n    case (insertI A a)\n    show ?case proof(cases \"a \\<in> A\") (* stupid induction rule *)\n      case True\n      then show ?thesis using insertI by (simp add: insert_absorb)\n    next\n      case False\n      hence \"dom (M(a := None)) = A\" using insertI.prems by simp\n      from insertI.IH[OF this] obtain m where \"M(a := None) = map_of m\" ..\n      then show ?thesis \n        by(intro exI[where x=\"(a, the (M a)) # m\"]) (simp; metis domIff fun_upd_apply insertCI insertI.prems option.collapse)\n    qed\n  qed (* hm, thought that would give me what I want\\<dots> *)\n  have ran_alt: \"ran f = (the o f) ` dom f\" for f by(auto simp add: ran_def dom_def image_def)\n  assume fD: \\<open>finite (dom \\<Gamma>)\\<close>\n  hence fS: \\<open>finite (ran \\<Gamma>)\\<close> by(simp add: ran_alt)\n  def called_c \\<equiv> \"\\<lambda>rs :: 'a rule list. {c. \\<exists>m. Rule m (Call c) \\<in> set rs}\"\n  def called_c' \\<equiv> \"\\<lambda>rs :: 'a rule list. set [c. r \\<leftarrow> rs, c \\<leftarrow> (case get_action r of Call c \\<Rightarrow> [c] | _ \\<Rightarrow> [])]\"\n  have cc: \"called_c' rs = called_c rs\" for rs\n    unfolding called_c'_def called_c_def\n    by(induction rs; simp add: Un_def) (auto; metis rule.collapse)      \n  have f: \"finite (called_c rs)\" for rs unfolding cc[symmetric] called_c'_def by blast\n  have ncc: \"no_call_to c rs \\<longleftrightarrow> c \\<notin> called_c rs\" for c rs \n    by(induction rs; auto simp add: no_call_to_def called_c_def split: action.splits) (metis rule.collapse) \n  have isu: \"infinite (UNIV :: string set)\" by (simp add: infinite_UNIV_listI)\n  have ff: \"finite (\\<Union>rs \\<in> ran \\<Gamma>. called_c rs)\" using f fS by simp\n  hence fff: \"finite (dom \\<Gamma> \\<union> (\\<Union>rs \\<in> ran \\<Gamma>. called_c rs))\" using fD by simp\n  then obtain c where ne: \"c \\<notin> (dom \\<Gamma> \\<union> (\\<Union>rs \\<in> ran \\<Gamma>. called_c rs))\" thm ex_new_if_finite\n    by (metis UNIV_I isu set_eqI)\n  thus ?thesis by(fastforce simp add: ncc)\nqed\n  \nlemma all_chains_no_call_upd_r: \"all_chains (no_call_to c) \\<Gamma> rs \\<Longrightarrow> (\\<Gamma>(c \\<mapsto> x)),\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>r t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>r t\"\nproof (rule iffI, goal_cases)\n  case 1\n  from 1(2,1) show ?case \n    by(induction rule: iptables_bigstep_r.induct; \n      (simp add: iptables_bigstep_r.intros no_call_to_def all_chains_def split: if_splits;fail)?)\nnext\n  case 2\n  from 2(2,1) show ?case \n    by(induction rule: iptables_bigstep_r.induct; \n      (simp add: iptables_bigstep_r.intros no_call_to_def all_chains_def split:  action.splits;fail)?)\nqed\n\n(* in a sense, this is code duplication with Ruleset_Update, but it's different enough that I can't use it. *)\nlemma all_chains_no_call_upd_orig: \"all_chains (no_call_to c) \\<Gamma> rs \\<Longrightarrow> (\\<Gamma>(c \\<mapsto> x)),\\<gamma>,p\\<turnstile> \\<langle>rs,s\\<rangle> \\<Rightarrow> t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs,s\\<rangle> \\<Rightarrow> t\"\nproof (rule iffI, goal_cases)\n  case 1\n  from 1(2,1) show ?case \n    by(induction rs s t rule: iptables_bigstep.induct; \n      (simp add: iptables_bigstep.intros no_call_to_def all_chains_def split: if_splits;fail)?)\nnext\n  case 2\n  from 2(2,1) show ?case \n    by(induction rule: iptables_bigstep.induct; \n      (simp add: iptables_bigstep.intros no_call_to_def all_chains_def split:  action.splits;fail)?)\nqed\n  \n  \ncorollary r_eq_orig''': assumes \"finite (ran \\<Gamma>)\" and \"\\<forall>r \\<in> set rs. get_action r \\<noteq> Return\"\n  shows \"\\<Gamma>,\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>r t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, Undecided\\<rangle> \\<Rightarrow> t\"\nproof -\n  from assms have \"finite ({rs} \\<union> (ran \\<Gamma>))\" by simp\n  from ex_no_call[OF this] obtain c where c: \"(\\<forall>rs\\<in>ran \\<Gamma>. no_call_to c rs)\" \"no_call_to c rs\" by blast\n  hence acnc: \"all_chains (no_call_to c) \\<Gamma> rs\" unfolding all_chains_def by (simp add: ranI)\n  have ranaway: \"\\<forall>rs\\<in>ran (\\<Gamma>(c \\<mapsto> rs)). no_call_to c rs\"\n  proof -\n    { (* hammer *)\n      fix rsa :: \"'a rule list\"\n      assume a1: \"rsa \\<in> ran (\\<Gamma>(c \\<mapsto> rs))\"\n      have \"\\<And>R. rs \\<in> R \\<union> Collect (no_call_to c)\"\n        using c(2) by force\n      then have \"rsa \\<in> ran (\\<Gamma>(c := None)) \\<union> Collect (no_call_to c)\"\n        using a1 by (metis (no_types) Un_iff Un_insert_left fun_upd_same fun_upd_upd insert_absorb ran_map_upd)\n      then have \"no_call_to c rsa\"\n        by (metis (no_types) Un_iff c(1) mem_Collect_eq ranI ran_restrictD restrict_complement_singleton_eq)\n    }\n    thus ?thesis by simp\n  qed\n  have \"\\<Gamma>(c \\<mapsto> rs),\\<gamma>,p\\<turnstile> rs \\<Rightarrow>\\<^sub>r t \\<longleftrightarrow> \\<Gamma>(c \\<mapsto> rs),\\<gamma>,p\\<turnstile> \\<langle>rs, Undecided\\<rangle> \\<Rightarrow> t\"\n    apply(subst r_call_eq[where c=c and m=MatchAny,symmetric])\n      apply(simp;fail)\n     apply(simp;fail)\n    apply(subst call_eq[where c=c and m=MatchAny,symmetric])\n      apply(simp;fail)\n      apply(simp;fail)\n     apply(simp add: assms;fail)\n    apply(rule r_eq_orig')\n    apply(fact ranaway)\n    done\n  thus ?thesis \n    apply -\n    apply(subst (asm) all_chains_no_call_upd_r[where x=rs, OF acnc])\n    apply(subst (asm) all_chains_no_call_upd_orig[where x=rs, OF acnc])\n    .\nqed\n\nend\n\nend\n", "meta": {"author": "diekmann", "repo": "Iptables_Semantics", "sha": "e0a2516bd885708fce875023b474ae341cbdee29", "save_path": "github-repos/isabelle/diekmann-Iptables_Semantics", "path": "github-repos/isabelle/diekmann-Iptables_Semantics/Iptables_Semantics-e0a2516bd885708fce875023b474ae341cbdee29/thy/Iptables_Semantics/Alternative_Semantics.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7025300573952052, "lm_q2_score": 0.42632159254749036, "lm_q1q2_score": 0.2995037328812037}}
{"text": "theory Initialization\nimports UnitPropagate\nbegin\n\n\n(*********************************************************************************)\n(*    A D D    C L A U S E                                                       *)\n(*********************************************************************************)\n\nlemma InvariantsAfterAddClause:\nfixes state::State and clause :: Clause and Vbl :: \"Variable set\"\nassumes\n  \"InvariantConsistent (getM state)\"\n  \"InvariantUniq (getM state)\"\n  \"InvariantWatchListsContainOnlyClausesFromF (getWatchList state) (getF state)\" and\n  \"InvariantWatchListsUniq (getWatchList state)\" and\n  \"InvariantWatchListsCharacterization (getWatchList state) (getWatch1 state) (getWatch2 state)\"\n  \"InvariantWatchesEl (getF state) (getWatch1 state) (getWatch2 state)\" and\n  \"InvariantWatchesDiffer (getF state) (getWatch1 state) (getWatch2 state)\" and\n  \"InvariantWatchCharacterization (getF state) (getWatch1 state) (getWatch2 state) (getM state)\"\n  \"InvariantConflictFlagCharacterization (getConflictFlag state) (getF state) (getM state)\"\n  \"InvariantConflictClauseCharacterization (getConflictFlag state) (getConflictClause state) (getF state) (getM state)\"\n  \"InvariantQCharacterization (getConflictFlag state) (getQ state) (getF state) (getM state)\"\n  \"InvariantUniqQ (getQ state)\"\n  \"InvariantGetReasonIsReason (getReason state) (getF state) (getM state) (set (getQ state))\"\n  \"currentLevel (getM state) = 0\"\n  \"(getConflictFlag state) \\<or> (getQ state) = []\"\n  \"InvariantVarsM (getM state) F0 Vbl\"\n  \"InvariantVarsQ (getQ state) F0 Vbl\"\n  \"InvariantVarsF (getF state) F0 Vbl\"\n  \"finite Vbl\"\n  \"vars clause \\<subseteq> vars F0\"\nshows\n  \"let state' = (addClause clause state) in\n      InvariantConsistent (getM state') \\<and> \n      InvariantUniq (getM state') \\<and> \n      InvariantWatchListsContainOnlyClausesFromF (getWatchList state') (getF state') \\<and> \n      InvariantWatchListsUniq (getWatchList state') \\<and> \n      InvariantWatchListsCharacterization (getWatchList state') (getWatch1 state') (getWatch2 state') \\<and> \n      InvariantWatchesEl (getF state') (getWatch1 state') (getWatch2 state') \\<and> \n      InvariantWatchesDiffer (getF state') (getWatch1 state') (getWatch2 state') \\<and> \n      InvariantWatchCharacterization (getF state') (getWatch1 state') (getWatch2 state') (getM state') \\<and> \n      InvariantConflictFlagCharacterization (getConflictFlag state') (getF state') (getM state') \\<and> \n      InvariantConflictClauseCharacterization (getConflictFlag state') (getConflictClause state') (getF state') (getM state') \\<and> \n      InvariantQCharacterization (getConflictFlag state') (getQ state') (getF state') (getM state') \\<and> \n      InvariantGetReasonIsReason (getReason state') (getF state') (getM state') (set (getQ state')) \\<and> \n      InvariantUniqQ (getQ state') \\<and> \n      InvariantVarsQ (getQ state') F0 Vbl \\<and> \n      InvariantVarsM (getM state') F0 Vbl \\<and> \n      InvariantVarsF (getF state') F0 Vbl \\<and> \n      currentLevel (getM state') = 0 \\<and> \n      ((getConflictFlag state') \\<or> (getQ state') = [])\n\"\nproof-\n  let ?clause' = \"remdups (removeFalseLiterals clause (elements (getM state)))\"\n\n  have *: \"\\<forall> l. l el ?clause' \\<longrightarrow> \\<not> literalFalse l (elements (getM state))\"\n    unfolding removeFalseLiterals_def\n    by auto\n\n  have \"vars ?clause' \\<subseteq> vars clause\"\n    using varsSubsetValuation[of \"?clause'\" \"clause\"]\n    unfolding removeFalseLiterals_def\n    by auto\n  hence \"vars ?clause' \\<subseteq> vars F0\"\n    using \\<open>vars clause \\<subseteq> vars F0\\<close>\n    by simp\n\n  show ?thesis\n  proof (cases \"clauseTrue ?clause' (elements (getM state))\")\n    case True\n    thus ?thesis\n      using assms\n      unfolding addClause_def\n      by simp\n  next\n    case False\n    show ?thesis\n    proof (cases \"?clause' = []\")\n      case True\n      thus ?thesis\n        using assms\n        using \\<open>\\<not> clauseTrue ?clause' (elements (getM state))\\<close>\n        unfolding addClause_def\n        by simp\n    next\n      case False\n      thus ?thesis\n      proof (cases \"length ?clause' = 1\")\n        case True\n        let ?state' = \"assertLiteral (hd ?clause') False state\"\n        have \"addClause clause state = exhaustiveUnitPropagate ?state'\"\n          using \\<open>\\<not> clauseTrue ?clause' (elements (getM state))\\<close>\n          using \\<open>\\<not> ?clause' = []\\<close>\n          using \\<open>length ?clause' = 1\\<close>\n          unfolding addClause_def\n          by (simp add: Let_def)\n        moreover\n        from \\<open>?clause' \\<noteq> []\\<close>\n        have \"hd ?clause' \\<in> set ?clause'\"\n          using hd_in_set[of \"?clause'\"]\n          by simp\n        with *\n        have \"\\<not> literalFalse (hd ?clause') (elements (getM state))\"\n          by simp\n        hence \"consistent (elements ((getM state) @ [(hd ?clause', False)]))\"\n          using assms\n          unfolding InvariantConsistent_def\n          using consistentAppendElement[of \"elements (getM state)\" \"hd ?clause'\"]\n          by simp\n        hence \"consistent (elements (getM ?state'))\"\n          using assms\n          using assertLiteralEffect[of \"state\" \"hd ?clause'\" \"False\"]\n          by simp\n        moreover\n        from \\<open>\\<not> clauseTrue ?clause' (elements (getM state))\\<close>\n        have \"uniq (elements (getM ?state'))\"\n          using assms\n          using assertLiteralEffect[of \"state\" \"hd ?clause'\" \"False\"]\n          using \\<open>hd ?clause' \\<in> set ?clause'\\<close>\n          unfolding InvariantUniq_def\n          by (simp add: uniqAppendIff clauseTrueIffContainsTrueLiteral)\n        moreover\n        have \"InvariantWatchListsContainOnlyClausesFromF (getWatchList ?state') (getF ?state')\" and\n          \"InvariantWatchListsUniq (getWatchList ?state')\" and\n          \"InvariantWatchListsCharacterization (getWatchList ?state') (getWatch1 ?state') (getWatch2 ?state')\"\n          \"InvariantWatchesEl (getF ?state') (getWatch1 ?state') (getWatch2 ?state')\" and\n          \"InvariantWatchesDiffer (getF ?state') (getWatch1 ?state') (getWatch2 ?state')\"\n          using assms\n          using WatchInvariantsAfterAssertLiteral[of \"state\" \"hd ?clause'\" \"False\"]\n          by (auto simp add: Let_def)\n        moreover\n        have \"InvariantWatchCharacterization (getF ?state') (getWatch1 ?state') (getWatch2 ?state') (getM ?state')\"\n          using assms\n          using InvariantWatchCharacterizationAfterAssertLiteral[of \"state\" \"hd ?clause'\" \"False\"]\n          using \\<open>uniq (elements (getM ?state'))\\<close>\n          using \\<open>consistent (elements (getM ?state'))\\<close>\n          unfolding InvariantConsistent_def\n          unfolding InvariantUniq_def\n          using assertLiteralEffect[of \"state\" \"hd ?clause'\" \"False\"]\n          by (simp add: Let_def)\n        moreover\n        have \"InvariantConflictFlagCharacterization (getConflictFlag ?state') (getF ?state') (getM ?state')\"\n          using assms\n          using InvariantConflictFlagCharacterizationAfterAssertLiteral[of \"state\" \"hd ?clause'\" \"False\"]\n          using \\<open>consistent (elements (getM ?state'))\\<close>\n          unfolding InvariantConsistent_def\n          using assertLiteralEffect[of \"state\" \"hd ?clause'\" \"False\"]\n          by (simp add: Let_def)\n        moreover\n        have \"InvariantConflictClauseCharacterization (getConflictFlag ?state') (getConflictClause ?state') (getF ?state') (getM ?state')\"\n          using assms\n          using InvariantConflictClauseCharacterizationAfterAssertLiteral[of \"state\" \"hd ?clause'\" \"False\"]\n          by (simp add: Let_def)\n        moreover\n        let ?state'' = \"?state'\\<lparr> getM := (getM ?state') @ [(hd ?clause', False)] \\<rparr>\"\n        have \"InvariantQCharacterization (getConflictFlag ?state') (getQ ?state') (getF ?state') (getM ?state')\"\n        proof (cases \"getConflictFlag state\")\n          case True\n          hence \"getConflictFlag ?state'\"\n            using assms\n            using assertLiteralConflictFlagEffect[of \"state\" \"hd ?clause'\" \"False\"]\n            using \\<open>uniq (elements (getM ?state'))\\<close>\n            using \\<open>consistent (elements (getM ?state'))\\<close>\n            unfolding InvariantConsistent_def\n            unfolding InvariantUniq_def\n            using assertLiteralEffect[of \"state\" \"hd ?clause'\" \"False\"]\n            by (auto simp add: Let_def)\n          thus ?thesis\n            using assms\n            unfolding InvariantQCharacterization_def\n            by simp\n        next\n          case False\n          with \\<open>(getConflictFlag state) \\<or> (getQ state) = []\\<close>\n          have \"getQ state = []\"\n            by simp\n          thus ?thesis\n            using InvariantQCharacterizationAfterAssertLiteralNotInQ[of \"state\" \"hd ?clause'\" \"False\"]\n            using assms\n            using \\<open>uniq (elements (getM ?state'))\\<close>\n            using \\<open>consistent (elements (getM ?state'))\\<close>\n            unfolding InvariantConsistent_def\n            unfolding InvariantUniq_def\n            using assertLiteralEffect[of \"state\" \"hd ?clause'\" \"False\"]\n            by (auto simp add: Let_def)\n        qed\n        moreover\n        have \"InvariantUniqQ (getQ ?state')\"\n          using assms\n          using InvariantUniqQAfterAssertLiteral[of \"state\" \"hd ?clause'\" \"False\"]\n          by (simp add: Let_def)\n        moreover\n        have \"currentLevel (getM ?state') = 0\"\n          using assms\n          using \\<open>\\<not> clauseTrue ?clause' (elements (getM state))\\<close>\n          using \\<open>\\<not> ?clause' = []\\<close>\n          using assertLiteralEffect[of \"state\" \"hd ?clause'\" \"False\"]\n          unfolding addClause_def\n          unfolding currentLevel_def\n          by (simp add:Let_def markedElementsAppend)\n        moreover\n        hence \"InvariantGetReasonIsReason (getReason ?state') (getF ?state') (getM ?state') (set (getQ ?state'))\"\n          unfolding InvariantGetReasonIsReason_def\n          using elementLevelLeqCurrentLevel[of _ \"getM ?state'\"]\n          by auto\n        moreover\n        have \"var (hd ?clause') \\<in> vars F0\"\n          using \\<open>?clause' \\<noteq> []\\<close>\n          using hd_in_set[of \"?clause'\"]\n          using \\<open>vars ?clause' \\<subseteq> vars F0\\<close>\n          using clauseContainsItsLiteralsVariable[of \"hd ?clause'\" \"?clause'\"]\n          by auto\n        hence \"InvariantVarsQ (getQ ?state') F0 Vbl\"\n          \"InvariantVarsM (getM ?state') F0 Vbl\"\n          \"InvariantVarsF (getF ?state') F0 Vbl\"\n          using \\<open>InvariantWatchListsContainOnlyClausesFromF (getWatchList state) (getF state)\\<close>\n          using \\<open>InvariantWatchesEl (getF state) (getWatch1 state) (getWatch2 state)\\<close>\n          using \\<open>InvariantWatchListsUniq (getWatchList state)\\<close>\n          using \\<open>InvariantWatchListsCharacterization (getWatchList state) (getWatch1 state) (getWatch2 state)\\<close>\n          using \\<open>InvariantWatchesDiffer (getF state) (getWatch1 state) (getWatch2 state)\\<close>\n          using \\<open>InvariantWatchCharacterization (getF state) (getWatch1 state) (getWatch2 state) (getM state)\\<close>\n          using \\<open>InvariantVarsF (getF state) F0 Vbl\\<close>\n          using \\<open>InvariantVarsM (getM state) F0 Vbl\\<close>\n          using \\<open>InvariantVarsQ (getQ state) F0 Vbl\\<close>\n          using \\<open>consistent (elements (getM ?state'))\\<close>\n          using \\<open>uniq (elements (getM ?state'))\\<close>\n          using assertLiteralEffect[of \"state\" \"hd ?clause'\" \"False\"]\n          using varsAppendValuation[of \"elements (getM state)\" \"[hd ?clause']\"]\n          using InvariantVarsQAfterAssertLiteral[of \"state\" \"hd ?clause'\" \"False\" \"F0\" \"Vbl\"]\n          unfolding InvariantVarsM_def\n          unfolding InvariantConsistent_def\n          unfolding InvariantUniq_def\n          by (auto simp add: Let_def)\n        moreover\n        have \"exhaustiveUnitPropagate_dom ?state'\"\n          using exhaustiveUnitPropagateTermination[of \"?state'\" \"F0\" \"Vbl\"]\n          using \\<open>InvariantUniqQ (getQ ?state')\\<close>\n          using \\<open>InvariantWatchListsContainOnlyClausesFromF (getWatchList ?state') (getF ?state')\\<close>\n          using \\<open>InvariantWatchListsUniq (getWatchList ?state')\\<close>\n          using \\<open>InvariantWatchListsCharacterization (getWatchList ?state') (getWatch1 ?state') (getWatch2 ?state')\\<close>\n          using \\<open>InvariantWatchesEl (getF ?state') (getWatch1 ?state') (getWatch2 ?state')\\<close>\n          using \\<open>InvariantWatchesDiffer (getF ?state') (getWatch1 ?state') (getWatch2 ?state')\\<close>\n          using \\<open>InvariantQCharacterization (getConflictFlag ?state') (getQ ?state') (getF ?state') (getM ?state')\\<close>\n          using \\<open>InvariantWatchCharacterization (getF ?state') (getWatch1 ?state') (getWatch2 ?state') (getM ?state')\\<close>\n          using \\<open>InvariantConflictFlagCharacterization (getConflictFlag ?state') (getF ?state') (getM ?state')\\<close>\n          using \\<open>consistent (elements (getM ?state'))\\<close>\n          using \\<open>uniq (elements (getM ?state'))\\<close>\n          using \\<open>finite Vbl\\<close>\n          using \\<open>InvariantVarsQ (getQ ?state') F0 Vbl\\<close>\n          using \\<open>InvariantVarsM (getM ?state') F0 Vbl\\<close>\n          using \\<open>InvariantVarsF (getF ?state') F0 Vbl\\<close>\n          unfolding InvariantConsistent_def\n          unfolding InvariantUniq_def\n          by simp\n        ultimately\n        show ?thesis\n          using \\<open>exhaustiveUnitPropagate_dom ?state'\\<close>\n          using InvariantsAfterExhaustiveUnitPropagate[of \"?state'\"]\n          using InvariantConflictClauseCharacterizationAfterExhaustivePropagate[of \"?state'\"]\n          using conflictFlagOrQEmptyAfterExhaustiveUnitPropagate[of \"?state'\"]\n          using exhaustiveUnitPropagatePreservesCurrentLevel[of \"?state'\"]\n          using InvariantGetReasonIsReasonAfterExhaustiveUnitPropagate[of \"?state'\"]\n          using assms\n          using assertLiteralEffect[of \"state\" \"hd ?clause'\" \"False\"]\n          unfolding InvariantConsistent_def\n          unfolding InvariantUniq_def\n          by (auto simp only:Let_def)\n      next\n        case False\n        thus ?thesis\n        proof (cases \"clauseTautology ?clause'\")\n          case True\n          thus ?thesis\n            using assms\n            using \\<open>\\<not> ?clause' = []\\<close>\n            using \\<open>\\<not> clauseTrue ?clause' (elements (getM state))\\<close>\n            using \\<open>length ?clause' \\<noteq> 1\\<close>\n            unfolding addClause_def\n            by simp\n        next\n          case False\n          from \\<open>\\<not> ?clause' = []\\<close> \\<open>length ?clause' \\<noteq> 1\\<close>\n          have \"length ?clause' > 1\"\n            by (induct (?clause')) auto\n\n          hence \"nth ?clause' 0 \\<noteq> nth ?clause' 1\"\n            using distinct_remdups[of \"?clause'\"]\n            using nth_eq_iff_index_eq[of \"?clause'\" \"0\" \"1\"]\n            using \\<open>\\<not> ?clause' = []\\<close>\n            by auto\n\n          let ?state' = \"let clauseIndex = length (getF state) in\n                         let state'   = state\\<lparr> getF := (getF state) @ [?clause']\\<rparr> in\n                         let state''  = setWatch1 clauseIndex (nth ?clause' 0) state' in\n                         let state''' = setWatch2 clauseIndex (nth ?clause' 1) state'' in\n                         state'''\"\n\n          have \"InvariantWatchesEl (getF ?state') (getWatch1 ?state') (getWatch2 ?state')\"\n            using \\<open>InvariantWatchesEl (getF state) (getWatch1 state) (getWatch2 state)\\<close>\n            using \\<open>length ?clause' > 1\\<close>\n            using \\<open>?clause' \\<noteq> []\\<close>\n            using nth_mem[of \"0\" \"?clause'\"]\n            using nth_mem[of \"1\" \"?clause'\"]\n            unfolding InvariantWatchesEl_def\n            unfolding setWatch1_def\n            unfolding setWatch2_def\n            by (auto simp add: Let_def nth_append)\n          moreover\n          have \"InvariantWatchesDiffer (getF ?state') (getWatch1 ?state') (getWatch2 ?state')\"\n            using \\<open>InvariantWatchesDiffer (getF state) (getWatch1 state) (getWatch2 state)\\<close>\n            using \\<open>nth ?clause' 0 \\<noteq> nth ?clause' 1\\<close>\n            unfolding InvariantWatchesDiffer_def\n            unfolding setWatch1_def\n            unfolding setWatch2_def\n            by (auto simp add: Let_def)\n          moreover\n          have \"InvariantWatchListsContainOnlyClausesFromF (getWatchList ?state') (getF ?state')\"\n            using \\<open>InvariantWatchListsContainOnlyClausesFromF (getWatchList state) (getF state)\\<close>\n            unfolding InvariantWatchListsContainOnlyClausesFromF_def\n            unfolding setWatch1_def\n            unfolding setWatch2_def\n            by (auto simp add:Let_def) (force)+\n          moreover\n          have \"InvariantWatchListsCharacterization (getWatchList ?state') (getWatch1 ?state') (getWatch2 ?state')\"\n            using \\<open>InvariantWatchListsCharacterization (getWatchList state) (getWatch1 state) (getWatch2 state)\\<close>\n            using \\<open>InvariantWatchListsContainOnlyClausesFromF (getWatchList state) (getF state)\\<close>\n            using \\<open>nth ?clause' 0 \\<noteq> nth ?clause' 1\\<close>\n            unfolding InvariantWatchListsCharacterization_def\n            unfolding InvariantWatchListsContainOnlyClausesFromF_def\n            unfolding setWatch1_def\n            unfolding setWatch2_def\n            by (auto simp add:Let_def)\n          moreover\n          have \"InvariantWatchCharacterization (getF ?state') (getWatch1 ?state') (getWatch2 ?state') (getM ?state')\"\n          proof-\n            {\n              fix c\n              assume \"0 \\<le> c \\<and> c < length (getF ?state')\"\n              fix www1 www2\n              assume \"Some www1 = (getWatch1 ?state' c)\" \"Some www2 = (getWatch2 ?state' c)\"\n              have \"watchCharacterizationCondition www1 www2 (getM ?state') (nth (getF ?state') c) \\<and> \n                    watchCharacterizationCondition www2 www1 (getM ?state') (nth (getF ?state') c)\"\n              proof (cases \"c < length (getF state)\")\n                case True\n                hence \"(nth (getF ?state') c) = (nth (getF state) c)\"\n                  unfolding setWatch1_def\n                  unfolding setWatch2_def\n                  by (auto simp add: Let_def nth_append)\n                have \"Some www1 = (getWatch1 state c)\" \"Some www2 = (getWatch2 state c)\"\n                  using True\n                  using \\<open>Some www1 = (getWatch1 ?state' c)\\<close> \\<open>Some www2 = (getWatch2 ?state' c)\\<close>\n                  unfolding setWatch1_def\n                  unfolding setWatch2_def\n                  by (auto simp add: Let_def)\n                thus ?thesis\n                  using \\<open>InvariantWatchCharacterization (getF state) (getWatch1 state) (getWatch2 state) (getM state)\\<close>\n                  unfolding InvariantWatchCharacterization_def\n                  using \\<open>(nth (getF ?state') c) = (nth (getF state) c)\\<close>\n                  using True\n                  unfolding setWatch1_def\n                  unfolding setWatch2_def\n                  by (auto simp add: Let_def)\n              next\n                case False\n                with \\<open>0 \\<le> c \\<and> c < length (getF ?state')\\<close>\n                have \"c = length (getF state)\"\n                  unfolding setWatch1_def\n                  unfolding setWatch2_def\n                  by (auto simp add: Let_def)\n                from \\<open>InvariantWatchesEl (getF ?state') (getWatch1 ?state') (getWatch2 ?state')\\<close>\n                obtain w1 w2 \n                  where \n                  \"w1 el ?clause'\" \"w2 el ?clause'\"\n                  \"getWatch1 ?state' (length (getF state)) = Some w1\"\n                  \"getWatch2 ?state' (length (getF state)) = Some w2\"\n                  unfolding InvariantWatchesEl_def\n                  unfolding setWatch2_def\n                  unfolding setWatch1_def\n                  by (auto simp add: Let_def)\n                hence \"w1 = www1\" and \"w2 = www2\"\n                  using \\<open>Some www1 = (getWatch1 ?state' c)\\<close> \\<open>Some www2 = (getWatch2 ?state' c)\\<close>\n                  using \\<open>c = length (getF state)\\<close>\n                  by auto\n                have \"\\<not> literalFalse  w1 (elements (getM ?state'))\" \n                  \"\\<not> literalFalse w2 (elements (getM ?state'))\"\n                  using \\<open>w1 el ?clause'\\<close> \\<open>w2 el ?clause'\\<close>\n                  using *\n                  unfolding setWatch2_def\n                  unfolding setWatch1_def\n                  by (auto simp add: Let_def)\n                thus ?thesis\n                  using \\<open>w1 = www1\\<close> \\<open>w2 = www2\\<close>\n                  unfolding watchCharacterizationCondition_def\n                  unfolding setWatch2_def\n                  unfolding setWatch1_def\n                  by (auto simp add: Let_def)\n              qed\n            } thus ?thesis\n              unfolding InvariantWatchCharacterization_def\n              by auto\n          qed\n          moreover \n          have \"\\<forall> l. length (getF state) \\<notin> set (getWatchList state l)\"\n            using \\<open>InvariantWatchListsContainOnlyClausesFromF (getWatchList state) (getF state)\\<close>            \n            unfolding InvariantWatchListsContainOnlyClausesFromF_def\n            by auto\n          hence \"InvariantWatchListsUniq (getWatchList ?state')\"\n            using \\<open>InvariantWatchListsUniq (getWatchList state)\\<close>\n            using \\<open>nth ?clause' 0 \\<noteq> nth ?clause' 1\\<close>\n            unfolding InvariantWatchListsUniq_def\n            unfolding setWatch1_def\n            unfolding setWatch2_def\n            by (auto simp add:Let_def uniqAppendIff)\n          moreover\n          from * \n          have \"\\<not> clauseFalse ?clause' (elements (getM state))\"\n            using \\<open>?clause' \\<noteq> []\\<close>\n            by (auto simp add: clauseFalseIffAllLiteralsAreFalse)\n          hence \"InvariantConflictFlagCharacterization (getConflictFlag ?state') (getF ?state') (getM ?state')\"\n            using \\<open>InvariantConflictFlagCharacterization (getConflictFlag state) (getF state) (getM state)\\<close>\n            unfolding InvariantConflictFlagCharacterization_def\n            unfolding setWatch1_def\n            unfolding setWatch2_def\n            by (auto simp add: Let_def formulaFalseIffContainsFalseClause)\n          moreover\n          have \"\\<not> (\\<exists> l. isUnitClause ?clause' l (elements (getM state)))\"\n          proof-\n            {\n              assume \"\\<not> ?thesis\"\n              then obtain l\n                where \"isUnitClause ?clause' l (elements (getM state))\"\n                by auto\n              hence \"l el ?clause'\"\n                unfolding isUnitClause_def\n                by simp\n              have \"\\<exists> l'. l' el ?clause' \\<and> l \\<noteq> l'\"\n              proof-\n                from \\<open>length ?clause' > 1\\<close>\n                obtain a1::Literal and a2::Literal\n                  where \"a1 el ?clause'\" \"a2 el ?clause'\" \"a1 \\<noteq> a2\"\n                  using lengthGtOneTwoDistinctElements[of \"?clause'\"]\n                  by (auto simp add: uniqDistinct) (force)\n                thus ?thesis\n                proof (cases \"a1 = l\")\n                  case True\n                  thus ?thesis\n                    using \\<open>a1 \\<noteq> a2\\<close> \\<open>a2 el ?clause'\\<close>\n                    by auto\n                next\n                  case False\n                  thus ?thesis\n                    using \\<open>a1 el ?clause'\\<close>\n                    by auto\n                qed\n              qed\n              then obtain l'::Literal\n                where \"l \\<noteq> l'\" \"l' el ?clause'\"\n                by auto\n              with * \n              have \"\\<not> literalFalse l' (elements (getM state))\"\n                by simp\n              hence \"False\"\n                using \\<open>isUnitClause ?clause' l (elements (getM state))\\<close>\n                using \\<open>l \\<noteq> l'\\<close> \\<open>l' el ?clause'\\<close>\n                unfolding isUnitClause_def\n                by auto\n            } thus ?thesis\n              by auto\n          qed\n          hence \"InvariantQCharacterization (getConflictFlag ?state') (getQ ?state') (getF ?state') (getM ?state')\"\n            using assms\n            unfolding InvariantQCharacterization_def\n            unfolding setWatch2_def\n            unfolding setWatch1_def\n            by (auto simp add: Let_def)\n          moreover\n          have \"InvariantConflictClauseCharacterization (getConflictFlag state) (getConflictClause state) (getF state @ [?clause']) (getM state)\"\n          proof (cases \"getConflictFlag state\")\n            case False\n            thus ?thesis\n              unfolding InvariantConflictClauseCharacterization_def\n              by simp\n          next\n            case True\n            hence \"getConflictClause state < length (getF state)\"\n              using \\<open>InvariantConflictClauseCharacterization (getConflictFlag state) (getConflictClause state) (getF state) (getM state)\\<close>\n              unfolding InvariantConflictClauseCharacterization_def\n              by (auto simp add: Let_def)\n            hence \"nth ((getF state) @ [?clause']) (getConflictClause state) = \n                   nth (getF state) (getConflictClause state)\"\n              by (simp add: nth_append)\n            thus ?thesis\n              using \\<open>InvariantConflictClauseCharacterization (getConflictFlag state) (getConflictClause state) (getF state) (getM state)\\<close>\n              unfolding InvariantConflictClauseCharacterization_def\n              by (auto simp add: Let_def clauseFalseAppendValuation)\n          qed\n          moreover\n          have \"InvariantGetReasonIsReason (getReason ?state') (getF ?state') (getM ?state') (set (getQ ?state'))\"\n            using \\<open>currentLevel (getM state) = 0\\<close>\n            using elementLevelLeqCurrentLevel[of _ \"getM state\"]\n            unfolding setWatch1_def\n            unfolding setWatch2_def\n            unfolding InvariantGetReasonIsReason_def\n            by (simp add: Let_def)\n          moreover\n          have \"InvariantVarsF (getF ?state') F0 Vbl\"\n            using \\<open>InvariantVarsF (getF state) F0 Vbl\\<close>\n            using \\<open>vars ?clause' \\<subseteq> vars F0\\<close>\n            using varsAppendFormulae[of \"getF state\" \"[?clause']\"]\n            unfolding setWatch2_def\n            unfolding setWatch1_def\n            unfolding InvariantVarsF_def\n            by (auto simp add: Let_def)\n          ultimately\n          show ?thesis\n            using assms\n            using \\<open>length ?clause' > 1\\<close>\n            using \\<open>\\<not> ?clause' = []\\<close>\n            using \\<open>\\<not> clauseTrue ?clause' (elements (getM state))\\<close>\n            using \\<open>length ?clause' \\<noteq> 1\\<close>\n            using \\<open>\\<not> clauseTautology ?clause'\\<close>\n            unfolding addClause_def\n            unfolding setWatch1_def\n            unfolding setWatch2_def\n            by (auto simp add: Let_def)\n        qed\n      qed\n    qed\n  qed\nqed\n\n\nlemma InvariantEquivalentZLAfterAddClause:\nfixes Phi :: Formula and clause :: Clause and state :: State and Vbl :: \"Variable set\"\nassumes \n*:\"(getSATFlag state = UNDEF \\<and> InvariantEquivalentZL (getF state) (getM state) Phi) \\<or> \n   (getSATFlag state = FALSE \\<and> \\<not> satisfiable Phi)\"\n  \"InvariantConsistent (getM state)\"\n  \"InvariantUniq (getM state)\"\n  \"InvariantWatchListsContainOnlyClausesFromF (getWatchList state) (getF state)\" and\n  \"InvariantWatchListsUniq (getWatchList state)\" and\n  \"InvariantWatchListsCharacterization (getWatchList state) (getWatch1 state) (getWatch2 state)\"\n  \"InvariantWatchesEl (getF state) (getWatch1 state) (getWatch2 state)\" and\n  \"InvariantWatchesDiffer (getF state) (getWatch1 state) (getWatch2 state)\" and\n  \"InvariantWatchCharacterization (getF state) (getWatch1 state) (getWatch2 state) (getM state)\"\n  \"InvariantConflictFlagCharacterization (getConflictFlag state) (getF state) (getM state)\"\n  \"InvariantQCharacterization (getConflictFlag state) (getQ state) (getF state) (getM state)\"\n  \"InvariantUniqQ (getQ state)\"\n  \"(getConflictFlag state) \\<or> (getQ state) = []\"\n  \"currentLevel (getM state) = 0\"\n  \"InvariantVarsM (getM state) F0 Vbl\"\n  \"InvariantVarsQ (getQ state) F0 Vbl\"\n  \"InvariantVarsF (getF state) F0 Vbl\"\n  \"finite Vbl\"\n  \"vars clause \\<subseteq> vars F0\"\nshows\n\"let state' = addClause clause state in\n let Phi' = Phi @ [clause] in\n let Phi'' = (if (clauseTautology clause) then Phi else Phi') in\n (getSATFlag state' = UNDEF \\<and> InvariantEquivalentZL (getF state') (getM state') Phi'') \\<or> \n (getSATFlag state' = FALSE \\<and> \\<not>satisfiable Phi'')\"\nproof-\n  let ?clause' = \"remdups (removeFalseLiterals clause (elements (getM state)))\"\n\n  from \\<open>currentLevel (getM state) = 0\\<close> \n  have \"getM state = prefixToLevel 0 (getM state)\"\n    by (rule currentLevelZeroTrailEqualsItsPrefixToLevelZero)\n\n  have **: \"\\<forall> l. l el ?clause' \\<longrightarrow> \\<not> literalFalse l (elements (getM state))\"\n    unfolding removeFalseLiterals_def\n    by auto\n\n  have \"vars ?clause' \\<subseteq> vars clause\"\n    using varsSubsetValuation[of \"?clause'\" \"clause\"]\n    unfolding removeFalseLiterals_def\n    by auto\n  hence \"vars ?clause' \\<subseteq> vars F0\"\n    using \\<open>vars clause \\<subseteq> vars F0\\<close>\n    by simp\n\n  show ?thesis\n  proof (cases \"clauseTrue ?clause' (elements (getM state))\")\n    case True\n    show ?thesis\n    proof-\n      from True \n      have \"clauseTrue clause (elements (getM state))\"\n        using clauseTrueRemoveDuplicateLiterals\n        [of \"removeFalseLiterals clause (elements (getM state))\" \"elements (getM state)\"]\n        using clauseTrueRemoveFalseLiterals\n        [of \"elements (getM state)\" \"clause\"]\n        using \\<open>InvariantConsistent (getM state)\\<close>\n        unfolding InvariantConsistent_def\n        by simp\n      show ?thesis\n      proof (cases \"getSATFlag state = UNDEF\")\n        case True\n        thus ?thesis\n          using *\n          using \\<open>clauseTrue clause (elements (getM state))\\<close>\n          using \\<open>getM state = prefixToLevel 0 (getM state)\\<close>\n          using satisfiedClauseCanBeRemoved\n          [of \"getF state\" \"(elements (prefixToLevel 0 (getM state)))\" \"Phi\" \"clause\"]\n          using \\<open>clauseTrue ?clause' (elements (getM state))\\<close>\n          unfolding addClause_def\n          unfolding InvariantEquivalentZL_def\n          by auto\n      next\n        case False\n        thus ?thesis\n          using *\n          using \\<open>clauseTrue ?clause' (elements (getM state))\\<close>\n          using satisfiableAppend[of \"Phi\" \"[clause]\"]\n          unfolding addClause_def\n          by force\n      qed\n    qed\n  next\n    case False\n    show ?thesis\n    proof (cases \"?clause' = []\")\n      case True\n      show ?thesis\n      proof (cases \"getSATFlag state = UNDEF\")\n        case True\n        thus ?thesis\n          using *\n          using falseAndDuplicateLiteralsCanBeRemoved\n          [of \"getF state\" \"(elements (prefixToLevel 0 (getM state)))\" \"[]\" \"Phi\" \"clause\"]\n          using \\<open>getM state = prefixToLevel 0 (getM state)\\<close>\n          using formulaWithEmptyClauseIsUnsatisfiable[of \"(getF state @ val2form (elements (getM state)) @ [[]])\"]\n          using satisfiableEquivalent\n          using \\<open>?clause' = []\\<close>\n          unfolding addClause_def\n          unfolding InvariantEquivalentZL_def\n          using satisfiableAppendTautology\n          by auto\n      next\n        case False\n        thus ?thesis\n          using \\<open>?clause' = []\\<close>\n          using *\n          using satisfiableAppend[of \"Phi\" \"[clause]\"]\n          unfolding addClause_def\n          by force\n      qed\n    next\n      case False\n      thus ?thesis\n      proof (cases \"length ?clause' = 1\")\n        case True\n        from \\<open>length ?clause' = 1\\<close>\n        have \"[hd ?clause'] = ?clause'\"\n          using lengthOneCharacterisation[of \"?clause'\"]\n          by simp\n\n        with \\<open>length ?clause' = 1\\<close>\n        have \"val2form (elements (getM state)) @ [?clause'] = val2form ((elements (getM state)) @ ?clause')\"\n          using val2formAppend[of \"elements (getM state)\" \"?clause'\"]\n          using val2formOfSingleLiteralValuation[of \"?clause'\"]\n          by auto\n\n        let ?state' = \"assertLiteral (hd ?clause') False state\"\n        have \"addClause clause state = exhaustiveUnitPropagate ?state'\"\n          using \\<open>\\<not> clauseTrue ?clause' (elements (getM state))\\<close>\n          using \\<open>\\<not> ?clause' = []\\<close>\n          using \\<open>length ?clause' = 1\\<close>\n          unfolding addClause_def\n          by (simp add: Let_def)\n        moreover\n        from \\<open>?clause' \\<noteq> []\\<close>\n        have \"hd ?clause' \\<in> set ?clause'\"\n          using hd_in_set[of \"?clause'\"]\n          by simp\n        with **\n        have \"\\<not> literalFalse (hd ?clause') (elements (getM state))\"\n          by simp\n        hence \"consistent (elements ((getM state) @ [(hd ?clause', False)]))\"\n          using assms\n          unfolding InvariantConsistent_def\n          using consistentAppendElement[of \"elements (getM state)\" \"hd ?clause'\"]\n          by simp\n        hence \"consistent (elements (getM ?state'))\"\n          using assms\n          using assertLiteralEffect[of \"state\" \"hd ?clause'\" \"False\"]\n          by simp\n        moreover\n        from \\<open>\\<not> clauseTrue ?clause' (elements (getM state))\\<close>\n        have \"uniq (elements (getM ?state'))\"\n          using assms\n          using assertLiteralEffect[of \"state\" \"hd ?clause'\" \"False\"]\n          using \\<open>hd ?clause' \\<in> set ?clause'\\<close>\n          unfolding InvariantUniq_def\n          by (simp add: uniqAppendIff clauseTrueIffContainsTrueLiteral)\n        moreover\n        have \"InvariantWatchListsContainOnlyClausesFromF (getWatchList ?state') (getF ?state')\" and\n          \"InvariantWatchListsUniq (getWatchList ?state')\" and\n          \"InvariantWatchListsCharacterization (getWatchList ?state') (getWatch1 ?state') (getWatch2 ?state')\"\n          \"InvariantWatchesEl (getF ?state') (getWatch1 ?state') (getWatch2 ?state')\" and\n          \"InvariantWatchesDiffer (getF ?state') (getWatch1 ?state') (getWatch2 ?state')\"\n          using assms\n          using WatchInvariantsAfterAssertLiteral[of \"state\" \"hd ?clause'\" \"False\"]\n          by (auto simp add: Let_def)\n        moreover\n        have \"InvariantWatchCharacterization (getF ?state') (getWatch1 ?state') (getWatch2 ?state') (getM ?state')\"\n          using assms\n          using InvariantWatchCharacterizationAfterAssertLiteral[of \"state\" \"hd ?clause'\" \"False\"]\n          using \\<open>uniq (elements (getM ?state'))\\<close>\n          using \\<open>consistent (elements (getM ?state'))\\<close>\n          unfolding InvariantConsistent_def\n          unfolding InvariantUniq_def\n          using assertLiteralEffect[of \"state\" \"hd ?clause'\" \"False\"]\n          by (simp add: Let_def)\n        moreover\n        have \"InvariantConflictFlagCharacterization (getConflictFlag ?state') (getF ?state') (getM ?state')\"\n          using assms\n          using InvariantConflictFlagCharacterizationAfterAssertLiteral[of \"state\" \"hd ?clause'\" \"False\"]\n          using \\<open>consistent (elements (getM ?state'))\\<close>\n          unfolding InvariantConsistent_def\n          using assertLiteralEffect[of \"state\" \"hd ?clause'\" \"False\"]\n          by (simp add: Let_def)\n        moreover\n        have \"InvariantQCharacterization (getConflictFlag ?state') (getQ ?state') (getF ?state') (getM ?state')\"\n        proof (cases \"getConflictFlag state\")\n          case True\n          hence \"getConflictFlag ?state'\"\n            using assms\n            using assertLiteralConflictFlagEffect[of \"state\" \"hd ?clause'\" \"False\"]\n            using \\<open>uniq (elements (getM ?state'))\\<close>\n            using \\<open>consistent (elements (getM ?state'))\\<close>\n            unfolding InvariantConsistent_def\n            unfolding InvariantUniq_def\n            using assertLiteralEffect[of \"state\" \"hd ?clause'\" \"False\"]\n            by (auto simp add: Let_def)\n          thus ?thesis\n            using assms\n            unfolding InvariantQCharacterization_def\n            by simp\n        next\n          case False\n          with \\<open>(getConflictFlag state) \\<or> (getQ state) = []\\<close>\n          have \"getQ state = []\"\n            by simp\n          thus ?thesis\n            using InvariantQCharacterizationAfterAssertLiteralNotInQ[of \"state\" \"hd ?clause'\" \"False\"]\n            using assms\n            using \\<open>uniq (elements (getM ?state'))\\<close>\n            using \\<open>consistent (elements (getM ?state'))\\<close>\n            unfolding InvariantConsistent_def\n            unfolding InvariantUniq_def\n            using assertLiteralEffect[of \"state\" \"hd ?clause'\" \"False\"]\n            by (auto simp add: Let_def)\n        qed\n        moreover\n        have\"InvariantUniqQ (getQ ?state')\"\n          using assms\n          using InvariantUniqQAfterAssertLiteral[of \"state\" \"hd ?clause'\" \"False\"]\n          by (simp add: Let_def)\n        moreover\n        have \"currentLevel (getM ?state') = 0\"\n          using assms\n          using \\<open>\\<not> clauseTrue ?clause' (elements (getM state))\\<close>\n          using \\<open>\\<not> ?clause' = []\\<close>\n          using assertLiteralEffect[of \"state\" \"hd ?clause'\" \"False\"]\n          unfolding addClause_def\n          unfolding currentLevel_def\n          by (simp add:Let_def markedElementsAppend)\n        moreover\n        have \"var (hd ?clause') \\<in> vars F0\"\n          using \\<open>?clause' \\<noteq> []\\<close>\n          using hd_in_set[of \"?clause'\"]\n          using \\<open>vars ?clause' \\<subseteq> vars F0\\<close>\n          using clauseContainsItsLiteralsVariable[of \"hd ?clause'\" \"?clause'\"]\n          by auto\n        hence \"InvariantVarsM (getM ?state') F0 Vbl\"\n          \"InvariantVarsQ (getQ ?state') F0 Vbl\"\n          \"InvariantVarsF (getF ?state') F0 Vbl\"\n          using \\<open>InvariantWatchListsContainOnlyClausesFromF (getWatchList state) (getF state)\\<close>\n          using \\<open>InvariantWatchesEl (getF state) (getWatch1 state) (getWatch2 state)\\<close>\n          using \\<open>InvariantWatchListsUniq (getWatchList state)\\<close>\n          using \\<open>InvariantWatchListsCharacterization (getWatchList state) (getWatch1 state) (getWatch2 state)\\<close>\n          using \\<open>InvariantWatchesDiffer (getF state) (getWatch1 state) (getWatch2 state)\\<close>\n          using \\<open>InvariantWatchCharacterization (getF state) (getWatch1 state) (getWatch2 state) (getM state)\\<close>\n          using \\<open>InvariantVarsF (getF state) F0 Vbl\\<close>\n          using \\<open>InvariantVarsM (getM state) F0 Vbl\\<close>\n          using \\<open>InvariantVarsQ (getQ state) F0 Vbl\\<close>\n          using \\<open>consistent (elements (getM ?state'))\\<close>\n          using \\<open>uniq (elements (getM ?state'))\\<close>\n          using assertLiteralEffect[of \"state\" \"hd ?clause'\" \"False\"]\n          using varsAppendValuation[of \"elements (getM state)\" \"[hd ?clause']\"]\n          using InvariantVarsQAfterAssertLiteral[of \"state\" \"hd ?clause'\" \"False\" \"F0\" \"Vbl\"]\n          unfolding InvariantVarsM_def\n          unfolding InvariantConsistent_def\n          unfolding InvariantUniq_def\n          by (auto simp add: Let_def)\n        moreover\n        have \"exhaustiveUnitPropagate_dom ?state'\"\n          using exhaustiveUnitPropagateTermination[of \"?state'\" \"F0\" \"Vbl\"]\n          using \\<open>InvariantUniqQ (getQ ?state')\\<close>\n          using \\<open>InvariantWatchListsContainOnlyClausesFromF (getWatchList ?state') (getF ?state')\\<close>\n          using \\<open>InvariantWatchListsUniq (getWatchList ?state')\\<close>\n          using \\<open>InvariantWatchListsCharacterization (getWatchList ?state') (getWatch1 ?state') (getWatch2 ?state')\\<close>\n          using \\<open>InvariantWatchesEl (getF ?state') (getWatch1 ?state') (getWatch2 ?state')\\<close>\n          using \\<open>InvariantWatchesDiffer (getF ?state') (getWatch1 ?state') (getWatch2 ?state')\\<close>\n          using \\<open>InvariantQCharacterization (getConflictFlag ?state') (getQ ?state') (getF ?state') (getM ?state')\\<close>\n          using \\<open>InvariantWatchCharacterization (getF ?state') (getWatch1 ?state') (getWatch2 ?state') (getM ?state')\\<close>\n          using \\<open>InvariantConflictFlagCharacterization (getConflictFlag ?state') (getF ?state') (getM ?state')\\<close>\n          using \\<open>consistent (elements (getM ?state'))\\<close>\n          using \\<open>uniq (elements (getM ?state'))\\<close>\n          using \\<open>finite Vbl\\<close>\n          using \\<open>InvariantVarsM (getM ?state') F0 Vbl\\<close>\n          using \\<open>InvariantVarsQ (getQ ?state') F0 Vbl\\<close>\n          using \\<open>InvariantVarsF (getF ?state') F0 Vbl\\<close>\n          unfolding InvariantConsistent_def\n          unfolding InvariantUniq_def\n          by simp\n        moreover\n        have \"\\<not> clauseTautology clause\"\n        proof-\n          {\n            assume \"\\<not> ?thesis\"\n            then obtain l'\n              where \"l' el clause\" \"opposite l' el clause\"\n              by (auto simp add: clauseTautologyCharacterization)\n            have False\n            proof (cases \"l' el ?clause'\")\n              case True\n              have \"opposite l' el ?clause'\"\n              proof-\n                {\n                  assume \"\\<not> ?thesis\"\n                  hence \"literalFalse l' (elements (getM state))\"\n                    using \\<open>l' el clause\\<close>\n                    using \\<open>opposite l' el clause\\<close>\n                    using \\<open>\\<not> clauseTrue ?clause' (elements (getM state))\\<close>\n                    using clauseTrueIffContainsTrueLiteral[of \"?clause'\" \"elements (getM state)\"]\n                    unfolding removeFalseLiterals_def\n                    by auto\n                  hence False\n                    using \\<open>l' el ?clause'\\<close>\n                    unfolding removeFalseLiterals_def\n                    by auto\n                } thus ?thesis\n                  by auto\n              qed\n              have \"\\<forall> x. x el ?clause' \\<longrightarrow> x = l'\"\n                using \\<open>l' el ?clause'\\<close>\n                using \\<open>length ?clause' = 1\\<close>\n                using lengthOneImpliesOnlyElement[of \"?clause'\" \"l'\"]\n                by simp\n              thus ?thesis\n                using \\<open>opposite l' el ?clause'\\<close>\n                by auto\n            next\n              case False\n              hence \"literalFalse l' (elements (getM state))\"\n                using \\<open>l' el clause\\<close>\n                unfolding removeFalseLiterals_def\n                by simp\n              hence \"\\<not> literalFalse (opposite l') (elements (getM state))\"\n                using \\<open>InvariantConsistent (getM state)\\<close>\n                unfolding InvariantConsistent_def\n                by (auto simp add: inconsistentCharacterization)\n              hence \"opposite l' el ?clause'\"\n                using \\<open>opposite l' el clause\\<close>\n                unfolding removeFalseLiterals_def\n                by auto\n              thus ?thesis\n                using \\<open>literalFalse l' (elements (getM state))\\<close>\n                using \\<open>\\<not> clauseTrue ?clause' (elements (getM state))\\<close>\n                by (simp add: clauseTrueIffContainsTrueLiteral)\n            qed\n          } thus ?thesis\n            by auto\n        qed\n        moreover\n        note clc = calculation\n\n        show ?thesis\n        proof (cases \"getSATFlag state = UNDEF\")\n          case True\n          hence \"InvariantEquivalentZL (getF state) (getM state) Phi\"\n            using assms\n            by simp\n          hence \"InvariantEquivalentZL (getF ?state') (getM ?state') (Phi @ [clause])\"\n            using *\n            using falseAndDuplicateLiteralsCanBeRemoved\n            [of \"getF state\" \"(elements (prefixToLevel 0 (getM state)))\" \"[]\" \"Phi\" \"clause\"]\n            using \\<open>[hd ?clause'] = ?clause'\\<close>\n            using \\<open>getM state = prefixToLevel 0 (getM state)\\<close>\n            using \\<open>currentLevel (getM state) = 0\\<close>\n            using prefixToLevelAppend[of \"0\" \"getM state\" \"[(hd ?clause', False)]\"]\n            using \\<open>InvariantWatchesEl (getF state) (getWatch1 state) (getWatch2 state)\\<close>\n            using \\<open>InvariantWatchListsContainOnlyClausesFromF (getWatchList state) (getF state)\\<close>\n            using assertLiteralEffect[of \"state\" \"hd ?clause'\" \"False\"]\n            using \\<open>val2form (elements (getM state)) @ [?clause'] = val2form ((elements (getM state)) @ ?clause')\\<close>\n            using \\<open>\\<not> ?clause' = []\\<close>\n            using \\<open>\\<not> clauseTrue ?clause' (elements (getM state))\\<close>\n            using \\<open>length ?clause' = 1\\<close>\n            using \\<open>getSATFlag state = UNDEF\\<close>\n            unfolding addClause_def\n            unfolding InvariantEquivalentZL_def\n            by (simp add: Let_def)\n          hence \"let state'' = addClause clause state in\n            InvariantEquivalentZL (getF state'') (getM state'') (Phi @ [clause]) \\<and> \n            getSATFlag state'' = getSATFlag state\"\n            using clc\n            using InvariantEquivalentZLAfterExhaustiveUnitPropagate[of \"?state'\" \"Phi @ [clause]\"]\n            using exhaustiveUnitPropagatePreservedVariables[of \"?state'\"]\n            using assms\n            unfolding InvariantConsistent_def\n            unfolding InvariantUniq_def\n            using assertLiteralEffect[of \"state\" \"hd ?clause'\" \"False\"]\n            by (auto simp only: Let_def)\n          thus ?thesis\n            using True\n            using \\<open>\\<not> clauseTautology clause\\<close>\n            by (auto simp only: Let_def split: if_split) \n        next\n          case False\n          hence \"getSATFlag state = FALSE\" \"\\<not> satisfiable Phi\"\n            using *\n            by auto\n          hence \"getSATFlag ?state' = FALSE\"\n            using assertLiteralEffect[of \"state\" \"hd ?clause'\" \"False\"]\n            using assms\n            by simp\n          hence \"getSATFlag (exhaustiveUnitPropagate ?state') = FALSE\" \n            using clc\n            using exhaustiveUnitPropagatePreservedVariables[of \"?state'\"]\n            by (auto simp only: Let_def)\n          moreover\n          have \"\\<not> satisfiable (Phi @ [clause])\"\n            using satisfiableAppend[of \"Phi\" \"[clause]\"]\n            using \\<open>\\<not> satisfiable Phi\\<close>\n            by auto\n          ultimately\n          show ?thesis\n            using clc\n            using \\<open>\\<not> clauseTautology clause\\<close>\n            by (simp only: Let_def) simp\n        qed\n      next\n        case False\n        thus ?thesis\n        proof (cases \"clauseTautology ?clause'\")\n          case True\n          moreover\n          hence \"clauseTautology clause\"\n            unfolding removeFalseLiterals_def\n            by (auto simp add: clauseTautologyCharacterization)\n          ultimately\n          show ?thesis\n            using *\n            using \\<open>\\<not> ?clause' = []\\<close>\n            using \\<open>\\<not> clauseTrue ?clause' (elements (getM state))\\<close>\n            using \\<open>length ?clause' \\<noteq> 1\\<close>\n            using satisfiableAppend[of \"Phi\" \"[clause]\"]\n            unfolding addClause_def\n            (* Tautology problem *)\n            by (auto simp add: Let_def)\n        next\n          case False\n          have \"\\<not> clauseTautology clause\"\n          proof-\n            {\n              assume \"\\<not> ?thesis\"\n              then obtain l' \n                where \"l' el clause\" \"opposite l' el clause\"\n                by (auto simp add: clauseTautologyCharacterization)\n              have False\n              proof (cases \"l' el ?clause'\")\n                case True\n                hence \"\\<not> opposite l' el ?clause'\"\n                  using \\<open>\\<not> clauseTautology ?clause'\\<close>\n                  by (auto simp add: clauseTautologyCharacterization)\n                hence \"literalFalse (opposite l') (elements (getM state))\"\n                  using \\<open>opposite l' el clause\\<close>\n                  unfolding removeFalseLiterals_def\n                  by auto\n                thus ?thesis\n                  using \\<open>\\<not> clauseTrue ?clause' (elements (getM state))\\<close>\n                  using \\<open>l' el ?clause'\\<close>\n                  by (simp add: clauseTrueIffContainsTrueLiteral)\n              next\n                case False\n                hence \"literalFalse l' (elements (getM state))\"\n                  using \\<open>l' el clause\\<close>\n                  unfolding removeFalseLiterals_def\n                  by auto\n                hence \"\\<not> literalFalse (opposite l') (elements (getM state))\"\n                  using \\<open>InvariantConsistent (getM state)\\<close>\n                  unfolding InvariantConsistent_def\n                  by (auto simp add: inconsistentCharacterization)\n                hence \"opposite l' el ?clause'\"\n                  using \\<open>opposite l' el clause\\<close>\n                  unfolding removeFalseLiterals_def\n                  by auto\n                thus ?thesis\n                  using \\<open>\\<not> clauseTrue ?clause' (elements (getM state))\\<close>\n                  using \\<open>literalFalse l' (elements (getM state))\\<close>\n                  by (simp add: clauseTrueIffContainsTrueLiteral)\n              qed\n            } thus ?thesis\n              by auto\n          qed\n          show ?thesis\n          proof (cases \"getSATFlag state = UNDEF\")\n            case True\n            show ?thesis\n              using *\n              using falseAndDuplicateLiteralsCanBeRemoved\n              [of \"getF state\" \"(elements (prefixToLevel 0 (getM state)))\" \"[]\" \"Phi\" \"clause\"]\n              using \\<open>getM state = prefixToLevel 0 (getM state)\\<close>\n              using \\<open>\\<not> ?clause' = []\\<close>\n              using \\<open>\\<not> clauseTrue ?clause' (elements (getM state))\\<close>\n              using \\<open>length ?clause' \\<noteq> 1\\<close>\n              using \\<open>\\<not> clauseTautology ?clause'\\<close>\n              using \\<open>\\<not> clauseTautology clause\\<close>\n              using \\<open>getSATFlag state = UNDEF\\<close>\n              unfolding addClause_def\n              unfolding InvariantEquivalentZL_def\n              unfolding setWatch1_def\n              unfolding setWatch2_def\n              using clauseOrderIrrelevant[of \"getF state\" \"[?clause']\" \"val2form (elements (getM state))\" \"[]\"]\n              using equivalentFormulaeTransitivity[of \n                \"getF state @ remdups (removeFalseLiterals clause (elements (getM state))) # val2form (elements (getM state))\" \n                \"getF state @ val2form (elements (getM state)) @ [remdups (removeFalseLiterals clause (elements (getM state)))]\"\n                \"Phi @ [clause]\"]\n              by (auto simp add: Let_def)\n          next\n            case False\n            thus ?thesis\n              using *\n              using satisfiableAppend[of \"Phi\" \"[clause]\"]\n              using \\<open>\\<not> clauseTrue ?clause' (elements (getM state))\\<close>\n              using \\<open>length ?clause' \\<noteq> 1\\<close>\n              using \\<open>\\<not> clauseTautology ?clause'\\<close>\n              using \\<open>\\<not> clauseTautology clause\\<close>\n              unfolding addClause_def\n              unfolding setWatch1_def\n              unfolding setWatch2_def\n              by (auto simp add: Let_def)\n          qed\n        qed\n      qed\n    qed\n  qed\nqed\n\n(*********************************************************************************)\n(*    I N I T I A L I Z E                                                        *)\n(*********************************************************************************)\n\nlemma InvariantsAfterInitializationStep:\nfixes\n  state :: State and Phi :: Formula and Vbl::\"Variable set\"\nassumes\n  \"InvariantConsistent (getM state)\"\n  \"InvariantUniq (getM state)\"\n  \"InvariantWatchListsContainOnlyClausesFromF (getWatchList state) (getF state)\" and\n  \"InvariantWatchListsUniq (getWatchList state)\" and\n  \"InvariantWatchListsCharacterization (getWatchList state) (getWatch1 state) (getWatch2 state)\"\n  \"InvariantWatchesEl (getF state) (getWatch1 state) (getWatch2 state)\" and\n  \"InvariantWatchesDiffer (getF state) (getWatch1 state) (getWatch2 state)\" and\n  \"InvariantWatchCharacterization (getF state) (getWatch1 state) (getWatch2 state) (getM state)\"\n  \"InvariantConflictFlagCharacterization (getConflictFlag state) (getF state) (getM state)\"\n  \"InvariantConflictClauseCharacterization (getConflictFlag state) (getConflictClause state) (getF state) (getM state)\"\n  \"InvariantQCharacterization (getConflictFlag state) (getQ state) (getF state) (getM state)\"\n  \"InvariantGetReasonIsReason (getReason state) (getF state) (getM state) (set (getQ state))\"\n  \"InvariantUniqQ (getQ state)\"\n  \"(getConflictFlag state) \\<or> (getQ state) = []\"\n  \"currentLevel (getM state) = 0\"\n  \"finite Vbl\"\n  \"InvariantVarsM (getM state) F0 Vbl\"\n  \"InvariantVarsQ (getQ state) F0 Vbl\"\n  \"InvariantVarsF (getF state) F0 Vbl\"\n  \"state' = initialize Phi state\"\n  \"set Phi \\<subseteq> set F0\"\nshows\n  \"InvariantConsistent (getM state') \\<and> \n   InvariantUniq (getM state') \\<and> \n   InvariantWatchListsContainOnlyClausesFromF (getWatchList state') (getF state') \\<and> \n   InvariantWatchListsUniq (getWatchList state') \\<and> \n   InvariantWatchListsCharacterization (getWatchList state') (getWatch1 state') (getWatch2 state') \\<and> \n   InvariantWatchesEl (getF state') (getWatch1 state') (getWatch2 state') \\<and> \n   InvariantWatchesDiffer (getF state') (getWatch1 state') (getWatch2 state') \\<and> \n   InvariantWatchCharacterization (getF state') (getWatch1 state') (getWatch2 state') (getM state') \\<and> \n   InvariantConflictFlagCharacterization (getConflictFlag state') (getF state') (getM state') \\<and> \n   InvariantConflictClauseCharacterization (getConflictFlag state') (getConflictClause state') (getF state') (getM state') \\<and> \n   InvariantQCharacterization (getConflictFlag state') (getQ state') (getF state') (getM state') \\<and> \n   InvariantUniqQ (getQ state') \\<and> \n   InvariantGetReasonIsReason (getReason state') (getF state') (getM state') (set (getQ state')) \\<and> \n   InvariantVarsM (getM state') F0 Vbl \\<and> \n   InvariantVarsQ (getQ state') F0 Vbl \\<and> \n   InvariantVarsF (getF state') F0 Vbl \\<and> \n   ((getConflictFlag state') \\<or> (getQ state') = []) \\<and> \n   currentLevel (getM state') = 0\" (is \"?Inv state'\")\nusing assms\nproof (induct Phi arbitrary: state)\n  case Nil\n  thus ?case\n    by simp\nnext\n  case (Cons clause Phi')\n  let ?state' = \"addClause clause state\"\n  have \"?Inv ?state'\"\n    using Cons\n    using InvariantsAfterAddClause[of \"state\" \"F0\" \"Vbl\" \"clause\"]\n    using formulaContainsItsClausesVariables[of \"clause\" \"F0\"]\n    by (simp add: Let_def)\n  thus ?case\n    using Cons(1)[of \"?state'\"] \\<open>finite Vbl\\<close> Cons(18) Cons(19) Cons(20) Cons(21) Cons(22)\n    by (simp add: Let_def)\nqed\n\nlemma InvariantEquivalentZLAfterInitializationStep:\nfixes Phi :: Formula\nassumes\n  \"(getSATFlag state = UNDEF \\<and> InvariantEquivalentZL (getF state) (getM state) (filter (\\<lambda> c. \\<not> clauseTautology c) Phi)) \\<or> \n   (getSATFlag state = FALSE \\<and> \\<not> satisfiable (filter (\\<lambda> c. \\<not> clauseTautology c) Phi))\"\n  \"InvariantConsistent (getM state)\"\n  \"InvariantUniq (getM state)\"\n  \"InvariantWatchListsContainOnlyClausesFromF (getWatchList state) (getF state)\" and\n  \"InvariantWatchListsUniq (getWatchList state)\" and\n  \"InvariantWatchListsCharacterization (getWatchList state) (getWatch1 state) (getWatch2 state)\"\n  \"InvariantWatchesEl (getF state) (getWatch1 state) (getWatch2 state)\" and\n  \"InvariantWatchesDiffer (getF state) (getWatch1 state) (getWatch2 state)\" and\n  \"InvariantWatchCharacterization (getF state) (getWatch1 state) (getWatch2 state) (getM state)\"\n  \"InvariantConflictFlagCharacterization (getConflictFlag state) (getF state) (getM state)\"\n  \"InvariantConflictClauseCharacterization (getConflictFlag state) (getConflictClause state) (getF state) (getM state)\"\n  \"InvariantQCharacterization (getConflictFlag state) (getQ state) (getF state) (getM state)\"\n  \"InvariantNoDecisionsWhenConflict (getF state) (getM state) (currentLevel (getM state))\"\n  \"InvariantNoDecisionsWhenUnit (getF state) (getM state) (currentLevel (getM state))\"\n  \"InvariantGetReasonIsReason (getReason state) (getF state) (getM state) (set (getQ state))\"\n  \"InvariantUniqQ (getQ state)\"\n  \"finite Vbl\"\n  \"InvariantVarsM (getM state) F0 Vbl\"\n  \"InvariantVarsQ (getQ state) F0 Vbl\"\n  \"InvariantVarsF (getF state) F0 Vbl\"\n  \"(getConflictFlag state) \\<or> (getQ state) = []\"\n  \"currentLevel (getM state) = 0\"\n  \"F0 = Phi @ Phi'\"\nshows\n  \"let state' = initialize Phi' state in\n     (getSATFlag state' = UNDEF \\<and> InvariantEquivalentZL (getF state') (getM state') (filter (\\<lambda> c. \\<not> clauseTautology c) F0)) \\<or> \n     (getSATFlag state' = FALSE \\<and> \\<not>satisfiable (filter (\\<lambda> c. \\<not> clauseTautology c) F0))\"\nusing assms\nproof (induct Phi' arbitrary: state Phi)\n  case Nil\n  thus ?case\n    unfolding prefixToLevel_def equivalentFormulae_def\n    by simp\nnext\n  case (Cons clause Phi'')\n  let ?filt = \"\\<lambda> F. (filter (\\<lambda> c. \\<not> clauseTautology c) F)\"\n  let ?state' = \"addClause clause state\"\n  let ?Phi' = \"?filt Phi @ [clause]\"\n  let ?Phi'' = \"if clauseTautology clause then ?filt Phi else ?Phi'\"\n  from Cons\n  have \"getSATFlag ?state' = UNDEF \\<and> InvariantEquivalentZL (getF ?state') (getM ?state') (?filt ?Phi'') \\<or> \n        getSATFlag ?state' = FALSE \\<and> \\<not> satisfiable (?filt ?Phi'')\"\n    using formulaContainsItsClausesVariables[of \"clause\" \"F0\"]\n    using InvariantEquivalentZLAfterAddClause[of \"state\" \"?filt Phi\" \"F0\" \"Vbl\" \"clause\"]\n    by (simp add:Let_def)\n  hence \"getSATFlag ?state' = UNDEF \\<and> InvariantEquivalentZL (getF ?state') (getM ?state') (?filt (Phi @ [clause])) \\<or>\n         getSATFlag ?state' = FALSE \\<and> \\<not> satisfiable (?filt (Phi @ [clause]))\"\n    by auto\n  moreover\n  from Cons\n  have \"InvariantConsistent (getM ?state') \\<and> \n   InvariantUniq (getM ?state') \\<and> \n   InvariantWatchListsContainOnlyClausesFromF (getWatchList ?state') (getF ?state') \\<and> \n   InvariantWatchListsUniq (getWatchList ?state') \\<and> \n   InvariantWatchListsCharacterization (getWatchList ?state') (getWatch1 ?state') (getWatch2 ?state') \\<and> \n   InvariantWatchesEl (getF ?state') (getWatch1 ?state') (getWatch2 ?state') \\<and> \n   InvariantWatchesDiffer (getF ?state') (getWatch1 ?state') (getWatch2 ?state') \\<and> \n   InvariantWatchCharacterization (getF ?state') (getWatch1 ?state') (getWatch2 ?state') (getM ?state') \\<and> \n   InvariantConflictFlagCharacterization (getConflictFlag ?state') (getF ?state') (getM ?state') \\<and> \n   InvariantConflictClauseCharacterization (getConflictFlag ?state') (getConflictClause ?state') (getF ?state') (getM ?state') \\<and> \n   InvariantQCharacterization (getConflictFlag ?state') (getQ ?state') (getF ?state') (getM ?state') \\<and> \n   InvariantGetReasonIsReason (getReason ?state') (getF ?state') (getM ?state') (set (getQ ?state')) \\<and> \n   InvariantUniqQ (getQ ?state') \\<and> \n   InvariantVarsM (getM ?state') F0 Vbl \\<and> \n   InvariantVarsQ (getQ ?state') F0 Vbl \\<and> \n   InvariantVarsF (getF ?state') F0 Vbl \\<and> \n   ((getConflictFlag ?state') \\<or> (getQ ?state') = []) \\<and> \n   currentLevel (getM ?state') = 0\"\n    using formulaContainsItsClausesVariables[of \"clause\" \"F0\"]\n    using InvariantsAfterAddClause\n    by (simp add: Let_def)\n  moreover\n  hence \"InvariantNoDecisionsWhenConflict (getF ?state') (getM ?state') (currentLevel (getM ?state'))\"\n    \"InvariantNoDecisionsWhenUnit (getF ?state') (getM ?state') (currentLevel (getM ?state'))\"\n    unfolding InvariantNoDecisionsWhenConflict_def\n    unfolding InvariantNoDecisionsWhenUnit_def\n    by auto\n  ultimately\n  show ?case\n    using Cons(1)[of \"?state'\" \"Phi @ [clause]\"] \\<open>finite Vbl\\<close> Cons(23) Cons(24)\n    by (simp add: Let_def)\nqed\n\nlemma InvariantsAfterInitialization:\nshows\n  \"let state' = (initialize F0 initialState) in\n       InvariantConsistent (getM state') \\<and> \n       InvariantUniq (getM state') \\<and> \n       InvariantWatchListsContainOnlyClausesFromF (getWatchList state') (getF state') \\<and> \n       InvariantWatchListsUniq (getWatchList state') \\<and> \n       InvariantWatchListsCharacterization (getWatchList state') (getWatch1 state') (getWatch2 state') \\<and> \n       InvariantWatchesEl (getF state') (getWatch1 state') (getWatch2 state') \\<and> \n       InvariantWatchesDiffer (getF state') (getWatch1 state') (getWatch2 state') \\<and> \n       InvariantWatchCharacterization (getF state') (getWatch1 state') (getWatch2 state') (getM state') \\<and> \n       InvariantConflictFlagCharacterization (getConflictFlag state') (getF state') (getM state') \\<and> \n       InvariantConflictClauseCharacterization (getConflictFlag state') (getConflictClause state') (getF state') (getM state') \\<and> \n       InvariantQCharacterization (getConflictFlag state') (getQ state') (getF state') (getM state') \\<and> \n       InvariantNoDecisionsWhenConflict (getF state') (getM state') (currentLevel (getM state')) \\<and> \n       InvariantNoDecisionsWhenUnit (getF state') (getM state') (currentLevel (getM state')) \\<and> \n       InvariantGetReasonIsReason (getReason state') (getF state') (getM state') (set (getQ state')) \\<and> \n       InvariantUniqQ (getQ state') \\<and> \n       InvariantVarsM (getM state') F0 {} \\<and> \n       InvariantVarsQ (getQ state') F0 {} \\<and> \n       InvariantVarsF (getF state') F0 {} \\<and> \n       ((getConflictFlag state') \\<or> (getQ state') = []) \\<and> \n       currentLevel (getM state') = 0\"\nusing InvariantsAfterInitializationStep[of \"initialState\" \"{}\" \"F0\" \"initialize F0 initialState\" \"F0\"]\nunfolding initialState_def\nunfolding InvariantConsistent_def\nunfolding InvariantUniq_def\nunfolding InvariantWatchListsContainOnlyClausesFromF_def\nunfolding InvariantWatchListsUniq_def\nunfolding InvariantWatchListsCharacterization_def\nunfolding InvariantWatchesEl_def\nunfolding InvariantWatchesDiffer_def\nunfolding InvariantWatchCharacterization_def\nunfolding watchCharacterizationCondition_def\nunfolding InvariantConflictFlagCharacterization_def\nunfolding InvariantConflictClauseCharacterization_def\nunfolding InvariantQCharacterization_def\nunfolding InvariantUniqQ_def\nunfolding InvariantNoDecisionsWhenConflict_def\nunfolding InvariantNoDecisionsWhenUnit_def\nunfolding InvariantGetReasonIsReason_def\nunfolding InvariantVarsM_def\nunfolding InvariantVarsQ_def\nunfolding InvariantVarsF_def\nunfolding currentLevel_def\nby (simp) (force)\n\nlemma InvariantEquivalentZLAfterInitialization:\nfixes F0 :: Formula\nshows\n  \"let state' = (initialize F0 initialState) in\n   let F0' = (filter (\\<lambda> c. \\<not> clauseTautology c) F0) in\n     (getSATFlag state' = UNDEF \\<and> InvariantEquivalentZL (getF state') (getM state') F0') \\<or> \n     (getSATFlag state' = FALSE \\<and> \\<not> satisfiable F0')\"\nusing InvariantEquivalentZLAfterInitializationStep[of \"initialState\" \"[]\" \"{}\" \"F0\" \"F0\"]\nunfolding initialState_def\nunfolding InvariantEquivalentZL_def\nunfolding InvariantConsistent_def\nunfolding InvariantUniq_def\nunfolding InvariantWatchesEl_def\nunfolding InvariantWatchesDiffer_def\nunfolding InvariantWatchListsContainOnlyClausesFromF_def\nunfolding InvariantWatchListsUniq_def\nunfolding InvariantWatchListsCharacterization_def\nunfolding InvariantWatchCharacterization_def\nunfolding InvariantConflictFlagCharacterization_def\nunfolding InvariantConflictClauseCharacterization_def\nunfolding InvariantQCharacterization_def\nunfolding InvariantNoDecisionsWhenConflict_def\nunfolding InvariantNoDecisionsWhenUnit_def\nunfolding InvariantGetReasonIsReason_def\nunfolding InvariantVarsM_def\nunfolding InvariantVarsQ_def\nunfolding InvariantVarsF_def\nunfolding watchCharacterizationCondition_def\nunfolding InvariantUniqQ_def\nunfolding prefixToLevel_def\nunfolding equivalentFormulae_def\nunfolding currentLevel_def\nby (auto simp add: Let_def)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/SATSolverVerification/Initialization.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6442251064863697, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.2995012643237018}}
{"text": "theory Monitor\n  imports MDL Temporal\nbegin\n\ntype_synonym ('h, 't) time = \"('h \\<times> 't) option\"\n\ndatatype (dead 'a, dead 't :: timestamp, dead 'h) vydra_aux =\n    VYDRA_None\n  | VYDRA_Bool bool 'h\n  | VYDRA_Atom 'a 'h\n  | VYDRA_Neg \"('a, 't, 'h) vydra_aux\"\n  | VYDRA_Bin \"bool \\<Rightarrow> bool \\<Rightarrow> bool\" \"('a, 't, 'h) vydra_aux\" \"('a, 't, 'h) vydra_aux\"\n  | VYDRA_Prev \"'t \\<I>\" \"('a, 't, 'h) vydra_aux\" 'h \"('t \\<times> bool) option\"\n  | VYDRA_Next \"'t \\<I>\" \"('a, 't, 'h) vydra_aux\" 'h \"'t option\"\n  | VYDRA_Since \"'t \\<I>\" \"('a, 't, 'h) vydra_aux\" \"('a, 't, 'h) vydra_aux\" \"('h, 't) time\" nat nat \"nat option\" \"'t option\"\n  | VYDRA_Until \"'t \\<I>\" \"('h, 't) time\" \"('a, 't, 'h) vydra_aux\" \"('a, 't, 'h) vydra_aux\" \"('h, 't) time\" nat \"('t \\<times> bool \\<times> bool) option\"\n  | VYDRA_MatchP \"'t \\<I>\" \"transition iarray\" nat\n    \"(bool iarray, nat set, 't, ('h, 't) time, ('a, 't, 'h) vydra_aux list) window\"\n  | VYDRA_MatchF \"'t \\<I>\" \"transition iarray\" nat\n    \"(bool iarray, nat set, 't, ('h, 't) time, ('a, 't, 'h) vydra_aux list) window\"\n\ntype_synonym ('a, 't, 'h) vydra = \"nat \\<times> ('a, 't, 'h) vydra_aux\"\n\nfun msize_vydra :: \"nat \\<Rightarrow> ('a, 't :: timestamp, 'h) vydra_aux \\<Rightarrow> nat\" where\n  \"msize_vydra n VYDRA_None = 0\"\n| \"msize_vydra n (VYDRA_Bool b e) = 0\"\n| \"msize_vydra n (VYDRA_Atom a e) = 0\"\n| \"msize_vydra (Suc n) (VYDRA_Bin f v1 v2) = msize_vydra n v1 + msize_vydra n v2 + 1\"\n| \"msize_vydra (Suc n) (VYDRA_Neg v) = msize_vydra n v + 1\"\n| \"msize_vydra (Suc n) (VYDRA_Prev I v e tb) = msize_vydra n v + 1\"\n| \"msize_vydra (Suc n) (VYDRA_Next I v e to) = msize_vydra n v + 1\"\n| \"msize_vydra (Suc n) (VYDRA_Since I vphi vpsi e cphi cpsi cppsi tppsi) = msize_vydra n vphi + msize_vydra n vpsi + 1\"\n| \"msize_vydra (Suc n) (VYDRA_Until I e vphi vpsi epsi c zo) = msize_vydra n vphi + msize_vydra n vpsi + 1\"\n| \"msize_vydra (Suc n) (VYDRA_MatchP I transs qf w) = size_list (msize_vydra n) (w_si w) + size_list (msize_vydra n) (w_sj w) + 1\"\n| \"msize_vydra (Suc n) (VYDRA_MatchF I transs qf w) = size_list (msize_vydra n) (w_si w) + size_list (msize_vydra n) (w_sj w) + 1\"\n| \"msize_vydra _ _ = 0\"\n\nfun next_vydra :: \"('a, 't :: timestamp, 'h) vydra_aux \\<Rightarrow> nat\" where\n  \"next_vydra (VYDRA_Next I v e None) = 1\"\n| \"next_vydra _ = 0\"\n\ncontext\n  fixes init_hd :: \"'h\"\n    and run_hd :: \"'h \\<Rightarrow> ('h \\<times> ('t :: timestamp \\<times> 'a set)) option\"\nbegin\n\ndefinition t0 :: \"('h, 't) time\" where\n  \"t0 = (case run_hd init_hd of None \\<Rightarrow> None | Some (e', (t, X)) \\<Rightarrow> Some (e', t))\"\n\nfun run_t :: \"('h, 't) time \\<Rightarrow> (('h, 't) time \\<times> 't) option\" where\n  \"run_t None = None\"\n| \"run_t (Some (e, t)) = (case run_hd e of None \\<Rightarrow> Some (None, t)\n  | Some (e', (t', X)) \\<Rightarrow> Some (Some (e', t'), t))\"\n\nfun read_t :: \"('h, 't) time \\<Rightarrow> 't option\" where\n  \"read_t None = None\"\n| \"read_t (Some (e, t)) = Some t\"\n\nlemma run_t_read: \"run_t x = Some (x', t) \\<Longrightarrow> read_t x = Some t\"\n  by (cases x) (auto split: option.splits)\n\nlemma read_t_run: \"read_t x = Some t \\<Longrightarrow> \\<exists>x'. run_t x = Some (x', t)\"\n  by (cases x) (auto split: option.splits)\n\nlemma reach_event_t: \"reaches_on run_hd e vs e'' \\<Longrightarrow> run_hd e = Some (e', (t, X)) \\<Longrightarrow>\n  run_hd e'' = Some (e''', (t', X')) \\<Longrightarrow>\n  reaches_on run_t (Some (e', t)) (map fst vs) (Some (e''', t'))\"\nproof (induction e vs e'' arbitrary: t' X' e''' rule: reaches_on_rev_induct)\n  case (2 s s' v vs s'')\n  obtain v_t v_X where v_def: \"v = (v_t, v_X)\"\n    by (cases v) auto\n  have run_t_s'': \"run_t (Some (s'', v_t)) = Some (Some (e''', t'), v_t)\"\n    by (auto simp: 2(5))\n  show ?case\n    using reaches_on_app[OF 2(3)[OF 2(4) 2(2)[unfolded v_def]] run_t_s'']\n    by (auto simp: v_def)\nqed (auto intro: reaches_on.intros)\n\nlemma reach_event_t0_t:\n  assumes \"reaches_on run_hd init_hd vs e''\" \"run_hd e'' = Some (e''', (t', X'))\"\n  shows \"reaches_on run_t t0 (map fst vs) (Some (e''', t'))\"\nproof -\n  have t0_not_None: \"t0 \\<noteq> None\"\n    apply (rule reaches_on.cases[OF assms(1)])\n    using assms(2)\n    by (auto simp: t0_def split: option.splits prod.splits)\n  then show ?thesis\n    using reach_event_t[OF assms(1) _ assms(2)]\n    by (auto simp: t0_def split: option.splits)\nqed\n\nlemma reaches_on_run_hd_t:\n  assumes \"reaches_on run_hd init_hd vs e\"\n  shows \"\\<exists>x. reaches_on run_t t0 (map fst vs) x\"\nproof (cases vs rule: rev_cases)\n  case (snoc ys y)\n  show ?thesis\n    using assms\n    apply (cases y)\n    apply (auto simp: snoc dest!: reaches_on_split_last)\n    apply (meson reaches_on_app[OF reach_event_t0_t] read_t.simps(2) read_t_run)\n    done\nqed (auto intro: reaches_on.intros)\n\ndefinition \"run_subs run = (\\<lambda>vs. let vs' = map run vs in\n  (if (\\<exists>x \\<in> set vs'. Option.is_none x) then None\n   else Some (map (fst \\<circ> the) vs', iarray_of_list (map (snd \\<circ> snd \\<circ> the) vs'))))\"\n\nlemma run_subs_lD: \"run_subs run vs = Some (vs', bs) \\<Longrightarrow>\n  length vs' = length vs \\<and> IArray.length bs = length vs\"\n  by (auto simp: run_subs_def Let_def iarray_of_list_def split: option.splits if_splits)\n\nlemma run_subs_vD: \"run_subs run vs = Some (vs', bs) \\<Longrightarrow> j < length vs \\<Longrightarrow>\n  \\<exists>vj' tj bj. run (vs ! j) = Some (vj', (tj, bj)) \\<and> vs' ! j = vj' \\<and> IArray.sub bs j = bj\"\n  apply (cases \"run (vs ! j)\")\n   apply (auto simp: Option.is_none_def run_subs_def Let_def iarray_of_list_def\n      split: option.splits if_splits)\n  by (metis image_eqI nth_mem)\n\nfun msize_fmla :: \"('a, 'b :: timestamp) formula \\<Rightarrow> nat\"\n  and msize_regex :: \"('a, 'b) regex \\<Rightarrow> nat\" where\n  \"msize_fmla (Bool b) = 0\"\n| \"msize_fmla (Atom a) = 0\"\n| \"msize_fmla (Neg phi) = Suc (msize_fmla phi)\"\n| \"msize_fmla (Bin f phi psi) = Suc (msize_fmla phi + msize_fmla psi)\"\n| \"msize_fmla (Prev I phi) = Suc (msize_fmla phi)\"\n| \"msize_fmla (Next I phi) = Suc (msize_fmla phi)\"\n| \"msize_fmla (Since phi I psi) = Suc (max (msize_fmla phi) (msize_fmla psi))\"\n| \"msize_fmla (Until phi I psi) = Suc (max (msize_fmla phi) (msize_fmla psi))\"\n| \"msize_fmla (MatchP I r) = Suc (msize_regex r)\"\n| \"msize_fmla (MatchF I r) = Suc (msize_regex r)\"\n| \"msize_regex (Lookahead phi) = msize_fmla phi\"\n| \"msize_regex (Symbol phi) = msize_fmla phi\"\n| \"msize_regex (Plus r s) = max (msize_regex r) (msize_regex s)\"\n| \"msize_regex (Times r s) = max (msize_regex r) (msize_regex s)\"\n| \"msize_regex (Star r) = msize_regex r\"\n\nlemma collect_subfmlas_msize: \"x \\<in> set (collect_subfmlas r []) \\<Longrightarrow>\n  msize_fmla x \\<le> msize_regex r\"\nproof (induction r)\n  case (Lookahead phi)\n  then show ?case\n    by (auto split: if_splits)\nnext\n  case (Symbol phi)\n  then show ?case\n    by (auto split: if_splits)\nnext\n  case (Plus r1 r2)\n  then show ?case\n    by (auto simp: collect_subfmlas_set[of r2 \"collect_subfmlas r1 []\"])\nnext\n  case (Times r1 r2)\n  then show ?case\n    by (auto simp: collect_subfmlas_set[of r2 \"collect_subfmlas r1 []\"])\nnext\n  case (Star r)\n  then show ?case\n    by fastforce\nqed\n\ndefinition \"until_ready I t c zo = (case (c, zo) of (Suc _, Some (t', b1, b2)) \\<Rightarrow> (b2 \\<and> memL t t' I) \\<or> \\<not>b1 | _ \\<Rightarrow> False)\"\n\ndefinition \"while_since_cond I t = (\\<lambda>(vpsi, e, cpsi :: nat, cppsi, tppsi). cpsi > 0 \\<and> memL (the (read_t e)) t I)\"\ndefinition \"while_since_body run =\n  (\\<lambda>(vpsi, e, cpsi :: nat, cppsi, tppsi).\n    case run vpsi of Some (vpsi', (t', b')) \\<Rightarrow>\n      Some (vpsi', fst (the (run_t e)), cpsi - 1, if b' then Some cpsi else cppsi, if b' then Some t' else tppsi)\n      | _ \\<Rightarrow> None\n    )\"\n\ndefinition \"while_until_cond I t = (\\<lambda>(vphi, vpsi, epsi, c, zo). \\<not>until_ready I t c zo \\<and> (case read_t epsi of Some t' \\<Rightarrow> memR t t' I | None \\<Rightarrow> False))\"\ndefinition \"while_until_body run =\n  (\\<lambda>(vphi, vpsi, epsi, c, zo). case run_t epsi of Some (epsi', t') \\<Rightarrow>\n    (case run vphi of Some (vphi', (_, b1)) \\<Rightarrow>\n      (case run vpsi of Some (vpsi', (_, b2)) \\<Rightarrow> Some (vphi', vpsi', epsi', Suc c, Some (t', b1, b2))\n      | _ \\<Rightarrow> None)\n    | _ \\<Rightarrow> None))\"\n\nfunction (sequential) run :: \"nat \\<Rightarrow> ('a, 't, 'h) vydra_aux \\<Rightarrow> (('a, 't, 'h) vydra_aux \\<times> ('t \\<times> bool)) option\" where\n  \"run n (VYDRA_None) = None\"\n| \"run n (VYDRA_Bool b e) = (case run_hd e of None \\<Rightarrow> None\n    | Some (e', (t, _)) \\<Rightarrow> Some (VYDRA_Bool b e', (t, b)))\"\n| \"run n (VYDRA_Atom a e) = (case run_hd e of None \\<Rightarrow> None\n    | Some (e', (t, X)) \\<Rightarrow> Some (VYDRA_Atom a e', (t, a \\<in> X)))\"\n| \"run (Suc n) (VYDRA_Neg v) = (case run n v of None \\<Rightarrow> None\n    | Some (v', (t, b)) \\<Rightarrow> Some (VYDRA_Neg v', (t, \\<not>b)))\"\n| \"run (Suc n) (VYDRA_Bin f vl vr) = (case run n vl of None \\<Rightarrow> None\n    | Some (vl', (t, bl)) \\<Rightarrow> (case run n vr of None \\<Rightarrow> None\n    | Some (vr', (_, br)) \\<Rightarrow> Some (VYDRA_Bin f vl' vr', (t, f bl br))))\"\n| \"run (Suc n) (VYDRA_Prev I v e tb) = (case run_hd e of Some (e', (t, _)) \\<Rightarrow>\n        (let \\<beta> = (case tb of Some (t', b') \\<Rightarrow> b' \\<and> mem t' t I | None \\<Rightarrow> False) in\n        case run n v of Some (v', _, b') \\<Rightarrow> Some (VYDRA_Prev I v' e' (Some (t, b')), (t, \\<beta>))\n        | None \\<Rightarrow> Some (VYDRA_None, (t, \\<beta>)))\n    | None \\<Rightarrow> None)\"\n| \"run (Suc n) (VYDRA_Next I v e to) = (case run_hd e of Some (e', (t, _)) \\<Rightarrow>\n    (case to of None \\<Rightarrow>\n      (case run n v of Some (v', _, _) \\<Rightarrow> run (Suc n) (VYDRA_Next I v' e' (Some t))\n      | None \\<Rightarrow> None)\n    | Some t' \\<Rightarrow>\n      (case run n v of Some (v', _, b) \\<Rightarrow> Some (VYDRA_Next I v' e' (Some t), (t', b \\<and> mem t' t I))\n      | None \\<Rightarrow> if mem t' t I then None else Some (VYDRA_None, (t', False))))\n    | None \\<Rightarrow> None)\"\n| \"run (Suc n) (VYDRA_Since I vphi vpsi e cphi cpsi cppsi tppsi) = (case run n vphi of\n    Some (vphi', (t, b1)) \\<Rightarrow>\n      let cphi = (if b1 then Suc cphi else 0) in\n      let cpsi = Suc cpsi in\n      let cppsi = map_option Suc cppsi in\n      (case while_break (while_since_cond I t) (while_since_body (run n)) (vpsi, e, cpsi, cppsi, tppsi) of Some (vpsi', e', cpsi', cppsi', tppsi') \\<Rightarrow>\n        (let \\<beta> = (case cppsi' of Some k \\<Rightarrow> k - 1 \\<le> cphi \\<and> memR (the tppsi') t I | _ \\<Rightarrow> False) in\n         Some (VYDRA_Since I vphi' vpsi' e' cphi cpsi' cppsi' tppsi', (t, \\<beta>)))\n      | _ \\<Rightarrow> None)\n    | _ \\<Rightarrow> None)\"\n| \"run (Suc n) (VYDRA_Until I e vphi vpsi epsi c zo) = (case run_t e of Some (e', t) \\<Rightarrow>\n      (case while_break (while_until_cond I t) (while_until_body (run n)) (vphi, vpsi, epsi, c, zo) of Some (vphi', vpsi', epsi', c', zo') \\<Rightarrow>\n        if c' = 0 then None else\n        (case zo' of Some (t', b1, b2) \\<Rightarrow>\n          (if b2 \\<and> memL t t' I then Some (VYDRA_Until I e' vphi' vpsi' epsi' (c' - 1) zo', (t, True))\n          else if \\<not>b1 then Some (VYDRA_Until I e' vphi' vpsi' epsi' (c' - 1) zo', (t, False))\n          else (case read_t epsi' of Some t' \\<Rightarrow> Some (VYDRA_Until I e' vphi' vpsi' epsi' (c' - 1) zo', (t, False)) | _ \\<Rightarrow> None))\n        | _ \\<Rightarrow> None)\n      | _ \\<Rightarrow> None)\n    | _ \\<Rightarrow> None)\"\n| \"run (Suc n) (VYDRA_MatchP I transs qf w) =\n    (case eval_matchP (init_args ({0}, NFA.delta' transs qf, NFA.accept' transs qf)\n      (run_t, read_t) (run_subs (run n))) I w of None \\<Rightarrow> None\n    | Some ((t, b), w') \\<Rightarrow> Some (VYDRA_MatchP I transs qf w', (t, b)))\"\n| \"run (Suc n) (VYDRA_MatchF I transs qf w) =\n    (case eval_matchF (init_args ({0}, NFA.delta' transs qf, NFA.accept' transs qf)\n      (run_t, read_t) (run_subs (run n))) I w of None \\<Rightarrow> None\n    | Some ((t, b), w') \\<Rightarrow> Some (VYDRA_MatchF I transs qf w', (t, b)))\"\n| \"run _ _ = undefined\"\n  by pat_completeness auto\ntermination\n  by (relation \"(\\<lambda>p. size (fst p)) <*mlex*> (\\<lambda>p. next_vydra (snd p)) <*mlex*> (\\<lambda>p. msize_vydra (fst p) (snd p)) <*mlex*> {}\") (auto simp: mlex_prod_def)\n\nlemma wf_since: \"wf {(t, s). while_since_cond I tt s \\<and> Some t = while_since_body (run n) s}\"\nproof -\n  let ?X = \"{(t, s). while_since_cond I tt s \\<and> Some t = while_since_body (run n) s}\"\n  have sub: \"?X \\<subseteq> measure (\\<lambda>(vpsi, e, cpsi, cppsi, tppsi). cpsi)\"\n    by (auto simp: while_since_cond_def while_since_body_def Let_def split: option.splits)\n  then show ?thesis\n    using wf_subset[OF wf_measure]\n    by auto\nqed\n\ndefinition run_vydra :: \"('a, 't, 'h) vydra \\<Rightarrow> (('a, 't, 'h) vydra \\<times> ('t \\<times> bool)) option\" where\n  \"run_vydra v = (case v of (n, w) \\<Rightarrow> map_option (apfst (Pair n)) (run n w))\"\n\nfun sub :: \"nat \\<Rightarrow> ('a, 't) formula \\<Rightarrow> ('a, 't, 'h) vydra_aux\" where\n  \"sub n (Bool b) = VYDRA_Bool b init_hd\"\n| \"sub n (Atom a) = VYDRA_Atom a init_hd\"\n| \"sub (Suc n) (Neg phi) = VYDRA_Neg (sub n phi)\"\n| \"sub (Suc n) (Bin f phi psi) = VYDRA_Bin f (sub n phi) (sub n psi)\"\n| \"sub (Suc n) (Prev I phi) = VYDRA_Prev I (sub n phi) init_hd None\"\n| \"sub (Suc n) (Next I phi) = VYDRA_Next I (sub n phi) init_hd None\"\n| \"sub (Suc n) (Since phi I psi) = VYDRA_Since I (sub n phi) (sub n psi) t0 0 0 None None\"\n| \"sub (Suc n) (Until phi I psi) = VYDRA_Until I t0 (sub n phi) (sub n psi) t0 0 None\"\n| \"sub (Suc n) (MatchP I r) = (let qf = state_cnt r;\n    transs = iarray_of_list (build_nfa_impl r (0, qf, [])) in\n    VYDRA_MatchP I transs qf (init_window (init_args\n      ({0}, NFA.delta' transs qf, NFA.accept' transs qf)\n      (run_t, read_t) (run_subs (run n)))\n      t0 (map (sub n) (collect_subfmlas r []))))\"\n| \"sub (Suc n) (MatchF I r) = (let qf = state_cnt r;\n    transs = iarray_of_list (build_nfa_impl r (0, qf, [])) in\n    VYDRA_MatchF I transs qf (init_window (init_args\n      ({0}, NFA.delta' transs qf, NFA.accept' transs qf)\n      (run_t, read_t) (run_subs (run n)))\n      t0 (map (sub n) (collect_subfmlas r []))))\"\n| \"sub _ _ = undefined\"\n\ndefinition init_vydra :: \"('a, 't) formula \\<Rightarrow> ('a, 't, 'h) vydra\" where\n  \"init_vydra \\<phi> = (let n = msize_fmla \\<phi> in (n, sub n \\<phi>))\"\n\nend\n\nlocale VYDRA_MDL = MDL \\<sigma>\n  for \\<sigma> :: \"('a, 't :: timestamp) trace\" +\n  fixes init_hd :: \"'h\"\n    and run_hd :: \"'h \\<Rightarrow> ('h \\<times> ('t \\<times> 'a set)) option\"\n  assumes run_hd_sound: \"reaches run_hd init_hd n s \\<Longrightarrow> run_hd s = Some (s', (t, X)) \\<Longrightarrow> (t, X) = (\\<tau> \\<sigma> n, \\<Gamma> \\<sigma> n)\"\nbegin\n\nlemma reaches_on_run_hd: \"reaches_on run_hd init_hd es s \\<Longrightarrow> run_hd s = Some (s', (t, X)) \\<Longrightarrow> t = \\<tau> \\<sigma> (length es) \\<and> X = \\<Gamma> \\<sigma> (length es)\"\n  using run_hd_sound\n  by (auto dest: reaches_on_n)\n\nabbreviation \"ru_t \\<equiv> run_t run_hd\"\nabbreviation \"l_t0 \\<equiv> t0 init_hd run_hd\"\nabbreviation \"ru \\<equiv> run run_hd\"\nabbreviation \"su \\<equiv> sub init_hd run_hd\"\n\nlemma ru_t_event: \"reaches_on ru_t t ts t' \\<Longrightarrow> t = l_t0 \\<Longrightarrow> ru_t t' = Some (t'', x) \\<Longrightarrow>\n  \\<exists>rho e tt. t' = Some (e, tt) \\<and> reaches_on run_hd init_hd rho e \\<and> length rho = Suc (length ts) \\<and>\n  x = \\<tau> \\<sigma> (length ts)\"\nproof (induction t ts t' arbitrary: t'' x rule: reaches_on_rev_induct)\n  case (1 s)\n  show ?case\n    using 1 reaches_on_run_hd[OF reaches_on.intros(1)]\n    by (auto simp: t0_def split: option.splits intro!: reaches_on.intros)\nnext\n  case (2 s s' v vs s'')\n  obtain rho e tt where rho_def: \"s' = Some (e, tt)\" \"reaches_on run_hd init_hd rho e\"\n    \"length rho = Suc (length vs)\"\n    using 2(3)[OF 2(4,2)]\n    by auto\n  then show ?case\n    using 2(2,5) reaches_on_app[OF rho_def(2)] reaches_on_run_hd[OF rho_def(2)]\n    by (fastforce split: option.splits)\nqed\n\nlemma ru_t_tau: \"reaches_on ru_t l_t0 ts t' \\<Longrightarrow> ru_t t' = Some (t'', x) \\<Longrightarrow> x = \\<tau> \\<sigma> (length ts)\"\n  using ru_t_event\n  by fastforce\n\nlemma ru_t_Some_tau:\n  assumes \"reaches_on ru_t l_t0 ts (Some (e, t))\"\n  shows \"t = \\<tau> \\<sigma> (length ts)\"\nproof -\n  obtain z where z_def: \"ru_t (Some (e, t)) = Some (z, t)\"\n    by (cases \"run_hd e\") auto\n  show ?thesis\n    by (rule ru_t_tau[OF assms z_def])\nqed\n\nlemma ru_t_tau_in:\n  assumes \"reaches_on ru_t l_t0 ts t\" \"j < length ts\"\n  shows \"ts ! j = \\<tau> \\<sigma> j\"\nproof -\n  obtain t' where t'_def: \"reaches_on ru_t l_t0 (take j ts) t'\" \"reaches_on ru_t t' (drop j ts) t\"\n    using reaches_on_split'[OF assms(1), where ?i=j] assms(2)\n    by auto\n  have drop: \"drop j ts = ts ! j # tl (drop j ts)\"\n    using assms(2)\n    by (cases \"drop j ts\") (auto simp add: nth_via_drop)\n  obtain t'' where t''_def: \"ru_t t' = Some (t'', ts ! j)\"\n    using t'_def(2) assms(2) drop\n    by (auto elim: reaches_on.cases)\n  show ?thesis\n    using ru_t_event[OF t'_def(1) refl t''_def] assms(2)\n    by auto\nqed\n\nlemmas run_hd_tau_in = ru_t_tau_in[OF reach_event_t0_t, simplified]\n\nfun last_before :: \"(nat \\<Rightarrow> bool) \\<Rightarrow> nat \\<Rightarrow> nat option\" where\n  \"last_before P 0 = None\"\n| \"last_before P (Suc n) = (if P n then Some n else last_before P n)\"\n\nlemma last_before_None: \"last_before P n = None \\<Longrightarrow> m < n \\<Longrightarrow> \\<not>P m\"\nproof (induction P n rule: last_before.induct)\n  case (2 P n)\n  then show ?case\n    by (cases \"m = n\") (auto split: if_splits)\nqed (auto split: if_splits)\n\nlemma last_before_Some: \"last_before P n = Some m \\<Longrightarrow> m < n \\<and> P m \\<and> (\\<forall>k \\<in> {m<..<n}. \\<not>P k)\"\n  apply (induction P n rule: last_before.induct)\n   apply (auto split: if_splits)\n  apply (metis greaterThanLessThan_iff less_antisym)\n  done\n\ninductive wf_vydra :: \"('a, 't :: timestamp) formula \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> ('a, 't, 'h) vydra_aux \\<Rightarrow> bool\" where\n  \"wf_vydra phi i n w \\<Longrightarrow> ru n w = None \\<Longrightarrow> wf_vydra (Prev I phi) (Suc i) (Suc n) VYDRA_None\"\n| \"wf_vydra phi i n w \\<Longrightarrow> ru n w = None \\<Longrightarrow> wf_vydra (Next I phi) i (Suc n) VYDRA_None\"\n| \"reaches_on run_hd init_hd es sub' \\<Longrightarrow> length es = i \\<Longrightarrow> wf_vydra (Bool b) i n (VYDRA_Bool b sub')\"\n| \"reaches_on run_hd init_hd es sub' \\<Longrightarrow> length es = i \\<Longrightarrow> wf_vydra (Atom a) i n (VYDRA_Atom a sub')\"\n| \"wf_vydra phi i n v \\<Longrightarrow> wf_vydra (Neg phi) i (Suc n) (VYDRA_Neg v)\"\n| \"wf_vydra phi i n v \\<Longrightarrow> wf_vydra psi i n v' \\<Longrightarrow> wf_vydra (Bin f phi psi) i (Suc n) (VYDRA_Bin f v v')\"\n| \"wf_vydra phi i n v \\<Longrightarrow> reaches_on run_hd init_hd es sub' \\<Longrightarrow> length es = i \\<Longrightarrow>\n   wf_vydra (Prev I phi) i (Suc n) (VYDRA_Prev I v sub' (case i of 0 \\<Rightarrow> None | Suc j \\<Rightarrow> Some (\\<tau> \\<sigma> j, sat phi j)))\"\n| \"wf_vydra phi i n v \\<Longrightarrow> reaches_on run_hd init_hd es sub' \\<Longrightarrow> length es = i \\<Longrightarrow>\n   wf_vydra (Next I phi) (i - 1) (Suc n) (VYDRA_Next I v sub' (case i of 0 \\<Rightarrow> None | Suc j \\<Rightarrow> Some (\\<tau> \\<sigma> j)))\"\n| \"wf_vydra phi i n vphi \\<Longrightarrow> wf_vydra psi j n vpsi \\<Longrightarrow> j \\<le> i \\<Longrightarrow>\n   reaches_on ru_t l_t0 es sub' \\<Longrightarrow> length es = j \\<Longrightarrow> (\\<And>t. t \\<in> set es \\<Longrightarrow> memL t (\\<tau> \\<sigma> i) I) \\<Longrightarrow>\n   cphi = i - (case last_before (\\<lambda>k. \\<not>sat phi k) i of None \\<Rightarrow> 0 | Some k \\<Rightarrow> Suc k) \\<Longrightarrow> cpsi = i - j \\<Longrightarrow>\n   cppsi = (case last_before (sat psi) j of None \\<Rightarrow> None | Some k \\<Rightarrow> Some (i - k)) \\<Longrightarrow>\n   tppsi = (case last_before (sat psi) j of None \\<Rightarrow> None | Some k \\<Rightarrow> Some (\\<tau> \\<sigma> k)) \\<Longrightarrow>\n   wf_vydra (Since phi I psi) i (Suc n) (VYDRA_Since I vphi vpsi sub' cphi cpsi cppsi tppsi)\"\n| \"wf_vydra phi j n vphi \\<Longrightarrow> wf_vydra psi j n vpsi \\<Longrightarrow> i \\<le> j \\<Longrightarrow>\n   reaches_on ru_t l_t0 es back \\<Longrightarrow> length es = i \\<Longrightarrow>\n   reaches_on ru_t l_t0 es' front \\<Longrightarrow> length es' = j \\<Longrightarrow> (\\<And>t. t \\<in> set es' \\<Longrightarrow> memR (\\<tau> \\<sigma> i) t I) \\<Longrightarrow>\n   c = j - i \\<Longrightarrow> z = (case j of 0 \\<Rightarrow> None | Suc k \\<Rightarrow> Some (\\<tau> \\<sigma> k, sat phi k, sat psi k)) \\<Longrightarrow>\n   (\\<And>k. k \\<in> {i..<j - 1} \\<Longrightarrow> sat phi k \\<and> (memL (\\<tau> \\<sigma> i) (\\<tau> \\<sigma> k) I \\<longrightarrow> \\<not>sat psi k)) \\<Longrightarrow>\n   wf_vydra (Until phi I psi) i (Suc n) (VYDRA_Until I back vphi vpsi front c z)\"\n| \"valid_window_matchP args I l_t0 (map (su n) (collect_subfmlas r [])) xs i w \\<Longrightarrow>\n    n \\<ge> msize_regex r \\<Longrightarrow> qf = state_cnt r \\<Longrightarrow>\n    transs = iarray_of_list (build_nfa_impl r (0, qf, [])) \\<Longrightarrow>\n    args = init_args ({0}, NFA.delta' transs qf, NFA.accept' transs qf)\n      (ru_t, read_t) (run_subs (ru n)) \\<Longrightarrow>\n    wf_vydra (MatchP I r) i (Suc n) (VYDRA_MatchP I transs qf w)\"\n| \"valid_window_matchF args I l_t0 (map (su n) (collect_subfmlas r [])) xs i w \\<Longrightarrow>\n    n \\<ge> msize_regex r \\<Longrightarrow> qf = state_cnt r \\<Longrightarrow>\n    transs = iarray_of_list (build_nfa_impl r (0, qf, [])) \\<Longrightarrow>\n    args = init_args ({0}, NFA.delta' transs qf, NFA.accept' transs qf)\n      (ru_t, read_t) (run_subs (ru n)) \\<Longrightarrow>\n    wf_vydra (MatchF I r) i (Suc n) (VYDRA_MatchF I transs qf w)\"\n\nlemma reach_run_subs_len:\n  assumes reaches_ons: \"reaches_on (run_subs (ru n)) (map (su n) (collect_subfmlas r [])) rho vs\"\n  shows \"length vs = length (collect_subfmlas r [])\"\n  using reaches_ons run_subs_lD\n  by (induction \"map (su n) (collect_subfmlas r [])\" rho vs rule: reaches_on_rev_induct) fastforce+\n\nlemma reach_run_subs_run:\n  assumes reaches_ons: \"reaches_on (run_subs (ru n)) (map (su n) (collect_subfmlas r [])) rho vs\"\n    and subfmla: \"j < length (collect_subfmlas r [])\" \"phi = collect_subfmlas r [] ! j\"\n  shows \"\\<exists>rho'. reaches_on (ru n) (su n phi) rho' (vs ! j) \\<and> length rho' = length rho\"\n  using reaches_ons subfmla\nproof (induction \"map (su n) (collect_subfmlas r [])\" rho vs rule: reaches_on_rev_induct)\n  case 1\n  then show ?case\n    by (auto intro: reaches_on.intros)\nnext\n  case (2 s' v vs' s'')\n  note len_s'_vs = reach_run_subs_len[OF 2(1)]\n  obtain rho' where reach_s'_vs: \"reaches_on (ru n) (su n phi) rho' (s' ! j)\"\n    \"length rho' = length vs'\"\n    using 2(2)[OF 2(4,5)]\n    by auto\n  note run_subslD = run_subs_lD[OF 2(3)]\n  note run_subsvD = run_subs_vD[OF 2(3) 2(4)[unfolded len_s'_vs[symmetric]]]\n  obtain vj' tj bj where vj'_def: \"ru n (s' ! j) = Some (vj', tj, bj)\"\n    \"s'' ! j = vj'\" \"IArray.sub v j = bj\"\n    using run_subsvD by auto\n  obtain rho'' where rho''_def: \"reaches_on (ru n) (su n phi) rho'' (s'' ! j)\"\n    \"length rho'' = Suc (length vs')\"\n    using reaches_on_app[OF reach_s'_vs(1) vj'_def(1)] vj'_def(2) reach_s'_vs(2)\n    by auto\n  then show ?case\n    using conjunct1[OF run_subslD, unfolded len_s'_vs[symmetric]]\n    by auto\nqed\n\nlemma IArray_nth_equalityI: \"IArray.length xs = length ys \\<Longrightarrow>\n  (\\<And>i. i < IArray.length xs \\<Longrightarrow> IArray.sub xs i = ys ! i) \\<Longrightarrow> xs = IArray ys\"\n  by (induction xs arbitrary: ys) (auto intro: nth_equalityI)\n\nlemma bs_sat:\n  assumes IH: \"\\<And>phi i v v' b. phi \\<in> set (collect_subfmlas r []) \\<Longrightarrow> wf_vydra phi i n v \\<Longrightarrow> ru n v = Some (v', b) \\<Longrightarrow> snd b = sat phi i\"\n    and reaches_ons: \"\\<And>j. j < length (collect_subfmlas r []) \\<Longrightarrow> wf_vydra (collect_subfmlas r [] ! j) i n (vs ! j)\"\n    and run_subs: \"run_subs (ru n) vs = Some (vs', bs)\" \"length vs = length (collect_subfmlas r [])\"\n  shows \"bs = iarray_of_list (map (\\<lambda>phi. sat phi i) (collect_subfmlas r []))\"\nproof -\n  have \"\\<And>j. j < length (collect_subfmlas r []) \\<Longrightarrow>\n    IArray.sub bs j = sat (collect_subfmlas r [] ! j) i\"\n  proof -\n    fix j\n    assume lassm: \"j < length (collect_subfmlas r [])\"\n    define phi where \"phi = collect_subfmlas r [] ! j\"\n    have phi_in_set: \"phi \\<in> set (collect_subfmlas r [])\"\n      using lassm\n      by (auto simp: phi_def)\n    have wf: \"wf_vydra phi i n (vs ! j)\"\n      using reaches_ons lassm phi_def\n      by metis\n    show \"IArray.sub bs j = sat (collect_subfmlas r [] ! j) i\"\n      using IH(1)[OF phi_in_set wf] run_subs_vD[OF run_subs(1) lassm[folded run_subs(2)]]\n      unfolding phi_def[symmetric]\n      by auto\n  qed\n  moreover have \"length (IArray.list_of bs) = length vs\"\n    using run_subs(1)\n    by (auto simp: run_subs_def Let_def iarray_of_list_def split: if_splits)\n  ultimately show ?thesis\n    using run_subs(2)\n    by (auto simp: iarray_of_list_def intro!: IArray_nth_equalityI)\nqed\n\nlemma run_induct[case_names Bool Atom Neg Bin Prev Next Since Until MatchP MatchF, consumes 1]:\n  fixes phi :: \"('a, 't) formula\"\n  assumes \"msize_fmla phi \\<le> n\" \"(\\<And>b n. P n (Bool b))\" \"(\\<And>a n. P n (Atom a))\"\n    \"(\\<And>n phi. msize_fmla phi \\<le> n \\<Longrightarrow> P n phi \\<Longrightarrow> P (Suc n) (Neg phi))\"\n    \"(\\<And>n f phi psi. msize_fmla (Bin f phi psi) \\<le> Suc n \\<Longrightarrow> P n phi \\<Longrightarrow> P n psi \\<Longrightarrow>\n      P (Suc n) (Bin f phi psi))\"\n    \"(\\<And>n I phi. msize_fmla phi \\<le> n \\<Longrightarrow> P n phi \\<Longrightarrow> P (Suc n) (Prev I phi))\"\n    \"(\\<And>n I phi. msize_fmla phi \\<le> n \\<Longrightarrow> P n phi \\<Longrightarrow> P (Suc n) (Next I phi))\"\n    \"(\\<And>n I phi psi. msize_fmla phi \\<le> n \\<Longrightarrow> msize_fmla psi \\<le> n \\<Longrightarrow> P n phi \\<Longrightarrow> P n psi \\<Longrightarrow> P (Suc n) (Since phi I psi))\"\n    \"(\\<And>n I phi psi. msize_fmla phi \\<le> n \\<Longrightarrow> msize_fmla psi \\<le> n \\<Longrightarrow> P n phi \\<Longrightarrow> P n psi \\<Longrightarrow> P (Suc n) (Until phi I psi))\"\n    \"(\\<And>n I r. msize_fmla (MatchP I r) \\<le> Suc n \\<Longrightarrow> (\\<And>x. msize_fmla x \\<le> n \\<Longrightarrow> P n x) \\<Longrightarrow>\n      P (Suc n) (MatchP I r))\"\n    \"(\\<And>n I r. msize_fmla (MatchF I r) \\<le> Suc n \\<Longrightarrow> (\\<And>x. msize_fmla x \\<le> n \\<Longrightarrow> P n x) \\<Longrightarrow>\n      P (Suc n) (MatchF I r))\"\n  shows \"P n phi\"\n  using assms(1)\nproof (induction n arbitrary: phi rule: nat_less_induct)\n  case (1 n)\n  show ?case\n  proof (cases n)\n    case 0\n    show ?thesis\n      using 1 assms(2-)\n      by (cases phi) (auto simp: 0)\n  next\n    case (Suc m)\n    show ?thesis\n      using 1 assms(2-)\n      by (cases phi) (auto simp: Suc)\n  qed\nqed\n\nlemma wf_vydra_sub: \"msize_fmla \\<phi> \\<le> n \\<Longrightarrow> wf_vydra \\<phi> 0 n (su n \\<phi>)\"\nproof (induction n \\<phi> rule: run_induct)\n  case (Prev n I phi)\n  then show ?case\n    using wf_vydra.intros(7)[where ?i=0, OF _ reaches_on.intros(1)]\n    by auto\nnext\n  case (Next n I phi)\n  then show ?case\n    using wf_vydra.intros(8)[where ?i=0, OF _ reaches_on.intros(1)]\n    by auto\nnext\n  case (MatchP n I r)\n  let ?qf = \"state_cnt r\"\n  let ?transs = \"iarray_of_list (build_nfa_impl r (0, ?qf, []))\"\n  let ?args = \"init_args ({0}, NFA.delta' ?transs ?qf, NFA.accept' ?transs ?qf) (ru_t, read_t) (run_subs (ru n))\"\n  show ?case\n    using MatchP valid_init_window[of ?args l_t0 \"map (su n) (collect_subfmlas r [])\", simplified]\n    by (auto simp: Let_def valid_window_matchP_def split: option.splits intro: reaches_on.intros\n        intro!: wf_vydra.intros(11)[where ?xs=\"[]\", OF _ _ refl refl refl])\nnext\n  case (MatchF n I r)\n  let ?qf = \"state_cnt r\"\n  let ?transs = \"iarray_of_list (build_nfa_impl r (0, ?qf, []))\"\n  let ?args = \"init_args ({0}, NFA.delta' ?transs ?qf, NFA.accept' ?transs ?qf) (ru_t, read_t) (run_subs (ru n))\"\n  show ?case\n    using MatchF valid_init_window[of ?args l_t0 \"map (su n) (collect_subfmlas r [])\", simplified]\n    by (auto simp: Let_def valid_window_matchF_def split: option.splits intro: reaches_on.intros\n        intro!: wf_vydra.intros(12)[where ?xs=\"[]\", OF _ _ refl refl refl])\nqed (auto simp: Let_def intro: wf_vydra.intros reaches_on.intros)\n\nlemma ru_t_Some: \"\\<exists>e' et. ru_t e = Some (e', et)\" if reaches_Suc_i: \"reaches_on run_hd init_hd fs f\" \"length fs = Suc i\"\n  and aux: \"reaches_on ru_t l_t0 es e\" \"length es \\<le> i\" for es e\nproof -\n  obtain fs' ft where ft_def: \"reaches_on ru_t l_t0 (map fst (fs' :: ('t \\<times> 'a set) list)) (Some (f, ft))\"\n    \"map fst fs = map fst fs' @ [ft]\" \"length fs' = i\"\n    using reaches_Suc_i\n    by (cases fs rule: rev_cases) (auto dest!: reaches_on_split_last reach_event_t0_t)\n  show ?thesis\n  proof (cases \"length es = i\")\n    case True\n    have e_def: \"e = Some (f, ft)\"\n      using reaches_on_inj[OF aux(1) ft_def(1)]\n      by (auto simp: True ft_def(3))\n    then show ?thesis\n      by (cases \"run_hd f\") (auto simp: e_def)\n  next\n    case False\n    obtain s' s'' where split: \"reaches_on ru_t l_t0 (take (length es) (map fst fs')) s'\"\n      \"ru_t s' = Some (s'', map fst fs' ! (length es))\"\n      using reaches_on_split[OF ft_def(1), where ?i=\"length es\"] False aux(2)\n      by (auto simp: ft_def(3))\n    show ?thesis\n      using reaches_on_inj[OF aux(1) split(1)] aux(2)\n      by (auto simp: ft_def(3) split(2))\n  qed\nqed\n\nlemma vydra_sound_aux:\n  assumes \"msize_fmla \\<phi> \\<le> n\" \"wf_vydra \\<phi> i n v\" \"ru n v = Some (v', t, b)\" \"bounded_future_fmla \\<phi>\" \"wf_fmla \\<phi>\"\n  shows \"wf_vydra \\<phi> (Suc i) n v' \\<and> (\\<exists>es e. reaches_on run_hd init_hd es e \\<and> length es = Suc i) \\<and> t = \\<tau> \\<sigma> i \\<and> b = sat \\<phi> i\"\n  using assms\nproof (induction n \\<phi> arbitrary: i v v' t b rule: run_induct)\n  case (Bool \\<beta> n)\n  then show ?case\n    using reaches_on_run_hd reaches_on_app wf_vydra.intros(3)[OF reaches_on_app refl]\n    by (fastforce elim!: wf_vydra.cases[of _ _ _ \"v\"] split: option.splits)\nnext\n  case (Atom a n)\n  then show ?case\n    using reaches_on_run_hd reaches_on_app wf_vydra.intros(4)[OF reaches_on_app refl]\n    by (fastforce elim!: wf_vydra.cases[of _ _ _ v] split: option.splits)\nnext\n  case (Neg n x)\n  have IH: \"wf_vydra x i n v \\<Longrightarrow> ru n v = Some (v', t, b) \\<Longrightarrow> wf_vydra x (Suc i) n v' \\<and> (\\<exists>es e. reaches_on run_hd init_hd es e \\<and> length es = Suc i) \\<and> t = \\<tau> \\<sigma> i \\<and> b = sat x i\" for v v' t b\n    using Neg(2,5,6)\n    by auto\n  show ?case\n    apply (rule wf_vydra.cases[OF Neg(3)])\n    using Neg(4) IH wf_vydra.intros(5)\n    by (fastforce split: option.splits)+\nnext\n  case (Bin n f x1 x2)\n  have IH1: \"wf_vydra x1 i n v \\<Longrightarrow> ru n v = Some (v', t, b) \\<Longrightarrow> wf_vydra x1 (Suc i) n v' \\<and> (\\<exists>es e. reaches_on run_hd init_hd es e \\<and> length es = Suc i) \\<and> t = \\<tau> \\<sigma> i \\<and> b = sat x1 i\" for v v' t b\n    using Bin(2,6,7)\n    by auto\n  have IH2: \"wf_vydra x2 i n v \\<Longrightarrow> ru n v = Some (v', t, b) \\<Longrightarrow> wf_vydra x2 (Suc i) n v' \\<and> t = \\<tau> \\<sigma> i \\<and> b = sat x2 i\" for v v' t b\n    using Bin(3,6,7)\n    by auto\n  show ?case\n    apply (rule wf_vydra.cases[OF Bin(4)])\n    using Bin(5) IH1 IH2 wf_vydra.intros(6)\n    by (fastforce split: option.splits)+\nnext\n  case (Prev n I phi)\n  show ?case\n  proof (cases i)\n    case 0\n    then show ?thesis\n      using Prev run_hd_sound[OF reaches.intros(1)] wf_vydra.intros(7)[OF _ reaches_on.intros(2)[OF _ reaches_on.intros(1)], where ?i=\"Suc 0\", simplified]\n      by (fastforce split: nat.splits option.splits dest!: reaches_on_NilD elim!: wf_vydra.cases[of _ _ _ v] intro: wf_vydra.intros(1) reaches_on.intros(2)[OF _ reaches_on.intros(1)])\n  next\n    case (Suc j)\n    obtain vphi es sub where v_def: \"v = VYDRA_Prev I vphi sub (Some (\\<tau> \\<sigma> j, sat phi j))\"\n      \"wf_vydra phi i n vphi\" \"reaches_on run_hd init_hd es sub\" \"length es = i\"\n      using Prev(3,4)\n      by (auto simp: Suc elim!: wf_vydra.cases[of _ _ _ v])\n    obtain sub' X where run_sub: \"run_hd sub = Some (sub', (t, X))\"\n      using Prev(4)\n      by (auto simp: v_def(1) Let_def split: option.splits)\n    note reaches_sub' = reaches_on_app[OF v_def(3) run_sub]\n    have t_def: \"t = \\<tau> \\<sigma> (Suc j)\"\n      using reaches_on_run_hd[OF v_def(3) run_sub]\n      by (auto simp: Suc v_def(2,4))\n    show ?thesis\n    proof (cases \"v' = VYDRA_None\")\n      case v'_def: True\n      show ?thesis\n        using Prev(4) v_def(2) reaches_sub'\n        by (auto simp: Suc Let_def v_def(1,4) v'_def run_sub t_def split: option.splits intro: wf_vydra.intros(1))\n    next\n      case False\n      obtain vphi' where ru_vphi: \"ru n vphi = Some (vphi', (\\<tau> \\<sigma> i, sat phi i))\"\n        using Prev(2)[OF v_def(2)] Prev(4,5,6) False\n        by (auto simp: v_def(1) Let_def split: option.splits)\n      have wf': \"wf_vydra phi (Suc (Suc j)) n vphi'\"\n        using Prev(2)[OF v_def(2) ru_vphi] Prev(5,6)\n        by (auto simp: Suc)\n      show ?thesis\n        using Prev(4) wf_vydra.intros(7)[OF wf' reaches_sub'] reaches_sub'\n        by (auto simp: Let_def Suc t_def v_def(1,4) run_sub ru_vphi)\n    qed\n  qed\nnext\n  case (Next n I phi)\n  obtain w sub to es where v_def: \"v = VYDRA_Next I w sub to\" \"wf_vydra phi (length es) n w\"\n    \"reaches_on run_hd init_hd es sub\" \"length es = (case to of None \\<Rightarrow> 0 | _ \\<Rightarrow> Suc i)\"\n    \"case to of None \\<Rightarrow> i = 0 | Some told \\<Rightarrow> told = \\<tau> \\<sigma> i\"\n    using Next(3,4)\n    by (auto elim!: wf_vydra.cases[of _ _ _ v] split: option.splits nat.splits)\n  obtain sub' tnew X where run_sub: \"run_hd sub = Some (sub', (tnew, X))\"\n    using Next(4)\n    by (auto simp: v_def(1) split: option.splits)\n  have tnew_def: \"tnew = \\<tau> \\<sigma> (length es)\"\n    using reaches_on_run_hd[OF v_def(3) run_sub]\n    by auto\n  have aux: ?case if aux_assms: \"wf_vydra phi (Suc i) n w\"\n    \"ru (Suc n) (VYDRA_Next I w sub (Some t0)) = Some (v', t, b)\"\n    \"reaches_on run_hd init_hd es sub\" \"length es = Suc i\" \"t0 = \\<tau> \\<sigma> i\" for w sub t0 es\n    using aux_assms(1,2,5) wf_vydra.intros(2)[OF aux_assms(1)]\n      Next(2)[where ?i=\"Suc i\" and ?v=\"w\"] Next(5,6) reaches_on_run_hd[OF aux_assms(3)]\n      wf_vydra.intros(8)[OF _ reaches_on_app[OF aux_assms(3)], where ?phi=phi and ?i=\"Suc (Suc i)\" and ?n=\"n\"] aux_assms(3)\n    by (auto simp: run_sub aux_assms(4,5) split: option.splits if_splits)\n  show ?case\n  proof (cases to)\n    case None\n    obtain w' z where w_def: \"ru (Suc n) v = ru (Suc n) (VYDRA_Next I w' sub' (Some tnew))\"\n      \"ru n w = Some (w', z)\"\n      using Next(4)\n      by (cases \"ru n w\") (auto simp: v_def(1) run_sub None split: option.splits)\n    have wf: \"wf_vydra phi (Suc i) n w'\"\n      using v_def w_def(2) Next(2,5,6)\n      by (cases z) (auto simp: None intro: wf_vydra.intros(1))\n    show ?thesis\n      using aux[OF wf Next(4)[unfolded w_def(1)] reaches_on_app[OF v_def(3) run_sub]] v_def(4,5) tnew_def\n      by (auto simp: None)\n  next\n    case (Some z)\n    show ?thesis\n      using aux[OF _ _ v_def(3), where ?w=\"w\"] v_def(2,4,5) Next(4)\n      by (auto simp: v_def(1) Some simp del: run.simps)\n  qed\nnext\n  case (Since n I phi psi)\n  obtain vphi vpsi e cphi cpsi cppsi tppsi j es where v_def:\n    \"v = VYDRA_Since I vphi vpsi e cphi cpsi cppsi tppsi\"\n    \"wf_vydra phi i n vphi\" \"wf_vydra psi j n vpsi\" \"j \\<le> i\"\n    \"reaches_on ru_t l_t0 es e\" \"length es = j\" \"\\<And>t. t \\<in> set es \\<Longrightarrow> memL t (\\<tau> \\<sigma> i) I\"\n    \"cphi = i - (case last_before (\\<lambda>k. \\<not>sat phi k) i of None \\<Rightarrow> 0 | Some k \\<Rightarrow> Suc k)\" \"cpsi = i - j\"\n    \"cppsi = (case last_before (sat psi) j of None \\<Rightarrow> None | Some k \\<Rightarrow> Some (i - k))\"\n    \"tppsi = (case last_before (sat psi) j of None \\<Rightarrow> None | Some k \\<Rightarrow> Some (\\<tau> \\<sigma> k))\"\n    using Since(5)\n    by (auto elim: wf_vydra.cases)\n  obtain vphi' b1 where run_vphi: \"ru n vphi = Some (vphi', t, b1)\"\n    using Since(6)\n    by (auto simp: v_def(1) Let_def split: option.splits)\n  obtain fs f where wf_vphi': \"wf_vydra phi (Suc i) n vphi'\"\n    and reaches_Suc_i: \"reaches_on run_hd init_hd fs f\" \"length fs = Suc i\"\n    and t_def: \"t = \\<tau> \\<sigma> i\" and b1_def: \"b1 = sat phi i\"\n    using Since(3)[OF v_def(2) run_vphi] Since(7,8)\n    by auto\n  note ru_t_Some = ru_t_Some[OF reaches_Suc_i]\n  define loop_inv where \"loop_inv = (\\<lambda>(vpsi, e, cpsi :: nat, cppsi, tppsi).\n    let j = Suc i - cpsi in cpsi \\<le> Suc i \\<and>\n    wf_vydra psi j n vpsi \\<and> (\\<exists>es. reaches_on ru_t l_t0 es e \\<and> length es = j \\<and> (\\<forall>t \\<in> set es. memL t (\\<tau> \\<sigma> i) I)) \\<and>\n    cppsi = (case last_before (sat psi) j of None \\<Rightarrow> None | Some k \\<Rightarrow> Some (Suc i - k)) \\<and>\n    tppsi = (case last_before (sat psi) j of None \\<Rightarrow> None | Some k \\<Rightarrow> Some (\\<tau> \\<sigma> k)))\"\n  define loop_init where \"loop_init = (vpsi, e, Suc cpsi, map_option Suc cppsi, tppsi)\"\n  obtain vpsi' e' cpsi' cppsi' tppsi' where loop_def: \"while_break (while_since_cond I t) (while_since_body run_hd (ru n)) loop_init =\n    Some (vpsi', e', cpsi', cppsi', tppsi')\"\n    using Since(6)\n    by (auto simp: v_def(1) run_vphi loop_init_def Let_def split: option.splits)\n  have j_def: \"j = i - cpsi\"\n    using v_def(4,9)\n    by auto\n  have \"cpsi \\<le> i\"\n    using v_def(9)\n    by auto\n  then have loop_inv_init: \"loop_inv loop_init\"\n    using v_def(3,5,6,7,10,11) last_before_Some\n    by (fastforce simp: loop_inv_def loop_init_def Let_def j_def split: option.splits)\n  have wf_loop: \"wf {(s', s). loop_inv s \\<and> while_since_cond I t s \\<and> Some s' = while_since_body run_hd (ru n) s}\"\n    by (auto intro: wf_subset[OF wf_since])\n  have step_loop: \"loop_inv s'\" if loop_assms: \"loop_inv s\" \"while_since_cond I t s\" \"while_since_body run_hd (ru n) s = Some s'\" for s s'\n  proof -\n    obtain vpsi e cpsi cppsi tppsi where s_def: \"s = (vpsi, e, cpsi, cppsi, tppsi)\"\n      by (cases s) auto\n    define j where \"j = Suc i - cpsi\"\n    obtain es where loop_before: \"cpsi \\<le> Suc i\" \"wf_vydra psi j n vpsi\"\n      \"reaches_on ru_t l_t0 es e\" \"length es = j\" \"\\<And>t. t \\<in> set es \\<Longrightarrow> memL t (\\<tau> \\<sigma> i) I\"\n      \"cppsi = (case last_before (sat psi) j of None \\<Rightarrow> None | Some k \\<Rightarrow> Some (Suc i - k))\"\n      \"tppsi = (case last_before (sat psi) j of None \\<Rightarrow> None | Some k \\<Rightarrow> Some (\\<tau> \\<sigma> k))\"\n      using loop_assms(1)\n      by (auto simp: s_def j_def loop_inv_def Let_def)\n    obtain tt h where tt_def: \"read_t e = Some tt\" \"memL tt t I\" \"e = Some (h, tt)\"\n      using ru_t_Some[OF loop_before(3)] loop_before(4) loop_assms(2)\n      by (cases e) (fastforce simp: while_since_cond_def s_def j_def split: option.splits)+\n    obtain e' where e'_def: \"reaches_on ru_t l_t0 (es @ [tt]) e'\" \"ru_t e = Some (e', tt)\"\n      using reaches_on_app[OF loop_before(3)] tt_def(1)\n      by (cases \"run_hd h\") (auto simp: tt_def(3))\n    obtain vpsi' t' b' where run_vpsi: \"ru n vpsi = Some (vpsi', (t', b'))\"\n      using loop_assms(3)\n      by (auto simp: while_since_body_def s_def Let_def split: option.splits)\n    have wf_psi': \"wf_vydra psi (Suc j) n vpsi'\" and t'_def: \"t' = \\<tau> \\<sigma> j\" and b'_def: \"b' = sat psi j\"\n      using Since(4)[OF loop_before(2) run_vpsi] Since(7,8)\n      by auto\n    define j' where j'_def: \"j' = Suc i - (cpsi - Suc 0)\"\n    have cpsi_pos: \"cpsi > 0\"\n      using loop_assms(2)\n      by (auto simp: while_since_cond_def s_def)\n    have j'_j: \"j' = Suc j\"\n      using loop_before(1) cpsi_pos\n      by (auto simp: j'_def j_def)\n    define cppsi' where \"cppsi' = (if b' then Some cpsi else cppsi)\"\n    define tppsi' where \"tppsi' = (if b' then Some t' else tppsi)\"\n    have cppsi': \"cppsi' = (case last_before (sat psi) j' of None \\<Rightarrow> None | Some k \\<Rightarrow> Some (Suc i - k))\"\n      using cpsi_pos loop_before(1)\n      by (auto simp: cppsi'_def b'_def j'_j loop_before(6) j_def)\n    have tppsi': \"tppsi' = (case last_before (sat psi) j' of None \\<Rightarrow> None | Some k \\<Rightarrow> Some (\\<tau> \\<sigma> k))\"\n      by (auto simp: tppsi'_def t'_def b'_def j'_j loop_before(7) split: option.splits)\n    have s'_def: \"s' = (vpsi', fst (the (ru_t e)), cpsi - Suc 0, cppsi', tppsi')\"\n      using loop_assms(3)\n      by (auto simp: while_since_body_def s_def run_vpsi cppsi'_def tppsi'_def)\n    show ?thesis\n      using loop_before(1,4,5) tt_def(2) wf_psi'[folded j'_j] cppsi' tppsi' e'_def(1)\n      by (fastforce simp: loop_inv_def s'_def j'_def[symmetric] e'_def(2) j'_j t_def)\n  qed\n  have loop: \"loop_inv (vpsi', e', cpsi', cppsi', tppsi')\" \"\\<not>while_since_cond I t (vpsi', e', cpsi', cppsi', tppsi')\"\n    using while_break_sound[where ?P=\"loop_inv\" and ?Q=\"\\<lambda>s. loop_inv s \\<and> \\<not>while_since_cond I t s\", OF step_loop _ wf_loop loop_inv_init]\n    by (auto simp: loop_def)\n  define cphi' where \"cphi' = (if b1 then Suc cphi else 0)\"\n  have v'_def: \"v' = VYDRA_Since I vphi' vpsi' e' cphi' cpsi' cppsi' tppsi'\"\n    and b_def: \"b = (case cppsi' of None \\<Rightarrow> False | Some k \\<Rightarrow> k - 1 \\<le> cphi' \\<and> memR (the tppsi') t I)\"\n    using Since(6)\n    by (auto simp: v_def(1) run_vphi loop_init_def[symmetric] loop_def cphi'_def Let_def split: option.splits)\n  have read_t_e': \"cpsi' > 0 \\<Longrightarrow> read_t e' = None \\<Longrightarrow> False\"\n    using loop(1) ru_t_Some[where ?e=e'] run_t_read\n    by (fastforce simp: loop_inv_def Let_def)\n  define j' where \"j' = Suc i - cpsi'\"\n  have wf_vpsi': \"wf_vydra psi j' n vpsi'\" and cpsi'_le_Suc_i: \"cpsi' \\<le> Suc i\"\n    and cppsi'_def: \"cppsi' = (case last_before (sat psi) j' of None \\<Rightarrow> None | Some k \\<Rightarrow> Some (Suc i - k))\"\n    and tppsi'_def: \"tppsi' = (case last_before (sat psi) j' of None \\<Rightarrow> None | Some k \\<Rightarrow> Some (\\<tau> \\<sigma> k))\"\n    using loop(1)\n    by (auto simp: loop_inv_def j'_def[symmetric])\n  obtain es' where es'_def: \"reaches_on ru_t l_t0 es' e'\" \"length es' = j'\" \"\\<And>t. t \\<in> set es' \\<Longrightarrow> memL t (\\<tau> \\<sigma> i) I\"\n    using loop(1)\n    by (auto simp: loop_inv_def j'_def[symmetric])\n  have wf_v': \"wf_vydra (Since phi I psi) (Suc i) (Suc n) v'\"\n    and cphi'_sat: \"cphi' = Suc i - (case last_before (\\<lambda>k. \\<not>sat phi k) (Suc i) of None \\<Rightarrow> 0 | Some k \\<Rightarrow> Suc k)\"\n    using cpsi'_le_Suc_i last_before_Some es'_def(3) memL_mono'[OF _ \\<tau>_mono[of i \"Suc i\" \\<sigma>]]\n    by (force simp: v'_def cppsi'_def tppsi'_def j'_def cphi'_def b1_def v_def(8) split: option.splits\n        intro!: wf_vydra.intros(9)[OF wf_vphi' wf_vpsi' _ es'_def(1-2)])+\n  have \"j' = Suc i \\<or> \\<not>memL (\\<tau> \\<sigma> j') (\\<tau> \\<sigma> i) I\"\n    using loop(2) j'_def read_t_e' ru_t_tau[OF es'_def(1)] read_t_run[where ?run_hd=run_hd]\n    by (fastforce simp: while_since_cond_def es'_def(2) t_def split: option.splits)\n  then have tau_k_j': \"k \\<le> i \\<Longrightarrow> memL (\\<tau> \\<sigma> k) (\\<tau> \\<sigma> i) I \\<longleftrightarrow> k < j'\" for k\n    using ru_t_tau_in[OF es'_def(1)] es'_def(3) \\<tau>_mono[of j' k \\<sigma>] memL_mono\n    by (fastforce simp: es'_def(2) in_set_conv_nth)\n  have b_sat: \"b = sat (Since phi I psi) i\"\n  proof (rule iffI)\n    assume b: \"b\"\n    obtain m where m_def: \"last_before (sat psi) j' = Some m\" \"i - m \\<le> cphi'\" \"memR (\\<tau> \\<sigma> m) (\\<tau> \\<sigma> i) I\"\n      using b\n      by (auto simp: b_def t_def cppsi'_def tppsi'_def split: option.splits)\n    note aux = last_before_Some[OF m_def(1)]\n    have mem: \"mem (\\<tau> \\<sigma> m) (\\<tau> \\<sigma> i) I\"\n      using m_def(3) tau_k_j' aux\n      by (auto simp: mem_def j'_def)\n    have sat_phi: \"sat phi x\" if \"m < x\" \"x \\<le> i\" for x\n      using m_def(2) that le_neq_implies_less\n      by (fastforce simp: cphi'_sat dest: last_before_None last_before_Some split: option.splits if_splits)\n    show \"sat (Since phi I psi) i\"\n      using aux mem sat_phi\n      by (auto simp: j'_def intro!: exI[of _ m])\n  next\n    assume sat: \"sat (Since phi I psi) i\"\n    then obtain k where k_def: \"k \\<le> i\" \"mem (\\<tau> \\<sigma> k) (\\<tau> \\<sigma> i) I\" \"sat psi k\" \"\\<And>k'. k < k' \\<and> k' \\<le> i \\<Longrightarrow> sat phi k'\"\n      by auto\n    have k_j': \"k < j'\"\n      using tau_k_j'[OF k_def(1)] k_def(2)\n      by (auto simp: mem_def)\n    obtain m where m_def: \"last_before (sat psi) j' = Some m\"\n      using last_before_None[where ?P=\"sat psi\" and ?n=j' and ?m=k] k_def(3) k_j'\n      by (cases \"last_before (sat psi) j'\") auto\n    have cppsi'_Some: \"cppsi' = Some (Suc i - m)\"\n      by (auto simp: cppsi'_def m_def)\n    have tppsi'_Some: \"tppsi' = Some (\\<tau> \\<sigma> m)\"\n      by (auto simp: tppsi'_def m_def)\n    have m_k: \"k \\<le> m\"\n      using last_before_Some[OF m_def] k_def(3) k_j'\n      by auto\n    have tau_i_m: \"memR (\\<tau> \\<sigma> m) (\\<tau> \\<sigma> i) I\"\n      using \\<tau>_mono[OF m_k, where ?s=\\<sigma>] memR_mono k_def(2)\n      by (auto simp: mem_def)\n    have \"i - m \\<le> cphi'\"\n      using k_def(1) k_def(4) m_k\n      apply (cases \"k = i\")\n       apply (auto simp: cphi'_sat b1_def dest!: last_before_Some split: option.splits)\n      apply (metis diff_le_mono2 le_neq_implies_less le_trans less_imp_le_nat nat_le_linear)\n      done\n    then show \"b\"\n      using tau_i_m\n      by (auto simp: b_def t_def cppsi'_Some tppsi'_Some)\n  qed\n  show ?case\n    using wf_v' reaches_Suc_i\n    by (auto simp: t_def b_sat)\nnext\n  case (Until n I phi psi)\n  obtain \"back\" vphi vpsi front c z es es' j where v_def:\n    \"v = VYDRA_Until I back vphi vpsi front c z\"\n    \"wf_vydra phi j n vphi\" \"wf_vydra psi j n vpsi\" \"i \\<le> j\"\n    \"reaches_on ru_t l_t0 es back\" \"length es = i\"\n    \"reaches_on ru_t l_t0 es' front\" \"length es' = j\" \"\\<And>t. t \\<in> set es' \\<Longrightarrow> memR (\\<tau> \\<sigma> i) t I\"\n    \"c = j - i\" \"z = (case j of 0 \\<Rightarrow> None | Suc k \\<Rightarrow> Some (\\<tau> \\<sigma> k, sat phi k, sat psi k))\"\n    \"\\<And>k. k \\<in> {i..<j - 1} \\<Longrightarrow> sat phi k \\<and> (memL (\\<tau> \\<sigma> i) (\\<tau> \\<sigma> k) I \\<longrightarrow> \\<not>sat psi k)\"\n    using Until(5)\n    by (auto elim: wf_vydra.cases)\n  define loop_init where \"loop_init = (vphi, vpsi, front, c, z)\"\n  obtain back' vphi' vpsi' epsi' c' zo' zt zb1 zb2 where run_back: \"ru_t back = Some (back', t)\"\n    and loop_def: \"while_break (while_until_cond I t) (while_until_body run_hd (ru n)) loop_init = Some (vphi', vpsi', epsi', c', zo')\"\n    and v'_def: \"v' = VYDRA_Until I back' vphi' vpsi' epsi' (c' - 1) zo'\"\n    and c'_pos: \"\\<not>c' = 0\"\n    and zo'_Some: \"zo' = Some (zt, (zb1, zb2))\"\n    and b_def: \"b = (zb2 \\<and> memL t zt I)\"\n    using Until(6)\n    apply (auto simp: v_def(1) Let_def loop_init_def[symmetric] split: option.splits nat.splits if_splits)\n    done\n  define j' where \"j' = i + c'\"\n  have j_eq: \"j = i + c\"\n    using v_def(4)\n    by (auto simp: v_def(10))\n  have t_def: \"t = \\<tau> \\<sigma> i\"\n    using ru_t_tau[OF v_def(5) run_back]\n    by (auto simp: v_def(6))\n  define loop_inv where \"loop_inv = (\\<lambda>(vphi, vpsi, epsi, c, zo).\n    let j = i + c in\n    wf_vydra phi j n vphi \\<and> wf_vydra psi j n vpsi \\<and>\n    (\\<exists>gs. reaches_on ru_t l_t0 gs epsi \\<and> length gs = j \\<and> (\\<forall>t. t \\<in> set gs \\<longrightarrow> memR (\\<tau> \\<sigma> i) t I)) \\<and>\n    zo = (case j of 0 \\<Rightarrow> None | Suc k \\<Rightarrow> Some (\\<tau> \\<sigma> k, sat phi k, sat psi k)) \\<and>\n    (\\<forall>k. k \\<in> {i..<j - 1} \\<longrightarrow> sat phi k \\<and> (memL (\\<tau> \\<sigma> i) (\\<tau> \\<sigma> k) I \\<longrightarrow> \\<not>sat psi k)))\"\n  have loop_inv_init: \"loop_inv loop_init\"\n    using v_def(2,3,7,9,12)\n    by (auto simp: loop_inv_def loop_init_def j_eq[symmetric] v_def(8,11))\n  have loop_step: \"loop_inv s'\" if loop_assms: \"loop_inv s\" \"while_until_cond I t s\" \"while_until_body run_hd (ru n) s = Some s'\" for s s'\n  proof -\n    obtain vphi_cur vpsi_cur epsi_cur c_cur zo_cur where s_def: \"s = (vphi_cur, vpsi_cur, epsi_cur, c_cur, zo_cur)\"\n      by (cases s) auto\n    define j_cur where \"j_cur = i + c_cur\"\n    obtain epsi'_cur t'_cur vphi'_cur tphi_cur bphi_cur vpsi'_cur tpsi_cur bpsi_cur where\n      run_epsi: \"ru_t epsi_cur = Some (epsi'_cur, t'_cur)\"\n      and run_vphi: \"ru n vphi_cur = Some (vphi'_cur, (tphi_cur, bphi_cur))\"\n      and run_vpsi: \"ru n vpsi_cur = Some (vpsi'_cur, (tpsi_cur, bpsi_cur))\"\n      using loop_assms(2,3)\n      apply (auto simp: while_until_cond_def while_until_body_def s_def split: option.splits dest: read_t_run[where ?run_hd=run_hd])\n      done\n    have wf: \"wf_vydra phi j_cur n vphi_cur\" \"wf_vydra psi j_cur n vpsi_cur\"\n      and zo_cur_def: \"zo_cur = (case j_cur of 0 \\<Rightarrow> None | Suc k \\<Rightarrow> Some (\\<tau> \\<sigma> k, sat phi k, sat psi k))\"\n      using loop_assms(1)\n      by (auto simp: loop_inv_def s_def j_cur_def[symmetric])\n    have wf': \"wf_vydra phi (Suc j_cur) n vphi'_cur\" \"tphi_cur = \\<tau> \\<sigma> j_cur\" \"bphi_cur = sat phi j_cur\"\n      \"wf_vydra psi (Suc j_cur) n vpsi'_cur\" \"tpsi_cur = \\<tau> \\<sigma> j_cur\" \"bpsi_cur = sat psi j_cur\"\n      using Until(3)[OF wf(1) run_vphi] Until(4)[OF wf(2) run_vpsi] Until(7,8)\n      apply (auto)\n      done\n    have s'_def: \"s' = (vphi'_cur, vpsi'_cur, epsi'_cur, Suc c_cur, Some (t'_cur, (bphi_cur, bpsi_cur)))\"\n      using loop_assms(3)\n      by (auto simp: while_until_body_def s_def run_epsi run_vphi run_vpsi)\n    obtain gs_cur where gs_cur_def: \"reaches_on ru_t l_t0 gs_cur epsi_cur\"\n      \"length gs_cur = j_cur\" \"\\<And>t. t \\<in> set gs_cur \\<Longrightarrow> memR (\\<tau> \\<sigma> i) t I\"\n      using loop_assms(1)\n      by (auto simp: loop_inv_def s_def j_cur_def[symmetric])\n    have t'_cur_def: \"t'_cur = \\<tau> \\<sigma> j_cur\"\n      using ru_t_tau[OF gs_cur_def(1) run_epsi]\n      by (auto simp: gs_cur_def(2))\n    have t'_cur_right_I: \"memR t t'_cur I\"\n      using loop_assms(2) run_t_read[OF run_epsi]\n      by (auto simp: while_until_cond_def s_def)\n    have c_cur_zero: \"c_cur = 0 \\<Longrightarrow> j_cur = i\"\n      by (auto simp: j_cur_def)\n    have \"k \\<in> {i..<Suc j_cur - 1} \\<Longrightarrow> sat phi k \\<and> (memL (\\<tau> \\<sigma> i) (\\<tau> \\<sigma> k) I \\<longrightarrow> \\<not>sat psi k)\" for k\n      using loop_assms(1,2)\n      by (cases \"k = j_cur - Suc 0\") (auto simp: while_until_cond_def loop_inv_def j_cur_def[symmetric] zo_cur_def s_def until_ready_def t_def split: nat.splits dest: c_cur_zero)\n    then show ?thesis\n      using wf' t'_cur_right_I\n      using reaches_on_app[OF gs_cur_def(1) run_epsi] gs_cur_def(2,3)\n      by (auto simp: loop_inv_def s'_def j_cur_def[symmetric] t_def t'_cur_def intro!: exI[of _ \"gs_cur @ [t'_cur]\"])\n  qed\n  have wf_loop: \"wf {(s', s). loop_inv s \\<and> while_until_cond I t s \\<and> Some s' = while_until_body run_hd (ru n) s}\"\n  proof -\n    obtain m where m_def: \"\\<not>\\<tau> \\<sigma> m \\<le> \\<tau> \\<sigma> i + right I\"\n      using ex_lt_\\<tau>[where ?x=\"right I\" and ?s=\\<sigma>] Until(7)\n      by auto\n    define X where \"X = {(s', s). loop_inv s \\<and> while_until_cond I t s \\<and> Some s' = while_until_body run_hd (ru n) s}\"\n    have \"memR t (\\<tau> \\<sigma> (i + c)) I \\<Longrightarrow> i + c < m\" for c\n      using m_def order_trans[OF \\<tau>_mono[where ?i=m and ?j=\"i + c\" and ?s=\\<sigma>]]\n      by (fastforce simp: t_def dest!: memR_dest)\n    then have \"X \\<subseteq> measure (\\<lambda>(vphi, vpsi, epsi, c, zo). m - c)\"\n      by (fastforce simp: X_def while_until_cond_def while_until_body_def loop_inv_def Let_def split: option.splits\n          dest!: read_t_run[where ?run_hd=run_hd] dest: ru_t_tau)\n    then show ?thesis\n      using wf_subset\n      by (auto simp: X_def[symmetric])\n  qed\n  have loop: \"loop_inv (vphi', vpsi', epsi', c', zo')\" \"\\<not>while_until_cond I t (vphi', vpsi', epsi', c', zo')\"\n    using while_break_sound[where ?Q=\"\\<lambda>s. loop_inv s \\<and> \\<not>while_until_cond I t s\", OF _ _ wf_loop loop_inv_init] loop_step\n    by (auto simp: loop_def)\n  have tau_right_I: \"k < j' \\<Longrightarrow> memR (\\<tau> \\<sigma> i) (\\<tau> \\<sigma> k) I\" for k\n    using loop(1) ru_t_tau_in\n    by (auto simp: loop_inv_def j'_def[symmetric] in_set_conv_nth)\n  have read_t_epsi': \"read_t epsi' = Some et \\<Longrightarrow> et = \\<tau> \\<sigma> j'\" for et\n    using loop(1) ru_t_tau\n    by (fastforce simp: loop_inv_def Let_def j'_def dest!: read_t_run[where ?run_hd=run_hd])\n  have end_cond: \"until_ready I t c' zo' \\<or> \\<not>(memR (\\<tau> \\<sigma> i) (\\<tau> \\<sigma> j') I)\"\n    unfolding t_def[symmetric]\n    using Until(6) c'_pos loop(2)[unfolded while_until_cond_def]\n    by (auto simp: until_ready_def v_def(1) run_back loop_init_def[symmetric] loop_def zo'_Some split: if_splits option.splits nat.splits dest: read_t_epsi')\n  have Suc_i_le_j': \"Suc i \\<le> j'\" and c'_j': \"c' - Suc 0 = j' - Suc i\"\n    using end_cond c'_pos\n    by (auto simp: until_ready_def j'_def split: nat.splits)\n  have zo'_def: \"zo' = (case j' of 0 \\<Rightarrow> None | Suc k \\<Rightarrow> Some (\\<tau> \\<sigma> k, sat phi k, sat psi k))\"\n    and sat_phi: \"k \\<in> {i..<j' - 1} \\<Longrightarrow> sat phi k\"\n    and not_sat_psi: \"k \\<in> {i..<j' - 1} \\<Longrightarrow> memL (\\<tau> \\<sigma> i) (\\<tau> \\<sigma> k) I \\<Longrightarrow> \\<not>sat psi k\" for k\n    using loop(1)\n    by (auto simp: loop_inv_def j'_def[symmetric])\n  have b_sat: \"b = sat (Until phi I psi) i\"\n  proof (rule iffI)\n    assume b: \"b\"\n    have mem: \"mem (\\<tau> \\<sigma> i) (\\<tau> \\<sigma> (j' - Suc 0)) I\"\n      using b zo'_def tau_right_I[where ?k=\"j' - 1\"]\n      by (auto simp: mem_def b_def t_def zo'_Some split: nat.splits)\n    have sat_psi: \"sat psi (j' - 1)\"\n      using b zo'_def\n      by (auto simp: b_def zo'_Some split: nat.splits)\n    show \"sat (Until phi I psi) i\"\n      using Suc_i_le_j' mem sat_psi sat_phi\n      by (auto intro!: exI[of _ \"j' - 1\"])\n  next\n    assume \"sat (Until phi I psi) i\"\n    then obtain k where k_def: \"i \\<le> k\" \"mem (\\<tau> \\<sigma> i) (\\<tau> \\<sigma> k) I\" \"sat psi k\" \"\\<forall>m \\<in> {i..<k}. sat phi m\"\n      by auto\n    define X where \"X = {m \\<in> {i..k}. memL (\\<tau> \\<sigma> i) (\\<tau> \\<sigma> m) I \\<and> sat psi m}\"\n    have fin_X: \"finite X\" and X_nonempty: \"X \\<noteq> {}\" and k_X: \"k \\<in> X\"\n      using k_def\n      by (auto simp: X_def mem_def)\n    define km where \"km = Min X\"\n    note aux = Min_in[OF fin_X X_nonempty, folded km_def]\n    have km_def: \"i \\<le> km\" \"km \\<le> k\" \"memL (\\<tau> \\<sigma> i) (\\<tau> \\<sigma> km) I\" \"sat psi km\" \"\\<forall>m \\<in> {i..<km}. sat phi m\"\n      \"\\<forall>m \\<in> {i..<km}. memL (\\<tau> \\<sigma> i) (\\<tau> \\<sigma> m) I \\<longrightarrow> \\<not>sat psi m\"\n      using aux Min_le[OF fin_X, folded km_def] k_def(4)\n      by (fastforce simp: X_def)+\n    have j'_le_km: \"j' - 1 \\<le> km\"\n      using not_sat_psi[OF _ km_def(3)] km_def(1,4)\n      by fastforce\n    show \"b\"\n    proof (cases \"j' - 1 < km\")\n      case True\n      have \"until_ready I t c' zo'\"\n        using end_cond True km_def(2) k_def(2) memR_mono'[OF _ \\<tau>_mono[where ?i=j' and ?j=k and ?s=\\<sigma>]]\n        by (auto simp: mem_def)\n      then show ?thesis\n        using c'_pos zo'_def km_def(5) Suc_i_le_j' True\n        by (auto simp: until_ready_def zo'_Some b_def split: nat.splits)\n    next\n      case False\n      have km_j': \"km = j' - 1\"\n        using j'_le_km False\n        by auto\n      show ?thesis\n        using c'_pos zo'_def km_def(3,4)\n        by (auto simp: zo'_Some b_def km_j' t_def split: nat.splits)\n    qed\n  qed\n  obtain gs where gs_def: \"reaches_on ru_t l_t0 gs epsi'\" \"length gs = j'\"\n    \"\\<And>t. t \\<in> set gs \\<Longrightarrow> memR (\\<tau> \\<sigma> i) t I\"\n    using loop(1)\n    by (auto simp: loop_inv_def j'_def[symmetric])\n  note aux = \\<tau>_mono[where ?s=\\<sigma> and ?i=i and ?j=\"Suc i\"]\n  have wf_v': \"wf_vydra (Until phi I psi) (Suc i) (Suc n) v'\"\n    unfolding v'_def\n    apply (rule wf_vydra.intros(10)[where ?j=j' and ?es'=gs])\n    using loop(1) reaches_on_app[OF v_def(5) run_back] Suc_i_le_j' c'_j' memL_mono[OF _ aux] memR_mono[OF _ aux] gs_def\n    by (auto simp: loop_inv_def j'_def[symmetric] v_def(6,8))\n  show ?case\n    using wf_v' ru_t_event[OF v_def(5) refl run_back]\n    by (auto simp: b_sat v_def(6))\nnext\n  case (MatchP n I r)\n  have IH: \"x \\<in> set (collect_subfmlas r []) \\<Longrightarrow> wf_vydra x j n v \\<Longrightarrow> ru n v = Some (v', t, b) \\<Longrightarrow> wf_vydra x (Suc j) n v' \\<and> t = \\<tau> \\<sigma> j \\<and> b = sat x j\" for x j v v' t b\n    using MatchP(2,1,5,6) le_trans[OF collect_subfmlas_msize]\n    using bf_collect_subfmlas[where ?r=\"r\" and ?phis=\"[]\"]\n    by (fastforce simp: collect_subfmlas_atms[where ?phis=\"[]\", simplified, symmetric])\n  have \"reaches_on (ru n) (su n phi) vs v \\<Longrightarrow> wf_vydra phi (length vs) n v\" if phi: \"phi \\<in> set (collect_subfmlas r [])\" for phi vs v\n    apply (induction vs arbitrary: v rule: rev_induct)\n    using MatchP(1) wf_vydra_sub collect_subfmlas_msize[OF phi]\n     apply (auto elim!: reaches_on.cases)[1]\n    using IH[OF phi]\n    apply (fastforce dest!: reaches_on_split_last)\n    done\n  then have wf: \"reaches_on (run_subs (ru n)) (map (su n) (collect_subfmlas r [])) bs s \\<Longrightarrow> j < length (collect_subfmlas r []) \\<Longrightarrow>\n    wf_vydra (collect_subfmlas r [] ! j) (length bs) n (s ! j)\" for bs s j\n    using reach_run_subs_run\n    by (fastforce simp: in_set_conv_nth)\n  let ?qf = \"state_cnt r\"\n  let ?transs = \"iarray_of_list (build_nfa_impl r (0, ?qf, []))\"\n  define args where \"args = init_args ({0}, NFA.delta' ?transs ?qf, NFA.accept' ?transs ?qf) (ru_t, read_t) (run_subs (ru n))\"\n  interpret MDL_window \\<sigma> r l_t0 \"map (su n) (collect_subfmlas r [])\" args\n    using bs_sat[where ?r=r and ?n=n, OF _ wf _ reach_run_subs_len[where ?n=n]] IH run_t_read[of run_hd]\n      read_t_run[of _ _ run_hd] ru_t_tau MatchP(5) collect_subfmlas_atms[where ?phis=\"[]\"]\n    unfolding args_def iarray_of_list_def\n    by unfold_locales auto\n  obtain w xs where w_def: \"v = VYDRA_MatchP I ?transs ?qf w\"\n    \"valid_window_matchP args I l_t0 (map (su n) (collect_subfmlas r [])) xs i w\"\n    using MatchP(3,4)\n    by (auto simp: args_def elim!: wf_vydra.cases[of _ _ _ v])\n  obtain tj' t' sj' bs where somes: \"w_run_t args (w_tj w) = Some (tj', t')\"\n   \"w_run_sub args (w_sj w) = Some (sj', bs)\"\n   using MatchP(4)\n   by (auto simp: w_def(1) adv_end_def args_def Let_def split: option.splits prod.splits)\n  obtain w' where w'_def: \"eval_mP I w = Some ((\\<tau> \\<sigma> i, sat (MatchP I r) i), w')\"\n    \"t' = \\<tau> \\<sigma> i\" \"valid_matchP I l_t0 (map (su n) (collect_subfmlas r [])) (xs @ [(t', bs)]) (Suc i) w'\"\n    using valid_eval_matchP[OF w_def(2) somes] MatchP(6)\n    by auto\n  have v'_def: \"v' = VYDRA_MatchP I ?transs ?qf w'\" \"(t, b) = (\\<tau> \\<sigma> i, sat (MatchP I r) i)\"\n    using MatchP(4)\n    by (auto simp: w_def(1) args_def[symmetric] w'_def(1) simp del: eval_matchP.simps init_args.simps)\n  have len_xs: \"length xs = i\"\n    using w'_def(3)\n    by (auto simp: valid_window_matchP_def)\n  have \"\\<exists>es e. reaches_on run_hd init_hd es e \\<and> length es = Suc i\"\n    using ru_t_event valid_window_matchP_reach_tj[OF w_def(2)] somes(1) len_xs\n    by (fastforce simp: args_def)\n  then show ?case\n    using MatchP(1) v'_def(2)  w'_def(3)\n    by (auto simp: v'_def(1) args_def[symmetric] simp del: init_args.simps intro!: wf_vydra.intros(11))\nnext\n  case (MatchF n I r)\n  have IH: \"x \\<in> set (collect_subfmlas r []) \\<Longrightarrow> wf_vydra x j n v \\<Longrightarrow> ru n v = Some (v', t, b) \\<Longrightarrow> wf_vydra x (Suc j) n v' \\<and> t = \\<tau> \\<sigma> j \\<and> b = sat x j\" for x j v v' t b\n    using MatchF(2,1,5,6) le_trans[OF collect_subfmlas_msize]\n    using bf_collect_subfmlas[where ?r=\"r\" and ?phis=\"[]\"]\n    by (fastforce simp: collect_subfmlas_atms[where ?phis=\"[]\", simplified, symmetric])\n  have \"reaches_on (ru n) (su n phi) vs v \\<Longrightarrow> wf_vydra phi (length vs) n v\" if phi: \"phi \\<in> set (collect_subfmlas r [])\" for phi vs v\n    apply (induction vs arbitrary: v rule: rev_induct)\n    using MatchF(1) wf_vydra_sub collect_subfmlas_msize[OF phi]\n     apply (auto elim!: reaches_on.cases)[1]\n    using IH[OF phi]\n    apply (fastforce dest!: reaches_on_split_last)\n    done\n  then have wf: \"reaches_on (run_subs (ru n)) (map (su n) (collect_subfmlas r [])) bs s \\<Longrightarrow> j < length (collect_subfmlas r []) \\<Longrightarrow>\n    wf_vydra (collect_subfmlas r [] ! j) (length bs) n (s ! j)\" for bs s j\n    using reach_run_subs_run\n    by (fastforce simp: in_set_conv_nth)\n  let ?qf = \"state_cnt r\"\n  let ?transs = \"iarray_of_list (build_nfa_impl r (0, ?qf, []))\"\n  define args where \"args = init_args ({0}, NFA.delta' ?transs ?qf, NFA.accept' ?transs ?qf) (ru_t, read_t) (run_subs (ru n))\"\n  interpret MDL_window \\<sigma> r l_t0 \"map (su n) (collect_subfmlas r [])\" args\n    using bs_sat[where ?r=r and ?n=n, OF _ wf _ reach_run_subs_len[where ?n=n]] IH run_t_read[of run_hd]\n      read_t_run[of _ _ run_hd] ru_t_tau MatchF(5) collect_subfmlas_atms[where ?phis=\"[]\"]\n    unfolding args_def iarray_of_list_def\n    by unfold_locales auto\n  obtain w xs where w_def: \"v = VYDRA_MatchF I ?transs ?qf w\"\n    \"valid_window_matchF args I l_t0 (map (su n) (collect_subfmlas r [])) xs i w\"\n    using MatchF(3,4)\n    by (auto simp: args_def elim!: wf_vydra.cases[of _ _ _ v])\n  obtain w' rho' where w'_def: \"eval_mF I w = Some ((t, b), w')\" \"valid_matchF I l_t0 (map (su n) (collect_subfmlas r [])) rho' (Suc i) w'\" \"t = \\<tau> \\<sigma> i\" \"b = sat (MatchF I r) i\"\n    using valid_eval_matchF_sound[OF w_def(2)] MatchF(4,5,6)\n    by (fastforce simp: w_def(1) args_def[symmetric] simp del: eval_matchF.simps init_args.simps split: option.splits)\n  have v'_def: \"v' = VYDRA_MatchF I ?transs ?qf w'\"\n    using MatchF(4)\n    by (auto simp: w_def(1) args_def[symmetric] w'_def(1) simp del: eval_matchF.simps init_args.simps)\n  obtain w_ti' ti where ru_w_ti: \"ru_t (w_ti w) = Some (w_ti', ti)\"\n    using MatchF(4) read_t_run\n    by (auto simp: w_def(1) args_def split: option.splits)\n  have \"\\<exists>es e. reaches_on run_hd init_hd es e \\<and> length es = Suc i\"\n    using w_def(2) ru_t_event[OF _ refl ru_w_ti, where ?ts=\"take (w_i w) (map fst xs)\"]\n    by (auto simp: valid_window_matchF_def args_def)\n  then show ?case\n    using MatchF(1) w'_def(2)\n    by (auto simp: v'_def(1) args_def[symmetric] w'_def(3,4) simp del: init_args.simps intro!: wf_vydra.intros(12))\nqed\n\nlemma reaches_ons_run_lD: \"reaches_on (run_subs (ru n)) vs ws vs' \\<Longrightarrow>\n  length vs = length vs'\"\n  by (induction vs ws vs' rule: reaches_on_rev_induct)\n     (auto simp: run_subs_def Let_def split: option.splits if_splits)\n\nlemma reaches_ons_run_vD: \"reaches_on (run_subs (ru n)) vs ws vs' \\<Longrightarrow>\n  i < length vs \\<Longrightarrow> (\\<exists>ys. reaches_on (ru n) (vs ! i) ys (vs' ! i) \\<and> length ys = length ws)\"\nproof (induction vs ws vs' rule: reaches_on_rev_induct)\n  case (2 s s' bs bss s'')\n  obtain ys where ys_def: \"reaches_on (ru n) (s ! i) ys (s' ! i)\"\n    \"length s = length s'\" \"length ys = length bss\"\n    using reaches_ons_run_lD[OF 2(1)] 2(3)[OF 2(4)]\n    by auto\n  obtain tb where tb_def: \"ru n (s' ! i) = Some (s'' ! i, tb)\"\n    using run_subs_vD[OF 2(2) 2(4)[unfolded ys_def(2)]]\n    by auto\n  show ?case\n    using reaches_on_app[OF ys_def(1) tb_def(1)] ys_def(2,3) tb_def\n    by auto\nqed (auto intro: reaches_on.intros)\n\nlemma reaches_ons_runI:\n  assumes \"\\<And>phi. phi \\<in> set (collect_subfmlas r []) \\<Longrightarrow> \\<exists>ws v. reaches_on (ru n) (su n phi) ws v \\<and> length ws = i\"\n  shows \"\\<exists>ws v. reaches_on (run_subs (ru n)) (map (su n) (collect_subfmlas r [])) ws v \\<and> length ws = i\"\n  using assms\nproof (induction i)\n  case 0\n  show ?case\n    by (fastforce intro: reaches_on.intros)\nnext\n  case (Suc i)\n  have IH': \"\\<And>phi. phi \\<in> set (collect_subfmlas r []) \\<Longrightarrow> \\<exists>ws v. reaches_on (ru n) (su n phi) ws v \\<and> length ws = i \\<and> ru n v \\<noteq> None\"\n  proof -\n    fix phi\n    assume lassm: \"phi \\<in> set (collect_subfmlas r [])\"\n    obtain ws v where ws_def: \"reaches_on (ru n) (su n phi) ws v\"\n      \"length ws = Suc i\"\n      using Suc(2)[OF lassm]\n      by auto\n    obtain y ys where ws_snoc: \"ws = ys @ [y]\"\n      using ws_def(2)\n      by (cases ws rule: rev_cases) auto\n    show \"\\<exists>ws v. reaches_on (ru n) (su n phi) ws v \\<and> length ws = i \\<and> ru n v \\<noteq> None\"\n      using reaches_on_split_last[OF ws_def(1)[unfolded ws_snoc]] ws_def(2) ws_snoc\n      by fastforce\n  qed\n  obtain ws v where ws_def: \"reaches_on (run_subs (ru n)) (map (su n) (collect_subfmlas r [])) ws v\" \"length ws = i\"\n    using Suc(1) IH'\n    by blast\n  have \"x \\<in> set v \\<Longrightarrow> Option.is_none (ru n x) \\<Longrightarrow> False\" for x\n    using ws_def IH'\n    by (auto simp: in_set_conv_nth) (metis is_none_code(2) reach_run_subs_len reach_run_subs_run reaches_on_inj)\n  then obtain v' tb where v'_def: \"run_subs (ru n) v = Some (v', tb)\"\n    by (fastforce simp: run_subs_def Let_def)\n  show ?case\n    using reaches_on_app[OF ws_def(1) v'_def] ws_def(2)\n    by fastforce\nqed\n\nlemma reaches_on_takeWhile: \"reaches_on r s vs s' \\<Longrightarrow> r s' = Some (s'', v) \\<Longrightarrow> \\<not>f v \\<Longrightarrow>\n  vs' = takeWhile f vs \\<Longrightarrow>\n  \\<exists>t' t'' v'. reaches_on r s vs' t' \\<and> r t' = Some (t'', v') \\<and> \\<not>f v' \\<and>\n  reaches_on r t' (drop (length vs') vs) s'\"\n  by (induction s vs s' arbitrary: vs' rule: reaches_on.induct) (auto intro: reaches_on.intros)\n\nlemma reaches_on_suffix:\n  assumes \"reaches_on r s vs s'\" \"reaches_on r s vs' s''\" \"length vs' \\<le> length vs\"\n  shows \"\\<exists>vs''. reaches_on r s'' vs'' s' \\<and> vs = vs' @ vs''\"\n  using reaches_on_split'[where ?i=\"length vs'\", OF assms(1,3)] assms(3) reaches_on_inj[OF assms(2)]\n  by (metis add_diff_cancel_right' append_take_drop_id diff_diff_cancel length_append length_drop)\n\nlemma vydra_wf_reaches_on:\n  assumes \"\\<And>j v. j < i \\<Longrightarrow> wf_vydra \\<phi> j n v \\<Longrightarrow> ru n v = None \\<Longrightarrow> False\" \"bounded_future_fmla \\<phi>\" \"wf_fmla \\<phi>\" \"msize_fmla \\<phi> \\<le> n\"\n  shows \"\\<exists>vs v. reaches_on (ru n) (su n \\<phi>) vs v \\<and> wf_vydra \\<phi> i n v \\<and> length vs = i\"\n  using assms(1)\nproof (induction i)\n  case (Suc i)\n  obtain vs v where IH: \"reaches_on (ru n) (su n \\<phi>) vs v\" \"wf_vydra \\<phi> i n v\" \"length vs = i\"\n    using Suc(1) Suc(2)[OF less_SucI]\n    by auto\n  show ?case\n    using reaches_on_app[OF IH(1)] Suc(2)[OF _ IH(2)] vydra_sound_aux[OF assms(4) IH(2) _ assms(2,3)] IH(3)\n    by fastforce\nqed (auto intro: reaches_on.intros wf_vydra_sub[OF assms(4)])\n\nlemma reaches_on_Some:\n  assumes \"reaches_on r s vs s'\" \"reaches_on r s vs' s''\" \"length vs < length vs'\"\n  shows \"\\<exists>s''' x. r s' = Some (s''', x)\"\n  using reaches_on_split[OF assms(2,3)] reaches_on_inj[OF assms(1)] assms(3)\n  by auto\n\nlemma reaches_on_progress:\n  assumes \"reaches_on run_hd init_hd vs e\"\n  shows \"progress phi (map fst vs) \\<le> length vs\"\n  using progress_le_ts[of \"map fst vs\" phi] reaches_on_run_hd \\<tau>_fin\n  by (fastforce dest!: reaches_on_setD[OF assms] reaches_on_split_last)\n\nlemma vydra_complete_aux:\n  assumes prefix: \"reaches_on run_hd init_hd vs e\"\n    and run: \"wf_vydra \\<phi> i n v\" \"ru n v = None\" \"i < progress \\<phi> (map fst vs)\" \"bounded_future_fmla \\<phi>\" \"wf_fmla \\<phi>\"\n    and msize: \"msize_fmla \\<phi> \\<le> n\"\n  shows \"False\"\n  using msize run\nproof (induction n \\<phi> arbitrary: i v rule: run_induct)\n  case (Bool b n)\n  have False if v_def: \"v = VYDRA_Bool b g\" for g\n  proof -\n    obtain es where g_def: \"reaches_on run_hd init_hd es g\" \"length es = i\"\n      using Bool(1)\n      by (auto simp: v_def elim: wf_vydra.cases)\n    show False\n      using Bool(2) reaches_on_Some[OF g_def(1) prefix] Bool(3)\n      by (auto simp: v_def g_def(2) split: option.splits)\n  qed\n  then show False\n    using Bool(1)\n    by (auto elim!: wf_vydra.cases[of _ _ _ v])\nnext\n  case (Atom a n)\n  have False if v_def: \"v = VYDRA_Atom a g\" for g\n  proof -\n    obtain es where g_def: \"reaches_on run_hd init_hd es g\" \"length es = i\"\n      using Atom(1)\n      by (auto simp: v_def elim: wf_vydra.cases)\n    show False\n      using Atom(2) reaches_on_Some[OF g_def(1) prefix] Atom(3)\n      by (auto simp: v_def g_def(2) split: option.splits)\n  qed\n  then show False\n    using Atom(1)\n    by (auto elim!: wf_vydra.cases[of _ _ _ v])\nnext\n  case (Neg n phi)\n  show ?case\n    apply (rule wf_vydra.cases[OF Neg(3)])\n    using Neg\n    by (fastforce split: option.splits)+\nnext\n  case (Bin n f phi psi)\n  show ?case\n    apply (rule wf_vydra.cases[OF Bin(4)])\n    using Bin\n    by (fastforce split: option.splits)+\nnext\n  case (Prev n I phi)\n  show ?case\n  proof (cases i)\n    case 0\n    obtain vphi where v_def: \"v = VYDRA_Prev I vphi init_hd None\"\n      using Prev(3)\n      by (auto simp: 0 dest: reaches_on_NilD elim!: wf_vydra.cases[of \"Prev I phi\"])\n    show ?thesis\n      using Prev(4,5) prefix\n      by (auto simp: 0 v_def elim: reaches_on.cases split: option.splits)\n  next\n    case (Suc j)\n    show ?thesis\n    proof (cases \"v = VYDRA_None\")\n      case v_def: True\n      obtain w where w_def: \"wf_vydra phi j n w\" \"ru n w = None\"\n        using Prev(3)\n        by (auto simp: Suc v_def elim!: wf_vydra.cases[of \"Prev I phi\"])\n      show ?thesis\n        using Prev(2)[OF w_def(1,2)] Prev(5,6,7)\n        by (auto simp: Suc)\n    next\n      case False\n      obtain vphi tphi bphi es g where v_def: \"v = VYDRA_Prev I vphi g (Some (tphi, bphi))\"\n        \"wf_vydra phi (Suc j) n vphi\" \"reaches_on run_hd init_hd es g\" \"length es = Suc j\"\n        using Prev(3) False\n        by (auto simp: Suc elim!: wf_vydra.cases[of \"Prev I phi\"])\n      show ?thesis\n        using Prev(4,5) reaches_on_Some[OF v_def(3) prefix]\n        by (auto simp: Let_def Suc v_def(1,4) split: option.splits)\n    qed\n  qed\nnext\n  case (Next n I phi)\n  show ?case\n  proof (cases \"v = VYDRA_None\")\n    case True\n    obtain w where w_def: \"wf_vydra phi i n w\" \"ru n w = None\"\n      using Next(3)\n      by (auto simp: True elim: wf_vydra.cases)\n    show ?thesis\n      using Next(2)[OF w_def] Next(5,6,7)\n      by (auto split: nat.splits)\n  next\n    case False\n    obtain w sub to es where v_def: \"v = VYDRA_Next I w sub to\" \"wf_vydra phi (length es) n w\"\n      \"reaches_on run_hd init_hd es sub\" \"length es = (case to of None \\<Rightarrow> 0 | _ \\<Rightarrow> Suc i)\"\n      \"case to of None \\<Rightarrow> i = 0 | Some told \\<Rightarrow> told = \\<tau> \\<sigma> i\"\n      using Next(3) False\n      by (auto elim!: wf_vydra.cases[of _ _ _ v] split: option.splits nat.splits)\n    show ?thesis\n    proof (cases to)\n      case None\n      obtain w' tw' bw' where w'_def: \"ru n w = Some (w', (tw', bw'))\"\n        using Next(2)[OF v_def(2)] Next(5,6,7)\n        by (fastforce simp: v_def(4) None split: nat.splits)\n      have wf: \"wf_vydra phi (Suc (length es)) n w'\"\n        using v_def(4,5) vydra_sound_aux[OF Next(1) v_def(2) w'_def] Next(6,7)\n        by (auto simp: None)\n      show ?thesis\n        using Next(2)[OF wf] Next(4,5,6,7) reaches_on_Some[OF v_def(3) prefix]\n          reaches_on_Some[OF reaches_on_app[OF v_def(3)] prefix] reaches_on_progress[OF prefix, where ?phi=phi]\n        by (cases vs) (fastforce simp: v_def(1,4) w'_def None split: option.splits nat.splits if_splits)+\n    next\n      case (Some z)\n      show ?thesis\n        using Next(2)[OF v_def(2)] Next(4,5,6,7) reaches_on_Some[OF v_def(3) prefix] reaches_on_progress[OF prefix, where ?phi=phi]\n        by (auto simp: v_def(1,4) Some split: option.splits nat.splits)\n    qed\n  qed\nnext\n  case (Since n I phi psi)\n  obtain vphi vpsi g cphi cpsi cppsi tppsi j gs where v_def:\n    \"v = VYDRA_Since I vphi vpsi g cphi cpsi cppsi tppsi\"\n    \"wf_vydra phi i n vphi\" \"wf_vydra psi j n vpsi\" \"j \\<le> i\"\n    \"reaches_on ru_t l_t0 gs g\" \"length gs = j\" \"cpsi = i - j\"\n    using Since(5)\n    by (auto elim: wf_vydra.cases)\n  obtain vphi' t1 b1 where run_vphi: \"ru n vphi = Some (vphi', t1, b1)\"\n    using Since(3)[OF v_def(2)] Since(7,8,9)\n    by fastforce\n  obtain cs c where wf_vphi': \"wf_vydra phi (Suc i) n vphi'\"\n    and reaches_Suc_i: \"reaches_on run_hd init_hd cs c\" \"length cs = Suc i\"\n    and t1_def: \"t1 = \\<tau> \\<sigma> i\"\n    using vydra_sound_aux[OF Since(1) v_def(2) run_vphi] Since(8,9)\n    by auto\n  note ru_t_Some = ru_t_Some[OF reaches_Suc_i]\n  define loop_inv where \"loop_inv = (\\<lambda>(vpsi, e, cpsi :: nat, cppsi :: nat option, tppsi :: 't option).\n    let j = Suc i - cpsi in cpsi \\<le> Suc i \\<and> wf_vydra psi j n vpsi \\<and> (\\<exists>es. reaches_on ru_t l_t0 es e \\<and> length es = j))\"\n  define loop_init where \"loop_init = (vpsi, g, Suc cpsi, map_option Suc cppsi, tppsi)\"\n  have j_def: \"j = i - cpsi\" and cpsi_i: \"cpsi \\<le> i\"\n    using v_def(4,7)\n    by auto\n  then have loop_inv_init: \"loop_inv loop_init\"\n    using v_def(3,5,6,7) last_before_Some\n    by (fastforce simp: loop_inv_def loop_init_def Let_def j_def split: option.splits)\n  have wf_loop: \"wf {(s', s). loop_inv s \\<and> while_since_cond I t1 s \\<and> Some s' = while_since_body run_hd (ru n) s}\"\n    by (auto intro: wf_subset[OF wf_since])\n  have step_loop: \"pred_option' loop_inv (while_since_body run_hd (ru n) s)\"\n    if loop_assms: \"loop_inv s\" \"while_since_cond I t1 s\" for s\n  proof -\n    obtain vpsi d cpsi cppsi tppsi where s_def: \"s = (vpsi, d, cpsi, cppsi, tppsi)\"\n      by (cases s) auto\n    have cpsi_pos: \"cpsi > 0\"\n      using loop_assms(2)\n      by (auto simp: while_since_cond_def s_def)\n    define j where \"j = Suc i - cpsi\"\n    have j_i: \"j \\<le> i\"\n      using cpsi_pos\n      by (auto simp: j_def)\n    obtain ds where loop_before: \"cpsi \\<le> Suc i\" \"wf_vydra psi j n vpsi\" \"reaches_on ru_t l_t0 ds d\" \"length ds = j\"\n      using loop_assms(1)\n      by (auto simp: s_def j_def loop_inv_def Let_def)\n    obtain h tt where tt_def: \"read_t d = Some tt\" \"d = Some (h, tt)\"\n      using ru_t_Some[OF loop_before(3)] loop_before(4) loop_assms(2)\n      by (cases d) (fastforce simp: while_since_cond_def s_def j_def split: option.splits)+\n    obtain d' where d'_def: \"reaches_on ru_t l_t0 (ds @ [tt]) d'\" \"ru_t d = Some (d', tt)\"\n      using reaches_on_app[OF loop_before(3)] tt_def(1)\n      by (cases \"run_hd h\") (auto simp: tt_def(2))\n    obtain vpsi' tpsi' bpsi' where run_vpsi: \"ru n vpsi = Some (vpsi', (tpsi', bpsi'))\"\n      using Since(4) j_i Since(7,8,9) loop_before(2)\n      by fastforce\n    have wf_psi': \"wf_vydra psi (Suc j) n vpsi'\" and t'_def: \"tpsi' = \\<tau> \\<sigma> j\" and b'_def: \"bpsi' = sat psi j\"\n      using vydra_sound_aux[OF Since(2) loop_before(2) run_vpsi] Since(8,9)\n      by auto\n    define j' where j'_def: \"j' = Suc i - (cpsi - Suc 0)\"\n    have j'_j: \"j' = Suc j\"\n      using loop_before(1) cpsi_pos\n      by (auto simp: j'_def j_def)\n    show ?thesis\n      using wf_psi'(1) loop_before(1,4) d'_def(1)\n      by (fastforce simp: while_since_body_def s_def run_vpsi pred_option'_def loop_inv_def j'_def[symmetric] j'_j d'_def(2) t1_def)\n  qed\n  show ?case\n    using while_break_complete[OF step_loop _ wf_loop loop_inv_init, where ?Q=\"\\<lambda>_. True\"] Since(6)\n    by (auto simp: pred_option'_def v_def(1) run_vphi Let_def loop_init_def split: option.splits)\nnext\n  case (Until n I phi psi)\n  obtain \"back\" vphi vpsi front c z es es' j where v_def:\n    \"v = VYDRA_Until I back vphi vpsi front c z\"\n    \"wf_vydra phi j n vphi\" \"wf_vydra psi j n vpsi\" \"i \\<le> j\"\n    \"reaches_on ru_t l_t0 es back\" \"length es = i\"\n    \"reaches_on ru_t l_t0 es' front\" \"length es' = j\" \"\\<And>t. t \\<in> set es' \\<Longrightarrow> memR (\\<tau> \\<sigma> i) t I\"\n    \"c = j - i\" \"z = (case j of 0 \\<Rightarrow> None | Suc k \\<Rightarrow> Some (\\<tau> \\<sigma> k, sat phi k, sat psi k))\"\n    \"\\<And>k. k \\<in> {i..<j - 1} \\<Longrightarrow> sat phi k \\<and> (memL (\\<tau> \\<sigma> i) (\\<tau> \\<sigma> k) I \\<longrightarrow> \\<not>sat psi k)\"\n    using Until(5)\n    by (auto simp: elim: wf_vydra.cases)\n  have ru_t_Some: \"reaches_on ru_t l_t0 gs g \\<Longrightarrow> length gs < length vs \\<Longrightarrow> \\<exists>g' gt. ru_t g = Some (g', gt)\" for gs g\n    using reaches_on_Some reaches_on_run_hd_t[OF prefix]\n    by fastforce\n  have vs_tau: \"map fst vs ! k = \\<tau> \\<sigma> k\" if k_vs: \"k < length vs\" for k\n    using reaches_on_split[OF prefix k_vs] run_hd_sound k_vs\n    apply (cases \"vs ! k\")\n    apply (auto)\n    apply (metis fst_conv length_map nth_map prefix reaches_on_run_hd_t ru_t_tau_in)\n    done\n  define m where \"m = min (length (map fst vs) - 1) (min (progress phi (map fst vs)) (progress psi (map fst vs)))\"\n  have m_vs: \"m < length vs\"\n    using Until(7)\n    by (cases vs) (auto simp: m_def split: if_splits)\n  define A where \"A = {j. 0 \\<le> j \\<and> j \\<le> m \\<and> memR (map fst vs ! j) (map fst vs ! m) I}\"\n  have m_A: \"m \\<in> A\"\n    using memR_tfin_refl[OF \\<tau>_fin] vs_tau[OF m_vs]\n    by (fastforce simp: A_def)\n  then have A_nonempty: \"A \\<noteq> {}\"\n    by auto\n  have A_finite: \"finite A\"\n    by (auto simp: A_def)\n  have p: \"progress (Until phi I psi) (map fst vs) = Min A\"\n    using Until(7)\n    unfolding progress.simps m_def[symmetric] Let_def A_def[symmetric]\n    by auto\n  have i_A: \"i \\<notin> A\"\n    using Until(7) A_finite A_nonempty\n    by (auto simp del: progress.simps simp: p)\n  have i_m: \"i < m\"\n    using Until(7) m_A A_finite A_nonempty\n    by (auto simp del: progress.simps simp: p)\n  have memR_i_m: \"\\<not>memR (map fst vs ! i) (map fst vs ! m) I\"\n    using i_A i_m\n    by (auto simp: A_def)\n  have i_vs: \"i < length vs\"\n    using i_m m_vs\n    by auto\n  have j_m: \"j \\<le> m\"\n    using ru_t_tau_in[OF v_def(7), of m] v_def(9)[of \"\\<tau> \\<sigma> m\"] memR_i_m\n    unfolding vs_tau[OF i_vs] vs_tau[OF m_vs]\n    by (force simp: in_set_conv_nth v_def(8))\n  have j_vs: \"j < length vs\"\n    using j_m m_vs\n    by auto\n  obtain back' t where run_back: \"ru_t back = Some (back', t)\" and t_def: \"t = \\<tau> \\<sigma> i\"\n    using ru_t_Some[OF v_def(5)] v_def(4) j_vs ru_t_tau[OF v_def(5)]\n    by (fastforce simp: v_def(6))\n  define loop_inv where \"loop_inv = (\\<lambda>(vphi, vpsi, front, c, z :: ('t \\<times> bool \\<times> bool) option).\n    let j = i + c in wf_vydra phi j n vphi \\<and> wf_vydra psi j n vpsi \\<and> j < length vs \\<and>\n    (\\<exists>es'. reaches_on ru_t l_t0 es' front \\<and> length es' = j) \\<and>\n    (z = None \\<longrightarrow> j = 0))\"\n  define loop_init where \"loop_init = (vphi, vpsi, front, c, z)\"\n  have j_eq: \"j = i + c\"\n    using v_def(4)\n    by (auto simp: v_def(10))\n  have \"j = 0 \\<Longrightarrow> c = 0\"\n    by (auto simp: j_eq)\n  then have loop_inv_init: \"loop_inv loop_init\"\n    using v_def(2,3,4,7,8,9,11) j_vs\n    by (auto simp: loop_inv_def loop_init_def j_eq[symmetric] split: nat.splits)\n  have loop_step: \"pred_option' loop_inv (while_until_body run_hd (ru n) s)\" if loop_assms: \"loop_inv s\" \"while_until_cond I t s\" for s\n  proof -\n    obtain vphi_cur vpsi_cur epsi_cur c_cur zo_cur where s_def: \"s = (vphi_cur, vpsi_cur, epsi_cur, c_cur, zo_cur)\"\n      by (cases s) auto\n    define j_cur where \"j_cur = i + c_cur\"\n    obtain gs where wf: \"wf_vydra phi j_cur n vphi_cur\" \"wf_vydra psi j_cur n vpsi_cur\"\n      and gs_def: \"reaches_on ru_t l_t0 gs epsi_cur\" \"length gs = j_cur\"\n      and j_cur_vs: \"j_cur < length vs\"\n      using loop_assms(1)\n      by (auto simp: loop_inv_def s_def j_cur_def[symmetric])\n    obtain epsi'_cur t'_cur where run_epsi: \"ru_t epsi_cur = Some (epsi'_cur, t'_cur)\"\n      and t'_cur_def: \"t'_cur = \\<tau> \\<sigma> (length gs)\"\n      using ru_t_Some[OF gs_def(1)] ru_t_event[OF gs_def(1) refl] j_cur_vs\n      by (auto simp: gs_def(2))\n    have j_m: \"j_cur < m\"\n      using loop_assms(2) memR_i_m memR_mono'[OF _ \\<tau>_mono, of _ _ _ _ m]\n      unfolding vs_tau[OF i_vs] vs_tau[OF m_vs]\n      by (fastforce simp: gs_def(2) while_until_cond_def s_def run_t_read[OF run_epsi] t_def t'_cur_def)\n    have j_cur_prog_phi: \"j_cur < progress phi (map fst vs)\"\n      using j_m\n      by (auto simp: m_def)\n    have j_cur_prog_psi: \"j_cur < progress psi (map fst vs)\"\n      using j_m\n      by (auto simp: m_def)\n    obtain vphi'_cur tphi_cur bphi_cur where run_vphi: \"ru n vphi_cur = Some (vphi'_cur, (tphi_cur, bphi_cur))\"\n      using Until(3)[OF wf(1) _ j_cur_prog_phi] Until(8,9)\n      by fastforce\n    obtain vpsi'_cur tpsi_cur bpsi_cur where run_vpsi: \"ru n vpsi_cur = Some (vpsi'_cur, (tpsi_cur, bpsi_cur))\"\n      using Until(4)[OF wf(2) _ j_cur_prog_psi] Until(8,9)\n      by fastforce\n    have wf': \"wf_vydra phi (Suc j_cur) n vphi'_cur\" \"wf_vydra psi (Suc j_cur) n vpsi'_cur\"\n      using vydra_sound_aux[OF Until(1) wf(1) run_vphi] vydra_sound_aux[OF Until(2) wf(2) run_vpsi] Until(8,9)\n      by auto\n    show ?thesis\n      using wf' reaches_on_app[OF gs_def(1) run_epsi] gs_def(2) j_m m_vs\n      by (auto simp: pred_option'_def while_until_body_def s_def run_epsi run_vphi run_vpsi loop_inv_def j_cur_def[symmetric])\n  qed\n  have wf_loop: \"wf {(s', s). loop_inv s \\<and> while_until_cond I t s \\<and> Some s' = while_until_body run_hd (ru n) s}\"\n  proof -\n    obtain m where m_def: \"\\<not>\\<tau> \\<sigma> m \\<le> \\<tau> \\<sigma> i + right I\"\n      using ex_lt_\\<tau>[where ?x=\"right I\" and ?s=\\<sigma>] Until(8)\n      by auto\n    define X where \"X = {(s', s). loop_inv s \\<and> while_until_cond I t s \\<and> Some s' = while_until_body run_hd (ru n) s}\"\n    have \"memR t (\\<tau> \\<sigma> (i + c)) I \\<Longrightarrow> i + c < m\" for c\n      using m_def order_trans[OF \\<tau>_mono[where ?i=m and ?j=\"i + c\" and ?s=\\<sigma>]]\n      by (fastforce simp: t_def dest!: memR_dest)\n    then have \"X \\<subseteq> measure (\\<lambda>(vphi, vpsi, epsi, c, zo). m - c)\"\n      by (fastforce simp: X_def while_until_cond_def while_until_body_def loop_inv_def Let_def split: option.splits\n          dest!: read_t_run[where ?run_hd=run_hd] dest: ru_t_tau)\n    then show ?thesis\n      using wf_subset\n      by (auto simp: X_def[symmetric])\n  qed\n  obtain vphi' vpsi' front' c' z' where loop:\n    \"while_break (while_until_cond I t) (while_until_body run_hd (ru n)) loop_init = Some (vphi', vpsi', front', c', z')\"\n    \"loop_inv (vphi', vpsi', front', c', z')\" \"\\<not>while_until_cond I t (vphi', vpsi', front', c', z')\"\n    using while_break_complete[where ?P=\"loop_inv\", OF loop_step _ wf_loop loop_inv_init]\n    by (cases \"while_break (while_until_cond I t) (while_until_body run_hd (ru n)) loop_init\") (force simp: pred_option'_def)+\n  define j' where \"j' = i + c'\"\n  obtain tf where read_front': \"read_t front' = Some tf\"\n    using loop(2)\n    by (auto simp: loop_inv_def j'_def[symmetric] dest!: ru_t_Some run_t_read[where ?run_hd=run_hd])\n  have tf_fin: \"tf \\<in> tfin\"\n    using loop(2) ru_t_Some[where ?g=front'] ru_t_tau[where ?t'=front'] read_t_run[OF read_front'] \\<tau>_fin[where ?\\<sigma>=\\<sigma>]\n    by (fastforce simp: loop_inv_def j'_def[symmetric])\n  have c'_pos: \"c' = 0 \\<Longrightarrow> False\"\n    using loop(2,3) ru_t_tau ru_t_tau[OF reaches_on.intros(1)] read_t_run[OF read_front']\n      memR_tfin_refl[OF tf_fin]\n    by (fastforce simp: loop_inv_def while_until_cond_def until_ready_def read_front' t_def dest!: reaches_on_NilD)\n  have z'_Some: \"z' = None \\<Longrightarrow> False\"\n    using loop(2) c'_pos\n    by (auto simp: loop_inv_def j'_def[symmetric])\n  show ?case\n    using Until(6) c'_pos z'_Some\n    by (auto simp: v_def(1) run_back loop_init_def[symmetric] loop(1) read_front' split: if_splits option.splits)\nnext\n  case (MatchP n I r)\n  have msize_sub: \"\\<And>x. x \\<in> set (collect_subfmlas r []) \\<Longrightarrow> msize_fmla x \\<le> n\"\n    using le_trans[OF collect_subfmlas_msize] MatchP(1)\n    by auto\n  have sound: \"x \\<in> set (collect_subfmlas r []) \\<Longrightarrow> wf_vydra x j n v \\<Longrightarrow> ru n v = Some (v', t, b) \\<Longrightarrow> wf_vydra x (Suc j) n v' \\<and> t = \\<tau> \\<sigma> j \\<and> b = sat x j\" for x j v v' t b\n    using MatchP vydra_sound_aux[OF msize_sub] le_trans[OF collect_subfmlas_msize]\n    using bf_collect_subfmlas[where ?r=\"r\" and ?phis=\"[]\"]\n    by (fastforce simp: collect_subfmlas_atms[where ?phis=\"[]\", simplified, symmetric])\n  have \"reaches_on (ru n) (su n phi) vs v \\<Longrightarrow> wf_vydra phi (length vs) n v\" if phi: \"phi \\<in> set (collect_subfmlas r [])\" for phi vs v\n    apply (induction vs arbitrary: v rule: rev_induct)\n    using MatchP(1) wf_vydra_sub collect_subfmlas_msize[OF phi]\n     apply (auto elim!: reaches_on.cases)[1]\n    using sound[OF phi]\n    apply (fastforce dest!: reaches_on_split_last)\n    done\n  then have wf: \"reaches_on (run_subs (ru n)) (map (su n) (collect_subfmlas r [])) bs s \\<Longrightarrow> j < length (collect_subfmlas r []) \\<Longrightarrow>\n    wf_vydra (collect_subfmlas r [] ! j) (length bs) n (s ! j)\" for bs s j\n    using reach_run_subs_run\n    by (fastforce simp: in_set_conv_nth)\n  let ?qf = \"state_cnt r\"\n  let ?transs = \"iarray_of_list (build_nfa_impl r (0, ?qf, []))\"\n  define args where \"args = init_args ({0}, NFA.delta' ?transs ?qf, NFA.accept' ?transs ?qf) (ru_t, read_t) (run_subs (ru n))\"\n  interpret MDL_window \\<sigma> r l_t0 \"map (su n) (collect_subfmlas r [])\" args\n    using bs_sat[where ?r=r and ?n=n, OF _ wf _ reach_run_subs_len[where ?n=n]] sound run_t_read[of run_hd]\n      read_t_run[of _ _ run_hd] ru_t_tau MatchP(5) collect_subfmlas_atms[where ?phis=\"[]\"]\n    unfolding args_def iarray_of_list_def\n    by unfold_locales auto\n  obtain w xs where w_def: \"v = VYDRA_MatchP I ?transs ?qf w\"\n    \"valid_window_matchP args I l_t0 (map (su n) (collect_subfmlas r [])) xs i w\"\n    using MatchP(3)\n    by (auto simp: args_def elim!: wf_vydra.cases)\n  note args' = args_def[unfolded init_args.simps, symmetric]\n  have run_args: \"w_run_t args = ru_t\" \"w_run_sub args = run_subs (ru n)\"\n    by (auto simp: args_def)\n  have len_xs: \"length xs = i\"\n    using w_def(2)\n    by (auto simp: valid_window_matchP_def)\n  obtain ej tj where w_tj: \"ru_t (w_tj w) = Some (ej, tj)\"\n    using reaches_on_Some[OF valid_window_matchP_reach_tj[OF w_def(2)]] reaches_on_run_hd_t[OF prefix]\n      MatchP(5) reaches_on_progress[OF prefix, where ?phi=\"MatchP I r\"]\n    by (fastforce simp: run_args len_xs simp del: progress.simps)\n  have \"run_subs (ru n) (w_sj w) = None\"\n    using valid_eval_matchP[OF w_def(2), unfolded run_args] w_tj MatchP(4,7)\n    by (cases \"run_subs (ru n) (w_sj w)\") (auto simp: w_def(1) args' simp del: eval_matchP.simps split: option.splits)\n  then obtain j where j_def: \"j < length (w_sj w)\" \"ru n (w_sj w ! j) = None\"\n    by (auto simp: run_subs_def Let_def in_set_conv_nth Option.is_none_def split: if_splits)\n  have len_w_sj: \"length (w_sj w) = length (collect_subfmlas r [])\"\n    using valid_window_matchP_reach_sj[OF w_def(2)] reach_run_subs_len\n    by (auto simp: run_args)\n  define phi where \"phi = collect_subfmlas r [] ! j\"\n  have phi_in_set: \"phi \\<in> set (collect_subfmlas r [])\"\n    using j_def(1)\n    by (auto simp: phi_def in_set_conv_nth len_w_sj)\n  have wf: \"wf_vydra phi i n (w_sj w ! j)\"\n    using valid_window_matchP_reach_sj[OF w_def(2)] wf[folded len_w_sj, OF _ j_def(1)] len_xs\n    by (fastforce simp: run_args phi_def)\n  have \"i < progress phi (map fst vs)\"\n    using MatchP(5) phi_in_set atms_nonempty[of r] atms_finite[of r] collect_subfmlas_atms[of r \"[]\"]\n    by auto\n  then show ?case\n    using MatchP(2)[OF msize_sub[OF phi_in_set] wf j_def(2)] MatchP(6,7) phi_in_set\n      bf_collect_subfmlas[where ?r=\"r\" and ?phis=\"[]\"]\n    by (auto simp: collect_subfmlas_atms)\nnext\n  case (MatchF n I r)\n  have subfmla: \"msize_fmla x \\<le> n\" \"bounded_future_fmla x\" \"wf_fmla x\" if \"x \\<in> set (collect_subfmlas r [])\" for x\n    using that MatchF(1,6,7) le_trans[OF collect_subfmlas_msize] bf_collect_subfmlas[where ?r=\"r\" and ?phis=\"[]\" and ?phi=x]\n      collect_subfmlas_atms[where ?phis=\"[]\" and ?r=r]\n    by auto\n  have sound: \"x \\<in> set (collect_subfmlas r []) \\<Longrightarrow> wf_vydra x j n v \\<Longrightarrow> ru n v = Some (v', t, b) \\<Longrightarrow> wf_vydra x (Suc j) n v' \\<and> t = \\<tau> \\<sigma> j \\<and> b = sat x j\" for x j v v' t b\n    using MatchF vydra_sound_aux subfmla\n    by fastforce\n  have \"reaches_on (ru n) (su n phi) vs v \\<Longrightarrow> wf_vydra phi (length vs) n v\" if phi: \"phi \\<in> set (collect_subfmlas r [])\" for phi vs v\n    apply (induction vs arbitrary: v rule: rev_induct)\n    using MatchF(1) wf_vydra_sub subfmla(1)[OF phi] sound[OF phi]\n     apply (auto elim!: reaches_on.cases)[1]\n    using sound[OF phi]\n    apply (fastforce dest!: reaches_on_split_last)\n    done\n  then have wf: \"reaches_on (run_subs (ru n)) (map (su n) (collect_subfmlas r [])) bs s \\<Longrightarrow> j < length (collect_subfmlas r []) \\<Longrightarrow>\n    wf_vydra (collect_subfmlas r [] ! j) (length bs) n (s ! j)\" for bs s j\n    using reach_run_subs_run\n    by (fastforce simp: in_set_conv_nth)\n  let ?qf = \"state_cnt r\"\n  let ?transs = \"iarray_of_list (build_nfa_impl r (0, ?qf, []))\"\n  define args where \"args = init_args ({0}, NFA.delta' ?transs ?qf, NFA.accept' ?transs ?qf) (ru_t, read_t) (run_subs (ru n))\"\n  interpret MDL_window \\<sigma> r l_t0 \"map (su n) (collect_subfmlas r [])\" args\n    using bs_sat[where ?r=r and ?n=n, OF _ wf _ reach_run_subs_len[where ?n=n]] sound run_t_read[of run_hd]\n      read_t_run[of _ _ run_hd] ru_t_tau MatchF(5) subfmla\n    unfolding args_def iarray_of_list_def\n    by unfold_locales auto\n  obtain w xs where w_def: \"v = VYDRA_MatchF I ?transs ?qf w\"\n    \"valid_window_matchF args I l_t0 (map (su n) (collect_subfmlas r [])) xs i w\"\n    using MatchF(3)\n    by (auto simp: args_def elim!: wf_vydra.cases)\n  note args' = args_def[unfolded init_args.simps, symmetric]\n  have run_args: \"w_run_t args = ru_t\" \"w_read_t args = read_t\" \"w_run_sub args = run_subs (ru n)\"\n    by (auto simp: args_def)\n  have vs_tau: \"map fst vs ! k = \\<tau> \\<sigma> k\" if k_vs: \"k < length vs\" for k\n    using reaches_on_split[OF prefix k_vs] run_hd_sound k_vs\n    apply (cases \"vs ! k\")\n    apply (auto)\n    apply (metis fst_conv length_map nth_map prefix reaches_on_run_hd_t ru_t_tau_in)\n    done\n  define m where \"m = min (length (map fst vs) - 1) (Min ((\\<lambda>f. progress f (map fst vs)) ` atms r))\"\n  have m_vs: \"m < length vs\"\n    using MatchF(5)\n    by (cases vs) (auto simp: m_def split: if_splits)\n  define A where \"A = {j. 0 \\<le> j \\<and> j \\<le> m \\<and> memR (map fst vs ! j) (map fst vs ! m) I}\"\n  have m_A: \"m \\<in> A\"\n    using memR_tfin_refl[OF \\<tau>_fin] vs_tau[OF m_vs]\n    by (fastforce simp: A_def)\n  then have A_nonempty: \"A \\<noteq> {}\"\n    by auto\n  have A_finite: \"finite A\"\n    by (auto simp: A_def)\n  have p: \"progress (MatchF I r) (map fst vs) = Min A\"\n    using MatchF(5)\n    unfolding progress.simps m_def[symmetric] Let_def A_def[symmetric]\n    by auto\n  have i_A: \"i \\<notin> A\"\n    using MatchF(5) A_finite A_nonempty\n    by (auto simp del: progress.simps simp: p)\n  have i_m: \"i < m\"\n    using MatchF(5) m_A A_finite A_nonempty\n    by (auto simp del: progress.simps simp: p)\n  have memR_i_m: \"\\<not>memR (map fst vs ! i) (map fst vs ! m) I\"\n    using i_A i_m\n    by (auto simp: A_def)\n  have i_vs: \"i < length vs\"\n    using i_m m_vs\n    by auto\n  obtain ti where read_ti: \"w_read_t args (w_ti w) = Some ti\"\n    using w_def(2) reaches_on_Some[where ?r=ru_t and ?s=l_t0 and ?s'=\"w_ti w\"]\n      reaches_on_run_hd_t[OF prefix] i_vs run_t_read[where ?t=\"w_ti w\"]\n    by (fastforce simp: valid_window_matchF_def run_args)\n  have ti_def: \"ti = \\<tau> \\<sigma> i\"\n    using w_def(2) ru_t_tau read_t_run[OF read_ti]\n    by (fastforce simp: valid_window_matchF_def run_args)\n  note reach_tj = valid_window_matchF_reach_tj[OF w_def(2), unfolded run_args]\n  note reach_sj = valid_window_matchF_reach_sj[OF w_def(2), unfolded run_args]\n  have len_xs: \"length xs = w_j w\" and memR_xs: \"\\<And>l. l\\<in>{w_i w..<w_j w} \\<Longrightarrow> memR (ts_at xs i) (ts_at xs l) I\"\n    and i_def: \"w_i w = i\"\n    using w_def(2)\n    unfolding valid_window_matchF_def\n    by (auto simp: valid_window_matchF_def run_args)\n  have j_m: \"w_j w \\<le> m\"\n    using ru_t_tau_in[OF reach_tj, of i] ru_t_tau_in[OF reach_tj, of m] memR_i_m i_m memR_xs[of m]\n    unfolding vs_tau[OF i_vs] vs_tau[OF m_vs]\n    by (force simp: in_set_conv_nth len_xs ts_at_def i_def)\n  obtain tm tm' where tm_def: \"reaches_on ru_t l_t0 (take m (map fst vs)) tm\"\n    \"ru_t tm = Some (tm', fst (vs ! m))\"\n    using reaches_on_split[where ?i=m] reaches_on_run_hd_t[OF prefix] m_vs\n    by fastforce\n  have reach_tj_m: \"reaches_on (w_run_t args) (w_tj w) (drop (w_j w) (take m (map fst vs))) tm\"\n    using reaches_on_split'[OF tm_def(1), where ?i=\"w_j w\"] reaches_on_inj[OF reach_tj] m_vs j_m\n    by (auto simp: len_xs run_args)\n  have vs_m: \"fst (vs ! m) = \\<tau> \\<sigma> m\"\n    using vs_tau[OF m_vs] m_vs\n    by auto\n  have memR_ti_m: \"\\<not>memR ti (\\<tau> \\<sigma> m) I\"\n    using memR_i_m\n    unfolding vs_tau[OF i_vs] vs_tau[OF m_vs]\n    by (auto simp: ti_def)\n  have m_prog: \"m \\<le> progress phi (map fst vs)\" if \"phi \\<in> set (collect_subfmlas r [])\" for phi\n    using collect_subfmlas_atms[where ?r=r and ?phis=\"[]\"] that atms_finite[of r]\n    by (auto simp: m_def min.coboundedI2)\n  obtain ws s where ws_def: \"reaches_on (run_subs (ru n)) (map (su n) (collect_subfmlas r [])) ws s\" \"length ws = m\"\n    using reaches_ons_runI[where ?r=r and ?n=n and ?i=m]\n      vydra_wf_reaches_on[where ?i=m and ?n=n] subfmla\n      MatchF(2) m_prog\n    by fastforce\n  have reach_sj_m: \"reaches_on (run_subs (ru n)) (w_sj w) (drop (w_j w) ws) s\"\n    using reaches_on_split'[OF ws_def(1), where ?i=\"w_j w\"] reaches_on_inj[OF reach_sj] i_m j_m\n    by (auto simp: ws_def(2) len_xs)\n  define rho where \"rho = zip (drop (w_j w) (take m (map fst vs))) (drop (w_j w) ws)\"\n  have map_fst_rho: \"map fst rho = drop (w_j w) (take m (map fst vs))\"\n    and map_snd_rho: \"map snd rho = drop (w_j w) ws\"\n    using ws_def(2) j_m m_vs\n    by (auto simp: rho_def)\n  show False\n    using valid_eval_matchF_complete[OF w_def(2) reach_tj_m[folded map_fst_rho] reach_sj_m[folded map_snd_rho run_args] read_ti run_t_read[OF tm_def(2)[folded run_args], unfolded vs_m] memR_ti_m] MatchF(4,7)\n    by (auto simp: w_def(1) args_def simp del: eval_matchF.simps)\nqed\n\ndefinition \"ru' \\<phi> = ru (msize_fmla \\<phi>)\"\ndefinition \"su' \\<phi> = su (msize_fmla \\<phi>) \\<phi>\"\n\nlemma vydra_wf:\n  assumes \"reaches (ru n) (su n \\<phi>) i v\" \"bounded_future_fmla \\<phi>\" \"wf_fmla \\<phi>\" \"msize_fmla \\<phi> \\<le> n\"\n  shows \"wf_vydra \\<phi> i n v\"\n  using assms(1)\nproof (induction i arbitrary: v)\n  case 0\n  then show ?case\n    using wf_vydra_sub[OF assms(4)]\n    by (auto elim: reaches.cases)\nnext\n  case (Suc i)\n  show ?case\n    using reaches_Suc_split_last[OF Suc(2)] Suc(1) vydra_sound_aux[OF assms(4) _ _ assms(2,3)]\n    by fastforce\nqed\n\nlemma vydra_sound':\n  assumes \"reaches (ru' \\<phi>) (su' \\<phi>) n v\" \"ru' \\<phi> v = Some (v', (t, b))\" \"bounded_future_fmla \\<phi>\" \"wf_fmla \\<phi>\"\n  shows \"(t, b) = (\\<tau> \\<sigma> n, sat \\<phi> n)\"\n  using vydra_sound_aux[OF order.refl vydra_wf[OF assms(1)[unfolded ru'_def su'_def] assms(3,4) order.refl] assms(2)[unfolded ru'_def] assms(3,4)]\n  by auto\n\nlemma vydra_complete':\n  assumes prefix: \"reaches_on run_hd init_hd vs e\"\n    and prog: \"n < progress \\<phi> (map fst vs)\" \"bounded_future_fmla \\<phi>\" \"wf_fmla \\<phi>\"\n  shows \"\\<exists>v v'. reaches (ru' \\<phi>) (su' \\<phi>) n v \\<and> ru' \\<phi> v = Some (v', (\\<tau> \\<sigma> n, sat \\<phi> n))\"\nproof -\n  have aux: \"False\" if aux_assms: \"j \\<le> n\" \"wf_vydra \\<phi> j (msize_fmla \\<phi>) v\" \"ru (msize_fmla \\<phi>) v = None\" for j v\n    using vydra_complete_aux[OF prefix aux_assms(2,3) _ prog(2-)] aux_assms(1) prog(1)\n    by auto\n  obtain ws v where ws_def: \"reaches_on (ru' \\<phi>) (su' \\<phi>) ws v\" \"wf_vydra \\<phi> n (msize_fmla \\<phi>) v\" \"length ws = n\"\n    using vydra_wf_reaches_on[OF _ prog(2,3)] aux[OF less_imp_le_nat]\n    unfolding ru'_def su'_def\n    by blast\n  have ru_Some: \"ru' \\<phi> v \\<noteq> None\"\n    using aux[OF order.refl ws_def(2)]\n    by (fastforce simp: ru'_def)\n  obtain v' t b where tb_def: \"ru' \\<phi> v = Some (v', (t, b))\"\n    using ru_Some\n    by auto\n  show ?thesis\n    using reaches_on_n[OF ws_def(1)] tb_def vydra_sound'[OF reaches_on_n[OF ws_def(1)] tb_def prog(2,3)]\n    by (auto simp: ws_def(3))\nqed\n\nlemma map_option_apfst_idle: \"map_option (apfst snd) (map_option (apfst (Pair n)) x) = x\"\n  by (cases x) auto\n\nlemma vydra_sound:\n  assumes \"reaches (run_vydra run_hd) (init_vydra init_hd run_hd \\<phi>) n v\" \"run_vydra run_hd v = Some (v', (t, b))\" \"bounded_future_fmla \\<phi>\" \"wf_fmla \\<phi>\"\n  shows \"(t, b) = (\\<tau> \\<sigma> n, sat \\<phi> n)\"\nproof -\n  have fst_v: \"fst v = msize_fmla \\<phi>\"\n    by (rule reaches_invar[OF assms(1)]) (auto simp: init_vydra_def run_vydra_def Let_def)\n  have \"reaches (ru' \\<phi>) (su' \\<phi>) n (snd v)\"\n    using reaches_cong[OF assms(1), where ?P=\"\\<lambda>(m, w). m = msize_fmla \\<phi>\" and ?g=snd]\n    by (auto simp: init_vydra_def run_vydra_def ru'_def su'_def map_option_apfst_idle Let_def simp del: sub.simps)\n  then show ?thesis\n    using vydra_sound'[OF _ _ assms(3,4)] assms(2) fst_v\n    by (auto simp: run_vydra_def ru'_def split: prod.splits)\nqed\n\nlemma vydra_complete:\n  assumes prefix: \"reaches_on run_hd init_hd vs e\"\n    and prog: \"n < progress \\<phi> (map fst vs)\" \"bounded_future_fmla \\<phi>\" \"wf_fmla \\<phi>\"\n  shows \"\\<exists>v v'. reaches (run_vydra run_hd) (init_vydra init_hd run_hd \\<phi>) n v \\<and> run_vydra run_hd v = Some (v', (\\<tau> \\<sigma> n, sat \\<phi> n))\"\nproof -\n  obtain v v' where wits: \"reaches (ru' \\<phi>) (su' \\<phi>) n v\" \"ru' \\<phi> v = Some (v', \\<tau> \\<sigma> n, sat \\<phi> n)\"\n    using vydra_complete'[OF assms]\n    by auto\n  have reach: \"reaches (run_vydra run_hd) (init_vydra init_hd run_hd \\<phi>) n (msize_fmla \\<phi>, v)\"\n    using reaches_cong[OF wits(1), where ?P=\"\\<lambda>x. True\" and ?f'=\"run_vydra run_hd\" and ?g=\"Pair (msize_fmla \\<phi>)\"]\n    by (auto simp: init_vydra_def run_vydra_def ru'_def su'_def Let_def simp del: sub.simps)\n  show ?thesis\n    apply (rule exI[of _ \"(msize_fmla \\<phi>, v)\"])\n    apply (rule exI[of _ \"(msize_fmla \\<phi>, v')\"])\n    apply (auto simp: run_vydra_def wits(2)[unfolded ru'_def] intro: reach)\n    done\nqed\n\nend\n\ncontext MDL\nbegin\n\nlemma reach_elem:\n  assumes \"reaches (\\<lambda>i. if P i then Some (Suc i, (\\<tau> \\<sigma> i, \\<Gamma> \\<sigma> i)) else None) s n s'\" \"s = 0\"\n  shows \"s' = n\"\nproof -\n  obtain vs where vs_def: \"reaches_on (\\<lambda>i. if P i then Some (Suc i, (\\<tau> \\<sigma> i, \\<Gamma> \\<sigma> i)) else None) s vs s'\" \"length vs = n\"\n    using reaches_on[OF assms(1)]\n    by auto\n  have \"s' = length vs\"\n    using vs_def(1) assms(2)\n    by (induction s vs s' rule: reaches_on_rev_induct) (auto split: if_splits)\n  then show ?thesis\n    using vs_def(2)\n    by auto\nqed\n\ninterpretation default_vydra: VYDRA_MDL \\<sigma> 0 \"\\<lambda>i. Some (Suc i, (\\<tau> \\<sigma> i, \\<Gamma> \\<sigma> i))\"\n  using reach_elem[where ?P=\"\\<lambda>_. True\"]\n  by unfold_locales auto\n\nend\n\nlemma reaches_inj: \"reaches r s i t \\<Longrightarrow> reaches r s i t' \\<Longrightarrow> t = t'\"\n  using reaches_on_inj reaches_on\n  by metis\n\nlemma progress_sound:\n  assumes\n    \"\\<And>n. n < length ts \\<Longrightarrow> ts ! n = \\<tau> \\<sigma> n\"\n    \"\\<And>n. n < length ts \\<Longrightarrow> \\<tau> \\<sigma> n = \\<tau> \\<sigma>' n\"\n    \"\\<And>n. n < length ts \\<Longrightarrow> \\<Gamma> \\<sigma> n = \\<Gamma> \\<sigma>' n\"\n    \"n < progress phi ts\"\n    \"bounded_future_fmla phi\"\n    \"wf_fmla phi\"\n  shows \"MDL.sat \\<sigma> phi n \\<longleftrightarrow> MDL.sat \\<sigma>' phi n\"\nproof -\n  define run_hd where \"run_hd = (\\<lambda>i. if i < length ts then Some (Suc i, (\\<tau> \\<sigma> i, \\<Gamma> \\<sigma> i)) else None)\"\n  interpret vydra: VYDRA_MDL \\<sigma> 0 run_hd\n    using MDL.reach_elem[where ?P=\"\\<lambda>i. i < length ts\"]\n    by unfold_locales (auto simp: run_hd_def split: if_splits)\n  define run_hd' where \"run_hd' = (\\<lambda>i. if i < length ts then Some (Suc i, (\\<tau> \\<sigma>' i, \\<Gamma> \\<sigma>' i)) else None)\"\n  interpret vydra': VYDRA_MDL \\<sigma>' 0 run_hd'\n    using MDL.reach_elem[where ?P=\"\\<lambda>i. i < length ts\"]\n    by unfold_locales (auto simp: run_hd'_def split: if_splits)\n  have run_hd_hd': \"run_hd = run_hd'\"\n    using assms(1-3)\n    by (auto simp: run_hd_def run_hd'_def)\n  have reaches_run_hd: \"n \\<le> length ts \\<Longrightarrow> reaches_on run_hd 0 (map (\\<lambda>i. (\\<tau> \\<sigma> i, \\<Gamma> \\<sigma> i)) [0..<n]) n\" for n\n    by (induction n) (auto simp: run_hd_def intro: reaches_on.intros(1) intro!: reaches_on_app)\n  have ts_map: \"ts = map fst (map (\\<lambda>i. (\\<tau> \\<sigma> i, \\<Gamma> \\<sigma> i)) [0..<length ts])\"\n    by (subst map_nth[symmetric]) (auto simp: assms(1))\n  obtain v v' where vv_def: \"reaches (run_vydra run_hd) (init_vydra 0 run_hd phi) n v\" \"run_vydra run_hd v = Some (v', \\<tau> \\<sigma> n, vydra.sat phi n)\"\n    using vydra.vydra_complete[OF reaches_run_hd[OF order.refl] _ assms(5,6)] assms(4)\n    unfolding ts_map[symmetric]\n    by blast\n  have reaches_run_hd': \"n \\<le> length ts \\<Longrightarrow> reaches_on run_hd' 0 (map (\\<lambda>i. (\\<tau> \\<sigma>' i, \\<Gamma> \\<sigma>' i)) [0..<n]) n\" for n\n    by (induction n) (auto simp: run_hd'_def intro: reaches_on.intros(1) intro!: reaches_on_app)\n  have ts'_map: \"ts = map fst (map (\\<lambda>i. (\\<tau> \\<sigma>' i, \\<Gamma> \\<sigma>' i)) [0..<length ts])\"\n    by (subst map_nth[symmetric]) (auto simp: assms(1,2))\n  obtain w w' where ww_def: \"reaches (run_vydra run_hd') (init_vydra 0 run_hd' phi) n w\" \"run_vydra run_hd' w = Some (w', \\<tau> \\<sigma>' n, vydra'.sat phi n)\"\n    using vydra'.vydra_complete[OF reaches_run_hd'[OF order.refl] _ assms(5,6)] assms(4)\n    unfolding ts'_map[symmetric]\n    by blast\n  note v_w = reaches_inj[OF vv_def(1) ww_def(1)[folded run_hd_hd']]\n  show ?thesis\n    using vv_def(2) ww_def(2)\n    by (auto simp: run_hd_hd' v_w)\nqed\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/VYDRA_MDL/Monitor.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6442251064863697, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.2995012643237018}}
{"text": "(*\n * Copyright 2016, Data61, CSIRO\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(DATA61_BSD)\n *)\nsection \\<open>Annotations, assertions and associated operations\\<close>\n\ntheory OG_Annotations\nimports SmallStep\nbegin\n\ntype_synonym 's assn = \"'s set\"\n\ndatatype ('s, dead 'p, dead 'f) ann =\n    AnnExpr \"'s assn\" \n  | AnnRec \"'s assn\" \"('s, 'p, 'f) ann\"\n  | AnnWhile \"'s assn\" \"'s assn\" \"('s, 'p, 'f) ann\"\n  | AnnComp \"('s, 'p, 'f) ann\" \"('s, 'p, 'f) ann\"\n  | AnnBin \"'s assn\" \"('s, 'p, 'f) ann\" \"('s, 'p, 'f) ann\"\n  | AnnPar \"(('s, 'p, 'f) ann \\<times> 's assn \\<times> 's assn) list\"\n  | AnnCall \"'s assn\" nat\n\ntype_synonym ('s, 'p, 'f) ann_triple = \"('s, 'p, 'f) ann \\<times> 's assn \\<times> 's assn\"\n\ntext \\<open>\n The list of \\<open>ann_triple\\<close> is useful if the code calls the same function multiple times\n and require different annotations for the function body each time.\n\\<close>\ntype_synonym ('s,'p,'f) proc_assns = \"'p \\<Rightarrow> (('s, 'p, 'f) ann) list option\"\n\nabbreviation  (input) pres:: \"('s, 'p, 'f) ann_triple \\<Rightarrow> ('s, 'p, 'f) ann\"\nwhere \"pres a \\<equiv> fst a\"\n\nabbreviation (input) postcond :: \"('s, 'p, 'f) ann_triple \\<Rightarrow> 's assn\"\nwhere \"postcond a \\<equiv> fst (snd a)\"\n\nabbreviation (input) abrcond :: \"('s, 'p, 'f) ann_triple \\<Rightarrow> 's assn\"\nwhere \"abrcond a \\<equiv> snd (snd a)\"\n\nfun pre :: \"('s, 'p, 'f) ann \\<Rightarrow> 's assn\" where\n  \"pre (AnnExpr r)      = r\"                                                                                               \n| \"pre (AnnRec r e)     = r\"\n| \"pre (AnnWhile r i e) = r\"\n| \"pre (AnnComp e\\<^sub>1 e\\<^sub>2)   =  pre e\\<^sub>1\"\n| \"pre (AnnBin r e\\<^sub>1 e\\<^sub>2)  = r\"\n| \"pre (AnnPar as)      = \\<Inter> (pre ` set (map pres (as)))\"\n| \"pre (AnnCall r n)    = r\"\n\nfun pre_par :: \"('s, 'p, 'f) ann \\<Rightarrow> bool\" where\n  \"pre_par (AnnComp e\\<^sub>1 e\\<^sub>2) =  pre_par e\\<^sub>1\"\n| \"pre_par (AnnPar as)  = True\"\n| \"pre_par _    = False\"\n\nfun pre_set :: \"('s, 'p, 'f) ann \\<Rightarrow> ('s assn) set\" where\n  \"pre_set (AnnExpr r)      = {r}\"\n| \"pre_set (AnnRec r e)     = {r}\"\n| \"pre_set (AnnWhile r i e) = {r}\"\n| \"pre_set (AnnComp e\\<^sub>1 e\\<^sub>2)   =  pre_set e\\<^sub>1\"\n| \"pre_set (AnnBin r e\\<^sub>1 e\\<^sub>2)  = {r}\"\n| \"pre_set (AnnPar as)       = \\<Union> (pre_set ` set (map pres (as)))\"\n(*| \"pre_set (AnnPar e\\<^sub>1 e\\<^sub>2)    = pre_set (pres e\\<^sub>1) \\<union> pre_set (pres e\\<^sub>2)\" *)\n| \"pre_set (AnnCall r n)    = {r}\"\n\nlemma fst_BNFs[simp]:\n  \"a \\<in> Basic_BNFs.fsts (a,b)\"\n   using fsts.intros by auto\n\nlemma \"\\<not>pre_par c  \\<Longrightarrow> pre c \\<in> pre_set c\"\n  by (induct c; simp)\n\nlemma pre_set:\n  \"pre c = \\<Inter> (pre_set c)\"\n  by (induct c; fastforce)\n\nlemma pre_imp_pre_set:\n  \"s \\<in> pre c \\<Longrightarrow> a \\<in> pre_set c \\<Longrightarrow> s \\<in> a\"\n  by (simp add: pre_set)\n\nabbreviation precond :: \"('s, 'p, 'f) ann_triple \\<Rightarrow> 's assn\"\nwhere \"precond a \\<equiv> pre (fst a)\"\n\nfun strengthen_pre :: \"('s, 'p, 'f) ann \\<Rightarrow> 's assn \\<Rightarrow> ('s, 'p, 'f) ann\" where\n  \"strengthen_pre (AnnExpr r)      r' = AnnExpr (r \\<inter> r')\"                                                                                               \n| \"strengthen_pre (AnnRec r e)     r' = AnnRec (r \\<inter> r') e\"\n| \"strengthen_pre (AnnWhile r i e) r' = AnnWhile (r \\<inter> r') i e\"\n| \"strengthen_pre (AnnComp e\\<^sub>1 e\\<^sub>2)   r' = AnnComp (strengthen_pre e\\<^sub>1 r') e\\<^sub>2\"\n| \"strengthen_pre (AnnBin r e\\<^sub>1 e\\<^sub>2) r' = AnnBin (r \\<inter> r') e\\<^sub>1 e\\<^sub>2\"\n| \"strengthen_pre (AnnPar as)    r' = (AnnPar as)\"\n| \"strengthen_pre (AnnCall r n)    r' = AnnCall (r \\<inter> r') n\"\n\nfun weaken_pre :: \"('s, 'p, 'f) ann \\<Rightarrow> 's assn \\<Rightarrow> ('s, 'p, 'f) ann\" where\n  \"weaken_pre (AnnExpr r)      r' = AnnExpr (r \\<union> r')\"                                                                                               \n| \"weaken_pre (AnnRec r e)     r' = AnnRec (r \\<union> r') e\"\n| \"weaken_pre (AnnWhile r i e) r' = AnnWhile (r \\<union> r') i e\"\n| \"weaken_pre (AnnComp e\\<^sub>1 e\\<^sub>2)   r' = AnnComp (weaken_pre e\\<^sub>1 r') e\\<^sub>2\"\n| \"weaken_pre (AnnBin r e\\<^sub>1 e\\<^sub>2) r' = AnnBin (r \\<union> r') e\\<^sub>1 e\\<^sub>2\"\n| \"weaken_pre (AnnPar as)   r' = AnnPar as\"\n| \"weaken_pre (AnnCall r n)    r' = AnnCall (r \\<union> r') n\"\n\nlemma weaken_pre_empty[simp]:\n  \"weaken_pre r {} = r\"\n  by (induct r) auto\n\ntext \\<open>Annotations for call definition (see Language.thy)\\<close>\ndefinition\n ann_call :: \"'s assn \\<Rightarrow> 's assn \\<Rightarrow> nat \\<Rightarrow>  's assn \\<Rightarrow>'s assn \\<Rightarrow>  's assn \\<Rightarrow> 's assn \\<Rightarrow> ('s,'p,'f) ann\"\nwhere\n \"ann_call init r n restoreq return restorea A \\<equiv> \n  AnnRec init (AnnComp (AnnComp (AnnComp (AnnExpr init) (AnnCall r n)) (AnnComp (AnnExpr restorea) (AnnExpr A)))\n          (AnnRec restoreq (AnnComp (AnnExpr restoreq) (AnnExpr return))))\"\n\n\ninductive ann_matches :: \"('s,'p,'f) body \\<Rightarrow> ('s,'p,'f) proc_assns \\<Rightarrow> ('s, 'p, 'f) ann \\<Rightarrow> ('s, 'p, 'f) com \\<Rightarrow> bool\" where\n  ann_skip: \"ann_matches \\<Gamma> \\<Theta> (AnnExpr a) Skip\"\n| ann_basic: \"ann_matches \\<Gamma> \\<Theta> (AnnExpr a) (Basic f)\"\n| ann_spec: \"ann_matches \\<Gamma> \\<Theta> (AnnExpr a) (Spec r)\"\n| ann_throw: \"ann_matches \\<Gamma> \\<Theta> (AnnExpr a) (Throw)\"\n| ann_await: \"ann_matches \\<Gamma> \\<Theta> a e \\<Longrightarrow>\n               ann_matches \\<Gamma> \\<Theta> (AnnRec r a) (Await b e)\"\n| ann_seq: \"\\<lbrakk> ann_matches \\<Gamma> \\<Theta> a1 p1; ann_matches \\<Gamma> \\<Theta> a2 p2 \\<rbrakk> \\<Longrightarrow>\n               ann_matches \\<Gamma> \\<Theta> (AnnComp a1 a2) (Seq p1 p2)\"\n| ann_cond: \"\\<lbrakk> ann_matches \\<Gamma> \\<Theta> a1 c1; ann_matches \\<Gamma> \\<Theta> a2 c2 \\<rbrakk> \\<Longrightarrow>\n               ann_matches \\<Gamma> \\<Theta> (AnnBin a a1 a2) (Cond b c1 c2)\"\n| ann_catch: \"\\<lbrakk> ann_matches \\<Gamma> \\<Theta> a1 c1; ann_matches \\<Gamma> \\<Theta> a2 c2 \\<rbrakk> \\<Longrightarrow>\n                ann_matches \\<Gamma> \\<Theta> (AnnComp a1 a2) (Catch c1 c2)\"\n| ann_while: \"ann_matches \\<Gamma> \\<Theta> a' e \\<Longrightarrow>\n                ann_matches \\<Gamma> \\<Theta> (AnnWhile a i a') (While b e)\"\n| ann_guard: \"\\<lbrakk> ann_matches \\<Gamma> \\<Theta> a' e \\<rbrakk> \\<Longrightarrow> \n                ann_matches \\<Gamma> \\<Theta> (AnnRec a a') (Guard f b e)\"\n| ann_call: \"\\<lbrakk> \\<Theta> f = Some as; \\<Gamma> f = Some b; n < length as;\n               ann_matches \\<Gamma> \\<Theta> (as!n) b\\<rbrakk> \\<Longrightarrow>\n   ann_matches \\<Gamma> \\<Theta> (AnnCall a n) (Call f)\"\n| ann_dyncom: \"\\<forall>s\\<in>r. ann_matches \\<Gamma> \\<Theta> a (c s) \\<Longrightarrow>\n               ann_matches \\<Gamma> \\<Theta> (AnnRec r a) (DynCom c)\"\n| ann_parallel: \"\\<lbrakk> length as = length cs;\n                   \\<forall>i<length cs. ann_matches \\<Gamma> \\<Theta> (pres (as!i)) (cs!i) \\<rbrakk> \\<Longrightarrow>\n   ann_matches \\<Gamma> \\<Theta> (AnnPar as) (Parallel cs)\"\n\nprimrec ann_guards:: \"'s assn \\<Rightarrow> ('f \\<times> 's bexp ) list \\<Rightarrow>\n                  ('s,'p,'f) ann \\<Rightarrow> ('s,'p,'f) ann\"\nwhere\n  \"ann_guards _ [] c = c\" |\n  \"ann_guards r (g#gs) c = AnnRec r (ann_guards (r \\<inter> snd g) gs c)\"\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Complx/OG_Annotations.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5851011686727232, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.2994059834416451}}
{"text": "section Occurrences\n\ntext \\<open>This theory contains all of the definitions and laws required for reasoning about\n  identifiers that occur in the data structures of the concurrent revisions model.\\<close>\n\ntheory Occurrences\n  imports Data\nbegin\n\nsubsection Definitions\n\nsubsubsection \\<open>Revision identifiers\\<close>\n\ndefinition RID\\<^sub>S :: \"('r,'l,'v) store \\<Rightarrow> 'r set\" where\n  \"RID\\<^sub>S \\<sigma> \\<equiv> \\<Union> (RID\\<^sub>V ` ran \\<sigma>)\"\n\ndefinition RID\\<^sub>L :: \"('r,'l,'v) local_state \\<Rightarrow> 'r set\" where\n  \"RID\\<^sub>L s \\<equiv> case s of (\\<sigma>, \\<tau>, e) \\<Rightarrow> RID\\<^sub>S \\<sigma> \\<union> RID\\<^sub>S \\<tau> \\<union> RID\\<^sub>E e\"\n\ndefinition RID\\<^sub>G :: \"('r,'l,'v) global_state \\<Rightarrow> 'r set\" where\n  \"RID\\<^sub>G s \\<equiv> dom s \\<union> \\<Union> (RID\\<^sub>L ` ran s)\"\n\nsubsubsection \\<open>Location identifiers\\<close>\n\ndefinition LID\\<^sub>S :: \"('r,'l,'v) store \\<Rightarrow> 'l set\" where\n  \"LID\\<^sub>S \\<sigma> \\<equiv> dom \\<sigma> \\<union> \\<Union> (LID\\<^sub>V ` ran \\<sigma>)\"\n\ndefinition LID\\<^sub>L :: \"('r,'l,'v) local_state \\<Rightarrow> 'l set\" where\n  \"LID\\<^sub>L s \\<equiv> case s of (\\<sigma>, \\<tau>, e) \\<Rightarrow> LID\\<^sub>S \\<sigma> \\<union> LID\\<^sub>S \\<tau> \\<union> LID\\<^sub>E e\"\n\ndefinition LID\\<^sub>G :: \"('r,'l,'v) global_state \\<Rightarrow> 'l set\" where\n  \"LID\\<^sub>G s \\<equiv> \\<Union> (LID\\<^sub>L ` ran s)\"\n\nsubsection \\<open>Inference rules\\<close>\n\nsubsubsection \\<open>Introduction and elimination rules\\<close>\n\nlemma RID\\<^sub>SI [intro]: \"\\<sigma> l = Some v \\<Longrightarrow> r \\<in> RID\\<^sub>V v \\<Longrightarrow> r \\<in> RID\\<^sub>S \\<sigma>\"\n  by (auto simp add: RID\\<^sub>S_def ran_def)\n\nlemma RID\\<^sub>SE [elim]: \"r \\<in> RID\\<^sub>S \\<sigma> \\<Longrightarrow> (\\<And>l v. \\<sigma> l = Some v \\<Longrightarrow> r \\<in> RID\\<^sub>V v \\<Longrightarrow> P) \\<Longrightarrow> P\"\n  by (auto simp add: RID\\<^sub>S_def ran_def)\n\nlemma RID\\<^sub>LI [intro, consumes 1]:\n  assumes \"s = (\\<sigma>, \\<tau>, e)\"\n  shows\n    \"r \\<in> RID\\<^sub>S \\<sigma> \\<Longrightarrow> r \\<in> RID\\<^sub>L s\"\n    \"r \\<in> RID\\<^sub>S \\<tau> \\<Longrightarrow> r \\<in> RID\\<^sub>L s\"\n    \"r \\<in> RID\\<^sub>E e \\<Longrightarrow> r \\<in> RID\\<^sub>L s\"\n  by (auto simp add: RID\\<^sub>L_def assms)\n\nlemma RID\\<^sub>LE [elim]:\n  \"\\<lbrakk> r \\<in> RID\\<^sub>L s; (\\<And>\\<sigma> \\<tau> e. s = (\\<sigma>, \\<tau>, e) \\<Longrightarrow> (r \\<in> RID\\<^sub>S \\<sigma> \\<Longrightarrow> P) \\<Longrightarrow> (r \\<in> RID\\<^sub>S \\<tau> \\<Longrightarrow> P) \\<Longrightarrow> (r \\<in> RID\\<^sub>E e \\<Longrightarrow> P) \\<Longrightarrow> P) \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P\" \n  by (cases s) (auto simp add: RID\\<^sub>L_def)\n\nlemma RID\\<^sub>GI [intro]:\n  \"s r = Some v \\<Longrightarrow> r \\<in> RID\\<^sub>G s\"\n  \"s r' = Some ls \\<Longrightarrow> r \\<in> RID\\<^sub>L ls \\<Longrightarrow> r \\<in> RID\\<^sub>G s\"\n   apply (simp add: RID\\<^sub>G_def domI)\n  by (metis (no_types, lifting) RID\\<^sub>G_def UN_I UnI2 ranI)\n\nlemma RID\\<^sub>GE [elim]:\n  assumes\n    \"r \\<in> RID\\<^sub>G s\"\n    \"r \\<in> dom s \\<Longrightarrow> P\"\n    \"\\<And>r' ls. s r' = Some ls \\<Longrightarrow> r \\<in> RID\\<^sub>L ls \\<Longrightarrow> P\"\n  shows P\n  using assms by (auto simp add: RID\\<^sub>G_def ran_def)\n\nlemma LID\\<^sub>SI [intro]:\n  \"\\<sigma> l = Some v \\<Longrightarrow> l \\<in> LID\\<^sub>S \\<sigma>\"\n  \"\\<sigma> l' = Some v \\<Longrightarrow> l \\<in> LID\\<^sub>V v \\<Longrightarrow> l \\<in> LID\\<^sub>S \\<sigma>\"\n  by (auto simp add: LID\\<^sub>S_def ran_def)\n\nlemma LID\\<^sub>SE [elim]:\n  assumes \n    \"l \\<in> LID\\<^sub>S \\<sigma>\"\n    \"l \\<in> dom \\<sigma> \\<Longrightarrow> P\"\n    \"\\<And>l' v. \\<sigma> l' = Some v \\<Longrightarrow> l \\<in> LID\\<^sub>V v \\<Longrightarrow> P\"\n  shows P\n  using assms by (auto simp add: LID\\<^sub>S_def ran_def)\n\nlemma LID\\<^sub>LI [intro]:\n  assumes \"s = (\\<sigma>, \\<tau>, e)\"\n  shows\n    \"r \\<in> LID\\<^sub>S \\<sigma> \\<Longrightarrow> r \\<in> LID\\<^sub>L s\" \n    \"r \\<in> LID\\<^sub>S \\<tau> \\<Longrightarrow> r \\<in> LID\\<^sub>L s\" \n    \"r \\<in> LID\\<^sub>E e \\<Longrightarrow> r \\<in> LID\\<^sub>L s\"\n  by (auto simp add: LID\\<^sub>L_def assms)\n\nlemma LID\\<^sub>LE [elim]:\n  \"\\<lbrakk> l \\<in> LID\\<^sub>L s; (\\<And>\\<sigma> \\<tau> e. s = (\\<sigma>, \\<tau>, e) \\<Longrightarrow> (l \\<in> LID\\<^sub>S \\<sigma> \\<Longrightarrow> P) \\<Longrightarrow> (l \\<in> LID\\<^sub>S \\<tau> \\<Longrightarrow> P) \\<Longrightarrow> (l \\<in> LID\\<^sub>E e \\<Longrightarrow> P) \\<Longrightarrow> P) \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P\" \n  by (cases s) (auto simp add: LID\\<^sub>L_def)\n\nlemma LID\\<^sub>GI [intro]: \"s r = Some ls \\<Longrightarrow> l \\<in> LID\\<^sub>L ls \\<Longrightarrow> l \\<in> LID\\<^sub>G s\"\n  by (auto simp add: LID\\<^sub>G_def LID\\<^sub>L_def ran_def)\n\nlemma LID\\<^sub>GE [elim]: \"l \\<in> LID\\<^sub>G s \\<Longrightarrow> (\\<And>r ls. s r = Some ls \\<Longrightarrow> l \\<in> LID\\<^sub>L ls \\<Longrightarrow> P) \\<Longrightarrow> P\"\n  by (auto simp add: LID\\<^sub>G_def ran_def)\n\nsubsubsection \\<open>Distributive laws\\<close>\n\nlemma ID_distr_completion [simp]: \n  \"RID\\<^sub>E (\\<E>[e]) = RID\\<^sub>C \\<E> \\<union> RID\\<^sub>E e\"\n  \"LID\\<^sub>E (\\<E>[e]) = LID\\<^sub>C \\<E> \\<union> LID\\<^sub>E e\"\n  by (induct rule: plug.induct) auto\n\nlemma ID_restricted_store_subset_store: \n  \"RID\\<^sub>S (\\<sigma>(l := None)) \\<subseteq> RID\\<^sub>S \\<sigma>\"\n  \"LID\\<^sub>S (\\<sigma>(l := None)) \\<subseteq> LID\\<^sub>S \\<sigma>\"\nproof -\n  show \"RID\\<^sub>S (\\<sigma>(l := None)) \\<subseteq> RID\\<^sub>S \\<sigma>\"\n  proof (rule subsetI)\n    fix r\n    assume \"r \\<in> RID\\<^sub>S (\\<sigma>(l := None))\"\n    then obtain l' v where \"(\\<sigma>(l := None)) l' = Some v\" and r_v: \"r \\<in> RID\\<^sub>V v\" by blast\n    have \"l' \\<noteq> l\" using \\<open>(\\<sigma>(l := None)) l' = Some v\\<close> by auto\n    hence \"\\<sigma> l' = Some v\" using \\<open>(\\<sigma>(l := None)) l' = Some v\\<close> by auto\n    thus \"r \\<in> RID\\<^sub>S \\<sigma>\" using r_v by blast\n  qed\nnext\n  show \"LID\\<^sub>S (\\<sigma>(l := None)) \\<subseteq> LID\\<^sub>S \\<sigma>\"\n  proof (rule subsetI)\n    fix l'\n    assume \"l' \\<in> LID\\<^sub>S (\\<sigma>(l := None))\"\n    hence \"l' \\<in> dom (\\<sigma>(l := None)) \\<or> (\\<exists>l'' v. (\\<sigma>(l := None)) l'' = Some v \\<and> l' \\<in> LID\\<^sub>V v)\" by blast\n    thus \"l' \\<in> LID\\<^sub>S \\<sigma>\"\n    proof (rule disjE)\n      assume \"l' \\<in> dom (\\<sigma>(l := None))\"\n      thus \"l' \\<in> LID\\<^sub>S \\<sigma>\" by auto\n    next\n      assume \"\\<exists>l'' v. (\\<sigma>(l := None)) l'' = Some v \\<and> l' \\<in> LID\\<^sub>V v\"\n      then obtain l'' v where \"(\\<sigma>(l := None)) l'' = Some v\" and l'_in_v: \"l' \\<in> LID\\<^sub>V v\" by blast\n      hence \"\\<sigma> l'' = Some v\" by (cases \"l = l''\", auto)\n      thus \"l' \\<in> LID\\<^sub>S \\<sigma>\" using l'_in_v by blast\n    qed\n  qed\nqed\n\nlemma in_restricted_store_in_unrestricted_store [intro]: \n  \"r \\<in> RID\\<^sub>S (\\<sigma>(l := None)) \\<Longrightarrow> r \\<in> RID\\<^sub>S \\<sigma>\"\n  \"l' \\<in> LID\\<^sub>S (\\<sigma>(l := None)) \\<Longrightarrow> l' \\<in> LID\\<^sub>S \\<sigma>\" \n  by (meson contra_subsetD ID_restricted_store_subset_store)+\n\nlemma in_restricted_store_in_updated_store [intro]: \n  \"r \\<in> RID\\<^sub>S (\\<sigma>(l := None)) \\<Longrightarrow> r \\<in> RID\\<^sub>S (\\<sigma>(l \\<mapsto> v))\" \n  \"l' \\<in> LID\\<^sub>S (\\<sigma>(l := None)) \\<Longrightarrow> l' \\<in> LID\\<^sub>S (\\<sigma>(l \\<mapsto> v))\"\nproof -\n  assume \"r \\<in> RID\\<^sub>S (\\<sigma>(l := None))\"\n  hence \"r \\<in> RID\\<^sub>S (\\<sigma> |` (- {l}))\" by (simp add: restrict_complement_singleton_eq)\n  hence \"r \\<in> RID\\<^sub>S (\\<sigma>(l \\<mapsto> v) |` (- {l}))\" by simp\n  hence \"r \\<in> RID\\<^sub>S (\\<sigma>(l := Some v, l := None))\" by (simp add: restrict_complement_singleton_eq)\n  thus \"r \\<in> RID\\<^sub>S (\\<sigma>(l \\<mapsto> v))\" by blast\nnext\n  assume \"l' \\<in> LID\\<^sub>S (\\<sigma>(l := None))\"\n  hence \"l' \\<in> LID\\<^sub>S (\\<sigma> |` (- {l}))\" by (simp add: restrict_complement_singleton_eq)\n  hence \"l' \\<in> LID\\<^sub>S (\\<sigma>(l \\<mapsto> v) |` (- {l}))\" by simp\n  hence \"l' \\<in> LID\\<^sub>S (\\<sigma>(l := Some v, l := None))\" by (simp add: restrict_complement_singleton_eq)\n  thus \"l' \\<in> LID\\<^sub>S (\\<sigma>(l \\<mapsto> v))\" by blast\nqed\n\nlemma ID_distr_store [simp]:\n  \"RID\\<^sub>S (\\<tau>(l \\<mapsto> v)) = RID\\<^sub>S (\\<tau>(l := None)) \\<union> RID\\<^sub>V v\"\n  \"LID\\<^sub>S (\\<tau>(l \\<mapsto> v)) = insert l (LID\\<^sub>S (\\<tau>(l := None)) \\<union> LID\\<^sub>V v)\"\nproof -\n  show \"RID\\<^sub>S (\\<tau>(l \\<mapsto> v)) = RID\\<^sub>S (\\<tau>(l := None)) \\<union> RID\\<^sub>V v\"\n  proof (rule set_eqI, rule iffI)\n    fix r\n    assume \"r \\<in> RID\\<^sub>S (\\<tau>(l \\<mapsto> v))\"\n    then obtain l' v' where \"(\\<tau>(l \\<mapsto> v)) l' = Some v'\" \"r \\<in> RID\\<^sub>V v'\" by blast\n    thus \"r \\<in> RID\\<^sub>S (\\<tau>(l := None)) \\<union> RID\\<^sub>V v\" by (cases \"l' = l\") auto\n  qed auto\nnext\n  show \"LID\\<^sub>S (\\<tau>(l \\<mapsto> v)) = insert l (LID\\<^sub>S (\\<tau>(l := None)) \\<union> LID\\<^sub>V v)\"\n  proof (rule set_eqI, rule iffI)\n    fix l'\n    assume \"l' \\<in> LID\\<^sub>S (\\<tau>(l \\<mapsto> v))\"\n    hence \"l' \\<in> dom (\\<tau>(l \\<mapsto> v)) \\<or> (\\<exists>l'' v'. (\\<tau>(l \\<mapsto> v)) l'' = Some v' \\<and> l' \\<in> LID\\<^sub>V v')\" by blast\n    thus \"l' \\<in> insert l (LID\\<^sub>S (\\<tau>(l := None)) \\<union> LID\\<^sub>V v)\"\n    proof (rule disjE)\n      assume \"l' \\<in> dom (\\<tau>(l \\<mapsto> v))\"\n      thus \"l' \\<in> insert l (LID\\<^sub>S (\\<tau>(l := None)) \\<union> LID\\<^sub>V v)\" by (cases \"l' = l\") auto\n    next\n      assume \"\\<exists>l'' v'. (\\<tau>(l \\<mapsto> v)) l'' = Some v' \\<and> l' \\<in> LID\\<^sub>V v'\"\n      then obtain l'' v' where \"(\\<tau>(l \\<mapsto> v)) l'' = Some v'\" \"l' \\<in> LID\\<^sub>V v'\" by blast\n      thus \"l' \\<in> insert l (LID\\<^sub>S (\\<tau>(l := None)) \\<union> LID\\<^sub>V v)\" by (cases \"l = l''\") auto\n    qed\n  qed auto\nqed\n\nlemma ID_distr_local [simp]: \n  \"LID\\<^sub>L (\\<sigma>,\\<tau>,e) = LID\\<^sub>S \\<sigma> \\<union> LID\\<^sub>S \\<tau> \\<union> LID\\<^sub>E e\"\n  \"RID\\<^sub>L (\\<sigma>,\\<tau>,e) = RID\\<^sub>S \\<sigma> \\<union> RID\\<^sub>S \\<tau> \\<union> RID\\<^sub>E e\"\n  by (simp add: LID\\<^sub>L_def RID\\<^sub>L_def)+\n\nlemma ID_restricted_global_subset_unrestricted:\n  \"LID\\<^sub>G (s(r := None)) \\<subseteq> LID\\<^sub>G s\"\n  \"RID\\<^sub>G (s(r := None)) \\<subseteq> RID\\<^sub>G s\"\nproof -\n  show \"LID\\<^sub>G (s(r := None)) \\<subseteq> LID\\<^sub>G s\"\n  proof (rule subsetI)\n    fix l\n    assume \"l \\<in> LID\\<^sub>G (s(r := None))\"\n    then obtain r'' ls where \"(s(r := None)) r'' = Some ls\" and l_in_ls: \"l \\<in> LID\\<^sub>L ls\" by blast\n    have \"r'' \\<noteq> r \" using \\<open>(s(r := None)) r'' = Some ls\\<close> by auto\n    hence \"s r'' = Some ls\" using \\<open>(s(r := None)) r'' = Some ls\\<close> by auto\n    thus \"l \\<in> LID\\<^sub>G s\" using l_in_ls by blast\n  qed\nnext\n  show \"RID\\<^sub>G (s(r := None)) \\<subseteq> RID\\<^sub>G s\"\n  proof (rule subsetI)\n    fix r'\n    assume \"r' \\<in> RID\\<^sub>G (s(r := None))\"\n    hence \"r' \\<in> dom (s(r := None)) \\<or> (\\<exists>r'' ls. (s(r := None)) r'' = Some ls \\<and> r' \\<in> RID\\<^sub>L ls)\" by blast\n    thus \"r' \\<in> RID\\<^sub>G s\"\n    proof (rule disjE)\n      assume \"\\<exists>r'' ls. (s(r := None)) r'' = Some ls \\<and> r' \\<in> RID\\<^sub>L ls\"\n      then obtain r'' ls where \"(s(r := None)) r'' = Some ls\" and r'_in_ls: \"r' \\<in> RID\\<^sub>L ls\" by blast\n      have neq: \"r'' \\<noteq> r\" using \\<open>(s(r := None)) r'' = Some ls\\<close> by auto\n      hence \"s r'' = Some ls\" using \\<open>(s(r := None)) r'' = Some ls\\<close> by auto\n      thus \"r' \\<in> RID\\<^sub>G s\" using r'_in_ls by blast\n    qed auto\n  qed\nqed\n\nlemma in_restricted_global_in_unrestricted_global [intro]: \n  \"r' \\<in> RID\\<^sub>G (s(r := None)) \\<Longrightarrow> r' \\<in> RID\\<^sub>G s\"\n  \"l \\<in> LID\\<^sub>G (s(r := None)) \\<Longrightarrow> l \\<in> LID\\<^sub>G s\"\n  by (simp add: ID_restricted_global_subset_unrestricted rev_subsetD)+\n\nlemma in_restricted_global_in_updated_global [intro]: \n  \"r' \\<in> RID\\<^sub>G (s(r := None)) \\<Longrightarrow> r' \\<in> RID\\<^sub>G (s(r \\<mapsto> ls))\" \n  \"l \\<in> LID\\<^sub>G (s(r := None)) \\<Longrightarrow> l \\<in> LID\\<^sub>G (s(r \\<mapsto> ls))\"\nproof -\n  assume \"r' \\<in> RID\\<^sub>G (s(r := None))\"\n  hence \"r' \\<in> RID\\<^sub>G (s |` (- {r}))\" by (simp add: restrict_complement_singleton_eq)\n  hence \"r' \\<in> RID\\<^sub>G (s(r \\<mapsto> ls) |` (- {r}))\" by simp\n  hence \"r' \\<in> RID\\<^sub>G (s(r := Some ls, r := None))\" by (simp add: restrict_complement_singleton_eq)\n  thus \"r' \\<in> RID\\<^sub>G (s(r \\<mapsto> ls))\" by blast\nnext\n  assume \"l \\<in> LID\\<^sub>G (s(r := None))\"\n  hence \"l \\<in> LID\\<^sub>G (s |` (- {r}))\" by (simp add: restrict_complement_singleton_eq)\n  hence \"l \\<in> LID\\<^sub>G (s(r \\<mapsto> ls) |` (- {r}))\" by simp\n  hence \"l \\<in> LID\\<^sub>G (s(r := Some ls, r := None))\" by (simp add: restrict_complement_singleton_eq)\n  thus \"l \\<in> LID\\<^sub>G (s(r \\<mapsto> ls))\" by blast\nqed\n\nlemma ID_distr_global [simp]:\n  \"RID\\<^sub>G (s(r \\<mapsto> ls)) = insert r (RID\\<^sub>G (s(r := None)) \\<union> RID\\<^sub>L ls)\"\n  \"LID\\<^sub>G (s(r \\<mapsto> ls)) = LID\\<^sub>G (s(r := None)) \\<union> LID\\<^sub>L ls\"\nproof -\n  show \"LID\\<^sub>G (s(r \\<mapsto> ls)) = LID\\<^sub>G (s(r := None)) \\<union> LID\\<^sub>L ls\"\n  proof (rule set_eqI)\n    fix l\n    show \"(l \\<in> LID\\<^sub>G (s(r \\<mapsto> ls))) = (l \\<in> LID\\<^sub>G (s(r := None)) \\<union> LID\\<^sub>L ls)\"\n    proof (rule iffI)\n      assume \"l \\<in> LID\\<^sub>G (s(r \\<mapsto> ls))\"\n      from this obtain r' ls' where \"(s(r \\<mapsto> ls)) r' = Some ls'\" \"l \\<in> LID\\<^sub>L ls'\" by auto\n      thus \"l \\<in> LID\\<^sub>G (s(r := None)) \\<union> LID\\<^sub>L ls\" by (cases \"r = r'\") auto\n    qed auto\n  qed\n  show \"RID\\<^sub>G (s(r \\<mapsto> ls)) = insert r (RID\\<^sub>G (s(r := None)) \\<union> RID\\<^sub>L ls)\"\n  proof (rule set_eqI)\n    fix r'\n    show \"(r' \\<in> RID\\<^sub>G (s(r \\<mapsto> ls))) = (r' \\<in> insert r (RID\\<^sub>G (s(r := None)) \\<union> RID\\<^sub>L ls))\"\n    proof (rule iffI, clarsimp)\n      assume r'_g: \"r' \\<in> RID\\<^sub>G (s(r \\<mapsto> ls))\" and neq: \"r' \\<noteq> r\" and r'_l: \"r' \\<notin> RID\\<^sub>L ls\"\n      show \"r' \\<in> RID\\<^sub>G (s(r := None))\"\n      proof (rule RID\\<^sub>GE[OF r'_g])\n        assume \"r' \\<in> dom (s(r \\<mapsto> ls))\"\n        thus ?thesis by (simp add: RID\\<^sub>G_def neq)\n      next\n        fix ls' r''\n        assume r'_in_range:\"(s(r \\<mapsto> ls)) r'' = Some ls'\" \"r' \\<in> RID\\<^sub>L ls'\"\n        thus ?thesis by (cases \"r'' = r\") (use neq r'_l in auto)\n      qed\n    qed auto\n  qed\nqed\n\nlemma restrictions_inwards [simp]:\n  \"x \\<noteq> x' \\<Longrightarrow> f(x := Some y, x' := None) = (f(x':= None, x := Some y))\"\n  by (rule fun_upd_twist)\n\nsubsubsection \\<open>Miscellaneous laws\\<close>\n\nlemma ID_combination_subset_union [intro]:\n  \"RID\\<^sub>S (\\<sigma>;;\\<tau>) \\<subseteq> RID\\<^sub>S \\<sigma> \\<union> RID\\<^sub>S \\<tau>\"\n  \"LID\\<^sub>S (\\<sigma>;;\\<tau>) \\<subseteq> LID\\<^sub>S \\<sigma> \\<union> LID\\<^sub>S \\<tau>\"\nproof -\n  show \"RID\\<^sub>S (\\<sigma>;;\\<tau>) \\<subseteq> RID\\<^sub>S \\<sigma> \\<union> RID\\<^sub>S \\<tau>\"\n  proof (rule subsetI)\n    fix r\n    assume \"r \\<in> RID\\<^sub>S (\\<sigma>;;\\<tau>)\"\n    from this obtain l v where \"(\\<sigma>;;\\<tau>) l = Some v\" and \"r \\<in> RID\\<^sub>V v\" by blast\n    thus \"r \\<in> RID\\<^sub>S \\<sigma> \\<union> RID\\<^sub>S \\<tau>\" by (cases \"l \\<in> dom \\<tau>\") auto\n  qed\n  show \"LID\\<^sub>S (\\<sigma>;;\\<tau>) \\<subseteq> LID\\<^sub>S \\<sigma> \\<union> LID\\<^sub>S \\<tau>\"\n  proof (rule subsetI)\n    fix l\n    assume \"l \\<in> LID\\<^sub>S (\\<sigma>;;\\<tau>)\"\n    hence \"l \\<in> dom (\\<sigma>;;\\<tau>) \\<or> (\\<exists>l' v. (\\<sigma>;;\\<tau>) l' = Some v \\<and> l \\<in> LID\\<^sub>V v)\" by blast\n    thus \"l \\<in> LID\\<^sub>S \\<sigma> \\<union> LID\\<^sub>S \\<tau>\"\n    proof (rule disjE)\n      assume \"l \\<in> dom (\\<sigma>;;\\<tau>)\"\n      thus \"l \\<in> LID\\<^sub>S \\<sigma> \\<union> LID\\<^sub>S \\<tau>\" by (cases \"l \\<in> dom \\<tau>\") auto\n    next \n      assume \"\\<exists>l' v. (\\<sigma>;;\\<tau>) l' = Some v \\<and> l \\<in> LID\\<^sub>V v\"\n      from this obtain l' v where \"(\\<sigma>;;\\<tau>) l' = Some v\" \"l \\<in> LID\\<^sub>V v\" by blast\n      thus \"l \\<in> LID\\<^sub>S \\<sigma> \\<union> LID\\<^sub>S \\<tau>\" by (cases \"l' \\<in> dom \\<tau>\") auto\n    qed\n  qed\nqed\n\nlemma in_combination_in_component [intro]: \n  \"r \\<in> RID\\<^sub>S (\\<sigma>;;\\<tau>) \\<Longrightarrow> r \\<notin> RID\\<^sub>S \\<sigma> \\<Longrightarrow> r \\<in> RID\\<^sub>S \\<tau>\"\n  \"r \\<in> RID\\<^sub>S (\\<sigma>;;\\<tau>) \\<Longrightarrow> r \\<notin> RID\\<^sub>S \\<tau> \\<Longrightarrow> r \\<in> RID\\<^sub>S \\<sigma>\"\n  \"l \\<in> LID\\<^sub>S (\\<sigma>;;\\<tau>) \\<Longrightarrow> l \\<notin> LID\\<^sub>S \\<sigma> \\<Longrightarrow> l \\<in> LID\\<^sub>S \\<tau>\"\n  \"l \\<in> LID\\<^sub>S (\\<sigma>;;\\<tau>) \\<Longrightarrow> l \\<notin> LID\\<^sub>S \\<tau> \\<Longrightarrow> l \\<in> LID\\<^sub>S \\<sigma>\"\n  by (meson Un_iff ID_combination_subset_union subsetCE)+\n\nlemma in_mapped_in_component_of_combination [intro]:\n  assumes \n    maps_to_v: \"(\\<sigma>;;\\<tau>) l = Some v\" and\n    l'_in_v: \"l' \\<in> LID\\<^sub>V v\"\n  shows\n    \"l' \\<notin> LID\\<^sub>S \\<tau> \\<Longrightarrow> l' \\<in> LID\\<^sub>S \\<sigma>\"\n    \"l' \\<notin> LID\\<^sub>S \\<sigma> \\<Longrightarrow> l' \\<in> LID\\<^sub>S \\<tau>\"\n  by (metis LID\\<^sub>SI(2) combine.simps l'_in_v maps_to_v)+\n\nlemma elim_trivial_restriction [simp]: \"l \\<notin> LID\\<^sub>S \\<tau> \\<Longrightarrow> (\\<tau>(l := None)) = \\<tau>\" \n  by (simp add: LID\\<^sub>S_def domIff fun_upd_idem)\n\nlemma ID_distr_global_conditional:\n  \"s r = Some ls \\<Longrightarrow> RID\\<^sub>G s = insert r (RID\\<^sub>G (s(r := None)) \\<union> RID\\<^sub>L ls)\"\n  \"s r = Some ls \\<Longrightarrow> LID\\<^sub>G s = LID\\<^sub>G (s(r := None)) \\<union> LID\\<^sub>L ls\"\nproof -\n  assume \"s r = Some ls\"\n  hence s_as_upd: \"s = (s(r \\<mapsto> ls))\" by (simp add: fun_upd_idem)\n  show \"RID\\<^sub>G s = insert r (RID\\<^sub>G (s(r := None)) \\<union> RID\\<^sub>L ls)\" by (subst s_as_upd, simp)\n  show \"LID\\<^sub>G s = LID\\<^sub>G (s(r := None)) \\<union> LID\\<^sub>L ls\" by (subst s_as_upd, simp)\nqed\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Concurrent_Revisions/Occurrences.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5851011542032313, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.2994059760373658}}
{"text": "(*****************************************************************************\n * Clean\n *                                                                            \n * HOL-TestGen --- theorem-prover based test case generation\n *                 http://www.brucker.ch/projects/hol-testgen/\n *                                                                            \n * Copyright (c) 2005-2007 ETH Zurich, Switzerland\n *               2009-2017 Univ. Paris-Sud, France \n *               2009-2012 Achim D. Brucker, Germany\n *               2015-2017 University Sheffield, UK\n *               2018-2019 Université Paris-Saclay, Univ. Paris-Sud, France\n *\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are\n * met:\n *\n *     * Redistributions of source code must retain the above copyright\n *       notice, this list of conditions and the following disclaimer.\n *\n *     * Redistributions in binary form must reproduce the above\n *       copyright notice, this list of conditions and the following\n *       disclaimer in the documentation and/or other materials provided\n *       with the distribution.\n *\n *     * Neither the name of the copyright holders nor the names of its\n *       contributors may be used to endorse or promote products derived\n *       from this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n ******************************************************************************)\n\n(*\n * Monads --- a base testing theory for sequential computations.\n * This file is part of HOL-TestGen.\n *)\n\ntheory MonadSE\n  imports Main\nbegin\n        \nsection\\<open>Definition : Standard State Exception Monads\\<close>\ntext\\<open>State exception monads in our sense are a direct, pure formulation\nof automata with a partial transition function.\\<close>\n\nsubsection\\<open>Definition : Core Types and Operators\\<close>\n\ntype_synonym ('o, '\\<sigma>) MON\\<^sub>S\\<^sub>E = \"'\\<sigma> \\<rightharpoonup> ('o \\<times> '\\<sigma>)\" (* = '\\<sigma> \\<Rightarrow> ('o \\<times> '\\<sigma>)option *)       \n      \ndefinition bind_SE :: \"('o,'\\<sigma>)MON\\<^sub>S\\<^sub>E \\<Rightarrow> ('o \\<Rightarrow> ('o','\\<sigma>)MON\\<^sub>S\\<^sub>E) \\<Rightarrow> ('o','\\<sigma>)MON\\<^sub>S\\<^sub>E\" \nwhere     \"bind_SE f g = (\\<lambda>\\<sigma>. case f \\<sigma> of None \\<Rightarrow> None \n                                        | Some (out, \\<sigma>') \\<Rightarrow> g out \\<sigma>')\"\n\nnotation bind_SE (\"bind\\<^sub>S\\<^sub>E\")\n\nsyntax    (xsymbols)\n          \"_bind_SE\" :: \"[pttrn,('o,'\\<sigma>)MON\\<^sub>S\\<^sub>E,('o','\\<sigma>)MON\\<^sub>S\\<^sub>E] \\<Rightarrow> ('o','\\<sigma>)MON\\<^sub>S\\<^sub>E\" \n          (\"(2 _ \\<leftarrow> _; _)\" [5,8,8]8)\ntranslations \n          \"x \\<leftarrow> f; g\" == \"CONST bind_SE f (% x . g)\"\n\ndefinition unit_SE :: \"'o \\<Rightarrow> ('o, '\\<sigma>)MON\\<^sub>S\\<^sub>E\"   (\"(result _)\" 8) \nwhere     \"unit_SE e = (\\<lambda>\\<sigma>. Some(e,\\<sigma>))\"\nnotation   unit_SE (\"unit\\<^sub>S\\<^sub>E\")\n\ntext\\<open>In the following, we prove the required Monad-laws\\<close>\n\nlemma bind_right_unit[simp]: \"(x \\<leftarrow> m; result x) = m\"\n  apply (simp add:  unit_SE_def bind_SE_def)\n  apply (rule ext)\n  apply (case_tac \"m \\<sigma>\", simp_all)\n  done\n\nlemma bind_left_unit [simp]: \"(x \\<leftarrow> result c; P x) = P c\"\n  by (simp add: unit_SE_def bind_SE_def)\n  \nlemma bind_assoc[simp]: \"(y \\<leftarrow> (x \\<leftarrow> m; k x); h y) = (x \\<leftarrow> m; (y \\<leftarrow> k x; h y))\"\n  apply (simp add: unit_SE_def bind_SE_def, rule ext)\n  apply (case_tac \"m \\<sigma>\", simp_all)\n  apply (case_tac \"a\", simp_all)\n  done\n    \nsubsection\\<open>Definition : More Operators and their Properties\\<close>\n\ndefinition fail_SE :: \"('o, '\\<sigma>)MON\\<^sub>S\\<^sub>E\"\nwhere     \"fail_SE = (\\<lambda>\\<sigma>. None)\" \nnotation   fail_SE (\"fail\\<^sub>S\\<^sub>E\")\n\ndefinition assert_SE :: \"('\\<sigma> \\<Rightarrow> bool) \\<Rightarrow> (bool, '\\<sigma>)MON\\<^sub>S\\<^sub>E\"\nwhere     \"assert_SE P = (\\<lambda>\\<sigma>. if P \\<sigma> then Some(True,\\<sigma>) else None)\"\nnotation   assert_SE (\"assert\\<^sub>S\\<^sub>E\")\n\ndefinition assume_SE :: \"('\\<sigma> \\<Rightarrow> bool) \\<Rightarrow> (unit, '\\<sigma>)MON\\<^sub>S\\<^sub>E\"\nwhere     \"assume_SE P = (\\<lambda>\\<sigma>. if \\<exists>\\<sigma> . P \\<sigma> then Some((), SOME \\<sigma> . P \\<sigma>) else None)\"\nnotation   assume_SE (\"assume\\<^sub>S\\<^sub>E\")\n\n\nlemma bind_left_fail_SE[simp] : \"(x \\<leftarrow> fail\\<^sub>S\\<^sub>E; P x) = fail\\<^sub>S\\<^sub>E\"\n  by (simp add: fail_SE_def bind_SE_def)\n\n\ntext\\<open>We also provide a \"Pipe-free\" - variant of the bind operator.\nJust a \"standard\" programming sequential operator without output frills.\\<close>\n(* TODO: Eliminate/Modify this. Is a consequence of the Monad-Instantiation. *)\n\n\ndefinition bind_SE' :: \"('\\<alpha>, '\\<sigma>)MON\\<^sub>S\\<^sub>E \\<Rightarrow> ('\\<beta>, '\\<sigma>)MON\\<^sub>S\\<^sub>E \\<Rightarrow> ('\\<beta>, '\\<sigma>)MON\\<^sub>S\\<^sub>E\" (infixr \";-\" 60)\nwhere     \"f ;- g = (_ \\<leftarrow> f ; g)\"\n\nlemma bind_assoc'[simp]: \"((m;- k);- h ) = (m;- (k;- h))\"\nby(simp add:bind_SE'_def)\n\n\nlemma bind_left_unit' [simp]: \"((result c);- P) = P\"\n  by (simp add:  bind_SE'_def)\n  \n\nlemma bind_left_fail_SE'[simp]: \"(fail\\<^sub>S\\<^sub>E;- P) = fail\\<^sub>S\\<^sub>E\"\n  by (simp add: bind_SE'_def)\n\nlemma bind_right_unit'[simp]: \"(m;- (result ())) = m\"\n  by (simp add:  bind_SE'_def)\n          \ntext\\<open>The bind-operator in the state-exception monad yields already\n       a semantics for the concept of an input sequence on the meta-level:\\<close>\nlemma     syntax_test: \"(o1 \\<leftarrow> f1 ; o2 \\<leftarrow> f2; result (post o1 o2)) = X\"\noops\n  \ndefinition yield\\<^sub>C :: \"('a  \\<Rightarrow> 'b) \\<Rightarrow>  ('b,'a ) MON\\<^sub>S\\<^sub>E\"\n    where \"yield\\<^sub>C f \\<equiv> (\\<lambda>\\<sigma>. Some(f \\<sigma>, \\<sigma>))\"\n\n\ndefinition try_SE :: \"('o,'\\<sigma>) MON\\<^sub>S\\<^sub>E \\<Rightarrow> ('o option,'\\<sigma>) MON\\<^sub>S\\<^sub>E\" (\"try\\<^sub>S\\<^sub>E\")\nwhere     \"try\\<^sub>S\\<^sub>E ioprog = (\\<lambda>\\<sigma>. case ioprog \\<sigma> of\n                                      None \\<Rightarrow> Some(None, \\<sigma>)\n                                    | Some(outs, \\<sigma>') \\<Rightarrow> Some(Some outs, \\<sigma>'))\" \ntext\\<open>In contrast, mbind as a failure safe operator can roughly be seen \n       as a foldr on bind - try:\n       m1 ; try m2 ; try m3; ... Note, that the rough equivalence only holds for\n       certain predicates in the sequence - length equivalence modulo None,\n       for example. However, if a conditional is added, the equivalence\n       can be made precise:\\<close>\n  \ntext\\<open>On this basis, a symbolic evaluation scheme can be established\n  that reduces mbind-code to try\\_SE\\_code and ite-cascades.\\<close>\n\ndefinition alt_SE :: \"[('o, '\\<sigma>)MON\\<^sub>S\\<^sub>E, ('o, '\\<sigma>)MON\\<^sub>S\\<^sub>E] \\<Rightarrow> ('o, '\\<sigma>)MON\\<^sub>S\\<^sub>E\"   (infixl \"\\<sqinter>\\<^sub>S\\<^sub>E\" 10)\nwhere     \"(f \\<sqinter>\\<^sub>S\\<^sub>E g) = (\\<lambda> \\<sigma>. case f \\<sigma> of None \\<Rightarrow> g \\<sigma>\n                                      | Some H \\<Rightarrow> Some H)\"\n\ndefinition malt_SE :: \"('o, '\\<sigma>)MON\\<^sub>S\\<^sub>E list \\<Rightarrow> ('o, '\\<sigma>)MON\\<^sub>S\\<^sub>E\"\nwhere     \"malt_SE S = foldr alt_SE S fail\\<^sub>S\\<^sub>E\"\nnotation   malt_SE (\"\\<Sqinter>\\<^sub>S\\<^sub>E\")\n\nlemma malt_SE_mt [simp]: \"\\<Sqinter>\\<^sub>S\\<^sub>E [] = fail\\<^sub>S\\<^sub>E\"\nby(simp add: malt_SE_def)\n\nlemma malt_SE_cons [simp]: \"\\<Sqinter>\\<^sub>S\\<^sub>E (a # S) = (a \\<sqinter>\\<^sub>S\\<^sub>E (\\<Sqinter>\\<^sub>S\\<^sub>E S))\"\nby(simp add: malt_SE_def)\n\n\nsubsection\\<open>Definition : Programming Operators and their Properties\\<close>\n\ndefinition  \"skip\\<^sub>S\\<^sub>E = unit\\<^sub>S\\<^sub>E ()\"\n\ndefinition if_SE :: \"['\\<sigma> \\<Rightarrow> bool, ('\\<alpha>, '\\<sigma>)MON\\<^sub>S\\<^sub>E, ('\\<alpha>, '\\<sigma>)MON\\<^sub>S\\<^sub>E] \\<Rightarrow> ('\\<alpha>, '\\<sigma>)MON\\<^sub>S\\<^sub>E\"\nwhere     \"if_SE c E F = (\\<lambda>\\<sigma>. if c \\<sigma> then E \\<sigma> else F \\<sigma>)\" \n\nsyntax    (xsymbols)\n          \"_if_SE\" :: \"['\\<sigma> \\<Rightarrow> bool,('o,'\\<sigma>)MON\\<^sub>S\\<^sub>E,('o','\\<sigma>)MON\\<^sub>S\\<^sub>E] \\<Rightarrow> ('o','\\<sigma>)MON\\<^sub>S\\<^sub>E\" \n          (\"(if\\<^sub>S\\<^sub>E _ then _ else _fi)\" [5,8,8]8)\ntranslations \n          \"(if\\<^sub>S\\<^sub>E cond then T1 else T2 fi)\" == \"CONST if_SE cond T1 T2\"\n\n\nsubsection\\<open>Theory of a Monadic While\\<close>\n\ntext\\<open>Prerequisites\\<close>\nfun replicator :: \"[('a, '\\<sigma>)MON\\<^sub>S\\<^sub>E, nat] \\<Rightarrow> (unit, '\\<sigma>)MON\\<^sub>S\\<^sub>E\" (infixr \"^^^\" 60)\nwhere     \"f ^^^ 0      = (result ())\"\n        | \"f ^^^ (Suc n) = (f ;- f ^^^  n)\"\n\n\nfun replicator2 :: \"[('a, '\\<sigma>)MON\\<^sub>S\\<^sub>E, nat, ('b, '\\<sigma>)MON\\<^sub>S\\<^sub>E] \\<Rightarrow> ('b, '\\<sigma>)MON\\<^sub>S\\<^sub>E\" (infixr \"^:^\" 60)\nwhere     \"(f ^:^ 0) M      = (M )\"\n        | \"(f ^:^ (Suc n)) M = (f ;- ((f ^:^  n) M))\"\n\n\ntext\\<open>First Step : Establishing an embedding between partial functions and relations\\<close> \n(* plongement *)\ndefinition Mon2Rel :: \"(unit, '\\<sigma>)MON\\<^sub>S\\<^sub>E \\<Rightarrow> ('\\<sigma> \\<times> '\\<sigma>) set\"\nwhere \"Mon2Rel f = {(x, y). (f x = Some((), y))}\"\n(* ressortir *)\ndefinition Rel2Mon :: \" ('\\<sigma> \\<times> '\\<sigma>) set \\<Rightarrow> (unit, '\\<sigma>)MON\\<^sub>S\\<^sub>E \"\nwhere \"Rel2Mon S = (\\<lambda> \\<sigma>. if \\<exists>\\<sigma>'. (\\<sigma>, \\<sigma>') \\<in> S then Some((), SOME \\<sigma>'. (\\<sigma>, \\<sigma>') \\<in> S) else None)\"\n\nlemma Mon2Rel_Rel2Mon_id: assumes det:\"single_valued R\" shows \"(Mon2Rel \\<circ> Rel2Mon) R = R\"\napply (simp add: comp_def Mon2Rel_def Rel2Mon_def,auto)\napply (case_tac \"\\<exists>\\<sigma>'. (a, \\<sigma>') \\<in> R\", auto)\napply (subst (2) some_eq_ex) \nusing det[simplified single_valued_def] by auto\n\n\nlemma Rel2Mon_Id: \"(Rel2Mon \\<circ> Mon2Rel) x = x\"\napply (rule ext)\napply (auto simp: comp_def Mon2Rel_def Rel2Mon_def)\napply (erule contrapos_pp, drule HOL.not_sym, simp)\ndone\n\nlemma single_valued_Mon2Rel: \"single_valued (Mon2Rel B)\"\nby (auto simp: single_valued_def Mon2Rel_def)\n\ntext\\<open>Second Step : Proving an induction principle allowing to establish that lfp remains\n       deterministic\\<close> \n\n\n(* A little complete partial order theory due to Tobias Nipkow *)\ndefinition chain :: \"(nat \\<Rightarrow> 'a set) \\<Rightarrow> bool\" \nwhere     \"chain S = (\\<forall>i. S i \\<subseteq> S(Suc i))\"\n\nlemma chain_total: \"chain S ==> S i \\<le> S j \\<or> S j \\<le> S i\"\nby (metis chain_def le_cases lift_Suc_mono_le)\n\ndefinition cont :: \"('a set => 'b set) => bool\" \nwhere     \"cont f = (\\<forall>S. chain S \\<longrightarrow> f(UN n. S n) = (UN n. f(S n)))\"\n\nlemma mono_if_cont: fixes f :: \"'a set \\<Rightarrow> 'b set\"\n  assumes \"cont f\" shows \"mono f\"\nproof\n  fix a b :: \"'a set\" assume \"a \\<subseteq> b\"\n  let ?S = \"\\<lambda>n::nat. if n=0 then a else b\"\n  have \"chain ?S\" using \\<open>a \\<subseteq> b\\<close> by(auto simp: chain_def)\n  hence \"f(UN n. ?S n) = (UN n. f(?S n))\"\n    using assms by (metis cont_def)\n  moreover have \"(UN n. ?S n) = b\" using \\<open>a \\<subseteq> b\\<close> by (auto split: if_splits)\n  moreover have \"(UN n. f(?S n)) = f a \\<union> f b\" by (auto split: if_splits)\n  ultimately show \"f a \\<subseteq> f b\" by (metis Un_upper1)\nqed\n\nlemma chain_iterates: fixes f :: \"'a set \\<Rightarrow> 'a set\"\n  assumes \"mono f\" shows \"chain(\\<lambda>n. (f^^n) {})\"\nproof-\n  { fix n have \"(f ^^ n) {} \\<subseteq> (f ^^ Suc n) {}\" using assms\n    by(induction n) (auto simp: mono_def) }\n  thus ?thesis by(auto simp: chain_def)\nqed\n\ntheorem lfp_if_cont:\n  assumes \"cont f\" shows \"lfp f =  (\\<Union>n. (f ^^ n) {})\" (is \"_ = ?U\")\nproof\n  show \"lfp f \\<subseteq> ?U\"\n  proof (rule lfp_lowerbound)\n    have \"f ?U = (UN n. (f^^Suc n){})\"\n      using chain_iterates[OF mono_if_cont[OF assms]] assms\n      by(simp add: cont_def)\n    also have \"\\<dots> = (f^^0){} \\<union> \\<dots>\" by simp\n    also have \"\\<dots> = ?U\"\n      apply(auto simp del: funpow.simps)\n      by (metis empty_iff funpow_0 old.nat.exhaust)\n    finally show \"f ?U \\<subseteq> ?U\" by simp\n  qed\nnext\n  { fix n p assume \"f p \\<subseteq> p\"\n    have \"(f^^n){} \\<subseteq> p\"\n    proof(induction n)\n      case 0 show ?case by simp\n    next\n      case Suc\n      from monoD[OF mono_if_cont[OF assms] Suc] \\<open>f p \\<subseteq> p\\<close>\n      show ?case by simp\n    qed\n  }\n  thus \"?U \\<subseteq> lfp f\" by(auto simp: lfp_def)\nqed\n\n\nlemma single_valued_UN_chain:\n  assumes \"chain S\" \"(!!n. single_valued (S n))\"\n  shows \"single_valued(UN n. S n)\"\nproof(auto simp: single_valued_def)\n  fix m n x y z assume \"(x, y) \\<in> S m\" \"(x, z) \\<in> S n\"\n  with chain_total[OF assms(1), of m n] assms(2)\n  show \"y = z\" by (auto simp: single_valued_def)\nqed\n\nlemma single_valued_lfp: \nfixes f :: \"('a \\<times> 'a) set \\<Rightarrow> ('a \\<times> 'a) set\"\nassumes \"cont f\" \"\\<And>r. single_valued r \\<Longrightarrow> single_valued (f r)\"\nshows \"single_valued(lfp f)\"\nunfolding lfp_if_cont[OF assms(1)]\nproof(rule single_valued_UN_chain[OF chain_iterates[OF mono_if_cont[OF assms(1)]]])\n  fix n show \"single_valued ((f ^^ n) {})\"\n  by(induction n)(auto simp: assms(2))\nqed\n\n\ntext\\<open>Third Step: Definition of the Monadic While \\<open> \\<close>\\<close>\ndefinition \\<Gamma> :: \"['\\<sigma> \\<Rightarrow> bool,('\\<sigma> \\<times> '\\<sigma>) set] \\<Rightarrow> (('\\<sigma> \\<times> '\\<sigma>) set \\<Rightarrow> ('\\<sigma> \\<times> '\\<sigma>) set)\" \nwhere     \"\\<Gamma> b cd = (\\<lambda>cw. {(s,t). if b s then (s, t) \\<in> cd O cw else s = t})\"\n\n\ndefinition while_SE :: \"['\\<sigma> \\<Rightarrow> bool, (unit, '\\<sigma>)MON\\<^sub>S\\<^sub>E] \\<Rightarrow> (unit, '\\<sigma>)MON\\<^sub>S\\<^sub>E\"\nwhere     \"while_SE c B \\<equiv> (Rel2Mon(lfp(\\<Gamma> c (Mon2Rel B))))\"\n\nsyntax    (xsymbols)\n          \"_while_SE\" :: \"['\\<sigma> \\<Rightarrow> bool, (unit, '\\<sigma>)MON\\<^sub>S\\<^sub>E] \\<Rightarrow> (unit, '\\<sigma>)MON\\<^sub>S\\<^sub>E\" \n          (\"(while\\<^sub>S\\<^sub>E _ do _ od)\" [8,8]8)\ntranslations \n          \"while\\<^sub>S\\<^sub>E c do b od\" == \"CONST while_SE c b\"\n\nlemma cont_\\<Gamma>: \"cont (\\<Gamma> c b)\"\nby (auto simp: cont_def \\<Gamma>_def)\n\ntext\\<open>The fixpoint theory now allows us to establish that the lfp constructed over\n       @{term Mon2Rel} remains deterministic\\<close>\n\ntheorem single_valued_lfp_Mon2Rel: \"single_valued (lfp(\\<Gamma> c (Mon2Rel B)))\"\napply(rule single_valued_lfp, simp_all add: cont_\\<Gamma>)\napply(auto simp: \\<Gamma>_def single_valued_def)\napply(metis single_valued_Mon2Rel[of \"B\"] single_valued_def)\ndone\n\n\nlemma Rel2Mon_if:\n  \"Rel2Mon {(s, t). if b s then (s, t) \\<in> Mon2Rel c O lfp (\\<Gamma> b (Mon2Rel c)) else s = t} \\<sigma> =\n  (if b \\<sigma> then Rel2Mon (Mon2Rel c O lfp (\\<Gamma> b (Mon2Rel c))) \\<sigma> else Some ((), \\<sigma>))\"\nby (simp add: Rel2Mon_def)\n\nlemma Rel2Mon_homomorphism:\n  assumes determ_X: \"single_valued X\" and determ_Y: \"single_valued Y\"\n  shows   \"Rel2Mon (X O Y) = (Rel2Mon X) ;- (Rel2Mon Y)\"\nproof - \n    have relational_partial_next_in_O: \"\\<And>x E F. (\\<exists>y. (x, y) \\<in> (E O F)) \\<Longrightarrow> (\\<exists>y. (x, y) \\<in> E)\" \n                        by (auto)\n    have some_eq_intro: \"\\<And> X x y . single_valued X \\<Longrightarrow> (x, y) \\<in> X \\<Longrightarrow> (SOME y. (x, y) \\<in> X) = y\"\n                        by (auto simp: single_valued_def)\n\n    show ?thesis\napply (simp add: Rel2Mon_def bind_SE'_def bind_SE_def)\napply (rule ext, rename_tac \"\\<sigma>\")\napply (case_tac \" \\<exists> \\<sigma>'. (\\<sigma>, \\<sigma>') \\<in> X O Y\")\napply (simp only: HOL.if_True)\napply (frule relational_partial_next_in_O)\napply (auto simp: single_valued_relcomp some_eq_intro determ_X determ_Y relcomp.relcompI)\nby blast\nqed\n\n\n\ntext\\<open>Putting everything together, the theory of embedding and the invariance of\n       determinism of the while-body, gives us the usual unfold-theorem:\\<close>\ntheorem while_SE_unfold:\n\"(while\\<^sub>S\\<^sub>E b do c od) = (if\\<^sub>S\\<^sub>E b then (c ;- (while\\<^sub>S\\<^sub>E b do c od)) else result () fi)\"\napply (simp add: if_SE_def bind_SE'_def while_SE_def unit_SE_def)\napply (subst lfp_unfold [OF mono_if_cont, OF cont_\\<Gamma>])\napply (rule ext)\napply (subst \\<Gamma>_def)\napply (auto simp: Rel2Mon_if Rel2Mon_homomorphism bind_SE'_def Rel2Mon_Id [simplified comp_def] \n                  single_valued_Mon2Rel single_valued_lfp_Mon2Rel )\ndone\n  \n\nlemma bind_cong : \" f \\<sigma> = g \\<sigma> \\<Longrightarrow>  (x \\<leftarrow> f ; M x)\\<sigma> = (x \\<leftarrow> g ; M x)\\<sigma>\"\n  unfolding bind_SE'_def bind_SE_def  by simp\n\nlemma bind'_cong : \" f \\<sigma> = g \\<sigma> \\<Longrightarrow>  (f ;- M )\\<sigma> = (g ;- M )\\<sigma>\"\n  unfolding bind_SE'_def bind_SE_def  by simp\n\n  \n  \nlemma if\\<^sub>S\\<^sub>E_True [simp]: \"(if\\<^sub>S\\<^sub>E (\\<lambda> x. True) then c else d fi) = c\" \n  apply(rule ext) by (simp add: MonadSE.if_SE_def) \n\nlemma if\\<^sub>S\\<^sub>E_False [simp]: \"(if\\<^sub>S\\<^sub>E (\\<lambda> x. False) then c else d fi) = d\" \n  apply(rule ext) by (simp add: MonadSE.if_SE_def) \n  \n    \nlemma if\\<^sub>S\\<^sub>E_cond_cong : \"f \\<sigma> = g \\<sigma> \\<Longrightarrow> \n                           (if\\<^sub>S\\<^sub>E f then c else d fi) \\<sigma> = \n                           (if\\<^sub>S\\<^sub>E g then c else d fi) \\<sigma>\"\n  unfolding if_SE_def  by simp\n \nlemma while\\<^sub>S\\<^sub>E_skip[simp] : \"(while\\<^sub>S\\<^sub>E (\\<lambda> x. False) do c od) = skip\\<^sub>S\\<^sub>E\" \n  apply(rule ext,subst MonadSE.while_SE_unfold)\n  by (simp add: MonadSE.if_SE_def skip\\<^sub>S\\<^sub>E_def)\n  \n    \nend\n  ", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Clean/src/MonadSE.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5117166047041654, "lm_q2_score": 0.5851011542032312, "lm_q1q2_score": 0.29940597603736574}}
{"text": "section \\<open>The Optimized Observing Quorums Model\\<close>\n\ntheory Observing_Quorums_Opt\nimports Observing_Quorums\nbegin\n\nsubsection \\<open>Model definition\\<close>\n(******************************************************************************)\n\nrecord opt_obsv_state = \n  next_round :: round \n  decisions :: \"(process, val)map\"\n  last_obs :: \"(process, val)map\"\n\ncontext mono_quorum\nbegin\n\ndefinition opt_obs_safe where\n  \"opt_obs_safe obs_f v \\<equiv> \\<exists>p. obs_f p \\<in> {None, Some v}\"\n\ndefinition olv_round where\n  \"olv_round r S v r_decisions Ob \\<equiv> {(s, s').\n    \\<comment> \\<open>guards\\<close>\n    r = next_round s\n    \\<and> (S \\<noteq> {} \\<longrightarrow> opt_obs_safe (last_obs s) v)\n    \\<and> (S \\<in> Quorum \\<longrightarrow> Ob = UNIV)\n    \\<and> d_guard r_decisions (const_map v S)\n    \\<and> (Ob \\<noteq> {} \\<longrightarrow> S \\<noteq> {})\n    \\<and> \\<comment> \\<open>actions\\<close>\n    s' = s\\<lparr> \n     next_round := Suc r\n     , decisions := decisions s ++ r_decisions\n     , last_obs := last_obs s ++ const_map v Ob\n   \\<rparr>\n  }\"\n\ndefinition olv_init where\n  \"olv_init = { \\<lparr> next_round = 0, decisions = Map.empty, last_obs = Map.empty \\<rparr> }\"\n\ndefinition olv_trans :: \"(opt_obsv_state \\<times> opt_obsv_state) set\" where\n  \"olv_trans = (\\<Union>r S v D Ob. olv_round r S v D Ob) \\<union> Id\"\n\ndefinition olv_TS :: \"opt_obsv_state TS\" where\n  \"olv_TS = \\<lparr> init = olv_init, trans = olv_trans \\<rparr>\"\n\nlemmas olv_TS_defs = olv_TS_def olv_init_def olv_trans_def\n\nsubsection \\<open>Refinement\\<close>\n(******************************************************************************)\n\ndefinition olv_ref_rel where\n  \"olv_ref_rel \\<equiv> {(sa, sc).\n    next_round sc = v_state.next_round sa\n    \\<and> decisions sc = v_state.decisions sa\n    \\<and> last_obs sc = map_option snd o process_mru (obsv_state.obs sa)\n  }\"\n\n\nlemma OV_inv2_finite_map_graph:\n   \"s \\<in> OV_inv2 \\<Longrightarrow> finite (map_graph (case_prod (obsv_state.obs s)))\"\n  apply(rule finite_dom_finite_map_graph)\n  apply(rule finite_subset[where B=\"{0..< v_state.next_round s} \\<times> UNIV\"])\n   apply(auto simp add: OV_inv2_def dom_def not_le[symmetric])\n  done\n\nlemma OV_inv2_finite_obs_set:\n   \"s \\<in> OV_inv2 \\<Longrightarrow> finite (vote_set (obsv_state.obs s) Q)\"\n   apply(drule OV_inv2_finite_map_graph)\n   apply(clarsimp simp add: map_graph_def fun_graph_def vote_set_def)\n   apply(erule finite_surj[where f=\"\\<lambda>((r, a), v). (r, v)\"])\n   by(force simp add: image_def)   \n\nlemma olv_round_refines:\n  \"{olv_ref_rel \\<inter> (OV_inv2 \\<inter> OV_inv3 \\<inter> OV_inv4) \\<times> UNIV} obsv_round r S v D Ob, olv_round r S v D Ob {>olv_ref_rel}\"\nproof(clarsimp simp add: PO_rhoare_defs)\n  fix sa :: obsv_state and sc sc'\n  assume\n    ainv: \"sa \\<in> OV_inv2\" \"sa \\<in> OV_inv3\" \"sa \\<in> OV_inv4\"\n    and step: \"(sc, sc') \\<in> olv_round r S v D Ob\"\n    and R: \"(sa, sc) \\<in> olv_ref_rel\"\n\n  \\<comment> \\<open>Abstract guard.\\<close>\n  have \"S \\<noteq> {} \\<longrightarrow> obs_safe (v_state.next_round sa) sa v\"\n  proof(rule impI, rule ccontr)\n    assume S_nonempty: \"S \\<noteq> {}\" and no_Q: \"\\<not> obs_safe (v_state.next_round sa) sa v\"\n    from no_Q obtain r_w w where \n      r_w: \"r_w < v_state.next_round sa\"\n      and all_obs: \"\\<forall>p. obsv_state.obs sa r_w p = Some w\"\n      and diff: \"w \\<noteq> v\" using ainv(3)[THEN OV_inv4D]\n      by(simp add: obs_safe_def)  (metis)\n    from diff step R obtain p where \n      p_w: \"S \\<noteq> {} \\<longrightarrow> (map_option snd \\<circ> process_mru (obsv_state.obs sa)) p \\<noteq> Some w\"\n      by (simp add: opt_obs_safe_def quorum_for_def olv_round_def  olv_ref_rel_def)  \n       (metis option.distinct(1) option.sel snd_conv)\n    from all_obs have nempty: \"vote_set (obsv_state.obs sa) {p} \\<noteq> {}\" \n      by(auto simp add:  vote_set_def)\n    then obtain r_w' w' where w': \"process_mru (obsv_state.obs sa) p = Some (r_w', w')\"\n      by (simp add: process_mru_def mru_of_set_def) \n        (metis option_Max_by_def surj_pair)\n    hence max: \"(r_w', w') = Max_by fst (vote_set (obsv_state.obs sa) {p})\"\n      by(auto simp add: process_mru_def mru_of_set_def option_Max_by_def)\n    hence w'_obs: \"(r_w', w') \\<in> vote_set (obsv_state.obs sa) {p}\" \n      using Max_by_in[OF OV_inv2_finite_obs_set[OF ainv(1), of \"{p}\"] nempty]\n      by fastforce\n    have \"r_w \\<le> r_w'\" using all_obs\n      apply -\n      apply(rule Max_by_ge[OF OV_inv2_finite_obs_set[OF ainv(1), of \"{p}\"], of \"(r_w, w)\" fst, \n                            simplified max[symmetric], simplified])\n      apply(auto simp add: quorum_for_def vote_set_def)\n      done\n    moreover have \"w' \\<noteq> w\" using p_w w' S_nonempty\n      by(auto)\n    ultimately have \"r_w < r_w'\" using all_obs w'_obs\n      apply(elim le_neq_implies_less)\n      apply(auto simp add: quorum_for_def vote_set_def)\n      done\n    thus False using ainv(2)[THEN OV_inv3D] w'_obs all_obs \\<open>w' \\<noteq> w\\<close>\n      by(fastforce simp add: vote_set_def obs_safe_def)\n  qed\n\n  \\<comment> \\<open>Action refinement.\\<close>\n  moreover have \n    \"(map_option snd \\<circ> process_mru (obsv_state.obs sa)) ++ const_map v Ob =\n      map_option snd \\<circ> process_mru ((obsv_state.obs sa)(v_state.next_round sa := const_map v Ob))\"\n  proof-\n    from \\<open>sa \\<in> OV_inv2\\<close>[THEN OV_inv2D] \n    have empty: \"\\<forall>r'\\<ge>v_state.next_round sa. obsv_state.obs sa r' = Map.empty\"\n      by simp\n    show ?thesis\n      by(auto simp add: map_add_def const_map_def restrict_map_def process_mru_new_votes[OF empty])\n  qed\n\n  ultimately show \"\\<exists>sa'. (sa, sa') \\<in> obsv_round r S v D Ob \\<and> (sa', sc') \\<in> olv_ref_rel\" \n    using R step\n    by(clarsimp simp add: obsv_round_def olv_round_def olv_ref_rel_def)\n\nqed\n\nlemma OLV_Refines:\n  \"PO_refines (olv_ref_rel \\<inter> (OV_inv2 \\<inter> OV_inv3 \\<inter> OV_inv4) \\<times> UNIV) obsv_TS olv_TS\"\nproof(rule refine_using_invariants)\n  show \"init olv_TS \\<subseteq> olv_ref_rel `` init obsv_TS\"\n    by(auto simp add: obsv_TS_defs olv_TS_defs olv_ref_rel_def process_mru_def mru_of_set_def\n      vote_set_def option_Max_by_def intro!: ext)\nnext\n  show\n    \"{olv_ref_rel \\<inter> (OV_inv2 \\<inter> OV_inv3 \\<inter> OV_inv4) \\<times> UNIV} TS.trans obsv_TS, TS.trans olv_TS {> olv_ref_rel}\"\n    by(auto simp add: PO_refines_def obsv_TS_defs olv_TS_defs \n      intro!: olv_round_refines)\nqed (auto intro: OV_inv2_inductive OV_inv3_inductive OV_inv4_inductive\n  OV_inv2_inductive(1)[THEN subsetD] OV_inv3_inductive(1)[THEN subsetD] \n  OV_inv4_inductive(1)[THEN subsetD])\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Consensus_Refined/Observing_Quorums_Opt.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6334102636778401, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.29940256556230654}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2005         |\n            |              Februaru 2006                |\n            |                 March 2007  (modified)    |\n            |                 August 2007  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory FNF_F_sf_rest\nimports FNF_F_sf_def\nbegin\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite UnionT and InterT.                 *)\n(*                  disj_not1: (~ P | Q) = (P --> Q)                   *)\n\ndeclare disj_not1 [simp del]\n\n(*  The following simplification rules are deleted in this theory file *)\n(*       P (if Q then x else y) = ((Q --> P x) & (~ Q --> P y))        *)\n(* Isabelle 2017: split_if --> if_split *)\n\ndeclare if_split  [split del]\n\n(*****************************************************************\n\n         1. full sequentialization for Depth-restriction (P |. n)\n         2.\n         3.\n\n *****************************************************************)\n\n(*============================================================*\n |                                                            |\n |                       Depth_rest                           |\n |                                                            |\n *============================================================*)\n\n(*============================================================*\n |                         Pfun P1 P2                         |\n *============================================================*)\n\n(*** relation ***)\n\ninductive_set\n  fsfF_Depth_rest_rel ::\n  \"(('p,'a) proc * nat * ('p,'a) proc) set\"\n\nwhere\nfsfF_Depth_rest_rel_zero:\n  \"(P1, 0, SDIV) : fsfF_Depth_rest_rel\"\n|\nfsfF_Depth_rest_rel_etc:\n  \"P1 ~: fsfF_proc\n   ==> (P1, Suc n, P1 |. (Suc n)) : fsfF_Depth_rest_rel\"\n|\nfsfF_Depth_rest_rel_int:\n  \"[| ALL c. if (c: sumset C1)\n             then (Rf1 c, Suc m, SRf c) : fsfF_Depth_rest_rel\n             else SRf c = DIV ;\n      sumset C1 ~= {} ; ALL c: sumset C1. Rf1 c : fsfF_proc |]\n   ==>\n   ((!! :C1 .. Rf1), Suc m, !! c:C1 .. SRf c)\n   : fsfF_Depth_rest_rel\"\n|\nfsfF_Depth_rest_rel_step:\n  \"[| ALL a. if a:A1\n             then (Pf1 a, n, SPf a) : fsfF_Depth_rest_rel\n             else SPf a = DIV ;\n      ALL a:A1. Pf1 a : fsfF_proc ;\n      Q1 = SKIP | Q1 = DIV | Q1 = STOP |]\n   ==> \n   ((? :A1 -> Pf1) [+] Q1, Suc n, (? :A1 -> SPf) [+] Q1) : fsfF_Depth_rest_rel\"\n\n(*** function ***)\n\ndefinition\n  fsfF_Depth_rest ::\n  \"('p,'a) proc => nat => ('p,'a) proc\"   (\"(1_ /|.seq _)\" [84,900] 84)\n  where\n  fsfF_Depth_rest_def:\n    \"P1 |.seq n == THE SP. (P1, n, SP) : fsfF_Depth_rest_rel\"\n\n(****************************************************************\n |                      uniquness                               |\n ****************************************************************)\n\nlemma fsfF_Depth_rest_rel_unique_in_lm:\n   \"(P1, n, SP1) : fsfF_Depth_rest_rel\n    ==> (ALL SP2. ((P1, n, SP2) : fsfF_Depth_rest_rel\n                   --> SP1 = SP2))\"\napply (rule fsfF_Depth_rest_rel.induct[of P1 n SP1])\napply (simp)\n\n(* zero *)\napply (intro allI impI)\napply (rotate_tac -1)\napply (erule fsfF_Depth_rest_rel.cases)\napply (simp_all)\n\n(* etc *)\napply (intro allI impI)\napply (rotate_tac -1)\napply (erule fsfF_Depth_rest_rel.cases)\napply (simp_all)\napply (simp add: fsfF_proc_int)\napply (simp add: fsfF_proc_ext)\n\n(* step_int *)\napply (intro allI impI)\napply (rotate_tac -1)\napply (erule fsfF_Depth_rest_rel.cases, simp_all)\n\n apply (rotate_tac -4)\n apply (drule sym)\n apply (simp add: fsfF_proc_int)\n\n apply (simp add: fun_eq_iff)\n apply (intro allI)\n apply (drule_tac x=\"x\" in spec)+\n apply (case_tac \"x : sumset C1a\")\n apply (simp)\n apply (simp)\n\n(* step *)\napply (intro allI impI)\napply (rotate_tac -1)\napply (erule fsfF_Depth_rest_rel.cases, simp_all)\n\n apply (rotate_tac -4)\n apply (drule sym)\n apply (simp add: fsfF_proc_ext)\n\n  apply (simp add: fun_eq_iff)\n  apply (rule allI)\n  apply (drule_tac x=\"x\" in spec)+\n  apply (case_tac \"x : A1a\")\n  apply (simp_all)\ndone\n\n(*-----------------------*\n |        unique         |\n *-----------------------*)\n\nlemma fsfF_Depth_rest_rel_unique:\n   \"[| (P1, n, SP1) : fsfF_Depth_rest_rel;\n       (P1, n, SP2) : fsfF_Depth_rest_rel |]\n    ==> SP1 = SP2\"\nby (simp add: fsfF_Depth_rest_rel_unique_in_lm)\n\nlemma fsfF_Depth_rest_rel_EX1:\n   \"(EX SP. (P1, n, SP) : fsfF_Depth_rest_rel)\n = (EX! SP. (P1, n, SP) : fsfF_Depth_rest_rel)\"\napply (rule iffI)\n\n apply (erule exE)\n apply (rule_tac a=\"SP\" in ex1I)\n apply (simp)\n apply (simp add: fsfF_Depth_rest_rel_unique)\n\n apply (elim ex1_implies_exE)\n apply (simp)\ndone\n\n(*------------------------------------------------------------*\n |                   fsfF_Depth_rest_rel (iff)                |\n *------------------------------------------------------------*)\n\n(* zero *)\n\nlemma fsfF_Depth_rest_rel_zero_iff:\n  \"(P1, 0, SP) : fsfF_Depth_rest_rel\n   = (SP = SDIV)\"\napply (rule)\napply (erule fsfF_Depth_rest_rel.cases, simp_all)\napply (simp add: fsfF_Depth_rest_rel_zero)\ndone\n\n(* etc *)\n\nlemma fsfF_Depth_rest_rel_etc_iff:\n  \"P1 ~: fsfF_proc\n   ==> (P1, Suc n, SP) : fsfF_Depth_rest_rel\n       = (SP = P1 |. Suc n)\"\napply (rule)\napply (erule fsfF_Depth_rest_rel.cases, simp_all)\n apply (simp add: fsfF_proc_int)\n apply (simp add: fsfF_proc_ext)\napply (simp add: fsfF_Depth_rest_rel_etc)\ndone\n\n(* int nat *)\n\nlemma fsfF_Depth_rest_rel_int_iff:\n  \"[| ALL c. if (c: sumset C1)\n             then (Rf1 c, Suc m, SRf c) : fsfF_Depth_rest_rel\n             else SRf c = DIV ;\n      sumset C1 ~= {} ; ALL c: sumset C1. Rf1 c : fsfF_proc |]\n   ==>\n   ((!! :C1 .. Rf1), Suc m, SP) : fsfF_Depth_rest_rel\n   = (SP = !! :C1 .. SRf)\"\napply (rule)\napply (erule fsfF_Depth_rest_rel.cases, simp_all)\n\n apply (rotate_tac -4)\n apply (drule sym)\n apply (simp add: fsfF_proc_int)\n\n apply (simp add: fun_eq_iff)\n apply (rule allI)\n apply (drule_tac x=\"x\" in spec)+\n apply (case_tac \"x : sumset C1a\")\n apply (simp add: fsfF_Depth_rest_rel_unique)\n\n apply (simp)\napply (simp add: fsfF_Depth_rest_rel_int)\ndone\n\n(* step *)\n\nlemma fsfF_Depth_rest_rel_step_iff:\n  \"[| ALL a. if a:A1\n             then (Pf1 a, n, SPf a) : fsfF_Depth_rest_rel\n             else SPf a = DIV ;\n      ALL a:A1. Pf1 a : fsfF_proc ;\n      Q1 = SKIP | Q1 = DIV | Q1 = STOP |]\n   ==> \n   ((? :A1 -> Pf1) [+] Q1, Suc n, SP) : fsfF_Depth_rest_rel\n   = (SP = (? :A1 -> SPf) [+] Q1)\"\napply (rule)\napply (erule fsfF_Depth_rest_rel.cases, simp_all)\n\n apply (rotate_tac -4)\n apply (drule sym)\n apply (simp add: fsfF_proc_ext)\n\n apply (simp add: fun_eq_iff)\n apply (intro allI conjI)\n apply (elim conjE)\n apply (drule_tac x=\"x\" in spec)+\n apply (case_tac \"x : A1a\")\n apply (simp add: fsfF_Depth_rest_rel_unique)\n apply (simp)\napply (simp add: fsfF_Depth_rest_rel_step)\ndone\n\n(****************************************************************\n |                      existency                               |\n ****************************************************************)\n\n(*** exists ***)\n\nlemma fsfF_Depth_rest_rel_exists_zero:\n   \"(EX SP. (P1, 0, SP) : fsfF_Depth_rest_rel)\"\napply (rule_tac x=\"SDIV\" in exI)\napply (simp add: fsfF_Depth_rest_rel.intros)\ndone\n\nlemma fsfF_Depth_rest_rel_exists_notin:\n   \"P1 ~: fsfF_proc\n    ==> (EX SP. (P1, n, SP) : fsfF_Depth_rest_rel)\"\napply (insert nat_zero_or_Suc)\napply (drule_tac x=\"n\" in spec)\napply (elim disjE exE)\napply (simp add: fsfF_Depth_rest_rel_exists_zero)\napply (rule_tac x=\"P1 |. n\" in exI)\napply (simp add: fsfF_Depth_rest_rel.intros)\ndone\n\n(*** in fsfF_proc ***)\n\n(********* P1 and P2 *********)\n\nlemma fsfF_Depth_rest_rel_exists_in:\n   \"P1 : fsfF_proc\n    ==> ALL n. (EX SP. (P1, n, SP) :  fsfF_Depth_rest_rel)\"\napply (rule fsfF_proc.induct[of P1])\napply (simp)\n\n(* int nat *)\napply (rule allI)\napply (insert nat_zero_or_Suc)\napply (drule_tac x=\"n\" in spec)\napply (elim disjE exE)\napply (simp add: fsfF_Depth_rest_rel_exists_zero)\n\napply (erule dist_BALL_conjE)\napply (simp add: exchange_ALL_BALL)\napply (simp add: choice_BALL_EX)\napply (drule_tac x=\"n\" in spec)\napply (elim exE)\napply (rule_tac x=\"!! c:C .. (if (c : sumset C) then f c else DIV)\" in exI)\napply (rule fsfF_Depth_rest_rel.intros)\napply (simp split: if_split)\napply (simp_all)\n\n(* ext *)\napply (rule allI)\napply (drule_tac x=\"n\" in spec)\napply (rotate_tac -1)\napply (erule disjE)\napply (simp add: fsfF_Depth_rest_rel_exists_zero)\n\napply (elim exE)\napply (erule dist_BALL_conjE)\n\napply (simp add: exchange_ALL_BALL)\napply (simp add: choice_BALL_EX)\napply (drule_tac x=\"m\" in spec)\napply (elim exE)\napply (rule_tac x=\"? a:A -> (if (a : A) then (f a) else DIV) [+] Q\" in exI)\napply (rule fsfF_Depth_rest_rel.intros)\napply (simp split: if_split)\napply (simp_all)\ndone\n\n(*-----------------------*\n |        exists         |\n *-----------------------*)\n\nlemma fsfF_Depth_rest_rel_exists:\n   \"EX SP. (P1, n, SP) :  fsfF_Depth_rest_rel\"\napply (case_tac \"P1 ~: fsfF_proc\")\napply (simp add: fsfF_Depth_rest_rel_exists_notin)\napply (simp add: fsfF_Depth_rest_rel_exists_in)\ndone\n\n(*-----------------------*\n |    uniquely exists    |\n *-----------------------*)\n\nlemma fsfF_Depth_rest_rel_unique_exists:\n   \"EX! SP. (P1, n, SP) :  fsfF_Depth_rest_rel\"\napply (simp add: fsfF_Depth_rest_rel_EX1[THEN sym])\napply (simp add: fsfF_Depth_rest_rel_exists)\ndone\n\n(*------------------------------------------------------------*\n |                        in fsfF_proc                        |\n *------------------------------------------------------------*)\n\nlemma fsfF_Depth_rest_rel_zero_in:\n  \"(P1, 0, SP) : fsfF_Depth_rest_rel ==> SP : fsfF_proc\"\napply (simp add: fsfF_Depth_rest_rel_zero_iff)\ndone\n\nlemma fsfF_Depth_rest_rel_in_lm:\n  \"P1 : fsfF_proc ==> \n   ALL n SP. (P1, n, SP) : fsfF_Depth_rest_rel --> SP : fsfF_proc\"\napply (rule fsfF_proc.induct[of P1])\napply (simp)\n\n(* int nat *)\napply (intro allI)\napply (insert nat_zero_or_Suc)\napply (drule_tac x=\"n\" in spec)\napply (elim disjE exE)\napply (simp add: fsfF_Depth_rest_rel_zero_in)\n\napply (intro impI)\napply (simp)\napply (rotate_tac -1)\napply (erule fsfF_Depth_rest_rel.cases, simp_all)\n\n apply (rotate_tac -4)\n apply (drule sym)\n apply (simp add: fsfF_proc.intros)\n\napply (rule fsfF_proc.intros)\napply (simp_all)\napply (rule ballI)\napply (drule_tac x=\"c\" in spec)\napply (drule_tac x=\"c\" in bspec, simp)\napply (force)\n\n(* ext *)\napply (intro allI)\napply (drule_tac x=\"n\" in spec)\napply (rotate_tac -1)\napply (erule disjE)\napply (simp add: fsfF_Depth_rest_rel_zero_in)\n\napply (intro impI)\napply (erule fsfF_Depth_rest_rel.cases, simp_all)\n\n apply (rotate_tac -4)\n apply (drule sym)\n apply (simp add: fsfF_proc.intros)\n\napply (rule fsfF_proc.intros)\napply (simp_all)\napply (rule ballI)\napply (drule_tac x=\"a\" in spec)\napply (drule_tac x=\"a\" in bspec, simp)\napply (force)\ndone\n\n(*------------------------------------*\n |                 in                 |\n *------------------------------------*)\n\nlemma fsfF_Depth_rest_rel_in:\n  \"[| P1 : fsfF_proc ; (P1, n, SP) : fsfF_Depth_rest_rel |]\n   ==> SP : fsfF_proc\"\napply (insert fsfF_Depth_rest_rel_in_lm[of P1])\napply (blast)\ndone\n\n(*------------------------------------------------------------*\n |             syntactical transformation to fsfF             |\n *------------------------------------------------------------*)\n\n(*** relation ***)\n\nlemma cspF_fsfF_Depth_rest_rel_eqF_zero:\n   \"(P1, 0, SP) : fsfF_Depth_rest_rel\n     ==> P1 |. 0 =F SP\"\napply (simp add: fsfF_Depth_rest_rel_zero_iff)\napply (rule cspF_rw_left)\napply (rule cspF_Depth_rest_Zero)\napply (rule cspF_SDIV_eqF)\ndone\n\nlemma cspF_fsfF_Depth_rest_rel_eqF_notin:\n   \"[| P1 ~: fsfF_proc ; (P1, n, SP) : fsfF_Depth_rest_rel |]\n    ==> P1 |. n =F SP\"\napply (insert nat_zero_or_Suc)\napply (drule_tac x=\"n\" in spec)\napply (elim disjE exE)\napply (simp add: cspF_fsfF_Depth_rest_rel_eqF_zero)\napply (simp add: fsfF_Depth_rest_rel_etc_iff)\ndone\n\nlemma cspF_fsfF_Depth_rest_rel_eqF_in:\n    \"P1 : fsfF_proc ==>\n     ALL n SP. (P1, n, SP) : fsfF_Depth_rest_rel\n                --> P1 |. n =F SP\"\napply (rule fsfF_proc.induct[of P1])\napply (simp)\n\n(* int *)\napply (intro allI)\napply (insert nat_zero_or_Suc)\napply (drule_tac x=\"n\" in spec)\napply (elim disjE exE)\napply (simp add: cspF_fsfF_Depth_rest_rel_eqF_zero)\n\napply (intro impI)\napply (simp)\napply (rotate_tac -1)\napply (erule fsfF_Depth_rest_rel.cases, simp_all)\napply (elim conjE)\n\napply (rule cspF_rw_left)\napply (rule cspF_Dist)\napply (rule cspF_decompo)\napply (simp)\napply (drule_tac x=\"c\" in bspec, simp)\napply (drule_tac x=\"c\" in spec)\napply (simp)\n\n(* ext *)\napply (intro allI)\napply (drule_tac x=\"n\" in spec)\napply (rotate_tac -1)\napply (erule disjE)\napply (simp add: cspF_fsfF_Depth_rest_rel_eqF_zero)\n\napply (intro impI)\napply (erule fsfF_Depth_rest_rel.cases, simp_all)\n\napply (rule cspF_rw_left)\napply (rule cspF_Ext_dist)\napply (rule cspF_decompo)\n\n apply (rule cspF_rw_left)\n apply (rule cspF_step)\n apply (rule cspF_decompo)\n apply (simp)\n apply (simp)\n apply (case_tac \"Q = STOP\")\n apply (simp add: cspF_STOP_Depth_rest)\n apply (simp add: cspF_SKIP_or_DIV_Depth_rest)\ndone\n\n(*------------------------------------*\n |                 eqF                |\n *------------------------------------*)\n\nlemma cspF_fsfF_Depth_rest_rel_eqF:\n   \"(P1, n, SP) : fsfF_Depth_rest_rel ==> P1 |. n =F SP\"\napply (case_tac \"P1 ~: fsfF_proc\")\napply (simp add: cspF_fsfF_Depth_rest_rel_eqF_notin)\napply (simp add: cspF_fsfF_Depth_rest_rel_eqF_in)\ndone\n\n(*************************************************************\n                  relation --> function\n *************************************************************)\n\nlemma fsfF_Depth_rest_in_rel:\n    \"(P1, n, P1 |.seq n) : fsfF_Depth_rest_rel\"\napply (simp add: fsfF_Depth_rest_def)\napply (rule theI'\n  [of \"(%R. (P1, n, R) : fsfF_Depth_rest_rel)\"])\napply (simp add: fsfF_Depth_rest_rel_unique_exists)\ndone\n\nlemma fsfF_Depth_rest_from_rel:\n    \"((P1, n, SP) : fsfF_Depth_rest_rel)\n   = (P1 |.seq n = SP)\"\napply (rule iffI)\napply (simp add: fsfF_Depth_rest_def)\napply (simp add: fsfF_Depth_rest_rel_unique_exists the1_equality)\n\napply (drule sym)\napply (simp add: fsfF_Depth_rest_in_rel)\ndone\n\nlemma fsfF_Depth_rest_to_rel:\n    \"(P1 |.seq n = SP)\n   = ((P1, n, SP) : fsfF_Depth_rest_rel)\"\nby (simp add: fsfF_Depth_rest_from_rel)\n\n(*************************************************************\n                          function\n *************************************************************)\n\nlemma fsfF_Depth_rest_zero:\n  \"P1 |.seq 0 = SDIV\"\napply (simp add: fsfF_Depth_rest_to_rel)\napply (simp add: fsfF_Depth_rest_rel_zero_iff)\ndone\n\nlemma fsfF_Depth_rest_etc:\n  \"P1 ~: fsfF_proc\n   ==> P1 |.seq (Suc n) = P1 |. (Suc n)\"\napply (simp add: fsfF_Depth_rest_to_rel)\napply (simp add: fsfF_Depth_rest_rel_etc_iff)\ndone\n\nlemma fsfF_Depth_rest_int:\n  \"[| sumset C1 ~= {} ; ALL c: sumset C1. Rf1 c : fsfF_proc |]\n   ==>\n   (!! :C1 .. Rf1) |.seq (Suc m) = \n    !! c:C1 .. (if c: sumset C1 then (Rf1 c |.seq (Suc m)) else DIV)\"\napply (simp add: fsfF_Depth_rest_to_rel)\napply (rule fsfF_Depth_rest_rel_int)\napply (simp_all)\napply (simp split: if_split)\napply (simp add: fsfF_Depth_rest_in_rel)\ndone\n\nlemma fsfF_Depth_rest_step:\n  \"[| ALL a:A1. Pf1 a : fsfF_proc ; Q1 = SKIP | Q1 = DIV | Q1 = STOP |]\n   ==>\n    ((? :A1 -> Pf1) [+] Q1) |.seq (Suc n) = \n    ((? a:A1 -> (if (a:A1) then (Pf1 a |.seq n) else DIV)) [+] Q1)\"\napply (simp add: fsfF_Depth_rest_to_rel)\napply (rule fsfF_Depth_rest_rel_step)\napply (simp_all)\napply (simp split: if_split)\napply (simp add: fsfF_Depth_rest_in_rel)\ndone\n\nlemmas fsfF_Depth_rest =\n       fsfF_Depth_rest_etc\n       fsfF_Depth_rest_int\n       fsfF_Depth_rest_step\n\n(*------------------------------------------------------------*\n |                        in fsfF_proc                        |\n *------------------------------------------------------------*)\n\nlemma fsfF_Depth_rest_in:\n  \"P1 : fsfF_proc\n   ==> P1 |.seq n : fsfF_proc\"\napply (rule fsfF_Depth_rest_rel_in[of P1 n])\napply (simp_all add: fsfF_Depth_rest_in_rel)\ndone\n\n(*------------------------------------------------------------*\n |             syntactical transformation to fsfF             |\n *------------------------------------------------------------*)\n\nlemma cspF_fsfF_Depth_rest_eqF:\n   \"P1 |. n =F P1 |.seq n\"\napply (rule cspF_fsfF_Depth_rest_rel_eqF)\napply (simp add: fsfF_Depth_rest_in_rel)\ndone\n\n(****************** to add them again ******************)\n\ndeclare if_split    [split]\ndeclare disj_not1   [simp]\n\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/FNF_F/FNF_F_sf_rest.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6334102636778401, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.29940256556230654}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory Memcpy\nimports\n  \"../../../c-parser/CTranslation\"\n  \"../../AutoCorres\"\nbegin\n\nabbreviation \"ADDR_MAX \\<equiv> UWORD_MAX TYPE(addr_bitsize)\"\n\n(* Helper for noticing when you accidentally haven't constrained an of_nat *)\nabbreviation \"of_nat_addr \\<equiv> of_nat::(nat \\<Rightarrow> addr)\"\n\nlemma byte_ptr_guarded:\n    \"ptr_val (x::8 word ptr) \\<noteq> 0 \\<Longrightarrow> c_guard x\"\n  unfolding c_guard_def c_null_guard_def ptr_aligned_def\n  by (clarsimp simp: intvl_Suc)\n\n(* FIXME: MOVE *)\nlemma ptr_add_coerce: \"ptr_val (((ptr_coerce x)::('a::{c_type}) ptr) +\\<^sub>p a) = (ptr_val x) + (of_int a * of_nat (size_of TYPE('a)))\"\n  apply (case_tac x)\n  apply (clarsimp simp: CTypesDefs.ptr_add_def)\n  done\n\n(* FIXME: MOVE *)\n(* Casting a valid pointer to char* and incrementing it by a value less than\n * the size of the underlying type does not give us NULL.\n *)\nlemma ptr_contained:\"\\<lbrakk> c_guard (x::('a::c_type) ptr); size_of TYPE('a) = sz;\n                       0 \\<le> i; i < int sz; (y::8 word ptr) = ptr_coerce x\\<rbrakk> \\<Longrightarrow> c_guard (y +\\<^sub>p i)\"\n  apply (rule byte_ptr_guarded)\n  unfolding c_guard_def c_null_guard_def ptr_add_def\n  apply simp\n  apply (clarsimp simp: CTypesDefs.ptr_add_def intvl_def)\n  apply (erule allE [where x=\"nat i\"])\n  apply (clarsimp simp: nat_less_iff of_nat_nat)\n  done\n\ninstall_C_file \"memcpy.c\"\n\n(* FIXME: MOVE *)\nlemma squash_auxupd_id[polish]:\n  \"modify (t_hrs_'_update (hrs_htd_update id)) = skip\"\n  by (monad_eq simp: skip_def id_def hrs_htd_update_def)\n\nautocorres [no_heap_abs=memcpy memcpy_int] \"memcpy.c\"\n\n(* Dereference a pointer *)\nabbreviation \"deref s x \\<equiv> h_val (hrs_mem (t_hrs_' s)) x\"\n\n(* char* cast *)\nabbreviation \"byte_cast x \\<equiv> ((ptr_coerce x)::8 word ptr)\"\n\ncontext memcpy begin\n\nlemma memcpy_char:\n  \"\\<lbrace> \\<lambda>s. c_guard (x::8 word ptr) \\<and>\n         c_guard (y::8 word ptr) \\<and>\n         unat sz = size_of TYPE(8 word) \\<and>\n         P (deref s x) \\<and>\n         x \\<noteq> y\\<rbrace>\n      memcpy' (ptr_coerce y) (ptr_coerce x) sz\n   \\<lbrace>\\<lambda> _ s. P (deref s y) \\<rbrace>!\"\n  (* Evaluate sz *)\n  apply clarsimp\n\n  unfolding memcpy'_def\n  apply (clarsimp simp:skip_def)\n  apply wp\n\n  (* Unroll the loop twice *)\n  apply (subst whileLoop_unroll, wp)\n     apply (subst whileLoop_unroll, wp)\n\n  (* The remaining loop is never encountered *)\n       apply (rule validNF_false_pre)\n      apply wp+\n\n  (* Finally we're left with the single assignment *)\n  apply (clarsimp simp:hrs_mem_update h_val_heap_update)\n  apply unat_arith\n done\n\nlemma of_nat_prop_exp: \"n < 32 \\<Longrightarrow> of_nat (2 ^ n) = 2 ^ (of_nat n)\"\n  by clarsimp\n\nlemma memcpy_word:\n  \"\\<lbrace> \\<lambda>s. c_guard (x::32 word ptr) \\<and>\n         c_guard (y::32 word ptr) \\<and>\n         unat sz = size_of TYPE(32 word) \\<and>\n         P (deref s x) \\<and>\n         x \\<noteq> y \\<rbrace>\n      memcpy' (ptr_coerce y) (ptr_coerce x) sz\n   \\<lbrace> \\<lambda>_ s. P (deref s y) \\<rbrace>!\"\n  apply clarsimp\n  unfolding memcpy'_def apply (clarsimp simp:skip_def)\n  apply (rule validNF_assume_pre)\n  apply (subgoal_tac \"{ptr_val x ..+ unat sz} \\<inter> {ptr_val y ..+ unat sz} = {}\")\n   apply (subst whileLoop_add_inv [where\n     I=\"\\<lambda>i s.  unat i \\<le> unat sz \\<and>\n                (\\<forall>a < i. deref s (byte_cast x +\\<^sub>p uint a) = deref s (byte_cast y +\\<^sub>p uint a)) \\<and>\n                P (deref s x)\" and\n     M=\"\\<lambda>(i, s). unat sz - unat i\"])\n   apply (wp validNF_whileLoop_inv_measure_twosteps)\n      apply clarsimp\n      apply (rule conjI, unat_arith)\n      apply (rule conjI, clarsimp)\n       apply (case_tac \"a = i\")\n        apply (clarsimp)\n        apply (erule_tac x=i in allE)\n        apply (clarsimp simp:hrs_mem_update h_val_heap_update)\n        apply (subst h_val_heap_same)\n            apply (rule ptr_retyp_h_t_valid)\n            apply simp\n           apply (rule ptr_retyp_disjoint)\n            apply (rule ptr_retyp_h_t_valid)\n            apply simp\n           apply (clarsimp simp:ptr_add_def intvl_def CTypesDefs.ptr_add_def)\n          apply simp\n         apply (clarsimp simp: CTypesDefs.ptr_add_def field_of_t_simple)\n         apply (drule field_of_t_simple)\n         apply clarsimp\n        apply simp\n       apply (subgoal_tac \"a < i\")\n        apply (clarsimp simp:hrs_mem_update)\n        apply (subst h_val_heap_update_disjoint)\n\n         (* The current goal should be obvious to unat_arith, but for some reason isn't *)\n         apply (clarsimp simp:ptr_add_def intvl_def disjoint_iff_not_equal)\n         apply (erule_tac x=\"ptr_val x + a\" in allE, clarsimp)\n         apply (erule impE)\n          apply (rule_tac x=\"unat a\" in exI, clarsimp)\n          apply unat_arith\n\n         apply (erule_tac x=\"ptr_val y + i\" and\n                          P=\"\\<lambda>ya. (\\<exists>k. ya = ptr_val y + of_nat k \\<and> k < 4) \\<longrightarrow> ptr_val y + i \\<noteq> ya\" in allE, clarsimp)\n         apply (erule_tac x=\"unat i\" in allE, clarsimp)\n          apply unat_arith\n         apply (clarsimp simp:CTypesDefs.ptr_add_def)\n        apply (subst h_val_heap_update_disjoint)\n         (* Similar goal to the previous irritation, but this time Isabelle decides to play ball *)\n         apply (clarsimp simp:ptr_add_def intvl_def ptr_val_def disjoint_iff_not_equal)\n        apply (clarsimp simp:CTypesDefs.ptr_add_def)\n       apply (clarsimp simp:CTypesDefs.ptr_add_def)\n      apply unat_arith\n\n      apply (rule conjI)\n       apply (subst hrs_mem_update)+\n       apply (subst h_val_heap_update_disjoint)\n        apply (clarsimp simp: disjoint_iff_not_equal)\n        apply (clarsimp simp:CTypesDefs.ptr_add_def intvl_def)\n        apply (erule_tac x=\"ptr_val x + of_nat k\" in allE)\n        apply (erule impE)\n         apply (rule_tac x=\"k\" in exI)\n         apply simp\n        apply (erule_tac x=\"ptr_val y + i\" and\n                         P=\"\\<lambda>ya. (\\<exists>k. ya = ptr_val y + of_nat k \\<and> k < 4) \\<longrightarrow> ptr_val x + of_nat k \\<noteq> ya\" in allE)\n        apply (erule impE)\n         apply (rule_tac x=\"unat i\" in exI)\n         apply simp\n         apply unat_arith\n        apply simp\n       apply simp\n\n      (* Yet more tedium that unat_arith doesn't like *)\n      apply (rule conjI)\n       apply (rule byte_ptr_guarded,\n              clarsimp simp:CTypesDefs.ptr_add_def c_guard_def c_null_guard_def intvl_def,\n              (erule_tac x=\"unat i\" in allE)+,\n              clarsimp,\n              unat_arith)+\n\n     apply wp\n     apply unat_arith\n    apply clarsimp\n    apply (subgoal_tac \"deref sa x = deref sa y\")\n     apply clarsimp\n    apply (clarsimp simp: h_val_def)[1]\n    apply (rule arg_cong[where f=from_bytes])\n    apply (subst numeral_eqs(3))+\n    apply simp\n    apply (rule_tac x=0 in allE, assumption, erule impE, unat_arith)\n    apply (rule_tac x=1 in allE, assumption, erule impE, unat_arith)\n    apply (rule_tac x=2 in allE, assumption, erule impE, unat_arith)\n    apply (rule_tac x=3 in allE, assumption, erule impE, unat_arith)\n    apply (simp add:CTypesDefs.ptr_add_def)\n    apply (simp add: add.commute from_bytes_eq)\n   apply clarsimp\n  apply (clarsimp simp:intvl_def disjoint_iff_not_equal)\n  apply (drule_tac x=x and y=y and j=\"of_nat k\" and i=\"of_nat ka\" and n=2 in neq_imp_bytes_disjoint)\n        apply assumption\n       apply (case_tac \"k = 0\", clarsimp) (* insert \"k > 0\" *)\n       apply (clarsimp simp:unat_of_nat_len)\n      apply (case_tac \"ka = 0\", clarsimp)\n      apply (clarsimp simp:unat_of_nat_len)\n     apply assumption\n    apply clarsimp+\n  done\n\ntext {* The bytes at the pointer @{term p} are @{term bs}. *}\ndefinition\n  bytes_at :: \"'a globals_scheme \\<Rightarrow> 'b::c_type ptr \\<Rightarrow> word8 list \\<Rightarrow> bool\"\nwhere\n  \"bytes_at s p bs \\<equiv> length bs = 0 \\<or>\n                      (length bs \\<le> ADDR_MAX \\<and> (\\<forall>i \\<in> {0..(length bs - 1)}. deref s (byte_cast p +\\<^sub>p (of_nat i)) = bs ! i))\"\n\nlemma bytes_at_none[simp]: \"bytes_at s p []\"\n  by (clarsimp simp:bytes_at_def)\n\ntext {* The bytes of typed pointer @{term p} are @{term bs}. *}\ndefinition\n  bytes_of :: \"'a globals_scheme \\<Rightarrow> 'b::c_type ptr \\<Rightarrow> word8 list \\<Rightarrow> bool\"\nwhere\n  \"bytes_of s p bs \\<equiv> length bs = size_of TYPE('b) \\<and> bytes_at s p bs\"\n\ntext {* The bytes at a char pointer are just it dereferenced. *}\nlemma bytes_of_char[simp]: \"bytes_of s (p::8word ptr) bs = (length bs = 1 \\<and> deref s p = hd bs)\"\n  apply (clarsimp simp:bytes_of_def bytes_at_def)\n  apply (rule iffI)\n   apply clarsimp\n   apply (erule disjE)\n    apply clarsimp+\n   apply (rule hd_conv_nth[symmetric])\n   apply clarsimp+\n  apply (subgoal_tac \"hd bs = bs ! 0\")\n   apply simp\n  apply (rule hd_conv_nth)\n  apply clarsimp\n  done\n\ntext {* A pointer does not wrap around memory. *}\ndefinition\n  no_wrap :: \"'a::c_type ptr \\<Rightarrow> nat \\<Rightarrow> bool\"\nwhere\n  \"no_wrap p sz \\<equiv> 0 \\<notin> {ptr_val p ..+ sz}\"\n\ntext {* Two pointers do not overlap. *}\ndefinition\n  no_overlap :: \"'a::c_type ptr \\<Rightarrow> 'b::c_type ptr \\<Rightarrow> nat \\<Rightarrow> bool\"\nwhere\n  \"no_overlap p q sz \\<equiv> {ptr_val p ..+ sz} \\<inter> {ptr_val q ..+ sz} = {}\"\n\nlemma no_overlap_sym: \"no_overlap x y = no_overlap y x\"\n  apply (rule ext)\n  apply (clarsimp simp:no_overlap_def)\n  by blast\n\n(* FIXME: MOVE *)\nlemma h_val_not_id:\n  fixes x :: \"'a::mem_type ptr\"\n    and y :: \"'b::mem_type ptr\"\n  shows \"{ptr_val x..+size_of TYPE('a)} \\<inter> {ptr_val y..+size_of TYPE('b)} = {}\n     \\<Longrightarrow> h_val (hrs_mem (hrs_mem_update (heap_update x v) s)) y = h_val (hrs_mem s) y\"\n  apply (subst hrs_mem_heap_update[symmetric])\n  apply (subst h_val_heap_update_disjoint)\n   apply blast\n  apply clarsimp\n  done\n\ndefinition\n  update_bytes :: \"'a globals_scheme \\<Rightarrow> 'b::mem_type ptr \\<Rightarrow> word8 list \\<Rightarrow> 'a globals_scheme\"\nwhere\n  \"update_bytes s p bs \\<equiv> s\\<lparr>t_hrs_' := hrs_mem_update (heap_update_list (ptr_val p) bs) (t_hrs_' s)\\<rparr>\"\n\nlemma the_horse_says_neigh: \"(s\\<lparr>t_hrs_' := x\\<rparr> = s\\<lparr>t_hrs_' := y\\<rparr>) = (x = y)\"\n by (metis (erased, lifting) globals.cases_scheme globals.select_convs(1) globals.update_convs(1))\n\nlemma upto_singleton[simp]:\"[x..x] = [x]\"\n  by (simp add: upto_rec1)\n\nlemma update_bytes_ignore_ptr_coerce[simp]: \"update_bytes s (ptr_coerce p) = update_bytes s p\"\n  by (clarsimp simp:update_bytes_def intro!:ext)\n\nlemma hrs_mem_update_commute:\n  \"f \\<circ> g = g \\<circ> f \\<Longrightarrow> hrs_mem_update f (hrs_mem_update g s) = hrs_mem_update g (hrs_mem_update f s)\"\n  by (metis (no_types, lifting) comp_eq_elim hrs_htd_def hrs_htd_mem_update hrs_mem_def hrs_mem_f prod.collapse)\n\nlemma hrs_mem_update_collapse:\n  \"hrs_mem_update f (hrs_mem_update g s) = hrs_mem_update (f \\<circ> g) s\"\n  by (metis comp_eq_dest_lhs hrs_htd_def hrs_htd_mem_update hrs_mem_def hrs_mem_f prod.collapse)\n\nlemma update_bytes_reorder:\n  \"{ptr_val p..+length cs} \\<inter> {ptr_val q..+length bs} = {} \\<Longrightarrow>\n      update_bytes (update_bytes s q bs) p cs = update_bytes (update_bytes s p cs) q bs\"\n  apply (clarsimp simp:update_bytes_def)\n  apply (subst the_horse_says_neigh)\n  apply (subst hrs_mem_update_commute)\n   apply (clarsimp intro!:ext)\n   apply (subst heap_update_list_commute)\n    apply clarsimp+\n  done\n\nlemma lt_step_down: \"\\<lbrakk>(x::nat) < y; x = y - 1 \\<longrightarrow> P; x < y - 1 \\<longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  by force\n\n(* XXX: This proof makes me sad. *)\nlemma under_uint_imp_no_overflow: \"x < ADDR_MAX \\<Longrightarrow> ((of_nat x)::addr) + 1 \\<noteq> 0\"\n  apply (induct x)\n   apply (clarsimp simp:UWORD_MAX_def)+\n  apply unat_arith\n  apply (clarsimp simp:UWORD_MAX_def)\n  apply (cut_tac y=x and z=\"(of_nat (ADDR_MAX - 1))::addr\" in le_unat_uoi)\n   apply (clarsimp simp:UWORD_MAX_def)+\n  done\n\nlemma heap_update_list_append3:\n  \"1 + length ys < 2 ^ word_bits \\<Longrightarrow>\n    heap_update_list s (y # ys) hp = heap_update_list s [y] (heap_update_list (s + 1) ys hp)\"\n  apply clarsimp\n  apply (subst heap_update_list_append2[where xs=\"[y]\", simplified])\n   apply clarsimp+\n  done\n\nlemma hrs_mem_update_cong': \"f = g \\<Longrightarrow> hrs_mem_update f s = hrs_mem_update g s\"\n  by presburger\n\nlemma update_bytes_append: \"length bs \\<le> ADDR_MAX \\<Longrightarrow>\n  update_bytes s p (b # bs) = update_bytes (update_bytes s p [b]) (byte_cast p +\\<^sub>p 1) bs\"\n  apply (clarsimp simp:update_bytes_def)\n  apply (subst the_horse_says_neigh)\n  apply (subst hrs_mem_update_commute)\n   apply (rule ext)+\n   apply simp\n   apply (case_tac \"xa = ptr_val p\")\n    apply (clarsimp simp:fun_upd_def)\n    apply (subst heap_update_nmem_same)\n     apply (clarsimp simp:intvl_def ptr_add_def)\n     apply (subgoal_tac \"k < ADDR_MAX\")\n      prefer 2\n      apply unat_arith\n     apply (drule under_uint_imp_no_overflow)\n     apply unat_arith\n    apply clarsimp\n   apply (subst heap_update_list_update)\n    apply simp\n   apply (clarsimp simp:fun_upd_def)\n  apply (subst hrs_mem_update_collapse)\n  apply (rule hrs_mem_update_cong')\n  apply (clarsimp simp:ptr_add_def)\n  apply (rule ext)\n  apply (cut_tac xs=\"[b]\" and ys=bs and s=\"ptr_val p\" and hp=x in heap_update_list_append)\n  apply (clarsimp simp:fun_upd_def intro!:ext)\n  apply (rule conjI)\n   apply clarsimp\n   apply (subst heap_update_nmem_same)\n    apply (clarsimp simp:ptr_add_def intvl_def)\n    apply (subgoal_tac \"k < ADDR_MAX\")\n     prefer 2\n     apply unat_arith\n    apply (drule under_uint_imp_no_overflow)\n    apply unat_arith\n   apply clarsimp\n  apply clarsimp\n  apply (case_tac \"xa \\<in> {ptr_val p + 1..+length bs}\")\n  apply (subst heap_update_mem_same_point)\n    apply simp\n   apply (subgoal_tac \"addr_card = ADDR_MAX + 1\")\n    apply clarsimp\n   apply (clarsimp simp:addr_card UWORD_MAX_def)\n  apply (subst heap_update_mem_same_point)\n    apply simp\n   apply (subgoal_tac \"addr_card = ADDR_MAX + 1\")\n    apply clarsimp\n   apply (clarsimp simp:addr_card UWORD_MAX_def)\n  apply clarsimp\n  apply (subst heap_update_nmem_same)\n   apply clarsimp\n  apply (subst heap_update_nmem_same)\n   apply clarsimp+\n  done\n\nlemma update_bytes_postpend: \"length bs = x + 1 \\<Longrightarrow>\n  update_bytes s p bs = update_bytes (update_bytes s p (take x bs)) (byte_cast p +\\<^sub>p (of_nat x)) [bs ! x]\"\n  apply (clarsimp simp:update_bytes_def)\n  apply (subst the_horse_says_neigh)\n  apply (clarsimp simp:ptr_add_def)\n  apply (subst heap_update_list_concat_fold_hrs_mem)\n   apply clarsimp+\n  by (metis append_eq_conv_conj append_self_conv hd_drop_conv_nth2 lessI take_hd_drop)\n\nlemma h_val_not_id_general:\n  fixes y :: \"'a::mem_type ptr\"\n  shows \"\\<forall>i \\<in> {0..+size_of TYPE('a)}. \\<forall>g. f g (ptr_val y + i) = g (ptr_val y + i)\n     \\<Longrightarrow> h_val (hrs_mem (hrs_mem_update f s)) y = h_val (hrs_mem s) y\"\n  apply (subst hrs_mem_update)\n  apply (clarsimp simp:h_val_def)\n  apply (subgoal_tac \"heap_list (f (hrs_mem s)) (size_of TYPE('a)) (ptr_val y) =\n                      heap_list (hrs_mem s) (size_of TYPE('a)) (ptr_val y)\")\n   apply clarsimp\n  apply (cut_tac h=\"f (hrs_mem s)\" and p=\"ptr_val y\" and n=\"size_of TYPE('a)\"\n                 and h'=\"hrs_mem s\" in heap_list_h_eq2)\n   apply (erule_tac x=\"x - ptr_val y\" in  ballE)\n    apply clarsimp\n   apply (clarsimp simp:intvl_def)+\n  done\n\nlemma h_val_not_id_list:\n  fixes y :: \"'a::mem_type ptr\"\n  shows \"{x..+length vs} \\<inter> {ptr_val y..+size_of TYPE('a)} = {}\n     \\<Longrightarrow> h_val (hrs_mem (hrs_mem_update (heap_update_list x vs) s)) y = h_val (hrs_mem s) y\"\n  apply (subst h_val_not_id_general)\n   apply clarsimp\n   apply (metis (erased, hide_lams) disjoint_iff_not_equal heap_update_nmem_same intvlD intvlI\n          monoid_add_class.add.left_neutral)\n  apply clarsimp\n  done\n\nlemma h_val_id_update_bytes:\n  fixes q :: \"'a::mem_type ptr\"\n  shows \"{ptr_val q..+size_of TYPE('a)} \\<inter> {ptr_val p..+length bs} = {}\n          \\<Longrightarrow> deref (update_bytes s p bs) q = deref s q\"\n  apply (clarsimp simp:update_bytes_def)\n  apply (subst h_val_not_id_list)\n   apply blast\n  by simp\n\nlemma bytes_at_len: \"bytes_at s p bs \\<Longrightarrow> length bs \\<le> ADDR_MAX\"\n  by (clarsimp simp:bytes_at_def, fastforce)\n\n(* Another sad proof. *)\nlemma le_uint_max_imp_id: \"x \\<le> ADDR_MAX \\<Longrightarrow> unat ((of_nat x)::addr) = x\"\n  apply (induct x)\n   apply (clarsimp simp: UWORD_MAX_def)+\n  apply unat_arith\n  apply clarsimp\n  done\n\nlemma update_bytes_id: \"update_bytes s p [] = s\"\n  apply (clarsimp simp:update_bytes_def)\n  apply (subst heap_update_list_base')\n  by (simp add: hrs_mem_update_id3)\n\nlemma a_horse_by_any_other_name: \"t_hrs_'_update f s = s\\<lparr>t_hrs_' := f (t_hrs_' s)\\<rparr>\"\n  by auto\n\nlemma heap_update_list_singleton: \"heap_update_list p [x] = heap_update (Ptr p) x\"\n  apply (rule ext)\n  by (metis heap_update_def ptr_val.simps to_bytes_word8)\n\nlemma update_bytes_eq: \"\\<lbrakk>s = s'; p = p'; bs = bs'\\<rbrakk> \\<Longrightarrow> update_bytes s p bs = update_bytes s' p' bs'\"\n  by clarsimp\n\ntext {*\n  Memcpy does what it says on the box.\n*}\nlemma memcpy_wp':\n  fixes src :: \"'a::mem_type ptr\"\n    and dst :: \"'b::mem_type ptr\"\n  shows \"\\<forall>s0 bs.\n  \\<lbrace>\\<lambda>s. s = s0 \\<and> c_guard src \\<and> c_guard dst \\<and> sz = of_nat (length bs) \\<and> bytes_at s src bs \\<and>\n       no_wrap src (unat sz) \\<and> no_wrap dst (unat sz) \\<and> no_overlap src dst (unat sz)\\<rbrace>\n    memcpy' (ptr_coerce dst) (ptr_coerce src) sz\n  \\<lbrace>\\<lambda>r s. r = ptr_coerce dst \\<and> bytes_at s dst bs \\<and> s = update_bytes s0 dst bs\\<rbrace>!\"\n  apply (rule allI)+\n  apply (rule validNF_assume_pre)\n  unfolding memcpy'_def\n  apply clarsimp\n  apply (subst whileLoop_add_inv[where\n    I=\"\\<lambda>i s. unat i \\<le> unat sz \\<and>\n             bytes_at s dst (take (unat i) bs) \\<and>\n             bytes_at s src bs \\<and>\n             s = update_bytes s0 dst (take (unat i) bs)\" and\n    M=\"\\<lambda>(i, s). unat sz - unat i\"])\n  apply wp\n    apply clarsimp\n    apply (rule conjI)\n     apply unat_arith\n    apply (rule conjI)\n     apply (simp add:bytes_at_def)\n     apply (case_tac \"bs = []\")\n      apply (rule disjI1)\n      apply clarsimp\n     apply (rule disjI2)\n     apply clarsimp\n     apply (rule conjI)\n      apply unat_arith\n     apply clarsimp\n     apply (case_tac \"unat i = ia\")\n      apply clarsimp\n      apply (subgoal_tac \"int (unat i) = uint i\")\n       prefer 2\n       apply (subst uint_nat)\n       apply simp\n      apply simp\n      apply (subst h_val_id)\n      apply (subst h_val_id_update_bytes)\n       apply (clarsimp simp:no_overlap_def ptr_add_def)\n       apply (subgoal_tac \"{ptr_val src + i..+Suc 0} \\<subseteq> {ptr_val src..+unat (of_nat_addr (length bs))}\")\n        prefer 2\n        apply (clarsimp simp:intvl_def)\n        apply (rule_tac x=\"unat i\" in exI)\n        apply unat_arith\n       apply (subgoal_tac \"{ptr_val dst..+unat i} \\<subseteq> {ptr_val dst..+unat (of_nat_addr (length bs))}\")\n        prefer 2\n        apply (clarsimp simp:intvl_def)\n        apply (rule exI, rule conjI, rule refl)\n        apply (simp add: unat_of_nat)\n       apply blast\n      apply (erule_tac x=\"unat i\" and P=\"\\<lambda>x. deref s0 (byte_cast src +\\<^sub>p int x) = bs ! x\" in ballE)\n       apply clarsimp\n       apply (subst nth_take)\n        apply unat_arith\n       apply simp\n      apply (erule disjE)\n       apply clarsimp+\n     apply (erule disjE)\n      apply (subgoal_tac \"length bs \\<noteq> 0\")\n       prefer 2\n       apply clarsimp\n      apply (case_tac \"unat i = 0\")\n       apply unat_arith\n      apply linarith\n     apply (subst h_val_not_id)\n      apply (clarsimp simp:ptr_add_def intvl_def)\n      (* Isabelle, why do you have to make it so hard? *)\n      apply (erule_tac P=\"unat (of_nat ia) = ia\" in notE)\n      apply (cut_tac y=ia and z=\"(of_nat ADDR_MAX)::addr\" in le_unat_uoi)\n       apply (subgoal_tac \"unat ((of_nat ADDR_MAX)::addr) = ADDR_MAX\")\n        prefer 2\n        apply (simp add: unat_of_nat)\n       apply (simp add: unat_of_nat)\n      apply clarsimp\n     apply clarsimp\n     apply (erule_tac x=ia and A=\"{0..min (length bs) (unat i) - Suc 0}\" in ballE)\n      apply clarsimp\n      apply (subst nth_take, unat_arith)+\n      apply simp\n     apply clarsimp\n     apply unat_arith\n    apply (rule conjI)\n     apply (clarsimp simp:bytes_at_def)\n     apply (subst h_val_not_id)\n      apply (clarsimp simp:no_overlap_def)\n      apply (subgoal_tac \"ptr_val (byte_cast dst +\\<^sub>p uint i) \\<in> {ptr_val dst..+unat (of_nat (length bs))}\")\n       prefer 2\n       apply (clarsimp simp:ptr_add_def intvl_def)\n       apply (rule_tac x=\"unat i\" in exI)\n       apply clarsimp\n       apply unat_arith\n      (* More or less symmetric subgoal *)\n      apply (subgoal_tac \"ptr_val (byte_cast src +\\<^sub>p int ia) \\<in> {ptr_val src..+unat ((of_nat (length bs))::addr)}\")\n       prefer 2\n       apply (clarsimp simp:ptr_add_def intvl_def)\n       apply (rule_tac x=ia in exI)\n       apply clarsimp\n       apply (subgoal_tac \"unat ((of_nat (length bs))::addr) = length bs\")\n        apply clarsimp\n        apply arith\n       apply (cut_tac y=\"length bs\" and z=\"(of_nat ADDR_MAX)::addr\" in le_unat_uoi)\n        apply (simp add: unat_of_nat)\n       apply arith\n      apply (clarsimp simp:intvl_def ptr_add_def)\n      apply blast\n     apply clarsimp\n    apply (rule conjI)\n     apply (subst h_val_id_update_bytes)\n      apply (clarsimp simp:no_overlap_def ptr_add_def)\n      apply (subgoal_tac \"{ptr_val src + i..+Suc 0} \\<subseteq> {ptr_val src..+unat (of_nat_addr (length bs))}\")\n       prefer 2\n       apply (clarsimp simp:intvl_def)\n       apply (rule_tac x=\"unat i\" in exI)\n       apply unat_arith\n      apply (subgoal_tac \"{ptr_val dst..+min (length bs) (unat i)} \\<subseteq> {ptr_val dst..+unat (of_nat_addr (length bs))}\")\n       prefer 2\n       apply (clarsimp simp:intvl_def)\n       apply (rule_tac x=ka in exI)\n       apply unat_arith\n      apply blast\n     apply (subgoal_tac \"deref s0 (byte_cast src +\\<^sub>p uint i) = bs ! (unat i)\")\n      apply clarsimp\n      apply (subgoal_tac \"update_bytes s0 dst (take (unat (i + 1)) bs) =\n                          update_bytes (update_bytes s0 dst (take (unat i) bs)) (byte_cast dst +\\<^sub>p uint i) [bs ! unat i]\")\n       apply clarsimp\n       apply (subgoal_tac\n               \"\\<forall>s'. t_hrs_'_update (hrs_mem_update (heap_update (byte_cast dst +\\<^sub>p uint i) (bs ! unat i))) s' =\n                     update_bytes s' (byte_cast dst +\\<^sub>p uint i) [bs ! unat i]\")\n        apply fast\n       apply (clarsimp simp:update_bytes_def)\n       apply (subst a_horse_by_any_other_name)\n       apply (subst the_horse_says_neigh)\n       apply (clarsimp simp:ptr_add_def)\n       apply (subst heap_update_list_singleton)\n       apply simp\n      apply (cut_tac s=s0 and p=dst and bs=\"take (unat (i + 1)) bs\" and x=\"unat i\"\n                     in update_bytes_postpend)\n       apply (subgoal_tac \"unat (i + 1) \\<le> length bs\")\n        apply clarsimp\n        apply unat_arith\n       apply (subgoal_tac \"unat i < length bs\")\n        apply unat_arith\n       apply (rule unat_less_helper)\n       apply simp\n      apply clarsimp\n      apply (rule update_bytes_eq)\n        apply (subgoal_tac \"min (unat i) (unat (i + 1)) = unat i\")\n         apply clarsimp\n        apply clarsimp\n        apply unat_arith\n       apply (clarsimp simp:ptr_add_def)\n      apply clarsimp\n      apply (rule nth_take)\n      apply unat_arith\n     apply (clarsimp simp:bytes_at_def)\n     apply (erule disjE)\n      apply clarsimp\n     apply clarsimp\n     apply (erule_tac x=\"unat i\" in ballE)\n      apply (subst (asm) uint_nat[symmetric])\n      apply simp\n     apply clarsimp\n     apply (subgoal_tac \"unat i < length bs\")\n      prefer 2\n      apply (rule unat_less_helper)\n      apply simp\n     apply unat_arith\n    apply (rule conjI)\n     apply unat_arith\n    apply (rule conjI)\n     apply (rule byte_ptr_guarded)\n     apply (clarsimp simp:no_wrap_def intvl_def ptr_add_def)\n     apply (erule_tac x=\"unat i\" in allE)\n     apply clarsimp\n    apply (rule byte_ptr_guarded)\n    apply (clarsimp simp:no_wrap_def intvl_def ptr_add_def)\n    apply (erule_tac x=\"unat i\" and\n                     P=\"\\<lambda>x. ptr_val dst + ((of_nat x)::addr) = 0 \\<longrightarrow> \\<not> x < unat ((of_nat_addr (length bs))::addr)\"\n                    in allE)\n    apply clarsimp\n   apply clarsimp\n   apply (rule conjI)\n    apply (subgoal_tac \"unat i = length bs\")\n     apply clarsimp\n    apply (case_tac \"length bs = 0\")\n     apply clarsimp\n    apply (subgoal_tac \"length bs \\<le> ADDR_MAX\")\n     prefer 2\n     apply (clarsimp simp:bytes_at_def)\n    (* XXX: We keep introducing this subgoal; we should do it once and for all up top. *)\n    apply (subgoal_tac \"unat ((of_nat (length bs))::addr) = length bs\")\n     prefer 2\n     apply (cut_tac y=\"length bs\" and z=\"(of_nat ADDR_MAX)::addr\" in le_unat_uoi)\n      apply (clarsimp simp:UWORD_MAX_def)\n     apply clarsimp+\n    apply unat_arith\n   (* insert a bunch a tedium... *)\n   apply (subgoal_tac \"unat i = length bs\")\n    prefer 2\n    apply (drule bytes_at_len)\n    apply (subgoal_tac \"unat (of_nat_addr (length bs)) = length bs\")\n     prefer 2\n     apply (rule le_uint_max_imp_id)\n     apply simp\n    apply unat_arith\n   apply clarsimp\n  apply (simp add:update_bytes_id)\n  done\n\nlemma validNF_make_schematic_post':\n  \"(\\<forall>s0 x. \\<lbrace> \\<lambda>s. P s0 x s \\<rbrace> f \\<lbrace> \\<lambda>rv s. Q s0 x rv s \\<rbrace>!) \\<Longrightarrow>\n   \\<lbrace> \\<lambda>s. \\<exists>s0 x. P s0 x s \\<and> (\\<forall>rv s'. Q s0 x rv s' \\<longrightarrow> Q' rv s') \\<rbrace> f \\<lbrace> Q'\\<rbrace>!\"\n  by (auto simp add: valid_def validNF_def no_fail_def split: prod.splits)\n\nlemmas memcpy_wp = memcpy_wp'[THEN validNF_make_schematic_post', simplified]\n\nlemma h_val_not_id_update_bytes:\n  fixes q :: \"'a::mem_type ptr\"\n  shows \"\\<lbrakk>ptr_val p = ptr_val q; length bs = size_of TYPE('a)\\<rbrakk> \\<Longrightarrow>\n            deref (update_bytes s p bs) q = from_bytes bs\"\n  apply (clarsimp simp:update_bytes_def h_val_def)\n  apply (subst hrs_mem_update)\n  apply (cut_tac p=\"ptr_val q\" and v=bs and h=\"hrs_mem (t_hrs_' s)\" in heap_list_update)\n   apply clarsimp\n   apply (metis less_imp_le max_size)\n  by clarsimp\n\ntext {*\n  Test that we can use memcpy in a compositional proof. The following proof can be done much more\n  pleasantly, but we're just trying to check that the memcpy WP lemma is usable.\n  TODO: This relies on disabling heap abstraction for the calling function as well. We should be\n  able to phrase an exec_concrete WP lemma over memcpy that lets us prove properties about\n  heap-abstracted callers. This will need AutoCorres support to connect is_valid_* with\n  c_guard/no_overlap/no_wrap.\n*}\n\ndefinition\n  memcpy_int_spec :: \"sword32 ptr \\<Rightarrow> sword32 ptr \\<Rightarrow> bool\"\nwhere\n  \"memcpy_int_spec dst src \\<equiv>\n    \\<forall>x. \\<lbrace>\\<lambda>s. deref s src = x \\<and>\n             {ptr_val src..+4} \\<inter> {ptr_val dst..+4} = {} \\<and>\n             c_guard src \\<and> c_guard dst \\<and>\n             no_wrap src 4 \\<and> no_wrap dst 4\\<rbrace>\n          memcpy_int' dst src\n        \\<lbrace>\\<lambda>_ s. deref s dst = x\\<rbrace>!\"\n\nlemma memcpy_int_wp'[unfolded memcpy_int_spec_def]: \"memcpy_int_spec dst src\"\n  unfolding memcpy_int_spec_def\n  apply (rule allI)\n  unfolding memcpy_int'_def\n  apply (wp memcpy_wp)\n  apply clarsimp\n  apply (rule_tac x=\"[deref s (byte_cast src),\n                      deref s (byte_cast src +\\<^sub>p 1),\n                      deref s (byte_cast src +\\<^sub>p 2),\n                      deref s (byte_cast src +\\<^sub>p 3)]\" in exI)\n  apply (clarsimp simp:bytes_at_def no_overlap_def UINT_MAX_def)\n  apply (rule conjI)\n   apply clarsimp\n   apply (case_tac \"i = 0\", clarsimp)\n   apply (case_tac \"i = 1\", clarsimp)\n   apply (case_tac \"i = 2\", clarsimp)\n   apply (case_tac \"i = 3\", clarsimp)\n   apply clarsimp\n  apply clarsimp\n  apply (subst h_val_not_id_update_bytes)\n    apply clarsimp+\n  apply (clarsimp simp:h_val_def)\n  apply (subgoal_tac \"heap_list (hrs_mem (t_hrs_' s)) 4 (ptr_val src) =\n                      deref s (byte_cast src) # (heap_list (hrs_mem (t_hrs_' s)) 3 (ptr_val src + 1))\")\n   prefer 2\n   apply (clarsimp simp:h_val_def)\n   apply (metis Suc_numeral from_bytes_eq heap_list_rec semiring_norm(2) semiring_norm(8))\n  apply (subgoal_tac \"heap_list (hrs_mem (t_hrs_' s)) 3 (ptr_val src + 1) =\n                      deref s (byte_cast src +\\<^sub>p 1) # (heap_list (hrs_mem (t_hrs_' s)) 2 (ptr_val src + 2))\")\n   prefer 2\n   apply (clarsimp simp:h_val_def ptr_add_def)\n   apply (cut_tac h=\"hrs_mem (t_hrs_' s)\" and p=\"ptr_val src + 1\" and n=2 in heap_list_rec)\n   apply clarsimp\n   apply (simp add: add.commute from_bytes_eq)\n  apply clarsimp\n  apply (subgoal_tac \"heap_list (hrs_mem (t_hrs_' s)) 2 (ptr_val src + 2) =\n                      deref s (byte_cast src +\\<^sub>p 2) # (heap_list (hrs_mem (t_hrs_' s)) 1 (ptr_val src + 3))\")\n   prefer 2\n   apply (cut_tac h=\"hrs_mem (t_hrs_' s)\" and p=\"ptr_val src + 2\" and n=3 in heap_list_rec)\n   apply (clarsimp simp:h_val_def ptr_add_def from_bytes_eq)\n   apply (metis (no_types, hide_lams) Suc_eq_plus1 heap_list_base heap_list_rec is_num_normalize(1)\n                monoid_add_class.add.left_neutral one_add_one one_plus_numeral semiring_norm(3))\n  apply (clarsimp simp:h_val_def ptr_add_def from_bytes_eq)\n  done\n\ntext {* memcpying a typed variable is equivalent to assignment. *}\nlemma memcpy_type_wp':\n  fixes dst :: \"'a::mem_type ptr\"\n    and src :: \"'a::mem_type ptr\"\n  shows \"\\<forall>s0 bs.\n   \\<lbrace>\\<lambda>s. s = s0 \\<and> c_guard dst \\<and> c_guard src \\<and> sz = of_nat (size_of TYPE('a)) \\<and>\n        no_overlap dst src (unat sz) \\<and> no_wrap dst (unat sz) \\<and> no_wrap src (unat sz) \\<and>\n        bytes_of s src bs\\<rbrace>\n     memcpy' (ptr_coerce dst) (ptr_coerce src) sz\n   \\<lbrace>\\<lambda>r s. r = ptr_coerce dst \\<and> bytes_of s dst bs \\<and> s = update_bytes s0 dst bs\\<rbrace>!\"\n  apply (rule allI)+\n  apply (wp memcpy_wp)\n  apply clarsimp\n  apply (rule_tac x=bs in exI)\n  apply clarsimp\n  apply (subst no_overlap_sym)\n  apply (clarsimp simp:bytes_of_def)\n  done\n\nlemmas memcpy_type_wp = memcpy_type_wp'[THEN validNF_make_schematic_post', simplified]\n\ntext {* Confirm that we can also prove memcpy_int using the previous generic lemma. *}\nlemma memcpy_int_wp''[unfolded memcpy_int_spec_def]: \"memcpy_int_spec dst src\"\n  unfolding memcpy_int_spec_def memcpy_int'_def\n  apply (rule allI)\n  apply (wp memcpy_type_wp)\n  (* Remainder mostly clagged from the original proof above. *)\n  apply clarsimp\n  apply (rule conjI, clarsimp simp:no_overlap_def, blast)\n  apply (rule_tac x=\"[deref s (byte_cast src),\n                      deref s (byte_cast src +\\<^sub>p 1),\n                      deref s (byte_cast src +\\<^sub>p 2),\n                      deref s (byte_cast src +\\<^sub>p 3)]\" in exI)\n  apply (rule conjI)\n   apply (clarsimp simp:bytes_of_def bytes_at_def UINT_MAX_def)\n   apply (case_tac \"i = 0\", clarsimp)\n   apply (case_tac \"i = 1\", clarsimp)\n   apply (case_tac \"i = 2\", clarsimp)\n   apply (case_tac \"i = 3\", clarsimp)\n   apply clarsimp\n  apply clarsimp\n  apply (subst h_val_not_id_update_bytes, clarsimp+)\n  apply (clarsimp simp:h_val_def)\n  apply (subgoal_tac \"heap_list (hrs_mem (t_hrs_' s)) 4 (ptr_val src) =\n                      deref s (byte_cast src) # (heap_list (hrs_mem (t_hrs_' s)) 3 (ptr_val src + 1))\")\n   prefer 2\n   apply (clarsimp simp:h_val_def from_bytes_eq)\n   apply (subst heap_list_rec[symmetric])\n   apply simp\n  apply (subgoal_tac \"heap_list (hrs_mem (t_hrs_' s)) 3 (ptr_val src + 1) =\n                      deref s (byte_cast src +\\<^sub>p 1) # (heap_list (hrs_mem (t_hrs_' s)) 2 (ptr_val src + 2))\")\n   prefer 2\n   apply (clarsimp simp:h_val_def ptr_add_def)\n   apply (cut_tac h=\"hrs_mem (t_hrs_' s)\" and p=\"ptr_val src + 1\" and n=2 in heap_list_rec)\n   apply (clarsimp simp: from_bytes_eq)\n   apply (metis add.commute)\n  apply clarsimp\n  apply (subgoal_tac \"heap_list (hrs_mem (t_hrs_' s)) 2 (ptr_val src + 2) =\n                      deref s (byte_cast src +\\<^sub>p 2) # (heap_list (hrs_mem (t_hrs_' s)) 1 (ptr_val src + 3))\")\n   prefer 2\n   apply (cut_tac h=\"hrs_mem (t_hrs_' s)\" and p=\"ptr_val src + 2\" and n=3 in heap_list_rec)\n   apply (clarsimp simp:h_val_def ptr_add_def from_bytes_eq)\n   apply (metis (no_types, hide_lams) Suc_eq_plus1 heap_list_base heap_list_rec is_num_normalize(1)\n                monoid_add_class.add.left_neutral one_add_one one_plus_numeral semiring_norm(3))\n  apply (clarsimp simp:h_val_def ptr_add_def from_bytes_eq)\n  done\n\nlemma bytes_of_imp_at[simp]: \"bytes_of s x bs \\<Longrightarrow> bytes_at s x bs\"\n  by (clarsimp simp:bytes_of_def bytes_at_def)\n\nlemma bytes_at_imp_of:\n  fixes x :: \"'a::mem_type ptr\"\n  shows \"\\<lbrakk>bytes_at s x bs; length bs = size_of TYPE('a)\\<rbrakk> \\<Longrightarrow> bytes_of s x bs\"\n  by (clarsimp simp:bytes_of_def bytes_at_def)\n\ntext {*\n  Memcpying from a source to a destination via an intermediary does what it should. This is close to\n  the desirable property we want for CAmkES systems; i.e. that copying into your IPC buffer on one\n  side and then out on the other gives you back what you put in. Note that the type of the\n  intermediate pointer is irrelevant and we don't need to assume that the source and final\n  destination do not overlap.\n*}\nlemma memcpy_seq:\n  fixes x :: \"'a::mem_type ptr\"\n    and y :: \"'b::mem_type ptr\"\n    and z :: \"'a::mem_type ptr\"\n  shows \"\\<forall>s0 bs.\n   \\<lbrace>\\<lambda>s. s = s0 \\<and> sz = of_nat (size_of TYPE('a)) \\<and>\n        c_guard x \\<and> c_guard y \\<and> c_guard z \\<and>\n        no_wrap x (unat sz) \\<and> no_wrap y (unat sz) \\<and> no_wrap z (unat sz) \\<and>\n        no_overlap x y (unat sz) \\<and> no_overlap y z (unat sz) \\<and>\n        bytes_of s x bs\\<rbrace>\n    do memcpy' (ptr_coerce y) (ptr_coerce x) sz;\n       memcpy' (ptr_coerce z) (ptr_coerce y) sz\n    od\n   \\<lbrace>\\<lambda>r s. r = ptr_coerce z \\<and> bytes_of s z bs\\<rbrace>!\"\n  apply (rule allI)+\n  apply (wp memcpy_wp)\n  apply clarsimp\n  apply (rule_tac x=bs in exI)\n  apply clarsimp\n  apply (rule conjI, clarsimp simp:bytes_of_def)\n  apply clarsimp\n  apply (rule_tac x=bs in exI)\n  apply (rule conjI, clarsimp simp:bytes_of_def)\n  apply clarsimp\n  apply (rule bytes_at_imp_of)\n   apply (clarsimp simp:bytes_of_def)+\n  done\n\nlemma update_ti_eq:\n  fixes x :: \"'a::mem_type\"\n    and y :: 'a\n  shows \"\\<lbrakk>length bs = size_of TYPE('a); bs = bs'\\<rbrakk>\n          \\<Longrightarrow> update_ti_t (typ_info_t TYPE('a)) bs x = update_ti_t (typ_info_t TYPE('a)) bs' y\"\n  by (clarsimp simp:upd)\n\nlemma from_bytes_cong: \"x = y \\<Longrightarrow> from_bytes x = from_bytes y\"\n  by simp\n\ndeclare from_bytes_eq [simp]\n\ntext {*\n  If you dereference a pointer, the value you get is the same as the underlying bytes backing that\n  memory.\n*}\nlemma val_eq_bytes:\n  fixes x :: \"'a::mem_type ptr\"\n  shows \"deref s x = from_bytes (map (\\<lambda>off. deref s (byte_cast x +\\<^sub>p of_nat off)) [0..<size_of TYPE('a)])\"\n  apply (clarsimp simp:h_val_def ptr_add_def)\n  apply (rule from_bytes_cong)\n  apply (rule nth_equalityI)\n   apply clarsimp+\n  apply (subst heap_list_nth)\n   apply clarsimp+\n  done\n\nlemma extract_list_elem: \"i < n \\<Longrightarrow> f i = (map f [0..<n]) ! i\"\n  apply (induct i)\n   apply clarsimp+\n  done\n\nlemma update_deref:\n  fixes x :: \"'a::mem_type ptr\"\n  shows \"size_of TYPE('a) = length bs \\<Longrightarrow> deref (update_bytes s x bs) x = from_bytes bs\"\n  apply (clarsimp simp:update_bytes_def)\n  apply (subst hrs_mem_update)\n  apply (clarsimp simp:h_val_def)\n  apply (subst heap_list_update)\n   apply (metis less_imp_le max_size)\n  apply clarsimp\n  done\n\ntext {*\n  The memcpy_int proof can now be completed more elegantly. Note that the body of this proof is more\n  generic than the previous attempts and doesn't involve manually reasoning about each byte.\n*}\nlemma memcpy_int_wp'''[unfolded memcpy_int_spec_def]: \"memcpy_int_spec dst src\"\n  unfolding memcpy_int_spec_def memcpy_int'_def\n  apply (rule allI)\n  apply (wp memcpy_type_wp)\n  apply clarsimp\n  apply (rule conjI, clarsimp simp:no_overlap_def, blast)\n  apply (rule_tac x=\"map (\\<lambda>i. deref s (byte_cast src +\\<^sub>p of_nat i)) [0..<size_of TYPE(32sword)]\" in exI)\n  apply (rule conjI)\n   apply (clarsimp simp:bytes_of_def bytes_at_def UINT_MAX_def)+\n  apply (subst update_deref)\n   apply clarsimp\n  apply (cut_tac s=s and x=src in val_eq_bytes)\n  apply clarsimp\n  done\n\nlemma bytes_at_heap_list:\n  fixes x :: \"'a::mem_type ptr\"\n  shows \"\\<lbrakk>n \\<le> ADDR_MAX; no_wrap x n\\<rbrakk>\n          \\<Longrightarrow> bytes_at s x (heap_list (hrs_mem (t_hrs_' s)) n (ptr_val x))\"\n  apply (clarsimp simp:bytes_at_def ptr_add_def h_val_def)\n  apply (subst heap_list_nth)\n   apply unat_arith\n  apply clarsimp\n  done\n\ntext {*\n  A collection of useful type-generic implications for moving from the abstract heap to the concrete\n  heap.\n*}\ndefinition\n  is_valid_imp_c_guard :: \"(lifted_globals \\<Rightarrow> 'b::mem_type ptr \\<Rightarrow> bool) \\<Rightarrow> bool\"\nwhere\n  \"is_valid_imp_c_guard is_valid \\<equiv> \\<forall>s p. is_valid (lift_global_heap s) p \\<longrightarrow> c_guard p\"\ndefinition\n  is_valid_imp_no_null :: \"(lifted_globals \\<Rightarrow> 'b::mem_type ptr \\<Rightarrow> bool) \\<Rightarrow> bool\"\nwhere\n  \"is_valid_imp_no_null is_valid \\<equiv>\n     \\<forall>s p. is_valid (lift_global_heap s) p \\<longrightarrow> 0 \\<notin> {ptr_val p..of_nat (size_of TYPE('b))}\"\ndefinition\n  is_valid_imp_no_wrap :: \"(lifted_globals \\<Rightarrow> 'b::mem_type ptr \\<Rightarrow> bool) \\<Rightarrow> bool\"\nwhere\n  \"is_valid_imp_no_wrap is_valid \\<equiv>\n     \\<forall>s p. is_valid (lift_global_heap s) p \\<longrightarrow> no_wrap p (size_of TYPE('b))\"\ndefinition\n  is_valid_imp_no_overlap :: \"(lifted_globals \\<Rightarrow> 'b::mem_type ptr \\<Rightarrow> bool) \\<Rightarrow> bool\"\nwhere\n  \"is_valid_imp_no_overlap is_valid \\<equiv>\n     \\<forall>s p q. is_valid (lift_global_heap s) p \\<and> is_valid (lift_global_heap s) q \\<and> p \\<noteq> q\n               \\<longrightarrow> no_overlap p q (size_of TYPE('b))\"\ndefinition\n  is_valid_imp_heap_ptr_valid :: \"(lifted_globals \\<Rightarrow> 'b::mem_type ptr \\<Rightarrow> bool) \\<Rightarrow> bool\"\nwhere\n  \"is_valid_imp_heap_ptr_valid is_valid \\<equiv>\n     \\<forall>s p. is_valid (lift_global_heap s) p \\<longrightarrow> heap_ptr_valid (hrs_htd (t_hrs_' s)) p\"\n\ntext {* We can easily discharge these for a given type. *}\nlemma is_valid_w32_imp_c_guard[unfolded is_valid_imp_c_guard_def, simplified]:\n    \"is_valid_imp_c_guard is_valid_w32\"\n  unfolding is_valid_imp_c_guard_def\n  apply clarsimp\n  apply (subst (asm) lifted_globals_ext_simps)\n  apply clarsimp\n  apply (rule simple_lift_c_guard, force)\n  done\n\nlemma is_valid_w32_imp_no_null[unfolded is_valid_imp_no_null_def, simplified]:\n    \"is_valid_imp_no_null is_valid_w32\"\n  unfolding is_valid_imp_no_null_def\n  apply clarsimp\n  apply (subst (asm) lifted_globals_ext_simps)\n  apply clarsimp\n  apply (drule simple_lift_c_guard)\n  apply (clarsimp simp:c_guard_def c_null_guard_def intvl_def)\n  by force\n\nlemma is_valid_w32_imp_no_wrap[unfolded is_valid_imp_no_wrap_def, simplified]:\n    \"is_valid_imp_no_wrap is_valid_w32\"\n  unfolding is_valid_imp_no_wrap_def no_wrap_def\n  apply clarsimp\n  apply (subst (asm) lifted_globals_ext_simps)\n  apply clarsimp\n  apply (drule simple_lift_c_guard)\n  apply (clarsimp simp:c_guard_def c_null_guard_def intvl_def)\n  done\n\nlemma is_valid_w32_imp_no_overlap[unfolded is_valid_imp_no_overlap_def, simplified]:\n    \"is_valid_imp_no_overlap is_valid_w32\"\n  unfolding is_valid_imp_no_overlap_def no_wrap_def\n  apply clarsimp\n  apply (subst (asm) lifted_globals_ext_simps)+\n  apply clarsimp\n  apply (drule simple_lift_heap_ptr_valid)+\n  apply (clarsimp simp:no_overlap_def)\n  apply (cut_tac p=p and q=q and d=\"hrs_htd (t_hrs_' s)\" in heap_ptr_valid_neq_disjoint)\n     apply clarsimp+\n  done\n\nlemma is_valid_w32_imp_heap_ptr_valid[unfolded is_valid_imp_heap_ptr_valid_def, simplified]:\n    \"is_valid_imp_heap_ptr_valid is_valid_w32\"\n  unfolding is_valid_imp_heap_ptr_valid_def\n  apply clarsimp\n  apply (subst (asm) lifted_globals_ext_simps)\n  apply clarsimp\n  by (rule simple_lift_heap_ptr_valid, force)\n\ntext {*\n  With that support in place, we can now prove a heap-abstracted call to memcpy of a type in a\n  reasonably generic way. Note that we leverage the relationship between\n  is_valid_*/lift_global_heap/simple_lift to transfer assumptions across the boundary between the\n  abstract and concrete heaps.\n*}\nlemma\n  fixes dst :: \"32word ptr\"\n    and src :: \"32word ptr\"\n  shows \"\\<forall>s0 x.\n   \\<lbrace>\\<lambda>s. s = s0 \\<and> is_valid_w32 s dst \\<and> is_valid_w32 s src \\<and> sz = of_nat (size_of TYPE(32word)) \\<and>\n        heap_w32 s src = x \\<and> dst \\<noteq> src\\<rbrace>\n     exec_concrete lift_global_heap (memcpy' (ptr_coerce dst) (ptr_coerce src) sz)\n   \\<lbrace>\\<lambda>r s. r = ptr_coerce dst \\<and> heap_w32 s dst = x\\<rbrace>!\"\n  apply (rule allI)+\n  apply (wp memcpy_wp)\n  apply (clarsimp simp:is_valid_w32_imp_c_guard\n                       is_valid_w32_imp_no_wrap\n                       is_valid_w32_imp_no_overlap)\n  apply (rule_tac x=\"map (\\<lambda>i. deref s (byte_cast src +\\<^sub>p of_nat i)) [0..<size_of TYPE(32word)]\" in exI)\n  apply clarsimp\n  apply (rule conjI)\n   apply (clarsimp simp:bytes_at_def UINT_MAX_def)\n  apply clarsimp\n  apply (subst lifted_globals_ext_simps(3))+\n  apply (clarsimp simp:simple_lift_def is_valid_w32_imp_heap_ptr_valid)\n  apply (rule conjI)\n   apply clarsimp\n   apply (subst update_deref)\n    apply clarsimp+\n   apply (cut_tac s=s and x=src in val_eq_bytes)\n   apply clarsimp\n  apply (clarsimp simp:update_bytes_def is_valid_w32_imp_heap_ptr_valid)\n  done\n\ntext {*\n  Let's do the same instantiation for a structure. Note that the proof text for the following lemmas\n  is identical to the word 32 instantiation above. These could be straightforwardly abstracted into\n  a locale which could be automatically interpreted with the use of generated proofs.\n*}\nlemma is_valid_my_structure_imp_c_guard[unfolded is_valid_imp_c_guard_def, simplified]:\n    \"is_valid_imp_c_guard is_valid_my_structure_C\"\n  unfolding is_valid_imp_c_guard_def\n  apply clarsimp\n  apply (subst (asm) lifted_globals_ext_simps)\n  apply clarsimp\n  apply (rule simple_lift_c_guard, force)\n  done\n\nlemma is_valid_my_structure_imp_no_null[unfolded is_valid_imp_no_null_def, simplified]:\n    \"is_valid_imp_no_null is_valid_my_structure_C\"\n  unfolding is_valid_imp_no_null_def\n  apply clarsimp\n  apply (subst (asm) lifted_globals_ext_simps)\n  apply clarsimp\n  apply (drule simple_lift_c_guard)\n  apply (clarsimp simp:c_guard_def c_null_guard_def intvl_def)\n  by force\n\nlemma is_valid_my_structure_imp_no_wrap[unfolded is_valid_imp_no_wrap_def, simplified]:\n    \"is_valid_imp_no_wrap is_valid_my_structure_C\"\n  unfolding is_valid_imp_no_wrap_def no_wrap_def\n  apply clarsimp\n  apply (subst (asm) lifted_globals_ext_simps)\n  apply clarsimp\n  apply (drule simple_lift_c_guard)\n  apply (clarsimp simp:c_guard_def c_null_guard_def intvl_def)\n  done\n\nlemma is_valid_my_structure_imp_no_overlap[unfolded is_valid_imp_no_overlap_def, simplified]:\n    \"is_valid_imp_no_overlap is_valid_my_structure_C\"\n  unfolding is_valid_imp_no_overlap_def no_wrap_def\n  apply clarsimp\n  apply (subst (asm) lifted_globals_ext_simps)+\n  apply clarsimp\n  apply (drule simple_lift_heap_ptr_valid)+\n  apply (clarsimp simp:no_overlap_def)\n  apply (cut_tac p=p and q=q and d=\"hrs_htd (t_hrs_' s)\" in heap_ptr_valid_neq_disjoint)\n     apply clarsimp+\n  done\n\nlemma is_valid_my_structure_imp_heap_ptr_valid[unfolded is_valid_imp_heap_ptr_valid_def, simplified]:\n    \"is_valid_imp_heap_ptr_valid is_valid_my_structure_C\"\n  unfolding is_valid_imp_heap_ptr_valid_def\n  apply clarsimp\n  apply (subst (asm) lifted_globals_ext_simps)\n  apply clarsimp\n  by (rule simple_lift_heap_ptr_valid, force)\n\ntext {*\n  Again, we can now trivially transfer Hoare triple properties.\n*}\nlemma\n  fixes dst :: \"my_structure_C ptr\"\n    and src :: \"my_structure_C ptr\"\n  shows \"\\<forall>s0 x.\n   \\<lbrace>\\<lambda>s. s = s0 \\<and> is_valid_my_structure_C s dst \\<and> is_valid_my_structure_C s src \\<and>\n        heap_my_structure_C s src = x \\<and> dst \\<noteq> src\\<rbrace>\n     memcpy_struct' dst src\n   \\<lbrace>\\<lambda>r s. r = dst \\<and> heap_my_structure_C s dst = x\\<rbrace>!\"\n  apply (rule allI)+\n  unfolding memcpy_struct'_def\n  apply (wp memcpy_wp)\n  apply (clarsimp simp:is_valid_my_structure_imp_c_guard)\n  apply (rule_tac x=\"map (\\<lambda>i. deref s (byte_cast src +\\<^sub>p of_nat i)) [0..<size_of TYPE(my_structure_C)]\" in exI)\n  apply (clarsimp simp:is_valid_my_structure_imp_no_wrap is_valid_my_structure_imp_no_overlap)\n  apply (rule conjI)\n   apply (clarsimp simp:bytes_at_def UINT_MAX_def)\n  apply clarsimp\n  apply (subst lifted_globals_ext_simps)+\n  apply (clarsimp simp:simple_lift_def is_valid_my_structure_imp_heap_ptr_valid)\n  apply (rule conjI)\n   apply clarsimp\n   apply (subst update_deref)\n    apply clarsimp\n   apply (cut_tac s=s and x=src in val_eq_bytes)\n   apply clarsimp\n  apply (clarsimp simp:update_bytes_def is_valid_my_structure_imp_heap_ptr_valid)\n  done\n\nend\n\nend\n", "meta": {"author": "z5146542", "repo": "TOR", "sha": "9a82d491288a6d013e0764f68e602a63e48f92cf", "save_path": "github-repos/isabelle/z5146542-TOR", "path": "github-repos/isabelle/z5146542-TOR/TOR-9a82d491288a6d013e0764f68e602a63e48f92cf/checker-verification/autocorres-1.4/autocorres/tests/examples/Memcpy.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6959583250334527, "lm_q2_score": 0.4301473485858429, "lm_q1q2_score": 0.2993646282393839}}
{"text": "(*  Title:      HOL/Auth/n_mutualExSimp_lemma_inv__4_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mutualExSimp Protocol Case Study*} \n\ntheory n_mutualExSimp_lemma_inv__4_on_rules imports n_mutualExSimp_lemma_on_inv__4\nbegin\nsection{*All lemmas on causal relation between inv__4*}\nlemma lemma_inv__4_on_rules:\n  assumes b1: \"r \\<in> rules N\" and b2: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__4  p__Inv4)\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have c1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n  apply (cut_tac b1, auto) done\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_CritVsinv__4) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_ExitVsinv__4) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_IdleVsinv__4) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "lyj238Gmail", "repo": "newParaVerifier", "sha": "5c2d49bf8e6c46c60efa53c98b0ba5c577d59618", "save_path": "github-repos/isabelle/lyj238Gmail-newParaVerifier", "path": "github-repos/isabelle/lyj238Gmail-newParaVerifier/newParaVerifier-5c2d49bf8e6c46c60efa53c98b0ba5c577d59618/examples/n_mutualExSimp/n_mutualExSimp_lemma_inv__4_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6959583124210895, "lm_q2_score": 0.43014734858584286, "lm_q1q2_score": 0.29936462281420934}}
{"text": "theory Lifter_idem\n imports  \"../Mergeable/Mergeable_Instances\" \"../Mergeable/Mergeable_Oalist\" \"../Mergeable/Mergeable_Roalist\" \"../Mergeable/Mono\"\nbegin\n\n(* When we lift syntaxes we reverse the function arrow *)\ntype_synonym ('a, 'b) syn_lifting = \"('b \\<Rightarrow> 'a)\"\n\n(*\ndatatype ('syn, 'a, 'b) lifting =\n  LMake  (LUpd : \"('syn \\<Rightarrow> 'a \\<Rightarrow> 'b \\<Rightarrow> 'b)\")\n         (LOut : \"('syn \\<Rightarrow> 'b \\<Rightarrow> 'a)\")\n         (LBase : \"('syn \\<Rightarrow> 'b)\")\n*)\n\n(*\n\"mappable\" typeclass?\n*)\n\n(* need a generic way to talk about things over which LMap makes sense.\n\n*)\n\ndatatype ('syn, 'a, 'b, 'f) lifting =\n  LMake  (LUpd_Idem : \"('syn \\<Rightarrow> 'a \\<Rightarrow> 'b \\<Rightarrow> 'b)\")\n         (LPost : \"('syn \\<Rightarrow> 'b \\<Rightarrow> 'b)\")\n         (LOut : \"('syn \\<Rightarrow> 'b \\<Rightarrow> 'a)\")\n         (LBase : \"('syn \\<Rightarrow> 'b)\")\n         (LFD : \"'f \\<Rightarrow> 'syn \\<Rightarrow> 'a \\<Rightarrow> 'a\")\n\ntype_synonym ('syn, 'a, 'b) lifting' =\n  \"('syn, 'a, 'b, 'syn \\<Rightarrow> 'a \\<Rightarrow> 'a) lifting\"\n\ndefinition LUpd ::\n  \"('syn, 'a, 'b, 'f) lifting \\<Rightarrow> 'syn \\<Rightarrow> 'a \\<Rightarrow> 'b \\<Rightarrow> 'b\" where\n\"LUpd l s a b =\n  LPost l s (LUpd_Idem l s a b)\"\n\n\ndefinition LMap_Idem ::\n  \"('x, 'a, 'b, 'f) lifting \\<Rightarrow> 'f \\<Rightarrow> ('x \\<Rightarrow> 'b \\<Rightarrow> 'b)\" where\n\"LMap_Idem l f s b =\n  LUpd_Idem l s (LFD l f s (LOut l s b)) b\"\n\ndefinition LMap ::\n  \"('x, 'a, 'b, 'f) lifting \\<Rightarrow> 'f \\<Rightarrow> ('x \\<Rightarrow> 'b \\<Rightarrow> 'b)\" where\n\"LMap l f s b =\n  LUpd l s (LFD l f s (LOut l s b)) b\"\n\n\ndefinition LNew :: \"('syn, 'a, 'b, 'f) lifting \\<Rightarrow> 'syn \\<Rightarrow> 'a \\<Rightarrow> 'b\"  where\n\"LNew l s a = LUpd l s a (LBase l s)\"\n\n(* TODO: make sure this is a good idea. *)\ndeclare LNew_def [simp]\ndeclare LMap_def [simp]\ndeclare LMap_Idem_def [simp]\ndeclare LUpd_def [simp]\n\ntype_synonym ('syn, 'b) valid_set =\n\"'syn \\<Rightarrow> 'b set\"\n\n(* liftings can have several kinds of validity properties, only some of\n   which depend on others.\n*)\n\n(* TODO: for inference purposes we are probably going to\n * still have to use something like our current formulation. *)\n\nclass Okay =\n  fixes ok_S :: \"('a) set\"\n\n\ninstantiation md_triv :: (_) Okay\nbegin\ndefinition triv_ok_S : \"(ok_S :: 'a md_triv set) = UNIV\"\ninstance proof\nqed\nend\n\ninstantiation md_prio :: (Okay) Okay\nbegin\ndefinition prio_ok_S : \"(ok_S :: 'a md_prio set) = ({x . \\<exists> px vx . x = mdp vx px \\<and> px \\<in> ok_S})\"\ninstance proof qed\nend\n\ninstantiation option :: (Okay) Okay\nbegin\ndefinition option_ok_S : \"(ok_S :: 'a option set) = (Some ` ok_S)\"\ninstance proof qed\nend\n\ninstantiation prod :: (Okay, Okay) Okay\nbegin\ndefinition prod_ok_S : \"(ok_S :: ('a * 'b) set) = { x :: 'a * 'b . \\<exists> a' b' . x = (a', b') \\<and> a' \\<in> ok_S \\<and> b' \\<in> ok_S}\"\ninstance proof qed\nend\n\ninstantiation oalist :: (linorder, Okay) Okay\nbegin\n\ndefinition oalist_ok_S :\n  \"(ok_S :: ('a, 'b) oalist set) = { x  :: ('a, 'b) oalist . oalist_all_val (\\<lambda> y . y \\<in> ok_S) x }\"\ninstance proof qed\nend\n\ninstantiation unit :: Okay\nbegin\ndefinition unit_ok_S :\n  \"(ok_S :: unit set) = UNIV\"\ninstance proof qed\nend\n\nlocale lifting_valid_weak =\n  fixes l :: \"('syn, 'a, 'b :: Pord_Weak, 'f) lifting\"\n  fixes S :: \"('syn, 'b) valid_set\"\n  assumes put_get : \"\\<And> s a b . LOut l s (LUpd_Idem l s a b) = a\"\n  assumes post_nop : \"\\<And> s b . LOut l s (LPost l s b) = LOut l s b\"\n  assumes put_S : \"\\<And> s a b . LUpd_Idem l s a b \\<in> S s\"\n  assumes post_S : \"\\<And> s b . b \\<in> S s \\<Longrightarrow> LPost l s b \\<in> S s\"\n  assumes post_geq : \"\\<And> s b . b <[ LPost l s b\"\n  assumes get_put_weak : \"\\<And> s b . b \\<in> S s \\<Longrightarrow> b = LUpd_Idem l s (LOut l s b) b\"\n  \n\nlocale lifting_putonly =\n  fixes l :: \"('syn, 'a, 'b :: Pord_Weak, 'f) lifting\"\n  fixes S :: \"('syn, 'b) valid_set\"\n  assumes put_S : \"\\<And> s a b . LUpd l s a b \\<in> S s\"\n\n(* TODO reexamine this *)\nlocale lifting_presonly =\n  fixes l :: \"('syn, 'a, 'b :: Pord_Weak, 'f) lifting\"\n  fixes S :: \"('syn, 'b) valid_set\"\n  assumes pres :\n    \"\\<And> v V supr f s . \n         v \\<in> V \\<Longrightarrow>\n         V \\<subseteq> S s \\<Longrightarrow>\n         is_sup V supr \\<Longrightarrow> supr \\<in> S s \\<Longrightarrow> is_sup (LMap_Idem l f s ` V) (LMap_Idem l f s supr)\"\n  assumes pres_post :\n    \"\\<And> v V supr s .\n      v \\<in> V \\<Longrightarrow>\n      V \\<subseteq> S s \\<Longrightarrow>\n      is_sup V supr \\<Longrightarrow>\n      supr \\<in> S s \\<Longrightarrow>\n      is_sup (LPost l s ` V) (LPost l s supr)\"\n    \n\n(* reduced version of lifting-valid, for use with\n * improper merges (when using merge_l as a tool for combining\n * semantics) *)\nlocale lifting_valid_presonly =\n  lifting_putonly + lifting_presonly\n\nlocale lifting_valid = lifting_valid_weak +\n  assumes put_put : \"\\<And> s a1 a2 b . LUpd_Idem l s a1 (LUpd_Idem l s a2 b) = LUpd_Idem l s a1 b\"\n\nlocale lifting_valid_weak_base = lifting_valid_weak +\n  assumes base : \"\\<And> s . LBase l s = \\<bottom>\"\n\nlocale lifting_valid_base = lifting_valid + lifting_valid_weak_base\n\nlocale lifting_valid_weak_ok = lifting_valid_weak +\n  assumes ok_S_valid : \"\\<And> s . ok_S \\<subseteq> S s\"\n  assumes ok_S_put : \"\\<And> s a b . b \\<in> ok_S \\<Longrightarrow> LUpd_Idem l s a b \\<in> ok_S\"\n  assumes ok_S_post : \"\\<And> s b . b \\<in> ok_S \\<Longrightarrow> LPost l s b \\<in> ok_S\"\n\nlocale lifting_valid_ok = lifting_valid + lifting_valid_weak_ok\n\nlocale lifting_valid_weak_base_ok = lifting_valid_weak_ok + lifting_valid_weak_base\n\nlocale lifting_valid_base_ok = lifting_valid_ok + lifting_valid_base\n\nlocale lifting_valid_weak_pres = lifting_valid_weak +\n  lifting_presonly\n(*\nsublocale lifting_valid_weak_pres \\<subseteq> lifting_valid_presonly\nproof\n  show \"\\<And>s a b. LUpd l s a b \\<in> S s\"\n    using put_S by auto\nnext\n  show \"\\<And>v V supr f s.\n       v \\<in> V \\<Longrightarrow>\n       V \\<subseteq> S s \\<Longrightarrow>\n       is_sup V supr \\<Longrightarrow>\n       supr \\<in> S s \\<Longrightarrow>\n       is_sup (LMap l f s ` V)\n        (LMap l f s supr)\"\n    using pres \n    by auto\nqed\n*)\n\nlocale lifting_valid_pres = lifting_valid + lifting_valid_weak_pres\n\nlocale lifting_valid_weak_base_pres = lifting_valid_weak_pres + lifting_valid_weak_base +\n  assumes bot_bad : \"\\<And> s . \\<bottom> \\<notin> S s\"\n\nlocale lifting_valid_base_pres = lifting_valid_pres + lifting_valid_weak_base_pres\n\nlocale lifting_valid_weak_ok_pres = lifting_valid_weak_pres + lifting_valid_weak_ok\n\nlocale lifting_valid_ok_pres = lifting_valid_pres + lifting_valid_ok\n\nlocale lifting_valid_weak_base_ok_pres =\n  lifting_valid_weak_base_pres + lifting_valid_weak_base_ok\n\n(* generally we are assuming we won't be using ok and pres separately.\n * we could if we wanted to though. *)\nlocale lifting_valid_base_ok_pres =\n  lifting_valid_base_pres + lifting_valid_base_ok\n\n(* orthogonality, used to define merge correctness *)\n(*\nthese were originally pord_weak, but this was\n(i think) insufficient to prove fst_l_ortho;\nthe strengthening to pord shouldn't be an issue though.\n*)\nlocale l_ortho' =\n  fixes l1 :: \"('a, 'b1, 'c :: Pord, 'f1) lifting\"\n  fixes S1 :: \"'a \\<Rightarrow> 'c set\"\n  fixes l2 :: \"('a, 'b2, 'c :: Pord, 'f2) lifting\"\n  fixes S2 :: \"'a \\<Rightarrow> 'c set\"\n\n(* need set membership constraints. *)\nlocale l_ortho =\n  l_ortho' +\n\n  assumes eq_base : \"\\<And> s . LBase l1 s = LBase l2 s\"\n  assumes compat_idem : \"\\<And> s a1 a2 b1 b2 supr .  \n    is_sup {b1, b2} supr \\<Longrightarrow>\n    has_sup {LUpd_Idem l1 s a1 b1, LUpd_Idem l2 s a2 b2}\"\n\n  assumes compat_post : \"\\<And> b1 b2 s supr . is_sup {b1, b2} supr \\<Longrightarrow> has_sup {LPost l1 s b1, LPost l2 s b2}\"\n\n  assumes compat_idem_S : \"\\<And> s a1 a2 b1 b2 supr0 supr . \n      is_sup {b1, b2} supr0 \\<Longrightarrow>\n      is_sup {LUpd_Idem l1 s a1 b1, LUpd_Idem l2 s a2 b2} supr \\<Longrightarrow>\n                        supr \\<in> (S1 s \\<inter> S2 s)\"\n\n  assumes compat_post_S : \"\\<And> s b1 b2 supr0 supr .\n        is_sup {b1, b2} supr0 \\<Longrightarrow>\n        supr0 \\<in> S1 s \\<Longrightarrow>\n        supr0 \\<in> S2 s \\<Longrightarrow>\n        is_sup {LPost l1 s b1, LPost l2 s b2} supr \\<Longrightarrow>\n        supr \\<in> (S1 s \\<inter> S2 s)\"\n\n  assumes compat_idem_get1 : \n      \"\\<And> s a1 a2 b1 b2 supr0 supr .\n         is_sup {b1, b2} supr0 \\<Longrightarrow>\n         is_sup {LUpd_Idem l1 s a1 b1, LUpd_Idem l2 s a2 b2} supr \\<Longrightarrow>\n                        LOut l1 s supr = a1\"\n  \n    assumes compat_idem_get2 : \"\\<And> s a1 a2 b1 b2 supr0 supr . \n         is_sup {b1, b2} supr0 \\<Longrightarrow>\n          is_sup {LUpd_Idem l1 s a1 b1, LUpd_Idem l2 s a2 b2} supr \\<Longrightarrow>\n                        LOut l2 s supr = a2\"\n\n  assumes compat_post_get1 : \"\\<And> s b1 b2 supr0 supr . \n     is_sup {b1, b2} supr0 \\<Longrightarrow>\n     is_sup {LPost l1 s b1, LPost l2 s b2} supr \\<Longrightarrow>\n      LOut l1 s supr = LOut l1 s supr0\"\n  \n  assumes compat_post_get2 : \"\\<And> s b1 b2 supr0 supr . \n    is_sup {b1, b2} supr0 \\<Longrightarrow>\n    is_sup {LPost l1 s b1, LPost l2 s b2} supr \\<Longrightarrow>\n        LOut l2 s supr = LOut l2 s supr0\"\n\n  assumes put1_S2 : \"\\<And> s a b . b \\<in> S2 s \\<Longrightarrow> LUpd_Idem l1 s a b \\<in> S2 s\"\n  assumes put2_S1 : \"\\<And> s a b . b \\<in> S1 s \\<Longrightarrow> LUpd_Idem l2 s a b \\<in> S1 s\"\n\n(* TODO: this feels weird*)\nlocale l_ortho_strong = l_ortho +\n  assumes compat_put_put :\n    \"\\<And> s x1 x2 y1 y2 b1 b2 supr0 supr1 supr2 supr3.\n      is_sup {b1, b2} supr0 \\<Longrightarrow>\n      is_sup {LUpd_Idem l1 s y1 b1, LUpd_Idem l2 s y2 b2} supr1 \\<Longrightarrow>\n      is_sup {LUpd_Idem l1 s x1 supr1, LUpd_Idem l2 s x2 supr1} supr2 \\<Longrightarrow>\n      is_sup {LUpd_Idem l1 s x1 b1, LUpd_Idem l2 s x2 b2} supr3 \\<Longrightarrow>\n      supr2 = supr3\"\n\nlemma (in l_ortho) compat :\n  fixes s a1 a2 b1 b2 supr\n  assumes Supr : \"is_sup {b1, b2} supr\"\n  shows \"has_sup {LUpd l1 s a1 b1, LUpd l2 s a2 b2}\"\nproof-\n\n  obtain supr' where Supr' : \"is_sup {LUpd_Idem l1 s a1 b1, LUpd_Idem l2 s a2 b2} supr'\"\n    using compat_idem[OF Supr]\n    by(fastforce simp add: has_sup_def)\n\n  show \"has_sup {LUpd l1 s a1 b1, LUpd l2 s a2 b2}\"\n    using compat_post[OF Supr']\n    unfolding LUpd_def\n    by(auto)\nqed\n\nlemma (in l_ortho) compat_get1 :\n  fixes s a1 a2 b1 b2 supr0 supr\n  assumes Supr0 : \"is_sup {b1, b2} supr0\"\n  assumes Supr : \"is_sup {LUpd l1 s a1 b1, LUpd l2 s a2 b2} supr\"\n  shows \"LOut l1 s supr = a1\"\nproof-\n\n  obtain supr' where Supr' : \"is_sup {LUpd_Idem l1 s a1 b1, LUpd_Idem l2 s a2 b2} supr'\"\n    using compat_idem[OF Supr0]\n    by(fastforce simp add: has_sup_def)\n\n  have \"LOut l1 s supr' = a1\"\n    using compat_idem_get1[OF Supr0 Supr']\n    by auto\n\n  then show \"LOut l1 s supr = a1\"\n    using compat_post_get1[OF Supr'] Supr\n    unfolding LUpd_def\n    by(auto simp add: LUpd_def)\nqed\n\nlemma (in l_ortho) compat_get2 :\n  fixes s a1 a2 b1 b2 supr0 supr\n  assumes Supr0 : \"is_sup {b1, b2} supr0\"\n  assumes Supr : \"is_sup {LUpd l1 s a1 b1, LUpd l2 s a2 b2} supr\"\n  shows \"LOut l2 s supr = a2\"\nproof-\n\n  obtain supr' where Supr' : \"is_sup {LUpd_Idem l1 s a1 b1, LUpd_Idem l2 s a2 b2} supr'\"\n    using compat_idem[OF Supr0]\n    by(fastforce simp add: has_sup_def)\n\n  have \"LOut l2 s supr' = a2\"\n    using compat_idem_get2[OF Supr0 Supr']\n    by auto\n\n  then show \"LOut l2 s supr = a2\"\n    using compat_post_get2[OF Supr'] Supr\n    unfolding LUpd_def\n    by(auto simp add: LUpd_def)\nqed\n\nlemma (in l_ortho) compat_S :\n  fixes s a1 a2 b1 b2 supr0 supr\n  assumes Supr0 : \"is_sup {b1, b2} supr0\"\n  assumes Supr : \"is_sup {LUpd l1 s a1 b1, LUpd l2 s a2 b2} supr\"\n  shows \"supr \\<in> S1 s \\<inter> S2 s\"\nproof-\n   obtain supr' where Supr' : \"is_sup {LUpd_Idem l1 s a1 b1, LUpd_Idem l2 s a2 b2} supr'\"\n     using compat_idem[OF Supr0]\n     by(fastforce simp add: has_sup_def)\n\n  have Supr'_in : \"supr' \\<in> S1 s\" \"supr' \\<in> S2 s\"\n    using compat_idem_S[OF Supr0 Supr']\n    by auto\n\n  obtain supr'2 where Supr'2 : \"is_sup {LPost l1 s (LUpd_Idem l1 s a1 b1), LPost l2 s (LUpd_Idem l2 s a2 b2)} supr'2\"\n    using compat_post[OF Supr']\n    by(fastforce simp add: has_sup_def)\n\n  have Supr'2_supr : \"supr'2 = supr\"\n    using is_sup_unique[OF Supr[unfolded LUpd_def] Supr'2]\n    by simp\n\n  show \"supr \\<in> S1 s \\<inter> S2 s\"\n    using compat_post_S[OF Supr' Supr'_in(1) Supr'_in(2) Supr'2]\n    unfolding Supr'2_supr\n    by auto\nqed\n\nlocale l_ortho_base' =\n  fixes l1 :: \"('a, 'b1, 'c :: Pord_Weakb, 'f1) lifting\"\n  fixes l2 :: \"('a, 'b2, 'c, 'f2) lifting\"\n\nlocale l_ortho_base = l_ortho + l_ortho_base' +\n  assumes compat_bases : \"\\<And> s . is_sup {LBase l1 s, LBase l2 s} \\<bottom>\"\n\nlocale l_ortho_ok' =\n  fixes l1 :: \"('a, 'b1, 'c :: {Pord_Weakb, Okay}, 'f1) lifting\"\n  fixes l2 :: \"('a, 'b2, 'c, 'f2) lifting\"\n\nlocale l_ortho_ok = l_ortho + l_ortho_ok' +\n  assumes compat_idem_ok :\n    \"\\<And> s a1 a2 b supr . b \\<in> ok_S \\<Longrightarrow> \n    is_sup {LUpd_Idem l1 s a1 b, LUpd_Idem l2 s a2 b} supr \\<Longrightarrow> supr \\<in> ok_S\"\n  assumes compat_post_ok :\n    \"\\<And> s b supr . b \\<in> ok_S \\<Longrightarrow>\n    is_sup {LPost l1 s b, LPost l2 s b} supr \\<Longrightarrow> supr \\<in> ok_S\"\n  \n\n(* lift_map_s is LMap plus a syntax translation *)\ndefinition lift_map_s ::\n  \"('b1 \\<Rightarrow> 'a1) \\<Rightarrow>\n   ('a1, 'a2, 'b2 :: Pord, 'f) lifting \\<Rightarrow>\n   'f \\<Rightarrow>\n   ('b1 \\<Rightarrow> 'b2 \\<Rightarrow> 'b2)\" where\n\"lift_map_s l' l sem syn st =\n  LMap l sem (l' syn) st\"\n\n\n(* commutativity of l_ortho *)\nsublocale l_ortho \\<subseteq> comm :\n  l_ortho l2 S2 l1 S1\nproof\n\n  fix s\n  show \"LBase l2 s = LBase l1 s\"\n    using eq_base by auto\nnext\n\n  fix s a1 a2 b1 b2 supr\n\n  have Comm : \"{LUpd_Idem l2 s a1 b1, LUpd_Idem l1 s a2 b2} = \n               {LUpd_Idem l1 s a2 b2, LUpd_Idem l2 s a1 b1}\"\n    by auto\n\n  have Comm' : \"{b1, b2} = {b2, b1}\"\n    by auto\n\n  assume \"is_sup {b1, b2} supr\"\n  then have \"has_sup {b2, b1}\" unfolding Comm' by auto\n\n  then show \"has_sup\n        {LUpd_Idem l2 s a1 b1,\n         LUpd_Idem l1 s a2 b2}\"\n    using compat_idem[of b2 b1 s a2 a1]\n    unfolding Comm\n    by auto\n\nnext\n  fix s\n  fix b1 b2 :: 'c\n\n  have Comm : \"{LPost l2 s b1, LPost l1 s b2} = {LPost l1 s b2, LPost l2 s b1}\"\n    by auto\n\n  have Comm' : \"{b1, b2} = {b2, b1}\"\n    by auto\n\n  assume Sup : \"has_sup {b1, b2}\"\n\n  then show \"has_sup {LPost l2 s b1, LPost l1 s b2}\"\n    using compat_post[OF Sup[unfolded Comm']] unfolding Comm \n    by auto\nnext\n  fix b s a1 a2\n  fix b1 b2 supr :: 'c\n\n  have Comm' : \"{b1, b2} = {b2, b1}\"\n    by auto\n\n  have Comm: \"{LUpd_Idem l2 s a1 b1, LUpd_Idem l1 s a2 b2} = {LUpd_Idem l1 s a2 b2, LUpd_Idem l2 s a1 b1}\"\n    by auto\n\n  assume Sup_b : \"has_sup {b1, b2}\"\n  assume Sup : \"is_sup {LUpd_Idem l2 s a1 b1, LUpd_Idem l1 s a2 b2} supr\"\n\n  then show \"supr \\<in> S2 s \\<inter> S1 s\"\n    using compat_S[OF Sup_b[unfolded Comm'] Sup[unfolded Comm]]\n    by auto\n\nnext\n\n  fix s a b\n\n  show \"b \\<in> S1 s \\<Longrightarrow>\n       LUpd_Idem l2 s a b \\<in> S1 s\"\n    using put2_S1[of b s a]\n    by auto\nnext\n\n  fix s a b\n\n  show \"b \\<in> S2 s \\<Longrightarrow>\n       LUpd_Idem l1 s a b \\<in> S2 s\"\n    using put1_S2[of b s a]\n    by auto\nqed\n\nsublocale l_ortho_base \\<subseteq> comm :\n  l_ortho_base l2 S2 l1 S1\nproof\n  fix s\n\n  have Comm : \"{LBase l2 s, LBase l1 s} = {LBase l1 s, LBase l2 s}\"\n    by auto\n\n  show \"is_sup {LBase l2 s, LBase l1 s} \\<bottom>\"\n    using compat_bases unfolding Comm\n    by auto\nqed\n\nsublocale l_ortho_ok \\<subseteq> comm :\n  l_ortho_ok l2 S2 l1 S1\nproof\n  fix s a1 a2 b supr\n\n  assume Sup : \"is_sup {LUpd l2 s a1 b, LUpd l1 s a2 b} supr\"\n\n  assume Bok : \"b \\<in> ok_S\"\n\n  have Comm : \"{LUpd l2 s a1 b, LUpd l1 s a2 b} = \n               {LUpd l1 s a2 b, LUpd l2 s a1 b}\"\n    by auto\n\n  show \"supr \\<in> ok_S\"\n    using compat_ok[OF Bok Sup[unfolded Comm]]\n    by auto\nqed\n(*\nlemma (in l_ortho) compat'_comm :\n  shows \"LUpd l1 s a1 (LUpd l2 s a2 b) = LUpd l2 s a2 (LUpd l1 s a1 b)\"\n  using is_sup_unique[OF compat'1 compat'2]\n  by auto\n*)\nend", "meta": {"author": "mmalvarez", "repo": "Gazelle", "sha": "0a80144107b3ec7487725bd88d658843beb6cb82", "save_path": "github-repos/isabelle/mmalvarez-Gazelle", "path": "github-repos/isabelle/mmalvarez-Gazelle/Gazelle-0a80144107b3ec7487725bd88d658843beb6cb82/Lifter/Attic/Lifter_idem_gen.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631698328917, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.29908460270624015}}
{"text": "theory EinChannel\n\nimports bundle.SB automaton.dAutomaton_causal\n\nbegin\ntext \\<open>You need to set THIS directory as Session-Directory. NOT the root-directory of the repository\\<close>\n\nlemma cempty_empty[simp]: \"cEmpty = {c3}\"\n  apply(auto simp add: cEmpty_def)\n  apply(insert ctype.elims,auto)\n  by (metis channel.exhaust ctype.simps(1) ctype.simps(2) ctype.simps(4) ctype.simps(5) ctype.simps(6)\n      empty_not_UNIV image_is_empty  sup_eq_bot_iff)\n\ntypedef singleChan = \"{c1}\"\n  by blast\n\n\n\nlemma \"Abs_singleChan c1 = undefined\"\n  oops\ntext \\<open>Macht nicht wirklich sinn, aber da wir nur den einen Channel haben...\n  Normalerweise erstellt der Nutzer hier seine eigenen channels zuerst\\<close>\ninstantiation singleChan::chan\nbegin\ndefinition \"Rep = Rep_singleChan\"\n  \n  instance\n    apply(intro_classes)\n     apply(auto simp add: Rep_singleChan_def)\n    by (meson Rep_singleChan_inject injI)\n\nend\n\n\n\n\n\n\nsection\\<open>Datatype Konstruktor\\<close>\n\n(* FYI: the old approach from v2 to create the datatype is not really reusable, \n  because: \n      lift_definition elem_raw_i :: \"int \\<Rightarrow> ndaExampleMessage sbElem\" is\n  Thats an old \"single-channel\" setter...\n  One has to replace the \"ndaExampleMessage\" with a \"chan\"... but which?\n  There can only be ONE channel in the replacement! ! !\n  But what if the channel-datatype of the component has 2 or more channels?\n*)\n\ntext \\<open>Motivation: I HATE freemarker and other templates. \n  And the workflow sucks. The generator people have no idea about isabelle, \n  feature-request take FOREVER and then it might not work in every case\\<close>\n\ntext\\<open>Goal: Move the heavy-stuff from the Generator to Isabelle.\n  Pretty much every proof should be done in Isabelle, the generator\n  can still create datatypes, functions and so on\\<close>\n\ntext\\<open>Implementation: Is using Locales... \\<close>\n\n\ntext \\<open>\\<open>'a\\<close> should be interpreted as a tuple. The goal of this local is to create a\n  bijective mapping from \\<open>'a\\<close> to \\<open>'cs\\<close>.\n  The user can freely choose \\<open>'a\\<close>, hence he will not use the datatype \\<open>M\\<close>. \n  for example \\<open>'a = (nat \\<times> bool)\\<close> which maps to a bundle with one bool-channel and one nat-channel\\<close>\nlocale sbeGen =\n  fixes lConstructor::\"'a::countable \\<Rightarrow> 'cs::{chan, finite} \\<Rightarrow> M\"\n  assumes c_well: \"\\<And>a. \\<not>chIsEmpty TYPE ('cs) \\<Longrightarrow> sbElem_well (Some (lConstructor a))\"\n      and c_inj: \"\\<not>chIsEmpty TYPE ('cs) \\<Longrightarrow> inj lConstructor\" \n      and c_surj: \"\\<And>sbe. \\<not>chIsEmpty TYPE ('cs) \\<Longrightarrow> sbElem_well (Some sbe) \\<Longrightarrow> sbe\\<in>range lConstructor\" (* Schöner? *)\n      and c_empty: \"\\<And>a b::'a. chIsEmpty TYPE ('cs) \\<Longrightarrow> a=b\"\nbegin\n\nlift_definition setter::\"'a \\<Rightarrow> 'cs\\<^sup>\\<surd>\" is \n  \"if(chIsEmpty TYPE ('cs)) then (\\<lambda>_. None) else Some o lConstructor\"\n  using c_well sbtypeempty_sbewell by auto\n\ndefinition getter::\"'cs\\<^sup>\\<surd> \\<Rightarrow> 'a\" where\n\"getter sbe = (case (Rep_sbElem sbe) of None \\<Rightarrow> (SOME x. True) | \n      Some f \\<Rightarrow> (inv lConstructor) f)\" (* geht was anderes als \"SOME x\"? *)\n\nlemma get_set[simp]: \"getter (setter a) = a\"\n  unfolding getter_def\n  by (simp add: setter.rep_eq c_inj c_empty)\n\nlemma set_inj: \"inj setter\"\n  by (metis get_set injI)\n\nlemma set_surj: \"surj setter\"\n  unfolding setter_def\n  apply(cases \"\\<not>(chIsEmpty(TYPE('cs)))\")\nproof(simp add: surj_def,auto)\n  fix y::\"'cs\\<^sup>\\<surd>\"\n  assume chnEmpty:\"\\<not> chIsEmpty TYPE('cs)\"\n  obtain f where f_def:\"Rep_sbElem y=(Some f)\"\n    using chnEmpty sbtypenotempty_fex by auto\n  then obtain x where x_def:\"f = lConstructor x\"\n    by (metis c_inj c_surj f_the_inv_into_f sbelemwell2fwell chnEmpty)\n  then show \"\\<exists>x::'a. y = Abs_sbElem (Some (lConstructor x))\"\n    by (metis Rep_sbElem_inverse f_def)\nqed \n\nlemma set_bij: \"bij setter\"\n  by (metis bijI inj_onI sbeGen.get_set sbeGen_axioms set_surj)\n\nlemma get_inv_set: \"getter = (inv setter)\"\n  by (metis get_set set_surj surj_imp_inv_eq)\n\nlemma set_get[simp]: \"setter (getter sbe) = sbe\"\n  apply(simp add: get_inv_set)\n  by (meson bij_inv_eq_iff set_bij)\n\nlemma \"getter A = getter B \\<Longrightarrow> A = B\"\n  by (metis set_get)\n\nfixrec setterSB::\"'a stream \\<rightarrow> 'cs\\<^sup>\\<Omega>\" where\n\"setterSB\\<cdot>((up\\<cdot>l)&&ls) = (setter (undiscr l)) \\<bullet>\\<^sup>\\<surd> (setterSB\\<cdot>ls)\" \n\nlemma settersb_unfold:\"setterSB\\<cdot>(\\<up>a \\<bullet> s) = (setter a) \\<bullet>\\<^sup>\\<surd> setterSB\\<cdot>s\"\n  unfolding setterSB_def\n  apply(subst fix_eq)\n  apply simp \n  apply(subgoal_tac \"\\<exists>l. \\<up>a \\<bullet> s = (up\\<cdot>l)&&s\")\n  apply auto \n  apply (metis (no_types, lifting) lshd_updis stream.sel_rews(4) undiscr_Discr up_inject)\n  by (metis lscons_conv)\n\nlemma settersb_emptyfix:\"chIsEmpty (TYPE ('cs)) \\<Longrightarrow> setterSB\\<cdot>s = \\<bottom>\"\n  by simp\n\nlemma settersb_epsbot:\"setterSB\\<cdot>\\<epsilon> = \\<bottom>\"\n  apply(simp add: setterSB_def)\n  apply(subst fix_eq)\n  by auto\n\n(* TODO : Dokumentireen! *)\ndefinition getterSB::\"'cs\\<^sup>\\<Omega> \\<rightarrow> 'a stream\" where\n\"getterSB \\<equiv> fix\\<cdot>(\\<Lambda> h. sb_case\\<cdot>(\\<lambda>sbe. \\<Lambda> sb. updis (getter sbe) && h\\<cdot>sb))\"\n\nlemma gettersb_unfold:\"getterSB\\<cdot>(sbe \\<bullet>\\<^sup>\\<surd> sb) = \\<up>(getter sbe) \\<bullet> getterSB\\<cdot>sb\"\n  unfolding getterSB_def\n  apply(subst fix_eq)\n  apply simp\n  by (simp add: lscons_conv)\n\nlemma gettersb_emptyfix:\"chIsEmpty (TYPE ('cs)) \\<Longrightarrow> getterSB\\<cdot>sb = \\<up>(getter (Abs_sbElem None)) \\<bullet> getterSB\\<cdot>sb\"\n  by (metis(full_types) gettersb_unfold sbtypeepmpty_sbbot)\n\nlemma gettersb_realboteps:\"\\<not>(chIsEmpty (TYPE ('cs))) \\<Longrightarrow> getterSB\\<cdot>\\<bottom> = \\<epsilon>\"\n  unfolding getterSB_def\n  apply(subst fix_eq)\n  by (simp add: sb_cases_bot)\n(* TODO: lemma über setterSB und getterSB *)\n\nlemma assumes \"chIsEmpty (TYPE ('cs))\"\n  shows \"\\<exists>a. (getterSB\\<cdot>sb) = (sinftimes(\\<up>(a)))\"\n  apply(insert assms,subst gettersb_emptyfix,simp) \n  using gettersb_emptyfix s2sinftimes by auto\n  \n (* TODO; warning entfernen. abbreviation-prioritäten für \\<infinity>?*)\n\nlemma \"sbLen (setterSB\\<cdot>s) = #s\"\n  oops(* gilt nicht für chIsEmpty *)\n\nlemma \"a \\<sqsubseteq> getterSB\\<cdot>(setterSB\\<cdot>a)\"\n  apply(induction a rule: ind)\n  apply(auto)\n  apply (simp add: gettersb_unfold settersb_unfold)\n  by (simp add: monofun_cfun_arg)\n\nlemma getset_eq:\"\\<not>chIsEmpty (TYPE ('cs)) \\<Longrightarrow> getterSB\\<cdot>(setterSB\\<cdot>a) = a\"\n  apply(induction a rule: ind)\n  apply(auto)\n  apply (simp add: gettersb_realboteps settersb_epsbot)\n  by (simp add: gettersb_unfold settersb_unfold)\n\nlemma \"setterSB\\<cdot>(getterSB\\<cdot>sb) \\<sqsubseteq> sb\"\n  apply(induction sb)\n  apply auto\n  apply(cases \"chIsEmpty(TYPE('cs))\")\n  apply (metis (full_types)minimal sbtypeepmpty_sbbot)\n  apply(simp add: sbIsLeast_def)\n  oops\n \n\nlemma setget_eq:\"(\\<forall>c. #(sb \\<^enum> c) = k) \\<Longrightarrow>setterSB\\<cdot>(getterSB\\<cdot>sb) = sb\"\n  apply(induction sb arbitrary: k)\n  apply auto\n  apply(rule adm_imp)\n     apply auto \n  apply(rule admI)\n  defer\n  apply(case_tac \"chIsEmpty (TYPE ('cs))\")\n  apply (metis (full_types)sbtypeepmpty_sbbot)\n    apply(simp add: sbIsLeast_def)\n  apply(subgoal_tac \"k = 0\",auto)\n     apply (metis gettersb_realboteps sb_eqI sbgetch_bot settersb_epsbot)\n    defer\n    apply(subst gettersb_unfold)\n    apply(subst settersb_unfold,simp)\n  apply(subgoal_tac \"\\<And>c. #(sb \\<^enum> c) \\<le> #(sbe \\<bullet>\\<^sup>\\<surd> sb  \\<^enum>  c)\",auto)\n  oops  (* Nur für gleichlange ströme *)\nend\n\n\n\n\n\n\nlocale sscanlGen =\n  fixes da::\"('state::countable, 'in::{chan, finite}, 'out::{chan,finite}, 'initOut::chan) dAutomaton_weak\"\n  and fin::\"'a::countable \\<Rightarrow> 'in \\<Rightarrow> M\"  \n  and fout::\"'b::countable \\<Rightarrow> 'out \\<Rightarrow> M\"\n  assumes sbegenfin:\"sbeGen fin\"\n      and sbegenfout:\"sbeGen fout\"\nbegin\n\nabbreviation \"sscanlTransition \\<equiv> (\\<lambda> s a. \n  let (nextState, nextOut) = dawTransition da s (sbeGen.setter fin a) in\n     (nextState, sbeGen.getter fout nextOut)\n)\"\n\nlemma daut2sscanl:\"dawStateSem da state\\<cdot>(input::'in\\<^sup>\\<Omega>) = \n       sbeGen.setterSB fout\\<cdot>(sscanlAsnd sscanlTransition state\\<cdot>(sbeGen.getterSB fin\\<cdot>input))\"\n  sorry\n\nlemma daut2sscnalinit:\"range(Rep::'out \\<Rightarrow> channel) = range(Rep::'initOut\\<Rightarrow> channel) \\<Longrightarrow> dawSem da\\<cdot>input = \n  sbeConvert(dawInitOut da) \\<bullet>\\<^sup>\\<surd> dawStateSem da state\\<cdot>(input::'in\\<^sup>\\<Omega>)\"\n  sorry\n\n(* TODO: initiale ausgabe ... \"sscanlA\" kann nichts partielles ausgben.\n  dh alles oder nichts. Das kann man durch den typ abfangen!\n    * weak = \"chIstEmpty\" als assumption (oder besser, dafür eine klasse anlegen)\n    * strong = gleicher typ wie ausgabe\n*)\n\nend\n\nlocale smapGen =\n fixes da::\"('state::countable, 'in::{chan, finite}, 'out::{chan,finite}, 'initOut::chan) dAutomaton_weak\"\n  and fin::\"'a::countable \\<Rightarrow> 'in \\<Rightarrow> M\"  \n  and fout::\"'b::countable \\<Rightarrow> 'out \\<Rightarrow> M\"\n  assumes scscanlgenf:\"sscanlGen fin fout\"\n  and singlestate:\"is_singleton(UNIV::'state set)\"\nbegin\n\nabbreviation \"smapTransition \\<equiv> (\\<lambda>a. \n  let nextOut = snd(dawTransition da (dawInitState da) (sbeGen.setter fin a)) in\n     sbeGen.getter fout nextOut)\"\n\nlemma daut2smap:\"dawStateSem da state\\<cdot>(input::'in\\<^sup>\\<Omega>) = \n       sbeGen.setterSB fout\\<cdot>(smap smapTransition\\<cdot>(sbeGen.getterSB fin\\<cdot>input))\"\n  sorry\n\nend\n\nsublocale  smapGen \\<subseteq> sscanlGen\n  by (simp add: scscanlgenf)\n\n\n\n\n\nlocale sumChanSB = (* TODO: anpassen wie oben, z.B. reihenfolge argumente *)\n  fixes lConstructor::\" 'a::pcpo \\<Rightarrow> 'cs::chan  \\<Rightarrow> M stream\"\n  assumes c_type: \"\\<And>a c. sValues (lConstructor a c) \\<subseteq> ctype (Rep c)\"\n    and c_inj: \"inj lConstructor\"\n    and c_surj: \"\\<And>f. sb_well f \\<Longrightarrow> f\\<in>range lConstructor\" (* Schöner? *)\nbegin\n\nlift_definition setter::\"'a \\<Rightarrow> ('cs::chan)\\<^sup>\\<Omega>\"is\"lConstructor\"\n  by (simp add: c_type sb_well_def)\n\ndefinition getter::\"'cs\\<^sup>\\<Omega> \\<Rightarrow> 'a\" where\n\"getter= (inv lConstructor) o  Rep_sb\"\n\nlemma get_set[simp]: \"getter (setter a) = a\"\n  unfolding getter_def\n  by (simp add: setter.rep_eq c_inj)  \n\nlemma set_inj: \"inj setter\"\n  by (metis get_set injI)\n\nlemma set_surj: \"surj setter\"\n  unfolding setter_def\nproof(simp add: surj_def,auto)\n  fix y::\"'cs\\<^sup>\\<Omega>\"\n obtain f where f_def:\"Rep_sb y=f\"\n   by simp\n then obtain x where x_def:\"f = lConstructor x\"\n    by (metis c_inj c_surj f_the_inv_into_f sbwell2fwell)\n  then show \"\\<exists>x::'a. y = Abs_sb (lConstructor x)\" \n    by (metis Rep_sb_inverse f_def)\nqed\n\nlemma set_bij: \"bij setter\"\n  using bij_betw_def set_inj set_surj by auto\n\nlemma get_inv_set: \"getter = (inv setter)\"\n  by (metis get_set set_surj surj_imp_inv_eq)\n\nlemma set_get[simp]: \"setter (getter sbe) = sbe\"\n  apply(simp add: get_inv_set)\n  by (meson bij_inv_eq_iff set_bij)\n\nlemma \"getter A = getter B \\<Longrightarrow> A = B\"\n  by (metis set_get)\n\nend\n\n\n\nsection \\<open>Beispiel\\<close>\n\ntypedef mymy = \"{c1, c2}\"\n  by blast\n\ndefinition \"mymyC1 = Abs_mymy c1\"\ndefinition \"mymyC2 = Abs_mymy c2\"\n\n(* Fuck Yeah, pattern matching! *)\n(* TODO: is it possible to put everything in a \"bundle\"? \n    eg. bundleName.c1 = mymyC1\n        bundleName.setter = dudu.setter\"\n*)\nfree_constructors mymy for \"mymyC1\"  | \"mymyC2\"\n   apply auto\n  unfolding mymyC1_def mymyC2_def\n  apply (metis Rep_mymy Rep_mymy_inverse empty_iff insert_iff)\n  by (meson channel.distinct(1) insertI1 insertI2 type_definition.Abs_inject type_definition_mymy)\n\nlemma mymy_rep_range [simp]:\"range Rep_mymy = {c1, c2}\"\n  using type_definition.Rep_range type_definition_mymy by blast\n\ninstantiation mymy::chan\nbegin\ndefinition \"Rep = Rep_mymy\" (* TODO: abbreviation oÄ, ich will nicht immer \"Rep_mymy_def\" anwenden *) \n\ninstance\n  apply(intro_classes)\n  unfolding Rep_mymy_def apply simp\n  by (meson Rep_mymy_inject injI)\nend\n\n\n\nlemma myc1_rep [simp]: \"Rep (mymyC1) = c1\"\n  unfolding Rep_mymy_def mymyC1_def\n  by (simp add: Abs_mymy_inverse)\n\nlemma myc2_rep [simp]: \"Rep (mymyC2) = c2\"\n  unfolding Rep_mymy_def mymyC2_def\n  by (simp add: Abs_mymy_inverse)\n\n(* :/ Schöner? *)\nfun orderChan::\"('nat::type \\<Rightarrow> 'a::type) \\<Rightarrow> ('bool::type \\<Rightarrow> 'a) \\<Rightarrow>('nat\\<times>'bool) \\<Rightarrow> mymy \\<Rightarrow> 'a\" where\n\"orderChan Cc1 Cc2 (port_c1, port_c2) mymyC1 = Cc1 port_c1\" |\n\"orderChan Cc1 Cc2 (port_c1, port_c2) mymyC2 = Cc2 port_c2\"\n\nabbreviation \"buildSBE \\<equiv> orderChan \\<N> \\<B>\" \n\nlemma build_ctype: \"buildSBE a c \\<in> ctype (Rep c)\"\n  by(cases c; cases a; simp)\n\nlemma build_inj: \"inj buildSBE\"\n  apply(rule injI)\n  apply(case_tac x; case_tac y; simp)\n  by (metis M.inject orderChan.simps)\n\nlemma build_range: \"range (\\<lambda>a. buildSBE a c) = ctype (Rep c)\"\n  apply(cases c)\n  by(auto simp add: image_iff)\n\nlemma build_surj: assumes \"sbElem_well (Some sbe)\"\n  shows \"sbe \\<in> range buildSBE\"\nproof -\n  have ctypewell:\"\\<And>c. sbe c\\<in> ctype (Rep c)\"\n    using assms by auto\n  hence \"\\<And>c. sbe c \\<in> range (\\<lambda>a. buildSBE a c)\"\n    by (simp add: build_range)\n  hence \"\\<exists>prod. sbe = buildSBE prod\"\n    apply(subst fun_eq_iff,auto) (*TODO: shorter proof*)\n  proof -\n    { fix mm :: \"nat \\<Rightarrow> bool \\<Rightarrow> mymy\"\n      obtain bb :: bool where\n        ff1: \"(\\<not> bb) = (\\<forall>x2. \\<B> x2 \\<noteq> sbe mymyC2)\"\n        by moura\n      then have ff2: bb\n        by (metis ctype.simps(2) ctypewell myc2_rep rangeE)\n      obtain bba :: bool where\n        ff3: \"(\\<not> bba) = (\\<forall>x1. \\<N> x1 \\<noteq> sbe mymyC1)\"\n        by moura\n      then have bba\n        by (metis ctype.simps(1) ctypewell myc1_rep rangeE)\n      then have \"\\<exists>n b. sbe (mm n b) = buildSBE (n, b) (mm n b)\"\n        using ff3 ff2 ff1 by (metis (full_types) mymy.exhaust orderChan.simps(1) orderChan.simps(2)) }\n    then show \"\\<exists>n b. \\<forall>m. sbe m = buildSBE (n, b) m\"\n      by metis\n  qed\n  thus ?thesis\n    by auto\nqed\n\ninstance mymy::finite\n  sorry\n\ninterpretation dudu: sbeGen \"buildSBE\" (*WTF Nitpick ? ? ?*)\n  apply(unfold_locales)\n  apply (simp add: build_ctype)\n  apply (simp add: build_inj)\n  using build_surj sorry\n\nterm \"dudu.setter\"\n\nterm \"curry dudu.setter\"  (* If you prefer the \"old way\" *)\n\nlemma \"dudu.getter (dudu.setter (1,True)) = (1,True)\"\n  by simp\n\n(*buildSB interpretation*)\n\nabbreviation \"buildSB \\<equiv> orderChan (Rep_cfun (smap \\<N>)) (Rep_cfun (smap \\<B>))\" \n\nlemma buildSB_ctype: \"sValues(buildSB a c) \\<subseteq> ctype (Rep c)\"\n  by(cases c; cases a; simp add: sValues_def)\n\nlemma buildSB_inj: \"inj buildSB\"\n  apply(rule injI)\n  apply(case_tac x; case_tac y; simp)\n  apply(auto)\n  sorry\n\nlemma buildSB_range: \"(\\<Union>a. sValues (buildSB a c)) = ctype (Rep c)\"\n  apply(cases c)\n  apply auto \n  apply (metis (no_types, lifting) in_mono sValues_def smap_sdom_range)\n  apply(rule_tac x=\"\\<up>xa\" in exI) \n  apply(simp add: sValues_def)\n  apply (metis (mono_tags) ctype.simps(2) image_iff range_eqI sValues_def smap_sdom)\n  apply(rule_tac x=\"\\<up>xa\" in exI) \n  by(simp add: sValues_def)\n\nlemma buildSB_surj: assumes \"sb_well f\"\n  shows \"f \\<in> range buildSB\"\nproof -\n  have ctypewell:\"\\<And>c. sValues (f c) \\<subseteq> ctype (Rep c)\"\n    using assms sb_well_def by blast\n  hence \"\\<And>c. sValues(f c) \\<subseteq> range (\\<lambda>a. buildSBE a c)\"\n    by (simp add: build_range)\n  hence \"\\<exists>prod. f = buildSB prod\"\n    apply(subst fun_eq_iff,auto,simp add: sValues_def) (*TODO: shorter proof*)\n    sorry\n  thus ?thesis\n    by auto\nqed\n\n\ninterpretation duda: sumChanSB \"buildSB\"\n  apply(unfold_locales)\n  apply (simp add: buildSB_ctype)\n  apply (simp add: buildSB_inj)\n  by (simp add: buildSB_surj)\n\nterm \"duda.setter\"\nterm \"duda.getter\"\n\n\n\n\n\nend", "meta": {"author": "yyisgladiator", "repo": "demo", "sha": "2a57300dfa7268721c78c233ee6b0a5454acce1f", "save_path": "github-repos/isabelle/yyisgladiator-demo", "path": "github-repos/isabelle/yyisgladiator-demo/demo-2a57300dfa7268721c78c233ee6b0a5454acce1f/src/demo/EinChannel/EinChannel.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631698328916, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.2990846027062401}}
{"text": "theory Pair_Automaton\n  imports Tree_Automata_Complement GTT_Compose\nbegin\n\nsubsection \\<open>Pair automaton and anchored GTTs\\<close>\n\ndefinition pair_at_lang :: \"('q, 'f) gtt \\<Rightarrow> ('q \\<times> 'q) fset \\<Rightarrow> 'f gterm rel\" where\n  \"pair_at_lang \\<G> Q = {(s, t) | s t p q. q |\\<in>| gta_der (fst \\<G>) s \\<and> p |\\<in>| gta_der (snd \\<G>) t \\<and> (q, p) |\\<in>| Q}\"\n\nlemma pair_at_lang_restr_states:\n  \"pair_at_lang \\<G> Q = pair_at_lang \\<G> (Q |\\<inter>| (\\<Q> (fst \\<G>) |\\<times>| \\<Q> (snd \\<G>)))\"\n  by (auto simp: pair_at_lang_def gta_der_def) (meson gterm_ta_der_states) \n\nlemma pair_at_langE:\n  assumes \"(s, t) \\<in> pair_at_lang \\<G> Q\"\n  obtains q p where \"(q, p) |\\<in>| Q\" and \"q |\\<in>| gta_der (fst \\<G>) s\" and \"p |\\<in>| gta_der (snd \\<G>) t\"\n  using assms by (auto simp: pair_at_lang_def)\n\nlemma pair_at_langI:\n  assumes \"q |\\<in>| gta_der (fst \\<G>) s\" \"p |\\<in>| gta_der (snd \\<G>) t\" \"(q, p) |\\<in>| Q\"\n  shows \"(s, t) \\<in> pair_at_lang \\<G> Q\"\n  using assms by (auto simp: pair_at_lang_def)\n\nlemma pair_at_lang_fun_states:\n  assumes \"finj_on f (\\<Q> (fst \\<G>))\" and \"finj_on g (\\<Q> (snd \\<G>))\"\n    and \"Q |\\<subseteq>| \\<Q> (fst \\<G>) |\\<times>| \\<Q> (snd \\<G>)\"\n  shows \"pair_at_lang \\<G> Q = pair_at_lang (map_prod (fmap_states_ta f) (fmap_states_ta g) \\<G>) (map_prod f g |`| Q)\"\n    (is \"?LS = ?RS\")\nproof\n  {fix s t assume \"(s, t) \\<in> ?LS\"\n    then have \"(s, t) \\<in> ?RS\" using ta_der_fmap_states_ta_mono[of f \"fst \\<G>\" s]\n      using ta_der_fmap_states_ta_mono[of g \"snd \\<G>\" t]\n      by (force simp: gta_der_def map_prod_def image_iff  elim!: pair_at_langE split: prod.split intro!: pair_at_langI)}\n  then show \"?LS \\<subseteq> ?RS\" by auto\nnext\n  {fix s t assume \"(s, t) \\<in> ?RS\"\n    then obtain p q where rs: \"p |\\<in>| ta_der (fst \\<G>) (term_of_gterm s)\" \"f p |\\<in>| ta_der (fmap_states_ta f (fst \\<G>)) (term_of_gterm s)\" and\n      ts: \"q |\\<in>| ta_der (snd \\<G>) (term_of_gterm t)\" \"g q |\\<in>| ta_der (fmap_states_ta g (snd \\<G>)) (term_of_gterm t)\" and\n      st: \"(f p, g q) |\\<in>| (map_prod f g |`| Q)\" using assms ta_der_fmap_states_inv[of f \"fst \\<G>\" _ s]\n      using ta_der_fmap_states_inv[of g \"snd \\<G>\" _ t]\n      by (auto simp: gta_der_def adapt_vars_term_of_gterm elim!: pair_at_langE)\n         (metis (no_types, opaque_lifting) fimageE fmap_prod_fimageI ta_der_fmap_states_conv)\n    then have \"p |\\<in>| \\<Q> (fst \\<G>)\" \"q |\\<in>| \\<Q> (snd \\<G>)\" by auto\n    then have \"(p, q) |\\<in>| Q\" using assms st unfolding fimage_iff fBex_def\n      by (auto dest!: fsubsetD simp: finj_on_eq_iff)\n    then have \"(s, t) \\<in> ?LS\" using st rs(1) ts(1) by (auto simp: gta_der_def intro!: pair_at_langI)}\n  then show \"?RS \\<subseteq> ?LS\" by auto\nqed\n\nlemma converse_pair_at_lang:\n  \"(pair_at_lang \\<G> Q)\\<inverse> = pair_at_lang (prod.swap \\<G>) (Q|\\<inverse>|)\"\n  by (auto simp: pair_at_lang_def)\n\nlemma pair_at_agtt:\n  \"agtt_lang \\<G> = pair_at_lang \\<G> (fId_on (gtt_interface \\<G>))\"\n  by (auto simp: agtt_lang_def gtt_interface_def pair_at_lang_def gtt_states_def gta_der_def fId_on_iff)\n\ndefinition \\<Delta>_eps_pair where\n  \"\\<Delta>_eps_pair \\<G>\\<^sub>1 Q\\<^sub>1 \\<G>\\<^sub>2 Q\\<^sub>2 \\<equiv>  Q\\<^sub>1 |O| \\<Delta>\\<^sub>\\<epsilon> (snd \\<G>\\<^sub>1) (fst \\<G>\\<^sub>2) |O| Q\\<^sub>2\"\n\nlemma pair_comp_sound1:\n  assumes \"(s, t) \\<in> pair_at_lang \\<G>\\<^sub>1 Q\\<^sub>1\"\n    and \"(t, u) \\<in> pair_at_lang \\<G>\\<^sub>2 Q\\<^sub>2\"\n  shows \"(s, u) \\<in> pair_at_lang (fst \\<G>\\<^sub>1, snd \\<G>\\<^sub>2) (\\<Delta>_eps_pair \\<G>\\<^sub>1 Q\\<^sub>1 \\<G>\\<^sub>2 Q\\<^sub>2)\"\nproof -\n  from pair_at_langE assms obtain p q  q' r where\n    wit: \"(p, q) |\\<in>| Q\\<^sub>1\" \"p |\\<in>| gta_der (fst \\<G>\\<^sub>1) s\" \"q |\\<in>| gta_der (snd \\<G>\\<^sub>1) t\"\n    \"(q', r) |\\<in>| Q\\<^sub>2\" \"q' |\\<in>| gta_der (fst \\<G>\\<^sub>2) t\" \"r |\\<in>| gta_der (snd \\<G>\\<^sub>2) u\"\n      by metis\n  from wit(3, 5) have \"(q, q') |\\<in>| \\<Delta>\\<^sub>\\<epsilon> (snd \\<G>\\<^sub>1) (fst \\<G>\\<^sub>2)\"\n    by (auto simp: \\<Delta>\\<^sub>\\<epsilon>_def' gta_der_def intro!: exI[of _ \"term_of_gterm t\"])\n  then have \"(p, r) |\\<in>| \\<Delta>_eps_pair \\<G>\\<^sub>1 Q\\<^sub>1 \\<G>\\<^sub>2 Q\\<^sub>2\" using wit(1, 4)\n    by (auto simp: \\<Delta>_eps_pair_def)\n  then show ?thesis using wit(2, 6) unfolding pair_at_lang_def\n    by auto\nqed\n\nlemma pair_comp_sound2:\n  assumes \"(s, u) \\<in>  pair_at_lang (fst \\<G>\\<^sub>1, snd \\<G>\\<^sub>2) (\\<Delta>_eps_pair \\<G>\\<^sub>1 Q\\<^sub>1 \\<G>\\<^sub>2 Q\\<^sub>2)\"\n  shows \"\\<exists> t. (s, t) \\<in> pair_at_lang \\<G>\\<^sub>1 Q\\<^sub>1 \\<and> (t, u) \\<in> pair_at_lang \\<G>\\<^sub>2 Q\\<^sub>2\"\n  using assms unfolding pair_at_lang_def \\<Delta>_eps_pair_def\n  by (auto simp: \\<Delta>\\<^sub>\\<epsilon>_def' gta_der_def) (metis gterm_of_term_inv)\n\nlemma pair_comp_sound:\n  \"pair_at_lang \\<G>\\<^sub>1 Q\\<^sub>1 O pair_at_lang \\<G>\\<^sub>2 Q\\<^sub>2 = pair_at_lang (fst \\<G>\\<^sub>1, snd \\<G>\\<^sub>2) (\\<Delta>_eps_pair \\<G>\\<^sub>1 Q\\<^sub>1 \\<G>\\<^sub>2 Q\\<^sub>2)\"\n  by (auto simp: pair_comp_sound1 pair_comp_sound2 relcomp.simps)\n\ninductive_set \\<Delta>_Atrans_set :: \"('q \\<times> 'q) fset \\<Rightarrow> ('q, 'f) ta \\<Rightarrow> ('q, 'f) ta \\<Rightarrow> ('q \\<times> 'q) set\" for Q \\<A> \\<B> where\n  base [simp]: \"(p, q) |\\<in>| Q \\<Longrightarrow> (p, q) \\<in> \\<Delta>_Atrans_set Q \\<A> \\<B>\"\n| step [intro]: \"(p, q) \\<in> \\<Delta>_Atrans_set Q \\<A> \\<B> \\<Longrightarrow> (q, r) |\\<in>| \\<Delta>\\<^sub>\\<epsilon> \\<B> \\<A> \\<Longrightarrow>\n     (r, v) \\<in> \\<Delta>_Atrans_set Q \\<A> \\<B> \\<Longrightarrow> (p, v) \\<in> \\<Delta>_Atrans_set Q \\<A> \\<B>\"\n\nlemma \\<Delta>_Atrans_set_states:\n  \"(p, q) \\<in> \\<Delta>_Atrans_set Q \\<A> \\<B> \\<Longrightarrow> (p, q) \\<in> fset ((fst |`| Q |\\<union>| \\<Q> \\<A>) |\\<times>| (snd |`| Q |\\<union>| \\<Q> \\<B>))\"\n  by (induct rule: \\<Delta>_Atrans_set.induct) (auto simp: fimage_iff fBex_def simp flip: fmember_iff_member_fset)\n\nlemma finite_\\<Delta>_Atrans_set: \"finite (\\<Delta>_Atrans_set Q \\<A> \\<B>)\"\nproof -\n  have \"\\<Delta>_Atrans_set Q \\<A> \\<B> \\<subseteq> fset ((fst |`| Q |\\<union>| \\<Q> \\<A>) |\\<times>| (snd |`| Q |\\<union>| \\<Q> \\<B>))\"\n    using \\<Delta>_Atrans_set_states by auto\n  from finite_subset[OF this] show ?thesis by simp\nqed\n\ncontext\nincludes fset.lifting\nbegin\nlift_definition \\<Delta>_Atrans ::  \"('q \\<times> 'q) fset \\<Rightarrow> ('q, 'f) ta \\<Rightarrow> ('q, 'f) ta \\<Rightarrow> ('q \\<times> 'q) fset\" is \\<Delta>_Atrans_set\n  by (simp add: finite_\\<Delta>_Atrans_set)\n\nlemmas \\<Delta>_Atrans_base [simp] = \\<Delta>_Atrans_set.base [Transfer.transferred]\nlemmas \\<Delta>_Atrans_step [intro] = \\<Delta>_Atrans_set.step [Transfer.transferred]\nlemmas \\<Delta>_Atrans_cases = \\<Delta>_Atrans_set.cases[Transfer.transferred]\nlemmas \\<Delta>_Atrans_induct [consumes 1, case_names base step] = \\<Delta>_Atrans_set.induct[Transfer.transferred]\nend\n\nabbreviation \"\\<Delta>_Atrans_gtt \\<G> Q \\<equiv> \\<Delta>_Atrans Q (fst \\<G>) (snd \\<G>)\"\n\nlemma pair_trancl_sound1:\n  assumes \"(s, t) \\<in> (pair_at_lang \\<G> Q)\\<^sup>+\"\n  shows \"\\<exists> q p. p |\\<in>| gta_der (fst \\<G>) s \\<and> q |\\<in>| gta_der (snd \\<G>) t \\<and> (p, q) |\\<in>| \\<Delta>_Atrans_gtt \\<G> Q\"\n  using assms\nproof (induct)\n  case (step t v)\n  obtain p q r r' where reach_t: \"r |\\<in>| gta_der (fst \\<G>) t\" \"q |\\<in>| gta_der (snd \\<G>) t\" and\n    reach: \"p |\\<in>| gta_der (fst \\<G>) s\" \"r' |\\<in>| gta_der (snd \\<G>) v\" and\n    st: \"(p, q) |\\<in>| \\<Delta>_Atrans_gtt \\<G> Q\"  \"(r, r') |\\<in>| Q\" using step(2, 3)\n    by (auto simp: pair_at_lang_def)\n  from reach_t have \"(q, r) |\\<in>| \\<Delta>\\<^sub>\\<epsilon> (snd \\<G>) (fst \\<G>)\"\n    by (auto simp: \\<Delta>\\<^sub>\\<epsilon>_def' gta_der_def intro: ground_term_of_gterm)\n  then have \"(p, r') |\\<in>| \\<Delta>_Atrans_gtt \\<G> Q\" using st by auto\n  then show ?case using reach reach_t\n    by (auto simp: pair_at_lang_def gta_der_def \\<Delta>\\<^sub>\\<epsilon>_def' intro: ground_term_of_gterm)\nqed (auto simp: pair_at_lang_def intro: \\<Delta>_Atrans_base)\n\nlemma pair_trancl_sound2:\n  assumes \"(p, q) |\\<in>| \\<Delta>_Atrans_gtt \\<G> Q\"\n    and \"p |\\<in>| gta_der (fst \\<G>) s\" \"q |\\<in>| gta_der (snd \\<G>) t\"\n  shows \"(s, t) \\<in> (pair_at_lang \\<G> Q)\\<^sup>+\" using assms\nproof (induct arbitrary: s t rule:\\<Delta>_Atrans_induct)\n  case (step p q r v)\n  from step(2)[OF step(6)] step(5)[OF _ step(7)] step(3)\n  show ?case by (auto simp: gta_der_def \\<Delta>\\<^sub>\\<epsilon>_def' intro!: ground_term_of_gterm)\n      (metis gterm_of_term_inv trancl_trans)\nqed (auto simp: pair_at_lang_def)\n\nlemma pair_trancl_sound:\n  \"(pair_at_lang \\<G> Q)\\<^sup>+ = pair_at_lang \\<G> (\\<Delta>_Atrans_gtt \\<G> Q)\"\n  by (auto simp: pair_trancl_sound2 dest: pair_trancl_sound1 elim: pair_at_langE intro: pair_at_langI)\n\nabbreviation \"fst_pair_cl \\<A> Q \\<equiv> TA (rules \\<A>) (eps \\<A> |\\<union>| (fId_on (\\<Q> \\<A>) |O| Q))\"\ndefinition pair_at_to_agtt :: \"('q, 'f) gtt \\<Rightarrow> ('q \\<times> 'q) fset \\<Rightarrow> ('q, 'f) gtt\" where\n  \"pair_at_to_agtt \\<G> Q = (fst_pair_cl (fst \\<G>) Q , TA (rules (snd \\<G>)) (eps (snd \\<G>)))\"\n\nlemma fst_pair_cl_eps:\n  assumes \"(p, q) |\\<in>| (eps (fst_pair_cl \\<A> Q))|\\<^sup>+|\"\n    and \"\\<Q> \\<A> |\\<inter>| snd |`| Q = {||}\"\n  shows \"(p, q) |\\<in>| (eps \\<A>)|\\<^sup>+| \\<or> (\\<exists> r. (p = r \\<or> (p, r) |\\<in>| (eps \\<A>)|\\<^sup>+|) \\<and> (r, q) |\\<in>| Q)\" using assms\nproof (induct rule: ftrancl_induct)\n  case (Step p q r)\n  then have y: \"q |\\<in>| \\<Q> \\<A>\" by (auto simp add: eps_trancl_statesD eps_statesD)\n  have [simp]: \"(p, q) |\\<in>| Q \\<Longrightarrow> q |\\<in>| snd |`| Q\" for p q by (auto simp: fimage_iff) force \n  then show ?case using Step y\n    by auto (simp add: ftrancl_into_trancl)\nqed auto\n\nlemma fst_pair_cl_res_aux:\n  assumes \"\\<Q> \\<A> |\\<inter>| snd |`| Q = {||}\"\n    and \"q |\\<in>| ta_der (fst_pair_cl \\<A> Q) (term_of_gterm t)\"\n  shows \"\\<exists> p. p |\\<in>| ta_der \\<A> (term_of_gterm t) \\<and> (q |\\<notin>| \\<Q> \\<A> \\<longrightarrow> (p, q) |\\<in>| Q) \\<and> (q |\\<in>| \\<Q> \\<A> \\<longrightarrow> p = q)\" using assms\nproof (induct t arbitrary: q)\n  case (GFun f ts)\n  then obtain qs q' where rule: \"TA_rule f qs q' |\\<in>| rules \\<A>\" \"length qs = length ts\" and\n    eps: \"q' = q \\<or> (q', q) |\\<in>| (eps (fst_pair_cl \\<A> Q))|\\<^sup>+|\" and\n    reach: \"\\<forall> i < length ts. qs ! i |\\<in>| ta_der (fst_pair_cl \\<A> Q) (term_of_gterm (ts ! i))\"\n    by auto\n  {fix i assume ass: \"i < length ts\" then have st: \"qs ! i |\\<in>| \\<Q> \\<A>\" using rule\n      by (auto simp: rule_statesD)\n    then have \"qs ! i |\\<notin>| snd |`| Q\" using GFun(2) by auto\n    then have \"qs ! i |\\<in>| ta_der \\<A> (term_of_gterm (ts ! i))\" using reach st ass\n      using fst_pair_cl_eps[OF _ GFun(2)] GFun(1)[OF nth_mem[OF ass] GFun(2), of \"qs ! i\"]\n      by blast} note IH = this\n  show ?case\n  proof (cases \"q' = q\")\n    case True\n    then show ?thesis using rule reach IH\n      by (auto dest: rule_statesD intro!: exI[of _ q'] exI[of _ qs])\n  next\n    case False note nt_eq = this\n    then have eps: \"(q', q) |\\<in>| (eps (fst_pair_cl \\<A> Q))|\\<^sup>+|\" using eps by simp\n    from fst_pair_cl_eps[OF this assms(1)] show ?thesis\n      using False rule IH\n    proof (cases \"q |\\<notin>| \\<Q> \\<A>\")\n      case True\n      from fst_pair_cl_eps[OF eps assms(1)] obtain r where\n         \"q' = r \\<or> (q', r) |\\<in>| (eps \\<A>)|\\<^sup>+|\" \"(r, q) |\\<in>| Q\" using True\n        by (auto simp: eps_trancl_statesD)\n      then show ?thesis using nt_eq rule IH True\n        by (auto simp: fimage_iff eps_trancl_statesD)\n    next\n      case False\n      from fst_pair_cl_eps[OF eps assms(1)] False assms(1)\n      have \"(q', q) |\\<in>| (eps \\<A>)|\\<^sup>+|\"\n        by (auto simp: fimage_iff) (metis fempty_iff fimage_eqI finterI snd_conv)+\n      then show ?thesis using IH rule\n        by (intro exI[of _ q]) (auto simp: eps_trancl_statesD)\n    qed\n  qed\nqed\n\nlemma restr_distjoing:\n  assumes \"Q |\\<subseteq>| \\<Q> \\<A> |\\<times>| \\<Q> \\<BB>\"\n    and \"\\<Q> \\<A> |\\<inter>| \\<Q> \\<BB> = {||}\"\n  shows \"\\<Q> \\<A> |\\<inter>| snd |`| Q = {||}\"\n  using assms by auto\n\nlemma pair_at_agtt_conv:\n  assumes \"Q |\\<subseteq>| \\<Q> (fst \\<G>) |\\<times>| \\<Q> (snd \\<G>)\" and \"\\<Q> (fst \\<G>) |\\<inter>| \\<Q> (snd \\<G>) = {||}\"\n  shows \"pair_at_lang \\<G> Q = agtt_lang (pair_at_to_agtt \\<G> Q)\" (is \"?LS = ?RS\")\nproof\n  let ?TA = \"fst_pair_cl (fst \\<G>) Q\"\n  {fix s t assume ls: \"(s, t) \\<in> ?LS\"\n    then obtain q p where w: \"(q, p) |\\<in>| Q\" \"q |\\<in>| gta_der (fst \\<G>) s\" \"p |\\<in>| gta_der (snd \\<G>) t\"\n      by (auto elim: pair_at_langE)\n    from w(2) have \"q |\\<in>| gta_der ?TA s\" \"q |\\<in>| \\<Q> (fst \\<G>)\"\n      using ta_der_mono'[of \"fst \\<G>\" ?TA \"term_of_gterm s\"]\n      by (auto simp add: fin_mono ta_subset_def gta_der_def in_mono)\n    then have \"(s, t) \\<in> ?RS\" using w(1, 3)\n      by (auto simp: pair_at_to_agtt_def agtt_lang_def gta_der_def ta_der_eps intro!: exI[of _ p])\n         (metis fId_onI frelcompI funionI2 ta.sel(2) ta_der_eps)}\n  then show \"?LS \\<subseteq> ?RS\" by auto\nnext\n  {fix s t assume ls: \"(s, t) \\<in> ?RS\"\n    then obtain q where w: \"q |\\<in>| ta_der (fst_pair_cl (fst \\<G>) Q) (term_of_gterm s)\"\n      \"q |\\<in>| ta_der (snd \\<G>) (term_of_gterm t)\"\n      by (auto simp: agtt_lang_def pair_at_to_agtt_def gta_der_def)\n    from w(2) have \"q |\\<in>| \\<Q> (snd \\<G>)\" \"q |\\<notin>| \\<Q> (fst \\<G>)\" using assms(2)\n      by auto\n    from fst_pair_cl_res_aux[OF restr_distjoing[OF assms] w(1)] this w(2)\n    have \"(s, t) \\<in> ?LS\" by (auto simp: agtt_lang_def pair_at_to_agtt_def gta_der_def intro: pair_at_langI)}\n  then show \"?RS \\<subseteq> ?LS\" by auto\nqed\n\ndefinition pair_at_to_agtt' where\n  \"pair_at_to_agtt' \\<G> Q = (let \\<A> = fmap_states_ta Inl (fst \\<G>) in\n    let \\<B> = fmap_states_ta Inr (snd \\<G>) in\n    let Q' = Q |\\<inter>| (\\<Q> (fst \\<G>) |\\<times>| \\<Q> (snd \\<G>)) in\n    pair_at_to_agtt (\\<A>, \\<B>) (map_prod Inl Inr |`| Q'))\"\n\nlemma pair_at_agtt_cost:\n  \"pair_at_lang \\<G> Q = agtt_lang (pair_at_to_agtt' \\<G> Q)\"\nproof -\n  let ?G = \"(fmap_states_ta CInl (fst \\<G>), fmap_states_ta CInr (snd \\<G>))\"\n  let ?Q = \"(Q |\\<inter>| (\\<Q> (fst \\<G>) |\\<times>| \\<Q> (snd \\<G>)))\"\n  let ?Q' = \"map_prod CInl CInr |`| ?Q\"\n  have *: \"pair_at_lang \\<G> Q = pair_at_lang \\<G> ?Q\"\n    using pair_at_lang_restr_states by blast\n  have \"pair_at_lang \\<G> ?Q = pair_at_lang (map_prod (fmap_states_ta CInl) (fmap_states_ta CInr) \\<G>) (map_prod CInl CInr |`| ?Q)\"\n    by (intro pair_at_lang_fun_states[where ?\\<G> = \\<G> and ?Q = ?Q and ?f = CInl and ?g = CInr])\n       (auto simp: finj_CInl_CInr)\n  then have **:\"pair_at_lang \\<G> ?Q = pair_at_lang ?G ?Q'\" by (simp add: map_prod_simp')\n  have \"pair_at_lang ?G ?Q' = agtt_lang (pair_at_to_agtt ?G ?Q')\"\n    by (intro pair_at_agtt_conv[where ?\\<G> = ?G]) auto\n  then show ?thesis unfolding * ** pair_at_to_agtt'_def Let_def\n    by simp\nqed\n\nlemma \\<Delta>_Atrans_states_stable:\n  assumes \"Q |\\<subseteq>| \\<Q> (fst \\<G>) |\\<times>| \\<Q> (snd \\<G>)\"\n  shows \"\\<Delta>_Atrans_gtt \\<G> Q |\\<subseteq>| \\<Q> (fst \\<G>) |\\<times>| \\<Q> (snd \\<G>)\"\nproof\n  fix s assume ass: \"s |\\<in>| \\<Delta>_Atrans_gtt \\<G> Q\"\n  then obtain t u where s: \"s = (t, u)\" by (cases s) blast\n  show \"s |\\<in>| \\<Q> (fst \\<G>) |\\<times>| \\<Q> (snd \\<G>)\" using ass assms unfolding s\n    by (induct rule: \\<Delta>_Atrans_induct) auto\nqed\n\nlemma \\<Delta>_Atrans_map_prod:\n  assumes \"finj_on f (\\<Q> (fst \\<G>))\" and \"finj_on g (\\<Q> (snd \\<G>))\"\n    and \"Q |\\<subseteq>| \\<Q> (fst \\<G>) |\\<times>| \\<Q> (snd \\<G>)\"\n  shows \"map_prod f g |`| (\\<Delta>_Atrans_gtt \\<G> Q) = \\<Delta>_Atrans_gtt (map_prod (fmap_states_ta f) (fmap_states_ta g) \\<G>) (map_prod f g |`| Q)\"\n    (is \"?LS = ?RS\")\nproof -\n  {fix p q assume \"(p, q) |\\<in>| \\<Delta>_Atrans_gtt \\<G> Q\"\n    then have \"(f p, g q) |\\<in>| ?RS\" using assms\n    proof (induct rule: \\<Delta>_Atrans_induct)\n      case (step p q r v)\n      from step(3, 6, 7) have \"(g q, f r) |\\<in>| \\<Delta>\\<^sub>\\<epsilon> (fmap_states_ta g (snd \\<G>)) (fmap_states_ta f (fst \\<G>))\"\n        by (auto simp: \\<Delta>\\<^sub>\\<epsilon>_def' intro!: ground_term_of_gterm)\n           (metis ground_term_of_gterm ground_term_to_gtermD ta_der_to_fmap_states_der)\n      then show ?case using step by auto\n    qed (auto simp add: fmap_prod_fimageI)}\n  moreover\n  {fix p q assume \"(p, q) |\\<in>| ?RS\"\n    then have \"(p, q) |\\<in>| ?LS\" using assms\n    proof (induct rule: \\<Delta>_Atrans_induct)\n      case (step p q r v)\n      let ?f = \"the_finv_into (\\<Q> (fst \\<G>)) f\" let ?g = \"the_finv_into (\\<Q> (snd \\<G>)) g\"\n      have sub: \"\\<Delta>\\<^sub>\\<epsilon> (snd \\<G>) (fst \\<G>) |\\<subseteq>| \\<Q> (snd \\<G>) |\\<times>| \\<Q> (fst \\<G>)\"\n        using \\<Delta>\\<^sub>\\<epsilon>_statesD(1, 2) by fastforce\n      have s_e: \"(?f p, ?g q) |\\<in>| \\<Delta>_Atrans_gtt \\<G> Q\" \"(?f r, ?g v) |\\<in>| \\<Delta>_Atrans_gtt \\<G> Q\"\n        using step assms(1, 2) fsubsetD[OF \\<Delta>_Atrans_states_stable[OF assms(3)]]\n        using finj_on_eq_iff[OF assms(1)] finj_on_eq_iff\n        using the_finv_into_f_f[OF assms(1)] the_finv_into_f_f[OF assms(2)]\n        by auto\n      from step(3) have \"(?g q, ?f r) |\\<in>| \\<Delta>\\<^sub>\\<epsilon> (snd \\<G>) (fst \\<G>)\"\n        using step(6-) sub\n        using ta_der_fmap_states_conv[OF assms(1)] ta_der_fmap_states_conv[OF assms(2)]\n        using the_finv_into_f_f[OF assms(1)] the_finv_into_f_f[OF assms(2)]\n        by (auto simp: \\<Delta>\\<^sub>\\<epsilon>_fmember fimage_iff fBex_def)\n           (metis ground_term_of_gterm ground_term_to_gtermD ta_der_fmap_states_inv)\n      then have \"(q, r) |\\<in>| map_prod g f |`| \\<Delta>\\<^sub>\\<epsilon> (snd \\<G>) (fst \\<G>)\" using step\n        using the_finv_into_f_f[OF assms(1)] the_finv_into_f_f[OF assms(2)] sub\n        by auto (smt \\<Delta>\\<^sub>\\<epsilon>_statesD(1, 2) f_the_finv_into_f fmap_prod_fimageI fmap_states)\n      then show ?case using s_e assms(1, 2) s_e\n        using fsubsetD[OF sub]\n        using fsubsetD[OF \\<Delta>_Atrans_states_stable[OF assms(3)]]\n        using \\<Delta>_Atrans_step[of \"?f p\" \"?g q\" Q \"fst \\<G>\" \"snd \\<G>\" \"?f r\" \"?g v\"]\n        using the_finv_into_f_f[OF assms(1)] the_finv_into_f_f[OF assms(2)]\n        by  (auto simp: fimage_iff fBex_def)\n            (smt Pair_inject prod_fun_fimageE step.hyps(2) step.hyps(5) step.prems(3))\n    qed auto}\n  ultimately show ?thesis by auto\nqed\n\n\\<comment> \\<open>Section: Pair Automaton is closed under Determinization\\<close>\n\ndefinition Q_pow where\n  \"Q_pow Q \\<S>\\<^sub>1 \\<S>\\<^sub>2 =\n    {|(Wrapp X, Wrapp Y) | X Y p q. X |\\<in>| fPow \\<S>\\<^sub>1 \\<and> Y |\\<in>| fPow \\<S>\\<^sub>2 \\<and> p |\\<in>| X \\<and> q |\\<in>| Y \\<and> (p, q) |\\<in>| Q|}\"\n\nlemma Q_pow_fmember:\n  \"(X, Y) |\\<in>| Q_pow Q \\<S>\\<^sub>1 \\<S>\\<^sub>2 \\<longleftrightarrow> (\\<exists> p q. ex X |\\<in>| fPow \\<S>\\<^sub>1 \\<and> ex Y |\\<in>| fPow \\<S>\\<^sub>2 \\<and> p |\\<in>| ex X \\<and> q |\\<in>| ex Y \\<and> (p, q) |\\<in>| Q)\"\nproof -\n  let ?S = \"{(Wrapp X, Wrapp Y) | X Y p q. X |\\<in>| fPow \\<S>\\<^sub>1 \\<and> Y |\\<in>| fPow \\<S>\\<^sub>2 \\<and> p |\\<in>| X \\<and> q |\\<in>| Y \\<and> (p, q) |\\<in>| Q}\" \n  have \"?S \\<subseteq> map_prod Wrapp Wrapp ` fset (fPow \\<S>\\<^sub>1 |\\<times>| fPow \\<S>\\<^sub>2)\" by (auto simp flip: fmember_iff_member_fset)\n  from finite_subset[OF this] show ?thesis unfolding Q_pow_def\n    apply auto apply blast\n    by (meson FSet_Lex_Wrapper.exhaust_sel)\nqed\n\nlemma pair_automaton_det_lang_sound_complete:\n  \"pair_at_lang \\<G> Q = pair_at_lang (map_both ps_ta \\<G>) (Q_pow Q (\\<Q> (fst \\<G>)) (\\<Q> (snd \\<G>)))\" (is \"?LS = ?RS\")\nproof -\n  {fix s t assume \"(s, t) \\<in> ?LS\"\n    then obtain  p q where\n      res : \"p |\\<in>| ta_der (fst \\<G>) (term_of_gterm s)\"\n      \"q |\\<in>| ta_der (snd \\<G>) (term_of_gterm t)\" \"(p, q) |\\<in>| Q\"\n      by (auto simp: pair_at_lang_def gta_der_def)\n    from ps_rules_complete[OF this(1)] ps_rules_complete[OF this(2)] this(3)\n    have \"(s, t) \\<in> ?RS\" using fPow_iff ps_ta_states'\n      by (auto simp: pair_at_lang_def gta_der_def Q_pow_fmember)\n         force}\n  moreover\n  {fix s t assume \"(s, t) \\<in> ?RS\" then have \"(s, t) \\<in> ?LS\"\n      using ps_rules_sound\n      by (auto simp: pair_at_lang_def gta_der_def ps_ta_def Let_def Q_pow_fmember) blast}\n  ultimately show ?thesis by auto\nqed\n\nlemma pair_automaton_complement_sound_complete:\n  assumes \"partially_completely_defined_on \\<A> \\<F>\" and \"partially_completely_defined_on \\<B> \\<F>\"\n    and \"ta_det \\<A>\" and \"ta_det \\<B>\"\n  shows \"pair_at_lang (\\<A>, \\<B>) (\\<Q> \\<A> |\\<times>| \\<Q> \\<B> |-| Q) = gterms (fset \\<F>) \\<times> gterms (fset \\<F>) - pair_at_lang (\\<A>, \\<B>) Q\"\n  using assms unfolding partially_completely_defined_on_def pair_at_lang_def\n  apply (auto simp: gta_der_def)\n  apply (metis ta_detE)\n  apply fastforce\n  done\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Regular_Tree_Relations/Pair_Automaton.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631698328916, "lm_q2_score": 0.4921881357207956, "lm_q1q2_score": 0.2990846027062401}}
{"text": "theory flash21Rev imports flashPub\nbegin\nsection{*Main defintions*}\nlemma NI_FAckVsInv21:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_InvVsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_InvAck_1VsInv21:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by(cut_tac a1 a2 a3 a4, auto) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto \n qed\n  lemma NI_InvAck_1_HomeVsInv21:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_InvAck_2VsInv21:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Local_GetX_GetXVsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak1VsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak2VsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak3VsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX1VsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv21:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10VsInv21:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10_homeVsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX11VsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_GetVsInv21:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Local_Get_Nak1VsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak2VsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak3VsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put1VsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put2VsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put3VsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_PutVsInv21:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_Local_PutXAcksDoneVsInv21:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_NakVsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Nak_ClearVsInv21:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_Nak_HomeVsInv21:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_Remote_GetX_NakVsInv21:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_Nak_HomeVsInv21:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Remote_GetX_PutXVsInv21:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_PutX_HomeVsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Nak1VsInv21:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Remote_Get_Nak2VsInv21:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Put1VsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Put2VsInv21:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutVsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                     have allCases:\"formEval  ( eqn ( IVar ( Para ''InvMarked'' iInv1) )  ( Const true ))  s  \\<or>formEval   (neg ( eqn ( IVar ( Para ''InvMarked'' iInv1) )  ( Const true )) )  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume c1:\"formEval ( eqn ( IVar ( Para ''InvMarked'' iInv1) )  ( Const true ))  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1  c1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n\n    moreover\n                       {assume c1:\"formEval  (neg ( eqn ( IVar ( Para ''InvMarked'' iInv1) )  ( Const true )) )  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1  c1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n   ultimately have \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutXVsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_ReplaceVsInv21:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_ReplaceHomeVsInv21:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_ReplaceHomeShrVldVsInv21:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_ReplaceShrVldVsInv21:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_ShWbVsInv21:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_WbVsInv21:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_GetX_GetX1VsInv21:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_GetX_GetX2VsInv21:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_GetX_PutX1VsInv21:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_GetX_PutX2VsInv21:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_GetX_PutX3VsInv21:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_GetX_PutX4VsInv21:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_Get_GetVsInv21:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_Get_PutVsInv21:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_PutXVsInv21:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_ReplaceVsInv21:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Remote_GetVsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_I ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_GetXVsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_PutXVsInv21:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_ReplaceVsInv21:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma StoreVsInv21:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma StoreHomeVsInv21:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv21  iInv1 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash21Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6224593312018545, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.2990784365944514}}
{"text": "theory Nielson_VCGi\nimports Nielson_Hoare \"Vars\"\nbegin\n\nsubsection \"Optimized Verification Condition Generator\"\n\ntext\\<open>Annotated commands: commands where loops are annotated with invariants.\\<close>\n\ndatatype acom =\n  Askip                  (\"SKIP\") |\n  Aassign vname aexp     (\"(_ ::= _)\" [1000, 61] 61) |\n  Aseq   acom acom       (\"_;;/ _\"  [60, 61] 60) |\n  Aif bexp acom acom     (\"(IF _/ THEN _/ ELSE _)\"  [0, 0, 61] 61) |\n  Aconseq \"assn2*(vname set)\" \"assn2*(vname set)\" \"tbd * (vname set)\"  acom\n  (\"({_'/_'/_}/ CONSEQ _)\"  [0, 0, 0, 61] 61)|\n  Awhile \"(assn2*(vname set))*((state\\<Rightarrow>state)*(tbd*((vname set*(vname \\<Rightarrow> vname set)))))\" bexp acom  (\"({_}/ WHILE _/ DO _)\"  [0, 0, 61] 61)\n  \nnotation com.SKIP (\"SKIP\")\n\ntext\\<open>Strip annotations:\\<close>\n\nfun strip :: \"acom \\<Rightarrow> com\" where\n  \"strip SKIP = SKIP\" |\n  \"strip (x ::= a) = (x ::= a)\" |\n  \"strip (C\\<^sub>1;; C\\<^sub>2) = (strip C\\<^sub>1;; strip C\\<^sub>2)\" |\n  \"strip (IF b THEN C\\<^sub>1 ELSE C\\<^sub>2) = (IF b THEN strip C\\<^sub>1 ELSE strip C\\<^sub>2)\" |\n  \"strip ({_/_/_} CONSEQ C) = strip C\" |\n  \"strip ({_} WHILE b DO C) = (WHILE b DO strip C)\"\n  \n  \n  \ntext \"support of an expression\"\n\ndefinition supportE :: \"((char list \\<Rightarrow> nat) \\<Rightarrow> (char list \\<Rightarrow> int) \\<Rightarrow> nat)  \\<Rightarrow> string set\" where\n  \"supportE P = {x. \\<exists>l1 l2 s. (\\<forall>y. y \\<noteq> x \\<longrightarrow> l1 y = l2 y) \\<and> P l1 s \\<noteq> P l2 s}\"\n  \n  \nlemma expr_lupd: \"x \\<notin> supportE Q \\<Longrightarrow> Q (l(x:=n)) = Q l\"\n  by(simp add: supportE_def fun_upd_other fun_eq_iff)\n    (metis (no_types, lifting) fun_upd_def)\n\n \nfun varacom :: \"acom \\<Rightarrow> lvname set\" where\n  \"varacom (C\\<^sub>1;; C\\<^sub>2)= varacom C\\<^sub>1 \\<union> varacom C\\<^sub>2\"\n| \"varacom (IF b THEN C\\<^sub>1 ELSE C\\<^sub>2)= varacom C\\<^sub>1 \\<union> varacom C\\<^sub>2\"\n| \"varacom ({(P,_)/(Qannot,_)/_} CONSEQ C)= support P \\<union> varacom C \\<union> support Qannot\"\n| \"varacom ({((I,_),(S,(E,Es)))} WHILE b DO C) = support I \\<union> varacom C \"\n| \"varacom _ = {}\"\n     \n  \nfun varnewacom :: \"acom \\<Rightarrow> lvname set\" where\n  \"varnewacom (C\\<^sub>1;; C\\<^sub>2)= varnewacom C\\<^sub>1 \\<union> varnewacom C\\<^sub>2\"\n| \"varnewacom (IF b THEN C\\<^sub>1 ELSE C\\<^sub>2)= varnewacom C\\<^sub>1 \\<union> varnewacom C\\<^sub>2\"\n| \"varnewacom ({_/_/_} CONSEQ C)= varnewacom C\"\n| \"varnewacom ({(I,(S,(E,Es)))} WHILE b DO C) = varnewacom C\"\n| \"varnewacom _ = {}\"\n  \nlemma finite_varnewacom: \"finite (varnewacom C)\"\n  by (induct C) (auto)\n\n\n\nfun wf :: \"acom \\<Rightarrow> lvname set \\<Rightarrow> bool\" where\n  \"wf SKIP _ = True\" |\n  \"wf (x ::= a) _ = True\" |\n  \"wf (C\\<^sub>1;; C\\<^sub>2) S = (wf C\\<^sub>1 (S \\<union> varnewacom C\\<^sub>2) \\<and> wf C\\<^sub>2 S)\" |\n  \"wf (IF b THEN C\\<^sub>1 ELSE C\\<^sub>2) S = (wf C\\<^sub>1 S \\<and> wf C\\<^sub>2 S)\" |\n  \"wf ({_/(Qannot,_)/_} CONSEQ C) S = (finite (support Qannot) \\<and> wf C S)\" |\n  \"wf ({(_,(_,(_,Es)))} WHILE b DO C) S = ( wf C S)\"\n    \ntext\\<open>Weakest precondition from annotated commands:\\<close>\n\nfun preT :: \"acom \\<Rightarrow> tbd \\<Rightarrow> tbd\" where\n  \"preT SKIP e = e\" |\n  \"preT (x ::= a) e = (\\<lambda>s. e(s(x := aval a s)))\" |\n  \"preT (C\\<^sub>1;; C\\<^sub>2) e = preT C\\<^sub>1 (preT C\\<^sub>2 e)\" |\n  \"preT ({_/_/_} CONSEQ C) e = preT C e\" |\n  \"preT (IF b THEN C\\<^sub>1 ELSE C\\<^sub>2) e =\n  (\\<lambda>s. if bval b s then preT C\\<^sub>1 e s else preT C\\<^sub>2 e s)\" |\n  \"preT ({(_,(S,_))} WHILE b DO C) e = e o S\"\n  \n\nlemma preT_constant: \"preT C (%_. a) = (%_. a)\"\n  by(induct C, auto)\n\nlemma preT_linear: \"preT C (%s. k * e s) = (%s. k * preT C e s)\"\nby (induct C arbitrary: e, auto)\n  \nfun postQ :: \"acom \\<Rightarrow> state \\<Rightarrow> state\" where (* seems to be forward?! *)\n  \"postQ SKIP s = s\" |\n  \"postQ (x ::= a) s =  s(x := aval a s)\" |\n  \"postQ (C\\<^sub>1;; C\\<^sub>2) s = postQ C\\<^sub>2 (postQ C\\<^sub>1 s)\" |\n  \"postQ ({_/_/_} CONSEQ C) s = postQ C s\" |\n  \"postQ (IF b THEN C\\<^sub>1 ELSE C\\<^sub>2) s =\n  (if bval b s then postQ C\\<^sub>1 s else postQ C\\<^sub>2 s)\" |\n  \"postQ ({(_,(S,_))} WHILE b DO C) s = S s\"\n  \n  \n  \n(* function that, given a Command C and a set of variables \n  gives the set of variables, that Es depends on,\n  meaning a set S where\n  if s1 = s2 on S \\<longrightarrow> \\<forall>x:Es. postQ C s1 x = postQ C s2 x\n*)\nfun fune :: \"acom \\<Rightarrow> vname set \\<Rightarrow> vname set\" where\n  \"fune SKIP LV = LV\" |\n  \"fune (x ::= a) LV = LV \\<union> vars a\" |\n  \"fune (C\\<^sub>1;; C\\<^sub>2) LV = fune C\\<^sub>1 (fune C\\<^sub>2 LV)\" |\n  \"fune ({_/_/_} CONSEQ C) LV = fune C LV\" |\n  \"fune (IF b THEN C\\<^sub>1 ELSE C\\<^sub>2) LV = vars b \\<union> fune C\\<^sub>1 LV \\<union> fune C\\<^sub>2 LV\" |\n  \"fune ({(_,(S,(E,Es,SS)))} WHILE b DO C) LV = (\\<Union>x\\<in>LV. SS x)\"\n  \nlemma fune_mono: \"A \\<subseteq> B \\<Longrightarrow> fune C A \\<subseteq> fune C B\"\nproof(induct C arbitrary: A B)  \n  case (Awhile x1 x2 C)\n  obtain a b c d e f where a: \"x1 = (a,b,c,d,e)\" using prod_cases5 by blast\n  from Awhile show ?case unfolding a by(auto)\nqed (auto simp add: le_supI1 le_supI2)\n  \n  \nlemma TQ: \"preT C e s = e (postQ C s)\"\n  apply(induct C arbitrary: e s) by (auto) \n\n\n  \n  \n(* given a state, how often will a While loop be evaluated ? *)  \nfunction (domintros) times :: \"state \\<Rightarrow> bexp \\<Rightarrow> acom \\<Rightarrow> nat\" where\n  \"times s b C = (if bval b s then Suc (times (postQ C s) b C) else 0)\" \n   apply(auto) done\n\nlemma assumes I: \"I z s\" and\n  i:   \"\\<And>s z. I (Suc z) s \\<Longrightarrow> bval b s \\<and> I z (postQ C s)\"\n  and  ii:  \"\\<And>s. I 0 s \\<Longrightarrow> ~ bval b s\"\nshows times_z: \"times s b C = z\"\nproof -  \n  have \"I z s \\<Longrightarrow> times_dom (s, b, C) \\<and> times s b C = z\"\n  proof(induct z arbitrary: s)\n    case 0\n    have A: \"times_dom (s, b, C)\"\n      apply(rule times.domintros)\n      apply(simp add:  ii[OF 0] ) done\n    have B: \"times s b C = 0\"\n      using times.psimps[OF A] by(simp add:  ii[OF 0])\n    \n    show ?case using A B by simp\n  next\n    case (Suc z)\n    from i[OF Suc(2)] have bv: \"bval b s\"\n      and g:  \"I z (postQ C s)\" by simp_all\n    from Suc(1)[OF g] have p1: \"times_dom (postQ C s, b, C)\"\n      and p2: \"times (postQ C s) b C = z\" by simp_all\n    have A: \"times_dom (s, b, C)\" \n      apply(rule times.domintros) apply(rule p1) done\n    have B: \"times s b C = Suc z\" \n      using times.psimps[OF A] bv p2 by simp\n    show ?case using A B by simp\n  qed\n  \n  then show \"times s b C = z\" using I by simp\nqed\n\nfun postQz :: \"acom \\<Rightarrow> state \\<Rightarrow> nat \\<Rightarrow> state\" where\n  \"postQz C s 0 = s\" |\n  \"postQz C s (Suc n) =  (postQz C (postQ C s) n)\"\n  \nfun preTz :: \"acom \\<Rightarrow> tbd \\<Rightarrow> nat \\<Rightarrow> tbd\" where\n  \"preTz C e 0 = e\" |\n  \"preTz C e (Suc n) = preT C (preTz C e n)\"\n  \n  \n  \nlemma TzQ: \"preTz C e n s = e (postQz C s n)\"\n  by (induct n arbitrary: s, simp_all add: TQ)\n\n\n\ntext\\<open>Weakest precondition from annotated commands:\\<close>\n\n  (* if the annotated command contains no loops,\n  then the weakest precondition is just some mangled post condition\n  in the other case, \n  the weakest precondition is essentially the annotated invariant\n  of the first while loop, mangled somewhat by the commands\n  preceding the loop. *)\n\nfun pre :: \"acom \\<Rightarrow> assn2 \\<Rightarrow> assn2\" where\n  \"pre SKIP Q  = Q\" |\n  \"pre (x ::= a) Q = (\\<lambda>l s. Q l (s(x := aval a s)))\" |\n  \"pre (C\\<^sub>1;; C\\<^sub>2) Q  = pre C\\<^sub>1 (pre C\\<^sub>2 Q)\" |\n  \"pre ({(P',Ps)/_/_} CONSEQ C) Q = P'\" |\n  \"pre (IF b THEN C\\<^sub>1 ELSE C\\<^sub>2) Q =\n  (\\<lambda>l s. if bval b s then pre C\\<^sub>1 Q l s else pre C\\<^sub>2 Q l s)\" |\n  \"pre ({((I,Is),(S,(E,Es,SS)))} WHILE b DO C) Q = I\" \n  \n  \nfun qdeps :: \"acom \\<Rightarrow> vname set \\<Rightarrow> vname set\" where\n  \"qdeps SKIP LV  = LV\" |\n  \"qdeps (x ::= a) LV = LV \\<union> vars a\" | \n  \"qdeps (C\\<^sub>1;; C\\<^sub>2) LV  = qdeps C\\<^sub>1 (qdeps C\\<^sub>2 LV)\" |\n  \"qdeps ({(P',Ps)/_/_} CONSEQ C) _ = Ps\" | (* the variables P' depends on *)\n  \"qdeps (IF b THEN C\\<^sub>1 ELSE C\\<^sub>2) LV = vars b \\<union> qdeps C\\<^sub>1 LV \\<union> qdeps C\\<^sub>2 LV\" | \n  \"qdeps ({((I,Is),(S,(E,x,Es)))} WHILE b DO C) _ = Is\" (* the variables I depends on *) \n   \nlemma qdeps_mono: \"A \\<subseteq> B \\<Longrightarrow> qdeps C A \\<subseteq> qdeps C B\"\n  by (induct C arbitrary: A B, auto simp: le_supI1 le_supI2)\n  \nlemma supportE_if: \"supportE (\\<lambda>l s. if b s then A l s else B l s)\n  \\<subseteq> supportE A \\<union> supportE B\"\n  unfolding supportE_def apply(auto)\n  by metis+\n\nlemma supportE_preT: \"supportE (%l. preT C (e l)) \\<subseteq> supportE e\"\nproof(induct C arbitrary: e)\n  case (Aif b C1 C2 e)\n  show ?case\n    apply(simp)\n    apply(rule subset_trans[OF supportE_if])\n    using Aif by fast\nnext\n  case (Awhile A y C e)\n  obtain I S E x where A: \"A= (I,S,E,x)\" using prod_cases4 by blast\n  show ?case using A apply(simp) unfolding supportE_def\n    by blast\nnext\n  case (Aseq)\n  then show ?case by force\nqed (simp_all add: supportE_def, blast)\n\nlemma supportE_twicepreT: \"supportE (%l. preT C1 (preT C2 (e l))) \\<subseteq> supportE e\"\n  by (rule subset_trans[OF supportE_preT supportE_preT])\n\n\n\nlemma supportE_preTz: \"supportE (%l. preTz C (e l) n) \\<subseteq> supportE e\"\nproof (induct n) \n  case (Suc n)\n  show ?case  \n    apply(simp)\n    apply(rule subset_trans[OF supportE_preT]) \n    by fact \nqed simp\n\n\nlemma supportE_preTz_Un: (* like in support_wpw_Un *)\n  \"supportE (\\<lambda>l. preTz C (e l) (l x)) \\<subseteq> insert x (UN n. supportE (\\<lambda>l. preTz C (e l) n))\"\n  apply(auto simp add: supportE_def subset_iff)\n  apply metis\n  done\n\nlemma support_eq: \"support (\\<lambda>l s. l x = E l s) \\<subseteq> supportE E \\<union> {x}\"\n  unfolding support_def supportE_def \n  apply(auto)\n   apply blast\n  by metis\n\n\nlemma support_impl_in: \"G e \\<longrightarrow> support (\\<lambda>l s.  H e l s) \\<subseteq> T\n  \\<Longrightarrow> support (\\<lambda>l s. G e \\<longrightarrow>  H e l s) \\<subseteq> T\"\n  unfolding support_def apply(auto)\n   apply blast+ done\n\nlemma support_supportE: \"\\<And>P e. support (\\<lambda>l s.  P (e l) s) \\<subseteq> supportE e\"\n  unfolding support_def supportE_def\n  apply(rule subsetI)\n  apply(simp)\nproof (clarify, goal_cases)\n  case (1 P e x l1 l2 s)\n  have P: \"\\<forall>s. e l1 s = e l2 s \\<Longrightarrow> e l1 = e l2\" by fast\n  show \"\\<exists>l1 l2. (\\<forall>y. y \\<noteq> x \\<longrightarrow> l1 y = l2 y) \\<and> (\\<exists>s. e l1 s \\<noteq> e l2 s)\"\n    apply(rule exI[where x=l1])\n    apply(rule exI[where x=l2])\n    apply(safe)\n    using 1 apply blast\n    apply(rule ccontr)\n    apply(simp) \n    using 1(2) P by force            \nqed \n\nlemma support_pre: \"support (pre C Q) \\<subseteq> support Q \\<union> varacom C\"\nproof (induct C arbitrary: Q)\n  case (Awhile A b C Q)\n  obtain I2 S E Es SS where A: \"A= (I2,(S,(E,Es,SS)))\" using prod_cases5 by blast \n  obtain I Is where \"I2=(I,Is)\" by fastforce\n  note A=this A\n  have support_inv: \"\\<And>P. support (\\<lambda>l s. P s) = {}\"\n    unfolding support_def by blast  \n  show ?case unfolding A  by(auto)\nnext\n  case (Aseq C1 C2)\n  then show ?case by(auto)\nnext\n  case (Aif x C1 C2 Q)\n  have s1: \"support (\\<lambda>l s. bval x s \\<longrightarrow> pre C1 Q l s) \\<subseteq> support Q \\<union> varacom C1\"\n    apply(rule subset_trans[OF support_impl]) by(rule Aif)\n  have s2: \"support (\\<lambda>l s. ~ bval x s \\<longrightarrow> pre C2 Q l s) \\<subseteq> support Q \\<union> varacom C2\"\n    apply(rule subset_trans[OF support_impl]) by(rule Aif)\n  \n  show ?case apply(simp)\n    apply(rule subset_trans[OF support_and]) \n    using s1 s2 by blast    \nnext\n  case (Aconseq x1 x2 x3 C)\n  obtain a b c d e f where \"x1=(a,b)\" \"x2=(c,d)\" \"x3=(e,f)\" by force\n  with Aconseq show ?case by auto  \nqed (auto simp add: support_def) \n\nlemma finite_support_pre: \"finite (support Q)  \\<Longrightarrow> finite (varacom C) \\<Longrightarrow>  finite (support (pre C Q))\"\n  using finite_subset support_pre finite_UnI by metis \n\n\nfun time :: \"acom \\<Rightarrow> tbd\" where\n  \"time SKIP = (%s. Suc 0)\" |\n  \"time (x ::= a) = (%s. Suc 0)\" |\n  \"time (C\\<^sub>1;; C\\<^sub>2) = (%s. time C\\<^sub>1 s + preT C\\<^sub>1 (time C\\<^sub>2) s)\" |\n  \"time ({_/_/(e,es)} CONSEQ C) = e\" |\n  \"time (IF b THEN C\\<^sub>1 ELSE C\\<^sub>2) =\n  (\\<lambda>s. if bval b s then 1 + time C\\<^sub>1 s else 1 + time C\\<^sub>2 s)\" |\n  \"time ({(_,(E',(E,x)))} WHILE b DO C) = E\"\n   \n   \n(* the set of variables, i need to know about, i.e. s1 and s2 have to agree on \n  s.th. time C s1 = time C s2 *)    \nfun kdeps :: \"acom \\<Rightarrow> vname set\" where\n  \"kdeps SKIP = {}\" |\n  \"kdeps (x ::= a) = {}\" |\n  \"kdeps (C\\<^sub>1;; C\\<^sub>2) = kdeps C\\<^sub>1 \\<union> fune C\\<^sub>1 (kdeps C\\<^sub>2)\" |\n  \"kdeps (IF b THEN C\\<^sub>1 ELSE C\\<^sub>2) =  vars b \\<union> kdeps C\\<^sub>1 \\<union> kdeps C\\<^sub>2\" |\n  \"kdeps ({(_,(E',(E,Es,SS)))} WHILE b DO C) = Es\" |\n  \"kdeps ({_/_/(e,es)} CONSEQ C) = es\"  \n     \n     \nlemma supportE_single: \"supportE (\\<lambda>l s. P) = {}\" \n  unfolding supportE_def by blast\n\n\nlemma supportE_plus: \"supportE (\\<lambda>l s. e1 l s + e2 l s) \\<subseteq> supportE e1 \\<union> supportE e2\" \n  unfolding supportE_def apply(auto)\n  by metis \n\nlemma supportE_Suc: \"supportE (\\<lambda>l s. Suc (e1 l s)) = supportE e1\"\n  unfolding supportE_def by (auto) \n\n\nlemma supportE_single2: \"supportE (\\<lambda>l . P) = {}\" \n  unfolding supportE_def by blast\n\nlemma supportE_time: \"supportE (\\<lambda>l. time C) = {}\"\n  using supportE_single2 by simp   \n\nlemma \"\\<And>s. (\\<forall>l. I (l(x:=0)) s) = (\\<forall>l. l x = 0 \\<longrightarrow> I l s)\"\n  apply(auto) \n  by (metis fun_upd_triv)\n\nlemma \"\\<And>s. (\\<forall>l. I (l(x:=Suc (l x))) s) = (\\<forall>l. (\\<exists>n. l x = Suc n) \\<longrightarrow> I l s)\"\n  apply(auto) \nproof (goal_cases)\n  case (1 s l n)\n  then have \"\\<And>l. I (l(x := Suc (l x))) s\" by simp\n  from this[where l=\"l(x:=n)\"]\n  have \"I ((l(x:=n))(x := Suc ((l(x:=n)) x))) s\" by simp\n  then show ?case using 1(2) apply(simp) \n    by (metis fun_upd_triv)\nqed \n\ntext\\<open>Verification condition:\\<close>\n\n     \ndefinition funStar where \"funStar f = (%x. {y. (x,y)\\<in>{(x,y). y\\<in>f x}\\<^sup>*})\"\n  \nlemma funStart_prop1: \"x \\<in> (funStar f) x\" unfolding funStar_def by auto\nlemma funStart_prop2: \"f x \\<subseteq> (funStar f) x\" unfolding funStar_def by auto\n\nfun vc :: \"acom \\<Rightarrow> assn2 \\<Rightarrow> vname set \\<Rightarrow> vname set \\<Rightarrow> bool\" where\n  \"vc SKIP Q _ _ = True\" |\n  \"vc (x ::= a) Q _ _ = True\" |\n  \"vc (C\\<^sub>1 ;; C\\<^sub>2) Q LVQ LVE = ((vc C\\<^sub>1 (pre C\\<^sub>2 Q) (qdeps C\\<^sub>2 LVQ) (fune C\\<^sub>2 LVE \\<union> kdeps C\\<^sub>2)) \\<and> (vc C\\<^sub>2 Q LVQ LVE) )\" |\n  \"vc (IF b THEN C\\<^sub>1 ELSE C\\<^sub>2) Q LVQ LVE = (vc C\\<^sub>1 Q LVQ LVE \\<and> vc C\\<^sub>2 Q LVQ LVE)\" |  \n  \"vc ({(P',Ps)/(Q,Qs)/(e',es)} CONSEQ C) Q' LVQ LVE = (vc C Q Qs LVE  \\<comment> \\<open>evtl \\<open>LV\\<close> weglassen - glaub eher nicht\\<close>\n              \\<and> (\\<forall>s1 s2 l. (\\<forall>x\\<in>Ps. s1 x=s2 x) \\<longrightarrow> P' l s1 = P' l s2)    \\<comment> \\<open>annotation \\<open>Ps\\<close> (the set of variables \\<open>P'\\<close> depends on) is correct\\<close>\n              \\<and> (\\<forall>s1 s2 l. (\\<forall>x\\<in>Qs. s1 x=s2 x) \\<longrightarrow> Q l s1 = Q l s2)    \\<comment> \\<open>annotation \\<open>Qs\\<close> (the set of variables \\<open>Q\\<close> depends on) is correct\\<close>\n              \\<and> (\\<forall>s1 s2. (\\<forall>x\\<in>es. s1 x=s2 x) \\<longrightarrow> e' s1 = e' s2)          \\<comment> \\<open>annotation \\<open>es\\<close> (the set of variables \\<open>e'\\<close> depends on) is correct\\<close>\n              \\<and> (\\<exists>k>0. (\\<forall>l s. P' l s \\<longrightarrow> time C s \\<le> k * e' s  \\<and> (\\<forall>t. \\<exists>l'. (pre C Q) l' s \\<and> ( Q l' t \\<longrightarrow> Q' l t) ))))\" |\n  \n  \"vc ({((I,Is),(S,(E,es,SS)))} WHILE b DO C) Q LVQ LVE = ((\\<forall>s1 s2 l. (\\<forall>x\\<in>Is. s1 x = s2 x) \\<longrightarrow> I l s1 = I l s2)  \\<comment> \\<open>annotation \\<open>Is\\<close> is correct\\<close>\n        \\<and> (\\<forall>y\\<in>LVE \\<union> LVQ. (let Ss=SS y in (\\<forall>s1 s2. (\\<forall>x\\<in>Ss. s1 x = s2 x) \\<longrightarrow> (S s1) y = (S s2) y)))                   \\<comment> \\<open>annotation \\<open>SS\\<close> is correct, for only one step\\<close>\n        \\<and> (\\<forall>s1 s2. (\\<forall>x\\<in>es. s1 x=s2 x) \\<longrightarrow> E s1 = E s2)                                \\<comment> \\<open>annotation \\<open>es\\<close> (the set of variables \\<open>E\\<close> depends on) is correct\\<close>\n  \\<and> (\\<forall>l s. (I l s \\<and> bval b s \\<longrightarrow> pre C I l s \\<and>   E s \\<ge> 1 + preT C E s + time C s\n  \\<and> (\\<forall>v\\<in>(\\<Union>y\\<in>LVE \\<union> LVQ. (funStar SS) y). (S s) v = (S (postQ C s)) v) ) \\<and>\n  (I l s \\<and> \\<not> bval b s \\<longrightarrow> Q l s \\<and> E s \\<ge> 1 \\<and> (\\<forall>v\\<in>(\\<Union>y\\<in>LVE \\<union> LVQ. (funStar SS) y). (S s) v  = s v)) ) \\<and>\n  vc C I Is (es \\<union> (\\<Union>y\\<in>LVE. (funStar SS) y)))\"\n     \nsubsubsection \\<open>Soundness:\\<close>\n\nabbreviation \"preSet U C l s == (Ball U (%u. case u of (x,e,v) \\<Rightarrow> l x = preT C e s))\"\nabbreviation \"postSet U l s == (Ball U (%u. case u of (x,e,v) \\<Rightarrow> l x = e s))\"\n\n\nfun ListUpdate where\n  \"ListUpdate f [] l = f\"\n| \"ListUpdate f ((x,e,v)#xs) q = (ListUpdate f xs q)(x:=q e x)\"\n\nlemma allg: \n  assumes U2: \"\\<And>l s n x. x\\<in> fst ` upds \\<Longrightarrow> A (l(x := n))  = A l\"\n  shows\n    \"fst ` set xs \\<subseteq> fst ` upds \\<Longrightarrow> A (ListUpdate l'' xs q) = A l''\" \nproof (induct xs) \n  case (Cons a xs)\n  obtain x e v where axe: \"a = (x,e,v)\"\n    using prod_cases3 by blast \n  have \"A (ListUpdate l'' (a # xs) q) \n    = A ((ListUpdate l'' xs q)(x := q e x))  \" unfolding axe by(simp)\n  also have\n    \"\\<dots> =  A  (ListUpdate l'' xs q)  \"\n    apply(rule U2)\n    using Cons axe by force\n  also have \"\\<dots> = A l'' \"\n    using Cons by force\n  finally show ?case .\nqed simp  \n\nfun ListUpdateE where\n  \"ListUpdateE f []   = f\"\n| \"ListUpdateE f ((x,e,v)#xs)  = (ListUpdateE f xs  )(x:=e)\"\n\nlemma ListUpdate_E: \"ListUpdateE f xs = ListUpdate f xs (%e x. e)\"\n  apply(induct xs) apply(simp_all)\n  subgoal for a xs apply(cases a) apply(simp) done\n  done\nlemma allg_E: fixes A::assn2\n    assumes \n   \" (\\<And>l s n x. x \\<in> fst ` upds \\<Longrightarrow> A (l(x := n)) = A l)\" \"fst ` set xs \\<subseteq> fst ` upds\"\n   shows \"A (ListUpdateE f xs) = A f\"\nproof -\n  have \" A (ListUpdate f xs (%e x. e)) = A f\"\n    apply(rule allg) \n    apply fact+ done\n  then show ?thesis by(simp only: ListUpdate_E)\nqed \n\nlemma ListUpdateE_updates: \"distinct (map fst xs) \\<Longrightarrow> x \\<in> set xs \\<Longrightarrow> ListUpdateE l'' xs (fst x) = fst (snd x)\"\nproof (induct xs)\n  case Nil\n  then show ?case apply(simp) done\nnext\n  case (Cons a xs)\n  show ?case\n  proof (cases \"fst a = fst x\")\n    case True\n    then obtain y e v where a: \"a=(y,e,v)\"\n      using prod_cases3 by blast \n    with True have fstx: \"fst x=y\" by simp\n    from Cons(2,3) fstx  a have a2: \"x=a\"\n      by force\n    show ?thesis unfolding a2 a by(simp)\n  next\n    case False\n    with Cons(3) have A: \"x\\<in>set xs\" by auto\n    then obtain y e v where a: \"a=(y,e,v)\"\n      using prod_cases3 by blast \n    from Cons(2) have B: \"distinct (map fst xs)\" by simp \n    from Cons(1)[OF B A] False\n      show ?thesis unfolding a by(simp)  \n  qed \nqed\n\n\nlemma ListUpdate_updates: \"x \\<in> fst ` (set xs) \\<Longrightarrow> ListUpdate l'' xs (%e. l) x = l x\"\nproof(induct xs)\n  case Nil\n  then show ?case by(simp)\nnext\n  case (Cons a xs)\n  obtain q p v where axe: \"a = (p,q,v)\"\n      using prod_cases3 by blast \n  from Cons show ?case unfolding axe\n    apply(cases \"x=p\")  \n    by(simp_all)\nqed\n  \nabbreviation \"lesvars xs == fst ` (set xs)\"\n  \nfun preList where\n  \"preList [] C l s = True\"\n| \"preList ((x,(e,v))#xs) C l s = (l x = preT C e s \\<and> preList xs C l s)\"\n      \n  \nlemma preList_Seq: \"preList upds (C1;; C2) l s = preList (map (\\<lambda>(x, e, v). (x, preT C2 e, fune C2 v)) upds) C1 l s\"\nproof (induct upds)\n  case Nil\n  then show ?case by simp\nnext\n  case (Cons a xs)\n  obtain y e v where a: \"a=(y,(e,v))\"\n    using prod_cases3 by blast \n  from Cons show ?case unfolding a by (simp)\nqed\n\n\n\nlemma preSetpreList: \"preList xs C l s \\<Longrightarrow>  preSet (set xs) C l s\"\nproof (induct xs) \n  case (Cons a xs)\n  obtain y e v where a: \"a=(y,(e,v))\"\n    using prod_cases3 by blast \n  from Cons show ?case unfolding a\n    by(simp)\nqed simp\n\n\n(* surprise. but makes sense, if the clauses are contradictory on the \n    left side, so are they on the right side *)\nlemma preSetpreList_eq: \"preList xs C l s = preSet (set xs) C l s\"\nproof (induct xs) \n  case (Cons a xs)\n  obtain y e v where a: \"a=(y,(e,v))\"\n    using prod_cases3 by blast \n  from Cons show ?case unfolding a\n    by(simp)\nqed simp  \n\n\nfun postList where\n  \"postList []  l s = True\"\n| \"postList ((x,e,v)#xs)  l s = (l x = e s \\<and> postList xs l s)\"\n\nlemma \"postList xs l s = (foldr (\\<lambda>(x,e,v) acc l s. l x = e s \\<and> acc l s) xs (%l s. True)) l s\" \napply(induct xs) apply(simp) by (auto)  \n  \nlemma support_postList: \"support (postList xs) \\<subseteq> lesvars xs\"\nproof (induct xs)    \n  case (Cons a xs)\n  obtain y e v where a: \"a=(y,(e,v))\"\n    using prod_cases3 by blast \n  from Cons show ?case unfolding a\n    apply(simp) apply(rule subset_trans[OF support_and])\n    apply(rule Un_least)\n    subgoal apply(rule subset_trans[OF support_eq])\n      using supportE_twicepreT subset_trans  supportE_single2 by simp\n    subgoal by(auto)\n      done   \nqed simp\n  \n  \n  \nlemma postList_preList: \"postList (map (\\<lambda>(x, e, v). (x, preT C2 e, fune C2 v)) upds) l s = preList upds C2 l s\"\nproof (induct upds) \n  case (Cons a xs)\n  obtain y e v where a: \"a=(y,(e,v))\"\n    using prod_cases3 by blast \n  from Cons show ?case unfolding a\n    by(simp)\nqed simp\n  \nlemma postSetpostList: \"postList xs l s \\<Longrightarrow>  postSet (set xs) l s\"\nproof (induct xs) \n  case (Cons a xs)\n  obtain y e v where a: \"a=(y,(e,v))\"\n    using prod_cases3 by blast \n  from Cons show ?case unfolding a\n    by(simp)\nqed simp\n  \n\nlemma postListpostSet: \"postSet (set xs) l s \\<Longrightarrow> postList xs l s\"\nproof (induct xs) \n  case (Cons a xs)\n  obtain y e v where a: \"a=(y,(e,v))\"\n    using prod_cases3 by blast \n  from Cons show ?case unfolding a\n    by(simp)\nqed simp\n\nlemma postListpostSet2: \" postList xs l s = postSet (set xs) l s \"\n  using postListpostSet postSetpostList by metis\n\n\n\nlemma ListAskip: \"preList xs Askip l s = postList xs  l s\"\n  apply(induct xs)\n   apply(simp) by force\n\nlemma SetAskip: \"preSet U Askip l s = postSet U l s\"\nby simp\n\nlemma ListAassign: \"preList upds (Aassign x1 x2) l s = postList upds l (s[x2/x1])\"\n  apply(induct upds)\n   apply(simp) by force\n\nlemma SetAassign: \"preSet U (Aassign x1 x2) l s = postSet U l (s[x2/x1])\"\nby simp\n\n\nlemma ListAconseq: \"preList upds (Aconseq x1 x2 x3 C) l s = preList upds C l s\"\n  apply(induct upds)\n   apply(simp) by force\n\nlemma SetAconseq: \"preSet U (Aconseq x1 x2 x3 C) l s = preSet U C l s\"\nby simp\n\nlemma ListAif1: \"bval b s \\<Longrightarrow> preList upds (IF b THEN C1 ELSE C2) l s = preList upds C1 l s\"\n  apply(induct upds)\n   apply(simp) by force\nlemma SetAif1: \"bval b s \\<Longrightarrow> preSet upds (IF b THEN C1 ELSE C2) l s = preSet upds C1 l s\"\n  apply(simp) done\nlemma ListAif2: \"~ bval b s \\<Longrightarrow> preList upds (IF b THEN C1 ELSE C2) l s = preList upds C2 l s\"\n  apply(induct upds)\n   apply(simp) by force\n\nlemma SetAif2: \"~ bval b s \\<Longrightarrow> preSet upds (IF b THEN C1 ELSE C2) l s = preSet upds C2 l s\"\n  apply(simp) done\n\ndefinition K where \"K C LVQ Q == (\\<forall>l s1 s2. s1 = s2 on qdeps C LVQ \\<longrightarrow> pre C Q l s1 = pre C Q l s2)\"\n  \n\ndefinition K2 where \"K2 C e Es Q == (\\<forall>s1 s2. s1 = s2 on fune C Es \\<longrightarrow> preT C e s1 = preT C e s2)\"\n  \ndefinition K3 where \"K3 upds C Q = (\\<forall>(a,b,c)\\<in>set upds. K2 C b c Q)\"\ndefinition K4 where \"K4 upds LV C Q = (K C LV Q \\<and> K3 upds C Q \\<and> (\\<forall>s1 s2. s1 = s2 on kdeps C \\<longrightarrow> time C s1 = time C s2))\"\n\nlemma k4If: \"K4 upds LVQ C1 Q \\<Longrightarrow> K4 upds LVQ C2 Q \\<Longrightarrow> K4 upds LVQ (IF b THEN C1 ELSE C2) Q\"    \nproof -\n  have fl: \"\\<And>A B s1 s2. A \\<subseteq> B \\<Longrightarrow> s1 = s2 on B \\<Longrightarrow> s1 = s2 on A\" by auto\n  assume \"K4 upds LVQ C1 Q\" \"K4 upds LVQ C2 Q\"\n  then show \"K4 upds LVQ (IF b THEN C1 ELSE C2) Q\"\n    unfolding K4_def K_def K3_def K2_def using bval_eq_if_eq_on_vars fl apply auto\n       apply blast+ done\nqed\n   \n\nsubsubsection \"Soundness\"\n  \nlemma vc_sound: \"vc C Q LVQ LVE \\<Longrightarrow> finite (support Q)\n  \\<Longrightarrow> fst ` (set upds) \\<inter> varacom C = {} \\<Longrightarrow> distinct (map fst upds)\n  \\<Longrightarrow> finite (varacom C) \n  \\<Longrightarrow> (\\<forall>l s1 s2. s1 = s2 on LVQ \\<longrightarrow> Q l s1 = Q l s2)\n  \\<Longrightarrow> (\\<forall>l s1 s2. s1 = s2 on LVE \\<longrightarrow> postList upds l s1 = postList upds l s2)\n  \\<Longrightarrow> (\\<forall>(a,b,c)\\<in>set upds. (\\<forall>s1 s2. s1 = s2 on c \\<longrightarrow> b s1 = b s2))             \\<comment> \\<open>\\<open>c\\<close> are really the variables \\<open>b\\<close> depends on\\<close>\n  \\<Longrightarrow> (\\<Union>(a,b,c)\\<in>set upds. c) \\<subseteq> LVE                                     \\<comment> \\<open>in \\<open>LV\\<close> are all the variables that the expressions in \\<open>upds\\<close> depend on\\<close>\n  \\<Longrightarrow> \\<turnstile>\\<^sub>1 {%l s. pre C Q l s \\<and> preList upds C l s} strip C { time C \\<Down> %l s. Q l s \\<and> postList upds l s}\n  \\<and> ((\\<forall>l s. pre C Q l s \\<longrightarrow> Q l (postQ C s)) \\<and>  K4 upds LVQ C Q)\"\nproof(induction C arbitrary: Q upds LVE LVQ)    \n  case (Askip Q upds)\n  then show ?case unfolding K4_def K_def K3_def K2_def\n    apply(auto)\n    apply(rule weaken_post[where Q=\"%l s. Q l s \\<and> preList upds Askip l s\"])\n     apply(simp add: Skip)  using ListAskip    \n    by fast\nnext\n  case (Aassign x1 x2 Q upds)\n  then show ?case unfolding K_def apply(safe) apply(auto simp add: Assign)[1]\n     apply(rule weaken_post[where Q=\"%l s. Q l s \\<and> postList upds l s\"]) \n      apply(simp only: ListAassign)\n      apply(rule Assign) apply simp\n     apply(simp only: postQ.simps pre.simps) apply(auto)  \n        unfolding K4_def K2_def K3_def K_def by (auto)\nnext\n  case (Aif b C1 C2 Q upds ) \n  from Aif(3) have 1: \"vc C1 Q LVQ LVE\" and 2: \"vc C2 Q LVQ LVE\" by auto\n  have T: \"\\<And>l s. pre C1 Q l s \\<Longrightarrow> bval b s \\<Longrightarrow> Q l (postQ C1 s)\"\n      and kT: \"K4 upds LVQ C1 Q\"\n    using Aif(1)[OF 1 Aif(4) _ Aif(6)] Aif(5-11) by auto \n  have F: \"\\<And>l s. pre C2 Q l s \\<Longrightarrow> \\<not> bval b s \\<Longrightarrow> Q l (postQ C2 s)\"\n    and kF: \"K4 upds LVQ C2 Q\"\n    using Aif(2)[OF 2 Aif(4) _ Aif(6)] Aif(5-11) by auto\n\n  show ?case apply(safe)\n    subgoal\n      apply(simp)\n     apply(rule If2[where e=\"\\<lambda>a. if bval b a then  time C1 a else time C2 a\"])\n    subgoal\n      apply(simp cong: rev_conj_cong)\n      apply(rule ub_cost[where e'=\"time C1\"])\n       apply(simp) apply(auto)[1]\n      apply(rule strengthen_pre[where P=\"%l s. pre C1 Q l s \\<and> preList upds C1 l s\"]) \n        using ListAif1\n       apply fast\n        apply(rule Aif(1)[THEN conjunct1])\n          using Aif\n           apply(auto)\n      done\n    subgoal \n      apply(simp cong: rev_conj_cong)\n      apply(rule ub_cost[where e'=\"time C2\"])  (* k=1 and *)\n       apply(simp) apply(auto)[1]\n      apply(rule strengthen_pre[where P=\"%l s. pre C2 Q l s \\<and> preList upds C2 l s\"])\n        using ListAif2\n       apply fast\n      apply(rule Aif(2)[THEN conjunct1])\n          using Aif\n           apply(auto)\n          done\n        by simp\n    using T F kT kF  by (auto intro: k4If)  \nnext\n  case (Aconseq P'2 Qannot2 eannot2 C Q upds) \n  obtain P' Ps where [simp]: \"P'2 = (P',Ps)\" by fastforce\n  obtain Qannot Q's where [simp]: \"Qannot2 = (Qannot,Q's)\" by fastforce\n  obtain eannot es where [simp]: \"eannot2 = (eannot,es)\" by fastforce\n    \n  have ih0: \"finite (support Qannot)\" using Aconseq(3,6) by simp\n  \n  from \\<open>vc ({P'2/Qannot2/eannot2} CONSEQ C) Q LVQ LVE\\<close>\n  obtain k where k0: \"k>0\" and ih1: \"vc C Qannot Q's LVE\"\n    and ih2: \" (\\<forall>l s. P' l s \\<longrightarrow>  time C s \\<le> k * eannot s \\<and> (\\<forall>t. \\<exists>l'. pre C Qannot l' s \\<and> (Qannot l' t \\<longrightarrow> Q l t)))\"\n    and pc: \"(\\<forall>s1 s2 l. (\\<forall>x\\<in>Ps. s1 x=s2 x) \\<longrightarrow> P' l s1 = P' l s2)\"\n    and qc: \"(\\<forall>s1 s2 l. (\\<forall>x\\<in>Q's. s1 x=s2 x) \\<longrightarrow> Qannot l s1 = Qannot l s2)\"\n    and ec: \"(\\<forall>s1 s2. (\\<forall>x\\<in>es. s1 x=s2 x) \\<longrightarrow> eannot s1 = eannot s2)\"  \n    by auto\n  have  k: \"\\<turnstile>\\<^sub>1 {\\<lambda>l s. pre C Qannot l s \\<and> preList upds C l s} strip C { time C \\<Down> \\<lambda>l s. Qannot l s \\<and> postList upds l s}\n    \\<and> ((\\<forall>l s. pre C Qannot l s \\<longrightarrow> Qannot l (postQ C s)) \\<and> K4 upds Q's C Qannot)\" \n    apply(rule Aconseq(1)) using Aconseq(2-10) by auto \n      \n  note ih=k[THEN conjunct1] and ihsnd=k[THEN conjunct2]\n\n  show ?case apply(simp, safe)\n     apply(rule conseq[where e=\"time C\" and P=\"\\<lambda>l s. pre C Qannot l s \\<and> preList upds C l s\" and Q=\"%l s. Qannot l s \\<and> postList upds l s\"])\n      prefer 2\n      apply(rule ih) \n    subgoal apply(rule exI[where x=k])\n    proof (safe, goal_cases)\n      case (1)\n      with k0 show ?case by auto\n    next      \n      case (2 l s)\n      then show ?case using ih2 by simp\n    next\n      case (3 l s t) \n      have finupds: \"finite (set upds)\" by simp\n      {\n        fix l s n x\n        assume \"x \\<in> fst ` (set upds)\"\n        then have \"x \\<notin> support (pre C Qannot)\" using Aconseq(4) support_pre by auto\n        from assn2_lupd[OF this] have \"pre C Qannot (l(x := n))  = pre C Qannot l\" .                \n      } note U2=this \n      {\n        fix l s n x\n        assume \"x \\<in> fst ` (set upds)\"\n        then have \"x \\<notin> support Qannot\" using Aconseq(4) by auto\n        from assn2_lupd[OF this] have \"Qannot (l(x := n))  = Qannot l\" .\n      } note K2=this  \n                           \n      from ih2 3(1) have *: \"(\\<exists>l'. pre C Qannot l' s \\<and> (Qannot l' t \\<longrightarrow> Q l t))\" by simp\n      obtain l' where i': \"pre C Qannot l' s\" and ii': \"(Qannot l' t \\<longrightarrow> Q l t)\" \n        and lxlx: \"\\<And>x. x\\<in> fst ` (set upds) \\<Longrightarrow> l' x = l x\" \n      proof (goal_cases)\n        case 1\n        from * obtain l'' where i': \"pre C Qannot l'' s\" and ii': \"(Qannot l'' t \\<longrightarrow> Q l t)\" \n          by blast\n        \n        note allg=allg[where q=\"%e x. l x\"]\n        \n        have \"pre C Qannot (ListUpdate l'' upds (\\<lambda>e. l))  = pre C Qannot l''  \"\n          apply(rule allg[where ?upds=\"set upds\"]) apply(rule U2) apply fast   by fast\n        with i' have U: \"pre C Qannot (ListUpdate l'' upds (\\<lambda>e. l)) s\" by simp\n        \n        have \"Qannot (ListUpdate l'' upds (\\<lambda>e. l)) = Qannot l''\"\n          apply(rule allg[where ?upds=\"set upds\"]) apply(rule K2) apply fast  by fast\n                \n        then have K: \"(%l' s. Qannot l' t \\<longrightarrow> Q l t) (ListUpdate l'' upds (\\<lambda>e. l)) s = (%l' s. Qannot l' t \\<longrightarrow> Q l t) l'' s\"\n          by simp\n        with ii' have K: \"(Qannot (ListUpdate l'' upds (\\<lambda>e. l)) t \\<longrightarrow> Q l t)\" by simp\n        \n        {\n          fix x\n          assume as: \"x \\<in> fst ` (set upds)\" \n          have \"ListUpdate l'' upds (\\<lambda>e. l) x = l x\"\n            apply(rule ListUpdate_updates)\n            using as   by fast\n        } note kla=this        \n        \n        show \"thesis\"\n          apply(rule 1)\n            apply(fact U)\n           apply(fact K)\n          apply(fact kla)\n          done\n      qed \n      \n      let ?upds' = \"set (map (%(x,e,v). (x,preT C e s,fune C v)) upds)\"\n      have \"finite ?upds'\" by simp \n      define xs where \"xs = map (%(x,e,v). (x,preT C e s,fune C v)) upds\"\n      then have \"set xs= ?upds'\" by simp\n                                \n      have \"pre C Qannot (ListUpdateE l' xs)  = pre C Qannot l' \" \n        apply(rule allg_E[where ?upds=\"?upds'\"]) apply(rule U2)  \n         apply force   unfolding xs_def by simp\n      with i' have U: \"pre C Qannot (ListUpdateE l' xs ) s\" by simp\n      \n      have \"Qannot (ListUpdateE l' xs) = Qannot l' \"\n          apply(rule allg_E[where ?upds=\"?upds'\"]) apply(rule K2) apply force unfolding xs_def by auto\n        then have K: \"(%l' s. Qannot l' t \\<longrightarrow> Q l t) (ListUpdateE l' xs) s = (%l' s. Qannot l' t \\<longrightarrow> Q l t) l' s\"\n          by simp\n        with ii' have K: \"(Qannot (ListUpdateE l' xs) t \\<longrightarrow> Q l t)\" by simp\n                  \n        \n      have xs_upds: \"map fst xs = map fst upds\"\n          unfolding xs_def by auto\n      \n      have grr: \"\\<And>x. x \\<in> ?upds' \\<Longrightarrow> ListUpdateE l' xs (fst x) = fst (snd x)\" apply(rule ListUpdateE_updates)\n         apply(simp only: xs_upds) using Aconseq(5) apply simp\n          unfolding xs_def apply(simp) done\n      show ?case\n        apply(rule exI[where x=\"ListUpdateE l' xs\"]) \n        apply(safe)\n        subgoal by fact\n        subgoal apply(rule preListpreSet)   proof (safe,goal_cases)\n          case (1 x e v)\n          then have \"(x, preT C e s, fune C v) \\<in> ?upds'\"  \n            by force\n          from grr[OF this, simplified]\n          show ?case .\n         \n          qed \n        subgoal using K apply(simp) done (* Qannot must be independent of x *)\n        subgoal apply(rule postListpostSet) \n          proof (safe, goal_cases)\n            case (1 x e v)\n            with lxlx[of x] have fF: \"l x = l' x\"  \n              by force \n            \n            from postSetpostList[OF 1(2)] have g: \"postSet (set upds) (ListUpdateE l' xs) t\" .\n            with 1(3) have A: \"(ListUpdateE l' xs) x = e t\"\n              by fast            \n            from 1(3) grr[of \"(x,preT C e s, fune C v)\"] have   B: \"ListUpdateE l' xs x = fst (snd (x, preT C e s, fune C v))\"\n               by force\n            from A B have X: \"e t = preT C e s\" by fastforce\n            from preSetpreList[OF 3(2)] have \"preSet (set upds) ({P'2/Qannot2/eannot2} CONSEQ C) l s\" apply(simp) done\n            with 1(3) have Y: \"l x = preT C e s\" apply(simp) by fast\n            from X Y show ?case by simp\n          qed  \n        done\n    qed\n    subgoal using ihsnd ih2 by blast\n    subgoal using ihsnd[THEN conjunct2] pc unfolding K4_def K_def apply(auto)\n              unfolding K3_def K2_def using ec by auto\n    done \nnext\n  case (Aseq C1 C2 Q upds)\n   \n  let ?P = \"(\\<lambda>l s. pre C1 (pre C2 Q) l s \\<and> preList upds (C1;;C2) l s  )\"\n  let ?P' = \"support Q \\<union> varacom C1 \\<union> varacom C2 \\<union> lesvars upds\"\n  \n  \n  have finite_varacom: \"finite (varacom (C1;; C2))\"  by fact \n  have finite_varacomC2: \"finite (varacom C2)\" \n    apply(rule finite_subset[OF _ finite_varacom]) by simp \n  \n  let ?y = \"SOME x. x \\<notin> ?P'\" \n  have sup_L: \"support (preList upds (C1;;C2)) \\<subseteq> lesvars upds\"\n    apply(rule support_preList) done \n  \n  \n  have sup_B: \"support ?P \\<subseteq> ?P'\"                         \n    apply(rule subset_trans[OF support_and]) using support_pre sup_L by blast \n  have fP': \"finite (?P')\" using finite_varacom Aseq(3,4,5)   apply simp done\n  hence \"\\<exists>x. x \\<notin> ?P'\" using infinite_UNIV_listI\n    using ex_new_if_finite by metis\n  hence ynP': \"?y \\<notin> ?P'\" by (rule someI_ex) \n  hence ysupPreC2Q: \"?y \\<notin> support (pre C2 Q)\" and ysupC1: \"?y \\<notin> varacom C1\" using support_pre by auto\n  \n  from Aseq(5) have \"lesvars upds \\<inter> varacom C2 = {}\" by auto\n  \n  from Aseq show ?case apply(auto)\n  proof (rule Seq, goal_cases)\n    case 2   \n    show \"\\<turnstile>\\<^sub>1 {(%l s. pre C2 Q l s \\<and>  preList upds C2 l s )} strip C2 { time C2 \\<Down> (%l s. Q l s \\<and> postList upds l s)}\"\n      apply(rule weaken_post[where Q=\"(%l s. Q l s \\<and> postList upds l s)\"])\n       apply(rule 2(2)[THEN conjunct1])\n          apply fact\n         apply (fact)+ using 2(8) by simp      \n  next\n    case 3\n    fix s\n    show \"time C1 s + preT C1 (time C2) s  \\<le> time C1 s + preT C1 (time C2) s\"\n      by simp\n  next\n    case 1 \n     \n    \n    from ynP' have yC1: \"?y \\<notin> varacom C1\" by blast\n    have xC1: \"lesvars upds \\<inter> varacom C1 = {}\" using Aseq(5) by auto\n    from finite_support_pre[OF Aseq(4) finite_varacomC2] \n    have G: \"finite (support (pre C2 Q))\" . \n         \n    let ?upds = \"map (\\<lambda>a. case a of (x,e,v) \\<Rightarrow> (x, preT C2 e, fune C2 v)) upds\"\n    let ?upds' = \"(?y,time C2, kdeps C2)#?upds\"\n    \n    { \n      have A: \" lesvars ?upds' = {?y} \\<union> lesvars upds\" apply simp \n        by force\n      from Aseq(5) have 2: \"lesvars upds \\<inter> varacom C1 = {}\" by auto\n      have \" lesvars ?upds' \\<inter> varacom C1 = {}\"\n        unfolding A using ysupC1 2 by blast\n    } note klar=this\n    \n    have t: \"fst \\<circ> (\\<lambda>(x, e, v). (x, preT C2 e, fune C2 v)) = fst\" by auto\n    \n    {\n      fix a b c X\n      assume \"a \\<notin> lesvars X\" \"(a,b,c) \\<in> set X\" \n      then have \"False\" by force\n    } note helper=this\n    \n    have dmap: \"distinct (map fst ?upds')\"\n      apply(auto simp add: t)\n      subgoal for e apply(rule helper[of ?y upds e])  using ynP' by auto\n      subgoal by fact\n      done\n    note bla1=1(1)[where Q=\"pre C2 Q\" and upds=\"?upds'\", OF 1(10) G klar dmap]  \n      \n    note bla=1(2)[OF 1(11,3), THEN conjunct2, THEN conjunct2] \n    from 1(4) have kal: \"lesvars upds \\<inter> varacom C2 = {}\" by auto\n    from bla[OF kal Aseq.prems(4,6,7,8,9)] have bla4: \"K4 upds LVQ C2 Q\"   by auto\n    then   have bla: \"K C2 LVQ Q\" unfolding K4_def  by auto\n      \n    have A:  \n        \"\\<turnstile>\\<^sub>1 {\\<lambda>l s. pre C1 (pre C2 Q) l s \\<and> preList ?upds' C1 l s}\n      strip C1\n      { time C1 \\<Down> \\<lambda>l s. pre C2 Q l s \\<and> postList ?upds' l s} \\<and>\n  (\\<forall>l s. pre C1 (pre C2 Q) l s \\<longrightarrow> pre C2 Q l (postQ C1 s)) \\<and>  K4 ?upds' (qdeps C2 LVQ) C1 (pre C2 Q)\"\n      apply(rule 1(1)[where Q=\"pre C2 Q\" and upds=\"?upds'\", OF 1(10) G klar dmap]) \n    proof (goal_cases)\n      case 1        \n      then show ?case using bla  unfolding K_def by auto\n    next\n      case 2\n      show ?case apply(rule,rule,rule,rule) proof (goal_cases)\n        case (1 l s1 s2)\n      then show ?case using bla4 using Aseq.prems(9) unfolding K4_def K3_def K2_def\n        apply(simp)\n        proof (goal_cases)\n          case 1\n          then have t: \"time C2 s1 = time C2 s2\" by auto\n          \n          have post: \"postList (map (\\<lambda>(x, e, v). (x, preT C2 e, fune C2 v)) upds) l s1 = postList (map (\\<lambda>(x, e, v). (x, preT C2 e, fune C2 v)) upds) l s2\" (is \"?IH upds\")\n            using 1 \n          proof (induct upds) \n            case (Cons a upds)\n            then have IH: \"?IH upds\" by auto\n            obtain x e v where a: \"a = (x,e,v)\" using prod_cases3 by blast\n            from Cons(4) have \"v \\<subseteq> LVE\" unfolding a by auto\n            with Cons(2) have s12v: \"s1 = s2 on fune C2 v\" unfolding a using fune_mono by blast \n            with Cons(3) IH a show ?case by auto \n          qed auto\n          \n          from post t show ?case by auto\n        qed \n      qed\n    next\n      case 3\n      then show ?case  using bla4 unfolding K4_def K3_def K2_def by(auto)\n    next\n      case 4\n      then show ?case apply(auto)\n      proof (goal_cases)\n        case (1 x a aa b)\n        with Aseq.prems(9) have \"b \\<subseteq> LVE\" by auto\n        with fune_mono have \"fune C2 b \\<subseteq> fune C2 LVE\" by auto\n        with 1 show ?case by blast\n      qed  \n    qed\n       \n    show \" \\<turnstile>\\<^sub>1 {\\<lambda>l s. (pre C1 (pre C2 Q) l s \\<and> preList upds (C1;; C2) l s) \\<and> l ?y = preT C1 (time C2) s} strip C1\n         { time C1 \\<Down> \\<lambda>l s. (pre C2 Q l s \\<and> preList upds C2 l s) \\<and> time C2 s \\<le> l ?y}\" \n      apply(rule conseq_old)\n       prefer 2 \n      apply(rule A[THEN conjunct1]) \n       apply(auto simp: preList_Seq postList_preList) done \n    \n    from A[THEN conjunct2, THEN conjunct2] have A1: \"K C1 (qdeps C2 LVQ) (pre C2 Q)\" \n            and A2: \"K3 ?upds' C1 (pre C2 Q)\"  and A3: \"(\\<forall>s1 s2. s1 = s2 on kdeps C1 \\<longrightarrow> time C1 s1 = time C1 s2)\" unfolding K4_def by auto\n    from bla4 have B1: \"K C2 LVQ Q\" and B2: \"K3 upds C2 Q\" and B3: \"(\\<forall>s1 s2. s1 = s2 on kdeps C2 \\<longrightarrow> time C2 s1 = time C2 s2)\" unfolding K4_def by auto\n    show \"K4 upds LVQ (C1;; C2) Q \" \n      unfolding K4_def apply(safe)\n      subgoal using A1 B1 unfolding K_def by(simp)  \n      subgoal using A2 B2 unfolding K3_def K2_def apply(auto) done\n      subgoal for s1 s2 using A3 B3 apply auto\n      proof (goal_cases)\n        case 1\n        then have t: \"time C1 s1 = time C1 s2\" by auto\n        from A2 have \"\\<forall>s1 s2. s1 = s2 on fune C1 (kdeps C2) \\<longrightarrow> preT C1 (time C2) s1 = preT C1 (time C2) s2\" unfolding K3_def K2_def by auto\n        then have p: \"preT C1 (time C2) s1 =  preT C1 (time C2) s2\"\n            using 1(1) by simp\n        from t p show ?case by auto\n      qed\n      done\n  next    \n    from ynP' sup_B show \"?y \\<notin> support ?P\" by blast \n    have F: \"support (preList upds C2) \\<subseteq> lesvars upds\"  \n      apply(rule support_preList) done \n    have \"support (\\<lambda>l s. pre C2 Q  l s \\<and> preList upds C2 l s) \\<subseteq> ?P'\"\n      apply(rule subset_trans[OF support_and]) using F support_pre by blast\n    with ynP'\n    show \"?y \\<notin> support (\\<lambda>l s. pre C2 Q  l s \\<and> preList upds C2 l s)\" by blast\n  next\n    case (6 l s) \n    \n    \n    note bla=6(2)[OF 6(11,3), THEN conjunct2, THEN conjunct2] \n    from 6(4) have kal: \"lesvars upds \\<inter> varacom C2 = {}\" by auto\n    from bla[OF kal Aseq.prems(4,6,7,8,9)] have bla4: \"K4 upds LVQ C2 Q\"   by auto\n    then   have bla: \"K C2 LVQ Q\" unfolding K4_def  by auto\n    \n    have 11: \"finite (support (pre C2 Q )) \" \n      apply(rule finite_subset[OF support_pre])\n      using 6(3,4,10)  finite_varacomC2 by blast \n    have A: \"\\<forall>l s. pre C1 (pre C2 Q )  l s \\<longrightarrow> pre C2 Q  l (postQ C1 s)\"\n      apply(rule 6(1)[where upds=\"[]\", THEN conjunct2, THEN conjunct1])\n            apply(fact)+  apply(auto) using bla unfolding K_def apply blast+ done \n    have B: \"(\\<forall>l s. pre C2 Q  l s \\<longrightarrow> Q l (postQ C2 s))\" \n      apply(rule 6(2)[where upds=\"[]\", THEN conjunct2, THEN conjunct1])\n        apply(fact)+ apply auto using Aseq.prems(6) by auto    \n    from A B 6 show ?case by simp \n  qed  \nnext\n  case (Awhile A b C Q upds)\n  obtain I2 S E Es SS where aha[simp]: \"A = (I2,(S,(E,Es,SS)))\" using prod_cases5 by blast\n  obtain I Is where aha2: \"I2 = (I, Is)\"  \n    by fastforce\n  let ?LV =\"(\\<Union>y\\<in>LVE \\<union> LVQ. (funStar SS) y)\" \n  have LVE_LVE: \"LVE \\<subseteq> (\\<Union>y\\<in>LVE. (funStar SS) y)\" using funStart_prop1  by fast\n  have LV_LV: \"LVE \\<union> LVQ \\<subseteq> ?LV\" using funStart_prop1  by fast\n  have LV_LV2: \"(\\<Union>y\\<in>LVE \\<union> LVQ. SS y) \\<subseteq> ?LV\" using funStart_prop2 by fast\n  have LVE_LV2: \"(\\<Union>y\\<in>LVE. SS y) \\<subseteq> (\\<Union>y\\<in>LVE. (funStar SS) y)\" using funStart_prop2 by fast\n  note aha = aha2 aha \n  with aha aha2 \\<open>vc (Awhile A b C) Q LVQ LVE\\<close> have \"vc (Awhile ((I,Is),S,E,Es,SS) b C) Q LVQ LVE\" apply auto apply fast+ done\n  then                 \n  have vc: \"vc C I Is (Es \\<union> (\\<Union>y\\<in>LVE. (funStar SS) y))\" \n    and IQ: \"\\<forall>l s. (I l s \\<and> bval b s \\<longrightarrow> pre C I l s \\<and>  1 + preT C E s + time C s \\<le> E s \\<and> S s = S (postQ C s) on ?LV)\" and\n    pre: \"\\<forall>l s. (I l s \\<and> \\<not> bval b s \\<longrightarrow> Q l s \\<and> 1 \\<le> E s \\<and> S s = s on ?LV)\"\n    and Is: \"(\\<forall>s1 s2 l. s1 = s2 on Is \\<longrightarrow> I l s1 = I l s2)\"\n    and Ss:  \"(\\<forall>y\\<in>LVE \\<union> LVQ. let Ss = SS y in \\<forall>s1 s2. s1 = s2 on Ss \\<longrightarrow> S s1 y = S s2 y)\"\n    and Es: \"(\\<forall>s1 s2. s1 = s2 on Es \\<longrightarrow> E s1 = E s2)\" apply simp_all apply auto apply fast+ done\n    \n  then have pre2: \"\\<And>l s. I l s \\<Longrightarrow> \\<not> bval b s \\<Longrightarrow> Q l s \\<and> 1 \\<le> E s \\<and> S s = s on ?LV\"\n    and IQ2: \"\\<And>l s. (I l s \\<Longrightarrow> bval b s \\<Longrightarrow> pre C I l s \\<and>  1 + preT C E s + time C s \\<le> E s \\<and> S s = S (postQ C s) on ?LV)\"\n    and Ss2:  \"\\<And>y s1 s2. s1 = s2 on (\\<Union>y\\<in>LVE. SS y) \\<Longrightarrow> S s1 = S s2 on LVE\"\n    by auto\n  \n  from Ss have Ssc: \"\\<And>c s1 s2. c \\<subseteq> LVE \\<Longrightarrow>  s1 = s2 on (\\<Union>y\\<in>c. SS y) \\<Longrightarrow> S s1 = S s2 on c\" \n    by auto\n    \n  from IQ have IQ_in: \"\\<And>l s. I l s \\<Longrightarrow> bval b s \\<Longrightarrow> S s = S (postQ C s) on ?LV\" by auto\n  \n  have inv_impl: \"\\<And>l s. I l s \\<Longrightarrow> bval b s \\<Longrightarrow> pre C I  l s\" using IQ by auto    \n  \n  have yC: \"lesvars upds \\<inter> varacom C = {}\" using Awhile(4) aha by auto\n   \n  let ?upds = \"map (%(x,e,v). (x, %s. e (S s), \\<Union>x\\<in>v. SS x)) upds\"\n  let ?INV = \"%l s. I l s \\<and> postList ?upds l s\" \n    \n  have \"lesvars upds \\<inter> support I = {}\" using Awhile(4) unfolding aha by auto\n    \n  let ?P=\"lesvars upds \\<union> varacom ({A} WHILE b DO C) \"\n  let ?z=\"SOME z::lvname. z \\<notin> ?P\"\n  have \"finite ?P\" apply(auto simp del: aha)   by (fact Awhile(6))  \n  hence \"\\<exists>z. z\\<notin>?P\"  using infinite_UNIV_listI\n    using ex_new_if_finite by metis\n  hence znP: \"?z \\<notin> ?P\" by (rule someI_ex) \n  from znP have   \n      zny:  \"?z \\<notin> lesvars upds\"\n    and zI:   \"?z \\<notin> support I\" \n    and blb:      \"?z \\<notin> varacom C\" by (simp_all add: aha)\n  \n  from Awhile(4,6) have 23: \"finite (varacom C)\" \n    and  26: \"finite (support I)\" by (auto simp add: finite_subset aha) \n   \n  have \"\\<forall>l s.  pre C I  l s \\<longrightarrow> I l (postQ C s)\"\n    apply(rule Awhile(1)[THEN conjunct2, THEN conjunct1])\n            apply(fact)+ subgoal using  Is apply auto done\n    subgoal using Awhile(8) LVE_LVE  by (metis subsetD sup.cobounded2)\n            apply fact using Awhile(10) LVE_LVE by blast \n  hence step: \"\\<And>l s. pre C I  l s \\<Longrightarrow> I l (postQ C s)\" by simp\n   \n  have fua: \"lesvars ?upds = lesvars upds\"\n    by force\n  let ?upds' = \"(?z,E,Es) # ?upds\"\n  \n  show ?case\n  proof (safe, goal_cases)\n    case (2 l s)\n    from 2 have A: \"I l s\" unfolding aha by(simp) \n    then have I: \"I l s\" by simp\n        \n    { fix n\n    have \"E s = n \\<Longrightarrow> I l s \\<Longrightarrow> Q l (postQ ({A} WHILE b DO C) s)\"\n    proof (induct n arbitrary: s l rule: less_induct)\n      case (less n)\n      then show ?case \n      proof (cases \"bval b s\")\n        case True\n        with less IQ2 have \"pre C I l s\" and S: \"S s = S (postQ C s) on ?LV\" and t: \"1 + preT C E s + time C s \\<le> E s\" by auto\n        with step have I': \"I l (postQ C s)\" and \"1 + E (postQ C s) + time C s \\<le> E s\" using TQ by auto\n        with less have \"E (postQ C s) < n\" by auto    \n        with less(1) I' have \"Q l (postQ ({A} WHILE b DO C) (postQ C s))\" by auto\n        with step show ?thesis using S  apply simp using Awhile(7)\n          by (metis (no_types, lifting) LV_LV SUP_union contra_subsetD sup.boundedE)\n      next\n        case False\n        with pre2 less(3) have \"Q l s\" \"S s = s  on ?LV\" by auto\n        then show ?thesis apply simp using Awhile(7)\n          by (metis (no_types, lifting) LV_LV SUP_union contra_subsetD sup.boundedE)  \n      qed\n    qed\n    }\n    with I show \"Q l (postQ ({A} WHILE b DO C) s)\" by simp   \n  next\n    case 1    \n   have g: \"\\<And>e. e \\<circ> S = (%s. e (S s)) \" by auto\n   \n   \n   have \"lesvars ?upds' \\<inter> varacom C = {}\"\n          using yC blb by(auto)\n        \n        have z: \"(fst \\<circ> (\\<lambda>(x, e, v). (x, \\<lambda>s. e (S s), \\<Union>x\\<in>v. SS x))) = fst\" by(auto)\n        have \"distinct (map fst ?upds')\"\n          using Awhile(5) zny by (auto simp add: z)\n          \n        have klae: \"\\<And>s1 s2 A B. B \\<subseteq> A \\<Longrightarrow> s1 = s2 on A \\<Longrightarrow> s1 = s2 on B\" by auto\n        from Awhile(8) Awhile(9) have gl: \"\\<And>a b c s1 s2. (a,b,c) \\<in> set upds \\<Longrightarrow> s1 = s2 on c \\<Longrightarrow> b s1 = b s2\" \n          by fast\n        have CombALL: \" \\<turnstile>\\<^sub>1 {\\<lambda>l s. pre C I l s \\<and> preList ?upds' C l s}\n                  strip C\n                  { time C \\<Down> \\<lambda>l s. I l s \\<and> postList ?upds' l s}   \\<and>\n(\\<forall>l s. pre C I l s \\<longrightarrow> I l (postQ C s)) \\<and> K4 ((SOME z. z \\<notin> lesvars upds \\<union> varacom ({A} WHILE b DO C), E, Es) # map (\\<lambda>(x, e, v). (x, \\<lambda>s. e (S s), \\<Union>x\\<in>v. SS x)) upds) Is C I \"\n          apply(rule Awhile.IH[where upds=\"?upds'\" ] )\n                 apply (fact)+  \n          \n          subgoal apply safe using Is apply blast\n            using Is apply blast done\n          subgoal\n            using Is Es apply auto   \n             apply(simp_all add: postListpostSet2, safe) \n          proof (goal_cases)\n            case (1 l s1 s2 x e v)\n            from 1(5,6) have i: \"l x = e (S s1)\" by auto\n            from  Awhile(10) 1(6) have vLC: \"v \\<subseteq> LVE\" by auto\n            have st: \"(\\<Union>y\\<in>v. SS y) \\<subseteq> (\\<Union>y\\<in>LVE. SS y)\" using vLC by blast\n            also have \"\\<dots> \\<subseteq> (\\<Union>y\\<in>LVE. funStar SS y)\" using LVE_LV2 by blast\n            finally have st: \"(\\<Union>y\\<in>v. SS y) \\<subseteq>  Es \\<union> (\\<Union>y\\<in>LVE. funStar SS y)\" by blast\n            have ii: \"e (S s1) = e (S s2)\"\n              apply(rule gl)\n               apply fact\n              apply(rule Ssc)\n              apply fact\n              using st 1(3) by blast\n            from i ii show ?case by simp \n          next\n            case (2 l s1 s2 x e v)\n            from 2(5,6) have i: \"l x = e (S s2)\" by auto\n            from  Awhile(10) 2(6) have vLC: \"v \\<subseteq> LVE\" by auto\n            have st: \"(\\<Union>y\\<in>v. SS y) \\<subseteq> (\\<Union>y\\<in>LVE. SS y)\" using vLC by blast\n            also have \"\\<dots> \\<subseteq> (\\<Union>y\\<in>LVE. funStar SS y)\" using LVE_LV2 by blast\n            finally have st: \"(\\<Union>y\\<in>v. SS y) \\<subseteq>  Es \\<union> (\\<Union>y\\<in>LVE. funStar SS y)\" by blast\n            have ii: \"e (S s1) = e (S s2)\"\n              apply(rule gl)\n               apply fact\n              apply(rule Ssc)\n              apply fact\n              using st 2(3) by blast\n            from i ii show ?case by simp \n          qed  apply(auto)\n          subgoal using Es by auto\n          subgoal apply(rule gl) apply(simp) using Ss Awhile(10) by fastforce\n          subgoal using Awhile(10) LVE_LV2 by  blast       \n          done\n        from this[THEN conjunct2, THEN conjunct2] have\n          K: \"K C Is I\" and K3: \"K3 ?upds' C I\" and Kt: \"\\<forall>s1 s2. s1 = s2 on kdeps C \\<longrightarrow> time C s1 = time C s2\" unfolding K4_def by auto\n        show \"K4 upds LVQ ({A} WHILE b DO C) Q\" \n          unfolding K4_def apply safe\n          subgoal using K unfolding K_def aha using Is by auto \n          subgoal using K3 unfolding K3_def K2_def aha apply auto\n            subgoal for x e v apply (rule gl) apply simp apply(rule Ssc)  using Awhile(10) \n               apply fast  apply blast done done\n          subgoal using Kt Es unfolding aha by auto\n          done\n   \n    show ?case  \n      \n      apply(simp add: aha) \n      apply(rule conseq_old[where P=\"?INV\" and e'=E and Q=\"\\<lambda>l s. ?INV l s \\<and> ~ bval b s\"])\n      defer \n    proof (goal_cases)\n      case 3\n      show ?case  apply(rule exI[where x=1]) apply(auto)[1] apply(simp only: postList_preList[symmetric] ) apply (auto)[1]\n        by(simp only:  g) \n    next\n      case 2 (* post condition is satisfied after exiting the loop *)\n      show ?case\n      proof (safe, goal_cases)\n        case (1 l s)\n        then show ?case using pre by auto\n      next\n        case (2 l s)\n        from Awhile(8) have Aw7: \"\\<And>l s1 s2. s1 = s2 on LVE \\<Longrightarrow>  postList upds l s1 = postList upds l s2\" by auto\n        have \"postList (map (\\<lambda>(x, e, v). (x, \\<lambda>s. e (S s), \\<Union>x\\<in>v. SS x)) upds) l s =\n                postList upds l (S s)\" apply(induct upds) apply auto done\n        also have \"\\<dots> = postList upds l s\" using  Aw7[of \"S s\" s \"l\"] pre2 2 LV_LV\n          by fast\n        finally show ?case using 2(3) by simp\n      qed \n    next\n      case 1\n      show ?case \n      proof(rule While, goal_cases)\n        case 1          \n        \n        \n        note Comb=CombALL[THEN conjunct1]\n        \n        show \"\\<turnstile>\\<^sub>1 {\\<lambda>l s. (I l s \\<and> postList ?upds l s) \\<and> bval b s \\<and> preT C E s = l ?z}\n         strip C {  time C \\<Down> \\<lambda>l s. (I l s \\<and> postList ?upds l s) \\<and> E s \\<le> l ?z}\" \n          apply(rule conseq_old)\n          apply(rule exI[where x=1]) apply(simp)\n            prefer 2 \n        proof (rule Comb, safe, goal_cases) \n          case (2 l s)\n          from IQ_in[OF 2(1)] gl Awhile(10,9)\n          have y: \"postList ?upds l s = \n                preList ?upds C l s\" (is \"?IH upds\")\n          proof (induct upds) \n            case (Cons a  upds')\n            obtain y e v where axe: \"a = (y,e,v)\" using prod_cases3 by blast    \n            have IH: \"?IH upds'\" apply(rule Cons(1))\n              using Cons(2-5) by auto\n            from Cons(3) axe have ke: \"\\<And>s1 s2. s1 = s2 on v \\<Longrightarrow> e s1 = e s2\"\n              by fastforce\n            have vLC: \"v \\<subseteq> LVE\" using axe Cons(4) by simp\n            have step: \"e (S s) = e (S (postQ C s))\" apply(rule ke) using Cons(2)  using vLC LV_LV 2(3) \n              by blast\n            show ?case unfolding axe using IH step apply(simp) \n                apply(simp only: TQ) done\n          qed simp\n          from 2 show ?case by(simp add: y) \n        qed  (auto simp: inv_impl)\n      next \n        show \"\\<forall>l s. bval b s \\<and> I l s \\<and> postList ?upds l s \\<longrightarrow>  1 + preT C E s + time C s \\<le>   E s\"\n        proof (clarify, goal_cases)\n          case (1 l s)\n          thus ?case\n            using 1 IQ by auto\n        qed\n      next \n        show \"\\<forall>l s. ~bval b s \\<and> I l s \\<and> postList ?upds l s \\<longrightarrow>  1 \\<le> E s\"\n        proof (clarify, goal_cases)\n          case (1 l s)\n          with pre show ?case by auto\n        qed  \n      next\n        have pff: \"?z \\<notin> lesvars ?upds\" apply(simp only: fua) by fact\n        have \"support (\\<lambda>l s. I l s \\<and> postList ?upds l s) \\<subseteq> support I \\<union> support (postList ?upds)\"\n          by(rule support_and) \n        also\n        have \"support (postList ?upds)\n          \\<subseteq> lesvars ?upds\"\n             apply(rule support_postList) done \n        finally \n        have \"support (\\<lambda>l s. I l s \\<and> postList ?upds l s) \\<subseteq> support I \\<union> lesvars ?upds\"\n          by blast \n        thus \"?z \\<notin> support (\\<lambda>l s. I l s \\<and> postList ?upds l s)\" \n          apply(rule contra_subsetD) \n          using zI pff by(simp)\n      qed\n    qed \n    \n  qed\nqed\n \n\ncorollary vc_sound':\n  assumes \"vc C Q Qset {}\" \n          \"finite (support Q)\" \"finite (varacom C)\"\n          \"\\<forall>l s. P l s \\<longrightarrow> pre C Q l s\" \n          \"\\<And>s1 s2 l. s1 = s2 on Qset \\<Longrightarrow> Q l s1 = Q l s2\"\n  shows \"\\<turnstile>\\<^sub>1 {P} strip C {time C \\<Down> Q}\"\nproof -\n  show ?thesis\n    apply(rule conseq_old)\n      prefer 2 apply(rule vc_sound[where upds=\"[]\", OF assms(1), simplified, OF assms(2-3), THEN conjunct1])      \n    using assms(4,5) apply auto \n    done \nqed\n\ncorollary vc_sound'':\n  assumes \"vc C Q Qset {}\" \n          \"finite (support Q)\" \"finite (varacom C)\"\n          \" (\\<exists>k>0. \\<forall>l s. P l s \\<longrightarrow> pre C Q l s \\<and> time C s \\<le> k * e s)\"\n          \"\\<And>s1 s2 l. s1 = s2 on Qset \\<Longrightarrow> Q l s1 = Q l s2\"\n  shows \"\\<turnstile>\\<^sub>1 {P} strip C {e \\<Down> Q}\"\nproof -\n  show ?thesis\n    apply(rule conseq_old)\n      prefer 2 apply(rule vc_sound[where upds=\"[]\", OF assms(1), simplified, OF assms(2-3), THEN conjunct1])      \n    using assms(4,5) apply auto \n    done \nqed    \n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Hoare_Time/Nielson_VCGi.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6224593171945417, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.2990784298642363}}
{"text": "(* \n   Title: The pi-calculus   \n   Author/Maintainer: Jesper Bengtson (jebe.dk), 2012\n*)\ntheory Weak_Late_Bisim_Subst_Pres\n  imports Weak_Late_Bisim_Subst Weak_Late_Bisim_Pres\nbegin\n\nlemma tauPres:\n  fixes P :: pi\n  and   Q :: pi\n  \n  assumes \"P \\<approx>\\<^sup>s Q\"\n\n  shows \"\\<tau>.(P) \\<approx>\\<^sup>s \\<tau>.(Q)\"\nusing assms\nby(force simp add: substClosed_def intro: Weak_Late_Bisim_Pres.tauPres)\n\nlemma inputPres:\n  fixes P :: pi\n  and   Q :: pi\n  and   a :: name\n  and   x :: name\n\n  assumes PeqQ: \"P \\<approx>\\<^sup>s Q\"\n\n  shows \"a<x>.P \\<approx>\\<^sup>s a<x>.Q\"\nproof(auto simp add: substClosed_def)\n  fix \\<sigma> :: \"(name \\<times> name) list\"\n  {\n    fix P Q a x \\<sigma>\n    assume \"P \\<approx>\\<^sup>s Q\"\n    then have \"P[<\\<sigma>>] \\<approx>\\<^sup>s Q[<\\<sigma>>]\" by(rule partUnfold)\n    then have \"\\<forall>y. (P[<\\<sigma>>])[x::=y] \\<approx> (Q[<\\<sigma>>])[x::=y]\"\n      apply(auto simp add: substClosed_def)\n      by(erule_tac x=\"[(x, y)]\" in allE) auto\n    moreover assume \"x \\<sharp> \\<sigma>\"\n    ultimately have \"(a<x>.P)[<\\<sigma>>] \\<approx> (a<x>.Q)[<\\<sigma>>]\" using weakBisimEqvt\n      by(force intro: Weak_Late_Bisim_Pres.inputPres)\n  }\n  note Goal = this\n\n  obtain y::name where \"y \\<sharp> P\" and \"y \\<sharp> Q\" and \"y \\<sharp> \\<sigma>\"\n    by(generate_fresh \"name\") auto\n  from `P \\<approx>\\<^sup>s Q` have \"([(x, y)] \\<bullet> P) \\<approx>\\<^sup>s ([(x, y)] \\<bullet> Q)\" by(rule eqvtI)\n  hence \"(a<y>.([(x, y)] \\<bullet> P))[<\\<sigma>>] \\<approx> (a<y>.([(x, y)] \\<bullet> Q))[<\\<sigma>>]\" using `y \\<sharp> \\<sigma>` by(rule Goal)\n  moreover from `y \\<sharp> P` `y \\<sharp> Q` have \"a<x>.P = a<y>.([(x, y)] \\<bullet> P)\" and \"a<x>.Q = a<y>.([(x, y)] \\<bullet> Q)\"\n    by(simp add: pi.alphaInput)+\n\n  ultimately show \"(a<x>.P)[<\\<sigma>>] \\<approx> (a<x>.Q)[<\\<sigma>>]\" by simp\nqed\n\nlemma outputPres:\n  fixes P :: pi\n  and   Q :: pi\n  \n  assumes \"P \\<approx>\\<^sup>s Q\"\n\n  shows \"a{b}.P \\<approx>\\<^sup>s a{b}.Q\"\nusing assms\nby(force simp add: substClosed_def intro: Weak_Late_Bisim_Pres.outputPres)\n\n\n\n  assumes \"P \\<approx>\\<^sup>s Q\"\n\n  shows \"[a\\<frown>b]P \\<approx>\\<^sup>s [a\\<frown>b]Q\"\nusing assms\nby(force simp add: substClosed_def intro: Weak_Late_Bisim_Pres.matchPres)\n\nlemma mismatchPres:\n  fixes P :: pi\n  and   Q :: pi\n  and   a :: name\n  and   b :: name\n\n  assumes \"P \\<approx>\\<^sup>s Q\"\n\n  shows \"[a\\<noteq>b]P \\<approx>\\<^sup>s [a\\<noteq>b]Q\"\nusing assms\nby(force simp add: substClosed_def intro: Weak_Late_Bisim_Pres.mismatchPres)\n\nlemma parPres:\n  fixes P :: pi\n  and   Q :: pi\n  and   R :: pi\n\n  assumes \"P \\<approx>\\<^sup>s Q\"\n\n  shows \"P \\<parallel> R \\<approx>\\<^sup>s Q \\<parallel> R\"\nusing assms\nby(force simp add: substClosed_def intro: Weak_Late_Bisim_Pres.parPres)\n\n\n\n  assumes PeqQ: \"P \\<approx>\\<^sup>s Q\"\n  \n  shows \"<\\<nu>x>P \\<approx>\\<^sup>s <\\<nu>x>Q\"\nproof(auto simp add: substClosed_def)\n  fix s::\"(name \\<times> name) list\"\n\n  have Res: \"\\<And>P Q x s. \\<lbrakk>P[<s>] \\<approx> Q[<s>]; x \\<sharp> s\\<rbrakk> \\<Longrightarrow> (<\\<nu>x>P)[<s>] \\<approx> (<\\<nu>x>Q)[<s>]\"\n    by(force intro: Weak_Late_Bisim_Pres.resPres)\n\n  have \"\\<exists>c::name. c \\<sharp> (P, Q, s)\" by(blast intro: name_exists_fresh)\n  then obtain c::name where cFreshP: \"c \\<sharp> P\" and cFreshQ: \"c \\<sharp> Q\" and cFreshs: \"c \\<sharp> s\"\n    by(force simp add: fresh_prod)\n\n  from PeqQ have \"P[<([(x, c)] \\<bullet> s)>] \\<approx> Q[<([(x, c)] \\<bullet> s)>]\" by(simp add: substClosed_def)\n  hence \"([(x, c)] \\<bullet> P[<([(x, c)] \\<bullet> s)>]) \\<approx> ([(x, c)] \\<bullet> Q[<([(x, c)] \\<bullet> s)>])\" by(rule Weak_Late_Bisim.eqvtI)\n  hence \"([(x, c)] \\<bullet> P)[<s>] \\<approx> ([(x, c)] \\<bullet> Q)[<s>]\" by simp\n  hence \"(<\\<nu>c>([(x, c)] \\<bullet> P))[<s>] \\<approx> (<\\<nu>c>([(x, c)] \\<bullet> Q))[<s>]\" using cFreshs by(rule Res)\n\n  moreover from cFreshP cFreshQ have \"<\\<nu>x>P = <\\<nu>c>([(x, c)] \\<bullet> P)\" and \"<\\<nu>x>Q = <\\<nu>c>([(x, c)] \\<bullet> Q)\"\n    by(simp add: alphaRes)+\n\n  ultimately show \"(<\\<nu>x>P)[<s>] \\<approx> (<\\<nu>x>Q)[<s>]\" by simp\nqed\n\n\n\n  shows \"!P \\<approx>\\<^sup>s !Q\"\nusing assms\nby(force simp add: substClosed_def intro: Weak_Late_Bisim_Pres.bangPres)\n\nend", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Pi_Calculus/Weak_Late_Bisim_Subst_Pres.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5078118642792044, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.299044887348973}}
{"text": "(*\n * Copyright 2019, NTU\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n *  Author: Albert Rizaldi, NTU Singapore\n *)\n\ntheory Multiplexer_Hoare_Typed\n  imports VHDL_Hoare_Typed\nbegin\n\ntext \\<open>Define the new datatype for the all signals occurred in a multiplexer. A multiplexer has three\ninputs: in0, in1, and a selector.\\<close>\n\ndatatype sig = IN0 | IN1 | SEL | OUT\n\n\\<comment> \\<open>We put suffix 2 because it only selects between two inputs\\<close>\ndefinition mux2 :: \"sig conc_stmt\" where\n  \"mux2 = process {IN0, IN1, SEL} : Bguarded (Bsig SEL)\n                                      (Bassign_trans OUT (Bsig IN1) 1)\n                                      (Bassign_trans OUT (Bsig IN0) 1)\"\n\nlemma potential_tyenv:\n  assumes \"seq_wt \\<Gamma> (Bguarded (Bsig SEL)\n                                      (Bassign_trans OUT (Bsig IN1) 1)\n                                      (Bassign_trans OUT (Bsig IN0) 1))\"\n  shows \"\\<exists>ki len. \\<Gamma> IN0 = Bty \\<and> \\<Gamma> IN1 = Bty \\<and> \\<Gamma> SEL = Bty \\<and> \\<Gamma> OUT = Bty\n             \\<or> \\<Gamma> IN0 = Lty ki len \\<and> \\<Gamma> IN1 = Lty ki len \\<and> \\<Gamma> SEL = Bty \\<and> \\<Gamma> OUT = Lty ki len\"\nproof  (rule seq_wt_cases(3)[OF assms])\n  assume \"bexp_wt \\<Gamma> (Bsig SEL) Bty\"\n  assume \"seq_wt \\<Gamma> (Bassign_trans OUT (Bsig IN1) 1)\"\n  assume \"seq_wt \\<Gamma> (Bassign_trans OUT (Bsig IN0) 1)\"\n  have \"\\<Gamma> SEL = Bty\"\n    by (rule bexp_wt_cases_all[OF \\<open>bexp_wt \\<Gamma> (Bsig SEL) Bty\\<close>]) auto\n  have \" bexp_wt \\<Gamma> (Bsig IN1) (\\<Gamma> OUT)\"\n    using seq_wt_cases(4)[OF \\<open>seq_wt \\<Gamma> (Bassign_trans OUT (Bsig IN1) 1)\\<close>] by auto\n  hence \"\\<Gamma> IN1 = \\<Gamma> OUT\"\n    by (rule bexp_wt_cases_all) auto\n  have \"bexp_wt \\<Gamma> (Bsig IN0) (\\<Gamma> OUT)\"\n    using seq_wt_cases(4)[OF \\<open>seq_wt \\<Gamma> (Bassign_trans OUT (Bsig IN0) 1)\\<close>] by auto\n  hence \"\\<Gamma> IN0 = \\<Gamma> OUT\"\n    by (rule bexp_wt_cases_all) auto\n  obtain ki len where \"\\<Gamma> OUT = Bty \\<or> \\<Gamma> OUT = Lty ki len\"\n    using ty.exhaust by meson\n  moreover\n  { assume \"\\<Gamma> OUT = Bty\"\n    hence \"\\<Gamma> IN0 = Bty\"\n      by (simp add: \\<open>\\<Gamma> IN0 = \\<Gamma> OUT\\<close>)\n    moreover have \"\\<Gamma> IN1 = Bty\"\n      using \\<open>\\<Gamma> IN1 = \\<Gamma> OUT\\<close> \\<open>\\<Gamma> OUT = Bty\\<close> by auto\n    ultimately have ?thesis\n      using \\<open>\\<Gamma> OUT = Bty\\<close> \\<open>\\<Gamma> SEL = Bty\\<close> by blast }\n  moreover\n  { assume \"\\<Gamma> OUT = Lty ki len\"\n    moreover hence \"\\<Gamma> IN0 = Lty ki len\" and \"\\<Gamma> IN1 = Lty ki len\"\n      using \\<open>\\<Gamma> IN0 = \\<Gamma> OUT\\<close> \\<open>\\<Gamma> IN1 = \\<Gamma> OUT\\<close> by auto\n    ultimately have ?thesis\n      using \\<open>\\<Gamma> SEL = Bty\\<close> by blast }\n  ultimately show ?thesis\n    by auto\nqed\n\nabbreviation \"bval_of_wline tw sig t \\<equiv> bval_of (wline_of tw sig t)\"\n\nlocale multiplexer_typed = \n  fixes \\<Gamma> :: \"sig tyenv\" and len :: nat and ki :: \"signedness\"\n  assumes tyin0: \"\\<Gamma> IN0 = Lty ki len\" and tyin1: \"\\<Gamma> IN1 = Lty ki len \" and tysel: \" \\<Gamma> SEL = Bty\" and tyout: \"\\<Gamma> OUT = Lty ki len\"  \nbegin\n\ndefinition inv :: \"sig assn2\" where\n  \"inv \\<equiv> \\<lambda>tw. (wline_of tw OUT (fst tw) = (if bval_of_wline tw SEL (fst tw - 1) then wline_of tw IN1 (fst tw - 1) else wline_of tw IN0 (fst tw - 1)))\"\n\ndefinition inv2 :: \"sig assn2\" where\n  \"inv2 \\<equiv> (\\<lambda>tw. disjnt {IN0, IN1, SEL} (event_of tw) \\<longrightarrow> (\\<forall>i > fst tw. wline_of tw OUT i = wline_of tw OUT (fst tw)))\"\n\nlemma inv_next_time_true:\n  fixes tw\n  defines \"v \\<equiv> eval_world_raw2 tw (Bsig IN1)\"\n  assumes \"eval_world_raw2 tw (Bsig SEL) = Bv True\"\n  defines \"tw' \\<equiv> tw[OUT, 1 :=\\<^sub>2 v]\"\n  shows   \"inv (fst tw' + 1, snd tw')\"\nproof - \n  have bexpIN1: \"bexp_wt \\<Gamma> (Bsig SEL) (Bty)\" \n    using multiplexer_typed_axioms unfolding multiplexer_typed_def by (metis bexp_wt.intros(3))+\n  have \"wline_of tw' OUT (fst tw + 1) = v\"\n    unfolding tw'_def worldline_upd2_def worldline_upd_def by auto\n  also have \"... = (if bval_of_wline tw SEL (fst tw) then wline_of tw IN1 (fst tw) else wline_of tw IN0 (fst tw))\"\n    using assms(2) unfolding v_def eval_world_raw.simps eval_arith.simps  Let_def comp_def by auto\n  finally show ?thesis\n    unfolding inv_def tw'_def worldline_upd2_def worldline_upd_def  by auto\nqed\n\nlemma inv_next_time_false:\n  fixes tw\n  defines \"v \\<equiv> eval_world_raw2 tw (Bsig IN0)\"\n  assumes \"eval_world_raw2 tw (Bsig SEL) \\<noteq> Bv True\"\n  defines \"tw' \\<equiv> tw[OUT, 1 :=\\<^sub>2 v]\"\n  assumes \"wityping \\<Gamma> (snd tw)\"\n  shows   \"inv (fst tw' + 1, snd tw')\"\nproof - \n  have bexpIN1: \"bexp_wt \\<Gamma> (Bsig SEL) (Bty)\" \n    using multiplexer_typed_axioms unfolding multiplexer_typed_def by (metis bexp_wt.intros(3))+\n  hence \"eval_world_raw2 tw (Bsig SEL) = Bv False\"\n    using eval_world_raw_bv[OF bexpIN1 assms(4)] assms(2) by metis\n  have \"wline_of tw' OUT (fst tw + 1) = v\"\n    unfolding tw'_def worldline_upd2_def worldline_upd_def by auto\n  also have \"... = (if bval_of_wline tw SEL (fst tw) then wline_of tw IN1 (fst tw) else wline_of tw IN0 (fst tw))\"\n    using `eval_world_raw2 tw (Bsig SEL) = Bv False` unfolding v_def eval_world_raw.simps eval_arith.simps  Let_def comp_def by auto\n  finally show ?thesis\n    unfolding inv_def tw'_def worldline_upd2_def worldline_upd_def  by auto\nqed\n\nlemma inv2_next_time:\n  fixes tw v\n  defines \"tw' \\<equiv> tw[OUT, 1 :=\\<^sub>2 v]\"\n  shows   \"inv2 (fst tw' + 1, snd tw')\"\n  unfolding inv2_def tw'_def worldline_upd2_def worldline_upd_def by auto\n\nlemma mult_conc_hoare:\n  \"\\<And>tw. inv tw \\<and> inv2 tw \\<and> disjnt {IN0, IN1, SEL} (event_of tw) \\<Longrightarrow> inv (fst tw + 1, snd tw)\"\nproof -\n  fix tw\n  assume \"inv tw \\<and> inv2 tw \\<and> disjnt {IN0, IN1, SEL} (event_of tw)\"\n  hence \"inv tw\" and \"inv2 tw\" and \"disjnt {IN0, IN1, SEL} (event_of tw)\"\n    by auto\n  have \"wline_of tw OUT (fst tw + 1) = wline_of tw OUT (fst tw)\"\n    using `inv2 tw` `disjnt {IN0, IN1, SEL} (event_of tw)` unfolding inv2_def by auto \n  also have \"... = (if bval_of_wline tw SEL (get_time tw - 1) then wline_of tw IN1 (get_time tw - 1) else wline_of tw IN0 (get_time tw - 1))\"\n    using `inv tw` unfolding inv_def by auto\n  also have \"... = (if bval_of_wline tw SEL (fst tw) then wline_of tw IN1 (fst tw) else wline_of tw IN0 (fst tw))\"\n    using `disjnt {IN0, IN1, SEL} (event_of tw)`  unfolding event_of_alt_def  \n    by (smt diff_0_eq_0 disjnt_insert1 mem_Collect_eq)\n  finally show \"inv (fst tw + 1, snd tw)\"\n    unfolding inv_def by auto\nqed\n\nlemma mult_conc_hoare2:\n  \"\\<And>tw. inv2 tw \\<and> disjnt {IN0, IN1, SEL} (event_of tw) \\<Longrightarrow> inv2 (fst tw + 1, snd tw)\"\n  unfolding inv2_def by auto\n\nlemma conc_stmt_wf_mult:\n  \"conc_stmt_wf mux2\"\n  unfolding mux2_def conc_stmt_wf_def by auto  \n\nlemma nonneg_delay_conc_mult:\n  \"nonneg_delay_conc mux2\"\n  unfolding mux2_def by auto\n\nlemma nonneg_delay_conc_mult':\n  \"nonneg_delay_conc ( process {IN0, IN1, SEL} : Bguarded (Bsig SEL) (Bassign_trans OUT (Bsig IN1) 1) (Bassign_trans OUT (Bsig IN0) 1))\"\n  using nonneg_delay_conc_mult unfolding mux2_def by auto\n\nlemma well_typed:\n  \"seq_wt \\<Gamma> (Bguarded (Bsig SEL) (Bassign_trans OUT (Bsig IN1) 1) (Bassign_trans OUT (Bsig IN0) 1))\"\n  by (metis bexp_wt.intros(3) seq_wt.intros(3) seq_wt.intros(4) tyin0 tyin1 tyout tysel)\n\nlemma conc_wt_mult:\n  \"conc_wt \\<Gamma> mux2\"\n  unfolding mux2_def by (meson conc_wt.intros(1) well_typed)\n\nlemma conc_wt_mult':\n  \"conc_wt \\<Gamma> ( process {IN0, IN1, SEL} : Bguarded (Bsig SEL) (Bassign_trans OUT (Bsig IN1) 1) (Bassign_trans OUT (Bsig IN0) 1))\"\n  using conc_wt_mult unfolding mux2_def by auto\n\nlemma mult_conc_sim2':\n  \"\\<Gamma> \\<turnstile>\\<^sub>s \\<lbrace>\\<lambda>tw. inv tw \\<and> inv2 tw\\<rbrace> mux2 \\<lbrace>\\<lambda>tw. inv tw \\<and> inv2 tw\\<rbrace>\"\n  apply (rule While_Suc)\n  apply (rule Conseq'[where P=\"wp3_conc \\<Gamma> mux2 (\\<lambda>tw. inv  (fst tw + 1, snd tw) \\<and> \n                                                     inv2 (fst tw + 1, snd tw))\", rotated])\n  apply (rule wp3_conc_is_pre, rule conc_stmt_wf_mult, rule nonneg_delay_conc_mult, rule conc_wt_mult, simp)\n  unfolding mux2_def  wp3_conc_single'[OF conc_wt_mult' nonneg_delay_conc_mult'] wp3_fun.simps  \n  using inv_next_time_true inv_next_time_false inv2_next_time mult_conc_hoare mult_conc_hoare2 by presburger\n\ntext \\<open>Initialisation preserves the invariant\\<close>\n\nlemma nonneg_delay_mult:\n  \"nonneg_delay ( Bguarded (Bsig SEL) (Bassign_trans OUT (Bsig IN1) 1) (Bassign_trans OUT (Bsig IN0) 1))\"\n  using nonneg_delay_conc_mult' by auto\n\nlemma init_sat_nand_inv_comb:\n  \"init_sim2_hoare_wt \\<Gamma> (\\<lambda>tw. fst tw = 0) mux2 (\\<lambda>tw. inv tw \\<and> inv2 tw)\"\n  unfolding mux2_def\n  apply (rule AssignI_suc, rule SingleI)\n  apply (rule Conseq3[where Q=\"\\<lambda>tw. inv (fst tw + 1, snd tw) \\<and> inv2 (fst tw + 1, snd tw)\", rotated])\n  apply (rule wp3_fun_is_pre[OF well_typed nonneg_delay_mult], simp)\n  unfolding wp3_fun.simps using inv_next_time_true inv_next_time_false inv2_next_time by auto\n\nlemma correctness:\n  assumes \"sim_fin2 w (i + 1) mux2 tw'\" and \"wityping \\<Gamma> w\"\n  shows \"wline_of tw' OUT (i + 1) = (if bval_of_wline tw' SEL (i) then wline_of tw' IN1 (i) else wline_of tw' IN0 (i))\"\n  using grand_correctness[OF assms conc_stmt_wf_mult conc_wt_mult nonneg_delay_conc_mult mult_conc_sim2' init_sat_nand_inv_comb]\n  unfolding mux2_def inv_def by (metis (no_types, lifting) add_diff_cancel_right' assms(1)\n  sim_fin2.cases world_maxtime_lt_fst_tres)\nend\n\nend", "meta": {"author": "rizaldialbert", "repo": "vhdl-semantics", "sha": "352f89c9ccdfe830c054757dfd86caeadbd67159", "save_path": "github-repos/isabelle/rizaldialbert-vhdl-semantics", "path": "github-repos/isabelle/rizaldialbert-vhdl-semantics/vhdl-semantics-352f89c9ccdfe830c054757dfd86caeadbd67159/Multiplexer_Hoare_Typed.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5078118493816807, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.29904487857598316}}
{"text": "theory TopoS_Stateful_Policy_impl\nimports TopoS_Composition_Theory_impl TopoS_Stateful_Policy_Algorithm\nbegin\n\nsection\\<open>Stateful Policy -- List Implementaion\\<close>\n\nrecord 'v stateful_list_policy =\n    hostsL :: \"'v list\"\n    flows_fixL :: \"('v \\<times>'v) list\"\n    flows_stateL :: \"('v \\<times>'v) list\"\n\n\ndefinition stateful_list_policy_to_list_graph :: \"'v stateful_list_policy \\<Rightarrow> 'v list_graph\" where\n  \"stateful_list_policy_to_list_graph \\<T> = \\<lparr> nodesL = hostsL \\<T>, edgesL = (flows_fixL \\<T>) @ [e \\<leftarrow> flows_stateL \\<T>. e \\<notin> set (flows_fixL \\<T>)] @ [e \\<leftarrow> backlinks (flows_stateL \\<T>). e \\<notin> set (flows_fixL \\<T>)] \\<rparr>\"\n\nlemma stateful_list_policy_to_list_graph_complies:\n  \"list_graph_to_graph (stateful_list_policy_to_list_graph \\<lparr> hostsL = V, flows_fixL = E\\<^sub>f, flows_stateL = E\\<^sub>\\<sigma> \\<rparr>) = \n    stateful_policy_to_network_graph \\<lparr> hosts = set V, flows_fix = set E\\<^sub>f, flows_state = set E\\<^sub>\\<sigma> \\<rparr>\"\n    by(simp add: stateful_list_policy_to_list_graph_def stateful_policy_to_network_graph_def all_flows_def list_graph_to_graph_def backlinks_correct, blast)\n\nlemma wf_list_graph_stateful_list_policy_to_list_graph: \n    \"wf_list_graph G \\<Longrightarrow> distinct E \\<Longrightarrow> set E \\<subseteq> set (edgesL G) \\<Longrightarrow> wf_list_graph (stateful_list_policy_to_list_graph \\<lparr>hostsL = nodesL G, flows_fixL = edgesL G, flows_stateL = E\\<rparr>)\"\n  apply(simp add: wf_list_graph_def stateful_list_policy_to_list_graph_def)\n  apply(rule conjI)\n   apply(simp add: backlinks_distinct)\n  apply(rule conjI)\n   apply(simp add: backlinks_set)\n   apply(blast)\n  apply(rule conjI)\n   apply(simp add: backlinks_set)\n   apply(blast)\n  apply(simp add: wf_list_graph_axioms_def)\n   apply(rule conjI)\n   apply(simp add: backlinks_set)\n   apply(force)\n  apply(simp add: backlinks_set)\n  apply(clarsimp)\n  apply(erule disjE)\n   apply(auto)[1]\n  apply(erule disjE)\n   apply(auto)[1]\n  by force\n  \n\n\nsubsection\\<open>Algorithms\\<close>\n\n   fun filter_IFS_no_violations_accu :: \"'v list_graph \\<Rightarrow> 'v SecurityInvariant list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> ('v \\<times> 'v) list\" where\n      \"filter_IFS_no_violations_accu G M accu [] = accu\" |\n      \"filter_IFS_no_violations_accu G M accu (e#Es) = (if\n        all_security_requirements_fulfilled (TopoS_Composition_Theory_impl.get_IFS M) (stateful_list_policy_to_list_graph \\<lparr> hostsL = nodesL G, flows_fixL = edgesL G, flows_stateL = (e#accu) \\<rparr>)\n        then filter_IFS_no_violations_accu G M (e#accu) Es\n        else filter_IFS_no_violations_accu G M accu Es)\"\n    definition filter_IFS_no_violations :: \"'v list_graph \\<Rightarrow> 'v SecurityInvariant list \\<Rightarrow> ('v \\<times> 'v) list\" where\n      \"filter_IFS_no_violations G M = filter_IFS_no_violations_accu G M [] (edgesL G)\"\n\n   lemma filter_IFS_no_violations_accu_distinct: \"\\<lbrakk> distinct (Es@accu) \\<rbrakk> \\<Longrightarrow> distinct (filter_IFS_no_violations_accu G M accu Es)\"\n    apply(induction Es arbitrary: accu)\n     by(simp_all)\n\n   lemma filter_IFS_no_violations_accu_complies:\n    \"\\<lbrakk>\\<forall> (m_impl, m_spec) \\<in> set M. SecurityInvariant_complies_formal_def m_impl m_spec;\n      wf_list_graph G; set Es \\<subseteq> set (edgesL G); set accu \\<subseteq> set (edgesL G); distinct (Es@accu) \\<rbrakk> \\<Longrightarrow>\n      filter_IFS_no_violations_accu G (get_impl M) accu Es = TopoS_Stateful_Policy_Algorithm.filter_IFS_no_violations_accu (list_graph_to_graph G) (get_spec M) accu Es\"\n      proof(induction Es arbitrary: accu)\n      case Nil\n        thus ?case by(simp add: get_impl_def get_spec_def)\n      next\n      case (Cons e Es)\n        \\<comment> \\<open>@{thm Cons.IH[OF Cons.prems(1) Cons.prems(2)]}\\<close>\n        let ?caseDistinction = \"all_security_requirements_fulfilled (TopoS_Composition_Theory_impl.get_IFS (get_impl M)) (stateful_list_policy_to_list_graph \\<lparr> hostsL = nodesL G, flows_fixL = edgesL G, flows_stateL = (e#accu) \\<rparr>)\"\n\n        from get_IFS_get_ACS_select_simps(2)[OF Cons.prems(1)] have get_impl_zip_simp: \"(get_impl (zip (TopoS_Composition_Theory_impl.get_IFS (get_impl M)) (TopoS_Composition_Theory.get_IFS (get_spec M)))) = TopoS_Composition_Theory_impl.get_IFS (get_impl M)\" by simp\n          \n        from get_IFS_get_ACS_select_simps(3)[OF Cons.prems(1)] have get_spec_zip_simp: \"(get_spec (zip (TopoS_Composition_Theory_impl.get_IFS (get_impl M)) (TopoS_Composition_Theory.get_IFS (get_spec M)))) = TopoS_Composition_Theory.get_IFS (get_spec M)\" by simp\n     \n        from Cons.prems(3) Cons.prems(4) have \"set (e # accu) \\<subseteq> set (edgesL G)\" by simp\n        from Cons.prems(4) have \"set (accu) \\<subseteq> set (edgesL G)\" by simp\n        from Cons.prems(5) have \"distinct (e # accu)\" by simp\n        from Cons.prems(3) have \"set Es \\<subseteq> set (edgesL G)\" by simp\n        from Cons.prems(5) have \"distinct (Es @ accu)\" by simp\n        from Cons.prems(5) have \"distinct (Es @ (e # accu))\" by simp\n\n        from Cons.prems(2) have validLG: \"wf_list_graph (stateful_list_policy_to_list_graph \\<lparr>hostsL = nodesL G, flows_fixL = edgesL G, flows_stateL = e # accu\\<rparr>)\"\n          apply(rule wf_list_graph_stateful_list_policy_to_list_graph)\n           apply(fact \\<open>distinct (e # accu)\\<close>)\n          apply(fact \\<open>set (e # accu) \\<subseteq> set (edgesL G)\\<close>)\n          done\n\n\n        from get_IFS_get_ACS_select_simps(1)[OF Cons.prems(1)]\n        have \"\\<forall> (m_impl, m_spec) \\<in> set (zip (get_IFS (get_impl M)) (TopoS_Composition_Theory.get_IFS (get_spec M))). SecurityInvariant_complies_formal_def m_impl m_spec\" .\n        from all_security_requirements_fulfilled_complies[OF this] have all_security_requirements_fulfilled_eq_rule: \n        \"\\<And>G. wf_list_graph G \\<Longrightarrow>\n            TopoS_Composition_Theory_impl.all_security_requirements_fulfilled (TopoS_Composition_Theory_impl.get_IFS (get_impl M)) G =\n            TopoS_Composition_Theory.all_security_requirements_fulfilled (TopoS_Composition_Theory.get_IFS (get_spec M)) (list_graph_to_graph G)\"\n            by(simp add: get_impl_zip_simp get_spec_zip_simp)\n\n        have case_impl_spec: \"?caseDistinction \\<longleftrightarrow> TopoS_Composition_Theory.all_security_requirements_fulfilled (TopoS_Composition_Theory.get_IFS (get_spec M)) (stateful_policy_to_network_graph \\<lparr> hosts = set (nodesL G), flows_fix = set (edgesL G), flows_state = set (e#accu) \\<rparr>)\"\n          apply(subst all_security_requirements_fulfilled_eq_rule[OF validLG])\n          by(simp add: stateful_list_policy_to_list_graph_complies)\n\n        show ?case\n          proof(case_tac ?caseDistinction)\n          assume cTrue: ?caseDistinction\n          \n          from cTrue have g1: \"TopoS_Stateful_Policy_impl.filter_IFS_no_violations_accu G (get_impl M) accu (e # Es) = TopoS_Stateful_Policy_impl.filter_IFS_no_violations_accu G (get_impl M) (e # accu) Es\" by simp\n\n          from cTrue[simplified case_impl_spec] have g2: \"TopoS_Stateful_Policy_Algorithm.filter_IFS_no_violations_accu (list_graph_to_graph G) (get_spec M) accu (e # Es) =\n            TopoS_Stateful_Policy_Algorithm.filter_IFS_no_violations_accu (list_graph_to_graph G) (get_spec M) (e#accu)Es\"\n            by(simp add: list_graph_to_graph_def)\n\n          show ?case\n            apply(simp only: g1 g2)\n            using Cons.IH[OF Cons.prems(1) Cons.prems(2) \\<open>set Es \\<subseteq> set (edgesL G)\\<close> \\<open>set (e # accu) \\<subseteq> set (edgesL G)\\<close> \\<open>distinct (Es @ (e # accu))\\<close>] by simp\n        next\n          assume cFalse: \"\\<not> ?caseDistinction\"\n\n          from cFalse have g1: \"TopoS_Stateful_Policy_impl.filter_IFS_no_violations_accu G (get_impl M) accu (e # Es) = TopoS_Stateful_Policy_impl.filter_IFS_no_violations_accu G (get_impl M) accu Es\" by simp\n\n          from cFalse[simplified case_impl_spec] have g2: \"TopoS_Stateful_Policy_Algorithm.filter_IFS_no_violations_accu (list_graph_to_graph G) (get_spec M) accu (e # Es) =\n            TopoS_Stateful_Policy_Algorithm.filter_IFS_no_violations_accu (list_graph_to_graph G) (get_spec M) accu Es\"\n            by(simp add: list_graph_to_graph_def)\n\n          show ?case\n            apply(simp only: g1 g2)\n            using Cons.IH[OF Cons.prems(1) Cons.prems(2) \\<open>set Es \\<subseteq> set (edgesL G)\\<close> \\<open>set accu \\<subseteq> set (edgesL G)\\<close> \\<open>distinct (Es @ accu)\\<close>] by simp\n          qed\n       qed\n\n\n\n   lemma filter_IFS_no_violations_complies:\n    \"\\<lbrakk> \\<forall> (m_impl, m_spec) \\<in> set M. SecurityInvariant_complies_formal_def m_impl m_spec; wf_list_graph G \\<rbrakk> \\<Longrightarrow>\n       filter_IFS_no_violations G (get_impl M) = TopoS_Stateful_Policy_Algorithm.filter_IFS_no_violations (list_graph_to_graph G) (get_spec M) (edgesL G)\"\n    apply(unfold filter_IFS_no_violations_def TopoS_Stateful_Policy_Algorithm.filter_IFS_no_violations_def) \n    apply(rule filter_IFS_no_violations_accu_complies)\n        apply(simp_all)\n    apply(simp add: wf_list_graph_def)\n    done\n\n\n\n\n\n    fun filter_compliant_stateful_ACS_accu :: \"'v list_graph \\<Rightarrow> 'v SecurityInvariant list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> ('v \\<times> 'v) list\" where\n      \"filter_compliant_stateful_ACS_accu G M accu [] = accu\" |\n      \"filter_compliant_stateful_ACS_accu G M accu (e#Es) = (if\n        e \\<notin> set (backlinks (edgesL G)) \\<and> (\\<forall>F \\<in> set (implc_get_offending_flows (get_ACS M) (stateful_list_policy_to_list_graph \\<lparr> hostsL = nodesL G, flows_fixL = edgesL G, flows_stateL = (e#accu) \\<rparr>)). set F \\<subseteq> set (backlinks (e#accu)))\n        then filter_compliant_stateful_ACS_accu G M (e#accu) Es\n        else filter_compliant_stateful_ACS_accu G M accu Es)\"\n    definition filter_compliant_stateful_ACS :: \"'v list_graph \\<Rightarrow> 'v SecurityInvariant list \\<Rightarrow> ('v \\<times> 'v) list\" where\n      \"filter_compliant_stateful_ACS G M = filter_compliant_stateful_ACS_accu G M [] (edgesL G)\"\n\n\n   lemma filter_compliant_stateful_ACS_accu_complies: \n    \"\\<lbrakk>\\<forall> (m_impl, m_spec) \\<in> set M. SecurityInvariant_complies_formal_def m_impl m_spec;\n      wf_list_graph G; set Es \\<subseteq> set (edgesL G); set accu \\<subseteq> set (edgesL G); distinct (Es@accu) \\<rbrakk> \\<Longrightarrow>\n      filter_compliant_stateful_ACS_accu G (get_impl M) accu Es = TopoS_Stateful_Policy_Algorithm.filter_compliant_stateful_ACS_accu (list_graph_to_graph G) (get_spec M) accu Es\"\n      proof(induction Es arbitrary: accu)\n      case Nil\n        thus ?case by(simp add: get_impl_def get_spec_def)\n      next\n      case (Cons e Es)\n        \\<comment> \\<open>@{thm Cons.IH[OF Cons.prems(1) Cons.prems(2)]}\\<close>\n        let ?caseDistinction = \"e \\<notin> set (backlinks (edgesL G)) \\<and> (\\<forall>F \\<in> set (implc_get_offending_flows (get_ACS (get_impl M)) (stateful_list_policy_to_list_graph \\<lparr> hostsL = nodesL G, flows_fixL = edgesL G, flows_stateL = (e#accu) \\<rparr>)). set F \\<subseteq> set (backlinks (e#accu)))\"\n        \n        have backlinks_simp: \"(e \\<notin> set (backlinks (edgesL G))) \\<longleftrightarrow> (e \\<notin> backflows (set (edgesL G)))\"\n          by(simp add: backlinks_correct)\n\n        have \"\\<And> G X. (\\<forall>F\\<in>set (implc_get_offending_flows (TopoS_Composition_Theory_impl.get_ACS (get_impl M)) G). set F \\<subseteq> X) =\n              (\\<forall>F\\<in>set ` set (implc_get_offending_flows (TopoS_Composition_Theory_impl.get_ACS (get_impl M)) G). F \\<subseteq> X)\" by blast\n        also have \"\\<And> G X. wf_list_graph G \\<Longrightarrow> (\\<forall>F\\<in>set ` set (implc_get_offending_flows (TopoS_Composition_Theory_impl.get_ACS (get_impl M)) G). F \\<subseteq> X) =\n          (\\<forall>F\\<in>get_offending_flows (TopoS_Composition_Theory.get_ACS (get_spec M)) (list_graph_to_graph G). F \\<subseteq> X)\"\n            using implc_get_offending_flows_complies[OF get_IFS_get_ACS_select_simps(4)[OF Cons.prems(1)], simplified get_IFS_get_ACS_select_simps[OF Cons.prems(1)]] by simp\n        finally have implc_get_offending_flows_simp_rule: \"\\<And>G X. wf_list_graph G \\<Longrightarrow> \n          (\\<forall>F\\<in>set (implc_get_offending_flows (TopoS_Composition_Theory_impl.get_ACS (get_impl M)) G). set F \\<subseteq> X) = (\\<forall>F\\<in>get_offending_flows (TopoS_Composition_Theory.get_ACS (get_spec M)) (list_graph_to_graph G). F \\<subseteq> X)\" .\n\n\n        from Cons.prems(3) Cons.prems(4) have \"set (e # accu) \\<subseteq> set (edgesL G)\" by simp\n        from Cons.prems(4) have \"set (accu) \\<subseteq> set (edgesL G)\" by simp\n        from Cons.prems(5) have \"distinct (e # accu)\" by simp\n        from Cons.prems(3) have \"set Es \\<subseteq> set (edgesL G)\" by simp\n        from Cons.prems(5) have \"distinct (Es @ accu)\" by simp\n        from Cons.prems(5) have \"distinct (Es @ (e # accu))\" by simp\n        from Cons.prems(2) have validLG: \"wf_list_graph (stateful_list_policy_to_list_graph \\<lparr>hostsL = nodesL G, flows_fixL = edgesL G, flows_stateL = e # accu\\<rparr>)\"\n          apply(rule wf_list_graph_stateful_list_policy_to_list_graph)\n           apply(fact \\<open>distinct (e # accu)\\<close>)\n          apply(fact \\<open>set (e # accu) \\<subseteq> set (edgesL G)\\<close>)\n          done\n\n        have \"set (backlinks (e # accu)) = backflows (insert e (set accu))\"\n          by(simp add: backlinks_set backflows_def)\n        \n        \\<comment> \\<open>@{thm implc_get_offending_flows_simp_rule[OF validLG]}\\<close>\n        have case_impl_spec: \"?caseDistinction \\<longleftrightarrow> (\n          e \\<notin> backflows (set (edgesL G)) \\<and> (\\<forall>F \\<in> get_offending_flows (TopoS_Composition_Theory.get_ACS (get_spec M)) (stateful_policy_to_network_graph \\<lparr> hosts = set (nodesL G), flows_fix = set (edgesL G), flows_state = set (e#accu) \\<rparr>). F \\<subseteq> (backflows (set (e#accu)))))\" \n          apply(simp add: backlinks_simp)\n          apply(simp add: implc_get_offending_flows_simp_rule[OF validLG])\n          apply(simp add: stateful_list_policy_to_list_graph_complies)\n          by(simp add: \\<open>set (backlinks (e # accu)) = backflows (insert e (set accu))\\<close>)\n          \n\n        show ?case\n          proof(case_tac ?caseDistinction)\n          assume cTrue: ?caseDistinction\n          \n          from cTrue have g1: \"TopoS_Stateful_Policy_impl.filter_compliant_stateful_ACS_accu G (get_impl M) accu (e # Es) =  TopoS_Stateful_Policy_impl.filter_compliant_stateful_ACS_accu G (get_impl M) (e#accu) Es\" by simp\n\n          from cTrue[simplified case_impl_spec] have g2: \"TopoS_Stateful_Policy_Algorithm.filter_compliant_stateful_ACS_accu (list_graph_to_graph G) (get_spec M) accu (e # Es) =\n            TopoS_Stateful_Policy_Algorithm.filter_compliant_stateful_ACS_accu (list_graph_to_graph G) (get_spec M) (e#accu) Es\"\n            by(simp add: list_graph_to_graph_def)\n\n          show ?case\n            apply(simp only: g1 g2)\n            using Cons.IH[OF Cons.prems(1) Cons.prems(2) \\<open>set Es \\<subseteq> set (edgesL G)\\<close> \\<open>set (e # accu) \\<subseteq> set (edgesL G)\\<close> \\<open>distinct (Es @ (e # accu))\\<close>] by simp\n        next\n          assume cFalse: \"\\<not> (?caseDistinction)\"\n\n          from cFalse have g1: \"TopoS_Stateful_Policy_impl.filter_compliant_stateful_ACS_accu G (get_impl M) accu (e # Es)  = TopoS_Stateful_Policy_impl.filter_compliant_stateful_ACS_accu G (get_impl M) accu Es\" by force\n\n          from cFalse[simplified case_impl_spec] have g2: \"TopoS_Stateful_Policy_Algorithm.filter_compliant_stateful_ACS_accu (list_graph_to_graph G) (get_spec M) accu (e # Es) =\n            TopoS_Stateful_Policy_Algorithm.filter_compliant_stateful_ACS_accu (list_graph_to_graph G) (get_spec M) accu Es\"\n            apply(simp add: list_graph_to_graph_def) by fast\n\n          show ?case\n            apply(simp only: g1 g2)\n            using Cons.IH[OF Cons.prems(1) Cons.prems(2) \\<open>set Es \\<subseteq> set (edgesL G)\\<close> \\<open>set accu \\<subseteq> set (edgesL G)\\<close> \\<open>distinct (Es @ accu)\\<close>] by simp\n          qed\n       qed\n\n\n   lemma filter_compliant_stateful_ACS_cont_complies:\n    \"\\<lbrakk> \\<forall> (m_impl, m_spec) \\<in> set M. SecurityInvariant_complies_formal_def m_impl m_spec; wf_list_graph G; set Es \\<subseteq> set (edgesL G); distinct Es \\<rbrakk> \\<Longrightarrow>\n       filter_compliant_stateful_ACS_accu G (get_impl M) [] Es = TopoS_Stateful_Policy_Algorithm.filter_compliant_stateful_ACS (list_graph_to_graph G) (get_spec M) Es\"\n    apply(unfold filter_compliant_stateful_ACS_def TopoS_Stateful_Policy_Algorithm.filter_compliant_stateful_ACS_def) \n    apply(rule filter_compliant_stateful_ACS_accu_complies)\n        apply(simp_all)\n    done\n\n   lemma filter_compliant_stateful_ACS_complies:\n    \"\\<lbrakk> \\<forall> (m_impl, m_spec) \\<in> set M. SecurityInvariant_complies_formal_def m_impl m_spec; wf_list_graph G \\<rbrakk> \\<Longrightarrow>\n       filter_compliant_stateful_ACS G (get_impl M) = TopoS_Stateful_Policy_Algorithm.filter_compliant_stateful_ACS (list_graph_to_graph G) (get_spec M) (edgesL G)\"\n    apply(unfold filter_compliant_stateful_ACS_def TopoS_Stateful_Policy_Algorithm.filter_compliant_stateful_ACS_def) \n    apply(rule filter_compliant_stateful_ACS_accu_complies)\n        apply(simp_all)\n    apply(simp add: wf_list_graph_def)\n    done\n\n\n(*TODO: show wf_stateful_policy and distinctness and wf_list_graph, ...*)\n\n\n   definition generate_valid_stateful_policy_IFSACS :: \"'v list_graph \\<Rightarrow> 'v SecurityInvariant list \\<Rightarrow> 'v stateful_list_policy\" where\n    \"generate_valid_stateful_policy_IFSACS G M = (let filterIFS = filter_IFS_no_violations G M in\n        (let filterACS = filter_compliant_stateful_ACS_accu G M [] filterIFS in \\<lparr> hostsL = nodesL G, flows_fixL = edgesL G, flows_stateL = filterACS \\<rparr>))\"\n\n\n\n  fun inefficient_list_intersect :: \"'a list \\<Rightarrow> 'a list \\<Rightarrow> 'a list\" where\n    \"inefficient_list_intersect [] bs = []\" |\n    \"inefficient_list_intersect (a#as) bs = (if a \\<in> set bs then a#(inefficient_list_intersect as bs) else inefficient_list_intersect as bs)\"\n  lemma inefficient_list_intersect_correct: \"set (inefficient_list_intersect a b) = (set a) \\<inter> (set b)\"\n    apply(induction a)\n     by(simp_all)\n\n  definition generate_valid_stateful_policy_IFSACS_2 :: \"'v list_graph \\<Rightarrow> 'v SecurityInvariant list \\<Rightarrow>  'v stateful_list_policy\" where\n    \"generate_valid_stateful_policy_IFSACS_2 G M =\n    \\<lparr> hostsL = nodesL G, flows_fixL = edgesL G, flows_stateL = inefficient_list_intersect (filter_IFS_no_violations G M) (filter_compliant_stateful_ACS G M) \\<rparr>\"\n\n\n   lemma generate_valid_stateful_policy_IFSACS_2_complies: \"\\<lbrakk>\\<forall> (m_impl, m_spec) \\<in> set M. SecurityInvariant_complies_formal_def m_impl m_spec;\n          wf_list_graph G;\n          valid_reqs (get_spec M);\n          TopoS_Composition_Theory.all_security_requirements_fulfilled (get_spec M) (list_graph_to_graph G);\n          \\<T> = (generate_valid_stateful_policy_IFSACS_2 G (get_impl M))\\<rbrakk> \\<Longrightarrow> \n   stateful_policy_compliance \\<lparr>hosts = set (hostsL \\<T>), flows_fix = set (flows_fixL \\<T>), flows_state = set (flows_stateL \\<T>) \\<rparr> (list_graph_to_graph G) (get_spec M)\"\n    apply(rule_tac edgesList=\"edgesL G\" in generate_valid_stateful_policy_IFSACS_2_stateful_policy_compliance)\n        apply(simp)\n       apply (metis wf_list_graph_def wf_list_graph_iff_wf_graph)\n      apply(simp)\n     apply(simp add: list_graph_to_graph_def)\n    apply(simp add: TopoS_Stateful_Policy_Algorithm.generate_valid_stateful_policy_IFSACS_2_def TopoS_Stateful_Policy_impl.generate_valid_stateful_policy_IFSACS_2_def)\n    apply(simp add: list_graph_to_graph_def inefficient_list_intersect_correct)\n    apply(thin_tac \"\\<T> = _\")\n    apply(frule(1) filter_compliant_stateful_ACS_complies)\n    apply(frule(1) filter_IFS_no_violations_complies)\n    apply(thin_tac \"_\")\n    apply(thin_tac \"_\")\n    apply(thin_tac \"_\")\n    apply(thin_tac \"_\")\n    apply(simp)\n    by (metis list_graph_to_graph_def)\n    \n\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Network_Security_Policy_Verification/TopoS_Stateful_Policy_impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.665410572017153, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.29903060995949104}}
{"text": "subsection \\<open>Heap Memory Implementations\\<close>\n\ntheory Memory_Heap\n  imports State_Heap DP_CRelVH Pair_Memory \"HOL-Eisbach.Eisbach\" \"../Index\"\nbegin\n\ntext \\<open>Move\\<close>\nabbreviation \"result_of c h \\<equiv> fst (the (execute c h))\"\nabbreviation \"heap_of   c h \\<equiv> snd (the (execute c h))\"\n\nlemma map_emptyI:\n  \"m \\<subseteq>\\<^sub>m Map.empty\" if \"\\<And> x. m x = None\"\n  using that unfolding map_le_def by auto\n\nlemma result_of_return[simp]:\n  \"result_of (Heap_Monad.return x) h = x\"\n  by (simp add: execute_simps)\n\nlemma get_result_of_lookup:\n  \"result_of (!r) heap = x\" if \"Ref.get heap r = x\"\n  using that by (auto simp: execute_simps)\n\ncontext\n  fixes size :: nat\n    and to_index :: \"('k2 :: heap) \\<Rightarrow> nat\"\nbegin\n\ndefinition\n  \"mem_empty = (Array.new size (None :: ('v :: heap) option))\"\n\nlemma success_empty[intro]:\n  \"success mem_empty heap\"\n  unfolding mem_empty_def by (auto intro: success_intros)\n\nlemma length_mem_empty:\n  \"Array.length\n    (heap_of (mem_empty:: (('b :: heap) option array) Heap) h)\n    (result_of (mem_empty :: ('b option array) Heap) h) = size\"\n  unfolding mem_empty_def by (auto simp: execute_simps Array.length_alloc)\n\nlemma nth_mem_empty:\n  \"result_of\n    (Array.nth (result_of (mem_empty :: ('b option array) Heap) h) i)\n    (heap_of (mem_empty :: (('b :: heap) option array) Heap) h) = None\" if \"i < size\"\n  apply (subst execute_nth(1))\n  apply (simp add: length_mem_empty that)\n  apply (simp add: execute_simps mem_empty_def Array.get_alloc that)\n  done\n\ncontext\n  fixes mem :: \"('v :: heap) option array\"\nbegin\n\ndefinition\n  \"mem_lookup k = (let i = to_index k in\n    if i < size then Array.nth mem i else return None\n  )\"\n\ndefinition\n  \"mem_update k v = (let i = to_index k in\n    if i < size then (Array.upd i (Some v) mem \\<bind> (\\<lambda> _. return ()))\n    else return ()\n  )\n  \"\n\ncontext assumes injective: \"injective size to_index\"\nbegin\n\ninterpretation heap_correct \"\\<lambda>heap. Array.length heap mem = size\" mem_update mem_lookup\n  apply standard\n  subgoal lookup_inv\n    unfolding State_Heap.lift_p_def mem_lookup_def by (simp add: Let_def execute_simps)\n  subgoal update_inv\n    unfolding State_Heap.lift_p_def mem_update_def by (simp add: Let_def execute_simps)\n  subgoal for k heap\n    unfolding heap_mem_defs.map_of_heap_def map_le_def mem_lookup_def\n    by (auto simp: execute_simps Let_def split: if_split_asm)\n  subgoal for heap k\n    unfolding heap_mem_defs.map_of_heap_def map_le_def mem_lookup_def mem_update_def\n    apply (auto simp: execute_simps Let_def length_def split: if_split_asm)\n    apply (subst (asm) nth_list_update_neq)\n    using injective[unfolded injective_def] apply auto\n    done\n  done\n\nlemmas mem_heap_correct = heap_correct_axioms\n\ncontext\n  assumes [simp]: \"mem = result_of mem_empty Heap.empty\"\nbegin\n\ninterpretation heap_correct_empty\n  \"\\<lambda>heap. Array.length heap mem = size\" mem_update mem_lookup\n  \"heap_of (mem_empty :: 'v option array Heap) Heap.empty\"\n  apply standard\n  subgoal\n    apply (rule map_emptyI)\n    unfolding map_of_heap_def mem_lookup_def by (auto simp: Let_def nth_mem_empty)\n  subgoal\n    by (simp add: length_mem_empty)\n  done\n\nlemmas array_heap_emptyI = heap_correct_empty_axioms\n\ncontext\n  fixes dp :: \"'k2 \\<Rightarrow> 'v\"\nbegin\n\ninterpretation dp_consistency_heap_empty\n  \"\\<lambda>heap. Array.length heap mem = size\" mem_update mem_lookup dp\n  \"heap_of (mem_empty :: 'v option array Heap) Heap.empty\"\n  by standard\n\nlemmas array_consistentI = dp_consistency_heap_empty_axioms\n\nend\n\nend (* Empty Memory *)\n\nend (* Injectivity *)\n\nend (* Fixed array *)\n\nlemma execute_bind_success':\n  assumes \"success f h\" \"execute (f \\<bind> g) h = Some (y, h'')\"\n  obtains x h' where \"execute f h = Some (x, h')\" \"execute (g x) h' = Some (y, h'')\"\n  using assms by (auto simp: execute_simps elim: successE)\n\nlemma success_bind_I:\n  assumes \"success f h\"\n    and \"\\<And> x h'. execute f h = Some (x, h') \\<Longrightarrow> success (g x) h'\"\n  shows \"success (f \\<bind> g) h\"\n  by (rule successE[OF assms(1)]) (auto elim: assms(2) intro: success_bind_executeI)\n\ndefinition\n  \"alloc_pair a b \\<equiv> do {\n    r1 \\<leftarrow> ref a;\n    r2 \\<leftarrow> ref b;\n    return (r1, r2)\n  }\"\n\nlemma alloc_pair_alloc:\n  \"Ref.get heap' r1 = a\" \"Ref.get heap' r2 = b\"\n  if \"execute (alloc_pair a b) heap = Some ((r1, r2), heap')\"\n  using that unfolding alloc_pair_def\n  by (auto simp: execute_simps elim!: execute_bind_success'[OF success_refI])\n     (metis Ref.get_alloc fst_conv get_alloc_neq next_present present_alloc_neq snd_conv)+\n\nlemma alloc_pairD1:\n  \"r =!= r1 \\<and> r =!= r2 \\<and> Ref.present heap' r\"\n  if \"execute (alloc_pair a b) heap = Some ((r1, r2), heap')\" \"Ref.present heap r\"\n  using that unfolding alloc_pair_def\n  by (auto simp: execute_simps elim!: execute_bind_success'[OF success_refI])\n     (metis next_fresh noteq_I Ref.present_alloc snd_conv)+\n\nlemma alloc_pairD2:\n  \"r1 =!= r2 \\<and> Ref.present heap' r2 \\<and> Ref.present heap' r1\"\n  if \"execute (alloc_pair a b) heap = Some ((r1, r2), heap')\"\n  using that unfolding alloc_pair_def\n  by (auto simp: execute_simps elim!: execute_bind_success'[OF success_refI])\n     (metis next_fresh next_present noteq_I Ref.present_alloc snd_conv)+\n\nlemma alloc_pairD3:\n  \"Array.present heap' r\"\n  if \"execute (alloc_pair a b) heap = Some ((r1, r2), heap')\" \"Array.present heap r\"\n  using that unfolding alloc_pair_def\n  by (auto simp: execute_simps elim!: execute_bind_success'[OF success_refI])\n     (metis array_present_alloc snd_conv)\n\nlemma alloc_pairD4:\n  \"Ref.get heap' r = x\"\n  if \"execute (alloc_pair a b) heap = Some ((r1, r2), heap')\"\n     \"Ref.get heap r = x\" \"Ref.present heap r\"\n  using that unfolding alloc_pair_def\n  by (auto simp: execute_simps elim!: execute_bind_success'[OF success_refI])\n     (metis Ref.not_present_alloc Ref.present_alloc get_alloc_neq noteq_I snd_conv)\n\nlemma alloc_pair_array_get:\n  \"Array.get heap' r = x\"\n  if \"execute (alloc_pair a b) heap = Some ((r1, r2), heap')\" \"Array.get heap r = x\"\n  using that unfolding alloc_pair_def\n  by (auto simp: execute_simps elim!: execute_bind_success'[OF success_refI])\n (metis array_get_alloc snd_conv)\n\nlemma alloc_pair_array_length:\n  \"Array.length heap' r = Array.length heap r\"\n  if \"execute (alloc_pair a b) heap = Some ((r1, r2), heap')\"\n  using that unfolding alloc_pair_def\n  by (auto simp: execute_simps elim!: execute_bind_success'[OF success_refI])\n     (metis Ref.length_alloc snd_conv)\n\nlemma alloc_pair_nth:\n  \"result_of (Array.nth r i) heap' = result_of (Array.nth r i) heap\"\n  if \"execute (alloc_pair a b) heap = Some ((r1, r2), heap')\"\n  using alloc_pair_array_get[OF that(1) HOL.refl, of r] alloc_pair_array_length[OF that(1), of r]\n  by (cases \"(\\<lambda>h. i < Array.length h r) heap\"; simp add: execute_simps Array.nth_def)\n\nlemma succes_alloc_pair[intro]:\n  \"success (alloc_pair a b) heap\"\n  unfolding alloc_pair_def by (auto intro: success_intros success_bind_I)\n\ndefinition\n  \"init_state_inner k1 k2 m1 m2 \\<equiv>  do {\n    (k_ref1, k_ref2) \\<leftarrow> alloc_pair k1 k2;\n    (m_ref1, m_ref2) \\<leftarrow> alloc_pair m1 m2;\n    return (k_ref1, k_ref2, m_ref1, m_ref2)\n  }\n  \"\n\nlemma init_state_inner_alloc:\n  assumes\n    \"execute (init_state_inner k1 k2 m1 m2) heap = Some ((k_ref1, k_ref2, m_ref1, m_ref2), heap')\"\n  shows\n    \"Ref.get heap' k_ref1 = k1\" \"Ref.get heap' k_ref2 = k2\"\n    \"Ref.get heap' m_ref1 = m1\" \"Ref.get heap' m_ref2 = m2\"\n  using assms unfolding init_state_inner_def\n  by (auto simp: execute_simps elim!: execute_bind_success'[OF succes_alloc_pair])\n     (auto intro: alloc_pair_alloc dest: alloc_pairD2 elim: alloc_pairD4)\n\nlemma init_state_inner_distinct:\n  assumes\n    \"execute (init_state_inner k1 k2 m1 m2) heap = Some ((k_ref1, k_ref2, m_ref1, m_ref2), heap')\"\n  shows\n    \"m_ref1 =!= m_ref2 \\<and> m_ref1 =!= k_ref1 \\<and> m_ref1 =!= k_ref2 \\<and> m_ref2 =!= k_ref1\n   \\<and> m_ref2 =!= k_ref2 \\<and> k_ref1 =!= k_ref2\"\n  using assms unfolding init_state_inner_def\n  by (auto simp: execute_simps elim!: execute_bind_success'[OF succes_alloc_pair])\n     (blast dest: alloc_pairD1 alloc_pairD2 intro: noteq_sym)+\n\nlemma init_state_inner_present:\n  assumes\n    \"execute (init_state_inner k1 k2 m1 m2) heap = Some ((k_ref1, k_ref2, m_ref1, m_ref2), heap')\"\n  shows\n    \"Ref.present heap' k_ref1\" \"Ref.present heap' k_ref2\"\n    \"Ref.present heap' m_ref1\" \"Ref.present heap' m_ref2\"\n  using assms unfolding init_state_inner_def\n  by (auto simp: execute_simps elim!: execute_bind_success'[OF succes_alloc_pair])\n     (blast dest: alloc_pairD1 alloc_pairD2)+\n\nlemma inite_state_inner_present':\n  assumes\n    \"execute (init_state_inner k1 k2 m1 m2) heap = Some ((k_ref1, k_ref2, m_ref1, m_ref2), heap')\"\n    \"Array.present heap a\"\n  shows\n    \"Array.present heap' a\"\n    using assms unfolding init_state_inner_def\n    by (auto simp: execute_simps elim!: execute_bind_success'[OF succes_alloc_pair] alloc_pairD3)\n\nlemma succes_init_state_inner[intro]:\n  \"success (init_state_inner k1 k2 m1 m2) heap\"\n  unfolding init_state_inner_def by (auto 4 3 intro: success_intros success_bind_I)\n\nlemma init_state_inner_nth:\n  \"result_of (Array.nth r i) heap' = result_of (Array.nth r i) heap\"\n  if \"execute (init_state_inner k1 k2 m1 m2) heap = Some ((r1, r2), heap')\"\n  using that unfolding init_state_inner_def\n  by (auto simp: execute_simps alloc_pair_nth elim!: execute_bind_success'[OF succes_alloc_pair])\n\ndefinition\n  \"init_state k1 k2 \\<equiv> do {\n    m1 \\<leftarrow> mem_empty;\n    m2 \\<leftarrow> mem_empty;\n    init_state_inner k1 k2 m1 m2\n  }\"\n\n\n\ndefinition\n  \"inv_distinct k_ref1 k_ref2 m_ref1 m_ref2 \\<equiv>\n     m_ref1 =!= m_ref2 \\<and> m_ref1 =!= k_ref1 \\<and> m_ref1 =!= k_ref2 \\<and> m_ref2 =!= k_ref1\n   \\<and> m_ref2 =!= k_ref2 \\<and> k_ref1 =!= k_ref2\n  \"\n\nlemma init_state_distinct:\n  assumes\n    \"execute (init_state k1 k2) heap = Some ((k_ref1, k_ref2, m_ref1, m_ref2), heap')\"\n  shows\n    \"inv_distinct k_ref1 k_ref2 m_ref1 m_ref2\"\n  using assms unfolding init_state_def inv_distinct_def\n  by (elim execute_bind_success'[OF success_empty] init_state_inner_distinct)\n\nlemma init_state_present:\n  assumes\n    \"execute (init_state k1 k2) heap = Some ((k_ref1, k_ref2, m_ref1, m_ref2), heap')\"\n  shows\n    \"Ref.present heap' k_ref1\" \"Ref.present heap' k_ref2\"\n    \"Ref.present heap' m_ref1\" \"Ref.present heap' m_ref2\"\n  using assms unfolding init_state_def\n  by (auto\n        simp: execute_simps elim!: execute_bind_success'[OF success_empty]\n        dest: init_state_inner_present\n     )\n\nlemma empty_present:\n  \"Array.present h' x\" if \"execute mem_empty heap = Some (x, h')\"\n  using that unfolding mem_empty_def\n  by (auto simp: execute_simps) (metis Array.present_alloc fst_conv snd_conv)\n\nlemma empty_present':\n  \"Array.present h' a\" if \"execute mem_empty heap = Some (x, h')\" \"Array.present heap a\"\n  using that unfolding mem_empty_def\n  by (auto simp: execute_simps Array.present_def Array.alloc_def Array.set_def Let_def)\n\nlemma init_state_present2:\n  assumes\n    \"execute (init_state k1 k2) heap = Some ((k_ref1, k_ref2, m_ref1, m_ref2), heap')\"\n  shows\n    \"Array.present heap' (Ref.get heap' m_ref1)\" \"Array.present heap' (Ref.get heap' m_ref2)\"\n  using assms unfolding init_state_def\n  by (auto 4 3\n        simp: execute_simps init_state_inner_alloc elim!: execute_bind_success'[OF success_empty]\n        dest: inite_state_inner_present' empty_present empty_present'\n     )\n\nlemma init_state_neq:\n  assumes\n    \"execute (init_state k1 k2) heap = Some ((k_ref1, k_ref2, m_ref1, m_ref2), heap')\"\n  shows\n    \"Ref.get heap' m_ref1 =!!= Ref.get heap' m_ref2\"\n  using assms unfolding init_state_def\n  by (auto 4 3\n        simp: execute_simps init_state_inner_alloc elim!: execute_bind_success'[OF success_empty]\n        dest: inite_state_inner_present' empty_present empty_present'\n     )\n    (metis empty_present execute_new fst_conv mem_empty_def option.inject present_alloc_noteq)\n\nlemma present_alloc_get:\n  \"Array.get heap' a = Array.get heap a\"\n  if \"Array.alloc xs heap = (a', heap')\" \"Array.present heap a\"\n  using that by (auto simp: Array.alloc_def Array.present_def Array.get_def Let_def Array.set_def)\n\nlemma init_state_length:\n  assumes\n    \"execute (init_state k1 k2) heap = Some ((k_ref1, k_ref2, m_ref1, m_ref2), heap')\"\n  shows\n    \"Array.length heap' (Ref.get heap' m_ref1) = size\"\n    \"Array.length heap' (Ref.get heap' m_ref2) = size\"\n  using assms unfolding init_state_def\n  apply (auto\n        simp: execute_simps init_state_inner_alloc elim!: execute_bind_success'[OF success_empty]\n        dest: inite_state_inner_present' empty_present empty_present'\n     )\n   apply (auto\n      simp: execute_simps init_state_inner_def alloc_pair_def mem_empty_def Array.length_def\n      elim!: execute_bind_success'[OF success_refI]\n     )\n  apply (metis\n      Array.alloc_def Array.get_set_eq Array.present_alloc array_get_alloc fst_conv length_replicate\n      present_alloc_get snd_conv\n     )+\n  done\n\ncontext\n  fixes key1 :: \"'k \\<Rightarrow> ('k1 :: heap)\" and key2 :: \"'k \\<Rightarrow> 'k2\"\n    and m_ref1 m_ref2 :: \"('v :: heap) option array ref\"\n    and k_ref1 k_ref2 :: \"('k1 :: heap) ref\"\nbegin\n\ntext \\<open>We assume that look-ups happen on the older row, so this is biased towards the second entry.\\<close>\ndefinition\n  \"lookup_pair k = do {\n    let k' = key1 k;\n    k2 \\<leftarrow> !k_ref2;\n    if k' = k2 then\n      do {\n        m2 \\<leftarrow> !m_ref2;\n        mem_lookup m2 (key2 k)\n      }\n    else\n      do {\n      k1 \\<leftarrow> !k_ref1;\n      if k' = k1 then\n        do {\n          m1 \\<leftarrow> !m_ref1;\n          mem_lookup m1 (key2 k)\n        }\n      else\n        return None\n    }\n  }\n   \"\n\ntext \\<open>We assume that updates happen on the newer row, so this is biased towards the first entry.\\<close>\ndefinition\n  \"update_pair k v = do {\n    let k' = key1 k;\n      k1 \\<leftarrow> !k_ref1;\n      if k' = k1 then do {\n        m \\<leftarrow> !m_ref1;\n        mem_update m (key2 k) v\n      }\n      else do {\n        k2 \\<leftarrow> !k_ref2;\n        if k' = k2 then do {\n          m \\<leftarrow> !m_ref2;\n          mem_update m (key2 k) v\n        }\n        else do {\n          do {\n            k1 \\<leftarrow> !k_ref1;\n            m \\<leftarrow> mem_empty;\n            m1 \\<leftarrow> !m_ref1;\n            k_ref2 := k1;\n            k_ref1 := k';\n            m_ref2 := m1;\n            m_ref1 := m\n          }\n        ;\n        m \\<leftarrow> !m_ref1;\n        mem_update m (key2 k) v\n      }\n    }\n   }\n   \"\n\ndefinition\n  \"inv_pair_weak heap = (\n    let\n      m1 = Ref.get heap m_ref1;\n      m2 = Ref.get heap m_ref2\n    in Array.length heap m1 = size \\<and> Array.length heap m2 = size\n      \\<and> Ref.present heap k_ref1 \\<and> Ref.present heap k_ref2\n      \\<and> Ref.present heap m_ref1 \\<and> Ref.present heap m_ref2\n      \\<and> Array.present heap m1 \\<and> Array.present heap m2\n      \\<and> m1 =!!= m2\n  )\"\n\n(* TODO: Remove? *)\ndefinition\n  \"inv_pair heap \\<equiv> inv_pair_weak heap \\<and> inv_distinct k_ref1 k_ref2 m_ref1 m_ref2\"\n\nlemma init_state_inv:\n  assumes\n    \"execute (init_state k1 k2) heap = Some ((k_ref1, k_ref2, m_ref1, m_ref2), heap')\"\n  shows \"inv_pair_weak heap'\"\n  using assms unfolding inv_pair_weak_def Let_def\n  by (auto intro:\n      init_state_present init_state_present2 init_state_neq init_state_length\n      init_state_distinct\n     )\n\nlemma inv_pair_lengthD1:\n  \"Array.length heap (Ref.get heap m_ref1) = size\" if \"inv_pair_weak heap\"\n  using that unfolding inv_pair_weak_def by (auto simp: Let_def)\n\nlemma inv_pair_lengthD2:\n  \"Array.length heap (Ref.get heap m_ref2) = size\" if \"inv_pair_weak heap\"\n  using that unfolding inv_pair_weak_def by (auto simp: Let_def)\n\nlemma inv_pair_presentD:\n  \"Array.present heap (Ref.get heap m_ref1)\" \"Array.present heap (Ref.get heap m_ref2)\"\n  if \"inv_pair_weak heap\"\n  using that unfolding inv_pair_weak_def by (auto simp: Let_def)\n\nlemma inv_pair_presentD2:\n  \"Ref.present heap m_ref1\" \"Ref.present heap m_ref2\"\n  \"Ref.present heap k_ref1\" \"Ref.present heap k_ref2\"\n  if \"inv_pair_weak heap\"\n  using that unfolding inv_pair_weak_def by (auto simp: Let_def)\n\nlemma inv_pair_not_eqD:\n  \"Ref.get heap m_ref1 =!!= Ref.get heap m_ref2\" if \"inv_pair_weak heap\"\n  using that unfolding inv_pair_weak_def by (auto simp: Let_def)\n\ndefinition \"lookup1 k \\<equiv> state_of (do {m \\<leftarrow> !m_ref1; mem_lookup m k})\"\n\ndefinition \"lookup2 k \\<equiv> state_of (do {m \\<leftarrow> !m_ref2; mem_lookup m k})\"\n\ndefinition \"update1 k v \\<equiv> state_of (do {m \\<leftarrow> !m_ref1; mem_update m k v})\"\n\ndefinition \"update2 k v \\<equiv> state_of (do {m \\<leftarrow> !m_ref2; mem_update m k v})\"\n\ndefinition \"move12 k \\<equiv> state_of (do {\n    k1 \\<leftarrow> !k_ref1;\n    m \\<leftarrow> mem_empty;\n    m1 \\<leftarrow> !m_ref1;\n    k_ref2 := k1;\n    k_ref1 := k;\n    m_ref2 := m1;\n    m_ref1 := m\n  })\n  \"\n\ndefinition \"get_k1 \\<equiv> state_of (!k_ref1)\"\n\ndefinition \"get_k2 \\<equiv> state_of (!k_ref2)\"\n\nlemma run_state_state_of[simp]:\n  \"State_Monad.run_state (state_of p) m = the (execute p m)\"\n  unfolding state_of_def by simp\n\ncontext assumes injective: \"injective size to_index\"\nbegin\n\ncontext\n  assumes inv_distinct: \"inv_distinct k_ref1 k_ref2 m_ref1 m_ref2\"\nbegin\n\nlemma disjoint[simp]:\n  \"m_ref1 =!= m_ref2\" \"m_ref1 =!= k_ref1\" \"m_ref1 =!= k_ref2\"\n  \"m_ref2 =!= k_ref1\" \"m_ref2 =!= k_ref2\"\n  \"k_ref1 =!= k_ref2\"\n  using inv_distinct unfolding inv_distinct_def by auto\n\nlemmas [simp] = disjoint[THEN noteq_sym]\n\n\n\nlemma [simp]:\n  \"Ref.get (snd (Array.alloc xs heap)) r = Ref.get heap r\" if \"Ref.present heap r\"\n  using that unfolding Array.alloc_def Ref.present_def\n  by (simp add: Let_def Ref.get_def Array.set_def)\n\n\n\nlemma alloc_present':\n  \"Ref.present (snd (Array.alloc xs heap)) r\" if \"Ref.present heap r\"\n  using that unfolding Ref.present_def Array.alloc_def by (simp add: Let_def Array.set_def)\n\nlemma length_get_upd[simp]:\n  \"length (Array.get (Array.update a i x heap) r) = length (Array.get heap r)\"\n  unfolding Array.get_def Array.update_def Array.set_def by simp\n\nmethod solve1 =\n  (frule inv_pair_lengthD1, frule inv_pair_lengthD2, frule inv_pair_not_eqD)?,\n  auto split: if_split_asm dest: Array.noteq_sym\n\ninterpretation pair: pair_mem lookup1 lookup2 update1 update2 move12 get_k1 get_k2 inv_pair_weak\n  supply [simp] =\n    mem_empty_def state_mem_defs.map_of_def map_le_def\n    move12_def update1_def update2_def lookup1_def lookup2_def get_k1_def get_k2_def\n    mem_update_def mem_lookup_def\n    execute_bind_success[OF success_newI] execute_simps Let_def Array.get_alloc length_def\n    inv_pair_presentD inv_pair_presentD2\n    Memory_Heap.lookup1_def Memory_Heap.lookup2_def Memory_Heap.mem_lookup_def\n  apply standard\n                      apply (solve1; fail)+\n  subgoal\n    apply (rule lift_pI)\n    unfolding inv_pair_weak_def\n    apply (auto simp:\n        intro: alloc_present alloc_present'\n        elim: present_alloc_noteq[THEN Array.noteq_sym]\n        )\n    done\n                     apply (rule lift_pI, unfold inv_pair_weak_def, auto split: if_split_asm; fail)+\n                 apply (solve1; fail)+\n  subgoal\n    using injective[unfolded injective_def] by - (solve1, subst (asm) nth_list_update_neq, auto)\n  subgoal\n    using injective[unfolded injective_def] by - (solve1, subst (asm) nth_list_update_neq, auto)\n   apply (solve1; fail)+\n  done\n\nlemmas mem_correct_pair = pair.mem_correct_pair\n\ndefinition\n  \"mem_lookup1 k = do {m \\<leftarrow> !m_ref1; mem_lookup m k}\"\n\ndefinition\n  \"mem_lookup2 k = do {m \\<leftarrow> !m_ref2; mem_lookup m k}\"\n\ndefinition \"get_k1' \\<equiv> !k_ref1\"\n\ndefinition \"get_k2' \\<equiv> !k_ref2\"\n\ndefinition \"update1' k v \\<equiv> do {m \\<leftarrow> !m_ref1; mem_update m k v}\"\n\ndefinition \"update2' k v \\<equiv> do {m \\<leftarrow> !m_ref2; mem_update m k v}\"\n\ndefinition \"move12' k \\<equiv> do {\n    k1 \\<leftarrow> !k_ref1;\n    m \\<leftarrow> mem_empty;\n    m1 \\<leftarrow> !m_ref1;\n    k_ref2 := k1;\n    k_ref1 := k;\n    m_ref2 := m1;\n    m_ref1 := m\n  }\"\n\ninterpretation heap_mem_defs inv_pair_weak lookup_pair update_pair .\n\nlemma rel_state_ofI:\n  \"rel_state (=) (state_of m) m\" if\n  \"\\<forall> heap. inv_pair_weak heap \\<longrightarrow> success m heap\"\n  \"lift_p inv_pair_weak m\"\n  using that unfolding rel_state_def\n  by (auto split: option.split intro: lift_p_P'' simp: success_def)\n\nlemma inv_pair_iff:\n  \"inv_pair_weak = inv_pair\"\n  unfolding inv_pair_def using inv_distinct by simp\n\nlemma lift_p_inv_pairI:\n  \"State_Heap.lift_p inv_pair m\" if \"State_Heap.lift_p inv_pair_weak m\"\n  using that unfolding inv_pair_iff by simp\n\nlemma lift_p_success:\n  \"State_Heap.lift_p inv_pair_weak m\"\n  if \"DP_CRelVS.lift_p inv_pair_weak (state_of m)\" \"\\<forall> heap. inv_pair_weak heap \\<longrightarrow> success m heap\"\n  using that\n  unfolding lift_p_def DP_CRelVS.lift_p_def\n  by (auto simp: success_def split: option.split)\n\nlemma rel_state_ofI2:\n  \"rel_state (=) (state_of m) m\" if\n  \"\\<forall> heap. inv_pair_weak heap \\<longrightarrow> success m heap\"\n  \"DP_CRelVS.lift_p inv_pair_weak (state_of m)\"\n  using that by (blast intro: rel_state_ofI lift_p_success)\n\ncontext\n  includes lifting_syntax\nbegin\n\n\n\nlemma [transfer_rule]:\n  \"((=) ===> rel_state (rel_option (=))) lookup1 mem_lookup1\"\n  unfolding lookup1_def mem_lookup1_def\n  apply (intro rel_funI)\n  apply (simp add: option.rel_eq)\n  apply (rule rel_state_ofI2)\n  subgoal\n    by (auto 4 4\n        simp: mem_lookup_def inv_pair_lengthD1 execute_simps Let_def\n        intro: success_bind_executeI success_returnI Array.success_nthI\n       )\n  subgoal\n    using pair.lookup_inv(1) unfolding lookup1_def .\n  done\n\nlemma [transfer_rule]:\n  \"((=) ===> rel_state (rel_option (=))) lookup2 mem_lookup2\"\n  unfolding lookup2_def mem_lookup2_def\n  apply (intro rel_funI)\n  apply (simp add: option.rel_eq)\n  apply (rule rel_state_ofI2)\n  subgoal\n    by (auto 4 3\n        simp: mem_lookup_def inv_pair_lengthD2 execute_simps Let_def\n        intro: success_intros intro!: success_bind_I\n       )\n  subgoal\n    using pair.lookup_inv(2) unfolding lookup2_def .\n  done\n\nlemma [transfer_rule]:\n  \"rel_state (=) get_k1 get_k1'\"\n  unfolding get_k1_def get_k1'_def\n  apply (rule rel_state_ofI2)\n  subgoal\n    by (auto intro: success_lookupI)\n  subgoal\n    unfolding get_k1_def[symmetric] by (auto dest: pair.get_state(1) intro: lift_pI)\n  done\n\nlemma [transfer_rule]:\n  \"rel_state (=) get_k2 get_k2'\"\n  unfolding get_k2_def get_k2'_def\n  apply (rule rel_state_ofI2)\n  subgoal\n    by (auto intro: success_lookupI)\n  subgoal\n    unfolding get_k2_def[symmetric] by (auto dest: pair.get_state(2) intro: lift_pI)\n  done\n\nlemma [transfer_rule]:\n  \"((=) ===> (=) ===> rel_state (=)) update1 update1'\"\n  unfolding update1_def update1'_def\n  apply (intro rel_funI)\n  apply simp\n  apply (rule rel_state_ofI2)\n  subgoal\n    by (auto 4 3\n        simp: mem_update_def inv_pair_lengthD1 execute_simps Let_def\n        intro: success_intros intro!: success_bind_I\n       )\n  subgoal\n    using pair.update_inv(1) unfolding update1_def .\n  done\n\nlemma [transfer_rule]:\n  \"((=) ===> (=) ===> rel_state (=)) update2 update2'\"\n  unfolding update2_def update2'_def\n  apply (intro rel_funI)\n  apply simp\n  apply (rule rel_state_ofI2)\n  subgoal\n    by (auto 4 3\n        simp: mem_update_def inv_pair_lengthD2 execute_simps Let_def\n        intro: success_intros intro!: success_bind_I\n       )\n  subgoal\n    using pair.update_inv(2) unfolding update2_def .\n  done\n\nlemma [transfer_rule]:\n  \"((=) ===> rel_state (rel_option (=))) lookup1 mem_lookup1\"\n  unfolding lookup1_def mem_lookup1_def\n  apply (intro rel_funI)\n  apply (simp add: option.rel_eq)\n  apply (rule rel_state_ofI2)\n  subgoal\n    by (auto 4 3\n        simp: mem_lookup_def inv_pair_lengthD1 execute_simps Let_def\n        intro: success_intros intro!: success_bind_I\n       )\n  subgoal\n    using pair.lookup_inv(1) unfolding lookup1_def .\n  done\n\nlemma rel_state_lookup:\n  \"((=) ===> rel_state (=)) pair.lookup_pair lookup_pair\"\n  unfolding pair.lookup_pair_def lookup_pair_def\n  unfolding\n    mem_lookup1_def[symmetric] mem_lookup2_def[symmetric]\n    get_k2_def[symmetric] get_k2'_def[symmetric]\n    get_k1_def[symmetric] get_k1'_def[symmetric]\n  by transfer_prover\n\nlemma rel_state_update:\n  \"((=) ===> (=) ===> rel_state (=)) pair.update_pair update_pair\"\n  unfolding pair.update_pair_def update_pair_def\n  unfolding move12'_def[symmetric]\n  unfolding\n    update1'_def[symmetric] update2'_def[symmetric]\n    get_k2_def[symmetric] get_k2'_def[symmetric]\n    get_k1_def[symmetric] get_k1'_def[symmetric]\n  by transfer_prover\n\ninterpretation mem: heap_mem_defs pair.inv_pair lookup_pair update_pair .\n\nlemma inv_pairD:\n  \"inv_pair_weak heap\" if \"pair.inv_pair heap\"\n  using that unfolding pair.inv_pair_def by (auto simp: Let_def)\n\nlemma mem_rel_state_ofI:\n  \"mem.rel_state (=) m' m\" if\n  \"rel_state (=) m' m\"\n  \"\\<And> heap. pair.inv_pair heap \\<Longrightarrow>\n    (case State_Monad.run_state m' heap of (_, heap) \\<Rightarrow> inv_pair_weak heap \\<longrightarrow> pair.inv_pair heap)\"\nproof -\n  show ?thesis\n    apply (rule mem.rel_state_intro)\n    subgoal for heap v heap'\n      by (auto elim: rel_state_elim[OF that(1)] dest!: inv_pairD)\n    subgoal premises prems for heap v heap'\n    proof -\n      from prems that(1) have \"inv_pair_weak heap'\"\n        by (fastforce elim: rel_state_elim dest: inv_pairD)\n      with prems show ?thesis\n        by (auto dest: that(2))\n    qed\n    done\nqed\n\nlemma mem_rel_state_ofI':\n  \"mem.rel_state (=) m' m\" if\n  \"rel_state (=) m' m\"\n  \"DP_CRelVS.lift_p pair.inv_pair m'\"\n  using that by (auto elim: DP_CRelVS.lift_p_P intro: mem_rel_state_ofI)\n\ncontext\n  assumes keys: \"\\<forall>k k'. key1 k = key1 k' \\<and> key2 k = key2 k' \\<longrightarrow> k = k'\"\nbegin\n\ninterpretation mem_correct pair.lookup_pair pair.update_pair pair.inv_pair\n  by (rule mem_correct_pair[OF keys])\n\nlemma rel_state_lookup':\n  \"((=) ===> mem.rel_state (=)) pair.lookup_pair lookup_pair\"\n  apply (intro rel_funI)\n  apply simp\n  apply (rule mem_rel_state_ofI')\n  subgoal for x y\n    using rel_state_lookup by (rule rel_funD) (rule HOL.refl)\n  by (rule lookup_inv)\n\nlemma rel_state_update':\n  \"((=) ===> (=) ===> mem.rel_state (=)) pair.update_pair update_pair\"\n  apply (intro rel_funI)\n  apply simp\n  apply (rule mem_rel_state_ofI')\n  subgoal for x y a b\n    using rel_state_update by (blast dest: rel_funD)\n  by (rule update_inv)\n\ninterpretation heap_correct pair.inv_pair update_pair lookup_pair\n  by (rule mem.mem_correct_heap_correct[OF _ rel_state_lookup' rel_state_update']) standard\n\nlemmas heap_correct_pairI = heap_correct_axioms \n\n(* TODO: Generalize *)\nlemma mem_rel_state_resultD:\n  \"result_of m heap = fst (run_state m' heap)\" if \"mem.rel_state (=) m' m\" \"pair.inv_pair heap\"\n  by (metis (mono_tags, lifting) mem.rel_state_elim option.sel that)\n\nlemma map_of_heap_eq:\n  \"mem.map_of_heap heap = pair.pair.map_of heap\" if \"pair.inv_pair heap\"\n  unfolding mem.map_of_heap_def pair.pair.map_of_def\n  using that by (simp add: mem_rel_state_resultD[OF rel_state_lookup'[THEN rel_funD]])\n\ncontext\n  fixes k1 k2 heap heap'\n  assumes init: \"execute (init_state k1 k2) heap = Some ((k_ref1, k_ref2, m_ref1, m_ref2), heap')\"\nbegin\n\nlemma init_state_empty1:\n  \"pair.mem1.map_of heap' k = None\"\n  using init\n  unfolding pair.mem1.map_of_def lookup1_def mem_lookup_def init_state_def\n  by (auto\n        simp: init_state_inner_nth init_state_inner_alloc(3) execute_simps Let_def\n        elim!: execute_bind_success'[OF success_empty])\n     (metis\n        Array.present_alloc Memory_Heap.length_mem_empty execute_new execute_nth(1) fst_conv\n        length_def mem_empty_def nth_mem_empty option.sel present_alloc_get snd_conv\n     )\n\nlemma init_state_empty2:\n  \"pair.mem2.map_of heap' k = None\"\n  using init\n  unfolding pair.mem2.map_of_def lookup2_def mem_lookup_def init_state_def\n  by (auto\n        simp: execute_simps init_state_inner_nth init_state_inner_alloc(4) Let_def\n        elim!: execute_bind_success'[OF success_empty]\n     )\n     (metis fst_conv nth_mem_empty option.sel snd_conv)\n\nlemma\n  shows init_state_k1: \"result_of (!k_ref1) heap' = k1\"\n    and init_state_k2: \"result_of (!k_ref2) heap' = k2\"\n  using init init_state_inner_alloc\n  by (auto simp: execute_simps init_state_def elim!: execute_bind_success'[OF success_empty])\n\ncontext\n  assumes neq: \"k1 \\<noteq> k2\"\nbegin\n\nlemma init_state_inv':\n  \"pair.inv_pair heap'\"\n  unfolding pair.inv_pair_def\n  apply (auto simp: Let_def)\n  subgoal\n    using init_state_empty1 by simp\n  subgoal\n    using init_state_empty2 by simp\n  subgoal\n    using neq init by (simp add: get_k1_def get_k2_def init_state_k1 init_state_k2)\n  subgoal\n    by (rule init_state_inv[OF init])\n  done\n\nlemma init_state_empty:\n  \"pair.pair.map_of heap' \\<subseteq>\\<^sub>m Map.empty\"\n  using neq by (intro pair.emptyI init_state_inv' map_emptyI init_state_empty1 init_state_empty2)\n\ninterpretation heap_correct_empty pair.inv_pair update_pair lookup_pair heap'\n  apply (rule heap_correct_empty.intro)\n   apply (rule heap_correct_pairI)\n  apply standard\n  subgoal\n    by (subst map_of_heap_eq; intro init_state_inv' init_state_empty)\n  subgoal\n    by (rule init_state_inv')\n  done\n\nlemmas heap_correct_empty_pairI = heap_correct_empty_axioms\n\ncontext\n  fixes dp :: \"'k \\<Rightarrow> 'v\"\nbegin\n\ninterpretation dp_consistency_heap_empty\n  pair.inv_pair update_pair lookup_pair dp heap'\n  by standard\n\nlemmas consistent_empty_pairI = dp_consistency_heap_empty_axioms\n\nend (* DP *)\n\nend (* Unequal Keys *)\n\nend (* Init State *)\n\nend (* Keys injective *)\n\nend (* Lifting Syntax *)\n\nend (* Disjoint *)\n\nend (* Injectivity *)\n\nend (* Refs *)\n\nend (* Key functions & Size *)\n\nend (* Theory *)\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Monad_Memo_DP/heap_monad/Memory_Heap.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5467381667555714, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.29892261491139677}}
{"text": "(* Title:     Xml\n   Author:    Christian Sternagel\n   Author:    René Thiemann\n*)\n\nsection \\<open>XML Transformers for Extracting Data from XML Nodes\\<close>\n\ntheory Xmlt\nimports\n  Xml\n  Certification_Monads.Strict_Sum\n  HOL.Rat\nbegin\n\ntype_synonym\n  tag = string\n\ntext \\<open>The type of transformers on xml nodes.\\<close>\ntype_synonym\n  'a xmlt = \"xml \\<Rightarrow> string +\\<^sub>\\<bottom> 'a\"\n\ndefinition map :: \"(xml \\<Rightarrow> ('e +\\<^sub>\\<bottom> 'a)) \\<Rightarrow> xml list \\<Rightarrow> 'e +\\<^sub>\\<bottom> 'a list\"\nwhere\n  [code_unfold]: \"map = map_sum_bot\"\n\nlemma map_mono [partial_function_mono]:\n  fixes C :: \"xml \\<Rightarrow> ('b \\<Rightarrow> ('e +\\<^sub>\\<bottom> 'c)) \\<Rightarrow> 'e +\\<^sub>\\<bottom> 'd\"\n  assumes C: \"\\<And>y. y \\<in> set B \\<Longrightarrow> mono_sum_bot (C y)\"\n  shows \"mono_sum_bot (\\<lambda>f. map (\\<lambda>y. C y f) B)\" \n  unfolding map_def by (auto intro: partial_function_mono C)\n\nhide_const (open) map\n\nfun \"text\" :: \"tag \\<Rightarrow> string xmlt\"\nwhere\n  \"text tag (XML n atts [XML_text t]) = \n    (if n = tag \\<and> atts = [] then return t\n    else error (concat\n      [''could not extract text for '', tag,'' from '', ''\\<newline>'', show (XML n atts [XML_text t])]))\"\n| \"text tag xml = error (concat [''could not extract text for '', tag,'' from '', ''\\<newline>'', show xml])\"\nhide_const (open) \"text\"\n\ndefinition bool_of_string :: \"string \\<Rightarrow> string +\\<^sub>\\<bottom> bool\"\nwhere\n  \"bool_of_string s =\n    (if s = ''true'' then return True\n    else if s = ''false'' then return False\n    else error (''cannot convert '' @ s @ '' into Boolean''))\"\n\nfun bool :: \"tag \\<Rightarrow> bool xmlt\"\nwhere\n  \"bool tag node = Xmlt.text tag node \\<bind> bool_of_string\"\nhide_const (open) bool\n\ndefinition fail :: \"tag \\<Rightarrow> 'a xmlt\"\nwhere\n  \"fail tag xml =\n    error (concat\n      [''could not transform the following xml element (expected '', tag, '')'', ''\\<newline>'', show xml])\"\nhide_const (open) fail\n\ndefinition guard :: \"(xml \\<Rightarrow> bool) \\<Rightarrow> 'a xmlt \\<Rightarrow> 'a xmlt \\<Rightarrow> 'a xmlt\"\nwhere\n  \"guard p p1 p2 x = (if p x then p1 x else p2 x)\"\nhide_const (open) guard\n\nlemma guard_mono [partial_function_mono]:\n  assumes p1: \"\\<And>y. mono_sum_bot (p1 y)\"\n    and p2: \"\\<And>y. mono_sum_bot (p2 y)\"\n  shows \"mono_sum_bot (\\<lambda>g. Xmlt.guard p (\\<lambda>y. p1 y g) (\\<lambda>y. p2 y g) x)\" \n  by (cases x) (auto intro!: partial_function_mono p1 p2 simp: Xmlt.guard_def)\n\nfun leaf :: \"tag \\<Rightarrow> 'a \\<Rightarrow> 'a xmlt\"\nwhere\n  \"leaf tag x (XML name atts cs) = \n    (if name = tag \\<and> atts = [] \\<and> cs = [] then return x \n    else Xmlt.fail tag (XML name atts cs))\" |\n  \"leaf tag x xml = Xmlt.fail tag xml\"\nhide_const (open) leaf\n\nfun list1element :: \"'a list \\<Rightarrow> 'a option\"\nwhere\n  \"list1element [x] = Some x\" |\n  \"list1element _ = None\"\n\nfun singleton :: \"tag \\<Rightarrow> 'a xmlt \\<Rightarrow> ('a \\<Rightarrow> 'b) \\<Rightarrow> 'b xmlt\"\nwhere\n  \"singleton tag p1 f xml =\n    (case xml of\n      XML name atts cs \\<Rightarrow>\n      (if name = tag \\<and> atts = [] then\n        (case list1element cs of \n          Some (cs1) \\<Rightarrow> p1 cs1 \\<bind> return \\<circ> f\n        | None \\<Rightarrow> Xmlt.fail tag xml)\n      else Xmlt.fail tag xml)\n    | _ \\<Rightarrow> Xmlt.fail tag xml)\"\nhide_const (open) singleton\n\nlemma singleton_mono [partial_function_mono]:\n  assumes p: \"\\<And>y. mono_sum_bot (p1 y)\"\n  shows \"mono_sum_bot (\\<lambda>g. Xmlt.singleton t (\\<lambda>y. p1 y g) f x)\" \n    by (cases x, cases \"list1element (Xml.children x)\") (auto intro!: partial_function_mono p)\n\nfun list2elements :: \"'a list \\<Rightarrow> ('a \\<times> 'a) option\"\nwhere\n  \"list2elements [x, y] = Some (x, y)\" |\n  \"list2elements _ = None\"\n\nfun pair :: \"tag \\<Rightarrow> 'a xmlt \\<Rightarrow> 'b xmlt \\<Rightarrow> ('a \\<Rightarrow> 'b \\<Rightarrow> 'c) \\<Rightarrow> 'c xmlt\"\nwhere\n  \"pair tag p1 p2 f xml =\n    (case xml of\n      XML name atts cs \\<Rightarrow>\n      (if name = tag \\<and> atts = [] then\n        (case list2elements cs of \n          Some (cs1, cs2) \\<Rightarrow>\n          do {\n            a \\<leftarrow> p1 cs1;\n            b \\<leftarrow> p2 cs2;\n            return (f a b)\n          }\n        | None \\<Rightarrow> Xmlt.fail tag xml)\n      else Xmlt.fail tag xml)\n    | _ \\<Rightarrow> Xmlt.fail tag xml)\"\nhide_const (open) pair\n\nlemma pair_mono [partial_function_mono]:\n  assumes \"\\<And>y. mono_sum_bot (p1 y)\"\n    and \"\\<And>y. mono_sum_bot (p2 y)\"\n  shows \"mono_sum_bot (\\<lambda>g. Xmlt.pair t (\\<lambda>y. p1 y g) (\\<lambda> y. p2 y g) f x)\"\n  using assms\n  by (cases x, cases \"list2elements (Xml.children x)\") (auto intro!: partial_function_mono)\n\nfun list3elements :: \"'a list \\<Rightarrow> ('a \\<times> 'a \\<times> 'a) option\"\nwhere\n  \"list3elements [x, y, z] = Some (x, y, z)\" |\n  \"list3elements _ = None\"\n\nfun triple :: \"string \\<Rightarrow> 'a xmlt \\<Rightarrow> 'b xmlt \\<Rightarrow> 'c xmlt \\<Rightarrow> ('a \\<Rightarrow> 'b \\<Rightarrow> 'c \\<Rightarrow> 'd) \\<Rightarrow> 'd xmlt\"\nwhere\n  \"triple tag p1 p2 p3 f xml = (case xml of XML name atts cs \\<Rightarrow>\n    (if name = tag \\<and> atts = [] then\n      (case list3elements cs of \n        Some (cs1, cs2, cs3) \\<Rightarrow>\n        do {\n          a \\<leftarrow> p1 cs1;\n          b \\<leftarrow> p2 cs2;\n          c \\<leftarrow> p3 cs3;\n          return (f a b c)\n        }\n      | None \\<Rightarrow> Xmlt.fail tag xml)\n    else Xmlt.fail tag xml)\n  | _ \\<Rightarrow> Xmlt.fail tag xml)\"\n\nlemma triple_mono [partial_function_mono]:\n  assumes \"\\<And>y. mono_sum_bot (p1 y)\"\n    and \"\\<And>y. mono_sum_bot (p2 y)\"\n    and \"\\<And>y. mono_sum_bot (p3 y)\"\n  shows \"mono_sum_bot (\\<lambda>g. Xmlt.triple t (\\<lambda>y. p1 y g) (\\<lambda> y. p2 y g) (\\<lambda> y. p3 y g) f x)\"\n  using assms\n  by (cases x, cases \"list3elements (Xml.children x)\", auto intro!: partial_function_mono)\n\nfun list4elements :: \"'a list \\<Rightarrow> ('a \\<times> 'a \\<times> 'a \\<times> 'a) option\"\nwhere\n  \"list4elements [x, y, z, u] = Some (x, y, z, u)\" |\n  \"list4elements _ = None\"\n\nfun\n  tuple4 ::\n    \"string \\<Rightarrow> 'a xmlt \\<Rightarrow> 'b xmlt \\<Rightarrow> 'c xmlt \\<Rightarrow> 'd xmlt \\<Rightarrow> ('a \\<Rightarrow> 'b \\<Rightarrow> 'c \\<Rightarrow> 'd \\<Rightarrow> 'e) \\<Rightarrow> 'e xmlt\"\nwhere\n  \"tuple4 tag p1 p2 p3 p4 f xml =\n    (case xml of\n      XML name atts cs \\<Rightarrow>\n        (if name = tag \\<and> atts = [] then\n          (case list4elements cs of \n            Some (cs1, cs2, cs3, cs4) \\<Rightarrow>\n            do {\n              a \\<leftarrow> p1 cs1;\n              b \\<leftarrow> p2 cs2;\n              c \\<leftarrow> p3 cs3;\n              d \\<leftarrow> p4 cs4;\n              return (f a b c d)\n            }\n          | None \\<Rightarrow> Xmlt.fail tag xml)\n        else Xmlt.fail tag xml)\n   | _ \\<Rightarrow> Xmlt.fail tag xml)\"\n\nlemma tuple4_mono [partial_function_mono]:\n  assumes \"\\<And>y. mono_sum_bot (p1 y)\"\n    and \"\\<And>y. mono_sum_bot (p2 y)\"\n    and \"\\<And>y. mono_sum_bot (p3 y)\"\n    and\"\\<And>y. mono_sum_bot (p4 y)\"\n  shows \"mono_sum_bot (\\<lambda>g. Xmlt.tuple4 t (\\<lambda>y. p1 y g) (\\<lambda> y. p2 y g) (\\<lambda> y. p3 y g) (\\<lambda> y. p4 y g) f x)\"\n  using assms\n  by (cases x, cases \"list4elements (Xml.children x)\") (auto intro!: partial_function_mono)\n\nfun list5elements :: \"'a list \\<Rightarrow> ('a \\<times> 'a \\<times> 'a \\<times> 'a \\<times> 'a) option\"\nwhere\n  \"list5elements [x, y, z, u, v] = Some (x, y, z, u, v)\" |\n  \"list5elements _ = None\"\n\nfun\n  tuple5 ::\n    \"string \\<Rightarrow> 'a xmlt \\<Rightarrow> 'b xmlt \\<Rightarrow> 'c xmlt \\<Rightarrow> 'd xmlt \\<Rightarrow> 'e xmlt \\<Rightarrow>\n      ('a \\<Rightarrow> 'b \\<Rightarrow> 'c \\<Rightarrow> 'd \\<Rightarrow> 'e \\<Rightarrow> 'f) \\<Rightarrow> 'f xmlt\"\nwhere\n  \"tuple5 tag p1 p2 p3 p4 p5 f xml =\n    (case xml of\n      XML name atts cs \\<Rightarrow>\n        (if name = tag \\<and> atts = [] then\n          (case list5elements cs of \n            Some (cs1,cs2,cs3,cs4,cs5) \\<Rightarrow>\n            do {\n              a \\<leftarrow> p1 cs1;\n              b \\<leftarrow> p2 cs2;\n              c \\<leftarrow> p3 cs3;\n              d \\<leftarrow> p4 cs4;\n              e \\<leftarrow> p5 cs5;\n              return (f a b c d e)\n            }\n          | None \\<Rightarrow> Xmlt.fail tag xml)\n        else Xmlt.fail tag xml)\n    | _ \\<Rightarrow> Xmlt.fail tag xml)\"\n\nlemma tuple5_mono [partial_function_mono]:\n  assumes \"\\<And>y. mono_sum_bot (p1 y)\"\n    and \"\\<And>y. mono_sum_bot (p2 y)\"\n    and \"\\<And>y. mono_sum_bot (p3 y)\"\n    and \"\\<And>y. mono_sum_bot (p4 y)\"\n    and \"\\<And>y. mono_sum_bot (p5 y)\"\n  shows \"mono_sum_bot (\\<lambda>g. Xmlt.tuple5 t (\\<lambda>y. p1 y g) (\\<lambda> y. p2 y g) (\\<lambda> y. p3 y g) (\\<lambda> y. p4 y g) (\\<lambda> y. p5 y g) f x)\"\n  using assms\n  by (cases x, cases \"list5elements (Xml.children x)\") (auto intro!: partial_function_mono)\n\nfun list6elements :: \"'a list \\<Rightarrow> ('a \\<times> 'a \\<times> 'a \\<times> 'a \\<times> 'a \\<times> 'a) option\"\nwhere\n  \"list6elements [x, y, z, u, v, w] = Some (x, y, z, u, v, w)\" |\n  \"list6elements _ = None\"\n\nfun\n  tuple6 ::\n    \"string \\<Rightarrow> 'a xmlt \\<Rightarrow> 'b xmlt \\<Rightarrow> 'c xmlt \\<Rightarrow> 'd xmlt \\<Rightarrow> 'e xmlt \\<Rightarrow> 'f xmlt \\<Rightarrow>\n      ('a \\<Rightarrow> 'b \\<Rightarrow> 'c \\<Rightarrow> 'd \\<Rightarrow> 'e \\<Rightarrow> 'f \\<Rightarrow> 'g) \\<Rightarrow> 'g xmlt\"\nwhere\n  \"tuple6 tag p1 p2 p3 p4 p5 p6 f xml =\n    (case xml of\n      XML name atts cs  \\<Rightarrow>\n        (if name = tag \\<and> atts = [] then\n          (case list6elements cs of \n            Some (cs1,cs2,cs3,cs4,cs5,cs6) \\<Rightarrow>\n            do {\n              a \\<leftarrow> p1 cs1;\n              b \\<leftarrow> p2 cs2;\n              c \\<leftarrow> p3 cs3;\n              d \\<leftarrow> p4 cs4;\n              e \\<leftarrow> p5 cs5;\n              ff \\<leftarrow> p6 cs6;\n              return (f a b c d e ff)\n            }\n          | None \\<Rightarrow> Xmlt.fail tag xml)\n        else Xmlt.fail tag xml)\n    | _ \\<Rightarrow> Xmlt.fail tag xml)\"\n\nlemma tuple6_mono [partial_function_mono]:\n  assumes \"\\<And>y. mono_sum_bot (p1 y)\"\n    and \"\\<And>y. mono_sum_bot (p2 y)\"\n    and \"\\<And>y. mono_sum_bot (p3 y)\"\n    and \"\\<And>y. mono_sum_bot (p4 y)\"\n    and \"\\<And>y. mono_sum_bot (p5 y)\"\n    and \"\\<And>y. mono_sum_bot (p6 y)\"\n  shows \"mono_sum_bot (\\<lambda>g. Xmlt.tuple6 t (\\<lambda>y. p1 y g) (\\<lambda> y. p2 y g) (\\<lambda> y. p3 y g) (\\<lambda> y. p4 y g) (\\<lambda> y. p5 y g) (\\<lambda> y. p6 y g) f x)\"\n  using assms\n  by (cases x, cases \"list6elements (Xml.children x)\") (auto intro!: partial_function_mono)\n\nfun optional :: \"tag \\<Rightarrow> 'a xmlt \\<Rightarrow> ('a option \\<Rightarrow> 'b) \\<Rightarrow> 'b xmlt\"\nwhere\n  \"optional tag p1 f (XML name atts cs) =\n    (let l = length cs in\n    (if name = tag \\<and> atts = [] \\<and> l \\<ge> 0 \\<and> l \\<le> 1 then do {\n      if l = 1 then do {\n        x1 \\<leftarrow> p1 (cs ! 0);\n        return (f (Some x1))\n      } else return (f None)\n    } else Xmlt.fail tag (XML name atts cs)))\" |\n  \"optional tag p1 f xml = Xmlt.fail tag xml\"\n\nlemma optional_mono [partial_function_mono]:\n  assumes \"\\<And>y. mono_sum_bot (p1 y)\"\n  shows \"mono_sum_bot (\\<lambda>g. Xmlt.optional t (\\<lambda>y. p1 y g) f x)\" \n  using assms by (cases x) (auto intro!: partial_function_mono)\n\nfun xml1to2elements :: \"string \\<Rightarrow> 'a xmlt \\<Rightarrow> 'b xmlt \\<Rightarrow> ('a \\<Rightarrow> 'b option \\<Rightarrow> 'c) \\<Rightarrow> 'c xmlt\"\nwhere\n  \"xml1to2elements tag p1 p2 f (XML name atts cs) = (\n     let l = length cs in\n     (if name = tag \\<and> atts = [] \\<and> l \\<ge> 1 \\<and> l \\<le> 2\n       then do {\n         x1 \\<leftarrow> p1 (cs ! 0);\n         (if l = 2\n           then do {\n             x2 \\<leftarrow> p2 (cs ! 1);\n             return (f x1 (Some x2))\n           } else return (f x1 None))\n       } else Xmlt.fail tag (XML name atts cs)))\" |\n  \"xml1to2elements tag p1 p2 f xml = Xmlt.fail tag xml\"\n\nlemma xml1to2elements_mono[partial_function_mono]:\n  assumes p1: \"\\<And>y. mono_sum_bot (p1 y)\"\n              \"\\<And>y. mono_sum_bot (p2 y)\"\n  shows \"mono_sum_bot (\\<lambda>g. xml1to2elements t (\\<lambda>y. p1 y g) (\\<lambda>y. p2 y g) f x)\" \n  by (cases x, auto intro!: partial_function_mono p1)\n\ntext \\<open>\n  Apply the first transformer to the first child-node, then check the second child-node,\n  which is must be a Boolean. If the Boolean is true, then apply the second transformer\n  to the last child-node.\n\\<close>\nfun xml2nd_choice :: \"tag \\<Rightarrow> 'a xmlt \\<Rightarrow> tag \\<Rightarrow> 'b xmlt \\<Rightarrow> ('a \\<Rightarrow> 'b option \\<Rightarrow> 'c) \\<Rightarrow> 'c xmlt\"\nwhere\n  \"xml2nd_choice tag p1 cn p2 f (XML name atts cs) = (\n    let l = length cs in\n    (if name = tag \\<and> atts = [] \\<and> l \\<ge> 2 then do {\n      x1 \\<leftarrow> p1 (cs ! 0);\n      b \\<leftarrow> Xmlt.bool cn (cs ! 1);\n      (if b then do {\n        x2 \\<leftarrow> p2 (cs ! (l - 1));\n        return (f x1 (Some x2))\n      } else return (f x1 None))\n    } else Xmlt.fail tag (XML name atts cs)))\" |\n  \"xml2nd_choice tag p1 cn p2 f xml = Xmlt.fail tag xml\"\n\nlemma xml2nd_choice_mono [partial_function_mono]:\n  assumes p1: \"\\<And>y. mono_sum_bot (p1 y)\"\n              \"\\<And>y. mono_sum_bot (p2 y)\"\n  shows \"mono_sum_bot (\\<lambda>g. xml2nd_choice t (\\<lambda>y. p1 y g) h (\\<lambda>y. p2 y g) f x)\" \n  by (cases x, auto intro!: partial_function_mono p1)\n\nfun\n  xml2to3elements ::\n    \"string \\<Rightarrow> 'a xmlt \\<Rightarrow> 'b xmlt \\<Rightarrow> 'c xmlt \\<Rightarrow> ('a \\<Rightarrow> 'b \\<Rightarrow> 'c option \\<Rightarrow> 'd) \\<Rightarrow> 'd xmlt\"\nwhere\n  \"xml2to3elements tag p1 p2 p3 f (XML name atts cs) = (\n     let l = length cs in\n     (if name = tag \\<and> atts = [] \\<and> l \\<ge> 2 \\<and> l \\<le> 3 then do {\n       x1 \\<leftarrow> p1 (cs ! 0);\n       x2 \\<leftarrow> p2 (cs ! 1);\n       (if l = 3 then do {\n         x3 \\<leftarrow> p3 (cs ! 2);\n         return (f x1 x2 (Some x3))\n       } else return (f x1 x2 None))\n     } else Xmlt.fail tag (XML name atts cs)))\" |\n  \"xml2to3elements tag p1 p2 p3 f xml = Xmlt.fail tag xml\"\n\nlemma xml2to3elements_mono [partial_function_mono]:\n  assumes p1: \"\\<And>y. mono_sum_bot (p1 y)\"\n              \"\\<And>y. mono_sum_bot (p2 y)\"\n              \"\\<And>y. mono_sum_bot (p3 y)\"\n  shows \"mono_sum_bot (\\<lambda>g. xml2to3elements t (\\<lambda>y. p1 y g) (\\<lambda>y. p2 y g) (\\<lambda>y. p3 y g) f x)\" \n  by (cases x, auto intro!: partial_function_mono p1)\n\nfun\n  xml3to4elements ::\n    \"string \\<Rightarrow> 'a xmlt \\<Rightarrow> 'b xmlt \\<Rightarrow> 'c xmlt \\<Rightarrow> 'd xmlt \\<Rightarrow> ('a \\<Rightarrow> 'b \\<Rightarrow> 'c option \\<Rightarrow> 'd \\<Rightarrow> 'e) \\<Rightarrow>\n      'e xmlt\"\nwhere\n  \"xml3to4elements tag p1 p2 p3 p4 f (XML name atts cs) = (\n     let l = length cs in\n     (if name = tag \\<and> atts = [] \\<and> l \\<ge> 3 \\<and> l \\<le> 4 then do {\n       x1 \\<leftarrow> p1 (cs ! 0);\n       x2 \\<leftarrow> p2 (cs ! 1);\n       (if l = 4 then do {\n         x3 \\<leftarrow> p3 (cs ! 2);\n         x4 \\<leftarrow> p4 (cs ! 3);\n         return (f x1 x2 (Some x3) x4)\n       } else do {\n         x4 \\<leftarrow> p4 (cs ! 2);\n         return (f x1 x2 None x4)\n       } )\n     } else Xmlt.fail tag (XML name atts cs)))\" |\n  \"xml3to4elements tag p1 p2 p3 p4 f xml = Xmlt.fail tag xml\"\n\nlemma xml3to4elements_mono [partial_function_mono]:\n  assumes p1: \"\\<And>y. mono_sum_bot (p1 y)\"\n              \"\\<And>y. mono_sum_bot (p2 y)\"\n              \"\\<And>y. mono_sum_bot (p3 y)\"\n              \"\\<And>y. mono_sum_bot (p4 y)\"\n  shows \"mono_sum_bot (\\<lambda>g. xml3to4elements t (\\<lambda>y. p1 y g) (\\<lambda>y. p2 y g) (\\<lambda>y. p3 y g) (\\<lambda>y. p4 y g) f x)\" \n  by (cases x, auto intro!: partial_function_mono p1)\n\nfun many :: \"tag \\<Rightarrow> 'a xmlt \\<Rightarrow> ('a list \\<Rightarrow> 'b) \\<Rightarrow> 'b xmlt\"\nwhere\n  \"many tag p f (XML name atts cs) =\n    (if name = tag \\<and> atts = [] then (Xmlt.map p cs \\<bind> (return \\<circ> f))\n    else Xmlt.fail tag (XML name atts cs))\" |\n  \"many tag p f xml = Xmlt.fail tag xml\"\nhide_const (open) many\n\nlemma many_mono [partial_function_mono]:\n  fixes p1 :: \"xml \\<Rightarrow> ('b \\<Rightarrow> (string +\\<^sub>\\<bottom> 'c)) \\<Rightarrow> string +\\<^sub>\\<bottom> 'd\"\n  assumes \"\\<And>y. y \\<in> set (Xml.children x) \\<Longrightarrow> mono_sum_bot (p1 y)\"\n  shows \"mono_sum_bot (\\<lambda>g. Xmlt.many t (\\<lambda>y. p1 y g) f x)\" \n  using assms by (cases x) (auto intro!: partial_function_mono)\n\nfun many1_gen :: \"tag \\<Rightarrow> 'a xmlt \\<Rightarrow> ('a \\<Rightarrow> 'b xmlt) \\<Rightarrow> ('a \\<Rightarrow> 'b list \\<Rightarrow> 'c) \\<Rightarrow> 'c xmlt\"\nwhere\n  \"many1_gen tag p1 p2 f (XML name atts cs) =\n    (if name = tag \\<and> atts = [] \\<and> cs \\<noteq> [] then\n      (case cs of h # t \\<Rightarrow> do {\n        x \\<leftarrow> p1 h;\n        xs \\<leftarrow> Xmlt.map (p2 x) t;\n        return (f x xs)\n      })\n    else Xmlt.fail tag (XML name atts cs))\" |\n  \"many1_gen tag p1 p2 f xml = Xmlt.fail tag xml\"\n\n(* TODO \nlemma Xmlt.many1_gen_mono[partial_function_mono]:\n  fixes p1 :: \"xml \\<Rightarrow> ('b \\<Rightarrow> 'c sum_bot) \\<Rightarrow> 'd sum_bot\"\n  assumes p1: \"\\<And>y. mono_sum_bot (p1 y)\"\n              \"\\<And>y. mono_sum_bot (p2 y)\"\n  shows \"mono_sum_bot (\\<lambda>g. Xmlt.many1_gen t (\\<lambda>y. p1 y g) (\\<lambda>y. p2 y g) f x)\" \n  by (cases x, auto intro!: partial_function_mono p1)\n*)\n\ndefinition many1 :: \"string \\<Rightarrow> 'a xmlt \\<Rightarrow> 'b xmlt \\<Rightarrow> ('a \\<Rightarrow> 'b list \\<Rightarrow> 'c) \\<Rightarrow> 'c xmlt\"\nwhere\n  \"many1 tag p1 p2 = Xmlt.many1_gen tag p1 (\\<lambda>_. p2)\"\nhide_const (open) many1\n\nlemma many1_mono [partial_function_mono]:\n  fixes p1 :: \"xml \\<Rightarrow> ('b \\<Rightarrow> (string +\\<^sub>\\<bottom> 'c)) \\<Rightarrow> string +\\<^sub>\\<bottom> 'd\"\n  assumes \"\\<And>y. mono_sum_bot (p1 y)\"\n    and \"\\<And>y. y \\<in> set (tl (Xml.children x)) \\<Longrightarrow> mono_sum_bot (p2 y)\"\n  shows \"mono_sum_bot (\\<lambda>g. Xmlt.many1 t (\\<lambda>y. p1 y g) (\\<lambda>y. p2 y g) f x)\" \n  unfolding Xmlt.many1_def using assms\n  by (cases x, cases \"Xml.children x\") (auto intro!: partial_function_mono)\n\nfun length_ge_2 :: \"'a list \\<Rightarrow> bool\"\nwhere \n  \"length_ge_2 (_ # _ # _) = True\" |\n  \"length_ge_2 _ = False\"\n\nfun many2 :: \"tag \\<Rightarrow> 'a xmlt \\<Rightarrow> 'b xmlt \\<Rightarrow> 'c xmlt \\<Rightarrow> ('a \\<Rightarrow> 'b \\<Rightarrow> 'c list \\<Rightarrow> 'd) \\<Rightarrow> 'd xmlt\"\nwhere\n  \"many2 tag p1 p2 p3 f (XML name atts cs) =\n    (if name = tag \\<and> atts = [] \\<and> length_ge_2 cs then\n      (case cs of cs0 # cs1 # t \\<Rightarrow> do {\n        x \\<leftarrow> p1 cs0;\n        y \\<leftarrow> p2 cs1;\n        xs \\<leftarrow> Xmlt.map p3 t;\n        return (f x y xs)\n      })\n    else Xmlt.fail tag (XML name atts cs))\" |\n  \"many2 tag p1 p2 p3 f xml = Xmlt.fail tag xml\"\n\nlemma many2_mono [partial_function_mono]:\n  fixes p1 :: \"xml \\<Rightarrow> ('b \\<Rightarrow> (string +\\<^sub>\\<bottom> 'c)) \\<Rightarrow> string +\\<^sub>\\<bottom> 'd\"\n  assumes \"\\<And>y. mono_sum_bot (p1 y)\"\n    and \"\\<And>y. mono_sum_bot (p2 y)\"\n    and \"\\<And>y. mono_sum_bot (p3 y)\"\n  shows \"mono_sum_bot (\\<lambda>g. Xmlt.many2 t (\\<lambda>y. p1 y g) (\\<lambda>y. p2 y g) (\\<lambda>y. p3 y g) f x)\"\n  using assms\n  by (cases x, cases \"Xml.children x\", (auto intro!: partial_function_mono)[1], cases \"tl (Xml.children x)\", auto intro!: partial_function_mono)\n\nfun\n  xml1or2many_elements ::\n    \"string \\<Rightarrow> 'a xmlt \\<Rightarrow> 'b xmlt \\<Rightarrow> 'c xmlt \\<Rightarrow> ('a \\<Rightarrow> 'b option \\<Rightarrow> 'c list \\<Rightarrow> 'd) \\<Rightarrow> 'd xmlt\"\nwhere\n  \"xml1or2many_elements tag p1 p2 p3 f (XML name atts cs) =\n    (if name = tag \\<and> atts = [] \\<and> cs \\<noteq> [] then\n      (case cs of\n        cs0 # tt \\<Rightarrow>\n        do { \n          x \\<leftarrow> p1 cs0;\n          (case tt of\n            cs1 # t \\<Rightarrow>\n            do {\n              try do {\n                y \\<leftarrow> p2 cs1;\n                xs \\<leftarrow> Xmlt.map p3 t;\n                return (f x (Some y) xs)\n              } catch (\\<lambda> _. do {\n                xs \\<leftarrow> Xmlt.map p3 tt;\n                return (f x None xs)\n              })\n            }\n          | [] \\<Rightarrow> return (f x None []))}) \n     else Xmlt.fail tag (XML name atts cs))\" |\n  \"xml1or2many_elements tag p1 p2 p3 f  xml = Xmlt.fail tag xml\"\n\nfun\n  xml1many2elements_gen ::\n    \"string \\<Rightarrow> 'a xmlt \\<Rightarrow> ('a \\<Rightarrow> 'b xmlt) \\<Rightarrow> 'c xmlt \\<Rightarrow> 'd xmlt \\<Rightarrow>\n      ('a \\<Rightarrow> 'b list \\<Rightarrow> 'c \\<Rightarrow> 'd \\<Rightarrow> 'e) \\<Rightarrow> 'e xmlt\"\nwhere\n  \"xml1many2elements_gen tag p1 p2 p3 p4 f (XML name atts cs) = (\n     let ds = List.rev cs; l = length cs in\n     (if name = tag \\<and> atts = [] \\<and> l \\<ge> 3 then do {\n       x \\<leftarrow> p1 (cs ! 0);\n       xs \\<leftarrow> Xmlt.map (p2 x) (tl (take (l - 2) cs));\n       y \\<leftarrow> p3 (ds ! 1);\n       z \\<leftarrow> p4 (ds ! 0);\n       return (f x xs y z)\n     } else Xmlt.fail tag (XML name atts cs)))\" |\n  \"xml1many2elements_gen tag p1 p2 p3 p4 f xml = Xmlt.fail tag xml\"\n\nlemma xml1many2elements_gen_mono [partial_function_mono]:\n  fixes p1 :: \"xml \\<Rightarrow> ('b \\<Rightarrow> (string +\\<^sub>\\<bottom> 'c)) \\<Rightarrow> string +\\<^sub>\\<bottom> 'd\"\n  assumes p1: \"\\<And>y. mono_sum_bot (p1 y)\"\n              \"\\<And>y. mono_sum_bot (p3 y)\"\n              \"\\<And>y. mono_sum_bot (p4 y)\"\n  shows \"mono_sum_bot (\\<lambda>g. xml1many2elements_gen t (\\<lambda>y. p1 y g) p2 (\\<lambda>y. p3 y g) (\\<lambda>y. p4 y g) f x)\" \n  by (cases x, auto intro!: partial_function_mono p1)\n\nfun\n  xml1many2elements ::\n    \"string \\<Rightarrow> 'a xmlt \\<Rightarrow> 'b xmlt \\<Rightarrow> 'c xmlt \\<Rightarrow> 'd xmlt \\<Rightarrow> ('a \\<Rightarrow> 'b list \\<Rightarrow> 'c \\<Rightarrow> 'd \\<Rightarrow> 'e) \\<Rightarrow>\n      'e xmlt\"\nwhere\n  \"xml1many2elements tag p1 p2 = xml1many2elements_gen tag p1 (\\<lambda>_. p2)\"\n\nfun\n  xml_many2elements ::\n    \"string \\<Rightarrow> 'a xmlt \\<Rightarrow> 'b xmlt \\<Rightarrow> 'c xmlt \\<Rightarrow> ('a list \\<Rightarrow> 'b \\<Rightarrow> 'c \\<Rightarrow> 'd) \\<Rightarrow> 'd xmlt\"\nwhere\n  \"xml_many2elements tag p1 p2 p3 f (XML name atts cs) = (\n     let ds = List.rev cs in\n     (if name = tag \\<and> atts = [] \\<and> length_ge_2 cs then do {\n       xs \\<leftarrow> Xmlt.map p1 (List.rev (tl (tl ds)));\n       y \\<leftarrow> p2 (ds ! 1);\n       z \\<leftarrow> p3 (ds ! 0);\n       return (f xs y z)\n     } else Xmlt.fail tag (XML name atts cs)))\" |\n  \"xml_many2elements tag p1 p2 p3 f xml = Xmlt.fail tag xml\"\n\ndefinition options :: \"(string \\<times> 'a xmlt) list \\<Rightarrow> 'a xmlt\"\nwhere\n  \"options ps x =\n    (case map_of ps (Xml.tag x) of \n      None \\<Rightarrow> error (concat\n        [''expected one of: '', concat (map (\\<lambda>p. fst p @ '' '') ps), ''\\<newline>'', ''but found'', ''\\<newline>'', show x])\n    | Some p \\<Rightarrow> p x)\"\nhide_const (open) options\n\nlemma options_mono_gen [partial_function_mono]:\n  assumes p: \"\\<And> k p. (k, p) \\<in> set ps \\<Longrightarrow> mono_sum_bot (p x)\"\n  shows \"mono_sum_bot (\\<lambda> g. Xmlt.options (map (\\<lambda> (k, p). (k, (\\<lambda> y. p y g))) ps) x)\"\nproof -\n  {\n    fix g\n    have \"(map (\\<lambda>p. fst p @ '' '') (map (\\<lambda>(k, p). (k, \\<lambda>y. p y g)) ps)) = \n      map (\\<lambda>p. fst p @ '' '') ps\"\n      by (induct ps) (auto)\n  } note id = this\n  {\n    fix z\n    have \"mono_sum_bot\n      (\\<lambda>g. case map_of (map (\\<lambda>(k, p). (k, \\<lambda>y. p y g)) ps) (Xml.tag x) of\n        None \\<Rightarrow> z\n      | Some p \\<Rightarrow> p x)\"\n      using p\n    proof (induct ps)\n      case Nil\n      show ?case by (auto intro: partial_function_mono)\n    next\n      case (Cons kp ps)\n      obtain k p where kp: \"kp = (k,p)\" by force\n      note Cons = Cons[unfolded kp]\n      from Cons(2) have monop: \"mono_sum_bot (p x)\" and mono: \"\\<And> k p. (k,p) \\<in> set ps \\<Longrightarrow> mono_sum_bot (p x)\" by auto\n      show ?case \n      proof (cases \"Xml.tag x = k\")\n        case True\n        thus ?thesis unfolding kp using monop by auto\n      next\n        case False\n        thus ?thesis using Cons(1) mono unfolding kp by auto\n      qed\n    qed\n  } note main = this\n  show ?thesis unfolding Xmlt.options_def \n    unfolding id\n    by (rule main)\nqed\n\n(* instantiate this lemma to have the monotonicity lemmas for lists of variable lengths which\n   are then applicable, e.g., for lists of length 3 it would be\n\nmono_sum_bot (p1 x) \\<Longrightarrow> mono_sum_bot (p2 x) \\<Longrightarrow> mono_sum_bot (p3 x) \n\\<Longrightarrow> mono_sum_bot (\\<lambda>g. Xmlt.options [(k1, \\<lambda>y. p1 y g), (k2, \\<lambda>y. p2 y g), (k3, \\<lambda>y. p3 y g)] x)\n\n*)\nlocal_setup \\<open>fn lthy => \n  let\n    val N = 30 (* we require monotonicity lemmas for xml-options for lists up to length N *) \n    val thy = Proof_Context.theory_of lthy\n    val options = @{term \"Xmlt.options :: (string \\<times> (xml \\<Rightarrow> (string +\\<^sub>\\<bottom> 'd))) list \\<Rightarrow> xml \\<Rightarrow> string +\\<^sub>\\<bottom> 'd\"}\n    val mono_sum_bot = @{term \"mono_sum_bot :: (('a \\<Rightarrow> ('b +\\<^sub>\\<bottom> 'c)) \\<Rightarrow> string +\\<^sub>\\<bottom> 'd) \\<Rightarrow> bool\"}\n    val ktyp = @{typ string}\n    val x = @{term \"x :: xml\"}\n    val y = @{term \"y :: xml\"}\n    val g = @{term \"g :: 'a \\<Rightarrow> 'b +\\<^sub>\\<bottom> 'c\"}\n    val ptyp = @{typ \"xml \\<Rightarrow> ('a \\<Rightarrow> ('b +\\<^sub>\\<bottom> 'c)) \\<Rightarrow> string +\\<^sub>\\<bottom> 'd\"}\n    fun k i = Free (\"k\" ^ string_of_int i,ktyp)\n    fun p i = Free (\"p\" ^ string_of_int i,ptyp)\n    fun prem i = HOLogic.mk_Trueprop (mono_sum_bot $ (p i $ x))\n    fun prems n = 1 upto n |> map prem\n    fun pair i = HOLogic.mk_prod (k i, lambda y (p i $ y $ g))\n    fun pair2 i = HOLogic.mk_prod (k i, p i)\n    fun list n = 1 upto n |> map pair |> HOLogic.mk_list @{typ \"(string \\<times> (xml \\<Rightarrow> string +\\<^sub>\\<bottom> 'd))\"}\n    fun list2 n = 1 upto n |> map pair2 |> HOLogic.mk_list (HOLogic.mk_prodT (ktyp,ptyp))\n    fun concl n = HOLogic.mk_Trueprop (mono_sum_bot $ lambda g (options $ (list n) $ x))\n    fun xs n = x :: (1 upto n |> map (fn i => [p i, k i]) |> List.concat)\n       |> map (fst o dest_Free)\n    fun tac n pc =\n      let\n        val {prems = prems, context = ctxt} = pc\n        val mono_thm = Thm.instantiate' \n            (map (SOME o Thm.ctyp_of ctxt) [@{typ 'a},@{typ 'b},@{typ 'c},@{typ 'd}]) \n            (map (SOME o Thm.cterm_of ctxt) [list2 n,x]) @{thm Xmlt.options_mono_gen}\n      in \n        Method.insert_tac ctxt (mono_thm :: prems) 1 THEN force_tac ctxt 1\n      end\n    fun thm n = Goal.prove lthy (xs n) (prems n) (concl n) (tac n)\n    val thms = map thm (0 upto N)\n  in Local_Theory.note ((@{binding \"options_mono_thms\"}, []), thms) lthy |> snd end\n\\<close>\n\ndeclare Xmlt.options_mono_thms [partial_function_mono]\n\nfun choice :: \"string \\<Rightarrow> 'a xmlt list \\<Rightarrow> 'a xmlt\"\nwhere\n  \"choice e [] x = error (concat [''error in parsing choice for '', e, ''\\<newline>'', show x])\" |\n  \"choice e (p # ps) x = (try p x catch (\\<lambda>_. choice e ps x))\"\nhide_const (open) choice\n\nlemma choice_mono_2 [partial_function_mono]:\n  assumes p: \"mono_sum_bot (p1 x)\"\n             \"mono_sum_bot (p2 x)\"\n  shows \"mono_sum_bot (\\<lambda> g. Xmlt.choice e [(\\<lambda> y. p1 y g), (\\<lambda> y. p2 y g)] x)\"\n  using p by (auto intro!: partial_function_mono) \n\nlemma choice_mono_3 [partial_function_mono]:\n  assumes p: \"mono_sum_bot (p1 x)\"\n             \"mono_sum_bot (p2 x)\"\n             \"mono_sum_bot (p3 x)\"\n  shows \"mono_sum_bot (\\<lambda> g. Xmlt.choice e [(\\<lambda> y. p1 y g), (\\<lambda> y. p2 y g), (\\<lambda> y. p3 y g)] x)\"\n  using p by (auto intro!: partial_function_mono) \n\nfun change :: \"'a xmlt \\<Rightarrow> ('a \\<Rightarrow> 'b) \\<Rightarrow> 'b xmlt\"\nwhere\n  \"change p f x = p x \\<bind> return \\<circ> f\"\nhide_const (open) change\n\nlemma change_mono [partial_function_mono]:\n  assumes p: \"\\<And>y. mono_sum_bot (p1 y)\"\n  shows \"mono_sum_bot (\\<lambda>g. Xmlt.change (\\<lambda>y. p1 y g) f x)\" \n  by (cases x, insert p, auto intro!: partial_function_mono)\n\nfun int_of_digit :: \"char \\<Rightarrow> string +\\<^sub>\\<bottom> int\"\nwhere\n  \"int_of_digit x =\n    (if x = CHR ''0'' then return 0\n    else if x = CHR ''1'' then return 1\n    else if x = CHR ''2'' then return 2\n    else if x = CHR ''3'' then return 3\n    else if x = CHR ''4'' then return 4\n    else if x = CHR ''5'' then return 5\n    else if x = CHR ''6'' then return 6\n    else if x = CHR ''7'' then return 7\n    else if x = CHR ''8'' then return 8\n    else if x = CHR ''9'' then return 9\n    else error (x # '' is not a digit''))\"\n\nfun int_of_string_aux :: \"int \\<Rightarrow> string \\<Rightarrow> string +\\<^sub>\\<bottom> int\"\nwhere\n  \"int_of_string_aux n [] = return n\" |\n  \"int_of_string_aux n (d # s) = (int_of_digit d \\<bind> (\\<lambda>m. int_of_string_aux (10 * n + m) s))\"\n\ndefinition int_of_string :: \"string \\<Rightarrow> string +\\<^sub>\\<bottom> int\"\nwhere\n  \"int_of_string s =\n    (if s = [] then error ''cannot convert empty string into number'' \n    else if take 1 s = ''-'' then int_of_string_aux 0 (tl s) \\<bind> (\\<lambda> i. return (0 - i))\n    else int_of_string_aux 0 s)\"\n\nhide_const int_of_string_aux\n\nfun int :: \"tag \\<Rightarrow> int xmlt\"\nwhere\n  \"int tag x = (Xmlt.text tag x \\<bind> int_of_string)\"\nhide_const (open) int\n\nfun nat :: \"tag \\<Rightarrow> nat xmlt\"\nwhere\n  \"nat tag x = do {\n    txt \\<leftarrow> Xmlt.text tag x;\n    i \\<leftarrow> int_of_string txt;\n    return (Int.nat i)\n  }\"\nhide_const (open) nat\n\ndefinition rat :: \"rat xmlt\"\nwhere\n  \"rat = Xmlt.options [\n    (''integer'', Xmlt.change (Xmlt.int ''integer'') of_int),\n    (''rational'',\n      Xmlt.pair ''rational'' (Xmlt.int ''numerator'') (Xmlt.int ''denominator'')\n        (\\<lambda> x y. of_int x / of_int y))]\"\nhide_const (open) rat\n\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/XML/Xmlt.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5506073655352405, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.29890452219342434}}
{"text": "subsection \\<open>Pure pattern matching rule sets\\<close>\n\ntheory Rewriting_Pterm\nimports Rewriting_Pterm_Elim\nbegin\n\ntype_synonym prule = \"name \\<times> pterm\"\n\nprimrec prule :: \"prule \\<Rightarrow> bool\" where\n\"prule (_, rhs) \\<longleftrightarrow> wellformed rhs \\<and> closed rhs \\<and> is_abs rhs\"\n\nlemma pruleI[intro!]: \"wellformed rhs \\<Longrightarrow> closed rhs \\<Longrightarrow> is_abs rhs \\<Longrightarrow> prule (name, rhs)\"\nby simp\n\nlocale prules = constants C_info \"fst |`| rs\" for C_info and rs :: \"prule fset\" +\n  assumes all_rules: \"fBall rs prule\"\n  assumes fmap: \"is_fmap rs\"\n  assumes not_shadows: \"fBall rs (\\<lambda>(_, rhs). \\<not> shadows_consts rhs)\"\n  assumes welldefined_rs: \"fBall rs (\\<lambda>(_, rhs). welldefined rhs)\"\n\nsubsubsection \\<open>Rewriting\\<close>\n\ninductive prewrite :: \"prule fset \\<Rightarrow> pterm \\<Rightarrow> pterm \\<Rightarrow> bool\" (\"_/ \\<turnstile>\\<^sub>p/ _ \\<longrightarrow>/ _\" [50,0,50] 50) for rs where\nstep: \"(name, rhs) |\\<in>| rs \\<Longrightarrow> rs \\<turnstile>\\<^sub>p Pconst name \\<longrightarrow> rhs\" |\nbeta: \"c |\\<in>| cs \\<Longrightarrow> c \\<turnstile> t \\<rightarrow> t' \\<Longrightarrow> rs \\<turnstile>\\<^sub>p Pabs cs $\\<^sub>p t \\<longrightarrow> t'\" |\n\"fun\": \"rs \\<turnstile>\\<^sub>p t \\<longrightarrow> t' \\<Longrightarrow> rs \\<turnstile>\\<^sub>p t $\\<^sub>p u \\<longrightarrow> t' $\\<^sub>p u\" |\narg: \"rs \\<turnstile>\\<^sub>p u \\<longrightarrow> u' \\<Longrightarrow> rs \\<turnstile>\\<^sub>p t $\\<^sub>p u \\<longrightarrow> t $\\<^sub>p u'\"\n\nglobal_interpretation prewrite: rewriting \"prewrite rs\" for rs\nby standard (auto intro: prewrite.intros simp: app_pterm_def)+\n\nabbreviation prewrite_rt :: \"prule fset \\<Rightarrow> pterm \\<Rightarrow> pterm \\<Rightarrow> bool\" (\"_/ \\<turnstile>\\<^sub>p/ _ \\<longrightarrow>*/ _\" [50,0,50] 50) where\n\"prewrite_rt rs \\<equiv> (prewrite rs)\\<^sup>*\\<^sup>*\"\n\nsubsubsection \\<open>Translation from @{typ irule_set} to @{typ \"prule fset\"}\\<close>\n\ndefinition finished :: \"irule_set \\<Rightarrow> bool\" where\n\"finished rs = fBall rs (\\<lambda>(_, irs). arity irs = 0)\"\n\ndefinition translate_rhs :: \"irules \\<Rightarrow> pterm\" where\n\"translate_rhs = snd \\<circ> fthe_elem\"\n\ndefinition compile :: \"irule_set \\<Rightarrow> prule fset\" where\n\"compile = fimage (map_prod id translate_rhs)\"\n\nlemma compile_heads: \"fst |`| compile rs = fst |`| rs\"\nunfolding compile_def by simp\n\nsubsubsection \\<open>Correctness of translation\\<close>\n\nlemma arity_zero_shape:\n  assumes \"arity_compatibles rs\" \"arity rs = 0\" \"is_fmap rs\" \"rs \\<noteq> {||}\"\n  obtains t where \"rs = {| ([], t) |}\"\nproof -\n  from assms obtain ppats prhs where \"(ppats, prhs) |\\<in>| rs\"\n    by fast\n\n  moreover {\n    fix pats rhs\n    assume \"(pats, rhs) |\\<in>| rs\"\n    with assms have \"length pats = 0\"\n      by (metis arity_compatible_length)\n    hence \"pats = []\"\n      by simp\n  }\n  note all = this\n\n  ultimately have proto: \"([], prhs) |\\<in>| rs\" by auto\n\n  have \"fBall rs (\\<lambda>(pats, rhs). pats = [] \\<and> rhs = prhs)\"\n    proof safe\n      fix pats rhs\n      assume cur: \"(pats, rhs) |\\<in>| rs\"\n      with all show \"pats = []\" .\n      with cur have \"([], rhs) |\\<in>| rs\" by auto\n\n      with proto show \"rhs = prhs\"\n        using assms by (auto dest: is_fmapD)\n    qed\n  hence \"fBall rs (\\<lambda>r. r = ([], prhs))\"\n    by blast\n  with assms have \"rs = {| ([], prhs) |}\"\n    by (simp add: singleton_fset_is)\n  thus thesis\n    by (rule that)\nqed\n\nlemma (in irules) compile_rules:\n  assumes \"finished rs\"\n  shows \"prules C_info (compile rs)\"\nproof\n  show \"is_fmap (compile rs)\"\n    using fmap\n    unfolding compile_def map_prod_def id_apply\n    by (rule is_fmap_image)\nnext\n  show \"fdisjnt (fst |`| compile rs) C\"\n    unfolding compile_def\n    using disjnt by simp\nnext\n  have\n    \"fBall (compile rs) prule\"\n    \"fBall (compile rs) (\\<lambda>(_, rhs). \\<not> shadows_consts rhs)\"\n    \"fBall (compile rs) (\\<lambda>(_, rhs). welldefined rhs)\"\n    proof (safe del: fsubsetI)\n      fix name rhs\n      assume \"(name, rhs) |\\<in>| compile rs\" (* FIXME clone of compile_correct *)\n      then obtain irs where \"(name, irs) |\\<in>| rs\" \"rhs = translate_rhs irs\"\n        unfolding compile_def by force\n      hence \"is_fmap irs\" \"irs \\<noteq> {||}\" \"arity irs = 0\"\n        using assms inner unfolding finished_def by blast+\n      moreover have \"arity_compatibles irs\"\n        using \\<open>(name, irs) |\\<in>| rs\\<close> inner by (blast dest: fpairwiseD)\n      ultimately obtain u where \"irs = {| ([], u) |}\"\n        by (metis arity_zero_shape)\n      hence \"rhs = u\" and u: \"([], u) |\\<in>| irs\"\n        unfolding \\<open>rhs = _\\<close> translate_rhs_def by simp+\n      hence \"abs_ish [] u\"\n        using inner \\<open>(name, irs) |\\<in>| rs\\<close> by blast\n      thus \"is_abs rhs\"\n        unfolding abs_ish_def \\<open>rhs = u\\<close> by simp\n\n      show \"wellformed rhs\"\n        using u \\<open>(name, irs) |\\<in>| rs\\<close> inner unfolding \\<open>rhs = u\\<close>\n        by blast\n\n      have \"closed_except u {||}\"\n        using u inner \\<open>(name, irs) |\\<in>| rs\\<close>\n        by (metis (mono_tags, lifting) case_prod_conv fbspec freess_empty)\n      thus \"closed rhs\"\n        unfolding \\<open>rhs = u\\<close> .\n\n      {\n        assume \"shadows_consts rhs\"\n        hence \"shadows_consts u\"\n          unfolding compile_def \\<open>rhs = u\\<close> by simp\n        moreover have \"\\<not> shadows_consts u\"\n          using inner \\<open>([], u) |\\<in>| irs\\<close> \\<open>(name, irs) |\\<in>| rs\\<close> by blast\n        ultimately show False by blast\n      }\n\n      have \"welldefined u\"\n        using fbspec[OF inner \\<open>(name, irs) |\\<in>| rs\\<close>, simplified] \\<open>([], u) |\\<in>| irs\\<close>\n        by blast\n      thus \"welldefined rhs\"\n        unfolding \\<open>rhs = u\\<close> compile_def\n        by simp\n    qed\n  thus\n    \"fBall (compile rs) prule\"\n    \"fBall (compile rs) (\\<lambda>(_, rhs). \\<not> pre_constants.shadows_consts C_info (fst |`| compile rs) rhs)\"\n    \"fBall (compile rs) (\\<lambda>(_, rhs). pre_constants.welldefined C_info (fst |`| compile rs) rhs)\"\n    unfolding compile_heads by auto\nnext\n  show \"distinct all_constructors\"\n    by (fact distinct_ctr)\nqed\n\ntheorem (in irules) compile_correct:\n  assumes \"compile rs \\<turnstile>\\<^sub>p t \\<longrightarrow> t'\" \"finished rs\"\n  shows \"rs \\<turnstile>\\<^sub>i t \\<longrightarrow> t'\"\nusing assms(1) proof induction\n  case (step name rhs)\n  then obtain irs where \"rhs = translate_rhs irs\" \"(name, irs) |\\<in>| rs\"\n    unfolding compile_def by force\n  hence \"arity_compatibles irs\"\n    using inner by (blast dest: fpairwiseD)\n\n  have \"is_fmap irs\" \"irs \\<noteq> {||}\" \"arity irs = 0\"\n    using assms inner \\<open>(name, irs) |\\<in>| rs\\<close> unfolding finished_def by blast+\n  then obtain u where \"irs = {| ([], u) |}\"\n    using \\<open>arity_compatibles irs\\<close>\n    by (metis arity_zero_shape)\n\n  show ?case\n    unfolding \\<open>rhs = _\\<close>\n    apply (rule irewrite.step)\n      apply fact\n    unfolding \\<open>irs = _\\<close> translate_rhs_def irewrite_step_def\n    by (auto simp: const_term_def)\nqed (auto intro: irewrite.intros)\n\ntheorem (in irules) compile_complete:\n  assumes \"rs \\<turnstile>\\<^sub>i t \\<longrightarrow> t'\" \"finished rs\"\n  shows \"compile rs \\<turnstile>\\<^sub>p t \\<longrightarrow> t'\"\nusing assms(1) proof induction\n  case (step name irs params rhs t t')\n  hence \"arity_compatibles irs\"\n    using inner by (blast dest: fpairwiseD)\n\n  have \"is_fmap irs\" \"irs \\<noteq> {||}\" \"arity irs = 0\"\n    using assms inner step unfolding finished_def by blast+\n  then obtain u where \"irs = {| ([], u) |}\"\n    using \\<open>arity_compatibles irs\\<close>\n    by (metis arity_zero_shape)\n  with step have \"name, [], u \\<turnstile>\\<^sub>i t \\<rightarrow> t'\"\n    by simp\n  hence \"t = Pconst name\"\n    unfolding irewrite_step_def\n    by (cases t) (auto split: if_splits simp: const_term_def)\n  hence \"t' = u\"\n    using \\<open>name, [], u \\<turnstile>\\<^sub>i t \\<rightarrow> t'\\<close>\n    unfolding irewrite_step_def\n    by (cases t) (auto split: if_splits simp: const_term_def)\n\n  have \"(name, t') |\\<in>| compile rs\"\n    unfolding compile_def\n    proof\n      show \"(name, t') = map_prod id translate_rhs (name, irs)\"\n        using \\<open>irs = _\\<close> \\<open>t' = u\\<close>\n        by (simp add: split_beta translate_rhs_def)\n    qed fact\n  thus ?case\n    unfolding \\<open>t = _\\<close>\n    by (rule prewrite.step)\nqed (auto intro: prewrite.intros)\n\nexport_code\n  compile finished\n  checking Scala\n\nend", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/CakeML_Codegen/Rewriting/Rewriting_Pterm.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.2989045221934243}}
{"text": "(* \n   Title: Psi-calculi   \n   Author/Maintainer: Jesper Bengtson (jebe@itu.dk), 2012\n*)\ntheory Chain\n  imports \"HOL-Nominal.Nominal\"\nbegin\n\nlemma pt_set_nil: \n  fixes Xs :: \"'a set\"\n  assumes pt: \"pt TYPE('a) TYPE ('x)\"\n  and     at: \"at TYPE('x)\"\n\n  shows \"([]::'x prm)\\<bullet>Xs = Xs\"\nby(auto simp add: perm_set_def pt1[OF pt])\n\nlemma pt_set_append: \n  fixes pi1 :: \"'x prm\"\n  and   pi2 :: \"'x prm\"\n  and   Xs  :: \"'a set\"\n  assumes pt: \"pt TYPE('a) TYPE ('x)\"\n  and     at: \"at TYPE('x)\"\n\n  shows \"(pi1@pi2)\\<bullet>Xs = pi1\\<bullet>(pi2\\<bullet>Xs)\"\nby(auto simp add: perm_set_def pt2[OF pt])\n\nlemma pt_set_prm_eq: \n  fixes pi1 :: \"'x prm\"\n  and   pi2 :: \"'x prm\"\n  and   Xs  :: \"'a set\"\n  assumes pt: \"pt TYPE('a) TYPE ('x)\"\n  and     at: \"at TYPE('x)\"\n\n  shows \"pi1 \\<triangleq> pi2  \\<Longrightarrow> pi1\\<bullet>Xs = pi2\\<bullet>Xs\"\nby(auto simp add: perm_set_def pt3[OF pt])\n\nlemma pt_set_inst:\n  assumes pt: \"pt TYPE('a) TYPE ('x)\"\n  and     at: \"at TYPE('x)\"\n\n  shows \"pt TYPE('a set) TYPE('x)\"\napply(simp add: pt_def pt_set_nil[OF pt, OF at] pt_set_append[OF pt, OF at])\napply(clarify)\nby(rule pt_set_prm_eq[OF pt, OF at])\n\nlemma pt_ball_eqvt:\n  fixes pi :: \"'a prm\"\n  and   Xs :: \"'b set\"\n  and   P :: \"'b \\<Rightarrow> bool\"\n\n  assumes pt: \"pt TYPE('b) TYPE('a)\"\n  and     at: \"at TYPE('a)\"\n\n  shows \"(pi \\<bullet> (\\<forall>x \\<in> Xs. P x)) = (\\<forall>x \\<in> (pi \\<bullet> Xs). pi \\<bullet> P (rev pi \\<bullet> x))\"\napply(auto simp add: perm_bool)\napply(drule_tac pi=\"rev pi\" in pt_set_bij2[OF pt, OF at])\napply(simp add: pt_rev_pi[OF pt_set_inst[OF pt, OF at], OF at])\napply(drule_tac pi=\"pi\" in pt_set_bij2[OF pt, OF at])\napply(erule_tac x=\"pi \\<bullet> x\" in ballE)\napply(simp add: pt_rev_pi[OF pt, OF at])\nby simp\n\nlemma perm_cart_prod:\n  fixes Xs :: \"'b set\"\n  and   Ys :: \"'c set\"\n  and   p  :: \"'a prm\"\n\n  assumes pt1: \"pt TYPE('b) TYPE('a)\"\n  and     pt2: \"pt TYPE('c) TYPE('a)\"\n  and     at:  \"at TYPE('a)\"\n\n  shows \"(p \\<bullet> (Xs \\<times> Ys)) = (((p \\<bullet> Xs) \\<times> (p \\<bullet> Ys))::(('b \\<times> 'c) set))\"\nby(auto simp add: perm_set_def)\n\nlemma supp_member:\n  fixes Xs :: \"'b set\"\n  and   x  :: 'a\n\n  assumes pt: \"pt TYPE('b) TYPE('a)\"\n  and     at: \"at TYPE('a)\"\n  and     fs: \"fs TYPE('b) TYPE('a)\"\n  and     \"finite Xs\"\n  and     \"x \\<in> ((supp Xs)::'a set)\"\n\n  obtains X where \"(X::'b) \\<in> Xs\" and \"x \\<in> supp X\"\nproof -\n  from \\<open>finite Xs\\<close> \\<open>x \\<in> supp Xs\\<close> have \"\\<exists>X::'b. (X \\<in> Xs) \\<and> (x \\<in> (supp X))\"\n  proof(induct rule: finite_induct)\n    case empty\n    from \\<open>x \\<in> ((supp {})::'a set)\\<close> have False\n      by(simp add: supp_set_empty)\n    thus ?case by simp\n  next\n    case(insert y Xs)\n    show ?case\n    proof(case_tac \"x \\<in> supp y\")\n      assume \"x \\<in> supp y\"\n      thus ?case by force\n    next\n      assume \"x \\<notin> supp y\"\n      with \\<open>x \\<in> supp(insert y Xs)\\<close> have \"x \\<in> supp Xs\"\n        by(simp add: supp_fin_insert[OF pt, OF at, OF fs, OF \\<open>finite Xs\\<close>])\n      with \\<open>x \\<in> supp Xs \\<Longrightarrow> \\<exists>X. X \\<in> Xs \\<and> x \\<in> supp X\\<close>\n      show ?case by force\n    qed\n  qed\n  with that show ?thesis by blast\nqed\n\nlemma supp_cart_prod_empty[simp]:\n  fixes Xs :: \"'b set\"\n\n  shows \"supp (Xs \\<times> {}) = ({}::'a set)\"\n  and   \"supp ({} \\<times> Xs) = ({}::'a set)\"\nby(auto simp add: supp_set_empty)\n\nlemma supp_cart_prod:\n  fixes Xs :: \"'b set\"\n  and   Ys :: \"'c set\"\n\n  assumes pt1: \"pt TYPE('b) TYPE('a)\"\n  and     pt2: \"pt TYPE('c) TYPE('a)\"\n  and     fs1: \"fs TYPE('b) TYPE('a)\"\n  and     fs2: \"fs TYPE('c) TYPE('a)\"\n  and     at:  \"at TYPE('a)\"\n  and     f1:  \"finite Xs\"\n  and     f2:  \"finite Ys\"\n  and     a:   \"Xs \\<noteq> {}\"\n  and     b:   \"Ys \\<noteq> {}\"\n\n  shows \"((supp (Xs \\<times> Ys))::'a set) = ((supp Xs) \\<union> (supp Ys))\"\nproof -\n  from f1 f2 have f3: \"finite(Xs \\<times> Ys)\" by simp\n  show ?thesis\n    apply(simp add: supp_of_fin_sets[OF pt_prod_inst[OF pt1, OF pt2], OF at, OF fs_prod_inst[OF fs1, OF fs2], OF f3] supp_prod)\n    apply(rule equalityI)\n    using Union_included_in_supp[OF pt1, OF at, OF fs1, OF f1] Union_included_in_supp[OF pt2, OF at, OF fs2, OF f2]\n    apply(force simp add: supp_prod)\n    using a b\n    apply(auto simp add: supp_prod)\n    using supp_member[OF pt1, OF at, OF fs1, OF f1]\n    apply blast\n    using supp_member[OF pt2, OF at, OF fs2, OF f2]\n    by blast\nqed\n\nlemma fresh_cart_prod:\n  fixes x  :: 'a\n  and   Xs :: \"'b set\"\n  and   Ys :: \"'c set\"\n\n  assumes pt1: \"pt TYPE('b) TYPE('a)\"\n  and     pt2: \"pt TYPE('c) TYPE('a)\"\n  and     fs1: \"fs TYPE('b) TYPE('a)\"\n  and     fs2: \"fs TYPE('c) TYPE('a)\"\n  and     at:  \"at TYPE('a)\"\n  and     f1:  \"finite Xs\"\n  and     f2:  \"finite Ys\"\n  and     a:   \"Xs \\<noteq> {}\"\n  and     b:   \"Ys \\<noteq> {}\"\n\n  shows \"(x \\<sharp> (Xs \\<times> Ys)) = (x \\<sharp> Xs \\<and> x \\<sharp> Ys)\"\nusing assms\nby(simp add: supp_cart_prod fresh_def)\n\nlemma fresh_star_cart_prod:\n  fixes Zs   :: \"'a set\"\n  and   xvec :: \"'a list\"\n  and   Xs   :: \"'b set\"\n  and   Ys   :: \"'c set\"\n\n  assumes pt1: \"pt TYPE('b) TYPE('a)\"\n  and     pt2: \"pt TYPE('c) TYPE('a)\"\n  and     fs1: \"fs TYPE('b) TYPE('a)\"\n  and     fs2: \"fs TYPE('c) TYPE('a)\"\n  and     at:  \"at TYPE('a)\"\n  and     f1:  \"finite Xs\"\n  and     f2:  \"finite Ys\"\n  and     a:   \"Xs \\<noteq> {}\"\n  and     b:   \"Ys \\<noteq> {}\"\n\n  shows \"(Zs \\<sharp>* (Xs \\<times> Ys)) = (Zs \\<sharp>* Xs \\<and> Zs \\<sharp>* Ys)\"\n  and   \"(xvec \\<sharp>* (Xs \\<times> Ys)) = (xvec \\<sharp>* Xs \\<and> xvec \\<sharp>* Ys)\"\nusing assms\nby(force simp add: fresh_cart_prod fresh_star_def)+\n\nlemma permCommute:\n  fixes p  :: \"'a prm\"\n  and   q  :: \"'a prm\"\n  and   P  :: 'x\n  and   Xs :: \"'a set\"\n  and   Ys :: \"'a set\"\n\n  assumes pt: \"pt TYPE('x) TYPE('a)\"\n  and     at: \"at TYPE('a)\"\n  and     a: \"(set p) \\<subseteq> Xs \\<times> Ys\"\n  and     b: \"Xs \\<sharp>* q\"\n  and     c: \"Ys \\<sharp>* q\"\n\n  shows \"p \\<bullet> q \\<bullet> P = q \\<bullet> p \\<bullet> P\"\nproof -\n  have \"p \\<bullet> q \\<bullet> P = (p \\<bullet> q) \\<bullet> p \\<bullet> P\"\n    by(rule pt_perm_compose[OF pt, OF at])\n  moreover from at have \"pt TYPE('a) TYPE('a)\"\n    by(rule at_pt_inst)\n  hence \"pt TYPE(('a \\<times> 'a) list) TYPE('a)\"\n    by(force intro: pt_prod_inst pt_list_inst)\n  hence \"p \\<bullet> q = q\" using at a b c\n    by(rule pt_freshs_freshs)\n  ultimately show ?thesis by simp\nqed\n\n\ndefinition\n  distinctPerm :: \"'a prm \\<Rightarrow> bool\" where\n  \"distinctPerm p \\<equiv> distinct((map fst p)@(map snd p))\"\n\nlemma at_set_avoiding_aux':\n  fixes Xs::\"'a set\"\n  and   As::\"'a set\"\n  assumes at: \"at TYPE('a)\"\n  and     a: \"finite Xs\"\n  and     b: \"Xs \\<subseteq> As\"\n  and     c: \"finite As\"\n  and     d: \"finite ((supp c)::'a set)\"\n  shows \"\\<exists>(Ys::'a set) (pi::'a prm). Ys\\<sharp>*c \\<and> Ys \\<inter> As = {} \\<and> (pi\\<bullet>Xs=Ys) \\<and> \n          set pi \\<subseteq> Xs \\<times> Ys \\<and> finite Ys \\<and> (distinctPerm pi)\"\nusing a b c\nproof (induct)\n  case empty\n  have \"({}::'a set)\\<sharp>*c\" by (simp add: fresh_star_def)\n  moreover\n  have \"({}::'a set) \\<inter> As = {}\" by simp\n  moreover\n  have \"([]::'a prm)\\<bullet>{} = ({}::'a set)\"\n    by(rule pt1) (metis Nominal.pt_set_inst at at_pt_inst)\n  moreover\n  have \"set ([]::'a prm) \\<subseteq> {} \\<times> {}\" by simp\n  moreover \n  have \"finite ({}::'a set)\" by simp\n  moreover have \"distinctPerm([]::'a prm)\"\n    by(simp add: distinctPerm_def)\n  ultimately show ?case by blast\nnext\n  case (insert x Xs)\n  then have ih: \"\\<exists>Ys pi. Ys\\<sharp>*c \\<and> Ys \\<inter> As = {} \\<and> pi\\<bullet>Xs = Ys \\<and> set pi \\<subseteq> Xs \\<times> Ys \\<and> finite Ys \\<and> distinctPerm pi\" by simp\n  then obtain Ys pi where a1: \"Ys\\<sharp>*c\" and a2: \"Ys \\<inter> As = {}\" and a3: \"(pi::'a prm)\\<bullet>Xs = Ys\" and \n                          a4: \"set pi \\<subseteq> Xs \\<times> Ys\" and a5: \"finite Ys\" \n                      and a6: \"distinctPerm pi\" by blast\n  have b: \"x\\<notin>Xs\" by fact\n  have d1: \"finite As\" by fact\n  have d2: \"finite Xs\" by fact\n  have d3: \"insert x Xs \\<subseteq> As\" by fact\n  have d4: \"finite((supp pi)::'a set)\"\n    by(induct pi)\n      (auto simp add: supp_list_nil supp_prod at_fin_set_supp[OF at]\n                      supp_list_cons at_supp[OF at])\n  have \"\\<exists>y::'a. y\\<sharp>(c,x,Ys,As,pi)\" using d d1 a5 d4\n    by (rule_tac at_exists_fresh'[OF at])\n       (simp add: supp_prod at_supp[OF at] at_fin_set_supp[OF at])\n  then obtain y::\"'a\" where  e: \"y\\<sharp>(c,x,Ys,As,pi)\" by blast\n  have \"({y}\\<union>Ys)\\<sharp>*c\" using a1 e by (simp add: fresh_star_def)\n  moreover\n  have \"({y}\\<union>Ys)\\<inter>As = {}\" using a2 d1 e by (simp add: fresh_prod at_fin_set_fresh[OF at])\n  moreover\n  have \"(((pi\\<bullet>x,y)#pi)\\<bullet>(insert x Xs)) = {y}\\<union>Ys\"\n  proof -\n    have eq: \"[(pi\\<bullet>x,y)]\\<bullet>Ys = Ys\" \n    proof -\n      have \"(pi\\<bullet>x)\\<sharp>Ys\" using a3[symmetric] b d2\n        by(simp add: pt_fresh_bij[OF pt_set_inst, OF at_pt_inst[OF at], OF at, OF at]\n                     at_fin_set_fresh[OF at d2])\n      moreover\n      have \"y\\<sharp>Ys\" using e by simp\n      ultimately show \"[(pi\\<bullet>x,y)]\\<bullet>Ys = Ys\" \n        by (simp add: pt_fresh_fresh[OF pt_set_inst, OF at_pt_inst[OF at], OF at, OF at])\n    qed\n    have \"(((pi\\<bullet>x,y)#pi)\\<bullet>({x}\\<union>Xs)) = ([(pi\\<bullet>x,y)]\\<bullet>(pi\\<bullet>({x}\\<union>Xs)))\"\n      by (simp add: pt2[symmetric, OF pt_set_inst, OF at_pt_inst[OF at], OF at])\n    also have \"\\<dots> = {y}\\<union>([(pi\\<bullet>x,y)]\\<bullet>(pi\\<bullet>Xs))\" \n      by (simp only: union_eqvt perm_set_def at_calc[OF at])(auto)\n    also have \"\\<dots> = {y}\\<union>([(pi\\<bullet>x,y)]\\<bullet>Ys)\" using a3 by simp\n    also have \"\\<dots> = {y}\\<union>Ys\" using eq by simp\n    finally show \"(((pi\\<bullet>x,y)#pi)\\<bullet>(insert x Xs)) = {y}\\<union>Ys\" by auto\n  qed\n  moreover\n  have \"pi\\<bullet>x=x\" using a4 b a2 a3 d3 by (rule_tac at_prm_fresh2[OF at]) (auto)\n  then have \"set ((pi\\<bullet>x,y)#pi) \\<subseteq> (insert x Xs) \\<times> ({y}\\<union>Ys)\" using a4 by auto\n  moreover \n  have \"finite ({y}\\<union>Ys)\" using a5 by simp\n  moreover from \\<open>Ys \\<inter> As = {}\\<close> \\<open>(insert x Xs) \\<subseteq> As\\<close> \\<open>finite Ys\\<close> have \"x \\<notin> Ys\"\n    by(auto simp add: fresh_def at_fin_set_supp[OF at])\n  with a6 \\<open>pi \\<bullet> x = x\\<close> \\<open>x \\<notin> Xs\\<close> \\<open>(set pi) \\<subseteq> Xs \\<times> Ys\\<close> e have \"distinctPerm((pi \\<bullet> x, y)#pi)\"\n    apply(auto simp add: distinctPerm_def fresh_prod at_fresh[OF at])\n    proof -\n      fix a b\n      assume \"b \\<sharp> pi\" and \"(a, b) \\<in> set pi\"\n      thus False\n        by(induct pi)\n          (auto simp add: supp_list_cons supp_prod at_supp[OF at] fresh_list_cons fresh_prod at_fresh[OF at])\n    next\n      fix a b\n      assume \"a \\<sharp> pi\" and \"(a, b) \\<in> set pi\"\n      thus False\n        by(induct pi)\n          (auto simp add: supp_list_cons supp_prod at_supp[OF at] fresh_list_cons fresh_prod at_fresh[OF at])\n    qed\n  ultimately \n  show ?case by blast\nqed\n\nlemma at_set_avoiding:\n  fixes Xs::\"'a set\"\n  assumes at: \"at TYPE('a)\"\n  and     a: \"finite Xs\"\n  and     b: \"finite ((supp c)::'a set)\"\n  obtains pi::\"'a prm\" where \"(pi \\<bullet> Xs) \\<sharp>* c\" and \"set pi \\<subseteq> Xs \\<times> (pi \\<bullet> Xs)\" and \"distinctPerm pi\"\n  using a b\n  by (frule_tac As=\"Xs\" in at_set_avoiding_aux'[OF at]) auto\n\nlemma pt_swap:\n  fixes x :: 'a\n  and a :: 'x\n  and b :: 'x\n\n  assumes pt: \"pt TYPE('a) TYPE('x)\"\n  and     at: \"at TYPE('x)\"\n\n  shows \"[(a, b)] \\<bullet> x = [(b, a)] \\<bullet> x\"\nproof -\n  show ?thesis by(simp add: pt3[OF pt] at_ds5[OF at])\nqed\n\n\natom_decl name\n\nlemma supp_subset:\n  fixes Xs :: \"'a::fs_name set\"\n  and   Ys :: \"'a::fs_name set\"\n\n  assumes \"Xs \\<subseteq> Ys\"\n  and     \"finite Xs\"\n  and     \"finite Ys\"\n\n  shows \"(supp Xs) \\<subseteq> ((supp Ys)::name set)\"\nproof(rule subsetI)\n  fix x\n  assume \"x \\<in> ((supp Xs)::name set)\"\n  with \\<open>finite Xs\\<close> obtain X where \"X \\<in> Xs\" and \"x \\<in> supp X\"\n    by(rule supp_member[OF pt_name_inst, OF at_name_inst, OF fs_name_inst])\n  from \\<open>X \\<in> Xs\\<close> \\<open>Xs \\<subseteq> Ys\\<close> have \"X \\<in> Ys\" by auto\n  with \\<open>finite Ys\\<close> \\<open>x \\<in> supp X\\<close> show \"x \\<in> supp Ys\"\n    by(induct rule: finite_induct)\n      (auto simp add: supp_fin_insert[OF pt_name_inst, OF at_name_inst, OF fs_name_inst])\nqed\n\nabbreviation mem_def :: \"'a \\<Rightarrow> 'a list \\<Rightarrow> bool\" (\"_ mem _\" [80, 80] 80)  where\n  \"x mem xs \\<equiv> x \\<in> set xs\"\n\nlemma memFresh:\n  fixes x :: name\n  and   p :: \"'a::fs_name\"\n  and   l :: \"('a::fs_name) list\"\n\n  assumes \"x \\<sharp> l\"\n  and     \"p mem l\"\n  \n  shows \"x \\<sharp> p\"\nusing assms\nby(induct l, auto simp add: fresh_list_cons)\n\nlemma memFreshChain:\n  fixes xvec :: \"name list\"\n  and   p    :: \"'a::fs_name\"\n  and   l    :: \"'a::fs_name list\"\n  and   Xs   :: \"name set\"\n\n  assumes \"p mem l\"\n  \n  shows \"xvec \\<sharp>* l \\<Longrightarrow> xvec \\<sharp>* p\"\n  and   \"Xs \\<sharp>* l \\<Longrightarrow> Xs \\<sharp>* p\"\nusing assms\nby(auto simp add: fresh_star_def intro: memFresh)\n\nlemma fresh_star_list_append[simp]:\n  fixes A :: \"name list\"\n  and   B :: \"name list\"\n  and   C :: \"name list\"\n\n  shows \"(A \\<sharp>* (B @ C)) = ((A \\<sharp>* B) \\<and> (A \\<sharp>* C))\"\nby(auto simp add: fresh_star_def fresh_list_append)\n\nlemma unionSimps[simp]:\n  fixes Xs :: \"name set\"\n  and   Ys :: \"name set\"\n  and   C  :: \"'a::fs_name\"\n\n  shows \"((Xs \\<union> Ys) \\<sharp>* C) = ((Xs \\<sharp>* C) \\<and> (Ys \\<sharp>* C))\"\nby(auto simp add: fresh_star_def)\n\nlemma substFreshAux[simp]:\n  fixes C    :: \"'a::fs_name\"\n  and   xvec :: \"name list\"\n\n  shows \"xvec \\<sharp>* (supp C - set xvec)\"\nby(auto simp add: fresh_star_def fresh_def at_fin_set_supp[OF at_name_inst] fs_name1)\n\nlemma fresh_star_perm_app[simp]:\n  fixes Xs :: \"name set\"\n  and   xvec :: \"name list\"\n  and   p  :: \"name prm\"\n  and   C  :: \"'d::fs_name\"\n\n  shows \"\\<lbrakk>Xs \\<sharp>* p; Xs \\<sharp>* C\\<rbrakk> \\<Longrightarrow> Xs \\<sharp>* (p \\<bullet> C)\"\n  and   \"\\<lbrakk>xvec \\<sharp>* p; xvec \\<sharp>* C\\<rbrakk> \\<Longrightarrow> xvec \\<sharp>* (p \\<bullet> C)\"\nby(auto simp add: fresh_star_def fresh_perm_app)\n\nlemma freshSets[simp]:\n  fixes x    :: name\n  and   y    :: name\n  and   xvec :: \"name list\"\n  and   X    :: \"name set\"\n  and   C    :: 'a\n\n  shows \"([]::name list) \\<sharp>* C\"\n  and   \"([]::name list) \\<sharp>* [y].C\"\n  and   \"({}::name set) \\<sharp>* C\"\n  and   \"({}::name set) \\<sharp>* [y].C\"\n  and   \"((x#xvec) \\<sharp>* C) = (x \\<sharp> C \\<and> xvec \\<sharp>* C)\"\n  and   \"((x#xvec) \\<sharp>* ([y].C)) = (x \\<sharp> ([y].C) \\<and> xvec \\<sharp>* ([y].C))\"\n  and   \"((insert x X) \\<sharp>* C) = (x \\<sharp> C \\<and> X \\<sharp>* C)\"\n  and   \"((insert x X) \\<sharp>* ([y].C)) = (x \\<sharp> ([y].C) \\<and> X \\<sharp>* ([y].C))\"\nby(auto simp add: fresh_star_def)\n\nlemma freshStarAtom[simp]: \"(xvec::name list) \\<sharp>* (x::name) = x \\<sharp> xvec\"\nby(induct xvec)\n  (auto simp add: fresh_list_nil fresh_list_cons fresh_atm)\n\nlemma name_list_set_fresh[simp]:\n  fixes xvec :: \"name list\"\n  and   x    :: \"'a::fs_name\"\n\n  shows \"(set xvec) \\<sharp>* x = xvec \\<sharp>* x\"\nby(auto simp add: fresh_star_def)\n\nlemma name_list_supp:\n  fixes xvec :: \"name list\"\n\n  shows \"set xvec = supp xvec\"\nproof -\n  have \"set xvec = supp(set xvec)\"\n    by(simp add: at_fin_set_supp[OF at_name_inst])\n  moreover have \"\\<dots> = supp xvec\"\n    by(simp add: pt_list_set_supp[OF pt_name_inst, OF at_name_inst, OF fs_name_inst])\n  ultimately show ?thesis\n    by simp\nqed\n\nlemma abs_fresh_list_star:\n  fixes xvec :: \"name list\"\n  and   a    :: name\n  and   P    :: \"'a::fs_name\"\n\n  shows \"(xvec \\<sharp>* [a].P) = ((set xvec) - {a}) \\<sharp>* P\"\nby(induct xvec) (auto simp add: fresh_star_def abs_fresh)\n\nlemma abs_fresh_set_star:\n  fixes X :: \"name set\"\n  and   a :: name\n  and   P :: \"'a::fs_name\"\n\n  shows \"(X \\<sharp>* [a].P) = (X - {a}) \\<sharp>* P\"\nby(auto simp add: fresh_star_def abs_fresh)\n\nlemmas abs_fresh_star = abs_fresh_list_star abs_fresh_set_star\n\nlemma abs_fresh_list_star'[simp]:\n  fixes xvec :: \"name list\"\n  and   a    :: name\n  and   P    :: \"'a::fs_name\"\n\n  assumes \"a \\<sharp> xvec\"\n\n  shows \"xvec \\<sharp>* [a].P = xvec \\<sharp>* P\"\nusing assms\nby(induct xvec) (auto simp add: abs_fresh fresh_list_cons fresh_atm)\n\nlemma freshChainSym[simp]:\n  fixes xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  \n  shows   \"xvec \\<sharp>* yvec = yvec \\<sharp>* xvec\"\nby(auto simp add: fresh_star_def fresh_def name_list_supp)\n\nlemmas [eqvt] = perm_cart_prod[OF pt_name_inst, OF pt_name_inst, OF at_name_inst]\n\nlemma name_set_avoiding:\n  fixes c :: \"'a::fs_name\"\n  and   X :: \"name set\"\n  \n  assumes \"finite X\"\n  and     \"\\<And>pi::name prm. \\<lbrakk>(pi \\<bullet> X) \\<sharp>* c; distinctPerm pi; set pi \\<subseteq> X \\<times> (pi \\<bullet> X)\\<rbrakk> \\<Longrightarrow> thesis\"\n\n  shows thesis\nusing assms\nby(rule_tac c=c in at_set_avoiding[OF at_name_inst]) (simp_all add: fs_name1)\n\nlemmas simps[simp] = fresh_atm fresh_prod\n                     pt3[OF pt_name_inst, OF at_ds1, OF at_name_inst]\n                     pt_fresh_fresh[OF pt_name_inst, OF at_name_inst]\n                     pt_rev_pi[OF pt_name_inst, OF at_name_inst]\n                     pt_pi_rev[OF pt_name_inst, OF at_name_inst]\n\nlemmas name_supp_cart_prod = supp_cart_prod[OF pt_name_inst, OF pt_name_inst, OF fs_name_inst, OF fs_name_inst, OF at_name_inst]\nlemmas name_fresh_cart_prod = fresh_cart_prod[OF pt_name_inst, OF pt_name_inst, OF fs_name_inst, OF fs_name_inst, OF at_name_inst]\nlemmas name_fresh_star_cart_prod = fresh_star_cart_prod[OF pt_name_inst, OF pt_name_inst, OF fs_name_inst, OF fs_name_inst, OF at_name_inst]\n\n\nlemmas name_swap_bij[simp] = pt_swap_bij[OF pt_name_inst, OF at_name_inst]\nlemmas name_swap = pt_swap[OF pt_name_inst, OF at_name_inst]\nlemmas name_set_fresh_fresh[simp] = pt_freshs_freshs[OF pt_name_inst, OF at_name_inst]\nlemmas list_fresh[simp] = fresh_list_nil fresh_list_cons fresh_list_append\n\ndefinition  eqvt :: \"'a::fs_name set \\<Rightarrow> bool\" where\n                  \"eqvt X \\<equiv> \\<forall>x \\<in> X. \\<forall>p::name prm. p \\<bullet> x \\<in> X\"\n\nlemma eqvtUnion[intro]:\n  fixes Rel  :: \"('d::fs_name) set\"\n  and   Rel' :: \"'d set\"\n\n  assumes EqvtRel:  \"eqvt Rel\"\n  and     EqvtRel': \"eqvt Rel'\"\n\n  shows \"eqvt (Rel \\<union> Rel')\"\nusing assms\nby(force simp add: eqvt_def)\n\nlemma eqvtPerm[simp]: \n  fixes X :: \"('d::fs_name) set\"\n  and   x :: name\n  and   y :: name\n\n  assumes \"eqvt X\"\n\n  shows \"([(x, y)] \\<bullet> X) = X\"\nusing assms\napply(auto simp add: eqvt_def)\napply(erule_tac x=\"[(x, y)] \\<bullet> xa\" in ballE)\napply(erule_tac x=\"[(x, y)]\" in allE)\napply simp\napply(drule_tac pi=\"[(x, y)]\" in pt_set_bij2[OF pt_name_inst, OF at_name_inst])\napply simp\napply(erule_tac x=xa in ballE)\napply(erule_tac x=\"[(x, y)]\" in allE)\napply(drule_tac pi=\"[(x, y)]\" and x=\"[(x, y)] \\<bullet> xa\" in pt_set_bij2[OF pt_name_inst, OF at_name_inst])\napply simp\nby simp\n\nlemma eqvtI:\n  fixes X :: \"'d::fs_name set\"\n  and   x :: 'd\n  and   p :: \"name prm\"\n  \n  assumes \"eqvt X\"\n  and     \"x \\<in> X\"\n \n  shows \"(p \\<bullet> x) \\<in> X\"\nusing assms\nby(unfold eqvt_def) auto\n\nlemma fresh_star_list_nil[simp]:\n  fixes xvec :: \"name list\"\n  and   Xs   :: \"name set\"\n  \n  shows \"xvec \\<sharp>* []\"\n  and   \"Xs \\<sharp>* []\"\nby(auto simp add: fresh_star_def)\n\nlemma fresh_star_list_cons[simp]:\n  fixes xvec :: \"name list\"\n  and   Xs   :: \"name set\"\n  and   x    :: \"'a::fs_name\"\n  and   xs   :: \"'a list\"\n\n  shows \"(xvec \\<sharp>* (x#xs)) = ((xvec \\<sharp>* x) \\<and> xvec \\<sharp>* xs)\"\n  and   \"(Xs \\<sharp>* (x#xs)) = ((Xs \\<sharp>* x) \\<and> (Xs \\<sharp>* xs))\"\nby(auto simp add: fresh_star_def)\n\nlemma freshStarPair[simp]:\n  fixes X    :: \"name set\"\n  and   xvec :: \"name list\"\n  and   x    :: \"'a::fs_name\"\n  and   y    :: \"'b::fs_name\"\n\n  shows \"(X \\<sharp>* (x, y)) = (X \\<sharp>* x \\<and> X \\<sharp>* y)\"\n  and   \"(xvec \\<sharp>* (x, y)) = (xvec \\<sharp>* x \\<and> xvec \\<sharp>* y)\"\nby(auto simp add: fresh_star_def)\nlemma name_list_avoiding:\n  fixes c    :: \"'a::fs_name\"\n  and   xvec :: \"name list\"\n  \n  assumes \"\\<And>pi::name prm. \\<lbrakk>(pi \\<bullet> xvec) \\<sharp>* c; distinctPerm pi; set pi \\<subseteq> (set xvec) \\<times> (set (pi \\<bullet> xvec))\\<rbrakk> \\<Longrightarrow> thesis\"\n\n  shows thesis\nproof -\n  have \"finite(set xvec)\" by simp\n  thus ?thesis using assms\n    by(rule name_set_avoiding) (auto simp add: eqvts fresh_star_def)\nqed\n\nlemma distinctPermSimps[simp]:\n  fixes p :: \"name prm\"\n  and   a :: name\n  and   b :: name\n\n  shows \"distinctPerm([]::name prm)\"\n  and   \"(distinctPerm((a, b)#p)) = (distinctPerm p \\<and> a \\<noteq> b \\<and> a \\<sharp> p \\<and> b \\<sharp> p)\"\napply(simp add: distinctPerm_def)\napply(induct p)\napply(unfold distinctPerm_def)\napply(clarsimp)\napply(rule iffI, erule iffE)\nby(clarsimp)+\n\nlemma map_eqvt[eqvt]:\n  fixes p   :: \"name prm\"\n  and   lst :: \"'a::pt_name list\"\n\n  shows \"(p \\<bullet> (map f lst)) = map (p \\<bullet> f) (p \\<bullet> lst)\"\napply(induct lst, auto) \nby(simp add: pt_fun_app_eq[OF pt_name_inst, OF at_name_inst])\n\nlemma consPerm:\n  fixes x :: name\n  and   y :: name\n  and   p :: \"name prm\"\n  and   C :: \"'a::pt_name\"\n\n  shows \"((x, y)#p) \\<bullet> C = [(x, y)] \\<bullet> p \\<bullet> C\"\nby(simp add: pt2[OF pt_name_inst, THEN sym])\n\nsimproc_setup consPerm (\"((x, y)#p) \\<bullet> C\") = \\<open>\n  fn _ => fn _ => fn ct => \n    case Thm.term_of ct of \n      Const (@{const_name perm}, _ ) $ (Const (@{const_name Cons}, _) $ _ $ p) $ _ =>\n        (case p of\n          Const (@{const_name Nil}, _) => NONE\n        | _ => SOME(mk_meta_eq @{thm consPerm}))\n    | _ => NONE\n\\<close>\n\nlemma distinctEqvt[eqvt]:\n  fixes p  :: \"name prm\"\n  and   xs :: \"'a::pt_name list\"\n\n  shows \"(p \\<bullet> (distinct xs)) = distinct (p \\<bullet> xs)\"\nby(induct xs) (auto simp add: eqvts)\n\nlemma distinctClosed[simp]:\n  fixes p  :: \"name prm\"\n  and   xs :: \"'a::pt_name list\"\n\n  shows \"distinct (p \\<bullet> xs) = distinct xs\"\napply(induct xs)\napply(auto simp add: eqvts)\napply(drule_tac pi=p in pt_set_bij2[OF pt_name_inst, OF at_name_inst])\napply(simp add: eqvts)\napply(drule_tac pi=\"rev p\" in pt_set_bij2[OF pt_name_inst, OF at_name_inst])\nby(simp add: eqvts)\n\nlemma lengthEqvt[eqvt]:\n  fixes p  :: \"name prm\"\n  and   xs :: \"'a::pt_name list\"\n  \n  shows \"p \\<bullet> (length xs) = length (p \\<bullet> xs)\"\nby(induct xs) (auto simp add: eqvts)\n\nlemma lengthClosed[simp]:\n  fixes p  :: \"name prm\"\n  and   xs :: \"'a::pt_name list\"\n  \n  shows \"length (p \\<bullet> xs) = length xs\"\nby(induct xs) (auto simp add: eqvts)\n\nlemma subsetEqvt[eqvt]:\n  fixes p :: \"name prm\"\n  and   S :: \"('a::pt_name) set\"\n  and   T :: \"('a::pt_name) set\"\n\n  shows \"(p \\<bullet> (S \\<subseteq> T)) = ((p \\<bullet> S) \\<subseteq> (p \\<bullet> T))\"\nby(rule pt_subseteq_eqvt[OF pt_name_inst, OF at_name_inst])\n\nlemma subsetClosed[simp]:\n  fixes p :: \"name prm\"\n  and   S :: \"('a::pt_name) set\"\n  and   T :: \"('a::pt_name) set\"\n\n  shows \"((p \\<bullet> S) \\<subseteq> (p \\<bullet> T)) = (S \\<subseteq> T)\"\napply auto\napply(drule_tac pi=p in pt_set_bij2[OF pt_name_inst, OF at_name_inst])\napply(insert pt_set_bij[OF pt_name_inst, OF at_name_inst])\napply auto\napply(drule_tac pi=\"rev p\" in pt_set_bij2[OF pt_name_inst, OF at_name_inst])\napply auto\napply(subgoal_tac \"rev p \\<bullet> x \\<in> T\")\napply auto\napply(drule_tac pi=\"p\" in pt_set_bij2[OF pt_name_inst, OF at_name_inst])\napply auto\napply(drule_tac pi=\"p\" in pt_set_bij2[OF pt_name_inst, OF at_name_inst])\nby auto\n\n\n\n  shows \"(set (p \\<bullet> xvec) \\<subseteq> supp (p \\<bullet> P)) = (set xvec \\<subseteq> supp P)\"\nby(simp add: eqvts[THEN sym])\n\nlemma memEqvt[eqvt]:\n  fixes p  :: \"name prm\"\n  and   x  :: \"'a::pt_name\"\n  and   xs :: \"('a::pt_name) list\"\n\n  shows \"(p \\<bullet> (x mem xs)) = ((p \\<bullet> x) mem (p \\<bullet> xs))\"\nby(induct xs)\n  (auto simp add: pt_bij[OF pt_name_inst, OF at_name_inst] eqvts)\n\nlemma memClosed[simp]:\n  fixes p  :: \"name prm\"\n  and   x  :: \"'a::pt_name\"\n  and   xs :: \"('a::pt_name) list\"\n\n  shows \"(p \\<bullet> x) mem (p \\<bullet> xs) = (x mem xs)\"\nproof -\n  have \"x mem xs = p \\<bullet> (x mem xs)\"\n    by(case_tac \"x mem xs\") auto\n  thus ?thesis by(simp add: eqvts)\nqed\n\nlemma memClosed'[simp]:\n  fixes p  :: \"name prm\"\n  and   x  :: \"'a::pt_name\"\n  and   y  :: \"'b::pt_name\"\n  and   xs :: \"('a \\<times>  'b) list\" \n\n  shows \"((p \\<bullet> x, p \\<bullet> y) mem (p \\<bullet> xs)) = ((x, y) mem xs)\"\napply(subgoal_tac \"((x, y) mem xs) = (p \\<bullet> (x, y)) mem (p \\<bullet> xs)\")\napply force\nby(force simp del: eqvts)\n\n\nlemma freshPerm:\n  fixes x :: name\n  and   p :: \"name prm\"\n\n  assumes \"x \\<sharp> p\"\n\n  shows \"p \\<bullet> x = x\"\nusing assms\napply(rule_tac pt_pi_fresh_fresh[OF pt_name_inst, OF at_name_inst])\nby(induct p, auto simp add: fresh_list_cons fresh_prod)\n\nlemma freshChainPermSimp:\n  fixes xvec :: \"name list\"\n  and   p    :: \"name prm\"\n\n  assumes \"xvec \\<sharp>* p\"\n\n  shows \"p \\<bullet> xvec = xvec\"\n  and   \"rev p \\<bullet> xvec = xvec\"\nusing assms\nby(induct xvec) (auto simp add: freshPerm pt_bij1[OF pt_name_inst, OF at_name_inst, THEN sym])\n\nlemma freshChainAppend[simp]:\n  fixes xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  and   C    :: \"'a::fs_name\"\n  \n  shows \"(xvec@yvec) \\<sharp>* C = ((xvec \\<sharp>* C) \\<and> (yvec \\<sharp>* C))\"\nby(force simp add: fresh_star_def)\n\nlemma subsetFresh:\n  fixes xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  and   C    :: \"'d::fs_name\"\n\n  assumes \"set xvec \\<subseteq> set yvec\"\n  and     \"yvec \\<sharp>* C\"\n\n  shows \"xvec \\<sharp>* C\"\nusing assms\nby(auto simp add: fresh_star_def)\n\nlemma distinctPermCancel[simp]:\n  fixes p :: \"name prm\"\n  and   T :: \"'a::pt_name\"\n\n  assumes \"distinctPerm p\"\n\n  shows \"(p \\<bullet> (p \\<bullet> T)) = T\"\nusing assms\nproof(induct p)\n  case Nil\n  show ?case by simp\nnext\n  case(Cons a p)\n  thus ?case\n  proof(case_tac a, auto)\n    fix a b\n    assume \"(a::name) \\<sharp> (p::name prm)\" \"b \\<sharp> p\" \"p \\<bullet> p \\<bullet> T = T\" \"a \\<noteq> b\"\n    thus \"[(a, b)] \\<bullet> p \\<bullet> [(a, b)] \\<bullet> p \\<bullet> T = T\"\n      by(subst pt_perm_compose[OF pt_name_inst, OF at_name_inst]) simp\n  qed\nqed\n\nfun composePerm :: \"name list \\<Rightarrow> name list \\<Rightarrow> name prm\"\nwhere\n  Base:  \"composePerm [] [] = []\"\n| Step:  \"composePerm (x#xs) (y#ys) = (x, y)#(composePerm xs ys)\"\n| Empty: \"composePerm _ _= []\"\n\nlemma composePermInduct[consumes 1, case_names cBase cStep]:\n  fixes xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  and   P    :: \"name list \\<Rightarrow> name list \\<Rightarrow> bool\"\n\n  assumes L: \"length xvec = length yvec\"\n  and     rBase: \"P [] []\"\n  and     rStep: \"\\<And>x xvec y yvec. \\<lbrakk>length xvec = length yvec; P xvec yvec\\<rbrakk> \\<Longrightarrow> P (x # xvec) (y # yvec)\"\n\n  shows \"P xvec yvec\"\nusing assms\nby(induct rule: composePerm.induct) auto\n\nlemma composePermEqvt[eqvt]:\n  fixes p    :: \"name prm\"\n  and   xvec :: \"name list\"\n  and   yvec :: \"name list\"\n\n  shows \"(p \\<bullet> (composePerm xvec yvec)) = composePerm (p \\<bullet> xvec) (p \\<bullet> yvec)\"\nby(induct xvec yvec rule: composePerm.induct) auto\n\nabbreviation\n  composePermJudge (\"[_ _] \\<bullet>\\<^sub>v _\" [80, 80, 80] 80) where \"[xvec yvec] \\<bullet>\\<^sub>v p \\<equiv> (composePerm xvec yvec) \\<bullet> p\"\n\nabbreviation\n  composePermInvJudge (\"[_ _]\\<^sup>- \\<bullet>\\<^sub>v _\" [80, 80, 80] 80) where \"[xvec yvec]\\<^sup>- \\<bullet>\\<^sub>v p \\<equiv> (rev (composePerm xvec yvec)) \\<bullet> p\"\n\nlemma permChainSimps[simp]:\n  fixes xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  and   perm :: \"name prm\"\n  and   p    :: \"'a::pt_name\"\n\n  shows \"((composePerm xvec yvec) @ perm) \\<bullet> p = [xvec yvec] \\<bullet>\\<^sub>v (perm \\<bullet> p)\"\nby(simp add: pt2[OF pt_name_inst])\n\nlemma permChainEqvt[eqvt]:\n  fixes p    :: \"name prm\"\n  and   xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  and   x    :: \"'a::pt_name\"\n\n  shows \"(p \\<bullet> ([xvec yvec] \\<bullet>\\<^sub>v x)) = [(p \\<bullet> xvec) (p \\<bullet> yvec)] \\<bullet>\\<^sub>v (p \\<bullet> x)\"\n  and   \"(p \\<bullet> ([xvec yvec]\\<^sup>- \\<bullet>\\<^sub>v x)) = [(p \\<bullet> xvec) (p \\<bullet> yvec)]\\<^sup>- \\<bullet>\\<^sub>v (p \\<bullet> x)\"\nby(subst pt_perm_compose[OF pt_name_inst, OF at_name_inst], simp add: eqvts rev_eqvt)+\n\nlemma permChainBij:\n  fixes xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  and   p    :: \"'a::pt_name\"\n  and   q    :: \"'a::pt_name\"\n\n  assumes \"length xvec = length yvec\"\n\n  shows \"(([xvec yvec] \\<bullet>\\<^sub>v p) = ([xvec yvec] \\<bullet>\\<^sub>v q)) = (p = q)\"\n  and   \"(([xvec yvec]\\<^sup>- \\<bullet>\\<^sub>v p) = ([xvec yvec]\\<^sup>- \\<bullet>\\<^sub>v q)) = (p = q)\"\nusing assms\nby(induct rule: composePermInduct)\n  (auto simp add: pt_bij[OF pt_name_inst, OF at_name_inst])\n\nlemma permChainAppend:\n  fixes xvec1 :: \"name list\"\n  and   yvec1 :: \"name list\"\n  and   xvec2 :: \"name list\"\n  and   yvec2 :: \"name list\"\n  and   p     :: \"'a::pt_name\"\n  \n  assumes \"length xvec1 = length yvec1\"\n\n  shows \"([(xvec1@xvec2) (yvec1@yvec2)] \\<bullet>\\<^sub>v p) = [xvec1 yvec1] \\<bullet>\\<^sub>v [xvec2 yvec2] \\<bullet>\\<^sub>v p\"\n  and   \"([(xvec1@xvec2) (yvec1@yvec2)]\\<^sup>- \\<bullet>\\<^sub>v p) = [xvec2 yvec2]\\<^sup>- \\<bullet>\\<^sub>v [xvec1 yvec1]\\<^sup>- \\<bullet>\\<^sub>v p\"\nusing assms\nby(induct arbitrary: p rule: composePermInduct, auto) (simp add: pt2[OF pt_name_inst])\n\nlemma calcChainAtom:\n  fixes xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  and   x    :: name\n\n  assumes \"length xvec = length yvec\"\n  and     \"x \\<sharp> xvec\"\n  and     \"x \\<sharp> yvec\"\n\n  shows \"[xvec yvec] \\<bullet>\\<^sub>v x = x\"\nusing assms\nby(induct rule: composePermInduct, auto)\n\nlemma calcChainAtomRev:\n  fixes xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  and   x    :: name\n\n  assumes \"length xvec = length yvec\"\n  and     \"x \\<sharp> xvec\"\n  and     \"x \\<sharp> yvec\"\n\n  shows \"[xvec yvec]\\<^sup>- \\<bullet>\\<^sub>v x = x\"\nusing assms\nby(induct rule: composePermInduct, auto)\n  (auto simp add: pt2[OF pt_name_inst] fresh_list_cons calc_atm)\n\nlemma permChainFresh[simp]:\n  fixes x    :: name\n  and   xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  and   p    :: \"'a::pt_name\"\n\n  assumes \"x \\<sharp> xvec\"\n  and     \"x \\<sharp> yvec\"\n  and     \"length xvec = length yvec\"\n\n  shows \"x \\<sharp> [xvec yvec] \\<bullet>\\<^sub>v p = x \\<sharp> p\"\n  and   \"x \\<sharp> [xvec yvec]\\<^sup>- \\<bullet>\\<^sub>v p = x \\<sharp> p\"\nusing assms\nby(auto simp add: fresh_left calcChainAtomRev calcChainAtom)\n\nlemma chainFreshFresh:\n  fixes x    :: name\n  and   y    :: name\n  and   xvec :: \"name list\"\n  and   p    :: \"'a::pt_name\"\n\n  assumes \"x \\<sharp> xvec\"\n  and     \"y \\<sharp> xvec\"\n\n  shows \"xvec \\<sharp>* ([(x, y)] \\<bullet> p) = (xvec \\<sharp>* p)\"\nusing assms\nby(induct xvec) (auto simp add: fresh_list_cons fresh_left)\n\nlemma permChainFreshFresh:\n  fixes xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  and   p    :: \"'a::pt_name\"\n\n  assumes \"xvec \\<sharp>* p\"\n  and     \"yvec \\<sharp>* p\"\n  and     \"length xvec = length yvec\"\n\n  shows \"[xvec yvec] \\<bullet>\\<^sub>v p = p\"\n  and   \"[xvec yvec]\\<^sup>- \\<bullet>\\<^sub>v p = p\"\nusing assms\nby(induct rule: composePerm.induct, auto) (simp add: pt2[OF pt_name_inst])\n\nlemma setFresh[simp]:\n  fixes x    :: name\n  and   xvec :: \"name list\"\n\n  shows \"x \\<notin> set xvec = x \\<sharp> xvec\"\nby(simp add: name_list_supp fresh_def)\n  \nlemma calcChain:\n  fixes xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  \n  assumes \"yvec \\<sharp>* xvec\"\n  and     \"length xvec = length yvec\"\n  and     \"distinct xvec\"\n  and     \"distinct yvec\"\n\n  shows \"[xvec yvec] \\<bullet>\\<^sub>v xvec = yvec\"\nusing assms\nby(induct xvec yvec rule: composePerm.induct, auto)\n  (subst consPerm, simp add: calcChainAtom calc_atm name_list_supp fresh_def[symmetric])+\n\nlemma freshChainPerm:\n  fixes xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  and   x    :: name\n  and   C    :: \"'a::pt_name\"\n\n  assumes \"length xvec = length yvec\"\n  and     \"yvec \\<sharp>* C\"\n  and     \"xvec \\<sharp>* yvec\"\n  and     \"x mem xvec\"\n  and     \"distinct yvec\"\n\n  shows \"x \\<sharp> [xvec yvec] \\<bullet>\\<^sub>v C\"\nusing assms\nproof(induct rule: composePermInduct)\n  case cBase\n  have \"x mem []\" by fact\n  hence False by simp\n  thus ?case by simp\nnext\n  case(cStep x' xvec y yvec)\n  have \"(y # yvec) \\<sharp>* C\" by fact\n  hence yFreshC: \"y \\<sharp> C\" and yvecFreshp: \"yvec \\<sharp>* C\" by simp+\n  have \"(x' # xvec) \\<sharp>* (y # yvec)\" by fact\n  hence x'ineqy: \"x' \\<noteq> y\" and xvecFreshyvec: \"xvec \\<sharp>* yvec\"\n    and x'Freshyvec: \"x' \\<sharp> yvec\" and yFreshxvec: \"y \\<sharp> xvec\"\n    by(auto simp add: fresh_list_cons)\n  have \"distinct (y#yvec)\" by fact\n  hence yFreshyvec: \"y \\<sharp> yvec\" and yvecDist: \"distinct yvec\"\n    by simp+\n  have L: \"length xvec = length yvec\" by fact\n  have \"x \\<sharp> [(x', y)] \\<bullet> [xvec yvec] \\<bullet>\\<^sub>v C\"\n  proof(case_tac \"x = x'\")\n    assume xeqx': \"x = x'\"\n    moreover from yFreshxvec yFreshyvec yFreshC L have \"y \\<sharp> [xvec yvec] \\<bullet>\\<^sub>v C\"\n      by simp\n    hence \"([(x, y)] \\<bullet> y) \\<sharp> [(x, y)] \\<bullet> [xvec yvec] \\<bullet>\\<^sub>v C\"\n      by(rule pt_fresh_bij1[OF pt_name_inst, OF at_name_inst])\n    with x'ineqy xeqx' show ?thesis by(simp add: calc_atm)\n  next\n    assume xineqx': \"x \\<noteq> x'\"\n    have \"x mem (x' # xvec)\" by fact\n    with xineqx' have xmemxvec: \"x mem xvec\" by simp\n    moreover have \"\\<lbrakk>yvec \\<sharp>* C; xvec \\<sharp>* yvec; x mem xvec; distinct yvec\\<rbrakk> \\<Longrightarrow> x \\<sharp> [xvec yvec] \\<bullet>\\<^sub>v C\" by fact\n    ultimately have \"x \\<sharp> [xvec yvec] \\<bullet>\\<^sub>v C\" using yvecFreshp xvecFreshyvec yvecDist\n      by simp\n    hence \"([(x', y)] \\<bullet> x) \\<sharp> [(x', y)] \\<bullet> [xvec yvec] \\<bullet>\\<^sub>v C\"\n      by(rule pt_fresh_bij1[OF pt_name_inst, OF at_name_inst])\n    moreover from xmemxvec yFreshxvec have \"x \\<noteq> y\"\n      by(induct xvec) (auto simp add: fresh_list_cons)\n    ultimately show ?thesis using xineqx' x'ineqy by(simp add: calc_atm)\n  qed\n  thus ?case by simp\nqed\n\nlemma memFreshSimp[simp]:\n  fixes y    :: name\n  and   yvec :: \"name list\"\n\n  shows \"(\\<not>(y mem yvec)) = y \\<sharp> yvec\"\nby(induct yvec)\n  (auto simp add: fresh_list_nil fresh_list_cons)\n\nlemma freshChainPerm':\n  fixes xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  and   p    :: \"'a::pt_name\"\n\n  assumes \"length xvec = length yvec\"\n  and     \"yvec \\<sharp>* p\"\n  and     \"xvec \\<sharp>* yvec\"\n  and     \"distinct yvec\"\n\n  shows \"xvec \\<sharp>* ([xvec yvec] \\<bullet>\\<^sub>v p)\"\nusing assms\nproof(induct rule: composePermInduct)\n  case cBase\n  show ?case by simp\nnext\n  case(cStep x xvec y yvec)\n  have \"(y # yvec) \\<sharp>* p\" by fact\n  hence yFreshp: \"y \\<sharp> p\" and yvecFreshp: \"yvec \\<sharp>* p\"\n    by simp+\n  moreover have \"(x # xvec) \\<sharp>* (y # yvec)\" by fact\n  hence xineqy: \"x \\<noteq> y\" and xvecFreshyvec: \"xvec \\<sharp>* yvec\"\n    and xFreshyvec: \"x \\<sharp> yvec\" and yFreshxvec: \"y \\<sharp> xvec\"\n    by(auto simp add: fresh_list_cons)\n  have \"distinct (y # yvec)\" by fact\n  hence yFreshyvec: \"y \\<sharp> yvec\" and yvecDist: \"distinct yvec\"\n    by simp+\n  have L: \"length xvec = length yvec\" by fact\n  have \"\\<lbrakk>yvec \\<sharp>* p; xvec \\<sharp>* yvec; distinct yvec\\<rbrakk> \\<Longrightarrow> xvec \\<sharp>* ([xvec yvec] \\<bullet>\\<^sub>v p)\" by fact\n  with yvecFreshp xvecFreshyvec yvecDist have IH: \"xvec \\<sharp>* ([xvec yvec] \\<bullet>\\<^sub>v p)\" by simp\n  show ?case\n  proof(auto)\n    from L yFreshp yvecFreshp xineqy xvecFreshyvec yvecDist yFreshyvec yFreshxvec xFreshyvec\n    have \"x \\<sharp> [(x # xvec) (y # yvec)] \\<bullet>\\<^sub>v p\"\n      by(rule_tac freshChainPerm) (auto simp add: fresh_list_cons)\n    thus \"x \\<sharp> [(x, y)] \\<bullet> [xvec yvec] \\<bullet>\\<^sub>v p\" by simp\n  next\n    show \"xvec \\<sharp>* ([(x, y)] \\<bullet> [xvec yvec] \\<bullet>\\<^sub>v p)\"\n    proof(case_tac \"x mem xvec\")\n      assume \"x mem xvec\"\n      with L yvecFreshp xvecFreshyvec yvecDist xFreshyvec\n      have\"x \\<sharp> [xvec yvec] \\<bullet>\\<^sub>v p\"\n        by(rule_tac freshChainPerm) (auto simp add: fresh_list_cons)\n      moreover from yFreshxvec yFreshyvec yFreshp L\n      have \"y \\<sharp> [xvec yvec] \\<bullet>\\<^sub>v p\" by simp\n      ultimately show ?thesis using IH\n        by(subst consPerm) (simp add: perm_fresh_fresh)\n    next\n      assume \"\\<not>(x mem xvec)\"\n      hence xFreshxvec: \"x \\<sharp> xvec\" by simp\n      from IH have \"([(x, y)] \\<bullet> xvec) \\<sharp>* ([(x, y)] \\<bullet> [xvec yvec] \\<bullet>\\<^sub>v p)\"\n        by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n      with xFreshxvec yFreshxvec show ?thesis by simp\n    qed\n  qed\nqed\n\nlemma permSym:\n  fixes x    :: name\n  and   y    :: name\n  and   xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  and   p    :: \"'a::pt_name\"\n  \n  assumes \"x \\<sharp> xvec\"\n  and     \"x \\<sharp> yvec\"\n  and     \"y \\<sharp> xvec\"\n  and     \"y \\<sharp> yvec\"\n  and     \"length xvec = length yvec\"\n\n  shows \"([(x, y)] \\<bullet> [xvec yvec] \\<bullet>\\<^sub>v p) = [xvec yvec] \\<bullet>\\<^sub>v [(x, y)] \\<bullet> p\"\nusing assms\napply(induct rule: composePerm.induct, auto)\nby(subst pt_perm_compose[OF pt_name_inst, OF at_name_inst]) simp\n\nlemma distinctPermClosed[simp]:\n  fixes p :: \"name prm\"\n  and   q :: \"name prm\"\n\n  assumes \"distinctPerm p\"\n\n  shows \"distinctPerm(q \\<bullet> p)\"\nusing assms\nby(induct p) (auto simp add: pt_fresh_bij[OF pt_name_inst, OF at_name_inst] dest: pt_bij4[OF pt_name_inst, OF at_name_inst])\n\nlemma freshStarSimps:\n  fixes x  :: name\n  and   Xs :: \"name set\"\n  and   Ys :: \"name set\"\n  and   C  :: \"'a::fs_name\"\n  and   p  :: \"name prm\"\n  \n  assumes \"set p \\<subseteq> Xs \\<times> Ys\"\n  and     \"Xs \\<sharp>* x\"\n  and     \"Ys \\<sharp>* x\"\n\n  shows \"x \\<sharp> (p \\<bullet> C) = x \\<sharp> C\"\nusing assms\nby(subst  pt_fresh_bij[OF pt_name_inst, OF at_name_inst, symmetric, of _ C p]) simp\n\nlemma freshStarChainSimps:\n  fixes xvec :: \"name list\"\n  and   Xs   :: \"name set\"\n  and   Ys   :: \"name set\"\n  and   C    :: \"'a::fs_name\"\n  and   p    :: \"name prm\"\n\n  assumes \"set p \\<subseteq> Xs \\<times> Ys\"\n  and     \"Xs \\<sharp>* xvec\"\n  and     \"Ys \\<sharp>* xvec\"\n\n  shows   \"xvec \\<sharp>* (p \\<bullet> C) = xvec \\<sharp>* C\"\nusing assms\nby(induct xvec) (auto simp add: freshStarSimps)\n\nlemma permStarFresh:\n  fixes xvec :: \"name list\"\n  and   p    :: \"name prm\"\n  and   T    :: \"'a::pt_name\"\n\n  assumes \"xvec \\<sharp>* p\"\n\n  shows \"xvec \\<sharp>* (p \\<bullet> T) = xvec \\<sharp>* T\"\nusing assms\nby(induct p) (auto simp add: chainFreshFresh)\n\nlemma swapStarFresh:\n  fixes x :: name\n  and   p :: \"name prm\"\n  and   T :: \"'a::pt_name\"\n\n  assumes \"x \\<sharp> p\"\n\n  shows \"x \\<sharp> (p \\<bullet> T) = x \\<sharp> T\"\nproof -\n  from assms have \"[x] \\<sharp>* (p \\<bullet> T) = [x] \\<sharp>* T\"\n    by(rule_tac permStarFresh) auto\n  thus ?thesis by simp\nqed\n\nlemmas freshChainSimps = freshStarSimps freshStarChainSimps permStarFresh swapStarFresh chainFreshFresh freshPerm subsetFresh\n\nlemma freshAlphaPerm:\n  fixes xvec :: \"name list\"\n  and   Xs   :: \"name set\"\n  and   Ys   :: \"name set\"\n  and   p    :: \"name prm\"\n\n  assumes S: \"set p \\<subseteq> Xs \\<times> Ys\"\n  and     \"Xs \\<sharp>* xvec\"\n  and     \"Ys \\<sharp>* xvec\"\n\n  shows \"xvec \\<sharp>* p\"\nusing assms\napply(induct p)\nby auto (simp add: fresh_star_def fresh_def name_list_supp supp_list_nil)+\n\nlemma freshAlphaSwap:\n  fixes x  :: name\n  and   Xs :: \"name set\"\n  and   Ys :: \"name set\"\n  and   p  :: \"name prm\"\n\n  assumes S: \"set p \\<subseteq> Xs \\<times> Ys\"\n  and     \"Xs \\<sharp>* x\"\n  and     \"Ys \\<sharp>* x\"\n\n  shows \"x \\<sharp> p\"\nproof -\n  from assms have \"[x] \\<sharp>* p\" \n    apply(rule_tac freshAlphaPerm)\n    apply assumption\n    by auto\n  thus ?thesis by simp\nqed\n\nlemma setToListFresh[simp]:\n  fixes xvec :: \"name list\"\n  and   C    :: \"'a::fs_name\"\n  and   yvec :: \"name list\"\n  and   Xs   :: \"name set\"\n  and   x    :: name\n\n  shows \"xvec \\<sharp>* (set yvec) = xvec \\<sharp>* yvec\"\n  and   \"Xs \\<sharp>* (set yvec) = Xs \\<sharp>* yvec\"\n  and   \"x \\<sharp> (set yvec) = x \\<sharp> yvec\"\n  and   \"set xvec \\<sharp>* Xs = xvec \\<sharp>* Xs\"\nby(auto simp add: fresh_star_def name_list_supp fresh_def fs_name1 at_fin_set_supp[OF at_name_inst])\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Psi_Calculi/Chain.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5544704796847396, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.2988502849167261}}
{"text": "theory HEAP01Reify\nimports HEAP1 \nbegin \n\n(*========================================================================*)\nsection {* Refinement L0-L1 definitions *}\n(*========================================================================*)\n\n(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)\nsubsubsection {* State reification definitions *}\n(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)\n\ndefinition\n  retr0 :: \"F1 \\<Rightarrow> F0\"\nwhere\n  \"retr0 f1 = locs f1\"\n\ndefinition \n  contiguous :: \"nat set \\<Rightarrow> bool\"\nwhere\n  \"contiguous F \\<equiv> \\<exists> m l . nat1 l \\<and> F = locs_of m l\"\n\ndefinition\n  non_abutting :: \"nat set \\<Rightarrow> nat set \\<Rightarrow> bool\"\nwhere\n  \"non_abutting F F' \\<equiv> (\\<forall> x \\<in> F . \\<forall> y \\<in> F' . x > y+1 \\<or> y > x + 1)\"\n\nlocale level01_new = level1_new + level0_new\nlocale level01_dispose = level1_dispose + level0_dispose\n\n(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)\nsubsubsection {* VDM auxiliary functions *}\n(* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *)\n\n(*========================================================================*)\nsection {* VDM proof obligations for L0-L1 refinement *}\n(*========================================================================*)\n\ntext {* Because of the (yet to be resolved) locale dependency/usage, we will\n        avoid adding locale-based POs\n      *}\n\n(* TODO: PUT in locale? *)\ndefinition\n  PO_l01_adequacy :: \"bool\"\nwhere\n  \"PO_l01_adequacy \\<equiv> (\\<forall> f0 . F0_inv f0 \\<longrightarrow> (\\<exists>! f1. f0 = retr0 f1 \\<and> F1_inv f1))\"\n\n(*\nlemma \"PO_l01_adequacy\" \nunfolding PO_l01_adequacy_def\napply auto\nunfolding retr0_def\ndefer\nfind_theorems \"locs _ = locs _\"\noops\n*)\n\n(* TODO: PUT in locale? Do it separate first to avoid confusion of assumptions across 4 locales! *)\ndefinition \n  PO_l01_new_widen_pre :: \"bool\"\nwhere\n  \"PO_l01_new_widen_pre \\<equiv> (\\<forall> f1 s1 . F1_inv f1 \\<and> nat1 s1 \\<and> new0_pre (retr0 f1) s1 \\<longrightarrow> new1_pre f1 s1)\"\n\ndefinition \n  PO_l01_new_narrow_post :: \"bool\"\nwhere\n  \"PO_l01_new_narrow_post \\<equiv> (\\<forall> f1 f1' s1 r . F1_inv f1 \\<and> F1_inv f1' \\<and> nat1 s1 \\<and> \n                                 new0_pre (retr0 f1) s1 \\<and> new1_post f1 s1 f1' r \\<longrightarrow> new0_post (retr0 f1) s1 (retr0 f1') r)\"\n\ndefinition \n  PO_l01_dispose_widen_pre :: \"bool\"\nwhere\n  \"PO_l01_dispose_widen_pre \\<equiv> (\\<forall> f1 d1 s1 . F1_inv f1 \\<and> nat1 s1 \\<and> \n                                    dispose0_pre (retr0 f1) d1 s1 \\<longrightarrow> dispose1_pre f1 d1 s1)\"\n\ndefinition \n  PO_l01_dispose_narrow_post :: \"bool\"\nwhere\n  \"PO_l01_dispose_narrow_post \\<equiv> (\\<forall> f1 f1' d1 s1 . F1_inv f1 \\<and> F1_inv f1' \\<and> nat1 s1 \\<and> \n                                    dispose0_pre (retr0 f1) d1 s1 \\<and> dispose1_post f1 d1 s1 f1' \\<longrightarrow> \n                                        dispose0_post (retr0 f1) d1 s1 (retr0 f1'))\"\n\nunused_thms\n\n(*\nlemma (in level1_dispose) \"False\"\nnitpick [show_all]\noops\nlemma (in level1_new) \"False\"\nnitpick [show_all]\noops\n*)\n(* NOTE: Nitpick trick to see if any axiom involved in the locales is inconsistent.\n         i.e. if axioms are inconsistent, then we shouldn't be able to find a mode\n         for False. If we do, then the axioms are conistent (i.e. it's unprovable \n         as it should be).\n *)\nend\n", "meta": {"author": "leouk", "repo": "VDM_Toolkit", "sha": "791013909961d45949fcd96d937ae18f0174c7ec", "save_path": "github-repos/isabelle/leouk-VDM_Toolkit", "path": "github-repos/isabelle/leouk-VDM_Toolkit/VDM_Toolkit-791013909961d45949fcd96d937ae18f0174c7ec/experiments/vdm/Heap/isa/HEAP01Reify.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.2988502769805688}}
{"text": "(*  Title:      HOL/Library/DAList_Multiset.thy\n    Author:     Lukas Bulwahn, TU Muenchen\n*)\n\nsection \\<open>Multisets partially implemented by association lists\\<close>\n\ntheory DAList_Multiset\nimports Multiset DAList\nbegin\n\ntext \\<open>Delete prexisting code equations\\<close>\n\nlemma [code, code del]: \"{#} = {#}\" ..\n\nlemma [code, code del]: \"single = single\" ..\n\nlemma [code, code del]: \"plus = (plus :: 'a multiset \\<Rightarrow> _)\" ..\n\nlemma [code, code del]: \"minus = (minus :: 'a multiset \\<Rightarrow> _)\" ..\n\nlemma [code, code del]: \"inf = (inf :: 'a multiset \\<Rightarrow> _)\" ..\n\nlemma [code, code del]: \"sup = (sup :: 'a multiset \\<Rightarrow> _)\" ..\n\nlemma [code, code del]: \"image_mset = image_mset\" ..\n\nlemma [code, code del]: \"Multiset.filter = Multiset.filter\" ..\n\nlemma [code, code del]: \"count = count\" ..\n\nlemma [code, code del]: \"mcard = mcard\" ..\n\nlemma [code, code del]: \"msetsum = msetsum\" ..\n\nlemma [code, code del]: \"msetprod = msetprod\" ..\n\nlemma [code, code del]: \"set_of = set_of\" ..\n\nlemma [code, code del]: \"sorted_list_of_multiset = sorted_list_of_multiset\" ..\n\nlemma [code, code del]: \"ord_multiset_inst.less_eq_multiset = ord_multiset_inst.less_eq_multiset\" ..\n\nlemma [code, code del]: \"ord_multiset_inst.less_multiset = ord_multiset_inst.less_multiset\" ..\n\nlemma [code, code del]: \"equal_multiset_inst.equal_multiset = equal_multiset_inst.equal_multiset\" ..\n\n\ntext \\<open>Raw operations on lists\\<close>\n\ndefinition join_raw ::\n    \"('key \\<Rightarrow> 'val \\<times> 'val \\<Rightarrow> 'val) \\<Rightarrow>\n      ('key \\<times> 'val) list \\<Rightarrow> ('key \\<times> 'val) list \\<Rightarrow> ('key \\<times> 'val) list\"\n  where \"join_raw f xs ys = foldr (\\<lambda>(k, v). map_default k v (\\<lambda>v'. f k (v', v))) ys xs\"\n\nlemma join_raw_Nil [simp]: \"join_raw f xs [] = xs\"\n  by (simp add: join_raw_def)\n\nlemma join_raw_Cons [simp]:\n  \"join_raw f xs ((k, v) # ys) = map_default k v (\\<lambda>v'. f k (v', v)) (join_raw f xs ys)\"\n  by (simp add: join_raw_def)\n\nlemma map_of_join_raw:\n  assumes \"distinct (map fst ys)\"\n  shows \"map_of (join_raw f xs ys) x =\n    (case map_of xs x of\n      None \\<Rightarrow> map_of ys x\n    | Some v \\<Rightarrow> (case map_of ys x of None \\<Rightarrow> Some v | Some v' \\<Rightarrow> Some (f x (v, v'))))\"\n  using assms\n  apply (induct ys)\n  apply (auto simp add: map_of_map_default split: option.split)\n  apply (metis map_of_eq_None_iff option.simps(2) weak_map_of_SomeI)\n  apply (metis Some_eq_map_of_iff map_of_eq_None_iff option.simps(2))\n  done\n\nlemma distinct_join_raw:\n  assumes \"distinct (map fst xs)\"\n  shows \"distinct (map fst (join_raw f xs ys))\"\n  using assms\nproof (induct ys)\n  case Nil\n  then show ?case by simp\nnext\n  case (Cons y ys)\n  then show ?case by (cases y) (simp add: distinct_map_default)\nqed\n\ndefinition \"subtract_entries_raw xs ys = foldr (\\<lambda>(k, v). AList.map_entry k (\\<lambda>v'. v' - v)) ys xs\"\n\nlemma map_of_subtract_entries_raw:\n  assumes \"distinct (map fst ys)\"\n  shows \"map_of (subtract_entries_raw xs ys) x =\n    (case map_of xs x of\n      None \\<Rightarrow> None\n    | Some v \\<Rightarrow> (case map_of ys x of None \\<Rightarrow> Some v | Some v' \\<Rightarrow> Some (v - v')))\"\n  using assms\n  unfolding subtract_entries_raw_def\n  apply (induct ys)\n  apply auto\n  apply (simp split: option.split)\n  apply (simp add: map_of_map_entry)\n  apply (auto split: option.split)\n  apply (metis map_of_eq_None_iff option.simps(3) option.simps(4))\n  apply (metis map_of_eq_None_iff option.simps(4) option.simps(5))\n  done\n\nlemma distinct_subtract_entries_raw:\n  assumes \"distinct (map fst xs)\"\n  shows \"distinct (map fst (subtract_entries_raw xs ys))\"\n  using assms\n  unfolding subtract_entries_raw_def\n  by (induct ys) (auto simp add: distinct_map_entry)\n\n\ntext \\<open>Operations on alists with distinct keys\\<close>\n\nlift_definition join :: \"('a \\<Rightarrow> 'b \\<times> 'b \\<Rightarrow> 'b) \\<Rightarrow> ('a, 'b) alist \\<Rightarrow> ('a, 'b) alist \\<Rightarrow> ('a, 'b) alist\"\n  is join_raw\n  by (simp add: distinct_join_raw)\n\nlift_definition subtract_entries :: \"('a, ('b :: minus)) alist \\<Rightarrow> ('a, 'b) alist \\<Rightarrow> ('a, 'b) alist\"\n  is subtract_entries_raw\n  by (simp add: distinct_subtract_entries_raw)\n\n\ntext \\<open>Implementing multisets by means of association lists\\<close>\n\ndefinition count_of :: \"('a \\<times> nat) list \\<Rightarrow> 'a \\<Rightarrow> nat\"\n  where \"count_of xs x = (case map_of xs x of None \\<Rightarrow> 0 | Some n \\<Rightarrow> n)\"\n\nlemma count_of_multiset: \"count_of xs \\<in> multiset\"\nproof -\n  let ?A = \"{x::'a. 0 < (case map_of xs x of None \\<Rightarrow> 0::nat | Some n \\<Rightarrow> n)}\"\n  have \"?A \\<subseteq> dom (map_of xs)\"\n  proof\n    fix x\n    assume \"x \\<in> ?A\"\n    then have \"0 < (case map_of xs x of None \\<Rightarrow> 0::nat | Some n \\<Rightarrow> n)\"\n      by simp\n    then have \"map_of xs x \\<noteq> None\"\n      by (cases \"map_of xs x\") auto\n    then show \"x \\<in> dom (map_of xs)\"\n      by auto\n  qed\n  with finite_dom_map_of [of xs] have \"finite ?A\"\n    by (auto intro: finite_subset)\n  then show ?thesis\n    by (simp add: count_of_def fun_eq_iff multiset_def)\nqed\n\nlemma count_simps [simp]:\n  \"count_of [] = (\\<lambda>_. 0)\"\n  \"count_of ((x, n) # xs) = (\\<lambda>y. if x = y then n else count_of xs y)\"\n  by (simp_all add: count_of_def fun_eq_iff)\n\nlemma count_of_empty: \"x \\<notin> fst ` set xs \\<Longrightarrow> count_of xs x = 0\"\n  by (induct xs) (simp_all add: count_of_def)\n\nlemma count_of_filter: \"count_of (List.filter (P \\<circ> fst) xs) x = (if P x then count_of xs x else 0)\"\n  by (induct xs) auto\n\nlemma count_of_map_default [simp]:\n  \"count_of (map_default x b (\\<lambda>x. x + b) xs) y =\n    (if x = y then count_of xs x + b else count_of xs y)\"\n  unfolding count_of_def by (simp add: map_of_map_default split: option.split)\n\nlemma count_of_join_raw:\n  \"distinct (map fst ys) \\<Longrightarrow>\n    count_of xs x + count_of ys x = count_of (join_raw (\\<lambda>x (x, y). x + y) xs ys) x\"\n  unfolding count_of_def by (simp add: map_of_join_raw split: option.split)\n\nlemma count_of_subtract_entries_raw:\n  \"distinct (map fst ys) \\<Longrightarrow>\n    count_of xs x - count_of ys x = count_of (subtract_entries_raw xs ys) x\"\n  unfolding count_of_def by (simp add: map_of_subtract_entries_raw split: option.split)\n\n\ntext \\<open>Code equations for multiset operations\\<close>\n\ndefinition Bag :: \"('a, nat) alist \\<Rightarrow> 'a multiset\"\n  where \"Bag xs = Abs_multiset (count_of (DAList.impl_of xs))\"\n\ncode_datatype Bag\n\nlemma count_Bag [simp, code]: \"count (Bag xs) = count_of (DAList.impl_of xs)\"\n  by (simp add: Bag_def count_of_multiset)\n\nlemma Mempty_Bag [code]: \"{#} = Bag (DAList.empty)\"\n  by (simp add: multiset_eq_iff alist.Alist_inverse DAList.empty_def)\n\nlemma single_Bag [code]: \"{#x#} = Bag (DAList.update x 1 DAList.empty)\"\n  by (simp add: multiset_eq_iff alist.Alist_inverse update.rep_eq empty.rep_eq)\n\nlemma union_Bag [code]: \"Bag xs + Bag ys = Bag (join (\\<lambda>x (n1, n2). n1 + n2) xs ys)\"\n  by (rule multiset_eqI)\n    (simp add: count_of_join_raw alist.Alist_inverse distinct_join_raw join_def)\n\nlemma minus_Bag [code]: \"Bag xs - Bag ys = Bag (subtract_entries xs ys)\"\n  by (rule multiset_eqI)\n    (simp add: count_of_subtract_entries_raw alist.Alist_inverse\n      distinct_subtract_entries_raw subtract_entries_def)\n\nlemma filter_Bag [code]: \"Multiset.filter P (Bag xs) = Bag (DAList.filter (P \\<circ> fst) xs)\"\n  by (rule multiset_eqI) (simp add: count_of_filter DAList.filter.rep_eq)\n\n\nlemma mset_eq [code]: \"HOL.equal (m1::'a::equal multiset) m2 \\<longleftrightarrow> m1 \\<le> m2 \\<and> m2 \\<le> m1\"\n  by (metis equal_multiset_def eq_iff)\n\ntext \\<open>By default the code for @{text \"<\"} is @{prop\"xs < ys \\<longleftrightarrow> xs \\<le> ys \\<and> \\<not> xs = ys\"}.\nWith equality implemented by @{text\"\\<le>\"}, this leads to three calls of  @{text\"\\<le>\"}.\nHere is a more efficient version:\\<close>\nlemma mset_less[code]: \"xs < (ys :: 'a multiset) \\<longleftrightarrow> xs \\<le> ys \\<and> \\<not> ys \\<le> xs\"\n  by (rule less_le_not_le)\n\nlemma mset_less_eq_Bag0:\n  \"Bag xs \\<le> A \\<longleftrightarrow> (\\<forall>(x, n) \\<in> set (DAList.impl_of xs). count_of (DAList.impl_of xs) x \\<le> count A x)\"\n    (is \"?lhs \\<longleftrightarrow> ?rhs\")\nproof\n  assume ?lhs\n  then show ?rhs by (auto simp add: mset_le_def)\nnext\n  assume ?rhs\n  show ?lhs\n  proof (rule mset_less_eqI)\n    fix x\n    from \\<open>?rhs\\<close> have \"count_of (DAList.impl_of xs) x \\<le> count A x\"\n      by (cases \"x \\<in> fst ` set (DAList.impl_of xs)\") (auto simp add: count_of_empty)\n    then show \"count (Bag xs) x \\<le> count A x\" by (simp add: mset_le_def)\n  qed\nqed\n\nlemma mset_less_eq_Bag [code]:\n  \"Bag xs \\<le> (A :: 'a multiset) \\<longleftrightarrow> (\\<forall>(x, n) \\<in> set (DAList.impl_of xs). n \\<le> count A x)\"\nproof -\n  {\n    fix x n\n    assume \"(x,n) \\<in> set (DAList.impl_of xs)\"\n    then have \"count_of (DAList.impl_of xs) x = n\"\n    proof transfer\n      fix x n\n      fix xs :: \"('a \\<times> nat) list\"\n      show \"(distinct \\<circ> map fst) xs \\<Longrightarrow> (x, n) \\<in> set xs \\<Longrightarrow> count_of xs x = n\"\n      proof (induct xs)\n        case Nil\n        then show ?case by simp\n      next\n        case (Cons ym ys)\n        obtain y m where ym: \"ym = (y,m)\" by force\n        note Cons = Cons[unfolded ym]\n        show ?case\n        proof (cases \"x = y\")\n          case False\n          with Cons show ?thesis\n            unfolding ym by auto\n        next\n          case True\n          with Cons(2-3) have \"m = n\" by force\n          with True show ?thesis\n            unfolding ym by auto\n        qed\n      qed\n    qed\n  }\n  then show ?thesis\n    unfolding mset_less_eq_Bag0 by auto\nqed\n\ndeclare multiset_inter_def [code]\ndeclare sup_multiset_def [code]\ndeclare multiset_of.simps [code]\n\n\nfun fold_impl :: \"('a \\<Rightarrow> nat \\<Rightarrow> 'b \\<Rightarrow> 'b) \\<Rightarrow> 'b \\<Rightarrow> ('a \\<times> nat) list \\<Rightarrow> 'b\"\nwhere\n  \"fold_impl fn e ((a,n) # ms) = (fold_impl fn ((fn a n) e) ms)\"\n| \"fold_impl fn e [] = e\"\n\ndefinition fold :: \"('a \\<Rightarrow> nat \\<Rightarrow> 'b \\<Rightarrow> 'b) \\<Rightarrow> 'b \\<Rightarrow> ('a, nat) alist \\<Rightarrow> 'b\"\n  where \"fold f e al = fold_impl f e (DAList.impl_of al)\"\n\nhide_const (open) fold\n\ncontext comp_fun_commute\nbegin\n\nlemma DAList_Multiset_fold:\n  assumes fn: \"\\<And>a n x. fn a n x = (f a ^^ n) x\"\n  shows \"Multiset.fold f e (Bag al) = DAList_Multiset.fold fn e al\"\n  unfolding DAList_Multiset.fold_def\nproof (induct al)\n  fix ys\n  let ?inv = \"{xs :: ('a \\<times> nat) list. (distinct \\<circ> map fst) xs}\"\n  note cs[simp del] = count_simps\n  have count[simp]: \"\\<And>x. count (Abs_multiset (count_of x)) = count_of x\"\n    by (rule Abs_multiset_inverse[OF count_of_multiset])\n  assume ys: \"ys \\<in> ?inv\"\n  then show \"Multiset.fold f e (Bag (Alist ys)) = fold_impl fn e (DAList.impl_of (Alist ys))\"\n    unfolding Bag_def unfolding Alist_inverse[OF ys]\n  proof (induct ys arbitrary: e rule: list.induct)\n    case Nil\n    show ?case\n      by (rule trans[OF arg_cong[of _ \"{#}\" \"Multiset.fold f e\", OF multiset_eqI]])\n         (auto, simp add: cs)\n  next\n    case (Cons pair ys e)\n    obtain a n where pair: \"pair = (a,n)\"\n      by force\n    from fn[of a n] have [simp]: \"fn a n = (f a ^^ n)\"\n      by auto\n    have inv: \"ys \\<in> ?inv\"\n      using Cons(2) by auto\n    note IH = Cons(1)[OF inv]\n    def Ys \\<equiv> \"Abs_multiset (count_of ys)\"\n    have id: \"Abs_multiset (count_of ((a, n) # ys)) = ((op + {# a #}) ^^ n) Ys\"\n      unfolding Ys_def\n    proof (rule multiset_eqI, unfold count)\n      fix c\n      show \"count_of ((a, n) # ys) c =\n        count ((op + {#a#} ^^ n) (Abs_multiset (count_of ys))) c\" (is \"?l = ?r\")\n      proof (cases \"c = a\")\n        case False\n        then show ?thesis\n          unfolding cs by (induct n) auto\n      next\n        case True\n        then have \"?l = n\" by (simp add: cs)\n        also have \"n = ?r\" unfolding True\n        proof (induct n)\n          case 0\n          from Cons(2)[unfolded pair] have \"a \\<notin> fst ` set ys\" by auto\n          then show ?case by (induct ys) (simp, auto simp: cs)\n        next\n          case Suc\n          then show ?case by simp\n        qed\n        finally show ?thesis .\n      qed\n    qed\n    show ?case\n      unfolding pair\n      apply (simp add: IH[symmetric])\n      unfolding id Ys_def[symmetric]\n      apply (induct n)\n      apply (auto simp: fold_mset_fun_left_comm[symmetric])\n      done\n  qed\nqed\n\nend\n\nlift_definition single_alist_entry :: \"'a \\<Rightarrow> 'b \\<Rightarrow> ('a, 'b) alist\" is \"\\<lambda>a b. [(a, b)]\"\n  by auto\n\nlemma image_mset_Bag [code]:\n  \"image_mset f (Bag ms) =\n    DAList_Multiset.fold (\\<lambda>a n m. Bag (single_alist_entry (f a) n) + m) {#} ms\"\n  unfolding image_mset_def\nproof (rule comp_fun_commute.DAList_Multiset_fold, unfold_locales, (auto simp: ac_simps)[1])\n  fix a n m\n  show \"Bag (single_alist_entry (f a) n) + m = ((op + \\<circ> single \\<circ> f) a ^^ n) m\" (is \"?l = ?r\")\n  proof (rule multiset_eqI)\n    fix x\n    have \"count ?r x = (if x = f a then n + count m x else count m x)\"\n      by (induct n) auto\n    also have \"\\<dots> = count ?l x\"\n      by (simp add: single_alist_entry.rep_eq)\n    finally show \"count ?l x = count ?r x\" ..\n  qed\nqed\n\nhide_const single_alist_entry\n\n(* we cannot use (\\<lambda>a n. op + (a * n)) for folding, since * is not defined\n   in comm_monoid_add *)\nlemma msetsum_Bag[code]: \"msetsum (Bag ms) = DAList_Multiset.fold (\\<lambda>a n. ((op + a) ^^ n)) 0 ms\"\n  unfolding msetsum.eq_fold\n  apply (rule comp_fun_commute.DAList_Multiset_fold)\n  apply unfold_locales\n  apply (auto simp: ac_simps)\n  done\n\n(* we cannot use (\\<lambda>a n. op * (a ^ n)) for folding, since ^ is not defined\n   in comm_monoid_mult *)\nlemma msetprod_Bag[code]: \"msetprod (Bag ms) = DAList_Multiset.fold (\\<lambda>a n. ((op * a) ^^ n)) 1 ms\"\n  unfolding msetprod.eq_fold\n  apply (rule comp_fun_commute.DAList_Multiset_fold)\n  apply unfold_locales\n  apply (auto simp: ac_simps)\n  done\n\nlemma mcard_fold: \"mcard A = Multiset.fold (\\<lambda>_. Suc) 0 A\" (is \"_ = Multiset.fold ?f _ _\")\nproof -\n  interpret comp_fun_commute ?f by default auto\n  show ?thesis by (induct A) auto\nqed\n\nlemma mcard_Bag[code]: \"mcard (Bag ms) = DAList_Multiset.fold (\\<lambda>a n. op + n) 0 ms\"\n  unfolding mcard_fold\nproof (rule comp_fun_commute.DAList_Multiset_fold, unfold_locales, simp)\n  fix a n x\n  show \"n + x = (Suc ^^ n) x\"\n    by (induct n) auto\nqed\n\n\nlemma set_of_fold: \"set_of A = Multiset.fold insert {} A\" (is \"_ = Multiset.fold ?f _ _\")\nproof -\n  interpret comp_fun_commute ?f by default auto\n  show ?thesis by (induct A) auto\nqed\n\nlemma set_of_Bag[code]:\n  \"set_of (Bag ms) = DAList_Multiset.fold (\\<lambda>a n. (if n = 0 then (\\<lambda>m. m) else insert a)) {} ms\"\n  unfolding set_of_fold\nproof (rule comp_fun_commute.DAList_Multiset_fold, unfold_locales, (auto simp: ac_simps)[1])\n  fix a n x\n  show \"(if n = 0 then \\<lambda>m. m else insert a) x = (insert a ^^ n) x\" (is \"?l n = ?r n\")\n  proof (cases n)\n    case 0\n    then show ?thesis by simp\n  next\n    case (Suc m)\n    then have \"?l n = insert a x\" by simp\n    moreover have \"?r n = insert a x\" unfolding Suc by (induct m) auto\n    ultimately show ?thesis by auto\n  qed\nqed\n\n\ninstantiation multiset :: (exhaustive) exhaustive\nbegin\n\ndefinition exhaustive_multiset ::\n  \"('a multiset \\<Rightarrow> (bool \\<times> term list) option) \\<Rightarrow> natural \\<Rightarrow> (bool \\<times> term list) option\"\n  where \"exhaustive_multiset f i = Quickcheck_Exhaustive.exhaustive (\\<lambda>xs. f (Bag xs)) i\"\n\ninstance ..\n\nend\n\nend\n\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/Library/DAList_Multiset.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.2988502769805688}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2005         |\n            |               December 2005  (modified)   |\n            |                  April 2006  (modified)   |\n            |                  March 2007  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory CSP_F_law_step_ext\nimports CSP_F_law_basic CSP_T.CSP_T_law_step_ext\nbegin\n\n(*****************************************************************\n\n         1. step laws\n         2.\n         3. \n         4. \n\n *****************************************************************)\n\n(*********************************************************\n              (P1 [> P2) |[X]| (Q1 [> Q2)\n *********************************************************)\n\n(* The following law in p.288 does not hold.                               *)\n(*     (P1 [> P2) |[X]| (Q1 [> Q2)                                         *)\n(*  =F (P1 |[X]| Q1) [> ((P2 |[X]| (Q1 [> Q2)) |~| ((P1 [> P2) |[X]| Q2))  *)\n(*                                                                         *)\n(* a counter example:                                                      *)\n(*  P1 = a -> STOP, P2 = STOP, Q1 = STOP, Q2 = b -> STOP, X = {}           *)\n(*  where (a ~= b)                                                         *)\n(*                                                                         *)\n(*  check the following lemmas                                             *)\n\nlemma \"a ~= b ==>\n       (<Ev a>, {(Ev b)}) ~:f \n        failures ((a -> STOP [> STOP) |[{}]| (STOP [> (b -> STOP))) M\"\napply (simp add: in_failures in_traces)\napply (intro allI impI)\napply (simp add: par_tr_Ev)\napply (erule disjE)\napply (auto)\ndone\n\nlemma \"(<Ev a>, {(Ev b)}) :f\n       failures (((a -> STOP) |[{}]| STOP) [> \n                 ((STOP |[{}]| (STOP [> (b -> STOP))) |~| \n                  (((a -> STOP [> STOP) |[X]| (b -> STOP))))) M\"\napply (simp add: in_failures in_traces)\napply (rule disjI1)\napply (rule_tac x=\"{(Ev b)}\" in exI)\napply (rule_tac x=\"{(Ev b)}\" in exI)\napply (simp)\napply (rule_tac x=\"<Ev a>\" in exI)\napply (simp add: par_tr_nil_right)\ndone\n\n(*********************************************************\n              (P [> Q) |[X]| (? :Y -> Rf)\n *********************************************************)\n\n(* The following law in p.289 does not hold.                               *)\n(*                                                                         *)\n(*     (P [> Q) |[X]| (? :Y -> Rf) =F[M,M]                                      *)\n(*     (? x:(Y - X) -> ((P [> Q) |[X]| Rf x))                              *)\n(*     [+] ((P |[X]| (? :Y -> Rf)) [> (Q |[X]| (? :Y -> Rf)))              *)\n(*                                                                         *)\n(* a counter example:                                                      *)\n(*  P = STOP, Q = b -> STOP, Y = {a}, Rf = (%x. STOP), X = {}              *)\n(*  where (a ~= b)                                                         *)\n(*                                                                         *)\n(*  check the following lemmas                                             *)\n\nlemma \"a ~= b ==>\n      (<Ev a>, {(Ev b)}) ~:f  \n       failures ((STOP [> (b -> STOP)) |[{}]| (? x:{a} -> STOP)) M\"\napply (simp add: in_failures in_traces)\napply (intro allI impI)\napply (simp add: par_tr_Ev)\napply (erule disjE)\napply (auto)\ndone\n\nlemma \"a ~= b ==>\n       (<Ev a>, {(Ev b)}) :f \n        failures ((? x:({a} - {}) -> ((STOP [>  (b -> STOP)) |[{}]| STOP))\n                  [+] ((STOP |[{}]| (? x:{a} -> STOP)) \n                       [> ((b -> STOP) |[{}]| (? x:{a} -> STOP)))) M\"\napply (fold Timeout_def)\napply (simp add: in_failures in_failures_Timeout in_traces)\napply (rule disjI2)\napply (rule disjI2)\napply (rule_tac x=\"{(Ev b)}\" in exI)\napply (rule_tac x=\"{(Ev b)}\" in exI)\napply (simp)\napply (rule_tac x=\"<Ev a>\" in exI)\napply (simp add: par_tr_nil_left)\ndone\n\n(*********************************************************\n              Parallel expansion & distribbution\n *********************************************************)\n\nlemma cspF_Parallel_Timeout_split:\n  \"((? :Y -> Pf) [> P) |[X]| ((? :Z -> Qf) [> Q) =F[M,M]\n     (? x:((X Int Y Int Z) Un (Y - X) Un (Z - X))\n         -> IF (x : X) THEN (Pf x |[X]| Qf x)\n               ELSE IF (x : Y & x : Z) THEN ((Pf x |[X]| ((? x:Z -> Qf x) [> Q))\n                                        |~| (((? x:Y -> Pf x) [> P) |[X]| Qf x))\n               ELSE IF (x : Y) THEN (Pf x |[X]| ((? x:Z -> Qf x) [> Q))\n               ELSE (((? x:Y -> Pf x) [> P) |[X]| Qf x))\n     [> (((P |[X]| ((? :Z -> Qf) [> Q)) |~|\n         (((? :Y -> Pf) [> P) |[X]| Q)))\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Parallel_Timeout_split)\napply (fold Timeout_def)\napply (rule order_antisym)\n\n (* => *)\n apply (rule)\n apply (simp add: in_failures_Timeout in_failures)\n apply (elim disjE conjE exE)\n apply (simp_all)\n\n  apply (force)\n\n  apply (rule disjI1)\n  apply (rule_tac x=\"Y\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"sa\" in exI)\n  apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n  apply (simp)\n\n  apply (rule disjI1)\n  apply (rule_tac x=\"Y\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"sa\" in exI)\n  apply (rule_tac x=\"<>\" in exI)\n  apply (simp)\n\n  apply (rule disjI2)\n  apply (rule disjI1)\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Z\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n  apply (rule_tac x=\"t\" in exI)\n  apply (simp)\n\n  apply (rule disjI2)\n  apply (rule disjI1)\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Z\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"<>\" in exI)\n  apply (rule_tac x=\"t\" in exI)\n  apply (simp)\n\n  (* main part *)\n\n  apply (case_tac \"s = <>\", simp, simp)\n  apply (rule disjI2)\n  apply (rule disjI2)\n  apply (simp add: par_tr_head_Ev_Ev)\n  apply (elim exE disjE)\n  apply (rule_tac x=\"c\" in exI)\n  apply (rule_tac x=\"v\" in exI)\n  apply (elim conjE disjE)\n\n   (* sync *)\n   apply (simp)\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (force)\n\n   (* left *)\n   apply (simp)\n   apply (case_tac \"c:Z\")\n\n    apply (simp)\n    apply (rule disjI1)\n    apply (rule_tac x=\"Ya\" in exI)\n    apply (rule_tac x=\"Za\" in exI)\n    apply (force)\n\n    apply (simp)\n    apply (rule_tac x=\"Ya\" in exI)\n    apply (rule_tac x=\"Za\" in exI)\n    apply (force)\n\n   (* right *)\n   apply (simp)\n   apply (case_tac \"c:Y\")\n\n    apply (simp)\n    apply (rule disjI2)\n    apply (rule_tac x=\"Ya\" in exI)\n    apply (rule_tac x=\"Za\" in exI)\n    apply (force)\n\n    apply (simp)\n    apply (rule_tac x=\"Ya\" in exI)\n    apply (rule_tac x=\"Za\" in exI)\n    apply (force)\n\n  (* others *)\n\n  apply (simp add: in_traces)\n  apply (simp add: in_traces)\n  apply (simp add: in_traces)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_failures_Timeout in_failures)\n apply (elim conjE exE disjE)\n apply (simp_all)\n\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (force)\n\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (force)\n\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (force)\n\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (force)\n\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (force)\n\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (force)\n\n  (* main part *)\n\n  (* sync *)\n  apply (simp add: in_failures_Parallel)\n  apply (elim disjE conjE exE)\n  apply (simp)\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n  apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n  apply (simp add: par_tr_head)\n\n  (* no_sync *)\n  apply (simp add: in_failures_IF)\n  apply (case_tac \"a:Z\")\n\n  apply (simp add: in_failures_Timeout in_failures)\n  apply (elim disjE conjE exE)\n  apply (simp_all)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n  (* a ~: Z *)\n  apply (simp add: in_failures_Timeout in_failures)\n  apply (elim disjE conjE exE)\n  apply (simp_all)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n  apply (simp add: in_traces)\n\n  (* no_sync *)\n  apply (simp add: in_failures_IF)\n  apply (case_tac \"a:Y\")\n\n  apply (simp add: in_failures_Timeout in_failures)\n  apply (elim disjE conjE exE)\n  apply (simp_all)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n  (* a ~: Y *)\n  apply (simp add: in_failures_Timeout in_failures)\n  apply (elim disjE conjE exE)\n  apply (simp_all)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n (* others *)\n\n apply (simp add: in_traces)\ndone\n\n(*********************************************************\n            Parallel expansion & distribbution 2\n *********************************************************)\n\n(*** left ****)\n\nlemma cspF_Parallel_Timeout_input_l: \n  \"((? :Y -> Pf) [> P) |[X]| (? :Z -> Qf) =F[M,M]\n     (? x:((X Int Y Int Z) Un (Y - X) Un (Z - X))\n         -> IF (x : X) THEN (Pf x |[X]| Qf x)\n               ELSE IF (x : Y & x : Z) THEN ((Pf x |[X]| (? x:Z -> Qf x))\n                                        |~| (((? x:Y -> Pf x) [> P) |[X]| Qf x))\n               ELSE IF (x : Y) THEN (Pf x |[X]| (? x:Z -> Qf x))\n               ELSE (((? x:Y -> Pf x) [> P) |[X]| Qf x))\n     [> (((P |[X]| (? :Z -> Qf))))\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Parallel_Timeout_input)\napply (fold Timeout_def)\napply (rule order_antisym)\n\n (* => *)\n apply (rule)\n apply (simp add: in_failures_Timeout in_failures)\n apply (elim disjE conjE exE)\n apply (simp_all)\n\n  apply (force)\n\n  apply (rule disjI1)\n  apply (rule_tac x=\"Y\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"sa\" in exI)\n  apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n  apply (simp)\n\n  apply (simp add: par_tr_nil_right)\n  apply (rule disjI2)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"sb\" in exI)\n  apply (elim conjE)\n  apply (simp add: image_iff)\n  apply (case_tac \"a : Z\")\n   apply (simp)\n   apply (rule disjI1)\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<>\" in exI)\n   apply (simp add: par_tr_nil_right)\n\n   apply (simp)\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<>\" in exI)\n   apply (simp add: par_tr_nil_right)\n\n  apply (simp add: in_traces)\n\n  (* main part *)\n\n  apply (case_tac \"s = <>\", simp, simp)\n  apply (rule disjI2)\n  apply (simp add: par_tr_head_Ev_Ev)\n  apply (elim exE disjE)\n  apply (rule_tac x=\"c\" in exI)\n  apply (rule_tac x=\"v\" in exI)\n  apply (elim conjE disjE)\n\n   (* sync *)\n   apply (simp)\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (force)\n\n   (* left *)\n   apply (simp)\n   apply (case_tac \"c:Z\")\n\n    apply (simp)\n    apply (rule disjI1)\n    apply (rule_tac x=\"Ya\" in exI)\n    apply (rule_tac x=\"Za\" in exI)\n    apply (force)\n\n    apply (simp)\n    apply (rule_tac x=\"Ya\" in exI)\n    apply (rule_tac x=\"Za\" in exI)\n    apply (force)\n\n   (* right *)\n   apply (simp)\n   apply (case_tac \"c:Y\")\n\n    apply (simp)\n    apply (rule disjI2)\n    apply (rule_tac x=\"Ya\" in exI)\n    apply (rule_tac x=\"Za\" in exI)\n    apply (force)\n\n    apply (simp)\n    apply (rule_tac x=\"Ya\" in exI)\n    apply (rule_tac x=\"Za\" in exI)\n    apply (force)\n\n  (* others *)\n\n  apply (simp add: in_traces)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_failures_Timeout in_failures)\n apply (elim conjE exE disjE)\n apply (simp_all)\n\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"sa\" in exI)\n  apply (rule_tac x=\"<>\" in exI)\n  apply (simp)\n\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (force)\n\n  (* main part *)\n\n  (* sync *)\n  apply (simp add: in_failures_Parallel)\n  apply (elim disjE conjE exE)\n  apply (simp)\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n  apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n  apply (simp add: par_tr_head)\n\n  (* no_sync *)\n  apply (simp add: in_failures_IF)\n  apply (case_tac \"a:Z\")\n\n  apply (simp add: in_failures_Timeout in_failures)\n  apply (elim disjE conjE exE)\n  apply (simp_all)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev aa> ^^^ sc\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (simp add: in_traces)\n\n  (* a ~: Z *)\n  apply (simp add: in_failures_Timeout in_failures)\n  apply (elim disjE conjE exE)\n  apply (simp_all)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"<>\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n  apply (simp add: in_traces)\n\n  (* no_sync *)\n  apply (simp add: in_failures_IF)\n  apply (case_tac \"a:Y\")\n\n  apply (simp add: in_failures_Timeout in_failures)\n  apply (elim disjE conjE exE)\n  apply (simp_all)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"<Ev aa> ^^^ sc\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev aa> ^^^ sc\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (simp add: in_traces)\n\n  (* a ~: Y *)\n  apply (simp add: in_failures_Timeout in_failures)\n  apply (elim disjE conjE exE)\n  apply (simp_all)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev aa> ^^^ sc\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (simp add: in_traces)\n\n (* others *)\n\n apply (simp add: in_traces)\ndone\n\n(*** right ****)\n\nlemma cspF_Parallel_Timeout_input_r: \n  \"(? :Y -> Pf) |[X]| ((? :Z -> Qf) [> Q) =F[M,M]\n     (? x:((X Int Y Int Z) Un (Y - X) Un (Z - X))\n         -> IF (x : X) THEN (Pf x |[X]| Qf x)\n               ELSE IF (x : Y & x : Z) THEN ((Pf x |[X]| ((? x:Z -> Qf x) [> Q))\n                                        |~| ((? x:Y -> Pf x) |[X]| Qf x))\n               ELSE IF (x : Y) THEN (Pf x |[X]| ((? x:Z -> Qf x) [> Q))\n               ELSE ((? x:Y -> Pf x) |[X]| Qf x))\n     [> ((? :Y -> Pf) |[X]| Q)\"\napply (rule cspF_rw_left)\napply (rule cspF_commut)\napply (rule cspF_rw_left)\napply (rule cspF_Parallel_Timeout_input_l)\napply (rule cspF_decompo)\napply (rule cspF_decompo)\napply (rule cspF_decompo)\napply (force)\napply (rule cspF_decompo)\napply (simp)\napply (rule cspF_commut)\n\napply (case_tac \"a : Z & a : Y\")\napply (simp)\napply (rule cspF_rw_left)\napply (rule cspF_IF_True)\napply (rule cspF_rw_right)\napply (rule cspF_IF_True)\napply (rule cspF_rw_left)\napply (rule cspF_commut)\napply (rule cspF_decompo)\napply (rule cspF_commut)\napply (rule cspF_commut)\n\napply (simp (no_asm_simp))\napply (rule cspF_rw_left)\napply (rule cspF_IF_False)\napply (rule cspF_rw_right)\napply (subgoal_tac \"~ (a : Y & a : Z)\")\napply (simp (no_asm_simp))\napply (rule cspF_IF_False)\napply (force)\n\napply (case_tac \"a : Z\")\napply (simp)\napply (rule cspF_rw_left)\napply (rule cspF_IF_True)\napply (rule cspF_rw_right)\napply (rule cspF_IF_False)\napply (rule cspF_commut)\napply (simp)\napply (rule cspF_rw_left)\napply (rule cspF_IF_False)\napply (rule cspF_rw_right)\napply (rule cspF_IF_True)\napply (rule cspF_commut)\n\napply (rule cspF_reflex)\napply (rule cspF_commut)\ndone\n\nlemmas cspF_Parallel_Timeout_input\n     = cspF_Parallel_Timeout_input_l\n       cspF_Parallel_Timeout_input_r\n\n(*** cspF_step_ext ***)\n\nlemmas cspF_step_ext = cspF_Parallel_Timeout_split\n                       cspF_Parallel_Timeout_input\n\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/CSP_F/CSP_F_law_step_ext.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5583270090337583, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.29875990519376}}
{"text": "theory Incredible_Predicate_Tasks\nimports\n  Incredible_Completeness\n  Incredible_Predicate\n  \"HOL-Eisbach.Eisbach\"\nbegin\n\ndeclare One_nat_def [simp del]\n\ncontext ND_Rules_Inst begin\nlemma eff_NatRuleI:\n  \"nat_rule rule c ants\n    \\<Longrightarrow> entail = (\\<Gamma> \\<turnstile> subst s (freshen a c))\n    \\<Longrightarrow> hyps = ((\\<lambda>ant. ((\\<lambda>p. subst s (freshen a p)) |`| a_hyps ant |\\<union>| \\<Gamma> \\<turnstile> subst s (freshen a (a_conc ant)))) |`| ants)\n    \\<Longrightarrow> (\\<And> ant f. ant |\\<in>| ants \\<Longrightarrow> f |\\<in>| \\<Gamma> \\<Longrightarrow> freshenLC a ` (a_fresh ant) \\<inter> lconsts f = {})\n    \\<Longrightarrow> (\\<And> ant. ant |\\<in>| ants \\<Longrightarrow> freshenLC a ` (a_fresh ant) \\<inter> subst_lconsts s = {})\n    \\<Longrightarrow> eff (NatRule rule) entail hyps\"\n  by (drule eff.intros(2)) simp_all\nend\n\ncontext Abstract_Task begin\nlemma  natEff_InstI:\n  \"rule = (r,c)\n  \\<Longrightarrow> c \\<in> set (consequent r)\n  \\<Longrightarrow> antec = f_antecedent r\n  \\<Longrightarrow> natEff_Inst rule c antec\"\n  by (metis natEff_Inst.intros)\nend\n\ncontext begin\n\ntext \\<open>A typical task with local constants:: \\<open>\\<forall>x. Q x \\<longrightarrow> Q x\\<close>\\<close>\n\ntext \\<open>First the task is defined as an @{term Abstract_Task}.\\<close>\n\ninterpretation task: Abstract_Task\n  \"curry to_nat :: nat \\<Rightarrow> var \\<Rightarrow> var\"\n  map_lc\n  lc\n  \"closed\"\n  subst\n  lc_subst\n  map_lc_subst\n  \"Var 0 []\"\n  antecedent\n  consequent\n  prop_rules\n  \"[]\"\n  \"[ForallX (imp (Q x) (Q x))]\"\nby unfold_locales auto\n\ntext \\<open>Then we show, that this task has a proof within our formalization of natural deduction\n  by giving a concrete proof tree.\\<close>\n\nabbreviation lx :: \"nat\" where \"lx \\<equiv> to_nat (1::nat,0::nat)\"\n\nabbreviation base_tree :: \"((form fset \\<times> form) \\<times> (prop_rule \\<times> form) NatRule) tree\" where\n  \"base_tree \\<equiv> Node ({|Q (LC lx)|} \\<turnstile> Q (LC lx), Axiom) {||}\"\n\nabbreviation imp_tree :: \"((form fset \\<times> form) \\<times> (prop_rule \\<times> form) NatRule) tree\" where\n  \"imp_tree \\<equiv> Node ({||} \\<turnstile> imp (Q (LC lx)) (Q (LC lx)), NatRule (impI, imp X Y)) {|base_tree|}\"\n\nabbreviation solution_tree :: \"((form fset \\<times> form) \\<times> (prop_rule \\<times> form) NatRule) tree\" where\n  \"solution_tree \\<equiv> Node ({||} \\<turnstile> ForallX (imp (Q x) (Q x)), NatRule (allI, ForallX (P x))) {|imp_tree|}\"\n\nabbreviation s1 where \"s1 \\<equiv> [(12, ([9], imp (Q x) (Q x)))] \"\nabbreviation s2 where \"s2 \\<equiv> [(10, ([], Q (LC lx))), (11, ([], Q (LC lx)))] \"\n\nlemma fv_subst_s1[simp]: \"fv_subst s1 = {}\"\n  by (simp add: fv_subst_def)\n\nlemma subst1_simps[simp]:\n  \"subst s1 (P (LC n)) = imp (Q (LC n)) (Q (LC n))\"\n  \"subst s1 (ForallX (P x)) = ForallX (imp (Q x) (Q x))\"\n  by simp_all\n\nlemma subst2_simps[simp]:\n    \"subst s2 X = Q (LC lx)\" \n    \"subst s2 Y = Q (LC lx)\"\n    \"subst s2 (imp X Y) = imp (subst s2 X) (subst s2 Y)\"\n  by simp_all\n\nlemma substI1: \"ForallX (imp (Q x) (Q x)) = subst s1 (predicate.freshen 1 (ForallX (P x)))\"\n  by (auto simp add: predicate.freshen_def Let_def)\n\nlemma substI2: \"imp (Q (LC lx)) (Q (LC lx)) = subst s2 (predicate.freshen 2 (imp X Y))\"\n  by (auto simp add: predicate.freshen_def Let_def)\n\ndeclare subst.simps[simp del]\n\nlemma \"task.solved\"\n  unfolding task.solved_def\napply clarsimp\napply (rule_tac x=\"{||}\" in exI)\napply clarsimp\napply (rule_tac x=\"solution_tree\" in exI)\napply clarsimp\napply (rule conjI)\n\n apply (rule task.wf)\n   apply (solves \\<open>(auto simp add: stream.set_map task.n_rules_def)[1]\\<close>)\n  apply clarsimp\n  apply (rule task.eff_NatRuleI)\n      apply (solves \\<open>rule task.natEff_Inst.intros;simp\\<close>)\n     apply clarsimp     \n     apply (rule conjI)\n      apply (solves \\<open>simp\\<close>)\n     apply (solves \\<open>rule substI1\\<close>)\n    apply (simp add: predicate.f_antecedent_def predicate.freshen_def)\n    apply (subst antecedent.sel(2))\n    apply (solves \\<open>simp\\<close>)\n   apply (solves \\<open>simp\\<close>)\n  apply (solves \\<open>simp\\<close>)\n apply simp\n\n apply (rule task.wf)\n   apply (solves \\<open>(auto simp add: stream.set_map task.n_rules_def)[1]\\<close>)\n  apply clarsimp\n  apply (rule task.eff_NatRuleI)\n      apply (solves \\<open>rule task.natEff_Inst.intros; simp\\<close>)\n     apply clarsimp     \n     apply (rule conjI)\n      apply (solves \\<open>simp\\<close>)\n     apply (solves \\<open>rule substI2\\<close>)\n    apply (solves \\<open>simp add: predicate.f_antecedent_def predicate.freshen_def\\<close>)\n   apply (solves \\<open>simp\\<close>)\n  apply (solves \\<open>simp add: predicate.f_antecedent_def\\<close>)\n apply simp\n\n apply (solves \\<open>(auto intro: task.wf intro!: task.eff.intros(1))[1]\\<close>)\napply (solves \\<open>(rule tfinite.intros, simp)+\\<close>)\ndone\n\nabbreviation vertices where \"vertices \\<equiv> {|0::nat,1,2 |}\"\nfun nodeOf  where \n    \"nodeOf n = [Conclusion (ForallX (imp (Q x) (Q x))), \n                 Rule allI, \n                 Rule impI] ! n \"\n\nfun inst  where \n    \"inst n = [[],s1,s2] ! n\"\n\n\ninterpretation task: Vertex_Graph task.nodes task.inPorts task.outPorts vertices nodeOf.\n\nabbreviation e1 :: \"(nat, form, nat) edge'\"\n  where \"e1 \\<equiv> ((1,Reg (ForallX (P x))), (0,plain_ant (ForallX (imp (Q x) (Q x)))))\"\nabbreviation e2  :: \"(nat, form, nat) edge'\"\n  where \"e2 \\<equiv> ((2,Reg (imp X Y)), (1,allI_input))\"\nabbreviation e3  :: \"(nat, form, nat) edge'\"\n  where \"e3 \\<equiv> ((2,Hyp X (impI_input)), (2,impI_input))\"\nabbreviation task_edges :: \"(nat, form, nat) edge' set\" where \"task_edges \\<equiv> {e1, e2, e3}\"\n\n\ninterpretation task: Scoped_Graph task.nodes task.inPorts task.outPorts vertices nodeOf task_edges task.hyps\n  by standard (auto simp add: predicate.f_consequent_def predicate.f_antecedent_def)\n\ninterpretation task: Instantiation\n  task.inPorts\n  task.outPorts\n  nodeOf\n  task.hyps\n  task.nodes\n  task_edges\n  vertices\n  task.labelsIn\n  task.labelsOut\n  \"curry to_nat :: nat \\<Rightarrow> var \\<Rightarrow> var\"\n  map_lc\n  lc\n  \"closed\"\n  subst\n  lc_subst\n  map_lc_subst\n  \"Var 0 []\"\n  \"id\"\n  \"inst\"\nby unfold_locales simp\n\ntext \\<open>Finally we can also show that there is a proof graph for this task.\\<close>\n\ninterpretation Well_Scoped_Graph\n  task.nodes\n  task.inPorts\n  task.outPorts\n  vertices\n  nodeOf\n  task_edges\n  task.hyps\nby standard (auto split: if_splits)\n\nlemma no_path_01[simp]: \"task.path 0 v pth \\<longleftrightarrow> (pth = [] \\<and> v = 0)\"\n  by (cases pth) (auto simp add: task.path_cons_simp)\nlemma no_path_12[simp]: \"\\<not> task.path 1 2 pth\"\n  by (cases pth) (auto simp add: task.path_cons_simp)\n\ninterpretation Acyclic_Graph\n  task.nodes\n  task.inPorts\n  task.outPorts\n  vertices\n  nodeOf\n  task_edges\n  task.hyps\nproof\n  fix v pth \n  assume \"task.path v v pth\" and \"task.hyps_free pth\"\n  thus \"pth = []\"\n    by (cases pth) (auto simp add: task.path_cons_simp predicate.f_antecedent_def)\nqed\n\ninterpretation Saturated_Graph\n  task.nodes\n  task.inPorts\n  task.outPorts\n  vertices\n  nodeOf\n  task_edges\nby standard\n   (auto simp add: predicate.f_consequent_def predicate.f_antecedent_def) \n\ninterpretation Pruned_Port_Graph\n  task.nodes\n  task.inPorts\n  task.outPorts\n  vertices\n  nodeOf\n  task_edges\nproof\n  fix v\n  assume \"v |\\<in>| vertices\"\n  hence \"\\<exists> pth. task.path v 0 pth\"\n    apply auto\n    apply (rule exI[where x = \"[e1]\"], auto simp add: task.path_cons_simp)\n    apply (rule exI[where x = \"[e2,e1]\"], auto simp add: task.path_cons_simp)\n    done\n  moreover\n  have \"task.terminal_vertex 0\" by auto\n  ultimately\n  show \"\\<exists>pth v'. task.path v v' pth \\<and> task.terminal_vertex v'\" by blast\nqed\n\ninterpretation Well_Shaped_Graph\n  task.nodes\n  task.inPorts\n  task.outPorts\n  vertices\n  nodeOf task_edges\n  task.hyps\n..\n\ninterpretation Solution\n  task.inPorts\n  task.outPorts\n  nodeOf\n  task.hyps\n  task.nodes\n  vertices\n  task.labelsIn\n  task.labelsOut\n  \"curry to_nat :: nat \\<Rightarrow> var \\<Rightarrow> var\"\n  map_lc\n  lc\n  \"closed\"\n  subst\n  lc_subst\n  map_lc_subst\n  \"Var 0 []\"\n  id\n  inst\n  task_edges\nby standard\n   (auto simp add: task.labelAtOut_def task.labelAtIn_def predicate.freshen_def, subst antecedent.sel, simp)\n\ninterpretation Proof_Graph\n  task.nodes\n  task.inPorts\n  task.outPorts\n  vertices\n  nodeOf\n  task_edges\n  task.hyps\n  task.labelsIn\n  task.labelsOut\n  \"curry to_nat :: nat \\<Rightarrow> var \\<Rightarrow> var\"\n  map_lc\n  lc\n  \"closed\"\n  subst\n  lc_subst\n  map_lc_subst\n  \"Var 0 []\"\n  id\n  inst\n..\n\nlemma path_20:\n  assumes \"task.path 2 0 pth\"\n  shows \"(1, allI_input) \\<in> snd ` set pth\"\nproof-\n  { fix v\n    assume \"task.path v 0 pth\"\n    hence \"v = 0 \\<or> v = 1 \\<or> (1, allI_input) \\<in> snd ` set pth\"\n    by (induction v \"0::nat\" pth rule: task.path.induct) auto\n  }\n  from this[OF assms]\n  show ?thesis by auto\nqed\n\nlemma scope_21: \"2 \\<in> task.scope (1, allI_input)\"\n  by (auto intro!: task.scope.intros elim: path_20 simp add: task.outPortsRule_def predicate.f_antecedent_def predicate.f_consequent_def)\n\ninterpretation Scoped_Proof_Graph\n  \"curry to_nat :: nat \\<Rightarrow> var \\<Rightarrow> var\"\n  map_lc\n  lc\n  \"closed\"\n  subst\n  lc_subst\n  map_lc_subst\n  \"Var 0 []\"\n  task.inPorts\n  task.outPorts\n  nodeOf\n  task.hyps\n  task.nodes\n  vertices\n  task.labelsIn\n  task.labelsOut\n  id\n  inst\n  task_edges\n  task.local_vars\nby standard (auto simp add: predicate.f_antecedent_def scope_21)\n\ninterpretation Tasked_Proof_Graph\n  \"curry to_nat :: nat \\<Rightarrow> var \\<Rightarrow> var\"\n  map_lc\n  lc\n  \"closed\"\n  subst\n  lc_subst\n  map_lc_subst\n  \"Var 0 []\"\n  antecedent\n  consequent\n  prop_rules\n  \"[]\"\n  \"[ForallX (imp (Q x) (Q x))]\"\n  vertices\n  nodeOf\n  task_edges\n  id\n  inst\nby unfold_locales auto\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Incredible_Proof_Machine/Incredible_Predicate_Tasks.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5583269943353745, "lm_q2_score": 0.5350984286266116, "lm_q1q2_score": 0.29875989732867797}}
{"text": "(******************************************************************************\n * Clean\n *\n * Copyright (c) 2018-2019 Université Paris-Saclay, Univ. Paris-Sud, France\n *\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are\n * met:\n *\n *     * Redistributions of source code must retain the above copyright\n *       notice, this list of conditions and the following disclaimer.\n *\n *     * Redistributions in binary form must reproduce the above\n *       copyright notice, this list of conditions and the following\n *       disclaimer in the documentation and/or other materials provided\n *       with the distribution.\n *\n *     * Neither the name of the copyright holders nor the names of its\n *       contributors may be used to endorse or promote products derived\n *       from this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n ******************************************************************************)\n\n(*\n * Quicksort : all at a glance. \n *\n * Authors : Burkhart Wolff, Frédéric Tuong\n *)\n\nchapter \\<open> Clean Semantics : A Coding-Concept Example\\<close>\n\ntext\\<open>The following show-case introduces subsequently a non-trivial example involving\nlocal and global variable declarations, declarations of operations with pre-post conditions as\nwell as direct-recursive operations (i.e. C-like functions with side-effects on global and\nlocal variables. \\<close>\n\ntheory Quicksort\n  imports Clean.Clean\n          Clean.Hoare_Clean\n          Clean.Clean_Symbex\nbegin\n\nsection\\<open>The Quicksort Example - At a Glance\\<close>\n\ntext\\<open> We present the following quicksort algorithm in some conceptual, high-level notation:\n\n\\begin{isar}\nalgorithm (A,i,j) =\n    tmp := A[i];\n    A[i]:=A[j];\n    A[j]:=tmp\n\nalgorithm partition(A, lo, hi) is\n    pivot := A[hi]\n    i := lo\n    for j := lo to hi - 1 do\n        if A[j] < pivot then\n            swap A[i] with A[j]\n            i := i + 1\n    swap A[i] with A[hi]\n    return i\n\nalgorithm quicksort(A, lo, hi) is\n    if lo < hi then\n        p := partition(A, lo, hi)\n        quicksort(A, lo, p - 1)\n        quicksort(A, p + 1, hi)\n\n\\end{isar}\n\\<close>\n\n\nsection\\<open>Clean Encoding of the Global State of Quicksort\\<close>\n\n\nglobal_vars state\n    A :: \"int list\"\n\nfunction_spec swap (i::nat,j::nat) \\<comment> \\<open>TODO: the hovering on parameters produces a number of report equal to the number of \\<^ML>\\<open>Proof_Context.add_fixes\\<close> called in \\<^ML>\\<open>Function_Specification_Parser.checkNsem_function_spec\\<close>\\<close>\npre          \"\\<open>i < length A \\<and> j < length A\\<close>\"    \npost         \"\\<open>\\<lambda>res. length A = length(old A) \\<and> res = ()\\<close>\" \nlocal_vars   tmp :: int \ndefines      \" \\<open> tmp := A ! i\\<close>  ;-\n               \\<open> A := list_update A i (A ! j)\\<close> ;- \n               \\<open> A := list_update A j tmp\\<close> \" \n\n\nfunction_spec partition (lo::nat, hi::nat) returns nat\npre          \"\\<open>lo < length A \\<and> hi < length A\\<close>\"    \npost         \"\\<open>\\<lambda>res::nat. length A = length(old A) \\<and> res = 3\\<close>\" \nlocal_vars   pivot  :: int\n             i      :: nat\n             j      :: nat\ndefines      \" \\<open>pivot := A ! hi \\<close>  ;- \\<open>i := lo \\<close> ;- \\<open>j := lo \\<close> ;-\n               while\\<^sub>C \\<open>j \\<le> hi - 1 \\<close> \n                do if\\<^sub>C \\<open>A ! j < pivot\\<close>  \n                     then call\\<^sub>C swap \\<open>(i , j) \\<close>  ;-\n                          \\<open>i := i + 1 \\<close>\n                     else skip\\<^sub>S\\<^sub>E \n                   fi ;-\n                    \\<open>j := j + 1 \\<close> \n                od;-\n                call\\<^sub>C swap \\<open>(i, j)\\<close>  ;-\n                return\\<^bsub>local_partition_state.result_value_update\\<^esub> \\<open>i\\<close>\" \n\nthm partition_core_def\n\n\nrec_function_spec quicksort (lo::nat, hi::nat) returns unit\npre          \"\\<open>lo \\<le> hi \\<and> hi < length A\\<close>\"\npost         \"\\<open>\\<lambda>res::unit. \\<forall>i\\<in>{lo .. hi}. \\<forall>j\\<in>{lo .. hi}. i \\<le> j \\<longrightarrow> A!i \\<le> A!j\\<close>\"\nvariant      \"hi - lo\" \nlocal_vars   p :: \"nat\" \ndefines      \" if\\<^sub>C \\<open>lo < hi\\<close>  \n               then (p\\<^sub>t\\<^sub>m\\<^sub>p \\<leftarrow> call\\<^sub>C partition \\<open>(lo, hi)\\<close> ; assign_local p_update (\\<lambda>\\<sigma>. p\\<^sub>t\\<^sub>m\\<^sub>p)) ;-\n                     call\\<^sub>C quicksort \\<open>(lo, p - 1)\\<close> ;-\n                     call\\<^sub>C quicksort \\<open>(lo, p + 1)\\<close>  \n               else skip\\<^sub>S\\<^sub>E \n               fi\"\n\n\nthm quicksort_core_def\nthm quicksort_def\nthm quicksort_pre_def\nthm quicksort_post_def\n\nsection\\<open>Possible Application Sketch\\<close>\n\nlemma quicksort_correct : \n  \"\\<lbrace>\\<lambda>\\<sigma>.   \\<triangleright> \\<sigma> \\<and> quicksort_pre (lo, hi)(\\<sigma>) \\<and> \\<sigma> = \\<sigma>\\<^sub>p\\<^sub>r\\<^sub>e \\<rbrace> \n     quicksort (lo, hi) \n   \\<lbrace>\\<lambda>r \\<sigma>. \\<triangleright> \\<sigma> \\<and> quicksort_post(lo, hi)(\\<sigma>\\<^sub>p\\<^sub>r\\<^sub>e)(\\<sigma>)(r) \\<rbrace>\"\n   oops\n\n\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Clean/examples/Quicksort.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5583269943353744, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.29875989732867786}}
{"text": "(*  Title:       Isabelle Collections Library\n    Author:      Peter Lammich <peter dot lammich at uni-muenster.de>\n    Maintainer:  Peter Lammich <peter dot lammich at uni-muenster.de>\n*)\n(*\n  Changes since submission on 2009-11-26:\n\n  2009-12-10: OrderedMap, algorithms for iterators, min, max, to_sorted_list\n\n*)\n\nsection {* \\isaheader{Generic Algorithms for Maps} *}\ntheory MapGA\nimports SetIteratorCollectionsGA\nbegin\n\ntext_raw {*\\label{thy:MapGA}*}\n\nrecord ('k,'v,'s) map_basic_ops =\n  bmap_op_\\<alpha> :: \"('k,'v,'s) map_\\<alpha>\"\n  bmap_op_invar :: \"('k,'v,'s) map_invar\"\n  bmap_op_empty :: \"('k,'v,'s) map_empty\"\n  bmap_op_lookup :: \"('k,'v,'s) map_lookup\"\n  bmap_op_update :: \"('k,'v,'s) map_update\"\n  bmap_op_update_dj :: \"('k,'v,'s) map_update_dj\"\n  bmap_op_delete :: \"('k,'v,'s) map_delete\"\n  bmap_op_list_it :: \"('k,'v,'s) map_list_it\"\n  \nrecord ('k,'v,'s) omap_basic_ops = \"('k,'v,'s) map_basic_ops\" +\n  bmap_op_ordered_list_it :: \"'s \\<Rightarrow> ('k,'v,('k\\<times>'v) list) map_iterator\"\n  bmap_op_rev_list_it :: \"'s \\<Rightarrow> ('k,'v,('k\\<times>'v) list) map_iterator\"\n\nlocale StdBasicMapDefs = \n  poly_map_iteratei_defs \"bmap_op_list_it ops\" \n  for ops :: \"('k,'v,'s,'more) map_basic_ops_scheme\"\nbegin\n  abbreviation \\<alpha> where \"\\<alpha> == bmap_op_\\<alpha> ops\" \n  abbreviation invar where \"invar == bmap_op_invar ops\" \n  abbreviation empty where \"empty == bmap_op_empty ops\" \n  abbreviation lookup where \"lookup == bmap_op_lookup ops\" \n  abbreviation update where \"update == bmap_op_update ops\" \n  abbreviation update_dj where \"update_dj == bmap_op_update_dj ops\" \n  abbreviation delete where \"delete == bmap_op_delete ops\" \n  abbreviation list_it where \"list_it == bmap_op_list_it ops\" \nend\n\nlocale StdBasicOMapDefs = StdBasicMapDefs ops\n  + poly_map_iterateoi_defs \"bmap_op_ordered_list_it ops\"\n  + poly_map_rev_iterateoi_defs \"bmap_op_rev_list_it ops\"\n  for ops :: \"('k::linorder,'v,'s,'more) omap_basic_ops_scheme\"\nbegin\n  abbreviation ordered_list_it where \"ordered_list_it \n    \\<equiv> bmap_op_ordered_list_it ops\"\n  abbreviation rev_list_it where \"rev_list_it \n    \\<equiv> bmap_op_rev_list_it ops\"\nend\n\nlocale StdBasicMap = StdBasicMapDefs ops +\n  map \\<alpha> invar +\n  map_empty \\<alpha> invar empty +\n  map_lookup \\<alpha> invar lookup  +\n  map_update \\<alpha> invar update  +\n  map_update_dj \\<alpha> invar update_dj +\n  map_delete \\<alpha> invar delete  +\n  poly_map_iteratei \\<alpha> invar list_it\n  for ops :: \"('k,'v,'s,'more) map_basic_ops_scheme\"\nbegin\n  lemmas correct[simp] = empty_correct lookup_correct update_correct \n    update_dj_correct delete_correct\nend\n\n\nlocale StdBasicOMap = \n  StdBasicOMapDefs ops +\n  StdBasicMap ops +\n  poly_map_iterateoi \\<alpha> invar ordered_list_it +\n  poly_map_rev_iterateoi \\<alpha> invar rev_list_it\n  for ops :: \"('k::linorder,'v,'s,'more) omap_basic_ops_scheme\"\nbegin\nend\n\ncontext StdBasicMapDefs begin\n  definition \"g_sng k v \\<equiv> update k v (empty ())\"\n  definition \"g_add m1 m2 \\<equiv> iterate m2 (\\<lambda>(k,v) \\<sigma>. update k v \\<sigma>) m1\"\n\n  definition \n    \"g_sel m P \\<equiv> \n      iteratei m (\\<lambda>\\<sigma>. \\<sigma> = None) (\\<lambda>x \\<sigma>. if P x then Some x else None) None\"\n\n  definition \"g_bex m P \\<equiv> iteratei m (\\<lambda>x. \\<not>x) (\\<lambda>kv \\<sigma>. P kv) False\"\n  definition \"g_ball m P \\<equiv> iteratei m id (\\<lambda>kv \\<sigma>. P kv) True\"\n\n  definition \"g_size m \\<equiv> iterate m (\\<lambda>_. Suc) (0::nat)\"\n  definition \"g_size_abort b m \\<equiv> iteratei m (\\<lambda>s. s<b) (\\<lambda>_. Suc) (0::nat)\"\n\n  definition \"g_isEmpty m \\<equiv> g_size_abort 1 m = 0\"\n  definition \"g_isSng m \\<equiv> g_size_abort 2 m = 1\"\n\n  definition \"g_to_list m \\<equiv> iterate m (op #) []\"\n\n  definition \"g_list_to_map l \\<equiv> foldl (\\<lambda>m (k,v). update k v m) (empty ()) \n    (rev l)\"\n\n  definition \"g_add_dj m1 m2 \\<equiv> iterate m2 (\\<lambda>(k,v) \\<sigma>. update_dj k v \\<sigma>) m1\"\n\n  definition \"g_restrict P m \\<equiv> iterate m \n    (\\<lambda>(k,v) \\<sigma>. if P (k,v) then update_dj k v \\<sigma> else \\<sigma>) (empty ())\"\n\n  definition dflt_ops :: \"('k,'v,'s) map_ops\" \n    where [icf_rec_def]:\n    \"dflt_ops \\<equiv> \n      \\<lparr> \n        map_op_\\<alpha> = \\<alpha>,\n        map_op_invar = invar,\n        map_op_empty = empty,\n        map_op_lookup = lookup,\n        map_op_update = update,\n        map_op_update_dj = update_dj,\n        map_op_delete = delete,\n        map_op_list_it = list_it,\n        map_op_sng = g_sng,\n        map_op_restrict = g_restrict, \n        map_op_add = g_add, \n        map_op_add_dj = g_add_dj, \n        map_op_isEmpty = g_isEmpty, \n        map_op_isSng = g_isSng, \n        map_op_ball = g_ball, \n        map_op_bex = g_bex, \n        map_op_size = g_size, \n        map_op_size_abort = g_size_abort, \n        map_op_sel = g_sel, \n        map_op_to_list = g_to_list, \n        map_op_to_map = g_list_to_map\n      \\<rparr>\"\n\n  local_setup {* Locale_Code.lc_decl_del @{term dflt_ops}*}\n\nend\n\nlemma update_dj_by_update: \n  assumes \"map_update \\<alpha> invar update\"\n  shows \"map_update_dj \\<alpha> invar update\"\nproof -\n  interpret map_update \\<alpha> invar update by fact\n  show ?thesis \n    apply (unfold_locales)\n    apply (auto simp add: update_correct)\n    done\nqed\n\nlemma map_iterator_linord_is_it: \n  \"map_iterator_linord m it \\<Longrightarrow> map_iterator m it\"\n  unfolding set_iterator_def set_iterator_map_linord_def\n  apply (erule set_iterator_genord.set_iterator_weaken_R)\n  ..\n\n\n\ncontext StdBasicMap \nbegin\n  \n\n  lemma g_add_impl: \"map_add \\<alpha> invar g_add\"\n  proof\n    fix m1 m2\n    assume \"invar m1\" \"invar m2\"\n\n    have A: \"g_add m1 m2 = iterate_add_to_map m1 update (iteratei m2)\"\n      unfolding g_add_def iterate_add_to_map_def by simp\n    have \"\\<alpha> (g_add m1 m2) = \\<alpha> m1 ++ \\<alpha> m2 \\<and> invar (g_add m1 m2)\"\n      unfolding A\n      apply (rule \n        iterate_add_to_map_correct[of \\<alpha> invar update m1 \"iteratei m2\" \"\\<alpha> m2\"])\n      apply unfold_locales []\n      apply fact\n      apply (rule iteratei_correct, fact)\n      done\n    thus \"\\<alpha> (g_add m1 m2) = \\<alpha> m1 ++ \\<alpha> m2\" \"invar (g_add m1 m2)\" by auto\n  qed\n\n  lemma g_sel_impl: \"map_sel' \\<alpha> invar g_sel\"\n  proof -\n    have A: \"\\<And>m P. g_sel m P = iterate_sel_no_map (iteratei m) P\"\n      unfolding g_sel_def iterate_sel_no_map_def iterate_sel_def by simp\n\n    { fix m P\n      assume I: \"invar m\"\n      note iterate_sel_no_map_correct[OF iteratei_correct[OF I], of P]\n    }\n    thus ?thesis\n      apply unfold_locales\n      unfolding A\n      apply (simp add: Bex_def Ball_def image_iff map_to_set_def)\n      apply clarify\n      apply (metis option.exhaust prod.exhaust)\n      apply (simp add: Bex_def Ball_def image_iff map_to_set_def)\n      done\n  qed\n  \n  lemma g_bex_impl: \"map_bex \\<alpha> invar g_bex\"\n    apply unfold_locales\n    unfolding g_bex_def\n    apply (rule_tac I=\"\\<lambda>it \\<sigma>. \\<sigma> \\<longleftrightarrow> (\\<exists>kv\\<in>it. P kv)\" \n      in iteratei_rule_insert_P)\n    by (auto simp: map_to_set_def)\n\n  \n\n  lemma g_size_impl: \"map_size \\<alpha> invar g_size\"\n  proof \n    fix m\n    assume I: \"invar m\"\n    have A: \"g_size m \\<equiv> iterate_size (iteratei m)\"\n      unfolding g_size_def iterate_size_def by simp\n  \n    from iterate_size_correct [OF iteratei_correct[OF I]]\n    show \"g_size m = card (dom (\\<alpha> m))\"\n      unfolding A\n      by (simp_all add: card_map_to_set) \n  qed \n\n  lemma g_size_abort_impl: \"map_size_abort \\<alpha> invar g_size_abort\"\n  proof \n    fix s m\n    assume I: \"invar m\"\n    have A: \"g_size_abort s m \\<equiv> iterate_size_abort (iteratei m) s\"\n      unfolding g_size_abort_def iterate_size_abort_def by simp\n  \n    from iterate_size_abort_correct [OF iteratei_correct[OF I]]\n    show \"g_size_abort s m = min s (card (dom (\\<alpha> m)))\"\n      unfolding A\n      by (simp_all add: card_map_to_set) \n  qed \n\n  lemma g_isEmpty_impl: \"map_isEmpty \\<alpha> invar g_isEmpty\"\n  proof \n    fix m\n    assume I: \"invar m\"\n    interpret map_size_abort \\<alpha> invar g_size_abort by (rule g_size_abort_impl)\n    from size_abort_correct[OF I] have \n      \"g_size_abort 1 m = min 1 (card (dom (\\<alpha> m)))\" .\n    thus \"g_isEmpty m = (\\<alpha> m = Map.empty)\" unfolding g_isEmpty_def\n      by (auto simp: min_def card_0_eq[OF finite] I)\n  qed\n\n  lemma g_isSng_impl: \"map_isSng \\<alpha> invar g_isSng\"\n  proof \n    fix m\n    assume I: \"invar m\"\n    interpret map_size_abort \\<alpha> invar g_size_abort by (rule g_size_abort_impl)\n    from size_abort_correct[OF I] have \n      \"g_size_abort 2 m = min 2 (card (dom (\\<alpha> m)))\" .\n    thus \"g_isSng m = (\\<exists>k v. \\<alpha> m = [k \\<mapsto> v])\" unfolding g_isSng_def\n      by (auto simp: min_def I card_Suc_eq dom_eq_singleton_conv)\n  qed\n  \n  lemma g_to_list_impl: \"map_to_list \\<alpha> invar g_to_list\"\n  proof \n    fix m \n    assume I: \"invar m\"\n\n    have A: \"g_to_list m = iterate_to_list (iteratei m)\"\n      unfolding g_to_list_def iterate_to_list_def by simp\n\n    from iterate_to_list_correct [OF iteratei_correct[OF I]]\n    have set_l_eq: \"set (g_to_list m) = map_to_set (\\<alpha> m)\" and \n      dist_l: \"distinct (g_to_list m)\" unfolding A by simp_all\n\n    from dist_l show dist_fst_l: \"distinct (map fst (g_to_list m))\"\n      by (simp add: distinct_map set_l_eq map_to_set_def inj_on_def)\n    \n    from map_of_map_to_set[of \"(g_to_list m)\" \"\\<alpha> m\", OF dist_fst_l] set_l_eq\n    show \"map_of (g_to_list m) = \\<alpha> m\" by simp\n  qed\n\n  lemma g_list_to_map_impl: \"list_to_map \\<alpha> invar g_list_to_map\"\n  proof -\n    {\n      fix m0 l\n      assume \"invar m0\"\n      hence \"invar (foldl (\\<lambda>s (k,v). update k v s) m0 l) \\<and> \n        \\<alpha> (foldl (\\<lambda>s (k,v). update k v s) m0 l) = \\<alpha> m0 ++ map_of (rev l)\"\n      proof (induction l arbitrary: m0)\n        case Nil thus ?case by simp\n      next\n        case (Cons kv l)\n        obtain k v where [simp]: \"kv=(k,v)\" by (cases kv) auto\n        have \"invar (foldl (\\<lambda>s (k, v). update k v s) m0 (kv # l))\"\n          apply simp\n          apply (rule conjunct1[OF Cons.IH])\n          apply (simp add: update_correct Cons.prems)\n          done\n        moreover have \"\\<alpha> (foldl (\\<lambda>s (k, v). update k v s) m0 (kv # l)) =\n          \\<alpha> m0 ++ map_of (rev (kv # l))\"\n          apply simp\n          thm trans[OF conjunct2[OF Cons.IH]]\n          apply (rule trans[OF conjunct2[OF Cons.IH]])\n          apply (auto \n            simp: update_correct Cons.prems Map.map_add_def[abs_def]\n            split: option.split\n          )\n          done\n        ultimately show ?case\n          by simp\n      qed\n    } thus ?thesis\n      apply unfold_locales\n      unfolding g_list_to_map_def\n      apply (auto simp: empty_correct)\n      done\n  qed\n\n  lemma g_add_dj_impl: \"map_add_dj \\<alpha> invar g_add_dj\"\n  proof\n    fix m1 m2\n    assume \"invar m1\" \"invar m2\" and DJ: \"dom (\\<alpha> m1) \\<inter> dom (\\<alpha> m2) = {}\"\n\n    have A: \"g_add_dj m1 m2 = iterate_add_to_map m1 update_dj (iteratei m2)\"\n      unfolding g_add_dj_def iterate_add_to_map_def by simp\n    have \"\\<alpha> (g_add_dj m1 m2) = \\<alpha> m1 ++ \\<alpha> m2 \\<and> invar (g_add_dj m1 m2)\"\n      unfolding A\n      apply (rule \n        iterate_add_to_map_dj_correct[\n        of \\<alpha> invar update_dj m1 \"iteratei m2\" \"\\<alpha> m2\"])\n      apply unfold_locales []\n      apply fact\n      apply (rule iteratei_correct, fact)\n      using DJ apply (simp add: Int_ac)\n      done\n    thus \"\\<alpha> (g_add_dj m1 m2) = \\<alpha> m1 ++ \\<alpha> m2\" \"invar (g_add_dj m1 m2)\" by auto\n  qed\n  \n  lemma g_restrict_impl: \"map_restrict \\<alpha> invar \\<alpha> invar g_restrict\"\n  proof \n    fix m P\n    assume I: \"invar m\"\n\n    have AUX: \"\\<And>k v it \\<sigma>.\n       \\<lbrakk>it \\<subseteq> {(k, v). \\<alpha> m k = Some v}; \\<alpha> m k = Some v; (k, v) \\<notin> it;\n        {(k, v). \\<alpha> \\<sigma> k = Some v} = it \\<inter> Collect P\\<rbrakk>\n       \\<Longrightarrow> k \\<notin> dom (\\<alpha> \\<sigma>)\"\n    proof (rule ccontr, simp)\n      fix k v it \\<sigma>\n      assume \"k\\<in>dom (\\<alpha> \\<sigma>)\" \n      then obtain v' where \"\\<alpha> \\<sigma> k = Some v'\" by auto\n      moreover assume \"{(k, v). \\<alpha> \\<sigma> k = Some v} = it \\<inter> Collect P\"\n      ultimately have MEM: \"(k,v')\\<in>it\" by auto\n      moreover assume \"it \\<subseteq> {(k, v). \\<alpha> m k = Some v}\" and \"\\<alpha> m k = Some v\"\n      ultimately have \"v'=v\" by auto\n      moreover assume \"(k,v)\\<notin>it\"\n      moreover note MEM \n      ultimately show False by simp\n    qed\n\n    have \"\\<alpha> (g_restrict P m) = \\<alpha> m |` {k. \\<exists>v. \\<alpha> m k = Some v \\<and> P (k, v)} \\<and>\n      invar (g_restrict P m)\"\n      unfolding g_restrict_def\n      apply (rule_tac I=\"\\<lambda>it \\<sigma>. invar \\<sigma> \n        \\<and> map_to_set (\\<alpha> \\<sigma>) = it \\<inter> Collect P\"\n        in iterate_rule_insert_P)\n      apply (auto simp: I empty_correct update_dj_correct map_to_set_def AUX)\n      apply (auto split: split_if_asm)\n      apply (rule ext)\n      apply (auto simp: Map.restrict_map_def)\n      apply force\n      apply (rule ccontr)\n      apply force\n      done\n    thus \"\\<alpha> (g_restrict P m) = \\<alpha> m |` {k. \\<exists>v. \\<alpha> m k = Some v \\<and> P (k, v)}\"\n      \"invar (g_restrict P m)\" by auto\n  qed\n\n  \n\n\ncontext StdBasicOMapDefs \nbegin\n  definition \n    \"g_min m P \\<equiv> \n      iterateoi m (\\<lambda>\\<sigma>. \\<sigma> = None) (\\<lambda>x \\<sigma>. if P x then Some x else None) None\"\n\n  definition \n    \"g_max m P \\<equiv> \n      rev_iterateoi m (\\<lambda>\\<sigma>. \\<sigma> = None) (\\<lambda>x \\<sigma>. if P x then Some x else None) None\"\n\n  definition \"g_to_sorted_list m \\<equiv> rev_iterateo m (op #) []\"\n  definition \"g_to_rev_list m \\<equiv> iterateo m (op #) []\"\n\n  definition dflt_oops :: \"('k,'v,'s) omap_ops\" \n    where [icf_rec_def]:\n    \"dflt_oops \\<equiv> map_ops.extend dflt_ops\n      \\<lparr> \n        map_op_ordered_list_it = ordered_list_it,\n        map_op_rev_list_it = rev_list_it,\n        map_op_min = g_min,\n        map_op_max = g_max,\n        map_op_to_sorted_list = g_to_sorted_list,\n        map_op_to_rev_list = g_to_rev_list\n      \\<rparr>\"\n  local_setup {* Locale_Code.lc_decl_del @{term dflt_oops}*}\n\nend\n\ncontext StdBasicOMap \nbegin\n  lemma g_min_impl: \"map_min \\<alpha> invar g_min\"\n  proof \n    fix m P\n\n    assume I: \"invar m\"\n  \n    from iterateoi_correct[OF I]\n    have iti': \"map_iterator_linord (iterateoi m) (\\<alpha> m)\" by simp\n    note sel_correct = iterate_sel_no_map_map_linord_correct[OF iti', of P]\n\n    have A: \"g_min m P = iterate_sel_no_map (iterateoi m) P\"\n      unfolding g_min_def iterate_sel_no_map_def iterate_sel_def by simp\n  \n    { assume \"rel_of (\\<alpha> m) P \\<noteq> {}\"\n      with sel_correct \n      show \"g_min m P \\<in> Some ` rel_of (\\<alpha> m) P\"\n        unfolding A\n        by (auto simp add: image_iff rel_of_def)\n    }\n\n    { assume \"rel_of (\\<alpha> m) P = {}\"        \n       with sel_correct show \"g_min m P = None\"\n        unfolding A\n        by (auto simp add: image_iff rel_of_def)\n    }\n\n    { fix k v\n      assume \"(k, v) \\<in> rel_of (\\<alpha> m) P\"\n      with sel_correct show \"fst (the (g_min m P)) \\<le> k\"\n        unfolding A\n        by (auto simp add: image_iff rel_of_def)\n    }\n  qed\n\n  lemma g_max_impl: \"map_max \\<alpha> invar g_max\"\n  proof \n    fix m P\n\n    assume I: \"invar m\"\n  \n    from rev_iterateoi_correct[OF I]\n    have iti': \"map_iterator_rev_linord (rev_iterateoi m) (\\<alpha> m)\" by simp\n    note sel_correct = iterate_sel_no_map_map_rev_linord_correct[OF iti', of P]\n\n    have A: \"g_max m P = iterate_sel_no_map (rev_iterateoi m) P\"\n      unfolding g_max_def iterate_sel_no_map_def iterate_sel_def by simp\n  \n    { assume \"rel_of (\\<alpha> m) P \\<noteq> {}\"\n      with sel_correct \n      show \"g_max m P \\<in> Some ` rel_of (\\<alpha> m) P\"\n        unfolding A\n        by (auto simp add: image_iff rel_of_def)\n    }\n\n    { assume \"rel_of (\\<alpha> m) P = {}\"        \n       with sel_correct show \"g_max m P = None\"\n        unfolding A\n        by (auto simp add: image_iff rel_of_def)\n    }\n\n    { fix k v\n      assume \"(k, v) \\<in> rel_of (\\<alpha> m) P\"\n      with sel_correct show \"fst (the (g_max m P)) \\<ge> k\"\n        unfolding A\n        by (auto simp add: image_iff rel_of_def)\n    }\n  qed\n\n  lemma g_to_sorted_list_impl: \"map_to_sorted_list \\<alpha> invar g_to_sorted_list\"\n  proof \n    fix m\n    assume I: \"invar m\"\n    note iti = rev_iterateoi_correct[OF I]\n    from iterate_to_list_map_rev_linord_correct[OF iti]\n    show \"sorted (map fst (g_to_sorted_list m))\" \n         \"distinct (map fst (g_to_sorted_list m))\"\n         \"map_of (g_to_sorted_list m) = \\<alpha> m\" \n      unfolding g_to_sorted_list_def iterate_to_list_def by simp_all\n  qed\n\n  lemma g_to_rev_list_impl: \"map_to_rev_list \\<alpha> invar g_to_rev_list\"\n  proof \n    fix m\n    assume I: \"invar m\"\n    note iti = iterateoi_correct[OF I]\n    from iterate_to_list_map_linord_correct[OF iti]\n    show \"sorted (rev (map fst (g_to_rev_list m)))\" \n         \"distinct (map fst (g_to_rev_list m))\"\n         \"map_of (g_to_rev_list m) = \\<alpha> m\" \n      unfolding g_to_rev_list_def iterate_to_list_def \n      by (simp_all add: rev_map)\n  qed\n  \n  lemma dflt_oops_impl: \"StdOMap dflt_oops\"\n  proof -\n    interpret aux: StdMap dflt_ops by (rule dflt_ops_impl)\n\n    show ?thesis\n      apply (rule StdOMap_intro)\n      apply icf_locales\n      apply (simp_all add: icf_rec_unf)\n      apply (rule g_min_impl)\n      apply (rule g_max_impl)\n      apply (rule g_to_sorted_list_impl)\n      apply (rule g_to_rev_list_impl)\n      done\n  qed\n\nend\n\nlocale g_image_filter_defs_loc = \n  m1: StdMapDefs ops1 + \n  m2: StdMapDefs ops2\n  for ops1 :: \"('k1,'v1,'s1,'m1) map_ops_scheme\"\n  and ops2 :: \"('k2,'v2,'s2,'m2) map_ops_scheme\"\nbegin\n  definition \"g_image_filter f m1 \\<equiv> m1.iterate m1 (\\<lambda>kv \\<sigma>. case f kv of \n      None => \\<sigma>\n    | Some (k',v') => m2.update_dj k' v' \\<sigma>\n    ) (m2.empty ())\"\nend\n\nlocale g_image_filter_loc = g_image_filter_defs_loc ops1 ops2 + \n  m1: StdMap ops1 + \n  m2: StdMap ops2\n  for ops1 :: \"('k1,'v1,'s1,'m1) map_ops_scheme\"\n  and ops2 :: \"('k2,'v2,'s2,'m2) map_ops_scheme\"\nbegin\n  lemma g_image_filter_impl: \n    \"map_image_filter m1.\\<alpha> m1.invar m2.\\<alpha> m2.invar g_image_filter\"\n  proof \n    fix m k' v' and f :: \"('k1 \\<times> 'v1) \\<Rightarrow> ('k2 \\<times> 'v2) option\"\n    assume invar_m: \"m1.invar m\" and\n           unique_f: \"transforms_to_unique_keys (m1.\\<alpha> m) f\"\n    \n    have A: \"g_image_filter f m = \n      iterate_to_map m2.empty m2.update_dj (\n        set_iterator_image_filter f (m1.iteratei m))\" \n      unfolding g_image_filter_def iterate_to_map_alt_def \n        set_iterator_image_filter_def case_prod_beta\n      by simp\n  \n    from m1.iteratei_correct[OF invar_m] \n    have iti_m: \"map_iterator (m1.iteratei m) (m1.\\<alpha> m)\" by simp\n\n    from unique_f have inj_on_f: \"inj_on f (map_to_set (m1.\\<alpha> m) \\<inter> dom f)\"\n      unfolding transforms_to_unique_keys_def inj_on_def Ball_def map_to_set_def\n      by auto (metis option.inject)\n\n    def vP \\<equiv> \"\\<lambda>k v. \\<exists>k' v'. m1.\\<alpha> m k' = Some v' \\<and> f (k', v') = Some (k, v)\"\n    have vP_intro: \"\\<And>k v. (\\<exists>k' v'. m1.\\<alpha> m k' = Some v' \n        \\<and> f (k', v') = Some (k, v)) \\<longleftrightarrow> vP k v\"\n      unfolding vP_def by simp\n    { fix k v\n      have \"Eps_Opt (vP k) = Some v \\<longleftrightarrow> vP k v\"\n        using unique_f unfolding vP_def transforms_to_unique_keys_def \n        apply (rule_tac Eps_Opt_eq_Some)\n        apply (metis prod.inject option.inject)\n      done\n    } note Eps_vP_elim[simp] = this\n    have map_intro: \"{y. \\<exists>x. x \\<in> map_to_set (m1.\\<alpha> m) \\<and> f x = Some y} \n      = map_to_set (\\<lambda>k. Eps_Opt (vP k))\"\n      by (simp add: map_to_set_def vP_intro set_eq_iff split: prod.splits)\n\n    from set_iterator_image_filter_correct [OF iti_m, OF inj_on_f, \n      unfolded map_intro] \n    have iti_filter: \"map_iterator (set_iterator_image_filter f (m1.iteratei m))\n          (\\<lambda>k. Eps_Opt (vP k))\" by auto\n\n    have upd: \"map_update_dj m2.\\<alpha> m2.invar m2.update_dj\" by unfold_locales\n    have emp: \"map_empty m2.\\<alpha> m2.invar m2.empty\" by unfold_locales\n  \n    from iterate_to_map_correct[OF upd emp iti_filter] show\n      \"map_op_invar ops2 (g_image_filter f m) \\<and>\n          (map_op_\\<alpha> ops2 (g_image_filter f m) k' = Some v') =\n          (\\<exists>k v. map_op_\\<alpha> ops1 m k = Some v \\<and> f (k, v) = Some (k', v'))\"\n      unfolding A vP_def[symmetric]\n      by (simp add: vP_intro)\n  \n  qed\nend\n\nsublocale g_image_filter_loc \n  < map_image_filter m1.\\<alpha> m1.invar m2.\\<alpha> m2.invar g_image_filter\n  by (rule g_image_filter_impl)\n\n\nlocale g_value_image_filter_defs_loc = \n  m1: StdMapDefs ops1 + \n  m2: StdMapDefs ops2\n  for ops1 :: \"('k,'v1,'s1,'m1) map_ops_scheme\"\n  and ops2 :: \"('k,'v2,'s2,'m2) map_ops_scheme\"\nbegin\n  definition \"g_value_image_filter f m1 \\<equiv> m1.iterate m1 (\\<lambda>(k,v) \\<sigma>. \n    case f k v of \n      None => \\<sigma>\n    | Some v' => m2.update_dj k v' \\<sigma>\n    ) (m2.empty ())\"\n  \nend\n\n(* TODO: Move to Misc *)\nlemma restrict_map_dom_subset: \"\\<lbrakk> dom m \\<subseteq> R\\<rbrakk> \\<Longrightarrow> m|`R = m\"\n  apply (rule ext)\n  apply (auto simp: restrict_map_def)\n  apply (case_tac \"m x\")\n  apply auto\n  done\n\n\nlocale g_value_image_filter_loc = g_value_image_filter_defs_loc ops1 ops2 + \n  m1: StdMap ops1 + \n  m2: StdMap ops2\n  for ops1 :: \"('k,'v1,'s1,'m1) map_ops_scheme\"\n  and ops2 :: \"('k,'v2,'s2,'m2) map_ops_scheme\"\nbegin\n  lemma g_value_image_filter_impl: \n    \"map_value_image_filter m1.\\<alpha> m1.invar m2.\\<alpha> m2.invar g_value_image_filter\"\n    apply unfold_locales\n    unfolding g_value_image_filter_def\n    apply (rule_tac I=\"\\<lambda>it \\<sigma>. m2.invar \\<sigma> \n      \\<and> m2.\\<alpha> \\<sigma> = (\\<lambda>k. Option.bind (map_op_\\<alpha> ops1 m k) (f k)) |` it\"\n      in m1.old_iterate_rule_insert_P)\n\n    apply auto []\n    apply (auto simp: m2.empty_correct) []\n    defer\n    apply simp []\n    apply (rule restrict_map_dom_subset)\n    apply (auto) []\n    apply (case_tac \"m1.\\<alpha> m x\")\n    apply (auto) [2]\n\n    apply (auto split: option.split simp: m2.update_dj_correct intro!: ext)\n    apply (auto simp: restrict_map_def)\n    done\nend\n\nsublocale g_value_image_filter_loc \n  < map_value_image_filter m1.\\<alpha> m1.invar m2.\\<alpha> m2.invar g_value_image_filter\n  by (rule g_value_image_filter_impl)\n\n\nend\n\n", "meta": {"author": "andredidier", "repo": "phd", "sha": "113f7c8b360a3914a571db13d9513e313954f4b2", "save_path": "github-repos/isabelle/andredidier-phd", "path": "github-repos/isabelle/andredidier-phd/phd-113f7c8b360a3914a571db13d9513e313954f4b2/thesis/Collections/ICF/gen_algo/MapGA.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5583269796369905, "lm_q2_score": 0.5350984286266116, "lm_q1q2_score": 0.29875988946359583}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |                    May 2005               |\n            |                   June 2005  (modified)   |\n            |              September 2005  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |               November 2005  (modified)   |\n            |                  April 2006  (modified)   |\n            |                  March 2007  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2017         |\n            |                  April 2018  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory CSP_F_op_rep_par\nimports CSP_F_op_alpha_par CSP_T.CSP_T_op_rep_par\nbegin\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite UnionT and InterT.                 *)\n(*                  Union (B ` A) = (UN x:A. B x)                      *)\n(*                  Inter (B ` A) = (INT x:A. B x)                     *)\n\n(*\ndeclare Union_image_eq [simp del]\ndeclare Inter_image_eq [simp del]\n*)\n(* no simp rules in Isabelle 2017 \ndeclare Sup_image_eq [simp del]\ndeclare Inf_image_eq [simp del]\n*)\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite (notick | t = <>)                 *)\n(*                                                                     *)\n(*                  disj_not1: (~ P | Q) = (P --> Q)                   *)\n\ndeclare disj_not1 [simp del]\n\n(*============================================================*\n |                                                            |\n |            replicated alphabetized parallel                |\n |                                                            |\n *============================================================*)\n\n(*** Inductive_parallel ***)\n\nlemma in_failures_Inductive_parallel_lm1: \n       \"Y Int insert Tick (Ev ` snd a) Un\n        Union {Y Int insert Tick (Ev ` X) |X Y. EX P. ((P, X), Y) : set PXYs} =\n          Union {Ya Int insert Tick (Ev ` X) |X Ya.\n                 EX P. P = fst a & X = snd a & Ya = Y | ((P, X), Ya) : set PXYs}\"\nby (auto)\n\nlemma in_failures_Inductive_parallel_lm2: \n  \"((P, X), Y) : set s ==> X <= Union (snd ` fst ` set s)\"\n  apply (auto)\n(* not necessary for Isabelle 2017\napply (rule_tac x=\"((P, X), Y)\" in bexI)\nby (simp_all)\n*)\n  done\n\nlemma in_failures_Inductive_parallel_lm3:\n   \"Union {Y Int insert Tick (Ev ` X) |X Y. EX P. ((P, X), Y) : set zs} <=\n    insert Tick (Ev ` Union (snd ` fst ` set zs))\"\napply (rule)\napply (simp)\napply (elim conjE exE)\napply (simp)\napply (elim conjE disjE)\napply (simp)\napply (rule disjI2)\napply (auto)\napply (simp add: image_iff)\napply (rule_tac x=\"((P, X), Y)\" in bexI)\napply (auto)\ndone\n\nlemma in_failures_Inductive_parallel_lm4:\n   \"Union {Y Int insert Tick (Ev ` X) |X Y. EX P. ((P, X), Y) : set zs} Int\n    insert Tick (Ev ` Union (snd ` fst ` set zs))\n    = Union {Y Int insert Tick (Ev ` X) |X Y. EX P. ((P, X), Y) : set zs}\"\n  apply (rule Int_subset_eq)\n(* for Isabelle 2017 *)\napply (simp add: in_failures_Inductive_parallel_lm3[simplified])\ndone\n\n(* main *)\n\nlemma in_failures_Inductive_parallel_lm:\n \"PXs ~= [] --> (ALL f.\n   (f :f failures([||] PXs) M) =\n         (EX u. (sett(u) <= insert Tick (Ev ` Union (snd ` set PXs)) & \n          (EX Z. f = (u, Z) &\n          (EX PXYs. map fst PXYs = PXs &\n          (Z Int insert Tick (Ev ` Union (snd ` set PXs))\n           = Union {(Y Int insert Tick (Ev ` X))|X Y. EX P. ((P,X),Y) : set PXYs} &\n          (ALL P X Y. ((P,X),Y) : set PXYs --> ((u rest-tr X), Y) :f failures(P) M)))))))\"\napply (induct_tac PXs)\n\n(* case 0 *)\n apply (simp)\n\n(* case 1 *)\n apply (case_tac \"list = []\")\n apply (simp)\n apply (intro allI)\n apply (simp add: in_failures_Alpha_parallel)\n apply (simp add: in_failures)\n apply (rule iffI)\n (* => *)\n  apply (elim conjE exE)\n  apply (simp)\n  apply (erule disjE)\n\n   apply (rule_tac x=\"[(a,Y)]\" in exI)\n   apply (simp)\n\n    apply (rule conjI)\n    apply (simp add: Evset_def pair_eq_decompo)\n    apply (fast)\n    apply (intro allI impI)\n    apply (simp add: pair_eq_decompo)\n\n   apply (case_tac \"Tick ~: Z\")\n    apply (rule_tac x=\"[(a,Y)]\" in exI)\n    apply (simp add: Evset_def pair_eq_decompo)\n(*    apply (fast) *)\n   (* Tick : Z *)\n    apply (rule_tac x=\"[(a,insert Tick Y)]\" in exI)\n    apply (simp)\n\n    apply (simp add: rest_tr_Tick_sett)\n    apply (elim conjE exE)\n    apply (simp add: pair_eq_decompo)\n    apply (rule conjI)\n    apply (fast)\n    apply (rule proc_T2_T3, simp)\n    apply (simp)\n\n (* <= *)\n  apply (elim conjE exE)\n  apply (simp)\n  apply (subgoal_tac \"EX bb. PXYs=[(a,bb)]\")\n  apply (elim conjE exE)\n  apply (subgoal_tac \"aa rest-tr {} = <> | aa rest-tr {} = <Tick>\")\n  apply (erule disjE)\n\n   (* <> *)\n   apply (rule_tac x=\"bb\" in exI)\n   apply (rule_tac x=\"{}\" in exI)\n   apply (simp add: pair_eq_decompo)\n\n   (* <Tick> *)\n   apply (rule_tac x=\"bb\" in exI)\n   apply (rule_tac x=\"{}\" in exI)\n   apply (simp add: pair_eq_decompo)\n\n   apply (simp add: rest_tr_empty)\n   apply (force)\n\n(* step case *)\napply (simp add: in_failures_Alpha_parallel)\napply (intro allI impI)\napply (rule iffI)\n\n(* => *)\n apply (elim conjE exE, simp)\n apply (rule_tac x=\"(a,Y) # PXYs\" in exI)\n apply (simp add: pair_eq_decompo)\n apply (simp add: in_failures_Inductive_parallel_lm1)\n\n apply (intro allI impI)\n apply (drule_tac x=\"P\" in spec)\n apply (drule_tac x=\"X\" in spec)\n apply (drule_tac x=\"Ya\" in spec)\n apply (simp)\n apply (subgoal_tac \"X <= Union (snd ` set list)\")\n apply (simp add: rest_tr_of_rest_tr_subset)\n\n apply (rotate_tac -4)\n   apply (drule sym)\n(* for Isabelle 2017 *)\n apply (simp add: in_failures_Inductive_parallel_lm2[simplified])\n\n(* <= *)\n apply (simp)\n apply (elim conjE exE)\n\n apply (subgoal_tac \"EX bb zs. PXYs = (a, bb) # zs & map fst zs = list\")\n apply (elim conjE exE)\n apply (rule_tac x=\"bb\" in exI)\n apply (rule_tac x=\n    \"Union {Y Int insert Tick (Ev ` X) |X Y. EX P. ((P, X), Y) : set zs}\" in exI)\n apply (simp)\n apply (rule conjI)\n apply (simp add: pair_eq_decompo)\n apply (rotate_tac -1)\n apply (drule sym)\n apply (simp)\n (* Isabelle 2017 *)\n apply (simp add: in_failures_Inductive_parallel_lm4[simplified])\n apply (simp add: in_failures_Inductive_parallel_lm1[simplified])\n\n apply (rule_tac x=\"zs\" in exI)\n apply (rotate_tac -1)\n apply (drule sym)\n apply (simp add: in_failures_Inductive_parallel_lm4[simplified])\n\n apply (intro allI impI)\n apply (subgoal_tac \"X <= Union (snd ` set list)\")\n apply (simp add: rest_tr_of_rest_tr_subset)\n apply (simp add: in_failures_Inductive_parallel_lm2)\napply (auto)\ndone\n\n(*** remove ALL ***)\n\nlemma in_failures_Inductive_parallel:\n \"PXs ~= [] ==> \n   (f :f failures([||] PXs) M) =\n         (EX u. (sett(u) <= insert Tick (Ev ` Union (snd ` set PXs)) & \n          (EX Z. f = (u, Z) &\n          (EX PXYs. map fst PXYs = PXs &\n          (Z Int insert Tick (Ev ` Union (snd ` set PXs))\n           = Union {(Y Int insert Tick (Ev ` X))|X Y. EX P. ((P,X),Y) : set PXYs} &\n          (ALL P X Y. ((P,X),Y) : set PXYs --> ((u rest-tr X), Y) :f failures(P) M))))))\"\nby (simp add: in_failures_Inductive_parallel_lm)\n\n(*** Semantics for replicated alphabetized parallel on F ***)\n\nlemma failures_Inductive_parallel:\n  \"PXs ~= []\n   ==> failures([||] PXs) M =\n      {f. (EX u. (sett(u) <= insert Tick (Ev ` Union (snd ` set PXs)) & \n          (EX Z. f = (u, Z) &\n          (EX PXYs. map fst PXYs = PXs &\n          (Z Int insert Tick (Ev ` Union (snd ` set PXs))\n           = Union {(Y Int insert Tick (Ev ` X))|X Y. EX P. ((P,X),Y) : set PXYs} &\n          (ALL P X Y. ((P,X),Y) : set PXYs --> ((u rest-tr X), Y) :f failures(P) M))))))}f\"\napply (simp add: in_failures_Inductive_parallel[THEN sym])\ndone\n\n(************************************\n |              traces              |\n ************************************)\n\nlemma sett_in_failures_Inductive_parallel:\n  \"[| PXs ~= [] ; (t,X) :f failures([||] PXs) M |] \n   ==> sett t <= insert Tick (Ev ` Union (snd ` set PXs))\"\nby (simp add: in_failures_Inductive_parallel)\n\n(*---------------------------------------------------------*\n |        another expression of Inductive_parallel_eval          |\n *---------------------------------------------------------*)\n\nlemma in_failures_Inductive_parallel_nth:\n \"PXs ~= [] ==> \n   (f :f failures([||] PXs) M) =\n         (EX u. (sett(u) <= insert Tick (Ev ` Union (snd ` set PXs)) & \n          (EX Z. f = (u, Z) &\n          (EX Ys. length PXs = length Ys &\n          (Z Int insert Tick (Ev ` Union (snd ` set PXs))\n           = Union {((Ys!i) Int insert Tick (Ev ` (snd (PXs!i))))|i. i < length PXs} &\n          (ALL i. i < length PXs --> ((u rest-tr (snd (PXs!i))), Ys!i) :f \n            failures(fst (PXs!i)) M))))))\"\napply (simp add: in_failures_Inductive_parallel)\napply (simp add: set_nth)\napply (rule iffI)\n\n(* => *)\n apply (elim conjE exE)\n apply (simp)\n apply (rule_tac x=\"map snd PXYs\" in exI)\n apply (simp)\n apply (rotate_tac 3)\n apply (drule sym)\n apply (simp)\n apply (rule conjI)\n apply (simp add: pair_eq_decompo)\n\n apply (rule equalityI)\n (* <= *)\n  apply (rule)\n  apply (simp)\n  apply (elim conjE exE)\n  apply (simp)\n  apply (elim conjE disjE)\n   apply (simp)\n   apply (rule_tac x=\"map snd PXYs ! i Int\n                      insert Tick (Ev ` snd (map fst PXYs ! i))\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"i\" in exI)\n   apply (simp)\n\n   apply (rule_tac x=\"map snd PXYs ! i Int\n                      insert Tick (Ev ` snd (map fst PXYs ! i))\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"i\" in exI)\n   apply (simp)\n\n (* => *)\n  apply (rule)\n  apply (simp)\n  apply (elim conjE exE)\n  apply (simp)\n  apply (elim conjE disjE)\n   apply (simp)\n   apply (rule_tac x=\n     \"(snd (PXYs ! i)) Int insert Tick (Ev ` snd (fst (PXYs ! i)))\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"snd (fst (PXYs ! i))\" in exI)\n   apply (rule_tac x=\"snd (PXYs ! i)\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"i\" in exI)\n   apply (simp)\n\n   apply (rule_tac x=\n     \"(snd (PXYs ! i)) Int insert Tick (Ev ` snd (fst (PXYs ! i)))\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"snd (fst (PXYs ! i))\" in exI)\n   apply (rule_tac x=\"snd (PXYs ! i)\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"i\" in exI)\n   apply (simp)\n\n  apply (intro allI impI)\n  apply (drule_tac x=\"fst (fst (PXYs ! i))\" in spec)\n  apply (drule_tac x=\"snd (fst (PXYs ! i))\" in spec)\n  apply (drule_tac x=\"snd (PXYs ! i)\" in spec)\n  apply (simp)\n  apply (fast)\n\n (* => *)\n apply (elim conjE exE)\n apply (simp)\n apply (rule_tac x=\"zip PXs Ys\" in exI)\n apply (simp add: map_fst_zip_eq)\n\n apply (rule conjI)\n apply (simp add: pair_eq_decompo)\n\n apply (rule equalityI)\n (* <= *)\n  apply (rule)\n  apply (simp)\n  apply (elim conjE exE)\n  apply (simp)\n  apply (elim conjE disjE)\n   apply (simp)\n   apply (rule_tac x=\"Ys ! i Int insert Tick (Ev ` snd (PXs ! i))\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"snd (PXs ! i)\" in exI)\n   apply (rule_tac x=\"Ys ! i\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"i\" in exI)\n   apply (simp)\n\n   apply (rule_tac x=\"Ys ! i Int insert Tick (Ev ` snd (PXs ! i))\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"snd (PXs ! i)\" in exI)\n   apply (rule_tac x=\"Ys ! i\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"i\" in exI)\n   apply (simp)\n\n (* => *)\n  apply (rule)\n  apply (simp)\n  apply (elim conjE exE)\n  apply (simp)\n  apply (elim conjE disjE)\n   apply (simp)\n   apply (rule_tac x=\"Ys ! i Int insert Tick (Ev ` snd (PXs ! i))\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"i\" in exI)\n   apply (simp)\n\n   apply (rule_tac x=\"Ys ! i Int insert Tick (Ev ` snd (PXs ! i))\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"i\" in exI)\n   apply (simp)\n\n  apply (intro allI impI)\n  apply (elim conjE exE)\n  apply (drule_tac x=\"i\" in spec)\n  apply (simp add: pair_eq_decompo)\ndone\n\n(*============================================================*\n |                                                            |\n |              indexed alphabetized parallel                 |\n |                                                            |\n *============================================================*)\n\n(*** failures Inductive_parallel ***)\n\nlemma in_failures_Rep_parallel_lm1:\n  \"[| Is isListOf I ; length Ys = length Is |] ==>\n    Union {(Ys ! i Int insert Tick (Ev ` snd (map PXf Is ! i))) |i. i < length Ys} =\n    Union {(Ys ! (THE n. Is ! n = i & n < length Is) Int\n            insert Tick (Ev ` snd (PXf i))) | i. i : I}\"\napply (rule)\n\n (* <= *)\n apply (rule)\n apply (simp)\n apply (elim conjE exE)\n apply (rule_tac x=\n   \"Ys ! (THE n. Is ! n = (Is ! i) & n < length Is) Int\n    insert Tick (Ev ` snd (PXf (Is ! i)))\" in exI)\n apply (simp add: isListOf_THE_nth)\n apply (rule_tac x=\"(Is ! i)\" in exI)\n apply (simp add: isListOf_THE_nth)\n apply (simp add: isListOf_nth_in_index)\n\n (* => *)\n apply (rule)\n apply (simp)\n apply (elim conjE exE)\n apply (simp)\n apply (erule isListOf_index_to_nthE)\n apply (drule_tac x=\"i\" in bspec, simp)\n apply (elim conjE exE, simp)\n apply (simp add: isListOf_THE_nth)\n apply (rule_tac x=\n   \"Ys ! n Int insert Tick (Ev ` snd (PXf (Is ! n)))\" in exI)\n apply (simp)\n apply (rule_tac x=\"n\" in exI)\n apply (simp)\ndone\n\nlemma in_failures_Rep_parallel_lm2:\n  \"Is isListOf I ==>\n   Union {(Yf i Int insert Tick (Ev ` snd (PXf i))) |i. i : I} =\n   Union {(map Yf Is ! i Int insert Tick (Ev ` snd (map PXf Is ! i))) |i. i < length Is}\"\napply (rule)\n\n (* <= *)\n apply (rule)\n apply (simp)\n apply (elim conjE exE)\n apply (erule isListOf_index_to_nthE)\n apply (drule_tac x=\"i\" in bspec, simp)\n apply (elim conjE exE, simp)\n apply (rule_tac x=\n   \"map Yf Is ! n Int insert Tick (Ev ` snd (map PXf Is ! n))\" in exI)\n apply (simp)\n apply (rule_tac x=\"n\" in exI)\n apply (simp)\n\n (* => *)\n apply (rule)\n apply (simp)\n apply (elim conjE exE)\n apply (rule_tac x= \"Yf (Is!i) Int insert Tick (Ev ` snd (PXf (Is!i)))\" in exI)\n apply (simp)\n apply (rule_tac x=\"(Is!i)\" in exI)\n apply (simp add: isListOf_nth_in_index)\ndone\n\nlemma in_failures_Rep_parallel:\n  \"[| I ~= {} ; finite I |]\n   ==> (f :f failures ([||]:I PXf) M) =\n         (EX u. (sett(u) <= insert Tick (Ev ` Union (snd ` PXf ` I)) & \n          (EX Z. f = (u, Z) &\n          (EX Yf. \n          (Z Int insert Tick (Ev ` Union (snd ` PXf ` I))\n           = Union {((Yf i) Int insert Tick (Ev ` (snd (PXf i))))|i. i : I} &\n          (ALL i:I. ((u rest-tr (snd (PXf i))), Yf i) :f failures(fst (PXf i)) M))))))\"\napply (simp add: Rep_parallel_def)\napply (subgoal_tac \"EX Is. Is isListOf I\")\napply (elim conjE exE)\napply (subgoal_tac \"(map PXf (SOME Is. Is isListOf I)) ~= []\")\napply (simp add: in_failures_Inductive_parallel_nth)\napply (rule someI2)\n apply (simp)\n apply (rule iffI)\n\n  (* => *)\n  apply (elim conjE exE)\n  apply (rename_tac Is' Is u Z Ys)\n  apply (rule_tac x=\"u\" in exI)\n  apply (simp add: isListOf_set_eq)\n  apply (rule_tac x= \"(%i. (Ys!(THE n. (Is!n) = i & n<length Is)))\" in exI)\n  apply (rule conjI)\n  apply (simp add: in_failures_Rep_parallel_lm1)\n  apply (rule ballI)\n\n  apply (rotate_tac 4)\n  apply (erule isListOf_index_to_nthE)\n  apply (drule_tac x=\"i\" in bspec, simp)\n  apply (elim conjE exE, simp)\n\n  apply (rotate_tac 2)\n  apply (drule sym)\n  apply (simp add: isListOf_THE_nth)\n\n  (* <= *)\n  apply (elim conjE exE)\n  apply (rename_tac Is' Is u Z Yf)\n  apply (rule_tac x=\"u\" in exI)\n  apply (simp add: isListOf_set_eq)\n  apply (rule_tac x= \"map Yf Is\" in exI)\n  apply (simp)\n  apply (rule conjI)\n  apply (rule in_failures_Rep_parallel_lm2, simp)\n  apply (intro allI impI)\n  apply (drule_tac x=\"Is ! i\" in bspec)\n  apply (simp add: isListOf_nth_in_index)\n  apply (simp)\n\n apply (rule someI2)\n apply (simp)\n apply (simp add: isListOf_nonemptyset)\n\napply (simp add: isListOf_EX)\ndone\n\nlemmas in_failures_par = in_failures_Alpha_parallel\n                         in_failures_Inductive_parallel\n                         in_failures_Rep_parallel\n\n(*** Semantics for indexed alphabetized parallel on F ***)\n\nlemma failures_Rep_parallel:\n  \"[| I ~= {} ; finite I |]\n   ==> failures ([||]:I PXf) M =\n      {f. (EX u. (sett(u) <= insert Tick (Ev ` Union (snd ` PXf ` I)) & \n          (EX Z. f = (u, Z) &\n          (EX Yf. \n          (Z Int insert Tick (Ev ` Union (snd ` PXf ` I))\n           = Union {((Yf i) Int insert Tick (Ev ` (snd (PXf i))))|i. i : I} &\n          (ALL i:I. ((u rest-tr (snd (PXf i))), Yf i) :f failures(fst (PXf i)) M))))))}f\"\n(* for Isabelle 2017 *)\n  apply (simp add: in_failures_Rep_parallel[simplified, THEN sym])\ndone\n\n(************************************\n |              traces              |\n ************************************)\n\nlemma sett_in_failures_Rep_parallel:\n  \"[| I ~= {} ; finite I ; (t,X) :f failures([||]:I PXf) M |] \n   ==> sett t <= insert Tick (Ev ` Union (snd ` PXf ` I))\"\nby (simp add: in_failures_Rep_parallel)\n\n(****************** to add it again ******************)\n\ndeclare disj_not1      [simp]\n(*\ndeclare Union_image_eq [simp]\ndeclare Inter_image_eq [simp]\n*)\n(*\ndeclare Sup_image_eq [simp]\ndeclare Inf_image_eq [simp]\n*)\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/CSP_F/CSP_F_op_rep_par.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5583269796369904, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.29875988946359566}}
{"text": "(* @TAG(OTHER_LGPL) *)\n\n(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      Closure.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2006-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection \"Experiments with Closures\"\n\ntheory Closure\nimports \"../Hoare\"\nbegin\n\n\ndefinition\n\"callClosure upd cl = Seq (Basic (upd (fst cl))) (Call (snd cl))\"\n\n\ndefinition\n\"dynCallClosure init upd cl return c =\n  DynCom (\\<lambda>s. call (upd (fst (cl s)) \\<circ> init) (snd (cl s)) return c)\"\n\n\n\n\n\nlemma dynCallClosure_sound:\nassumes adapt: \n  \"P \\<subseteq> {s. \\<exists>P' Q' A'. \\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F \\<^esub> P' (callClosure upd (cl s)) Q',A' \\<and>\n                  init s \\<in> P' \\<and> \n                  (\\<forall>t \\<in> Q'. return s t \\<in> R s t) \\<and>\n                  (\\<forall>t \\<in> A'. return s t \\<in> A)}\"\nassumes res: \"\\<forall>s t n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nshows\n\"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F \\<^esub>P (dynCallClosure init upd cl return c) Q,A\"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P Call p Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile> \\<langle>dynCallClosure init upd cl return c,Normal s\\<rangle> =n\\<Rightarrow> t\" \n  from execn.Basic [where f=\"(upd (fst (cl s)))\" and s=\"(init s)\"]\n  have exec_upd: \"\\<Gamma>\\<turnstile>\\<langle>Basic (upd (fst (cl s))),Normal (init s)\\<rangle> =n\\<Rightarrow> \n             Normal (((upd (fst (cl s))) \\<circ> init) s)\"\n      by auto\n  assume P: \"s \\<in> P\"\n  from P adapt obtain P' Q' A'\n      where \n      valid: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F \\<^esub> P' (callClosure upd (cl s)) Q',A'\" and\n      init_P': \"init s \\<in> P'\"  and\n      R: \"(\\<forall>t \\<in> Q'. return s t \\<in> R s t)\" and\n      A: \"(\\<forall>t \\<in> A'. return s t \\<in> A)\"\n      by auto\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from exec [simplified dynCallClosure_def]\n  have exec_call:\n      \"\\<Gamma>\\<turnstile>\\<langle>call (upd (fst (cl s)) \\<circ> init) (snd (cl s)) return c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n    by cases\n  then\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: execn_call_Normal_elim)\n    fix bdy m t'\n    assume bdy: \"\\<Gamma> (snd (cl s)) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal ((upd (fst (cl s)) \\<circ> init) s)\\<rangle> =m\\<Rightarrow> Normal t'\" \n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> =Suc m\\<Rightarrow> t\"\n    assume n: \"n = Suc m\"\n    have \"\\<Gamma>\\<turnstile>\\<langle>Basic init,Normal s\\<rangle> =m\\<Rightarrow> Normal (init s)\" \n      by (rule execn.Basic)\n    from bdy exec_body \n    have exec_callC:\n      \"\\<Gamma>\\<turnstile>\\<langle>Call (snd (cl s)),Normal ((upd (fst (cl s)) \\<circ> init) s)\\<rangle> =Suc m\\<Rightarrow> Normal t'\"\n      by (rule execn.Call)\n    from execn.Seq [OF exec_upd [simplified n]exec_callC]\n    have exec_closure: \"\\<Gamma>\\<turnstile> \\<langle>callClosure upd (cl s),Normal (init s)\\<rangle> =n\\<Rightarrow> Normal t'\"\n      by (simp add: callClosure_def n)\n    from cnvalidD [OF valid [rule_format] ctxt exec_closure init_P']\n    have \"t' \\<in> Q'\"\n      by auto\n    with R have \"return s t' \\<in> R s t'\"\n      by auto\n    from cnvalidD [OF res [rule_format] ctxt exec_c [simplified n[symmetric]] this\n         t_notin_F]\n    show ?thesis\n      by auto\n  next\n    fix bdy m t'\n    assume bdy: \"\\<Gamma> (snd (cl s)) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal ((upd (fst (cl s)) \\<circ> init) s)\\<rangle> =m\\<Rightarrow> Abrupt t'\" \n    assume t: \"t=Abrupt (return s t')\"\n    assume n: \"n = Suc m\"\n    from bdy exec_body \n    have exec_callC:\n      \"\\<Gamma>\\<turnstile>\\<langle>Call (snd (cl s)),Normal ((upd (fst (cl s)) \\<circ> init) s)\\<rangle> =Suc m\\<Rightarrow> Abrupt t'\"\n      by (rule execn.Call)\n    from execn.Seq [OF exec_upd [simplified n] exec_callC]\n    have exec_closure: \"\\<Gamma>\\<turnstile> \\<langle>callClosure upd (cl s),Normal (init s)\\<rangle> =n\\<Rightarrow> Abrupt t'\"\n      by (simp add: callClosure_def n)\n\n    from cnvalidD [OF valid [rule_format] ctxt exec_closure init_P']\n    have \"t' \\<in> A'\"\n      by auto\n    with A have \"return s t' \\<in> A\"\n      by auto\n    with t show ?thesis\n      by auto\n  next\n    fix bdy m f\n    assume bdy: \"\\<Gamma> (snd (cl s)) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal ((upd (fst (cl s)) \\<circ> init) s)\\<rangle> =m\\<Rightarrow> Fault f\" \n    assume t: \"t=Fault f\"\n    assume n: \"n = Suc m\"\n    from bdy exec_body \n    have exec_callC:\n      \"\\<Gamma>\\<turnstile>\\<langle>Call (snd (cl s)),Normal ((upd (fst (cl s)) \\<circ> init) s)\\<rangle> =Suc m\\<Rightarrow> Fault f\"\n      by (rule execn.Call)\n    from execn.Seq [OF exec_upd [simplified n] exec_callC]\n    have exec_closure: \"\\<Gamma>\\<turnstile> \\<langle>callClosure upd (cl s),Normal (init s)\\<rangle> =n\\<Rightarrow> Fault f\"\n      by (simp add: callClosure_def n)\n    from cnvalidD [OF valid [rule_format] ctxt exec_closure init_P'] t_notin_F t\n    have False\n      by auto\n    thus ?thesis ..\n  next\n    fix bdy m \n    assume bdy: \"\\<Gamma> (snd (cl s)) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal ((upd (fst (cl s)) \\<circ> init) s)\\<rangle> =m\\<Rightarrow> Stuck\" \n    assume t: \"t=Stuck\"\n    assume n: \"n = Suc m\"\n    from execn.Basic [where f=\"(upd (fst (cl s)))\" and s=\"(init s)\"]\n    have exec_upd: \"\\<Gamma>\\<turnstile>\\<langle>Basic (upd (fst (cl s))),Normal (init s)\\<rangle> =Suc m\\<Rightarrow> \n             Normal (((upd (fst (cl s))) \\<circ> init) s)\"\n      by auto\n    from bdy exec_body \n    have exec_callC:\n      \"\\<Gamma>\\<turnstile>\\<langle>Call (snd (cl s)),Normal ((upd (fst (cl s)) \\<circ> init) s)\\<rangle> =Suc m\\<Rightarrow> Stuck\"\n      by (rule execn.Call)\n    from execn.Seq [OF exec_upd [simplified n] exec_callC]\n    have exec_closure: \"\\<Gamma>\\<turnstile> \\<langle>callClosure upd (cl s),Normal (init s)\\<rangle> =n\\<Rightarrow> Stuck\"\n      by (simp add: callClosure_def n)\n    from cnvalidD [OF valid [rule_format] ctxt exec_closure init_P'] t_notin_F t\n    have False\n      by auto\n    thus ?thesis ..\n  next\n    fix m\n    assume no_bdy: \"\\<Gamma> (snd (cl s)) = None\"\n    assume t: \"t=Stuck\"\n    assume n: \"n = Suc m\"\n    from no_bdy  \n    have exec_callC:\n      \"\\<Gamma>\\<turnstile>\\<langle>Call (snd (cl s)),Normal ((upd (fst (cl s)) \\<circ> init) s)\\<rangle> =Suc m\\<Rightarrow> Stuck\"\n      by (rule execn.CallUndefined)\n    from execn.Seq [OF exec_upd [simplified n]exec_callC]\n    have exec_closure: \"\\<Gamma>\\<turnstile> \\<langle>callClosure upd (cl s),Normal (init s)\\<rangle> =n\\<Rightarrow> Stuck\"\n      by (simp add: callClosure_def n)\n    from cnvalidD [OF valid [rule_format] ctxt exec_closure init_P'] t_notin_F t\n    have False\n      by auto\n    thus ?thesis ..\n  qed\nqed\n\n      \nlemma dynCallClosure:\nassumes adapt: \"P \\<subseteq> {s. \\<exists>P' Q' A'. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub> P' (callClosure upd (cl s)) Q',A' \\<and>\n                  init s \\<in> P' \\<and> \n                  (\\<forall>t \\<in> Q'. return s t \\<in> R s t) \\<and>\n                  (\\<forall>t \\<in> A'. return s t \\<in> A)}\"\nassumes res: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nshows\n\"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P (dynCallClosure init upd cl return c) Q,A\"\n  apply (rule hoare_complete')\n  apply (rule allI)\n  apply (rule dynCallClosure_sound [where R=R])\n  using adapt\n  apply (blast intro: hoare_cnvalid)\n  using res\n  apply (blast intro: hoare_cnvalid)\n  done\n\n\n\nlemma dynCallClosureFix:\nassumes adapt: \"P \\<subseteq> {s. \\<exists>Z. cl'=cl s \\<and>   \n                  init s \\<in> P' Z \\<and> \n                  (\\<forall>t \\<in> Q' Z. return s t \\<in> R s t) \\<and>\n                  (\\<forall>t \\<in> A' Z. return s t \\<in> A)}\"\nassumes res: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub> (P' Z) (callClosure upd cl') (Q' Z),(A' Z)\"\nshows\n\"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P (dynCallClosure init upd cl return c) Q,A\"\n  apply (rule dynCallClosure [OF _ res])\n  using adapt spec\n  apply clarsimp\n  apply (drule (1) in_subsetD)\n  apply clarsimp\n  apply (rule_tac x=\"P' Z\" in exI)\n  apply (rule_tac x=\"Q' Z\" in exI)\n  apply (rule_tac x=\"A' Z\" in exI)\n  apply blast\n  done\n\n\nlemma conseq_extract_pre:\n             \"\\<lbrakk>\\<forall>s \\<in> P. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s}) c Q,A\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule hoarep.Conseq)\n  apply clarify\n  apply (rule_tac x=\"{s}\" in exI)  \n  apply (rule_tac x=\"Q\" in exI)  \n  apply (rule_tac x=\"A\" in exI)  \n  by simp\n\n\n\nlemma app_closure_sound:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>P' Q' A'. \\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P' (callClosure upd (e',p)) Q',A' \\<and>\n                           upd x s \\<in> P' \\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A}\"\n  assumes ap: \"upd e = upd e' \\<circ> upd x\"     \n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (callClosure upd (e,p)) Q,A\"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P Call p Q,A\"\n  assume exec_e: \"\\<Gamma>\\<turnstile> \\<langle>callClosure upd (e, p),Normal s\\<rangle> =n\\<Rightarrow> t\" \n  assume P: \"s \\<in> P\" \n  assume t: \"t \\<notin> Fault ` F\"\n  from P adapt obtain P' Q' A'\n    where \n    valid: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F \\<^esub> P' (callClosure upd (e',p)) Q',A'\" and\n    init_P': \"upd x s \\<in> P'\"  and\n    Q: \"Q' \\<subseteq> Q\" and\n    A: \"A' \\<subseteq> A\"\n    by auto\n  from exec_e [simplified callClosure_def] obtain s'\n    where\n    exec_e: \"\\<Gamma>\\<turnstile> \\<langle>Basic (upd (fst (e, p))),Normal s\\<rangle> =n\\<Rightarrow> s'\"and\n    exec_p: \"\\<Gamma>\\<turnstile> \\<langle>Call (snd (e, p)),s'\\<rangle> =n\\<Rightarrow> t\"\n    by cases\n  from exec_e [simplified]\n  have s': \"s'=Normal (upd e s)\"\n    by cases simp\n  from ap obtain s'' where\n   s'': \"upd x s = s''\" and upd_e': \"upd e' s''=upd e s\" \n    by auto\n  from ap s' execn.Basic [where f=\"(upd (fst (e', p)))\" and s=\"upd x s\" and \\<Gamma>=\\<Gamma>]\n  have exec_e': \"\\<Gamma>\\<turnstile> \\<langle>Basic (upd (fst (e', p))),Normal (upd x s)\\<rangle> =n\\<Rightarrow> s'\"\n    by simp\n  with exec_p\n  have \"\\<Gamma>\\<turnstile> \\<langle>callClosure upd (e', p),Normal (upd x s)\\<rangle> =n\\<Rightarrow> t\"\n    by (auto simp add: callClosure_def intro: execn.Seq)\n  from cnvalidD [OF valid [rule_format] ctxt this init_P'] t Q A\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    by auto\nqed\n\nlemma app_closure:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>P' Q' A'. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' (callClosure upd (e',p)) Q',A' \\<and>\n                           upd x s \\<in> P' \\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A}\"\n  assumes ap: \"upd e = upd e' \\<circ> upd x\"     \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (callClosure upd (e,p)) Q,A\"\n  apply (rule hoare_complete')\n  apply (rule allI)\n  apply (rule app_closure_sound [where x=x and e'=e', OF _ ap])\n  using adapt\n  apply (blast intro: hoare_cnvalid)\n  done\n\nlemma app_closure_spec:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. upd x s \\<in> P' Z \\<and> Q' Z \\<subseteq> Q \\<and> A' Z \\<subseteq> A}\"\n  assumes ap: \"upd e = upd e' \\<circ> upd x\"     \n  assumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) (callClosure upd (e',p)) (Q' Z),(A' Z)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (callClosure upd (e,p)) Q,A\"\n  apply (rule app_closure [OF _ ap])\n  apply clarsimp\n  using adapt spec\n  apply -\n  apply (drule (1) in_subsetD)\n  apply clarsimp\n  apply (rule_tac x=\"P' Z\" in exI)\n  apply (rule_tac x=\"Q' Z\" in exI)\n  apply (rule_tac x=\"A' Z\" in exI)\n  apply blast\n  done\n\ntext {* Implementation of closures as association lists. *}\n\ndefinition \"gen_upd var es s = foldl (\\<lambda>s (x,i). the (var x) i s) s es\"\ndefinition \"ap es c \\<equiv> (es@fst c,snd c)\"\n\nlemma gen_upd_app: \"\\<And>es'. gen_upd var (es@es') = gen_upd var es' \\<circ> gen_upd var es\"\n  apply (induct es)\n  apply  (rule ext)\n  apply  (simp add: gen_upd_def)\n  apply (rule ext)\n  apply (simp add: gen_upd_def)\n  done\n\nlemma gen_upd_ap:\n  \"gen_upd var (fst (ap es (es',p))) = gen_upd var es' \\<circ> gen_upd var es\"\n  by (simp add: gen_upd_app ap_def)\n\nlemma ap_closure:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>P' Q' A'. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' (callClosure (gen_upd var) c) Q',A' \\<and>\n                           gen_upd var es s \\<in> P' \\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (callClosure (gen_upd var) (ap es c)) Q,A\"\nproof -\n  obtain es' p where c: \"c=(es',p)\"\n    by (cases c) \n  have \"gen_upd var (fst (ap es (es',p))) = gen_upd var es' \\<circ> gen_upd var es\"\n    by (simp add: gen_upd_ap)\n  from app_closure [OF adapt [simplified c] this]\n  show ?thesis\n    by (simp add: c ap_def)\nqed\n\n\nlemma ap_closure_spec:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. gen_upd var es s \\<in> P' Z \\<and> Q' Z \\<subseteq> Q \\<and> A' Z \\<subseteq> A}\"\n  assumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) (callClosure (gen_upd var) c) (Q' Z),(A' Z)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (callClosure (gen_upd var) (ap es c)) Q,A\"\nproof -\n  obtain es' p where c: \"c=(es',p)\"\n    by (cases c) \n  have \"gen_upd var (fst (ap es (es',p))) = gen_upd var es' \\<circ> gen_upd var es\"\n    by (simp add: gen_upd_ap)\n  from app_closure_spec [OF adapt [simplified c] this spec [simplified c]]\n  show ?thesis\n    by (simp add: c ap_def)\nqed\n\nend", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/c-parser/Simpl/ex/Closure.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5926665999540698, "lm_q2_score": 0.5039061705290806, "lm_q1q2_score": 0.2986483567833459}}
{"text": "header {* Tagging of Terms *}\ntheory Autoref_Tagging\nimports \"../Lib/Refine_Lib\" \nbegin\ntext {*\n  We provide a mechanism to tag terms, that supports relator annotations,\n  and introduces tags to protect operations, function applications, and \n  abstractions from automatic beta and eta conversions.\n*}\n\n\nML {*\n  structure Autoref_Tag_Defs = Named_Thms (\n    val name = @{binding autoref_tag_defs}\n    val description = \"Autoref: Definitions of internal tags\"\n  )\n*}\nsetup Autoref_Tag_Defs.setup\n\n\ntext {* General protection tag *}\ndefinition PROTECT where [simp, autoref_tag_defs]: \"PROTECT x \\<equiv> x\"\n\ntext {* General annotation tag *}\ntypedecl annot\ndefinition ANNOT :: \"'a \\<Rightarrow> annot \\<Rightarrow> 'a\" \n  where [simp, autoref_tag_defs]: \"ANNOT x a \\<equiv> x\"\n\ntext {* Operation-tag, Autoref does not look beyond this *}\ndefinition OP where [simp, autoref_tag_defs]: \"OP x \\<equiv> x\"\n\ntext {* Protected function application *}\ndefinition APP (infixl \"$\" 900) where [simp, autoref_tag_defs]: \"f$a \\<equiv> f a\"\n\ntext {* Protected abstraction *}\nabbreviation ABS :: \"('a\\<Rightarrow>'b)\\<Rightarrow>'a\\<Rightarrow>'b\" (binder \"\\<lambda>''\" 10)\n  where \"ABS f \\<equiv> PROTECT (\\<lambda>x. PROTECT (f x))\"\n\n\nlemma ABS_beta: \"(\\<lambda>'x. f x)$x \\<equiv> f x\" by simp\nlemma ABS_eta: \"\\<lambda>'x. (f$x) \\<equiv> f\" by simp\n\ntext {* This tag is used to highlight failures during operation \n  identification *}\ndefinition \"ID_FAIL x \\<equiv> x\"\nnotation (output) ID_FAIL (\"FAIL *** _ ***\")\n\n\ntext {* Relator annotation *}\nconsts rel_annot :: \"('c\\<times>'a) set \\<Rightarrow> annot\"\nabbreviation rel_ANNOT :: \"'a \\<Rightarrow> ('c \\<times> 'a) set \\<Rightarrow> 'a\" (infix \":::\" 10)\n  where \"t:::R \\<equiv> ANNOT t (rel_annot R)\"\n\nlemma rel_ANNOT_eq: \"t \\<equiv> t:::R\" by simp\n\ntext {* Indirect annotation *}\ntypedecl rel_name\nconsts ind_annot :: \"rel_name \\<Rightarrow> annot\"\nabbreviation ind_ANNOT :: \"'a \\<Rightarrow> rel_name \\<Rightarrow> 'a\" (infix \"::#\" 10)\n  where \"t::#s \\<equiv> ANNOT t (ind_annot s)\"\n\n\n\n\n\nML {*\n  signature AUTOREF_TAGGING = sig\n    val term_of_tagged: term -> term\n    val is_valid_tagged: term -> bool\n\n    val mk_APP: term -> term -> term\n    val mk_OP: term -> term\n    val lambda': string * typ -> term -> term\n\n    val list_APP: term * term list -> term\n    val strip_app: term -> term * term list\n\n    val untag_conv: Proof.context -> conv\n\n    val mk_APP_conv: conv\n    val mk_OP_conv: conv\n    val mk_ABS_conv: Proof.context -> conv\n    val mk_ANNOT_conv: cterm -> conv\n    val mk_rel_ANNOT_conv: cterm -> conv\n\n    val ABS_beta_conv: Proof.context -> conv\n\n    val rhs_conv: (Proof.context -> conv) -> Proof.context -> conv\n  end\n\n\n  structure Autoref_Tagging :AUTOREF_TAGGING = struct\n    fun term_of_tagged (Free v) = Free v\n      | term_of_tagged (Var v) = Var v\n      | term_of_tagged (Bound i) = Bound i\n      | term_of_tagged @{mpat \"OP ?t\"} = t\n      | term_of_tagged @{mpat \"ANNOT ?t _\"} = term_of_tagged t\n      | term_of_tagged @{mpat \"?f$?x\"} = term_of_tagged f $ term_of_tagged x\n      | term_of_tagged @{mpat \"PROTECT (\\<lambda>x. PROTECT ?t)\"} \n        = Abs (x,x_T,term_of_tagged t)\n      | term_of_tagged @{mpat (typs) \"PROTECT (PROTECT::?'v_T\\<Rightarrow>_)\"} \n        = Abs (\"x\",T,Bound 0)\n      | term_of_tagged t = raise TERM (\"term_of_tagged\",[t])\n\n    fun is_valid_tagged (Free _) = true\n      | is_valid_tagged (Var _) = true\n      | is_valid_tagged (Bound _) = true\n      | is_valid_tagged @{mpat \"OP _\"} = true\n      | is_valid_tagged @{mpat \"ANNOT ?t _\"} = is_valid_tagged t\n      | is_valid_tagged @{mpat \"?f$?x\"} \n        = is_valid_tagged f andalso is_valid_tagged x\n      | is_valid_tagged @{mpat \"PROTECT (\\<lambda>_. PROTECT ?t)\"} = is_valid_tagged t\n      | is_valid_tagged @{mpat \"PROTECT PROTECT\"} = true\n      | is_valid_tagged _ = false\n\n    fun mk_APP f x = let\n      val fT = fastype_of f\n      val xT = fastype_of x\n      val rT = range_type fT\n    in\n      Const (@{const_name APP},fT --> xT --> rT)$f$x\n    end;\n\n    fun mk_OP x = let \n      val T = fastype_of x \n    in \n      Const(@{const_name OP},T-->T)$x\n    end\n\n    fun lambda' (name,T) t = let\n      val tT = fastype_of t\n      val t' = Const (@{const_name PROTECT},tT --> tT)$\n        abstract_over (Free (name,T), t)\n      val t' = \n        Const (@{const_name PROTECT},(T --> tT) --> T --> tT)$Abs (name,T,t')\n    in\n      t'\n    end\n\n    val list_APP = Library.foldl (uncurry mk_APP)\n\n    (* f$x1$...$xn goes to (f,[x1,...,xn]*)\n    fun strip_app t = let\n      fun strip_app_aux @{mpat \"?f$?x\"} args = strip_app_aux f (x::args)\n        | strip_app_aux t args = (t,args)\n    in strip_app_aux t [] end\n      \n    fun untag_conv ctxt = Raw_Simplifier.rewrite ctxt\n      true (Autoref_Tag_Defs.get ctxt)\n\n    fun ABS_beta_conv ctxt = Raw_Simplifier.rewrite ctxt\n      true @{thms ABS_beta}\n  \n    val mk_PROTECT_conv = Conv.rewr_conv @{thm PROTECT_def[symmetric]}\n    val mk_APP_conv = Conv.rewr_conv @{thm APP_def[symmetric]}\n    val mk_OP_conv = Conv.rewr_conv @{thm OP_def[symmetric]}\n    fun mk_ABS_conv ctxt = Conv.abs_conv (K mk_PROTECT_conv) ctxt\n      then_conv mk_PROTECT_conv\n\n    fun mk_ANNOT_conv a ct = let\n      val Tt = ctyp_of_term ct\n\n      val thm = Drule.instantiate' [SOME Tt] [SOME ct,SOME a] \n        @{thm ANNOT_def[symmetric]}\n    in\n      thm\n    end\n\n    fun mk_rel_ANNOT_conv a ct = let\n      val thy = theory_of_cterm ct\n      val T = ctyp_of_term a |> typ_of\n      val (Tc,Ta) = HOLogic.dest_setT T \n        |> HOLogic.dest_prodT \n        |> pairself (ctyp_of thy)\n      val thm = Drule.instantiate' [SOME Ta, SOME Tc] [SOME ct,SOME a] \n        @{thm rel_ANNOT_eq}\n    in\n      thm\n    end\n\n    (* Convert right hand side of refinement statement *)\n    fun rhs_conv conv ctxt ct = let \n      open Conv Refine_Util \n    in\n      case Logic.strip_imp_concl (term_of ct) of\n        @{mpat \"Trueprop ((_,_)\\<in>_)\"} =>\n          HOL_concl_conv (fn ctxt => (arg1_conv (arg_conv (conv ctxt)))) ctxt ct\n      | _ => raise CTERM (\"rhs_conv\",[ct])\n    end\n  end\n\n*}\n\nML_val {*\n  Autoref_Tagging.mk_ANNOT_conv @{cterm \"bar::annot\"} @{cterm \"foo::'a::type\"};\n*}\n\nML_val {*\n  Autoref_Tagging.mk_rel_ANNOT_conv \n    @{cterm \"bar::('c\\<times>'a) set\"} @{cterm \"foo::'a::type\"}\n*}\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Automatic_Refinement/Tool/Autoref_Tagging.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5926665999540698, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.29864835678334584}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\n(*\n  Compatibility theory to recreate syntax for NICTA developments.\n*)\n\ntheory NICTACompat\nimports\n  \"~~/src/HOL/Word/WordBitwise\"\n  SignedWords\n  NICTATools\nbegin\n\n(* all theories should import from NICTACompat rather than any ancestors *)\n\ntype_synonym word8 = \"8 word\"\ntype_synonym word16 = \"16 word\"\ntype_synonym word32 = \"32 word\"\ntype_synonym word64 = \"64 word\"\n\nlemma len8: \"len_of (x :: 8 itself) = 8\" by simp\nlemma len16: \"len_of (x :: 16 itself) = 16\" by simp\nlemma len32: \"len_of (x :: 32 itself) = 32\" by simp\nlemma len64: \"len_of (x :: 64 itself) = 64\" by simp\n\n\nabbreviation\n  wordNOT  :: \"'a::len0 word \\<Rightarrow> 'a word\"      (\"~~ _\" [70] 71)\nwhere\n  \"~~ x == NOT x\"\n\nabbreviation\n  wordAND  :: \"'a::len0 word \\<Rightarrow> 'a word \\<Rightarrow> 'a word\" (infixr \"&&\" 64)\nwhere\n  \"a && b == a AND b\"\n\nabbreviation\n  wordOR   :: \"'a::len0 word \\<Rightarrow> 'a word \\<Rightarrow> 'a word\" (infixr \"||\"  59)\nwhere\n  \"a || b == a OR b\"\n\nabbreviation\n  wordXOR  :: \"'a::len0 word \\<Rightarrow> 'a word \\<Rightarrow> 'a word\" (infixr \"xor\" 59)\nwhere\n  \"a xor b == a XOR b\"\n\n(* testing for presence of word_bitwise *)\nlemma \"((x :: word32) >> 3) AND 7 = (x AND 56) >> 3\"\n  by word_bitwise\n\n(* print words in hex *)\n(* mostly clagged from Num.thy *)\ntyped_print_translation  {*\nlet\n  fun dest_num (Const (@{const_syntax Num.Bit0}, _) $ n) = 2 * dest_num n\n    | dest_num (Const (@{const_syntax Num.Bit1}, _) $ n) = 2 * dest_num n + 1\n    | dest_num (Const (@{const_syntax Num.One}, _)) = 1;\n\n  fun dest_bin_hex_str tm =\n  let\n    val num = dest_num tm;\n    val pre = if num < 10 then \"\" else \"0x\"\n  in\n    pre ^ (Int.fmt StringCvt.HEX num)\n  end;\n\n  fun num_tr' sign ctxt T [n] =\n    let\n      val k = dest_bin_hex_str n;\n      val t' = Syntax.const @{syntax_const \"_Numeral\"} $\n        Syntax.free (sign ^ k);\n    in\n      case T of\n        Type (@{type_name fun}, [_, T' as Type(\"Word.word\",_)]) =>\n          if not (Config.get ctxt show_types) andalso can Term.dest_Type T'\n          then t'\n          else Syntax.const @{syntax_const \"_constrain\"} $ t' $\n                            Syntax_Phases.term_of_typ ctxt T'\n      | T' => if T' = dummyT then t' else raise Match\n    end;\nin [(@{const_syntax numeral}, num_tr' \"\")] end\n*}\n\nlemma neg_num_bintr:\n  \"(- numeral x :: 'a::len word) =\n  word_of_int (bintrunc (len_of TYPE('a)) (-numeral x))\"\n  by (simp only: word_ubin.Abs_norm word_neg_numeral_alt)\n\n(* normalise word numerals to the interval [0..2^len_of 'a) *)\nML {*\n  fun is_refl (Const (@{const_name Pure.eq}, _) $ x $ y) = (x = y)\n    | is_refl _ = false;\n\n  fun typ_size_of t = Word_Lib.dest_wordT (type_of (term_of t));\n\n  fun num_len (Const (@{const_name Num.Bit0}, _) $ n) = num_len n + 1\n    | num_len (Const (@{const_name Num.Bit1}, _) $ n) = num_len n + 1\n    | num_len (Const (@{const_name Num.One}, _)) = 1\n    | num_len (Const (@{const_name numeral}, _) $ t) = num_len t\n    | num_len (Const (@{const_name uminus}, _) $ t) = num_len t\n    | num_len t = raise TERM (\"num_len\", [t])\n\n  fun unsigned_norm is_neg _ ctxt ct =\n  (if is_neg orelse num_len (term_of ct) > typ_size_of ct then let\n      val btr = if is_neg\n                then @{thm neg_num_bintr} else @{thm num_abs_bintr}\n      val th = [Thm.reflexive ct, mk_eq btr] MRS transitive_thm\n\n      (* will work in context of theory Word as well *)\n      val ss = simpset_of (@{context} addsimps @{thms bintrunc_numeral})\n      val cnv = simplify (put_simpset ss ctxt) th\n    in if is_refl (prop_of cnv) then NONE else SOME cnv end\n    else NONE)\n  handle TERM (\"num_len\", _) => NONE\n       | TYPE (\"dest_binT\", _, _) => NONE\n*}\n\nsimproc_setup\n  unsigned_norm (\"numeral n::'a::len word\") = {* unsigned_norm false *}\n\nsimproc_setup\n  unsigned_norm_neg0 (\"-numeral (num.Bit0 num)::'a::len word\") = {* unsigned_norm true *}\n\nsimproc_setup\n  unsigned_norm_neg1 (\"-numeral (num.Bit1 num)::'a::len word\") = {* unsigned_norm true *}\n\nlemma minus_one_norm:\n \"(-1 :: ('a :: len) word)\n    = of_nat (2 ^ len_of TYPE('a) - 1)\"\n  by (simp add:of_nat_diff)\nlemma \"f (7 :: 2 word) = f 3\"\n  apply simp\n  done\n\n\n\nlemma \"f -2 = f (22 :: 3 word)\"\n  apply simp\n  done\n\nlemma \"f -1 = f (13 :: 'a::len word)\"\n  (* apply simp *)\n  oops\n\nlemma \"f -2 = f (8589934590 :: word32)\"\n  using [[simp_trace]]\n  apply simp\n  done\n\nlemma \"(-1 :: 2 word) = 3\"\n  apply simp\n  done\n\nlemma \"f -1 = f (15 :: 4 word)\"\n  apply (simp add: minus_one_norm)\n  done\n\nlemma \"f -1 = f (7 :: 3 word)\"\n  apply (simp add: minus_one_norm)\n  done\n\nlemma \"f -1 = f (0xFFFF :: 16 word)\"\n  by (simp add: minus_one_norm)\n\nlemma bin_nth_minus_Bit0[simp]:\n  \"0 < n \\<Longrightarrow> bin_nth (numeral (num.Bit0 w)) n = bin_nth (numeral w) (n - 1)\"\n  by (cases n, simp_all)\n\nlemma bin_nth_minus_Bit1[simp]:\n  \"0 < n \\<Longrightarrow> bin_nth (numeral (num.Bit1 w)) n = bin_nth (numeral w) (n - 1)\"\n  by (cases n, simp_all)\n\nend\n", "meta": {"author": "crizkallah", "repo": "checker-verification", "sha": "cd5101e57ef70dcdd1680db2de2f08521605bd7c", "save_path": "github-repos/isabelle/crizkallah-checker-verification", "path": "github-repos/isabelle/crizkallah-checker-verification/checker-verification-cd5101e57ef70dcdd1680db2de2f08521605bd7c/autocorres-1.0/lib/NICTACompat.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.5926665999540698, "lm_q1q2_score": 0.29864835678334584}}
{"text": "(* \n   Title: The pi-calculus   \n   Author/Maintainer: Jesper Bengtson (jebe.dk), 2012\n*)\ntheory Weak_Early_Sim_Pres\n  imports Weak_Early_Sim\nbegin\n\nlemma tauPres:\n  fixes P    :: pi\n  and   Q    :: pi\n  and   Rel  :: \"(pi \\<times> pi) set\"\n  and   Rel' :: \"(pi \\<times> pi) set\"\n\n  assumes PRelQ: \"(P, Q) \\<in> Rel\"\n\n  shows \"\\<tau>.(P) \\<leadsto><Rel> \\<tau>.(Q)\"\nproof(induct rule: simCases)\n  case(Bound Q' a x)\n  have \"\\<tau>.(Q) \\<longmapsto>a<\\<nu>x> \\<prec> Q'\" by fact\n  hence False by(induct rule: tauCases', auto)\n  thus ?case by simp\nnext\n  case(Free Q' \\<alpha>)\n  have \"\\<tau>.(Q) \\<longmapsto>(\\<alpha> \\<prec> Q')\" by fact\n  thus ?case\n  proof(induct rule: tauCases', auto simp only: pi.inject residual.inject)\n    have \"\\<tau>.(P) \\<Longrightarrow>\\<^sup>^ \\<tau> \\<prec> P\" by(rule Tau)\n    with PRelQ show \"\\<exists>P'. \\<tau>.(P) \\<Longrightarrow>\\<^sup>^\\<tau> \\<prec> P' \\<and> (P', Q) \\<in> Rel\" by blast\n  qed\nqed\n\nlemma inputPres:\n  fixes P    :: pi\n  and   x    :: name\n  and   Q    :: pi\n  and   a    :: name\n  and   Rel  :: \"(pi \\<times> pi) set\"\n\n  assumes PRelQ: \"\\<forall>y. (P[x::=y], Q[x::=y]) \\<in> Rel\"\n  and     Eqvt: \"eqvt Rel\"\n\n  shows \"a<x>.P \\<leadsto><Rel> a<x>.Q\"\nusing Eqvt\nproof(induct rule: simCasesCont[where C=\"(x, a, P, Q)\"])\n  case(Bound b y Q')\n  from `y \\<sharp> (x, a, P, Q)` have \"y \\<noteq> x\" \"y \\<noteq> a\" \"y \\<sharp> P\" \"y \\<sharp> Q\" by simp+\n  from `a<x>.Q \\<longmapsto>b<\\<nu>y> \\<prec> Q'` `y \\<noteq> a` `y \\<noteq> x` `y \\<sharp> Q` show ?case\n    by(erule_tac inputCases') auto\nnext\n  case(Free \\<alpha> Q')\n  from `a<x>.Q \\<longmapsto> \\<alpha> \\<prec> Q'`\n  show ?case\n  proof(induct rule: inputCases)\n    case(cInput u)\n    have \"a<x>.P \\<Longrightarrow>\\<^sup>^(a<u>) \\<prec> P[x::=u]\"\n      by(rule Input)\n    moreover from PRelQ have \"(P[x::=u], Q[x::=u]) \\<in> Rel\" by auto\n    ultimately show ?case by blast\n  qed\nqed\n\nlemma outputPres:\n  fixes P    :: pi\n  and   Q    :: pi\n  and   a    :: name\n  and   b    :: name\n  and   Rel  :: \"(pi \\<times> pi) set\"\n\n  assumes PRelQ: \"(P, Q) \\<in> Rel\"\n\n  shows \"a{b}.P \\<leadsto><Rel> a{b}.Q\"\nproof(induct rule: simCases)\n  case(Bound Q' c x)\n  have \"a{b}.Q \\<longmapsto>c<\\<nu>x> \\<prec> Q'\" by fact\n  hence False by(induct rule: outputCases', auto)\n  thus ?case by simp\nnext\n  case(Free Q' \\<alpha>)\n  have \"a{b}.Q \\<longmapsto>\\<alpha> \\<prec> Q'\" by fact\n  thus \"\\<exists>P'. a{b}.P \\<Longrightarrow>\\<^sup>^ \\<alpha> \\<prec> P' \\<and> (P', Q') \\<in> Rel\"\n  proof(induct rule: outputCases', auto simp add: pi.inject residual.inject)\n    have \"a{b}.P \\<Longrightarrow>\\<^sup>^ a[b] \\<prec> P\" by(rule Output)\n    with PRelQ show \"\\<exists>P'. a{b}.P \\<Longrightarrow>\\<^sup>^ a[b] \\<prec> P' \\<and> (P', Q) \\<in> Rel\" by blast\n  qed\nqed\n\n\n\n  assumes PSimQ: \"P \\<leadsto><Rel> Q\"\n  and     RelRel': \"Rel \\<subseteq> Rel'\"\n  and     RelStay: \"\\<And>R S c. (R, S) \\<in> Rel \\<Longrightarrow> ([c\\<frown>c]R, S) \\<in> Rel\"\n\n  shows \"[a\\<frown>b]P \\<leadsto><Rel'> [a\\<frown>b]Q\"\nproof(induct rule: simCases)\n  case(Bound Q' c x)\n  have \"x \\<sharp> [a\\<frown>b]P\" by fact\n  hence xFreshP: \"(x::name) \\<sharp> P\" by simp\n  have \"[a\\<frown>b]Q \\<longmapsto>c<\\<nu>x> \\<prec> Q'\" by fact\n  thus ?case\n  proof(induct rule: matchCases)\n    case Match\n    have \"Q \\<longmapsto>c<\\<nu>x> \\<prec> Q'\" by fact\n    with PSimQ xFreshP obtain P' where PTrans: \"P \\<Longrightarrow>c<\\<nu>x> \\<prec> P'\"\n                                   and P'RelQ': \"(P', Q') \\<in> Rel\"\n      by(blast dest: simE)\n    from PTrans have \"[a\\<frown>a]P \\<Longrightarrow>c<\\<nu>x> \\<prec> P'\" by(rule Weak_Early_Step_Semantics.Match)\n    moreover from P'RelQ' RelRel' have \"(P', Q') \\<in> Rel'\" by blast\n    ultimately show ?case by blast\n  qed\nnext\n  case(Free Q' \\<alpha>)\n  have \"[a\\<frown>b]Q \\<longmapsto>\\<alpha> \\<prec> Q'\" by fact\n  thus ?case\n  proof(induct rule: matchCases)\n    case Match\n    have \"Q \\<longmapsto> \\<alpha> \\<prec> Q'\" by fact\n    with PSimQ obtain P' where \"P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P'\" and \"(P', Q') \\<in> Rel\"\n      by(blast dest: simE)\n    thus ?case\n    proof(induct rule: transitionCases)\n      case Step\n      have \"P \\<Longrightarrow>\\<alpha> \\<prec> P'\" by fact\n      hence \"[a\\<frown>a]P \\<Longrightarrow>\\<alpha> \\<prec> P'\" by(rule Weak_Early_Step_Semantics.Match)\n      with RelRel' `(P', Q') \\<in> Rel` show ?case by(force simp add: weakFreeTransition_def)\n    next\n      case Stay\n      have \"[a\\<frown>a]P \\<Longrightarrow>\\<^sup>^\\<tau> \\<prec> [a\\<frown>a]P\" by(simp add: weakFreeTransition_def)\n      moreover from `(P, Q') \\<in> Rel` have \"([a\\<frown>a]P, Q') \\<in> Rel\" by(blast intro: RelStay)\n      ultimately show ?case using RelRel' by blast\n    qed\n  qed\nqed\n\nlemma mismatchPres:\n  fixes P    :: pi\n  and   Q    :: pi\n  and   a    :: name\n  and   b    :: name\n  and   Rel  :: \"(pi \\<times> pi) set\"\n  and   Rel' :: \"(pi \\<times> pi) set\"\n\n  assumes PSimQ: \"P \\<leadsto><Rel> Q\"\n  and     RelRel': \"Rel \\<subseteq> Rel'\"\n  and     RelStay: \"\\<And>R S c d. \\<lbrakk>(R, S) \\<in> Rel; c \\<noteq> d\\<rbrakk> \\<Longrightarrow> ([c\\<noteq>d]R, S) \\<in> Rel\"\n\n  shows \"[a\\<noteq>b]P \\<leadsto><Rel'> [a\\<noteq>b]Q\"\nproof(induct rule: simCases)\n  case(Bound Q' c x)\n  have \"x \\<sharp> [a\\<noteq>b]P\" by fact\n  hence xFreshP: \"(x::name) \\<sharp> P\" by simp\n  have \"[a\\<noteq>b]Q \\<longmapsto>c<\\<nu>x> \\<prec> Q'\" by fact\n  thus ?case\n  proof(induct rule: mismatchCases)\n    case Mismatch\n    have aineqb: \"a \\<noteq> b\" by fact\n    have \"Q \\<longmapsto>c<\\<nu>x> \\<prec> Q'\" by fact\n    with PSimQ xFreshP obtain P' where PTrans: \"P \\<Longrightarrow>c<\\<nu>x> \\<prec> P'\"\n                                   and P'RelQ': \"(P', Q') \\<in> Rel\"\n      by(blast dest: simE)\n    from PTrans aineqb have \"[a\\<noteq>b]P \\<Longrightarrow>c<\\<nu>x> \\<prec> P'\" by(rule Weak_Early_Step_Semantics.Mismatch)\n    moreover from P'RelQ' RelRel' have \"(P', Q') \\<in> Rel'\" by blast\n    ultimately show ?case by blast\n  qed\nnext\n  case(Free Q' \\<alpha>)\n  have \"[a\\<noteq>b]Q \\<longmapsto>\\<alpha> \\<prec> Q'\" by fact\n  thus ?case\n  proof(induct rule: mismatchCases)\n    case Mismatch\n    have aineqb: \"a \\<noteq> b\" by fact\n    have \"Q \\<longmapsto> \\<alpha> \\<prec> Q'\" by fact\n    with PSimQ obtain P' where \"P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P'\" and \"(P', Q') \\<in> Rel\"\n      by(blast dest: simE)\n    thus ?case\n    proof(induct rule: transitionCases)\n      case Step\n      have \"P \\<Longrightarrow>\\<alpha> \\<prec> P'\" by fact\n      hence \"[a\\<noteq>b]P \\<Longrightarrow>\\<alpha> \\<prec> P'\" using aineqb by(rule Weak_Early_Step_Semantics.Mismatch)\n      with RelRel' `(P', Q') \\<in> Rel` show ?case by(force simp add: weakFreeTransition_def)\n    next\n      case Stay\n      have \"[a\\<noteq>b]P \\<Longrightarrow>\\<^sup>^\\<tau> \\<prec> [a\\<noteq>b]P\" by(simp add: weakFreeTransition_def)\n      moreover from `(P, Q') \\<in> Rel` aineqb have \"([a\\<noteq>b]P, Q') \\<in> Rel\" by(blast intro: RelStay)\n      ultimately show ?case using RelRel' by blast\n    qed\n  qed\nqed\n\nlemma parCompose:\n  fixes P     :: pi\n  and   Q     :: pi\n  and   R     :: pi\n  and   S     :: pi\n  and   Rel   :: \"(pi \\<times> pi) set\"\n  and   Rel'  :: \"(pi \\<times> pi) set\"\n  and   Rel'' :: \"(pi \\<times> pi) set\"\n  \n  assumes PSimQ:    \"P \\<leadsto><Rel> Q\"\n  and     RSimT:    \"R \\<leadsto><Rel'> S\"\n  and     PRelQ:    \"(P, Q) \\<in> Rel\"\n  and     RRel'T:   \"(R, S) \\<in> Rel'\"\n  and     Par:      \"\\<And>P' Q' R' S'. \\<lbrakk>(P', Q') \\<in> Rel; (R', S') \\<in> Rel'\\<rbrakk> \\<Longrightarrow> (P' \\<parallel> R', Q' \\<parallel> S') \\<in> Rel''\"\n  and     Res:      \"\\<And>T U x. (T, U) \\<in> Rel'' \\<Longrightarrow> (<\\<nu>x>T, <\\<nu>x>U) \\<in> Rel''\"\n\n  shows \"P \\<parallel> R \\<leadsto><Rel''> Q \\<parallel> S\"\nproof -\n  show ?thesis\n  proof(induct rule: simCases)\n    case(Bound Q' a x)\n    have \"x \\<sharp> P \\<parallel> R\" by fact\n    hence xFreshP: \"x \\<sharp> P\" and xFreshR: \"x \\<sharp> R\" by simp+\n    have \"Q \\<parallel> S \\<longmapsto>a<\\<nu>x> \\<prec> Q'\" by fact\n    thus ?case\n    proof(induct rule: parCasesB)\n      case(cPar1 Q')\n      have QTrans: \"Q \\<longmapsto> a<\\<nu>x> \\<prec> Q'\" and xFreshT: \"x \\<sharp> S\" by fact+\n      from xFreshP PSimQ QTrans obtain P' where PTrans:\"P \\<Longrightarrow>a<\\<nu>x> \\<prec> P'\"\n                                            and P'RelQ': \"(P', Q') \\<in> Rel\"\n        by(blast dest: simE)\n      from PTrans xFreshR have \"P \\<parallel> R \\<Longrightarrow>a<\\<nu>x> \\<prec> (P' \\<parallel> R)\" by(rule Weak_Early_Step_Semantics.Par1B)\n      moreover from P'RelQ' RRel'T have \"(P' \\<parallel> R, Q' \\<parallel> S) \\<in> Rel''\" by(rule Par)\n      ultimately show ?case by blast\n    next\n      case(cPar2 S')\n      have STrans: \"S \\<longmapsto> a<\\<nu>x> \\<prec> S'\" and xFreshQ: \"x \\<sharp> Q\" by fact+\n      from xFreshR RSimT STrans obtain R' where RTrans:\"R \\<Longrightarrow>a<\\<nu>x> \\<prec> R'\"\n                                            and R'Rel'T': \"(R', S') \\<in>  Rel'\"\n        by(blast dest: simE)\n      from RTrans xFreshP xFreshR have ParTrans: \"P \\<parallel> R \\<Longrightarrow>a<\\<nu>x> \\<prec> (P \\<parallel> R')\"\n        by(blast intro: Weak_Early_Step_Semantics.Par2B)\n      moreover from PRelQ R'Rel'T' have \"(P \\<parallel> R', Q \\<parallel>  S') \\<in> Rel''\" by(rule Par)\n      ultimately show ?case by blast\n    qed\n  next\n    case(Free QT' \\<alpha>)\n    have \"Q \\<parallel> S \\<longmapsto> \\<alpha> \\<prec> QT'\" by fact\n    thus ?case\n    proof(induct rule: parCasesF[of _ _ _ _ _ \"(P, R)\"])\n      case(cPar1 Q')\n      have \"Q \\<longmapsto> \\<alpha> \\<prec> Q'\" by fact\n      with PSimQ obtain P' where PTrans: \"P \\<Longrightarrow>\\<^sup>^ \\<alpha> \\<prec> P'\" and PRel: \"(P', Q') \\<in> Rel\"\n        by(blast dest: simE)\n      from PTrans have Trans: \"P \\<parallel> R \\<Longrightarrow>\\<^sup>^ \\<alpha> \\<prec> P' \\<parallel> R\" by(rule Weak_Early_Semantics.Par1F)\n      moreover from PRel RRel'T have \"(P' \\<parallel> R, Q' \\<parallel> S) \\<in> Rel''\" by(blast intro: Par)\n      ultimately show ?case by blast\n    next\n      case(cPar2 S')\n      have \"S \\<longmapsto> \\<alpha> \\<prec> S'\" by fact\n      with RSimT obtain R' where RTrans: \"R \\<Longrightarrow>\\<^sup>^ \\<alpha> \\<prec> R'\" and RRel: \"(R', S') \\<in> Rel'\"\n        by(blast dest: simE)\n      from RTrans have Trans: \"P \\<parallel> R \\<Longrightarrow>\\<^sup>^ \\<alpha> \\<prec> P \\<parallel> R'\" by(rule Weak_Early_Semantics.Par2F)\n      moreover from PRelQ RRel have \"(P \\<parallel> R', Q \\<parallel> S') \\<in> Rel''\" by(blast intro: Par)\n      ultimately show ?case by blast\n    next\n      case(cComm1 Q' S' a b)\n      have QTrans: \"Q \\<longmapsto> a<b> \\<prec> Q'\" and STrans: \"S \\<longmapsto> a[b] \\<prec> S'\" by fact+\n\n      from PSimQ QTrans obtain P' where PTrans: \"P \\<Longrightarrow>a<b> \\<prec> P'\"\n                                    and P'RelQ': \"(P', Q') \\<in> Rel\"\n        by(fastforce dest: simE simp add: weakFreeTransition_def)\n      \n      from RSimT STrans obtain R' where RTrans: \"R \\<Longrightarrow>a[b] \\<prec> R'\"\n                                    and RRel: \"(R', S') \\<in> Rel'\"\n        by(fastforce dest: simE simp add: weakFreeTransition_def)\n      \n      from PTrans RTrans have \"P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> P' \\<parallel> R'\" by(rule Weak_Early_Step_Semantics.Comm1)\n      hence \"P \\<parallel> R \\<Longrightarrow>\\<^sup>^\\<tau> \\<prec> P' \\<parallel> R'\" \n        by(auto simp add: trancl_into_rtrancl dest: Weak_Early_Step_Semantics.tauTransitionChain)\n\n      moreover from P'RelQ' RRel have \"(P' \\<parallel> R', Q' \\<parallel> S') \\<in> Rel''\" by(rule Par)\n      ultimately show ?case by blast\n    next\n      case(cComm2 Q' S' a b)\n      have QTrans: \"Q \\<longmapsto>a[b] \\<prec> Q'\" and STrans: \"S \\<longmapsto>a<b> \\<prec> S'\" by fact+\n      \n      from PSimQ QTrans obtain P' where PTrans: \"P \\<Longrightarrow>a[b] \\<prec> P'\"\n                                    and PRel: \"(P', Q') \\<in> Rel\"\n        by(fastforce dest: simE simp add: weakFreeTransition_def)\n      \n      from RSimT STrans obtain R' where RTrans: \"R \\<Longrightarrow>a<b> \\<prec> R'\"\n                                   and R'Rel'T': \"(R', S') \\<in> Rel'\"\n        by(fastforce dest: simE simp add: weakFreeTransition_def)\n      \n      from PTrans RTrans have \"P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> P' \\<parallel> R'\" by(rule Weak_Early_Step_Semantics.Comm2)\n      hence \"P \\<parallel> R \\<Longrightarrow>\\<^sup>^\\<tau> \\<prec> P' \\<parallel> R'\" \n        by(auto simp add: trancl_into_rtrancl dest: Weak_Early_Step_Semantics.tauTransitionChain)\n      moreover from PRel R'Rel'T' have \"(P' \\<parallel> R', Q' \\<parallel> S') \\<in> Rel''\" by(rule Par)\n      ultimately show ?case by blast\n    next\n      case(cClose1 Q' S' a x)\n      have QTrans: \"Q \\<longmapsto>a<x> \\<prec> Q'\" and STrans: \"S \\<longmapsto>a<\\<nu>x> \\<prec> S'\" by fact+\n      have \"x \\<sharp> (P, R)\" by fact\n      hence xFreshP: \"x \\<sharp> P\" and xFreshR: \"x \\<sharp> R\" by(simp add: fresh_prod)+\n      \n      from PSimQ QTrans obtain P' where PTrans: \"P \\<Longrightarrow>a<x> \\<prec> P'\"\n                                    and P'RelQ': \"(P', Q') \\<in> Rel\"\n        by(fastforce dest: simE simp add: weakFreeTransition_def)\n      \n      from RSimT STrans xFreshR obtain R' where RTrans: \"R \\<Longrightarrow>a<\\<nu>x> \\<prec> R'\" \n                                            and R'Rel'T': \"(R', S') \\<in> Rel'\"\n        by(blast dest: simE)\n       \n      from PTrans RTrans xFreshP have Trans: \"P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> <\\<nu>x>(P' \\<parallel> R')\"\n        by(rule Weak_Early_Step_Semantics.Close1)\n      hence \"P \\<parallel> R \\<Longrightarrow>\\<^sup>^\\<tau> \\<prec> <\\<nu>x>(P' \\<parallel> R')\" \n        by(auto simp add: trancl_into_rtrancl dest: Weak_Early_Step_Semantics.tauTransitionChain)\n      moreover from P'RelQ' R'Rel'T' have \"(<\\<nu>x>(P' \\<parallel> R'), <\\<nu>x>(Q' \\<parallel> S')) \\<in> Rel''\"\n        by(blast intro: Par Res)\n      ultimately show ?case by blast\n    next\n      case(cClose2 Q' S' a x)\n      have QTrans: \"Q \\<longmapsto>a<\\<nu>x> \\<prec> Q'\" and STrans: \"S \\<longmapsto>a<x> \\<prec> S'\" by fact+\n      have \"x \\<sharp> (P, R)\" by fact\n      hence xFreshR: \"x \\<sharp> R\" and xFreshP: \"x \\<sharp> P\" by(simp add: fresh_prod)+\n\n      from PSimQ QTrans xFreshP obtain P' where PTrans: \"P \\<Longrightarrow>a<\\<nu>x> \\<prec> P'\"\n                                            and P'RelQ': \"(P', Q') \\<in> Rel\"\n        by(blast dest: simE)\n      \n      from RSimT STrans obtain R' where RTrans: \"R \\<Longrightarrow>a<x> \\<prec> R'\"\n                                    and R'Rel'T': \"(R', S') \\<in> Rel'\"\n        by(fastforce dest: simE simp add: weakFreeTransition_def)\n      from PTrans RTrans xFreshR have Trans: \"P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> <\\<nu>x>(P' \\<parallel> R')\"\n        by(rule Weak_Early_Step_Semantics.Close2)\n      hence \"P \\<parallel> R \\<Longrightarrow>\\<^sup>^\\<tau> \\<prec> <\\<nu>x>(P' \\<parallel> R')\" \n        by(auto simp add: trancl_into_rtrancl dest: Weak_Early_Step_Semantics.tauTransitionChain)\n      moreover from P'RelQ' R'Rel'T' have \"(<\\<nu>x>(P' \\<parallel> R'), <\\<nu>x>(Q' \\<parallel> S')) \\<in> Rel''\"\n        by(blast intro: Par Res)\n      ultimately show ?case by blast\n    qed\n  qed\nqed\n\nlemma parPres:\n  fixes P   :: pi\n  and   Q   :: pi\n  and   R   :: pi\n  and   a   :: name\n  and   Rel :: \"(pi \\<times> pi) set\"\n  and   Rel' :: \"(pi \\<times> pi) set\"\n  \n  assumes PSimQ:    \"P \\<leadsto><Rel> Q\"\n  and     PRelQ:    \"(P, Q) \\<in> Rel\"\n  and     Par:      \"\\<And>S T U. (S, T) \\<in> Rel \\<Longrightarrow> (S \\<parallel> U, T \\<parallel> U) \\<in> Rel'\"\n  and     Res:      \"\\<And>S T x. (S, T) \\<in> Rel' \\<Longrightarrow> (<\\<nu>x>S, <\\<nu>x>T) \\<in> Rel'\"\n\n  shows \"P \\<parallel> R \\<leadsto><Rel'> Q \\<parallel> R\"\nproof -\n  note PSimQ \n  moreover have RSimR: \"R \\<leadsto><Id> R\" by(auto intro: reflexive)\n  moreover note PRelQ moreover have \"(R, R) \\<in> Id\" by auto\n  moreover from Par have \"\\<And>P Q R T. \\<lbrakk>(P, Q) \\<in> Rel; (R, T) \\<in> Id\\<rbrakk> \\<Longrightarrow> (P \\<parallel> R, Q \\<parallel> T) \\<in> Rel'\"\n    by auto\n  ultimately show ?thesis using Res by(rule parCompose)\nqed\n\n\n\n  assumes PSimQ: \"P \\<leadsto><Rel> Q\"\n  and     ResRel: \"\\<And>R S y. (R, S) \\<in> Rel \\<Longrightarrow> (<\\<nu>y>R, <\\<nu>y>S) \\<in> Rel'\"\n  and     RelRel': \"Rel \\<subseteq> Rel'\"\n  and     EqvtRel: \"eqvt Rel\"\n  and     EqvtRel': \"eqvt Rel'\"\n\n  shows \"<\\<nu>x>P \\<leadsto><Rel'> <\\<nu>x>Q\"\nproof -\n  from EqvtRel' show ?thesis\n  proof(induct rule: simCasesCont[where C=\"(P, x)\"])\n    case(Bound a y Q')\n    have Trans: \"<\\<nu>x>Q \\<longmapsto>a<\\<nu>y> \\<prec> Q'\" by fact\n    have \"y \\<sharp> (P, x)\" by fact\n    hence yineqx: \"y \\<noteq> x\" and yFreshP: \"y \\<sharp> P\" by(simp add: fresh_prod)+\n    from Trans yineqx show ?case\n    proof(induct rule: resCasesB)\n      case(Open Q')\n      have QTrans: \"Q \\<longmapsto>a[x] \\<prec> Q'\" and aineqx: \"a \\<noteq> x\" by fact+\n\n      from PSimQ QTrans obtain P' where PTrans: \"P \\<Longrightarrow>\\<^sup>^a[x] \\<prec> P'\"\n                                    and P'RelQ': \"(P', Q') \\<in> Rel\"\n        by(blast dest: simE)\n      \n      from PTrans aineqx have \"<\\<nu>x>P \\<Longrightarrow>a<\\<nu>x> \\<prec> P'\" \n        by(force intro: Weak_Early_Step_Semantics.Open simp add: weakFreeTransition_def)\n      with `y \\<sharp> P` `y \\<noteq> x` have \"<\\<nu>x>P \\<Longrightarrow>a<\\<nu>y> \\<prec> ([(y, x)] \\<bullet> P')\"\n        by(force intro: weakTransitionAlpha simp add: abs_fresh name_swap)\n      moreover from EqvtRel P'RelQ' RelRel' have \"([(y, x)] \\<bullet> P', [(y, x)] \\<bullet> Q') \\<in> Rel'\"\n        by(blast intro: eqvtRelI)\n      ultimately show ?case by blast\n    next\n      case(Res Q')\n      have QTrans: \"Q \\<longmapsto>a<\\<nu>y> \\<prec> Q'\" and xineqa: \"x \\<noteq> a\" by fact+\n\n      from PSimQ yFreshP QTrans obtain P' where PTrans: \"P \\<Longrightarrow>a<\\<nu>y> \\<prec> P'\"\n                                            and P'RelQ': \"(P', Q') \\<in> Rel\"\n        by(blast dest: simE)\n      from PTrans xineqa yineqx yFreshP have ResTrans: \"<\\<nu>x>P \\<Longrightarrow>a<\\<nu>y> \\<prec> (<\\<nu>x>P')\"\n        by(blast intro: Weak_Early_Step_Semantics.ResB)\n      moreover from P'RelQ' have \"((<\\<nu>x>P'), (<\\<nu>x>Q')) \\<in> Rel'\"\n        by(rule ResRel)\n      ultimately show ?case by blast\n    qed\n  next\n    case(Free \\<alpha> Q')\n    have QTrans: \"<\\<nu>x>Q \\<longmapsto> \\<alpha> \\<prec> Q'\" by fact\n    have \"\\<exists>c::name. c \\<sharp> (P, Q, Q', \\<alpha>)\" by(blast intro: name_exists_fresh)\n    then obtain c::name where cFreshQ: \"c \\<sharp> Q\" and cFreshAlpha: \"c \\<sharp> \\<alpha>\" and cFreshQ': \"c \\<sharp> Q'\" and cFreshP: \"c \\<sharp> P\"\n      by(force simp add: fresh_prod)\n    from cFreshP have \"<\\<nu>x>P = <\\<nu>c>([(x, c)] \\<bullet> P)\" by(simp add: alphaRes)\n    moreover have \"\\<exists>P'.<\\<nu>c>([(x, c)] \\<bullet> P) \\<Longrightarrow>\\<^sup>^ \\<alpha> \\<prec> P' \\<and> (P', Q') \\<in> Rel'\"\n    proof -\n      from QTrans cFreshQ have \"<\\<nu>c>([(x, c)] \\<bullet> Q) \\<longmapsto>\\<alpha> \\<prec> Q'\" by(simp add: alphaRes)\n      moreover have \"c \\<sharp> \\<alpha>\" by(rule cFreshAlpha)\n      moreover from PSimQ EqvtRel have \"([(x, c)] \\<bullet> P) \\<leadsto><Rel> ([(x, c)] \\<bullet> Q)\"\n        by(blast intro: eqvtI)\n      ultimately show ?thesis\n        apply(induct rule: resCasesF, auto simp add: residual.inject pi.inject name_abs_eq)\n        by(blast intro: ResF ResRel dest: simE)\n    qed\n\n    ultimately show ?case by force\n  qed\nqed\n\nlemma resChainI:\n  fixes P   :: pi\n  and   Q   :: pi\n  and   Rel :: \"(pi \\<times> pi) set\"\n  and   lst :: \"name list\"\n\n  assumes eqvtRel: \"eqvt Rel\"\n  and     Res:     \"\\<And>R S y. (R, S) \\<in> Rel \\<Longrightarrow> (<\\<nu>y>R, <\\<nu>y>S) \\<in> Rel\"\n  and     PRelQ:   \"P \\<leadsto><Rel> Q\"\n\n  shows \"(resChain lst) P \\<leadsto><Rel> (resChain lst) Q\"\nproof -\n  show ?thesis\n  proof(induct lst) (* Base case *)\n    from PRelQ show \"resChain [] P \\<leadsto><Rel> resChain [] Q\" by simp\n  next (* Inductive step *)\n    fix a lst\n    assume IH: \"(resChain lst P) \\<leadsto><Rel> (resChain lst Q)\"\n    moreover from Res have \"\\<And>P Q a. (P, Q) \\<in> Rel \\<Longrightarrow> (<\\<nu>a>P, <\\<nu>a>Q) \\<in> Rel\"\n      by simp\n    moreover have \"Rel \\<subseteq> Rel\" by simp\n    ultimately have \"<\\<nu>a>(resChain lst P) \\<leadsto><Rel> <\\<nu>a>(resChain lst Q)\" using eqvtRel\n      by(rule_tac resPres)\n    thus \"resChain (a # lst) P \\<leadsto><Rel> resChain (a # lst) Q\"\n      by simp\n  qed\nqed\n\n\n\n  and     ParComp:     \"\\<And>R S T U. \\<lbrakk>(R, S) \\<in> Rel; (T, U) \\<in> Rel'\\<rbrakk> \\<Longrightarrow> (R \\<parallel> T, S \\<parallel> U) \\<in> Rel'\"\n  and     Res:         \"\\<And>R S x. (R, S) \\<in> Rel' \\<Longrightarrow> (<\\<nu>x>R, <\\<nu>x>S) \\<in> Rel'\"\n\n  and     RelStay:        \"\\<And>R S. (R \\<parallel> !R, S) \\<in> Rel' \\<Longrightarrow> (!R, S) \\<in> Rel'\"\n  and     BangRelRel': \"(bangRel Rel) \\<subseteq> Rel'\"\n  and     eqvtRel':    \"eqvt Rel'\"\n\n  shows \"!P \\<leadsto><Rel'> !Q\"\nproof -\n  let ?Sim = \"\\<lambda>P Rs. (\\<forall>a x Q'. Rs = a<\\<nu>x> \\<prec> Q' \\<longrightarrow> x \\<sharp> P \\<longrightarrow> (\\<exists>P'. P \\<Longrightarrow>a<\\<nu>x> \\<prec> P' \\<and> (P', Q') \\<in> Rel')) \\<and>\n                     (\\<forall>\\<alpha> Q'. Rs = \\<alpha> \\<prec> Q' \\<longrightarrow> (\\<exists>P'. P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P' \\<and> (P', Q') \\<in> Rel'))\"\n  {\n    fix Rs P\n    assume \"!Q \\<longmapsto> Rs\" and \"(P, !Q) \\<in> bangRel Rel\"\n    hence \"?Sim P Rs\" using PRelQ\n    proof(nominal_induct avoiding: P rule: bangInduct)\n      case(Par1B a x Q')\n      have QTrans: \"Q \\<longmapsto>a<\\<nu>x> \\<prec> Q'\" and xFreshQ: \"x \\<sharp> Q\" by fact+\n      have \"(P, Q \\<parallel> !Q) \\<in> bangRel Rel\" and \"x \\<sharp> P\" by fact+\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBangRelT: \"(R, !Q) \\<in> bangRel Rel\" by fact+\n        have \"x \\<sharp> P \\<parallel> R\" by fact\n        hence xFreshP: \"x \\<sharp> P\" and xFreshR: \"x \\<sharp> R\" by simp+\n        from PRelQ have PSimQ: \"P \\<leadsto><Rel> Q\" by(rule Sim)\n        from `x \\<sharp> P` `x \\<sharp> Q` show ?case\n        proof(auto simp add: residual.inject alpha' name_fresh_fresh)\n          from PSimQ QTrans xFreshP obtain P' where PTrans: \"P \\<Longrightarrow>a<\\<nu>x> \\<prec> P'\"\n                                                and P'RelQ': \"(P', Q') \\<in> Rel\"\n            by(blast dest: simE)\n          from PTrans xFreshR have \"P \\<parallel> R \\<Longrightarrow>a<\\<nu>x>\\<prec> (P' \\<parallel> R)\"\n            by(rule Weak_Early_Step_Semantics.Par1B)\n          moreover from P'RelQ' RBangRelT BangRelRel' have \"(P' \\<parallel> R, Q' \\<parallel> !Q) \\<in> Rel'\"\n            by(blast intro: Rel.BRPar)\n          ultimately show \"\\<exists>P'. P \\<parallel> R \\<Longrightarrow>a<\\<nu>x> \\<prec> P' \\<and> (P', Q' \\<parallel> !Q) \\<in> Rel'\" by blast\n        next\n          fix y\n          assume \"(y::name) \\<sharp> Q'\" and \"y \\<sharp> P\" and \"y \\<sharp> R\"\n          from QTrans `y \\<sharp> Q'` have \"Q \\<longmapsto>a<\\<nu>y> \\<prec> ([(x, y)] \\<bullet> Q')\" by(simp add: alphaBoundOutput)\n          with PSimQ `y \\<sharp> P` obtain P' where PTrans: \"P \\<Longrightarrow>a<\\<nu>y> \\<prec> P'\"\n                                         and P'RelQ': \"(P', [(x, y)] \\<bullet> Q') \\<in> Rel\"\n            by(blast dest: simE)\n          from PTrans `y \\<sharp> R` have \"P \\<parallel> R \\<Longrightarrow>a<\\<nu>y>\\<prec> (P' \\<parallel> R)\" by(rule Weak_Early_Step_Semantics.Par1B)\n          moreover from P'RelQ' RBangRelT BangRelRel' have \"(P' \\<parallel> R, ([(y, x)] \\<bullet> Q') \\<parallel> !Q) \\<in> Rel'\"\n            by(fastforce intro: Rel.BRPar simp add: name_swap) \n          ultimately show \"\\<exists>P'. P \\<parallel> R \\<Longrightarrow>a<\\<nu>y> \\<prec> P' \\<and> (P', ([(y, x)] \\<bullet> Q') \\<parallel> !Q) \\<in> Rel'\" by blast\n        qed\n      qed\n    next\n      case(Par1F \\<alpha> Q' P)\n      have QTrans: \"Q \\<longmapsto>\\<alpha> \\<prec> Q'\" by fact\n      have \"(P, Q \\<parallel> !Q) \\<in> bangRel Rel\" by fact\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBangRelQ: \"(R, !Q) \\<in> bangRel Rel\" by fact+\n        show ?case\n        proof(auto simp add: residual.inject)\n          from PRelQ have \"P \\<leadsto><Rel> Q\" by(rule Sim)\n          with QTrans obtain P' where PTrans: \"P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P'\" and P'RelQ': \"(P', Q') \\<in> Rel\"\n            by(blast dest: simE)\n\n          from PTrans have \"P \\<parallel> R \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P' \\<parallel> R\" by(rule Weak_Early_Semantics.Par1F)\n          moreover from P'RelQ' RBangRelQ have \"(P' \\<parallel> R, Q' \\<parallel> !Q) \\<in> bangRel Rel\"\n            by(rule Rel.BRPar)\n          ultimately show \"\\<exists>P'. P \\<parallel> R \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P' \\<and> (P', Q' \\<parallel> !Q) \\<in> Rel'\" using BangRelRel' by blast\n        qed\n      qed\n    next\n      case(Par2B a x Q' P)\n      hence IH: \"\\<And>P. (P, !Q) \\<in> bangRel Rel \\<Longrightarrow> ?Sim P (a<\\<nu>x> \\<prec> Q')\" by simp\n      have xFreshQ: \"x \\<sharp> Q\" by fact\n      have \"(P, Q \\<parallel> !Q) \\<in> bangRel Rel\" and \"x \\<sharp> P\" by fact+\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBangRelQ: \"(R, !Q) \\<in> bangRel Rel\" by fact+\n        have \"x \\<sharp> P \\<parallel> R\" by fact\n        hence xFreshP: \"x \\<sharp> P\" and xFreshR: \"x \\<sharp> R\" by simp+\n        show ?case using `x \\<sharp> Q`\n        proof(auto simp add: residual.inject alpha' name_fresh_fresh)\n          from IH RBangRelQ have \"?Sim R (a<\\<nu>x> \\<prec> Q')\" by blast\n          with xFreshR obtain R' where RTrans: \"R \\<Longrightarrow>a<\\<nu>x> \\<prec> R'\" and R'BangRelQ': \"(R', Q') \\<in> Rel'\"\n            by(blast dest: simE)\n          from RTrans xFreshP have \"P \\<parallel> R \\<Longrightarrow>a<\\<nu>x> \\<prec> (P \\<parallel> R')\"\n            by(auto intro: Weak_Early_Step_Semantics.Par2B)\n          moreover from PRelQ R'BangRelQ' have \"(P \\<parallel> R', Q \\<parallel> Q') \\<in> Rel'\"\n            by(rule ParComp)\n          ultimately show \"\\<exists>P'. P \\<parallel> R \\<Longrightarrow>a<\\<nu>x> \\<prec> P' \\<and> (P', Q \\<parallel> Q') \\<in> Rel'\" by blast\n        next\n          fix y\n          assume \"(y::name) \\<sharp> Q'\" and \"y \\<sharp> R\" and \"y \\<sharp> P\"\n          from IH RBangRelQ have \"?Sim R (a<\\<nu>x> \\<prec> Q')\" by blast\n          with `y \\<sharp> Q'` have  \"?Sim R (a<\\<nu>y> \\<prec> ([(x, y)] \\<bullet> Q'))\" by(simp add: alphaBoundOutput)\n          with `y \\<sharp> R`obtain R' where RTrans: \"R \\<Longrightarrow>a<\\<nu>y> \\<prec> R'\" and R'BangRelQ': \"(R', [(x, y)] \\<bullet> Q') \\<in> Rel'\"\n            by(blast dest: simE)\n          from RTrans `y \\<sharp> P` have \"P \\<parallel> R \\<Longrightarrow>a<\\<nu>y> \\<prec> (P \\<parallel> R')\"\n            by(auto intro: Weak_Early_Step_Semantics.Par2B)\n          moreover from PRelQ R'BangRelQ' have \"(P \\<parallel> R', Q \\<parallel> ([(y, x)] \\<bullet> Q')) \\<in> Rel'\"\n            by(fastforce intro: ParComp simp add: name_swap)\n          ultimately show \"\\<exists>P'. P \\<parallel> R \\<Longrightarrow>a<\\<nu>y> \\<prec> P' \\<and> (P', Q \\<parallel> ([(y, x)] \\<bullet> Q')) \\<in> Rel'\" by blast\n        qed\n      qed\n    next\n      case(Par2F \\<alpha> Q' P)\n      hence IH: \"\\<And>P. (P, !Q) \\<in> bangRel Rel \\<Longrightarrow> ?Sim P (\\<alpha> \\<prec> Q')\" by simp\n      have \"(P, Q \\<parallel> !Q) \\<in> bangRel Rel\" by fact\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBangRelQ: \"(R, !Q) \\<in> bangRel Rel\" by fact+\n        show ?case\n        proof(auto simp add: residual.inject)\n          from RBangRelQ have \"?Sim R (\\<alpha> \\<prec> Q')\" by(rule IH)\n          then obtain R' where RTrans: \"R \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> R'\" and R'RelQ': \"(R', Q') \\<in> Rel'\"\n            by(blast dest: simE)\n          from RTrans have \"P \\<parallel> R \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P \\<parallel> R'\" by(rule Weak_Early_Semantics.Par2F)\n          moreover from PRelQ R'RelQ' have \"(P \\<parallel> R', Q \\<parallel> Q') \\<in> Rel'\" by(rule ParComp)\n          ultimately show \"\\<exists>P'. P \\<parallel> R \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P' \\<and> (P', Q \\<parallel> Q') \\<in> Rel'\" by blast\n        qed\n      qed\n    next\n      case(Comm1 a Q' b Q'' P)\n      hence IH: \"\\<And>P. (P, !Q) \\<in> bangRel Rel \\<Longrightarrow> ?Sim P (a[b] \\<prec> Q'')\" by simp\n      have QTrans: \"Q \\<longmapsto> a<b> \\<prec> Q'\" by fact\n      have \"(P, Q \\<parallel> !Q) \\<in> bangRel Rel\" by fact\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBangRelQ: \"(R, !Q) \\<in> bangRel Rel\" by fact+\n        show ?case\n        proof(auto simp add: residual.inject)\n          from PRelQ have \"P \\<leadsto><Rel> Q\" by(rule Sim)\n          with QTrans obtain P' where PTrans: \"P \\<Longrightarrow>a<b> \\<prec> P'\" and P'RelQ': \"(P', Q') \\<in> Rel\"\n            by(fastforce dest: simE simp add: weakFreeTransition_def)\n\n          from RBangRelQ have \"?Sim R (a[b] \\<prec> Q'')\" by(rule IH)\n          then obtain R' where RTrans: \"R \\<Longrightarrow>a[b] \\<prec> R'\"\n                           and R'RelQ'': \"(R', Q'') \\<in> Rel'\"\n            by(fastforce dest: simE simp add: weakFreeTransition_def)\n          from PTrans RTrans have \"P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> (P' \\<parallel> R')\"\n            by(rule Weak_Early_Step_Semantics.Comm1)\n          hence \"P \\<parallel> R \\<Longrightarrow>\\<^sub>\\<tau> P' \\<parallel> R'\" \n            by(auto simp add: trancl_into_rtrancl dest: Weak_Early_Step_Semantics.tauTransitionChain)\n          moreover from P'RelQ' R'RelQ'' have \"(P' \\<parallel> R', Q' \\<parallel> Q'') \\<in> Rel'\"\n            by(rule ParComp)\n          ultimately show \"\\<exists>P'. (P \\<parallel> R, P') \\<in> {(P, P'). P \\<longmapsto> \\<tau> \\<prec> P'}\\<^sup>* \\<and> (P', Q' \\<parallel> Q'') \\<in> Rel'\"\n            by auto\n        qed\n      qed\n    next\n      case(Comm2 a b Q' Q'' P)\n      hence IH: \"\\<And>P. (P, !Q) \\<in> bangRel Rel \\<Longrightarrow> ?Sim P (a<b> \\<prec> Q'')\" by simp\n      have QTrans: \"Q \\<longmapsto>a[b] \\<prec> Q'\" by fact\n      have \"(P, Q \\<parallel> !Q) \\<in> bangRel Rel\" by fact\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBangRelQ: \"(R, !Q) \\<in> bangRel Rel\" by fact+\n        show ?case\n        proof(auto simp add: residual.inject)\n          from PRelQ have \"P \\<leadsto><Rel> Q\" by(rule Sim)\n          with QTrans obtain P' where PTrans: \"P \\<Longrightarrow>a[b] \\<prec> P'\" and P'RelQ': \"(P', Q') \\<in> Rel\"\n            by(fastforce dest: simE simp add: weakFreeTransition_def)\n\n          from RBangRelQ have \"?Sim R (a<b> \\<prec> Q'')\" by(rule IH)\n          then obtain R' where RTrans: \"R \\<Longrightarrow>a<b> \\<prec> R'\" and R'BangRelQ'': \"(R', Q'') \\<in> Rel'\"\n            by(fastforce dest: simE simp add: weakFreeTransition_def)\n        \n          from PTrans RTrans have \"P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> (P' \\<parallel> R')\"\n            by(rule Weak_Early_Step_Semantics.Comm2)\n          hence \"P \\<parallel> R \\<Longrightarrow>\\<^sub>\\<tau> P' \\<parallel> R'\" \n            by(auto simp add: trancl_into_rtrancl dest: Weak_Early_Step_Semantics.tauTransitionChain)\n          moreover from P'RelQ' R'BangRelQ'' have \"(P' \\<parallel> R', Q' \\<parallel> Q'') \\<in> Rel'\"\n            by(rule ParComp)\n          ultimately show \"\\<exists>P'. (P \\<parallel> R, P') \\<in> {(P, P'). P \\<longmapsto> \\<tau> \\<prec> P'}\\<^sup>* \\<and> (P', Q' \\<parallel> Q'') \\<in> Rel'\" by auto\n        qed\n      qed\n    next\n      case(Close1 a x Q' Q'' P)\n      hence IH: \"\\<And>P. (P, !Q) \\<in> bangRel Rel \\<Longrightarrow> ?Sim P (a<\\<nu>x> \\<prec> Q'')\" by simp\n      have QTrans: \"Q \\<longmapsto> a<x> \\<prec> Q'\" by fact\n      have \"(P, Q \\<parallel> !Q) \\<in> bangRel Rel\" and \"x \\<sharp> P\" by fact+\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBangRelQ: \"(R, !Q) \\<in> bangRel Rel\" by fact+\n        have \"x \\<sharp> P \\<parallel> R\" by fact\n        hence xFreshR: \"x \\<sharp> R\" and xFreshP: \"x \\<sharp> P\" by simp+\n        show ?case\n        proof(auto simp add: residual.inject)\n          from PRelQ have \"P \\<leadsto><Rel> Q\" by(rule Sim)\n          with QTrans obtain P' where PTrans: \"P \\<Longrightarrow>a<x> \\<prec> P'\" and P'RelQ': \"(P', Q') \\<in> Rel\"\n            by(fastforce dest: simE simp add: weakFreeTransition_def)\n          \n          from RBangRelQ have \"?Sim R (a<\\<nu>x> \\<prec> Q'') \" by(rule IH)\n          with xFreshR obtain R' where RTrans: \"R \\<Longrightarrow>a<\\<nu>x> \\<prec> R'\"\n                                   and R'RelQ'': \"(R', Q'') \\<in> Rel'\"\n            by(blast dest: simE)\n        \n          from PTrans RTrans xFreshP have \"P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> <\\<nu>x>(P' \\<parallel> R')\"\n            by(rule Weak_Early_Step_Semantics.Close1)\n          moreover from P'RelQ' R'RelQ'' have \"(<\\<nu>x>(P' \\<parallel> R'), <\\<nu>x>(Q' \\<parallel> Q'')) \\<in> Rel'\"\n            by(force intro: ParComp Res)\n          ultimately show \"\\<exists>P'. (P \\<parallel> R, P') \\<in> {(P, P'). P \\<longmapsto> \\<tau> \\<prec> P'}\\<^sup>* \\<and> (P', <\\<nu>x>(Q' \\<parallel> Q'')) \\<in> Rel'\" by auto\n        qed\n      qed\n    next\n      case(Close2 a x Q' Q'' P)\n      hence IH: \"\\<And>P. (P, !Q) \\<in> bangRel Rel \\<Longrightarrow> ?Sim P (a<x> \\<prec> Q'')\" by simp\n      have QTrans: \"Q \\<longmapsto> a<\\<nu>x> \\<prec> Q'\" by fact\n      have \"(P, Q \\<parallel> !Q) \\<in> bangRel Rel\" and \"x \\<sharp> P\" by fact+\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBangRelQ: \"(R, !Q) \\<in> bangRel Rel\" by fact+\n        have \"x \\<sharp> P \\<parallel> R\" by fact\n        hence xFreshP: \"x \\<sharp> P\" and xFreshR: \"x \\<sharp> R\" by simp+\n        show ?case\n        proof(auto simp add: residual.inject)\n          from PRelQ have \"P \\<leadsto><Rel> Q\" by(rule Sim)\n          with QTrans xFreshP obtain P' where PTrans: \"P \\<Longrightarrow>a<\\<nu>x> \\<prec> P'\"\n                                          and P'RelQ': \"(P', Q') \\<in> Rel\"\n            by(blast dest: simE)\n\n          from RBangRelQ have \"?Sim R (a<x> \\<prec> Q'')\" by(rule IH)\n          with xFreshR obtain R' where RTrans: \"R \\<Longrightarrow>a<x> \\<prec> R'\"\n                                       and R'RelQ'': \"(R', Q'') \\<in> Rel'\"\n            by(fastforce simp add: weakFreeTransition_def)\n          from PTrans RTrans xFreshR have \"P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> <\\<nu>x>(P' \\<parallel> R')\"\n            by(rule Weak_Early_Step_Semantics.Close2)\n          moreover from P'RelQ' R'RelQ'' have \"(<\\<nu>x>(P' \\<parallel> R'), <\\<nu>x>(Q' \\<parallel> Q'')) \\<in> Rel'\"\n            by(force intro: ParComp Res)\n          ultimately show \"\\<exists>P'. (P \\<parallel> R, P') \\<in> {(P, P'). P \\<longmapsto> \\<tau> \\<prec> P'}\\<^sup>* \\<and> (P', <\\<nu>x>(Q' \\<parallel> Q'')) \\<in> Rel'\" by auto\n        qed\n      qed\n    next\n      case(Bang Rs)\n      hence IH: \"\\<And>P. (P, Q \\<parallel> !Q) \\<in> bangRel Rel \\<Longrightarrow> ?Sim P Rs\" by simp\n      have \"(P, !Q) \\<in> bangRel Rel\" by fact\n      thus ?case\n      proof(induct rule: BRBangCases)\n        case(BRBang P)\n        have PRelQ: \"(P, Q) \\<in> Rel\" by fact\n        hence \"(!P, !Q) \\<in> bangRel Rel\" by(rule Rel.BRBang)\n        with PRelQ have \"(P \\<parallel> !P, Q \\<parallel> !Q) \\<in> bangRel Rel\" by(rule Rel.BRPar)\n        hence IH: \"?Sim (P \\<parallel> !P) Rs\" by(rule IH)\n        show ?case\n        proof(intro conjI allI impI)\n          fix Q' a x\n          assume \"Rs = a<\\<nu>x> \\<prec> Q'\" and \"x \\<sharp> !P\"\n          then obtain P' where PTrans: \"(P \\<parallel> !P) \\<Longrightarrow>a<\\<nu>x> \\<prec> P'\"\n                           and P'RelQ': \"(P', Q') \\<in> Rel'\" using IH\n            by(auto simp add: residual.inject)\n          from PTrans have \"!P \\<Longrightarrow>a<\\<nu>x> \\<prec> P'\"\n            by(force intro: Weak_Early_Step_Semantics.Bang simp add: weakFreeTransition_def)\n          with P'RelQ' show \"\\<exists>P'. !P \\<Longrightarrow>a<\\<nu>x> \\<prec> P' \\<and> (P', Q') \\<in> Rel'\" by blast\n        next\n          fix Q' \\<alpha>\n          assume \"Rs = \\<alpha> \\<prec> Q'\"\n          then obtain P' where PTrans: \"(P \\<parallel> !P) \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P'\"\n                           and P'RelQ': \"(P', Q') \\<in> Rel'\" using IH\n            by auto\n          from PTrans show \"\\<exists>P'. !P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P' \\<and> (P', Q') \\<in> Rel'\" using P'RelQ'\n          proof(induct rule: transitionCases)\n            case Step\n            have \"P \\<parallel> !P \\<Longrightarrow>\\<alpha> \\<prec> P'\" by fact\n            hence \"!P \\<Longrightarrow>\\<alpha> \\<prec> P'\" by(rule Weak_Early_Step_Semantics.Bang)\n            with P'RelQ' show ?case by(force simp add: weakFreeTransition_def)\n          next\n            case Stay\n            have \"!P \\<Longrightarrow>\\<^sup>^\\<tau> \\<prec> !P\" by(simp add: weakFreeTransition_def)\n            moreover assume \"(P \\<parallel> !P, Q') \\<in> Rel'\"\n            hence \"(!P, Q') \\<in> Rel'\" by(blast intro: RelStay)\n            ultimately show ?case by blast\n          qed\n        qed\n      qed\n    qed\n  }\n  moreover from PRelQ have \"(!P, !Q) \\<in> bangRel Rel\" by(rule Rel.BRBang)\n  ultimately show ?thesis by(auto simp add: weakSimulation_def)\nqed\n\nlemma bangRelSim:\n  fixes P    :: pi\n  and   Q    :: pi\n  and   Rel  :: \"(pi \\<times> pi) set\"\n  and   Rel'l :: \"(pi \\<times> pi) set\"\n\n  assumes PBangRelQ: \"(P, Q) \\<in> bangRel Rel\"\n  and     Sim:       \"\\<And>R S. (R, S) \\<in> Rel \\<Longrightarrow> R \\<leadsto><Rel> S\"\n\n  and     ParComp:     \"\\<And>R S T U. \\<lbrakk>(R, S) \\<in> Rel; (T, U) \\<in> Rel'\\<rbrakk> \\<Longrightarrow> (R \\<parallel> T, S \\<parallel> U) \\<in> Rel'\"\n  and     Res:         \"\\<And>R S x. (R, S) \\<in> Rel' \\<Longrightarrow> (<\\<nu>x>R, <\\<nu>x>S) \\<in> Rel'\"\n\n  and     RelStay:        \"\\<And>R S. (R \\<parallel> !R, S) \\<in> Rel' \\<Longrightarrow> (!R, S) \\<in> Rel'\"\n  and     BangRelRel': \"(bangRel Rel) \\<subseteq> Rel'\"\n  and     eqvtRel':    \"eqvt Rel'\"\n  and     Eqvt: \"eqvt Rel\"\n\n  shows \"P \\<leadsto><Rel'> Q\"\nproof -\n  from PBangRelQ show ?thesis\n  proof(induct rule: bangRel.induct)\n    case(BRBang P Q)\n    have PRelQ: \"(P, Q) \\<in> Rel\" by fact\n    thus ?case using ParComp Res BangRelRel' eqvtRel' Eqvt RelStay Sim\n      by(rule_tac bangPres)\n  next\n    case(BRPar P Q R T) \n    have \"(P, Q) \\<in> Rel\" by fact\n    moreover hence \"P \\<leadsto><Rel> Q\" by(rule Sim)\n    moreover have \"R \\<leadsto><Rel'> T\" by fact\n    moreover have \"(R, T) \\<in> bangRel Rel\" by fact\n    ultimately show ?case using ParComp eqvtRel' Res Eqvt BangRelRel'\n      by(blast intro: parCompose)\n  next\n    case(BRRes P Q x)\n    have \"P \\<leadsto><Rel'> Q\" by fact\n    thus ?case using BangRelRel' eqvtRel' Res by(blast intro: resPres)\n  qed\nqed\n\nend", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Pi_Calculus/Weak_Early_Sim_Pres.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5926665855647395, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.2986483495324735}}
{"text": "section {* Operational Semantics *}\n\ntheory RG_Tran\nimports RG_Com\nbegin\n\nsubsection {* Semantics of Component Programs *}\n\nsubsubsection {* Environment transitions *}\n\ntype_synonym 'a conf = \"(('a com) option) \\<times> 'a\"\n\ninductive_set\n  etran :: \"('a conf \\<times> 'a conf) set\" \n  and etran' :: \"'a conf \\<Rightarrow> 'a conf \\<Rightarrow> bool\"  (\"_ -e\\<rightarrow> _\" [81,81] 80)\nwhere\n  \"P -e\\<rightarrow> Q \\<equiv> (P,Q) \\<in> etran\"\n| Env: \"(P, s) -e\\<rightarrow> (P, t)\"\n\nlemma etranE: \"c -e\\<rightarrow> c' \\<Longrightarrow> (\\<And>P s t. c = (P, s) \\<Longrightarrow> c' = (P, t) \\<Longrightarrow> Q) \\<Longrightarrow> Q\"\n  by (induct c, induct c', erule etran.cases, blast)\n\nsubsubsection {* Component transitions *}\n\ninductive_set\n  ctran :: \"('a conf \\<times> 'a conf) set\"\n  and ctran' :: \"'a conf \\<Rightarrow> 'a conf \\<Rightarrow> bool\"   (\"_ -c\\<rightarrow> _\" [81,81] 80)\n  and ctrans :: \"'a conf \\<Rightarrow> 'a conf \\<Rightarrow> bool\"   (\"_ -c*\\<rightarrow> _\" [81,81] 80)\nwhere\n  \"P -c\\<rightarrow> Q \\<equiv> (P,Q) \\<in> ctran\"\n| \"P -c*\\<rightarrow> Q \\<equiv> (P,Q) \\<in> ctran^*\"\n\n| Basic:  \"(Some(Basic f), s) -c\\<rightarrow> (None, f s)\"\n\n| Seq1:   \"(Some P0, s) -c\\<rightarrow> (None, t) \\<Longrightarrow> (Some(Seq P0 P1), s) -c\\<rightarrow> (Some P1, t)\"\n\n| Seq2:   \"(Some P0, s) -c\\<rightarrow> (Some P2, t) \\<Longrightarrow> (Some(Seq P0 P1), s) -c\\<rightarrow> (Some(Seq P2 P1), t)\"\n\n| CondT: \"s\\<in>b  \\<Longrightarrow> (Some(Cond b P1 P2), s) -c\\<rightarrow> (Some P1, s)\"\n| CondF: \"s\\<notin>b \\<Longrightarrow> (Some(Cond b P1 P2), s) -c\\<rightarrow> (Some P2, s)\"\n\n| WhileF: \"s\\<notin>b \\<Longrightarrow> (Some(While b P), s) -c\\<rightarrow> (None, s)\"\n| WhileT: \"s\\<in>b  \\<Longrightarrow> (Some(While b P), s) -c\\<rightarrow> (Some(Seq P (While b P)), s)\"\n\n| Await:  \"\\<lbrakk>s\\<in>b; (Some P, s) -c*\\<rightarrow> (None, t)\\<rbrakk> \\<Longrightarrow> (Some(Await b P), s) -c\\<rightarrow> (None, t)\" \n\nmonos \"rtrancl_mono\"\n\nsubsection {* Semantics of Parallel Programs *}\n\ntype_synonym 'a par_conf = \"('a par_com) \\<times> 'a\"\n\ninductive_set\n  par_etran :: \"('a par_conf \\<times> 'a par_conf) set\"\n  and par_etran' :: \"['a par_conf,'a par_conf] \\<Rightarrow> bool\" (\"_ -pe\\<rightarrow> _\" [81,81] 80)\nwhere\n  \"P -pe\\<rightarrow> Q \\<equiv> (P,Q) \\<in> par_etran\"\n| ParEnv:  \"(Ps, s) -pe\\<rightarrow> (Ps, t)\"\n\ninductive_set\n  par_ctran :: \"('a par_conf \\<times> 'a par_conf) set\"\n  and par_ctran' :: \"['a par_conf,'a par_conf] \\<Rightarrow> bool\" (\"_ -pc\\<rightarrow> _\" [81,81] 80)\nwhere\n  \"P -pc\\<rightarrow> Q \\<equiv> (P,Q) \\<in> par_ctran\"\n| ParComp: \"\\<lbrakk>i<length Ps; (Ps!i, s) -c\\<rightarrow> (r, t)\\<rbrakk> \\<Longrightarrow> (Ps, s) -pc\\<rightarrow> (Ps[i:=r], t)\"\n\nlemma par_ctranE: \"c -pc\\<rightarrow> c' \\<Longrightarrow>\n  (\\<And>i Ps s r t. c = (Ps, s) \\<Longrightarrow> c' = (Ps[i := r], t) \\<Longrightarrow> i < length Ps \\<Longrightarrow>\n     (Ps ! i, s) -c\\<rightarrow> (r, t) \\<Longrightarrow> P) \\<Longrightarrow> P\"\n  by (induct c, induct c', erule par_ctran.cases, blast)\n\nsubsection {* Computations *}\n\nsubsubsection {* Sequential computations *}\n\ntype_synonym 'a confs = \"'a conf list\"\n\ninductive_set cptn :: \"'a confs set\"\nwhere\n  CptnOne: \"[(P,s)] \\<in> cptn\"\n| CptnEnv: \"(P, t)#xs \\<in> cptn \\<Longrightarrow> (P,s)#(P,t)#xs \\<in> cptn\"\n| CptnComp: \"\\<lbrakk>(P,s) -c\\<rightarrow> (Q,t); (Q, t)#xs \\<in> cptn \\<rbrakk> \\<Longrightarrow> (P,s)#(Q,t)#xs \\<in> cptn\"\n\ndefinition cp :: \"('a com) option \\<Rightarrow> 'a \\<Rightarrow> ('a confs) set\" where\n  \"cp P s \\<equiv> {l. l!0=(P,s) \\<and> l \\<in> cptn}\"  \n\nsubsubsection {* Parallel computations *}\n\ntype_synonym 'a par_confs = \"'a par_conf list\"\n\ninductive_set par_cptn :: \"'a par_confs set\"\nwhere\n  ParCptnOne: \"[(P,s)] \\<in> par_cptn\"\n| ParCptnEnv: \"(P,t)#xs \\<in> par_cptn \\<Longrightarrow> (P,s)#(P,t)#xs \\<in> par_cptn\"\n| ParCptnComp: \"\\<lbrakk> (P,s) -pc\\<rightarrow> (Q,t); (Q,t)#xs \\<in> par_cptn \\<rbrakk> \\<Longrightarrow> (P,s)#(Q,t)#xs \\<in> par_cptn\"\n\ndefinition par_cp :: \"'a par_com \\<Rightarrow> 'a \\<Rightarrow> ('a par_confs) set\" where\n  \"par_cp P s \\<equiv> {l. l!0=(P,s) \\<and> l \\<in> par_cptn}\"  \n\nsubsection{* Modular Definition of Computation *}\n\ndefinition lift :: \"'a com \\<Rightarrow> 'a conf \\<Rightarrow> 'a conf\" where\n  \"lift Q \\<equiv> \\<lambda>(P, s). (if P=None then (Some Q,s) else (Some(Seq (the P) Q), s))\"\n\ninductive_set cptn_mod :: \"('a confs) set\"\nwhere\n  CptnModOne: \"[(P, s)] \\<in> cptn_mod\"\n| CptnModEnv: \"(P, t)#xs \\<in> cptn_mod \\<Longrightarrow> (P, s)#(P, t)#xs \\<in> cptn_mod\"\n| CptnModNone: \"\\<lbrakk>(Some P, s) -c\\<rightarrow> (None, t); (None, t)#xs \\<in> cptn_mod \\<rbrakk> \\<Longrightarrow> (Some P,s)#(None, t)#xs \\<in>cptn_mod\"\n| CptnModCondT: \"\\<lbrakk>(Some P0, s)#ys \\<in> cptn_mod; s \\<in> b \\<rbrakk> \\<Longrightarrow> (Some(Cond b P0 P1), s)#(Some P0, s)#ys \\<in> cptn_mod\"\n| CptnModCondF: \"\\<lbrakk>(Some P1, s)#ys \\<in> cptn_mod; s \\<notin> b \\<rbrakk> \\<Longrightarrow> (Some(Cond b P0 P1), s)#(Some P1, s)#ys \\<in> cptn_mod\"\n| CptnModSeq1: \"\\<lbrakk>(Some P0, s)#xs \\<in> cptn_mod; zs=map (lift P1) xs \\<rbrakk>\n                 \\<Longrightarrow> (Some(Seq P0 P1), s)#zs \\<in> cptn_mod\"\n| CptnModSeq2: \n  \"\\<lbrakk>(Some P0, s)#xs \\<in> cptn_mod; fst(last ((Some P0, s)#xs)) = None; \n  (Some P1, snd(last ((Some P0, s)#xs)))#ys \\<in> cptn_mod; \n  zs=(map (lift P1) xs)@ys \\<rbrakk> \\<Longrightarrow> (Some(Seq P0 P1), s)#zs \\<in> cptn_mod\"\n\n| CptnModWhile1: \n  \"\\<lbrakk> (Some P, s)#xs \\<in> cptn_mod; s \\<in> b; zs=map (lift (While b P)) xs \\<rbrakk> \n  \\<Longrightarrow> (Some(While b P), s)#(Some(Seq P (While b P)), s)#zs \\<in> cptn_mod\"\n| CptnModWhile2: \n  \"\\<lbrakk> (Some P, s)#xs \\<in> cptn_mod; fst(last ((Some P, s)#xs))=None; s \\<in> b; \n  zs=(map (lift (While b P)) xs)@ys; \n  (Some(While b P), snd(last ((Some P, s)#xs)))#ys \\<in> cptn_mod\\<rbrakk> \n  \\<Longrightarrow> (Some(While b P), s)#(Some(Seq P (While b P)), s)#zs \\<in> cptn_mod\"\n\nsubsection {* Equivalence of Both Definitions.*}\n\nlemma last_length: \"((a#xs)!(length xs))=last (a#xs)\"\n  by (induct xs) auto\n\nlemma div_seq [rule_format]: \"list \\<in> cptn_mod \\<Longrightarrow>\n (\\<forall>s P Q zs. list=(Some (Seq P Q), s)#zs \\<longrightarrow>\n  (\\<exists>xs. (Some P, s)#xs \\<in> cptn_mod  \\<and> (zs=(map (lift Q) xs) \\<or>\n  ( fst(((Some P, s)#xs)!length xs)=None \\<and> \n  (\\<exists>ys. (Some Q, snd(((Some P, s)#xs)!length xs))#ys \\<in> cptn_mod  \n  \\<and> zs=(map (lift (Q)) xs)@ys)))))\"\napply(erule cptn_mod.induct)\napply simp_all\n    apply clarify\n    apply(force intro:CptnModOne)\n   apply clarify\n   apply(erule_tac x=Pa in allE)\n   apply(erule_tac x=Q in allE)\n   apply simp\n   apply clarify\n   apply(erule disjE)\n    apply(rule_tac x=\"(Some Pa,t)#xsa\" in exI)\n    apply(rule conjI)\n     apply clarify\n     apply(erule CptnModEnv)\n    apply(rule disjI1)\n    apply(simp add:lift_def)\n   apply clarify\n   apply(rule_tac x=\"(Some Pa,t)#xsa\" in exI)\n   apply(rule conjI)\n    apply(erule CptnModEnv)\n   apply(rule disjI2)\n   apply(rule conjI)\n    apply(case_tac xsa,simp,simp)\n   apply(rule_tac x=\"ys\" in exI)\n   apply(rule conjI)\n    apply simp\n   apply(simp add:lift_def)\n  apply clarify\n  apply(erule ctran.cases,simp_all)\n apply clarify\n apply(rule_tac x=\"xs\" in exI)\n apply simp\n apply clarify\napply(rule_tac x=\"xs\" in exI)\napply(simp add: last_length)\ndone\n\nlemma cptn_onlyif_cptn_mod_aux [rule_format]:\n  \"\\<forall>s Q t xs.((Some a, s), Q, t) \\<in> ctran \\<longrightarrow> (Q, t) # xs \\<in> cptn_mod \n  \\<longrightarrow> (Some a, s) # (Q, t) # xs \\<in> cptn_mod\"\napply(induct a)\napply simp_all\n--{* basic *}\napply clarify\napply(erule ctran.cases,simp_all)\napply(rule CptnModNone,rule Basic,simp)\napply clarify\napply(erule ctran.cases,simp_all)\n--{* Seq1 *}\napply(rule_tac xs=\"[(None,ta)]\" in CptnModSeq2)\n  apply(erule CptnModNone)\n  apply(rule CptnModOne)\n apply simp\napply simp\napply(simp add:lift_def)\n--{* Seq2 *}\napply(erule_tac x=sa in allE)\napply(erule_tac x=\"Some P2\" in allE)\napply(erule allE,erule impE, assumption)\napply(drule div_seq,simp)\napply clarify\napply(erule disjE)\n apply clarify\n apply(erule allE,erule impE, assumption)\n apply(erule_tac CptnModSeq1)\n apply(simp add:lift_def)\napply clarify \napply(erule allE,erule impE, assumption)\napply(erule_tac CptnModSeq2)\n  apply (simp add:last_length)\n apply (simp add:last_length)\napply(simp add:lift_def)\n--{* Cond *}\napply clarify\napply(erule ctran.cases,simp_all)\napply(force elim: CptnModCondT)\napply(force elim: CptnModCondF)\n--{* While *}\napply  clarify\napply(erule ctran.cases,simp_all)\napply(rule CptnModNone,erule WhileF,simp)\napply(drule div_seq,force)\napply clarify\napply (erule disjE)\n apply(force elim:CptnModWhile1)\napply clarify\napply(force simp add:last_length elim:CptnModWhile2)\n--{* await *}\napply clarify\napply(erule ctran.cases,simp_all)\napply(rule CptnModNone,erule Await,simp+)\ndone\n\nlemma cptn_onlyif_cptn_mod [rule_format]: \"c \\<in> cptn \\<Longrightarrow> c \\<in> cptn_mod\"\napply(erule cptn.induct)\n  apply(rule CptnModOne)\n apply(erule CptnModEnv)\napply(case_tac P)\n apply simp\n apply(erule ctran.cases,simp_all)\napply(force elim:cptn_onlyif_cptn_mod_aux)\ndone\n\nlemma lift_is_cptn: \"c\\<in>cptn \\<Longrightarrow> map (lift P) c \\<in> cptn\"\napply(erule cptn.induct)\n  apply(force simp add:lift_def CptnOne)\n apply(force intro:CptnEnv simp add:lift_def)\napply(force simp add:lift_def intro:CptnComp Seq2 Seq1 elim:ctran.cases)\ndone\n\nlemma cptn_append_is_cptn [rule_format]: \n \"\\<forall>b a. b#c1\\<in>cptn \\<longrightarrow>  a#c2\\<in>cptn \\<longrightarrow> (b#c1)!length c1=a \\<longrightarrow> b#c1@c2\\<in>cptn\"\napply(induct c1)\n apply simp\napply clarify\napply(erule cptn.cases,simp_all)\n apply(force intro:CptnEnv)\napply(force elim:CptnComp)\ndone\n\nlemma last_lift: \"\\<lbrakk>xs\\<noteq>[]; fst(xs!(length xs - (Suc 0)))=None\\<rbrakk> \n \\<Longrightarrow> fst((map (lift P) xs)!(length (map (lift P) xs)- (Suc 0)))=(Some P)\"\n  by (cases \"(xs ! (length xs - (Suc 0)))\") (simp add:lift_def)\n\nlemma last_fst [rule_format]: \"P((a#x)!length x) \\<longrightarrow> \\<not>P a \\<longrightarrow> P (x!(length x - (Suc 0)))\" \n  by (induct x) simp_all\n\nlemma last_fst_esp: \n \"fst(((Some a,s)#xs)!(length xs))=None \\<Longrightarrow> fst(xs!(length xs - (Suc 0)))=None\" \napply(erule last_fst)\napply simp\ndone\n\nlemma last_snd: \"xs\\<noteq>[] \\<Longrightarrow> \n  snd(((map (lift P) xs))!(length (map (lift P) xs) - (Suc 0)))=snd(xs!(length xs - (Suc 0)))\"\n  by (cases \"(xs ! (length xs - (Suc 0)))\") (simp_all add:lift_def)\n\nlemma Cons_lift: \"(Some (Seq P Q), s) # (map (lift Q) xs) = map (lift Q) ((Some P, s) # xs)\"\n  by (simp add:lift_def)\n\nlemma Cons_lift_append: \n  \"(Some (Seq P Q), s) # (map (lift Q) xs) @ ys = map (lift Q) ((Some P, s) # xs)@ ys \"\n  by (simp add:lift_def)\n\nlemma lift_nth: \"i<length xs \\<Longrightarrow> map (lift Q) xs ! i = lift Q  (xs! i)\"\n  by (simp add:lift_def)\n\nlemma snd_lift: \"i< length xs \\<Longrightarrow> snd(lift Q (xs ! i))= snd (xs ! i)\"\n  by (cases \"xs!i\") (simp add:lift_def)\n\nlemma cptn_if_cptn_mod: \"c \\<in> cptn_mod \\<Longrightarrow> c \\<in> cptn\"\napply(erule cptn_mod.induct)\n        apply(rule CptnOne)\n       apply(erule CptnEnv)\n      apply(erule CptnComp,simp)\n     apply(rule CptnComp)\n      apply(erule CondT,simp)\n    apply(rule CptnComp)\n     apply(erule CondF,simp)\n--{* Seq1 *}\napply(erule cptn.cases,simp_all)\n  apply(rule CptnOne)\n apply clarify\n apply(drule_tac P=P1 in lift_is_cptn)\n apply(simp add:lift_def)\n apply(rule CptnEnv,simp)\napply clarify\napply(simp add:lift_def)\napply(rule conjI)\n apply clarify\n apply(rule CptnComp)\n  apply(rule Seq1,simp)\n apply(drule_tac P=P1 in lift_is_cptn)\n apply(simp add:lift_def)\napply clarify\napply(rule CptnComp)\n apply(rule Seq2,simp)\napply(drule_tac P=P1 in lift_is_cptn)\napply(simp add:lift_def)\n--{* Seq2 *}\napply(rule cptn_append_is_cptn)\n  apply(drule_tac P=P1 in lift_is_cptn)\n  apply(simp add:lift_def)\n apply simp\napply(simp split: split_if_asm)\napply(frule_tac P=P1 in last_lift)\n apply(rule last_fst_esp)\n apply (simp add:last_length)\napply(simp add:Cons_lift lift_def split_def last_conv_nth)\n--{* While1 *}\napply(rule CptnComp)\n apply(rule WhileT,simp)\napply(drule_tac P=\"While b P\" in lift_is_cptn)\napply(simp add:lift_def)\n--{* While2 *}\napply(rule CptnComp)\n apply(rule WhileT,simp)\napply(rule cptn_append_is_cptn)\n  apply(drule_tac P=\"While b P\" in lift_is_cptn)\n  apply(simp add:lift_def)\n apply simp\napply(simp split: split_if_asm)\napply(frule_tac P=\"While b P\" in last_lift)\n apply(rule last_fst_esp,simp add:last_length)\napply(simp add:Cons_lift lift_def split_def last_conv_nth)\ndone\n\ntheorem cptn_iff_cptn_mod: \"(c \\<in> cptn) = (c \\<in> cptn_mod)\"\napply(rule iffI)\n apply(erule cptn_onlyif_cptn_mod)\napply(erule cptn_if_cptn_mod)\ndone\n\nsection {* Validity  of Correctness Formulas*}\n\nsubsection {* Validity for Component Programs. *}\n\ntype_synonym 'a rgformula =\n  \"'a com \\<times> 'a set \\<times> ('a \\<times> 'a) set \\<times> ('a \\<times> 'a) set \\<times> 'a set\"\n\ndefinition assum :: \"('a set \\<times> ('a \\<times> 'a) set) \\<Rightarrow> ('a confs) set\" where\n  \"assum \\<equiv> \\<lambda>(pre, rely). {c. snd(c!0) \\<in> pre \\<and> (\\<forall>i. Suc i<length c \\<longrightarrow> \n               c!i -e\\<rightarrow> c!(Suc i) \\<longrightarrow> (snd(c!i), snd(c!Suc i)) \\<in> rely)}\"\n\ndefinition comm :: \"(('a \\<times> 'a) set \\<times> 'a set) \\<Rightarrow> ('a confs) set\" where\n  \"comm \\<equiv> \\<lambda>(guar, post). {c. (\\<forall>i. Suc i<length c \\<longrightarrow> \n               c!i -c\\<rightarrow> c!(Suc i) \\<longrightarrow> (snd(c!i), snd(c!Suc i)) \\<in> guar) \\<and> \n               (fst (last c) = None \\<longrightarrow> snd (last c) \\<in> post)}\"\n\ndefinition com_validity :: \"'a com \\<Rightarrow> 'a set \\<Rightarrow> ('a \\<times> 'a) set \\<Rightarrow> ('a \\<times> 'a) set \\<Rightarrow> 'a set \\<Rightarrow> bool\" \n                 (\"\\<Turnstile> _ sat [_, _, _, _]\" [60,0,0,0,0] 45) where\n  \"\\<Turnstile> P sat [pre, rely, guar, post] \\<equiv> \n   \\<forall>s. cp (Some P) s \\<inter> assum(pre, rely) \\<subseteq> comm(guar, post)\"\n\nsubsection {* Validity for Parallel Programs. *}\n\ndefinition All_None :: \"(('a com) option) list \\<Rightarrow> bool\" where\n  \"All_None xs \\<equiv> \\<forall>c\\<in>set xs. c=None\"\n\ndefinition par_assum :: \"('a set \\<times> ('a \\<times> 'a) set) \\<Rightarrow> ('a par_confs) set\" where\n  \"par_assum \\<equiv> \\<lambda>(pre, rely). {c. snd(c!0) \\<in> pre \\<and> (\\<forall>i. Suc i<length c \\<longrightarrow> \n             c!i -pe\\<rightarrow> c!Suc i \\<longrightarrow> (snd(c!i), snd(c!Suc i)) \\<in> rely)}\"\n\ndefinition par_comm :: \"(('a \\<times> 'a) set \\<times> 'a set) \\<Rightarrow> ('a par_confs) set\" where\n  \"par_comm \\<equiv> \\<lambda>(guar, post). {c. (\\<forall>i. Suc i<length c \\<longrightarrow>   \n        c!i -pc\\<rightarrow> c!Suc i \\<longrightarrow> (snd(c!i), snd(c!Suc i)) \\<in> guar) \\<and> \n         (All_None (fst (last c)) \\<longrightarrow> snd( last c) \\<in> post)}\"\n\ndefinition par_com_validity :: \"'a  par_com \\<Rightarrow> 'a set \\<Rightarrow> ('a \\<times> 'a) set \\<Rightarrow> ('a \\<times> 'a) set \n\\<Rightarrow> 'a set \\<Rightarrow> bool\"  (\"\\<Turnstile> _ SAT [_, _, _, _]\" [60,0,0,0,0] 45) where\n  \"\\<Turnstile> Ps SAT [pre, rely, guar, post] \\<equiv> \n   \\<forall>s. par_cp Ps s \\<inter> par_assum(pre, rely) \\<subseteq> par_comm(guar, post)\"\n\nsubsection {* Compositionality of the Semantics *}\n\nsubsubsection {* Definition of the conjoin operator *}\n\ndefinition same_length :: \"'a par_confs \\<Rightarrow> ('a confs) list \\<Rightarrow> bool\" where\n  \"same_length c clist \\<equiv> (\\<forall>i<length clist. length(clist!i)=length c)\"\n \ndefinition same_state :: \"'a par_confs \\<Rightarrow> ('a confs) list \\<Rightarrow> bool\" where\n  \"same_state c clist \\<equiv> (\\<forall>i <length clist. \\<forall>j<length c. snd(c!j) = snd((clist!i)!j))\"\n\ndefinition same_program :: \"'a par_confs \\<Rightarrow> ('a confs) list \\<Rightarrow> bool\" where\n  \"same_program c clist \\<equiv> (\\<forall>j<length c. fst(c!j) = map (\\<lambda>x. fst(nth x j)) clist)\"\n\ndefinition compat_label :: \"'a par_confs \\<Rightarrow> ('a confs) list \\<Rightarrow> bool\" where\n  \"compat_label c clist \\<equiv> (\\<forall>j. Suc j<length c \\<longrightarrow> \n         (c!j -pc\\<rightarrow> c!Suc j \\<and> (\\<exists>i<length clist. (clist!i)!j -c\\<rightarrow> (clist!i)! Suc j \\<and> \n                       (\\<forall>l<length clist. l\\<noteq>i \\<longrightarrow> (clist!l)!j -e\\<rightarrow> (clist!l)! Suc j))) \\<or> \n         (c!j -pe\\<rightarrow> c!Suc j \\<and> (\\<forall>i<length clist. (clist!i)!j -e\\<rightarrow> (clist!i)! Suc j)))\"\n\ndefinition conjoin :: \"'a par_confs \\<Rightarrow> ('a confs) list \\<Rightarrow> bool\"  (\"_ \\<propto> _\" [65,65] 64) where\n  \"c \\<propto> clist \\<equiv> (same_length c clist) \\<and> (same_state c clist) \\<and> (same_program c clist) \\<and> (compat_label c clist)\"\n\nsubsubsection {* Some previous lemmas *}\n\nlemma list_eq_if [rule_format]: \n  \"\\<forall>ys. xs=ys \\<longrightarrow> (length xs = length ys) \\<longrightarrow> (\\<forall>i<length xs. xs!i=ys!i)\"\n  by (induct xs) auto\n\nlemma list_eq: \"(length xs = length ys \\<and> (\\<forall>i<length xs. xs!i=ys!i)) = (xs=ys)\"\napply(rule iffI)\n apply clarify\n apply(erule nth_equalityI)\n apply simp+\ndone\n\nlemma nth_tl: \"\\<lbrakk> ys!0=a; ys\\<noteq>[] \\<rbrakk> \\<Longrightarrow> ys=(a#(tl ys))\"\n  by (cases ys) simp_all\n\nlemma nth_tl_if [rule_format]: \"ys\\<noteq>[] \\<longrightarrow> ys!0=a \\<longrightarrow> P ys \\<longrightarrow> P (a#(tl ys))\"\n  by (induct ys) simp_all\n\nlemma nth_tl_onlyif [rule_format]: \"ys\\<noteq>[] \\<longrightarrow> ys!0=a \\<longrightarrow> P (a#(tl ys)) \\<longrightarrow> P ys\"\n  by (induct ys) simp_all\n\nlemma seq_not_eq1: \"Seq c1 c2\\<noteq>c1\"\n  by (induct c1) auto\n\nlemma seq_not_eq2: \"Seq c1 c2\\<noteq>c2\"\n  by (induct c2) auto\n\nlemma if_not_eq1: \"Cond b c1 c2 \\<noteq>c1\"\n  by (induct c1) auto\n\nlemma if_not_eq2: \"Cond b c1 c2\\<noteq>c2\"\n  by (induct c2) auto\n\nlemmas seq_and_if_not_eq [simp] = seq_not_eq1 seq_not_eq2 \nseq_not_eq1 [THEN not_sym] seq_not_eq2 [THEN not_sym] \nif_not_eq1 if_not_eq2 if_not_eq1 [THEN not_sym] if_not_eq2 [THEN not_sym]\n\nlemma prog_not_eq_in_ctran_aux:\n  assumes c: \"(P,s) -c\\<rightarrow> (Q,t)\"\n  shows \"P\\<noteq>Q\" using c\n  by (induct x1 \\<equiv> \"(P,s)\" x2 \\<equiv> \"(Q,t)\" arbitrary: P s Q t) auto\n\nlemma prog_not_eq_in_ctran [simp]: \"\\<not> (P,s) -c\\<rightarrow> (P,t)\"\napply clarify\napply(drule prog_not_eq_in_ctran_aux)\napply simp\ndone\n\nlemma prog_not_eq_in_par_ctran_aux [rule_format]: \"(P,s) -pc\\<rightarrow> (Q,t) \\<Longrightarrow> (P\\<noteq>Q)\"\napply(erule par_ctran.induct)\napply(drule prog_not_eq_in_ctran_aux)\napply clarify\napply(drule list_eq_if)\n apply simp_all\napply force\ndone\n\nlemma prog_not_eq_in_par_ctran [simp]: \"\\<not> (P,s) -pc\\<rightarrow> (P,t)\"\napply clarify\napply(drule prog_not_eq_in_par_ctran_aux)\napply simp\ndone\n\nlemma tl_in_cptn: \"\\<lbrakk> a#xs \\<in>cptn; xs\\<noteq>[] \\<rbrakk> \\<Longrightarrow> xs\\<in>cptn\"\n  by (force elim: cptn.cases)\n\nlemma tl_zero[rule_format]: \n  \"P (ys!Suc j) \\<longrightarrow> Suc j<length ys \\<longrightarrow> ys\\<noteq>[] \\<longrightarrow> P (tl(ys)!j)\"\n  by (induct ys) simp_all\n\nsubsection {* The Semantics is Compositional *}\n\nlemma aux_if [rule_format]: \n  \"\\<forall>xs s clist. (length clist = length xs \\<and> (\\<forall>i<length xs. (xs!i,s)#clist!i \\<in> cptn) \n  \\<and> ((xs, s)#ys \\<propto> map (\\<lambda>i. (fst i,s)#snd i) (zip xs clist)) \n   \\<longrightarrow> (xs, s)#ys \\<in> par_cptn)\"\napply(induct ys)\n apply(clarify)\n apply(rule ParCptnOne)\napply(clarify)\napply(simp add:conjoin_def compat_label_def)\napply clarify\napply(erule_tac x=\"0\" and P=\"\\<lambda>j. ?H j \\<longrightarrow> (?P j \\<or> ?Q j)\" in all_dupE,simp)\napply(erule disjE)\n--{* first step is a Component step *}\n apply clarify \n apply simp\n apply(subgoal_tac \"a=(xs[i:=(fst(clist!i!0))])\")\n  apply(subgoal_tac \"b=snd(clist!i!0)\",simp)\n   prefer 2\n   apply(simp add: same_state_def)\n   apply(erule_tac x=i in allE,erule impE,assumption, \n         erule_tac x=1 and P=\"\\<lambda>j. (?H j) \\<longrightarrow> (snd (?d j))=(snd (?e j))\" in allE,simp)\n  prefer 2\n  apply(simp add:same_program_def)\n  apply(erule_tac x=1 and P=\"\\<lambda>j. ?H j \\<longrightarrow> (fst (?s j))=(?t j)\" in allE,simp)\n  apply(rule nth_equalityI,simp)\n  apply clarify\n  apply(case_tac \"i=ia\",simp,simp)\n  apply(erule_tac x=ia and P=\"\\<lambda>j. ?H j \\<longrightarrow> ?I j \\<longrightarrow> ?J j\" in allE)\n  apply(drule_tac t=i in not_sym,simp)\n  apply(erule etranE,simp)\n apply(rule ParCptnComp)\n  apply(erule ParComp,simp)\n--{* applying the induction hypothesis *}\n apply(erule_tac x=\"xs[i := fst (clist ! i ! 0)]\" in allE)\n apply(erule_tac x=\"snd (clist ! i ! 0)\" in allE)\n apply(erule mp)\n apply(rule_tac x=\"map tl clist\" in exI,simp)\n apply(rule conjI,clarify)\n  apply(case_tac \"i=ia\",simp)\n   apply(rule nth_tl_if)\n     apply(force simp add:same_length_def length_Suc_conv)\n    apply simp\n   apply(erule allE,erule impE,assumption,erule tl_in_cptn)\n   apply(force simp add:same_length_def length_Suc_conv)\n  apply(rule nth_tl_if)\n    apply(force simp add:same_length_def length_Suc_conv)\n   apply(simp add:same_state_def)\n   apply(erule_tac x=ia in allE, erule impE, assumption, \n     erule_tac x=1 and P=\"\\<lambda>j. ?H j \\<longrightarrow> (snd (?d j))=(snd (?e j))\" in allE)\n   apply(erule_tac x=ia and P=\"\\<lambda>j. ?H j \\<longrightarrow> ?I j \\<longrightarrow> ?J j\" in allE)\n   apply(drule_tac t=i  in not_sym,simp)\n   apply(erule etranE,simp)\n  apply(erule allE,erule impE,assumption,erule tl_in_cptn)\n  apply(force simp add:same_length_def length_Suc_conv)\n apply(simp add:same_length_def same_state_def)\n apply(rule conjI)\n  apply clarify\n  apply(case_tac j,simp,simp)\n  apply(erule_tac x=ia in allE, erule impE, assumption,\n        erule_tac x=\"Suc(Suc nat)\" and P=\"\\<lambda>j. ?H j \\<longrightarrow> (snd (?d j))=(snd (?e j))\" in allE,simp)\n  apply(force simp add:same_length_def length_Suc_conv)\n apply(rule conjI)\n  apply(simp add:same_program_def)\n  apply clarify\n  apply(case_tac j,simp)\n   apply(rule nth_equalityI,simp)\n   apply clarify\n   apply(case_tac \"i=ia\",simp,simp)\n  apply(erule_tac x=\"Suc(Suc nat)\" and P=\"\\<lambda>j. ?H j \\<longrightarrow> (fst (?s j))=(?t j)\" in allE,simp)\n  apply(rule nth_equalityI,simp,simp)\n  apply(force simp add:length_Suc_conv)\n apply(rule allI,rule impI)\n apply(erule_tac x=\"Suc j\" and P=\"\\<lambda>j. ?H j \\<longrightarrow> (?I j \\<or> ?J j)\" in allE,simp)\n apply(erule disjE) \n  apply clarify\n  apply(rule_tac x=ia in exI,simp)\n  apply(case_tac \"i=ia\",simp)\n   apply(rule conjI)\n    apply(force simp add: length_Suc_conv)\n   apply clarify\n   apply(erule_tac x=l and P=\"\\<lambda>j. ?H j \\<longrightarrow> ?I j \\<longrightarrow> ?J j\" in allE,erule impE,assumption)\n   apply(erule_tac x=l and P=\"\\<lambda>j. ?H j \\<longrightarrow> ?I j \\<longrightarrow> ?J j\" in allE,erule impE,assumption)\n   apply simp\n   apply(case_tac j,simp)\n    apply(rule tl_zero)\n      apply(erule_tac x=l in allE, erule impE, assumption, \n            erule_tac x=1 and P=\"\\<lambda>j.  (?H j) \\<longrightarrow> (snd (?d j))=(snd (?e j))\" in allE,simp)\n      apply(force elim:etranE intro:Env)\n     apply force\n    apply force\n   apply simp\n   apply(rule tl_zero)\n     apply(erule tl_zero)\n      apply force\n     apply force\n    apply force\n   apply force\n  apply(rule conjI,simp)\n   apply(rule nth_tl_if)\n     apply force\n    apply(erule_tac x=ia  in allE, erule impE, assumption,\n          erule_tac x=1 and P=\"\\<lambda>j. ?H j \\<longrightarrow> (snd (?d j))=(snd (?e j))\" in allE)\n    apply(erule_tac x=ia and P=\"\\<lambda>j. ?H j \\<longrightarrow> ?I j \\<longrightarrow> ?J j\" in allE)\n    apply(drule_tac t=i  in not_sym,simp)\n    apply(erule etranE,simp)\n   apply(erule tl_zero)\n    apply force\n   apply force\n  apply clarify\n  apply(case_tac \"i=l\",simp)\n   apply(rule nth_tl_if)\n     apply(erule_tac x=l and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE,force)\n    apply simp\n   apply(erule_tac P=\"\\<lambda>j. ?H j \\<longrightarrow> ?I j \\<longrightarrow> ?J j\" in allE,erule impE,assumption,erule impE,assumption)\n   apply(erule tl_zero,force)\n   apply(erule_tac x=l and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE,force)\n   apply(rule nth_tl_if)\n     apply(erule_tac x=l and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE,force)\n    apply(erule_tac x=l  in allE, erule impE, assumption,\n          erule_tac x=1 and P=\"\\<lambda>j. ?H j \\<longrightarrow> (snd (?d j))=(snd (?e j))\" in allE)\n    apply(erule_tac x=l and P=\"\\<lambda>j. ?H j \\<longrightarrow> ?I j \\<longrightarrow> ?J j\" in allE,erule impE, assumption,simp)\n    apply(erule etranE,simp)\n   apply(rule tl_zero)\n    apply force\n   apply force\n  apply(erule_tac x=l and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE,force)\n apply(rule disjI2)\n apply(case_tac j,simp)\n  apply clarify\n  apply(rule tl_zero)\n    apply(erule_tac x=ia and P=\"\\<lambda>j. ?H j \\<longrightarrow> ?I j\\<in>etran\" in allE,erule impE, assumption)\n    apply(case_tac \"i=ia\",simp,simp)\n    apply(erule_tac x=ia  in allE, erule impE, assumption,\n    erule_tac x=1 and P=\"\\<lambda>j. ?H j \\<longrightarrow> (snd (?d j))=(snd (?e j))\" in allE)\n    apply(erule_tac x=ia and P=\"\\<lambda>j. ?H j \\<longrightarrow> ?I j \\<longrightarrow> ?J j\" in allE,erule impE, assumption,simp)\n    apply(force elim:etranE intro:Env)\n   apply force\n  apply(erule_tac x=ia and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE,force)\n apply simp\n apply clarify\n apply(rule tl_zero)\n   apply(rule tl_zero,force)\n    apply force\n   apply(erule_tac x=ia and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE,force)\n  apply force\n apply(erule_tac x=ia and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE,force)\n--{* first step is an environmental step *}\napply clarify\napply(erule par_etran.cases)\napply simp\napply(rule ParCptnEnv)\napply(erule_tac x=\"Ps\" in allE)\napply(erule_tac x=\"t\" in allE)\napply(erule mp)\napply(rule_tac x=\"map tl clist\" in exI,simp)\napply(rule conjI)\n apply clarify\n apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (?I ?s j) \\<in> cptn\" in allE,simp)\n apply(erule cptn.cases)\n   apply(simp add:same_length_def)\n   apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE,force)\n  apply(simp add:same_state_def)\n  apply(erule_tac x=i  in allE, erule impE, assumption,\n   erule_tac x=1 and P=\"\\<lambda>j. ?H j \\<longrightarrow> (snd (?d j))=(snd (?e j))\" in allE,simp)\n apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> ?J j \\<in>etran\" in allE,simp)\n apply(erule etranE,simp)\napply(simp add:same_state_def same_length_def)\napply(rule conjI,clarify)\n apply(case_tac j,simp,simp)\n apply(erule_tac x=i  in allE, erule impE, assumption,\n       erule_tac x=\"Suc(Suc nat)\" and P=\"\\<lambda>j. ?H j \\<longrightarrow> (snd (?d j))=(snd (?e j))\" in allE,simp)\n apply(rule tl_zero)\n   apply(simp)\n  apply force\n apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE,force)\napply(rule conjI)\n apply(simp add:same_program_def)\n apply clarify\n apply(case_tac j,simp)\n  apply(rule nth_equalityI,simp)\n  apply clarify\n  apply simp\n apply(erule_tac x=\"Suc(Suc nat)\" and P=\"\\<lambda>j. ?H j \\<longrightarrow> (fst (?s j))=(?t j)\" in allE,simp)\n apply(rule nth_equalityI,simp,simp)\n apply(force simp add:length_Suc_conv)\napply(rule allI,rule impI)\napply(erule_tac x=\"Suc j\" and P=\"\\<lambda>j. ?H j \\<longrightarrow> (?I j \\<or> ?J j)\" in allE,simp)\napply(erule disjE) \n apply clarify\n apply(rule_tac x=i in exI,simp)\n apply(rule conjI)\n  apply(erule_tac x=i and P=\"\\<lambda>i. ?H i \\<longrightarrow> ?J i \\<in>etran\" in allE, erule impE, assumption)\n  apply(erule etranE,simp)\n  apply(erule_tac x=i  in allE, erule impE, assumption,\n        erule_tac x=1 and P=\"\\<lambda>j.  (?H j) \\<longrightarrow> (snd (?d j))=(snd (?e j))\" in allE,simp)\n  apply(rule nth_tl_if)\n   apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE,force)\n  apply simp\n apply(erule tl_zero,force) \n  apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE,force)\n apply clarify\n apply(erule_tac x=l and P=\"\\<lambda>i. ?H i \\<longrightarrow> ?J i \\<in>etran\" in allE, erule impE, assumption)\n apply(erule etranE,simp)\n apply(erule_tac x=l  in allE, erule impE, assumption,\n       erule_tac x=1 and P=\"\\<lambda>j.  (?H j) \\<longrightarrow> (snd (?d j))=(snd (?e j))\" in allE,simp)\n apply(rule nth_tl_if)\n   apply(erule_tac x=l and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE,force)\n  apply simp\n  apply(rule tl_zero,force)\n  apply force\n apply(erule_tac x=l and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE,force)\napply(rule disjI2)\napply simp\napply clarify\napply(case_tac j,simp)\n apply(rule tl_zero)\n   apply(erule_tac x=i and P=\"\\<lambda>i. ?H i \\<longrightarrow> ?J i \\<in>etran\" in allE, erule impE, assumption)\n   apply(erule_tac x=i and P=\"\\<lambda>i. ?H i \\<longrightarrow> ?J i \\<in>etran\" in allE, erule impE, assumption)\n   apply(force elim:etranE intro:Env)\n  apply force\n apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE,force)\napply simp\napply(rule tl_zero)\n  apply(rule tl_zero,force)\n   apply force\n  apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE,force)\n apply force\napply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE,force)\ndone\n\nlemma aux_onlyif [rule_format]: \"\\<forall>xs s. (xs, s)#ys \\<in> par_cptn \\<longrightarrow> \n  (\\<exists>clist. (length clist = length xs) \\<and> \n  (xs, s)#ys \\<propto> map (\\<lambda>i. (fst i,s)#(snd i)) (zip xs clist) \\<and> \n  (\\<forall>i<length xs. (xs!i,s)#(clist!i) \\<in> cptn))\"\napply(induct ys)\n apply(clarify)\n apply(rule_tac x=\"map (\\<lambda>i. []) [0..<length xs]\" in exI)\n apply(simp add: conjoin_def same_length_def same_state_def same_program_def compat_label_def)\n apply(rule conjI)\n  apply(rule nth_equalityI,simp,simp)\n apply(force intro: cptn.intros)\napply(clarify)\napply(erule par_cptn.cases,simp)\n apply simp\n apply(erule_tac x=\"xs\" in allE)\n apply(erule_tac x=\"t\" in allE,simp)\n apply clarify\n apply(rule_tac x=\"(map (\\<lambda>j. (P!j, t)#(clist!j)) [0..<length P])\" in exI,simp)\n apply(rule conjI)\n  prefer 2\n  apply clarify\n  apply(rule CptnEnv,simp)\n apply(simp add:conjoin_def same_length_def same_state_def)\n apply (rule conjI)\n  apply clarify\n  apply(case_tac j,simp,simp)\n apply(rule conjI)\n  apply(simp add:same_program_def)\n  apply clarify\n  apply(case_tac j,simp)\n   apply(rule nth_equalityI,simp,simp)\n  apply simp\n  apply(rule nth_equalityI,simp,simp)\n apply(simp add:compat_label_def)\n apply clarify\n apply(case_tac j,simp)\n  apply(simp add:ParEnv)\n  apply clarify\n  apply(simp add:Env)\n apply simp\n apply(erule_tac x=nat in allE,erule impE, assumption)\n apply(erule disjE,simp)\n  apply clarify\n  apply(rule_tac x=i in exI,simp)\n apply force\napply(erule par_ctran.cases,simp)\napply(erule_tac x=\"Ps[i:=r]\" in allE)\napply(erule_tac x=\"ta\" in allE,simp)\napply clarify\napply(rule_tac x=\"(map (\\<lambda>j. (Ps!j, ta)#(clist!j)) [0..<length Ps]) [i:=((r, ta)#(clist!i))]\" in exI,simp)\napply(rule conjI)\n prefer 2\n apply clarify\n apply(case_tac \"i=ia\",simp)\n  apply(erule CptnComp)\n  apply(erule_tac x=ia and P=\"\\<lambda>j. ?H j \\<longrightarrow> (?I j \\<in> cptn)\" in allE,simp)\n apply simp\n apply(erule_tac x=ia in allE)\n apply(rule CptnEnv,simp)\napply(simp add:conjoin_def)\napply (rule conjI)\n apply(simp add:same_length_def)\n apply clarify\n apply(case_tac \"i=ia\",simp,simp)\napply(rule conjI)\n apply(simp add:same_state_def)\n apply clarify\n apply(case_tac j, simp, simp (no_asm_simp))\n apply(case_tac \"i=ia\",simp,simp)\napply(rule conjI)\n apply(simp add:same_program_def)\n apply clarify\n apply(case_tac j,simp)\n  apply(rule nth_equalityI,simp,simp)\n apply simp\n apply(rule nth_equalityI,simp,simp)\n apply(erule_tac x=nat and P=\"\\<lambda>j. ?H j \\<longrightarrow> (fst (?a j))=((?b j))\" in allE)\n apply(case_tac nat)\n  apply clarify\n  apply(case_tac \"i=ia\",simp,simp)\n apply clarify\n apply(case_tac \"i=ia\",simp,simp)\napply(simp add:compat_label_def)\napply clarify\napply(case_tac j)\n apply(rule conjI,simp)\n  apply(erule ParComp,assumption)\n  apply clarify\n  apply(rule_tac x=i in exI,simp)\n apply clarify\n apply(rule Env)\napply simp\napply(erule_tac x=nat and P=\"\\<lambda>j. ?H j \\<longrightarrow> (?P j \\<or> ?Q j)\" in allE,simp)\napply(erule disjE)\n apply clarify\n apply(rule_tac x=ia in exI,simp)\n apply(rule conjI)\n  apply(case_tac \"i=ia\",simp,simp)\n apply clarify\n apply(case_tac \"i=l\",simp)\n  apply(case_tac \"l=ia\",simp,simp)\n  apply(erule_tac x=l in allE,erule impE,assumption,erule impE, assumption,simp)\n apply simp\n apply(erule_tac x=l in allE,erule impE,assumption,erule impE, assumption,simp)\napply clarify\napply(erule_tac x=ia and P=\"\\<lambda>j. ?H j \\<longrightarrow> (?P j)\\<in>etran\" in allE, erule impE, assumption)\napply(case_tac \"i=ia\",simp,simp)\ndone\n\nlemma one_iff_aux: \"xs\\<noteq>[] \\<Longrightarrow> (\\<forall>ys. ((xs, s)#ys \\<in> par_cptn) = \n (\\<exists>clist. length clist= length xs \\<and> \n ((xs, s)#ys \\<propto> map (\\<lambda>i. (fst i,s)#(snd i)) (zip xs clist)) \\<and> \n (\\<forall>i<length xs. (xs!i,s)#(clist!i) \\<in> cptn))) = \n (par_cp (xs) s = {c. \\<exists>clist. (length clist)=(length xs) \\<and>\n (\\<forall>i<length clist. (clist!i) \\<in> cp(xs!i) s) \\<and> c \\<propto> clist})\" \napply (rule iffI)\n apply(rule subset_antisym)\n  apply(rule subsetI) \n  apply(clarify)\n  apply(simp add:par_cp_def cp_def)\n  apply(case_tac x)\n   apply(force elim:par_cptn.cases)\n  apply simp\n  apply(rename_tac a list)\n  apply(erule_tac x=\"list\" in allE)\n  apply clarify\n  apply simp\n  apply(rule_tac x=\"map (\\<lambda>i. (fst i, s) # snd i) (zip xs clist)\" in exI,simp)\n apply(rule subsetI) \n apply(clarify)\n apply(case_tac x)\n  apply(erule_tac x=0 in allE)\n  apply(simp add:cp_def conjoin_def same_length_def same_program_def same_state_def compat_label_def)\n  apply clarify\n  apply(erule cptn.cases,force,force,force)\n apply(simp add:par_cp_def conjoin_def  same_length_def same_program_def same_state_def compat_label_def)\n apply clarify\n apply(erule_tac x=0 and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in all_dupE)\n apply(subgoal_tac \"a = xs\")\n  apply(subgoal_tac \"b = s\",simp)\n   prefer 3\n   apply(erule_tac x=0 and P=\"\\<lambda>j. ?H j \\<longrightarrow> (fst (?s j))=((?t j))\" in allE)\n   apply (simp add:cp_def)\n   apply(rule nth_equalityI,simp,simp)\n  prefer 2\n  apply(erule_tac x=0 in allE)\n  apply (simp add:cp_def)\n  apply(erule_tac x=0 and P=\"\\<lambda>j. ?H j \\<longrightarrow> (\\<forall>i. ?T i \\<longrightarrow> (snd (?d j i))=(snd (?e j i)))\" in allE,simp)\n  apply(erule_tac x=0 and P=\"\\<lambda>j. ?H j \\<longrightarrow> (snd (?d j))=(snd (?e j))\" in allE,simp)\n apply(erule_tac x=list in allE)\n apply(rule_tac x=\"map tl clist\" in exI,simp) \n apply(rule conjI)\n  apply clarify\n  apply(case_tac j,simp)\n   apply(erule_tac x=i  in allE, erule impE, assumption,\n        erule_tac x=\"0\" and P=\"\\<lambda>j. ?H j \\<longrightarrow> (snd (?d j))=(snd (?e j))\" in allE,simp)\n  apply(erule_tac x=i  in allE, erule impE, assumption,\n        erule_tac x=\"Suc nat\" and P=\"\\<lambda>j. ?H j \\<longrightarrow> (snd (?d j))=(snd (?e j))\" in allE)\n  apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE)\n  apply(case_tac \"clist!i\",simp,simp)\n apply(rule conjI)\n  apply clarify\n  apply(rule nth_equalityI,simp,simp)\n  apply(case_tac j)\n   apply clarify\n   apply(erule_tac x=i in allE)\n   apply(simp add:cp_def)\n  apply clarify\n  apply simp\n  apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE)\n  apply(case_tac \"clist!i\",simp,simp)\n apply(thin_tac \"?H = (\\<exists>i. ?J i)\")\n apply(rule conjI)\n  apply clarify\n  apply(erule_tac x=j in allE,erule impE, assumption,erule disjE)\n   apply clarify\n   apply(rule_tac x=i in exI,simp)\n   apply(case_tac j,simp)\n    apply(rule conjI)\n     apply(erule_tac x=i in allE)\n     apply(simp add:cp_def)\n     apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE)\n     apply(case_tac \"clist!i\",simp,simp)\n    apply clarify\n    apply(erule_tac x=l in allE)\n    apply(erule_tac x=l and P=\"\\<lambda>j. ?H j \\<longrightarrow> ?I j \\<longrightarrow> ?J j\" in allE)\n    apply clarify\n    apply(simp add:cp_def)\n    apply(erule_tac x=l and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE)\n    apply(case_tac \"clist!l\",simp,simp)\n   apply simp\n   apply(rule conjI)\n    apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE)\n    apply(case_tac \"clist!i\",simp,simp)\n   apply clarify\n   apply(erule_tac x=l and P=\"\\<lambda>j. ?H j \\<longrightarrow> ?I j \\<longrightarrow> ?J j\" in allE)\n   apply(erule_tac x=l and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE)\n   apply(case_tac \"clist!l\",simp,simp)\n  apply clarify\n  apply(erule_tac x=i in allE)\n  apply(simp add:cp_def)\n  apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE)\n  apply(case_tac \"clist!i\",simp)\n  apply(rule nth_tl_if,simp,simp)\n  apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (?P j)\\<in>etran\" in allE, erule impE, assumption,simp)\n  apply(simp add:cp_def)\n  apply clarify\n  apply(rule nth_tl_if)\n   apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE)\n   apply(case_tac \"clist!i\",simp,simp)\n  apply force\n apply force\napply clarify\napply(rule iffI)\n apply(simp add:par_cp_def)\n apply(erule_tac c=\"(xs, s) # ys\" in equalityCE)\n  apply simp\n  apply clarify\n  apply(rule_tac x=\"map tl clist\" in exI)\n  apply simp\n  apply (rule conjI)\n   apply(simp add:conjoin_def cp_def)\n   apply(rule conjI)\n    apply clarify\n    apply(unfold same_length_def)\n    apply clarify\n    apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE,simp)\n   apply(rule conjI)\n    apply(simp add:same_state_def)\n    apply clarify\n    apply(erule_tac x=i in allE, erule impE, assumption,\n       erule_tac x=j and P=\"\\<lambda>j. ?H j \\<longrightarrow> (snd (?d j))=(snd (?e j))\" in allE)\n    apply(case_tac j,simp)\n    apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE)\n    apply(case_tac \"clist!i\",simp,simp)\n   apply(rule conjI)\n    apply(simp add:same_program_def)\n    apply clarify\n    apply(rule nth_equalityI,simp,simp)\n    apply(case_tac j,simp)\n    apply clarify\n    apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE)\n    apply(case_tac \"clist!i\",simp,simp)\n   apply clarify\n   apply(simp add:compat_label_def)\n   apply(rule allI,rule impI)\n   apply(erule_tac x=j in allE,erule impE, assumption)\n   apply(erule disjE)\n    apply clarify\n    apply(rule_tac x=i in exI,simp)\n    apply(rule conjI)\n     apply(erule_tac x=i in allE)\n     apply(case_tac j,simp)\n      apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE)\n      apply(case_tac \"clist!i\",simp,simp)\n     apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE)\n     apply(case_tac \"clist!i\",simp,simp)\n    apply clarify\n    apply(erule_tac x=l and P=\"\\<lambda>j. ?H j \\<longrightarrow> ?I j \\<longrightarrow> ?J j\" in allE)\n    apply(erule_tac x=l and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE)\n    apply(case_tac \"clist!l\",simp,simp)\n    apply(erule_tac x=l in allE,simp)\n   apply(rule disjI2)\n   apply clarify\n   apply(rule tl_zero)\n     apply(case_tac j,simp,simp)\n     apply(rule tl_zero,force)   \n      apply force\n     apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE,force)\n    apply force\n   apply(erule_tac x=i and P=\"\\<lambda>j. ?H j \\<longrightarrow> (length (?s j) = ?t)\" in allE,force)\n  apply clarify\n  apply(erule_tac x=i in allE)\n  apply(simp add:cp_def)\n  apply(rule nth_tl_if)\n    apply(simp add:conjoin_def)\n    apply clarify\n    apply(simp add:same_length_def)\n    apply(erule_tac x=i in allE,simp)\n   apply simp\n  apply simp\n apply simp\napply clarify\napply(erule_tac c=\"(xs, s) # ys\" in equalityCE)\n apply(simp add:par_cp_def)\napply simp\napply(erule_tac x=\"map (\\<lambda>i. (fst i, s) # snd i) (zip xs clist)\" in allE)\napply simp\napply clarify\napply(simp add:cp_def)\ndone\n\ntheorem one: \"xs\\<noteq>[] \\<Longrightarrow> \n par_cp xs s = {c. \\<exists>clist. (length clist)=(length xs) \\<and> \n               (\\<forall>i<length clist. (clist!i) \\<in> cp(xs!i) s) \\<and> c \\<propto> clist}\"\napply(frule one_iff_aux)\napply(drule sym)\napply(erule iffD2)\napply clarify\napply(rule iffI)\n apply(erule aux_onlyif)\napply clarify\napply(force intro:aux_if)\ndone\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/Hoare_Parallel/RG_Tran.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5926665855647394, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.29864834953247343}}
{"text": "(*  Title:      HOL/MicroJava/BV/JVM.thy\n\n    Author:     Tobias Nipkow, Gerwin Klein\n    Copyright   2000 TUM\n*)\n\nheader {* \\isaheader{LBV for the JVM}\\label{sec:JVM} *}\n\ntheory LBVJVM\nimports \"../DFA/Abstract_BV\" TF_JVM\nbegin\n\ntype_synonym prog_cert = \"cname \\<Rightarrow> mname \\<Rightarrow> ty\\<^sub>i' err list\"\n\ndefinition check_cert :: \"jvm_prog \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> ty\\<^sub>i' err list \\<Rightarrow> bool\"\nwhere\n  \"check_cert P mxs mxl n cert \\<equiv> check_types P mxs mxl cert \\<and> size cert = n+1 \\<and>\n                                 (\\<forall>i<n. cert!i \\<noteq> Err) \\<and> cert!n = OK None\"\n\ndefinition lbvjvm :: \"jvm_prog \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> ty \\<Rightarrow> ex_table \\<Rightarrow> \n             ty\\<^sub>i' err list \\<Rightarrow> instr list \\<Rightarrow> ty\\<^sub>i' err \\<Rightarrow> ty\\<^sub>i' err\"\nwhere\n  \"lbvjvm P mxs maxr T\\<^sub>r et cert bs \\<equiv>\n  wtl_inst_list bs cert (JVM_SemiType.sup P mxs maxr) (JVM_SemiType.le P mxs maxr) Err (OK None) (exec P mxs T\\<^sub>r et bs) 0\"\n\ndefinition wt_lbv :: \"jvm_prog \\<Rightarrow> cname \\<Rightarrow> ty list \\<Rightarrow> ty \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> \n             ex_table \\<Rightarrow> ty\\<^sub>i' err list \\<Rightarrow> instr list \\<Rightarrow> bool\"\nwhere\n  \"wt_lbv P C Ts T\\<^sub>r mxs mxl\\<^sub>0 et cert ins \\<equiv>\n   check_cert P mxs (1+size Ts+mxl\\<^sub>0) (size ins) cert \\<and>\n   0 < size ins \\<and> \n   (let start  = Some ([],(OK (Class C))#((map OK Ts))@(replicate mxl\\<^sub>0 Err));\n        result = lbvjvm P mxs (1+size Ts+mxl\\<^sub>0) T\\<^sub>r et cert ins (OK start)\n    in result \\<noteq> Err)\"\n\ndefinition wt_jvm_prog_lbv :: \"jvm_prog \\<Rightarrow> prog_cert \\<Rightarrow> bool\"\nwhere\n  \"wt_jvm_prog_lbv P cert \\<equiv>\n  wf_prog (\\<lambda>P C (mn,Ts,T\\<^sub>r,(mxs,mxl\\<^sub>0,b,et)). wt_lbv P C Ts T\\<^sub>r mxs mxl\\<^sub>0 et (cert C mn) b) P\"\n\ndefinition mk_cert :: \"jvm_prog \\<Rightarrow> nat \\<Rightarrow> ty \\<Rightarrow> ex_table \\<Rightarrow> instr list \n              \\<Rightarrow> ty\\<^sub>m \\<Rightarrow> ty\\<^sub>i' err list\"\nwhere\n  \"mk_cert P mxs T\\<^sub>r et bs phi \\<equiv> make_cert (exec P mxs T\\<^sub>r et bs) (map OK phi) (OK None)\"\n\ndefinition prg_cert :: \"jvm_prog \\<Rightarrow> ty\\<^sub>P \\<Rightarrow> prog_cert\"\nwhere\n  \"prg_cert P phi C mn \\<equiv> let (C,Ts,T\\<^sub>r,(mxs,mxl\\<^sub>0,ins,et)) = method P C mn\n                         in  mk_cert P mxs T\\<^sub>r et ins (phi C mn)\"\n   \nlemma check_certD [intro?]:\n  \"check_cert P mxs mxl n cert \\<Longrightarrow> cert_ok cert n Err (OK None) (states P mxs mxl)\"\n  by (unfold cert_ok_def check_cert_def check_types_def) auto\n\n\nlemma (in start_context) wt_lbv_wt_step:\n  assumes lbv: \"wt_lbv P C Ts T\\<^sub>r mxs mxl\\<^sub>0 xt cert is\"\n  shows \"\\<exists>\\<tau>s \\<in> list (size is) A. wt_step r Err step \\<tau>s \\<and> OK first \\<sqsubseteq>\\<^sub>r \\<tau>s!0\"\n(*<*)\nproof -\n  from wf have \"semilat (JVM_SemiType.sl P mxs mxl)\" ..\n  hence \"semilat (A, r, f)\" by (simp add: sl_def2)\n  moreover have \"top r Err\" by (simp add: JVM_le_Err_conv)\n  moreover have \"Err \\<in> A\" by (simp add: JVM_states_unfold)\n  moreover have \"bottom r (OK None)\" \n    by (simp add: JVM_le_Err_conv bottom_def lesub_def Err.le_def split: err.split)\n  moreover have \"OK None \\<in> A\" by (simp add: JVM_states_unfold)\n  moreover note bounded_step\n  moreover from lbv have \"cert_ok cert (size is) Err (OK None) A\"\n    by (unfold wt_lbv_def) (auto dest: check_certD)\n  moreover note exec_pres_type\n  moreover\n  from lbv \n  have \"wtl_inst_list is cert f r Err (OK None) step 0 (OK first) \\<noteq> Err\"\n    by (simp add: wt_lbv_def lbvjvm_def step_def_exec [symmetric])    \n  moreover note first_in_A\n  moreover from lbv have \"0 < size is\" by (simp add: wt_lbv_def)\n  ultimately show ?thesis by (rule lbvs.wtl_sound_strong [OF lbvs.intro, OF lbv.intro lbvs_axioms.intro, OF Semilat.intro lbv_axioms.intro])\nqed\n(*>*)\n\n\nlemma (in start_context) wt_lbv_wt_method:\n  assumes lbv: \"wt_lbv P C Ts T\\<^sub>r mxs mxl\\<^sub>0 xt cert is\"  \n  shows \"\\<exists>\\<tau>s. wt_method P C Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt \\<tau>s\"\n(*<*)\nproof -\n  from lbv have l: \"is \\<noteq> []\" by (simp add: wt_lbv_def)\n  moreover\n  from wf lbv C Ts obtain \\<tau>s where \n    list:  \"\\<tau>s \\<in> list (size is) A\" and\n    step:  \"wt_step r Err step \\<tau>s\" and    \n    start: \"OK first \\<sqsubseteq>\\<^sub>r \\<tau>s!0\" \n    by (blast dest: wt_lbv_wt_step)\n  from list have [simp]: \"size \\<tau>s = size is\" by simp\n  have \"size (map ok_val \\<tau>s) = size is\" by simp  \n  moreover from l have 0: \"0 < size \\<tau>s\" by simp\n  with step obtain \\<tau>s0 where \"\\<tau>s!0 = OK \\<tau>s0\"\n    by (unfold wt_step_def) blast\n  with start 0 have \"wt_start P C Ts mxl\\<^sub>0 (map ok_val \\<tau>s)\"\n    by (simp add: wt_start_def JVM_le_Err_conv lesub_def Err.le_def)    \n  moreover {\n    from list have \"check_types P mxs mxl \\<tau>s\" by (simp add: check_types_def)\n    also from step  have \"\\<forall>x \\<in> set \\<tau>s. x \\<noteq> Err\" \n      by (auto simp add: all_set_conv_all_nth wt_step_def)    \n    hence [symmetric]: \"map OK (map ok_val \\<tau>s) = \\<tau>s\"\n      by (auto intro!: map_idI)\n    finally have \"check_types P mxs mxl (map OK (map ok_val \\<tau>s))\" .\n  }\n  moreover {  \n    note bounded_step\n    moreover from list have \"set \\<tau>s \\<subseteq> A\" by simp\n    moreover from step have \"wt_err_step (sup_state_opt P) step \\<tau>s\"\n      by (simp add: wt_err_step_def JVM_le_Err_conv)\n    ultimately have \"wt_app_eff (sup_state_opt P) app eff (map ok_val \\<tau>s)\"\n      by (auto intro: wt_err_imp_wt_app_eff simp add: exec_def states_def)\n  }    \n  ultimately have \"wt_method P C Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt (map ok_val \\<tau>s)\"\n    by (simp add: wt_method_def2 check_types_def del: map_map)\n  thus ?thesis ..\nqed\n(*>*)\n\n  \nlemma (in start_context) wt_method_wt_lbv:\n  assumes wt: \"wt_method P C Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt \\<tau>s\" \n  defines [simp]: \"cert \\<equiv> mk_cert P mxs T\\<^sub>r xt is \\<tau>s\"\n  \n  shows \"wt_lbv P C Ts T\\<^sub>r mxs mxl\\<^sub>0 xt cert is\" \n(*<*)\nproof -\n  let ?\\<tau>s  = \"map OK \\<tau>s\"\n  let ?cert = \"make_cert step ?\\<tau>s (OK None)\"\n\n  from wt obtain \n    0:        \"0 < size is\" and\n    size:     \"size is = size ?\\<tau>s\" and\n    ck_types: \"check_types P mxs mxl ?\\<tau>s\" and\n    wt_start: \"wt_start P C Ts mxl\\<^sub>0 \\<tau>s\" and\n    app_eff:  \"wt_app_eff (sup_state_opt P) app eff \\<tau>s\"\n    by (force simp add: wt_method_def2 check_types_def) \n  \n  from wf have \"semilat (JVM_SemiType.sl P mxs mxl)\" ..\n  hence \"semilat (A, r, f)\" by (simp add: sl_def2)\n  moreover have \"top r Err\" by (simp add: JVM_le_Err_conv)\n  moreover have \"Err \\<in> A\" by (simp add: JVM_states_unfold)\n  moreover have \"bottom r (OK None)\" \n    by (simp add: JVM_le_Err_conv bottom_def lesub_def Err.le_def split: err.split)\n  moreover have \"OK None \\<in> A\" by (simp add: JVM_states_unfold)\n  moreover from wf have \"mono r step (size is) A\" by (rule step_mono)\n  hence \"mono r step (size ?\\<tau>s) A\" by (simp add: size)\n  moreover from exec_pres_type \n  have \"pres_type step (size ?\\<tau>s) A\" by (simp add: size) \n  moreover\n  from ck_types have \\<tau>s_in_A: \"set ?\\<tau>s \\<subseteq> A\" by (simp add: check_types_def)\n  hence \"\\<forall>pc. pc < size ?\\<tau>s \\<longrightarrow> ?\\<tau>s!pc \\<in> A \\<and> ?\\<tau>s!pc \\<noteq> Err\" by auto\n  moreover from bounded_step \n  have \"bounded step (size ?\\<tau>s)\" by (simp add: size)\n  moreover have \"OK None \\<noteq> Err\" by simp\n  moreover from bounded_step size \\<tau>s_in_A app_eff\n  have \"wt_err_step (sup_state_opt P) step ?\\<tau>s\"\n    by (auto intro: wt_app_eff_imp_wt_err simp add: exec_def states_def)    \n  hence \"wt_step r Err step ?\\<tau>s\"\n    by (simp add: wt_err_step_def JVM_le_Err_conv)\n  moreover\n  from 0 size have \"0 < size \\<tau>s\" by auto\n  hence \"?\\<tau>s!0 = OK (\\<tau>s!0)\" by simp\n  with wt_start have \"OK first \\<sqsubseteq>\\<^sub>r ?\\<tau>s!0\"\n    by (clarsimp simp add: wt_start_def lesub_def Err.le_def JVM_le_Err_conv)\n  moreover note first_in_A\n  moreover have \"OK first \\<noteq> Err\" by simp\n  moreover note size \n  ultimately\n  have \"wtl_inst_list is ?cert f r Err (OK None) step 0 (OK first) \\<noteq> Err\"\n    by (rule lbvc.wtl_complete [OF lbvc.intro, OF lbv.intro lbvc_axioms.intro, OF Semilat.intro lbv_axioms.intro])\n  moreover from 0 size have \"\\<tau>s \\<noteq> []\" by auto\n  moreover from ck_types have \"check_types P mxs mxl ?cert\"\n    by (auto simp add: make_cert_def check_types_def JVM_states_unfold)\n  moreover note 0 size\n  ultimately show ?thesis \n    by (simp add: wt_lbv_def lbvjvm_def mk_cert_def step_def_exec [symmetric]\n                  check_cert_def make_cert_def nth_append)\nqed  \n(*>*)\n\n\ntheorem jvm_lbv_correct:\n  \"wt_jvm_prog_lbv P Cert \\<Longrightarrow> wf_jvm_prog P\"\n(*<*)\nproof -  \n  let ?\\<Phi> = \"\\<lambda>C mn. let (C,Ts,T\\<^sub>r,(mxs,mxl\\<^sub>0,is,xt)) = method P C mn in \n              SOME \\<tau>s. wt_method P C Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt \\<tau>s\"\n    \n  assume wt: \"wt_jvm_prog_lbv P Cert\"\n  hence \"wf_jvm_prog\\<^bsub>?\\<Phi>\\<^esub> P\"\n    apply (unfold wf_jvm_prog_phi_def wt_jvm_prog_lbv_def) \n    apply (erule wf_prog_lift)\n    apply (auto dest!: start_context.wt_lbv_wt_method [OF start_context.intro] \n                intro: someI)\n    apply (erule sees_method_is_class)\n    done\n  thus ?thesis by (unfold wf_jvm_prog_def) blast\nqed\n(*>*)\n\ntheorem jvm_lbv_complete:\n  assumes wt: \"wf_jvm_prog\\<^bsub>\\<Phi>\\<^esub> P\" \n  shows \"wt_jvm_prog_lbv P (prg_cert P \\<Phi>)\"\n(*<*)\n  using wt\n  apply (unfold wf_jvm_prog_phi_def wt_jvm_prog_lbv_def)\n  apply (erule wf_prog_lift)\n  apply (auto simp add: prg_cert_def \n              intro!: start_context.wt_method_wt_lbv start_context.intro)\n  apply (erule sees_method_is_class)                                     \n  done\n(*>*)\n\nend  \n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Jinja/BV/LBVJVM.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.29864584808453953}}
{"text": "theory IOTickTock_Prefix\n  imports IOTickTock_Core\nbegin\n\ndefinition PrefixIOTT :: \"'e \\<Rightarrow> 'e set \\<Rightarrow> 'e ttprocess \\<Rightarrow> 'e ttprocess\" (infixr \"\\<rightarrow>\\<^sub>C\\<^bsup>_\\<^esup>\" 61) where\n  \"PrefixIOTT e Outs P = \n    {t. \\<exists> s\\<in>tocks({x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}). e \\<notin> Outs \\<and> (t = s \\<or> (\\<exists> X. Tock \\<notin> X \\<and> Event e \\<notin> X \\<and> t = s @ [[X]\\<^sub>R]))}\n     \\<union> {t. \\<exists> s\\<in>tocks({x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}). e \\<notin> Outs \\<and> (t = s \\<or> (\\<exists> \\<sigma>\\<in>P. t = s @ [[Event e]\\<^sub>E] @ \\<sigma>))}\n     \\<union> {t. ((\\<exists> \\<sigma>\\<in>P. t = [[Event e]\\<^sub>E] @ \\<sigma>) \\<or> t = []) \\<and> e \\<in> Outs}\"\n\nlemma PrefixIOTT_input_eq_PrefixTT:\n  \"e \\<notin> Outs \\<Longrightarrow> (e \\<rightarrow>\\<^sub>C\\<^bsup>Outs\\<^esup> P) = (e \\<rightarrow>\\<^sub>C P)\"\n  unfolding PrefixTT_def PrefixIOTT_def by auto\n\nlemma \"\\<forall>x\\<in>P. ttWF x \\<Longrightarrow> \\<forall> x \\<in> e \\<rightarrow>\\<^sub>C\\<^bsup>Outs\\<^esup> P. ttWF x\"\nproof (cases \"e \\<in> Outs\")\n  assume \"e \\<in> Outs\"\n  then show \"\\<forall>x\\<in>P. ttWF x \\<Longrightarrow> \\<forall>x\\<in>e \\<rightarrow>\\<^sub>C\\<^bsup>Outs\\<^esup> P. ttWF x\"\n    unfolding PrefixIOTT_def by auto\nnext\n  assume \"e \\<notin> Outs\"\n  then show \"\\<forall>x\\<in>P. ttWF x \\<Longrightarrow> \\<forall>x\\<in>e \\<rightarrow>\\<^sub>C\\<^bsup>Outs\\<^esup> P. ttWF x\"\n    by (simp add: PrefixIOTT_input_eq_PrefixTT PrefixTT_wf)\nqed\n\nlemma TT0_PrefixIOTT:\n  \"TT0 (e \\<rightarrow>\\<^sub>C\\<^bsup>Outs\\<^esup> P)\"\nproof (cases \"e \\<in> Outs\")\n  assume \"e \\<in> Outs\"\n  then show \"TT0 (e \\<rightarrow>\\<^sub>C\\<^bsup>Outs\\<^esup> P)\"\n    unfolding PrefixIOTT_def TT0_def by auto\nnext\n  assume \"e \\<notin> Outs\"\n  then show \"TT0 (e \\<rightarrow>\\<^sub>C\\<^bsup>Outs\\<^esup> P)\"\n    using PrefixIOTT_input_eq_PrefixTT PrefixTT_def TT0_def tocks.empty_in_tocks by fastforce\nqed\n\nlemma TT1_PrefixIOTT:\n  \"TT1 P \\<Longrightarrow> TT1 (e \\<rightarrow>\\<^sub>C\\<^bsup>Outs\\<^esup> P)\"\nproof (cases \"e \\<in> Outs\")\n  assume \"e \\<in> Outs\"\n  then show \"TT1 P \\<Longrightarrow> TT1 (e \\<rightarrow>\\<^sub>C\\<^bsup>Outs\\<^esup> P)\"\n    unfolding PrefixIOTT_def TT1_def apply auto\n    apply (metis add_Tick_refusal_trace.cases tt_prefix_subset.simps(3) tt_prefix_subset.simps(5))\n    using tt_prefix_subset.elims(2) by blast\nnext\n  assume \"e \\<notin> Outs\"\n  then show \"TT1 P \\<Longrightarrow> TT1 (e \\<rightarrow>\\<^sub>C\\<^bsup>Outs\\<^esup> P)\"\n    by (simp add: PrefixIOTT_input_eq_PrefixTT TT1_Prefix)\nqed\n\nlemma TT2_PrefixIOTT:\n  assumes \"TT0 P\" \"TT1 P\" \"TT2 P\"\n  shows \"TT2 (e \\<rightarrow>\\<^sub>C\\<^bsup>Outs\\<^esup> P)\"\nproof (cases \"e \\<in> Outs\")\n  assume \"e \\<in> Outs\"\n  then show \"TT2 (e \\<rightarrow>\\<^sub>C\\<^bsup>Outs\\<^esup> P)\"\n    unfolding PrefixIOTT_def TT2_def\n  proof auto\n    fix \\<rho> \\<sigma> X Y \\<sigma>'\n    assume case_assms: \"Y \\<inter> {ea. ea \\<noteq> Tock \\<and> (\\<exists>\\<sigma>\\<in>P. \\<rho> @ [[ea]\\<^sub>E] = [Event e]\\<^sub>E # \\<sigma>) \n        \\<or> ea = Tock \\<and> (\\<exists>\\<sigma>\\<in>P. \\<rho> @ [[X]\\<^sub>R, [ea]\\<^sub>E] = [Event e]\\<^sub>E # \\<sigma>)} = {}\"\n      \"\\<sigma>' \\<in> P\" \"\\<rho> @ [X]\\<^sub>R # \\<sigma> = [Event e]\\<^sub>E # \\<sigma>'\"\n    obtain \\<rho>' where \\<rho>'_def: \"\\<rho> = [Event e]\\<^sub>E # \\<rho>'\"\n      using case_assms(3) by (induct \\<rho> rule:ttWF.induct, auto)\n    have \"\\<rho>' @ [X \\<union> Y]\\<^sub>R # \\<sigma> \\<in> P\"\n      using  \\<rho>'_def case_assms assms unfolding TT2_def by auto\n    then show \"\\<exists>\\<sigma>'\\<in>P. \\<rho> @ [X \\<union> Y]\\<^sub>R # \\<sigma> = [Event e]\\<^sub>E # \\<sigma>'\"\n      by (simp add: \\<rho>'_def)\n  qed\nnext\n  assume \"e \\<notin> Outs\"\n  then show \"TT2 (e \\<rightarrow>\\<^sub>C\\<^bsup>Outs\\<^esup> P)\"\n    using assms by (simp add: PrefixIOTT_input_eq_PrefixTT TT2_Prefix)\nqed\n\nlemma TT3_PrefixIOTT:\n  assumes \"TT1 P\" \"TT3 P\"\n  shows \"TT3 (e \\<rightarrow>\\<^sub>C\\<^bsup>Outs\\<^esup> P)\"\nproof (cases \"e \\<in> Outs\")\n  assume \"e \\<in> Outs\"\n  then show \"TT3 (e \\<rightarrow>\\<^sub>C\\<^bsup>Outs\\<^esup> P)\"\n    unfolding PrefixIOTT_def TT3_def \n  proof auto\n    fix \\<rho> \\<sigma> X \\<sigma>'\n    assume case_assms: \"e \\<in> Outs\" \"\\<sigma>' \\<in> P\" \"\\<rho> @ [X]\\<^sub>R # \\<sigma> = [Event e]\\<^sub>E # \\<sigma>'\"\n    obtain \\<rho>' where \\<rho>'_def: \"\\<rho> = [Event e]\\<^sub>E # \\<rho>'\"\n      using case_assms(3) by (induct \\<rho> rule:ttWF.induct, auto)\n    have \"\\<rho>' @ [insert Tick X]\\<^sub>R # \\<sigma> \\<in> P\"\n      using  \\<rho>'_def case_assms assms unfolding TT3_def by auto\n    then show \"\\<exists>\\<sigma>'\\<in>P. \\<rho> @ [insert Tick X]\\<^sub>R # \\<sigma> = [Event e]\\<^sub>E # \\<sigma>'\"\n      by (simp add: \\<rho>'_def)\n  qed\nnext\n  assume \"e \\<notin> Outs\"\n  then show \"TT3 (e \\<rightarrow>\\<^sub>C\\<^bsup>Outs\\<^esup> P)\"\n    by (simp add: PrefixIOTT_input_eq_PrefixTT TT3_Prefix assms)\nqed\n\nlemma IOTT0_PrefixIOTT:\n  \"IOTT0 Outs P \\<Longrightarrow> IOTT0 Outs (e \\<rightarrow>\\<^sub>C\\<^bsup>Outs\\<^esup> P)\"\n  unfolding IOTT0_def PrefixIOTT_def\nproof auto\n  fix s\n  assume case_assms: \"s \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\" \"e \\<notin> Outs\"\n  then have \"IOTT0_trace Outs s \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\"\n    apply - apply (induct s rule:tocks.induct, auto)\n    using tocks.empty_in_tocks apply blast\n    using tocks.simps by fastforce\n  then show \"\\<forall>sa\\<in>tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}.\n            IOTT0_trace Outs s \\<noteq> sa \\<and> (\\<forall>\\<sigma>\\<in>P. IOTT0_trace Outs s \\<noteq> sa @ [Event e]\\<^sub>E # \\<sigma>) \\<Longrightarrow>\n         \\<exists>sa\\<in>tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}. \\<exists>X. Tock \\<notin> X \\<and> Event e \\<notin> X \\<and> IOTT0_trace Outs s = sa @ [[X]\\<^sub>R]\"\n    by auto\nnext\n  fix s X\n  assume case_assms: \"s \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\" \"e \\<notin> Outs\" \"Tock \\<notin> X\" \"Event e \\<notin> X\"\n  then have \"IOTT0_trace Outs s \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\"\n    apply - apply (induct s rule:tocks.induct, auto)\n    using tocks.empty_in_tocks apply blast\n    using tocks.simps by fastforce\n  then show \"\\<exists>sa\\<in>tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}.\n              \\<exists>Xa. Tock \\<notin> Xa \\<and> Event e \\<notin> Xa \\<and> IOTT0_trace Outs (s @ [[X]\\<^sub>R]) = sa @ [[Xa]\\<^sub>R]\"\n    apply (rule_tac x=\"IOTT0_trace Outs s\" in bexI, simp_all)\n    by (rule_tac x=\"X \\<union> Event ` Outs\" in exI, auto simp add: case_assms IOTT0_trace_append_refusal)\nnext\n  fix s\n  assume case_assms: \"s \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\" \"e \\<notin> Outs\"\n  then have \"IOTT0_trace Outs s \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\"\n    apply - apply (induct s rule:tocks.induct, auto)\n    using tocks.empty_in_tocks apply blast\n    using tocks.simps by fastforce\n  then show \"\\<forall>sa\\<in>tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}.\n            IOTT0_trace Outs s \\<noteq> sa \\<and> (\\<forall>\\<sigma>\\<in>P. IOTT0_trace Outs s \\<noteq> sa @ [Event e]\\<^sub>E # \\<sigma>) \\<Longrightarrow>\n         \\<exists>sa\\<in>tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}. \\<exists>X. Tock \\<notin> X \\<and> Event e \\<notin> X \\<and> IOTT0_trace Outs s = sa @ [[X]\\<^sub>R]\"\n    by auto\nnext\n  fix s \\<sigma>\n  assume case_assms: \"s \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\" \"e \\<notin> Outs\" \"\\<sigma> \\<in> P\" \n    \"\\<forall>x. x \\<in> P \\<longrightarrow> IOTT0_trace Outs x \\<in> P\" \n  then have \"IOTT0_trace Outs s \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\"\n    apply - apply (induct s rule:tocks.induct, auto)\n    using tocks.empty_in_tocks apply blast\n    using tocks.simps by fastforce\n  also have \"IOTT0_trace Outs \\<sigma> \\<in> P\"\n    using case_assms(3) case_assms(4) by blast\n  then show \"\\<forall>sa\\<in>tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}. IOTT0_trace Outs (s @ [Event e]\\<^sub>E # \\<sigma>) \\<noteq> sa \\<and>\n              (\\<forall>\\<sigma>'\\<in>P. IOTT0_trace Outs (s @ [Event e]\\<^sub>E # \\<sigma>) \\<noteq> sa @ [Event e]\\<^sub>E # \\<sigma>') \\<Longrightarrow>\n           \\<exists>sa\\<in>tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}.\n              \\<exists>X. Tock \\<notin> X \\<and> Event e \\<notin> X \\<and> IOTT0_trace Outs (s @ [Event e]\\<^sub>E # \\<sigma>) = sa @ [[X]\\<^sub>R]\"\n    using calculation apply (erule_tac x=\"IOTT0_trace Outs s\" in ballE, auto)\n    by (erule_tac x=\"IOTT0_trace Outs \\<sigma>\" in ballE, auto simp add: IOTT0_trace_append)\nqed\n\nend", "meta": {"author": "UoY-RoboStar", "repo": "tick-tock-CSP", "sha": "7186d2e7f70116589850112a7353bc521372c913", "save_path": "github-repos/isabelle/UoY-RoboStar-tick-tock-CSP", "path": "github-repos/isabelle/UoY-RoboStar-tick-tock-CSP/tick-tock-CSP-7186d2e7f70116589850112a7353bc521372c913/IOTickTock/IOTickTock_Prefix.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.29864584808453953}}
{"text": "section {* Constant Time (inductive) *}\n\ntheory Wasm_Constant_Time_Ind imports Wasm_Secret begin\n\ndefinition config_actions :: \"[s, v list, e list, nat, action list] \\<Rightarrow> bool\" (\"p'_actions \\<lparr>_;_;_\\<rparr> _ _\" 60) where\n  \"config_actions s vs es i as \\<equiv> (\\<exists>s' vs' es'. \\<lparr>s;vs;es\\<rparr> as^^\\<leadsto>_i \\<lparr>s';vs';es'\\<rparr>)\"\n\ndefinition config_trace_set_ind :: \"[(s \\<times> v list \\<times> e list), nat] \\<Rightarrow> (action list) set\" where\n  \"config_trace_set_ind \\<equiv> \\<lambda>(s,vs,es) i. Collect (config_actions s vs es i)\"\n\nlemma config_actions_indistinguishable_secrets_ind:\n  assumes \"(p_actions \\<lparr>s;vs;es\\<rparr> i as)\"\n          \"(s,vs,es) \\<sim>_c (s',vs',es')\"\n          \"\\<turnstile>_i s;vs;es : (Untrusted,ts)\"\n  shows \"\\<exists>as'. (p_actions \\<lparr>s';vs';es'\\<rparr> i as') \\<and> list_all2 action_indistinguishable as as'\"\n  using assms(1,3) config_indistinguishable_trace_noninterference[OF _ assms(2)]\n        config_indistinguishable_imp_config_typing[OF _ assms(2)]\n  unfolding config_actions_def\n  by blast\n\nlemma config_actions_indistinguishable_secrets_abs_ind:\n  assumes \"(p_actions \\<lparr>s;vs;es\\<rparr> i as)\"\n          \"(s,vs,es) \\<sim>_c (s',vs',es')\"\n          \"\\<turnstile>_i s;vs;es : (Untrusted,ts)\"\n  shows \"\\<exists>as'. (p_actions \\<lparr>s';vs';es'\\<rparr> i as') \\<and> ($\\<A> as) = ($\\<A> as')\"\n  using Quotient3_observation config_actions_indistinguishable_secrets_ind[OF assms]\n  unfolding Quotient3_def\n  by metis\n\nlemma config_trace_set_ind_indistinguishable_secrets_ind:\n  assumes \"as \\<in> (config_trace_set_ind (s,vs,es) i)\"\n          \"(s,vs,es) \\<sim>_c (s',vs',es')\"\n          \"\\<turnstile>_i s;vs;es : (Untrusted,ts)\"\n  shows \"\\<exists>as' \\<in> (config_trace_set_ind (s',vs',es') i). list_all2 action_indistinguishable as as'\"\nproof -\n  have \"(p_actions \\<lparr>s;vs;es\\<rparr> i as)\"\n    using assms(1)\n    unfolding config_trace_set_ind_def\n    by fastforce\n  then obtain as' where \"(p_actions \\<lparr>s';vs';es'\\<rparr> i as') \\<and> list_all2 action_indistinguishable as as'\"\n    using config_actions_indistinguishable_secrets_ind[OF _ assms(2,3)]\n    by fastforce\n  thus ?thesis\n    unfolding config_trace_set_ind_def\n    by fastforce\nqed\n\nlemma config_actions_indistinguishable_secrets_abs_set_ind:\n  assumes \"t \\<in> (image abs_obs (config_trace_set_ind (s,vs,es) i))\"\n          \"(s,vs,es) \\<sim>_c (s',vs',es')\"\n          \"\\<turnstile>_i s;vs;es : (Untrusted,ts)\"\n  shows \"t \\<in> (image abs_obs (config_trace_set_ind (s',vs',es') i))\"\nproof -\n  obtain as where \"(p_actions \\<lparr>s;vs;es\\<rparr> i as) \\<and> ($\\<A> as) = t\"\n    using assms(1)\n    unfolding config_trace_set_ind_def\n    by fastforce\n  then obtain as' where \"(p_actions \\<lparr>s';vs';es'\\<rparr> i as') \\<and> ($\\<A> as') = t\"\n    using config_actions_indistinguishable_secrets_abs_ind[OF _ assms(2)] assms(3)\n    by fastforce\n  thus ?thesis\n    unfolding config_trace_set_ind_def\n    by fastforce\nqed\n\nlemma config_actions_indistinguishable_secrets_abs_set_equiv_ind:\n  assumes \"(s,vs,es) \\<sim>_c (s',vs',es')\"\n          \"\\<turnstile>_i s;vs;es : (Untrusted,ts)\"\n  shows \"(image abs_obs (config_trace_set_ind (s,vs,es) i)) = (image abs_obs (config_trace_set_ind (s',vs',es') i))\"\n  using config_actions_indistinguishable_secrets_abs_set_ind[OF _ assms(1,2)]\n        config_indistinguishable_imp_config_typing[OF assms(2,1)]\n        config_actions_indistinguishable_secrets_abs_set_ind[OF _ config_indistinguishable_symm[OF assms(1)]]\n  by fastforce\n\nlift_definition config_obs_set_ind :: \"((s \\<times> v list \\<times> e list) \\<times> nat) \\<Rightarrow> observation set\" is \"(\\<lambda>(c,i). (config_trace_set_ind c i))\" .\n\nlift_definition config_untrusted_quot_obs_set_ind :: \"config_untrusted_quot \\<Rightarrow> observation set\" is \"(\\<lambda>c. config_obs_set_ind c)\"\nproof -\n  fix prod1 prod2\n  assume assms:\"prod1 \\<sim>_cp prod2\"\n  show \"config_obs_set_ind prod1 = config_obs_set_ind prod2\"\n  proof (cases prod1; cases prod2)\n    fix c1 i1 c2 i2\n    assume prod_assms:\"prod1 = (c1,i1)\" \"prod2 = (c2,i2)\"\n    show ?thesis\n    proof (cases c1; cases c2)\n      fix s vs es s' vs' es'\n      assume config_assms:\"c1 = (s,vs,es)\" \"c2 = (s',vs',es')\"\n      obtain ts where ts_def:\"(s,vs,es) \\<sim>_c (s',vs',es')\"\n                             \"\\<turnstile>_i1 s;vs;es : (Untrusted,ts)\"\n                             \"i1 = i2\"\n        using assms prod_assms config_assms\n        unfolding config_untrusted_equiv_def\n        by fastforce\n      thus ?thesis\n        using assms prod_assms config_assms config_actions_indistinguishable_secrets_abs_set_equiv_ind\n        unfolding config_obs_set_ind_def\n        by simp\n    qed\n  qed\nqed\n\ndefinition constant_time_ind :: \"((s \\<times> v list \\<times> e list) \\<times> nat) \\<Rightarrow> bool\" where\n  \"constant_time_ind = (\\<lambda>(c, i). \\<forall>c'. (c \\<sim>_c c') \\<longrightarrow> ((config_obs_set_ind (c,i)) = (config_obs_set_ind (c',i))))\"\n\ntheorem config_untrusted_constant_time_ind:\n  assumes \"\\<turnstile>_i s;vs;es : (Untrusted,ts)\"\n  shows \"constant_time_ind ((s,vs,es),i)\"\n    using config_actions_indistinguishable_secrets_abs_set_equiv_ind assms\n    unfolding constant_time_ind_def config_obs_set_ind_def\n    by simp\n\nlift_definition config_untrusted_quot_constant_time_ind :: \"config_untrusted_quot \\<Rightarrow> bool\" is constant_time_ind\nproof -\n  fix prod1 prod2\n  assume assms:\"prod1 \\<sim>_cp prod2\"\n  show \"constant_time_ind prod1 = constant_time_ind prod2\"\n  proof (cases prod1; cases prod2)\n    fix c i c' i'\n    assume local_assms:\"prod1 = (c,i)\" \"prod2 = (c',i')\"\n    show ?thesis\n    proof (cases c; cases c')\n      fix s vs es s' vs' es'\n      assume inner_assms:\"c = (s,vs,es)\" \"c' = (s',vs',es')\"\n      thus ?thesis\n        using assms local_assms config_untrusted_constant_time_ind\n        unfolding config_untrusted_equiv_def\n        by (simp del: config_indistinguishable.simps) (metis config_indistinguishable_imp_config_typing)\n    qed\n  qed\nqed\n  \nlemma config_untrusted_quot_constant_time_trivial_ind:\n  \"config_untrusted_quot_constant_time_ind = (\\<lambda>x. True)\"\n  using config_untrusted_constant_time_ind rep_config_untrusted_quot_typing\n  unfolding config_untrusted_quot_constant_time_ind.rep_eq\n  by (metis prod.exhaust)\n\ndefinition \"trace_set_equiv = rel_set (list_all2 action_indistinguishable)\"\n\ndefinition constant_time_traces_ind :: \"((s \\<times> v list \\<times> e list) \\<times> nat) \\<Rightarrow> bool\" where\n  \"constant_time_traces_ind = (\\<lambda>(c, i). \\<forall>c'. (c \\<sim>_c c') \\<longrightarrow> trace_set_equiv (config_trace_set_ind c i) (config_trace_set_ind c' i))\"\n\nlemma config_untrusted_constant_time_traces:\n  assumes \"\\<turnstile>_i s;vs;es : (Untrusted,ts)\"\n  shows \"constant_time_traces_ind ((s,vs,es),i)\"\n  using assms\n  unfolding trace_set_equiv_def rel_set_def constant_time_traces_ind_def\n  apply (simp del: config_indistinguishable.simps)\n  apply (metis config_indistinguishable_imp_config_typing config_indistinguishable_symm config_trace_set_ind_indistinguishable_secrets_ind observation.abs_eq_iff)\n  done\nend", "meta": {"author": "PLSysSec", "repo": "ct-wasm-proofs", "sha": "3fa5c38ecda3d05c351096ba5e6d7ba1df793c21", "save_path": "github-repos/isabelle/PLSysSec-ct-wasm-proofs", "path": "github-repos/isabelle/PLSysSec-ct-wasm-proofs/ct-wasm-proofs-3fa5c38ecda3d05c351096ba5e6d7ba1df793c21/CT-WASM_model/Wasm_Constant_Time_Ind.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6370307944803832, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.2986340653246728}}
{"text": "section \\<open>Array-Blocks --- Reasoning Setup\\<close>\ntheory Sep_Array_Block_RS\nimports \"../basic/LLVM_Basic_Main\" Sep_Block_Allocator_RS\nbegin\n\ntype_synonym 'aval ablock = \"nat \\<Rightarrow> 'aval\"\n\ninstantiation baddr :: (this_addr) addr_algebra begin\n  definition \"abase \\<equiv> \\<lambda>BADDR i va \\<Rightarrow> va=this_addr\"\n  definition \"(~\\<^sub>a) \\<equiv> \\<lambda>BADDR i1 va1 \\<Rightarrow> \\<lambda>BADDR i2 va2 \\<Rightarrow> va1=this_addr \\<and> va2=this_addr\"\n  definition \"(-\\<^sub>a) \\<equiv> \\<lambda>BADDR i1 va1 \\<Rightarrow> \\<lambda>BADDR i2 va2 \\<Rightarrow> i1 - i2\"\n  definition \"(+\\<^sub>a) \\<equiv> \\<lambda>BADDR i va \\<Rightarrow> \\<lambda>j. BADDR (i+j) va\"\n\n  lemma abase_baddr_simp[simp]: \"abase (BADDR i va) \\<longleftrightarrow> va=this_addr\"\n    by (simp add: abase_baddr_def)\n  lemma acompat_baddr_simp[simp]: \"BADDR i1 va1 ~\\<^sub>a BADDR i2 va2 \\<longleftrightarrow> va1=this_addr \\<and> va2=this_addr\"\n    by (simp add: acompat_baddr_def)\n  lemma adiff_baddr_simp[simp]: \"BADDR i1 va1 -\\<^sub>a BADDR i2 va2 = i1 - i2\"\n    by (simp add: adiff_baddr_def)\n  lemma aidx_baddr_simp[simp]: \"BADDR i va +\\<^sub>a j = BADDR (i+j) va\"\n    by (simp add: aidx_baddr_def)\n  \n  instance\n    apply standard\n    apply (intro part_equivpI sympI transpI)\n    apply (auto \n      simp: abase_baddr_def acompat_baddr_def adiff_baddr_def aidx_baddr_def\n      split: baddr.splits)\n    done\n\nend\n\n\nlocale array_block2 = array_block1 static_err mem_err vload vstore vgep\n    for static_err :: 'err\n    and mem_err :: 'err\n    and vload :: \"'vaddr::this_addr \\<Rightarrow> ('val,_,'val,'err) M\"\n    and vstore :: \"'val \\<Rightarrow> 'vaddr \\<Rightarrow> (unit,_,'val,'err) M\"\n    and vgep :: \"'vaddr \\<Rightarrow> 'vidx \\<Rightarrow> ('vaddr,_,'val,'err) M\"\n    \n+ fixes \\<alpha>v :: \"'val \\<Rightarrow> 'aval::unique_zero_sep_algebra\"\n    and vpto :: \"'val \\<Rightarrow> 'vaddr \\<Rightarrow> 'aval \\<Rightarrow> bool\"\n    and vcomplete :: \"'aval \\<Rightarrow> bool\"\n    \n  assumes vload_rule: \"htriple \\<alpha>v (vpto x va) (vload va) (\\<lambda>r. \\<up>(r=x) ** vpto x va)\" \n      and vstore_rule: \"htriple \\<alpha>v (vpto xx va) (vstore x va) (\\<lambda>_. vpto x va)\"\n      and vpto_notZ: \"\\<And>x a. \\<not>vpto x a 0\"\n      and vcompleteD: \"\\<And>v v'. \\<lbrakk>vcomplete v; v##v'\\<rbrakk> \\<Longrightarrow> v'=0\"\n      and vpto_this: \"\\<And>v av. vpto v this_addr av \\<longleftrightarrow> av = \\<alpha>v v\"\n      and \\<alpha>v_complete: \"\\<And>v. vcomplete (\\<alpha>v v)\"\n      \n      \nbegin\n\n  (*\n  lemma is_arr_baddr_idx[simp]: \"is_arr_baddr (idx_baddr a i) \\<longleftrightarrow> is_arr_baddr a\"\n    by (auto simp: is_arr_baddr_def idx_baddr_def split: baddr.splits)\n  \n  lemma idx_baddr_add[simp]: \"idx_baddr (idx_baddr a i) j = idx_baddr a (i+j)\"\n    by (auto simp: idx_baddr_def split: prod.splits baddr.splits)\n    \n  definition \"idx_ptr \\<equiv> \\<lambda>RP_ADDR (ADDR bi ba) \\<Rightarrow> \\<lambda>i. RP_ADDR (ADDR bi (idx_baddr ba i)) | RP_NULL \\<Rightarrow> \\<lambda>i. RP_NULL\"\n  *)\n  \n  (* TODO: Rename to is_block_ptr! *)    \n  definition is_block_ptr :: \"'vaddr baddr addr rptr \\<Rightarrow> bool\" \n    where \"is_block_ptr \\<equiv> \\<lambda>RP_ADDR (ADDR bi ba) \\<Rightarrow> ba=this_addr | _ \\<Rightarrow> False\"\n  \n  \n  (*definition \"is_arr_ptr \\<equiv> \\<lambda>RP_ADDR (ADDR bi ba) \\<Rightarrow> is_arr_baddr ba | _ \\<Rightarrow> False\"*)\n  \n  (* \n  lemma is_arr_ptr_simps[simp]:\n    \"is_arr_ptr (RP_ADDR (ADDR bi ba)) = is_arr_baddr ba\"    \n    \"is_arr_ptr RP_NULL \\<longleftrightarrow> False\"\n    by (auto simp: is_arr_ptr_def)\n  *)\n\n  \n  lemma is_block_ptr_simps[simp]:\n    \"\\<not>is_block_ptr RP_NULL\"\n    \"is_block_ptr (RP_ADDR (ADDR bi ba)) \\<longleftrightarrow> ba=this_addr\"\n    by (auto simp: is_block_ptr_def)\n    \n  lemma block_ptr_imp_abase[simp, intro]: \"is_block_ptr p \\<Longrightarrow> abase p\"  \n    by (auto simp: is_block_ptr_def this_addr_baddr_def split: rptr.splits addr.splits)\n    \n  \n  (*\n  \n  lemma idx_ptr_add[simp]: \"idx_ptr (idx_ptr a i) j = idx_ptr a (i+j)\"\n    by (auto simp: idx_ptr_def split: rptr.splits addr.splits)\n    \n  lemma is_arr_ptr_idx[simp]: \"is_arr_ptr (idx_ptr p i) \\<longleftrightarrow> is_arr_ptr p\"\n    by (cases p) (auto simp: idx_ptr_def is_arr_ptr_def split: rptr.splits addr.splits)\n  *)  \n    \n  lemma \\<alpha>v_notZ[simp]: \"\\<alpha>v v \\<noteq> 0\"  \n    using vpto_notZ vpto_this by fastforce  \n  \n  definition \"\\<alpha> \\<equiv> list\\<alpha> \\<alpha>v\"\n\n  definition pto :: \"'val \\<Rightarrow> 'vaddr baddr \\<Rightarrow> 'aval ablock \\<Rightarrow> bool\"\n    where \"pto \\<equiv> \\<lambda>x. \\<lambda>BADDR i va \\<Rightarrow> \\<lambda>s. \\<exists>v. i\\<ge>0 \\<and> s=0(nat i:=v) \\<and> vpto x va v\"\n  \n  definition tag_of :: \"'val block \\<Rightarrow> int\" where \"tag_of \\<equiv> int o length\"\n  \n  definition \"is_complete_tag ablk n \\<equiv> 0\\<le>n \\<and> (\\<forall>i. (ablk i \\<noteq> 0 \\<longleftrightarrow> i<nat n) \\<and> (\\<forall>i. ablk i \\<noteq> 0 \\<longrightarrow> vcomplete (ablk i)))\"\n    \n  \n  definition \"array_lifter i \\<equiv> idx_lifter (\\<lambda>_. ()) \\<alpha>v i\"\n  \n  lemma array_lifter_simps[simp]: \n    \"sep_lifter.\\<alpha>s (array_lifter i) = \\<alpha>v\"  \n    \"sep_lifter.\\<alpha>b (array_lifter i) = \\<alpha>\"  \n    \"sep_lifter.L (array_lifter i) = idx\\<^sub>L i\"\n    unfolding array_lifter_def \\<alpha>_def by auto\n  \n  interpretation array_lifter: sep_lifter \"array_lifter i\" for i\n    unfolding array_lifter_def by simp\n\n  lemma pto_is_lift: \"pto x = (\\<lambda>BADDR i va \\<Rightarrow> (\\<up>(i\\<ge>0) ** array_lifter.lift_assn (nat i) (vpto x va)))\"  \n    unfolding array_lifter.lift_assn_def\n    apply (rule ext)\n    apply (clarsimp simp: array_lifter_def pto_def split: baddr.splits)\n    apply (intro ext)\n    apply (auto simp: sep_algebra_simps pred_lift_extract_simps)\n    by (metis fun_upd_triv fun_upd_upd)\n    \n  lemma lift_is_pto: \"i\\<ge>0 \\<Longrightarrow> array_lifter.lift_assn (nat i) (vpto x va) = pto x (BADDR i va)\"  \n    by (simp add: pto_is_lift sep_algebra_simps pred_lift_extract_simps)\n    \n  declare vpto_notZ[simp]  \n    \n  \n  lemma load_rule: \"htriple \\<alpha> (pto x va) (load va) (\\<lambda>r. \\<up>(r=x) ** pto x va)\"\n    unfolding load_def\n    supply pto_is_lift[simp]\n    apply (cases va; clarsimp simp: htriple_extract_pre_pure sep_algebra_simps)\n    using array_lifter.lift_operation[simplified, OF _ vload_rule, simplified] \n    .\n    \n  lemma store_rule: \"htriple \\<alpha> (pto xx va) (store x va) (\\<lambda>_. pto x va)\"\n    unfolding store_def\n    supply pto_is_lift[simp]\n    apply (cases va; clarsimp simp: htriple_extract_pre_pure sep_algebra_simps)\n    using array_lifter.lift_operation[simplified, OF _ vstore_rule, simplified] \n    .\n    \n  \n  lemma load_pres_tag: \"wlp (load a) (\\<lambda>_ s'. tag_of s' = tag_of s) s\"\n    unfolding load_def \n    apply (auto simp: wlp_def run_simps tag_of_def split: prod.splits option.splits baddr.splits)\n    apply (rule mwp_trivI)\n    by auto\n\n  lemma store_pres_tag: \"wlp (store a x) (\\<lambda>_ s'. tag_of s' = tag_of s) s\"\n    unfolding store_def \n    apply (auto simp: wlp_def run_simps tag_of_def split: prod.splits option.splits baddr.splits)\n    apply (rule mwp_trivI)\n    by auto\n    \n  lemma complete_tag: \n    \"\\<lbrakk>is_complete_tag ablock (tag_of cblock); ablock ## f; \\<alpha> cblock = ablock + f\\<rbrakk> \\<Longrightarrow> f = 0\"  \n    apply (auto simp: is_complete_tag_def tag_of_def)\n    by (smt \\<alpha>_def disjoint_zero_sym list\\<alpha>_in_range sep_add_disj_eq sep_disj_fun_def sep_disj_zero unique_zero vcompleteD)\n    \n  (* TODO: Move *)\n  lemma Z_upd_eq_Z_iff[simp]: \"0(i:=x) = 0 \\<longleftrightarrow> x=0\" by (auto simp: fun_eq_iff)\n  \n  lemma pto_notZ: \"\\<not> pto x a 0\"\n    apply (cases a)\n    apply (auto simp: pto_def sep_algebra_simps)\n    done\n      \n  lemma checked_idx_baddr_rule: \"abase a \n    \\<Longrightarrow> htriple \\<alpha> (pto xx (a +\\<^sub>a i)) (checked_idx_baddr a i) (\\<lambda>r. \\<up>(r=a +\\<^sub>a i) ** pto xx (a +\\<^sub>a i))\"\n    apply (rule htripleI')\n    unfolding checked_idx_baddr_def check_addr_def pto_is_lift\n    apply (clarsimp simp: pred_lift_extract_simps split: baddr.splits)\n    apply (frule (1) array_lifter.infer_pre_get_with_frame, simp, simp)\n    apply (force simp: wp_def run_simps aidx_baddr_def abase_baddr_def sep_algebra_simps split: prod.splits baddr.splits)\n    done\n    \n\n  sublocale ba: block_allocator2 static_err mem_err load store check_addr \\<alpha> pto tag_of is_complete_tag\n    apply unfold_locales\n    apply (rule load_rule)\n    apply (rule store_rule)\n    apply (rule load_pres_tag)\n    apply (rule store_pres_tag)\n    apply (rule complete_tag; assumption)\n    apply (rule pto_notZ)\n    done\n       \n      \n  lemma list\\<alpha>_rep_nn: \"list\\<alpha> \\<alpha>v (replicate n v) n = 0\"\n    by (auto simp: list\\<alpha>_def)\n  \n    \n  lemma pto_this_exact: \"pto x (BADDR i this_addr) = (\\<up>(i\\<ge>0) ** EXACT (0(nat i:=\\<alpha>v x)))\" \n    by (auto simp: pto_def vpto_this pred_lift_extract_simps del: ext intro!: ext)\n\n  lemma ba_pto_this_exact: \n    \"\\<lbrakk>is_block_ptr p; i\\<ge>0\\<rbrakk> \n    \\<Longrightarrow> ba.pto x (p +\\<^sub>a i) = EXACT (0(rptr_the_block_index p := (0(nat i:=\\<alpha>v x),0)))\"  \n    apply (auto \n      simp: ba.pto_def aidx_baddr_def pto_this_exact this_addr_baddr_def \n      simp: pred_lift_extract_simps is_block_ptr_def\n      split: rptr.splits addr.splits baddr.splits)\n    done\n  \n  lemma lift_pto_exact: \"i\\<ge>0 \\<Longrightarrow> ba.block_lifter.lift_assn bi (pto v (this_addr +\\<^sub>a i)) = EXACT (0(bi := (0(nat i:=\\<alpha>v v),0)))\"  \n    apply (auto \n      simp:  aidx_baddr_def pto_this_exact this_addr_baddr_def \n      simp: pred_lift_extract_simps is_block_ptr_def\n      split: rptr.splits addr.splits baddr.splits)\n    done\n    \n\n  (* TODO: Move *)  \n  lemma atLeast_lessThan_plus1: \n    \"l\\<le>v \\<Longrightarrow> {l..<1+v::int} = insert v {l..<v}\" \n    \"l\\<le>v \\<Longrightarrow> {l..<v+1::int} = insert v {l..<v}\" \n    by auto\n    \n  lemma sep_set_img_int_range_to_nat: \"(\\<Union>*i\\<in>{0..<int n}. f i) = (\\<Union>*i\\<in>{0..<n}. f (int i))\"  \n    apply (induction n)\n    apply (auto simp: atLeast_lessThan_plus1 atLeast0_lessThan_Suc)\n    done\n    \n    \n  lemma ba_block_alt: \n    \"ba.block (\\<alpha> (init v n)) p = (\\<up>(is_block_ptr p) ** (\\<Union>*i\\<in>{0..<int n}. ba.pto v (p +\\<^sub>a i)))\"\n  proof -\n    have ba_block_alt_aux: \"(\\<Union>*i\\<in>{0..<int n}. EXACT (0(x1 := (0(nat i := \\<alpha>v v), 0)))) = EXACT (0(x1 := (list\\<alpha> \\<alpha>v (replicate n v), 0)))\"\n      for x1::nat\n      apply (induction n)\n      supply replicate_Suc_conv_snoc[simp] replicate_Suc[simp del]\n      subgoal by (auto simp: sep_algebra_simps del: ext intro!: ext)\n      subgoal\n        apply simp\n        by (auto \n          simp: list\\<alpha>_snoc sep_algebra_simps sep_disj_fun_def atLeast0_lessThan_Suc atLeast_lessThan_plus1 sep_conj_def list\\<alpha>_rep_nn\n          cong del: if_cong \n          del: ext intro!: ext)\n      done\n    \n    have foo: \"\\<lbrakk>P=Q; Q \\<Longrightarrow> X=Y\\<rbrakk> \\<Longrightarrow> (\\<up>P**X) = (\\<up>Q**Y)\" for P Q X Y by auto\n    have [simp]: \"(\\<Union>*x\\<in>{0..<int n}. ba.pto v ((RP_ADDR (ADDR x1 (this_addr +\\<^sub>a x))))) \n      = (\\<Union>*x\\<in>{0..<int n}. EXACT (0(x1 := (0(nat x := \\<alpha>v v), 0))))\" for x1 \n      apply (rule sep_set_img_cong)\n      apply (auto simp: lift_pto_exact)\n      done\n  \n    note [simp del] = ba.pto_addr_eq  \n      \n    show ?thesis\n      unfolding init_def ba.block_def\n      by (auto \n        split: rptr.splits addr.splits \n        simp: sep_algebra_simps\n        simp: \\<alpha>_def ba_block_alt_aux \n        intro!: foo\n        )\n  qed    \n\n  \n  lemma ba_block_exs_alt_aux: \n    assumes \"n\\<ge>0\"\n    shows \"(\\<Union>*i\\<in>{0..<n}. (EXS x. ba.pto x ((RP_ADDR (ADDR bi (this_addr +\\<^sub>a i)))))) \n      = (EXS xs. \\<up>(int (length xs) = n) ** EXACT (0(bi := (list\\<alpha> \\<alpha>v xs, 0))))\"  \n    using assms\n  proof (induction n rule: int_induct[where k=0])\n    case base\n    then show ?case by (auto simp: sep_algebra_simps pred_lift_extract_simps del: ext intro!: ext)\n  next\n    case (step1 n)\n\n    \n        \n    note [simp] = \\<open>0\\<le>n\\<close>\n    note IH = step1.IH[simplified]\n\n    have [simp]: \"n+1\\<noteq>0\" using \\<open>0\\<le>n\\<close> by linarith\n        \n    note replicate_Suc_conv_snoc[simp] replicate_Suc[simp del]\n    show ?case\n      apply (simp add: atLeast_lessThan_plus1)\n      apply (simp add: IH)\n      apply (rule ext)\n      apply (auto simp: sep_algebra_simps pred_lift_extract_simps sep_disj_fun_def sep_conj_def list\\<alpha>_at_len lift_pto_exact)\n      subgoal for x xs\n        apply (rule exI[where x=\"xs@[x]\"])\n        apply (auto del: ext intro!: ext simp: list\\<alpha>_snoc sep_algebra_simps list\\<alpha>_at_len\n          simp: this_addr_baddr_def pto_this_exact\n        )\n        done\n      subgoal for xs\n        apply (rule exI[where x=\"last xs\"])\n        apply (rule exI[where x=\"butlast xs\"]; simp)\n        apply (cases xs rule: rev_cases)\n        apply (auto simp: list\\<alpha>_gt_len sep_algebra_simps list\\<alpha>_snoc del: ext intro!: ext)\n        done\n      done\n  next    \n    case (step2 n) thus ?case by (auto)     \n  qed \n  \n  lemma ba_block_exs_alt: \n    \"\\<lbrakk>is_block_ptr p; n\\<ge>0\\<rbrakk> \\<Longrightarrow> (\\<Union>*i\\<in>{0..<n}. EXS v. ba.pto v (p +\\<^sub>a i)) = (EXS blk. \\<up>(int (length blk) = n) ** ba.block (\\<alpha> blk) p)\"\n    unfolding init_def ba.block_def\n    supply [simp del] = ba.pto_addr_eq\n    apply (cases p rule: ba.rptr_cases.cases; simp)\n    apply (rule ext)\n    apply (auto \n      split: rptr.splits addr.splits \n      simp: sep_algebra_simps pred_lift_extract_simps \\<alpha>_def ba_block_exs_alt_aux\n      )\n    done\n    \n  lemma tag_of_init[simp]: \"tag_of (init v n) = int n\" by (auto simp: tag_of_def init_def)\n\n  lemma ba_allocn_rule: \"htriple ba.\\<alpha> \\<box> (ba_allocn v n) (\\<lambda>r. (\\<Union>*i\\<in>{0..<int n}. ba.pto v (r +\\<^sub>a i)) ** ba.tag (int n) r ** \\<up>(abase r))\"\n    unfolding ba_allocn_def\n    apply (rule cons_rule[OF ba.alloc_rule])\n    apply simp\n    apply (simp add: ba_block_alt sep_algebra_simps pred_lift_extract_simps)\n    done\n\n  (* TODO: Move to gen_wp locale *)          \n  lemma wp_cons: \"wp c Q s \\<Longrightarrow> (\\<And>x s. Q x s \\<Longrightarrow> Q' x s) \\<Longrightarrow> wp c Q' s\"  \n    by (simp add: wp_monoI)\n    \n  lemma blk_complete_tag[simp]: \"is_complete_tag (\\<alpha> blk) (int (length blk))\"  \n    by (auto simp: is_complete_tag_def \\<alpha>_def list\\<alpha>_def \\<alpha>v_complete)\n\n  (* TODO: is_base_ptr: This logic is already encoded in ba.tag! Try to get rid of is_base_ptr! *)  \n  lemma ba_tag_extr_baseptr: \"ba.tag n p = (\\<up>(is_block_ptr p \\<and> 0\\<le>n) ** ba.tag n p)\"  \n    apply (rule ext)\n    apply (auto simp: ba.tag_def sep_algebra_simps pred_lift_extract_simps split: addr.splits rptr.splits)\n    apply (auto simp: tag_of_def)\n    done\n    \n  lemma ba_freen_rule: \"htriple ba.\\<alpha> ((\\<Union>*i\\<in>{0..<n}. EXS v. ba.pto v (p+\\<^sub>ai)) \\<and>* ba.tag n p) (ba.free p) (\\<lambda>_. \\<box>)\"\n    apply (subst ba_tag_extr_baseptr)\n    apply (rule htripleI')\n    apply (clarsimp simp: sep_algebra_simps pred_lift_extract_simps)\n    apply (simp add: ba_block_exs_alt)\n    apply (clarsimp simp: sep_algebra_simps pred_lift_extract_simps)\n    \n    subgoal for pp s f blk\n      supply R = ba.free_rule[of \"\\<alpha> blk\" p \"int (length blk)\"]\n      apply (rule R[THEN htripleD', THEN wp_cons])\n      apply assumption+\n      apply (simp add: sep_algebra_simps)\n      apply (simp add: sep_algebra_simps)\n      done\n    done\n    \n  lemma checked_idx_baddr_pres_tag: \"wlp (checked_idx_baddr (BADDR a b) i) (\\<lambda>_ s'. tag_of s' = tag_of sa) sa\"  \n    by (auto simp: wlp_def checked_idx_baddr_def check_addr_def run_simps split: prod.splits baddr.splits)\n    \n  (* TODO: Move *)  \n  lemma return_rule: \"htriple \\<alpha> P (return x) (\\<lambda>r. \\<up>(r=x)**P)\" for \\<alpha>\n    by vcg\n    \n  (* TODO: Move *)  \n  lemma wlp_return[simp]: \"wlp (return x) Q s = Q x s\"\n    by (auto simp: wlp_def run_simps)\n    \n  lemma checked_idx_ptr_rule: \"abase p \n    \\<Longrightarrow> htriple ba.\\<alpha> (ba.pto xx (p +\\<^sub>a i)) (checked_idx_ptr p i) (\\<lambda>r. \\<up>(r=p +\\<^sub>a i) ** ba.pto xx (p +\\<^sub>a i))\"\n    unfolding checked_idx_ptr_def\n    apply (cases p rule: ba.rptr_cases.cases; simp add: zoom_bind)\n    supply [vcg_rules] = ba.block_lifter.lift_operation[simplified, OF _ _ checked_idx_baddr_rule]\n    supply [vcg_rules] = ba.block_lifter.lift_operation[simplified, OF _ _ return_rule]\n    supply [simp] = pto_notZ checked_idx_baddr_pres_tag abase_baddr_def\n    supply [named_ss fri_prepare_simps] = aidx_baddr_simp\n    supply [split] = baddr.splits\n    apply vcg\n    done\n    \nend\n  \nend\n\n", "meta": {"author": "lammich", "repo": "isabelle_llvm", "sha": "6be37a9c3cae74a1134dbef2979e312abb5f7f42", "save_path": "github-repos/isabelle/lammich-isabelle_llvm", "path": "github-repos/isabelle/lammich-isabelle_llvm/isabelle_llvm-6be37a9c3cae74a1134dbef2979e312abb5f7f42/thys/vcg/Sep_Array_Block_RS.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6370307944803832, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.29863406532467274}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\nsection \"32-Bit Machine Word Setup\"\n\ntheory Machine_Word_32\n  imports Machine_Word_32_Basics More_Word Bit_Shifts_Infix_Syntax Rsplit\nbegin\n\ncontext\n  includes bit_operations_syntax\nbegin\n\ntype_synonym machine_word = \\<open>machine_word_len word\\<close>\n\nlemma word_bits_len_of:\n  \\<open>LENGTH(machine_word_len) = word_bits\\<close>\n  by (simp add: word_bits_conv)\n\nlemma word_bits_size:\n  \"size (w :: machine_word) = word_bits\"\n  by (simp add: word_bits_def word_size)\n\nlemma word_bits_word_size_conv:\n  \\<open>word_bits = word_size * 8\\<close>\n  by (simp add: word_bits_def word_size_def)\n\nlemma word_size_word_size_bits:\n  \\<open>word_size = (2 :: 'a :: semiring_1) ^ word_size_bits\\<close>\n  by (simp add: word_size_def word_size_bits_def)\n\nlemma lt_word_bits_lt_pow:\n  \"sz < word_bits \\<Longrightarrow> sz < 2 ^ word_bits\"\n  by (simp add: word_bits_conv)\n\nlemma if_then_1_else_0:\n  \"((if P then 1 else 0) = (0 :: machine_word)) = (\\<not> P)\"\n  by simp\n\nlemma if_then_0_else_1:\n  \"((if P then 0 else 1) = (0 :: machine_word)) = (P)\"\n  by simp\n\nlemmas if_then_simps = if_then_0_else_1 if_then_1_else_0\n\nlemma bool_mask [simp]:\n  \\<open>0 < x AND 1 \\<longleftrightarrow> x AND 1 = 1\\<close> for x :: machine_word\n  by (rule bool_mask') auto\n\nlemma in_16_range:\n  \"0 \\<in> S \\<Longrightarrow> r \\<in> (\\<lambda>x. r + x * (16 :: machine_word)) ` S\"\n  \"n - 1 \\<in> S \\<Longrightarrow> (r + (16 * n - 16)) \\<in> (\\<lambda>x :: machine_word. r + x * 16) ` S\"\n  by (clarsimp simp: image_def elim!: bexI[rotated])+\n\nlemma le_step_down_word_3:\n  fixes x :: machine_word\n  shows \"\\<lbrakk>x \\<le> y; x \\<noteq> y\\<rbrakk> \\<Longrightarrow> x \\<le> y - 1\"\n  by (fact le_step_down_word_2)\n\nlemma shiftr_1:\n  \"(x::machine_word) >> 1 = 0 \\<Longrightarrow> x < 2\"\n  apply transfer\n  apply (simp add: take_bit_drop_bit)\n  apply (simp add: drop_bit_Suc)\n  done\n\nlemma Suc_unat_mask_div:\n  \"Suc (unat (mask sz div word_size :: machine_word)) = 2 ^ (min sz word_bits - word_size_bits)\"\n  by (simp add: word_size_word_size_bits unat_drop_bit_eq unat_mask_eq drop_bit_mask_eq Suc_mask_eq_exp\n    flip: drop_bit_eq_div word_bits_conv)\n\nlemma ucast_not_helper:\n  fixes a::\"8 word\"\n  assumes a: \"a \\<noteq> 0xFF\"\n  shows \"ucast a \\<noteq> (0xFF::machine_word)\"\nproof\n  assume \"ucast a = (0xFF::machine_word)\"\n  also\n  have \"(0xFF::machine_word) = ucast (0xFF::8 word)\" by simp\n  finally\n  show False using a\n    apply -\n    apply (drule up_ucast_inj, simp)\n    apply simp\n    done\nqed\n\nlemma unat_less_2p_word_bits:\n  \"unat (x :: machine_word) < 2 ^ word_bits\"\n  apply (simp only: word_bits_def)\n  apply (rule unat_lt2p)\n  done\n\nlemma unat_less_word_bits:\n  fixes y :: machine_word\n  shows \"x < unat y \\<Longrightarrow> x < 2 ^ word_bits\"\n  unfolding word_bits_def\n  by (rule order_less_trans [OF _ unat_lt2p])\n\nlemma unat_mask_2_less_4:\n  \"unat (p AND mask 2 :: machine_word) < 4\"\n  by (rule unat_less_helper) (simp only: take_bit_eq_mod word_mod_less_divisor flip: take_bit_eq_mask, simp add: word_mod_less_divisor)\n\nlemma unat_mult_simple:\n  \\<open>unat (x * y) = unat x * unat y\\<close>\n    if \\<open>unat x * unat y < 2 ^ LENGTH(machine_word_len)\\<close>\n    for x y :: machine_word\n  using that by (simp flip: unat_mult_lem)\n\nlemma upto_2_helper:\n  \"{0..<2 :: machine_word} = {0, 1}\"\n  by (safe; simp) unat_arith\n\nlemma word_ge_min:\n  \\<open>- (2 ^ (word_bits - 1)) \\<le> sint x\\<close> for x :: machine_word\n  using sint_ge [of x] by (simp add: word_bits_def)\n\nlemma word_rsplit_0:\n  \"word_rsplit (0 :: machine_word) = replicate (word_bits div 8) (0 :: 8 word)\"\n  by (simp add: word_rsplit_def bin_rsplit_def word_bits_def word_size_def Cons_replicate_eq)\n\nlemma x_less_2_0_1:\n  fixes x :: machine_word\n  shows \"x < 2 \\<Longrightarrow> x = 0 \\<or> x = 1\"\n  by (rule x_less_2_0_1') auto\n\nend\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Word_Lib/Machine_Word_32.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6370307806984445, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.29863405886382904}}
{"text": "(*  Title:       Isabelle Collections Library\n    Author:      Peter Lammich <peter dot lammich at uni-muenster.de>\n    Maintainer:  Peter Lammich <peter dot lammich at uni-muenster.de>\n*)\nsection {* \\isaheader{Map Implementation by Associative Lists} *}\ntheory ListMapImpl\nimports \n  \"../spec/MapSpec\" \n  \"../../Lib/Assoc_List\" \n  \"../gen_algo/MapGA\"\nbegin\ntext_raw {*\\label{thy:ListMapImpl}*}\n\n(*@impl Map\n  @type 'a lm\n  @abbrv lm,l\n  Maps implemented by associative lists. If you need efficient \n  @{text \"insert_dj\"} operation, you should use list sets with explicit \n  invariants (lmi).\n*)\n\ntype_synonym ('k,'v) lm = \"('k,'v) assoc_list\"\n\ndefinition [icf_rec_def]: \"lm_basic_ops \\<equiv> \\<lparr>\n  bmap_op_\\<alpha> = Assoc_List.lookup,\n  bmap_op_invar = \\<lambda>_. True,\n  bmap_op_empty = (\\<lambda>_::unit. Assoc_List.empty),\n  bmap_op_lookup = (\\<lambda>k m. Assoc_List.lookup m k),\n  bmap_op_update = Assoc_List.update,\n  bmap_op_update_dj = Assoc_List.update,\n  bmap_op_delete = Assoc_List.delete,\n  bmap_op_list_it = Assoc_List.iteratei\n\\<rparr>\"\n\nsetup Locale_Code.open_block\ninterpretation lm_basic: StdBasicMapDefs lm_basic_ops .\ninterpretation lm_basic: StdBasicMap lm_basic_ops\n  apply unfold_locales\n  apply (simp_all add: icf_rec_unf \n    Assoc_List.lookup_empty' Assoc_List.iteratei_correct)\n  done\nsetup Locale_Code.close_block\n\ndefinition [icf_rec_def]: \"lm_ops \\<equiv> lm_basic.dflt_ops\"\nsetup Locale_Code.open_block\ninterpretation lm: StdMapDefs lm_ops .\ninterpretation lm: StdMap lm_ops \n  unfolding lm_ops_def\n  by (rule lm_basic.dflt_ops_impl)\ninterpretation lm: StdMap_no_invar lm_ops \n  by unfold_locales (simp add: icf_rec_unf)\nsetup Locale_Code.close_block\n\nsetup {* ICF_Tools.revert_abbrevs \"lm\"*}\n\nlemma pi_lm[proper_it]: \n  \"proper_it' Assoc_List.iteratei Assoc_List.iteratei\"\n  unfolding Assoc_List.iteratei_def[abs_def]\n  by (intro icf_proper_iteratorI proper_it'I)\n\ninterpretation pi_lm: proper_it_loc Assoc_List.iteratei Assoc_List.iteratei\n  apply unfold_locales\n  apply (rule pi_lm)\n  done\n\nlemma pi_lm'[proper_it]: \n  \"proper_it' lm.iteratei lm.iteratei\"\n  unfolding lm.iteratei_def[abs_def]\n  by (intro icf_proper_iteratorI proper_it'I)\n\ninterpretation pi_lm': proper_it_loc lm.iteratei lm.iteratei\n  apply unfold_locales\n  apply (rule pi_lm')\n  done\n\n\ntext {* Code generator test *}\ndefinition \"test_codegen \\<equiv> (\n  lm.add ,\n  lm.add_dj ,\n  lm.ball ,\n  lm.bex ,\n  lm.delete ,\n  lm.empty ,\n  lm.isEmpty ,\n  lm.isSng ,\n  lm.iterate ,\n  lm.iteratei ,\n  lm.list_it ,\n  lm.lookup ,\n  lm.restrict ,\n  lm.sel ,\n  lm.size ,\n  lm.size_abort ,\n  lm.sng ,\n  lm.to_list ,\n  lm.to_map ,\n  lm.update ,\n  lm.update_dj)\"\n\nexport_code test_codegen in SML\n\nend\n", "meta": {"author": "andredidier", "repo": "phd", "sha": "113f7c8b360a3914a571db13d9513e313954f4b2", "save_path": "github-repos/isabelle/andredidier-phd", "path": "github-repos/isabelle/andredidier-phd/phd-113f7c8b360a3914a571db13d9513e313954f4b2/thesis/Collections/ICF/impl/ListMapImpl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5621765008857981, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.29863342676099575}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\n(* License: BSD, terms see file ./LICENSE *)\n\ntheory Addr_Type\nimports \"~~/src/HOL/Word/Word\"\nbegin\n\ntype_synonym addr_bitsize = \"32\"\ntype_synonym addr = \"addr_bitsize word\"\ndefinition addr_bitsize :: nat where \"addr_bitsize \\<equiv> 32\"\ndefinition addr_align :: nat where \"addr_align \\<equiv> 2\"\ndeclare addr_align_def[simp]\n\ndefinition addr_card :: nat where\n  \"addr_card \\<equiv> card (UNIV::addr set)\"\n\n\n\ndeclare addr_bitsize_def[simp]\n\nlemma addr_card:\n  \"addr_card = 2^addr_bitsize\"\n  by (simp add: addr_card_def card_word)\n\nlemma len_of_addr_card:\n  \"2 ^ len_of TYPE(addr_bitsize) = addr_card\"\n  by (simp add: addr_card)\n\nlemma of_nat_addr_card [simp]:\n  \"of_nat addr_card = (0::addr)\"\n  by (simp add: addr_card)\n\nend\n", "meta": {"author": "z5146542", "repo": "TOR", "sha": "9a82d491288a6d013e0764f68e602a63e48f92cf", "save_path": "github-repos/isabelle/z5146542-TOR", "path": "github-repos/isabelle/z5146542-TOR/TOR-9a82d491288a6d013e0764f68e602a63e48f92cf/checker-verification/autocorres-1.4/c-parser/umm_heap/ARM_HYP/Addr_Type.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6113819874558604, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.2985276726576629}}
{"text": "theory AltDropEnv\n  imports WTLemma\nbegin\n  \n\n  (*\nlemma var_value_prim1: \"\\<lbrakk> v \\<noteq> NoRef; var_val_type v tau tau_x \\<rbrakk> \\<Longrightarrow> req_type tau \\<noteq> Prim\"  \n  apply (case_tac v)\n    apply (auto)\n   apply (case_tac tau_x)\n         apply (auto)\n  apply (case_tac tau_x)\n        apply (auto)\n  done\n\nlemma var_value_unlim: \"\\<lbrakk> v \\<noteq> NoRef; var_val_type v tau tau_x \\<rbrakk> \\<Longrightarrow> req_type tau_x = Ref\" \n  apply (case_tac v)\n    apply (auto)\n   apply (case_tac tau_x)\n         apply (auto)\n  apply (case_tac tau_x)\n        apply (auto)\n  done  *)\n  \n    (* - requirements dropping (reduces requirements to pass into lambdas) *)\n    \ndefinition drop_use_env where\n  \"drop_use_env r_s = (\\<lambda> x. if r_s x = OwnPerm then UsePerm else r_s x)\"    \n\nlemma self_drop_leq_use_env: \"leq_use_env (drop_use_env r_x) r_x\"  \n  apply (simp add: leq_use_env_def)\n  apply (simp add: drop_use_env_def)\n  apply (auto)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n  done\n    \nlemma drop_leq_use_env: \"\\<lbrakk> leq_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> leq_use_env (drop_use_env r_x) r_s\"    \n  apply (rule_tac r_sb=\"r_x\" in trans_leq_use_env)\n   apply (simp)\n  apply (rule_tac self_drop_leq_use_env)\n  done  \n    \nlemma dist_drop_leq_use_env: \"\\<lbrakk> leq_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> leq_use_env (drop_use_env r_x) (drop_use_env r_s)\"    \n  apply (simp add: leq_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (simp add: drop_use_env_def)\n  apply (auto)\n   apply (case_tac \"r_s x\")\n     apply (auto)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n  done    \n  \nlemma weak_drop_use_env: \"\\<lbrakk> weak_use_env r_s \\<rbrakk> \\<Longrightarrow> drop_use_env r_s = r_s\"\n  apply (case_tac \"\\<forall> x. drop_use_env r_s x = r_s x\")\n   apply (auto)\n  apply (simp add: drop_use_env_def)\n  apply (simp add: weak_use_env_def)\n  done    \n    \nlemma drop_weak_use_env: \"weak_use_env (drop_use_env r_s)\"    \n  apply (simp add: weak_use_env_def)\n  apply (simp add: drop_use_env_def)\n  done    \n\nlemma dist_drop_comp_use_env: \"drop_use_env (comp_use_env r_sa r_sb) = comp_use_env (drop_use_env r_sa) (drop_use_env r_sb)\"    \n  apply (case_tac \"\\<forall> x. drop_use_env (comp_use_env r_sa r_sb) x = comp_use_env (drop_use_env r_sa) (drop_use_env r_sb) x\")\n   apply (auto)\n  apply (simp add: comp_use_env_def)\n  apply (simp add: drop_use_env_def)\n  apply (case_tac \"r_sa x\")\n    apply (auto)\n    apply (case_tac \"r_sb x\")\n      apply (auto)\n   apply (case_tac \"r_sb x\")\n     apply (auto)\n  apply (case_tac \"r_sb x\")\n    apply (auto)\n  done\n    \nlemma dom_lift_comp_use_env: \"\\<lbrakk> r = OwnPerm \\<rbrakk> \\<Longrightarrow> comp_use_env r_s (lift_use_env r_s r) = comp_use_env (drop_use_env r_s) (lift_use_env r_s r)\"    \n  apply (case_tac \"\\<forall> x. comp_use_env r_s (lift_use_env r_s r) x = comp_use_env (drop_use_env r_s) (lift_use_env r_s r) x\")\n   apply (auto)\n  apply (simp add: comp_use_env_def)\n  apply (simp add: drop_use_env_def)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n  done    \n    \nlemma drop_lift_leq_use_env: \"leq_use_env (drop_use_env (lift_use_env r_s r)) (lift_use_env (drop_use_env r_s) r)\"    \n  apply (simp add: drop_use_env_def)\n  apply (simp add: leq_use_env_def)\n  apply (auto)\n   apply (case_tac r)\n     apply (auto)\n  apply (case_tac r)\n    apply (auto)\n   apply (case_tac \"r_s x\")\n     apply (auto)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n  done\n\nlemma rhs_drop_leq_use_env: \"\\<lbrakk> weak_use_env r_x; leq_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> leq_use_env r_x (drop_use_env r_s)\"    \n  apply (simp add: weak_use_env_def)\n  apply (simp add: leq_use_env_def)\n  apply (simp add: drop_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n  done     \n    \nlemma diff_drop_use_env: \"drop_use_env (diff_use_env r_s r_ex) = diff_use_env (drop_use_env r_s) r_ex\"\n  apply (case_tac \"\\<forall> x. drop_use_env (diff_use_env r_s r_ex) x = diff_use_env (drop_use_env r_s) r_ex x\")\n   apply (auto)\n  apply (simp add: diff_use_env_def)\n  apply (simp add: drop_use_env_def)\n  apply (case_tac \"r_ex x\")\n    apply (auto)\n   apply (case_tac \"r_s x\")\n     apply (auto)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n  done  \n  \n\nlemma dist_drop_diff_use_env: \"diff_use_env (drop_use_env r_s) r_x = drop_use_env (diff_use_env r_s r_x)\"    \n  apply (case_tac \"\\<forall> x. diff_use_env (drop_use_env r_s) r_x x = drop_use_env (diff_use_env r_s r_x) x\")\n   apply (auto)\n  apply (simp add: diff_use_env_def)\n  apply (simp add: drop_use_env_def)\n  apply (case_tac \"r_s x = OwnPerm\")\n   apply (auto)\n   apply (case_tac \"r_x x\")\n     apply (auto)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n  done\n    \n\nlemma wtsdr_weak_use_env: \"\\<lbrakk> leq_use_env r_s (diff_use_env r_s r_x); leq_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> weak_use_env r_x\"  \n  apply (simp add: leq_use_env_def)\n  apply (simp add: diff_use_env_def)\n  apply (simp add: weak_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n  done    \n    \n \nlemma wt_sexp_drop_all: \"\\<lbrakk> well_typed env rx e tau rx rx'; req_type tau \\<noteq> Aff; is_sexp e \\<rbrakk> \\<Longrightarrow>\n  well_typed env (drop_use_env rx) e tau (drop_use_env rx) (drop_use_env rx')\"    \n  apply (induct e arbitrary: env tau rx rx')\n        apply (auto)\n    (* const + op cases *)\n          apply (rule_tac id_leq_use_env)\n         apply (rule_tac dist_drop_leq_use_env)\n         apply (simp)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac dist_drop_leq_use_env)\n       apply (simp)\n    (* var case p1.\n        - say that x was non-affine, but was owned by an affine data structure. in this case, the permissions we receive cannot be reduced.\n     *)\n      apply (case_tac x)\n       apply (auto)\n      apply (rule_tac ereq_leq_use_envx)\n      apply (cut_tac r_x=\"ereq_use_env (Loc x22) tau_x\" and r_s=\"rx\" and x=\"Loc x22\" in spec_leq_perm)\n       apply (simp)\n      apply (simp add: ereq_use_env_def)\n      apply (simp add: one_use_env_def)\n      apply (simp add: drop_use_env_def)\n      apply (simp add: end_req_perm_def)\n    (* var case p2 *)\n     apply (cut_tac r_s=\"rx\" and r_x=\"comp_use_env (ereq_use_env (owner_name x) tau_x) r_ex\" in wtsdr_weak_use_env)\n       apply (simp)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (auto)\n     apply (rule_tac x=\"r_ex\" in exI)\n     apply (auto)\n        apply (rule_tac rhs_weak_leq_use_env)\n         apply (case_tac tau)\n               apply (auto)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac dist_drop_leq_use_env)\n       apply (simp)\n      apply (rule_tac rhs_drop_leq_use_env)\n       apply (rule_tac r_sa=\"ereq_use_env (owner_name x) tau_x\" in weak_comp_use_env2)\n       apply (auto)\n     apply (rule_tac rhs_drop_leq_use_env)\n      apply (rule_tac weak_diff_use_env)\n      apply (rule_tac r_sb=\"r_ex\" in weak_comp_use_env1)\n      apply (case_tac tau)\n            apply (auto)\n    (* pair case *)\n    apply (case_tac \"r = OwnPerm\")\n     apply (auto)\n    apply (case_tac \"max_aff (req_type t1) (req_type t2) = Aff\")\n     apply (case_tac r)\n       apply (auto)\n    apply (case_tac \"req_type t1 = Aff\")\n     apply (auto)\n    apply (case_tac \"req_type t2 = Aff\")\n      apply (case_tac \"req_type t1\")\n       apply (auto)\n    apply (case_tac \"lift_use_env rx2 r \\<noteq> rx2 \\<or> lift_use_env rx1 r \\<noteq> rx1\")\n     apply (case_tac r)\n       apply (auto)\n(*\n    apply (case_tac \"\\<not> (req_type t1 \\<noteq> Aff \\<and> req_type t2 \\<noteq> Aff)\")\n     apply (auto)\n     apply (case_tac \"req_type t1\")\n       apply (auto)*)\n    apply (cut_tac r_s=\"rx\" and r_x=\"r_ex\" in wtsdr_weak_use_env)\n      apply (rule_tac r_sb=\"diff_use_env r_s3 r_ex\" in trans_leq_use_env)\n       apply (rule_tac dist_diff_leq_use_env)\n       apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n        apply (rule_tac well_typed_perm_leq)\n        apply (auto)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n    apply (rule_tac x=\"drop_use_env rx\" in exI)\n    apply (rule_tac x=\"drop_use_env rx\" in exI)\n    apply (rule_tac x=\"drop_use_env rx1\" in exI)\n    apply (auto)\n     apply (cut_tac e=\"e1\" in value_is_sexp)\n      apply (auto)\n     apply (cut_tac env=\"env\" and ?r_s1.0=\"rx\" and r_c=\"r_s2\" and ?r_s2.0=\"rx\" and e=\"e1\" and tau=\"t1\" and rx=\"rx1\" in well_typed_decr_end_perm)\n        apply (auto)\n      apply (rule_tac r_sb=\"diff_use_env r_s3 r_ex\" in trans_leq_use_env)\n       apply (rule_tac diff_leq_use_env)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n     apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n     apply (rule_tac well_typed_perm_leqx)\n     apply (auto)\n    apply (cut_tac r_sc=\"r_s3\" and r_sb=\"r_s2\" and r_sa=\"rx\" in trans_leq_use_env)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n    apply (cut_tac r_sc=\"rx\" and r_sb=\"diff_use_env r_s3 r_ex\" and r_sa=\"r_s3\" in trans_leq_use_env)\n      apply (rule_tac self_diff_leq_use_env)\n     apply (simp)\n    apply (case_tac \"lift_use_env (drop_use_env rx2) r \\<noteq> drop_use_env rx2\")\n     apply (case_tac r)\n       apply (auto)\n    apply (case_tac \"lift_use_env (drop_use_env rx1) r \\<noteq> drop_use_env rx1\")\n     apply (case_tac r)\n       apply (auto)\n    apply (rule_tac x=\"drop_use_env rx2\" in exI)\n    apply (auto)\n          apply (cut_tac e=\"e2\" in value_is_sexp)\n           apply (auto)\n          apply (cut_tac env=\"env\" and ?r_s1.0=\"rx\" and r_c=\"r_s3\" and ?r_s2.0=\"rx\" and e=\"e2\" and tau=\"t2\" and rx=\"rx2\" in well_typed_decr_end_perm)\n             apply (rule_tac ?r_s1.0=\"r_s2\" in well_typed_incr_start_perm)\n              apply (auto)\n           apply (rule_tac well_typed_perm_leq)\n           apply (auto)\n          apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n         apply (auto)\n         apply (rule_tac dist_drop_leq_use_env)\n         apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n          apply (auto)\n        apply (rule_tac dist_drop_leq_use_env)\n        apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n         apply (auto)\n     apply (rule_tac r_s=\"rx1\" in disj_leq_use_env1)\n      apply (rule_tac r_s=\"rx2\" in disj_leq_use_env2)\n       apply (simp)\n      apply (rule_tac self_drop_leq_use_env)\n     apply (rule_tac self_drop_leq_use_env)\n    apply (rule_tac x=\"empty_use_env\" in exI)\n    apply (auto)\n       apply (rule_tac rhs_weak_leq_use_env)\n        apply (simp add: weak_use_env_def)\n        apply (simp add: empty_use_env_def)\n       apply (rule_tac id_leq_use_env)\n      apply (rule_tac dist_drop_leq_use_env)\n      apply (simp)\n     apply (rule_tac leq_empty_use_env)\n    apply (case_tac \"req_type (PairTy t1 t2 r) = Prim\")\n     apply (simp add: pair_req_def)\n     apply (rule_tac leq_empty_use_env)\n    apply (simp add: pair_req_def)\n    apply (rule_tac diff_leq_use_env)\n    apply (rule_tac r_sb=\"drop_use_env (diff_use_env (comp_use_env rx1 rx2) r_ex)\" in trans_leq_use_env)\n     apply (rule_tac dist_drop_leq_use_env)\n     apply (simp)\n    apply (rule_tac t=\"drop_use_env (diff_use_env (comp_use_env rx1 rx2) r_ex)\" and s=\"diff_use_env (drop_use_env (comp_use_env rx1 rx2)) r_ex\" in subst)\n     apply (rule_tac dist_drop_diff_use_env)\n    apply (rule_tac rhs_weak_leq_use_env)\n     apply (simp)\n    apply (simp add: dist_drop_comp_use_env)\n    apply (rule_tac id_leq_use_env)\n    (* lam case *)\n   apply (simp add: aff_use_env_def)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n    apply (rule_tac rhs_drop_leq_use_env)\n     apply (auto)\n    apply (case_tac a)\n      apply (auto)\n    apply (simp add: weak_use_env_def)\n    apply (simp add: null_use_env_def)\n   apply (cut_tac r_s=\"rx\" and r_x=\"r_ex\" in wtsdr_weak_use_env)\n     apply (auto)\n   apply (rule_tac x=\"r_ex\" in exI)\n   apply (auto)\n      apply (rule_tac rhs_weak_leq_use_env)\n       apply (simp)\n      apply (rule_tac id_leq_use_env)\n     apply (rule_tac dist_drop_leq_use_env)\n     apply (simp)\n    apply (rule_tac rhs_drop_leq_use_env)\n     apply (auto)\n   apply (rule_tac rhs_drop_leq_use_env)\n    apply (rule_tac weak_diff_use_env)\n    apply (auto)\n   apply (case_tac a)\n     apply (auto)\n   apply (simp add: weak_use_env_def)\n   apply (simp add: null_use_env_def)\n    (* app case. e1 *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"drop_use_env rx\" in exI)\n  apply (rule_tac x=\"empty_use_env\" in exI)\n  apply (auto)\n   apply (case_tac e1)\n         apply (auto)\n    apply (rule_tac id_leq_use_env)\n   apply (rule_tac leq_empty_use_env)\n    (* app case. e2, lambda unrolling *)\n  apply (rule_tac x=\"drop_use_env rx2\" in exI)\n  apply (rule_tac x=\"drop_use_env rx\" in exI)\n  apply (auto)\n   apply (cut_tac env=\"env\" and r_c=\"rx\" and ?r_s1.0=\"r_s2\" and ?r_s2.0=\"rx\" and e=\"e2\" and tau=\"t1\" and rx=\"rx2\" in well_typed_incr_start_perm)\n     apply (rule_tac r_c=\"r_s3\" in well_typed_decr_end_perm)\n       apply (simp)\n      apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n       apply (rule_tac self_diff_leq_use_env)\n      apply (simp)\n     apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n      apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n     apply (rule_tac well_typed_perm_leqx)\n     apply (auto)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n    (* - prove that e2 is an s-expression *)\n   apply (case_tac \"\\<not> is_sexp e2\")\n    apply (cut_tac ?e1.0=\"e1\" and ?e2.0=\"e2\" in e2_sexp)\n     apply (simp_all)\n    (* - prove that t1 is unlim *)\n   apply (case_tac \"\\<not> req_type t1 \\<noteq> Aff\")\n    apply (case_tac e1)\n         apply (auto)\n    apply (case_tac x1)\n               apply (auto)\n        apply (simp_all add: pure_fun_def)\n    (* app case. tau primitive case (only happens for fixed point w/ primitive fun) *)\n  apply (simp add: app_req_def)\n  apply (case_tac \"req_type tau = Prim\")\n   apply (auto)\n   apply (case_tac e1)\n        apply (auto)\n    apply (case_tac x1)\n                apply (auto)\n        apply (simp_all add: pure_fun_def)\n   apply (auto)\n   apply (case_tac t)\n          apply (auto)\n   apply (case_tac \"\\<not> weak_use_env empty_use_env\")\n    apply (simp add: weak_use_env_def)\n    apply (simp add: empty_use_env_def)\n   apply (rule_tac x=\"empty_use_env\" in exI)\n   apply (auto)\n         apply (rule_tac rhs_weak_leq_use_env)\n          apply (rule_tac dist_weak_comp_use_env)\n           apply (rule_tac dist_weak_comp_use_env)\n            apply (auto)\n          apply (rule_tac drop_weak_use_env)\n         apply (rule_tac id_leq_use_env)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac leq_empty_use_env)\n       apply (rule_tac dist_drop_leq_use_env)\n       apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n        apply (simp)\n       apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n        apply (rule_tac well_typed_perm_leq)\n        apply (auto)\n       apply (rule_tac well_typed_perm_leqx)\n       apply (auto)\n      apply (rule_tac disj_empty_use_env2)\n     apply (rule_tac dist_drop_leq_use_env)\n     apply (simp)\n    apply (rule_tac leq_empty_use_env)\n   apply (rule_tac leq_empty_use_env)\n    (* non prim case. *)\n    (* - prove weakness of rx1 + rx2 + r_ex *)\n  apply (cut_tac r_s=\"r_s3\" and r_x=\"comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex\" in wtsdr_weak_use_env)\n    apply (rule_tac r_sb=\"rx\" in trans_leq_use_env)\n     apply (simp)\n    apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n   apply (rule_tac dist_comp_leq_use_env)\n    apply (simp)\n   apply (rule_tac r_sb=\"rx\" in trans_leq_use_env)\n    apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n     apply (rule_tac self_diff_leq_use_env)\n    apply (simp_all)\n    (* - r not ownership *)\n  apply (case_tac \"r = OwnPerm\")\n   apply (case_tac e1)\n        apply (auto)\n   apply (case_tac x1)\n               apply (auto)\n        apply (simp_all add: pure_fun_def)\n    (* - final manipulation *)\n  apply (rule_tac x=\"r_ex\" in exI)\n  apply (auto)\n       apply (rule_tac rhs_weak_leq_use_env)\n        apply (rule_tac r_s=\"comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex\" in leq_weak_use_env)\n         apply (simp)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (rule_tac comp_leq_use_env1)\n         apply (rule_tac dist_comp_leq_use_env)\n          apply (rule_tac leq_empty_use_env)\n         apply (rule_tac comp_leq_use_env2)\n         apply (rule_tac dist_lift_leq_use_env)\n         apply (rule_tac self_drop_leq_use_env)\n        apply (rule_tac self_comp_leq_use_env2)\n       apply (rule_tac id_leq_use_env)\n(*\n       apply (simp add: drop_use_env_def)\n       apply (case_tac r)\n         apply (auto)*)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (rule_tac leq_empty_use_env)\n      apply (case_tac \"lift_use_env (drop_use_env rx2) r \\<noteq> drop_use_env rx2\")\n       apply (case_tac r)\n         apply (auto)\n      apply (rule_tac dist_drop_leq_use_env)\n      apply (rule_tac r_sb=\"comp_use_env rx1 (lift_use_env rx2 r)\" in trans_leq_use_env)\n       apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n        apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n         apply (rule_tac well_typed_perm_leq)\n         apply (auto)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n      apply (rule_tac comp_leq_use_env2)\n      apply (rule_tac self_lift_leq_use_env)\n     apply (rule_tac disj_empty_use_env2)\n    apply (rule_tac dist_drop_leq_use_env)\n    apply (simp)\n   apply (rule_tac rhs_drop_leq_use_env)\n    apply (rule_tac r_sa=\"comp_use_env rx1 (lift_use_env rx2 r)\" in weak_comp_use_env2)\n    apply (auto)\n  apply (rule_tac r_sb=\"drop_use_env (diff_use_env (comp_use_env rx1 rx2) (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex))\" in trans_leq_use_env)\n   apply (rule_tac dist_drop_leq_use_env)\n   apply (auto)\n  apply (rule_tac rhs_drop_leq_use_env)\n   apply (rule_tac weak_diff_use_env)\n   apply (rule_tac dist_weak_comp_use_env)\n    apply (simp add: weak_use_env_def)\n    apply (simp add: empty_use_env_def)\n   apply (rule_tac drop_weak_use_env)\n  apply (rule_tac rhs_weak_leq_use_env)\n   apply (simp)\n  apply (rule_tac diff_leq_use_env)\n  apply (rule_tac dist_comp_leq_use_env)\n   apply (rule_tac leq_empty_use_env)\n  apply (rule_tac comp_leq_use_env2)\n  apply (rule_tac self_drop_leq_use_env)\n  done        \n    \nlemma wt_sexp_drop_req: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; req_type tau \\<noteq> Aff; (*\\<not> aff_fun_ty tau;*) is_sexp e \\<rbrakk> \\<Longrightarrow>\n    well_typed env r_s1 e tau r_s2 (drop_use_env rx)\"\n  apply (induct e arbitrary: r_s1 r_s2 tau rx)\n        apply (auto)\n    (* const + op cases *)\n       apply (rule_tac drop_leq_use_env)\n       apply (simp)\n      apply (rule_tac drop_leq_use_env)\n      apply (simp)\n    (* var case. *)\n     apply (rule_tac x=\"r_ex\" in exI)\n     apply (auto)\n      apply (rule_tac drop_leq_use_env)\n      apply (simp)\n     apply (rule_tac rhs_drop_leq_use_env)\n      apply (rule_tac weak_diff_use_env)\n      apply (rule_tac weak_ereq_use_env)\n      apply (simp add: unlim_def)\n      apply (case_tac x)\n       apply (auto)\n    (* pair case. *)\n    apply (case_tac \"r = OwnPerm\")\n     apply (auto)\n    apply (case_tac \"max_aff (req_type t1) (req_type t2) = Aff\")\n     apply (case_tac r)\n       apply (auto)\n    apply (rule_tac x=\"r_s2a\" in exI)\n    apply (rule_tac x=\"r_s3\" in exI)\n    apply (rule_tac x=\"drop_use_env rx1\" in exI)\n    apply (auto)\n     apply (case_tac \"req_type t1 = Aff\")\n      apply (auto)\n     apply (cut_tac e=\"e1\" in value_is_sexp)\n      apply (auto)\n    apply (rule_tac x=\"drop_use_env rx2\" in exI)\n    apply (auto)\n        apply (case_tac \"req_type t2 = Aff\")\n         apply (case_tac \"req_type t1\")\n           apply (auto)\n        apply (cut_tac e=\"e2\" in value_is_sexp)\n         apply (auto)\n       apply (rule_tac r_sb=\"lift_use_env rx1 r\" in trans_leq_use_env)\n        apply (simp)\n       apply (rule_tac dist_lift_leq_use_env)\n       apply (rule_tac self_drop_leq_use_env)\n      apply (rule_tac r_sb=\"lift_use_env rx2 r\" in trans_leq_use_env)\n       apply (simp)\n      apply (rule_tac dist_lift_leq_use_env)\n      apply (rule_tac self_drop_leq_use_env)\n     apply (rule_tac r_s=\"lift_use_env rx1 r\" in disj_leq_use_env1)\n      apply (rule_tac r_s=\"lift_use_env rx2 r\" in disj_leq_use_env2)\n       apply (simp)\n      apply (rule_tac dist_lift_leq_use_env)\n      apply (rule_tac self_drop_leq_use_env)\n     apply (rule_tac dist_lift_leq_use_env)\n     apply (rule_tac self_drop_leq_use_env)\n    apply (rule_tac x=\"r_ex\" in exI)\n    apply (auto)\n     apply (rule_tac drop_leq_use_env)\n     apply (simp)\n    apply (case_tac \"lift_use_env (drop_use_env rx1) r \\<noteq> drop_use_env rx1\")\n     apply (case_tac r)\n       apply (auto)\n    apply (case_tac \"lift_use_env (drop_use_env rx2) r \\<noteq> drop_use_env rx2\")\n     apply (case_tac r)\n       apply (auto)\n    apply (case_tac \"req_type (PairTy t1 t2 r) = Prim\")\n     apply (simp add: pair_req_def)\n     apply (rule_tac leq_empty_use_env)\n    apply (simp add: pair_req_def)\n    apply (rule_tac rhs_drop_leq_use_env)\n     apply (rule_tac weak_diff_use_env)\n     apply (rule_tac dist_weak_comp_use_env)\n      apply (rule_tac drop_weak_use_env)\n     apply (rule_tac drop_weak_use_env)\n    apply (rule_tac r_sb=\"diff_use_env (comp_use_env (lift_use_env rx1 r) (lift_use_env rx2 r)) r_ex\" in trans_leq_use_env)\n     apply (simp)\n    apply (rule_tac dist_diff_leq_use_env)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (rule_tac comp_leq_use_env1)\n     apply (rule_tac drop_leq_use_env)\n     apply (rule_tac self_lift_leq_use_env)\n    apply (rule_tac comp_leq_use_env2)\n    apply (rule_tac drop_leq_use_env)\n    apply (rule_tac self_lift_leq_use_env)\n    (* lam case  *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_ex\" in exI)\n   apply (auto)\n    apply (rule_tac drop_leq_use_env)\n    apply (simp)\n   apply (rule_tac rhs_drop_leq_use_env)\n    apply (rule_tac weak_diff_use_env)\n    apply (simp add: aff_use_env_def)\n    apply (case_tac a)\n      apply (auto)\n   apply (simp add: null_use_env_def)\n   apply (simp add: weak_use_env_def)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"drop_use_env rx1\" in exI)\n  apply (auto)\n   apply (case_tac \"req_type (FunTy t1 tau r a) = Aff\")\n    apply (case_tac e1)\n          apply (auto)\n    apply (case_tac x1)\n                apply (auto)\n         apply (simp_all add: pure_fun_def)\n   apply (case_tac \"\\<not> is_sexp e1\")\n    apply (case_tac e1)\n          apply (auto)\n  apply (rule_tac x=\"drop_use_env rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n   apply (case_tac \"req_type t1 = Aff\")\n    apply (case_tac e1)\n          apply (auto)\n    apply (case_tac x1)\n                apply (auto)\n         apply (simp_all add: pure_fun_def)\n   apply (case_tac \"\\<not> is_sexp e2\")\n    apply (case_tac \"is_value e2\")\n     apply (cut_tac e=\"e2\" in value_is_sexp)\n      apply (auto)\n    apply (case_tac e1)\n          apply (auto)\n   apply (case_tac x1)\n               apply (auto)\n   apply (case_tac e2)\n         apply (auto)\n  apply (cut_tac r_xa=\"drop_use_env rx1\" and r_xb=\"lift_use_env (drop_use_env rx2) r\" and r_s=\"comp_use_env rx1 (lift_use_env rx2 r)\" in dist_comp_leq_use_env)\n    apply (rule_tac comp_leq_use_env1)\n    apply (rule_tac self_drop_leq_use_env)\n   apply (rule_tac comp_leq_use_env2)\n   apply (rule_tac dist_lift_leq_use_env)\n   apply (rule_tac self_drop_leq_use_env)\n  apply (rule_tac x=\"comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex\" in exI)\n  apply (auto)\n      apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n       apply (rule_tac dist_diff_leq_use_env_gen)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac comp_leq_use_env1)\n         apply (simp)\n        apply (rule_tac id_leq_use_env)\n       apply (simp)\n     apply (rule_tac r_sb=\"comp_use_env rx1 (lift_use_env rx2 r)\" in trans_leq_use_env)\n      apply (simp_all)\n    apply (rule_tac r_s=\"rx1\" in disj_leq_use_env1)\n     apply (rule_tac r_s=\"lift_use_env rx2 r\" in disj_leq_use_env2)\n      apply (simp)\n     apply (rule_tac dist_lift_leq_use_env)\n     apply (rule_tac self_drop_leq_use_env)\n    apply (rule_tac self_drop_leq_use_env)\n   apply (rule_tac drop_leq_use_env)\n    apply (simp)\n   apply (rule_tac dist_comp_leq_use_env)\n    apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n     apply (rule_tac r_sb=\"r_s2a\" in trans_leq_use_env)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n   apply (rule_tac well_typed_perm_leq)\n   apply (auto)\n  apply (case_tac \"req_type tau = Prim\")\n   apply (simp add: app_req_def)\n   apply (rule_tac leq_empty_use_env)\n  apply (simp add: app_req_def)\n  apply (rule_tac rhs_drop_leq_use_env)\n   apply (rule_tac weak_diff_use_env)\n   apply (rule_tac dist_weak_comp_use_env)\n    apply (rule_tac drop_weak_use_env)\n   apply (rule_tac drop_weak_use_env)\n  apply (rule_tac r_sb=\"diff_use_env (comp_use_env rx1 rx2) (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n   apply (simp)\n  apply (rule_tac dist_diff_leq_use_env_gen)\n   apply (rule_tac dist_comp_leq_use_env)\n    apply (rule_tac comp_leq_use_env1)\n    apply (rule_tac self_drop_leq_use_env)\n   apply (rule_tac comp_leq_use_env2)\n   apply (rule_tac self_drop_leq_use_env)\n  apply (rule_tac self_comp_leq_use_env2)\n  done\n    \n    (* ####### primitive lemmas *)\n    \nlemma wt_sexp_no_all: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; req_type tau = Prim; is_sexp e \\<rbrakk> \\<Longrightarrow> well_typed env empty_use_env e tau empty_use_env empty_use_env\"     \n  apply (induction e arbitrary: env tau r_s1 r_s2 rx)\n        apply (auto)\n    (* const + op case *)   \n        apply (rule_tac leq_empty_use_env)\n       apply (rule_tac leq_empty_use_env)\n    (* var case *)\n      apply (case_tac x)\n       apply (auto)\n     apply (case_tac x)\n      apply (auto)\n    (* pair case *)\n    apply (case_tac \"r \\<noteq> NoPerm\")\n     apply (case_tac r)\n       apply (auto)\n    apply (case_tac \"max_aff (req_type t1) (req_type t2)\")\n      apply (auto)\n    apply (case_tac \"req_type t1\")\n       apply (auto)\n     apply (case_tac \"req_type t2\")\n       apply (auto)\n    apply (case_tac \"req_type t2\")\n      apply (auto)\n    apply (rule_tac x=\"empty_use_env\" in exI)\n    apply (rule_tac x=\"empty_use_env\" in exI)\n    apply (rule_tac x=\"empty_use_env\" in exI)\n    apply (auto)\n     apply (cut_tac e=\"e1\" in value_is_sexp)\n      apply (auto)\n    apply (rule_tac x=\"empty_use_env\" in exI)\n    apply (auto)\n        apply (cut_tac e=\"e2\" in value_is_sexp)\n         apply (auto)\n      apply (rule_tac leq_empty_use_env)\n     apply (rule_tac disj_empty_use_env1)\n    apply (rule_tac x=\"empty_use_env\" in exI)\n    apply (auto)\n      apply (rule_tac leq_empty_use_env)\n     apply (rule_tac leq_empty_use_env)\n    apply (simp add: pair_req_def)\n    apply (rule_tac leq_empty_use_env)\n    (* lam case *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n    apply (simp add: leq_use_env_def)\n    apply (simp add: aff_use_env_def)\n    apply (simp add: null_use_env_def)\n   apply (rule_tac x=\"empty_use_env\" in exI)\n   apply (auto)\n     apply (rule_tac leq_empty_use_env)\n    apply (rule_tac leq_empty_use_env)\n   apply (rule_tac diff_leq_use_env)\n   apply (simp add: leq_use_env_def)\n   apply (simp add: aff_use_env_def)\n   apply (simp add: null_use_env_def)\n    (* app case. since tau is primitive, the only possible const is the fix point *)\n  apply (case_tac e1)\n        apply (auto)\n  apply (case_tac \"x1 \\<noteq> FixConst\")\n   apply (case_tac x1)\n               apply (auto)\n       apply (simp_all add: pure_fun_def)\n    (* - with that in mind, we fill in the rest *)\n  apply (auto)\n  apply (rule_tac x=\"empty_use_env\" in exI)\n  apply (auto)\n   apply (rule_tac leq_empty_use_env)\n  apply (rule_tac x=\"empty_use_env\" in exI)\n  apply (auto)\n   apply (rule_tac leq_empty_use_env)\n  apply (rule_tac x=\"empty_use_env\" in exI)\n  apply (rule_tac x=\"empty_use_env\" in exI)\n  apply (auto)\n   apply (case_tac \"\\<not> is_sexp e2\")\n    apply (case_tac e2)\n          apply (auto)\n  apply (rule_tac x=\"empty_use_env\" in exI)\n  apply (auto)\n       apply (rule_tac leq_empty_use_env)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac leq_empty_use_env)\n     apply (rule_tac leq_empty_use_env)\n    apply (rule_tac disj_empty_use_env2)\n   apply (rule_tac leq_empty_use_env)\n  apply (simp add: app_req_def)\n  apply (rule_tac leq_empty_use_env)\n  done\n    \nlemma wt_sexp_no_req: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; req_type tau = Prim; is_sexp e \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau r_s2 empty_use_env\"     \n  apply (rule_tac r_c=\"r_s1\" in well_typed_decr_end_perm)\n    apply (rule_tac r_s=\"empty_use_env\" in well_typed_incr_simul_perm)\n     apply (rule_tac leq_empty_use_env)\n    apply (rule_tac wt_sexp_no_all)\n      apply (auto)\n   apply (rule_tac well_typed_perm_leq)\n   apply (auto)\n  apply (rule_tac leq_empty_use_env)\n  done       \n    \n    \nfun drop_use_env_dep where\n  \"drop_use_env_dep r_s OwnPerm = r_s\"\n| \"drop_use_env_dep r_s UsePerm = drop_use_env r_s\"\n| \"drop_use_env_dep r_s NoPerm = empty_use_env\"    \n  \nlemma wt_sexp_drop_dep_req: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; is_sexp e; safe_type_x tau r \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau r_s2 (drop_use_env_dep rx r)\"  \n  apply (case_tac r)\n    apply (auto)\n   apply (rule_tac wt_sexp_no_req)\n     apply (auto)\n  apply (rule_tac wt_sexp_drop_req)\n    apply (auto)\n  apply (simp add: unlim_def)\n  done\n    \nend", "meta": {"author": "anon-ef", "repo": "perm_lang_ef2", "sha": "0fcb6e4c175193cc7b94f297a8aaa605f502d711", "save_path": "github-repos/isabelle/anon-ef-perm_lang_ef2", "path": "github-repos/isabelle/anon-ef-perm_lang_ef2/perm_lang_ef2-0fcb6e4c175193cc7b94f297a8aaa605f502d711/perm_ref/AltDropEnv.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6113819732941511, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.2985276657427354}}
{"text": "theory ExtraLemmas\nimports AutoCorres\nbegin\n\nlemma shiftr1_is_div_2': \"shiftr1 (x :: ('a :: len) word) = x div 2\"\napply (simp only: shiftr1_unfold)\nusing shiftr1_is_div_2 by auto\n\nlemma shiftr2_is_div_4:\nassumes \"2 < len_of TYPE('a)\"\nshows \"(x :: ('a :: len) word) >> 2 = x div 4\"\nproof -\n  from assms have \"x >> 2 = x div 2 ^ 2\" by (simp add: shiftr_div_2n_w word_size)\n  thus ?thesis by auto\nqed\n\nlemma shiftr3_is_div_8:\nassumes \"3 < len_of TYPE('a)\"\nshows \"(x :: ('a :: len) word) >> 3 = x div 8\"\nproof -\n  from assms have \"x >> 3 = x div 2 ^ 3\" by (simp add: shiftr_div_2n_w word_size)\n  thus ?thesis by auto\nqed\n\nlemma array_addrs_ptr_add[intro]: \"0 \\<le> i \\<Longrightarrow> i < int n \\<Longrightarrow> p +\\<^sub>p i \\<in> set (array_addrs p n)\"\napply (simp add: set_array_addrs)\napply (rule_tac x=\"nat i\" in exI)\napply simp\ndone\n\nlemma array_addrs_ptr_ex[dest]:\n  \"q \\<in> set (array_addrs p n)\\<Longrightarrow> \\<exists>i. q = p +\\<^sub>p (int i) \\<and> i < n\"\nby (simp add: set_array_addrs)\n\nlemma ptr_val_inject: \"(p :: 'a ptr) = q \\<Longrightarrow> ptr_val p = ptr_val q\"\nby auto\n\nlemma ptr_arith_index: \"0 \\<le> i \\<Longrightarrow> 0 \\<le> k\n  \\<Longrightarrow> nat i * size_of TYPE('a :: wf_type) < 2 ^ len_of TYPE(32)\n  \\<Longrightarrow> nat k * size_of TYPE('a :: wf_type) < 2 ^ len_of TYPE(32)\n  \\<Longrightarrow> ((p :: 'a ptr) +\\<^sub>p i = p +\\<^sub>p k) = (i = k)\"\nunfolding ptr_add_def\nproof auto\n  fix i k :: int\n  assume size_i: \"nat i * size_of TYPE('a) < 4294967296\" and \"0 \\<le> i\"\n     and size_k: \"nat k * size_of TYPE('a) < 4294967296\" and \"0 \\<le> k\"\n     and eq: \"of_int i * of_nat (size_of TYPE('a)) = (of_int k * of_nat (size_of TYPE('a)) :: 32 word)\"\n  hence \"(of_nat (nat i) :: 32 word) * of_nat (size_of TYPE('a))\n    = of_nat (nat k) * of_nat (size_of TYPE('a))\" by simp\n  hence \"(of_nat (nat i * size_of TYPE('a)) :: 32 word) = of_nat (nat k * size_of TYPE('a))\"\n    (is \"of_nat ?L = of_nat ?R\") by simp\n  moreover have \"((of_nat ?L :: 32 word) = of_nat ?R) = (?L = ?R)\"\n    using size_i and size_k by (fastforce intro!: Word_Lemmas.of_nat_inj)\n  ultimately have \"?L = ?R\" by auto\n  thus \"i = k\" using not_gr0 sz_nzero\n    by (metis \\<open>0 \\<le> i\\<close> \\<open>0 \\<le> k\\<close> int_nat_eq mult.commute mult_cancel1)\nqed\n\nlemma hoare_post_imp: \"\\<forall>r s. Q r s \\<longrightarrow> R r s \\<Longrightarrow> \\<lbrace>P\\<rbrace> m \\<lbrace>Q\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> m \\<lbrace>R\\<rbrace>\"\nunfolding valid_def by blast\n\nlemma size_of_le_n[dest]: \"size_of TYPE('a :: wf_type) \\<le> unat (n :: ('b :: len) word) \\<Longrightarrow> 0 < n\"\nproof -\n  fix n :: \"'b word\"\n  assume \"size_of TYPE('a) \\<le> unat n\"\n  moreover have \"0 < size_of TYPE('a)\" using sz_nzero by auto\n  ultimately have \"0 < unat n\" by linarith \n  thus \"0 < n\" using word_of_nat_less by force\nqed\n\nlemma ptr_less_simp : \"a < b = (ptr_val a < ptr_val b)\" \n  by (simp add: ptr_less_def ptr_less_def')\nlemma ptr_le_simp : \"a \\<le> b = (ptr_val a \\<le> ptr_val b)\" \n  by (simp add: ptr_le_def ptr_le_def')\nlemmas ptr_comp_simps = ptr_less_simp and ptr_le_simp \nend", "meta": {"author": "CriticalTechnologiesInc", "repo": "SableModel", "sha": "a452a2b5e3636b612a4d04cfb6e2ab1c1a132639", "save_path": "github-repos/isabelle/CriticalTechnologiesInc-SableModel", "path": "github-repos/isabelle/CriticalTechnologiesInc-SableModel/SableModel-a452a2b5e3636b612a4d04cfb6e2ab1c1a132639/lib/ExtraLemmas.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.611381973294151, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.29852766574273537}}
{"text": "(*\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n     http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n \n *)\n\ntheory BitVector_Rewriting\n  imports reassembly_rewriting.Take_Bits_Rewriting reassembly_manual_execution.BitVectors\nbegin\n\n\nsubsection \\<open>Logical Operators\\<close>\n\nlemma bv_to_bool_bool_to_bv:\n  shows \"bv_to_bool (bool_to_bv b) = b\"\n  by (cases b,auto simp add: bv_to_bool_def)\n      \nlemma snd_bool_to_bv:\n  shows \"snd (bool_to_bv b) = 1\"\n  by (cases b,auto)\n\nlemma bv_to_bool_True:\n  shows \"bv_to_bool (1, 1) = True\"\n  by (auto simp add: bv_to_bool_def)\n\nlemma bv_to_bool_True_Suc0:\n  shows \"bv_to_bool (1, Suc 0) = True\"\n  by (auto simp add: bv_to_bool_def)\n\nlemma bv_to_bool_False:\n  shows \"bv_to_bool (0, 1) = False\"\n  by (auto simp add: bv_to_bool_def)\n\nlemma bv_to_bool_False_Suc0:\n  shows \"bv_to_bool (0, Suc 0) = False\"\n  by (auto simp add: bv_to_bool_def)\n\n\nlemma bool_to_bv_eq:\n  shows \"bool_to_bv b = (x, Suc 0) \\<longleftrightarrow> (x \\<in> {0,1} \\<and> ((x = 1) \\<longleftrightarrow> b))\"\n  by (cases b,auto)\n\nlemma bv_NOT_bool_to_bv:\n  shows \"bv_NOT (bool_to_bv b) = bool_to_bv (\\<not>b)\"\n  by (cases b, auto simp add: max_word_def) \n\n\n\nsubsection \\<open>Concatenation and slicing\\<close>\n\n\n\nlemmas bv_slice_simps[simp] =\n  bv_slice.simps[of \"numeral h\" \"numeral l\" \"numeral w\" \"numeral s\"]\n  bv_slice.simps[of \"numeral h\" \"numeral l\" \"numeral w\" 0]\n  bv_slice.simps[of \"numeral h\" \"numeral l\" \"numeral w\" 1]\n  bv_slice.simps[of \"numeral h\" \"numeral l\" 0            \"numeral s\"]\n  bv_slice.simps[of \"numeral h\" \"numeral l\" 0            0]\n  bv_slice.simps[of \"numeral h\" \"numeral l\" 0            1]\n  bv_slice.simps[of \"numeral h\" \"numeral l\" 1            \"numeral s\"]\n  bv_slice.simps[of \"numeral h\" \"numeral l\" 1            0]\n  bv_slice.simps[of \"numeral h\" \"numeral l\" 1            1]\n  bv_slice.simps[of \"numeral h\" 0            \"numeral w\" \"numeral s\"]\n  bv_slice.simps[of \"numeral h\" 0            \"numeral w\" 0]\n  bv_slice.simps[of \"numeral h\" 0            \"numeral w\" 1]\n  bv_slice.simps[of \"numeral h\" 0            0            \"numeral s\"]\n  bv_slice.simps[of \"numeral h\" 0            0            0]\n  bv_slice.simps[of \"numeral h\" 0            0            1]\n  bv_slice.simps[of \"numeral h\" 0            1            \"numeral s\"]\n  bv_slice.simps[of \"numeral h\" 0            1            0]\n  bv_slice.simps[of \"numeral h\" 0            1            1]\n  bv_slice.simps[of \"numeral h\" 1            \"numeral w\" \"numeral s\"]\n  bv_slice.simps[of \"numeral h\" 1            \"numeral w\" 0]\n  bv_slice.simps[of \"numeral h\" 1            \"numeral w\" 1]\n  bv_slice.simps[of \"numeral h\" 1            0            \"numeral s\"]\n  bv_slice.simps[of \"numeral h\" 1            0            0]\n  bv_slice.simps[of \"numeral h\" 1            0            1]\n  bv_slice.simps[of \"numeral h\" 1            1            \"numeral s\"]\n  bv_slice.simps[of \"numeral h\" 1            1            0]\n  bv_slice.simps[of \"numeral h\" 1            1            1]\n  bv_slice.simps[of 0           \"numeral l\" \"numeral w\" \"numeral s\"]\n  bv_slice.simps[of 0           \"numeral l\" \"numeral w\" 0]\n  bv_slice.simps[of 0           \"numeral l\" \"numeral w\" 1]\n  bv_slice.simps[of 0           \"numeral l\" 0            \"numeral s\"]\n  bv_slice.simps[of 0           \"numeral l\" 0            0]\n  bv_slice.simps[of 0           \"numeral l\" 0            1]\n  bv_slice.simps[of 0           \"numeral l\" 1            \"numeral s\"]\n  bv_slice.simps[of 0           \"numeral l\" 1            0]\n  bv_slice.simps[of 0           \"numeral l\" 1            1]\n  bv_slice.simps[of 0           0            \"numeral w\" \"numeral s\"]\n  bv_slice.simps[of 0           0            \"numeral w\" 0]\n  bv_slice.simps[of 0           0            \"numeral w\" 1]\n  bv_slice.simps[of 0           0            0            \"numeral s\"]\n  bv_slice.simps[of 0           0            0            0]\n  bv_slice.simps[of 0           0            0            1]\n  bv_slice.simps[of 0           0            1            \"numeral s\"]\n  bv_slice.simps[of 0           0            1            0]\n  bv_slice.simps[of 0           0            1            1]\n  bv_slice.simps[of 0           1            \"numeral w\" \"numeral s\"]\n  bv_slice.simps[of 0           1            \"numeral w\" 0]\n  bv_slice.simps[of 0           1            \"numeral w\" 1]\n  bv_slice.simps[of 0           1            0            \"numeral s\"]\n  bv_slice.simps[of 0           1            0            0]\n  bv_slice.simps[of 0           1            0            1]\n  bv_slice.simps[of 0           1            1            \"numeral s\"]\n  bv_slice.simps[of 0           1            1            0]\n  bv_slice.simps[of 0           1            1            1]\n  bv_slice.simps[of 1           \"numeral l\" \"numeral w\" \"numeral s\"]\n  bv_slice.simps[of 1           \"numeral l\" \"numeral w\" 0]\n  bv_slice.simps[of 1           \"numeral l\" \"numeral w\" 1]\n  bv_slice.simps[of 1           \"numeral l\" 0            \"numeral s\"]\n  bv_slice.simps[of 1           \"numeral l\" 0            0]\n  bv_slice.simps[of 1           \"numeral l\" 0            1]\n  bv_slice.simps[of 1           \"numeral l\" 1            \"numeral s\"]\n  bv_slice.simps[of 1           \"numeral l\" 1            0]\n  bv_slice.simps[of 1           \"numeral l\" 1            1]\n  bv_slice.simps[of 1           0            \"numeral w\" \"numeral s\"]\n  bv_slice.simps[of 1           0            \"numeral w\" 0]\n  bv_slice.simps[of 1           0            \"numeral w\" 1]\n  bv_slice.simps[of 1           0            0            \"numeral s\"]\n  bv_slice.simps[of 1           0            0            0]\n  bv_slice.simps[of 1           0            0            1]\n  bv_slice.simps[of 1           0            1            \"numeral s\"]\n  bv_slice.simps[of 1           0            1            0]\n  bv_slice.simps[of 1           0            1            1]\n  bv_slice.simps[of 1           1            \"numeral w\" \"numeral s\"]\n  bv_slice.simps[of 1           1            \"numeral w\" 0]\n  bv_slice.simps[of 1           1            \"numeral w\" 1]\n  bv_slice.simps[of 1           1            0            \"numeral s\"]\n  bv_slice.simps[of 1           1            0            0]\n  bv_slice.simps[of 1           1            0            1]\n  bv_slice.simps[of 1           1            1            \"numeral s\"]\n  bv_slice.simps[of 1           1            1            0]\n  bv_slice.simps[of 1           1            1            1]\n  for h l w s\n\nlemmas bv_cat_simps[simp] =\n  bv_cat.simps[of \"numeral w0\" \"numeral s0\" \"numeral w1\" \"numeral s1\"]\n  bv_cat.simps[of \"numeral w0\" \"numeral s0\" \"numeral w1\" 0]\n  bv_cat.simps[of \"numeral w0\" \"numeral s0\" \"numeral w1\" 1]\n  bv_cat.simps[of \"numeral w0\" \"numeral s0\" 0            \"numeral s1\"]\n  bv_cat.simps[of \"numeral w0\" \"numeral s0\" 0            0]\n  bv_cat.simps[of \"numeral w0\" \"numeral s0\" 0            1]\n  bv_cat.simps[of \"numeral w0\" \"numeral s0\" 1            \"numeral s1\"]\n  bv_cat.simps[of \"numeral w0\" \"numeral s0\" 1            0]\n  bv_cat.simps[of \"numeral w0\" \"numeral s0\" 1            1]\n  bv_cat.simps[of \"numeral w0\" 0            \"numeral w1\" \"numeral s1\"]\n  bv_cat.simps[of \"numeral w0\" 0            \"numeral w1\" 0]\n  bv_cat.simps[of \"numeral w0\" 0            \"numeral w1\" 1]\n  bv_cat.simps[of \"numeral w0\" 0            0            \"numeral s1\"]\n  bv_cat.simps[of \"numeral w0\" 0            0            0]\n  bv_cat.simps[of \"numeral w0\" 0            0            1]\n  bv_cat.simps[of \"numeral w0\" 0            1            \"numeral s1\"]\n  bv_cat.simps[of \"numeral w0\" 0            1            0]\n  bv_cat.simps[of \"numeral w0\" 0            1            1]\n  bv_cat.simps[of \"numeral w0\" 1            \"numeral w1\" \"numeral s1\"]\n  bv_cat.simps[of \"numeral w0\" 1            \"numeral w1\" 0]\n  bv_cat.simps[of \"numeral w0\" 1            \"numeral w1\" 1]\n  bv_cat.simps[of \"numeral w0\" 1            0            \"numeral s1\"]\n  bv_cat.simps[of \"numeral w0\" 1            0            0]\n  bv_cat.simps[of \"numeral w0\" 1            0            1]\n  bv_cat.simps[of \"numeral w0\" 1            1            \"numeral s1\"]\n  bv_cat.simps[of \"numeral w0\" 1            1            0]\n  bv_cat.simps[of \"numeral w0\" 1            1            1]\n  bv_cat.simps[of 0           \"numeral s0\" \"numeral w1\" \"numeral s1\"]\n  bv_cat.simps[of 0           \"numeral s0\" \"numeral w1\" 0]\n  bv_cat.simps[of 0           \"numeral s0\" \"numeral w1\" 1]\n  bv_cat.simps[of 0           \"numeral s0\" 0            \"numeral s1\"]\n  bv_cat.simps[of 0           \"numeral s0\" 0            0]\n  bv_cat.simps[of 0           \"numeral s0\" 0            1]\n  bv_cat.simps[of 0           \"numeral s0\" 1            \"numeral s1\"]\n  bv_cat.simps[of 0           \"numeral s0\" 1            0]\n  bv_cat.simps[of 0           \"numeral s0\" 1            1]\n  bv_cat.simps[of 0           0            \"numeral w1\" \"numeral s1\"]\n  bv_cat.simps[of 0           0            \"numeral w1\" 0]\n  bv_cat.simps[of 0           0            \"numeral w1\" 1]\n  bv_cat.simps[of 0           0            0            \"numeral s1\"]\n  bv_cat.simps[of 0           0            0            0]\n  bv_cat.simps[of 0           0            0            1]\n  bv_cat.simps[of 0           0            1            \"numeral s1\"]\n  bv_cat.simps[of 0           0            1            0]\n  bv_cat.simps[of 0           0            1            1]\n  bv_cat.simps[of 0           1            \"numeral w1\" \"numeral s1\"]\n  bv_cat.simps[of 0           1            \"numeral w1\" 0]\n  bv_cat.simps[of 0           1            \"numeral w1\" 1]\n  bv_cat.simps[of 0           1            0            \"numeral s1\"]\n  bv_cat.simps[of 0           1            0            0]\n  bv_cat.simps[of 0           1            0            1]\n  bv_cat.simps[of 0           1            1            \"numeral s1\"]\n  bv_cat.simps[of 0           1            1            0]\n  bv_cat.simps[of 0           1            1            1]\n  bv_cat.simps[of 1           \"numeral s0\" \"numeral w1\" \"numeral s1\"]\n  bv_cat.simps[of 1           \"numeral s0\" \"numeral w1\" 0]\n  bv_cat.simps[of 1           \"numeral s0\" \"numeral w1\" 1]\n  bv_cat.simps[of 1           \"numeral s0\" 0            \"numeral s1\"]\n  bv_cat.simps[of 1           \"numeral s0\" 0            0]\n  bv_cat.simps[of 1           \"numeral s0\" 0            1]\n  bv_cat.simps[of 1           \"numeral s0\" 1            \"numeral s1\"]\n  bv_cat.simps[of 1           \"numeral s0\" 1            0]\n  bv_cat.simps[of 1           \"numeral s0\" 1            1]\n  bv_cat.simps[of 1           0            \"numeral w1\" \"numeral s1\"]\n  bv_cat.simps[of 1           0            \"numeral w1\" 0]\n  bv_cat.simps[of 1           0            \"numeral w1\" 1]\n  bv_cat.simps[of 1           0            0            \"numeral s1\"]\n  bv_cat.simps[of 1           0            0            0]\n  bv_cat.simps[of 1           0            0            1]\n  bv_cat.simps[of 1           0            1            \"numeral s1\"]\n  bv_cat.simps[of 1           0            1            0]\n  bv_cat.simps[of 1           0            1            1]\n  bv_cat.simps[of 1           1            \"numeral w1\" \"numeral s1\"]\n  bv_cat.simps[of 1           1            \"numeral w1\" 0]\n  bv_cat.simps[of 1           1            \"numeral w1\" 1]\n  bv_cat.simps[of 1           1            0            \"numeral s1\"]\n  bv_cat.simps[of 1           1            0            0]\n  bv_cat.simps[of 1           1            0            1]\n  bv_cat.simps[of 1           1            1            \"numeral s1\"]\n  bv_cat.simps[of 1           1            1            0]\n  bv_cat.simps[of 1           1            1            1]\n  for w0 s0 w1 s1\n\nlemma size_bv_cat:\n  shows \"snd (bv_cat a b) = snd a + snd b\"\n  by (cases a,cases b,auto simp add: bv_cat.simps)\n\nlemma size_bv_slice:\n  shows \"snd (bv_slice h l a) = h + 1 - l\"\n  by (cases a,auto simp add: bv_slice.simps)\n\nlemma bv_cat_prepend_0:\n  fixes a :: \"'a::len word\"\n  assumes \"s < LENGTH('a)\"\n  shows \"bv_cat (0, s') (a,s) = (if s = 0 then 0 else \\<langle>s-1,0\\<rangle>a,s + s')\"\nproof(cases \"s = 0\")\n  case True\n  thus ?thesis\n    by (auto simp add: bv_cat.simps)\nnext\n  case False\n  {\n    fix b :: \"'a::len word\"\n    assume b: \"b=0\"\n    {\n      fix n::nat\n      assume n: \"n < LENGTH('a)\"  \n      {\n        fix x h l :: nat\n        {\n          fix m :: nat\n          assume m: \"m < LENGTH('a)\"\n          hence \"\\<not> b !! (LENGTH('a) - 1 - m)\"\n            using b\n            by auto\n          hence \"\\<not> to_bl b ! m\"\n            using m\n            by (auto simp add: unfold_test_bit split: if_split_asm)\n        }\n        hence \"\\<not>((\\<langle>h,l\\<rangle>b)::'a::len word) !! x\"\n          apply (cases \"x < LENGTH('a)\";cases \"h < LENGTH('a)\")\n          apply (auto simp add: test_bit_of_take_bits)[1]\n          using b apply simp\n          by (auto simp add: take_bits_def test_bit_bl word_size rev_nth word_rep_drop min_def nth_append)\n      }\n      note 1 = this\n      have \"(fst (bv_cat (b, s') (a,s))) !! n= ((\\<langle>s-1,0\\<rangle>a):: 'a::len word)!!n\"\n        using assms n 1 False\n        apply (auto split: if_split_asm simp add: test_bit_of_take_bits bv_cat.simps word_ao_nth nth_shiftl)\n        using b nth_0 by blast\n    }\n    hence \"(fst (bv_cat (b, s') (a,s))) = ((\\<langle>s-1,0\\<rangle>a):: 'a::len word)\"\n      and \"(snd (bv_cat (b, s') (a,s))) = (s+s')\"\n      apply (intro word_eqI)\n      by (auto simp add: word_size bv_cat.simps)+\n  }\n  thus ?thesis\n    using False\n    apply auto\n    by (metis prod.exhaust_sel)\nqed\n\n\n\n\n\nlemma test_bit_of_bv_cat:\n  fixes a b :: \"'a ::len0 word \\<times> nat\"\n  assumes \"snd a \\<le> LENGTH('a)\"\n      and \"snd b \\<le> LENGTH('a)\"\n      and \"i < LENGTH('a)\"\n    shows \"fst (bv_cat a b) !! i = (if i \\<ge> snd b then (fst a) !! (i - snd b) else (fst b) !! i)\"\n  using assms\n  by (cases a, cases b,auto simp add: bv_cat.simps test_bit_of_take_bits word_ao_nth nth_shiftl word_size split: if_split_asm)\n\nlemma test_bit_of_bv_slice:\n  assumes \"h < \\<M>\"\n  shows \"fst (bv_slice h l a) !! n = (if n < Suc h - l then fst a!!(l+n) else False)\"\n  using assms\n  apply (cases a, cases \"n < \\<M>\",auto simp add: bv_slice.simps test_bit_of_take_bits)\n  by (simp add: word_size test_bit_bin')\n\n\n\nlemma bv_slice_bv_cat:\nassumes \"h < \\<M>\"\n    and \"snd a \\<le> \\<M>\"\n    and \"snd b \\<le> \\<M>\"\n  shows \"bv_slice h l (bv_cat a b) =\n        (if h \\<ge> snd b then\n          (if l \\<ge> snd b then\n            bv_slice (h - snd b) (l - snd b) a\n           else\n            bv_cat (bv_slice (h - snd b) 0 a) (bv_slice (snd b - 1) l b))\n        else\n          (if l \\<ge> snd b then\n               (0,0)\n           else\n              bv_slice h l b))\"\nproof(cases \"h \\<ge> snd b\")\n  case True\n  note h = this\n  show ?thesis\n  proof(cases \"l \\<ge> snd b\")\n    case True\n    {\n      fix i :: nat\n      assume \"i < \\<M>\"\n      hence \"fst (bv_slice h l (bv_cat a b)) !! i = fst (bv_slice (h - snd b) (l - snd b) a) !! i\"\n        using h True assms\n        by (auto simp add: bv_cat.simps test_bit_of_bv_slice nth_ucast test_bit_of_bv_cat split: if_split_asm)\n    }\n    hence \"fst (bv_slice h l (bv_cat a b)) = fst (bv_slice (h - snd b) (l - snd b) a)\"\n      apply (intro word_eqI)\n      by (auto simp add: word_size)\n    moreover\n    have \"snd (bv_slice h l (bv_cat a b)) = snd (bv_slice (h - snd b) (l - snd b) a)\"\n      using True h\n      by (cases a, cases b,auto simp add: size_bv_slice)\n    ultimately\n    show ?thesis\n      using True h\n      apply (auto)\n      by (metis prod.exhaust_sel)\n  next\n    case False\n    {\n      fix i :: nat\n      assume \"i < \\<M>\"\n      hence \"fst (bv_slice h l (bv_cat a b)) !! i = fst (bv_cat (bv_slice (h - snd b) 0 a) (bv_slice (snd b - 1) l b)) !! i\"\n        using h False assms\n        apply (auto simp add: bv_cat.simps nth_ucast test_bit_of_bv_slice test_bit_of_bv_cat word_ao_nth nth_shiftl size_bv_slice split: if_split_asm)\n        by (simp add: Groups.add_ac(2))+\n    }\n    hence \"fst (bv_slice h l (bv_cat a b)) = fst (bv_cat (bv_slice (h - snd b) 0 a) (bv_slice (snd b - 1) l b))\"\n      apply (intro word_eqI)\n      by (auto simp add: word_size)\n    moreover\n    have \"snd (bv_slice h l (bv_cat a b)) = snd (bv_cat (bv_slice (h - snd b) 0 a) (bv_slice (snd b - 1) l b))\"\n      using False h\n      by (cases a, cases b,auto simp add: size_bv_slice size_bv_cat)\n    ultimately\n    show ?thesis\n      using False h\n      apply (auto)\n      by (metis prod.exhaust_sel)\n  qed\nnext\n  case False\n  note h = this\n  show ?thesis\n  proof(cases \"l \\<ge> snd b\")\n    case True\n    {\n      fix i :: nat\n      assume \"i < \\<M>\"\n      hence \"fst (bv_slice h l (bv_cat a b)) !! i = (0::longword) !! i\"\n        using h True assms\n        by (auto simp add: bv_cat.simps nth_ucast test_bit_of_bv_slice test_bit_of_bv_cat split: if_split_asm)\n    }\n    hence \"fst (bv_slice h l (bv_cat a b)) = 0\"\n      apply (intro word_eqI)\n      by (auto simp add: word_size)\n    moreover\n    have \"snd (bv_slice h l (bv_cat a b)) = 0\"\n      using True h\n      by (cases a, cases b,auto simp add: size_bv_slice size_bv_cat)\n    ultimately\n    show ?thesis\n      using True h\n      apply (auto)\n      by (metis prod.exhaust_sel)\n  next\n    case False\n    {\n      fix i :: nat\n      assume \"i < \\<M>\"\n      hence \"fst (bv_slice h l (bv_cat a b)) !! i = fst (bv_slice h l b) !! i\"\n        using h False assms\n        by (auto simp add: bv_cat.simps nth_ucast test_bit_of_bv_slice test_bit_of_bv_cat split: if_split_asm)\n    }\n    hence \"fst (bv_slice h l (bv_cat a b)) = fst (bv_slice h l b)\"\n      apply (intro word_eqI)\n      by (auto simp add: word_size)\n    moreover\n    have \"snd (bv_slice h l (bv_cat a b)) = snd (bv_slice h l b)\"\n      using False h\n      by (cases a, cases b,auto simp add: size_bv_slice size_bv_cat)\n    ultimately\n    show ?thesis\n      using False h\n      apply (auto)\n      by (metis prod.exhaust_sel)\n  qed\nqed\n\n\n\ndefinition \"bv_cat' \\<equiv> bv_cat\"\nlemma take_bits_bv_cat:\n  fixes a b :: \"'b ::len0 word \\<times> nat\"\n  assumes \"h < LENGTH('b)\"\n      and \"snd a \\<le> LENGTH('b)\"\n      and \"snd b \\<le> LENGTH('b)\"\n    shows \"((\\<langle>h,l\\<rangle> (fst (bv_cat a b)))::'a::len0 word) =\n        (if h \\<ge> snd b then\n          (if l \\<ge> snd b then\n            \\<langle>h - snd b,l - snd b\\<rangle>fst a\n           else\n            ((\\<langle>h,l\\<rangle> (fst (bv_cat' a b)))::'a::len0 word))\n        else\n          (if l \\<ge> snd b then\n               0\n           else\n              \\<langle>h,l\\<rangle> (fst b)))\"\nproof(cases \"h \\<ge> snd b\")\n  case True\n  note h = this\n  show ?thesis\n  proof(cases \"l \\<ge> snd b\")\n    case True\n    {\n      fix i :: nat\n      assume \"i < LENGTH('a)\"\n      hence \"((\\<langle>h,l\\<rangle> (fst (bv_cat a b)))::'a::len0 word) !! i = ((\\<langle>h - snd b,l - snd b\\<rangle>fst a)::'a::len0 word) !! i\"\n        using h True assms\n        by (auto simp add: bv_cat.simps test_bit_of_take_bits nth_ucast test_bit_of_bv_cat split: if_split_asm)\n    }\n    hence \"((\\<langle>h,l\\<rangle> (fst (bv_cat a b)))::'a::len0 word) = ((\\<langle>h - snd b,l - snd b\\<rangle>fst a)::'a::len0 word)\"\n      apply (intro word_eqI)\n      by (auto simp add: word_size)\n    thus ?thesis\n      using True h\n      by auto\n  next\n    case False\n    thus ?thesis\n      using h\n      by (auto simp add: bv_cat'_def)\n  qed\nnext\n  case False\n  note h = this\n  show ?thesis\n  proof(cases \"l \\<ge> snd b\")\n    case True\n    {\n      fix i :: nat\n      assume \"i < LENGTH('a)\"\n      hence \"((\\<langle>h,l\\<rangle> (fst (bv_cat a b)))::'a::len0 word) !! i = (0::'a::len0 word) !! i\"\n        using h True assms\n        by (auto simp add: bv_cat.simps nth_ucast test_bit_of_take_bits test_bit_of_bv_cat split: if_split_asm)\n    }\n    thus ?thesis\n      using True h\n      apply (auto)\n      apply (intro word_eqI)\n      by (auto simp add: word_size)\n  next\n    case False\n    {\n      fix i :: nat\n      assume \"i < LENGTH('a)\"\n      hence \"((\\<langle>h,l\\<rangle> (fst (bv_cat a b)))::'a::len0 word) !! i = (\\<langle>h,l\\<rangle> (fst b)::'a::len0 word) !! i\"\n        using h False assms\n        by (auto simp add: bv_cat.simps nth_ucast test_bit_of_take_bits test_bit_of_bv_cat split: if_split_asm)\n\n    }\n    thus ?thesis\n      using False h\n      apply (auto)\n      apply (intro word_eqI)\n      by (auto simp add: word_size)\n  qed\nqed\n\n\nlemma take_bits_bv_slice:\n  assumes \"h < \\<M>\"\n      and \"h' < \\<M>\"\n  shows \"\\<langle>h,l\\<rangle>fst (bv_slice h' l' a) =  \\<langle>(if Suc h - l < Suc h' - (l + l') then h + l' else h'),l + l'\\<rangle>fst a\"\n  using assms\n  by (cases a,auto simp add: bv_slice.simps)\n\nlemma bv_slice_take_bits:\n  assumes \"h < \\<M>\"\n      and \"h' < LENGTH('a)\"\n  fixes a ::\"'a::len0 word\"\n  shows \"bv_slice h l (\\<langle>h',l'\\<rangle>a, s) = (\\<langle>(if Suc h - l < Suc h' - (l + l') then h + l' else h'),l + l'\\<rangle>a, h + 1 - l)\"\n  using assms\n  by (auto simp add: bv_slice.simps)\n\nlemma bv_slice_bit32:\n  fixes a :: longword\n  assumes \"s \\<ge> 32\"\n  shows \"bv_slice 31 0 (a,s) = (ucast ((\\<langle>31,0\\<rangle>a)::32 word), 32)\"\n  using assms\n  by (auto simp add: bv_slice.simps)\n\n\n \nlemma bv_slice_nth_bit:\n  assumes \"h < \\<M>\"\n  shows \"bv_slice h h a = bool_to_bv (fst a !! h)\"\nproof-\n  {\n    fix i :: nat\n    assume \"i < \\<M>\"\n    hence \"((\\<langle>h,h\\<rangle>(fst a))::longword) !! i = (if fst a !! h then 1::longword else 0) !! i\"\n      using assms\n      by (auto simp add: test_bit_of_take_bits)\n  }\n  hence \"((\\<langle>h,h\\<rangle>(fst a))::longword) = (if fst a !! h then 1::longword else 0)\"\n    apply (intro word_eqI)\n    by (auto simp add: word_size)\n  thus ?thesis\n    by (cases a;auto simp add: bv_slice.simps)\nqed\n\n\n\nsubsection \\<open>Arithmetic\\<close>\n\nlemma BV_Add_bit64:\n  fixes a b :: longword\n    shows \"(a,64) +\\<^sup>b\\<^sup>v (b,64) = (ucast (((\\<langle>63,0\\<rangle>a)::64 word) + \\<langle>63,0\\<rangle>b), 64)\"\nproof-\n  have \"(a,64) +\\<^sup>b\\<^sup>v (b,64) = (\\<langle>63,0\\<rangle>(a + b), 64)\"\n    by (cases a;cases b;auto simp add: exec_BV_Plus_def case_prod_unfold)\n  also have \"... = (ucast ((\\<langle>63,0\\<rangle>(a + b))::64 word), 64)\"\n    by (subst ucast_take_bits,simp,simp,simp)\n  also have \"... = (ucast (((\\<langle>63,0\\<rangle>a)::64 word) + \\<langle>63,0\\<rangle>b), 64)\"\n    by (subst take_bits_plus,simp,simp,simp)\n  finally\n  show ?thesis\n    by auto\nqed\n\nlemma BV_Add_bit33:\n  fixes a b :: longword\n    shows \"(a,33) +\\<^sup>b\\<^sup>v (b,33) = (ucast (((\\<langle>32,0\\<rangle>a)::33 word) + \\<langle>32,0\\<rangle>b), 33)\"\nproof-\n  have \"(a,33) +\\<^sup>b\\<^sup>v (b,33) = (\\<langle>32,0\\<rangle>(a + b), 33)\"\n    by (cases a;cases b;auto simp add: exec_BV_Plus_def case_prod_unfold)\n  also have \"... = (ucast ((\\<langle>32,0\\<rangle>(a + b))::33 word), 33)\"\n    by (subst ucast_take_bits,simp,simp,simp)\n  also have \"... = (ucast (((\\<langle>32,0\\<rangle>a)::33 word) + \\<langle>32,0\\<rangle>b), 33)\"\n    by (subst take_bits_plus,simp,simp,simp)\n  finally\n  show ?thesis\n    by auto\nqed\n\nlemma BV_Add_bit65:\n  fixes a b :: longword\n    shows \"(a,65) +\\<^sup>b\\<^sup>v (b,65) = (ucast (((\\<langle>64,0\\<rangle>a)::65 word) + \\<langle>64,0\\<rangle>b), 65)\"\nproof-\n  have \"(a,65) +\\<^sup>b\\<^sup>v (b,65) = (\\<langle>64,0\\<rangle>(a + b), 65)\"\n    by (cases a;cases b;auto simp add: exec_BV_Plus_def case_prod_unfold)\n  also have \"... = (ucast ((\\<langle>64,0\\<rangle>(a + b))::65 word), 65)\"\n    by (subst ucast_take_bits,simp,simp,simp)\n  also have \"... = (ucast (((\\<langle>64,0\\<rangle>a)::65 word) + \\<langle>64,0\\<rangle>b), 65)\"\n    by (subst take_bits_plus,simp,simp,simp)\n  finally\n  show ?thesis\n    by auto\nqed\n\nsubsection \\<open>Floating Point operations\\<close>\n\ncontext abstract_float\nbegin\n\n\nlemma BV_Plus_bit64:\n  fixes a b :: \"64 word\"\n  shows \"(\\<langle>63,0\\<rangle>a, 64) fplus\\<^sup>b\\<^sup>v (\\<langle>63,0\\<rangle>b, 64) = (\\<langle>63,0\\<rangle>(a +\\<^sup>f b), 64)\"\n  by (auto simp add: exec_BV_Plus_Double_def)\n\nlemma BV_Plus_bit64_numeral:\n  fixes a :: \"64 word\"\n  shows \"(\\<langle>63,0\\<rangle>a, 64) fplus\\<^sup>b\\<^sup>v (numeral n, 64) = (\\<langle>63,0\\<rangle>(a +\\<^sup>f \\<langle>63,0\\<rangle>((numeral n)::longword)), 64)\"\n  by (auto simp add: exec_BV_Plus_Double_def)\n\nlemma BV_Sub_bit64:\n  fixes a b :: \"64 word\"\n  shows \"(\\<langle>63,0\\<rangle>a, 64) fsub\\<^sup>b\\<^sup>v (\\<langle>63,0\\<rangle>b, 64) = (\\<langle>63,0\\<rangle>(a -\\<^sup>f b), 64)\"\n  by (auto simp add: exec_BV_Sub_Double_def)\n\nlemma BV_Sub_bit64_numeral:\n  fixes a :: \"64 word\"\n  shows \"(\\<langle>63,0\\<rangle>a, 64) fsub\\<^sup>b\\<^sup>v (numeral n, 64) = (\\<langle>63,0\\<rangle>(a -\\<^sup>f \\<langle>63,0\\<rangle>((numeral n)::longword)), 64)\"\n  by (auto simp add: exec_BV_Sub_Double_def)\n\nlemma BV_Mult_bit64:\n  fixes a b :: \"64 word\"\n  shows \"(\\<langle>63,0\\<rangle>a, 64) fmult\\<^sup>b\\<^sup>v (\\<langle>63,0\\<rangle>b, 64) = (\\<langle>63,0\\<rangle>(a *\\<^sup>f b), 64)\"\n  by (auto simp add: exec_BV_Mul_Double_def)\n\nlemma BV_Mult_bit64_numeral_r:\n  fixes a :: \"64 word\"\n  shows \"(\\<langle>63,0\\<rangle>a, 64) fmult\\<^sup>b\\<^sup>v (numeral n, 64) = (\\<langle>63,0\\<rangle>(a *\\<^sup>f \\<langle>63,0\\<rangle>((numeral n)::longword)), 64)\"\n  by (auto simp add: exec_BV_Mul_Double_def)\nlemma BV_Mult_bit64_numeral_l:\n  fixes a :: \"64 word\"\n  shows \"(numeral n, 64) fmult\\<^sup>b\\<^sup>v (\\<langle>63,0\\<rangle>a, 64) = (\\<langle>63,0\\<rangle>(\\<langle>63,0\\<rangle>((numeral n)::longword) *\\<^sup>f a), 64)\"\n  by (auto simp add: exec_BV_Mul_Double_def)\nlemma BV_Mult_bit64_0_l:\n  fixes a :: \"64 word\"\n  shows \"(0, 64) fmult\\<^sup>b\\<^sup>v (\\<langle>63,0\\<rangle>a, 64) = (\\<langle>63,0\\<rangle>(0\\<^sup>+ *\\<^sup>f a), 64)\"\n  by (auto simp add: exec_BV_Mul_Double_def plus_zero_def)\nlemma BV_Mult_bit64_0_r:\n  fixes a :: \"64 word\"\n  shows \"(\\<langle>63,0\\<rangle>a, 64) fmult\\<^sup>b\\<^sup>v (0, 64) = (\\<langle>63,0\\<rangle>(a *\\<^sup>f 0\\<^sup>+), 64)\"\n  by (auto simp add: exec_BV_Mul_Double_def plus_zero_def)\n\n\nlemma BV_Div_bit64:\n  fixes a b :: \"64 word\"\n  shows \"(\\<langle>63,0\\<rangle>a, 64) fdiv\\<^sup>b\\<^sup>v (\\<langle>63,0\\<rangle>b, 64) = (\\<langle>63,0\\<rangle>(a div\\<^sup>f b), 64)\"\n  by (auto simp add: exec_BV_Div_Double_def)\n\nlemma BV_Div_bit64_numeral: \n  fixes a :: \"64 word\"\n  shows \"(\\<langle>63,0\\<rangle>a, 64) fdiv\\<^sup>b\\<^sup>v (numeral n, 64) = (\\<langle>63,0\\<rangle>(a div\\<^sup>f \\<langle>63,0\\<rangle>((numeral n)::longword)), 64)\"\n  by (auto simp add: exec_BV_Div_Double_def)\n\nend\n\n\n\nsubsection \\<open>Simplification rules\\<close>\n\n\nlemmas (in abstract_float) bit_vector_simps =\n    bv_slice_bv_cat take_bits_bv_slice bv_slice_take_bits take_bits_bv_cat bv_slice_bit32\n    bv_cat_prepend_0 size_bv_cat size_bv_slice\n    bv_to_bool_bool_to_bv snd_bool_to_bv\n    bv_to_bool_True bv_to_bool_True_Suc0\n    bv_to_bool_False bv_to_bool_False_Suc0\n    BV_Add_bit65 BV_Add_bit64 BV_Add_bit33\n    BV_Plus_bit64 BV_Plus_bit64_numeral\n    BV_Sub_bit64 BV_Sub_bit64_numeral\n    BV_Mult_bit64 BV_Mult_bit64_numeral_r BV_Mult_bit64_numeral_l BV_Mult_bit64_0_l BV_Mult_bit64_0_r\n    BV_Div_bit64 BV_Div_bit64_numeral\n    bv_slice_bit32\n    bv_NOT.simps\n    bv_NOT_bool_to_bv bool_to_bv_eq bv_slice_nth_bit\nend\n", "meta": {"author": "ssrg-vt", "repo": "Luce-src", "sha": "f7f1ef0fd07bba48bcb3d5e32404db6013a5f1bc", "save_path": "github-repos/isabelle/ssrg-vt-Luce-src", "path": "github-repos/isabelle/ssrg-vt-Luce-src/Luce-src-f7f1ef0fd07bba48bcb3d5e32404db6013a5f1bc/safecomp2019_artifact/current_work/isabelle/BitVector_Rewriting.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5660185351961015, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.29847092614800336}}
{"text": "theory flash105Bra  imports flash105Rev\n \n  begin\nlemma onInv105:\n\n   assumes  a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" and \n\n     b1:\"r \\<in> rules N\" and b2:\"invf=inv105  iInv1  iInv2 \"\n   shows  \"invHoldForRule' s invf r (invariants   N)\" \n   proof - \nhave c1:\"ex1P N (% iRule1 .  r=NI_Local_GetX_PutX1 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_GetX  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Replace  iRule1 )\\<or>ex0P N (  r=NI_ShWb N )\\<or>ex0P N (  r=PI_Local_GetX_GetX2 )\\<or>ex0P N (  r=NI_Local_PutXAcksDone )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX7 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Nak2  iRule1 )\\<or>ex0P N (  r=NI_ReplaceHomeShrVld )\\<or>ex1P N (% iRule1 .  r=NI_Remote_Put  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX5 N  iRule1 )\\<or>ex0P N (  r=NI_Wb )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Get  iRule1 )\\<or>ex0P N (  r=PI_Local_Replace )\\<or>ex1P N (% iRule1 .  r=NI_ReplaceShrVld  iRule1 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Local_GetX_PutX8 N  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=NI_InvAck_2 N  iRule1 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Remote_Get_Nak2  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=PI_Remote_Replace  iRule1 )\\<or>ex0P N (  r=NI_Nak_Home )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Put2  iRule1 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_InvAck_1  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX11 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX6 N  iRule1 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Remote_Get_Put2  iRule1  iRule2 )\\<or>ex0P N (  r=PI_Local_Get_Put )\\<or>ex0P N (  r=PI_Local_GetX_PutX1 N )\\<or>ex1P N (% iRule1 .  r=NI_InvAck_1_Home  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Remote_Get_Nak1  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Nak1  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_Nak2  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX10_home N  iRule1 )\\<or>ex1P N (% iRule1 .  r=PI_Remote_Get  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_Nak3  iRule1 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Local_GetX_PutX10 N  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX2 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Remote_Get_Put1  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Remote_PutX  iRule1 )\\<or>ex1P N (% iRule1 .  r=Store  iRule1 )\\<or>ex0P N (  r=NI_FAck )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX3 N  iRule1 )\\<or>ex0P N (  r=PI_Local_GetX_PutX3 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Remote_GetX_PutX  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX8_home N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Put1 N  iRule1 )\\<or>ex0P N (  r=PI_Local_GetX_GetX1 )\\<or>ex0P N (  r=StoreHome )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Remote_GetX_Nak  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=NI_Inv  iRule1 )\\<or>ex1P N (% iRule1 .  r=PI_Remote_PutX  iRule1 )\\<or>ex0P N (  r=PI_Local_GetX_PutX4 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX4 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Nak  iRule1 )\\<or>ex0P N (  r=PI_Local_GetX_PutX2 N )\\<or>ex0P N (  r=NI_Local_Put )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_Nak1  iRule1 )\\<or>ex0P N (  r=NI_Nak_Clear )\\<or>ex0P N (  r=PI_Local_PutX )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Nak3  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Remote_GetX_Nak_Home  iRule1 )\\<or>ex0P N (  r=PI_Local_Get_Get )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX9 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=PI_Remote_GetX  iRule1 )\\<or>ex0P N (  r=NI_ReplaceHome )\\<or>ex1P N (% iRule1 .  r=NI_Remote_GetX_PutX_Home  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Put3  iRule1 )\" \n\n        apply(cut_tac  b1)\n        apply auto\n        done      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX1 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX1 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX1VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_GetX  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_GetX  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_GetX_GetX  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_GetXVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Replace  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Replace  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Replace  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_ReplaceVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_ShWb N )\n\"\n         \n         from c1 have c2:\" r= NI_ShWb N \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_ShWb N ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_ShWbVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_GetX2 )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_GetX2 \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (PI_Local_GetX_GetX2 ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_GetX_GetX2VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= NI_Local_PutXAcksDone )\n\"\n         \n         from c1 have c2:\" r= NI_Local_PutXAcksDone \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_PutXAcksDone ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_Local_PutXAcksDoneVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX7 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX7 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX7VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Nak2  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Nak2  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_Get_Nak2  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_Nak2VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_ReplaceHomeShrVld )\n\"\n         \n         from c1 have c2:\" r= NI_ReplaceHomeShrVld \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_ReplaceHomeShrVld ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_ReplaceHomeShrVldVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_Put  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_Put  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Remote_Put  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_PutVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX5 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX5 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX5VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_Wb )\n\"\n         \n         from c1 have c2:\" r= NI_Wb \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Wb ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_WbVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Get  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Get  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_Get_Get  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_GetVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_Replace )\n\"\n         \n         from c1 have c2:\" r= PI_Local_Replace \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (PI_Local_Replace ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_ReplaceVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_ReplaceShrVld  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_ReplaceShrVld  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_ReplaceShrVld  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_ReplaceShrVldVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Local_GetX_PutX8 N  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Local_GetX_PutX8 N  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX8VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_InvAck_2 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_InvAck_2 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_InvAck_2 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_InvAck_2VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Remote_Get_Nak2  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Remote_Get_Nak2  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_Get_Nak2VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= PI_Remote_Replace  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= PI_Remote_Replace  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (PI_Remote_Replace  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis PI_Remote_ReplaceVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_Nak_Home )\n\"\n         \n         from c1 have c2:\" r= NI_Nak_Home \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Nak_Home ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_Nak_HomeVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Put2  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Put2  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_Get_Put2  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_Put2VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_InvAck_1  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_InvAck_1  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_InvAck_1VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX11 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX11 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX11VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX6 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX6 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX6VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Remote_Get_Put2  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Remote_Get_Put2  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_Get_Put2VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_Get_Put )\n\"\n         \n         from c1 have c2:\" r= PI_Local_Get_Put \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (PI_Local_Get_Put ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_Get_PutVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_PutX1 N )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_PutX1 N \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (PI_Local_GetX_PutX1 N ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_GetX_PutX1VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_InvAck_1_Home  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_InvAck_1_Home  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_InvAck_1_Home  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_InvAck_1_HomeVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_Get_Nak1  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_Get_Nak1  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_Get_Nak1VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Nak1  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Nak1  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_Get_Nak1  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_Nak1VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_Nak2  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_Nak2  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_Nak2VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX10_home N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX10_home N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX10_homeVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= PI_Remote_Get  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= PI_Remote_Get  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (PI_Remote_Get  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis PI_Remote_GetVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_Nak3  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_Nak3  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_Nak3VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Local_GetX_PutX10 N  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Local_GetX_PutX10 N  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX10VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX2 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX2 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX2VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_Get_Put1  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_Get_Put1  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Remote_Get_Put1  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_Get_Put1VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_PutX  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_PutX  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Remote_PutX  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_PutXVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= Store  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= Store  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (Store  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis StoreVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_FAck )\n\"\n         \n         from c1 have c2:\" r= NI_FAck \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_FAck ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_FAckVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX3 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX3 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX3VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_PutX3 )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_PutX3 \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (PI_Local_GetX_PutX3 ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_GetX_PutX3VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Remote_GetX_PutX  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Remote_GetX_PutX  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_GetX_PutXVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX8_home N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX8_home N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX8_homeVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Put1 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Put1 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_Put1VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_GetX1 )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_GetX1 \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (PI_Local_GetX_GetX1 ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_GetX_GetX1VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= StoreHome )\n\"\n         \n         from c1 have c2:\" r= StoreHome \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (StoreHome ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis StoreHomeVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Remote_GetX_Nak  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Remote_GetX_Nak  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_GetX_NakVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Inv  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Inv  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Inv  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_InvVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= PI_Remote_PutX  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= PI_Remote_PutX  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (PI_Remote_PutX  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis PI_Remote_PutXVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_PutX4 )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_PutX4 \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (PI_Local_GetX_PutX4 ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_GetX_PutX4VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX4 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX4 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX4VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Nak  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Nak  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Nak  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_NakVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_PutX2 N )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_PutX2 N \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (PI_Local_GetX_PutX2 N ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_GetX_PutX2VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= NI_Local_Put )\n\"\n         \n         from c1 have c2:\" r= NI_Local_Put \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_Put ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_Local_PutVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_Nak1  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_Nak1  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_Nak1VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_Nak_Clear )\n\"\n         \n         from c1 have c2:\" r= NI_Nak_Clear \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Nak_Clear ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_Nak_ClearVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_PutX )\n\"\n         \n         from c1 have c2:\" r= PI_Local_PutX \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (PI_Local_PutX ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_PutXVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Nak3  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Nak3  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_Get_Nak3  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_Nak3VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_GetX_Nak_Home  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_GetX_Nak_Home  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_GetX_Nak_HomeVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_Get_Get )\n\"\n         \n         from c1 have c2:\" r= PI_Local_Get_Get \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (PI_Local_Get_Get ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_Get_GetVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX9 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX9 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX9VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= PI_Remote_GetX  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= PI_Remote_GetX  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (PI_Remote_GetX  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis PI_Remote_GetXVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_ReplaceHome )\n\"\n         \n         from c1 have c2:\" r= NI_ReplaceHome \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_ReplaceHome ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_ReplaceHomeVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_GetX_PutX_Home  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_GetX_PutX_Home  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_GetX_PutX_HomeVsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Put3  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Put3  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv105  iInv1  iInv2 ) (NI_Local_Get_Put3  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_Put3VsInv105 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }ultimately show \"invHoldForRule' s invf r (invariants N) \"\n          by blast \n     qed\nend", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash105Bra.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6757645879592642, "lm_q2_score": 0.44167300566462553, "lm_q1q2_score": 0.29846697668568545}}
{"text": "theory Combine_Opt\n  imports        \n  \"../Combine\"\n  \"Balance_Opt_LR\"\nbegin\n\n\ncontext rbt_impl\nbegin\ninterpretation rbt_impl_deps .\n\n\npartial_function (M) combine_opt ::\n  \"('ki, 'vi) rbti \\<Rightarrow> ('ki, 'vi) rbti \\<Rightarrow> ('ki, 'vi) rbti llM\" where\n  \"combine_opt l_p r_p = do {\n    if l_p = null then return r_p\n    else if r_p = null then return l_p\n    else do {\n      l \\<leftarrow> ll_load l_p;\n      r \\<leftarrow> ll_load r_p;\n      if rbt_node.color l = rbt_node.color r\n      then do {\n        combined_p \\<leftarrow> combine_opt (rbt_node.right l) (rbt_node.left r);\n        is_red_b \\<leftarrow> ll_is_red_br combined_p;\n        if is_red_b = ll_True then\n        do {\n            combined \\<leftarrow> ll_load combined_p;\n            case combined of (RBT_NODE cc cl ck cv cr) \\<Rightarrow>\n            do {\n              set_right_p cl l_p;\n              set_left_p cr r_p;\n              ll_store (RBT_NODE cc l_p ck cv r_p) combined_p;\n              return combined_p\n            }\n        }\n        else do {\n          set_left_p combined_p r_p;\n          if rbt_node.color l = 0\n          then do {\n            set_right_p r_p l_p;\n            return l_p\n          }\n          else do {\n            set_right_p r_p l_p;\n            balance_left_opt l_p\n          }\n        }\n      }\n      else if (rbt_node.color r = 0)\n      then do {\n        combined_p \\<leftarrow> combine_opt l_p (rbt_node.left r);\n        set_left_p combined_p r_p;\n        return r_p\n      }\n      else do { \n        combined_p \\<leftarrow> combine_opt (rbt_node.right l) r_p;\n        set_right_p combined_p l_p;\n        return l_p\n      }\n    }\n  }\"\n\n\nlemma combine_opt_correct [vcg_rules]:\n  \"\n  llvm_htriple\n  (rbt_assn l li ** rbt_assn r ri)\n  (combine_opt li ri)\n  (\\<lambda>x. rbt_assn (rbt_combine l r) x)\n\"\nproof(induction l r arbitrary: li ri rule: RBT_Impl.combine.induct)\n  case (1 x)\n  then show ?case \n    apply (subst combine_opt.simps)\n    apply vcg\n    done\nnext\n  case (2 v va vb vc vd)\n  then show ?case \n    apply (subst combine_opt.simps)\n    apply vcg\n    done\nnext\n  case (3 a k x b c s y d)\n  note [vcg_rules] = 3\n  show ?case\n    apply (subst combine_opt.simps)\n    apply vcg\n    apply (cases \"rbt_combine b c\")\n     apply (auto split: color.splits)\n     apply vcg\n    done\nnext\n  case (4 a k x b c s y d)\n  note [vcg_rules] = 4\n  show ?case\n    apply (subst combine_opt.simps)\n    apply vcg\n    apply (cases \"rbt_combine b c\")\n     apply (auto split: color.splits)\n     apply vcg\n    done\nnext\n  case (5 va vb vc vd b k x c)\n  note [vcg_rules] = 5\n  show ?case\n    apply (subst combine_opt.simps)\n    apply vcg\n    done\nnext\n  case (6 a k x b va vb vc vd)\n  note [vcg_rules] = 6\n  show ?case\n    apply (subst combine_opt.simps)\n    apply vcg\n    done\nqed\n\n\nlemmas [llvm_code] = combine_opt.simps\n\n\nend\n\n\nend", "meta": {"author": "leanderBehr", "repo": "isabelle-llvm-RBT", "sha": "9456c7160d0d190bdb3ac358bc0058d22fb19926", "save_path": "github-repos/isabelle/leanderBehr-isabelle-llvm-RBT", "path": "github-repos/isabelle/leanderBehr-isabelle-llvm-RBT/isabelle-llvm-RBT-9456c7160d0d190bdb3ac358bc0058d22fb19926/LLVM_DS_RBT/Delete/Alloc_Optimized/Combine_Opt.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6261241772283034, "lm_q2_score": 0.476579651063676, "lm_q1q2_score": 0.29839804190599606}}
{"text": "theory CoCallImplTTreeSafe\nimports CoCallImplTTree CoCallAnalysisSpec TTreeAnalysisSpec\nbegin\n\nlemma valid_lists_many_calls:\n  assumes \"\\<not> one_call_in_path x p\"\n  assumes \"p \\<in> valid_lists S G\"\n  shows \"x--x \\<in> G\"\nusing assms(2,1)\nproof(induction rule:valid_lists.induct[case_names Nil Cons])\n  case Nil thus ?case by simp\nnext\n  case (Cons xs x')\n  show ?case\n  proof(cases \"one_call_in_path x xs\")\n    case False\n    from Cons.IH[OF this]\n    show ?thesis.\n  next\n    case True\n    with \\<open>\\<not> one_call_in_path x (x' # xs)\\<close>\n    have [simp]: \"x' = x\" by (auto split: if_splits)\n\n    have \"x \\<in> set xs\"\n    proof(rule ccontr)\n      assume \"x \\<notin> set xs\"\n      hence \"no_call_in_path x xs\" by (metis no_call_in_path_set_conv)\n      hence \"one_call_in_path x (x # xs)\" by simp\n      with Cons show False by simp\n    qed\n    with \\<open>set xs \\<subseteq> ccNeighbors x' G\\<close>\n    have \"x \\<in> ccNeighbors x G\" by auto\n    thus ?thesis by simp\n  qed\nqed\n\ncontext CoCallArityEdom\nbegin\n lemma carrier_Fexp': \"carrier (Texp e\\<cdot>a) \\<subseteq> fv e\"\n    unfolding Texp_simp carrier_ccTTree\n    by (rule Aexp_edom)\n\nend\n\n\ncontext CoCallAritySafe\nbegin\n\nlemma carrier_AnalBinds_below:\n  \"carrier ((Texp.AnalBinds  \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) x) \\<subseteq> edom ((ABinds \\<Delta>)\\<cdot>(Aheap \\<Delta> e\\<cdot>a))\"\nby (auto simp add: Texp.AnalBinds_lookup Texp_def split: option.splits \n         elim!: subsetD[OF edom_mono[OF monofun_cfun_fun[OF ABind_below_ABinds]]])\n\nsublocale TTreeAnalysisCarrier Texp\n  apply standard\n  unfolding Texp_simp carrier_ccTTree\n  apply standard\n  done\n\nsublocale TTreeAnalysisSafe Texp\nproof\n  fix x e a\n\n  from edom_mono[OF Aexp_App]\n  have \"{x} \\<union> edom (Aexp e\\<cdot>(inc\\<cdot>a)) \\<subseteq> edom (Aexp (App e x)\\<cdot>a)\" by auto\n  moreover\n  {\n  have \"ccApprox (many_calls x \\<otimes>\\<otimes> ccTTree (edom (Aexp e\\<cdot>(inc\\<cdot>a))) (ccExp e\\<cdot>(inc\\<cdot>a))) \n    = cc_restr (edom (Aexp e\\<cdot>(inc\\<cdot>a))) (ccExp e\\<cdot>(inc\\<cdot>a)) \\<squnion> ccProd {x} (insert x (edom (Aexp e\\<cdot>(inc\\<cdot>a))))\"\n    by (simp add: ccApprox_both ccProd_insert2[where S' = \"edom e\" for e])\n  also\n  have \"edom (Aexp e\\<cdot>(inc\\<cdot>a)) \\<subseteq> fv e\"\n    by (rule Aexp_edom)\n  also(below_trans[OF eq_imp_below join_mono[OF below_refl ccProd_mono2[OF insert_mono] ]])\n  have \"cc_restr (edom (Aexp e\\<cdot>(inc\\<cdot>a))) (ccExp e\\<cdot>(inc\\<cdot>a)) \\<sqsubseteq> ccExp e\\<cdot>(inc\\<cdot>a)\"\n    by (rule cc_restr_below_arg)\n  also\n  have \"ccExp e\\<cdot>(inc\\<cdot>a) \\<squnion> ccProd {x} (insert x (fv e)) \\<sqsubseteq> ccExp (App e x)\\<cdot>a\" \n    by (rule ccExp_App)\n  finally\n  have \"ccApprox (many_calls x \\<otimes>\\<otimes> ccTTree (edom (Aexp e\\<cdot>(inc\\<cdot>a))) (ccExp e\\<cdot>(inc\\<cdot>a))) \\<sqsubseteq> ccExp (App e x)\\<cdot>a\" by this simp_all\n  }\n  ultimately\n  show \"many_calls x \\<otimes>\\<otimes> Texp e\\<cdot>(inc\\<cdot>a) \\<sqsubseteq> Texp (App e x)\\<cdot>a\"\n    unfolding Texp_simp by (auto intro!: below_ccTTreeI)\nnext\n  fix y e n\n  show \"without y (Texp e\\<cdot>(pred\\<cdot>n)) \\<sqsubseteq> Texp (Lam [y]. e)\\<cdot>n\"\n    unfolding Texp_simp\n    by (auto dest: subsetD[OF Aexp_edom]\n             intro!: below_ccTTreeI  below_trans[OF _ ccExp_Lam] cc_restr_mono1 subsetD[OF edom_mono[OF Aexp_Lam]])\nnext\n  fix e y x a\n\n  from edom_mono[OF Aexp_subst]\n  have *: \"edom (Aexp e[y::=x]\\<cdot>a) \\<subseteq> insert x (edom (Aexp e\\<cdot>a) - {y})\" by simp\n\n  have \"Texp e[y::=x]\\<cdot>a = ccTTree (edom (Aexp e[y::=x]\\<cdot>a)) (ccExp e[y::=x]\\<cdot>a)\"\n    unfolding Texp_simp..\n  also have \"\\<dots> \\<sqsubseteq> ccTTree (insert x (edom (Aexp e\\<cdot>a) - {y})) (ccExp e[y::=x]\\<cdot>a)\"\n    by (rule ccTTree_mono1[OF *])\n  also have \"\\<dots> \\<sqsubseteq> many_calls x \\<otimes>\\<otimes> without x (\\<dots>)\"\n    by (rule paths_many_calls_subset)\n  also have \"without x (ccTTree (insert x (edom (Aexp e\\<cdot>a) - {y})) (ccExp e[y::=x]\\<cdot>a))\n    = ccTTree (edom (Aexp e\\<cdot>a) - {y} - {x}) (ccExp e[y::=x]\\<cdot>a)\"\n    by simp\n  also have \"\\<dots> \\<sqsubseteq> ccTTree (edom (Aexp e\\<cdot>a) - {y} - {x}) (ccExp e\\<cdot>a)\"\n    by (rule ccTTree_cong_below[OF ccExp_subst]) auto\n  also have \"\\<dots> = without y (ccTTree (edom (Aexp e\\<cdot>a) - {x}) (ccExp e\\<cdot>a))\"\n    by simp (metis Diff_insert Diff_insert2)\n  also have \"ccTTree (edom (Aexp e\\<cdot>a) - {x}) (ccExp e\\<cdot>a) \\<sqsubseteq> ccTTree (edom (Aexp e\\<cdot>a)) (ccExp e\\<cdot>a)\"\n    by (rule ccTTree_mono1) auto\n  also have \"\\<dots> = Texp e\\<cdot>a\"\n    unfolding Texp_simp..\n  finally\n  show \"Texp e[y::=x]\\<cdot>a \\<sqsubseteq> many_calls x \\<otimes>\\<otimes> without y (Texp e\\<cdot>a)\"\n    by this simp_all\nnext\n  fix v a\n  have \"up\\<cdot>a \\<sqsubseteq> (Aexp (Var v)\\<cdot>a) v\" by (rule Aexp_Var)\n  hence \"v \\<in> edom (Aexp (Var v)\\<cdot>a)\" by (auto simp add: edom_def)\n  thus \"single v \\<sqsubseteq> Texp (Var v)\\<cdot>a\"\n    unfolding Texp_simp\n    by (auto intro: below_ccTTreeI)\nnext\n  fix scrut e1 a e2\n  have \"ccTTree (edom (Aexp e1\\<cdot>a)) (ccExp e1\\<cdot>a) \\<oplus>\\<oplus> ccTTree (edom (Aexp e2\\<cdot>a)) (ccExp e2\\<cdot>a)\n    \\<sqsubseteq> ccTTree (edom (Aexp e1\\<cdot>a) \\<union> edom (Aexp e2\\<cdot>a)) (ccExp e1\\<cdot>a \\<squnion> ccExp e2\\<cdot>a)\"\n      by (rule either_ccTTree)\n  note both_mono2'[OF this]\n  also\n  have \"ccTTree (edom (Aexp scrut\\<cdot>0)) (ccExp scrut\\<cdot>0) \\<otimes>\\<otimes> ccTTree (edom (Aexp e1\\<cdot>a) \\<union> edom (Aexp e2\\<cdot>a)) (ccExp e1\\<cdot>a \\<squnion> ccExp e2\\<cdot>a)\n    \\<sqsubseteq> ccTTree (edom (Aexp scrut\\<cdot>0) \\<union> (edom (Aexp e1\\<cdot>a) \\<union> edom (Aexp e2\\<cdot>a))) (ccExp scrut\\<cdot>0 \\<squnion> (ccExp e1\\<cdot>a \\<squnion> ccExp e2\\<cdot>a) \\<squnion> ccProd (edom (Aexp scrut\\<cdot>0)) (edom (Aexp e1\\<cdot>a) \\<union> edom (Aexp e2\\<cdot>a)))\"\n    by (rule interleave_ccTTree)\n  also\n  have \"edom (Aexp scrut\\<cdot>0) \\<union> (edom (Aexp e1\\<cdot>a) \\<union> edom (Aexp e2\\<cdot>a)) = edom (Aexp scrut\\<cdot>0 \\<squnion> Aexp e1\\<cdot>a \\<squnion> Aexp e2\\<cdot>a)\" by auto\n  also\n  have \"Aexp scrut\\<cdot>0 \\<squnion> Aexp e1\\<cdot>a \\<squnion> Aexp e2\\<cdot>a \\<sqsubseteq> Aexp (scrut ? e1 : e2)\\<cdot>a\"\n    by (rule Aexp_IfThenElse)\n  also\n  have \"ccExp scrut\\<cdot>0 \\<squnion> (ccExp e1\\<cdot>a \\<squnion> ccExp e2\\<cdot>a) \\<squnion> ccProd (edom (Aexp scrut\\<cdot>0)) (edom (Aexp e1\\<cdot>a) \\<union> edom (Aexp e2\\<cdot>a)) \\<sqsubseteq>\n        ccExp (scrut ? e1 : e2)\\<cdot>a\"\n    by (rule ccExp_IfThenElse)\n  \n  show \"Texp scrut\\<cdot>0 \\<otimes>\\<otimes> (Texp e1\\<cdot>a \\<oplus>\\<oplus> Texp e2\\<cdot>a) \\<sqsubseteq> Texp (scrut ? e1 : e2)\\<cdot>a\"\n    unfolding Texp_simp\n    by (auto simp add: ccApprox_both join_below_iff  below_trans[OF _ join_above2]\n             intro!: below_ccTTreeI below_trans[OF cc_restr_below_arg]\n                     below_trans[OF _ ccExp_IfThenElse]  subsetD[OF edom_mono[OF Aexp_IfThenElse]])\nnext\n  fix e\n  assume \"isVal e\"\n  hence [simp]: \"ccExp e\\<cdot>0 = ccSquare (fv e)\" by (rule ccExp_pap)\n  thus \"repeatable (Texp e\\<cdot>0)\"\n    unfolding Texp_simp by (auto intro: repeatable_ccTTree_ccSquare[OF Aexp_edom])\nqed\n\ndefinition Theap :: \"heap \\<Rightarrow> exp \\<Rightarrow> Arity \\<rightarrow> var ttree\"\n  where \"Theap \\<Gamma> e = (\\<Lambda> a. if nonrec \\<Gamma> then ccTTree (edom (Aheap \\<Gamma> e\\<cdot>a)) (ccExp e\\<cdot>a) else ttree_restr (edom (Aheap \\<Gamma> e\\<cdot>a)) anything)\"\n\nlemma Theap_simp: \"Theap \\<Gamma> e\\<cdot>a = (if nonrec \\<Gamma> then ccTTree (edom (Aheap \\<Gamma> e\\<cdot>a)) (ccExp e\\<cdot>a) else ttree_restr (edom (Aheap \\<Gamma> e\\<cdot>a)) anything)\"\n  unfolding Theap_def by simp\n\nlemma carrier_Fheap':\"carrier (Theap \\<Gamma> e\\<cdot>a) = edom (Aheap \\<Gamma> e\\<cdot>a)\"\n    unfolding Theap_simp carrier_ccTTree by simp\n\nsublocale TTreeAnalysisCardinalityHeap Texp Aexp Aheap Theap\nproof\n  fix \\<Gamma> e a\n  show \"carrier (Theap \\<Gamma> e\\<cdot>a) = edom (Aheap \\<Gamma> e\\<cdot>a)\"\n    by (rule carrier_Fheap')\nnext\n  fix x \\<Gamma> p e a\n  assume \"x \\<in> thunks \\<Gamma>\"\n  \n  assume \"\\<not> one_call_in_path x p\"\n  hence \"x \\<in> set p\" by (rule more_than_one_setD)\n  \n  assume \"p \\<in> paths (Theap \\<Gamma> e\\<cdot>a)\" with \\<open>x \\<in> set p\\<close>\n  have \"x \\<in> carrier (Theap \\<Gamma> e\\<cdot>a)\" by (auto simp add: Union_paths_carrier[symmetric])\n  hence \"x \\<in> edom (Aheap \\<Gamma> e\\<cdot>a)\"\n    unfolding Theap_simp by (auto split: if_splits)\n  \n  show \"(Aheap \\<Gamma> e\\<cdot>a) x = up\\<cdot>0\"\n  proof(cases \"nonrec \\<Gamma>\")\n    case False\n    from False \\<open>x \\<in> thunks \\<Gamma>\\<close>  \\<open>x \\<in> edom (Aheap \\<Gamma> e\\<cdot>a)\\<close>\n    show ?thesis  by (rule aHeap_thunks_rec)\n  next\n    case True\n    with \\<open>p \\<in> paths (Theap \\<Gamma> e\\<cdot>a)\\<close>\n    have \"p \\<in> valid_lists (edom (Aheap \\<Gamma> e\\<cdot>a)) (ccExp e\\<cdot>a)\" by (simp add: Theap_simp)\n\n    with \\<open>\\<not> one_call_in_path x p\\<close>\n    have \"x--x\\<in> (ccExp e\\<cdot>a)\" by (rule valid_lists_many_calls)\n  \n    from True \\<open>x \\<in> thunks \\<Gamma>\\<close> this\n    show ?thesis by (rule aHeap_thunks_nonrec)\n  qed\nnext\n  fix \\<Delta> e a\n\n  have carrier: \"carrier (substitute (Texp.AnalBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>) (Texp e\\<cdot>a)) \\<subseteq> edom (Aheap \\<Delta> e\\<cdot>a) \\<union> edom (Aexp (Let \\<Delta> e)\\<cdot>a)\"\n  proof(rule carrier_substitute_below)\n    from edom_mono[OF Aexp_Let[of \\<Delta> e a]]\n    show \"carrier (Texp e\\<cdot>a) \\<subseteq> edom (Aheap \\<Delta> e\\<cdot>a) \\<union> edom (Aexp (Let \\<Delta> e)\\<cdot>a)\"  by (simp add: Texp_def)\n  next\n    fix x\n    assume \"x \\<in> edom (Aheap \\<Delta> e\\<cdot>a) \\<union> edom (Aexp (Let \\<Delta> e)\\<cdot>a)\"\n    hence \"x \\<in> edom (Aheap \\<Delta> e\\<cdot>a) \\<or> x : (edom (Aexp (Let \\<Delta> e)\\<cdot>a))\" by simp\n    thus \"carrier ((Texp.AnalBinds  \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) x) \\<subseteq> edom (Aheap \\<Delta> e\\<cdot>a) \\<union> edom (Aexp (Let \\<Delta> e)\\<cdot>a)\"\n    proof\n      assume \"x \\<in> edom (Aheap \\<Delta> e\\<cdot>a)\"\n      \n      have \"carrier ((Texp.AnalBinds  \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) x) \\<subseteq> edom (ABinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a))\"\n        by (rule carrier_AnalBinds_below)\n      also have \"\\<dots> \\<subseteq> edom (Aheap \\<Delta> e\\<cdot>a \\<squnion> Aexp (Terms.Let \\<Delta> e)\\<cdot>a)\"\n        using edom_mono[OF Aexp_Let[of \\<Delta> e a]] by simp\n      finally show ?thesis by simp\n    next\n      assume \"x \\<in> edom (Aexp (Terms.Let \\<Delta> e)\\<cdot>a)\"\n      hence \"x \\<notin> domA \\<Delta>\" by (auto  dest: subsetD[OF Aexp_edom])\n      hence \"(Texp.AnalBinds  \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) x = \\<bottom>\"\n        by (rule Texp.AnalBinds_not_there)\n      thus ?thesis by simp\n    qed\n  qed\n\n  show \"ttree_restr (- domA \\<Delta>) (substitute (Texp.AnalBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>) (Texp e\\<cdot>a)) \\<sqsubseteq> Texp (Let \\<Delta> e)\\<cdot>a\"\n  proof (rule below_trans[OF _ eq_imp_below[OF Texp_simp[symmetric]]], rule below_ccTTreeI)\n    have \"carrier (ttree_restr (- domA \\<Delta>) (substitute (Texp.AnalBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>) (Texp e\\<cdot>a)))\n       = carrier (substitute (Texp.AnalBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>) (Texp e\\<cdot>a)) - domA \\<Delta>\" by auto\n    also note carrier\n    also have \"edom (Aheap \\<Delta> e\\<cdot>a) \\<union> edom (Aexp (Terms.Let \\<Delta> e)\\<cdot>a) - domA \\<Delta> = edom (Aexp (Let \\<Delta> e)\\<cdot>a)\"\n      by (auto dest: subsetD[OF edom_Aheap] subsetD[OF Aexp_edom])\n    finally\n    show \"carrier (ttree_restr (- domA \\<Delta>) (substitute (Texp.AnalBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>)(Texp e\\<cdot>a)))\n          \\<subseteq> edom (Aexp (Terms.Let \\<Delta> e)\\<cdot>a)\" by this auto\n  next\n    let ?x = \"ccApprox (ttree_restr (- domA \\<Delta>) (substitute (Texp.AnalBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>) (Texp e\\<cdot>a)))\"\n  \n    have \"?x = cc_restr (- domA \\<Delta>) ?x\"  by simp\n    also have \"\\<dots> \\<sqsubseteq> cc_restr (- domA \\<Delta>) (ccHeap \\<Delta> e\\<cdot>a)\"\n    proof(rule cc_restr_mono2[OF wild_recursion_thunked])\n      have \"ccExp e\\<cdot>a \\<sqsubseteq> ccHeap \\<Delta> e\\<cdot>a\" by (rule ccHeap_Exp)\n      thus \"ccApprox (Texp e\\<cdot>a) \\<sqsubseteq> ccHeap \\<Delta> e\\<cdot>a\"\n        by (auto simp add: Texp_simp intro: below_trans[OF cc_restr_below_arg])\n    next\n      fix x\n      assume \"x \\<notin> domA \\<Delta>\"\n      thus \"(Texp.AnalBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) x = empty\"\n        by (metis Texp.AnalBinds_not_there empty_is_bottom)\n    next\n      fix x\n      assume \"x \\<in> domA \\<Delta>\"\n      then obtain e' where e': \"map_of \\<Delta> x = Some e'\" by (metis domA_map_of_Some_the)\n      \n      show \"ccApprox ((Texp.AnalBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) x) \\<sqsubseteq> ccHeap \\<Delta> e\\<cdot>a\"\n      proof(cases \"(Aheap \\<Delta> e\\<cdot>a) x\")\n        case bottom thus ?thesis using e' by (simp add: Texp.AnalBinds_lookup)\n      next\n        case (up a')\n        with e'\n        have \"ccExp e'\\<cdot>a' \\<sqsubseteq> ccHeap \\<Delta> e\\<cdot>a\" by (rule ccHeap_Heap)\n        thus ?thesis using up e'\n          by (auto simp add: Texp.AnalBinds_lookup Texp_simp  intro: below_trans[OF cc_restr_below_arg])\n      qed\n\n      show \"ccProd (ccNeighbors x (ccHeap \\<Delta> e\\<cdot>a)- {x} \\<inter> thunks \\<Delta>) (carrier ((Texp.AnalBinds  \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) x)) \\<sqsubseteq> ccHeap \\<Delta> e\\<cdot>a\"\n      proof(cases \"(Aheap \\<Delta> e\\<cdot>a) x\")\n        case bottom thus ?thesis using e' by (simp add: Texp.AnalBinds_lookup)\n      next\n        case (up a')\n        have subset: \"(carrier (fup\\<cdot>(Texp e')\\<cdot>((Aheap \\<Delta> e\\<cdot>a) x))) \\<subseteq> fv e'\"\n          using up e' by (auto simp add: Texp.AnalBinds_lookup carrier_Fexp dest!: subsetD[OF Aexp_edom])\n        \n        from e' up\n        have \"ccProd (fv e') (ccNeighbors x (ccHeap \\<Delta> e\\<cdot>a) - {x} \\<inter> thunks \\<Delta>) \\<sqsubseteq> ccHeap \\<Delta> e\\<cdot>a\"\n          by (rule ccHeap_Extra_Edges)\n        then\n        show ?thesis using e'\n          by (simp add: Texp.AnalBinds_lookup  Texp_simp ccProd_comm  below_trans[OF ccProd_mono2[OF subset]])\n      qed\n    qed\n    also have \"\\<dots> \\<sqsubseteq> ccExp (Let \\<Delta> e)\\<cdot>a\"\n      by (rule ccExp_Let)\n    finally\n    show \"ccApprox (ttree_restr (- domA \\<Delta>) (substitute (Texp.AnalBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>) (Texp e\\<cdot>a)))\n        \\<sqsubseteq> ccExp (Terms.Let \\<Delta> e)\\<cdot>a\" by this simp_all\n  qed\n\n  note carrier\n  hence \"carrier (substitute (ExpAnalysis.AnalBinds Texp \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>) (Texp e\\<cdot>a)) \\<subseteq> edom (Aheap \\<Delta> e\\<cdot>a) \\<union> - domA \\<Delta>\"\n    by (rule order_trans) (auto dest: subsetD[OF Aexp_edom])\n  hence \"ttree_restr (domA \\<Delta>)            (substitute (Texp.AnalBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>) (Texp e\\<cdot>a))\n      = ttree_restr (edom (Aheap \\<Delta> e\\<cdot>a)) (ttree_restr (domA \\<Delta>) (substitute (Texp.AnalBinds  \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>) (Texp e\\<cdot>a)))\"\n    by -(rule ttree_restr_noop[symmetric], auto)\n  also\n  have \"\\<dots> = ttree_restr (edom (Aheap \\<Delta> e\\<cdot>a)) (substitute (Texp.AnalBinds  \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>) (Texp e\\<cdot>a))\"\n    by (simp add: inf.absorb2[OF edom_Aheap ])\n  also\n  have \"\\<dots> \\<sqsubseteq> Theap \\<Delta> e \\<cdot>a\"\n  proof(cases \"nonrec \\<Delta>\")\n    case False\n    have \"ttree_restr (edom (Aheap \\<Delta> e\\<cdot>a)) (substitute (Texp.AnalBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>) (Texp e\\<cdot>a))\n      \\<sqsubseteq> ttree_restr (edom (Aheap \\<Delta> e\\<cdot>a)) anything\"\n      by (rule ttree_restr_mono) simp\n    also have \"\\<dots> = Theap \\<Delta> e\\<cdot>a\"\n      by (simp add: Theap_simp False)\n    finally show ?thesis.\n  next\n    case [simp]: True\n\n    from True\n    have \"ttree_restr (edom (Aheap \\<Delta> e\\<cdot>a)) (substitute (Texp.AnalBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>) (Texp e\\<cdot>a))\n       = ttree_restr (edom (Aheap \\<Delta> e\\<cdot>a)) (Texp e\\<cdot>a)\"\n      by (rule nonrecE) (rule ttree_rest_substitute, auto simp add: carrier_Fexp fv_def fresh_def dest!: subsetD[OF edom_Aheap] subsetD[OF Aexp_edom])\n    also have \"\\<dots> = ccTTree (edom (Aexp e\\<cdot>a) \\<inter> edom (Aheap \\<Delta> e\\<cdot>a)) (ccExp e\\<cdot>a)\"\n      by (simp add: Texp_simp)\n    also have \"\\<dots> \\<sqsubseteq> ccTTree (edom (Aexp e\\<cdot>a) \\<inter> domA \\<Delta>) (ccExp e\\<cdot>a)\"\n      by (rule ccTTree_mono1[OF Int_mono[OF order_refl edom_Aheap]])\n    also have \"\\<dots> \\<sqsubseteq> ccTTree (edom (Aheap \\<Delta> e\\<cdot>a)) (ccExp e\\<cdot>a)\"\n      by (rule ccTTree_mono1[OF edom_mono[OF Aheap_nonrec[OF True], simplified]])\n    also have \"\\<dots> \\<sqsubseteq> Theap \\<Delta> e\\<cdot>a\"\n      by (simp add: Theap_simp)\n    finally\n    show ?thesis by this simp_all\n  qed\n  finally\n  show \"ttree_restr (domA \\<Delta>) (substitute (ExpAnalysis.AnalBinds Texp \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>) (Texp e\\<cdot>a)) \\<sqsubseteq> Theap \\<Delta> e\\<cdot>a\".\n\nqed\nend\n\n(* TODO: Unused stuff from here, mostly about singles. Might be useful later. *)\n\n\nlemma paths_singles: \"xs \\<in> paths (singles S) \\<longleftrightarrow> (\\<forall>x \\<in> S. one_call_in_path x xs)\"\n  by transfer (auto simp add: one_call_in_path_filter_conv)\n\nlemma paths_singles': \"xs \\<in> paths (singles S) \\<longleftrightarrow> (\\<forall>x \\<in> (set xs \\<inter> S). one_call_in_path x xs)\"\n  apply transfer\n  apply (auto simp add: one_call_in_path_filter_conv)\n  apply (erule_tac x = x in ballE)\n  apply auto\n  by (metis (poly_guards_query) filter_empty_conv le0 length_0_conv)\n\nlemma both_below_singles1:\n  assumes \"t \\<sqsubseteq> singles S\"\n  assumes \"carrier t' \\<inter> S = {}\"\n  shows \"t \\<otimes>\\<otimes> t' \\<sqsubseteq> singles S\"\nproof (rule ttree_belowI)\n  fix xs\n  assume \"xs \\<in> paths (t \\<otimes>\\<otimes> t')\"\n  then obtain ys zs where \"ys \\<in> paths t\" and \"zs \\<in> paths t'\" and \"xs \\<in> ys \\<otimes> zs\" by (auto simp add: paths_both)\n  with assms \n  have \"ys \\<in> paths (singles S)\" and \"set zs \\<inter> S = {}\"\n    by (metis below_ttree.rep_eq contra_subsetD paths.rep_eq, auto simp add: Union_paths_carrier[symmetric])\n  with \\<open>xs \\<in> ys \\<otimes> zs\\<close>\n  show \"xs \\<in> paths (singles S)\"\n    by (induction) (auto simp add: paths_singles no_call_in_path_set_conv interleave_set dest: more_than_one_setD split: if_splits)\nqed\n\n\nlemma paths_ttree_restr_singles: \"xs \\<in> paths (ttree_restr S' (singles S)) \\<longleftrightarrow> set xs \\<subseteq> S' \\<and> (\\<forall>x \\<in> S. one_call_in_path x xs)\"\nproof\n  show \"xs \\<in> paths (ttree_restr S' (singles S)) \\<Longrightarrow>  set xs \\<subseteq> S' \\<and> (\\<forall>x \\<in> S. one_call_in_path x xs)\"\n    by (auto simp add: filter_paths_conv_free_restr[symmetric] paths_singles)\nnext\n  assume *: \"set xs \\<subseteq> S' \\<and> (\\<forall>x\\<in>S. one_call_in_path x xs)\"\n  hence \"set xs \\<subseteq> S'\" by auto\n  hence [simp]: \"filter (\\<lambda> x'. x' \\<in> S') xs = xs\" by (auto simp add: filter_id_conv)\n  \n  from *\n  have \"xs \\<in> paths (singles S)\"\n     by (auto simp add: paths_singles')\n  hence \"filter (\\<lambda> x'. x' \\<in> S') xs \\<in> filter (\\<lambda>x'. x' \\<in> S') ` paths (singles S)\"\n    by (rule imageI)\n  thus \"xs \\<in> paths (ttree_restr S' (singles S))\"\n    by (auto simp add: filter_paths_conv_free_restr[symmetric] )\nqed\n\n\n\n(* TODO: unused *)\nlemma substitute_not_carrier:\n  assumes \"x \\<notin> carrier t\"\n  assumes \"\\<And> x'. x \\<notin> carrier (f x')\"\n  shows \"x \\<notin>  carrier (substitute f T t)\"\nproof-\n  have \"ttree_restr ({x}) (substitute f T t) = ttree_restr ({x}) t\"\n  proof(rule ttree_rest_substitute)\n    fix x'\n    from \\<open>x \\<notin> carrier (f x')\\<close>\n    show \"carrier (f x') \\<inter> {x} = {}\" by auto\n  qed\n  hence \"x \\<notin> carrier (ttree_restr ({x}) (substitute f T t)) \\<longleftrightarrow> x \\<notin> carrier (ttree_restr ({x}) t)\" by metis\n  with assms(1)\n  show ?thesis by simp\nqed\n\n(* TODO: unused *)\nlemma substitute_below_singlesI:\n  assumes \"t \\<sqsubseteq> singles S\"\n  assumes \"\\<And> x. carrier (f x) \\<inter> S = {}\"\n  shows \"substitute f T t \\<sqsubseteq> singles S\"\nproof(rule ttree_belowI)\n  fix xs\n  assume \"xs \\<in> paths (substitute f T t)\"\n  thus \"xs \\<in> paths (singles S)\"\n  using assms\n  proof(induction f T t xs arbitrary: S rule: substitute_induct)\n    case Nil\n    thus ?case by simp\n  next\n    case (Cons f T t x xs)\n\n    from \\<open>x#xs \\<in> _\\<close>\n    have xs: \"xs \\<in> paths (substitute (f_nxt f T x) T (nxt t x \\<otimes>\\<otimes> f x))\" by auto\n    moreover\n\n    from \\<open>t \\<sqsubseteq> singles S\\<close>\n    have \"nxt t x \\<sqsubseteq> singles S\" \n      by (metis \"TTree-HOLCF.nxt_mono\" below_trans nxt_singles_below_singles)\n    from this \\<open>carrier (f x) \\<inter> S = {}\\<close>\n    have \"nxt t x \\<otimes>\\<otimes> f x \\<sqsubseteq> singles S\"\n      by (rule both_below_singles1)\n    moreover\n    { fix x'\n      from  \\<open>carrier (f x') \\<inter> S = {}\\<close>\n      have \"carrier (f_nxt f T x x') \\<inter> S = {}\"\n        by (auto simp add: f_nxt_def)\n    }\n    ultimately\n    have IH: \"xs \\<in> paths (singles S)\"\n      by (rule Cons.IH) \n  \n  show ?case\n    proof(cases \"x \\<in> S\")\n      case True\n      with \\<open>carrier (f x) \\<inter> S = {}\\<close>\n      have \"x \\<notin> carrier (f x)\" by auto\n      moreover\n      from \\<open>t \\<sqsubseteq> singles S\\<close>\n      have \"nxt t x \\<sqsubseteq> nxt (singles S) x\" by (rule nxt_mono)\n      hence \"carrier (nxt t x) \\<subseteq> carrier (nxt (singles S) x)\" by (rule carrier_mono)\n      from subsetD[OF this] True\n      have \"x \\<notin> carrier (nxt t x)\" by auto\n      ultimately\n      have \"x \\<notin> carrier (nxt t x \\<otimes>\\<otimes> f x)\" by simp\n      hence \"x \\<notin> carrier (substitute (f_nxt f T x) T (nxt t x \\<otimes>\\<otimes> f x))\"\n      proof(rule substitute_not_carrier)\n        fix x'  \n        from \\<open>carrier (f x') \\<inter> S = {}\\<close> \\<open>x \\<in> S\\<close>\n        show \"x \\<notin> carrier (f_nxt f T x x')\" by (auto simp add: f_nxt_def)\n      qed\n      with xs\n      have \"x \\<notin> set xs\" by (auto simp add: Union_paths_carrier[symmetric])\n      with IH\n      have \"xs \\<in> paths (without x (singles S))\" by (rule paths_withoutI)\n      thus ?thesis using True by (simp add: Cons_path)\n    next\n      case False\n      with IH\n      show ?thesis by (simp add: Cons_path)\n    qed\n  qed\nqed\n\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Call_Arity/CoCallImplTTreeSafe.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5698526660244838, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.29827248129282985}}
{"text": "section \\<open>Implementation of Relabel-to-Front\\<close>\ntheory Relabel_To_Front_Impl\nimports\n  Relabel_To_Front\n  Prpu_Common_Impl\nbegin\n  \n  \nsubsection \\<open>Basic Operations\\<close>  \n  \ncontext Network_Impl\nbegin\n  \nsubsubsection \\<open>Neighbor Lists\\<close>\ndefinition n_init :: \"(node \\<Rightarrow> node list) \\<Rightarrow> (node \\<Rightarrow> node list) nres\" \n  where \"n_init am \\<equiv> return (am( s := [], t := []) )\"\n  \ndefinition n_at_end :: \"(node \\<Rightarrow> node list) \\<Rightarrow> node \\<Rightarrow> bool nres\" \n  where \"n_at_end n u \\<equiv> do {\n    assert (u\\<in>V-{s,t});\n    return (n u = [])\n  }\"\n    \ndefinition n_get_hd :: \"(node \\<Rightarrow> node list) \\<Rightarrow> node \\<Rightarrow> node nres\"    \n  where \"n_get_hd n u \\<equiv> do {\n    assert (u\\<in>V-{s,t} \\<and> n u \\<noteq> []);\n    return (hd (n u))\n  }\"\n\ndefinition n_move_next \n  :: \"(node \\<Rightarrow> node list) \\<Rightarrow> node \\<Rightarrow> (node \\<Rightarrow> node list) nres\"\n  where \"n_move_next n u \\<equiv> do {\n    assert (u\\<in>V-{s,t} \\<and> n u \\<noteq> []);\n    return (n (u := tl (n u)))\n  }\"\n    \ndefinition n_reset \n  :: \"(node \\<Rightarrow> node list) \\<Rightarrow> (node \\<Rightarrow> node list) \\<Rightarrow> node \n    \\<Rightarrow> (node \\<Rightarrow> node list) nres\"\n  where \"n_reset am n u \\<equiv> do {\n    assert (u\\<in>V-{s,t});\n    return (n (u := am u))\n  }\"\n  \nlemma n_init_refine[refine2]: \n  assumes AM: \"is_adj_map am\"  \n  shows \"n_init am \n    \\<le> (spec c. (c, rtf_init_n) \\<in> (nat_rel \\<rightarrow> \\<langle>nat_rel\\<rangle>list_set_rel))\"\nproof -\n  have[simp]: \"am v = []\" if \"v\\<notin>V\" for v\n  proof -\n    from that have \"adjacent_nodes v = {}\" \n      unfolding adjacent_nodes_def using E_ss_VxV by auto\n    thus ?thesis using am_to_adj_nodes_refine[OF AM] \n      by (auto simp: list_set_rel_def in_br_conv)\n  qed\n  show ?thesis      \n    unfolding n_init_def rtf_init_n_def \n    by (auto \n        simp: pw_le_iff refine_pw_simps list_set_autoref_empty \n        simp: am_to_adj_nodes_refine[OF AM])\nqed  \n  \nsubsection \\<open>Refinement to Basic Operations\\<close>  \n  \nsubsubsection \\<open>Discharge\\<close>  \ndefinition \"discharge2 am x cf l n u \\<equiv> do {  \n  assert (u \\<in> V);\n  monadic_WHILEIT (\\<lambda>_. True) \n    (\\<lambda>((x,cf),l,n). do { xu \\<leftarrow> x_get x u; return (xu \\<noteq> 0) } ) \n    (\\<lambda>((x,cf),l,n). do {\n      at_end \\<leftarrow> n_at_end n u;\n      if at_end then do {\n        l \\<leftarrow> relabel2 am cf l u;\n        n \\<leftarrow> n_reset am n u;\n        return ((x,cf),l,n)\n      } else do {\n        v \\<leftarrow> n_get_hd n u;\n        cfuv \\<leftarrow> cf_get cf (u,v);\n        lu \\<leftarrow> l_get l u;\n        lv \\<leftarrow> l_get l v;\n        if (cfuv \\<noteq> 0 \\<and> lu = lv + 1) then do {\n          (x,cf) \\<leftarrow> push2 x cf (u,v);\n          return ((x,cf),l,n)\n        } else do {\n          n \\<leftarrow> n_move_next n u;\n          return ((x,cf),l,n)\n        }\n      }\n    }) ((x,cf),l,n)\n}\"\n\nlemma discharge_structure_refine_aux:\n  assumes SR: \"(ni,n)\\<in>nat_rel \\<rightarrow> \\<langle>nat_rel\\<rangle>list_set_rel\"\n  assumes SU: \"(ui,u)\\<in>Id\"  \n  assumes fNR: \"fNi \\<le> \\<Down>R fN\"\n  assumes UIV: \"u\\<in>V-{s,t}\"  \n  assumes fSR: \"\\<And>v vi vs. \\<lbrakk> \n      (vi,v)\\<in>Id; v\\<in>n u; ni u = v#vs; (v#vs,n u)\\<in>\\<langle>nat_rel\\<rangle>list_set_rel \n    \\<rbrakk> \\<Longrightarrow> fSi vi \\<le> \\<Down>R (fS v)\"\n  shows\n  \"( do {\n    at_end \\<leftarrow> n_at_end ni ui;\n    if at_end then fNi\n    else do {\n      v \\<leftarrow> n_get_hd ni ui;\n      fSi v\n    }\n  } ) \\<le> \\<Down>R (\n\n  do {\n    v \\<leftarrow> select v. v\\<in>n u;\n    case v of\n      None \\<Rightarrow> fN\n    | Some v \\<Rightarrow> fS v\n  })\" (is \"?lhs \\<le>\\<Down>R ?rhs\")\n  unfolding n_at_end_def n_get_hd_def\n  apply (simp only: nres_monad_laws)  \n  apply (cases \"ni u\")\n  subgoal\n    using fun_relD[OF SR SU] SU UIV fNR\n    by (auto simp: list_set_rel_def in_br_conv pw_le_iff refine_pw_simps)\n    \n  subgoal for v vs\n    using fun_relD[OF SR SU] SU UIV\n    using fSR[OF IdI[of v], of vs]  \n    apply (clarsimp \n        simp: list_set_rel_def in_br_conv pw_le_iff refine_pw_simps \n        split: option.splits)\n    by fastforce  \n  done    \n  \nlemma xf_rel_RELATES[refine_dref_RELATES]: \"RELATES xf_rel\" \n  by (auto simp: RELATES_def)\n  \nlemma discharge2_refine[refine]:     \n  assumes A: \"((x,cf),f) \\<in> xf_rel\"\n  assumes AM: \"(am,adjacent_nodes)\\<in>nat_rel\\<rightarrow>\\<langle>nat_rel\\<rangle>list_set_rel\"\n  assumes [simplified,simp]: \"(li,l)\\<in>Id\" \"(ui,u)\\<in>Id\"\n  assumes NR: \"(ni,n)\\<in>nat_rel \\<rightarrow> \\<langle>nat_rel\\<rangle>list_set_rel\"  \n  shows \"discharge2 am x cf li ni ui \n    \\<le> \\<Down>(xf_rel \\<times>\\<^sub>r Id \\<times>\\<^sub>r (nat_rel \\<rightarrow> \\<langle>nat_rel\\<rangle>list_set_rel)) (discharge f l n u)\"  \n  unfolding discharge2_def discharge_def\n  apply (rewrite in \"monadic_WHILEIT _ _ \\<hole> _\" vcg_intro_frame)  \n  apply refine_rcg  \n  apply (vc_solve simp: A NR)\n  subgoal by (simp add: xf_rel_def x_get_def)  \n  subgoal for f l n x cf ni   \n    apply (subst vcg_rem_frame)\n    unfolding n_reset_def cf_get_def l_get_def n_move_next_def  \n    apply (simp only: nres_monad_laws)  \n    apply (rule discharge_structure_refine_aux; (refine_vcg AM)?; (assumption)?)  \n    apply (vc_solve simp: fun_relD fun_relD[OF AM])  \n    subgoal for v vs unfolding xf_rel_def Graph.E_def by auto\n    subgoal for v vs by (auto simp: list_set_rel_def in_br_conv)  \n    done\n  done\n  \nsubsubsection \\<open> Initialization of Queue \\<close>\n    \nlemma V_is_adj_nodes: \"V = { v . adjacent_nodes v \\<noteq> {} }\"\n  unfolding V_def adjacent_nodes_def by auto\n    \ndefinition \"init_CQ am \\<equiv> do {\n  let cardV=0;\n  let Q=[];\n  nfoldli [0..<N] (\\<lambda>_. True) (\\<lambda>v (cardV,Q). do {\n    assert (v<N);\n    inV \\<leftarrow> am_is_in_V am v;\n    if inV then do {\n      let cardV = cardV + 1;\n      if v\\<noteq>s \\<and> v\\<noteq>t then\n        return (cardV,v#Q)\n      else \n        return (cardV,Q)\n    } else\n      return (cardV,Q)\n  }) (cardV,Q)\n}\"    \n\nlemma init_CQ_correct[THEN order_trans, refine_vcg]:\n  assumes AM: \"is_adj_map am\"  \n  shows \"init_CQ am \\<le> SPEC (\\<lambda>(C,Q). C = card V \\<and> distinct Q \\<and> set Q = V-{s,t})\"\n  unfolding init_CQ_def  \n  apply (refine_vcg \n      nfoldli_rule[where \n        I=\"\\<lambda>l1 _ (C,Q). \n             C = card (V\\<inter>set l1) \\<and> distinct Q \\<and> set Q = (V\\<inter>set l1)-{s,t} \"]\n      )  \n  apply (clarsimp_all simp: am_to_adj_nodes_refine[OF AM])\n  using V_ss by (auto simp: upt_eq_lel_conv Int_absorb2)\n    \nsubsubsection \\<open>Main Algorithm\\<close>    \n    \ndefinition \"relabel_to_front2 am \\<equiv> do {\n  (cardV, L_right) \\<leftarrow> init_CQ am;\n\n  xcf \\<leftarrow> pp_init_xcf2 am;\n  l \\<leftarrow> l_init cardV;\n  n \\<leftarrow> n_init am;\n\n  let L_left=[];\n\n  ((x,cf),l,n,L_left,L_right) \\<leftarrow> while\\<^sub>T \n    (\\<lambda>((x,cf),l,n,L_left,L_right). L_right \\<noteq> []) \n    (\\<lambda>((x,cf),l,n,L_left,L_right). do {\n      assert (L_right \\<noteq> []);\n      let u = hd L_right;\n      old_lu \\<leftarrow> l_get l u;\n  \n      ((x,cf),l,n) \\<leftarrow> discharge2 am x cf l n u;\n  \n      lu \\<leftarrow> l_get l u;\n      if (lu \\<noteq> old_lu) then do {\n        \\<comment> \\<open>Move \\<open>u\\<close> to front of \\<open>l\\<close>, and restart scanning \\<open>L\\<close>. The cost for\\<close>\n        \\<comment> \\<open>\\<open>rev_append\\<close> is amortized by going to next node in \\<open>L\\<close>\\<close>\n        let (L_left,L_right) = ([u],rev_append L_left (tl L_right));\n        return ((x,cf),l,n,L_left,L_right)\n      } else do {\n        \\<comment> \\<open>Goto next node in \\<open>L\\<close>\\<close>\n        let (L_left,L_right) = (u#L_left, tl L_right);\n        return ((x,cf),l,n,L_left,L_right)\n      }\n  \n    }) (xcf,l,n,L_left,L_right);\n\n  return cf\n}\"\n  \n    \nlemma relabel_to_front2_refine[refine]: \n  assumes AM: \"is_adj_map am\"  \n  shows \"relabel_to_front2 am \n    \\<le> \\<Down>(br (flow_of_cf) (RPreGraph c s t)) relabel_to_front\"\nproof -\n  define s_rel \n    :: \"( _ \\<times> (\n       capacity_impl flow \n    \\<times> (nat\\<Rightarrow>nat) \n    \\<times> (node\\<Rightarrow>node set) \n    \\<times> node list \n    \\<times> node list)) set\"\n    where \"s_rel \\<equiv> \n       xf_rel \n    \\<times>\\<^sub>r Id \n    \\<times>\\<^sub>r (nat_rel \\<rightarrow> \\<langle>nat_rel\\<rangle>list_set_rel) \n    \\<times>\\<^sub>r br rev (\\<lambda>_. True) \n    \\<times>\\<^sub>r Id\"\n  \n  have [refine_dref_RELATES]: \"RELATES s_rel\" unfolding RELATES_def ..\n      \n  {\n    fix f l n\n    assume \"neighbor_invar c s t f l n\"\n    then interpret neighbor_invar c s t f l n .  \n    have G1: \"flow_of_cf cf = f\" by (rule fo_rg_inv)\n    have G2: \"RPreGraph c s t cf\" by (rule is_RPreGraph)\n    note G1 G2    \n  } note AUX1=this   \n      \n  have AUXR: \"do {\n      (cardV, L_right) \\<leftarrow> init_CQ am;\n      xcf \\<leftarrow> pp_init_xcf2 am;\n      l \\<leftarrow> l_init cardV;\n      n \\<leftarrow> n_init am;\n      Fi L_right xcf l n\n    }\n    \\<le> \\<Down>R (do {\n      L_right \\<leftarrow> spec l. distinct l \\<and> set l = V - {s, t};\n      F L_right\n    })\n  \" \n  if \"\\<And>L_right xcf n. \n    \\<lbrakk> (xcf,pp_init_f)\\<in>xf_rel; (n,rtf_init_n) \\<in> nat_rel \\<rightarrow> \\<langle>nat_rel\\<rangle>list_set_rel \\<rbrakk>\n    \\<Longrightarrow> Fi L_right xcf pp_init_l n \\<le> \\<Down>R (F L_right)\"\n  for Fi F R\n    unfolding l_init_def\n    apply (rule refine2specI)\n    supply pp_init_xcf2_refine\n            [OF AM, unfolded conc_fun_RETURN, THEN order_trans, refine_vcg]  \n    supply n_init_refine[OF AM,THEN order_trans, refine_vcg]  \n    apply (refine_vcg AM V_ss)\n    apply clarsimp  \n    subgoal for L_right x cf n\n      using that[of \"(x,cf)\" n L_right]\n      unfolding pp_init_l_def  \n      by (clarsimp simp: pw_le_iff refine_pw_simps; meson)  \n    done  \n  show ?thesis\n    unfolding relabel_to_front2_def relabel_to_front_def Let_def l_get_def\n    apply (simp only: nres_monad_laws)  \n    apply (rule AUXR)  \n    apply (refine_rcg)\n    apply refine_dref_type\n    unfolding s_rel_def\n    apply (vc_solve \n        simp: in_br_conv rev_append_eq xf_rel_def AUX1 fun_relD \n        simp: am_to_adj_nodes_refine[OF AM])\n    done  \nqed  \n  \n  \nsubsection \\<open>Refinement to Efficient Data Structures\\<close>  \n  \ncontext includes Network_Impl_Sepref_Register \nbegin  \n  sepref_register n_init  \n  sepref_register n_at_end\n  sepref_register n_get_hd\n  sepref_register n_move_next\n  sepref_register n_reset\n  sepref_register discharge2\n  sepref_register \"init_CQ\"\n  sepref_register relabel_to_front2\nend  \n  \nsubsubsection \\<open>Neighbor Lists by Array of Lists\\<close>  \ndefinition \"n_assn \\<equiv> is_nf N ([]::nat list)\"    \n    \ndefinition (in -) \"n_init_impl s t am \\<equiv> do {\n  n \\<leftarrow> array_copy am;\n  n \\<leftarrow> Array.upd s [] n;\n  n \\<leftarrow> Array.upd t [] n;\n  return n\n}\"      \n    \nlemma [sepref_fr_rules]: \n  \"(n_init_impl s t,PR_CONST n_init) \\<in> am_assn\\<^sup>k \\<rightarrow>\\<^sub>a n_assn\" \n  apply sepref_to_hoare\n  unfolding am_assn_def n_assn_def n_init_impl_def n_init_def\n  by (sep_auto)  \n    \ndefinition (in -) \"n_at_end_impl n u \\<equiv> do {\n  nu \\<leftarrow> Array.nth n u;\n  return (is_Nil nu)\n}\"\n    \nlemma [sepref_fr_rules]: \n  \"(uncurry n_at_end_impl, uncurry (PR_CONST n_at_end)) \n  \\<in> n_assn\\<^sup>k *\\<^sub>a node_assn\\<^sup>k \\<rightarrow>\\<^sub>a bool_assn\"  \n  apply sepref_to_hoare unfolding n_at_end_impl_def n_at_end_def n_assn_def\n  by (sep_auto simp: refine_pw_simps split: list.split)\n  \ndefinition (in -) \"n_get_hd_impl n u \\<equiv> do {\n  nu \\<leftarrow> Array.nth n u;\n  return (hd nu)\n}\"      \nlemma [sepref_fr_rules]: \n  \"(uncurry n_get_hd_impl, uncurry (PR_CONST n_get_hd)) \n  \\<in> n_assn\\<^sup>k *\\<^sub>a node_assn\\<^sup>k \\<rightarrow>\\<^sub>a node_assn\"  \n  apply sepref_to_hoare unfolding n_get_hd_impl_def n_get_hd_def n_assn_def\n  by (sep_auto simp: refine_pw_simps)\n  \ndefinition (in -) \"n_move_next_impl n u \\<equiv> do {\n  nu \\<leftarrow> Array.nth n u;\n  n \\<leftarrow> Array.upd u (tl nu) n;\n  return n\n}\" \nlemma [sepref_fr_rules]: \n  \"(uncurry n_move_next_impl, uncurry (PR_CONST n_move_next)) \n  \\<in> n_assn\\<^sup>d *\\<^sub>a node_assn\\<^sup>k \\<rightarrow>\\<^sub>a n_assn\"  \n  apply sepref_to_hoare \n  unfolding n_move_next_impl_def n_move_next_def n_assn_def\n  by (sep_auto simp: refine_pw_simps)\n  \ndefinition (in -) \"n_reset_impl am n u \\<equiv> do {\n  nu \\<leftarrow> Array.nth am u;\n  n \\<leftarrow> Array.upd u nu n;\n  return n\n}\"\nlemma [sepref_fr_rules]: \n  \"(uncurry2 n_reset_impl, uncurry2 (PR_CONST n_reset)) \n  \\<in> am_assn\\<^sup>k *\\<^sub>a n_assn\\<^sup>d *\\<^sub>a node_assn\\<^sup>k \\<rightarrow>\\<^sub>a n_assn\"  \n  apply sepref_to_hoare \n  unfolding n_reset_impl_def n_reset_def n_assn_def am_assn_def\n  by (sep_auto simp: refine_pw_simps)\n  \nsubsubsection \\<open>Discharge\\<close>  \nsepref_thm discharge_impl is \"uncurry5 (PR_CONST discharge2)\" \n  :: \"am_assn\\<^sup>k *\\<^sub>a x_assn\\<^sup>d *\\<^sub>a cf_assn\\<^sup>d *\\<^sub>a l_assn\\<^sup>d *\\<^sub>a n_assn\\<^sup>d *\\<^sub>a node_assn\\<^sup>k \n    \\<rightarrow>\\<^sub>a (x_assn \\<times>\\<^sub>a cf_assn) \\<times>\\<^sub>a l_assn \\<times>\\<^sub>a n_assn\"  \n  unfolding discharge2_def PR_CONST_def\n  by sepref  \nconcrete_definition (in -) discharge_impl \n  uses Network_Impl.discharge_impl.refine_raw is \"(uncurry5 ?f,_)\\<in>_\"\nlemmas [sepref_fr_rules] = discharge_impl.refine[OF Network_Impl_axioms]    \n\nsubsubsection \\<open>Initialization of Queue\\<close>  \n  \nsepref_thm init_CQ_impl is \"(PR_CONST init_CQ)\" \n  :: \"am_assn\\<^sup>k \\<rightarrow>\\<^sub>a nat_assn \\<times>\\<^sub>a list_assn nat_assn\"\n  unfolding init_CQ_def PR_CONST_def\n  apply (rewrite HOL_list.fold_custom_empty)\n  by sepref\nconcrete_definition (in -) init_CQ_impl \n  uses Network_Impl.init_CQ_impl.refine_raw is \"(?f,_)\\<in>_\"\nlemmas [sepref_fr_rules] = init_CQ_impl.refine[OF Network_Impl_axioms]    \n  \nsubsubsection \\<open>Main Algorithm\\<close>  \nsepref_thm relabel_to_front_impl is \n  \"(PR_CONST relabel_to_front2)\" :: \"am_assn\\<^sup>k \\<rightarrow>\\<^sub>a cf_assn\"  \n  unfolding relabel_to_front2_def PR_CONST_def\n  supply [[goals_limit = 1]]  \n  apply (rewrite in \"Let [] _\" HOL_list.fold_custom_empty)\n  apply (rewrite in \"[_]\" HOL_list.fold_custom_empty)\n  by sepref  \nconcrete_definition (in -) relabel_to_front_impl \n  uses Network_Impl.relabel_to_front_impl.refine_raw is \"(?f,_)\\<in>_\"\nlemmas [sepref_fr_rules] = relabel_to_front_impl.refine[OF Network_Impl_axioms]\n  \nend \\<comment> \\<open>Network Implementation Locale\\<close> \n  \nexport_code relabel_to_front_impl checking SML_imp\n  \nsubsection \\<open>Combination with Network Checker and Correctness\\<close>  \ncontext Network_Impl begin\n  \n  theorem relabel_to_front_impl_correct[sep_heap_rules]: \n    assumes AM: \"is_adj_map am\"\n    shows \"\n      <am_assn am ami> \n        relabel_to_front_impl c s t N ami\n      <\\<lambda>cfi. \\<exists>\\<^sub>Acf. cf_assn cf cfi \n                * \\<up>(isMaxFlow (flow_of_cf cf) \\<and> RGraph_Impl c s t N cf)>\\<^sub>t\"\n  proof -\n    note relabel_to_front2_refine[OF AM]    \n    also note relabel_to_front_correct\n    finally have R1: \n      \"relabel_to_front2 am \n      \\<le> \\<Down> (br flow_of_cf (RPreGraph c s t)) (SPEC isMaxFlow)\" .  \n\n    have [simp]: \"nofail (\\<Down>R (RES X))\" for R X by (auto simp: refine_pw_simps)\n        \n    note R2 = relabel_to_front_impl.refine[\n      OF Network_Impl_axioms, to_hnr, unfolded autoref_tag_defs]\n    note R3 = hn_refine_ref[OF R1 R2, of ami]  \n    note R4 = R3[unfolded hn_ctxt_def pure_def, THEN hn_refineD, simplified]\n\n    note RGII = rgraph_and_network_impl_imp_rgraph_impl[OF \n      RPreGraph.maxflow_imp_rgraph\n      Network_Impl_axioms\n        ]  \n      \n    show ?thesis  \n      by (sep_auto heap: R4 simp: pw_le_iff refine_pw_simps in_br_conv RGII)\n  qed\nend    \n\ndefinition \"relabel_to_front_impl_tab_am c s t N am \\<equiv> do {\n  ami \\<leftarrow> Array.make N am;  \\<comment> \\<open>TODO/DUP: Called \\<open>init_ps\\<close> in Edmonds-Karp impl\\<close>\n  relabel_to_front_impl c s t N ami\n}\"  \n  \ntheorem relabel_to_front_impl_tab_am_correct[sep_heap_rules]: \n  assumes NW: \"Network c s t\"\n  assumes VN: \"Graph.V c \\<subseteq> {0..<N}\"\n  assumes ABS_PS: \"Graph.is_adj_map c am\"\n  shows \"\n    <emp> \n      relabel_to_front_impl_tab_am c s t N am\n    <\\<lambda>cfi. \\<exists>\\<^sub>Acf. \n        asmtx_assn N id_assn cf cfi \n      * \\<up>(Network.isMaxFlow c s t (Network.flow_of_cf c cf)\n        \\<and> RGraph_Impl c s t N cf\n        )>\\<^sub>t\"\nproof -\n  interpret Network c s t by fact\n  interpret Network_Impl c s t N using VN by unfold_locales    \n  \n  from ABS_PS have [simp]: \"am u = []\" if \"u\\<ge>N\" for u\n    unfolding is_adj_map_def\n    using E_ss_VxV VN that \n    apply (subgoal_tac \"u\\<notin>V\") \n    by (auto simp del: inV_less_N)\n  \n  show ?thesis\n    unfolding relabel_to_front_impl_tab_am_def \n    apply vcg\n    apply (rule \n        Hoare_Triple.cons_rule[OF _ _ relabel_to_front_impl_correct[OF ABS_PS]])\n    subgoal unfolding am_assn_def is_nf_def by sep_auto\n    subgoal unfolding cf_assn_def by sep_auto\n    done  \nqed        \n  \ndefinition \"relabel_to_front el s t \\<equiv> do {\n  case prepareNet el s t of\n    None \\<Rightarrow> return None\n  | Some (c,am,N) \\<Rightarrow> do {\n      cf \\<leftarrow> relabel_to_front_impl_tab_am c s t N am;\n      return (Some (c,am,N,cf))\n  }\n}\"\nexport_code relabel_to_front checking SML_imp\n\ntext \\<open>\n  Main correctness statement:\n  \\<^item> If \\<open>relabel_to_front\\<close> returns \\<open>None\\<close>, the edge list was invalid or described \n    an invalid network. \n  \\<^item> If it returns \\<open>Some (c,am,N,cfi)\\<close>, then the edge list is valid and describes\n    a valid network. Moreover, \\<open>cfi\\<close> is an integer square matrix of \n    dimension \\<open>N\\<close>, which describes a valid residual graph in the network, whose\n    corresponding flow is maximal. Finally, \\<open>am\\<close> is a valid adjacency map of the\n    graph, and the nodes of the graph are integers less than \\<open>N\\<close>.\n\\<close>  \ntheorem relabel_to_front_correct:\n  \"<emp>\n  relabel_to_front el s t\n  <\\<lambda>\n    None \\<Rightarrow> \\<up>(\\<not>ln_invar el \\<or> \\<not>Network (ln_\\<alpha> el) s t)\n  | Some (c,am,N,cfi) \\<Rightarrow> \n      \\<up>(c = ln_\\<alpha> el \\<and> ln_invar el) \n    * (\\<exists>\\<^sub>Acf. asmtx_assn N int_assn cf cfi\n          * \\<up>(RGraph_Impl c s t N cf \n            \\<and> Network.isMaxFlow c s t (Network.flow_of_cf c cf))) \n    * \\<up>(Graph.is_adj_map c am)\n  >\\<^sub>t\n  \"\n  unfolding relabel_to_front_def\n  using prepareNet_correct[of el s t]\n  by (sep_auto simp: ln_rel_def in_br_conv)\n  \n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Prpu_Maxflow/Relabel_To_Front_Impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5698526514141571, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.29827247364548753}}
{"text": "(*  Title:      HOL/Auth/n_mutualEx.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n \n\ntheory n_mutualEx imports n_mutualEx_lemma_invs_on_rules n_mutualEx_on_inis\nbegin\nlemma main:\nassumes a1: \"s \\<in> reachableSet {andList (allInitSpecs N)} (rules N)\"\nand a2: \"0 < N\"\nshows \"\\<forall> f. f \\<in> (invariants N) --> formEval f s\"\nproof (rule consistentLemma)\nshow \"consistent (invariants N) {andList (allInitSpecs N)} (rules N)\"\nproof (cut_tac a1, unfold consistent_def, rule conjI)\nshow \"\\<forall> f ini s. f \\<in> (invariants N) --> ini \\<in> {andList (allInitSpecs N)} --> formEval ini s --> formEval f s\"\nproof ((rule allI)+, (rule impI)+)\n  fix f ini s\n  assume b1: \"f \\<in> (invariants N)\" and b2: \"ini \\<in> {andList (allInitSpecs N)}\" and b3: \"formEval ini s\"\n  have b4: \"formEval (andList (allInitSpecs N)) s\"\n  apply (cut_tac b2 b3, simp) done\n  show \"formEval f s\"\n  apply (rule on_inis, cut_tac b1, assumption, cut_tac b2, assumption, cut_tac b3, assumption) done\nqed\nnext show \"\\<forall> f r s. f \\<in> invariants N --> r \\<in> rules N --> invHoldForRule s f r (invariants N)\"\nproof ((rule allI)+, (rule impI)+)\n  fix f r s\n  assume b1: \"f \\<in> invariants N\" and b2: \"r \\<in> rules N\"\n  show \"invHoldForRule s f r (invariants N)\"\n  apply (rule invs_on_rules, cut_tac b1, assumption, cut_tac b2, assumption) done\nqed\nqed\nnext show \"s \\<in> reachableSet {andList (allInitSpecs N)} (rules N)\"\n  apply (metis a1) done\nqed\nend\n", "meta": {"author": "lyj238Gmail", "repo": "gsteProof", "sha": "3070d08e1f31a93be6fde85ab6b65d489c05f99e", "save_path": "github-repos/isabelle/lyj238Gmail-gsteProof", "path": "github-repos/isabelle/lyj238Gmail-gsteProof/gsteProof-3070d08e1f31a93be6fde85ab6b65d489c05f99e/mutualEx/n_mutualEx.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5698526514141571, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.29827247364548753}}
{"text": "\\<^marker>\\<open>creator Bernhard Pöttinger\\<close>\n\nchapter \\<open>Footprints of Modifications to Flow Graphs\\<close>\ntheory Flow_Footprint\nimports Flow_Base Flow_Extensions\nbegin\n\nparagraph \\<open>Summary\\<close>\ntext \\<open>A theoretical result on the footprint of flow interfaces.\\<close>\ntext \\<open>@{cite \\<open>def. 7\\<close> krishna19b}\\<close>\n\nparagraph \\<open>Major Definitions\\<close>\ntext \\<open>\\<^item>  @{text flow_footprint}\n\\<^item> @{text the_flow_footprint}\\<close>\n\nparagraph \\<open>Major Theorems\\<close>\ntext \\<open>\\<^item> @{cite \\<open>lem. 4\\<close> krishna19b}\n\\<^item> flow footprints are unique\\<close>\n\nsection \\<open>Flow Footprints\\<close>\n\ndefinition flow_footprint where\n  \"flow_footprint \\<equiv> \\<lambda>h h' h1'.\n             (\\<exists>h1 h2. h = h1 + h2 \\<and> h' = h1'  + h2 \\<and> int_fg h1 = int_fg h1' \\<and>\n     (\\<forall>h1''. (\\<exists>h1 h2. h = h1 + h2 \\<and> h' = h1'' + h2 \\<and> int_fg h1 = int_fg h1'')\n              \\<longrightarrow> (dom_fg h1' \\<subseteq> dom_fg h1'')))\"\n\ndefinition \"the_flow_footprint \\<equiv> \\<lambda>h h'. (THE h1'. flow_footprint h h' h1')\"\n\ntext \\<open>\nThe proof structure of @{text in_footprint_iff_changed}@{cite \\<open>lem. 4\\<close> krishna19b} is:\n@{text in_footprint_iff_changed}\n- ==> @{text in_footprint_iff_changed1}\n- <== @{text in_footprint_iff_changed2}\n\\<close>\n\nlemma in_footprint_iff_changed1:\n  assumes \"int_fg h = int_fg h'\" \"h \\<noteq> bot\" \"h' \\<noteq> bot\" \"n \\<in> dom_fg h\" \"flow_footprint h h' h1'\"\n    \"fg {n} (edge_fg h) (flow_fg h) \\<noteq> fg {n} (edge_fg h') (flow_fg h')\"\n  shows \"n \\<in> dom_fg h1'\"\nproof -\n  have *: \"flow_fg h n \\<noteq> flow_fg h' n \\<or> edge_fg h n \\<noteq> edge_fg h' n\"\n  proof (rule ccontr, goal_cases)\n    case 1\n    then have *: \"flow_fg h n = flow_fg h' n\" \"edge_fg h n = edge_fg h' n\" by auto\n    have \"fg {n} (edge_fg h) (flow_fg h) = fg {n} (edge_fg h') (flow_fg h')\"\n      apply (rule fg_cong) using assms * by auto\n    then show ?case using assms by simp\n  qed\n\n  obtain h1 h2 where **: \"h = h1 + h2\" \"h' = h1' + h2\" \"int_fg h1 = int_fg h1'\"\n    \"\\<forall>h1''. (\\<exists>h1 h2. h = h1 + h2 \\<and> h' = h1'' + h2 \\<and> int_fg h1 = int_fg h1'')\n            \\<longrightarrow> (dom_fg h1' \\<subseteq> dom_fg h1'')\"\n    using assms unfolding flow_footprint_def by blast\n\n  have \"n \\<notin> dom_fg h2\"\n  proof\n    assume AA: \"n \\<in> dom_fg h2\"\n    consider (a) \"flow_fg h n \\<noteq> flow_fg h' n\" | (b) \"edge_fg h n \\<noteq> edge_fg h' n\"\n      using * by blast\n    then show False\n    proof cases\n      case a\n      moreover have \"flow_fg h n = flow_fg h' n\"\n        using ** AA assms flow_fg_plus_fg_on2[of h1 h2] flow_fg_plus_fg_on2[of h1' h2]\n        by simp\n      ultimately show ?thesis\n        by simp\n    next\n      case b\n      moreover have \"edge_fg h n = edge_fg h' n\"\n        using ** AA assms edge_fg_plus_fg_on2[of h1 h2] edge_fg_plus_fg_on2[of h1' h2]\n        by simp\n      ultimately show ?thesis\n        by simp\n    qed\n  qed\n  moreover have \"dom_fg h = dom_fg h1 \\<union> dom_fg h2\" \"dom_fg h1 \\<inter> dom_fg h2 = {}\"\n    using assms ** by auto\n  ultimately have \"n \\<in> dom_fg h1\"\n    using assms by simp\n  then show ?thesis\n    using assms **\n    by (metis dom_fi_int_fg)\nqed\n\nlemma in_footprint_iff_changed2:\n  assumes \"int_fg h = int_fg h'\" \"h \\<noteq> bot\" \"h' \\<noteq> bot\" \"n \\<in> dom_fg h\" \"flow_footprint h h' h1'\"\n    \"n \\<in> dom_fg h1'\"\n  shows \"fg {n} (edge_fg h) (flow_fg h) \\<noteq> fg {n} (edge_fg h') (flow_fg h')\"\nproof\n  (* proof by contradiction: we construct a \"smaller\" h1' which can not exist due to minimality\n     of h1'. The false assumption fg {n} ... = fg {n} ... implies that we can move n\n     from h1' to h2. *)\n\n  let ?h = \"fg {n} (edge_fg h) (flow_fg h)\"\n  let ?h' = \"fg {n} (edge_fg h') (flow_fg h')\"\n\n  (* first show that ?h is valid in order to access its components*)\n  obtain g1 g2 where J: \"h = g1 + g2 \\<and> dom_fg g1 = {n} \\<and> dom_fg g2 = dom_fg h - {n} \\<and>\n    edge_fg h = edge_fg g1 on {n} \\<and> edge_fg h = edge_fg g2 on dom_fg h - {n} \\<and>\n    flow_fg h = flow_fg g1 on {n} \\<and> flow_fg h = flow_fg g2 on dom_fg h - {n}\"\n    \"g1 \\<noteq> bot\" \"g2 \\<noteq> bot\"\n    using split_fg[of h \"{n}\" \"dom_fg h - {n}\"] assms by blast\n\n  have \"g1 = fg (dom_fg g1) (edge_fg g1) (flow_fg g1)\" by (simp add: J(2))\n  have \"?h = fg (dom_fg g1) (edge_fg g1) (flow_fg g1)\"\n    apply (rule fg_cong) using J \\<open>g1 \\<noteq> bot\\<close> by auto\n  then have \"?h \\<noteq> bot\" using \\<open>g1 \\<noteq> bot\\<close> by simp\n  (* then we can show that the assumption that we obtain from our proof by contradiction\n     implies equality of edge and flow on n *)\n  moreover assume AA: \"?h = ?h'\"\n  ultimately have EE: \"edge_fg h n = edge_fg h' n\" \"flow_fg h n = flow_fg h' n\"\n    using fg_eqD[of ?h ?h']\n     apply (metis edge_fg_fg singletonI)\n    using fg_eqD[of ?h ?h'] \n    by (metis AA \\<open>fg {n} (edge_fg h) (flow_fg h) \\<noteq> bot\\<close> flow_fg_fg singletonI)\n\n  (* unfold the flow footprint assumption *)\n  obtain h1 h2 where **: \"h = h1 + h2\" \"h' = h1' + h2\" \"int_fg h1 = int_fg h1'\"\n    \"\\<forall>h1''. (\\<exists>h1 h2. h = h1 + h2 \\<and> h' = h1'' + h2 \\<and> int_fg h1 = int_fg h1'')\n            \\<longrightarrow> (dom_fg h1' \\<subseteq> dom_fg h1'')\"\n    using assms unfolding flow_footprint_def by blast\n\n  (* some observations *)\n  have X: \"dom_fg h1 = dom_fg h1'\"\n    using ** dom_fi_int_fg[of h1] dom_fi_int_fg[of h1']\n    by simp\n\n  have \"dom_fg h = (dom_fg h1 - {n}) \\<union> (dom_fg h2 \\<union> {n})\"\n    \"(dom_fg h1 - {n}) \\<inter> (dom_fg h2 \\<union> {n}) = {}\"\n    using ** plus_fg_dom_un assms plus_fg_dom_disj by blast+\n\n  (* fact 1: split h into hh1 and hh2 such that n is now part of hh2 instead of hh1 *)\n  then obtain hh1 hh2 where C: \"h = hh1 + hh2\" \"dom_fg hh1 = dom_fg h1 - {n}\"\n      \"dom_fg hh2 = dom_fg h2 \\<union> {n}\"\n      \"edge_fg h = edge_fg hh2 on dom_fg h2 \\<union> {n}\" \"flow_fg h = flow_fg hh2 on dom_fg h2 \\<union> {n}\"\n      \"edge_fg h = edge_fg hh1 on dom_fg h1 - {n}\" \"flow_fg h = flow_fg hh1 on dom_fg h1 - {n}\"\n    using split_fg[of h \"dom_fg h1 - {n}\" \"dom_fg h2 \\<union> {n}\"] assms\n    by auto\n\n  have \"dom_fg h' = (dom_fg h1 - {n}) \\<union> (dom_fg h2 \\<union> {n})\"\n    \"(dom_fg h1 - {n}) \\<inter> (dom_fg h2 \\<union> {n}) = {}\"\n    using X ** plus_fg_dom_un assms plus_fg_dom_disj by blast+\n\n  (* fact 2: split h' into hh1' and hh2' such that n is now part of hh2 instead of hh1' *)\n  then obtain hh1' hh2' where D: \"h' = hh1' + hh2'\" \"dom_fg hh1' = dom_fg h1 - {n}\"\n      \"dom_fg hh2' = dom_fg h2 \\<union> {n}\"\n      \"edge_fg h' = edge_fg hh2' on dom_fg h2 \\<union> {n}\" \"flow_fg h' = flow_fg hh2' on dom_fg h2 \\<union> {n}\"\n      \"edge_fg h' = edge_fg hh1' on dom_fg h1 - {n}\" \"flow_fg h' = flow_fg hh1' on dom_fg h1 - {n}\"\n    using split_fg[of h' \"dom_fg h1 - {n}\" \"dom_fg h2 \\<union> {n}\"] assms\n    by auto\n\n  have E0: \"edge_fg h' = edge_fg h2 on (dom_fg h2)\" \"edge_fg h = edge_fg h2 on (dom_fg h2)\"\n    \"flow_fg h' = flow_fg h2 on (dom_fg h2)\" \"flow_fg h = flow_fg h2 on (dom_fg h2)\"\n    using ** assms edge_fg_plus_fg_on2 flow_fg_plus_fg_on2 by blast+\n\n  (* notice that h = h1 + h2 and h' = h1' + h2 imply hh2 = hh2' *)\n  have E1: \"hh2 = hh2'\"\n    apply (rule fg_eqI)\n    using C D EE apply auto[1]\n    using D(1) assms(3) plus_fg_ops_exist apply blast\n    using C D EE E0 by auto\n  then have E2: \"int_fg hh2 = int_fg hh2'\"\n    by simp\n\n  have \"int_fg hh1 + int_fg hh2 = int_fg h\"\n    by (simp add: C(1) int_fg_fi_hom)\n  also have \"... = int_fg h'\"\n    using assms by simp\n  also have \"... = int_fg hh1' + int_fg hh2'\"\n    by (simp add: D(1) int_fg_fi_hom)\n  (* fact 3: interface have to be equal *)\n  finally have E2: \"int_fg hh1 = int_fg hh1'\"\n    using E2 plus_fi_cancel_left[of \"int_fg hh1\" \"int_fg hh2\"] int_fg_fi_hom[of hh1 hh2] assms C\n    by simp\n\n  (* we collected all facts 1-3 that are required to contradict minimality of h1' *)\n  have \"h = hh1 + hh2\" \"h' = hh1' + hh2\" \"int_fg hh1 = int_fg hh1'\" \"dom_fg hh1' \\<subset> dom_fg h1'\"\n    using E1 E2 C D ** X assms by auto\n  then show False\n    using ** by blast\nqed\n\ntext \\<open>@{cite \\<open>lem. 4\\<close> krishna19b}\\<close>\n\nlemma in_footprint_iff_changed:\n  assumes \"int_fg h = int_fg h'\" \"h \\<noteq> bot\" \"h' \\<noteq> bot\"\n    \"n \\<in> dom_fg h\" \"flow_footprint h h' h1'\"\n  shows \"n \\<in> dom_fg h1' \\<longleftrightarrow>\n    fg {n} (edge_fg h) (flow_fg h) \\<noteq> fg {n} (edge_fg h') (flow_fg h')\"\n  using assms in_footprint_iff_changed1 in_footprint_iff_changed2 by metis\n\ntext \\<open>Additionally show that flow footprints are unique:\\<close>\n\nlemma flow_footprint_unique:\n  assumes \"flow_footprint h h' h1'\" \"flow_footprint h h' h1''\" \"h \\<noteq> bot\" \"h' \\<noteq> bot\"\n  shows \"h1' = h1''\"\nproof -\n  obtain h11 h12 where *: \"h = h11 + h12\" \"h' = h1' + h12\" \"int_fg h11 = int_fg h1'\"\n    using assms unfolding flow_footprint_def by blast\n\n  obtain h21 h22 where **: \"h = h21 + h22\" \"h' = h1'' + h22\" \"int_fg h21 = int_fg h1''\"\n    using assms unfolding flow_footprint_def by blast\n\n  have nbot2: \"h12 \\<noteq> bot\" \"h22 \\<noteq> bot\" using * ** plus_fg_ops_exist assms by auto\n\n  let ?h12 = \"fg (dom_fg h12) (edge_fg h12) (flow_fg h12)\"\n  let ?h22 = \"fg (dom_fg h22) (edge_fg h22) (flow_fg h22)\"\n\n  have \"int_fg (h11 + h12) = int_fg h11 + int_fg h12\" using int_fg_fi_hom by metis\n  also have \"... = int_fg h1' + int_fg h12\" using * by simp\n  also have \"... = int_fg (h1' + h12)\" using int_fg_fi_hom by metis\n  finally have inbot: \"int_fg (h1' + h12) \\<noteq> bot\" \"int_fg h = int_fg h'\" using assms * by auto\n\n  let ?X = \"{n . n \\<in> dom_fg h \\<and> fg {n} (edge_fg h) (flow_fg h) \\<noteq> fg {n} (edge_fg h') (flow_fg h')}\"\n\n  have BLA: \"\\<And>x. x \\<in> dom_fg h1' \\<Longrightarrow> x \\<in> dom_fg h\"\n    using assms * plus_fg_dom_un[of h1' h12]\n    by (metis Diff_insert_absorb dom_fg_plus_fg_subs1 dom_fi_int_fg subset_Diff_insert)\n\n  have dom1: \"dom_fg h1' = ?X\"\n    using BLA apply auto\n    using in_footprint_iff_changed2[OF inbot(2)] assms inbot BLA apply blast\n    using * inbot in_footprint_iff_changed1[OF inbot(2) \\<open>h \\<noteq> bot\\<close> \\<open>h' \\<noteq> bot\\<close>] assms by blast\n\n  have BLA: \"\\<And>x. x \\<in> dom_fg h1'' \\<Longrightarrow> x \\<in> dom_fg h\"\n    using assms * ** plus_fg_dom_un[of h1'' h22]\n    by (metis Diff_insert_absorb dom_fg_plus_fg_subs1 dom_fi_int_fg subset_Diff_insert)\n\n  have dom2: \"dom_fg h1'' = ?X\"\n    using BLA apply auto\n    using in_footprint_iff_changed2[OF inbot(2)] assms inbot BLA apply blast\n    using * inbot in_footprint_iff_changed1[OF inbot(2) \\<open>h \\<noteq> bot\\<close> \\<open>h' \\<noteq> bot\\<close>] assms by blast\n\n  have dom: \"dom_fg h1' = dom_fg h1''\" using dom1 dom2 by simp\n  then have \"dom_fg h12 = dom_fg h' - dom_fg h1'\" using assms plus_fg_dom_un[of h1' h12]\n      plus_fg_dom_disj[of h1' h12] assms * by blast\n  moreover have \"dom_fg h22 = dom_fg h' - dom_fg h1''\" using assms plus_fg_dom_un[of h1'' h22]\n      plus_fg_dom_disj[of h1'' h22] assms ** \\<open>dom_fg h1' = dom_fg h1''\\<close> ** by blast\n  ultimately have dom: \"dom_fg h12 = dom_fg h22\" using dom by simp\n\n  have X1: \"edge_fg h = edge_fg h12 on dom_fg h12\" using edge_fg_plus_fg_on2 * assms by auto\n  have X2: \"edge_fg h = edge_fg h22 on dom_fg h22\" using edge_fg_plus_fg_on2 ** assms by auto\n  have X3: \"flow_fg h = flow_fg h12 on dom_fg h12\" using flow_fg_plus_fg_on2 * assms by auto\n  have X4: \"flow_fg h = flow_fg h22 on dom_fg h22\" using flow_fg_plus_fg_on2 ** assms by auto\n\n  have \"?h12 = ?h22\"\n    apply (rule fg_cong)\n    using dom X1 X2 X3 X4 by auto\n  then have \"h12 = h22\"\n    using nbot2 by auto\n  then have \"h1' + h12 = h1'' + h12\" using * ** by simp\n  then show \"h1' = h1''\" using plus_fg_cancel_right assms * by blast\nqed\n\nend\n", "meta": {"author": "bpoettinger", "repo": "Flow", "sha": "c95ea5f88a0a3d39e44421e0cc36139a3c3687de", "save_path": "github-repos/isabelle/bpoettinger-Flow", "path": "github-repos/isabelle/bpoettinger-Flow/Flow-c95ea5f88a0a3d39e44421e0cc36139a3c3687de/Flow_Footprint.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.523420348936324, "lm_q2_score": 0.5698526514141571, "lm_q1q2_score": 0.29827247364548753}}
{"text": "(*\n *\n * Copyright 2017, Data61, CSIRO\n *\n * This software may be distributed and modified according to the terms of\n * the GNU General Public License version 2. Note that NO WARRANTY is provided.\n * See \"LICENSE_GPLv2.txt\" for details.\n *\n * @TAG(DATA61_GPL)\n *)\n\n(*\n   Test proofs for corres methods. Builds on AInvs image.\n*)\n\ntheory Corres_Test\nimports \"../proof/refine/ARM/VSpace_R\" Corres_Method\nbegin\n\nchapter \\<open>The Corres Method\\<close>\n\nsection \\<open>Introduction\\<close>\n\ntext \\<open>The @{method corres} method tries to do for corres-style refinement proofs what\n@{method wp} did for hoare logic proofs. The intention is to automate the application\nof corres calculational rules, so that the bulk of the manual proof is now handling\na verification condition. In general refinement proofs are difficult to automate, so here we\nexploit the fact that in l4v the abstract and executable specifications tend to be structurally\nsimilar. Corres proofs are based on the @{const corres_underlying} constant, which takes a number\nof parameters that allow it to be specialized for different flavours of refinement.\n\nA corres statement has the following form: @{term \"corres_underlying sr nf nf' r P P' f f'\"}, where\n@{term sr} is a state-relation, @{term nf} and @{term nf'} refer to whether or not the left and\nright hand functions may fail, @{term r} is a return value relation between the functions, @{term P}\nand @{term P'} are preconditions for the functions @{term f} and @{term f'} respectively. Informally\nthe statement says that: under the given preconditions, for every execution of @{term f'} there exists\nan execution of @{term f} that is related by the given state relation @{term sr} and return-value\nrelation @{term r}.\n\nIf the left and right side of a corres statement share similar structure, we can \"unzip\" the function\ninto one corres obligation for each atomic function. This is done through the application of\n  @{thm corres_split}.\n\\<close>\n\nthm corres_split[no_vars]\n\ntext \\<open>Briefly this states that: given a corres goal proving refinement between @{term \"a >>= b\"} and\n  @{term \"c >>= d\"}, we can decompose this into a proof showing refinement between @{term a} and\n@{term c}, and between @{term a} and @{term c}. Additionally @{term a} and @{term c} must establish\nappropriate postconditions to satisfy the obligations of proving refinement between @{term b} and @{term d}.\n\nThe first subgoal that is produced has an important characteristic: the preconditions for each\nside may only discuss the return value of its respective side. This means that rules such as\n@{term \"corres_underlying sr nf nf' r (\\<lambda>s. x = x') (\\<lambda>_. True) (f x) (f' x')\"} will not apply to a goal\n if @{term x} and @{term x'} are variables generated by applying @{thm corres_split} (i.e. the\nreturn values of functions).\n\nThis means that any such conditions must instead be phrased as an assumption to the rule, and our rule must be\nrephrased as follows:\n  @{term \"x = x' \\<Longrightarrow> corres_underlying sr nf nf' r (\\<lambda>_. True) (\\<lambda>_. True) (f x) (f' x')\"}.\nThe result is that we must solve @{term \"x = x'\"} immediately after applying our rule. While this\nis not a major concern for a manual proof, it proves to be a significant obstacle if we're trying\nto focus on automating the \"corres\" part of the refinement.\n\\<close>\n\nsection \\<open>corres_underlyingK and corres_rv\\<close>\n\ntext \\<open>To remedy this situation, we augment the @{const corres_underlying} definition to include\nyet another flag: a single boolean. This new constant: @{const corres_underlyingK},\nwill form the basis of the calculus for our corres method.\\<close>\n\nthm corres_underlyingK_def[no_vars]\n\ntext \\<open>The boolean in @{const corres_underlyingK} can be thought of as a stateless precondition. It\nis used to propagate additional proof obligations for rules that either do not need to discuss\neither the left or right hand state, or must discuss bound variables from both sides.\\<close>\n\nthm corresK_split[no_vars]\n\ntext \\<open>In this split rule for @{const corres_underlyingK} we see that the additional precondition @{term F'}\nmay discuss both @{term rv} and @{term rv'}. To show that this condition is satisified, however,\nwe can't use hoare logic and instead need a new definition: @{const corres_rv}.\\<close>\n\nthm corres_rv_def_I_know_what_I'm_doing[no_vars]\n\ntext \\<open>This is a weaker form of @{const corres_underlying} that is only interested in the return value\nof the functions. In essence, it states the given functions will establish @{term Q} after executing,\nassuming the given return-value relation @{term r} holds, along with the given stateless precondition\n@{term F} and left/right preconditions @{term P} and @{term P'}.\n\nThe assumption in general is that corres_rv rules should never be written, instead corres_rv obligations\nshould be propagated into either the stateless precondition (@{term F} from @{term corres_underlyingK}),\nthe left precondition (@{term P}) or the right precondition @{term P'}. This is implicitly handled\nby @{method corres_rv} (called from @{method corres}) by applying one of the following rules to each conjunct:\\<close>\n\nthm corres_rv_defer\nthm corres_rv_wp_left\nthm corres_rv_wp_right\n\ntext \\<open>If none of these rules can be safely applied, then @{method corres_rv} will leave the\n  obligation untouched. The user can manually apply one of them if desired, but this is liable to\n  create unsolvable proof obligations. In the worst case, the user may manually solve the goal in-place.\\<close>\n\nthm corres_rv_proveT[no_vars]\n\nsection \\<open>The corres method\\<close>\n\ntext \\<open>The core algorithm of the corres method is simple:\n  1) start by applying any necessary weakening rules to ensure the goal has schematic preconditions\n  2) apply a known @{thm corres} or @{thm corresK} rule (see next section)\n  3) if unsuccessful, apply a split rule (i.e. @{thm corresK_split}) and go to 2\n\nImportantly, @{method corres} will not split a goal if it ultimately is not able to apply at least\none @{thm corres} or @{thm corresK} rule.\n\\<close>\n\nsubsection \\<open>The corres and corresK named_theorems\\<close>\n\ntext \\<open>To address the fact that existing refinement rules are phrased as @{const corres_underlying}\nand not @{const corres_underlyingK} there are two different named_theorems that are used for different\nkind of rules @{thm corres} and @{thm corresK}. A @{thm corres} rule is understood to be phrased\nwith @{const corres_underlying} and may have additional assumptions. These assumptions will be\npropagated through the additional @{term F} flag in @{const corres_underlyingK}, rather than presented\nas proof obligations immediately. A @{thm corresK} rule is understood to be phrased with\n@{const corres_underlyingK}, and is meant for calculational rules which may have proper assumptions that\nshould not be propagated.\n\\<close>\nthm corresK\nthm corres\n\nsubsection \\<open>The corresc method\\<close>\n\ntext \\<open>Similar to @{method wpc}, @{method corresc} can handle case statements in @{const corres_underlyingK}\nproof goals. Importantly, however, it is split into two sub-methods @{method corresc_left} and\n@{method corresc_right}, which perform case-splitting on each side respectively. The combined method\n@{method corresc}, however, attempts to discharge the contradictions that arise from the quadratic\nblowup of a case analysis on both the left and right sides.\\<close>\n\nsubsection \\<open>corres_concrete_r, corres_concrete_rE\\<close>\n\ntext \\<open>Some @{thm corresK} rules should only be applied if certain variables are concrete\n(i.e. not schematic) in the goal. These are classified separately with the named_theorems\n@{thm corres_concrete_r} and @{thm corres_concrete_rER}. The first\nindicates that the return value relation of the goal must be concrete, the second indicates that\nonly the left side of the error relation must be concrete.\\<close>\n\nthm corres_concrete_r\nthm corres_concrete_rER\n\nsubsection \\<open>The corres_search method\\<close>\n\ntext \\<open>The purpose of @{method corres_search} is to address cases where there is non-trivial control flow.\nIn particular: in the case where there is an \"if\" statement or either side needs to be symbolically\nexecuted. The core idea is that corres_search should be provided with a \"search\" rule that acts\nas an anchoring point. Symbolic execution and control flow is decomposed until either the given\nrule is successfully applied or all search branches are exhausted.\\<close>\n\nsubsubsection \\<open>Symbolic Execution\\<close>\n\ntext \\<open>Symbolic execution is handled by two named theorems:\n @{thm corres_symb_exec_ls} and @{thm corres_symb_exec_rs}, which perform symbolic execution on\nthe left and right hand sides of a corres goal.\\<close>\n\nthm corres_symb_exec_ls\nthm corres_symb_exec_rs\n\ntext \\<open>A function may be symbolically executed if it does not modify the state, i.e. its only purpose\nis to compute some value and return it. After being symbolically executed,\nthis value can only be discussed by the precondition of the associated side or the stateless\nprecondition of corresK. The resulting @{const corres_rv} goal has @{const corres_noop} as the\nfunction on the alternate side. This gives @{method corres_rv} a hint that the resulting obligation\nshould be aggressively re-written into a hoare triple over @{term m} if it can't be propagated\nback statelessly safely.\n\\<close>\n\n\nsection \\<open>Demo\\<close>\n\n\ncontext begin interpretation Arch .\n\n(* VSpace_R *)\n\n\nlemmas load_hw_asid_corres_args[corres] =\n  load_hw_asid_corres[@lift_corres_args]\n\nlemmas invalidate_asid_corres_args[corres] =\n  invalidate_asid_corres[@lift_corres_args]\n\nlemmas invalidate_hw_asid_entry_corres_args[corres] =\n  invalidate_hw_asid_entry_corres[@lift_corres_args]\n\nlemma invalidate_asid_entry_corres:\n  \"corres dc (valid_arch_objs and valid_asid_map\n                and K (asid \\<le> mask asid_bits \\<and> asid \\<noteq> 0)\n                and vspace_at_asid asid pd and valid_vs_lookup\n                and unique_table_refs o caps_of_state\n                and valid_global_objs and valid_arch_state\n                and pspace_aligned and pspace_distinct)\n             (pspace_aligned' and pspace_distinct' and no_0_obj')\n             (invalidate_asid_entry asid) (invalidateASIDEntry asid)\"\n  apply (simp add: invalidate_asid_entry_def invalidateASIDEntry_def)\n  apply_debug (trace) (* apply_trace between steps *)\n   (tags \"corres\") (* break at breakpoints labelled \"corres\" *)\n   corres (* weaken precondition *)\n   continue (* split *)\n   continue (* solve load_hw_asid *)\n   continue (* split *)\n   continue (* apply corres_when *)\n   continue (* trivial simplification *)\n   continue (* invalidate _hw_asid_entry *)\n   finish (* invalidate_asid *)\n\n  apply (corressimp wp: load_hw_asid_wp)+\n  apply clarsimp\n  apply (fastforce simp: pd_at_asid_uniq)\n  done\n\n\ncrunch typ_at'[wp]: invalidateASIDEntry, flushSpace \"typ_at' T t\"\ncrunch pspace_aligned'[wp]: invalidateASIDEntry \"pspace_aligned'\"\ncrunch pspace_distinct'[wp]: invalidateASIDEntry \"pspace_distinct'\"\ncrunch ksCurThread[wp]: invalidateASIDEntry, flushSpace \"\\<lambda>s. P (ksCurThread s)\"\ncrunch obj_at'[wp]: invalidateASIDEntry, flushSpace \"obj_at' P p\"\n\nlemmas flush_space_corres_args[corres] =\n  flush_space_corres[@lift_corres_args]\n\nlemmas invalidate_asid_entry_corres_args[corres] =\n  invalidate_asid_entry_corres[@lift_corres_args]\n\n\nlemma corres_inst_eq_ext:\n  \"(\\<And>x. corres_inst_eq (f x) (f' x)) \\<Longrightarrow> corres_inst_eq f f'\"\n  by (auto simp add: corres_inst_eq_def)\n\nlemma delete_asid_corresb:\n  notes [corres] = corres_gets_asid gct_corres set_asid_pool_corres and\n    [@lift_corres_args, corres] =  get_asid_pool_corres_inv'\n    invalidate_asid_entry_corres\n    set_vm_root_corres\n  notes [wp] = set_asid_pool_asid_map_unmap set_asid_pool_vs_lookup_unmap'\n    set_asid_pool_arch_objs_unmap'\n    invalidate_asid_entry_invalidates\n    getASID_wp\n  shows\n    \"corres dc\n          (invs and valid_etcbs and K (asid \\<le> mask asid_bits \\<and> asid \\<noteq> 0))\n          (pspace_aligned' and pspace_distinct' and no_0_obj'\n              and valid_arch_state' and cur_tcb')\n          (delete_asid asid pd) (deleteASID asid pd)\"\n  apply (simp add: delete_asid_def deleteASID_def)\n  apply_debug (trace) (* apply_trace between steps *)\n    (tags \"corres\") (* break at breakpoints labelled \"corres\" *)\n    corres (* weaken precondition *)\n   continue (* split *)\n       continue (* gets rule *)\n      continue (* corresc *)\n       continue (* return rule *)\n      continue (* split *)\n          continue (* function application *)\n          continue (* liftM rule *)\n          continue (* get_asid_pool_corres_inv' *)\n         continue (* function application *)\n         continue (* function application *)\n         continue (* corresK_when *)\n         continue (* split *)\n             continue (* flush_space_corres *)\n            continue (* K_bind *)\n            continue (* K_bind *)\n            continue (* split *)\n                continue (* invalidate_asid_entry_corres *)\n               continue (* K_bind *)\n               continue (* return bind *)\n               continue (* K_bind *)\n               continue (* split *)\n                   continue (* backtracking *)\n               continue (* split *)\n                   continue (* function application *)\n                   continue (* set_asid_pool_corres *)\n                  continue (* K_bind *)\n                  continue (* K_bind *)\n                  continue (* split *)\n                      continue (* gct_corres *)\n                     continue (* set_vm_root_corres *)\n                    finish (* backtracking? *)\n                    apply (corressimp simp: mask_asid_low_bits_ucast_ucast\n      | fold cur_tcb_def | wps)+\n  apply (frule arm_asid_table_related,clarsimp)\n  apply (rule conjI)\n   apply (intro impI allI)\n    apply (rule conjI)\n     apply (safe; assumption?)\n     apply (rule ext)\n     apply (fastforce simp: inv_def dest: ucast_ucast_eq)\n    apply (rule context_conjI)\n    apply (fastforce simp: o_def dest: valid_asid_tableD invs_valid_asid_table)\n   apply (intro allI impI)\n   apply (subgoal_tac \"vspace_at_asid asid pd s\")\n    prefer 2\n    apply (simp add: vspace_at_asid_def)\n    apply (rule vs_lookupI)\n     apply (simp add: vs_asid_refs_def)\n     apply (rule image_eqI[OF refl])\n     apply (rule graph_ofI)\n     apply fastforce\n    apply (rule r_into_rtrancl)\n    apply simp\n    apply (rule vs_lookup1I [OF _ _ refl], assumption)\n    apply (simp add: vs_refs_def)\n    apply (rule image_eqI[rotated], erule graph_ofI)\n    apply (simp add: mask_asid_low_bits_ucast_ucast)\n   prefer 2\n   apply (intro allI impI context_conjI; assumption?)\n    apply (rule aligned_distinct_relation_asid_pool_atI'; fastforce?)\n    apply (fastforce simp: o_def dest: valid_asid_tableD invs_valid_asid_table)\n    apply (simp add: cur_tcb'_def)\n    apply (safe; assumption?)\n    apply (erule ko_at_weakenE)\n    apply (clarsimp simp: graph_of_def)\n    apply (fastforce split: if_split_asm)\n   apply (frule invs_arch_objs)\n   apply (drule (2) valid_arch_objsD)\n   apply (erule ranE)\n   apply (fastforce split: if_split_asm)\n  apply (erule ko_at_weakenE)\n  apply (clarsimp simp: graph_of_def)\n  apply (fastforce split: if_split_asm)\n  done\n\nlemma cte_wp_at_ex:\n  \"cte_wp_at (\\<lambda>_. True) p s \\<Longrightarrow> (\\<exists>cap. cte_wp_at (op = cap) p s)\"\n  by (simp add: cte_wp_at_def)\n\nlemma set_vm_root_for_flush_corres:\n  notes [corres] = gct_corres getSlotCap_corres\n  shows\n  \"corres (op =)\n          (cur_tcb and vspace_at_asid asid pd\n           and K (asid \\<noteq> 0 \\<and> asid \\<le> mask asid_bits)\n           and valid_asid_map and valid_vs_lookup\n           and valid_arch_objs and valid_global_objs\n           and unique_table_refs o caps_of_state\n           and valid_arch_state\n           and pspace_aligned and pspace_distinct)\n          (pspace_aligned' and pspace_distinct' and no_0_obj')\n          (set_vm_root_for_flush pd asid)\n          (setVMRootForFlush pd asid)\"\n  apply (simp add: set_vm_root_for_flush_def setVMRootForFlush_def getThreadVSpaceRoot_def locateSlot_conv)\n  apply corres\n  apply_debug (trace) (tags \"corres_search\")\n     (corres_search search: arm_context_switch_corres)\n    continue (* step left *)\n    continue (* if rule *)\n    continue (* failed corres on first subgoal, trying next *)\n    continue (* fail corres on last subgoal, trying reverse if rule *)\n    continue (* can't make corres progress here, trying other goal *)\n    finish (* successful goal discharged by corres *)\n\n  apply (corressimp wp: get_cap_wp getSlotCap_wp)+\n  apply (rule context_conjI)\n  subgoal by (simp add: cte_map_def objBits_simps tcb_cnode_index_def\n                        tcbVTableSlot_def to_bl_1 cte_level_bits_def)\n  apply (rule context_conjI)\n  subgoal by (fastforce simp: cur_tcb_def intro!: tcb_at_cte_at_1[simplified])\n  apply (rule conjI)\n   subgoal by (fastforce simp: isCap_simps)\n  apply (drule cte_wp_at_ex)\n  apply clarsimp\n  apply (drule (1) pspace_relation_cte_wp_at[rotated 1]; (assumption | clarsimp)?)\n  apply (drule cte_wp_at_norm')\n  apply clarsimp\n  apply (rule_tac x=\"cteCap cte\" in exI)\n  apply (auto elim: cte_wp_at_weakenE' dest!: curthread_relation)\n  done\n\ntext \\<open>Note we can wrap it all up in corressimp\\<close>\n\nlemma set_vm_root_for_flush_corres':\n  notes [corres] = gct_corres getSlotCap_corres\n  shows\n  \"corres (op =)\n          (cur_tcb and vspace_at_asid asid pd\n           and K (asid \\<noteq> 0 \\<and> asid \\<le> mask asid_bits)\n           and valid_asid_map and valid_vs_lookup\n           and valid_arch_objs and valid_global_objs\n           and unique_table_refs o caps_of_state\n           and valid_arch_state\n           and pspace_aligned and pspace_distinct)\n          (pspace_aligned' and pspace_distinct' and no_0_obj')\n          (set_vm_root_for_flush pd asid)\n          (setVMRootForFlush pd asid)\"\n  apply (simp add: set_vm_root_for_flush_def setVMRootForFlush_def getThreadVSpaceRoot_def locateSlot_conv)\n  apply (corressimp search: arm_context_switch_corres\n                        wp: get_cap_wp getSlotCap_wp\n                      simp: isCap_simps)\n  apply (rule context_conjI)\n  subgoal by (simp add: cte_map_def objBits_simps tcb_cnode_index_def\n                        tcbVTableSlot_def to_bl_1 cte_level_bits_def)\n  apply (rule context_conjI)\n  subgoal by (fastforce simp: cur_tcb_def intro!: tcb_at_cte_at_1[simplified])\n  apply (rule conjI)\n   subgoal by (fastforce)\n  apply (drule cte_wp_at_ex)\n  apply clarsimp\n  apply (drule (1) pspace_relation_cte_wp_at[rotated 1]; (assumption | clarsimp)?)\n  apply (drule cte_wp_at_norm')\n  apply clarsimp\n  apply (rule_tac x=\"cteCap cte\" in exI)\n  apply (auto elim: cte_wp_at_weakenE' dest!: curthread_relation)\n  done\n\nend\nend\n", "meta": {"author": "carl88888", "repo": "filesystem", "sha": "2700e011249e8a675f675c5e0fd13efc1a0957f7", "save_path": "github-repos/isabelle/carl88888-filesystem", "path": "github-repos/isabelle/carl88888-filesystem/filesystem-2700e011249e8a675f675c5e0fd13efc1a0957f7/lib/Corres_Test.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5234203489363239, "lm_q2_score": 0.5698526514141572, "lm_q1q2_score": 0.29827247364548753}}
{"text": "\ntheory mutualEx\n  imports ECMP\nbegin\n\ndefinition I :: \"scalrValueType\" where [simp]:\n \"I \\<equiv> enum ''state'' ''I''\"\n\ndefinition T :: \"scalrValueType\" where [simp]:\n \"T \\<equiv> enum ''state'' ''T''\"\n\ndefinition C :: \"scalrValueType\" where [simp]:\n \"C \\<equiv> enum ''state'' ''C''\"\n\ndefinition E :: \"scalrValueType\" where [simp]:\n \"E \\<equiv> enum ''state'' ''E''\"\n\ndefinition true :: \"scalrValueType\" where [simp]:\n \"true \\<equiv> boolV True\"\n\ndefinition false :: \"scalrValueType\" where [simp]:\n \"false \\<equiv> boolV False\"\n\nprimrec env :: \"nat => envType\" where\n\"env N (Ident n) = (if Ident n = Ident ''x'' then\n  boolType\nelse\n  anyType\n)\"|\n\"env N (Para n i) = (if Para n i = Para ''n'' i \\<and> (i \\<le> N) then\n  enumType\nelse\n  anyType\n)\"|\n\"env N dontCareVar = anyType\"\n\nlemma env_simp : \n \"[|i <= N|] ==> env N (Para ''n'' i) = enumType\"\n \n\n\"  env N (Ident ''x'') = boolType\"\n \n\n\"[|i > N|] ==> env N (Para n i) = anyType\"\n \n \n   apply(auto      )    \n \ndone\n\ndefinition initSpec0 :: \"nat \\<Rightarrow> formula\" where [simp]:\n \"initSpec0 N \\<equiv> (\\<forall>\\<^sub>fi. IVar (Para ''n'' i) =\\<^sub>f Const I) N\"\n\nlemma symPreds0 [intro]: \n \"  symPredSet' N {initSpec0 N}\"\n unfolding initSpec0_def   apply(rule symPredSetForall)\nunfolding symParamForm_def  apply(auto      )    \n \ndone\n\nlemma deriveFormInitSpec0 [intro]: \n \"[|f : {initSpec0 N}|] ==> deriveForm (env N) f\"\n   apply(auto      )    \n \ndone\n\ndefinition initSpec1 :: \"formula\" where [simp]:\n \"initSpec1 \\<equiv> IVar (Ident ''x'') =\\<^sub>f Const true\"\n\nlemma symPreds1 [intro]: \n \"  symPredSet' N {initSpec1}\"\n   apply(auto      )    \n \ndone\n\nlemma deriveFormInitSpec1 [intro]: \n \"[|f : {initSpec1}|] ==> deriveForm (env N) f\"\n   apply(auto      )    \n \ndone\n\ndefinition allInitSpecs :: \"nat \\<Rightarrow> formula set\" where [simp]:\n \"allInitSpecs N \\<equiv> {initSpec0 N} \\<union> {initSpec1}\"\n\nlemma symPreds [intro]: \n \"  symPredSet' N (allInitSpecs N)\"\n unfolding allInitSpecs_def   apply(rule symPredsUnion)\n  apply(blast      )\n\n  apply(blast      )\n\ndone\n\nlemma deriveFormAllInitSpec : \n \"[|f : allInitSpecs N|] ==> deriveForm (env N) f\"\n  using deriveFormInitSpec0 deriveFormInitSpec1 apply(auto      simp del: initSpec0_def initSpec1_def)    \n \ndone\n\ndefinition Try :: \"nat \\<Rightarrow> rule\" where\n \"Try i \\<equiv> \n   IVar (Para ''n'' i) =\\<^sub>f Const I\n  \\<triangleright>\n   assign (Para ''n'' i, Const T)\"\n\nlemma symTry : \n \"  symParamRule N Try\"\n \n\n\"[|i <= N|] ==> wellFormedRule (env N) N (Try i)\"\n \n \n unfolding Try_def  apply(auto intro!: symParamRuleI2 symParamRuleI symParamFormAnd symParamFormForall symParamFormForallExcl symParamFormImply symParamStatementParallel symParamStatementForall symParamStatementForallExcl symParamStatementIte     )    \n \nunfolding symParamForm_def  symParamStatement_def     symParamForm2_def symParamStatement2_def mutualDiffVars_def equivForm_def  apply(auto      )    \n \ndone\n\ndefinition Trys :: \"nat \\<Rightarrow> rule set\" where\n \"Trys N \\<equiv> oneParamCons N Try\"\n\ndefinition Crit :: \"nat \\<Rightarrow> rule\" where\n \"Crit i \\<equiv> \n   IVar (Para ''n'' i) =\\<^sub>f Const T \\<and>\\<^sub>f\n   IVar (Ident ''x'') =\\<^sub>f Const true\n  \\<triangleright>\n   assign (Para ''n'' i, Const C) ||\n   assign (Ident ''x'', Const false)\"\n\nlemma symCrit : \n \"  symParamRule N Crit\"\n \n\n\"[|i <= N|] ==> wellFormedRule (env N) N (Crit i)\"\n \n \n unfolding Crit_def  apply(auto intro!: symParamRuleI2 symParamRuleI symParamFormAnd symParamFormForall symParamFormForallExcl symParamFormImply symParamStatementParallel symParamStatementForall symParamStatementForallExcl symParamStatementIte     )    \n \nunfolding symParamForm_def  symParamStatement_def     symParamForm2_def symParamStatement2_def mutualDiffVars_def equivForm_def  apply(auto      )    \n \ndone\n\ndefinition Crits :: \"nat \\<Rightarrow> rule set\" where\n \"Crits N \\<equiv> oneParamCons N Crit\"\n\ndefinition Exit :: \"nat \\<Rightarrow> rule\" where\n \"Exit i \\<equiv> \n   IVar (Para ''n'' i) =\\<^sub>f Const C\n  \\<triangleright>\n   assign (Para ''n'' i, Const E)\"\n\nlemma symExit : \n \"  symParamRule N Exit\"\n \n\n\"[|i <= N|] ==> wellFormedRule (env N) N (Exit i)\"\n \n \n unfolding Exit_def  apply(auto intro!: symParamRuleI2 symParamRuleI symParamFormAnd symParamFormForall symParamFormForallExcl symParamFormImply symParamStatementParallel symParamStatementForall symParamStatementForallExcl symParamStatementIte     )    \n \nunfolding symParamForm_def  symParamStatement_def     symParamForm2_def symParamStatement2_def mutualDiffVars_def equivForm_def  apply(auto      )    \n \ndone\n\ndefinition Exits :: \"nat \\<Rightarrow> rule set\" where\n \"Exits N \\<equiv> oneParamCons N Exit\"\n\ndefinition Idle :: \"nat \\<Rightarrow> rule\" where\n \"Idle i \\<equiv> \n   IVar (Para ''n'' i) =\\<^sub>f Const E\n  \\<triangleright>\n   assign (Para ''n'' i, Const I) ||\n   assign (Ident ''x'', Const true)\"\n\nlemma symIdle : \n \"  symParamRule N Idle\"\n \n\n\"[|i <= N|] ==> wellFormedRule (env N) N (Idle i)\"\n \n \n unfolding Idle_def  apply(auto intro!: symParamRuleI2 symParamRuleI symParamFormAnd symParamFormForall symParamFormForallExcl symParamFormImply symParamStatementParallel symParamStatementForall symParamStatementForallExcl symParamStatementIte     )    \n \nunfolding symParamForm_def  symParamStatement_def     symParamForm2_def symParamStatement2_def mutualDiffVars_def equivForm_def  apply(auto      )    \n \ndone\n\ndefinition Idles :: \"nat \\<Rightarrow> rule set\" where\n \"Idles N \\<equiv> oneParamCons N Idle\"\n\ndefinition mutualEx :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> formula\" where\n \"mutualEx N i j \\<equiv> \\<not>\\<^sub>f Const (index i) =\\<^sub>f Const (index j) \\<longrightarrow>\\<^sub>f\n  IVar (Para ''n'' i) =\\<^sub>f Const C \\<longrightarrow>\\<^sub>f\n  \\<not>\\<^sub>f IVar (Para ''n'' j) =\\<^sub>f Const C\"\n\ndefinition ABS_Crit :: \"rule\" where\n \"ABS_Crit \\<equiv> \n   IVar (Ident ''x'') =\\<^sub>f Const true\n  \\<triangleright>\n   assign (Ident ''x'', Const false)\"\n\ndefinition ABS_Crits :: \"rule set\" where\n \"ABS_Crits \\<equiv> {ABS_Crit}\"\n\ndefinition ABS_Idle :: \"nat \\<Rightarrow> rule\" where\n \"ABS_Idle N \\<equiv> \n   (\\<forall>\\<^sub>fj. \\<not>\\<^sub>f IVar (Para ''n'' j) =\\<^sub>f Const C \\<and>\\<^sub>f\n   \\<not>\\<^sub>f IVar (Para ''n'' j) =\\<^sub>f Const E) N\n  \\<triangleright>\n   assign (Ident ''x'', Const true)\"\n\ndefinition ABS_Idles :: \"nat \\<Rightarrow> rule set\" where\n \"ABS_Idles N \\<equiv> {ABS_Idle N}\"\n\ndefinition Lemma_1 :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> formula\" where\n \"Lemma_1 N p i \\<equiv> IVar (Para ''n'' i) =\\<^sub>f Const E \\<longrightarrow>\\<^sub>f\n  forallFormExcl (\\<lambda>j. \\<not>\\<^sub>f IVar (Para ''n'' j) =\\<^sub>f Const C \\<and>\\<^sub>f\n  \\<not>\\<^sub>f IVar (Para ''n'' j) =\\<^sub>f Const E) i N\"\n\ndefinition rules :: \"nat \\<Rightarrow> rule set\" where\n \"rules N = (Trys N \\<union> (Crits N \\<union> (Exits N \\<union> Idles N)))\"\n\nlemma deriveAll : \n \"[|r : Trys N|] ==> deriveRule (env N) r\"\n \n\n\"[|r : Crits N|] ==> deriveRule (env N) r\"\n \n\n\"[|r : Exits N|] ==> deriveRule (env N) r\"\n \n\n\"[|r : Idles N|] ==> deriveRule (env N) r\"\n \n\n\"[|r : ABS_Crits|] ==> deriveRule (env N) r\"\n \n\n\"[|r : ABS_Idles N|] ==> deriveRule (env N) r\"\n \n \n unfolding deriveRule_def deriveForm_def deriveStmt_def Trys_def Try_def Crits_def Crit_def Exits_def Exit_def Idles_def Idle_def ABS_Crits_def ABS_Crit_def ABS_Idles_def ABS_Idle_def  apply(auto      )    \n \ndone\n\nlemma symProtAll : \n \"  symProtRules' N (Trys N)\"\n \n\n\"  symProtRules' N (Crits N)\"\n \n\n\"  symProtRules' N (Exits N)\"\n \n\n\"  symProtRules' N (Idles N)\"\n \n \n  using symTry(1) Trys_def symParaRuleInfSymRuleSet symParaRuleInfSymRuleSet2 apply(auto      )[1]    \n \n using symCrit(1) Crits_def symParaRuleInfSymRuleSet symParaRuleInfSymRuleSet2 apply(auto      )[1]    \n \n using symExit(1) Exits_def symParaRuleInfSymRuleSet symParaRuleInfSymRuleSet2 apply(auto      )[1]    \n \n using symIdle(1) Idles_def symParaRuleInfSymRuleSet symParaRuleInfSymRuleSet2 apply(auto      )[1]    \n \ndone\n\nlemma symmutualEx : \n \"  symParamForm2 N (mutualEx N)\"\n unfolding mutualEx_def  apply(auto      )    \n \n  apply(intro  symParamForm2Imply symParamFormForallExcl2 )\n\nunfolding symParamForm2_def  apply(auto      )    \n \ndone\n\nlemma symLemma_1 : \n \"  symParamForm2 N (Lemma_1 N)\"\n unfolding Lemma_1_def  apply(auto      )    \n \n  apply(intro  symParamForm2Imply symParamFormForallExcl2 )\n\nunfolding symParamForm2_def  apply(auto      )    \n \ndone\n\ndefinition lemmasFor_Try :: \"nat \\<Rightarrow> ((nat \\<Rightarrow> nat \\<Rightarrow> formula) list)\" where\n \"lemmasFor_Try N = []\"\n\ndefinition Try_ref :: \"nat \\<Rightarrow> rule\" where\n \"Try_ref i \\<equiv> \n   IVar (Para ''n'' i) =\\<^sub>f Const I\n  \\<triangleright>\n   assign (Para ''n'' i, Const T)\"\n\nlemma symTry_ref : \n \"  symParamRule N Try_ref\"\n \n\n\"[|i <= N|] ==> wellFormedRule (env N) N (Try_ref i)\"\n \n \n unfolding Try_ref_def  apply(auto intro!: symParamRuleI2 symParamRuleI symParamFormAnd symParamFormForall symParamFormForallExcl symParamFormImply symParamStatementParallel symParamStatementForall symParamStatementForallExcl symParamStatementIte     )    \n \nunfolding symParamForm_def  symParamStatement_def     symParamForm2_def symParamStatement2_def mutualDiffVars_def equivForm_def  apply(auto      )    \n \ndone\n\ndefinition Try_refs :: \"nat \\<Rightarrow> rule set\" where\n \"Try_refs N \\<equiv> oneParamCons N Try_ref\"\n\nlemma Try_strengthen : \n \"  strengthenRuleByFrmL2 (map2' (lemmasFor_Try N) j i) (Try i) = Try_ref i\"\n unfolding lemmasFor_Try_def  Try_def Try_ref_def  apply(auto      )    \n \ndone\n\nlemma abs_Try_ref : \n \"[|M <= N;i <= M|] ==> absTransfRule (env N) M (Try_ref i) = Try_ref i\"\n \n\n\"[|M <= N;i > M|] ==> absTransfRule (env N) M (Try_ref i) = skipRule\"\n \n \n unfolding Try_ref_def Try_ref_def skipRule_def  apply(auto     simp add: Let_def )    \n \ndone\n\ndefinition lemmasFor_Crit :: \"nat \\<Rightarrow> ((nat \\<Rightarrow> nat \\<Rightarrow> formula) list)\" where\n \"lemmasFor_Crit N = []\"\n\ndefinition Crit_ref :: \"nat \\<Rightarrow> rule\" where\n \"Crit_ref i \\<equiv> \n   IVar (Para ''n'' i) =\\<^sub>f Const T \\<and>\\<^sub>f\n   IVar (Ident ''x'') =\\<^sub>f Const true\n  \\<triangleright>\n   assign (Para ''n'' i, Const C) ||\n   assign (Ident ''x'', Const false)\"\n\nlemma symCrit_ref : \n \"  symParamRule N Crit_ref\"\n \n\n\"[|i <= N|] ==> wellFormedRule (env N) N (Crit_ref i)\"\n \n \n unfolding Crit_ref_def  apply(auto intro!: symParamRuleI2 symParamRuleI symParamFormAnd symParamFormForall symParamFormForallExcl symParamFormImply symParamStatementParallel symParamStatementForall symParamStatementForallExcl symParamStatementIte     )    \n \nunfolding symParamForm_def  symParamStatement_def     symParamForm2_def symParamStatement2_def mutualDiffVars_def equivForm_def  apply(auto      )    \n \ndone\n\ndefinition Crit_refs :: \"nat \\<Rightarrow> rule set\" where\n \"Crit_refs N \\<equiv> oneParamCons N Crit_ref\"\n\nlemma Crit_strengthen : \n \"  strengthenRuleByFrmL2 (map2' (lemmasFor_Crit N) j i) (Crit i) = Crit_ref i\"\n unfolding lemmasFor_Crit_def  Crit_def Crit_ref_def  apply(auto      )    \n \ndone\n\nlemma abs_Crit_ref : \n \"[|M <= N;i <= M|] ==> absTransfRule (env N) M (Crit_ref i) = Crit_ref i\"\n \n\n\"[|M <= N;i > M|] ==> absTransfRule (env N) M (Crit_ref i) = ABS_Crit\"\n \n \n unfolding Crit_ref_def Crit_ref_def ABS_Crit_def  apply(auto     simp add: Let_def )    \n \ndone\n\ndefinition lemmasFor_Exit :: \"nat \\<Rightarrow> ((nat \\<Rightarrow> nat \\<Rightarrow> formula) list)\" where\n \"lemmasFor_Exit N = []\"\n\ndefinition Exit_ref :: \"nat \\<Rightarrow> rule\" where\n \"Exit_ref i \\<equiv> \n   IVar (Para ''n'' i) =\\<^sub>f Const C\n  \\<triangleright>\n   assign (Para ''n'' i, Const E)\"\n\nlemma symExit_ref : \n \"  symParamRule N Exit_ref\"\n \n\n\"[|i <= N|] ==> wellFormedRule (env N) N (Exit_ref i)\"\n \n \n unfolding Exit_ref_def  apply(auto intro!: symParamRuleI2 symParamRuleI symParamFormAnd symParamFormForall symParamFormForallExcl symParamFormImply symParamStatementParallel symParamStatementForall symParamStatementForallExcl symParamStatementIte     )    \n \nunfolding symParamForm_def  symParamStatement_def     symParamForm2_def symParamStatement2_def mutualDiffVars_def equivForm_def  apply(auto      )    \n \ndone\n\ndefinition Exit_refs :: \"nat \\<Rightarrow> rule set\" where\n \"Exit_refs N \\<equiv> oneParamCons N Exit_ref\"\n\nlemma Exit_strengthen : \n \"  strengthenRuleByFrmL2 (map2' (lemmasFor_Exit N) j i) (Exit i) = Exit_ref i\"\n unfolding lemmasFor_Exit_def  Exit_def Exit_ref_def  apply(auto      )    \n \ndone\n\nlemma abs_Exit_ref : \n \"[|M <= N;i <= M|] ==> absTransfRule (env N) M (Exit_ref i) = Exit_ref i\"\n \n\n\"[|M <= N;i > M|] ==> absTransfRule (env N) M (Exit_ref i) = skipRule\"\n \n \n unfolding Exit_ref_def Exit_ref_def skipRule_def  apply(auto     simp add: Let_def )    \n \ndone\n\ndefinition lemmasFor_Idle :: \"nat \\<Rightarrow> ((nat \\<Rightarrow> nat \\<Rightarrow> formula) list)\" where\n \"lemmasFor_Idle N = [Lemma_1 N]\"\n\ndefinition Idle_ref :: \"nat \\<Rightarrow> nat \\<Rightarrow> rule\" where\n \"Idle_ref N i \\<equiv> \n   IVar (Para ''n'' i) =\\<^sub>f Const E \\<and>\\<^sub>f\n   forallFormExcl (\\<lambda>j. \\<not>\\<^sub>f IVar (Para ''n'' j) =\\<^sub>f Const C \\<and>\\<^sub>f\n   \\<not>\\<^sub>f IVar (Para ''n'' j) =\\<^sub>f Const E) i N\n  \\<triangleright>\n   assign (Para ''n'' i, Const I) ||\n   assign (Ident ''x'', Const true)\"\n\nlemma symIdle_ref : \n \"  symParamRule N (Idle_ref N)\"\n \n\n\"[|i <= N|] ==> wellFormedRule (env N) N (Idle_ref N i)\"\n \n \n unfolding Idle_ref_def  apply(auto intro!: symParamRuleI2 symParamRuleI symParamFormAnd symParamFormForall symParamFormForallExcl symParamFormImply symParamStatementParallel symParamStatementForall symParamStatementForallExcl symParamStatementIte     )    \n \nunfolding symParamForm_def  symParamStatement_def     symParamForm2_def symParamStatement2_def mutualDiffVars_def equivForm_def  apply(auto      )    \n \ndone\n\ndefinition Idle_refs :: \"nat \\<Rightarrow> rule set\" where\n \"Idle_refs N \\<equiv> oneParamCons N (Idle_ref N)\"\n\nlemma Idle_strengthen : \n \"  strengthenRuleByFrmL2 (map2' (lemmasFor_Idle N) j i) (Idle i) = Idle_ref N i\"\n unfolding lemmasFor_Idle_def Lemma_1_def Idle_def Idle_ref_def  apply(auto      )    \n \ndone\n\nlemma abs_Idle_ref : \n \"[|M <= N;i <= M|] ==> absTransfRule (env N) M (Idle_ref N i) = Idle_ref M i\"\n \n\n\"[|M <= N;i > M|] ==> absTransfRule (env N) M (Idle_ref N i) = ABS_Idle M\"\n \n \n unfolding Idle_ref_def Idle_ref_def ABS_Idle_def  apply(auto     simp add: Let_def )    \n \ndone\n\ndefinition InvS :: \"nat \\<Rightarrow> (((nat \\<Rightarrow> nat \\<Rightarrow> formula) list) list)\" where\n \"InvS N = [lemmasFor_Try N, lemmasFor_Crit N, lemmasFor_Exit N, lemmasFor_Idle N]\"\n\ndefinition rule_refs :: \"nat \\<Rightarrow> rule set\" where\n \"rule_refs N = (Try_refs N \\<union> (Crit_refs N \\<union> (Exit_refs N \\<union> Idle_refs N)))\"\n\nlemma TryStrengthRel : \n \"  strengthenRel (Trys N) (set (InvS N)) (Try_refs N) N\"\n unfolding Trys_def Try_refs_def  apply(rule_tac ?lemmasFor_r=\"lemmasFor_Try\" in strengthenExt1)\n using Try_strengthen apply(presburger      )\n\nunfolding InvS_def  apply(auto      )    \n \ndone\n\nlemma CritStrengthRel : \n \"  strengthenRel (Crits N) (set (InvS N)) (Crit_refs N) N\"\n unfolding Crits_def Crit_refs_def  apply(rule_tac ?lemmasFor_r=\"lemmasFor_Crit\" in strengthenExt1)\n using Crit_strengthen apply(presburger      )\n\nunfolding InvS_def  apply(auto      )    \n \ndone\n\nlemma ExitStrengthRel : \n \"  strengthenRel (Exits N) (set (InvS N)) (Exit_refs N) N\"\n unfolding Exits_def Exit_refs_def  apply(rule_tac ?lemmasFor_r=\"lemmasFor_Exit\" in strengthenExt1)\n using Exit_strengthen apply(presburger      )\n\nunfolding InvS_def  apply(auto      )    \n \ndone\n\nlemma IdleStrengthRel : \n \"  strengthenRel (Idles N) (set (InvS N)) (Idle_refs N) N\"\n unfolding Idles_def Idle_refs_def  apply(rule_tac ?lemmasFor_r=\"lemmasFor_Idle\" in strengthenExt1)\n using Idle_strengthen apply(presburger      )\n\nunfolding InvS_def  apply(auto      )    \n \ndone\n\nlemma deriveAllRef : \n \"[|r : Try_refs N|] ==> deriveRule (env N) r\"\n \n\n\"[|r : Crit_refs N|] ==> deriveRule (env N) r\"\n \n\n\"[|r : Exit_refs N|] ==> deriveRule (env N) r\"\n \n\n\"[|r : Idle_refs N|] ==> deriveRule (env N) r\"\n \n \n unfolding deriveRule_def deriveForm_def deriveStmt_def Try_refs_def Try_ref_def Crit_refs_def Crit_ref_def Exit_refs_def Exit_ref_def Idle_refs_def Idle_ref_def  apply(auto      )    \n \ndone\n\nlemma symProtAllRef : \n \"  symProtRules' N (Try_refs N)\"\n \n\n\"  symProtRules' N (Crit_refs N)\"\n \n\n\"  symProtRules' N (Exit_refs N)\"\n \n\n\"  symProtRules' N (Idle_refs N)\"\n \n \n  using symTry_ref(1) Try_refs_def symCrit_ref(1) Crit_refs_def symExit_ref(1) Exit_refs_def symIdle_ref(1) Idle_refs_def symParaRuleInfSymRuleSet symParaRuleInfSymRuleSet2 apply(auto      )    \n \ndone\n\nlemma StrengthRelRules2Rule_refs : \n \"  strengthenRel (rules N) (set (InvS N)) (rule_refs N) N\"\n unfolding rules_def rule_refs_def   apply(rule strenRelUnion)\n  apply(blast intro: TryStrengthRel     )\n\n   apply(rule strenRelUnion)\n  apply(blast intro: CritStrengthRel     )\n\n   apply(rule strenRelUnion)\n  apply(blast intro: ExitStrengthRel     )\n\n  apply(blast intro: IdleStrengthRel     )\n\ndone\n\nlemma Abs_Try_refs : \n \"[|M < N|] ==> (absTransfRule (env N) M ` Try_refs N) = (Try_refs M Un {skipRule})\"\n unfolding Try_refs_def   apply(rule absGen)\n using abs_Try_ref apply(auto      )    \n \ndone\n\nlemma Abs_Crit_refs : \n \"[|M < N|] ==> (absTransfRule (env N) M ` Crit_refs N) = (Crit_refs M Un ABS_Crits)\"\n unfolding Crit_refs_def ABS_Crits_def   apply(rule absGen)\n using abs_Crit_ref apply(auto      )    \n \ndone\n\nlemma Abs_Exit_refs : \n \"[|M < N|] ==> (absTransfRule (env N) M ` Exit_refs N) = (Exit_refs M Un {skipRule})\"\n unfolding Exit_refs_def   apply(rule absGen)\n using abs_Exit_ref apply(auto      )    \n \ndone\n\nlemma Abs_Idle_refs : \n \"[|M < N|] ==> (absTransfRule (env N) M ` Idle_refs N) = (Idle_refs M Un ABS_Idles M)\"\n unfolding Idle_refs_def ABS_Idles_def   apply(rule absGen)\n using abs_Idle_ref apply(auto      )    \n \ndone\n\ndefinition ABS_rules :: \"nat \\<Rightarrow> rule set\" where [simp]:\n \"ABS_rules N = (Try_refs N \\<union> (Crit_refs N \\<union> (ABS_Crits \\<union> (Exit_refs N \\<union> (Idle_refs N \\<union> (ABS_Idles N \\<union> {skipRule}))))))\"\n\ndefinition ABS_rules' :: \"nat \\<Rightarrow> rule set\" where [simp]:\n \"ABS_rules' N = ((Try_refs N \\<union> {skipRule}) \\<union> ((Crit_refs N \\<union> ABS_Crits) \\<union> ((Exit_refs N \\<union> {skipRule}) \\<union> (Idle_refs N \\<union> ABS_Idles N))))\"\n\nlemma ABS_rules_eq_rules' : \n \"  ABS_rules M = ABS_rules' M\"\n   apply(auto      )    \n \ndone\n\nlemma ABS_all : \n \"[|M < N|] ==> (absTransfRule (env N) M ` rule_refs N) = ABS_rules M\"\n   apply(subst ABS_rules_eq_rules'       )\n\nunfolding rule_refs_def ABS_rules'_def  apply(intro  image_UnI )\n\n  apply(auto     simp add: Abs_Try_refs Abs_Crit_refs Abs_Exit_refs Abs_Idle_refs )    \n \ndone\n\ndefinition Lemma_1' :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> formula\" where\n \"Lemma_1' N i j \\<equiv> \\<not>\\<^sub>f Const (index i) =\\<^sub>f Const (index j) \\<and>\\<^sub>f\n  IVar (Para ''n'' i) =\\<^sub>f Const E \\<longrightarrow>\\<^sub>f\n  \\<not>\\<^sub>f IVar (Para ''n'' j) =\\<^sub>f Const C \\<and>\\<^sub>f\n  \\<not>\\<^sub>f IVar (Para ''n'' j) =\\<^sub>f Const E\"\n\nlemma absTransfLemma_1' : \n \"[|M < N;M = 1;l <= 1|] ==> absTransfForm (env N) M (Lemma_1' N 0 l) = Lemma_1' N 0 l\"\n unfolding Lemma_1'_def  apply(auto      )    \n \ndone\n\nlemma strengthenVsObsLemma_1 : \n \"  strengthenVsObs (Lemma_1 N) (Lemma_1' N) N\"\n unfolding Lemma_1_def Lemma_1'_def   apply(rule strengthenVsObsDiff)\nunfolding symParamForm_def  apply(auto      )    \n \ndone\n\nlemma SafeAndderiveFormLemma_1' : \n \"[|M < N;M = 1;l <= M;k <= M|] ==> safeForm (env N) M (Lemma_1' N k l) & deriveForm (env N) (Lemma_1' N k l)\"\n unfolding Lemma_1'_def  apply(auto      )    \n \ndone\n\nlemma symInvs : \n \"  symParamForm2 N (Lemma_1' N)\"\n \n \n unfolding Lemma_1'_def  apply(auto      )    \n \nsubgoal    apply(intro  symParamForm2Imply symParamFormForallExcl2 )\n  \n  unfolding symParamForm2_def  apply(auto      )    \n   done\n\ndone\n\ndefinition lemmasFor_Try' :: \"nat \\<Rightarrow> ((nat \\<Rightarrow> nat \\<Rightarrow> formula) list)\" where\n \"lemmasFor_Try' N = []\"\n\nlemma strengthenVsObsLs_lemmasFor_Try : \n \"  strengthenVsObsLs (lemmasFor_Try N) (lemmasFor_Try' N) N\"\n unfolding strengthenVsObsLs_def lemmasFor_Try_def lemmasFor_Try'_def  apply(auto      )    \n \ndone\n\nlemma lemmaTry_fitEnv : \n \"[|formEval (pre r) s;fitEnv s (env N);r : Try_refs N|] ==> fitEnv (trans1 (act r) s) (env N)\"\n unfolding Try_refs_def Try_ref_def  apply(auto      )    \n \ndone\n\ndefinition lemmasFor_Crit' :: \"nat \\<Rightarrow> ((nat \\<Rightarrow> nat \\<Rightarrow> formula) list)\" where\n \"lemmasFor_Crit' N = []\"\n\nlemma strengthenVsObsLs_lemmasFor_Crit : \n \"  strengthenVsObsLs (lemmasFor_Crit N) (lemmasFor_Crit' N) N\"\n unfolding strengthenVsObsLs_def lemmasFor_Crit_def lemmasFor_Crit'_def  apply(auto      )    \n \ndone\n\nlemma lemmaCrit_fitEnv : \n \"[|formEval (pre r) s;fitEnv s (env N);r : Crit_refs N|] ==> fitEnv (trans1 (act r) s) (env N)\"\n unfolding Crit_refs_def Crit_ref_def  apply(auto      )    \n \ndone\n\ndefinition lemmasFor_Exit' :: \"nat \\<Rightarrow> ((nat \\<Rightarrow> nat \\<Rightarrow> formula) list)\" where\n \"lemmasFor_Exit' N = []\"\n\nlemma strengthenVsObsLs_lemmasFor_Exit : \n \"  strengthenVsObsLs (lemmasFor_Exit N) (lemmasFor_Exit' N) N\"\n unfolding strengthenVsObsLs_def lemmasFor_Exit_def lemmasFor_Exit'_def  apply(auto      )    \n \ndone\n\nlemma lemmaExit_fitEnv : \n \"[|formEval (pre r) s;fitEnv s (env N);r : Exit_refs N|] ==> fitEnv (trans1 (act r) s) (env N)\"\n unfolding Exit_refs_def Exit_ref_def  apply(auto      )    \n \ndone\n\ndefinition lemmasFor_Idle' :: \"nat \\<Rightarrow> ((nat \\<Rightarrow> nat \\<Rightarrow> formula) list)\" where\n \"lemmasFor_Idle' N = [Lemma_1' N]\"\n\nlemma strengthenVsObsLs_lemmasFor_Idle : \n \"  strengthenVsObsLs (lemmasFor_Idle N) (lemmasFor_Idle' N) N\"\n unfolding strengthenVsObsLs_def lemmasFor_Idle_def lemmasFor_Idle'_def  apply(auto intro: strengthenVsObsLemma_1     )    \n \ndone\n\nlemma lemmaIdle_fitEnv : \n \"[|formEval (pre r) s;fitEnv s (env N);r : Idle_refs N|] ==> fitEnv (trans1 (act r) s) (env N)\"\n unfolding Idle_refs_def Idle_ref_def  apply(auto      )    \n \ndone\n\ndefinition InvS' :: \"nat \\<Rightarrow> (((nat \\<Rightarrow> nat \\<Rightarrow> formula) list) list)\" where\n \"InvS' N = [lemmasFor_Try' N, lemmasFor_Crit' N, lemmasFor_Exit' N, lemmasFor_Idle' N]\"\n\nlemma wellFormedRule_refs : \n \"[|r : rule_refs N|] ==> wellFormedRule (env N) N r\"\n   apply(auto     simp add: rule_refs_def   Try_refs_def Crit_refs_def Exit_refs_def Idle_refs_def symTry_ref symCrit_ref symExit_ref symIdle_ref )    \n \ndone\n\nlemma SafeAndderiveAll : \n \"[|M < N;M = 1;l <= M;k <= M;pinvL : set (InvS' N);pf : set pinvL|] ==> safeForm (env N) M (pf k l) & deriveForm (env N) (pf k l)\"\n unfolding InvS'_def lemmasFor_Try'_def lemmasFor_Crit'_def lemmasFor_Exit'_def lemmasFor_Idle'_def using SafeAndderiveFormLemma_1' apply(auto      )    \n \ndone\n\nlemma rulesIsSym : \n \"  symProtRules' N (rules N)\"\n unfolding rules_def   apply(rule symProtRulesUnion, blast intro:symProtAll)+\nunfolding rules_def  apply(blast intro: symProtAll     )\n\ndone\n\nlemma rule_refsIsSym : \n \"  symProtRules' N (rule_refs N)\"\n unfolding rule_refs_def   apply(rule symProtRulesUnion, blast intro:symProtAllRef)+\nunfolding rule_refs_def  apply(blast intro: symProtAllRef     )\n\ndone\n\nlemma rule_refsWellTyped : \n \"[|r : rule_refs N|] ==> deriveRule (env N) r\"\n unfolding rule_refs_def using deriveAllRef apply(auto      )    \n \ndone\n\nlemma ReachStafitEnv : \n \"[|reachableUpTo (allInitSpecs N) (rule_refs N) k s|] ==> fitEnv s (env N)\"\n   apply(erule invIntro1)\nsubgoal for s0\n  unfolding fitEnv_def   apply(rule allI)\n     apply(rule impI)\n  apply(case_tac   \"v\")\n  \n  subgoal for v x1\n    apply(case_tac   \"x1 = ''x''\")\n    \n    apply(subgoal_tac   \"formEval (initSpec1) s0\")\n    \n      apply(auto      )[1]    \n     \n      apply(auto      )[1]    \n     \n      apply(auto      )    \n     done\n  \n  subgoal for v x21 x22\n    apply(case_tac   \"x21 = ''n''\")\n    \n    apply(subgoal_tac   \"formEval (initSpec0 N) s0\")\n    \n      apply(auto      )[1]    \n     \n      apply(auto      )[1]    \n     \n      apply(auto      )    \n     done\n  \n    apply(auto      )    \n   done\n\nsubgoal for r sk\n  unfolding rule_refs_def  apply(auto intro: Un_iff lemmaTry_fitEnv lemmaCrit_fitEnv lemmaExit_fitEnv lemmaIdle_fitEnv     )    \n   done\n\ndone\n\nlemma absProtSim : \n \"[|M < N;M = 1;isProtObsInvSet (ABS_rules M) (absTransfForm (env N) M ` allInitSpecs N) (set (InvS' N)) M (env N)|] ==> isParamProtInvSet (rules N) (allInitSpecs N) (set (InvS N)) N\"\n   apply(rule_tac ?rs2.0 = \"rule_refs N\" and env=\"env N\" and S=\"set (InvS N)\" and S'=\"set (InvS' N)\" and M=M and absRules=\"ABS_rules M\" in CMP)\nsubgoal for r\n   using wellFormedRule_refs apply(auto      )    \n   done\n\nsubgoal  unfolding InvS'_def lemmasFor_Try'_def lemmasFor_Crit'_def lemmasFor_Exit'_def lemmasFor_Idle'_def using symInvs apply(auto      )    \n   done\n\nsubgoal   using rulesIsSym apply(auto      )    \n   done\n\nsubgoal   using symPreds apply(auto      )    \n   done\n\nsubgoal    apply(auto      )    \n   done\n\nsubgoal    apply(auto      )    \n   done\n\nsubgoal   using SafeAndderiveAll apply(auto      )    \n   done\n\nsubgoal   using StrengthRelRules2Rule_refs apply(auto      )    \n   done\n\nsubgoal   using rule_refsIsSym apply(auto      )    \n   done\n\nsubgoal   using rule_refsWellTyped apply(auto      )    \n   done\n\nsubgoal    apply(auto      )    \n   done\n\nsubgoal   using ReachStafitEnv apply(auto      )    \n   done\n\nsubgoal  unfolding InvS_def InvS'_def  apply(auto      )    \n   \n  subgoal   using strengthenVsObsLs_lemmasFor_Try apply(auto      )    \n     done\n  \n  subgoal   using strengthenVsObsLs_lemmasFor_Crit apply(auto      )    \n     done\n  \n  subgoal   using strengthenVsObsLs_lemmasFor_Exit apply(auto      )    \n     done\n  \n  subgoal   using strengthenVsObsLs_lemmasFor_Idle apply(auto      )    \n     done\n  done\n\n   apply(rule equivRuleSetReflex)\n using ABS_all  apply(auto      )    \n \ndone\n\nend\n", "meta": {"author": "forSubmission238", "repo": "autoCMP", "sha": "5d8dfa67306904b61a1cb92777edb311c68bd53b", "save_path": "github-repos/isabelle/forSubmission238-autoCMP", "path": "github-repos/isabelle/forSubmission238-autoCMP/autoCMP-5d8dfa67306904b61a1cb92777edb311c68bd53b/mutualEx/mutualEx.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331462646254, "lm_q2_score": 0.5, "lm_q1q2_score": 0.2982165731323127}}
{"text": "section \\<open>Operation Identification Phase\\<close>\ntheory Sepref_Id_Op\nimports \n  Main \n  Automatic_Refinement.Refine_Lib\n  Automatic_Refinement.Autoref_Tagging\n  \"Lib/Named_Theorems_Rev\"\nbegin\n\ntext \\<open>\n  The operation identification phase is adapted from the Autoref tool.\n  The basic idea is to have a type system, which works on so called \n  interface types (also called conceptual types). Each conceptual type\n  denotes an abstract data type, e.g., set, map, priority queue.\n  \n  Each abstract operation, which must be a constant applied to its arguments,\n  is assigned a conceptual type. Additionally, there is a set of \n  {\\emph pattern rewrite rules},\n  which are applied to subterms before type inference takes place, and \n  which may be backtracked over. \n  This way, encodings of abstract operations in Isabelle/HOL, like \n  @{term [source] \"\\<lambda>_. None\"} for the empty map, \n  or @{term [source] \"fun_upd m k (Some v)\"} for map update, can be rewritten\n  to abstract operations, and get properly typed.\n\\<close>\n\nsubsection \"Proper Protection of Term\"\ntext \\<open> The following constants are meant to encode abstraction and \n  application as proper HOL-constants, and thus avoid strange effects with\n  HOL's higher-order unification heuristics and automatic \n  beta and eta-contraction.\n\n  The first step of operation identification is to protect the term\n  by replacing all function applications and abstractions be \n  the constants defined below.\n\\<close>\n\ndefinition [simp]: \"PROTECT2 x (y::prop) \\<equiv> x\"\nconsts DUMMY :: \"prop\"\n\nabbreviation PROTECT2_syn (\"'(#_#')\") where \"PROTECT2_syn t \\<equiv> PROTECT2 t DUMMY\"\n\nabbreviation (input)ABS2 :: \"('a\\<Rightarrow>'b)\\<Rightarrow>'a\\<Rightarrow>'b\" (binder \"\\<lambda>\\<^sub>2\" 10)\n  where \"ABS2 f \\<equiv> (\\<lambda>x. PROTECT2 (f x) DUMMY)\"\n\nlemma beta: \"(\\<lambda>\\<^sub>2x. f x)$x \\<equiv> f x\" by simp\n\ntext \\<open>\n  Another version of @{const \"APP\"}. Treated like @{const APP} by our tool.\n  Required to avoid infinite pattern rewriting in some cases, e.g., map-lookup.\n\\<close>\n\ndefinition APP' (infixl \"$''\" 900) where [simp, autoref_tag_defs]: \"f$'a \\<equiv> f a\"\n\ntext \\<open>\n  Sometimes, whole terms should be protected from being processed by our tool.\n  For example, our tool should not look into numerals. For this reason,\n  the \\<open>PR_CONST\\<close> tag indicates terms that our tool shall handle as\n  atomic constants, an never look into them.\n\n  The special form \\<open>UNPROTECT\\<close> can be used inside pattern rewrite rules.\n  It has the effect to revert the protection from its argument, and then wrap\n  it into a \\<open>PR_CONST\\<close>.\n\\<close>\ndefinition [simp, autoref_tag_defs]: \"PR_CONST x \\<equiv> x\" \\<comment> \\<open>Tag to protect constant\\<close>\ndefinition [simp, autoref_tag_defs]: \"UNPROTECT x \\<equiv> x\" \\<comment> \\<open>Gets \n  converted to @{term PR_CONST}, after unprotecting its content\\<close>\n\n\nsubsection \\<open>Operation Identification\\<close>\n\ntext \\<open> Indicator predicate for conceptual typing of a constant \\<close>\ndefinition intf_type :: \"'a \\<Rightarrow> 'b itself \\<Rightarrow> bool\" (infix \"::\\<^sub>i\" 10) where\n  [simp]: \"c::\\<^sub>iI \\<equiv> True\"\n\nlemma itypeI: \"c::\\<^sub>iI\" by simp\nlemma itypeI': \"intf_type c TYPE('T)\" by (rule itypeI)\n\nlemma itype_self: \"(c::'a) ::\\<^sub>i TYPE('a)\" by simp\n\ndefinition CTYPE_ANNOT :: \"'b \\<Rightarrow> 'a itself \\<Rightarrow> 'b\" (infix \":::\\<^sub>i\" 10) where\n  [simp]: \"c:::\\<^sub>iI \\<equiv> c\"\n\ntext \\<open> Wrapper predicate for an conceptual type inference \\<close>\ndefinition ID :: \"'a \\<Rightarrow> 'a \\<Rightarrow> 'c itself \\<Rightarrow> bool\" \n  where [simp]: \"ID t t' T \\<equiv> t=t'\"\n\nsubsubsection \\<open>Conceptual Typing Rules\\<close>\n\nlemma ID_unfold_vars: \"ID x y T \\<Longrightarrow> x\\<equiv>y\" by simp\nlemma ID_PR_CONST_trigger: \"ID (PR_CONST x) y T \\<Longrightarrow> ID (PR_CONST x) y T\" .\n\nlemma pat_rule:\n  \"\\<lbrakk> p\\<equiv>p'; ID p' t' T \\<rbrakk> \\<Longrightarrow> ID p t' T\" by simp\n\nlemma app_rule:\n  \"\\<lbrakk> ID f f' TYPE('a\\<Rightarrow>'b); ID x x' TYPE('a)\\<rbrakk> \\<Longrightarrow> ID (f$x) (f'$x') TYPE('b)\"\n  by simp\n\nlemma app'_rule:\n  \"\\<lbrakk> ID f f' TYPE('a\\<Rightarrow>'b); ID x x' TYPE('a)\\<rbrakk> \\<Longrightarrow> ID (f$'x) (f'$x') TYPE('b)\"\n  by simp\n\nlemma abs_rule:\n  \"\\<lbrakk> \\<And>x x'. ID x x' TYPE('a) \\<Longrightarrow> ID (t x) (t' x x') TYPE('b) \\<rbrakk> \\<Longrightarrow>\n    ID (\\<lambda>\\<^sub>2x. t x) (\\<lambda>\\<^sub>2x'. t' x' x') TYPE('a\\<Rightarrow>'b)\"\n  by simp\n\nlemma id_rule: \"c::\\<^sub>iI \\<Longrightarrow> ID c c I\" by simp\n\nlemma annot_rule: \"ID t t' I \\<Longrightarrow> ID (t:::\\<^sub>iI) t' I\"\n  by simp\n\nlemma fallback_rule:\n  \"ID (c::'a) c TYPE('c)\"\n  by simp\n\nlemma unprotect_rl1: \"ID (PR_CONST x) t T \\<Longrightarrow> ID (UNPROTECT x) t T\"\n  by simp\n\nsubsection \\<open> ML-Level code \\<close>\nML \\<open>\ninfix 0 THEN_ELSE_COMB'\n\nsignature ID_OP_TACTICAL = sig\n  val SOLVE_FWD: tactic' -> tactic'\n  val DF_SOLVE_FWD: bool -> tactic' -> tactic'\nend\n\nstructure Id_Op_Tactical :ID_OP_TACTICAL = struct\n\n  fun SOLVE_FWD tac i st = SOLVED' (\n    tac \n    THEN_ALL_NEW_FWD (SOLVE_FWD tac)) i st\n\n\n  (* Search for solution with DFS-strategy. If dbg-flag is given,\n    return sequence of stuck states if no solution is found.\n  *)\n  fun DF_SOLVE_FWD dbg tac = let\n    val stuck_list_ref = Unsynchronized.ref []\n\n    fun stuck_tac _ st = if dbg then (\n      stuck_list_ref := st :: !stuck_list_ref;\n      Seq.empty\n    ) else Seq.empty\n\n    fun rec_tac i st = (\n        (tac THEN_ALL_NEW_FWD (SOLVED' rec_tac))\n        ORELSE' stuck_tac\n      ) i st\n\n    fun fail_tac _ _ = if dbg then\n      Seq.of_list (rev (!stuck_list_ref))\n    else Seq.empty\n  in\n    rec_tac ORELSE' fail_tac    \n  end\n\nend\n\\<close>\n\n\nnamed_theorems_rev id_rules \"Operation identification rules\"\nnamed_theorems_rev pat_rules \"Operation pattern rules\"\nnamed_theorems_rev def_pat_rules \"Definite operation pattern rules (not backtracked over)\"\n\n\n\nML \\<open>\n\n  structure Id_Op = struct\n\n    fun id_a_conv cnv ct = case Thm.term_of ct of\n      @{mpat \"ID _ _ _\"} => Conv.fun_conv (Conv.fun_conv (Conv.arg_conv cnv)) ct\n    | _ => raise CTERM(\"id_a_conv\",[ct])\n\n    fun \n      protect env (@{mpat \"?t:::\\<^sub>i?I\"}) = let\n        val t = protect env t\n      in \n        @{mk_term env: \"?t:::\\<^sub>i?I\"}\n      end\n    | protect _ (t as @{mpat \"PR_CONST _\"}) = t\n    | protect env (t1$t2) = let\n        val t1 = protect env t1\n        val t2 = protect env t2\n      in\n        @{mk_term env: \"?t1.0 $ ?t2.0\"}\n      end\n    | protect env (Abs (x,T,t)) = let\n        val t = protect (T::env) t\n      in\n        @{mk_term env: \"\\<lambda>v_x::?'v_T. PROTECT2 ?t DUMMY\"}\n      end\n    | protect _ t = t\n\n    fun protect_conv ctxt = Refine_Util.f_tac_conv ctxt\n      (protect []) \n      (simp_tac \n        (put_simpset HOL_basic_ss ctxt addsimps @{thms PROTECT2_def APP_def}) 1)\n\n    fun unprotect_conv ctxt\n      = Simplifier.rewrite (put_simpset HOL_basic_ss ctxt \n        addsimps @{thms PROTECT2_def APP_def})\n\n    fun do_unprotect_tac ctxt =\n      resolve_tac ctxt @{thms unprotect_rl1} THEN'\n      CONVERSION (Refine_Util.HOL_concl_conv (fn ctxt => id_a_conv (unprotect_conv ctxt)) ctxt)\n\n    val cfg_id_debug = \n      Attrib.setup_config_bool @{binding id_debug} (K false)\n\n    val cfg_id_trace_fallback = \n      Attrib.setup_config_bool @{binding id_trace_fallback} (K false)\n\n    fun dest_id_rl thm = case Thm.concl_of thm of\n      @{mpat (typs) \"Trueprop (?c::\\<^sub>iTYPE(?'v_T))\"} => (c,T)\n    | _ => raise THM(\"dest_id_rl\",~1,[thm])\n\n    \n    val add_id_rule = snd oo Thm.proof_attributes [Named_Theorems_Rev.add @{named_theorems_rev id_rules}]\n\n    datatype id_tac_mode = Init | Step | Normal | Solve\n\n    fun id_tac ss ctxt = let\n      open Id_Op_Tactical\n      val certT = Thm.ctyp_of ctxt\n      val cert = Thm.cterm_of ctxt\n\n      val thy = Proof_Context.theory_of ctxt\n\n      val id_rules = Named_Theorems_Rev.get ctxt @{named_theorems_rev id_rules}\n      val pat_rules = Named_Theorems_Rev.get ctxt @{named_theorems_rev pat_rules}\n      val def_pat_rules = Named_Theorems_Rev.get ctxt @{named_theorems_rev def_pat_rules}\n\n      val rl_net = Tactic.build_net (\n        (pat_rules |> map (fn thm => thm RS @{thm pat_rule})) \n        @ @{thms annot_rule app_rule app'_rule abs_rule} \n        @ (id_rules |> map (fn thm => thm RS @{thm id_rule}))\n      )\n\n      val def_rl_net = Tactic.build_net (\n        (def_pat_rules |> map (fn thm => thm RS @{thm pat_rule}))\n      )  \n\n      val id_pr_const_rename_tac = \n          resolve_tac ctxt @{thms ID_PR_CONST_trigger} THEN'\n          Subgoal.FOCUS (fn { context=ctxt, prems, ... } => \n            let\n              fun is_ID @{mpat \"Trueprop (ID _ _ _)\"} = true | is_ID _ = false\n              val prems = filter (Thm.prop_of #> is_ID) prems\n              val eqs = map (fn thm => thm RS @{thm ID_unfold_vars}) prems\n              val conv = Conv.rewrs_conv eqs\n              val conv = fn ctxt => (Conv.top_sweep_conv (K conv) ctxt)\n              val conv = fn ctxt => Conv.fun2_conv (Conv.arg_conv (conv ctxt))\n              val conv = Refine_Util.HOL_concl_conv conv ctxt\n            in CONVERSION conv 1 end \n          ) ctxt THEN'\n          resolve_tac ctxt @{thms id_rule} THEN'\n          resolve_tac ctxt id_rules \n\n      val ityping = id_rules \n        |> map dest_id_rl\n        |> filter (is_Const o #1)\n        |> map (apfst (#1 o dest_Const))\n        |> Symtab.make_list\n\n      val has_type = Symtab.defined ityping\n\n      fun mk_fallback name cT =\n        case try (Sign.the_const_constraint thy) name of\n          SOME T => try (Thm.instantiate' \n                          [SOME (certT cT), SOME (certT T)] [SOME (cert (Const (name,cT)))])\n                        @{thm fallback_rule} \n        | NONE => NONE\n\n      fun trace_fallback thm = \n        Config.get ctxt cfg_id_trace_fallback       \n        andalso let \n          open Pretty\n          val p = block [str \"ID_OP: Applying fallback rule: \", Thm.pretty_thm ctxt thm]\n        in \n          string_of p |> tracing; \n          false\n        end  \n\n      val fallback_tac = CONVERSION Thm.eta_conversion THEN' IF_EXGOAL (fn i => fn st =>\n        case Logic.concl_of_goal (Thm.prop_of st) i of\n          @{mpat \"Trueprop (ID (mpaq_STRUCT (mpaq_Const ?name ?cT)) _ _)\"} => (\n            if not (has_type name) then \n              case mk_fallback name cT of\n                SOME thm => (trace_fallback thm; resolve_tac ctxt [thm] i st)\n              | NONE => Seq.empty  \n            else Seq.empty\n          )\n        | _ => Seq.empty)\n\n      val init_tac = CONVERSION (\n        Refine_Util.HOL_concl_conv (fn ctxt => (id_a_conv (protect_conv ctxt))) \n          ctxt\n      )\n\n      val step_tac = (FIRST' [\n        assume_tac ctxt, \n        eresolve_tac ctxt @{thms id_rule},\n        resolve_from_net_tac ctxt def_rl_net, \n        resolve_from_net_tac ctxt rl_net, \n        id_pr_const_rename_tac,\n        do_unprotect_tac ctxt, \n        fallback_tac])\n\n      val solve_tac = DF_SOLVE_FWD (Config.get ctxt cfg_id_debug) step_tac  \n\n    in\n      case ss of\n        Init => init_tac \n      | Step => step_tac \n      | Normal => init_tac THEN' solve_tac\n      | Solve => solve_tac\n\n    end\n\n  end\n\n\\<close>\n\nsubsection \\<open>Default Setup\\<close>\n\nsubsubsection \\<open>Numerals\\<close> \nlemma pat_numeral[def_pat_rules]: \"numeral$x \\<equiv> UNPROTECT (numeral$x)\" by simp\n\nlemma id_nat_const[id_rules]: \"(PR_CONST (a::nat)) ::\\<^sub>i TYPE(nat)\" by simp\nlemma id_int_const[id_rules]: \"(PR_CONST (a::int)) ::\\<^sub>i TYPE(int)\" by simp\n\n(*subsection \\<open>Example\\<close>\nschematic_lemma \n  \"ID (\\<lambda>a b. (b(1::int\\<mapsto>2::nat) |`(-{3})) a, Map.empty, \\<lambda>a. case a of None \\<Rightarrow> Some a | Some _ \\<Rightarrow> None) (?c) (?T::?'d itself)\"\n  (*\"TERM (?c,?T)\"*)\n  using [[id_debug]]\n  apply (tactic {* Id_Op.id_tac Id_Op.Normal @{context} 1  *})  \n  done\n*)\n\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Evaluation/Refine_Imperative_HOL/Sepref_Id_Op.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5736784220301065, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.2980381721884717}}
{"text": "theory spatial\nimports Main\nbegin\n\ndeclare [[ smt_timeout = 20 ]]\n\nabbreviation reflexive\n  where \"reflexive \\<equiv> \\<lambda> R. \\<forall> r. R r r\"\nabbreviation transitive\n  where \"transitive \\<equiv> \\<lambda> R. \\<forall> x. \\<forall> y. \\<forall> z. R x y \\<and> R y z \\<longrightarrow> R x z\"\nabbreviation symmetric\n  where \"symmetric \\<equiv> \\<lambda> R. \\<forall> x. \\<forall> y. R x y \\<longrightarrow> R y x\"\n\n\n(*The mutually recursive datatypes of processes and names*)\ndatatype P = Null             (\"\\<^bold>0\")\n           | Input n n P      (\"_\\<leftarrow>_._.\" 80)\n           | Lift n P         (\"_\\<triangleleft>_\\<triangleright>\" 80)\n           | Drop n           (\"\\<acute>_`\" 80)\n           | Par P P          (infixl \"\\<parallel>\" 75)    \n     and n = Quote P          (\"`_\\<acute>\")\ntermination\n  apply size_change\n  proof - qed\n\n(*Syntactic sugar for output on a channel*)\nabbreviation Output :: \"n \\<Rightarrow> n \\<Rightarrow> P\" (\"_[[_]]\")\n  where \"Output x y \\<equiv> x\\<triangleleft>\\<acute>y`\\<triangleright>\"\n\nvalue \"a[[b]]\"\nvalue \"zero \\<leftarrow> zero.\\<^bold>0\"\nvalue \"\\<^bold>0\\<parallel>\\<^bold>0\"\nvalue \"\\<acute>zero`\"\nvalue \"zero\\<triangleleft>\\<^bold>0\\<triangleright>\"\nvalue \"(c\\<leftarrow>d.(e))\"\n\n\nfun newName :: \"nat \\<Rightarrow> n\"\n  where \"newName 0 = `\\<^bold>0\\<acute>\"\n       |\"newName (Suc n) = `(Output (newName n) (newName n))\\<acute>\"\n\nabbreviation zero :: n\n  where \"zero \\<equiv> `\\<^bold>0\\<acute>\"\nabbreviation one :: n\n  where \"one \\<equiv> newName 1\"\nabbreviation two :: n\n  where \"two \\<equiv> newName 2\"\nabbreviation three :: n\n  where \"three \\<equiv> newName 3\"\nabbreviation four :: n\n  where \"four \\<equiv> newName 4\"\n\nabbreviation Zero :: P\n  where \"Zero \\<equiv> Null\"\nabbreviation One :: P\n  where \"One \\<equiv> \\<acute>one`\"\nabbreviation Two :: P\n  where \"Two \\<equiv> \\<acute>two`\"\nabbreviation Three :: P\n  where \"Three \\<equiv> \\<acute>three`\"\nabbreviation Four :: P\n  where \"Four \\<equiv> \\<acute>four`\" \n\nvalue \"zero \\<leftarrow> zero.\\<^bold>0.\"\nvalue \"\\<^bold>0\\<parallel>\\<^bold>0\"\nvalue \"\\<acute>zero`\"\nvalue \"zero\\<triangleleft>\\<^bold>0\\<triangleright>\"\nvalue \"(c\\<leftarrow>d.(e).)\"\n\nfun getList :: \"P \\<Rightarrow> P list\"\nwhere\n  \"getList \\<^bold>0 = []\"\n |\"getList (a\\<parallel>b) = ((getList a)@(getList b))\"\n |\"getList a = [a]\"\n\n(*\nfun la :: \"P \\<Rightarrow> P\"\nwhere\n  \"la (a\\<parallel>(b\\<parallel>c)) = ((la (a\\<parallel>b))\\<parallel>(la c))\"\n |\"la a = a\"\n\nvalue \"la (Null \\<parallel> (Null \\<parallel> (Null \\<parallel> (Null \\<parallel> Null))))\"\nvalue \"la ((Null \\<parallel> Null) \\<parallel> (Null \\<parallel> (Null \\<parallel> Null)))\"\n*)\n\nfunction congru :: \"P \\<Rightarrow> P \\<Rightarrow> bool\" (infixl \"=C\" 42)\n     and eq2 :: \"P list \\<Rightarrow> P list \\<Rightarrow> P list \\<Rightarrow> bool\"\nwhere\n   \"congru (a\\<parallel>b) (c\\<parallel>d)       = (eq2 (getList (a\\<parallel>b)) (getList (c\\<parallel>d)) [])\"\n  |\"congru (x\\<leftarrow>y.(a).) (xx\\<leftarrow>yy.(b).) = ((a =C b) \\<and> (x=xx) \\<and> (y = yy))\"\n  |\"congru (x\\<triangleleft>a\\<triangleright>) (y\\<triangleleft>b\\<triangleright>)     = ((a =C b) \\<and> (x = y))\"\n  |\"congru (\\<acute>a`) (\\<acute>b`)       = (a = b)\"\n  |\"congru Null Null         = True\"\n  |\"congru (a\\<parallel>b) Null        = ((a =C Null)\\<and>(b =C Null))\"\n  |\"congru Null (a\\<parallel>b)        = ((a =C Null)\\<and>(b =C Null))\"\n  |\"congru (a\\<parallel>b) (c\\<leftarrow>d.(e).)  = (eq2 (getList (a\\<parallel>b)) ((c\\<leftarrow>d.(e).)#[]) [])\"\n  |\"congru (c\\<leftarrow>d.(e).) (a\\<parallel>b)  = (eq2 (getList (a\\<parallel>b)) ((c\\<leftarrow>d.(e).)#[]) [])\"\n  |\"congru (a\\<parallel>b) (c\\<triangleleft>d\\<triangleright>)      = (eq2 (getList (a\\<parallel>b)) ((c\\<triangleleft>d\\<triangleright>)#[]) [])\"\n  |\"congru (c\\<triangleleft>d\\<triangleright>) (a\\<parallel>b)      = (eq2 (getList (a\\<parallel>b)) ((c\\<triangleleft>d\\<triangleright>)#[]) [])\"\n  |\"congru (a\\<parallel>b) (\\<acute>c`)       = (eq2 (getList (a\\<parallel>b)) ((\\<acute>c`)#[]) [])\"\n  |\"congru (\\<acute>c`) (a\\<parallel>b)       = (eq2 (getList (a\\<parallel>b)) ((\\<acute>c`)#[]) [])\"\n\n  (* for f*cks sake, why cant I have some statement for remaining cases? *)\n  |\"congru (\\<acute>a`) Null        = False\"\n  |\"congru Null (\\<acute>b`)        = False\"\n  |\"congru (\\<acute>a`) (_\\<leftarrow>_._.)    = False\"\n  |\"congru (_\\<leftarrow>_._.) (\\<acute>b`)    = False\"\n  |\"congru (\\<acute>a`) (_\\<triangleleft>_\\<triangleright>)      = False\"\n  |\"congru (_\\<triangleleft>_\\<triangleright>) (\\<acute>b`)      = False\"\n  |\"congru (_\\<triangleleft>_\\<triangleright>) Null       = False\"\n  |\"congru Null (_\\<triangleleft>_\\<triangleright>)       = False\"\n  |\"congru (_\\<triangleleft>_\\<triangleright>) (_\\<leftarrow>_._.)   = False\"\n  |\"congru (_\\<leftarrow>_._.) (_\\<triangleleft>_\\<triangleright>)   = False\"\n  |\"congru (_\\<leftarrow>_._.) Null     = False\"\n  |\"congru Null (_\\<leftarrow>_._.)     = False\"\n\n  |\"eq2 [] [] [] = True\"\n  |\"eq2 (x#xs) [] [] = False\"\n  |\"eq2 [] [] (a#as) = False\"\n  |\"eq2 (x#xs) [] (b#bs) = False\"\n  |\"eq2 [] (b#bs) _ = False\"\n  |\"eq2 (x#xs) (y#ys) zs = (if (x =C y) then (eq2 xs (zs@ys) []) else (eq2 (x#xs) ys (y#zs)))\"\nby (auto, pat_completeness)\n\n(* \n  in order to proof the termination I'd need to find a measure function\n  the bad part is that i need to prove the termination of this counting function as well\n *)\n\nabbreviation maxl where \"maxl \\<equiv> \\<lambda>l. foldl (\\<lambda>a.\\<lambda>b. (max a b)) 0 l\"\n\nfun sdepth :: \"P \\<Rightarrow> nat\" where\n  \"sdepth Null = 0\"\n  | \"sdepth (x \\<leftarrow> y . P.) = 1 + sdepth P\"\n  | \"sdepth (x \\<triangleleft> P \\<triangleright>) = 1 + sdepth P\"\n  | \"sdepth (P \\<parallel> Q) = 1 + (max (sdepth P) (sdepth Q))\"\n  | \"sdepth (\\<acute>x`) = 0\"\n\nfun di::\"nat \\<Rightarrow> nat\" where \n  \"di 0 = 0\"\n| \"di (Suc(Suc v)) = (Suc (di v))\"\n\n\nabbreviation llength where \"llength \\<equiv> \\<lambda>x::P list. (di ((length x)*(length x + 1)))\"\n\n\nfunction\n  depth :: \"P \\<Rightarrow> nat\"\nwhere\n  \"depth \\<^bold>0 = 0\"\n  | \"depth (x \\<leftarrow> y . P.) = 1 + depth P\"\n  | \"depth (x \\<triangleleft> P \\<triangleright>) = 1 + depth P\"\n  | \"depth (P \\<parallel> Q) = 1 + (maxl (map depth (getList (P\\<parallel>Q)))) + llength (getList (P\\<parallel>Q))\"\n  | \"depth (\\<acute>x`) = 0\"\napply auto\napply pat_completeness\ndone\ntermination\napply (relation \"measure (\\<lambda>x.(sdepth x))\")\napply auto\n(*proof -\n  fix P Q x\n  assume \"x\\<in> set (getList P)\"\n  show \"sdepth x < Suc (max (sdepth P) (sdepth Q))\"\n  (* damn it, so close *)*)\nsorry\n\ntermination congru\n(* cannot come up with a good measuring function without *)\napply (relation \"measure (\n\\<lambda>x. case x of \n  Inl (a,b) \n    \\<Rightarrow> (Max({depth a, depth b})) \n| Inr (a,b,c) \n    \\<Rightarrow> max (maxl (map depth (a))) (maxl (map depth (b@c))) )\")\napply auto\nsorry\n\n\nvalue \"(( \\<^bold>0 \\<parallel> (n\\<^sub>1\\<triangleleft>\\<^bold>0 \\<parallel> \\<^bold>0\\<triangleright>)) =C (n\\<^sub>1\\<triangleleft>\\<^bold>0\\<triangleright>))\"\n\n\n\n(*\ntheorem eqReflexive:\n  assumes \"reflexive congru\"\n  shows \"reflexive eq\"\nproof \n  fix r\n  show \"eq r r\"\n  proof (induction r)\n    show \"eq [] []\" by simp\n  next\n    fix a r\n    assume eqr: \"eq r r\"\n    show \"eq (a#r) (a#r)\"\n    proof auto\n      assume \"a =C a\"\n      show \"eq2 r r []\" using eqr by auto\n    next\n      assume na: \"\\<not> a =C a\"\n      show \"eq2 (a#r) r [a]\"\n      proof -\n       (* assume req: \"reflexive eq\"\n        from this req have \"reflexive congru\" by (meson assms eq.elims(2) eq2.simps(4) eq2.simps(6))*)\n        from assms have \"a =C a\" by simp\n        from this na show \"eq2 (a#r) r [a]\" by simp (* i want to prove this through contradiction *)\n      qed\n    qed\n  qed  \nqed\n\nlemma \"getList r = getList r\" by simp\n*)\n\n(*\nlemma listtocongru:\n  assumes \"eq2 (getList a) (getList a) []\"\n  shows \"a =C a\"\n  apply (induction a)\n  apply auto\n  proof -\n    fix a1 a2\n    assume \"a1 =C a1\" and \"a2 =C a2\"\n    show \"eq2 (getList a1 @ getList a2) (getList a1 @ getList a2) []\"\n    apply (induction a1)\n    apply auto    \nsorry\n*)\n\n(*\nlemma congrutolist:\n  assumes \"a =C a\"\n  shows \"eq2 (getList a) (getList a) []\"\n  apply (induction a)\n  apply auto\n  apply (simp add: listtocongru)\n  apply (simp add: listtocongru) \n  proof -\n    fix a1 a2\n    assume h1: \"eq2 (getList a1) (getList a1) []\"\n    assume h2: \"eq2 (getList a2) (getList a2) []\"\n    show \"eq2 (getList a1 @ getList a2) (getList a1 @ getList a2) []\"\n    apply (induction a1)\n    apply auto\n    apply (simp add: h1 h2)\n    apply (simp add: h1 h2)\n    proof (rule ccontr)\n      fix x1 x2a a1\n      assume \"eq2 (getList a1 @ getList a2) (getList a1 @ getList a2) []\"\n      assume \"\\<not> a1 =C a1\"\n      from assms have \"a1 =C a1\"\n\nsorry\n\nlemma partolist:\n  assumes \"a =C a\" and \"b =C b\"\n  shows \"eq2 ((getList a)@(getList b)) ((getList a)@(getList b)) []\"\nsorry\n*)\n(*\n  proof (auto, induction r1)\n      show \"eq2 (getList \\<^bold>0 @ getList r2) (getList \\<^bold>0 @ getList r2) []\"\n      apply auto\n      apply (simp add: congrutolist b)\n      done\n    next\n      fix x1 x2a::n\n      fix P2:: \"n \\<Rightarrow> bool\"\n      assume \"P2 x1\"\n      assume \"P2 x2a\"\n      assume \"eq2 (getList r1 @ getList r2) (getList r1 @ getList r2) []\" \n      show \"eq2 (getList (x1\\<leftarrow>x2a.(r1)) @ getList r2) (getList (x1\\<leftarrow>x2a.(r1)) @ getList r2) []\"\n      proof -\n*)\n\n\n(*\ntheorem asdadsds:\n  assumes \"\\<forall> a. a =C a\"\n  shows \"eq (getList a) (getList a)\"\n  apply auto\n  apply (induction a)\n  apply auto\n  apply (simp add: listtocongru)\n  apply (simp add: listtocongru) \n  proof -\n    fix a1 a2\n    assume h1: \"eq2 (getList a1) (getList a1) []\"\n    assume h2: \"eq2 (getList a2) (getList a2) []\"\n    show \"eq2 (getList a1 @ getList a2) (getList a1 @ getList a2) []\"\n    apply (induction a1)\n    apply auto\n    apply (simp add: h1 h2)\n    apply (simp add: h1 h2)\n    proof (rule ccontr)\n      fix x1 x2a a1\n      assume \"eq2 (getList a1 @ getList a2) (getList a1 @ getList a2) []\"\n      assume \"\\<not> a1 =C a1\"\n      from assms have \"a1 =C a1\"\n    sledgehammer\n*)\n(*\ntheorem congruReflexive:\n  shows \"reflexive congru\"\n  and \"\\<forall>b::P. eq2 (getList b) (getList b) []\"\nproof auto\n  fix r\n  fix b::P\n  show \"r =C r\"  \"eq2 (getList r) (getList r) []\"\n  apply (induct r)\n  apply auto\n  proof -\n    show \"Null =C Null\" by simp\n  next\n    fix x1 x2a r2\n    assume \"r2 =C r2\"\n    show \"(Input x1 x2a r2 =C Input x1 x2a r2)\" by (simp add: \\<open>r2 =C r2\\<close>)\n  next\n    fix x1 r2\n    assume a:\"r2 =C r2\"\n    show \"(x1\\<triangleleft>r2\\<triangleright>) =C (x1\\<triangleleft>r2\\<triangleright>)\" by (simp add: a)\n  next\n    fix x\n    show \"\\<acute>x` =C \\<acute>x`\" by simp\n  next\n    fix r1 r2\n    assume a: \"r1 =C r1\" and b: \"r2 =C r2\"\n    show \"(r1\\<parallel>r2) =C (r1\\<parallel>r2)\"\n    apply auto\n    apply (simp add: a b partolist)\n    done\n  next\n    (* I have no idea what I have to show here!? *)\n    fix r2\n    fix P2::\"n \\<Rightarrow> bool\"\n    assume \"r2 =C r2\"\n    show \"P2 `r2\\<acute>\"\n    sorry\n  next\n  qed\nqed\n*)\n\n\ntheorem congruReflexive:\n  shows \"reflexive congru\"\nsorry\n\ntheorem congruTransitive:\n  shows \"transitive congru\"\nsorry\n\ntheorem congruSymmetric:\n  shows \"symmetric congru\"\nsorry\n\ntheorem eqReflexive:\n  shows \"\\<forall> a b. (eq2 a a [])\"\nsorry\n\ntheorem eqSymmetric:\n  shows \"\\<forall> a b. (eq2 a b [] \\<longrightarrow> eq2 b a [])\"\nsorry\n\ntheorem eqTransitive:\n  shows \"\\<forall> a b c. (((eq2 a b []) \\<and> (eq2 b c [])) \\<longrightarrow> (eq2 a c []))\"\nsorry\n\ntheorem parAssoc:\n  shows \"((a\\<parallel>b)\\<parallel>c) =C (a\\<parallel>(b\\<parallel>c))\"\nsorry\n\ntheorem parKommutative:\n  shows \"a\\<parallel>b =C b\\<parallel>a\"\nsorry\n\ntheorem zeroLeft:\n  shows \"(Null \\<parallel> a) =C a\"\nsorry\n\ntheorem zeroRight:\n  shows \"(a \\<parallel> Null) =C a\"\nsorry\n\ntheorem someshit:\nshows \"(((zero\\<leftarrow>zero.\\<^bold>0.) \\<parallel> \\<^bold>0) \\<parallel> (zero\\<leftarrow>zero.\\<^bold>0.)) =C (((zero\\<leftarrow>zero.\\<^bold>0.) \\<parallel> (zero\\<leftarrow>zero.\\<^bold>0.)) \\<parallel> \\<^bold>0)\"\nby simp\n\nvalue \"getList ((a \\<parallel> b) \\<parallel> c)\"\nvalue \"(((zero\\<leftarrow>zero.\\<^bold>0.) \\<parallel> \\<^bold>0) \\<parallel> (zero\\<leftarrow>zero.\\<^bold>0.)) =C (((zero\\<leftarrow>zero.\\<^bold>0.) \\<parallel> (zero\\<leftarrow>zero.\\<^bold>0.)) \\<parallel> \\<^bold>0)\"\n\n\n(*Name equivalence*)\nfun name_equivalence :: \"n \\<Rightarrow> n \\<Rightarrow> bool\" (infix \"=N\" 52)\n  where \n    \"zero =N `Input x y P\\<acute> = False\"\n  | \"zero =N `Lift _ _\\<acute> = False\"\n  | \"zero =N `Par P Q\\<acute> = (Null =C (P\\<parallel>Q))\"\n  | \"zero =N `\\<acute>a`\\<acute> = (zero =N a)\"\n  | \"zero =N zero = True\"\n\n  | \"((`(Input x y P)\\<acute>) =N `Input p q Q\\<acute>) = ((Input x y P)  =C (Input p q Q))\"\n  | \"((`(Input x y P)\\<acute>) =N `Lift _ _\\<acute>) = False\"\n  | \"((`(Input x y P)\\<acute>) =N `Par _ _\\<acute>) = False\"\n  | \"((`(Input x y P)\\<acute>) =N zero) = False\"\n  | \"((`(Input x y P)\\<acute>) =N `\\<acute>a`\\<acute>) = (`(Input x y P)\\<acute> =N a)\"\n\n  | \"((`Lift x P\\<acute>) =N `Lift y Q\\<acute>) = (Lift x P =C Lift y Q)\"\n  | \"((`Lift x P\\<acute>) =N `Input _ _ _\\<acute>) = False\"\n  | \"((`Lift x P\\<acute>) =N `Par _ _\\<acute>) = False\"\n  | \"((`Lift x P\\<acute>) =N zero) = False\"\n  | \"((`Lift x P\\<acute>) =N `\\<acute>a`\\<acute>) = (`(Lift x P)\\<acute> =N a)\"\n\n  | \"((`P\\<parallel>Q\\<acute>) =N (`A\\<parallel>B\\<acute>)) = ((P\\<parallel>Q) =C (A\\<parallel>B))\"\n  | \"((`P\\<parallel>Q\\<acute>) =N (`Lift _ _\\<acute>)) = False\"\n  | \"((`P\\<parallel>Q\\<acute>) =N (`Input _ _ _\\<acute>)) = False\"\n  | \"((`P\\<parallel>Q\\<acute>) =N zero) = ((P\\<parallel>Q) =C Null)\"\n  | \"((`P\\<parallel>Q\\<acute>) =N (`\\<acute>a`\\<acute>)) = (`(P\\<parallel>Q)\\<acute> =N a)\"\n\n  | \"`\\<acute>a`\\<acute> =N `Input x y P\\<acute> = (a =N `Input x y P\\<acute>)\"\n  | \"`\\<acute>a`\\<acute> =N `Lift x P\\<acute> = (a =N `Lift x P\\<acute>)\"\n  | \"`\\<acute>a`\\<acute> =N `Par P Q\\<acute> = (a =N `Par P Q\\<acute>)\"\n  | \"`\\<acute>a`\\<acute> =N `\\<acute>b`\\<acute> = (a =N b)\"\n  | \"`\\<acute>a`\\<acute> =N zero = (a =N zero)\"\n\n\nvalue \"`\\<acute>zero`\\<acute> =N zero\"\nvalue \"`\\<acute>`\\<acute>zero`\\<acute>`\\<acute> =N zero\"\nvalue \"newName 3 =N three\"\nvalue \"newName 3 =N zero\"\nvalue \"three =N newName 3\"\nvalue \"`((One\\<parallel>Two)\\<parallel>(Three\\<parallel>Four))\\<parallel>Null\\<acute> =N `((One\\<parallel>Three)\\<parallel>(Two\\<parallel>Four))\\<acute>\"\n\ntheorem name_equivalence_reflexive:\n  shows \"reflexive name_equivalence\"\napply auto\nproof -\n  fix r\n  show \"r =N r\"\n  using congruReflexive by (induction r rule: name_equivalence.induct, auto)\nqed\n\ntheorem name_equivalence_symmetric:\n  assumes \"x =N y\"\n  shows \"y =N x\"\nusing assms congruSymmetric eqSymmetric by (induct x rule: name_equivalence.induct, auto)\n\ntheorem name_equivalence_transitive:\n  assumes \"a =N b\" and \"b =N c\"\n  shows \"a =N c\"\n(* I dont know how to make an induction argument here which runs over all three variables *)\n(*\nusing assms apply (induct a c rule: name_equivalence.induct)\napply auto\napply (simp add: assms congruTransitive eqTransitive)\n*)\nsorry\n\n\nvalue \"`p \\<parallel> (\\<^bold>0 \\<parallel> q)\\<acute> =N `q \\<parallel> p\\<acute>\"\n\ntheorem testNameEQ1:\n  shows \"`p \\<parallel> (\\<^bold>0 \\<parallel> q)\\<acute> =N `q \\<parallel> p\\<acute>\"\nusing parKommutative by auto\n\n(*Gives the set of free names in a process*)\nfun free :: \"P \\<Rightarrow> n set\" where\n  \"free \\<^bold>0 = {}\"\n  | \"free (x \\<leftarrow> y . P.) = {x} \\<union> (free(P) - {y})\"\n  | \"free (x \\<triangleleft> P \\<triangleright>) = {x} \\<union> free P\"\n  | \"free (P \\<parallel> Q) = free P \\<union> free Q\"\n  | \"free (\\<acute>x`) = {x}\"\n\n(*Gives the set of bound names in a process*)\nfun bound :: \"P \\<Rightarrow> n set\" where\n  \"bound \\<^bold>0 = {}\"\n  | \"bound (x \\<leftarrow> y . P.) = {y} \\<union> bound(P)\"\n  | \"bound (x \\<triangleleft> P \\<triangleright>) = bound P\"\n  | \"bound (P \\<parallel> Q) = bound P \\<union> bound Q\"\n  | \"bound (\\<acute>x`) = {}\"\n\n(*Names occurring in a process*)\nfun names :: \"P \\<Rightarrow> n set\"\n  where \"names P = free(P) \\<union> bound(P)\"\n\n(*quote depth*)\nfunction n_depth :: \"n \\<Rightarrow> nat\" (\"#\" 60) \n  and P_depth :: \"P \\<Rightarrow> nat\" (\"#\" 60)\n  where\n  \"n_depth `P\\<acute> = 1 + (P_depth P)\"\n  | \"P_depth P = (if (names P \\<noteq> {}) then Max({ ( n_depth x ) | x. x \\<in> (names P)}) else 0)\"\n  apply pat_completeness\n  apply blast\n  apply simp\n  by blast\ntermination\n  sorry  (*Even without termination proof, we can use the n_depth/P_depth function*)\n\nvalue \"P_depth (\\<acute>zero`)\"\n\n\n(*substitution*)\n(*Takes a process, specifies the names to be substituted and returns a process*)\n\nabbreviation sn :: \"n \\<Rightarrow> n \\<Rightarrow> n \\<Rightarrow> n\" where\n  \"sn x q p \\<equiv> (if (x =N p) then q else x)\" \n\nvalue \"(sn zero zero zero)\"\nvalue \"newName (Max ({(n_depth zero), 0::nat}))\"\n\n(*with z = (newName (P_depth(R)))*)\nabbreviation genz\n  where \"genz \\<equiv> \\<lambda> q::n.  \\<lambda> p::n. \\<lambda> R::P. newName (Max({(n_depth(q)), (P_depth(R)), (n_depth(p)) }))\"\n  \n(* syntactic substitution *)\nfunction s :: \"P \\<Rightarrow> n \\<Rightarrow> n \\<Rightarrow> P\" (\"(_) {_\\<setminus>_}\" 52)\nwhere \"(\\<^bold>0){_\\<setminus>_}             = \\<^bold>0\"\n   | \"(R \\<parallel> S){q\\<setminus>p}          = ((R){q\\<setminus>p}) \\<parallel> ((S){q\\<setminus>p})\" \n   | \"( x \\<leftarrow> y . R.){q\\<setminus>p}    = ((sn x q p) \\<leftarrow> (genz q p R)  . ((R {(genz q p R)\\<setminus>y}){q\\<setminus>p}).)\"  \n   | \"(x \\<triangleleft> R \\<triangleright>) {q\\<setminus>p}       = ((sn x q p) \\<triangleleft>R{q\\<setminus>p}\\<triangleright>)\"\n   | \"(\\<acute>x`){q\\<setminus>p}            = (if (x =N p) then \\<acute>q` else \\<acute>x`)\"\napply pat_completeness by auto\ntermination\napply (relation \"measure (\\<lambda>(p,x,y). (P_depth p))\", auto)\n\n(* see http://isabelle.in.tum.de/doc/functions.pdf *)\n  sorry (*induction measure on n_depth*)\n  \n(* semantic substitution *)\nfunction ss :: \"P \\<Rightarrow> n \\<Rightarrow> n \\<Rightarrow> P\" (\"(_) s{_\\<setminus>_}\" 52)\nwhere \"(\\<^bold>0)s{_\\<setminus>_}             = \\<^bold>0\"\n   | \"(R \\<parallel> S) s{q\\<setminus>p}          = ((R) s{q\\<setminus>p}) \\<parallel> ((S) s{q\\<setminus>p})\" \n   | \"( x \\<leftarrow> y . R.) s{q\\<setminus>p}    = ((sn x q p) \\<leftarrow> (genz q p R)  . ((R {(genz q p R)\\<setminus>y}) s{q\\<setminus>p}).)\"  \n   | \"(x \\<triangleleft> R \\<triangleright>) s{q\\<setminus>p}       = ((sn x q p) \\<triangleleft>R s{q\\<setminus>p}\\<triangleright>)\"\n   | \"(\\<acute>x`) s{`q\\<acute>\\<setminus>p}            = (if (x =N p) then q else \\<acute>x`)\" (* semantic substitution *)\napply pat_completeness by auto\ntermination\napply (relation \"measure (\\<lambda>(p,x,y). (P_depth p))\", auto)\n\n(* see http://isabelle.in.tum.de/doc/functions.pdf *)\n  sorry (*induction measure on n_depth*)\n\nvalue \"\\<^bold>0{zero\\<setminus>zero}\"\nvalue \"(zero \\<leftarrow> zero . Zero){two \\<setminus> zero}\"\nvalue \"(\\<^bold>0 \\<parallel> (\\<acute>zero`)) { (newName 2) \\<setminus> zero }\"\n\n(*\n 2.6 Dynamic quote: an example\n*)\n\nvalue \"zero\\<triangleleft>zero[[three]]\\<triangleright>{two\\<setminus>three}\"\nvalue \"(zero\\<triangleleft>zero[[three]]\\<triangleright>{two\\<setminus>three}) = (zero\\<triangleleft>zero[[two]]\\<triangleright>)\"\n\nvalue \"zero[[`zero[[three]]\\<acute>]]{two\\<setminus>three}\"\nvalue \"zero[[`zero[[three]]\\<acute>]]{two\\<setminus>three} = (zero[[`zero[[three]]\\<acute>]])\"\n\n(* Operational Semantics *)\n\nfun toPar:: \"P list \\<Rightarrow> P\" where\n  \"toPar []   = Null\"\n |\"toPar (x#[]) = x\"\n |\"toPar (x#y#xs) = (x \\<parallel> (toPar (y#xs)))\"\n\n\n\nfun syncable:: \"P \\<Rightarrow> P \\<Rightarrow> bool\" where\n  \"syncable (Lift x Q) (Input y z P)    = (x =N z)\"\n |\"syncable (Input y z P) (Lift x Q)    = (x =N z)\"\n |\"syncable (Lift y P) (Lift x Q)       = False\"\n |\"syncable (Input y z P) (Input a b Q) = False\"\n |\"syncable _ (vc \\<parallel> vd)                 = False\"\n |\"syncable   (vc \\<parallel> vd) _               = False\"\n |\"syncable   (\\<acute>v`) _                   = False\"\n |\"syncable _ (\\<acute>v`)                     = False\"\n |\"syncable   Null _                    = False\"\n |\"syncable _ Null                      = False\"\n\nfun sync:: \"P \\<Rightarrow> P \\<Rightarrow> P\" where\n  \"sync (Lift x Q) (Input y z P) = (P s{`Q\\<acute>\\<setminus>y})\"\n |\"sync (Input y z P) (Lift x Q) = (P s{`Q\\<acute>\\<setminus>y})\"\n\nfunction fineRun:: \"P list \\<Rightarrow> P list \\<Rightarrow> P list \\<Rightarrow> P list\" where\n   \"fineRun []     []  []         = []\"\n  |\"fineRun (x#[]) []  []         = (x#[])\"\n  |\"fineRun (x#y#xs) []  zs       = (fineRun (y#xs) (x#[]) zs)\"\n  |\"fineRun [] (y#ys) (z#[])      = (z#y#ys)\"\n  |\"fineRun [] (y#ys) (z#zs)      = (fineRun zs (z#y#ys) [])\"\n  |\"fineRun (x#xs) (y#ys) zs      = (if (syncable x y) then ((sync x y)#xs@ys@zs) else (fineRun (xs) (y#ys) (x#zs)))\"\napply auto\nsorry\ntermination\nsorry\n\nfun step:: \"P \\<Rightarrow> P\" where\n  \"step P = toPar( fineRun (getList P) [] [])\"\n\n\nabbreviation replication where \"replication \\<equiv> (\\<lambda>y.\\<lambda>(P,x).(x\\<triangleleft>((y\\<leftarrow>x.(x[[y]]\\<parallel>\\<acute>y`).)\\<parallel>P)\\<triangleright>\\<parallel>(y \\<leftarrow> x.(x[[y]]\\<parallel>\\<acute>y`).)))(`zero[[zero]]\\<acute>)\"\nabbreviation xx where \"xx \\<equiv> zero\"\nabbreviation yy where \"yy \\<equiv> `xx[[xx]]\\<acute>\"\n\nvalue \"(replication (two, zero))\"\nvalue \"step (replication (two, zero))\"\nvalue \"step(step (replication (two, zero)))\"\nvalue \"step(step(step (replication (two, zero))))\"\nvalue \"step(step(step(step (replication (two, zero)))))\"\n\n\nlemma False\nsledgehammer\n(*theory is consistent, yay*)\noops\n\nsection\\<open>Alpha equivalence\\<close>\ntext\\<open>Alpha equivalence equates processes that only differ by their bound variables. In our calculus,\nthe bound variables are the names to which we bound input values. As an example we would want the \nfollowing terms to be alpha-equal: \\<close>\n\n(*\ntheorem alphaEq: \nshows \"zero \\<leftarrow> zero . Zero \\<equiv>\\<alpha> one \\<leftarrow> zero . Zero\"\nsorry\n*)\n\nend", "meta": {"author": "MrChico", "repo": "CompMeta", "sha": "6ea156d26df6feaac10d652a3743252f7112655a", "save_path": "github-repos/isabelle/MrChico-CompMeta", "path": "github-repos/isabelle/MrChico-CompMeta/CompMeta-6ea156d26df6feaac10d652a3743252f7112655a/proj/spatial.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.29803816461509924}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory ArraysMemInstance\nimports Arrays CompoundCTypes\nbegin\n\nprimrec\n  array_tag_n :: \"nat \\<Rightarrow> ('a::c_type,'b::finite) array typ_info\"\nwhere\n  atn_base:\n  \"array_tag_n 0 = ((empty_typ_info (typ_name (typ_uinfo_t TYPE('a)) @ ''_array_'' @\n      nat_to_bin_string (CARD('b::finite))))::('a::c_type,'b) array\n          typ_info)\"\n| atn_rec:\n  \"array_tag_n (Suc n) = ((ti_typ_combine TYPE('a::c_type)\n      (\\<lambda>x. index x n) (\\<lambda>x f. update f n x) (replicate n CHR ''1'')\n          (array_tag_n n))::('a,'b::finite) array typ_info)\"\n\ndefinition\n  array_tag :: \"('a::c_type,'b::finite) array itself \\<Rightarrow> ('a,'b) array typ_info\" where\n  \"array_tag t \\<equiv> array_tag_n (CARD('b))\"\n\ninstantiation array :: (c_type,finite) c_type\nbegin\ninstance ..\nend\n\noverloading typ_info_array \\<equiv> typ_info_t begin\ndefinition\n  typ_info_array: \"typ_info_array (w::('a::c_type,'b::finite) array itself) \\<equiv> array_tag w\"\nend\n\nlemma field_names_array_tag_length [rule_format]:\n  \"x \\<in> set (field_names_list (array_tag_n n)) \\<longrightarrow> length x < n\"\napply(induct_tac n)\n apply simp\napply clarsimp\ndone\n\nlemma replicate_mem_field_names_array_tag [simp]:\n  \"replicate n x \\<notin> set (field_names_list (array_tag_n n))\"\napply clarsimp\napply(drule field_names_array_tag_length)\napply simp\ndone\n\nlemma aggregate_array_tag [simp]:\n  \"aggregate (array_tag_n n)\"\napply(case_tac n)\n apply simp+\ndone\n\nlemma wf_desc_array_tag [simp]:\n  \"wf_desc ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info)\"\napply(induct_tac n)\n apply simp+\napply(erule wf_desc_ti_typ_combine)\napply simp\ndone\n\nlemma wf_size_desc_array_tag [simp, rule_format]:\n  \"0 < n \\<longrightarrow> wf_size_desc ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info)\"\napply(induct n)\n apply simp+\napply(case_tac \"n=0\")\n apply simp\napply(rule wf_size_desc_ti_typ_combine)\napply simp\ndone\n\nlemma g_ind_array_tag_udpate [simp]:\n  \"n \\<le> m \\<longrightarrow> n \\<le> CARD('b) \\<longrightarrow>\n      g_ind (lf_set ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info) []) (\\<lambda>x f. update f m x)\"\napply(induct_tac n)\n apply clarsimp+\napply(erule g_ind_ti_typ_combine)\n apply clarsimp+\ndone\n\nlemma fc_array_tag_udpate [simp]:\n  \"n \\<le> m \\<longrightarrow> n \\<le> CARD('b) \\<longrightarrow>\n      fu_commutes (update_ti_t ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info)) (\\<lambda>x f. update f m x)\"\napply(induct_tac n)\n apply clarsimp+\napply(erule fc_ti_typ_combine)\n  apply(clarsimp simp: fg_cons_def)\n apply clarsimp+\ndone\n\nlemma f_ind_array_tag_udpate [simp, rule_format]:\n  \"n \\<le> m \\<longrightarrow> m < CARD('b) \\<longrightarrow>\n      f_ind (\\<lambda>x. index x m) (lf_fd ` lf_set ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info) [])\"\napply(induct_tac n)\n apply clarsimp+\napply(erule f_ind_ti_typ_combine)\n apply clarsimp\napply simp\ndone\n\nlemma fa_fu_g_array_tag_udpate [simp, rule_format]:\n  \"n \\<le> m \\<longrightarrow> m < CARD('b) \\<longrightarrow>\n      fa_ind (lf_fd ` lf_set ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info) []) (\\<lambda>x f. update f m x)\"\napply(induct_tac n)\n apply clarsimp+\napply(erule fa_ind_ti_typ_combine)\napply clarsimp+\ndone\n\nlemma wf_fdp_array_tag [simp, rule_format]:\n  \"n \\<le> CARD('b) \\<longrightarrow>\n      wf_lf (lf_set ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info) [])\"\napply(induct_tac n)\n apply clarsimp+\napply(erule wf_lf_ti_typ_combine)\n      apply simp+\ndone\n\nlemma upd_local_update [simp]:\n  \"upd_local (\\<lambda>x f. update f n x)\"\napply(auto simp: upd_local_def)\napply(subst cart_eq)\napply clarsimp\napply(subst (asm) cart_eq)\napply(drule_tac x=i in spec)\napply clarsimp\napply(case_tac \"i=n\")\n apply simp+\ndone\n\nlemma fu_eq_mask_array_tag [simp, rule_format]:\n  \"n \\<le> CARD('b) \\<longrightarrow> (\\<forall>m. (\\<forall>k v. k < CARD('b) \\<longrightarrow>\n      index ((m v)::('a,'b) array) k = (if n \\<le> k then\n          index (undefined::('a::mem_type,'b::finite) array) k\n          else index v k)) \\<longrightarrow> fu_eq_mask (array_tag_n n) m)\"\napply(induct n)\n apply clarsimp\n apply(rule fu_eq_mask_empty_typ_info)\n apply clarsimp\n apply(subst cart_eq)\n apply simp\napply clarsimp\napply(rule fu_eq_mask_ti_typ_combine)\n     apply(drule_tac x=\"\\<lambda>v. update (m v) n (index undefined n)\" in spec)\n     apply(erule impE)\n      apply clarsimp\n      apply(drule_tac x=k in spec)\n      apply clarsimp\n      apply(case_tac \"k=n\")\n       apply simp\n      apply clarsimp\n     apply(subgoal_tac \"\\<forall>v bs. m (update v n bs) = update (m v) n bs\")\n      apply clarsimp+\n     apply(subst cart_eq)\n     apply clarsimp\n     apply(drule_tac x=i in spec)\n     apply clarsimp\n     apply(case_tac \"i=n\")\n      apply clarsimp+\n     apply(frule_tac x=\"update v n bs\" in spec)\n     apply(drule_tac x=\"v\" in spec)\n     apply clarsimp\n     apply(case_tac \"Suc n \\<le> i\")\n      apply clarsimp+\n    apply(clarsimp simp: fg_cons_def)\n   apply(clarsimp)\n  apply simp\ndone\n\nlemma size_td_array_tag [simp]:\n  \"size_td (((array_tag_n n)::('a,'b::finite) array typ_info)) =\n      n * size_of TYPE('a::c_type)\"\napply(induct_tac n)\n apply simp\napply simp\napply(simp add: size_td_lt_ti_typ_combine size_of_def)\ndone\n\nlemma align_td_array_tag [rule_format]:\n  \"0 < n \\<longrightarrow> align_td ((array_tag_n n)::('a,'b::finite) array typ_info) = (align_td (typ_info_t (TYPE('a::c_type))))\"\napply(induct_tac n)\n apply simp\napply(clarsimp simp: ti_typ_combine_def Let_def)\napply(case_tac \"n = 0\")\n apply(clarsimp simp: align_of_def max_def)+\ndone\n\nlemma align_field_array [simp]:\n  \"align_field ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info)\"\napply(induct_tac n)\n apply simp\napply clarsimp\napply(erule align_field_ti_typ_combine)\napply simp\napply(rule dvd_mult)\napply(subgoal_tac \"align_of TYPE('a) dvd size_of TYPE('a)\")\n apply(simp add: align_of_def)\napply(rule align_size_of)\ndone\n\ninstantiation array :: (mem_type,finite) mem_type_sans_size\nbegin\n\ninstance\napply intro_classes\n     apply(simp_all add: typ_info_array array_tag_def size_of_def\n                         norm_bytes_def)\n\n apply clarsimp\n apply(rule fu_eq_mask)\n  apply(simp add: size_of_def)\n apply(rule fu_eq_mask_array_tag)\n    apply simp+\n\napply(clarsimp simp: align_of_def typ_info_array array_tag_def)\napply(subst align_td_array_tag)\n apply simp\napply(rule dvd_trans)\n apply(subgoal_tac \"align_of TYPE('a) dvd size_of TYPE('a)\")\n  apply(simp only: align_of_def)\n apply(rule align_size_of)\napply(simp add: size_of_def)\ndone\n\nend\n\ndeclare atn_base [simp del]\ndeclare atn_rec [simp del]\n\nlemma size_of_array [simp]:\n  \"size_of TYPE(('a,'b::finite) array) = CARD('b) * size_of TYPE('a::c_type)\"\n  by (simp add: size_of_def typ_info_array array_tag_def)\n\nlemma size_td_array:\n  \"size_td (typ_info_t TYPE(('a,'b::finite) array)) = CARD('b) * size_of TYPE('a::c_type)\"\n  by (simp add: size_of_def typ_info_array array_tag_def)\n\nlemma align_td_array:\n  \"2^align_td (typ_info_t TYPE(('a,'b::finite) array)) = align_of TYPE('a::c_type)\"\napply(simp add: align_of_def typ_info_array array_tag_def)\napply(subst align_td_array_tag)\n apply simp+\ndone\n\n(* Showing arrays are in mem_type requires maximum sizes for objects,\n   and maximum counts for elements *)\nclass oneMB_size = mem_type +\n  assumes oneMB_size_ax: \"size_of TYPE('a::c_type) < 2 ^ 19\"\n\nclass fourthousand_count = finite +\n  assumes fourthousand_count_ax: \"CARD ('a) <= 2 ^ 13\"\n\ninstantiation array :: (oneMB_size, fourthousand_count) mem_type\nbegin\n\ninstance\napply intro_classes\napply simp\napply (subgoal_tac \"addr_card = 2 ^ (addr_bitsize - 19) * 2 ^ 19\")\n  apply (erule ssubst)\n  apply (rule less_le_trans[where y = \"card (UNIV::'b set) * 2 ^ 19\"])\n    apply (rule mult_less_mono2)\n      apply (rule oneMB_size_ax)\n    apply simp\n  apply (rule mult_le_mono1)\n    apply (rule le_trans[where j = \"2 ^ 13\"])\n      apply (rule fourthousand_count_ax)\n    apply simp\n  apply simp\napply (simp add: addr_card)\ndone\n\nend\n\nclass twoToSix_size = oneMB_size +\n  assumes twoToSix_size_ax: \"size_of TYPE('a::c_type) < 2 ^ 6\"\n\ninstantiation array :: (twoToSix_size, fourthousand_count) oneMB_size\nbegin\n\ninstance\napply intro_classes\napply simp\n  apply (rule order_less_le_trans)\n   apply (rule mult_le_less_imp_less)\n    apply (rule fourthousand_count_ax)\n   apply (rule twoToSix_size_ax)\n  apply simp\n   apply simp\n  apply simp\n  done\n\nend\n\ninstantiation word :: (len8) oneMB_size\nbegin\ninstance\napply intro_classes\napply(simp add: size_of_def)\napply(subgoal_tac \"len_of TYPE('a) \\<le> 128\")\n apply simp\napply(rule len8_width)\ndone\nend\n\ninstantiation word :: (len8) twoToSix_size\nbegin\ninstance\napply intro_classes\napply(simp add: size_of_def)\napply(subgoal_tac \"len_of TYPE('a) \\<le> 128\")\n apply simp\napply(rule len8_width)\ndone\nend\n\ninstantiation ptr :: (c_type) oneMB_size\nbegin\ninstance\napply intro_classes\napply (simp add: size_of_def)\ndone\nend\n\ninstantiation ptr :: (c_type) twoToSix_size\nbegin\ninstance\napply intro_classes\napply (simp add: size_of_def)\ndone\nend\n\nclass lt12 = finite +\n  assumes lt12_ax: \"CARD ('a) < 2 ^ 12\"\nclass lt11 = lt12 +\n  assumes lt11_ax: \"CARD ('a) < 2 ^ 11\"\nclass lt10 = lt11 +\n  assumes lt10_ax: \"CARD ('a) < 2 ^ 10\"\nclass lt9 = lt10 +\n  assumes lt9_ax: \"CARD ('a) < 2 ^ 9\"\nclass lt8 = lt9 +\n  assumes lt8_ax: \"CARD ('a) < 2 ^ 8\"\nclass lt7 = lt8 +\n  assumes lt7_ax: \"CARD ('a) < 2 ^ 7\"\nclass lt6 = lt7 +\n  assumes lt6_ax: \"CARD ('a) < 2 ^ 6\"\nclass lt5 = lt6 +\n  assumes lt5_ax: \"CARD ('a) < 2 ^ 5\"\nclass lt4 = lt5 +\n  assumes lt4_ax: \"CARD ('a) < 2 ^ 4\"\nclass lt3 = lt4 +\n  assumes lt3_ax: \"CARD ('a) < 2 ^ 3\"\nclass lt2 = lt3 +\n  assumes lt2_ax: \"CARD ('a) < 2 ^ 2\"\nclass lt1 = lt2 +\n  assumes lt1_ax: \"CARD ('a) < 2 ^ 1\"\n\ninstantiation bit0 :: (lt12) fourthousand_count\nbegin\ninstance\n  by (intro_classes, insert lt12_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt12) fourthousand_count\nbegin\ninstance\n  by (intro_classes, insert lt12_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt11) lt12\nbegin\ninstance\n  by (intro_classes, insert lt11_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt11) lt12\nbegin\ninstance\n  by (intro_classes, insert lt11_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt10) lt11\nbegin\ninstance\n  by (intro_classes, insert lt10_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt10) lt11\nbegin\ninstance\n  by (intro_classes, insert lt10_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt9) lt10\nbegin\ninstance\n  by (intro_classes, insert lt9_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt9) lt10\nbegin\ninstance\n  by (intro_classes, insert lt9_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt8) lt9\nbegin\ninstance\n  by (intro_classes, insert lt8_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt8) lt9\nbegin\ninstance\n  by (intro_classes, insert lt8_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt7) lt8\nbegin\ninstance\n  by (intro_classes, insert lt7_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt7) lt8\nbegin\ninstance\n  by (intro_classes, insert lt7_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt6) lt7\nbegin\ninstance\n  by (intro_classes, insert lt6_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt6) lt7\nbegin\ninstance\n  by (intro_classes, insert lt6_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt5) lt6\nbegin\ninstance\n  by (intro_classes, insert lt5_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt5) lt6\nbegin\ninstance\n  by (intro_classes, insert lt5_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt4) lt5\nbegin\ninstance\n  by (intro_classes, insert lt4_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt4) lt5\nbegin\ninstance\n  by (intro_classes, insert lt4_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt3) lt4\nbegin\ninstance\n  by (intro_classes, insert lt3_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt3) lt4\nbegin\ninstance\n  by (intro_classes, insert lt3_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt2) lt3\nbegin\ninstance\n  by (intro_classes, insert lt2_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt2) lt3\nbegin\ninstance\n  by (intro_classes, insert lt2_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt1) lt2\nbegin\ninstance\n  by (intro_classes, insert lt1_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt1) lt2\nbegin\ninstance\n  by (intro_classes, insert lt1_ax[where 'a = 'a], simp)\nend\n\ninstantiation num1 :: lt1\nbegin\ninstance\n  by (intro_classes, simp_all)\nend\n\n(* don't understand why this also seems to be necessary *)\ninstantiation num1 :: fourthousand_count\nbegin\ninstance\n  by (intro_classes, simp)\nend\n\n(* introduce hackish handling of 8192 type by making a copy of the type\n   under a constructor, and then manually showing that it is an instance of\n   fourthousand_count *)\ndatatype ty8192 = ty8192 \"8192\"\n\nlemma univ8192: \"(UNIV::ty8192 set) = image ty8192 (UNIV::8192 set)\"\napply (simp add: set_eq_iff image_iff)\napply (rule_tac allI)\napply (rule_tac ty8192.induct)\napply simp\ndone\n\ninstance \"ty8192\" :: finite\napply intro_classes\napply (simp add: univ8192)\ndone\n\nlemma card8192[simp]: \"CARD(ty8192) = CARD(8192)\"\napply (simp add: univ8192 card_image inj_on_def)\ndone\n\ninstance \"ty8192\" :: fourthousand_count\nby intro_classes simp\n\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/l4v/tools/c-parser/umm_heap/ArraysMemInstance.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.29803816461509924}}
{"text": "(*<*)\n\n(* Author: Kyndylan Nienhuis *)\n\ntheory CheriAltDefs\n\nimports \n  \"Preamble\"\n  \"L3Lemmas\"\n  \"CHERI-p256.CHERI_Monadic_p256\"\nbegin\n\n(*>*)\nsection \\<open>Alternative definitions\\<close>\n\ntext \\<open>In this theory we give an alternative definition for all CHERI instructions and auxiliary\nfunctions. Each alternative definition is equivalent to the original definition. The first\ntransformation is that we remove all occurrences of @{const extend_state}. We achieve this by\nsubstituting the value of the extra state components in the places where they are used. To cover\nfor-loops, we define a new variant that carries a value to the next iteration. The second\ntransformation is that we merge accessing or updating sub-components of the state into one step.\\<close>\n\nsection \\<open>Preamble\\<close>\n\ntext \\<open>The following is conceptually part of the theory Preamble, but could not be inserted there\nbecause Preamble.thy cannot have a reference to CHERI.\\<close>\n\nsubsection \\<open>Distributive laws\\<close>\n\ntext \\<open>We collect the distributive laws of the types of cases that are used in the model.\\<close>\n\nlemmas case_distrib = \n  Option.option.case_distrib\n  List.list.case_distrib\n  Product_Type.prod.case_distrib\n  bool.case_distrib\n  DataType.case_distrib\n  ShadowMem.case_distrib\n  ShadowTags.case_distrib\n  RegSet.case_distrib\n  CmpType.case_distrib\n  Branch.case_distrib\n  CP.case_distrib\n  Store.case_distrib\n  Load.case_distrib\n  Trap.case_distrib\n  Shift.case_distrib\n  MultDiv.case_distrib\n  ArithR.case_distrib\n  ArithI.case_distrib\n  CGet.case_distrib\n  CSet.case_distrib\n  CCheck.case_distrib\n  CHERICOP2.case_distrib\n  COP2.case_distrib\n  CHERISWC2.case_distrib\n  SWC2.case_distrib\n  CHERILWC2.case_distrib\n  LWC2.case_distrib\n  CHERILDC2.case_distrib\n  LDC2.case_distrib\n  CHERISDC2.case_distrib\n  SDC2.case_distrib\n  instruction.case_distrib\n\nlemmas case_distrib_cancel [simp] = \n  case_distrib[where h=\"\\<lambda>_. _\", THEN sym]\n\nlemmas if_distrib_h = \n  if_distrib[where f=h] for h\n\nlemma let_distrib:\n  shows \"h (let x = y in f x) = (let x = y in h (f x))\"\nby simp\n\nlemmas all_distrib = \n  if_distrib_h\n  let_distrib\n  case_distrib\n\nlemmas ValuePart_cases [ValueAndStatePart_simp] =\n  all_distrib[where h=\"\\<lambda>x. ValuePart x _\"]\n\nlemmas StatePart_cases [ValueAndStatePart_simp] =\n  all_distrib[where h=\"\\<lambda>x. StatePart x _\"]\n\nsubsection \\<open>Split laws\\<close>\n\nlemmas case_split = \n  Option.option.split\n  List.list.split\n  Product_Type.prod.split\n  bool.split\n  DataType.split\n  ShadowMem.split\n  ShadowTags.split\n  RegSet.split\n  CmpType.split\n  Branch.split\n  CP.split\n  Store.split\n  Load.split\n  Trap.split\n  Shift.split\n  MultDiv.split\n  ArithR.split\n  ArithI.split\n  CGet.split\n  CSet.split\n  CCheck.split\n  CHERICOP2.split\n  COP2.split\n  CHERISWC2.split\n  SWC2.split\n  CHERILWC2.split\n  LWC2.split\n  CHERILDC2.split\n  LDC2.split\n  CHERISDC2.split\n  SDC2.split\n  instruction.split\n\nlemma let_split:\n  fixes P\n  shows \"P (let x = y in f x) = (\\<forall>x. x = y \\<longrightarrow> P (f x))\"\nby simp\n\nlemmas all_split = \n  if_splits(1)\n  let_split\n  case_split\n  \n(*\n(* I tried to get the above lemmas for free using one of the following existing lemmas. *)\n\nthm instruction.case_distrib\nthm instruction.induct\nthm instruction.exhaust\nthm instruction.split\n\n(* However, xxx.split doesn't work, because I can't get rid of the conjunction. *)\nlemmas foo_split = \n  instruction.split[where P=\"isInvariant _\", THEN sym, THEN iffD1, OF conjI, OF allI, OF impI]\n\n(* But I could use split, and also add conjI, allI and impI to the method *)\nlemmas foo_split2  = \n  instruction.split[where P=\"isInvariant _\", THEN sym, THEN iffD1]\n\n(* xxx.exhaust doesn't work, because I can't bind P and y to something that shares a variable. *)\nlemmas foo_exhaust = \n  instruction.exhaust[where P=\"isInvariant _ _\" and y=\"_\"]\n\n(* xxx.induct does work, but takes much too long to process, and I still need to state the case. *)\nlemmas foo_induct = \n  instruction.induct[where P=\"\\<lambda>ins. isInvariant _ \n                         (case ins of ArithI x \\<Rightarrow> _ x\n                                   |  ArithR x \\<Rightarrow> _ x\n                                   |  BREAK \\<Rightarrow> _\n                                   |  Branch x \\<Rightarrow> _ x\n                                   |  CACHE x \\<Rightarrow> _ x\n                                   |  COP1 x \\<Rightarrow> _ x\n                                   |  COP2 x \\<Rightarrow> _ x\n                                   |  CP x \\<Rightarrow> _ x\n                                   |  ERET \\<Rightarrow> _ \n                                   |  LDC2 x \\<Rightarrow> _ x\n                                   |  LWC2 x \\<Rightarrow> _ x\n                                   |  Load x \\<Rightarrow> _ x\n                                   |  MultDiv x \\<Rightarrow> _ x\n                                   |  RDHWR x \\<Rightarrow> _ x\n                                   |  ReservedInstruction \\<Rightarrow> _\n                                   |  SDC2 x \\<Rightarrow> _ x\n                                   |  SWC2 x \\<Rightarrow> _ x\n                                   |  SYNC x \\<Rightarrow> _ x\n                                   |  SYSCALL \\<Rightarrow> _ \n                                   |  Shift x \\<Rightarrow> _ x\n                                   |  Store x \\<Rightarrow> _ x\n                                   |  TLBP \\<Rightarrow> _\n                                   |  TLBR \\<Rightarrow> _ \n                                   |  TLBWI \\<Rightarrow> _\n                                   |  TLBWR \\<Rightarrow> _\n                                   |  Trap x \\<Rightarrow> _ x\n                                   |  Unpredictable \\<Rightarrow> _\n                                   |  WAIT \\<Rightarrow> _)\"]\n\n(* xxx.case_distrib doesn't work, because it doesn't get rid of the case in the assumption. *)\nlemmas foo_case_distrib =\n  instruction.case_distrib[where h=\"isInvariant _\", THEN sym, THEN iffD1]\n*)\n\nsubsection \\<open>Congruences\\<close>\n\nlemmas weak_cong = \n  if_weak_cong\n  option.case_cong_weak\n  list.case_cong_weak\n  prod.case_cong_weak\n  DataType.case_cong_weak\n  ShadowMem.case_cong_weak\n  ShadowTags.case_cong_weak\n  RegSet.case_cong_weak\n  CmpType.case_cong_weak\n  Branch.case_cong_weak\n  CP.case_cong_weak\n  Store.case_cong_weak\n  Load.case_cong_weak\n  Trap.case_cong_weak\n  Shift.case_cong_weak\n  MultDiv.case_cong_weak\n  ArithR.case_cong_weak\n  ArithI.case_cong_weak\n  CGet.case_cong_weak\n  CSet.case_cong_weak\n  CCheck.case_cong_weak\n  CHERICOP2.case_cong_weak\n  COP2.case_cong_weak\n  CHERISWC2.case_cong_weak\n  SWC2.case_cong_weak\n  CHERILWC2.case_cong_weak\n  LWC2.case_cong_weak\n  CHERILDC2.case_cong_weak\n  LDC2.case_cong_weak\n  CHERISDC2.case_cong_weak\n  SDC2.case_cong_weak\n  instruction.case_cong_weak\n\nlemmas cong =\n  if_cong\n  option.case_cong\n  list.case_cong\n  prod.case_cong\n  DataType.case_cong\n  ShadowMem.case_cong\n  ShadowTags.case_cong\n  RegSet.case_cong\n  CmpType.case_cong\n  Branch.case_cong\n  CP.case_cong\n  Store.case_cong\n  Load.case_cong\n  Trap.case_cong\n  Shift.case_cong\n  MultDiv.case_cong\n  ArithR.case_cong\n  ArithI.case_cong\n  CGet.case_cong\n  CSet.case_cong\n  CCheck.case_cong\n  CHERICOP2.case_cong\n  COP2.case_cong\n  CHERISWC2.case_cong\n  SWC2.case_cong\n  CHERILWC2.case_cong\n  LWC2.case_cong\n  CHERILDC2.case_cong\n  LDC2.case_cong\n  CHERISDC2.case_cong\n  SDC2.case_cong\n  instruction.case_cong    \n\nsubsection \\<open>Strong congruence simplifier\\<close>\n\ntext \\<open>We remove \\<open>if_splits\\<close> from the split rules of the simplifier (to avoid an explosion of the\nstate). That means that some obvious simplifications are not done anymore, so we add these manually.\nWe do not like negations and disjunctions in our generated definitions, so we only add the following\nlemmas to \\<open>alt_def_simp\\<close>.\\<close>\n\nlemma if_bool_simps2 [alt_def_simp]:\n  shows \"(if b then x else False) = (b \\<and> x)\"\n    and \"(if b then x else True) = (b \\<longrightarrow> x)\"\nby simp_all\n\nmethod strong_cong_simp uses add del = \n  (simp \n     add: add\n     del: del\n     split del: if_splits(1)\n     cong del: weak_cong\n     cong add: cong)\n\nmethod strong_cong_simp_all uses add del = \n  (simp_all\n     add: add\n     del: del\n     split del: if_splits(1)\n     cong del: weak_cong\n     cong add: cong)\n\nsubsection \\<open>Simple version of @{method auto}\\<close>\n\ntext \\<open>In some rare cases @{method auto} gets stuck, but the proof is too difficult for @{method\nsimp}. The following method could help in that case: it invokes the simplifier and does some simple\nelimination and introduction, but nothing fancy. Sometimes @{method auto} is quicker than this\nmethod and sometimes the other way around. The proof method does not introduce any new\nuninstantiated variables.\\<close>\n\nmethod simple_auto uses simp intro elim =\n  (strong_cong_simp add: simp |\n   elim conjE exE elim | \n   intro conjI impI allI intro);\n  (simple_auto simp: simp intro: intro elim: elim)?\n\nsection \\<open>Removing extend-state\\<close>\n\nsubsection \\<open>foreach-loop that returns a value\\<close>\n\ntext \\<open>The expression inside a @{term foreach_loop} cannot use the result of the previous\niteration. We define a new variant of the loop where this is possible.\\<close>\n\nfun foreach_loop_agg :: \"'a list \\<Rightarrow> 'b \\<Rightarrow> ('a \\<Rightarrow> 'b \\<Rightarrow> 's \\<Rightarrow> 'b \\<times> 's) \\<Rightarrow>\n                          's \\<Rightarrow> 'b \\<times> 's\" where\n  \"foreach_loop_agg [] b _    = return b\" |\n  \"foreach_loop_agg (h#t) b f = bind (f h b) (\\<lambda>b. foreach_loop_agg t b f)\"\n\nlemma foreach_loop_agg_return [simp]:\n  shows \"foreach_loop_agg l b (\\<lambda>a v. return (x a v)) = \n         return (fold x l b)\"\nby (induct l arbitrary: b) simp_all\n\nlemma fold_id [simp]:\n  shows \"fold (\\<lambda>_ v. v) l = (\\<lambda>v. v)\"\nby (induct l) simp_all\n\nlemma foreach_loop_agg_bind_return_constant [simp]:\n  shows \"foreach_loop_agg l b (\\<lambda>a b. bind (f a b) (\\<lambda>_. return b)) =\n         bind (foreach_loop (l, (\\<lambda>a. (f a b)))) (\\<lambda>_. return b)\"\nby (induct l) (simp_all add: bind_associativity)\n\nlemma foreach_loop_agg_bind_bind_return_constant [simp]:\n  shows \"foreach_loop_agg l b (\\<lambda>a b. bind (f a b) (\\<lambda>c. bind (g a b c) (\\<lambda>_. return b))) =\n         bind (foreach_loop (l, (\\<lambda>a. bind (f a b) (\\<lambda>c. (g a b c) )))) (\\<lambda>_. return b)\"\nby (induct l) (simp_all add: bind_associativity)\n\nlemma foreach_loop_agg_bind_bind_bind_return_constant [simp]:\n  shows \"foreach_loop_agg l b (\\<lambda>a b. bind (f a b) (\\<lambda>c. bind (g a b c) (\\<lambda>d. bind (h a b c d) (\\<lambda>_. return b)))) =\n         bind (foreach_loop (l, (\\<lambda>a. bind (f a b) (\\<lambda>c. bind (g a b c) (\\<lambda>d. h a b c d))))) (\\<lambda>_. return b)\"\nby (induct l) (simp_all add: bind_associativity)\n\nlemma foreach_loop_agg_bind_return_left [simp]:\n  shows \"foreach_loop_agg l b (\\<lambda>a b. bind (f a b) (\\<lambda>c. return (fst b, x a b c))) =\n         bind (foreach_loop_agg l (snd b) (\\<lambda>a b2. \n                 bind (f a (fst b, b2)) (\\<lambda>c. return (x a (fst b, b2) c))))\n         (\\<lambda>b2. return (fst b, b2))\"\nby (induct l arbitrary: b) (simp_all add: bind_associativity)\n\nlemma foreach_loop_agg_bind_return_right [simp]:\n  shows \"foreach_loop_agg l b (\\<lambda>a b. bind (f a b) (\\<lambda>c. return (x a b c, snd b))) =\n         bind (foreach_loop_agg l (fst b) (\\<lambda>a b2. \n                 bind (f a (b2, snd b)) (\\<lambda>c. return (x a (b2, snd b) c))))\n         (\\<lambda>b2. return (b2, snd b))\"\nby (induct l arbitrary: b) (simp_all add: bind_associativity)\n\nlemma foreach_loop_agg_bind_bind_return_left [simp]:\n  shows \"foreach_loop_agg l b (\\<lambda>a b. bind (f a b) (\\<lambda>c. bind (g a b c) (\\<lambda>d. return (fst b, x a b c d)))) =\n         bind (foreach_loop_agg l (snd b) (\\<lambda>a b2. \n                 bind (f a (fst b, b2)) (\\<lambda>c. bind (g a (fst b, b2) c) (\\<lambda>d. return (x a (fst b, b2) c d)))))\n         (\\<lambda>b2. return (fst b, b2))\"\nby (induct l arbitrary: b) (simp_all add: bind_associativity)\n\nlemma foreach_loop_agg_bind_bind_return_right [simp]:\n  shows \"foreach_loop_agg l b (\\<lambda>a b. bind (f a b) (\\<lambda>c. bind (g a b c) (\\<lambda>d. return (x a b c d, snd b)))) =\n         bind (foreach_loop_agg l (fst b) (\\<lambda>a b2. \n                 bind (f a (b2, snd b)) (\\<lambda>c. bind (g a (b2, snd b) c) (\\<lambda>d. return (x a (b2, snd b) c d)))))\n         (\\<lambda>b2. return (b2, snd b))\"\nby (induct l arbitrary: b) (simp_all add: bind_associativity)\n\nlemma foreach_loop_agg_read_state [simp]:\n  shows \"foreach_loop_agg l b (\\<lambda>a v. read_state (f a v)) = \n         read_state (\\<lambda>s. fold (\\<lambda>a v. f a v s) l b)\"\nproof (induct l arbitrary: b)\n  case (Cons h t)\n  hence \"foreach_loop_agg (h # t) b (\\<lambda>a v. read_state (f a v)) =\n         bind (read_state (f h b)) (\\<lambda>b. read_state (\\<lambda>s. fold (\\<lambda>a v. f a v s) t b))\"\n    by simp\n  also have \"... = read_state (\\<lambda>s. fold (\\<lambda>a v. f a v s) (h # t) b)\"\n    unfolding monad_def by simp\n  finally show ?case .\nqed simp\n\nlemma foreach_loop_agg_bind_read_state_return [simp]:\n  shows \"foreach_loop_agg l b (\\<lambda>a v. bind (read_state (f a v)) (\\<lambda>b. return (x a v b))) = \n         read_state (\\<lambda>s. fold (\\<lambda>a v. x a v (f a v s)) l b)\" (is \"?l = ?r\")\nproof -\n  have \"bind (read_state (f a v)) (\\<lambda>b. return (x a v b)) = read_state (\\<lambda>s. x a v (f a v s))\" for a v\n    unfolding monad_def Let_def by simp\n  hence \"?l = foreach_loop_agg l b (\\<lambda>a v. read_state (\\<lambda>s. x a v (f a v s)))\" by simp\n  also have \"... = read_state (\\<lambda>s. fold (\\<lambda>a v. x a v (f a v s)) l b)\" by simp\n  finally show ?thesis .\nqed\n\nlemma StatePart_foreach_loop_agg:\n  assumes \"\\<And>a a' v v' s. ValuePart (m a v) (StatePart (m a' v') s) = ValuePart (m a v) s\"\n  shows \"ValuePart (foreach_loop_agg l v m) = \n         (\\<lambda>s. fold (\\<lambda>a v. ValuePart (m a v) s) l v)\"\nusing assms\nby (induct l arbitrary: v)\n   (auto simp add: ValuePart_bind)\n\nsubsection \\<open>Extend state\\<close>\n\ntext \\<open>To simplify @{term extend_state} in the general case, we (temporarily) introduce two new\nfunctions, namely @{term extend_before} and @{term extend_after}. Then we add rewrite rules that\neliminate those as well.\\<close>\n\ndefinition extend_before :: \"'v \\<Rightarrow> ('v \\<times> 's \\<Rightarrow> 'a \\<times> 'v \\<times> 's) \\<Rightarrow> 's \\<Rightarrow> ('a \\<times> 'v) \\<times> 's\" where\n  \"extend_before v m = (\\<lambda>s. let (a, s') = m (v, s) in ((a, fst s'), snd s'))\"\n\ndefinition extend_after :: \"'v \\<Rightarrow> ('s \\<Rightarrow> 'a \\<times> 's) \\<Rightarrow> 's \\<Rightarrow> ('a \\<times> 'v) \\<times> 's\" where\n  \"extend_after v m = bind m (\\<lambda>a. return (a, v))\" \n\ntext \\<open>We always expand the definition of @{term extend_after}; we only defined it to state the\nsimplifications of @{term extend_before} more elegantly. (In previous versions we did not always\nexpand the definition and ran into problems because the simplification rules were not confluent.\\<close>\n\ndeclare extend_after_def [alt_def_simp]\n\nsubsection \\<open>Extend-state bind\\<close>\n\nlemma extend_state_bind [alt_def_simp]:\n  shows \"extend_state v (bind m n) = \n         bind (extend_before v m) (\\<lambda>(a, v). extend_state v (n a))\"    (is \"?l = ?r\")\nproof (intro ext)\n  fix s\n  show \"?l s = ?r s\"\n    unfolding extend_before_def monad_def\n    by (cases \"m (v, s)\") auto\nqed\n\nlemma extend_before_bind [alt_def_simp]:\n  shows \"extend_before v (bind m n) = \n         bind (extend_before v m) (\\<lambda>(a, v). extend_before v (n a))\"    (is \"?l = ?r\")\nproof (intro ext)\n  fix s\n  show \"?l s = ?r s\"\n    unfolding extend_before_def monad_def\n    by (cases \"m (v, s)\") auto\nqed\n\nsubsection \\<open>Extend-state return\\<close>\n\ntext \\<open>There already is a simplification in L3_Lib for @{term \"extend_state v (return x)\"}\\<close>\n\nlemma extend_before_return [alt_def_simp]:\n  shows \"extend_before v (return x) = extend_after v (return x)\"\nunfolding extend_before_def extend_after_def monad_def\nby auto\n\nsubsection \\<open>Extend-state read-state\\<close>\n\nlemma extend_state_read_state [alt_def_simp]:\n  shows \"extend_state v (read_state f) = read_state (\\<lambda>s. f (v, s))\"\nunfolding monad_def\nby simp\n\nlemma extend_before_read_state [alt_def_simp]:\n  shows \"extend_before v (read_state f) = \n         extend_after v (read_state (\\<lambda>s. f (v, s)))\"\nunfolding extend_before_def extend_after_def monad_def\nby auto\n\nsubsection \\<open>Extend-state update-state\\<close>\n\nlemma extend_state_update_state [alt_def_simp]:\n  shows \"extend_state v (update_state f) = update_state (\\<lambda>s. snd (f (v, s)))\"\nunfolding monad_def\nby simp\n\ntext \\<open>The general case above for @{term \"extend_before v (update_state f)\"} is quite complicated,\nand in the exported Isabelle/HOL only two variations appear, so we only add the specialised\nlemmas to the simplification set.\\<close>\n\nlemma extend_before_update_state:\n  shows \"extend_before v (update_state f) = \n         bind (read_state (\\<lambda>s. fst (f (v, s)))) \n              (\\<lambda>v'. extend_after v' (update_state (\\<lambda>s. snd (f (v, s))))) \"\nunfolding extend_before_def extend_after_def monad_def\nby simp\n\nlemma extend_before_update_state_1 [alt_def_simp]:\n  shows \"extend_before v (update_state (\\<lambda>s. (fst s, f s))) = \n         extend_after v (update_state (\\<lambda>s. f (v, s)))\"\nunfolding extend_before_update_state\nby simp\n\nlemma extend_before_update_state_2 [alt_def_simp]:\n  shows \"extend_before v (update_state (\\<lambda>s. (x, snd s))) = \n         extend_after x (return ())\"\nunfolding extend_before_update_state\nby simp\n\nsubsection \\<open>Extend-state trim-state\\<close>\n\ntext \\<open>There already is a simplification in L3_Lib for @{term \"extend_state v (trim_state m)\"}.\\<close>\n\nlemma extend_before_trim_state [alt_def_simp]:\n  shows \"extend_before v (trim_state m) = extend_after v m\"\n        (is \"?l = ?r\")\nproof\n  fix s\n  show \"?l s = ?r s\"\n    unfolding extend_before_def extend_after_def monad_def\n    by (cases \"m s\") auto\nqed\n\nsubsection \\<open>Extend-state foreach-loop\\<close>\n\nlemma extend_state_foreach_loop [alt_def_simp]:\n  shows \"extend_state v (foreach_loop (l, m)) = \n         bind (foreach_loop_agg l v (\\<lambda>a v. bind (extend_before v (m a)) (\\<lambda>(_, v). return v)))\n              (\\<lambda>_. return ())\"\nproof (induct l arbitrary: v)\n  case Nil\n  thus ?case \n    by simp\nnext\n  case (Cons h t)\n  thus ?case\n    by (simp add: extend_state_bind case_prod_unfold bind_associativity)  \nqed\n\nlemma extend_before_foreach_loop [alt_def_simp]:\n  shows \"extend_before v (foreach_loop (l, m)) = \n         bind (foreach_loop_agg l v (\\<lambda>a v. bind (extend_before v (m a)) (\\<lambda>(_, v). return v)))\n              (\\<lambda>v. extend_after v (return ()))\"\nproof (induct l arbitrary: v)\n  case Nil\n  thus ?case \n    by (simp add: extend_before_return extend_after_def)\nnext\n  case (Cons h t)\n  thus ?case\n    by (simp add: extend_before_bind case_prod_unfold bind_associativity)  \nqed\n\nsubsection \\<open>Extend-state foreach-loop-agg\\<close>\n\nlemma extend_state_foreach_loop_agg [alt_def_simp]:\n  shows \"extend_state v2 (foreach_loop_agg l v1 f) = \n         bind (foreach_loop_agg l (v1, v2) (\\<lambda>a v. extend_before (snd v) (f a (fst v))))\n              (\\<lambda>v. return (fst v))\"\nproof (induct l arbitrary: v1 v2)\n  case Nil\n  thus ?case\n    by simp\nnext\n  case (Cons h t)\n  thus ?case\n    by (simp add: extend_state_bind case_prod_unfold bind_associativity)  \nqed\n\nlemma extend_before_foreach_loop_agg [alt_def_simp]:\n  shows \"extend_before v2 (foreach_loop_agg l v1 f) = \n         foreach_loop_agg l (v1, v2) (\\<lambda>a v. extend_before (snd v) (f a (fst v)))\"\nproof (induct l arbitrary: v1 v2)\n  case Nil\n  thus ?case\n    by (simp add: extend_before_return extend_after_def)\nnext\n  case (Cons h t)\n  thus ?case\n    by (simp add: extend_before_bind case_prod_unfold)  \nqed\n\nsubsection \\<open>Extend-state distributive cases\\<close>\n\nlemmas extend_state_case [alt_def_simp] = \n  all_distrib[where h=\"extend_state _\"]\n\nlemmas extend_before_case [alt_def_simp] = \n  all_distrib[where h=\"extend_before _\"]\n\nsection \\<open>Contracting reads and updates\\<close>\n\nlemma bind_arg_cong:\n  assumes \"bind m n = k\"\n  shows \"bind m (\\<lambda>a. bind (n a) l) = bind k l\"\nusing assms \nby (simp add: bind_associativity[THEN sym])\n\nlemma contract_read:\n  shows \"bind (read_state getParent) (\\<lambda>a. return (sub a)) = \n         read_state (\\<lambda>s. sub (getParent s))\" (is \"?T1\")\n    and \"bind (read_state getParent) (\\<lambda>a. bind (return (sub a)) m) = \n         bind (read_state (\\<lambda>s. sub (getParent s))) m\" (is \"?T2\")\nproof -\n  show ?T1\n    unfolding monad_def Let_def\n    by simp\n  from bind_arg_cong[OF this]\n  show ?T2 .\nqed\n\nlemma contract_update:\n  shows \"bind (read_state getParent) \n              (\\<lambda>v'. update_state (setParent (sub_update (\\<lambda>_. f (sub v')) v'))) = \n         bind (read_state (\\<lambda>s. sub (getParent s))) \n              (\\<lambda>v. update_state (\\<lambda>s. setParent (sub_update (\\<lambda>_. f v) (getParent s)) s))\" \n         (is \"?T1\")\n    and \"bind (read_state getParent) \n              (\\<lambda>v'. bind (update_state (setParent (sub_update (\\<lambda>_. f (sub v')) v'))) m) = \n         bind (read_state (\\<lambda>s. sub (getParent s))) \n              (\\<lambda>v. bind (update_state (\\<lambda>s. setParent (sub_update (\\<lambda>_. f v) (getParent s)) s)) m)\" \n         (is \"?T2\")\nproof -\n  show ?T1\n    unfolding monad_def Let_def\n    by simp\n  from bind_arg_cong[OF this]\n  show ?T2 by (simp add: bind_associativity)\nqed\n\nlemma contract_update_constant:\n  shows \"bind (read_state getParent) \n              (\\<lambda>v'. update_state (setParent (sub_update (\\<lambda>_. x) v'))) = \n         update_state (\\<lambda>s. setParent (sub_update (\\<lambda>_. x) (getParent s)) s)\" (is \"?T1\")\n    and \"bind (read_state getParent) \n              (\\<lambda>v'. bind (update_state (setParent (sub_update (\\<lambda>_. x) v'))) m) = \n         bind (update_state (\\<lambda>s. setParent (sub_update (\\<lambda>_. x) (getParent s)) s)) m\" (is \"?T2\")\nproof -\n  show ?T1\n    unfolding monad_def Let_def\n    by simp\n  from bind_arg_cong[OF this]\n  show ?T2 .\nqed\n\nsubsection \\<open>Simplifying nested updates\\<close>\n\n(* Code generation - start - state component updates *)\n\nlemma state_component_update_simps [simp]:\n  shows \"BranchDelayPCC_update (\\<lambda>_. f_BranchDelayPCC (BranchDelayPCC s)) s = \n         BranchDelayPCC_update (f_BranchDelayPCC) s\"\n    and \"BranchToPCC_update (\\<lambda>_. f_BranchToPCC (BranchToPCC s)) s = \n         BranchToPCC_update (f_BranchToPCC) s\"\n    and \"JTAG_UART_update (\\<lambda>_. f_JTAG_UART (JTAG_UART s)) s = \n         JTAG_UART_update (f_JTAG_UART) s\"\n    and \"PIC_base_address_update (\\<lambda>_. f_PIC_base_address (PIC_base_address s)) s = \n         PIC_base_address_update (f_PIC_base_address) s\"\n    and \"PIC_config_regs_update (\\<lambda>_. f_PIC_config_regs (PIC_config_regs s)) s = \n         PIC_config_regs_update (f_PIC_config_regs) s\"\n    and \"PIC_external_intrs_update (\\<lambda>_. f_PIC_external_intrs (PIC_external_intrs s)) s = \n         PIC_external_intrs_update (f_PIC_external_intrs) s\"\n    and \"PIC_ip_bits_update (\\<lambda>_. f_PIC_ip_bits (PIC_ip_bits s)) s = \n         PIC_ip_bits_update (f_PIC_ip_bits) s\"\n    and \"UNPREDICTABLE_HI_update (\\<lambda>_. f_UNPREDICTABLE_HI (UNPREDICTABLE_HI s)) s = \n         UNPREDICTABLE_HI_update (f_UNPREDICTABLE_HI) s\"\n    and \"UNPREDICTABLE_LO_update (\\<lambda>_. f_UNPREDICTABLE_LO (UNPREDICTABLE_LO s)) s = \n         UNPREDICTABLE_LO_update (f_UNPREDICTABLE_LO) s\"\n    and \"UNPREDICTABLE_TLB_update (\\<lambda>_. f_UNPREDICTABLE_TLB (UNPREDICTABLE_TLB s)) s = \n         UNPREDICTABLE_TLB_update (f_UNPREDICTABLE_TLB) s\"\n    and \"all_BranchDelayPCC_update (\\<lambda>_. f_all_BranchDelayPCC (all_BranchDelayPCC s)) s = \n         all_BranchDelayPCC_update (f_all_BranchDelayPCC) s\"\n    and \"all_BranchToPCC_update (\\<lambda>_. f_all_BranchToPCC (all_BranchToPCC s)) s = \n         all_BranchToPCC_update (f_all_BranchToPCC) s\"\n    and \"all_TLB_assoc_update (\\<lambda>_. f_all_TLB_assoc (all_TLB_assoc s)) s = \n         all_TLB_assoc_update (f_all_TLB_assoc) s\"\n    and \"all_TLB_direct_update (\\<lambda>_. f_all_TLB_direct (all_TLB_direct s)) s = \n         all_TLB_direct_update (f_all_TLB_direct) s\"\n    and \"all_capcause_update (\\<lambda>_. f_all_capcause (all_capcause s)) s = \n         all_capcause_update (f_all_capcause) s\"\n    and \"all_capr_update (\\<lambda>_. f_all_capr (all_capr s)) s = \n         all_capr_update (f_all_capr) s\"\n    and \"all_gpr_update (\\<lambda>_. f_all_gpr (all_gpr s)) s = \n         all_gpr_update (f_all_gpr) s\"\n    and \"all_pcc_update (\\<lambda>_. f_all_pcc (all_pcc s)) s = \n         all_pcc_update (f_all_pcc) s\"\n    and \"all_scapr_update (\\<lambda>_. f_all_scapr (all_scapr s)) s = \n         all_scapr_update (f_all_scapr) s\"\n    and \"all_state_update (\\<lambda>_. f_all_state (all_state s)) s = \n         all_state_update (f_all_state) s\"\n    and \"c_TLB_assoc_update (\\<lambda>_. f_c_TLB_assoc (c_TLB_assoc s)) s = \n         c_TLB_assoc_update (f_c_TLB_assoc) s\"\n    and \"c_TLB_direct_update (\\<lambda>_. f_c_TLB_direct (c_TLB_direct s)) s = \n         c_TLB_direct_update (f_c_TLB_direct) s\"\n    and \"c_capr_update (\\<lambda>_. f_c_capr (c_capr s)) s = \n         c_capr_update (f_c_capr) s\"\n    and \"c_gpr_update (\\<lambda>_. f_c_gpr (c_gpr s)) s = \n         c_gpr_update (f_c_gpr) s\"\n    and \"c_pcc_update (\\<lambda>_. f_c_pcc (c_pcc s)) s = \n         c_pcc_update (f_c_pcc) s\"\n    and \"c_scapr_update (\\<lambda>_. f_c_scapr (c_scapr s)) s = \n         c_scapr_update (f_c_scapr) s\"\n    and \"c_state_update (\\<lambda>_. f_c_state (c_state s)) s = \n         c_state_update (f_c_state) s\"\n    and \"c_state_update (c_BranchDelay_update (\\<lambda>_. f_c_BranchDelay (c_BranchDelay (c_state s)))) s = \n         c_state_update (c_BranchDelay_update (f_c_BranchDelay)) s\"\n    and \"c_state_update (c_BranchTo_update (\\<lambda>_. f_c_BranchTo (c_BranchTo (c_state s)))) s = \n         c_state_update (c_BranchTo_update (f_c_BranchTo)) s\"\n    and \"c_state_update (c_CP0_update (\\<lambda>_. f_c_CP0 (c_CP0 (c_state s)))) s = \n         c_state_update (c_CP0_update (f_c_CP0)) s\"\n    and \"c_state_update (c_CP0_update (BadInstr_update (\\<lambda>_. f_BadInstr (BadInstr (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (BadInstr_update (f_BadInstr))) s\"\n    and \"c_state_update (c_CP0_update (BadInstrP_update (\\<lambda>_. f_BadInstrP (BadInstrP (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (BadInstrP_update (f_BadInstrP))) s\"\n    and \"c_state_update (c_CP0_update (BadVAddr_update (\\<lambda>_. f_BadVAddr (BadVAddr (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (BadVAddr_update (f_BadVAddr))) s\"\n    and \"c_state_update (c_CP0_update (Cause_update (\\<lambda>_. f_Cause (Cause (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (Cause_update (f_Cause))) s\"\n    and \"c_state_update (c_CP0_update (Cause_update (BD_update (\\<lambda>_. f_BD (BD (Cause (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Cause_update (BD_update (f_BD)))) s\"\n    and \"c_state_update (c_CP0_update (Cause_update (CE_update (\\<lambda>_. f_CE (CE (Cause (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Cause_update (CE_update (f_CE)))) s\"\n    and \"c_state_update (c_CP0_update (Cause_update (CauseRegister.ExcCode_update (\\<lambda>_. f_CauseRegisterExcCode (CauseRegister.ExcCode (Cause (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Cause_update (CauseRegister.ExcCode_update (f_CauseRegisterExcCode)))) s\"\n    and \"c_state_update (c_CP0_update (Cause_update (IP_update (\\<lambda>_. f_IP (IP (Cause (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Cause_update (IP_update (f_IP)))) s\"\n    and \"c_state_update (c_CP0_update (Cause_update (TI_update (\\<lambda>_. f_TI (TI (Cause (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Cause_update (TI_update (f_TI)))) s\"\n    and \"c_state_update (c_CP0_update (Cause_update (causeregister'rst_update (\\<lambda>_. f_causeregister'rst (causeregister'rst (Cause (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Cause_update (causeregister'rst_update (f_causeregister'rst)))) s\"\n    and \"c_state_update (c_CP0_update (Compare_update (\\<lambda>_. f_Compare (Compare (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (Compare_update (f_Compare))) s\"\n    and \"c_state_update (c_CP0_update (Config_update (\\<lambda>_. f_Config (Config (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (Config_update (f_Config))) s\"\n    and \"c_state_update (c_CP0_update (Config_update (AR_update (\\<lambda>_. f_AR (AR (Config (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Config_update (AR_update (f_AR)))) s\"\n    and \"c_state_update (c_CP0_update (Config_update (AT_update (\\<lambda>_. f_AT (AT (Config (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Config_update (AT_update (f_AT)))) s\"\n    and \"c_state_update (c_CP0_update (Config_update (BE_update (\\<lambda>_. f_BE (BE (Config (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Config_update (BE_update (f_BE)))) s\"\n    and \"c_state_update (c_CP0_update (Config_update (K0_update (\\<lambda>_. f_K0 (K0 (Config (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Config_update (K0_update (f_K0)))) s\"\n    and \"c_state_update (c_CP0_update (Config_update (ConfigRegister.M_update (\\<lambda>_. f_ConfigRegisterM (ConfigRegister.M (Config (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Config_update (ConfigRegister.M_update (f_ConfigRegisterM)))) s\"\n    and \"c_state_update (c_CP0_update (Config_update (ConfigRegister.MT_update (\\<lambda>_. f_ConfigRegisterMT (ConfigRegister.MT (Config (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Config_update (ConfigRegister.MT_update (f_ConfigRegisterMT)))) s\"\n    and \"c_state_update (c_CP0_update (Config_update (configregister'rst_update (\\<lambda>_. f_configregister'rst (configregister'rst (Config (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Config_update (configregister'rst_update (f_configregister'rst)))) s\"\n    and \"c_state_update (c_CP0_update (Config1_update (\\<lambda>_. f_Config1 (Config1 (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (Config1_update (f_Config1))) s\"\n    and \"c_state_update (c_CP0_update (Config2_update (\\<lambda>_. f_Config2 (Config2 (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (Config2_update (f_Config2))) s\"\n    and \"c_state_update (c_CP0_update (Config3_update (\\<lambda>_. f_Config3 (Config3 (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (Config3_update (f_Config3))) s\"\n    and \"c_state_update (c_CP0_update (Config6_update (\\<lambda>_. f_Config6 (Config6 (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (Config6_update (f_Config6))) s\"\n    and \"c_state_update (c_CP0_update (Context_update (\\<lambda>_. f_Context (Context (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (Context_update (f_Context))) s\"\n    and \"c_state_update (c_CP0_update (Context_update (Context.BadVPN2_update (\\<lambda>_. f_ContextBadVPN2 (Context.BadVPN2 (Context (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Context_update (Context.BadVPN2_update (f_ContextBadVPN2)))) s\"\n    and \"c_state_update (c_CP0_update (Context_update (Context.PTEBase_update (\\<lambda>_. f_ContextPTEBase (Context.PTEBase (Context (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Context_update (Context.PTEBase_update (f_ContextPTEBase)))) s\"\n    and \"c_state_update (c_CP0_update (Context_update (context'rst_update (\\<lambda>_. f_context'rst (context'rst (Context (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Context_update (context'rst_update (f_context'rst)))) s\"\n    and \"c_state_update (c_CP0_update (Count_update (\\<lambda>_. f_Count (Count (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (Count_update (f_Count))) s\"\n    and \"c_state_update (c_CP0_update (Debug_update (\\<lambda>_. f_Debug (Debug (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (Debug_update (f_Debug))) s\"\n    and \"c_state_update (c_CP0_update (EPC_update (\\<lambda>_. f_EPC (EPC (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (EPC_update (f_EPC))) s\"\n    and \"c_state_update (c_CP0_update (EntryHi_update (\\<lambda>_. f_EntryHi (EntryHi (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (EntryHi_update (f_EntryHi))) s\"\n    and \"c_state_update (c_CP0_update (EntryHi_update (EntryHi.ASID_update (\\<lambda>_. f_EntryHiASID (EntryHi.ASID (EntryHi (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (EntryHi_update (EntryHi.ASID_update (f_EntryHiASID)))) s\"\n    and \"c_state_update (c_CP0_update (EntryHi_update (EntryHi.R_update (\\<lambda>_. f_EntryHiR (EntryHi.R (EntryHi (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (EntryHi_update (EntryHi.R_update (f_EntryHiR)))) s\"\n    and \"c_state_update (c_CP0_update (EntryHi_update (EntryHi.VPN2_update (\\<lambda>_. f_EntryHiVPN2 (EntryHi.VPN2 (EntryHi (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (EntryHi_update (EntryHi.VPN2_update (f_EntryHiVPN2)))) s\"\n    and \"c_state_update (c_CP0_update (EntryHi_update (entryhi'rst_update (\\<lambda>_. f_entryhi'rst (entryhi'rst (EntryHi (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (EntryHi_update (entryhi'rst_update (f_entryhi'rst)))) s\"\n    and \"c_state_update (c_CP0_update (EntryLo0_update (\\<lambda>_. f_EntryLo0 (EntryLo0 (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (EntryLo0_update (f_EntryLo0))) s\"\n    and \"c_state_update (c_CP0_update (EntryLo1_update (\\<lambda>_. f_EntryLo1 (EntryLo1 (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (EntryLo1_update (f_EntryLo1))) s\"\n    and \"c_state_update (c_CP0_update (ErrCtl_update (\\<lambda>_. f_ErrCtl (ErrCtl (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (ErrCtl_update (f_ErrCtl))) s\"\n    and \"c_state_update (c_CP0_update (ErrorEPC_update (\\<lambda>_. f_ErrorEPC (ErrorEPC (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (ErrorEPC_update (f_ErrorEPC))) s\"\n    and \"c_state_update (c_CP0_update (HWREna_update (\\<lambda>_. f_HWREna (HWREna (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (HWREna_update (f_HWREna))) s\"\n    and \"c_state_update (c_CP0_update (Index_update (\\<lambda>_. f_Index (Index (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (Index_update (f_Index))) s\"\n    and \"c_state_update (c_CP0_update (LLAddr_update (\\<lambda>_. f_LLAddr (LLAddr (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (LLAddr_update (f_LLAddr))) s\"\n    and \"c_state_update (c_CP0_update (PRId_update (\\<lambda>_. f_PRId (PRId (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (PRId_update (f_PRId))) s\"\n    and \"c_state_update (c_CP0_update (PageMask_update (\\<lambda>_. f_PageMask (PageMask (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (PageMask_update (f_PageMask))) s\"\n    and \"c_state_update (c_CP0_update (Random_update (\\<lambda>_. f_Random (Random (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (Random_update (f_Random))) s\"\n    and \"c_state_update (c_CP0_update (Random_update (Random.Random_update (\\<lambda>_. f_RandomRandom (Random.Random (Random (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Random_update (Random.Random_update (f_RandomRandom)))) s\"\n    and \"c_state_update (c_CP0_update (Random_update (random'rst_update (\\<lambda>_. f_random'rst (random'rst (Random (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Random_update (random'rst_update (f_random'rst)))) s\"\n    and \"c_state_update (c_CP0_update (Status_update (\\<lambda>_. f_Status (Status (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (Status_update (f_Status))) s\"\n    and \"c_state_update (c_CP0_update (Status_update (BEV_update (\\<lambda>_. f_BEV (BEV (Status (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Status_update (BEV_update (f_BEV)))) s\"\n    and \"c_state_update (c_CP0_update (Status_update (CU0_update (\\<lambda>_. f_CU0 (CU0 (Status (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Status_update (CU0_update (f_CU0)))) s\"\n    and \"c_state_update (c_CP0_update (Status_update (CU1_update (\\<lambda>_. f_CU1 (CU1 (Status (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Status_update (CU1_update (f_CU1)))) s\"\n    and \"c_state_update (c_CP0_update (Status_update (CU2_update (\\<lambda>_. f_CU2 (CU2 (Status (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Status_update (CU2_update (f_CU2)))) s\"\n    and \"c_state_update (c_CP0_update (Status_update (CU3_update (\\<lambda>_. f_CU3 (CU3 (Status (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Status_update (CU3_update (f_CU3)))) s\"\n    and \"c_state_update (c_CP0_update (Status_update (ERL_update (\\<lambda>_. f_ERL (ERL (Status (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Status_update (ERL_update (f_ERL)))) s\"\n    and \"c_state_update (c_CP0_update (Status_update (EXL_update (\\<lambda>_. f_EXL (EXL (Status (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Status_update (EXL_update (f_EXL)))) s\"\n    and \"c_state_update (c_CP0_update (Status_update (FR_update (\\<lambda>_. f_FR (FR (Status (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Status_update (FR_update (f_FR)))) s\"\n    and \"c_state_update (c_CP0_update (Status_update (IE_update (\\<lambda>_. f_IE (IE (Status (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Status_update (IE_update (f_IE)))) s\"\n    and \"c_state_update (c_CP0_update (Status_update (IM_update (\\<lambda>_. f_IM (IM (Status (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Status_update (IM_update (f_IM)))) s\"\n    and \"c_state_update (c_CP0_update (Status_update (KSU_update (\\<lambda>_. f_KSU (KSU (Status (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Status_update (KSU_update (f_KSU)))) s\"\n    and \"c_state_update (c_CP0_update (Status_update (KX_update (\\<lambda>_. f_KX (KX (Status (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Status_update (KX_update (f_KX)))) s\"\n    and \"c_state_update (c_CP0_update (Status_update (StatusRegister.RE_update (\\<lambda>_. f_StatusRegisterRE (StatusRegister.RE (Status (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Status_update (StatusRegister.RE_update (f_StatusRegisterRE)))) s\"\n    and \"c_state_update (c_CP0_update (Status_update (SX_update (\\<lambda>_. f_SX (SX (Status (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Status_update (SX_update (f_SX)))) s\"\n    and \"c_state_update (c_CP0_update (Status_update (UX_update (\\<lambda>_. f_UX (UX (Status (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Status_update (UX_update (f_UX)))) s\"\n    and \"c_state_update (c_CP0_update (Status_update (statusregister'rst_update (\\<lambda>_. f_statusregister'rst (statusregister'rst (Status (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Status_update (statusregister'rst_update (f_statusregister'rst)))) s\"\n    and \"c_state_update (c_CP0_update (UsrLocal_update (\\<lambda>_. f_UsrLocal (UsrLocal (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (UsrLocal_update (f_UsrLocal))) s\"\n    and \"c_state_update (c_CP0_update (Wired_update (\\<lambda>_. f_Wired (Wired (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (Wired_update (f_Wired))) s\"\n    and \"c_state_update (c_CP0_update (Wired_update (Wired.Wired_update (\\<lambda>_. f_WiredWired (Wired.Wired (Wired (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Wired_update (Wired.Wired_update (f_WiredWired)))) s\"\n    and \"c_state_update (c_CP0_update (Wired_update (wired'rst_update (\\<lambda>_. f_wired'rst (wired'rst (Wired (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (Wired_update (wired'rst_update (f_wired'rst)))) s\"\n    and \"c_state_update (c_CP0_update (XContext_update (\\<lambda>_. f_XContext (XContext (c_CP0 (c_state s)))))) s = \n         c_state_update (c_CP0_update (XContext_update (f_XContext))) s\"\n    and \"c_state_update (c_CP0_update (XContext_update (XContext.BadVPN2_update (\\<lambda>_. f_XContextBadVPN2 (XContext.BadVPN2 (XContext (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (XContext_update (XContext.BadVPN2_update (f_XContextBadVPN2)))) s\"\n    and \"c_state_update (c_CP0_update (XContext_update (XContext.PTEBase_update (\\<lambda>_. f_XContextPTEBase (XContext.PTEBase (XContext (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (XContext_update (XContext.PTEBase_update (f_XContextPTEBase)))) s\"\n    and \"c_state_update (c_CP0_update (XContext_update (XContext.R_update (\\<lambda>_. f_XContextR (XContext.R (XContext (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (XContext_update (XContext.R_update (f_XContextR)))) s\"\n    and \"c_state_update (c_CP0_update (XContext_update (xcontext'rst_update (\\<lambda>_. f_xcontext'rst (xcontext'rst (XContext (c_CP0 (c_state s)))))))) s = \n         c_state_update (c_CP0_update (XContext_update (xcontext'rst_update (f_xcontext'rst)))) s\"\n    and \"c_state_update (c_CoreStats_update (\\<lambda>_. f_c_CoreStats (c_CoreStats (c_state s)))) s = \n         c_state_update (c_CoreStats_update (f_c_CoreStats)) s\"\n    and \"c_state_update (c_CoreStats_update (branch_not_taken_update (\\<lambda>_. f_branch_not_taken (branch_not_taken (c_CoreStats (c_state s)))))) s = \n         c_state_update (c_CoreStats_update (branch_not_taken_update (f_branch_not_taken))) s\"\n    and \"c_state_update (c_CoreStats_update (branch_taken_update (\\<lambda>_. f_branch_taken (branch_taken (c_CoreStats (c_state s)))))) s = \n         c_state_update (c_CoreStats_update (branch_taken_update (f_branch_taken))) s\"\n    and \"c_state_update (c_LLbit_update (\\<lambda>_. f_c_LLbit (c_LLbit (c_state s)))) s = \n         c_state_update (c_LLbit_update (f_c_LLbit)) s\"\n    and \"c_state_update (c_PC_update (\\<lambda>_. f_c_PC (c_PC (c_state s)))) s = \n         c_state_update (c_PC_update (f_c_PC)) s\"\n    and \"c_state_update (c_exceptionSignalled_update (\\<lambda>_. f_c_exceptionSignalled (c_exceptionSignalled (c_state s)))) s = \n         c_state_update (c_exceptionSignalled_update (f_c_exceptionSignalled)) s\"\n    and \"c_state_update (c_hi_update (\\<lambda>_. f_c_hi (c_hi (c_state s)))) s = \n         c_state_update (c_hi_update (f_c_hi)) s\"\n    and \"c_state_update (c_lo_update (\\<lambda>_. f_c_lo (c_lo (c_state s)))) s = \n         c_state_update (c_lo_update (f_c_lo)) s\"\n    and \"capcause_update (\\<lambda>_. f_capcause (capcause s)) s = \n         capcause_update (f_capcause) s\"\n    and \"csv_stats_header_done_update (\\<lambda>_. f_csv_stats_header_done (csv_stats_header_done s)) s = \n         csv_stats_header_done_update (f_csv_stats_header_done) s\"\n    and \"currentInst_update (\\<lambda>_. f_currentInst (currentInst s)) s = \n         currentInst_update (f_currentInst) s\"\n    and \"done_update (\\<lambda>_. f_done (done s)) s = \n         done_update (f_done) s\"\n    and \"dynamicMemStats_update (\\<lambda>_. f_dynamicMemStats (dynamicMemStats s)) s = \n         dynamicMemStats_update (f_dynamicMemStats) s\"\n    and \"dynamic_shadow_16K_TAGS_update (\\<lambda>_. f_dynamic_shadow_16K_TAGS (dynamic_shadow_16K_TAGS s)) s = \n         dynamic_shadow_16K_TAGS_update (f_dynamic_shadow_16K_TAGS) s\"\n    and \"dynamic_shadow_4K_MEM_update (\\<lambda>_. f_dynamic_shadow_4K_MEM (dynamic_shadow_4K_MEM s)) s = \n         dynamic_shadow_4K_MEM_update (f_dynamic_shadow_4K_MEM) s\"\n    and \"dynamic_shadow_4K_TAGS_update (\\<lambda>_. f_dynamic_shadow_4K_TAGS (dynamic_shadow_4K_TAGS s)) s = \n         dynamic_shadow_4K_TAGS_update (f_dynamic_shadow_4K_TAGS) s\"\n    and \"dynamic_shadow_MEM_update (\\<lambda>_. f_dynamic_shadow_MEM (dynamic_shadow_MEM s)) s = \n         dynamic_shadow_MEM_update (f_dynamic_shadow_MEM) s\"\n    and \"dynamic_shadow_TAGS_update (\\<lambda>_. f_dynamic_shadow_TAGS (dynamic_shadow_TAGS s)) s = \n         dynamic_shadow_TAGS_update (f_dynamic_shadow_TAGS) s\"\n    and \"exception_update (\\<lambda>_. f_exception (exception s)) s = \n         exception_update (f_exception) s\"\n    and \"hasCP1_update (\\<lambda>_. f_hasCP1 (hasCP1 s)) s = \n         hasCP1_update (f_hasCP1) s\"\n    and \"hasCP2_update (\\<lambda>_. f_hasCP2 (hasCP2 s)) s = \n         hasCP2_update (f_hasCP2) s\"\n    and \"instCnt_update (\\<lambda>_. f_instCnt (instCnt s)) s = \n         instCnt_update (f_instCnt) s\"\n    and \"lastInst_update (\\<lambda>_. f_lastInst (lastInst s)) s = \n         lastInst_update (f_lastInst) s\"\n    and \"log_update (\\<lambda>_. f_log (log s)) s = \n         log_update (f_log) s\"\n    and \"memAccessStats_update (\\<lambda>_. f_memAccessStats (memAccessStats s)) s = \n         memAccessStats_update (f_memAccessStats) s\"\n    and \"print_update (\\<lambda>_. f_print (print s)) s = \n         print_update (f_print) s\"\n    and \"procID_update (\\<lambda>_. f_procID (procID s)) s = \n         procID_update (f_procID) s\"\n    and \"staticMemStats_update (\\<lambda>_. f_staticMemStats (staticMemStats s)) s = \n         staticMemStats_update (f_staticMemStats) s\"\n    and \"static_shadow_16K_TAGS_update (\\<lambda>_. f_static_shadow_16K_TAGS (static_shadow_16K_TAGS s)) s = \n         static_shadow_16K_TAGS_update (f_static_shadow_16K_TAGS) s\"\n    and \"static_shadow_4K_MEM_update (\\<lambda>_. f_static_shadow_4K_MEM (static_shadow_4K_MEM s)) s = \n         static_shadow_4K_MEM_update (f_static_shadow_4K_MEM) s\"\n    and \"static_shadow_4K_TAGS_update (\\<lambda>_. f_static_shadow_4K_TAGS (static_shadow_4K_TAGS s)) s = \n         static_shadow_4K_TAGS_update (f_static_shadow_4K_TAGS) s\"\n    and \"static_shadow_MEM_update (\\<lambda>_. f_static_shadow_MEM (static_shadow_MEM s)) s = \n         static_shadow_MEM_update (f_static_shadow_MEM) s\"\n    and \"static_shadow_TAGS_update (\\<lambda>_. f_static_shadow_TAGS (static_shadow_TAGS s)) s = \n         static_shadow_TAGS_update (f_static_shadow_TAGS) s\"\n    and \"the_MEM_update (\\<lambda>_. f_the_MEM (the_MEM s)) s = \n         the_MEM_update (f_the_MEM) s\"\n    and \"totalCore_update (\\<lambda>_. f_totalCore (totalCore s)) s = \n         totalCore_update (f_totalCore) s\"\n    and \"trace_level_update (\\<lambda>_. f_trace_level (trace_level s)) s = \n         trace_level_update (f_trace_level) s\"\n    and \"unknown_counters_update (\\<lambda>_. f_unknown_counters (unknown_counters s)) s = \n         unknown_counters_update (f_unknown_counters) s\"\n    and \"watchOOBCap_update (\\<lambda>_. f_watchOOBCap (watchOOBCap s)) s = \n         watchOOBCap_update (f_watchOOBCap) s\"\n    and \"watchPaddr_update (\\<lambda>_. f_watchPaddr (watchPaddr s)) s = \n         watchPaddr_update (f_watchPaddr) s\"\n    and \"watcher_update (\\<lambda>_. f_watcher (watcher s)) s = \n         watcher_update (f_watcher) s\"\nby simp_all\n\n(* Code generation - end *)\n\n(* Code generation - start - contracting reads and updates *)\n\nsubsection \\<open>@{const c_BranchDelay}\\<close>\n\nabbreviation getBranchDelay where\n  \"getBranchDelay \\<equiv> (\\<lambda>s. c_BranchDelay (c_state s))\"\n\nlemma BranchDelay_alt [alt_def_simp]:\n  shows \"BranchDelay = read_state getBranchDelay\"\nunfolding BranchDelay_def\nunfolding monad_def Let_def\nby simp\n\nlemmas contract_c_state_BranchDelay [alt_def_simp] = \n  contract_read[where getParent=c_state and sub=c_BranchDelay]\n\nabbreviation setBranchDelay where\n  \"setBranchDelay v \\<equiv> c_state_update (c_BranchDelay_update (\\<lambda>_. v))\"\n\nlemma write'BranchDelay_alt [alt_def_simp]:\n  shows \"write'BranchDelay = (\\<lambda>v. update_state (setBranchDelay v))\"\nunfolding write'BranchDelay_def\nunfolding monad_def Let_def\nby (intro ext) simp\n\nlemmas contract_c_state_update_BranchDelay [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=c_state \n                           and setParent=\"\\<lambda>v. c_state_update (\\<lambda>_. v)\"\n                           and sub_update=c_BranchDelay_update]\n  contract_update[where getParent=c_state \n                    and setParent=\"\\<lambda>v. c_state_update (\\<lambda>_. v)\"\n                    and sub=c_BranchDelay\n                    and sub_update=c_BranchDelay_update]\n\nsubsection \\<open>@{const c_BranchTo}\\<close>\n\nabbreviation getBranchTo where\n  \"getBranchTo \\<equiv> (\\<lambda>s. c_BranchTo (c_state s))\"\n\nlemma BranchTo_alt [alt_def_simp]:\n  shows \"BranchTo = read_state getBranchTo\"\nunfolding BranchTo_def\nunfolding monad_def Let_def\nby simp\n\nlemmas contract_c_state_BranchTo [alt_def_simp] = \n  contract_read[where getParent=c_state and sub=c_BranchTo]\n\nabbreviation setBranchTo where\n  \"setBranchTo v \\<equiv> c_state_update (c_BranchTo_update (\\<lambda>_. v))\"\n\nlemma write'BranchTo_alt [alt_def_simp]:\n  shows \"write'BranchTo = (\\<lambda>v. update_state (setBranchTo v))\"\nunfolding write'BranchTo_def\nunfolding monad_def Let_def\nby (intro ext) simp\n\nlemmas contract_c_state_update_BranchTo [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=c_state \n                           and setParent=\"\\<lambda>v. c_state_update (\\<lambda>_. v)\"\n                           and sub_update=c_BranchTo_update]\n  contract_update[where getParent=c_state \n                    and setParent=\"\\<lambda>v. c_state_update (\\<lambda>_. v)\"\n                    and sub=c_BranchTo\n                    and sub_update=c_BranchTo_update]\n\nsubsection \\<open>@{const c_CP0}\\<close>\n\nabbreviation getCP0 where\n  \"getCP0 \\<equiv> (\\<lambda>s. c_CP0 (c_state s))\"\n\nlemma CP0_alt [alt_def_simp]:\n  shows \"CP0 = read_state getCP0\"\nunfolding CP0_def\nunfolding monad_def Let_def\nby simp\n\nlemmas contract_c_state_CP0 [alt_def_simp] = \n  contract_read[where getParent=c_state and sub=c_CP0]\n\nabbreviation setCP0 where\n  \"setCP0 v \\<equiv> c_state_update (c_CP0_update (\\<lambda>_. v))\"\n\nlemma write'CP0_alt [alt_def_simp]:\n  shows \"write'CP0 = (\\<lambda>v. update_state (setCP0 v))\"\nunfolding write'CP0_def\nunfolding monad_def Let_def\nby (intro ext) simp\n\nlemmas contract_c_state_update_CP0 [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=c_state \n                           and setParent=\"\\<lambda>v. c_state_update (\\<lambda>_. v)\"\n                           and sub_update=c_CP0_update]\n  contract_update[where getParent=c_state \n                    and setParent=\"\\<lambda>v. c_state_update (\\<lambda>_. v)\"\n                    and sub=c_CP0\n                    and sub_update=c_CP0_update]\n\nsubsection \\<open>@{const BadInstr}\\<close>\n\nabbreviation getCP0BadInstr where\n  \"getCP0BadInstr \\<equiv> (\\<lambda>s. BadInstr (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0BadInstr [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=BadInstr]\n\nabbreviation setCP0BadInstr where\n  \"setCP0BadInstr v \\<equiv> c_state_update (c_CP0_update (BadInstr_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0BadInstr [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=BadInstr_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=BadInstr\n                    and sub_update=BadInstr_update]\n\nsubsection \\<open>@{const BadInstrP}\\<close>\n\nabbreviation getCP0BadInstrP where\n  \"getCP0BadInstrP \\<equiv> (\\<lambda>s. BadInstrP (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0BadInstrP [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=BadInstrP]\n\nabbreviation setCP0BadInstrP where\n  \"setCP0BadInstrP v \\<equiv> c_state_update (c_CP0_update (BadInstrP_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0BadInstrP [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=BadInstrP_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=BadInstrP\n                    and sub_update=BadInstrP_update]\n\nsubsection \\<open>@{const BadVAddr}\\<close>\n\nabbreviation getCP0BadVAddr where\n  \"getCP0BadVAddr \\<equiv> (\\<lambda>s. BadVAddr (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0BadVAddr [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=BadVAddr]\n\nabbreviation setCP0BadVAddr where\n  \"setCP0BadVAddr v \\<equiv> c_state_update (c_CP0_update (BadVAddr_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0BadVAddr [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=BadVAddr_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=BadVAddr\n                    and sub_update=BadVAddr_update]\n\nsubsection \\<open>@{const Cause}\\<close>\n\nabbreviation getCP0Cause where\n  \"getCP0Cause \\<equiv> (\\<lambda>s. Cause (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0Cause [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=Cause]\n\nabbreviation setCP0Cause where\n  \"setCP0Cause v \\<equiv> c_state_update (c_CP0_update (Cause_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0Cause [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=Cause_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=Cause\n                    and sub_update=Cause_update]\n\nsubsection \\<open>@{const BD}\\<close>\n\nabbreviation getCP0CauseBD where\n  \"getCP0CauseBD \\<equiv> (\\<lambda>s. BD (Cause (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Cause_CP0CauseBD [alt_def_simp] = \n  contract_read[where getParent=getCP0Cause and sub=BD]\n\nabbreviation setCP0CauseBD where\n  \"setCP0CauseBD v \\<equiv> c_state_update (c_CP0_update (Cause_update (BD_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0CauseBD [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Cause\n                           and setParent=setCP0Cause\n                           and sub_update=BD_update]\n  contract_update[where getParent=getCP0Cause \n                    and setParent=setCP0Cause\n                    and sub=BD\n                    and sub_update=BD_update]\n\nsubsection \\<open>@{const CE}\\<close>\n\nabbreviation getCP0CauseCE where\n  \"getCP0CauseCE \\<equiv> (\\<lambda>s. CE (Cause (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Cause_CP0CauseCE [alt_def_simp] = \n  contract_read[where getParent=getCP0Cause and sub=CE]\n\nabbreviation setCP0CauseCE where\n  \"setCP0CauseCE v \\<equiv> c_state_update (c_CP0_update (Cause_update (CE_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0CauseCE [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Cause\n                           and setParent=setCP0Cause\n                           and sub_update=CE_update]\n  contract_update[where getParent=getCP0Cause \n                    and setParent=setCP0Cause\n                    and sub=CE\n                    and sub_update=CE_update]\n\nsubsection \\<open>@{const CauseRegister.ExcCode}\\<close>\n\nabbreviation getCP0CauseExcCode where\n  \"getCP0CauseExcCode \\<equiv> (\\<lambda>s. CauseRegister.ExcCode (Cause (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Cause_CP0CauseExcCode [alt_def_simp] = \n  contract_read[where getParent=getCP0Cause and sub=CauseRegister.ExcCode]\n\nabbreviation setCP0CauseExcCode where\n  \"setCP0CauseExcCode v \\<equiv> c_state_update (c_CP0_update (Cause_update (CauseRegister.ExcCode_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0CauseExcCode [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Cause\n                           and setParent=setCP0Cause\n                           and sub_update=CauseRegister.ExcCode_update]\n  contract_update[where getParent=getCP0Cause \n                    and setParent=setCP0Cause\n                    and sub=CauseRegister.ExcCode\n                    and sub_update=CauseRegister.ExcCode_update]\n\nsubsection \\<open>@{const IP}\\<close>\n\nabbreviation getCP0CauseIP where\n  \"getCP0CauseIP \\<equiv> (\\<lambda>s. IP (Cause (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Cause_CP0CauseIP [alt_def_simp] = \n  contract_read[where getParent=getCP0Cause and sub=IP]\n\nabbreviation setCP0CauseIP where\n  \"setCP0CauseIP v \\<equiv> c_state_update (c_CP0_update (Cause_update (IP_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0CauseIP [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Cause\n                           and setParent=setCP0Cause\n                           and sub_update=IP_update]\n  contract_update[where getParent=getCP0Cause \n                    and setParent=setCP0Cause\n                    and sub=IP\n                    and sub_update=IP_update]\n\nsubsection \\<open>@{const TI}\\<close>\n\nabbreviation getCP0CauseTI where\n  \"getCP0CauseTI \\<equiv> (\\<lambda>s. TI (Cause (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Cause_CP0CauseTI [alt_def_simp] = \n  contract_read[where getParent=getCP0Cause and sub=TI]\n\nabbreviation setCP0CauseTI where\n  \"setCP0CauseTI v \\<equiv> c_state_update (c_CP0_update (Cause_update (TI_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0CauseTI [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Cause\n                           and setParent=setCP0Cause\n                           and sub_update=TI_update]\n  contract_update[where getParent=getCP0Cause \n                    and setParent=setCP0Cause\n                    and sub=TI\n                    and sub_update=TI_update]\n\nsubsection \\<open>@{const causeregister'rst}\\<close>\n\nabbreviation getCP0CauseCauseregister'rst where\n  \"getCP0CauseCauseregister'rst \\<equiv> (\\<lambda>s. causeregister'rst (Cause (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Cause_CP0CauseCauseregister'rst [alt_def_simp] = \n  contract_read[where getParent=getCP0Cause and sub=causeregister'rst]\n\nabbreviation setCP0CauseCauseregister'rst where\n  \"setCP0CauseCauseregister'rst v \\<equiv> c_state_update (c_CP0_update (Cause_update (causeregister'rst_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0CauseCauseregister'rst [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Cause\n                           and setParent=setCP0Cause\n                           and sub_update=causeregister'rst_update]\n  contract_update[where getParent=getCP0Cause \n                    and setParent=setCP0Cause\n                    and sub=causeregister'rst\n                    and sub_update=causeregister'rst_update]\n\nsubsection \\<open>@{const Compare}\\<close>\n\nabbreviation getCP0Compare where\n  \"getCP0Compare \\<equiv> (\\<lambda>s. Compare (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0Compare [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=Compare]\n\nabbreviation setCP0Compare where\n  \"setCP0Compare v \\<equiv> c_state_update (c_CP0_update (Compare_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0Compare [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=Compare_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=Compare\n                    and sub_update=Compare_update]\n\nsubsection \\<open>@{const Config}\\<close>\n\nabbreviation getCP0Config where\n  \"getCP0Config \\<equiv> (\\<lambda>s. Config (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0Config [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=Config]\n\nabbreviation setCP0Config where\n  \"setCP0Config v \\<equiv> c_state_update (c_CP0_update (Config_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0Config [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=Config_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=Config\n                    and sub_update=Config_update]\n\nsubsection \\<open>@{const AR}\\<close>\n\nabbreviation getCP0ConfigAR where\n  \"getCP0ConfigAR \\<equiv> (\\<lambda>s. AR (Config (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Config_CP0ConfigAR [alt_def_simp] = \n  contract_read[where getParent=getCP0Config and sub=AR]\n\nabbreviation setCP0ConfigAR where\n  \"setCP0ConfigAR v \\<equiv> c_state_update (c_CP0_update (Config_update (AR_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0ConfigAR [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Config\n                           and setParent=setCP0Config\n                           and sub_update=AR_update]\n  contract_update[where getParent=getCP0Config \n                    and setParent=setCP0Config\n                    and sub=AR\n                    and sub_update=AR_update]\n\nsubsection \\<open>@{const AT}\\<close>\n\nabbreviation getCP0ConfigAT where\n  \"getCP0ConfigAT \\<equiv> (\\<lambda>s. AT (Config (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Config_CP0ConfigAT [alt_def_simp] = \n  contract_read[where getParent=getCP0Config and sub=AT]\n\nabbreviation setCP0ConfigAT where\n  \"setCP0ConfigAT v \\<equiv> c_state_update (c_CP0_update (Config_update (AT_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0ConfigAT [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Config\n                           and setParent=setCP0Config\n                           and sub_update=AT_update]\n  contract_update[where getParent=getCP0Config \n                    and setParent=setCP0Config\n                    and sub=AT\n                    and sub_update=AT_update]\n\nsubsection \\<open>@{const BE}\\<close>\n\nabbreviation getCP0ConfigBE where\n  \"getCP0ConfigBE \\<equiv> (\\<lambda>s. BE (Config (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Config_CP0ConfigBE [alt_def_simp] = \n  contract_read[where getParent=getCP0Config and sub=BE]\n\nabbreviation setCP0ConfigBE where\n  \"setCP0ConfigBE v \\<equiv> c_state_update (c_CP0_update (Config_update (BE_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0ConfigBE [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Config\n                           and setParent=setCP0Config\n                           and sub_update=BE_update]\n  contract_update[where getParent=getCP0Config \n                    and setParent=setCP0Config\n                    and sub=BE\n                    and sub_update=BE_update]\n\nsubsection \\<open>@{const K0}\\<close>\n\nabbreviation getCP0ConfigK0 where\n  \"getCP0ConfigK0 \\<equiv> (\\<lambda>s. K0 (Config (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Config_CP0ConfigK0 [alt_def_simp] = \n  contract_read[where getParent=getCP0Config and sub=K0]\n\nabbreviation setCP0ConfigK0 where\n  \"setCP0ConfigK0 v \\<equiv> c_state_update (c_CP0_update (Config_update (K0_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0ConfigK0 [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Config\n                           and setParent=setCP0Config\n                           and sub_update=K0_update]\n  contract_update[where getParent=getCP0Config \n                    and setParent=setCP0Config\n                    and sub=K0\n                    and sub_update=K0_update]\n\nsubsection \\<open>@{const ConfigRegister.M}\\<close>\n\nabbreviation getCP0ConfigM where\n  \"getCP0ConfigM \\<equiv> (\\<lambda>s. ConfigRegister.M (Config (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Config_CP0ConfigM [alt_def_simp] = \n  contract_read[where getParent=getCP0Config and sub=ConfigRegister.M]\n\nabbreviation setCP0ConfigM where\n  \"setCP0ConfigM v \\<equiv> c_state_update (c_CP0_update (Config_update (ConfigRegister.M_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0ConfigM [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Config\n                           and setParent=setCP0Config\n                           and sub_update=ConfigRegister.M_update]\n  contract_update[where getParent=getCP0Config \n                    and setParent=setCP0Config\n                    and sub=ConfigRegister.M\n                    and sub_update=ConfigRegister.M_update]\n\nsubsection \\<open>@{const ConfigRegister.MT}\\<close>\n\nabbreviation getCP0ConfigMT where\n  \"getCP0ConfigMT \\<equiv> (\\<lambda>s. ConfigRegister.MT (Config (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Config_CP0ConfigMT [alt_def_simp] = \n  contract_read[where getParent=getCP0Config and sub=ConfigRegister.MT]\n\nabbreviation setCP0ConfigMT where\n  \"setCP0ConfigMT v \\<equiv> c_state_update (c_CP0_update (Config_update (ConfigRegister.MT_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0ConfigMT [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Config\n                           and setParent=setCP0Config\n                           and sub_update=ConfigRegister.MT_update]\n  contract_update[where getParent=getCP0Config \n                    and setParent=setCP0Config\n                    and sub=ConfigRegister.MT\n                    and sub_update=ConfigRegister.MT_update]\n\nsubsection \\<open>@{const configregister'rst}\\<close>\n\nabbreviation getCP0ConfigConfigregister'rst where\n  \"getCP0ConfigConfigregister'rst \\<equiv> (\\<lambda>s. configregister'rst (Config (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Config_CP0ConfigConfigregister'rst [alt_def_simp] = \n  contract_read[where getParent=getCP0Config and sub=configregister'rst]\n\nabbreviation setCP0ConfigConfigregister'rst where\n  \"setCP0ConfigConfigregister'rst v \\<equiv> c_state_update (c_CP0_update (Config_update (configregister'rst_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0ConfigConfigregister'rst [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Config\n                           and setParent=setCP0Config\n                           and sub_update=configregister'rst_update]\n  contract_update[where getParent=getCP0Config \n                    and setParent=setCP0Config\n                    and sub=configregister'rst\n                    and sub_update=configregister'rst_update]\n\nsubsection \\<open>@{const Config1}\\<close>\n\nabbreviation getCP0Config1 where\n  \"getCP0Config1 \\<equiv> (\\<lambda>s. Config1 (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0Config1 [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=Config1]\n\nabbreviation setCP0Config1 where\n  \"setCP0Config1 v \\<equiv> c_state_update (c_CP0_update (Config1_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0Config1 [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=Config1_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=Config1\n                    and sub_update=Config1_update]\n\nsubsection \\<open>@{const Config2}\\<close>\n\nabbreviation getCP0Config2 where\n  \"getCP0Config2 \\<equiv> (\\<lambda>s. Config2 (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0Config2 [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=Config2]\n\nabbreviation setCP0Config2 where\n  \"setCP0Config2 v \\<equiv> c_state_update (c_CP0_update (Config2_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0Config2 [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=Config2_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=Config2\n                    and sub_update=Config2_update]\n\nsubsection \\<open>@{const Config3}\\<close>\n\nabbreviation getCP0Config3 where\n  \"getCP0Config3 \\<equiv> (\\<lambda>s. Config3 (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0Config3 [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=Config3]\n\nabbreviation setCP0Config3 where\n  \"setCP0Config3 v \\<equiv> c_state_update (c_CP0_update (Config3_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0Config3 [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=Config3_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=Config3\n                    and sub_update=Config3_update]\n\nsubsection \\<open>@{const Config6}\\<close>\n\nabbreviation getCP0Config6 where\n  \"getCP0Config6 \\<equiv> (\\<lambda>s. Config6 (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0Config6 [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=Config6]\n\nabbreviation setCP0Config6 where\n  \"setCP0Config6 v \\<equiv> c_state_update (c_CP0_update (Config6_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0Config6 [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=Config6_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=Config6\n                    and sub_update=Config6_update]\n\nsubsection \\<open>@{const Context}\\<close>\n\nabbreviation getCP0Context where\n  \"getCP0Context \\<equiv> (\\<lambda>s. Context (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0Context [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=Context]\n\nabbreviation setCP0Context where\n  \"setCP0Context v \\<equiv> c_state_update (c_CP0_update (Context_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0Context [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=Context_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=Context\n                    and sub_update=Context_update]\n\nsubsection \\<open>@{const Context.BadVPN2}\\<close>\n\nabbreviation getCP0ContextBadVPN2 where\n  \"getCP0ContextBadVPN2 \\<equiv> (\\<lambda>s. Context.BadVPN2 (Context (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Context_CP0ContextBadVPN2 [alt_def_simp] = \n  contract_read[where getParent=getCP0Context and sub=Context.BadVPN2]\n\nabbreviation setCP0ContextBadVPN2 where\n  \"setCP0ContextBadVPN2 v \\<equiv> c_state_update (c_CP0_update (Context_update (Context.BadVPN2_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0ContextBadVPN2 [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Context\n                           and setParent=setCP0Context\n                           and sub_update=Context.BadVPN2_update]\n  contract_update[where getParent=getCP0Context \n                    and setParent=setCP0Context\n                    and sub=Context.BadVPN2\n                    and sub_update=Context.BadVPN2_update]\n\nsubsection \\<open>@{const Context.PTEBase}\\<close>\n\nabbreviation getCP0ContextPTEBase where\n  \"getCP0ContextPTEBase \\<equiv> (\\<lambda>s. Context.PTEBase (Context (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Context_CP0ContextPTEBase [alt_def_simp] = \n  contract_read[where getParent=getCP0Context and sub=Context.PTEBase]\n\nabbreviation setCP0ContextPTEBase where\n  \"setCP0ContextPTEBase v \\<equiv> c_state_update (c_CP0_update (Context_update (Context.PTEBase_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0ContextPTEBase [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Context\n                           and setParent=setCP0Context\n                           and sub_update=Context.PTEBase_update]\n  contract_update[where getParent=getCP0Context \n                    and setParent=setCP0Context\n                    and sub=Context.PTEBase\n                    and sub_update=Context.PTEBase_update]\n\nsubsection \\<open>@{const context'rst}\\<close>\n\nabbreviation getCP0ContextContext'rst where\n  \"getCP0ContextContext'rst \\<equiv> (\\<lambda>s. context'rst (Context (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Context_CP0ContextContext'rst [alt_def_simp] = \n  contract_read[where getParent=getCP0Context and sub=context'rst]\n\nabbreviation setCP0ContextContext'rst where\n  \"setCP0ContextContext'rst v \\<equiv> c_state_update (c_CP0_update (Context_update (context'rst_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0ContextContext'rst [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Context\n                           and setParent=setCP0Context\n                           and sub_update=context'rst_update]\n  contract_update[where getParent=getCP0Context \n                    and setParent=setCP0Context\n                    and sub=context'rst\n                    and sub_update=context'rst_update]\n\nsubsection \\<open>@{const Count}\\<close>\n\nabbreviation getCP0Count where\n  \"getCP0Count \\<equiv> (\\<lambda>s. Count (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0Count [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=Count]\n\nabbreviation setCP0Count where\n  \"setCP0Count v \\<equiv> c_state_update (c_CP0_update (Count_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0Count [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=Count_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=Count\n                    and sub_update=Count_update]\n\nsubsection \\<open>@{const Debug}\\<close>\n\nabbreviation getCP0Debug where\n  \"getCP0Debug \\<equiv> (\\<lambda>s. Debug (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0Debug [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=Debug]\n\nabbreviation setCP0Debug where\n  \"setCP0Debug v \\<equiv> c_state_update (c_CP0_update (Debug_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0Debug [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=Debug_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=Debug\n                    and sub_update=Debug_update]\n\nsubsection \\<open>@{const EPC}\\<close>\n\nabbreviation getCP0EPC where\n  \"getCP0EPC \\<equiv> (\\<lambda>s. EPC (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0EPC [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=EPC]\n\nabbreviation setCP0EPC where\n  \"setCP0EPC v \\<equiv> c_state_update (c_CP0_update (EPC_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0EPC [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=EPC_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=EPC\n                    and sub_update=EPC_update]\n\nsubsection \\<open>@{const EntryHi}\\<close>\n\nabbreviation getCP0EntryHi where\n  \"getCP0EntryHi \\<equiv> (\\<lambda>s. EntryHi (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0EntryHi [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=EntryHi]\n\nabbreviation setCP0EntryHi where\n  \"setCP0EntryHi v \\<equiv> c_state_update (c_CP0_update (EntryHi_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0EntryHi [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=EntryHi_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=EntryHi\n                    and sub_update=EntryHi_update]\n\nsubsection \\<open>@{const EntryHi.ASID}\\<close>\n\nabbreviation getCP0EntryHiASID where\n  \"getCP0EntryHiASID \\<equiv> (\\<lambda>s. EntryHi.ASID (EntryHi (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0EntryHi_CP0EntryHiASID [alt_def_simp] = \n  contract_read[where getParent=getCP0EntryHi and sub=EntryHi.ASID]\n\nabbreviation setCP0EntryHiASID where\n  \"setCP0EntryHiASID v \\<equiv> c_state_update (c_CP0_update (EntryHi_update (EntryHi.ASID_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0EntryHiASID [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0EntryHi\n                           and setParent=setCP0EntryHi\n                           and sub_update=EntryHi.ASID_update]\n  contract_update[where getParent=getCP0EntryHi \n                    and setParent=setCP0EntryHi\n                    and sub=EntryHi.ASID\n                    and sub_update=EntryHi.ASID_update]\n\nsubsection \\<open>@{const EntryHi.R}\\<close>\n\nabbreviation getCP0EntryHiR where\n  \"getCP0EntryHiR \\<equiv> (\\<lambda>s. EntryHi.R (EntryHi (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0EntryHi_CP0EntryHiR [alt_def_simp] = \n  contract_read[where getParent=getCP0EntryHi and sub=EntryHi.R]\n\nabbreviation setCP0EntryHiR where\n  \"setCP0EntryHiR v \\<equiv> c_state_update (c_CP0_update (EntryHi_update (EntryHi.R_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0EntryHiR [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0EntryHi\n                           and setParent=setCP0EntryHi\n                           and sub_update=EntryHi.R_update]\n  contract_update[where getParent=getCP0EntryHi \n                    and setParent=setCP0EntryHi\n                    and sub=EntryHi.R\n                    and sub_update=EntryHi.R_update]\n\nsubsection \\<open>@{const EntryHi.VPN2}\\<close>\n\nabbreviation getCP0EntryHiVPN2 where\n  \"getCP0EntryHiVPN2 \\<equiv> (\\<lambda>s. EntryHi.VPN2 (EntryHi (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0EntryHi_CP0EntryHiVPN2 [alt_def_simp] = \n  contract_read[where getParent=getCP0EntryHi and sub=EntryHi.VPN2]\n\nabbreviation setCP0EntryHiVPN2 where\n  \"setCP0EntryHiVPN2 v \\<equiv> c_state_update (c_CP0_update (EntryHi_update (EntryHi.VPN2_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0EntryHiVPN2 [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0EntryHi\n                           and setParent=setCP0EntryHi\n                           and sub_update=EntryHi.VPN2_update]\n  contract_update[where getParent=getCP0EntryHi \n                    and setParent=setCP0EntryHi\n                    and sub=EntryHi.VPN2\n                    and sub_update=EntryHi.VPN2_update]\n\nsubsection \\<open>@{const entryhi'rst}\\<close>\n\nabbreviation getCP0EntryHiEntryhi'rst where\n  \"getCP0EntryHiEntryhi'rst \\<equiv> (\\<lambda>s. entryhi'rst (EntryHi (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0EntryHi_CP0EntryHiEntryhi'rst [alt_def_simp] = \n  contract_read[where getParent=getCP0EntryHi and sub=entryhi'rst]\n\nabbreviation setCP0EntryHiEntryhi'rst where\n  \"setCP0EntryHiEntryhi'rst v \\<equiv> c_state_update (c_CP0_update (EntryHi_update (entryhi'rst_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0EntryHiEntryhi'rst [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0EntryHi\n                           and setParent=setCP0EntryHi\n                           and sub_update=entryhi'rst_update]\n  contract_update[where getParent=getCP0EntryHi \n                    and setParent=setCP0EntryHi\n                    and sub=entryhi'rst\n                    and sub_update=entryhi'rst_update]\n\nsubsection \\<open>@{const EntryLo0}\\<close>\n\nabbreviation getCP0EntryLo0 where\n  \"getCP0EntryLo0 \\<equiv> (\\<lambda>s. EntryLo0 (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0EntryLo0 [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=EntryLo0]\n\nabbreviation setCP0EntryLo0 where\n  \"setCP0EntryLo0 v \\<equiv> c_state_update (c_CP0_update (EntryLo0_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0EntryLo0 [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=EntryLo0_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=EntryLo0\n                    and sub_update=EntryLo0_update]\n\nsubsection \\<open>@{const EntryLo1}\\<close>\n\nabbreviation getCP0EntryLo1 where\n  \"getCP0EntryLo1 \\<equiv> (\\<lambda>s. EntryLo1 (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0EntryLo1 [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=EntryLo1]\n\nabbreviation setCP0EntryLo1 where\n  \"setCP0EntryLo1 v \\<equiv> c_state_update (c_CP0_update (EntryLo1_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0EntryLo1 [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=EntryLo1_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=EntryLo1\n                    and sub_update=EntryLo1_update]\n\nsubsection \\<open>@{const ErrCtl}\\<close>\n\nabbreviation getCP0ErrCtl where\n  \"getCP0ErrCtl \\<equiv> (\\<lambda>s. ErrCtl (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0ErrCtl [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=ErrCtl]\n\nabbreviation setCP0ErrCtl where\n  \"setCP0ErrCtl v \\<equiv> c_state_update (c_CP0_update (ErrCtl_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0ErrCtl [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=ErrCtl_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=ErrCtl\n                    and sub_update=ErrCtl_update]\n\nsubsection \\<open>@{const ErrorEPC}\\<close>\n\nabbreviation getCP0ErrorEPC where\n  \"getCP0ErrorEPC \\<equiv> (\\<lambda>s. ErrorEPC (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0ErrorEPC [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=ErrorEPC]\n\nabbreviation setCP0ErrorEPC where\n  \"setCP0ErrorEPC v \\<equiv> c_state_update (c_CP0_update (ErrorEPC_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0ErrorEPC [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=ErrorEPC_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=ErrorEPC\n                    and sub_update=ErrorEPC_update]\n\nsubsection \\<open>@{const HWREna}\\<close>\n\nabbreviation getCP0HWREna where\n  \"getCP0HWREna \\<equiv> (\\<lambda>s. HWREna (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0HWREna [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=HWREna]\n\nabbreviation setCP0HWREna where\n  \"setCP0HWREna v \\<equiv> c_state_update (c_CP0_update (HWREna_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0HWREna [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=HWREna_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=HWREna\n                    and sub_update=HWREna_update]\n\nsubsection \\<open>@{const Index}\\<close>\n\nabbreviation getCP0Index where\n  \"getCP0Index \\<equiv> (\\<lambda>s. Index (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0Index [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=Index]\n\nabbreviation setCP0Index where\n  \"setCP0Index v \\<equiv> c_state_update (c_CP0_update (Index_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0Index [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=Index_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=Index\n                    and sub_update=Index_update]\n\nsubsection \\<open>@{const LLAddr}\\<close>\n\nabbreviation getCP0LLAddr where\n  \"getCP0LLAddr \\<equiv> (\\<lambda>s. LLAddr (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0LLAddr [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=LLAddr]\n\nabbreviation setCP0LLAddr where\n  \"setCP0LLAddr v \\<equiv> c_state_update (c_CP0_update (LLAddr_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0LLAddr [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=LLAddr_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=LLAddr\n                    and sub_update=LLAddr_update]\n\nsubsection \\<open>@{const PRId}\\<close>\n\nabbreviation getCP0PRId where\n  \"getCP0PRId \\<equiv> (\\<lambda>s. PRId (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0PRId [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=PRId]\n\nabbreviation setCP0PRId where\n  \"setCP0PRId v \\<equiv> c_state_update (c_CP0_update (PRId_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0PRId [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=PRId_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=PRId\n                    and sub_update=PRId_update]\n\nsubsection \\<open>@{const PageMask}\\<close>\n\nabbreviation getCP0PageMask where\n  \"getCP0PageMask \\<equiv> (\\<lambda>s. PageMask (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0PageMask [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=PageMask]\n\nabbreviation setCP0PageMask where\n  \"setCP0PageMask v \\<equiv> c_state_update (c_CP0_update (PageMask_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0PageMask [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=PageMask_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=PageMask\n                    and sub_update=PageMask_update]\n\nsubsection \\<open>@{const Random}\\<close>\n\nabbreviation getCP0Random where\n  \"getCP0Random \\<equiv> (\\<lambda>s. Random (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0Random [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=Random]\n\nabbreviation setCP0Random where\n  \"setCP0Random v \\<equiv> c_state_update (c_CP0_update (Random_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0Random [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=Random_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=Random\n                    and sub_update=Random_update]\n\nsubsection \\<open>@{const Random.Random}\\<close>\n\nabbreviation getCP0RandomRandom where\n  \"getCP0RandomRandom \\<equiv> (\\<lambda>s. Random.Random (Random (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Random_CP0RandomRandom [alt_def_simp] = \n  contract_read[where getParent=getCP0Random and sub=Random.Random]\n\nabbreviation setCP0RandomRandom where\n  \"setCP0RandomRandom v \\<equiv> c_state_update (c_CP0_update (Random_update (Random.Random_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0RandomRandom [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Random\n                           and setParent=setCP0Random\n                           and sub_update=Random.Random_update]\n  contract_update[where getParent=getCP0Random \n                    and setParent=setCP0Random\n                    and sub=Random.Random\n                    and sub_update=Random.Random_update]\n\nsubsection \\<open>@{const random'rst}\\<close>\n\nabbreviation getCP0RandomRandom'rst where\n  \"getCP0RandomRandom'rst \\<equiv> (\\<lambda>s. random'rst (Random (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Random_CP0RandomRandom'rst [alt_def_simp] = \n  contract_read[where getParent=getCP0Random and sub=random'rst]\n\nabbreviation setCP0RandomRandom'rst where\n  \"setCP0RandomRandom'rst v \\<equiv> c_state_update (c_CP0_update (Random_update (random'rst_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0RandomRandom'rst [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Random\n                           and setParent=setCP0Random\n                           and sub_update=random'rst_update]\n  contract_update[where getParent=getCP0Random \n                    and setParent=setCP0Random\n                    and sub=random'rst\n                    and sub_update=random'rst_update]\n\nsubsection \\<open>@{const Status}\\<close>\n\nabbreviation getCP0Status where\n  \"getCP0Status \\<equiv> (\\<lambda>s. Status (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0Status [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=Status]\n\nabbreviation setCP0Status where\n  \"setCP0Status v \\<equiv> c_state_update (c_CP0_update (Status_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0Status [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=Status_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=Status\n                    and sub_update=Status_update]\n\nsubsection \\<open>@{const BEV}\\<close>\n\nabbreviation getCP0StatusBEV where\n  \"getCP0StatusBEV \\<equiv> (\\<lambda>s. BEV (Status (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Status_CP0StatusBEV [alt_def_simp] = \n  contract_read[where getParent=getCP0Status and sub=BEV]\n\nabbreviation setCP0StatusBEV where\n  \"setCP0StatusBEV v \\<equiv> c_state_update (c_CP0_update (Status_update (BEV_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0StatusBEV [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Status\n                           and setParent=setCP0Status\n                           and sub_update=BEV_update]\n  contract_update[where getParent=getCP0Status \n                    and setParent=setCP0Status\n                    and sub=BEV\n                    and sub_update=BEV_update]\n\nsubsection \\<open>@{const CU0}\\<close>\n\nabbreviation getCP0StatusCU0 where\n  \"getCP0StatusCU0 \\<equiv> (\\<lambda>s. CU0 (Status (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Status_CP0StatusCU0 [alt_def_simp] = \n  contract_read[where getParent=getCP0Status and sub=CU0]\n\nabbreviation setCP0StatusCU0 where\n  \"setCP0StatusCU0 v \\<equiv> c_state_update (c_CP0_update (Status_update (CU0_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0StatusCU0 [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Status\n                           and setParent=setCP0Status\n                           and sub_update=CU0_update]\n  contract_update[where getParent=getCP0Status \n                    and setParent=setCP0Status\n                    and sub=CU0\n                    and sub_update=CU0_update]\n\nsubsection \\<open>@{const CU1}\\<close>\n\nabbreviation getCP0StatusCU1 where\n  \"getCP0StatusCU1 \\<equiv> (\\<lambda>s. CU1 (Status (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Status_CP0StatusCU1 [alt_def_simp] = \n  contract_read[where getParent=getCP0Status and sub=CU1]\n\nabbreviation setCP0StatusCU1 where\n  \"setCP0StatusCU1 v \\<equiv> c_state_update (c_CP0_update (Status_update (CU1_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0StatusCU1 [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Status\n                           and setParent=setCP0Status\n                           and sub_update=CU1_update]\n  contract_update[where getParent=getCP0Status \n                    and setParent=setCP0Status\n                    and sub=CU1\n                    and sub_update=CU1_update]\n\nsubsection \\<open>@{const CU2}\\<close>\n\nabbreviation getCP0StatusCU2 where\n  \"getCP0StatusCU2 \\<equiv> (\\<lambda>s. CU2 (Status (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Status_CP0StatusCU2 [alt_def_simp] = \n  contract_read[where getParent=getCP0Status and sub=CU2]\n\nabbreviation setCP0StatusCU2 where\n  \"setCP0StatusCU2 v \\<equiv> c_state_update (c_CP0_update (Status_update (CU2_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0StatusCU2 [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Status\n                           and setParent=setCP0Status\n                           and sub_update=CU2_update]\n  contract_update[where getParent=getCP0Status \n                    and setParent=setCP0Status\n                    and sub=CU2\n                    and sub_update=CU2_update]\n\nsubsection \\<open>@{const CU3}\\<close>\n\nabbreviation getCP0StatusCU3 where\n  \"getCP0StatusCU3 \\<equiv> (\\<lambda>s. CU3 (Status (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Status_CP0StatusCU3 [alt_def_simp] = \n  contract_read[where getParent=getCP0Status and sub=CU3]\n\nabbreviation setCP0StatusCU3 where\n  \"setCP0StatusCU3 v \\<equiv> c_state_update (c_CP0_update (Status_update (CU3_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0StatusCU3 [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Status\n                           and setParent=setCP0Status\n                           and sub_update=CU3_update]\n  contract_update[where getParent=getCP0Status \n                    and setParent=setCP0Status\n                    and sub=CU3\n                    and sub_update=CU3_update]\n\nsubsection \\<open>@{const ERL}\\<close>\n\nabbreviation getCP0StatusERL where\n  \"getCP0StatusERL \\<equiv> (\\<lambda>s. ERL (Status (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Status_CP0StatusERL [alt_def_simp] = \n  contract_read[where getParent=getCP0Status and sub=ERL]\n\nabbreviation setCP0StatusERL where\n  \"setCP0StatusERL v \\<equiv> c_state_update (c_CP0_update (Status_update (ERL_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0StatusERL [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Status\n                           and setParent=setCP0Status\n                           and sub_update=ERL_update]\n  contract_update[where getParent=getCP0Status \n                    and setParent=setCP0Status\n                    and sub=ERL\n                    and sub_update=ERL_update]\n\nsubsection \\<open>@{const EXL}\\<close>\n\nabbreviation getCP0StatusEXL where\n  \"getCP0StatusEXL \\<equiv> (\\<lambda>s. EXL (Status (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Status_CP0StatusEXL [alt_def_simp] = \n  contract_read[where getParent=getCP0Status and sub=EXL]\n\nabbreviation setCP0StatusEXL where\n  \"setCP0StatusEXL v \\<equiv> c_state_update (c_CP0_update (Status_update (EXL_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0StatusEXL [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Status\n                           and setParent=setCP0Status\n                           and sub_update=EXL_update]\n  contract_update[where getParent=getCP0Status \n                    and setParent=setCP0Status\n                    and sub=EXL\n                    and sub_update=EXL_update]\n\nsubsection \\<open>@{const FR}\\<close>\n\nabbreviation getCP0StatusFR where\n  \"getCP0StatusFR \\<equiv> (\\<lambda>s. FR (Status (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Status_CP0StatusFR [alt_def_simp] = \n  contract_read[where getParent=getCP0Status and sub=FR]\n\nabbreviation setCP0StatusFR where\n  \"setCP0StatusFR v \\<equiv> c_state_update (c_CP0_update (Status_update (FR_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0StatusFR [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Status\n                           and setParent=setCP0Status\n                           and sub_update=FR_update]\n  contract_update[where getParent=getCP0Status \n                    and setParent=setCP0Status\n                    and sub=FR\n                    and sub_update=FR_update]\n\nsubsection \\<open>@{const IE}\\<close>\n\nabbreviation getCP0StatusIE where\n  \"getCP0StatusIE \\<equiv> (\\<lambda>s. IE (Status (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Status_CP0StatusIE [alt_def_simp] = \n  contract_read[where getParent=getCP0Status and sub=IE]\n\nabbreviation setCP0StatusIE where\n  \"setCP0StatusIE v \\<equiv> c_state_update (c_CP0_update (Status_update (IE_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0StatusIE [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Status\n                           and setParent=setCP0Status\n                           and sub_update=IE_update]\n  contract_update[where getParent=getCP0Status \n                    and setParent=setCP0Status\n                    and sub=IE\n                    and sub_update=IE_update]\n\nsubsection \\<open>@{const IM}\\<close>\n\nabbreviation getCP0StatusIM where\n  \"getCP0StatusIM \\<equiv> (\\<lambda>s. IM (Status (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Status_CP0StatusIM [alt_def_simp] = \n  contract_read[where getParent=getCP0Status and sub=IM]\n\nabbreviation setCP0StatusIM where\n  \"setCP0StatusIM v \\<equiv> c_state_update (c_CP0_update (Status_update (IM_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0StatusIM [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Status\n                           and setParent=setCP0Status\n                           and sub_update=IM_update]\n  contract_update[where getParent=getCP0Status \n                    and setParent=setCP0Status\n                    and sub=IM\n                    and sub_update=IM_update]\n\nsubsection \\<open>@{const KSU}\\<close>\n\nabbreviation getCP0StatusKSU where\n  \"getCP0StatusKSU \\<equiv> (\\<lambda>s. KSU (Status (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Status_CP0StatusKSU [alt_def_simp] = \n  contract_read[where getParent=getCP0Status and sub=KSU]\n\nabbreviation setCP0StatusKSU where\n  \"setCP0StatusKSU v \\<equiv> c_state_update (c_CP0_update (Status_update (KSU_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0StatusKSU [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Status\n                           and setParent=setCP0Status\n                           and sub_update=KSU_update]\n  contract_update[where getParent=getCP0Status \n                    and setParent=setCP0Status\n                    and sub=KSU\n                    and sub_update=KSU_update]\n\nsubsection \\<open>@{const KX}\\<close>\n\nabbreviation getCP0StatusKX where\n  \"getCP0StatusKX \\<equiv> (\\<lambda>s. KX (Status (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Status_CP0StatusKX [alt_def_simp] = \n  contract_read[where getParent=getCP0Status and sub=KX]\n\nabbreviation setCP0StatusKX where\n  \"setCP0StatusKX v \\<equiv> c_state_update (c_CP0_update (Status_update (KX_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0StatusKX [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Status\n                           and setParent=setCP0Status\n                           and sub_update=KX_update]\n  contract_update[where getParent=getCP0Status \n                    and setParent=setCP0Status\n                    and sub=KX\n                    and sub_update=KX_update]\n\nsubsection \\<open>@{const StatusRegister.RE}\\<close>\n\nabbreviation getCP0StatusRE where\n  \"getCP0StatusRE \\<equiv> (\\<lambda>s. StatusRegister.RE (Status (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Status_CP0StatusRE [alt_def_simp] = \n  contract_read[where getParent=getCP0Status and sub=StatusRegister.RE]\n\nabbreviation setCP0StatusRE where\n  \"setCP0StatusRE v \\<equiv> c_state_update (c_CP0_update (Status_update (StatusRegister.RE_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0StatusRE [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Status\n                           and setParent=setCP0Status\n                           and sub_update=StatusRegister.RE_update]\n  contract_update[where getParent=getCP0Status \n                    and setParent=setCP0Status\n                    and sub=StatusRegister.RE\n                    and sub_update=StatusRegister.RE_update]\n\nsubsection \\<open>@{const SX}\\<close>\n\nabbreviation getCP0StatusSX where\n  \"getCP0StatusSX \\<equiv> (\\<lambda>s. SX (Status (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Status_CP0StatusSX [alt_def_simp] = \n  contract_read[where getParent=getCP0Status and sub=SX]\n\nabbreviation setCP0StatusSX where\n  \"setCP0StatusSX v \\<equiv> c_state_update (c_CP0_update (Status_update (SX_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0StatusSX [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Status\n                           and setParent=setCP0Status\n                           and sub_update=SX_update]\n  contract_update[where getParent=getCP0Status \n                    and setParent=setCP0Status\n                    and sub=SX\n                    and sub_update=SX_update]\n\nsubsection \\<open>@{const UX}\\<close>\n\nabbreviation getCP0StatusUX where\n  \"getCP0StatusUX \\<equiv> (\\<lambda>s. UX (Status (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Status_CP0StatusUX [alt_def_simp] = \n  contract_read[where getParent=getCP0Status and sub=UX]\n\nabbreviation setCP0StatusUX where\n  \"setCP0StatusUX v \\<equiv> c_state_update (c_CP0_update (Status_update (UX_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0StatusUX [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Status\n                           and setParent=setCP0Status\n                           and sub_update=UX_update]\n  contract_update[where getParent=getCP0Status \n                    and setParent=setCP0Status\n                    and sub=UX\n                    and sub_update=UX_update]\n\nsubsection \\<open>@{const statusregister'rst}\\<close>\n\nabbreviation getCP0StatusStatusregister'rst where\n  \"getCP0StatusStatusregister'rst \\<equiv> (\\<lambda>s. statusregister'rst (Status (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Status_CP0StatusStatusregister'rst [alt_def_simp] = \n  contract_read[where getParent=getCP0Status and sub=statusregister'rst]\n\nabbreviation setCP0StatusStatusregister'rst where\n  \"setCP0StatusStatusregister'rst v \\<equiv> c_state_update (c_CP0_update (Status_update (statusregister'rst_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0StatusStatusregister'rst [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Status\n                           and setParent=setCP0Status\n                           and sub_update=statusregister'rst_update]\n  contract_update[where getParent=getCP0Status \n                    and setParent=setCP0Status\n                    and sub=statusregister'rst\n                    and sub_update=statusregister'rst_update]\n\nsubsection \\<open>@{const UsrLocal}\\<close>\n\nabbreviation getCP0UsrLocal where\n  \"getCP0UsrLocal \\<equiv> (\\<lambda>s. UsrLocal (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0UsrLocal [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=UsrLocal]\n\nabbreviation setCP0UsrLocal where\n  \"setCP0UsrLocal v \\<equiv> c_state_update (c_CP0_update (UsrLocal_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0UsrLocal [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=UsrLocal_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=UsrLocal\n                    and sub_update=UsrLocal_update]\n\nsubsection \\<open>@{const Wired}\\<close>\n\nabbreviation getCP0Wired where\n  \"getCP0Wired \\<equiv> (\\<lambda>s. Wired (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0Wired [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=Wired]\n\nabbreviation setCP0Wired where\n  \"setCP0Wired v \\<equiv> c_state_update (c_CP0_update (Wired_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0Wired [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=Wired_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=Wired\n                    and sub_update=Wired_update]\n\nsubsection \\<open>@{const Wired.Wired}\\<close>\n\nabbreviation getCP0WiredWired where\n  \"getCP0WiredWired \\<equiv> (\\<lambda>s. Wired.Wired (Wired (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Wired_CP0WiredWired [alt_def_simp] = \n  contract_read[where getParent=getCP0Wired and sub=Wired.Wired]\n\nabbreviation setCP0WiredWired where\n  \"setCP0WiredWired v \\<equiv> c_state_update (c_CP0_update (Wired_update (Wired.Wired_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0WiredWired [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Wired\n                           and setParent=setCP0Wired\n                           and sub_update=Wired.Wired_update]\n  contract_update[where getParent=getCP0Wired \n                    and setParent=setCP0Wired\n                    and sub=Wired.Wired\n                    and sub_update=Wired.Wired_update]\n\nsubsection \\<open>@{const wired'rst}\\<close>\n\nabbreviation getCP0WiredWired'rst where\n  \"getCP0WiredWired'rst \\<equiv> (\\<lambda>s. wired'rst (Wired (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0Wired_CP0WiredWired'rst [alt_def_simp] = \n  contract_read[where getParent=getCP0Wired and sub=wired'rst]\n\nabbreviation setCP0WiredWired'rst where\n  \"setCP0WiredWired'rst v \\<equiv> c_state_update (c_CP0_update (Wired_update (wired'rst_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0WiredWired'rst [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0Wired\n                           and setParent=setCP0Wired\n                           and sub_update=wired'rst_update]\n  contract_update[where getParent=getCP0Wired \n                    and setParent=setCP0Wired\n                    and sub=wired'rst\n                    and sub_update=wired'rst_update]\n\nsubsection \\<open>@{const XContext}\\<close>\n\nabbreviation getCP0XContext where\n  \"getCP0XContext \\<equiv> (\\<lambda>s. XContext (c_CP0 (c_state s)))\"\n\nlemmas contract_getCP0_CP0XContext [alt_def_simp] = \n  contract_read[where getParent=getCP0 and sub=XContext]\n\nabbreviation setCP0XContext where\n  \"setCP0XContext v \\<equiv> c_state_update (c_CP0_update (XContext_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CP0XContext [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0\n                           and setParent=setCP0\n                           and sub_update=XContext_update]\n  contract_update[where getParent=getCP0 \n                    and setParent=setCP0\n                    and sub=XContext\n                    and sub_update=XContext_update]\n\nsubsection \\<open>@{const XContext.BadVPN2}\\<close>\n\nabbreviation getCP0XContextBadVPN2 where\n  \"getCP0XContextBadVPN2 \\<equiv> (\\<lambda>s. XContext.BadVPN2 (XContext (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0XContext_CP0XContextBadVPN2 [alt_def_simp] = \n  contract_read[where getParent=getCP0XContext and sub=XContext.BadVPN2]\n\nabbreviation setCP0XContextBadVPN2 where\n  \"setCP0XContextBadVPN2 v \\<equiv> c_state_update (c_CP0_update (XContext_update (XContext.BadVPN2_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0XContextBadVPN2 [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0XContext\n                           and setParent=setCP0XContext\n                           and sub_update=XContext.BadVPN2_update]\n  contract_update[where getParent=getCP0XContext \n                    and setParent=setCP0XContext\n                    and sub=XContext.BadVPN2\n                    and sub_update=XContext.BadVPN2_update]\n\nsubsection \\<open>@{const XContext.PTEBase}\\<close>\n\nabbreviation getCP0XContextPTEBase where\n  \"getCP0XContextPTEBase \\<equiv> (\\<lambda>s. XContext.PTEBase (XContext (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0XContext_CP0XContextPTEBase [alt_def_simp] = \n  contract_read[where getParent=getCP0XContext and sub=XContext.PTEBase]\n\nabbreviation setCP0XContextPTEBase where\n  \"setCP0XContextPTEBase v \\<equiv> c_state_update (c_CP0_update (XContext_update (XContext.PTEBase_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0XContextPTEBase [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0XContext\n                           and setParent=setCP0XContext\n                           and sub_update=XContext.PTEBase_update]\n  contract_update[where getParent=getCP0XContext \n                    and setParent=setCP0XContext\n                    and sub=XContext.PTEBase\n                    and sub_update=XContext.PTEBase_update]\n\nsubsection \\<open>@{const XContext.R}\\<close>\n\nabbreviation getCP0XContextR where\n  \"getCP0XContextR \\<equiv> (\\<lambda>s. XContext.R (XContext (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0XContext_CP0XContextR [alt_def_simp] = \n  contract_read[where getParent=getCP0XContext and sub=XContext.R]\n\nabbreviation setCP0XContextR where\n  \"setCP0XContextR v \\<equiv> c_state_update (c_CP0_update (XContext_update (XContext.R_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0XContextR [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0XContext\n                           and setParent=setCP0XContext\n                           and sub_update=XContext.R_update]\n  contract_update[where getParent=getCP0XContext \n                    and setParent=setCP0XContext\n                    and sub=XContext.R\n                    and sub_update=XContext.R_update]\n\nsubsection \\<open>@{const xcontext'rst}\\<close>\n\nabbreviation getCP0XContextXcontext'rst where\n  \"getCP0XContextXcontext'rst \\<equiv> (\\<lambda>s. xcontext'rst (XContext (c_CP0 (c_state s))))\"\n\nlemmas contract_getCP0XContext_CP0XContextXcontext'rst [alt_def_simp] = \n  contract_read[where getParent=getCP0XContext and sub=xcontext'rst]\n\nabbreviation setCP0XContextXcontext'rst where\n  \"setCP0XContextXcontext'rst v \\<equiv> c_state_update (c_CP0_update (XContext_update (xcontext'rst_update (\\<lambda>_. v))))\"\n\nlemmas contract_c_state_update_CP0XContextXcontext'rst [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCP0XContext\n                           and setParent=setCP0XContext\n                           and sub_update=xcontext'rst_update]\n  contract_update[where getParent=getCP0XContext \n                    and setParent=setCP0XContext\n                    and sub=xcontext'rst\n                    and sub_update=xcontext'rst_update]\n\nsubsection \\<open>@{const c_CoreStats}\\<close>\n\nabbreviation getCoreStats where\n  \"getCoreStats \\<equiv> (\\<lambda>s. c_CoreStats (c_state s))\"\n\nlemma coreStats_alt [alt_def_simp]:\n  shows \"coreStats = read_state getCoreStats\"\nunfolding coreStats_def\nunfolding monad_def Let_def\nby simp\n\nlemmas contract_c_state_CoreStats [alt_def_simp] = \n  contract_read[where getParent=c_state and sub=c_CoreStats]\n\nabbreviation setCoreStats where\n  \"setCoreStats v \\<equiv> c_state_update (c_CoreStats_update (\\<lambda>_. v))\"\n\nlemma write'coreStats_alt [alt_def_simp]:\n  shows \"write'coreStats = (\\<lambda>v. update_state (setCoreStats v))\"\nunfolding write'coreStats_def\nunfolding monad_def Let_def\nby (intro ext) simp\n\nlemmas contract_c_state_update_CoreStats [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=c_state \n                           and setParent=\"\\<lambda>v. c_state_update (\\<lambda>_. v)\"\n                           and sub_update=c_CoreStats_update]\n  contract_update[where getParent=c_state \n                    and setParent=\"\\<lambda>v. c_state_update (\\<lambda>_. v)\"\n                    and sub=c_CoreStats\n                    and sub_update=c_CoreStats_update]\n\nsubsection \\<open>@{const branch_not_taken}\\<close>\n\nabbreviation getCoreStatsBranch_not_taken where\n  \"getCoreStatsBranch_not_taken \\<equiv> (\\<lambda>s. branch_not_taken (c_CoreStats (c_state s)))\"\n\nlemmas contract_getCoreStats_CoreStatsBranch_not_taken [alt_def_simp] = \n  contract_read[where getParent=getCoreStats and sub=branch_not_taken]\n\nabbreviation setCoreStatsBranch_not_taken where\n  \"setCoreStatsBranch_not_taken v \\<equiv> c_state_update (c_CoreStats_update (branch_not_taken_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CoreStatsBranch_not_taken [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCoreStats\n                           and setParent=setCoreStats\n                           and sub_update=branch_not_taken_update]\n  contract_update[where getParent=getCoreStats \n                    and setParent=setCoreStats\n                    and sub=branch_not_taken\n                    and sub_update=branch_not_taken_update]\n\nsubsection \\<open>@{const branch_taken}\\<close>\n\nabbreviation getCoreStatsBranch_taken where\n  \"getCoreStatsBranch_taken \\<equiv> (\\<lambda>s. branch_taken (c_CoreStats (c_state s)))\"\n\nlemmas contract_getCoreStats_CoreStatsBranch_taken [alt_def_simp] = \n  contract_read[where getParent=getCoreStats and sub=branch_taken]\n\nabbreviation setCoreStatsBranch_taken where\n  \"setCoreStatsBranch_taken v \\<equiv> c_state_update (c_CoreStats_update (branch_taken_update (\\<lambda>_. v)))\"\n\nlemmas contract_c_state_update_CoreStatsBranch_taken [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=getCoreStats\n                           and setParent=setCoreStats\n                           and sub_update=branch_taken_update]\n  contract_update[where getParent=getCoreStats \n                    and setParent=setCoreStats\n                    and sub=branch_taken\n                    and sub_update=branch_taken_update]\n\nsubsection \\<open>@{const c_LLbit}\\<close>\n\nabbreviation getLLbit where\n  \"getLLbit \\<equiv> (\\<lambda>s. c_LLbit (c_state s))\"\n\nlemma LLbit_alt [alt_def_simp]:\n  shows \"LLbit = read_state getLLbit\"\nunfolding LLbit_def\nunfolding monad_def Let_def\nby simp\n\nlemmas contract_c_state_LLbit [alt_def_simp] = \n  contract_read[where getParent=c_state and sub=c_LLbit]\n\nabbreviation setLLbit where\n  \"setLLbit v \\<equiv> c_state_update (c_LLbit_update (\\<lambda>_. v))\"\n\nlemma write'LLbit_alt [alt_def_simp]:\n  shows \"write'LLbit = (\\<lambda>v. update_state (setLLbit v))\"\nunfolding write'LLbit_def\nunfolding monad_def Let_def\nby (intro ext) simp\n\nlemmas contract_c_state_update_LLbit [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=c_state \n                           and setParent=\"\\<lambda>v. c_state_update (\\<lambda>_. v)\"\n                           and sub_update=c_LLbit_update]\n  contract_update[where getParent=c_state \n                    and setParent=\"\\<lambda>v. c_state_update (\\<lambda>_. v)\"\n                    and sub=c_LLbit\n                    and sub_update=c_LLbit_update]\n\nsubsection \\<open>@{const c_PC}\\<close>\n\nabbreviation getPC where\n  \"getPC \\<equiv> (\\<lambda>s. c_PC (c_state s))\"\n\nlemma PC_alt [alt_def_simp]:\n  shows \"PC = read_state getPC\"\nunfolding PC_def\nunfolding monad_def Let_def\nby simp\n\nlemmas contract_c_state_PC [alt_def_simp] = \n  contract_read[where getParent=c_state and sub=c_PC]\n\nabbreviation setPC where\n  \"setPC v \\<equiv> c_state_update (c_PC_update (\\<lambda>_. v))\"\n\nlemma write'PC_alt [alt_def_simp]:\n  shows \"write'PC = (\\<lambda>v. update_state (setPC v))\"\nunfolding write'PC_def\nunfolding monad_def Let_def\nby (intro ext) simp\n\nlemmas contract_c_state_update_PC [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=c_state \n                           and setParent=\"\\<lambda>v. c_state_update (\\<lambda>_. v)\"\n                           and sub_update=c_PC_update]\n  contract_update[where getParent=c_state \n                    and setParent=\"\\<lambda>v. c_state_update (\\<lambda>_. v)\"\n                    and sub=c_PC\n                    and sub_update=c_PC_update]\n\nsubsection \\<open>@{const c_exceptionSignalled}\\<close>\n\nabbreviation getExceptionSignalled where\n  \"getExceptionSignalled \\<equiv> (\\<lambda>s. c_exceptionSignalled (c_state s))\"\n\nlemma exceptionSignalled_alt [alt_def_simp]:\n  shows \"exceptionSignalled = read_state getExceptionSignalled\"\nunfolding exceptionSignalled_def\nunfolding monad_def Let_def\nby simp\n\nlemmas contract_c_state_ExceptionSignalled [alt_def_simp] = \n  contract_read[where getParent=c_state and sub=c_exceptionSignalled]\n\nabbreviation setExceptionSignalled where\n  \"setExceptionSignalled v \\<equiv> c_state_update (c_exceptionSignalled_update (\\<lambda>_. v))\"\n\nlemma write'exceptionSignalled_alt [alt_def_simp]:\n  shows \"write'exceptionSignalled = (\\<lambda>v. update_state (setExceptionSignalled v))\"\nunfolding write'exceptionSignalled_def\nunfolding monad_def Let_def\nby (intro ext) simp\n\nlemmas contract_c_state_update_ExceptionSignalled [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=c_state \n                           and setParent=\"\\<lambda>v. c_state_update (\\<lambda>_. v)\"\n                           and sub_update=c_exceptionSignalled_update]\n  contract_update[where getParent=c_state \n                    and setParent=\"\\<lambda>v. c_state_update (\\<lambda>_. v)\"\n                    and sub=c_exceptionSignalled\n                    and sub_update=c_exceptionSignalled_update]\n\nsubsection \\<open>@{const c_hi}\\<close>\n\nabbreviation getHi where\n  \"getHi \\<equiv> (\\<lambda>s. c_hi (c_state s))\"\n\nlemma hi_alt [alt_def_simp]:\n  shows \"hi = read_state getHi\"\nunfolding hi_def\nunfolding monad_def Let_def\nby simp\n\nlemmas contract_c_state_Hi [alt_def_simp] = \n  contract_read[where getParent=c_state and sub=c_hi]\n\nabbreviation setHi where\n  \"setHi v \\<equiv> c_state_update (c_hi_update (\\<lambda>_. v))\"\n\nlemma write'hi_alt [alt_def_simp]:\n  shows \"write'hi = (\\<lambda>v. update_state (setHi v))\"\nunfolding write'hi_def\nunfolding monad_def Let_def\nby (intro ext) simp\n\nlemmas contract_c_state_update_Hi [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=c_state \n                           and setParent=\"\\<lambda>v. c_state_update (\\<lambda>_. v)\"\n                           and sub_update=c_hi_update]\n  contract_update[where getParent=c_state \n                    and setParent=\"\\<lambda>v. c_state_update (\\<lambda>_. v)\"\n                    and sub=c_hi\n                    and sub_update=c_hi_update]\n\nsubsection \\<open>@{const c_lo}\\<close>\n\nabbreviation getLo where\n  \"getLo \\<equiv> (\\<lambda>s. c_lo (c_state s))\"\n\nlemma lo_alt [alt_def_simp]:\n  shows \"lo = read_state getLo\"\nunfolding lo_def\nunfolding monad_def Let_def\nby simp\n\nlemmas contract_c_state_Lo [alt_def_simp] = \n  contract_read[where getParent=c_state and sub=c_lo]\n\nabbreviation setLo where\n  \"setLo v \\<equiv> c_state_update (c_lo_update (\\<lambda>_. v))\"\n\nlemma write'lo_alt [alt_def_simp]:\n  shows \"write'lo = (\\<lambda>v. update_state (setLo v))\"\nunfolding write'lo_def\nunfolding monad_def Let_def\nby (intro ext) simp\n\nlemmas contract_c_state_update_Lo [simplified, alt_def_simp] = \n  contract_update_constant[where getParent=c_state \n                           and setParent=\"\\<lambda>v. c_state_update (\\<lambda>_. v)\"\n                           and sub_update=c_lo_update]\n  contract_update[where getParent=c_state \n                    and setParent=\"\\<lambda>v. c_state_update (\\<lambda>_. v)\"\n                    and sub=c_lo\n                    and sub_update=c_lo_update]\n\n(* Code generation - end *)\n\nsection \\<open>Rewriting the structure of functions\\<close>\n\nsubsection \\<open>Associativity\\<close>\n\ndeclare bind_associativity [alt_def_simp]\n\nsubsection \\<open>Distributive lemmas\\<close>\n\nlemmas case_return_return [alt_def_simp] =\n  all_distrib[where h=\"\\<lambda>x. return x\", THEN sym]\n\nlemmas pair_cases_distrib [alt_def_simp] = \n  all_distrib[where h=\"\\<lambda>x. (x, _)\", THEN sym]\n  all_distrib[where h=\"\\<lambda>x. (_, x)\", THEN sym]\n\nlemma if_bind_return_return [alt_def_simp]:\n  shows \"(if b then bind m (\\<lambda>_. return x) else return x) = \n         bind (if b then m else return ()) (\\<lambda>_. return x)\"\nunfolding monad_def Let_def\nby simp\n\nlemma if_return_bind_return [alt_def_simp]:\n  shows \"(if b then return x else bind m (\\<lambda>_. return x)) = \n         bind (if b then return () else m) (\\<lambda>_. return x)\"\nunfolding monad_def Let_def\nby simp\n\nlemma if_bind_return_bind_return [alt_def_simp]:\n  shows \"(if b then bind m (\\<lambda>v. return (x v)) else bind n (\\<lambda>v. return (x v))) = \n         bind (if b then m else n) (\\<lambda>v. return (x v))\"\nunfolding monad_def Let_def\nby simp\n\nlemma if_bind_bind_return_return [alt_def_simp]:\n  shows \"(if b then bind m (\\<lambda>a. bind (n a) (\\<lambda>_. return x)) else return x) = \n         bind (if b then bind m (\\<lambda>a. n a) else return ()) (\\<lambda>_. return x)\"\nunfolding monad_def Let_def\nby simp\n\nlemma if_return_bind_bind_return [alt_def_simp]:\n  shows \"(if b then return x else bind m (\\<lambda>a. bind (n a) (\\<lambda>_. return x))) = \n         bind (if b then return () else bind m (\\<lambda>a. n a)) (\\<lambda>_. return x)\"\nunfolding monad_def Let_def\nby simp\n\nlemma if_return_return_pair_left [alt_def_simp]:\n  shows \"(if b then return (x, y) else return (x, z)) = \n         bind (if b then return y else return z) (\\<lambda>a. return (x, a))\"\nunfolding monad_def Let_def\nby simp\n\nlemma if_return_return_pair_right [alt_def_simp]:\n  shows \"(if b then return (x, z) else return (y, z)) = \n         bind (if b then return x else return y) (\\<lambda>a. return (a, z))\"\nunfolding monad_def Let_def\nby simp\n\nlemma if_bind_return_return_pair_left [alt_def_simp]:\n  shows \"(if b then bind m (\\<lambda>a. return (x, y a)) else return (x, z)) = \n         bind (if b then bind m (\\<lambda>a. return (y a)) else return z) (\\<lambda>a. return (x, a))\"\nunfolding monad_def Let_def\nby simp\n\nlemma if_bind_return_return_pair_right [alt_def_simp]:\n  shows \"(if b then bind m (\\<lambda>a. return (x a, z)) else return (y, z)) = \n         bind (if b then bind m (\\<lambda>a. return (x a)) else return y) (\\<lambda>a. return (a, z))\"\nunfolding monad_def Let_def\nby simp\n\nlemma prod_bind_left [alt_def_simp]:\n  shows \"case x of (y, z) \\<Rightarrow> bind (m y z) n = \n         bind (case x of (y, z) \\<Rightarrow> m y z) n\" \nby (cases x) auto \n\nlemma prod_bind_right [alt_def_simp]:\n  shows \"case x of (y, z) \\<Rightarrow> bind m (n y z) = \n         bind m (\\<lambda>a. case x of (y, z) \\<Rightarrow> n y z a)\" \nby (cases x) auto \n\nlemma let_bind_left [alt_def_simp]:\n  shows \"(let x = y in bind (m x) n) =\n         bind (let x = y in m x) n\"\nby simp\n\nlemma let_bind_right [alt_def_simp]:\n  shows \"(let x = y in bind m (n x)) =\n         bind m (\\<lambda>a. let x = y in n x a)\"\nby simp\n\nsubsection \\<open>Changing the order\\<close>\n\ntext \\<open>The following lemmas are tailored to the generated CHERI definition and not of general\ninterest.\\<close>\n\nlemma swap_CP0_return [alt_def_simp]:\n  shows \"bind (read_state getCP0) (\\<lambda>a. bind (return x) (k a)) = \n         bind (return x) (\\<lambda>b. bind (read_state getCP0) (\\<lambda>a. k a b))\"\nunfolding monad_def Let_def\nby simp\n\ntext \\<open>The following lemma was included by mistake, and turned out crucial for generating the\nalternative definition of @{const Fetch}. Together with \\<open>swap_c_state_CP0\\<close> it should loop, but for\nsome reason the simplifier does not loop when both these lemmas are used together.\\<close>\n\nlemma swap_CP0_read_state [alt_def_simp]:\n  shows \"bind (read_state getCP0) (\\<lambda>a. bind (read_state f) (k a)) = \n         bind (read_state f) (\\<lambda>b. bind (read_state getCP0) (\\<lambda>a. k a b))\"\nunfolding monad_def Let_def\nby simp\n\nlemma swap_CP0_PC [alt_def_simp]:\n  shows \"bind (read_state getCP0) (\\<lambda>a. bind (read_state getPC) (k a)) = \n         bind (read_state getPC) (\\<lambda>b. bind (read_state getCP0) (\\<lambda>a. k a b))\"\nunfolding monad_def Let_def\nby simp\n\nlemma swap_CP0_currentInst [alt_def_simp]:\n  shows \"bind (read_state getCP0) (\\<lambda>a. bind (read_state currentInst) (k a)) = \n         bind (read_state currentInst) (\\<lambda>b. bind (read_state getCP0) (\\<lambda>a. k a b))\"\nunfolding monad_def Let_def\nby simp\n\nlemma swap_CP0_if_return_read_state_return [alt_def_simp]:\n  shows \"bind (read_state getCP0) \n              (\\<lambda>a. bind (if b then return x else bind (read_state f) (\\<lambda>a. return (g a))) \n              (k a)) = \n         bind (if b then return x else bind (read_state f) (\\<lambda>a. return (g a))) \n              (\\<lambda>b. bind (read_state getCP0) \n              (\\<lambda>a. k a b))\"\nunfolding monad_def Let_def\nby simp\n\nlemma swap_CP0_PCC [alt_def_simp]:\n  shows \"bind (read_state getCP0) (\\<lambda>a. bind PCC (k a)) = \n         bind PCC (\\<lambda>b. bind (read_state getCP0) (\\<lambda>a. k a b))\"\nunfolding PCC_def\nunfolding monad_def Let_def\nby simp\n\nlemma swap_CP0_CAPR [alt_def_simp]:\n  shows \"bind (read_state getCP0) (\\<lambda>a. bind (CAPR cd) (k a)) = \n         bind (CAPR cd) (\\<lambda>b. bind (read_state getCP0) (\\<lambda>a. k a b))\"\nunfolding CAPR_def\nunfolding monad_def Let_def\nby simp\n\nlemma swap_CP0_next_unknown [alt_def_simp]:\n  shows \"bind (read_state getCP0) (\\<lambda>a. bind (next_unknown v) (k a)) = \n         bind (next_unknown v) (\\<lambda>b. bind (read_state getCP0) (\\<lambda>a. k a b))\"\nunfolding next_unknown_def\nunfolding monad_def Let_def\nby simp\n\nlemma swap_c_state_return [alt_def_simp]:\n  shows \"bind (read_state c_state) (\\<lambda>a. bind (return x) (k a)) = \n         bind (return x) (\\<lambda>b. bind (read_state c_state) (\\<lambda>a. k a b))\"\nunfolding monad_def Let_def\nby simp\n\nlemma swap_c_state_CP0 [alt_def_simp]:\n  shows \"bind (read_state c_state) (\\<lambda>a. bind (read_state getCP0) (k a)) = \n         bind (read_state getCP0) (\\<lambda>b. bind (read_state c_state) (\\<lambda>a. k a b))\"\nunfolding monad_def Let_def\nby simp\n\nsubsection \\<open>Manual contractions\\<close>\n\nlemmas contract_c_state_update_CP0CauseIP_2 [alt_def_simp] =\n  contract_c_state_update_CP0Cause(3-4)\n    [where f=\"\\<lambda>cause. cause\\<lparr>IP := _ (IP cause)\\<rparr>\"]\n\nlemmas contract_c_state_update_CP0EntryLo0_2 [alt_def_simp] =\n  contract_c_state_update_CP0EntryLo0(3-4)\n    [where f=\"\\<lambda>x. _ (x, _)\"]\n\nlemmas contract_c_state_update_CP0EntryLo1_2 [alt_def_simp] =\n  contract_c_state_update_CP0EntryLo1(3-4)\n    [where f=\"\\<lambda>x. _ (x, _)\"]\n\nlemmas contract_c_state_update_CP0EntryHi_2 [alt_def_simp] =\n  contract_c_state_update_CP0EntryHi(3-4)\n    [where f=\"\\<lambda>x. _ (x, _)\"]\n\nlemmas contract_c_state_update_CP0Status_2 [alt_def_simp] =\n  contract_c_state_update_CP0Status(3-4)\n    [where f=\"\\<lambda>x. _ (x, _)\"]\n\nsubsection \\<open>Removing @{const return}\\<close>\n\ntext \\<open>We later remove the lemma \\<open>bind_left_identity\\<close> from the proof method, to avoid the proof\nmethod to simplify away \\<open>return (X a)\\<close> where \\<open>X\\<close> is a state component. In the following cases it is\nstill fine to simplify away \\<open>return\\<close>. \\<close>\n\nnamed_theorems bind_left_identity_specific\n\nthm bind_left_identity\n\nlemmas bind_left_identity_unit [bind_left_identity_specific] =\n  bind_left_identity[where a=\"()\"]\n\nlemmas bind_left_identity_fst [bind_left_identity_specific] =\n  bind_left_identity[where a=\"fst _\"]\n\nlemmas bind_left_identity_snd [bind_left_identity_specific] =\n  bind_left_identity[where a=\"snd _\"]\n\nlemmas bind_left_identity_pair [bind_left_identity_specific] =\n  bind_left_identity[where a=\"(_,_)\"]\n\nlemmas bind_left_identity_not [bind_left_identity_specific] =\n  bind_left_identity[where a=\"\\<not> _\"]\n\nlemmas bind_left_identity_eq [bind_left_identity_specific] =\n  bind_left_identity[where a=\"_ = _\"]\n\nlemmas bind_left_identity_plus [bind_left_identity_specific] =\n  bind_left_identity[where a=\"_ + _\"]\n\nlemmas bind_left_identity_minus [bind_left_identity_specific] =\n  bind_left_identity[where a=\"_ - _\"]\n\nlemmas bind_left_identity_BadInstr [bind_left_identity_specific] =\n  bind_left_identity[where a=\"_\\<lparr>BadInstr := _\\<rparr>\"]\n\nlemmas bind_left_identity_BadInstrP [bind_left_identity_specific] =\n  bind_left_identity[where a=\"_\\<lparr>BadInstrP := _\\<rparr>\"]\n\nlemmas bind_left_identity_BadVAddr [bind_left_identity_specific] =\n  bind_left_identity[where a=\"_\\<lparr>BadVAddr := _\\<rparr>\"]\n\nlemmas bind_left_identity_EPC [bind_left_identity_specific] =\n  bind_left_identity[where a=\"_\\<lparr>EPC := _\\<rparr>\"]\n\nlemmas bind_left_identity_c_CP0 [bind_left_identity_specific] =\n  bind_left_identity[where a=\"_\\<lparr>c_CP0 := _\\<rparr>\"]\n\nlemmas bind_left_identity_Count [bind_left_identity_specific] =\n  bind_left_identity[where a=\"_\\<lparr>Count := _\\<rparr>\"]\n\nlemmas bind_left_identity_Cause [bind_left_identity_specific] =\n  bind_left_identity[where a=\"_\\<lparr>Cause := _\\<rparr>\"]\n\nlemmas bind_left_identity_CauseIP [bind_left_identity_specific] =\n  bind_left_identity[where a=\"Cause _\\<lparr>IP := _\\<rparr>\"]\n\nlemmas bind_left_identity_Random [bind_left_identity_specific] =\n  bind_left_identity[where a=\"_\\<lparr>CP0.Random := _\\<rparr>\"]\n\nlemmas bind_left_identity_RandomRandom [bind_left_identity_specific] =\n  bind_left_identity[where a=\"CP0.Random _\\<lparr>Random.Random := _\\<rparr>\"]\n\nlemmas bind_left_identity_word_bit_field_insert [bind_left_identity_specific] =\n  bind_left_identity[where a=\"word_bit_field_insert _ _ _ _\"]\n\nsection \\<open>Alternative definitions\\<close>\n\nmethod compute_alt_def_pass_1 uses simp del =\n  -- \\<open>In the first pass we only simplify some occurrences of @{const return}.\\<close>\n  (strong_cong_simp \n     add: bind_left_identity_specific alt_def_simp simp\n     del: bind_left_identity alt_def_simp_del del)\n\nmethod compute_alt_def_pass_2 uses simp del =\n  -- \\<open>In the second pass we simplify all occurrences of @{const return}.\\<close>\n  (strong_cong_simp \n     add: alt_def_simp simp\n     del: alt_def_simp_del del)\n\nmethod compute_alt_def uses simp del =\n  -- \\<open>Applying \\<open>trans\\<close> allows us to simplify schematic goals twice.\\<close>\n  (rule trans),\n  (compute_alt_def_pass_1 simp: simp del: del),\n  (compute_alt_def_pass_2 simp: simp del: del)\n\n(* Code generation - start - alternative definitions *)\n\n(* Code generation - prefix - raise'exception *)\n\ntext \\<open>The function @{const raise'exception} can have any type @{typ \"state \\<Rightarrow> 'a \\<times> state\"}. When\n@{const raise'exception} is used in other functions, we do not know which type they use, which makes\nit hard to state assumptions about that use of @{const raise'exception}.\n\nTo circumvent that, we replace @{const raise'exception} with another version that only updates the\nstate, and a @{term \"return undefined\"}. We give this other version the same name, which means that\nin the rest of the development it seems that @{const raise'exception} has always been of type @{typ\n\"state \\<Rightarrow> unit \\<times> state\"}.\\<close>\n\ndefinition raise'exception :: \"exception \\<Rightarrow> state \\<Rightarrow> unit \\<times> state\" where\n  \"raise'exception \\<equiv> \\<lambda>e. bind (read_state exception) \n                               (\\<lambda>v. if v = NoException \n                                    then update_state (exception_update (\\<lambda>_. e)) \n                                    else return ())\"\n\nlemma raise'exception_simp [alt_def_simp]:\n  shows \"CHERI_Monadic_p256.raise'exception = \n         (\\<lambda>ex. bind (raise'exception ex)\n                    (\\<lambda>_. return undefined))\"\nunfolding CHERI_Monadic_p256.raise'exception_def\n          raise'exception_def\nby (simp add: bind_associativity)\n\n(* Code generation - end prefix *)\n\nschematic_goal raise'exception_alt_def:\n  shows \"raise'exception = ?x\"\nunfolding raise'exception_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal println_alt_def [simp]:\n  shows \"println = ?x\"\nunfolding println_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal clear_watcher_alt_def [simp]:\n  shows \"clear_watcher = ?x\"\nunfolding clear_watcher_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal clear_logs_alt_def [simp]:\n  shows \"clear_logs = ?x\"\nunfolding clear_logs_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal PIC_update_alt_def:\n  shows \"PIC_update = ?x\"\nunfolding PIC_update_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal PIC_initialise_alt_def:\n  shows \"PIC_initialise = ?x\"\nunfolding PIC_initialise_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal PIC_load_alt_def:\n  shows \"PIC_load = ?x\"\nunfolding PIC_load_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal PIC_store_alt_def:\n  shows \"PIC_store = ?x\"\nunfolding PIC_store_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal JTAG_UART_update_interrupt_bit_alt_def:\n  shows \"JTAG_UART_update_interrupt_bit = ?x\"\nunfolding JTAG_UART_update_interrupt_bit_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal JTAG_UART_load_alt_def:\n  shows \"JTAG_UART_load = ?x\"\nunfolding JTAG_UART_load_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal JTAG_UART_input_alt_def:\n  shows \"JTAG_UART_input = ?x\"\nunfolding JTAG_UART_input_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal JTAG_UART_store_alt_def:\n  shows \"JTAG_UART_store = ?x\"\nunfolding JTAG_UART_store_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal JTAG_UART_output_alt_def:\n  shows \"JTAG_UART_output = ?x\"\nunfolding JTAG_UART_output_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal JTAG_UART_initialise_alt_def:\n  shows \"JTAG_UART_initialise = ?x\"\nunfolding JTAG_UART_initialise_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal gpr_alt_def:\n  shows \"gpr = ?x\"\nunfolding gpr_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'gpr_alt_def:\n  shows \"write'gpr = ?x\"\nunfolding write'gpr_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal GPR_alt_def:\n  shows \"GPR = ?x\"\nunfolding GPR_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'GPR_alt_def:\n  shows \"write'GPR = ?x\"\nunfolding write'GPR_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal UserMode_alt_def:\n  shows \"UserMode = ?x\"\nunfolding UserMode_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal SupervisorMode_alt_def:\n  shows \"SupervisorMode = ?x\"\nunfolding SupervisorMode_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal KernelMode_alt_def:\n  shows \"KernelMode = ?x\"\nunfolding KernelMode_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal BigEndianMem_alt_def:\n  shows \"BigEndianMem = ?x\"\nunfolding BigEndianMem_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal ReverseEndian_alt_def:\n  shows \"ReverseEndian = ?x\"\nunfolding ReverseEndian_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal BigEndianCPU_alt_def:\n  shows \"BigEndianCPU = ?x\"\nunfolding BigEndianCPU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal CheckBranch_alt_def:\n  shows \"CheckBranch = ?x\"\nunfolding CheckBranch_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal BranchNotTaken_alt_def:\n  shows \"BranchNotTaken = ?x\"\nunfolding BranchNotTaken_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal BranchLikelyNotTaken_alt_def:\n  shows \"BranchLikelyNotTaken = ?x\"\nunfolding BranchLikelyNotTaken_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dumpRegs_alt_def [simp]:\n  shows \"dumpRegs = ?x\"\nunfolding dumpRegs_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal initCoreStats_alt_def:\n  shows \"initCoreStats = ?x\"\nunfolding initCoreStats_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal printCoreStats_alt_def:\n  shows \"printCoreStats = ?x\"\nunfolding printCoreStats_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal next_unknown_alt_def:\n  shows \"next_unknown = ?x\"\nunfolding next_unknown_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dumpCRegs_alt_def [simp]:\n  shows \"dumpCRegs = ?x\"\nunfolding dumpCRegs_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal PCC_alt_def:\n  shows \"PCC = ?x\"\nunfolding PCC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'PCC_alt_def:\n  shows \"write'PCC = ?x\"\nunfolding write'PCC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal CAPR_alt_def:\n  shows \"CAPR = ?x\"\nunfolding CAPR_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'CAPR_alt_def:\n  shows \"write'CAPR = ?x\"\nunfolding write'CAPR_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal SCAPR_alt_def:\n  shows \"SCAPR = ?x\"\nunfolding SCAPR_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'SCAPR_alt_def:\n  shows \"write'SCAPR = ?x\"\nunfolding write'SCAPR_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal RCC_alt_def [simp]:\n  shows \"RCC = ?x\"\nunfolding RCC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'RCC_alt_def [simp]:\n  shows \"write'RCC = ?x\"\nunfolding write'RCC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal IDC_alt_def [simp]:\n  shows \"IDC = ?x\"\nunfolding IDC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'IDC_alt_def [simp]:\n  shows \"write'IDC = ?x\"\nunfolding write'IDC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal DDC_alt_def [simp]:\n  shows \"DDC = ?x\"\nunfolding DDC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'DDC_alt_def [simp]:\n  shows \"write'DDC = ?x\"\nunfolding write'DDC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal TLSC_alt_def [simp]:\n  shows \"TLSC = ?x\"\nunfolding TLSC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'TLSC_alt_def [simp]:\n  shows \"write'TLSC = ?x\"\nunfolding write'TLSC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal PTLSC_alt_def [simp]:\n  shows \"PTLSC = ?x\"\nunfolding PTLSC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'PTLSC_alt_def [simp]:\n  shows \"write'PTLSC = ?x\"\nunfolding write'PTLSC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal KR1C_alt_def [simp]:\n  shows \"KR1C = ?x\"\nunfolding KR1C_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'KR1C_alt_def [simp]:\n  shows \"write'KR1C = ?x\"\nunfolding write'KR1C_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal KR2C_alt_def [simp]:\n  shows \"KR2C = ?x\"\nunfolding KR2C_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'KR2C_alt_def [simp]:\n  shows \"write'KR2C = ?x\"\nunfolding write'KR2C_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal KCC_alt_def [simp]:\n  shows \"KCC = ?x\"\nunfolding KCC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'KCC_alt_def [simp]:\n  shows \"write'KCC = ?x\"\nunfolding write'KCC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal KDC_alt_def [simp]:\n  shows \"KDC = ?x\"\nunfolding KDC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'KDC_alt_def [simp]:\n  shows \"write'KDC = ?x\"\nunfolding write'KDC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal EPCC_alt_def [simp]:\n  shows \"EPCC = ?x\"\nunfolding EPCC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'EPCC_alt_def [simp]:\n  shows \"write'EPCC = ?x\"\nunfolding write'EPCC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal SignalException_alt_def:\n  shows \"SignalException = ?x\"\nunfolding SignalException_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal SignalCP2UnusableException_alt_def:\n  shows \"SignalCP2UnusableException = ?x\"\nunfolding SignalCP2UnusableException_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal SignalCapException_internal_alt_def:\n  shows \"SignalCapException_internal = ?x\"\nunfolding SignalCapException_internal_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal SignalCapException_alt_def:\n  shows \"SignalCapException = ?x\"\nunfolding SignalCapException_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal SignalCapException_noReg_alt_def:\n  shows \"SignalCapException_noReg = ?x\"\nunfolding SignalCapException_noReg_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'ERET_alt_def:\n  shows \"dfn'ERET = ?x\"\nunfolding dfn'ERET_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal TLB_direct_alt_def:\n  shows \"TLB_direct = ?x\"\nunfolding TLB_direct_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'TLB_direct_alt_def:\n  shows \"write'TLB_direct = ?x\"\nunfolding write'TLB_direct_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal TLB_assoc_alt_def:\n  shows \"TLB_assoc = ?x\"\nunfolding TLB_assoc_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'TLB_assoc_alt_def:\n  shows \"write'TLB_assoc = ?x\"\nunfolding write'TLB_assoc_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal LookupTLB_alt_def:\n  shows \"LookupTLB = ?x\"\nunfolding LookupTLB_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal SignalTLBException_internal_alt_def:\n  shows \"SignalTLBException_internal = ?x\"\nunfolding SignalTLBException_internal_def\nunfolding Let_def\nby compute_alt_def\n\n(* Code generation - override - SignalTLBException *)\n\ntext \\<open>Like @{const raise'exception}, @{const SignalTLBException}\n\n can have any type @{typ \"state \\<Rightarrow> 'a \\<times> state\"}. For the same reason as for @{const raise'exception}\n we provide a different definition of @{const SignalTLBException} that always returns @{typ unit}.\\<close>\n\ndefinition SignalTLBException where\n  \"SignalTLBException \\<equiv> \n   \\<lambda>v. case v of (v1, v2) \\<Rightarrow> \n       bind (SignalTLBException_internal v2) (\\<lambda>_. SignalException v1)\"\n\nlemma bind_bind_return:\n  shows \"bind (bind m (\\<lambda>v. return (x v))) n =\n         bind m (\\<lambda>v. n (x v))\" \nunfolding bind_associativity\nby simp\n\nlemma SignalTLBException_simp [alt_def_simp]:\n  shows \"CHERI_Monadic_p256.SignalTLBException = \n         (\\<lambda>ex. bind (SignalTLBException ex) \n                    (\\<lambda>_. bind (next_unknown ''tlb-translation'')\n                    (\\<lambda>v. return (undefined v))))\"\nunfolding Let_def\n  SignalTLBException_def\n  CHERI_Monadic_p256.SignalTLBException_def\nby (auto simp: bind_associativity)\n\nschematic_goal SignalTLBException_alt_def:\n  shows \"SignalTLBException = ?x\"\nunfolding SignalTLBException_def\nunfolding CHERI_Monadic_p256.SignalTLBException_def Let_def\nby compute_alt_def\n\n(* Code generation - end override *)\n\nschematic_goal CheckSegment_alt_def:\n  shows \"CheckSegment = ?x\"\nunfolding CheckSegment_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal check_cca_alt_def:\n  shows \"check_cca = ?x\"\nunfolding check_cca_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal TLB_next_random_alt_def:\n  shows \"TLB_next_random = ?x\"\nunfolding TLB_next_random_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal AddressTranslation_alt_def:\n  shows \"AddressTranslation = ?x\"\nunfolding AddressTranslation_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal CP0TLBEntry_alt_def:\n  shows \"CP0TLBEntry = ?x\"\nunfolding CP0TLBEntry_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal SignalTLBCapException_alt_def:\n  shows \"SignalTLBCapException = ?x\"\nunfolding SignalTLBCapException_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal printMemStats_alt_def:\n  shows \"printMemStats = ?x\"\nunfolding printMemStats_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal initMemStats_alt_def:\n  shows \"initMemStats = ?x\"\nunfolding initMemStats_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal stats_data_reads_updt_alt_def:\n  shows \"stats_data_reads_updt = ?x\"\nunfolding stats_data_reads_updt_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal stats_data_writes_updt_alt_def:\n  shows \"stats_data_writes_updt = ?x\"\nunfolding stats_data_writes_updt_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal stats_inst_reads_updt_alt_def:\n  shows \"stats_inst_reads_updt = ?x\"\nunfolding stats_inst_reads_updt_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal stats_valid_cap_reads_updt_alt_def:\n  shows \"stats_valid_cap_reads_updt = ?x\"\nunfolding stats_valid_cap_reads_updt_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal stats_valid_cap_writes_updt_alt_def:\n  shows \"stats_valid_cap_writes_updt = ?x\"\nunfolding stats_valid_cap_writes_updt_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal stats_invalid_cap_reads_updt_alt_def:\n  shows \"stats_invalid_cap_reads_updt = ?x\"\nunfolding stats_invalid_cap_reads_updt_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal stats_invalid_cap_writes_updt_alt_def:\n  shows \"stats_invalid_cap_writes_updt = ?x\"\nunfolding stats_invalid_cap_writes_updt_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal MEM_alt_def:\n  shows \"MEM = ?x\"\nunfolding MEM_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'MEM_alt_def:\n  shows \"write'MEM = ?x\"\nunfolding write'MEM_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal InitMEM_alt_def:\n  shows \"InitMEM = ?x\"\nunfolding InitMEM_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal ReadData_alt_def:\n  shows \"ReadData = ?x\"\nunfolding ReadData_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal WriteData_alt_def:\n  shows \"WriteData = ?x\"\nunfolding WriteData_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal ReadInst_alt_def:\n  shows \"ReadInst = ?x\"\nunfolding ReadInst_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal ReadCap_alt_def:\n  shows \"ReadCap = ?x\"\nunfolding ReadCap_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal WriteCap_alt_def:\n  shows \"WriteCap = ?x\"\nunfolding WriteCap_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal AdjustEndian_alt_def:\n  shows \"AdjustEndian = ?x\"\nunfolding AdjustEndian_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal initMemAccessStats_alt_def:\n  shows \"initMemAccessStats = ?x\"\nunfolding initMemAccessStats_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal printMemAccessStats_alt_def:\n  shows \"printMemAccessStats = ?x\"\nunfolding printMemAccessStats_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal watchForLoad_alt_def [simp]:\n  shows \"watchForLoad = ?x\"\nunfolding watchForLoad_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal watchForCapLoad_alt_def [simp]:\n  shows \"watchForCapLoad = ?x\"\nunfolding watchForCapLoad_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal watchForStore_alt_def [simp]:\n  shows \"watchForStore = ?x\"\nunfolding watchForStore_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal watchForCapStore_alt_def [simp]:\n  shows \"watchForCapStore = ?x\"\nunfolding watchForCapStore_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal getVirtualAddress_alt_def:\n  shows \"getVirtualAddress = ?x\"\nunfolding getVirtualAddress_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal LoadMemoryCap_alt_def:\n  shows \"LoadMemoryCap = ?x\"\nunfolding LoadMemoryCap_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal LoadMemory_alt_def:\n  shows \"LoadMemory = ?x\"\nunfolding LoadMemory_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal LoadCap_alt_def:\n  shows \"LoadCap = ?x\"\nunfolding LoadCap_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal StoreMemoryCap_alt_def:\n  shows \"StoreMemoryCap = ?x\"\nunfolding StoreMemoryCap_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal StoreMemory_alt_def:\n  shows \"StoreMemory = ?x\"\nunfolding StoreMemory_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal StoreCap_alt_def:\n  shows \"StoreCap = ?x\"\nunfolding StoreCap_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal Fetch_alt_def:\n  shows \"Fetch = ?x\"\nunfolding Fetch_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal CP0R_alt_def:\n  shows \"CP0R = ?x\"\nunfolding CP0R_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'CP0R_alt_def:\n  shows \"write'CP0R = ?x\"\nunfolding write'CP0R_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal resetStats_alt_def:\n  shows \"resetStats = ?x\"\nunfolding resetStats_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dumpStats_alt_def [simp]:\n  shows \"dumpStats = ?x\"\nunfolding dumpStats_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal HI_alt_def:\n  shows \"HI = ?x\"\nunfolding HI_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'HI_alt_def:\n  shows \"write'HI = ?x\"\nunfolding write'HI_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal LO_alt_def:\n  shows \"LO = ?x\"\nunfolding LO_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal write'LO_alt_def:\n  shows \"write'LO = ?x\"\nunfolding write'LO_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal mtc_alt_def:\n  shows \"mtc = ?x\"\nunfolding mtc_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dmtc_alt_def:\n  shows \"dmtc = ?x\"\nunfolding dmtc_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal mfc_alt_def:\n  shows \"mfc = ?x\"\nunfolding mfc_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dmfc_alt_def:\n  shows \"dmfc = ?x\"\nunfolding dmfc_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'ADDI_alt_def:\n  shows \"dfn'ADDI = ?x\"\nunfolding dfn'ADDI_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'ADDIU_alt_def:\n  shows \"dfn'ADDIU = ?x\"\nunfolding dfn'ADDIU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DADDI_alt_def:\n  shows \"dfn'DADDI = ?x\"\nunfolding dfn'DADDI_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DADDIU_alt_def:\n  shows \"dfn'DADDIU = ?x\"\nunfolding dfn'DADDIU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SLTI_alt_def:\n  shows \"dfn'SLTI = ?x\"\nunfolding dfn'SLTI_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SLTIU_alt_def:\n  shows \"dfn'SLTIU = ?x\"\nunfolding dfn'SLTIU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'ANDI_alt_def:\n  shows \"dfn'ANDI = ?x\"\nunfolding dfn'ANDI_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'ORI_alt_def:\n  shows \"dfn'ORI = ?x\"\nunfolding dfn'ORI_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'XORI_alt_def:\n  shows \"dfn'XORI = ?x\"\nunfolding dfn'XORI_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'LUI_alt_def:\n  shows \"dfn'LUI = ?x\"\nunfolding dfn'LUI_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'ADD_alt_def:\n  shows \"dfn'ADD = ?x\"\nunfolding dfn'ADD_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'ADDU_alt_def:\n  shows \"dfn'ADDU = ?x\"\nunfolding dfn'ADDU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SUB_alt_def:\n  shows \"dfn'SUB = ?x\"\nunfolding dfn'SUB_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SUBU_alt_def:\n  shows \"dfn'SUBU = ?x\"\nunfolding dfn'SUBU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DADD_alt_def:\n  shows \"dfn'DADD = ?x\"\nunfolding dfn'DADD_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DADDU_alt_def:\n  shows \"dfn'DADDU = ?x\"\nunfolding dfn'DADDU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DSUB_alt_def:\n  shows \"dfn'DSUB = ?x\"\nunfolding dfn'DSUB_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DSUBU_alt_def:\n  shows \"dfn'DSUBU = ?x\"\nunfolding dfn'DSUBU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SLT_alt_def:\n  shows \"dfn'SLT = ?x\"\nunfolding dfn'SLT_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SLTU_alt_def:\n  shows \"dfn'SLTU = ?x\"\nunfolding dfn'SLTU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'AND_alt_def:\n  shows \"dfn'AND = ?x\"\nunfolding dfn'AND_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'OR_alt_def:\n  shows \"dfn'OR = ?x\"\nunfolding dfn'OR_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'XOR_alt_def:\n  shows \"dfn'XOR = ?x\"\nunfolding dfn'XOR_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'NOR_alt_def:\n  shows \"dfn'NOR = ?x\"\nunfolding dfn'NOR_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'MOVN_alt_def:\n  shows \"dfn'MOVN = ?x\"\nunfolding dfn'MOVN_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'MOVZ_alt_def:\n  shows \"dfn'MOVZ = ?x\"\nunfolding dfn'MOVZ_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'MADD_alt_def:\n  shows \"dfn'MADD = ?x\"\nunfolding dfn'MADD_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'MADDU_alt_def:\n  shows \"dfn'MADDU = ?x\"\nunfolding dfn'MADDU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'MSUB_alt_def:\n  shows \"dfn'MSUB = ?x\"\nunfolding dfn'MSUB_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'MSUBU_alt_def:\n  shows \"dfn'MSUBU = ?x\"\nunfolding dfn'MSUBU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'MUL_alt_def:\n  shows \"dfn'MUL = ?x\"\nunfolding dfn'MUL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'MULT_alt_def:\n  shows \"dfn'MULT = ?x\"\nunfolding dfn'MULT_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'MULTU_alt_def:\n  shows \"dfn'MULTU = ?x\"\nunfolding dfn'MULTU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DMULT_alt_def:\n  shows \"dfn'DMULT = ?x\"\nunfolding dfn'DMULT_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DMULTU_alt_def:\n  shows \"dfn'DMULTU = ?x\"\nunfolding dfn'DMULTU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DIV_alt_def:\n  shows \"dfn'DIV = ?x\"\nunfolding dfn'DIV_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DIVU_alt_def:\n  shows \"dfn'DIVU = ?x\"\nunfolding dfn'DIVU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DDIV_alt_def:\n  shows \"dfn'DDIV = ?x\"\nunfolding dfn'DDIV_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DDIVU_alt_def:\n  shows \"dfn'DDIVU = ?x\"\nunfolding dfn'DDIVU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'MFHI_alt_def:\n  shows \"dfn'MFHI = ?x\"\nunfolding dfn'MFHI_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'MFLO_alt_def:\n  shows \"dfn'MFLO = ?x\"\nunfolding dfn'MFLO_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'MTHI_alt_def:\n  shows \"dfn'MTHI = ?x\"\nunfolding dfn'MTHI_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'MTLO_alt_def:\n  shows \"dfn'MTLO = ?x\"\nunfolding dfn'MTLO_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SLL_alt_def:\n  shows \"dfn'SLL = ?x\"\nunfolding dfn'SLL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SRL_alt_def:\n  shows \"dfn'SRL = ?x\"\nunfolding dfn'SRL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SRA_alt_def:\n  shows \"dfn'SRA = ?x\"\nunfolding dfn'SRA_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SLLV_alt_def:\n  shows \"dfn'SLLV = ?x\"\nunfolding dfn'SLLV_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SRLV_alt_def:\n  shows \"dfn'SRLV = ?x\"\nunfolding dfn'SRLV_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SRAV_alt_def:\n  shows \"dfn'SRAV = ?x\"\nunfolding dfn'SRAV_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DSLL_alt_def:\n  shows \"dfn'DSLL = ?x\"\nunfolding dfn'DSLL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DSRL_alt_def:\n  shows \"dfn'DSRL = ?x\"\nunfolding dfn'DSRL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DSRA_alt_def:\n  shows \"dfn'DSRA = ?x\"\nunfolding dfn'DSRA_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DSLLV_alt_def:\n  shows \"dfn'DSLLV = ?x\"\nunfolding dfn'DSLLV_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DSRLV_alt_def:\n  shows \"dfn'DSRLV = ?x\"\nunfolding dfn'DSRLV_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DSRAV_alt_def:\n  shows \"dfn'DSRAV = ?x\"\nunfolding dfn'DSRAV_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DSLL32_alt_def:\n  shows \"dfn'DSLL32 = ?x\"\nunfolding dfn'DSLL32_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DSRL32_alt_def:\n  shows \"dfn'DSRL32 = ?x\"\nunfolding dfn'DSRL32_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DSRA32_alt_def:\n  shows \"dfn'DSRA32 = ?x\"\nunfolding dfn'DSRA32_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'TGE_alt_def:\n  shows \"dfn'TGE = ?x\"\nunfolding dfn'TGE_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'TGEU_alt_def:\n  shows \"dfn'TGEU = ?x\"\nunfolding dfn'TGEU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'TLT_alt_def:\n  shows \"dfn'TLT = ?x\"\nunfolding dfn'TLT_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'TLTU_alt_def:\n  shows \"dfn'TLTU = ?x\"\nunfolding dfn'TLTU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'TEQ_alt_def:\n  shows \"dfn'TEQ = ?x\"\nunfolding dfn'TEQ_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'TNE_alt_def:\n  shows \"dfn'TNE = ?x\"\nunfolding dfn'TNE_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'TGEI_alt_def:\n  shows \"dfn'TGEI = ?x\"\nunfolding dfn'TGEI_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'TGEIU_alt_def:\n  shows \"dfn'TGEIU = ?x\"\nunfolding dfn'TGEIU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'TLTI_alt_def:\n  shows \"dfn'TLTI = ?x\"\nunfolding dfn'TLTI_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'TLTIU_alt_def:\n  shows \"dfn'TLTIU = ?x\"\nunfolding dfn'TLTIU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'TEQI_alt_def:\n  shows \"dfn'TEQI = ?x\"\nunfolding dfn'TEQI_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'TNEI_alt_def:\n  shows \"dfn'TNEI = ?x\"\nunfolding dfn'TNEI_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal loadByte_alt_def:\n  shows \"loadByte = ?x\"\nunfolding loadByte_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal loadHalf_alt_def:\n  shows \"loadHalf = ?x\"\nunfolding loadHalf_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal loadWord_alt_def:\n  shows \"loadWord = ?x\"\nunfolding loadWord_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal loadDoubleword_alt_def:\n  shows \"loadDoubleword = ?x\"\nunfolding loadDoubleword_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'LB_alt_def:\n  shows \"dfn'LB = ?x\"\nunfolding dfn'LB_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'LBU_alt_def:\n  shows \"dfn'LBU = ?x\"\nunfolding dfn'LBU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'LH_alt_def:\n  shows \"dfn'LH = ?x\"\nunfolding dfn'LH_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'LHU_alt_def:\n  shows \"dfn'LHU = ?x\"\nunfolding dfn'LHU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'LW_alt_def:\n  shows \"dfn'LW = ?x\"\nunfolding dfn'LW_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'LWU_alt_def:\n  shows \"dfn'LWU = ?x\"\nunfolding dfn'LWU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'LL_alt_def:\n  shows \"dfn'LL = ?x\"\nunfolding dfn'LL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'LD_alt_def:\n  shows \"dfn'LD = ?x\"\nunfolding dfn'LD_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'LLD_alt_def:\n  shows \"dfn'LLD = ?x\"\nunfolding dfn'LLD_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'LWL_alt_def:\n  shows \"dfn'LWL = ?x\"\nunfolding dfn'LWL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'LWR_alt_def:\n  shows \"dfn'LWR = ?x\"\nunfolding dfn'LWR_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'LDL_alt_def:\n  shows \"dfn'LDL = ?x\"\nunfolding dfn'LDL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'LDR_alt_def:\n  shows \"dfn'LDR = ?x\"\nunfolding dfn'LDR_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SB_alt_def:\n  shows \"dfn'SB = ?x\"\nunfolding dfn'SB_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SH_alt_def:\n  shows \"dfn'SH = ?x\"\nunfolding dfn'SH_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal storeWord_alt_def:\n  shows \"storeWord = ?x\"\nunfolding storeWord_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal storeDoubleword_alt_def:\n  shows \"storeDoubleword = ?x\"\nunfolding storeDoubleword_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SW_alt_def:\n  shows \"dfn'SW = ?x\"\nunfolding dfn'SW_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SD_alt_def:\n  shows \"dfn'SD = ?x\"\nunfolding dfn'SD_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SC_alt_def:\n  shows \"dfn'SC = ?x\"\nunfolding dfn'SC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SCD_alt_def:\n  shows \"dfn'SCD = ?x\"\nunfolding dfn'SCD_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SWL_alt_def:\n  shows \"dfn'SWL = ?x\"\nunfolding dfn'SWL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SWR_alt_def:\n  shows \"dfn'SWR = ?x\"\nunfolding dfn'SWR_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SDL_alt_def:\n  shows \"dfn'SDL = ?x\"\nunfolding dfn'SDL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SDR_alt_def:\n  shows \"dfn'SDR = ?x\"\nunfolding dfn'SDR_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'BREAK_alt_def:\n  shows \"dfn'BREAK = ?x\"\nunfolding dfn'BREAK_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'SYSCALL_alt_def:\n  shows \"dfn'SYSCALL = ?x\"\nunfolding dfn'SYSCALL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'MTC0_alt_def:\n  shows \"dfn'MTC0 = ?x\"\nunfolding dfn'MTC0_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DMTC0_alt_def:\n  shows \"dfn'DMTC0 = ?x\"\nunfolding dfn'DMTC0_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'MFC0_alt_def:\n  shows \"dfn'MFC0 = ?x\"\nunfolding dfn'MFC0_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DMFC0_alt_def:\n  shows \"dfn'DMFC0 = ?x\"\nunfolding dfn'DMFC0_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'J_alt_def:\n  shows \"dfn'J = ?x\"\nunfolding dfn'J_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'JAL_alt_def:\n  shows \"dfn'JAL = ?x\"\nunfolding dfn'JAL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'JALR_alt_def:\n  shows \"dfn'JALR = ?x\"\nunfolding dfn'JALR_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'JR_alt_def:\n  shows \"dfn'JR = ?x\"\nunfolding dfn'JR_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'BEQ_alt_def:\n  shows \"dfn'BEQ = ?x\"\nunfolding dfn'BEQ_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'BNE_alt_def:\n  shows \"dfn'BNE = ?x\"\nunfolding dfn'BNE_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'BLEZ_alt_def:\n  shows \"dfn'BLEZ = ?x\"\nunfolding dfn'BLEZ_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'BGTZ_alt_def:\n  shows \"dfn'BGTZ = ?x\"\nunfolding dfn'BGTZ_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'BLTZ_alt_def:\n  shows \"dfn'BLTZ = ?x\"\nunfolding dfn'BLTZ_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'BGEZ_alt_def:\n  shows \"dfn'BGEZ = ?x\"\nunfolding dfn'BGEZ_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'BLTZAL_alt_def:\n  shows \"dfn'BLTZAL = ?x\"\nunfolding dfn'BLTZAL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'BGEZAL_alt_def:\n  shows \"dfn'BGEZAL = ?x\"\nunfolding dfn'BGEZAL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'BEQL_alt_def:\n  shows \"dfn'BEQL = ?x\"\nunfolding dfn'BEQL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'BNEL_alt_def:\n  shows \"dfn'BNEL = ?x\"\nunfolding dfn'BNEL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'BLEZL_alt_def:\n  shows \"dfn'BLEZL = ?x\"\nunfolding dfn'BLEZL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'BGTZL_alt_def:\n  shows \"dfn'BGTZL = ?x\"\nunfolding dfn'BGTZL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'BLTZL_alt_def:\n  shows \"dfn'BLTZL = ?x\"\nunfolding dfn'BLTZL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'BGEZL_alt_def:\n  shows \"dfn'BGEZL = ?x\"\nunfolding dfn'BGEZL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'BLTZALL_alt_def:\n  shows \"dfn'BLTZALL = ?x\"\nunfolding dfn'BLTZALL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'BGEZALL_alt_def:\n  shows \"dfn'BGEZALL = ?x\"\nunfolding dfn'BGEZALL_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'RDHWR_alt_def:\n  shows \"dfn'RDHWR = ?x\"\nunfolding dfn'RDHWR_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CACHE_alt_def:\n  shows \"dfn'CACHE = ?x\"\nunfolding dfn'CACHE_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'ReservedInstruction_alt_def:\n  shows \"dfn'ReservedInstruction = ?x\"\nunfolding dfn'ReservedInstruction_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'Unpredictable_alt_def:\n  shows \"dfn'Unpredictable = ?x\"\nunfolding dfn'Unpredictable_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'TLBP_alt_def:\n  shows \"dfn'TLBP = ?x\"\nunfolding dfn'TLBP_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'TLBR_alt_def:\n  shows \"dfn'TLBR = ?x\"\nunfolding dfn'TLBR_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'TLBWI_alt_def:\n  shows \"dfn'TLBWI = ?x\"\nunfolding dfn'TLBWI_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'TLBWR_alt_def:\n  shows \"dfn'TLBWR = ?x\"\nunfolding dfn'TLBWR_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'COP1_alt_def:\n  shows \"dfn'COP1 = ?x\"\nunfolding dfn'COP1_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal watchOOB_alt_def [simp]:\n  shows \"watchOOB = ?x\"\nunfolding watchOOB_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'DumpCapReg_alt_def [simp]:\n  shows \"dfn'DumpCapReg = ?x\"\nunfolding dfn'DumpCapReg_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CGetBase_alt_def:\n  shows \"dfn'CGetBase = ?x\"\nunfolding dfn'CGetBase_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CGetOffset_alt_def:\n  shows \"dfn'CGetOffset = ?x\"\nunfolding dfn'CGetOffset_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CGetLen_alt_def:\n  shows \"dfn'CGetLen = ?x\"\nunfolding dfn'CGetLen_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CGetTag_alt_def:\n  shows \"dfn'CGetTag = ?x\"\nunfolding dfn'CGetTag_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CGetSealed_alt_def:\n  shows \"dfn'CGetSealed = ?x\"\nunfolding dfn'CGetSealed_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CGetPerm_alt_def:\n  shows \"dfn'CGetPerm = ?x\"\nunfolding dfn'CGetPerm_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CGetType_alt_def:\n  shows \"dfn'CGetType = ?x\"\nunfolding dfn'CGetType_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CGetAddr_alt_def:\n  shows \"dfn'CGetAddr = ?x\"\nunfolding dfn'CGetAddr_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CGetPCC_alt_def:\n  shows \"dfn'CGetPCC = ?x\"\nunfolding dfn'CGetPCC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CGetPCCSetOffset_alt_def:\n  shows \"dfn'CGetPCCSetOffset = ?x\"\nunfolding dfn'CGetPCCSetOffset_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CGetCause_alt_def:\n  shows \"dfn'CGetCause = ?x\"\nunfolding dfn'CGetCause_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CSetCause_alt_def:\n  shows \"dfn'CSetCause = ?x\"\nunfolding dfn'CSetCause_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CIncOffset_alt_def:\n  shows \"dfn'CIncOffset = ?x\"\nunfolding dfn'CIncOffset_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CIncOffsetImmediate_alt_def:\n  shows \"dfn'CIncOffsetImmediate = ?x\"\nunfolding dfn'CIncOffsetImmediate_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CSetBounds_alt_def:\n  shows \"dfn'CSetBounds = ?x\"\nunfolding dfn'CSetBounds_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CSetBoundsExact_alt_def:\n  shows \"dfn'CSetBoundsExact = ?x\"\nunfolding dfn'CSetBoundsExact_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CSetBoundsImmediate_alt_def:\n  shows \"dfn'CSetBoundsImmediate = ?x\"\nunfolding dfn'CSetBoundsImmediate_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal ClearRegs_alt_def:\n  shows \"ClearRegs = ?x\"\nunfolding ClearRegs_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'ClearLo_alt_def:\n  shows \"dfn'ClearLo = ?x\"\nunfolding dfn'ClearLo_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'ClearHi_alt_def:\n  shows \"dfn'ClearHi = ?x\"\nunfolding dfn'ClearHi_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CClearLo_alt_def:\n  shows \"dfn'CClearLo = ?x\"\nunfolding dfn'CClearLo_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CClearHi_alt_def:\n  shows \"dfn'CClearHi = ?x\"\nunfolding dfn'CClearHi_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CClearTag_alt_def:\n  shows \"dfn'CClearTag = ?x\"\nunfolding dfn'CClearTag_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CAndPerm_alt_def:\n  shows \"dfn'CAndPerm = ?x\"\nunfolding dfn'CAndPerm_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CSetOffset_alt_def:\n  shows \"dfn'CSetOffset = ?x\"\nunfolding dfn'CSetOffset_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CSub_alt_def:\n  shows \"dfn'CSub = ?x\"\nunfolding dfn'CSub_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CCheckPerm_alt_def:\n  shows \"dfn'CCheckPerm = ?x\"\nunfolding dfn'CCheckPerm_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CCheckType_alt_def:\n  shows \"dfn'CCheckType = ?x\"\nunfolding dfn'CCheckType_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CFromPtr_alt_def:\n  shows \"dfn'CFromPtr = ?x\"\nunfolding dfn'CFromPtr_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CToPtr_alt_def:\n  shows \"dfn'CToPtr = ?x\"\nunfolding dfn'CToPtr_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal CPtrCmp_alt_def:\n  shows \"CPtrCmp = ?x\"\nunfolding CPtrCmp_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CEQ_alt_def:\n  shows \"dfn'CEQ = ?x\"\nunfolding dfn'CEQ_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CNE_alt_def:\n  shows \"dfn'CNE = ?x\"\nunfolding dfn'CNE_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CLT_alt_def:\n  shows \"dfn'CLT = ?x\"\nunfolding dfn'CLT_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CLE_alt_def:\n  shows \"dfn'CLE = ?x\"\nunfolding dfn'CLE_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CLTU_alt_def:\n  shows \"dfn'CLTU = ?x\"\nunfolding dfn'CLTU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CLEU_alt_def:\n  shows \"dfn'CLEU = ?x\"\nunfolding dfn'CLEU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CEXEQ_alt_def:\n  shows \"dfn'CEXEQ = ?x\"\nunfolding dfn'CEXEQ_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CNEXEQ_alt_def:\n  shows \"dfn'CNEXEQ = ?x\"\nunfolding dfn'CNEXEQ_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CBTU_alt_def:\n  shows \"dfn'CBTU = ?x\"\nunfolding dfn'CBTU_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CBTS_alt_def:\n  shows \"dfn'CBTS = ?x\"\nunfolding dfn'CBTS_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CBEZ_alt_def:\n  shows \"dfn'CBEZ = ?x\"\nunfolding dfn'CBEZ_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CBNZ_alt_def:\n  shows \"dfn'CBNZ = ?x\"\nunfolding dfn'CBNZ_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CSC_alt_def:\n  shows \"dfn'CSC = ?x\"\nunfolding dfn'CSC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CLC_alt_def:\n  shows \"dfn'CLC = ?x\"\nunfolding dfn'CLC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CLoad_alt_def:\n  shows \"dfn'CLoad = ?x\"\nunfolding dfn'CLoad_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal store_alt_def:\n  shows \"store = ?x\"\nunfolding store_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CStore_alt_def:\n  shows \"dfn'CStore = ?x\"\nunfolding dfn'CStore_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CLLC_alt_def:\n  shows \"dfn'CLLC = ?x\"\nunfolding dfn'CLLC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CLLx_alt_def:\n  shows \"dfn'CLLx = ?x\"\nunfolding dfn'CLLx_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CSCC_alt_def:\n  shows \"dfn'CSCC = ?x\"\nunfolding dfn'CSCC_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CSCx_alt_def:\n  shows \"dfn'CSCx = ?x\"\nunfolding dfn'CSCx_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CMOVN_alt_def:\n  shows \"dfn'CMOVN = ?x\"\nunfolding dfn'CMOVN_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CMOVZ_alt_def:\n  shows \"dfn'CMOVZ = ?x\"\nunfolding dfn'CMOVZ_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CMove_alt_def:\n  shows \"dfn'CMove = ?x\"\nunfolding dfn'CMove_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CTestSubset_alt_def:\n  shows \"dfn'CTestSubset = ?x\"\nunfolding dfn'CTestSubset_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CBuildCap_alt_def:\n  shows \"dfn'CBuildCap = ?x\"\nunfolding dfn'CBuildCap_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CCopyType_alt_def:\n  shows \"dfn'CCopyType = ?x\"\nunfolding dfn'CCopyType_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CJR_alt_def:\n  shows \"dfn'CJR = ?x\"\nunfolding dfn'CJR_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CJALR_alt_def:\n  shows \"dfn'CJALR = ?x\"\nunfolding dfn'CJALR_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CSeal_alt_def:\n  shows \"dfn'CSeal = ?x\"\nunfolding dfn'CSeal_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CUnseal_alt_def:\n  shows \"dfn'CUnseal = ?x\"\nunfolding dfn'CUnseal_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CCall_alt_def:\n  shows \"dfn'CCall = ?x\"\nunfolding dfn'CCall_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CCallFast_alt_def:\n  shows \"dfn'CCallFast = ?x\"\nunfolding dfn'CCallFast_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal special_register_accessible_alt_def:\n  shows \"special_register_accessible = ?x\"\nunfolding special_register_accessible_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CReadHwr_alt_def:\n  shows \"dfn'CReadHwr = ?x\"\nunfolding dfn'CReadHwr_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CWriteHwr_alt_def:\n  shows \"dfn'CWriteHwr = ?x\"\nunfolding dfn'CWriteHwr_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'CReturn_alt_def:\n  shows \"dfn'CReturn = ?x\"\nunfolding dfn'CReturn_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal dfn'UnknownCapInstruction_alt_def:\n  shows \"dfn'UnknownCapInstruction = ?x\"\nunfolding dfn'UnknownCapInstruction_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal log_instruction_alt_def:\n  shows \"log_instruction = ?x\"\nunfolding log_instruction_def\nunfolding Let_def\nby compute_alt_def\n\nschematic_goal Run_alt_def:\n  shows \"Run = ?x\"\nunfolding Run_def\nunfolding Let_def\nby compute_alt_def\n\n(* Code generation - override - Next *)\n\nschematic_goal Next_alt_def_aux:\n  shows \"Next = ?x\"\nunfolding Next_def\nunfolding Let_def\nby compute_alt_def\n\ndefinition TakeBranch :: \"state \\<Rightarrow> unit \\<times> state\" where\n  \"TakeBranch \\<equiv>\n   bind (read_state getBranchDelay)\n        (\\<lambda>v. bind (read_state getBranchTo)\n        (\\<lambda>a. bind (read_state BranchDelayPCC)\n        (\\<lambda>aa. bind (read_state BranchToPCC)\n        (\\<lambda>aaa. (case v of None \\<Rightarrow> \n                 (case a of None \\<Rightarrow> \n                   (case aa of None \\<Rightarrow> \n                     (case aaa of None \\<Rightarrow> \n                       bind (read_state getExceptionSignalled)\n                            (\\<lambda>v. if \\<not> v \n                                 then bind (read_state getPC)\n                                           (\\<lambda>v. update_state (setPC (v + 4)))\n                                 else return ())\n                     | Some a \\<Rightarrow> \n                       bind (update_state (BranchDelayPCC_update (\\<lambda>_. Some a)))\n                            (\\<lambda>_. bind (update_state (BranchToPCC_update Map.empty))\n                            (\\<lambda>_. bind (read_state getPC) \n                            (\\<lambda>v. update_state (setPC (v + 4))))))\n                   | Some (addr, cap) \\<Rightarrow> \n                     (case aaa of None \\<Rightarrow>\n                       bind (update_state (BranchDelayPCC_update Map.empty)) \n                            (\\<lambda>_. bind (update_state (setPC addr)) \n                            (\\<lambda>_. write'PCC cap))\n                     | Some aa \\<Rightarrow> \n                       raise'exception (UNPREDICTABLE ''Branch follows branch'')))\n                 | Some addr \\<Rightarrow> \n                   (case aa of None \\<Rightarrow> \n                     (case aaa of None \\<Rightarrow> \n                       bind (update_state (setBranchDelay (Some addr)))\n                            (\\<lambda>_. bind (update_state (setBranchTo None)) \n                            (\\<lambda>_. bind (read_state getPC) \n                            (\\<lambda>v. update_state (setPC (v + 4)))))\n                     | Some a \\<Rightarrow> \n                       raise'exception (UNPREDICTABLE ''Branch follows branch''))\n                   | Some ab \\<Rightarrow> \n                       raise'exception (UNPREDICTABLE ''Branch follows branch'')))\n               | Some addr \\<Rightarrow> \n                 (case a of None \\<Rightarrow> \n                   (case aa of None \\<Rightarrow> \n                     (case aaa of None \\<Rightarrow> \n                       bind (update_state (setBranchDelay None)) \n                            (\\<lambda>_. update_state (setPC addr))\n                     | Some a \\<Rightarrow> \n                       raise'exception (UNPREDICTABLE ''Branch follows branch''))\n                   | Some ab \\<Rightarrow> \n                       raise'exception (UNPREDICTABLE ''Branch follows branch''))\n                 | Some ab \\<Rightarrow> \n                       raise'exception (UNPREDICTABLE ''Branch follows branch'')))))))\" \n\nlemma Next_alt_def:\n  shows \"Next =\n         bind (update_state (currentInst_update Map.empty))\n              (\\<lambda>_. bind Fetch \n              (\\<lambda>v. bind (update_state (currentInst_update (\\<lambda>_. v)))\n              (\\<lambda>_. bind (read_state currentInst)\n              (\\<lambda>v. bind (case v of None \\<Rightarrow> return () | Some w \\<Rightarrow> Run (Decode w))\n              (\\<lambda>_. bind TakeBranch\n              (\\<lambda>_. bind (update_state (setExceptionSignalled False))\n              (\\<lambda>_. bind (read_state getCP0Count) \n              (\\<lambda>b. bind (update_state (setCP0Count (b + 1)))\n              (\\<lambda>_. bind (read_state currentInst) \n              (\\<lambda>v. update_state (lastInst_update (\\<lambda>_. v))))))))))))\"\nunfolding Next_alt_def_aux TakeBranch_def\nby (simp add: bind_associativity)\n\n(* Code generation - end override *)\n\n(* Code generation - end *)\n\n(*<*)\nend\n(*>*)", "meta": {"author": "CTSRD-CHERI", "repo": "l3-cheri-mips-proofs", "sha": "239c37ad1587caf261501478bbcd1293b9ecb7b7", "save_path": "github-repos/isabelle/CTSRD-CHERI-l3-cheri-mips-proofs", "path": "github-repos/isabelle/CTSRD-CHERI-l3-cheri-mips-proofs/l3-cheri-mips-proofs-239c37ad1587caf261501478bbcd1293b9ecb7b7/core/CheriAltDefs.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.519521321952093, "lm_q2_score": 0.5736784074525096, "lm_q1q2_score": 0.29803816461509924}}
{"text": "section \\<open>State monad transformer\\<close>\n\ntheory State_Transformer\nimports Monad_Zero_Plus\nbegin\n\ntext \\<open>\n  This version has non-lifted product, and a non-lifted function space.\n\\<close>\n\ntycondef 'a\\<cdot>('f::\"functor\", 's) stateT =\n  StateT (runStateT :: \"'s \\<rightarrow> ('a \\<times> 's)\\<cdot>'f\")\n\nlemma coerce_stateT_abs [simp]: \"coerce\\<cdot>(stateT_abs\\<cdot>x) = stateT_abs\\<cdot>(coerce\\<cdot>x)\"\napply (simp add: stateT_abs_def coerce_def)\napply (simp add: emb_prj_emb prj_emb_prj DEFL_eq_stateT)\ndone\n\nlemma coerce_StateT [simp]: \"coerce\\<cdot>(StateT\\<cdot>k) = StateT\\<cdot>(coerce\\<cdot>k)\"\nunfolding StateT_def by simp\n\nlemma stateT_cases [case_names StateT]:\n  obtains k where \"y = StateT\\<cdot>k\"\nproof\n  show \"y = StateT\\<cdot>(runStateT\\<cdot>y)\"\n    by (cases y, simp_all)\nqed\n\nlemma stateT_induct [case_names StateT]:\n  fixes P :: \"'a\\<cdot>('f::functor,'s) stateT \\<Rightarrow> bool\"\n  assumes \"\\<And>k. P (StateT\\<cdot>k)\"\n  shows \"P y\"\nby (cases y rule: stateT_cases, simp add: assms)\n\nlemma stateT_eqI:\n  \"(\\<And>s. runStateT\\<cdot>a\\<cdot>s = runStateT\\<cdot>b\\<cdot>s) \\<Longrightarrow> a = b\"\napply (cases a rule: stateT_cases)\napply (cases b rule: stateT_cases)\napply (simp add: cfun_eq_iff)\ndone\n\nlemma runStateT_coerce [simp]:\n  \"runStateT\\<cdot>(coerce\\<cdot>k)\\<cdot>s = coerce\\<cdot>(runStateT\\<cdot>k\\<cdot>s)\"\nby (induct k rule: stateT_induct, simp)\n\nsubsection \\<open>Functor class instance\\<close>\n\nlemma fmapU_StateT [simp]:\n  \"fmapU\\<cdot>f\\<cdot>(StateT\\<cdot>k) =\n    StateT\\<cdot>(\\<Lambda> s. fmap\\<cdot>(\\<Lambda>(x, s'). (f\\<cdot>x, s'))\\<cdot>(k\\<cdot>s))\"\nunfolding fmapU_stateT_def stateT_map_def StateT_def\nby (subst fix_eq, simp add: cfun_map_def csplit_def prod_map_def)\n\nlemma runStateT_fmapU [simp]:\n  \"runStateT\\<cdot>(fmapU\\<cdot>f\\<cdot>m)\\<cdot>s =\n    fmap\\<cdot>(\\<Lambda>(x, s'). (f\\<cdot>x, s'))\\<cdot>(runStateT\\<cdot>m\\<cdot>s)\"\nby (cases m rule: stateT_cases, simp)\n\ninstantiation stateT :: (\"functor\", \"domain\") \"functor\"\nbegin\n\ninstance\napply standard\napply (induct_tac xs rule: stateT_induct)\napply (simp_all add: fmap_fmap ID_def csplit_def)\ndone\n\nend\n\nsubsection \\<open>Monad class instance\\<close>\n\ninstantiation stateT :: (monad, \"domain\") monad\nbegin\n\ndefinition returnU_stateT_def:\n  \"returnU = (\\<Lambda> x. StateT\\<cdot>(\\<Lambda> s. return\\<cdot>(x, s)))\"\n\ndefinition bindU_stateT_def:\n  \"bindU = (\\<Lambda> m k. StateT\\<cdot>(\\<Lambda> s. runStateT\\<cdot>m\\<cdot>s \\<bind> (\\<Lambda> (x, s'). runStateT\\<cdot>(k\\<cdot>x)\\<cdot>s')))\"\n\nlemma bindU_stateT_StateT [simp]:\n  \"bindU\\<cdot>(StateT\\<cdot>f)\\<cdot>k =\n    StateT\\<cdot>(\\<Lambda> s. f\\<cdot>s \\<bind> (\\<Lambda> (x, s'). runStateT\\<cdot>(k\\<cdot>x)\\<cdot>s'))\"\nunfolding bindU_stateT_def by simp\n\nlemma runStateT_bindU [simp]:\n  \"runStateT\\<cdot>(bindU\\<cdot>m\\<cdot>k)\\<cdot>s = runStateT\\<cdot>m\\<cdot>s \\<bind> (\\<Lambda> (x, s'). runStateT\\<cdot>(k\\<cdot>x)\\<cdot>s')\"\nunfolding bindU_stateT_def by simp\n\ninstance proof\n  fix f :: \"udom \\<rightarrow> udom\" and r :: \"udom\\<cdot>('a,'b) stateT\"\n  show \"fmapU\\<cdot>f\\<cdot>r = bindU\\<cdot>r\\<cdot>(\\<Lambda> x. returnU\\<cdot>(f\\<cdot>x))\"\n    by (rule stateT_eqI)\n       (simp add: returnU_stateT_def monad_fmap prod_map_def csplit_def)\nnext\n  fix f :: \"udom \\<rightarrow> udom\\<cdot>('a,'b) stateT\" and x :: \"udom\"\n  show \"bindU\\<cdot>(returnU\\<cdot>x)\\<cdot>f = f\\<cdot>x\"\n    by (rule stateT_eqI)\n       (simp add: returnU_stateT_def eta_cfun)\nnext\n  fix r :: \"udom\\<cdot>('a,'b) stateT\" and f g :: \"udom \\<rightarrow> udom\\<cdot>('a,'b) stateT\"\n  show \"bindU\\<cdot>(bindU\\<cdot>r\\<cdot>f)\\<cdot>g = bindU\\<cdot>r\\<cdot>(\\<Lambda> x. bindU\\<cdot>(f\\<cdot>x)\\<cdot>g)\"\n    by (rule stateT_eqI)\n       (simp add: bind_bind csplit_def)\nqed\n\nend\n\nsubsection \\<open>Monad zero instance\\<close>\n\ninstantiation stateT :: (monad_zero, \"domain\") monad_zero\nbegin\n\ndefinition zeroU_stateT_def:\n  \"zeroU = StateT\\<cdot>(\\<Lambda> s. mzero)\"\n\nlemma runStateT_zeroU [simp]:\n  \"runStateT\\<cdot>zeroU\\<cdot>s = mzero\"\nunfolding zeroU_stateT_def by simp\n\ninstance proof\n  fix k :: \"udom \\<rightarrow> udom\\<cdot>('a,'b) stateT\"\n  show \"bindU\\<cdot>zeroU\\<cdot>k = zeroU\"\n    by (rule stateT_eqI, simp add: bind_mzero)\nqed\n\nend\n\nsubsection \\<open>Monad plus instance\\<close>\n\ninstantiation stateT :: (monad_plus, \"domain\") monad_plus\nbegin\n\ndefinition plusU_stateT_def:\n  \"plusU = (\\<Lambda> a b. StateT\\<cdot>(\\<Lambda> s. mplus\\<cdot>(runStateT\\<cdot>a\\<cdot>s)\\<cdot>(runStateT\\<cdot>b\\<cdot>s)))\"\n\nlemma runStateT_plusU [simp]:\n  \"runStateT\\<cdot>(plusU\\<cdot>a\\<cdot>b)\\<cdot>s =\n    mplus\\<cdot>(runStateT\\<cdot>a\\<cdot>s)\\<cdot>(runStateT\\<cdot>b\\<cdot>s)\"\nunfolding plusU_stateT_def by simp\n\ninstance proof\n  fix a b :: \"udom\\<cdot>('a, 'b) stateT\" and k :: \"udom \\<rightarrow> udom\\<cdot>('a, 'b) stateT\"\n  show \"bindU\\<cdot>(plusU\\<cdot>a\\<cdot>b)\\<cdot>k = plusU\\<cdot>(bindU\\<cdot>a\\<cdot>k)\\<cdot>(bindU\\<cdot>b\\<cdot>k)\"\n    by (rule stateT_eqI, simp add: bind_mplus)\nnext\n  fix a b c :: \"udom\\<cdot>('a, 'b) stateT\"\n  show \"plusU\\<cdot>(plusU\\<cdot>a\\<cdot>b)\\<cdot>c = plusU\\<cdot>a\\<cdot>(plusU\\<cdot>b\\<cdot>c)\"\n    by (rule stateT_eqI, simp add: mplus_assoc)\nqed\n\nend\n\nsubsection \\<open>Monad zero plus instance\\<close>\n\ninstance stateT :: (monad_zero_plus, \"domain\") monad_zero_plus\nproof\n  fix m :: \"udom\\<cdot>('a, 'b) stateT\"\n  show \"plusU\\<cdot>zeroU\\<cdot>m = m\"\n    by (rule stateT_eqI, simp add: mplus_mzero_left)\nnext\n  fix m :: \"udom\\<cdot>('a, 'b) stateT\"\n  show \"plusU\\<cdot>m\\<cdot>zeroU = m\"\n    by (rule stateT_eqI, simp add: mplus_mzero_right)\nqed\n\nsubsection \\<open>Transfer properties to polymorphic versions\\<close>\n\nlemma coerce_csplit [coerce_simp]:\n  shows \"coerce\\<cdot>(csplit\\<cdot>f\\<cdot>p) = csplit\\<cdot>(\\<Lambda> x y. coerce\\<cdot>(f\\<cdot>x\\<cdot>y))\\<cdot>p\"\nunfolding csplit_def by simp\n\nlemma csplit_coerce [coerce_simp]:\n  fixes p :: \"'a \\<times> 'b\"\n  shows \"csplit\\<cdot>f\\<cdot>(COERCE('a \\<times> 'b, 'c \\<times> 'd)\\<cdot>p) =\n    csplit\\<cdot>(\\<Lambda> x y. f\\<cdot>(COERCE('a, 'c)\\<cdot>x)\\<cdot>(COERCE('b, 'd)\\<cdot>y))\\<cdot>p\"\nunfolding coerce_prod csplit_def prod_map_def by simp\n\nlemma fmap_stateT_simps [simp]:\n  \"fmap\\<cdot>f\\<cdot>(StateT\\<cdot>m :: 'a\\<cdot>('f::functor,'s) stateT) =\n    StateT\\<cdot>(\\<Lambda> s. fmap\\<cdot>(\\<Lambda> (x, s'). (f\\<cdot>x, s'))\\<cdot>(m\\<cdot>s))\"\nunfolding fmap_def [where 'f=\"('f, 's) stateT\"]\nby (simp add: coerce_simp eta_cfun)\n\nlemma runStateT_fmap [simp]:\n  \"runStateT\\<cdot>(fmap\\<cdot>f\\<cdot>m)\\<cdot>s = fmap\\<cdot>(\\<Lambda> (x, s'). (f\\<cdot>x, s'))\\<cdot>(runStateT\\<cdot>m\\<cdot>s)\"\nby (induct m rule: stateT_induct, simp)\n\nlemma return_stateT_def:\n  \"(return :: _ \\<rightarrow> 'a\\<cdot>('m::monad, 's) stateT) =\n    (\\<Lambda> x. StateT\\<cdot>(\\<Lambda> s. return\\<cdot>(x, s)))\"\nunfolding return_def [where 'm=\"('m, 's) stateT\"] returnU_stateT_def\nby (simp add: coerce_simp)\n\nlemma bind_stateT_def:\n  \"bind = (\\<Lambda> m k. StateT\\<cdot>(\\<Lambda> s. runStateT\\<cdot>m\\<cdot>s \\<bind> (\\<Lambda> (x, s'). runStateT\\<cdot>(k\\<cdot>x)\\<cdot>s')))\"\napply (subst bind_def, subst bindU_stateT_def)\napply (simp add: coerce_simp)\napply (simp add: coerce_idem domain_defl_simps monofun_cfun)\napply (simp add: eta_cfun)\ndone\n\ntext \"TODO: add \\<open>coerce_idem\\<close> to \\<open>coerce_simps\\<close>, along\\010with monotonicity rules for DEFL.\"\n\nlemma bind_stateT_simps [simp]:\n  \"bind\\<cdot>(StateT\\<cdot>m :: 'a\\<cdot>('m::monad,'s) stateT)\\<cdot>k =\n    StateT\\<cdot>(\\<Lambda> s. m\\<cdot>s \\<bind> (\\<Lambda> (x, s'). runStateT\\<cdot>(k\\<cdot>x)\\<cdot>s'))\"\nunfolding bind_stateT_def by simp\n\nlemma runStateT_bind [simp]:\n  \"runStateT\\<cdot>(m \\<bind> k)\\<cdot>s = runStateT\\<cdot>m\\<cdot>s \\<bind> (\\<Lambda> (x, s'). runStateT\\<cdot>(k\\<cdot>x)\\<cdot>s')\"\nunfolding bind_stateT_def by simp\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Tycon/State_Transformer.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.519521321952093, "lm_q2_score": 0.5736784074525096, "lm_q1q2_score": 0.29803816461509924}}
{"text": "(*  Title:      HOL/Auth/n_mutualEx_lemma_inv__2_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n \n\ntheory n_mutualEx_lemma_inv__2_on_rules imports n_mutualEx_lemma_on_inv__2\nbegin\nsection{*All lemmas on causal relation between inv__2*}\nlemma lemma_inv__2_on_rules:\n  assumes b1: \"r \\<in> rules N\" and b2: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__2  p__Inv4)\"\n  shows \"invHoldForRule Interp s f r (invariants N)\"\n  proof -\n  have c1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n  apply (cut_tac b1, auto) done\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\"\n      have \"invHoldForRule Interp s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_TryVsinv__2) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\"\n      have \"invHoldForRule Interp s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_CritVsinv__2) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\"\n      have \"invHoldForRule Interp s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_ExitVsinv__2) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n      have \"invHoldForRule Interp s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_IdleVsinv__2) done\n    }\n\n  ultimately show \"invHoldForRule Interp s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "lyj238Gmail", "repo": "gsteProof", "sha": "3070d08e1f31a93be6fde85ab6b65d489c05f99e", "save_path": "github-repos/isabelle/lyj238Gmail-gsteProof", "path": "github-repos/isabelle/lyj238Gmail-gsteProof/gsteProof-3070d08e1f31a93be6fde85ab6b65d489c05f99e/mutualEx/n_mutualEx_lemma_inv__2_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6688802603710086, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.2980059114002438}}
{"text": "theory Deadlock_Checking\n  imports Deadlock_Impl Uppaal_Networks.UPPAAL_Model_Checking\nbegin\n\nparagraph \\<open>Standard Deadlock Checker Implementation\\<close>\ncontext Reachability_Problem_Impl\nbegin\n\ndefinition deadlock_checker where\n  \"deadlock_checker \\<equiv>\n    let\n      key = return \\<circ> fst;\n      sub = subsumes_impl;\n      copy = state_copy_impl;\n      start = a\\<^sub>0_impl;\n      final = (\\<lambda>_. return False);\n      succs = succs_impl;\n      empty = emptiness_check_impl;\n      P = check_deadlock_neg_impl;\n      trace = tracei\n    in do {\n      r1 \\<leftarrow> is_start_in_states_impl;\n      if r1 then do {\n        r2 \\<leftarrow> check_passed_impl succs start final sub empty key copy trace P;\n        return r2\n      }\n      else return True\n    }\n    \"\n\ninterpretation ta_bisim: Bisimulation_Invariant\n  \"(\\<lambda>(l, u) (l', u'). conv_A A \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow> \\<langle>l', u'\\<rangle>)\"\n  \"(\\<lambda>(l, u) (l', u'). conv_A A \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow> \\<langle>l', u'\\<rangle>)\"\n  \"(\\<lambda>(l, u) (l', u'). l' = l \\<and> (\\<forall> c. c \\<in> clk_set (conv_A A) \\<longrightarrow> u c = u' c))\"\n  \"(\\<lambda>_. True)\" \"(\\<lambda>_. True)\"\n  by (rule ta_bisimulation[of \"conv_A A\"])\n\nlemma deadlock_zero_clock_val_iff:\n  \"(\\<exists>u\\<^sub>0. (\\<forall>c\\<in>{1..n}. u\\<^sub>0 c = 0) \\<and> deadlock (l\\<^sub>0, u\\<^sub>0)) \\<longleftrightarrow> deadlock (l\\<^sub>0, \\<lambda>_. 0)\"\n  apply safe\n  subgoal for u\n    using clocks_I[of \"\\<lambda>_. 0\" u] by (subst ta_bisim.deadlock_iff; simp)\n  by auto\n\ncontext\n  assumes F_fun_False: \"\\<And>x. F_fun x = False\" and F_False: \"F = (\\<lambda>_. False)\"\nbegin\nlemma F_impl_is_False:\n  \"F_impl = (\\<lambda>_. return False)\"\n  unfolding F_impl_def F_fun_False by simp\n\nlemma deadlock_checker_correct:\n  \"(uncurry0 deadlock_checker, uncurry0 (Refine_Basic.RETURN (deadlock (l\\<^sub>0, \\<lambda>_. 0))))\n  \\<in> unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a bool_assn\"\n  unfolding\n    deadlock_checker_def Let_def F_impl_is_False[symmetric]\n    check_passed_impl_start_def[symmetric] deadlock_zero_clock_val_iff[symmetric]\n  using check_passed_impl_start_hnr[OF F_False] .\n\nlemmas deadlock_checker_hoare = deadlock_checker_correct[to_hnr, unfolded hn_refine_def, simplified]\n\nend\n\nend\n\n\ncontext UPPAAL_Reachability_Problem_precompiled'\nbegin\n\ntext \\<open>\n  \\<^item> @{term equiv.defs.states'}\n  \\<^item> @{term EA} is @{term equiv.state_ta},\n    the state automaton constructed from UPPAAL network (\\<open>equiv\\<close>/\\<open>N\\<close>)\n  \\<^item> @{term A} is @{term equiv.defs.prod_ta},\n    the product automaton constructed from UPPAAL network (\\<open>equiv\\<close>/\\<open>N\\<close>)\n\\<close>\n\ncontext\n  fixes \\<phi>\n  assumes formula_is_false: \"formula = formula.EX (and \\<phi> (not \\<phi>))\"\nbegin\n\nlemma F_is_FalseI:\n  shows \"PR_CONST (\\<lambda>(x, y). F x y) = (\\<lambda>_. False)\"\n  unfolding F_def by (subst formula_is_false) auto\n\nlemma final_fun_is_False:\n  \"final_fun a = False\"\n  unfolding final_fun_def by (subst formula_is_false) auto\n\nlemmas deadlock_checker_hoare = impl.deadlock_checker_hoare[\n    OF final_fun_is_False F_is_FalseI, folded deadlock_start_iff has_deadlock_def]\n\nend\n\nschematic_goal deadlock_checker_alt_def:\n  \"impl.deadlock_checker \\<equiv> ?impl\"\n  unfolding impl.deadlock_checker_def impl.succs_impl_def\n  unfolding impl.E_op''_impl_def impl.abstr_repair_impl_def impl.abstra_repair_impl_def\n  unfolding\n    impl.start_inv_check_impl_def impl.unbounded_dbm_impl_def\n    impl.unbounded_dbm'_def unbounded_dbm_def\n  unfolding k_impl_alt_def\n  unfolding impl.check_deadlock_neg_impl_def impl.check_deadlock_impl_def\n  unfolding impl.is_start_in_states_impl_def\n  apply (abstract_let k_i ceiling)\n  apply (abstract_let \"inv_fun :: (_ \\<times> int list \\<Rightarrow> _)\" inv)\n  apply (abstract_let \"trans_fun\" trans)\n  unfolding impl.init_dbm_impl_def impl.a\\<^sub>0_impl_def\n  unfolding impl.F_impl_def\n  unfolding impl.subsumes_impl_def\n  unfolding impl.emptiness_check_impl_def\n  unfolding impl.state_copy_impl_def\n  by (rule Pure.reflexive)\n\nschematic_goal deadlock_checker_alt_def_refined:\n  \"impl.deadlock_checker \\<equiv> ?impl\"\n  unfolding deadlock_checker_alt_def\n  unfolding fw_impl'_int\n  unfolding inv_fun_def trans_fun_def trans_s_fun_def trans_i_fun_def\n  unfolding trans_i_from_impl\n  unfolding runf_impl runt_impl check_g_impl pairs_by_action_impl check_pred_impl\n  apply (abstract_let \"IArray (map IArray inv)\" inv_array)\n  apply (abstract_let \"IArray (map IArray trans_out_map)\" trans_out)\n  apply (abstract_let \"IArray (map IArray trans_in_map)\" trans_in)\n  apply (abstract_let \"IArray (map IArray trans_i_map)\" trans_internal)\n  apply (abstract_let \"IArray bounds\" bounds_array)\n  apply (abstract_let PF PF)\n  apply (abstract_let PT PT)\n  unfolding PF_alt_def PT_alt_def\n  apply (abstract_let PROG' PROG')\n  unfolding PROG'_def\n  apply (abstract_let \"length prog\" len_prog)\n  apply (abstract_let \"IArray (map (map_option stripf) prog)\" prog_f)\n  apply (abstract_let \"IArray (map (map_option stript) prog)\" prog_t)\n  apply (abstract_let \"IArray prog\" prog_array)\n  unfolding all_actions_by_state_impl\n  apply (abstract_let \"[0..<p]\" p_ran)\n  apply (abstract_let \"[0..<na]\" num_actions_ran)\n  apply (abstract_let \"{0..<p}\" num_processes_ran)\n  apply (abstract_let \"[0..<m+1]\" num_clocks_ran)\n  by (rule Pure.reflexive)\n\nend\n\nconcrete_definition deadlock_checker uses\n  UPPAAL_Reachability_Problem_precompiled'.deadlock_checker_alt_def_refined\n\ndefinition\n  \"precond_dc\n    num_processes num_clocks clock_ceiling max_steps I T prog bounds program s\\<^sub>0 num_actions\n  \\<equiv>\n    if UPPAAL_Reachability_Problem_precompiled'\n      num_processes num_clocks max_steps I T prog bounds program s\\<^sub>0 num_actions clock_ceiling\n    then\n      deadlock_checker\n        num_processes num_clocks max_steps I T prog bounds program s\\<^sub>0 num_actions clock_ceiling\n      \\<bind> (\\<lambda>x. return (Some x))\n    else return None\"\n\ntheorem deadlock_check:\n  \"<emp>\n      precond_dc p m k max_steps I T prog bounds P s\\<^sub>0 na\n   <\\<lambda> Some r \\<Rightarrow> \\<up>(\n       UPPAAL_Reachability_Problem_precompiled' p m max_steps I T prog bounds P s\\<^sub>0 na k \\<and>\n       r = has_deadlock (conv (N p I P T prog bounds)) max_steps (repeat 0 p, s\\<^sub>0, \\<lambda>_ . 0))\n    | None \\<Rightarrow> \\<up>(\\<not> UPPAAL_Reachability_Problem_precompiled' p m max_steps I T prog bounds P s\\<^sub>0 na k)\n   >\\<^sub>t\"\nproof -\n  define A where \"A \\<equiv> conv (N p I P T prog bounds)\"\n  note [sep_heap_rules] = UPPAAL_Reachability_Problem_precompiled'.deadlock_checker_hoare[\n      OF _ HOL.refl,\n      of p m max_steps I T prog bounds P s\\<^sub>0 na k,\n      unfolded UPPAAL_Reachability_Problem_precompiled_defs.init_def,\n      folded A_def\n      ]\n  show ?thesis\n    unfolding A_def[symmetric] precond_dc_def\n    by (sep_auto simp:\n        deadlock_checker.refine[symmetric] UPPAAL_Reachability_Problem_precompiled_defs.init_def \n        mod_star_conv has_deadlock_def)\nqed\n\nexport_code precond_dc checking SML\n\nend", "meta": {"author": "wimmers", "repo": "munta", "sha": "62cb1a4a4dbcfcf62c365e90faba15b0012d5a12", "save_path": "github-repos/isabelle/wimmers-munta", "path": "github-repos/isabelle/wimmers-munta/munta-62cb1a4a4dbcfcf62c365e90faba15b0012d5a12/Deadlock/Deadlock_Checking.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6688802603710086, "lm_q2_score": 0.44552953503957266, "lm_q1q2_score": 0.29800591140024374}}
{"text": "theory VCG_Check\n                  \nimports Logic\n        \n\nbegin               \n\n\n(* theorems for the checking the correctness of vcg *)\n\n\nlemma  write_consistent_defined_address:\n  \"\\<Turnstile> \\<lbrace> \\<lambda>s. aval lval s = Some vp \\<and> aval rval s = Some v \\<and> Addr vp \\<notin> incon_set s \\<and>\n      ptable_lift_m (heap s) (root s) (mode s) (Addr vp) = Some pp \\<rbrace>  lval ::= rval \\<lbrace>\\<lambda>s. heap s pp = Some v \\<rbrace>\"\n   by vcgm\n \n(* successful memory writes to inconsistent address after flushing, in Kernel Mode *) \n\n\n\n\n\n\n\nlemma [simp]:\n  \"aval e s = Some v \\<Longrightarrow> aval e (s\\<lparr>incon_set := {}\\<rparr>) = Some v \"\n  by (induct e arbitrary: v; clarsimp split: option.splits; fastforce)\n\n\nlemma [simp]:\n  \"aval e s = Some v \\<Longrightarrow> aval e (s\\<lparr>incon_set := {}, ptable_snapshot := \\<lambda>a. ({}, \\<lambda>v. Fault) \\<rparr>) = Some v \"\n  by (induct e arbitrary: v; clarsimp split: option.splits; fastforce)\n\n\n\n\nend", "meta": {"author": "SEL4PROJ", "repo": "tlb", "sha": "88bb017dd96c3830baed93ba62e45b45050d1417", "save_path": "github-repos/isabelle/SEL4PROJ-tlb", "path": "github-repos/isabelle/SEL4PROJ-tlb/tlb-88bb017dd96c3830baed93ba62e45b45050d1417/Logic/VCG_Check.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6926419704455589, "lm_q2_score": 0.4301473485858429, "lm_q1q2_score": 0.2979381071064309}}
{"text": "theory Diff_Arr_Safe\n  imports Diff_Arr\nbegin\n\ncontext\nbegin\n\nqualified definition lookup where\n  \"lookup arr i = do {\n    len \\<leftarrow> Diff_Arr.length arr;\n    if i < len\n    then Diff_Arr.lookup arr i\n    else return (undefined(i - len))\n  }\"\n\nqualified definition update where\n  \"update arr i v = do {\n    len \\<leftarrow> Diff_Arr.length arr;\n    if i < len\n    then Diff_Arr.update arr i v \n    else return arr\n  }\"\n\nqualified definition update_tailrec where\n  \"update_tailrec arr i v = do {\n    len \\<leftarrow> Diff_Arr.length arr;\n    if i < len\n    then Diff_Arr.update_tailrec arr i v \n    else return arr\n  }\"\n\nlemma nth_undefined: \"i \\<ge> length xs \\<Longrightarrow> xs ! i = undefined(i - length xs)\"\n  unfolding List.nth_def\n  by(induction xs arbitrary: i)(auto split: nat.split)\n\nlemma lookup_safe [sep_heap_rules]: \"\n  <master_assn t * \\<up>(t \\<turnstile> xs \\<sim> a)> \n     lookup a i \n  <\\<lambda>r. master_assn t * \\<up>(r = xs!i)>\"\n  unfolding lookup_def\n  apply sep_auto\n  using length \n  apply sep_auto\n  apply sep_auto\n  using lookup\n  by(sep_auto simp: nth_undefined[of xs i])+\n\nlemma update_safe [sep_heap_rules]: \"\n  <master_assn t * \\<up>(t \\<turnstile> xs \\<sim> diff_arr)> \n     update diff_arr i v\n  <\\<lambda>diff_arr. \\<exists>\\<^sub>At'. master_assn t' * \n    \\<up>((\\<forall>xs' diff_arr'. t \\<turnstile> xs' \\<sim> diff_arr' \\<longrightarrow> t' \\<turnstile> xs' \\<sim> diff_arr') \n      \\<and> (t' \\<turnstile> xs[i := v] \\<sim> diff_arr))>\"\n  unfolding update_def\n  apply sep_auto\n  apply(rule fi_rule[OF length, where F = emp])\n  apply sep_auto+\n  apply(rule cons_post_rule)\n  apply(rule fi_rule[OF update, where F = emp])\n  by sep_auto+\n\nlemma update_tailrec_safe [sep_heap_rules]: \"\n  <master_assn t * \\<up>(t \\<turnstile> xs \\<sim> diff_arr)> \n     update_tailrec diff_arr i v\n  <\\<lambda>diff_arr. \\<exists>\\<^sub>At'. master_assn t' * \n    \\<up>((\\<forall>xs' diff_arr'. t \\<turnstile> xs' \\<sim> diff_arr' \\<longrightarrow> t' \\<turnstile> xs' \\<sim> diff_arr') \n      \\<and> (t' \\<turnstile> xs[i := v] \\<sim> diff_arr))>\"\n  unfolding update_tailrec_def\n  apply sep_auto\n  apply(rule fi_rule[OF length, where F = emp])\n  apply sep_auto+\n  apply(rule cons_post_rule)\n  apply(rule fi_rule[OF update_tailrec, where F = emp])\n  by sep_auto+\n\nend\n\nend\n", "meta": {"author": "balazstothofficial", "repo": "arrays-in-isabelle", "sha": "9d5dd28b0b3d245dae534d546879045a54b4244f", "save_path": "github-repos/isabelle/balazstothofficial-arrays-in-isabelle", "path": "github-repos/isabelle/balazstothofficial-arrays-in-isabelle/arrays-in-isabelle-9d5dd28b0b3d245dae534d546879045a54b4244f/Diff_Arr_Safe.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6150878414043814, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.29793630045720265}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory PackedTypes\nimports CProof\nbegin\n\nsection \\<open>Underlying definitions for the class axioms\\<close>\n\ntext \\<open>field_access / field_update is the identity for packed types\\<close>\n\ndefinition fa_fu_idem :: \"'a field_desc \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"fa_fu_idem fd n \\<equiv>\n     \\<forall>bs bs' v. length bs = n \\<longrightarrow> length bs' = n \\<longrightarrow> field_access fd (field_update fd bs v) bs' = bs\"\n\n(* Is it better to do this or to use a fold over td?  This seems easier to use *)\nprimrec\n  td_fafu_idem :: \"'a field_desc typ_desc \\<Rightarrow> bool\" and\n  td_fafu_idem_struct :: \"'a field_desc typ_struct \\<Rightarrow> bool\" and\n  td_fafu_idem_list :: \" ('a field_desc typ_desc, char list) dt_pair list \\<Rightarrow> bool\" and\n  td_fafu_idem_pair :: \"('a field_desc typ_desc, char list) dt_pair \\<Rightarrow> bool\"\nwhere\n  fai0: \"td_fafu_idem (TypDesc ts n) = td_fafu_idem_struct ts\"\n\n| fai1: \"td_fafu_idem_struct (TypScalar n algn d) = fa_fu_idem d n\"\n| fai2: \"td_fafu_idem_struct (TypAggregate ts) = td_fafu_idem_list ts\"\n\n| fai3: \"td_fafu_idem_list [] = True\"\n| fai4: \"td_fafu_idem_list (x#xs) = (td_fafu_idem_pair x \\<and> td_fafu_idem_list xs)\"\n\n| fai5: \"td_fafu_idem_pair (DTPair x n) = td_fafu_idem x\"\n\nlemmas td_fafu_idem_simps = fai0 fai1 fai2 fai3 fai4 fai5\n\ntext \\<open>field_access is independent of the underlying bytes\\<close>\n\ndefinition  fa_heap_indep :: \"'a field_desc \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"fa_heap_indep fd n \\<equiv>\n     \\<forall>bs bs' v. length bs = n \\<longrightarrow> length bs' = n \\<longrightarrow> field_access fd v bs = field_access fd v bs'\"\n\n\nprimrec\n  td_fa_hi :: \"'a field_desc typ_desc \\<Rightarrow> bool\" and\n  td_fa_hi_struct :: \"'a field_desc typ_struct \\<Rightarrow> bool\" and\n  td_fa_hi_list :: \"('a field_desc typ_desc, char list) dt_pair list \\<Rightarrow> bool\" and\n  td_fa_hi_pair :: \"('a field_desc typ_desc, char list) dt_pair \\<Rightarrow> bool\"\nwhere\n  fahi0: \"td_fa_hi (TypDesc ts n) = td_fa_hi_struct ts\"\n\n| fahi1: \"td_fa_hi_struct (TypScalar n algn d) = fa_heap_indep d n\"\n| fahi2: \"td_fa_hi_struct (TypAggregate ts) = td_fa_hi_list ts\"\n\n| fahi3: \"td_fa_hi_list [] = True\"\n| fahi4: \"td_fa_hi_list (x#xs) = (td_fa_hi_pair x \\<and> td_fa_hi_list xs)\"\n\n| fahi5: \"td_fa_hi_pair (DTPair x n) = td_fa_hi x\"\n\nlemmas td_fa_hi_simps = fahi0 fahi1 fahi2 fahi3 fahi4 fahi5\n\nsection \\<open>Lemmas about td_fafu_idem\\<close>\n\nlemma field_lookup_td_fafu_idem:\n  shows \"\\<And>(s :: 'a field_desc typ_desc) f m n.\n           \\<lbrakk> field_lookup t f m = Some (s, n); td_fafu_idem t \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  and   \"\\<And>(s :: 'a field_desc typ_desc) f m n.\n           \\<lbrakk> field_lookup_struct st f m = Some (s, n); td_fafu_idem_struct st \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  and   \"\\<And>(s :: 'a field_desc typ_desc) f m n.\n           \\<lbrakk> field_lookup_list ts f m = Some (s, n); td_fafu_idem_list ts \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  and   \"\\<And>(s :: 'a field_desc typ_desc) f m n.\n           \\<lbrakk> field_lookup_pair p f m = Some (s, n); td_fafu_idem_pair p \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  by (induct t and st and ts and p) (auto split: if_split_asm option.splits)\n\nlemma field_access_update_same:\n  fixes t :: \"'a :: mem_type field_desc typ_desc\" and st :: \"'a field_desc typ_struct\"\n  shows \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem t; wf_fd t; length bs = size_td t; length bs' = size_td t\\<rbrakk>\n  \\<Longrightarrow> access_ti t (update_ti t bs v) bs' = bs\"\n  and \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem_struct st; wf_fd_struct st; length bs = size_td_struct st; length bs' = size_td_struct st \\<rbrakk>\n  \\<Longrightarrow> access_ti_struct st (update_ti_struct st bs v) bs' = bs\"\n  and \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem_list ts; wf_fd_list ts; length bs = size_td_list ts; length bs' = size_td_list ts\\<rbrakk>\n  \\<Longrightarrow> access_ti_list ts (update_ti_list ts bs v) bs' = bs\"\n  and \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem_pair p; wf_fd_pair p; length bs = size_td_pair p; length bs' = size_td_pair p\\<rbrakk>\n  \\<Longrightarrow> access_ti_pair p (update_ti_pair p bs v) bs' = bs\"\nproof (induct t and st and ts and p)\n  case TypScalar thus ?case by (clarsimp simp: fa_fu_idem_def)\nnext\n  case (Cons_typ_desc p' ts' v bs bs')\n  hence \"fu_commutes (update_ti_pair_t p') (update_ti_list_t ts')\" by clarsimp\n  moreover\n  have \"update_ti_pair p' (take (size_td_pair p') bs) = update_ti_pair_t p' (take (size_td_pair p') bs)\"\n    using Cons_typ_desc.prems by (simp add: update_ti_pair_t_def min_ll)\n  moreover\n  have \"update_ti_list ts' (drop (size_td_pair p') bs) = update_ti_list_t ts' (drop (size_td_pair p') bs)\"\n    using Cons_typ_desc.prems by (simp add: update_ti_list_t_def)\n  ultimately have updeq:\n    \"(update_ti_pair p' (take (size_td_pair p') bs) (update_ti_list ts' (drop (size_td_pair p') bs) v))\n    = (update_ti_list ts' (drop (size_td_pair p') bs) (update_ti_pair p' (take (size_td_pair p') bs) v))\"\n    unfolding fu_commutes_def by simp\n\n  show ?case using Cons_typ_desc.prems\n    by (clarsimp simp add: Cons_typ_desc.hyps) (simp add: updeq  Cons_typ_desc.hyps)\nqed simp+\n\nlemma access_ti_pair_dt_fst:\n  \"access_ti_pair p v bs = access_ti (dt_fst p) v bs\"\n  by (cases p, simp)\n\nlemma size_td_pair_dt_fst:\n  \"size_td_pair p = size_td (dt_fst p)\"\n  by (cases p, simp)\n\nlemma wf_fd_pair_dt_fst:\n  \"wf_fd_pair p = wf_fd (dt_fst p)\"\n  by (cases p, simp)\n\nlemma field_lookup_offset2:\n  assumes fl: \"(field_lookup t f (m + n) = Some (s, q))\"\n  shows   \"field_lookup t f m = Some (s, q - n)\"\nproof -\n  from fl have le: \"m + n \\<le> q\"\n    by (rule field_lookup_offset_le)\n\n  hence \"q = (m + n) + (q - (m + n))\"\n    by simp\n\n  hence \"field_lookup t f (m + n) = Some (s, (m + n) + (q - (m + n)))\" using fl by simp\n\n  hence \"field_lookup t f m = Some (s, m + (q - (m + n)))\"\n    by (rule iffD1 [OF field_lookup_offset'(1)])\n\n  thus ?thesis using le by simp\nqed\n\nlemma field_lookup_offset2_list:\n  assumes fl: \"(field_lookup_list ts f (m + n) = Some (s, q))\"\n  shows   \"field_lookup_list ts f m = Some (s, q - n)\"\nproof -\n  from fl have le: \"m + n \\<le> q\"\n    by (rule field_lookup_offset_le)\n\n  hence \"q = (m + n) + (q - (m + n))\"\n    by simp\n\n  hence \"field_lookup_list ts f (m + n) = Some (s, (m + n) + (q - (m + n)))\" using fl by simp\n\n  hence \"field_lookup_list ts f m = Some (s, m + (q - (m + n)))\"\n    by (rule iffD1 [OF field_lookup_offset'(3)])\n\n  thus ?thesis using le by simp\nqed\n\nlemma field_lookup_offset2_pair:\n  assumes fl: \"(field_lookup_pair p f (m + n) = Some (s, q))\"\n  shows   \"field_lookup_pair p f m = Some (s, q - n)\"\nproof -\n  from fl have le: \"m + n \\<le> q\"\n    by (rule field_lookup_offset_le)\n\n  hence \"q = (m + n) + (q - (m + n))\"\n    by simp\n\n  hence \"field_lookup_pair p f (m + n) = Some (s, (m + n) + (q - (m + n)))\" using fl by simp\n\n  hence \"field_lookup_pair p f m = Some (s, m + (q - (m + n)))\"\n    by (rule iffD1 [OF field_lookup_offset'(4)])\n\n  thus ?thesis using le by simp\nqed\n\nlemma field_lookup_offset_size':\n  shows \"field_lookup t f 0 = Some (t',n) \\<Longrightarrow> size_td t' + n \\<le> size_td t\"\n  apply(drule td_set_field_lookupD)\n  apply(erule td_set_offset_size)\ndone\n\nlemma field_access_update_nth_inner:\n  shows \"\\<And>f (s :: 'a :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk> field_lookup t f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd t;\n  length bs = size_td s; length bs' = size_td t \\<rbrakk>\n  \\<Longrightarrow> access_ti t (update_ti s bs v) bs' ! x = bs ! (x - n)\"\n\n  and \"\\<And>f (s :: 'a  :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk>field_lookup_struct st f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd_struct st;\n  length bs = size_td s; length bs' = size_td_struct st \\<rbrakk>\n  \\<Longrightarrow> access_ti_struct st (update_ti s bs v) bs' ! x = bs ! (x - n)\"\n\n  and \"\\<And>f (s :: 'a  :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk>field_lookup_list ts f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd_list ts;\n  length bs = size_td s; length bs' = size_td_list ts\\<rbrakk>\n  \\<Longrightarrow> access_ti_list ts (update_ti s bs v) bs' ! x = bs ! (x - n)\"\n\n  and \"\\<And>f (s :: 'a  :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk>field_lookup_pair p f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd_pair p;\n  length bs = size_td s; length bs' = size_td_pair p\\<rbrakk>\n  \\<Longrightarrow> access_ti_pair p (update_ti s bs v) bs' ! x = bs ! (x - n)\"\nproof (induct t and st and ts and p)\n  case (TypDesc typ_struct ls f s n x v bs bs')\n\n  show ?case\n  proof (cases \"f = []\")\n    case False thus ?thesis using TypDesc by clarsimp\n  next\n    case True\n    thus ?thesis using TypDesc.prems\n      by (simp add: field_access_update_same)\n  qed\nnext\n  case (Cons_typ_desc p' ts' f s n x v bs bs')\n  have nlex: \"n \\<le> x\" and xln: \"x < n + size_td s\"\n    and lbs: \"length bs = size_td s\" and lbs': \"length bs' = size_td_list (p' # ts')\" by fact+\n  from Cons_typ_desc have wf: \"wf_fd (dt_fst p')\" and wfts: \"wf_fd_list ts'\" by (cases p', auto)\n\n  {\n    assume fl: \"field_lookup_list ts' f (size_td (dt_fst p')) = Some (s, n)\"\n\n    hence mlt: \"size_td (dt_fst p') \\<le> n\"\n      by (rule field_lookup_offset_le)\n\n    hence \"size_td (dt_fst p') \\<le> x\"\n      by (rule order_trans) fact\n\n    hence ?case using wf lbs lbs'\n    proof (simp add: nth_append length_fa_ti access_ti_pair_dt_fst size_td_pair_dt_fst)\n      from fl have fl': \"field_lookup_list ts' f 0 = Some (s, n - size_td (dt_fst p'))\"\n        by (rule field_lookup_offset2_list [where m = 0, simplified])\n\n      show \"access_ti_list ts' (update_ti s bs v) (drop (size_td (dt_fst p')) bs') ! (x - size_td (dt_fst p')) = bs ! (x - n)\"\n        using mlt nlex xln lbs lbs' wf wfts \\<open>td_fafu_idem s\\<close> \\<open>wf_fd s\\<close>\n        by (simp add: Cons_typ_desc.hyps(2) [OF fl'] size_td_pair_dt_fst)\n    qed\n  }\n  moreover\n  {\n    note ih = Cons_typ_desc.hyps(1)[simplified access_ti_pair_dt_fst wf_fd_pair_dt_fst]\n\n    assume fl: \"field_lookup_pair p' f 0 = Some (s, n)\"\n\n    hence \"x < size_td (dt_fst p')\"\n      apply (cases p')\n      apply (simp split: if_split_asm)\n      apply (drule field_lookup_offset_size')\n      apply (rule order_less_le_trans [OF xln])\n      apply simp\n      done\n\n    hence ?case using wf lbs lbs' nlex xln wf wfts \\<open>td_fafu_idem s\\<close> \\<open>wf_fd s\\<close>\n      by (simp add: nth_append length_fa_ti access_ti_pair_dt_fst size_td_pair_dt_fst ih[OF fl])\n  }\n  ultimately show ?case using \\<open>field_lookup_list (p' # ts') f 0 = Some (s, n)\\<close> by (simp split: option.splits)\nqed (clarsimp split: if_split_asm)+\n\nsubsection \\<open>td_fa_hi\\<close>\n\n(* \\<lbrakk> size_of TYPE('a::mem_type) \\<le> length h; size_of TYPE('a) \\<le> length h' \\<rbrakk> \\<Longrightarrow> *)\n\nlemma fa_heap_indepD:\n  \"\\<lbrakk> fa_heap_indep fd n; length bs = n; length bs' = n \\<rbrakk> \\<Longrightarrow>\n  field_access fd v bs = field_access fd v bs'\"\n  unfolding fa_heap_indep_def\n  apply (drule spec, drule spec, drule spec)\n  apply (drule (1) mp)\n  apply (erule (1) mp)\n  done\n\n(* The simplifier spins on the IHs here, hence the proofs for each case *)\nlemma td_fa_hi_heap_independence:\n  shows \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi t; length h = size_td t; length h' = size_td t \\<rbrakk>\n  \\<Longrightarrow> access_ti t v h = access_ti t v h'\"\n  and   \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi_struct st; length h = size_td_struct st; length h' = size_td_struct st\\<rbrakk>\n  \\<Longrightarrow> access_ti_struct st v h = access_ti_struct st v h'\"\n  and   \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi_list ts;  length h = size_td_list ts; length h' = size_td_list ts \\<rbrakk>\n  \\<Longrightarrow> access_ti_list ts v h = access_ti_list ts v h'\"\n  and   \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi_pair p;  length h = size_td_pair p; length h' = size_td_pair p \\<rbrakk>\n  \\<Longrightarrow> access_ti_pair p v h = access_ti_pair p v h'\"\nproof (induct t and st and ts and p)\n  case TypDesc\n  from TypDesc.prems show ?case\n    by (simp) (erule (2) TypDesc.hyps)\nnext\n  case TypScalar\n  from TypScalar.prems show ?case\n    by simp (erule (2) fa_heap_indepD)\nnext\n  case TypAggregate\n  from TypAggregate.prems show ?case\n    by (simp) (erule (2) TypAggregate.hyps)\nnext\n  case Nil_typ_desc thus ?case by simp\nnext\n  case Cons_typ_desc\n  from Cons_typ_desc.prems show ?case\n    apply simp\n    apply (erule conjE)\n    apply (rule arg_cong2 [where f = \"(@)\"])\n    apply (erule Cons_typ_desc.hyps; simp)\n    apply (erule Cons_typ_desc.hyps; simp)\n    done\nnext\n  case DTPair_typ_desc\n  from DTPair_typ_desc.prems show ?case\n    by simp (erule (2) DTPair_typ_desc.hyps)\nqed\n\nsection \\<open>Simp rules for deriving packed props from the type combinators\\<close>\n\nsubsection \\<open>td_fafu_idem\\<close>\n\nlemma td_fafu_idem_final_pad:\n  \"padup (2 ^ align_td t) (size_td t) = 0\n  \\<Longrightarrow> td_fafu_idem (final_pad t) = td_fafu_idem t\"\n  unfolding final_pad_def\n  by (clarsimp simp add: padup_def Let_def)\n\nlemma td_fafu_idem_ti_typ_pad_combine:\n  fixes t :: \"'a :: c_type itself\" and s :: \"'b :: c_type field_desc typ_desc\"\n  assumes pad: \"padup (align_of TYPE('a)) (size_td s) = 0\"\n  shows \"td_fafu_idem (ti_typ_pad_combine t xf xfu nm s) = td_fafu_idem (ti_typ_combine t xf xfu nm s)\"\n  unfolding ti_typ_pad_combine_def using pad\n  by (clarsimp simp: Let_def)\n\nlemma td_fafu_idem_list_append:\n  fixes xs :: \"'a :: c_type field_desc typ_pair list\"\n  shows \"td_fafu_idem_list (xs @ ys) = (td_fafu_idem_list xs \\<and> td_fafu_idem_list ys)\"\n  by (induct xs) simp+\n\nlemma td_fafu_idem_extend_ti:\n  fixes t :: \"'a :: c_type field_desc typ_desc\"\n  assumes as: \"td_fafu_idem s\"\n  and     at: \"td_fafu_idem t\"\n  shows \"td_fafu_idem (extend_ti s t nm)\" using as at\n  by (cases s, rename_tac typ_struct xs)\n     (case_tac typ_struct; simp add: td_fafu_idem_list_append)\n\nlemma fd_cons_access_updateD:\n  \"\\<lbrakk> fd_cons_access_update d n; length bs = n; length bs' = n\\<rbrakk> \\<Longrightarrow>\n   field_access d (field_update d bs v) bs' = field_access d (field_update d bs v') bs'\"\n  unfolding fd_cons_access_update_def by clarsimp\n\nlemma fa_fu_idem_update_desc:\n  fixes a :: \"'a field_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and     fd: \"fd_cons_struct (TypScalar n n' a)\"\n  shows   \"fa_fu_idem (update_desc xf xfu a) n = fa_fu_idem a n\"\nproof\n  assume asm: \"fa_fu_idem (update_desc xf xfu a) n\"\n\n  let ?fu = \"\\<lambda>bs. if length bs = n then field_update a bs else id\"\n  let ?a' = \"\\<lparr> field_access = field_access a, field_update = ?fu \\<rparr>\"\n\n  show \"fa_fu_idem a n\"\n    unfolding fa_fu_idem_def\n  proof (intro impI conjI allI)\n    fix bs :: \"byte list\" and bs' :: \"byte list\" and v\n    assume l: \"length bs = n\" and l': \"length bs' = n\"\n\n    hence \"(\\<forall>v. field_access a (field_update a bs (xf v)) bs' = bs)\n           = (\\<forall>v. field_access a (?fu bs (xf v)) bs' = bs)\" by simp\n\n    also have \"\\<dots> = (\\<forall>v. field_access a (field_update a bs v) bs' = bs)\" using fd\n      apply -\n      apply (rule iffI)\n       apply (rule allI)\n       apply (subst (asm) fd_cons_access_updateD [OF _ l l', where d = ?a', simplified])\n        apply (simp add: fd_cons_struct_def fd_cons_desc_def)\n       apply (fastforce simp: l l')\n      apply (fastforce simp: l l')\n      done\n\n    finally show \"field_access a (field_update a bs v) bs' = bs\" using asm fg l l'\n      by (clarsimp simp add: update_desc_def fa_fu_idem_def fg_cons_def)\n  qed\nnext\n  assume \"fa_fu_idem a n\"\n  thus \"fa_fu_idem (update_desc xf xfu a) n\"\n    unfolding fa_fu_idem_def update_desc_def using fg\n    by (clarsimp simp add: update_desc_def fa_fu_idem_def fg_cons_def)\nqed\n\nlemma td_fafu_idem_map_td_update_desc:\n  assumes fg: \"fg_cons xf xfu\"\n  shows  \"wf_fd t \\<Longrightarrow> td_fafu_idem (map_td (\\<lambda>_ _. update_desc xf xfu) t) = td_fafu_idem t\"\n  and    \"wf_fd_struct st \\<Longrightarrow> td_fafu_idem_struct (map_td_struct (\\<lambda>_ _. update_desc xf xfu) st) = td_fafu_idem_struct st\"\n  and    \"wf_fd_list ts \\<Longrightarrow> td_fafu_idem_list (map_td_list (\\<lambda>_ _. update_desc xf xfu) ts) = td_fafu_idem_list ts\"\n  and    \"wf_fd_pair p \\<Longrightarrow> td_fafu_idem_pair (map_td_pair (\\<lambda>_ _. update_desc xf xfu) p) = td_fafu_idem_pair p\"\n  by (induct t and st and ts and p) (auto elim!: fa_fu_idem_update_desc [OF fg])\n\nlemmas td_fafu_idem_adjust_ti = td_fafu_idem_map_td_update_desc(1)[folded adjust_ti_def]\n\nlemma td_fafu_idem_ti_typ_combine:\n  fixes s :: \"'b :: c_type field_desc typ_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and    tda: \"td_fafu_idem (typ_info_t TYPE('a :: mem_type))\"\n  and    tds: \"td_fafu_idem s\"\n  shows \"td_fafu_idem (ti_typ_combine TYPE('a :: mem_type) xf xfu nm s)\"\n  unfolding ti_typ_combine_def using tda tds\n  apply (clarsimp simp: Let_def)\n  apply (cases s)\n  apply (rename_tac typ_struct xs)\n  apply (case_tac typ_struct)\n   apply simp\n   apply (subst td_fafu_idem_adjust_ti [OF fg wf_fd], assumption)\n  apply (simp add: td_fafu_idem_list_append)\n  apply (subst td_fafu_idem_adjust_ti [OF fg wf_fd], assumption)\n  done\n\nlemma td_fafu_idem_ptr:\n   \"td_fafu_idem (typ_info_t TYPE('a :: c_type ptr))\"\n  apply (clarsimp simp add: fa_fu_idem_def)\n  apply (subst word_rsplit_rcat_size)\n   apply (clarsimp simp add: size_of_def word_size)\n  apply simp\n  done\n\nlemma td_fafu_idem_word:\n   \"td_fafu_idem (typ_info_t TYPE('a :: len8 word))\"\n  apply(clarsimp simp: fa_fu_idem_def)\n  apply (subst word_rsplit_rcat_size)\n   apply (insert len8_dv8)\n   apply (clarsimp simp add: size_of_def word_size)\n   apply (subst dvd_div_mult_self; simp)\n  apply simp\n  done\n\nlemma fg_cons_array [simp]:\n  \"n < card (UNIV :: 'b :: finite set) \\<Longrightarrow>\n   fg_cons (\\<lambda>x. index x n) (\\<lambda>x f. Arrays.update (f :: 'a['b]) n x)\"\n  unfolding fg_cons_def by simp\n\nlemma td_fafu_idem_array_n:\n  \"\\<lbrakk> td_fafu_idem (typ_info_t TYPE('a)); n \\<le> card (UNIV :: 'b set) \\<rbrakk> \\<Longrightarrow>\n   td_fafu_idem (array_tag_n n :: ('a :: mem_type ['b :: finite]) field_desc typ_desc)\"\n  by (induct n; simp add: array_tag_n.simps empty_typ_info_def)\n     (simp add: td_fafu_idem_ti_typ_combine)\n\nlemma td_fafu_idem_array:\n  \"td_fafu_idem (typ_info_t TYPE('a)) \\<Longrightarrow> td_fafu_idem (typ_info_t TYPE('a :: mem_type ['b :: finite]))\"\n  by (clarsimp simp: typ_info_array array_tag_def fa_fu_idem_def td_fafu_idem_array_n)\n\nlemma td_fafu_idem_empty_typ_info:\n  \"td_fafu_idem (empty_typ_info t)\"\n  unfolding empty_typ_info_def\n  by simp\n\nsubsection \\<open>td_fa_hi\\<close>\n\n(* These are mostly identical to the above --- surely there is something which implies both? *)\n\nlemma td_fa_hi_final_pad:\n  \"padup (2 ^ align_td t) (size_td t) = 0\n  \\<Longrightarrow> td_fa_hi (final_pad t) = td_fa_hi t\"\n  unfolding final_pad_def\n  by (clarsimp simp add: padup_def Let_def)\n\nlemma td_fa_hi_ti_typ_pad_combine:\n  fixes t :: \"'a :: c_type itself\" and s :: \"'b :: c_type field_desc typ_desc\"\n  assumes pad: \"padup (align_of TYPE('a)) (size_td s) = 0\"\n  shows \"td_fa_hi (ti_typ_pad_combine t xf xfu nm s) = td_fa_hi (ti_typ_combine t xf xfu nm s)\"\n  unfolding ti_typ_pad_combine_def using pad\n  by (clarsimp simp: Let_def)\n\nlemma td_fa_hi_list_append:\n  fixes xs :: \"'a :: c_type field_desc typ_pair list\"\n  shows \"td_fa_hi_list (xs @ ys) = (td_fa_hi_list xs \\<and> td_fa_hi_list ys)\"\n  by (induct xs) simp+\n\nlemma td_fa_hi_extend_ti:\n  fixes t :: \"'a :: c_type field_desc typ_desc\"\n  assumes as: \"td_fa_hi s\"\n  and     at: \"td_fa_hi t\"\n  shows \"td_fa_hi (extend_ti s t nm)\" using as at\n  by (cases s, rename_tac typ_struct xs)\n     (case_tac typ_struct; simp add: td_fa_hi_list_append)\n\nlemma fa_heap_indep_update_desc:\n  fixes a :: \"'a field_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and     fd: \"fd_cons_struct (TypScalar n n' a)\"\n  shows   \"fa_heap_indep (update_desc xf xfu a) n = fa_heap_indep a n\"\nproof\n  assume asm: \"fa_heap_indep (update_desc xf xfu a) n\"\n\n  have xf_xfu: \"\\<And>v v'. xf (xfu v v') = v\" using fg\n    unfolding fg_cons_def\n    by simp\n\n  show \"fa_heap_indep a n\"\n    unfolding fa_heap_indep_def\n  proof (intro impI conjI allI)\n    fix bs :: \"byte list\" and bs' :: \"byte list\" and v\n    assume l: \"length bs = n\" and l': \"length bs' = n\"\n    with asm\n    have \"field_access (update_desc xf xfu a) (xfu v undefined) bs =\n          field_access (update_desc xf xfu a) (xfu v undefined) bs'\"\n      by (rule fa_heap_indepD)\n\n    thus \"field_access a v bs = field_access a v bs'\"\n      unfolding update_desc_def\n      by (simp add: xf_xfu)\n  qed\nnext\n  assume asm: \"fa_heap_indep a n\"\n  show \"fa_heap_indep (update_desc xf xfu a) n\"\n    unfolding fa_heap_indep_def update_desc_def\n  proof (simp, intro impI conjI allI)\n    fix bs :: \"byte list\" and bs' :: \"byte list\" and v\n    assume l: \"length bs = n\" and l': \"length bs' = n\"\n\n    with asm show \"field_access a (xf v) bs = field_access a (xf v) bs'\"\n      by (rule fa_heap_indepD)\n  qed\nqed\n\nlemma td_fa_hi_map_td_update_desc:\n  assumes fg: \"fg_cons xf xfu\"\n  shows  \"wf_fd t \\<Longrightarrow> td_fa_hi (map_td (\\<lambda>_ _. update_desc xf xfu) t) = td_fa_hi t\"\n  and    \"wf_fd_struct st \\<Longrightarrow> td_fa_hi_struct (map_td_struct (\\<lambda>_ _. update_desc xf xfu) st) = td_fa_hi_struct st\"\n  and    \"wf_fd_list ts \\<Longrightarrow> td_fa_hi_list (map_td_list (\\<lambda>_ _. update_desc xf xfu) ts) = td_fa_hi_list ts\"\n  and    \"wf_fd_pair p \\<Longrightarrow> td_fa_hi_pair (map_td_pair (\\<lambda>_ _. update_desc xf xfu) p) = td_fa_hi_pair p\"\n  by (induct t and st and ts and p) (auto elim!: fa_heap_indep_update_desc [OF fg])\n\nlemmas td_fa_hi_adjust_ti = td_fa_hi_map_td_update_desc(1)[folded adjust_ti_def]\n\nlemma td_fa_hi_ti_typ_combine:\n  fixes s :: \"'b :: c_type field_desc typ_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and    tda: \"td_fa_hi (typ_info_t TYPE('a :: mem_type))\"\n  and    tds: \"td_fa_hi s\"\n  shows \"td_fa_hi (ti_typ_combine TYPE('a :: mem_type) xf xfu nm s)\"\n  unfolding ti_typ_combine_def Let_def using tda tds\n  by (cases s, rename_tac typ_struct xs)\n     (case_tac typ_struct; simp add: td_fa_hi_list_append td_fa_hi_adjust_ti[OF fg wf_fd])\n\nlemma td_fa_hi_ptr:\n   \"td_fa_hi (typ_info_t TYPE('a :: c_type ptr))\"\n  by (clarsimp simp add: fa_heap_indep_def)\n\nlemma td_fa_hi_word:\n   \"td_fa_hi (typ_info_t TYPE('a :: len8 word))\"\n  by (clarsimp simp add: fa_heap_indep_def)\n\nlemma td_fa_hi_array_n:\n  \"\\<lbrakk>td_fa_hi (typ_info_t TYPE('a)); n \\<le> card (UNIV :: 'b set) \\<rbrakk> \\<Longrightarrow> td_fa_hi (array_tag_n n :: ('a :: mem_type ['b :: finite]) field_desc typ_desc)\"\n  by (induct n; simp add: array_tag_n.simps empty_typ_info_def td_fa_hi_ti_typ_combine)\n\nlemma td_fa_hi_array:\n  \"td_fa_hi (typ_info_t TYPE('a)) \\<Longrightarrow> td_fa_hi (typ_info_t TYPE('a :: mem_type ['b :: finite]))\"\n  by (clarsimp simp add: typ_info_array array_tag_def fa_fu_idem_def td_fa_hi_array_n)\n\nlemma td_fa_hi_empty_typ_info:\n  \"td_fa_hi (empty_typ_info t)\"\n  unfolding empty_typ_info_def\n  by simp\n\nsection \\<open>The type class and simp sets\\<close>\n\ntext \\<open>Packed types, with no padding, have the defining property that\n        access is invariant under substitution of the underlying heap and\n        access/update is the identity\\<close>\n\nclass packed_type = mem_type +\n  assumes td_fafu_idem: \"td_fafu_idem (typ_info_t TYPE('a::c_type))\"\n  assumes td_fa_hi:     \"td_fa_hi (typ_info_t TYPE('a::c_type))\"\n\nlemmas td_fafu_idem_intro_simps =\n  \\<comment> \\<open>Axioms\\<close>\n  td_fafu_idem\n  \\<comment> \\<open>Combinators\\<close>\n  td_fafu_idem_final_pad td_fafu_idem_ti_typ_pad_combine td_fafu_idem_ti_typ_combine td_fafu_idem_empty_typ_info\n  \\<comment> \\<open>Constructors\\<close>\n  td_fafu_idem_ptr td_fafu_idem_word td_fafu_idem_array\n\nlemmas td_fa_hi_intro_simps =\n  \\<comment> \\<open>Axioms\\<close>\n  td_fa_hi\n  \\<comment> \\<open>Combinators\\<close>\n  td_fa_hi_final_pad td_fa_hi_ti_typ_pad_combine td_fa_hi_ti_typ_combine td_fa_hi_empty_typ_info\n  \\<comment> \\<open>Constructors\\<close>\n  td_fa_hi_ptr td_fa_hi_word td_fa_hi_array\n\nlemma align_td_array':\n  \"align_td (typ_info_t TYPE('a :: c_type['b :: finite])) = align_td (typ_info_t TYPE('a))\"\n  by (simp add: typ_info_array array_tag_def align_td_array_tag)\n\nlemmas packed_type_intro_simps =\n  td_fafu_idem_intro_simps td_fa_hi_intro_simps align_td_array' size_td_simps size_td_array\n\nlemma access_ti_append':\n  \"\\<And>list.\n   access_ti_list (xs @ ys) t list =\n     access_ti_list xs t (take (size_td_list xs) list) @\n     access_ti_list ys t (drop (size_td_list xs) list)\"\nproof(induct xs)\n  case Nil show ?case by simp\nnext\n  case (Cons x xs) thus ?case by (simp add: min_def ac_simps drop_take)\nqed\n\nsection \\<open>Instances\\<close>\n\ntext \\<open>Words (of multiple of 8 size) are packed\\<close>\n\ninstantiation word :: (len8) packed_type\nbegin\ninstance\n  by (intro_classes; rule td_fafu_idem_word td_fa_hi_word)\nend\n\ntext \\<open>Pointers are always packed\\<close>\n\ninstantiation ptr :: (c_type)packed_type\nbegin\ninstance\n  by (intro_classes; simp add: fa_fu_idem_def word_rsplit_rcat_size word_size fa_heap_indep_def)\nend\n\ntext \\<open>Arrays of packed types are in turn packed\\<close>\n\nclass array_outer_packed = packed_type + array_outer_max_size\nclass array_inner_packed = array_outer_packed + array_inner_max_size\n\ninstance word :: (len8)array_outer_packed ..\ninstance word :: (len8)array_inner_packed ..\n\ninstance array :: (array_outer_packed, array_max_count) packed_type\n  by (intro_classes; simp add: td_fafu_idem_intro_simps td_fa_hi_intro_simps)\n\ninstance array :: (array_inner_packed, array_max_count) array_outer_packed ..\n\nsection \\<open>Theorems about packed types\\<close>\n\nsubsection \\<open>td_fa_hi\\<close>\n\nlemma heap_independence:\n  \"\\<lbrakk>length h = size_of TYPE('a :: packed_type); length h' = size_of TYPE('a) \\<rbrakk>\n  \\<Longrightarrow> access_ti (typ_info_t TYPE('a)) v h = access_ti (typ_info_t TYPE('a)) v h'\"\n  by (rule td_fa_hi_heap_independence(1)[OF td_fa_hi], simp_all add: size_of_def)\n\ntheorem packed_heap_update_collapse:\n fixes u::\"'a::packed_type\"\n fixes v::\"'a\"\n shows \"heap_update p v (heap_update p u h) = heap_update p v h\"\n  unfolding heap_update_def\n  apply(rule ext)\n  apply(case_tac \"x \\<in> {ptr_val p..+size_of TYPE('a)}\")\n   apply(simp add: heap_update_mem_same_point)\n   apply(simp add:to_bytes_def)\n   apply(subst heap_independence, simp)\n    prefer 2\n    apply(rule refl)\n   apply(simp)\n  apply(simp add: heap_update_nmem_same)\n  done\n\nlemma packed_heap_update_collapse_hrs:\n  fixes p :: \"'a :: packed_type ptr\"\n  shows \"hrs_mem_update (heap_update p v) (hrs_mem_update (heap_update p v') hp) =\n         hrs_mem_update (heap_update p v) hp\"\n  unfolding hrs_mem_update_def\n  by (simp add: split_def packed_heap_update_collapse)\n\nsubsection \\<open>td_fafu_idem\\<close>\n\nlemma order_leE:\n  fixes x :: \"'a :: order\"\n  shows \"\\<lbrakk> x \\<le> y; x = y \\<Longrightarrow> P; x < y \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P\"\n  by (auto simp: order_le_less)\n\nlemma of_nat_mono_maybe_le:\n  shows \"\\<lbrakk>X < 2 ^ len_of TYPE('a); Y \\<le> X\\<rbrakk> \\<Longrightarrow> (of_nat Y :: 'a :: len word) \\<le> of_nat X\"\n  apply (erule order_leE)\n   apply simp\n  apply (rule order_less_imp_le)\n  apply (erule (1) of_nat_mono_maybe)\n  done\n\nlemma intvl_le_lower:\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk> x \\<in> {y..+n}; y \\<le> y + of_nat (n - 1); n < 2 ^ len_of TYPE('a) \\<rbrakk> \\<Longrightarrow> y \\<le> x\"\n  apply (drule intvlD)\n  apply (elim conjE exE)\n  apply (erule ssubst)\n  apply (erule word_plus_mono_right2)\n  apply (rule of_nat_mono_maybe_le)\n   apply simp\n  apply simp\n  done\n\nlemma intvl_less_upper:\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk> x \\<in> {y..+n}; y \\<le> y + of_nat (n - 1); n < 2 ^ len_of TYPE('a) \\<rbrakk> \\<Longrightarrow> x \\<le> y + of_nat (n - 1)\"\n  apply (drule intvlD)\n  apply (elim conjE exE)\n  apply (erule ssubst)\n  apply (rule word_plus_mono_right; assumption?)\n  apply (rule of_nat_mono_maybe_le; simp)\n  done\n\nlemma packed_type_access_ti:\n  fixes v :: \"'a :: packed_type\"\n  assumes lbs: \"length bs = size_of TYPE('a)\"\n  shows \"access_ti (typ_info_t TYPE('a)) v bs = access_ti\\<^sub>0 (typ_info_t TYPE('a)) v\"\n  unfolding access_ti\\<^sub>0_def\n  by (rule heap_independence; simp add: lbs size_of_def)\n\nlemma update_ti_update_ti_t:\n  \"length bs = size_td s \\<Longrightarrow> update_ti s bs v = update_ti_t s bs v\"\n  unfolding update_ti_t_def by simp\n\nlemma heap_list_nth:\n  \"m < n \\<Longrightarrow> heap_list hp n p ! m = hp (p + of_nat m)\"\nproof (induct m arbitrary: n p)\n  case (0 n' p')\n  thus ?case by (cases n', simp_all)\nnext\n  case (Suc m' n' p')\n  show ?case\n  proof (cases n')\n    case 0 thus ?thesis using \\<open>Suc m' < n'\\<close> by simp\n  next\n    case (Suc n'')\n    hence \"m' < n''\" using \\<open>Suc m' < n'\\<close> by simp\n    thus ?thesis using Suc\n      by (simp add: Suc.hyps ac_simps)\n  qed\nqed\n\nlemma c_guard_field_lvalue:\n  fixes p :: \"'a :: mem_type ptr\"\n  assumes cg: \"c_guard p\"\n  and     fl: \"field_lookup (typ_info_t TYPE('a)) f 0 = Some (t, n)\"\n  and     eu: \"export_uinfo t = typ_uinfo_t TYPE('b :: mem_type)\"\n  shows   \"c_guard (Ptr &(p\\<rightarrow>f) :: 'b :: mem_type ptr)\"\n  unfolding c_guard_def\nproof (rule conjI)\n  from cg fl eu show \"ptr_aligned (Ptr &(p\\<rightarrow>f) :: 'b ptr)\"\n    by (rule c_guard_ptr_aligned_fl)\nnext\n  from eu have std: \"size_td t = size_of TYPE('b)\" using fl\n    by (simp add: export_size_of)\n\n  from cg have \"c_null_guard p\" unfolding c_guard_def ..\n  thus \"c_null_guard (Ptr &(p\\<rightarrow>f)  :: 'b ptr)\" unfolding c_null_guard_def\n    apply (rule contrapos_nn)\n    apply (rule subsetD [OF field_tag_sub, OF fl])\n    apply (simp add: std)\n    done\nqed\n\n\nlemma c_guard_no_wrap:\n  fixes p :: \"'a :: mem_type ptr\"\n  assumes cgrd: \"c_guard p\"\n  shows   \"ptr_val p \\<le> ptr_val p + of_nat (size_of TYPE('a) - 1)\"\n  using cgrd unfolding c_guard_def c_null_guard_def\n  apply -\n  apply (erule conjE)\n  apply (erule contrapos_np)\n  apply (simp add: intvl_def)\n  apply (drule word_wrap_of_natD)\n  apply (erule exE)\n  apply (rule exI)\n  apply (simp add: nat_le_Suc_less)\n  done\n\ntheorem packed_heap_super_field_update:\n  fixes v :: \"'a :: packed_type\" and p :: \"'b :: packed_type ptr\"\n  assumes fl: \"field_lookup (typ_info_t TYPE('b)) f 0 = Some (t, n)\"\n  and   cgrd: \"c_guard p\"\n  and     eu: \"export_uinfo t = typ_uinfo_t TYPE('a)\"\n  shows   \"heap_update (Ptr &(p\\<rightarrow>f)) v hp = heap_update p (update_ti t (to_bytes_p v) (h_val hp p)) hp\"\n  unfolding heap_update_def to_bytes_def\nproof (simp add: packed_type_access_ti, rule ext)\n  fix x\n  let ?LHS = \"heap_update_list &(p\\<rightarrow>f) (to_bytes_p v) hp x\"\n  let ?RHS = \"heap_update_list (ptr_val p) (to_bytes_p (update_ti t (to_bytes_p v) (h_val hp p))) hp x\"\n\n  from cgrd have al: \"ptr_val p \\<le> ptr_val p + of_nat (size_of TYPE('b) - 1)\" by (rule c_guard_no_wrap)\n\n  have szb: \"size_of TYPE('b) < 2 ^ len_of TYPE(addr_bitsize)\"\n    by (metis len_of_addr_card max_size)\n\n  have szt: \"n + size_td t \\<le> size_of TYPE('b)\"\n    unfolding size_of_def\n    by (subst add.commute, rule field_lookup_offset_size [OF fl])\n  moreover have t0: \"0 < size_td t\" using fl wf_size_desc\n    by (rule field_lookup_wf_size_desc_gt)\n  ultimately have szn: \"n < size_of TYPE('b)\" by simp\n  from szt have szt1: \"n + (size_td t - 1) \\<le> size_of TYPE('b)\"\n    by simp\n\n  have b0: \"0 < size_of (TYPE ('b))\" using wf_size_desc\n    unfolding size_of_def\n    by (rule wf_size_desc_gt)\n\n  have uofn: \"unat (of_nat n :: addr_bitsize word) = n\" using szn szb\n    by (metis le_unat_uoi nat_less_le unat_of_nat_len)\n\n  from eu have std: \"size_td t = size_of TYPE('a)\" using fl\n    by (simp add: export_size_of)\n\n  hence \"?LHS = (if x \\<in> {&(p\\<rightarrow>f)..+size_td t} then (to_bytes_p v) ! unat (x - &(p\\<rightarrow>f)) else hp x)\"\n    by (simp add: heap_update_mem_same_point heap_update_nmem_same)\n  also have \"... = ?RHS\"\n  proof (simp, intro impI conjI)\n    assume xin: \"x \\<in> {&(p\\<rightarrow>f)..+size_td t}\"\n    have \"to_bytes_p v ! unat (x - &(p\\<rightarrow>f)) = to_bytes_p (update_ti t (to_bytes_p v) (h_val hp p)) ! unat (x - ptr_val p)\"\n    proof (simp add: to_bytes_p_def to_bytes_def, subst field_access_update_nth_inner(1)[OF fl, simplified])\n\n      have \"c_guard (Ptr &(p\\<rightarrow>f) :: 'a ptr)\" using cgrd fl eu\n        by (rule c_guard_field_lvalue)\n      hence pft: \"&(p\\<rightarrow>f) \\<le> &(p\\<rightarrow>f) + of_nat (size_td t - 1)\"\n        by (metis c_guard_no_wrap ptr_val.ptr_val_def std)\n\n      have szt': \"size_td t < 2 ^ len_of TYPE(addr_bitsize)\"\n        by (metis len_of_addr_card max_size std)\n\n      have ofn: \"of_nat n \\<le> x - ptr_val p\"\n      proof (rule le_minus')\n        from xin show \"ptr_val p + of_nat n \\<le> x\" using pft szt'\n          unfolding field_lvalue_def field_lookup_offset_eq [OF fl]\n          by (rule intvl_le_lower)\n      next\n        from szb szn have \"of_nat n \\<le> (of_nat (size_of TYPE('b) - 1) :: addr_bitsize word)\"\n          by (metis One_nat_def of_nat_mono_maybe_le b0 less_imp_diff_less nat_le_Suc_less)\n        with al show \"ptr_val p \\<le> ptr_val p + of_nat n\"\n          by (rule word_plus_mono_right2)\n      qed\n\n      thus nlt: \"n \\<le> unat (x - ptr_val p)\"\n        by (metis uofn word_le_nat_alt)\n      have \"x \\<le> ptr_val p + (of_nat n + of_nat (size_td t - 1))\" using xin pft szt' t0\n        unfolding field_lvalue_def field_lookup_offset_eq [OF fl]\n        by (metis (no_types) add.assoc intvl_less_upper)\n      moreover have \"x \\<in> {ptr_val p..+size_of TYPE('b)}\" using fl xin\n        by (rule subsetD [OF field_tag_sub])\n      ultimately have \"x - ptr_val p \\<le> (of_nat n + of_nat (size_td t - 1))\" using al szb\n        by (metis add_diff_cancel_left' intvl_le_lower word_diff_ls(4))\n      moreover have \"unat (of_nat n + of_nat (size_td t - 1) :: addr_bitsize word) = n + size_td t - 1\"\n        using t0 order_le_less_trans [OF szt1 szb]\n        by (metis Nat.add_diff_assoc One_nat_def Suc_leI of_nat_add unat_of_nat_len)\n      ultimately have \"unat (x - ptr_val p) \\<le> n + size_td t - 1\"\n        by (simp add: word_le_nat_alt)\n      thus \"unat (x - ptr_val p) < n + size_td t\" using t0\n        by simp\n\n      show \"td_fafu_idem t\"\n        by (rule field_lookup_td_fafu_idem(1)[OF fl td_fafu_idem])\n\n      show \"wf_fd t\"\n        by (rule wf_fd_field_lookupD [OF fl wf_fd])\n\n      show \"length (access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0)) = size_td t\"\n        using wf_fd [where 'a = 'a]\n        by (simp add: length_fa_ti size_of_def std)\n\n      show \"length (replicate (size_of TYPE('b)) 0) = size_td (typ_info_t TYPE('b))\"\n        by (simp add: size_of_def)\n\n      have \"unat (x - &(p\\<rightarrow>f)) = unat ((x - ptr_val p) - of_nat n)\"\n        by (simp add: field_lvalue_def field_lookup_offset_eq [OF fl])\n      also have \"\\<dots> = unat (x - ptr_val p) - n\"\n        by (metis ofn unat_sub uofn)\n      finally have \"unat (x - &(p\\<rightarrow>f)) = unat (x - ptr_val p) - n\" .\n\n      thus \"access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0) ! unat (x - &(p\\<rightarrow>f)) =\n        access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0) ! (unat (x - ptr_val p) - n)\"\n        by simp\n    qed\n\n    thus \"to_bytes_p v ! unat (x - &(p\\<rightarrow>f)) = ?RHS\"\n    proof (subst heap_update_mem_same_point, simp_all)\n      show \"x \\<in> {ptr_val p..+size_of TYPE('b)}\" using fl xin\n        by (rule subsetD [OF field_tag_sub])\n    qed\n  next\n    assume xni: \"x \\<notin> {&(p\\<rightarrow>f)..+size_td t}\"\n    have \"?RHS = (if x \\<in> {ptr_val p..+size_of TYPE('b)}\n          then (to_bytes_p (update_ti t (to_bytes_p v) (h_val hp p))) ! unat (x - ptr_val p) else hp x)\"\n      by (simp add: heap_update_mem_same_point heap_update_nmem_same)\n\n    also\n    {\n      assume xin: \"x \\<in> {ptr_val p..+size_of TYPE('b)}\"\n\n      hence \"access_ti (typ_info_t TYPE('b))\n        (update_ti_t t (access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0)) (h_val hp p))\n        (replicate (size_of TYPE('b)) 0) ! unat (x - ptr_val p) = hp x\"\n      proof (subst field_access_update_nth_disjD [OF fl])\n        have \"x - ptr_val p \\<le> of_nat (size_of TYPE('b) - 1)\"\n        proof (rule word_diff_ls(4)[where xa=x and x=x for x, simplified])\n          from xin show \"x \\<le> of_nat (size_of TYPE('b) - 1) + ptr_val p\" using al szb\n            by (subst add.commute, rule intvl_less_upper)\n          show \"ptr_val p \\<le> x\" using xin al szb\n            by (rule intvl_le_lower)\n        qed\n        thus unx: \"unat (x - ptr_val p) < size_td (typ_info_t TYPE('b))\" using szb b0\n          by (metis (no_types) One_nat_def Suc_leI le_m1_iff_lt of_nat_1 of_nat_diff of_nat_mono_maybe\n                               semiring_1_class.of_nat_0 size_of_def unat_less_helper)\n\n        show \"unat (x - ptr_val p) < n - 0 \\<or> n - 0 + size_td t \\<le> unat (x - ptr_val p)\" using xin xni\n          unfolding field_lvalue_def field_lookup_offset_eq [OF fl]\n          using intvl_cut by auto\n\n        show \"wf_fd (typ_info_t TYPE('b))\" by (rule wf_fd)\n            (* clag *)\n        show \"length (access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0)) = size_td t\"\n          using wf_fd [where 'a = 'a]\n          by (simp add: length_fa_ti size_of_def std)\n\n        show \"length (replicate (size_of TYPE('b)) 0) = size_td (typ_info_t TYPE('b))\"\n          by (simp add: size_of_def)\n\n        have \"heap_list hp (size_td (typ_info_t TYPE('b))) (ptr_val p) ! unat (x - ptr_val p) = hp x\"\n          by (subst heap_list_nth, rule unx) simp\n\n        thus \"access_ti (typ_info_t TYPE('b)) (h_val hp p) (replicate (size_of TYPE('b)) 0) ! unat (x - ptr_val p) = hp x\"\n          unfolding h_val_def\n          by (simp add: from_bytes_def update_ti_t_def size_of_def field_access_update_same(1)[OF td_fafu_idem wf_fd])\n      qed\n    }\n    hence \"\\<dots> = hp x\"\n      by (simp add: to_bytes_p_def to_bytes_def update_ti_update_ti_t length_fa_ti [OF wf_fd] std size_of_def)\n    finally show \"hp x = ?RHS\" by simp\n  qed\n  finally show \"?LHS = ?RHS\" .\nqed\n\nsubsection \\<open>Proof automation for packed types\\<close>\n\ndefinition td_packed :: \"'a field_desc typ_desc \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> bool\"\n  where \"td_packed t sz al \\<longleftrightarrow>\n    td_fafu_idem t \\<and> td_fa_hi t \\<and> aggregate t \\<and> size_td t = sz \\<and> align_td t = al\"\n\nlemma packed_type_class_intro:\n  \"td_packed (typ_info_t TYPE('a::mem_type)) s a\n    \\<Longrightarrow> OFCLASS('a::mem_type, packed_type_class)\"\n  by standard (simp_all add: td_packed_def)\n\nlemma td_packed_final_pad:\n  \"\\<lbrakk>td_packed t s a; 2 ^ a dvd s\\<rbrakk> \\<Longrightarrow> td_packed (final_pad t) s a\"\n  by (simp add: padup_dvd [symmetric] td_packed_def final_pad_def)\n\nlemma td_packed_ti_typ_combine:\n  \"\\<lbrakk> td_packed (td::'a::c_type field_desc typ_desc) s a;\n     align_of TYPE('b::packed_type) dvd s; fg_cons xf xfu \\<rbrakk>\n    \\<Longrightarrow> td_packed (ti_typ_combine TYPE('b) xf xfu nm td)\n                  (s + size_td (typ_info_t TYPE('b)))\n                  (max a (align_td (typ_info_t TYPE('b))))\"\n  unfolding td_packed_def\n  apply safe\n      apply (rule td_fafu_idem_ti_typ_combine; assumption?)\n      apply (rule td_fafu_idem)\n     apply (rule td_fa_hi_ti_typ_combine; assumption?)\n     apply (rule td_fa_hi)\n    apply simp\n   apply (simp only: size_td_lt_ti_typ_combine)\n  apply (simp only: align_of_ti_typ_combine)\n  done\n\nlemma td_packed_ti_typ_pad_combine:\n  \"\\<lbrakk> td_packed (td::'a::c_type field_desc typ_desc) s a;\n     align_of TYPE('b::packed_type) dvd s; fg_cons xf xfu \\<rbrakk>\n    \\<Longrightarrow> td_packed (ti_typ_pad_combine TYPE('b) xf xfu nm td)\n                  (s + size_td (typ_info_t TYPE('b)))\n                  (max a (align_td (typ_info_t TYPE('b))))\"\n  apply (subgoal_tac \"padup (align_of TYPE('b)) (size_td td) = 0\")\n   apply (simp add: ti_typ_pad_combine_def Let_def td_packed_ti_typ_combine)\n  apply (simp add: align_of_def padup_dvd td_packed_def)\n  done\n\nlemma td_packed_ti_typ_combine_array:\n  \"\\<lbrakk>td_packed (td::'a::c_type field_desc typ_desc) s a;\n    align_of TYPE('b::packed_type) dvd s; fg_cons xf xfu\\<rbrakk>\n    \\<Longrightarrow> td_packed\n      (ti_typ_combine TYPE('b ['n :: finite]) xf xfu nm td)\n      (s + size_td (typ_info_t TYPE('b)) * CARD('n))\n      (max a (align_td (typ_info_t TYPE('b))))\"\n  by (clarsimp simp: ti_typ_combine_def td_packed_def\n                     packed_type_intro_simps td_fafu_idem_extend_ti\n                     td_fa_hi_extend_ti td_fa_hi_adjust_ti\n                     size_td_extend_ti size_of_def\n                     td_fafu_idem_adjust_ti)\n\nlemma td_packed_ti_typ_pad_combine_array:\n  \"\\<lbrakk> td_packed (td::'a::c_type field_desc typ_desc) s a;\n     align_of TYPE('b::packed_type) dvd s; fg_cons xf xfu \\<rbrakk>\n    \\<Longrightarrow> td_packed (ti_typ_pad_combine TYPE('b ['n :: finite]) xf xfu nm td)\n                  (s + size_td (typ_info_t TYPE('b)) * CARD('n))\n                  (max a (align_td (typ_info_t TYPE('b))))\"\n  apply (subgoal_tac \"padup (align_of TYPE('b['n])) (size_td td) = 0\")\n   apply (simp add: ti_typ_pad_combine_def Let_def)\n   apply (simp add: td_packed_ti_typ_combine_array)\n  apply (simp add: align_of_def padup_dvd td_packed_def align_td_array)\n  done\n\nlemma td_packed_empty_typ_info:\n  \"td_packed (empty_typ_info fn) 0 0\"\n  apply (unfold td_packed_def, safe)\n      apply (rule td_fafu_idem_empty_typ_info)\n     apply (rule td_fa_hi_empty_typ_info)\n    apply (rule aggregate_empty_typ_info)\n   apply (rule size_td_empty_typ_info)\n  apply (rule align_of_empty_typ_info)\n  done\n\nlemmas td_packed_intros =\n  td_packed_final_pad\n  td_packed_empty_typ_info\n  td_packed_ti_typ_combine\n  td_packed_ti_typ_pad_combine\n  td_packed_ti_typ_combine_array\n  td_packed_ti_typ_pad_combine_array\n\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/c-parser/PackedTypes.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.640635868562172, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.2978326219727093}}
{"text": "theory WTLemma\n  imports GenSubEnv WellTypedExp PermEnvMisc AltNormEnv \nbegin\n    \n    (* \n      ####################################\n        P2. general well-typed lemmas\n      ####################################\n    *)\n\nlemma well_typed_perm_leq: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx \\<rbrakk> \\<Longrightarrow> leq_use_env r_s2 r_s1\"\n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n        apply (auto)\n      apply (rule_tac r_sb=\"diff_use_env r_s1 (comp_use_env (ereq_use_env (owner_name x) tau_x) r_ex)\" in trans_leq_use_env)\n       apply (rule_tac self_diff_leq_use_env)\n      apply (simp)\n     apply (rule_tac r_sb=\"diff_use_env r_s3 r_ex\" in trans_leq_use_env)\n      apply (rule_tac diff_leq_use_env)\n      apply (rule_tac r_sb=\"r_s2a\" in trans_leq_use_env)\n       apply (auto)\n    apply (rule_tac r_sb=\"r_s2a\" in trans_leq_use_env)\n     apply (auto)\n   apply (rule_tac r_sb=\"diff_use_env r_s1 r_ex\" in trans_leq_use_env)\n    apply (rule_tac self_diff_leq_use_env)\n   apply (simp)\n  apply (rule_tac r_sb=\"r_s2a\" in trans_leq_use_env)\n   apply (auto)\n  apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n   apply (auto)\n  apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n   apply (rule_tac self_diff_leq_use_env)\n  apply (simp)\n  done\n\nlemma well_typed_perm_leqx: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx \\<rbrakk> \\<Longrightarrow> leq_use_env rx r_s2\"    \n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n       apply (auto)\n    (* if case *)\n  apply (rule_tac dist_comp_leq_use_env)\n   apply (auto)\n  done\n\nlemma well_typed_spec_perm_leq: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx \\<rbrakk> \\<Longrightarrow> leq_perm (r_s2 x) (r_s1 x)\"\n  apply (cut_tac ?r_s2.0=\"r_s2\" and ?r_s1.0=\"r_s1\" in well_typed_perm_leq)\n   apply (auto)\n  apply (simp add: leq_use_env_def)\n  done       \n  \n    (* \n      ####################################\n        P3. well-typed free var lemmas\n      ####################################\n    *)\n    \nlemma well_typed_fv_env_use: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; x \\<in> free_vars e \\<rbrakk> \\<Longrightarrow> env (Var x) \\<noteq> None\"\n  (*apply (simp add: env_gen_use_def)*)\n  apply (induction e arbitrary: env tau r_s1 r_s2 rx)\n        apply (auto)\n   apply (case_tac xa)\n    apply (auto)\n  apply (case_tac \"\\<exists> y. add_env env (Var x1a) t1 (Var x) = Some y\")\n   apply (simp add: add_env_def)\n  apply (auto)\n  done\n    \nlemma well_typed_rv_env_use: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; x \\<in> ref_vars e \\<rbrakk> \\<Longrightarrow> env (Loc x) \\<noteq> None\"\n  (*apply (simp add: env_gen_use_def)*)\n  apply (induction e arbitrary: env tau r_s1 r_s2 rx)\n        apply (auto)\n   apply (case_tac xa)\n    apply (auto)\n  apply (case_tac \"\\<exists> y. add_env env (Var x1a) t1 (Loc x) = Some y\")\n   apply (simp add: add_env_def)\n   apply (auto)\n  done    \n\nlemma well_typed_no_npv_use: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; r_s1 x = NoPerm \\<rbrakk> \\<Longrightarrow> x \\<notin> non_prim_vars env e\"\n  apply (induction e arbitrary: env r_s1 tau r_s2 rx)\n       apply (auto)\n    (* const + op case *)\n        apply (simp add: non_prim_vars_def)\n       apply (simp add: non_prim_vars_def)\n    (* var case. *)\n      apply (cut_tac r_x=\"ereq_use_env (owner_name xa) tau_x\" and r_s=\"r_s1\" in leq_use_none)\n        apply (auto)\n      apply (case_tac \"x \\<noteq> owner_name xa\")\n       apply (simp add: non_prim_vars_def)\n       apply (case_tac xa)\n        apply (auto)\n      apply (cut_tac x=\"x\" and tau=\"tau_x\" in ereq_use_none)\n       apply (auto)\n      apply (simp add: non_prim_vars_def)\n      apply (simp add: non_prim_entry_def)\n    (* pair case 1 *)\n     apply (case_tac \"x \\<notin> res_vars (PairExp e1 e2)\")\n      apply (simp add: non_prim_vars_def)\n     apply (auto)\n      apply (simp add: non_prim_vars_def)\n    (* pair case 2 *)\n     apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" and x=\"x\" in leq_use_none)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n     apply (simp add: non_prim_vars_def)\n    (* if case 1 *)\n    apply (case_tac \"x \\<notin> res_vars (IfExp e1 e2 e3)\")\n     apply (simp add: non_prim_vars_def)\n    apply (auto)\n      apply (case_tac \"x \\<notin> non_prim_vars env e1\")\n      apply (simp add: non_prim_vars_def)\n      apply (auto)\n    (* if case 2 *)\n     apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" and x=\"x\" in leq_use_none)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n     apply (case_tac \"x \\<notin> non_prim_vars env e2\")\n      apply (simp add: non_prim_vars_def)\n     apply (auto)\n    (* if case 3 *)\n     apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" and x=\"x\" in leq_use_none)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n    apply (case_tac \"x \\<notin> non_prim_vars env e3\")\n     apply (simp add: non_prim_vars_def)\n    apply (auto)\n    (* lambda case *)\n    apply (case_tac \"x \\<noteq> Var x1a\")\n     apply (auto)\n    apply (cut_tac r_x=\"rxa\" and r_s=\"r_s1\" and x=\"x\" in leq_use_none)\n      apply (auto)\n    apply (cut_tac r_s=\"rxa\" and y=\"Var x1a\" and r=\"r\" and x=\"x\" in add_use_none_rev)\n      apply (auto)\n    apply (case_tac \"x \\<notin> non_prim_vars (add_env env (Var x1a) t1) e\")\n     apply (simp add: non_prim_vars_def)\n    apply (case_tac \"\\<not> non_prim_entry (add_env env (Var x1a) t1) x\")\n      apply (simp add: non_prim_entry_def)\n      apply (simp add: add_env_def)\n      apply (auto)\n   apply (simp add: non_prim_vars_def)\n    (* app case 1 *)\n  apply (case_tac \"x \\<notin> res_vars (AppExp e1 e2)\")\n   apply (simp add: non_prim_vars_def)\n  apply (auto)\n   apply (case_tac \"x \\<notin> non_prim_vars env e1\")\n    apply (simp add: non_prim_vars_def)\n   apply (auto)\n    (* app case 2 *)\n  apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" and x=\"x\" in leq_use_none)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n  apply (case_tac \"x \\<notin> non_prim_vars env e2\")\n   apply (simp add: non_prim_vars_def)\n  apply (auto)\n  done\n    \nlemma well_typed_aff_fv_own: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; x \\<in> res_vars e; env x = Some t; req_type t = Aff \\<rbrakk> \\<Longrightarrow> r_s1 x = OwnPerm\"    \n  apply (induction e arbitrary: env r_s1 tau r_s2 rx)\n       apply (auto)\n    (* var case *)\n       apply (case_tac xa)\n        apply (auto)\n       apply (case_tac \"ereq_use_env x t x \\<noteq> OwnPerm\")\n        apply (simp add: ereq_use_env_def)\n        apply (simp add: end_req_perm_def)\n        apply (simp add: one_use_env_def)\n       apply (cut_tac r_x=\"ereq_use_env x t\" and r_s=\"r_s1\" and x=\"x\" in leq_use_own)\n         apply (auto)\n    (* pair case 2 *)\n      apply (rule_tac r_x=\"r_s2a\" in leq_use_own)\n       apply (auto)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n    (* if case 2 *)\n     apply (rule_tac r_x=\"r_s2a\" in leq_use_own)\n      apply (auto)\n     apply (rule_tac e=\"e1\" in well_typed_perm_leq)\n     apply (auto)\n    (* if case 3 *)\n    apply (rule_tac r_x=\"r_s2a\" in leq_use_own)\n     apply (auto)\n    apply (rule_tac e=\"e1\" in well_typed_perm_leq)\n    apply (auto)\n    (* lambda case *)\n   apply (rule_tac r_x=\"rxa\" in leq_use_own)\n    apply (auto)\n   apply (case_tac \"\\<not> add_use_env rxa (Var x1a) r x = OwnPerm\")\n    apply (auto)\n    apply (case_tac \"\\<not> add_env env (Var x1a) t1 x = Some t\")\n     apply (simp add: add_env_def)\n    apply (auto)\n   apply (simp add: add_use_env_def)\n    (* app case *)\n  apply (rule_tac r_x = \"r_s2a\" in leq_use_own)\n   apply (auto)\n  apply (rule_tac e=\"e1\" in well_typed_perm_leq)\n  apply (auto)\n  done\n\n  \n    (* \n      ####################################\n        P4. well-typed manipulation for type environments\n      ####################################\n    *)\n\nlemma well_typed_add_vars: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; x \\<notin> free_vars e \\<rbrakk> \\<Longrightarrow> well_typed (add_env env (Var x) t) r_s1 e tau r_s2 rx\"       \n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n        apply (auto)\n    (* var case *)\n        apply (simp add: add_env_def)\n        apply (case_tac xa)\n         apply (auto)\n       apply (simp add: add_env_def)\n       apply (case_tac xa)\n        apply (auto)\n    (* pair case *)\n      apply (rule_tac x=\"r_s2a\" in exI)\n      apply (rule_tac x=\"r_s3\" in exI)\n      apply (rule_tac x=\"rx1\" in exI)\n      apply (auto)\n      apply (rule_tac x=\"rx2\" in exI)\n      apply (auto)\n    (* if case *)\n     apply (rule_tac x=\"rx'\" in exI)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)    \n    (* lambda case 1 *)\n    apply (rule_tac x=\"rxa\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"r_end\" in exI)\n    apply (rule_tac x=\"r_s'\" in exI)\n    apply (case_tac \"x = x1a\")\n     apply (cut_tac env=\"env\" and x=\"Var x\" and t=\"t\" and t'=\"t1\" in double_add_env)\n     apply (auto)\n    apply (cut_tac env=\"env\" and x=\"Var x1a\" and y=\"Var x\" and t=\"t\" and t'=\"t1\" in almost_comm_add_env)\n     apply (auto)\n    (* lambda case 2 *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_end\" in exI)\n   apply (rule_tac x=\"r_s'\" in exI)\n   apply (cut_tac env=\"env\" and x=\"Var x\" and t=\"t\" and t'=\"t1\" in double_add_env)\n   apply (auto)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  done    \n\nlemma well_typed_rem_vars: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; x \\<notin> free_vars e \\<rbrakk> \\<Longrightarrow> well_typed (rem_env env (Var x)) r_s1 e tau r_s2 rx\"    \n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n        apply (auto)\n    (* var case *)\n        apply (simp add: rem_env_def)\n        apply (case_tac xa)\n         apply (auto)\n       apply (simp add: rem_env_def)\n       apply (case_tac xa)\n        apply (auto)\n    (* pair case *)\n      apply (rule_tac x=\"r_s2a\" in exI)\n      apply (rule_tac x=\"r_s3\" in exI)\n      apply (rule_tac x=\"rx1\" in exI)\n      apply (auto)\n      apply (rule_tac x=\"rx2\" in exI)\n      apply (auto)\n    (* if case *)\n     apply (rule_tac x=\"rx'\" in exI)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n    (* lambda case 1 *)\n    apply (rule_tac x=\"rxa\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"r_end\" in exI)\n    apply (rule_tac x=\"r_s'\" in exI)\n    apply (case_tac \"x = x1a\")\n     apply (cut_tac env=\"env\" and x=\"Var x\" and t=\"t1\" in partial_add_rem_env)\n    apply (auto)\n    apply (cut_tac env=\"env\" and x=\"Var x\" and y=\"Var x1a\" and t=\"t1\" in almost_comm_add_rem_env)\n     apply (auto)\n    (* lambda case 2 *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_end\" in exI)\n   apply (rule_tac x=\"r_s'\" in exI)\n   apply (cut_tac env=\"env\" and x=\"Var x\" and t=\"t1\" in partial_add_rem_env)\n   apply (auto)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  done   \n    \nlemma well_typed_add_vars2: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; x \\<notin> ref_vars e \\<rbrakk> \\<Longrightarrow> well_typed (add_env env (Loc x) t) r_s1 e tau r_s2 rx\"       \n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n        apply (auto)\n    (* var case *)\n        apply (simp add: add_env_def)\n        apply (case_tac xa)\n         apply (auto)\n       apply (simp add: add_env_def)\n       apply (case_tac xa)\n        apply (auto)\n    (* pair case *)\n      apply (rule_tac x=\"r_s2a\" in exI)\n      apply (rule_tac x=\"r_s3\" in exI)\n      apply (rule_tac x=\"rx1\" in exI)\n      apply (auto)\n      apply (rule_tac x=\"rx2\" in exI)\n      apply (auto)\n    (* if case *)\n     apply (rule_tac x=\"rx'\" in exI)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)    \n    (* lambda case *)\n    apply (rule_tac x=\"rxa\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"r_end\" in exI)\n    apply (rule_tac x=\"r_s'\" in exI)\n    apply (cut_tac env=\"env\" and x=\"Var x1a\" and y=\"Loc x\" and t=\"t\" and t'=\"t1\" in almost_comm_add_env)\n     apply (auto)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  done        \n\nlemma well_typed_add_vars_rev: \"\\<lbrakk> well_typed (add_env env (Var x) t) r_s1 e tau r_s2 rx; x \\<notin> free_vars e \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau r_s2 rx\"\n  apply (cut_tac env=\"add_env env (Var x) t\" and ?r_s1.0=\"r_s1\" and e=\"e\" and tau=\"tau\" and ?r_s2.0=\"r_s2\" and rx=\"rx\" and x=\"x\" in well_typed_rem_vars)\n    apply (auto)\n  apply (case_tac \"env (Var x) = None\")\n   apply (auto)\n   apply (cut_tac env=\"env\" and x=\"Var x\" and t=\"t\" in cancel_rem_add_env)\n    apply (auto)\n  apply (rule_tac t=\"well_typed env r_s1 e tau r_s2 rx\" and s=\"well_typed (add_env (rem_env env (Var x)) (Var x) y) r_s1 e tau r_s2 rx\" in subst)\n   apply (cut_tac env=\"env\" and x=\"Var x\" and y=\"y\" in cancel_add_rem_env)\n    apply (auto)\n  apply (rule_tac well_typed_add_vars)\n   apply (cut_tac env=\"env\" and x=\"Var x\" and y=\"t\" in partial_rem_add_env)\n   apply (auto)\n  done\n\nlemma well_typed_contain_env: \"\\<lbrakk> contain_env env env'; well_typed env' r_s1 e tau r_s2 rx \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau r_s2 rx\"    \n  apply (induct e arbitrary: env env' r_s1 tau r_s2 rx)\n        apply (auto)\n    (* var case *)\n       apply (simp add: contain_env_def)\n       apply (erule_tac x=\"res_name x\" in allE)\n       apply (auto)\n      apply (simp add: contain_env_def)\n      apply (erule_tac x=\"owner_name x\" in allE)\n      apply (auto)\n    (* pair case *)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (rule_tac x=\"r_s3\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"r_s2a\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"rx1\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"rx2\" in exI)\n    apply (auto)\n    (* lam case *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_end\" in exI)\n   apply (rule_tac x=\"r_s'\" in exI)\n   apply (cut_tac r_s=\"env\" and r_x=\"env'\" and x=\"Var x1a\" and t=\"t1\" in dist_add_contain_env)\n    apply (auto)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  done\n    \n    (* \n      ####################################\n        P5. well-typed manipulation for start permissions\n      ####################################\n    *)    \n    \nlemma well_typed_comp_start_perm: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx \\<rbrakk> \\<Longrightarrow> well_typed env (comp_use_env r_s1 r_ex) e tau r_s2 rx\"\n  apply (induction e arbitrary: env r_s1 tau r_s2 rx)\n        apply (auto)\n    (* const, op, var case 1 *)\n         apply (rule_tac comp_leq_use_env1)\n         apply (simp)\n        apply (rule_tac comp_leq_use_env1)\n        apply (simp)\n       apply (rule_tac comp_leq_use_env1)\n       apply (simp)\n    (* var case 2 *)\n      apply (rule_tac x=\"r_exa\" in exI)\n      apply (auto)\n       apply (rule_tac r_sb=\"diff_use_env r_s1 (comp_use_env (ereq_use_env (owner_name x) tau_x) r_exa)\" in trans_leq_use_env)\n        apply (rule_tac dist_diff_leq_use_env)\n        apply (rule_tac self_comp_leq_use_env1)\n       apply (auto)\n      apply (rule_tac comp_leq_use_env1)\n      apply (simp)\n    (* pair case *)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (rule_tac x=\"r_s3\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"r_exa\" in exI)\n     apply (auto)\n     apply (rule_tac comp_leq_use_env1)\n     apply (simp)\n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"r_s2a\" in exI)\n    apply (auto)\n    (* lambda case *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n    apply (rule_tac r_sb=\"r_s1\" in trans_leq_use_env)\n     apply (rule_tac comp_leq_use_env1)\n     apply (rule_tac id_leq_use_env)\n    apply (simp)\n   apply (rule_tac x=\"r_exa\" in exI)\n   apply (auto)\n    apply (rule_tac r_sb=\"diff_use_env r_s1 r_exa\" in trans_leq_use_env)\n     apply (rule_tac dist_diff_leq_use_env)\n     apply (rule_tac self_comp_leq_use_env1)\n    apply (simp)\n   apply (rule_tac comp_leq_use_env1)\n   apply (simp)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"r_exa\" in exI)\n  apply (auto)\n  apply (rule_tac comp_leq_use_env1)\n  apply (simp)\n  done\n  \nlemma well_typed_comp_start_perm2: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx \\<rbrakk> \\<Longrightarrow> well_typed env (comp_use_env r_ex r_s1) e tau r_s2 rx\"\n  apply (cut_tac r_s=\"r_ex\" and r_x=\"r_s1\" in comm_comp_use_env)\n  apply (auto)\n  apply (rule_tac well_typed_comp_start_perm)\n  apply (auto)\n  done    \n    \nlemma well_typed_incr_start_perm: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; leq_use_env r_s1 r_c \\<rbrakk> \\<Longrightarrow> well_typed env r_c e tau r_s2 rx\"\n  apply (cut_tac r_s=\"r_c\" and r_x=\"r_s1\" in cancel_comp_use_env2)\n   apply (auto)\n  apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s1\" and r_ex=\"r_c\" and e=\"e\" and tau=\"tau\" and ?r_s2.0=\"r_s2\" and rx=\"rx\" in well_typed_comp_start_perm2)\n   apply (auto)\n  done\n    \n    (* \n      ####################################\n        P6. well-typed manipulation for sweeping changes\n      ####################################\n    *)        \n    \n    (* - diff perm lemmas *)\n    \nlemma wtdp_start_perm_req: \"\\<lbrakk> y \\<notin> own_env_vars r_x; leq_use_env (req_use_env y tau) r_s1 \\<rbrakk>\n       \\<Longrightarrow> leq_use_env (req_use_env y tau) (diff_use_env r_s1 r_x)\"        \n  apply (rule_tac r_s=\"r_s1\" in req_leq_use_env)\n   apply (simp)\n  apply (cut_tac r_s=\"r_s1\" and x=\"y\" and r_x=\"r_x\" in diff_use_eq)\n   apply (auto)\n  apply (simp add: own_env_vars_def)\n  done\n\nlemma weak_diff_req_use_env: \"weak_use_env (diff_use_env (req_use_env x tau) (req_use_env x tau))\"\n  apply (simp add: diff_use_env_def)\n  apply (simp add: weak_use_env_def)\n  apply (auto)\n  apply (case_tac \"req_use_env x tau xa\")\n    apply (auto)\n  done\n  \nlemma wtdp_disj_req_use_env2: \"\\<lbrakk> r_x x \\<noteq> OwnPerm \\<rbrakk> \\<Longrightarrow> disj_use_env r_x (diff_use_env (req_use_env x tau) (req_use_env x tau))\"\n  apply (cut_tac x=\"x\" and tau=\"tau\" in weak_diff_req_use_env)\n  apply (simp add: disj_use_env_def)\n  apply (auto)\n   apply (simp add: mini_disj_use_env_def)\n   apply (auto)\n   apply (rule_tac r_s=\"req_use_env x tau\" in leq_use_none)\n    apply (rule_tac self_diff_leq_use_env)\n   apply (rule_tac req_use_none_alt)\n   apply (auto)\n  apply (simp add: mini_disj_use_env_def)\n  apply (auto)\n  apply (simp add: weak_use_env_def)\n  done\n    \nlemma wtdp_end_req: \"\\<lbrakk> non_prim_vars env e \\<inter> own_env_vars r_x = {}; x \\<in> res_vars e; env x = Some tau;\n  r_x x = OwnPerm \\<rbrakk> \\<Longrightarrow> end_req_perm tau = NoPerm\" \n  apply (case_tac \"x \\<in> non_prim_vars env e\")\n   apply (simp add: own_env_vars_def)\n   apply (auto)\n  apply (case_tac \"req_type tau \\<noteq> Prim\")\n   apply (simp add: non_prim_vars_def)\n   apply (simp add: non_prim_entry_def)\n  apply (simp add: end_req_perm_def)\n  done\n    \nlemma well_typed_diff_perms: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; non_prim_vars env e \\<inter> own_env_vars r_x = {} \\<rbrakk> \\<Longrightarrow>\n  well_typed env (diff_use_env r_s1 r_x) e tau (diff_use_env r_s2 r_x) (diff_use_env rx r_x)\"\n  apply (induction e arbitrary: env r_s1 tau r_s2 rx r_x)\n       apply (auto)\n    (* const case *)\n          apply (rule_tac dist_diff_leq_use_env)\n          apply (simp)\n         apply (rule_tac dist_diff_leq_use_env)\n         apply (simp)\n    (* op case *)\n        apply (rule_tac dist_diff_leq_use_env)\n        apply (simp)\n       apply (rule_tac dist_diff_leq_use_env)\n       apply (simp)\n    (* var case p1. manipulation to show that x1a exists in r_s2 *)\n      apply (rule_tac mini_disj_diff_leq_use_env2)\n       apply (simp)\n      apply (simp add: ereq_use_env_def)\n      apply (simp add: mini_disj_use_env_def)\n      apply (simp add: one_use_env_def)\n      apply (auto)\n      apply (rule_tac env=\"env\" and e=\"VarExp x\" and r_x=\"r_x\" and x=\"owner_name x\" in wtdp_end_req)\n          apply (auto)\n       apply (case_tac x)\n        apply (auto)\n    (* var case p2 *)\n     apply (rule_tac x=\"diff_use_env r_ex r_x\" in exI)\n     apply (auto)\n        apply (rule_tac rhs_fold_dcl_use_env)\n        apply (rule_tac rhs_flip_use_env)\n        apply (rule_tac rhs_pull_comp_use_env)\n        apply (cut_tac r_ex=\"r_ex\" and r_x=\"r_x\" in sum_comp_diff_use_env)\n        apply (auto)\n        apply (rule_tac rhs_unroll_dcl_use_env)\n        apply (rule_tac rhs_unroll_dcl_use_env)\n        apply (rule_tac dist_diff_leq_use_env)\n        apply (rule_tac rhs_fold_dcl_use_env)\n        apply (simp)\n       apply (rule_tac dist_diff_leq_use_env)\n       apply (simp)\n      apply (rule_tac dist_diff_leq_use_env)\n      apply (simp)\n    (* - use disjointess of r_x from (req x tau) to remove - r_x *)\n     apply (rule_tac disj_diff_leq_use_env)\n      apply (simp add: ereq_use_env_def)\n      apply (simp add: disj_use_env_def)\n      apply (auto)\n       apply (rule_tac one_mini_disj_use_env1)\n       apply (auto)\n       apply (rule_tac env=\"env\" and e=\"VarExp x\" and r_x=\"r_x\" and x=\"owner_name x\" in wtdp_end_req)\n           apply (auto)\n        apply (case_tac x)\n         apply (auto)\n      apply (rule_tac one_mini_disj_use_env2)\n      apply (auto)\n      apply (simp add: comp_use_env_def)\n      apply (simp add: one_use_env_def)\n    (* - through a slightly more involved process we can also remove it from the left *)\n     apply (rule_tac lhs_unroll_dcl_use_env)\n     apply (rule_tac r_sb=\"diff_use_env (diff_use_env (ereq_use_env (owner_name x) tau_x) (ereq_use_env (owner_name x) tau_x)) r_ex\" in trans_leq_use_env)\n       apply (rule_tac lhs_fold_dcl_use_env)\n       apply (simp)\n      apply (rule_tac lhs_ddl_use_env)\n      apply (rule_tac comm_disj_use_env)\n      apply (simp add: ereq_use_env_def)\n      apply (simp add: disj_use_env_def)\n      apply (auto)\n       apply (rule_tac one_mini_disj_use_env1)\n       apply (auto)\n       apply (rule_tac env=\"env\" and e=\"VarExp x\" and r_x=\"r_x\" and x=\"owner_name x\" in wtdp_end_req)\n          apply (auto)\n       apply (case_tac x)\n        apply (auto)\n     apply (rule_tac one_mini_disj_use_env2)\n     apply (auto)\n      apply (simp add: one_use_env_def)\n    (* pair case *)\n     apply (rule_tac x=\"diff_use_env r_s2a r_x\" in exI)\n     apply (rule_tac x=\"diff_use_env r_s3 r_x\" in exI)\n     apply (rule_tac x=\"diff_use_env rx1 r_x\" in exI)\n     apply (auto)\n      apply (case_tac \"\\<not> non_prim_vars env e1 \\<inter> own_env_vars r_x = {}\")\n       apply (simp add: non_prim_vars_def)\n       apply (auto)\n     apply (rule_tac x=\"diff_use_env rx2 r_x\" in exI)\n     apply (auto)\n           apply (case_tac \"\\<not> non_prim_vars env e2 \\<inter> own_env_vars r_x = {}\")\n            apply (simp add: non_prim_vars_def)\n            apply (auto)\n          (*apply (rule_tac aff_diff_use_env)\n          apply (simp)*)\n          apply (rule_tac t=\"lift_use_env (diff_use_env rx1 r_x) r\" and s=\"diff_use_env (lift_use_env rx1 r) r_x\" in subst)\n           apply (rule_tac lift_diff_use_env)\n          apply (rule_tac dist_diff_leq_use_env)\n          apply (simp)\n         apply (rule_tac t=\"lift_use_env (diff_use_env rx2 r_x) r\" and s=\"diff_use_env (lift_use_env rx2 r) r_x\" in subst)\n          apply (rule_tac lift_diff_use_env)\n         apply (rule_tac dist_diff_leq_use_env)\n         apply (simp)\n      apply (rule_tac r_s=\"lift_use_env rx1 r\" in disj_leq_use_env1)\n       apply (rule_tac r_s=\"lift_use_env rx2 r\" in disj_leq_use_env2)\n        apply (simp)\n       apply (rule_tac dist_lift_leq_use_env)\n       apply (rule_tac self_diff_leq_use_env)\n      apply (rule_tac dist_lift_leq_use_env)\n      apply (rule_tac self_diff_leq_use_env)\n     apply (rule_tac x=\"diff_use_env r_ex r_x\" in exI)\n     apply (auto)\n        apply (rule_tac t=\"diff_use_env (diff_use_env r_s3 r_x) (diff_use_env r_ex r_x)\" and s=\"diff_use_env (diff_use_env r_s3 r_ex) r_x\" in subst)\n         apply (rule_tac dist_sq_diff_use_env)\n        apply (rule_tac dist_diff_leq_use_env)\n        apply (simp)\n       apply (rule_tac dist_diff_leq_use_env)\n       apply (simp)\n      apply (rule_tac dist_diff_leq_use_env)\n      apply (simp)\n     apply (case_tac \"req_type (PairTy t1 t2 r) = Prim\")\n      apply (simp add: pair_req_def)\n      apply (auto)\n      apply (rule_tac leq_empty_use_env)     \n     apply (simp add: pair_req_def)\n     apply (rule_tac t=\"lift_use_env (diff_use_env rx1 r_x) r\" and s=\"diff_use_env (lift_use_env rx1 r) r_x\" in subst)\n      apply (rule_tac lift_diff_use_env)\n     apply (rule_tac t=\"lift_use_env (diff_use_env rx2 r_x) r\" and s=\"diff_use_env (lift_use_env rx2 r) r_x\" in subst)\n      apply (rule_tac lift_diff_use_env)\n     apply (simp add: dist_diff_comp_use_env)\n     apply (rule_tac t=\"diff_use_env (diff_use_env (comp_use_env (lift_use_env rx1 r) (lift_use_env rx2 r)) r_x)\n        (diff_use_env r_ex r_x)\" and s=\"diff_use_env (diff_use_env (comp_use_env (lift_use_env rx1 r) (lift_use_env rx2 r)) r_ex) r_x\" in subst)\n      apply (rule_tac dist_sq_diff_use_env)\n     apply (rule_tac dist_diff_leq_use_env)\n     apply (simp)\n    (* if case *)\n    apply (rule_tac x=\"diff_use_env rx' r_x\" in exI)\n    apply (rule_tac x=\"diff_use_env r_s2a r_x\" in exI)\n    apply (auto)\n     apply (case_tac \"\\<not> non_prim_vars env e1 \\<inter> own_env_vars r_x = {}\")\n      apply (simp add: non_prim_vars_def)\n      apply (auto)\n    apply (rule_tac x=\"diff_use_env rx1 r_x\" in exI)\n    apply (auto)\n     apply (case_tac \"\\<not> non_prim_vars env e2 \\<inter> own_env_vars r_x = {}\")\n      apply (simp add: non_prim_vars_def)\n      apply (auto)\n    apply (rule_tac x=\"diff_use_env rx2 r_x\" in exI)\n    apply (auto)\n     apply (case_tac \"\\<not> non_prim_vars env e3 \\<inter> own_env_vars r_x = {}\")\n      apply (simp add: non_prim_vars_def)\n      apply (auto)\n    apply (simp add: dist_diff_comp_use_env)\n    (* lambda case *)\n   apply (rule_tac x=\"diff_use_env rxa r_x\" in exI)\n   apply (auto)\n      apply (rule_tac x=\"diff_use_env r_end (rem_use_env r_x (Var x1a))\" in exI)\n      apply (rule_tac x=\"diff_use_env r_s' (rem_use_env r_x (Var x1a))\" in exI)\n      apply (cut_tac r_s=\"rxa\" and x=\"Var x1a\" and r=\"r\" and r_x=\"r_x\" in diff_add_rem_use_env)\n      apply (auto)\n      apply (case_tac \"\\<not> non_prim_vars (add_env env (Var x1a) t1) e \\<inter> own_env_vars (rem_use_env r_x (Var x1a)) = {}\")\n       apply (auto)\n      apply (simp add: rem_use_env_def)\n      apply (simp add: own_env_vars_def)\n      apply (case_tac \"x = Var x1a\")\n       apply (auto)\n      apply (simp add: non_prim_vars_def)\n      apply (simp add: non_prim_entry_def)\n      apply (simp add: add_env_def)\n      apply (auto)\n     apply (rule_tac aff_diff_use_env)\n     apply (simp)\n    apply (rule_tac dist_diff_leq_use_env)\n    apply (simp)\n   apply (rule_tac x=\"diff_use_env r_ex r_x\" in exI)\n   apply (auto)\n    (* - proving bounds *)\n      apply (rule_tac t=\"diff_use_env (diff_use_env r_s1 r_x) (diff_use_env r_ex r_x)\" and s=\"diff_use_env (diff_use_env r_s1 r_ex) r_x\" in subst)\n       apply (cut_tac r_s=\"r_s1\" and r_x=\"r_ex\" and r_ex=\"r_x\" in dist_sq_diff_use_env)\n       apply (auto)\n      apply (rule_tac dist_diff_leq_use_env)\n      apply (simp)\n     apply (rule_tac dist_diff_leq_use_env)\n     apply (simp)\n    apply (rule_tac dist_diff_leq_use_env)\n    apply (simp)\n   apply (rule_tac t=\"diff_use_env (diff_use_env rxa r_x) (diff_use_env r_ex r_x)\" and s=\"diff_use_env (diff_use_env rxa r_ex) r_x\" in subst)\n    apply (cut_tac r_s=\"rxa\" and r_x=\"r_ex\" and r_ex=\"r_x\" in dist_sq_diff_use_env)\n    apply (auto)\n   apply (rule_tac dist_diff_leq_use_env)\n   apply (simp)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"diff_use_env r_s2a r_x\" in exI)\n  apply (rule_tac x=\"diff_use_env rx1 r_x\" in exI)\n  apply (auto)\n   apply (case_tac \"\\<not> non_prim_vars env e1 \\<inter> own_env_vars r_x = {}\")\n    apply (simp add: non_prim_vars_def)\n    apply (auto)\n  apply (rule_tac x=\"diff_use_env rx2 r_x\" in exI)\n  apply (rule_tac x=\"diff_use_env r_s3 r_x\" in exI)\n  apply (auto)\n   apply (case_tac \"\\<not> non_prim_vars env e2 \\<inter> own_env_vars r_x = {}\")\n    apply (simp add: non_prim_vars_def)\n    apply (auto)\n    (* - reusable substitutions *)\n  apply (case_tac \"\\<not> lift_use_env (diff_use_env rx2 r_x) r = diff_use_env (lift_use_env rx2 r) r_x\")\n   apply (cut_tac r_s=\"rx2\" and r=\"r\" and r_x=\"r_x\" in lift_diff_use_env)\n   apply (simp)\n    (* - last instantiation *)\n  apply (rule_tac x=\"diff_use_env r_ex r_x\" in exI)\n  apply (auto)\n    (* - prove the bound for r_s2 *)\n        apply (rule_tac rhs_fold_dcl_use_env)\n        apply (rule_tac rhs_flip_use_env)\n        apply (rule_tac rhs_unroll_dcl_use_env)\n        apply (rule_tac rhs_diff_leq_use_env)\n        apply (rule_tac r_sb=\"diff_use_env (diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)) r_x\" in trans_leq_use_env)\n         apply (rule_tac lhs_fold_dcl_use_env)\n         apply (rule_tac lhs_flip_use_env)\n         apply (rule_tac lhs_unroll_dcl_use_env)\n         apply (rule_tac unroll_dcl_use_env)\n         apply (rule_tac dist_diff_leq_use_env_gen)\n          apply (rule_tac dist_diff_leq_use_env_gen)\n           apply (rule_tac self_diff_leq_use_env)\n          apply (rule_tac dist_comp_leq_use_env)\n           apply (rule_tac comp_leq_use_env1)\n           apply (rule_tac self_diff_leq_use_env)\n          apply (rule_tac comp_leq_use_env2)\n          apply (rule_tac self_diff_leq_use_env)\n         apply (rule_tac self_diff_leq_use_env)\n        apply (rule_tac dist_diff_leq_use_env)\n        apply (simp)\n    (* - prove lift safety *)\n    (* - prove rx1 + rx2 is subtractable *)\n      apply (rule_tac r_sb=\"diff_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_x\" in trans_leq_use_env)\n       apply (rule_tac dist_diff_leq_use_env)\n       apply (simp)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (rule_tac dist_diff_leq_use_env)\n       apply (rule_tac self_comp_leq_use_env1)\n      apply (rule_tac dist_diff_leq_use_env)\n      apply (rule_tac self_comp_leq_use_env2)\n    (* - prove disjointedness *)\n     apply (rule_tac r_s=\"rx1\" in disj_leq_use_env1)\n      apply (rule_tac r_s=\"lift_use_env rx2 r\" in disj_leq_use_env2)\n       apply (simp)\n      apply (rule_tac self_diff_leq_use_env)\n     apply (rule_tac self_diff_leq_use_env)\n    apply (rule_tac dist_diff_leq_use_env)\n    apply (simp)\n    (* - prove r_ex bound *)\n   apply (rule_tac dist_diff_leq_use_env)\n   apply (simp)\n    (* - prove the bound for rx *)\n  apply (simp add: app_req_def)\n  apply (auto)\n   apply (rule_tac leq_empty_use_env)\n  apply (rule_tac t=\"comp_use_env (diff_use_env rx1 r_x) (diff_use_env rx2 r_x)\" and s=\"diff_use_env (comp_use_env rx1 rx2) r_x\" in subst)\n   apply (simp add: dist_diff_comp_use_env) \n  apply (rule_tac t=\"comp_use_env (diff_use_env rx1 r_x) (diff_use_env (lift_use_env rx2 r) r_x)\" and\n      s=\"diff_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_x\" in subst)\n   apply (simp add: dist_diff_comp_use_env)\n  apply (rule_tac t=\"comp_use_env (diff_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_x) (diff_use_env r_ex r_x)\" and\n      s=\"diff_use_env (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex) r_x\" in subst)\n   apply (simp add: dist_diff_comp_use_env)\n  apply (rule_tac t=\"diff_use_env (diff_use_env (comp_use_env rx1 rx2) r_x) (diff_use_env (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex) r_x)\" and\n      s=\"diff_use_env (diff_use_env (comp_use_env rx1 rx2) (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)) r_x\" in subst)\n   apply (rule_tac dist_sq_diff_use_env)\n  apply (rule_tac dist_diff_leq_use_env)\n  apply (simp)\n  done \n    \nlemma well_typed_disj_diff_perms: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; mini_disj_use_env r_ex r_s1 \\<rbrakk> \\<Longrightarrow>\n  well_typed env (diff_use_env r_s1 r_ex) e tau (diff_use_env r_s2 r_ex) (diff_use_env rx r_ex)\"    \n  apply (rule_tac well_typed_diff_perms)\n   apply (simp)\n  apply (auto)\n  apply (case_tac \"r_s1 x = NoPerm\")\n   apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s1\" and x=\"x\" in well_typed_no_npv_use)\n     apply (auto)\n  apply (simp add: own_env_vars_def)\n  apply (simp add: mini_disj_use_env_def)\n  done      \n\nlemma well_typed_rem_perms: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; x \\<notin> non_prim_vars env e \\<rbrakk> \\<Longrightarrow>\n  well_typed env (rem_use_env r_s1 x) e tau (rem_use_env r_s2 x) (rem_use_env rx x)\"  \n  apply (cut_tac r_s=\"r_s1\" and x=\"x\" in diff_rem_use_env)\n  apply (cut_tac r_s=\"r_s2\" and x=\"x\" in diff_rem_use_env)\n  apply (cut_tac r_s=\"rx\" and x=\"x\" in diff_rem_use_env)\n  apply (auto)\n  apply (rule_tac well_typed_diff_perms)\n   apply (auto)\n  apply (simp add: one_use_env_def)\n  apply (simp add: own_env_vars_def)\n  apply (case_tac \"x = xa\")\n   apply (auto)\n  done\n\nlemma well_typed_add_perms_rev: \"\\<lbrakk> well_typed env (add_use_env r_s1 x r) e tau (add_use_env r_s2 x r') (add_use_env rx x r3);\n  r_s1 x = NoPerm; r_s2 x = NoPerm; rx x = NoPerm; x \\<notin> non_prim_vars env e \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau r_s2 rx\"\n  apply (cut_tac r_s=\"r_s1\" and x=\"x\" and r=\"r\" in cancel_rem_add_use_env)\n   apply (auto)\n  apply (cut_tac r_s=\"r_s2\" and x=\"x\" and r=\"r'\" in cancel_rem_add_use_env)\n   apply (auto)\n  apply (cut_tac r_s=\"rx\" and x=\"x\" and r=\"r3\" in cancel_rem_add_use_env)\n   apply (auto)\n  apply (cut_tac env=\"env\" and ?r_s1.0=\"add_use_env r_s1 x r\" and e=\"e\" and tau=\"tau\" and ?r_s2.0=\"add_use_env r_s2 x r'\" and rx=\"add_use_env rx x r3\" and x=\"x\" in well_typed_rem_perms)\n    apply (auto)\n  done\n\nlemma wtapr_ex: \"\\<lbrakk>leq_use_env rxa (add_use_env r_s1 x r);\n     leq_use_env r_s2 (diff_use_env (add_use_env r_s1 x r) r_ex); leq_use_env rx r_s2; leq_use_env r_ex (add_use_env r_s1 x r);\n     leq_use_env (diff_use_env rxa r_ex) rx\\<rbrakk>\n    \\<Longrightarrow> \\<exists>r_ex. leq_use_env (rem_use_env r_s2 x) (diff_use_env r_s1 r_ex) \\<and>\n               leq_use_env (rem_use_env rx x) (rem_use_env r_s2 x) \\<and>\n               leq_use_env r_ex r_s1 \\<and> leq_use_env (diff_use_env (rem_use_env rxa x) r_ex) (rem_use_env rx x)\"  \n  apply (rule_tac x=\"rem_use_env r_ex x\" in exI)\n  apply (auto)\n     apply (rule_tac r=\"r\" in rem_add_leq_use_env)\n     apply (rule_tac r_sb=\"add_use_env (diff_use_env r_s1 r_ex) x r\" in trans_leq_use_env)\n      apply (rule_tac dist_add_leq_use_env)\n      apply (rule_tac dist_diff_leq_use_env_gen)\n       apply (rule_tac id_leq_use_env)\n      apply (rule_tac self_rem_leq_use_env)\n     apply (rule_tac r_sb=\"diff_use_env (add_use_env r_s1 x r) r_ex\" in trans_leq_use_env)\n      apply (rule_tac add_diff_leq_use_env)\n     apply (simp)\n    apply (rule_tac dist_rem_leq_use_env)\n    apply (simp)\n   apply (rule_tac r=\"r\" in rem_add_leq_use_env)\n   apply (simp)\n  apply (rule_tac t=\"diff_use_env (rem_use_env rxa x) (rem_use_env r_ex x)\" and s=\"rem_use_env (diff_use_env rxa r_ex) x\" in subst)\n   apply (rule_tac dist_diff_rem_use_env)\n  apply (rule_tac dist_rem_leq_use_env)\n  apply (simp)  \n  done\n\nlemma wtapr_helper: \"\\<lbrakk>\\<And>env r_s1 tau r_s2 rx.\n           \\<lbrakk>well_typed env (add_use_env r_s1 (Var x1a) r) e tau r_s2 rx; Var x1a \\<notin> res_vars e\\<rbrakk>\n           \\<Longrightarrow> well_typed env r_s1 e tau (rem_use_env r_s2 (Var x1a)) (rem_use_env rx (Var x1a));\n        well_typed (add_env env (Var x1a) t1) (add_use_env rxa (Var x1a) ra) e t2 r_s' r_end; aff_use_env rxa a;\n        leq_use_env rxa (add_use_env r_s1 (Var x1a) r); leq_use_env r_s2 (diff_use_env (add_use_env r_s1 (Var x1a) r) r_ex); leq_use_env rx r_s2;\n        leq_use_env r_ex (add_use_env r_s1 (Var x1a) r); leq_use_env (diff_use_env rxa r_ex) rx; x = Var x1a\\<rbrakk>\n       \\<Longrightarrow> \\<exists>rxa. (\\<exists>r_end r_s'. well_typed (add_env env (Var x1a) t1) (add_use_env rxa (Var x1a) ra) e t2 r_s' r_end) \\<and>\n                 aff_use_env rxa a \\<and>\n                 leq_use_env rxa r_s1 \\<and>\n                 (\\<exists>r_ex. leq_use_env (rem_use_env r_s2 (Var x1a)) (diff_use_env r_s1 r_ex) \\<and>\n                         leq_use_env (rem_use_env rx (Var x1a)) (rem_use_env r_s2 (Var x1a)) \\<and>\n                         leq_use_env r_ex r_s1 \\<and> leq_use_env (diff_use_env rxa r_ex) (rem_use_env rx (Var x1a)))\"\n  apply (rule_tac x=\"rem_use_env rxa x\" in exI)\n  apply (auto)\n     apply (rule_tac t=\"add_use_env (rem_use_env rxa (Var x1a)) (Var x1a) ra\" and s=\"add_use_env rxa (Var x1a) ra\" in subst)\n      apply (rule_tac partial_add_rem_use_env)\n     apply (auto)\n    apply (rule_tac aff_rem_use_env)\n    apply (simp)\n   apply (rule_tac r=\"r\" in rem_add_leq_use_env)\n   apply (simp)\n  apply (rule_tac wtapr_ex)\n  apply (auto)\n  done\n    \nlemma well_typed_add_perms_rev2: \"\\<lbrakk> well_typed env (add_use_env r_s1 x r) e tau r_s2 rx; x \\<notin> res_vars e \\<rbrakk> \\<Longrightarrow>\n  well_typed env r_s1 e tau (rem_use_env r_s2 x) (rem_use_env rx x)\"\n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n        apply (auto)\n    (* const + op cases *)\n            apply (rule_tac r=\"r\" in rem_add_leq_use_env)\n            apply (auto)\n           apply (rule_tac dist_rem_leq_use_env)\n           apply (auto)\n          apply (rule_tac r=\"r\" in rem_add_leq_use_env)\n          apply (auto)\n         apply (rule_tac dist_rem_leq_use_env)\n         apply (auto)\n    (* var cases *)\n        apply (rule_tac r_sb=\"rem_use_env (ereq_use_env (owner_name xa) tau_x) x\" in trans_leq_use_env)\n         apply (rule_tac r=\"r\" in rem_add_leq_use_env)\n         apply (auto)\n        apply (rule_tac rhs_rem_leq_use_env)\n         apply (simp add: ereq_use_env_def)\n         apply (simp add: one_use_env_def)\n         apply (case_tac xa)\n          apply (auto)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac x=\"rem_use_env r_ex x\" in exI)\n       apply (auto)\n          apply (rule_tac r=\"r\" in rem_add_leq_use_env)\n          apply (rule_tac r_sb=\"add_use_env (diff_use_env r_s1 (comp_use_env (ereq_use_env (owner_name xa) tau_x) r_ex)) x r\" in trans_leq_use_env)\n           apply (rule_tac dist_add_leq_use_env)\n           apply (rule_tac dist_diff_leq_use_env_gen)\n            apply (rule_tac id_leq_use_env)\n           apply (rule_tac dist_comp_leq_use_env)\n            apply (rule_tac self_comp_leq_use_env1)\n           apply (rule_tac comp_leq_use_env2)\n           apply (rule_tac self_rem_leq_use_env)\n          apply (rule_tac r_sb=\"diff_use_env (add_use_env r_s1 x r) (comp_use_env (ereq_use_env (owner_name xa) tau_x) r_ex)\" in trans_leq_use_env)\n           apply (rule_tac add_diff_leq_use_env)\n          apply (simp)\n         apply (rule_tac dist_rem_leq_use_env)\n         apply (simp)\n        apply (rule_tac r=\"r\" in rem_add_leq_use_env)\n        apply (auto)\n       apply (rule_tac r_sb=\"rem_use_env (diff_use_env (ereq_use_env (owner_name xa) tau_x) (comp_use_env (ereq_use_env (owner_name xa) tau_x) r_ex)) x\" in trans_leq_use_env)\n        apply (rule_tac dist_rem_leq_use_env)\n        apply (simp)\n       apply (simp add: dist_diff_rem_use_env)\n       apply (rule_tac dist_diff_leq_use_env_gen)\n        apply (rule_tac rhs_rem_leq_use_env)\n         apply (simp add: ereq_use_env_def)\n         apply (simp add: one_use_env_def)\n         apply (case_tac xa)\n          apply (auto)\n        apply (rule_tac id_leq_use_env)\n       apply (simp add: dist_rem_comp_use_env)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac comp_leq_use_env1)\n        apply (rule_tac self_rem_leq_use_env)\n       apply (rule_tac self_comp_leq_use_env2)\n    (* pair case *)\n      apply (rule_tac x=\"rem_use_env r_s2a x\" in exI)\n      apply (rule_tac x=\"rem_use_env r_s3 x\" in exI)\n      apply (rule_tac x=\"rem_use_env rx1 x\" in exI)\n      apply (auto)\n      apply (rule_tac x=\"rem_use_env rx2 x\" in exI)\n      apply (auto)\n            apply (rule_tac well_typed_rem_perms)\n             apply (simp_all)\n            apply (simp add: non_prim_vars_def)\n           apply (simp add: lift_rem_use_env)\n           apply (rule_tac dist_rem_leq_use_env)\n           apply (simp)\n          apply (simp add: lift_rem_use_env)\n          apply (rule_tac dist_rem_leq_use_env)\n          apply (simp)(*\n         apply (rule_tac safe_lift_rem_use_env)\n         apply (simp)\n        apply (rule_tac safe_lift_rem_use_env)\n        apply (simp)*)\n       apply (simp add: lift_rem_use_env)\n       apply (rule_tac r_s=\"lift_use_env rx1 ra\" in disj_leq_use_env1)\n        apply (rule_tac r_s=\"lift_use_env rx2 ra\" in disj_leq_use_env2)\n         apply (simp)\n        apply (rule_tac self_rem_leq_use_env)\n       apply (rule_tac self_rem_leq_use_env)\n      apply (rule_tac x=\"rem_use_env r_ex x\" in exI)\n      apply (auto)\n         apply (rule_tac t=\"diff_use_env (rem_use_env r_s3 x) (rem_use_env r_ex x)\" and s=\"rem_use_env (diff_use_env r_s3 r_ex) x\" in subst)\n          apply (rule_tac dist_diff_rem_use_env)\n         apply (rule_tac dist_rem_leq_use_env)\n         apply (simp)\n        apply (rule_tac dist_rem_leq_use_env)\n        apply (simp)\n       apply (rule_tac r=\"r\" in rem_add_leq_use_env)\n       apply (auto)\n      apply (case_tac \"req_type (PairTy t1 t2 ra) = Prim\")\n       apply (simp add: pair_req_def)\n       apply (rule_tac leq_empty_use_env)\n      apply (simp add: pair_req_def)\n      apply (rule_tac r_sb=\"rem_use_env (diff_use_env (comp_use_env (lift_use_env rx1 ra) (lift_use_env rx2 ra)) r_ex) x\" in trans_leq_use_env)\n       apply (rule_tac dist_rem_leq_use_env)\n       apply (simp)\n      apply (simp add: dist_diff_rem_use_env)\n      apply (rule_tac dist_diff_leq_use_env)\n      apply (simp add: dist_rem_comp_use_env)\n      apply (simp add: lift_rem_use_env)\n      apply (rule_tac id_leq_use_env)\n    (* if case *)\n     apply (rule_tac x=\"rem_use_env rx' x\" in exI)\n     apply (rule_tac x=\"rem_use_env r_s2a x\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rem_use_env rx1 x\" in exI)\n     apply (auto)\n      apply (rule_tac well_typed_rem_perms)\n       apply (simp)\n      apply (simp add: non_prim_vars_def)\n     apply (rule_tac x=\"rem_use_env rx2 x\" in exI)\n     apply (auto)\n      apply (rule_tac well_typed_rem_perms)\n       apply (simp)\n      apply (simp add: non_prim_vars_def)\n     apply (simp add: dist_rem_comp_use_env)\n    (* lam case 1. x \\<noteq> x1a *)\n    apply (case_tac \"x \\<noteq> Var x1a\")\n     apply (auto)\n     apply (rule_tac x=\"rem_use_env rxa x\" in exI)\n     apply (auto)\n        apply (rule_tac t=\"add_use_env (rem_use_env rxa x) (Var x1a) ra\" and s=\"rem_use_env (add_use_env rxa (Var x1a) ra) x\" in subst)\n         apply (rule_tac almost_comm_rem_add_use_env)\n         apply (auto)\n        apply (rule_tac x=\"rem_use_env r_end x\" in exI)\n        apply (rule_tac x=\"rem_use_env r_s' x\" in exI)\n        apply (rule_tac well_typed_rem_perms)\n         apply (auto)\n        apply (simp add: non_prim_vars_def)\n       apply (rule_tac aff_rem_use_env)\n       apply (simp)\n      apply (rule_tac r=\"r\" in rem_add_leq_use_env)\n      apply (simp) \n     apply (rule_tac wtapr_ex)\n         apply (auto)\n    (* lam case 1b / 2. x = x1a *)\n    apply (rule_tac wtapr_helper)\n           apply (auto)\n   apply (rule_tac wtapr_helper)\n          apply (auto)\n    (* app case. *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"ra\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"rem_use_env r_s2a x\" in exI)\n  apply (rule_tac x=\"rem_use_env rx1 x\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rem_use_env rx2 x\" in exI)\n  apply (rule_tac x=\"rem_use_env r_s3 x\" in exI)\n  apply (auto)\n   apply (rule_tac well_typed_rem_perms)\n    apply (auto)\n   apply (simp add: non_prim_vars_def)\n  apply (rule_tac x=\"rem_use_env r_ex x\" in exI)\n  apply (auto)\n        apply (rule_tac r_sb=\"rem_use_env (diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 ra)) r_ex)) x\" in trans_leq_use_env)\n         apply (simp add: dist_diff_rem_use_env)\n         apply (rule_tac dist_diff_leq_use_env_gen)\n          apply (rule_tac id_leq_use_env)\n         apply (simp add: dist_rem_comp_use_env)\n         apply (simp add: lift_rem_use_env)\n         apply (rule_tac id_leq_use_env)\n        apply (rule_tac dist_rem_leq_use_env)\n        apply (simp)(*\n       apply (rule_tac safe_lift_rem_use_env)\n       apply (simp)*)\n      apply (simp add: lift_rem_use_env)\n      apply (rule_tac r_sb=\"rem_use_env (comp_use_env rx1 (lift_use_env rx2 ra)) x\" in trans_leq_use_env)\n       apply (rule_tac dist_rem_leq_use_env)\n       apply (simp)\n      apply (simp add: dist_rem_comp_use_env)\n      apply (rule_tac id_leq_use_env)\n     apply (simp add: lift_rem_use_env)\n     apply (rule_tac r_s=\"rx1\" in disj_leq_use_env1)\n      apply (rule_tac r_s=\"lift_use_env rx2 ra\" in disj_leq_use_env2)\n       apply (simp)\n      apply (rule_tac self_rem_leq_use_env)\n     apply (rule_tac self_rem_leq_use_env)\n    apply (rule_tac dist_rem_leq_use_env)\n    apply (simp)\n   apply (rule_tac r=\"r\" in rem_add_leq_use_env)\n   apply (simp)\n  apply (simp add: app_req_def)\n  apply (auto)\n   apply (rule_tac leq_empty_use_env)\n  apply (rule_tac r_sb=\"rem_use_env (diff_use_env (comp_use_env rx1 rx2) (comp_use_env (comp_use_env rx1 (lift_use_env rx2 ra)) r_ex)) x\" in trans_leq_use_env)\n   apply (rule_tac dist_rem_leq_use_env)\n   apply (simp)\n  apply (simp add: dist_diff_rem_use_env)\n  apply (simp add: lift_rem_use_env)\n  apply (simp add: dist_rem_comp_use_env)\n  apply (rule_tac id_leq_use_env)\n  done        \n    \n    (* \n      ####################################\n        P7. well-typed manipulation for permission changes\n      ####################################\n    *)    \n\nlemma well_typed_comp_perms_gen: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; mini_disj_use_env r_s1 r_ex \\<rbrakk> \\<Longrightarrow>\n  well_typed env (comp_use_env r_s1 r_ex) e tau (comp_use_env r_s2 r_ex) rx\"\n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n       apply (auto)\n    (* const case *)\n           apply (rule_tac dist_comp_leq_use_env)\n            apply (rule_tac comp_leq_use_env1)\n            apply (simp)\n           apply (rule_tac comp_leq_use_env2)\n           apply (rule_tac id_leq_use_env)\n          apply (rule_tac comp_leq_use_env1)\n          apply (simp)\n    (* op case *)\n         apply (rule_tac dist_comp_leq_use_env)\n          apply (rule_tac comp_leq_use_env1)\n          apply (simp)\n         apply (rule_tac comp_leq_use_env2)\n         apply (rule_tac id_leq_use_env)\n        apply (rule_tac comp_leq_use_env1)\n        apply (simp)\n    (* var case *)\n       apply (rule_tac comp_leq_use_env1)\n       apply (simp)\n      apply (rule_tac x=\"r_exa\" in exI)\n      apply (auto)\n    (* - first half of end permission bounds check *)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (rule_tac r_sb=\"diff_use_env r_s1 (comp_use_env (ereq_use_env (owner_name x) tau_x) r_exa)\" in trans_leq_use_env)\n          apply (rule_tac dist_diff_leq_use_env)\n          apply (rule_tac self_comp_leq_use_env1)\n         apply (simp)\n    (* - second half of end permission bounds check *)\n        apply (rule_tac rhs_dist_dcl_use_env)\n        apply (rule_tac comp_leq_use_env2)\n        apply (rule_tac mini_disj_diff_leq_use_env)\n         apply (rule_tac id_leq_use_env)\n        apply (rule_tac r_s=\"r_s1\" in mini_disj_leq_use_env1)\n         apply (simp)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (auto)\n    (* - various bounds checks *)\n       apply (rule_tac comp_leq_use_env1)\n       apply (simp)\n      apply (rule_tac comp_leq_use_env1)\n      apply (simp)\n    (* pair case *)\n     apply (rule_tac x=\"comp_use_env r_s2a r_ex\" in exI)\n     apply (rule_tac x=\"comp_use_env r_s3 r_ex\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n        apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" and r_ex=\"r_ex\" in mini_disj_leq_use_env1)\n          apply (simp)\n         apply (rule_tac well_typed_perm_leq)\n         apply (auto)\n       apply (rule_tac comp_leq_use_env1)\n       apply (simp)\n      apply (rule_tac comp_leq_use_env1)\n      apply (simp)\n     apply (rule_tac x=\"r_exa\" in exI)\n     apply (auto)\n       apply (rule_tac rhs_dist_dcl_use_env)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac comp_leq_use_env1)\n        apply (simp)\n       apply (rule_tac comp_leq_use_env2)\n       apply (rule_tac mini_disj_diff_leq_use_env)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac r_s=\"r_s1\" in mini_disj_leq_use_env1)\n        apply (simp_all)\n      apply (rule_tac comp_leq_use_env1)\n      apply (simp)\n     apply (rule_tac comp_leq_use_env1)\n     apply (simp)\n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"comp_use_env r_s2a r_ex\" in exI)\n    apply (auto)\n    apply (cut_tac r_s=\"r_s1\" and r_x=\"r_s2a\" and r_ex=\"r_ex\" in mini_disj_leq_use_env1)\n      apply (simp)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n    apply (rule_tac x=\"rx1\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"rx2\" in exI)\n    apply (auto)\n    (* lambda case *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n    apply (rule_tac comp_leq_use_env1)\n    apply (simp)\n   apply (rule_tac x=\"r_exa\" in exI)\n   apply (auto)\n     apply (rule_tac rhs_dist_dcl_use_env)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac comp_leq_use_env1)\n      apply (simp)\n     apply (rule_tac comp_leq_use_env2)\n     apply (rule_tac mini_disj_diff_leq_use_env)\n      apply (rule_tac id_leq_use_env)\n     apply (rule_tac r_s=\"r_s1\" in mini_disj_leq_use_env1)\n      apply (auto)\n    apply (rule_tac comp_leq_use_env1)\n    apply (simp)\n   apply (rule_tac comp_leq_use_env1)\n   apply (simp)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"comp_use_env r_s2a r_ex\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"comp_use_env r_s3 r_ex\" in exI)\n  apply (auto)\n   apply (cut_tac r_s=\"r_s1\" and r_x=\"r_s2a\" and r_ex=\"r_ex\" in mini_disj_leq_use_env1)\n     apply (simp)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n  apply (cut_tac r_sa=\"r_s1\" and r_sb=\"r_s2a\" and r_sc=\"r_s3\" in trans_leq_use_env)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n   apply (rule_tac well_typed_perm_leq)\n   apply (auto)\n  apply (rule_tac x=\"r_exa\" in exI)\n  apply (auto)\n    (* - first half of end permissions bounds check *)\n     apply (rule_tac rhs_dist_dcl_use_env)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac comp_leq_use_env1)\n      apply (simp)\n    (* - second half of end permissions bounds check *)\n     apply (rule_tac comp_leq_use_env2)\n     apply (rule_tac mini_disj_diff_leq_use_env)\n      apply (rule_tac id_leq_use_env)\n     apply (rule_tac r_s=\"r_s1\" in mini_disj_leq_use_env1)\n      apply (simp)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n       apply (auto)\n    (* - final bounds checks *)\n    apply (rule_tac comp_leq_use_env1)\n    apply (simp)\n   apply (rule_tac comp_leq_use_env1)\n   apply (simp)\n  apply (rule_tac comp_leq_use_env1)\n  apply (simp)\n  done    \n \nlemma well_typed_comp_perms: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; disj_use_env r_s1 r_ex \\<rbrakk> \\<Longrightarrow>\n  well_typed env (comp_use_env r_s1 r_ex) e tau (comp_use_env r_s2 r_ex) rx\"\n  apply (rule_tac well_typed_comp_perms_gen)\n   apply (simp)\n  apply (simp add: disj_use_env_def)\n  done\n\nlemma well_typed_comp_perms2: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; disj_use_env r_s1 r_ex \\<rbrakk> \\<Longrightarrow>\n  well_typed env (comp_use_env r_ex r_s1) e tau (comp_use_env r_ex r_s2) rx\"    \n  apply (cut_tac r_s=\"r_ex\" and r_x=\"r_s1\" in comm_comp_use_env)  \n  apply (cut_tac r_s=\"r_ex\" and r_x=\"r_s2\" in comm_comp_use_env)\n  apply (auto)\n  apply (rule_tac well_typed_comp_perms)\n   apply (auto)\n  done           \n    \nlemma well_typed_add_perms: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; x \\<notin> non_prim_vars env e; r = OwnPerm; rx x = NoPerm \\<rbrakk> \\<Longrightarrow>\n  well_typed env (add_use_env r_s1 x r) e tau (add_use_env r_s2 x r) rx\"\n  apply (cut_tac r_s=\"r_s1\" and x=\"x\" and r=\"r\" in partial_add_rem_use_env)\n  apply (cut_tac r_s=\"r_s2\" and x=\"x\" and r=\"r\" in partial_add_rem_use_env)\n  apply (cut_tac r_s=\"rx\" and x=\"x\" in ignore_rem_use_env)\n   apply (simp)\n  apply (cut_tac r_s=\"rem_use_env r_s1 x\" and x=\"x\" and r=\"r\" in add_comp_use_env)\n   apply (auto)\n  apply (cut_tac r_s=\"rem_use_env r_s2 x\" and x=\"x\" and r=\"r\" in add_comp_use_env)\n    apply (auto)\n  apply (rule_tac well_typed_comp_perms)\n   apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s1\" and e=\"e\" and tau=\"tau\" and ?r_s2.0=\"r_s2\" and rx=\"rx\" and x=\"x\" in well_typed_rem_perms)\n     apply (auto)\n  apply (rule_tac disj_one_use_env)\n  apply (simp add: rem_use_env_def)\n  done    \n  \nlemma well_typed_incr_simul_perm: \"\\<lbrakk> leq_use_env r_s r_c; well_typed env r_s e tau r_s rx \\<rbrakk> \\<Longrightarrow> well_typed env r_c e tau r_c rx\"\n  apply (rule_tac t=\"r_c\" and s=\"comp_use_env r_s (diff_use_env r_c r_s)\" in subst)\n   apply (rule_tac msum_diff_comp_use_env)\n   apply (simp)\n  apply (rule_tac well_typed_comp_perms_gen)\n   apply (simp)\n  apply (rule_tac mini_disj_diff_use_env)\n  done    \n    \nlemma well_typed_lift_perms: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx \\<rbrakk> \\<Longrightarrow> well_typed env (lift_use_env r_s1 r) e tau (lift_use_env r_s2 r) rx\"\n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)  \n        apply (auto)\n    (* const + op cases *)\n           apply (rule_tac dist_lift_leq_use_env)\n           apply (simp)\n          apply (rule_tac lift_leq_use_env)\n          apply (simp)\n         apply (rule_tac dist_lift_leq_use_env)\n         apply (simp)\n        apply (rule_tac lift_leq_use_env)\n        apply (simp)\n    (* var cases *)\n       apply (rule_tac lift_leq_use_env)\n       apply (simp)\n      apply (rule_tac x=\"r_ex\" in exI)\n      apply (auto)\n        apply (cut_tac r_s=\"r_s1\" and r_x=\"comp_use_env (ereq_use_env (owner_name x) tau_x) r_ex\" and r=\"r\" in lift_diff_use_env)\n        apply (auto)\n        apply (rule_tac dist_lift_leq_use_env)\n        apply (simp)\n       apply (rule_tac lift_leq_use_env)\n       apply (simp)\n      apply (rule_tac lift_leq_use_env)\n      apply (simp)\n    (* pair case *)\n     apply (rule_tac x=\"lift_use_env r_s2a r\" in exI)\n     apply (rule_tac x=\"lift_use_env r_s3 r\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n       apply (rule_tac lift_leq_use_env)\n       apply (simp)\n      apply (rule_tac lift_leq_use_env)\n      apply (simp)\n     apply (rule_tac x=\"r_ex\" in exI)\n     apply (auto)\n       apply (cut_tac r_s=\"r_s3\" and r_x=\"r_ex\" and r=\"r\" in lift_diff_use_env)\n       apply (simp)\n       apply (rule_tac dist_lift_leq_use_env)\n       apply (simp)\n      apply (rule_tac lift_leq_use_env)\n      apply (simp)\n     apply (rule_tac lift_leq_use_env)\n     apply (simp)\n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"lift_use_env r_s2a r\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"rx1\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"rx2\" in exI)\n    apply (auto)\n    (* lam case *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n    apply (rule_tac lift_leq_use_env)\n    apply (simp)\n   apply (rule_tac x=\"r_ex\" in exI)\n   apply (auto)\n     apply (cut_tac r_s=\"r_s1\" and r_x=\"r_ex\" and r=\"r\" in lift_diff_use_env)\n     apply (auto)\n     apply (rule_tac dist_lift_leq_use_env)\n     apply (simp)\n    apply (rule_tac lift_leq_use_env)\n    apply (simp)\n   apply (rule_tac lift_leq_use_env)\n   apply (simp)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"ra\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"lift_use_env r_s2a r\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"lift_use_env r_s3 r\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"r_ex\" in exI)\n  apply (auto)\n     apply (cut_tac r_s=\"r_s3\" and r_x=\"comp_use_env (comp_use_env rx1 (lift_use_env rx2 ra)) r_ex\" and r=\"r\" in lift_diff_use_env)\n     apply (auto)\n     apply (rule_tac dist_lift_leq_use_env)\n     apply (simp)\n    apply (rule_tac lift_leq_use_env)\n    apply (simp)\n   apply (rule_tac lift_leq_use_env)\n   apply (simp)\n  apply (rule_tac lift_leq_use_env)\n  apply (simp)\n  done    \n    \n    (* \n      ####################################\n        P8. well-typed manipulation for end permissions\n      ####################################\n    *)    \n    \nlemma wtdep_diff_use_env: \"\\<lbrakk> leq_use_env r_x (diff_use_env r_s r_xa) \\<rbrakk> \\<Longrightarrow> diff_use_env r_x r_ex = diff_use_env r_x (comp_use_env (diff_use_env r_ex r_xa) r_xa)\"    \n  apply (case_tac \"\\<forall> x. diff_use_env r_x r_ex x = diff_use_env r_x (comp_use_env (diff_use_env r_ex r_xa) r_xa) x\")\n   apply (auto)\n  apply (simp add: diff_use_env_def)\n  apply (simp add: leq_use_env_def)\n  apply (simp add: comp_use_env_def)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_xa x\")\n    apply (auto)\n    apply (case_tac \"r_ex x\")\n      apply (auto)\n   apply (case_tac \"r_ex x\")\n     apply (auto)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n  apply (case_tac \"r_ex x\")\n    apply (auto)\n  done\n\nlemma wtdep_strong_use_vars: \"\\<lbrakk> well_typed env (diff_use_env r_s1 r_x) e tau r_s2 rx; strong_use_env r_x \\<rbrakk> \\<Longrightarrow> non_prim_vars env e \\<inter> own_env_vars r_x = {}\"    \n  apply (auto)\n  apply (case_tac \"r_x x \\<noteq> NoPerm\")\n   apply (case_tac \"r_x x\")\n     apply (auto)\n    apply (simp add: strong_use_env_def)\n   apply (cut_tac r_s=\"r_s1\" and r_ex=\"r_x\" and x=\"x\" in diff_use_none_ex)\n    apply (auto)\n   apply (cut_tac x=\"x\" and e=\"e\" and env=\"env\" and ?r_s1.0=\"diff_use_env r_s1 r_x\" in well_typed_no_npv_use)\n     apply (auto)\n  apply (simp add: own_env_vars_def)\n  done\n  \n    \nlemma well_typed_break: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau (norm_use_env r_s1 r_s2) rx\"    \n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n        apply (auto)\n    (* const case *)\n          apply (rule_tac self_norm_leq_use_env)\n         apply (rule_tac rhs_norm_leq_use_env)\n          apply (auto)\n    (* op case *)\n        apply (rule_tac self_norm_leq_use_env)\n       apply (rule_tac rhs_norm_leq_use_env)\n        apply (auto)\n    (* var case *)\n      apply (rule_tac x=\"r_ex\" in exI)\n      apply (auto)\n       apply (rule_tac diff_norm_leq_use_env)\n       apply (simp)\n      apply (rule_tac rhs_norm_leq_use_env)\n       apply (simp)\n      apply (rule_tac r_sb=\"diff_use_env r_s1 (comp_use_env (ereq_use_env (owner_name x) tau_x) r_ex)\" in trans_leq_use_env)\n       apply (rule_tac self_diff_leq_use_env)\n      apply (auto)\n    (* pair case *)\n     apply (cut_tac r_sc=\"r_s3\" and r_sb=\"r_s2a\" and r_sa=\"r_s1\" in trans_leq_use_env)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n     apply (rule_tac x=\"norm_use_env r_s1 r_s2a\" in exI)\n     apply (rule_tac x=\"norm_use_env r_s1 r_s3\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n        apply (rule_tac t=\"norm_use_env r_s1 r_s3\" and s=\"norm_use_env (norm_use_env r_s1 r_s2a) r_s3\" in subst)\n         apply (rule_tac sub_norm_use_env)\n         apply (rule_tac well_typed_perm_leq)\n         apply (auto)\n        apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s2a\" and r_c=\"norm_use_env r_s1 r_s2a\" and e=\"e2\" and ?r_s2.0=\"r_s3\" and rx=\"rx2\" in well_typed_incr_start_perm)\n          apply (auto)\n        apply (rule_tac rhs_self_norm_leq_use_env)\n        apply (rule_tac well_typed_perm_leq)\n        apply (auto)\n       apply (rule_tac rhs_norm_leq_use_env)\n        apply (auto)\n      apply (rule_tac rhs_norm_leq_use_env)\n       apply (auto)\n     apply (rule_tac x=\"r_ex\" in exI)\n     apply (auto)\n      apply (rule_tac spec_norm_leq_use_env)\n      apply (simp)\n     apply (rule_tac rhs_norm_leq_use_env)\n      apply (simp)\n     apply (rule_tac r_sb=\"diff_use_env r_s3 r_ex\" in trans_leq_use_env)\n      apply (rule_tac diff_leq_use_env)\n     apply (auto)\n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"norm_use_env r_s1 r_s2a\" in exI)\n    apply (auto)\n    (* - common substitution *)\n    apply (cut_tac ?r_s1.0=\"r_s2a\" and ?r_s2.0=\"r_s2\" in well_typed_perm_leq)\n     apply (auto)\n    apply (rule_tac t=\"norm_use_env r_s1 r_s2\" and s=\"norm_use_env (norm_use_env r_s1 r_s2a) r_s2\" in subst)\n     apply (rule_tac sub_norm_use_env)\n     apply (simp)\n    (* - rx1 *)\n    apply (rule_tac x=\"rx1\" in exI)\n    apply (auto)\n     apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s2a\" and r_c=\"norm_use_env r_s1 r_s2a\" and e=\"e2\" and ?r_s2.0=\"r_s2\" and rx=\"rx1\" in well_typed_incr_start_perm)\n       apply (auto)\n     apply (rule_tac rhs_self_norm_leq_use_env)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n    (* - rx2 *)\n    apply (rule_tac x=\"rx2\" in exI)\n    apply (auto)\n    apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s2a\" and r_c=\"norm_use_env r_s1 r_s2a\" and e=\"e3\" and ?r_s2.0=\"r_s2\" and rx=\"rx2\" in well_typed_incr_start_perm)\n      apply (auto)\n    apply (rule_tac rhs_self_norm_leq_use_env)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n    (* lam case *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_ex\" in exI)\n   apply (auto)\n    apply (rule_tac diff_norm_leq_use_env)\n    apply (simp)\n   apply (rule_tac rhs_norm_leq_use_env)\n    apply (auto)\n   apply (rule_tac r_sb=\"diff_use_env r_s1 r_ex\" in trans_leq_use_env)\n    apply (rule_tac self_diff_leq_use_env)\n   apply (auto)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"norm_use_env r_s1 r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"norm_use_env r_s1 r_s3\" in exI)\n  apply (cut_tac ?r_s1.0=\"r_s2a\" and ?r_s2.0=\"r_s3\" in well_typed_perm_leq)\n   apply (auto)\n   apply (rule_tac t=\"norm_use_env r_s1 r_s3\" and s=\"norm_use_env (norm_use_env r_s1 r_s2a) r_s3\" in subst)\n    apply (rule_tac sub_norm_use_env)\n    apply (simp)\n   apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s2a\" and r_c=\"norm_use_env r_s1 r_s2a\" and e=\"e2\" and ?r_s2.0=\"r_s3\" and rx=\"rx2\" in well_typed_incr_start_perm)\n     apply (auto)\n   apply (rule_tac rhs_self_norm_leq_use_env)\n   apply (rule_tac well_typed_perm_leq)\n   apply (auto)\n  apply (cut_tac r_sc=\"r_s3\" and r_sb=\"r_s2a\" and r_sa=\"r_s1\" in trans_leq_use_env)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n  apply (rule_tac x=\"r_ex\" in exI)\n  apply (auto)\n    apply (rule_tac spec_norm_leq_use_env)\n    apply (simp)\n   apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n    apply (rule_tac rhs_self_norm_leq_use_env)\n    apply (auto)\n  apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n   apply (rule_tac rhs_self_norm_leq_use_env)\n   apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n    apply (auto)\n  apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n   apply (rule_tac self_diff_leq_use_env)\n  apply (simp)\n  done\n    \n    (* when we perform substitution, we need to be able to stop \"requiring\" permissions. the\n    intuition behind this lemma is that we no longer need a permission if we simply remove it from\n    the list of permissions in the environment. *)    \n\nlemma well_typed_diff_end_perm: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; leq_use_env r_ex r_s1 \\<rbrakk> \\<Longrightarrow>\n  well_typed env r_s1 e tau (diff_use_env r_s2 r_ex) (diff_use_env rx r_ex)\"\n  apply (induct e arbitrary: env r_s1 tau r_s2 rx r_ex)\n        apply (auto)\n    (* const case + op case are trivial since they never require permissions *)\n          apply (rule_tac diff_leq_use_env)\n          apply (simp)\n         apply (rule_tac dist_diff_leq_use_env)\n         apply (simp)\n        apply (rule_tac diff_leq_use_env)\n        apply (simp)\n       apply (rule_tac dist_diff_leq_use_env)\n       apply (simp)\n    (* var case *)\n      apply (rule_tac x=\"comp_use_env r_exa r_ex\" in exI)\n      apply (auto)\n         apply (rule_tac rhs_unroll_dcl_use_env)\n         apply (rule_tac rhs_unroll_dcl_use_env)\n         apply (rule_tac dist_diff_leq_use_env)\n         apply (rule_tac rhs_fold_dcl_use_env)\n         apply (simp)\n        apply (rule_tac dist_diff_leq_use_env)\n        apply (simp)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (auto)\n      apply (rule_tac lhs_unroll_dcl_use_env)\n      apply (rule_tac lhs_unroll_dcl_use_env)\n      apply (rule_tac dist_diff_leq_use_env)\n      apply (rule_tac lhs_fold_dcl_use_env)\n      apply (simp)\n    (* pair case *)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (rule_tac x=\"r_s3\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"comp_use_env r_exa r_ex\" in exI)\n     apply (auto)\n        apply (rule_tac rhs_unroll_dcl_use_env)\n        apply (rule_tac dist_diff_leq_use_env)\n        apply (simp)\n       apply (rule_tac dist_diff_leq_use_env)\n       apply (simp)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (simp_all)\n     apply (case_tac \"req_type (PairTy t1 t2 r) = Prim\")\n      apply (simp add: pair_req_def)\n      apply (rule_tac leq_empty_use_env)\n     apply (simp add: pair_req_def)\n     apply (rule_tac lhs_unroll_dcl_use_env)\n     apply (rule_tac dist_diff_leq_use_env)\n     apply (simp)\n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s1\" and e=\"e1\" and ?r_s2.0=\"r_s2a\" in well_typed_break)\n     apply (auto)\n    apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" in ex_norm_use_env)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n    (* - setup r_s2 \\<le> r_s1 - r_exa *)\n    apply (cut_tac r_sc=\"r_s2\" and r_sb=\"r_s2a\" and r_sa=\"norm_use_env r_s1 r_s2a\" in trans_leq_use_env)\n      apply (rule_tac rhs_self_norm_leq_use_env)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n    (* - prelim for both inductions *)\n    apply (case_tac \"diff_use_env r_s2 (comp_use_env (diff_use_env r_ex r_exa) r_exa) \\<noteq> diff_use_env (diff_use_env r_s2 (diff_use_env r_ex r_exa)) r_exa\")\n     apply (cut_tac r_s=\"r_s2\" and r_x=\"diff_use_env r_ex r_exa\" and r_ex=\"r_exa\" in diff_comp_use_env)\n     apply (auto)\n    apply (cut_tac r_sc=\"diff_use_env r_ex r_exa\" and r_sb=\"r_ex\" and r_sa=\"r_s1\" in trans_leq_use_env)\n      apply (simp)\n     apply (rule_tac self_diff_leq_use_env)\n    (* - first induction *)\n    apply (rule_tac x=\"diff_use_env r_s1 r_exa\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"diff_use_env rx1 r_ex\" in exI)\n    apply (auto)\n    apply (cut_tac r_x=\"r_s2\" and r_s=\"r_s1\" and r_xa=\"r_exa\" and r_ex=\"r_ex\" in wtdep_diff_use_env)\n     apply (auto)\n    apply (cut_tac r_x=\"rx1\" and r_s=\"r_s1\" and r_xa=\"r_exa\" and r_ex=\"r_ex\" in wtdep_diff_use_env)\n      apply (auto)\n      apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n       apply (simp)\n      apply (rule_tac well_typed_perm_leqx)\n      apply (auto)\n     apply (rule_tac t=\"diff_use_env rx1 (comp_use_env (diff_use_env r_ex r_exa) r_exa)\" and s=\"diff_use_env (diff_use_env rx1 (diff_use_env r_ex r_exa)) r_exa\" in subst)\n      apply (rule_tac diff_comp_use_env)\n     apply (rule_tac well_typed_diff_perms)\n      apply (auto)\n      apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s2a\" and r_c=\"r_s1\" and e=\"e2\" and tau=\"tau\" and ?r_s2.0=\"r_s2\" and rx=\"rx1\" in well_typed_incr_start_perm)\n        apply (auto)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n    (* - lemma to prove non-prim x is not in e2 *)\n     apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s1\" and tau=\"tau\" and ?r_s2.0=\"r_s2\" and rx=\"rx1\" and e=\"e2\" and r_x=\"r_exa\" in wtdep_strong_use_vars)\n       apply (rule_tac ?r_s1.0=\"r_s2a\" in well_typed_incr_start_perm)\n        apply (auto)\n     apply (rule_tac r_sb=\"norm_use_env r_s1 r_s2a\" in trans_leq_use_env)\n      apply (simp)\n      apply (rule_tac id_leq_use_env)\n     apply (rule_tac rhs_self_norm_leq_use_env)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n    (* - second induction *)\n    apply (rule_tac x=\"diff_use_env rx2 r_ex\" in exI)\n    apply (auto)\n     apply (cut_tac r_x=\"r_s2\" and r_s=\"r_s1\" and r_xa=\"r_exa\" and r_ex=\"r_ex\" in wtdep_diff_use_env)\n      apply (auto)\n     apply (cut_tac r_x=\"rx2\" and r_s=\"r_s1\" and r_xa=\"r_exa\" and r_ex=\"r_ex\" in wtdep_diff_use_env)\n      apply (auto)\n      apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n       apply (simp)\n      apply (rule_tac well_typed_perm_leqx)\n      apply (auto)\n     apply (rule_tac t=\"diff_use_env rx2 (comp_use_env (diff_use_env r_ex r_exa) r_exa)\" and s=\"diff_use_env (diff_use_env rx2 (diff_use_env r_ex r_exa)) r_exa\" in subst)\n      apply (rule_tac diff_comp_use_env)\n     apply (rule_tac well_typed_diff_perms)\n      apply (auto)\n      apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s2a\" and r_c=\"r_s1\" and e=\"e3\" and tau=\"tau\" and ?r_s2.0=\"r_s2\" and rx=\"rx2\" in well_typed_incr_start_perm)\n        apply (auto)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n    (* - lemma to prove non-prim x is not in e3 *)\n     apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s1\" and tau=\"tau\" and ?r_s2.0=\"r_s2\" and rx=\"rx2\" and e=\"e3\" and r_x=\"r_exa\" in wtdep_strong_use_vars)\n       apply (rule_tac ?r_s1.0=\"r_s2a\" in well_typed_incr_start_perm)\n        apply (auto)\n     apply (rule_tac r_sb=\"norm_use_env r_s1 r_s2a\" in trans_leq_use_env)\n      apply (simp)\n      apply (rule_tac id_leq_use_env)\n     apply (rule_tac rhs_self_norm_leq_use_env)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n    (* - final equality *)\n    apply (simp add: dist_diff_comp_use_env)\n    (* the lambda case allows us to select any r_s2 + rx as long as they match. *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"comp_use_env r_exa r_ex\" in exI)\n   apply (auto)\n      apply (rule_tac r_sb=\"diff_use_env (diff_use_env r_s1 r_exa) r_ex\" in trans_leq_use_env)\n       apply (rule_tac diff_comp_leq_use_env1)\n      apply (rule_tac dist_diff_leq_use_env)\n      apply (simp)\n     apply (rule_tac dist_diff_leq_use_env)\n     apply (simp)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (simp_all)\n   apply (rule_tac lhs_unroll_dcl_use_env)\n   apply (rule_tac dist_diff_leq_use_env)\n   apply (simp)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"comp_use_env r_exa r_ex\" in exI)\n  apply (auto)\n     apply (rule_tac rhs_unroll_dcl_use_env)\n     apply (rule_tac rhs_unroll_dcl_use_env)\n     apply (rule_tac dist_diff_leq_use_env)\n     apply (rule_tac rhs_fold_dcl_use_env)\n     apply (simp)\n    apply (rule_tac dist_diff_leq_use_env)\n    apply (simp)\n   apply (rule_tac dist_comp_leq_use_env)\n    apply (simp_all)\n  apply (simp add: app_req_def)\n  apply (auto)\n   apply (rule_tac leq_empty_use_env)\n  apply (rule_tac lhs_unroll_dcl_use_env)\n  apply (rule_tac lhs_unroll_dcl_use_env)\n  apply (rule_tac dist_diff_leq_use_env)\n  apply (rule_tac lhs_fold_dcl_use_env)\n  apply (simp)\n  done\n\nlemma well_typed_rem_end_perm: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; r_s1 x = OwnPerm \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau (rem_use_env r_s2 x) (rem_use_env rx x)\"  \n  apply (cut_tac r_s=\"r_s2\" and x=\"x\" in diff_rem_use_env)\n  apply (cut_tac r_s=\"rx\" and x=\"x\" in diff_rem_use_env)\n  apply (auto)\n  apply (rule_tac well_typed_diff_end_perm)\n   apply (auto)\n  apply (simp add: leq_use_env_def)\n  apply (simp add: one_use_env_def)\n  done \n    \nlemma well_typed_decr_end_perm: \"\\<lbrakk> well_typed env r_s1 e tau r_c rx; leq_use_env r_s2 r_c; leq_use_env rx r_s2 \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau r_s2 rx\"    \n  apply (induction e arbitrary: env r_s1 tau rx)\n        apply (auto)\n        apply (rule_tac r_sb=\"r_c\" in trans_leq_use_env)\n         apply (auto)\n       apply (rule_tac r_sb=\"r_c\" in trans_leq_use_env)\n        apply (auto)\n      apply (rule_tac x=\"r_ex\" in exI)\n      apply (auto)\n      apply (rule_tac r_sb=\"r_c\" in trans_leq_use_env)\n       apply (auto)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (rule_tac x=\"r_s3\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"r_ex\" in exI)\n     apply (auto)\n     apply (rule_tac r_sb=\"r_c\" in trans_leq_use_env)\n      apply (simp_all)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"r_s2a\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"rx1\" in exI)\n    apply (auto)\n     apply (cut_tac r_sa=\"r_s2\" and r_sb=\"comp_use_env rx1 rx2\" and r_sc=\"rx1\" in trans_leq_use_env)\n       apply (auto)\n     apply (rule_tac comp_leq_use_env1)\n     apply (rule_tac id_leq_use_env)\n    apply (rule_tac x=\"rx2\" in exI)\n    apply (auto)\n    apply (cut_tac r_sa=\"r_s2\" and r_sb=\"comp_use_env rx1 rx2\" and r_sc=\"rx2\" in trans_leq_use_env)\n      apply (auto)\n    apply (rule_tac comp_leq_use_env2)\n    apply (rule_tac id_leq_use_env)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_ex\" in exI)\n   apply (auto)\n   apply (rule_tac r_sb=\"r_c\" in trans_leq_use_env)\n    apply (auto)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"r_ex\" in exI)\n  apply (auto)\n  apply (rule_tac r_sb=\"r_c\" in trans_leq_use_env)\n   apply (auto)\n  done\n  \nlemma well_typed_diff_decr_end_perm: \"\\<lbrakk> well_typed env r_s1 e tau (diff_use_env r_s2 r_ex) (diff_use_env rx r_ex');\n    leq_use_env r_ex' r_ex; leq_use_env r_ex r_s1 \\<rbrakk> \\<Longrightarrow>    \n    well_typed env r_s1 e tau (diff_use_env r_s2 r_ex) (diff_use_env rx r_ex)\"\n  apply (case_tac \"well_typed env r_s1 e tau (diff_use_env r_s2 r_ex) (diff_use_env rx r_ex) =\n    well_typed env r_s1 e tau (diff_use_env (diff_use_env r_s2 r_ex) r_ex) (diff_use_env (diff_use_env rx r_ex') r_ex)\")\n   apply (simp)\n   apply (rule_tac well_typed_diff_end_perm)\n    apply (auto)\n  apply (cut_tac r_s=\"r_s2\" and r_x=\"r_ex\" in double_diff_use_env)\n  apply (cut_tac r_s=\"rx\" and r_x=\"r_ex'\" and r_c=\"r_ex\" in cancel_diff_use_env)\n   apply (auto)\n  done    \n\nlemma well_typed_diff_decr_end_perm_gen: \"\\<lbrakk> well_typed env r_s1 e tau (diff_use_env r_s2 r_exb) (diff_use_env rx r_exb);\n  leq_use_env r_exb r_exa; leq_use_env r_exa r_s1 \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau (diff_use_env r_s2 r_exa) (diff_use_env rx r_exa)\"    \n  apply (cut_tac r_s=\"r_s2\" and r_x=\"r_exb\" and r_c=\"r_exa\" in cancel_diff_use_env)\n   apply (auto)\n  apply (cut_tac r_s=\"rx\" and r_x=\"r_exb\" and r_c=\"r_exa\" in cancel_diff_use_env)\n   apply (auto)\n  apply (rule_tac well_typed_diff_end_perm)\n   apply (auto)\n  done    \n    \n    (* \n      ####################################\n        P9. well-typed manipulation for requirements\n      ####################################\n    *)\n\nlemma well_typed_comp_req1: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; leq_use_env r_ex r_s2 \\<rbrakk> \\<Longrightarrow>\n  well_typed env r_s1 e tau r_s2 (comp_use_env r_ex rx)\"\n  apply (induct e arbitrary: env r_s1 tau r_s2 rx r_ex)\n        apply (auto)\n    (* const + op case *)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (auto)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (auto)\n    (* var cases *)\n      apply (rule_tac x=\"r_exa\" in exI)\n      apply (auto)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (auto)\n      apply (rule_tac comp_leq_use_env2)\n      apply (simp)\n    (* pair case *)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (rule_tac x=\"r_s3\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"r_exa\" in exI)\n     apply (auto)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (simp_all)\n     apply (rule_tac comp_leq_use_env2)\n     apply (simp)\n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"r_s2a\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"comp_use_env r_ex rx1\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"rx2\" in exI)\n    apply (auto)\n    apply (rule_tac assoc_comp_use_env)\n    (* lambda case *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_exa\" in exI)\n   apply (auto)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (auto)\n   apply (rule_tac comp_leq_use_env2)\n   apply (simp)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"r_exa\" in exI)\n  apply (auto)\n   apply (rule_tac dist_comp_leq_use_env)\n    apply (auto)\n  apply (rule_tac comp_leq_use_env2)\n  apply (simp)\n  done\n    \nlemma well_typed_comp_req2: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; leq_use_env r_ex r_s2 \\<rbrakk> \\<Longrightarrow>\n  well_typed env r_s1 e tau r_s2 (comp_use_env rx r_ex)\"\n  apply (cut_tac r_s=\"rx\" and r_x=\"r_ex\" in comm_comp_use_env)\n  apply (auto)\n  apply (rule_tac well_typed_comp_req1)\n   apply (auto)\n  done\n\nlemma well_typed_incr_req: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; leq_use_env rx rc; leq_use_env rc r_s2 \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau r_s2 rc\"    \n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n        apply (auto)\n    (* var case *)\n      apply (rule_tac x=\"r_ex\" in exI)\n      apply (auto)\n      apply (rule_tac r_sb=\"rx\" in trans_leq_use_env)\n       apply (auto)\n    (* pair case *)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (rule_tac x=\"r_s3\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"r_ex\" in exI)\n     apply (auto)\n     apply (rule_tac r_sb=\"rx\" in trans_leq_use_env)\n      apply (auto)\n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"r_s2a\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"rc\" in exI)\n    apply (auto)\n     apply (cut_tac r_sc=\"rx1\" and r_sb=\"comp_use_env rx1 rx2\" and r_sa=\"rc\" in trans_leq_use_env)\n       apply (simp)\n      apply (rule_tac self_comp_leq_use_env1)\n     apply (simp)\n    apply (rule_tac x=\"rc\" in exI)\n    apply (auto)\n     apply (cut_tac r_sc=\"rx2\" and r_sb=\"comp_use_env rx1 rx2\" and r_sa=\"rc\" in trans_leq_use_env)\n       apply (simp)\n      apply (rule_tac self_comp_leq_use_env2)\n     apply (simp)\n    apply (case_tac \"\\<forall> x. rc x = comp_use_env rc rc x\")\n     apply (auto)\n    apply (simp add: comp_use_env_def)\n    apply (case_tac \"rc x\")\n      apply (auto)\n    (* lam case *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_ex\" in exI)\n   apply (auto)\n   apply (rule_tac r_sb=\"rx\" in trans_leq_use_env)\n    apply (auto)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"r_ex\" in exI)\n  apply (auto)\n  apply (rule_tac r_sb=\"rx\" in trans_leq_use_env)\n   apply (auto)\n  done    \n\nlemma well_typed_simul_end_perm: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; leq_use_env r_c r_s2;\n  leq_use_env rc r_c; leq_use_env rx rc \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau r_c rc\"\n  apply (rule_tac rx=\"rx\" in well_typed_incr_req)\n    apply (rule_tac r_c=\"r_s2\" in well_typed_decr_end_perm)\n      apply (auto)\n  apply (rule_tac r_sb=\"rc\" in trans_leq_use_env)\n   apply (auto)\n  done    \n    \n    \nlemma well_typed_add_permsx: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; x \\<notin> non_prim_vars env e \\<rbrakk> \\<Longrightarrow>\n  well_typed env (add_use_env r_s1 x r) e tau (add_use_env r_s2 x r) (add_use_env rx x r)\"  \n  apply (cut_tac r_s=\"r_s1\" and x=\"x\" and r=\"r\" in partial_add_rem_use_env)\n  apply (cut_tac r_s=\"r_s2\" and x=\"x\" and r=\"r\" in partial_add_rem_use_env)  \n  apply (cut_tac r_s=\"rx\" and x=\"x\" and r=\"r\" in partial_add_rem_use_env)  \n  apply (simp)\n  apply (cut_tac r_s=\"rem_use_env r_s1 x\" and x=\"x\" and r=\"r\" in add_comp_use_env)\n   apply (auto)\n   apply (simp add: rem_use_env_def)\n  apply (cut_tac r_s=\"rem_use_env r_s2 x\" and x=\"x\" and r=\"r\" in add_comp_use_env)\n   apply (auto)\n   apply (simp add: rem_use_env_def)\n  apply (cut_tac r_s=\"rem_use_env rx x\" and x=\"x\" and r=\"r\" in add_comp_use_env)\n   apply (auto)\n   apply (simp add: rem_use_env_def)\n  apply (rule_tac well_typed_comp_req2)\n   apply (rule_tac well_typed_comp_perms)\n    apply (rule_tac well_typed_rem_perms)\n     apply (auto)\n   apply (simp add: disj_use_env_def)\n   apply (simp add: mini_disj_use_env_def)\n   apply (simp add: one_use_env_def)\n   apply (simp add: rem_use_env_def)\n  apply (rule_tac self_comp_leq_use_env2)\n  done\n    \n    (* \n      ####################################\n        P10. well-typed manipulation involving lifts\n      ####################################\n    *)     \n\nlemma well_typed_lift_req: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; leq_use_env (lift_use_env rx r) r_s2 \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau r_s2 (lift_use_env rx r)\"    \n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n        apply (auto)\n    (* var case *)\n      apply (rule_tac x=\"r_ex\" in exI)\n      apply (auto)\n      apply (rule_tac lift_leq_use_env)\n      apply (simp)\n    (* pair case *)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (rule_tac x=\"r_s3\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"r_ex\" in exI)\n     apply (auto)\n     apply (rule_tac lift_leq_use_env)\n     apply (simp)\n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"r_s2a\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"lift_use_env rx1 r\" in exI)\n    apply (auto)\n     apply (cut_tac r_sc=\"lift_use_env rx1 r\" and r_sb=\"lift_use_env (comp_use_env rx1 rx2) r\" and r_sa=\"r_s2\" in trans_leq_use_env)\n       apply (simp)\n      apply (rule_tac dist_lift_leq_use_env)\n      apply (rule_tac self_comp_leq_use_env1)\n     apply (auto)\n    apply (rule_tac x=\"lift_use_env rx2 r\" in exI)\n    apply (auto)\n     apply (cut_tac r_sc=\"lift_use_env rx2 r\" and r_sb=\"lift_use_env (comp_use_env rx1 rx2) r\" and r_sa=\"r_s2\" in trans_leq_use_env)\n       apply (simp)\n      apply (rule_tac dist_lift_leq_use_env)\n      apply (rule_tac self_comp_leq_use_env2)\n     apply (auto)\n    apply (rule_tac lift_comp_use_env)\n    (* lam case *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_ex\" in exI)\n   apply (auto)\n   apply (rule_tac lift_leq_use_env)\n   apply (simp)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"ra\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"r_ex\" in exI)\n  apply (auto)\n  apply (rule_tac lift_leq_use_env)\n  apply (auto)\n  done    \n  \nlemma well_typed_lift_all_perms: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx \\<rbrakk> \\<Longrightarrow> well_typed env (lift_use_env r_s1 r) e tau (lift_use_env r_s2 r) (lift_use_env rx r)\"\n  apply (rule_tac well_typed_lift_req)\n   apply (rule_tac well_typed_lift_perms)\n   apply (simp)\n  apply (rule_tac dist_lift_leq_use_env)\n  apply (rule_tac well_typed_perm_leqx)\n  apply (auto)\n  done\n    \nend", "meta": {"author": "anon-ef", "repo": "perm_lang_ef2", "sha": "0fcb6e4c175193cc7b94f297a8aaa605f502d711", "save_path": "github-repos/isabelle/anon-ef-perm_lang_ef2", "path": "github-repos/isabelle/anon-ef-perm_lang_ef2/perm_lang_ef2-0fcb6e4c175193cc7b94f297a8aaa605f502d711/perm_ref/WTLemma.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.640635854839898, "lm_q2_score": 0.4649015713733885, "lm_q1q2_score": 0.2978326155932026}}
{"text": "(*  Title:      HOL/Auth/n_germanSymIndex.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_germanSymIndex Protocol Case Study*} \n\ntheory n_germanSymIndex imports n_germanSymIndex_lemma_invs_on_rules n_germanSymIndex_on_inis\nbegin\nlemma main:\nassumes a1: \"s \\<in> reachableSet {andList (allInitSpecs N)} (rules N)\"\nand a2: \"0 < N\"\nshows \"\\<forall> f. f \\<in> (invariants N) --> formEval f s\"\nproof (rule consistentLemma)\nshow \"consistent (invariants N) {andList (allInitSpecs N)} (rules N)\"\nproof (cut_tac a1, unfold consistent_def, rule conjI)\nshow \"\\<forall> f ini s. f \\<in> (invariants N) --> ini \\<in> {andList (allInitSpecs N)} --> formEval ini s --> formEval f s\"\nproof ((rule allI)+, (rule impI)+)\n  fix f ini s\n  assume b1: \"f \\<in> (invariants N)\" and b2: \"ini \\<in> {andList (allInitSpecs N)}\" and b3: \"formEval ini s\"\n  have b4: \"formEval (andList (allInitSpecs N)) s\"\n  apply (cut_tac b2 b3, simp) done\n  show \"formEval f s\"\n  apply (rule on_inis, cut_tac b1, assumption, cut_tac b2, assumption, cut_tac b3, assumption) done\nqed\nnext show \"\\<forall> f r s. f \\<in> invariants N --> r \\<in> rules N --> invHoldForRule s f r (invariants N)\"\nproof ((rule allI)+, (rule impI)+)\n  fix f r s\n  assume b1: \"f \\<in> invariants N\" and b2: \"r \\<in> rules N\"\n  show \"invHoldForRule s f r (invariants N)\"\n  apply (rule invs_on_rules, cut_tac b1, assumption, cut_tac b2, assumption) done\nqed\nqed\nnext show \"s \\<in> reachableSet {andList (allInitSpecs N)} (rules N)\"\n  apply (metis a1) done\nqed\nend\n", "meta": {"author": "lyj238Gmail", "repo": "newParaVerifier", "sha": "5c2d49bf8e6c46c60efa53c98b0ba5c577d59618", "save_path": "github-repos/isabelle/lyj238Gmail-newParaVerifier", "path": "github-repos/isabelle/lyj238Gmail-newParaVerifier/newParaVerifier-5c2d49bf8e6c46c60efa53c98b0ba5c577d59618/examples/n_germanSymIndex/n_germanSymIndex.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5774953651858118, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.29776811152754046}}
{"text": "(*\n * Copyright 2017, Data61\n * Commonwealth Scientific and Industrial Research Organisation (CSIRO)\n * ABN 41 687 119 230.\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n\n * @TAG(DATA61_BSD)\n *)\n\ntheory OG_More\n\nimports\n  \"../lib/Hoare_Parallel/OG_Tactics\"\n  \"../lib/Hoare_Parallel/Quote_Antiquote\"\n\nbegin\n\nfun add_inv_assn_com :: \"'a assn \\<Rightarrow> 'a ann_com \\<Rightarrow> 'a ann_com\" where\n  \"add_inv_assn_com I (AnnBasic(x, r) f) = (AnnBasic (x, r\\<inter>I) f)\"\n| \"add_inv_assn_com I (AnnSeq c1 c2) =  (AnnSeq (add_inv_assn_com I c1) (add_inv_assn_com I c2))\"\n| \"add_inv_assn_com I (AnnCond1(x, r) bb c1 c2) = (AnnCond1 (x, r\\<inter>I) bb (add_inv_assn_com I c1) (add_inv_assn_com I c2))\" \n| \"add_inv_assn_com I (AnnCond2(x, r) bb c) = (AnnCond2 (x, r\\<inter>I) bb (add_inv_assn_com I c))\"\n| \"add_inv_assn_com I (AnnWhile(x, r) bb (y, i) c) = (AnnWhile (x, r\\<inter>I) bb (y, i\\<inter>I) (add_inv_assn_com I c))\"\n| \"add_inv_assn_com I (AnnAwait(x, r) bb c) = (AnnAwait (x, r\\<inter>I) bb c)\"\n\ndefinition add_inv_aux:: \"'a assn \\<Rightarrow> ('a ann_com option \\<times> 'a assn) \\<Rightarrow> ('a ann_com option \\<times> 'a assn)\"\nwhere\n\" add_inv_aux I p \\<equiv>\n    case p of\n       (Some ac, aa) \\<Rightarrow> (Some (add_inv_assn_com I ac), aa\\<inter>I)\n      |(None, aa) \\<Rightarrow> (None, aa\\<inter>I)\"\n      \nprimrec add_inv_com :: \"'a assn \\<Rightarrow> 'a com \\<Rightarrow> 'a com\" where \n  \"add_inv_com I (Parallel Ts) = (Parallel (map (add_inv_aux I) Ts))\" \n| \"add_inv_com I (Basic f)  =  (Basic f)\" \n| \"add_inv_com I (Seq c1 c2)  = (Seq (add_inv_com I c1) (add_inv_com I c2))\" \n| \"add_inv_com I (Cond bb c1 c2) = (Cond bb (add_inv_com I c1) (add_inv_com I c2))\"\n| \"add_inv_com I (While bb i c)  = (While bb i (add_inv_com I c))\"\n\n(* FIXME: check if other similar lemmas are redundant*)\nlemma pre_add_inv_assn_com:\n  \" pre (add_inv_assn_com I cc) = pre cc \\<inter> I\"\n  apply (induct cc, simp_all)\n  by (clarsimp split: prod.splits)+\n  \nlemma pre_add_inv_aux:\n  \"\\<exists>cc q. c= (Some cc, q) \\<Longrightarrow>\n  pre (the (OG_Hoare.com (add_inv_aux I c))) =\n  pre (the (OG_Hoare.com c)) \\<inter> I\"\n  unfolding add_inv_aux_def\n  apply (clarsimp split: prod.splits option.splits simp: pre_add_inv_assn_com)\n  done\n\nlemma post_add_inv_aux:\n  \"OG_Hoare.post (add_inv_aux I c) = OG_Hoare.post c \\<inter> I\"\n  by (clarsimp simp: add_inv_aux_def \n                  split: prod.splits option.splits)\n  \nlemma atomics_add_assn_com:\n  \"(atomics (add_inv_assn_com I c)) \n     = {(r,a). \\<exists> rr. (rr, a) \\<in> atomics c \\<and> r=rr\\<inter>I }\"\n  by (induct c, auto)\n  \nlemma assertions_add_assn_com:\n  \"(assertions (add_inv_assn_com I c)) \n     = {r. \\<exists> rr. rr \\<in> assertions c \\<and> r=rr\\<inter>I }\"\n  apply (induct c arbitrary: I rule: add_inv_assn_com.induct, simp_all)\n     apply auto [1] \n    apply blast\n   apply blast\n  apply blast\n  done\n\nlemma assertions_add_invs_assn_com:\n  \"assertions (add_inv_assn_com I a) = (\\<lambda>A. A\\<inter>I)`(assertions a)\"\n  by (induction a, simp_all, (clarsimp|blast)+)\n\nlemma pre_add_inv_aux_inter:  \n  \"pre (the (OG_Hoare.com (add_inv_aux (I1\\<inter>I2) c))) =\n   pre (the (OG_Hoare.com (add_inv_aux I1 c))) \\<inter> \n   pre (the (OG_Hoare.com (add_inv_aux I2 c)))\"\n  apply (simp add:add_inv_aux_def)\n  apply (case_tac c)\n  apply clarsimp\n  apply (case_tac a)\n   apply clarsimp\n  apply clarsimp\n  apply (auto simp:pre_add_inv_assn_com)\n  done\n\nlemma add_inv_aux_D:\n  \"add_inv_aux I t = (Some c, q) \\<Longrightarrow> \n  \\<exists> ac aa. t = (Some ac, aa) \\<and> q = aa\\<inter>I \\<and> add_inv_assn_com I ac=c\"\n  by (simp add: add_inv_aux_def split: option.splits prod.splits) \n\nlemma com_add_inv_aux:\n  \"(OG_Hoare.com (add_inv_aux I p)) = \n      (case p of \n          (Some ac, aa) \\<Rightarrow> (Some (add_inv_assn_com I ac)) \n         | (None, _) \\<Rightarrow> None)\"\n  by (clarsimp simp: add_inv_aux_def split: prod.splits option.splits)\n\nlemma add_inv_assn_com_idempotent:\n  \"add_inv_assn_com I (add_inv_assn_com I c) = add_inv_assn_com I c\"\n  by (induct c, simp_all, auto)\n\ndefinition\n  oghoare_inv :: \"'a assn \\<Rightarrow> 'a assn \\<Rightarrow> 'a assn \\<Rightarrow> 'a com \\<Rightarrow> 'a assn \\<Rightarrow> bool\"  (\"(_ \\<parallel>-\\<^sub>i _//_//_//_)\" [55,90,90,55,90] 50)\nwhere\n  \"I' \\<parallel>-\\<^sub>i I p c q \\<equiv> I' \\<parallel>- p (add_inv_com I c) (q(*\\<inter>I*))\"\n\nabbreviation\n  oghoare_inv' :: \"'a assn \\<Rightarrow> 'a assn \\<Rightarrow> 'a com \\<Rightarrow> 'a assn \\<Rightarrow> bool\"  (\"(\\<parallel>-\\<^sub>i _//_//_//_)\" [90,90,55,90] 50)\nwhere\n  \"\\<parallel>-\\<^sub>i I p c q \\<equiv> UNIV \\<parallel>-\\<^sub>i I p c q\"\n\n\nprimrec add_await_ann_com :: \"'a bexp \\<Rightarrow> 'a ann_com \\<Rightarrow> 'a ann_com\" where\n  \"add_await_ann_com P (AnnBasic r f) = (AnnAwait r P (Basic f))\"\n| \"add_await_ann_com P (AnnSeq c1 c2) =  (AnnSeq (add_await_ann_com P c1) (add_await_ann_com P c2))\"\n| \"add_await_ann_com P (AnnCond1 r bb c1 c2) = (AnnCond1 r bb (add_await_ann_com P c1) (add_await_ann_com P c2))\"\n| \"add_await_ann_com P (AnnCond2 r bb c) = (AnnCond2 r bb (add_await_ann_com P c))\"\n| \"add_await_ann_com P (AnnWhile r bb i c) = (AnnWhile r bb i (add_await_ann_com P c))\"\n| \"add_await_ann_com P (AnnAwait r bb c) = (AnnAwait r (bb\\<inter>P) c)\"\n\ndefinition add_await_aux:: \"'a bexp \\<Rightarrow> ('a ann_com option \\<times> 'a assn) \\<Rightarrow> ('a ann_com option \\<times> 'a assn)\"\nwhere\n  \"add_await_aux P p \\<equiv>\n    case p of\n       (Some ac, aa) \\<Rightarrow> (Some (add_await_ann_com P ac), aa)\n      |(None, aa) \\<Rightarrow> (None, aa)\"\n\nfun add_await_com :: \"'a bexp \\<Rightarrow> 'a com \\<Rightarrow> 'a com\" where\n  \"add_await_com P (Parallel Ts) = (Parallel (map (add_await_aux P) Ts))\"\n| \"add_await_com P c = c\"\n\n\n\n(*Checks whether two programs are the same up to cruft*)\nfun same_ann_program_assn_com :: \"'a ann_com \\<Rightarrow> 'a ann_com \\<Rightarrow> bool\" where\n  \"same_ann_program_assn_com (AnnBasic (_, r) f) (AnnBasic(_, r') f') = (r = r' \\<and> f = f')\"\n| \"same_ann_program_assn_com (AnnSeq c1 c2) (AnnSeq c1' c2') = (same_ann_program_assn_com c1 c1' \\<and> same_ann_program_assn_com c2 c2')\"\n| \"same_ann_program_assn_com (AnnCond1(_, r) bb c1 c2) (AnnCond1(_, r') bb' c1' c2') = (r = r' \\<and> bb = bb' \\<and> same_ann_program_assn_com c1 c1' \\<and> same_ann_program_assn_com c2 c2')\" \n| \"same_ann_program_assn_com (AnnCond2(_, r) bb c) (AnnCond2(_, r') bb' c') = (r = r' \\<and> bb = bb' \\<and> same_ann_program_assn_com c c')\"\n| \"same_ann_program_assn_com (AnnWhile(_, r) bb (y, i) c) (AnnWhile(_, r') bb' (_, i') c') = (r = r' \\<and> bb = bb' \\<and> i = i' \\<and> same_ann_program_assn_com c c')\"\n| \"same_ann_program_assn_com (AnnAwait(_, r) bb c) (AnnAwait(_, r') bb' c') = (r = r' \\<and> bb = bb' \\<and> c = c')\"\n| \"same_ann_program_assn_com _ _ = False\"\n\nfun same_ann_prog_aux:: \"('a ann_com option \\<times> 'a assn) \\<Rightarrow> ('a ann_com option \\<times> 'a assn) \\<Rightarrow> bool\" where\n  \"same_ann_prog_aux (Some ac, aa) (Some ac', aa') = (same_ann_program_assn_com ac ac' \\<and> aa = aa')\"\n| \"same_ann_prog_aux (None, aa) (None, aa') = (aa = aa')\"\n| \"same_ann_prog_aux _ _ = False\"\n\nfun same_ann_prog_com :: \"'a com \\<Rightarrow> 'a com \\<Rightarrow> bool\" where \n  \"same_ann_prog_com (Parallel Ts) (Parallel Ts') = (length Ts = length Ts' \\<and> list_all (\\<lambda>(c, c'). same_ann_prog_aux c c') (zip Ts Ts'))\" \n| \"same_ann_prog_com (Basic f) (Basic f') = (f = f')\" \n| \"same_ann_prog_com (Seq c1 c2) (Seq c1' c2') = (same_ann_prog_com c1 c1' \\<and> same_ann_prog_com c2 c2')\" \n| \"same_ann_prog_com (Cond bb c1 c2) (Cond bb' c1' c2') = (bb = bb' \\<and> same_ann_prog_com c1 c1' \\<and> same_ann_prog_com c2 c2')\"\n| \"same_ann_prog_com (While bb i c) (While bb' i' c') = (bb = bb' \\<and> i = i' \\<and> same_ann_prog_com c c')\"\n| \"same_ann_prog_com _ _ = False\"\n\n(*Combines two programs that are assumed to be the same up to cruft.\n  If either program marks an annotation as cruft then the resulting\n  annotation is marked as cruft.*)\nfun combine_pres_assn_com :: \"'a ann_com \\<Rightarrow> 'a ann_com \\<Rightarrow> 'a ann_com\" where\n  \"combine_pres_assn_com (AnnBasic (x, r) f) (AnnBasic(y, r') f') = (AnnBasic (x \\<or> y, r) f)\"\n| \"combine_pres_assn_com (AnnSeq c1 c2) (AnnSeq c1' c2') = (AnnSeq (combine_pres_assn_com c1 c1') (combine_pres_assn_com c2 c2'))\"\n| \"combine_pres_assn_com (AnnCond1(x, r) bb c1 c2) (AnnCond1(y, r') bb' c1' c2') = (AnnCond1 (x \\<or> y, r) bb (combine_pres_assn_com c1 c1') (combine_pres_assn_com c2 c2'))\" \n| \"combine_pres_assn_com (AnnCond2(x, r) bb c) (AnnCond2(y, r') bb' c') = (AnnCond2 (x \\<or> y, r) bb (combine_pres_assn_com c c'))\"\n| \"combine_pres_assn_com (AnnWhile(x, r) bb (y, i) c) (AnnWhile(x', r') bb' (y', i') c') = (AnnWhile (x \\<or> x', r) bb (y \\<or> y', i) (combine_pres_assn_com c c'))\"\n| \"combine_pres_assn_com (AnnAwait(x, r) bb c) (AnnAwait(y, r') bb' c') = (AnnAwait (x \\<or> y, r) bb c)\"\n\nfun combine_pres_aux:: \"('a ann_com option \\<times> 'a assn) \\<Rightarrow> ('a ann_com option \\<times> 'a assn) \\<Rightarrow> ('a ann_com option \\<times> 'a assn)\" where\n  \"combine_pres_aux (Some ac, aa) (Some ac', aa') = (Some (combine_pres_assn_com ac ac'), aa)\"\n| \"combine_pres_aux (None, aa) (None, aa') = (None, aa)\"\n\nfun combine_pres_com :: \"'a com \\<Rightarrow> 'a com \\<Rightarrow> 'a com\" where \n  \"combine_pres_com (Parallel Ts) (Parallel Ts') = (Parallel (map (\\<lambda>(c, c'). combine_pres_aux c c') (zip Ts Ts')))\"\n| \"combine_pres_com (Basic f) (Basic f') = (Basic f)\" \n| \"combine_pres_com (Seq c1 c2) (Seq c1' c2') = (Seq (combine_pres_com c1 c1') (combine_pres_com c2 c2'))\"\n| \"combine_pres_com (Cond bb c1 c2) (Cond bb' c1' c2') = (Cond bb (combine_pres_com c1 c1') (combine_pres_com c2 c2'))\"\n| \"combine_pres_com (While bb i c) (While bb' i' c') = (While bb i (combine_pres_com c c'))\"\n\nlemma Parallel'[rule_format]:\n  \"I \\<parallel>- p c q \\<longrightarrow> c = Parallel Ts\n       \\<longrightarrow> p \\<subseteq> ((\\<Inter>i\\<in>{i. i<length Ts}. pre(the(com(Ts!i)))) \\<union> -I)\n        \\<and> (\\<Inter>i\\<in>{i. i<length Ts}. post(Ts!i)) \\<subseteq> q\n        \\<and> [\\<turnstile>] I Ts \\<and> interfree I Ts\"\n  apply (induct rule: oghoare_induct, (rule TrueI)+)\n       by (auto simp: map_ann_hoare_def)\n\nlemma Basic'[rule_format]:\n  \"I \\<parallel>- p c q \\<longrightarrow> c = Basic f \\<longrightarrow> p \\<subseteq> {s. f s \\<subseteq> q}\"\n  apply (induct rule: oghoare_induct, (rule TrueI)+)\n       apply (auto intro: Conseq dest: subsetD)\n  done\n\nlemma Seq'[rule_format]:\n  \"I \\<parallel>- p c q \\<longrightarrow> c = Seq c1 c2 \\<longrightarrow> (\\<exists>r. I \\<parallel>- p c1 r \\<and> I \\<parallel>- r c2 q)\"\n  apply (induct rule: oghoare_induct, (rule TrueI)+)\n       apply (auto intro: Conseq)\n  done\n\nlemma Cond'[rule_format]:\n  \"I \\<parallel>- p c q \\<longrightarrow> c = Cond b c1 c2 \\<longrightarrow> I \\<parallel>- (p \\<inter> b) c1 q \\<and> I \\<parallel>- (p \\<inter> -b) c2 q\"\n  apply (induct rule: oghoare_induct, (rule TrueI)+)\n       apply simp_all\n   apply clarsimp\n  apply clarsimp\n  apply (rule conjI)\n   apply (erule Conseq[rotated])\n     apply clarsimp\n    apply blast\n  apply (erule Conseq[rotated])\n    apply clarsimp\n   apply blast\n  done\n\nlemma While'[rule_format]:\n  \"I \\<parallel>- p c q \\<longrightarrow> c = While b i c1 \\<longrightarrow> (\\<exists>p'. p \\<subseteq> p' \\<and> p' \\<inter> -b \\<subseteq> q \\<and> I \\<parallel>- (p' \\<inter> b) c1 p')\"\n  apply (induct rule: oghoare_induct, (rule TrueI)+)\n       apply (simp_all)\n   apply force\n  apply clarsimp\n  by (meson subset_trans)\n  \nlemma AnnBasic'[rule_format]:\n  \"I \\<turnstile> c q \\<longrightarrow> c = AnnBasic (b,r) f  \\<longrightarrow>  r \\<inter> I \\<subseteq> {s. f s \\<subseteq> q \\<union> - I}\"\n  by (induct rule: ann_hoare_induct, auto) \n  \nlemma AnnSeq'[rule_format]:\n  \"I \\<turnstile> c q \\<longrightarrow> c = AnnSeq c0 c1  \\<longrightarrow>  I \\<turnstile> c0 (pre c1) \\<and> I \\<turnstile> c1 q \"\n  apply (induct rule: ann_hoare_induct, simp_all)\n  apply (auto intro: AnnConseq)\n  done \n\nlemma AnnCond1'[rule_format]:\n  \"I \\<turnstile> c q \\<longrightarrow> c = AnnCond1 (x,r) b c1 c2  \\<longrightarrow>   \n   r \\<inter> b \\<inter> I \\<subseteq> pre c1 \\<and> I \\<turnstile> c1 q \\<and> r \\<inter> -b \\<inter> I \\<subseteq> pre c2 \\<and> I \\<turnstile> c2 q\"\n  apply (induct rule: ann_hoare_induct, simp_all)\n  apply (auto intro: AnnConseq)\n  done \n  \nlemma AnnCond2'[rule_format]:\n  \"I \\<turnstile> c q \\<longrightarrow> c = AnnCond2 (x,r) b c1  \\<longrightarrow>   \n   r \\<inter> b \\<inter> I \\<subseteq> pre c1 \\<and> I \\<turnstile> c1 q \\<and> r \\<inter> -b \\<inter> I \\<subseteq> q  \"\n  apply (induct rule: ann_hoare_induct, simp_all)\n  apply (auto intro: AnnConseq)\n  done \n   \nlemma AnnWhile'[rule_format]:\n  \"I \\<turnstile> c q \\<longrightarrow> c = AnnWhile (x,r) b (y,i) c1  \\<longrightarrow>   \n   r \\<inter> I \\<subseteq> i \\<and> i \\<inter> b \\<inter> I \\<subseteq> pre c1 \\<and> I \\<turnstile> c1 i \\<and> i \\<inter> -b \\<inter> I \\<subseteq> q\"\n  apply (induct rule: ann_hoare_induct, simp_all)\n  apply (auto intro: AnnConseq)\n  done \n     \nlemma AnnAwait'[rule_format]:\n  \"I \\<turnstile> c q \\<longrightarrow> c = AnnAwait (x,r) b c1  \\<longrightarrow>   \n   atom_com c1 \\<and> UNIV \\<parallel>- (r \\<inter> b \\<inter> I) c1 (q \\<union> -I)\"\n  apply (induct rule: ann_hoare_induct, simp_all)\n  apply (auto intro: AnnConseq Conseq)\n  done\n\nlemma parallel_conseq_combine_aux':\n  \"\\<lbrakk>same_ann_program_assn_com ac ac'; x \\<in> pre ac; x \\<in> pre ac'\\<rbrakk>\n    \\<Longrightarrow> x \\<in> pre (combine_pres_assn_com ac ac')\"\n   by (induct ac ac' rule: combine_pres_assn_com.induct) auto\n\nlemma parallel_conseq_combine_aux:\n  \"\\<lbrakk>\\<forall>n<length Ts'. same_ann_prog_aux (Ts ! n) (Ts' ! n); p \\<subseteq> p'; p \\<subseteq> p'';\n    p' \\<subseteq> (\\<Inter> i\\<in>{i. i<length Ts'}. pre (the (OG_Hoare.com (Ts ! i)))) \\<union> -I;\n    p'' \\<subseteq> (\\<Inter> i\\<in>{i. i<length Ts'}. pre (the (OG_Hoare.com (Ts' ! i)))) \\<union> -I\\<rbrakk>\n   \\<Longrightarrow> p \\<subseteq> (\\<Inter>i\\<in>\\<lbrace>\\<acute>op < (length (map (\\<lambda>(x, y). combine_pres_aux x y) (zip Ts Ts')))\\<rbrace>.\n                 pre (the (OG_Hoare.com (map (\\<lambda>(x, y). combine_pres_aux x y) (zip Ts Ts') ! i)))) \\<union> -I\"\n  by (fastforce elim: same_ann_prog_aux.elims  dest: parallel_conseq_combine_aux')\n \nlemma inter_helper: \n  \"\\<forall>x\\<in>q' \\<inter> q''. x \\<in> q \\<Longrightarrow> x \\<in> q' \\<Longrightarrow> x \\<in> q'' \\<Longrightarrow> x \\<in> q\"\n  by blast\n\n\nlemma parallel_conseq_combine:\n  \"\\<lbrakk>I \\<parallel>- p'\n         Parallel Ts\n         q';\n    I \\<parallel>- p''\n         Parallel Ts'\n         q'';\n    length Ts = length Ts'; list_all (\\<lambda>(x, y). same_ann_prog_aux x y) (zip Ts Ts'); p \\<subseteq> p';\n    p \\<subseteq> p''; q' \\<inter> q'' \\<subseteq> q;\n    I \\<parallel>- ((\\<Inter> i\\<in>{i. i<length (map (\\<lambda>(x, y). combine_pres_aux x y) (zip Ts Ts'))}.\n            pre (the (OG_Hoare.com (map (\\<lambda>(x, y). combine_pres_aux x y) (zip Ts Ts') ! i)))) \\<union> -I)\n    Parallel (map (\\<lambda>(x, y). combine_pres_aux x y) (zip Ts Ts'))\n    (\\<Inter> i\\<in>{i. i<length (map (\\<lambda>(x, y). combine_pres_aux x y) (zip Ts Ts'))}.\n         OG_Hoare.post (map (\\<lambda>(x, y). combine_pres_aux x y) (zip Ts Ts') ! i))\\<rbrakk>\n   \\<Longrightarrow> I \\<parallel>- p\n           Parallel (map (\\<lambda>(x, y). combine_pres_aux x y) (zip Ts Ts'))\n           q\"\n  apply (drule Parallel', fastforce)\n  apply (drule Parallel', fastforce)\n  apply (clarsimp simp: list_all_length)\n  apply (rule ParallelConseqRule)\n    apply (erule (4) parallel_conseq_combine_aux)\n   apply (erule Conseq[rotated])\n    apply clarsimp\n   apply clarsimp\n  apply (clarsimp simp: subset_eq)\n  by (erule inter_helper; (erule bspec, fastforce elim: same_ann_prog_aux.elims))\n\nlemma cruft_compose:\n  assumes valid': \"I \\<parallel>- p' c' q'\"\n  and valid'': \"I \\<parallel>- p'' c'' q''\"\n  and same: \"same_ann_prog_com c' c''\"\n  and combine: \"c = combine_pres_com c' c''\"\n  and conseq: \"p \\<subseteq> p' \\<inter> p''\\<and> q' \\<inter> q'' \\<subseteq> q\"j\n  shows \"I \\<parallel>- p c q\"\nusing assms\nproof (induct c' c'' arbitrary: p p' p'' c q q' q'' rule: same_ann_prog_com.induct)\n  case 1 then show ?case\n    apply clarsimp\n    apply (frule Parallel', fastforce)\n    apply (erule (6) parallel_conseq_combine)\n    apply (drule Parallel', fastforce)\n    apply (rule ParallelRule)\napply clarsimp\n     apply (clarsimp simp: map_ann_hoare_def)\n  oops (*\nnext\n  case 2 then show ?case\n    apply clarsimp\n    apply (drule Basic', fastforce)\n    apply (drule Basic', fastforce)\n    apply (rule BasicRule)\n    apply force\n  done\nnext\n  case 3 then show ?case\n    apply clarsimp\n    apply (drule Seq', fastforce)\n    apply (drule Seq', fastforce)\n    apply clarsimp\n    apply (rule_tac r=\"r \\<inter> ra\" in SeqRule)\n     apply force\n    apply (rule 3(2), force+)\n  done\nnext\n  case 4 then show ?case\n    apply clarsimp\n    apply (drule Cond', fastforce)\n    apply (drule Cond', fastforce)\n    apply clarsimp\n    apply (rule Conseq[OF _ Cond subset_refl])\n      apply force\n     apply (rule 4(1), force+)[1]\n    apply (rule 4(2), force+)[1]\n  done\nnext\n  case 5 then show ?case\n    apply clarsimp\n    apply (drule While', fastforce)\n    apply (drule While', fastforce)\n    apply clarsimp\n    apply (rule_tac p=\"p' \\<inter> p'aa\" in Conseq[OF _ While _])\n      apply force\n     apply (rule 5(1), force+)[1]\n    apply force\n  done\nnext\nqed simp_all*)\n\nend\n", "meta": {"author": "echronos", "repo": "echronos-proofs", "sha": "5983821e591c6878f1fe96aa831e11c5c97ce385", "save_path": "github-repos/isabelle/echronos-echronos-proofs", "path": "github-repos/isabelle/echronos-echronos-proofs/echronos-proofs-5983821e591c6878f1fe96aa831e11c5c97ce385/verif/OG_More.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5774953651858118, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.2977681115275404}}
{"text": "(*  Title:      Jinja/Compiler/TypeComp.thy\n\n    Author:     Tobias Nipkow\n    Copyright   TUM 2003\n*)\n\nsection \\<open>Preservation of Well-Typedness\\<close>\n\ntheory TypeComp\nimports Compiler \"../BV/BVSpec\"\nbegin\n\n(*<*)\ndeclare nth_append[simp]\n(*>*)\n\nlocale TC0 =\n  fixes P :: \"J\\<^sub>1_prog\" and mxl :: nat\nbegin\n\ndefinition \"ty E e = (THE T. P,E \\<turnstile>\\<^sub>1 e :: T)\"\n\ndefinition \"ty\\<^sub>l E A' = map (\\<lambda>i. if i \\<in> A' \\<and> i < size E then OK(E!i) else Err) [0..<mxl]\"\n\ndefinition \"ty\\<^sub>i' ST E A = (case A of None \\<Rightarrow> None | \\<lfloor>A'\\<rfloor> \\<Rightarrow> Some(ST, ty\\<^sub>l E A'))\"\n\ndefinition \"after E A ST e = ty\\<^sub>i' (ty E e # ST) E (A \\<squnion> \\<A> e)\"\n\nend\n\nlemma (in TC0) ty_def2 [simp]: \"P,E \\<turnstile>\\<^sub>1 e :: T \\<Longrightarrow> ty E e = T\"\n(*<*)\napply (unfold ty_def)\napply(blast intro: the_equality WT\\<^sub>1_unique)\ndone\n(*>*)\n\nlemma (in TC0) [simp]: \"ty\\<^sub>i' ST E None = None\"\n(*<*)by (simp add: ty\\<^sub>i'_def)(*>*)\n\nlemma (in TC0) ty\\<^sub>l_app_diff[simp]:\n \"ty\\<^sub>l (E@[T]) (A - {size E}) = ty\\<^sub>l E A\"\n(*<*)by(auto simp add:ty\\<^sub>l_def hyperset_defs)(*>*)\n\n\nlemma (in TC0) ty\\<^sub>i'_app_diff[simp]:\n \"ty\\<^sub>i' ST (E @ [T]) (A \\<ominus> size E) = ty\\<^sub>i' ST E A\"\n(*<*)by(auto simp add:ty\\<^sub>i'_def hyperset_defs)(*>*)\n\n\nlemma (in TC0) ty\\<^sub>l_antimono:\n \"A \\<subseteq> A' \\<Longrightarrow> P \\<turnstile> ty\\<^sub>l E A' [\\<le>\\<^sub>\\<top>] ty\\<^sub>l E A\"\n(*<*)by(auto simp:ty\\<^sub>l_def list_all2_conv_all_nth)(*>*)\n\n\nlemma (in TC0) ty\\<^sub>i'_antimono:\n \"A \\<subseteq> A' \\<Longrightarrow> P \\<turnstile> ty\\<^sub>i' ST E \\<lfloor>A'\\<rfloor> \\<le>' ty\\<^sub>i' ST E \\<lfloor>A\\<rfloor>\"\n(*<*)by(auto simp:ty\\<^sub>i'_def ty\\<^sub>l_def list_all2_conv_all_nth)(*>*)\n\n\nlemma (in TC0) ty\\<^sub>l_env_antimono:\n \"P \\<turnstile> ty\\<^sub>l (E@[T]) A [\\<le>\\<^sub>\\<top>] ty\\<^sub>l E A\" \n(*<*)by(auto simp:ty\\<^sub>l_def list_all2_conv_all_nth)(*>*)\n\n\nlemma (in TC0) ty\\<^sub>i'_env_antimono:\n \"P \\<turnstile> ty\\<^sub>i' ST (E@[T]) A \\<le>' ty\\<^sub>i' ST E A\" \n(*<*)by(auto simp:ty\\<^sub>i'_def ty\\<^sub>l_def list_all2_conv_all_nth)(*>*)\n\n\nlemma (in TC0) ty\\<^sub>i'_incr:\n \"P \\<turnstile> ty\\<^sub>i' ST (E @ [T]) \\<lfloor>insert (size E) A\\<rfloor> \\<le>' ty\\<^sub>i' ST E \\<lfloor>A\\<rfloor>\"\n(*<*)by(auto simp:ty\\<^sub>i'_def ty\\<^sub>l_def list_all2_conv_all_nth)(*>*)\n\n\nlemma (in TC0) ty\\<^sub>l_incr:\n \"P \\<turnstile> ty\\<^sub>l (E @ [T]) (insert (size E) A) [\\<le>\\<^sub>\\<top>] ty\\<^sub>l E A\"\n(*<*)by(auto simp: hyperset_defs ty\\<^sub>l_def list_all2_conv_all_nth)(*>*)\n\n\nlemma (in TC0) ty\\<^sub>l_in_types:\n \"set E \\<subseteq> types P \\<Longrightarrow> ty\\<^sub>l E A \\<in> list mxl (err (types P))\"\n(*<*)by(auto simp add:ty\\<^sub>l_def intro!:listI dest!: nth_mem)(*>*)\n\nlocale TC1 = TC0\nbegin\n\nprimrec compT :: \"ty list \\<Rightarrow> nat hyperset \\<Rightarrow> ty list \\<Rightarrow> expr\\<^sub>1 \\<Rightarrow> ty\\<^sub>i' list\" and\n   compTs :: \"ty list \\<Rightarrow> nat hyperset \\<Rightarrow> ty list \\<Rightarrow> expr\\<^sub>1 list \\<Rightarrow> ty\\<^sub>i' list\" where\n\"compT E A ST (new C) = []\"\n| \"compT E A ST (Cast C e) =  \n   compT E A ST e @ [after E A ST e]\"\n| \"compT E A ST (Val v) = []\"\n| \"compT E A ST (e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2) =\n  (let ST\\<^sub>1 = ty E e\\<^sub>1#ST; A\\<^sub>1 = A \\<squnion> \\<A> e\\<^sub>1 in\n   compT E A ST e\\<^sub>1 @ [after E A ST e\\<^sub>1] @\n   compT E A\\<^sub>1 ST\\<^sub>1 e\\<^sub>2 @ [after E A\\<^sub>1 ST\\<^sub>1 e\\<^sub>2])\"\n| \"compT E A ST (Var i) = []\"\n| \"compT E A ST (i := e) = compT E A ST e @\n   [after E A ST e, ty\\<^sub>i' ST E (A \\<squnion> \\<A> e \\<squnion> \\<lfloor>{i}\\<rfloor>)]\"\n| \"compT E A ST (e\\<bullet>F{D}) = \n   compT E A ST e @ [after E A ST e]\"\n| \"compT E A ST (e\\<^sub>1\\<bullet>F{D} := e\\<^sub>2) =\n  (let ST\\<^sub>1 = ty   E e\\<^sub>1#ST; A\\<^sub>1 = A \\<squnion> \\<A> e\\<^sub>1; A\\<^sub>2 = A\\<^sub>1 \\<squnion> \\<A> e\\<^sub>2 in\n   compT E A ST e\\<^sub>1 @ [after E A ST e\\<^sub>1] @\n   compT E A\\<^sub>1 ST\\<^sub>1 e\\<^sub>2 @ [after E A\\<^sub>1 ST\\<^sub>1 e\\<^sub>2] @\n   [ty\\<^sub>i' ST E A\\<^sub>2])\"\n| \"compT E A ST {i:T; e} = compT (E@[T]) (A\\<ominus>i) ST e\"\n| \"compT E A ST (e\\<^sub>1;;e\\<^sub>2) =\n  (let A\\<^sub>1 = A \\<squnion> \\<A> e\\<^sub>1 in\n   compT E A ST e\\<^sub>1 @ [after E A ST e\\<^sub>1, ty\\<^sub>i' ST E A\\<^sub>1] @\n   compT E A\\<^sub>1 ST e\\<^sub>2)\"\n| \"compT E A ST (if (e) e\\<^sub>1 else e\\<^sub>2) =\n   (let A\\<^sub>0 = A \\<squnion> \\<A> e; \\<tau> = ty\\<^sub>i' ST E A\\<^sub>0 in\n    compT E A ST e @ [after E A ST e, \\<tau>] @\n    compT E A\\<^sub>0 ST e\\<^sub>1 @ [after E A\\<^sub>0 ST e\\<^sub>1, \\<tau>] @\n    compT E A\\<^sub>0 ST e\\<^sub>2)\"\n| \"compT E A ST (while (e) c) =\n   (let A\\<^sub>0 = A \\<squnion> \\<A> e;  A\\<^sub>1 = A\\<^sub>0 \\<squnion> \\<A> c; \\<tau> = ty\\<^sub>i' ST E A\\<^sub>0 in\n    compT E A ST e @ [after E A ST e, \\<tau>] @\n    compT E A\\<^sub>0 ST c @ [after E A\\<^sub>0 ST c, ty\\<^sub>i' ST E A\\<^sub>1, ty\\<^sub>i' ST E A\\<^sub>0])\"\n| \"compT E A ST (throw e) = compT E A ST e @ [after E A ST e]\"\n| \"compT E A ST (e\\<bullet>M(es)) =\n   compT E A ST e @ [after E A ST e] @\n   compTs E (A \\<squnion> \\<A> e) (ty   E e # ST) es\"\n| \"compT E A ST (try e\\<^sub>1 catch(C i) e\\<^sub>2) =\n   compT E A ST e\\<^sub>1 @ [after E A ST e\\<^sub>1] @\n   [ty\\<^sub>i' (Class C#ST) E A, ty\\<^sub>i' ST (E@[Class C]) (A \\<squnion> \\<lfloor>{i}\\<rfloor>)] @\n   compT (E@[Class C]) (A \\<squnion> \\<lfloor>{i}\\<rfloor>) ST e\\<^sub>2\"\n| \"compTs E A ST [] = []\"\n| \"compTs  E A ST (e#es) = compT E A ST e @ [after E A ST e] @\n                            compTs E (A \\<squnion> (\\<A> e)) (ty E e # ST) es\"\n\ndefinition compT\\<^sub>a :: \"ty list \\<Rightarrow> nat hyperset \\<Rightarrow> ty list \\<Rightarrow> expr\\<^sub>1 \\<Rightarrow> ty\\<^sub>i' list\" where\n  \"compT\\<^sub>a E A ST e = compT E A ST e @ [after E A ST e]\"\n\nend\n\nlemma compE\\<^sub>2_not_Nil[simp]: \"compE\\<^sub>2 e \\<noteq> []\"\n(*<*)by(induct e) auto(*>*)\n\nlemma (in TC1) compT_sizes[simp]:\nshows \"\\<And>E A ST. size(compT E A ST e) = size(compE\\<^sub>2 e) - 1\"\nand \"\\<And>E A ST. size(compTs E A ST es) = size(compEs\\<^sub>2 es)\"\n(*<*)\napply(induct e and es rule: compE\\<^sub>2.induct compEs\\<^sub>2.induct)\napply(auto split:bop.splits nat_diff_split)\ndone\n(*>*)\n\n\nlemma (in TC1) [simp]: \"\\<And>ST E. \\<lfloor>\\<tau>\\<rfloor> \\<notin> set (compT E None ST e)\"\nand [simp]: \"\\<And>ST E. \\<lfloor>\\<tau>\\<rfloor> \\<notin> set (compTs E None ST es)\"\n(*<*)by(induct e and es rule: compT.induct compTs.induct) (simp_all add:after_def)(*>*)\n\n\nlemma (in TC0) pair_eq_ty\\<^sub>i'_conv:\n  \"(\\<lfloor>(ST, LT)\\<rfloor> = ty\\<^sub>i' ST\\<^sub>0 E A) =\n  (case A of None \\<Rightarrow> False | Some A \\<Rightarrow> (ST = ST\\<^sub>0 \\<and> LT = ty\\<^sub>l E A))\"\n(*<*)by(simp add:ty\\<^sub>i'_def)(*>*)\n\n\nlemma (in TC0) pair_conv_ty\\<^sub>i':\n  \"\\<lfloor>(ST, ty\\<^sub>l E A)\\<rfloor> = ty\\<^sub>i' ST E \\<lfloor>A\\<rfloor>\"\n(*<*)by(simp add:ty\\<^sub>i'_def)(*>*)\n\n(*<*)\ndeclare (in TC0)\n  ty\\<^sub>i'_antimono [intro!] after_def[simp]\n  pair_conv_ty\\<^sub>i'[simp] pair_eq_ty\\<^sub>i'_conv[simp]\n(*>*)\n\n\nlemma (in TC1) compT_LT_prefix:\n \"\\<And>E A ST\\<^sub>0. \\<lbrakk> \\<lfloor>(ST,LT)\\<rfloor> \\<in> set(compT E A ST\\<^sub>0 e); \\<B> e (size E) \\<rbrakk>\n               \\<Longrightarrow> P \\<turnstile> \\<lfloor>(ST,LT)\\<rfloor> \\<le>' ty\\<^sub>i' ST E A\"\nand\n \"\\<And>E A ST\\<^sub>0. \\<lbrakk> \\<lfloor>(ST,LT)\\<rfloor> \\<in> set(compTs E A ST\\<^sub>0 es); \\<B>s es (size E) \\<rbrakk>\n               \\<Longrightarrow> P \\<turnstile> \\<lfloor>(ST,LT)\\<rfloor> \\<le>' ty\\<^sub>i' ST E A\"\n(*<*)\nproof(induct e and es rule: compT.induct compTs.induct)\n  case FAss thus ?case by(fastforce simp:hyperset_defs elim!:sup_state_opt_trans)\nnext\n  case BinOp thus ?case\n    by(fastforce simp:hyperset_defs elim!:sup_state_opt_trans split:bop.splits)\nnext\n  case Seq thus ?case by(fastforce simp:hyperset_defs elim!:sup_state_opt_trans)\nnext\n  case While thus ?case by(fastforce simp:hyperset_defs elim!:sup_state_opt_trans)\nnext\n  case Cond thus ?case by(fastforce simp:hyperset_defs elim!:sup_state_opt_trans)\nnext\n  case Block thus ?case\n    by(force simp add:hyperset_defs ty\\<^sub>i'_def simp del:pair_conv_ty\\<^sub>i'\n             elim!:sup_state_opt_trans)\nnext\n  case Call thus ?case by(fastforce simp:hyperset_defs elim!:sup_state_opt_trans)\nnext\n  case Cons_exp thus ?case\n    by(fastforce simp:hyperset_defs elim!:sup_state_opt_trans)\nnext\n  case TryCatch thus ?case\n    by(fastforce simp:hyperset_defs intro!:(* ty\\<^sub>i'_env_antimono *) ty\\<^sub>i'_incr\n                elim!:sup_state_opt_trans)\nqed (auto simp:hyperset_defs)\n\ndeclare (in TC0)\n  ty\\<^sub>i'_antimono [rule del] after_def[simp del]\n  pair_conv_ty\\<^sub>i'[simp del] pair_eq_ty\\<^sub>i'_conv[simp del]\n(*>*)\n\n\n\n\nlemma (in TC0) after_in_states:\n \"\\<lbrakk> wf_prog p P; P,E \\<turnstile>\\<^sub>1 e :: T; set E \\<subseteq> types P; set ST \\<subseteq> types P;\n    size ST + max_stack e \\<le> mxs \\<rbrakk>\n \\<Longrightarrow> OK (after E A ST e) \\<in> states P mxs mxl\"\n(*<*)\napply(subgoal_tac \"size ST + 1 \\<le> mxs\")\n apply(simp add: after_def ty\\<^sub>i'_def JVM_states_unfold ty\\<^sub>l_in_types)\n apply(blast intro!:listI WT\\<^sub>1_is_type)\nusing max_stack1[of e] apply simp\ndone\n(*>*)\n\n\nlemma (in TC0) OK_ty\\<^sub>i'_in_statesI[simp]:\n  \"\\<lbrakk> set E \\<subseteq> types P; set ST \\<subseteq> types P; size ST \\<le> mxs \\<rbrakk>\n  \\<Longrightarrow> OK (ty\\<^sub>i' ST E A) \\<in> states P mxs mxl\"\n(*<*)\napply(simp add:ty\\<^sub>i'_def JVM_states_unfold ty\\<^sub>l_in_types)\napply(blast intro!:listI)\ndone\n(*>*)\n\n\nlemma is_class_type_aux: \"is_class P C \\<Longrightarrow> is_type P (Class C)\"\n(*<*)by(simp)(*>*)\n\n(*<*)\ndeclare is_type_simps[simp del] subsetI[rule del]\n(*>*)\n\ntheorem (in TC1) compT_states:\nassumes wf: \"wf_prog p P\"\nshows \"\\<And>E T A ST.\n  \\<lbrakk> P,E \\<turnstile>\\<^sub>1 e :: T; set E \\<subseteq> types P; set ST \\<subseteq> types P;\n    size ST + max_stack e \\<le> mxs; size E + max_vars e \\<le> mxl \\<rbrakk>\n  \\<Longrightarrow> OK ` set(compT E A ST e) \\<subseteq> states P mxs mxl\"\n(*<*)(is \"\\<And>E T A ST. PROP ?P e E T A ST\")(*>*)\n\nand \"\\<And>E Ts A ST.\n  \\<lbrakk> P,E \\<turnstile>\\<^sub>1 es[::]Ts;  set E \\<subseteq> types P; set ST \\<subseteq> types P;\n    size ST + max_stacks es \\<le> mxs; size E + max_varss es \\<le> mxl \\<rbrakk>\n  \\<Longrightarrow> OK ` set(compTs E A ST es) \\<subseteq> states P mxs mxl\"\n(*<*)(is \"\\<And>E Ts A ST. PROP ?Ps es E Ts A ST\")\nproof(induct e and es rule: compT.induct compTs.induct)\n  case new thus ?case by(simp)\nnext\n  case (Cast C e) thus ?case by (auto simp:after_in_states[OF wf])\nnext\n  case Val thus  ?case by(simp)\nnext\n  case Var thus ?case by(simp)\nnext\n  case LAss thus ?case  by(auto simp:after_in_states[OF wf])\nnext\n  case FAcc thus ?case by(auto simp:after_in_states[OF wf])\nnext\n  case FAss thus ?case\n    by(auto simp:image_Un WT\\<^sub>1_is_type[OF wf] after_in_states[OF wf])\nnext\n  case Seq thus ?case\n    by(auto simp:image_Un after_in_states[OF wf])\nnext\n  case BinOp thus ?case\n    by(auto simp:image_Un WT\\<^sub>1_is_type[OF wf] after_in_states[OF wf])\nnext\n  case Cond thus ?case\n    by(force simp:image_Un WT\\<^sub>1_is_type[OF wf] after_in_states[OF wf])\nnext\n  case While thus ?case\n    by(auto simp:image_Un WT\\<^sub>1_is_type[OF wf] after_in_states[OF wf])\nnext\n  case Block thus ?case by(auto)\nnext\n  case (TryCatch e\\<^sub>1 C i e\\<^sub>2)\n  moreover have \"size ST + 1 \\<le> mxs\" using TryCatch.prems max_stack1[of e\\<^sub>1] by auto\n  ultimately show ?case  \n    by(auto simp:image_Un WT\\<^sub>1_is_type[OF wf] after_in_states[OF wf]\n                  is_class_type_aux)\nnext\n  case Nil_exp thus ?case by simp\nnext\n  case Cons_exp thus ?case\n    by(auto simp:image_Un  WT\\<^sub>1_is_type[OF wf] after_in_states[OF wf])\nnext\n  case throw thus ?case\n    by(auto simp: WT\\<^sub>1_is_type[OF wf] after_in_states[OF wf])\nnext\n  case Call thus ?case\n    by(auto simp:image_Un WT\\<^sub>1_is_type[OF wf] after_in_states[OF wf])\nqed\n\ndeclare is_type_simps[simp] subsetI[intro!]\n(*>*)\n\n\ndefinition shift :: \"nat \\<Rightarrow> ex_table \\<Rightarrow> ex_table\"\nwhere\n  \"shift n xt \\<equiv> map (\\<lambda>(from,to,C,handler,depth). (from+n,to+n,C,handler+n,depth)) xt\"\n\n\n\n\nlemma [simp]: \"shift n [] = []\"\n(*<*)by(simp add:shift_def)(*>*)\n\nlemma [simp]: \"shift n (xt\\<^sub>1 @ xt\\<^sub>2) = shift n xt\\<^sub>1 @ shift n xt\\<^sub>2\"\n(*<*)by(simp add:shift_def)(*>*)\n\nlemma [simp]: \"shift m (shift n xt) = shift (m+n) xt\"\n(*<*)by(induct xt)(auto simp:shift_def)(*>*)\n\nlemma [simp]: \"pcs (shift n xt) = {pc+n|pc. pc \\<in> pcs xt}\"\n(*<*)\napply(auto simp:shift_def pcs_def)\napply(rule_tac x = \"x-n\" in exI)\napply (force split:nat_diff_split)\ndone\n(*>*)\n\n\nlemma shift_compxE\\<^sub>2:\nshows \"\\<And>pc pc' d. shift pc (compxE\\<^sub>2 e pc' d) = compxE\\<^sub>2 e (pc' + pc) d\"\nand  \"\\<And>pc pc' d. shift pc (compxEs\\<^sub>2 es pc' d) = compxEs\\<^sub>2 es (pc' + pc) d\"\n(*<*)\napply(induct e and es rule: compxE\\<^sub>2.induct compxEs\\<^sub>2.induct)\napply(auto simp:shift_def ac_simps)\ndone\n(*>*)\n\n\nlemma compxE\\<^sub>2_size_convs[simp]:\nshows \"n \\<noteq> 0 \\<Longrightarrow> compxE\\<^sub>2 e n d = shift n (compxE\\<^sub>2 e 0 d)\"\nand \"n \\<noteq> 0 \\<Longrightarrow> compxEs\\<^sub>2 es n d = shift n (compxEs\\<^sub>2 es 0 d)\"\n(*<*)by(simp_all add:shift_compxE\\<^sub>2)(*>*)\n\nlocale TC2 = TC1 +\n  fixes T\\<^sub>r :: ty and mxs :: pc\nbegin\n\ndefinition\n  wt_instrs :: \"instr list \\<Rightarrow> ex_table \\<Rightarrow> ty\\<^sub>i' list \\<Rightarrow> bool\"\n    (\"(\\<turnstile> _, _ /[::]/ _)\" [0,0,51] 50) where\n  \"\\<turnstile> is,xt [::] \\<tau>s \\<longleftrightarrow> size is < size \\<tau>s \\<and> pcs xt \\<subseteq> {0..<size is} \\<and>\n  (\\<forall>pc< size is. P,T\\<^sub>r,mxs,size \\<tau>s,xt \\<turnstile> is!pc,pc :: \\<tau>s)\"\n\nend\n\nnotation TC2.wt_instrs (\"(_,_,_ \\<turnstile>/ _, _ /[::]/ _)\" [50,50,50,50,50,51] 50)\n\n(*<*)\nlemmas (in TC2) wt_defs =\n  wt_instrs_def wt_instr_def app_def eff_def norm_eff_def\n(*>*)\n\nlemma (in TC2) [simp]: \"\\<tau>s \\<noteq> [] \\<Longrightarrow> \\<turnstile> [],[] [::] \\<tau>s\"\n(*<*) by (simp add: wt_defs) (*>*)\n\nlemma [simp]: \"eff i P pc et None = []\"\n(*<*)by (simp add: Effect.eff_def)(*>*)\n\n(*<*)\ndeclare split_comp_eq[simp del]\n(*>*)\n\nlemma wt_instr_appR:\n \"\\<lbrakk> P,T,m,mpc,xt \\<turnstile> is!pc,pc :: \\<tau>s;\n    pc < size is; size is < size \\<tau>s; mpc \\<le> size \\<tau>s; mpc \\<le> mpc' \\<rbrakk>\n  \\<Longrightarrow> P,T,m,mpc',xt \\<turnstile> is!pc,pc :: \\<tau>s@\\<tau>s'\"\n(*<*)by (fastforce simp:wt_instr_def app_def)(*>*)\n\n\nlemma relevant_entries_shift [simp]:\n  \"relevant_entries P i (pc+n) (shift n xt) = shift n (relevant_entries P i pc xt)\"\n(*<*)\n  apply (induct xt)\n  apply (unfold relevant_entries_def shift_def)\n   apply simp\n  apply (auto simp add: is_relevant_entry_def)\n  done\n(*>*)\n\n\nlemma [simp]:\n  \"xcpt_eff i P (pc+n) \\<tau> (shift n xt) =\n   map (\\<lambda>(pc,\\<tau>). (pc + n, \\<tau>)) (xcpt_eff i P pc \\<tau> xt)\"\n(*<*)\napply(simp add: xcpt_eff_def)\napply(cases \\<tau>)\napply(auto simp add: shift_def)\ndone\n(*>*)\n\n\nlemma  [simp]:\n  \"app\\<^sub>i (i, P, pc, m, T, \\<tau>) \\<Longrightarrow>\n   eff i P (pc+n) (shift n xt) (Some \\<tau>) =\n   map (\\<lambda>(pc,\\<tau>). (pc+n,\\<tau>)) (eff i P pc xt (Some \\<tau>))\"\n(*<*)\napply(simp add:eff_def norm_eff_def)\napply(cases \"i\",auto)\ndone\n(*>*)\n\n\nlemma [simp]:\n  \"xcpt_app i P (pc+n) mxs (shift n xt) \\<tau> = xcpt_app i P pc mxs xt \\<tau>\"\n(*<*)by (simp add: xcpt_app_def) (auto simp add: shift_def)(*>*)\n\n\nlemma wt_instr_appL:\n  \"\\<lbrakk> P,T,m,mpc,xt \\<turnstile> i,pc :: \\<tau>s; pc < size \\<tau>s; mpc \\<le> size \\<tau>s \\<rbrakk>\n  \\<Longrightarrow> P,T,m,mpc + size \\<tau>s',shift (size \\<tau>s') xt \\<turnstile> i,pc+size \\<tau>s' :: \\<tau>s'@\\<tau>s\"\n(*<*)\napply(auto simp:wt_instr_def app_def)\nprefer 2 apply(fast)\nprefer 2 apply(fast)\napply(cases \"i\",auto)\ndone\n(*>*)\n\n\nlemma wt_instr_Cons:\n  \"\\<lbrakk> P,T,m,mpc - 1,[] \\<turnstile> i,pc - 1 :: \\<tau>s;\n     0 < pc; 0 < mpc; pc < size \\<tau>s + 1; mpc \\<le> size \\<tau>s + 1 \\<rbrakk>\n  \\<Longrightarrow> P,T,m,mpc,[] \\<turnstile> i,pc :: \\<tau>#\\<tau>s\"\n(*<*)\napply(drule wt_instr_appL[where \\<tau>s' = \"[\\<tau>]\"])\napply arith\napply arith\napply (simp split:nat_diff_split_asm)\ndone\n(*>*)\n\n\nlemma wt_instr_append:\n  \"\\<lbrakk> P,T,m,mpc - size \\<tau>s',[] \\<turnstile> i,pc - size \\<tau>s' :: \\<tau>s;\n     size \\<tau>s' \\<le> pc; size \\<tau>s' \\<le> mpc; pc < size \\<tau>s + size \\<tau>s'; mpc \\<le> size \\<tau>s + size \\<tau>s' \\<rbrakk>\n  \\<Longrightarrow> P,T,m,mpc,[] \\<turnstile> i,pc :: \\<tau>s'@\\<tau>s\"\n(*<*)\napply(drule wt_instr_appL[where \\<tau>s' = \\<tau>s'])\napply arith\napply arith\napply (simp split:nat_diff_split_asm)\ndone\n(*>*)\n\n\nlemma xcpt_app_pcs:\n  \"pc \\<notin> pcs xt \\<Longrightarrow> xcpt_app i P pc mxs xt \\<tau>\"\n(*<*)\nby (auto simp add: xcpt_app_def relevant_entries_def is_relevant_entry_def pcs_def)\n(*>*)\n\n\nlemma xcpt_eff_pcs:\n  \"pc \\<notin> pcs xt \\<Longrightarrow> xcpt_eff i P pc \\<tau> xt = []\"\n(*<*)\nby (cases \\<tau>)\n   (auto simp add: is_relevant_entry_def xcpt_eff_def relevant_entries_def pcs_def\n           intro!: filter_False)\n(*>*)\n\n\nlemma pcs_shift:\n  \"pc < n \\<Longrightarrow> pc \\<notin> pcs (shift n xt)\" \n(*<*)by (auto simp add: shift_def pcs_def)(*>*)\n\n\nlemma wt_instr_appRx:\n  \"\\<lbrakk> P,T,m,mpc,xt \\<turnstile> is!pc,pc :: \\<tau>s; pc < size is; size is < size \\<tau>s; mpc \\<le> size \\<tau>s \\<rbrakk>\n  \\<Longrightarrow> P,T,m,mpc,xt @ shift (size is) xt' \\<turnstile> is!pc,pc :: \\<tau>s\"\n(*<*)by (auto simp:wt_instr_def eff_def app_def xcpt_app_pcs xcpt_eff_pcs)(*>*)\n\n\nlemma wt_instr_appLx: \n  \"\\<lbrakk> P,T,m,mpc,xt \\<turnstile> i,pc :: \\<tau>s; pc \\<notin> pcs xt' \\<rbrakk>\n  \\<Longrightarrow> P,T,m,mpc,xt'@xt \\<turnstile> i,pc :: \\<tau>s\"\n(*<*)by (auto simp:wt_instr_def app_def eff_def xcpt_app_pcs xcpt_eff_pcs)(*>*)\n\n\nlemma (in TC2) wt_instrs_extR:\n  \"\\<turnstile> is,xt [::] \\<tau>s \\<Longrightarrow> \\<turnstile> is,xt [::] \\<tau>s @ \\<tau>s'\"\n(*<*)by(auto simp add:wt_instrs_def wt_instr_appR)(*>*)\n\n\nlemma (in TC2) wt_instrs_ext:\n  \"\\<lbrakk> \\<turnstile> is\\<^sub>1,xt\\<^sub>1 [::] \\<tau>s\\<^sub>1@\\<tau>s\\<^sub>2; \\<turnstile> is\\<^sub>2,xt\\<^sub>2 [::] \\<tau>s\\<^sub>2; size \\<tau>s\\<^sub>1 = size is\\<^sub>1 \\<rbrakk>\n  \\<Longrightarrow> \\<turnstile> is\\<^sub>1@is\\<^sub>2, xt\\<^sub>1 @ shift (size is\\<^sub>1) xt\\<^sub>2 [::] \\<tau>s\\<^sub>1@\\<tau>s\\<^sub>2\"\n(*<*)\napply(clarsimp simp:wt_instrs_def)\napply(rule conjI, fastforce)\napply(rule conjI, fastforce)\napply clarsimp\napply(rule conjI, fastforce simp:wt_instr_appRx)\napply clarsimp\napply(erule_tac x = \"pc - size is\\<^sub>1\" in allE)+\napply(thin_tac \"P \\<longrightarrow> Q\" for P Q)\napply(erule impE, arith) \napply(drule_tac \\<tau>s' = \"\\<tau>s\\<^sub>1\" in wt_instr_appL)\n  apply arith\n apply simp\napply(fastforce simp add:add.commute intro!: wt_instr_appLx)\ndone\n(*>*)\n\ncorollary (in TC2) wt_instrs_ext2:\n  \"\\<lbrakk> \\<turnstile> is\\<^sub>2,xt\\<^sub>2 [::] \\<tau>s\\<^sub>2; \\<turnstile> is\\<^sub>1,xt\\<^sub>1 [::] \\<tau>s\\<^sub>1@\\<tau>s\\<^sub>2; size \\<tau>s\\<^sub>1 = size is\\<^sub>1 \\<rbrakk>\n  \\<Longrightarrow> \\<turnstile> is\\<^sub>1@is\\<^sub>2, xt\\<^sub>1 @ shift (size is\\<^sub>1) xt\\<^sub>2 [::] \\<tau>s\\<^sub>1@\\<tau>s\\<^sub>2\"\n(*<*)by(rule wt_instrs_ext)(*>*)\n\n\ncorollary (in TC2) wt_instrs_ext_prefix [trans]:\n  \"\\<lbrakk> \\<turnstile> is\\<^sub>1,xt\\<^sub>1 [::] \\<tau>s\\<^sub>1@\\<tau>s\\<^sub>2; \\<turnstile> is\\<^sub>2,xt\\<^sub>2 [::] \\<tau>s\\<^sub>3;\n     size \\<tau>s\\<^sub>1 = size is\\<^sub>1; prefix \\<tau>s\\<^sub>3 \\<tau>s\\<^sub>2 \\<rbrakk>\n  \\<Longrightarrow> \\<turnstile> is\\<^sub>1@is\\<^sub>2, xt\\<^sub>1 @ shift (size is\\<^sub>1) xt\\<^sub>2 [::] \\<tau>s\\<^sub>1@\\<tau>s\\<^sub>2\"\n(*<*)by(bestsimp simp:prefix_def elim: wt_instrs_ext dest:wt_instrs_extR)(*>*)\n\n\ncorollary (in TC2) wt_instrs_app:\n  assumes is\\<^sub>1: \"\\<turnstile> is\\<^sub>1,xt\\<^sub>1 [::] \\<tau>s\\<^sub>1@[\\<tau>]\"\n  assumes is\\<^sub>2: \"\\<turnstile> is\\<^sub>2,xt\\<^sub>2 [::] \\<tau>#\\<tau>s\\<^sub>2\"\n  assumes s: \"size \\<tau>s\\<^sub>1 = size is\\<^sub>1\"\n  shows \"\\<turnstile> is\\<^sub>1@is\\<^sub>2, xt\\<^sub>1@shift (size is\\<^sub>1) xt\\<^sub>2 [::] \\<tau>s\\<^sub>1@\\<tau>#\\<tau>s\\<^sub>2\"\n(*<*)\nproof -\n  from is\\<^sub>1 have \"\\<turnstile> is\\<^sub>1,xt\\<^sub>1 [::] (\\<tau>s\\<^sub>1@[\\<tau>])@\\<tau>s\\<^sub>2\"\n    by (rule wt_instrs_extR)\n  hence \"\\<turnstile> is\\<^sub>1,xt\\<^sub>1 [::] \\<tau>s\\<^sub>1@\\<tau>#\\<tau>s\\<^sub>2\" by simp\n  from this is\\<^sub>2 s show ?thesis by (rule wt_instrs_ext) \nqed\n(*>*)\n\n\ncorollary (in TC2) wt_instrs_app_last[trans]:\n  \"\\<lbrakk> \\<turnstile> is\\<^sub>2,xt\\<^sub>2 [::] \\<tau>#\\<tau>s\\<^sub>2; \\<turnstile> is\\<^sub>1,xt\\<^sub>1 [::] \\<tau>s\\<^sub>1;\n     last \\<tau>s\\<^sub>1 = \\<tau>;  size \\<tau>s\\<^sub>1 = size is\\<^sub>1+1 \\<rbrakk>\n  \\<Longrightarrow> \\<turnstile> is\\<^sub>1@is\\<^sub>2, xt\\<^sub>1@shift (size is\\<^sub>1) xt\\<^sub>2 [::] \\<tau>s\\<^sub>1@\\<tau>s\\<^sub>2\"\n(*<*)\napply(cases \\<tau>s\\<^sub>1 rule:rev_cases)\n apply simp\napply(simp add:wt_instrs_app)\ndone\n(*>*)\n\n\ncorollary (in TC2) wt_instrs_append_last[trans]:\n  \"\\<lbrakk> \\<turnstile> is,xt [::] \\<tau>s; P,T\\<^sub>r,mxs,mpc,[] \\<turnstile> i,pc :: \\<tau>s;\n     pc = size is; mpc = size \\<tau>s; size is + 1 < size \\<tau>s \\<rbrakk>\n  \\<Longrightarrow> \\<turnstile> is@[i],xt [::] \\<tau>s\"\n(*<*)\napply(clarsimp simp add:wt_instrs_def)\napply(rule conjI, fastforce)\napply(fastforce intro!:wt_instr_appLx[where xt = \"[]\",simplified]\n               dest!:less_antisym)\ndone\n(*>*)\n\n\ncorollary (in TC2) wt_instrs_app2:\n  \"\\<lbrakk> \\<turnstile> is\\<^sub>2,xt\\<^sub>2 [::] \\<tau>'#\\<tau>s\\<^sub>2;  \\<turnstile> is\\<^sub>1,xt\\<^sub>1 [::] \\<tau>#\\<tau>s\\<^sub>1@[\\<tau>'];\n     xt' = xt\\<^sub>1 @ shift (size is\\<^sub>1) xt\\<^sub>2;  size \\<tau>s\\<^sub>1+1 = size is\\<^sub>1 \\<rbrakk>\n  \\<Longrightarrow> \\<turnstile> is\\<^sub>1@is\\<^sub>2,xt' [::] \\<tau>#\\<tau>s\\<^sub>1@\\<tau>'#\\<tau>s\\<^sub>2\"\n(*<*)using wt_instrs_app[where ?\\<tau>s\\<^sub>1.0 = \"\\<tau> # \\<tau>s\\<^sub>1\"] by simp (*>*)\n\n\ncorollary (in TC2) wt_instrs_app2_simp[trans,simp]:\n  \"\\<lbrakk> \\<turnstile> is\\<^sub>2,xt\\<^sub>2 [::] \\<tau>'#\\<tau>s\\<^sub>2;  \\<turnstile> is\\<^sub>1,xt\\<^sub>1 [::] \\<tau>#\\<tau>s\\<^sub>1@[\\<tau>']; size \\<tau>s\\<^sub>1+1 = size is\\<^sub>1 \\<rbrakk>\n  \\<Longrightarrow> \\<turnstile> is\\<^sub>1@is\\<^sub>2, xt\\<^sub>1@shift (size is\\<^sub>1) xt\\<^sub>2 [::] \\<tau>#\\<tau>s\\<^sub>1@\\<tau>'#\\<tau>s\\<^sub>2\"\n(*<*)using wt_instrs_app[where ?\\<tau>s\\<^sub>1.0 = \"\\<tau> # \\<tau>s\\<^sub>1\"] by simp(*>*)\n\n\ncorollary (in TC2) wt_instrs_Cons[simp]:\n  \"\\<lbrakk> \\<tau>s \\<noteq> []; \\<turnstile> [i],[] [::] [\\<tau>,\\<tau>']; \\<turnstile> is,xt [::] \\<tau>'#\\<tau>s \\<rbrakk>\n  \\<Longrightarrow> \\<turnstile> i#is,shift 1 xt [::] \\<tau>#\\<tau>'#\\<tau>s\"\n(*<*)\nusing wt_instrs_app2[where ?is\\<^sub>1.0 = \"[i]\" and ?\\<tau>s\\<^sub>1.0 = \"[]\" and ?is\\<^sub>2.0 = \"is\"\n                      and ?xt\\<^sub>1.0 = \"[]\"]\nby simp\n\n\ncorollary (in TC2) wt_instrs_Cons2[trans]:\n  assumes \\<tau>s: \"\\<turnstile> is,xt [::] \\<tau>s\"\n  assumes i: \"P,T\\<^sub>r,mxs,mpc,[] \\<turnstile> i,0 :: \\<tau>#\\<tau>s\"\n  assumes mpc: \"mpc = size \\<tau>s + 1\"\n  shows \"\\<turnstile> i#is,shift 1 xt [::] \\<tau>#\\<tau>s\"\n(*<*)\nproof -\n  from \\<tau>s have \"\\<tau>s \\<noteq> []\" by (auto simp: wt_instrs_def)\n  with mpc i have \"\\<turnstile> [i],[] [::] [\\<tau>]@\\<tau>s\" by (simp add: wt_instrs_def)\n  with \\<tau>s show ?thesis by (fastforce dest: wt_instrs_ext)\nqed\n(*>*)\n\n\nlemma (in TC2) wt_instrs_last_incr[trans]:\n  \"\\<lbrakk> \\<turnstile> is,xt [::] \\<tau>s@[\\<tau>]; P \\<turnstile> \\<tau> \\<le>' \\<tau>' \\<rbrakk> \\<Longrightarrow> \\<turnstile> is,xt [::] \\<tau>s@[\\<tau>']\"\n(*<*)\napply(clarsimp simp add:wt_instrs_def wt_instr_def)\napply(rule conjI)\napply(fastforce)\napply(clarsimp)\napply(rename_tac pc' tau')\napply(erule allE, erule (1) impE)\napply(clarsimp)\napply(drule (1) bspec)\napply(clarsimp)\napply(subgoal_tac \"pc' = size \\<tau>s\")\nprefer 2\napply(clarsimp simp:app_def)\napply(drule (1) bspec)\napply(clarsimp)\napply(auto elim!:sup_state_opt_trans)\ndone\n(*>*)\n\n\nlemma [iff]: \"xcpt_app i P pc mxs [] \\<tau>\"\n(*<*)by (simp add: xcpt_app_def relevant_entries_def)(*>*)\n\n\nlemma [simp]: \"xcpt_eff i P pc \\<tau> [] = []\"\n(*<*)by (simp add: xcpt_eff_def relevant_entries_def)(*>*)\n\n\nlemma (in TC2) wt_New:\n  \"\\<lbrakk> is_class P C; size ST < mxs \\<rbrakk> \\<Longrightarrow>\n   \\<turnstile> [New C],[] [::] [ty\\<^sub>i' ST E A, ty\\<^sub>i' (Class C#ST) E A]\"\n(*<*)by(simp add:wt_defs ty\\<^sub>i'_def)(*>*)\n\n\nlemma (in TC2) wt_Cast:\n  \"is_class P C \\<Longrightarrow>\n   \\<turnstile> [Checkcast C],[] [::] [ty\\<^sub>i' (Class D # ST) E A, ty\\<^sub>i' (Class C # ST) E A]\"\n(*<*)by(simp add: ty\\<^sub>i'_def wt_defs)(*>*)\n\n\nlemma (in TC2) wt_Push:\n  \"\\<lbrakk> size ST < mxs; typeof v = Some T \\<rbrakk>\n  \\<Longrightarrow> \\<turnstile> [Push v],[] [::] [ty\\<^sub>i' ST E A, ty\\<^sub>i' (T#ST) E A]\"\n(*<*)by(simp add: ty\\<^sub>i'_def wt_defs)(*>*)\n\n\nlemma (in TC2) wt_Pop:\n \"\\<turnstile> [Pop],[] [::] (ty\\<^sub>i' (T#ST) E A # ty\\<^sub>i' ST E A # \\<tau>s)\"\n(*<*)by(simp add: ty\\<^sub>i'_def wt_defs)(*>*)\n\n\nlemma (in TC2) wt_CmpEq:\n  \"\\<lbrakk> P \\<turnstile> T\\<^sub>1 \\<le> T\\<^sub>2 \\<or> P \\<turnstile> T\\<^sub>2 \\<le> T\\<^sub>1\\<rbrakk>\n  \\<Longrightarrow> \\<turnstile> [CmpEq],[] [::] [ty\\<^sub>i' (T\\<^sub>2 # T\\<^sub>1 # ST) E A, ty\\<^sub>i' (Boolean # ST) E A]\"\n(*<*) by(auto simp:ty\\<^sub>i'_def wt_defs elim!: refTE not_refTE) (*>*)\n\n\nlemma (in TC2) wt_IAdd:\n  \"\\<turnstile> [IAdd],[] [::] [ty\\<^sub>i' (Integer#Integer#ST) E A, ty\\<^sub>i' (Integer#ST) E A]\"\n(*<*)by(simp add:ty\\<^sub>i'_def wt_defs)(*>*)\n\n\nlemma (in TC2) wt_Load:\n  \"\\<lbrakk> size ST < mxs; size E \\<le> mxl; i \\<in>\\<in> A; i < size E \\<rbrakk>\n  \\<Longrightarrow> \\<turnstile> [Load i],[] [::] [ty\\<^sub>i' ST E A, ty\\<^sub>i' (E!i # ST) E A]\"\n(*<*)by(auto simp add:ty\\<^sub>i'_def wt_defs ty\\<^sub>l_def hyperset_defs)(*>*)\n\n\nlemma (in TC2) wt_Store:\n \"\\<lbrakk> P \\<turnstile> T \\<le> E!i; i < size E; size E \\<le> mxl \\<rbrakk> \\<Longrightarrow>\n  \\<turnstile> [Store i],[] [::] [ty\\<^sub>i' (T#ST) E A, ty\\<^sub>i' ST E (\\<lfloor>{i}\\<rfloor> \\<squnion> A)]\"\n(*<*)\nby(auto simp:hyperset_defs nth_list_update ty\\<^sub>i'_def wt_defs ty\\<^sub>l_def\n        intro:list_all2_all_nthI)\n(*>*)\n\n\nlemma (in TC2) wt_Get:\n \"\\<lbrakk> P \\<turnstile> C sees F:T in D \\<rbrakk> \\<Longrightarrow>\n  \\<turnstile> [Getfield F D],[] [::] [ty\\<^sub>i' (Class C # ST) E A, ty\\<^sub>i' (T # ST) E A]\"\n(*<*)by(auto simp: ty\\<^sub>i'_def wt_defs dest: sees_field_idemp sees_field_decl_above)(*>*)\n\n\nlemma (in TC2) wt_Put:\n  \"\\<lbrakk> P \\<turnstile> C sees F:T in D; P \\<turnstile> T' \\<le> T \\<rbrakk> \\<Longrightarrow>\n  \\<turnstile> [Putfield F D],[] [::] [ty\\<^sub>i' (T' # Class C # ST) E A, ty\\<^sub>i' ST E A]\"\n(*<*)by(auto intro: sees_field_idemp sees_field_decl_above simp: ty\\<^sub>i'_def wt_defs)(*>*)\n\n\nlemma (in TC2) wt_Throw:\n  \"\\<turnstile> [Throw],[] [::] [ty\\<^sub>i' (Class C # ST) E A, \\<tau>']\"\n(*<*)by(auto simp: ty\\<^sub>i'_def wt_defs)(*>*)\n\n\nlemma (in TC2) wt_IfFalse:\n  \"\\<lbrakk> 2 \\<le> i; nat i < size \\<tau>s + 2; P \\<turnstile> ty\\<^sub>i' ST E A \\<le>' \\<tau>s ! nat(i - 2) \\<rbrakk>\n  \\<Longrightarrow> \\<turnstile> [IfFalse i],[] [::] ty\\<^sub>i' (Boolean # ST) E A # ty\\<^sub>i' ST E A # \\<tau>s\"\n(*<*)\nby(simp add: ty\\<^sub>i'_def wt_defs eval_nat_numeral nat_diff_distrib)\n(*>*)\n\n\nlemma wt_Goto:\n \"\\<lbrakk> 0 \\<le> int pc + i; nat (int pc + i) < size \\<tau>s; size \\<tau>s \\<le> mpc;\n    P \\<turnstile> \\<tau>s!pc \\<le>' \\<tau>s ! nat (int pc + i) \\<rbrakk>\n \\<Longrightarrow> P,T,mxs,mpc,[] \\<turnstile> Goto i,pc :: \\<tau>s\"\n(*<*)by(clarsimp simp add: TC2.wt_defs)(*>*)\n\n\nlemma (in TC2) wt_Invoke:\n  \"\\<lbrakk> size es = size Ts'; P \\<turnstile> C sees M: Ts\\<rightarrow>T = m in D; P \\<turnstile> Ts' [\\<le>] Ts \\<rbrakk>\n  \\<Longrightarrow> \\<turnstile> [Invoke M (size es)],[] [::] [ty\\<^sub>i' (rev Ts' @ Class C # ST) E A, ty\\<^sub>i' (T#ST) E A]\"\n(*<*)by(fastforce simp add: ty\\<^sub>i'_def wt_defs)(*>*)\n\n\ncorollary (in TC2) wt_instrs_app3[simp]:\n  \"\\<lbrakk> \\<turnstile> is\\<^sub>2,[] [::] (\\<tau>' # \\<tau>s\\<^sub>2);  \\<turnstile> is\\<^sub>1,xt\\<^sub>1 [::] \\<tau> # \\<tau>s\\<^sub>1 @ [\\<tau>']; size \\<tau>s\\<^sub>1+1 = size is\\<^sub>1\\<rbrakk>\n  \\<Longrightarrow> \\<turnstile> (is\\<^sub>1 @ is\\<^sub>2),xt\\<^sub>1 [::] \\<tau> # \\<tau>s\\<^sub>1 @ \\<tau>' # \\<tau>s\\<^sub>2\"\n(*<*)using wt_instrs_app2[where ?xt\\<^sub>2.0 = \"[]\"] by (simp add:shift_def)(*>*)\n\n\ncorollary (in TC2) wt_instrs_Cons3[simp]:\n  \"\\<lbrakk> \\<tau>s \\<noteq> []; \\<turnstile> [i],[] [::] [\\<tau>,\\<tau>']; \\<turnstile> is,[] [::] \\<tau>'#\\<tau>s \\<rbrakk>\n  \\<Longrightarrow> \\<turnstile> (i # is),[] [::] \\<tau> # \\<tau>' # \\<tau>s\"\n(*<*)\nusing wt_instrs_Cons[where ?xt = \"[]\"]\nby (simp add:shift_def)\n\n(*<*)\ndeclare nth_append[simp del]\ndeclare [[simproc del: list_to_set_comprehension]]\n(*>*)\n\nlemma (in TC2) wt_instrs_xapp[trans]:\n  \"\\<lbrakk> \\<turnstile> is\\<^sub>1 @ is\\<^sub>2, xt [::] \\<tau>s\\<^sub>1 @ ty\\<^sub>i' (Class C # ST) E A # \\<tau>s\\<^sub>2;\n     \\<forall>\\<tau> \\<in> set \\<tau>s\\<^sub>1. \\<forall>ST' LT'. \\<tau> = Some(ST',LT') \\<longrightarrow> \n      size ST \\<le> size ST' \\<and> P \\<turnstile> Some (drop (size ST' - size ST) ST',LT') \\<le>' ty\\<^sub>i' ST E A;\n     size is\\<^sub>1 = size \\<tau>s\\<^sub>1; is_class P C; size ST < mxs  \\<rbrakk> \\<Longrightarrow>\n  \\<turnstile> is\\<^sub>1 @ is\\<^sub>2, xt @ [(0,size is\\<^sub>1 - 1,C,size is\\<^sub>1,size ST)] [::] \\<tau>s\\<^sub>1 @ ty\\<^sub>i' (Class C # ST) E A # \\<tau>s\\<^sub>2\"\n(*<*)\napply(simp add:wt_instrs_def)\napply(rule conjI)\n apply(clarsimp)\n apply arith\napply clarsimp\napply(erule allE, erule (1) impE)\napply(clarsimp simp add: wt_instr_def app_def eff_def)\napply(rule conjI)\n apply (thin_tac \"\\<forall>x\\<in> A \\<union> B. P x\" for A B P)\n apply (thin_tac \"\\<forall>x\\<in> A \\<union> B. P x\" for A B P)\n apply (clarsimp simp add: xcpt_app_def relevant_entries_def)\n apply (simp add: nth_append is_relevant_entry_def split!: if_splits)\n  apply (drule_tac x=\"\\<tau>s\\<^sub>1!pc\" in bspec)\n   apply (blast intro: nth_mem) \n  apply fastforce\napply (rule conjI)\n apply clarsimp\n apply (erule disjE, blast)\n apply (erule disjE, blast)\n apply (clarsimp simp add: xcpt_eff_def relevant_entries_def split: if_split_asm)\napply clarsimp\napply (erule disjE, blast)\napply (erule disjE, blast)\napply (clarsimp simp add: xcpt_eff_def relevant_entries_def split: if_split_asm)\napply (simp add: nth_append is_relevant_entry_def split: if_split_asm)\n apply (drule_tac x = \"\\<tau>s\\<^sub>1!pc\" in bspec)\n  apply (blast intro: nth_mem) \n apply (fastforce simp add: ty\\<^sub>i'_def)\ndone\n\ndeclare [[simproc add: list_to_set_comprehension]]\ndeclare nth_append[simp]\n(*>*)\n\nlemma drop_Cons_Suc:\n  \"\\<And>xs. drop n xs = y#ys \\<Longrightarrow> drop (Suc n) xs = ys\"\n  apply (induct n)\n   apply simp\n  apply (simp add: drop_Suc)\n  done\n\nlemma drop_mess:\n  \"\\<lbrakk>Suc (length xs\\<^sub>0) \\<le> length xs; drop (length xs - Suc (length xs\\<^sub>0)) xs = x # xs\\<^sub>0\\<rbrakk> \n  \\<Longrightarrow> drop (length xs - length xs\\<^sub>0) xs = xs\\<^sub>0\"\napply (cases xs)\n apply simp\napply (simp add: Suc_diff_le)\napply (case_tac \"length list - length xs\\<^sub>0\")\n apply simp\napply (simp add: drop_Cons_Suc)\ndone\n\n(*<*)\ndeclare (in TC0)\n  after_def[simp] pair_eq_ty\\<^sub>i'_conv[simp]\n(*>*)\n\nlemma (in TC1) compT_ST_prefix:\n \"\\<And>E A ST\\<^sub>0. \\<lfloor>(ST,LT)\\<rfloor> \\<in> set(compT E A ST\\<^sub>0 e) \\<Longrightarrow> \n  size ST\\<^sub>0 \\<le> size ST \\<and> drop (size ST - size ST\\<^sub>0) ST = ST\\<^sub>0\"\nand\n \"\\<And>E A ST\\<^sub>0. \\<lfloor>(ST,LT)\\<rfloor> \\<in> set(compTs E A ST\\<^sub>0 es) \\<Longrightarrow> \n  size ST\\<^sub>0 \\<le> size ST \\<and> drop (size ST - size ST\\<^sub>0) ST = ST\\<^sub>0\"\n(*<*)\nproof(induct e and es rule: compT.induct compTs.induct)\n  case (FAss e\\<^sub>1 F D e\\<^sub>2)\n  moreover {\n    let ?ST\\<^sub>0 = \"ty E e\\<^sub>1 # ST\\<^sub>0\"\n    fix A assume \"\\<lfloor>(ST, LT)\\<rfloor> \\<in> set (compT E A ?ST\\<^sub>0 e\\<^sub>2)\"\n    with FAss\n    have \"length ?ST\\<^sub>0 \\<le> length ST \\<and> drop (size ST - size ?ST\\<^sub>0) ST = ?ST\\<^sub>0\" by blast\n    hence ?case  by (clarsimp simp add: drop_mess)\n  }\n  ultimately show ?case by auto\nnext\n  case TryCatch thus ?case by auto\nnext\n  case Block thus ?case by auto\nnext\n  case Seq thus ?case by auto\nnext\n  case While thus ?case by auto\nnext\n  case Cond thus ?case by auto\nnext\n  case (Call e M es)\n  moreover {\n    let ?ST\\<^sub>0 = \"ty E e # ST\\<^sub>0\"\n    fix A assume \"\\<lfloor>(ST, LT)\\<rfloor> \\<in> set (compTs E A ?ST\\<^sub>0 es)\"\n    with Call\n    have \"length ?ST\\<^sub>0 \\<le> length ST \\<and> drop (size ST - size ?ST\\<^sub>0) ST = ?ST\\<^sub>0\" by blast\n    hence ?case  by (clarsimp simp add: drop_mess)\n  }\n  ultimately show ?case by auto\nnext\n  case (Cons_exp e es)\n  moreover {\n    let ?ST\\<^sub>0 = \"ty E e # ST\\<^sub>0\"\n    fix A assume \"\\<lfloor>(ST, LT)\\<rfloor> \\<in> set (compTs E A ?ST\\<^sub>0 es)\"\n    with Cons_exp\n    have \"length ?ST\\<^sub>0 \\<le> length ST \\<and> drop (size ST - size ?ST\\<^sub>0) ST = ?ST\\<^sub>0\" by blast\n    hence ?case  by (clarsimp simp add: drop_mess)\n  }\n  ultimately show ?case by auto\nnext\n  case (BinOp e\\<^sub>1 bop e\\<^sub>2)\n  moreover {\n    let ?ST\\<^sub>0 = \"ty E e\\<^sub>1 # ST\\<^sub>0\"\n    fix A assume \"\\<lfloor>(ST, LT)\\<rfloor> \\<in> set (compT E A ?ST\\<^sub>0 e\\<^sub>2)\"\n    with BinOp \n    have \"length ?ST\\<^sub>0 \\<le> length ST \\<and> drop (size ST - size ?ST\\<^sub>0) ST = ?ST\\<^sub>0\" by blast\n    hence ?case by (clarsimp simp add: drop_mess)\n  }\n  ultimately show ?case by auto\nnext\n  case new thus ?case by auto\nnext\n  case Val thus ?case by auto    \nnext\n  case Cast thus ?case by auto\nnext\n  case Var thus ?case by auto\nnext\n  case LAss thus ?case by auto\nnext\n  case throw thus ?case by auto\nnext\n  case FAcc thus ?case by auto\nnext\n  case Nil_exp thus ?case by auto\nqed \n\ndeclare (in TC0) \n  after_def[simp del] pair_eq_ty\\<^sub>i'_conv[simp del]\n(*>*)\n\n(* FIXME *)\nlemma fun_of_simp [simp]: \"fun_of S x y = ((x,y) \\<in> S)\" \n(*<*) by (simp add: fun_of_def)(*>*)\n\ntheorem (in TC2) compT_wt_instrs: \"\\<And>E T A ST.\n  \\<lbrakk> P,E \\<turnstile>\\<^sub>1 e :: T; \\<D> e A; \\<B> e (size E); \n    size ST + max_stack e \\<le> mxs; size E + max_vars e \\<le> mxl \\<rbrakk>\n  \\<Longrightarrow> \\<turnstile> compE\\<^sub>2 e, compxE\\<^sub>2 e 0 (size ST) [::]\n                 ty\\<^sub>i' ST E A # compT E A ST e @ [after E A ST e]\"\n(*<*)(is \"\\<And>E T A ST. PROP ?P e E T A ST\")(*>*)\n\nand \"\\<And>E Ts A ST.\n  \\<lbrakk> P,E \\<turnstile>\\<^sub>1 es[::]Ts;  \\<D>s es A; \\<B>s es (size E); \n    size ST + max_stacks es \\<le> mxs; size E + max_varss es \\<le> mxl \\<rbrakk>\n  \\<Longrightarrow> let \\<tau>s = ty\\<^sub>i' ST E A # compTs E A ST es in\n       \\<turnstile> compEs\\<^sub>2 es,compxEs\\<^sub>2 es 0 (size ST) [::] \\<tau>s \\<and>\n       last \\<tau>s = ty\\<^sub>i' (rev Ts @ ST) E (A \\<squnion> \\<A>s es)\"\n(*<*)\n(is \"\\<And>E Ts A ST. PROP ?Ps es E Ts A ST\")\nproof(induct e and es rule: compxE\\<^sub>2.induct compxEs\\<^sub>2.induct)\n  case (TryCatch e\\<^sub>1 C i e\\<^sub>2)\n  hence [simp]: \"i = size E\" by simp\n  have wt\\<^sub>1: \"P,E \\<turnstile>\\<^sub>1 e\\<^sub>1 :: T\" and wt\\<^sub>2: \"P,E@[Class C] \\<turnstile>\\<^sub>1 e\\<^sub>2 :: T\"\n    and \"class\": \"is_class P C\" using TryCatch by auto\n  let ?A\\<^sub>1 = \"A \\<squnion> \\<A> e\\<^sub>1\" let ?A\\<^sub>i = \"A \\<squnion> \\<lfloor>{i}\\<rfloor>\" let ?E\\<^sub>i = \"E @ [Class C]\"\n  let ?\\<tau> = \"ty\\<^sub>i' ST E A\" let ?\\<tau>s\\<^sub>1 = \"compT E A ST e\\<^sub>1\"\n  let ?\\<tau>\\<^sub>1 = \"ty\\<^sub>i' (T#ST) E ?A\\<^sub>1\" let ?\\<tau>\\<^sub>2 = \"ty\\<^sub>i' (Class C#ST) E A\"\n  let ?\\<tau>\\<^sub>3 = \"ty\\<^sub>i' ST ?E\\<^sub>i ?A\\<^sub>i\" let ?\\<tau>s\\<^sub>2 = \"compT ?E\\<^sub>i ?A\\<^sub>i ST e\\<^sub>2\"\n  let ?\\<tau>\\<^sub>2' = \"ty\\<^sub>i' (T#ST) ?E\\<^sub>i (?A\\<^sub>i \\<squnion> \\<A> e\\<^sub>2)\"\n  let ?\\<tau>' = \"ty\\<^sub>i' (T#ST) E (A \\<squnion> \\<A> e\\<^sub>1 \\<sqinter> (\\<A> e\\<^sub>2 \\<ominus> i))\"\n  let ?go = \"Goto (int(size(compE\\<^sub>2 e\\<^sub>2)) + 2)\"\n  have \"PROP ?P e\\<^sub>2 ?E\\<^sub>i T ?A\\<^sub>i ST\" by fact\n  hence \"\\<turnstile> compE\\<^sub>2 e\\<^sub>2,compxE\\<^sub>2 e\\<^sub>2 0 (size ST) [::] (?\\<tau>\\<^sub>3 # ?\\<tau>s\\<^sub>2) @ [?\\<tau>\\<^sub>2']\"\n    using TryCatch.prems by(auto simp:after_def)\n  also have \"?A\\<^sub>i \\<squnion> \\<A> e\\<^sub>2 = (A \\<squnion> \\<A> e\\<^sub>2) \\<squnion> \\<lfloor>{size E}\\<rfloor>\"\n    by(fastforce simp:hyperset_defs)\n  also have \"P \\<turnstile> ty\\<^sub>i' (T#ST) ?E\\<^sub>i \\<dots> \\<le>' ty\\<^sub>i' (T#ST) E (A \\<squnion> \\<A> e\\<^sub>2)\"\n    by(simp add:hyperset_defs ty\\<^sub>l_incr ty\\<^sub>i'_def)\n  also have \"P \\<turnstile> \\<dots> \\<le>' ty\\<^sub>i' (T#ST) E (A \\<squnion> \\<A> e\\<^sub>1 \\<sqinter> (\\<A> e\\<^sub>2 \\<ominus> i))\"\n    by(auto intro!: ty\\<^sub>l_antimono simp:hyperset_defs ty\\<^sub>i'_def)\n  also have \"(?\\<tau>\\<^sub>3 # ?\\<tau>s\\<^sub>2) @ [?\\<tau>'] = ?\\<tau>\\<^sub>3 # ?\\<tau>s\\<^sub>2 @ [?\\<tau>']\" by simp\n  also have \"\\<turnstile> [Store i],[] [::] ?\\<tau>\\<^sub>2 # [] @ [?\\<tau>\\<^sub>3]\"\n    using TryCatch.prems\n    by(auto simp:nth_list_update wt_defs ty\\<^sub>i'_def ty\\<^sub>l_def\n      list_all2_conv_all_nth hyperset_defs)\n  also have \"[] @ (?\\<tau>\\<^sub>3 # ?\\<tau>s\\<^sub>2 @ [?\\<tau>']) = (?\\<tau>\\<^sub>3 # ?\\<tau>s\\<^sub>2 @ [?\\<tau>'])\" by simp\n  also have \"P,T\\<^sub>r,mxs,size(compE\\<^sub>2 e\\<^sub>2)+3,[] \\<turnstile> ?go,0 :: ?\\<tau>\\<^sub>1#?\\<tau>\\<^sub>2#?\\<tau>\\<^sub>3#?\\<tau>s\\<^sub>2 @ [?\\<tau>']\"\n    by (auto simp: hyperset_defs ty\\<^sub>i'_def wt_defs nth_Cons nat_add_distrib\n      fun_of_def intro: ty\\<^sub>l_antimono list_all2_refl split:nat.split)\n  also have \"\\<turnstile> compE\\<^sub>2 e\\<^sub>1,compxE\\<^sub>2 e\\<^sub>1 0 (size ST) [::] ?\\<tau> # ?\\<tau>s\\<^sub>1 @ [?\\<tau>\\<^sub>1]\"\n    using TryCatch by(auto simp:after_def)\n  also have \"?\\<tau> # ?\\<tau>s\\<^sub>1 @ ?\\<tau>\\<^sub>1 # ?\\<tau>\\<^sub>2 # ?\\<tau>\\<^sub>3 # ?\\<tau>s\\<^sub>2 @ [?\\<tau>'] =\n             (?\\<tau> # ?\\<tau>s\\<^sub>1 @ [?\\<tau>\\<^sub>1]) @ ?\\<tau>\\<^sub>2 # ?\\<tau>\\<^sub>3 # ?\\<tau>s\\<^sub>2 @ [?\\<tau>']\" by simp\n  also have \"compE\\<^sub>2 e\\<^sub>1 @ ?go  # [Store i] @ compE\\<^sub>2 e\\<^sub>2 =\n             (compE\\<^sub>2 e\\<^sub>1 @ [?go]) @ (Store i # compE\\<^sub>2 e\\<^sub>2)\" by simp\n  also \n  let \"?Q \\<tau>\" = \"\\<forall>ST' LT'. \\<tau> = \\<lfloor>(ST', LT')\\<rfloor> \\<longrightarrow> \n    size ST \\<le> size ST' \\<and> P \\<turnstile> Some (drop (size ST' - size ST) ST',LT') \\<le>' ty\\<^sub>i' ST E A\"\n  {\n    have \"?Q (ty\\<^sub>i' ST E A)\" by (clarsimp simp add: ty\\<^sub>i'_def)\n    moreover have \"?Q (ty\\<^sub>i' (T # ST) E ?A\\<^sub>1)\" \n      by (fastforce simp add: ty\\<^sub>i'_def hyperset_defs intro!: ty\\<^sub>l_antimono)\n    moreover have \"\\<And>\\<tau>. \\<tau> \\<in> set (compT E A ST e\\<^sub>1) \\<Longrightarrow> ?Q \\<tau>\" using TryCatch.prems\n      by clarsimp (frule compT_ST_prefix,\n                   fastforce dest!: compT_LT_prefix simp add: ty\\<^sub>i'_def)\n    ultimately\n    have \"\\<forall>\\<tau>\\<in>set (ty\\<^sub>i' ST E A # compT E A ST e\\<^sub>1 @ [ty\\<^sub>i' (T # ST) E ?A\\<^sub>1]). ?Q \\<tau>\" \n      by auto\n  }\n  also from TryCatch.prems max_stack1[of e\\<^sub>1] have \"size ST + 1 \\<le> mxs\" by auto\n  ultimately show ?case using wt\\<^sub>1 wt\\<^sub>2 TryCatch.prems \"class\"\n    by (simp add:after_def)\nnext\n  case new thus ?case by(auto simp add:after_def wt_New)\nnext\n  case (BinOp e\\<^sub>1 bop e\\<^sub>2) \n  let ?op = \"case bop of Eq \\<Rightarrow> [CmpEq] | Add \\<Rightarrow> [IAdd]\"\n  have T: \"P,E \\<turnstile>\\<^sub>1 e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2 :: T\" by fact\n  then obtain T\\<^sub>1 T\\<^sub>2 where T\\<^sub>1: \"P,E \\<turnstile>\\<^sub>1 e\\<^sub>1 :: T\\<^sub>1\" and T\\<^sub>2: \"P,E \\<turnstile>\\<^sub>1 e\\<^sub>2 :: T\\<^sub>2\" and \n    bopT: \"case bop of Eq \\<Rightarrow> (P \\<turnstile> T\\<^sub>1 \\<le> T\\<^sub>2 \\<or> P \\<turnstile> T\\<^sub>2 \\<le> T\\<^sub>1) \\<and> T = Boolean \n                    | Add \\<Rightarrow> T\\<^sub>1 = Integer \\<and> T\\<^sub>2 = Integer \\<and> T = Integer\" by auto\n  let ?A\\<^sub>1 = \"A \\<squnion> \\<A> e\\<^sub>1\" let ?A\\<^sub>2 = \"?A\\<^sub>1 \\<squnion> \\<A> e\\<^sub>2\"\n  let ?\\<tau> = \"ty\\<^sub>i' ST E A\" let ?\\<tau>s\\<^sub>1 = \"compT E A ST e\\<^sub>1\"\n  let ?\\<tau>\\<^sub>1 = \"ty\\<^sub>i' (T\\<^sub>1#ST) E ?A\\<^sub>1\" let ?\\<tau>s\\<^sub>2 = \"compT E ?A\\<^sub>1 (T\\<^sub>1#ST) e\\<^sub>2\"\n  let ?\\<tau>\\<^sub>2 = \"ty\\<^sub>i' (T\\<^sub>2#T\\<^sub>1#ST) E ?A\\<^sub>2\" let ?\\<tau>' = \"ty\\<^sub>i' (T#ST) E ?A\\<^sub>2\"\n  from bopT have \"\\<turnstile> ?op,[] [::] [?\\<tau>\\<^sub>2,?\\<tau>']\" \n    by (cases bop) (auto simp add: wt_CmpEq wt_IAdd)\n  also have \"PROP ?P e\\<^sub>2 E T\\<^sub>2 ?A\\<^sub>1 (T\\<^sub>1#ST)\" by fact\n  with BinOp.prems T\\<^sub>2 \n  have \"\\<turnstile> compE\\<^sub>2 e\\<^sub>2, compxE\\<^sub>2 e\\<^sub>2 0 (size (T\\<^sub>1#ST)) [::] ?\\<tau>\\<^sub>1#?\\<tau>s\\<^sub>2@[?\\<tau>\\<^sub>2]\" \n    by (auto simp: after_def)\n  also from BinOp T\\<^sub>1 have \"\\<turnstile> compE\\<^sub>2 e\\<^sub>1, compxE\\<^sub>2 e\\<^sub>1 0 (size ST) [::] ?\\<tau>#?\\<tau>s\\<^sub>1@[?\\<tau>\\<^sub>1]\" \n    by (auto simp: after_def)\n  finally show ?case using T T\\<^sub>1 T\\<^sub>2 by (simp add: after_def hyperUn_assoc)\nnext\n  case (Cons_exp e es)\n  have \"P,E \\<turnstile>\\<^sub>1 e # es [::] Ts\" by fact\n  then obtain T\\<^sub>e Ts' where \n    T\\<^sub>e: \"P,E \\<turnstile>\\<^sub>1 e :: T\\<^sub>e\" and Ts': \"P,E \\<turnstile>\\<^sub>1 es [::] Ts'\" and\n    Ts: \"Ts = T\\<^sub>e#Ts'\" by auto\n  let ?A\\<^sub>e = \"A \\<squnion> \\<A> e\"  \n  let ?\\<tau> = \"ty\\<^sub>i' ST E A\" let ?\\<tau>s\\<^sub>e = \"compT E A ST e\"  \n  let ?\\<tau>\\<^sub>e = \"ty\\<^sub>i' (T\\<^sub>e#ST) E ?A\\<^sub>e\" let ?\\<tau>s' = \"compTs E ?A\\<^sub>e (T\\<^sub>e#ST) es\"\n  let ?\\<tau>s = \"?\\<tau> # ?\\<tau>s\\<^sub>e @ (?\\<tau>\\<^sub>e # ?\\<tau>s')\"\n  have Ps: \"PROP ?Ps es E Ts' ?A\\<^sub>e (T\\<^sub>e#ST)\" by fact\n  with Cons_exp.prems T\\<^sub>e Ts'\n  have \"\\<turnstile> compEs\\<^sub>2 es, compxEs\\<^sub>2 es 0 (size (T\\<^sub>e#ST)) [::] ?\\<tau>\\<^sub>e#?\\<tau>s'\" by (simp add: after_def)\n  also from Cons_exp T\\<^sub>e have \"\\<turnstile> compE\\<^sub>2 e, compxE\\<^sub>2 e 0 (size ST) [::] ?\\<tau>#?\\<tau>s\\<^sub>e@[?\\<tau>\\<^sub>e]\" \n    by (auto simp: after_def)\n  moreover\n  from Ps Cons_exp.prems T\\<^sub>e Ts' Ts\n  have \"last ?\\<tau>s = ty\\<^sub>i' (rev Ts@ST) E (?A\\<^sub>e \\<squnion> \\<A>s es)\" by simp\n  ultimately show ?case using T\\<^sub>e by (simp add: after_def hyperUn_assoc)\nnext\n  case (FAss e\\<^sub>1 F D e\\<^sub>2)\n  hence Void: \"P,E \\<turnstile>\\<^sub>1 e\\<^sub>1\\<bullet>F{D} := e\\<^sub>2 :: Void\" by auto\n  then obtain C T T' where    \n    C: \"P,E \\<turnstile>\\<^sub>1 e\\<^sub>1 :: Class C\" and sees: \"P \\<turnstile> C sees F:T in D\" and\n    T': \"P,E \\<turnstile>\\<^sub>1 e\\<^sub>2 :: T'\" and T'_T: \"P \\<turnstile> T' \\<le> T\" by auto\n  let ?A\\<^sub>1 = \"A \\<squnion> \\<A> e\\<^sub>1\" let ?A\\<^sub>2 = \"?A\\<^sub>1 \\<squnion> \\<A> e\\<^sub>2\"  \n  let ?\\<tau> = \"ty\\<^sub>i' ST E A\" let ?\\<tau>s\\<^sub>1 = \"compT E A ST e\\<^sub>1\"\n  let ?\\<tau>\\<^sub>1 = \"ty\\<^sub>i' (Class C#ST) E ?A\\<^sub>1\" let ?\\<tau>s\\<^sub>2 = \"compT E ?A\\<^sub>1 (Class C#ST) e\\<^sub>2\"\n  let ?\\<tau>\\<^sub>2 = \"ty\\<^sub>i' (T'#Class C#ST) E ?A\\<^sub>2\" let ?\\<tau>\\<^sub>3 = \"ty\\<^sub>i' ST E ?A\\<^sub>2\"\n  let ?\\<tau>' = \"ty\\<^sub>i' (Void#ST) E ?A\\<^sub>2\"\n  from FAss.prems sees T'_T \n  have \"\\<turnstile> [Putfield F D,Push Unit],[] [::] [?\\<tau>\\<^sub>2,?\\<tau>\\<^sub>3,?\\<tau>']\"\n    by (fastforce simp add: wt_Push wt_Put)\n  also have \"PROP ?P e\\<^sub>2 E T' ?A\\<^sub>1 (Class C#ST)\" by fact\n  with FAss.prems T' \n  have \"\\<turnstile> compE\\<^sub>2 e\\<^sub>2, compxE\\<^sub>2 e\\<^sub>2 0 (size ST+1) [::] ?\\<tau>\\<^sub>1#?\\<tau>s\\<^sub>2@[?\\<tau>\\<^sub>2]\"\n    by (auto simp add: after_def hyperUn_assoc) \n  also from FAss C have \"\\<turnstile> compE\\<^sub>2 e\\<^sub>1, compxE\\<^sub>2 e\\<^sub>1 0 (size ST) [::] ?\\<tau>#?\\<tau>s\\<^sub>1@[?\\<tau>\\<^sub>1]\" \n    by (auto simp add: after_def)\n  finally show ?case using Void C T' by (simp add: after_def hyperUn_assoc) \nnext\n  case Val thus ?case by(auto simp:after_def wt_Push)\nnext\n  case Cast thus ?case by (auto simp:after_def wt_Cast)\nnext\n  case (Block i T\\<^sub>i e)\n  let ?\\<tau>s = \"ty\\<^sub>i' ST E A # compT (E @ [T\\<^sub>i]) (A\\<ominus>i) ST e\"\n  have IH: \"PROP ?P e (E@[T\\<^sub>i]) T (A\\<ominus>i) ST\" by fact\n  hence \"\\<turnstile> compE\\<^sub>2 e, compxE\\<^sub>2 e 0 (size ST) [::]\n         ?\\<tau>s @ [ty\\<^sub>i' (T#ST) (E@[T\\<^sub>i]) (A\\<ominus>(size E) \\<squnion> \\<A> e)]\"\n    using Block.prems by (auto simp add: after_def)\n  also have \"P \\<turnstile> ty\\<^sub>i' (T # ST) (E@[T\\<^sub>i]) (A \\<ominus> size E \\<squnion> \\<A> e) \\<le>'\n                 ty\\<^sub>i' (T # ST) (E@[T\\<^sub>i]) ((A \\<squnion> \\<A> e) \\<ominus> size E)\"\n     by(auto simp add:hyperset_defs intro: ty\\<^sub>i'_antimono)\n  also have \"\\<dots> = ty\\<^sub>i' (T # ST) E (A \\<squnion> \\<A> e)\" by simp\n  also have \"P \\<turnstile> \\<dots> \\<le>' ty\\<^sub>i' (T # ST) E (A \\<squnion> (\\<A> e \\<ominus> i))\"\n     by(auto simp add:hyperset_defs intro: ty\\<^sub>i'_antimono)\n  finally show ?case using Block.prems by(simp add: after_def)\nnext\n  case Var thus ?case by(auto simp:after_def wt_Load)\nnext\n  case FAcc thus ?case by(auto simp:after_def wt_Get)\nnext\n  case (LAss i e) thus ?case using max_stack1[of e]\n    by(auto simp: hyper_insert_comm after_def wt_Store wt_Push)\nnext\n  case Nil_exp thus ?case by auto\nnext\n  case throw thus ?case by(auto simp add: after_def wt_Throw)\nnext\n  case (While e c)\n  obtain Tc where wte: \"P,E \\<turnstile>\\<^sub>1 e :: Boolean\" and wtc: \"P,E \\<turnstile>\\<^sub>1 c :: Tc\"\n    and [simp]: \"T = Void\" using While by auto\n  have [simp]: \"ty E (while (e) c) = Void\" using While by simp\n  let ?A\\<^sub>0 = \"A \\<squnion> \\<A> e\" let ?A\\<^sub>1 = \"?A\\<^sub>0 \\<squnion> \\<A> c\"\n  let ?\\<tau> = \"ty\\<^sub>i' ST E A\" let ?\\<tau>s\\<^sub>e = \"compT E A ST e\"\n  let ?\\<tau>\\<^sub>e = \"ty\\<^sub>i' (Boolean#ST) E ?A\\<^sub>0\" let ?\\<tau>\\<^sub>1 = \"ty\\<^sub>i' ST E ?A\\<^sub>0\"\n  let ?\\<tau>s\\<^sub>c = \"compT E ?A\\<^sub>0 ST c\" let ?\\<tau>\\<^sub>c = \"ty\\<^sub>i' (Tc#ST) E ?A\\<^sub>1\"\n  let ?\\<tau>\\<^sub>2 = \"ty\\<^sub>i' ST E ?A\\<^sub>1\" let ?\\<tau>' = \"ty\\<^sub>i' (Void#ST) E ?A\\<^sub>0\"\n  let ?\\<tau>s = \"(?\\<tau> # ?\\<tau>s\\<^sub>e @ [?\\<tau>\\<^sub>e]) @ ?\\<tau>\\<^sub>1 # ?\\<tau>s\\<^sub>c @ [?\\<tau>\\<^sub>c, ?\\<tau>\\<^sub>2, ?\\<tau>\\<^sub>1, ?\\<tau>']\"\n  have \"\\<turnstile> [],[] [::] [] @ ?\\<tau>s\" by(simp add:wt_instrs_def)\n  also\n  have \"PROP ?P e E Boolean A ST\" by fact\n  hence \"\\<turnstile> compE\\<^sub>2 e,compxE\\<^sub>2 e 0 (size ST) [::] ?\\<tau> # ?\\<tau>s\\<^sub>e @ [?\\<tau>\\<^sub>e]\"\n    using While.prems by (auto simp:after_def)\n  also\n  have \"[] @ ?\\<tau>s = (?\\<tau> # ?\\<tau>s\\<^sub>e) @ ?\\<tau>\\<^sub>e # ?\\<tau>\\<^sub>1 # ?\\<tau>s\\<^sub>c @ [?\\<tau>\\<^sub>c,?\\<tau>\\<^sub>2,?\\<tau>\\<^sub>1,?\\<tau>']\" by simp\n  also\n  let ?n\\<^sub>e = \"size(compE\\<^sub>2 e)\"  let ?n\\<^sub>c = \"size(compE\\<^sub>2 c)\"\n  let ?if = \"IfFalse (int ?n\\<^sub>c + 3)\"\n  have \"\\<turnstile> [?if],[] [::] ?\\<tau>\\<^sub>e # ?\\<tau>\\<^sub>1 # ?\\<tau>s\\<^sub>c @ [?\\<tau>\\<^sub>c, ?\\<tau>\\<^sub>2, ?\\<tau>\\<^sub>1, ?\\<tau>']\"\n    by(simp add: wt_instr_Cons wt_instr_append wt_IfFalse\n                 nat_add_distrib split: nat_diff_split)\n  also\n  have \"(?\\<tau> # ?\\<tau>s\\<^sub>e) @ (?\\<tau>\\<^sub>e # ?\\<tau>\\<^sub>1 # ?\\<tau>s\\<^sub>c @ [?\\<tau>\\<^sub>c, ?\\<tau>\\<^sub>2, ?\\<tau>\\<^sub>1, ?\\<tau>']) = ?\\<tau>s\" by simp\n  also\n  have \"PROP ?P c E Tc ?A\\<^sub>0 ST\" by fact\n  hence \"\\<turnstile> compE\\<^sub>2 c,compxE\\<^sub>2 c 0 (size ST) [::] ?\\<tau>\\<^sub>1 # ?\\<tau>s\\<^sub>c @ [?\\<tau>\\<^sub>c]\"\n    using While.prems wtc by (auto simp:after_def)\n  also have \"?\\<tau>s = (?\\<tau> # ?\\<tau>s\\<^sub>e @ [?\\<tau>\\<^sub>e,?\\<tau>\\<^sub>1] @ ?\\<tau>s\\<^sub>c) @ [?\\<tau>\\<^sub>c,?\\<tau>\\<^sub>2,?\\<tau>\\<^sub>1,?\\<tau>']\" by simp\n  also have \"\\<turnstile> [Pop],[] [::] [?\\<tau>\\<^sub>c, ?\\<tau>\\<^sub>2]\"  by(simp add:wt_Pop)\n  also have \"(?\\<tau> # ?\\<tau>s\\<^sub>e @ [?\\<tau>\\<^sub>e,?\\<tau>\\<^sub>1] @ ?\\<tau>s\\<^sub>c) @ [?\\<tau>\\<^sub>c,?\\<tau>\\<^sub>2,?\\<tau>\\<^sub>1,?\\<tau>'] = ?\\<tau>s\" by simp\n  also let ?go = \"Goto (-int(?n\\<^sub>c+?n\\<^sub>e+2))\"\n  have \"P \\<turnstile> ?\\<tau>\\<^sub>2 \\<le>' ?\\<tau>\" by(fastforce intro: ty\\<^sub>i'_antimono simp: hyperset_defs)\n  hence \"P,T\\<^sub>r,mxs,size ?\\<tau>s,[] \\<turnstile> ?go,?n\\<^sub>e+?n\\<^sub>c+2 :: ?\\<tau>s\"\n    by(simp add: wt_Goto split: nat_diff_split)\n  also have \"?\\<tau>s = (?\\<tau> # ?\\<tau>s\\<^sub>e @ [?\\<tau>\\<^sub>e,?\\<tau>\\<^sub>1] @ ?\\<tau>s\\<^sub>c @ [?\\<tau>\\<^sub>c, ?\\<tau>\\<^sub>2]) @ [?\\<tau>\\<^sub>1, ?\\<tau>']\"\n    by simp\n  also have \"\\<turnstile> [Push Unit],[] [::] [?\\<tau>\\<^sub>1,?\\<tau>']\"\n    using While.prems max_stack1[of c] by(auto simp add:wt_Push)\n  finally show ?case using wtc wte\n    by (simp add:after_def)\nnext\n  case (Cond e e\\<^sub>1 e\\<^sub>2)\n  obtain T\\<^sub>1 T\\<^sub>2 where wte: \"P,E \\<turnstile>\\<^sub>1 e :: Boolean\"\n    and wt\\<^sub>1: \"P,E \\<turnstile>\\<^sub>1 e\\<^sub>1 :: T\\<^sub>1\" and wt\\<^sub>2: \"P,E \\<turnstile>\\<^sub>1 e\\<^sub>2 :: T\\<^sub>2\"\n    and sub\\<^sub>1: \"P \\<turnstile> T\\<^sub>1 \\<le> T\" and sub\\<^sub>2: \"P \\<turnstile> T\\<^sub>2 \\<le> T\"\n    using Cond by auto\n  have [simp]: \"ty E (if (e) e\\<^sub>1 else e\\<^sub>2) = T\" using Cond by simp\n  let ?A\\<^sub>0 = \"A \\<squnion> \\<A> e\" let ?A\\<^sub>2 = \"?A\\<^sub>0 \\<squnion> \\<A> e\\<^sub>2\" let ?A\\<^sub>1 = \"?A\\<^sub>0 \\<squnion> \\<A> e\\<^sub>1\"\n  let ?A' = \"?A\\<^sub>0 \\<squnion> \\<A> e\\<^sub>1 \\<sqinter> \\<A> e\\<^sub>2\"\n  let ?\\<tau>\\<^sub>2 = \"ty\\<^sub>i' ST E ?A\\<^sub>0\" let ?\\<tau>' = \"ty\\<^sub>i' (T#ST) E ?A'\"\n  let ?\\<tau>s\\<^sub>2 = \"compT E ?A\\<^sub>0 ST e\\<^sub>2\"\n  have \"PROP ?P e\\<^sub>2 E T\\<^sub>2 ?A\\<^sub>0 ST\" by fact\n  hence \"\\<turnstile> compE\\<^sub>2 e\\<^sub>2, compxE\\<^sub>2 e\\<^sub>2 0 (size ST) [::] (?\\<tau>\\<^sub>2#?\\<tau>s\\<^sub>2) @ [ty\\<^sub>i' (T\\<^sub>2#ST) E ?A\\<^sub>2]\"\n    using Cond.prems wt\\<^sub>2 by(auto simp add:after_def)\n  also have \"P \\<turnstile> ty\\<^sub>i' (T\\<^sub>2#ST) E ?A\\<^sub>2 \\<le>' ?\\<tau>'\" using sub\\<^sub>2\n    by(auto simp add: hyperset_defs ty\\<^sub>i'_def intro!: ty\\<^sub>l_antimono)\n  also\n  let ?\\<tau>\\<^sub>3 = \"ty\\<^sub>i' (T\\<^sub>1 # ST) E ?A\\<^sub>1\"\n  let ?g\\<^sub>2 = \"Goto(int (size (compE\\<^sub>2 e\\<^sub>2) + 1))\"\n  from sub\\<^sub>1 have \"P,T\\<^sub>r,mxs,size(compE\\<^sub>2 e\\<^sub>2)+2,[] \\<turnstile> ?g\\<^sub>2,0 :: ?\\<tau>\\<^sub>3#(?\\<tau>\\<^sub>2#?\\<tau>s\\<^sub>2)@[?\\<tau>']\"\n    by(auto simp: hyperset_defs wt_defs nth_Cons ty\\<^sub>i'_def\n             split:nat.split intro!: ty\\<^sub>l_antimono)\n  also\n  let ?\\<tau>s\\<^sub>1 = \"compT E ?A\\<^sub>0 ST e\\<^sub>1\"\n  have \"PROP ?P e\\<^sub>1 E T\\<^sub>1 ?A\\<^sub>0 ST\" by fact\n  hence \"\\<turnstile> compE\\<^sub>2 e\\<^sub>1,compxE\\<^sub>2 e\\<^sub>1 0 (size ST) [::] ?\\<tau>\\<^sub>2 # ?\\<tau>s\\<^sub>1 @ [?\\<tau>\\<^sub>3]\"\n    using Cond.prems wt\\<^sub>1 by(auto simp add:after_def)\n  also\n  let ?\\<tau>s\\<^sub>1\\<^sub>2 = \"?\\<tau>\\<^sub>2 # ?\\<tau>s\\<^sub>1 @ ?\\<tau>\\<^sub>3 # (?\\<tau>\\<^sub>2 # ?\\<tau>s\\<^sub>2) @ [?\\<tau>']\"\n  let ?\\<tau>\\<^sub>1 = \"ty\\<^sub>i' (Boolean#ST) E ?A\\<^sub>0\"\n  let ?g\\<^sub>1 = \"IfFalse(int (size (compE\\<^sub>2 e\\<^sub>1) + 2))\"\n  let ?code = \"compE\\<^sub>2 e\\<^sub>1 @ ?g\\<^sub>2 # compE\\<^sub>2 e\\<^sub>2\"\n  have \"\\<turnstile> [?g\\<^sub>1],[] [::] [?\\<tau>\\<^sub>1] @ ?\\<tau>s\\<^sub>1\\<^sub>2\"\n    by(simp add: wt_IfFalse nat_add_distrib split:nat_diff_split)\n  also (wt_instrs_ext2) have \"[?\\<tau>\\<^sub>1] @ ?\\<tau>s\\<^sub>1\\<^sub>2 = ?\\<tau>\\<^sub>1 # ?\\<tau>s\\<^sub>1\\<^sub>2\" by simp also\n  let ?\\<tau> = \"ty\\<^sub>i' ST E A\"\n  have \"PROP ?P e E Boolean A ST\" by fact\n  hence \"\\<turnstile> compE\\<^sub>2 e, compxE\\<^sub>2 e 0 (size ST) [::] ?\\<tau> # compT E A ST e @ [?\\<tau>\\<^sub>1]\"\n    using Cond.prems wte by(auto simp add:after_def)\n  finally show ?case using wte wt\\<^sub>1 wt\\<^sub>2 by(simp add:after_def hyperUn_assoc)\nnext\n  case (Call e M es)\n  obtain C D Ts m Ts' where C: \"P,E \\<turnstile>\\<^sub>1 e :: Class C\"\n    and \"method\": \"P \\<turnstile> C sees M:Ts \\<rightarrow> T = m in D\"\n    and wtes: \"P,E \\<turnstile>\\<^sub>1 es [::] Ts'\" and subs: \"P \\<turnstile> Ts' [\\<le>] Ts\"\n    using Call.prems by auto\n  from wtes have same_size: \"size es = size Ts'\" by(rule WTs\\<^sub>1_same_size)\n  let ?A\\<^sub>0 = \"A \\<squnion> \\<A> e\" let ?A\\<^sub>1 = \"?A\\<^sub>0 \\<squnion> \\<A>s es\"\n  let ?\\<tau> = \"ty\\<^sub>i' ST E A\" let ?\\<tau>s\\<^sub>e = \"compT E A ST e\"\n  let ?\\<tau>\\<^sub>e = \"ty\\<^sub>i' (Class C # ST) E ?A\\<^sub>0\"\n  let ?\\<tau>s\\<^sub>e\\<^sub>s = \"compTs E ?A\\<^sub>0 (Class C # ST) es\"\n  let ?\\<tau>\\<^sub>1 = \"ty\\<^sub>i' (rev Ts' @ Class C # ST) E ?A\\<^sub>1\"\n  let ?\\<tau>' = \"ty\\<^sub>i' (T # ST) E ?A\\<^sub>1\"\n  have \"\\<turnstile> [Invoke M (size es)],[] [::] [?\\<tau>\\<^sub>1,?\\<tau>']\"\n    by(rule wt_Invoke[OF same_size \"method\" subs])\n  also\n  have \"PROP ?Ps es E Ts' ?A\\<^sub>0 (Class C # ST)\" by fact\n  hence \"\\<turnstile> compEs\\<^sub>2 es,compxEs\\<^sub>2 es 0 (size ST+1) [::] ?\\<tau>\\<^sub>e # ?\\<tau>s\\<^sub>e\\<^sub>s\"\n        \"last (?\\<tau>\\<^sub>e # ?\\<tau>s\\<^sub>e\\<^sub>s) = ?\\<tau>\\<^sub>1\"\n    using Call.prems wtes by(auto simp add:after_def)\n  also have \"(?\\<tau>\\<^sub>e # ?\\<tau>s\\<^sub>e\\<^sub>s) @ [?\\<tau>'] = ?\\<tau>\\<^sub>e # ?\\<tau>s\\<^sub>e\\<^sub>s @ [?\\<tau>']\" by simp\n  also have \"\\<turnstile> compE\\<^sub>2 e,compxE\\<^sub>2 e 0 (size ST) [::] ?\\<tau> # ?\\<tau>s\\<^sub>e @ [?\\<tau>\\<^sub>e]\"\n    using Call C by(auto simp add:after_def)\n  finally show ?case using Call.prems C by(simp add:after_def hyperUn_assoc)\nnext\n  case Seq thus ?case\n    by(auto simp:after_def)\n      (fastforce simp:wt_Push wt_Pop hyperUn_assoc\n                intro:wt_instrs_app2 wt_instrs_Cons)\nqed\n(*>*)\n\n\nlemma [simp]: \"types (compP f P) = types P\"\n(*<*)by auto(*>*)\n\nlemma [simp]: \"states (compP f P) mxs mxl = states P mxs mxl\"\n(*<*)by (simp add: JVM_states_unfold)(*>*)\n\nlemma [simp]: \"app\\<^sub>i (i, compP f P, pc, mpc, T, \\<tau>) = app\\<^sub>i (i, P, pc, mpc, T, \\<tau>)\"\n(*<*)\n  apply (cases \\<tau>)  \n  apply (cases i)\n  apply auto\n   apply (fastforce dest!: sees_method_compPD)\n  apply (force dest: sees_method_compP)\n  done\n(*>*)\n  \nlemma [simp]: \"is_relevant_entry (compP f P) i = is_relevant_entry P i\"\n(*<*)\n  apply (rule ext)+\n  apply (unfold is_relevant_entry_def)\n  apply (cases i)\n  apply auto\n  done\n(*>*)\n\nlemma [simp]: \"relevant_entries (compP f P) i pc xt = relevant_entries P i pc xt\"\n(*<*) by (simp add: relevant_entries_def)(*>*)\n\nlemma [simp]: \"app i (compP f P) mpc T pc mxl xt \\<tau> = app i P mpc T pc mxl xt \\<tau>\"\n(*<*)\n  apply (simp add: app_def xcpt_app_def eff_def xcpt_eff_def norm_eff_def)\n  apply (fastforce simp add: image_def)\n  done\n(*>*)\n\nlemma [simp]: \"app i P mpc T pc mxl xt \\<tau> \\<Longrightarrow> eff i (compP f P) pc xt \\<tau> = eff i P pc xt \\<tau>\"\n(*<*)\n  apply (clarsimp simp add: eff_def norm_eff_def xcpt_eff_def app_def)\n  apply (cases i)\n  apply auto\n  done\n(*>*)\n\nlemma [simp]: \"subtype (compP f P) = subtype P\"\n(*<*)\n  apply (rule ext)+\n  apply (simp)\n  done\n(*>*)\n  \nlemma [simp]: \"compP f P \\<turnstile> \\<tau> \\<le>' \\<tau>' = P \\<turnstile> \\<tau> \\<le>' \\<tau>'\"\n(*<*) by (simp add: sup_state_opt_def sup_state_def sup_ty_opt_def)(*>*)\n\nlemma [simp]: \"compP f P,T,mpc,mxl,xt \\<turnstile> i,pc :: \\<tau>s = P,T,mpc,mxl,xt \\<turnstile> i,pc :: \\<tau>s\"\n(*<*)by (simp add: wt_instr_def cong: conj_cong)(*>*)\n\ndeclare TC1.compT_sizes[simp]  TC0.ty_def2[simp]\n\ncontext TC2\nbegin\n\nlemma compT_method:\n  fixes e and A and C and Ts and mxl\\<^sub>0\n  defines [simp]: \"E \\<equiv> Class C # Ts\"\n    and [simp]: \"A \\<equiv> \\<lfloor>{..size Ts}\\<rfloor>\"\n    and [simp]: \"A' \\<equiv> A \\<squnion> \\<A> e\"\n    and [simp]: \"mxl\\<^sub>0 \\<equiv> max_vars e\"\n  assumes mxs: \"max_stack e = mxs\"\n    and mxl: \"Suc (length Ts + max_vars e) = mxl\"\n  assumes assm: \"wf_prog p P\" \"P,E \\<turnstile>\\<^sub>1 e :: T\" \"\\<D> e A\" \"\\<B> e (size E)\"\n    \"set E \\<subseteq> types P\" \"P \\<turnstile> T \\<le> T\\<^sub>r\"\n  shows \"wt_method (compP\\<^sub>2 P) C Ts T\\<^sub>r mxs mxl\\<^sub>0 (compE\\<^sub>2 e @ [Return])\n    (compxE\\<^sub>2 e 0 0) (ty\\<^sub>i' [] E A # compT\\<^sub>a E A [] e)\"\n(*<*)\nusing assms apply (simp add: wt_method_def compT\\<^sub>a_def after_def mxl)\napply (rule conjI)\napply (simp add: check_types_def OK_ty\\<^sub>i'_in_statesI)\napply (rule conjI)\napply (drule (1) WT\\<^sub>1_is_type)\napply simp\napply (insert max_stack1 [of e])\napply (rule OK_ty\\<^sub>i'_in_statesI) apply (simp_all add: mxs)[3]\napply (erule compT_states(1))\napply assumption\napply (simp_all add: mxs mxl)[4]\napply (rule conjI)\napply (auto simp add: wt_start_def ty\\<^sub>i'_def ty\\<^sub>l_def list_all2_conv_all_nth\n  nth_Cons mxl split: nat.split dest: less_antisym)[1]\napply (frule (1) TC2.compT_wt_instrs [of P _ _ _ _ \"[]\" \"max_stack e\" \"Suc (length Ts + max_vars e)\" T\\<^sub>r])\napply simp_all\napply (clarsimp simp: after_def)\napply hypsubst_thin\napply (rule conjI)\napply (clarsimp simp: wt_instrs_def after_def mxl mxs)\napply clarsimp\napply (drule (1) less_antisym)\napply (clarsimp simp: wt_defs xcpt_app_pcs xcpt_eff_pcs ty\\<^sub>i'_def)\ndone\n(*>*)\n\nend\n\ndefinition compTP :: \"J\\<^sub>1_prog \\<Rightarrow> ty\\<^sub>P\" where\n  \"compTP P C M = (\n  let (D,Ts,T,e) = method P C M;\n       E = Class C # Ts;\n       A = \\<lfloor>{..size Ts}\\<rfloor>;\n       mxl = 1 + size Ts + max_vars e\n  in  (TC0.ty\\<^sub>i' mxl [] E A # TC1.compT\\<^sub>a P mxl E A [] e))\"\n\ntheorem wt_compP\\<^sub>2:\n  \"wf_J\\<^sub>1_prog P \\<Longrightarrow> wf_jvm_prog (compP\\<^sub>2 P)\"\n(*<*)\n  apply (simp add: wf_jvm_prog_def wf_jvm_prog_phi_def)\n  apply(rule_tac x = \"compTP P\" in exI)\n  apply (rule wf_prog_compPI)\n   prefer 2 apply assumption\n  apply (clarsimp simp add: wf_mdecl_def)\n  apply (simp add: compTP_def)\n  apply (rule TC2.compT_method [simplified])\n       apply (rule refl)\n       apply (rule refl)\n       apply assumption\n       apply assumption\n       apply assumption\n       apply assumption\n    apply (drule (1) sees_wf_mdecl)\n    apply (simp add: wf_mdecl_def)\n   apply (blast intro: sees_method_is_class)\n  apply assumption\n  done\n(*>*)\n\ntheorem wt_J2JVM:\n  \"wf_J_prog P \\<Longrightarrow> wf_jvm_prog (J2JVM P)\"\n(*<*)\napply(simp only:o_def J2JVM_def)\napply(blast intro:wt_compP\\<^sub>2 compP\\<^sub>1_pres_wf)\ndone\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Jinja/Compiler/TypeComp.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6513548646660542, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.2977582243230572}}
{"text": "(* *********************************************************************\n\n    Theory Prelims.thy is part of a framework for modelling,\n    verification and transformation of concurrent imperative\n    programs. Copyright (c) 2021  M. Bortin\n\n    The framework is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n    For more details see the license agreement (LICENSE) you should have\n    received along with the framework.\n    \n   ******************************************************************* *)\n\ntheory Prelims\nimports Main\nbegin\n\nlemma choice' :\n\"\\<exists>f. \\<forall>x. P x (f x) \\<Longrightarrow> \\<forall>x. \\<exists>y. P x y\"\nby force\n\nlemma choice'' :\n\"\\<forall>i. P i \\<longrightarrow> (\\<exists>j. Q i j) \\<Longrightarrow> \\<exists>\\<phi>. \\<forall>i. P i \\<longrightarrow> Q i (\\<phi> i)\"\n  by(rule choice, fast)\n\n\n\nlemma least_ix :\n\"P (j :: nat) \\<Longrightarrow>\n \\<exists>i\\<le>j. P i \\<and> (\\<forall>k<i. \\<not> P k)\" \n  apply(rule_tac x=\"LEAST j. P j\" in exI)\n  apply(rule conjI)\n   apply(erule Least_le)\n  apply(rule conjI)\n   apply(erule LeastI)\n  apply clarify\n  apply(drule not_less_Least)\n  by clarify\n\n\nlemma Int_Image :\n\"(R \\<inter> S) `` A \\<subseteq> (R `` A) \\<inter> (S `` A)\"\n  apply clarify\n  apply simp\n  apply(rule conjI)\n   apply(erule ImageI, assumption)+\n  done\n\nlemma Int_Image_singleton_sub :\n\"(R `` {a}) \\<inter> (S `` {a}) \\<subseteq> (R \\<inter> S) `` {a}\"\n  by blast\n\nlemma Int_Image_singleton :\n\"(R \\<inter> S) `` {a} = (R `` {a}) \\<inter> (S `` {a})\"\n  apply(rule equalityI)\n   apply(rule Int_Image)\n  by(rule Int_Image_singleton_sub)\n\n\nlemma pred_less :\n\"(0::nat) < x \\<Longrightarrow> x - 1 < x\"\n  by simp\n\n\n   \nlemma inj_on_imp_surj :\n\"inj_on \\<sigma> A \\<Longrightarrow>\n finite A \\<Longrightarrow>\n \\<forall>a\\<in>A. \\<sigma> a \\<in> A \\<Longrightarrow>\n \\<forall>b\\<in>A. \\<exists>a\\<in>A. \\<sigma> a = b\"\n  apply clarsimp\n  apply(rule ccontr, simp)\n  apply(subgoal_tac \"\\<sigma> ` A \\<subset> A\")\n   apply(frule psubset_card_mono, assumption)\n   apply(drule card_image)\n   apply simp\n  apply(rule psubsetI)\n   apply fastforce\n  apply(rule notI)\n  apply(drule equalityD2)\n  apply(drule subsetD, assumption)\n  apply fastforce\n  done\n    \n    \n\ncorollary inj_on_surj_set_intv :\n\"inj_on \\<sigma> {0..<(n :: nat)} \\<Longrightarrow>\n \\<forall>i<n. \\<sigma> i < n \\<Longrightarrow>\n \\<forall>j<n. \\<exists>i<n. \\<sigma> i = j\"\n  apply(drule inj_on_imp_surj, simp, simp)\n  by fastforce\n\n\nlemma mem_nth :\n\"x \\<in> set xs \\<Longrightarrow> \\<exists>i<length xs. x = xs!i\"\n  apply(induct xs, simp_all)\n  apply(erule disjE, clarsimp)\n   apply(rule_tac x=0 in exI, simp)\n  apply clarsimp\n  apply(rule_tac x=\"Suc i\" in exI, simp)\n  done\n\n\nlemma zip_nthD :\n\"(a, b) \\<in> set(zip xs zs) \\<Longrightarrow> \n \\<exists>i<length xs. a = xs!i \\<and> b = zs!i\"\n  apply(induct zs arbitrary: a b xs)\n   apply simp\n  apply(case_tac xs, simp)\n  apply clarsimp\n  apply(erule disjE, clarsimp)\n  apply(rule_tac x=0 in exI, simp)\n  by fastforce\n\n\nlemma map_zip_aux :\n\"\\<forall>sq \\<in> set sqs. length sq = n \\<Longrightarrow> length ps = length sqs \\<Longrightarrow>\n map (\\<lambda>x. (case x of (x, sq) \\<Rightarrow> sq @ [x]) ! n) (zip ps sqs) = ps\"\n  apply(induct ps arbitrary: sqs)\n   apply simp\n  apply clarsimp\n  apply(case_tac sqs, simp)\n  apply clarsimp\n done\n\nlemma map_zip_aux2 :\n\"\\<forall>sq \\<in> set sqs. length sq = n \\<Longrightarrow> m < n \\<Longrightarrow> length ps = length sqs \\<Longrightarrow>\n map ((\\<lambda>x. x ! m) \\<circ> (\\<lambda>(x, sq). sq @ [x])) (zip ps sqs) = map (\\<lambda>x. x ! m) sqs\"\n  apply(induct ps arbitrary: sqs)\n   apply simp\n  apply clarsimp\n  apply(case_tac sqs, simp)\n  apply clarsimp\n  apply(subst nth_append, simp)\n done\n\n\n\n\nend", "meta": {"author": "maksym-bortin", "repo": "a_framework", "sha": "df46703505efafcf1087d4461e93e502d94712ab", "save_path": "github-repos/isabelle/maksym-bortin-a_framework", "path": "github-repos/isabelle/maksym-bortin-a_framework/a_framework-df46703505efafcf1087d4461e93e502d94712ab/Prelims.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6001883449573376, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.29774973445369884}}
{"text": "(*  File:       Drop_And Pass_Compatibility.thy\n    Copyright   2021  Karlsruhe Institute of Technology (KIT)\n*)\n\\<^marker>\\<open>creator \"Karsten Diekhoff, Karlsruhe Institute of Technology (KIT)\"\\<close>\n\\<^marker>\\<open>contributor \"Jonas Kraemer, Karlsruhe Institute of Technology (KIT)\"\\<close>\n\\<^marker>\\<open>contributor \"Michael Kirsten, Karlsruhe Institute of Technology (KIT)\"\\<close>\n\nchapter \\<open>Compositional Structures\\<close>\n\nsection \\<open>Drop And Pass Compatibility\\<close>\n\ntheory Drop_And_Pass_Compatibility\n  imports \"Basic_Modules/Drop_Module\"\n          \"Basic_Modules/Pass_Module\"\nbegin\n\ntext\n\\<open>This is a collection of properties about the interplay and compatibility\nof both the drop module and the pass module.\\<close>\n\nsubsection \\<open>Properties\\<close>\n\ntheorem drop_zero_mod_rej_zero[simp]:\n  assumes order: \"linear_order r\"\n  shows \"rejects 0 (drop_module 0 r)\"\n  unfolding rejects_def\nproof (safe)\n  show \"electoral_module (drop_module 0 r)\"\n    using order\n    by simp\nnext\n  fix\n    A :: \"'a set\" and\n    p :: \"'a Profile\" and\n    vs:: \"'a Pair_Vectors\"\n  assume\n    card_pos: \"0 \\<le> card A\" and\n    finite_A: \"finite A\" and\n    prof_A: \"profile A p\"\n  have f1: \"connex UNIV r\"\n    using assms lin_ord_imp_connex\n    by auto\n  obtain aa :: \"('a \\<Rightarrow> bool) \\<Rightarrow> 'a\" where\n    f2:\n    \"\\<forall>p. (Collect p = {} \\<longrightarrow> (\\<forall>a. \\<not> p a)) \\<and>\n          (Collect p \\<noteq> {} \\<longrightarrow> p (aa p))\"\n    by moura\n  have f3: \"\\<forall>a. (a::'a) \\<notin> {}\"\n    using empty_iff\n    by simp\n  have connex:\n    \"connex A (limit A r)\"\n    using f1 limit_presv_connex subset_UNIV\n    by metis\n  have\n    \"\\<forall>A a. A \\<noteq> {} \\<or> (a::'a) \\<notin> A\"\n    by simp\n  hence f4:\n    \"\\<forall>a Aa.\n      \\<not> connex Aa (limit A r) \\<or> a \\<notin> Aa \\<or> a \\<notin> A \\<or>\n        \\<not> card (above (limit A r) a) \\<le> 0\"\n    using above_connex above_presv_limit card_eq_0_iff\n          finite_A finite_subset le_0_eq order\n    by (metis (no_types))\n  have \"{a \\<in> A. card(above (limit A r) a) \\<le> 0} = {}\"\n    using connex f4\n    by auto\n  hence \"card {a \\<in> A. card(above (limit A r) a) \\<le> 0} = 0\"\n    using card.empty\n    by (metis (full_types))\n  thus \"card (reject (drop_module 0 r) A p vs) = 0\"\n    by simp\nqed\n\n(*\n  The drop module rejects n alternatives (if there are n alternatives).\n  NOTE: The induction proof is still missing. Following is the proof for n=2.\n*)\ntheorem drop_two_mod_rej_two[simp]:\n  assumes order: \"linear_order r\"\n  shows \"rejects 2 (drop_module 2 r)\"\nproof -\n  have rej_drop_eq_def_pass:\n    \"reject (drop_module 2 r) = defer (pass_module 2 r)\"\n    by simp\n  thus ?thesis\n  proof -\n    obtain\n      AA :: \"('a Electoral_Module) \\<Rightarrow> nat \\<Rightarrow> 'a set\" and\n      rrs :: \"('a Electoral_Module) \\<Rightarrow> nat \\<Rightarrow> 'a Profile\" and\n      vvs :: \"('a Electoral_Module) \\<Rightarrow> nat \\<Rightarrow> 'a Pair_Vectors\"  where\n      \"\\<forall>x0 x1. (\\<exists>v2 v3 v4. (x1 \\<le> card v2 \\<and> finite_profile v2 v3 \\<and> vector_pair v2 v4) \\<and>\n          card (reject x0 v2 v3 v4) \\<noteq> x1) =\n              ((x1 \\<le> card (AA x0 x1) \\<and> finite_profile (AA x0 x1) (rrs x0 x1) \\<and>\n                vector_pair (AA x0 x1) (vvs x0 x1)) \\<and>\n                card (reject x0 (AA x0 x1) (rrs x0 x1) (vvs x0 x1)) \\<noteq> x1)\"\n      by moura\n    hence\n      \"\\<forall>n f. (\\<not> rejects n f \\<or> electoral_module f \\<and>\n          (\\<forall>A rs vs. (\\<not> n \\<le> card A \\<or> infinite A \\<or> \\<not> profile A rs \\<or> \\<not> vector_pair A vs) \\<or>\n              card (reject f A rs vs) = n)) \\<and>\n          (rejects n f \\<or> \\<not> electoral_module f \\<or> (n \\<le> card (AA f n) \\<and>\n              finite_profile (AA f n) (rrs f n) \\<and> vector_pair (AA f n) (vvs f n)) \\<and>\n              card (reject f (AA f n) (rrs f n) (vvs f n)) \\<noteq> n)\"\n      using rejects_def\n      by fastforce\n    hence f1:\n      \"\\<forall>n f. (\\<not> rejects n f \\<or> electoral_module f \\<and>\n        (\\<forall>A rs vs. \\<not> n \\<le> card A \\<or> infinite A \\<or> \\<not> profile A rs \\<or> \\<not> vector_pair A vs \\<or>\n            card (reject f A rs vs) = n)) \\<and>\n        (rejects n f \\<or> \\<not> electoral_module f \\<or> n \\<le> card (AA f n) \\<and>\n            finite (AA f n) \\<and> profile (AA f n) (rrs f n) \\<and> \n            vector_pair (AA f n) (vvs f n) \\<and>\n            card (reject f (AA f n) (rrs f n) (vvs f n)) \\<noteq> n)\"  \n      by presburger\n    have\n      \"\\<not> 2 \\<le> card (AA (drop_module 2 r) 2) \\<or>\n          infinite (AA (drop_module 2 r) 2) \\<or>\n          \\<not> profile (AA (drop_module 2 r) 2) (rrs (drop_module 2 r) 2) \\<or>\n          \\<not> vector_pair (AA (drop_module 2 r) 2) (vvs (drop_module 2 r) 2) \\<or>\n          card (reject (drop_module 2 r) (AA (drop_module 2 r) 2)\n              (rrs (drop_module 2 r) 2) (vvs (drop_module 2 r) 2)) = 2\"\n      using rej_drop_eq_def_pass defers_def order\n            pass_two_mod_def_two\n      by (metis (no_types))\n    thus ?thesis\n      using f1 drop_mod_sound order\n      by blast\n  qed\nqed\n\n(*The pass and drop module are (disjoint-)compatible.*)\ntheorem drop_pass_disj_compat[simp]:\n  assumes order: \"linear_order r\"\n  shows \"disjoint_compatibility (drop_module n r) (pass_module n r)\"\n  unfolding disjoint_compatibility_def\nproof (safe)\n  show \"electoral_module (drop_module n r)\"\n    using order\n    by simp\nnext\n  show \"electoral_module (pass_module n r)\"\n    using order\n    by simp\nnext\n\n  fix\n    S :: \"'a set\"\n  assume\n    fin: \"finite S\"\n  obtain\n    p :: \"'a Profile\"\n    where \"finite_profile S p\"  \n    using empty_iff empty_set fin profile_set\n    by metis\n  show \"\\<exists>A\\<subseteq>S. (\\<forall>a\\<in>A. indep_of_alt (drop_module n r) S a \\<and>\n                       (\\<forall>p vs. finite_profile S p \\<and> vector_pair S vs \\<longrightarrow> a \\<in> reject (drop_module n r) S p vs)) \\<and>\n                (\\<forall>a\\<in>S - A.\n                    indep_of_alt (pass_module n r) S a \\<and>\n                    (\\<forall>p vs. finite_profile S p \\<and> vector_pair S vs \\<longrightarrow> a \\<in> reject (pass_module n r) S p vs))\"\n  proof\n    have same_A:\n      \"\\<forall>p q. (finite_profile S p \\<and> finite_profile S q) \\<longrightarrow>\n        reject (drop_module n r) S p vs =\n          reject (drop_module n r) S q vs\"\n      by auto\n    let ?A = \"reject (drop_module n r) S p vs\"\n    have \"?A \\<subseteq> S\"\n      by auto\n    moreover have\n      \"(\\<forall>a \\<in> ?A. indep_of_alt (drop_module n r) S a)\"\n      using order\n      by (simp add: indep_of_alt_def)\n    moreover have\n      \"\\<forall>a \\<in> ?A. \\<forall>p vs. finite_profile S p \\<and> finite_pair_vectors S vs \\<longrightarrow>\n        a \\<in> reject (drop_module n r) S p vs\"\n      by auto\n    moreover have\n      \"(\\<forall>a \\<in> S-?A. indep_of_alt (pass_module n r) S a)\"\n      using order\n      by (simp add: indep_of_alt_def)\n    moreover have\n      \"\\<forall>a \\<in> S-?A. \\<forall>p vs. finite_profile S p \\<and> finite_pair_vectors S vs \\<longrightarrow>\n        a \\<in> reject (pass_module n r) S p vs\"\n      by auto\n    ultimately show\n      \"?A \\<subseteq> S \\<and>\n        (\\<forall>a \\<in> ?A. indep_of_alt (drop_module n r) S a \\<and>\n          (\\<forall>p vs. finite_profile S p \\<and> vector_pair S vs \\<longrightarrow>\n            a \\<in> reject (drop_module n r) S p vs)) \\<and>\n        (\\<forall>a \\<in> S-?A. indep_of_alt (pass_module n r) S a \\<and>\n          (\\<forall>p vs. finite_profile S p \\<and> vector_pair S vs \\<longrightarrow>\n            a \\<in> reject (pass_module n r) S p vs))\"\n      by simp\n  qed\nqed\n\nend\n", "meta": {"author": "ChrisMackKit", "repo": "ba-scoring-rule-reinforcement-homogeneity", "sha": "d87febd04743389ac578b332349ae446b9c55e89", "save_path": "github-repos/isabelle/ChrisMackKit-ba-scoring-rule-reinforcement-homogeneity", "path": "github-repos/isabelle/ChrisMackKit-ba-scoring-rule-reinforcement-homogeneity/ba-scoring-rule-reinforcement-homogeneity-d87febd04743389ac578b332349ae446b9c55e89/verifiedVotingRuleConstruction-master/theories/Compositional_Structures/Drop_And_Pass_Compatibility.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6001883449573376, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.29774973445369884}}
{"text": "(*\n * Copyright 2016, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the GNU General Public License version 2. Note that NO WARRANTY is provided.\n * See \"LICENSE_GPLv2.txt\" for details.\n *\n * @TAG(NICTA_GPL)\n *)\n\ntheory SerialS\nimports\n  PleSle\nbegin  \ntype_synonym U8 = \"8 word\"\ntype_synonym U16 = \"16 word\"\ntype_synonym U32 = \"32 word\"\ntype_synonym U64 = \"64 word\"\n\nlemma sle32_length:\n  \"length (sle32 x) = 4\"\n  by (simp add: sle32_def length_word_rsplit_exp_size' word_size)\n\nlemma ple32_word_rcat_eq1:\n  \"ple32 (sle32 x @ xs) 0 = x\"\n  apply (simp only: ple32_def unat_0)\n  apply (subst drop_0)\n  apply (cut_tac x=x in sle32_length)\n  apply (simp add: sle32_def word_rcat_rsplit)\n  done\n  \nlemma ple32_word_rcat_eq2:\n \"length ys = (unat n) \\<Longrightarrow> ple32 (ys @ sle32 x @ xs) n = x\"\n  by (simp add: ple32_def ple32_word_rcat_eq1[simplified ple32_def, simplified])\n\nlemmas ple32_word_rcat_eq = ple32_word_rcat_eq1 ple32_word_rcat_eq2\n\nlemma sle64_length:\n  \"length (sle64 x) = 8\"\n  by (simp add: sle64_def length_word_rsplit_exp_size' word_size)\n  \nlemma ple64_word_rcat_eq1:\n  \"ple64 (sle64 x @ xs) 0 = x\"\n  apply (simp only: ple64_def unat_0)\n  apply (subst drop_0)\n  apply (cut_tac x=x in sle64_length)\n  apply (simp add: sle64_def word_rcat_rsplit)\n done\n  \nlemma ple64_word_rcat_eq2:\n \"length ys = (unat n) \\<Longrightarrow> ple64 (ys @ sle64 x @ xs) n = x\"\n  by (simp add: ple64_def ple64_word_rcat_eq1[simplified ple64_def, simplified])\n\nlemmas ple64_word_rcat_eq = ple64_word_rcat_eq1 ple64_word_rcat_eq2\n\ndefinition pObjDel :: \"U8 list \\<Rightarrow> U32 \\<Rightarrow> U64 ObjDel\"\nwhere\n  \"pObjDel data' offs' \\<equiv> ObjDel.make (ple64 data' offs')  \\<comment> \\<open>id\\<close>\n   \\<comment> \\<open>End 4 bytes\\<close>\"\n       \ndefinition sObjDel :: \"ObjDel\\<^sub>T \\<Rightarrow> U8 list\"\nwhere\n  \"sObjDel odel \\<equiv> (sle64 $ ObjDel.id\\<^sub>f odel)\"  (* id *) (* End 8 bytes *)\n\nlemma objDel_inverse:\n \"pObjDel (sObjDel odel) 0 = odel\"\n  apply(simp add: pObjDel_def sObjDel_def)\n  apply(simp add: ObjDel.defs)\n  using ple64_word_rcat_eq[where xs=Nil]\n  by simp\n\ndefinition pObjData :: \"U8 list \\<Rightarrow> U32 \\<Rightarrow> U32 \\<Rightarrow> ObjData\\<^sub>T\"\nwhere\n  \"pObjData data offs olen \\<equiv>\n   ObjData.make (ple64 data offs) \\<comment> \\<open> id \\<close>\n     (WordArrayT.make $ slice (unat (offs + 8)) (unat (offs + 8) + unat (olen - bilbyFsObjHeaderSize - bilbyFsObjDataHeaderSize)) data)\"\n\ndefinition sObjData :: \"ObjData\\<^sub>T \\<Rightarrow> U32 \\<Rightarrow> U8 list\"\nwhere\n  \"sObjData odata len \\<equiv> (sle64 $ ObjData.id\\<^sub>f odata) @ take (unat len) (\\<alpha>wa (ObjData.odata\\<^sub>f odata))\"\n\nlemma length_sle32: \n \"length ((sle32 (x::U32))::U8 list) = 4\"\nby (simp add: Word.length_word_rsplit_exp_size' Word.word_size sle32_def )\n\nlemma length_sle64: \n \"length ((sle64 (x::U64))::U8 list) = 8\"\nby (simp add: Word.length_word_rsplit_exp_size' Word.word_size sle64_def )\n\nlemma objData_inverse:\n  \"unat (len - bilbyFsObjHeaderSize - bilbyFsObjDataHeaderSize) = length (\\<alpha>wa (odata\\<^sub>f odata)) \\<Longrightarrow>\n  len - bilbyFsObjHeaderSize - bilbyFsObjDataHeaderSize < len \\<Longrightarrow>\n  pObjData (sObjData odata len) 0 len = odata\"\n  apply(simp add: pObjData_def)\n  apply(simp add: sObjData_def)\n  apply(simp add: ObjData.defs)\n  apply(simp add: ple64_word_rcat_eq length_sle64 slice_def)\n  apply (subgoal_tac \"unat len \\<ge> length (\\<alpha>wa (odata\\<^sub>f odata)) \")\n   apply (simp add:  wordarray_make')\n  apply unat_arith\n done\n\ndefinition\n pu8 :: \"U8 list \\<Rightarrow> U32 \\<Rightarrow> U8\"\nwhere\n \"pu8 xs offs =  word_rcat (slice (unat offs) (unat offs+1) xs)\"\n \ndefinition pObjDentry :: \"U8 list \\<Rightarrow> U32 \\<Rightarrow> ObjDentry\\<^sub>T\"\nwhere\n \"pObjDentry data offs \\<equiv>\n   let nlen = ple16 data (offs+6)\n   in ObjDentry.make\n    (ple32 data (offs+0)) \\<comment> \\<open> ino \\<close>\n    (pu8 data (offs+4))   \\<comment> \\<open> dtype \\<close>\n    \\<comment> \\<open> 1 byte padding \\<close>\n    nlen  \\<comment> \\<open> nlen \\<close>\n    (WordArrayT.make $ slice (unat (offs+ 8)) (unat (offs + 8) + unat nlen) data) \\<comment> \\<open> name \\<close>\"\n\ndefinition pArrObjDentry :: \"U8 list \\<Rightarrow> U32 \\<Rightarrow> U32 \\<Rightarrow> (ObjDentry\\<^sub>T Array \\<times> 32 word \\<times> 32 word list)\"\nwhere\n \"pArrObjDentry data offs nb_dentry =\n    (case (fold      \n    (\\<lambda>_ (xs,doffs,offslist).\n      let dentry = pObjDentry data doffs ;\n          newoffs = doffs +  8 + wordarray_length (ObjDentry.name\\<^sub>f dentry)\n      in (xs@[Option.Some dentry], newoffs, offslist@ [newoffs])) [0..<unat nb_dentry] ([], offs, []))\n   of (xs, doffs, offslist) \\<Rightarrow> (ArrayT.make (xs@ [Option.None ()]), doffs, offslist))\"\n\ndefinition pObjDentarr :: \"U8 list \\<Rightarrow> U32 \\<Rightarrow> U32 \\<Rightarrow> ObjDentarr\\<^sub>T\"\nwhere\n\"pObjDentarr data offs olen \\<equiv>\n let nb_dentry = ple32 data (offs+8)\n in ObjDentarr.make\n     (ple64 data offs) \\<comment> \\<open> id \\<close>\n     (nb_dentry) \\<comment> \\<open> nb_dentry \\<close>\n     (prod.fst (pArrObjDentry (take (unat (offs+olen-bilbyFsObjHeaderSize)) data) (offs+bilbyFsObjDentarrHeaderSize) nb_dentry))\n     \"\n\ndefinition pObjDentarrSize :: \"U8 list \\<Rightarrow> U32 \\<Rightarrow> U32 \\<Rightarrow> U32\"\nwhere\n\"pObjDentarrSize data offs olen \\<equiv>\n let nb_dentry = ple32 data (offs+8)\n in (prod.fst (prod.snd (pArrObjDentry (take (unat (offs+olen-bilbyFsObjHeaderSize)) data) (offs+bilbyFsObjDentarrHeaderSize) nb_dentry)))\n \"\n\ndefinition pObjSuper :: \"U8 list \\<Rightarrow> U32 \\<Rightarrow> ObjSuper\\<^sub>T\"\nwhere\n  \"pObjSuper data offs \\<equiv>\n   ObjSuper.make\n     (ple32 data offs) \\<comment> \\<open> nb_eb \\<close>\n     (ple32 data (offs+4)) \\<comment> \\<open> eb_size \\<close>\n     (ple32 data (offs+8)) \\<comment> \\<open> io_size \\<close>\n     (ple32 data (offs+12)) \\<comment> \\<open> nb_reserved_gc \\<close>\n     (ple32 data (offs+16)) \\<comment> \\<open> nb_reserved_del \\<close>\n     (ple32 data (offs+20)) \\<comment> \\<open> cur_eb \\<close>\n     (ple32 data (offs+24)) \\<comment> \\<open> cur_offs \\<close>\n     (ple32 data (offs+28)) \\<comment> \\<open> last_inum \\<close>\n     (ple64 data (offs+32)) \\<comment> \\<open> next_sqnum \\<close>\n     \"\n\n(* TODO: we do not have pObjSumEntry . Probably we need it.*)\ndefinition sObjSumEntry :: \"ObjSumEntry\\<^sub>T \\<Rightarrow> U8 list\"\nwhere\n \"sObjSumEntry ose \\<equiv> \n   (sle64 $ ObjSumEntry.id\\<^sub>f ose)\n @ (sle64 $ ObjSumEntry.sqnum\\<^sub>f ose)\n @ (sle32 $ ObjSumEntry.len\\<^sub>f ose)\n @ (sle32 $ ObjSumEntry.del_flags_and_offs\\<^sub>f ose)\n @ (sle16 $ ObjSumEntry.count\\<^sub>f ose)\"\n\nconsts sObjSuper :: \"ObjSuper\\<^sub>T \\<Rightarrow> U8 list\" \n\ntype_synonym Buffer\\<^sub>T = \"(U8 WordArray, U32) Buffer\"\n\ndefinition bounded :: \"Buffer\\<^sub>T \\<Rightarrow> U8 list\"\nwhere\n \"bounded buf = take (unat (bound\\<^sub>f buf)) (WordArrayT.\\<alpha>wa (data\\<^sub>f buf))\"\n\ndefinition wellformed_buf :: \"Buffer\\<^sub>T \\<Rightarrow> bool\"\nwhere\n \"wellformed_buf buf \\<equiv> unat (bound\\<^sub>f buf) \\<le> List.length (\\<alpha>wa (Buffer.data\\<^sub>f buf))\"\n\nlemma elem_take_n:\n \"i<n \\<Longrightarrow> (take n xs ! i) = xs ! i\"\n by simp\n\nlemma deserialise_le32_bounded_ret:\nassumes bounded:\n  \"bbuf = bounded buf\"\nassumes valid_offs:\n  \"unat offs + 3 < length (bounded buf)\"\nshows\n  \"deserialise_le32 (buf, offs) = ple32 bbuf offs\"\napply (simp add: bounded)\nusing valid_offs\n  apply (subgoal_tac \"(\\<forall>i\\<in>{0..3}. unat (offs+i) < length (bounded buf))\")\n   prefer 2\n   apply unat_arith\n  apply (simp add: bounded_def)\n  apply (clarsimp simp: wordarray_get_ret[where arr=\"data\\<^sub>f buf\"] ple32_def \n                        deserialise_le32_def)\n  apply (subgoal_tac \"\\<forall>j\\<in>{1..3}. (unat (offs + j) > 0)\")\n   prefer 2\n   apply clarsimp\n   apply (drule_tac x=j in bspec, simp)\n   apply unat_arith\n  apply (subst take_drop_decomp, (simp+))+\n  apply (subst unatSuc[symmetric], (simp add: unat_gt_0[symmetric] add.commute[where b=offs]))+\n  apply simp\n  apply (rule trans, rule word_rcat_rsplit[symmetric])\n  apply (rule arg_cong[where f=word_rcat])\n  apply (subst word_rsplit_upt[where n=4], simp add: word_size)\n   apply simp\n  apply (simp add: upt_rec shiftr_over_or_dist shiftl_shiftr1 shiftl_shiftr2 word_size)\n  apply (safe intro!: word_eqI, simp_all add: word_size word_ops_nth_size nth_ucast\n        nth_shiftr nth_shiftl add.commute[where b=offs] test_bit_out_of_bounds)\n done\n \nlemma deserialise_le64_bounded_ret:\nassumes bounded:\n  \"bbuf = bounded buf\"\nassumes valid_offs:\n  \"unat offs + 7 < length (bounded buf)\"\nshows\n  \"deserialise_le64 (buf, offs) = ple64 bbuf offs\"\napply (simp add: bounded)\nusing valid_offs\n  apply (subgoal_tac \"(\\<forall>i\\<in>{0..7}. unat (offs+i) < length (bounded buf))\")\n   prefer 2\n   apply unat_arith\n  apply (simp add: bounded_def)\n  apply (clarsimp simp: wordarray_get_ret[where arr=\"data\\<^sub>f buf\"] ple64_def \n                       deserialise_le64_def)\n  apply (subgoal_tac \"\\<forall>j\\<in>{1..7}. (unat (offs + j) > 0)\")\n   prefer 2\n   apply clarsimp\n   apply (drule_tac x=j in bspec, simp)\n   apply unat_arith\n  (* feel free to improve this apply script..*)\n  apply (subst take_drop_decomp, (simp+))+\n  apply (subst unatSuc[symmetric], (simp add: unat_gt_0[symmetric] add.commute[where b=offs]))+\n  apply simp\n  apply (rule trans, rule word_rcat_rsplit[symmetric])\n  apply (rule arg_cong[where f=word_rcat])\n  apply (subst word_rsplit_upt[where n=8], simp add: word_size)\n   apply simp\n  apply (simp add: upt_rec shiftr_over_or_dist shiftl_shiftr1 shiftl_shiftr2 word_size)\n  apply (safe intro!: word_eqI, simp_all add: word_size word_ops_nth_size nth_ucast\n        nth_shiftr nth_shiftl add.commute[where b=offs] test_bit_out_of_bounds)\n  done\n\n\ndefinition buf_unchanged :: \"Buffer\\<^sub>T \\<Rightarrow> Buffer\\<^sub>T \\<Rightarrow> U32 \\<Rightarrow> U32 \\<Rightarrow> bool\"\nwhere\n \"buf_unchanged newbuf oldbuf offs' l \\<equiv> take (unat offs') (\\<alpha>wa (data\\<^sub>f newbuf)) = take (unat offs') (\\<alpha>wa (data\\<^sub>f oldbuf)) \\<and>\n  drop (unat offs' + unat l) (\\<alpha>wa (data\\<^sub>f newbuf)) = drop (unat offs' + unat l) (\\<alpha>wa (data\\<^sub>f oldbuf)) \\<and>\n  bound\\<^sub>f newbuf = bound\\<^sub>f oldbuf\"\n\nlemma bounded_le_length:\n  \"(length $ bounded  x) \\<le> length (\\<alpha>wa $ data\\<^sub>f x)\"\n  by (simp add: bounded_def)\n\nlemmas serialise_le64_simps = ArrA.make_def ElemA.make_def ElemAO.make_def ArrayUseValueP.defs\n                              setu8_def[unfolded sanitizers] wordarray_make bounded_def\n                             serialise_u8_def[unfolded tuple_simps sanitizers]\n\n(*\nlemma serialise_le64_ret:\nassumes valid_offs:\n  \"unat offs + 7 < length (bounded buf)\"\nassumes ret:\n  \"P (buf\\<lparr>data\\<^sub>f := WordArrayT.make (\\<alpha>wa (data\\<^sub>f buf)[\n      unat offs := u64_to_u8 v,\n      unat (offs+1) := u64_to_u8 (v >> 8),\n      unat (offs+2) := u64_to_u8 (v >> 16),\n      unat (offs+3) := u64_to_u8 (v >> 24),\n      unat (offs+4) := u64_to_u8 (v >> 32),\n      unat (offs+5) := u64_to_u8 (v >> 40),\n      unat (offs+6) := u64_to_u8 (v >> 48),\n      unat (offs+7) := u64_to_u8 (v >> 56)])\\<rparr>)\"\nnotes  wa_modify_ret = wordarray_modify_ret[rotated - 1, simplified Let_def ArrayUseValueP.defs ArrA.defs]\nshows\n  \"P (serialise_le64 (buf, offs, v))\"\n  unfolding serialise_le64_def[unfolded tuple_simps sanitizers]\n  apply (simp add: serialise_le64_simps Let_def)\n  apply (rule wa_modify_ret[where index=\"offs\"], simp add: serialise_le64_simps)\n    apply (rule wa_modify_ret[where index=\"offs+1\"], simp add: serialise_le64_simps)\n      apply (rule wa_modify_ret[where index=\"offs+2\"], simp add: serialise_le64_simps)\n        apply (rule wa_modify_ret[where index=\"offs+3\"], simp add: serialise_le64_simps)\n          apply (rule  wa_modify_ret[where index=\"offs+4\"], simp add: serialise_le64_simps)\n            apply (rule wa_modify_ret[where index=\"offs+5\"], simp add: serialise_le64_simps)\n              apply (rule wa_modify_ret[where index=\"offs+6\"], simp add: serialise_le64_simps)\n                apply (rule wa_modify_ret[where index=\"offs+7\"], simp add: serialise_le64_simps)\n                  using ret apply simp\n                 using valid_offs \n                 apply ((simp add: serialise_le64_simps) , unat_arith?)+\n done\n*)\n\nlemma take_irrelevance:\n  \"P (xs!(unat (x + y))) \\<Longrightarrow> unat (x + y) < unat z \\<Longrightarrow>\n   P ((take (unat z) xs)!(unat (x + y)))\" \n   by auto\n\nlemma unat_space:\nassumes \"unat (x + y) < z\"\nand \"unat (x + y) > unat x\"\nand \"y' \\<le> y\"\nshows \"unat (x + y') < z\"\nproof -\n  have \"\\<And>x\\<^sub>1. unat (x + y) \\<le> x\\<^sub>1 \\<or> \\<not> z \\<le> x\\<^sub>1\"\n  using assms(1)  by fastforce\n  thus ?thesis using assms\n  by (metis antisym_conv leI less_not_sym word_le_nat_alt word_plus_mono_right)\nqed\n\nlemma ple32_ret:\n  assumes 1:\"unat offs < unat (offs + 3)\"\n  assumes 2:\"unat (offs + 3) < (length $ bounded buf)\"\n  assumes 3:\"P(ple32 (bounded buf) offs)\"\n  shows \"P (deserialise_le32 (buf, offs))\"\n  proof -\n    from 1 2 have 4:\"unat offs + 3 < (length $ bounded buf)\" by (unat_arith, auto?)\n    show ?thesis\n    apply(subst deserialise_le32_bounded_ret)\n       apply simp\n      using 1 2 apply unat_arith\n      apply auto[1]\n     using 1 2 apply unat_arith\n    using 3 apply auto\n    done\n  qed\n\nlemma ple64_ret:\n  assumes 1:\"unat offs < unat (offs + 7)\"\n  assumes 2:\"unat (offs + 7) < (length $ bounded buf)\"\n  assumes 3:\"P (ple64 (bounded buf) offs)\"\n  shows \"P (deserialise_le64 (buf, offs))\"\n  proof -\n    from 1 2 have 4:\"unat offs + 7 < (length $ bounded buf)\" by (unat_arith, auto?)\n    show ?thesis\n    apply(subst deserialise_le64_bounded_ret)\n       apply simp\n      using 1 2 apply unat_arith\n      apply auto[1]\n     using 1 2 apply unat_arith\n    using 3 apply auto\n    done\n  qed\n\nlemma offs_le:\n assumes \"offs < offs+n\"\n assumes \"unat (offs + n) \\<le> ntake\"\n shows   \"unat offs < ntake\"\n using assms by unat_arith\n\nlemma word_add_eq_unat:\n assumes \"(offs::('a::len word)) < offs + n\"\n assumes \"i < n\"\n shows   \"unat (offs + i) = unat offs  + unat i\"\nusing assms by unat_arith\n\nlemma ple16_eq_slice2:\n assumes \"offs < offs + 2\" \n assumes \"unat offs + 2 \\<le> length xs\"\n shows   \"ple16 xs offs = ple16 (slice (unat offs) (unat offs + 2) xs) 0\"\n using assms by (simp add:  slice_def ple16_def drop_take word_add_eq_unat)\n\nlemma ple32_eq_slice4:\n assumes \"offs < offs + 4\" \n assumes \"unat offs + 4 \\<le> length xs\"\n shows   \"ple32 xs offs = ple32 (slice (unat offs) (unat offs + 4) xs) 0\"\n using assms by (simp add:  slice_def ple32_def drop_take word_add_eq_unat)\n\nlemma ple64_eq_slice8:\n assumes \"offs < offs + 8\" \n assumes \"unat offs + 8 \\<le> length xs\"\n shows   \"ple64 xs offs = ple64 (slice (unat offs) (unat offs + 8) xs) 0\"\n using assms by (simp add:  slice_def ple64_def drop_take word_add_eq_unat)\n\ndefinition pObjInode :: \"U8 list \\<Rightarrow> U32 \\<Rightarrow> ObjInode\\<^sub>T\"\nwhere\n \"pObjInode data offs \\<equiv>\n     ObjInode.make\n       (((ple64 data offs) AND (NOT (bilbyFsOidMaskAll OR ucast word32Max))) OR bilbyFsOidMaskInode) \\<comment> \\<open> id \\<close>\n       (ple64 data (offs+8)) \\<comment> \\<open> size \\<close>\n       (ple64 data (offs+16)) \\<comment> \\<open> atime \\<close>\n       (ple64 data (offs+24)) \\<comment> \\<open> ctime \\<close>\n       (ple64 data (offs+32)) \\<comment> \\<open> mtime \\<close>\n       (ple32 data (offs+40)) \\<comment> \\<open> nlink \\<close>\n       (ple32 data (offs+44)) \\<comment> \\<open> uid \\<close>\n       (ple32 data (offs+48)) \\<comment> \\<open> gid \\<close>\n       (ple32 data (offs+52)) \\<comment> \\<open> mode \\<close>\n       (ple32 data (offs+56)) \\<comment> \\<open> flags \\<close>\n       \\<comment> \\<open> End 60 bytes \\<close>\"\n\ndefinition sObjInode :: \"ObjInode\\<^sub>T \\<Rightarrow> U8 list\"\nwhere\n \"sObjInode odata \\<equiv> \n   (sle64 $ ObjInode.id\\<^sub>f odata) \n @ (sle64 $ ObjInode.size\\<^sub>f odata) \n @ (sle64 $ ObjInode.atime_sec\\<^sub>f odata)\n @ (sle64 $ ObjInode.ctime_sec\\<^sub>f odata)\n @ (sle64 $ ObjInode.mtime_sec\\<^sub>f odata)\n @ (sle32 $ ObjInode.nlink\\<^sub>f odata)\n @ (sle32 $ ObjInode.uid\\<^sub>f odata)\n @ (sle32 $ ObjInode.gid\\<^sub>f odata)\n @ (sle32 $ ObjInode.mode\\<^sub>f odata)\n @ (sle32 $ ObjInode.flags\\<^sub>f odata)  \\<comment> \\<open> End 60 bytes \\<close>\"\n\ndefinition pObjHeader :: \"U8 list \\<Rightarrow> U32 \\<Rightarrow> Obj\\<^sub>T\"\nwhere\n \"pObjHeader data offs \\<equiv>\n     Obj.make\n       (ple32 data offs)      \\<comment> \\<open> magic \\<close>\n       (ple32 data (offs+4))  \\<comment> \\<open> crc \\<close>\n       (ple64 data (offs+8))  \\<comment> \\<open> sqnum \\<close>\n       (offs)                    \\<comment> \\<open> offs not stored on medium \\<close> \\<comment> \\<open> changed back to offs, otherwise this doesnt correspond to the code\\<close>\n       (ple32 data (offs+16)) \\<comment> \\<open> len \\<close>\n       \\<comment> \\<open> 2 padding bytes \\<close>\n       (data!unat (offs+22))  \\<comment> \\<open> trans \\<close>\n       (data!unat (offs+23))  \\<comment> \\<open> otype \\<close>\n       undefined               \\<comment> \\<open> ounion \\<close>\n       \\<comment> \\<open> End 24 bytes \\<close>\"\n\ndefinition sObjHeader :: \"Obj\\<^sub>T \\<Rightarrow> U8 list\"\nwhere\n  \"sObjHeader obj \\<equiv>\n   (sle32 $ Obj.magic\\<^sub>f obj)\n @ (sle32 $ Obj.crc\\<^sub>f obj)\n @ (sle64 $ Obj.sqnum\\<^sub>f obj)\n @ (sle32 $ Obj.len\\<^sub>f obj)\n @ [bilbyFsPadByte]\n @ [bilbyFsPadByte]\n @ [Obj.trans\\<^sub>f obj]\n @ [Obj.otype\\<^sub>f obj] \\<comment> \\<open> End 24 bytes \\<close>\"\n\nlemma ObjHeader_inverse:\n  \"pObjHeader (sObjHeader obj@xs) 0 = (obj\\<lparr> Obj.ounion\\<^sub>f := undefined, Obj.offs\\<^sub>f := 0 \\<rparr>) \"\n   apply(clarsimp simp: pObjHeader_def sObjHeader_def)\n   apply(clarsimp simp: Obj.defs)\n   apply(clarsimp simp: ple32_word_rcat_eq length_sle32 length_sle64)\n   apply(clarsimp simp: bilbyFsObjHeaderSize_def bilbyFsPadByte_def)\n   proof -\n     let ?magic = \"sle32 (magic\\<^sub>f obj)\"\n     let ?crc = \"sle32 (crc\\<^sub>f obj)\"\n     let ?sqnum = \"sle64 (Obj.sqnum\\<^sub>f obj)\"\n     let ?len = \"sle32 (Obj.len\\<^sub>f obj)\"\n     let ?tail = \"0x42 # 0x42 # trans\\<^sub>f obj # otype\\<^sub>f obj # xs\"\n\n     have append_assoc_intro : \"\\<And>P ys1 ys2 xs. \n       P ((ys1 @ ys2) @ xs) \\<Longrightarrow> P (ys1 @ (ys2 @ xs))\" by auto\n\n     have sqnum: \"ple64 (?magic @ ?crc @ ?sqnum @ ?len @ ?tail) 8 = (Obj.sqnum\\<^sub>f obj)\"\n     apply(rule append_assoc_intro)\n     apply(rule ple64_word_rcat_eq)\n     apply(subst List.length_append)\n     using length_sle32 by auto\n\n     have len: \"ple32 (?magic @ ?crc @ ?sqnum @ ?len @ ?tail) 16 = Obj.len\\<^sub>f obj\"\n     apply(rule append_assoc_intro[of _ \"?magic\"])\n     apply(rule append_assoc_intro[of _ \"?magic @ ?crc\"])\n     apply(rule append_assoc_intro[of _ \"?magic @ ?crc @ ?sqnum\"])\n     apply(rule ple32_word_rcat_eq)\n     using length_sle32 length_sle64 by auto\n\n     have trans:\"(?magic @ ?crc @ ?sqnum @ ?len @ ?tail) ! 22 = Obj.trans\\<^sub>f obj\"\n     proof -\n       have \"length (?magic @ ?crc @ ?sqnum @ ?len @ (66::8 word) # [66::8 word]) = 22\"\n       using length_sle32 length_sle64 by simp\n       from this show ?thesis\n       by (metis (erased, hide_lams) append_Cons append_Nil append_assoc nth_append_length)\n     qed\n\n     have otype:\"(?magic @ ?crc @ ?sqnum @ ?len @ ?tail) ! 23 = Obj.otype\\<^sub>f obj\"\n     proof -\n       have \"length (?magic @ ?crc @ ?sqnum @ ?len @ (66::8 word) # (66::8 word) # [trans\\<^sub>f obj]) = 23\"\n       using length_sle32 length_sle64 by simp\n       from this show ?thesis\n       by (metis (erased, hide_lams) append_Cons append_Nil append_assoc nth_append_length)\n     qed\n\n     from sqnum len trans otype\n     show \n       \"\\<lparr>magic\\<^sub>f = magic\\<^sub>f obj, crc\\<^sub>f = crc\\<^sub>f obj,\n         sqnum\\<^sub>f = ple64 (?magic @ ?crc @ ?sqnum @ ?len @ ?tail) 8,\n         offs\\<^sub>f = 0,\n         len\\<^sub>f = ple32 (?magic @ ?crc @ ?sqnum @ ?len @ ?tail) 16,\n         trans\\<^sub>f = (?magic @ ?crc @ ?sqnum @ ?len @ ?tail) ! 22,\n         otype\\<^sub>f = (?magic @ ?crc @ ?sqnum @ ?len @ ?tail) ! 23,\n         ounion\\<^sub>f = undefined\\<rparr> = obj\\<lparr>ounion\\<^sub>f := undefined, Obj.offs\\<^sub>f := 0\\<rparr>\"\n      by auto\n   qed\n\nlemmas pObjHeader_simp =\n  pObjHeader_def Let_def Obj.make_def bilbyFsObjHeaderSize_def\n\ndefinition is_valid_ObjHeader :: \"Obj\\<^sub>T \\<Rightarrow> U8 list \\<Rightarrow> bool\"\nwhere\n \"is_valid_ObjHeader obj data \\<equiv>\n    magic\\<^sub>f obj = bilbyFsMagic \\<and>\n    (unat $ Obj.len\\<^sub>f obj) \\<le> length data \\<and>\n    trans\\<^sub>f obj \\<in> {bilbyFsTransIn, bilbyFsTransCommit} \\<and>\n    is_len_and_type_ok (otype\\<^sub>f obj, Obj.len\\<^sub>f obj)\"\n\nlemma is_len_and_type_ok_hdr_szD:\n  \"is_len_and_type_ok (otype, olen) \\<Longrightarrow> bilbyFsObjHeaderSize \\<le> olen\"\n by (auto simp add: \n         is_len_and_type_ok_def[unfolded sanitizers tuple_simps] \n        bilbyFsObjHeaderSize_def\n        prod.case_eq_if split: if_splits)\n  unat_arith+\n\nlemma is_valid_ObjHeader_len_facts:\n \"is_valid_ObjHeader obj data \\<Longrightarrow> unat bilbyFsObjHeaderSize \\<le> length data \\<and>\n   bilbyFsObjHeaderSize \\<le> Obj.len\\<^sub>f obj\"\n  apply (clarsimp simp: is_valid_ObjHeader_def)\n  apply (drule is_len_and_type_ok_hdr_szD)\n  apply unat_arith\n done\n\n\nlemmas otype_simps =\n  bilbyFsObjTypeInode_def\n  bilbyFsObjTypeData_def\n  bilbyFsObjTypeDentarr_def\n  bilbyFsObjTypeDel_def\n  bilbyFsObjTypePad_def\n  bilbyFsObjTypeSuper_def\n  bilbyFsObjTypeSum_def\n\nlemma is_len_and_type_ok_otype_valD:\n  \"is_len_and_type_ok (otype, olen) \\<Longrightarrow> otype \\<in> {bilbyFsObjTypeInode,bilbyFsObjTypeData,bilbyFsObjTypeDentarr,bilbyFsObjTypeDel,bilbyFsObjTypePad,bilbyFsObjTypeSuper,bilbyFsObjTypeSum} \"\n by (auto simp add: \n         is_len_and_type_ok_def[unfolded sanitizers tuple_simps] \n         otype_simps  split: if_splits)\n\ndefinition is_valid_Obj :: \"Obj\\<^sub>T \\<Rightarrow> bool\"\nwhere\n \"is_valid_Obj obj \\<equiv> \n    if otype\\<^sub>f obj = bilbyFsObjTypePad then \\<exists>v. ounion\\<^sub>f obj = TObjPad v else\n    if otype\\<^sub>f obj = bilbyFsObjTypeInode then \\<exists>v. ounion\\<^sub>f obj = TObjInode v else\n    if otype\\<^sub>f obj = bilbyFsObjTypeData then \\<exists>v. ounion\\<^sub>f obj = TObjData v else\n    if otype\\<^sub>f obj = bilbyFsObjTypeDentarr then \\<exists>v. ounion\\<^sub>f obj = TObjDentarr v else\n    if otype\\<^sub>f obj = bilbyFsObjTypeDel then \\<exists>v. ounion\\<^sub>f obj = TObjDel v else\n    True\"\n\n\nlemma is_valid_ObjHeader_len:\n  \"is_valid_ObjHeader obj data \\<Longrightarrow> bilbyFsObjHeaderSize \\<le> Obj.len\\<^sub>f obj\"\n  apply (clarsimp simp add: is_valid_ObjHeader_def)\n  apply (erule is_len_and_type_ok_hdr_szD)\n done\n\nlemma is_valid_ObjHeader_len_unat:\n  \"is_valid_ObjHeader obj data \\<Longrightarrow> unat bilbyFsObjHeaderSize \\<le> unat (Obj.len\\<^sub>f obj)\"\n by (drule is_valid_ObjHeader_len) unat_arith\n\nlemma is_valid_ObjHeader_buf_len:\n  \"is_valid_ObjHeader obj data \\<Longrightarrow>\n   (unat $ Obj.len\\<^sub>f obj) \\<le> length data \\<and>\n  unat bilbyFsObjHeaderSize \\<le> length data\"\n  apply (clarsimp simp add: is_valid_ObjHeader_def)\n  apply (drule is_len_and_type_ok_hdr_szD)\n  apply unat_arith\n done\n\ndefinition sObjPad :: \"U32 \\<Rightarrow> U8 list\"\nwhere\n  \"sObjPad olen \\<equiv> replicate (unat (olen - bilbyFsObjHeaderSize)) bilbyFsPadByte\"\n\nconsts pObjSummary :: \"U8 list \\<Rightarrow> U32 \\<Rightarrow> ObjSummary\\<^sub>T\"\nconsts pObjPad :: \"U8 list \\<Rightarrow> U32 \\<Rightarrow> unit\"\n\ndefinition pObjUnion :: \"U8 list \\<Rightarrow> U8 \\<Rightarrow> U32 \\<Rightarrow> U32 \\<Rightarrow> ObjUnion\\<^sub>T\"\nwhere\n \"pObjUnion data otype olen offs  \\<equiv>\n   if otype = bilbyFsObjTypePad then\n    TObjPad ()\n   else if otype = bilbyFsObjTypeData then\n    TObjData (pObjData data offs olen)\n   else if otype = bilbyFsObjTypeInode then\n    TObjInode (pObjInode data offs)\n   else if otype = bilbyFsObjTypeDentarr then\n    TObjDentarr (pObjDentarr data offs olen)\n   else if otype = bilbyFsObjTypeDel then\n    TObjDel (pObjDel data offs)\n   else if otype = bilbyFsObjTypeSuper then\n    TObjSuper (pObjSuper data offs)\n   else \\<comment> \\<open>if otype = bilbyFsObjTypeSum then\n    TObjSummary (pObjSummary data offs) \\<close> \\<comment> \\<open> see comments in: serial.cogent for deserialise_ObjUnion:\\<close>\n    TObjPad ()\"\n\ndefinition pObj :: \"U8 list \\<Rightarrow> U32 \\<Rightarrow> Obj\\<^sub>T\"\nwhere\n \"pObj data offs \\<equiv>\n   let obj = pObjHeader data offs\n   in obj \\<lparr>ounion\\<^sub>f:= pObjUnion (take (unat offs + unat (Obj.len\\<^sub>f obj)) data) (otype\\<^sub>f  obj) (Obj.len\\<^sub>f obj) (offs+bilbyFsObjHeaderSize)\\<rparr>\"\n\ntext \\<open> This could be implemented in Cogent instead \\<close>\ndefinition serialise_size_summary_Obj :: \"ObjSummary\\<^sub>T \\<Rightarrow> U32\"\nwhere\n \"serialise_size_summary_Obj summary \\<equiv>\n   bilbyFsObjHeaderSize + serialise_size_ObjSummary (nb_sum_entry\\<^sub>f summary)\"\n\ndefinition os_sum_sz :: \"OstoreState\\<^sub>T \\<Rightarrow> U32\"\nwhere\n \"os_sum_sz ostore_st \\<equiv> serialise_size_summary_Obj (summary\\<^sub>f ostore_st)\"\n\ndefinition bilbyFsMinObjSize :: U32\nwhere\n \"bilbyFsMinObjSize \\<equiv> bilbyFsObjHeaderSize + 8\"\n\nlemma deserialise_u8_ret:\nassumes wf: \"wellformed_buf buf\"\nassumes valid_offs:\n  \"offs < bound\\<^sub>f buf\"\nshows\n  \"deserialise_u8 (buf, offs) =  (\\<alpha>wa $ data\\<^sub>f buf) ! (unat offs)\"\nusing valid_offs wordarray_get_ret[where arr=\"data\\<^sub>f buf\" and index=offs]\n  wf[simplified wellformed_buf_def]\n  apply  (simp add: deserialise_u8_def)\n  apply (erule meta_impE)\n   apply unat_arith\n  apply simp\n done\n\nlemmas objheaders_simps = bilbyFsMagic_def\n    bilbyFsObjTypeInode_def bilbyFsObjTypeData_def\n                  bilbyFsObjTypeDentarr_def bilbyFsObjTypeDel_def bilbyFsObjTypePad_def\n                  bilbyFsObjTypeSuper_def bilbyFsObjTypeSum_def\n    bilbyFsTransIn_def bilbyFsTransCommit_def is_valid_ObjHeader_def pObjHeader_def\n    Obj.make_def  \n\nlemma deserialise_ObjHeader_ret:\n  assumes wf: \"wellformed_buf buf\"\n  assumes bound: \"offs + bilbyFsObjHeaderSize \\<le> bound\\<^sub>f buf\"\n  assumes no_of: \"offs < offs + bilbyFsObjHeaderSize\"\n  assumes err: \"\\<And>obj. P (obj, Error eInval)\"\n  assumes suc:\n  \"\\<And>obj offs'. \\<lbrakk>  is_valid_ObjHeader (pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs) (bounded buf) ;\n    \\<exists>v. obj\\<lparr>ounion\\<^sub>f:=v\\<rparr> = pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs;\n    offs' = offs + bilbyFsObjHeaderSize;\n    offs + Obj.len\\<^sub>f obj \\<le> bound\\<^sub>f buf;\n    offs < offs + Obj.len\\<^sub>f obj\\<rbrakk> \\<Longrightarrow> \n   P (obj, Success (offs'))\"\n notes bilbyFsObjHeaderSize_def[simp]\n  shows \"P (deserialise_ObjHeader (buf, offs, obj))\"\nproof -\n  have des_u8: \n    \"deserialise_u8 (buf, offs + 23) =  (\\<alpha>wa $ data\\<^sub>f buf) ! unat (offs + 23)\"  \n    \"deserialise_u8 (buf, offs + 22) =  (\\<alpha>wa $ data\\<^sub>f buf) ! unat (offs + 22)\"\n    using bound no_of\n    by - ((subst deserialise_u8_ret[OF wf]), (unat_arith, simp+))+\n\n  have des_le64:\n    \"deserialise_le64 (buf, offs + 8) = (ple64 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 8))\"\n  apply (rule ple64_ret)\n    using no_of\n    apply (simp add: )\n    apply (simp add: unat_arith_simps, unat_arith)\n   using bound wf no_of\n   apply (simp add: bounded_def wellformed_buf_def unat_arith_simps)\n   apply unat_arith\n  apply (simp add: bounded_def)\n  apply (subst  ple64_take)\n    using bound no_of\n    apply (simp add: bounded_def unat_arith_simps)\n    apply unat_arith\n   using wf bound no_of\n   apply (simp add: wellformed_buf_def unat_arith_simps)\n  apply unat_arith\n  apply simp\n done\n\n have des_le32:\n    \"deserialise_le32 (buf, offs) = (ple32 (\\<alpha>wa $ data\\<^sub>f buf) offs)\"  \n    \"deserialise_le32 (buf, offs+4) = (ple32 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 4))\"  \n    \"deserialise_le32 (buf, offs+16) = (ple32 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 16))\"\nML_prf \\<open>\nfun solve_deserialise_le32 ctxt = \n  let \n  val add_simp = Simplifier.add_simp;\n  fun add_simps ctxt [] = ctxt\n   |  add_simps ctxt (thm::thms) = add_simps (add_simp thm ctxt) thms;\n  val simp = Simplifier.asm_full_simp_tac;\n  val unat = (unat_arith_tac ctxt 1);\n\n  val ple32 = Method.rule_tac ctxt @{thms ple32_ret} [] 1;\n  val wf_bounded_unat = @{thms wellformed_buf_def bounded_def unat_arith_simps};\n  val simp_wf_bounded_unat = simp (add_simps ctxt wf_bounded_unat) 1;\n  val simp_bounded = simp (add_simp @{thm bounded_def} ctxt) 1;\n  val ple32_take = Method.rule_tac ctxt @{thms ple32_take} [] 1;\n  val simp_unat_plus = REPEAT_DETERM_N 2 ( simp_wf_bounded_unat THEN unat);\n  in\n    DETERM (ple32 THEN  simp_unat_plus )\n    THEN (simp_bounded THEN ple32_take THEN simp_unat_plus)\n  end\n\\<close>\n    using wf bound no_of\n    by - (tactic \\<open> solve_deserialise_le32  @{context} \\<close>)+\n  show ?thesis\n  unfolding deserialise_ObjHeader_def[unfolded tuple_simps sanitizers]\n  apply (clarsimp simp:Let_def err[simplified eInval_def])\n  apply (frule is_len_and_type_ok_hdr_szD)\n  apply (rule suc)\n       apply (clarsimp simp: objheaders_simps buf_simps des_le32 des_u8 )\n       apply (subgoal_tac \"\\<exists>v. ple32 (\\<alpha>wa (data\\<^sub>f buf)) (offs + 0x10) = v\")\n        prefer 2\n        apply clarsimp\n       apply (erule exE, simp add: bounded_def)\n       using bound no_of wf apply (simp add: wellformed_buf_def)\n      apply (rule conjI)\n       apply unat_arith\n      apply (unat_arith)\n     apply (rule_tac x=undefined in exI) \n     apply (simp add: pObjHeader_def Obj.defs buf_simps des_le32 des_u8 des_le64)\n    apply (simp)\n   apply (simp, unat_arith)+\n done\nqed\n\ndefinition\n  sObjUnion :: \"ObjUnion\\<^sub>T \\<Rightarrow> U8 \\<Rightarrow> U32 \\<Rightarrow> U8 list\"\nwhere\n \"sObjUnion (ou::ObjUnion\\<^sub>T) (otype::U8) (olen::U32) \\<equiv> \n  case ou of\n    TObjDentarr odent \\<Rightarrow> undefined \\<comment> \\<open> TODO: no dentarr support for now \\<close>\n  | TObjInode oinod \\<Rightarrow> sObjInode oinod\n  | TObjData odata \\<Rightarrow> sObjData odata olen\n  | TObjDel odel \\<Rightarrow> sObjDel odel\n  | TObjSuper osup \\<Rightarrow> sObjSuper osup\n  | TObjSummary g \\<Rightarrow> undefined \\<comment> \\<open> TODO: sObjSummary is undefined\\<close>\n  | TObjPad opad \\<Rightarrow>  sObjPad olen\"\n\nlemmas bilbyFsObjTypes = \n  bilbyFsObjTypePad_def\n  bilbyFsObjTypeInode_def\n  bilbyFsObjTypeData_def\n  bilbyFsObjTypeDentarr_def\n  bilbyFsObjTypeDel_def\n  bilbyFsObjTypeSuper_def\n  bilbyFsObjTypeSum_def\n\nlemma ObjUnion_inverse:\n \"\\<And>v. ounion = TObjPad v \\<Longrightarrow> otype = bilbyFsObjTypePad \\<Longrightarrow>\n pObjUnion (sObjUnion ounion otype olen @ xs) otype olen 0 = ounion\"\n by (simp add: sObjUnion_def pObjUnion_def )\n\nlemma length_sObjUnion:\n \"\\<And>v. ounion = TObjPad v \\<Longrightarrow> otype = bilbyFsObjTypePad \\<Longrightarrow>\n  olen \\<ge> bilbyFsObjHeaderSize  \\<Longrightarrow>\n    length (sObjUnion ounion otype olen) = unat olen - unat bilbyFsObjHeaderSize\"\n  apply (simp add: sObjUnion_def sObjPad_def )\n  apply unat_arith\n done\n\n\ndefinition sObj :: \"Obj\\<^sub>T \\<Rightarrow> U8 list\"\nwhere\n \"sObj obj \\<equiv> sObjHeader obj @ sObjUnion (ounion\\<^sub>f obj) (otype\\<^sub>f obj) (Obj.len\\<^sub>f obj)\"\n\nlemma length_sObjHeader:\n \"length (sObjHeader obj) = unat bilbyFsObjHeaderSize\"\n by (simp add: sObjHeader_def length_sle32 length_sle64 bilbyFsObjHeaderSize_def)\n \nlemma length_sObj:\n  \"Obj.len\\<^sub>f obj \\<ge> bilbyFsObjHeaderSize \\<Longrightarrow>\n   otype\\<^sub>f obj = bilbyFsObjTypePad \\<Longrightarrow> \n   is_valid_Obj obj \\<Longrightarrow>\n   length (sObj obj) = unat (Obj.len\\<^sub>f obj)\"\n  apply (clarsimp simp add: is_valid_Obj_def split:if_splits)\n  apply (drule (2)  length_sObjUnion)\n  apply (simp add: sObj_def length_sObjHeader word_le_nat_alt)\n done\n\nlemma Obj_inverse:\n \"otype\\<^sub>f obj = bilbyFsObjTypePad \\<Longrightarrow>\n   is_valid_Obj obj \\<Longrightarrow>\n   Obj.offs\\<^sub>f obj = 0 \\<Longrightarrow>\n   pObj (sObj obj @ xs) 0 = obj\"\n unfolding pObj_def sObj_def Let_def\n  apply (simp add: ObjHeader_inverse)\n  apply (clarsimp simp: is_valid_Obj_def)\n  apply (frule (1) ObjUnion_inverse)\n  apply (simp add: pObjUnion_def sObjHeader_def word_le_nat_alt length_sObjHeader)\n done\n\nlemma buf_sub_slice_len_simplified:\n  \"length v1 = unat j \\<Longrightarrow> unat (offs :: 32 word) < length (\\<alpha>wa (data\\<^sub>f buf)) \\<Longrightarrow>\n    unat (offs + j) \\<le> length (\\<alpha>wa (data\\<^sub>f buf)) \\<Longrightarrow>\n    unat offs < unat (offs + j) \\<Longrightarrow>\n     length (take (unat offs) (\\<alpha>wa (data\\<^sub>f buf)) @\n              v1 @\n              drop (unat (offs + j)) (\\<alpha>wa (data\\<^sub>f buf))) = length (\\<alpha>wa (data\\<^sub>f buf))\"\n    by simp unat_arith\n \nlemma buf_sub_slice_absorb:\n  assumes len1: \"length v1 = unat j\"\n  and     len2: \"length v2 = unat (k-j)\"\n  and   j_less: \"j \\<le> k\"\n  and     j_nz: \"j > 0\"\n  and    no_of: \"unat offs < unat (offs + k)\"\n  and   len_ge: \"unat (offs + k) \\<le> length (\\<alpha>wa (data\\<^sub>f buf))\"\n  shows \"(buf_sub_slice (buf \\<lparr>data\\<^sub>f := WordArrayT.make\n      (buf_sub_slice buf offs (offs + j) v1)\\<rparr>)\n                               (offs + j) (offs + k)\n                               v2) =\n             buf_sub_slice buf offs (offs + k) (v1 @ v2)\"\n  proof -\n    have j_sub: \"unat (offs + j) - unat offs = unat j\"\n      using no_of j_less by unat_arith\n    have j_max: \"unat (offs + j) \\<ge> unat offs\"\n      using no_of j_less by unat_arith\n    have k_j_sub: \"unat (offs + k) - unat (offs + j) = unat (k - j)\"\n      using no_of j_less by unat_arith\n    have k_sub: \"(unat (offs + k) - unat offs) = unat k\"\n      using no_of by unat_arith\n    have k_max: \"(unat (offs + k)) \\<ge> (unat offs)\"\n      using no_of by unat_arith\n    have k_j_max: \"(unat (offs + k)) \\<ge> (unat (offs + j))\"\n      using no_of j_less by unat_arith\n    have xx: \"\\<And>x v. data\\<^sub>f (x\\<lparr>data\\<^sub>f := v\\<rparr>) = v\"\n      by simp\n    have len_ge': \" unat offs < length (\\<alpha>wa (data\\<^sub>f buf))\"\n      using len_ge no_of by unat_arith\n    have len_ge'': \" unat (offs + j) \\<le> length (\\<alpha>wa (data\\<^sub>f buf))\"\n      using len_ge no_of j_less by unat_arith\n    have no_of': \"unat offs < unat (offs + j)\"\n      using no_of j_less j_nz by unat_arith\n    have len_app: \"length (v1 @ v2) = unat k\"\n      using len1 len2 j_less by unat_arith\n    have take_prefix: \"(take (unat (offs + j))\n           (take (unat offs) (\\<alpha>wa (data\\<^sub>f buf)) @\n            v1 @ drop (unat (offs + j)) (\\<alpha>wa (data\\<^sub>f buf)))) \n         = take (unat offs) (\\<alpha>wa (data\\<^sub>f buf)) @\n            v1\" \n        using len1 no_of' len_ge' j_sub by simp\n    have drop_prefix: \"drop (unat (offs + k))\n           (take (unat offs) (\\<alpha>wa (data\\<^sub>f buf)) @\n            v1 @ drop (unat (offs + j)) (\\<alpha>wa (data\\<^sub>f buf))) \n             = drop (unat (offs + k))(\\<alpha>wa (data\\<^sub>f buf))\"\n        apply (subgoal_tac \"(unat k - unat j + unat (offs + j)) = unat (offs + k)\")\n         prefer 2\n         using no_of j_less apply unat_arith\n        using len1 len_ge' k_sub j_less no_of apply simp\n        by unat_arith\n    thus ?thesis\n      unfolding buf_sub_slice_def \n      using j_sub j_max k_j_sub k_sub k_max k_j_max apply (simp only: max_absorb1)\n      using len1\n      apply (subst take_append[where n=\"unat j\"])+\n      apply (simp only: diff_self_eq_0 take_0 append_Nil2)\n      using len2 apply (subst take_append[where n=\"unat (k-j)\"])+\n      apply (simp only: diff_self_eq_0 take_0 append_Nil2)\n      using len_app apply (subst take_append[where n=\"unat k\"])\n      apply (simp only: diff_self_eq_0 take_0 append_Nil2)\n      using len1 k_j_sub apply (simp only:)\n      apply (simp only:  xx wordarray_make fun_app_def)\n      using len1 len2 len_app apply (simp only: take_all[where n=\"unat j\"]\n                                        take_all[where n=\"unat k\"]\n                                        take_all[where n=\"unat (k-j)\"])\n      using len1 len_ge len_ge' len_ge'' no_of' len_app no_of\n      by (simp add: buf_sub_slice_len_simplified take_prefix drop_prefix)\n   qed\n\n\nlemma serialise_u8_ret':\n    notes  wa_modify_ret = wordarray_modify_ret[rotated - 1, simplified Let_def ArrayUseValueP.defs]\n    assumes no_of: \"offs < offs + 1\"\n       and len_ge: \"unat offs + 1 \\<le> length (\\<alpha>wa (data\\<^sub>f buf))\"\n    shows \"serialise_u8 (buf, offs, v) = \n      buf \\<lparr>data\\<^sub>f := WordArrayT.make (buf_sub_slice buf offs (offs + 1) [v])\\<rparr>\"\n   proof -\n    have offs_sub: \"(unat (offs + 1) - unat offs) = 1\" using no_of by unat_arith\n    have no_of_unat: \" unat offs < unat (offs + 1)\" using no_of by (simp add: word_less_nat_alt)\n    show ?thesis\n    unfolding serialise_u8_def[unfolded sanitizers]\n  using no_of len_ge\n  apply simp\n  apply (rule wa_modify_ret[where index=\"offs\" and varr=\"(data\\<^sub>f buf)\" and modifier=\"setu8\"])\n   prefer 2\n   apply (unat_arith)\n  apply (simp_all add:ArrA.defs ElemAO.defs ElemA.defs\n                  setu8_def[unfolded tuple_simps sanitizers] wordarray_make buf_simps\n                  min_absorb1 min_absorb2)\n  apply (rule arg_cong[where f=\"\\<lambda>v. Buffer.data\\<^sub>f_update v buf\"])\n  apply (rule ext)\n\n  apply (rule arg_cong[where f=\"WordArrayT.make\"])\n  apply (simp only: list_eq_iff_nth_eq)\n  apply (clarsimp simp: buf_sub_slice_length)\n  apply (simp add: buf_sub_slice_def min_absorb1 min_absorb2)\n  apply (case_tac \"i=unat offs\")\n   apply (simp only: append_assoc[symmetric] nth_append)\n   apply (simp add: min_absorb1 min_absorb2)\n   apply unat_arith\n  apply (case_tac \"i < unat offs\")\n   apply (simp add: min_absorb1 offs_sub max_absorb1 no_of no_of_unat nth_append)\n  apply (simp add: min_absorb1 offs_sub max_absorb1)\n  apply (subgoal_tac \"(max (unat (offs + 1)) (unat offs)) = unat (offs + 1)\")\n   prefer 2\n   using no_of_unat apply auto[1]\n  apply (clarsimp simp add: nth_append nth_Cons split: nat.splits)\n  apply (subst nth_drop)\n   apply unat_arith\n  apply (subgoal_tac \"unat (offs + 1) = unat offs + 1\")\n   prefer 2\n   using no_of_unat offs_sub apply simp\n  apply simp\n  apply (subgoal_tac \"i = Suc (unat offs + x2)\")\n   apply simp\n  apply unat_arith\n  done\nqed\n\nlemma serialise_ObjHeader_ret:\n  assumes no_overflow: \"offs \\<le> offs + bilbyFsObjHeaderSize\"\n  and     is_valid_obj: \"is_valid_ObjHeader obj (drop (unat offs) (\\<alpha>wa (data\\<^sub>f buf)))\"\n  and     suc: \"\\<And>buf' offs'. \n   offs' = offs + bilbyFsObjHeaderSize \\<Longrightarrow>\n   buf' = buf\\<lparr>data\\<^sub>f := WordArrayT.make (buf_sub_slice buf offs (offs +bilbyFsObjHeaderSize) (sObjHeader obj))\\<rparr> \\<Longrightarrow>\n    P (buf', offs')\"\n  shows\n   \"P (serialise_ObjHeader (buf, offs, obj))\" \n   proof -\n    have offs_le_length: \"unat offs \\<le> length (\\<alpha>wa (data\\<^sub>f buf))\"\n      using is_valid_ObjHeader_len_facts[OF is_valid_obj]\n      by (clarsimp simp: is_valid_ObjHeader_def bilbyFsObjHeaderSize_def) unat_arith\n   have offs_sub_le: \"(unat (offs + bilbyFsObjHeaderSize) - unat offs) \\<le> (length (\\<alpha>wa (data\\<^sub>f buf)) - unat offs)\"\n      using is_valid_obj is_valid_ObjHeader_len_facts[OF is_valid_obj]\n      by (clarsimp simp: is_valid_ObjHeader_def bilbyFsObjHeaderSize_def) unat_arith\n   have offs_len_sub_eq: \"unat (offs + bilbyFsObjHeaderSize) - unat offs = unat (bilbyFsObjHeaderSize)\"\n      using no_overflow by unat_arith\n   have offs_obj_len_le_length: \"unat (offs + bilbyFsObjHeaderSize) \\<le> length (\\<alpha>wa (data\\<^sub>f buf))\"\n     using is_valid_obj offs_sub_le is_valid_ObjHeader_len_facts[OF is_valid_obj]\n     by (clarsimp simp: is_valid_ObjHeader_def bilbyFsObjHeaderSize_def) unat_arith\n   have offs_obj_len_le_length': \"(unat (offs + bilbyFsObjHeaderSize) -\n                (unat offs + unat bilbyFsObjHeaderSize)) \\<le> (length (\\<alpha>wa (data\\<^sub>f buf)) -\n                   (unat offs + unat bilbyFsObjHeaderSize))\"\n      using offs_obj_len_le_length by unat_arith   \n   have offs_plus_eq: \" (unat (offs + bilbyFsObjHeaderSize) = (unat offs + unat bilbyFsObjHeaderSize))\"\n      using no_overflow by unat_arith\n   show ?thesis\n  unfolding serialise_ObjHeader_def[unfolded sanitizers tuple_simps]\n  apply (simp add: Let_def)\n  apply (rule suc)\n   apply (simp add: bilbyFsObjHeaderSize_def)\n  apply (simp add: buf_sub_slice_def wordarray_make)\n  apply (simp add:  min_absorb1 offs_le_length offs_sub_le)\n  apply (simp add: offs_len_sub_eq length_sObjHeader\n                    offs_obj_len_le_length' offs_plus_eq)\n  using no_overflow apply (simp add: word_le_nat_alt max_absorb1 bilbyFsObjHeaderSize_def)\n  using no_overflow offs_obj_len_le_length apply (simp add: bilbyFsObjHeaderSize_def)\n  apply (subst serialise_le32_ret[where v=\"magic\\<^sub>f obj\"])\n    apply ((unat_arith, auto)+)[2]\n  apply (subst serialise_le32_ret[where v=\"crc\\<^sub>f obj\"])\n     apply ((unat_arith, auto)+)[1]\n    apply (simp add: buf_sub_slice_length wordarray_make)\n    apply (unat_arith, auto)[1]\n   apply (simp)\n   apply (subst add.commute[where a=8])\n   apply (subst buf_sub_slice_absorb[where offs=offs and j=4 and k=8, simplified])\n       apply (simp add: length_sle32)+\n     apply unat_arith \n     apply auto[1]\n    apply unat_arith \n    apply auto[1]\n   apply (subst serialise_le64_ret)\n     apply (unat_arith, auto)[1]\n\n    apply (simp add: buf_sub_slice_length wordarray_make)\n    apply (unat_arith, auto)[1]\n   apply simp\n   apply (subst add.commute[where a=\"0x10\"])\n   apply (subst buf_sub_slice_absorb)\n         apply (simp add: length_sle32 length_sle64)+\n     apply ((unat_arith, auto)+)[2]\n   apply (subst serialise_le32_ret)\n     apply ((unat_arith, auto)+)[1]\n    apply (simp add: buf_sub_slice_length wordarray_make)\n    apply (unat_arith, auto)[1]\n   apply (simp)\n   apply (subst add.commute[where a=\"0x14\"])\n   apply (subst buf_sub_slice_absorb)\n           apply (simp add: length_sle32 length_sle64)+\n      apply ((unat_arith, auto)+)[2]\n   apply (subst serialise_u8_ret'[where offs=\"offs + 0x14\"])\n     apply (unat_arith, auto)[1]\n    apply (simp add: buf_sub_slice_length wordarray_make)\n    apply (unat_arith, auto)[1]\n   apply (simp)\n   apply (subst add.commute[where a=\"0x15\"])\n   apply (subst buf_sub_slice_absorb)\n         apply (simp add: length_sle32 length_sle64)+\n     apply ((unat_arith, auto)+)[2]\n    apply (subst serialise_u8_ret'[where offs=\"offs + 0x15\"])\n     apply (unat_arith, auto)[1]\n    apply (simp add: buf_sub_slice_length wordarray_make)\n    apply (unat_arith, auto)[1]\n   apply (simp)\n   apply (subst add.commute[where a=\"0x16\"])\n   apply (subst buf_sub_slice_absorb)\n         apply (simp add: length_sle32 length_sle64)+\n     apply ((unat_arith, auto)+)[2] \n   apply (subst serialise_u8_ret'[where offs=\"offs + 0x16\"])\n     apply (unat_arith, auto)[1]\n    apply (simp add: buf_sub_slice_length wordarray_make)\n    apply (unat_arith, auto)[1]\n   apply (simp)\n   apply (subst add.commute[where a=\"0x17\"])\n   apply (subst buf_sub_slice_absorb)\n         apply (simp add: length_sle32 length_sle64)+\n     apply ((unat_arith, auto)+)[2] \n   apply (subst serialise_u8_ret'[where offs=\"offs + 0x17\"])\n     apply (unat_arith, auto)[1]\n    apply (simp add: buf_sub_slice_length wordarray_make)\n    apply (unat_arith, auto)[1]\n   apply (simp)\n   apply (subst add.commute[where a=\"0x18\"])\n   apply (subst buf_sub_slice_absorb)\n         apply (simp add: length_sle32 length_sle64)+\n     apply ((unat_arith, auto)+)[2]\n  \n  apply (simp add: sObjHeader_def bilbyFsPadByte_def)\n  apply (unfold buf_sub_slice_def)\n  apply (simp add: offs_len_sub_eq[unfolded bilbyFsObjHeaderSize_def, simplified])\n  apply (simp add: length_sle32 length_sle64)\n  apply (subgoal_tac \"(length (\\<alpha>wa (data\\<^sub>f buf)) - unat offs) \\<ge> 24\")\n   prefer 2\n   using offs_len_sub_eq bilbyFsObjHeaderSize_def apply (unat_arith, auto)[1]\n  apply simp\n  apply (subgoal_tac \"(unat (offs + 0x18)) > (unat offs)\")\n   prefer 2\n   using no_overflow apply (unat_arith, auto)[1]\n  apply (simp add: max_absorb1)\n  apply (rule arg_cong[where f=\"\\<lambda>v. Buffer.data\\<^sub>f_update v buf\"])\n  apply (rule ext)\n  apply (rule arg_cong[where f=\"WordArrayT.make\"])\n   apply simp\n  by (subst take_all, \n          ( simp add: length_sle32 length_sle64 | (unat_arith, auto)[1] )+\n     )+\nqed\n  \nlemmas ObjUnion_splits = ObjUnion.splits\n\nlemma take_drop_decomp:\"x \\<ge> a \\<Longrightarrow> take (x - a) (drop a xs) @ drop x xs = drop a xs\"\n  by (metis drop_take drop_take_drop)\n\nlemma serialise_ObjPad_ret:\n  assumes no_overflow: \"offs \\<le> offs + (olen - bilbyFsObjHeaderSize)\"\n  and     no_underflow: \"olen - bilbyFsObjHeaderSize \\<ge> 0\"\n  and     bound: \"offs+ (olen - bilbyFsObjHeaderSize) \\<le> bound\\<^sub>f buf \\<and> unat (bound\\<^sub>f buf) \\<le> length (\\<alpha>wa (data\\<^sub>f buf))\" \n  and     suc: \"\\<And>buf' offs'. \n   offs' = offs + olen - bilbyFsObjHeaderSize \\<Longrightarrow>\n   buf' = buf\\<lparr>data\\<^sub>f := WordArrayT.make (buf_sub_slice buf offs (offs + (olen - bilbyFsObjHeaderSize)) (sObjPad olen))\\<rparr> \\<Longrightarrow>\n    P (buf', offs')\"\n  shows\n   \"P (serialise_ObjPad (buf, offs, olen))\"\n   proof -\n   \n    have offs_le_bound: \"offs \\<le> bound\\<^sub>f buf\"\n      using bound no_overflow by unat_arith\n    have sub1: \"(unat (olen - 0x18)) \\<le> (unat (bound\\<^sub>f buf) - unat offs)\"\n      using bound no_overflow no_underflow apply (clarsimp simp: bilbyFsObjHeaderSize_def)\n      by unat_arith\n    have sub2: \"(unat (offs + (olen - 0x18)) - unat offs) = unat (olen - 0x18)\"\n      using bound no_overflow no_underflow apply (clarsimp simp: bilbyFsObjHeaderSize_def)\n      by unat_arith (* takes ages *)\n    have sub3: \"unat (olen - 0x18) \\<le> (length (\\<alpha>wa (data\\<^sub>f buf)) - unat offs)\"\n      using bound no_overflow no_underflow apply (clarsimp simp: bilbyFsObjHeaderSize_def)\n      by unat_arith\n    have sub4: \"(unat (offs + (olen - 0x18)) - (unat offs + unat (olen - 0x18))) = 0\"\n      using bound no_overflow no_underflow apply (clarsimp simp: bilbyFsObjHeaderSize_def)\n      by unat_arith\n    have sub5: \"(unat offs +\n            (unat (olen - 0x18) + length (\\<alpha>wa (data\\<^sub>f buf))) -\n            unat (offs + (olen - 0x18))) = length (\\<alpha>wa (data\\<^sub>f buf))\"\n      using bound no_overflow no_underflow apply (clarsimp simp: bilbyFsObjHeaderSize_def)\n      by unat_arith\n    have no_of_unat: \"unat offs \\<le> (unat (offs + (olen - 0x18)))\"\n      using no_overflow no_underflow by (simp add: bilbyFsObjHeaderSize_def word_le_nat_alt)\n    have assoc: \"(unat (offs + (olen - 0x18))) = unat offs + unat (olen - 0x18)\"\n      using no_overflow no_underflow by (simp add: bilbyFsObjHeaderSize_def) unat_arith\n   show ?thesis\n    unfolding serialise_ObjPad_def[unfolded sanitizers tuple_simps]\n  apply (simp add: Let_def split: ObjUnion_splits)\n  apply (rule suc)\n   apply (simp add: bilbyFsObjHeaderSize_def)\n  apply (subst buf_memset_eq)\n    using bound apply simp\n   using no_overflow  apply  (simp add: bilbyFsObjHeaderSize_def)\n  apply (rule arg_cong[where f=\"\\<lambda>v. Buffer.data\\<^sub>f_update v buf\"])\n  apply (rule ext)\n  apply (rule arg_cong[where f=\"WordArrayT.make\"])\n  using bound offs_le_bound apply (clarsimp simp: buf_sub_slice_def bilbyFsObjHeaderSize_def)\n  apply (simp add: sObjPad_def bilbyFsPadByte_def buf_simps\n                    min_absorb1 min_absorb2 word_le_nat_alt sub1 sub2 sub3 sub4 sub5\n                    bilbyFsObjHeaderSize_def no_of_unat max_absorb1 assoc)\n   \n  apply (subst take_drop_decomp)\n   using no_overflow no_underflow apply (clarsimp simp: bilbyFsObjHeaderSize_def)\n  apply simp\n done\n qed\n   \nlemma serialise_ObjUnion_ret:\n  assumes no_overflow: \"offs \\<le> offs + (olen - bilbyFsObjHeaderSize)\"\n  and     otype: \"otype = bilbyFsObjTypePad\"\n  and     ounion: \"\\<And>v. ounion = TObjPad v\"\n  and     olen: \" 0 \\<le> olen - bilbyFsObjHeaderSize\"\n  and     bound: \"offs + (olen - bilbyFsObjHeaderSize) \\<le> bound\\<^sub>f buf \\<and> unat (bound\\<^sub>f buf) \\<le> length (\\<alpha>wa (data\\<^sub>f buf))\" \n  and     suc: \"\\<And>buf' offs'. \n   offs' = offs + olen - bilbyFsObjHeaderSize \\<Longrightarrow>\n   buf' = buf\\<lparr>data\\<^sub>f := WordArrayT.make (buf_sub_slice buf offs (offs + (olen - bilbyFsObjHeaderSize)) (sObjUnion ounion otype olen))\\<rparr> \\<Longrightarrow>\n    P (buf', offs')\"\n  shows\n   \"P (serialise_ObjUnion (buf, offs, ounion, olen))\"\n  unfolding serialise_ObjUnion_def[unfolded sanitizers tuple_simps]\n  using ounion apply (simp add: Let_def split: ObjUnion_splits)\n  apply (rule serialise_ObjPad_ret)\n    using no_overflow apply simp\n    using olen apply simp\n    using bound apply simp\n   apply (rule suc, simp)\n  apply (simp add: sObjUnion_def)\n done\n\nlemma data\\<^sub>f_of_data\\<^sub>f_update:\n  \"data\\<^sub>f (x\\<lparr>data\\<^sub>f := v\\<rparr>) = v\"\n by simp\n\nlemma serialise_Obj_ret:\n  assumes no_overflow: \"offs \\<le> offs + Obj.len\\<^sub>f obj\"\n  and     is_valid_obj: \"is_valid_ObjHeader obj (drop (unat offs) (\\<alpha>wa (data\\<^sub>f buf)))\"\n  and     otype: \"otype\\<^sub>f obj = bilbyFsObjTypePad\"\n  and     ounion: \"\\<And>v. ounion\\<^sub>f obj = TObjPad v\"\n  and     bound: \" offs + Obj.len\\<^sub>f obj \\<le> bound\\<^sub>f buf \\<and>\n           unat (bound\\<^sub>f buf) \\<le> length (\\<alpha>wa (data\\<^sub>f buf))\"\n  and     suc: \"\\<And>buf'. \n   buf' = buf\\<lparr>data\\<^sub>f := WordArrayT.make (buf_sub_slice buf offs (offs + Obj.len\\<^sub>f obj) (sObj obj))\\<rparr> \\<Longrightarrow>\n    P (buf', offs + Obj.len\\<^sub>f obj)\"\n  shows\n   \"P (serialise_Obj (buf, offs, obj))\"\n   unfolding serialise_Obj_def[unfolded tuple_simps sanitizers]\n  apply (simp add: Let_def)\n  apply (rule serialise_ObjHeader_ret)\n    using no_overflow is_valid_obj apply (clarsimp simp: is_valid_ObjHeader_def bilbyFsObjHeaderSize_def)\n    apply (frule is_len_and_type_ok_hdr_szD, simp add: bilbyFsObjHeaderSize_def)\n    apply unat_arith\n   using is_valid_obj apply assumption\n  apply simp\n  apply (rule serialise_ObjUnion_ret)\n       using is_valid_obj no_overflow apply (clarsimp simp: is_valid_ObjHeader_def bilbyFsObjHeaderSize_def )\n       apply (frule  is_len_and_type_ok_hdr_szD)\n       apply (simp add: bilbyFsObjHeaderSize_def)\n       apply unat_arith\n      apply (rule otype)\n     using ounion apply simp\n    using is_valid_obj no_overflow apply (clarsimp simp: is_valid_ObjHeader_def bilbyFsObjHeaderSize_def)\n   using bound apply (simp add: wordarray_make buf_sub_slice_length)\n  apply simp\n apply (rule suc)\n    apply (rule arg_cong[where f=\"\\<lambda>v. Buffer.data\\<^sub>f_update v buf\"])\n   apply (rule ext)\n   apply (rule arg_cong[where f=\"WordArrayT.make\"])\n   apply (thin_tac x for x)+\n   apply (subst buf_sub_slice_absorb)\n         apply (simp  add: length_sObjHeader)\n        apply (subst length_sObjUnion[OF ounion otype])\n        using is_valid_obj apply (clarsimp simp: is_valid_ObjHeader_def is_len_and_type_ok_hdr_szD)\n       using is_valid_obj no_overflow apply (clarsimp simp: is_valid_ObjHeader_def  unat_plus_simple)\n       apply (drule is_len_and_type_ok_hdr_szD)\n       apply (unat_arith)\n       apply (simp add: is_len_and_type_ok_hdr_szD)\n      apply(simp add: bilbyFsObjHeaderSize_def)\n     using no_overflow is_valid_obj apply (clarsimp simp: is_valid_ObjHeader_def  bilbyFsObjHeaderSize_def)\n     apply (simp add:  is_len_and_type_ok_def otype otype_simps)\n     apply (unat_arith)\n    using bound is_valid_obj apply (clarsimp simp: is_valid_ObjHeader_def)\n    apply unat_arith\n   apply (simp add: sObj_def)\n done\n\nlemma binNot_NOT: \"binNot (x::64 word) = NOT x\"\n  unfolding  binNot_def[unfolded Let_def]\n  by (rule subst[where s=\"-1\"], fastforce, fastforce)\n\nlemma deserialise_ObjDel_ret:\n  assumes bound: \"unat offs + 8 \\<le> length (\\<alpha>wa $ data\\<^sub>f buf)\"\n  assumes err: \"P (Error (eInval, ex))\"\n  assumes offs: \"offs < offs + 8\"\n  assumes suc:\n   \"\\<And>obj offs'. \\<lbrakk> \n    obj = pObjDel (\\<alpha>wa $ data\\<^sub>f buf) offs;\n    ObjDel.id\\<^sub>f obj AND NOT bilbyFsOidMaskAll \\<in> \n      { bilbyFsOidMaskData, bilbyFsOidMaskInode,bilbyFsOidMaskDentarr};\n    offs' = offs + 8\\<rbrakk> \\<Longrightarrow> \n   P (Success (ex, obj, offs'))\"\n  shows \"P (deserialise_ObjDel (ex, buf, offs))\"\nproof - \n  have des_le64: \"deserialise_le64 (buf, offs) = ple64 (\\<alpha>wa $ data\\<^sub>f buf) offs\"\n   using bound offs\n   by (fastforce intro!: deserialise_le64_ret simp: unat_arith_simps)\n  show ?thesis\n  unfolding deserialise_ObjDel_def[unfolded tuple_simps sanitizers] \n  apply (clarsimp simp: Let_def err[simplified eInval_def])\n  by (fastforce\n     intro: suc\n     simp: Let_def binNot_NOT bilbyFsOidMaskData_def des_le64 bilbyFsOidMaskAll_def\n      bilbyFsOidMaskInode_def bilbyFsOidMaskDentarr_def pObjDel_def ObjDel.make_def)\nqed\n\nlemma deserialise_ObjInode_ret:\n  assumes bound: \"unat offs + 60 \\<le> length (\\<alpha>wa $ data\\<^sub>f buf)\"\n  assumes offs: \"offs < offs + 60\"\n  assumes err: \"\\<And>ex e. e \\<in> {eInval, eNoMem} \\<Longrightarrow> P (Error (e, ex))\"\n  assumes suc:\n   \"\\<And>ex oi offs'. \\<lbrakk> \n    oi = pObjInode (\\<alpha>wa (data\\<^sub>f buf)) offs;\n    offs' = offs + 60\\<rbrakk> \\<Longrightarrow> \n   P (Success (ex, oi, offs'))\"\n  shows \"P (deserialise_ObjInode (ex, buf, offs))\"\nproof -\n  have des_le64:\n    \"deserialise_le64 (buf, offs) = (ple64 (\\<alpha>wa $ data\\<^sub>f buf) offs)\"\n    \"deserialise_le64 (buf, offs + 8) = (ple64 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 8))\"\n    \"deserialise_le64 (buf, offs + 16) = (ple64 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 16))\"\n    \"deserialise_le64 (buf, offs + 24) = (ple64 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 24))\"\n    \"deserialise_le64 (buf, offs + 32) = (ple64 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 32))\"\n     using bound offs\n     by - (simp,rule deserialise_le64_ret[simplified];\n                  (simp add: unat_arith_simps, unat_arith?))+\n  have des_le32:\n   \"deserialise_le32 (buf, offs + 40) = (ple32 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 40))\"\n   \"deserialise_le32 (buf, offs + 44) = (ple32 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 44))\"\n   \"deserialise_le32 (buf, offs + 48) = (ple32 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 48))\"\n   \"deserialise_le32 (buf, offs + 52) = (ple32 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 52))\"\n   \"deserialise_le32 (buf, offs + 56) = (ple32 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 56))\"\n     using bound offs\n     by - (simp,rule deserialise_le32_ret[simplified];\n                  (simp add: unat_arith_simps, unat_arith?))+\n\n  show ?thesis\n  unfolding deserialise_ObjInode_def[unfolded tuple_simps sanitizers] \n  by (fastforce \n     intro: suc err\n     split: Result.split\n     simp: eInval_def eNoMem_def binNot_NOT Let_def bilbyFsOidMaskAll_def des_le32\n      bilbyFsOidMaskInode_def word32Max_def pObjInode_def ObjInode.make_def des_le64)\nqed\n\nlemma deserialise_ObjSuper_ret:\n  assumes bound: \"unat offs + 40 \\<le> length (\\<alpha>wa $ data\\<^sub>f buf)\"\n  assumes offs: \"offs \\<le> offs + 40\" (* added by Yutaka on 11th.*)\n  assumes err: \"\\<And>ex. P (Error (eNoMem, ex))\"\n  assumes suc:\n   \"\\<And>ex osup offs'. \\<lbrakk> \n    osup = pObjSuper (\\<alpha>wa (data\\<^sub>f buf)) offs;\n    offs' = offs + 40\\<rbrakk> \\<Longrightarrow> \n   P (Success (ex, osup, offs'))\"\n  shows \"P (deserialise_ObjSuper (ex, buf, offs))\"\nproof -\n  have des_le64:\n    \"deserialise_le64 (buf, offs + 32) = (ple64 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 32))\"\n     using bound offs\n     by - (simp,rule deserialise_le64_ret[simplified];\n                  (simp add: unat_arith_simps, unat_arith?))\n  have des_le32:\n   \"deserialise_le32 (buf, offs) = (ple32 (\\<alpha>wa $ data\\<^sub>f buf) offs)\"\n   \"deserialise_le32 (buf, offs + 4) = (ple32 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 4))\"\n   \"deserialise_le32 (buf, offs + 8) = (ple32 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 8))\"\n   \"deserialise_le32 (buf, offs + 12) = (ple32 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 12))\"\n   \"deserialise_le32 (buf, offs + 16) = (ple32 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 16))\"\n   \"deserialise_le32 (buf, offs + 20) = (ple32 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 20))\"\n   \"deserialise_le32 (buf, offs + 24) = (ple32 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 24))\"\n   \"deserialise_le32 (buf, offs + 28) = (ple32 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 28))\"\n     using bound offs\n     by - (simp,rule deserialise_le32_ret[simplified];\n                  (simp add: unat_arith_simps, unat_arith?))+\n\n  show ?thesis\n  unfolding deserialise_ObjSuper_def[unfolded tuple_simps sanitizers] \n  by (fastforce \n     intro: suc err[unfolded eNoMem_def] \n     split: Result.split \n     simp: pObjSuper_def ObjSuper.make_def des_le32 des_le64)\nqed\n\nlemma slice_Cons_helper:\n  \"i < length xs \\<Longrightarrow>\n    xs \\<noteq> [] \\<Longrightarrow>\n    drop i xs = \n    (xs !  i) # drop ( (i + 1)) xs\" \n    apply (cases xs, simp_all)\n    by (metis (no_types, hide_lams) drop_Suc_Cons Cons_nth_drop_Suc length_Cons)\n\nlemma slice_singleton:\n \"f < length xs \\<Longrightarrow> slice f (Suc f) xs = [xs ! f]\"\n unfolding slice_def by (simp add:drop_take list_eq_iff_nth_eq)\n\nlemma take_n_minus_1_append:\n  \"0<n \\<Longrightarrow> xs \\<noteq> [] \\<Longrightarrow> n \\<le> length xs \\<Longrightarrow>\n take (n - Suc 0) xs @ [xs ! (n - Suc 0)] = take n xs\"\n  apply (simp only: list_eq_iff_nth_eq)\n  apply clarsimp\n  apply (case_tac \"(length xs) < (n - Suc 0)\")\n   apply (clarsimp simp add: min_absorb2)+\n  by (metis One_nat_def Suc_pred' elem_take_n le0 le_less_trans diff_le_self\n  less_not_refl linorder_neqE_nat diff_Suc_less take_Suc_conv_app_nth)\n\nlemma take_n_minus_1_append_eq:\n  \"v = xs ! (unat (n - 1)) \\<Longrightarrow> unat n  \\<le> length xs \\<Longrightarrow> n> 0 \\<Longrightarrow>\n  take (unat ((n::U32) - 1)) xs @ [v] = take (unat n) xs\"\n  apply (simp add: list_eq_iff_nth_eq min_absorb2 unat_arith_simps)\n  apply clarsimp\n  apply (subst take_n_minus_1_append)\n     apply simp+\n  apply (case_tac xs, simp_all)\n done\n\nlemma slice_n_minus_1_append_last:\n \"unat acc + unat n \\<le> length xs \\<Longrightarrow>\n  (n::U32) > 0 \\<Longrightarrow>\n  acc \\<le> acc + n \\<Longrightarrow>\n  slice (unat acc) (unat acc + unat (n - 1)) xs @\n  [xs ! unat (acc + (n - 1))] =\n  slice (unat acc) (unat acc + unat n) xs\"\n  apply (simp add:  slice_def list_eq_iff_nth_eq)\n  apply (subgoal_tac \"(length xs) \\<ge> (unat acc + unat (n - 1))\")\n   prefer 2\n   apply unat_arith\n  apply (rule conjI)\n   apply (simp add: min_absorb1 min_absorb2)\n  apply (clarsimp simp: drop_take min_absorb1 min_absorb2 )\n  apply (subst take_n_minus_1_append_eq)\n     apply simp\n     apply (rule arg_cong[where f=\"nth xs\"]) \n     apply unat_arith (* takes long *)\n    apply simp+\n done\n\nlemma map_deserialise_waU8_map_eq_slice_apply:\n  assumes nonempty: \"xs \\<noteq> []\"\n  assumes \"length xs = unat (n:: 32 word)\"\n  assumes n_gr_0: \"n > 0\"\n  assumes no_overflow: \"acc \\<le> acc + n\"\n  assumes bound: \"unat acc + length xs \\<le> length (\\<alpha>wa d)\"\n  shows \"\n    (mapAccumObs 0 (length xs) deserialise_waU8_map xs acc d) =\n (FunBucket.slice (unat acc) (unat acc + (length xs)) (\\<alpha>wa d), acc + n)\"\n  using assms\n  apply (clarsimp simp: mapAccumObs_def ElemAO.make_def\n        deserialise_waU8_map_def[unfolded tuple_simps sanitizers] slice_def[where frm=0])\n  apply (induct \"xs\" arbitrary: n rule: rev_nonempty_induct)\n   apply (drule sym, simp add: slice_singleton wordarray_get_ret unat_arith_simps)\n  apply (drule_tac x=\"n - 1\" in meta_spec)\n  apply (erule meta_impE)\n   apply unat_arith\n  apply (erule meta_impE)\n   apply (subgoal_tac \"unat n \\<ge> 2\")\n   apply unat_arith\n   apply (case_tac xs, simp, simp)\n  apply (erule meta_impE)\n   apply unat_arith\n  apply (erule meta_impE)\n   apply unat_arith\n  apply (simp add: prod.case_eq_if)\n  apply (rule wordarray_get_ret')\n   apply unat_arith (* takes a while *)\n  apply (simp only: slice_n_minus_1_append_last)\n done\n\nlemma map_deserialise_waU8_map_eq_slice:\n  assumes n_gr_0: \"n > 0\"\n  assumes no_overflow: \"acc \\<le> acc + n\"\n  assumes bound: \"unat acc + unat n \\<le> length (\\<alpha>wa d)\"\n  assumes \"length xs = unat (n:: 32 word)\"\n  shows \"\n    prod.fst (mapAccumObs 0 (unat n) deserialise_waU8_map xs acc d) =\n     (FunBucket.slice (unat acc) (unat acc + unat n ) (\\<alpha>wa d))\"\n  using map_deserialise_waU8_map_eq_slice_apply[THEN arg_cong[where f=prod.fst]]\n        assms\n\n by (subgoal_tac \"xs \\<noteq> []\") (fastforce simp: unat_arith_simps)+\n\nlemma deserialise_wordarray_U8_ret:\n  assumes err: \"\\<And>ex. P (Error (eNoMem, ex))\"\n  assumes suc:                       \n   \"\\<And>ex wa. \n   offs \\<le> offs + len \\<longrightarrow> unat offs + unat len \\<le> length (\\<alpha>wa $ data\\<^sub>f buf) \\<longrightarrow> \n   wa = WordArrayT.make (slice (unat offs) (unat offs + unat len) (\\<alpha>wa (data\\<^sub>f buf))) \\<Longrightarrow> \n   P (Success (ex, wa))\"\n  shows \"P (deserialise_wordarray_U8 (ex, buf, offs, len))\"\n  unfolding deserialise_wordarray_U8_def[unfolded tuple_simps sanitizers] \n  apply (simp add: Let_def)\n  apply (rule wordarray_create_ret)\n   apply simp\n   apply (simp add: err[unfolded eNoMem_def])\n  apply (rename_tac ex' wa)\n  apply  simp\n  apply (rule wordarray_copy_ret)\n  apply (simp add:Let_def prod.case_eq_if)\n  apply (rule suc)\n  apply clarsimp\n done\n\nlemma deserialise_ObjData_ret:\n  assumes offs_no_of: \"offs \\<le> offs + (olen - bilbyFsObjHeaderSize)\"\n  assumes buf_len: \"unat (offs + (olen - bilbyFsObjHeaderSize)) \\<le> length (\\<alpha>wa (data\\<^sub>f buf))\"\n  assumes olen: \"is_len_and_type_ok (bilbyFsObjTypeData, olen)\"\n  assumes err: \"\\<And>ex e. e \\<in> {eInval, eNoMem} \\<Longrightarrow> P (Error (e, ex))\"\n  assumes suc:\n   \"\\<And>ex od offs' . \\<lbrakk>\n   ObjData.id\\<^sub>f od AND NOT bilbyFsOidMaskAll OR bilbyFsOidMaskData = ObjData.id\\<^sub>f od;\n     od = pObjData (\\<alpha>wa (data\\<^sub>f buf)) offs olen;\n    offs' = offs + olen - bilbyFsObjHeaderSize\\<rbrakk> \\<Longrightarrow> \n   P (Success (ex, od, offs'))\"\n  shows \"P (deserialise_ObjData (ex, buf, offs, olen))\"\n  proof -\n\n   have hdr_le_olen: \"bilbyFsObjDataHeaderSize \\<le> (olen - bilbyFsObjHeaderSize)\"\n    using olen\n    by (simp add: is_len_and_type_ok_def[unfolded sanitizers tuple_simps] otype_simps\n      bilbyFsObjHeaderSize_def bilbyFsObjDataHeaderSize_def) unat_arith\n\n  have offs_pl_hdr_le_offs_pl_olen:\n  \"offs + bilbyFsObjDataHeaderSize \\<le> offs + (olen - bilbyFsObjHeaderSize)\"\n   using hdr_le_olen offs_no_of\n   by (simp add: bilbyFsObjDataHeaderSize_def bilbyFsObjHeaderSize_def word_plus_mono_right)\n\n\n  have offs_pl_hdr_no_of:\n   \"offs < offs + bilbyFsObjDataHeaderSize\"\n    using offs_no_of  hdr_le_olen\n    by (simp add: bilbyFsObjDataHeaderSize_def bilbyFsObjHeaderSize_def)\n       unat_arith\n\n  have offs_pl_hdr_le_buf_len:\n   \"unat offs + unat bilbyFsObjDataHeaderSize \\<le> length (\\<alpha>wa (data\\<^sub>f buf))\"\n   using  buf_len hdr_le_olen offs_pl_hdr_no_of offs_pl_hdr_le_offs_pl_olen\n   by (simp add: bilbyFsObjHeaderSize_def bilbyFsObjDataHeaderSize_def)\n      unat_arith\n\n  have unat_offs_pl_olen_etc_eq: \"unat (offs + (olen - bilbyFsObjHeaderSize)) = unat (offs + 8) + unat (0xFFFFFFE0 + olen)\"\n   using olen hdr_le_olen offs_pl_hdr_no_of offs_pl_hdr_le_offs_pl_olen\n   apply (simp add: bilbyFsObjHeaderSize_def bilbyFsObjDataHeaderSize_def)\n   apply (simp add: is_len_and_type_ok_def[unfolded sanitizers tuple_simps] otype_simps bilbyFsObjHeaderSize_def)\n   apply (subgoal_tac \"unat (offs + (olen - 0x18)) = unat (offs + 8) + unat (olen - 0x18 - 8)\")\n    apply unat_arith\n   apply (simp add: unat_arith_simps)\n   apply unat_arith\n  done\n\n  show ?thesis\n  unfolding deserialise_ObjData_def[unfolded tuple_simps sanitizers] \n  apply (clarsimp simp: Let_def err[unfolded eNoMem_def eInval_def] binNot_NOT)\n  apply (rule deserialise_wordarray_U8_ret)\n    apply (simp add: err)\n   apply (erule impE)\n    using offs_pl_hdr_no_of apply (simp add: bilbyFsObjHeaderSize_def bilbyFsObjDataHeaderSize_def add.commute add.assoc)\n    apply (subgoal_tac \"olen + 0xFFFFFFE8 = olen - 0x18\") (* Oh! Beloved words <3 *)\n     prefer 2\n     apply simp\n   apply (simp only:)\n   apply simp\n   using offs_pl_hdr_le_offs_pl_olen apply (simp add: bilbyFsObjHeaderSize_def bilbyFsObjDataHeaderSize_def )\n  apply simp\n  apply (rule suc)\n    apply simp\n    apply (simp add: bilbyFsOidMaskAll_def bilbyFsOidMaskData_def\n      pObjData_def ObjData.make_def bilbyFsObjHeaderSize_def)\n   apply (simp add: Let_def  pObjData_def ObjData.make_def bilbyFsObjHeaderSize_def bilbyFsObjDataHeaderSize_def)\n  apply (subst deserialise_le64_ret)\n    using offs_pl_hdr_le_buf_len[simplified bilbyFsObjHeaderSize_def bilbyFsObjDataHeaderSize_def]\n    apply (simp add:)\n   using offs_pl_hdr_no_of\n    apply (simp add: bilbyFsObjDataHeaderSize_def)\n   apply (erule impE)\n    using buf_len unat_offs_pl_olen_etc_eq\n    apply simp\n   apply simp\n  apply (simp add: bilbyFsObjHeaderSize_def)\n done\nqed\n\nlemma deserialise_ObjPad_ret:\n  assumes err: \"P (Error (eInval, ex))\"\n  assumes suc: \"\\<And> out offs' .\n    \\<lbrakk> olen - bilbyFsObjHeaderSize \\<le> olen ; \n      out=(); \n      offs' = offs + (olen - bilbyFsObjHeaderSize) \\<rbrakk> \\<Longrightarrow> \n    P (Success (ex, out, offs'))\"\n  shows \"P (deserialise_ObjPad (ex, buf, offs, olen))\"\n  unfolding deserialise_ObjPad_def[unfolded tuple_simps sanitizers]\n  by (auto simp: Let_def err[unfolded eInval_def] suc[unfolded bilbyFsObjHeaderSize_def] split: Result.split)\n\nlemma no_offs_overflow:\n  assumes wellformed_buf: \"wellformed_buf buf\"\n  assumes no_overflow: \"length (\\<alpha>wa $ data\\<^sub>f buf) \\<le> unat bilbyFsMaxEbSize\"\n  assumes offs_bound: \"offs \\<le> (bound\\<^sub>f buf)\"\n  assumes \"n < bilbyFsMaxEbSize\"\n  assumes \"m < bilbyFsMaxEbSize\"\n  shows \"offs + n \\<le> offs + n + m\"\n  using assms\n  by (auto simp add: bilbyFsMaxEbSize_def wellformed_buf_def unat_arith_simps)\n\nlemma no_offs_overflow_le:\n  assumes wellformed_buf: \"wellformed_buf buf\"\n  assumes no_overflow: \"length (\\<alpha>wa $ data\\<^sub>f buf) \\<le> unat bilbyFsMaxEbSize\"\n  assumes offs_bound: \"offs \\<le> (bound\\<^sub>f buf)\"\n  assumes \"n < bilbyFsMaxEbSize\"\n  assumes \"m < bilbyFsMaxEbSize\"\n  assumes \"m > 0\"\n  shows \"offs + n < offs + n + m\"\n  using assms\n  by (auto simp add: bilbyFsMaxEbSize_def wellformed_buf_def unat_arith_simps)\n\nlemma conc_offs_no_of:\n  assumes wellformed_buf: \"wellformed_buf buf\"\n  assumes no_overflow: \"length (\\<alpha>wa $ data\\<^sub>f buf) \\<le> unat bilbyFsMaxEbSize\"\n  assumes offs_bound: \"offs \\<le> (bound\\<^sub>f buf)\"\n  assumes \"m < bilbyFsMaxEbSize\"\n  assumes \"m > 0\"\n  shows \"offs < offs + m\"\n  using assms\n  by (auto simp add: bilbyFsMaxEbSize_def wellformed_buf_def unat_arith_simps)\n\nlemma slice_take:\n  \"m \\<le> l \\<Longrightarrow> \n  slice n m (take l xs) = slice n m xs\"\n  by (simp add: slice_def)\n\nlemma deserialise_pu8_ret:\nassumes valid_offs:\n  \"unat offs + 1 < length (\\<alpha>wa $ data\\<^sub>f buf)\"\nassumes no_of:\n  \"offs < offs + 1\"\nshows\n  \"deserialise_u8 (buf, offs) = (pu8 (\\<alpha>wa $ data\\<^sub>f buf) offs)\"\nproof -\n  from no_of have no_of': \"offs \\<le> offs + 1\" by simp\n  hence offs_pl_1: \"unat (offs + 1) = unat offs + 1\" by (simp add: unat_plus_simple)\n  show ?thesis\nusing valid_offs\n  apply (clarsimp simp:  wordarray_get_ret[where arr=\"data\\<^sub>f buf\"]\n                        deserialise_u8_def pu8_def)\n  apply (rule trans, rule word_rcat_rsplit[symmetric])\n  apply (rule arg_cong[where f=word_rcat])\n  apply (subst word_rsplit_upt[where n=1], simp add: word_size)\n   apply (simp)\n  apply (simp add: slice_def)\n  apply (simp add: ucast_def)\n  apply (subst Cons_nth_drop_Suc[symmetric])\n   apply simp\n  apply simp\n done\nqed\n\nlemma pu8_take:\n assumes offs:\"offs < offs+1\"\n assumes ntake:\"unat (offs + 1) \\<le> ntake\"\n shows   \"pu8 (take ntake ys) offs = pu8 ys offs\"\n  apply (simp add: pu8_def)\n  apply (rule arg_cong[where f=\"word_rcat\"])\n  apply (rule slice_take)\n using ntake offs by unat_arith\n\nlemma deserialise_ObjDentry_ret:\n  assumes wellformed_buf: \"wellformed_buf buf\"\n  assumes no_buf_overflow: \"length (\\<alpha>wa $ data\\<^sub>f buf) \\<le> unat bilbyFsMaxEbSize\"\n  assumes bound: \"end_offs \\<le> bound\\<^sub>f buf\"\n  assumes off_less_end_offs: \"offs \\<le> end_offs\"\n  assumes err:\n    \"\\<And>ex e. e \\<in> {eInval, eNoMem} \\<Longrightarrow> P (Error (e, ex))\"\n  assumes suc:\n    \"\\<And>ex dentry offs'. \\<lbrakk>\n      unat offs + 8 + unat (wordarray_length (name\\<^sub>f dentry)) \\<le> unat (bound\\<^sub>f buf);\n      wordarray_length (name\\<^sub>f dentry) \\<le> bilbyFsMaxNameLen + 1;\n      offs + 8 + wordarray_length (name\\<^sub>f dentry) \\<le> end_offs ;\n      dentry = pObjDentry (take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf))) offs ;\n      offs' = offs + 8 + wordarray_length (name\\<^sub>f dentry);\n      offs' \\<le> (bound\\<^sub>f buf)\n        \\<rbrakk> \\<Longrightarrow>\n      P (Success (ex, dentry, offs'))\"\n  shows \"P (deserialise_ObjDentry (ex, buf, offs, end_offs))\"\nproof -\n  {\n    fix ex' dentry offs'\n    assume des_suc: \"unat offs + 8 \\<le> unat (bound\\<^sub>f buf)\"\n\n    then have offs_ok:\"\\<forall>n\\<in>{0..7}. unat (offs + n)  < length (\\<alpha>wa $ data\\<^sub>f buf)\"\n    proof -\n      from wellformed_buf[unfolded wellformed_buf_def] des_suc\n      have \"unat offs + 8 \\<le> length (\\<alpha>wa $ data\\<^sub>f buf)\"\n        by unat_arith\n\n      thus ?thesis\n        by unat_arith\n    qed\n\n    from des_suc have deserialises:\n      \"deserialise_le32 (buf, offs)     = (ple32 (\\<alpha>wa $ data\\<^sub>f buf) offs)\"\n      \"deserialise_u8   (buf, offs + 4) = (pu8 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 4))\"\n      \"deserialise_le16 (buf, offs + 6) = (ple16 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 6))\"\n        apply clarsimp\n        apply(rule deserialise_le32_ret[simplified])\n      using assms[simplified bilbyFsMaxEbSize_def wellformed_buf_def]\n         apply unat_arith \n      using assms[simplified bilbyFsMaxEbSize_def ]\n        apply unat_arith\n       apply (subst deserialise_pu8_ret)\n      using offs_ok des_suc wellformed_buf\n         apply (simp add: wellformed_buf_def, unat_arith)\n      using des_suc\n        apply unat_arith\n       apply simp+\n      apply(rule deserialise_le16_ret[simplified])\n      using offs_ok des_suc wellformed_buf apply (simp add: wellformed_buf_def, unat_arith)\n      using des_suc\n      apply unat_arith\n      done\n  }\n  note deserialises = this\n\n  have offs_le_bound: \"offs  \\<le> bound\\<^sub>f buf\"\n    using off_less_end_offs bound by simp\n\n  have const_offs_no_of: \"\\<And>n. n < bilbyFsMaxEbSize \\<Longrightarrow> 0 < n \\<Longrightarrow> offs < offs + n\"\n    apply (rule conc_offs_no_of[OF wellformed_buf no_buf_overflow, unfolded bilbyFsMaxEbSize_def, simplified])\n    using offs_le_bound by (simp add:bilbyFsMaxEbSize_def)+\n  note no_of_8 = no_offs_overflow[OF wellformed_buf no_buf_overflow offs_le_bound, where m=8 and n=0, unfolded bilbyFsMaxEbSize_def, simplified, simplified unat_plus_simple]\n  show ?thesis\n    unfolding deserialise_ObjDentry_def[simplified tuple_simps sanitizers]\n    apply (clarsimp simp: Let_def err[unfolded eNoMem_def eInval_def])\n    apply (subst (asm) not_less)+\n    apply (rule deserialise_wordarray_U8_ret)\n     apply (clarsimp simp add: err)\n    apply(clarsimp simp add: err eNoMem_def Let_def prod.case_eq_if split: Result.splits)\n    apply (erule impE)\n     apply (rule no_offs_overflow[OF wellformed_buf no_buf_overflow])\n    using off_less_end_offs bound apply fastforce\n      apply (simp add: bilbyFsMaxEbSize_def)+\n     apply unat_arith\n    apply (subgoal_tac \"unat offs + unat (8::32word) + unat (ucast (deserialise_le16 (buf, offs + 6))) \\<le> unat end_offs\")\n     prefer 2\n     apply (subst add.assoc)\n     apply (subst unat_plus_simple[THEN iffD1, symmetric])\n      apply (simp add: unat_arith_simps)\n     apply (subst unat_plus_simple[THEN iffD1, symmetric])\n      apply (rule no_offs_overflow[OF wellformed_buf no_buf_overflow, where n=0, simplified])\n    using off_less_end_offs bound apply fastforce\n       apply (simp add: bilbyFsMaxEbSize_def)+\n      apply (simp add: unat_arith_simps)\n     apply (simp add: word_le_nat_alt[symmetric] add.assoc)\n    apply (erule impE)\n    using bound wellformed_buf[unfolded wellformed_buf_def] \n     apply (simp add: unat_arith_simps)\n     apply unat_arith\n    apply (subgoal_tac \"unat offs + 8 \\<le> unat (bound\\<^sub>f buf)\")\n     prefer 2 \n     apply (subst unat_plus_simple[THEN iffD1, symmetric, \n          where y=\"8::32word\", simplified])\n      apply (rule no_offs_overflow[OF wellformed_buf no_buf_overflow, \n          where n=0, simplified])\n    using off_less_end_offs bound apply fastforce\n       apply (simp add: bilbyFsMaxEbSize_def)+ \n     apply (subst word_le_nat_alt[symmetric])\n     apply (cut_tac no_offs_overflow[OF wellformed_buf no_buf_overflow, \n          where offs=offs and n=8 and m=\"ucast (deserialise_le16 (buf, offs + 6))\"])\n    using off_less_end_offs bound apply (simp_all add: bilbyFsMaxEbSize_def)\n     apply unat_arith\n    apply (simp add: deserialises) \n    apply (subgoal_tac \"wordarray_length (WordArrayT.make\n         (FunBucket.slice (unat (offs + 8)) \n          (unat (offs + 8) + unat (ucast (ple16 (\\<alpha>wa (data\\<^sub>f buf)) (offs + 6)) :: 32 word))\n          (\\<alpha>wa (data\\<^sub>f buf)))) \\<le> ucast (ple16 (\\<alpha>wa (data\\<^sub>f buf)) (offs + 6))\")\n     prefer 2\n     apply (subst wordarray_length_ofnat)\n      apply (simp add: wordarray_length_ret)\n     apply (subst wordarray_make)\n     apply (simp add: slice_length)\n     apply (subst min_absorb1)  \n      prefer 3\n    using wellformed_buf[unfolded wellformed_buf_def]  no_buf_overflow[unfolded bilbyFsMaxEbSize_def]\n      apply (simp add: unat_arith_simps)\n      apply (subgoal_tac \n        \"unat (ucast (ple16 (\\<alpha>wa (data\\<^sub>f buf)) (offs + 6)) :: 32 word) = \n              unat (ple16 (\\<alpha>wa (data\\<^sub>f buf)) (offs + 6))\")\n       prefer 2 \n       apply (fastforce intro: uint_up_ucast simp: eq_nat_nat_iff unat_def is_up)\n      apply (rule suc)\n           apply (simp_all add: Let_def pObjDentry_def ObjDentry.make_def bilbyFsMaxNameLen_def)\n    using bound apply unat_arith\n    using wellformed_buf[unfolded wellformed_buf_def]  no_buf_overflow[unfolded bilbyFsMaxEbSize_def]\n        apply (simp add: unat_arith_simps)\n       apply (simp add: ple16_take ple32_take const_offs_no_of bilbyFsMaxEbSize_def plus_no_overflow_unat_lift[OF const_offs_no_of[unfolded bilbyFsMaxEbSize_def, simplified]])\n       apply (subst ple16_take)\n         apply (rule no_offs_overflow_le[OF wellformed_buf no_buf_overflow offs_le_bound])\n           apply (simp add: bilbyFsMaxEbSize_def)+\n    using no_of_8\n        apply (simp add: add.commute)\n       apply (subst ple16_take)\n         apply (rule no_offs_overflow_le[OF wellformed_buf no_buf_overflow offs_le_bound])\n           apply (simp add: bilbyFsMaxEbSize_def)+\n    using no_of_8\n        apply (simp add: add.commute)\n       apply (subst pu8_take)\n    using no_offs_overflow[OF wellformed_buf no_buf_overflow offs_le_bound, where m=5 and n=0, unfolded bilbyFsMaxEbSize_def, simplified]\n      no_offs_overflow[OF wellformed_buf no_buf_overflow offs_le_bound, where m=4 and n=0, unfolded bilbyFsMaxEbSize_def, simplified]\n         apply (simp add: add.commute unat_plus_simple)\n         apply unat_arith\n    using no_of_8\n      no_offs_overflow[OF wellformed_buf no_buf_overflow offs_le_bound, where m=5 and n=0, unfolded bilbyFsMaxEbSize_def, simplified]\n        apply (fastforce simp add: unat_plus_simple add.commute)\n       apply (subst ObjDentry.surjective, simp)\n       apply (rule arg_cong[where f=WordArrayT.make])\n       apply (rule slice_take[symmetric], simp)\n      apply (rule word_unat.Rep_eqD)\n      apply (simp add: wordarray_length_ret wordarray_make length_slice)\n    using no_of_8 wellformed_buf\n     apply (simp add: wellformed_buf_def)\n     apply unat_arith\n    using wellformed_buf[unfolded wellformed_buf_def]  no_buf_overflow[unfolded bilbyFsMaxEbSize_def]\n    apply (simp add: unat_arith_simps)\n    done\nqed\n\nlemma loop_deserialise_ObjDentry_ret:\n  assumes wellformed_buf: \"wellformed_buf buf\"\n  assumes no_buf_overflow: \"length (\\<alpha>wa $ data\\<^sub>f buf) \\<le> unat bilbyFsMaxEbSize\"\n  assumes bound: \"end_offs \\<le> bound\\<^sub>f buf\"\n  assumes off_less_end_offs: \"offs  \\<le> end_offs\"\n  assumes st_offs: \"st_offs \\<le> offs\"\n  shows \"case loop_deserialise_ObjDentry (OptElemAO.make dentry (ex, offs) (buf, end_offs)) of\n            Break (none, e, ex) \\<Rightarrow> none= Option.None () \\<and> e = eInval \n          | Iterate (optdentry, ex, offs') \\<Rightarrow>\n             \\<exists>dentry. optdentry = Option.Some dentry \\<and>\n                unat offs + 8 + unat (wordarray_length (name\\<^sub>f dentry)) \\<le> unat (bound\\<^sub>f buf)  \\<and>\n                wordarray_length (name\\<^sub>f dentry) \\<le> bilbyFsMaxNameLen + 1  \\<and>\n                offs + 8 + wordarray_length (name\\<^sub>f dentry) \\<le> end_offs  \\<and>\n                dentry = pObjDentry (take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf))) offs  \\<and>\n                offs' = offs + 8 + wordarray_length (name\\<^sub>f dentry) \\<and>\n                offs' \\<le> (bound\\<^sub>f buf)\"\n  unfolding loop_deserialise_ObjDentry_def[unfolded tuple_simps sanitizers]\n  apply (clarsimp simp: Let_def OptElemAO.make_def)\n  apply (rule deserialise_ObjDentry_ret[OF assms(1-4)])\n  by (clarsimp simp: eInval_def)+\n\nlemma slice_Cons:\n  \"frm < length xs \\<Longrightarrow> frm < to\n    \\<Longrightarrow> slice frm to xs = xs ! frm # slice (Suc frm) to xs\"\n  apply (simp add: slice_def)\n  apply (subst slice_Cons_helper[where i=frm], simp_all)\n  apply clarsimp\n  done\n\nlemma slice_list_update:\n  \"n < length xs\n    \\<Longrightarrow> slice i j (xs[n := x]) = (if n < i then slice i j xs\n        else if n \\<ge> j then slice i j xs\n        else (slice i j xs)[n - i := x])\"\n  by (simp add: slice_def drop_list_update take_list_update)\n\nlemma mapAccumObsOpt_step:\n  assumes frm: \"frm < to\" \"frm < length xs\"\n  shows \"mapAccumObsOpt frm to fn xs vacc obs =\n        (case fn (OptElemAO.make (xs ! frm) vacc obs)\n         of Iterate (oelem, acc) \\<Rightarrow> \n             mapAccumObsOpt (Suc frm) to fn (xs [frm := oelem]) acc obs\n         | Break (oelem, d) \\<Rightarrow> Break (xs [frm := oelem], d))\"\nproof -\n  let ?folder = \"(\\<lambda>elem. case_LoopResult (\\<lambda>(ys, d). Break (ys @ [elem], d))\n                               (\\<lambda>(ys, acc).\n                                   case fn (OptElemAO.make elem acc obs) of\n                                  Break (oelem, d) \\<Rightarrow> Break (ys @ [oelem], d)\n                                | Iterate (oelem, acc) \\<Rightarrow> Iterate (ys @ [oelem], acc)))\"\n\n  { fix xs ys d\n  have fold_break: \"fold ?folder xs (Break (ys, d))\n        = Break (ys @ xs, d)\"\n    by (induct xs arbitrary: ys d, simp_all)\n  }\n  note fold_break = this\n\n  have fold_iterate_Cons: \"\\<And>xs. \\<forall>y ys acc. fold ?folder xs (Iterate (y # ys, acc))\n        = (case (fold ?folder xs (Iterate (ys, acc)))\n            of Iterate (zs, acc) \\<Rightarrow> Iterate (y # zs, acc)\n          | Break (zs, d) \\<Rightarrow> Break (y # zs, d))\"\n    apply (induct_tac xs, simp_all)\n    apply clarsimp\n    apply (case_tac \"fn (OptElemAO.make a acc obs)\")\n     apply (clarsimp simp add: fold_break)\n    apply clarsimp\n    done\n\n  from frm have drop_helper: \"\\<And>x xs. drop (to - frm) (x # xs) = drop (to - Suc frm) xs\"\n    apply (cases \"to - frm\", simp_all)\n    apply (cases to, simp_all)\n    apply (cases frm, simp_all)\n    apply (metis Suc_diff_Suc Suc_inject)\n    done\n\n  show ?thesis using frm\n    apply (simp add: mapAccumObsOpt_def)\n    apply (simp add: slice_Cons)\n    apply (cases \"fn (OptElemAO.make (xs ! frm) vacc obs)\")\n     apply (clarsimp simp: fold_break)\n     apply (simp add: slice_def upd_conv_take_nth_drop max_absorb2)\n     apply (subst append_take_drop_id\n                  [where xs=\"drop (Suc frm) xs\" and n=\"to -frm - 1\", \n                    simplified take_drop, symmetric])\n     apply simp\n    apply (clarsimp simp: mapAccumObsOpt_def slice_list_update take_list_update)\n    apply (simp add: fold_iterate_Cons)\n    apply (simp split: LoopResult.split)\n    apply (clarsimp simp: slice_def upd_conv_take_nth_drop min_absorb2 max_absorb2\n                          drop_helper)\n    done\n qed\n\nlemma mapAccumObsOpt_n_n:\n  \"mapAccumObsOpt n n fn xs vacc obs = Iterate (xs, vacc)\"\n  by (clarsimp simp: mapAccumObsOpt_def slice_n_n)\n\nlemma mapAccumObsOpt_frm_eq_len:\n  \"frm = length xs \\<Longrightarrow> mapAccumObsOpt frm to fn xs vacc obs = Iterate (xs @ [], vacc)\"\n  by (clarsimp simp: mapAccumObsOpt_def slice_def)\n\nlemma snd_fold_simp:\n \"prod.snd (fold (\\<lambda>_ (a, b). (f a b, f' b)) xs (a,b)) =\n  fold (\\<lambda>_ b. f' b) xs b\"\n  by (induct xs arbitrary: a b, simp_all) \n\nlemma fst_fold_append_simp:\n  \"prod.fst (fold (\\<lambda>_ (xs, n). (xs @ [f n], f' n)) ls (f n' # xs, f' n)) = \n   f n' # prod.fst (fold (\\<lambda>_ (xs, n). (xs @ [f n], f' n)) ls (xs, f' n)) \"\n   by (induct ls arbitrary: n xs, simp_all)\n\nlemma snd_snd_fold_simp:\n  \"(prod.snd (fold (\\<lambda>_ (xs, doffs, offslist). (f xs doffs, f' doffs, f'' doffs offslist))  ls (xs, n, offslist))) =\n    fold (\\<lambda>_ (doffs, offslist).  (f' doffs, f'' doffs offslist)) ls (n, offslist)\" \n  by (induct ls arbitrary: xs n offslist, simp_all) \n\nlemma snd_fold_append_gen_simp:\n \"prod.snd (fold (\\<lambda>_ (x, xs). (f' x, xs @ [f x])) ls (x, xs @ ys)) =\n   xs @ prod.snd (fold (\\<lambda>_ (x, xs). (f' x, xs @ [f x])) ls (x, ys))\"\n  by (induct ls arbitrary: x ys, simp_all)\n\nlemma snd_fold_append_simp:\n \"prod.snd (fold (\\<lambda>_ (x, xs). (f' x, xs @ [f x])) ls (x, xs)) =\n   xs @ prod.snd (fold (\\<lambda>_ (x, xs). (f' x, xs @ [f x])) ls (x, []))\"\n using snd_fold_append_gen_simp[where ys=Nil, simplified] .\n\nlemma fst_fold_triple_simp:\n \"prod.fst (fold (\\<lambda>_ (a, b, c). (f a b, f' b, f'' b c)) ns (a, b, c)) =\n  prod.fst (fold (\\<lambda>_ (a, b). (f a b, f' b)) ns (a, b))\"\n  by (induct  ns arbitrary: a b c, simp_all)\n\nlemma fst_snd_fold_triple_simp:\n \"prod.fst (prod.snd (fold (\\<lambda>_ (a, b, c). (f a b, f' b, f'' b c)) ns (a, b, c))) =\n  prod.snd (fold (\\<lambda>_ (a, b). (f a b, f' b)) ns (a, b))\"\n  by (induct  ns arbitrary: a b c, simp_all)\n\ndefinition dentarr_offs_list_drop :: \"U8 list \\<Rightarrow> U32 \\<Rightarrow> nat list \\<Rightarrow> U32 \\<Rightarrow> (32 word list)\"\nwhere\n \"dentarr_offs_list_drop data ost entriesno offs =\n    prod.snd (fold (\\<lambda>_ (doffs, offslist).\n      let dentry = pObjDentry (drop (unat offs) data) (doffs - offs);\n          newoffs = doffs + 8 + wordarray_length (ObjDentry.name\\<^sub>f dentry)\n       in (newoffs, offslist @ [newoffs]))\n      entriesno (ost, []))\n\"\ndefinition\n  dentarr_offs_list_drop_end_offs_pred\nwhere\n \"dentarr_offs_list_drop_end_offs_pred data ost entriesno offs end_offs \\<equiv>\n \\<forall>v\\<in>set (dentarr_offs_list_drop data ost entriesno offs).\n   v \\<le> end_offs\"\n\ndefinition\n \"dentarr_offs_list data ost entriesno \\<equiv> \n  (prod.snd (fold (\\<lambda>_ (doffs, offslist).\n     let dentry = pObjDentry data doffs;\n         newoffs = doffs + 8 + wordarray_length (ObjDentry.name\\<^sub>f dentry)\n     in (newoffs, offslist @ [newoffs]))\n   entriesno (ost, [])))\"\n\ndefinition\n  dentarr_offs_list_end_offs_pred\nwhere\n \"dentarr_offs_list_end_offs_pred data ost entriesno end_offs \\<equiv>\n \\<forall>v\\<in>set (dentarr_offs_list data ost entriesno).\n   v \\<le> end_offs\"\n\ndefinition\n  dentarr_otype_end_offs_pred\nwhere\n \"dentarr_otype_end_offs_pred otype data offs end_offs \\<equiv>\n (otype = bilbyFsObjTypeDentarr \\<longrightarrow>\n (let nbentry = ple32 data (offs + 8)\n in dentarr_offs_list_end_offs_pred data (offs+bilbyFsObjDentarrHeaderSize) [0..<unat nbentry] end_offs))\"\n\nlemmas dentarr_end_offs_simps = dentarr_offs_list_def dentarr_offs_list_end_offs_pred_def\n  dentarr_otype_end_offs_pred_def\n\ndefinition\n  dentarr_otype_drop_end_offs_pred\nwhere\n \"dentarr_otype_drop_end_offs_pred otype data offs end_offs \\<equiv>\n (otype = bilbyFsObjTypeDentarr \\<longrightarrow>\n  (let nbentry = ple32 data (offs+8)\n  in dentarr_offs_list_drop_end_offs_pred data (offs+bilbyFsObjDentarrHeaderSize)\n  [0..<unat nbentry] offs end_offs))\n\"\ndefinition\n  dentarr_otype_drop_end_offs_st_pred\nwhere\n \"dentarr_otype_drop_end_offs_st_pred otype data offs st_offs end_offs \\<equiv>\n (otype = bilbyFsObjTypeDentarr \\<longrightarrow>\n  (let nbentry = ple32 data (offs+8)\n  in dentarr_offs_list_drop_end_offs_pred data (offs+bilbyFsObjDentarrHeaderSize)\n  [0..<unat nbentry] st_offs end_offs))\n\"\n\nlemmas dentarr_drop_end_offs_simps = dentarr_offs_list_drop_def dentarr_offs_list_drop_end_offs_pred_def\n  dentarr_otype_drop_end_offs_pred_def dentarr_otype_drop_end_offs_st_pred_def\n\nlemma ple32_eq_slice:\n assumes \"offs < offs + 4\" \n assumes \"unat offs + 4 \\<le> length xs\"\n assumes \"offs + 4 < end_offs\"\n shows   \"ple32 xs offs = ple32 (slice (unat offs) (unat end_offs) xs) 0\"\n using assms \n  apply (simp add:  slice_def ple32_def drop_take word_add_eq_unat)\n  apply (drule less_to_le, simp add: unat_plus_simple word_less_nat_alt)\n done\n\nlemma split_upt_on_l_n:\n  \"n < m \\<Longrightarrow> l \\<le> n \\<Longrightarrow> [l ..< m] = [l ..< n] @ [n] @ [Suc n ..< m]\"\n  apply (subst upt_add_eq_append')\n  apply simp+\n  apply (simp add: upt_conv_Cons)\n  done\n\nlemma unat_plus_simple_imp:\n \"x \\<le> (x::'a::len word) + y \\<Longrightarrow> (unat (x + y) = unat x + unat y)\"\n by (simp add: unat_plus_simple)\n\nlemma pObjDentry_drop_eq:\n assumes offs_le_ost: \"offs \\<le> ost\"\n and     ost_no_of8: \" ost < ost + 8\"\n and     ost_le_offs_olen: \" ost \\<le> end_offs\"\n and     offs_olen_ys: \"unat end_offs \\<le> length ys\"\n and     ys_le_max: \" length ys \\<le> unat bilbyFsMaxEbSize\"\n and     end_offs: \"end_offs_nat = unat end_offs\"\n shows \" pObjDentry (take end_offs_nat ys) ost = pObjDentry (drop (unat offs) (take end_offs_nat ys)) (ost - offs)\"\nproof -\n have ost_4_nat: \"unat (ost + 4) = unat ost + 4\"\n   using ost_no_of8 by (simp add: unat_arith_simps) unat_arith\n\n have ost_le_max: \"ost \\<le> bilbyFsMaxEbSize\" using ys_le_max offs_olen_ys ost_le_offs_olen\n  by unat_arith\n\n hence offs_le_max: \"offs \\<le> bilbyFsMaxEbSize\"\n  using offs_le_ost by unat_arith\n\n\n have ost_minus_offs_bound: \"ost - offs \\<le> bilbyFsMaxEbSize\"\n  using  offs_le_ost ost_le_max\n  by unat_arith\n\n have ost_no_ofs: \"ost < ost + 4\" \"ost < ost + 6\" using ost_no_of8\n   by (clarsimp simp add: unat_arith_simps , unat_arith)+\n\n hence ost_offs_x: \"unat (ost - offs + 4) = unat ost - unat offs + 4\"\n                   \"unat (ost - offs + 6) = unat ost - unat offs + 6\"\n                   \"unat (ost - offs + 8) = unat ost - unat offs + 8\"\n   using offs_le_ost offs_le_ost[simplified word_le_nat_alt] ost_4_nat \n   ost_minus_offs_bound\n   apply (simp_all add: bilbyFsMaxEbSize_def)\n   apply ((drule plus_no_overflow_unat_lift)+, \n      (subst unat_plus_simple_imp,\n       simp only: word_le_nat_alt, unat_arith,subst unat_sub, simp+))\n\n   apply ((drule plus_no_overflow_unat_lift)+, \n      (subst unat_plus_simple_imp,\n       simp only: word_le_nat_alt, unat_arith,subst unat_sub, simp+))\n\n   apply ((drule plus_no_overflow_unat_lift)+)\n   apply (subst unat_plus_simple_imp)\n   apply (simp only: word_le_nat_alt word_less_nat_alt)\n   using offs_le_max[simplified bilbyFsMaxEbSize_def word_le_nat_alt]\n   ost_no_of8\n\n   apply (simp only:unat_arith_simps)\n   apply unat_arith\n  apply (subst unat_sub, simp+)\n done\n\n have offs_cancel: \"(unat ost - unat offs + 4 + unat offs) = unat ost + 4\" \n                   \"(unat ost - unat offs + 6 + unat offs) = unat ost + 6\"\n                   \"(unat ost - unat offs + 8 + unat offs) = unat ost + 8\"\n  using offs_le_ost[simplified word_less_nat_alt] by unat_arith+\n\n have ple16_eq: \"ple16 (take end_offs_nat ys) (ost + 6) = ple16 (drop (unat offs) (take end_offs_nat ys)) (ost - offs + 6)\"\n   apply (simp add: ple16_def)\n   apply (rule arg_cong[where f=word_rcat])\n   apply (rule arg_cong[where f=rev])\n   apply (rule arg_cong[where f=\"take 2\"])\n   apply (fastforce simp add: ost_offs_x offs_cancel less_to_le[OF ost_no_ofs(2), simplified unat_plus_simple])\n  done\n\n have offs_cancel': \"\\<forall>v. unat ost - unat offs + 8 + unat v + unat offs = unat ost + 8 + unat v\"\n  using offs_le_ost[simplified word_less_nat_alt]\n  by unat_arith\n\n show ?thesis\n  apply (simp add: pObjDentry_def Let_def ObjDentry.make_def)\n  apply (rule conjI)\n   apply (simp add: ple32_def)\n   apply (rule arg_cong[where f=word_rcat])\n   apply (rule arg_cong[where f=rev])\n   apply (rule arg_cong[where f=\"take 4\"])\n   apply (subst unat_sub[OF offs_le_ost])\n   using offs_le_ost\n   apply (subst add_diff_assoc2, fastforce simp: word_le_nat_alt)\n   apply fastforce\n  apply (rule conjI)\n   apply (simp add: pu8_def )\n   apply (rule arg_cong[where f=word_rcat])\n   apply (simp only: slice_def drop_take fun_app_def)\n   using ost_offs_x ost_4_nat\n   apply simp\n   apply (simp add: take_drop offs_cancel)\n   apply (subst add.commute, fastforce simp only: offs_cancel)\n  apply (simp add: ple16_eq )\n  apply (rule arg_cong[where f=WordArrayT.make])\n  apply (subgoal_tac \"\\<exists>v. ple16 (drop (unat offs) (take (unat offs + unat (Obj.len\\<^sub>f obj)) ys)) (ost - offs + 6) = v\")\n   apply (erule exE)\n   apply (simp only: ost_offs_x less_to_le[OF ost_no_of8, simplified unat_plus_simple])\n   apply (simp add: slice_def take_drop )\n   apply (simp add: offs_cancel offs_cancel')+\n  done\nqed\n\nlemma wa_length_ObjDentry_name_le:\n \"unat (wordarray_length (ObjDentry.name\\<^sub>f (pObjDentry xs ost))) \\<le> length xs\"\n by (simp add: pObjDentry_def Let_def ObjDentry.make_def wordarray_make wordarray_length_ret slice_def)\n\nlemma wa_length_ObjDentry_name_le_len:\n \"unat (wordarray_length (ObjDentry.name\\<^sub>f (pObjDentry xs ost))) \\<le> unat (ple16 xs (ost + 6))\"\n by (simp add: pObjDentry_def Let_def ObjDentry.make_def wordarray_make wordarray_length_ret slice_def)\n\nlemma dentarr_end_offs_list_induct_helper:\n assumes diff: \"Suc diff = unat to - frm\"\n and     ih: \"dentarr_offs_list_end_offs_pred (take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf))) (offs + 8 +\n     wordarray_length\n      (ObjDentry.name\\<^sub>f (pObjDentry (take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf))) offs)))\n    [Suc frm..<unat to] end_offs\"\n and cur: \"   offs + 8 +\n   wordarray_length (ObjDentry.name\\<^sub>f (pObjDentry (take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf))) offs))\n   \\<le> end_offs\"\n shows\n \"dentarr_offs_list_end_offs_pred (take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf))) offs [frm..<unat to] end_offs\"\nproof -\n  have frm_lt_to: \"frm < unat to\" using diff by unat_arith\n  show ?thesis\n  apply (clarsimp simp: dentarr_end_offs_simps )\n  apply (subst (asm) upt_rec, simp add: frm_lt_to Let_def) \n  apply (subst (asm) snd_fold_append_simp)\n  apply clarsimp\n  apply (erule disjE)\n   using cur apply simp\n  using ih apply (simp add: dentarr_end_offs_simps Let_def)\n done\nqed\n\nlemma offs_pl_8_name_of:\n  \" wellformed_buf buf \\<Longrightarrow>\n    length (\\<alpha>wa $ data\\<^sub>f buf) \\<le> unat bilbyFsMaxEbSize \\<Longrightarrow>\n    offs + 8 + wordarray_length (ObjDentry.name\\<^sub>f (pObjDentry (take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf))) offs)) \\<le> bound\\<^sub>f buf \\<Longrightarrow>\n    offs \\<le> bilbyFsMaxEbSize  \\<Longrightarrow>\n    offs < offs + 8\"\n apply (simp add: bilbyFsMaxEbSize_def)\n using wa_length_ObjDentry_name_le[where xs=\"(take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf)))\" and ost=offs]\n apply (clarsimp simp add: wellformed_buf_def)\n apply (simp add: unat_arith_simps)\ndone\n\nlemma mapAccumObsOpt_loop_deserialise_ObjDentry_ret:\n  assumes wellformed_buf: \"wellformed_buf buf\"\n  assumes no_buf_overflow: \"length (\\<alpha>wa $ data\\<^sub>f buf) \\<le> unat bilbyFsMaxEbSize\"\n  assumes bound: \"end_offs \\<le> bound\\<^sub>f buf\"\n  assumes off_less_end_offs: \"offs  \\<le> end_offs\"\n  assumes frm: \"frm \\<le> unat (to::word32)\" \"unat to \\<le> length ys\" \n  assumes st_offs: \"st_offs \\<le> offs\"\n  shows \n  \"let list_spec = \n      case (fold (\\<lambda>_ (xs, doffs, offslist).\n             let dentry = pObjDentry (take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf))) doffs ;\n                 newoffs = doffs +  8 + wordarray_length (ObjDentry.name\\<^sub>f dentry)\n             in (xs@[Option.Some dentry], \n                newoffs, offslist @ [newoffs])) \n           [frm..<unat to] ([], offs, [])) \n         of (xs, offs) \\<Rightarrow> ((take frm ys) @ xs @ (drop (unat to) ys), offs);\n      data = take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf)) in\n  (case mapAccumObsOpt frm (unat to) loop_deserialise_ObjDentry \n     ys (ex, offs) (buf, end_offs) of\n       Break (ys, d, ex) \\<Rightarrow> \n        d \\<in> {eInval, eNoMem}\n     | Iterate (ys, ex, offs') \\<Rightarrow> \n        \n        (ys, ex, offs') = (prod.fst list_spec, ex, prod.fst (prod.snd list_spec)) \\<and>\n        offs' \\<le> end_offs \\<and>\n        dentarr_offs_list_end_offs_pred data offs [frm..<unat to] end_offs \\<and>\n        dentarr_offs_list_drop_end_offs_pred data offs [frm..<unat to] st_offs end_offs)\"\n  using assms\n  proof (induct \"unat to - frm\" arbitrary: frm ys ex offs)\n  case 0\n  thus ?case\n   by (simp add: dentarr_end_offs_simps mapAccumObsOpt_n_n dentarr_drop_end_offs_simps)\nnext   \n  case (Suc diff) \n  note IH = this(1) and rest = this(2-)\n\n  have offs_le_max: \"offs \\<le> bilbyFsMaxEbSize\"\n   using rest by (simp add: unat_arith_simps wellformed_buf_def) \n\n  hence offs_pl_8: \"offs < offs + 8\"\n   by (simp add: bilbyFsMaxEbSize_def unat_arith_simps)\n\n  have offs_pl_8_pl_name:\n  \"offs + 8 \\<le> offs + 8 + wordarray_length (ObjDentry.name\\<^sub>f (pObjDentry (take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf))) offs))\"\n   using wa_length_ObjDentry_name_le[where xs=\"take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf))\" and ost=offs] rest offs_le_max\n     less_to_le[OF offs_pl_8]\n   by (simp add: wellformed_buf_def bilbyFsMaxEbSize_def unat_arith_simps)\n\n  have pObjDentry_eq: \n  \"pObjDentry (drop (unat st_offs) (take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf)))) (offs - st_offs) = pObjDentry (take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf))) offs\"\n      using rest offs_pl_8 by (fastforce intro: pObjDentry_drop_eq[symmetric,where end_offs=end_offs and offs=st_offs]\n                                simp add: wellformed_buf_def word_le_nat_alt)\n  \n  from rest show ?case\n  apply (subst mapAccumObsOpt_step, simp, simp)\n  apply (clarsimp simp: Let_def split: LoopResult.split)\n  apply (rule conjI)\n   using loop_deserialise_ObjDentry_ret[OF wellformed_buf no_buf_overflow bound , \n    where dentry=\"ys ! frm\" and  ex = ex and offs=offs]\n   apply fastforce\n  apply clarsimp\n  apply (rename_tac elem ex' offs')\n  apply (cut_tac \n            frm=\"Suc frm\" and \n            ys= \"ys[frm := elem]\" and    \n            ex =ex' and offs = offs' in IH[OF _ wellformed_buf no_buf_overflow bound], simp_all)\n    apply(cut_tac loop_deserialise_ObjDentry_ret[OF wellformed_buf no_buf_overflow bound ,\n          where dentry=\"ys ! frm\" and  ex = ex and offs=offs and st_offs=st_offs], simp_all)\n   apply(cut_tac loop_deserialise_ObjDentry_ret[OF wellformed_buf no_buf_overflow bound ,\n      where dentry=\"ys ! frm\" and  ex = ex and offs=offs and st_offs=st_offs], simp_all)\n   apply clarsimp\n   using  offs_pl_8_pl_name less_to_le[OF offs_pl_8]\n   apply (fastforce simp add:  unat_plus_simple word_le_nat_alt)\n  apply (clarsimp simp: Let_def)\n  apply (rule conjI)\n   apply fastforce\n  apply (clarsimp simp: Let_def)\n  apply (rename_tac ex'')\n  apply (thin_tac \"mapAccumObsOpt _ _ _ _ _ _ = _\")\n  apply(cut_tac loop_deserialise_ObjDentry_ret[OF wellformed_buf no_buf_overflow bound, \n      where dentry=\"ys ! frm\" and  ex = ex and offs=offs], simp_all)\n\n  apply (clarsimp simp: Let_def fst_fold_triple_simp fst_snd_fold_triple_simp prod.case_eq_if)\n  apply (rule conjI)\n   apply (simp add: upt_conv_Cons[where i = frm])\n   apply (subst take_Suc_conv_app_nth, simp)\n   apply (simp add: take_list_update prod.case_eq_if snd_fold_simp)\n   apply (subst fst_fold_append_simp[where xs=\"[]\", simplified, symmetric]) \n   apply fastforce\n\n  apply (rule conjI)\n   apply (simp add: snd_fold_simp)\n    apply (case_tac \"[frm..<unat to]\")\n     apply (fastforce+)\n   apply (rename_tac l ls)\n   apply (subgoal_tac \"[Suc frm..<unat to] = ls\")\n    prefer 2\n    apply (subst (asm) upt_rec[where i=frm], case_tac \"frm = unat to\"; fastforce)\n   apply simp\n\n  apply (rule conjI)\n   apply (erule (2) dentarr_end_offs_list_induct_helper)\n\n  apply (simp add: dentarr_offs_list_drop_end_offs_pred_def)\n  apply clarsimp\n  apply (rename_tac offs')\n  apply (simp add:  snd_fold_simp)\n  apply (case_tac \"offs' = offs + 8 + wordarray_length (ObjDentry.name\\<^sub>f (pObjDentry (take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf))) offs))\")\n   apply simp\n\n  apply (simp add: dentarr_offs_list_drop_def)\n  apply (subst (asm) split_upt_on_l_n[where l=frm and n=frm, simplified], fastforce)\n  apply (simp add: Let_def)\n  apply (subst (asm) snd_fold_append_simp[where xs=\"[_]\"])\n  apply (erule_tac x=\"offs' \" in ballE, fastforce)\n  apply (fastforce simp add: pObjDentry_eq)\n  done\nqed \n\nlemma replicate_simp:\n  \"replicate (unat to + 1 - unat to) (Option.None ()) = [Option.None ()]\"\n  by (simp add: unat_arith_simps)\n\nlemma mapAccumObsOpt_loop_deserialise_ObjDentry_array_ret:\n  assumes wellformed_buf: \"wellformed_buf buf\"\n  assumes no_buf_overflow: \"length (\\<alpha>wa $ data\\<^sub>f buf) \\<le> unat bilbyFsMaxEbSize\"\n  assumes bound: \"end_offs \\<le> bound\\<^sub>f buf\"\n  assumes off_less_end_offs: \"offs  \\<le> end_offs\"\n  assumes st_offs: \"st_offs \\<le> offs\"\n  shows\n  \"let data = take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf));\n       arr_spec = pArrObjDentry data offs to in \n   (case mapAccumObsOpt 0 (unat to) loop_deserialise_ObjDentry \n      (replicate (unat to + 1) (Option.None ())) (ex, offs) (buf, end_offs) of\n        LoopResult.Break (ys, d, ex) \\<Rightarrow> \n         d \\<in> {eInval, eNoMem}\n      | LoopResult.Iterate (ys, ex, offs') \\<Rightarrow> \n         (ys, ex, offs') = (\\<alpha>a (prod.fst arr_spec), ex, prod.fst (prod.snd arr_spec)) \\<and> \n         offs' \\<le> end_offs \\<and>\n        dentarr_offs_list_end_offs_pred data offs [0..<unat to] end_offs \\<and>\n        dentarr_offs_list_drop_end_offs_pred data offs [0..<unat to] st_offs end_offs)\"\n  unfolding pArrObjDentry_def Let_def\n  apply (clarsimp simp: array_make split: LoopResult.splits prod.splits)\n  using mapAccumObsOpt_loop_deserialise_ObjDentry_ret[OF assms(1-4), simplified Let_def, \n       where frm=0 and to=to and ex=ex  and st_offs=st_offs and\n       ys=\"replicate (unat to + 1)(Option.None ())\", simplified take_0 drop_replicate replicate_simp]\n   st_offs\n  apply (clarsimp split: LoopResult.splits) \n  done\n\nlemma array_map_loop_deserialise_ObjDentry_ret:\n  assumes wellformed_buf: \"wellformed_buf buf\"\n  assumes no_buf_overflow: \"length (\\<alpha>wa $ data\\<^sub>f buf) \\<le> unat bilbyFsMaxEbSize\"\n  assumes bound: \"end_offs \\<le> bound\\<^sub>f buf\"\n  assumes off_less_end_offs: \"offs  \\<le> end_offs\"\n  assumes st_offs: \"st_offs \\<le> offs\"\n  shows \"case array_map (ArrayMapP.make (ArrayT.make (replicate (unat to + 1) (Option.None ())))\n                   0 to loop_deserialise_ObjDentry (ex, offs) (buf, end_offs)) of\n         LoopResult.Break (arr, err, ex) \\<Rightarrow> err \\<in> {eInval, eNoMem}\n       | LoopResult.Iterate (arr, ex', offs') \\<Rightarrow>\n                  let data = take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf));\n                      (parr, poffs, poffslist) = pArrObjDentry data offs to;\n                      ostlist = pArrObjDentry data offs to\n                  in\n                   arr = parr \\<and> offs' = poffs \\<and>\n                  offs' \\<le> end_offs \\<and>\n        dentarr_offs_list_end_offs_pred data offs [0..<unat to] end_offs \\<and>\n        dentarr_offs_list_drop_end_offs_pred data offs [0..<unat to] st_offs end_offs\"\n  apply (clarsimp simp: ArrayMapP.make_def array_make array_map_ret)\n  using assms mapAccumObsOpt_loop_deserialise_ObjDentry_array_ret\n  [unfolded Let_def, where to=to and buf=buf and ex=ex and offs=offs and end_offs=end_offs and st_offs=st_offs]\n  by (clarsimp simp: array_make' Let_def split: LoopResult.splits)\n\nlemma deserialise_Array_ObjDentry_ret:\n  assumes wellformed_buf: \"wellformed_buf buf\"\n  assumes no_buf_overflow: \"length (\\<alpha>wa $ data\\<^sub>f buf) \\<le> unat bilbyFsMaxEbSize\"\n  assumes bound: \"end_offs \\<le> bound\\<^sub>f buf\"\n  assumes off_less_end_offs: \"offs  \\<le> end_offs\"\n  assumes st_offs: \"st_offs \\<le> offs\"\n  assumes offs_pl_8_no_of: \"offs \\<le> offs + 8\"\n  assumes offs_pl_8_le_end_offs: \"offs + 8 \\<le> end_offs\"\n  assumes err: \"\\<And>ex e. e \\<in> {eInval, eNoMem} \\<Longrightarrow> P (Error (e, ex))\"\n  assumes suc:\n   \"\\<And>ex arr offs' offslist data.\n    \\<lbrakk> (arr, offs',offslist) = (pArrObjDentry (take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf))) offs nb_dentry);\n       offs' \\<le>  end_offs;\n       data = take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf));\n        dentarr_offs_list_end_offs_pred data offs [0..<unat nb_dentry] end_offs;\n        dentarr_offs_list_drop_end_offs_pred data offs [0..<unat nb_dentry] st_offs end_offs \\<rbrakk> \\<Longrightarrow>\n      P (Success (ex, arr, offs'))\"\n  shows \"P (deserialise_Array_ObjDentry (ex, buf, offs, nb_dentry, end_offs))\"\n  unfolding deserialise_Array_ObjDentry_def[unfolded tuple_simps sanitizers]\n  apply (simp add: Let_def)\n  apply (rule array_create_ret)\n   apply (simp add: err[unfolded eNoMem_def])\n  apply (rename_tac ex' arr a)\n  apply (subgoal_tac \"unat nb_dentry + 1 = unat (nb_dentry+1) \")\n   apply (clarsimp simp: prod.case_eq_if id_def Let_def split: LoopResult.splits)\n   apply (subgoal_tac \"a = ArrayT.make (replicate (unat (nb_dentry + 1)) (Option.None ()))\", simp)\n    apply (cut_tac ex=ex' in array_map_loop_deserialise_ObjDentry_ret[simplified ArrayMapP.defs, OF assms(1-5), where to = nb_dentry])\n    apply (clarsimp simp: Let_def err split: LoopResult.splits)\n     apply (rename_tac offslist a ex'' offs')\n     apply (rule suc)\n     apply simp+  \n   apply (metis array_make')\n  apply unat_arith\n  done\n\n\nlemma word_add_diff_assoc:\n \"(a::'a:: len0 word) + b - c = a + (b - c)\"\n by simp\n\nmethod offs_olen_of_solver =\n  (((drule less_to_le)?, simp add: word_add_diff_assoc unat_plus_simple),\n   (simp only: unat_arith_simps)?, simp? ; unat_arith)\n\nlemma deserialise_ObjDentarr_ret:\n  assumes wf: \"wellformed_buf buf\"\n  assumes buf_len: \"length (\\<alpha>wa $ data\\<^sub>f buf) \\<le> unat bilbyFsMaxEbSize\"\n  assumes err: \"\\<And>ex e. e \\<in> {eInval, eNoMem} \\<Longrightarrow> P (Error (e, ex))\"\n  assumes offs_bound: \"offs + olen - bilbyFsObjHeaderSize \\<le> (bound\\<^sub>f buf)\"\n  assumes offs_olen: \"offs < offs + olen - bilbyFsObjHeaderSize\"\n  assumes olen: \"bilbyFsObjHeaderSize + bilbyFsObjDentarrHeaderSize + bilbyFsObjDentryHeaderSize \\<le> olen\"\n  assumes st_offs: \"st_offs \\<le> offs\"\n  assumes suc:\n  \"\\<And>ex dentarr offs'. \\<lbrakk>\n  dentarr = pObjDentarr (\\<alpha>wa (data\\<^sub>f buf)) offs olen;\n  offs' = pObjDentarrSize (\\<alpha>wa (data\\<^sub>f buf)) offs olen;\n  let end_offs = offs + olen - bilbyFsObjHeaderSize;\n  data = take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf));\n  nb_dentry = ple32 (\\<alpha>wa (data\\<^sub>f buf)) (offs+8) in\n  dentarr_offs_list_end_offs_pred data (offs+bilbyFsObjDentarrHeaderSize) [0..<unat nb_dentry] end_offs \\<and>\n  dentarr_offs_list_drop_end_offs_pred data (offs+bilbyFsObjDentarrHeaderSize) [0..<unat nb_dentry] st_offs end_offs;\n  offs' \\<le> offs + olen - bilbyFsObjHeaderSize\n  \\<rbrakk> \\<Longrightarrow>\n  P (Success (ex, dentarr, offs'))\"\n notes bilbyFsObjDentarrHeaderSize_def[simp] bilbyFsObjHeaderSize_def[simp]\n       bilbyFsObjDentryHeaderSize_def[simp]\n  shows \"P (deserialise_ObjDentarr (ex, buf, offs, olen))\"\n  proof -\n\n  have offs_no_of: \"offs < offs + bilbyFsObjDentarrHeaderSize\"\n    using olen and offs_olen by simp unat_arith\n\n   have bound_max: \"bound\\<^sub>f buf \\<le> bilbyFsMaxEbSize\"\n     using wf and buf_len by (simp add: wellformed_buf_def) unat_arith\n\n   have offs_bound':  \"offs < bilbyFsMaxEbSize\"\n     using offs_bound offs_olen bound_max offs_no_of by simp\n\n   have offs_hdr_no_of: \"offs < offs + bilbyFsObjDentarrHeaderSize\"\n     using offs_bound' by (simp add: bilbyFsMaxEbSize_def unat_arith_simps)\n\n  have offs_pl_hdr_le_len: \"unat offs + unat bilbyFsObjDentarrHeaderSize \\<le> length (\\<alpha>wa $ data\\<^sub>f buf)\"\n   using offs_bound wf offs_no_of offs_olen olen\n   by (simp add: wellformed_buf_def) unat_arith\n  have deserialises:\n    \"deserialise_le32 (buf, offs + 8) = (ple32 (\\<alpha>wa $ data\\<^sub>f buf) (offs + 8))\"\n    \"deserialise_le64 (buf, offs) = (ple64 (\\<alpha>wa $ data\\<^sub>f buf) offs)\"\n       using offs_pl_hdr_le_len apply (clarsimp simp:)\n       apply (rule deserialise_le32_ret[simplified])\n         using offs_hdr_no_of apply unat_arith\n       using offs_hdr_no_of apply (simp add: unat_arith_simps)\n       apply unat_arith\n\n     using offs_pl_hdr_le_len apply (clarsimp)\n     apply (rule deserialise_le64_ret[simplified])\n    using offs_hdr_no_of  apply unat_arith\n   using offs_hdr_no_of apply (simp add: unat_arith_simps)\n   apply unat_arith\n  done\n  show ?thesis\n  unfolding deserialise_ObjDentarr_def[unfolded tuple_simps sanitizers]\n   apply (clarsimp simp: Let_def err[unfolded eInval_def])\n   apply (subgoal_tac \"\\<exists>v. olen - bilbyFsObjHeaderSize = v \\<and> bilbyFsObjDentarrHeaderSize + bilbyFsObjDentryHeaderSize \\<le> v\")\n    apply (erule exE)\n   apply (erule conjE)\n    apply (rule deserialise_Array_ObjDentry_ret[OF assms(1,2), where st_offs=st_offs,\n             simplified])\n         using offs_bound apply simp\n        subgoal using offs_olen olen by - offs_olen_of_solver\n       subgoal for v\n        using st_offs  offs_olen by - offs_olen_of_solver\n      subgoal for v\n       using offs_olen by - offs_olen_of_solver\n     subgoal for v\n      using offs_olen by (simp add: word_add_diff_assoc add.commute)\n                         (rule word_plus_mono_right; simp)\n    subgoal for v _ e by (fastforce intro: err)\n   subgoal for v ex arr offs' offslist\n    apply (case_tac \"Result.Success (ex, arr, offs')\", simp_all)\n    apply (clarsimp simp: Let_def err[unfolded eNoMem_def] split: Result.split)\n    apply (rule suc)\n        subgoal\n        apply (simp add: pObjDentarr_def Let_def)\n        apply (subst ObjDentarr.surjective, simp add: ObjDentarr.make_def deserialises prod_eq_iff)\n        done\n       subgoal by (clarsimp simp add: prod_eq_iff pObjDentarrSize_def deserialises)\n      subgoal by (simp add: Let_def deserialises)\n     subgoal by simp\n   done\n  subgoal using olen by (simp) unat_arith\n  done\nqed\n\nlemmas pObjUnion_def' = \n  pObjUnion_def[unfolded otype_simps, simplified]\n\nlemmas len_otype_ok = is_len_and_type_ok_def[unfolded sanitizers tuple_simps]\n\nlemma olen_bound_trivial:\n \"   0x28 \\<le> (olen::U32) \\<Longrightarrow>\n    offs + olen - 0x18 \\<le> bound\\<^sub>f buf \\<Longrightarrow>\n    offs \\<le> offs + olen - 0x18 \\<Longrightarrow> offs + 0x10 \\<le> bound\\<^sub>f buf\"\n  by unat_arith\n\nlemma offs_trivial:\n \"(offs::U32) \\<le> offs + olen - 0x18 \\<Longrightarrow>\n    0x28 \\<le> olen \\<Longrightarrow>\n    offs < offs + 0x10\"\n by unat_arith\n\nlemma unat_obj_len_minus_hdrsz:\n  assumes len_otype_rel: \"bilbyFsObjHeaderSize \\<le> olen\"\n  assumes offs_no_of: \"offs \\<le> offs + olen - bilbyFsObjHeaderSize\"\nshows\n \"unat (offs + olen - bilbyFsObjHeaderSize) = unat offs + unat olen - unat bilbyFsObjHeaderSize\"\n using assms\n by (simp add: bilbyFsObjHeaderSize_def word_add_diff_assoc  unat_plus_simple) (simp add: unat_arith_simps)\n \n\nlemma deserialise_ObjUnion_ret:\n  assumes wf: \"wellformed_buf buf\"\n  assumes no_buf_overflow: \"length (\\<alpha>wa $ data\\<^sub>f buf) \\<le> unat bilbyFsMaxEbSize\"\n  assumes bound: \"offs + olen - bilbyFsObjHeaderSize \\<le> bound\\<^sub>f buf\"\n  assumes len_otype_rel: \"is_len_and_type_ok (otype, olen)\"\n  assumes offs_no_of: \"offs \\<le> offs + olen - bilbyFsObjHeaderSize\"\n  assumes offs_no_underflow: \"offs - bilbyFsObjHeaderSize \\<le> offs\"\n  assumes err:\n  \"\\<And>ex e. e \\<in> {eInval, eNoMem} \\<Longrightarrow> P (Error (e, ex))\"\n  assumes suc:\n  \"\\<And>ex ounion offs'. ounion = pObjUnion (\\<comment> \\<open>take (unat (offs + olen))\\<close> (\\<alpha>wa (data\\<^sub>f buf))) otype olen offs  \\<Longrightarrow>\n   offs' \\<le> (offs + olen - bilbyFsObjHeaderSize) \\<Longrightarrow>\n  let end_offs = offs + olen - bilbyFsObjHeaderSize;\n  data = take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf));\n  nb_dentry = ple32 (\\<alpha>wa (data\\<^sub>f buf)) (offs+8) in\n  dentarr_otype_end_offs_pred otype data offs end_offs \\<and>\n  dentarr_otype_drop_end_offs_st_pred otype data offs (offs - bilbyFsObjHeaderSize) end_offs \n  \\<Longrightarrow>\n   P (Success (ex, ounion, offs'))\"\n  notes suc_simps = len_otype_ok Let_def  pObjUnion_def' suc add.commute bilbyFsObjHeaderSize_def\n          otype_simps dentarr_end_offs_simps  dentarr_drop_end_offs_simps\n        shows \"P (deserialise_ObjUnion (ex, buf, offs, (otype, olen)))\"\n  unfolding deserialise_ObjUnion_def[unfolded tuple_simps, simplified sanitizers]\n  using is_len_and_type_ok_hdr_szD[OF len_otype_rel] \n  apply (clarsimp simp: Let_def)\n  apply (rule conjI)\n   apply clarsimp\n   apply (rule deserialise_ObjSuper_ret, simp)\n      using len_otype_rel offs_no_of bound wf\n      apply (simp add: len_otype_ok Let_def prod.case_eq_if wellformed_buf_def bilbyFsObjHeaderSize_def)\n      apply unat_arith\n     using len_otype_rel offs_no_of bound wf\n     apply (simp add: len_otype_ok Let_def prod.case_eq_if wellformed_buf_def bilbyFsObjHeaderSize_def)\n     apply unat_arith\n    apply (simp add: err)\n\n   using len_otype_rel\n   apply (simp add: suc_simps)\n  apply clarsimp\n  apply (rule conjI)\n   apply clarsimp\n   apply (rule deserialise_ObjDel_ret, simp)\n      using len_otype_rel offs_no_of bound wf\n      apply (simp add: len_otype_ok Let_def prod.case_eq_if wellformed_buf_def bilbyFsObjHeaderSize_def)\n      apply unat_arith\n     apply (simp add: err)\n      using len_otype_rel offs_no_of bound wf\n      apply (simp add: len_otype_ok Let_def prod.case_eq_if wellformed_buf_def bilbyFsObjHeaderSize_def)\n      apply unat_arith\n   using len_otype_rel\n   apply (simp add: suc_simps)\n\n  apply clarsimp\n  apply (rule conjI)\n   apply clarsimp\n   apply (rule deserialise_ObjDentarr_ret[OF wf no_buf_overflow, where st_offs =\"offs - bilbyFsObjHeaderSize\"])\n        apply (simp add: err)\n       using bound  offs_no_of len_otype_rel \n       apply (simp add: len_otype_ok Let_def prod.case_eq_if wellformed_buf_def bilbyFsObjHeaderSize_def)\n      using offs_no_of len_otype_rel \n      apply (simp add: len_otype_ok bilbyFsObjHeaderSize_def )\n      apply (simp add: word_add_diff_assoc unat_plus_simple word_less_nat_alt )\n      apply unat_arith\n     using  len_otype_rel\n     apply (simp add: len_otype_ok bilbyFsObjHeaderSize_def bilbyFsObjDentryHeaderSize_def bilbyFsObjDentarrHeaderSize_def)\n     using offs_no_underflow apply simp\n   apply (simp add: suc pObjUnion_def' )\n   apply (rule suc)\n      apply (clarsimp simp add: pObjUnion_def')+\n   apply (simp add: dentarr_otype_drop_end_offs_st_pred_def dentarr_otype_end_offs_pred_def dentarr_otype_drop_end_offs_pred_def\n        bilbyFsObjTypeDentarr_def Let_def)\n   apply clarsimp\n   apply (subgoal_tac \"ple32 (take (unat (offs + olen - bilbyFsObjHeaderSize)) (\\<alpha>wa (data\\<^sub>f buf))) (offs + 8) = ple32 (\\<alpha>wa (data\\<^sub>f buf)) (offs + 8)\")\n    apply simp\n   apply (subgoal_tac \"\\<exists>v. olen - bilbyFsObjHeaderSize = v\")\n    apply (erule exE)\n    apply (subst ple32_take)\n(* <automate?> *)\n      using len_otype_rel \n      apply (simp add: len_otype_ok bilbyFsObjHeaderSize_def)\n      using offs_no_of apply (simp add: word_add_diff_assoc  bilbyFsObjHeaderSize_def)\n      apply (simp add: word_add_diff_assoc unat_plus_simple word_less_nat_alt word_le_nat_alt add.commute)\n      apply (subst (asm) add.commute)\n      using offs_no_of apply (simp add: bilbyFsObjHeaderSize_def) apply (simp add: word_add_diff_assoc word_le_nat_alt)\n      apply (simp only: unat_arith_simps)\n      apply unat_arith\n    apply (simp add: bilbyFsObjHeaderSize_def word_add_diff_assoc)\n     using offs_no_of \n     apply (simp add: bilbyFsObjHeaderSize_def word_add_diff_assoc word_less_nat_alt  add.commute)\n     apply (subst (asm) add.commute, simp add: unat_plus_simple)\n     using offs_no_of apply (simp add: bilbyFsObjHeaderSize_def)\n     apply (simp add: word_add_diff_assoc)\n     using len_otype_rel\n      apply (simp add: len_otype_ok)\n     apply (subgoal_tac \"offs \\<le> offs + 0xC\")\n      apply (simp add: unat_plus_simple add.commute, simp only: word_le_nat_alt)\n      apply unat_arith\n     apply (simp add: unat_plus_simple add.commute, simp only: word_le_nat_alt)\n     apply unat_arith\n(* </automate?> *)\n    apply simp\n   apply (fastforce)\n  apply clarsimp\n  apply (rule conjI)\n   apply clarsimp\n   apply (rule deserialise_ObjData_ret[OF ])\n       using offs_no_of \n       apply (simp only: diff_conv_add_uminus)\n       apply (simp only: add.assoc)\n      using bound wf offs_no_of apply (simp add: bilbyFsObjHeaderSize_def\n        wellformed_buf_def diff_conv_add_uminus add.assoc)\n      apply unat_arith\n     using len_otype_rel   apply (simp add: otype_simps)\n    apply (simp add: err)\n   apply simp\n   apply (simp add: suc_simps)\n\n  apply (clarsimp)\n  apply (rule conjI)\n   apply clarsimp\n   apply (rule deserialise_ObjInode_ret)\n      using len_otype_rel offs_no_of bound\n         bound wf offs_no_of\n       apply (simp add: bilbyFsObjHeaderSize_def wellformed_buf_def )\n     using len_otype_rel  apply (simp add: otype_simps len_otype_ok)\n       apply unat_arith\n     using len_otype_rel  apply (simp add: otype_simps len_otype_ok)\n       using  offs_no_of\n       apply (simp add: bilbyFsObjHeaderSize_def)\n       apply unat_arith\n     apply (simp add: err)\n     using len_otype_rel  apply (simp add: otype_simps len_otype_ok)\n    apply (simp add: suc_simps)\n  apply clarsimp\n  apply (rule deserialise_ObjPad_ret)\n   apply (simp add:err)  \n  apply (simp add: suc_simps add_diff_eq)+\n done\n\nlemma pObjDel_take:\n \"is_valid_ObjHeader (pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs) (bounded buf) \\<Longrightarrow>\n       offs + Obj.len\\<^sub>f obj \\<le> bound\\<^sub>f buf \\<Longrightarrow>\n       is_len_and_type_ok (otype\\<^sub>f obj, Obj.len\\<^sub>f obj) \\<Longrightarrow>\n       offs < offs + Obj.len\\<^sub>f obj \\<Longrightarrow>\n       otype\\<^sub>f obj = 3 \\<Longrightarrow>\n       \\<exists>v. obj\\<lparr>ounion\\<^sub>f := v\\<rparr> = pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs \\<Longrightarrow>\n   pObjDel (\\<alpha>wa (data\\<^sub>f buf)) (offs + bilbyFsObjHeaderSize) =\n      pObjDel (take (unat (offs + Obj.len\\<^sub>f obj)) (\\<alpha>wa (data\\<^sub>f buf))) (offs + bilbyFsObjHeaderSize)\"\n  apply (simp add: pObjDel_def)\n  apply (frule is_valid_ObjHeader_buf_len, clarify)\n  apply (subst ple64_take, (simp add: otype_simps len_otype_ok bilbyFsObjHeaderSize_def, unat_arith)+)\n  apply simp\ndone\n\nlemma pObjSuper_take:\n \"is_valid_ObjHeader (pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs) (bounded buf) \\<Longrightarrow>\n       offs + Obj.len\\<^sub>f obj \\<le> bound\\<^sub>f buf \\<Longrightarrow>\n       is_len_and_type_ok (otype\\<^sub>f obj, Obj.len\\<^sub>f obj) \\<Longrightarrow>\n       offs < offs + Obj.len\\<^sub>f obj \\<Longrightarrow>\n       otype\\<^sub>f obj = 4 \\<Longrightarrow>\n       \\<exists>v. obj\\<lparr>ounion\\<^sub>f := v\\<rparr> = pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs \\<Longrightarrow>\n    pObjSuper (\\<alpha>wa (data\\<^sub>f buf)) (offs + bilbyFsObjHeaderSize) =\n     pObjSuper (take (unat (offs + Obj.len\\<^sub>f obj)) (\\<alpha>wa (data\\<^sub>f buf))) (offs + bilbyFsObjHeaderSize)\"\n  apply (simp add: pObjSuper_def)\n  apply (frule is_valid_ObjHeader_buf_len, clarify)\n  apply (subst ple64_take, ((simp add: otype_simps len_otype_ok bilbyFsObjHeaderSize_def, unat_arith)+)[2])\n  apply (subst ple32_take, ((simp add: otype_simps len_otype_ok bilbyFsObjHeaderSize_def, unat_arith)+)[2])+\n  apply simp\n done\n\nlemma pObjInode_take:\n \"is_valid_ObjHeader (pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs) (bounded buf) \\<Longrightarrow>\n       offs + Obj.len\\<^sub>f obj \\<le> bound\\<^sub>f buf \\<Longrightarrow>\n       is_len_and_type_ok (otype\\<^sub>f obj, Obj.len\\<^sub>f obj) \\<Longrightarrow>\n       offs < offs + Obj.len\\<^sub>f obj \\<Longrightarrow>\n       otype\\<^sub>f obj = 0 \\<Longrightarrow>\n       \\<exists>v. obj\\<lparr>ounion\\<^sub>f := v\\<rparr> = pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs \\<Longrightarrow>\n    pObjInode (\\<alpha>wa (data\\<^sub>f buf)) (offs + bilbyFsObjHeaderSize) =\n     pObjInode (take (unat (offs + Obj.len\\<^sub>f obj)) (\\<alpha>wa (data\\<^sub>f buf))) (offs + bilbyFsObjHeaderSize)\"\n  apply (simp add: pObjInode_def)\n  apply (frule is_valid_ObjHeader_buf_len, clarify)\n  apply (subst ple64_take, ((simp add: otype_simps len_otype_ok bilbyFsObjHeaderSize_def, unat_arith)+)[2])+\n  apply (subst ple32_take, ((simp add: otype_simps len_otype_ok bilbyFsObjHeaderSize_def, unat_arith)+)[2])+\n  apply simp\n done\n\nlemma pObjDentarr_take:\n \"is_valid_ObjHeader (pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs) (bounded buf) \\<Longrightarrow>\n       offs + Obj.len\\<^sub>f obj \\<le> bound\\<^sub>f buf \\<Longrightarrow>\n       is_len_and_type_ok (otype\\<^sub>f obj, Obj.len\\<^sub>f obj) \\<Longrightarrow>\n       offs < offs + Obj.len\\<^sub>f obj \\<Longrightarrow>\n       otype\\<^sub>f obj = 2 \\<Longrightarrow>\n       \\<exists>v. obj\\<lparr>ounion\\<^sub>f := v\\<rparr> = pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs \\<Longrightarrow>\n    pObjDentarr (\\<alpha>wa (data\\<^sub>f buf)) (offs + bilbyFsObjHeaderSize) (Obj.len\\<^sub>f obj) =\n     pObjDentarr (take (unat (offs + Obj.len\\<^sub>f obj)) (\\<alpha>wa (data\\<^sub>f buf))) (offs + bilbyFsObjHeaderSize) (Obj.len\\<^sub>f obj)\"\n  apply (simp add: pObjDentarr_def)\n  apply (frule is_valid_ObjHeader_buf_len, clarify)\n  apply (subst ple64_take, ((simp add: otype_simps len_otype_ok bilbyFsObjHeaderSize_def, unat_arith)+)[2])+\n  apply (subst ple32_take, ((simp add: otype_simps len_otype_ok bilbyFsObjHeaderSize_def, unat_arith)+)[2])+\n  apply (simp add: Let_def) \n done\n\n\nlemma pObjData_take:\n\"is_valid_ObjHeader (pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs) (bounded buf) \\<Longrightarrow>\n       offs + Obj.len\\<^sub>f obj \\<le> bound\\<^sub>f buf \\<Longrightarrow>\n       is_len_and_type_ok (otype\\<^sub>f obj, Obj.len\\<^sub>f obj) \\<Longrightarrow>\n       offs < offs + Obj.len\\<^sub>f obj \\<Longrightarrow>\n       otype\\<^sub>f obj = 1 \\<Longrightarrow>\n       \\<exists>v. obj\\<lparr>ounion\\<^sub>f := v\\<rparr> = pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs \\<Longrightarrow>\npObjData (\\<alpha>wa (data\\<^sub>f buf)) (offs + bilbyFsObjHeaderSize) (Obj.len\\<^sub>f obj) =\n    pObjData (take (unat (offs + Obj.len\\<^sub>f obj)) (\\<alpha>wa (data\\<^sub>f buf))) (offs + bilbyFsObjHeaderSize)\n     (Obj.len\\<^sub>f obj)\"\n   apply (simp add: pObjData_def)\n  apply (subst ple64_take, ((simp add: otype_simps len_otype_ok bilbyFsObjHeaderSize_def, unat_arith)+)[2])+\n    apply (simp add: otype_simps len_otype_ok)\n    apply (subst slice_take)\n      apply (frule is_valid_ObjHeader_len)\n      apply (subgoal_tac \" unat (Obj.len\\<^sub>f obj - bilbyFsObjHeaderSize - bilbyFsObjDataHeaderSize) =  unat (Obj.len\\<^sub>f obj) - unat bilbyFsObjHeaderSize - unat bilbyFsObjDataHeaderSize\")\n       apply (subgoal_tac \"unat (offs + Obj.len\\<^sub>f obj) = unat offs + unat ( Obj.len\\<^sub>f obj)\")\n         apply simp\n         apply (simp add: bilbyFsObjHeaderSize_def bilbyFsObjDataHeaderSize_def)\n         apply unat_arith\n        apply (simp add: word_less_nat_alt unat_plus_simple[symmetric], unat_arith)\n      apply (subst unat_sub, simp add: bilbyFsObjHeaderSize_def bilbyFsObjDataHeaderSize_def, unat_arith)+\n    apply simp+\n done\n\nlemma pObjUnion_take:\n \"is_valid_ObjHeader (pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs) (bounded buf) \\<Longrightarrow>\n       offs + Obj.len\\<^sub>f obj \\<le> bound\\<^sub>f buf \\<Longrightarrow>\n       is_len_and_type_ok (otype\\<^sub>f obj, Obj.len\\<^sub>f obj) \\<Longrightarrow>\n       offs < offs + Obj.len\\<^sub>f obj \\<Longrightarrow>\n       \\<exists>v. obj\\<lparr>ounion\\<^sub>f := v\\<rparr> = pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs \\<Longrightarrow>\n      pObjUnion (\\<alpha>wa (data\\<^sub>f buf)) (otype\\<^sub>f obj) (Obj.len\\<^sub>f obj) (offs + bilbyFsObjHeaderSize) = \n      pObjUnion (take (unat (offs + Obj.len\\<^sub>f obj)) (\\<alpha>wa (data\\<^sub>f buf))) (otype\\<^sub>f obj) (Obj.len\\<^sub>f obj) (offs + bilbyFsObjHeaderSize)\"\n  apply (simp add: pObjUnion_def')\n  apply (case_tac \"otype\\<^sub>f obj = 0\")\n   apply (simp add: pObjInode_take)\n  apply (case_tac \"otype\\<^sub>f obj = 1\")\n   apply (simp add: pObjData_take)\n  apply (case_tac \"otype\\<^sub>f obj = 2\")\n   apply (simp add: pObjDentarr_take)\n  apply (case_tac \"otype\\<^sub>f obj = 3\")\n   apply (simp add: pObjDel_take)\n  apply (case_tac \"otype\\<^sub>f obj = 4\")\n   apply (simp add: pObjSuper_take)\n  apply simp\n done\n\nlemmas Obj_ext_eq_expand = trans[OF _ Obj.ext_inject,\n    OF arg_cong2[where f=\"(=)\"], OF refl Obj.surjective]\n\nlemma deserialise_Obj_ret:\n  assumes wf: \"wellformed_buf buf\"\n  assumes buf_len: \"length (\\<alpha>wa $ data\\<^sub>f buf) \\<le> unat bilbyFsMaxEbSize\"\n  assumes bound: \"offs + bilbyFsObjHeaderSize \\<le> bound\\<^sub>f buf\"\n  assumes no_of: \"offs < offs + bilbyFsObjHeaderSize\"\n  assumes err: \"\\<And>ex e. e \\<in> {eInval, eNoMem} \\<Longrightarrow> P (Error (e, ex))\"\n  assumes suc:\n   \"\\<And>ex obj offs'. \\<lbrakk> \n    is_valid_ObjHeader (pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs) (\\<alpha>wa (data\\<^sub>f buf)) ;\n\n    let end_offs = offs + (Obj.len\\<^sub>f obj);\n    data = take (unat end_offs) (\\<alpha>wa (data\\<^sub>f buf));\n    nb_dentry = ple32 (\\<alpha>wa (data\\<^sub>f buf)) (offs+8) in\n    dentarr_otype_end_offs_pred (Obj.otype\\<^sub>f obj) data (offs + bilbyFsObjHeaderSize) end_offs \\<and>\n    dentarr_otype_drop_end_offs_st_pred (Obj.otype\\<^sub>f obj) data (offs + bilbyFsObjHeaderSize) offs end_offs;\n    obj = pObj (\\<alpha>wa (data\\<^sub>f buf)) offs;\n    offs' \\<le> offs + Obj.len\\<^sub>f obj \\<rbrakk> \\<Longrightarrow> \n\n   P (Success (ex, obj, offs'))\"\n  notes bilbyFsObjHeaderSize_def[simp]\n  shows \"P (deserialise_Obj (ex, buf, offs))\"\n  unfolding deserialise_Obj_def[unfolded tuple_simps sanitizers]\n  apply (clarsimp simp: err eNoMem_def split: Result.split)\n  apply (rule deserialise_ObjHeader_ret[OF wf bound no_of])\n   apply (simp add: err)\n  apply simp\n  apply (rule deserialise_ObjUnion_ret[OF wf buf_len])\n        apply (simp)\n     apply (clarsimp, drule sym[where t=\"pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs\"])\n     apply (clarsimp simp  add: is_valid_ObjHeader_def)\n    apply simp\n    apply (drule is_valid_ObjHeader_len)\n    apply (clarsimp, drule sym[where t=\"pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs\"])\n    apply (drule arg_cong[where f=Obj.len\\<^sub>f])\n    using no_of bound\n    apply simp\n    apply  (simp only: word_le_nat_alt plus_no_overflow_unat_lift)\n   apply (drule is_valid_ObjHeader_len)\n    apply (clarsimp, drule sym[where t=\"pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs\"])\n    apply (drule arg_cong[where f=Obj.len\\<^sub>f])\n   apply (clarsimp simp add: )\n   apply unat_arith\n   apply (simp add: err)\n\n  apply simp\n  apply (rule suc)\n       apply (clarsimp simp add: is_valid_ObjHeader_def bounded_def)\n      apply simp\n   apply (clarsimp simp add: pObj_def Let_def)\n   apply (drule sym[where t=\"pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs\"])\n   apply (subst pObjUnion_take[simplified], (fastforce simp add: is_valid_ObjHeader_def)+)\n   apply (rename_tac obj offs' v)\n   apply (subgoal_tac \"pObjUnion (take (unat (offs + Obj.len\\<^sub>f obj)) (\\<alpha>wa (data\\<^sub>f buf))) (otype\\<^sub>f obj)\n              (Obj.len\\<^sub>f obj) (offs + 0x18) = pObjUnion\n           (take (unat offs + unat (Obj.len\\<^sub>f (pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs))) (\\<alpha>wa (data\\<^sub>f buf)))\n           (otype\\<^sub>f (pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs))\n           (Obj.len\\<^sub>f (pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs)) (offs + 0x18)\")\n    apply simp\n   apply (case_tac \"pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs\", case_tac obj, simp)\n   apply (case_tac \"pObjHeader (\\<alpha>wa (data\\<^sub>f buf)) offs\", case_tac obj, simp)\n   apply (simp add: plus_no_overflow_unat_lift)+\n    done\n\nlemma pObjHeader_take:\n \"is_valid_ObjHeader (pObjHeader xs (ObjAddr.offs\\<^sub>f oaddr)) xs \\<Longrightarrow>\nis_obj_addr_consistent (pObj (take (unat (ObjAddr.offs\\<^sub>f oaddr) + unat (ObjAddr.len\\<^sub>f oaddr)) xs)\n          (ObjAddr.offs\\<^sub>f oaddr)) oaddr \\<Longrightarrow>\n  ObjAddr.offs\\<^sub>f oaddr < ObjAddr.offs\\<^sub>f oaddr + bilbyFsObjHeaderSize \\<Longrightarrow>\n  bilbyFsObjHeaderSize \\<le> ObjAddr.len\\<^sub>f oaddr \\<Longrightarrow>\n   pObjHeader xs (ObjAddr.offs\\<^sub>f oaddr) = pObjHeader (take (unat (ObjAddr.offs\\<^sub>f oaddr) + unat (ObjAddr.len\\<^sub>f oaddr)) xs) (ObjAddr.offs\\<^sub>f oaddr)\"\n\n  apply (simp add: pObjHeader_def)\n  apply (subst ple32_take, ((simp add: bilbyFsObjHeaderSize_def, unat_arith, fastforce? )[2])+)+\n  apply (subst ple64_take, ((simp add: bilbyFsObjHeaderSize_def, unat_arith, fastforce? )[2])+)+\n  apply (subst nth_take,   (simp add: bilbyFsObjHeaderSize_def, unat_arith))+\n  apply (rule refl)\ndone\n\nend\n\n", "meta": {"author": "au-ts", "repo": "cogent", "sha": "a1464313bbd1bbfaa5c4e58ab14f669c6d2436a2", "save_path": "github-repos/isabelle/au-ts-cogent", "path": "github-repos/isabelle/au-ts-cogent/cogent-a1464313bbd1bbfaa5c4e58ab14f669c6d2436a2/impl/fs/bilby/proof/spec/SerialS.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297745935070806, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.2976840443461467}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory Memset\nimports \"../../AutoCorres\"\nbegin\n\ninstall_C_file \"memset.c\"\n\nautocorres [\n  heap_abs_syntax,\n  no_heap_abs=memset,\n  no_signed_word_abs=memset,\n  unsigned_word_abs=memset] \"memset.c\"\n\nlemma c_guard_word8_ptr [simp]:\n     \"c_guard (x :: word8 ptr) = (x \\<noteq> NULL)\"\n  apply (clarsimp simp: c_guard_def ptr_aligned_def c_null_guard_def)\n  apply (metis Ptr_ptr_val first_in_intvl intvl_Suc not_less_eq ptr_val.ptr_val_def)\n  done\n\nlemma to_bytes_word8 [simp]: \"to_bytes (a :: word8) x = [a]\"\n  by (clarsimp simp: to_bytes_def typ_info_word word_rsplit_same)\n\nlemma heap_update_list_id [simp]:\n    \"heap_update_list x [] = (\\<lambda>x. x)\"\n  apply (rule ext)\n  apply simp\n  done\n\nlemma heap_update_heap_update_list:\n   \"\\<lbrakk> ptr_val p = q + (of_nat (length l)); Suc (length l) < addr_card \\<rbrakk> \\<Longrightarrow>\n      heap_update (p :: word8 ptr) v (heap_update_list q l s) = (heap_update_list q (l @ [v]) s)\"\n  apply (rule ext)\n  apply (clarsimp simp: heap_update_def unat_of_nat\n    addr_card word_bits_def fun_upd_def)\n  apply (subst heap_update_list_value, clarsimp simp: addr_card)\n  apply safe\n   apply (subst if_P)\n    apply (fastforce intro: intvlI)\n   apply (clarsimp simp: unat_of_nat word_bits_def)\n  apply (subst (1 2)  heap_update_list_value,\n    simp add: addr_card,\n    simp add: addr_card)\n  apply (case_tac \"x \\<in> {q..+length l}\")\n   apply (subst if_P, simp)\n   apply (subst if_P)\n    apply clarsimp\n    apply (metis (full_types) intvlD intvlI less_SucI)\n   apply (subst nth_append, clarsimp)\n   apply (metis (hide_lams, no_types) add_diff_cancel2 intvlD le_unat_uoi less_or_eq_imp_le not_le)\n  apply clarsimp\n  apply (metis intvlD intvlI less_antisym)\n  done\n\nlemma (in memset) memset:\n  \"\\<forall>s\\<^sub>0. \\<lbrace> \\<lambda>s. s = s\\<^sub>0 \\<and> n < addr_card \\<and> 0 \\<notin> {ptr_val p ..+ n} \\<rbrace>\n      memset' p c n\n      \\<lbrace> \\<lambda>rv s. s = t_hrs_'_update (hrs_mem_update (\n          heap_update_list (ptr_val p) (replicate n (scast c)))) s\\<^sub>0 \\<rbrace>!\"\nproof -\n  {\n     fix s0\n     have \"\\<lbrace> \\<lambda>s. s = s0 \\<and> n < addr_card \\<and> 0 \\<notin> {ptr_val p ..+ n} \\<rbrace>\n                memset' p c n\n          \\<lbrace> \\<lambda>rv s. s = t_hrs_'_update (hrs_mem_update\n              (heap_update_list (ptr_val p) (replicate n (scast c)))) s0 \\<rbrace>!\"\n      apply (rule validNF_assume_pre)\n      apply (unfold memset'_def)\n      apply (subst whileLoop_add_inv [where M=\"\\<lambda>((d', n'), _). n'\"\n                and I=\"\\<lambda>(d', n') s.\n                   n' \\<le> n \\<and>\n                   (n' \\<le> n \\<longrightarrow> d' = ptr_coerce p +\\<^sub>p int (n - n')) \\<and>\n                   (n' \\<le> n \\<longrightarrow> s = t_hrs_'_update\n                  (hrs_mem_update (heap_update_list (ptr_val p) (replicate (n - n') (scast c)))) s0)\"])\n      apply wp\n        apply (clarsimp simp:)\n        apply (intro conjI impI)\n           apply arith\n          apply (clarsimp simp: ptr_add_def)\n         apply (rule globals.fold_congs, simp, simp)\n         apply (clarsimp simp: hrs_mem_update_def)\n         apply (subst heap_update_heap_update_list)\n           apply (clarsimp simp: ptr_add_def)\n          apply (clarsimp)\n          apply arith\n         apply (metis diff_Suc_diff_eq2 diff_diff_left minus_nat.diff_0 replicate_Suc_append)\n        apply (clarsimp simp: ptr_add_def)\n        apply (metis (hide_lams, no_types) add_less_cancel_right add.left_neutral intvl_inter_le le0 le_add_diff_inverse of_nat_diff semiring_1_class.of_nat_0)\n       apply clarsimp\n      apply (clarsimp simp: hrs_mem_update_def)\n      done\n  }\n\n  thus ?thesis\n    by simp\nqed\n\nlemma word_rsplit_sword_0 [simplified, simp]:\n  \"word_rsplit (0 :: addr_bitsize signed word) = replicate (size_of TYPE(addr)) (0 :: word8)\"\n  apply (simp add: word_rsplit_def bin_rsplit_def Let_def)\n  done\n\nlemma word_rsplit_word_0 [simplified, simp]:\n  \"word_rsplit (0 :: addr_bitsize word) = replicate (size_of TYPE(addr)) (0 :: word8)\"\n  apply (simp add: word_rsplit_def bin_rsplit_def Let_def)\n  done\n\nlemma heap_update_zero_node [simplified]:\n  \"heap_update_list p (replicate (size_of TYPE(node_C)) 0) = heap_update (Ptr p) (node_C NULL 0)\"\n  apply (rule ext)\n  apply (clarsimp simp: heap_update_def to_bytes_def)\n  apply (subst packed_type_access_ti, simp)\n  apply (clarsimp simp: access_ti\\<^sub>0_def)\n  apply (clarsimp simp: to_bytes_def to_bytes_p_def node_C_tag_def node_C_typ_tag)\n  apply (subst final_pad_def)\n  apply (clarsimp simp: typ_info_word size_td_lt_ti_typ_pad_combine Let_def padup_def)\n  apply (clarsimp simp: ti_typ_pad_combine_def)\n  apply (clarsimp simp: ti_typ_combine_def empty_typ_info_def typ_info_ptr typ_info_word)\n  done\n\nlemma (in memset) is_valid_node_C_non_NULL [simp]:\n  \"is_valid_node_C (lift_global_heap s) p \\<Longrightarrow> 0 \\<notin> {ptr_val p ..+ size_of TYPE(node_C)}\"\n  by (auto simp: lift_global_heap_def c_guard_def c_null_guard_def dest: simple_lift_c_guard)\n\nlemma (in memset) zero_node:\n  \"\\<forall>s\\<^sub>0. \\<lbrace> \\<lambda>s. is_valid_node_C s p \\<and> s = s\\<^sub>0\\<rbrace> zero_node' p \\<lbrace> \\<lambda>rv s. s = s\\<^sub>0[p := (node_C NULL 0) ] \\<rbrace>! \"\n  apply (clarsimp simp: zero_node'_def)\n  apply (wp add: memset [THEN validNF_make_schematic_post, simplified])\n  apply (fastforce dest: simple_lift_c_guard is_valid_node_C_non_NULL\n                   simp: addr_card lift_global_heap_def heap_update_zero_node\n                         memset.update_node_def typ_simple_heap_simps fun_upd_def)\n  done\n\nend\n", "meta": {"author": "z5146542", "repo": "TOR", "sha": "9a82d491288a6d013e0764f68e602a63e48f92cf", "save_path": "github-repos/isabelle/z5146542-TOR", "path": "github-repos/isabelle/z5146542-TOR/TOR-9a82d491288a6d013e0764f68e602a63e48f92cf/checker-verification/autocorres-1.4/autocorres/tests/examples/Memset.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297745935070806, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.2976840443461467}}
{"text": "header {* \\isaheader{Static backward slice} *}\n\ntheory Slice imports SCDObservable Distance begin\n\ncontext SDG begin\n\nsubsection {* Preliminary definitions on the parameter nodes for defining\n  sliced call and return edges *}\n\nfun csppa :: \"'node \\<Rightarrow> 'node SDG_node set \\<Rightarrow> nat \\<Rightarrow> \n  ((('var \\<rightharpoonup> 'val) \\<Rightarrow> 'val option) list) \\<Rightarrow> ((('var \\<rightharpoonup> 'val) \\<Rightarrow> 'val option) list)\"\n  where \"csppa m S x [] = []\"\n  | \"csppa m S x (f#fs) = \n     (if Formal_in(m,x) \\<notin> S then empty else f)#csppa m S (Suc x) fs\"\n\ndefinition cspp :: \"'node \\<Rightarrow> 'node SDG_node set \\<Rightarrow> \n  ((('var \\<rightharpoonup> 'val) \\<Rightarrow> 'val option) list) \\<Rightarrow> ((('var \\<rightharpoonup> 'val) \\<Rightarrow> 'val option) list)\"\n  where \"cspp m S fs \\<equiv> csppa m S 0 fs\"\n\n\n\nlemma [simp]: \"length (cspp m S fs) = length fs\"\nby(simp add:cspp_def)\n\nlemma csppa_Formal_in_notin_slice: \n  \"\\<lbrakk>x < length fs; Formal_in(m,x + i) \\<notin> S\\<rbrakk>\n  \\<Longrightarrow> (csppa m S i fs)!x = empty\"\nby(induct fs arbitrary:i x,auto simp:nth_Cons')\n\nlemma csppa_Formal_in_in_slice: \n  \"\\<lbrakk>x < length fs; Formal_in(m,x + i) \\<in> S\\<rbrakk>\n  \\<Longrightarrow> (csppa m S i fs)!x = fs!x\"\nby(induct fs arbitrary:i x,auto simp:nth_Cons')\n\n\ndefinition map_merge :: \"('var \\<rightharpoonup> 'val) \\<Rightarrow> ('var \\<rightharpoonup> 'val) \\<Rightarrow> (nat \\<Rightarrow> bool) \\<Rightarrow> \n                         'var list \\<Rightarrow> ('var \\<rightharpoonup> 'val)\"\nwhere \"map_merge f g Q xs \\<equiv> (\\<lambda>V. if (\\<exists>i. i < length xs \\<and> xs!i = V \\<and> Q i) then g V \n                                 else f V)\"\n\n\ndefinition rspp :: \"'node \\<Rightarrow> 'node SDG_node set \\<Rightarrow> 'var list \\<Rightarrow> \n  ('var \\<rightharpoonup> 'val) \\<Rightarrow> ('var \\<rightharpoonup> 'val) \\<Rightarrow> ('var \\<rightharpoonup> 'val)\"\nwhere \"rspp m S xs f g \\<equiv> map_merge f (empty(ParamDefs m [:=] map g xs))\n  (\\<lambda>i. Actual_out(m,i) \\<in> S) (ParamDefs m)\"\n\n\nlemma rspp_Actual_out_in_slice:\n  assumes \"x < length (ParamDefs (targetnode a))\" and \"valid_edge a\"\n  and \"length (ParamDefs (targetnode a)) = length xs\" \n  and \"Actual_out (targetnode a,x) \\<in> S\"\n  shows \"(rspp (targetnode a) S xs f g) ((ParamDefs (targetnode a))!x) = g(xs!x)\"\nproof -\n  from `valid_edge a` have \"distinct(ParamDefs (targetnode a))\"\n    by(rule distinct_ParamDefs)\n  from `x < length (ParamDefs (targetnode a))` \n    `length (ParamDefs (targetnode a)) = length xs`\n    `distinct(ParamDefs (targetnode a))`\n  have \"(empty(ParamDefs (targetnode a) [:=] map g xs))\n    ((ParamDefs (targetnode a))!x) = (map g xs)!x\"\n    by(fastforce intro:fun_upds_nth)\n  with `Actual_out(targetnode a,x) \\<in> S` `x < length (ParamDefs (targetnode a))`\n    `length (ParamDefs (targetnode a)) = length xs` show ?thesis\n    by(fastforce simp:rspp_def map_merge_def)\nqed\n\nlemma rspp_Actual_out_notin_slice:\n  assumes \"x < length (ParamDefs (targetnode a))\" and \"valid_edge a\"\n  and \"length (ParamDefs (targetnode a)) = length xs\" \n  and \"Actual_out((targetnode a),x) \\<notin> S\"\n  shows \"(rspp (targetnode a) S xs f g) ((ParamDefs (targetnode a))!x) = \n  f((ParamDefs (targetnode a))!x)\"\nproof -\n  from `valid_edge a` have \"distinct(ParamDefs (targetnode a))\"\n    by(rule distinct_ParamDefs)\n  from `x < length (ParamDefs (targetnode a))` \n    `length (ParamDefs (targetnode a)) = length xs`\n    `distinct(ParamDefs (targetnode a))`\n  have \"(empty(ParamDefs (targetnode a) [:=] map g xs))\n    ((ParamDefs (targetnode a))!x) = (map g xs)!x\"\n    by(fastforce intro:fun_upds_nth)\n  with `Actual_out((targetnode a),x) \\<notin> S` `distinct(ParamDefs (targetnode a))` \n    `x < length (ParamDefs (targetnode a))`\n  show ?thesis by(fastforce simp:rspp_def map_merge_def nth_eq_iff_index_eq)\nqed\n\n\nsubsection {* Defining the sliced edge kinds *}\n\nprimrec slice_kind_aux :: \"'node \\<Rightarrow> 'node \\<Rightarrow> 'node SDG_node set \\<Rightarrow> \n  ('var,'val,'ret,'pname) edge_kind \\<Rightarrow> ('var,'val,'ret,'pname) edge_kind\"\nwhere \"slice_kind_aux m m' S \\<Up>f = (if m \\<in> \\<lfloor>S\\<rfloor>\\<^bsub>CFG\\<^esub> then \\<Up>f else \\<Up>id)\"\n  | \"slice_kind_aux m m' S (Q)\\<^sub>\\<surd> = (if m \\<in> \\<lfloor>S\\<rfloor>\\<^bsub>CFG\\<^esub> then (Q)\\<^sub>\\<surd> else\n  (if obs_intra m \\<lfloor>S\\<rfloor>\\<^bsub>CFG\\<^esub> = {} then \n    (let mex = (THE mex. method_exit mex \\<and> get_proc m = get_proc mex) in\n    (if (\\<exists>x. distance m' mex x \\<and> distance m mex (x + 1) \\<and>\n        (m' = (SOME mx'. \\<exists>a'. m = sourcenode a' \\<and> \n                              distance (targetnode a') mex x \\<and>\n                              valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                              targetnode a' = mx'))) \n          then (\\<lambda>cf. True)\\<^sub>\\<surd> else (\\<lambda>cf. False)\\<^sub>\\<surd>))\n     else (let mx = THE mx. mx \\<in> obs_intra m \\<lfloor>S\\<rfloor>\\<^bsub>CFG\\<^esub> in \n       (if (\\<exists>x. distance m' mx x \\<and> distance m mx (x + 1) \\<and>\n            (m' = (SOME mx'. \\<exists>a'. m = sourcenode a' \\<and> \n                                  distance (targetnode a') mx x \\<and>\n                                  valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                  targetnode a' = mx'))) \n          then (\\<lambda>cf. True)\\<^sub>\\<surd> else (\\<lambda>cf. False)\\<^sub>\\<surd>))))\"\n  | \"slice_kind_aux m m' S (Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs) = (if m \\<in> \\<lfloor>S\\<rfloor>\\<^bsub>CFG\\<^esub> then (Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>(cspp m' S fs))\n                           else ((\\<lambda>cf. False):r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs))\"\n  | \"slice_kind_aux m m' S (Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f) = (if m \\<in> \\<lfloor>S\\<rfloor>\\<^bsub>CFG\\<^esub> then \n      (let outs = THE outs. \\<exists>ins. (p,ins,outs) \\<in> set procs in\n         (Q\\<hookleftarrow>\\<^bsub>p\\<^esub>(\\<lambda>cf cf'. rspp m' S outs cf' cf)))\n    else ((\\<lambda>cf. True)\\<hookleftarrow>\\<^bsub>p\\<^esub>(\\<lambda>cf cf'. cf')))\"\n\ndefinition slice_kind :: \"'node SDG_node set \\<Rightarrow> 'edge \\<Rightarrow> \n  ('var,'val,'ret,'pname) edge_kind\"\n  where \"slice_kind S a \\<equiv> \n  slice_kind_aux (sourcenode a) (targetnode a) (HRB_slice S) (kind a)\"\n\ndefinition slice_kinds :: \"'node SDG_node set \\<Rightarrow> 'edge list \\<Rightarrow> \n  ('var,'val,'ret,'pname) edge_kind list\"\n  where \"slice_kinds S as \\<equiv> map (slice_kind S) as\"\n\n\n\nlemma slice_intra_kind_in_slice:\n  \"\\<lbrakk>sourcenode a \\<in> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>; intra_kind (kind a)\\<rbrakk> \n  \\<Longrightarrow> slice_kind S a = kind a\"\nby(fastforce simp:intra_kind_def slice_kind_def)\n\n\nlemma slice_kind_Upd:\n  \"\\<lbrakk>sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>; kind a = \\<Up>f\\<rbrakk> \\<Longrightarrow> slice_kind S a = \\<Up>id\"\nby(simp add:slice_kind_def)\n\n\nlemma slice_kind_Pred_empty_obs_nearer_SOME:\n  assumes \"sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\" and \"kind a = (Q)\\<^sub>\\<surd>\"\n  and \"obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub> = {}\" \n  and \"method_exit mex\" and \"get_proc (sourcenode a) = get_proc mex\"\n  and \"distance (targetnode a) mex x\" and \"distance (sourcenode a) mex (x + 1)\"\n  and \"targetnode a = (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> \n                                     distance (targetnode a') mex x \\<and>\n                                     valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                     targetnode a' = n')\"\n  shows \"slice_kind S a = (\\<lambda>s. True)\\<^sub>\\<surd>\"\nproof -\n  from `method_exit mex` `get_proc (sourcenode a) = get_proc mex`\n  have \"mex = (THE mex. method_exit mex \\<and> get_proc (sourcenode a) = get_proc mex)\"\n    by(auto intro!:the_equality[THEN sym] intro:method_exit_unique)\n  with `sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>` `kind a = (Q)\\<^sub>\\<surd>` \n    `obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub> = {}`\n  have \"slice_kind S a = \n    (if (\\<exists>x. distance (targetnode a) mex x \\<and> distance (sourcenode a) mex (x + 1) \\<and>\n    (targetnode a = (SOME mx'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> \n    distance (targetnode a') mex x \\<and> valid_edge a' \\<and> intra_kind(kind a') \\<and>\n    targetnode a' = mx'))) then (\\<lambda>cf. True)\\<^sub>\\<surd> else (\\<lambda>cf. False)\\<^sub>\\<surd>)\"\n    by(simp add:slice_kind_def Let_def)\n  with `distance (targetnode a) mex x` `distance (sourcenode a) mex (x + 1)`\n    `targetnode a = (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> \n                                     distance (targetnode a') mex x \\<and>\n                                     valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                     targetnode a' = n')`\n  show ?thesis by fastforce\nqed\n\n\nlemma slice_kind_Pred_empty_obs_nearer_not_SOME:\n  assumes \"sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\" and \"kind a = (Q)\\<^sub>\\<surd>\"\n  and \"obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub> = {}\" \n  and \"method_exit mex\" and \"get_proc (sourcenode a) = get_proc mex\"\n  and \"distance (targetnode a) mex x\" and \"distance (sourcenode a) mex (x + 1)\"\n  and \"targetnode a \\<noteq> (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> \n                                     distance (targetnode a') mex x \\<and>\n                                     valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                     targetnode a' = n')\"\n  shows \"slice_kind S a = (\\<lambda>s. False)\\<^sub>\\<surd>\"\nproof -\n  from `method_exit mex` `get_proc (sourcenode a) = get_proc mex`\n  have \"mex = (THE mex. method_exit mex \\<and> get_proc (sourcenode a) = get_proc mex)\"\n    by(auto intro!:the_equality[THEN sym] intro:method_exit_unique)\n  with `sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>` `kind a = (Q)\\<^sub>\\<surd>` \n    `obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub> = {}`\n  have \"slice_kind S a = \n    (if (\\<exists>x. distance (targetnode a) mex x \\<and> distance (sourcenode a) mex (x + 1) \\<and>\n    (targetnode a = (SOME mx'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> \n    distance (targetnode a') mex x \\<and> valid_edge a' \\<and> intra_kind(kind a') \\<and>\n    targetnode a' = mx'))) then (\\<lambda>cf. True)\\<^sub>\\<surd> else (\\<lambda>cf. False)\\<^sub>\\<surd>)\"\n    by(simp add:slice_kind_def Let_def)\n  with `distance (targetnode a) mex x` `distance (sourcenode a) mex (x + 1)`\n    `targetnode a \\<noteq> (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> \n                                     distance (targetnode a') mex x \\<and>\n                                     valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                     targetnode a' = n')`\n  show ?thesis by(auto dest:distance_det)\nqed\n\n\nlemma slice_kind_Pred_empty_obs_not_nearer:\n  assumes \"sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\" and \"kind a = (Q)\\<^sub>\\<surd>\"\n  and \"obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub> = {}\" \n  and \"method_exit mex\" and \"get_proc (sourcenode a) = get_proc mex\"\n  and dist:\"distance (sourcenode a) mex (x + 1)\" \"\\<not> distance (targetnode a) mex x\"\n  shows \"slice_kind S a = (\\<lambda>s. False)\\<^sub>\\<surd>\"\nproof -\n  from `method_exit mex` `get_proc (sourcenode a) = get_proc mex`\n  have \"mex = (THE mex. method_exit mex \\<and> get_proc (sourcenode a) = get_proc mex)\"\n    by(auto intro!:the_equality[THEN sym] intro:method_exit_unique)\n  moreover\n  from dist have \"\\<not> (\\<exists>x. distance (targetnode a) mex x \\<and> \n                            distance (sourcenode a) mex (x + 1))\"\n    by(fastforce dest:distance_det)\n  ultimately show ?thesis using assms by(auto simp:slice_kind_def Let_def)\nqed\n\n\nlemma slice_kind_Pred_obs_nearer_SOME:\n  assumes \"sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\" and \"kind a = (Q)\\<^sub>\\<surd>\" \n  and \"m \\<in> obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\"\n  and \"distance (targetnode a) m x\" \"distance (sourcenode a) m (x + 1)\"\n  and \"targetnode a = (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and>\n                                     distance (targetnode a') m x \\<and>\n                                     valid_edge a' \\<and> intra_kind(kind a') \\<and> \n                                     targetnode a' = n')\"\n  shows \"slice_kind S a = (\\<lambda>s. True)\\<^sub>\\<surd>\"\nproof -\n  from `m \\<in> obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>`\n  have \"m = (THE m. m \\<in> obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>)\"\n    by(rule obs_intra_the_element[THEN sym])\n  with assms show ?thesis by(auto simp:slice_kind_def Let_def)\nqed\n\n\nlemma slice_kind_Pred_obs_nearer_not_SOME:\n  assumes \"sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\" and \"kind a = (Q)\\<^sub>\\<surd>\" \n  and \"m \\<in> obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\"\n  and \"distance (targetnode a) m x\" \"distance (sourcenode a) m (x + 1)\"\n  and \"targetnode a \\<noteq> (SOME nx'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> \n                                      distance (targetnode a') m x \\<and>\n                                      valid_edge a' \\<and> intra_kind(kind a') \\<and> \n                                      targetnode a' = nx')\"\n  shows \"slice_kind S a = (\\<lambda>s. False)\\<^sub>\\<surd>\"\nproof -\n  from `m \\<in> obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>`\n  have \"m = (THE m. m \\<in> obs_intra (sourcenode a) (\\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>))\"\n    by(rule obs_intra_the_element[THEN sym])\n  with assms show ?thesis by(auto dest:distance_det simp:slice_kind_def Let_def)\nqed\n\n\nlemma slice_kind_Pred_obs_not_nearer:\n  assumes \"sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\" and \"kind a = (Q)\\<^sub>\\<surd>\" \n  and in_obs:\"m \\<in> obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\"\n  and dist:\"distance (sourcenode a) m (x + 1)\" \n           \"\\<not> distance (targetnode a) m x\"\n  shows \"slice_kind S a = (\\<lambda>s. False)\\<^sub>\\<surd>\"\nproof -\n  from in_obs have the:\"m = (THE m. m \\<in> obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>)\"\n    by(rule obs_intra_the_element[THEN sym])\n  from dist have \"\\<not> (\\<exists>x. distance (targetnode a) m x \\<and> \n                            distance (sourcenode a) m (x + 1))\"\n    by(fastforce dest:distance_det)\n  with `sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>` `kind a = (Q)\\<^sub>\\<surd>` in_obs the show ?thesis\n    by(auto simp:slice_kind_def Let_def)\nqed\n\n\nlemma kind_Predicate_notin_slice_slice_kind_Predicate:\n  assumes \"sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\" and \"valid_edge a\" and \"kind a = (Q)\\<^sub>\\<surd>\"\n  obtains Q' where \"slice_kind S a = (Q')\\<^sub>\\<surd>\" and \"Q' = (\\<lambda>s. False) \\<or> Q' = (\\<lambda>s. True)\"\nproof(atomize_elim)\n  show \"\\<exists>Q'. slice_kind S a = (Q')\\<^sub>\\<surd> \\<and> (Q' = (\\<lambda>s. False) \\<or> Q' = (\\<lambda>s. True))\"\n  proof(cases \"obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub> = {}\")\n    case True\n    from `valid_edge a` have \"valid_node (sourcenode a)\" by simp\n    then obtain as where \"sourcenode a -as\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\" by(fastforce dest:Exit_path)\n    then obtain as' mex where \"sourcenode a -as'\\<rightarrow>\\<^sub>\\<iota>* mex\" and \"method_exit mex\" \n      by -(erule valid_Exit_path_intra_path)\n    from `sourcenode a -as'\\<rightarrow>\\<^sub>\\<iota>* mex` have \"get_proc (sourcenode a) = get_proc mex\"\n      by(rule intra_path_get_procs)\n    show ?thesis\n    proof(cases \"\\<exists>x. distance (targetnode a) mex x \\<and> \n        distance (sourcenode a) mex (x + 1)\")\n      case True\n      then obtain x where \"distance (targetnode a) mex x\" \n        and \"distance (sourcenode a) mex (x + 1)\" by blast\n      show ?thesis\n      proof(cases \"targetnode a = (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and>\n                                                 distance (targetnode a') mex x \\<and>\n                                                 valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                                 targetnode a' = n')\")\n        case True\n        with `sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>` `kind a = (Q)\\<^sub>\\<surd>`\n          `obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub> = {}`\n          `method_exit mex` `get_proc (sourcenode a) = get_proc mex`\n          `distance (targetnode a) mex x` `distance (sourcenode a) mex (x + 1)`\n        have \"slice_kind S a = (\\<lambda>s. True)\\<^sub>\\<surd>\"\n          by(rule slice_kind_Pred_empty_obs_nearer_SOME)\n        thus ?thesis by simp\n      next\n        case False\n        with `sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>` `kind a = (Q)\\<^sub>\\<surd>`\n          `obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub> = {}`\n          `method_exit mex` `get_proc (sourcenode a) = get_proc mex`\n          `distance (targetnode a) mex x` `distance (sourcenode a) mex (x + 1)`\n        have \"slice_kind S a = (\\<lambda>s. False)\\<^sub>\\<surd>\"\n          by(rule slice_kind_Pred_empty_obs_nearer_not_SOME)\n        thus ?thesis by simp\n      qed\n    next\n      case False\n      from `method_exit mex` `get_proc (sourcenode a) = get_proc mex`\n      have \"mex = (THE mex. method_exit mex \\<and> get_proc (sourcenode a) = get_proc mex)\"\n        by(auto intro!:the_equality[THEN sym] intro:method_exit_unique)\n      with `sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>` `kind a = (Q)\\<^sub>\\<surd>`\n        `obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub> = {}` False\n      have \"slice_kind S a = (\\<lambda>s. False)\\<^sub>\\<surd>\"\n        by(auto simp:slice_kind_def Let_def)\n      thus ?thesis by simp\n    qed\n  next\n    case False\n    then obtain m where \"m \\<in> obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\" by blast\n    show ?thesis\n    proof(cases \"\\<exists>x. distance (targetnode a) m x \\<and> \n        distance (sourcenode a) m (x + 1)\")\n      case True\n      then obtain x where \"distance (targetnode a) m x\" \n        and \"distance (sourcenode a) m (x + 1)\" by blast\n      show ?thesis\n      proof(cases \"targetnode a = (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and>\n                                                 distance (targetnode a') m x \\<and>\n                                                 valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                                 targetnode a' = n')\")\n        case True\n        with `sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>` `kind a = (Q)\\<^sub>\\<surd>`\n          `m \\<in> obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>`\n          `distance (targetnode a) m x` `distance (sourcenode a) m (x + 1)`\n        have \"slice_kind S a = (\\<lambda>s. True)\\<^sub>\\<surd>\"\n          by(rule slice_kind_Pred_obs_nearer_SOME)\n        thus ?thesis by simp\n      next\n        case False\n        with `sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>` `kind a = (Q)\\<^sub>\\<surd>`\n          `m \\<in> obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>`\n          `distance (targetnode a) m x` `distance (sourcenode a) m (x + 1)`\n        have \"slice_kind S a = (\\<lambda>s. False)\\<^sub>\\<surd>\"\n          by(rule slice_kind_Pred_obs_nearer_not_SOME)\n        thus ?thesis by simp\n      qed\n    next\n      case False\n      from `m \\<in> obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>`\n      have \"m = (THE m. m \\<in> obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>)\"\n        by(rule obs_intra_the_element[THEN sym])\n      with `sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>` `kind a = (Q)\\<^sub>\\<surd>` False\n        `m \\<in> obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>`\n      have \"slice_kind S a = (\\<lambda>s. False)\\<^sub>\\<surd>\"\n        by(auto simp:slice_kind_def Let_def)\n      thus ?thesis by simp\n    qed\n  qed\nqed\n\n\nlemma slice_kind_Call:\n  \"\\<lbrakk>sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>; kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\\<rbrakk> \n  \\<Longrightarrow> slice_kind S a = (\\<lambda>cf. False):r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\"\nby(simp add:slice_kind_def)\n\n\nlemma slice_kind_Call_in_slice:\n  \"\\<lbrakk>sourcenode a \\<in> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>; kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\\<rbrakk> \n  \\<Longrightarrow> slice_kind S a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>(cspp (targetnode a) (HRB_slice S) fs)\"\nby(simp add:slice_kind_def)\n\n\nlemma slice_kind_Call_in_slice_Formal_in_not:\n  assumes \"sourcenode a \\<in> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\" and \"kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\"\n  and \"\\<forall>x < length fs. Formal_in(targetnode a,x) \\<notin> HRB_slice S\" \n  shows \"slice_kind S a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>replicate (length fs) empty\"\nproof -\n  from `sourcenode a \\<in> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>` `kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs`\n  have \"slice_kind S a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>(cspp (targetnode a) (HRB_slice S) fs)\"\n    by(simp add:slice_kind_def)\n  from `\\<forall>x < length fs. Formal_in(targetnode a,x) \\<notin> HRB_slice S`\n  have \"cspp (targetnode a) (HRB_slice S) fs = replicate (length fs) empty\"\n    by(fastforce intro:nth_equalityI csppa_Formal_in_notin_slice simp:cspp_def)\n  with `slice_kind S a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>(cspp (targetnode a) (HRB_slice S) fs)`\n  show ?thesis by simp\nqed\n\n\nlemma slice_kind_Call_in_slice_Formal_in_also:\n  assumes \"sourcenode a \\<in> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\" and \"kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\"\n  and \"\\<forall>x < length fs. Formal_in(targetnode a,x) \\<in> HRB_slice S\" \n  shows \"slice_kind S a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\"\nproof -\n  from `sourcenode a \\<in> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>` `kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs`\n  have \"slice_kind S a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>(cspp (targetnode a) (HRB_slice S) fs)\"\n    by(simp add:slice_kind_def)\n  from `\\<forall>x < length fs. Formal_in(targetnode a,x) \\<in> HRB_slice S`\n  have \"cspp (targetnode a) (HRB_slice S) fs = fs\"\n    by(fastforce intro:nth_equalityI csppa_Formal_in_in_slice simp:cspp_def)\n  with `slice_kind S a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>(cspp (targetnode a) (HRB_slice S) fs)`\n  show ?thesis by simp\nqed\n\n\nlemma slice_kind_Call_intra_notin_slice:\n  assumes \"sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\" and \"valid_edge a\" \n  and \"intra_kind (kind a)\" and \"valid_edge a'\" and \"kind a' = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\"\n  and \"sourcenode a' = sourcenode a\"\n  shows \"slice_kind S a = (\\<lambda>s. True)\\<^sub>\\<surd>\"\nproof -\n  from `valid_edge a'` `kind a' = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs` obtain a'' \n    where \"a'' \\<in> get_return_edges a'\"\n    by(fastforce dest:get_return_edge_call)\n  with `valid_edge a'` obtain ax where \"valid_edge ax\" \n    and \"sourcenode ax = sourcenode a'\" and \" targetnode ax = targetnode a''\"\n    and \"kind ax = (\\<lambda>cf. False)\\<^sub>\\<surd>\"\n    by(fastforce dest:call_return_node_edge)\n  from `valid_edge a'` `kind a' = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs`\n  have \"\\<exists>!a''. valid_edge a'' \\<and> sourcenode a'' = sourcenode a' \\<and> \n    intra_kind(kind a'')\"\n    by(rule call_only_one_intra_edge)\n  with `valid_edge a` `sourcenode a' = sourcenode a` `intra_kind (kind a)`\n  have all:\"\\<forall>a''. valid_edge a'' \\<and> sourcenode a'' = sourcenode a' \\<and> \n    intra_kind(kind a'') \\<longrightarrow> a'' = a\" by fastforce\n  with `valid_edge ax` `sourcenode ax = sourcenode a'` `kind ax = (\\<lambda>cf. False)\\<^sub>\\<surd>`\n  have [simp]:\"ax = a\" by(fastforce simp:intra_kind_def)\n  show ?thesis\n  proof(cases \"obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub> = {}\")\n    case True\n    from `valid_edge a` have \"valid_node (sourcenode a)\" by simp\n    then obtain asx where \"sourcenode a -asx\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\" by(fastforce dest:Exit_path)\n    then obtain as pex where \"sourcenode a-as\\<rightarrow>\\<^sub>\\<iota>* pex\" and \"method_exit pex\"\n      by -(erule valid_Exit_path_intra_path)\n    from `sourcenode a-as\\<rightarrow>\\<^sub>\\<iota>* pex` have \"get_proc (sourcenode a) = get_proc pex\"\n      by(rule intra_path_get_procs)\n    from `sourcenode a-as\\<rightarrow>\\<^sub>\\<iota>* pex` obtain x where \"distance (sourcenode a) pex x\"\n      and \"x \\<le> length as\" by(erule every_path_distance)\n    from `method_exit pex` have \"sourcenode a \\<noteq> pex\"\n    proof(rule method_exit_cases)\n      assume \"pex = (_Exit_)\"\n      show ?thesis\n      proof\n        assume \"sourcenode a = pex\"\n        with `pex = (_Exit_)` have \"sourcenode a = (_Exit_)\" by simp\n        with `valid_edge a` show False by(rule Exit_source)\n      qed\n    next\n      fix ax Qx px fx \n      assume \"pex = sourcenode ax\" and \"valid_edge ax\" and \"kind ax = Qx\\<hookleftarrow>\\<^bsub>px\\<^esub>fx\"\n      hence \"\\<forall>a'. valid_edge a' \\<and> sourcenode a' = sourcenode ax \\<longrightarrow> \n        (\\<exists>Qx' fx'. kind a' = Qx'\\<hookleftarrow>\\<^bsub>px\\<^esub>fx')\" by -(rule return_edges_only)\n      with `valid_edge a` `intra_kind (kind a)` `pex = sourcenode ax`\n      show ?thesis by(fastforce simp:intra_kind_def)\n    qed\n    have \"x \\<noteq> 0\"\n    proof\n      assume \"x = 0\"\n      with `distance (sourcenode a) pex x` have \"sourcenode a = pex\"\n        by(fastforce elim:distance.cases simp:intra_path_def)\n      with `sourcenode a \\<noteq> pex` show False by simp\n    qed\n    with `distance (sourcenode a) pex x` obtain ax' where \"valid_edge ax'\"\n      and \"sourcenode a = sourcenode ax'\" and \"intra_kind(kind ax')\"\n      and \"distance (targetnode ax') pex (x - 1)\"\n      and Some:\"targetnode ax' = (SOME nx. \\<exists>a'. sourcenode ax' = sourcenode a' \\<and> \n                                          distance (targetnode a') pex (x - 1) \\<and>\n                                          valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                          targetnode a' = nx)\"\n      by(erule distance_successor_distance)\n    from `valid_edge ax'` `sourcenode a = sourcenode ax'` `intra_kind(kind ax')`\n      `sourcenode a' = sourcenode a` all\n    have [simp]:\"ax' = a\" by fastforce\n    from `sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>` `kind ax = (\\<lambda>cf. False)\\<^sub>\\<surd>`\n      True `method_exit pex` `get_proc (sourcenode a) = get_proc pex` `x \\<noteq> 0`\n      `distance (targetnode ax') pex (x - 1)` `distance (sourcenode a) pex x` Some\n    show ?thesis by(fastforce elim:slice_kind_Pred_empty_obs_nearer_SOME)\n  next\n    case False\n    then obtain m where \"m \\<in> obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\" by fastforce\n    then obtain as where \"sourcenode a-as\\<rightarrow>\\<^sub>\\<iota>* m\" and \"m \\<in> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\"\n      by -(erule obs_intraE)\n    from `sourcenode a-as\\<rightarrow>\\<^sub>\\<iota>* m` obtain x where \"distance (sourcenode a) m x\"\n      and \"x \\<le> length as\" by(erule every_path_distance)\n    from `sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>` `m \\<in> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>`\n    have \"sourcenode a \\<noteq> m\" by fastforce\n    have \"x \\<noteq> 0\"\n    proof\n      assume \"x = 0\"\n      with `distance (sourcenode a) m x` have \"sourcenode a = m\"\n        by(fastforce elim:distance.cases simp:intra_path_def)\n      with `sourcenode a \\<noteq> m` show False by simp\n    qed\n    with `distance (sourcenode a) m x` obtain ax' where \"valid_edge ax'\"\n      and \"sourcenode a = sourcenode ax'\" and \"intra_kind(kind ax')\"\n      and \"distance (targetnode ax') m (x - 1)\"\n      and Some:\"targetnode ax' = (SOME nx. \\<exists>a'. sourcenode ax' = sourcenode a' \\<and> \n                                          distance (targetnode a') m (x - 1) \\<and>\n                                          valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                          targetnode a' = nx)\"\n      by(erule distance_successor_distance)\n    from `valid_edge ax'` `sourcenode a = sourcenode ax'` `intra_kind(kind ax')`\n      `sourcenode a' = sourcenode a` all\n    have [simp]:\"ax' = a\" by fastforce\n    from `sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>` `kind ax = (\\<lambda>cf. False)\\<^sub>\\<surd>`\n      `m \\<in> obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>` `x \\<noteq> 0`\n      `distance (targetnode ax') m (x - 1)` `distance (sourcenode a) m x` Some\n    show ?thesis by(fastforce elim:slice_kind_Pred_obs_nearer_SOME)\n  qed\nqed\n\n\nlemma slice_kind_Return:\n  \"\\<lbrakk>sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>; kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\\<rbrakk>\n  \\<Longrightarrow> slice_kind S a = (\\<lambda>cf. True)\\<hookleftarrow>\\<^bsub>p\\<^esub>(\\<lambda>cf cf'. cf')\"\nby(simp add:slice_kind_def)\n\n\nlemma slice_kind_Return_in_slice:\n  \"\\<lbrakk>sourcenode a \\<in> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>; valid_edge a; kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f; \n   (p,ins,outs) \\<in> set procs\\<rbrakk>\n  \\<Longrightarrow> slice_kind S a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>(\\<lambda>cf cf'. rspp (targetnode a) (HRB_slice S) outs cf' cf)\"\nby(simp add:slice_kind_def,unfold formal_out_THE,simp)\n\n\nlemma length_transfer_kind_slice_kind:\n  assumes \"valid_edge a\" and \"length s\\<^sub>1 = length s\\<^sub>2\"\n  and \"transfer (kind a) s\\<^sub>1 = s\\<^sub>1'\" and \"transfer (slice_kind S a) s\\<^sub>2 = s\\<^sub>2'\"\n  shows \"length s\\<^sub>1' = length s\\<^sub>2'\"\nproof(cases \"kind a\" rule:edge_kind_cases)\n  case Intra\n  show ?thesis\n  proof(cases \"sourcenode a \\<in> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\")\n    case True\n    with Intra assms show ?thesis\n      by(cases s\\<^sub>1)(cases s\\<^sub>2,auto dest:slice_intra_kind_in_slice simp:intra_kind_def)+\n  next\n    case False\n    with Intra assms show ?thesis\n      by(cases s\\<^sub>1)(cases s\\<^sub>2,auto dest:slice_kind_Upd \n        elim:kind_Predicate_notin_slice_slice_kind_Predicate simp:intra_kind_def)+\n  qed\nnext\n  case (Call Q r p fs)\n  show ?thesis\n  proof(cases \"sourcenode a \\<in> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\")\n    case True\n    with Call assms show ?thesis\n      by(cases s\\<^sub>1)(cases s\\<^sub>2,auto dest:slice_kind_Call_in_slice)+\n  next\n    case False\n    with Call assms show ?thesis\n      by(cases s\\<^sub>1)(cases s\\<^sub>2,auto dest:slice_kind_Call)+\n  qed\nnext\n  case (Return Q p f)\n  show ?thesis\n  proof(cases \"sourcenode a \\<in> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\")\n    case True\n    from Return `valid_edge a` obtain a' Q' r fs \n      where \"valid_edge a'\" and \"kind a' = Q':r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\"\n      by -(drule return_needs_call,auto)\n    then obtain ins outs where \"(p,ins,outs) \\<in> set procs\"\n      by(fastforce dest!:callee_in_procs)\n    with True `valid_edge a` Return assms show ?thesis\n      by(cases s\\<^sub>1)(cases s\\<^sub>2,auto dest:slice_kind_Return_in_slice split:list.split)+\n  next    \n    case False\n    with Return assms show ?thesis\n      by(cases s\\<^sub>1)(cases s\\<^sub>2,auto dest:slice_kind_Return split:list.split)+\n  qed\nqed\n\n\nsubsection {* The sliced graph of a deterministic CFG is still deterministic *} \n\nlemma only_one_SOME_edge:\n  assumes \"valid_edge a\" and \"intra_kind(kind a)\" and \"distance (targetnode a) mex x\"\n  shows \"\\<exists>!a'. sourcenode a = sourcenode a' \\<and> distance (targetnode a') mex x \\<and>\n               valid_edge a' \\<and> intra_kind(kind a') \\<and>\n               targetnode a' = (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> \n                                              distance (targetnode a') mex x \\<and>\n                                              valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                              targetnode a' = n')\"\nproof(rule ex_ex1I)\n  show \"\\<exists>a'. sourcenode a = sourcenode a' \\<and> distance (targetnode a') mex x \\<and>\n             valid_edge a' \\<and> intra_kind(kind a') \\<and>\n             targetnode a' = (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> \n                                            distance (targetnode a') mex x \\<and>\n                                            valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                            targetnode a' = n')\"\n  proof -\n    have \"(\\<exists>a'. sourcenode a = sourcenode a' \\<and> distance (targetnode a') mex x \\<and>\n                valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                targetnode a' = (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> \n                                               distance (targetnode a') mex x \\<and>\n                                               valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                               targetnode a' = n')) =\n      (\\<exists>n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> distance (targetnode a') mex x \\<and>\n                 valid_edge a' \\<and> intra_kind(kind a') \\<and> targetnode a' = n')\"\n      apply(unfold some_eq_ex[of \"\\<lambda>n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> \n                                            distance (targetnode a') mex x \\<and>\n                                            valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                            targetnode a' = n'\"])\n      by simp\n    also have \"\\<dots>\" \n      using `valid_edge a` `intra_kind(kind a)` `distance (targetnode a) mex x` \n      by blast\n    finally show ?thesis .\n  qed\nnext\n  fix a' ax\n  assume \"sourcenode a = sourcenode a' \\<and> distance (targetnode a') mex x \\<and>\n    valid_edge a' \\<and> intra_kind(kind a') \\<and>\n    targetnode a' = (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> \n                                   distance (targetnode a') mex x \\<and>\n                                   valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                   targetnode a' = n')\"\n    and \"sourcenode a = sourcenode ax \\<and> distance (targetnode ax) mex x \\<and>\n    valid_edge ax \\<and> intra_kind(kind ax) \\<and>\n    targetnode ax = (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> \n                                   distance (targetnode a') mex x \\<and>\n                                   valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                   targetnode a' = n')\"\n  thus \"a' = ax\" by(fastforce intro!:edge_det)\nqed\n\n\nlemma slice_kind_only_one_True_edge:\n  assumes \"sourcenode a = sourcenode a'\" and \"targetnode a \\<noteq> targetnode a'\" \n  and \"valid_edge a\" and \"valid_edge a'\" and \"intra_kind (kind a)\" \n  and \"intra_kind (kind a')\" and \"slice_kind S a = (\\<lambda>s. True)\\<^sub>\\<surd>\"\n  shows \"slice_kind S a' = (\\<lambda>s. False)\\<^sub>\\<surd>\"\nproof -\n  from assms obtain Q Q' where \"kind a = (Q)\\<^sub>\\<surd>\"\n    and \"kind a' = (Q')\\<^sub>\\<surd>\" and det:\"\\<forall>s. (Q s \\<longrightarrow> \\<not> Q' s) \\<and> (Q' s \\<longrightarrow> \\<not> Q s)\"\n    by(auto dest:deterministic)\n  show ?thesis\n  proof(cases \"sourcenode a \\<in> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\")\n    case True\n    with `slice_kind S a = (\\<lambda>s. True)\\<^sub>\\<surd>` `kind a = (Q)\\<^sub>\\<surd>` have \"Q = (\\<lambda>s. True)\"\n      by(simp add:slice_kind_def Let_def)\n    with det have \"Q' = (\\<lambda>s. False)\" by(simp add:fun_eq_iff)\n    with True `kind a' = (Q')\\<^sub>\\<surd>` `sourcenode a = sourcenode a'` show ?thesis\n      by(simp add:slice_kind_def Let_def)\n  next\n    case False\n    hence \"sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\" by simp\n    thus ?thesis\n    proof(cases \"obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub> = {}\")\n      case True\n      with `sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>` `slice_kind S a = (\\<lambda>s. True)\\<^sub>\\<surd>`\n        `kind a = (Q)\\<^sub>\\<surd>`\n      obtain mex x where mex:\"mex = (THE mex. method_exit mex \\<and> \n        get_proc (sourcenode a) = get_proc mex)\"\n        and dist:\"distance (targetnode a) mex x\" \"distance (sourcenode a) mex (x + 1)\"\n        and target:\"targetnode a = (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> \n                                                 distance (targetnode a') mex x \\<and>\n                                                 valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                                 targetnode a' = n')\"\n        by(auto simp:slice_kind_def Let_def fun_eq_iff split:split_if_asm)\n      from `valid_edge a` `intra_kind (kind a)` `distance (targetnode a) mex x`\n      have ex1:\"\\<exists>!a'. sourcenode a = sourcenode a' \\<and> distance (targetnode a') mex x \\<and> \n        valid_edge a' \\<and> intra_kind(kind a') \\<and>\n        targetnode a' = (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> \n                                       distance (targetnode a') mex x \\<and>\n                                       valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                       targetnode a' = n')\"\n        by(rule only_one_SOME_edge)\n      have \"targetnode a' \\<noteq> (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> \n                                           distance (targetnode a') mex x \\<and>\n                                           valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                           targetnode a' = n')\"\n      proof(rule ccontr)\n        assume \"\\<not> targetnode a' \\<noteq> (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> \n                                                 distance (targetnode a') mex x \\<and>\n                                                 valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                                 targetnode a' = n')\"\n        hence \"targetnode a' = (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> \n                                              distance (targetnode a') mex x \\<and>\n                                              valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                              targetnode a' = n')\"\n          by simp\n        with ex1 target `sourcenode a = sourcenode a'` `valid_edge a` `valid_edge a'`\n          `intra_kind(kind a)` `intra_kind(kind a')` `distance (targetnode a) mex x`\n        have \"a = a'\" by fastforce\n        with `targetnode a \\<noteq> targetnode a'` show False by simp\n      qed\n      with `sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>` True `kind a' = (Q')\\<^sub>\\<surd>`\n        `sourcenode a = sourcenode a'` mex dist\n      show ?thesis by(auto dest:distance_det \n        simp:slice_kind_def Let_def fun_eq_iff split:split_if_asm)\n    next\n      case False\n      hence \"obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub> \\<noteq> {}\" .\n      then obtain m where \"m \\<in> obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\" by auto\n      hence \"m = (THE m. m \\<in> obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>)\"\n        by(auto dest:obs_intra_the_element)\n      with `sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>` \n        `obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub> \\<noteq> {}` \n        `slice_kind S a = (\\<lambda>s. True)\\<^sub>\\<surd>` `kind a = (Q)\\<^sub>\\<surd>`\n      obtain x x' where \"distance (targetnode a) m x\" \n        \"distance (sourcenode a) m (x + 1)\"\n        and target:\"targetnode a = (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and>\n                                                 distance (targetnode a') m x \\<and>\n                                                 valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                                 targetnode a' = n')\"\n        by(auto simp:slice_kind_def Let_def fun_eq_iff split:split_if_asm)\n      show ?thesis\n      proof(cases \"distance (targetnode a') m x\")\n        case False\n        with `sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>` `kind a' = (Q')\\<^sub>\\<surd>`\n          `m \\<in> obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>`\n          `distance (targetnode a) m x` `distance (sourcenode a) m (x + 1)`\n          `sourcenode a = sourcenode a'` show ?thesis\n          by(fastforce intro:slice_kind_Pred_obs_not_nearer)\n      next\n        case True\n        from `valid_edge a` `intra_kind(kind a)` `distance (targetnode a) m x`\n          `distance (sourcenode a) m (x + 1)`\n        have ex1:\"\\<exists>!a'. sourcenode a = sourcenode a' \\<and> \n               distance (targetnode a') m x \\<and> valid_edge a' \\<and> intra_kind(kind a') \\<and> \n               targetnode a' = (SOME nx. \\<exists>a'. sourcenode a = sourcenode a' \\<and>\n                                              distance (targetnode a') m x \\<and>\n                                              valid_edge a' \\<and> intra_kind(kind a') \\<and> \n                                              targetnode a' = nx)\"\n          by -(rule only_one_SOME_dist_edge)\n        have \"targetnode a' \\<noteq> (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> \n                                               distance (targetnode a') m x \\<and>\n                                               valid_edge a' \\<and> intra_kind(kind a') \\<and> \n                                               targetnode a' = n')\"\n        proof(rule ccontr)\n          assume \"\\<not> targetnode a' \\<noteq> (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and> \n                                                 distance (targetnode a') m x \\<and>\n                                                 valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                                 targetnode a' = n')\"\n          hence \"targetnode a' = (SOME n'. \\<exists>a'. sourcenode a = sourcenode a' \\<and>\n                                                distance (targetnode a') m x \\<and>\n                                                valid_edge a' \\<and> intra_kind(kind a') \\<and>\n                                                targetnode a' = n')\"\n            by simp\n          with ex1 target `sourcenode a = sourcenode a'` \n            `valid_edge a` `valid_edge a'` `intra_kind(kind a)` `intra_kind(kind a')`\n            `distance (targetnode a) m x` `distance (sourcenode a) m (x + 1)`\n          have \"a = a'\" by auto\n          with `targetnode a \\<noteq> targetnode a'` show False by simp\n        qed\n        with `sourcenode a \\<notin> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>` \n          `kind a' = (Q')\\<^sub>\\<surd>` `m \\<in> obs_intra (sourcenode a) \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>`\n          `distance (targetnode a) m x` `distance (sourcenode a) m (x + 1)`\n          True `sourcenode a = sourcenode a'` show ?thesis\n          by(fastforce intro:slice_kind_Pred_obs_nearer_not_SOME)\n      qed\n    qed\n  qed\nqed\n\n\nlemma slice_deterministic:\n  assumes \"valid_edge a\" and \"valid_edge a'\"\n  and \"intra_kind (kind a)\" and \"intra_kind (kind a')\"\n  and \"sourcenode a = sourcenode a'\" and \"targetnode a \\<noteq> targetnode a'\"\n  obtains Q Q' where \"slice_kind S a = (Q)\\<^sub>\\<surd>\" and \"slice_kind S a' = (Q')\\<^sub>\\<surd>\"\n  and \"\\<forall>s. (Q s \\<longrightarrow> \\<not> Q' s) \\<and> (Q' s \\<longrightarrow> \\<not> Q s)\"\nproof(atomize_elim)\n  from assms obtain Q Q' \n    where \"kind a = (Q)\\<^sub>\\<surd>\" and \"kind a' = (Q')\\<^sub>\\<surd>\" \n    and det:\"\\<forall>s. (Q s \\<longrightarrow> \\<not> Q' s) \\<and> (Q' s \\<longrightarrow> \\<not> Q s)\"\n    by(auto dest:deterministic)\n  show \"\\<exists>Q Q'. slice_kind S a = (Q)\\<^sub>\\<surd> \\<and> slice_kind S a' = (Q')\\<^sub>\\<surd> \\<and> \n                (\\<forall>s. (Q s \\<longrightarrow> \\<not> Q' s) \\<and> (Q' s \\<longrightarrow> \\<not> Q s))\"\n  proof(cases \"sourcenode a \\<in> \\<lfloor>HRB_slice S\\<rfloor>\\<^bsub>CFG\\<^esub>\")\n    case True\n    with `kind a = (Q)\\<^sub>\\<surd>` have \"slice_kind S a = (Q)\\<^sub>\\<surd>\"\n      by(simp add:slice_kind_def Let_def)\n    from True `kind a' = (Q')\\<^sub>\\<surd>` `sourcenode a = sourcenode a'`\n    have \"slice_kind S a' = (Q')\\<^sub>\\<surd>\"\n      by(simp add:slice_kind_def Let_def)\n    with `slice_kind S a = (Q)\\<^sub>\\<surd>` det show ?thesis by blast\n  next\n    case False\n    with `kind a = (Q)\\<^sub>\\<surd>` \n    have \"slice_kind S a = (\\<lambda>s. True)\\<^sub>\\<surd> \\<or> slice_kind S a = (\\<lambda>s. False)\\<^sub>\\<surd>\"\n      by(simp add:slice_kind_def Let_def)\n    thus ?thesis\n    proof\n      assume true:\"slice_kind S a = (\\<lambda>s. True)\\<^sub>\\<surd>\"\n      with `sourcenode a = sourcenode a'` `targetnode a \\<noteq> targetnode a'`\n        `valid_edge a` `valid_edge a'` `intra_kind (kind a)` `intra_kind (kind a')`\n      have \"slice_kind S a' = (\\<lambda>s. False)\\<^sub>\\<surd>\"\n        by(rule slice_kind_only_one_True_edge)\n      with true show ?thesis by simp\n    next\n      assume false:\"slice_kind S a = (\\<lambda>s. False)\\<^sub>\\<surd>\"\n      from False `kind a' = (Q')\\<^sub>\\<surd>` `sourcenode a = sourcenode a'`\n      have \"slice_kind S a' = (\\<lambda>s. True)\\<^sub>\\<surd> \\<or> slice_kind S a' = (\\<lambda>s. False)\\<^sub>\\<surd>\"\n        by(simp add:slice_kind_def Let_def)\n      with false show ?thesis by auto\n    qed\n  qed\nqed\n\nend\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/HRB-Slicing/StaticInter/Slice.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6619228758499942, "lm_q2_score": 0.4493926344647597, "lm_q1q2_score": 0.29746326499071896}}
{"text": "section \\<open>Postdomination\\<close>\n\ntheory Postdomination imports CFGExit begin\n\nsubsection \\<open>Standard Postdomination\\<close>\n\nlocale Postdomination = CFGExit sourcenode targetnode kind valid_edge Entry Exit \n  for sourcenode :: \"'edge \\<Rightarrow> 'node\" and targetnode :: \"'edge \\<Rightarrow> 'node\"\n  and kind :: \"'edge \\<Rightarrow> 'state edge_kind\" and valid_edge :: \"'edge \\<Rightarrow> bool\"\n  and Entry :: \"'node\" (\"'('_Entry'_')\") and Exit :: \"'node\" (\"'('_Exit'_')\") +\n  assumes Entry_path:\"valid_node n \\<Longrightarrow> \\<exists>as. (_Entry_) -as\\<rightarrow>* n\"\n  and Exit_path:\"valid_node n \\<Longrightarrow> \\<exists>as. n -as\\<rightarrow>* (_Exit_)\"\n\nbegin\n\ndefinition postdominate :: \"'node \\<Rightarrow> 'node \\<Rightarrow> bool\" (\"_ postdominates _\" [51,0])\nwhere postdominate_def:\"n' postdominates n \\<equiv> \n    (valid_node n \\<and> valid_node n' \\<and>\n    ((\\<forall>as. n -as\\<rightarrow>* (_Exit_) \\<longrightarrow> n' \\<in> set (sourcenodes as))))\"\n\n\nlemma postdominate_implies_path: \n  assumes \"n' postdominates n\" obtains as where \"n -as\\<rightarrow>* n'\"\nproof(atomize_elim)\n  from \\<open>n' postdominates n\\<close> have \"valid_node n\"\n    and all:\"\\<forall>as. n -as\\<rightarrow>* (_Exit_) \\<longrightarrow> n' \\<in> set(sourcenodes as)\"\n    by(auto simp:postdominate_def)\n  from \\<open>valid_node n\\<close> obtain as where \"n -as\\<rightarrow>* (_Exit_)\" by(auto dest:Exit_path)\n  with all have \"n' \\<in> set(sourcenodes as)\" by simp\n  then obtain ns ns' where \"sourcenodes as = ns@n'#ns'\" by(auto dest:split_list)\n  then obtain as' a as'' where \"sourcenodes as' = ns\" \n    and \"sourcenode a = n'\" and \"as = as'@a#as''\"\n    by(fastforce elim:map_append_append_maps simp:sourcenodes_def)\n  from \\<open>n -as\\<rightarrow>* (_Exit_)\\<close> \\<open>as = as'@a#as''\\<close> have \"n -as'\\<rightarrow>* sourcenode a\"\n    by(fastforce dest:path_split)\n  with \\<open>sourcenode a = n'\\<close> show \"\\<exists>as. n -as\\<rightarrow>* n'\" by blast\nqed\n\n\n\nlemma postdominate_refl:\n  assumes valid:\"valid_node n\" and notExit:\"n \\<noteq> (_Exit_)\"\n  shows \"n postdominates n\"\nusing valid\nproof(induct rule:valid_node_cases)\n  case Entry\n  { fix as assume path:\"(_Entry_) -as\\<rightarrow>* (_Exit_)\"\n    hence notempty:\"as \\<noteq> []\" \n      apply - apply(erule path.cases)\n      by (drule sym,simp,drule Exit_noteq_Entry,auto)\n    with path have \"hd (sourcenodes as) = (_Entry_)\" \n      by(fastforce intro:path_sourcenode)\n    with notempty have \"(_Entry_) \\<in> set (sourcenodes as)\"\n      by(fastforce intro:hd_in_set simp:sourcenodes_def) }\n  with Entry show ?thesis by(simp add:postdominate_def)\nnext\n  case Exit\n  with notExit have False by simp\n  thus ?thesis by simp\nnext\n  case inner\n  show ?thesis\n  proof(cases \"\\<exists>as. n -as\\<rightarrow>* (_Exit_)\")\n    case True\n    { fix as' assume path':\"n -as'\\<rightarrow>* (_Exit_)\"\n      with inner have notempty:\"as' \\<noteq> []\"\n        by(cases as',auto elim!:path.cases simp:inner_node_def)\n      with path' inner have hd:\"hd (sourcenodes as') = n\"\n        by -(rule path_sourcenode)\n      from notempty have \"sourcenodes as' \\<noteq> []\" by(simp add:sourcenodes_def)\n      with hd[THEN sym] have \"n \\<in> set (sourcenodes as')\" by simp }\n    hence \"\\<forall>as. n -as\\<rightarrow>* (_Exit_) \\<longrightarrow> n \\<in> set (sourcenodes as)\" by simp\n    with True inner show ?thesis by(simp add:postdominate_def inner_is_valid)\n  next\n    case False\n    with inner show ?thesis by(simp add:postdominate_def inner_is_valid)\n  qed\nqed\n\n\nlemma postdominate_trans:\n  assumes pd1:\"n'' postdominates n\" and pd2:\"n' postdominates n''\"\n  shows \"n' postdominates n\"\nproof -\n  from pd1 pd2 have valid:\"valid_node n\" and valid':\"valid_node n'\"\n    by(simp_all add:postdominate_def)\n  { fix as assume path:\"n -as\\<rightarrow>* (_Exit_)\"\n    with pd1 have \"n'' \\<in> set (sourcenodes as)\" by(simp add:postdominate_def)\n    then obtain ns' ns'' where \"sourcenodes as = ns'@n''#ns''\"\n      by(auto dest:split_list)\n    then obtain as' as'' a\n      where as'':\"sourcenodes as'' = ns''\" and as:\"as=as'@a#as''\"\n      and source:\"sourcenode a = n''\"\n      by(fastforce elim:map_append_append_maps simp:sourcenodes_def)\n    from as path have \"n -as'@a#as''\\<rightarrow>* (_Exit_)\" by simp\n    with source have path':\"n'' -a#as''\\<rightarrow>* (_Exit_)\"\n      by(fastforce dest:path_split_second)\n    with pd2 have \"n' \\<in> set(sourcenodes (a#as''))\"\n      by(auto simp:postdominate_def)\n    with as have \"n' \\<in> set(sourcenodes as)\" by(auto simp:sourcenodes_def) }\n  with valid valid' show ?thesis by(simp add:postdominate_def)\nqed\n\n\nlemma postdominate_antisym:\n  assumes pd1:\"n' postdominates n\" and pd2:\"n postdominates n'\"\n  shows \"n = n'\"\nproof -\n  from pd1 have valid:\"valid_node n\" and valid':\"valid_node n'\" \n    by(auto simp:postdominate_def)\n  from valid obtain as where path1:\"n -as\\<rightarrow>* (_Exit_)\" by(fastforce dest:Exit_path)\n  from valid' obtain as' where path2:\"n' -as'\\<rightarrow>* (_Exit_)\" by(fastforce dest:Exit_path)\n  from pd1 path1 have \"\\<exists>nx \\<in> set(sourcenodes as). nx = n'\"\n    by(simp add:postdominate_def)\n  then obtain ns ns' where sources:\"sourcenodes as = ns@n'#ns'\"\n    and all:\"\\<forall>nx \\<in> set ns'. nx \\<noteq> n'\"\n    by(fastforce elim!: rightmost_element_property)\n  from sources obtain asx a asx' where ns':\"ns' = sourcenodes asx'\"\n    and as:\"as = asx@a#asx'\" and source:\"sourcenode a = n'\"\n    by(fastforce elim:map_append_append_maps simp:sourcenodes_def)\n  from path1 as have \"n -asx@a#asx'\\<rightarrow>* (_Exit_)\" by simp\n  with source have \"n' -a#asx'\\<rightarrow>* (_Exit_)\" by(fastforce dest:path_split_second)\n  with pd2 have \"n \\<in> set(sourcenodes (a#asx'))\" by(simp add:postdominate_def)\n  with source have \"n = n' \\<or> n \\<in> set(sourcenodes asx')\" by(simp add:sourcenodes_def)\n  thus ?thesis\n  proof\n    assume \"n = n'\" thus ?thesis .\n  next\n    assume \"n \\<in> set(sourcenodes asx')\"\n    then obtain nsx' nsx'' where \"sourcenodes asx' = nsx'@n#nsx''\"\n      by(auto dest:split_list)\n    then obtain asi asi' a' where asx':\"asx' = asi@a'#asi'\"\n      and source':\"sourcenode a' = n\"\n      by(fastforce elim:map_append_append_maps simp:sourcenodes_def)\n    with path1 as have \"n -(asx@a#asi)@a'#asi'\\<rightarrow>* (_Exit_)\" by simp\n    with source' have \"n -a'#asi'\\<rightarrow>* (_Exit_)\" by(fastforce dest:path_split_second)\n    with pd1 have \"n' \\<in> set(sourcenodes (a'#asi'))\" by(auto simp:postdominate_def)\n    with source' have \"n' = n \\<or> n' \\<in> set(sourcenodes asi')\"\n      by(simp add:sourcenodes_def)\n    thus ?thesis\n    proof\n      assume \"n' = n\" thus ?thesis by(rule sym)\n    next\n      assume \"n' \\<in> set(sourcenodes asi')\"\n      with asx' ns' have \"n' \\<in> set ns'\" by(simp add:sourcenodes_def)\n      with all have False by blast\n      thus ?thesis by simp\n    qed\n  qed\nqed\n\n\nlemma postdominate_path_branch:\n  assumes \"n -as\\<rightarrow>* n''\" and \"n' postdominates n''\" and \"\\<not> n' postdominates n\"  \n  obtains a as' as'' where \"as = as'@a#as''\" and \"valid_edge a\"\n  and \"\\<not> n' postdominates (sourcenode a)\" and \"n' postdominates (targetnode a)\"\nproof(atomize_elim)\n  from assms\n  show \"\\<exists>as' a as''. as = as'@a#as'' \\<and> valid_edge a \\<and> \n    \\<not> n' postdominates (sourcenode a) \\<and> n' postdominates (targetnode a)\"\n  proof(induct rule:path.induct)\n    case (Cons_path n'' as nx a n)\n    note IH = \\<open>\\<lbrakk>n' postdominates nx; \\<not> n' postdominates n''\\<rbrakk>\n      \\<Longrightarrow> \\<exists>as' a as''. as = as'@a#as'' \\<and> valid_edge a \\<and>\n        \\<not> n' postdominates sourcenode a \\<and> n' postdominates targetnode a\\<close>\n    show ?case\n    proof(cases \"n' postdominates n''\")\n      case True\n      with \\<open>\\<not> n' postdominates n\\<close> \\<open>sourcenode a = n\\<close> \\<open>targetnode a = n''\\<close> \n        \\<open>valid_edge a\\<close>\n      show ?thesis by blast\n    next\n      case False\n      from IH[OF \\<open>n' postdominates nx\\<close> this] show ?thesis\n        by clarsimp(rule_tac x=\"a#as'\" in exI,clarsimp)\n    qed\n  qed simp\nqed\n\n\nlemma Exit_no_postdominator:\n  \"(_Exit_) postdominates n \\<Longrightarrow> False\"\nby(fastforce dest:Exit_path simp:postdominate_def)\n\n\nlemma postdominate_path_targetnode:\n  assumes \"n' postdominates n\" and \"n -as\\<rightarrow>* n''\" and \"n' \\<notin> set(sourcenodes as)\"\n  shows \"n' postdominates n''\"\nproof -\n  from \\<open>n' postdominates n\\<close> have \"valid_node n\" and \"valid_node n'\"\n    and all:\"\\<forall>as''. n -as''\\<rightarrow>* (_Exit_) \\<longrightarrow> n' \\<in> set(sourcenodes as'')\"\n    by(simp_all add:postdominate_def)\n  from \\<open>n -as\\<rightarrow>* n''\\<close> have \"valid_node n''\" by(fastforce dest:path_valid_node)\n  have \"\\<forall>as''. n'' -as''\\<rightarrow>* (_Exit_) \\<longrightarrow> n' \\<in> set(sourcenodes as'')\"\n  proof(rule ccontr)\n    assume \"\\<not> (\\<forall>as''. n'' -as''\\<rightarrow>* (_Exit_) \\<longrightarrow> n' \\<in> set (sourcenodes as''))\"\n    then obtain as'' where \"n'' -as''\\<rightarrow>* (_Exit_)\"\n      and \"n' \\<notin> set (sourcenodes as'')\" by blast\n    from \\<open>n -as\\<rightarrow>* n''\\<close> \\<open>n'' -as''\\<rightarrow>* (_Exit_)\\<close> have \"n -as@as''\\<rightarrow>* (_Exit_)\" \n      by(rule path_Append)\n    with \\<open>n' \\<notin> set(sourcenodes as)\\<close> \\<open>n' \\<notin> set (sourcenodes as'')\\<close>\n    have \"n' \\<notin> set (sourcenodes (as@as''))\"\n      by(simp add:sourcenodes_def)\n    with \\<open>n -as@as''\\<rightarrow>* (_Exit_)\\<close> \\<open>n' postdominates n\\<close> show False\n      by(simp add:postdominate_def)\n  qed\n  with \\<open>valid_node n'\\<close> \\<open>valid_node n''\\<close> show ?thesis by(simp add:postdominate_def)\nqed\n\n\nlemma not_postdominate_source_not_postdominate_target:\n  assumes \"\\<not> n postdominates (sourcenode a)\" and \"valid_node n\" and \"valid_edge a\"\n  obtains ax where \"sourcenode a = sourcenode ax\" and \"valid_edge ax\"\n  and \"\\<not> n postdominates targetnode ax\"\nproof(atomize_elim)\n  show \"\\<exists>ax. sourcenode a = sourcenode ax \\<and> valid_edge ax \\<and> \n    \\<not> n postdominates targetnode ax\"\n  proof -\n    from assms obtain asx \n      where \"sourcenode a -asx\\<rightarrow>* (_Exit_)\"\n      and \"n \\<notin> set(sourcenodes asx)\" by(auto simp:postdominate_def)\n    from \\<open>sourcenode a -asx\\<rightarrow>* (_Exit_)\\<close> \\<open>valid_edge a\\<close> \n    obtain ax asx' where [simp]:\"asx = ax#asx'\"\n      apply - apply(erule path.cases)\n      apply(drule_tac s=\"(_Exit_)\" in sym)\n      apply simp\n      apply(drule Exit_source)\n      by simp_all\n    with \\<open>sourcenode a -asx\\<rightarrow>* (_Exit_)\\<close> have \"sourcenode a -[]@ax#asx'\\<rightarrow>* (_Exit_)\"\n      by simp\n    hence \"valid_edge ax\" and \"sourcenode a = sourcenode ax\"\n      and \"targetnode ax -asx'\\<rightarrow>* (_Exit_)\"\n      by(fastforce dest:path_split)+\n    with \\<open>n \\<notin> set(sourcenodes asx)\\<close> have \"\\<not> n postdominates targetnode ax\"\n      by(fastforce simp:postdominate_def sourcenodes_def)\n    with \\<open>sourcenode a = sourcenode ax\\<close> \\<open>valid_edge ax\\<close> show ?thesis by blast\n  qed\nqed\n\n\nlemma inner_node_Entry_edge:\n  assumes \"inner_node n\" \n  obtains a where \"valid_edge a\" and \"inner_node (targetnode a)\"\n  and \"sourcenode a = (_Entry_)\"\nproof(atomize_elim)\n  from \\<open>inner_node n\\<close> have \"valid_node n\" by(rule inner_is_valid)\n  then obtain as where \"(_Entry_) -as\\<rightarrow>* n\" by(fastforce dest:Entry_path)\n  show \"\\<exists>a. valid_edge a \\<and> inner_node (targetnode a) \\<and> sourcenode a = (_Entry_)\"\n  proof(cases \"as = []\")\n    case True\n    with \\<open>inner_node n\\<close> \\<open>(_Entry_) -as\\<rightarrow>* n\\<close> have False \n      by(fastforce simp:inner_node_def)\n    thus ?thesis by simp\n  next\n    case False\n    with \\<open>(_Entry_) -as\\<rightarrow>* n\\<close> obtain a' as' where \"as = a'#as'\"\n      and \"(_Entry_) = sourcenode a'\" and \"valid_edge a'\" \n      and \"targetnode a' -as'\\<rightarrow>* n\" \n      by -(erule path_split_Cons)\n    from \\<open>valid_edge a'\\<close> have \"valid_node (targetnode a')\" by simp\n    thus ?thesis\n    proof(cases \"targetnode a'\" rule:valid_node_cases)\n      case Entry\n      from \\<open>valid_edge a'\\<close> this have False by(rule Entry_target)\n      thus ?thesis by simp\n    next\n      case Exit\n      with \\<open>targetnode a' -as'\\<rightarrow>* n\\<close> \\<open>inner_node n\\<close>\n      have False by simp (drule path_Exit_source,auto simp:inner_node_def)\n      thus ?thesis by simp\n    next\n      case inner\n      with \\<open>valid_edge a'\\<close> \\<open>(_Entry_) = sourcenode a'\\<close> show ?thesis by simp blast\n    qed\n  qed\nqed\n\n\nlemma inner_node_Exit_edge:\n  assumes \"inner_node n\" \n  obtains a where \"valid_edge a\" and \"inner_node (sourcenode a)\"\n  and \"targetnode a = (_Exit_)\"\nproof(atomize_elim)\n  from \\<open>inner_node n\\<close> have \"valid_node n\" by(rule inner_is_valid)\n  then obtain as where \"n -as\\<rightarrow>* (_Exit_)\" by(fastforce dest:Exit_path)\n  show \"\\<exists>a. valid_edge a \\<and> inner_node (sourcenode a) \\<and> targetnode a = (_Exit_)\"\n  proof(cases \"as = []\")\n    case True\n    with \\<open>inner_node n\\<close> \\<open>n -as\\<rightarrow>* (_Exit_)\\<close> have False by fastforce\n    thus ?thesis by simp\n  next\n    case False\n    with \\<open>n -as\\<rightarrow>* (_Exit_)\\<close> obtain a' as' where \"as = as'@[a']\" \n      and \"n -as'\\<rightarrow>* sourcenode a'\" and \"valid_edge a'\" \n      and \"(_Exit_) = targetnode a'\" by -(erule path_split_snoc)\n    from \\<open>valid_edge a'\\<close> have \"valid_node (sourcenode a')\" by simp\n    thus ?thesis\n    proof(cases \"sourcenode a'\" rule:valid_node_cases)\n      case Entry\n      with \\<open>n -as'\\<rightarrow>* sourcenode a'\\<close> \\<open>inner_node n\\<close>\n      have False by simp (drule path_Entry_target,auto simp:inner_node_def)\n      thus ?thesis by simp\n    next\n      case Exit\n      from \\<open>valid_edge a'\\<close> this have False by(rule Exit_source)\n      thus ?thesis by simp\n    next\n      case inner\n      with \\<open>valid_edge a'\\<close> \\<open>(_Exit_) = targetnode a'\\<close> show ?thesis by simp blast\n    qed\n  qed\nqed\n\n\n\n\nend\n\nsubsection \\<open>Strong Postdomination\\<close>\n\n\nlocale StrongPostdomination = \n  Postdomination sourcenode targetnode kind valid_edge Entry Exit \n  for sourcenode :: \"'edge \\<Rightarrow> 'node\" and targetnode :: \"'edge \\<Rightarrow> 'node\"\n  and kind :: \"'edge \\<Rightarrow> 'state edge_kind\" and valid_edge :: \"'edge \\<Rightarrow> bool\"\n  and Entry :: \"'node\" (\"'('_Entry'_')\") and Exit :: \"'node\" (\"'('_Exit'_')\") +\n  assumes successor_set_finite: \"valid_node n \\<Longrightarrow> \n  finite {n'. \\<exists>a'. valid_edge a' \\<and> sourcenode a' = n \\<and> targetnode a' = n'}\"\n\nbegin\n\ndefinition  strong_postdominate :: \"'node \\<Rightarrow> 'node \\<Rightarrow> bool\" \n(\"_ strongly-postdominates _\" [51,0])\nwhere strong_postdominate_def:\"n' strongly-postdominates n \\<equiv>\n  (n' postdominates n \\<and> \n  (\\<exists>k \\<ge> 1. \\<forall>as nx. n -as\\<rightarrow>* nx \\<and> \n                    length as \\<ge> k \\<longrightarrow> n' \\<in> set(sourcenodes as)))\"\n\n\nlemma strong_postdominate_prop_smaller_path:\n  assumes all:\"\\<forall>as nx. n -as\\<rightarrow>* nx \\<and> length as \\<ge> k \\<longrightarrow> n' \\<in> set(sourcenodes as)\"\n  and \"n -as\\<rightarrow>* n''\" and \"length as \\<ge> k\"\n  obtains as' as'' where \"n -as'\\<rightarrow>* n'\" and \"length as' < k\" and \"n' -as''\\<rightarrow>* n''\"\n  and \"as = as'@as''\"\nproof(atomize_elim)\n  show \"\\<exists>as' as''. n -as'\\<rightarrow>* n' \\<and> length as' < k \\<and> n' -as''\\<rightarrow>* n'' \\<and> as = as'@as''\"\n  proof(rule ccontr)\n    assume \"\\<not> (\\<exists>as' as''. n -as'\\<rightarrow>* n' \\<and> length as' < k \\<and> n' -as''\\<rightarrow>* n'' \\<and> \n                          as = as'@as'')\"\n    hence all':\"\\<forall>as' as''. n -as'\\<rightarrow>* n' \\<and> n' -as''\\<rightarrow>* n'' \\<and> as = as'@as'' \n      \\<longrightarrow> length as' \\<ge> k\" by fastforce\n    from all \\<open>n -as\\<rightarrow>* n''\\<close> \\<open>length as \\<ge> k\\<close> have \"\\<exists>nx \\<in> set(sourcenodes as). nx = n'\"\n      by fastforce\n    then obtain ns ns' where \"sourcenodes as = ns@n'#ns'\"\n      and \"\\<forall>nx \\<in> set ns. nx \\<noteq> n'\"\n      by(fastforce elim!:split_list_first_propE)\n    then obtain asx a asx' where [simp]:\"ns = sourcenodes asx\"\n      and [simp]:\"as = asx@a#asx'\" and \"sourcenode a = n'\"\n      by(fastforce elim:map_append_append_maps simp:sourcenodes_def)\n    from \\<open>n -as\\<rightarrow>* n''\\<close> have \"n -asx@a#asx'\\<rightarrow>* n''\" by simp\n    with \\<open>sourcenode a = n'\\<close> have \"n -asx\\<rightarrow>* n'\" and \"valid_edge a\"\n      and \"targetnode a -asx'\\<rightarrow>* n''\" by(fastforce dest:path_split)+\n    with \\<open>sourcenode a = n'\\<close> have \"n' -a#asx'\\<rightarrow>* n''\" by(fastforce intro:Cons_path)\n    with \\<open>n -asx\\<rightarrow>* n'\\<close> all' have \"length asx \\<ge> k\" by simp\n    with \\<open>n -asx\\<rightarrow>* n'\\<close> all have \"n' \\<in> set(sourcenodes asx)\" by fastforce\n    with \\<open>\\<forall>nx \\<in> set ns. nx \\<noteq> n'\\<close> show False by fastforce\n  qed\nqed\n\n\n\nlemma strong_postdominate_refl:\n  assumes \"valid_node n\" and \"n \\<noteq> (_Exit_)\"\n  shows \"n strongly-postdominates n\"\nproof -\n  from assms have \"n postdominates n\" by(rule postdominate_refl)\n  { fix as nx assume \"n -as\\<rightarrow>* nx\" and \"length as \\<ge> 1\"\n    then obtain a' as' where [simp]:\"as = a'#as'\" by(cases as) auto\n    with \\<open>n -as\\<rightarrow>* nx\\<close> have \"n -[]@a'#as'\\<rightarrow>* nx\" by simp\n    hence \"n = sourcenode a'\" by(fastforce dest:path_split)\n    hence \"n \\<in> set(sourcenodes as)\" by(simp add:sourcenodes_def) }\n  hence \"\\<forall>as nx. n -as\\<rightarrow>* nx \\<and> length as \\<ge> 1 \\<longrightarrow> n \\<in> set(sourcenodes as)\"\n    by auto\n  hence \"\\<exists>k \\<ge> 1. \\<forall>as nx. n -as\\<rightarrow>* nx \\<and> length as \\<ge> k \\<longrightarrow> n \\<in> set(sourcenodes as)\"\n    by blast\n  with \\<open>n postdominates n\\<close> show ?thesis by(simp add:strong_postdominate_def)\nqed\n\n\nlemma strong_postdominate_trans:\n  assumes \"n'' strongly-postdominates n\" and \"n' strongly-postdominates n''\"\n  shows \"n' strongly-postdominates n\"\nproof -\n  from \\<open>n'' strongly-postdominates n\\<close> have \"n'' postdominates n\"\n    and paths1:\"\\<exists>k \\<ge> 1. \\<forall>as nx. n -as\\<rightarrow>* nx \\<and> length as \\<ge> k \n             \\<longrightarrow> n'' \\<in> set(sourcenodes as)\"\n    by(auto simp only:strong_postdominate_def)\n  from paths1 obtain k1 \n    where all1:\"\\<forall>as nx. n -as\\<rightarrow>* nx \\<and> length as \\<ge> k1 \\<longrightarrow> n'' \\<in> set(sourcenodes as)\"\n    and \"k1 \\<ge> 1\" by blast\n  from \\<open>n' strongly-postdominates n''\\<close> have \"n' postdominates n''\"\n    and paths2:\"\\<exists>k \\<ge> 1. \\<forall>as nx. n'' -as\\<rightarrow>* nx \\<and> length as \\<ge> k \n             \\<longrightarrow> n' \\<in> set(sourcenodes as)\"\n    by(auto simp only:strong_postdominate_def)\n  from paths2 obtain k2 \n    where all2:\"\\<forall>as nx. n'' -as\\<rightarrow>* nx \\<and> length as \\<ge> k2 \\<longrightarrow> n' \\<in> set(sourcenodes as)\"\n    and \"k2 \\<ge> 1\" by blast\n  from \\<open>n'' postdominates n\\<close> \\<open>n' postdominates n''\\<close> \n  have \"n' postdominates n\" by(rule postdominate_trans)\n  { fix as nx assume \"n -as\\<rightarrow>* nx\" and \"length as \\<ge> k1 + k2\"\n    hence \"length as \\<ge> k1\" by fastforce\n    with \\<open>n -as\\<rightarrow>* nx\\<close> all1 obtain asx asx' where \"n -asx\\<rightarrow>* n''\"\n      and \"length asx < k1\" and \"n'' -asx'\\<rightarrow>* nx\"\n      and [simp]:\"as = asx@asx'\" by -(erule strong_postdominate_prop_smaller_path)\n    with \\<open>length as \\<ge> k1 + k2\\<close> have \"length asx' \\<ge> k2\" by fastforce\n    with \\<open>n'' -asx'\\<rightarrow>* nx\\<close> all2 have \"n' \\<in> set(sourcenodes asx')\" by fastforce\n    hence \"n' \\<in> set(sourcenodes as)\" by(simp add:sourcenodes_def) }\n  with \\<open>k1 \\<ge> 1\\<close> \\<open>k2 \\<ge> 1\\<close> have \"\\<exists>k \\<ge> 1. \\<forall>as nx. n -as\\<rightarrow>* nx \\<and> length as \\<ge> k \n             \\<longrightarrow> n' \\<in> set(sourcenodes as)\"\n    by(rule_tac x=\"k1 + k2\" in exI,auto)\n  with \\<open>n' postdominates n\\<close> show ?thesis by(simp add:strong_postdominate_def)\nqed\n\n\nlemma strong_postdominate_antisym:\n  \"\\<lbrakk>n' strongly-postdominates n; n strongly-postdominates n'\\<rbrakk> \\<Longrightarrow> n = n'\"\nby(fastforce intro:postdominate_antisym simp:strong_postdominate_def)\n\n\nlemma strong_postdominate_path_branch:\n  assumes \"n -as\\<rightarrow>* n''\" and \"n' strongly-postdominates n''\" \n  and \"\\<not> n' strongly-postdominates n\"\n  obtains a as' as'' where \"as = as'@a#as''\" and \"valid_edge a\"\n  and \"\\<not> n' strongly-postdominates (sourcenode a)\" \n  and \"n' strongly-postdominates (targetnode a)\"\nproof(atomize_elim)\n  from assms\n  show \"\\<exists>as' a as''. as = as'@a#as'' \\<and> valid_edge a \\<and> \n    \\<not> n' strongly-postdominates (sourcenode a) \\<and> \n      n' strongly-postdominates (targetnode a)\"\n  proof(induct rule:path.induct)\n    case (Cons_path n'' as nx a n)\n    note IH = \\<open>\\<lbrakk>n' strongly-postdominates nx; \\<not> n' strongly-postdominates n''\\<rbrakk>\n      \\<Longrightarrow> \\<exists>as' a as''. as = as'@a#as'' \\<and> valid_edge a \\<and>\n        \\<not> n' strongly-postdominates sourcenode a \\<and> \n          n' strongly-postdominates targetnode a\\<close>\n    show ?case\n    proof(cases \"n' strongly-postdominates n''\")\n      case True\n      with \\<open>\\<not> n' strongly-postdominates n\\<close> \\<open>sourcenode a = n\\<close> \\<open>targetnode a = n''\\<close>\n        \\<open>valid_edge a\\<close>\n      show ?thesis by blast\n    next\n      case False\n      from IH[OF \\<open>n' strongly-postdominates nx\\<close> this] show ?thesis\n        by clarsimp(rule_tac x=\"a#as'\" in exI,clarsimp)\n    qed\n  qed simp\nqed\n\n\nlemma Exit_no_strong_postdominator:\n  \"\\<lbrakk>(_Exit_) strongly-postdominates n; n -as\\<rightarrow>* (_Exit_)\\<rbrakk> \\<Longrightarrow> False\"\nby(fastforce intro:Exit_no_postdominator path_valid_node simp:strong_postdominate_def)\n\n\nlemma strong_postdominate_path_targetnode:\n  assumes \"n' strongly-postdominates n\" and \"n -as\\<rightarrow>* n''\"\n  and \"n' \\<notin> set(sourcenodes as)\"\n  shows \"n' strongly-postdominates n''\"\nproof -\n  from \\<open>n' strongly-postdominates n\\<close> have \"n' postdominates n\"\n    and \"\\<exists>k \\<ge> 1. \\<forall>as nx. n -as\\<rightarrow>* nx \\<and> length as \\<ge> k \n             \\<longrightarrow> n' \\<in> set(sourcenodes as)\"\n    by(auto simp only:strong_postdominate_def)\n  then obtain k where \"k \\<ge> 1\"\n    and paths:\"\\<forall>as nx. n -as\\<rightarrow>* nx \\<and> length as \\<ge> k \n                         \\<longrightarrow> n' \\<in> set(sourcenodes as)\" by auto\n  from \\<open>n' postdominates n\\<close> \\<open>n -as\\<rightarrow>* n''\\<close> \\<open>n' \\<notin> set(sourcenodes as)\\<close>\n  have \"n' postdominates n''\"\n    by(rule postdominate_path_targetnode)\n  { fix as' nx assume \"n'' -as'\\<rightarrow>* nx\" and \"length as' \\<ge> k\"\n    with \\<open>n -as\\<rightarrow>* n''\\<close> have \"n -as@as'\\<rightarrow>* nx\" and \"length (as@as') \\<ge> k\"\n      by(auto intro:path_Append)\n    with paths have \"n' \\<in> set(sourcenodes (as@as'))\" by fastforce\n    with \\<open>n' \\<notin> set(sourcenodes as)\\<close> have \"n' \\<in> set(sourcenodes as')\"\n      by(fastforce simp:sourcenodes_def) }\n  with \\<open>k \\<ge> 1\\<close> have \"\\<exists>k \\<ge> 1. \\<forall>as' nx. n'' -as'\\<rightarrow>* nx \\<and> length as' \\<ge> k \n             \\<longrightarrow> n' \\<in> set(sourcenodes as')\" by auto\n  with \\<open>n' postdominates n''\\<close> show ?thesis by(simp add:strong_postdominate_def)\nqed\n\n\nlemma not_strong_postdominate_successor_set:\n  assumes \"\\<not> n strongly-postdominates (sourcenode a)\" and \"valid_node n\"\n  and \"valid_edge a\"\n  and all:\"\\<forall>nx \\<in> N. \\<exists>a'. valid_edge a' \\<and> sourcenode a' = sourcenode a \\<and>\n    targetnode a' = nx \\<and> n strongly-postdominates nx\"\n  obtains a' where \"valid_edge a'\" and \"sourcenode a' =  sourcenode a\"\n  and \"targetnode a' \\<notin> N\"\nproof(atomize_elim)\n  show \"\\<exists>a'. valid_edge a' \\<and> sourcenode a' =  sourcenode a \\<and> targetnode a' \\<notin> N\"\n  proof(cases \"n postdominates (sourcenode a)\")\n    case False\n    with \\<open>valid_edge a\\<close> \\<open>valid_node n\\<close>\n    obtain a' where [simp]:\"sourcenode a = sourcenode a'\"\n      and \"valid_edge a'\" and \"\\<not> n postdominates targetnode a'\"\n      by -(erule not_postdominate_source_not_postdominate_target)\n    with all have \"targetnode a' \\<notin> N\" by(auto simp:strong_postdominate_def)\n    with \\<open>valid_edge a'\\<close> show ?thesis by simp blast\n  next\n    case True\n    let ?M = \"{n'. \\<exists>a'. valid_edge a' \\<and> sourcenode a' =  sourcenode a \\<and> \n                         targetnode a' = n'}\"\n    let ?M' = \"{n'. \\<exists>a'. valid_edge a' \\<and> sourcenode a' =  sourcenode a \\<and> \n                          targetnode a' = n' \\<and> n strongly-postdominates n'}\"\n    let ?N' = \"(\\<lambda>n'. SOME i. i \\<ge> 1 \\<and> \n      (\\<forall>as nx. n' -as\\<rightarrow>* nx \\<and> length as \\<ge> i \n                                \\<longrightarrow> n \\<in> set(sourcenodes as))) ` N\"\n    obtain k where [simp]:\"k = Max ?N'\" by simp\n    have eq:\"{x \\<in> ?M. (\\<lambda>n'. n strongly-postdominates n') x} = ?M'\" by auto\n    from \\<open>valid_edge a\\<close> have \"finite ?M\" by(simp add:successor_set_finite)\n    hence \"finite {x \\<in> ?M. (\\<lambda>n'. n strongly-postdominates n') x}\" by fastforce\n    with eq have \"finite ?M'\" by simp\n    from all have \"N \\<subseteq> ?M'\" by auto\n    with \\<open>finite ?M'\\<close> have \"finite N\" by(auto intro:finite_subset)\n    hence \"finite ?N'\" by fastforce\n    show ?thesis\n    proof(rule ccontr)\n      assume \"\\<not> (\\<exists>a'. valid_edge a' \\<and> sourcenode a' = sourcenode a \\<and> \n                      targetnode a' \\<notin> N)\"\n      hence allImp:\"\\<forall>a'. valid_edge a' \\<and> sourcenode a' = sourcenode a\n                         \\<longrightarrow> targetnode a' \\<in> N\" by blast\n      from True \\<open>\\<not> n strongly-postdominates (sourcenode a)\\<close>\n      have allPaths:\"\\<forall>k \\<ge> 1. \\<exists>as nx. sourcenode a -as\\<rightarrow>* nx \\<and> length as \\<ge> k \n        \\<and> n \\<notin> set(sourcenodes as)\" by(auto simp:strong_postdominate_def)\n      then obtain as nx where \"sourcenode a -as\\<rightarrow>* nx\"\n        and \"length as \\<ge> k + 1\" and \"n \\<notin> set(sourcenodes as)\"\n        by (erule_tac x=\"k + 1\" in allE) auto\n      then obtain ax as' where [simp]:\"as = ax#as'\" and \"valid_edge ax\"\n        and \"sourcenode ax = sourcenode a\" and \"targetnode ax -as'\\<rightarrow>* nx\"\n        by -(erule path.cases,auto)\n      with allImp have \"targetnode ax \\<in> N\" by fastforce\n      with all have \"n strongly-postdominates (targetnode ax)\"\n        by auto\n      then obtain k' where k':\"k' = (SOME i. i \\<ge> 1 \\<and>\n        (\\<forall>as nx. targetnode ax -as\\<rightarrow>* nx \\<and> length as \\<ge> i \n                 \\<longrightarrow> n \\<in> set(sourcenodes as)))\" by simp\n      with \\<open>n strongly-postdominates (targetnode ax)\\<close>\n      have \"k' \\<ge> 1 \\<and> (\\<forall>as nx. targetnode ax -as\\<rightarrow>* nx \\<and> length as \\<ge> k'\n        \\<longrightarrow> n \\<in> set(sourcenodes as))\"\n        by(auto elim!:someI_ex simp:strong_postdominate_def)\n      hence \"k' \\<ge> 1\"\n        and spdAll:\"\\<forall>as nx. targetnode ax -as\\<rightarrow>* nx \\<and> length as \\<ge> k'\n        \\<longrightarrow> n \\<in> set(sourcenodes as)\"\n        by simp_all\n      from \\<open>targetnode ax \\<in> N\\<close> k' have \"k' \\<in> ?N'\" by blast\n      with \\<open>targetnode ax \\<in> N\\<close> have \"?N' \\<noteq> {}\" by auto\n      with \\<open>k' \\<in> ?N'\\<close> have \"k' \\<le> Max ?N'\" using \\<open>finite ?N'\\<close> by(fastforce intro:Max_ge)\n      hence \"k' \\<le> k\" by simp\n      with \\<open>targetnode ax -as'\\<rightarrow>* nx\\<close> \\<open>length as \\<ge> k + 1\\<close> spdAll \n      have \"n \\<in> set(sourcenodes as')\"\n        by fastforce\n      with \\<open>n \\<notin> set(sourcenodes as)\\<close> show False by(simp add:sourcenodes_def)\n    qed\n  qed\nqed\n\n\n\nlemma not_strong_postdominate_predecessor_successor:\n  assumes \"\\<not> n strongly-postdominates (sourcenode a)\"\n  and \"valid_node n\" and \"valid_edge a\"\n  obtains a' where \"valid_edge a'\" and \"sourcenode a' = sourcenode a\"\n  and \"\\<not> n strongly-postdominates (targetnode a')\"\nproof(atomize_elim)\n  show \"\\<exists>a'. valid_edge a' \\<and> sourcenode a' = sourcenode a \\<and> \n             \\<not> n strongly-postdominates (targetnode a')\"\n  proof(rule ccontr)\n    assume \"\\<not> (\\<exists>a'. valid_edge a' \\<and> sourcenode a' = sourcenode a \\<and>\n            \\<not> n strongly-postdominates targetnode a')\"\n    hence all:\"\\<forall>a'. valid_edge a' \\<and> sourcenode a' = sourcenode a \\<longrightarrow> \n                    n strongly-postdominates (targetnode a')\" by auto\n    let ?N = \"{n'. \\<exists>a'. sourcenode a' =  sourcenode a \\<and> valid_edge a' \\<and> \n                        targetnode a' = n'}\"\n    from all have \"\\<forall>nx \\<in> ?N. \\<exists>a'. valid_edge a' \\<and> sourcenode a' = sourcenode a \\<and> \n      targetnode a' = nx \\<and> n strongly-postdominates nx\"\n      by auto\n    with assms obtain a' where \"valid_edge a'\" \n      and \"sourcenode a' =  sourcenode a\" and \"targetnode a' \\<notin> ?N\"\n      by(erule not_strong_postdominate_successor_set)\n    thus False by auto\n  qed\nqed\n\n\nend\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Slicing/Basic/Postdomination.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5813030906443134, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.2974624438485457}}
{"text": "header  {* Syntax tree helpers *}\n\ntheory CPSUtils\nimports CPSScheme\nbegin\n\ntext {*\nThis theory defines the sets @{text \"lambdas p\"}, @{text \"calls p\"}, @{text \"calls p\"}, @{text \"vars p\"}, @{text \"labels p\"} and @{text \"prims p\"} as the subexpressions of the program @{text \"p\"}. Finiteness is shown for each of these sets, and some rules about how these sets relate. All these rules are proven more or less the same ways, which is very inelegant due to the nesting of the type and the shape of the derived induction rule.\n\nIt would be much nicer to start with these rules and define the set inductively. Unfortunately, that approach would make it very hard to show the finiteness of the sets in question.\n*}\n\n\nfun lambdas :: \"lambda \\<Rightarrow> lambda set\"\nand lambdasC :: \"call \\<Rightarrow> lambda set\"\nand lambdasV :: \"val \\<Rightarrow> lambda set\"\nwhere \"lambdas  (Lambda l vs c) = ({Lambda l vs c} \\<union> lambdasC c)\"\n    | \"lambdasC (App l d ds) = lambdasV d \\<union> (UNION (set ds) lambdasV)\"\n    | \"lambdasC (Let l binds c') = (UNION (set binds) (\\<lambda>(_,l). lambdas l)\n                                    \\<union> lambdasC c')\"\n    | \"lambdasV (L l) = lambdas l\"\n    | \"lambdasV _     = {}\"\n\n\nfun calls :: \"lambda \\<Rightarrow> call set\"\nand callsC :: \"call \\<Rightarrow> call set\"\nand callsV :: \"val \\<Rightarrow> call set\"\nwhere \"calls  (Lambda l vs c) = callsC c\"\n    | \"callsC (App l d ds) = {App l d ds} \\<union> callsV d \\<union> (UNION (set ds) callsV)\"\n    | \"callsC (Let l binds c') = {Let l binds c'}\n                                    \\<union> (UNION (set binds) (\\<lambda>(_,l). calls l)\n                                    \\<union> callsC c')\"\n    | \"callsV (L l) = calls l\"\n    | \"callsV _     = {}\"\n\nlemma finite_lambdas[simp]: \"finite (lambdas l)\" and \"finite (lambdasC c)\" \"finite (lambdasV v)\"\nby (induct rule: lambdas_lambdasC_lambdasV.induct, auto)\n\nlemma finite_calls[simp]: \"finite (calls l)\" and \"finite (callsC c)\" \"finite (callsV v)\"\nby (induct rule: calls_callsC_callsV.induct, auto)\n\nfun vars :: \"lambda \\<Rightarrow> var set\"\nand varsC :: \"call \\<Rightarrow> var set\"\nand varsV :: \"val \\<Rightarrow> var set\"\nwhere \"vars (Lambda _ vs c) = set vs \\<union> varsC c\"\n    | \"varsC (App _ a as) = varsV a \\<union> UNION (set as) varsV\"\n    | \"varsC (Let _ binds c') = UNION (set binds) (\\<lambda>(v,l). {v} \\<union> vars l) \\<union> varsC c'\"\n    | \"varsV (L l) = vars l\"\n    | \"varsV (R _ v) = {v}\"\n    | \"varsV _  = {}\"\n\n\n\nfun label :: \"lambda + call \\<Rightarrow> label\"\nwhere \"label (Inl (Lambda l _ _)) = l\"\n    | \"label (Inr (App l _ _)) = l\"\n    | \"label (Inr (Let l _ _)) = l\"\n\nfun labels :: \"lambda \\<Rightarrow> label set\"\nand labelsC :: \"call \\<Rightarrow> label set\"\nand labelsV :: \"val \\<Rightarrow> label set\"\nwhere \"labels (Lambda l vs c) = {l} \\<union> labelsC c\"\n    | \"labelsC (App l a as) = {l} \\<union> labelsV a \\<union> UNION (set as) labelsV\"\n    | \"labelsC (Let l binds c') = {l} \\<union> UNION (set binds) (\\<lambda>(v,l). labels l) \\<union> labelsC c'\"\n    | \"labelsV (L l) = labels l\"\n    | \"labelsV (R l _) = {l}\"\n    | \"labelsV _  = {}\"\n\nlemma finite_labels[simp]: \"finite (labels l)\" and \"finite (labelsC c)\" \"finite (labelsV v)\"\nby (induct rule: labels_labelsC_labelsV.induct, auto)\n\nfun prims :: \"lambda \\<Rightarrow> prim set\"\nand primsC :: \"call \\<Rightarrow> prim set\"\nand primsV :: \"val \\<Rightarrow> prim set\"\nwhere \"prims (Lambda _ vs c) = primsC c\"\n    | \"primsC (App _ a as) = primsV a \\<union> UNION (set as) primsV\"\n    | \"primsC (Let _ binds c') = UNION (set binds) (\\<lambda>(_,l). prims l) \\<union> primsC c'\"\n    | \"primsV (L l) = prims l\"\n    | \"primsV (R l v) = {}\"\n    | \"primsV (P prim) = {prim}\"\n    | \"primsV (C l v) = {}\"\n\nlemma finite_prims[simp]: \"finite (prims l)\" and \"finite (primsC c)\" \"finite (primsV v)\"\nby (induct rule: labels_labelsC_labelsV.induct, auto)\n\nfun vals :: \"lambda \\<Rightarrow> val set\"\nand valsC :: \"call \\<Rightarrow> val set\"\nand valsV :: \"val \\<Rightarrow> val set\"\nwhere \"vals (Lambda _ vs c) = valsC c\"\n    | \"valsC (App _ a as) = valsV a \\<union> UNION (set as) valsV\"\n    | \"valsC (Let _ binds c') = UNION (set binds) (\\<lambda>(_,l). vals l) \\<union> valsC c'\"\n    | \"valsV (L l) = {L l} \\<union> vals l\"\n    | \"valsV (R l v) = {R l v}\"\n    | \"valsV (P prim) = {P prim}\"\n    | \"valsV (C l v) = {C l v}\"\n\nlemma\n  fixes list2 :: \"(var \\<times> lambda) list\" and t :: \"var\\<times>lambda\"\n  shows lambdas1: \"Lambda l vs c \\<in> lambdas x \\<Longrightarrow> c \\<in> calls x\"\n  and \"Lambda l vs c \\<in> lambdasC y \\<Longrightarrow> c \\<in> callsC y\"\n  and \"Lambda l vs c \\<in> lambdasV z \\<Longrightarrow> c \\<in> callsV z\"\n  and \"\\<forall>z\\<in> set list. Lambda l vs c \\<in> lambdasV z \\<longrightarrow> c \\<in> callsV z\"\n  and \"\\<forall>x\\<in> set list2. Lambda l vs c \\<in> lambdas (snd x) \\<longrightarrow> c \\<in> calls (snd x)\"\n  and \"Lambda l vs c \\<in> lambdas (snd t) \\<Longrightarrow> c \\<in> calls (snd t)\"\napply (induct rule:mutual_lambda_call_var_inducts)\napply auto\napply (case_tac c, auto)[1]\napply (rule_tac x=\"((a, b), ba)\" in bexI, auto)\ndone\n\nlemma \n  shows lambdas2: \"Lambda l vs c \\<in> lambdas x \\<Longrightarrow> l \\<in> labels x\"\n  and \"Lambda l vs c \\<in> lambdasC y \\<Longrightarrow> l \\<in> labelsC y\"\n  and \"Lambda l vs c \\<in> lambdasV z \\<Longrightarrow> l \\<in> labelsV z\"\n  and \"\\<forall>z\\<in> set list. Lambda l vs c \\<in> lambdasV z \\<longrightarrow> l \\<in> labelsV z\"\n  and \"\\<forall>x\\<in> set (list2 :: (var \\<times> lambda) list) . Lambda l vs c \\<in> lambdas (snd x) \\<longrightarrow> l \\<in> labels (snd x)\"\n  and \"Lambda l vs c \\<in> lambdas (snd (t:: var\\<times>lambda)) \\<Longrightarrow> l \\<in> labels (snd t)\"\napply (induct rule:mutual_lambda_call_var_inducts)\napply auto\napply (rule_tac x=\"((a, b), ba)\" in bexI, auto)\ndone\n\nlemma \n  shows lambdas3: \"Lambda l vs c \\<in> lambdas x \\<Longrightarrow> set vs \\<subseteq> vars x\"\n  and \"Lambda l vs c \\<in> lambdasC y \\<Longrightarrow> set vs \\<subseteq> varsC y\"\n  and \"Lambda l vs c \\<in> lambdasV z \\<Longrightarrow> set vs \\<subseteq> varsV z\"\n  and \"\\<forall>z\\<in> set list. Lambda l vs c \\<in> lambdasV z \\<longrightarrow> set vs \\<subseteq> varsV z\"\n  and \"\\<forall>x\\<in> set (list2 :: (var \\<times> lambda) list) . Lambda l vs c \\<in> lambdas (snd x) \\<longrightarrow> set vs \\<subseteq> vars (snd x)\"\n  and \"Lambda l vs c \\<in> lambdas (snd (t:: var\\<times>lambda)) \\<Longrightarrow> set vs \\<subseteq> vars (snd t)\"\napply (induct x and y and z and list and list2 and t rule:mutual_lambda_call_var_inducts)\napply auto\napply (erule_tac x=\"((aa, ba), bb)\" in ballE)\napply (rule_tac x=\"((aa, ba), bb)\" in bexI, auto)\ndone\n\nlemma \n  shows app1: \"App l d ds \\<in> calls x \\<Longrightarrow> d \\<in> vals x\"\n  and \"App l d ds \\<in> callsC y \\<Longrightarrow> d \\<in> valsC y\"\n  and \"App l d ds \\<in> callsV z \\<Longrightarrow> d \\<in> valsV z\"\n  and \"\\<forall>z\\<in> set list. App l d ds \\<in> callsV z \\<longrightarrow> d \\<in> valsV z\"\n  and \"\\<forall>x\\<in> set (list2 :: (var \\<times> lambda) list) . App l d ds \\<in> calls (snd x) \\<longrightarrow> d \\<in> vals (snd x)\"\n  and \"App l d ds \\<in> calls (snd (t:: var\\<times>lambda)) \\<Longrightarrow> d \\<in> vals (snd t)\"\napply (induct x and y and z and list and list2 and t rule:mutual_lambda_call_var_inducts)\napply auto\napply (case_tac d, auto)\napply (erule_tac x=\"((a, b), ba)\" in ballE)\napply (rule_tac x=\"((a, b), ba)\" in bexI, auto)\ndone\n\nlemma \n  shows app2: \"App l d ds \\<in> calls x \\<Longrightarrow> set ds \\<subseteq> vals x\"\n  and \"App l d ds \\<in> callsC y \\<Longrightarrow> set ds \\<subseteq> valsC y\"\n  and \"App l d ds \\<in> callsV z \\<Longrightarrow> set ds \\<subseteq> valsV z\"\n  and \"\\<forall>z\\<in> set list. App l d ds \\<in> callsV z \\<longrightarrow> set ds \\<subseteq> valsV z\"\n  and \"\\<forall>x\\<in> set (list2 :: (var \\<times> lambda) list) . App l d ds \\<in> calls (snd x) \\<longrightarrow> set ds \\<subseteq> vals (snd x)\"\n  and \"App l d ds \\<in> calls (snd (t:: var\\<times>lambda)) \\<Longrightarrow> set ds \\<subseteq> vals (snd t)\"\napply (induct  x and y and z and list and list2 and t rule:mutual_lambda_call_var_inducts)\napply auto\napply (case_tac x, auto)\napply (erule_tac x=\"((a, b), ba)\" in ballE)\napply (rule_tac x=\"((a, b), ba)\" in bexI, auto)\ndone\n\nlemma \n  shows let1: \"Let l binds c' \\<in> calls x \\<Longrightarrow> l \\<in> labels x\"\n  and \"Let l binds c' \\<in> callsC y \\<Longrightarrow> l \\<in> labelsC y\"\n  and \"Let l binds c' \\<in> callsV z \\<Longrightarrow> l \\<in> labelsV z\"\n  and \"\\<forall>z\\<in> set list. Let l binds c' \\<in> callsV z \\<longrightarrow> l \\<in> labelsV z\"\n  and \"\\<forall>x\\<in> set (list2 :: (var \\<times> lambda) list) . Let l binds c' \\<in> calls (snd x) \\<longrightarrow> l \\<in> labels (snd x)\"\n  and \"Let l binds c' \\<in> calls (snd (t:: var\\<times>lambda)) \\<Longrightarrow> l \\<in> labels (snd t)\"\napply (induct x and y and z and list and list2 and t rule:mutual_lambda_call_var_inducts)\napply auto\napply (erule_tac x=\"((a, b), ba)\" in ballE)\napply (rule_tac x=\"((a, b), ba)\" in bexI, auto)\ndone\n\nlemma \n  shows let2: \"Let l binds c' \\<in> calls x \\<Longrightarrow> c' \\<in> calls x\"\n  and \"Let l binds c' \\<in> callsC y \\<Longrightarrow> c' \\<in> callsC y\"\n  and \"Let l binds c' \\<in> callsV z \\<Longrightarrow> c' \\<in> callsV z\"\n  and \"\\<forall>z\\<in> set list. Let l binds c' \\<in> callsV z \\<longrightarrow> c' \\<in> callsV z\"\n  and \"\\<forall>x\\<in> set (list2 :: (var \\<times> lambda) list) . Let l binds c' \\<in> calls (snd x) \\<longrightarrow> c' \\<in> calls (snd x)\"\n  and \"Let l binds c' \\<in> calls (snd (t:: var\\<times>lambda)) \\<Longrightarrow> c' \\<in> calls (snd t)\"\napply (induct x and y and z and list and list2 and t rule:mutual_lambda_call_var_inducts)\napply auto\napply (case_tac c', auto)\napply (erule_tac x=\"((a, b), ba)\" in ballE)\napply (rule_tac x=\"((a, b), ba)\" in bexI, auto)\ndone\n\nlemma \n  shows let3: \"Let l binds c' \\<in> calls x \\<Longrightarrow> fst ` set binds \\<subseteq> vars x\"\n  and \"Let l binds c' \\<in> callsC y \\<Longrightarrow> fst ` set binds \\<subseteq> varsC y\"\n  and \"Let l binds c' \\<in> callsV z \\<Longrightarrow> fst ` set binds \\<subseteq> varsV z\"\n  and \"\\<forall>z\\<in> set list. Let l binds c' \\<in> callsV z \\<longrightarrow> fst ` set binds \\<subseteq> varsV z\"\n  and \"\\<forall>x\\<in> set (list2 :: (var \\<times> lambda) list) . Let l binds c' \\<in> calls (snd x) \\<longrightarrow> fst ` set binds \\<subseteq> vars (snd x)\"\n  and \"Let l binds c' \\<in> calls (snd (t:: var\\<times>lambda)) \\<Longrightarrow> fst ` set binds \\<subseteq> vars (snd t)\"\napply (induct x and y and z and list and list2 and t rule:mutual_lambda_call_var_inducts)\napply auto\napply (erule_tac x=\"((ab, bc), bd)\" in ballE)\napply (rule_tac x=\"((ab, bc), bd)\" in bexI, auto)\ndone\n\nlemma\n  shows let4: \"Let l binds c' \\<in> calls x \\<Longrightarrow> snd ` set binds \\<subseteq> lambdas x\"\n  and \"Let l binds c' \\<in> callsC y \\<Longrightarrow> snd ` set binds \\<subseteq> lambdasC y\"\n  and \"Let l binds c' \\<in> callsV z \\<Longrightarrow> snd ` set binds \\<subseteq> lambdasV z\"\n  and \"\\<forall>z\\<in> set list. Let l binds c' \\<in> callsV z \\<longrightarrow> snd ` set binds \\<subseteq> lambdasV z\"\n  and \"\\<forall>x\\<in> set (list2 :: (var \\<times> lambda) list) . Let l binds c' \\<in> calls (snd x) \\<longrightarrow> snd ` set binds \\<subseteq> lambdas (snd x)\"\n  and \"Let l binds c' \\<in> calls (snd (t:: var\\<times>lambda)) \\<Longrightarrow> snd ` set binds \\<subseteq> lambdas (snd t)\"\napply (induct x and y and z and list and list2 and t rule:mutual_lambda_call_var_inducts)\napply auto\napply (rule_tac x=\"((a, b), ba)\" in bexI, auto)\napply (case_tac ba, auto)\napply (erule_tac x=\"((aa, bb), bc)\" in ballE)\napply (rule_tac x=\"((aa, bb), bc)\" in bexI, auto)\ndone\n\nlemma\nshows vals1: \"P prim \\<in> vals p \\<Longrightarrow> prim \\<in> prims p\"\n  and \"P prim \\<in> valsC y \\<Longrightarrow> prim \\<in> primsC y\"\n  and \"P prim \\<in> valsV z \\<Longrightarrow> prim \\<in> primsV z\"\n  and \"\\<forall>z\\<in> set list. P prim \\<in> valsV z \\<longrightarrow> prim \\<in> primsV z\"\n  and \"\\<forall>x\\<in> set (list2 :: (var \\<times> lambda) list) . P prim \\<in> vals (snd x) \\<longrightarrow> prim \\<in> prims (snd x)\"\n  and \"P prim \\<in> vals (snd (t:: var\\<times>lambda)) \\<Longrightarrow> prim \\<in> prims (snd t)\"\napply (induct rule:mutual_lambda_call_var_inducts)\napply auto\napply (erule_tac x=\"((a, b), ba)\" in ballE)\napply (rule_tac x=\"((a, b), ba)\" in bexI, auto)\ndone\n\nlemma\nshows vals2: \"R l var \\<in> vals p \\<Longrightarrow> var \\<in> vars p\"\n  and \"R l var \\<in> valsC y \\<Longrightarrow> var \\<in> varsC y\"\n  and \"R l var \\<in> valsV z \\<Longrightarrow> var \\<in> varsV z\"\n  and \"\\<forall>z\\<in> set list. R l var \\<in> valsV z \\<longrightarrow> var \\<in> varsV z\"\n  and \"\\<forall>x\\<in> set (list2 :: (var \\<times> lambda) list) . R l var \\<in> vals (snd x) \\<longrightarrow> var \\<in> vars (snd x)\"\n  and \"R l var \\<in> vals (snd (t:: var\\<times>lambda)) \\<Longrightarrow> var \\<in> vars (snd t)\"\napply (induct rule:mutual_lambda_call_var_inducts)\napply auto\napply (erule_tac x=\"((a, b), ba)\" in ballE)\napply (rule_tac x=\"((a, b), ba)\" in bexI, auto)\ndone\n\nlemma\nshows vals3: \"L l \\<in> vals p \\<Longrightarrow> l \\<in> lambdas p\"\n  and \"L l \\<in> valsC y \\<Longrightarrow> l \\<in> lambdasC y\"\n  and \"L l \\<in> valsV z \\<Longrightarrow> l \\<in> lambdasV z\"\n  and \"\\<forall>z\\<in> set list. L l \\<in> valsV z \\<longrightarrow> l \\<in> lambdasV z\"\n  and \"\\<forall>x\\<in> set (list2 :: (var \\<times> lambda) list) . L l \\<in> vals (snd x) \\<longrightarrow> l \\<in> lambdas (snd x)\"\n  and \"L l \\<in> vals (snd (t:: var\\<times>lambda)) \\<Longrightarrow> l \\<in> lambdas (snd t)\"\napply (induct rule:mutual_lambda_call_var_inducts)\napply auto\napply (erule_tac x=\"((a, b), ba)\" in ballE)\napply (rule_tac x=\"((a, b), ba)\" in bexI, auto)\napply (case_tac l, auto)\ndone\n\n\ndefinition nList :: \"'a set => nat => 'a list set\"\nwhere \"nList A n \\<equiv> {l. set l \\<le> A \\<and> length l = n}\"\n\n\n\ndefinition NList :: \"'a set => nat set => 'a list set\"\nwhere \"NList A N \\<equiv> \\<Union> n \\<in> N. nList A n\"\n\nlemma finite_Nlist[intro]:\n  \"\\<lbrakk> finite A; finite N \\<rbrakk> \\<Longrightarrow> finite (NList A N)\"\nunfolding NList_def using assms by auto\n\ndefinition call_list_lengths\n  where \"call_list_lengths p = {0,1,2,3} \\<union> (\\<lambda>c. case c of (App _ _ ds) \\<Rightarrow> length ds | _ \\<Rightarrow> 0) ` calls p\"\n\nlemma finite_call_list_lengths[simp]: \"finite (call_list_lengths p)\"\n  unfolding call_list_lengths_def by auto\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Shivers-CFA/CPSUtils.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5813030906443133, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.29746244384854564}}
{"text": "theory Arl_Ext\n  imports\n    \"../Setup\"\n    \"../Separation_Logic_Solver/Methods\"\n    \"../Bool_Assn_Setup\"\n\n    \"Isabelle_LLVM.LLVM_DS_All\"\nbegin\n\n\nhide_const Proto_EOArray.list_assn\n\n\ndefinition arl_elem_assn_ex ::\n  \"('a, 'b) dr_assn \\<Rightarrow> 'a list \\<Rightarrow> 'b list \\<Rightarrow> ('b::llvm_rep, 'l::len2) array_list \\<Rightarrow> nat set \\<Rightarrow> ll_assn\" where \n  \"arl_elem_assn_ex A xs xsi arl ex \\<equiv> \\<upharpoonleft>arl_assn xsi arl ** \\<upharpoonleft>(list_assn A (idxe_map xsi |` ex)) xs xsi\"\n\n\nabbreviation \"arl_elem_assn A xs arl \\<equiv> (EXS xsi. arl_elem_assn_ex A xs xsi arl {})\"\n\n\nlemma \n  frame_assumption_rule_dyn :\n  \"\\<lbrakk>P = Q; PS -- Pr \\<tturnstile> QS -- Qr\\<rbrakk> \\<Longrightarrow> P ** PS -- Pr \\<tturnstile> Q ** QS -- Qr\"\n  \"\\<lbrakk>P = Q; \\<box> -- Pr \\<tturnstile> QS -- Qr\\<rbrakk> \\<Longrightarrow> P -- Pr \\<tturnstile> Q ** QS -- Qr\"\n  \"\\<lbrakk>P = Q; \\<box> -- Pr \\<tturnstile> \\<box> -- Qr\\<rbrakk> \\<Longrightarrow> P -- Pr \\<tturnstile> Q -- Qr\"\n  apply (simp_all add: conj_entails_mono sep_conj_left_commute sep_conj_commute) \n  \n  oops\n  \n\nlemma entails_refl_dyn:\n  \"\\<lbrakk>P = Q; PS \\<turnstile> QS \\<rbrakk> \\<Longrightarrow> P ** PS \\<turnstile> Q ** QS\"\n  \"\\<lbrakk>P = Q; \\<box> \\<turnstile> QS\\<rbrakk> \\<Longrightarrow> P \\<turnstile> Q ** QS\"\n  \"\\<lbrakk>P = Q; \\<box> \\<turnstile> \\<box>\\<rbrakk> \\<Longrightarrow> P \\<turnstile> Q\"\n    apply (auto intro: conj_entails_mono)[1]\n   apply (simp, isep_assumption, simp)\n  apply simp\n  done\n\n\nlemma arl_elem_assn_def':\n  \"arl_elem_assn A xs xsi = (EXS l. \\<upharpoonleft>arl_assn l xsi ** \\<upharpoonleft>(list_assn A (Map.empty)) xs l)\"\n  unfolding arl_elem_assn_ex_def\n  by simp\n\n\nlemma is_pure_pureI:\n  \"is_pure A \\<Longrightarrow> pure_part (\\<upharpoonleft>A x y) \\<Longrightarrow> \\<box> \\<turnstile> \\<upharpoonleft>A x y\"\n  by (simp add: extract_pure_assn pure_true_conv)\n\n\nlemma pure_pure_asm_prefixI:\n  \"\\<flat>\\<^sub>passn x y \\<Longrightarrow> \\<box> \\<turnstile> \\<upharpoonleft>assn x y\"\n  by (metis (full_types) dr_assn_pure_asm_prefix_def entails_refl extract_pure_assn pure_true_conv)\n\n\nlemma snat_assn_le_iso [simp]:\n  \"\\<lbrakk>\\<flat>\\<^sub>psnat.assn x xi; \\<flat>\\<^sub>psnat.assn y yi\\<rbrakk> \\<Longrightarrow> xi < yi \\<longleftrightarrow> x < y\"\n  unfolding snat.assn_def  \n  by (auto simp add: snat_eq_unat_aux2 unat_mono word_less_nat_alt)\n\n\nlemmas la_ired_extract[isep_red] = la_red_extract[simplified PRECOND_def SOLVE_AUTO_def]\n\nlemma la_ired_join[isep_red]:\n  \"R i = None \\<and> i<length xs \\<and> x=xs!i \\<and> y=ys!i \n      \\<Longrightarrow> is_sep_red \\<box> \\<box> (\\<upharpoonleft>A x y ** \\<upharpoonleft>(list_assn A (R(i\\<mapsto>ys!i))) xs ys) (\\<upharpoonleft>(list_assn A R) xs ys)\"\n  apply (rule is_sep_redI)\n  subgoal premises prems\n    apply (isep_drule drule: prems(2))\n    apply (isep_drule drule: list_assn_join)\n    using prems apply auto\n    apply (simp add: fun_upd_idem)\n    done\n  done\n\n\n\nlemma arl_mems_len_rule [vcg_rules]:\n  \"\n  llvm_htriple\n  (arl_elem_assn_ex A xs xsi arl ex)\n  (arl_len arl)\n  (\\<lambda>len. \\<upharpoonleft>snat.assn (length xs) len ** arl_elem_assn_ex A xs xsi arl ex)\n\"\n  unfolding arl_elem_assn_ex_def\n  apply vcg\n  apply vcg_compat\n  apply isep_extract_pure\n  apply (isep_rule rule: pure_pure_asm_prefixI, (auto dest: list_assn_pure_partD)[1])\n  apply sep\n  done\n\n\n\nlemma arl_mems_nth_rule [vcg_rules]:\n\"\n  llvm_htriple\n  (arl_elem_assn_ex A xs xsi arl ex ** \\<upharpoonleft>snat.assn i ii ** \\<up>(i < length xs) ** \\<up>(i \\<notin> ex))\n  (arl_nth arl ii)\n  (\\<lambda>elem. arl_elem_assn_ex A xs xsi arl (ex \\<union> {i}) ** \\<upharpoonleft>A (xs ! i) elem ** \\<up>(elem = xsi ! i))\n\"\n  unfolding arl_elem_assn_ex_def\n  apply vcg\n  apply vcg_compat\n  apply (sep | find_sep)+\n    apply ((auto dest!: list_assn_pure_partD))\n  unfolding idxe_map_def\n  by (simp add: restrict_map_insert)\n\n\n\n\nunbundle monad_syntax_M \n\n\ndefinition [llvm_inline]: \"llc_for_range l h c s \\<equiv> doM {\n  (_,s) \\<leftarrow> llc_while (\\<lambda>(i,s). ll_cmp (i<h)) (\\<lambda>(i,s). doM { \n    s\\<leftarrow>c i s; \n    i \\<leftarrow> ll_add i 1; \n    Mreturn (i,s)}\n  ) (l,s);\n  Mreturn s\n}\"\n\n\nlemma llc_for_range_rule:\n  assumes [vcg_rules]:\n    \"\\<And>i ii si.\n     llvm_htriple \n      (\\<upharpoonleft>snat.assn i ii ** \\<up>\\<^sub>d(lo\\<le>i \\<and> i<hi) ** I i si) \n      (c ii si) \n      (\\<lambda>si. I (i+1) si)\"\n  shows \n    \"llvm_htriple\n      (\\<upharpoonleft>snat.assn lo loi ** \\<upharpoonleft>snat.assn hi hii ** \\<up>(lo\\<le>hi) ** I lo si)\n      (llc_for_range loi hii c si)\n      (\\<lambda>si. I hi si)\"\n  unfolding llc_for_range_def\n  apply (rewrite at 1 to \"signed_nat 1\" signed_nat_def[symmetric])\n  apply (rewrite annotate_llc_while[where \n    I=\"\\<lambda>(ii,si) t. EXS i. \\<upharpoonleft>snat.assn i ii ** \\<up>(lo\\<le>i \\<and> i\\<le>hi) ** \\<up>\\<^sub>!(t=hi-i) ** I i si\" \n    and R=\"measure id\"])\n  apply vcg_monadify\n  apply vcg'\n  done\n\n\ndefinition [llvm_code]:\n  \"arl_mems_free mem_free arl =\n  do {\n    len \\<leftarrow> arl_len arl;\n    llc_for_range 0 len \n    (\\<lambda>i x.\n      do {\n        mem \\<leftarrow> arl_nth arl i;\n        mem_free mem;\n        return 0\n      }\n    )\n    (0::1 word);\n    arl_free arl\n  }\"\n\n\ndefinition \"loop_inv A xs xsi arl i si \\<equiv> arl_elem_assn_ex A xs xsi arl {0..<i}\"\n\n\nlemma empty_arl_elem_assn_ex_sepD:\n  \"arl_elem_assn_ex A xs xsi arl {0..<length xs} \\<turnstile> \\<upharpoonleft>arl_assn xsi arl\"\n  unfolding arl_elem_assn_ex_def\n  apply isep_assumption\n  apply isep_extract_pure\n  apply (isep_drule drule: list_assn_free_none)\n  apply (auto dest: list_assn_pure_partD)\n  done\n\n\n(*\n  uint\n  unat\n  sint\n  snat\n*)\n\n\n(*uint \\<longrightarrow> unat*)\nlemma \"uint c1 = a1 \\<Longrightarrow> unat c1 = nat a1\" by auto\n\n(*uint \\<longrightarrow> sint*)\nlemma uint_sint_pos: \n  \"\\<lbrakk>uint c1 = a1; a1 < 2^(word_len c1 - 1)\\<rbrakk> \\<Longrightarrow> sint c1 = a1\"\n  by (simp add: sint_eq_uint_2pl uint_power_lower word_less_def)\n\nlemma uint_sint_neg:\n  \"\\<lbrakk>uint c1 = a1; a1 \\<ge> 2^(word_len c1 - 1)\\<rbrakk> \\<Longrightarrow> sint c1 = a1 - 2^(word_len c1)\"\n  using word_sint_msb_eq word_size msb_uint_big by (metis (full_types))\n\n(*uint \\<rightarrow> snat*)\nlemma uint_snat_pos:\n  \"\\<lbrakk>uint c1 = a1; a1 < 2^(word_len c1 - 1)\\<rbrakk> \\<Longrightarrow> snat c1 = nat a1\"\n  by (simp add: snat_eq_unat_aux1 unat_def)\n\nlemma uint_snat_neg:\n  \"\\<lbrakk>uint c1 = a1; a1 \\<ge> 2^(word_len c1 - 1)\\<rbrakk> \\<Longrightarrow> snat c1 = 0\"\n  unfolding snat_def\n  apply (auto simp add: uint_sint_neg)\n  using less_le_not_le by blast\n\n\n\n\n(*unat \\<longrightarrow> uint*)\nlemma \"unat c1 = a1 \\<Longrightarrow> uint c1 = int a1\" by auto\n\n(*unat \\<longrightarrow> snat*)\nlemma \"\\<lbrakk>unat c1 = a1; a1 < 2^(word_len c1 - 1)\\<rbrakk> \\<Longrightarrow> snat c1 = a1\" using snat_eq_unat by blast \nlemma \"\\<lbrakk>unat c1 = a1; a1 \\<ge> 2^(word_len c1 - 1)\\<rbrakk> \\<Longrightarrow> snat c1 = 0\"\nproof -\n  assume \"unat c1 = a1\" \"a1 \\<ge> 2^(word_len c1 - 1)\"  \n\n  hence \"msb c1\" using msb_unat_big by blast\n  hence \"sint c1 < 0\" using word_msb_sint by blast\n\n  thus \"snat c1 = 0\" by (simp add: snat_def)\nqed\n\n\n(*unat \\<longrightarrow> sint*)\n\n\nlemma \"uint c1 = a1 \\<Longrightarrow> unat c1 = nat a1\" by auto (*uint \\<longrightarrow> unat*)\n\n\n\nlemma \"snat c1 = a1 \\<Longrightarrow> \\<not>msb c1 \\<Longrightarrow> sint c1 = int a1\"\n  by (simp add: sint_eq_uint snat_eq_unat(2) snat_invar_def uint_nat)\nlemma \"\\<lbrakk>snat c1 = a1; msb c1\\<rbrakk> \\<Longrightarrow> a1 = 0\"\n  unfolding snat_def using word_msb_sint by force\n\n\n\nlemma arl_mems_free_rule:\n  assumes\n    mem_free_rule:\n    \"\\<And>el eli.\n      llvm_htriple\n      (\\<upharpoonleft>A el eli)\n      (mem_free eli)\n      (\\<lambda>_. \\<box>)\n    \"\n  shows\n    \"\n      llvm_htriple\n      (arl_elem_assn_ex A xs xsi arl {})\n      (arl_mems_free mem_free arl)\n      (\\<lambda>_. \\<box>)\n    \"\n  unfolding arl_mems_free_def\n  supply llc_for_range_rule[where I=\"loop_inv A xs xsi arl\", vcg_rules]\n  apply vcg\n  apply vcg_rl\n  unfolding loop_inv_def apply vcg_solve (*pre cond*)\n  subgoal for asf r sa i ii si (*step*)\n    supply mem_free_rule[vcg_rules]\n    apply vcg\n    apply (simp only: atLeast0_lessThan_Suc)\n    apply vcg_solve\n    done\n  subgoal (*after loop*)\n    apply vcg_solve\n    unfolding arl_elem_assn_ex_def\n    apply vcg\n    apply vcg_compat\n    apply isep_extract_pure\n    apply (isep_drule drule: list_assn_free_none)\n     apply (auto dest: list_assn_pure_partD)\n    done\n  done\n\n  \nend", "meta": {"author": "leanderBehr", "repo": "isabelle-llvm-RBT", "sha": "9456c7160d0d190bdb3ac358bc0058d22fb19926", "save_path": "github-repos/isabelle/leanderBehr-isabelle-llvm-RBT", "path": "github-repos/isabelle/leanderBehr-isabelle-llvm-RBT/isabelle-llvm-RBT-9456c7160d0d190bdb3ac358bc0058d22fb19926/LLVM_DS_RBT/Example/Arl_Ext.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5813030761371503, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.2974624364249895}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |               December 2004               |\n            |                   June 2005  (modified)   |\n            |              September 2005  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |                October 2005  (modified)   |\n            |                  April 2006  (modified)   |\n            |                  March 2007  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2009         |\n            |                   June 2009  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory CSP_T_law_step\nimports CSP_T_traces\nbegin\n\n(*****************************************************************\n\n         1. step laws\n         2.\n         3. \n         4. \n\n *****************************************************************)\n\n(*********************************************************\n                    stop expansion\n *********************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_STOP_step: \"STOP =T[M1,M2] ? :{} -> Pf\"\napply (simp add: cspT_semantics)\napply (simp add: traces_iff)\ndone\n\n(* to avoide producing free variables (Pf) in tactics *)\n\nlemma cspT_STOP_step_DIV: \"STOP =T[M1,M2] ? x:{} -> DIV\"\napply (simp add: cspT_semantics)\napply (simp add: traces_iff)\ndone\n\n(*********************************************************\n                    Act_prefix expansion\n *********************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_Act_prefix_step: \"a -> P =T[M,M] ? x:{a} -> P\"\napply (simp add: cspT_semantics)\napply (simp add: traces_iff)\ndone\n\n(*********************************************************\n                    Ext choice expansion\n *********************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_Ext_choice_step:\n  \"(? :X -> Pf) [+] (? :Y -> Qf) =T[M,M]\n      ? x:(X Un Y) -> \n                (IF (x : X & x : Y) THEN (Pf x |~| Qf x)\n                 ELSE IF (x : X) THEN Pf x\n                 ELSE Qf x)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim disjE conjE exE)\n apply (simp_all)\n\n apply (rule_tac x=\"a\" in exI)\n apply (rule_tac x=\"s\" in exI)\n apply (simp)\n\n apply (rule_tac x=\"a\" in exI)\n apply (rule_tac x=\"s\" in exI)\n apply (simp)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim disjE conjE exE)\n apply (simp_all)\n\n apply (case_tac \"a : Y\")\n apply (simp_all add: in_traces)\n\n apply (case_tac \"a : X\")\n apply (simp_all add: in_traces)\ndone\n\n(*********************************************************\n                    Parallel expansion\n *********************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_Parallel_step: \n  \"(? :Y -> Pf) |[X]| (? :Z -> Qf) =T[M,M]\n      ? x:((X Int Y Int Z) Un (Y - X) Un (Z - X))\n         -> IF (x : X) THEN (Pf x |[X]| Qf x)\n               ELSE IF (x : Y & x : Z) THEN ((Pf x |[X]| ? x:Z -> Qf x)\n                                     |~| (? x:Y -> Pf x |[X]| Qf x))\n               ELSE IF (x : Y) THEN (Pf x |[X]| ? x:Z -> Qf x)\n               ELSE (? x:Y -> Pf x |[X]| Qf x)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (insert trace_nil_or_Tick_or_Ev)\n apply (drule_tac x=\"t\" in spec)\n apply (elim disjE conjE exE)\n\n (* <> *)\n  apply (simp)\n\n (* [Tick]t *)\n  apply (simp add: in_traces)\n\n (* [Ev .]t *)\n  apply (simp add: in_traces)\n  apply (elim disjE conjE exE)\n\n  (* 1 *)\n  apply (simp)\n\n  (* 2 *)\n  apply (simp add: par_tr_head)\n  apply (elim conjE exE)\n  apply (case_tac \"a : Y\")\n   apply (simp)\n   apply (rule disjI2)\n   apply (rule_tac x=\"<>\" in exI)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (simp)\n   (* a ~: Y *)\n   apply (simp)\n   apply (rule_tac x=\"<>\" in exI)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (simp)\n\n  (* 3 *)\n  apply (simp add: par_tr_head)\n  apply (elim conjE exE)\n  apply (case_tac \"a : Z\")\n   apply (simp)\n   apply (rule disjI1)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<>\" in exI)\n   apply (simp)\n   (* a ~: Z *)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<>\" in exI)\n   apply (simp)\n\n  (* 4 *)\n  apply (simp add: par_tr_head)\n  apply (elim disjE conjE exE)\n\n   (* 4-1 *)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"sc\" in exI)\n   apply (simp)\n\n   (* 4-2 *)\n   apply (case_tac \"a : Z\")\n    apply (simp)\n    apply (rule disjI1)\n    apply (rule_tac x=\"sb\" in exI)\n    apply (rule_tac x=\"<Ev ab> ^^^ sc\" in exI)\n    apply (simp)\n    (* a ~: Z *)\n    apply (simp)\n    apply (rule_tac x=\"sb\" in exI)\n    apply (rule_tac x=\"<Ev ab> ^^^ sc\" in exI)\n    apply (simp)\n\n   (* 4-3 *)\n   apply (simp)\n   apply (case_tac \"a : Y\")\n    apply (simp)\n    apply (rule disjI2)\n    apply (rule_tac x=\"<Ev aa> ^^^ sb\" in exI)\n    apply (rule_tac x=\"sc\" in exI)\n    apply (simp)\n    (* a ~: Y *)\n    apply (simp)\n    apply (rule_tac x=\"<Ev aa> ^^^ sb\" in exI)\n    apply (rule_tac x=\"sc\" in exI)\n    apply (simp)\n\n(* <= *)\n apply (rule)+\n apply (drule_tac x=\"t\" in spec)\n apply (elim disjE conjE exE)\n\n (* <> *)\n  apply (simp)\n\n (* [Tick]t *)\n  apply (simp add: in_traces)\n\n (* [Ev .]t *)\n  apply (simp add: in_traces)\n  apply (elim disjE conjE exE)\n\n  (* 1 *)\n  apply (simp add: in_traces)\n  apply (elim conjE exE)\n  apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n  apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n  apply (simp add: par_tr_head)\n\n  (* 2 *)\n  apply (simp add: in_traces)\n  apply (case_tac \"a : Z\")\n   apply (simp add: in_traces)\n   apply (erule disjE)\n\n    apply (elim conjE exE)\n    apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n    apply (rule_tac x=\"ta\" in exI)\n    apply (simp add: par_tr_head)\n\n    apply (elim conjE exE)\n    apply (rule_tac x=\"sa\" in exI)\n    apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n    apply (simp add: par_tr_head)\n\n  (* 3 *)\n  apply (simp add: in_traces)\n  apply (elim conjE exE)\n\n   apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n   apply (rule_tac x=\"ta\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (simp add: in_traces)\n   apply (case_tac \"a : Y\")\n\n    apply (simp add: in_traces)\n    apply (erule disjE)\n     apply (elim conjE exE)\n     apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n     apply (rule_tac x=\"ta\" in exI)\n     apply (simp add: par_tr_head)\n     (* *)\n     apply (elim conjE exE)\n     apply (rule_tac x=\"sa\" in exI)\n     apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n     apply (simp add: par_tr_head)\n\n    apply (simp add: in_traces)\n    apply (elim conjE exE)\n    apply (rule_tac x=\"sa\" in exI)\n    apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n    apply (simp add: par_tr_head)\ndone\n\n(*********************************************************\n                      Hide expansion\n *********************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_Hiding_step: \n  \"(? :Y -> Pf) -- X =T[M,M]\n      IF (Y Int X = {}) THEN (? x:Y -> (Pf x -- X))\n                         ELSE ((? x:(Y-X) -> (Pf x -- X)) \n                               [> (! x:(Y Int X) .. (Pf x -- X)))\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n (* => *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim conjE exE)\n apply (erule disjE, simp)\n apply (elim conjE exE)\n\n apply (case_tac \"Y Int X = {}\")\n  apply (simp)\n  apply (case_tac \"a : X\", fast)\n  apply (simp)\n  apply (rule_tac x=\"sa\" in exI)\n  apply (simp)\n\n  (* Y Int X ~= {} *)\n  apply (simp)\n  apply (case_tac \"a : X\")\n   apply (simp)\n   apply (fast)\n  (* a ~: X *)\n   apply (simp)\n   apply (fast)\n\n (* <= *)\n apply (rule)\n apply (case_tac \"Y Int X = {}\")\n  apply (simp add: in_traces)\n  apply (erule disjE, simp)\n   apply (rule_tac x=\"<>\" in exI)\n   apply (simp)\n\n  apply (elim conjE exE)\n  apply (case_tac \"a : X\", fast)\n   apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n   apply (simp)\n\n (* Y Int X = {} *)\n  apply (simp add: in_traces)\n  apply (erule disjE, simp)\n   apply (rule_tac x=\"<>\" in exI)\n   apply (simp)\n\n  apply (erule disjE)\n  (* a~:X *)\n   apply (elim conjE exE)\n   apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n   apply (simp)\n  (* a:X *)\n   apply (erule disjE, simp)\n    apply (rule_tac x=\"<>\" in exI)\n    apply (simp)\n\n   apply (elim conjE exE bexE)\n   apply (rule_tac x=\"<Ev a> ^^^ s\" in exI)\n   apply (simp)\ndone\n\n(*********************************************************\n                    Renaming expansion\n *********************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_Renaming_step:\n  \"(? :X -> Pf) [[r]] =T[M,M]\n    ? y:(r `` X) -> (! x:{x. x:X & (x,y):r} .. (Pf x)[[r]])\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim disjE conjE exE)\n  (* 1 *)\n  apply (simp)\n\n  (* 2 *)\n  apply (rule disjI2)\n  apply (simp add: ren_tr_decompo)\n  apply (elim conjE exE)\n  apply (rule_tac x=\"b\" in exI)\n  apply (rule_tac x=\"ta\" in exI)\n  apply (simp)\n  apply (fast)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_traces)\n apply (erule disjE, simp)\n apply (elim disjE conjE exE)\n  apply (simp add: Image_iff)\n  apply (erule bexE)\n  apply (rule_tac x=\"<Ev x>\" in exI)\n  apply (simp)\n (* *)\n  apply (rule_tac x=\"<Ev aa> ^^^ sa\" in exI)\n  apply (simp)\ndone\n\n(*********************************************************\n            Sequential composition expansion\n *********************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_Seq_compo_step: \n  \"(? :X -> Pf) ;; Q =T[M,M] ? x:X -> (Pf x ;; Q)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim conjE exE disjE)\n apply (simp_all)\n\n  (* 1 *)\n apply (fast)\n\n  (* 2 *)\n apply (insert trace_last_nil_or_unnil)\n apply (drule_tac x=\"sa\" in spec)\n apply (erule disjE, simp)\n apply (elim conjE exE, simp)\n apply (simp add: appt_assoc_sym)\n apply (rule_tac x=\"a\" in exI)\n apply (rule_tac x=\"sb ^^^ ta\" in exI)\n apply (simp add: appt_assoc)\n apply (fast)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_traces)\n apply (erule disjE, simp)\n apply (rule disjI1)\n apply (rule_tac x=\"<>\" in exI)\n apply (simp)\n apply (elim disjE conjE exE)\n\n (* 1 *)\n  apply (rule disjI1)\n  apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI, simp)\n\n (* 2 *)\n  apply (rule disjI2)\n  apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n  apply (rule_tac x=\"ta\" in exI)\n  apply (simp add: appt_assoc)\ndone\n\n(*********************************************************\n                    Depth_rest expansion\n *********************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_Depth_rest_step:\n  \"(? :X -> Pf) |. (Suc n) =T[M,M] ? x:X -> (Pf x |. n)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim disjE conjE exE)\n apply (simp_all)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim disjE conjE exE)\n apply (simp_all)\ndone\n\n(*********************************************************)\n\nlemmas cspT_step = cspT_STOP_step       cspT_Act_prefix_step \n                   cspT_Ext_choice_step cspT_Parallel_step\n                   cspT_Hiding_step     cspT_Renaming_step\n                   cspT_Seq_compo_step  cspT_Depth_rest_step\n\nlemmas cspT_light_step = cspT_STOP_step  cspT_Act_prefix_step \n\nlemmas cspT_step_rw = cspT_STOP_step_DIV       cspT_Act_prefix_step \n                   cspT_Ext_choice_step cspT_Parallel_step\n                   cspT_Hiding_step     cspT_Renaming_step\n                   cspT_Seq_compo_step  cspT_Depth_rest_step\n\nlemmas cspT_light_step_rw = cspT_STOP_step_DIV  cspT_Act_prefix_step \n\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/CSP_T/CSP_T_law_step.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6039318479832804, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.2972480903613057}}
{"text": "(*\n(C) Copyright Andreas Viktor Hess, DTU, 2015-2020\n\nAll Rights Reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\n- Redistributions of source code must retain the above copyright\n  notice, this list of conditions and the following disclaimer.\n\n- Redistributions in binary form must reproduce the above copyright\n  notice, this list of conditions and the following disclaimer in the\n  documentation and/or other materials provided with the distribution.\n\n- Neither the name of the copyright holder nor the names of its\n  contributors may be used to endorse or promote products\n  derived from this software without specific prior written\n  permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\nLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\nA PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\nOWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\nLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\nTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n*)\n\n(*  Title:      Typing_Result.thy\n    Author:     Andreas Viktor Hess, DTU\n*)\n\nsection \\<open>The Typing Result\\<close>\ntext \\<open>\\label{sec:Typing-Result}\\<close>\n\ntheory Typing_Result\nimports Typed_Model\nbegin\n\nsubsection \\<open>The Typing Result for the Composition-Only Intruder\\<close>\ncontext typed_model\nbegin\n\nsubsubsection \\<open>Well-typedness and Type-Flaw Resistance Preservation\\<close>\ncontext\nbegin\n\nprivate lemma LI_preserves_tfr_stp_all_single:\n  assumes \"(S,\\<theta>) \\<leadsto> (S',\\<theta>')\" \"wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r S \\<theta>\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\"\n  and \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\" \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t S)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t S)\"\n  shows \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S'\"\nusing assms\nproof (induction rule: LI_rel.induct)\n  case (Compose S X f S' \\<theta>)\n  hence \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\" \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S'\" by simp_all\n  moreover have \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (map Send X)\" by (induct X) auto\n  ultimately show ?case by simp\nnext\n  case (Unify S f Y \\<delta> X S' \\<theta>)\n  hence \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (S@S')\" by simp\n\n  have \"fv\\<^sub>s\\<^sub>t (S@Send (Fun f X)#S') \\<inter> bvars\\<^sub>s\\<^sub>t (S@S') = {}\"\n    using Unify.prems(1) by (auto simp add: wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r_def)\n  moreover have \"fv (Fun f X) \\<subseteq> fv\\<^sub>s\\<^sub>t (S@Send (Fun f X)#S')\" by auto\n  moreover have \"fv (Fun f Y) \\<subseteq> fv\\<^sub>s\\<^sub>t (S@Send (Fun f X)#S')\"\n    using Unify.hyps(2) fv_subset_if_in_strand_ik'[of \"Fun f Y\" S] by force\n  ultimately have bvars_disj:\n      \"bvars\\<^sub>s\\<^sub>t (S@S') \\<inter> fv (Fun f X) = {}\" \"bvars\\<^sub>s\\<^sub>t (S@S') \\<inter> fv (Fun f Y) = {}\"\n    by blast+\n\n  have \"wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f X)\" using Unify.prems(5) by simp\n  moreover have \"wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f Y)\"\n  proof -\n    obtain x where \"x \\<in> set S\" \"Fun f Y \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t\\<^sub>p x)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t\\<^sub>p x)\"\n      using Unify.hyps(2) Unify.prems(5) by force+\n    thus ?thesis using wf_trm_subterm by auto\n  qed\n  moreover have\n      \"Fun f X \\<in> SMP (trms\\<^sub>s\\<^sub>t (S@Send (Fun f X)#S'))\" \"Fun f Y \\<in> SMP (trms\\<^sub>s\\<^sub>t (S@Send (Fun f X)#S'))\"\n    using SMP_append[of S \"Send (Fun f X)#S'\"] SMP_Cons[of \"Send (Fun f X)\" S']\n          SMP_ikI[OF Unify.hyps(2)]\n    by auto\n  hence \"\\<Gamma> (Fun f X) = \\<Gamma> (Fun f Y)\"\n    using Unify.prems(4) mgu_gives_MGU[OF Unify.hyps(3)[symmetric]]\n    unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by blast\n  ultimately have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" using mgu_wt_if_same_type[OF Unify.hyps(3)[symmetric]] by metis\n  moreover have \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\"\n    using mgu_wf_trm[OF Unify.hyps(3)[symmetric] \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f X)\\<close> \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f Y)\\<close>]\n    by (metis wf_trm_subst_range_iff)\n  moreover have \"bvars\\<^sub>s\\<^sub>t (S@S') \\<inter> range_vars \\<delta> = {}\"\n    using mgu_vars_bounded[OF Unify.hyps(3)[symmetric]] bvars_disj by fast\n  ultimately show ?case using tfr_stp_all_wt_subst_apply[OF \\<open>list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (S@S')\\<close>] by metis\nnext\n  case (Equality S \\<delta> t t' a S' \\<theta>)\n  have \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (S@S')\" \"\\<Gamma> t = \\<Gamma> t'\"\n    using tfr_stp_all_same_type[of S a t t' S']\n          tfr_stp_all_split(5)[of S _ S']\n          MGU_is_Unifier[OF mgu_gives_MGU[OF Equality.hyps(2)[symmetric]]]\n          Equality.prems(3)\n    by blast+\n  moreover have \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m t'\" using Equality.prems(5) by auto\n  ultimately have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\"\n    using mgu_wt_if_same_type[OF Equality.hyps(2)[symmetric]]\n    by metis\n  moreover have \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\"\n    using mgu_wf_trm[OF Equality.hyps(2)[symmetric] \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m t\\<close> \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m t'\\<close>]\n    by (metis wf_trm_subst_range_iff)\n  moreover have \"fv\\<^sub>s\\<^sub>t (S@Equality a t t'#S') \\<inter> bvars\\<^sub>s\\<^sub>t (S@Equality a t t'#S') = {}\"\n    using Equality.prems(1) by (auto simp add: wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r_def)\n  hence \"bvars\\<^sub>s\\<^sub>t (S@S') \\<inter> fv t = {}\" \"bvars\\<^sub>s\\<^sub>t (S@S') \\<inter> fv t' = {}\" by auto\n  hence \"bvars\\<^sub>s\\<^sub>t (S@S') \\<inter> range_vars \\<delta> = {}\"\n    using mgu_vars_bounded[OF Equality.hyps(2)[symmetric]] by fast\n  ultimately show ?case using tfr_stp_all_wt_subst_apply[OF \\<open>list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (S@S')\\<close>] by metis\nqed\n\nprivate lemma LI_in_SMP_subset_single:\n  assumes \"(S,\\<theta>) \\<leadsto> (S',\\<theta>')\" \"wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r S \\<theta>\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\"\n          \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t S)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t S)\" \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n  and \"trms\\<^sub>s\\<^sub>t S \\<subseteq> SMP M\"\n  shows \"trms\\<^sub>s\\<^sub>t S' \\<subseteq> SMP M\"\nusing assms\nproof (induction rule: LI_rel.induct)\n  case (Compose S X f S' \\<theta>)\n  hence \"SMP (trms\\<^sub>s\\<^sub>t [Send (Fun f X)]) \\<subseteq> SMP M\"\n  proof -\n    have \"SMP (trms\\<^sub>s\\<^sub>t [Send (Fun f X)]) \\<subseteq> SMP (trms\\<^sub>s\\<^sub>t (S@Send (Fun f X)#S'))\"\n      using trms\\<^sub>s\\<^sub>t_append SMP_mono by auto\n    thus ?thesis\n      using SMP_union[of \"trms\\<^sub>s\\<^sub>t (S@Send (Fun f X)#S')\" M]\n            SMP_subset_union_eq[OF Compose.prems(6)]\n      by auto\n  qed\n  thus ?case using Compose.prems(6) by auto\nnext\n  case (Unify S f Y \\<delta> X S' \\<theta>)\n  have \"Fun f X \\<in> SMP (trms\\<^sub>s\\<^sub>t (S@Send (Fun f X)#S'))\" by auto\n  moreover have \"MGU \\<delta> (Fun f X) (Fun f Y)\"\n    by (metis mgu_gives_MGU[OF Unify.hyps(3)[symmetric]])\n  moreover have\n        \"\\<And>x. x \\<in> set S \\<Longrightarrow> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t\\<^sub>p x)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f X)\"\n    using Unify.prems(4) by force+\n  moreover have \"Fun f Y \\<in> SMP (trms\\<^sub>s\\<^sub>t (S@Send (Fun f X)#S'))\"\n    by (meson SMP_ikI Unify.hyps(2) contra_subsetD ik_append_subset(1))\n  ultimately have \"wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f Y)\" \"\\<Gamma> (Fun f X) = \\<Gamma> (Fun f Y)\"\n    using ik\\<^sub>s\\<^sub>t_subterm_exD[OF \\<open>Fun f Y \\<in> ik\\<^sub>s\\<^sub>t S\\<close>] \\<open>tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t (S@Send (Fun f X)#S'))\\<close>\n    unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by (metis (full_types) SMP_wf_trm Unify.prems(4), blast)\n  hence \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" by (metis mgu_wt_if_same_type[OF Unify.hyps(3)[symmetric] \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f X)\\<close>])\n  moreover have \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\"\n    using mgu_wf_trm[OF Unify.hyps(3)[symmetric] \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f X)\\<close> \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f Y)\\<close>] by simp\n  ultimately have \"trms\\<^sub>s\\<^sub>t ((S@Send (Fun f X)#S') \\<cdot>\\<^sub>s\\<^sub>t \\<delta>) \\<subseteq> SMP M\"\n    using SMP.Substitution Unify.prems(6) wt_subst_SMP_subset by metis\n  thus ?case by auto\nnext\n  case (Equality S \\<delta> t t' a S' \\<theta>)\n  hence \"\\<Gamma> t = \\<Gamma> t'\"\n    using tfr_stp_all_same_type MGU_is_Unifier[OF mgu_gives_MGU[OF Equality.hyps(2)[symmetric]]]\n    by metis\n  moreover have \"t \\<in> SMP (trms\\<^sub>s\\<^sub>t (S@Equality a t t'#S'))\" \"t' \\<in> SMP (trms\\<^sub>s\\<^sub>t (S@Equality a t t'#S'))\"\n    using Equality.prems(1) by auto\n  moreover have \"MGU \\<delta> t t'\" using mgu_gives_MGU[OF Equality.hyps(2)[symmetric]] by metis\n  moreover have \"\\<And>x. x \\<in> set S \\<Longrightarrow> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t\\<^sub>p x)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m t'\"\n    using Equality.prems(4) by force+\n  ultimately have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" by (metis mgu_wt_if_same_type[OF Equality.hyps(2)[symmetric] \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m t\\<close>])\n  moreover have \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\"\n    using mgu_wf_trm[OF Equality.hyps(2)[symmetric] \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m t\\<close> \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m t'\\<close>] by simp\n  ultimately have \"trms\\<^sub>s\\<^sub>t ((S@Equality a t t'#S') \\<cdot>\\<^sub>s\\<^sub>t \\<delta>) \\<subseteq> SMP M\"\n    using SMP.Substitution Equality.prems wt_subst_SMP_subset by metis\n  thus ?case by auto\nqed\n\nprivate lemma LI_preserves_tfr_single:\n  assumes \"(S,\\<theta>) \\<leadsto> (S',\\<theta>')\" \"wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r S \\<theta>\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n          \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t S)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t S)\"\n          \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n  shows \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t S') \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t S')\"\nusing assms\nproof (induction rule: LI_rel.induct)\n  case (Compose S X f S' \\<theta>)\n  let ?SMPmap = \"SMP (trms\\<^sub>s\\<^sub>t (S@map Send X@S')) - (Var`\\<V>)\"\n  have \"?SMPmap \\<subseteq> SMP (trms\\<^sub>s\\<^sub>t (S@Send (Fun f X)#S')) - (Var`\\<V>)\"\n    using SMP_fun_map_snd_subset[of X f]\n          SMP_append[of \"map Send X\" S'] SMP_Cons[of \"Send (Fun f X)\" S']\n          SMP_append[of S \"Send (Fun f X)#S'\"] SMP_append[of S \"map Send X@S'\"]\n    by auto\n  hence \"\\<forall>s \\<in> ?SMPmap. \\<forall>t \\<in> ?SMPmap. (\\<exists>\\<delta>. Unifier \\<delta> s t) \\<longrightarrow> \\<Gamma> s = \\<Gamma> t\"\n    using Compose unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by (meson subsetCE)\n  thus ?case\n    using LI_preserves_trm_wf[OF r_into_rtrancl[OF LI_rel.Compose[OF Compose.hyps]], of S']\n          Compose.prems(5)\n    unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by blast\nnext\n  case (Unify S f Y \\<delta> X S' \\<theta>)\n  let ?SMP\\<delta> = \"SMP (trms\\<^sub>s\\<^sub>t (S@S' \\<cdot>\\<^sub>s\\<^sub>t \\<delta>)) - (Var`\\<V>)\"\n\n  have \"SMP (trms\\<^sub>s\\<^sub>t (S@S' \\<cdot>\\<^sub>s\\<^sub>t \\<delta>)) \\<subseteq> SMP (trms\\<^sub>s\\<^sub>t (S@Send (Fun f X)#S'))\"\n  proof\n    fix s assume \"s \\<in> SMP (trms\\<^sub>s\\<^sub>t (S@S' \\<cdot>\\<^sub>s\\<^sub>t \\<delta>))\" thus \"s \\<in> SMP (trms\\<^sub>s\\<^sub>t (S@Send (Fun f X)#S'))\"\n      using LI_in_SMP_subset_single[\n              OF LI_rel.Unify[OF Unify.hyps] Unify.prems(1,2,4,5,6)\n                 MP_subset_SMP(2)[of \"S@Send (Fun f X)#S'\"]]\n      by (metis SMP_union SMP_subset_union_eq Un_iff)\n  qed\n  hence \"\\<forall>s \\<in> ?SMP\\<delta>. \\<forall>t \\<in> ?SMP\\<delta>. (\\<exists>\\<delta>. Unifier \\<delta> s t) \\<longrightarrow> \\<Gamma> s = \\<Gamma> t\"\n    using Unify.prems(4) unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by (meson Diff_iff subsetCE)\n  thus ?case\n    using LI_preserves_trm_wf[OF r_into_rtrancl[OF LI_rel.Unify[OF Unify.hyps]], of S']\n          Unify.prems(5)\n    unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by blast\nnext\n  case (Equality S \\<delta> t t' a S' \\<theta>)\n  let ?SMP\\<delta> = \"SMP (trms\\<^sub>s\\<^sub>t (S@S' \\<cdot>\\<^sub>s\\<^sub>t \\<delta>)) - (Var`\\<V>)\"\n\n  have \"SMP (trms\\<^sub>s\\<^sub>t (S@S' \\<cdot>\\<^sub>s\\<^sub>t \\<delta>)) \\<subseteq> SMP (trms\\<^sub>s\\<^sub>t (S@Equality a t t'#S'))\"\n  proof\n    fix s assume \"s \\<in> SMP (trms\\<^sub>s\\<^sub>t (S@S' \\<cdot>\\<^sub>s\\<^sub>t \\<delta>))\" thus \"s \\<in> SMP (trms\\<^sub>s\\<^sub>t (S@Equality a t t'#S'))\"\n      using LI_in_SMP_subset_single[\n              OF LI_rel.Equality[OF Equality.hyps] Equality.prems(1,2,4,5,6)\n                 MP_subset_SMP(2)[of \"S@Equality a t t'#S'\"]]\n      by (metis SMP_union SMP_subset_union_eq Un_iff)\n  qed\n  hence \"\\<forall>s \\<in> ?SMP\\<delta>. \\<forall>t \\<in> ?SMP\\<delta>. (\\<exists>\\<delta>. Unifier \\<delta> s t) \\<longrightarrow> \\<Gamma> s = \\<Gamma> t\"\n    using Equality.prems unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by (meson Diff_iff subsetCE)\n  thus ?case\n    using LI_preserves_trm_wf[OF r_into_rtrancl[OF LI_rel.Equality[OF Equality.hyps]], of _ S']\n          Equality.prems\n    unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by blast\nqed\n\nprivate lemma LI_preserves_welltypedness_single:\n  assumes \"(S,\\<theta>) \\<leadsto> (S',\\<theta>')\" \"wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r S \\<theta>\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n  and \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t S)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t S)\" \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n  shows \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>' \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>')\"\nusing assms\nproof (induction rule: LI_rel.induct)\n  case (Unify S f Y \\<delta> X S' \\<theta>)\n  have \"wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f X)\" using Unify.prems(5) unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by simp\n  moreover have \"wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f Y)\"\n  proof -\n    obtain x where \"x \\<in> set S\" \"Fun f Y \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t\\<^sub>p x)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t\\<^sub>p x)\"\n      using Unify.hyps(2) Unify.prems(5) unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by force\n    thus ?thesis using wf_trm_subterm by auto\n  qed\n  moreover have\n      \"Fun f X \\<in> SMP (trms\\<^sub>s\\<^sub>t (S@Send (Fun f X)#S'))\" \"Fun f Y \\<in> SMP (trms\\<^sub>s\\<^sub>t (S@Send (Fun f X)#S'))\"\n    using SMP_append[of S \"Send (Fun f X)#S'\"] SMP_Cons[of \"Send (Fun f X)\" S']\n          SMP_ikI[OF Unify.hyps(2)]\n    by auto\n  hence \"\\<Gamma> (Fun f X) = \\<Gamma> (Fun f Y)\"\n    using Unify.prems(4) mgu_gives_MGU[OF Unify.hyps(3)[symmetric]]\n    unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by blast\n  ultimately have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" using mgu_wt_if_same_type[OF Unify.hyps(3)[symmetric]] by metis\n\n  have \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\"\n    by (meson mgu_wf_trm[OF Unify.hyps(3)[symmetric] \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f X)\\<close> \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f Y)\\<close>]\n              wf_trm_subst_range_iff)\n  hence \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range (\\<theta> \\<circ>\\<^sub>s \\<delta>))\"\n    using wf_trm_subst_range_iff wf_trm_subst \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\\<close>\n    unfolding subst_compose_def\n    by (metis (no_types, lifting))\n  thus ?case by (metis wt_subst_compose[OF \\<open>wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\\<close> \\<open>wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\\<close>])\nnext\n  case (Equality S \\<delta> t t' a S' \\<theta>)\n  have \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m t'\" using Equality.prems(5) by simp_all\n  moreover have \"\\<Gamma> t = \\<Gamma> t'\"\n    using \\<open>list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (S@Equality a t t'#S')\\<close>\n          MGU_is_Unifier[OF mgu_gives_MGU[OF Equality.hyps(2)[symmetric]]]\n    by auto\n  ultimately have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" using mgu_wt_if_same_type[OF Equality.hyps(2)[symmetric]] by metis\n\n  have \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\"\n    by (meson mgu_wf_trm[OF Equality.hyps(2)[symmetric] \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m t\\<close> \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m t'\\<close>] wf_trm_subst_range_iff)\n  hence \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range (\\<theta> \\<circ>\\<^sub>s \\<delta>))\"\n    using wf_trm_subst_range_iff wf_trm_subst \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\\<close>\n    unfolding subst_compose_def\n    by (metis (no_types, lifting))\n  thus ?case by (metis wt_subst_compose[OF \\<open>wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\\<close> \\<open>wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\\<close>])\nqed metis\n\nlemma LI_preserves_welltypedness:\n  assumes \"(S,\\<theta>) \\<leadsto>\\<^sup>* (S',\\<theta>')\" \"wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r S \\<theta>\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n    and \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t S)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t S)\" \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n  shows \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>'\" (is \"?A \\<theta>'\")\n    and \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>')\" (is \"?B \\<theta>'\")\nproof -\n  have \"?A \\<theta>' \\<and> ?B \\<theta>'\" using assms\n  proof (induction S \\<theta> rule: converse_rtrancl_induct2)\n    case (step S1 \\<theta>1 S2 \\<theta>2)\n    hence \"?A \\<theta>2 \\<and> ?B \\<theta>2\" using LI_preserves_welltypedness_single by presburger\n    moreover have \"wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r S2 \\<theta>2\"\n      by (fact LI_preserves_wellformedness[OF r_into_rtrancl[OF step.hyps(1)] step.prems(1)])\n    moreover have \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t S2)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t S2)\"\n      using LI_preserves_tfr_single[OF step.hyps(1)] step.prems by presburger+\n    moreover have \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S2\"\n      using LI_preserves_tfr_stp_all_single[OF step.hyps(1)] step.prems by fastforce\n    ultimately show ?case using step.IH by presburger\n  qed simp\n  thus \"?A \\<theta>'\" \"?B \\<theta>'\" by simp_all\nqed\n\nlemma LI_preserves_tfr:\n  assumes \"(S,\\<theta>) \\<leadsto>\\<^sup>* (S',\\<theta>')\" \"wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r S \\<theta>\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n    and \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t S)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t S)\" \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n  shows \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t S')\" (is \"?A S'\")\n    and \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t S')\" (is \"?B S'\")\n    and \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S'\" (is \"?C S'\")\nproof -\n  have \"?A S' \\<and> ?B S' \\<and> ?C S'\" using assms\n  proof (induction S \\<theta> rule: converse_rtrancl_induct2)\n    case (step S1 \\<theta>1 S2 \\<theta>2)\n    have \"wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r S2 \\<theta>2\" \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t S2)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t S2)\" \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S2\"\n      using LI_preserves_wellformedness[OF r_into_rtrancl[OF step.hyps(1)] step.prems(1)]\n            LI_preserves_tfr_single[OF step.hyps(1) step.prems(1,2)]\n            LI_preserves_tfr_stp_all_single[OF step.hyps(1) step.prems(1,2)]\n            step.prems(3,4,5,6)\n      by metis+\n    moreover have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>2\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>2)\"\n      using LI_preserves_welltypedness[OF r_into_rtrancl[OF step.hyps(1)] step.prems]\n      by simp_all\n    ultimately show ?case using step.IH by presburger\n  qed blast\n  thus \"?A S'\" \"?B S'\" \"?C S'\" by simp_all\nqed\nend\n\nsubsubsection \\<open>Simple Constraints are Well-typed Satisfiable\\<close>\ntext \\<open>Proving the existence of a well-typed interpretation\\<close>\ncontext\nbegin\nlemma wt_interpretation_exists:\n  obtains \\<I>::\"('fun,'var) subst\"\n  where \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\" \"subst_range \\<I> \\<subseteq> public_ground_wf_terms\"\nproof\n  define \\<I> where \"\\<I> = (\\<lambda>x. (SOME t. \\<Gamma> (Var x) = \\<Gamma> t \\<and> public_ground_wf_term t))\"\n\n  { fix x t assume \"\\<I> x = t\"\n    hence \"\\<Gamma> (Var x) = \\<Gamma> t \\<and> public_ground_wf_term t\"\n      using someI_ex[of \"\\<lambda>t. \\<Gamma> (Var x) = \\<Gamma> t \\<and> public_ground_wf_term t\",\n                     OF type_pgwt_inhabited[of \"Var x\"]]\n      unfolding \\<I>_def wf\\<^sub>t\\<^sub>r\\<^sub>m_def by simp\n  } hence props: \"\\<I> v = t \\<Longrightarrow> \\<Gamma> (Var v) = \\<Gamma> t \\<and> public_ground_wf_term t\" for v t by metis\n\n  have \"\\<I> v \\<noteq> Var v\" for v using props pgwt_ground by (simp add: empty_fv_not_var)\n  hence \"subst_domain \\<I> = UNIV\" by auto\n  moreover have \"ground (subst_range \\<I>)\" by (simp add: props pgwt_ground)\n  ultimately show \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\" by metis\n  show \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\" unfolding wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def using props by simp\n  show \"subst_range \\<I> \\<subseteq> public_ground_wf_terms\" by (auto simp add: props)\nqed\n\nlemma wt_grounding_subst_exists:\n  \"\\<exists>\\<theta>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>) \\<and> fv (t \\<cdot> \\<theta>) = {}\"\nproof -\n  obtain \\<theta> where \\<theta>: \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"subst_range \\<theta> \\<subseteq> public_ground_wf_terms\"\n    using wt_interpretation_exists by blast\n  show ?thesis using pgwt_wellformed interpretation_grounds[OF \\<theta>(1)] \\<theta>(2,3) by blast\nqed\n\nprivate fun fresh_pgwt::\"'fun set \\<Rightarrow> ('fun,'atom) term_type \\<Rightarrow> ('fun,'var) term\"  where\n  \"fresh_pgwt S (TAtom a) =\n    Fun (SOME c. c \\<notin> S \\<and> \\<Gamma> (Fun c []) = TAtom a \\<and> public c) []\"\n| \"fresh_pgwt S (TComp f T) = Fun f (map (fresh_pgwt S) T)\"\n\nprivate lemma fresh_pgwt_same_type:\n  assumes \"finite S\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\n  shows \"\\<Gamma> (fresh_pgwt S (\\<Gamma> t)) = \\<Gamma> t\"\nproof -\n  let ?P = \"\\<lambda>\\<tau>::('fun,'atom) term_type. wf\\<^sub>t\\<^sub>r\\<^sub>m \\<tau> \\<and> (\\<forall>f T. TComp f T \\<sqsubseteq> \\<tau> \\<longrightarrow> 0 < arity f)\"\n  { fix \\<tau> assume \"?P \\<tau>\" hence \"\\<Gamma> (fresh_pgwt S \\<tau>) = \\<tau>\"\n    proof (induction \\<tau>)\n      case (Var a)\n      let ?P = \"\\<lambda>c. c \\<notin> S \\<and> \\<Gamma> (Fun c []) = Var a \\<and> public c\"\n      let ?Q = \"\\<lambda>c. \\<Gamma> (Fun c []) = Var a \\<and> public c\"\n      have \" {c. ?Q c} - S = {c. ?P c}\" by auto\n      hence \"infinite {c. ?P c}\"\n        using Diff_infinite_finite[OF assms(1) infinite_typed_consts[of a]]\n        by metis\n      hence \"\\<exists>c. ?P c\" using not_finite_existsD by blast\n      thus ?case using someI_ex[of ?P] by auto\n    next\n      case (Fun f T)\n      have f: \"0 < arity f\" using Fun.prems fun_type_inv by auto\n      have \"\\<And>t. t \\<in> set T \\<Longrightarrow> ?P t\"\n        using Fun.prems wf_trm_subtermeq term.le_less_trans Fun_param_is_subterm\n        by metis\n      hence \"\\<And>t. t \\<in> set T \\<Longrightarrow> \\<Gamma> (fresh_pgwt S t) = t\" using Fun.prems Fun.IH by auto\n      hence \"map \\<Gamma> (map (fresh_pgwt S) T) = T\"  by (induct T) auto\n      thus ?case using fun_type[OF f] by simp\n    qed\n  } thus ?thesis using assms(1) \\<Gamma>_wf'[OF assms(2)] \\<Gamma>_wf(1) by auto\nqed\n\nprivate lemma fresh_pgwt_empty_synth:\n  assumes \"finite S\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\n  shows \"{} \\<turnstile>\\<^sub>c fresh_pgwt S (\\<Gamma> t)\"\nproof -\n  let ?P = \"\\<lambda>\\<tau>::('fun,'atom) term_type. wf\\<^sub>t\\<^sub>r\\<^sub>m \\<tau> \\<and> (\\<forall>f T. TComp f T \\<sqsubseteq> \\<tau> \\<longrightarrow> 0 < arity f)\"\n  { fix \\<tau> assume \"?P \\<tau>\" hence \"{} \\<turnstile>\\<^sub>c fresh_pgwt S \\<tau>\"\n    proof (induction \\<tau>)\n      case (Var a)\n      let ?P = \"\\<lambda>c. c \\<notin> S \\<and> \\<Gamma> (Fun c []) = Var a \\<and> public c\"\n      let ?Q = \"\\<lambda>c. \\<Gamma> (Fun c []) = Var a \\<and> public c\"\n      have \" {c. ?Q c} - S = {c. ?P c}\" by auto\n      hence \"infinite {c. ?P c}\"\n        using Diff_infinite_finite[OF assms(1) infinite_typed_consts[of a]]\n        by metis\n      hence \"\\<exists>c. ?P c\" using not_finite_existsD by blast\n      thus ?case\n        using someI_ex[of ?P] intruder_synth.ComposeC[of \"[]\" _ \"{}\"] const_type_inv\n        by auto\n    next\n      case (Fun f T)\n      have f: \"0 < arity f\" \"length T = arity f\" \"public f\"\n        using Fun.prems fun_type_inv unfolding wf\\<^sub>t\\<^sub>r\\<^sub>m_def by auto\n      have \"\\<And>t. t \\<in> set T \\<Longrightarrow> ?P t\"\n        using Fun.prems wf_trm_subtermeq term.le_less_trans Fun_param_is_subterm\n        by metis\n      hence \"\\<And>t. t \\<in> set T \\<Longrightarrow> {} \\<turnstile>\\<^sub>c fresh_pgwt S t\" using Fun.prems Fun.IH by auto\n      moreover have \"length (map (fresh_pgwt S) T) = arity f\" using f(2) by auto\n      ultimately show ?case using intruder_synth.ComposeC[of \"map (fresh_pgwt S) T\" f] f by auto\n    qed\n  } thus ?thesis using assms(1) \\<Gamma>_wf'[OF assms(2)] \\<Gamma>_wf(1) by auto\nqed\n\nprivate lemma fresh_pgwt_has_fresh_const:\n  assumes \"finite S\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\n  obtains c where \"Fun c [] \\<sqsubseteq> fresh_pgwt S (\\<Gamma> t)\" \"c \\<notin> S\"\nproof -\n  let ?P = \"\\<lambda>\\<tau>::('fun,'atom) term_type. wf\\<^sub>t\\<^sub>r\\<^sub>m \\<tau> \\<and> (\\<forall>f T. TComp f T \\<sqsubseteq> \\<tau> \\<longrightarrow> 0 < arity f)\"\n  { fix \\<tau> assume \"?P \\<tau>\" hence \"\\<exists>c. Fun c [] \\<sqsubseteq> fresh_pgwt S \\<tau> \\<and> c \\<notin> S\"\n    proof (induction \\<tau>)\n      case (Var a)\n      let ?P = \"\\<lambda>c. c \\<notin> S \\<and> \\<Gamma> (Fun c []) = Var a \\<and> public c\"\n      let ?Q = \"\\<lambda>c. \\<Gamma> (Fun c []) = Var a \\<and> public c\"\n      have \" {c. ?Q c} - S = {c. ?P c}\" by auto\n      hence \"infinite {c. ?P c}\"\n        using Diff_infinite_finite[OF assms(1) infinite_typed_consts[of a]]\n        by metis\n      hence \"\\<exists>c. ?P c\" using not_finite_existsD by blast\n      thus ?case using someI_ex[of ?P] by auto\n    next\n      case (Fun f T)\n      have f: \"0 < arity f\" \"length T = arity f\" \"public f\" \"T \\<noteq> []\"\n        using Fun.prems fun_type_inv unfolding wf\\<^sub>t\\<^sub>r\\<^sub>m_def by auto\n      obtain t' where t': \"t' \\<in> set T\" by (meson all_not_in_conv f(4) set_empty)\n      have \"\\<And>t. t \\<in> set T \\<Longrightarrow> ?P t\"\n        using Fun.prems wf_trm_subtermeq term.le_less_trans Fun_param_is_subterm\n        by metis\n      hence \"\\<And>t. t \\<in> set T \\<Longrightarrow> \\<exists>c. Fun c [] \\<sqsubseteq> fresh_pgwt S t \\<and> c \\<notin> S\"\n        using Fun.prems Fun.IH by auto\n      then obtain c where c: \"Fun c [] \\<sqsubseteq> fresh_pgwt S t'\" \"c \\<notin> S\" using t' by metis\n      thus ?case using t' by auto\n    qed\n  } thus ?thesis using that assms \\<Gamma>_wf'[OF assms(2)] \\<Gamma>_wf(1) by blast\nqed\n\nprivate lemma fresh_pgwt_subterm_fresh:\n  assumes \"finite S\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m s\" \"funs_term s \\<subseteq> S\"\n  shows \"s \\<notin> subterms (fresh_pgwt S (\\<Gamma> t))\"\nproof -\n  let ?P = \"\\<lambda>\\<tau>::('fun,'atom) term_type. wf\\<^sub>t\\<^sub>r\\<^sub>m \\<tau> \\<and> (\\<forall>f T. TComp f T \\<sqsubseteq> \\<tau> \\<longrightarrow> 0 < arity f)\"\n  { fix \\<tau> assume \"?P \\<tau>\" hence \"s \\<notin> subterms (fresh_pgwt S \\<tau>)\"\n    proof (induction \\<tau>)\n      case (Var a)\n      let ?P = \"\\<lambda>c. c \\<notin> S \\<and> \\<Gamma> (Fun c []) = Var a \\<and> public c\"\n      let ?Q = \"\\<lambda>c. \\<Gamma> (Fun c []) = Var a \\<and> public c\"\n      have \" {c. ?Q c} - S = {c. ?P c}\" by auto\n      hence \"infinite {c. ?P c}\"\n        using Diff_infinite_finite[OF assms(1) infinite_typed_consts[of a]]\n        by metis\n      hence \"\\<exists>c. ?P c\" using not_finite_existsD by blast\n      thus ?case using someI_ex[of ?P] assms(4) by auto\n    next\n      case (Fun f T)\n      have f: \"0 < arity f\" \"length T = arity f\" \"public f\"\n        using Fun.prems fun_type_inv unfolding wf\\<^sub>t\\<^sub>r\\<^sub>m_def by auto\n      have \"\\<And>t. t \\<in> set T \\<Longrightarrow> ?P t\"\n        using Fun.prems wf_trm_subtermeq term.le_less_trans Fun_param_is_subterm\n        by metis\n      hence \"\\<And>t. t \\<in> set T \\<Longrightarrow> s \\<notin> subterms (fresh_pgwt S t)\" using Fun.prems Fun.IH by auto\n      moreover have \"s \\<noteq> fresh_pgwt S (Fun f T)\"\n      proof -\n        obtain c where c: \"Fun c [] \\<sqsubseteq> fresh_pgwt S (Fun f T)\" \"c \\<notin> S\"\n          using fresh_pgwt_has_fresh_const[OF assms(1)] type_wfttype_inhabited Fun.prems\n          by metis\n        hence \"\\<not>Fun c [] \\<sqsubseteq> s\" using assms(4) subtermeq_imp_funs_term_subset by force\n        thus ?thesis using c(1) by auto\n      qed\n      ultimately show ?case by auto\n    qed\n  } thus ?thesis using assms(1) \\<Gamma>_wf'[OF assms(2)] \\<Gamma>_wf(1) by auto\nqed\n\nprivate lemma wt_fresh_pgwt_term_exists:\n  assumes \"finite T\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m s\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s T\"\n  obtains t where \"\\<Gamma> t = \\<Gamma> s\" \"{} \\<turnstile>\\<^sub>c t\" \"\\<forall>s \\<in> T. \\<forall>u \\<in> subterms s. u \\<notin> subterms t\"\nproof -\n  have finite_S: \"finite (\\<Union>(funs_term ` T))\" using assms(1) by auto\n\n  have 1: \"\\<Gamma> (fresh_pgwt (\\<Union>(funs_term ` T)) (\\<Gamma> s)) = \\<Gamma> s\"\n    using fresh_pgwt_same_type[OF finite_S assms(2)] by auto\n\n  have 2: \"{} \\<turnstile>\\<^sub>c fresh_pgwt (\\<Union>(funs_term ` T)) (\\<Gamma> s)\"\n    using fresh_pgwt_empty_synth[OF finite_S assms(2)] by auto\n\n  have 3: \"\\<forall>v \\<in> T. \\<forall>u \\<in> subterms v. u \\<notin> subterms (fresh_pgwt (\\<Union>(funs_term ` T)) (\\<Gamma> s))\"\n    using fresh_pgwt_subterm_fresh[OF finite_S assms(2)] assms(3)\n          wf_trm_subtermeq subtermeq_imp_funs_term_subset\n    by force\n\n  show ?thesis by (rule that[OF 1 2 3])\nqed\n\nlemma wt_bij_finite_subst_exists:\n  assumes \"finite (S::'var set)\" \"finite (T::('fun,'var) terms)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s T\"\n  shows \"\\<exists>\\<sigma>::('fun,'var) subst.\n              subst_domain \\<sigma> = S\n            \\<and> bij_betw \\<sigma> (subst_domain \\<sigma>) (subst_range \\<sigma>)\n            \\<and> subterms\\<^sub>s\\<^sub>e\\<^sub>t (subst_range \\<sigma>) \\<subseteq> {t. {} \\<turnstile>\\<^sub>c t} - T\n            \\<and> (\\<forall>s \\<in> subst_range \\<sigma>. \\<forall>u \\<in> subst_range \\<sigma>. (\\<exists>v. v \\<sqsubseteq> s \\<and> v \\<sqsubseteq> u) \\<longrightarrow> s = u)\n            \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma>\n            \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<sigma>)\"\nusing assms\nproof (induction rule: finite_induct)\n  case empty\n  have \"subst_domain Var = {}\"\n       \"bij_betw Var (subst_domain Var) (subst_range Var)\"\n       \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (subst_range Var) \\<subseteq> {t. {} \\<turnstile>\\<^sub>c t} - T\"\n       \"\\<forall>s \\<in> subst_range Var. \\<forall>u \\<in> subst_range Var. (\\<exists>v. v \\<sqsubseteq> s \\<and> v \\<sqsubseteq> u) \\<longrightarrow> s = u\"\n       \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t Var\"\n       \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range Var)\"\n    unfolding bij_betw_def\n    by auto\n  thus ?case by (force simp add: subst_domain_def)\nnext\n  case (insert x S)\n  then obtain \\<sigma> where \\<sigma>:\n      \"subst_domain \\<sigma> = S\" \"bij_betw \\<sigma> (subst_domain \\<sigma>) (subst_range \\<sigma>)\"\n      \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (subst_range \\<sigma>) \\<subseteq> {t. {} \\<turnstile>\\<^sub>c t} - T\"\n      \"\\<forall>s \\<in> subst_range \\<sigma>. \\<forall>u \\<in> subst_range \\<sigma>. (\\<exists>v. v \\<sqsubseteq> s \\<and> v \\<sqsubseteq> u) \\<longrightarrow> s = u\"\n      \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<sigma>)\"\n    by (auto simp del: subst_range.simps)\n\n  have *: \"finite (T \\<union> subst_range \\<sigma>)\"\n    using insert.prems(1) insert.hyps(1) \\<sigma>(1) by simp\n  have **: \"wf\\<^sub>t\\<^sub>r\\<^sub>m (Var x)\" by simp\n  have ***: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (T \\<union> subst_range \\<sigma>)\" using assms(3) \\<sigma>(6) by blast\n  obtain t where t:\n      \"\\<Gamma> t = \\<Gamma> (Var x)\" \"{} \\<turnstile>\\<^sub>c t\"\n      \"\\<forall>s \\<in> T \\<union> subst_range \\<sigma>. \\<forall>u \\<in> subterms s. u \\<notin> subterms t\"\n    using wt_fresh_pgwt_term_exists[OF * ** ***] by auto\n\n  obtain \\<theta> where \\<theta>: \"\\<theta> \\<equiv> \\<lambda>y. if x = y then t else \\<sigma> y\" by simp\n\n  have t_ground: \"fv t = {}\" using t(2) pgwt_ground[of t] pgwt_is_empty_synth[of t] by auto\n  hence x_dom: \"x \\<notin> subst_domain \\<sigma>\" \"x \\<in> subst_domain \\<theta>\" using insert.hyps(2) \\<sigma>(1) \\<theta> by auto\n  moreover have \"subst_range \\<sigma> \\<subseteq> subterms\\<^sub>s\\<^sub>e\\<^sub>t (subst_range \\<sigma>)\" by auto\n  hence ground_imgs: \"ground (subst_range \\<sigma>)\"\n    using \\<sigma>(3) pgwt_ground pgwt_is_empty_synth\n    by force\n  ultimately have x_img: \"\\<sigma> x \\<notin> subst_range \\<sigma>\"\n    using ground_subst_dom_iff_img\n    by (auto simp add: subst_domain_def)\n\n  have \"ground (insert t (subst_range \\<sigma>))\"\n    using ground_imgs x_dom t_ground\n    by auto\n  have \\<theta>_dom: \"subst_domain \\<theta> = insert x (subst_domain \\<sigma>)\"\n    using \\<theta> t_ground by (auto simp add: subst_domain_def)\n  have \\<theta>_img: \"subst_range \\<theta> = insert t (subst_range \\<sigma>)\"\n  proof\n    show \"subst_range \\<theta> \\<subseteq> insert t (subst_range \\<sigma>)\"\n    proof\n      fix t' assume \"t' \\<in> subst_range \\<theta>\"\n      then obtain y where \"y \\<in> subst_domain \\<theta>\" \"t' = \\<theta> y\" by auto\n      thus \"t' \\<in> insert t (subst_range \\<sigma>)\" using \\<theta> by (auto simp add: subst_domain_def)\n    qed\n    show \"insert t (subst_range \\<sigma>) \\<subseteq> subst_range \\<theta>\"\n    proof\n      fix t' assume t': \"t' \\<in> insert t (subst_range \\<sigma>)\"\n      hence \"fv t' = {}\" using ground_imgs x_img t_ground by auto\n      hence \"t' \\<noteq> Var x\" by auto\n      show \"t' \\<in> subst_range \\<theta>\"\n      proof (cases \"t' = t\")\n        case False\n        hence \"t' \\<in> subst_range \\<sigma>\" using t' by auto\n        then obtain y where \"\\<sigma> y \\<in> subst_range \\<sigma>\" \"t' = \\<sigma> y\" by auto\n        hence \"y \\<in> subst_domain \\<sigma>\" \"t' \\<noteq> Var y\"\n          using ground_subst_dom_iff_img[OF ground_imgs(1)]\n          by (auto simp add: subst_domain_def simp del: subst_range.simps)\n        hence \"x \\<noteq> y\" using x_dom by auto\n        hence \"\\<theta> y = \\<sigma> y\" unfolding \\<theta> by auto\n        thus ?thesis using \\<open>t' \\<noteq> Var y\\<close> \\<open>t' = \\<sigma> y\\<close> subst_imgI[of \\<theta> y] by auto\n      qed (metis subst_imgI \\<theta> \\<open>t' \\<noteq> Var x\\<close>)\n    qed\n  qed\n  hence \\<theta>_ground_img: \"ground (subst_range \\<theta>)\"\n    using ground_imgs t_ground\n    by auto\n\n  have \"subst_domain \\<theta> = insert x S\" using \\<theta>_dom \\<sigma>(1) by auto\n  moreover have \"bij_betw \\<theta> (subst_domain \\<theta>) (subst_range \\<theta>)\"\n  proof (intro bij_betwI')\n    fix y z assume *: \"y \\<in> subst_domain \\<theta>\" \"z \\<in> subst_domain \\<theta>\"\n    hence \"fv (\\<theta> y) = {}\" \"fv (\\<theta> z) = {}\" using \\<theta>_ground_img by auto\n    { assume \"\\<theta> y = \\<theta> z\" hence \"y = z\"\n      proof (cases \"\\<theta> y \\<in> subst_range \\<sigma> \\<and> \\<theta> z \\<in> subst_range \\<sigma>\")\n        case True\n        hence **: \"y \\<in> subst_domain \\<sigma>\" \"z \\<in> subst_domain \\<sigma>\"\n          using \\<theta> \\<theta>_dom True * t(3) by (metis Un_iff term.order_refl insertE)+\n        hence \"y \\<noteq> x\" \"z \\<noteq> x\" using x_dom by auto\n        hence \"\\<theta> y = \\<sigma> y\" \"\\<theta> z = \\<sigma> z\" using \\<theta> by auto\n        thus ?thesis using \\<open>\\<theta> y = \\<theta> z\\<close> \\<sigma>(2) ** unfolding bij_betw_def inj_on_def by auto\n      qed (metis \\<theta> * \\<open>\\<theta> y = \\<theta> z\\<close> \\<theta>_dom ground_imgs(1) ground_subst_dom_iff_img insertE)\n    }\n    thus \"(\\<theta> y = \\<theta> z) = (y = z)\" by auto\n  next\n    fix y assume \"y \\<in> subst_domain \\<theta>\" thus \"\\<theta> y \\<in> subst_range \\<theta>\" by auto\n  next\n    fix t assume \"t \\<in> subst_range \\<theta>\" thus \"\\<exists>z \\<in> subst_domain \\<theta>. t = \\<theta> z\" by auto\n  qed\n  moreover have \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (subst_range \\<theta>) \\<subseteq> {t. {} \\<turnstile>\\<^sub>c t}  - T\"\n  proof -\n    { fix s assume \"s \\<sqsubseteq> t\"\n      hence \"s \\<in> {t. {} \\<turnstile>\\<^sub>c t}  - T\"\n        using t(2,3)\n        by (metis Diff_eq_empty_iff Diff_iff Un_upper1 term.order_refl\n                  deduct_synth_subterm mem_Collect_eq)\n    } thus ?thesis using \\<sigma>(3) \\<theta> \\<theta>_img by auto\n  qed\n  moreover have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" using \\<theta> t(1) \\<sigma>(5) unfolding wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def by auto\n  moreover have \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n    using \\<theta> \\<sigma>(6) t(2) pgwt_is_empty_synth pgwt_wellformed\n          wf_trm_subst_range_iff[of \\<sigma>] wf_trm_subst_range_iff[of \\<theta>]\n    by metis\n  moreover have \"\\<forall>s\\<in>subst_range \\<theta>. \\<forall>u\\<in>subst_range \\<theta>. (\\<exists>v. v \\<sqsubseteq> s \\<and> v \\<sqsubseteq> u) \\<longrightarrow> s = u\"\n    using \\<sigma>(4) \\<theta>_img t(3) by (auto simp del: subst_range.simps)\n  ultimately show ?case by blast\nqed\n\nprivate lemma wt_bij_finite_tatom_subst_exists_single:\n  assumes \"finite (S::'var set)\" \"finite (T::('fun,'var) terms)\"\n  and \"\\<And>x. x \\<in> S \\<Longrightarrow> \\<Gamma> (Var x) = TAtom a\"\n  shows \"\\<exists>\\<sigma>::('fun,'var) subst. subst_domain \\<sigma> = S\n                      \\<and> bij_betw \\<sigma> (subst_domain \\<sigma>) (subst_range \\<sigma>)\n                      \\<and> subst_range \\<sigma> \\<subseteq> ((\\<lambda>c. Fun c []) `  {c. \\<Gamma> (Fun c []) = TAtom a \\<and>\n                                                            public c \\<and> arity c = 0}) - T\n                      \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma>\n                      \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<sigma>)\"\nproof -\n  let ?U = \"{c. \\<Gamma> (Fun c []) = TAtom a \\<and> public c \\<and> arity c = 0}\"\n\n  obtain \\<sigma> where \\<sigma>:\n      \"subst_domain \\<sigma> = S\" \"bij_betw \\<sigma> (subst_domain \\<sigma>) (subst_range \\<sigma>)\"\n      \"subst_range \\<sigma> \\<subseteq> ((\\<lambda>c. Fun c []) ` ?U) - T\"\n    using bij_finite_const_subst_exists'[OF assms(1,2) infinite_typed_consts'[of a]]\n    by auto\n\n  { fix x assume \"x \\<notin> subst_domain \\<sigma>\" hence \"\\<Gamma> (Var x) = \\<Gamma> (\\<sigma> x)\" by auto }\n  moreover\n  { fix x assume \"x \\<in> subst_domain \\<sigma>\"\n    hence \"\\<exists>c \\<in> ?U. \\<sigma> x = Fun c [] \\<and> arity c = 0\" using \\<sigma> by auto\n    hence \"\\<Gamma> (\\<sigma> x) = TAtom a\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m (\\<sigma> x)\" using assms(3) const_type wf_trmI[of \"[]\"] by auto\n    hence \"\\<Gamma> (Var x) = \\<Gamma> (\\<sigma> x)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m (\\<sigma> x)\" using assms(3) \\<sigma>(1) by force+\n  }\n  ultimately have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<sigma>)\"\n    using wf_trm_subst_range_iff[of \\<sigma>]\n    unfolding wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def\n    by force+\n  thus ?thesis using \\<sigma> by auto\nqed\n\nlemma wt_bij_finite_tatom_subst_exists:\n  assumes \"finite (S::'var set)\" \"finite (T::('fun,'var) terms)\"\n  and \"\\<And>x. x \\<in> S \\<Longrightarrow> \\<exists>a. \\<Gamma> (Var x) = TAtom a\"\n  shows \"\\<exists>\\<sigma>::('fun,'var) subst. subst_domain \\<sigma> = S\n                      \\<and> bij_betw \\<sigma> (subst_domain \\<sigma>) (subst_range \\<sigma>)\n                      \\<and> subst_range \\<sigma> \\<subseteq> ((\\<lambda>c. Fun c []) `  \\<C>\\<^sub>p\\<^sub>u\\<^sub>b) - T\n                      \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma>\n                      \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<sigma>)\"\nusing assms\nproof (induction rule: finite_induct)\n  case empty\n  have \"subst_domain Var = {}\"\n       \"bij_betw Var (subst_domain Var) (subst_range Var)\"\n       \"subst_range Var \\<subseteq> ((\\<lambda>c. Fun c []) `  \\<C>\\<^sub>p\\<^sub>u\\<^sub>b) - T\"\n       \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t Var\"\n       \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range Var)\"\n    unfolding bij_betw_def\n    by auto\n  thus ?case by (auto simp add: subst_domain_def)\nnext\n  case (insert x S)\n  then obtain a where a: \"\\<Gamma> (Var x) = TAtom a\" by fastforce\n\n  from insert obtain \\<sigma> where \\<sigma>:\n      \"subst_domain \\<sigma> = S\" \"bij_betw \\<sigma> (subst_domain \\<sigma>) (subst_range \\<sigma>)\"\n      \"subst_range \\<sigma> \\<subseteq> ((\\<lambda>c. Fun c []) `  \\<C>\\<^sub>p\\<^sub>u\\<^sub>b) - T\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma>\"\n      \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<sigma>)\"\n    by auto\n\n  let ?S' = \"{y \\<in> S. \\<Gamma> (Var y) = TAtom a}\"\n  let ?T' = \"T \\<union> subst_range \\<sigma>\"\n\n  have *: \"finite (insert x ?S')\" using insert by simp\n  have **: \"finite ?T'\" using insert.prems(1) insert.hyps(1) \\<sigma>(1) by simp\n  have ***: \"\\<And>y. y \\<in> insert x ?S' \\<Longrightarrow> \\<Gamma> (Var y) = TAtom a\" using a by auto\n\n  obtain \\<delta> where \\<delta>:\n      \"subst_domain \\<delta> = insert x ?S'\" \"bij_betw \\<delta> (subst_domain \\<delta>) (subst_range \\<delta>)\"\n      \"subst_range \\<delta> \\<subseteq> ((\\<lambda>c. Fun c []) `  \\<C>\\<^sub>p\\<^sub>u\\<^sub>b) - ?T'\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\"\n    using wt_bij_finite_tatom_subst_exists_single[OF * ** ***] const_type_inv[of _ \"[]\" a]\n    by blast\n\n  obtain \\<theta> where \\<theta>: \"\\<theta> \\<equiv> \\<lambda>y. if x = y then \\<delta> y else \\<sigma> y\" by simp\n\n  have x_dom: \"x \\<notin> subst_domain \\<sigma>\" \"x \\<in> subst_domain \\<delta>\" \"x \\<in> subst_domain \\<theta>\"\n    using insert.hyps(2) \\<sigma>(1) \\<delta>(1) \\<theta> by (auto simp add: subst_domain_def)\n  moreover have ground_imgs: \"ground (subst_range \\<sigma>)\" \"ground (subst_range \\<delta>)\"\n    using pgwt_ground \\<sigma>(3) \\<delta>(3) by auto\n  ultimately have x_img: \"\\<sigma> x \\<notin> subst_range \\<sigma>\" \"\\<delta> x \\<in> subst_range \\<delta>\"\n    using ground_subst_dom_iff_img by (auto simp add: subst_domain_def)\n\n  have \"ground (insert (\\<delta> x) (subst_range \\<sigma>))\" using ground_imgs x_dom by auto\n  have \\<theta>_dom: \"subst_domain \\<theta> = insert x (subst_domain \\<sigma>)\"\n    using \\<delta>(1) \\<theta> by (auto simp add: subst_domain_def)\n  have \\<theta>_img: \"subst_range \\<theta> = insert (\\<delta> x) (subst_range \\<sigma>)\"\n  proof\n    show \"subst_range \\<theta> \\<subseteq> insert (\\<delta> x) (subst_range \\<sigma>)\"\n    proof\n      fix t assume \"t \\<in> subst_range \\<theta>\"\n      then obtain y where \"y \\<in> subst_domain \\<theta>\" \"t = \\<theta> y\" by auto\n      thus \"t \\<in> insert (\\<delta> x) (subst_range \\<sigma>)\" using \\<theta> by (auto simp add: subst_domain_def)\n    qed\n    show \"insert (\\<delta> x) (subst_range \\<sigma>) \\<subseteq> subst_range \\<theta>\"\n    proof\n      fix t assume t: \"t \\<in> insert (\\<delta> x) (subst_range \\<sigma>)\"\n      hence \"fv t = {}\" using ground_imgs x_img(2) by auto\n      hence \"t \\<noteq> Var x\" by auto\n      show \"t \\<in> subst_range \\<theta>\"\n      proof (cases \"t = \\<delta> x\")\n        case True thus ?thesis using subst_imgI \\<theta> \\<open>t \\<noteq> Var x\\<close> by metis\n      next\n        case False\n        hence \"t \\<in> subst_range \\<sigma>\" using t by auto\n        then obtain y where \"\\<sigma> y \\<in> subst_range \\<sigma>\" \"t = \\<sigma> y\" by auto\n        hence \"y \\<in> subst_domain \\<sigma>\" \"t \\<noteq> Var y\"\n          using ground_subst_dom_iff_img[OF ground_imgs(1)]\n          by (auto simp add: subst_domain_def simp del: subst_range.simps)\n        hence \"x \\<noteq> y\" using x_dom by auto\n        hence \"\\<theta> y = \\<sigma> y\" unfolding \\<theta> by auto\n        thus ?thesis using \\<open>t \\<noteq> Var y\\<close> \\<open>t = \\<sigma> y\\<close> subst_imgI[of \\<theta> y] by auto\n      qed\n    qed\n  qed\n  hence \\<theta>_ground_img: \"ground (subst_range \\<theta>)\" using ground_imgs x_img by auto\n\n  have \"subst_domain \\<theta> = insert x S\" using \\<theta>_dom \\<sigma>(1) by auto\n  moreover have \"bij_betw \\<theta> (subst_domain \\<theta>) (subst_range \\<theta>)\"\n  proof (intro bij_betwI')\n    fix y z assume *: \"y \\<in> subst_domain \\<theta>\" \"z \\<in> subst_domain \\<theta>\"\n    hence \"fv (\\<theta> y) = {}\" \"fv (\\<theta> z) = {}\" using \\<theta>_ground_img by auto\n    { assume \"\\<theta> y = \\<theta> z\" hence \"y = z\"\n      proof (cases \"\\<theta> y \\<in> subst_range \\<sigma> \\<and> \\<theta> z \\<in> subst_range \\<sigma>\")\n        case True\n        hence **: \"y \\<in> subst_domain \\<sigma>\" \"z \\<in> subst_domain \\<sigma>\"\n          using \\<theta> \\<theta>_dom x_img(2) \\<delta>(3) True\n          by (metis (no_types) *(1) DiffE Un_upper2 insertE subsetCE,\n              metis (no_types) *(2) DiffE Un_upper2 insertE subsetCE)\n        hence \"y \\<noteq> x\" \"z \\<noteq> x\" using x_dom by auto\n        hence \"\\<theta> y = \\<sigma> y\" \"\\<theta> z = \\<sigma> z\" using \\<theta> by auto\n        thus ?thesis using \\<open>\\<theta> y = \\<theta> z\\<close> \\<sigma>(2) ** unfolding bij_betw_def inj_on_def by auto\n      qed (metis \\<theta> * \\<open>\\<theta> y = \\<theta> z\\<close> \\<theta>_dom ground_imgs(1) ground_subst_dom_iff_img insertE)\n    }\n    thus \"(\\<theta> y = \\<theta> z) = (y = z)\" by auto\n  next\n    fix y assume \"y \\<in> subst_domain \\<theta>\" thus \"\\<theta> y \\<in> subst_range \\<theta>\" by auto\n  next\n    fix t assume \"t \\<in> subst_range \\<theta>\" thus \"\\<exists>z \\<in> subst_domain \\<theta>. t = \\<theta> z\" by auto\n  qed\n  moreover have \"subst_range \\<theta> \\<subseteq> (\\<lambda>c. Fun c []) ` \\<C>\\<^sub>p\\<^sub>u\\<^sub>b - T\"\n    using \\<sigma>(3) \\<delta>(3) \\<theta> by (auto simp add: subst_domain_def)\n  moreover have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" using \\<sigma>(4) \\<delta>(4) \\<theta> unfolding wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def by auto\n  moreover have \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n    using \\<theta> \\<sigma>(5) \\<delta>(5) wf_trm_subst_range_iff[of \\<delta>]\n          wf_trm_subst_range_iff[of \\<sigma>] wf_trm_subst_range_iff[of \\<theta>]\n    by presburger\n  ultimately show ?case by blast\nqed\n\ntheorem wt_sat_if_simple:\n  assumes \"simple S\" \"wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r S \\<theta>\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t S)\"\n  and \\<I>': \"\\<forall>X F. Inequality X F \\<in> set S \\<longrightarrow> ineq_model \\<I>' X F\"\n         \"ground (subst_range \\<I>')\"\n         \"subst_domain \\<I>' = {x \\<in> vars\\<^sub>s\\<^sub>t S. \\<exists>X F. Inequality X F \\<in> set S \\<and> x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F - set X}\"\n  and tfr_stp_all: \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n  shows \"\\<exists>\\<I>. interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I> \\<and> (\\<I> \\<Turnstile>\\<^sub>c \\<langle>S, \\<theta>\\<rangle>) \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<I>)\"\nproof -\n  from \\<open>wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r S \\<theta>\\<close> have \"wf\\<^sub>s\\<^sub>t {} S\" \"subst_idem \\<theta>\" and S_\\<theta>_disj: \"\\<forall>v \\<in> vars\\<^sub>s\\<^sub>t S. \\<theta> v = Var v\"\n    using subst_idemI[of \\<theta>] unfolding wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r_def wf\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def by force+\n\n  obtain \\<I>::\"('fun,'var) subst\"\n    where \\<I>: \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\" \"subst_range \\<I> \\<subseteq> public_ground_wf_terms\"\n    using wt_interpretation_exists by blast\n  hence \\<I>_deduct: \"\\<And>x M. M \\<turnstile>\\<^sub>c \\<I> x\" and \\<I>_wf_trm: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<I>)\"\n    using pgwt_deducible pgwt_wellformed by fastforce+\n\n  let ?P = \"\\<lambda>\\<delta> X. subst_domain \\<delta> = set X \\<and> ground (subst_range \\<delta>)\"\n  let ?Sineqsvars = \"{x \\<in> vars\\<^sub>s\\<^sub>t S. \\<exists>X F. Inequality X F \\<in> set S \\<and> x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<and> x \\<notin> set X}\"\n  let ?Strms = \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t S)\"\n\n  have finite_vars: \"finite ?Sineqsvars\" \"finite ?Strms\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s ?Strms\"\n    using wf_trm_subtermeq assms(5) by fastforce+\n\n  define Q1 where \"Q1 = (\\<lambda>(F::(('fun,'var) term \\<times> ('fun,'var) term) list) X.\n    \\<forall>x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F - set X. \\<exists>a. \\<Gamma> (Var x) = TAtom a)\"\n\n  define Q2 where \"Q2 = (\\<lambda>(F::(('fun,'var) term \\<times> ('fun,'var) term) list) X.\n    \\<forall>f T. Fun f T \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F) \\<longrightarrow> T = [] \\<or> (\\<exists>s \\<in> set T. s \\<notin> Var ` set X))\"\n\n  define Q1' where \"Q1' = (\\<lambda>(t::('fun,'var) term) (t'::('fun,'var) term) X.\n    \\<forall>x \\<in> (fv t \\<union> fv t') - set X. \\<exists>a. \\<Gamma> (Var x) = TAtom a)\"\n\n  define Q2' where \"Q2' = (\\<lambda>(t::('fun,'var) term) (t'::('fun,'var) term) X.\n    \\<forall>f T. Fun f T \\<in> subterms t \\<union> subterms t' \\<longrightarrow> T = [] \\<or> (\\<exists>s \\<in> set T. s \\<notin> Var ` set X))\"\n\n  have ex_P: \"\\<forall>X. \\<exists>\\<delta>. ?P \\<delta> X\" using interpretation_subst_exists' by blast\n\n  have tfr_ineq: \"\\<forall>X F. Inequality X F \\<in> set S \\<longrightarrow> Q1 F X \\<or> Q2 F X\"\n    using tfr_stp_all Q1_def Q2_def tfr\\<^sub>s\\<^sub>t\\<^sub>p_list_all_alt_def[of S] by blast\n\n  have S_fv_bvars_disj: \"fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\" using \\<open>wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r S \\<theta>\\<close> unfolding wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r_def by metis\n  hence ineqs_vars_not_bound: \"\\<forall>X F x. Inequality X F \\<in> set S \\<longrightarrow> x \\<in> ?Sineqsvars \\<longrightarrow> x \\<notin> set X\"\n    using strand_fv_bvars_disjoint_unfold by blast\n\n  have \\<theta>_vars_S_bvars_disj: \"(subst_domain \\<theta> \\<union> range_vars \\<theta>) \\<inter> set X = {}\"\n    when \"Inequality X F \\<in> set S\" for F X\n    using wf_constr_bvars_disj[OF \\<open>wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r S \\<theta>\\<close>]\n          strand_fv_bvars_disjointD(1)[OF S_fv_bvars_disj that]\n    by blast\n\n  obtain \\<sigma>::\"('fun,'var) subst\"\n    where \\<sigma>_fv_dom: \"subst_domain \\<sigma> = ?Sineqsvars\"\n    and \\<sigma>_subterm_inj: \"subterm_inj_on \\<sigma> (subst_domain \\<sigma>)\"\n    and \\<sigma>_fresh_pub_img: \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (subst_range \\<sigma>) \\<subseteq> {t. {} \\<turnstile>\\<^sub>c t} - ?Strms\"\n    and \\<sigma>_wt: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma>\"\n    and \\<sigma>_wf_trm: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<sigma>)\"\n    using wt_bij_finite_subst_exists[OF finite_vars]\n          subst_inj_on_is_bij_betw subterm_inj_on_alt_def'\n    by moura\n\n  have \\<sigma>_bij_dom_img: \"bij_betw \\<sigma> (subst_domain \\<sigma>) (subst_range \\<sigma>)\"\n    by (metis \\<sigma>_subterm_inj subst_inj_on_is_bij_betw subterm_inj_on_alt_def)\n\n  have \"finite (subst_domain \\<sigma>)\" by(metis \\<sigma>_fv_dom finite_vars(1))\n  hence \\<sigma>_finite_img: \"finite (subst_range \\<sigma>)\" using \\<sigma>_bij_dom_img bij_betw_finite by blast\n\n  have \\<sigma>_img_subterms: \"\\<forall>s \\<in> subst_range \\<sigma>. \\<forall>u \\<in> subst_range \\<sigma>. (\\<exists>v. v \\<sqsubseteq> s \\<and> v \\<sqsubseteq> u) \\<longrightarrow> s = u\"\n    by (metis \\<sigma>_subterm_inj subterm_inj_on_alt_def')\n\n  have \"subst_range \\<sigma> \\<subseteq> subterms\\<^sub>s\\<^sub>e\\<^sub>t (subst_range \\<sigma>)\" by auto\n  hence \"subst_range \\<sigma> \\<subseteq> public_ground_wf_terms - ?Strms\"\n      and \\<sigma>_pgwt_img:\n        \"subst_range \\<sigma> \\<subseteq> public_ground_wf_terms\"\n        \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (subst_range \\<sigma>) \\<subseteq> public_ground_wf_terms\"\n    using \\<sigma>_fresh_pub_img pgwt_is_empty_synth by blast+\n\n  have \\<sigma>_img_ground: \"ground (subst_range \\<sigma>)\"\n    using \\<sigma>_pgwt_img pgwt_ground by auto\n  hence \\<sigma>_inj: \"inj \\<sigma>\"\n    using \\<sigma>_bij_dom_img subst_inj_is_bij_betw_dom_img_if_ground_img by auto\n\n  have \\<sigma>_ineqs_fv_dom: \"\\<And>X F. Inequality X F \\<in> set S \\<Longrightarrow> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F - set X \\<subseteq> subst_domain \\<sigma>\"\n    using \\<sigma>_fv_dom by fastforce\n\n  have \\<sigma>_dom_bvars_disj: \"\\<forall>X F. Inequality X F \\<in> set S \\<longrightarrow> subst_domain \\<sigma> \\<inter> set X = {}\"\n    using ineqs_vars_not_bound \\<sigma>_fv_dom by fastforce\n\n  have \\<I>'1: \"\\<forall>X F \\<delta>. Inequality X F \\<in> set S \\<longrightarrow> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F - set X \\<subseteq> subst_domain \\<I>'\"\n    using \\<I>'(3) ineqs_vars_not_bound by fastforce\n\n  have \\<I>'2: \"\\<forall>X F. Inequality X F \\<in> set S \\<longrightarrow> subst_domain \\<I>' \\<inter> set X = {}\"\n    using \\<I>'(3) ineqs_vars_not_bound by blast\n\n  have doms_eq: \"subst_domain \\<I>' = subst_domain \\<sigma>\" using \\<I>'(3) \\<sigma>_fv_dom by simp\n\n  have \\<sigma>_ineqs_neq: \"ineq_model \\<sigma> X F\" when \"Inequality X F \\<in> set S\" for X F\n  proof -\n    obtain a::\"'fun\" where a: \"a \\<notin> \\<Union>(funs_term ` subterms\\<^sub>s\\<^sub>e\\<^sub>t (subst_range \\<sigma>))\"\n      using exists_fun_notin_funs_terms[OF subterms_union_finite[OF \\<sigma>_finite_img]]\n      by moura\n    hence a': \"\\<And>T. Fun a T \\<notin> subterms\\<^sub>s\\<^sub>e\\<^sub>t (subst_range \\<sigma>)\"\n              \"\\<And>S. Fun a [] \\<in> set (Fun a []#S)\" \"Fun a [] \\<notin> Var ` set X\"\n      by (meson a UN_I term.set_intros(1), auto)\n\n    define t where \"t \\<equiv> Fun a (Fun a []#map fst F)\"\n    define t' where \"t' \\<equiv> Fun a (Fun a []#map snd F)\"\n\n    note F_in = that\n\n    have t_fv: \"fv t \\<union> fv t' \\<subseteq> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F\"\n      unfolding t_def t'_def by force\n\n    have t_subterms: \"subterms t \\<union> subterms t' \\<subseteq> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F) \\<union> {t, t', Fun a []}\"\n      unfolding t_def t'_def by force\n\n    have \"t \\<cdot> \\<delta> \\<cdot> \\<sigma> \\<noteq> t' \\<cdot> \\<delta> \\<cdot> \\<sigma>\" when \"?P \\<delta> X\" for \\<delta>\n    proof -\n      have tfr_assms: \"Q1 F X \\<or> Q2 F X\" using tfr_ineq F_in by metis\n\n      have \"Q1 F X \\<Longrightarrow> \\<forall>x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F - set X. \\<exists>c. \\<sigma> x = Fun c []\"\n      proof\n        fix x assume \"Q1 F X\" and x: \"x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F - set X\"\n        then obtain a where \"\\<Gamma> (Var x) = TAtom a\" unfolding Q1_def by moura\n        hence a: \"\\<Gamma> (\\<sigma> x) = TAtom a\" using \\<sigma>_wt unfolding wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def by simp\n\n        have \"x \\<in> subst_domain \\<sigma>\" using \\<sigma>_ineqs_fv_dom x F_in by auto\n        then obtain f T where fT: \"\\<sigma> x = Fun f T\" by (meson \\<sigma>_img_ground ground_img_obtain_fun)\n        hence \"T = []\" using \\<sigma>_wf_trm a TAtom_term_cases by fastforce\n        thus \"\\<exists>c. \\<sigma> x = Fun c []\" using fT by metis\n      qed\n      hence 1: \"Q1 F X \\<Longrightarrow> \\<forall>x \\<in> (fv t \\<union> fv t') - set X. \\<exists>c. \\<sigma> x = Fun c []\"\n        using t_fv by auto\n\n      have 2: \"\\<not>Q1 F X \\<Longrightarrow> Q2 F X\" by (metis tfr_assms)\n\n      have 3: \"subst_domain \\<sigma> \\<inter> set X = {}\" using \\<sigma>_dom_bvars_disj F_in by auto\n\n      have 4: \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (subst_range \\<sigma>) \\<inter> (subterms t \\<union> subterms t') = {}\"\n      proof -\n        define M1 where \"M1 \\<equiv> {t, t', Fun a []}\"\n        define M2 where \"M2 \\<equiv> ?Strms\"\n\n        have \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F) \\<subseteq> M2\"\n          using F_in unfolding M2_def by force\n        moreover have \"subterms t \\<union> subterms t' \\<subseteq> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F) \\<union> M1\"\n          using t_subterms unfolding M1_def by blast\n        ultimately have *: \"subterms t \\<union> subterms t' \\<subseteq> M2 \\<union> M1\"\n          by auto\n\n        have \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (subst_range \\<sigma>) \\<inter> M1 = {}\"\n             \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (subst_range \\<sigma>) \\<inter> M2 = {}\"\n          using a' \\<sigma>_fresh_pub_img\n          unfolding t_def t'_def M1_def M2_def\n          by blast+\n        thus ?thesis using * by blast\n      qed\n\n      have 5: \"(fv t \\<union> fv t') - subst_domain \\<sigma> \\<subseteq> set X\"\n        using \\<sigma>_ineqs_fv_dom[OF F_in] t_fv\n        by auto\n\n      have 6: \"\\<forall>\\<delta>. ?P \\<delta> X \\<longrightarrow> t \\<cdot> \\<delta> \\<cdot> \\<I>' \\<noteq> t' \\<cdot> \\<delta> \\<cdot> \\<I>'\"\n        by (metis t_def t'_def \\<I>'(1) F_in ineq_model_singleE ineq_model_single_iff)\n\n      have 7: \"fv t \\<union> fv t' - set X \\<subseteq> subst_domain \\<I>'\" using \\<I>'1 F_in t_fv by force\n\n      have 8: \"subst_domain \\<I>' \\<inter> set X = {}\" using \\<I>'2 F_in by auto\n\n      have 9: \"Q1' t t' X\" when \"Q1 F X\"\n        using that t_fv\n        unfolding Q1_def Q1'_def t_def t'_def\n        by blast\n\n      have 10: \"Q2' t t' X\" when \"Q2 F X\" unfolding Q2'_def\n      proof (intro allI impI)\n        fix f T assume \"Fun f T \\<in> subterms t \\<union> subterms t'\"\n        moreover {\n          assume \"Fun f T \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F)\"\n          hence \"T = [] \\<or> (\\<exists>s\\<in>set T. s \\<notin> Var ` set X)\" by (metis Q2_def that)\n        } moreover {\n          assume \"Fun f T = t\" hence \"T = [] \\<or> (\\<exists>s\\<in>set T. s \\<notin> Var ` set X)\"\n            unfolding t_def using a'(2,3) by simp\n        } moreover {\n          assume \"Fun f T = t'\" hence \"T = [] \\<or> (\\<exists>s\\<in>set T. s \\<notin> Var ` set X)\"\n            unfolding t'_def using a'(2,3) by simp\n        } moreover {\n          assume \"Fun f T = Fun a []\" hence \"T = [] \\<or> (\\<exists>s\\<in>set T. s \\<notin> Var ` set X)\" by simp\n        } ultimately show \"T = [] \\<or> (\\<exists>s\\<in>set T. s \\<notin> Var ` set X)\" using t_subterms by blast\n      qed\n\n      note 11 = \\<sigma>_subterm_inj \\<sigma>_img_ground 3 4 5\n\n      note 12 = 6 7 8 \\<I>'(2) doms_eq\n\n      show \"t \\<cdot> \\<delta> \\<cdot> \\<sigma> \\<noteq> t' \\<cdot> \\<delta> \\<cdot> \\<sigma>\"\n        using 1 2 9 10 that sat_ineq_subterm_inj_subst[OF 11 _ 12]\n        unfolding Q1'_def Q2'_def by metis\n    qed\n    thus ?thesis by (metis t_def t'_def ineq_model_singleI ineq_model_single_iff)\n  qed\n\n  have \\<sigma>_ineqs_fv_dom': \"fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<delta>) \\<subseteq> subst_domain \\<sigma>\"\n    when \"Inequality X F \\<in> set S\" and \"?P \\<delta> X\" for F \\<delta> X\n    using \\<sigma>_ineqs_fv_dom[OF that(1)]\n  proof (induction F)\n    case (Cons g G)\n    obtain t t' where g: \"g = (t,t')\" by (metis surj_pair)\n    hence \"fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (g#G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<delta>)  = fv (t \\<cdot> \\<delta>) \\<union> fv (t' \\<cdot> \\<delta>) \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<delta>)\"\n          \"fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (g#G) = fv t \\<union> fv t' \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G\"\n      by (simp_all add: subst_apply_pairs_def)\n    moreover have \"fv (t \\<cdot> \\<delta>) = fv t - subst_domain \\<delta>\" \"fv (t' \\<cdot> \\<delta>) = fv t' - subst_domain \\<delta>\"\n      using g that(2) by (simp_all add: subst_fv_unfold_ground_img range_vars_alt_def)\n    moreover have \"fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<delta>) \\<subseteq> subst_domain \\<sigma>\" using Cons by auto\n    ultimately show ?case using Cons.prems that(2) by auto\n  qed (simp add: subst_apply_pairs_def)\n\n  have \\<sigma>_ineqs_ground: \"fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ((F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<delta>) \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<sigma>) = {}\"\n    when \"Inequality X F \\<in> set S\" and \"?P \\<delta> X\" for F \\<delta> X\n    using \\<sigma>_ineqs_fv_dom'[OF that]\n  proof (induction F)\n    case (Cons g G)\n    obtain t t' where g: \"g = (t,t')\" by (metis surj_pair)\n    hence \"fv (t \\<cdot> \\<delta>) \\<subseteq> subst_domain \\<sigma>\" \"fv (t' \\<cdot> \\<delta>) \\<subseteq> subst_domain \\<sigma>\"\n      using Cons.prems by (auto simp add: subst_apply_pairs_def)\n    hence \"fv (t \\<cdot> \\<delta> \\<cdot> \\<sigma>) = {}\" \"fv (t' \\<cdot> \\<delta> \\<cdot> \\<sigma>) = {}\"\n      using subst_fv_dom_ground_if_ground_img[OF _ \\<sigma>_img_ground] by metis+\n    thus ?case using g Cons by (auto simp add: subst_apply_pairs_def)\n  qed (simp add: subst_apply_pairs_def)\n\n  from \\<sigma>_pgwt_img \\<sigma>_ineqs_neq have \\<sigma>_deduct: \"M \\<turnstile>\\<^sub>c \\<sigma> x\" when \"x \\<in> subst_domain \\<sigma>\" for x M\n    using that pgwt_deducible by fastforce\n\n  { fix M::\"('fun,'var) terms\"\n    have \"\\<lbrakk>M; S\\<rbrakk>\\<^sub>c (\\<theta> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<I>)\"\n      using \\<open>wf\\<^sub>s\\<^sub>t {} S\\<close> \\<open>simple S\\<close> S_\\<theta>_disj \\<sigma>_ineqs_neq \\<sigma>_ineqs_fv_dom' \\<theta>_vars_S_bvars_disj\n    proof (induction S arbitrary: M rule: wf\\<^sub>s\\<^sub>t_simple_induct)\n      case (ConsSnd v S)\n      hence S_sat: \"\\<lbrakk>M; S\\<rbrakk>\\<^sub>c (\\<theta> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<I>)\" and \"\\<theta> v = Var v\" by auto\n      hence \"\\<And>M. M \\<turnstile>\\<^sub>c Var v \\<cdot> (\\<theta> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<I>)\"\n        using \\<I>_deduct \\<sigma>_deduct\n        by (metis ideduct_synth_subst_apply subst_apply_term.simps(1)\n                  subst_subst_compose trm_subst_ident')\n      thus ?case using strand_sem_append(1)[OF S_sat] by (metis strand_sem_c.simps(1,2))\n    next\n      case (ConsIneq X F S)\n      have dom_disj: \"subst_domain \\<theta> \\<inter> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F = {}\"\n        using ConsIneq.prems(1) subst_dom_vars_in_subst\n        by force\n      hence *: \"F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<theta> = F\" by blast\n\n      have **: \"ineq_model \\<sigma> X F\" by (meson ConsIneq.prems(2) in_set_conv_decomp)\n\n      have \"\\<And>x. x \\<in> vars\\<^sub>s\\<^sub>t S \\<Longrightarrow> x \\<in> vars\\<^sub>s\\<^sub>t (S@[Inequality X F])\"\n           \"\\<And>x. x \\<in> set S \\<Longrightarrow> x \\<in> set (S@[Inequality X F])\" by auto\n      hence IH: \"\\<lbrakk>M; S\\<rbrakk>\\<^sub>c (\\<theta> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<I>)\" by (metis ConsIneq.IH ConsIneq.prems(1,2,3,4))\n\n      have \"ineq_model (\\<sigma> \\<circ>\\<^sub>s \\<I>) X F\"\n      proof -\n        have \"fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<delta>) \\<subseteq> subst_domain \\<sigma>\" when \"?P \\<delta> X\" for \\<delta>\n          using ConsIneq.prems(3)[OF _ that] by simp\n        hence \"fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F - set X \\<subseteq> subst_domain \\<sigma>\"\n          using fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_subst_subset ex_P\n          by (metis Diff_subset_conv Un_commute)\n        thus ?thesis by (metis ineq_model_ground_subst[OF _ \\<sigma>_img_ground **])\n      qed\n      hence \"ineq_model (\\<theta> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<I>) X F\"\n        using * ineq_model_subst' subst_compose_assoc ConsIneq.prems(4)\n        by (metis UnCI list.set_intros(1) set_append)\n      thus ?case using IH by (auto simp add: ineq_model_def)\n    qed auto\n  }\n  moreover have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t (\\<theta> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<I>)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range (\\<theta> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<I>))\"\n    by (metis wt_subst_compose \\<open>wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\\<close> \\<open>wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma>\\<close> \\<open>wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\\<close>,\n        metis assms(4) \\<I>_wf_trm \\<sigma>_wf_trm wf_trm_subst subst_img_comp_subset')\n  ultimately show ?thesis\n    using interpretation_comp(1)[OF \\<open>interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\\<close>, of \"\\<theta> \\<circ>\\<^sub>s \\<sigma>\"]\n          subst_idem_support[OF \\<open>subst_idem \\<theta>\\<close>, of \"\\<sigma> \\<circ>\\<^sub>s \\<I>\"] subst_compose_assoc\n    unfolding constr_sem_c_def by metis\nqed\nend\n\n\nsubsubsection \\<open>Theorem: Type-flaw resistant constraints are well-typed satisfiable (composition-only)\\<close>\ntext \\<open>\n  There exists well-typed models of satisfiable type-flaw resistant constraints in the\n  semantics where the intruder is limited to composition only (i.e., he cannot perform\n  decomposition/analysis of deducible messages).\n\\<close>\ntheorem wt_attack_if_tfr_attack:\n  assumes \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\"\n    and \"\\<I> \\<Turnstile>\\<^sub>c \\<langle>S, \\<theta>\\<rangle>\"\n    and \"wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r S \\<theta>\"\n    and \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\"\n    and \"tfr\\<^sub>s\\<^sub>t S\"\n    and \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t S)\"\n    and \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n  obtains \\<I>\\<^sub>\\<tau> where \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\\<^sub>\\<tau>\"\n    and \"\\<I>\\<^sub>\\<tau> \\<Turnstile>\\<^sub>c \\<langle>S, \\<theta>\\<rangle>\"\n    and \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\\<^sub>\\<tau>\"\n    and \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<I>\\<^sub>\\<tau>)\"\nproof -\n  have tfr: \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t S)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t S)\" \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n    using assms(5,6) unfolding tfr\\<^sub>s\\<^sub>t_def by metis+\n  obtain S' \\<theta>' where *: \"simple S'\" \"(S,\\<theta>) \\<leadsto>\\<^sup>* (S',\\<theta>')\" \"\\<lbrakk>{}; S'\\<rbrakk>\\<^sub>c \\<I>\"\n    using LI_completeness[OF assms(3,2)] unfolding constr_sem_c_def\n    by (meson term.order_refl)\n  have **: \"wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r S' \\<theta>'\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>'\" \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S'\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t S')\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>')\"\n    using LI_preserves_welltypedness[OF *(2) assms(3,4,7) tfr]\n          LI_preserves_wellformedness[OF *(2) assms(3)]\n          LI_preserves_tfr[OF *(2) assms(3,4,7) tfr]\n    by metis+\n\n  define A where \"A \\<equiv> {x \\<in> vars\\<^sub>s\\<^sub>t S'. \\<exists>X F. Inequality X F \\<in> set S' \\<and> x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<and> x \\<notin> set X}\"\n  define B where \"B \\<equiv> UNIV - A\"\n\n  let ?\\<I> = \"rm_vars B \\<I>\"\n\n  have gr\\<I>: \"ground (subst_range \\<I>)\" \"ground (subst_range ?\\<I>)\"\n    using assms(1) rm_vars_img_subset[of B \\<I>] by (auto simp add: subst_domain_def)\n\n  { fix X F\n    assume \"Inequality X F \\<in> set S'\"\n    hence *: \"ineq_model \\<I> X F\"\n      using strand_sem_c_imp_ineq_model[OF *(3)]\n      by (auto simp del: subst_range.simps)\n    hence \"ineq_model ?\\<I> X F\"\n    proof -\n      { fix \\<delta>\n        assume 1: \"subst_domain \\<delta> = set X\" \"ground (subst_range \\<delta>)\"\n            and 2: \"list_ex (\\<lambda>f. fst f \\<cdot> \\<delta> \\<circ>\\<^sub>s \\<I> \\<noteq> snd f \\<cdot> \\<delta> \\<circ>\\<^sub>s \\<I>) F\"\n        have \"list_ex (\\<lambda>f. fst f \\<cdot> \\<delta> \\<circ>\\<^sub>s rm_vars B \\<I> \\<noteq> snd f \\<cdot> \\<delta> \\<circ>\\<^sub>s rm_vars B \\<I>) F\" using 2\n        proof (induction F)\n          case (Cons g G)\n          obtain t t' where g: \"g = (t,t')\" by (metis surj_pair)\n          thus ?case\n            using Cons Unifier_ground_rm_vars[OF gr\\<I>(1), of \"t \\<cdot> \\<delta>\" B \"t' \\<cdot> \\<delta>\"]\n            by auto\n        qed simp\n      } thus ?thesis using * unfolding ineq_model_def by simp\n    qed\n  } moreover have \"subst_domain \\<I> = UNIV\" using assms(1) by metis\n  hence \"subst_domain ?\\<I> = A\" using rm_vars_dom[of B \\<I>] B_def by blast\n  ultimately obtain \\<I>\\<^sub>\\<tau> where\n      \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\\<^sub>\\<tau>\" \"\\<I>\\<^sub>\\<tau> \\<Turnstile>\\<^sub>c \\<langle>S', \\<theta>'\\<rangle>\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\\<^sub>\\<tau>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<I>\\<^sub>\\<tau>)\"\n    using wt_sat_if_simple[OF *(1) **(1,2,5,4) _ gr\\<I>(2) _ **(3)] A_def\n    by (auto simp del: subst_range.simps)\n  thus ?thesis using that LI_soundness[OF assms(3) *(2)] by metis\nqed\n\ntext \\<open>\n  Contra-positive version: if a type-flaw resistant constraint does not have a well-typed model\n  then it is unsatisfiable\n\\<close>\ncorollary secure_if_wt_secure:\n  assumes \"\\<not>(\\<exists>\\<I>\\<^sub>\\<tau>. interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\\<^sub>\\<tau> \\<and> (\\<I>\\<^sub>\\<tau> \\<Turnstile>\\<^sub>c \\<langle>S, \\<theta>\\<rangle>) \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\\<^sub>\\<tau>)\"\n  and     \"wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r S \\<theta>\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"tfr\\<^sub>s\\<^sub>t S\"\n  and     \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t S)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n  shows \"\\<not>(\\<exists>\\<I>. interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I> \\<and> (\\<I> \\<Turnstile>\\<^sub>c \\<langle>S, \\<theta>\\<rangle>))\"\nusing wt_attack_if_tfr_attack[OF _ _ assms(2,3,4,5,6)] assms(1) by metis\n\nend\n\n\nsubsection \\<open>Lifting the Composition-Only Typing Result to the Full Intruder Model\\<close>\ncontext typed_model\nbegin\n\nsubsubsection \\<open>Analysis Invariance\\<close>\ndefinition (in typed_model) Ana_invar_subst where\n  \"Ana_invar_subst \\<M> \\<equiv>\n    (\\<forall>f T K M \\<delta>. Fun f T \\<in> (subterms\\<^sub>s\\<^sub>e\\<^sub>t \\<M>) \\<longrightarrow>\n                 Ana (Fun f T) = (K, M) \\<longrightarrow> Ana (Fun f T \\<cdot> \\<delta>) = (K \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta>, M \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta>))\"\n\nlemma (in typed_model) Ana_invar_subst_subset:\n  assumes \"Ana_invar_subst M\" \"N \\<subseteq> M\"\n  shows \"Ana_invar_subst N\"\nusing assms unfolding Ana_invar_subst_def by blast\n\nlemma (in typed_model) Ana_invar_substD:\n  assumes \"Ana_invar_subst \\<M>\"\n  and \"Fun f T \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t \\<M>\" \"Ana (Fun f T) = (K, M)\"\n  shows \"Ana (Fun f T \\<cdot> \\<I>) = (K \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<I>, M \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<I>)\"\nusing assms Ana_invar_subst_def by blast\n\nend\n\n\nsubsubsection \\<open>Preliminary Definitions\\<close>\ntext \\<open>Strands extended with \"decomposition steps\"\\<close>\ndatatype (funs\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p: 'a, vars\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p: 'b) extstrand_step =\n  Step   \"('a,'b) strand_step\"\n| Decomp \"('a,'b) term\"\n\ncontext typed_model\nbegin\n\ncontext\nbegin\nprivate fun trms\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p where\n  \"trms\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p (Step x) = trms\\<^sub>s\\<^sub>t\\<^sub>p x\"\n| \"trms\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p (Decomp t) = {t}\"\n\nprivate abbreviation trms\\<^sub>e\\<^sub>s\\<^sub>t where \"trms\\<^sub>e\\<^sub>s\\<^sub>t S \\<equiv> \\<Union>(trms\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p ` set S)\"\n\nprivate type_synonym ('a,'b) extstrand = \"('a,'b) extstrand_step list\"\nprivate type_synonym ('a,'b) extstrands = \"('a,'b) extstrand set\"\n\nprivate definition decomp::\"('fun,'var) term \\<Rightarrow> ('fun,'var) strand\" where\n  \"decomp t \\<equiv> (case (Ana t) of (K,T) \\<Rightarrow> send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#map Send K@map Receive T)\"\n\nprivate fun to_st where\n  \"to_st [] = []\"\n| \"to_st (Step x#S) = x#(to_st S)\"\n| \"to_st (Decomp t#S) = (decomp t)@(to_st S)\"\n\nprivate fun to_est where\n  \"to_est [] = []\"\n| \"to_est (x#S) = Step x#to_est S\"\n\nprivate abbreviation \"ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<equiv> ik\\<^sub>s\\<^sub>t (to_st A)\"\nprivate abbreviation \"wf\\<^sub>e\\<^sub>s\\<^sub>t V A \\<equiv> wf\\<^sub>s\\<^sub>t V (to_st A)\"\nprivate abbreviation \"assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A \\<equiv> assignment_rhs\\<^sub>s\\<^sub>t (to_st A)\"\nprivate abbreviation \"vars\\<^sub>e\\<^sub>s\\<^sub>t A \\<equiv> vars\\<^sub>s\\<^sub>t (to_st A)\"\nprivate abbreviation \"wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t A \\<equiv> wfrestrictedvars\\<^sub>s\\<^sub>t (to_st A)\"\nprivate abbreviation \"bvars\\<^sub>e\\<^sub>s\\<^sub>t A \\<equiv> bvars\\<^sub>s\\<^sub>t (to_st A)\"\nprivate abbreviation \"fv\\<^sub>e\\<^sub>s\\<^sub>t A \\<equiv> fv\\<^sub>s\\<^sub>t (to_st A)\"\nprivate abbreviation \"funs\\<^sub>e\\<^sub>s\\<^sub>t A \\<equiv> funs\\<^sub>s\\<^sub>t (to_st A)\"\n\nprivate definition wf\\<^sub>s\\<^sub>t\\<^sub>s'::\"('fun,'var) strands \\<Rightarrow> ('fun,'var) extstrand \\<Rightarrow> bool\" where\n  \"wf\\<^sub>s\\<^sub>t\\<^sub>s' \\<S> \\<A> \\<equiv> (\\<forall>S \\<in> \\<S>. wf\\<^sub>s\\<^sub>t (wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>) (dual\\<^sub>s\\<^sub>t S)) \\<and>\n                 (\\<forall>S \\<in> \\<S>. \\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}) \\<and>\n                 (\\<forall>S \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A> = {}) \\<and>\n                 (\\<forall>S \\<in> \\<S>. fv\\<^sub>s\\<^sub>t (to_st \\<A>) \\<inter> bvars\\<^sub>s\\<^sub>t S = {})\"\n\nprivate definition wf\\<^sub>s\\<^sub>t\\<^sub>s::\"('fun,'var) strands \\<Rightarrow> bool\" where\n  \"wf\\<^sub>s\\<^sub>t\\<^sub>s \\<S> \\<equiv> (\\<forall>S \\<in> \\<S>. wf\\<^sub>s\\<^sub>t {} (dual\\<^sub>s\\<^sub>t S)) \\<and> (\\<forall>S \\<in> \\<S>. \\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>s\\<^sub>t S' = {})\"\n\nprivate inductive well_analyzed::\"('fun,'var) extstrand \\<Rightarrow> bool\" where\n  Nil[simp]: \"well_analyzed []\"\n| Step: \"well_analyzed A \\<Longrightarrow> well_analyzed (A@[Step x])\"\n| Decomp: \"\\<lbrakk>well_analyzed A; t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A) - (Var ` \\<V>)\\<rbrakk>\n    \\<Longrightarrow> well_analyzed (A@[Decomp t])\"\n\nprivate fun subst_apply_extstrandstep (infix \"\\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p\" 51) where\n  \"subst_apply_extstrandstep (Step x) \\<theta> = Step (x \\<cdot>\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\"\n| \"subst_apply_extstrandstep (Decomp t) \\<theta> = Decomp (t \\<cdot> \\<theta>)\"\n\nprivate lemma subst_apply_extstrandstep'_simps[simp]:\n  \"(Step (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)) \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p \\<theta> = Step (send\\<langle>t \\<cdot> \\<theta>\\<rangle>\\<^sub>s\\<^sub>t)\"\n  \"(Step (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)) \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p \\<theta> = Step (receive\\<langle>t \\<cdot> \\<theta>\\<rangle>\\<^sub>s\\<^sub>t)\"\n  \"(Step (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t)) \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p \\<theta> = Step (\\<langle>a: (t \\<cdot> \\<theta>) \\<doteq> (t' \\<cdot> \\<theta>)\\<rangle>\\<^sub>s\\<^sub>t)\"\n  \"(Step (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t)) \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p \\<theta> = Step (\\<forall>X\\<langle>\\<or>\\<noteq>: (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<theta>)\\<rangle>\\<^sub>s\\<^sub>t)\"\nby simp_all\n\nprivate lemma vars\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p_subst_apply_simps[simp]:\n  \"vars\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p ((Step (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)) \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = fv (t \\<cdot> \\<theta>)\"\n  \"vars\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p ((Step (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)) \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = fv (t \\<cdot> \\<theta>)\"\n  \"vars\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p ((Step (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t)) \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = fv (t \\<cdot> \\<theta>) \\<union> fv (t' \\<cdot> \\<theta>)\"\n  \"vars\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p ((Step (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t)) \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = set X \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<theta>)\"\nby auto\n\nprivate definition subst_apply_extstrand (infix \"\\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t\" 51) where \"S \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<theta> \\<equiv> map (\\<lambda>x. x \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) S\"\n\nprivate abbreviation update\\<^sub>s\\<^sub>t::\"('fun,'var) strands \\<Rightarrow> ('fun,'var) strand \\<Rightarrow> ('fun,'var) strands\"\nwhere\n  \"update\\<^sub>s\\<^sub>t \\<S> S \\<equiv> (case S of Nil \\<Rightarrow> \\<S> - {S} | Cons _ S' \\<Rightarrow> insert S' (\\<S> - {S}))\"\n\nprivate inductive_set decomps\\<^sub>e\\<^sub>s\\<^sub>t::\n  \"('fun,'var) terms \\<Rightarrow> ('fun,'var) terms \\<Rightarrow> ('fun,'var) subst \\<Rightarrow> ('fun,'var) extstrands\"\n(* \\<M>: intruder knowledge\n   \\<N>: additional messages\n*)\nfor \\<M> and \\<N> and \\<I> where\n  Nil: \"[] \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t \\<M> \\<N> \\<I>\"\n| Decomp: \"\\<lbrakk>\\<D> \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t \\<M> \\<N> \\<I>; Fun f T \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (\\<M> \\<union> \\<N>);\n            Ana (Fun f T) = (K,M); M \\<noteq> [];\n            (\\<M> \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t \\<D>) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile>\\<^sub>c Fun f T \\<cdot> \\<I>;\n            \\<And>k. k \\<in> set K \\<Longrightarrow> (\\<M> \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t \\<D>) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile>\\<^sub>c k \\<cdot> \\<I>\\<rbrakk>\n            \\<Longrightarrow> \\<D>@[Decomp (Fun f T)] \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t \\<M> \\<N> \\<I>\"\n\nprivate fun decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t::\"('fun,'var) extstrand \\<Rightarrow> ('fun,'var) extstrand\" where\n  \"decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t [] = []\"\n| \"decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t (Decomp t#S) = decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t S\"\n| \"decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t (Step x#S) = Step x#(decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t S)\"\n\nprivate inductive sem\\<^sub>e\\<^sub>s\\<^sub>t_d::\"('fun,'var) terms \\<Rightarrow> ('fun,'var) subst \\<Rightarrow> ('fun,'var) extstrand \\<Rightarrow> bool\"\nwhere\n  Nil[simp]: \"sem\\<^sub>e\\<^sub>s\\<^sub>t_d M\\<^sub>0 \\<I> []\"\n| Send: \"sem\\<^sub>e\\<^sub>s\\<^sub>t_d M\\<^sub>0 \\<I> S \\<Longrightarrow> (ik\\<^sub>e\\<^sub>s\\<^sub>t S \\<union> M\\<^sub>0) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> t \\<cdot> \\<I> \\<Longrightarrow> sem\\<^sub>e\\<^sub>s\\<^sub>t_d M\\<^sub>0 \\<I> (S@[Step (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)])\"\n| Receive: \"sem\\<^sub>e\\<^sub>s\\<^sub>t_d M\\<^sub>0 \\<I> S \\<Longrightarrow> sem\\<^sub>e\\<^sub>s\\<^sub>t_d M\\<^sub>0 \\<I> (S@[Step (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)])\"\n| Equality: \"sem\\<^sub>e\\<^sub>s\\<^sub>t_d M\\<^sub>0 \\<I> S \\<Longrightarrow> t \\<cdot> \\<I> = t' \\<cdot> \\<I> \\<Longrightarrow> sem\\<^sub>e\\<^sub>s\\<^sub>t_d M\\<^sub>0 \\<I> (S@[Step (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t)])\"\n| Inequality: \"sem\\<^sub>e\\<^sub>s\\<^sub>t_d M\\<^sub>0 \\<I> S\n    \\<Longrightarrow> ineq_model \\<I> X F\n    \\<Longrightarrow> sem\\<^sub>e\\<^sub>s\\<^sub>t_d M\\<^sub>0 \\<I> (S@[Step (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t)])\"\n| Decompose: \"sem\\<^sub>e\\<^sub>s\\<^sub>t_d M\\<^sub>0 \\<I> S \\<Longrightarrow> (ik\\<^sub>e\\<^sub>s\\<^sub>t S \\<union> M\\<^sub>0) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> t \\<cdot> \\<I> \\<Longrightarrow> Ana t = (K, M)\n    \\<Longrightarrow> (\\<And>k. k \\<in> set K \\<Longrightarrow> (ik\\<^sub>e\\<^sub>s\\<^sub>t S \\<union> M\\<^sub>0) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> k \\<cdot> \\<I>) \\<Longrightarrow> sem\\<^sub>e\\<^sub>s\\<^sub>t_d M\\<^sub>0 \\<I> (S@[Decomp t])\"\n\nprivate inductive sem\\<^sub>e\\<^sub>s\\<^sub>t_c::\"('fun,'var) terms \\<Rightarrow> ('fun,'var) subst \\<Rightarrow> ('fun,'var) extstrand \\<Rightarrow> bool\"\nwhere\n  Nil[simp]: \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c M\\<^sub>0 \\<I> []\"\n| Send: \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c M\\<^sub>0 \\<I> S \\<Longrightarrow> (ik\\<^sub>e\\<^sub>s\\<^sub>t S \\<union> M\\<^sub>0) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile>\\<^sub>c t \\<cdot> \\<I> \\<Longrightarrow> sem\\<^sub>e\\<^sub>s\\<^sub>t_c M\\<^sub>0 \\<I> (S@[Step (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)])\"\n| Receive: \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c M\\<^sub>0 \\<I> S \\<Longrightarrow> sem\\<^sub>e\\<^sub>s\\<^sub>t_c M\\<^sub>0 \\<I> (S@[Step (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)])\"\n| Equality: \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c M\\<^sub>0 \\<I> S \\<Longrightarrow> t \\<cdot> \\<I> = t' \\<cdot> \\<I> \\<Longrightarrow> sem\\<^sub>e\\<^sub>s\\<^sub>t_c M\\<^sub>0 \\<I> (S@[Step (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t)])\"\n| Inequality: \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c M\\<^sub>0 \\<I> S\n    \\<Longrightarrow> ineq_model \\<I> X F\n    \\<Longrightarrow> sem\\<^sub>e\\<^sub>s\\<^sub>t_c M\\<^sub>0 \\<I> (S@[Step (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t)])\"\n| Decompose: \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c M\\<^sub>0 \\<I> S \\<Longrightarrow> (ik\\<^sub>e\\<^sub>s\\<^sub>t S \\<union> M\\<^sub>0) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile>\\<^sub>c t \\<cdot> \\<I> \\<Longrightarrow> Ana t = (K, M)\n    \\<Longrightarrow> (\\<And>k. k \\<in> set K \\<Longrightarrow> (ik\\<^sub>e\\<^sub>s\\<^sub>t S \\<union> M\\<^sub>0) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile>\\<^sub>c k \\<cdot> \\<I>) \\<Longrightarrow> sem\\<^sub>e\\<^sub>s\\<^sub>t_c M\\<^sub>0 \\<I> (S@[Decomp t])\"\n\n\nsubsubsection \\<open>Preliminary Lemmata\\<close>\nprivate lemma wf\\<^sub>s\\<^sub>t\\<^sub>s_wf\\<^sub>s\\<^sub>t\\<^sub>s':\n  \"wf\\<^sub>s\\<^sub>t\\<^sub>s \\<S> = wf\\<^sub>s\\<^sub>t\\<^sub>s' \\<S> []\"\nby (simp add: wf\\<^sub>s\\<^sub>t\\<^sub>s_def wf\\<^sub>s\\<^sub>t\\<^sub>s'_def)\n\nprivate lemma decomp_ik:\n  assumes \"Ana t = (K,M)\"\n  shows \"ik\\<^sub>s\\<^sub>t (decomp t) = set M\"\nusing ik_rcv_map[of _ M] ik_rcv_map'[of _ M]\nby (auto simp add: decomp_def inv_def assms)\n\nprivate lemma decomp_assignment_rhs_empty:\n  assumes \"Ana t = (K,M)\"\n  shows \"assignment_rhs\\<^sub>s\\<^sub>t (decomp t) = {}\"\nby (auto simp add: decomp_def inv_def assms)\n\nprivate lemma decomp_tfr\\<^sub>s\\<^sub>t\\<^sub>p:\n  \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (decomp t)\"\nby (auto simp add: decomp_def list_all_def)\n\nprivate lemma trms\\<^sub>e\\<^sub>s\\<^sub>t_ikI:\n  \"t \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<Longrightarrow> t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>e\\<^sub>s\\<^sub>t A)\"\nproof (induction A rule: to_st.induct)\n  case (2 x S) thus ?case by (cases x) auto\nnext\n  case (3 t' A)\n  obtain K M where Ana: \"Ana t' = (K,M)\" by (metis surj_pair)\n  show ?case using 3 decomp_ik[OF Ana] Ana_subterm[OF Ana] by auto\nqed simp\n\nprivate lemma trms\\<^sub>e\\<^sub>s\\<^sub>t_ik_assignment_rhsI:\n  \"t \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A \\<Longrightarrow> t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>e\\<^sub>s\\<^sub>t A)\"\nproof (induction A rule: to_st.induct)\n  case (2 x S) thus ?case\n  proof (cases x)\n    case (Equality ac t t') thus ?thesis using 2 by (cases ac) auto\n  qed auto\nnext\n  case (3 t' A)\n  obtain K M where Ana: \"Ana t' = (K,M)\" by (metis surj_pair)\n  show ?case\n    using 3 decomp_ik[OF Ana] decomp_assignment_rhs_empty[OF Ana] Ana_subterm[OF Ana]\n    by auto\nqed simp\n\nprivate lemma trms\\<^sub>e\\<^sub>s\\<^sub>t_ik_subtermsI:\n  assumes \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A)\"\n  shows \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>e\\<^sub>s\\<^sub>t A)\"\nproof -\n  obtain t' where \"t' \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t A\" \"t \\<sqsubseteq> t'\" using trms\\<^sub>e\\<^sub>s\\<^sub>t_ikI assms by auto\n  thus ?thesis by (meson contra_subsetD in_subterms_subset_Union trms\\<^sub>e\\<^sub>s\\<^sub>t_ikI)\nqed\n\nprivate lemma trms\\<^sub>e\\<^sub>s\\<^sub>tD:\n  assumes \"t \\<in> trms\\<^sub>e\\<^sub>s\\<^sub>t A\"\n  shows \"t \\<in> trms\\<^sub>s\\<^sub>t (to_st A)\"\nusing assms\nproof (induction A)\n  case (Cons a A)\n  obtain K M where Ana: \"Ana t = (K,M)\" by (metis surj_pair)\n  hence \"t \\<in> trms\\<^sub>s\\<^sub>t (decomp t)\" unfolding decomp_def by force\n  thus ?case using Cons.IH Cons.prems by (cases a) auto\nqed simp\n\nprivate lemma subst_apply_extstrand_nil[simp]:\n  \"[] \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<theta> = []\"\nby (simp add: subst_apply_extstrand_def)\n\nprivate lemma subst_apply_extstrand_singleton[simp]:\n  \"[Step (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)] \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<theta> = [Step (Receive (t \\<cdot> \\<theta>))]\"\n  \"[Step (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)] \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<theta> = [Step (Send (t \\<cdot> \\<theta>))]\"\n  \"[Step (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t)] \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<theta> = [Step (Equality a (t \\<cdot> \\<theta>) (t' \\<cdot> \\<theta>))]\"\n  \"[Decomp t] \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<theta> = [Decomp (t \\<cdot> \\<theta>)]\"\nunfolding subst_apply_extstrand_def by auto\n\nprivate lemma extstrand_subst_hom:\n  \"(S@S') \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<theta> = (S \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<theta>)@(S' \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<theta>)\" \"(x#S) \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<theta> = (x \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)#(S \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<theta>)\"\nunfolding subst_apply_extstrand_def by auto\n\nprivate lemma decomp_vars:\n  \"wfrestrictedvars\\<^sub>s\\<^sub>t (decomp t) = fv t\" \"vars\\<^sub>s\\<^sub>t (decomp t) = fv t\" \"bvars\\<^sub>s\\<^sub>t (decomp t) = {}\"\n  \"fv\\<^sub>s\\<^sub>t (decomp t) = fv t\"\nproof -\n  obtain K M where Ana: \"Ana t = (K,M)\" by (metis surj_pair)\n  hence \"decomp t = send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#map Send K@map Receive M\"\n    unfolding decomp_def by simp\n  moreover have \"\\<Union>(set (map fv K)) = fv\\<^sub>s\\<^sub>e\\<^sub>t (set K)\" \"\\<Union>(set (map fv M)) = fv\\<^sub>s\\<^sub>e\\<^sub>t (set M)\" by auto\n  moreover have \"fv\\<^sub>s\\<^sub>e\\<^sub>t (set K) \\<subseteq> fv t\" \"fv\\<^sub>s\\<^sub>e\\<^sub>t (set M) \\<subseteq> fv t\"\n    using Ana_subterm[OF Ana(1)] Ana_keys_fv[OF Ana(1)]\n    by (simp_all add: UN_least psubsetD subtermeq_vars_subset)\n  ultimately show\n      \"wfrestrictedvars\\<^sub>s\\<^sub>t (decomp t) = fv t\" \"vars\\<^sub>s\\<^sub>t (decomp t) = fv t\" \"bvars\\<^sub>s\\<^sub>t (decomp t) = {}\"\n      \"fv\\<^sub>s\\<^sub>t (decomp t) = fv t\"\n    by auto\nqed\n\nprivate lemma bvars\\<^sub>e\\<^sub>s\\<^sub>t_cons: \"bvars\\<^sub>e\\<^sub>s\\<^sub>t (x#X) = bvars\\<^sub>e\\<^sub>s\\<^sub>t [x] \\<union> bvars\\<^sub>e\\<^sub>s\\<^sub>t X\"\nby (cases x) auto\n\nprivate lemma bvars\\<^sub>e\\<^sub>s\\<^sub>t_append: \"bvars\\<^sub>e\\<^sub>s\\<^sub>t (A@B) = bvars\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> bvars\\<^sub>e\\<^sub>s\\<^sub>t B\"\nproof (induction A)\n  case (Cons x A) thus ?case using bvars\\<^sub>e\\<^sub>s\\<^sub>t_cons[of x \"A@B\"] bvars\\<^sub>e\\<^sub>s\\<^sub>t_cons[of x A] by force\nqed simp\n\nprivate lemma fv\\<^sub>e\\<^sub>s\\<^sub>t_cons: \"fv\\<^sub>e\\<^sub>s\\<^sub>t (x#X) = fv\\<^sub>e\\<^sub>s\\<^sub>t [x] \\<union> fv\\<^sub>e\\<^sub>s\\<^sub>t X\"\nby (cases x) auto\n\nprivate lemma fv\\<^sub>e\\<^sub>s\\<^sub>t_append: \"fv\\<^sub>e\\<^sub>s\\<^sub>t (A@B) = fv\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> fv\\<^sub>e\\<^sub>s\\<^sub>t B\"\nproof (induction A)\n  case (Cons x A) thus ?case using fv\\<^sub>e\\<^sub>s\\<^sub>t_cons[of x \"A@B\"] fv\\<^sub>e\\<^sub>s\\<^sub>t_cons[of x A] by auto\nqed simp\n\nprivate lemma bvars_decomp: \"bvars\\<^sub>e\\<^sub>s\\<^sub>t (A@[Decomp t]) = bvars\\<^sub>e\\<^sub>s\\<^sub>t A\" \"bvars\\<^sub>e\\<^sub>s\\<^sub>t (Decomp t#A) = bvars\\<^sub>e\\<^sub>s\\<^sub>t A\"\nusing bvars\\<^sub>e\\<^sub>s\\<^sub>t_append decomp_vars(3) by fastforce+\n\nprivate lemma bvars_decomp_rm: \"bvars\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A) = bvars\\<^sub>e\\<^sub>s\\<^sub>t A\"\nusing bvars_decomp by (induct A rule: decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t.induct) simp_all+\n\nprivate lemma fv_decomp_rm: \"fv\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A) \\<subseteq> fv\\<^sub>e\\<^sub>s\\<^sub>t A\"\nby (induct A rule: decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t.induct) auto\n\nprivate lemma ik_assignment_rhs_decomp_fv:\n  assumes \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A)\"\n  shows \"fv\\<^sub>e\\<^sub>s\\<^sub>t (A@[Decomp t]) = fv\\<^sub>e\\<^sub>s\\<^sub>t A\"\nproof -\n  have \"fv\\<^sub>e\\<^sub>s\\<^sub>t (A@[Decomp t]) = fv\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> fv t\" using fv\\<^sub>e\\<^sub>s\\<^sub>t_append decomp_vars by simp\n  moreover have \"fv\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A) \\<subseteq> fv\\<^sub>e\\<^sub>s\\<^sub>t A\" by force\n  moreover have \"fv t \\<subseteq> fv\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A)\"\n    using fv_subset_subterms[OF assms(1)] by simp\n  ultimately show ?thesis by blast\nqed\n\nprivate lemma wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t_decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_subset:\n  \"wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A) \\<subseteq> wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t A\"\nby (induct A rule: decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t.induct) auto+\n\nprivate lemma wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t_eq_wfrestrictedvars\\<^sub>s\\<^sub>t:\n  \"wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t A = wfrestrictedvars\\<^sub>s\\<^sub>t (to_st A)\"\nby simp\n\nprivate lemma decomp_set_unfold:\n  assumes \"Ana t = (K, M)\"\n  shows \"set (decomp t) = {send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t} \\<union> (Send ` set K) \\<union> (Receive ` set M)\"\nusing assms unfolding decomp_def by auto\n\nprivate lemma ik\\<^sub>e\\<^sub>s\\<^sub>t_finite: \"finite (ik\\<^sub>e\\<^sub>s\\<^sub>t A)\"\nby (rule finite_ik\\<^sub>s\\<^sub>t)\n\nprivate lemma assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_finite: \"finite (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A)\"\nby (rule finite_assignment_rhs\\<^sub>s\\<^sub>t)\n\nprivate lemma to_est_append: \"to_est (A@B) = to_est A@to_est B\"\nby (induct A rule: to_est.induct) auto\n\nprivate lemma to_st_to_est_inv: \"to_st (to_est A) = A\"\nby (induct A rule: to_est.induct) auto\n\nprivate lemma to_st_append: \"to_st (A@B) = (to_st A)@(to_st B)\"\nby (induct A rule: to_st.induct) auto\n\nprivate lemma to_st_cons: \"to_st (a#B) = (to_st [a])@(to_st B)\"\nusing to_st_append[of \"[a]\" B] by simp\n\nprivate lemma wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t_split:\n  \"wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t (x#S) = wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t [x] \\<union> wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t S\"\n  \"wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t (S@S') = wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t S \\<union> wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t S'\"\nusing to_st_cons[of x S] to_st_append[of S S'] by auto\n\nprivate lemma ik\\<^sub>e\\<^sub>s\\<^sub>t_append: \"ik\\<^sub>e\\<^sub>s\\<^sub>t (A@B) = ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t B\"\nby (metis ik_append to_st_append)\n\nprivate lemma assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append:\n  \"assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t (A@B) = assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t B\"\nby (metis assignment_rhs_append to_st_append)\n\nprivate lemma ik\\<^sub>e\\<^sub>s\\<^sub>t_cons: \"ik\\<^sub>e\\<^sub>s\\<^sub>t (a#A) = ik\\<^sub>e\\<^sub>s\\<^sub>t [a] \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t A\"\nby (metis ik_append to_st_cons)\n\nprivate lemma ik\\<^sub>e\\<^sub>s\\<^sub>t_append_subst:\n  \"ik\\<^sub>e\\<^sub>s\\<^sub>t (A@B \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<theta>) = ik\\<^sub>e\\<^sub>s\\<^sub>t (A \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<theta>) \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<theta>)\"\n  \"ik\\<^sub>e\\<^sub>s\\<^sub>t (A@B) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta> = (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t B \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>)\"\nby (metis ik\\<^sub>e\\<^sub>s\\<^sub>t_append extstrand_subst_hom(1), simp add: image_Un to_st_append)\n\nprivate lemma assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append_subst:\n  \"assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t (A@B \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<theta>) = assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t (A \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<theta>) \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<theta>)\"\n  \"assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t (A@B) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta> = (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t B \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>)\"\nby (metis assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append extstrand_subst_hom(1), use assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append in blast)\n\nprivate lemma ik\\<^sub>e\\<^sub>s\\<^sub>t_cons_subst:\n  \"ik\\<^sub>e\\<^sub>s\\<^sub>t (a#A \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<theta>) = ik\\<^sub>e\\<^sub>s\\<^sub>t ([a \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>]) \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t (A \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<theta>)\"\n  \"ik\\<^sub>e\\<^sub>s\\<^sub>t (a#A) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta> = (ik\\<^sub>e\\<^sub>s\\<^sub>t [a] \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>)\"\nby (metis ik\\<^sub>e\\<^sub>s\\<^sub>t_cons extstrand_subst_hom(2), metis image_Un ik\\<^sub>e\\<^sub>s\\<^sub>t_cons)\n\nprivate lemma decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append: \"decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t (S@S') = (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t S)@(decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t S')\"\nby (induct S rule: decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t.induct) auto\n\nprivate lemma decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_single[simp]:\n  \"decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t [Step (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)] = [Step (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)]\"\n  \"decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t [Step (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)] = [Step (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)]\"\n  \"decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t [Decomp t] = []\"\nby auto\n\nprivate lemma decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_ik_subset: \"ik\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t S) \\<subseteq> ik\\<^sub>e\\<^sub>s\\<^sub>t S\"\nproof (induction S rule: decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t.induct)\n  case (3 x S) thus ?case by (cases x) auto\nqed auto\n\nprivate lemma decomps\\<^sub>e\\<^sub>s\\<^sub>t_ik_subset: \"D \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t M N \\<I> \\<Longrightarrow> ik\\<^sub>e\\<^sub>s\\<^sub>t D \\<subseteq> subterms\\<^sub>s\\<^sub>e\\<^sub>t (M \\<union> N)\"\nproof (induction D rule: decomps\\<^sub>e\\<^sub>s\\<^sub>t.induct)\n  case (Decomp D f T K M')\n  have \"ik\\<^sub>s\\<^sub>t (decomp (Fun f T)) \\<subseteq> subterms (Fun f T)\"\n       \"ik\\<^sub>s\\<^sub>t (decomp (Fun f T)) = ik\\<^sub>e\\<^sub>s\\<^sub>t [Decomp (Fun f T)]\"\n    using decomp_ik[OF Decomp.hyps(3)] Ana_subterm[OF Decomp.hyps(3)]\n    by auto\n  hence \"ik\\<^sub>s\\<^sub>t (to_st [Decomp (Fun f T)]) \\<subseteq> subterms\\<^sub>s\\<^sub>e\\<^sub>t (M \\<union> N)\"\n    using in_subterms_subset_Union[OF Decomp.hyps(2)]\n    by blast\n  thus ?case using ik\\<^sub>e\\<^sub>s\\<^sub>t_append[of D \"[Decomp (Fun f T)]\"] using Decomp.IH by auto\nqed simp\n\nprivate lemma decomps\\<^sub>e\\<^sub>s\\<^sub>t_decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_empty: \"D \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t M N \\<I> \\<Longrightarrow> decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t D = []\"\nby (induct D rule: decomps\\<^sub>e\\<^sub>s\\<^sub>t.induct) (auto simp add: decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append)\n\nprivate lemma decomps\\<^sub>e\\<^sub>s\\<^sub>t_append:\n  assumes \"A \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t S N \\<I>\" \"B \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t S N \\<I>\"\n  shows \"A@B \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t S N \\<I>\"\nusing assms(2)\nproof (induction B rule: decomps\\<^sub>e\\<^sub>s\\<^sub>t.induct)\n  case Nil show ?case using assms(1) by simp\nnext\n  case (Decomp B f X K T)\n  hence \"S \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t B \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<subseteq> S \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t (A@B) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" using ik\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\n  thus ?case\n    using decomps\\<^sub>e\\<^sub>s\\<^sub>t.Decomp[OF Decomp.IH(1) Decomp.hyps(2,3,4)]\n          ideduct_synth_mono[OF Decomp.hyps(5)]\n          ideduct_synth_mono[OF Decomp.hyps(6)]\n    by auto\nqed\n\nprivate lemma decomps\\<^sub>e\\<^sub>s\\<^sub>t_subterms:\n  assumes \"A' \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t M N \\<I>\"\n  shows \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A') \\<subseteq> subterms\\<^sub>s\\<^sub>e\\<^sub>t (M \\<union> N)\"\nusing assms\nproof (induction A' rule: decomps\\<^sub>e\\<^sub>s\\<^sub>t.induct)\n  case (Decomp D f X K T)\n  hence \"Fun f X \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (M \\<union> N)\" by auto\n  hence \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (set X) \\<subseteq> subterms\\<^sub>s\\<^sub>e\\<^sub>t (M \\<union> N)\"\n    using in_subterms_subset_Union[of \"Fun f X\" \"M \\<union> N\"] params_subterms_Union[of X f]\n    by blast\n  moreover have \"ik\\<^sub>s\\<^sub>t (to_st [Decomp (Fun f X)]) = set T\" using Decomp.hyps(3) decomp_ik by simp\n  hence \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>s\\<^sub>t (to_st [Decomp (Fun f X)])) \\<subseteq> subterms\\<^sub>s\\<^sub>e\\<^sub>t (set X)\"\n    using Ana_fun_subterm[OF Decomp.hyps(3)] by auto\n  ultimately show ?case\n    using ik\\<^sub>e\\<^sub>s\\<^sub>t_append[of D \"[Decomp (Fun f X)]\"] Decomp.IH\n    by auto\nqed simp\n\nprivate lemma decomps\\<^sub>e\\<^sub>s\\<^sub>t_assignment_rhs_empty:\n  assumes \"A' \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t M N \\<I>\"\n  shows \"assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A' = {}\"\nusing assms\nby (induction A' rule: decomps\\<^sub>e\\<^sub>s\\<^sub>t.induct)\n   (simp_all add: decomp_assignment_rhs_empty assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append)\n\nprivate lemma decomps\\<^sub>e\\<^sub>s\\<^sub>t_finite_ik_append:\n  assumes \"finite M\" \"M \\<subseteq> decomps\\<^sub>e\\<^sub>s\\<^sub>t A N \\<I>\"\n  shows \"\\<exists>D \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t A N \\<I>. ik\\<^sub>e\\<^sub>s\\<^sub>t D = (\\<Union>m \\<in> M. ik\\<^sub>e\\<^sub>s\\<^sub>t m)\"\nusing assms\nproof (induction M rule: finite_induct)\n  case empty\n  moreover have \"[] \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t A N \\<I>\" \"ik\\<^sub>s\\<^sub>t (to_st []) = {}\" using decomps\\<^sub>e\\<^sub>s\\<^sub>t.Nil by auto\n  ultimately show ?case by blast\nnext\n  case (insert m M)\n  then obtain D where \"D \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t A N \\<I>\" \"ik\\<^sub>e\\<^sub>s\\<^sub>t D = (\\<Union>m\\<in>M. ik\\<^sub>s\\<^sub>t (to_st m))\" by moura\n  moreover have \"m \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t A N \\<I>\" using insert.prems(1) by blast\n  ultimately show ?case using decomps\\<^sub>e\\<^sub>s\\<^sub>t_append[of D A N \\<I> m] ik\\<^sub>e\\<^sub>s\\<^sub>t_append[of D m] by blast\nqed\n\nprivate lemma decomp_snd_exists[simp]: \"\\<exists>D. decomp t = send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#D\"\nby (metis (mono_tags, lifting) decomp_def prod.case surj_pair)\n\nprivate lemma decomp_nonnil[simp]: \"decomp t \\<noteq> []\"\nusing decomp_snd_exists[of t] by fastforce\n\nprivate lemma to_st_nil_inv[dest]: \"to_st A = [] \\<Longrightarrow> A = []\"\nby (induct A rule: to_st.induct) auto\n\nprivate lemma well_analyzedD:\n  assumes \"well_analyzed A\" \"Decomp t \\<in> set A\"\n  shows \"\\<exists>f T. t = Fun f T\"\nusing assms\nproof (induction A rule: well_analyzed.induct)\n  case (Decomp A t')\n  hence \"\\<exists>f T. t' = Fun f T\" by (cases t') auto\n  moreover have \"Decomp t \\<in> set A \\<or> t = t'\" using Decomp by auto\n  ultimately show ?case using Decomp.IH by auto\nqed auto\n\nprivate lemma well_analyzed_inv:\n  assumes \"well_analyzed (A@[Decomp t])\"\n  shows \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A) - (Var ` \\<V>)\"\nusing assms well_analyzed.cases[of \"A@[Decomp t]\"] by fastforce\n\nprivate lemma well_analyzed_split_left_single: \"well_analyzed (A@[a]) \\<Longrightarrow> well_analyzed A\"\nby (induction \"A@[a]\" rule: well_analyzed.induct) auto\n\nprivate lemma well_analyzed_split_left: \"well_analyzed (A@B) \\<Longrightarrow> well_analyzed A\"\nproof (induction B rule: List.rev_induct)\n  case (snoc b B) thus ?case using well_analyzed_split_left_single[of \"A@B\" b] by simp\nqed simp\n\nprivate lemma well_analyzed_append:\n  assumes \"well_analyzed A\" \"well_analyzed B\"\n  shows \"well_analyzed (A@B)\"\nusing assms(2,1)\nproof (induction B rule: well_analyzed.induct)\n  case (Step B x) show ?case using well_analyzed.Step[OF Step.IH[OF Step.prems]] by simp\nnext\n  case (Decomp B t) thus ?case\n    using well_analyzed.Decomp[OF Decomp.IH[OF Decomp.prems]] ik\\<^sub>e\\<^sub>s\\<^sub>t_append assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append\n    by auto\nqed simp_all\n\nprivate lemma well_analyzed_singleton:\n  \"well_analyzed [Step (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)]\" \"well_analyzed [Step (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)]\"\n  \"well_analyzed [Step (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t)]\" \"well_analyzed [Step (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t)]\"\n  \"\\<not>well_analyzed [Decomp t]\"\nproof -\n  show \"well_analyzed [Step (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)]\" \"well_analyzed [Step (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)]\"\n       \"well_analyzed [Step (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t)]\" \"well_analyzed [Step (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t)]\"\n    using well_analyzed.Step[OF well_analyzed.Nil]\n    by simp_all\n\n  show \"\\<not>well_analyzed [Decomp t]\" using well_analyzed.cases[of \"[Decomp t]\"] by auto\nqed\n\nprivate lemma well_analyzed_decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_fv: \"well_analyzed A \\<Longrightarrow> fv\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A) = fv\\<^sub>e\\<^sub>s\\<^sub>t A\"\nproof\n  assume \"well_analyzed A\" thus \"fv\\<^sub>e\\<^sub>s\\<^sub>t A \\<subseteq> fv\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A)\"\n  proof (induction A rule: well_analyzed.induct)\n    case Decomp thus ?case using ik_assignment_rhs_decomp_fv decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\n  next\n    case (Step A x)\n    have \"fv\\<^sub>e\\<^sub>s\\<^sub>t (A@[Step x]) = fv\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> fv\\<^sub>s\\<^sub>t\\<^sub>p x\"\n         \"fv\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t (A@[Step x])) = fv\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A) \\<union> fv\\<^sub>s\\<^sub>t\\<^sub>p x\"\n      using fv\\<^sub>e\\<^sub>s\\<^sub>t_append decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\n    thus ?case using Step by auto\n  qed simp\nqed (rule fv_decomp_rm)\n\nprivate lemma sem\\<^sub>e\\<^sub>s\\<^sub>t_d_split_left: assumes \"sem\\<^sub>e\\<^sub>s\\<^sub>t_d M\\<^sub>0 \\<I> (\\<A>@\\<A>')\" shows \"sem\\<^sub>e\\<^sub>s\\<^sub>t_d M\\<^sub>0 \\<I> \\<A>\"\nusing assms sem\\<^sub>e\\<^sub>s\\<^sub>t_d.cases by (induction \\<A>' rule: List.rev_induct) fastforce+\n\nprivate lemma sem\\<^sub>e\\<^sub>s\\<^sub>t_d_eq_sem_st: \"sem\\<^sub>e\\<^sub>s\\<^sub>t_d M\\<^sub>0 \\<I> \\<A> = \\<lbrakk>M\\<^sub>0; to_st \\<A>\\<rbrakk>\\<^sub>d' \\<I>\"\nproof\n  show \"\\<lbrakk>M\\<^sub>0; to_st \\<A>\\<rbrakk>\\<^sub>d' \\<I> \\<Longrightarrow> sem\\<^sub>e\\<^sub>s\\<^sub>t_d M\\<^sub>0 \\<I> \\<A>\"\n  proof (induction \\<A> arbitrary: M\\<^sub>0 rule: List.rev_induct)\n    case Nil show ?case using to_st_nil_inv by simp\n  next\n    case (snoc a \\<A>)\n    hence IH: \"sem\\<^sub>e\\<^sub>s\\<^sub>t_d M\\<^sub>0 \\<I> \\<A>\" and *: \"\\<lbrakk>ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A> \\<union> M\\<^sub>0; to_st [a]\\<rbrakk>\\<^sub>d' \\<I>\"\n      using to_st_append by (auto simp add: sup.commute)\n    thus ?case using snoc\n    proof (cases a)\n      case (Step b) thus ?thesis\n      proof (cases b)\n        case (Send t) thus ?thesis using sem\\<^sub>e\\<^sub>s\\<^sub>t_d.Send[OF IH] * Step by auto\n      next\n        case (Receive t) thus ?thesis using sem\\<^sub>e\\<^sub>s\\<^sub>t_d.Receive[OF IH] Step by auto\n      next\n        case (Equality a t t') thus ?thesis using sem\\<^sub>e\\<^sub>s\\<^sub>t_d.Equality[OF IH] * Step by auto\n      next\n        case (Inequality X F) thus ?thesis using sem\\<^sub>e\\<^sub>s\\<^sub>t_d.Inequality[OF IH] * Step by auto\n      qed\n    next\n      case (Decomp t)\n      obtain K M where Ana: \"Ana t = (K,M)\" by moura\n      have \"to_st [a] = decomp t\" using Decomp by auto\n      hence \"to_st [a] = send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#map Send K@map Receive M\"\n        using Ana unfolding decomp_def by auto\n      hence **: \"ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A> \\<union> M\\<^sub>0 \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> t \\<cdot> \\<I>\" and \"\\<lbrakk>ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A> \\<union> M\\<^sub>0; map Send K\\<rbrakk>\\<^sub>d' \\<I>\"\n        using * by auto\n      hence \"\\<And>k. k \\<in> set K \\<Longrightarrow> ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A> \\<union> M\\<^sub>0 \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> k \\<cdot> \\<I>\"\n        using *\n        by (metis (full_types) strand_sem_d.simps(2) strand_sem_eq_defs(2) strand_sem_Send_split(2))\n      thus ?thesis using Decomp sem\\<^sub>e\\<^sub>s\\<^sub>t_d.Decompose[OF IH ** Ana] by metis\n    qed\n  qed\n\n  show \"sem\\<^sub>e\\<^sub>s\\<^sub>t_d M\\<^sub>0 \\<I> \\<A> \\<Longrightarrow> \\<lbrakk>M\\<^sub>0; to_st \\<A>\\<rbrakk>\\<^sub>d' \\<I>\"\n  proof (induction rule: sem\\<^sub>e\\<^sub>s\\<^sub>t_d.induct)\n    case Nil thus ?case by simp\n  next\n    case (Send M\\<^sub>0 \\<I> \\<A> t) thus ?case\n      using strand_sem_append'[of M\\<^sub>0 \"to_st \\<A>\" \\<I> \"[send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t]\"]\n            to_st_append[of \\<A> \"[Step (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)]\"]\n      by (simp add: sup.commute)\n  next\n    case (Receive M\\<^sub>0 \\<I> \\<A> t) thus ?case\n      using strand_sem_append'[of M\\<^sub>0 \"to_st \\<A>\" \\<I> \"[receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t]\"]\n            to_st_append[of \\<A> \"[Step (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)]\"]\n      by (simp add: sup.commute)\n  next\n    case (Equality M\\<^sub>0 \\<I> \\<A> t t' a) thus ?case\n      using strand_sem_append'[of M\\<^sub>0 \"to_st \\<A>\" \\<I> \"[\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t]\"]\n            to_st_append[of \\<A> \"[Step (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t)]\"]\n      by (simp add: sup.commute)\n  next\n    case (Inequality M\\<^sub>0 \\<I> \\<A> X F) thus ?case\n      using strand_sem_append'[of M\\<^sub>0 \"to_st \\<A>\" \\<I> \"[\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t]\"]\n            to_st_append[of \\<A> \"[Step (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t)]\"]\n      by (simp add: sup.commute)\n  next\n    case (Decompose M\\<^sub>0 \\<I> \\<A> t K M)\n    have \"\\<lbrakk>M\\<^sub>0 \\<union> ik\\<^sub>s\\<^sub>t (to_st \\<A>); decomp t\\<rbrakk>\\<^sub>d' \\<I>\"\n    proof -\n      have \"\\<lbrakk>M\\<^sub>0 \\<union> ik\\<^sub>s\\<^sub>t (to_st \\<A>); [send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t]\\<rbrakk>\\<^sub>d' \\<I>\"\n        using Decompose.hyps(2) by (auto simp add: sup.commute)\n      moreover have \"\\<And>k. k \\<in> set K \\<Longrightarrow> M\\<^sub>0 \\<union> ik\\<^sub>s\\<^sub>t (to_st \\<A>) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> k \\<cdot> \\<I>\"\n        using Decompose by (metis sup.commute)\n      hence \"\\<And>k. k \\<in> set K \\<Longrightarrow> \\<lbrakk>M\\<^sub>0 \\<union> ik\\<^sub>s\\<^sub>t (to_st \\<A>); [Send k]\\<rbrakk>\\<^sub>d' \\<I>\" by auto\n      hence \"\\<lbrakk>M\\<^sub>0 \\<union> ik\\<^sub>s\\<^sub>t (to_st \\<A>); map Send K\\<rbrakk>\\<^sub>d' \\<I>\"\n        using strand_sem_Send_map(2)[of K, of \"M\\<^sub>0 \\<union> ik\\<^sub>s\\<^sub>t (to_st \\<A>) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" \\<I>] strand_sem_eq_defs(2)\n        by auto\n      moreover have \"\\<lbrakk>M\\<^sub>0 \\<union> ik\\<^sub>s\\<^sub>t (to_st \\<A>); map Receive M\\<rbrakk>\\<^sub>d' \\<I>\"\n        by (metis strand_sem_Receive_map(2) strand_sem_eq_defs(2))\n      ultimately have\n          \"\\<lbrakk>M\\<^sub>0 \\<union> ik\\<^sub>s\\<^sub>t (to_st \\<A>); send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#map Send K@map Receive M\\<rbrakk>\\<^sub>d' \\<I>\"\n        by auto\n      thus ?thesis using Decompose.hyps(3) unfolding decomp_def by auto\n    qed\n    hence \"\\<lbrakk>M\\<^sub>0; to_st \\<A>@decomp t\\<rbrakk>\\<^sub>d' \\<I>\"\n      using strand_sem_append'[of M\\<^sub>0 \"to_st \\<A>\" \\<I> \"decomp t\"] Decompose.IH\n      by simp\n    thus ?case using to_st_append[of \\<A> \"[Decomp t]\"] by simp\n  qed\nqed\n\nprivate lemma sem\\<^sub>e\\<^sub>s\\<^sub>t_c_eq_sem_st: \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c M\\<^sub>0 \\<I> \\<A> = \\<lbrakk>M\\<^sub>0; to_st \\<A>\\<rbrakk>\\<^sub>c' \\<I>\"\nproof\n  show \"\\<lbrakk>M\\<^sub>0; to_st \\<A>\\<rbrakk>\\<^sub>c' \\<I> \\<Longrightarrow> sem\\<^sub>e\\<^sub>s\\<^sub>t_c M\\<^sub>0 \\<I> \\<A>\"\n  proof (induction \\<A> arbitrary: M\\<^sub>0 rule: List.rev_induct)\n    case Nil show ?case using to_st_nil_inv by simp\n  next\n    case (snoc a \\<A>)\n    hence IH: \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c M\\<^sub>0 \\<I> \\<A>\" and *: \"\\<lbrakk>ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A> \\<union> M\\<^sub>0; to_st [a]\\<rbrakk>\\<^sub>c' \\<I>\"\n      using to_st_append\n      by (auto simp add: sup.commute)\n    thus ?case using snoc\n    proof (cases a)\n      case (Step b) thus ?thesis\n      proof (cases b)\n        case (Send t) thus ?thesis using sem\\<^sub>e\\<^sub>s\\<^sub>t_c.Send[OF IH] * Step by auto\n      next\n        case (Receive t) thus ?thesis using sem\\<^sub>e\\<^sub>s\\<^sub>t_c.Receive[OF IH] Step by auto\n      next\n        case (Equality t) thus ?thesis using sem\\<^sub>e\\<^sub>s\\<^sub>t_c.Equality[OF IH] * Step by auto\n      next\n        case (Inequality t) thus ?thesis using sem\\<^sub>e\\<^sub>s\\<^sub>t_c.Inequality[OF IH] * Step by auto\n      qed\n    next\n      case (Decomp t)\n      obtain K M where Ana: \"Ana t = (K,M)\" by moura\n      have \"to_st [a] = decomp t\" using Decomp by auto\n      hence \"to_st [a] = send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#map Send K@map Receive M\"\n        using Ana unfolding decomp_def by auto\n      hence **: \"ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A> \\<union> M\\<^sub>0 \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile>\\<^sub>c t \\<cdot> \\<I>\" and \"\\<lbrakk>ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A> \\<union> M\\<^sub>0; map Send K\\<rbrakk>\\<^sub>c' \\<I>\"\n        using * by auto\n      hence \"\\<And>k. k \\<in> set K \\<Longrightarrow> ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A> \\<union> M\\<^sub>0 \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile>\\<^sub>c k \\<cdot> \\<I>\"\n        using * strand_sem_Send_split(1) strand_sem_eq_defs(1)\n        by auto\n      thus ?thesis using Decomp sem\\<^sub>e\\<^sub>s\\<^sub>t_c.Decompose[OF IH ** Ana] by metis\n    qed\n  qed\n\n  show \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c M\\<^sub>0 \\<I> \\<A> \\<Longrightarrow> \\<lbrakk>M\\<^sub>0; to_st \\<A>\\<rbrakk>\\<^sub>c' \\<I>\"\n  proof (induction rule: sem\\<^sub>e\\<^sub>s\\<^sub>t_c.induct)\n    case Nil thus ?case by simp\n  next\n    case (Send M\\<^sub>0 \\<I> \\<A> t) thus ?case\n      using strand_sem_append'[of M\\<^sub>0 \"to_st \\<A>\" \\<I> \"[send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t]\"]\n            to_st_append[of \\<A> \"[Step (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)]\"]\n      by (simp add: sup.commute)\n  next\n    case (Receive M\\<^sub>0 \\<I> \\<A> t) thus ?case\n      using strand_sem_append'[of M\\<^sub>0 \"to_st \\<A>\" \\<I> \"[receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t]\"]\n            to_st_append[of \\<A> \"[Step (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)]\"]\n      by (simp add: sup.commute)\n  next\n    case (Equality M\\<^sub>0 \\<I> \\<A> t t' a) thus ?case\n      using strand_sem_append'[of M\\<^sub>0 \"to_st \\<A>\" \\<I> \"[\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t]\"]\n            to_st_append[of \\<A> \"[Step (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t)]\"]\n      by (simp add: sup.commute)\n  next\n    case (Inequality M\\<^sub>0 \\<I> \\<A> X F) thus ?case\n      using strand_sem_append'[of M\\<^sub>0 \"to_st \\<A>\" \\<I> \"[\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t]\"]\n            to_st_append[of \\<A> \"[Step (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t)]\"]\n      by (auto simp add: sup.commute)\n  next\n    case (Decompose M\\<^sub>0 \\<I> \\<A> t K M)\n    have \"\\<lbrakk>M\\<^sub>0 \\<union> ik\\<^sub>s\\<^sub>t (to_st \\<A>); decomp t\\<rbrakk>\\<^sub>c' \\<I>\"\n    proof -\n      have \"\\<lbrakk>M\\<^sub>0 \\<union> ik\\<^sub>s\\<^sub>t (to_st \\<A>); [send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t]\\<rbrakk>\\<^sub>c' \\<I>\"\n        using Decompose.hyps(2) by (auto simp add: sup.commute)\n      moreover have \"\\<And>k. k \\<in> set K \\<Longrightarrow> M\\<^sub>0 \\<union> ik\\<^sub>s\\<^sub>t (to_st \\<A>) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile>\\<^sub>c k \\<cdot> \\<I>\"\n        using Decompose by (metis sup.commute)\n      hence \"\\<And>k. k \\<in> set K \\<Longrightarrow> \\<lbrakk>M\\<^sub>0 \\<union> ik\\<^sub>s\\<^sub>t (to_st \\<A>); [Send k]\\<rbrakk>\\<^sub>c' \\<I>\" by auto\n      hence \"\\<lbrakk>M\\<^sub>0 \\<union> ik\\<^sub>s\\<^sub>t (to_st \\<A>); map Send K\\<rbrakk>\\<^sub>c' \\<I>\"\n        using strand_sem_Send_map(1)[of K, of \"M\\<^sub>0 \\<union> ik\\<^sub>s\\<^sub>t (to_st \\<A>) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" \\<I>]\n              strand_sem_eq_defs(1)\n        by auto\n      moreover have \"\\<lbrakk>M\\<^sub>0 \\<union> ik\\<^sub>s\\<^sub>t (to_st \\<A>); map Receive M\\<rbrakk>\\<^sub>c' \\<I>\"\n        by (metis strand_sem_Receive_map(1) strand_sem_eq_defs(1))\n      ultimately have\n          \"\\<lbrakk>M\\<^sub>0 \\<union> ik\\<^sub>s\\<^sub>t (to_st \\<A>); send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#map Send K@map Receive M\\<rbrakk>\\<^sub>c' \\<I>\"\n        by auto\n      thus ?thesis using Decompose.hyps(3) unfolding decomp_def by auto\n    qed\n    hence \"\\<lbrakk>M\\<^sub>0; to_st \\<A>@decomp t\\<rbrakk>\\<^sub>c' \\<I>\"\n      using strand_sem_append'[of M\\<^sub>0 \"to_st \\<A>\" \\<I> \"decomp t\"] Decompose.IH\n      by simp\n    thus ?case using to_st_append[of \\<A> \"[Decomp t]\"] by simp\n  qed\nqed\n\nprivate lemma sem\\<^sub>e\\<^sub>s\\<^sub>t_c_decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_deduct_aux:\n  assumes \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c M\\<^sub>0 \\<I> A\" \"t \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" \"t \\<notin> ik\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n  shows \"ik\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A) \\<union> M\\<^sub>0 \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> t\"\nusing assms\nproof (induction M\\<^sub>0 \\<I> A arbitrary: t rule: sem\\<^sub>e\\<^sub>s\\<^sub>t_c.induct)\n  case (Send M\\<^sub>0 \\<I> A t') thus ?case using decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append ik\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\nnext\n  case (Receive M\\<^sub>0 \\<I> A t')\n  hence \"t \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" \"t \\<notin> ik\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n    using decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append ik\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\n  hence IH: \"ik\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A) \\<union> M\\<^sub>0 \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> t\" using Receive.IH by auto\n  show ?case using ideduct_mono[OF IH] decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append ik\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\nnext\n  case (Equality M\\<^sub>0 \\<I> A t') thus ?case using decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append ik\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\nnext\n  case (Inequality M\\<^sub>0 \\<I> A t') thus ?case using decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append ik\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\nnext\n  case (Decompose M\\<^sub>0 \\<I> A t' K M t)\n  have *: \"ik\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A) \\<union> M\\<^sub>0 \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> t' \\<cdot> \\<I>\" using Decompose.hyps(2)\n  proof (induction rule: intruder_synth_induct)\n    case (AxiomC t'')\n    moreover {\n      assume \"t'' \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" \"t'' \\<notin> ik\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n      hence ?case using Decompose.IH by auto\n    }\n    ultimately show ?case by force\n  qed simp\n\n  { fix k assume \"k \\<in> set K\"\n    hence \"ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> M\\<^sub>0 \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile>\\<^sub>c k \\<cdot> \\<I>\" using Decompose.hyps by auto\n    hence \"ik\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A) \\<union> M\\<^sub>0 \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> k \\<cdot> \\<I>\"\n    proof (induction rule: intruder_synth_induct)\n      case (AxiomC t'')\n      moreover {\n        assume \"t'' \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" \"t'' \\<notin> ik\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n        hence ?case using Decompose.IH by auto\n      }\n      ultimately show ?case by force\n    qed simp\n  }\n  hence **: \"\\<And>k. k \\<in> set (K \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<I>) \\<Longrightarrow> ik\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A) \\<union> M\\<^sub>0 \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> k\" by auto\n\n  show ?case\n  proof (cases \"t \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\")\n    case True thus ?thesis using Decompose.IH Decompose.prems(2) decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\n  next\n    case False\n    hence \"t \\<in> ik\\<^sub>s\\<^sub>t (decomp t') \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" using Decompose.prems(1) ik\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\n    hence ***: \"t \\<in> set (M \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<I>)\" using Decompose.hyps(3) decomp_ik by auto\n    hence \"M \\<noteq> []\" by auto\n    hence ****: \"Ana (t' \\<cdot> \\<I>) = (K \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<I>, M \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<I>)\" using Ana_subst[OF Decompose.hyps(3)] by auto\n\n    have \"ik\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A) \\<union> M\\<^sub>0 \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> t\" by (rule intruder_deduct.Decompose[OF * **** ** ***])\n    thus ?thesis using ideduct_mono decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\n  qed\nqed simp\n\nprivate lemma sem\\<^sub>e\\<^sub>s\\<^sub>t_c_decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_deduct:\n  assumes \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c M\\<^sub>0 \\<I> A\" \"ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> M\\<^sub>0 \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile>\\<^sub>c t\"\n  shows \"ik\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A) \\<union> M\\<^sub>0 \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> t\"\nusing assms(2)\nproof (induction t rule: intruder_synth_induct)\n  case (AxiomC t)\n  hence \"t \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<or> t \\<in> M\\<^sub>0 \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" by auto\n  moreover {\n    assume \"t \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" \"t \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n    hence ?case using ideduct_mono[OF intruder_deduct.Axiom] by auto\n  }\n  moreover {\n    assume \"t \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" \"t \\<notin> ik\\<^sub>e\\<^sub>s\\<^sub>t (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n    hence ?case using sem\\<^sub>e\\<^sub>s\\<^sub>t_c_decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_deduct_aux[OF assms(1)] by auto\n  }\n  ultimately show ?case by auto\nqed simp\n\nprivate lemma sem\\<^sub>e\\<^sub>s\\<^sub>t_d_decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_if_sem\\<^sub>e\\<^sub>s\\<^sub>t_c: \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c M\\<^sub>0 \\<I> A \\<Longrightarrow> sem\\<^sub>e\\<^sub>s\\<^sub>t_d M\\<^sub>0 \\<I> (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A)\"\nproof (induction M\\<^sub>0 \\<I> A rule: sem\\<^sub>e\\<^sub>s\\<^sub>t_c.induct)\n  case (Send M\\<^sub>0 \\<I> A t)\n  thus ?case using decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append sem\\<^sub>e\\<^sub>s\\<^sub>t_d.Send[OF Send.IH] sem\\<^sub>e\\<^sub>s\\<^sub>t_c_decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_deduct by auto\nnext\n  case (Receive t) thus ?case using decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append sem\\<^sub>e\\<^sub>s\\<^sub>t_d.Receive by auto\nnext\n  case (Equality M\\<^sub>0 \\<I> A t)\n  thus ?case\n    using decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append sem\\<^sub>e\\<^sub>s\\<^sub>t_d.Equality[OF Equality.IH] sem\\<^sub>e\\<^sub>s\\<^sub>t_c_decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_deduct\n    by auto\nnext\n  case (Inequality M\\<^sub>0 \\<I> A t)\n  thus ?case\n    using decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append sem\\<^sub>e\\<^sub>s\\<^sub>t_d.Inequality[OF Inequality.IH] sem\\<^sub>e\\<^sub>s\\<^sub>t_c_decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_deduct\n    by auto\nnext\n  case Decompose thus ?case using decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\nqed auto\n\nprivate lemma sem\\<^sub>e\\<^sub>s\\<^sub>t_c_decomps\\<^sub>e\\<^sub>s\\<^sub>t_append:\n  assumes \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c {} \\<I> A\" \"D \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A) (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>) \\<I>\"\n  shows \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c {} \\<I> (A@D)\"\nusing assms(2,1)\nproof (induction D rule: decomps\\<^sub>e\\<^sub>s\\<^sub>t.induct)\n  case (Decomp D f T K M)\n  hence *: \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c {} \\<I> (A @ D)\" \"ik\\<^sub>e\\<^sub>s\\<^sub>t (A@D) \\<union> {} \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile>\\<^sub>c Fun f T \\<cdot> \\<I>\"\n           \"\\<And>k. k \\<in> set K \\<Longrightarrow> ik\\<^sub>e\\<^sub>s\\<^sub>t (A @ D) \\<union> {} \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile>\\<^sub>c k \\<cdot> \\<I>\"\n    using ik\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\n  show ?case using sem\\<^sub>e\\<^sub>s\\<^sub>t_c.Decompose[OF *(1,2) Decomp.hyps(3) *(3)] by simp\nqed auto\n\nprivate lemma decomps\\<^sub>e\\<^sub>s\\<^sub>t_preserves_wf:\n  assumes \"D \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A) (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A) \\<I>\" \"wf\\<^sub>e\\<^sub>s\\<^sub>t V A\"\n  shows \"wf\\<^sub>e\\<^sub>s\\<^sub>t V (A@D)\"\nusing assms\nproof (induction D rule: decomps\\<^sub>e\\<^sub>s\\<^sub>t.induct)\n  case (Decomp D f T K M)\n  have \"wfrestrictedvars\\<^sub>s\\<^sub>t (decomp (Fun f T)) \\<subseteq> fv\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A)\"\n    using decomp_vars fv_subset_subterms[OF Decomp.hyps(2)] by fast\n  hence \"wfrestrictedvars\\<^sub>s\\<^sub>t (decomp (Fun f T)) \\<subseteq> wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t A\"\n    using ik\\<^sub>s\\<^sub>t_assignment_rhs\\<^sub>s\\<^sub>t_wfrestrictedvars_subset[of \"to_st A\"] by blast\n  hence \"wfrestrictedvars\\<^sub>s\\<^sub>t (decomp (Fun f T)) \\<subseteq> wfrestrictedvars\\<^sub>s\\<^sub>t (to_st (A@D)) \\<union> V\"\n    using to_st_append[of A D] strand_vars_split(2)[of \"to_st A\" \"to_st D\"]\n    by (metis le_supI1)\n  thus ?case\n    using wf_append_suffix[OF Decomp.IH[OF Decomp.prems], of \"decomp (Fun f T)\"]\n          to_st_append[of \"A@D\" \"[Decomp (Fun f T)]\"]\n    by auto\nqed auto\n\nprivate lemma decomps\\<^sub>e\\<^sub>s\\<^sub>t_preserves_model_c:\n  assumes \"D \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A) (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A) \\<I>\" \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c M\\<^sub>0 \\<I> A\"\n  shows \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c M\\<^sub>0 \\<I> (A@D)\"\nusing assms\nproof (induction D rule: decomps\\<^sub>e\\<^sub>s\\<^sub>t.induct)\n  case (Decomp D f T K M) show ?case\n    using sem\\<^sub>e\\<^sub>s\\<^sub>t_c.Decompose[OF Decomp.IH[OF Decomp.prems] _ Decomp.hyps(3)]\n          Decomp.hyps(5,6) ideduct_synth_mono ik\\<^sub>e\\<^sub>s\\<^sub>t_append\n    by (metis (mono_tags, lifting) List.append_assoc image_Un sup_ge1)\nqed auto\n\nprivate lemma decomps\\<^sub>e\\<^sub>s\\<^sub>t_exist_aux:\n  assumes \"D \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t M N \\<I>\" \"M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D \\<turnstile> t\" \"\\<not>(M \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t D) \\<turnstile>\\<^sub>c t)\"\n  obtains D' where\n    \"D@D' \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t M N \\<I>\" \"M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t (D@D') \\<turnstile>\\<^sub>c t\" \"M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D \\<subset> M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t (D@D')\"\nproof -\n  have \"\\<exists>D' \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t M N \\<I>. M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<turnstile>\\<^sub>c t\" using assms(2)\n  proof (induction t rule: intruder_deduct_induct)\n    case (Compose X f)\n    from Compose.IH have \"\\<exists>D \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t M N \\<I>. \\<forall>x \\<in> set X. M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D \\<turnstile>\\<^sub>c x\"\n    proof (induction X)\n      case (Cons t X)\n      then obtain D' D'' where\n          D': \"D' \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t M N \\<I>\" \"M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<turnstile>\\<^sub>c t\" and\n          D'': \"D'' \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t M N \\<I>\" \"\\<forall>x \\<in> set X. M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D'' \\<turnstile>\\<^sub>c x\"\n        by moura\n      hence \"M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t (D'@D'') \\<turnstile>\\<^sub>c t\" \"\\<forall>x \\<in> set X. M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t (D'@D'') \\<turnstile>\\<^sub>c x\"\n        by (auto intro: ideduct_synth_mono simp add: ik\\<^sub>e\\<^sub>s\\<^sub>t_append)\n      thus ?case using decomps\\<^sub>e\\<^sub>s\\<^sub>t_append[OF D'(1) D''(1)] by (metis set_ConsD)\n    qed (auto intro: decomps\\<^sub>e\\<^sub>s\\<^sub>t.Nil)\n    thus ?case using intruder_synth.ComposeC[OF Compose.hyps(1,2)] by metis\n  next\n    case (Decompose t K T t\\<^sub>i)\n    have \"\\<exists>D \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t M N \\<I>. \\<forall>k \\<in> set K. M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D \\<turnstile>\\<^sub>c k\" using Decompose.IH\n    proof (induction K)\n      case (Cons t X)\n      then obtain D' D'' where\n          D': \"D' \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t M N \\<I>\" \"M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<turnstile>\\<^sub>c t\" and\n          D'': \"D'' \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t M N \\<I>\" \"\\<forall>x \\<in> set X. M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D'' \\<turnstile>\\<^sub>c x\"\n        using assms(1) by moura\n      hence \"M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t (D'@D'') \\<turnstile>\\<^sub>c t\" \"\\<forall>x \\<in> set X. M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t (D'@D'') \\<turnstile>\\<^sub>c x\"\n        by (auto intro: ideduct_synth_mono simp add: ik\\<^sub>e\\<^sub>s\\<^sub>t_append)\n      thus ?case using decomps\\<^sub>e\\<^sub>s\\<^sub>t_append[OF D'(1) D''(1)] by auto\n    qed auto\n    then obtain D' where D': \"D' \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t M N \\<I>\" \"\\<And>k. k \\<in> set K \\<Longrightarrow> M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<turnstile>\\<^sub>c k\" by metis\n    obtain D'' where D'': \"D'' \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t M N \\<I>\" \"M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D'' \\<turnstile>\\<^sub>c t\" by (metis Decompose.IH(1))\n    obtain f X where fX: \"t = Fun f X\" \"t\\<^sub>i \\<in> set X\"\n      using Decompose.hyps(2,4) by (cases t) (auto dest: Ana_fun_subterm)\n\n    from decomps\\<^sub>e\\<^sub>s\\<^sub>t_append[OF D'(1) D''(1)] D'(2) D''(2) have *:\n        \"D'@D'' \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t M N \\<I>\" \"\\<And>k. k \\<in> set K \\<Longrightarrow> M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t (D'@D'') \\<turnstile>\\<^sub>c k\"\n        \"M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t (D'@D'') \\<turnstile>\\<^sub>c t\"\n      by (auto intro: ideduct_synth_mono simp add: ik\\<^sub>e\\<^sub>s\\<^sub>t_append)\n    hence **: \"\\<And>k. k \\<in> set K \\<Longrightarrow> M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t (D'@D'') \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile>\\<^sub>c k \\<cdot> \\<I>\"\n      using ideduct_synth_subst by auto\n\n    have \"t\\<^sub>i \\<in> ik\\<^sub>s\\<^sub>t (decomp t)\" using Decompose.hyps(2,4) ik_rcv_map unfolding decomp_def by auto\n    with *(3) fX(1) Decompose.hyps(2) show ?case\n    proof (induction t rule: intruder_synth_induct)\n      case (AxiomC t)\n      hence t_in_subterms: \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (M \\<union> N)\"\n        using decomps\\<^sub>e\\<^sub>s\\<^sub>t_ik_subset[OF *(1)] subset_subterms_Union\n        by auto\n      have \"M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t (D'@D'') \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile>\\<^sub>c t \\<cdot> \\<I>\"\n        using ideduct_synth_subst[OF intruder_synth.AxiomC[OF AxiomC.hyps(1)]] by metis\n      moreover have \"T \\<noteq> []\" using decomp_ik[OF \\<open>Ana t = (K,T)\\<close>] \\<open>t\\<^sub>i \\<in> ik\\<^sub>s\\<^sub>t (decomp t)\\<close> by auto\n      ultimately have \"D'@D''@[Decomp (Fun f X)] \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t M N \\<I>\"\n        using AxiomC decomps\\<^sub>e\\<^sub>s\\<^sub>t.Decomp[OF *(1) _ _ _ _ **] subset_subterms_Union t_in_subterms\n        by (simp add: subset_eq)\n      moreover have \"decomp t = to_st [Decomp (Fun f X)]\" using AxiomC.prems(1,2) by auto\n      ultimately show ?case\n        by (metis AxiomC.prems(3) UnCI intruder_synth.AxiomC ik\\<^sub>e\\<^sub>s\\<^sub>t_append to_st_append)\n    qed (auto intro!: fX(2) *(1))\n  qed (fastforce intro: intruder_synth.AxiomC assms(1))\n  hence \"\\<exists>D' \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t M N \\<I>. M \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t (D@D') \\<turnstile>\\<^sub>c t\"\n    by (auto intro: ideduct_synth_mono simp add: ik\\<^sub>e\\<^sub>s\\<^sub>t_append)\n  thus thesis using that[OF decomps\\<^sub>e\\<^sub>s\\<^sub>t_append[OF assms(1)]] assms ik\\<^sub>e\\<^sub>s\\<^sub>t_append by moura\nqed\n\nprivate lemma decomps\\<^sub>e\\<^sub>s\\<^sub>t_ik_max_exist:\n  assumes \"finite A\" \"finite N\"\n  shows \"\\<exists>D \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t A N \\<I>. \\<forall>D' \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t A N \\<I>. ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<subseteq> ik\\<^sub>e\\<^sub>s\\<^sub>t D\"\nproof -\n  let ?IK = \"\\<lambda>M. \\<Union>D \\<in> M. ik\\<^sub>e\\<^sub>s\\<^sub>t D\"\n  have \"?IK (decomps\\<^sub>e\\<^sub>s\\<^sub>t A N \\<I>) \\<subseteq> (\\<Union>t \\<in> A \\<union> N. subterms t)\" by (auto dest!: decomps\\<^sub>e\\<^sub>s\\<^sub>t_ik_subset)\n  hence \"finite (?IK (decomps\\<^sub>e\\<^sub>s\\<^sub>t A N \\<I>))\"\n    using subterms_union_finite[OF assms(1)] subterms_union_finite[OF assms(2)] infinite_super\n    by auto\n  then obtain M where M: \"finite M\" \"M \\<subseteq> decomps\\<^sub>e\\<^sub>s\\<^sub>t A N \\<I>\" \"?IK M = ?IK (decomps\\<^sub>e\\<^sub>s\\<^sub>t A N \\<I>)\"\n    using finite_subset_Union by moura\n  show ?thesis using decomps\\<^sub>e\\<^sub>s\\<^sub>t_finite_ik_append[OF M(1,2)] M(3) by auto\nqed\n\nprivate lemma decomps\\<^sub>e\\<^sub>s\\<^sub>t_exist:\n  assumes \"finite A\" \"finite N\"\n  shows \"\\<exists>D \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t A N \\<I>. \\<forall>t. A \\<turnstile> t \\<longrightarrow> A \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D \\<turnstile>\\<^sub>c t\"\nproof (rule ccontr)\n  assume neg: \"\\<not>(\\<exists>D \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t A N \\<I>. \\<forall>t. A \\<turnstile> t \\<longrightarrow> A \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D \\<turnstile>\\<^sub>c t)\"\n\n  obtain D where D: \"D \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t A N \\<I>\" \"\\<forall>D' \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t A N \\<I>. ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<subseteq> ik\\<^sub>e\\<^sub>s\\<^sub>t D\"\n    using decomps\\<^sub>e\\<^sub>s\\<^sub>t_ik_max_exist[OF assms] by moura\n  then obtain t where t: \"A \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D \\<turnstile> t\" \"\\<not>(A \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D \\<turnstile>\\<^sub>c t)\"\n    using neg by (fastforce intro: ideduct_mono)\n\n  obtain D' where D':\n      \"D@D' \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t A N \\<I>\" \"A \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t (D@D') \\<turnstile>\\<^sub>c t\"\n      \"A \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D \\<subset> A \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t (D@D')\"\n    by (metis decomps\\<^sub>e\\<^sub>s\\<^sub>t_exist_aux t D(1))\n  hence \"ik\\<^sub>e\\<^sub>s\\<^sub>t D \\<subset> ik\\<^sub>e\\<^sub>s\\<^sub>t (D@D')\" using ik\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\n  moreover have \"ik\\<^sub>e\\<^sub>s\\<^sub>t (D@D') \\<subseteq> ik\\<^sub>e\\<^sub>s\\<^sub>t D\" using D(2) D'(1) by auto\n  ultimately show False by simp\nqed\n\nprivate lemma decomps\\<^sub>e\\<^sub>s\\<^sub>t_exist_subst:\n  assumes \"ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> t \\<cdot> \\<I>\"\n  and \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c {} \\<I> A\" \"wf\\<^sub>e\\<^sub>s\\<^sub>t {} A\" \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\"\n  and \"Ana_invar_subst (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A)\"\n  and \"well_analyzed A\"\n  shows \"\\<exists>D \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A) (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A) \\<I>. ik\\<^sub>e\\<^sub>s\\<^sub>t (A@D) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile>\\<^sub>c t \\<cdot> \\<I>\"\nproof -\n  have ik_eq: \"ik\\<^sub>e\\<^sub>s\\<^sub>t (A \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<I>) = ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" using assms(5,6)\n  proof (induction A rule: List.rev_induct)\n    case (snoc a A)\n    hence \"Ana_invar_subst (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A)\"\n      using Ana_invar_subst_subset[OF snoc.prems(1)] ik\\<^sub>e\\<^sub>s\\<^sub>t_append assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append\n      unfolding Ana_invar_subst_def by simp\n    with snoc have IH:\n        \"ik\\<^sub>e\\<^sub>s\\<^sub>t (A@[a] \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<I>) = (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t ([a] \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<I>)\"\n        \"ik\\<^sub>e\\<^sub>s\\<^sub>t (A@[a]) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> = (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t [a] \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>)\"\n      using well_analyzed_split_left[OF snoc.prems(2)]\n      by (auto simp add: to_st_append ik\\<^sub>e\\<^sub>s\\<^sub>t_append_subst)\n\n    have \"ik\\<^sub>e\\<^sub>s\\<^sub>t [a \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p \\<I>] = ik\\<^sub>e\\<^sub>s\\<^sub>t [a] \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n    proof (cases a)\n      case (Step b) thus ?thesis by (cases b) auto\n    next\n      case (Decomp t)\n      then obtain f T where t: \"t = Fun f T\" using well_analyzedD[OF snoc.prems(2)] by force\n      obtain K M where Ana_t: \"Ana (Fun f T) = (K,M)\" by (metis surj_pair)\n      moreover have \"Fun f T \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t ((ik\\<^sub>e\\<^sub>s\\<^sub>t (A@[a]) \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t (A@[a])))\"\n        using t Decomp snoc.prems(2)\n        by (auto dest: well_analyzed_inv simp add: ik\\<^sub>e\\<^sub>s\\<^sub>t_append assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append)\n      hence \"Ana (Fun f T \\<cdot> \\<I>) = (K \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<I>, M \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<I>)\"\n        using Ana_t snoc.prems(1)\n        unfolding Ana_invar_subst_def by blast\n      ultimately show ?thesis using Decomp t by (auto simp add: decomp_ik)\n    qed\n    thus ?case using IH unfolding subst_apply_extstrand_def by simp\n  qed simp\n  moreover have assignment_rhs_eq: \"assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t (A \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<I>) = assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n    using assms(5,6)\n  proof (induction A rule: List.rev_induct)\n    case (snoc a A)\n    hence \"Ana_invar_subst (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A)\"\n      using Ana_invar_subst_subset[OF snoc.prems(1)] ik\\<^sub>e\\<^sub>s\\<^sub>t_append assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append\n      unfolding Ana_invar_subst_def by simp\n    hence \"assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t (A \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<I>) = assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n      using snoc.IH well_analyzed_split_left[OF snoc.prems(2)]\n      by simp\n    hence IH:\n        \"assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t (A@[a] \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<I>) = (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t ([a] \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<I>)\"\n        \"assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t (A@[a]) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> = (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t [a] \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>)\"\n      by (metis assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append_subst(1), metis assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append_subst(2))\n\n    have \"assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t [a \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t\\<^sub>p \\<I>] = assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t [a] \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n    proof (cases a)\n      case (Step b) thus ?thesis by (cases b) auto\n    next\n      case (Decomp t)\n      then obtain f T where t: \"t = Fun f T\" using well_analyzedD[OF snoc.prems(2)] by force\n      obtain K M where Ana_t: \"Ana (Fun f T) = (K,M)\" by (metis surj_pair)\n      moreover have \"Fun f T \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t ((ik\\<^sub>e\\<^sub>s\\<^sub>t (A@[a]) \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t (A@[a])))\"\n        using t Decomp snoc.prems(2)\n        by (auto dest: well_analyzed_inv simp add: ik\\<^sub>e\\<^sub>s\\<^sub>t_append assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append)\n      hence \"Ana (Fun f T \\<cdot> \\<I>) = (K \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<I>, M \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<I>)\"\n        using Ana_t snoc.prems(1) unfolding Ana_invar_subst_def by blast\n      ultimately show ?thesis using Decomp t by (auto simp add: decomp_assignment_rhs_empty)\n    qed\n    thus ?case using IH unfolding subst_apply_extstrand_def by simp\n  qed simp\n  ultimately obtain D where D:\n      \"D \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) Var\"\n      \"(ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t D) \\<turnstile>\\<^sub>c t \\<cdot> \\<I>\"\n    using decomps\\<^sub>e\\<^sub>s\\<^sub>t_exist[OF ik\\<^sub>e\\<^sub>s\\<^sub>t_finite assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_finite, of \"A \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<I>\" \"A \\<cdot>\\<^sub>e\\<^sub>s\\<^sub>t \\<I>\"]\n          ik\\<^sub>e\\<^sub>s\\<^sub>t_append assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append assms(1)\n    by force\n\n  let ?P = \"\\<lambda>D D'. \\<forall>t. (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t D) \\<turnstile>\\<^sub>c t \\<longrightarrow> (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<turnstile>\\<^sub>c t\"\n\n  have \"\\<exists>D' \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A) (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A) \\<I>. ?P D D'\" using D(1)\n  proof (induction D rule: decomps\\<^sub>e\\<^sub>s\\<^sub>t.induct)\n    case Nil\n    have \"ik\\<^sub>e\\<^sub>s\\<^sub>t [] = ik\\<^sub>e\\<^sub>s\\<^sub>t [] \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" by auto\n    thus ?case by (metis decomps\\<^sub>e\\<^sub>s\\<^sub>t.Nil)\n  next\n    case (Decomp D f T K M)\n    obtain D' where D': \"D' \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A) (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A) \\<I>\" \"?P D D'\"\n      using Decomp.IH by auto\n    hence IH: \"\\<And>k. k \\<in> set K \\<Longrightarrow> (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<turnstile>\\<^sub>c k\"\n              \"(ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<turnstile>\\<^sub>c Fun f T\"\n      using Decomp.hyps(5,6) by auto\n\n    have D'_ik: \"ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<subseteq> subterms\\<^sub>s\\<^sub>e\\<^sub>t ((ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n                \"ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<subseteq> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A)\"\n      using decomps\\<^sub>e\\<^sub>s\\<^sub>t_ik_subset[OF D'(1)] by (metis subst_all_mono, metis)\n\n    show ?case using IH(2,1) Decomp.hyps(2,3,4)\n    proof (induction \"Fun f T\" arbitrary: f T K M rule: intruder_synth_induct)\n      case (AxiomC f T)\n      then obtain s where s: \"s \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D'\" \"Fun f T = s \\<cdot> \\<I>\" using AxiomC.prems by blast\n      hence fT_s_in: \"Fun f T \\<in> (subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n                     \"s \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A)\"\n        using AxiomC D'_ik subset_subterms_Union[of \"ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A\"]\n              subst_all_mono[OF subset_subterms_Union, of \\<I>]\n        by (metis (no_types) Un_iff image_eqI subset_Un_eq, metis (no_types) Un_iff subset_Un_eq)\n      obtain Ks Ms where Ana_s: \"Ana s = (Ks,Ms)\" by moura\n\n      have AD'_props: \"wf\\<^sub>e\\<^sub>s\\<^sub>t {} (A@D')\" \"\\<lbrakk>{}; to_st (A@D')\\<rbrakk>\\<^sub>c \\<I>\"\n        using decomps\\<^sub>e\\<^sub>s\\<^sub>t_preserves_model_c[OF D'(1) assms(2)]\n              decomps\\<^sub>e\\<^sub>s\\<^sub>t_preserves_wf[OF D'(1) assms(3)]\n              sem\\<^sub>e\\<^sub>s\\<^sub>t_c_eq_sem_st strand_sem_eq_defs(1)\n        by auto\n\n      show ?case\n      proof (cases s)\n        case (Var x)\n        \\<comment> \\<open>In this case \\<open>\\<I> x\\<close> (is a subterm of something that) was derived from an\n            \"earlier intruder knowledge\" because \\<open>A\\<close> is well-formed and has \\<open>\\<I>\\<close> as a model.\n            So either the intruder composed \\<open>Fun f T\\<close> himself (making \\<open>Decomp (Fun f T)\\<close>\n            unnecessary) or \\<open>Fun f T\\<close> is an instance of something else in the intruder\n            knowledge (in which case the \"something\" can be used in place of \\<open>Fun f T\\<close>)\\<close>\n        hence \"Var x \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t (A@D')\" \"\\<I> x = Fun f T\" using s ik\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\n\n        show ?thesis\n        proof (cases \"\\<forall>m \\<in> set M. ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile>\\<^sub>c m\")\n          case True\n          \\<comment> \\<open>All terms acquired by decomposing \\<open>Fun f T\\<close> are already derivable.\n              Hence there is no need to consider decomposition of \\<open>Fun f T\\<close> at all.\\<close>\n          have *: \"(ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t (D@[Decomp (Fun f T)]) = (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D \\<union> set M\"\n            using decomp_ik[OF \\<open>Ana (Fun f T) = (K,M)\\<close>] ik\\<^sub>e\\<^sub>s\\<^sub>t_append[of D \"[Decomp (Fun f T)]\"]\n            by auto\n\n          { fix t' assume \"(ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D \\<union> set M \\<turnstile>\\<^sub>c t'\"\n            hence \"(ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<turnstile>\\<^sub>c t'\"\n            proof (induction t' rule: intruder_synth_induct)\n              case (AxiomC t') thus ?case\n              proof\n                assume \"t' \\<in> set M\"\n                moreover have \"(ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) = ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" by auto\n                ultimately show ?case using True by auto\n              qed (metis D'(2) intruder_synth.AxiomC)\n            qed auto\n          }\n          thus ?thesis using D'(1) * by metis\n        next\n          case False\n          \\<comment> \\<open>Some term acquired by decomposition of \\<open>Fun f T\\<close> cannot be derived in \\<open>\\<turnstile>\\<^sub>c\\<close>.\n              \\<open>Fun f T\\<close> must therefore be an instance of something else in the intruder knowledge,\n              because of well-formedness.\\<close>\n          then obtain t\\<^sub>i where t\\<^sub>i: \"t\\<^sub>i \\<in> set T\" \"\\<not>ik\\<^sub>e\\<^sub>s\\<^sub>t (A@D') \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile>\\<^sub>c t\\<^sub>i\"\n            using Ana_fun_subterm[OF \\<open>Ana (Fun f T) = (K,M)\\<close>] by (auto simp add: ik\\<^sub>e\\<^sub>s\\<^sub>t_append)\n          obtain S where fS:\n              \"Fun f S \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t (A@D')) \\<or>\n               Fun f S \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t (A@D'))\"\n              \"\\<I> x = Fun f S \\<cdot> \\<I>\"\n            using strand_sem_wf_ik_or_assignment_rhs_fun_subterm[\n                    OF AD'_props \\<open>Var x \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t (A@D')\\<close> _ t\\<^sub>i \\<open>interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\\<close>]\n                  \\<open>\\<I> x = Fun f T\\<close>\n            by moura\n          hence fS_in: \"Fun f S \\<cdot> \\<I> \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n                       \"Fun f S \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A)\"\n            using imageI[OF s(1), of \"\\<lambda>x. x \\<cdot> \\<I>\"] Var\n                  ik\\<^sub>e\\<^sub>s\\<^sub>t_append[of A D'] assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append[of A D']\n                  decomps\\<^sub>e\\<^sub>s\\<^sub>t_subterms[OF D'(1)] decomps\\<^sub>e\\<^sub>s\\<^sub>t_assignment_rhs_empty[OF D'(1)]\n            by auto\n          obtain KS MS where Ana_fS: \"Ana (Fun f S) = (KS, MS)\" by moura\n          hence \"K = KS \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<I>\" \"M = MS \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<I>\"\n            using Ana_invar_substD[OF assms(5) fS_in(2)]\n                  s(2) fS(2) \\<open>s = Var x\\<close> \\<open>Ana (Fun f T) = (K,M)\\<close>\n            by simp_all\n          hence \"MS \\<noteq> []\" using \\<open>M \\<noteq> []\\<close> by simp\n          have \"\\<And>k. k \\<in> set KS \\<Longrightarrow> ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile>\\<^sub>c k \\<cdot> \\<I>\"\n            using AxiomC.prems(1) \\<open>K = KS \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<I>\\<close> by (simp add: image_Un)\n          hence D'': \"D'@[Decomp (Fun f S)] \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A) (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A) \\<I>\"\n            using decomps\\<^sub>e\\<^sub>s\\<^sub>t.Decomp[OF D'(1) fS_in(2) Ana_fS \\<open>MS \\<noteq> []\\<close>] AxiomC.prems(1)\n                  intruder_synth.AxiomC[OF fS_in(1)]\n            by simp\n          moreover {\n            fix t' assume \"(ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t (D@[Decomp (Fun f T)]) \\<turnstile>\\<^sub>c t'\"\n            hence \"(ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t (D'@[Decomp (Fun f S)]) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<turnstile>\\<^sub>c t'\"\n            proof (induction t' rule: intruder_synth_induct)\n              case (AxiomC t')\n              hence \"t' \\<in> (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D \\<or> t' \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t [Decomp (Fun f T)]\"\n                by (simp add: ik\\<^sub>e\\<^sub>s\\<^sub>t_append)\n              thus ?case\n              proof\n                assume \"t' \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t [Decomp (Fun f T)]\"\n                hence \"t' \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t [Decomp (Fun f S)] \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n                  using decomp_ik \\<open>Ana (Fun f T) = (K,M)\\<close> \\<open>Ana (Fun f S) = (KS,MS)\\<close> \\<open>M = MS \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<I>\\<close>\n                  by simp\n                thus ?case\n                  using ideduct_synth_mono[\n                          OF intruder_synth.AxiomC[of t' \"ik\\<^sub>e\\<^sub>s\\<^sub>t [Decomp (Fun f S)] \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"],\n                          of \"(ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t (D'@[Decomp (Fun f S)]) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>)\"]\n                  by (auto simp add: ik\\<^sub>e\\<^sub>s\\<^sub>t_append)\n              next\n                assume \"t' \\<in> (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t D\"\n                hence \"(ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<turnstile>\\<^sub>c t'\"\n                  by (metis D'(2) intruder_synth.AxiomC)\n                hence \"(ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t [Decomp (Fun f S)] \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<turnstile>\\<^sub>c t'\"\n                  by (simp add: ideduct_synth_mono)\n                thus ?case\n                  using ik\\<^sub>e\\<^sub>s\\<^sub>t_append[of D' \"[Decomp (Fun f S)]\"]\n                        image_Un[of \"\\<lambda>x. x \\<cdot> \\<I>\" \"ik\\<^sub>e\\<^sub>s\\<^sub>t D'\" \"ik\\<^sub>e\\<^sub>s\\<^sub>t [Decomp (Fun f S)]\"]\n                  by (simp add: sup_aci(2))\n              qed\n            qed auto\n          }\n          ultimately show ?thesis using D'' by auto\n        qed\n      next\n        case (Fun g S) \\<comment> \\<open>Hence \\<open>Decomp (Fun f T)\\<close> can be substituted for \\<open>Decomp (Fun g S)\\<close>\\<close>\n        hence KM: \"K = Ks \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<I>\" \"M = Ms \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<I>\" \"set K = set Ks \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" \"set M = set Ms \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n          using fT_s_in(2) \\<open>Ana (Fun f T) = (K,M)\\<close> Ana_s s(2)\n                Ana_invar_substD[OF assms(5), of g S]\n          by auto\n        hence Ms_nonempty: \"Ms \\<noteq> []\" using \\<open>M \\<noteq> []\\<close> by auto\n        { fix t' assume \"(ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t (D@[Decomp (Fun f T)]) \\<turnstile>\\<^sub>c t'\"\n          hence \"(ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t (D'@[Decomp (Fun g S)]) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<turnstile>\\<^sub>c t'\" using AxiomC\n          proof (induction t' rule: intruder_synth_induct)\n            case (AxiomC t')\n            hence \"t' \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<or> t' \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t D \\<or> t' \\<in> set M\"\n              by (simp add: decomp_ik ik\\<^sub>e\\<^sub>s\\<^sub>t_append)\n            thus ?case\n            proof (elim disjE)\n              assume \"t' \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t D\"\n              hence *: \"(ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<turnstile>\\<^sub>c t'\" using D'(2) by simp\n              show ?case by (auto intro: ideduct_synth_mono[OF *] simp add: ik\\<^sub>e\\<^sub>s\\<^sub>t_append_subst(2))\n            next\n              assume \"t' \\<in> set M\"\n              hence \"t' \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t [Decomp (Fun g S)] \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n                using KM(2) Fun decomp_ik[OF Ana_s] by auto\n              thus ?case by (simp add: image_Un ik\\<^sub>e\\<^sub>s\\<^sub>t_append)\n            qed (simp add: ideduct_synth_mono[OF intruder_synth.AxiomC])\n          qed auto\n        }\n        thus ?thesis\n          using s Fun Ana_s AxiomC.prems(1) KM(3) fT_s_in\n                decomps\\<^sub>e\\<^sub>s\\<^sub>t.Decomp[OF D'(1) _ _ Ms_nonempty, of g S Ks]\n          by (metis AxiomC.hyps image_Un image_eqI intruder_synth.AxiomC)\n      qed\n    next\n      case (ComposeC T f)\n      have *: \"\\<And>m. m \\<in> set M \\<Longrightarrow> (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<turnstile>\\<^sub>c m\"\n        using Ana_fun_subterm[OF \\<open>Ana (Fun f T) = (K, M)\\<close>] ComposeC.hyps(3)\n        by auto\n\n      have **: \"ik\\<^sub>e\\<^sub>s\\<^sub>t (D@[Decomp (Fun f T)]) = ik\\<^sub>e\\<^sub>s\\<^sub>t D \\<union> set M\"\n        using decomp_ik[OF \\<open>Ana (Fun f T) = (K, M)\\<close>] ik\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\n\n      { fix t' assume \"(ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t (D@[Decomp (Fun f T)]) \\<turnstile>\\<^sub>c t'\"\n        hence \"(ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t D' \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<turnstile>\\<^sub>c t'\"\n          by (induct rule: intruder_synth_induct) (auto simp add: D'(2) * **)\n      }\n      thus ?case using D'(1) by auto\n    qed\n  qed\n  thus ?thesis using D(2) assms(1) by (auto simp add: ik\\<^sub>e\\<^sub>s\\<^sub>t_append_subst(2))\nqed\n\nprivate lemma wf\\<^sub>s\\<^sub>t\\<^sub>s'_update\\<^sub>s\\<^sub>t_nil: assumes \"wf\\<^sub>s\\<^sub>t\\<^sub>s' \\<S> \\<A>\" shows \"wf\\<^sub>s\\<^sub>t\\<^sub>s' (update\\<^sub>s\\<^sub>t \\<S> []) \\<A>\"\nusing assms unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by auto\n\nprivate lemma wf\\<^sub>s\\<^sub>t\\<^sub>s'_update\\<^sub>s\\<^sub>t_snd:\n  assumes \"wf\\<^sub>s\\<^sub>t\\<^sub>s' \\<S> \\<A>\" \"send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S>\"\n  shows \"wf\\<^sub>s\\<^sub>t\\<^sub>s' (update\\<^sub>s\\<^sub>t \\<S> (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S)) (\\<A>@[Step (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)])\"\nunfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def\nproof (intro conjI)\n  let ?S = \"send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S\"\n  let ?A = \"\\<A>@[Step (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)]\"\n\n  have \\<S>: \"\\<And>S'. S' \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S \\<Longrightarrow> S' = S \\<or> S' \\<in> \\<S>\" by auto\n\n  have 1: \"\\<forall>S \\<in> \\<S>. wf\\<^sub>s\\<^sub>t (wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>) (dual\\<^sub>s\\<^sub>t S)\" using assms unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by auto\n  moreover have 2: \"wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A> \\<union> fv t\"\n    using wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t_split(2) by (auto simp add: Un_assoc)\n  ultimately have 3: \"\\<forall>S \\<in> \\<S>. wf\\<^sub>s\\<^sub>t (wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t ?A) (dual\\<^sub>s\\<^sub>t S)\" by (metis wf_vars_mono)\n\n  have 4: \"\\<forall>S \\<in> \\<S>. \\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\" using assms unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by simp\n\n  have \"wf\\<^sub>s\\<^sub>t (wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t ?A) (dual\\<^sub>s\\<^sub>t S)\" using 1 2 3 assms(2) by auto\n  thus \"\\<forall>S \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S. wf\\<^sub>s\\<^sub>t (wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t ?A) (dual\\<^sub>s\\<^sub>t S)\" by (metis 3 \\<S>)\n\n  have \"fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\"\n       \"\\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\"\n       \"\\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S' \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\"\n    using 4 assms(2) unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by force+\n  thus \"\\<forall>S \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S. \\<forall>S' \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\" by (metis 4 \\<S>)\n\n  have \"\\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t ?S \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\" \"\\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S' \\<inter> bvars\\<^sub>s\\<^sub>t ?S = {}\"\n    using assms unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by metis+\n  hence 5: \"fv\\<^sub>e\\<^sub>s\\<^sub>t ?A = fv\\<^sub>e\\<^sub>s\\<^sub>t \\<A> \\<union> fv t\" \"bvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = bvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\" \"\\<forall>S' \\<in> \\<S>. fv t \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\"\n    using to_st_append by fastforce+\n\n  have *: \"\\<forall>S \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = {}\"\n    using 5 assms(1) unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by fast\n  hence \"fv\\<^sub>s\\<^sub>t ?S \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = {}\" using assms(2) by metis\n  hence \"fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = {}\" by auto\n  thus \"\\<forall>S \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = {}\" by (metis * \\<S>)\n\n  have **: \"\\<forall>S \\<in> \\<S>. fv\\<^sub>e\\<^sub>s\\<^sub>t ?A \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\"\n    using 5 assms(1) unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by fast\n  hence \"fv\\<^sub>e\\<^sub>s\\<^sub>t ?A \\<inter> bvars\\<^sub>s\\<^sub>t ?S = {}\" using assms(2) by metis\n  hence \"fv\\<^sub>e\\<^sub>s\\<^sub>t ?A \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\" by fastforce\n  thus \"\\<forall>S \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S. fv\\<^sub>e\\<^sub>s\\<^sub>t ?A \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\" by (metis ** \\<S>)\nqed\n\nprivate lemma wf\\<^sub>s\\<^sub>t\\<^sub>s'_update\\<^sub>s\\<^sub>t_rcv:\n  assumes \"wf\\<^sub>s\\<^sub>t\\<^sub>s' \\<S> \\<A>\" \"receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S>\"\n  shows \"wf\\<^sub>s\\<^sub>t\\<^sub>s' (update\\<^sub>s\\<^sub>t \\<S> (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S)) (\\<A>@[Step (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)])\"\nunfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def\nproof (intro conjI)\n  let ?S = \"receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S\"\n  let ?A = \"\\<A>@[Step (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)]\"\n\n  have \\<S>: \"\\<And>S'. S' \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S \\<Longrightarrow> S' = S \\<or> S' \\<in> \\<S>\" by auto\n\n  have 1: \"\\<forall>S \\<in> \\<S>. wf\\<^sub>s\\<^sub>t (wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>) (dual\\<^sub>s\\<^sub>t S)\" using assms unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by auto\n  moreover have 2: \"wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A> \\<union> fv t\"\n    using wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t_split(2) by (auto simp add: Un_assoc)\n  ultimately have 3: \"\\<forall>S \\<in> \\<S>. wf\\<^sub>s\\<^sub>t (wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t ?A) (dual\\<^sub>s\\<^sub>t S)\" by (metis wf_vars_mono)\n\n  have 4: \"\\<forall>S \\<in> \\<S>. \\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\" using assms unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by simp\n\n  have \"wf\\<^sub>s\\<^sub>t (wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t ?A) (dual\\<^sub>s\\<^sub>t S)\" using 1 2 3 assms(2) by auto\n  thus \"\\<forall>S \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S. wf\\<^sub>s\\<^sub>t (wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t ?A) (dual\\<^sub>s\\<^sub>t S)\" by (metis 3 \\<S>)\n\n  have \"fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\"\n       \"\\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\"\n       \"\\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S' \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\"\n    using 4 assms(2) unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by force+\n  thus \"\\<forall>S \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S. \\<forall>S' \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\" by (metis 4 \\<S>)\n\n  have \"\\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t ?S \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\" \"\\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S' \\<inter> bvars\\<^sub>s\\<^sub>t ?S = {}\"\n    using assms unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by metis+\n  hence 5: \"fv\\<^sub>e\\<^sub>s\\<^sub>t ?A = fv\\<^sub>e\\<^sub>s\\<^sub>t \\<A> \\<union> fv t\" \"bvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = bvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\" \"\\<forall>S' \\<in> \\<S>. fv t \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\"\n    using to_st_append by fastforce+\n\n  have *: \"\\<forall>S \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = {}\"\n    using 5 assms(1) unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by fast\n  hence \"fv\\<^sub>s\\<^sub>t ?S \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = {}\" using assms(2) by metis\n  hence \"fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = {}\" by auto\n  thus \"\\<forall>S \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = {}\" by (metis * \\<S>)\n\n  have **: \"\\<forall>S \\<in> \\<S>. fv\\<^sub>e\\<^sub>s\\<^sub>t ?A \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\"\n    using 5 assms(1) unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by fast\n  hence \"fv\\<^sub>e\\<^sub>s\\<^sub>t ?A \\<inter> bvars\\<^sub>s\\<^sub>t ?S = {}\" using assms(2) by metis\n  hence \"fv\\<^sub>e\\<^sub>s\\<^sub>t ?A \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\" by fastforce\n  thus \"\\<forall>S \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S. fv\\<^sub>e\\<^sub>s\\<^sub>t ?A \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\" by (metis ** \\<S>)\nqed\n\nprivate lemma wf\\<^sub>s\\<^sub>t\\<^sub>s'_update\\<^sub>s\\<^sub>t_eq:\n  assumes \"wf\\<^sub>s\\<^sub>t\\<^sub>s' \\<S> \\<A>\" \"\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S>\"\n  shows \"wf\\<^sub>s\\<^sub>t\\<^sub>s' (update\\<^sub>s\\<^sub>t \\<S> (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#S)) (\\<A>@[Step (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t)])\"\nunfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def\nproof (intro conjI)\n  let ?S = \"\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#S\"\n  let ?A = \"\\<A>@[Step (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t)]\"\n\n  have \\<S>: \"\\<And>S'. S' \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S \\<Longrightarrow> S' = S \\<or> S' \\<in> \\<S>\" by auto\n\n  have 1: \"\\<forall>S \\<in> \\<S>. wf\\<^sub>s\\<^sub>t (wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>) (dual\\<^sub>s\\<^sub>t S)\" using assms unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by auto\n  moreover have 2:\n      \"a = Assign \\<Longrightarrow> wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A> \\<union> fv t \\<union> fv t'\"\n      \"a = Check \\<Longrightarrow> wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\"\n    using wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t_split(2) by (auto simp add: Un_assoc)\n  ultimately have 3: \"\\<forall>S \\<in> \\<S>. wf\\<^sub>s\\<^sub>t (wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t ?A) (dual\\<^sub>s\\<^sub>t S)\"\n    by (cases a) (metis wf_vars_mono, metis)\n\n  have 4: \"\\<forall>S \\<in> \\<S>. \\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\" using assms unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by simp\n\n  have \"wf\\<^sub>s\\<^sub>t (wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t ?A) (dual\\<^sub>s\\<^sub>t S)\" using 1 2 3 assms(2) by (cases a) auto\n  thus \"\\<forall>S \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S. wf\\<^sub>s\\<^sub>t (wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t ?A) (dual\\<^sub>s\\<^sub>t S)\" by (metis 3 \\<S>)\n\n  have \"fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\"\n       \"\\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\"\n       \"\\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S' \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\"\n    using 4 assms(2) unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by force+\n  thus \"\\<forall>S \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S. \\<forall>S' \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\" by (metis 4 \\<S>)\n\n  have \"\\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t ?S \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\" \"\\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S' \\<inter> bvars\\<^sub>s\\<^sub>t ?S = {}\"\n    using assms unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by metis+\n  hence 5: \"fv\\<^sub>e\\<^sub>s\\<^sub>t ?A = fv\\<^sub>e\\<^sub>s\\<^sub>t \\<A> \\<union> fv t \\<union> fv t'\" \"bvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = bvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\"\n           \"\\<forall>S' \\<in> \\<S>. fv t \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\" \"\\<forall>S' \\<in> \\<S>. fv t' \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\"\n    using to_st_append by fastforce+\n\n  have *: \"\\<forall>S \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = {}\"\n    using 5 assms(1) unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by fast\n  hence \"fv\\<^sub>s\\<^sub>t ?S \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = {}\" using assms(2) by metis\n  hence \"fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = {}\" by auto\n  thus \"\\<forall>S \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = {}\" by (metis * \\<S>)\n\n  have **: \"\\<forall>S \\<in> \\<S>. fv\\<^sub>e\\<^sub>s\\<^sub>t ?A \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\"\n    using 5 assms(1) unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by fast\n  hence \"fv\\<^sub>e\\<^sub>s\\<^sub>t ?A \\<inter> bvars\\<^sub>s\\<^sub>t ?S = {}\" using assms(2) by metis\n  hence \"fv\\<^sub>e\\<^sub>s\\<^sub>t ?A \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\" by fastforce\n  thus \"\\<forall>S \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S. fv\\<^sub>e\\<^sub>s\\<^sub>t ?A \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\" by (metis ** \\<S>)\nqed\n\nprivate lemma wf\\<^sub>s\\<^sub>t\\<^sub>s'_update\\<^sub>s\\<^sub>t_ineq:\n  assumes \"wf\\<^sub>s\\<^sub>t\\<^sub>s' \\<S> \\<A>\" \"\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S>\"\n  shows \"wf\\<^sub>s\\<^sub>t\\<^sub>s' (update\\<^sub>s\\<^sub>t \\<S> (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t#S)) (\\<A>@[Step (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t)])\"\nunfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def\nproof (intro conjI)\n  let ?S = \"\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t#S\"\n  let ?A = \"\\<A>@[Step (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t)]\"\n\n  have \\<S>: \"\\<And>S'. S' \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S \\<Longrightarrow> S' = S \\<or> S' \\<in> \\<S>\" by auto\n\n  have 1: \"\\<forall>S \\<in> \\<S>. wf\\<^sub>s\\<^sub>t (wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>) (dual\\<^sub>s\\<^sub>t S)\" using assms unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by auto\n  moreover have 2: \"wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\"\n    using wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t_split(2) by (auto simp add: Un_assoc)\n  ultimately have 3: \"\\<forall>S \\<in> \\<S>. wf\\<^sub>s\\<^sub>t (wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t ?A) (dual\\<^sub>s\\<^sub>t S)\" by metis\n\n  have 4: \"\\<forall>S \\<in> \\<S>. \\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\" using assms unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by simp\n\n  have \"wf\\<^sub>s\\<^sub>t (wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t ?A) (dual\\<^sub>s\\<^sub>t S)\" using 1 2 3 assms(2) by auto\n  thus \"\\<forall>S \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S. wf\\<^sub>s\\<^sub>t (wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t ?A) (dual\\<^sub>s\\<^sub>t S)\" by (metis 3 \\<S>)\n\n  have \"fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\"\n       \"\\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\"\n       \"\\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S' \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\"\n    using 4 assms(2) unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by force+\n  thus \"\\<forall>S \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S. \\<forall>S' \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\" by (metis 4 \\<S>)\n\n  have \"\\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t ?S \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\" \"\\<forall>S' \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S' \\<inter> bvars\\<^sub>s\\<^sub>t ?S = {}\"\n    using assms unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by metis+\n  moreover have \"fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F - set X \\<subseteq> fv\\<^sub>s\\<^sub>t (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t # S)\" by auto\n  ultimately have 5:\n      \"\\<forall>S' \\<in> \\<S>. (fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F - set X) \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\"\n      \"fv\\<^sub>e\\<^sub>s\\<^sub>t ?A = fv\\<^sub>e\\<^sub>s\\<^sub>t \\<A> \\<union> (fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F - set X)\" \"bvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = set X \\<union> bvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\"\n      \"\\<forall>S \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S \\<inter> set X = {}\"\n    using to_st_append\n    by (blast, force, force, force)\n\n  have *: \"\\<forall>S \\<in> \\<S>. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = {}\" using 5(3,4) assms(1) unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by blast\n  hence \"fv\\<^sub>s\\<^sub>t ?S \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = {}\" using assms(2) by metis\n  hence \"fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = {}\" by auto\n  thus \"\\<forall>S \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t ?A = {}\" by (metis * \\<S>)\n\n  have **: \"\\<forall>S \\<in> \\<S>. fv\\<^sub>e\\<^sub>s\\<^sub>t ?A \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\"\n    using 5(1,2) assms(1) unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by fast\n  hence \"fv\\<^sub>e\\<^sub>s\\<^sub>t ?A \\<inter> bvars\\<^sub>s\\<^sub>t ?S = {}\" using assms(2) by metis\n  hence \"fv\\<^sub>e\\<^sub>s\\<^sub>t ?A \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\" by auto\n  thus \"\\<forall>S \\<in> update\\<^sub>s\\<^sub>t \\<S> ?S. fv\\<^sub>e\\<^sub>s\\<^sub>t ?A \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\" by (metis ** \\<S>)\nqed\n\nprivate lemma trms\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_eq:\n  assumes \"x#S \\<in> \\<S>\"\n  shows \"\\<Union>(trms\\<^sub>s\\<^sub>t ` update\\<^sub>s\\<^sub>t \\<S> (x#S)) \\<union> trms\\<^sub>s\\<^sub>t\\<^sub>p x = \\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>)\" (is \"?A = ?B\")\nproof\n  show \"?B \\<subseteq> ?A\"\n  proof\n    have \"trms\\<^sub>s\\<^sub>t\\<^sub>p x \\<subseteq> trms\\<^sub>s\\<^sub>t (x#S)\" by auto\n    hence \"\\<And>t'. t' \\<in> ?B \\<Longrightarrow> t' \\<in> trms\\<^sub>s\\<^sub>t\\<^sub>p x \\<Longrightarrow> t' \\<in> ?A\" by simp\n    moreover {\n      fix t' assume t': \"t' \\<in> ?B\" \"t' \\<notin> trms\\<^sub>s\\<^sub>t\\<^sub>p x\"\n      then obtain S' where S': \"t' \\<in> trms\\<^sub>s\\<^sub>t S'\" \"S' \\<in> \\<S>\" by auto\n      hence \"S' = x#S \\<or> S' \\<in> update\\<^sub>s\\<^sub>t \\<S> (x#S)\" by auto\n      moreover {\n        assume \"S' = x#S\"\n        hence \"t' \\<in> trms\\<^sub>s\\<^sub>t S\" using S' t' by simp\n        hence \"t' \\<in> ?A\" by auto\n      }\n      ultimately have \"t' \\<in> ?A\" using t' S' by auto\n    }\n    ultimately show \"\\<And>t'. t' \\<in> ?B \\<Longrightarrow> t' \\<in> ?A\" by metis\n  qed\n\n  show \"?A \\<subseteq> ?B\"\n  proof\n    have \"\\<And>t'. t' \\<in> ?A \\<Longrightarrow> t' \\<in> trms\\<^sub>s\\<^sub>t\\<^sub>p x \\<Longrightarrow> trms\\<^sub>s\\<^sub>t\\<^sub>p x \\<subseteq> ?B\"\n      using assms by force+\n    moreover {\n      fix t' assume t': \"t' \\<in> ?A\" \"t' \\<notin> trms\\<^sub>s\\<^sub>t\\<^sub>p x\"\n      then obtain S' where \"t' \\<in> trms\\<^sub>s\\<^sub>t S'\" \"S' \\<in> update\\<^sub>s\\<^sub>t \\<S> (x#S)\" by auto\n      hence \"S' = S \\<or> S' \\<in> \\<S>\" by auto\n      moreover have \"trms\\<^sub>s\\<^sub>t S \\<subseteq> ?B\" using assms trms\\<^sub>s\\<^sub>t_cons[of x S] by blast\n      ultimately have \"t' \\<in> ?B\" using t' by fastforce\n    }\n    ultimately show \"\\<And>t'. t' \\<in> ?A \\<Longrightarrow> t' \\<in> ?B\" by blast\n  qed\nqed\n\nprivate lemma trms\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_eq_snd:\n  assumes \"send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S>\" \"\\<S>' = update\\<^sub>s\\<^sub>t \\<S> (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S)\" \"\\<A>' = \\<A>@[Step (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)]\"\n  shows \"(\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>) = (\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>')\"\nproof -\n  have \"(trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>') = (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>) \\<union> {t}\" \"\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>') \\<union> {t} = \\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>)\"\n    using to_st_append trms\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_eq[OF assms(1)] assms(2,3) by auto\n  thus ?thesis\n    by (metis (no_types, lifting) Un_insert_left Un_insert_right sup_bot.right_neutral)\nqed\n\nprivate lemma trms\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_eq_rcv:\n  assumes \"receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S>\" \"\\<S>' = update\\<^sub>s\\<^sub>t \\<S> (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S)\" \"\\<A>' = \\<A>@[Step (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)]\"\n  shows \"(\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>) = (\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>')\"\nproof -\n  have \"(trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>') = (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>) \\<union> {t}\" \"\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>') \\<union> {t} = \\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>)\"\n    using to_st_append trms\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_eq[OF assms(1)] assms(2,3) by auto\n  thus ?thesis\n    by (metis (no_types, lifting) Un_insert_left Un_insert_right sup_bot.right_neutral)\nqed\n\nprivate lemma trms\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_eq_eq:\n  assumes \"\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S>\" \"\\<S>' = update\\<^sub>s\\<^sub>t \\<S> (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#S)\" \"\\<A>' = \\<A>@[Step (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t)]\"\n  shows \"(\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>) = (\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>')\"\nproof -\n  have \"(trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>') = (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>) \\<union> {t,t'}\" \"\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>') \\<union> {t,t'} = \\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>)\"\n    using to_st_append trms\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_eq[OF assms(1)] assms(2,3) by auto\n  thus ?thesis\n    by (metis (no_types, lifting) Un_insert_left Un_insert_right sup_bot.right_neutral)\nqed\n\nprivate lemma trms\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_eq_ineq:\n  assumes \"\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S>\" \"\\<S>' = update\\<^sub>s\\<^sub>t \\<S> (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t#S)\" \"\\<A>' = \\<A>@[Step (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t)]\"\n  shows \"(\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>) = (\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>')\"\nproof -\n  have \"(trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>') = (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>) \\<union> trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F\" \"\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>') \\<union> trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F = \\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>)\"\n    using to_st_append trms\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_eq[OF assms(1)] assms(2,3) by auto\n  thus ?thesis by (simp add: Un_commute sup_left_commute)\nqed\n\nprivate lemma ik\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_subset:\n  assumes \"x#S \\<in> \\<S>\"\n  shows \"\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` (update\\<^sub>s\\<^sub>t \\<S> (x#S))) \\<subseteq> \\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` \\<S>)\" (is ?A)\n        \"\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` (update\\<^sub>s\\<^sub>t \\<S> (x#S))) \\<subseteq> \\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>)\" (is ?B)\nproof -\n  { fix t assume \"t \\<in> \\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` (update\\<^sub>s\\<^sub>t \\<S> (x#S)))\"\n    then obtain S' where S': \"S' \\<in> update\\<^sub>s\\<^sub>t \\<S> (x#S)\" \"t \\<in> ik\\<^sub>s\\<^sub>t (dual\\<^sub>s\\<^sub>t S')\" by auto\n\n    have *: \"ik\\<^sub>s\\<^sub>t (dual\\<^sub>s\\<^sub>t S) \\<subseteq> ik\\<^sub>s\\<^sub>t (dual\\<^sub>s\\<^sub>t (x#S))\"\n      using ik_append[of \"dual\\<^sub>s\\<^sub>t [x]\" \"dual\\<^sub>s\\<^sub>t S\"] dual\\<^sub>s\\<^sub>t_append[of \"[x]\" S]\n      by auto\n\n    hence \"t \\<in> \\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` \\<S>)\"\n    proof (cases \"S' = S\")\n      case True thus ?thesis using * assms S' by auto\n    next\n      case False thus ?thesis using S' by auto\n    qed\n  }\n  moreover\n  { fix t assume \"t \\<in> \\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` (update\\<^sub>s\\<^sub>t \\<S> (x#S)))\"\n    then obtain S' where S': \"S' \\<in> update\\<^sub>s\\<^sub>t \\<S> (x#S)\" \"t \\<in> assignment_rhs\\<^sub>s\\<^sub>t S'\" by auto\n\n    have \"assignment_rhs\\<^sub>s\\<^sub>t S \\<subseteq> assignment_rhs\\<^sub>s\\<^sub>t (x#S)\"\n      using assignment_rhs_append[of \"[x]\" S] by simp\n    hence \"t \\<in> \\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>)\"\n      using assms S' by (cases \"S' = S\") auto\n  }\n  ultimately show ?A ?B by (metis subsetI)+\nqed\n\nprivate lemma ik\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_subset_snd:\n  assumes \"send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S>\"\n          \"\\<S>' = update\\<^sub>s\\<^sub>t \\<S> (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S)\"\n          \"\\<A>' = \\<A>@[Step (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)]\"\n  shows \"(\\<Union>(ik\\<^sub>s\\<^sub>t ` dual\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>') \\<subseteq>\n         (\\<Union>(ik\\<^sub>s\\<^sub>t ` dual\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\" (is ?A)\n        \"(\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>') \\<subseteq>\n         (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\" (is ?B)\nproof -\n  { fix t' assume t'_in: \"t' \\<in> (\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>')\"\n    hence \"t' \\<in> (\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>) \\<union> {t}\" using assms ik\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\n    moreover have \"t \\<in> \\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` \\<S>)\" using assms(1) by force\n    ultimately have \"t' \\<in> (\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\"\n      using ik\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_subset[OF assms(1)] assms(2) by auto\n  }\n  moreover\n  { fix t' assume t'_in: \"t' \\<in> (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>')\"\n    hence \"t' \\<in> (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\"\n      using assms assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\n    hence \"t' \\<in> (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\"\n      using ik\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_subset[OF assms(1)] assms(2) by auto\n  }\n  ultimately show ?A ?B by (metis subsetI)+\nqed\n\nprivate lemma ik\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_subset_rcv:\n  assumes \"receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S>\"\n          \"\\<S>' = update\\<^sub>s\\<^sub>t \\<S> (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S)\"\n          \"\\<A>' = \\<A>@[Step (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)]\"\n  shows \"(\\<Union>(ik\\<^sub>s\\<^sub>t ` dual\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>') \\<subseteq>\n         (\\<Union>(ik\\<^sub>s\\<^sub>t ` dual\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\" (is ?A)\n        \"(\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>') \\<subseteq>\n         (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\" (is ?B)\nproof -\n  { fix t' assume t'_in: \"t' \\<in> (\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>')\"\n    hence \"t' \\<in> (\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\" using assms ik\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\n    hence \"t' \\<in> (\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\"\n      using ik\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_subset[OF assms(1)] assms(2) by auto\n  }\n  moreover\n  { fix t' assume t'_in: \"t' \\<in> (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>')\"\n    hence \"t' \\<in> (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\"\n      using assms assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\n    hence \"t' \\<in> (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\"\n      using ik\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_subset[OF assms(1)] assms(2) by auto\n  }\n  ultimately show ?A ?B by (metis subsetI)+\nqed\n\nprivate lemma ik\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_subset_eq:\n  assumes \"\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S>\"\n          \"\\<S>' = update\\<^sub>s\\<^sub>t \\<S> (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#S)\"\n          \"\\<A>' = \\<A>@[Step (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t)]\"\n  shows \"(\\<Union>(ik\\<^sub>s\\<^sub>t ` dual\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>') \\<subseteq>\n         (\\<Union>(ik\\<^sub>s\\<^sub>t ` dual\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\" (is ?A)\n        \"(\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>') \\<subseteq>\n         (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\" (is ?B)\nproof -\n  have 1: \"t' \\<in> (\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\"\n    when \"t' \\<in> (\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>')\"\n    for t'\n  proof -\n    have \"t' \\<in> (\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\" using that assms ik\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\n    thus ?thesis using ik\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_subset[OF assms(1)] assms(2) by auto\n  qed\n\n  have 2: \"t'' \\<in> (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\"\n    when \"t'' \\<in> (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>')\" \"a = Assign\"\n    for t''\n  proof -\n    have \"t'' \\<in> (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>) \\<union> {t'}\"\n      using that assms assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\n    moreover have \"t' \\<in> \\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>)\" using assms(1) that by force\n    ultimately show ?thesis using ik\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_subset[OF assms(1)] assms(2) that by auto\n  qed\n\n  have 3: \"assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>' = assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\" (is ?C)\n          \"(\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>')) \\<subseteq> (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>))\" (is ?D)\n    when \"a = Check\"\n  proof -\n    show ?C using that assms(2,3) by (simp add: assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append)\n    show ?D using assms(1,2,3) ik\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_subset(2) by auto\n  qed\n\n  show ?A using 1 2 by (metis subsetI)\n  show ?B using 1 2 3 by (cases a) blast+\nqed\n\nprivate lemma ik\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_subset_ineq:\n  assumes \"\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S>\"\n          \"\\<S>' = update\\<^sub>s\\<^sub>t \\<S> (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t#S)\"\n          \"\\<A>' = \\<A>@[Step (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t)]\"\n  shows \"(\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>') \\<subseteq>\n          (\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\" (is ?A)\n        \"(\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>') \\<subseteq>\n         (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\" (is ?B)\nproof -\n  { fix t' assume t'_in: \"t' \\<in> (\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>')\"\n    hence \"t' \\<in> (\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\" using assms ik\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\n    hence \"t' \\<in> (\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\"\n      using ik\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_subset[OF assms(1)] assms(2) by auto\n  }\n  moreover\n  { fix t' assume t'_in: \"t' \\<in> (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>')\"\n    hence \"t' \\<in> (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\"\n      using assms assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append by auto\n    hence \"t' \\<in> (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\"\n      using ik\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_subset[OF assms(1)] assms(2) by auto\n  }\n  ultimately show ?A ?B by (metis subsetI)+\nqed\n\n\nsubsubsection \\<open>Transition Systems Definitions\\<close>\ninductive pts_symbolic::\n  \"(('fun,'var) strands \\<times> ('fun,'var) strand) \\<Rightarrow>\n   (('fun,'var) strands \\<times> ('fun,'var) strand) \\<Rightarrow> bool\"\n(infix \"\\<Rightarrow>\\<^sup>\\<bullet>\" 50) where\n  Nil[simp]:        \"[] \\<in> \\<S> \\<Longrightarrow> (\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet> (update\\<^sub>s\\<^sub>t \\<S> [],\\<A>)\"\n| Send[simp]:       \"send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S> \\<Longrightarrow> (\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet> (update\\<^sub>s\\<^sub>t \\<S> (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S),\\<A>@[receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t])\"\n| Receive[simp]:    \"receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S> \\<Longrightarrow> (\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet> (update\\<^sub>s\\<^sub>t \\<S> (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S),\\<A>@[send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t])\"\n| Equality[simp]:   \"\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S> \\<Longrightarrow> (\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet> (update\\<^sub>s\\<^sub>t \\<S> (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#S),\\<A>@[\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t])\"\n| Inequality[simp]: \"\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S> \\<Longrightarrow> (\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet> (update\\<^sub>s\\<^sub>t \\<S> (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t#S),\\<A>@[\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t])\"\n\nprivate inductive pts_symbolic_c::\n  \"(('fun,'var) strands \\<times> ('fun,'var) extstrand) \\<Rightarrow>\n   (('fun,'var) strands \\<times> ('fun,'var) extstrand) \\<Rightarrow> bool\"\n(infix \"\\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\" 50) where\n  Nil[simp]:        \"[] \\<in> \\<S> \\<Longrightarrow> (\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c (update\\<^sub>s\\<^sub>t \\<S> [],\\<A>)\"\n| Send[simp]:       \"send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S> \\<Longrightarrow> (\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c (update\\<^sub>s\\<^sub>t \\<S> (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S),\\<A>@[Step (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)])\"\n| Receive[simp]:    \"receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S> \\<Longrightarrow> (\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c (update\\<^sub>s\\<^sub>t \\<S> (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S),\\<A>@[Step (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)])\"\n| Equality[simp]:   \"\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S> \\<Longrightarrow> (\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c (update\\<^sub>s\\<^sub>t \\<S> (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#S),\\<A>@[Step (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t)])\"\n| Inequality[simp]: \"\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S> \\<Longrightarrow> (\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c (update\\<^sub>s\\<^sub>t \\<S> (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t#S),\\<A>@[Step (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t)])\"\n| Decompose[simp]:  \"Fun f T \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A> \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\n                     \\<Longrightarrow> (\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c (\\<S>,\\<A>@[Decomp (Fun f T)])\"\n\nabbreviation pts_symbolic_rtrancl (infix \"\\<Rightarrow>\\<^sup>\\<bullet>\\<^sup>*\" 50) where \"a \\<Rightarrow>\\<^sup>\\<bullet>\\<^sup>* b \\<equiv> pts_symbolic\\<^sup>*\\<^sup>* a b\"\nprivate abbreviation pts_symbolic_c_rtrancl (infix \"\\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\\<^sup>*\" 50) where \"a \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\\<^sup>* b \\<equiv> pts_symbolic_c\\<^sup>*\\<^sup>* a b\"\n\nlemma pts_symbolic_induct[consumes 1, case_names Nil Send Receive Equality Inequality]:\n  assumes \"(\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet> (\\<S>',\\<A>')\"\n  and \"\\<lbrakk>[] \\<in> \\<S>; \\<S>' = update\\<^sub>s\\<^sub>t \\<S> []; \\<A>' = \\<A>\\<rbrakk> \\<Longrightarrow> P\"\n  and \"\\<And>t S. \\<lbrakk>send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S>; \\<S>' = update\\<^sub>s\\<^sub>t \\<S> (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S); \\<A>' = \\<A>@[receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t]\\<rbrakk> \\<Longrightarrow> P\"\n  and \"\\<And>t S. \\<lbrakk>receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S>; \\<S>' = update\\<^sub>s\\<^sub>t \\<S> (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S); \\<A>' = \\<A>@[send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t]\\<rbrakk> \\<Longrightarrow> P\"\n  and \"\\<And>a t t' S. \\<lbrakk>\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S>; \\<S>' = update\\<^sub>s\\<^sub>t \\<S> (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#S); \\<A>' = \\<A>@[\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t]\\<rbrakk> \\<Longrightarrow> P\"\n  and \"\\<And>X F S. \\<lbrakk>\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S>; \\<S>' = update\\<^sub>s\\<^sub>t \\<S> (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t#S); \\<A>' = \\<A>@[\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t]\\<rbrakk> \\<Longrightarrow> P\"\n  shows \"P\"\napply (rule pts_symbolic.cases[OF assms(1)])\nusing assms(2,3,4,5,6) by simp_all\n\nprivate lemma pts_symbolic_c_induct[consumes 1, case_names Nil Send Receive Equality Inequality Decompose]:\n  assumes \"(\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c (\\<S>',\\<A>')\"\n  and \"\\<lbrakk>[] \\<in> \\<S>; \\<S>' = update\\<^sub>s\\<^sub>t \\<S> []; \\<A>' = \\<A>\\<rbrakk> \\<Longrightarrow> P\"\n  and \"\\<And>t S. \\<lbrakk>send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S>; \\<S>' = update\\<^sub>s\\<^sub>t \\<S> (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S); \\<A>' = \\<A>@[Step (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)]\\<rbrakk> \\<Longrightarrow> P\"\n  and \"\\<And>t S. \\<lbrakk>receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S>; \\<S>' = update\\<^sub>s\\<^sub>t \\<S> (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S); \\<A>' = \\<A>@[Step (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)]\\<rbrakk> \\<Longrightarrow> P\"\n  and \"\\<And>a t t' S. \\<lbrakk>\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S>; \\<S>' = update\\<^sub>s\\<^sub>t \\<S> (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#S); \\<A>' = \\<A>@[Step (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t)]\\<rbrakk> \\<Longrightarrow> P\"\n  and \"\\<And>X F S. \\<lbrakk>\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t#S \\<in> \\<S>; \\<S>' = update\\<^sub>s\\<^sub>t \\<S> (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t#S); \\<A>' = \\<A>@[Step (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t)]\\<rbrakk> \\<Longrightarrow> P\"\n  and \"\\<And>f T. \\<lbrakk>Fun f T \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A> \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>); \\<S>' = \\<S>; \\<A>' = \\<A>@[Decomp (Fun f T)]\\<rbrakk> \\<Longrightarrow> P\"\n  shows \"P\"\napply (rule pts_symbolic_c.cases[OF assms(1)])\nusing assms(2,3,4,5,6,7) by simp_all\n\nprivate lemma pts_symbolic_c_preserves_wf_prot:\n  assumes \"(\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\\<^sup>* (\\<S>',\\<A>')\" \"wf\\<^sub>s\\<^sub>t\\<^sub>s' \\<S> \\<A>\"\n  shows \"wf\\<^sub>s\\<^sub>t\\<^sub>s' \\<S>' \\<A>'\"\nusing assms\nproof (induction rule: rtranclp_induct2)\n  case (step \\<S>1 \\<A>1 \\<S>2 \\<A>2)\n  from step.hyps(2) step.IH[OF step.prems] show ?case\n  proof (induction rule: pts_symbolic_c_induct)\n    case Decompose\n    hence \"fv\\<^sub>e\\<^sub>s\\<^sub>t \\<A>2 = fv\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1\" \"bvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>2 = bvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1\"\n      using bvars_decomp ik_assignment_rhs_decomp_fv by metis+\n    thus ?case using Decompose unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def\n      by (metis wf_vars_mono wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t_split(2))\n  qed (metis wf\\<^sub>s\\<^sub>t\\<^sub>s'_update\\<^sub>s\\<^sub>t_nil, metis wf\\<^sub>s\\<^sub>t\\<^sub>s'_update\\<^sub>s\\<^sub>t_snd,\n       metis wf\\<^sub>s\\<^sub>t\\<^sub>s'_update\\<^sub>s\\<^sub>t_rcv, metis wf\\<^sub>s\\<^sub>t\\<^sub>s'_update\\<^sub>s\\<^sub>t_eq,\n       metis wf\\<^sub>s\\<^sub>t\\<^sub>s'_update\\<^sub>s\\<^sub>t_ineq)\nqed metis\n\nprivate lemma pts_symbolic_c_preserves_wf_is:\n  assumes \"(\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\\<^sup>* (\\<S>',\\<A>')\" \"wf\\<^sub>s\\<^sub>t\\<^sub>s' \\<S> \\<A>\" \"wf\\<^sub>s\\<^sub>t V (to_st \\<A>)\"\n  shows \"wf\\<^sub>s\\<^sub>t V (to_st \\<A>')\"\nusing assms\nproof (induction rule: rtranclp_induct2)\n  case (step \\<S>1 \\<A>1 \\<S>2 \\<A>2)\n  hence \"(\\<S>, \\<A>) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\\<^sup>* (\\<S>2, \\<A>2)\" by auto\n  hence *: \"wf\\<^sub>s\\<^sub>t\\<^sub>s' \\<S>1 \\<A>1\" \"wf\\<^sub>s\\<^sub>t\\<^sub>s' \\<S>2 \\<A>2\"\n    using pts_symbolic_c_preserves_wf_prot[OF _ step.prems(1)] step.hyps(1)\n    by auto\n\n  from step.hyps(2) step.IH[OF step.prems] show ?case\n  proof (induction rule: pts_symbolic_c_induct)\n    case Nil thus ?case by auto\n  next\n    case (Send t S)\n    hence \"wf\\<^sub>s\\<^sub>t (wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1) (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#(dual\\<^sub>s\\<^sub>t S))\"\n      using *(1) unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by fastforce\n    hence \"fv t \\<subseteq> wfrestrictedvars\\<^sub>s\\<^sub>t (to_st \\<A>1) \\<union> V\"\n      using wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t_eq_wfrestrictedvars\\<^sub>s\\<^sub>t by auto\n    thus ?case using Send wf_rcv_append''' to_st_append by simp\n  next\n    case (Receive t) thus ?case using wf_snd_append to_st_append by simp\n  next\n    case (Equality a t t' S)\n    hence \"wf\\<^sub>s\\<^sub>t (wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1) (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#(dual\\<^sub>s\\<^sub>t S))\"\n      using *(1) unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by fastforce\n    hence \"fv t' \\<subseteq> wfrestrictedvars\\<^sub>s\\<^sub>t (to_st \\<A>1) \\<union> V\" when \"a = Assign\"\n      using wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t_eq_wfrestrictedvars\\<^sub>s\\<^sub>t that by auto\n    thus ?case using Equality wf_eq_append''' to_st_append by (cases a) auto\n  next\n    case (Inequality t t' S) thus ?case using wf_ineq_append'' to_st_append by simp\n  next\n    case (Decompose f T)\n    hence \"fv (Fun f T) \\<subseteq> wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1\"\n      by (metis fv_subterms_set fv_subset subset_trans\n                ik\\<^sub>s\\<^sub>t_assignment_rhs\\<^sub>s\\<^sub>t_wfrestrictedvars_subset)\n    hence \"vars\\<^sub>s\\<^sub>t (decomp (Fun f T)) \\<subseteq> wfrestrictedvars\\<^sub>s\\<^sub>t (to_st \\<A>1) \\<union> V\"\n      using decomp_vars[of \"Fun f T\"] wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t_eq_wfrestrictedvars\\<^sub>s\\<^sub>t[of \\<A>1] by auto\n    thus ?case\n      using to_st_append[of \\<A>1 \"[Decomp (Fun f T)]\"]\n            wf_append_suffix[OF Decompose.prems] Decompose.hyps(3)\n      by (metis append_Nil2 decomp_vars(1,2) to_st.simps(1,3))\n  qed\nqed metis\n\nprivate lemma pts_symbolic_c_preserves_tfr\\<^sub>s\\<^sub>e\\<^sub>t:\n  assumes \"(\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\\<^sup>* (\\<S>',\\<A>')\"\n    and \"tfr\\<^sub>s\\<^sub>e\\<^sub>t ((\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>))\"\n    and \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s ((\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>)) \\<union> (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>))\"\n  shows \"tfr\\<^sub>s\\<^sub>e\\<^sub>t ((\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>')) \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s ((\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>')) \\<union> (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>'))\"\nusing assms\nproof (induction rule: rtranclp_induct2)\n  case (step \\<S>1 \\<A>1 \\<S>2 \\<A>2)\n  from step.hyps(2) step.IH[OF step.prems] show ?case\n  proof (induction rule: pts_symbolic_c_induct)\n    case Nil\n    hence \"\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>1) = \\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>2)\" by force\n    thus ?case using Nil by metis\n  next\n    case (Decompose f T)\n    obtain t where t: \"t \\<in> ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1 \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1\" \"Fun f T \\<sqsubseteq> t\"\n      using Decompose.hyps(1) by auto\n    have t_wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\n      using Decompose.prems wf_trm_subterm[of _ t]\n            trms\\<^sub>e\\<^sub>s\\<^sub>t_ik_assignment_rhsI[OF t(1)]\n      unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def\n      by (metis UN_E Un_iff)\n    have \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1)\" using trms\\<^sub>e\\<^sub>s\\<^sub>t_ik_assignment_rhsI t by auto\n    hence \"Fun f T \\<in> SMP (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1)\"\n      by (metis (no_types) SMP.MP SMP.Subterm UN_E t(2))\n    hence \"{Fun f T} \\<subseteq> SMP (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1)\" using SMP.Subterm[of \"Fun f T\"] by auto\n    moreover have \"trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>2 = insert (Fun f T) (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1)\"\n      using Decompose.hyps(3) by auto\n    ultimately have *: \"SMP (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1) = SMP (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>2)\"\n      using SMP_subset_union_eq[of \"{Fun f T}\"]\n      by (simp add: Un_commute)\n    hence \"SMP ((\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>1)) \\<union> (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1)) = SMP ((\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>2)) \\<union> (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>2))\"\n      using Decompose.hyps(2) SMP_union by auto\n    moreover have \"\\<forall>t \\<in> trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1. wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f T)\"\n      using Decompose.prems wf_trm_subterm t(2) t_wf unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by auto\n    hence \"\\<forall>t \\<in> trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>2. wf\\<^sub>t\\<^sub>r\\<^sub>m t\" by (metis * SMP.MP SMP_wf_trm)\n    hence \"\\<forall>t \\<in> (\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>2)) \\<union> (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>2). wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\n      using Decompose.prems Decompose.hyps(2) unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by force\n    ultimately show ?thesis using Decompose.prems unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by presburger\n  qed (metis trms\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_eq_snd, metis trms\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_eq_rcv,\n       metis trms\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_eq_eq, metis trms\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_eq_ineq)\nqed metis\n\nprivate lemma pts_symbolic_c_preserves_tfr\\<^sub>s\\<^sub>t\\<^sub>p:\n  assumes \"(\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\\<^sup>* (\\<S>',\\<A>')\" \"\\<forall>S \\<in> \\<S> \\<union> {to_st \\<A>}. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n  shows \"\\<forall>S \\<in> \\<S>' \\<union> {to_st \\<A>'}. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\nusing assms\nproof (induction rule: rtranclp_induct2)\n  case (step \\<S>1 \\<A>1 \\<S>2 \\<A>2)\n  from step.hyps(2) step.IH[OF step.prems] show ?case\n  proof (induction rule: pts_symbolic_c_induct)\n    case Nil\n    have 1: \"\\<forall>S \\<in> {to_st \\<A>2}. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\" using Nil by simp\n    have 2: \"\\<S>2 = \\<S>1 - {[]}\" \"\\<forall>S \\<in> \\<S>1. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"  using Nil by simp_all\n    have \"\\<forall>S \\<in> \\<S>2. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n    proof\n      fix S assume \"S \\<in> \\<S>2\"\n      hence \"S \\<in> \\<S>1\" using 2(1) by simp\n      thus \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\" using 2(2) by simp\n    qed\n    thus ?case using 1 by auto\n  next\n    case (Send t S)\n    have 1: \"\\<forall>S \\<in> {to_st \\<A>2}. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\" using Send by (simp add: to_st_append)\n    have 2: \"\\<S>2 = insert S (\\<S>1 - {send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S})\" \"\\<forall>S \\<in> \\<S>1. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"  using Send by simp_all\n    have 3: \"\\<forall>S \\<in> \\<S>2. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n    proof\n      fix S' assume \"S' \\<in> \\<S>2\"\n      hence \"S' \\<in> \\<S>1 \\<or> S' = S\" using 2(1) by auto\n      moreover have \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\" using Send.hyps 2(2) by auto\n      ultimately show \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S'\" using 2(2) by blast\n    qed\n    thus ?case using 1 by auto\n  next\n    case (Receive t S)\n    have 1: \"\\<forall>S \\<in> {to_st \\<A>2}. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\" using Receive by (simp add: to_st_append)\n    have 2: \"\\<S>2 = insert S (\\<S>1 - {receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S})\" \"\\<forall>S \\<in> \\<S>1. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n      using Receive by simp_all\n    have 3: \"\\<forall>S \\<in> \\<S>2. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n    proof\n      fix S' assume \"S' \\<in> \\<S>2\"\n      hence \"S' \\<in> \\<S>1 \\<or> S' = S\" using 2(1) by auto\n      moreover have \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\" using Receive.hyps 2(2) by auto\n      ultimately show \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S'\" using 2(2) by blast\n    qed\n    show ?case using 1 3 by auto\n  next\n    case (Equality a t t' S)\n    have 1: \"to_st \\<A>2 = to_st \\<A>1@[\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t]\" \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (to_st \\<A>1)\"\n      using Equality by (simp_all add: to_st_append)\n    have 2: \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p [\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t]\" using Equality by fastforce\n    have 3: \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (to_st \\<A>2)\"\n      using tfr_stp_all_append[of \"to_st \\<A>1\" \"[\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t]\"] 1 2 by metis\n    hence 4: \"\\<forall>S \\<in> {to_st \\<A>2}. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\" using Equality by simp\n    have 5: \"\\<S>2 = insert S (\\<S>1 - {\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#S})\" \"\\<forall>S \\<in> \\<S>1. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n      using Equality by simp_all\n    have 6: \"\\<forall>S \\<in> \\<S>2. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n    proof\n      fix S' assume \"S' \\<in> \\<S>2\"\n      hence \"S' \\<in> \\<S>1 \\<or> S' = S\" using 5(1) by auto\n      moreover have \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\" using Equality.hyps 5(2) by auto\n      ultimately show \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S'\" using 5(2) by blast\n    qed\n    thus ?case using 4 by auto\n  next\n    case (Inequality X F S)\n    have 1: \"to_st \\<A>2 = to_st \\<A>1@[\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t]\" \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (to_st \\<A>1)\"\n      using Inequality by (simp_all add: to_st_append)\n    have \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t#S)\" using Inequality(1,4) by blast\n    hence 2: \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p [\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t]\" by simp\n    have 3: \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (to_st \\<A>2)\"\n      using tfr_stp_all_append[of \"to_st \\<A>1\" \"[\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t]\"] 1 2 by metis\n    hence 4: \"\\<forall>S \\<in> {to_st \\<A>2}. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\" using Inequality by simp\n    have 5: \"\\<S>2 = insert S (\\<S>1 - {\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t#S})\" \"\\<forall>S \\<in> \\<S>1. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n      using Inequality by simp_all\n    have 6: \"\\<forall>S \\<in> \\<S>2. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n    proof\n      fix S' assume \"S' \\<in> \\<S>2\"\n      hence \"S' \\<in> \\<S>1 \\<or> S' = S\" using 5(1) by auto\n      moreover have \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\" using Inequality.hyps 5(2) by auto\n      ultimately show \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S'\" using 5(2) by blast\n    qed\n    thus ?case using 4 by auto\n  next\n    case (Decompose f T)\n    hence 1: \"\\<forall>S \\<in> \\<S>2. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\" by blast\n    have 2: \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (to_st \\<A>1)\" \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (to_st [Decomp (Fun f T)])\"\n      using Decompose.prems decomp_tfr\\<^sub>s\\<^sub>t\\<^sub>p by auto\n    hence \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (to_st \\<A>1@to_st [Decomp (Fun f T)])\" by auto\n    hence \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (to_st \\<A>2)\"\n      using Decompose.hyps(3) to_st_append[of \\<A>1 \"[Decomp (Fun f T)]\"]\n      by auto\n    thus ?case using 1 by blast\n  qed\nqed\n\nprivate lemma pts_symbolic_c_preserves_well_analyzed:\n  assumes \"(\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\\<^sup>* (\\<S>',\\<A>')\" \"well_analyzed \\<A>\"\n  shows \"well_analyzed \\<A>'\"\nusing assms\nproof (induction rule: rtranclp_induct2)\n  case (step \\<S>1 \\<A>1 \\<S>2 \\<A>2)\n  from step.hyps(2) step.IH[OF step.prems] show ?case\n  proof (induction rule: pts_symbolic_c_induct)\n    case Receive thus ?case by (metis well_analyzed_singleton(1) well_analyzed_append)\n  next\n    case Send thus ?case by (metis well_analyzed_singleton(2) well_analyzed_append)\n  next\n    case Equality thus ?case by (metis well_analyzed_singleton(3) well_analyzed_append)\n  next\n    case Inequality thus ?case by (metis well_analyzed_singleton(4) well_analyzed_append)\n  next\n    case (Decompose f T)\n    hence \"Fun f T \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1 \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1) - (Var`\\<V>)\" by auto\n    thus ?case by (metis well_analyzed.Decomp Decompose.prems Decompose.hyps(3))\n  qed simp\nqed metis\n\nprivate lemma pts_symbolic_c_preserves_Ana_invar_subst:\n  assumes \"(\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\\<^sup>* (\\<S>',\\<A>')\"\n    and \"Ana_invar_subst (\n          (\\<Union>(ik\\<^sub>s\\<^sub>t ` dual\\<^sub>s\\<^sub>t ` \\<S>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)) \\<union>\n          (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)))\"\n  shows \"Ana_invar_subst (\n          (\\<Union>(ik\\<^sub>s\\<^sub>t ` dual\\<^sub>s\\<^sub>t ` \\<S>') \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>')) \\<union>\n          (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>') \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>')))\"\nusing assms\nproof (induction rule: rtranclp_induct2)\n  case (step \\<S>1 \\<A>1 \\<S>2 \\<A>2)\n  from step.hyps(2) step.IH[OF step.prems] show ?case\n  proof (induction rule: pts_symbolic_c_induct)\n    case Nil\n    hence \"\\<Union>(ik\\<^sub>s\\<^sub>t ` dual\\<^sub>s\\<^sub>t ` \\<S>1) = \\<Union>(ik\\<^sub>s\\<^sub>t ` dual\\<^sub>s\\<^sub>t ` \\<S>2)\"\n          \"\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>1) = \\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>2)\"\n      by force+\n    thus ?case using Nil by metis\n  next\n    case Send show ?case\n      using ik\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_subset_snd[OF Send.hyps]\n            Ana_invar_subst_subset[OF Send.prems]\n      by (metis Un_mono)\n  next\n    case Receive show ?case\n      using ik\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_subset_rcv[OF Receive.hyps]\n            Ana_invar_subst_subset[OF Receive.prems]\n      by (metis Un_mono)\n  next\n    case Equality show ?case\n      using ik\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_subset_eq[OF Equality.hyps]\n            Ana_invar_subst_subset[OF Equality.prems]\n      by (metis Un_mono)\n  next\n    case Inequality show ?case\n      using ik\\<^sub>s\\<^sub>t_update\\<^sub>s\\<^sub>t_subset_ineq[OF Inequality.hyps]\n            Ana_invar_subst_subset[OF Inequality.prems]\n      by (metis Un_mono)\n  next\n    case (Decompose f T)\n    let ?X = \"\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t`\\<S>2) \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>2\"\n    let ?Y = \"\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t`\\<S>1) \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1\"\n    obtain K M where Ana: \"Ana (Fun f T) = (K,M)\" by moura\n    hence *: \"ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>2 = ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1 \\<union> set M\" \"assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>2 = assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1\"\n      using ik\\<^sub>e\\<^sub>s\\<^sub>t_append assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append decomp_ik\n            decomp_assignment_rhs_empty Decompose.hyps(3)\n      by auto\n    { fix g S assume \"Fun g S \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t`\\<S>2) \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>2 \\<union> ?X)\"\n      hence \"Fun g S \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` \\<S>1) \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1 \\<union> set M \\<union> ?X)\"\n        using * Decompose.hyps(2) by auto\n      hence \"Fun g S \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` \\<S>1))\n            \\<or> Fun g S \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1)\n            \\<or> Fun g S \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (set M)\n            \\<or> Fun g S \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t`\\<S>1))\n            \\<or> Fun g S \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1)\"\n        using Decompose * Ana_fun_subterm[OF Ana] by auto\n      moreover have \"Fun f T \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1 \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1)\"\n        using trms\\<^sub>e\\<^sub>s\\<^sub>t_ik_subtermsI Decompose.hyps(1) by auto\n      hence \"subterms (Fun f T) \\<subseteq> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1 \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1)\"\n        by (metis in_subterms_subset_Union)\n      hence \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (set M) \\<subseteq> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1 \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1)\"\n        by (meson Un_upper2 Ana_subterm[OF Ana] subterms_subset_set psubsetE subset_trans)\n      ultimately have \"Fun g S \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t ` \\<S>1) \\<union> ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1 \\<union> ?Y)\"\n        by auto\n    }\n    thus ?case using Decompose unfolding Ana_invar_subst_def by metis\n  qed\nqed\n\nprivate lemma pts_symbolic_c_preserves_constr_disj_vars:\n  assumes \"(\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\\<^sup>* (\\<S>',\\<A>')\" \"wf\\<^sub>s\\<^sub>t\\<^sub>s' \\<S> \\<A>\" \"fv\\<^sub>e\\<^sub>s\\<^sub>t \\<A> \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A> = {}\"\n  shows \"fv\\<^sub>e\\<^sub>s\\<^sub>t \\<A>' \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>' = {}\"\nusing assms\nproof (induction rule: rtranclp_induct2)\n  case (step \\<S>1 \\<A>1 \\<S>2 \\<A>2)\n  have *: \"\\<And>S. S \\<in> \\<S>1 \\<Longrightarrow> fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1 = {}\" \"\\<And>S. S \\<in> \\<S>1 \\<Longrightarrow> fv\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1 \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\"\n    using pts_symbolic_c_preserves_wf_prot[OF step.hyps(1) step.prems(1)]\n    unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def by auto\n  from step.hyps(2) step.IH[OF step.prems]\n  show ?case\n  proof (induction rule: pts_symbolic_c_induct)\n    case Nil thus ?case by auto\n  next\n    case (Send t S)\n    hence \"fv\\<^sub>e\\<^sub>s\\<^sub>t \\<A>2 = fv\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1 \\<union> fv t\" \"bvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>2 = bvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1\"\n          \"fv\\<^sub>s\\<^sub>t (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S) = fv t \\<union> fv\\<^sub>s\\<^sub>t S\"\n      using fv\\<^sub>e\\<^sub>s\\<^sub>t_append bvars\\<^sub>e\\<^sub>s\\<^sub>t_append by simp+\n    thus ?case using *(1)[OF Send(1)] Send(4) by auto\n  next\n    case (Receive t S)\n    hence \"fv\\<^sub>e\\<^sub>s\\<^sub>t \\<A>2 = fv\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1 \\<union> fv t\" \"bvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>2 = bvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1\"\n          \"fv\\<^sub>s\\<^sub>t (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#S) = fv t \\<union> fv\\<^sub>s\\<^sub>t S\"\n      using fv\\<^sub>e\\<^sub>s\\<^sub>t_append bvars\\<^sub>e\\<^sub>s\\<^sub>t_append by simp+\n    thus ?case using *(1)[OF Receive(1)] Receive(4) by auto\n  next\n    case (Equality a t t' S)\n    hence \"fv\\<^sub>e\\<^sub>s\\<^sub>t \\<A>2 = fv\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1 \\<union> fv t \\<union> fv t'\" \"bvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>2 = bvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1\"\n          \"fv\\<^sub>s\\<^sub>t (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#S) = fv t \\<union> fv t' \\<union> fv\\<^sub>s\\<^sub>t S\"\n      using fv\\<^sub>e\\<^sub>s\\<^sub>t_append bvars\\<^sub>e\\<^sub>s\\<^sub>t_append by fastforce+\n    thus ?case using *(1)[OF Equality(1)] Equality(4) by auto\n  next\n    case (Inequality X F S)\n    hence \"fv\\<^sub>e\\<^sub>s\\<^sub>t \\<A>2 = fv\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1 \\<union> (fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F - set X)\" \"bvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>2 = bvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1 \\<union> set X\"\n          \"fv\\<^sub>s\\<^sub>t (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t#S) = (fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F - set X) \\<union> fv\\<^sub>s\\<^sub>t S\"\n      using fv\\<^sub>e\\<^sub>s\\<^sub>t_append bvars\\<^sub>e\\<^sub>s\\<^sub>t_append strand_vars_split(3)[of \"[\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t]\" S]\n      by auto+\n    moreover have \"fv\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1 \\<inter> set X = {}\" using *(2)[OF Inequality(1)] by auto\n    ultimately show ?case using *(1)[OF Inequality(1)] Inequality(4) by auto\n  next\n    case (Decompose f T)\n    thus ?case\n      using Decompose(3,4) bvars_decomp ik_assignment_rhs_decomp_fv[OF Decompose(1)] by auto\n  qed\nqed\n\n\nsubsubsection \\<open>Theorem: The Typing Result Lifted to the Transition System Level\\<close>\nprivate lemma wf\\<^sub>s\\<^sub>t\\<^sub>s'_decomp_rm:\n  assumes \"well_analyzed A\" \"wf\\<^sub>s\\<^sub>t\\<^sub>s' S (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t A)\" shows \"wf\\<^sub>s\\<^sub>t\\<^sub>s' S A\"\nunfolding wf\\<^sub>s\\<^sub>t\\<^sub>s'_def\nproof (intro conjI)\n  show \"\\<forall>S\\<in>S. wf\\<^sub>s\\<^sub>t (wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t A) (dual\\<^sub>s\\<^sub>t S)\"\n    by (metis (no_types) assms(2) wf\\<^sub>s\\<^sub>t\\<^sub>s'_def wfrestrictedvars\\<^sub>e\\<^sub>s\\<^sub>t_decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_subset\n                wf_vars_mono le_iff_sup)\n\n  show \"\\<forall>Sa\\<in>S. \\<forall>S'\\<in>S. fv\\<^sub>s\\<^sub>t Sa \\<inter> bvars\\<^sub>s\\<^sub>t S' = {}\" by (metis assms(2) wf\\<^sub>s\\<^sub>t\\<^sub>s'_def)\n\n  show \"\\<forall>S\\<in>S. fv\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t A = {}\" by (metis assms(2) wf\\<^sub>s\\<^sub>t\\<^sub>s'_def bvars_decomp_rm)\n\n  show \"\\<forall>S\\<in>S. fv\\<^sub>e\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>t S = {}\" by (metis assms wf\\<^sub>s\\<^sub>t\\<^sub>s'_def well_analyzed_decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_fv)\nqed\n\nprivate lemma decomps\\<^sub>e\\<^sub>s\\<^sub>t_pts_symbolic_c:\n  assumes \"D \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A) (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A) \\<I>\"\n  shows \"(S,A) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\\<^sup>* (S,A@D)\"\nusing assms(1)\nproof (induction D rule: decomps\\<^sub>e\\<^sub>s\\<^sub>t.induct)\n  case (Decomp B f X K T)\n  have \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t A \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t A) \\<subseteq>\n        subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t (A@B) \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t (A@B))\"\n    using ik\\<^sub>e\\<^sub>s\\<^sub>t_append[of A B] assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t_append[of A B]\n    by auto\n  hence \"Fun f X \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t (A@B) \\<union> assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t (A@B))\" using Decomp.hyps by auto\n  hence \"(S,A@B) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c (S,A@B@[Decomp (Fun f X)])\"\n    using pts_symbolic_c.Decompose[of f X \"A@B\"]\n    by simp\n  thus ?case\n    using Decomp.IH rtrancl_into_rtrancl\n          rtranclp_rtrancl_eq[of pts_symbolic_c \"(S,A)\" \"(S,A@B)\"]\n    by auto\nqed simp\n\nprivate lemma pts_symbolic_to_pts_symbolic_c:\n  assumes \"(\\<S>,to_st (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\\<^sub>d)) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sup>* (\\<S>',\\<A>')\" \"sem\\<^sub>e\\<^sub>s\\<^sub>t_d {} \\<I> (to_est \\<A>')\" \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c {} \\<I> \\<A>\\<^sub>d\"\n  and wf: \"wf\\<^sub>s\\<^sub>t\\<^sub>s' \\<S> (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\\<^sub>d)\" \"wf\\<^sub>e\\<^sub>s\\<^sub>t {} \\<A>\\<^sub>d\"\n  and tar: \"Ana_invar_subst ((\\<Union>(ik\\<^sub>s\\<^sub>t` dual\\<^sub>s\\<^sub>t` \\<S>) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\\<^sub>d))\n                            \\<union> (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t` \\<S>) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\\<^sub>d)))\"\n  and wa: \"well_analyzed \\<A>\\<^sub>d\"\n  and \\<I>: \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\"\n  shows \"\\<exists>\\<A>\\<^sub>d'. \\<A>' = to_st (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\\<^sub>d') \\<and> (\\<S>,\\<A>\\<^sub>d) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\\<^sup>* (\\<S>',\\<A>\\<^sub>d') \\<and> sem\\<^sub>e\\<^sub>s\\<^sub>t_c {} \\<I> \\<A>\\<^sub>d'\"\nusing assms(1,2)\nproof (induction rule: rtranclp_induct2)\n  case refl thus ?case using assms by auto\nnext\n  case (step \\<S>1 \\<A>1 \\<S>2 \\<A>2)\n  have \"sem\\<^sub>e\\<^sub>s\\<^sub>t_d {} \\<I> (to_est \\<A>1)\" using step.hyps(2) step.prems\n    by (induct rule: pts_symbolic_induct, metis, (metis sem\\<^sub>e\\<^sub>s\\<^sub>t_d_split_left to_est_append)+)\n  then obtain \\<A>1d where\n      \\<A>1d: \"\\<A>1 = to_st (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1d)\" \"(\\<S>, \\<A>\\<^sub>d) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\\<^sup>* (\\<S>1, \\<A>1d)\" \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c {} \\<I> \\<A>1d\"\n    using step.IH by moura\n\n  show ?case using step.hyps(2)\n  proof (induction rule: pts_symbolic_induct)\n    case Nil\n    hence \"(\\<S>, \\<A>\\<^sub>d) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\\<^sup>* (\\<S>2, \\<A>1d)\" using \\<A>1d pts_symbolic_c.Nil[OF Nil.hyps(1), of \\<A>1d] by simp\n    thus ?case using \\<A>1d Nil by auto\n  next\n    case (Send t S)\n    hence \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c {} \\<I> (\\<A>1d@[Step (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)])\" using sem\\<^sub>e\\<^sub>s\\<^sub>t_c.Receive[OF \\<A>1d(3)] by simp\n    moreover have \"(\\<S>1, \\<A>1d) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c (\\<S>2, \\<A>1d@[Step (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)])\"\n      using Send.hyps(2) pts_symbolic_c.Send[OF Send.hyps(1), of \\<A>1d] by simp\n    moreover have \"to_st (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t (\\<A>1d@[Step (receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)])) = \\<A>2\"\n      using Send.hyps(3) decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append \\<A>1d(1) by (simp add: to_st_append)\n    ultimately show ?case using \\<A>1d(2) by auto\n  next\n    case (Equality a t t' S)\n    hence \"t \\<cdot> \\<I> = t' \\<cdot> \\<I>\"\n      using step.prems sem\\<^sub>e\\<^sub>s\\<^sub>t_d_eq_sem_st[of \"{}\" \\<I> \"to_est \\<A>2\"]\n            to_st_append to_est_append to_st_to_est_inv\n      by auto\n    hence \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c {} \\<I> (\\<A>1d@[Step (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t)])\" using sem\\<^sub>e\\<^sub>s\\<^sub>t_c.Equality[OF \\<A>1d(3)] by simp\n    moreover have \"(\\<S>1, \\<A>1d) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c (\\<S>2, \\<A>1d@[Step (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t)])\"\n      using Equality.hyps(2) pts_symbolic_c.Equality[OF Equality.hyps(1), of \\<A>1d] by simp\n    moreover have \"to_st (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t (\\<A>1d@[Step (\\<langle>a: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t)])) = \\<A>2\"\n      using Equality.hyps(3) decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append \\<A>1d(1) by (simp add: to_st_append)\n    ultimately show ?case using \\<A>1d(2) by auto\n  next\n    case (Inequality X F S)\n    hence \"ineq_model \\<I> X F\"\n      using step.prems sem\\<^sub>e\\<^sub>s\\<^sub>t_d_eq_sem_st[of \"{}\" \\<I> \"to_est \\<A>2\"]\n            to_st_append to_est_append to_st_to_est_inv\n      by auto\n    hence \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c {} \\<I> (\\<A>1d@[Step (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t)])\" using sem\\<^sub>e\\<^sub>s\\<^sub>t_c.Inequality[OF \\<A>1d(3)] by simp\n    moreover have \"(\\<S>1, \\<A>1d) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c (\\<S>2, \\<A>1d@[Step (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t)])\"\n      using Inequality.hyps(2) pts_symbolic_c.Inequality[OF Inequality.hyps(1), of \\<A>1d] by simp\n    moreover have \"to_st (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t (\\<A>1d@[Step (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t)])) = \\<A>2\"\n      using Inequality.hyps(3) decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append \\<A>1d(1) by (simp add: to_st_append)\n    ultimately show ?case using \\<A>1d(2) by auto\n  next\n    case (Receive t S)\n    hence \"ik\\<^sub>s\\<^sub>t \\<A>1 \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> t \\<cdot> \\<I>\"\n      using step.prems sem\\<^sub>e\\<^sub>s\\<^sub>t_d_eq_sem_st[of \"{}\" \\<I> \"to_est \\<A>2\"]\n            strand_sem_split(4)[of \"{}\" \\<A>1 \"[send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t]\" \\<I>]\n            to_st_append to_est_append to_st_to_est_inv\n      by auto\n    moreover have \"ik\\<^sub>s\\<^sub>t \\<A>1 \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<subseteq> ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1d \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" using \\<A>1d(1) decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_ik_subset by auto\n    ultimately have *: \"ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1d \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> t \\<cdot> \\<I>\" using ideduct_mono by auto\n\n    have \"wf\\<^sub>s\\<^sub>t\\<^sub>s' \\<S> \\<A>\\<^sub>d\" by (rule wf\\<^sub>s\\<^sub>t\\<^sub>s'_decomp_rm[OF wa assms(4)])\n    hence **: \"wf\\<^sub>e\\<^sub>s\\<^sub>t {} \\<A>1d\" by (rule pts_symbolic_c_preserves_wf_is[OF \\<A>1d(2) _ assms(5)])\n\n    have \"Ana_invar_subst (\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t`\\<S>1) \\<union> (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1d) \\<union>\n                           (\\<Union>(assignment_rhs\\<^sub>s\\<^sub>t`\\<S>1) \\<union> (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1d)))\"\n      using tar \\<A>1d(2) pts_symbolic_c_preserves_Ana_invar_subst by metis\n    hence \"Ana_invar_subst (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1d)\" \"Ana_invar_subst (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1d)\"\n      using Ana_invar_subst_subset by blast+\n    moreover have \"well_analyzed \\<A>1d\"\n      using pts_symbolic_c_preserves_well_analyzed[OF \\<A>1d(2) wa] by metis\n    ultimately obtain D where D:\n        \"D \\<in> decomps\\<^sub>e\\<^sub>s\\<^sub>t (ik\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1d) (assignment_rhs\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1d) \\<I>\"\n        \"ik\\<^sub>e\\<^sub>s\\<^sub>t (\\<A>1d@D) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile>\\<^sub>c t \\<cdot> \\<I>\"\n      using decomps\\<^sub>e\\<^sub>s\\<^sub>t_exist_subst[OF * \\<A>1d(3) ** assms(8)] unfolding Ana_invar_subst_def by auto\n\n    have \"(\\<S>, \\<A>\\<^sub>d) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\\<^sup>* (\\<S>1, \\<A>1d@D)\" using \\<A>1d(2) decomps\\<^sub>e\\<^sub>s\\<^sub>t_pts_symbolic_c[OF D(1), of \\<S>1] by auto\n    hence \"(\\<S>, \\<A>\\<^sub>d) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\\<^sup>* (\\<S>2, \\<A>1d@D@[Step (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)])\"\n      using Receive(2) pts_symbolic_c.Receive[OF Receive.hyps(1), of \"\\<A>1d@D\"] by auto\n    moreover have \"\\<A>2 = to_st (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t (\\<A>1d@D@[Step (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)]))\"\n      using Receive.hyps(3) \\<A>1d(1) decomps\\<^sub>e\\<^sub>s\\<^sub>t_decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_empty[OF D(1)]\n            decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append to_st_append\n      by auto\n    moreover have \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c {} \\<I> (\\<A>1d@D@[Step (send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t)])\"\n      using D(2) sem\\<^sub>e\\<^sub>s\\<^sub>t_c.Send[OF sem\\<^sub>e\\<^sub>s\\<^sub>t_c_decomps\\<^sub>e\\<^sub>s\\<^sub>t_append[OF \\<A>1d(3) D(1)]] by simp\n    ultimately show ?case by auto\n  qed\nqed\n\nprivate lemma pts_symbolic_c_to_pts_symbolic:\n  assumes \"(\\<S>,\\<A>) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\\<^sup>* (\\<S>',\\<A>')\" \"sem\\<^sub>e\\<^sub>s\\<^sub>t_c {} \\<I> \\<A>'\"\n  shows \"(\\<S>,to_st (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sup>* (\\<S>',to_st (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t \\<A>'))\"\n        \"sem\\<^sub>e\\<^sub>s\\<^sub>t_d {} \\<I> (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t \\<A>')\"\nproof -\n  show \"(\\<S>,to_st (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sup>* (\\<S>',to_st (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t \\<A>'))\" using assms(1)\n  proof (induction rule: rtranclp_induct2)\n    case (step \\<S>1 \\<A>1 \\<S>2 \\<A>2) show ?case using step.hyps(2,1) step.IH\n    proof (induction rule: pts_symbolic_c_induct)\n      case Nil thus ?case\n        using pts_symbolic.Nil[OF Nil.hyps(1), of \"to_st (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1)\"] by simp\n    next\n      case (Send t S) thus ?case\n        using pts_symbolic.Send[OF Send.hyps(1), of \"to_st (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1)\"]\n        by (simp add: decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append to_st_append)\n    next\n      case (Receive t S) thus ?case\n        using pts_symbolic.Receive[OF Receive.hyps(1), of \"to_st (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1)\"]\n        by (simp add: decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append to_st_append)\n    next\n      case (Equality a t t' S) thus ?case\n        using pts_symbolic.Equality[OF Equality.hyps(1), of \"to_st (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1)\"]\n        by (simp add: decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append to_st_append)\n    next\n      case (Inequality t t' S) thus ?case\n        using pts_symbolic.Inequality[OF Inequality.hyps(1), of \"to_st (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t \\<A>1)\"]\n        by (simp add: decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append to_st_append)\n    next\n      case (Decompose t) thus ?case using decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_append by simp\n    qed\n  qed simp\nqed (rule sem\\<^sub>e\\<^sub>s\\<^sub>t_d_decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t_if_sem\\<^sub>e\\<^sub>s\\<^sub>t_c[OF assms(2)])\n\nprivate lemma pts_symbolic_to_pts_symbolic_c_from_initial:\n  assumes \"(\\<S>\\<^sub>0,[]) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sup>* (\\<S>,\\<A>)\" \"\\<I> \\<Turnstile> \\<langle>\\<A>\\<rangle>\" \"wf\\<^sub>s\\<^sub>t\\<^sub>s' \\<S>\\<^sub>0 []\"\n  and \"Ana_invar_subst (\\<Union>(ik\\<^sub>s\\<^sub>t ` dual\\<^sub>s\\<^sub>t ` \\<S>\\<^sub>0) \\<union> \\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>\\<^sub>0))\" \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\"\n  shows \"\\<exists>\\<A>\\<^sub>d. \\<A> = to_st (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\\<^sub>d) \\<and> (\\<S>\\<^sub>0,[]) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\\<^sup>* (\\<S>,\\<A>\\<^sub>d) \\<and> (\\<I> \\<Turnstile>\\<^sub>c \\<langle>to_st \\<A>\\<^sub>d\\<rangle>)\"\nusing assms pts_symbolic_to_pts_symbolic_c[of \\<S>\\<^sub>0 \"[]\" \\<S> \\<A> \\<I>]\n      sem\\<^sub>e\\<^sub>s\\<^sub>t_c_eq_sem_st[of \"{}\" \\<I>] sem\\<^sub>e\\<^sub>s\\<^sub>t_d_eq_sem_st[of \"{}\" \\<I>]\n      to_st_to_est_inv[of \\<A>] strand_sem_eq_defs\nby (auto simp add: constr_sem_c_def constr_sem_d_def simp del: subst_range.simps)\n\nprivate lemma pts_symbolic_c_to_pts_symbolic_from_initial:\n  assumes \"(\\<S>\\<^sub>0,[]) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\\<^sup>* (\\<S>,\\<A>)\" \"\\<I> \\<Turnstile>\\<^sub>c \\<langle>to_st \\<A>\\<rangle>\"\n  shows \"(\\<S>\\<^sub>0,[]) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sup>* (\\<S>,to_st (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t \\<A>))\" \"\\<I> \\<Turnstile> \\<langle>to_st (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t \\<A>)\\<rangle>\"\nusing assms pts_symbolic_c_to_pts_symbolic[of \\<S>\\<^sub>0 \"[]\" \\<S> \\<A> \\<I>]\n      sem\\<^sub>e\\<^sub>s\\<^sub>t_c_eq_sem_st[of \"{}\" \\<I>] sem\\<^sub>e\\<^sub>s\\<^sub>t_d_eq_sem_st[of \"{}\" \\<I>] strand_sem_eq_defs\nby (auto simp add: constr_sem_c_def constr_sem_d_def)\n\nprivate lemma to_st_trms_wf:\n  assumes \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>e\\<^sub>s\\<^sub>t A)\"\n  shows \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t (to_st A))\"\nusing assms\nproof (induction A)\n  case (Cons x A)\n  hence IH: \"\\<forall>t \\<in> trms\\<^sub>s\\<^sub>t (to_st A). wf\\<^sub>t\\<^sub>r\\<^sub>m t\" by auto\n  with Cons show ?case\n  proof (cases x)\n    case (Decomp t)\n    hence \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" using Cons.prems by auto\n    obtain K T where Ana_t: \"Ana t = (K,T)\" by moura\n    hence \"trms\\<^sub>s\\<^sub>t (decomp t) \\<subseteq> {t} \\<union> set K \\<union> set T\" using decomp_set_unfold[OF Ana_t] by force\n    moreover have \"\\<forall>t \\<in> set T. wf\\<^sub>t\\<^sub>r\\<^sub>m t\" using Ana_subterm[OF Ana_t] \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m t\\<close> wf_trm_subterm by auto\n    ultimately have \"\\<forall>t \\<in> trms\\<^sub>s\\<^sub>t (decomp t). wf\\<^sub>t\\<^sub>r\\<^sub>m t\" using Ana_keys_wf'[OF Ana_t] \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m t\\<close> by auto\n    thus ?thesis using IH Decomp by auto\n  qed auto\nqed simp\n\nprivate lemma to_st_trms_SMP_subset: \"trms\\<^sub>s\\<^sub>t (to_st A) \\<subseteq> SMP (trms\\<^sub>e\\<^sub>s\\<^sub>t A)\"\nproof\n  fix t assume \"t \\<in> trms\\<^sub>s\\<^sub>t (to_st A)\" thus \"t \\<in> SMP (trms\\<^sub>e\\<^sub>s\\<^sub>t A)\"\n  proof (induction A)\n    case (Cons x A)\n    hence *: \"t \\<in> trms\\<^sub>s\\<^sub>t (to_st [x]) \\<union> trms\\<^sub>s\\<^sub>t (to_st A)\" using to_st_append[of \"[x]\" A] by auto\n    have **: \"trms\\<^sub>s\\<^sub>t (to_st A) \\<subseteq> trms\\<^sub>s\\<^sub>t (to_st (x#A))\" \"trms\\<^sub>e\\<^sub>s\\<^sub>t A \\<subseteq> trms\\<^sub>e\\<^sub>s\\<^sub>t (x#A)\"\n      using to_st_append[of \"[x]\" A] by auto\n    show ?case\n    proof (cases \"t \\<in> trms\\<^sub>s\\<^sub>t (to_st A)\")\n      case True thus ?thesis using Cons.IH SMP_mono[OF **(2)] by auto\n    next\n      case False\n      hence ***: \"t \\<in> trms\\<^sub>s\\<^sub>t (to_st [x])\" using * by auto\n      thus ?thesis\n      proof (cases x)\n        case (Decomp t')\n        hence ****: \"t \\<in> trms\\<^sub>s\\<^sub>t (decomp t')\" \"t' \\<in> trms\\<^sub>e\\<^sub>s\\<^sub>t (x#A)\" using *** by auto\n        obtain K T where Ana_t': \"Ana t' = (K,T)\" by moura\n        hence \"t \\<in> {t'} \\<union> set K \\<union> set T\" using decomp_set_unfold[OF Ana_t'] ****(1) by force\n        moreover\n        { assume \"t = t'\" hence ?thesis using SMP.MP[OF ****(2)] by simp }\n        moreover\n        { assume \"t \\<in> set K\" hence ?thesis using SMP.Ana[OF SMP.MP[OF ****(2)] Ana_t'] by auto }\n        moreover\n        { assume \"t \\<in> set T\" \"t \\<noteq> t'\"\n          hence \"t \\<sqsubset> t'\" using Ana_subterm[OF Ana_t'] by blast\n          hence ?thesis using SMP.Subterm[OF SMP.MP[OF ****(2)]] by auto\n        }\n        ultimately show ?thesis using Decomp by auto\n      qed auto\n    qed\n  qed simp\nqed\n\nprivate lemma to_st_trms_tfr\\<^sub>s\\<^sub>e\\<^sub>t:\n  assumes \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>e\\<^sub>s\\<^sub>t A)\"\n  shows \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t (to_st A))\"\nproof -\n  have *: \"trms\\<^sub>s\\<^sub>t (to_st A) \\<subseteq> SMP (trms\\<^sub>e\\<^sub>s\\<^sub>t A)\"\n    using to_st_trms_wf to_st_trms_SMP_subset assms unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by auto\n  have \"trms\\<^sub>s\\<^sub>t (to_st A) = trms\\<^sub>s\\<^sub>t (to_st A) \\<union> trms\\<^sub>e\\<^sub>s\\<^sub>t A\" by (blast dest!: trms\\<^sub>e\\<^sub>s\\<^sub>tD)\n  hence \"SMP (trms\\<^sub>e\\<^sub>s\\<^sub>t A) = SMP (trms\\<^sub>s\\<^sub>t (to_st A))\" using SMP_subset_union_eq[OF *] by auto\n  thus ?thesis using * assms unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by presburger\nqed\n\ntheorem wt_attack_if_tfr_attack_pts:\n  assumes \"wf\\<^sub>s\\<^sub>t\\<^sub>s \\<S>\\<^sub>0\" \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>\\<^sub>0))\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>\\<^sub>0))\" \"\\<forall>S \\<in> \\<S>\\<^sub>0. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n  and \"Ana_invar_subst (\\<Union>(ik\\<^sub>s\\<^sub>t ` dual\\<^sub>s\\<^sub>t ` \\<S>\\<^sub>0) \\<union> \\<Union>(assignment_rhs\\<^sub>s\\<^sub>t ` \\<S>\\<^sub>0))\"\n  and \"(\\<S>\\<^sub>0,[]) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sup>* (\\<S>,\\<A>)\" \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\" \"\\<I> \\<Turnstile> \\<langle>\\<A>, Var\\<rangle>\"\n  shows \"\\<exists>\\<I>\\<^sub>\\<tau>. interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\\<^sub>\\<tau> \\<and> (\\<I>\\<^sub>\\<tau> \\<Turnstile> \\<langle>\\<A>, Var\\<rangle>) \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\\<^sub>\\<tau> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<I>\\<^sub>\\<tau>)\"\nproof -\n  have \"(\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>\\<^sub>0)) \\<union> (trms\\<^sub>e\\<^sub>s\\<^sub>t []) = \\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>\\<^sub>0)\" \"to_st [] = []\" \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p []\"\n    using assms by simp_all\n  hence *: \"tfr\\<^sub>s\\<^sub>e\\<^sub>t ((\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>\\<^sub>0)) \\<union> (trms\\<^sub>e\\<^sub>s\\<^sub>t []))\"\n           \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s ((\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>\\<^sub>0)) \\<union> (trms\\<^sub>e\\<^sub>s\\<^sub>t []))\"\n           \"wf\\<^sub>s\\<^sub>t\\<^sub>s' \\<S>\\<^sub>0 []\" \"\\<forall>S \\<in> \\<S>\\<^sub>0 \\<union> {to_st []}. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n    using assms wf\\<^sub>s\\<^sub>t\\<^sub>s_wf\\<^sub>s\\<^sub>t\\<^sub>s' by (metis, metis, metis, simp)\n\n  obtain \\<A>\\<^sub>d where \\<A>\\<^sub>d: \"\\<A> = to_st (decomp_rm\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\\<^sub>d)\" \"(\\<S>\\<^sub>0,[]) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sub>c\\<^sup>* (\\<S>,\\<A>\\<^sub>d)\" \"\\<I> \\<Turnstile>\\<^sub>c \\<langle>to_st \\<A>\\<^sub>d\\<rangle>\"\n    using pts_symbolic_to_pts_symbolic_c_from_initial assms *(3) by metis\n  hence \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>) \\<union> (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\\<^sub>d))\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (\\<Union>(trms\\<^sub>s\\<^sub>t ` \\<S>) \\<union> (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\\<^sub>d))\"\n    using pts_symbolic_c_preserves_tfr\\<^sub>s\\<^sub>e\\<^sub>t[OF _ *(1,2)] by blast+\n  hence \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\\<^sub>d)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\\<^sub>d)\"\n    unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by (metis DiffE DiffI SMP_union UnCI, metis UnCI)\n  hence \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t (to_st \\<A>\\<^sub>d))\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t (to_st \\<A>\\<^sub>d))\"\n    by (metis to_st_trms_tfr\\<^sub>s\\<^sub>e\\<^sub>t, metis to_st_trms_wf)\n  moreover have \"wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r (to_st \\<A>\\<^sub>d) Var\"\n  proof -\n    have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t Var\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range Var)\" \"subst_domain Var \\<inter> vars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\\<^sub>d = {}\"\n         \"range_vars Var \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\\<^sub>d = {}\"\n      by (simp_all add: range_vars_alt_def)\n    moreover have \"wf\\<^sub>e\\<^sub>s\\<^sub>t {} \\<A>\\<^sub>d\"\n      using pts_symbolic_c_preserves_wf_is[OF \\<A>\\<^sub>d(2) *(3), of \"{}\"]\n      by auto\n    moreover have \"fv\\<^sub>s\\<^sub>t (to_st \\<A>\\<^sub>d) \\<inter> bvars\\<^sub>e\\<^sub>s\\<^sub>t \\<A>\\<^sub>d = {}\"\n      using pts_symbolic_c_preserves_constr_disj_vars[OF \\<A>\\<^sub>d(2)] assms(1) wf\\<^sub>s\\<^sub>t\\<^sub>s_wf\\<^sub>s\\<^sub>t\\<^sub>s'\n      by fastforce\n    ultimately show ?thesis unfolding wf\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>s\\<^sub>t\\<^sub>r_def wf\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def by simp\n  qed\n  moreover have \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (to_st \\<A>\\<^sub>d)\"\n    using pts_symbolic_c_preserves_tfr\\<^sub>s\\<^sub>t\\<^sub>p[OF \\<A>\\<^sub>d(2) *(4)] by blast\n  moreover have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t Var\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range Var)\" by simp_all\n  ultimately obtain \\<I>\\<^sub>\\<tau> where \\<I>\\<^sub>\\<tau>:\n      \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\\<^sub>\\<tau>\" \"\\<I>\\<^sub>\\<tau> \\<Turnstile>\\<^sub>c \\<langle>to_st \\<A>\\<^sub>d, Var\\<rangle>\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\\<^sub>\\<tau>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<I>\\<^sub>\\<tau>)\"\n    using wt_attack_if_tfr_attack[OF assms(7) \\<A>\\<^sub>d(3)]\n          \\<open>tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t (to_st \\<A>\\<^sub>d))\\<close> \\<open>list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (to_st \\<A>\\<^sub>d)\\<close>\n    unfolding tfr\\<^sub>s\\<^sub>t_def by metis\n  hence \"\\<I>\\<^sub>\\<tau> \\<Turnstile> \\<langle>\\<A>, Var\\<rangle>\" using pts_symbolic_c_to_pts_symbolic_from_initial \\<A>\\<^sub>d by metis\n  thus ?thesis using \\<I>\\<^sub>\\<tau>(1,3,4) by metis\nqed\n\n\nsubsubsection \\<open>Corollary: The Typing Result on the Level of Constraints\\<close>\ntext \\<open>There exists well-typed models of satisfiable type-flaw resistant constraints\\<close>\ncorollary wt_attack_if_tfr_attack_d:\n  assumes \"wf\\<^sub>s\\<^sub>t {} \\<A>\" \"fv\\<^sub>s\\<^sub>t \\<A> \\<inter> bvars\\<^sub>s\\<^sub>t \\<A> = {}\" \"tfr\\<^sub>s\\<^sub>t \\<A>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t \\<A>)\"\n  and \"Ana_invar_subst (ik\\<^sub>s\\<^sub>t \\<A> \\<union> assignment_rhs\\<^sub>s\\<^sub>t \\<A>)\"\n  and \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\" \"\\<I> \\<Turnstile> \\<langle>\\<A>\\<rangle>\"\n  shows \"\\<exists>\\<I>\\<^sub>\\<tau>. interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\\<^sub>\\<tau> \\<and> (\\<I>\\<^sub>\\<tau> \\<Turnstile> \\<langle>\\<A>\\<rangle>) \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\\<^sub>\\<tau> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<I>\\<^sub>\\<tau>)\"\nproof -\n  { fix S A have \"({S},A) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sup>* ({},A@dual\\<^sub>s\\<^sub>t S)\"\n    proof (induction S arbitrary: A)\n      case Nil thus ?case using pts_symbolic.Nil[of \"{[]}\"] by auto\n    next\n      case (Cons x S)\n      hence \"({S}, A@dual\\<^sub>s\\<^sub>t [x]) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sup>* ({}, A@dual\\<^sub>s\\<^sub>t (x#S))\"\n        by (metis dual\\<^sub>s\\<^sub>t_append List.append_assoc List.append_Nil List.append_Cons)\n      moreover have \"({x#S}, A) \\<Rightarrow>\\<^sup>\\<bullet> ({S}, A@dual\\<^sub>s\\<^sub>t [x])\"\n        using pts_symbolic.Send[of _ S \"{x#S}\"] pts_symbolic.Receive[of _ S \"{x#S}\"]\n              pts_symbolic.Equality[of _ _ _ S \"{x#S}\"] pts_symbolic.Inequality[of _ _ S \"{x#S}\"]\n        by (cases x) auto\n      ultimately show ?case by simp\n    qed\n  }\n  hence 0: \"({dual\\<^sub>s\\<^sub>t \\<A>},[]) \\<Rightarrow>\\<^sup>\\<bullet>\\<^sup>* ({},\\<A>)\" using dual\\<^sub>s\\<^sub>t_self_inverse by (metis List.append_Nil)\n\n  have \"fv\\<^sub>s\\<^sub>t (dual\\<^sub>s\\<^sub>t \\<A>) \\<inter> bvars\\<^sub>s\\<^sub>t (dual\\<^sub>s\\<^sub>t \\<A>) = {}\" using assms(2) dual\\<^sub>s\\<^sub>t_fv dual\\<^sub>s\\<^sub>t_bvars by metis+\n  hence 1: \"wf\\<^sub>s\\<^sub>t\\<^sub>s {dual\\<^sub>s\\<^sub>t \\<A>}\" using assms(1,2) dual\\<^sub>s\\<^sub>t_self_inverse[of \\<A>] unfolding wf\\<^sub>s\\<^sub>t\\<^sub>s_def by auto\n\n  have \"\\<Union>(trms\\<^sub>s\\<^sub>t ` {\\<A>}) = trms\\<^sub>s\\<^sub>t \\<A>\" \"\\<Union>(trms\\<^sub>s\\<^sub>t ` {dual\\<^sub>s\\<^sub>t \\<A>}) = trms\\<^sub>s\\<^sub>t (dual\\<^sub>s\\<^sub>t \\<A>)\" by auto\n  hence \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (\\<Union>(trms\\<^sub>s\\<^sub>t ` {\\<A>}))\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (\\<Union>(trms\\<^sub>s\\<^sub>t ` {\\<A>}))\"\n        \"(\\<Union>(trms\\<^sub>s\\<^sub>t ` {\\<A>})) = \\<Union>(trms\\<^sub>s\\<^sub>t ` {dual\\<^sub>s\\<^sub>t \\<A>})\"\n    using assms(3,4) unfolding tfr\\<^sub>s\\<^sub>t_def\n    by (metis, metis, metis dual\\<^sub>s\\<^sub>t_trms_eq)\n  hence 2: \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (\\<Union>(trms\\<^sub>s\\<^sub>t ` {dual\\<^sub>s\\<^sub>t \\<A>}))\" and 3: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (\\<Union>(trms\\<^sub>s\\<^sub>t ` {dual\\<^sub>s\\<^sub>t \\<A>}))\" by metis+\n\n  have 4: \"\\<forall>S \\<in> {dual\\<^sub>s\\<^sub>t \\<A>}. list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n    using dual\\<^sub>s\\<^sub>t_tfr\\<^sub>s\\<^sub>t\\<^sub>p assms(3) unfolding tfr\\<^sub>s\\<^sub>t_def by blast\n\n  have \"assignment_rhs\\<^sub>s\\<^sub>t \\<A> = assignment_rhs\\<^sub>s\\<^sub>t (dual\\<^sub>s\\<^sub>t \\<A>)\"\n    by (induct \\<A> rule: assignment_rhs\\<^sub>s\\<^sub>t.induct) auto\n  hence 5: \"Ana_invar_subst (\\<Union>(ik\\<^sub>s\\<^sub>t`dual\\<^sub>s\\<^sub>t`{dual\\<^sub>s\\<^sub>t \\<A>}) \\<union> \\<Union>(assignment_rhs\\<^sub>s\\<^sub>t`{dual\\<^sub>s\\<^sub>t \\<A>}))\"\n    using assms(5) dual\\<^sub>s\\<^sub>t_self_inverse[of \\<A>] by auto\n\n  show ?thesis by (rule wt_attack_if_tfr_attack_pts[OF 1 2 3 4 5 0 assms(6,7)])\nqed\n\nend\n\nend\n\nend\n\n", "meta": {"author": "logicalhacking", "repo": "Stateful_Protocol_Composition_and_Typing", "sha": "34755583e50bc8a2e3eb0f91350c0b8510422a16", "save_path": "github-repos/isabelle/logicalhacking-Stateful_Protocol_Composition_and_Typing", "path": "github-repos/isabelle/logicalhacking-Stateful_Protocol_Composition_and_Typing/Stateful_Protocol_Composition_and_Typing-34755583e50bc8a2e3eb0f91350c0b8510422a16/Stateful_Protocol_Composition_and_Typing/Typing_Result.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318337259583, "lm_q2_score": 0.4921881357207955, "lm_q1q2_score": 0.29724808334402086}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory IndirectCalls\n\nimports\n  \"PrettyProgs\"\n\nbegin\n\ndefinition\n  lookup_proc :: \"(string \\<Rightarrow> 'proc_addr) \\<Rightarrow> ('proc_id \\<rightharpoonup> string)\n    \\<Rightarrow> 'proc_addr \\<Rightarrow> 'proc_id\"\nwhere\n  \"lookup_proc symtab naming x\n    = (THE pid. naming pid \\<noteq> None \\<and> symtab (the (naming pid)) = x)\"\n\ndefinition\n  lookup_proc_safe :: \"(string \\<Rightarrow> 'proc_addr) \\<Rightarrow> ('proc_id \\<rightharpoonup> string)\n    \\<Rightarrow> 'proc_addr \\<Rightarrow> bool\"\nwhere\n  \"lookup_proc_safe symtab naming x\n    = (card {pid. naming pid \\<noteq> None \\<and> symtab (the (naming pid)) = x} = 1)\"\n\ndefinition\n  procs_consistent :: \"(string \\<Rightarrow> 'proc_addr) \\<Rightarrow> ('proc_nm \\<rightharpoonup> string)\n    \\<Rightarrow> bool\"\nwhere\n  \"procs_consistent symtab naming\n    = (finite (dom naming)\n        \\<and> (\\<forall>x y nm nm'. naming x = Some nm \\<and> naming y = Some nm'\n            \\<and> symtab nm = symtab nm'\n                \\<longrightarrow> x = y))\"\n\nlemma procs_consistent_eq:\n  \"\\<lbrakk> naming proc = Some nm; procs_consistent symtab naming; addr = symtab nm \\<rbrakk>\n    \\<Longrightarrow> lookup_proc symtab naming addr = proc\"\n  apply (clarsimp simp: procs_consistent_def lookup_proc_def)\n  apply (rule the_equality)\n   apply clarsimp\n  apply clarsimp\n  done\n\nlemma procs_consistent_safe:\n  \"\\<lbrakk> naming proc = Some nm; procs_consistent symtab naming; addr = symtab nm \\<rbrakk>\n    \\<Longrightarrow> lookup_proc_safe symtab naming addr\"\n  apply (clarsimp simp: procs_consistent_def lookup_proc_safe_def)\n  apply (rule trans, rule arg_cong[where f=card and y=\"{proc}\"])\n   apply auto\n  done\n\nlemma hoare_indirect_call_procs_consistent:\n  \"\\<lbrakk> naming proc = Some nm; \n        \\<Gamma> \\<turnstile> P (call initf proc ret c) Q, A \\<rbrakk>\n    \\<Longrightarrow> \\<Gamma> \\<turnstile> ({s. procs_consistent symtab naming \\<and> x_fn s = symtab nm} \\<inter> P)\n            (dynCall initf (\\<lambda>s. lookup_proc symtab naming (x_fn s))\n                    ret c) Q, A\"\n  apply (rule hoare_complete, drule hoare_sound)\n  apply (clarsimp simp: cvalid_def HoarePartialDef.valid_def)\n  apply (erule exec_dynCall_Normal_elim)\n  apply (simp add: procs_consistent_eq)\n  apply blast\n  done\n\nend\n\n", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/c-parser/IndirectCalls.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5851011542032312, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.29712130790785707}}
{"text": "           (*-------------------------------------------*\n            |                DFP package                |\n            |                   June 2005               |\n            |               December 2005  (modified)   |\n            |                                           |\n            |   DFP on CSP-Prover ver.3.0               |\n            |              September 2006  (modified)   |\n            |                  April 2007  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2017         |\n            |                  April 2018  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory DFP_Deadlock\nimports DFP_Network\nbegin\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite UnionT and InterT.                 *)\n(*                  Union (B ` A) = (UN x:A. B x)                      *)\n(*                  Inter (B ` A) = (INT x:A. B x)                     *)\n(*\ndeclare Union_image_eq [simp del]\ndeclare Inter_image_eq [simp del]\n*)\n(* no simp rules in Isabelle 2017 \ndeclare Sup_image_eq [simp del]\ndeclare Inf_image_eq [simp del]\n*)\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite (notick | t = []t)                 *)\n(*                                                                     *)\n(*                  disj_not1: (~ P | Q) = (P --> Q)                   *)\n\ndeclare disj_not1 [simp del]\n\n(*****************************************************************\n\n         1. \n         2. \n         3. \n         4. \n\n *****************************************************************)\n\n(*********************************************************\n                    definitions\n *********************************************************)\n\ndefinition\n  DeadlockFree :: \"'a event set => ('p,'a) proc => bool\" \n                                           (\"(0[_]-DeadlockFree _)\" [0,55] 55)\n  where\n  DeadlockFree_def : \n    \"[X]-DeadlockFree P == (ALL s. (Tick ~: sett(s)) --> (s,X) ~:f failures P MF)\"\n\n  (* R is deadlock free with respect to X, thus\n     R can always perform an event in X at least *)\n\ndefinition     \n  DeadlockFreeNetwork :: \"('i,'p,'a) Network => bool\" \n  where\n  DeadlockFreeNetwork_def : \n    \"DeadlockFreeNetwork V == \n     [Ev ` (ALP V)]-DeadlockFree PAR V\"\n\n\n(*** UNIV deadlockfree ***)\n\nsyntax\n  \"@isDeadlockFree\"  :: \"('p,'a) proc => bool\" \n                         (\"_ isDeadlockFree\" [1000] 1000)\n\ntranslations\n  \"P isDeadlockFree\"  == \"[(CONST UNIV)]-DeadlockFree P\"\n\ndefinition\n  isDeadlockStateOf :: \n   \"('i,'a) net_state => ('i,'a) NetworkF => bool\"\n                           (\"(0_ isDeadlockStateOf _)\" [55,55] 55)\n  where\n  isDeadlockStateOf_def : \n   \"sigma isDeadlockStateOf VF == \n                sigma isStateOf VF & \n                Union {((snd sigma) i) |i. i : fst VF}\n                = Ev ` (ALP VF)\"\n\n(*********************************************************\n           isDeadlockStateOf subset alpha\n *********************************************************)\n\nlemma isDeadlockStateOf_subset_alpha1:\n   \"[| (I, FXf) isFailureOf (I, PXf) ; \n       (t, Yf) isDeadlockStateOf (I, FXf) ;\n       i : I ; e : Yf i|]\n    ==> e : (Ev ` (snd (PXf i)))\"\napply (simp add: isDeadlockStateOf_def)\napply (auto simp add: isStateOf_subset_alpha)\ndone\n\nlemma isDeadlockStateOf_subset_alpha2:\n   \"[| (I, FXf) isFailureOf (I, PXf) ; \n       (t, Yf) isDeadlockStateOf (I, FXf) ;\n       i : I ; e : Yf i|]\n    ==> e : (Ev ` (snd (FXf i)))\"\napply (simp add: isDeadlockStateOf_def)\napply (auto simp add: isStateOf_subset_alpha)\ndone\n\nlemmas isDeadlockStateOf_subset_alpha = isDeadlockStateOf_subset_alpha1\n                                        isDeadlockStateOf_subset_alpha2\n\n(*********************************************************\n             Deadlock and Deadlock freedom\n *********************************************************)\n\n(*** Existency ***)\n\nlemma DeadlockState_notDeadlockFree_only_if_lmEX_lm:\n  \"[|  ALL s Y.\n                 (s, Y) : fst (FXf i) -->\n                 (s, Y) :f failures (fst (PXf i)) MF & Y <= Ev ` snd (FXf i);\n        (s rest-tr snd (FXf i), Z) : fst (FXf i);\n              Yf i Int Ev ` snd (FXf i) <= Z |]\n           ==> (s rest-tr snd (FXf i),\n                SOME Z.\n                   (s rest-tr snd (FXf i), Z) : fst (FXf i) &\n                   Yf i Int Ev ` snd (FXf i) <= Z & Z <= Ev ` snd (FXf i))\n               : fst (FXf i) &\n               Yf i Int Ev ` snd (FXf i)\n               <= (SOME Z.\n                      (s rest-tr snd (FXf i), Z) : fst (FXf i) &\n                      Yf i Int Ev ` snd (FXf i) <= Z & Z <= Ev ` snd (FXf i)) &\n               (SOME Z.\n                   (s rest-tr snd (FXf i), Z) : fst (FXf i) &\n                   Yf i Int Ev ` snd (FXf i) <= Z & Z <= Ev ` snd (FXf i))\n               <= Ev ` snd (FXf i)\"\napply (rule someI2[of\n\"(%Z. (s rest-tr snd (FXf i), Z) : fst (FXf i) &\n      Yf i Int Ev ` snd (FXf i) <= Z & Z <= Ev ` snd (FXf i))\" Z])\napply (rule conjI)\napply (simp)\napply (simp)\napply (simp)\ndone\n\nlemma DeadlockState_notDeadlockFree_only_if_lmEX:\n   \"[| (I, FXf) isFailureOf (I, PXf) ;\n       ALL i:I. (s rest-tr (snd (PXf i)), Yf i)\n                :f failures (fst (PXf i)) MF |]\n    ==>\n    EX Zf. ALL i:I. (s rest-tr (snd (FXf i)), Zf i) : fst (FXf i) &\n                    Yf i Int Ev ` snd (FXf i) <= Zf i &\n                    Zf i <= Ev ` snd (FXf i)\"\n apply (rule_tac x=\n   \"(%i. (SOME Z. (s rest-tr (snd (FXf i)), Z) : fst (FXf i) &\n                    Yf i Int Ev ` snd (FXf i) <= Z &\n                    Z <= Ev ` snd (FXf i)))\" in exI)\napply (intro ballI impI)\napply (simp add: isFailureOf_def)\napply (drule_tac x=\"i\" in bspec, simp)\napply (drule_tac x=\"i\" in bspec, simp)\napply (simp add: subseteqEX_restRefusal_iff)\napply (elim conjE exE)\napply (rotate_tac -2)\n\napply (drule_tac x=\"s rest-tr snd (FXf i)\" in spec)\napply (drule_tac x=\"Yf i\" in spec)\napply (simp)\napply (elim conjE exE)\napply (rule DeadlockState_notDeadlockFree_only_if_lmEX_lm)\napply (simp_all)\napply (force)\ndone\n\n(* only if part *)\n       \nlemma DeadlockState_notDeadlockFree_only_if:\n  \"[| I ~= {} ; finite I ; (I,FXf) isFailureOf (I,PXf) ;\n      ~ DeadlockFreeNetwork (I,PXf) |]\n   ==> (EX sigma. (sigma isDeadlockStateOf (I,FXf)))\"\napply (simp add: DeadlockFreeNetwork_def)\napply (simp add: DeadlockFree_def)\napply (simp add: isDeadlockStateOf_def)\napply (subgoal_tac \"Union (snd ` PXf ` I) = {a. EX i:I. a : snd (FXf i)}\")\n                                               (* ... sub 1 *)\n\n apply (elim conjE exE)\n apply (simp add: PAR_def)\n apply (simp add: in_failures_par)\n apply (elim conjE exE)\n\n apply (subgoal_tac \n   \"EX Zf. ALL i:I. (s rest-tr (snd (FXf i)), Zf i) :  fst (FXf i) & \n           ((Yf i) Int (Ev ` snd (FXf i))) <= Zf i &\n           Zf i <= (Ev ` snd (FXf i))\")\n                                               (* ... sub 2 *)\n  apply (elim conjE exE)\n\n apply (rule_tac x=\"s\" in exI)\n apply (rule_tac x=\"Zf\" in exI)\n apply (rule conjI)\n\n  apply (simp add: isStateOf_def)\n  apply (simp add: ALP_def)\n  apply (simp add: subset_insert)\n\n  (* set *)\n  apply (simp add: ALP_def)\n  apply (simp add: isFailureOf_def)\n  apply (simp add: Int_insert_eq)\n  apply (rule)\n   (* <= *)\n   apply (rotate_tac -3)\n   apply (drule sym)\n   apply (simp)\n   apply (rule)\n   apply (simp)\n   apply (elim conjE exE)\n   apply (simp)\n   apply (rotate_tac 1)\n   apply (drule_tac x=\"i\" in bspec, simp)\n   apply (elim conjE)\n\n   apply (rule rev_subsetD)\n   apply (simp)\n   apply (simp)\n   apply (rule order_trans)\n   apply (simp)\n\n   apply (rule)\n   apply (simp add: image_iff)\n   apply (elim conjE bexE)\n   apply (simp)\n   apply (rule_tac x=\"i\" in bexI)\n   apply (simp)\n   apply (simp)\n\n   (* => *)\n   apply (rule)\n   apply (simp)\n   apply (elim conjE bexE exE)\n   apply (simp)\n   apply (rule_tac x=\"Zf i\" in exI)\n   apply (rule conjI)\n   apply (fast)\n\n   apply (elim conjE disjE)\n    apply (drule_tac x=\"i\" in bspec, simp)\n    apply (simp)\n    apply (subgoal_tac \n      \"Tick : Union {(Yf i Int insert Tick (Ev ` snd (PXf i))) |i. i : I}\")\n     apply (rotate_tac 5)\n     apply (drule sym)\n     apply (simp add: image_iff)\n    apply (simp)\n    apply (rule_tac x=\"Yf i Int insert Tick (Ev ` snd (PXf i))\" in exI, simp)\n    apply (rule_tac x=\"i\" in exI, simp)\n\n    apply (rotate_tac -5)\n    apply (drule_tac x=\"i\" in bspec, simp)\n    apply (elim conjE disjE)\n    apply (rule subsetD)\n    apply (simp)\n    apply (fast)\n\n (* sub 2 *)\n apply (simp add: DeadlockState_notDeadlockFree_only_if_lmEX)\n\n(* sub 1 *)\napply (simp add: isFailureOf_def)\napply (auto)\ndone\n\n(*** if part ***)\n\nlemma DeadlockState_notDeadlockFree_if:\n  \"[| I ~= {} ; finite I ; (I,FXf) isFailureOf (I,PXf) ;\n      EX sigma. (sigma isDeadlockStateOf (I,FXf)) |]\n   ==> ~ DeadlockFreeNetwork (I,PXf)\"\napply (simp add: DeadlockFreeNetwork_def)\napply (simp add: DeadlockFree_def)\napply (simp add: isDeadlockStateOf_def)\n\napply (elim conjE exE)\napply (simp add: PAR_def)\n\napply (rule_tac x=\"a\" in exI)\napply (simp add: in_failures_par)\napply (simp add: isStateOf_def ALP_def)\n\napply (elim conjE exE)\napply (rule conjI)\napply (fast)\napply (rule conjI)\n\napply (rule order_trans)\napply (simp)\napply (simp add: isFailureOf_def)\napply (fast)\n\napply (rule_tac x=\"b\" in exI)\napply (rename_tac s Ys)\napply (drule sym)\napply (simp)\napply (subgoal_tac \"Union (snd ` PXf ` I) = {a. EX i:I. a : snd (PXf i)}\")\napply (simp add: Int_insert_eq)\napply (rule conjI)\n apply (rule)\n\n (* <= *)\n  apply (rule)\n   apply (simp add: image_iff)\n   apply (elim conjE exE bexE)\n   apply (simp)\n   apply (subgoal_tac \"x : Ev ` {a. EX i:I. a : snd (FXf i)}\")\n\n    apply (simp)\n    apply (elim conjE exE)\n    apply (rule_tac x=\"Ys ia Int insert Tick (Ev ` snd (PXf ia))\" in exI)\n    apply (rule conjI)\n    apply (fast)\n\n    apply (simp)\n    apply (drule_tac x=\"ia\" in bspec, simp)\n    apply (simp add: isFailureOf_same_alpha)\n    apply (blast)\n\n   apply (simp (no_asm) add: image_iff)\n   apply (rule_tac x=\"xa\" in exI)\n   apply (simp add: isFailureOf_def)\n   apply (force)\n\n (* => *)\n  apply (rule)\n   apply (simp)\n   apply (elim conjE exE)\n   apply (simp add: image_iff)\n   apply (elim disjE conjE exE)\n    apply (drule_tac x=\"i\" in bspec, simp)\n    apply (force)\n\n    apply (elim conjE bexE)\n    apply (rule_tac x=\"xb\" in exI, simp)\n    apply (rule_tac x=\"i\" in bexI)\n    apply (simp)\n    apply (simp)\n\napply (intro ballI)\napply (simp add: isFailureOf_def)\napply (simp add: subseteqEX_restRefusal_iff)\n\napply (auto)\ndone\n\n(*** iff ***)\n\nlemma DeadlockState_notDeadlockFree:\n  \"[| I ~= {} ; finite I ; (I,FXf) isFailureOf (I,PXf) |]\n   ==> (~ DeadlockFreeNetwork (I,PXf)) = \n       (EX sigma. (sigma isDeadlockStateOf (I,FXf)))\"\napply (rule)\napply (rule DeadlockState_notDeadlockFree_only_if, simp_all)\napply (simp add: DeadlockState_notDeadlockFree_if)\ndone\n\n(*** DeadlockFree ***)\n\nlemma DeadlockFree_notDeadlockState:\n  \"[| I ~= {} ; finite I ; (I,FXf) isFailureOf (I,PXf) |]\n   ==> DeadlockFreeNetwork (I,PXf) = \n       (ALL sigma. ~(sigma isDeadlockStateOf (I,FXf)))\"\napply (rule iffI)\napply (rotate_tac -1)\napply (erule contrapos_pp)\napply (simp add: DeadlockState_notDeadlockFree)\napply (rotate_tac -1)\napply (erule contrapos_pp)\napply (simp add: DeadlockState_notDeadlockFree)\ndone\n\n(****************** to add it again ******************)\n\ndeclare disj_not1   [simp]\n(*\ndeclare Union_image_eq [simp]\ndeclare Inter_image_eq [simp]\n*)\n(*\ndeclare Sup_image_eq [simp]\ndeclare Inf_image_eq [simp]\n*)\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/DFP/DFP_Deadlock.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5851011542032312, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.29712130790785707}}
{"text": "(*  Title:      JinjaDCI/Compiler/J1.thy\n    Author:     Tobias Nipkow, Susannah Mansky\n    Copyright   2003 Technische Universitaet Muenchen, 2019-20 UIUC\n\n    Based on the Jinja theory Compiler/J1.thy by Tobias Nipkow\n*)\n\nchapter \\<open> Compilation \\label{cha:comp} \\<close>\n\nsection \\<open> An Intermediate Language \\<close>\n\ntheory J1 imports \"../J/BigStep\" begin\n\ntype_synonym expr\\<^sub>1 = \"nat exp\"\ntype_synonym J\\<^sub>1_prog = \"expr\\<^sub>1 prog\"\ntype_synonym state\\<^sub>1 = \"heap \\<times> (val list) \\<times> sheap\"\n\ndefinition hp\\<^sub>1 :: \"state\\<^sub>1 \\<Rightarrow> heap\"\nwhere\n  \"hp\\<^sub>1  \\<equiv>  fst\"\ndefinition lcl\\<^sub>1 :: \"state\\<^sub>1 \\<Rightarrow> val list\"\nwhere\n  \"lcl\\<^sub>1  \\<equiv>  fst \\<circ> snd\"\ndefinition shp\\<^sub>1 :: \"state\\<^sub>1 \\<Rightarrow> sheap\"\nwhere\n  \"shp\\<^sub>1  \\<equiv>  snd \\<circ> snd\"\n\n(*<*)\ndeclare hp\\<^sub>1_def[simp] lcl\\<^sub>1_def[simp] shp\\<^sub>1_def[simp]\n(*>*)\n\nprimrec\n  max_vars :: \"'a exp \\<Rightarrow> nat\"\n  and max_varss :: \"'a exp list \\<Rightarrow> nat\"\nwhere\n  \"max_vars(new C) = 0\"\n| \"max_vars(Cast C e) = max_vars e\"\n| \"max_vars(Val v) = 0\"\n| \"max_vars(e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2) = max (max_vars e\\<^sub>1) (max_vars e\\<^sub>2)\"\n| \"max_vars(Var V) = 0\"\n| \"max_vars(V:=e) = max_vars e\"\n| \"max_vars(e\\<bullet>F{D}) = max_vars e\"\n| \"max_vars(C\\<bullet>\\<^sub>sF{D}) = 0\"\n| \"max_vars(FAss e\\<^sub>1 F D e\\<^sub>2) = max (max_vars e\\<^sub>1) (max_vars e\\<^sub>2)\"\n| \"max_vars(SFAss C F D e\\<^sub>2) = max_vars e\\<^sub>2\"\n| \"max_vars(e\\<bullet>M(es)) = max (max_vars e) (max_varss es)\"\n| \"max_vars(C\\<bullet>\\<^sub>sM(es)) = max_varss es\"\n| \"max_vars({V:T; e}) = max_vars e + 1\"\n| \"max_vars(e\\<^sub>1;;e\\<^sub>2) = max (max_vars e\\<^sub>1) (max_vars e\\<^sub>2)\"\n| \"max_vars(if (e) e\\<^sub>1 else e\\<^sub>2) =\n   max (max_vars e) (max (max_vars e\\<^sub>1) (max_vars e\\<^sub>2))\"\n| \"max_vars(while (b) e) = max (max_vars b) (max_vars e)\"\n| \"max_vars(throw e) = max_vars e\"\n| \"max_vars(try e\\<^sub>1 catch(C V) e\\<^sub>2) = max (max_vars e\\<^sub>1) (max_vars e\\<^sub>2 + 1)\"\n| \"max_vars(INIT C (Cs,b) \\<leftarrow> e) = max_vars e\"\n| \"max_vars(RI(C,e);Cs \\<leftarrow> e') = max (max_vars e) (max_vars e')\"\n\n| \"max_varss [] = 0\"\n| \"max_varss (e#es) = max (max_vars e) (max_varss es)\"\n\ninductive\n  eval\\<^sub>1 :: \"J\\<^sub>1_prog \\<Rightarrow> expr\\<^sub>1 \\<Rightarrow> state\\<^sub>1 \\<Rightarrow> expr\\<^sub>1 \\<Rightarrow> state\\<^sub>1 \\<Rightarrow> bool\"\n          (\"_ \\<turnstile>\\<^sub>1 ((1\\<langle>_,/_\\<rangle>) \\<Rightarrow>/ (1\\<langle>_,/_\\<rangle>))\" [51,0,0,0,0] 81)\n  and evals\\<^sub>1 :: \"J\\<^sub>1_prog \\<Rightarrow> expr\\<^sub>1 list \\<Rightarrow> state\\<^sub>1 \\<Rightarrow> expr\\<^sub>1 list \\<Rightarrow> state\\<^sub>1 \\<Rightarrow> bool\"\n           (\"_ \\<turnstile>\\<^sub>1 ((1\\<langle>_,/_\\<rangle>) [\\<Rightarrow>]/ (1\\<langle>_,/_\\<rangle>))\" [51,0,0,0,0] 81)\n  for P :: J\\<^sub>1_prog\nwhere\n\n  New\\<^sub>1:\n  \"\\<lbrakk> sh C = Some (sfs, Done); new_Addr h = Some a;\n     P \\<turnstile> C has_fields FDTs; h' = h(a\\<mapsto>blank P C) \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>new C,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>addr a,(h',l,sh)\\<rangle>\"\n| NewFail\\<^sub>1:\n  \"\\<lbrakk> sh C = Some (sfs, Done); new_Addr h = None \\<rbrakk> \\<Longrightarrow>\n  P \\<turnstile>\\<^sub>1 \\<langle>new C, (h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>THROW OutOfMemory,(h,l,sh)\\<rangle>\"\n| NewInit\\<^sub>1:\n  \"\\<lbrakk> \\<nexists>sfs. sh C = Some (sfs, Done); P \\<turnstile>\\<^sub>1 \\<langle>INIT C ([C],False) \\<leftarrow> unit,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>Val v',(h',l',sh')\\<rangle>;\n     new_Addr h' = Some a; P \\<turnstile> C has_fields FDTs; h'' = h'(a\\<mapsto>blank P C) \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>new C,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>addr a,(h'',l',sh')\\<rangle>\"\n| NewInitOOM\\<^sub>1:\n  \"\\<lbrakk> \\<nexists>sfs. sh C = Some (sfs, Done); P \\<turnstile>\\<^sub>1 \\<langle>INIT C ([C],False) \\<leftarrow> unit,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>Val v',(h',l',sh')\\<rangle>;\n     new_Addr h' = None; is_class P C \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>new C,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>THROW OutOfMemory,(h',l',sh')\\<rangle>\"\n| NewInitThrow\\<^sub>1:\n  \"\\<lbrakk> \\<nexists>sfs. sh C = Some (sfs, Done); P \\<turnstile>\\<^sub>1 \\<langle>INIT C ([C],False) \\<leftarrow> unit,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>throw a,s'\\<rangle>;\n     is_class P C \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>new C,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>throw a,s'\\<rangle>\"\n\n| Cast\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>addr a,(h,l,sh)\\<rangle>; h a = Some(D,fs); P \\<turnstile> D \\<preceq>\\<^sup>* C \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>Cast C e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>addr a,(h,l,sh)\\<rangle>\"\n| CastNull\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>1\\<rangle> \\<Longrightarrow>\n  P \\<turnstile>\\<^sub>1 \\<langle>Cast C e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>1\\<rangle>\"\n| CastFail\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>addr a,(h,l,sh)\\<rangle>; h a = Some(D,fs); \\<not> P \\<turnstile> D \\<preceq>\\<^sup>* C \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>Cast C e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>THROW ClassCast,(h,l,sh)\\<rangle>\"\n| CastThrow\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>1\\<rangle> \\<Longrightarrow>\n  P \\<turnstile>\\<^sub>1 \\<langle>Cast C e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>1\\<rangle>\"\n\n| Val\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>Val v,s\\<rangle> \\<Rightarrow> \\<langle>Val v,s\\<rangle>\"\n\n| BinOp\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val v\\<^sub>1,s\\<^sub>1\\<rangle>; P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>Val v\\<^sub>2,s\\<^sub>2\\<rangle>; binop(bop,v\\<^sub>1,v\\<^sub>2) = Some v \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val v,s\\<^sub>2\\<rangle>\"\n| BinOpThrow\\<^sub>1\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e,s\\<^sub>1\\<rangle> \\<Longrightarrow>\n  P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2, s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e,s\\<^sub>1\\<rangle>\"\n| BinOpThrow\\<^sub>2\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val v\\<^sub>1,s\\<^sub>1\\<rangle>; P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>throw e,s\\<^sub>2\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e,s\\<^sub>2\\<rangle>\"\n\n| Var\\<^sub>1:\n  \"\\<lbrakk> ls!i = v; i < size ls \\<rbrakk> \\<Longrightarrow>\n  P \\<turnstile>\\<^sub>1 \\<langle>Var i,(h,ls,sh)\\<rangle> \\<Rightarrow> \\<langle>Val v,(h,ls,sh)\\<rangle>\"\n\n| LAss\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val v,(h,ls,sh)\\<rangle>; i < size ls; ls' = ls[i := v] \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>i:= e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>unit,(h,ls',sh)\\<rangle>\"\n| LAssThrow\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>1\\<rangle> \\<Longrightarrow>\n  P \\<turnstile>\\<^sub>1 \\<langle>i:= e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>1\\<rangle>\"\n\n| FAcc\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>addr a,(h,ls,sh)\\<rangle>; h a = Some(C,fs);\n     P \\<turnstile> C has F,NonStatic:t in D;\n     fs(F,D) = Some v \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>e\\<bullet>F{D},s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val v,(h,ls,sh)\\<rangle>\"\n| FAccNull\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>1\\<rangle> \\<Longrightarrow>\n  P \\<turnstile>\\<^sub>1 \\<langle>e\\<bullet>F{D},s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>THROW NullPointer,s\\<^sub>1\\<rangle>\"\n| FAccThrow\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>1\\<rangle> \\<Longrightarrow>\n  P \\<turnstile>\\<^sub>1 \\<langle>e\\<bullet>F{D},s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>1\\<rangle>\"\n| FAccNone\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>addr a,(h,ls,sh)\\<rangle>; h a = Some(C,fs);\n    \\<not>(\\<exists>b t. P \\<turnstile> C has F,b:t in D) \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>e\\<bullet>F{D},s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>THROW NoSuchFieldError,(h,ls,sh)\\<rangle>\"\n| FAccStatic\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>addr a,(h,ls,sh)\\<rangle>; h a = Some(C,fs);\n    P \\<turnstile> C has F,Static:t in D \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>e\\<bullet>F{D},s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>THROW IncompatibleClassChangeError,(h,ls,sh)\\<rangle>\"\n\n| SFAcc\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile> C has F,Static:t in D;\n     sh D = Some (sfs,Done);\n     sfs F = Some v \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>C\\<bullet>\\<^sub>sF{D},(h,ls,sh)\\<rangle> \\<Rightarrow> \\<langle>Val v,(h,ls,sh)\\<rangle>\"\n| SFAccInit\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile> C has F,Static:t in D;\n     \\<nexists>sfs. sh D = Some (sfs,Done); P \\<turnstile>\\<^sub>1 \\<langle>INIT D ([D],False) \\<leftarrow> unit,(h,ls,sh)\\<rangle> \\<Rightarrow> \\<langle>Val v',(h',ls',sh')\\<rangle>;\n     sh' D = Some (sfs,i);\n     sfs F = Some v \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>C\\<bullet>\\<^sub>sF{D},(h,ls,sh)\\<rangle> \\<Rightarrow> \\<langle>Val v,(h',ls',sh')\\<rangle>\"\n| SFAccInitThrow\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile> C has F,Static:t in D;\n     \\<nexists>sfs. sh D = Some (sfs,Done); P \\<turnstile>\\<^sub>1 \\<langle>INIT D ([D],False) \\<leftarrow> unit,(h,ls,sh)\\<rangle> \\<Rightarrow> \\<langle>throw a,s'\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>C\\<bullet>\\<^sub>sF{D},(h,ls,sh)\\<rangle> \\<Rightarrow> \\<langle>throw a,s'\\<rangle>\"\n| SFAccNone\\<^sub>1:\n  \"\\<lbrakk> \\<not>(\\<exists>b t. P \\<turnstile> C has F,b:t in D) \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>C\\<bullet>\\<^sub>sF{D},s\\<rangle> \\<Rightarrow> \\<langle>THROW NoSuchFieldError,s\\<rangle>\"\n| SFAccNonStatic\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile> C has F,NonStatic:t in D \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>C\\<bullet>\\<^sub>sF{D},s\\<rangle> \\<Rightarrow> \\<langle>THROW IncompatibleClassChangeError,s\\<rangle>\"\n\n\n| FAss\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>addr a,s\\<^sub>1\\<rangle>; P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>Val v,(h\\<^sub>2,l\\<^sub>2,sh\\<^sub>2)\\<rangle>;\n     h\\<^sub>2 a = Some(C,fs); P \\<turnstile> C has F,NonStatic:t in D;\n     fs' = fs((F,D)\\<mapsto>v); h\\<^sub>2' = h\\<^sub>2(a\\<mapsto>(C,fs')) \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1\\<bullet>F{D}:=e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>unit,(h\\<^sub>2',l\\<^sub>2,sh\\<^sub>2)\\<rangle>\"\n| FAssNull\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>1\\<rangle>;  P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>Val v,s\\<^sub>2\\<rangle> \\<rbrakk> \\<Longrightarrow>\n  P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1\\<bullet>F{D}:=e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>THROW NullPointer,s\\<^sub>2\\<rangle>\"\n| FAssThrow\\<^sub>1\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>1\\<rangle> \\<Longrightarrow>\n  P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1\\<bullet>F{D}:=e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>1\\<rangle>\"\n| FAssThrow\\<^sub>2\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val v,s\\<^sub>1\\<rangle>; P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1\\<bullet>F{D}:=e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2\\<rangle>\"\n| FAssNone\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>addr a,s\\<^sub>1\\<rangle>; P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>Val v,(h\\<^sub>2,l\\<^sub>2,sh\\<^sub>2)\\<rangle>;\n     h\\<^sub>2 a = Some(C,fs); \\<not>(\\<exists>b t. P \\<turnstile> C has F,b:t in D) \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1\\<bullet>F{D}:=e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>THROW NoSuchFieldError,(h\\<^sub>2,l\\<^sub>2,sh\\<^sub>2)\\<rangle>\"\n| FAssStatic\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>addr a,s\\<^sub>1\\<rangle>; P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>Val v,(h\\<^sub>2,l\\<^sub>2,sh\\<^sub>2)\\<rangle>;\n     h\\<^sub>2 a = Some(C,fs); P \\<turnstile> C has F,Static:t in D \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1\\<bullet>F{D}:=e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>THROW IncompatibleClassChangeError,(h\\<^sub>2,l\\<^sub>2,sh\\<^sub>2)\\<rangle>\"\n\n| SFAss\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val v,(h\\<^sub>1,l\\<^sub>1,sh\\<^sub>1)\\<rangle>;\n     P \\<turnstile> C has F,Static:t in D;\n     sh\\<^sub>1 D = Some(sfs,Done); sfs' = sfs(F\\<mapsto>v); sh\\<^sub>1' = sh\\<^sub>1(D\\<mapsto>(sfs',Done)) \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>C\\<bullet>\\<^sub>sF{D}:=e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>unit,(h\\<^sub>1,l\\<^sub>1,sh\\<^sub>1')\\<rangle>\"\n| SFAssInit\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val v,(h\\<^sub>1,l\\<^sub>1,sh\\<^sub>1)\\<rangle>;\n     P \\<turnstile> C has F,Static:t in D;\n     \\<nexists>sfs. sh\\<^sub>1 D = Some(sfs,Done); P \\<turnstile>\\<^sub>1 \\<langle>INIT D ([D],False) \\<leftarrow> unit,(h\\<^sub>1,l\\<^sub>1,sh\\<^sub>1)\\<rangle> \\<Rightarrow> \\<langle>Val v',(h',l',sh')\\<rangle>;\n     sh' D = Some(sfs,i);\n     sfs' = sfs(F\\<mapsto>v); sh'' = sh'(D\\<mapsto>(sfs',i)) \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>C\\<bullet>\\<^sub>sF{D}:=e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>unit,(h',l',sh'')\\<rangle>\"\n| SFAssInitThrow\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val v,(h\\<^sub>1,l\\<^sub>1,sh\\<^sub>1)\\<rangle>;\n     P \\<turnstile> C has F,Static:t in D;\n     \\<nexists>sfs. sh\\<^sub>1 D = Some(sfs,Done); P \\<turnstile>\\<^sub>1 \\<langle>INIT D ([D],False) \\<leftarrow> unit,(h\\<^sub>1,l\\<^sub>1,sh\\<^sub>1)\\<rangle> \\<Rightarrow> \\<langle>throw a,s'\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>C\\<bullet>\\<^sub>sF{D}:=e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw a,s'\\<rangle>\"\n| SFAssThrow\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2\\<rangle>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>C\\<bullet>\\<^sub>sF{D}:=e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2\\<rangle>\"\n| SFAssNone\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val v,(h\\<^sub>2,l\\<^sub>2,sh\\<^sub>2)\\<rangle>;\n    \\<not>(\\<exists>b t. P \\<turnstile> C has F,b:t in D) \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>C\\<bullet>\\<^sub>sF{D}:=e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>THROW NoSuchFieldError,(h\\<^sub>2,l\\<^sub>2,sh\\<^sub>2)\\<rangle>\"\n| SFAssNonStatic\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val v,(h\\<^sub>2,l\\<^sub>2,sh\\<^sub>2)\\<rangle>;\n    P \\<turnstile> C has F,NonStatic:t in D \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>C\\<bullet>\\<^sub>sF{D}:=e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>THROW IncompatibleClassChangeError,(h\\<^sub>2,l\\<^sub>2,sh\\<^sub>2)\\<rangle>\"\n\n| CallObjThrow\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>1\\<rangle> \\<Longrightarrow>\n  P \\<turnstile>\\<^sub>1 \\<langle>e\\<bullet>M(es),s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>1\\<rangle>\"\n| CallNull\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>1\\<rangle>; P \\<turnstile>\\<^sub>1 \\<langle>es,s\\<^sub>1\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs,s\\<^sub>2\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>e\\<bullet>M(es),s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>THROW NullPointer,s\\<^sub>2\\<rangle>\"\n| Call\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>addr a,s\\<^sub>1\\<rangle>; P \\<turnstile>\\<^sub>1 \\<langle>es,s\\<^sub>1\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs,(h\\<^sub>2,ls\\<^sub>2,sh\\<^sub>2)\\<rangle>;\n    h\\<^sub>2 a = Some(C,fs); P \\<turnstile> C sees M,NonStatic:Ts\\<rightarrow>T = body in D;\n    size vs = size Ts; ls\\<^sub>2' = (Addr a) # vs @ replicate (max_vars body) undefined;\n    P \\<turnstile>\\<^sub>1 \\<langle>body,(h\\<^sub>2,ls\\<^sub>2',sh\\<^sub>2)\\<rangle> \\<Rightarrow> \\<langle>e',(h\\<^sub>3,ls\\<^sub>3,sh\\<^sub>3)\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>e\\<bullet>M(es),s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e',(h\\<^sub>3,ls\\<^sub>2,sh\\<^sub>3)\\<rangle>\"\n| CallParamsThrow\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val v,s\\<^sub>1\\<rangle>; P \\<turnstile>\\<^sub>1 \\<langle>es,s\\<^sub>1\\<rangle> [\\<Rightarrow>] \\<langle>es',s\\<^sub>2\\<rangle>;\n     es' = map Val vs @ throw ex # es\\<^sub>2 \\<rbrakk>\n   \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>e\\<bullet>M(es),s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2\\<rangle>\"\n| CallNone\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>addr a,s\\<^sub>1\\<rangle>;  P \\<turnstile>\\<^sub>1 \\<langle>ps,s\\<^sub>1\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs,(h\\<^sub>2,ls\\<^sub>2,sh\\<^sub>2)\\<rangle>;\n     h\\<^sub>2 a = Some(C,fs); \\<not>(\\<exists>b Ts T body D. P \\<turnstile> C sees M,b:Ts\\<rightarrow>T = body in D) \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>e\\<bullet>M(ps),s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>THROW NoSuchMethodError,(h\\<^sub>2,ls\\<^sub>2,sh\\<^sub>2)\\<rangle>\"\n| CallStatic\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>addr a,s\\<^sub>1\\<rangle>;  P \\<turnstile>\\<^sub>1 \\<langle>ps,s\\<^sub>1\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs,(h\\<^sub>2,ls\\<^sub>2,sh\\<^sub>2)\\<rangle>;\n     h\\<^sub>2 a = Some(C,fs); P \\<turnstile> C sees M,Static:Ts\\<rightarrow>T = body in D \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>e\\<bullet>M(ps),s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>THROW IncompatibleClassChangeError,(h\\<^sub>2,ls\\<^sub>2,sh\\<^sub>2)\\<rangle>\"\n\n| SCallParamsThrow\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>es,s\\<^sub>0\\<rangle> [\\<Rightarrow>] \\<langle>es',s\\<^sub>2\\<rangle>; es' = map Val vs @ throw ex # es\\<^sub>2 \\<rbrakk>\n   \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>C\\<bullet>\\<^sub>sM(es),s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2\\<rangle>\"\n| SCallNone\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>ps,s\\<^sub>0\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs,s\\<^sub>2\\<rangle>;\n     \\<not>(\\<exists>b Ts T body D. P \\<turnstile> C sees M,b:Ts\\<rightarrow>T = body in D) \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>C\\<bullet>\\<^sub>sM(ps),s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>THROW NoSuchMethodError,s\\<^sub>2\\<rangle>\"\n| SCallNonStatic\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>ps,s\\<^sub>0\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs,s\\<^sub>2\\<rangle>;\n     P \\<turnstile> C sees M,NonStatic:Ts\\<rightarrow>T = body in D \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>C\\<bullet>\\<^sub>sM(ps),s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>THROW IncompatibleClassChangeError,s\\<^sub>2\\<rangle>\"\n| SCallInitThrow\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>ps,s\\<^sub>0\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs,(h\\<^sub>1,ls\\<^sub>1,sh\\<^sub>1)\\<rangle>;\n     P \\<turnstile> C sees M,Static:Ts\\<rightarrow>T = body in D;\n     \\<nexists>sfs. sh\\<^sub>1 D = Some(sfs,Done); M \\<noteq> clinit;\n     P \\<turnstile>\\<^sub>1 \\<langle>INIT D ([D],False) \\<leftarrow> unit,(h\\<^sub>1,ls\\<^sub>1,sh\\<^sub>1)\\<rangle> \\<Rightarrow> \\<langle>throw a,s'\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>C\\<bullet>\\<^sub>sM(ps),s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw a,s'\\<rangle>\"\n| SCallInit\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>ps,s\\<^sub>0\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs,(h\\<^sub>1,ls\\<^sub>1,sh\\<^sub>1)\\<rangle>;\n     P \\<turnstile> C sees M,Static:Ts\\<rightarrow>T = body in D;\n     \\<nexists>sfs. sh\\<^sub>1 D = Some(sfs,Done); M \\<noteq> clinit;\n     P \\<turnstile>\\<^sub>1 \\<langle>INIT D ([D],False) \\<leftarrow> unit,(h\\<^sub>1,ls\\<^sub>1,sh\\<^sub>1)\\<rangle> \\<Rightarrow> \\<langle>Val v',(h\\<^sub>2,ls\\<^sub>2,sh\\<^sub>2)\\<rangle>;\n     size vs = size Ts; ls\\<^sub>2' = vs @ replicate (max_vars body) undefined;\n     P \\<turnstile>\\<^sub>1 \\<langle>body,(h\\<^sub>2,ls\\<^sub>2',sh\\<^sub>2)\\<rangle> \\<Rightarrow> \\<langle>e',(h\\<^sub>3,ls\\<^sub>3,sh\\<^sub>3)\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>C\\<bullet>\\<^sub>sM(ps),s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e',(h\\<^sub>3,ls\\<^sub>2,sh\\<^sub>3)\\<rangle>\"\n| SCall\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>ps,s\\<^sub>0\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs,(h\\<^sub>2,ls\\<^sub>2,sh\\<^sub>2)\\<rangle>;\n     P \\<turnstile> C sees M,Static:Ts\\<rightarrow>T = body in D;\n     sh\\<^sub>2 D = Some(sfs,Done) \\<or> (M = clinit \\<and> sh\\<^sub>2 D = \\<lfloor>(sfs, Processing)\\<rfloor>);\n     size vs = size Ts; ls\\<^sub>2' = vs @ replicate (max_vars body) undefined;\n     P \\<turnstile>\\<^sub>1 \\<langle>body,(h\\<^sub>2,ls\\<^sub>2',sh\\<^sub>2)\\<rangle> \\<Rightarrow> \\<langle>e',(h\\<^sub>3,ls\\<^sub>3,sh\\<^sub>3)\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>C\\<bullet>\\<^sub>sM(ps),s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e',(h\\<^sub>3,ls\\<^sub>2,sh\\<^sub>3)\\<rangle>\"\n\n| Block\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e',s\\<^sub>1\\<rangle> \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>Block i T e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e',s\\<^sub>1\\<rangle>\"\n\n| Seq\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>0,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val v,s\\<^sub>1\\<rangle>; P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>0;;e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n| SeqThrow\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>0,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e,s\\<^sub>1\\<rangle> \\<Longrightarrow>\n  P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>0;;e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e,s\\<^sub>1\\<rangle>\"\n\n| CondT\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>true,s\\<^sub>1\\<rangle>; P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>e',s\\<^sub>2\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>if (e) e\\<^sub>1 else e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e',s\\<^sub>2\\<rangle>\"\n| CondF\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>false,s\\<^sub>1\\<rangle>; P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>e',s\\<^sub>2\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>if (e) e\\<^sub>1 else e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e',s\\<^sub>2\\<rangle>\"\n| CondThrow\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>1\\<rangle> \\<Longrightarrow>\n  P \\<turnstile>\\<^sub>1 \\<langle>if (e) e\\<^sub>1 else e\\<^sub>2, s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>1\\<rangle>\"\n\n| WhileF\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>false,s\\<^sub>1\\<rangle> \\<Longrightarrow>\n  P \\<turnstile>\\<^sub>1 \\<langle>while (e) c,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>unit,s\\<^sub>1\\<rangle>\"\n| WhileT\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>true,s\\<^sub>1\\<rangle>; P \\<turnstile>\\<^sub>1 \\<langle>c,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>Val v\\<^sub>1,s\\<^sub>2\\<rangle>;\n    P \\<turnstile>\\<^sub>1 \\<langle>while (e) c,s\\<^sub>2\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>3,s\\<^sub>3\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>while (e) c,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>3,s\\<^sub>3\\<rangle>\"\n| WhileCondThrow\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>1\\<rangle> \\<Longrightarrow>\n  P \\<turnstile>\\<^sub>1 \\<langle>while (e) c,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>1\\<rangle>\"\n| WhileBodyThrow\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>true,s\\<^sub>1\\<rangle>; P \\<turnstile>\\<^sub>1 \\<langle>c,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2\\<rangle>\\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>while (e) c,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2\\<rangle>\"\n\n| Throw\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>addr a,s\\<^sub>1\\<rangle> \\<Longrightarrow>\n  P \\<turnstile>\\<^sub>1 \\<langle>throw e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Throw a,s\\<^sub>1\\<rangle>\"\n| ThrowNull\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>1\\<rangle> \\<Longrightarrow>\n  P \\<turnstile>\\<^sub>1 \\<langle>throw e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>THROW NullPointer,s\\<^sub>1\\<rangle>\"\n| ThrowThrow\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>1\\<rangle> \\<Longrightarrow>\n  P \\<turnstile>\\<^sub>1 \\<langle>throw e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>1\\<rangle>\"\n\n| Try\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val v\\<^sub>1,s\\<^sub>1\\<rangle> \\<Longrightarrow>\n  P \\<turnstile>\\<^sub>1 \\<langle>try e\\<^sub>1 catch(C i) e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val v\\<^sub>1,s\\<^sub>1\\<rangle>\"\n| TryCatch\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Throw a,(h\\<^sub>1,ls\\<^sub>1,sh\\<^sub>1)\\<rangle>;\n    h\\<^sub>1 a = Some(D,fs); P \\<turnstile> D \\<preceq>\\<^sup>* C; i < length ls\\<^sub>1;\n    P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>2,(h\\<^sub>1,ls\\<^sub>1[i:=Addr a],sh\\<^sub>1)\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2',(h\\<^sub>2,ls\\<^sub>2,sh\\<^sub>2)\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>try e\\<^sub>1 catch(C i) e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2',(h\\<^sub>2,ls\\<^sub>2,sh\\<^sub>2)\\<rangle>\"\n| TryThrow\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Throw a,(h\\<^sub>1,ls\\<^sub>1,sh\\<^sub>1)\\<rangle>; h\\<^sub>1 a = Some(D,fs); \\<not> P \\<turnstile> D \\<preceq>\\<^sup>* C \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>try e\\<^sub>1 catch(C i) e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Throw a,(h\\<^sub>1,ls\\<^sub>1,sh\\<^sub>1)\\<rangle>\"\n\n| Nil\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>[],s\\<rangle> [\\<Rightarrow>] \\<langle>[],s\\<rangle>\"\n\n| Cons\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val v,s\\<^sub>1\\<rangle>; P \\<turnstile>\\<^sub>1 \\<langle>es,s\\<^sub>1\\<rangle> [\\<Rightarrow>] \\<langle>es',s\\<^sub>2\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>e#es,s\\<^sub>0\\<rangle> [\\<Rightarrow>] \\<langle>Val v # es',s\\<^sub>2\\<rangle>\"\n| ConsThrow\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>1\\<rangle> \\<Longrightarrow>\n  P \\<turnstile>\\<^sub>1 \\<langle>e#es,s\\<^sub>0\\<rangle> [\\<Rightarrow>] \\<langle>throw e' # es, s\\<^sub>1\\<rangle>\"\n\n\\<comment> \\<open> init rules \\<close>\n\n| InitFinal\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle> \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>INIT C (Nil,b) \\<leftarrow> e,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n| InitNone\\<^sub>1:\n  \"\\<lbrakk> sh C = None; P \\<turnstile>\\<^sub>1 \\<langle>INIT C' (C#Cs,False) \\<leftarrow> e,(h,l,sh(C \\<mapsto> (sblank P C, Prepared)))\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>INIT C' (C#Cs,False) \\<leftarrow> e,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n| InitDone\\<^sub>1:\n  \"\\<lbrakk> sh C = Some(sfs,Done); P \\<turnstile>\\<^sub>1 \\<langle>INIT C' (Cs,True) \\<leftarrow> e,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>INIT C' (C#Cs,False) \\<leftarrow> e,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n| InitProcessing\\<^sub>1:\n  \"\\<lbrakk> sh C = Some(sfs,Processing); P \\<turnstile>\\<^sub>1 \\<langle>INIT C' (Cs,True) \\<leftarrow> e,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>INIT C' (C#Cs,False) \\<leftarrow> e,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n| InitError\\<^sub>1:\n  \"\\<lbrakk> sh C = Some(sfs,Error);\n     P \\<turnstile>\\<^sub>1 \\<langle>RI (C, THROW NoClassDefFoundError);Cs \\<leftarrow> e,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>INIT C' (C#Cs,False) \\<leftarrow> e,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n| InitObject\\<^sub>1:\n  \"\\<lbrakk> sh C = Some(sfs,Prepared);\n     C = Object;\n     sh' = sh(C \\<mapsto> (sfs,Processing));\n     P \\<turnstile>\\<^sub>1 \\<langle>INIT C' (C#Cs,True) \\<leftarrow> e,(h,l,sh')\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>INIT C' (C#Cs,False) \\<leftarrow> e,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n| InitNonObject\\<^sub>1:\n  \"\\<lbrakk> sh C = Some(sfs,Prepared);\n     C \\<noteq> Object;\n     class P C = Some (D,r);\n     sh' = sh(C \\<mapsto> (sfs,Processing));\n     P \\<turnstile>\\<^sub>1 \\<langle>INIT C' (D#C#Cs,False) \\<leftarrow> e,(h,l,sh')\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>INIT C' (C#Cs,False) \\<leftarrow> e,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n| InitRInit\\<^sub>1:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>RI (C,C\\<bullet>\\<^sub>sclinit([]));Cs \\<leftarrow> e,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>INIT C' (C#Cs,True) \\<leftarrow> e,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n\n| RInit\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<rangle> \\<Rightarrow> \\<langle>Val v, (h',l',sh')\\<rangle>;\n     sh' C = Some(sfs, i); sh'' = sh'(C \\<mapsto> (sfs, Done));\n     C' = last(C#Cs);\n     P \\<turnstile>\\<^sub>1 \\<langle>INIT C' (Cs,True) \\<leftarrow> e', (h',l',sh'')\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>1,s\\<^sub>1\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>RI (C,e);Cs \\<leftarrow> e',s\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>1,s\\<^sub>1\\<rangle>\"\n| RInitInitFail\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<rangle> \\<Rightarrow> \\<langle>throw a, (h',l',sh')\\<rangle>;\n     sh' C = Some(sfs, i); sh'' = sh'(C \\<mapsto> (sfs, Error));\n     P \\<turnstile>\\<^sub>1 \\<langle>RI (D,throw a);Cs \\<leftarrow> e', (h',l',sh'')\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>1,s\\<^sub>1\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>RI (C,e);D#Cs \\<leftarrow> e',s\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>1,s\\<^sub>1\\<rangle>\"\n| RInitFailFinal\\<^sub>1:\n  \"\\<lbrakk> P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<rangle> \\<Rightarrow> \\<langle>throw a, (h',l',sh')\\<rangle>;\n     sh' C = Some(sfs, i); sh'' = sh'(C \\<mapsto> (sfs, Error)) \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile>\\<^sub>1 \\<langle>RI (C,e);Nil \\<leftarrow> e',s\\<rangle> \\<Rightarrow> \\<langle>throw a, (h',l',sh'')\\<rangle>\"\n\n\n(*<*)\nlemmas eval\\<^sub>1_evals\\<^sub>1_induct = eval\\<^sub>1_evals\\<^sub>1.induct [split_format (complete)]\n  and eval\\<^sub>1_evals\\<^sub>1_inducts = eval\\<^sub>1_evals\\<^sub>1.inducts [split_format (complete)]\n(*>*)\n\n\ninductive_cases eval\\<^sub>1_cases [cases set]:\n \"P \\<turnstile>\\<^sub>1 \\<langle>new C,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n \"P \\<turnstile>\\<^sub>1 \\<langle>Cast C e,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n \"P \\<turnstile>\\<^sub>1 \\<langle>Val v,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n \"P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n \"P \\<turnstile>\\<^sub>1 \\<langle>Var v,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n \"P \\<turnstile>\\<^sub>1 \\<langle>V:=e,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n \"P \\<turnstile>\\<^sub>1 \\<langle>e\\<bullet>F{D},s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n \"P \\<turnstile>\\<^sub>1 \\<langle>C\\<bullet>\\<^sub>sF{D},s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n \"P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1\\<bullet>F{D}:=e\\<^sub>2,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n \"P \\<turnstile>\\<^sub>1 \\<langle>C\\<bullet>\\<^sub>sF{D}:=e\\<^sub>2,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n \"P \\<turnstile>\\<^sub>1 \\<langle>e\\<bullet>M(es),s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n \"P \\<turnstile>\\<^sub>1 \\<langle>C\\<bullet>\\<^sub>sM(es),s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n \"P \\<turnstile>\\<^sub>1 \\<langle>{V:T;e\\<^sub>1},s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n \"P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>1;;e\\<^sub>2,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n \"P \\<turnstile>\\<^sub>1 \\<langle>if (e) e\\<^sub>1 else e\\<^sub>2,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n \"P \\<turnstile>\\<^sub>1 \\<langle>while (b) c,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n \"P \\<turnstile>\\<^sub>1 \\<langle>throw e,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n \"P \\<turnstile>\\<^sub>1 \\<langle>try e\\<^sub>1 catch(C V) e\\<^sub>2,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n \"P \\<turnstile>\\<^sub>1 \\<langle>INIT C (Cs,b) \\<leftarrow> e,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n \"P \\<turnstile>\\<^sub>1 \\<langle>RI (C,e);Cs \\<leftarrow> e\\<^sub>0,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n \ninductive_cases evals\\<^sub>1_cases [cases set]:\n \"P \\<turnstile>\\<^sub>1 \\<langle>[],s\\<rangle> [\\<Rightarrow>] \\<langle>e',s'\\<rangle>\"\n \"P \\<turnstile>\\<^sub>1 \\<langle>e#es,s\\<rangle> [\\<Rightarrow>] \\<langle>e',s'\\<rangle>\"\n(*>*) \n\n\nlemma eval\\<^sub>1_final: \"P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle> \\<Longrightarrow> final e'\"\n and evals\\<^sub>1_final: \"P \\<turnstile>\\<^sub>1 \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>es',s'\\<rangle> \\<Longrightarrow> finals es'\"\n(*<*)by(induct rule:eval\\<^sub>1_evals\\<^sub>1.inducts, simp_all)(*>*)\n\n\nlemma eval\\<^sub>1_final_same:\nassumes eval: \"P \\<turnstile>\\<^sub>1 \\<langle>e,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\" shows \"final e \\<Longrightarrow> e = e' \\<and> s = s'\"\n(*<*)\nproof(erule finalE)\n  fix v assume Val: \"e = Val v\"\n  then show ?thesis using eval eval\\<^sub>1_cases(3) by blast\nnext\n  fix a assume \"e = Throw a\"\n  then show ?thesis using eval\n    by (metis eval\\<^sub>1_cases(3,17) exp.distinct(101) exp.inject(3) val.distinct(13))\nqed\n(*>*)\n\nsubsection \"Property preservation\"\n\nlemma eval\\<^sub>1_preserves_len:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>e\\<^sub>0,(h\\<^sub>0,ls\\<^sub>0,sh\\<^sub>0)\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>1,(h\\<^sub>1,ls\\<^sub>1,sh\\<^sub>1)\\<rangle> \\<Longrightarrow> length ls\\<^sub>0 = length ls\\<^sub>1\"\nand evals\\<^sub>1_preserves_len:\n  \"P \\<turnstile>\\<^sub>1 \\<langle>es\\<^sub>0,(h\\<^sub>0,ls\\<^sub>0,sh\\<^sub>0)\\<rangle> [\\<Rightarrow>] \\<langle>es\\<^sub>1,(h\\<^sub>1,ls\\<^sub>1,sh\\<^sub>1)\\<rangle> \\<Longrightarrow> length ls\\<^sub>0 = length ls\\<^sub>1\"\n(*<*)by (induct rule:eval\\<^sub>1_evals\\<^sub>1_inducts, simp_all)(*>*)\n\n\nlemma evals\\<^sub>1_preserves_elen:\n  \"\\<And>es' s s'. P \\<turnstile>\\<^sub>1 \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>es',s'\\<rangle> \\<Longrightarrow> length es = length es'\"\n(*<*)by(induct es type:list) (auto elim:evals\\<^sub>1.cases)(*>*)\n\n\nlemma clinit\\<^sub>1_loc_pres:\n \"P \\<turnstile>\\<^sub>1 \\<langle>C\\<^sub>0\\<bullet>\\<^sub>sclinit([]),(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>e',(h',l',sh')\\<rangle> \\<Longrightarrow> l = l'\"\n by(auto elim!: eval\\<^sub>1_cases(12) evals\\<^sub>1_cases(1))\n\nlemma\nshows init\\<^sub>1_ri\\<^sub>1_same_loc: \"P \\<turnstile>\\<^sub>1 \\<langle>e,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>e',(h',l',sh')\\<rangle>\n   \\<Longrightarrow> (\\<And>C Cs b M a. e = INIT C (Cs,b) \\<leftarrow> unit \\<or> e = C\\<bullet>\\<^sub>sM([]) \\<or> e = RI (C,Throw a) ; Cs \\<leftarrow> unit\n          \\<or> e = RI (C,C\\<bullet>\\<^sub>sclinit([])) ; Cs \\<leftarrow> unit\n           \\<Longrightarrow> l = l')\"\n  and \"P \\<turnstile>\\<^sub>1 \\<langle>es,(h,l,sh)\\<rangle> [\\<Rightarrow>] \\<langle>es',(h',l',sh')\\<rangle> \\<Longrightarrow> True\"\nproof(induct rule: eval\\<^sub>1_evals\\<^sub>1_inducts)\n  case (RInitInitFail\\<^sub>1 e h l sh a')\n  then show ?case using eval\\<^sub>1_final[of _ _ _ \"throw a'\"]\n     by(fastforce dest: eval\\<^sub>1_final_same[of _ \"Throw a\"])\nnext\n  case RInitFailFinal\\<^sub>1 then show ?case by(auto dest: eval\\<^sub>1_final_same)\nqed(auto dest: evals\\<^sub>1_cases eval\\<^sub>1_cases(17) eval\\<^sub>1_final_same)\n\nlemma init\\<^sub>1_same_loc: \"P \\<turnstile>\\<^sub>1 \\<langle>INIT C (Cs,b) \\<leftarrow> unit,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>e',(h',l',sh')\\<rangle> \\<Longrightarrow> l = l'\"\n by(simp add: init\\<^sub>1_ri\\<^sub>1_same_loc)\n\n\ntheorem eval\\<^sub>1_hext: \"P \\<turnstile>\\<^sub>1 \\<langle>e,(h,l,sh)\\<rangle> \\<Rightarrow> \\<langle>e',(h',l',sh')\\<rangle> \\<Longrightarrow> h \\<unlhd> h'\"\nand evals\\<^sub>1_hext:  \"P \\<turnstile>\\<^sub>1 \\<langle>es,(h,l,sh)\\<rangle> [\\<Rightarrow>] \\<langle>es',(h',l',sh')\\<rangle> \\<Longrightarrow> h \\<unlhd> h'\"\n(*<*)\nproof (induct rule: eval\\<^sub>1_evals\\<^sub>1_inducts)\n  case New\\<^sub>1 thus ?case\n    by(fastforce intro!: hext_new intro:LeastI simp:new_Addr_def\n                split:if_split_asm simp del:fun_upd_apply)\nnext\n  case NewInit\\<^sub>1 thus ?case\n    by (meson hext_new hext_trans new_Addr_SomeD)\nnext\n  case FAss\\<^sub>1 thus ?case\n    by(auto simp:sym[THEN hext_upd_obj] simp del:fun_upd_apply\n            elim!: hext_trans)\nqed (auto elim!: hext_trans)\n(*>*)\n\nsubsection \"Initialization\"\n\nlemma rinit\\<^sub>1_throw:\n \"P\\<^sub>1 \\<turnstile>\\<^sub>1 \\<langle>RI (D,Throw xa) ; Cs \\<leftarrow> e,(h, l, sh)\\<rangle> \\<Rightarrow> \\<langle>e',(h', l', sh')\\<rangle>\n    \\<Longrightarrow> e' = Throw xa\"\nproof(induct Cs arbitrary: D h l sh h' l' sh')\n  case Nil then show ?case\n  proof(rule eval\\<^sub>1_cases(20)) qed(auto elim: eval\\<^sub>1_cases)\nnext\n  case (Cons C Cs) show ?case using Cons.prems\n  proof(induct rule: eval\\<^sub>1_cases(20))\n    case RInit\\<^sub>1: 1\n    then show ?case using Cons.hyps by(auto elim: eval\\<^sub>1_cases)\n  next\n    case RInitInitFail\\<^sub>1: 2\n    then show ?case using Cons.hyps eval\\<^sub>1_final_same final_def by blast\n  next\n    case RInitFailFinal\\<^sub>1: 3 then show ?case by simp\n  qed\nqed\n\nlemma rinit\\<^sub>1_throwE:\n\"P \\<turnstile>\\<^sub>1 \\<langle>RI (C,throw e) ; Cs \\<leftarrow> e\\<^sub>0,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\n   \\<Longrightarrow> \\<exists>a s\\<^sub>t. e' = throw a \\<and> P \\<turnstile>\\<^sub>1 \\<langle>throw e,s\\<rangle> \\<Rightarrow> \\<langle>throw a,s\\<^sub>t\\<rangle>\"\nproof(induct Cs arbitrary: C e s)\n  case Nil\n  then show ?case\n  proof(rule eval\\<^sub>1_cases(20)) \\<comment> \\<open> RI \\<close>\n    fix v h' l' sh' assume \"P \\<turnstile>\\<^sub>1 \\<langle>throw e,s\\<rangle> \\<Rightarrow> \\<langle>Val v,(h', l', sh')\\<rangle>\"\n    then show ?case using eval\\<^sub>1_cases(17) by blast\n  qed(auto)\nnext\n  case (Cons C' Cs')\n  show ?case using Cons.prems(1)\n  proof(rule eval\\<^sub>1_cases(20)) \\<comment> \\<open> RI \\<close>\n    fix v h' l' sh' assume \"P \\<turnstile>\\<^sub>1 \\<langle>throw e,s\\<rangle> \\<Rightarrow> \\<langle>Val v,(h', l', sh')\\<rangle>\"\n    then show ?case using eval\\<^sub>1_cases(17) by blast\n  next\n    fix a h' l' sh' sfs i D Cs''\n    assume e''step: \"P \\<turnstile>\\<^sub>1 \\<langle>throw e,s\\<rangle> \\<Rightarrow> \\<langle>throw a,(h', l', sh')\\<rangle>\"\n       and shC: \"sh' C = \\<lfloor>(sfs, i)\\<rfloor>\"\n       and riD: \"P \\<turnstile>\\<^sub>1 \\<langle>RI (D,throw a) ; Cs'' \\<leftarrow> e\\<^sub>0,(h', l', sh'(C \\<mapsto> (sfs, Error)))\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n       and \"C' # Cs' = D # Cs''\"\n    then show ?thesis using Cons.hyps eval\\<^sub>1_final eval\\<^sub>1_final_same by blast\n  qed(simp)\nqed\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/JinjaDCI/Compiler/J1.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6442251064863695, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.29699858374447985}}
{"text": "theory Pid_Scheduler\nimports Gen_Scheduler_Refine Partial_Order_Reduction.Transition_System_Extensions\nbegin\n\n  lemma system_complete_language_eq_lsystem_accept:\n    fixes ex en init int\n    defines \"S \\<equiv> \\<lparr> g_V = UNIV, g_E = rel_of_enex (en, ex), g_V0 = {init}, sa_L = int \\<rparr>\"\n    assumes \"sa S\"\n    shows \"snth ` transition_system_complete.language ex (\\<lambda> a p. a \\<in> en p) (\\<lambda> p. p = init) int = {w. sa.accept S w}\"\n  proof -\n    interpret jsys?: transition_system_complete ex \"\\<lambda> a p. a \\<in> en p\" \"\\<lambda> p. p = init\" int by this\n    interpret psys?: sa S by fact\n    show ?thesis\n    unfolding jsys.language_def\n    unfolding psys.accept_def\n    proof safe\n      fix p w\n      assume 1: \"run w init\"\n      show \"\\<exists> r. is_run r \\<and> snth (smap int (init ## trace w init)) = L \\<circ> r\"\n      unfolding is_run_def ipath_def\n      unfolding S_def graph_rec.simps sa_rec.simps\n      unfolding rel_of_enex_def Let_def prod.case\n      proof (intro allI exI conjI)\n        fix i\n        show \"(init ## trace w init) !! 0 \\<in> {init}\" by simp\n        show \"snth (smap int (init ## trace w init)) = int \\<circ> snth (init ## trace w init)\"\n          by (metis (full_types) fun_comp_eq_conv smap_alt)\n        have 10: \"w = stake i w @- [w !! i] @- sdrop (Suc i) w\" using id_stake_snth_sdrop by auto\n        have 20: \"run (stake i w @- [w !! i] @- sdrop (Suc i) w) init\" using 1 10 by simp\n        have 1: \"w !! i \\<in> en (target (stake i w) init)\" using 20 by auto\n        have 2: \"ex (w !! i) (target (stake i w) init) = target (stake (Suc i) w) init\"\n          using 20 unfolding stake_Suc by auto\n        show \"((init ## trace w init) !! i, (init ## trace w init) !! Suc i) \\<in>\n          {(s, ex a s) |s a. a \\<in> en s}\" using 1 2 by force\n      qed\n    next\n      fix r\n      assume 1: \"is_run r\"\n      obtain w where 2: \"r 0 = init\" \"\\<And> i. w i \\<in> en (r i)\" \"\\<And> i. r (Suc i) = ex (w i) (r i)\"\n        using 1\n        unfolding is_run_def ipath_def\n        unfolding S_def graph_rec.simps\n        unfolding rel_of_enex_def Let_def prod.case\n        by simp metis\n      have 3: \"L \\<circ> r = snth (smap int (smap r nats))\" unfolding assms(1) by auto\n      have 4: \"(init ## trace (smap w nats) init) !! i = smap r nats !! i\" for i\n        using 2 by (induct i) (auto)\n      have 5: \"smap r nats = init ## trace (smap w nats) init\" using eqI_snth 4 by metis\n      have 6: \"target (stake k (smap w nats)) init = smap r nats !! k\" for k\n        unfolding sscan_scons_snth 5 by rule\n      have 7: \"run (smap w nats) init\" using 2(2) 6 by (auto intro: snth_run)\n      show \"L \\<circ> r \\<in> (!!) ` {smap int (p ## trace w p) |p w. p = init \\<and> run w p}\"\n        unfolding 3 using 5 7 by force\n    qed\n  qed\n\n  (* TODO: Move *)  \n  lemma prod_splitE:\n    assumes \"\\<forall>a b. p=(a,b) \\<longrightarrow> P a b\"\n    obtains a b where \"p=(a,b)\" \"P a b\"\n    using assms\n    by (cases p) auto\n\n  lemma sngp_sym_conv: \"(\\<lambda>p. p=x) = (=) x\" by auto  \n\n\n  lemma in_multiset_of_conv_nth: \"x \\<in># mset l \\<longleftrightarrow> (\\<exists>i<length l. x = l!i)\"\n    by (metis in_multiset_in_set in_set_conv_nth)\n    \n  lemma multiset_of_em_conv_nth: \"mset l = {#x#} + m' \n    \\<longleftrightarrow> (\\<exists>i<length l. x = l!i \\<and> m' = mset l - {#x#})\"\n    by (metis add_diff_cancel_left' in_multiset_of_conv_nth \n      insert_DiffM multi_member_this)\n\n  \n  type_synonym pid = nat\n  record ('c,'ls,'gs) pid_global_config =\n    processes :: \"('c,'ls) local_config list\"  \n    state :: 'gs\n\n  definition pidgc_\\<alpha> \n    :: \"('c,'ls,'gs) pid_global_config \\<Rightarrow> ('c,'ls,'gs) global_config\" where\n    \"pidgc_\\<alpha> pgc \\<equiv> \\<lparr>     \n      global_config.processes = mset (pid_global_config.processes pgc),\n      global_config.state = pid_global_config.state pgc\n    \\<rparr>\"\n\n  abbreviation pid_valid :: \"('c,'ls,'gs) pid_global_config \\<Rightarrow> pid \\<Rightarrow> bool\" \n    where\n    \"pid_valid gc pid \\<equiv> pid < length (pid_global_config.processes gc)\"\n    \n  abbreviation \"lc_of_pid gc pid \n    \\<equiv> pid_global_config.processes gc ! pid\"\n  \n  abbreviation \"cmd_of_pid gc pid \n    \\<equiv> local_config.command (lc_of_pid gc pid)\"\n    \n  abbreviation \"ls_of_pid gc pid \n    \\<equiv> local_config.state (lc_of_pid gc pid)\"\n\n\n  context Gen_Scheduler'\n  begin\n\n    definition pid_gstep_succ \n      :: \"('c,'ls,'gs) pid_global_config \\<Rightarrow> ('c,'ls,'gs) pid_global_config set\" \n      where\n      \"pid_gstep_succ gc \\<equiv> do {\n        \\<comment> \\<open> Select process \\<close>\n        let lcs = pid_global_config.processes gc;\n        pid \\<leftarrow> {0..<length lcs};\n        let lc = lcs!pid;\n        \\<comment> \\<open> Focus state \\<close>\n        let gs = pid_global_config.state gc;\n        let ls = local_config.state lc;\n  \n        \\<comment> \\<open> Select action \\<close>\n        let cmd = local_config.command lc;\n        (a,cmd') \\<leftarrow> {(a,cmd'). cstep cmd a cmd'};\n  \n        if en (ls,gs) a then {do { \n          \\<comment> \\<open> Execute \\<close>\n          let (ls,gs) = ex (ls,gs) a;\n          \\<comment> \\<open> Unfocus state. \\<close>\n          let lc = \\<lparr> local_config.command = cmd', local_config.state = ls\\<rparr>;\n          \\<lparr> \n            pid_global_config.processes = lcs[pid:=lc],\n            pid_global_config.state = gs  \n          \\<rparr>\n        }}\n      else {}\n    }\"\n\n    lemma pid_gstep_succE:\n      assumes \"gc' \\<in> pid_gstep_succ gc\"\n      obtains pid a c' ls' gs' where\n        \"pid_valid gc pid\"\n        \"cstep (cmd_of_pid gc pid) a c'\"\n        \"en (ls_of_pid gc pid, pid_global_config.state gc) a\"\n        \"ex (ls_of_pid gc pid, pid_global_config.state gc) a = (ls',gs')\"\n        \"gc' = \\<lparr> \n          pid_global_config.processes = (pid_global_config.processes gc)\n            [pid := \n              \\<lparr> local_config.command = c', local_config.state = ls'\\<rparr>\n            ],\n          pid_global_config.state = gs'\\<rparr>\"\n      using assms\n      unfolding pid_gstep_succ_def\n      by (auto \n        split: if_split_asm prod.splits \n        elim!: prod_splitE\n        simp: all_conj_distrib)\n\n  lemma pid_gstep_succI:\n    assumes\n      \"pid_valid gc pid\"\n      \"cstep (cmd_of_pid gc pid) a c'\"\n      \"en (ls_of_pid gc pid, pid_global_config.state gc) a\"\n      \"ex (ls_of_pid gc pid, pid_global_config.state gc) a = (ls',gs')\"\n    shows \"\n      \\<lparr> \n        pid_global_config.processes = (pid_global_config.processes gc)\n          [pid := \n            \\<lparr> local_config.command = c', local_config.state = ls'\\<rparr>\n          ],\n        pid_global_config.state = gs'\n      \\<rparr> \\<in> pid_gstep_succ gc\"\n    using assms\n    unfolding pid_gstep_succ_def\n    by fastforce\n\n  lemma pid_gc_state_eq: \n    \"pid_global_config.state pgc = global_config.state (pidgc_\\<alpha> pgc)\"\n    unfolding pidgc_\\<alpha>_def by auto  \n    \n  lemma pid_gc_proc_eq:\n    assumes \"pid_valid gc pid\"  \n    shows \"\n      global_config.processes (pidgc_\\<alpha> gc) \n      = {#lc_of_pid gc pid#} \n      + (global_config.processes (pidgc_\\<alpha> gc) - {#lc_of_pid gc pid#})\"\n    using assms\n    by (auto simp: pidgc_\\<alpha>_def multiset_of_em_conv_nth)\n\n\n  lemma pid_gstep_correct: \n    \"gstep_succ (pidgc_\\<alpha> pgc) = pidgc_\\<alpha>`pid_gstep_succ pgc\"\n    apply safe\n    apply (erule gstep_succE)\n    apply (clarsimp simp: pidgc_\\<alpha>_def multiset_of_em_conv_nth)\n    apply (frule (3) pid_gstep_succI)\n    apply (erule image_eqI[rotated])\n    apply (auto simp: pidgc_\\<alpha>_def mset_update add_ac union_mset_add_mset_right) []\n\n    apply (erule pid_gstep_succE)\n    apply (clarsimp simp: pidgc_\\<alpha>_def mset_update)\n    apply (simp add: pid_gc_state_eq)\n    apply (frule (2) gstep_succI[rotated])\n    apply (rule pid_gc_proc_eq, assumption)\n    apply (auto simp: add_ac pidgc_\\<alpha>_def union_mset_add_mset_left) []\n    done\n\n  abbreviation \"pid_gstep \\<equiv> rel_of_succ pid_gstep_succ\"\n  definition \"pid_step \\<equiv> stutter_extend_edges UNIV pid_gstep\"\n\nend\n\nlocale Pid_Gen_Scheduler_linit = \n  Gen_Scheduler'_linit cstep en ex init label\n  for cstep :: \"'c \\<Rightarrow> 'a \\<Rightarrow> 'c \\<Rightarrow> bool\"\n  and en :: \"('ls\\<times>'gs) \\<Rightarrow> 'a \\<Rightarrow> bool\"\n  and ex :: \"('ls\\<times>'gs) \\<Rightarrow> 'a \\<Rightarrow> ('ls\\<times>'gs)\"\n  and init :: \"('c,'ls,'gs) global_config set\"\n  and label :: \"('c,'ls,'gs) global_config \\<Rightarrow> 'l\" +\n  fixes pid_init :: \"('c,'ls,'gs) pid_global_config\"\n  and pid_label :: \"('c,'ls,'gs) pid_global_config \\<Rightarrow> 'l\"\n  assumes pid_init_eq: \"gc \\<in> init \\<longleftrightarrow> (gc=pidgc_\\<alpha> pid_init)\"\n  assumes pid_label_eq: \"label (pidgc_\\<alpha> pgc) = pid_label pgc\"\nbegin\n\n  definition pid_system_automaton' :: \"(('c,'ls,'gs) pid_global_config, 'l) sa_rec\"\n    where \"pid_system_automaton' \\<equiv>\n      \\<lparr> g_V = UNIV, g_E = pid_gstep, g_V0 = {pid_init}, sa_L = pid_label \\<rparr>\"\n\n  lemma pid_system_automaton'_simps[simp]:\n    \"g_V pid_system_automaton' = UNIV\"\n    \"g_E pid_system_automaton' = pid_gstep\"\n    \"g_V0 pid_system_automaton' = {pid_init}\"\n    \"sa_L pid_system_automaton' = pid_label\"\n    unfolding pid_system_automaton'_def by auto\n\n  definition pid_system_automaton :: \"(('c,'ls,'gs) pid_global_config, 'l) sa_rec\"\n    where \"pid_system_automaton \\<equiv>\n      \\<lparr> g_V = UNIV, g_E = pid_step, g_V0 = {pid_init}, sa_L = pid_label \\<rparr>\"\n\n  lemma pid_system_automaton_simps[simp]:\n    \"g_V pid_system_automaton = UNIV\"\n    \"g_E pid_system_automaton = pid_step\"\n    \"g_V0 pid_system_automaton = {pid_init}\"\n    \"sa_L pid_system_automaton = pid_label\"\n    unfolding pid_system_automaton_def by auto\n\n  lemma pid_system_automaton_alt_def: \"pid_system_automaton = stutter_extend pid_system_automaton'\"\n    unfolding pid_step_def pid_system_automaton'_def pid_system_automaton_def stutter_extend_def\n    by simp\n\n  sublocale pid': sa pid_system_automaton' by unfold_locales auto\n  sublocale pid: sa pid_system_automaton\n    unfolding pid_system_automaton_alt_def using pid'.stutter_extend_sa by this\n\n  sublocale bisim: lbisimulation \"br pidgc_\\<alpha> (\\<lambda>_. True)\" pid_system_automaton system_automaton\n  proof -\n    interpret bisim: lbisimulation \"br pidgc_\\<alpha> (\\<lambda>_. True)\" pid_system_automaton' system_automaton'\n      apply unfold_locales\n      apply (auto simp: build_rel_def pid_init_eq pid_gstep_correct pid_label_eq)\n      done\n    interpret bisim: lbisimulation \"br pidgc_\\<alpha> (\\<lambda>_. True)\" pid_system_automaton system_automaton\n      unfolding system_automaton_alt_def pid_system_automaton_alt_def\n      using bisim.lstutter_extend by this\n    show \"lbisimulation (br pidgc_\\<alpha> (\\<lambda> _. True)) pid_system_automaton system_automaton\"\n      by unfold_locales\n  qed\n\n  lemma pid_accept_eq: \"pid.accept = sa.accept\" by (rule bisim.accept_bisim)\n\n  lemma pid_run_conv: \"sa.g.is_run r \\<longleftrightarrow> (\\<exists>r'. r=pidgc_\\<alpha> o r' \\<and> pid.g.is_run r')\"\n    by (rule bisim.br_run_conv[OF refl])   \n\n  lemma pid_run_sim: \"pid.g.is_run r \\<Longrightarrow> sa.g.is_run (pidgc_\\<alpha> o r)\"\n    by (rule bisim.s1.br_run_sim[OF refl])\n\nsection \"Global Actions\"\n\ntext \\<open>\n  A global action consists of a PID and a control flow graph edge\n\\<close>\ntype_synonym (in -) ('c,'a) global_action = \"pid \\<times> 'c \\<times> 'a \\<times> 'c\"\n\n\nabbreviation (in -) \"fs_of_pid gc pid \\<equiv> (ls_of_pid gc pid,pid_global_config.state gc)\"\n\n  definition ga_gen \n    :: \"('c,'ls,'gs) pid_global_config \\<Rightarrow> ('c,'a) global_action set\"\n  where\n    \"ga_gen gc \\<equiv> { (pid,c,a,c') .\n      cstep c a c' \n    \\<and> pid_valid gc pid \n    \\<and> c=cmd_of_pid gc pid\n    \\<and> en (fs_of_pid gc pid) a }\"\n\n  definition ga_gex\n    :: \"('c,'a) global_action \\<Rightarrow> ('c,'ls,'gs) pid_global_config \\<Rightarrow> ('c,'ls,'gs) pid_global_config\"\n  where\n    \"ga_gex ga gc \\<equiv> let \n      (pid,c,a,c') = ga;\n      fs = fs_of_pid gc pid;\n      (ls',gs') = ex fs a;\n      gc' = \\<lparr> \n          pid_global_config.processes = (pid_global_config.processes gc)\n            [pid := \n              \\<lparr> local_config.command = c', local_config.state = ls'\\<rparr>\n            ],\n          pid_global_config.state = gs'\\<rparr>\n    in\n      gc'\"\n\n  definition \"ga_gstep \\<equiv> rel_of_enex (ga_gen,ga_gex)\"\n  definition \"ga_en \\<equiv> stutter_extend_en ga_gen\"\n  definition \"ga_ex \\<equiv> stutter_extend_ex ga_gex\"\n  definition \"ga_step \\<equiv> stutter_extend_edges UNIV ga_gstep\"\n  lemma ga_step_alt: \"ga_step = rel_of_enex (ga_en,ga_ex)\"\n    unfolding ga_step_def ga_gstep_def ga_en_def ga_ex_def\n    by (auto simp: stutter_extend_pred_of_enex_conv)\n\n  lemma some_ga_en_eq: \n    \"Some a \\<in> ga_en gc \\<longleftrightarrow> a \\<in> ga_gen gc\"\n    by (auto simp: ga_en_def)\n  lemma some_ga_ex_eq: \n    \"ga_ex (Some a) gc = ga_gex a gc\"\n    \"ga_ex \\<circ> Some = ga_gex\"\n    by (auto simp: ga_ex_def intro!: ext)\n  lemma none_ga_en_eq: \"None \\<in> ga_en gc \\<longleftrightarrow> ga_gen gc = {}\"\n    by (auto simp: ga_en_def stutter_extend_en_def)\n  lemma ga_ex_none[simp]: \"ga_ex None = id\"   \n    by (auto simp: ga_ex_def)\n\n  lemma ga_gstep_eq: \"ga_gstep = pid_gstep\"\n    apply safe\n    apply (auto \n      simp: ga_gstep_def ga_gen_def ga_gex_def \n      split: prod.splits elim!: prod_splitE\n      intro: pid_gstep_succI) []\n     \n    apply (fastforce \n      simp: pred_of_succ_def ga_gstep_def ga_gen_def ga_gex_def\n      split: prod.splits\n      elim!: pid_gstep_succE)\n    done\n\n  lemma ga_step_eq: \"ga_step = pid_step\" \n    unfolding ga_step_def pid_step_def ga_gstep_eq by rule\n\n  definition ga_automaton :: \"(('c,'ls,'gs) pid_global_config, 'l) sa_rec\"\n    where \"ga_automaton \\<equiv> \\<lparr> g_V = UNIV, g_E = ga_step, g_V0 = {pid_init}, sa_L = pid_label \\<rparr>\"\n\n  lemma ga_automaton_simps[simp]:\n    \"g_V ga_automaton = UNIV\"\n    \"g_E ga_automaton = ga_step\"\n    \"g_V0 ga_automaton = {pid_init}\"\n    \"sa_L ga_automaton = pid_label\"\n    unfolding ga_automaton_def by simp+\n\n  lemma ga_pid_system_automaton: \"ga_automaton = pid_system_automaton\"\n    unfolding ga_automaton_def pid_system_automaton_def ga_step_eq by rule\n\n  sublocale jsys: transition_system ga_ex \"\\<lambda> a p. a \\<in> ga_en p\" .\n  sublocale ga: sa ga_automaton unfolding ga_pid_system_automaton by unfold_locales\n\n  sublocale ga_bisim: lbisimulation Id ga_automaton pid_system_automaton\n    unfolding ga_pid_system_automaton by auto\n\n  lemma ga_accept_eq: \"ga.accept = sa.accept\" \n    by (simp add: ga_bisim.accept_bisim pid_accept_eq) \n\n  lemma ga_run_eq: \"pid.g.is_run r = ga.is_run r\"\n    using ga_bisim.br_run_conv[of id \"\\<lambda>_. True\" r]\n    by (auto simp: build_rel_def[abs_def])\n\n  sublocale jsys: transition_system_initial ga_ex \"\\<lambda> a p. a \\<in> ga_en p\" \"\\<lambda> p. p = pid_init\" . \n\n  lemma reachable_alt: \"jsys.nodes = ga.E\\<^sup>* `` ga.V0\"\n  proof safe\n    fix gc\n    assume \"gc \\<in> jsys.nodes\"\n    thus \"gc \\<in> ga.E\\<^sup>* `` ga.V0\"\n      unfolding ga_automaton_def ga_step_alt rel_of_enex_def\n      by (induct, auto intro: rtrancl_into_rtrancl)\n  next\n    fix gc gc'\n    assume \"(gc, gc') \\<in> ga.E\\<^sup>*\" \"gc \\<in> ga.V0\"\n    thus \"gc' \\<in> jsys.nodes\" unfolding ga_automaton_def ga_step_alt by induct auto\n  qed\n\n  lemma rtrancl_step_exec_word_conv:  \n    \"(gc, gc') \\<in> ga_step\\<^sup>* \\<longleftrightarrow> (\\<exists>w. jsys.path w gc \\<and> gc' = jsys.target w gc)\"\n  proof safe\n    assume \"(gc, gc') \\<in> ga_step\\<^sup>*\"\n    thus \"\\<exists> w. jsys.path w gc \\<and> gc' = jsys.target w gc\"\n      apply induction\n      apply force\n      apply (force simp: ga_step_alt pred_of_enex_def)\n      done\n  next\n    fix w\n    assume \"jsys.path w gc\"\n    thus \"(gc, jsys.target w gc) \\<in> ga_step\\<^sup>*\"\n      apply induction\n      apply (auto simp: ga_step_alt rel_of_enex_def\n        intro: converse_rtrancl_into_rtrancl)\n      done\n  qed\n\n  sublocale jsys: transition_system_complete ga_ex \"\\<lambda> a p. a \\<in> ga_en p\" \"\\<lambda> p. p = pid_init\" pid_label .\n\n  lemma accept_eq_lang: \"snth ` jsys.language = Collect sa.accept\"\n    unfolding ga_accept_eq[symmetric]\n    unfolding ga_automaton_def\n    unfolding ga_step_alt\n    apply (rule system_complete_language_eq_lsystem_accept)\n    unfolding ga_step_alt[symmetric]\n    unfolding ga_automaton_def[symmetric]\n    by unfold_locales\n\nend\n\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/CAVA_LTL_Modelchecker/SM/Refine/Pid_Scheduler.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.63341027751814, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.2969368009092318}}
{"text": "(*  Title:      HOL/HOLCF/IOA/meta_theory/CompoExecs.thy\n    Author:     Olaf Müller\n*)\n\nsection {* Compositionality on Execution level *}\n\ntheory CompoExecs\nimports Traces\nbegin\n\ndefinition\n  ProjA2 :: \"('a,'s * 't)pairs -> ('a,'s)pairs\" where\n  \"ProjA2 = Map (%x.(fst x,fst(snd x)))\"\n\ndefinition\n  ProjA :: \"('a,'s * 't)execution => ('a,'s)execution\" where\n  \"ProjA ex = (fst (fst ex), ProjA2$(snd ex))\"\n\ndefinition\n  ProjB2 :: \"('a,'s * 't)pairs -> ('a,'t)pairs\" where\n  \"ProjB2 = Map (%x.(fst x,snd(snd x)))\"\n\ndefinition\n  ProjB :: \"('a,'s * 't)execution => ('a,'t)execution\" where\n  \"ProjB ex = (snd (fst ex), ProjB2$(snd ex))\"\n\ndefinition\n  Filter_ex2 :: \"'a signature => ('a,'s)pairs -> ('a,'s)pairs\" where\n  \"Filter_ex2 sig = Filter (%x. fst x:actions sig)\"\n\ndefinition\n  Filter_ex :: \"'a signature => ('a,'s)execution => ('a,'s)execution\" where\n  \"Filter_ex sig ex = (fst ex,Filter_ex2 sig$(snd ex))\"\n\ndefinition\n  stutter2 :: \"'a signature => ('a,'s)pairs -> ('s => tr)\" where\n  \"stutter2 sig = (fix$(LAM h ex. (%s. case ex of\n      nil => TT\n    | x##xs => (flift1\n            (%p.(If Def ((fst p)~:actions sig)\n                 then Def (s=(snd p))\n                 else TT)\n                andalso (h$xs) (snd p))\n             $x)\n   )))\"\n\ndefinition\n  stutter :: \"'a signature => ('a,'s)execution => bool\" where\n  \"stutter sig ex = ((stutter2 sig$(snd ex)) (fst ex) ~= FF)\"\n\ndefinition\n  par_execs :: \"[('a,'s)execution_module,('a,'t)execution_module] => ('a,'s*'t)execution_module\" where\n  \"par_execs ExecsA ExecsB =\n      (let exA = fst ExecsA; sigA = snd ExecsA;\n           exB = fst ExecsB; sigB = snd ExecsB\n       in\n       (    {ex. Filter_ex sigA (ProjA ex) : exA}\n        Int {ex. Filter_ex sigB (ProjB ex) : exB}\n        Int {ex. stutter sigA (ProjA ex)}\n        Int {ex. stutter sigB (ProjB ex)}\n        Int {ex. Forall (%x. fst x:(actions sigA Un actions sigB)) (snd ex)},\n        asig_comp sigA sigB))\"\n\n\nlemmas [simp del] = split_paired_All\n\n\nsection \"recursive equations of operators\"\n\n\n(* ---------------------------------------------------------------- *)\n(*                               ProjA2                             *)\n(* ---------------------------------------------------------------- *)\n\n\nlemma ProjA2_UU: \"ProjA2$UU = UU\"\napply (simp add: ProjA2_def)\ndone\n\nlemma ProjA2_nil: \"ProjA2$nil = nil\"\napply (simp add: ProjA2_def)\ndone\n\nlemma ProjA2_cons: \"ProjA2$((a,t)>>xs) = (a,fst t) >> ProjA2$xs\"\napply (simp add: ProjA2_def)\ndone\n\n\n(* ---------------------------------------------------------------- *)\n(*                               ProjB2                             *)\n(* ---------------------------------------------------------------- *)\n\n\nlemma ProjB2_UU: \"ProjB2$UU = UU\"\napply (simp add: ProjB2_def)\ndone\n\nlemma ProjB2_nil: \"ProjB2$nil = nil\"\napply (simp add: ProjB2_def)\ndone\n\nlemma ProjB2_cons: \"ProjB2$((a,t)>>xs) = (a,snd t) >> ProjB2$xs\"\napply (simp add: ProjB2_def)\ndone\n\n\n\n(* ---------------------------------------------------------------- *)\n(*                             Filter_ex2                           *)\n(* ---------------------------------------------------------------- *)\n\n\nlemma Filter_ex2_UU: \"Filter_ex2 sig$UU=UU\"\napply (simp add: Filter_ex2_def)\ndone\n\nlemma Filter_ex2_nil: \"Filter_ex2 sig$nil=nil\"\napply (simp add: Filter_ex2_def)\ndone\n\nlemma Filter_ex2_cons: \"Filter_ex2 sig$(at >> xs) =\n             (if (fst at:actions sig)\n                  then at >> (Filter_ex2 sig$xs)\n                  else        Filter_ex2 sig$xs)\"\n\napply (simp add: Filter_ex2_def)\ndone\n\n\n(* ---------------------------------------------------------------- *)\n(*                             stutter2                             *)\n(* ---------------------------------------------------------------- *)\n\n\nlemma stutter2_unfold: \"stutter2 sig = (LAM ex. (%s. case ex of\n       nil => TT\n     | x##xs => (flift1\n             (%p.(If Def ((fst p)~:actions sig)\n                  then Def (s=(snd p))\n                  else TT)\n                 andalso (stutter2 sig$xs) (snd p))\n              $x)\n            ))\"\napply (rule trans)\napply (rule fix_eq2)\napply (simp only: stutter2_def)\napply (rule beta_cfun)\napply (simp add: flift1_def)\ndone\n\nlemma stutter2_UU: \"(stutter2 sig$UU) s=UU\"\napply (subst stutter2_unfold)\napply simp\ndone\n\nlemma stutter2_nil: \"(stutter2 sig$nil) s = TT\"\napply (subst stutter2_unfold)\napply simp\ndone\n\nlemma stutter2_cons: \"(stutter2 sig$(at>>xs)) s =\n               ((if (fst at)~:actions sig then Def (s=snd at) else TT)\n                 andalso (stutter2 sig$xs) (snd at))\"\napply (rule trans)\napply (subst stutter2_unfold)\napply (simp add: Consq_def flift1_def If_and_if)\napply simp\ndone\n\n\ndeclare stutter2_UU [simp] stutter2_nil [simp] stutter2_cons [simp]\n\n\n(* ---------------------------------------------------------------- *)\n(*                             stutter                              *)\n(* ---------------------------------------------------------------- *)\n\nlemma stutter_UU: \"stutter sig (s, UU)\"\napply (simp add: stutter_def)\ndone\n\nlemma stutter_nil: \"stutter sig (s, nil)\"\napply (simp add: stutter_def)\ndone\n\nlemma stutter_cons: \"stutter sig (s, (a,t)>>ex) =\n      ((a~:actions sig --> (s=t)) & stutter sig (t,ex))\"\napply (simp add: stutter_def)\ndone\n\n(* ----------------------------------------------------------------------------------- *)\n\ndeclare stutter2_UU [simp del] stutter2_nil [simp del] stutter2_cons [simp del]\n\nlemmas compoex_simps = ProjA2_UU ProjA2_nil ProjA2_cons\n  ProjB2_UU ProjB2_nil ProjB2_cons\n  Filter_ex2_UU Filter_ex2_nil Filter_ex2_cons\n  stutter_UU stutter_nil stutter_cons\n\ndeclare compoex_simps [simp]\n\n\n\n(* ------------------------------------------------------------------ *)\n(*                      The following lemmata aim for                 *)\n(*             COMPOSITIONALITY   on    EXECUTION     Level           *)\n(* ------------------------------------------------------------------ *)\n\n\n(* --------------------------------------------------------------------- *)\n(*  Lemma_1_1a : is_ex_fr propagates from A||B to Projections A and B    *)\n(* --------------------------------------------------------------------- *)\n\nlemma lemma_1_1a: \"!s. is_exec_frag (A||B) (s,xs)\n       -->  is_exec_frag A (fst s, Filter_ex2 (asig_of A)$(ProjA2$xs)) &\n            is_exec_frag B (snd s, Filter_ex2 (asig_of B)$(ProjB2$xs))\"\n\napply (tactic {* pair_induct_tac @{context} \"xs\" [@{thm is_exec_frag_def}] 1 *})\n(* main case *)\napply (auto simp add: trans_of_defs2)\ndone\n\n\n(* --------------------------------------------------------------------- *)\n(*  Lemma_1_1b : is_ex_fr (A||B) implies stuttering on Projections       *)\n(* --------------------------------------------------------------------- *)\n\nlemma lemma_1_1b: \"!s. is_exec_frag (A||B) (s,xs)\n       --> stutter (asig_of A) (fst s,ProjA2$xs)  &\n           stutter (asig_of B) (snd s,ProjB2$xs)\"\n\napply (tactic {* pair_induct_tac @{context} \"xs\"\n  [@{thm stutter_def}, @{thm is_exec_frag_def}] 1 *})\n(* main case *)\napply (auto simp add: trans_of_defs2)\ndone\n\n\n(* --------------------------------------------------------------------- *)\n(*  Lemma_1_1c : Executions of A||B have only  A- or B-actions           *)\n(* --------------------------------------------------------------------- *)\n\nlemma lemma_1_1c: \"!s. (is_exec_frag (A||B) (s,xs)\n   --> Forall (%x. fst x:act (A||B)) xs)\"\n\napply (tactic {* pair_induct_tac @{context} \"xs\" [@{thm Forall_def}, @{thm sforall_def},\n  @{thm is_exec_frag_def}] 1 *})\n(* main case *)\napply auto\napply (simp add: trans_of_defs2 actions_asig_comp asig_of_par)\ndone\n\n\n(* ----------------------------------------------------------------------- *)\n(*  Lemma_1_2 : ex A, exB, stuttering and forall a:A|B implies ex (A||B)   *)\n(* ----------------------------------------------------------------------- *)\n\nlemma lemma_1_2:\n\"!s. is_exec_frag A (fst s,Filter_ex2 (asig_of A)$(ProjA2$xs)) &\n     is_exec_frag B (snd s,Filter_ex2 (asig_of B)$(ProjB2$xs)) &\n     stutter (asig_of A) (fst s,(ProjA2$xs)) &\n     stutter (asig_of B) (snd s,(ProjB2$xs)) &\n     Forall (%x. fst x:act (A||B)) xs\n     --> is_exec_frag (A||B) (s,xs)\"\n\napply (tactic {* pair_induct_tac @{context} \"xs\" [@{thm Forall_def}, @{thm sforall_def},\n  @{thm is_exec_frag_def}, @{thm stutter_def}] 1 *})\napply (auto simp add: trans_of_defs1 actions_asig_comp asig_of_par)\ndone\n\n\nsubsection {* COMPOSITIONALITY on EXECUTION Level -- Main Theorem *}\n\nlemma compositionality_ex:\n\"(ex:executions(A||B)) =\n (Filter_ex (asig_of A) (ProjA ex) : executions A &\n  Filter_ex (asig_of B) (ProjB ex) : executions B &\n  stutter (asig_of A) (ProjA ex) & stutter (asig_of B) (ProjB ex) &\n  Forall (%x. fst x:act (A||B)) (snd ex))\"\n\napply (simp (no_asm) add: executions_def ProjB_def Filter_ex_def ProjA_def starts_of_par)\napply (tactic {* pair_tac @{context} \"ex\" 1 *})\napply (rule iffI)\n(* ==>  *)\napply (erule conjE)+\napply (simp add: lemma_1_1a lemma_1_1b lemma_1_1c)\n(* <==  *)\napply (erule conjE)+\napply (simp add: lemma_1_2)\ndone\n\n\nsubsection {* COMPOSITIONALITY on EXECUTION Level -- for Modules *}\n\nlemma compositionality_ex_modules:\n  \"Execs (A||B) = par_execs (Execs A) (Execs B)\"\napply (unfold Execs_def par_execs_def)\napply (simp add: asig_of_par)\napply (rule set_eqI)\napply (simp add: compositionality_ex actions_of_par)\ndone\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/HOLCF/IOA/meta_theory/CompoExecs.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6334102498375401, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.296936787932826}}
{"text": "theory Extra14\n  imports ExtraInv VCTheoryLemmas\nbegin\n\nabbreviation s where \"s s0 userAtTop_value userAtBottom_value directionSwitch_value alarmButton_value stuck_value \\<equiv>\n (toEnv (setVarAny s0 userAtTop_value userAtBottom_value directionSwitch_value alarmButton_value stuck_value))\"\n\ntheorem extra14: \"VC14 extraInv env s0 userAtTop_value userAtBottom_value directionSwitch_value alarmButton_value stuck_value \"\n  apply(simp only: VC14_def extraInv_def)\n  apply(rule impI)\n  apply(rule conjI)\n   apply simp\n  subgoal\n    apply((drule conjE[of _ _ ?thesis])+)\n                        defer\n                        apply assumption+\n    subgoal premises prems\n      apply(rule conjI)\n      using prems(1-7) prems(8) apply simp\n      apply(rule conjI)\n      using prems(1-7) prems(9) apply simp\n      apply(rule conjI)\n      using prems(10) apply -[1]\n       apply(rule allI)\n      subgoal for s1\n        apply(cases \"s1 = s s0 userAtTop_value userAtBottom_value directionSwitch_value alarmButton_value stuck_value\")\n         apply(rule impI)\n         apply(drule allE[of _ s0])\n          prefer 2\n          apply assumption\n         apply(drule impE)\n           prefer 3\n           apply assumption\n        using prems(1-7) substate_refl apply simp\n         apply(drule exE)\n          prefer 2\n          apply assumption\n         apply(drule exE)\n          prefer 2\n          apply assumption\n        subgoal for s2 s3\n          apply(rule exI[of _ s2])\n          apply(rule exI[of _ s3])\n          apply(rule cut_rl[of \"s2 \\<noteq> s s0 userAtTop_value userAtBottom_value directionSwitch_value alarmButton_value stuck_value\"])\n           apply auto[1]\n          apply(rule cut_rl[of \"s2 \\<noteq> s0 \\<and> substate s0 (s s0 userAtTop_value userAtBottom_value directionSwitch_value alarmButton_value stuck_value)\"])\n          using substate_trans substate_antisym apply blast\n          using prems(1-7) substate_refl apply simp\n          by (metis substate_antisym toEnvNum_id)\n        using prems(1-7) by simp\n      apply(rule conjI)\n      using prems(11) apply -[1]\n       apply(rule allI)\n      subgoal for s3\n        apply(cases \"s3 = s s0 userAtTop_value userAtBottom_value directionSwitch_value alarmButton_value stuck_value\")\n         apply(rule impI)\n          apply(drule allE[of _ s0])\n           prefer 2\n        apply assumption\n        using prems(1-7) substate_refl toEnvP_ltime apply simp\n         apply (metis One_nat_def Suc_less_eq2 diff_Suc_1)\n        using prems(1-7) by simp\n      apply(rule conjI)\n      using prems(1-7) prems(12) apply simp\n      apply(rule conjI)\n      using prems(1-7) prems(13) apply simp\n      apply(rule conjI)\n      using prems(1-7) prems(14) apply simp\n      apply(rule conjI)\n      using prems(1-7)  prems(15) apply simp\n      apply(rule conjI)\n      using prems(1-7)  prems(16) apply simp\n      apply(rule conjI)\n      using prems(1-7)  prems(17) apply simp\n      apply(rule conjI)\n      using prems(1-7)  prems(18) apply simp\n      apply(rule conjI)\n      using prems(1-7)  prems(19) apply simp\n      apply(rule conjI)\n      using prems(1-7) prems(20) apply simp\n      apply(rule conjI)\n      using prems(1-7)  prems(21) apply simp\n      apply(rule conjI)\n      using prems(1-7)  prems(22) substate_refl apply simp\n      apply(rule conjI)\n      using prems(1-7) prems(23) apply simp\n      using prems(1-7) prems(24) by simp\n    done\n  done\n\nend       \n", "meta": {"author": "ivchernenko", "repo": "post_vcgenerator", "sha": "fadfff131086870a027d6bd1c78b8d5a3baf183b", "save_path": "github-repos/isabelle/ivchernenko-post_vcgenerator", "path": "github-repos/isabelle/ivchernenko-post_vcgenerator/post_vcgenerator-fadfff131086870a027d6bd1c78b8d5a3baf183b/case-studies/escalator/Extra14.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6548947290421275, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.2968387951411703}}
{"text": "           (*-------------------------------------------*\n            |  The Dining Mathematicians in CSP-Prover  |\n            |               August 2004                 |\n            |             December 2004 (modified)      |\n            |             November 2005 (modified)      |\n            |                March 2007  (modified)     |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory DM2_para\nimports DM1_Imp_def\nbegin\n\n(*****************************************************************\n\n         1. expands parallel operators in Imp\n         2.\n         3. \n         4. \n\n *****************************************************************)\n\n(*** TH0 VAR step 1 ***)\n\nlemma TH0_VAR: \n  \"(($TH0) |[CH0]| ($(VAR n)))\n   =F (? x:insert (RD0 n) (insert (RD1 n) (range WR1)) \n          -> IF (x : (range RD0) | x : (range WR0))\n                THEN IF EVEN (getInt x) \n                     THEN (Eat0  -> ($(EAT0 n)) |[CH0]| ($(VAR n)))\n                     ELSE (Back0 -> ($TH0) |[CH0]| ($(VAR n)))\n                ELSE (($TH0) |[CH0]| ($(VAR (getInt x)))))\"\napply (cspF_simp unfold_Imp_rules3)+\napply (cspF_step_left)+\napply (case_tac \"EVEN n\")\napply (auto)\napply (cspF_simp fold_Imp_rules3)+\ndone\n\nlemmas TH0_VAR_simp = TH0_VAR[simplified]\nlemmas unfold_Imp_rules4 = unfold_Imp_rules3 TH0_VAR_simp\nlemmas fold_Imp_rules4 = fold_Imp_rules3 TH0_VAR_simp[THEN cspF_sym]\n\n(*** TH0 VAR TH1 step 1 ***)\n\nlemma TH0_VAR_TH1:\n  \"(($TH0) |[CH0]| ($(VAR n)) |[CH1]| ($TH1))\n   =F\n    ? x:{(RD0 n), (RD1 n)} \n      -> IF (x = RD0 n)\n            THEN IF EVEN n\n                 THEN (Eat0 -> ($(EAT0 n)) |[CH0]| ($(VAR n)) \n                                                 |[CH1]| ($TH1))\n                 ELSE (Back0 -> ($TH0)   |[CH0]| ($(VAR n)) \n                                               |[CH1]| ($TH1))\n            ELSE IF ODD n\n                 THEN (($TH0) |[CH0]| ($(VAR n)) \n                                    |[CH1]| Eat1 -> ($(EAT1 n)))\n                 ELSE (($TH0) |[CH0]| ($(VAR n)) \n                                    |[CH1]| Back1 -> ($TH1))\"\napply (cspF_simp unfold_Imp_rules4)\napply (cspF_step_left)\napply (case_tac \"EVEN n\")\napply (auto)\napply (cspF_simp fold_Imp_rules4)+\ndone\n\nlemmas TH0_VAR_TH1_simp = TH0_VAR_TH1[simplified]\nlemmas unfold_Imp_rules5 = unfold_Imp_rules4 TH0_VAR_TH1_simp\nlemmas fold_Imp_rules5 = fold_Imp_rules4 TH0_VAR_TH1_simp[THEN cspF_sym]\n\n(*** Eat0 VAR step 2 ***)\n\nlemma Eat0_VAR: \n  \" (Eat0 -> ($(EAT0 n)) |[CH0]| ($(VAR n)))\n   =F\n    ? x:insert Eat0 (insert (RD1 n) (range WR1))\n        -> IF (x = Eat0) \n              THEN (($(EAT0 n)) |[CH0]| ($(VAR n)))\n              ELSE IF (x = RD1 n) \n                   THEN (Eat0 -> ($(EAT0 n)) |[CH0]| ($(VAR n)))\n                   ELSE (Eat0 -> ($(EAT0 n)) |[CH0]| ($(VAR (getInt x))))\"\napply (cspF_simp unfold_Imp_rules5)\napply (cspF_step_left)+\napply (auto)\napply (cspF_simp fold_Imp_rules5)+\ndone\n\nlemmas Eat0_VAR_simp = Eat0_VAR[simplified]\nlemmas unfold_Imp_rules6 = unfold_Imp_rules5 Eat0_VAR_simp\nlemmas fold_Imp_rules6 = fold_Imp_rules5 Eat0_VAR_simp[THEN cspF_sym]\n\n(*** Back0 VAR step 2 ***)\n\nlemma Back0_VAR: \n  \" (Back0 -> ($TH0) |[CH0]| ($(VAR n)))\n   =F\n    ? x:insert Back0 (insert (RD1 n) (range WR1))\n        -> IF (x = Back0) \n              THEN (($TH0) |[CH0]| ($(VAR n)))\n              ELSE IF (x = RD1 n)\n                   THEN (Back0 -> ($TH0) |[CH0]| ($(VAR n)))\n                   ELSE (Back0 -> ($TH0) |[CH0]| ($(VAR (getInt x))))\"\napply (cspF_simp unfold_Imp_rules6)\napply (cspF_step_left)+\napply (auto)\napply (cspF_simp fold_Imp_rules6)+\ndone\n\nlemmas Back0_VAR_simp = Back0_VAR[simplified]\nlemmas unfold_Imp_rules7 = unfold_Imp_rules6 Back0_VAR_simp\nlemmas fold_Imp_rules7 = fold_Imp_rules6 Back0_VAR_simp[THEN cspF_sym]\n\n(*** Eat0 VAR TH1 step 2 ***)\n\nlemma Eat0_VAR_TH1: \n  \"EVEN n ==>\n    (Eat0 -> ($(EAT0 n)) |[CH0]| ($(VAR n)) |[CH1]| ($TH1))\n   =F\n    ? x:{Eat0, (RD1 n)} \n      -> IF (x = Eat0)\n            THEN (($(EAT0 n)) |[CH0]| ($(VAR n)) |[CH1]| ($TH1))\n            ELSE (Eat0 -> ($(EAT0 n)) |[CH0]| ($(VAR n)) \n                                            |[CH1]| Back1 -> ($TH1))\"\napply (cspF_simp unfold_Imp_rules7)\napply (cspF_step_left)\napply (auto)\napply (cspF_simp fold_Imp_rules7)+\ndone\n\nlemmas Eat0_VAR_TH1_simp = Eat0_VAR_TH1[simplified]\nlemmas unfold_Imp_rules8 = unfold_Imp_rules7 Eat0_VAR_TH1_simp\nlemmas fold_Imp_rules8 = fold_Imp_rules7 Eat0_VAR_TH1_simp[THEN cspF_sym]\n\n(****************************)\n(*** Back0 VAR TH1 step 2 ***)\n\nlemma Back0_VAR_TH1: \n  \" (Back0 -> ($TH0) |[CH0]| ($(VAR n))\n                           |[CH1]| ($TH1))\n   =F\n    ? x:{Back0, (RD1 n)} \n      -> IF (x = Back0)\n            THEN (($TH0) |[CH0]| ($(VAR n)) |[CH1]| ($TH1))\n            ELSE IF ODD n \n                 THEN (Back0 -> ($TH0) |[CH0]| ($(VAR n))\n                                             |[CH1]| Eat1 -> ($(EAT1 n)))\n                 ELSE (Back0 -> ($TH0) |[CH0]| ($(VAR n))\n                                             |[CH1]| Back1 -> ($TH1))\"\napply (cspF_simp unfold_Imp_rules8)\napply (cspF_step_left)\napply (case_tac \"EVEN n\")\napply (auto)\napply (cspF_simp fold_Imp_rules8)+\ndone\n\nlemmas Back0_VAR_TH1_simp = Back0_VAR_TH1[simplified]\nlemmas unfold_Imp_rules9 = unfold_Imp_rules8 Back0_VAR_TH1_simp\nlemmas fold_Imp_rules9 = fold_Imp_rules8 Back0_VAR_TH1_simp[THEN cspF_sym]\n\n(*** TH0 VAR Eat1 step 2 ***)\n\nlemma TH0_VAR_Eat1: \n  \"ODD n ==>\n    (($TH0) |[CH0]| ($(VAR n)) \n                  |[CH1]| Eat1 -> ($(EAT1 n)))\n   =F\n    ? x:{Eat1, (RD0 n)} \n      -> IF (x = Eat1)\n            THEN (($TH0) |[CH0]| ($(VAR n)) |[CH1]| ($(EAT1 n))) \n            ELSE (Back0 -> ($TH0) |[CH0]| ($(VAR n)) \n                                        |[CH1]| Eat1 -> ($(EAT1 n)))\"\napply (cspF_simp unfold_Imp_rules9)\napply (cspF_step_left)+\napply (auto)\napply (cspF_simp fold_Imp_rules9)+\ndone\n\nlemmas TH0_VAR_Eat1_simp = TH0_VAR_Eat1[simplified]\nlemmas unfold_Imp_rules10 = unfold_Imp_rules9 TH0_VAR_Eat1_simp\nlemmas fold_Imp_rules10 = fold_Imp_rules9 TH0_VAR_Eat1_simp[THEN cspF_sym]\n\n(****************************)\n(*** TH0 VAR Back1 step 2 ***)\n\nlemma TH0_VAR_Back1: \n  \" (($TH0) |[CH0]| ($(VAR n)) |[CH1]| Back1 -> ($TH1))\n   =F\n    ? x:{Back1, (RD0 n)}\n      -> IF (x = Back1)\n            THEN (($TH0) |[CH0]| ($(VAR n)) |[CH1]| ($TH1))\n            ELSE IF EVEN n \n                 THEN (Eat0 -> ($(EAT0 n)) |[CH0]| ($(VAR n)) \n                                                 |[CH1]| Back1 -> ($TH1)) \n                 ELSE (Back0 -> ($TH0) |[CH0]| ($(VAR n)) \n                                             |[CH1]| Back1 -> ($TH1))\"\napply (cspF_simp unfold_Imp_rules10)\napply (cspF_step_left)+\napply (case_tac \"EVEN n\")\napply (auto)\napply (cspF_simp fold_Imp_rules10)+\ndone\n\nlemmas TH0_VAR_Back1_simp = TH0_VAR_Back1[simplified]\nlemmas unfold_Imp_rules11 = unfold_Imp_rules10 TH0_VAR_Back1_simp\nlemmas fold_Imp_rules11 = fold_Imp_rules10 TH0_VAR_Back1_simp[THEN cspF_sym]\n\n(*** EAT0 VAR step 3 ***)\n\nlemma EAT0_VAR: \n  \" (($(EAT0 n)) |[CH0]| ($(VAR n)))\n   =F\n    ? x:insert End0 (insert (RD1 n) (range WR1))\n     -> IF (x = End0) \n           THEN (WR0 (n div 2) -> ($TH0) |[CH0]| ($(VAR n)))\n           ELSE IF (x = RD1 n) \n                THEN (($(EAT0 n)) |[CH0]| ($(VAR n)))\n                ELSE (($(EAT0 n)) |[CH0]| ($(VAR (getInt x))))\"\napply (cspF_simp unfold_Imp_rules11)\napply (cspF_step_left)+\napply (case_tac \"EVEN n\")\napply (auto)\napply (cspF_simp fold_Imp_rules11)+\ndone\n\nlemmas EAT0_VAR_simp = EAT0_VAR[simplified]\nlemmas unfold_Imp_rules12 = unfold_Imp_rules11 EAT0_VAR_simp\nlemmas fold_Imp_rules12 = fold_Imp_rules11 EAT0_VAR_simp[THEN cspF_sym]\n\n(*** EAT0 VAR TH1 step 3 ***)\n\nlemma EAT0_VAR_TH1: \n  \"EVEN n ==>\n    (($(EAT0 n)) |[CH0]| ($(VAR n)) |[CH1]| ($TH1))\n   =F\n    ? x:{End0, (RD1 n)} \n      -> IF (x = End0)\n            THEN (WR0 (n div 2) -> ($TH0) |[CH0]| ($(VAR n)) \n                                                |[CH1]| ($TH1))\n            ELSE (($(EAT0 n)) |[CH0]| ($(VAR n)) \n                                    |[CH1]| Back1 -> ($TH1))\"\napply (cspF_simp unfold_Imp_rules12)\napply (cspF_step_left)+\napply (auto)\napply (cspF_simp fold_Imp_rules12)+\ndone\n\nlemmas EAT0_VAR_TH1_simp = EAT0_VAR_TH1[simplified]\nlemmas unfold_Imp_rules13 = unfold_Imp_rules12 EAT0_VAR_TH1_simp\nlemmas fold_Imp_rules13 = fold_Imp_rules12 EAT0_VAR_TH1_simp[THEN cspF_sym]\n\n(*** Eat0 VAR Back1 step 3 ***)\n\nlemma Eat0_VAR_Back1:\n  \"EVEN n ==>\n        (Eat0 -> ($(EAT0 n)) |[CH0]| ($(VAR n)) \n                                   |[CH1]| Back1 -> ($TH1))\n   =F\n    ? x:{Eat0, Back1} \n      -> IF (x = Eat0)\n            THEN (($(EAT0 n)) |[CH0]| ($(VAR n)) \n                                    |[CH1]| Back1 -> ($TH1))\n            ELSE (Eat0 -> ($(EAT0 n)) |[CH0]| ($(VAR n)) \n                                            |[CH1]| ($TH1))\"\napply (cspF_simp unfold_Imp_rules13)\napply (cspF_step_left)+\napply (auto)\napply (cspF_simp fold_Imp_rules13)+\ndone\n\nlemmas Eat0_VAR_Back1_simp = Eat0_VAR_Back1[simplified]\nlemmas unfold_Imp_rules14 = unfold_Imp_rules13 Eat0_VAR_Back1_simp\nlemmas fold_Imp_rules14 = fold_Imp_rules13 Eat0_VAR_Back1_simp[THEN cspF_sym]\n\n(*** TH0 VAR EAT1 step 3 ***)\n\nlemma TH0_VAR_EAT1: \n  \"ODD n ==>\n    (($TH0) |[CH0]| ($(VAR n)) |[CH1]| ($(EAT1 n)))\n   =F\n    ? x:{End1, (RD0 n)} \n   -> IF (x = End1)\n         THEN (($TH0) |[CH0]| ($(VAR n)) \n                            |[CH1]| WR1 (3 * n + 1) -> ($TH1))\n         ELSE (Back0 -> ($TH0) |[CH0]| ($(VAR n)) \n                                     |[CH1]| ($(EAT1 n)))\"\napply (cspF_simp unfold_Imp_rules14)\napply (cspF_step_left)+\napply (auto)\napply (cspF_simp fold_Imp_rules14)+\ndone\n\nlemmas TH0_VAR_EAT1_simp = TH0_VAR_EAT1[simplified]\nlemmas unfold_Imp_rules15 = unfold_Imp_rules14 TH0_VAR_EAT1_simp\nlemmas fold_Imp_rules15 = fold_Imp_rules14 TH0_VAR_EAT1_simp[THEN cspF_sym]\n\n(*** Back0 VAR Eat1 step 3 ***)\n\nlemma Back0_VAR_Eat1: \n  \"ODD n ==>\n    (Back0 -> ($TH0) |[CH0]| ($(VAR n)) |[CH1]| Eat1 -> ($(EAT1 n)))\n   =F\n    ? x:{Eat1, Back0} \n   -> IF (x = Eat1)\n         THEN (Back0 -> ($TH0) |[CH0]| ($(VAR n)) \n                                     |[CH1]| ($(EAT1 n)))\n         ELSE (($TH0) |[CH0]| ($(VAR n)) \n                            |[CH1]| Eat1 -> ($(EAT1 n)))\"\napply (cspF_simp unfold_Imp_rules15)\napply (cspF_step_left)+\napply (auto)\napply (cspF_simp fold_Imp_rules15)+\ndone\n\nlemmas Back0_VAR_Eat1_simp = Back0_VAR_Eat1[simplified]\nlemmas unfold_Imp_rules16 = unfold_Imp_rules15 Back0_VAR_Eat1_simp\nlemmas fold_Imp_rules16 = fold_Imp_rules15 Back0_VAR_Eat1_simp[THEN cspF_sym]\n\n(*** Back0 VAR Back1 step 3 ***)\n\nlemma Back0_VAR_Back1: \n  \" (Back0 -> ($TH0) |[CH0]| ($(VAR n)) |[CH1]| Back1 -> ($TH1))\n   =F\n    ? x:{Back0, Back1} \n      -> IF (x = Back0)\n            THEN (($TH0) |[CH0]| ($(VAR n)) |[CH1]| Back1 -> ($TH1))\n            ELSE (Back0 -> ($TH0) |[CH0]| ($(VAR n)) |[CH1]| ($TH1))\"\napply (cspF_simp unfold_Imp_rules16)\napply (cspF_step_left)+\napply (auto)\napply (cspF_simp fold_Imp_rules16)+\ndone\n\nlemmas Back0_VAR_Back1_simp = Back0_VAR_Back1[simplified]\nlemmas unfold_Imp_rules17 = unfold_Imp_rules16 Back0_VAR_Back1_simp\nlemmas fold_Imp_rules17 = fold_Imp_rules16 Back0_VAR_Back1_simp[THEN cspF_sym]\n\n(*** WR0 VAR step 4 ***)\n\nlemma WR0_VAR: \n  \" (WR0 (n div 2) -> ($TH0) |[CH0]| ($(VAR n)))\n   =F\n    ? x:insert (WR0 (n div 2)) (insert (RD1 n) (range WR1))\n     -> IF (x = WR0 (n div 2))\n           THEN (($TH0) |[CH0]| ($(VAR (n div 2))))\n           ELSE IF (x = RD1 n)\n                THEN (WR0 (n div 2) -> ($TH0) |[CH0]| ($(VAR n)))\n                ELSE (WR0 (n div 2) -> ($TH0) |[CH0]| ($(VAR (getInt x))))\"\napply (cspF_simp unfold_Imp_rules17)\napply (cspF_step_left)+\napply (auto)\napply (cspF_simp fold_Imp_rules17)+\ndone\n\nlemmas WR0_VAR_simp = WR0_VAR[simplified]\nlemmas unfold_Imp_rules18 = unfold_Imp_rules17 WR0_VAR_simp\nlemmas fold_Imp_rules18 = fold_Imp_rules17 WR0_VAR_simp[THEN cspF_sym]\n\n(*** WR0 VAR TH1 step 4 ***)\n\nlemma WR0_VAR_TH1: \n  \"EVEN n ==>\n    (WR0 (n div 2) -> ($TH0) |[CH0]| ($(VAR n)) |[CH1]| ($TH1))\n   =F\n    ? x:{(WR0 (n div 2)), (RD1 n)}\n      -> IF (x = WR0 (n div 2))\n            THEN (($TH0)  |[CH0]| ($(VAR (n div 2))) |[CH1]| ($TH1))\n            ELSE (WR0 (n div 2) -> ($TH0) |[CH0]| ($(VAR n)) \n                                                |[CH1]| Back1 -> ($TH1))\"\napply (cspF_simp unfold_Imp_rules18)\napply (cspF_step_left)+\napply (auto)\napply (cspF_simp fold_Imp_rules18)+\ndone\n\nlemmas WR0_VAR_TH1_simp = WR0_VAR_TH1[simplified]\nlemmas unfold_Imp_rules19 = unfold_Imp_rules18 WR0_VAR_TH1_simp\nlemmas fold_Imp_rules19 = fold_Imp_rules18 WR0_VAR_TH1_simp[THEN cspF_sym]\n\n(*** EAT0 VAR Back1 step 4 ***)\n\nlemma EAT0_VAR_Back1: \n  \"EVEN n ==>\n    (($(EAT0 n)) |[CH0]| ($(VAR n)) |[CH1]| Back1 -> ($TH1))\n   =F\n    ? x:{End0, Back1} \n      -> IF (x = End0)\n            THEN (WR0 (n div 2) -> ($TH0) |[CH0]| ($(VAR n)) \n                                                |[CH1]| Back1 -> ($TH1))\n            ELSE (($(EAT0 n)) |[CH0]| ($(VAR n)) |[CH1]| ($TH1))\"\napply (cspF_simp unfold_Imp_rules19)\napply (cspF_step_left)+\napply (auto)\napply (cspF_simp fold_Imp_rules19)+\ndone\n\nlemmas EAT0_VAR_Back1_simp = EAT0_VAR_Back1[simplified]\nlemmas unfold_Imp_rules20 = unfold_Imp_rules19 EAT0_VAR_Back1_simp\nlemmas fold_Imp_rules20 = fold_Imp_rules19 EAT0_VAR_Back1_simp[THEN cspF_sym]\n\n(*** TH0 VAR EAT1 step 4 ***)\n\nlemma TH0_VAR_WR1: \n  \"ODD n ==>\n    (($TH0) |[CH0]| ($(VAR n)) |[CH1]| WR1 (3 * n + 1) -> ($TH1))\n   =F\n    ? x:{(WR1 (3 * n + 1)), (RD0 n)} \n   -> IF (x = WR1 (3 * n + 1))\n         THEN (($TH0) |[CH0]| ($(VAR (3 * n + 1))) |[CH1]| ($TH1))\n         ELSE (Back0 -> ($TH0) |[CH0]| ($(VAR n)) \n                                     |[CH1]| WR1 (3 * n + 1) -> ($TH1))\"\napply (cspF_simp unfold_Imp_rules20)\napply (cspF_step_left)+\napply (auto)\napply (cspF_simp fold_Imp_rules20)+\ndone\n\nlemmas TH0_VAR_WR1_simp = TH0_VAR_WR1[simplified]\nlemmas unfold_Imp_rules21 = unfold_Imp_rules20 TH0_VAR_WR1_simp\nlemmas fold_Imp_rules21 = fold_Imp_rules20 TH0_VAR_WR1_simp[THEN cspF_sym]\n\n(*** Back0 VAR EAT1 step 4 ***)\n\nlemma Back0_VAR_EAT1: \n  \"ODD n ==>\n    (Back0 -> ($TH0) |[CH0]| ($(VAR n)) |[CH1]| ($(EAT1 n)))\n   =F\n    ? x:{End1, Back0} \n   -> IF (x = End1)\n         THEN (Back0 -> ($TH0) |[CH0]| ($(VAR n)) \n                                     |[CH1]| WR1 (3 * n + 1) -> ($TH1))\n         ELSE (($TH0) |[CH0]| ($(VAR n)) |[CH1]| ($(EAT1 n)))\"\napply (cspF_simp unfold_Imp_rules21)\napply (cspF_step_left)+\napply (auto)\napply (cspF_simp fold_Imp_rules21)+\ndone\n\nlemmas Back0_VAR_EAT1_simp = Back0_VAR_EAT1[simplified]\nlemmas unfold_Imp_rules22 = unfold_Imp_rules21 Back0_VAR_EAT1_simp\nlemmas fold_Imp_rules22 = fold_Imp_rules21 Back0_VAR_EAT1_simp[THEN cspF_sym]\n\n(*** WR0 VAR Back1 step 5 ***)\n\nlemma WR0_VAR_Back1: \n  \"EVEN n ==>\n    (WR0 (n div 2) -> ($TH0) |[CH0]| ($(VAR n)) |[CH1]| Back1 -> ($TH1))\n   =F\n    ? x:{(WR0 (n div 2)), Back1}\n      -> IF (x = WR0 (n div 2))\n            THEN (($TH0)  |[CH0]| ($(VAR (n div 2))) \n                                |[CH1]| Back1 -> ($TH1))\n            ELSE (WR0 (n div 2) -> ($TH0) |[CH0]| ($(VAR n)) \n                                                |[CH1]| ($TH1))\"\napply (cspF_simp unfold_Imp_rules22)\napply (cspF_step_left)+\napply (auto)\napply (cspF_simp fold_Imp_rules22)+\ndone\n\nlemmas WR0_VAR_Back1_simp = WR0_VAR_Back1[simplified]\nlemmas unfold_Imp_rules23 = unfold_Imp_rules22 WR0_VAR_Back1_simp\nlemmas fold_Imp_rules23 = fold_Imp_rules22 WR0_VAR_Back1_simp[THEN cspF_sym]\n\n(*** Back0 VAR WR1 step 5 ***)\n\nlemma Back0_VAR_WR1: \n  \"ODD n ==>\n    (Back0 -> ($TH0) |[CH0]| ($(VAR n)) \n                                 |[CH1]| WR1 (3 * n + 1) -> ($TH1))\n   =F\n    ? x:{(WR1 (3 * n + 1)), Back0} \n   -> IF (x = WR1 (3 * n + 1))\n         THEN (Back0 -> ($TH0) |[CH0]| ($(VAR (3 * n + 1))) \n                                     |[CH1]| ($TH1))\n         ELSE (($TH0) |[CH0]| ($(VAR n)) \n                            |[CH1]| WR1 (3 * n + 1) -> ($TH1))\"\napply (cspF_simp unfold_Imp_rules23)\napply (cspF_step_left)+\napply (auto)\napply (cspF_simp fold_Imp_rules23)+\ndone\n\nlemmas Back0_VAR_WR1_simp = Back0_VAR_WR1[simplified]\nlemmas unfold_Imp_rules24 = unfold_Imp_rules23 Back0_VAR_WR1_simp\nlemmas fold_Imp_rules24 = fold_Imp_rules23 Back0_VAR_WR1_simp[THEN cspF_sym]\n\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/DM/DM2_para.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6548947155710233, "lm_q2_score": 0.4532618480153861, "lm_q1q2_score": 0.2968387890352327}}
{"text": "(* Copyright 2021 (C) Mihails Milehins *)\n\nsection\\<open>Cones and cocones\\<close>\ntheory CZH_ECAT_Cone\n  imports \n    CZH_ECAT_NTCF\n    CZH_ECAT_Hom\n    CZH_ECAT_FUNCT\nbegin\n\n\n\nsubsection\\<open>Cone and cocone\\<close>\n\n\nsubsubsection\\<open>Definition and elementary properties\\<close>\n\n\ntext\\<open>\nIn the context of this work, the concept of a cone corresponds to that of a cone\nto the base of a functor from a vertex, as defined in Chapter III-4 in\n\\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>; the concept of a cocone corresponds to that\nof a cone from the base of a functor to a vertex, as defined in Chapter III-3\nin \\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>.\n\\<close>\n\nlocale is_cat_cone = is_ntcf \\<alpha> \\<JJ> \\<CC> \\<open>cf_const \\<JJ> \\<CC> c\\<close> \\<FF> \\<NN> for \\<alpha> c \\<JJ> \\<CC> \\<FF> \\<NN> +\n  assumes cat_cone_obj[cat_cs_intros]: \"c \\<in>\\<^sub>\\<circ> \\<CC>\\<lparr>Obj\\<rparr>\"\n\nsyntax \"_is_cat_cone\" :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> bool\"\n  (\\<open>(_ :/ _ <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e _ :/ _ \\<mapsto>\\<mapsto>\\<^sub>C\\<index> _)\\<close> [51, 51, 51, 51, 51] 51)\ntranslations \"\\<NN> : c <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \\<rightleftharpoons> \n  \"CONST is_cat_cone \\<alpha> c \\<JJ> \\<CC> \\<FF> \\<NN>\"\n\nlocale is_cat_cocone = is_ntcf \\<alpha> \\<JJ> \\<CC> \\<FF> \\<open>cf_const \\<JJ> \\<CC> c\\<close> \\<NN> for \\<alpha> c \\<JJ> \\<CC> \\<FF> \\<NN> +\n  assumes cat_cocone_obj[cat_cs_intros]: \"c \\<in>\\<^sub>\\<circ> \\<CC>\\<lparr>Obj\\<rparr>\"\n\nsyntax \"_is_cat_cocone\" :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> bool\"\n  (\\<open>(_ :/ _ >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e _ :/ _ \\<mapsto>\\<mapsto>\\<^sub>C\\<index> _)\\<close> [51, 51, 51, 51, 51] 51)\ntranslations \"\\<NN> : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e c : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \\<rightleftharpoons> \n  \"CONST is_cat_cocone \\<alpha> c \\<JJ> \\<CC> \\<FF> \\<NN>\"\n\n\ntext\\<open>Rules.\\<close>\n\nlemma (in is_cat_cone) is_cat_cone_axioms'[cat_cs_intros]:\n  assumes \"\\<alpha>' = \\<alpha>\" and \"c' = c\" and \"\\<JJ>' = \\<JJ>\" and \"\\<CC>' = \\<CC>\" and \"\\<FF>' = \\<FF>\"\n  shows \"\\<NN> : c' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF>' : \\<JJ>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>'\\<^esub> \\<CC>'\"\n  unfolding assms by (rule is_cat_cone_axioms)\n\nmk_ide rf is_cat_cone_def[unfolded is_cat_cone_axioms_def]\n  |intro is_cat_coneI|\n  |dest is_cat_coneD[dest!]|\n  |elim is_cat_coneE[elim!]|\n\nlemma (in is_cat_cone) is_cat_coneD'[cat_cs_intros]:\n  assumes \"c' = cf_const \\<JJ> \\<CC> c\"\n  shows \"\\<NN> : c' \\<mapsto>\\<^sub>C\\<^sub>F \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  unfolding assms by (cs_concl cs_shallow cs_intro: cat_cs_intros)\n\nlemma (in is_cat_cocone) is_cat_cocone_axioms'[cat_cs_intros]:\n  assumes \"\\<alpha>' = \\<alpha>\" and \"c' = c\" and \"\\<JJ>' = \\<JJ>\" and \"\\<CC>' = \\<CC>\" and \"\\<FF>' = \\<FF>\"\n  shows \"\\<NN> : \\<FF>' >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e c' : \\<JJ>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>'\\<^esub> \\<CC>'\"\n  unfolding assms by (rule is_cat_cocone_axioms)\n\nmk_ide rf is_cat_cocone_def[unfolded is_cat_cocone_axioms_def]\n  |intro is_cat_coconeI|\n  |dest is_cat_coconeD[dest!]|\n  |elim is_cat_coconeE[elim!]|\n\nlemma (in is_cat_cocone) is_cat_coconeD'[cat_cs_intros]:\n  assumes \"c' = cf_const \\<JJ> \\<CC> c\"\n  shows \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>C\\<^sub>F c' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  unfolding assms by (cs_concl cs_shallow cs_intro: cat_cs_intros)\n\n\ntext\\<open>Duality.\\<close>\n\nlemma (in is_cat_cone) is_cat_cocone_op:\n  \"op_ntcf \\<NN> : op_cf \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e c : op_cat \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_cat \\<CC>\"\n  by (intro is_cat_coconeI)\n    (\n      cs_concl cs_shallow \n        cs_simp: cat_op_simps cs_intro: cat_cs_intros cat_op_intros\n    )+\n\nlemma (in is_cat_cone) is_cat_cocone_op'[cat_op_intros]:\n  assumes \"\\<alpha>' = \\<alpha>\" and \"\\<JJ>' = op_cat \\<JJ>\" and \"\\<CC>' = op_cat \\<CC>\" and \"\\<FF>' = op_cf \\<FF>\"\n  shows \"op_ntcf \\<NN> : \\<FF>' >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e c : \\<JJ>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>'\\<^esub> \\<CC>'\"\n  unfolding assms by (rule is_cat_cocone_op)\n\nlemmas [cat_op_intros] = is_cat_cone.is_cat_cocone_op'\n\nlemma (in is_cat_cocone) is_cat_cone_op:\n  \"op_ntcf \\<NN> : c <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e op_cf \\<FF> : op_cat \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_cat \\<CC>\"\n  by (intro is_cat_coneI)\n    (\n      cs_concl cs_shallow \n        cs_simp: cat_op_simps cs_intro: cat_cs_intros cat_op_intros\n    )\n\nlemma (in is_cat_cocone) is_cat_cone_op'[cat_op_intros]:\n  assumes \"\\<alpha>' = \\<alpha>\" and \"\\<JJ>' = op_cat \\<JJ>\" and \"\\<CC>' = op_cat \\<CC>\" and \"\\<FF>' = op_cf \\<FF>\"\n  shows \"op_ntcf \\<NN> : c <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF>' : \\<JJ>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>'\\<^esub> \\<CC>'\"\n  unfolding assms by (rule is_cat_cone_op)\n\nlemmas [cat_op_intros] = is_cat_cocone.is_cat_cone_op'\n\n\ntext\\<open>Elementary properties.\\<close>\n\nlemma (in is_cat_cone) cat_cone_LArr_app_is_arr: \n  assumes \"j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> : c \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>j\\<rparr>\"\nproof-\n  from assms have [simp]: \"cf_const \\<JJ> \\<CC> c\\<lparr>ObjMap\\<rparr>\\<lparr>j\\<rparr> = c\"\n    by (cs_concl cs_shallow cs_simp: cat_cs_simps)\n  from ntcf_NTMap_is_arr[OF assms] show ?thesis by simp \nqed\n\nlemma (in is_cat_cone) cat_cone_LArr_app_is_arr'[cat_cs_intros]: \n  assumes \"j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr>\" and \"\\<FF>j = \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>j\\<rparr>\"\n  shows \"\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> : c \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<FF>j\"\n  using assms(1) unfolding assms(2) by (rule cat_cone_LArr_app_is_arr)\n\nlemmas [cat_cs_intros] = is_cat_cone.cat_cone_LArr_app_is_arr'\n\nlemma (in is_cat_cocone) cat_cocone_LArr_app_is_arr: \n  assumes \"j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>j\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c\"\nproof-\n  from assms have [simp]: \"cf_const \\<JJ> \\<CC> c\\<lparr>ObjMap\\<rparr>\\<lparr>j\\<rparr> = c\"\n    by (cs_concl cs_shallow cs_simp: cat_cs_simps)\n  from ntcf_NTMap_is_arr[OF assms] show ?thesis by simp \nqed\n\nlemma (in is_cat_cocone) cat_cocone_LArr_app_is_arr'[cat_cs_intros]: \n  assumes \"j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr>\" and \"\\<FF>j = \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>j\\<rparr>\"\n  shows \"\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> : \\<FF>j \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c\"\n  using assms(1) unfolding assms(2) by (rule cat_cocone_LArr_app_is_arr)\n\nlemmas [cat_cs_intros] = is_cat_cocone.cat_cocone_LArr_app_is_arr'\n\nlemma (in is_cat_cone) cat_cone_Comp_commute[cat_cs_simps]:\n  assumes \"f : a \\<mapsto>\\<^bsub>\\<JJ>\\<^esub> b\"\n  shows \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> = \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr>\"\n  using ntcf_Comp_commute[symmetric, OF assms] assms \n  by (cs_prems cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n\nthm (*not ca_cs_simps*) is_cat_cone.cat_cone_Comp_commute\n\nlemma (in is_cat_cocone) cat_cocone_Comp_commute[cat_cs_simps]:\n  assumes \"f : a \\<mapsto>\\<^bsub>\\<JJ>\\<^esub> b\"\n  shows \"\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> = \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\n  using ntcf_Comp_commute[OF assms] assms \n  by\n    (\n      cs_prems \n        cs_simp: cat_cs_simps dghm_const_ArrMap_app cs_intro: cat_cs_intros\n    )\n\nthm (*not ca_cs_simps*) is_cat_cocone.cat_cocone_Comp_commute\n\n\ntext\\<open>Utilities/helper lemmas.\\<close>\n\nlemma (in is_cat_cone) helper_cat_cone_ntcf_vcomp_Comp:\n  assumes \"\\<NN>' : c' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"f' : c' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c\" \n    and \"\\<NN>' = \\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f'\" \n    and \"j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<NN>'\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f'\"\nproof-\n  from assms(3) have \"\\<NN>'\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = (\\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f')\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr>\"\n    by simp\n  from this assms(1,2,4) show \"\\<NN>'\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f'\"\n    by (cs_prems cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\nqed\n\nlemma (in is_cat_cone) helper_cat_cone_Comp_ntcf_vcomp:\n  assumes \"\\<NN>' : c' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"f' : c' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c\" \n    and \"\\<And>j. j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr> \\<Longrightarrow> \\<NN>'\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f'\" \n  shows \"\\<NN>' = \\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f'\"\nproof-\n  interpret \\<NN>': is_cat_cone \\<alpha> c' \\<JJ> \\<CC> \\<FF> \\<NN>' by (rule assms(1))\n  show ?thesis\n  proof(rule ntcf_eqI[OF \\<NN>'.is_ntcf_axioms])\n    from assms(2) show \n      \"\\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f' : cf_const \\<JJ> \\<CC> c' \\<mapsto>\\<^sub>C\\<^sub>F \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n      by (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n    show \"\\<NN>'\\<lparr>NTMap\\<rparr> = (\\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f')\\<lparr>NTMap\\<rparr>\"\n    proof(rule vsv_eqI, unfold cat_cs_simps)\n      show \"vsv ((\\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f')\\<lparr>NTMap\\<rparr>)\"\n        by (cs_concl cs_intro: cat_cs_intros)\n      from assms show \"\\<JJ>\\<lparr>Obj\\<rparr> = \\<D>\\<^sub>\\<circ> ((\\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f')\\<lparr>NTMap\\<rparr>)\"\n        by (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n      fix j assume prems': \"j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr>\"\n      with assms(1,2) show \"\\<NN>'\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = (\\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f')\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr>\"\n        by (cs_concl cs_simp: cat_cs_simps assms(3) cs_intro: cat_cs_intros)\n    qed auto\n  qed simp_all\nqed\n\nlemma (in is_cat_cone) helper_cat_cone_Comp_ntcf_vcomp_iff:\n  assumes \"\\<NN>' : c' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"f' : c' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c \\<and> \\<NN>' = \\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f' \\<longleftrightarrow>\n    f' : c' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c \\<and> (\\<forall>j\\<in>\\<^sub>\\<circ>\\<JJ>\\<lparr>Obj\\<rparr>. \\<NN>'\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f')\"\n  using \n    helper_cat_cone_ntcf_vcomp_Comp[OF assms]\n    helper_cat_cone_Comp_ntcf_vcomp[OF assms]\n  by (intro iffI; elim conjE; intro conjI) metis+\n\nlemma (in is_cat_cocone) helper_cat_cocone_ntcf_vcomp_Comp:\n  assumes \"\\<NN>' : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e c' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"f' : c \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c'\" \n    and \"\\<NN>' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<NN>\" \n    and \"j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<NN>'\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr>\"\nproof-\n  interpret \\<NN>': is_cat_cocone \\<alpha> c' \\<JJ> \\<CC> \\<FF> \\<NN>' by (rule assms(1))\n  from assms(3) have \"op_ntcf \\<NN>' = op_ntcf (ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<NN>)\" by simp\n  from this assms(2) have op_\\<NN>':\n    \"op_ntcf \\<NN>' = op_ntcf \\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f'\"\n    by (cs_prems cs_simp: cat_op_simps cs_intro: cat_cs_intros cat_op_intros)\n  have \"\\<NN>'\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> \\<circ>\\<^sub>A\\<^bsub>op_cat \\<CC>\\<^esub> f'\"\n    by \n      (\n        rule is_cat_cone.helper_cat_cone_ntcf_vcomp_Comp[\n          OF is_cat_cone_op \\<NN>'.is_cat_cone_op, \n          unfolded cat_op_simps, \n          OF assms(2) op_\\<NN>' assms(4)\n          ]\n      )\n  from this assms(2,4) show \"\\<NN>'\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr>\"\n    by \n      (\n        cs_prems cs_shallow \n          cs_simp: cat_cs_simps cat_op_simps cs_intro: cat_cs_intros\n      )\nqed\n\nlemma (in is_cat_cocone) helper_cat_cocone_Comp_ntcf_vcomp:\n  assumes \"\\<NN>' : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e c' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"f' : c \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c'\" \n    and \"\\<And>j. j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr> \\<Longrightarrow> \\<NN>'\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr>\" \n  shows \"\\<NN>' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<NN>\"\nproof-\n  interpret \\<NN>': is_cat_cocone \\<alpha> c' \\<JJ> \\<CC> \\<FF> \\<NN>' by (rule assms(1))\n  from assms(2) have \\<NN>'j: \"\\<NN>'\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> \\<circ>\\<^sub>A\\<^bsub>op_cat \\<CC>\\<^esub> f'\"\n    if \"j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr>\" for j\n    using that\n    unfolding assms(3)[OF that] \n    by \n      (\n        cs_concl cs_shallow \n          cs_simp: cat_op_simps cat_cs_simps cs_intro: cat_cs_intros\n      )\n  have op_\\<NN>': \n    \"op_ntcf \\<NN>' = op_ntcf \\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f'\"\n    by \n      (\n        rule is_cat_cone.helper_cat_cone_Comp_ntcf_vcomp[\n          OF is_cat_cone_op \\<NN>'.is_cat_cone_op,\n          unfolded cat_op_simps, \n          OF assms(2) \\<NN>'j, \n          simplified\n          ]\n      )\n  from assms(2) show \"\\<NN>' = (ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<NN>)\"\n    by \n      (\n        cs_concl  \n          cs_simp: \n            cat_op_simps op_\\<NN>' eq_op_ntcf_iff[symmetric, OF \\<NN>'.is_ntcf_axioms]\n          cs_intro: cat_cs_intros\n      )\nqed\n\nlemma (in is_cat_cocone) helper_cat_cocone_Comp_ntcf_vcomp_iff:\n  assumes \"\\<NN>' : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e c' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"f' : c \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c' \\<and> \\<NN>' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<NN> \\<longleftrightarrow>\n    f' : c \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c' \\<and> (\\<forall>j\\<in>\\<^sub>\\<circ>\\<JJ>\\<lparr>Obj\\<rparr>. \\<NN>'\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr>)\"\n  using \n    helper_cat_cocone_ntcf_vcomp_Comp[OF assms]\n    helper_cat_cocone_Comp_ntcf_vcomp[OF assms]\n  by (intro iffI; elim conjE; intro conjI) metis+\n\n\nsubsubsection\\<open>Vertical composition of a natural transformation and a cone\\<close>\n\nlemma ntcf_vcomp_is_cat_cone[cat_cs_intros]:\n  assumes \"\\<MM> : \\<GG> \\<mapsto>\\<^sub>C\\<^sub>F \\<HH> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"\\<NN> : a <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<NN> : a <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<HH> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  by \n    (\n      intro is_cat_coneI ntcf_vcomp_is_ntcf, rule assms(1); \n      rule is_cat_coneD[OF assms(2)]\n    )\n\n\nsubsubsection\\<open>\nComposition of a functor and a cone, composition of a functor and a cocone\n\\<close>\n\nlemma cf_ntcf_comp_cf_cat_cone: \n  assumes \"\\<NN> : c <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\" and \"\\<GG> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"\\<GG> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<NN> : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>c\\<rparr> <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<GG> \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\nproof-\n  interpret \\<NN>: is_cat_cone \\<alpha> c \\<AA> \\<BB> \\<FF> \\<NN> by (rule assms(1))\n  interpret \\<GG>: is_functor \\<alpha> \\<BB> \\<CC> \\<GG> by (rule assms(2))\n  show ?thesis\n    by (intro is_cat_coneI)\n      (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros )+\nqed\n\nlemma cf_ntcf_comp_cf_cat_cone'[cat_cs_intros]: \n  assumes \"\\<NN> : c <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\" \n    and \"\\<GG> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"c' = \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>c\\<rparr>\"\n    and \"\\<GG>\\<FF> = \\<GG> \\<circ>\\<^sub>C\\<^sub>F \\<FF>\"\n  shows \"\\<GG> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<NN> : c' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<GG>\\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  using assms(1,2) unfolding assms(3,4) by (rule cf_ntcf_comp_cf_cat_cone)\n\nlemma cf_ntcf_comp_cf_cat_cocone:\n  assumes \"\\<NN> : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e c : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\" and \"\\<GG> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"\\<GG> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<NN> : \\<GG> \\<circ>\\<^sub>C\\<^sub>F \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>c\\<rparr> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\nproof-\n  interpret \\<NN>: is_cat_cocone \\<alpha> c \\<AA> \\<BB> \\<FF> \\<NN> by (rule assms(1))\n  interpret \\<GG>: is_functor \\<alpha> \\<BB> \\<CC> \\<GG> by (rule assms(2))\n  show ?thesis\n    by\n      (\n        rule is_cat_cone.is_cat_cocone_op\n          [\n            OF cf_ntcf_comp_cf_cat_cone[\n              OF \\<NN>.is_cat_cone_op \\<GG>.is_functor_op, unfolded cat_op_simps\n              ], \n            unfolded cat_op_simps\n          ]\n      )\nqed\n\nlemma cf_ntcf_comp_cf_cat_cocone'[cat_cs_intros]: \n  assumes \"\\<NN> : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e c : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"\\<GG> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"c' = \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>c\\<rparr>\"\n    and \"\\<GG>\\<FF> = \\<GG> \\<circ>\\<^sub>C\\<^sub>F \\<FF>\"\n  shows \"\\<GG> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<NN> : \\<GG>\\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e c' : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  using assms(1,2) unfolding assms(3,4) by (rule cf_ntcf_comp_cf_cat_cocone)\n\n\nsubsubsection\\<open>Cones, cocones and constant natural transformations\\<close>\n\nlemma ntcf_vcomp_ntcf_const_is_cat_cone:\n  assumes \"\\<NN> : b <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\" and \"f : a \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n  shows \"\\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<AA> \\<BB> f : a <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\nproof-\n  interpret \\<NN>: is_cat_cone \\<alpha> b \\<AA> \\<BB> \\<FF> \\<NN> by (rule assms(1))\n  from assms(2) show ?thesis\n    by (intro is_cat_coneI) (cs_concl cs_intro: cat_cs_intros)\nqed\n\nlemma ntcf_vcomp_ntcf_const_is_cat_cone'[cat_cs_intros]:\n  assumes \"\\<NN> : b <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"\\<MM> = ntcf_const \\<AA> \\<BB> f\"\n    and \"f : a \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n  shows \"\\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<MM> : a <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  using assms(1,3) unfolding assms(2) by (rule ntcf_vcomp_ntcf_const_is_cat_cone)\n\nlemma ntcf_vcomp_ntcf_const_is_cat_cocone:\n  assumes \"\\<NN> : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e a : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\" and \"f : a \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n  shows \"ntcf_const \\<AA> \\<BB> f \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<NN> : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e b : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\nproof-\n  interpret \\<NN>: is_cat_cocone \\<alpha> a \\<AA> \\<BB> \\<FF> \\<NN> by (rule assms(1))\n  from is_cat_cone.is_cat_cocone_op\n    [\n      OF ntcf_vcomp_ntcf_const_is_cat_cone[\n        OF \\<NN>.is_cat_cone_op, unfolded cat_op_simps, OF assms(2)\n        ],\n      unfolded cat_op_simps, \n      folded op_ntcf_ntcf_const\n    ]\n    assms(2)\n  show ?thesis\n    by (cs_prems cs_simp: cat_op_simps cs_intro: cat_cs_intros cat_op_intros)\nqed\n\nlemma ntcf_vcomp_ntcf_const_is_cat_cocone'[cat_cs_intros]:\n  assumes \"\\<NN> : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e a : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"\\<MM> = ntcf_const \\<AA> \\<BB> f\"\n    and \"f : a \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n  shows \"\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<NN> : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e b : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  using assms(1,3) \n  unfolding assms(2)\n  by (rule ntcf_vcomp_ntcf_const_is_cat_cocone)\n\nlemma ntcf_vcomp_ntcf_const_CId: \n  assumes \"\\<NN> : b <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"\\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<AA> \\<BB> (\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>) = \\<NN>\"\nproof-\n\n  interpret \\<NN>: is_cat_cone \\<alpha> b \\<AA> \\<BB> \\<FF> \\<NN> by (rule assms) \n\n  show ?thesis\n  proof(rule ntcf_eqI)\n\n    from \\<NN>.cat_cone_obj show lhs_is_ntcf: \n      \"\\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<AA> \\<BB> (\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>) :\n        cf_const \\<AA> \\<BB> b \\<mapsto>\\<^sub>C\\<^sub>F \\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n      by (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n    then have dom_lhs: \n      \"\\<D>\\<^sub>\\<circ> ((\\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<AA> \\<BB> (\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>))\\<lparr>NTMap\\<rparr>) = \\<AA>\\<lparr>Obj\\<rparr>\"\n      by (simp add: cat_cs_simps)\n\n    from \\<NN>.cat_cone_obj show \"\\<NN> : cf_const \\<AA> \\<BB> b \\<mapsto>\\<^sub>C\\<^sub>F \\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n      by (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n    then have dom_rhs: \"\\<D>\\<^sub>\\<circ> (\\<NN>\\<lparr>NTMap\\<rparr>) = \\<AA>\\<lparr>Obj\\<rparr>\"\n      by (simp add: cat_cs_simps)\n\n    show \"(\\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<AA> \\<BB> (\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>))\\<lparr>NTMap\\<rparr> = \\<NN>\\<lparr>NTMap\\<rparr>\"\n    proof(rule vsv_eqI, unfold dom_lhs dom_rhs)\n      fix a assume prems: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n      from prems \\<NN>.cat_cone_obj show \n        \"(\\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<AA> \\<BB> (\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>))\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> = \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\n        by (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n    qed (use lhs_is_ntcf in \\<open>cs_concl cs_intro: cat_cs_intros\\<close>)+\n\n  qed simp_all\n\nqed\n\nlemma ntcf_vcomp_ntcf_const_CId'[cat_cs_simps]: \n  assumes \"\\<NN> : b <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\" and \"\\<BB>' = \\<BB>\"\n  shows \"\\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<AA> \\<BB> (\\<BB>'\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>) = \\<NN>\"\n  using assms(1) unfolding assms(2) by (rule ntcf_vcomp_ntcf_const_CId)\n\n\n\nsubsection\\<open>Cone and cocone functors\\<close>\n\n\nsubsubsection\\<open>Definition and elementary properties\\<close>\n\n\ntext\\<open>See Chapter V-1 in \\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>.\\<close>\n\ndefinition cf_Cone :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V\"\n  where \"cf_Cone \\<alpha> \\<beta> \\<FF> = \n    Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<beta>\\<^esub>cat_FUNCT \\<alpha> (\\<FF>\\<lparr>HomDom\\<rparr>) (\\<FF>\\<lparr>HomCod\\<rparr>)(-,cf_map \\<FF>) \\<circ>\\<^sub>C\\<^sub>F\n    op_cf (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> (\\<FF>\\<lparr>HomDom\\<rparr>) (\\<FF>\\<lparr>HomCod\\<rparr>))\"\n\ndefinition cf_Cocone :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V\"\n  where \"cf_Cocone \\<alpha> \\<beta> \\<FF> =\n    Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<beta>\\<^esub>cat_FUNCT \\<alpha> (\\<FF>\\<lparr>HomDom\\<rparr>) (\\<FF>\\<lparr>HomCod\\<rparr>)(cf_map \\<FF>,-) \\<circ>\\<^sub>C\\<^sub>F\n    (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> (\\<FF>\\<lparr>HomDom\\<rparr>) (\\<FF>\\<lparr>HomCod\\<rparr>))\"\n\n\ntext\\<open>An alternative form of the definition.\\<close>\n\ncontext is_functor\nbegin\n\nlemma cf_Cone_def': \n  \"cf_Cone \\<alpha> \\<beta> \\<FF> = Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<beta>\\<^esub>cat_FUNCT \\<alpha> \\<AA> \\<BB>(-,cf_map \\<FF>) \\<circ>\\<^sub>C\\<^sub>F op_cf (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<AA> \\<BB>)\"\n  unfolding cf_Cone_def cat_cs_simps by simp\n\nlemma cf_Cocone_def': \n  \"cf_Cocone \\<alpha> \\<beta> \\<FF> = Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<beta>\\<^esub>cat_FUNCT \\<alpha> \\<AA> \\<BB>(cf_map \\<FF>,-) \\<circ>\\<^sub>C\\<^sub>F (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<AA> \\<BB>)\"\n  unfolding cf_Cocone_def cat_cs_simps by simp\n\nend\n\n\nsubsubsection\\<open>Object map\\<close>\n\nlemma (in is_functor) cf_Cone_ObjMap_vsv[cat_cs_intros]:\n  assumes \"\\<Z> \\<beta>\" and \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\" \n  shows \"vsv (cf_Cone \\<alpha> \\<beta> \\<FF>\\<lparr>ObjMap\\<rparr>)\"\nproof-\n  from assms interpret \\<beta>: \\<Z> \\<beta> by simp \n  from assms interpret \\<Delta>: is_functor \\<beta> \\<BB> \\<open>cat_FUNCT \\<alpha> \\<AA> \\<BB>\\<close> \\<open>\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<AA> \\<BB>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_op_intros)+\n  from assms(2) show ?thesis\n    unfolding cf_Cone_def'\n    by\n      (\n        cs_concl cs_shallow\n          cs_simp: cat_cs_simps cat_FUNCT_components(1) cat_op_simps \n          cs_intro: cat_cs_intros cat_FUNCT_cs_intros cat_op_intros\n      )\nqed\n\nlemmas [cat_cs_intros] = is_functor.cf_Cone_ObjMap_vsv\n\nlemma (in is_functor) cf_Cocone_ObjMap_vsv[cat_cs_intros]:\n  assumes \"\\<Z> \\<beta>\" and \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\" \n  shows \"vsv (cf_Cocone \\<alpha> \\<beta> \\<FF>\\<lparr>ObjMap\\<rparr>)\"\nproof-\n  from assms interpret \\<beta>: \\<Z> \\<beta> by simp \n  from assms interpret \\<Delta>: is_functor \\<beta> \\<BB> \\<open>cat_FUNCT \\<alpha> \\<AA> \\<BB>\\<close> \\<open>\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<AA> \\<BB>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_op_intros)+\n  from assms(2) show ?thesis\n    unfolding cf_Cocone_def'\n    by\n      (\n        cs_concl\n          cs_simp: cat_cs_simps cat_FUNCT_cs_simps cat_op_simps \n          cs_intro: cat_cs_intros cat_FUNCT_cs_intros cat_op_intros\n      )\nqed\n\nlemmas [cat_cs_intros] = is_functor.cf_Cocone_ObjMap_vsv\n\nlemma (in is_functor) cf_Cone_ObjMap_vdomain[cat_cs_simps]:\n  assumes \"\\<Z> \\<beta>\" and \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\" and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<D>\\<^sub>\\<circ> (cf_Cone \\<alpha> \\<beta> \\<FF>\\<lparr>ObjMap\\<rparr>) = \\<BB>\\<lparr>Obj\\<rparr>\"\nproof-\n  from assms interpret \\<beta>: \\<Z> \\<beta> by simp \n  from assms interpret \\<Delta>: is_functor \\<beta> \\<BB> \\<open>cat_FUNCT \\<alpha> \\<AA> \\<BB>\\<close> \\<open>\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<AA> \\<BB>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_op_intros)+\n  from assms show ?thesis\n    unfolding cf_Cone_def'\n    by\n      (\n        cs_concl cs_shallow\n          cs_simp: cat_cs_simps cat_FUNCT_components(1) cat_op_simps\n          cs_intro: cat_cs_intros cat_FUNCT_cs_intros cat_op_intros\n      )\nqed\n\nlemmas [cat_cs_simps] = is_functor.cf_Cone_ObjMap_vdomain\n\nlemma (in is_functor) cf_Cocone_ObjMap_vdomain[cat_cs_simps]:\n  assumes \"\\<Z> \\<beta>\" and \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\" and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<D>\\<^sub>\\<circ> (cf_Cocone \\<alpha> \\<beta> \\<FF>\\<lparr>ObjMap\\<rparr>) = \\<BB>\\<lparr>Obj\\<rparr>\"\nproof-\n  from assms interpret \\<beta>: \\<Z> \\<beta> by simp \n  from assms interpret \\<Delta>: is_functor \\<beta> \\<BB> \\<open>cat_FUNCT \\<alpha> \\<AA> \\<BB>\\<close> \\<open>\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<AA> \\<BB>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_op_intros)+\n  from assms show ?thesis\n    unfolding cf_Cocone_def'\n    by\n      (\n        cs_concl cs_shallow\n          cs_simp: cat_cs_simps cat_FUNCT_components(1) cat_op_simps\n          cs_intro: cat_cs_intros cat_FUNCT_cs_intros cat_op_intros\n      )\nqed\n\nlemmas [cat_cs_simps] = is_functor.cf_Cocone_ObjMap_vdomain\n\nlemma (in is_functor) cf_Cone_ObjMap_app[cat_cs_simps]:\n  assumes \"\\<Z> \\<beta>\" and \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\" and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"cf_Cone \\<alpha> \\<beta> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr> =\n    Hom (cat_FUNCT \\<alpha> \\<AA> \\<BB>) (cf_map (cf_const \\<AA> \\<BB> b)) (cf_map \\<FF>)\"\nproof-\n  from assms interpret \\<beta>: \\<Z> \\<beta> by simp \n  from assms interpret \\<Delta>: is_functor \\<beta> \\<BB> \\<open>cat_FUNCT \\<alpha> \\<AA> \\<BB>\\<close> \\<open>\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<AA> \\<BB>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_op_intros)+\n  from assms(2,3) show ?thesis\n    unfolding cf_Cone_def'\n    by\n      (\n        cs_concl cs_shallow\n          cs_simp: cat_cs_simps cat_FUNCT_components(1) cat_op_simps\n          cs_intro: cat_cs_intros cat_FUNCT_cs_intros cat_op_intros\n      )\nqed\n\nlemmas [cat_cs_simps] = is_functor.cf_Cone_ObjMap_app\n\nlemma (in is_functor) cf_Cocone_ObjMap_app[cat_cs_simps]:\n  assumes \"\\<Z> \\<beta>\" and \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\" and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"cf_Cocone \\<alpha> \\<beta> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr> =\n    Hom (cat_FUNCT \\<alpha> \\<AA> \\<BB>) (cf_map \\<FF>) (cf_map (cf_const \\<AA> \\<BB> b))\"\nproof-\n  from assms interpret \\<beta>: \\<Z> \\<beta> by simp \n  from assms interpret \\<Delta>: is_functor \\<beta> \\<BB> \\<open>cat_FUNCT \\<alpha> \\<AA> \\<BB>\\<close> \\<open>\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<AA> \\<BB>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_op_intros)+\n  from assms(2,3) show ?thesis\n    unfolding cf_Cocone_def'\n    by\n      (\n        cs_concl\n          cs_simp: cat_cs_simps cat_FUNCT_components(1) cat_op_simps\n          cs_intro: cat_cs_intros cat_FUNCT_cs_intros cat_op_intros\n      )\nqed\n\nlemmas [cat_cs_simps] = is_functor.cf_Cocone_ObjMap_app\n\n\nsubsubsection\\<open>Arrow map\\<close>\n\nlemma (in is_functor) cf_Cone_ArrMap_vsv[cat_cs_intros]:\n  assumes \"\\<Z> \\<beta>\" and \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\" \n  shows \"vsv (cf_Cone \\<alpha> \\<beta> \\<FF>\\<lparr>ArrMap\\<rparr>)\"\nproof-\n  from assms interpret \\<beta>: \\<Z> \\<beta> by simp \n  from assms interpret \\<Delta>: is_functor \\<beta> \\<BB> \\<open>cat_FUNCT \\<alpha> \\<AA> \\<BB>\\<close> \\<open>\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<AA> \\<BB>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_op_intros)+\n  from assms(2) show ?thesis\n    unfolding cf_Cone_def\n    by\n      (\n        cs_concl cs_shallow\n          cs_simp: cat_cs_simps cat_FUNCT_components(1) cat_op_simps \n          cs_intro: cat_cs_intros cat_FUNCT_cs_intros cat_op_intros\n      )\nqed\n\nlemmas [cat_cs_intros] = is_functor.cf_Cone_ArrMap_vsv\n\nlemma (in is_functor) cf_Cocone_ArrMap_vsv[cat_cs_intros]:\n  assumes \"\\<Z> \\<beta>\" and \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\" \n  shows \"vsv (cf_Cocone \\<alpha> \\<beta> \\<FF>\\<lparr>ArrMap\\<rparr>)\"\nproof-\n  from assms interpret \\<beta>: \\<Z> \\<beta> by simp \n  from assms interpret \\<Delta>: is_functor \\<beta> \\<BB> \\<open>cat_FUNCT \\<alpha> \\<AA> \\<BB>\\<close> \\<open>\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<AA> \\<BB>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_op_intros)+\n  from assms(2) show ?thesis\n    unfolding cf_Cocone_def'\n    by\n      (\n        cs_concl cs_shallow\n          cs_simp: cat_cs_simps cat_FUNCT_components(1) cat_op_simps \n          cs_intro: cat_cs_intros cat_FUNCT_cs_intros cat_op_intros\n      )\nqed\n\nlemmas [cat_cs_intros] = is_functor.cf_Cocone_ArrMap_vsv\n\nlemma (in is_functor) cf_Cone_ArrMap_vdomain[cat_cs_simps]:\n  assumes \"\\<Z> \\<beta>\" and \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\" and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<D>\\<^sub>\\<circ> (cf_Cone \\<alpha> \\<beta> \\<FF>\\<lparr>ArrMap\\<rparr>) = \\<BB>\\<lparr>Arr\\<rparr>\"\nproof-\n  from assms interpret \\<beta>: \\<Z> \\<beta> by simp \n  from assms interpret \\<Delta>: is_functor \\<beta> \\<BB> \\<open>cat_FUNCT \\<alpha> \\<AA> \\<BB>\\<close> \\<open>\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<AA> \\<BB>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_op_intros)+\n  from assms(2) show ?thesis\n    unfolding cf_Cone_def'\n    by\n      (\n        cs_concl cs_shallow\n          cs_simp: cat_cs_simps cat_FUNCT_components(1) cat_op_simps\n          cs_intro: cat_cs_intros cat_FUNCT_cs_intros cat_op_intros\n      )\nqed\n\nlemmas [cat_cs_simps] = is_functor.cf_Cone_ArrMap_vdomain\n\nlemma (in is_functor) cf_Cocone_ArrMap_vdomain[cat_cs_simps]:\n  assumes \"\\<Z> \\<beta>\" and \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\" and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<D>\\<^sub>\\<circ> (cf_Cocone \\<alpha> \\<beta> \\<FF>\\<lparr>ArrMap\\<rparr>) = \\<BB>\\<lparr>Arr\\<rparr>\"\nproof-\n  from assms interpret \\<beta>: \\<Z> \\<beta> by simp \n  from assms interpret \\<Delta>: is_functor \\<beta> \\<BB> \\<open>cat_FUNCT \\<alpha> \\<AA> \\<BB>\\<close> \\<open>\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<AA> \\<BB>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_op_intros)+\n  from assms(2) show ?thesis\n    unfolding cf_Cocone_def'\n    by\n      (\n        cs_concl cs_shallow\n          cs_simp: cat_cs_simps cat_FUNCT_components(1) cat_op_simps\n          cs_intro: cat_cs_intros cat_FUNCT_cs_intros cat_op_intros\n      )\nqed\n\nlemmas [cat_cs_simps] = is_functor.cf_Cocone_ArrMap_vdomain\n\nlemma (in is_functor) cf_Cone_ArrMap_app[cat_cs_simps]:\n  assumes \"\\<Z> \\<beta>\"\n    and \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\" \n    and \"f : a \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n  shows \"cf_Cone \\<alpha> \\<beta> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> = cf_hom\n    (cat_FUNCT \\<alpha> \\<AA> \\<BB>)\n    [ntcf_arrow (ntcf_const \\<AA> \\<BB> f), cat_FUNCT \\<alpha> \\<AA> \\<BB>\\<lparr>CId\\<rparr>\\<lparr>cf_map \\<FF>\\<rparr>]\\<^sub>\\<circ>\"\nproof-\n  from assms interpret \\<beta>: \\<Z> \\<beta> by simp \n  from assms interpret \\<Delta>: is_functor \\<beta> \\<BB> \\<open>cat_FUNCT \\<alpha> \\<AA> \\<BB>\\<close> \\<open>\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<AA> \\<BB>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_op_intros)+\n  from assms(2,3) show ?thesis\n    unfolding cf_Cone_def\n    by\n      (\n        cs_concl \n          cs_simp: cat_cs_simps cat_FUNCT_components(1) cat_op_simps \n          cs_intro: cat_cs_intros cat_FUNCT_cs_intros cat_op_intros\n      )\nqed\n\nlemmas [cat_cs_simps] = is_functor.cf_Cone_ArrMap_app\n\nlemma (in is_functor) cf_Cocone_ArrMap_app[cat_cs_simps]:\n  assumes \"\\<Z> \\<beta>\"\n    and \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\" \n    and \"f : a \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n  shows \"cf_Cocone \\<alpha> \\<beta> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> = cf_hom\n    (cat_FUNCT \\<alpha> \\<AA> \\<BB>)\n    [cat_FUNCT \\<alpha> \\<AA> \\<BB>\\<lparr>CId\\<rparr>\\<lparr>cf_map \\<FF>\\<rparr>, ntcf_arrow (ntcf_const \\<AA> \\<BB> f)]\\<^sub>\\<circ>\"\nproof-\n  from assms interpret \\<beta>: \\<Z> \\<beta> by simp \n  from assms interpret \\<Delta>: is_functor \\<beta> \\<BB> \\<open>cat_FUNCT \\<alpha> \\<AA> \\<BB>\\<close> \\<open>\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<AA> \\<BB>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_op_intros)+\n  from assms(2,3) show ?thesis\n    unfolding cf_Cocone_def'\n    by\n      (\n        cs_concl \n          cs_simp: cat_cs_simps cat_FUNCT_components(1) cat_op_simps \n          cs_intro: cat_cs_intros cat_FUNCT_cs_intros cat_op_intros\n      )\nqed\n\nlemmas [cat_cs_simps] = is_functor.cf_Cocone_ArrMap_app\n\n\nsubsubsection\\<open>The cone functor is a functor\\<close>\n\nlemma (in is_functor) tm_cf_cf_Cone_is_functor_if_ge_Limit:\n  assumes \"\\<Z> \\<beta>\" and \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\"\n  shows \"cf_Cone \\<alpha> \\<beta> \\<FF> : op_cat \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<beta>\\<^esub> cat_Set \\<beta>\"\nproof-\n  from assms interpret FUNCT: category \\<beta> \\<open>cat_FUNCT \\<alpha> \\<AA> \\<BB>\\<close>\n    by\n      (\n        cs_concl cs_intro:\n          cat_small_cs_intros cat_cs_intros cat_FUNCT_cs_intros\n      )\n  from assms interpret op_\\<Delta>: \n    is_functor \\<beta> \\<open>op_cat \\<BB>\\<close> \\<open>op_cat (cat_FUNCT \\<alpha> \\<AA> \\<BB>)\\<close> \\<open>op_cf (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<AA> \\<BB>)\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_op_intros)+\n  have \"Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<beta>\\<^esub>cat_FUNCT \\<alpha> \\<AA> \\<BB>(-,cf_map \\<FF>) :\n    op_cat (cat_FUNCT \\<alpha> \\<AA> \\<BB>) \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<beta>\\<^esub> cat_Set \\<beta>\"\n    by\n      (\n        cs_concl cs_shallow\n          cs_simp: cat_FUNCT_cs_simps \n          cs_intro: cat_cs_intros cat_FUNCT_cs_intros\n      )\n  then show \"cf_Cone \\<alpha> \\<beta> \\<FF> : op_cat \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<beta>\\<^esub> cat_Set \\<beta>\"\n    unfolding cf_Cone_def' by (cs_concl cs_intro: cat_cs_intros)\nqed\n\nlemma (in is_functor) tm_cf_cf_Cocone_is_functor_if_ge_Limit:\n  assumes \"\\<Z> \\<beta>\" and \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\"\n  shows \"cf_Cocone \\<alpha> \\<beta> \\<FF> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<beta>\\<^esub> cat_Set \\<beta>\"\nproof-\n  from assms interpret Funct: category \\<beta> \\<open>cat_FUNCT \\<alpha> \\<AA> \\<BB>\\<close>\n    by\n      (\n        cs_concl cs_intro:\n          cat_small_cs_intros cat_cs_intros cat_FUNCT_cs_intros\n      )\n  from assms interpret op_\\<Delta>: is_functor \\<beta> \\<BB> \\<open>cat_FUNCT \\<alpha> \\<AA> \\<BB>\\<close> \\<open>\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<AA> \\<BB>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_op_intros)+\n  have \"Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<beta>\\<^esub>cat_FUNCT \\<alpha> \\<AA> \\<BB>(cf_map \\<FF>,-) :\n    cat_FUNCT \\<alpha> \\<AA> \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<beta>\\<^esub> cat_Set \\<beta>\"\n    by\n      (\n        cs_concl cs_shallow\n          cs_simp: cat_FUNCT_cs_simps \n          cs_intro: cat_cs_intros cat_FUNCT_cs_intros\n      )\n  then show \"cf_Cocone \\<alpha> \\<beta>  \\<FF> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<beta>\\<^esub> cat_Set \\<beta>\"\n    unfolding cf_Cocone_def' by (cs_concl cs_intro: cat_cs_intros)\nqed\n\ntext\\<open>\\newpage\\<close>\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/CZH_Elementary_Categories/czh_ecategories/CZH_ECAT_Cone.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5428632979641571, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.29680407630919603}}
{"text": "(*\nCopyright 2018\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*)\ntheory Abstract_System\n  imports SE_Monad\nbegin\n\nlocale det_system =\n  fixes step :: \"(unit,'s) se\"\n  fixes halted :: \"'s \\<Rightarrow> bool\"\nbegin\n\n  definition \"step_rel s s' \\<equiv>\n    case s of\n      None \\<Rightarrow> False\n    | Some s \\<Rightarrow> \\<not>halted s \\<and> map_option snd (step s) = s'\"\n\n  fun terminated where\n    \"terminated (Some s) = halted s\"\n  | \"terminated None = True \"\n\n  lemma terminated_no_step[simp, intro]: \"terminated s \\<Longrightarrow> \\<not>step_rel s s'\"\n    by (auto simp: step_rel_def split: option.splits)\n\n  lemma terminated_no_step': \"terminated s \\<longleftrightarrow> (\\<forall>s'. \\<not>step_rel s s')\"\n    by (cases s; auto simp: step_rel_def split: option.splits)\n\n  definition \"is_result s s' \\<equiv> step_rel\\<^sup>*\\<^sup>* (Some s) s' \\<and> terminated s'\"\n\n  lemma is_result_1_step_eq: \"\\<not>halted s \\<Longrightarrow> step s = Some ((),sh) \\<Longrightarrow> is_result s s' \\<longleftrightarrow> is_result sh s'\"\n    apply (rule iffI)\n    subgoal\n      unfolding is_result_def step_rel_def\n      by (auto split: option.splits elim: converse_rtranclpE)\n    subgoal\n      unfolding is_result_def\n      apply simp\n      apply (rule converse_rtranclp_into_rtranclp)\n      apply (auto simp: step_rel_def) []\n      by simp\n    done\n\n  lemma result_determ: \"is_result s s' \\<Longrightarrow> is_result s s'' \\<Longrightarrow> s'=s''\"\n    unfolding is_result_def\n    apply safe\n    apply (induction rule: converse_rtranclp_induct)\n    apply (erule converse_rtranclpE; auto; fail)\n\n    apply (erule converse_rtranclpE[of _ _ s'']; clarsimp)\n    apply (auto simp: step_rel_def split: option.splits; fail)\n    done\n\n  definition \"yields' s \\<equiv> if \\<exists>s'. is_result s s' then Some (THE s'. is_result s s') else None\"\n\n  lemma yields_eq_Some_conv: \"yields' s = Some s' \\<longleftrightarrow> is_result s s'\"\n    unfolding yields'_def using result_determ\n    by (auto simp: theI2)\n\n  lemma yields_eq_None_conv: \"yields' s = None \\<longleftrightarrow> (\\<nexists>s'. is_result s s')\"\n    unfolding yields'_def by auto\n\n  lemma halted_res[simp]: \"halted s \\<Longrightarrow> is_result s (Some s)\"\n    by (auto simp: is_result_def)\n\n  lemma exec1_None_res[simp]: \"\\<lbrakk>step s = None; \\<not> halted s\\<rbrakk> \\<Longrightarrow> is_result s None\"\n    by (auto simp: is_result_def step_rel_def r_into_rtranclp)\n\n  lemma yields_unfold: \"yields' s = (\n    if halted s then\n      Some (Some s)\n    else\n      case step s of\n        Some (_,s') \\<Rightarrow> yields' s'\n      | None \\<Rightarrow> Some None\n    )\"\n    apply (clarsimp split: option.splits simp: yields_eq_Some_conv yields_eq_None_conv)\n    subgoal for s'\n      apply (cases \"yields' s\"; cases \"yields' s'\"; simp only:)\n      apply (auto\n        split: option.splits\n        simp: yields_eq_Some_conv yields_eq_None_conv is_result_1_step_eq result_determ\n        )+\n      done\n    done\n\n  lemma yields'_simps[simp]:\n    \"halted s \\<Longrightarrow> yields' s = Some (Some s)\"\n    \"\\<not>halted s \\<Longrightarrow> step s = Some ((),s') \\<Longrightarrow> yields' s = yields' s'\"\n    \"\\<not>halted s \\<Longrightarrow> step s = None \\<Longrightarrow> yields' s = Some None\"\n    by (subst yields_unfold; auto split: option.splits)+\n\n\n  definition \"is_invar \\<phi> \\<equiv> \\<forall>s. \\<phi> s \\<and> \\<not>halted s \\<longrightarrow> wps step (\\<lambda>_. \\<phi>) s\"\n  definition \"is_weak_invar \\<phi> \\<equiv> \\<forall>s s'. \\<phi> s \\<and> \\<not>halted s \\<and> step s = Some ((),s') \\<longrightarrow> \\<phi> s'\"\n\n  lemma is_invar_step: \"is_invar \\<phi> \\<Longrightarrow> \\<phi> s \\<Longrightarrow> step_rel (Some s) so' \\<Longrightarrow> \\<exists>s'. so'=Some s' \\<and> \\<phi> s'\"\n    by (auto simp: is_invar_def wps_def step_rel_def split: option.splits)\n\n  lemma is_weak_invar_step: \"is_weak_invar \\<phi> \\<Longrightarrow> \\<phi> s \\<Longrightarrow> step_rel (Some s) (Some s') \\<Longrightarrow> \\<phi> s'\"\n    by (auto simp: is_weak_invar_def wps_def step_rel_def split: option.splits)\n\n  lemma is_invar_exec:\n    assumes \"is_invar \\<phi>\"\n    assumes \"\\<phi> s\"\n    assumes \"step_rel\\<^sup>*\\<^sup>* (Some s) so'\"\n    shows \"\\<exists>s'. so'=Some s' \\<and> \\<phi> s'\"\n    using assms(3,2)\n    apply (induction a\\<equiv>\"Some s\" arbitrary: s rule: converse_rtranclp_induct)\n    subgoal by simp\n    apply (drule (1) is_invar_step[OF \\<open>is_invar \\<phi>\\<close>])\n    by auto\n\n  lemma step_rel_rtrancl_None_eq[simp]: \"step_rel\\<^sup>*\\<^sup>* None s \\<longleftrightarrow> s=None\"\n    using converse_rtranclpE by fastforce\n\n  lemma is_weak_invar_exec:\n    assumes \"is_weak_invar \\<phi>\"\n    assumes \"\\<phi> s\"\n    assumes \"step_rel\\<^sup>*\\<^sup>* (Some s) (Some s')\"\n    shows \"\\<phi> s'\"\n    using assms(3,2)\n    apply (induction a\\<equiv>\"Some s\" arbitrary: s rule: converse_rtranclp_induct)\n    subgoal by simp\n    subgoal for z s\n      apply (cases z; simp)\n      apply (drule (1) is_weak_invar_step[OF \\<open>is_weak_invar \\<phi>\\<close>])\n      by auto\n    done\n\n  lemma is_invar_yields:\n    assumes \"is_invar \\<phi>\"\n    assumes \"\\<phi> s\"\n    assumes \"yields' s = Some so'\"\n    shows \"\\<exists>s'. so'=Some s' \\<and> halted s' \\<and> \\<phi> s'\"\n    using assms\n    apply (auto simp: yields_eq_Some_conv is_result_def is_invar_exec)\n    using is_invar_exec terminated.simps(1) by blast\n\n  lemma is_weak_invar_yields:\n    assumes \"is_weak_invar \\<phi>\"\n    assumes \"\\<phi> s\"\n    assumes \"yields' s = Some (Some s')\"\n    shows \"\\<phi> s'\"\n    using assms\n    by (auto simp: yields_eq_Some_conv is_result_def is_weak_invar_exec)\n\n\n\n\n  lemma is_invarI:\n    assumes \"\\<And>s. \\<lbrakk> \\<phi> s; \\<not>halted s \\<rbrakk> \\<Longrightarrow> wps step (\\<lambda>_. \\<phi>) s\"\n    shows \"is_invar \\<phi>\"\n    using assms\n    unfolding is_invar_def by blast\n\n  lemma is_weak_invarI:\n    assumes \"\\<And>s s'. \\<lbrakk> \\<phi> s; \\<not>halted s; step s = Some ((),s') \\<rbrakk> \\<Longrightarrow> \\<phi> s'\"\n    shows \"is_weak_invar \\<phi>\"\n    using assms\n    unfolding is_weak_invar_def by blast\n\n  lemma app_weak_invar:\n    assumes \"is_weak_invar \\<phi>'\"\n    assumes \"\\<not>halted s\" \"\\<phi>' s\"\n    assumes \"wps step (\\<lambda>_ s'. \\<phi>' s' \\<longrightarrow> \\<phi> s') s\"\n    shows \"wps step (\\<lambda>_. \\<phi>) s\"\n    using assms unfolding is_weak_invar_def wps_def\n    by (auto split: option.splits)\n\n  lemma is_weak_invarD:\n    assumes \"is_weak_invar \\<phi>\"\n    assumes \"\\<phi> s\" \"\\<not>halted s\"\n    assumes \"step s = Some ((),s')\"\n    shows \"\\<phi> s'\"\n    using assms\n    by (auto simp: is_weak_invar_def)\n\n\nend\n\nlocale std_invar_system = det_system step halted for step :: \"(unit,'s) se\" and halted +\n  fixes stdI :: \"'s \\<Rightarrow> bool\"\n  assumes stdI: \"is_weak_invar stdI\"\nbegin\n  definition \"is_std_invar \\<phi> \\<equiv> is_invar (\\<lambda>s. stdI s \\<and> \\<phi> s)\"\n\n  lemma is_std_invarI:\n    assumes \"\\<And>s. \\<lbrakk> \\<phi> s; stdI s; \\<not>halted s \\<rbrakk> \\<Longrightarrow> wps step (\\<lambda>_ s'. stdI s' \\<longrightarrow> \\<phi> s') s\"\n    shows \"is_std_invar \\<phi>\"\n    unfolding is_std_invar_def\n    apply (rule is_invarI)\n    apply (rule app_weak_invar[OF stdI]; simp)\n    using assms by blast\n\n  definition \"htriple P Q \\<equiv> \\<forall>s. stdI s \\<and> P s \\<longrightarrow> (case yields' s of\n      None \\<Rightarrow> True\n    | Some None \\<Rightarrow> False\n    | Some (Some s') \\<Rightarrow> Q s'\n  )\"\n\n  lemma htripleI:\n    assumes \"\\<And>s so'. \\<lbrakk> stdI s; P s; yields' s = Some so' \\<rbrakk> \\<Longrightarrow> \\<exists>s'. so' = Some s' \\<and> (stdI s' \\<longrightarrow> Q s')\"\n    shows \"local.htriple P Q\"\n    using assms unfolding htriple_def\n    using local.is_weak_invar_yields local.stdI\n    by (fastforce split: option.split)\n\nend\n\n\nlocale floyd_system = std_invar_system step halted stdI for step :: \"(unit,'s) se\" and halted stdI +\n  fixes \\<Theta> :: \"'s \\<rightharpoonup> bool\"\nbegin\n  definition \"has_invar s \\<equiv> halted s \\<or> \\<Theta> s \\<noteq> None\"\n\n  lemma has_invar_simps[simp]:\n    \"\\<Theta> s = Some x \\<Longrightarrow> has_invar s\"\n    \"\\<Theta> s = None \\<Longrightarrow> has_invar s = halted s\"\n    by (auto simp: has_invar_def)\n\n  sublocale isys: det_system step has_invar .\n\n\n  definition \"invar s \\<equiv>\n    case isys.yields' s of\n      None \\<Rightarrow> False\n    | Some so' \\<Rightarrow> (case so' of None \\<Rightarrow> False | Some s' \\<Rightarrow> \\<Theta> s' = Some True)\n    \"\n\n  lemma invar_unfold:\n    \"invar s = (case \\<Theta> s of Some b \\<Rightarrow> b | None \\<Rightarrow> (\\<not>halted s \\<and> wps (step) (\\<lambda>_. invar) s))\"\n    unfolding invar_def wps_def\n    apply (subst isys.yields_unfold)\n    by (auto split: option.splits)\n\n\n  \n\n\n  lemma invar_imp_\\<Theta>_true: \"invar s \\<Longrightarrow> has_invar s \\<Longrightarrow> \\<Theta> s = Some True\"\n    unfolding invar_def by (auto split: option.splits)\n\n  lemma invarI:\n    assumes \"\\<And>s. \\<lbrakk> \\<Theta> s = Some True; stdI s; \\<not>halted s \\<rbrakk> \\<Longrightarrow> wps step (\\<lambda>_ s'. stdI s' \\<longrightarrow> invar s') s\"\n    shows \"is_std_invar invar\"\n  proof (rule is_std_invarI)\n    fix s\n    assume \"invar s\" \"\\<not>halted s\" \"stdI s\"\n\n    from \\<open>invar s\\<close> consider (HAS_INVAR) \"\\<Theta> s = Some True\" | (NO_INVAR) \"\\<Theta> s = None\"\n      using has_invar_def invar_imp_\\<Theta>_true by blast\n    then show \"wps step (\\<lambda>_ s'. stdI s' \\<longrightarrow> invar s') s\" proof cases\n      case HAS_INVAR\n      then show ?thesis\n        using \\<open>\\<not> halted s\\<close> \\<open>stdI s\\<close> assms by blast\n    next\n      case NO_INVAR\n      hence \"\\<not>has_invar s\" using \\<open>\\<not> halted s\\<close> by (auto simp: has_invar_def)\n      then show ?thesis\n        using \\<open>invar s\\<close> invar_step wps_mono by fastforce\n    qed\n  qed\n\n\n  lemma halted_invar_conv:\n    assumes [simp]: \"halted s\"\n    shows \"invar s \\<longleftrightarrow> \\<Theta> s = Some True\"\n    by (subst invar_unfold) (auto split: option.split)\n\n  lemma std_invar_yields:\n    assumes \"is_std_invar invar\"\n    assumes \"stdI s\" \"invar s\" \"yields' s = Some so'\"\n    shows \"\\<exists>s'. so' = Some s' \\<and> halted s' \\<and> stdI s' \\<and> \\<Theta> s' = Some True\"\n  proof -\n    from assms(1) have \"is_invar (\\<lambda>s. stdI s \\<and> invar s)\" by (simp add: is_std_invar_def)\n    note X1 = is_invar_yields[OF this]\n\n    from assms(2-) X1 obtain s' where X2: \"so' = Some s'\" \"halted s'\" \"stdI s'\" \"invar s'\"\n      by auto\n    with halted_invar_conv have \"\\<Theta> s' = Some True\" by blast\n    with X2 show ?thesis by blast\n  qed\n\nend\n\n\n\nlocale cfg_system = std_invar_system step halted stdI for step :: \"(unit,'s) se\" and halted stdI +\n  fixes location :: \"'s \\<Rightarrow> 'loc\"\nbegin\n  definition linvar :: \"('loc \\<Rightarrow> ('s \\<Rightarrow> bool) option) \\<Rightarrow> 's \\<Rightarrow> bool option\" where\n    \"linvar \\<Theta> s \\<equiv>\n        case \\<Theta> (location s) of\n          None \\<Rightarrow> None\n        | Some \\<phi> \\<Rightarrow> Some (\\<phi> s)\"\n\n  sublocale floyd: floyd_system step halted stdI \"linvar \\<Theta>\" for \\<Theta> by standard\n\n  definition \"floyd_vcs \\<Theta>' \\<Theta> \\<equiv>\n    \\<forall>\\<phi> s. \\<Theta>' (location s) = Some \\<phi> \\<and> \\<phi> s \\<and> stdI s \\<and> \\<not>halted s \\<longrightarrow> wps step (\\<lambda>_ s'. stdI s' \\<longrightarrow> floyd.invar \\<Theta> s') s\"\n\n  lemma floyd_vcs_emptyI:\n    \"floyd_vcs Map.empty \\<Theta>\"\n    by (auto simp: floyd_vcs_def)\n\n  lemma floyd_vcs_updI:\n    assumes \"floyd_vcs \\<Theta>' \\<Theta>\"\n    assumes \"\\<And>s. \\<lbrakk> location s = l; \\<phi> s; stdI s; \\<not>halted s \\<rbrakk> \\<Longrightarrow> wps step (\\<lambda>_ s'. stdI s' \\<longrightarrow> floyd.invar \\<Theta> s') s\"\n    shows \"floyd_vcs (\\<Theta>'(l\\<mapsto>\\<phi>)) \\<Theta>\"\n    using assms\n    by (auto simp: floyd_vcs_def)\n\n  lemmas floyd_vcsI = floyd_vcs_emptyI floyd_vcs_updI\n\n  lemma linvar_conv:\n    \"linvar \\<Theta> s = None \\<longleftrightarrow> \\<Theta> (location s) = None\"\n    \"linvar \\<Theta> s = Some b \\<longleftrightarrow> (\\<exists>\\<phi>. \\<Theta> (location s) = Some \\<phi> \\<and> b=\\<phi> s)\"\n    by (auto simp: linvar_def split: option.splits)\n\n  lemma floyd_invarI: \"floyd_vcs \\<Theta> \\<Theta> \\<Longrightarrow> is_std_invar (floyd.invar \\<Theta>)\"\n    apply (rule floyd.invarI)\n    unfolding floyd_vcs_def\n    by (auto simp: linvar_conv)\n\n  lemma linvar_unfoldI:\n    assumes \"case \\<Theta> (location s) of\n        None \\<Rightarrow> \\<not>halted s \\<and> wps step (\\<lambda>_. floyd.invar \\<Theta>) s\n      | Some \\<phi> \\<Rightarrow> \\<phi> s\"\n    shows \"floyd.invar \\<Theta> s\"\n    apply (subst floyd.invar_unfold)\n    using assms\n    by (auto simp: linvar_conv split: option.split)\n\n\n  lemma floyd_htripleI:\n    assumes \"\\<And>s. P s \\<Longrightarrow> floyd.invar \\<Theta> s\" \\<comment> \\<open>Precondition implies invariant\\<close>\n    assumes \"is_std_invar (floyd.invar \\<Theta>)\" \\<comment> \\<open>Invariant\\<close>\n    assumes \"\\<And>s \\<phi>. \\<lbrakk> halted s; stdI s; \\<Theta> (location s) = Some \\<phi>; \\<phi> s \\<rbrakk> \\<Longrightarrow> Q s\" \\<comment> \\<open>On termination, invariant implies postcondition\\<close>\n    shows \"local.htriple P Q\"\n    apply (rule htripleI)\n    subgoal for s so'\n      using floyd.std_invar_yields[OF assms(2), of s so']\n      apply (clarsimp simp: linvar_conv)\n      using assms(1,3) by blast\n    done\n\n\nend\n\nend\n", "meta": {"author": "ssrg-vt", "repo": "Luce-src", "sha": "f7f1ef0fd07bba48bcb3d5e32404db6013a5f1bc", "save_path": "github-repos/isabelle/ssrg-vt-Luce-src", "path": "github-repos/isabelle/ssrg-vt-Luce-src/Luce-src-f7f1ef0fd07bba48bcb3d5e32404db6013a5f1bc/safecomp2019_artifact/old_work/isabelle/Monads/Abstract_System.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.2968040682220356}}
{"text": "(*  Title:      HOL/Record.thy\n    Author:     Wolfgang Naraschewski, TU Muenchen\n    Author:     Markus Wenzel, TU Muenchen\n    Author:     Norbert Schirmer, TU Muenchen\n    Author:     Thomas Sewell, NICTA\n    Author:     Florian Haftmann, TU Muenchen\n*)\n\nsection \\<open>Extensible records with structural subtyping\\<close>\n\ntheory Record\nimports Quickcheck_Exhaustive\nkeywords\n  \"record\" :: thy_defn and\n  \"print_record\" :: diag\nbegin\n\nsubsection \\<open>Introduction\\<close>\n\ntext \\<open>\n  Records are isomorphic to compound tuple types. To implement\n  efficient records, we make this isomorphism explicit. Consider the\n  record access/update simplification \\<open>alpha (beta_update f\n  rec) = alpha rec\\<close> for distinct fields alpha and beta of some record\n  rec with n fields. There are \\<open>n ^ 2\\<close> such theorems, which\n  prohibits storage of all of them for large n. The rules can be\n  proved on the fly by case decomposition and simplification in O(n)\n  time. By creating O(n) isomorphic-tuple types while defining the\n  record, however, we can prove the access/update simplification in\n  \\<open>O(log(n)^2)\\<close> time.\n\n  The O(n) cost of case decomposition is not because O(n) steps are\n  taken, but rather because the resulting rule must contain O(n) new\n  variables and an O(n) size concrete record construction. To sidestep\n  this cost, we would like to avoid case decomposition in proving\n  access/update theorems.\n\n  Record types are defined as isomorphic to tuple types. For instance,\n  a record type with fields \\<open>'a\\<close>, \\<open>'b\\<close>, \\<open>'c\\<close>\n  and \\<open>'d\\<close> might be introduced as isomorphic to \\<open>'a \\<times>\n  ('b \\<times> ('c \\<times> 'd))\\<close>. If we balance the tuple tree to \\<open>('a \\<times>\n  'b) \\<times> ('c \\<times> 'd)\\<close> then accessors can be defined by converting to the\n  underlying type then using O(log(n)) fst or snd operations.\n  Updators can be defined similarly, if we introduce a \\<open>fst_update\\<close> and \\<open>snd_update\\<close> function. Furthermore, we can\n  prove the access/update theorem in O(log(n)) steps by using simple\n  rewrites on fst, snd, \\<open>fst_update\\<close> and \\<open>snd_update\\<close>.\n\n  The catch is that, although O(log(n)) steps were taken, the\n  underlying type we converted to is a tuple tree of size\n  O(n). Processing this term type wastes performance. We avoid this\n  for large n by taking each subtree of size K and defining a new type\n  isomorphic to that tuple subtree. A record can now be defined as\n  isomorphic to a tuple tree of these O(n/K) new types, or, if \\<open>n > K*K\\<close>, we can repeat the process, until the record can be\n  defined in terms of a tuple tree of complexity less than the\n  constant K.\n\n  If we prove the access/update theorem on this type with the\n  analogous steps to the tuple tree, we consume \\<open>O(log(n)^2)\\<close>\n  time as the intermediate terms are \\<open>O(log(n))\\<close> in size and\n  the types needed have size bounded by K.  To enable this analogous\n  traversal, we define the functions seen below: \\<open>iso_tuple_fst\\<close>, \\<open>iso_tuple_snd\\<close>, \\<open>iso_tuple_fst_update\\<close>\n  and \\<open>iso_tuple_snd_update\\<close>. These functions generalise tuple\n  operations by taking a parameter that encapsulates a tuple\n  isomorphism.  The rewrites needed on these functions now need an\n  additional assumption which is that the isomorphism works.\n\n  These rewrites are typically used in a structured way. They are here\n  presented as the introduction rule \\<open>isomorphic_tuple.intros\\<close>\n  rather than as a rewrite rule set. The introduction form is an\n  optimisation, as net matching can be performed at one term location\n  for each step rather than the simplifier searching the term for\n  possible pattern matches. The rule set is used as it is viewed\n  outside the locale, with the locale assumption (that the isomorphism\n  is valid) left as a rule assumption. All rules are structured to aid\n  net matching, using either a point-free form or an encapsulating\n  predicate.\n\\<close>\n\nsubsection \\<open>Operators and lemmas for types isomorphic to tuples\\<close>\n\ndatatype (dead 'a, dead 'b, dead 'c) tuple_isomorphism =\n  Tuple_Isomorphism \"'a \\<Rightarrow> 'b \\<times> 'c\" \"'b \\<times> 'c \\<Rightarrow> 'a\"\n\nprimrec\n  repr :: \"('a, 'b, 'c) tuple_isomorphism \\<Rightarrow> 'a \\<Rightarrow> 'b \\<times> 'c\" where\n  \"repr (Tuple_Isomorphism r a) = r\"\n\nprimrec\n  abst :: \"('a, 'b, 'c) tuple_isomorphism \\<Rightarrow> 'b \\<times> 'c \\<Rightarrow> 'a\" where\n  \"abst (Tuple_Isomorphism r a) = a\"\n\ndefinition\n  iso_tuple_fst :: \"('a, 'b, 'c) tuple_isomorphism \\<Rightarrow> 'a \\<Rightarrow> 'b\" where\n  \"iso_tuple_fst isom = fst \\<circ> repr isom\"\n\ndefinition\n  iso_tuple_snd :: \"('a, 'b, 'c) tuple_isomorphism \\<Rightarrow> 'a \\<Rightarrow> 'c\" where\n  \"iso_tuple_snd isom = snd \\<circ> repr isom\"\n\ndefinition\n  iso_tuple_fst_update ::\n    \"('a, 'b, 'c) tuple_isomorphism \\<Rightarrow> ('b \\<Rightarrow> 'b) \\<Rightarrow> ('a \\<Rightarrow> 'a)\" where\n  \"iso_tuple_fst_update isom f = abst isom \\<circ> apfst f \\<circ> repr isom\"\n\ndefinition\n  iso_tuple_snd_update ::\n    \"('a, 'b, 'c) tuple_isomorphism \\<Rightarrow> ('c \\<Rightarrow> 'c) \\<Rightarrow> ('a \\<Rightarrow> 'a)\" where\n  \"iso_tuple_snd_update isom f = abst isom \\<circ> apsnd f \\<circ> repr isom\"\n\ndefinition\n  iso_tuple_cons ::\n    \"('a, 'b, 'c) tuple_isomorphism \\<Rightarrow> 'b \\<Rightarrow> 'c \\<Rightarrow> 'a\" where\n  \"iso_tuple_cons isom = curry (abst isom)\"\n\n\nsubsection \\<open>Logical infrastructure for records\\<close>\n\ndefinition\n  iso_tuple_surjective_proof_assist :: \"'a \\<Rightarrow> 'b \\<Rightarrow> ('a \\<Rightarrow> 'b) \\<Rightarrow> bool\" where\n  \"iso_tuple_surjective_proof_assist x y f \\<longleftrightarrow> f x = y\"\n\ndefinition\n  iso_tuple_update_accessor_cong_assist ::\n    \"(('b \\<Rightarrow> 'b) \\<Rightarrow> ('a \\<Rightarrow> 'a)) \\<Rightarrow> ('a \\<Rightarrow> 'b) \\<Rightarrow> bool\" where\n  \"iso_tuple_update_accessor_cong_assist upd ac \\<longleftrightarrow>\n     (\\<forall>f v. upd (\\<lambda>x. f (ac v)) v = upd f v) \\<and> (\\<forall>v. upd id v = v)\"\n\ndefinition\n  iso_tuple_update_accessor_eq_assist ::\n    \"(('b \\<Rightarrow> 'b) \\<Rightarrow> ('a \\<Rightarrow> 'a)) \\<Rightarrow> ('a \\<Rightarrow> 'b) \\<Rightarrow> 'a \\<Rightarrow> ('b \\<Rightarrow> 'b) \\<Rightarrow> 'a \\<Rightarrow> 'b \\<Rightarrow> bool\" where\n  \"iso_tuple_update_accessor_eq_assist upd ac v f v' x \\<longleftrightarrow>\n     upd f v = v' \\<and> ac v = x \\<and> iso_tuple_update_accessor_cong_assist upd ac\"\n\nlemma update_accessor_congruence_foldE:\n  assumes uac: \"iso_tuple_update_accessor_cong_assist upd ac\"\n    and r: \"r = r'\" and v: \"ac r' = v'\"\n    and f: \"\\<And>v. v' = v \\<Longrightarrow> f v = f' v\"\n  shows \"upd f r = upd f' r'\"\n  using uac r v [symmetric]\n  apply (subgoal_tac \"upd (\\<lambda>x. f (ac r')) r' = upd (\\<lambda>x. f' (ac r')) r'\")\n   apply (simp add: iso_tuple_update_accessor_cong_assist_def)\n  apply (simp add: f)\n  done\n\nlemma update_accessor_congruence_unfoldE:\n  \"iso_tuple_update_accessor_cong_assist upd ac \\<Longrightarrow>\n    r = r' \\<Longrightarrow> ac r' = v' \\<Longrightarrow> (\\<And>v. v = v' \\<Longrightarrow> f v = f' v) \\<Longrightarrow>\n    upd f r = upd f' r'\"\n  apply (erule(2) update_accessor_congruence_foldE)\n  apply simp\n  done\n\nlemma iso_tuple_update_accessor_cong_assist_id:\n  \"iso_tuple_update_accessor_cong_assist upd ac \\<Longrightarrow> upd id = id\"\n  by rule (simp add: iso_tuple_update_accessor_cong_assist_def)\n\nlemma update_accessor_noopE:\n  assumes uac: \"iso_tuple_update_accessor_cong_assist upd ac\"\n    and ac: \"f (ac x) = ac x\"\n  shows \"upd f x = x\"\n  using uac\n  by (simp add: ac iso_tuple_update_accessor_cong_assist_id [OF uac, unfolded id_def]\n    cong: update_accessor_congruence_unfoldE [OF uac])\n\nlemma update_accessor_noop_compE:\n  assumes uac: \"iso_tuple_update_accessor_cong_assist upd ac\"\n    and ac: \"f (ac x) = ac x\"\n  shows \"upd (g \\<circ> f) x = upd g x\"\n  by (simp add: ac cong: update_accessor_congruence_unfoldE[OF uac])\n\nlemma update_accessor_cong_assist_idI:\n  \"iso_tuple_update_accessor_cong_assist id id\"\n  by (simp add: iso_tuple_update_accessor_cong_assist_def)\n\nlemma update_accessor_cong_assist_triv:\n  \"iso_tuple_update_accessor_cong_assist upd ac \\<Longrightarrow>\n    iso_tuple_update_accessor_cong_assist upd ac\"\n  by assumption\n\nlemma update_accessor_accessor_eqE:\n  \"iso_tuple_update_accessor_eq_assist upd ac v f v' x \\<Longrightarrow> ac v = x\"\n  by (simp add: iso_tuple_update_accessor_eq_assist_def)\n\nlemma update_accessor_updator_eqE:\n  \"iso_tuple_update_accessor_eq_assist upd ac v f v' x \\<Longrightarrow> upd f v = v'\"\n  by (simp add: iso_tuple_update_accessor_eq_assist_def)\n\nlemma iso_tuple_update_accessor_eq_assist_idI:\n  \"v' = f v \\<Longrightarrow> iso_tuple_update_accessor_eq_assist id id v f v' v\"\n  by (simp add: iso_tuple_update_accessor_eq_assist_def update_accessor_cong_assist_idI)\n\nlemma iso_tuple_update_accessor_eq_assist_triv:\n  \"iso_tuple_update_accessor_eq_assist upd ac v f v' x \\<Longrightarrow>\n    iso_tuple_update_accessor_eq_assist upd ac v f v' x\"\n  by assumption\n\nlemma iso_tuple_update_accessor_cong_from_eq:\n  \"iso_tuple_update_accessor_eq_assist upd ac v f v' x \\<Longrightarrow>\n    iso_tuple_update_accessor_cong_assist upd ac\"\n  by (simp add: iso_tuple_update_accessor_eq_assist_def)\n\nlemma iso_tuple_surjective_proof_assistI:\n  \"f x = y \\<Longrightarrow> iso_tuple_surjective_proof_assist x y f\"\n  by (simp add: iso_tuple_surjective_proof_assist_def)\n\nlemma iso_tuple_surjective_proof_assist_idE:\n  \"iso_tuple_surjective_proof_assist x y id \\<Longrightarrow> x = y\"\n  by (simp add: iso_tuple_surjective_proof_assist_def)\n\nlocale isomorphic_tuple =\n  fixes isom :: \"('a, 'b, 'c) tuple_isomorphism\"\n  assumes repr_inv: \"\\<And>x. abst isom (repr isom x) = x\"\n    and abst_inv: \"\\<And>y. repr isom (abst isom y) = y\"\nbegin\n\nlemma repr_inj: \"repr isom x = repr isom y \\<longleftrightarrow> x = y\"\n  by (auto dest: arg_cong [of \"repr isom x\" \"repr isom y\" \"abst isom\"]\n    simp add: repr_inv)\n\nlemma abst_inj: \"abst isom x = abst isom y \\<longleftrightarrow> x = y\"\n  by (auto dest: arg_cong [of \"abst isom x\" \"abst isom y\" \"repr isom\"]\n    simp add: abst_inv)\n\nlemmas simps = Let_def repr_inv abst_inv repr_inj abst_inj\n\nlemma iso_tuple_access_update_fst_fst:\n  \"f \\<circ> h g = j \\<circ> f \\<Longrightarrow>\n    (f \\<circ> iso_tuple_fst isom) \\<circ> (iso_tuple_fst_update isom \\<circ> h) g =\n      j \\<circ> (f \\<circ> iso_tuple_fst isom)\"\n  by (clarsimp simp: iso_tuple_fst_update_def iso_tuple_fst_def simps\n    fun_eq_iff)\n\nlemma iso_tuple_access_update_snd_snd:\n  \"f \\<circ> h g = j \\<circ> f \\<Longrightarrow>\n    (f \\<circ> iso_tuple_snd isom) \\<circ> (iso_tuple_snd_update isom \\<circ> h) g =\n      j \\<circ> (f \\<circ> iso_tuple_snd isom)\"\n  by (clarsimp simp: iso_tuple_snd_update_def iso_tuple_snd_def simps\n    fun_eq_iff)\n\nlemma iso_tuple_access_update_fst_snd:\n  \"(f \\<circ> iso_tuple_fst isom) \\<circ> (iso_tuple_snd_update isom \\<circ> h) g =\n    id \\<circ> (f \\<circ> iso_tuple_fst isom)\"\n  by (clarsimp simp: iso_tuple_snd_update_def iso_tuple_fst_def simps\n    fun_eq_iff)\n\nlemma iso_tuple_access_update_snd_fst:\n  \"(f \\<circ> iso_tuple_snd isom) \\<circ> (iso_tuple_fst_update isom \\<circ> h) g =\n    id \\<circ> (f \\<circ> iso_tuple_snd isom)\"\n  by (clarsimp simp: iso_tuple_fst_update_def iso_tuple_snd_def simps\n    fun_eq_iff)\n\nlemma iso_tuple_update_swap_fst_fst:\n  \"h f \\<circ> j g = j g \\<circ> h f \\<Longrightarrow>\n    (iso_tuple_fst_update isom \\<circ> h) f \\<circ> (iso_tuple_fst_update isom \\<circ> j) g =\n      (iso_tuple_fst_update isom \\<circ> j) g \\<circ> (iso_tuple_fst_update isom \\<circ> h) f\"\n  by (clarsimp simp: iso_tuple_fst_update_def simps apfst_compose fun_eq_iff)\n\nlemma iso_tuple_update_swap_snd_snd:\n  \"h f \\<circ> j g = j g \\<circ> h f \\<Longrightarrow>\n    (iso_tuple_snd_update isom \\<circ> h) f \\<circ> (iso_tuple_snd_update isom \\<circ> j) g =\n      (iso_tuple_snd_update isom \\<circ> j) g \\<circ> (iso_tuple_snd_update isom \\<circ> h) f\"\n  by (clarsimp simp: iso_tuple_snd_update_def simps apsnd_compose fun_eq_iff)\n\nlemma iso_tuple_update_swap_fst_snd:\n  \"(iso_tuple_snd_update isom \\<circ> h) f \\<circ> (iso_tuple_fst_update isom \\<circ> j) g =\n    (iso_tuple_fst_update isom \\<circ> j) g \\<circ> (iso_tuple_snd_update isom \\<circ> h) f\"\n  by (clarsimp simp: iso_tuple_fst_update_def iso_tuple_snd_update_def\n    simps fun_eq_iff)\n\nlemma iso_tuple_update_swap_snd_fst:\n  \"(iso_tuple_fst_update isom \\<circ> h) f \\<circ> (iso_tuple_snd_update isom \\<circ> j) g =\n    (iso_tuple_snd_update isom \\<circ> j) g \\<circ> (iso_tuple_fst_update isom \\<circ> h) f\"\n  by (clarsimp simp: iso_tuple_fst_update_def iso_tuple_snd_update_def simps\n    fun_eq_iff)\n\nlemma iso_tuple_update_compose_fst_fst:\n  \"h f \\<circ> j g = k (f \\<circ> g) \\<Longrightarrow>\n    (iso_tuple_fst_update isom \\<circ> h) f \\<circ> (iso_tuple_fst_update isom \\<circ> j) g =\n      (iso_tuple_fst_update isom \\<circ> k) (f \\<circ> g)\"\n  by (clarsimp simp: iso_tuple_fst_update_def simps apfst_compose fun_eq_iff)\n\nlemma iso_tuple_update_compose_snd_snd:\n  \"h f \\<circ> j g = k (f \\<circ> g) \\<Longrightarrow>\n    (iso_tuple_snd_update isom \\<circ> h) f \\<circ> (iso_tuple_snd_update isom \\<circ> j) g =\n      (iso_tuple_snd_update isom \\<circ> k) (f \\<circ> g)\"\n  by (clarsimp simp: iso_tuple_snd_update_def simps apsnd_compose fun_eq_iff)\n\nlemma iso_tuple_surjective_proof_assist_step:\n  \"iso_tuple_surjective_proof_assist v a (iso_tuple_fst isom \\<circ> f) \\<Longrightarrow>\n    iso_tuple_surjective_proof_assist v b (iso_tuple_snd isom \\<circ> f) \\<Longrightarrow>\n    iso_tuple_surjective_proof_assist v (iso_tuple_cons isom a b) f\"\n  by (clarsimp simp: iso_tuple_surjective_proof_assist_def simps\n    iso_tuple_fst_def iso_tuple_snd_def iso_tuple_cons_def)\n\nlemma iso_tuple_fst_update_accessor_cong_assist:\n  assumes \"iso_tuple_update_accessor_cong_assist f g\"\n  shows \"iso_tuple_update_accessor_cong_assist\n    (iso_tuple_fst_update isom \\<circ> f) (g \\<circ> iso_tuple_fst isom)\"\nproof -\n  from assms have \"f id = id\"\n    by (rule iso_tuple_update_accessor_cong_assist_id)\n  with assms show ?thesis\n    by (clarsimp simp: iso_tuple_update_accessor_cong_assist_def simps\n      iso_tuple_fst_update_def iso_tuple_fst_def)\nqed\n\nlemma iso_tuple_snd_update_accessor_cong_assist:\n  assumes \"iso_tuple_update_accessor_cong_assist f g\"\n  shows \"iso_tuple_update_accessor_cong_assist\n    (iso_tuple_snd_update isom \\<circ> f) (g \\<circ> iso_tuple_snd isom)\"\nproof -\n  from assms have \"f id = id\"\n    by (rule iso_tuple_update_accessor_cong_assist_id)\n  with assms show ?thesis\n    by (clarsimp simp: iso_tuple_update_accessor_cong_assist_def simps\n      iso_tuple_snd_update_def iso_tuple_snd_def)\nqed\n\nlemma iso_tuple_fst_update_accessor_eq_assist:\n  assumes \"iso_tuple_update_accessor_eq_assist f g a u a' v\"\n  shows \"iso_tuple_update_accessor_eq_assist\n    (iso_tuple_fst_update isom \\<circ> f) (g \\<circ> iso_tuple_fst isom)\n    (iso_tuple_cons isom a b) u (iso_tuple_cons isom a' b) v\"\nproof -\n  from assms have \"f id = id\"\n    by (auto simp add: iso_tuple_update_accessor_eq_assist_def\n      intro: iso_tuple_update_accessor_cong_assist_id)\n  with assms show ?thesis\n    by (clarsimp simp: iso_tuple_update_accessor_eq_assist_def\n      iso_tuple_fst_update_def iso_tuple_fst_def\n      iso_tuple_update_accessor_cong_assist_def iso_tuple_cons_def simps)\nqed\n\nlemma iso_tuple_snd_update_accessor_eq_assist:\n  assumes \"iso_tuple_update_accessor_eq_assist f g b u b' v\"\n  shows \"iso_tuple_update_accessor_eq_assist\n    (iso_tuple_snd_update isom \\<circ> f) (g \\<circ> iso_tuple_snd isom)\n    (iso_tuple_cons isom a b) u (iso_tuple_cons isom a b') v\"\nproof -\n  from assms have \"f id = id\"\n    by (auto simp add: iso_tuple_update_accessor_eq_assist_def\n      intro: iso_tuple_update_accessor_cong_assist_id)\n  with assms show ?thesis\n    by (clarsimp simp: iso_tuple_update_accessor_eq_assist_def\n      iso_tuple_snd_update_def iso_tuple_snd_def\n      iso_tuple_update_accessor_cong_assist_def iso_tuple_cons_def simps)\nqed\n\nlemma iso_tuple_cons_conj_eqI:\n  \"a = c \\<and> b = d \\<and> P \\<longleftrightarrow> Q \\<Longrightarrow>\n    iso_tuple_cons isom a b = iso_tuple_cons isom c d \\<and> P \\<longleftrightarrow> Q\"\n  by (clarsimp simp: iso_tuple_cons_def simps)\n\nlemmas intros =\n  iso_tuple_access_update_fst_fst\n  iso_tuple_access_update_snd_snd\n  iso_tuple_access_update_fst_snd\n  iso_tuple_access_update_snd_fst\n  iso_tuple_update_swap_fst_fst\n  iso_tuple_update_swap_snd_snd\n  iso_tuple_update_swap_fst_snd\n  iso_tuple_update_swap_snd_fst\n  iso_tuple_update_compose_fst_fst\n  iso_tuple_update_compose_snd_snd\n  iso_tuple_surjective_proof_assist_step\n  iso_tuple_fst_update_accessor_eq_assist\n  iso_tuple_snd_update_accessor_eq_assist\n  iso_tuple_fst_update_accessor_cong_assist\n  iso_tuple_snd_update_accessor_cong_assist\n  iso_tuple_cons_conj_eqI\n\nend\n\nlemma isomorphic_tuple_intro:\n  fixes repr abst\n  assumes repr_inj: \"\\<And>x y. repr x = repr y \\<longleftrightarrow> x = y\"\n    and abst_inv: \"\\<And>z. repr (abst z) = z\"\n    and v: \"v \\<equiv> Tuple_Isomorphism repr abst\"\n  shows \"isomorphic_tuple v\"\nproof\n  fix x have \"repr (abst (repr x)) = repr x\"\n    by (simp add: abst_inv)\n  then show \"Record.abst v (Record.repr v x) = x\"\n    by (simp add: v repr_inj)\nnext\n  fix y\n  show \"Record.repr v (Record.abst v y) = y\"\n    by (simp add: v) (fact abst_inv)\nqed\n\ndefinition\n  \"tuple_iso_tuple \\<equiv> Tuple_Isomorphism id id\"\n\nlemma tuple_iso_tuple:\n  \"isomorphic_tuple tuple_iso_tuple\"\n  by (simp add: isomorphic_tuple_intro [OF _ _ reflexive] tuple_iso_tuple_def)\n\nlemma refl_conj_eq: \"Q = R \\<Longrightarrow> P \\<and> Q \\<longleftrightarrow> P \\<and> R\"\n  by simp\n\nlemma iso_tuple_UNIV_I: \"x \\<in> UNIV \\<equiv> True\"\n  by simp\n\nlemma iso_tuple_True_simp: \"(True \\<Longrightarrow> PROP P) \\<equiv> PROP P\"\n  by simp\n\nlemma prop_subst: \"s = t \\<Longrightarrow> PROP P t \\<Longrightarrow> PROP P s\"\n  by simp\n\nlemma K_record_comp: \"(\\<lambda>x. c) \\<circ> f = (\\<lambda>x. c)\"\n  by (simp add: comp_def)\n\n\nsubsection \\<open>Concrete record syntax\\<close>\n\nnonterminal\n  ident and\n  field_type and\n  field_types and\n  field and\n  fields and\n  field_update and\n  field_updates\n\nsyntax\n  \"_constify\"           :: \"id => ident\"                        (\"_\")\n  \"_constify\"           :: \"longid => ident\"                    (\"_\")\n\n  \"_field_type\"         :: \"ident => type => field_type\"        (\"(2_ ::/ _)\")\n  \"\"                    :: \"field_type => field_types\"          (\"_\")\n  \"_field_types\"        :: \"field_type => field_types => field_types\"    (\"_,/ _\")\n  \"_record_type\"        :: \"field_types => type\"                (\"(3\\<lparr>_\\<rparr>)\")\n  \"_record_type_scheme\" :: \"field_types => type => type\"        (\"(3\\<lparr>_,/ (2\\<dots> ::/ _)\\<rparr>)\")\n\n  \"_field\"              :: \"ident => 'a => field\"               (\"(2_ =/ _)\")\n  \"\"                    :: \"field => fields\"                    (\"_\")\n  \"_fields\"             :: \"field => fields => fields\"          (\"_,/ _\")\n  \"_record\"             :: \"fields => 'a\"                       (\"(3\\<lparr>_\\<rparr>)\")\n  \"_record_scheme\"      :: \"fields => 'a => 'a\"                 (\"(3\\<lparr>_,/ (2\\<dots> =/ _)\\<rparr>)\")\n\n  \"_field_update\"       :: \"ident => 'a => field_update\"        (\"(2_ :=/ _)\")\n  \"\"                    :: \"field_update => field_updates\"      (\"_\")\n  \"_field_updates\"      :: \"field_update => field_updates => field_updates\"  (\"_,/ _\")\n  \"_record_update\"      :: \"'a => field_updates => 'b\"          (\"_/(3\\<lparr>_\\<rparr>)\" [900, 0] 900)\n\nsyntax (ASCII)\n  \"_record_type\"        :: \"field_types => type\"                (\"(3'(| _ |'))\")\n  \"_record_type_scheme\" :: \"field_types => type => type\"        (\"(3'(| _,/ (2... ::/ _) |'))\")\n  \"_record\"             :: \"fields => 'a\"                       (\"(3'(| _ |'))\")\n  \"_record_scheme\"      :: \"fields => 'a => 'a\"                 (\"(3'(| _,/ (2... =/ _) |'))\")\n  \"_record_update\"      :: \"'a => field_updates => 'b\"          (\"_/(3'(| _ |'))\" [900, 0] 900)\n\n\nsubsection \\<open>Record package\\<close>\n\nML_file \\<open>Tools/record.ML\\<close>\n\nhide_const (open) Tuple_Isomorphism repr abst iso_tuple_fst iso_tuple_snd\n  iso_tuple_fst_update iso_tuple_snd_update iso_tuple_cons\n  iso_tuple_surjective_proof_assist iso_tuple_update_accessor_cong_assist\n  iso_tuple_update_accessor_eq_assist tuple_iso_tuple\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/Record.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5389832354982647, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.29676813936535956}}
{"text": "(* Copyright 2021 (C) Mihails Milehins *)\n\nsection\\<open>Natural transformation of a semifunctor\\<close>\ntheory CZH_SMC_NTSMCF\n  imports \n    CZH_SMC_Semifunctor\n    CZH_DG_TDGHM\nbegin\n\n\n\nsubsection\\<open>Background\\<close>\n\nnamed_theorems ntsmcf_cs_simps\nnamed_theorems ntsmcf_cs_intros\n\nlemmas [smc_cs_simps] = dg_shared_cs_simps\nlemmas [smc_cs_intros] = dg_shared_cs_intros\n\n\nsubsubsection\\<open>Slicing\\<close>\n\ndefinition ntsmcf_tdghm :: \"V \\<Rightarrow> V\"\n  where \"ntsmcf_tdghm \\<NN> = \n    [\n      \\<NN>\\<lparr>NTMap\\<rparr>, \n      smcf_dghm (\\<NN>\\<lparr>NTDom\\<rparr>),\n      smcf_dghm (\\<NN>\\<lparr>NTCod\\<rparr>),\n      smc_dg (\\<NN>\\<lparr>NTDGDom\\<rparr>),\n      smc_dg (\\<NN>\\<lparr>NTDGCod\\<rparr>)\n    ]\\<^sub>\\<circ>\"\n\n\ntext\\<open>Components.\\<close>\n\nlemma ntsmcf_tdghm_components:\n  shows [slicing_simps]: \"ntsmcf_tdghm \\<NN>\\<lparr>NTMap\\<rparr> = \\<NN>\\<lparr>NTMap\\<rparr>\"\n    and [slicing_commute]: \"ntsmcf_tdghm \\<NN>\\<lparr>NTDom\\<rparr> = smcf_dghm (\\<NN>\\<lparr>NTDom\\<rparr>)\"\n    and [slicing_commute]: \"ntsmcf_tdghm \\<NN>\\<lparr>NTCod\\<rparr> = smcf_dghm (\\<NN>\\<lparr>NTCod\\<rparr>)\"\n    and [slicing_commute]: \"ntsmcf_tdghm \\<NN>\\<lparr>NTDGDom\\<rparr> = smc_dg (\\<NN>\\<lparr>NTDGDom\\<rparr>)\"\n    and [slicing_commute]: \"ntsmcf_tdghm \\<NN>\\<lparr>NTDGCod\\<rparr> = smc_dg (\\<NN>\\<lparr>NTDGCod\\<rparr>)\"\n  unfolding ntsmcf_tdghm_def nt_field_simps by (auto simp: nat_omega_simps)\n\n\n\nsubsection\\<open>Definition and elementary properties\\<close>\n\n\ntext\\<open>\nA natural transformation of semifunctors, as presented in this work,\nis a generalization of the concept of a natural transformation, as presented in\nChapter I-4 in \\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>, to semicategories and\nsemifunctors.\n\\<close>\n\nlocale is_ntsmcf = \n  \\<Z> \\<alpha> + \n  vfsequence \\<NN> + \n  NTDom: is_semifunctor \\<alpha> \\<AA> \\<BB> \\<FF> + \n  NTCod: is_semifunctor \\<alpha> \\<AA> \\<BB> \\<GG>\n  for \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN> +\n  assumes ntsmcf_length[smc_cs_simps]: \"vcard \\<NN> = 5\\<^sub>\\<nat>\"  \n    and ntsmcf_is_tdghm[slicing_intros]: \"ntsmcf_tdghm \\<NN> :\n      smcf_dghm \\<FF> \\<mapsto>\\<^sub>D\\<^sub>G\\<^sub>H\\<^sub>M smcf_dghm \\<GG> : smc_dg \\<AA> \\<mapsto>\\<mapsto>\\<^sub>D\\<^sub>G\\<^bsub>\\<alpha>\\<^esub> smc_dg \\<BB>\"\n    and ntsmcf_NTDom[smc_cs_simps]: \"\\<NN>\\<lparr>NTDom\\<rparr> = \\<FF>\"\n    and ntsmcf_NTCod[smc_cs_simps]: \"\\<NN>\\<lparr>NTCod\\<rparr> = \\<GG>\"\n    and ntsmcf_NTDGDom[smc_cs_simps]: \"\\<NN>\\<lparr>NTDGDom\\<rparr> = \\<AA>\"\n    and ntsmcf_NTDGCod[smc_cs_simps]: \"\\<NN>\\<lparr>NTDGCod\\<rparr> = \\<BB>\"\n    and ntsmcf_Comp_commute[smc_cs_intros]: \"f : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b \\<Longrightarrow>\n      \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> = \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\" \n\nsyntax \"_is_ntsmcf\" :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> bool\"\n  (\\<open>(_ :/ _ \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F _ :/ _ \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<index> _)\\<close> [51, 51, 51, 51, 51] 51)\ntranslations \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\" \\<rightleftharpoons> \n  \"CONST is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN>\"\n\nabbreviation all_ntsmcfs :: \"V \\<Rightarrow> V\"\n  where \"all_ntsmcfs \\<alpha> \\<equiv> set {\\<NN>. \\<exists>\\<FF> \\<GG> \\<AA> \\<BB>. \\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>}\"\n\nabbreviation ntsmcfs :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V\"\n  where \"ntsmcfs \\<alpha> \\<AA> \\<BB> \\<equiv> set {\\<NN>. \\<exists>\\<FF> \\<GG>. \\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>}\"\n\nabbreviation these_ntsmcfs :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V\"\n  where \"these_ntsmcfs \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<equiv> set {\\<NN>. \\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>}\"\n\nlemmas [smc_cs_simps] =\n  is_ntsmcf.ntsmcf_length\n  is_ntsmcf.ntsmcf_NTDom\n  is_ntsmcf.ntsmcf_NTCod\n  is_ntsmcf.ntsmcf_NTDGDom\n  is_ntsmcf.ntsmcf_NTDGCod\n  is_ntsmcf.ntsmcf_Comp_commute\n\nlemmas [smc_cs_intros] = is_ntsmcf.ntsmcf_Comp_commute\n\nlemma (in is_ntsmcf) ntsmcf_is_tdghm':\n  assumes \"\\<FF>' = smcf_dghm \\<FF>\"\n    and \"\\<GG>' = smcf_dghm \\<GG>\"\n    and \"\\<AA>' = smc_dg \\<AA>\"\n    and \"\\<BB>' = smc_dg \\<BB>\"\n  shows \"ntsmcf_tdghm \\<NN> : \\<FF>' \\<mapsto>\\<^sub>D\\<^sub>G\\<^sub>H\\<^sub>M \\<GG>' : \\<AA>' \\<mapsto>\\<mapsto>\\<^sub>D\\<^sub>G\\<^bsub>\\<alpha>\\<^esub> \\<BB>'\"\n  unfolding assms(1-4) by (rule ntsmcf_is_tdghm)\n\nlemmas [slicing_intros] = is_ntsmcf.ntsmcf_is_tdghm'\n\n\ntext\\<open>Rules.\\<close>\n\nlemma (in is_ntsmcf) is_ntsmcf_axioms'[smc_cs_intros]:\n  assumes \"\\<alpha>' = \\<alpha>\" and \"\\<AA>' = \\<AA>\" and \"\\<BB>' = \\<BB>\" and \"\\<FF>' = \\<FF>\" and \"\\<GG>' = \\<GG>\"\n  shows \"\\<NN> : \\<FF>' \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>' : \\<AA>' \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>'\\<^esub> \\<BB>'\"\n  unfolding assms by (rule is_ntsmcf_axioms)\n\nmk_ide rf is_ntsmcf_def[unfolded is_ntsmcf_axioms_def]\n  |intro is_ntsmcfI|\n  |dest is_ntsmcfD[dest]|\n  |elim is_ntsmcfE[elim]|\n\nlemmas [smc_cs_intros] = \n  is_ntsmcfD(3,4)\n\nlemma is_ntsmcfI':\n  assumes \"\\<Z> \\<alpha>\"\n    and \"vfsequence \\<NN>\"\n    and \"\\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"vcard \\<NN> = 5\\<^sub>\\<nat>\"\n    and \"\\<NN>\\<lparr>NTDom\\<rparr> = \\<FF>\"\n    and \"\\<NN>\\<lparr>NTCod\\<rparr> = \\<GG>\"\n    and \"\\<NN>\\<lparr>NTDGDom\\<rparr> = \\<AA>\"\n    and \"\\<NN>\\<lparr>NTDGCod\\<rparr> = \\<BB>\"\n    and \"vsv (\\<NN>\\<lparr>NTMap\\<rparr>)\"\n    and \"\\<D>\\<^sub>\\<circ> (\\<NN>\\<lparr>NTMap\\<rparr>) = \\<AA>\\<lparr>Obj\\<rparr>\"\n    and \"\\<And>a. a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr> \\<Longrightarrow> \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n    and \"\\<And>a b f. f : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b \\<Longrightarrow>\n      \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> = \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\n  shows \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  by (intro is_ntsmcfI is_tdghmI, unfold ntsmcf_tdghm_components slicing_simps)\n    (\n      simp_all add: \n        assms nat_omega_simps \n        ntsmcf_tdghm_def  \n        is_semifunctorD(6)[OF assms(3)] \n        is_semifunctorD(6)[OF assms(4)]\n    )\n\nlemma is_ntsmcfD':\n  assumes \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"\\<Z> \\<alpha>\"\n    and \"vfsequence \\<NN>\"\n    and \"\\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"vcard \\<NN> = 5\\<^sub>\\<nat>\"\n    and \"\\<NN>\\<lparr>NTDom\\<rparr> = \\<FF>\"\n    and \"\\<NN>\\<lparr>NTCod\\<rparr> = \\<GG>\"\n    and \"\\<NN>\\<lparr>NTDGDom\\<rparr> = \\<AA>\"\n    and \"\\<NN>\\<lparr>NTDGCod\\<rparr> = \\<BB>\"\n    and \"vsv (\\<NN>\\<lparr>NTMap\\<rparr>)\"\n    and \"\\<D>\\<^sub>\\<circ> (\\<NN>\\<lparr>NTMap\\<rparr>) = \\<AA>\\<lparr>Obj\\<rparr>\"\n    and \"\\<And>a. a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr> \\<Longrightarrow> \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n    and \"\\<And>a b f. f : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b \\<Longrightarrow>\n      \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> = \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\n  by \n    (\n      simp_all add: \n        is_ntsmcfD(2-11)[OF assms] \n        is_tdghmD[OF is_ntsmcfD(6)[OF assms], unfolded slicing_simps]\n    )\n\nlemma is_ntsmcfE':\n  assumes \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  obtains \"\\<Z> \\<alpha>\"\n    and \"vfsequence \\<NN>\"\n    and \"\\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"vcard \\<NN> = 5\\<^sub>\\<nat>\"\n    and \"\\<NN>\\<lparr>NTDom\\<rparr> = \\<FF>\"\n    and \"\\<NN>\\<lparr>NTCod\\<rparr> = \\<GG>\"\n    and \"\\<NN>\\<lparr>NTDGDom\\<rparr> = \\<AA>\"\n    and \"\\<NN>\\<lparr>NTDGCod\\<rparr> = \\<BB>\"\n    and \"vsv (\\<NN>\\<lparr>NTMap\\<rparr>)\"\n    and \"\\<D>\\<^sub>\\<circ> (\\<NN>\\<lparr>NTMap\\<rparr>) = \\<AA>\\<lparr>Obj\\<rparr>\"\n    and \"\\<And>a. a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr> \\<Longrightarrow> \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n    and \"\\<And>a b f. f : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b \\<Longrightarrow>\n      \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> = \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\n  using assms by (simp add: is_ntsmcfD')\n\n\ntext\\<open>Slicing.\\<close>\n\ncontext is_ntsmcf\nbegin\n\ninterpretation tdghm: is_tdghm \n  \\<alpha> \\<open>smc_dg \\<AA>\\<close> \\<open>smc_dg \\<BB>\\<close> \\<open>smcf_dghm \\<FF>\\<close> \\<open>smcf_dghm \\<GG>\\<close> \\<open>ntsmcf_tdghm \\<NN>\\<close>\n  by (rule ntsmcf_is_tdghm)\n\nlemmas_with [unfolded slicing_simps]:\n  ntsmcf_NTMap_vsv = tdghm.tdghm_NTMap_vsv\n  and ntsmcf_NTMap_vdomain[smc_cs_simps] = tdghm.tdghm_NTMap_vdomain\n  and ntsmcf_NTMap_is_arr = tdghm.tdghm_NTMap_is_arr\n  and ntsmcf_NTMap_is_arr'[smc_cs_intros]  = tdghm.tdghm_NTMap_is_arr'\n\nsublocale NTMap: vsv \\<open>\\<NN>\\<lparr>NTMap\\<rparr>\\<close>\n  rewrites \"\\<D>\\<^sub>\\<circ> (\\<NN>\\<lparr>NTMap\\<rparr>) = \\<AA>\\<lparr>Obj\\<rparr>\"\n  by (rule ntsmcf_NTMap_vsv) (simp add: smc_cs_simps)\n\nlemmas_with [unfolded slicing_simps]:\n  ntsmcf_NTMap_app_in_Arr[smc_cs_intros] = tdghm.tdghm_NTMap_app_in_Arr\n  and ntsmcf_NTMap_vrange_vifunion = tdghm.tdghm_NTMap_vrange_vifunion\n  and ntsmcf_NTMap_vrange = tdghm.tdghm_NTMap_vrange\n  and ntsmcf_NTMap_vsubset_Vset = tdghm.tdghm_NTMap_vsubset_Vset\n  and ntsmcf_NTMap_in_Vset = tdghm.tdghm_NTMap_in_Vset\n  and ntsmcf_is_tdghm_if_ge_Limit = tdghm.tdghm_is_tdghm_if_ge_Limit\n\nend\n\nlemmas [smc_cs_intros] = is_ntsmcf.ntsmcf_NTMap_is_arr'\n\nlemma (in is_ntsmcf) ntsmcf_Comp_commute':\n  assumes \"f : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b\" and \"g : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n  shows \n    \"\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> (\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> g) =\n      (\\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>) \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> g\"\n  using assms\n  by \n    (\n      cs_concl cs_shallow\n        cs_simp: ntsmcf_Comp_commute semicategory.smc_Comp_assoc[symmetric] \n        cs_intro: smc_cs_intros\n    )\n\nlemma (in is_ntsmcf) ntsmcf_Comp_commute'':\n  assumes \"f : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b\" and \"g : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n  shows \n    \"\\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> (\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> g) =\n      (\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr>) \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> g\"\n  using assms\n  by \n    (\n      cs_concl  \n        cs_simp: ntsmcf_Comp_commute semicategory.smc_Comp_assoc[symmetric] \n        cs_intro: smc_cs_intros\n    )\n\n\ntext\\<open>Elementary properties.\\<close>\n\nlemma ntsmcf_eqI:\n  assumes \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\" \n    and \"\\<NN>' : \\<FF>' \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>' : \\<AA>' \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>'\"\n    and \"\\<NN>\\<lparr>NTMap\\<rparr> = \\<NN>'\\<lparr>NTMap\\<rparr>\"\n    and \"\\<FF> = \\<FF>'\"\n    and \"\\<GG> = \\<GG>'\"\n    and \"\\<AA> = \\<AA>'\"\n    and \"\\<BB> = \\<BB>'\"\n  shows \"\\<NN> = \\<NN>'\"\nproof-\n  interpret L: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN> by (rule assms(1))\n  interpret R: is_ntsmcf \\<alpha> \\<AA>' \\<BB>' \\<FF>' \\<GG>' \\<NN>' by (rule assms(2))\n  show ?thesis\n  proof(rule vsv_eqI)\n    have dom: \"\\<D>\\<^sub>\\<circ> \\<NN> = 5\\<^sub>\\<nat>\" \n      by (cs_concl cs_shallow cs_simp: smc_cs_simps V_cs_simps)\n    show \"\\<D>\\<^sub>\\<circ> \\<NN> = \\<D>\\<^sub>\\<circ> \\<NN>'\" \n      by (cs_concl cs_shallow cs_simp: smc_cs_simps V_cs_simps)\n    from assms(4-7) have sup: \n      \"\\<NN>\\<lparr>NTDom\\<rparr> = \\<NN>'\\<lparr>NTDom\\<rparr>\" \"\\<NN>\\<lparr>NTCod\\<rparr> = \\<NN>'\\<lparr>NTCod\\<rparr>\" \n      \"\\<NN>\\<lparr>NTDGDom\\<rparr> = \\<NN>'\\<lparr>NTDGDom\\<rparr>\" \"\\<NN>\\<lparr>NTDGCod\\<rparr> = \\<NN>'\\<lparr>NTDGCod\\<rparr>\" \n      by (simp_all add: smc_cs_simps)\n    show \"a \\<in>\\<^sub>\\<circ> \\<D>\\<^sub>\\<circ> \\<NN> \\<Longrightarrow> \\<NN>\\<lparr>a\\<rparr> = \\<NN>'\\<lparr>a\\<rparr>\" for a \n      by (unfold dom, elim_in_numeral, insert assms(3) sup)\n        (auto simp: nt_field_simps)\n  qed auto\nqed\n\nlemma ntsmcf_tdghm_eqI:\n  assumes \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\" \n    and \"\\<NN>' : \\<FF>' \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>' : \\<AA>' \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>'\"\n    and \"\\<FF> = \\<FF>'\"\n    and \"\\<GG> = \\<GG>'\"\n    and \"\\<AA> = \\<AA>'\"\n    and \"\\<BB> = \\<BB>'\"\n    and \"ntsmcf_tdghm \\<NN> = ntsmcf_tdghm \\<NN>'\"\n  shows \"\\<NN> = \\<NN>'\"\nproof(rule ntsmcf_eqI[of \\<alpha>])\n  from assms(7) have \"ntsmcf_tdghm \\<NN>\\<lparr>NTMap\\<rparr> = ntsmcf_tdghm \\<NN>'\\<lparr>NTMap\\<rparr>\" by simp\n  then show \"\\<NN>\\<lparr>NTMap\\<rparr> = \\<NN>'\\<lparr>NTMap\\<rparr>\" unfolding slicing_simps by simp_all\n  from assms(3-6) show \"\\<FF> = \\<FF>'\" \"\\<GG> = \\<GG>'\" \"\\<AA> = \\<AA>'\" \"\\<BB> = \\<BB>'\" by simp_all\nqed (simp_all add: assms(1,2))\n\nlemma (in is_ntsmcf) ntsmcf_def:\n  \"\\<NN> = [\\<NN>\\<lparr>NTMap\\<rparr>, \\<NN>\\<lparr>NTDom\\<rparr>, \\<NN>\\<lparr>NTCod\\<rparr>, \\<NN>\\<lparr>NTDGDom\\<rparr>, \\<NN>\\<lparr>NTDGCod\\<rparr>]\\<^sub>\\<circ>\"\nproof(rule vsv_eqI)\n  have dom_lhs: \"\\<D>\\<^sub>\\<circ> \\<NN> = 5\\<^sub>\\<nat>\" \n    by (cs_concl cs_shallow cs_simp: smc_cs_simps V_cs_simps)\n  have dom_rhs:\n    \"\\<D>\\<^sub>\\<circ> [\\<NN>\\<lparr>NTMap\\<rparr>, \\<NN>\\<lparr>NTDGDom\\<rparr>, \\<NN>\\<lparr>NTDGCod\\<rparr>, \\<NN>\\<lparr>NTDom\\<rparr>, \\<NN>\\<lparr>NTCod\\<rparr>]\\<^sub>\\<circ> = 5\\<^sub>\\<nat>\"\n    by (simp add: nat_omega_simps)\n  then show \"\\<D>\\<^sub>\\<circ> \\<NN> = \\<D>\\<^sub>\\<circ> [\\<NN>\\<lparr>NTMap\\<rparr>, \\<NN>\\<lparr>NTDom\\<rparr>, \\<NN>\\<lparr>NTCod\\<rparr>, \\<NN>\\<lparr>NTDGDom\\<rparr>, \\<NN>\\<lparr>NTDGCod\\<rparr>]\\<^sub>\\<circ>\"\n    unfolding dom_lhs dom_rhs by (simp add: nat_omega_simps)\n  show \"a \\<in>\\<^sub>\\<circ> \\<D>\\<^sub>\\<circ> \\<NN> \\<Longrightarrow>\n    \\<NN>\\<lparr>a\\<rparr> = [\\<NN>\\<lparr>NTMap\\<rparr>, \\<NN>\\<lparr>NTDom\\<rparr>, \\<NN>\\<lparr>NTCod\\<rparr>, \\<NN>\\<lparr>NTDGDom\\<rparr>, \\<NN>\\<lparr>NTDGCod\\<rparr>]\\<^sub>\\<circ>\\<lparr>a\\<rparr>\" \n    for a\n    by (unfold dom_lhs, elim_in_numeral, unfold nt_field_simps)\n      (simp_all add: nat_omega_simps)\nqed (auto simp: vsv_axioms)\n\n\ntext\\<open>Size.\\<close>\n\nlemma (in is_ntsmcf) ntsmcf_in_Vset: \n  assumes \"\\<Z> \\<beta>\" and \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\"\n  shows \"\\<NN> \\<in>\\<^sub>\\<circ> Vset \\<beta>\"\nproof-\n  interpret \\<beta>: \\<Z> \\<beta> by (rule assms(1))\n  note [smc_cs_intros] = \n    ntsmcf_NTMap_in_Vset\n    NTDom.smcf_in_Vset\n    NTCod.smcf_in_Vset\n    NTDom.HomDom.smc_in_Vset\n    NTDom.HomCod.smc_in_Vset\n  from assms(2) show ?thesis\n    by (subst ntsmcf_def) \n      (\n        cs_concl cs_shallow \n          cs_simp: smc_cs_simps cs_intro: smc_cs_intros V_cs_intros\n      )\nqed\n\nlemma (in is_ntsmcf) ntsmcf_is_ntsmcf_if_ge_Limit:\n  assumes \"\\<Z> \\<beta>\" and \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\"\n  shows \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<beta>\\<^esub> \\<BB>\"\nproof(intro is_ntsmcfI )\n  show \"ntsmcf_tdghm \\<NN> :\n    smcf_dghm \\<FF> \\<mapsto>\\<^sub>D\\<^sub>G\\<^sub>H\\<^sub>M smcf_dghm \\<GG> : smc_dg \\<AA> \\<mapsto>\\<mapsto>\\<^sub>D\\<^sub>G\\<^bsub>\\<beta>\\<^esub> smc_dg \\<BB>\"\n    by (rule is_tdghm.tdghm_is_tdghm_if_ge_Limit[OF ntsmcf_is_tdghm assms])\n  show \"\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> = \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\n    if \"f : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b\" for f a b\n    by \n      (\n        use that in \n          \\<open>cs_concl cs_shallow cs_simp: smc_cs_simps cs_intro: smc_cs_intros\\<close>\n      )+\nqed \n  (\n    cs_concl cs_shallow\n      cs_simp: smc_cs_simps \n      cs_intro:\n        smc_cs_intros\n        V_cs_intros\n        assms \n        NTDom.smcf_is_semifunctor_if_ge_Limit\n        NTCod.smcf_is_semifunctor_if_ge_Limit\n   )+\n\nlemma small_all_ntsmcfs[simp]: \n  \"small {\\<NN>. \\<exists>\\<FF> \\<GG> \\<AA> \\<BB>. \\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>}\"\nproof(cases \\<open>\\<Z> \\<alpha>\\<close>)\n  case True\n  from is_ntsmcf.ntsmcf_in_Vset show ?thesis\n    by (intro down[of _ \\<open>Vset (\\<alpha> + \\<omega>)\\<close>]) \n      (auto simp: True \\<Z>.\\<Z>_Limit_\\<alpha>\\<omega> \\<Z>.\\<Z>_\\<omega>_\\<alpha>\\<omega> \\<Z>.intro \\<Z>.\\<Z>_\\<alpha>_\\<alpha>\\<omega>)\nnext\n  case False\n  then have \"{\\<NN>. \\<exists>\\<FF> \\<GG> \\<AA> \\<BB>. \\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>} = {}\" by auto\n  then show ?thesis by simp\nqed\n\nlemma small_ntsmcfs[simp]: \"small {\\<NN>. \\<exists>\\<FF> \\<GG>. \\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>}\"\n  by (rule down[of _ \\<open>set {\\<NN>. \\<exists>\\<FF> \\<GG> \\<AA> \\<BB>. \\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>}\\<close>])\n    auto\n\nlemma small_these_ntcfs[simp]: \"small {\\<NN>. \\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>}\"\n  by (rule down[of _ \\<open>set {\\<NN>. \\<exists>\\<FF> \\<GG> \\<AA> \\<BB>. \\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>}\\<close>]) \n    auto\n\n\ntext\\<open>Further elementary results.\\<close>\n\nlemma these_ntsmcfs_iff(*not simp*):  \n  \"\\<NN> \\<in>\\<^sub>\\<circ> these_ntsmcfs \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<longleftrightarrow> \\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  by auto\n\n\n\nsubsection\\<open>Opposite natural transformation of semifunctors\\<close>\n\n\nsubsubsection\\<open>Definition and elementary properties\\<close>\n\n\ntext\\<open>See section 1.5 in \\<^cite>\\<open>\"bodo_categories_1970\"\\<close>.\\<close>\n\ndefinition op_ntsmcf :: \"V \\<Rightarrow> V\"\n  where \"op_ntsmcf \\<NN> =\n    [\n      \\<NN>\\<lparr>NTMap\\<rparr>,\n      op_smcf (\\<NN>\\<lparr>NTCod\\<rparr>),\n      op_smcf (\\<NN>\\<lparr>NTDom\\<rparr>),\n      op_smc (\\<NN>\\<lparr>NTDGDom\\<rparr>),\n      op_smc (\\<NN>\\<lparr>NTDGCod\\<rparr>)\n    ]\\<^sub>\\<circ>\"\n\n\ntext\\<open>Components.\\<close>\n\nlemma op_ntsmcf_components[smc_op_simps]:\n  shows \"op_ntsmcf \\<NN>\\<lparr>NTMap\\<rparr> = \\<NN>\\<lparr>NTMap\\<rparr>\"\n    and \"op_ntsmcf \\<NN>\\<lparr>NTDom\\<rparr> = op_smcf (\\<NN>\\<lparr>NTCod\\<rparr>)\"\n    and \"op_ntsmcf \\<NN>\\<lparr>NTCod\\<rparr> = op_smcf (\\<NN>\\<lparr>NTDom\\<rparr>)\"\n    and \"op_ntsmcf \\<NN>\\<lparr>NTDGDom\\<rparr> = op_smc (\\<NN>\\<lparr>NTDGDom\\<rparr>)\"\n    and \"op_ntsmcf \\<NN>\\<lparr>NTDGCod\\<rparr> = op_smc (\\<NN>\\<lparr>NTDGCod\\<rparr>)\"\n  unfolding op_ntsmcf_def nt_field_simps by (auto simp: nat_omega_simps)\n\n\ntext\\<open>Slicing.\\<close>\n\nlemma op_tdghm_ntsmcf_tdghm[slicing_commute]: \n  \"op_tdghm (ntsmcf_tdghm \\<NN>) = ntsmcf_tdghm (op_ntsmcf \\<NN>)\"\nproof(rule vsv_eqI)\n  have dom_lhs: \"\\<D>\\<^sub>\\<circ> (op_tdghm (ntsmcf_tdghm \\<NN>)) = 5\\<^sub>\\<nat>\"\n    unfolding op_tdghm_def by (auto simp: nat_omega_simps)\n  have dom_rhs: \"\\<D>\\<^sub>\\<circ> (ntsmcf_tdghm (op_ntsmcf \\<NN>)) = 5\\<^sub>\\<nat>\"\n    unfolding ntsmcf_tdghm_def by (auto simp: nat_omega_simps)\n  show \"\\<D>\\<^sub>\\<circ> (op_tdghm (ntsmcf_tdghm \\<NN>)) = \\<D>\\<^sub>\\<circ> (ntsmcf_tdghm (op_ntsmcf \\<NN>))\"\n    unfolding dom_lhs dom_rhs by simp\n  show \"a \\<in>\\<^sub>\\<circ> \\<D>\\<^sub>\\<circ> (op_tdghm (ntsmcf_tdghm \\<NN>)) \\<Longrightarrow> \n    op_tdghm (ntsmcf_tdghm \\<NN>)\\<lparr>a\\<rparr> = ntsmcf_tdghm (op_ntsmcf \\<NN>)\\<lparr>a\\<rparr>\"\n    for a\n    by\n      (\n        unfold dom_lhs,\n        elim_in_numeral,\n        unfold ntsmcf_tdghm_def op_ntsmcf_def op_tdghm_def nt_field_simps\n      )\n      (auto simp: nat_omega_simps slicing_commute[symmetric])\nqed (auto simp: ntsmcf_tdghm_def op_tdghm_def)\n\n\nsubsubsection\\<open>Further properties\\<close>\n\nlemma (in is_ntsmcf) is_ntsmcf_op: \n  \"op_ntsmcf \\<NN> : op_smcf \\<GG> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F op_smcf \\<FF> : op_smc \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_smc \\<BB>\"\nproof(rule is_ntsmcfI, unfold smc_op_simps)\n  show \"vfsequence (op_ntsmcf \\<NN>)\" by (simp add: op_ntsmcf_def)\n  show \"vcard (op_ntsmcf \\<NN>) = 5\\<^sub>\\<nat>\" by (simp add: op_ntsmcf_def nat_omega_simps)\n  fix f a b assume \"f : b \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a\"\n  with is_ntsmcf_axioms show \n    \"\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr> \\<circ>\\<^sub>A\\<^bsub>op_smc \\<BB>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> =\n      \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> \\<circ>\\<^sub>A\\<^bsub>op_smc \\<BB>\\<^esub> \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\n    by (cs_concl cs_simp: smc_cs_simps smc_op_simps cs_intro: smc_cs_intros)\nqed\n  (\n    insert is_ntsmcf_axioms,\n    (\n      cs_concl cs_shallow \n        cs_simp: smc_cs_simps slicing_commute[symmetric]\n        cs_intro: smc_cs_intros smc_op_intros dg_op_intros slicing_intros\n    )+\n  )\n\nlemma (in is_ntsmcf) is_ntsmcf_op'[smc_op_intros]: \n  assumes \"\\<GG>' = op_smcf \\<GG>\"\n    and \"\\<FF>' = op_smcf \\<FF>\"\n    and \"\\<AA>' = op_smc \\<AA>\"\n    and \"\\<BB>' = op_smc \\<BB>\"\n  shows \"op_ntsmcf \\<NN> : \\<GG>' \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF>' : \\<AA>' \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>'\"\n  unfolding assms by (rule is_ntsmcf_op)\n\nlemmas [smc_op_intros] = is_ntsmcf.is_ntsmcf_op'\n\nlemma (in is_ntsmcf) ntsmcf_op_ntsmcf_op_ntsmcf[smc_op_simps]: \n  \"op_ntsmcf (op_ntsmcf \\<NN>) = \\<NN>\"\nproof(rule ntsmcf_eqI[of \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> _ \\<AA> \\<BB> \\<FF> \\<GG>], unfold smc_op_simps)\n  interpret op: \n    is_ntsmcf \\<alpha> \\<open>op_smc \\<AA>\\<close> \\<open>op_smc \\<BB>\\<close> \\<open>op_smcf \\<GG>\\<close> \\<open>op_smcf \\<FF>\\<close> \\<open>op_ntsmcf \\<NN>\\<close>\n    by (rule is_ntsmcf_op)\n  from op.is_ntsmcf_op show \n    \"op_ntsmcf (op_ntsmcf \\<NN>) : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (simp add: smc_op_simps)\nqed (auto simp: smc_cs_intros)\n\nlemmas ntsmcf_op_ntsmcf_op_ntsmcf[smc_op_simps] =\n  is_ntsmcf.ntsmcf_op_ntsmcf_op_ntsmcf\n\nlemma eq_op_ntsmcf_iff: \n  assumes \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\" \n    and \"\\<NN>' : \\<FF>' \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>' : \\<AA>' \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>'\"\n  shows \"op_ntsmcf \\<NN> = op_ntsmcf \\<NN>' \\<longleftrightarrow> \\<NN> = \\<NN>'\"\nproof\n  interpret L: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN> by (rule assms(1))\n  interpret R: is_ntsmcf \\<alpha> \\<AA>' \\<BB>' \\<FF>' \\<GG>' \\<NN>' by (rule assms(2))\n  assume prems: \"op_ntsmcf \\<NN> = op_ntsmcf \\<NN>'\"\n  show \"\\<NN> = \\<NN>'\"\n  proof(rule ntsmcf_eqI[OF assms])\n    from prems L.ntsmcf_op_ntsmcf_op_ntsmcf R.ntsmcf_op_ntsmcf_op_ntsmcf show \n      \"\\<NN>\\<lparr>NTMap\\<rparr> = \\<NN>'\\<lparr>NTMap\\<rparr>\"\n      by metis+\n    from prems L.ntsmcf_op_ntsmcf_op_ntsmcf R.ntsmcf_op_ntsmcf_op_ntsmcf \n    have \"\\<NN>\\<lparr>NTDom\\<rparr> = \\<NN>'\\<lparr>NTDom\\<rparr>\" \n      and \"\\<NN>\\<lparr>NTCod\\<rparr> = \\<NN>'\\<lparr>NTCod\\<rparr>\" \n      and \"\\<NN>\\<lparr>NTDGDom\\<rparr> = \\<NN>'\\<lparr>NTDGDom\\<rparr>\" \n      and \"\\<NN>\\<lparr>NTDGCod\\<rparr> = \\<NN>'\\<lparr>NTDGCod\\<rparr>\" \n      by metis+\n    then show \"\\<FF> = \\<FF>'\" \"\\<GG> = \\<GG>'\" \"\\<AA> = \\<AA>'\" \"\\<BB> = \\<BB>'\" by (auto simp: smc_cs_simps)\n  qed\nqed auto\n\n\n\nsubsection\\<open>Vertical composition of natural transformations\\<close>\n\n\nsubsubsection\\<open>Definition and elementary properties\\<close>\n\n\ntext\\<open>See Chapter II-4 in \\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>.\\<close>\n\ndefinition ntsmcf_vcomp :: \"V \\<Rightarrow> V \\<Rightarrow> V\" (infixl \\<open>\\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<close> 55)\n  where \"ntsmcf_vcomp \\<MM> \\<NN> = \n    [\n      (\\<lambda>a\\<in>\\<^sub>\\<circ>\\<NN>\\<lparr>NTDGDom\\<rparr>\\<lparr>Obj\\<rparr>. (\\<MM>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>) \\<circ>\\<^sub>A\\<^bsub>\\<NN>\\<lparr>NTDGCod\\<rparr>\\<^esub> (\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>)),\n      \\<NN>\\<lparr>NTDom\\<rparr>,\n      \\<MM>\\<lparr>NTCod\\<rparr>,\n      \\<NN>\\<lparr>NTDGDom\\<rparr>,\n      \\<MM>\\<lparr>NTDGCod\\<rparr>\n    ]\\<^sub>\\<circ>\"\n\n\ntext\\<open>Components.\\<close>\n\nlemma ntsmcf_vcomp_components:\n  shows\n    \"(\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr> =\n      (\\<lambda>a\\<in>\\<^sub>\\<circ>\\<NN>\\<lparr>NTDGDom\\<rparr>\\<lparr>Obj\\<rparr>. (\\<MM>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>) \\<circ>\\<^sub>A\\<^bsub>\\<NN>\\<lparr>NTDGCod\\<rparr>\\<^esub> (\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>))\"\n    and [dg_shared_cs_simps, smc_cs_simps]: \"(\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTDom\\<rparr> = \\<NN>\\<lparr>NTDom\\<rparr>\" \n    and [dg_shared_cs_simps, smc_cs_simps]: \"(\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTCod\\<rparr> = \\<MM>\\<lparr>NTCod\\<rparr>\"\n    and [dg_shared_cs_simps, smc_cs_simps]: \n      \"(\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTDGDom\\<rparr> = \\<NN>\\<lparr>NTDGDom\\<rparr>\"\n    and [dg_shared_cs_simps, smc_cs_simps]: \n      \"(\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTDGCod\\<rparr> = \\<MM>\\<lparr>NTDGCod\\<rparr>\"\n  unfolding nt_field_simps ntsmcf_vcomp_def by (simp_all add: nat_omega_simps)\n\n\nsubsubsection\\<open>Natural transformation map\\<close>\n\nlemma ntsmcf_vcomp_NTMap_vsv[dg_shared_cs_intros, smc_cs_intros]: \n  \"vsv ((\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>)\"\n  unfolding ntsmcf_vcomp_components by simp\n\nlemma ntsmcf_vcomp_NTMap_vdomain[smc_cs_simps]:\n  assumes \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"\\<D>\\<^sub>\\<circ> ((\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>) = \\<AA>\\<lparr>Obj\\<rparr>\"\nproof-\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN> using assms by auto\n  show ?thesis unfolding ntsmcf_vcomp_components by (simp add: smc_cs_simps)\nqed\n\nlemma ntsmcf_vcomp_NTMap_app[smc_cs_simps]:\n  assumes \"\\<MM> : \\<GG> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\" \n    and \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n  shows \"(\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> = \\<MM>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\nproof-\n  interpret \\<MM>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<GG> \\<HH> \\<MM> using assms by auto\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN> using assms by auto\n  from assms show ?thesis \n    unfolding ntsmcf_vcomp_components by (simp add: smc_cs_simps)\nqed\n\nlemma ntsmcf_vcomp_NTMap_vrange:\n  assumes \"\\<MM> : \\<GG> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\" \n    and \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"\\<R>\\<^sub>\\<circ> ((\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<BB>\\<lparr>Arr\\<rparr>\"\n  unfolding ntsmcf_vcomp_components\nproof(rule vrange_VLambda_vsubset)\n  fix x assume prems: \"x \\<in>\\<^sub>\\<circ> \\<NN>\\<lparr>NTDGDom\\<rparr>\\<lparr>Obj\\<rparr>\"\n  from prems assms show \"\\<MM>\\<lparr>NTMap\\<rparr>\\<lparr>x\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<NN>\\<lparr>NTDGCod\\<rparr>\\<^esub> \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>x\\<rparr> \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Arr\\<rparr>\"\n    by (cs_prems cs_shallow cs_simp: smc_cs_simps cs_intro: smc_cs_intros)\n      (cs_concl cs_shallow cs_simp: smc_cs_simps cs_intro: smc_cs_intros)\nqed\n\n\nsubsubsection\\<open>Further properties\\<close>\n\nlemma ntsmcf_vcomp_composable_commute[smc_cs_simps]:\n  \\<comment>\\<open>See Chapter II-4 in \\cite{mac_lane_categories_2010}).\\<close>\n  assumes \"\\<MM> : \\<GG> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"f : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b\"\n  shows \n    \"(\\<MM>\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr>) \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> = \n      \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> (\\<MM>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>)\"\n    (is \\<open>(?MC \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> ?NC) \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> ?R = ?T \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> (?MD \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> ?ND)\\<close>)\nproof-\n  interpret \\<MM>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<GG> \\<HH> \\<MM> by (rule assms(1)) \n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN> by (rule assms(2))\n  from assms show ?thesis\n    by (intro \\<MM>.NTDom.HomCod.smc_pattern_rectangle_left)\n      (cs_concl cs_intro: smc_cs_intros cs_simp: \\<NN>.ntsmcf_Comp_commute)\nqed \n\nlemma ntsmcf_vcomp_is_ntsmcf[smc_cs_intros]:\n  \\<comment>\\<open>See Chapter II-4 in \\cite{mac_lane_categories_2010}.\\<close>\n  assumes \"\\<MM> : \\<GG> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\nproof-\n  interpret \\<MM>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<GG> \\<HH> \\<MM> by (rule assms(1))\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN> by (rule assms(2))\n  show ?thesis \n  proof(intro is_ntsmcfI')\n    show \"vfsequence (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\" by (simp add: ntsmcf_vcomp_def)\n    show \"vcard (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>) = 5\\<^sub>\\<nat>\"\n      by (auto simp: nat_omega_simps ntsmcf_vcomp_def)\n    show \"vsv ((\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>)\"\n      unfolding ntsmcf_vcomp_components by simp\n    from assms show \"(\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n      if \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" for a\n      by \n        (\n          use that in \n            \\<open>cs_concl cs_shallow cs_simp: smc_cs_simps cs_intro: smc_cs_intros\\<close>\n        )\n    fix f a b assume \"f : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b\"\n    with assms show \n      \"(\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> =\n        \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\n      by \n        (\n          cs_concl  \n            cs_simp: smc_cs_simps is_ntsmcf.ntsmcf_Comp_commute' \n            cs_intro: smc_cs_intros\n        )\n  qed (use assms in \\<open>auto simp: smc_cs_simps ntsmcf_vcomp_NTMap_vrange\\<close>)\nqed\n\nlemma ntsmcf_vcomp_assoc[smc_cs_simps]: \n  \\<comment>\\<open>See Chapter II-4 in \\cite{mac_lane_categories_2010}.\\<close>\n  assumes \"\\<LL> : \\<HH> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\" \n    and \"\\<MM> : \\<GG> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"(\\<LL> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<MM>) \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN> = \\<LL> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\"\nproof-\n  interpret \\<LL>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<HH> \\<KK> \\<LL> by (rule assms(1))\n  interpret \\<MM>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<GG> \\<HH> \\<MM> by (rule assms(2))\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN> by (rule assms(3))\n  show ?thesis\n  proof(rule ntsmcf_eqI[of \\<alpha>])\n    show \"((\\<LL> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<MM>) \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr> = (\\<LL> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>))\\<lparr>NTMap\\<rparr>\"\n    proof(rule vsv_eqI)\n      fix a assume \"a \\<in>\\<^sub>\\<circ> \\<D>\\<^sub>\\<circ> ((\\<LL> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>)\"\n      then have \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n        unfolding ntsmcf_vcomp_components by (simp add: smc_cs_simps)\n      with assms show \n        \"((\\<LL> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<MM>) \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> =\n          (\\<LL> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>))\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\n        by (cs_concl cs_shallow cs_simp: smc_cs_simps cs_intro: smc_cs_intros)\n    qed (simp_all add: ntsmcf_vcomp_components)\n  qed (auto intro: smc_cs_intros)\nqed\n\n\nsubsubsection\\<open>\nOpposite of the vertical composition of natural transformations\nof semifunctors\n\\<close>\n\nlemma op_ntsmcf_ntsmcf_vcomp[smc_op_simps]: \n  assumes \"\\<MM> : \\<GG> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\" \n    and \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"op_ntsmcf (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>) = op_ntsmcf \\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F op_ntsmcf \\<MM>\"\nproof-\n  interpret \\<MM>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<GG> \\<HH> \\<MM> using assms(1) by auto\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN> using assms(2) by auto\n  show ?thesis\n  proof(rule ntsmcf_eqI[of \\<alpha>]; (intro symmetric)?)\n    show \"op_ntsmcf (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr> = \n      (op_ntsmcf \\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F op_ntsmcf \\<MM>)\\<lparr>NTMap\\<rparr>\"\n    proof(rule vsv_eqI)\n      fix a assume \"a \\<in>\\<^sub>\\<circ> \\<D>\\<^sub>\\<circ> (op_ntsmcf (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>)\"\n      then have a: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n        unfolding smc_op_simps ntsmcf_vcomp_NTMap_vdomain[OF assms(2)] by simp\n      with \n        \\<MM>.NTDom.HomCod.op_smc_Comp \n        \\<MM>.ntsmcf_NTMap_is_arr[OF a]\n        \\<NN>.ntsmcf_NTMap_is_arr[OF a] \n      show \"op_ntsmcf (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> =\n        (op_ntsmcf \\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F op_ntsmcf \\<MM>)\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\n        unfolding smc_op_simps ntsmcf_vcomp_components \n        by (simp add: smc_cs_simps)\n    qed (simp_all add: smc_op_simps smc_cs_simps ntsmcf_vcomp_components(1))\n  qed (auto intro: smc_cs_intros smc_op_intros)\nqed\n\n\n\nsubsection\\<open>Horizontal composition of natural transformations\\<close>\n\n\nsubsubsection\\<open>Definition and elementary properties\\<close>\n\n\ntext\\<open>See Chapter II-5 in \\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>.\\<close>\n\ndefinition ntsmcf_hcomp :: \"V \\<Rightarrow> V \\<Rightarrow> V\" (infixl \\<open>\\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<close> 55)\n  where \"ntsmcf_hcomp \\<MM> \\<NN> =\n    [\n      (\n        \\<lambda>a\\<in>\\<^sub>\\<circ>\\<NN>\\<lparr>NTDGDom\\<rparr>\\<lparr>Obj\\<rparr>.\n          (\n            \\<MM>\\<lparr>NTCod\\<rparr>\\<lparr>ArrMap\\<rparr>\\<lparr>\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<MM>\\<lparr>NTDGCod\\<rparr>\\<^esub> \n            \\<MM>\\<lparr>NTMap\\<rparr>\\<lparr>\\<NN>\\<lparr>NTDom\\<rparr>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\\<rparr>\n          )\n      ),\n      (\\<MM>\\<lparr>NTDom\\<rparr> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>\\<lparr>NTDom\\<rparr>),\n      (\\<MM>\\<lparr>NTCod\\<rparr> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>\\<lparr>NTCod\\<rparr>),\n      (\\<NN>\\<lparr>NTDGDom\\<rparr>),\n      (\\<MM>\\<lparr>NTDGCod\\<rparr>)\n    ]\\<^sub>\\<circ>\"\n\n\ntext\\<open>Components.\\<close>                                            \n\nlemma ntsmcf_hcomp_components:\n  shows \n    \"(\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr> = \n      (\n        \\<lambda>a\\<in>\\<^sub>\\<circ>\\<NN>\\<lparr>NTDGDom\\<rparr>\\<lparr>Obj\\<rparr>.\n          (\n            \\<MM>\\<lparr>NTCod\\<rparr>\\<lparr>ArrMap\\<rparr>\\<lparr>\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<MM>\\<lparr>NTDGCod\\<rparr>\\<^esub> \n            \\<MM>\\<lparr>NTMap\\<rparr>\\<lparr>\\<NN>\\<lparr>NTDom\\<rparr>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\\<rparr>\n          )\n      )\"\n    and [dg_shared_cs_simps, smc_cs_simps]:\n      \"(\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTDom\\<rparr> = \\<MM>\\<lparr>NTDom\\<rparr> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>\\<lparr>NTDom\\<rparr>\" \n    and [dg_shared_cs_simps, smc_cs_simps]:\n      \"(\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTCod\\<rparr> = \\<MM>\\<lparr>NTCod\\<rparr> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>\\<lparr>NTCod\\<rparr>\"\n    and [dg_shared_cs_simps, smc_cs_simps]: \n      \"(\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTDGDom\\<rparr> = \\<NN>\\<lparr>NTDGDom\\<rparr>\"\n    and [dg_shared_cs_simps, smc_cs_simps]:\n      \"(\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTDGCod\\<rparr> = \\<MM>\\<lparr>NTDGCod\\<rparr>\"\n  unfolding nt_field_simps ntsmcf_hcomp_def by (auto simp: nat_omega_simps)\n\n\nsubsubsection\\<open>Natural transformation map\\<close>\n\nlemma ntsmcf_hcomp_NTMap_vsv[smc_cs_intros]: \"vsv ((\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>)\"\n  unfolding ntsmcf_hcomp_components by auto\n\nlemma ntsmcf_hcomp_NTMap_vdomain[smc_cs_simps]: \n  assumes \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"\\<D>\\<^sub>\\<circ> ((\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>) = \\<AA>\\<lparr>Obj\\<rparr>\"\nproof-\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN> by (rule assms(1))\n  show ?thesis unfolding ntsmcf_hcomp_components by (simp add: smc_cs_simps)\nqed\n\nlemma ntsmcf_hcomp_NTMap_app[smc_cs_simps]:\n  assumes \"\\<MM> : \\<FF>' \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>' : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n  shows \"(\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> = \n    \\<GG>'\\<lparr>ArrMap\\<rparr>\\<lparr>\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<MM>\\<lparr>NTMap\\<rparr>\\<lparr>\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\\<rparr>\"\nproof-\n  interpret \\<MM>: is_ntsmcf \\<alpha> \\<BB> \\<CC> \\<FF>' \\<GG>' \\<MM> by (rule assms(1))\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN> by (rule assms(2))\n  from assms(3) show ?thesis \n    unfolding ntsmcf_hcomp_components by (simp add: smc_cs_simps)\nqed\n\nlemma ntsmcf_hcomp_NTMap_vrange:\n  assumes \"\\<MM> : \\<FF>' \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>' : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \n    and \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"\\<R>\\<^sub>\\<circ> ((\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<CC>\\<lparr>Arr\\<rparr>\"\nproof\n  interpret \\<MM>: is_ntsmcf \\<alpha> \\<BB> \\<CC> \\<FF>' \\<GG>' \\<MM> by (rule assms(1))\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN> by (rule assms(2))\n  fix f assume \"f \\<in>\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> ((\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>)\"\n  with ntsmcf_hcomp_NTMap_vdomain obtain a \n    where a: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" and f_def: \"f = (\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\n    unfolding ntsmcf_hcomp_components by (force simp: smc_cs_simps)\n  have \\<FF>a: \"\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" \n    by (simp add: \\<NN>.NTDom.smcf_ObjMap_app_in_HomCod_Obj a)\n  from \\<NN>.ntsmcf_NTMap_is_arr[OF a] have \"\\<GG>'\\<lparr>ArrMap\\<rparr>\\<lparr>\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\\<rparr> :\n    \\<GG>'\\<lparr>ObjMap\\<rparr>\\<lparr>\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<GG>'\\<lparr>ObjMap\\<rparr>\\<lparr>\\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\\<rparr>\"\n    by (force intro: smc_cs_intros)\n  then have \"\\<GG>'\\<lparr>ArrMap\\<rparr>\\<lparr>\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<MM>\\<lparr>NTMap\\<rparr>\\<lparr>\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\\<rparr> \\<in>\\<^sub>\\<circ> \\<CC>\\<lparr>Arr\\<rparr>\"\n    by \n      (\n        meson \n          \\<MM>.ntsmcf_NTMap_is_arr[OF \\<FF>a] \n          \\<MM>.NTDom.HomCod.smc_is_arrE \n          \\<MM>.NTDom.HomCod.smc_Comp_is_arr\n      )\n  with a show \"f \\<in>\\<^sub>\\<circ> \\<CC>\\<lparr>Arr\\<rparr>\" \n    unfolding f_def ntsmcf_hcomp_components by (simp add: smc_cs_simps)\nqed\n\n\nsubsubsection\\<open>Further properties\\<close>\n\nlemma ntsmcf_hcomp_composable_commute:\n  \\<comment>\\<open>See Chapter II-5 in \\cite{mac_lane_categories_2010}.\\<close>\n  assumes \"\\<MM> : \\<FF>' \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>' : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"f : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b\" \n  shows \n    \"(\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> (\\<FF>' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> = \n      (\\<GG>' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>)\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> (\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\nproof-\n  interpret \\<MM>: is_ntsmcf \\<alpha> \\<BB> \\<CC> \\<FF>' \\<GG>' \\<MM> by (rule assms(1))\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN> by (rule assms(2))\n  from assms(3) have [simp]: \"b \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" and a: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" by auto\n  from \\<MM>.is_ntsmcf_axioms \\<NN>.is_ntsmcf_axioms have \\<MM>\\<NN>b: \n    \"(\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr> =\n      (\\<GG>'\\<lparr>ArrMap\\<rparr>\\<lparr>\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr>\\<rparr>) \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> (\\<MM>\\<lparr>NTMap\\<rparr>\\<lparr>\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\\<rparr>)\"\n    by (auto simp: smc_cs_simps)\n  let ?\\<GG>'\\<FF>f = \\<open>\\<GG>'\\<lparr>ArrMap\\<rparr>\\<lparr>\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr>\\<rparr>\\<close>\n  from a \\<MM>.is_ntsmcf_axioms \\<NN>.is_ntsmcf_axioms have \\<MM>\\<NN>a: \n    \"(\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> =\n      \\<GG>'\\<lparr>ArrMap\\<rparr>\\<lparr>\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<MM>\\<lparr>NTMap\\<rparr>\\<lparr>\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: smc_cs_simps)+\n  note \\<MM>.NTCod.smcf_ArrMap_Comp[smc_cs_simps del]\n  from assms show ?thesis\n    unfolding \\<MM>\\<NN>b \\<MM>\\<NN>a \n    by (intro \\<MM>.NTDom.HomCod.smc_pattern_rectangle_left)\n      (\n        cs_concl  \n          cs_simp: smc_cs_simps is_semifunctor.smcf_ArrMap_Comp[symmetric] \n          cs_intro: smc_cs_intros\n      )+\nqed\n\nlemma ntsmcf_hcomp_is_ntsmcf:\n  \\<comment>\\<open>See Chapter II-5 in \\cite{mac_lane_categories_2010}.\\<close>\n  assumes \"\\<MM> : \\<FF>' \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>' : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \n    and \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN> : \\<FF>' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\nproof-\n  interpret \\<MM>: is_ntsmcf \\<alpha> \\<BB> \\<CC> \\<FF>' \\<GG>' \\<MM> by (rule assms(1))\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN> by (rule assms(2))\n  show ?thesis\n  proof(intro is_ntsmcfI', unfold ntsmcf_hcomp_components(3,4)) \n    show \"vfsequence (\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\" unfolding ntsmcf_hcomp_def by auto\n    show \"vcard (\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>) = 5\\<^sub>\\<nat>\"\n      unfolding ntsmcf_hcomp_def by (simp add: nat_omega_simps)\n    from assms show \"(\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> : \n      (\\<FF>' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> (\\<GG>' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>)\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n      if \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" for a\n      by \n        (\n          use that in \n            \\<open>cs_concl cs_shallow cs_simp: smc_cs_simps cs_intro: smc_cs_intros\\<close>\n        )\n    fix f a b assume \"f : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b\"\n    with ntsmcf_hcomp_composable_commute[OF assms] \n    show \"(\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> (\\<FF>' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> = \n      (\\<GG>' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>)\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> (\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\n      by auto\n  qed (auto simp: ntsmcf_hcomp_components(1) smc_cs_simps intro: smc_cs_intros)\nqed\n\nlemma ntsmcf_hcomp_is_ntsmcf'[smc_cs_intros]:\n  assumes \"\\<MM> : \\<FF>' \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>' : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \n    and \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"\\<SS> = \\<FF>' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF>\"\n    and \"\\<SS>' = \\<GG>' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>\"\n  shows \"\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN> : \\<SS> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<SS>' : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  using assms(1,2) unfolding assms(3,4) by (rule ntsmcf_hcomp_is_ntsmcf)\n\nlemma ntsmcf_hcomp_assoc[smc_cs_simps]: \n  \\<comment>\\<open>See Chapter II-5 in \\cite{mac_lane_categories_2010}.\\<close>\n  assumes \"\\<LL> : \\<FF>'' \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>'' : \\<CC> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<DD>\" \n    and \"\\<MM> : \\<FF>' \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>' : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"(\\<LL> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<MM>) \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN> = \\<LL> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\"\nproof-\n  interpret \\<LL>: is_ntsmcf \\<alpha> \\<CC> \\<DD> \\<FF>'' \\<GG>'' \\<LL> by (rule assms(1))\n  interpret \\<MM>: is_ntsmcf \\<alpha> \\<BB> \\<CC> \\<FF>' \\<GG>' \\<MM>  by (rule assms(2))\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN> by (rule assms(3))\n  interpret \\<LL>\\<MM>: is_ntsmcf \\<alpha> \\<BB> \\<DD> \\<open>\\<FF>'' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF>'\\<close> \\<open>\\<GG>'' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>'\\<close> \\<open>\\<LL> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<MM>\\<close> \n    by (auto intro: smc_cs_intros)\n  interpret \\<MM>\\<NN>: is_ntsmcf \\<alpha> \\<AA> \\<CC> \\<open>\\<FF>' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF>\\<close> \\<open>\\<GG>' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>\\<close> \\<open>\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>\\<close> \n    by (auto intro: smc_cs_intros)\n  note smcf_axioms =\n    \\<LL>.NTDom.is_semifunctor_axioms \n    \\<LL>.NTCod.is_semifunctor_axioms \n    \\<MM>.NTDom.is_semifunctor_axioms \n    \\<MM>.NTCod.is_semifunctor_axioms \n    \\<NN>.NTDom.is_semifunctor_axioms \n    \\<NN>.NTCod.is_semifunctor_axioms \n  show ?thesis\n  proof(rule ntsmcf_eqI)\n    from assms show \n      \"\\<LL> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN> :\n        (\\<FF>'' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF>') \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<GG>'' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>') \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> :\n        \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<DD>\"\n      by (auto intro: smc_cs_intros)\n    from \\<LL>\\<MM>.is_ntsmcf_axioms \\<NN>.is_ntsmcf_axioms have dom_lhs:\n      \"\\<D>\\<^sub>\\<circ> ((\\<LL> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>) = \\<AA>\\<lparr>Obj\\<rparr>\"\n      by (simp add: smc_cs_simps)\n    from \\<MM>\\<NN>.is_ntsmcf_axioms \\<LL>.is_ntsmcf_axioms have dom_rhs:  \n      \"\\<D>\\<^sub>\\<circ> ((\\<LL> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>))\\<lparr>NTMap\\<rparr>) = \\<AA>\\<lparr>Obj\\<rparr>\"\n      by (simp add: smc_cs_simps)\n    show \"(\\<LL> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr> = (\\<LL> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>))\\<lparr>NTMap\\<rparr>\"\n    proof(rule vsv_eqI, unfold dom_lhs dom_rhs)\n      fix a assume \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n      with assms show\n        \"(\\<LL> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> =\n          (\\<LL> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>))\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\n        by (cs_concl cs_shallow cs_simp: smc_cs_simps cs_intro: smc_cs_intros)\n    qed (simp_all add: ntsmcf_hcomp_components)\n  qed \n    (\n      insert smcf_axioms, \n      auto simp: smcf_comp_assoc intro!: smc_cs_intros\n    )\nqed\n\n\nsubsubsection\\<open>Opposite of the horizontal composition of the \nnatural transformation of semifunctors\\<close>\n\nlemma op_ntsmcf_ntsmcf_hcomp[smc_op_simps]: \n  assumes \"\\<MM> : \\<FF>' \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>' : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"op_ntsmcf (\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>) = op_ntsmcf \\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F op_ntsmcf \\<NN>\"\nproof-\n  interpret \\<MM>: is_ntsmcf \\<alpha> \\<BB> \\<CC> \\<FF>' \\<GG>' \\<MM> by (rule assms(1))\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN> by (rule assms(2))\n  have op_\\<MM>: \"op_ntsmcf \\<MM> :\n    op_smcf \\<GG>' \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F op_smcf \\<FF>' : op_smc \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_smc \\<CC>\"\n    and op_\\<NN>: \"op_ntsmcf \\<NN> :\n    op_smcf \\<GG> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F op_smcf \\<FF> : op_smc \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_smc \\<BB>\" \n    by \n      (\n        cs_concl cs_shallow \n          cs_simp: smc_op_simps cs_intro: smc_cs_intros smc_op_intros\n      )\n  show ?thesis\n  proof(rule sym, rule ntsmcf_eqI, unfold smc_op_simps slicing_simps)\n    show \n      \"op_ntsmcf \\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F op_ntsmcf \\<NN> :\n        op_smcf \\<GG>' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F op_smcf \\<GG> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F op_smcf \\<FF>' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F op_smcf \\<FF> :\n        op_smc \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_smc \\<CC>\"\n      by \n        (\n          cs_concl cs_shallow \n            cs_simp: smc_op_simps cs_intro: smc_cs_intros smc_op_intros\n        )\n    show \"op_ntsmcf (\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>) :\n      op_smcf \\<GG>' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F op_smcf \\<GG> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F op_smcf \\<FF>' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F op_smcf \\<FF> :\n      op_smc \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_smc \\<CC>\"\n      by \n        (\n          cs_concl cs_shallow \n            cs_simp: smc_op_simps cs_intro: smc_cs_intros smc_op_intros\n        )\n    show \"(op_ntsmcf \\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F op_ntsmcf \\<NN>)\\<lparr>NTMap\\<rparr> = (\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>\"\n    proof\n      (\n        rule vsv_eqI, \n        unfold \n          ntsmcf_hcomp_NTMap_vdomain[OF assms(2)]\n          ntsmcf_hcomp_NTMap_vdomain[OF op_\\<NN>]\n          smc_op_simps\n      )\n      fix a assume \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n      with assms show \n        \"(op_ntsmcf \\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F op_ntsmcf \\<NN>)\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> = (\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\n        by \n          (\n            cs_concl cs_shallow\n              cs_simp: smc_cs_simps smc_op_simps \n              cs_intro: smc_cs_intros smc_op_intros\n          )\n    qed (auto simp: ntsmcf_hcomp_components)\n  qed simp_all\nqed \n\n\n\nsubsection\\<open>Interchange law\\<close>\n\nlemma ntsmcf_comp_interchange_law:\n  \\<comment>\\<open>See Chapter II-5 in \\cite{mac_lane_categories_2010}.\\<close>\n  assumes \"\\<MM> : \\<GG> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"\\<MM>' : \\<GG>' \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>' : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<NN>' : \\<FF>' \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>' : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \n    \"((\\<MM>' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>') \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)) =\n      (\\<MM>' \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<MM>) \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<NN>' \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\"\nproof-\n  interpret \\<MM>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<GG> \\<HH> \\<MM> by (rule assms(1))\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN> by (rule assms(2))\n  interpret \\<MM>': is_ntsmcf \\<alpha> \\<BB> \\<CC> \\<GG>' \\<HH>' \\<MM>' by (rule assms(3))\n  interpret \\<NN>': is_ntsmcf \\<alpha> \\<BB> \\<CC> \\<FF>' \\<GG>' \\<NN>' by (rule assms(4))\n  interpret \\<NN>'\\<NN>: \n    is_ntsmcf \\<alpha> \\<AA> \\<CC> \\<open>\\<FF>' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF>\\<close> \\<open>\\<GG>' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>\\<close> \\<open>\\<NN>' \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>\\<close> \n    by (auto intro: smc_cs_intros)\n  interpret \\<MM>\\<NN>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<HH> \\<open>\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>\\<close> \n    by (auto intro: smc_cs_intros)\n  show ?thesis\n  proof(rule ntsmcf_eqI[of \\<alpha>])\n    show \n      \"(\\<MM>' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>' \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>))\\<lparr>NTMap\\<rparr> =\n        (\\<MM>' \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<NN>' \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>))\\<lparr>NTMap\\<rparr>\"\n    proof\n      (\n        rule vsv_eqI,\n        unfold \n          ntsmcf_vcomp_NTMap_vdomain[OF \\<NN>'\\<NN>.is_ntsmcf_axioms]\n          ntsmcf_hcomp_NTMap_vdomain[OF \\<MM>\\<NN>.is_ntsmcf_axioms]\n      )\n      fix a assume \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n      with assms show\n        \"(\\<MM>' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>' \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>))\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> =\n          ((\\<MM>' \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<MM>) \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<NN>' \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>))\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\n        by\n          (\n            cs_concl \n              cs_simp: smc_cs_simps is_ntsmcf.ntsmcf_Comp_commute' \n              cs_intro: smc_cs_intros\n          )\n    qed (auto intro: smc_cs_intros)\n  qed (auto intro: smc_cs_intros)\nqed\n\n\n\nsubsection\\<open>\nComposition of a natural transformation of semifunctors and a semifunctor\n\\<close>\n\n\nsubsubsection\\<open>Definition and elementary properties\\<close>\n\nabbreviation (input) ntsmcf_smcf_comp :: \"V \\<Rightarrow> V \\<Rightarrow> V\" (infixl \"\\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\" 55)\n  where \"ntsmcf_smcf_comp \\<equiv> tdghm_dghm_comp\"\n\n\ntext\\<open>Slicing.\\<close>\n\nlemma ntsmcf_tdghm_ntsmcf_smcf_comp[slicing_commute]: \n  \"ntsmcf_tdghm \\<NN> \\<circ>\\<^sub>T\\<^sub>D\\<^sub>G\\<^sub>H\\<^sub>M\\<^sub>-\\<^sub>D\\<^sub>G\\<^sub>H\\<^sub>M smcf_dghm \\<HH> = ntsmcf_tdghm (\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>)\"\n  unfolding \n    tdghm_dghm_comp_def \n    dghm_comp_def \n    ntsmcf_tdghm_def \n    smcf_dghm_def \n    smc_dg_def\n    dg_field_simps\n    dghm_field_simps \n    nt_field_simps \n  by (simp add: nat_omega_simps) (*slow*)\n\n\nsubsubsection\\<open>Natural transformation map\\<close>\n\nmk_VLambda (in is_semifunctor) \n  tdghm_dghm_comp_components(1)[where \\<HH>=\\<FF>, unfolded smcf_HomDom]\n  |vdomain ntsmcf_smcf_comp_NTMap_vdomain[smc_cs_simps]|\n  |app ntsmcf_smcf_comp_NTMap_app[smc_cs_simps]|\n\nlemmas [smc_cs_simps] = \n  is_semifunctor.ntsmcf_smcf_comp_NTMap_vdomain\n  is_semifunctor.ntsmcf_smcf_comp_NTMap_app\n\nlemma ntsmcf_smcf_comp_NTMap_vrange: \n  assumes \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"\\<R>\\<^sub>\\<circ> ((\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>NTMap\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<CC>\\<lparr>Arr\\<rparr>\"\nproof-\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<BB> \\<CC> \\<FF> \\<GG> \\<NN> by (rule assms(1))\n  interpret \\<HH>: is_semifunctor \\<alpha> \\<AA> \\<BB> \\<HH> by (rule assms(2))\n  show ?thesis \n    unfolding tdghm_dghm_comp_components \n    by (auto simp: smc_cs_simps intro: smc_cs_intros)\nqed\n\n\nsubsubsection\\<open>\nOpposite of the composition of a natural transformation of \nsemifunctors and a semifunctor\n\\<close>\n\nlemma op_ntsmcf_ntsmcf_smcf_comp[smc_op_simps]: \n  \"op_ntsmcf (\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>) = op_ntsmcf \\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F op_smcf \\<HH>\"\n  unfolding \n    tdghm_dghm_comp_def \n    dghm_comp_def \n    op_ntsmcf_def \n    op_smcf_def \n    op_smc_def\n    dg_field_simps\n    dghm_field_simps\n    nt_field_simps\n  by (simp add: nat_omega_simps) (*slow*)\n\n\nsubsubsection\\<open>\nComposition of a natural transformation of semifunctors and a \nsemifunctors is a natural transformation of semifunctors\n\\<close>\n\nlemma ntsmcf_smcf_comp_is_ntsmcf[intro]:\n  assumes \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> : \\<FF> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\nproof-\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<BB> \\<CC> \\<FF> \\<GG> \\<NN> by (rule assms(1))\n  interpret \\<HH>: is_semifunctor \\<alpha> \\<AA> \\<BB> \\<HH> by (rule assms(2))\n  show ?thesis\n  proof(rule is_ntsmcfI)\n    show \"vfsequence (\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>)\"\n      unfolding tdghm_dghm_comp_def by (simp add: nat_omega_simps)\n    from assms show \"\\<FF> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n      by (cs_concl cs_intro: smc_cs_intros)\n    from assms show \"\\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \n      by (cs_concl cs_intro: smc_cs_intros)\n    show \"vcard (\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>) = 5\\<^sub>\\<nat>\"\n      unfolding tdghm_dghm_comp_def by (simp add: nat_omega_simps)\n    from assms show \n      \"ntsmcf_tdghm (\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>) :\n        smcf_dghm (\\<FF> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>) \\<mapsto>\\<^sub>D\\<^sub>G\\<^sub>H\\<^sub>M smcf_dghm (\\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>) :\n        smc_dg \\<AA> \\<mapsto>\\<mapsto>\\<^sub>D\\<^sub>G\\<^bsub>\\<alpha>\\<^esub> smc_dg \\<CC>\"\n      by \n        (\n          cs_concl \n            cs_simp: slicing_commute[symmetric] \n            cs_intro: slicing_intros dg_cs_intros\n        )\n    show \n      \"(\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> (\\<FF> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> =\n        (\\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> (\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\n      if \"f : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b\" for a b f\n      using that by (cs_concl cs_simp: smc_cs_simps cs_intro: smc_cs_intros)\n  qed (auto simp: smc_cs_simps)\nqed\n\nlemma ntsmcf_smcf_comp_is_semifunctor'[smc_cs_intros]:\n  assumes \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \n    and \"\\<HH> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"\\<FF>' = \\<FF> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>\"\n    and \"\\<GG>' = \\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>\"\n  shows \"\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> : \\<FF>' \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>' : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  using assms(1,2) unfolding assms(3,4) ..\n\n\nsubsubsection\\<open>Further properties\\<close>\n\nlemma ntsmcf_smcf_comp_ntsmcf_smcf_comp_assoc:\n  assumes \"\\<NN> : \\<HH> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>' : \\<CC> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<DD>\" \n    and \"\\<GG> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \n    and \"\\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"(\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>) \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF> = \\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF>)\"\nproof-\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<CC> \\<DD> \\<HH> \\<HH>' \\<NN> by (rule assms(1))\n  interpret \\<GG>: is_semifunctor \\<alpha> \\<BB> \\<CC> \\<GG> by (rule assms(2))\n  interpret \\<FF>: is_semifunctor \\<alpha> \\<AA> \\<BB> \\<FF> by (rule assms(3))\n  show ?thesis  \n  proof(rule ntsmcf_tdghm_eqI)\n    from assms show \n      \"(\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>) \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF> :\n        \\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF> :\n        \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<DD>\"\n      by (cs_concl cs_shallow cs_simp: smc_cs_simps cs_intro: smc_cs_intros)\n    show \"\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF>) :\n      \\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>' \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF> :\n      \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<DD>\"\n      by (cs_concl cs_simp: smc_cs_simps cs_intro: smc_cs_intros)\n    from assms show \n      \"ntsmcf_tdghm ((\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>) \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF>) =\n        ntsmcf_tdghm (\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF>))\"\n      by \n        (\n          cs_concl \n            cs_simp: slicing_commute[symmetric] \n            cs_intro: slicing_intros tdghm_dghm_comp_tdghm_dghm_comp_assoc\n        )\n  qed simp_all\nqed\n\nlemma (in is_ntsmcf) ntsmcf_ntsmcf_smcf_comp_smcf_id[smc_cs_simps]:\n  \"\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F smcf_id \\<AA> = \\<NN>\"\nproof(rule ntsmcf_tdghm_eqI)\n  show \"\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F smcf_id \\<AA> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_simp: smc_cs_simps cs_intro: smc_cs_intros)\n  show \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_shallow cs_simp: smc_cs_simps cs_intro: smc_cs_intros)\n  show \"ntsmcf_tdghm (\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F smcf_id \\<AA>) = ntsmcf_tdghm \\<NN>\"\n    by \n      (\n        cs_concl cs_shallow\n          cs_simp: slicing_simps slicing_commute[symmetric] \n          cs_intro: smc_cs_intros slicing_intros dg_cs_simps\n      )\nqed simp_all\n\nlemmas [smc_cs_simps] = is_ntsmcf.ntsmcf_ntsmcf_smcf_comp_smcf_id\n\nlemma ntsmcf_vcomp_ntsmcf_smcf_comp[smc_cs_simps]:\n  assumes \"\\<KK> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"\\<MM> : \\<GG> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \n    \"(\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK>) \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK>) = \n      (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>) \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK>\"\nproof(rule ntsmcf_eqI)\n  from assms show \"(\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>) \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK> : \n    \\<FF> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    by (cs_concl cs_shallow cs_intro: smc_cs_intros)\n  from assms show \"\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK>) : \n    \\<FF> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    by (cs_concl cs_shallow cs_intro: smc_cs_intros)\n  from assms have dom_lhs: \n    \"\\<D>\\<^sub>\\<circ> ((\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK>))\\<lparr>NTMap\\<rparr>) = \\<AA>\\<lparr>Obj\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: smc_cs_simps cs_intro: smc_cs_intros)\n  from assms have dom_rhs: \"\\<D>\\<^sub>\\<circ> ((\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK>)\\<lparr>NTMap\\<rparr>) = \\<AA>\\<lparr>Obj\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: smc_cs_simps cs_intro: smc_cs_intros)\n  show \n    \"(\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK>))\\<lparr>NTMap\\<rparr> = \n      (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK>)\\<lparr>NTMap\\<rparr>\"\n  proof(rule vsv_eqI, unfold dom_lhs dom_rhs)\n    fix a assume \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n    with assms show \n      \"(\\<MM> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK>))\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> =\n        (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK>)\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\n      by (cs_concl cs_shallow cs_simp: smc_cs_simps cs_intro: smc_cs_intros)\n  qed (cs_concl cs_shallow cs_intro: smc_cs_intros)+\nqed simp_all\n\n\n\nsubsection\\<open>\nComposition of a semifunctor and a natural transformation of semifunctors\n\\<close>\n\n\nsubsubsection\\<open>Definition and elementary properties\\<close>\n\nabbreviation (input) smcf_ntsmcf_comp :: \"V \\<Rightarrow> V \\<Rightarrow> V\" (infixl \"\\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\" 55)\n  where \"smcf_ntsmcf_comp \\<equiv> dghm_tdghm_comp\"\n\n\ntext\\<open>Slicing.\\<close>\n\nlemma ntsmcf_tdghm_smcf_ntsmcf_comp[slicing_commute]: \n  \"smcf_dghm \\<HH> \\<circ>\\<^sub>D\\<^sub>G\\<^sub>H\\<^sub>M\\<^sub>-\\<^sub>T\\<^sub>D\\<^sub>G\\<^sub>H\\<^sub>M ntsmcf_tdghm \\<NN> = ntsmcf_tdghm (\\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\"\n  unfolding \n    dghm_tdghm_comp_def \n    dghm_comp_def \n    ntsmcf_tdghm_def \n    smcf_dghm_def \n    smc_dg_def\n    dg_field_simps\n    dghm_field_simps \n    nt_field_simps \n  by (simp add: nat_omega_simps) (*slow*)\n\n\nsubsubsection\\<open>Natural transformation map\\<close>\n\nmk_VLambda (in is_ntsmcf) \n  dghm_tdghm_comp_components(1)[where \\<NN>=\\<NN>, unfolded ntsmcf_NTDGDom]\n  |vdomain smcf_ntsmcf_comp_NTMap_vdomain[smc_cs_simps]|\n  |app smcf_ntsmcf_comp_NTMap_app[smc_cs_simps]|\n\nlemmas [smc_cs_simps] = \n  is_ntsmcf.smcf_ntsmcf_comp_NTMap_vdomain\n  is_ntsmcf.smcf_ntsmcf_comp_NTMap_app\n\nlemma smcf_ntsmcf_comp_NTMap_vrange: \n  assumes \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"\\<R>\\<^sub>\\<circ> ((\\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<CC>\\<lparr>Arr\\<rparr>\"\nproof-\n  interpret \\<HH>: is_semifunctor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule assms(1))\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN> by (rule assms(2))\n  show ?thesis \n    unfolding dghm_tdghm_comp_components \n    by (auto simp: smc_cs_simps intro: smc_cs_intros)\nqed\n\n\nsubsubsection\\<open>\nOpposite of the composition of a semifunctor\nand a natural transformation of semifunctors \n\\<close>\n\nlemma op_ntsmcf_smcf_ntsmcf_comp[smc_op_simps]: \n  \"op_ntsmcf (\\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>) = op_smcf \\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F op_ntsmcf \\<NN>\"\n  unfolding \n    dghm_tdghm_comp_def\n    dghm_comp_def\n    op_ntsmcf_def\n    op_smcf_def\n    op_smc_def\n    dg_field_simps\n    dghm_field_simps\n    nt_field_simps\n  by (simp add: nat_omega_simps) (*slow*)\n\n\nsubsubsection\\<open>\nComposition of a semifunctor and a natural transformation of\nsemifunctors is a natural transformation of semifunctors\n\\<close>\n\nlemma smcf_ntsmcf_comp_is_ntsmcf[intro]:\n  assumes \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"\\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN> : \\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\nproof-\n  interpret \\<HH>: is_semifunctor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule assms(1))\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN> by (rule assms(2))\n  show ?thesis\n  proof(rule is_ntsmcfI)\n    show \"vfsequence (\\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\" unfolding dghm_tdghm_comp_def by simp\n    from assms show \"\\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n      by (cs_concl cs_intro: smc_cs_intros)\n    from assms show \"\\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n      by (cs_concl cs_intro: smc_cs_intros)\n    show \"vcard (\\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>) = 5\\<^sub>\\<nat>\"\n      unfolding dghm_tdghm_comp_def by (simp add: nat_omega_simps)\n    from assms show \"ntsmcf_tdghm (\\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>) :\n      smcf_dghm (\\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF>) \\<mapsto>\\<^sub>D\\<^sub>G\\<^sub>H\\<^sub>M smcf_dghm (\\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>) :\n      smc_dg \\<AA> \\<mapsto>\\<mapsto>\\<^sub>D\\<^sub>G\\<^bsub>\\<alpha>\\<^esub> smc_dg \\<CC>\"\n      by \n        (\n          cs_concl  \n            cs_simp: slicing_commute[symmetric]  \n            cs_intro: dg_cs_intros slicing_intros\n        )\n    have [smc_cs_simps]:  \n      \"\\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr>\\<rparr> =\n        \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>\\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>\\<NN>\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\\<rparr>\"\n      if \"f : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b\" for a b f\n      using assms that \n      by \n        (\n          cs_concl  \n            cs_simp:\n              is_ntsmcf.ntsmcf_Comp_commute \n              is_semifunctor.smcf_ArrMap_Comp[symmetric]\n            cs_intro: smc_cs_intros\n        )\n    from assms show \n      \"(\\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> (\\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> =\n        (\\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>)\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> (\\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\n      if \"f : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b\" for a b f\n      using assms that\n      by (cs_concl cs_simp: smc_cs_simps cs_intro: smc_cs_intros)\n  qed (auto simp: smc_cs_simps)\nqed\n\nlemma smcf_ntsmcf_comp_is_semifunctor'[smc_cs_intros]:\n  assumes \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"\\<FF>' = \\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF>\"\n    and \"\\<GG>' = \\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>\"\n  shows \"\\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN> : \\<FF>' \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG>' : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  using assms(1,2) unfolding assms(3,4) ..\n\n\nsubsubsection\\<open>Further properties\\<close>\n\nlemma smcf_comp_smcf_ntsmcf_comp_assoc:\n  assumes \"\\<NN> : \\<HH> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>' : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"\\<FF> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<GG> : \\<CC> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<DD>\"\n  shows \"(\\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF>) \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN> = \\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<FF> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\"\nproof(rule ntsmcf_tdghm_eqI)\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<HH> \\<HH>' \\<NN> by (rule assms(1))\n  interpret \\<FF>: is_semifunctor \\<alpha> \\<BB> \\<CC> \\<FF> by (rule assms(2))\n  interpret \\<GG>: is_semifunctor \\<alpha> \\<CC> \\<DD> \\<GG> by (rule assms(3))\n  from assms show \"(\\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF>) \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN> :\n    \\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>' : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<DD>\"\n    by (cs_concl cs_simp: smc_cs_simps cs_intro: smc_cs_intros)\n  from assms show \"\\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<FF> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>) :\n    \\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH>' : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<DD>\"\n    by (cs_concl cs_shallow cs_simp: smc_cs_simps cs_intro: smc_cs_intros)\n  from assms show \n    \"ntsmcf_tdghm (\\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<FF> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>) =\n      ntsmcf_tdghm (\\<GG> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<FF> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>))\"\n    by\n      (\n        cs_concl \n          cs_simp: slicing_commute[symmetric] \n          cs_intro: slicing_intros dghm_comp_dghm_tdghm_comp_assoc\n      )\nqed simp_all\n\nlemma (in is_ntsmcf) ntsmcf_smcf_ntsmcf_comp_smcf_id[smc_cs_simps]:\n  \"smcf_id \\<BB> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN> = \\<NN>\"\nproof(rule ntsmcf_tdghm_eqI)\n  show \"smcf_id \\<BB> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_simp: smc_cs_simps cs_intro: smc_cs_intros)\n  show \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_simp: smc_cs_simps cs_intro: smc_cs_intros)\n  show \"ntsmcf_tdghm (dghm_id \\<BB> \\<circ>\\<^sub>D\\<^sub>G\\<^sub>H\\<^sub>M\\<^sub>-\\<^sub>T\\<^sub>D\\<^sub>G\\<^sub>H\\<^sub>M \\<NN>) = ntsmcf_tdghm \\<NN>\"\n    by \n      (\n        cs_concl cs_shallow\n          cs_simp: slicing_simps slicing_commute[symmetric] \n          cs_intro: smc_cs_intros slicing_intros dg_cs_simps\n      )\nqed simp_all\n\nlemmas [smc_cs_simps] = is_ntsmcf.ntsmcf_smcf_ntsmcf_comp_smcf_id\n\nlemma smcf_ntsmcf_comp_ntsmcf_smcf_comp_assoc:\n  assumes \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<HH> : \\<CC> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<DD>\"\n    and \"\\<KK> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"(\\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>) \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK> = \\<HH> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<NN> \\<circ>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<KK>)\"\nproof-\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<BB> \\<CC> \\<FF> \\<GG> \\<NN> by (rule assms(1))\n  interpret \\<HH>: is_semifunctor \\<alpha> \\<CC> \\<DD> \\<HH> by (rule assms(2))\n  interpret \\<KK>: is_semifunctor \\<alpha> \\<AA> \\<BB> \\<KK> by (rule assms(3))\n  show ?thesis\n    by (rule ntsmcf_tdghm_eqI)\n      (\n        use assms in\n          \\<open>\n            cs_concl \n              cs_simp: smc_cs_simps slicing_commute[symmetric]\n              cs_intro:\n                smc_cs_intros\n                slicing_intros\n                dghm_tdghm_comp_tdghm_dghm_comp_assoc\n          \\<close>\n      )+\nqed\n\nlemma smcf_ntsmcf_comp_ntsmcf_vcomp: \n  assumes \"\\<KK> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<MM> : \\<GG> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<HH> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\" \n    and \"\\<NN> : \\<FF> \\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>S\\<^sub>M\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \n    \"\\<KK> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>) =\n      (\\<KK> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<MM>) \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<KK> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\"\nproof-\n  interpret \\<KK>: is_semifunctor \\<alpha> \\<BB> \\<CC> \\<KK> by (rule assms(1))\n  interpret \\<MM>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<GG> \\<HH> \\<MM> by (rule assms(2))\n  interpret \\<NN>: is_ntsmcf \\<alpha> \\<AA> \\<BB> \\<FF> \\<GG> \\<NN> by (rule assms(3))\n  show \n    \"\\<KK> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>) = \\<KK> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<KK> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>)\"\n  proof(rule ntsmcf_eqI)\n    have dom_lhs: \"\\<D>\\<^sub>\\<circ> ((\\<KK> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>))\\<lparr>NTMap\\<rparr>) = \\<AA>\\<lparr>Obj\\<rparr>\"\n      unfolding dghm_tdghm_comp_components smc_cs_simps by simp\n    have dom_rhs: \n      \"\\<D>\\<^sub>\\<circ> ((\\<KK> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<KK> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>))\\<lparr>NTMap\\<rparr>) = \\<AA>\\<lparr>Obj\\<rparr>\"\n      unfolding ntsmcf_vcomp_components smc_cs_simps by simp\n    show\n      \"(\\<KK> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>))\\<lparr>NTMap\\<rparr> =\n        (\\<KK> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<KK> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>))\\<lparr>NTMap\\<rparr>\"\n    proof(rule vsv_eqI, unfold dom_lhs dom_rhs smc_cs_simps)\n      fix a assume \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n      then show \n        \"(\\<KK> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>))\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> =\n          (\\<KK> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<MM> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F (\\<KK> \\<circ>\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>S\\<^sub>M\\<^sub>C\\<^sub>F \\<NN>))\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\n        by (cs_concl cs_shallow cs_simp: smc_cs_simps cs_intro: smc_cs_intros)\n    qed (cs_concl cs_shallow cs_intro: smc_cs_intros)+\n  qed (cs_concl cs_shallow cs_intro: smc_cs_intros)+\nqed\n\ntext\\<open>\\newpage\\<close>\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/CZH_Foundations/czh_semicategories/CZH_SMC_NTSMCF.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5506073802837477, "lm_q2_score": 0.538983220687684, "lm_q1q2_score": 0.2967681391597427}}
{"text": "section \\<open> Imperative Programming in Designs \\<close>\n\ntheory utp_des_prog\n  imports utp_des_tactics\nbegin\n\nsubsection \\<open> Assignment \\<close>\n\ndefinition assigns_d :: \"'\\<alpha> usubst \\<Rightarrow> '\\<alpha> hrel_des\" (\"\\<langle>_\\<rangle>\\<^sub>D\") where \n[upred_defs]: \"assigns_d \\<sigma> = (true \\<turnstile>\\<^sub>r assigns_r \\<sigma>)\"\n\nsyntax\n  \"_assignmentd\" :: \"svids \\<Rightarrow> uexprs \\<Rightarrow> logic\"  (infixr \":=\\<^sub>D\" 62)\n\ntranslations\n  \"_assignmentd xs vs\" => \"CONST assigns_d (_mk_usubst (id\\<^sub>s) xs vs)\"\n  \"_assignmentd x v\" <= \"CONST assigns_d (CONST subst_upd (id\\<^sub>s) x v)\"\n  \"_assignmentd x v\" <= \"_assignmentd (_spvar x) v\"\n  \"x,y :=\\<^sub>D u,v\" <= \"CONST assigns_d (CONST subst_upd (CONST subst_upd (id\\<^sub>s) (CONST pr_var x) u) (CONST pr_var y) v)\"\n\nlemma assigns_d_is_H1_H2 [closure]: \"\\<langle>\\<sigma>\\<rangle>\\<^sub>D is \\<^bold>H\"\n  by (simp add: assigns_d_def rdesign_is_H1_H2)\n\nlemma assigns_d_H1_H3 [closure]: \"\\<langle>\\<sigma>\\<rangle>\\<^sub>D is \\<^bold>N\"\n  by (metis H1_rdesign H3_ndesign Healthy_def' aext_true assigns_d_def ndesign_def)\n\ntext \\<open> Designs are closed under substitutions on state variables only (via lifting) \\<close>\n\nlemma state_subst_H1_H2_closed [closure]: \n  \"P is \\<^bold>H \\<Longrightarrow> \\<lceil>\\<sigma> \\<oplus>\\<^sub>s \\<Sigma>\\<^sub>D\\<rceil>\\<^sub>s \\<dagger> P is \\<^bold>H\"\n  by (metis H1_H2_eq_rdesign Healthy_if rdesign_is_H1_H2 state_subst_design)\n\nlemma assigns_d_ndes_def [ndes_simp]:\n  \"\\<langle>\\<sigma>\\<rangle>\\<^sub>D = (true \\<turnstile>\\<^sub>n \\<langle>\\<sigma>\\<rangle>\\<^sub>a)\"\n  by (rel_auto)\n    \nlemma assigns_d_id [simp]: \"\\<langle>id\\<^sub>s\\<rangle>\\<^sub>D = II\\<^sub>D\"\n  by (rel_auto)\n\nlemma assign_d_left_comp:\n  \"(\\<langle>f\\<rangle>\\<^sub>D ;; (P \\<turnstile>\\<^sub>r Q)) = (\\<lceil>f\\<rceil>\\<^sub>s \\<dagger> P \\<turnstile>\\<^sub>r \\<lceil>f\\<rceil>\\<^sub>s \\<dagger> Q)\"\n  by (simp add: assigns_d_def rdesign_composition assigns_r_comp subst_not)\n\nlemma assign_d_right_comp:\n  \"((P \\<turnstile>\\<^sub>r Q) ;; \\<langle>f\\<rangle>\\<^sub>D) = ((\\<not> ((\\<not> P) ;; true)) \\<turnstile>\\<^sub>r (Q ;; \\<langle>f\\<rangle>\\<^sub>a))\"\n  by (simp add: assigns_d_def rdesign_composition)\n\nlemma assigns_d_comp:\n  \"(\\<langle>f\\<rangle>\\<^sub>D ;; \\<langle>g\\<rangle>\\<^sub>D) = \\<langle>g \\<circ>\\<^sub>s f\\<rangle>\\<^sub>D\"\n  by (simp add: assigns_d_def rdesign_composition assigns_comp)\n\nlemma assigns_d_comp_ext:\n  assumes \"P is \\<^bold>H\"\n  shows \"(\\<langle>\\<sigma>\\<rangle>\\<^sub>D ;; P) = \\<lceil>\\<sigma> \\<oplus>\\<^sub>s \\<Sigma>\\<^sub>D\\<rceil>\\<^sub>s \\<dagger> P\"\nproof -\n  have \"\\<langle>\\<sigma>\\<rangle>\\<^sub>D ;; P = \\<langle>\\<sigma>\\<rangle>\\<^sub>D ;; (pre\\<^sub>D(P) \\<turnstile>\\<^sub>r post\\<^sub>D(P))\"\n    by (metis H1_H2_commute H1_H2_is_rdesign H2_idem Healthy_def' assms)\n  also have \"... = \\<lceil>\\<sigma>\\<rceil>\\<^sub>s \\<dagger> pre\\<^sub>D(P) \\<turnstile>\\<^sub>r \\<lceil>\\<sigma>\\<rceil>\\<^sub>s \\<dagger> post\\<^sub>D(P)\"\n    by (simp add: assign_d_left_comp)\n  also have \"... = \\<lceil>\\<sigma> \\<oplus>\\<^sub>s \\<Sigma>\\<^sub>D\\<rceil>\\<^sub>s \\<dagger> (pre\\<^sub>D(P) \\<turnstile>\\<^sub>r post\\<^sub>D(P))\"\n    by (rel_auto)\n  also have \"... = \\<lceil>\\<sigma> \\<oplus>\\<^sub>s \\<Sigma>\\<^sub>D\\<rceil>\\<^sub>s \\<dagger> P\"\n    by (metis H1_H2_commute H1_H2_is_rdesign H2_idem Healthy_def' assms)\n  finally show ?thesis by (simp_all add: closure assms)\nqed\n\ntext \\<open> Normal designs are closed under substitutions on state variables only \\<close>\n\nlemma state_subst_H1_H3_closed [closure]: \n  \"P is \\<^bold>N \\<Longrightarrow> \\<lceil>\\<sigma> \\<oplus>\\<^sub>s \\<Sigma>\\<^sub>D\\<rceil>\\<^sub>s \\<dagger> P is \\<^bold>N\"\n  by (metis H1_H2_eq_rdesign H1_H3_impl_H2 Healthy_if assign_d_left_comp assigns_d_H1_H3 seq_r_H1_H3_closed state_subst_design)\n\nlemma H4_assigns_d: \"\\<langle>\\<sigma>\\<rangle>\\<^sub>D is H4\"\nproof -\n  have \"(\\<langle>\\<sigma>\\<rangle>\\<^sub>D ;; (false \\<turnstile>\\<^sub>r true\\<^sub>h)) = (false \\<turnstile>\\<^sub>r true)\"\n    by (simp add: assigns_d_def rdesign_composition assigns_r_feasible)\n  moreover have \"... = true\"\n    by (rel_auto)\n  ultimately show ?thesis\n    using is_H4_alt_def by auto\nqed\n\nsubsection \\<open> Guarded Commands \\<close>\n\ndefinition GrdCommD :: \"'\\<alpha> upred \\<Rightarrow> ('\\<alpha>, '\\<beta>) rel_des \\<Rightarrow> ('\\<alpha>, '\\<beta>) rel_des\" where\n[upred_defs]: \"GrdCommD b P = P \\<triangleleft> b \\<triangleright>\\<^sub>D \\<top>\\<^sub>D\"\n\nsyntax \"_GrdCommD\" :: \"logic \\<Rightarrow> logic \\<Rightarrow> logic\" (\"_ \\<rightarrow>\\<^sub>D _\" [60, 61] 61)\ntranslations \"_GrdCommD b P\" == \"CONST GrdCommD b P\"\n\nlemma GrdCommD_ndes_simp [ndes_simp]:\n  \"b \\<rightarrow>\\<^sub>D (p\\<^sub>1 \\<turnstile>\\<^sub>n P\\<^sub>2) = ((b \\<Rightarrow> p\\<^sub>1) \\<turnstile>\\<^sub>n (\\<lceil>b\\<rceil>\\<^sub>< \\<and> P\\<^sub>2))\"\n  by (rel_auto)\n\nlemma GrdCommD_H1_H3_closed [closure]: \"P is \\<^bold>N \\<Longrightarrow> b \\<rightarrow>\\<^sub>D P is \\<^bold>N\"\n  by (simp add: GrdCommD_def closure)\n\nlemma GrdCommD_true [simp]: \"true \\<rightarrow>\\<^sub>D P = P\"\n  by (rel_auto)\n    \nlemma GrdCommD_false [simp]: \"false \\<rightarrow>\\<^sub>D P = \\<top>\\<^sub>D\"\n  by (rel_auto)\n  \nlemma GrdCommD_abort [simp]: \"b \\<rightarrow>\\<^sub>D true = ((\\<not> b) \\<turnstile>\\<^sub>n false)\"\n  by (rel_auto)\n\nsubsection \\<open> Frames and Extensions \\<close>\n  \ndefinition des_frame :: \"('\\<alpha> \\<Longrightarrow> '\\<beta>) \\<Rightarrow> '\\<beta> hrel_des \\<Rightarrow> '\\<beta> hrel_des\" where\n[upred_defs]: \"des_frame x P = frame (ok +\\<^sub>L x ;\\<^sub>L \\<Sigma>\\<^sub>D) P\"\n\ndefinition des_frame_ext :: \"('\\<alpha> \\<Longrightarrow> '\\<beta>) \\<Rightarrow> '\\<alpha> hrel_des \\<Rightarrow> '\\<beta> hrel_des\" where\n[upred_defs]: \"des_frame_ext a P = des_frame a (rel_aext P (lmap\\<^sub>D a))\"\n\nsyntax\n  \"_des_frame\"     :: \"salpha \\<Rightarrow> logic \\<Rightarrow> logic\" (\"_:[_]\\<^sub>D\" [99,0] 100)\n  \"_des_frame_ext\" :: \"salpha \\<Rightarrow> logic \\<Rightarrow> logic\" (\"_:[_]\\<^sub>D\\<^sup>+\" [99,0] 100)\n\ntranslations\n  \"_des_frame x P\" => \"CONST des_frame x P\"\n  \"_des_frame (_salphaset (_salphamk x)) P\" <= \"CONST des_frame x P\"\n  \"_des_frame_ext x P\" => \"CONST des_frame_ext x P\"\n  \"_des_frame_ext (_salphaset (_salphamk x)) P\" <= \"CONST des_frame_ext x P\"\n\nlemma lmapD_rel_aext_ndes [ndes_simp]:\n  \"(p \\<turnstile>\\<^sub>n Q) \\<oplus>\\<^sub>r lmap\\<^sub>D[a] = (p \\<oplus>\\<^sub>p a \\<turnstile>\\<^sub>n Q \\<oplus>\\<^sub>r a)\"\n  by (rel_auto)\n\nsubsection \\<open> Alternation \\<close>\n  \nconsts\n  ualtern       :: \"'a set \\<Rightarrow> ('a \\<Rightarrow> 'p) \\<Rightarrow> ('a \\<Rightarrow> 'r) \\<Rightarrow> 'r \\<Rightarrow> 'r\"\n  ualtern_list  :: \"('a \\<times> 'r) list \\<Rightarrow> 'r \\<Rightarrow> 'r\"\n  \ndefinition AlternateD :: \"'a set \\<Rightarrow> ('a \\<Rightarrow> '\\<alpha> upred) \\<Rightarrow> ('a \\<Rightarrow> ('\\<alpha>, '\\<beta>) rel_des) \\<Rightarrow> ('\\<alpha>, '\\<beta>) rel_des \\<Rightarrow> ('\\<alpha>, '\\<beta>) rel_des\" where\n[upred_defs, ndes_simp]:\n\"AlternateD A g P Q = (\\<Sqinter> i\\<in>A \\<bullet> g(i) \\<rightarrow>\\<^sub>D P(i)) \\<sqinter> ((\\<And> i\\<in>A \\<bullet> \\<not> g(i)) \\<rightarrow>\\<^sub>D Q)\"\n\ntext \\<open> This lemma shows that our generalised alternation is the same operator as Marcel Oliveira's\n  definition of alternation when the else branch is abort. \\<close>\n\nlemma AlternateD_abort_alternate:\n  assumes \"\\<And> i. P(i) is \\<^bold>N\"\n  shows\n  \"AlternateD A g P \\<bottom>\\<^sub>D = \n  ((\\<Or> i\\<in>A \\<bullet> g(i)) \\<and> (\\<And> i\\<in>A \\<bullet> g(i) \\<Rightarrow> \\<lfloor>pre\\<^sub>D(P i)\\<rfloor>\\<^sub><)) \\<turnstile>\\<^sub>n (\\<Or> i\\<in>A \\<bullet> \\<lceil>g(i)\\<rceil>\\<^sub>< \\<and> post\\<^sub>D(P i))\"\nproof (cases \"A = {}\")\n  case False\n  have \"AlternateD A g P \\<bottom>\\<^sub>D = \n        (\\<Sqinter> i\\<in>A \\<bullet> g(i) \\<rightarrow>\\<^sub>D (\\<lfloor>pre\\<^sub>D(P i)\\<rfloor>\\<^sub>< \\<turnstile>\\<^sub>n post\\<^sub>D(P i))) \\<sqinter> ((\\<And> i\\<in>A \\<bullet> \\<not> g(i)) \\<rightarrow>\\<^sub>D (false \\<turnstile>\\<^sub>n true))\"\n    by (simp add: AlternateD_def ndesign_form bot_d_ndes_def assms)\n  also have \"... = ((\\<Or> i\\<in>A \\<bullet> g(i)) \\<and> (\\<And> i\\<in>A \\<bullet> g(i) \\<Rightarrow> \\<lfloor>pre\\<^sub>D(P i)\\<rfloor>\\<^sub><)) \\<turnstile>\\<^sub>n (\\<Or> i\\<in>A \\<bullet> \\<lceil>g(i)\\<rceil>\\<^sub>< \\<and> post\\<^sub>D(P i))\"\n    by (simp add: ndes_simp False, rel_auto)\n  finally show ?thesis by simp\nnext\n  case True\n  thus ?thesis\n    by (simp add: AlternateD_def, rel_auto)\nqed\n     \ndefinition AlternateD_list :: \"('\\<alpha> upred \\<times> ('\\<alpha>, '\\<beta>) rel_des) list \\<Rightarrow> ('\\<alpha>, '\\<beta>) rel_des  \\<Rightarrow> ('\\<alpha>, '\\<beta>) rel_des\" where \n[upred_defs, ndes_simp]:\n\"AlternateD_list xs P = \n  AlternateD {0..<length xs} (\\<lambda> i. map fst xs ! i) (\\<lambda> i. map snd xs ! i) P\"\n\nadhoc_overloading\n  ualtern AlternateD and\n  ualtern_list AlternateD_list\n\nnonterminal gcomm and gcomms\n  \nsyntax\n  \"_altind_els\"   :: \"pttrn \\<Rightarrow> logic \\<Rightarrow> logic \\<Rightarrow> logic \\<Rightarrow> logic \\<Rightarrow> logic\" (\"if _\\<in>_ \\<bullet> _ \\<rightarrow> _ else _ fi\")\n  \"_altind\"       :: \"pttrn \\<Rightarrow> logic \\<Rightarrow> logic \\<Rightarrow> logic \\<Rightarrow> logic\" (\"if _\\<in>_ \\<bullet> _ \\<rightarrow> _ fi\")\n  \"_gcomm\"        :: \"logic \\<Rightarrow> logic \\<Rightarrow> gcomm\" (\"_ \\<rightarrow> _\" [60, 60] 61)\n  \"_gcomm_nil\"    :: \"gcomm \\<Rightarrow> gcomms\" (\"_\")\n  \"_gcomm_cons\"   :: \"gcomm \\<Rightarrow> gcomms \\<Rightarrow> gcomms\" (\"_ |/ _\" [60, 61] 61)\n  \"_gcomm_show\"   :: \"logic \\<Rightarrow> logic\"\n  \"_altgcomm_els\" :: \"gcomms \\<Rightarrow> logic \\<Rightarrow> logic\" (\"if/ _ /else _ /fi\")\n  \"_altgcomm\"     :: \"gcomms \\<Rightarrow> logic\" (\"if/ _ /fi\")\n\ntranslations\n  \"_altind_els x A g P Q\" => \"CONST ualtern A (\\<lambda> x. g) (\\<lambda> x. P) Q\"\n  \"_altind_els x A g P Q\" <= \"CONST ualtern A (\\<lambda> x. g) (\\<lambda> x'. P) Q\"\n  \"_altind x A g P\" => \"CONST ualtern A (\\<lambda> x. g) (\\<lambda> x. P) (CONST Orderings.top)\"\n  \"_altind x A g P\" <= \"CONST ualtern A (\\<lambda> x. g) (\\<lambda> x'. P) (CONST Orderings.top)\"\n  \"_altgcomm cs\" => \"CONST ualtern_list cs (CONST Orderings.top)\"\n  \"_altgcomm (_gcomm_show cs)\" <= \"CONST ualtern_list cs (CONST Orderings.top)\"\n  \"_altgcomm_els cs P\" => \"CONST ualtern_list cs P\"\n  \"_altgcomm_els (_gcomm_show cs) P\" <= \"CONST ualtern_list cs P\"\n\n  \"_gcomm g P\" => \"(g, P)\"\n  \"_gcomm g P\" <= \"_gcomm_show (g, P)\"\n  \"_gcomm_cons c cs\" => \"c # cs\"\n  \"_gcomm_cons (_gcomm_show c) (_gcomm_show (d # cs))\" <= \"_gcomm_show (c # d # cs)\"\n  \"_gcomm_nil c\" => \"[c]\"\n  \"_gcomm_nil (_gcomm_show c)\" <= \"_gcomm_show [c]\"\n\nlemma AlternateD_H1_H3_closed [closure]: \n  assumes \"\\<And> i. i \\<in> A \\<Longrightarrow> P i is \\<^bold>N\" \"Q is \\<^bold>N\"\n  shows \"if i\\<in>A \\<bullet> g(i) \\<rightarrow> P(i) else Q fi is \\<^bold>N\"\nproof (cases \"A = {}\")\n  case True\n  then show ?thesis\n    by (simp add: AlternateD_def closure false_upred_def assms)\nnext\n  case False\n  then show ?thesis\n    by (simp add: AlternateD_def closure assms)\nqed\n    \nlemma AltD_ndes_simp [ndes_simp]: \n  \"if i\\<in>A \\<bullet> g(i) \\<rightarrow> (P\\<^sub>1(i) \\<turnstile>\\<^sub>n P\\<^sub>2(i)) else Q\\<^sub>1 \\<turnstile>\\<^sub>n Q\\<^sub>2 fi \n   = ((\\<And> i \\<in> A \\<bullet> g i \\<Rightarrow> P\\<^sub>1 i) \\<and> ((\\<And> i \\<in> A \\<bullet> \\<not> g i) \\<Rightarrow> Q\\<^sub>1)) \\<turnstile>\\<^sub>n\n     ((\\<Or> i \\<in> A \\<bullet> \\<lceil>g i\\<rceil>\\<^sub>< \\<and> P\\<^sub>2 i) \\<or> (\\<And> i \\<in> A \\<bullet> \\<not> \\<lceil>g i\\<rceil>\\<^sub><) \\<and> Q\\<^sub>2)\"\nproof (cases \"A = {}\")\n  case True\n  then show ?thesis by (simp add: AlternateD_def)\nnext\n  case False\n  then show ?thesis\n    by (simp add: ndes_simp, rel_auto)\nqed\n\ndeclare UINF_upto_expand_first [ndes_simp]\ndeclare UINF_Suc_shift [ndes_simp]\ndeclare USUP_upto_expand_first [ndes_simp]\ndeclare USUP_Suc_shift [ndes_simp]\ndeclare true_upred_def [THEN sym, ndes_simp]\n  \nlemma AlternateD_mono_refine:\n  assumes \"\\<And> i. P i \\<sqsubseteq> Q i\" \"R \\<sqsubseteq> S\"\n  shows \"(if i\\<in>A \\<bullet> g(i) \\<rightarrow> P(i) else R fi) \\<sqsubseteq> (if i\\<in>A \\<bullet> g(i) \\<rightarrow> Q(i) else S fi)\"\n  using assms by (rel_auto, meson)\n  \nlemma Monotonic_AlternateD [closure]:\n  \"\\<lbrakk> \\<And> i. Monotonic (F i); Monotonic G \\<rbrakk> \\<Longrightarrow> Monotonic (\\<lambda> X. if i\\<in>A \\<bullet> g(i) \\<rightarrow> F i X else G(X) fi)\" \n  by (rel_auto, meson)\n\nlemma AlternateD_eq:\n  assumes \"A = B\" \"\\<And> i. i\\<in>A \\<Longrightarrow> g(i) = h(i)\" \"\\<And> i. i\\<in>A \\<Longrightarrow> P(i) = Q(i)\" \"R = S\"\n  shows \"if i\\<in>A \\<bullet> g(i) \\<rightarrow> P(i) else R fi = if i\\<in>B \\<bullet> h(i) \\<rightarrow> Q(i) else S fi\"\n  by (insert assms, rel_blast)\n\nlemma AlternateD_empty:\n  \"if i\\<in>{} \\<bullet> g(i) \\<rightarrow> P(i) else Q fi = Q\"\n  by (rel_auto)\n    \nlemma AlternateD_true_singleton:\n  assumes \"P is \\<^bold>N\"\n  shows \"if true \\<rightarrow> P fi = P\"\n  by (ndes_eq cls: assms)\n\nlemma AlernateD_no_ind:\n  assumes \"A \\<noteq> {}\" \"P is \\<^bold>N\" \"Q is \\<^bold>N\"\n  shows \"if i\\<in>A \\<bullet> b \\<rightarrow> P else Q fi = if b \\<rightarrow> P else Q fi\"\n  by (ndes_eq cls: assms)\n\nlemma AlernateD_singleton:\n  assumes \"P k is \\<^bold>N\" \"Q is \\<^bold>N\"\n  shows \"if i\\<in>{k} \\<bullet> b(i) \\<rightarrow> P(i) else Q fi = if b(k) \\<rightarrow> P(k) else Q fi\" (is \"?lhs = ?rhs\")\nproof -\n  have \"?lhs = if i\\<in>{k} \\<bullet> b(k) \\<rightarrow> P(k) else Q fi\"\n    by (auto intro: AlternateD_eq simp add: assms ndesign_form)\n  also have \"... = ?rhs\"\n    by (simp add: AlernateD_no_ind assms closure)\n  finally show ?thesis .\nqed\n\nlemma AlternateD_commute:\n  assumes \"P is \\<^bold>N\" \"Q is \\<^bold>N\"\n  shows \"if g\\<^sub>1 \\<rightarrow> P | g\\<^sub>2 \\<rightarrow> Q fi = if g\\<^sub>2 \\<rightarrow> Q | g\\<^sub>1 \\<rightarrow> P fi\"\n  by (ndes_eq cls:assms)\n\nlemma AlternateD_dcond:\n  assumes \"P is \\<^bold>N\" \"Q is \\<^bold>N\"\n  shows \"if g \\<rightarrow> P else Q fi = P \\<triangleleft> g \\<triangleright>\\<^sub>D Q\"\n  by (ndes_eq cls:assms)\n\nlemma AlternateD_cover:\n  assumes \"P is \\<^bold>N\" \"Q is \\<^bold>N\"\n  shows \"if g \\<rightarrow> P else Q fi = if g \\<rightarrow> P | (\\<not> g) \\<rightarrow> Q fi\"\n  by (ndes_eq cls: assms)\n\nlemma UINF_ndes_expand:\n  assumes \"\\<And> i. i\\<in>A \\<Longrightarrow> P(i) is \\<^bold>N\"\n  shows \"(\\<Sqinter> i \\<in> A \\<bullet> \\<lfloor>pre\\<^sub>D(P(i))\\<rfloor>\\<^sub>< \\<turnstile>\\<^sub>n post\\<^sub>D(P(i))) = (\\<Sqinter> i \\<in> A \\<bullet> P(i))\"\n  by (rule UINF_cong, simp add: assms ndesign_form)\n\nlemma USUP_ndes_expand:\n  assumes \"\\<And> i. i\\<in>A \\<Longrightarrow> P(i) is \\<^bold>N\"\n  shows \"(\\<Squnion> i \\<in> A \\<bullet> \\<lfloor>pre\\<^sub>D(P(i))\\<rfloor>\\<^sub>< \\<turnstile>\\<^sub>n post\\<^sub>D(P(i))) = (\\<Squnion> i \\<in> A \\<bullet> P(i))\"\n  by (rule USUP_cong, simp add: assms ndesign_form)\n    \nlemma AlternateD_ndes_expand:\n  assumes \"\\<And> i. i\\<in>A \\<Longrightarrow> P(i) is \\<^bold>N\" \"Q is \\<^bold>N\"\n  shows \"if i\\<in>A \\<bullet> g(i) \\<rightarrow> P(i) else Q fi =\n         if i\\<in>A \\<bullet> g(i) \\<rightarrow> (\\<lfloor>pre\\<^sub>D(P(i))\\<rfloor>\\<^sub>< \\<turnstile>\\<^sub>n post\\<^sub>D(P(i))) else \\<lfloor>pre\\<^sub>D(Q)\\<rfloor>\\<^sub>< \\<turnstile>\\<^sub>n post\\<^sub>D(Q) fi\"\n  apply (simp add: AlternateD_def)\n  apply (subst UINF_ndes_expand[THEN sym])\n   apply (simp add: assms closure)\n  apply (ndes_simp cls: assms)\n  apply (rel_auto)\n  done\n\nlemma AlternateD_ndes_expand':\n  assumes \"\\<And> i. i\\<in>A \\<Longrightarrow> P(i) is \\<^bold>N\"\n  shows \"if i\\<in>A \\<bullet> g(i) \\<rightarrow> P(i) fi = if i\\<in>A \\<bullet> g(i) \\<rightarrow> (\\<lfloor>pre\\<^sub>D(P(i))\\<rfloor>\\<^sub>< \\<turnstile>\\<^sub>n post\\<^sub>D(P(i))) fi\"\n  apply (simp add: AlternateD_def)\n  apply (subst UINF_ndes_expand[THEN sym])\n   apply (simp add: assms closure)\n  apply (ndes_simp cls: assms)\n  apply (rel_auto)\n  done\n\nlemma ndesign_ind_form:\n  assumes \"\\<And> i. P(i) is \\<^bold>N\"\n  shows \"(\\<lambda> i. \\<lfloor>pre\\<^sub>D(P(i))\\<rfloor>\\<^sub>< \\<turnstile>\\<^sub>n post\\<^sub>D(P(i))) = P\"\n  by (simp add: assms ndesign_form)\n    \nlemma AlternateD_insert:\n  assumes \"\\<And> i. i\\<in>(insert x A) \\<Longrightarrow> P(i) is \\<^bold>N\" \"Q is \\<^bold>N\"\n  shows \"if i\\<in>(insert x A) \\<bullet> g(i) \\<rightarrow> P(i) else Q fi = \n         if g(x) \\<rightarrow> P(x) | \n            (\\<Or> i\\<in>A \\<bullet> g(i)) \\<rightarrow> if i\\<in>A \\<bullet> g(i) \\<rightarrow> P(i) fi \n            else Q \n         fi\" (is \"?lhs = ?rhs\")\nproof -\n  have \"?lhs = if i\\<in>(insert x A) \\<bullet> g(i) \\<rightarrow> (\\<lfloor>pre\\<^sub>D(P(i))\\<rfloor>\\<^sub>< \\<turnstile>\\<^sub>n post\\<^sub>D(P(i))) else (\\<lfloor>pre\\<^sub>D(Q)\\<rfloor>\\<^sub>< \\<turnstile>\\<^sub>n post\\<^sub>D(Q)) fi\"\n    using AlternateD_ndes_expand assms(1) assms(2) by blast\n  also \n  have \"... =\n         if g(x) \\<rightarrow> (\\<lfloor>pre\\<^sub>D(P(x))\\<rfloor>\\<^sub>< \\<turnstile>\\<^sub>n post\\<^sub>D(P(x))) | \n            (\\<Or> i\\<in>A \\<bullet> g(i)) \\<rightarrow> if i\\<in>A \\<bullet> g(i) \\<rightarrow> \\<lfloor>pre\\<^sub>D(P(i))\\<rfloor>\\<^sub>< \\<turnstile>\\<^sub>n post\\<^sub>D(P(i)) fi \n            else \\<lfloor>pre\\<^sub>D(Q)\\<rfloor>\\<^sub>< \\<turnstile>\\<^sub>n post\\<^sub>D(Q)\n         fi\"\n    by (ndes_simp cls:assms, rel_auto)\n  also have \"... = ?rhs\"\n    by (simp add: AlternateD_ndes_expand' ndesign_form assms)\n  finally show ?thesis .\nqed\n   \nsubsection \\<open> Iteration \\<close>\n\ntheorem ndesign_iteration_wlp [ndes_simp]:\n  \"(p \\<turnstile>\\<^sub>n Q) ;; (p \\<turnstile>\\<^sub>n Q) \\<^bold>^ n = ((\\<And> i\\<in>{0..n} \\<bullet> (Q \\<^bold>^ i) wlp p) \\<turnstile>\\<^sub>n Q \\<^bold>^ Suc n)\"\nproof (induct n)\n  case 0\n  then show ?case by (rel_auto)\nnext\n  case (Suc n) note hyp = this\n  have \"(p \\<turnstile>\\<^sub>n Q) ;; (p \\<turnstile>\\<^sub>n Q) \\<^bold>^ Suc n = (p \\<turnstile>\\<^sub>n Q) ;; (p \\<turnstile>\\<^sub>n Q) ;; (p \\<turnstile>\\<^sub>n Q) \\<^bold>^ n\"\n    by (simp add: upred_semiring.power_Suc)\n  also have \"... = (p \\<turnstile>\\<^sub>n Q) ;; ((\\<Squnion> i \\<in> {0..n} \\<bullet> Q \\<^bold>^ i wlp p) \\<turnstile>\\<^sub>n Q \\<^bold>^ Suc n)\"\n    by (simp add: hyp)\n  also have \"... = (p \\<and> Q wlp (\\<Squnion> i \\<in> {0..n} \\<bullet> Q \\<^bold>^ i wlp p)) \\<turnstile>\\<^sub>n (Q ;; Q) ;; Q \\<^bold>^ n\"\n    by (simp add: upred_semiring.power_Suc ndesign_composition_wp seqr_assoc)\n  also have \"... = (p \\<and> U(\\<forall> i \\<in> {0..\\<guillemotleft>n\\<guillemotright>}. Q \\<^bold>^ Suc i wlp p)) \\<turnstile>\\<^sub>n (Q ;; Q) ;; Q \\<^bold>^ n\"\n    by (simp add: upred_semiring.power_Suc wp, rel_simp)\n  also have \"... = (p \\<and> (\\<Squnion> i \\<in> {0..n}. Q \\<^bold>^ Suc i wlp p)) \\<turnstile>\\<^sub>n (Q ;; Q) ;; Q \\<^bold>^ n\"\n    by (rel_auto)\n  also have \"... = (p \\<and> (\\<Squnion> i \\<in> {1..Suc n}. Q \\<^bold>^ i wlp p)) \\<turnstile>\\<^sub>n (Q ;; Q) ;; Q \\<^bold>^ n\"\n    by (metis (no_types, lifting) One_nat_def image_Suc_atLeastAtMost image_cong image_image)  \n  also have \"... = (Q \\<^bold>^ 0 wlp p \\<and> (\\<Squnion> i \\<in> {1..Suc n}. Q \\<^bold>^ i wlp p)) \\<turnstile>\\<^sub>n (Q ;; Q) ;; Q \\<^bold>^ n\"\n    by (simp add: wp)\n  also have \"... = ((\\<Squnion> i \\<in> {0..Suc n}. Q \\<^bold>^ i wlp p)) \\<turnstile>\\<^sub>n (Q ;; Q) ;; Q \\<^bold>^ n\"\n    by (simp add: atMost_Suc_eq_insert_0 atLeast0AtMost conj_upred_def image_Suc_atMost)      \n  also have \"... = (\\<Squnion> i \\<in> {0..Suc n} \\<bullet> Q \\<^bold>^ i wlp p) \\<turnstile>\\<^sub>n Q \\<^bold>^ Suc (Suc n)\"\n    by (simp add: upred_semiring.power_Suc USUP_as_Inf_image upred_semiring.mult_assoc)\n  finally show ?case .\nqed\n\ntext \\<open> Overloadable Syntax \\<close>\n  \nconsts\n  uiterate       :: \"'a set \\<Rightarrow> ('a \\<Rightarrow> 'p) \\<Rightarrow> ('a \\<Rightarrow> 'r) \\<Rightarrow> 'r\"\n  uiterate_list  :: \"('a \\<times> 'r) list \\<Rightarrow> 'r\"\n\nsyntax\n  \"_iterind\"       :: \"pttrn \\<Rightarrow> logic \\<Rightarrow> logic \\<Rightarrow> logic \\<Rightarrow> logic\" (\"do _\\<in>_ \\<bullet> _ \\<rightarrow> _ od\")\n  \"_itergcomm\"     :: \"gcomms \\<Rightarrow> logic\" (\"do _ od\")\n  \ntranslations\n  \"_iterind x A g P\" => \"CONST uiterate A (\\<lambda> x. g) (\\<lambda> x. P)\"\n  \"_iterind x A g P\" <= \"CONST uiterate A (\\<lambda> x. g) (\\<lambda> x'. P)\"\n  \"_itergcomm cs\" => \"CONST uiterate_list cs\"\n  \"_itergcomm (_gcomm_show cs)\" <= \"CONST uiterate_list cs\"\n  \ndefinition IterateD :: \"'a set \\<Rightarrow> ('a \\<Rightarrow> '\\<alpha> upred) \\<Rightarrow> ('a \\<Rightarrow> '\\<alpha> hrel_des) \\<Rightarrow> '\\<alpha> hrel_des\" where\n[upred_defs, ndes_simp]:\n\"IterateD A g P = (\\<mu>\\<^sub>N X \\<bullet> if i\\<in>A \\<bullet> g(i) \\<rightarrow> P(i) ;; X else II\\<^sub>D fi)\"\n\ndefinition IterateD_list :: \"('\\<alpha> upred \\<times> '\\<alpha> hrel_des) list \\<Rightarrow> '\\<alpha> hrel_des\" where \n[upred_defs, ndes_simp]:\n\"IterateD_list xs = IterateD {0..<length xs} (\\<lambda> i. fst (nth xs i)) (\\<lambda> i. snd (nth xs i))\"\n\nadhoc_overloading\n  uiterate IterateD and\n  uiterate_list IterateD_list\n  \nlemma IterateD_H1_H3_closed [closure]: \n  assumes \"\\<And> i. i \\<in> A \\<Longrightarrow> P i is \\<^bold>N\"\n  shows \"do i\\<in>A \\<bullet> g(i) \\<rightarrow> P(i) od is \\<^bold>N\"\nproof (cases \"A = {}\")\n  case True\n  then show ?thesis\n    by (simp add: IterateD_def closure assms)\nnext\n  case False\n  then show ?thesis\n    by (simp add: IterateD_def closure assms)\nqed\n\nlemma IterateD_empty:\n  \"do i\\<in>{} \\<bullet> g(i) \\<rightarrow> P(i) od = II\\<^sub>D\"\n  by (simp add: IterateD_def AlternateD_empty ndes_theory.LFP_const skip_d_is_H1_H3)\n\nlemma IterateD_list_single_expand:\n  \"do b \\<rightarrow> P od = (\\<^bold>\\<mu>\\<^bsub>NDES\\<^esub> X \\<bullet> if b \\<rightarrow> P ;; X else II\\<^sub>D fi)\"\noops\n    \nlemma IterateD_singleton:\n  assumes \"P is \\<^bold>N\"\n  shows \"do b \\<rightarrow> P od = do i\\<in>{0} \\<bullet> b \\<rightarrow> P od\"\n  apply (simp add: IterateD_list_def IterateD_def AlernateD_singleton assms)\n  apply (subst AlernateD_singleton)\n  apply (simp)\n  apply (rel_auto)\noops\n\nlemma IterateD_mono_refine:\n  assumes \n    \"\\<And> i. P i is \\<^bold>N\" \"\\<And> i. Q i is \\<^bold>N\"\n    \"\\<And> i. P i \\<sqsubseteq> Q i\"\n  shows \"(do i\\<in>A \\<bullet> g(i) \\<rightarrow> P(i) od) \\<sqsubseteq> (do i\\<in>A \\<bullet> g(i) \\<rightarrow> Q(i) od)\"\n  apply (simp add: IterateD_def ndes_theory.utp_lfp_def)\n  apply (subst ndes_theory.utp_lfp_def)\n  apply (simp_all add: closure assms)\n  apply (subst ndes_theory.utp_lfp_def)\n  apply (simp_all add: closure assms)\n  apply (rule gfp_mono)\n  apply (rule AlternateD_mono_refine)\n  apply (simp_all add: closure seqr_mono assms)\ndone\n\nlemma IterateD_single_refine:\n  assumes \n    \"P is \\<^bold>N\" \"Q is \\<^bold>N\" \"P \\<sqsubseteq> Q\"\n  shows \"(do g \\<rightarrow> P od) \\<sqsubseteq> (do g \\<rightarrow> Q od)\"\noops\n  \nlemma IterateD_refine_intro:\n  fixes V :: \"(nat, 'a) uexpr\"\n  assumes \"vwb_lens w\"\n  shows\n  \"I \\<turnstile>\\<^sub>n (w:[\\<lceil>I \\<and> \\<not> (\\<Or> i\\<in>A \\<bullet> g(i))\\<rceil>\\<^sub>>]) \\<sqsubseteq> \n   do i\\<in>A \\<bullet> g(i) \\<rightarrow> (I \\<and> g(i)) \\<turnstile>\\<^sub>n (w:[\\<lceil>I\\<rceil>\\<^sub>> \\<and> \\<lceil>V\\<rceil>\\<^sub>> <\\<^sub>u \\<lceil>V\\<rceil>\\<^sub><]) od\"\nproof (cases \"A = {}\")\n  case True\n  with assms show ?thesis\n    by (simp add: IterateD_empty, rel_auto)\nnext\n  case False\n  then show ?thesis\n  using assms\n    apply (simp add: IterateD_def)\n    apply (rule ndesign_mu_wf_refine_intro[where e=V and R=\"{(x, y). x < y}\"])\n    apply (simp_all add: wf closure)\n    apply (simp add: ndes_simp unrest)\n    apply (rule ndesign_refine_intro)\n    apply (rel_auto)\n    apply (rel_auto)\n    apply (metis mwb_lens.put_put vwb_lens_mwb)\n  done\nqed\n  \nlemma IterateD_single_refine_intro:\n  fixes V :: \"(nat, 'a) uexpr\"\n  assumes \"vwb_lens w\"\n  shows\n  \"I \\<turnstile>\\<^sub>n (w:[\\<lceil>I \\<and> \\<not> g\\<rceil>\\<^sub>>]) \\<sqsubseteq> \n   do g \\<rightarrow> ((I \\<and> g) \\<turnstile>\\<^sub>n (w:[\\<lceil>I\\<rceil>\\<^sub>> \\<and> \\<lceil>V\\<rceil>\\<^sub>> <\\<^sub>u \\<lceil>V\\<rceil>\\<^sub><])) od\"\n  apply (rule order_trans)\n  defer\n   apply (rule IterateD_refine_intro[of w \"{0}\" \"\\<lambda> i. g\" I V, simplified, OF assms(1)])\n  oops\n\nsubsection \\<open> Let and Local Variables \\<close>\n  \ndefinition LetD :: \"('a, '\\<alpha>) uexpr \\<Rightarrow> ('a \\<Rightarrow> '\\<alpha> hrel_des) \\<Rightarrow> '\\<alpha> hrel_des\" where\n[upred_defs]: \"LetD v P = (P x)\\<lbrakk>x \\<rightarrow> \\<lceil>v\\<rceil>\\<^sub>D\\<^sub><\\<rbrakk>\"\n\nsyntax\n  \"_LetD\"       :: \"[letbinds, 'a] \\<Rightarrow> 'a\"                (\"(let\\<^sub>D (_)/ in (_))\" [0, 10] 10)\n\ntranslations\n  \"_LetD (_binds b bs) e\"  \\<rightleftharpoons> \"_LetD b (_LetD bs e)\"\n  \"let\\<^sub>D x = a in e\"        \\<rightleftharpoons> \"CONST LetD a (\\<lambda>x. e)\"\n\nlemma LetD_ndes_simp [ndes_simp]: \n  \"LetD v (\\<lambda> x. p(x) \\<turnstile>\\<^sub>n Q(x)) = (p(x)\\<lbrakk>x \\<rightarrow> v\\<rbrakk>) \\<turnstile>\\<^sub>n (Q(x)\\<lbrakk>x \\<rightarrow> \\<lceil>v\\<rceil>\\<^sub><\\<rbrakk>)\"\n  by (rel_auto)\n    \nlemma LetD_H1_H3_closed [closure]:\n  \"\\<lbrakk> \\<And> x. P(x) is \\<^bold>N \\<rbrakk> \\<Longrightarrow> LetD v P is \\<^bold>N\"\n  by (rel_auto)\n\nend", "meta": {"author": "isabelle-utp", "repo": "utp-main", "sha": "27bdf3aee6d4fc00c8fe4d53283d0101857e0d41", "save_path": "github-repos/isabelle/isabelle-utp-utp-main", "path": "github-repos/isabelle/isabelle-utp-utp-main/utp-main-27bdf3aee6d4fc00c8fe4d53283d0101857e0d41/theories/designs/utp_des_prog.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5506073655352404, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.2967681312105448}}
{"text": "theory Term5\nimports \"../Nominal2_Atoms\" \"../Nominal2_Eqvt\" \"../Nominal2_Supp\" \"../Abs\" \"../Perm\" \"../Fv\" \"../Rsp\"\nbegin\n\natom_decl name\n\ndatatype rtrm5 =\n  rVr5 \"name\"\n| rAp5 \"rtrm5\" \"rtrm5\"\n| rLt5 \"rlts\" \"rtrm5\" --\"bind (bv5 lts) in (rtrm5)\"\nand rlts =\n  rLnil\n| rLcons \"name\" \"rtrm5\" \"rlts\"\n\nprimrec\n  rbv5\nwhere\n  \"rbv5 rLnil = {}\"\n| \"rbv5 (rLcons n t ltl) = {atom n} \\<union> (rbv5 ltl)\"\n\n\nsetup {* snd o define_raw_perms (Datatype.the_info @{theory} \"Term5.rtrm5\") 2 *}\nprint_theorems\n\nlocal_setup {* snd o define_fv_alpha (Datatype.the_info @{theory} \"Term5.rtrm5\")\n  [[[], [], [(SOME (@{term rbv5}, true), 0, 1)]], [[], []]] [(@{term rbv5}, 1, [[], [(0,NONE), (2,SOME @{term rbv5})]])] *}\nprint_theorems\n\nnotation\n  alpha_rtrm5 (\"_ \\<approx>5 _\" [100, 100] 100) and\n  alpha_rlts (\"_ \\<approx>l _\" [100, 100] 100)\nthm alpha_rtrm5_alpha_rlts_alpha_rbv5.intros\n\nlocal_setup {* (fn ctxt => snd (Local_Theory.note ((@{binding alpha5_inj}, []), (build_rel_inj @{thms alpha_rtrm5_alpha_rlts_alpha_rbv5.intros} @{thms rtrm5.distinct rtrm5.inject rlts.distinct rlts.inject} @{thms alpha_rtrm5.cases alpha_rlts.cases alpha_rbv5.cases} ctxt)) ctxt)) *}\nthm alpha5_inj\n\nlemma rbv5_eqvt[eqvt]:\n  \"pi \\<bullet> (rbv5 x) = rbv5 (pi \\<bullet> x)\"\n  apply (induct x)\n  apply (simp_all add: eqvts atom_eqvt)\n  done\n\nlemma fv_rtrm5_rlts_eqvt[eqvt]:\n  \"pi \\<bullet> (fv_rtrm5 x) = fv_rtrm5 (pi \\<bullet> x)\"\n  \"pi \\<bullet> (fv_rlts l) = fv_rlts (pi \\<bullet> l)\"\n  apply (induct x and l)\n  apply (simp_all add: eqvts atom_eqvt)\n  done\n\n(*lemma alpha5_eqvt:\n  \"(xa \\<approx>5 y \\<longrightarrow> (p \\<bullet> xa) \\<approx>5 (p \\<bullet> y)) \\<and>\n  (xb \\<approx>l ya \\<longrightarrow> (p \\<bullet> xb) \\<approx>l (p \\<bullet> ya)) \\<and>\n  (alpha_rbv5 b c \\<longrightarrow> alpha_rbv5 (p \\<bullet> b) (p \\<bullet> c))\"\napply (tactic {* alpha_eqvt_tac @{thm alpha_rtrm5_alpha_rlts_alpha_rbv5.induct} @{thms alpha5_inj permute_rtrm5_permute_rlts.simps} @{context} 1 *})\ndone*)\n\nlocal_setup {*\n(fn ctxt => snd (Local_Theory.note ((@{binding alpha5_eqvt}, []),\nbuild_alpha_eqvts [@{term alpha_rtrm5}, @{term alpha_rlts}, @{term alpha_rbv5}] (fn _ => alpha_eqvt_tac  @{thm alpha_rtrm5_alpha_rlts_alpha_rbv5.induct} @{thms alpha5_inj permute_rtrm5_permute_rlts.simps} ctxt 1) ctxt) ctxt)) *}\nprint_theorems\n\nlemma alpha5_reflp:\n\"y \\<approx>5 y \\<and> (x \\<approx>l x \\<and> alpha_rbv5 x x)\"\napply (rule rtrm5_rlts.induct)\napply (simp_all add: alpha5_inj)\napply (rule_tac x=\"0::perm\" in exI)\napply (simp add: eqvts alpha_gen fresh_star_def fresh_zero_perm)\ndone\n\nlemma alpha5_symp:\n\"(a \\<approx>5 b \\<longrightarrow> b \\<approx>5 a) \\<and>\n(x \\<approx>l y \\<longrightarrow> y \\<approx>l x) \\<and>\n(alpha_rbv5 x y \\<longrightarrow> alpha_rbv5 y x)\"\napply (rule alpha_rtrm5_alpha_rlts_alpha_rbv5.induct)\napply (simp_all add: alpha5_inj)\napply (erule exE)\napply (rule_tac x=\"-pi\" in exI)\napply (rule alpha_gen_sym)\napply (simp_all add: alphas)\napply (case_tac x)\napply (case_tac y)\napply (simp add: alpha5_eqvt)\napply clarify\napply simp\ndone\n\nlemma alpha5_symp1:\n\"(a \\<approx>5 b \\<longrightarrow> b \\<approx>5 a) \\<and>\n(x \\<approx>l y \\<longrightarrow> y \\<approx>l x) \\<and>\n(alpha_rbv5 x y \\<longrightarrow> alpha_rbv5 y x)\"\napply (rule alpha_rtrm5_alpha_rlts_alpha_rbv5.induct)\napply (simp_all add: alpha5_inj)\napply (erule exE)\napply (rule_tac x=\"- pi\" in exI)\napply (simp add: alpha_gen)\n  apply(simp add: fresh_star_def fresh_minus_perm)\napply clarify\napply (rule conjI)\napply (rotate_tac 3)\napply (frule_tac p=\"- pi\" in alpha5_eqvt(2))\napply simp\napply (rule conjI)\napply (rotate_tac 5)\napply (frule_tac p=\"- pi\" in alpha5_eqvt(1))\napply simp\napply (rotate_tac 6)\napply simp\napply (drule_tac p1=\"- pi\" in permute_eq_iff[symmetric,THEN iffD1])\napply (simp)\ndone\n\nthm alpha_gen_sym[no_vars]\nthm alpha_gen_compose_sym[no_vars]\n\nlemma tt: \n  \"\\<lbrakk>R (- p \\<bullet> x) y \\<Longrightarrow> R (p \\<bullet> y) x; (bs, x) \\<approx>gen R f (- p) (cs, y)\\<rbrakk> \\<Longrightarrow> (cs, y) \\<approx>gen R f p (bs, x)\"\n  unfolding alphas\n  unfolding fresh_star_def\n  by (auto simp add:  fresh_minus_perm)\n\nlemma alpha5_symp2:\n  shows \"a \\<approx>5 b \\<Longrightarrow> b \\<approx>5 a\"\n  and   \"x \\<approx>l y \\<Longrightarrow> y \\<approx>l x\"\n  and   \"alpha_rbv5 x y \\<Longrightarrow> alpha_rbv5 y x\"\napply(induct rule:  alpha_rtrm5_alpha_rlts_alpha_rbv5.inducts)\n(* non-binding case *)\napply(simp add: alpha5_inj)\n(* non-binding case *)\napply(simp add: alpha5_inj)\n(* binding case *)\napply(simp add: alpha5_inj)\napply(erule exE)\napply(rule_tac x=\"- pi\" in exI)\napply(rule tt)\napply(simp add: alphas)\napply(erule conjE)+\napply(drule_tac p=\"- pi\" in alpha5_eqvt(2))\napply(drule_tac p=\"- pi\" in alpha5_eqvt(2))\napply(drule_tac p=\"- pi\" in alpha5_eqvt(1))\napply(drule_tac p=\"- pi\" in alpha5_eqvt(1))\napply(simp)\napply(simp add: alphas)\napply(erule conjE)+\napply metis\n(* non-binding case *)\napply(simp add: alpha5_inj)\n(* non-binding case *)\napply(simp add: alpha5_inj)\n(* non-binding case *)\napply(simp add: alpha5_inj)\n(* non-binding case *)\napply(simp add: alpha5_inj)\ndone\n\nlemma alpha5_transp:\n\"(a \\<approx>5 b \\<longrightarrow> (\\<forall>c. b \\<approx>5 c \\<longrightarrow> a \\<approx>5 c)) \\<and>\n(x \\<approx>l y \\<longrightarrow> (\\<forall>z. y \\<approx>l z \\<longrightarrow> x \\<approx>l z)) \\<and>\n(alpha_rbv5 k l \\<longrightarrow> (\\<forall>m. alpha_rbv5 l m \\<longrightarrow> alpha_rbv5 k m))\"\n(*apply (tactic {* transp_tac @{context} @{thm alpha_rtrm5_alpha_rlts_alpha_rbv5.induct} @{thms alpha5_inj} @{thms rtrm5.distinct rtrm5.inject rlts.distinct rlts.inject} [] @{thms alpha_rtrm5.cases alpha_rlts.cases alpha_rbv5.cases} @{thms alpha5_eqvt} 1 *})*)\napply (rule alpha_rtrm5_alpha_rlts_alpha_rbv5.induct)\napply (rule_tac [!] allI)\napply (tactic {* (imp_elim_tac @{thms alpha_rtrm5.cases alpha_rlts.cases alpha_rbv5.cases} @{context}) 1 *})\napply (simp_all add: alpha5_inj)\napply (tactic {* (imp_elim_tac @{thms alpha_rtrm5.cases alpha_rlts.cases alpha_rbv5.cases} @{context}) 1 *})\napply (simp_all add: alpha5_inj)\napply (tactic {* (imp_elim_tac @{thms alpha_rtrm5.cases alpha_rlts.cases alpha_rbv5.cases} @{context}) 1 *})\napply (simp_all add: alpha5_inj)\ndefer\napply (tactic {* (imp_elim_tac @{thms alpha_rtrm5.cases alpha_rlts.cases alpha_rbv5.cases} @{context}) 1 *})\napply (simp_all add: alpha5_inj)\napply (tactic {* (imp_elim_tac @{thms alpha_rtrm5.cases alpha_rlts.cases alpha_rbv5.cases} @{context}) 1 *})\napply (simp_all add: alpha5_inj)\napply (tactic {* eetac @{thm exi_sum} @{context} 1 *})\n(* HERE *)\n(*\napply(rule alpha_gen_trans)\nthm alpha_gen_trans\ndefer\napply (simp add: alpha_gen)\napply clarify\napply(simp add: fresh_star_plus)\napply (rule conjI)\napply (erule_tac x=\"- pi \\<bullet> rltsaa\" in allE)\napply (rotate_tac 5)\napply (drule_tac p=\"- pi\" in alpha5_eqvt(2))\napply simp\napply (drule_tac p=\"pi\" in alpha5_eqvt(2))\napply simp\napply (erule_tac x=\"- pi \\<bullet> rtrm5aa\" in allE)\napply (rotate_tac 7)\napply (drule_tac p=\"- pi\" in alpha5_eqvt(1))\napply simp\napply (rotate_tac 3)\napply (drule_tac p=\"pi\" in alpha5_eqvt(1))\napply simp\ndone\n*)\nsorry\n\nlemma alpha5_equivp:\n  \"equivp alpha_rtrm5\"\n  \"equivp alpha_rlts\"\n  unfolding equivp_reflp_symp_transp reflp_def symp_def transp_def\n  apply (simp_all only: alpha5_reflp)\n  apply (meson alpha5_symp alpha5_transp)\n  apply (meson alpha5_symp alpha5_transp)\n  done\n\nquotient_type\n  trm5 = rtrm5 / alpha_rtrm5\nand\n  lts = rlts / alpha_rlts\n  by (auto intro: alpha5_equivp)\n\nlocal_setup {*\n(fn ctxt => ctxt\n |> snd o (Quotient_Def.quotient_lift_const (\"Vr5\", @{term rVr5}))\n |> snd o (Quotient_Def.quotient_lift_const (\"Ap5\", @{term rAp5}))\n |> snd o (Quotient_Def.quotient_lift_const (\"Lt5\", @{term rLt5}))\n |> snd o (Quotient_Def.quotient_lift_const (\"Lnil\", @{term rLnil}))\n |> snd o (Quotient_Def.quotient_lift_const (\"Lcons\", @{term rLcons}))\n |> snd o (Quotient_Def.quotient_lift_const (\"fv_trm5\", @{term fv_rtrm5}))\n |> snd o (Quotient_Def.quotient_lift_const (\"fv_lts\", @{term fv_rlts}))\n |> snd o (Quotient_Def.quotient_lift_const (\"bv5\", @{term rbv5}))\n |> snd o (Quotient_Def.quotient_lift_const (\"alpha_bv5\", @{term alpha_rbv5})))\n*}\nprint_theorems\n\nlemma alpha5_rfv:\n  \"(t \\<approx>5 s \\<Longrightarrow> fv_rtrm5 t = fv_rtrm5 s)\"\n  \"(l \\<approx>l m \\<Longrightarrow> fv_rlts l = fv_rlts m)\"\n  \"(alpha_rbv5 b c \\<Longrightarrow> True)\"\n  apply(induct rule: alpha_rtrm5_alpha_rlts_alpha_rbv5.inducts)\n  apply(simp_all add: eqvts)\n  apply(simp add: alpha_gen)\n  apply(clarify)\n  apply blast\ndone\n\nlemma bv_list_rsp:\n  shows \"x \\<approx>l y \\<Longrightarrow> rbv5 x = rbv5 y\"\n  apply(induct rule: alpha_rtrm5_alpha_rlts_alpha_rbv5.inducts(2))\n  apply(simp_all)\n  apply(clarify)\n  apply simp\n  done\n\nlocal_setup {* snd o Local_Theory.note ((@{binding alpha_dis}, []), (flat (map (distinct_rel @{context} @{thms alpha_rtrm5.cases alpha_rlts.cases alpha_rbv5.cases}) [(@{thms rtrm5.distinct}, @{term alpha_rtrm5}), (@{thms rlts.distinct}, @{term alpha_rlts}), (@{thms rlts.distinct}, @{term alpha_rbv5})]))) *}\nprint_theorems\n\nlocal_setup {* snd o Local_Theory.note ((@{binding alpha_bn_rsp}, []), prove_alpha_bn_rsp [@{term alpha_rtrm5}, @{term alpha_rlts}] @{thms alpha_rtrm5_alpha_rlts_alpha_rbv5.inducts} @{thms rtrm5.exhaust rlts.exhaust} @{thms alpha5_inj alpha_dis} @{thms alpha5_equivp} @{context} (@{term alpha_rbv5}, 1)) *}\nthm alpha_bn_rsp\n\nlemma [quot_respect]:\n  \"(alpha_rlts ===> op =) fv_rlts fv_rlts\"\n  \"(alpha_rtrm5 ===> op =) fv_rtrm5 fv_rtrm5\"\n  \"(alpha_rlts ===> op =) rbv5 rbv5\"\n  \"(op = ===> alpha_rtrm5) rVr5 rVr5\"\n  \"(alpha_rtrm5 ===> alpha_rtrm5 ===> alpha_rtrm5) rAp5 rAp5\"\n  \"(alpha_rlts ===> alpha_rtrm5 ===> alpha_rtrm5) rLt5 rLt5\"\n  \"(op = ===> alpha_rtrm5 ===> alpha_rlts ===> alpha_rlts) rLcons rLcons\"\n  \"(op = ===> alpha_rtrm5 ===> alpha_rtrm5) permute permute\"\n  \"(op = ===> alpha_rlts ===> alpha_rlts) permute permute\"\n  \"(alpha_rlts ===> alpha_rlts ===> op =) alpha_rbv5 alpha_rbv5\"\n  apply (simp_all add: alpha5_inj alpha5_rfv alpha5_eqvt bv_list_rsp alpha_bn_rsp)\n  apply (clarify)\n  apply (rule_tac x=\"0\" in exI)\n  apply (simp add: fresh_star_def fresh_zero_perm alpha_gen alpha5_rfv)\ndone\n\n\nlemma\n  shows \"(alpha_rlts ===> op =) rbv5 rbv5\"\n  by (simp add: bv_list_rsp)\n\nlemmas trm5_lts_inducts = rtrm5_rlts.inducts[quot_lifted]\n\ninstantiation trm5 and lts :: pt\nbegin\n\nquotient_definition\n  \"permute_trm5 :: perm \\<Rightarrow> trm5 \\<Rightarrow> trm5\"\nis\n  \"permute :: perm \\<Rightarrow> rtrm5 \\<Rightarrow> rtrm5\"\n\nquotient_definition\n  \"permute_lts :: perm \\<Rightarrow> lts \\<Rightarrow> lts\"\nis\n  \"permute :: perm \\<Rightarrow> rlts \\<Rightarrow> rlts\"\n\ninstance by default\n  (simp_all add: permute_rtrm5_permute_rlts_zero[quot_lifted] permute_rtrm5_permute_rlts_append[quot_lifted])\n\nend\n\nlemmas permute_trm5_lts = permute_rtrm5_permute_rlts.simps[quot_lifted]\nlemmas bv5[simp] = rbv5.simps[quot_lifted]\nlemmas fv_trm5_lts[simp] = fv_rtrm5_fv_rlts.simps[quot_lifted]\nlemmas alpha5_INJ = alpha5_inj[unfolded alpha_gen2, unfolded alpha_gen, quot_lifted, folded alpha_gen2, folded alpha_gen]\nlemmas alpha5_DIS = alpha_dis[quot_lifted]\n\nend\n", "meta": {"author": "goodlyrottenapple", "repo": "Nominal2-Isabelle", "sha": "214274ed6db74c19b8694fc5c8dd9cafa13b056a", "save_path": "github-repos/isabelle/goodlyrottenapple-Nominal2-Isabelle", "path": "github-repos/isabelle/goodlyrottenapple-Nominal2-Isabelle/Nominal2-Isabelle-214274ed6db74c19b8694fc5c8dd9cafa13b056a/Nominal/Manual/Term5.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.538983220687684, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.29676813121054474}}
{"text": "section\\<open>Auxiliary renamings for Separation\\<close>\ntheory Separation_Rename\n  imports\n    Interface\nbegin\n\nno_notation Aleph (\\<open>\\<aleph>_\\<close> [90] 90)\n\nlemmas apply_fun = apply_iff[THEN iffD1]\n\nlemma nth_concat : \"[p,t] \\<in> list(A) \\<Longrightarrow> env\\<in> list(A) \\<Longrightarrow> nth(1 +\\<^sub>\\<omega> length(env),[p]@ env @ [t]) = t\"\n  by(auto simp add:nth_append)\n\nlemma nth_concat2 : \"env\\<in> list(A) \\<Longrightarrow> nth(length(env),env @ [p,t]) = p\"\n  by(auto simp add:nth_append)\n\nlemma nth_concat3 : \"env\\<in> list(A) \\<Longrightarrow> u = nth(succ(length(env)), env @ [pi, u])\"\n  by(auto simp add:nth_append)\n\ndefinition\n  sep_var :: \"i \\<Rightarrow> i\" where\n  \"sep_var(n) \\<equiv> {\\<langle>0,1\\<rangle>,\\<langle>1,3\\<rangle>,\\<langle>2,4\\<rangle>,\\<langle>3,5\\<rangle>,\\<langle>4,0\\<rangle>,\\<langle>5+\\<^sub>\\<omega>n,6\\<rangle>,\\<langle>6+\\<^sub>\\<omega>n,2\\<rangle>}\"\n\ndefinition\n  sep_env :: \"i \\<Rightarrow> i\" where\n  \"sep_env(n) \\<equiv> \\<lambda> i \\<in> (5+\\<^sub>\\<omega>n)-5 . i+\\<^sub>\\<omega>2\"\n\ndefinition weak :: \"[i, i] \\<Rightarrow> i\" where\n  \"weak(n,m) \\<equiv> {i+\\<^sub>\\<omega>m . i \\<in> n}\"\n\nlemma weakD :\n  assumes \"n \\<in> nat\" \"k\\<in>nat\" \"x \\<in> weak(n,k)\"\n  shows \"\\<exists> i \\<in> n . x = i+\\<^sub>\\<omega>k\"\n  using assms unfolding weak_def by blast\n\nlemma weak_equal :\n  assumes \"n\\<in>nat\" \"m\\<in>nat\"\n  shows \"weak(n,m) = (m+\\<^sub>\\<omega>n) - m\"\nproof -\n  have \"weak(n,m)\\<subseteq>(m+\\<^sub>\\<omega>n)-m\"\n  proof(intro subsetI)\n    fix x\n    assume \"x\\<in>weak(n,m)\"\n    with assms\n    obtain i where\n      \"i\\<in>n\" \"x=i+\\<^sub>\\<omega>m\"\n      using weakD by blast\n    then\n    have \"m\\<le>i+\\<^sub>\\<omega>m\" \"i<n\"\n      using add_le_self2[of m i] \\<open>m\\<in>nat\\<close> \\<open>n\\<in>nat\\<close> ltI[OF \\<open>i\\<in>n\\<close>] by simp_all\n    then\n    have \"\\<not>i+\\<^sub>\\<omega>m<m\"\n      using not_lt_iff_le in_n_in_nat[OF \\<open>n\\<in>nat\\<close> \\<open>i\\<in>n\\<close>] \\<open>m\\<in>nat\\<close> by simp\n    with \\<open>x=i+\\<^sub>\\<omega>m\\<close>\n    have \"x\\<notin>m\"\n      using ltI \\<open>m\\<in>nat\\<close> by auto\n    moreover\n    from assms \\<open>x=i+\\<^sub>\\<omega>m\\<close> \\<open>i<n\\<close>\n    have \"x<m+\\<^sub>\\<omega>n\"\n      using add_lt_mono1[OF \\<open>i<n\\<close> \\<open>n\\<in>nat\\<close>] by simp\n    ultimately\n    show \"x\\<in>(m+\\<^sub>\\<omega>n)-m\"\n      using ltD DiffI by simp\n  qed\n  moreover\n  have \"(m+\\<^sub>\\<omega>n)-m\\<subseteq>weak(n,m)\"\n  proof (intro subsetI)\n    fix x\n    assume \"x\\<in>(m+\\<^sub>\\<omega>n)-m\"\n    then\n    have \"x\\<in>m+\\<^sub>\\<omega>n\" \"x\\<notin>m\"\n      using DiffD1[of x \"n+\\<^sub>\\<omega>m\" m] DiffD2[of x \"n+\\<^sub>\\<omega>m\" m] by simp_all\n    then\n    have \"x<m+\\<^sub>\\<omega>n\" \"x\\<in>nat\"\n      using ltI in_n_in_nat[OF add_type[of m n]] by simp_all\n    then\n    obtain i where\n      \"m+\\<^sub>\\<omega>n = succ(x+\\<^sub>\\<omega>i)\"\n      using less_iff_succ_add[OF \\<open>x\\<in>nat\\<close>,of \"m+\\<^sub>\\<omega>n\"] add_type by auto\n    then\n    have \"x+\\<^sub>\\<omega>i<m+\\<^sub>\\<omega>n\" using succ_le_iff by simp\n    with \\<open>x\\<notin>m\\<close>\n    have \"\\<not>x<m\" using ltD by blast\n    with \\<open>m\\<in>nat\\<close> \\<open>x\\<in>nat\\<close>\n    have \"m\\<le>x\" using not_lt_iff_le by simp\n    with \\<open>x<m+\\<^sub>\\<omega>n\\<close>  \\<open>n\\<in>nat\\<close>\n    have \"x-\\<^sub>\\<omega>m<m+\\<^sub>\\<omega>n-\\<^sub>\\<omega>m\"\n      using diff_mono[OF \\<open>x\\<in>nat\\<close> _ \\<open>m\\<in>nat\\<close>] by simp\n    have \"m+\\<^sub>\\<omega>n-\\<^sub>\\<omega>m =  n\" using diff_cancel2 \\<open>m\\<in>nat\\<close> \\<open>n\\<in>nat\\<close> by simp\n    with \\<open>x-\\<^sub>\\<omega>m<m+\\<^sub>\\<omega>n-\\<^sub>\\<omega>m\\<close> \\<open>x\\<in>nat\\<close>\n    have \"x-\\<^sub>\\<omega>m \\<in> n\" \"x=x-\\<^sub>\\<omega>m+\\<^sub>\\<omega>m\"\n      using ltD add_diff_inverse2[OF \\<open>m\\<le>x\\<close>] by simp_all\n    then\n    show \"x\\<in>weak(n,m)\"\n      unfolding weak_def by auto\n  qed\n  ultimately\n  show ?thesis by auto\nqed\n\nlemma weak_zero:\n  shows \"weak(0,n) = 0\"\n  unfolding weak_def by simp\n\nlemma weakening_diff :\n  assumes \"n \\<in> nat\"\n  shows \"weak(n,7) - weak(n,5) \\<subseteq> {5+\\<^sub>\\<omega>n, 6+\\<^sub>\\<omega>n}\"\n  unfolding weak_def using assms\nproof(auto)\n  {\n    fix i\n    assume \"i\\<in>n\" \"succ(succ(natify(i)))\\<noteq>n\" \"\\<forall>w\\<in>n. succ(succ(natify(i))) \\<noteq> natify(w)\"\n    then\n    have \"i<n\"\n      using ltI \\<open>n\\<in>nat\\<close> by simp\n    from \\<open>n\\<in>nat\\<close> \\<open>i\\<in>n\\<close> \\<open>succ(succ(natify(i)))\\<noteq>n\\<close>\n    have \"i\\<in>nat\" \"succ(succ(i))\\<noteq>n\" using in_n_in_nat by simp_all\n    from \\<open>i<n\\<close>\n    have \"succ(i)\\<le>n\" using succ_leI by simp\n    with \\<open>n\\<in>nat\\<close>\n    consider (a) \"succ(i) = n\" | (b) \"succ(i) < n\"\n      using leD by auto\n    then have \"succ(i) = n\"\n    proof cases\n      case a\n      then show ?thesis .\n    next\n      case b\n      then\n      have \"succ(succ(i))\\<le>n\" using succ_leI by simp\n      with \\<open>n\\<in>nat\\<close>\n      consider (a) \"succ(succ(i)) = n\" | (b) \"succ(succ(i)) < n\"\n        using leD by auto\n      then have \"succ(i) = n\"\n      proof cases\n        case a\n        with \\<open>succ(succ(i))\\<noteq>n\\<close> show ?thesis by blast\n      next\n        case b\n        then\n        have \"succ(succ(i))\\<in>n\" using ltD by simp\n        with \\<open>i\\<in>nat\\<close>\n        have \"succ(succ(natify(i))) \\<noteq> natify(succ(succ(i)))\"\n          using  \\<open>\\<forall>w\\<in>n. succ(succ(natify(i))) \\<noteq> natify(w)\\<close> by auto\n        then\n        have \"False\" using \\<open>i\\<in>nat\\<close> by auto\n        then show ?thesis by blast\n      qed\n      then show ?thesis .\n    qed\n    with \\<open>i\\<in>nat\\<close> have \"succ(natify(i)) = n\" by simp\n  }\n  then\n  show \"n \\<in> nat \\<Longrightarrow>\n    succ(succ(natify(y))) \\<noteq> n \\<Longrightarrow>\n    \\<forall>x\\<in>n. succ(succ(natify(y))) \\<noteq> natify(x) \\<Longrightarrow>\n    y \\<in> n \\<Longrightarrow> succ(natify(y)) = n\" for y\n    by blast\nqed\n\nlemma in_add_del :\n  assumes \"x\\<in>j+\\<^sub>\\<omega>n\" \"n\\<in>nat\" \"j\\<in>nat\"\n  shows \"x < j \\<or> x \\<in> weak(n,j)\"\nproof (cases \"x<j\")\n  case True\n  then show ?thesis ..\nnext\n  case False\n  have \"x\\<in>nat\" \"j+\\<^sub>\\<omega>n\\<in>nat\"\n    using in_n_in_nat[OF _ \\<open>x\\<in>j+\\<^sub>\\<omega>n\\<close>] assms by simp_all\n  then\n  have \"j \\<le> x\" \"x < j+\\<^sub>\\<omega>n\"\n    using not_lt_iff_le False \\<open>j\\<in>nat\\<close> \\<open>n\\<in>nat\\<close> ltI[OF \\<open>x\\<in>j+\\<^sub>\\<omega>n\\<close>] by auto\n  then\n  have \"x-\\<^sub>\\<omega>j < (j +\\<^sub>\\<omega> n) -\\<^sub>\\<omega> j\" \"x = j +\\<^sub>\\<omega> (x -\\<^sub>\\<omega>j)\"\n    using diff_mono \\<open>x\\<in>nat\\<close> \\<open>j+\\<^sub>\\<omega>n\\<in>nat\\<close> \\<open>j\\<in>nat\\<close> \\<open>n\\<in>nat\\<close>\n      add_diff_inverse[OF \\<open>j\\<le>x\\<close>] by simp_all\n  then\n  have \"x-\\<^sub>\\<omega>j < n\" \"x = (x -\\<^sub>\\<omega>j ) +\\<^sub>\\<omega> j\"\n    using diff_add_inverse \\<open>n\\<in>nat\\<close> add_commute by simp_all\n  then\n  have \"x-\\<^sub>\\<omega>j \\<in>n\" using ltD by simp\n  then\n  have \"x \\<in> weak(n,j)\"\n    unfolding weak_def\n    using \\<open>x= (x-\\<^sub>\\<omega>j) +\\<^sub>\\<omega>j\\<close> RepFunI[OF \\<open>x-\\<^sub>\\<omega>j\\<in>n\\<close>] add_commute by force\n  then show ?thesis  ..\nqed\n\n\nlemma sep_env_action:\n  assumes\n    \"[t,p,u,P,leq,o,pi] \\<in> list(M)\"\n    \"env \\<in> list(M)\"\n  shows \"\\<forall> i . i \\<in> weak(length(env),5) \\<longrightarrow>\n      nth(sep_env(length(env))`i,[t,p,u,P,leq,o,pi]@env) = nth(i,[p,P,leq,o,t] @ env @ [pi,u])\"\nproof -\n  from assms\n  have A: \"5+\\<^sub>\\<omega>length(env)\\<in>nat\" \"[p, P, leq, o, t] \\<in>list(M)\"\n    by simp_all\n  let ?f=\"sep_env(length(env))\"\n  have EQ: \"weak(length(env),5) = 5+\\<^sub>\\<omega>length(env) - 5\"\n    using weak_equal length_type[OF \\<open>env\\<in>list(M)\\<close>] by simp\n  let ?tgt=\"[t,p,u,P,leq,o,pi]@env\"\n  let ?src=\"[p,P,leq,o,t] @ env @ [pi,u]\"\n  have \"nth(?f`i,[t,p,u,P,leq,o,pi]@env) = nth(i,[p,P,leq,o,t] @ env @ [pi,u])\"\n    if \"i \\<in> (5+\\<^sub>\\<omega>length(env)-5)\" for i\n  proof -\n    from that\n    have 2: \"i \\<in> 5+\\<^sub>\\<omega>length(env)\"  \"i \\<notin> 5\" \"i \\<in> nat\" \"i-\\<^sub>\\<omega>5\\<in>nat\" \"i+\\<^sub>\\<omega>2\\<in>nat\"\n      using in_n_in_nat[OF \\<open>5+\\<^sub>\\<omega>length(env)\\<in>nat\\<close>] by simp_all\n    then\n    have 3: \"\\<not> i < 5\" using ltD by force\n    then\n    have \"5 \\<le> i\" \"2 \\<le> 5\"\n      using  not_lt_iff_le \\<open>i\\<in>nat\\<close> by simp_all\n    then have \"2 \\<le> i\" using le_trans[OF \\<open>2\\<le>5\\<close>] by simp\n    from A \\<open>i \\<in> 5+\\<^sub>\\<omega>length(env)\\<close>\n    have \"i < 5+\\<^sub>\\<omega>length(env)\" using ltI by simp\n    with \\<open>i\\<in>nat\\<close> \\<open>2\\<le>i\\<close> A\n    have C:\"i+\\<^sub>\\<omega>2 < 7+\\<^sub>\\<omega>length(env)\"  by simp\n    with that\n    have B: \"?f`i = i+\\<^sub>\\<omega>2\" unfolding sep_env_def by simp\n    from 3 assms(1) \\<open>i\\<in>nat\\<close>\n    have \"\\<not> i+\\<^sub>\\<omega>2 < 7\" using not_lt_iff_le add_le_mono by simp\n    from \\<open>i < 5+\\<^sub>\\<omega>length(env)\\<close> 3 \\<open>i\\<in>nat\\<close>\n    have \"i-\\<^sub>\\<omega>5 < 5+\\<^sub>\\<omega>length(env) -\\<^sub>\\<omega> 5\"\n      using diff_mono[of i \"5+\\<^sub>\\<omega>length(env)\" 5,OF _ _ _ \\<open>i < 5+\\<^sub>\\<omega>length(env)\\<close>]\n        not_lt_iff_le[THEN iffD1] by force\n    with assms(2)\n    have \"i-\\<^sub>\\<omega>5 < length(env)\" using diff_add_inverse length_type by simp\n    have \"nth(i,?src) =nth(i-\\<^sub>\\<omega>5,env@[pi,u])\"\n      using nth_append[OF A(2) \\<open>i\\<in>nat\\<close>] 3 by simp\n    also\n    have \"... = nth(i-\\<^sub>\\<omega>5, env)\"\n      using nth_append[OF \\<open>env \\<in>list(M)\\<close> \\<open>i-\\<^sub>\\<omega>5\\<in>nat\\<close>] \\<open>i-\\<^sub>\\<omega>5 < length(env)\\<close> by simp\n    also\n    have \"... = nth(i+\\<^sub>\\<omega>2, ?tgt)\"\n      using nth_append[OF assms(1) \\<open>i+\\<^sub>\\<omega>2\\<in>nat\\<close>] \\<open>\\<not> i+\\<^sub>\\<omega>2 <7\\<close> by simp\n    ultimately\n    have \"nth(i,?src) = nth(?f`i,?tgt)\"\n      using B by simp\n    then show ?thesis using that by simp\n  qed\n  then show ?thesis using EQ by force\nqed\n\nlemma sep_env_type :\n  assumes \"n \\<in> nat\"\n  shows \"sep_env(n) : (5+\\<^sub>\\<omega>n)-5 \\<rightarrow> (7+\\<^sub>\\<omega>n)-7\"\nproof -\n  let ?h=\"sep_env(n)\"\n  from \\<open>n\\<in>nat\\<close>\n  have \"(5+\\<^sub>\\<omega>n)+\\<^sub>\\<omega>2 = 7+\\<^sub>\\<omega>n\" \"7+\\<^sub>\\<omega>n\\<in>nat\" \"5+\\<^sub>\\<omega>n\\<in>nat\" by simp_all\n  have\n    D: \"sep_env(n)`x \\<in> (7+\\<^sub>\\<omega>n)-7\" if \"x \\<in> (5+\\<^sub>\\<omega>n)-5\" for x\n  proof -\n    from \\<open>x\\<in>5+\\<^sub>\\<omega>n-5\\<close>\n    have \"?h`x = x+\\<^sub>\\<omega>2\" \"x<5+\\<^sub>\\<omega>n\" \"x\\<in>nat\"\n      unfolding sep_env_def using ltI in_n_in_nat[OF \\<open>5+\\<^sub>\\<omega>n\\<in>nat\\<close>] by simp_all\n    then\n    have \"x+\\<^sub>\\<omega>2 < 7+\\<^sub>\\<omega>n\" by simp\n    then\n    have \"x+\\<^sub>\\<omega>2 \\<in> 7+\\<^sub>\\<omega>n\" using ltD by simp\n    from \\<open>x\\<in>5+\\<^sub>\\<omega>n-5\\<close>\n    have \"x\\<notin>5\" by simp\n    then have \"\\<not>x<5\" using ltD by blast\n    then have \"5\\<le>x\" using not_lt_iff_le \\<open>x\\<in>nat\\<close> by simp\n    then have \"7\\<le>x+\\<^sub>\\<omega>2\" using add_le_mono \\<open>x\\<in>nat\\<close> by simp\n    then have \"\\<not>x+\\<^sub>\\<omega>2<7\" using not_lt_iff_le \\<open>x\\<in>nat\\<close> by simp\n    then have \"x+\\<^sub>\\<omega>2 \\<notin> 7\" using ltI \\<open>x\\<in>nat\\<close> by force\n    with \\<open>x+\\<^sub>\\<omega>2 \\<in> 7+\\<^sub>\\<omega>n\\<close> show ?thesis using  \\<open>?h`x = x+\\<^sub>\\<omega>2\\<close> DiffI by simp\n  qed\n  then show ?thesis unfolding sep_env_def using lam_type by simp\nqed\n\nlemma sep_var_fin_type :\n  assumes \"n \\<in> nat\"\n  shows \"sep_var(n) : 7+\\<^sub>\\<omega>n  -||> 7+\\<^sub>\\<omega>n\"\n  unfolding sep_var_def\n  using consI ltD emptyI by force\n\nlemma sep_var_domain :\n  assumes \"n \\<in> nat\"\n  shows \"domain(sep_var(n)) =  7+\\<^sub>\\<omega>n - weak(n,5)\"\nproof -\n  let ?A=\"weak(n,5)\"\n  have A:\"domain(sep_var(n)) \\<subseteq> (7+\\<^sub>\\<omega>n)\"\n    unfolding sep_var_def\n    by(auto simp add: le_natE)\n  have C: \"x=5+\\<^sub>\\<omega>n \\<or> x=6+\\<^sub>\\<omega>n \\<or> x \\<le> 4\" if \"x\\<in>domain(sep_var(n))\" for x\n    using that unfolding sep_var_def by auto\n  have D : \"x<n+\\<^sub>\\<omega>7\" if \"x\\<in>7+\\<^sub>\\<omega>n\" for x\n    using that \\<open>n\\<in>nat\\<close> ltI by simp\n  have \"\\<not> 5+\\<^sub>\\<omega>n < 5+\\<^sub>\\<omega>n\" using \\<open>n\\<in>nat\\<close>  lt_irrefl[of _ False] by force\n  have \"\\<not> 6+\\<^sub>\\<omega>n < 5+\\<^sub>\\<omega>n\" using \\<open>n\\<in>nat\\<close> by force\n  have R: \"x < 5+\\<^sub>\\<omega>n\" if \"x\\<in>?A\" for x\n  proof -\n    from that\n    obtain i where\n      \"i<n\" \"x=5+\\<^sub>\\<omega>i\"\n      unfolding weak_def\n      using ltI \\<open>n\\<in>nat\\<close> RepFun_iff by force\n    with \\<open>n\\<in>nat\\<close>\n    have \"5+\\<^sub>\\<omega>i < 5+\\<^sub>\\<omega>n\" using add_lt_mono2 by simp\n    with \\<open>x=5+\\<^sub>\\<omega>i\\<close>\n    show \"x < 5+\\<^sub>\\<omega>n\" by simp\n  qed\n  then\n  have 1:\"x\\<notin>?A\" if \"\\<not>x <5+\\<^sub>\\<omega>n\" for x using that by blast\n  have \"5+\\<^sub>\\<omega>n \\<notin> ?A\" \"6+\\<^sub>\\<omega>n\\<notin>?A\"\n  proof -\n    show \"5+\\<^sub>\\<omega>n \\<notin> ?A\" using 1 \\<open>\\<not>5+\\<^sub>\\<omega>n<5+\\<^sub>\\<omega>n\\<close> by blast\n    with 1 show \"6+\\<^sub>\\<omega>n \\<notin> ?A\" using  \\<open>\\<not>6+\\<^sub>\\<omega>n<5+\\<^sub>\\<omega>n\\<close> by blast\n  qed\n  then\n  have E:\"x\\<notin>?A\" if \"x\\<in>domain(sep_var(n))\" for x\n    unfolding weak_def\n    using C that by force\n  then\n  have F: \"domain(sep_var(n)) \\<subseteq> 7+\\<^sub>\\<omega>n - ?A\" using A by auto\n  from assms\n  have \"x<7 \\<or> x\\<in>weak(n,7)\" if \"x\\<in>7+\\<^sub>\\<omega>n\" for x\n    using in_add_del[OF \\<open>x\\<in>7+\\<^sub>\\<omega>n\\<close>] by simp\n  moreover\n  {\n    fix x\n    assume asm:\"x\\<in>7+\\<^sub>\\<omega>n\"  \"x\\<notin>?A\"  \"x\\<in>weak(n,7)\"\n    then\n    have \"x\\<in>domain(sep_var(n))\"\n    proof -\n      from \\<open>n\\<in>nat\\<close>\n      have \"weak(n,7)-weak(n,5)\\<subseteq>{n+\\<^sub>\\<omega>5,n+\\<^sub>\\<omega>6}\"\n        using weakening_diff by simp\n      with  \\<open>x\\<notin>?A\\<close> asm\n      have \"x\\<in>{n+\\<^sub>\\<omega>5,n+\\<^sub>\\<omega>6}\" using  subsetD DiffI by blast\n      then\n      show ?thesis unfolding sep_var_def by simp\n    qed\n  }\n  moreover\n  {\n    fix x\n    assume asm:\"x\\<in>7+\\<^sub>\\<omega>n\"  \"x\\<notin>?A\" \"x<7\"\n    then have \"x\\<in>domain(sep_var(n))\"\n    proof (cases \"2 \\<le> n\")\n      case True\n      moreover\n      have \"0<n\" using  leD[OF \\<open>n\\<in>nat\\<close> \\<open>2\\<le>n\\<close>] lt_imp_0_lt by auto\n      ultimately\n      have \"x<5\"\n        using \\<open>x<7\\<close> \\<open>x\\<notin>?A\\<close> \\<open>n\\<in>nat\\<close> in_n_in_nat\n        unfolding weak_def\n        by (clarsimp simp add:not_lt_iff_le, auto simp add:lt_def)\n      then\n      show ?thesis unfolding sep_var_def\n        by (clarsimp simp add:not_lt_iff_le, auto simp add:lt_def)\n    next\n      case False\n      then\n      show ?thesis\n      proof (cases \"n=0\")\n        case True\n        then show ?thesis\n          unfolding sep_var_def using ltD asm \\<open>n\\<in>nat\\<close> by auto\n      next\n        case False\n        then\n        have \"n < 2\" using  \\<open>n\\<in>nat\\<close> not_lt_iff_le \\<open>\\<not> 2 \\<le> n\\<close>  by force\n        then\n        have \"\\<not> n <1\" using \\<open>n\\<noteq>0\\<close> by simp\n        then\n        have \"n=1\" using not_lt_iff_le \\<open>n<2\\<close> le_iff by auto\n        then show ?thesis\n          using \\<open>x\\<notin>?A\\<close>\n          unfolding weak_def sep_var_def\n          using ltD asm \\<open>n\\<in>nat\\<close> by force\n      qed\n    qed\n  }\n  ultimately\n  have \"w\\<in>domain(sep_var(n))\" if \"w\\<in> 7+\\<^sub>\\<omega>n - ?A\" for w\n    using that by blast\n  then\n  have \"7+\\<^sub>\\<omega>n - ?A \\<subseteq> domain(sep_var(n))\" by blast\n  with F\n  show ?thesis by auto\nqed\n\nlemma sep_var_type :\n  assumes \"n \\<in> nat\"\n  shows \"sep_var(n) : (7+\\<^sub>\\<omega>n)-weak(n,5) \\<rightarrow> 7+\\<^sub>\\<omega>n\"\n  using FiniteFun_is_fun[OF sep_var_fin_type[OF \\<open>n\\<in>nat\\<close>]]\n    sep_var_domain[OF \\<open>n\\<in>nat\\<close>] by simp\n\nlemma sep_var_action :\n  assumes\n    \"[t,p,u,P,leq,o,pi] \\<in> list(M)\"\n    \"env \\<in> list(M)\"\n  shows \"\\<forall> i . i \\<in> (7+\\<^sub>\\<omega>length(env)) - weak(length(env),5) \\<longrightarrow>\n    nth(sep_var(length(env))`i,[t,p,u,P,leq,o,pi]@env) = nth(i,[p,P,leq,o,t] @ env @ [pi,u])\"\n  using assms\nproof (subst sep_var_domain[OF length_type[OF \\<open>env\\<in>list(M)\\<close>],symmetric],auto)\n  fix i y\n  assume \"\\<langle>i, y\\<rangle> \\<in> sep_var(length(env))\"\n  with assms\n  show \"nth(sep_var(length(env)) ` i,\n               Cons(t, Cons(p, Cons(u, Cons(P, Cons(leq, Cons(o, Cons(pi, env)))))))) =\n           nth(i, Cons(p, Cons(P, Cons(leq, Cons(o, Cons(t, env @ [pi, u]))))))\"\n    using apply_fun[OF sep_var_type] assms\n    unfolding sep_var_def\n    using nth_concat2[OF \\<open>env\\<in>list(M)\\<close>]  nth_concat3[OF \\<open>env\\<in>list(M)\\<close>,symmetric]\n    by force\nqed\n\ndefinition\n  rensep :: \"i \\<Rightarrow> i\" where\n  \"rensep(n) \\<equiv> union_fun(sep_var(n),sep_env(n),7+\\<^sub>\\<omega>n-weak(n,5),weak(n,5))\"\n\nlemma rensep_aux :\n  assumes \"n\\<in>nat\"\n  shows \"(7+\\<^sub>\\<omega>n-weak(n,5)) \\<union> weak(n,5) = 7+\\<^sub>\\<omega>n\" \"7+\\<^sub>\\<omega>n \\<union> ( 7 +\\<^sub>\\<omega> n - 7) = 7+\\<^sub>\\<omega>n\"\nproof -\n  from \\<open>n\\<in>nat\\<close>\n  have \"weak(n,5) = n+\\<^sub>\\<omega>5-5\"\n    using weak_equal by simp\n  with  \\<open>n\\<in>nat\\<close>\n  show \"(7+\\<^sub>\\<omega>n-weak(n,5)) \\<union> weak(n,5) = 7+\\<^sub>\\<omega>n\" \"7+\\<^sub>\\<omega>n \\<union> ( 7 +\\<^sub>\\<omega> n - 7) = 7+\\<^sub>\\<omega>n\"\n    using Diff_partition le_imp_subset by auto\nqed\n\nlemma rensep_type :\n  assumes \"n\\<in>nat\"\n  shows \"rensep(n) \\<in> 7+\\<^sub>\\<omega>n \\<rightarrow> 7+\\<^sub>\\<omega>n\"\nproof -\n  from \\<open>n\\<in>nat\\<close>\n  have \"rensep(n) \\<in> (7+\\<^sub>\\<omega>n-weak(n,5)) \\<union> weak(n,5) \\<rightarrow> 7+\\<^sub>\\<omega>n \\<union> (7+\\<^sub>\\<omega>n - 7)\"\n    unfolding rensep_def\n    using union_fun_type  sep_var_type \\<open>n\\<in>nat\\<close> sep_env_type weak_equal\n    by force\n  then\n  show ?thesis using rensep_aux \\<open>n\\<in>nat\\<close> by auto\nqed\n\nlemma rensep_action :\n  assumes \"[t,p,u,P,leq,o,pi] @ env \\<in> list(M)\"\n  shows \"\\<forall> i . i < 7+\\<^sub>\\<omega>length(env) \\<longrightarrow> nth(rensep(length(env))`i,[t,p,u,P,leq,o,pi]@env) = nth(i,[p,P,leq,o,t] @ env @ [pi,u])\"\nproof -\n  let ?tgt=\"[t,p,u,P,leq,o,pi]@env\"\n  let ?src=\"[p,P,leq,o,t] @ env @ [pi,u]\"\n  let ?m=\"7 +\\<^sub>\\<omega> length(env) - weak(length(env),5)\"\n  let ?p=\"weak(length(env),5)\"\n  let ?f=\"sep_var(length(env))\"\n  let ?g=\"sep_env(length(env))\"\n  let ?n=\"length(env)\"\n  from assms\n  have 1 : \"[t,p,u,P,leq,o,pi] \\<in> list(M)\" \" env \\<in> list(M)\"\n    \"?src \\<in> list(M)\" \"?tgt \\<in> list(M)\"\n    \"7+\\<^sub>\\<omega>?n = (7+\\<^sub>\\<omega>?n-weak(?n,5)) \\<union> weak(?n,5)\"\n    \" length(?src) = (7+\\<^sub>\\<omega>?n-weak(?n,5)) \\<union> weak(?n,5)\"\n    using Diff_partition le_imp_subset rensep_aux by auto\n  then\n  have \"nth(i, ?src) = nth(union_fun(?f, ?g, ?m, ?p) ` i, ?tgt)\" if \"i < 7+\\<^sub>\\<omega>length(env)\" for i\n  proof -\n    from \\<open>i<7+\\<^sub>\\<omega>?n\\<close>\n    have \"i \\<in> (7+\\<^sub>\\<omega>?n-weak(?n,5)) \\<union> weak(?n,5)\"\n      using ltD by simp\n    then show ?thesis\n      unfolding rensep_def using\n        union_fun_action[OF \\<open>?src\\<in>list(M)\\<close> \\<open>?tgt\\<in>list(M)\\<close> \\<open>length(?src) = (7+\\<^sub>\\<omega>?n-weak(?n,5)) \\<union> weak(?n,5)\\<close>\n          sep_var_action[OF \\<open>[t,p,u,P,leq,o,pi] \\<in> list(M)\\<close> \\<open>env\\<in>list(M)\\<close>]\n          sep_env_action[OF \\<open>[t,p,u,P,leq,o,pi] \\<in> list(M)\\<close> \\<open>env\\<in>list(M)\\<close>]\n          ] that\n      by simp\n  qed\n  then show ?thesis unfolding rensep_def by simp\nqed\n\ndefinition sep_ren :: \"[i,i] \\<Rightarrow> i\" where\n  \"sep_ren(n,\\<phi>) \\<equiv> ren(\\<phi>)`(7+\\<^sub>\\<omega>n)`(7+\\<^sub>\\<omega>n)`rensep(n)\"\n\nlemma arity_rensep: assumes \"\\<phi>\\<in>formula\" \"env \\<in> list(M)\"\n  \"arity(\\<phi>) \\<le> 7+\\<^sub>\\<omega>length(env)\"\nshows \"arity(sep_ren(length(env),\\<phi>)) \\<le> 7+\\<^sub>\\<omega>length(env)\"\n  unfolding sep_ren_def\n  using arity_ren rensep_type assms\n  by simp\n\nlemma type_rensep [TC]:\n  assumes \"\\<phi>\\<in>formula\" \"env\\<in>list(M)\"\n  shows \"sep_ren(length(env),\\<phi>) \\<in> formula\"\n  unfolding sep_ren_def\n  using ren_tc rensep_type assms\n  by simp\n\nlemma sepren_action:\n  assumes \"arity(\\<phi>) \\<le> 7 +\\<^sub>\\<omega> length(env)\"\n    \"[t,p,u,P,leq,o,pi] \\<in> list(M)\"\n    \"env\\<in>list(M)\"\n    \"\\<phi>\\<in>formula\"\n  shows \"sats(M, sep_ren(length(env),\\<phi>),[t,p,u,P,leq,o,pi] @ env) \\<longleftrightarrow> sats(M, \\<phi>,[p,P,leq,o,t] @ env @ [pi,u])\"\nproof -\n  from assms\n  have 1: \"[t, p, u, P, leq, o, pi] @ env \\<in> list(M)\"\n    by simp_all\n  then\n  have 2: \"[p,P,leq,o,t] @ env @ [pi,u] \\<in> list(M)\"\n    using app_type by simp\n  show ?thesis\n    unfolding sep_ren_def\n    using sats_iff_sats_ren[OF \\<open>\\<phi>\\<in>formula\\<close>\n        add_type[of 7 \"length(env)\"]\n        add_type[of 7 \"length(env)\"]\n        2 1\n        rensep_type[OF length_type[OF \\<open>env\\<in>list(M)\\<close>]]\n        \\<open>arity(\\<phi>) \\<le> 7 +\\<^sub>\\<omega> length(env)\\<close>]\n      rensep_action[OF 1,rule_format,symmetric]\n    by simp\nqed\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Independence_CH/Separation_Rename.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.29674486675141715}}
{"text": "\\<^marker>\\<open>creator \"Alexander Krauss\"\\<close>\n\\<^marker>\\<open>creator \"Kevin Kappelmann\"\\<close>\nsection \\<open>Soft types for HOL\\<close>\ntheory Soft_Types_HOL\n  imports\n    HOL.HOL\n    Implicit_Arguments\n    \"HOL-Eisbach.Eisbach\"\n  keywords\n    \"opaque\" :: thy_decl and\n    \"soft_type_translation\" :: thy_goal_stmt and\n    \"print_opaque_terms\" \"print_types\" :: diag\nbegin\n\ntext \\<open>This theory introduces a generic notion of soft types based on HOL\npredicates. It contains the basic definitions and technical tool setup.\\<close>\n\ntext \\<open>Remove conflicting HOL-specific syntax.\\<close>\n\nbundle HOL_ascii_syntax\nbegin\nnotation (ASCII)\n  Not (\"~ _\" [40] 40) and\n  conj (infixr \"&\" 35) and\n  disj (infixr \"|\" 30) and\n  implies (infixr \"-->\" 25) and\n  not_equal (infixl \"~=\" 50)\nsyntax \"_Let\" :: \"[letbinds, 'a] \\<Rightarrow> 'a\" (\"(let (_)/ in (_))\" 10)\nend\nbundle no_HOL_ascii_syntax\nbegin\nno_notation (ASCII)\n  Not (\"~ _\" [40] 40) and\n  conj (infixr \"&\" 35) and\n  disj (infixr \"|\" 30) and\n  implies (infixr \"-->\" 25) and\n  not_equal (infixl \"~=\" 50)\nno_syntax \"_Let\" :: \"[letbinds, 'a] \\<Rightarrow> 'a\" (\"(let (_)/ in (_))\" 10)\nend\n\nunbundle no_HOL_ascii_syntax\n\n\nsubsection \\<open>Basic type judgments\\<close>\n\ntext \\<open>Soft types are \"just\" predicates wrapped up in a constructor.\\<close>\n\ntypedecl 'a type\n\naxiomatization\n  type :: \\<open>('a \\<Rightarrow> bool) \\<Rightarrow> 'a type\\<close> and\n  adj :: \\<open>('a \\<Rightarrow> bool) \\<Rightarrow> 'a type \\<Rightarrow> 'a type\\<close>  and\n  has_type :: \\<open>'a \\<Rightarrow> 'a type \\<Rightarrow> bool\\<close>\nwhere\n  meaning_of_adj: \"has_type x (adj P T) \\<equiv> P x \\<and> has_type x T\" and\n  meaning_of_type: \"has_type x (type P) \\<equiv> P x\"\n\nbundle soft_type_base_syntax\nbegin notation adj (infixr \"\\<sqdot>\" \\<comment>\\<open>\\<sqdot>\\<close> 56) and has_type (infix \":\" 45) end\nbundle no_soft_type_base_syntax\nbegin no_notation adj (infixr \"\\<sqdot>\" \\<comment>\\<open>\\<sqdot>\\<close> 56) and has_type (infix \":\" 45) end\n\nunbundle soft_type_base_syntax\n\nabbreviation (input) \"type_pred T x \\<equiv> x : T\"\n\nlemma has_typeI: \"P x \\<Longrightarrow> x : type P\"\n  unfolding meaning_of_type by assumption\n\nlemma has_typeD: \"x : type P \\<Longrightarrow> P x\"\n  unfolding meaning_of_type by assumption\n\nlemma has_typeE:\n  assumes \"x : type P\"\n  obtains \"P x\"\n  using assms unfolding meaning_of_type by auto\n\nlemma has_adjI: \"\\<lbrakk>P x; x : T\\<rbrakk> \\<Longrightarrow> x : P \\<sqdot> T\"\n  unfolding meaning_of_adj by auto\n\nlemma\n  has_adjD1: \"x : P \\<sqdot> T \\<Longrightarrow> P x\" and\n  has_adjD2: \"x : P \\<sqdot> T \\<Longrightarrow> x : T\"\n  unfolding meaning_of_adj by auto\n\nlemma has_adjE:\n  \"\\<lbrakk>x: P \\<sqdot> T; \\<lbrakk>P x; x : T\\<rbrakk> \\<Longrightarrow> Q\\<rbrakk> \\<Longrightarrow> Q\"\n  unfolding meaning_of_adj by auto\n\n\nsubsection \\<open>Type-Bounded quantifiers\\<close>\n\ndefinition tball :: \"'a type \\<Rightarrow> ('a \\<Rightarrow> bool) \\<Rightarrow> bool\"\n  where \"tball A P \\<equiv> (\\<forall>x. x : A \\<longrightarrow> P x)\"\n\ndefinition tbex :: \"'a type \\<Rightarrow> ('a \\<Rightarrow> bool) \\<Rightarrow> bool\"\n  where \"tbex A P \\<equiv> (\\<exists>x. x : A \\<and> P x)\"\n\nbundle soft_types_bounded_quantifiers_syntax\nbegin\nsyntax\n  \"_tball\"  :: \\<open>[idts, 'a type, bool] \\<Rightarrow> bool\\<close> (\"(2\\<forall>_ : _./ _)\" 10)\n  \"_tball2\" :: \\<open>[idts, 'a type, bool] \\<Rightarrow> bool\\<close>\n  \"_tbex\"   :: \\<open>[idts, 'a type, bool] \\<Rightarrow> bool\\<close> (\"(2\\<exists>_ : _./ _)\" 10)\n  \"_tbex2\"  :: \\<open>[idts, 'a type, bool] \\<Rightarrow> bool\\<close>\nend\nbundle no_soft_types_bounded_quantifiers_syntax\nbegin\nno_syntax\n  \"_tball\"  :: \\<open>[idts, 'a type, bool] \\<Rightarrow> bool\\<close> (\"(2\\<forall>_ : _./ _)\" 10)\n  \"_tball2\" :: \\<open>[idts, 'a type, bool] \\<Rightarrow> bool\\<close>\n  \"_tbex\"   :: \\<open>[idts, 'a type, bool] \\<Rightarrow> bool\\<close> (\"(2\\<exists>_ : _./ _)\" 10)\n  \"_tbex2\"  :: \\<open>[idts, 'a type, bool] \\<Rightarrow> bool\\<close>\nend\nunbundle soft_types_bounded_quantifiers_syntax\n\ntranslations\n  \"\\<forall>x xs : A. P\" \\<rightharpoonup> \"CONST tball A (\\<lambda>x. _tball2 xs A P)\"\n  \"_tball2 x A P\" \\<rightharpoonup> \"\\<forall>x : A. P\"\n  \"\\<forall>x : A. P\" \\<rightleftharpoons> \"CONST tball A (\\<lambda>x. P)\"\n\n  \"\\<exists>x xs : A. P\" \\<rightharpoonup> \"CONST tbex A (\\<lambda>x. _tbex2 xs A P)\"\n  \"_tbex2 x A P\" \\<rightharpoonup> \"\\<exists>x : A. P\"\n  \"\\<exists>x : A. P\" \\<rightleftharpoons> \"CONST tbex A (\\<lambda>x. P)\"\n\n\ntext\\<open>Setup of one point rules.\\<close>\n\nsimproc_setup defined_bex (\"\\<exists>x : A. P x \\<and> Q x\") =\n  \\<open>fn _ => Quantifier1.rearrange_Bex\n    (fn ctxt => unfold_tac ctxt @{thms tbex_def})\\<close>\n\nsimproc_setup defined_ball (\"\\<forall>x : A. P x \\<longrightarrow> Q x\") =\n  \\<open>fn _ => Quantifier1.rearrange_Ball\n    (fn ctxt => unfold_tac ctxt @{thms tball_def})\\<close>\n\nlemma tballI [intro!]: \"(\\<And>x. x : A \\<Longrightarrow> P x) \\<Longrightarrow> \\<forall>x : A. P x\"\n  unfolding tball_def by auto\n\nlemma tballE [elim!]:\n  assumes \"\\<forall>x : A. P x\"\n  obtains \"\\<And>x. x : A \\<Longrightarrow> P x\"\n  using assms unfolding tball_def by auto\n\nlemma tballD [elim]: \"\\<lbrakk>\\<forall>x : A. P x; x : A\\<rbrakk> \\<Longrightarrow> P x\"\n  unfolding tball_def by auto\n\nlemma tball_iff_ex_has_type [simp]: \"(\\<forall>x : A. P) \\<longleftrightarrow> ((\\<exists>x. x : A) \\<longrightarrow> P)\"\n  by (simp add: tball_def)\n\nlemma tball_cong [cong]:\n  \"\\<lbrakk>A = A'; \\<And>x. x : A' \\<Longrightarrow> P x \\<longleftrightarrow> P' x\\<rbrakk> \\<Longrightarrow> (\\<forall>x : A. P x) \\<longleftrightarrow> (\\<forall>x : A'. P' x)\"\n  by (simp add: tball_def)\n\nlemma tball_or_iff_tball_or [simp]: \"(\\<forall>x : A. P x \\<or> Q) \\<longleftrightarrow> ((\\<forall>x : A. P x) \\<or> Q)\"\n  by auto\n\nlemma tball_or_iff_or_tball [simp]: \"(\\<forall>x : A. P \\<or> Q x) \\<longleftrightarrow> (P \\<or> (\\<forall>x : A. Q x))\"\n  by auto\n\nlemma tball_imp_iff_imp_tball [simp]: \"(\\<forall>x : A. P \\<longrightarrow> Q x) \\<longleftrightarrow> (P \\<longrightarrow> (\\<forall>x : A. Q x))\"\n  by auto\n\nlemma atomize_tball: \"(\\<And>x. x : A \\<Longrightarrow> P x) \\<equiv> Trueprop (\\<forall>x : A. P x)\"\n  by (simp only: tball_def atomize_all atomize_imp)\n\ndeclare atomize_tball[symmetric, rulify]\ndeclare atomize_tball[symmetric, defn]\n\nlemma tbexI [intro]: \"\\<lbrakk>x : A; P x\\<rbrakk> \\<Longrightarrow> \\<exists>x : A. P x\"\n  unfolding tbex_def by auto\n\nlemma tbexE [elim!]:\n  assumes \"\\<exists>x : A. P x\"\n  obtains x where \"x : A\" and \"P x\"\n  using assms unfolding tbex_def by auto\n\nlemma tbex_iff_ex_and [simp]: \"(\\<exists>x : A. P) \\<longleftrightarrow> ((\\<exists>x. x : A) \\<and> P)\"\n  unfolding tbex_def by simp\n\nlemma tbex_cong [cong]:\n  \"\\<lbrakk>A = A'; \\<And>x. x : A' \\<Longrightarrow> P x \\<longleftrightarrow> P' x\\<rbrakk> \\<Longrightarrow> (\\<exists>x : A. P x) \\<longleftrightarrow> (\\<exists>x : A'. P' x)\"\n  unfolding tbex_def by (simp cong: conj_cong)\n\nlemma tbex_and_iff_tbex_and [simp]: \"(\\<exists>x : A. P x \\<and> Q) \\<longleftrightarrow> ((\\<exists>x : A. P x) \\<and> Q)\"\n  by auto\n\nlemma tbex_and_iff_or_tbex [simp]: \"(\\<exists>x : A. P \\<and> Q x) \\<longleftrightarrow> (P \\<and> (\\<exists>x : A. Q x))\"\n  by auto\n\nlemma tball_imp_iff_tbex_imp [simp]: \"(\\<forall>x : A. P x \\<longrightarrow> Q) \\<longleftrightarrow> ((\\<exists>x : A. P x) \\<longrightarrow> Q)\"\n  by auto\n\nlemma not_tball_iff_tbex_not [simp]: \"(\\<not>(\\<forall>x : A. P x)) \\<longleftrightarrow> (\\<exists>x : A. \\<not>P x)\"\n  by auto\n\nlemma not_tbex_iff_tball_not [simp]: \"(\\<not>(\\<exists>x : A. P x)) \\<longleftrightarrow> (\\<forall>x : A. \\<not>P x)\"\n  by auto\n\n\nsubsection \\<open>Low-level soft type methods\\<close>\n\n(*FUTURE: Dedicated keyword setup for soft type declarations should go here*)\n\ntext \\<open>Unfold all type information to work only in the underlying theory:\\<close>\n\nnamed_theorems typedef \\<comment>\\<open>soft type definitions\\<close>\nnamed_theorems type_intro \\<comment>\\<open>soft type introduction rules\\<close>\n  (*FUTURE: This should be kept for typechecking, so only introduction rules\n    whose premises and conclusion are type judgments should be declared*)\n\nmethod unfold_types =\n  (rule type_intro\n  |simp_all only: typedef meaning_of_type meaning_of_adj tball_def tbex_def)+\n\n\nsubsection \\<open>Dependent Function/Pi-Types (\\<Pi>-Types)\\<close>\n\ntext \\<open>Dependent function soft type for HOL lambda terms.\\<close>\n\ndefinition Dep_fun_type :: \"'a type \\<Rightarrow> ('a \\<Rightarrow> 'b type) \\<Rightarrow> ('a \\<Rightarrow> 'b) type\"\n  where [typedef]: \"Dep_fun_type A B \\<equiv> type (\\<lambda>f. \\<forall>x : A. f x : B x)\"\n\nabbreviation \"Fun_type A B \\<equiv> Dep_fun_type A (\\<lambda>_. B)\"\n\nbundle soft_types_functions_syntax\nbegin\nsyntax\n  \"_functions_telescope\" :: \"logic \\<Rightarrow> logic \\<Rightarrow> logic\"  (infixr \"\\<Rightarrow>\" 50)\nend\nbundle no_soft_types_functions_syntax\nbegin\nno_syntax\n  \"_functions_telescope\" :: \"logic \\<Rightarrow> logic \\<Rightarrow> logic\"  (infixr \"\\<Rightarrow>\" 50)\nend\nunbundle soft_types_functions_syntax\n\ntranslations\n  \"(x y : A) \\<Rightarrow> B\" \\<rightharpoonup> \"(x : A)(y : A) \\<Rightarrow> B\"\n  \"(x : A) args \\<Rightarrow> B\" \\<rightleftharpoons> \"(x : A) \\<Rightarrow> args \\<Rightarrow> B\"\n  \"(x : A) \\<Rightarrow> B\" \\<rightleftharpoons> \"CONST Dep_fun_type A (\\<lambda>x. B)\"\n  \"A \\<Rightarrow> B\" \\<rightleftharpoons> \"CONST Fun_type A B\"\n\nlemma Dep_fun_typeI [type_intro]:\n  \"(\\<And>x. x : A \\<Longrightarrow> f x : B x) \\<Longrightarrow> f : (x : A) \\<Rightarrow> B x\"\n  unfolding Dep_fun_type_def meaning_of_type by auto\n\nlemma Dep_fun_typeE:\n  \"\\<lbrakk>f : (x : A) \\<Rightarrow> B x; x : A\\<rbrakk> \\<Longrightarrow> f x : B x\"\n  unfolding Dep_fun_type_def meaning_of_type by auto\n\nlemma Dep_fun_contravariant_dom:\n  \"\\<lbrakk>f : (x : A) \\<Rightarrow> B x; \\<And>x. x : A' \\<Longrightarrow> x : A\\<rbrakk> \\<Longrightarrow> f : (x : A') \\<Rightarrow> B x\"\n  unfolding Dep_fun_type_def meaning_of_type by auto\n\nlemma Dep_fun_covariant_codom:\n  assumes \"f : (x : A) \\<Rightarrow> B x\"\n  and \"\\<And>x. x : A \\<Longrightarrow> f x : B x \\<Longrightarrow> f x : B' x\"\n  shows \"f : (x : A) \\<Rightarrow> B' x\"\n  using assms unfolding Dep_fun_type_def meaning_of_type by auto\n\n\nsubsection \\<open>Intersection and Union Types\\<close>\n\ndefinition [typedef]: \"Int_type A B \\<equiv> type (\\<lambda>x. x : A \\<and> x : B)\"\n\nbundle soft_type_Int_type_syntax\nbegin notation Int_type (infixl \"&\" 55) end\nbundle no_soft_type_Int_type_syntax\nbegin no_notation Int_type (infixl \"&\" 55) end\n\nunbundle soft_type_Int_type_syntax\n\nlemma\n  Int_typeI [type_intro]: \"x : A \\<Longrightarrow> x : B \\<Longrightarrow> x : A & B\" and\n  Int_typeD1: \"x : A & B \\<Longrightarrow> x : A\" and\n  Int_typeD2: \"x : A & B \\<Longrightarrow> x : B\" and\n  Int_type_covariant_left: \"x : A & B \\<Longrightarrow> (x : A \\<Longrightarrow> x : A') \\<Longrightarrow> x : A' & B\" and\n  Int_type_covariant_right: \"x : A & B \\<Longrightarrow> (x : B \\<Longrightarrow> x : B') \\<Longrightarrow> x : A & B'\"\n  by unfold_types\n\nlemma Int_typeE:\n  assumes \"x : A & B\"\n  obtains \"x : A\" \"x : B\"\n  using assms unfolding Int_type_def by unfold_types\n\ndefinition [typedef]: \"Union_type A B \\<equiv> type (\\<lambda>x. x : A \\<or> x : B)\"\n\nbundle soft_type_Union_type_syntax\nbegin notation Union_type (infixl \"\\<bar>\" 55) end\nbundle no_soft_type_Union_type_syntax\nbegin no_notation Union_type (infixl \"\\<bar>\" 55) end\n\nunbundle soft_type_Union_type_syntax\n\nlemma\n  Union_type_leftI: \"x : A \\<Longrightarrow> x : A \\<bar> B\" and\n  Union_type_rightI: \"x : B \\<Longrightarrow> x : A \\<bar> B\" and\n  Union_typeD: \"x : A \\<bar> B \\<Longrightarrow> x : A \\<or> x : B\" and\n  Union_type_covariant_left: \"x : A \\<bar> B \\<Longrightarrow> (x : A \\<Longrightarrow> x : A') \\<Longrightarrow> x : A' \\<bar> B\" and\n  Union_type_covariant_right: \"x : A \\<bar> B \\<Longrightarrow> (x : B \\<Longrightarrow> x : B') \\<Longrightarrow> x : A \\<bar> B'\"\n  by unfold_types auto\n\nlemma Union_typeE:\n  assumes \"x : A \\<bar> B\"\n  obtains (left) \"x : A\" | (right) \"x : B\"\n  using assms by (auto dest: Union_typeD)\n\nsubsection \\<open>The Any type\\<close>\n\ntext \\<open>Used, for example, to reflect rigid types back into the soft type system.\\<close>\n\ndefinition Any_type :: \"'a type\" (\"Any\")\n  where [typedef]: \"Any \\<equiv> type (\\<lambda>_. True)\"\n\nlemma Any_typeI [type_intro]: \"x : Any\"\n  by unfold_types\n\nabbreviation Bool_type :: \"bool type\" (\"Bool\")\n  where \"Bool \\<equiv> Any\"\n\nlemma tball_Any_iff_ball [simp]: \"(\\<forall>x : Any. P x) \\<longleftrightarrow> (\\<forall>x. P x)\"\n  by (auto intro: Any_typeI)\n\nlemma tbex_Any_iff_ex [simp]: \"(\\<exists>x : Any. P x) \\<longleftrightarrow> (\\<exists>x. P x)\"\n  by (auto intro: Any_typeI)\n\n\nsubsection \\<open>Type annotations\\<close>\n\ndefinition with_type :: \"'a \\<Rightarrow> 'a type \\<Rightarrow> 'a\"\n  where \"with_type x A \\<equiv> x\"\n\nbundle soft_type_with_type_syntax\nbegin notation with_type (infixl \":>\" 50) end\nbundle no_soft_type_with_type_syntax\nbegin no_notation with_type (infixl \":>\" 50) end\n\nunbundle soft_type_with_type_syntax\n\ntext \\<open>\n\\<^term>\\<open>x :> A\\<close> annotates \\<^term>\\<open>x\\<close> with type \\<^term>\\<open>A\\<close>, and is used by automated\ntools to represent additional typing information in a term.\n\\<close>\n\n\nsubsection \\<open>Tooling and automation\\<close>\n\ndeclare atomize_conjL [symmetric, rulify]\n  \\<comment>\\<open>Used in normalization of type judgments.\\<close>\n\nnamed_theorems type_simp \\<comment>\\<open>For type elaboration\\<close>\nnamed_theorems type_instance \\<comment>\\<open>For type class reasoning\\<close>\n\n\nnamed_theorems derivation_rules\nnamed_theorems backderivation_rules\n(* named_theorems subtype_rules *) \\<comment>\\<open>Unused, for now\\<close>\n\ntext \\<open>\n@{thm derivation_rules}, @{thm backderivation_rules} \\<open>(*and @{thm subtype_rules}*)\\<close>\nshould only be inspected and not assigned to directly; use the \\<open>derive\\<close>,\n\\<open>backward_derive\\<close> \\<open>(*and \\<open>subtype\\<close>*)\\<close> attributes instead.\n\\<close>\n\n(* Enable this when debugging exceptions:\ndeclare [[ML_debugger, ML_exception_debugger]]\n*)\n\nML_file \\<open>soft_type.ML\\<close>\nML_file \\<open>soft_type_context.ML\\<close>\nML_file \\<open>derivation.ML\\<close>\n\nsubsubsection \\<open>Type derivation\\<close>\n\nmethod_setup raw_discharge_type =\n  \\<open>Scan.optional (Scan.lift (Args.add -- Args.colon) |-- Scan.repeat Args.term) []\n    >> (fn add_tms => fn ctxt => SIMPLE_METHOD (\n      HEADGOAL (Derivation.raw_discharge_type_tac [] add_tms ctxt)))\\<close>\n\nmethod_setup discharge_types =\n  \\<open>Scan.optional (Scan.lift (Args.add -- Args.colon) |-- Scan.repeat Args.term) []\n    >> (fn add_tms => fn ctxt => SIMPLE_METHOD (\n      REPEAT1 (CHANGED (ALLGOALS (TRY o (\n        Derivation.full_discharge_types_tac [] add_tms ctxt))))))\\<close>\n\nML \\<open>\nval soft_type_simp_solver =\n  let\n    fun solver ctxt i =\n      (if Config.get ctxt Derivation.debug\n      then print_tac ctxt (\"type derivation called on subgoal \" ^ string_of_int i)\n      else all_tac)\n      THEN\n      (SUBGOAL (fn (_, j) =>\n        Derivation.full_discharge_types_tac (Simplifier.prems_of ctxt) [] ctxt j)) i\n  in\n    map_theory_simpset (fn ctxt => ctxt\n      addSolver (mk_solver \"discharge_types\" solver))\n  end\n\\<close>\n\nsetup \\<open>soft_type_simp_solver\\<close>\n\nML_file \\<open>unification.ML\\<close>\nML_file \\<open>type_classes.ML\\<close>\nML_file \\<open>elaboration.ML\\<close>\nML_file \\<open>isar_integration.ML\\<close>\n\nsetup \\<open>Isar_Integration.setup\\<close>\n\ndeclare with_type_def [type_simp]\n\n\nsubsection \\<open>Basic declarations\\<close>\n\ndeclare Any_typeI [type]\ndeclare Dep_fun_typeI [backward_derive]\ndeclare Dep_fun_typeE [derive]\n\nlemma eq_type [type]: \"(=) : A \\<Rightarrow> A \\<Rightarrow> Bool\"\n  by discharge_types\n\nlemma imp_type [type]: \"(\\<longrightarrow>) : Bool \\<Rightarrow> Bool \\<Rightarrow> Bool\"\n  by discharge_types\n\nlemma const_fun_type [derive]: \"c : C \\<Longrightarrow> (\\<lambda>a. c) : A \\<Rightarrow> C\"\n  by discharge_types\n\nlemma id_type [type]: \"(\\<lambda>x. x) : A \\<Rightarrow> A\"\n  by discharge_types\n\nlemma if_type [type]: \"If : Bool \\<Rightarrow> A \\<Rightarrow> A \\<Rightarrow> A\"\n  by unfold_types auto\n\n\nend\n", "meta": {"author": "kappelmann", "repo": "Isabelle-Set", "sha": "2ac3e1cb6bf847d413f06978b7c82e4d0c103477", "save_path": "github-repos/isabelle/kappelmann-Isabelle-Set", "path": "github-repos/isabelle/kappelmann-Isabelle-Set/Isabelle-Set-2ac3e1cb6bf847d413f06978b7c82e4d0c103477/Soft_Types/Soft_Types_HOL.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.588889130767832, "lm_q1q2_score": 0.29674486675141715}}
{"text": "theory WordArrayMono\n  imports \n    WordArrayValue\n    Cogent.Mono\n    MonoHelper\nbegin\n\nsection \"Word Array Methods\"\n\nsubsection \"wordarray_length\"\n\nlemma (in WordArrayValue) vwa_length_monoexpr_correct:\n  \"\\<And>v v'.\n       vwa_length (rename_val rename' (monoval v)) v'\n       \\<Longrightarrow> \\<exists>v''. v' = rename_val rename' (monoval v'') \\<and> vwa_length v v''\"\n  apply (clarsimp simp: vwa_length_def)\n  apply (case_tac v; clarsimp)\n  done\n\nsubsection \"wordarray_get\"\n\nlemma (in WordArrayValue) vwa_get_monoexpr_correct:\n  \"\\<And>v v'.\n       vwa_get (rename_val rename' (monoval v)) v'\n       \\<Longrightarrow> \\<exists>v''. v' = rename_val rename' (monoval v'') \\<and> vwa_get v v''\"\n  apply (clarsimp simp: vwa_get_def)\n  apply (case_tac v; clarsimp)\n  apply (rename_tac z za zb)\n  apply (case_tac z; clarsimp)\n  apply (case_tac za; clarsimp)\n  apply (clarsimp split: if_splits)\n   apply (rule_tac x = \"xs ! unat i\" in exI)\n   apply (clarsimp simp: no_vfuns_rename_monoval)\n   apply fastforce\n  apply (rule_tac x = zb in exI)\n  apply (clarsimp simp: no_vfuns_rename_monoval)\n  apply (rule exI, rule exI, rule_tac x = i in exI, intro exI conjI impI; simp?)\n  apply (clarsimp simp: rename_monoval_no_vfuns)\n  done\n\nsubsection \"wordarray_put\"\n\nlemma (in WordArrayValue) vwa_put_monoexpr_correct:\n  \"\\<And>v v'.\n       vwa_put (rename_val rename' (monoval v)) v'\n       \\<Longrightarrow> \\<exists>v''. v' = rename_val rename' (monoval v'') \\<and> vwa_put v v''\"\n  apply (clarsimp simp: vwa_put_def)\n  apply (case_tac v; clarsimp)\n  apply (rename_tac z za zb)\n  apply (case_tac z; clarsimp)\n  apply (case_tac za; clarsimp)\n  apply (clarsimp simp: rename_monoval_no_vfuns[THEN no_vfuns_rename_monoval] rename_monoval_no_vfuns)\n  done\n\nsubsection \"wordarray_get_opt\"\n\nlemma (in WordArrayValue) vwa_get_opt_monoexpr_correct:\n  \"\\<And>v v'.\n       vwa_get_opt (rename_val rename' (monoval v)) v'\n       \\<Longrightarrow> \\<exists>v''. v' = rename_val rename' (monoval v'') \\<and> vwa_get_opt v v''\"\n  apply (clarsimp simp: vwa_get_opt_def)\n  apply (case_tac v; clarsimp)\n  apply (rename_tac v' t xs i z za)\n  apply (case_tac z; clarsimp)\n  apply (case_tac za; clarsimp)\n  apply (clarsimp split: if_splits)\n   apply (rule_tac x = \" VSum ''Something'' (xs ! unat i)\" in exI)\n   apply (clarsimp simp: no_vfuns_rename_monoval)\n   apply fastforce\n  apply (rule_tac x = \"VSum ''Nothing'' VUnit\" in exI)\n  apply (clarsimp simp: no_vfuns_rename_monoval)\n  apply (rule exI, rule exI, rule_tac x = i in exI, intro exI conjI impI; simp?)\n  done\n\nend", "meta": {"author": "zilinc", "repo": "popl23-artefact", "sha": "1fe1490d2d34f93dc01ada940c160477db3b9b72", "save_path": "github-repos/isabelle/zilinc-popl23-artefact", "path": "github-repos/isabelle/zilinc-popl23-artefact/popl23-artefact-1fe1490d2d34f93dc01ada940c160477db3b9b72/arrays/loops/WordArrayMono.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631840431539, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.2967118427008688}}
{"text": "theory Impl_List_Playground_ChairNetwork\nimports \"../TopoS_Impl\"\nbegin\n\n\ntext\\<open>An example of our chair network [simplified]\\<close>\n\ntext\\<open>Our access control view on the network\\<close>\n  definition ChairNetwork_empty :: \"string list_graph\" where\n    \"ChairNetwork_empty \\<equiv> \\<lparr> nodesL = [''WebSrv'', ''FilesSrv'', ''PrinterBW'',\n                                ''PrinterColor'', ''Students'',\n                                ''Employees'', ''EReachable'',\n                                ''Internet''],\n                      edgesL = [] \\<rparr>\"\n  \n  lemma \"wf_list_graph ChairNetwork_empty\" by eval\n\n\nsubsection\\<open>Our security requirements\\<close>\n  subsubsection\\<open>We have a server with confidential data\\<close>\n    definition ConfidentialChairData::\"(string SecurityInvariant)\" where\n      \"ConfidentialChairData \\<equiv> new_configured_list_SecurityInvariant SINVAR_BLPtrusted_impl.SINVAR_LIB_BLPtrusted \\<lparr> \n          node_properties = [''FilesSrv'' \\<mapsto> \\<lparr> security_level = 1, trusted = False \\<rparr>,\n                             ''Employees'' \\<mapsto> \\<lparr> security_level = 0, trusted = True \\<rparr>,\n                             ''EReachable'' \\<mapsto> \\<lparr> security_level = 0, trusted = True \\<rparr>]\n          \\<rparr> ''confidential data''\"\n\n\n  (*\n  subsubsection{*We have a hierarchical printing policy*}\n    definition \"PrintingHierarchy_nodes=[''Employees''\\<mapsto> DN (''ColorPrinting''--Leaf, 0),\n                           ''PrinterColor''\\<mapsto> DN (''ColorPrinting''--''Printer''--Leaf, 0),\n                           ''Students''\\<mapsto> DN (''ColorPrinting''--''BwPrinting''--Leaf, 0),\n                           ''PrinterBW''\\<mapsto> DN (''ColorPrinting''--''BwPrinting''--''Printer''--Leaf, 0)]\"\n    definition \"PrintingHierarchy_tree=Department ''ColorPrinting'' [\n              Department ''Printer'' [], \n              Department ''BwPrinting'' [\n                  Department ''Printer'' []]]\"\n    definition PrintingHierarchy::\"string SecurityInvariant\" where\n      \"PrintingHierarchy \\<equiv> new_configured_list_SecurityInvariant SINVAR_DomainHierarchyNG_impl.SINVAR_LIB_DomainHierarchyNG \\<lparr> \n        node_properties = PrintingHierarchy_nodes\n        \\<rparr>\"  *)\n  subsubsection\\<open>The color printer is only accessibly by employees, The black.white printer by employees and students\\<close>\n    definition \"PrintingACL \\<equiv> new_configured_list_SecurityInvariant SINVAR_LIB_CommunicationPartners \\<lparr> \n          node_properties = [''PrinterColor'' \\<mapsto> Master [''Employees'', ''EReachable''],\n                             ''PrinterBW'' \\<mapsto> Master [''Employees'', ''EReachable'', ''Students''],\n                             ''Employees'' \\<mapsto> Care,\n                             ''EReachable'' \\<mapsto> Care,\n                             ''Students'' \\<mapsto> Care]\n          \\<rparr> ''printing ACL''\"\n\n  subsubsection\\<open>Printers are information sinks\\<close>\n    definition \"PrintingSink \\<equiv> new_configured_list_SecurityInvariant SINVAR_LIB_Sink \\<lparr> \n          node_properties = [''PrinterColor'' \\<mapsto> Sink,\n                             ''PrinterBW'' \\<mapsto> Sink]\n          \\<rparr> ''printing sink''\"\n\n\n\n  subsubsection\\<open>Students may access each other but are not accessible from the outside\\<close>\n    definition \"StudentSubnet \\<equiv> new_configured_list_SecurityInvariant SINVAR_LIB_SubnetsInGW \\<lparr> \n          node_properties = [''Students'' \\<mapsto> Member, ''Employees'' \\<mapsto> Member, ''EReachable'' \\<mapsto> InboundGateway]\n          \\<rparr> ''student subnet''\"\n\n\n  subsubsection\\<open>The files server is only accessibly by employees\\<close>\n    definition \"FilesSrvACL \\<equiv> new_configured_list_SecurityInvariant SINVAR_LIB_CommunicationPartners \\<lparr> \n          node_properties = [''FilesSrv'' \\<mapsto> Master [''Employees'', ''EReachable''],\n                             ''Employees'' \\<mapsto> Care,\n                             ''EReachable'' \\<mapsto> Care]\n          \\<rparr> ''file srv acl''\"\n\n\n  subsubsection\\<open>emplyees are reachable from the Internet\\<close>\n    (*nothing to do here*)\n\nlemma \"implc_sinvar ConfidentialChairData ChairNetwork_empty\" by eval\nlemma \"implc_sinvar PrintingACL ChairNetwork_empty\" by eval\nlemma \"implc_sinvar PrintingSink ChairNetwork_empty\" by eval\nlemma \"implc_sinvar StudentSubnet ChairNetwork_empty\" by eval\nlemma \"implc_sinvar FilesSrvACL ChairNetwork_empty\" by eval\n\ndefinition \"ChairSecurityRequirements = [ConfidentialChairData, PrintingACL, PrintingSink, StudentSubnet, FilesSrvACL]\"\n\nvalue \"implc_get_offending_flows ChairSecurityRequirements ChairNetwork_empty\"\nvalue \"generate_valid_topology ChairSecurityRequirements ChairNetwork_empty\"\n\nvalue \"List.product (nodesL ChairNetwork_empty) (nodesL ChairNetwork_empty)\"\n\ndefinition \"ChairNetwork = generate_valid_topology ChairSecurityRequirements \n      \\<lparr>nodesL = nodesL ChairNetwork_empty, edgesL = List.product (nodesL ChairNetwork_empty) (nodesL ChairNetwork_empty) \\<rparr>\"\n\nlemma \"all_security_requirements_fulfilled ChairSecurityRequirements ChairNetwork\" by eval\n\nvalue \"ChairNetwork\"\n\nML_val\\<open>\nvisualize_graph @{context} @{term \"ChairSecurityRequirements\"} @{term \"ChairNetwork\"};\n\\<close>\n\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Network_Security_Policy_Verification/Examples/Impl_List_Playground_ChairNetwork.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631698328917, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.29671183576223376}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory longlong\nimports \"CParser.CTranslation\"\nbegin\n\nexternal_file \"longlong.c\"\ninstall_C_file \"longlong.c\"\n\nML \\<open>NameGeneration.return_var_name (Absyn.Signed Absyn.LongLong)\\<close>\n\ncontext longlong\nbegin\n\nthm f_body_def\nthm shifts1_body_def\nthm shifts2_body_def\n\nlemma \"(ucast :: 16 word \\<Rightarrow> 8 word) 32768 = 0\"\n  by simp\n\nlemma \"(scast :: 16 word \\<Rightarrow> 8 word) 32768 = 0\"\n  by simp\n\nlemma \"(scast :: 16 word \\<Rightarrow> 8 word) 65535 = 255\"\n  by simp\n\nlemma \"(ucast :: 16 word \\<Rightarrow> 8 word) 65535 = 255\"\n  by simp\n\nlemma \"(ucast :: 16 word \\<Rightarrow> 8 word) 32767 = 255\" by simp\nlemma \"(scast :: 16 word \\<Rightarrow> 8 word) 32767 = 255\" by simp\n\nlemma \"(scast :: 8 word \\<Rightarrow> 16 word) 255 = 65535\" by simp\nlemma \"(ucast :: 8 word \\<Rightarrow> 16 word) 255 = 255\" by simp\n\nlemma g_result:\n  \"\\<Gamma> \\<turnstile> \\<lbrace> True \\<rbrace> \\<acute>ret__int :== CALL callg() \\<lbrace> \\<acute>ret__int = 0 \\<rbrace>\"\n  by vcg (simp add: mask_def)\n\nthm literals_body_def\n\nlemma literals_result:\n  \"\\<Gamma> \\<turnstile> \\<lbrace> True \\<rbrace> \\<acute>ret__int :== CALL literals() \\<lbrace> \\<acute>ret__int = 31 \\<rbrace>\"\n  by vcg simp\n\nend (* context *)\n\nend (* theory *)\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/c-parser/testfiles/longlong.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5544704796847395, "lm_q2_score": 0.5350984286266116, "lm_q1q2_score": 0.2966962823991477}}
{"text": "theory Test_Asm_Sem\nimports\n  Lense_Knowledge_Base\n  \"HOL-Word.Word\"\n  \"More_Eisbach_Tools\"\n  Abstract_System\n  \"HOL-Library.Rewrite\"\nbegin\n\n  section \\<open>Syntax\\<close>\n\n  type_synonym val64 = \"64 word\"\n  (*type_synonym byte = \"8 word\"*)\n\n  datatype rname = RAX_REG | RBX_REG | RCX_REG | RDX_REG | RIP_REG\n  datatype fname = Z_FLAG\n\n  datatype instr =\n    LOAD rname rname  (* LOAD dst:reg src:reg    dst = [src] *)\n  | STORE rname rname (* STORE dst:reg src:reg   [dst] = src *)\n  | LOADI rname val64\n  | MOV rname rname\n  | ADD rname rname rname\n  | CMP rname rname\n  | JMP val64\n  | JE val64\n  | HLT        (* Defined termination of program *)\n\n  section \\<open>Semantics\\<close>\n\n\n  datatype state = STATE\n    (regs: \"rname \\<Rightarrow> val64\")\n    (mem: \"val64 \\<Rightarrow> val64\")\n    (flags: \"fname \\<Rightarrow> bool\")\n    (instrs: \"instr list\")\n    (halted: bool)\n\n  define_lenses state\n\n  lemma pre_state_lenses[simp]:\n    \"pre_get regs\\<^sub>L s\"\n    \"pre_get mem\\<^sub>L s\"\n    \"pre_get flags\\<^sub>L s\"\n    \"pre_get instrs\\<^sub>L s\"\n    \"pre_get halted\\<^sub>L s\"\n    unfolding regs\\<^sub>L_def mem\\<^sub>L_def flags\\<^sub>L_def instrs\\<^sub>L_def halted\\<^sub>L_def\n    by (auto split: state.splits)\n\n  lemma state\\<^sub>L_indeps[simp]:\n    \"regs\\<^sub>L \\<bowtie> mem\\<^sub>L\"\n    \"regs\\<^sub>L \\<bowtie> flags\\<^sub>L\"\n    \"regs\\<^sub>L \\<bowtie> instrs\\<^sub>L\"\n    \"regs\\<^sub>L \\<bowtie> halted\\<^sub>L\"\n\n    \"mem\\<^sub>L \\<bowtie> flags\\<^sub>L\"\n    \"mem\\<^sub>L \\<bowtie> instrs\\<^sub>L\"\n    \"mem\\<^sub>L \\<bowtie> halted\\<^sub>L\"\n\n    \"flags\\<^sub>L \\<bowtie> instrs\\<^sub>L\"\n    \"flags\\<^sub>L \\<bowtie> halted\\<^sub>L\"\n\n    \"instrs\\<^sub>L \\<bowtie> halted\\<^sub>L\"\n    by (unfold_locales; unfold regs\\<^sub>L_def mem\\<^sub>L_def flags\\<^sub>L_def instrs\\<^sub>L_def halted\\<^sub>L_def; auto split: state.split)+\n\n  lemmas [simp] = state\\<^sub>L_indeps[THEN lens_indep_sym]\n\n\n\n  definition \"reg\\<^sub>L r \\<equiv> regs\\<^sub>L (r)\\<^sub>L\"    (* TODO: Attribute [lens] to auto-prove and register \"lens x\" lemma! *)\n  definition \"flag\\<^sub>L r \\<equiv> flags\\<^sub>L (r)\\<^sub>L\"\n\n  lemma lens_reg\\<^sub>L[simp]: \"hlens (reg\\<^sub>L r)\" by (simp add: reg\\<^sub>L_def)\n  lemma pre_reg\\<^sub>L[simp]: \"pre_get (reg\\<^sub>L r) s\" by (simp add: reg\\<^sub>L_def)\n  lemma lens_flag\\<^sub>L[simp]: \"hlens (flag\\<^sub>L r)\" by (simp add: flag\\<^sub>L_def)\n  lemma pre_flag\\<^sub>L[simp]: \"pre_get (flag\\<^sub>L r) s\" by (simp add: flag\\<^sub>L_def)\n\n  fun exec_instr :: \"instr \\<Rightarrow> (unit, state) se\" where\n    \"exec_instr (LOAD dst src) = doE {\n      addr \\<leftarrow> use (reg\\<^sub>L src);\n      val \\<leftarrow> use (mem\\<^sub>L (addr)\\<^sub>L);\n      reg\\<^sub>L dst ::= val\n    }\"\n  | \"exec_instr (STORE dst src) = doE {\n      addr \\<leftarrow> use (reg\\<^sub>L dst);\n      val \\<leftarrow> use (reg\\<^sub>L src);\n      mem\\<^sub>L (addr)\\<^sub>L ::= val\n    }\"\n  | \"exec_instr (LOADI dst val) = doE {\n      reg\\<^sub>L dst ::= val\n    }\"\n  | \"exec_instr (MOV dst src) = doE {\n      reg\\<^sub>L dst ::^= use (reg\\<^sub>L src)\n    }\"\n  | \"exec_instr (ADD dst src1 src2) = doE {\n      v1 \\<leftarrow> use (reg\\<^sub>L src1);\n      v2 \\<leftarrow> use (reg\\<^sub>L src2);\n      let v = v1+v2;\n      reg\\<^sub>L dst ::= v;\n      flag\\<^sub>L Z_FLAG ::= (v=0)\n    }\"\n  | \"exec_instr (CMP src1 src2) = doE {\n      v1 \\<leftarrow> use (reg\\<^sub>L src1);\n      v2 \\<leftarrow> use (reg\\<^sub>L src2);\n      flag\\<^sub>L Z_FLAG ::= (v1 = v2)\n    }\"\n  | \"exec_instr (JMP tgt) = doE {\n      reg\\<^sub>L RIP_REG ::= tgt\n    }\"\n  | \"exec_instr (JE tgt) = doE {\n      zf \\<leftarrow> use (flag\\<^sub>L Z_FLAG);\n      if zf then\n        reg\\<^sub>L RIP_REG ::= tgt\n      else sreturn ()\n    }\"\n  | \"exec_instr HLT = doE { halted\\<^sub>L ::= True }\"\n\n\n  definition \"fetch_instr \\<equiv> doE {\n    ip \\<leftarrow> use (reg\\<^sub>L RIP_REG);\n    use (instrs\\<^sub>L[unat ip]\\<^sub>L)\n  }\"\n\n  definition step :: \"(unit, state) se\" where\n    \"step \\<equiv> doE {\n      instr \\<leftarrow> fetch_instr;\n      reg\\<^sub>L RIP_REG %= op+1;\n      exec_instr instr\n    }\"\n\n\n  global_interpretation det_system step halted\n    defines yields = yields' .\n\n  declare yields_unfold[code]\n\n  definition \"execute \\<equiv> doE {\n    s \\<leftarrow> sget;\n    s \\<leftarrow> lift (yields s);\n    case s of None \\<Rightarrow> sfail | Some s \\<Rightarrow> sput s\n  }\"\n\n\n  definition zero_state :: state where\n    \"zero_state \\<equiv> (STATE\n      (\\<lambda>_. 0)\n      (\\<lambda>_. 0)\n      (\\<lambda>_. False)\n      ([])\n      False\n    )\"\n\n\n  section \\<open>Execution Example\\<close>\n\n\n  definition \"pow_prog \\<equiv> [\n(*0*)   LOADI RCX_REG 0,\n(*1*)   LOADI RAX_REG 1,\n(*2*)   LOADI RBX_REG 1,\n(*3*)   CMP RCX_REG RDX_REG,\n(*4*)   JE 8,\n(*5*)     ADD RAX_REG RAX_REG RAX_REG,\n(*6*)     ADD RCX_REG RCX_REG RBX_REG,\n(*7*)   JMP 3,\n(*8*)   HLT\n(*9*)\n  ]\"\n\n  value \"(doE {\n    reg\\<^sub>L RDX_REG ::= 5;\n    instrs\\<^sub>L ::= pow_prog;\n    execute;\n    use (reg\\<^sub>L RAX_REG)\n  })\n  zero_state\"\n\n\n\nsection \\<open>Verification\\<close>\n\n\ndefinition wf_state :: \"state \\<Rightarrow> bool\"\n  where \"wf_state _ \\<equiv> True\" (* Can be used to add additional constraints to state *)\n\nlemma wf_state_weak_invar: \"is_weak_invar wf_state\"\n  apply (rule is_weak_invarI)\n  by (simp add: wf_state_def)\n\nhide_fact (open) wf_state_def (* Once wf_state is established as invariant,\n  we should not need it any more! -- At least for now, when it is True.\n  Thus, wf_state is just a dummy to show that additional invariant kbxfer works!\n*)\n\n\nlemma [DEL_KBXFER_simps]:\n  assumes \"KBXFER R s s'\"\n  shows\n    \"wf_state s = DEL_TAG (wf_state s)\"\n    by (auto simp: DEL_TAG_def)\n\n\ninterpretation std_invar_system step halted wf_state\n  apply standard\n  by (rule wf_state_weak_invar)\n\n\n\n\ndefinition \"location \\<equiv> get' (reg\\<^sub>L RIP_REG)\"\n\ninterpretation cfg_system step halted wf_state location by standard\n\ntype_synonym floyd_invar = \"val64 \\<rightharpoonup> (state \\<Rightarrow> bool)\"\n\nthm floyd_invarI floyd_vcsI\n\n\n\nlemma reg\\<^sub>L_indep[simp]: \"r\\<noteq>r' \\<Longrightarrow> reg\\<^sub>L r \\<bowtie> reg\\<^sub>L r'\"\n  unfolding reg\\<^sub>L_def\n  by (simp add: lens_indep_left_comp)\n\nlemma flag\\<^sub>L_indep[simp]: \"r\\<noteq>r' \\<Longrightarrow> flag\\<^sub>L r \\<bowtie> flag\\<^sub>L r'\"\n  unfolding flag\\<^sub>L_def\n  by (simp add: lens_indep_left_comp)\n\nlemma flag_regL_indep[simp, THEN lens_indep_sym, simp]:\n  \"flag\\<^sub>L f \\<bowtie> reg\\<^sub>L r\"\n  unfolding reg\\<^sub>L_def flag\\<^sub>L_def\n  by (simp add: lens_indep_extend2)\n\nlemma flag\\<^sub>L_more_indep[simp, THEN lens_indep_sym, simp]:\n  \"flag\\<^sub>L f \\<bowtie> mem\\<^sub>L\"\n  \"flag\\<^sub>L f \\<bowtie> instrs\\<^sub>L\"\n  \"flag\\<^sub>L f \\<bowtie> halted\\<^sub>L\"\n  unfolding flag\\<^sub>L_def\n  by (simp_all add: lens_indep_left_ext)\n\nlemma reg\\<^sub>L_more_indep[simp, THEN lens_indep_sym, simp]:\n  \"reg\\<^sub>L f \\<bowtie> mem\\<^sub>L\"\n  \"reg\\<^sub>L f \\<bowtie> instrs\\<^sub>L\"\n  \"reg\\<^sub>L f \\<bowtie> halted\\<^sub>L\"\n  unfolding reg\\<^sub>L_def\n  by (simp_all add: lens_indep_left_ext)\n\n\nabbreviation \"REG r \\<equiv> VAL (reg\\<^sub>L r)\"\nabbreviation \"RAX \\<equiv> REG RAX_REG\"\nabbreviation \"RBX \\<equiv> REG RBX_REG\"\nabbreviation \"RCX \\<equiv> REG RCX_REG\"\nabbreviation \"RDX \\<equiv> REG RDX_REG\"\nabbreviation \"RIP \\<equiv> REG RIP_REG\"\nabbreviation \"FLAG f \\<equiv> VAL (flag\\<^sub>L f)\"\nabbreviation \"ZFLAG \\<equiv> FLAG Z_FLAG\"\nabbreviation \"PROG \\<equiv> VAL instrs\\<^sub>L\"\n\n\ntext \\<open>Use to convert location into value for RIP\\<close>\nlemma location_eq_conv: \"location s = i \\<longleftrightarrow> RIP i s\"\n  unfolding VAL_def by (auto simp: location_def)\n\nlemma halted_eq_conv:\n  \"halted s \\<longleftrightarrow> VAL halted\\<^sub>L True s\"\n  \"\\<not>VAL halted\\<^sub>L True s \\<longleftrightarrow> VAL halted\\<^sub>L False s\"\n  \"VAL halted\\<^sub>L True s \\<Longrightarrow> \\<not>VAL halted\\<^sub>L False s\"\n  unfolding VAL_def\n  by auto (auto simp: halted\\<^sub>L_def split: state.splits)\n\nlemmas prep_precond_conv = location_eq_conv halted_eq_conv\n\nlemma location_conv[simp]: \"RIP i s \\<Longrightarrow> location s = i\"\n  by (auto simp: location_def)\n\n\n\n\nlemma wps_fetch_instr_eq[wps_iffs]:\n  assumes \"RIP i s\" \"PROG \\<pi> s\"\n  assumes \"unat i < length \\<pi>\"\n  shows \"wps fetch_instr Q s \\<longleftrightarrow> Q (\\<pi> ! unat i) s\"\n  unfolding fetch_instr_def\n  using assms\n  by (simp add: wps_eqs wps_use_eq)\n\n\nlemma wps_stepI[wps_intros]:\n  assumes \"RIP i s\" \"PROG \\<pi> s\"\n  assumes \"unat i < length \\<pi>\"\n  assumes \"\\<And>s'. \\<lbrakk>KBXFER (ltrans (reg\\<^sub>L RIP_REG)) s s'; RIP (1 + i) s'\\<rbrakk> \\<Longrightarrow> wps (exec_instr (\\<pi> ! unat i)) Q s'\"\n  shows \"wps step Q s\"\n  unfolding step_def\n  apply (rule wps_rls | fact)+\n  done\n\n\nlemma wps_CMPI[wps_intros]:\n  assumes \"REG r1 x1 s\" \"REG r2 x2 s\"\n  assumes \"\\<And>s'. \\<lbrakk>KBXFER (ltrans (flag\\<^sub>L Z_FLAG)) s s'; ZFLAG (x1 = x2) s'\\<rbrakk> \\<Longrightarrow> Q () s'\"\n  shows \"wps (exec_instr (CMP r1 r2)) Q s\"\n  apply (simp)\n  apply (intro wps_rls)\n  apply (fact|simp)+\n  done\n\n\nlemma wps_JEI[wps_intros]:\n  assumes \"ZFLAG z s\"\n  assumes \"\\<And>s'. \\<lbrakk>z; KBXFER (ltrans (reg\\<^sub>L RIP_REG)) s s'; RIP tgt s'\\<rbrakk> \\<Longrightarrow> Q () s'\"\n  assumes \"\\<not> z \\<Longrightarrow> Q () s\"\n  shows \"wps (exec_instr (JE tgt)) Q s\"\n  apply (simp)\n  apply (intro wps_rls)\n  apply (fact|simp)+\n  done\n\nlemma wps_JMPI[wps_intros]:\n  assumes \"\\<And>s'. \\<lbrakk>KBXFER (ltrans (reg\\<^sub>L RIP_REG)) s s'; RIP tgt s'\\<rbrakk> \\<Longrightarrow> Q () s'\"\n  shows \"wps (exec_instr (JMP tgt)) Q s\"\n  apply (simp)\n  apply (intro wps_rls)\n  apply (fact|simp)+\n  done\n\n\nlemma wps_HLTI[wps_intros]:\n  assumes \"\\<And>s'. \\<lbrakk>KBXFER (ltrans halted\\<^sub>L) s s'; VAL halted\\<^sub>L True s'\\<rbrakk> \\<Longrightarrow> Q () s'\"\n  shows \"wps (exec_instr HLT) Q s\"\n  apply (simp)\n  apply (intro wps_rls)\n  apply (fact|simp)+\n  done\n\nlemma wps_ADDI[wps_intros]:\n  assumes \"REG r2 x2 s\" \"REG r3 x3 s\"\n  assumes \"\\<And>s'a. \\<lbrakk>REG r1 (x2 + x3) s'a; ZFLAG (x2 + x3 = 0) s'a;\n            KBXFER (ltrans (reg\\<^sub>L r1) OO ltrans (flag\\<^sub>L Z_FLAG)) s s'a\\<rbrakk>\n           \\<Longrightarrow> Q () s'a\"\n  shows \"wps (exec_instr (ADD r1 r2 r3)) Q s\"\n  apply (simp add: Let_def)\n  apply (rule wps_rls | fact | kbxfer')+\n  apply kbxfer_trans\n  by fact\n\nlemma wps_LOADI[wps_intros]:\n  assumes \"\\<And>s'. \\<lbrakk>KBXFER (ltrans (reg\\<^sub>L r)) s s'; REG r i s'\\<rbrakk> \\<Longrightarrow> Q () s'\"\n  shows \"wps (exec_instr (LOADI r i)) Q s\"\n  apply (simp)\n  apply (intro wps_rls)\n  apply (fact|simp)+\n  done\n\n\n\ndeclare exec_instr.simps[simp del]\n\n\nsection \\<open>Verification Example\\<close>\n\n\nlemma nat_to_numeral1:\n  \"Suc 0 = Numeral1\"\n  \"Suc (numeral n) = numeral (Num.inc n)\"\n  by (auto simp: add_One)\n\nlemmas nat_to_numeral = nat_to_numeral1 Num.inc.simps\n\n\nschematic_goal [simplified nat_to_numeral, simp]: \"length pow_prog = ?l\"\n  unfolding pow_prog_def by simp\n\nschematic_goal [simplified,simp]:\n  \"pow_prog ! 0 = ?c0\"\n  \"pow_prog ! 1 = ?c1\"\n  \"pow_prog ! 2 = ?c2\"\n  \"pow_prog ! 3 = ?c3\"\n  \"pow_prog ! 4 = ?c4\"\n  \"pow_prog ! 5 = ?c5\"\n  \"pow_prog ! 6 = ?c6\"\n  \"pow_prog ! 7 = ?c7\"\n  \"pow_prog ! 8 = ?c8\"\n  unfolding pow_prog_def by auto\n\n\nprop \"RDX p s \\<and> VAL (mem\\<^sub>L((p + 0))\\<^sub>L) x0 s \\<and> VAL (mem\\<^sub>L((p + 1))\\<^sub>L) x1 s\"\n\ndefinition pp_\\<Theta> :: \"_ \\<Rightarrow> floyd_invar\" where \"pp_\\<Theta> rdx\\<^sub>0 \\<equiv> [\n  0 \\<mapsto> (\\<lambda>s. VAL halted\\<^sub>L False s \\<and> PROG pow_prog s \\<and> RDX rdx\\<^sub>0 s),\n  3 \\<mapsto> (\\<lambda>s. \\<exists>rax rbx rcx hlt. RAX rax s \\<and> RBX rbx s \\<and> RCX rcx s \\<and> RDX rdx\\<^sub>0 s\n      \\<and> VAL halted\\<^sub>L hlt s \\<and> \\<not>hlt \\<and> PROG pow_prog s\n      \\<and> rbx = 1 \\<and> rax = 2 ^ unat rcx \\<and> rcx \\<le> rdx\\<^sub>0),\n  9 \\<mapsto> (\\<lambda>s. \\<exists>rax hlt. RAX rax s \\<and> RDX rdx\\<^sub>0 s\n      \\<and> VAL halted\\<^sub>L hlt s \\<and> hlt \\<and> PROG pow_prog s\n      \\<and> rax = 2 ^ unat rdx\\<^sub>0\n      )\n]\"\n\nschematic_goal [simplified,simp]:\n  \"pp_\\<Theta> rdx\\<^sub>0 0 = ?p0\"\n  \"pp_\\<Theta> rdx\\<^sub>0 3 = ?p3\"\n  \"pp_\\<Theta> rdx\\<^sub>0 9 = ?p9\"\n  \"i\\<notin>{0,3,9} \\<Longrightarrow> pp_\\<Theta> rdx\\<^sub>0 i = None\"\n  unfolding pp_\\<Theta>_def by auto\n\nlemma incr_aux1:\n  fixes a b :: \"'a::len word\"\n  shows \"a \\<le> b \\<Longrightarrow> a \\<noteq> b \\<Longrightarrow> unat (a+1) = Suc (unat a)\"\n  by (smt Suc_eq_plus1 add.commute inc_i inc_le le_less not_less unatSuc unat_1 unat_plus_simple)\n\nlemma incr_aux2:\n  fixes a b :: \"'a::len word\"\n  shows \"a \\<le> b \\<Longrightarrow> a \\<noteq> b \\<Longrightarrow> a+1\\<le>b\"\n  by (simp add: inc_le)\n\n(* TODO: Move this VCG to more generic place! Currently placed here for quick experiments. *)\nmethod vcg_clarify = (intro impI conjI)?, (((rule exI, rule conjI, assumption)+ | (simp add: prep_precond_conv))+)?\nmethod vcg_step_aux = (rule wps_rls linvar_unfoldI, (assumption+)?); kbxfer?\nmethod vcg_step = vcg_clarify, vcg_step_aux\nmethod vcg = (vcg_step+, vcg_clarify)\n\n\nlemma pp_std_invar: \"is_std_invar (floyd.invar (pp_\\<Theta> rdx\\<^sub>0))\"\n  apply (rule floyd_invarI)\n  apply (rewrite at \"floyd_vcs \\<hole> _\" pp_\\<Theta>_def)\n  apply (intro floyd_vcsI; (clarsimp simp: prep_precond_conv)?)\n\n  subgoal for s by vcg\n\n  subgoal for s\n    apply vcg\n    apply (elim_determ thin_rl[of \"VAL _ _ _\"])\n    apply (auto simp: incr_aux1 inc_le) []\n    done\n  done\n\n\n\ntheorem pow_prog_correct: \"htriple\n  (\\<lambda>s. RIP 0 s \\<and> PROG pow_prog s \\<and> VAL halted\\<^sub>L False s \\<and> RDX n s)\n  (\\<lambda>s. RAX (2^unat n) s)\"\n  apply (rule floyd_htripleI[where \\<Theta> = \"pp_\\<Theta> n\"], clarify)\n  subgoal by vcg\n  subgoal by (rule pp_std_invar)\n  subgoal for s \\<phi>\n    unfolding pp_\\<Theta>_def\n    by (clarsimp split: if_splits simp: prep_precond_conv)\n  done\n\nend\n", "meta": {"author": "ssrg-vt", "repo": "Luce-src", "sha": "f7f1ef0fd07bba48bcb3d5e32404db6013a5f1bc", "save_path": "github-repos/isabelle/ssrg-vt-Luce-src", "path": "github-repos/isabelle/ssrg-vt-Luce-src/Luce-src-f7f1ef0fd07bba48bcb3d5e32404db6013a5f1bc/tacas2020_artifact/isabelle/Monads/Test_Asm_Sem.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5544704796847395, "lm_q2_score": 0.5350984286266116, "lm_q1q2_score": 0.2966962823991477}}
{"text": "(*  Title:       The Standard Redundancy Criterion\n    Author:      Jasmin Blanchette <j.c.blanchette at vu.nl>, 2014, 2017\n    Author:      Dmitriy Traytel <traytel at inf.ethz.ch>, 2014\n    Author:      Anders Schlichtkrull <andschl at dtu.dk>, 2017\n    Maintainer:  Anders Schlichtkrull <andschl at dtu.dk>\n*)\n\nsection \\<open>The Standard Redundancy Criterion\\<close>\n\ntheory Standard_Redundancy\n  imports Proving_Process\nbegin\n\ntext \\<open>\nThis material is based on Section 4.2.2 (``The Standard Redundancy Criterion'') of Bachmair and\nGanzinger's chapter.\n\\<close>\n\nlocale standard_redundancy_criterion =\n  inference_system \\<Gamma> for \\<Gamma> :: \"('a :: wellorder) inference set\"\nbegin\n\ndefinition redundant_infer :: \"'a clause set \\<Rightarrow> 'a inference \\<Rightarrow> bool\" where\n  \"redundant_infer N \\<gamma> \\<longleftrightarrow>\n   (\\<exists>DD. set_mset DD \\<subseteq> N \\<and> (\\<forall>I. I \\<Turnstile>m DD + side_prems_of \\<gamma> \\<longrightarrow> I \\<Turnstile> concl_of \\<gamma>)\n      \\<and> (\\<forall>D. D \\<in># DD \\<longrightarrow> D < main_prem_of \\<gamma>))\"\n\ndefinition Rf :: \"'a clause set \\<Rightarrow> 'a clause set\" where\n  \"Rf N = {C. \\<exists>DD. set_mset DD \\<subseteq> N \\<and> (\\<forall>I. I \\<Turnstile>m DD \\<longrightarrow> I \\<Turnstile> C) \\<and> (\\<forall>D. D \\<in># DD \\<longrightarrow> D < C)}\"\n\ndefinition Ri :: \"'a clause set \\<Rightarrow> 'a inference set\" where\n  \"Ri N = {\\<gamma> \\<in> \\<Gamma>. redundant_infer N \\<gamma>}\"\n\nlemma tautology_Rf:\n  assumes \"Pos A \\<in># C\"\n  assumes \"Neg A \\<in># C\"\n  shows \"C \\<in> Rf N\"\nproof -\n  have \"set_mset {#} \\<subseteq> N \\<and> (\\<forall>I. I \\<Turnstile>m {#} \\<longrightarrow> I \\<Turnstile> C) \\<and> (\\<forall>D. D \\<in># {#} \\<longrightarrow> D < C)\"\n    using assms by auto\n  then show \"C \\<in> Rf N\"\n    unfolding Rf_def by blast\nqed\n\nlemma tautology_redundant_infer:\n  assumes\n    pos: \"Pos A \\<in># concl_of \\<iota>\" and\n    neg: \"Neg A \\<in># concl_of \\<iota>\"\n  shows \"redundant_infer N \\<iota>\"\n  by (metis empty_iff empty_subsetI neg pos pos_neg_in_imp_true redundant_infer_def set_mset_empty)\n\nlemma contradiction_Rf: \"{#} \\<in> N \\<Longrightarrow> Rf N = UNIV - {{#}}\"\n  unfolding Rf_def by force\n\ntext \\<open>\nThe following results correspond to Lemma 4.5. The lemma \\<open>wlog_non_Rf\\<close> generalizes the core of\nthe argument.\n\\<close>\n\nlemma Rf_mono: \"N \\<subseteq> N' \\<Longrightarrow> Rf N \\<subseteq> Rf N'\"\n  unfolding Rf_def by auto\n\nlemma wlog_non_Rf:\n  assumes ex: \"\\<exists>DD. set_mset DD \\<subseteq> N \\<and> (\\<forall>I. I \\<Turnstile>m DD + CC \\<longrightarrow> I \\<Turnstile> E) \\<and> (\\<forall>D'. D' \\<in># DD \\<longrightarrow> D' < D)\"\n  shows \"\\<exists>DD. set_mset DD \\<subseteq> N - Rf N \\<and> (\\<forall>I. I \\<Turnstile>m DD + CC \\<longrightarrow> I \\<Turnstile> E) \\<and> (\\<forall>D'. D' \\<in># DD \\<longrightarrow> D' < D)\"\nproof -\n  from ex obtain DD0 where\n    dd0: \"DD0 \\<in> {DD. set_mset DD \\<subseteq> N \\<and> (\\<forall>I. I \\<Turnstile>m DD + CC \\<longrightarrow> I \\<Turnstile> E) \\<and> (\\<forall>D'. D' \\<in># DD \\<longrightarrow> D' < D)}\"\n    by blast\n  have \"\\<exists>DD. set_mset DD \\<subseteq> N \\<and> (\\<forall>I. I \\<Turnstile>m DD + CC \\<longrightarrow> I \\<Turnstile> E) \\<and> (\\<forall>D'. D' \\<in># DD \\<longrightarrow> D' < D) \\<and>\n      (\\<forall>DD'. set_mset DD' \\<subseteq> N \\<and> (\\<forall>I. I \\<Turnstile>m DD' + CC \\<longrightarrow> I \\<Turnstile> E) \\<and> (\\<forall>D'. D' \\<in># DD' \\<longrightarrow> D' < D) \\<longrightarrow>\n    DD \\<le> DD')\"\n    using wf_eq_minimal[THEN iffD1, rule_format, OF wf_less_multiset dd0]\n    unfolding not_le[symmetric] by blast\n  then obtain DD where\n    dd_subs_n: \"set_mset DD \\<subseteq> N\" and\n    ddcc_imp_e: \"\\<forall>I. I \\<Turnstile>m DD + CC \\<longrightarrow> I \\<Turnstile> E\" and\n    dd_lt_d: \"\\<forall>D'. D' \\<in># DD \\<longrightarrow> D' < D\" and\n    d_min: \"\\<forall>DD'. set_mset DD' \\<subseteq> N \\<and> (\\<forall>I. I \\<Turnstile>m DD' + CC \\<longrightarrow> I \\<Turnstile> E) \\<and> (\\<forall>D'. D' \\<in># DD' \\<longrightarrow> D' < D) \\<longrightarrow>\n      DD \\<le> DD'\"\n    by blast\n\n  have \"\\<forall>Da. Da \\<in># DD \\<longrightarrow> Da \\<notin> Rf N\"\n  proof clarify\n    fix Da\n    assume\n      da_in_dd: \"Da \\<in># DD\" and\n      da_rf: \"Da \\<in> Rf N\"\n\n    from da_rf obtain DD' where\n      dd'_subs_n: \"set_mset DD' \\<subseteq> N\" and\n      dd'_imp_da: \"\\<forall>I. I \\<Turnstile>m DD' \\<longrightarrow> I \\<Turnstile> Da\" and\n      dd'_lt_da: \"\\<forall>D'. D' \\<in># DD' \\<longrightarrow> D' < Da\"\n      unfolding Rf_def by blast\n\n    define DDa where\n      \"DDa = DD - {#Da#} + DD'\"\n\n    have \"set_mset DDa \\<subseteq> N\"\n      unfolding DDa_def using dd_subs_n dd'_subs_n\n      by (meson contra_subsetD in_diffD subsetI union_iff)\n    moreover have \"\\<forall>I. I \\<Turnstile>m DDa + CC \\<longrightarrow> I \\<Turnstile> E\"\n      using dd'_imp_da ddcc_imp_e da_in_dd unfolding DDa_def true_cls_mset_def\n      by (metis in_remove1_mset_neq union_iff)\n    moreover have \"\\<forall>D'. D' \\<in># DDa \\<longrightarrow> D' < D\"\n      using dd_lt_d dd'_lt_da da_in_dd unfolding DDa_def\n      by (metis insert_DiffM2 order.strict_trans union_iff)\n    moreover have \"DDa < DD\"\n      unfolding DDa_def\n      by (meson da_in_dd dd'_lt_da mset_lt_single_right_iff single_subset_iff union_le_diff_plus)\n    ultimately show False\n      using d_min unfolding less_eq_multiset_def by (auto intro!: antisym)\n  qed\n  then show ?thesis\n    using dd_subs_n ddcc_imp_e dd_lt_d by auto\nqed\n\nlemma Rf_imp_ex_non_Rf:\n  assumes \"C \\<in> Rf N\"\n  shows \"\\<exists>CC. set_mset CC \\<subseteq> N - Rf N \\<and> (\\<forall>I. I \\<Turnstile>m CC \\<longrightarrow> I \\<Turnstile> C) \\<and> (\\<forall>C'. C' \\<in># CC \\<longrightarrow> C' < C)\"\n  using assms by (auto simp: Rf_def intro: wlog_non_Rf[of _ \"{#}\", simplified])\n\nlemma Rf_subs_Rf_diff_Rf: \"Rf N \\<subseteq> Rf (N - Rf N)\"\nproof\n  fix C\n  assume c_rf: \"C \\<in> Rf N\"\n  then obtain CC where\n    cc_subs: \"set_mset CC \\<subseteq> N - Rf N\" and\n    cc_imp_c: \"\\<forall>I. I \\<Turnstile>m CC \\<longrightarrow> I \\<Turnstile> C\" and\n    cc_lt_c: \"\\<forall>C'. C' \\<in># CC \\<longrightarrow> C' < C\"\n    using Rf_imp_ex_non_Rf by blast\n  have \"\\<forall>D. D \\<in># CC \\<longrightarrow> D \\<notin> Rf N\"\n    using cc_subs by (simp add: subset_iff)\n  then have cc_nr:\n    \"\\<And>C DD. C \\<in># CC \\<Longrightarrow> set_mset DD \\<subseteq> N \\<Longrightarrow> \\<forall>I. I \\<Turnstile>m DD \\<longrightarrow> I \\<Turnstile> C \\<Longrightarrow> \\<exists>D. D \\<in># DD \\<and> \\<not> D < C\"\n      unfolding Rf_def by auto metis\n  have \"set_mset CC \\<subseteq> N\"\n    using cc_subs by auto\n  then have \"set_mset CC \\<subseteq>\n    N - {C. \\<exists>DD. set_mset DD \\<subseteq> N \\<and> (\\<forall>I. I \\<Turnstile>m DD \\<longrightarrow> I \\<Turnstile> C) \\<and> (\\<forall>D. D \\<in># DD \\<longrightarrow> D < C)}\"\n    using cc_nr by blast\n  then show \"C \\<in> Rf (N - Rf N)\"\n    using cc_imp_c cc_lt_c unfolding Rf_def by auto\nqed\n\nlemma Rf_eq_Rf_diff_Rf: \"Rf N = Rf (N - Rf N)\"\n  by (metis Diff_subset Rf_mono Rf_subs_Rf_diff_Rf subset_antisym)\n\ntext \\<open>\nThe following results correspond to Lemma 4.6.\n\\<close>\n\nlemma Ri_mono: \"N \\<subseteq> N' \\<Longrightarrow> Ri N \\<subseteq> Ri N'\"\n  unfolding Ri_def redundant_infer_def by auto\n\nlemma Ri_subs_Ri_diff_Rf: \"Ri N \\<subseteq> Ri (N - Rf N)\"\nproof\n  fix \\<gamma>\n  assume \\<gamma>_ri: \"\\<gamma> \\<in> Ri N\"\n  then obtain CC D E where \\<gamma>: \"\\<gamma> = Infer CC D E\"\n    by (cases \\<gamma>)\n  have cc: \"CC = side_prems_of \\<gamma>\" and d: \"D = main_prem_of \\<gamma>\" and e: \"E = concl_of \\<gamma>\"\n    unfolding \\<gamma> by simp_all\n  obtain DD where\n    \"set_mset DD \\<subseteq> N\" and \"\\<forall>I. I \\<Turnstile>m DD + CC \\<longrightarrow> I \\<Turnstile> E\" and \"\\<forall>C. C \\<in># DD \\<longrightarrow> C < D\"\n    using \\<gamma>_ri unfolding Ri_def redundant_infer_def cc d e by blast\n  then obtain DD' where\n    \"set_mset DD' \\<subseteq> N - Rf N\" and \"\\<forall>I. I \\<Turnstile>m DD' + CC \\<longrightarrow> I \\<Turnstile> E\" and \"\\<forall>D'. D' \\<in># DD' \\<longrightarrow> D' < D\"\n    using wlog_non_Rf by atomize_elim blast\n  then show \"\\<gamma> \\<in> Ri (N - Rf N)\"\n    using \\<gamma>_ri unfolding Ri_def redundant_infer_def d cc e by blast\nqed\n\nlemma Ri_eq_Ri_diff_Rf: \"Ri N = Ri (N - Rf N)\"\n  by (metis Diff_subset Ri_mono Ri_subs_Ri_diff_Rf subset_antisym)\n\nlemma Ri_subset_\\<Gamma>: \"Ri N \\<subseteq> \\<Gamma>\"\n  unfolding Ri_def by blast\n\nlemma Rf_indep: \"N' \\<subseteq> Rf N \\<Longrightarrow> Rf N \\<subseteq> Rf (N - N')\"\n  by (metis Diff_cancel Diff_eq_empty_iff Diff_mono Rf_eq_Rf_diff_Rf Rf_mono)\n\nlemma Ri_indep: \"N' \\<subseteq> Rf N \\<Longrightarrow> Ri N \\<subseteq> Ri (N - N')\"\n  by (metis Diff_mono Ri_eq_Ri_diff_Rf Ri_mono order_refl)\n\nlemma Rf_model:\n  assumes \"I \\<Turnstile>s N - Rf N\"\n  shows \"I \\<Turnstile>s N\"\nproof -\n  have \"I \\<Turnstile>s Rf (N - Rf N)\"\n    unfolding true_clss_def\n    by (subst Rf_def, simp add: true_cls_mset_def, metis assms subset_eq true_clss_def)\n  then have \"I \\<Turnstile>s Rf N\"\n    using Rf_subs_Rf_diff_Rf true_clss_mono by blast\n  then show ?thesis\n    using assms by (metis Un_Diff_cancel true_clss_union)\nqed\n\nlemma Rf_sat: \"satisfiable (N - Rf N) \\<Longrightarrow> satisfiable N\"\n  by (metis Rf_model)\n\ntext \\<open>\nThe following corresponds to Theorem 4.7:\n\\<close>\n\nsublocale redundancy_criterion \\<Gamma> Rf Ri\n  by unfold_locales (rule Ri_subset_\\<Gamma>, (elim Rf_mono Ri_mono Rf_indep Ri_indep Rf_sat)+)\n\nend\n\nlocale standard_redundancy_criterion_reductive =\n  standard_redundancy_criterion + reductive_inference_system\nbegin\n\ntext \\<open>\nThe following corresponds to Theorem 4.8:\n\\<close>\n\nlemma Ri_effective:\n  assumes\n    in_\\<gamma>: \"\\<gamma> \\<in> \\<Gamma>\" and\n    concl_of_in_n_un_rf_n: \"concl_of \\<gamma> \\<in> N \\<union> Rf N\"\n  shows \"\\<gamma> \\<in> Ri N\"\nproof -\n  obtain CC D E where\n    \\<gamma>: \"\\<gamma> = Infer CC D E\"\n    by (cases \\<gamma>)\n  then have cc: \"CC = side_prems_of \\<gamma>\" and d: \"D = main_prem_of \\<gamma>\" and e: \"E = concl_of \\<gamma>\"\n    unfolding \\<gamma> by simp_all\n  note e_in_n_un_rf_n = concl_of_in_n_un_rf_n[folded e]\n\n  {\n    assume \"E \\<in> N\"\n    moreover have \"E < D\"\n      using \\<Gamma>_reductive e d in_\\<gamma> by auto\n    ultimately have\n      \"set_mset {#E#} \\<subseteq> N\" and \"\\<forall>I. I \\<Turnstile>m {#E#} + CC \\<longrightarrow> I \\<Turnstile> E\" and \"\\<forall>D'. D' \\<in># {#E#} \\<longrightarrow> D' < D\"\n      by simp_all\n    then have \"redundant_infer N \\<gamma>\"\n      using redundant_infer_def cc d e by blast\n  }\n  moreover\n  {\n    assume \"E \\<in> Rf N\"\n    then obtain DD where\n      dd_sset: \"set_mset DD \\<subseteq> N\" and\n      dd_imp_e: \"\\<forall>I. I \\<Turnstile>m DD \\<longrightarrow> I \\<Turnstile> E\" and\n      dd_lt_e: \"\\<forall>C'. C' \\<in># DD \\<longrightarrow> C' < E\"\n      unfolding Rf_def by blast\n    from dd_lt_e have \"\\<forall>Da. Da \\<in># DD \\<longrightarrow> Da < D\"\n      using d e in_\\<gamma> \\<Gamma>_reductive less_trans by blast\n    then have \"redundant_infer N \\<gamma>\"\n      using redundant_infer_def dd_sset dd_imp_e cc d e by blast\n  }\n  ultimately show \"\\<gamma> \\<in> Ri N\"\n    using in_\\<gamma> e_in_n_un_rf_n unfolding Ri_def by blast\nqed\n\nsublocale effective_redundancy_criterion \\<Gamma> Rf Ri\n  unfolding effective_redundancy_criterion_def\n  by (intro conjI redundancy_criterion_axioms, unfold_locales, rule Ri_effective)\n\nlemma contradiction_Rf: \"{#} \\<in> N \\<Longrightarrow> Ri N = \\<Gamma>\"\n  unfolding Ri_def redundant_infer_def using \\<Gamma>_reductive le_multiset_empty_right\n  by (force intro: exI[of _ \"{#{#}#}\"] le_multiset_empty_left)\n\nend\n\nlocale standard_redundancy_criterion_counterex_reducing =\n  standard_redundancy_criterion + counterex_reducing_inference_system\nbegin\n\ntext \\<open>\nThe following result corresponds to Theorem 4.9.\n\\<close>\n\nlemma saturated_upto_complete_if:\n  assumes\n    satur: \"saturated_upto N\" and\n    unsat: \"\\<not> satisfiable N\"\n  shows \"{#} \\<in> N\"\nproof (rule ccontr)\n  assume ec_ni_n: \"{#} \\<notin> N\"\n\n  define M where\n    \"M = N - Rf N\"\n\n  have ec_ni_m: \"{#} \\<notin> M\"\n    unfolding M_def using ec_ni_n by fast\n\n  have \"I_of M \\<Turnstile>s M\"\n  proof (rule ccontr)\n    assume \"\\<not> I_of M \\<Turnstile>s M\"\n    then obtain D where\n      d_in_m: \"D \\<in> M\" and\n      d_cex: \"\\<not> I_of M \\<Turnstile> D\" and\n      d_min: \"\\<And>C. C \\<in> M \\<Longrightarrow> C < D \\<Longrightarrow> I_of M \\<Turnstile> C\"\n      using ex_min_counterex by meson\n    then obtain \\<gamma> CC E where\n      \\<gamma>: \"\\<gamma> = Infer CC D E\" and\n      cc_subs_m: \"set_mset CC \\<subseteq> M\" and\n      cc_true: \"I_of M \\<Turnstile>m CC\" and\n      \\<gamma>_in: \"\\<gamma> \\<in> \\<Gamma>\" and\n      e_cex: \"\\<not> I_of M \\<Turnstile> E\" and\n      e_lt_d: \"E < D\"\n      using \\<Gamma>_counterex_reducing[OF ec_ni_m] not_less by metis\n    have cc: \"CC = side_prems_of \\<gamma>\" and d: \"D = main_prem_of \\<gamma>\" and e: \"E = concl_of \\<gamma>\"\n      unfolding \\<gamma> by simp_all\n    have \"\\<gamma> \\<in> Ri N\"\n      by (rule subsetD[OF satur[unfolded saturated_upto_def inferences_from_def infer_from_def]])\n        (simp add: \\<gamma>_in d_in_m cc_subs_m cc[symmetric] d[symmetric] M_def[symmetric])\n    then have \"\\<gamma> \\<in> Ri M\"\n      unfolding M_def using Ri_indep by fast\n    then obtain DD where\n      dd_subs_m: \"set_mset DD \\<subseteq> M\" and\n      dd_cc_imp_d: \"\\<forall>I. I \\<Turnstile>m DD + CC \\<longrightarrow> I \\<Turnstile> E\" and\n      dd_lt_d: \"\\<forall>C. C \\<in># DD \\<longrightarrow> C < D\"\n      unfolding Ri_def redundant_infer_def cc d e by blast\n    from dd_subs_m dd_lt_d have \"I_of M \\<Turnstile>m DD\"\n      using d_min unfolding true_cls_mset_def by (metis contra_subsetD)\n    then have \"I_of M \\<Turnstile> E\"\n      using dd_cc_imp_d cc_true by auto\n    then show False\n      using e_cex by auto\n  qed\n  then have \"I_of M \\<Turnstile>s N\"\n    using M_def Rf_model by blast\n  then show False\n    using unsat by blast\nqed\n\ntheorem saturated_upto_complete:\n  assumes \"saturated_upto N\"\n  shows \"\\<not> satisfiable N \\<longleftrightarrow> {#} \\<in> N\"\n  using assms saturated_upto_complete_if true_clss_def by auto\n\nend\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Ordered_Resolution_Prover/Standard_Redundancy.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5350984286266116, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.29669627452019137}}
{"text": "(*  Title:       Isabelle Collections Library\n    Author:      Peter Lammich <peter dot lammich at uni-muenster.de>\n    Maintainer:  Peter Lammich <peter dot lammich at uni-muenster.de>\n*)\n(*\n  Changes since submission on 2009-11-26:\n\n  2009-12-10: OrderedMap, algorithms for iterators, min, max, to_sorted_list\n\n*)\n\nheader {* \\isaheader{Generic Algorithms for Maps} *}\ntheory MapGA\nimports SetIteratorCollectionsGA\nbegin\n\ntext_raw {*\\label{thy:MapGA}*}\n\nrecord ('k,'v,'s) map_basic_ops =\n  bmap_op_\\<alpha> :: \"('k,'v,'s) map_\\<alpha>\"\n  bmap_op_invar :: \"('k,'v,'s) map_invar\"\n  bmap_op_empty :: \"('k,'v,'s) map_empty\"\n  bmap_op_lookup :: \"('k,'v,'s) map_lookup\"\n  bmap_op_update :: \"('k,'v,'s) map_update\"\n  bmap_op_update_dj :: \"('k,'v,'s) map_update_dj\"\n  bmap_op_delete :: \"('k,'v,'s) map_delete\"\n  bmap_op_list_it :: \"('k,'v,'s) map_list_it\"\n  \nrecord ('k,'v,'s) omap_basic_ops = \"('k,'v,'s) map_basic_ops\" +\n  bmap_op_ordered_list_it :: \"'s \\<Rightarrow> ('k,'v,('k\\<times>'v) list) map_iterator\"\n  bmap_op_rev_list_it :: \"'s \\<Rightarrow> ('k,'v,('k\\<times>'v) list) map_iterator\"\n\nlocale StdBasicMapDefs = \n  poly_map_iteratei_defs \"bmap_op_list_it ops\" \n  for ops :: \"('k,'v,'s,'more) map_basic_ops_scheme\"\nbegin\n  abbreviation \\<alpha> where \"\\<alpha> == bmap_op_\\<alpha> ops\" \n  abbreviation invar where \"invar == bmap_op_invar ops\" \n  abbreviation empty where \"empty == bmap_op_empty ops\" \n  abbreviation lookup where \"lookup == bmap_op_lookup ops\" \n  abbreviation update where \"update == bmap_op_update ops\" \n  abbreviation update_dj where \"update_dj == bmap_op_update_dj ops\" \n  abbreviation delete where \"delete == bmap_op_delete ops\" \n  abbreviation list_it where \"list_it == bmap_op_list_it ops\" \nend\n\nlocale StdBasicOMapDefs = StdBasicMapDefs ops\n  + poly_map_iterateoi_defs \"bmap_op_ordered_list_it ops\"\n  + poly_map_rev_iterateoi_defs \"bmap_op_rev_list_it ops\"\n  for ops :: \"('k::linorder,'v,'s,'more) omap_basic_ops_scheme\"\nbegin\n  abbreviation ordered_list_it where \"ordered_list_it \n    \\<equiv> bmap_op_ordered_list_it ops\"\n  abbreviation rev_list_it where \"rev_list_it \n    \\<equiv> bmap_op_rev_list_it ops\"\nend\n\nlocale StdBasicMap = StdBasicMapDefs ops +\n  map \\<alpha> invar +\n  map_empty \\<alpha> invar empty +\n  map_lookup \\<alpha> invar lookup  +\n  map_update \\<alpha> invar update  +\n  map_update_dj \\<alpha> invar update_dj +\n  map_delete \\<alpha> invar delete  +\n  poly_map_iteratei \\<alpha> invar list_it\n  for ops :: \"('k,'v,'s,'more) map_basic_ops_scheme\"\nbegin\n  lemmas correct[simp] = empty_correct lookup_correct update_correct \n    update_dj_correct delete_correct\nend\n\n\nlocale StdBasicOMap = \n  StdBasicOMapDefs ops +\n  StdBasicMap ops +\n  poly_map_iterateoi \\<alpha> invar ordered_list_it +\n  poly_map_rev_iterateoi \\<alpha> invar rev_list_it\n  for ops :: \"('k::linorder,'v,'s,'more) omap_basic_ops_scheme\"\nbegin\nend\n\ncontext StdBasicMapDefs begin\n  definition \"g_sng k v \\<equiv> update k v (empty ())\"\n  definition \"g_add m1 m2 \\<equiv> iterate m2 (\\<lambda>(k,v) \\<sigma>. update k v \\<sigma>) m1\"\n\n  definition \n    \"g_sel m P \\<equiv> \n      iteratei m (\\<lambda>\\<sigma>. \\<sigma> = None) (\\<lambda>x \\<sigma>. if P x then Some x else None) None\"\n\n  definition \"g_bex m P \\<equiv> iteratei m (\\<lambda>x. \\<not>x) (\\<lambda>kv \\<sigma>. P kv) False\"\n  definition \"g_ball m P \\<equiv> iteratei m id (\\<lambda>kv \\<sigma>. P kv) True\"\n\n  definition \"g_size m \\<equiv> iterate m (\\<lambda>_. Suc) (0::nat)\"\n  definition \"g_size_abort b m \\<equiv> iteratei m (\\<lambda>s. s<b) (\\<lambda>_. Suc) (0::nat)\"\n\n  definition \"g_isEmpty m \\<equiv> g_size_abort 1 m = 0\"\n  definition \"g_isSng m \\<equiv> g_size_abort 2 m = 1\"\n\n  definition \"g_to_list m \\<equiv> iterate m (op #) []\"\n\n  definition \"g_list_to_map l \\<equiv> foldl (\\<lambda>m (k,v). update k v m) (empty ()) \n    (rev l)\"\n\n  definition \"g_add_dj m1 m2 \\<equiv> iterate m2 (\\<lambda>(k,v) \\<sigma>. update_dj k v \\<sigma>) m1\"\n\n  definition \"g_restrict P m \\<equiv> iterate m \n    (\\<lambda>(k,v) \\<sigma>. if P (k,v) then update_dj k v \\<sigma> else \\<sigma>) (empty ())\"\n\n  definition dflt_ops :: \"('k,'v,'s) map_ops\" \n    where [icf_rec_def]:\n    \"dflt_ops \\<equiv> \n      \\<lparr> \n        map_op_\\<alpha> = \\<alpha>,\n        map_op_invar = invar,\n        map_op_empty = empty,\n        map_op_lookup = lookup,\n        map_op_update = update,\n        map_op_update_dj = update_dj,\n        map_op_delete = delete,\n        map_op_list_it = list_it,\n        map_op_sng = g_sng,\n        map_op_restrict = g_restrict, \n        map_op_add = g_add, \n        map_op_add_dj = g_add_dj, \n        map_op_isEmpty = g_isEmpty, \n        map_op_isSng = g_isSng, \n        map_op_ball = g_ball, \n        map_op_bex = g_bex, \n        map_op_size = g_size, \n        map_op_size_abort = g_size_abort, \n        map_op_sel = g_sel, \n        map_op_to_list = g_to_list, \n        map_op_to_map = g_list_to_map\n      \\<rparr>\"\n\n  local_setup {* Locale_Code.lc_decl_del @{term dflt_ops}*}\n\nend\n\nlemma update_dj_by_update: \n  assumes \"map_update \\<alpha> invar update\"\n  shows \"map_update_dj \\<alpha> invar update\"\nproof -\n  interpret map_update \\<alpha> invar update by fact\n  show ?thesis \n    apply (unfold_locales)\n    apply (auto simp add: update_correct)\n    done\nqed\n\nlemma map_iterator_linord_is_it: \n  \"map_iterator_linord m it \\<Longrightarrow> map_iterator m it\"\n  unfolding set_iterator_def set_iterator_map_linord_def\n  apply (erule set_iterator_genord.set_iterator_weaken_R)\n  ..\n\n\n\ncontext StdBasicMap \nbegin\n  \n\n  lemma g_add_impl: \"map_add \\<alpha> invar g_add\"\n  proof\n    fix m1 m2\n    assume \"invar m1\" \"invar m2\"\n\n    have A: \"g_add m1 m2 = iterate_add_to_map m1 update (iteratei m2)\"\n      unfolding g_add_def iterate_add_to_map_def by simp\n    have \"\\<alpha> (g_add m1 m2) = \\<alpha> m1 ++ \\<alpha> m2 \\<and> invar (g_add m1 m2)\"\n      unfolding A\n      apply (rule \n        iterate_add_to_map_correct[of \\<alpha> invar update m1 \"iteratei m2\" \"\\<alpha> m2\"])\n      apply unfold_locales []\n      apply fact\n      apply (rule iteratei_correct, fact)\n      done\n    thus \"\\<alpha> (g_add m1 m2) = \\<alpha> m1 ++ \\<alpha> m2\" \"invar (g_add m1 m2)\" by auto\n  qed\n\n  lemma g_sel_impl: \"map_sel' \\<alpha> invar g_sel\"\n  proof -\n    have A: \"\\<And>m P. g_sel m P = iterate_sel_no_map (iteratei m) P\"\n      unfolding g_sel_def iterate_sel_no_map_def iterate_sel_def by simp\n\n    { fix m P\n      assume I: \"invar m\"\n      note iterate_sel_no_map_correct[OF iteratei_correct[OF I], of P]\n    }\n    thus ?thesis\n      apply unfold_locales\n      unfolding A\n      apply (simp add: Bex_def Ball_def image_iff map_to_set_def)\n      apply clarify\n      apply (metis option.exhaust PairE)\n      apply (simp add: Bex_def Ball_def image_iff map_to_set_def)\n      done\n  qed\n  \n  lemma g_bex_impl: \"map_bex \\<alpha> invar g_bex\"\n    apply unfold_locales\n    unfolding g_bex_def\n    apply (rule_tac I=\"\\<lambda>it \\<sigma>. \\<sigma> \\<longleftrightarrow> (\\<exists>kv\\<in>it. P kv)\" \n      in iteratei_rule_insert_P)\n    by (auto simp: map_to_set_def)\n\n  \n\n  lemma g_size_impl: \"map_size \\<alpha> invar g_size\"\n  proof \n    fix m\n    assume I: \"invar m\"\n    have A: \"g_size m \\<equiv> iterate_size (iteratei m)\"\n      unfolding g_size_def iterate_size_def by simp\n  \n    from iterate_size_correct [OF iteratei_correct[OF I]]\n    show \"g_size m = card (dom (\\<alpha> m))\"\n      unfolding A\n      by (simp_all add: card_map_to_set) \n  qed \n\n  lemma g_size_abort_impl: \"map_size_abort \\<alpha> invar g_size_abort\"\n  proof \n    fix s m\n    assume I: \"invar m\"\n    have A: \"g_size_abort s m \\<equiv> iterate_size_abort (iteratei m) s\"\n      unfolding g_size_abort_def iterate_size_abort_def by simp\n  \n    from iterate_size_abort_correct [OF iteratei_correct[OF I]]\n    show \"g_size_abort s m = min s (card (dom (\\<alpha> m)))\"\n      unfolding A\n      by (simp_all add: card_map_to_set) \n  qed \n\n  lemma g_isEmpty_impl: \"map_isEmpty \\<alpha> invar g_isEmpty\"\n  proof \n    fix m\n    assume I: \"invar m\"\n    interpret map_size_abort \\<alpha> invar g_size_abort by (rule g_size_abort_impl)\n    from size_abort_correct[OF I] have \n      \"g_size_abort 1 m = min 1 (card (dom (\\<alpha> m)))\" .\n    thus \"g_isEmpty m = (\\<alpha> m = Map.empty)\" unfolding g_isEmpty_def\n      by (auto simp: min_def card_0_eq[OF finite] I)\n  qed\n\n  lemma g_isSng_impl: \"map_isSng \\<alpha> invar g_isSng\"\n  proof \n    fix m\n    assume I: \"invar m\"\n    interpret map_size_abort \\<alpha> invar g_size_abort by (rule g_size_abort_impl)\n    from size_abort_correct[OF I] have \n      \"g_size_abort 2 m = min 2 (card (dom (\\<alpha> m)))\" .\n    thus \"g_isSng m = (\\<exists>k v. \\<alpha> m = [k \\<mapsto> v])\" unfolding g_isSng_def\n      by (auto simp: min_def I card_Suc_eq dom_eq_singleton_conv)\n  qed\n  \n  lemma g_to_list_impl: \"map_to_list \\<alpha> invar g_to_list\"\n  proof \n    fix m \n    assume I: \"invar m\"\n\n    have A: \"g_to_list m = iterate_to_list (iteratei m)\"\n      unfolding g_to_list_def iterate_to_list_def by simp\n\n    from iterate_to_list_correct [OF iteratei_correct[OF I]]\n    have set_l_eq: \"set (g_to_list m) = map_to_set (\\<alpha> m)\" and \n      dist_l: \"distinct (g_to_list m)\" unfolding A by simp_all\n\n    from dist_l show dist_fst_l: \"distinct (map fst (g_to_list m))\"\n      by (simp add: distinct_map set_l_eq map_to_set_def inj_on_def)\n    \n    from map_of_map_to_set[of \"(g_to_list m)\" \"\\<alpha> m\", OF dist_fst_l] set_l_eq\n    show \"map_of (g_to_list m) = \\<alpha> m\" by simp\n  qed\n\n  lemma g_list_to_map_impl: \"list_to_map \\<alpha> invar g_list_to_map\"\n  proof -\n    {\n      fix m0 l\n      assume \"invar m0\"\n      hence \"invar (foldl (\\<lambda>s (k,v). update k v s) m0 l) \\<and> \n        \\<alpha> (foldl (\\<lambda>s (k,v). update k v s) m0 l) = \\<alpha> m0 ++ map_of (rev l)\"\n      proof (induction l arbitrary: m0)\n        case Nil thus ?case by simp\n      next\n        case (Cons kv l)\n        obtain k v where [simp]: \"kv=(k,v)\" by (cases kv) auto\n        have \"invar (foldl (\\<lambda>s (k, v). update k v s) m0 (kv # l))\"\n          apply simp\n          apply (rule conjunct1[OF Cons.IH])\n          apply (simp add: update_correct Cons.prems)\n          done\n        moreover have \"\\<alpha> (foldl (\\<lambda>s (k, v). update k v s) m0 (kv # l)) =\n          \\<alpha> m0 ++ map_of (rev (kv # l))\"\n          apply simp\n          thm trans[OF conjunct2[OF Cons.IH]]\n          apply (rule trans[OF conjunct2[OF Cons.IH]])\n          apply (auto \n            simp: update_correct Cons.prems Map.map_add_def[abs_def]\n            split: option.split\n          )\n          done\n        ultimately show ?case\n          by simp\n      qed\n    } thus ?thesis\n      apply unfold_locales\n      unfolding g_list_to_map_def\n      apply (auto simp: empty_correct)\n      done\n  qed\n\n  lemma g_add_dj_impl: \"map_add_dj \\<alpha> invar g_add_dj\"\n  proof\n    fix m1 m2\n    assume \"invar m1\" \"invar m2\" and DJ: \"dom (\\<alpha> m1) \\<inter> dom (\\<alpha> m2) = {}\"\n\n    have A: \"g_add_dj m1 m2 = iterate_add_to_map m1 update_dj (iteratei m2)\"\n      unfolding g_add_dj_def iterate_add_to_map_def by simp\n    have \"\\<alpha> (g_add_dj m1 m2) = \\<alpha> m1 ++ \\<alpha> m2 \\<and> invar (g_add_dj m1 m2)\"\n      unfolding A\n      apply (rule \n        iterate_add_to_map_dj_correct[\n        of \\<alpha> invar update_dj m1 \"iteratei m2\" \"\\<alpha> m2\"])\n      apply unfold_locales []\n      apply fact\n      apply (rule iteratei_correct, fact)\n      using DJ apply (simp add: Int_ac)\n      done\n    thus \"\\<alpha> (g_add_dj m1 m2) = \\<alpha> m1 ++ \\<alpha> m2\" \"invar (g_add_dj m1 m2)\" by auto\n  qed\n  \n  lemma g_restrict_impl: \"map_restrict \\<alpha> invar \\<alpha> invar g_restrict\"\n  proof \n    fix m P\n    assume I: \"invar m\"\n\n    have AUX: \"\\<And>k v it \\<sigma>.\n       \\<lbrakk>it \\<subseteq> {(k, v). \\<alpha> m k = Some v}; \\<alpha> m k = Some v; (k, v) \\<notin> it;\n        {(k, v). \\<alpha> \\<sigma> k = Some v} = it \\<inter> Collect P\\<rbrakk>\n       \\<Longrightarrow> k \\<notin> dom (\\<alpha> \\<sigma>)\"\n    proof (rule ccontr, simp)\n      fix k v it \\<sigma>\n      assume \"k\\<in>dom (\\<alpha> \\<sigma>)\" \n      then obtain v' where \"\\<alpha> \\<sigma> k = Some v'\" by auto\n      moreover assume \"{(k, v). \\<alpha> \\<sigma> k = Some v} = it \\<inter> Collect P\"\n      ultimately have MEM: \"(k,v')\\<in>it\" by auto\n      moreover assume \"it \\<subseteq> {(k, v). \\<alpha> m k = Some v}\" and \"\\<alpha> m k = Some v\"\n      ultimately have \"v'=v\" by auto\n      moreover assume \"(k,v)\\<notin>it\"\n      moreover note MEM \n      ultimately show False by simp\n    qed\n\n    have \"\\<alpha> (g_restrict P m) = \\<alpha> m |` {k. \\<exists>v. \\<alpha> m k = Some v \\<and> P (k, v)} \\<and>\n      invar (g_restrict P m)\"\n      unfolding g_restrict_def\n      apply (rule_tac I=\"\\<lambda>it \\<sigma>. invar \\<sigma> \n        \\<and> map_to_set (\\<alpha> \\<sigma>) = it \\<inter> Collect P\"\n        in iterate_rule_insert_P)\n      apply (auto simp: I empty_correct update_dj_correct map_to_set_def AUX)\n      apply (auto split: split_if_asm)\n      apply (rule ext)\n      apply (auto simp: Map.restrict_map_def)\n      apply force\n      apply (rule ccontr)\n      apply force\n      done\n    thus \"\\<alpha> (g_restrict P m) = \\<alpha> m |` {k. \\<exists>v. \\<alpha> m k = Some v \\<and> P (k, v)}\"\n      \"invar (g_restrict P m)\" by auto\n  qed\n\n  \n\n\ncontext StdBasicOMapDefs \nbegin\n  definition \n    \"g_min m P \\<equiv> \n      iterateoi m (\\<lambda>\\<sigma>. \\<sigma> = None) (\\<lambda>x \\<sigma>. if P x then Some x else None) None\"\n\n  definition \n    \"g_max m P \\<equiv> \n      rev_iterateoi m (\\<lambda>\\<sigma>. \\<sigma> = None) (\\<lambda>x \\<sigma>. if P x then Some x else None) None\"\n\n  definition \"g_to_sorted_list m \\<equiv> rev_iterateo m (op #) []\"\n  definition \"g_to_rev_list m \\<equiv> iterateo m (op #) []\"\n\n  definition dflt_oops :: \"('k,'v,'s) omap_ops\" \n    where [icf_rec_def]:\n    \"dflt_oops \\<equiv> map_ops.extend dflt_ops\n      \\<lparr> \n        map_op_ordered_list_it = ordered_list_it,\n        map_op_rev_list_it = rev_list_it,\n        map_op_min = g_min,\n        map_op_max = g_max,\n        map_op_to_sorted_list = g_to_sorted_list,\n        map_op_to_rev_list = g_to_rev_list\n      \\<rparr>\"\n  local_setup {* Locale_Code.lc_decl_del @{term dflt_oops}*}\n\nend\n\ncontext StdBasicOMap \nbegin\n  lemma g_min_impl: \"map_min \\<alpha> invar g_min\"\n  proof \n    fix m P\n\n    assume I: \"invar m\"\n  \n    from iterateoi_correct[OF I]\n    have iti': \"map_iterator_linord (iterateoi m) (\\<alpha> m)\" by simp\n    note sel_correct = iterate_sel_no_map_map_linord_correct[OF iti', of P]\n\n    have A: \"g_min m P = iterate_sel_no_map (iterateoi m) P\"\n      unfolding g_min_def iterate_sel_no_map_def iterate_sel_def by simp\n  \n    { assume \"rel_of (\\<alpha> m) P \\<noteq> {}\"\n      with sel_correct \n      show \"g_min m P \\<in> Some ` rel_of (\\<alpha> m) P\"\n        unfolding A\n        by (auto simp add: image_iff rel_of_def)\n    }\n\n    { assume \"rel_of (\\<alpha> m) P = {}\"        \n       with sel_correct show \"g_min m P = None\"\n        unfolding A\n        by (auto simp add: image_iff rel_of_def)\n    }\n\n    { fix k v\n      assume \"(k, v) \\<in> rel_of (\\<alpha> m) P\"\n      with sel_correct show \"fst (the (g_min m P)) \\<le> k\"\n        unfolding A\n        by (auto simp add: image_iff rel_of_def)\n    }\n  qed\n\n  lemma g_max_impl: \"map_max \\<alpha> invar g_max\"\n  proof \n    fix m P\n\n    assume I: \"invar m\"\n  \n    from rev_iterateoi_correct[OF I]\n    have iti': \"map_iterator_rev_linord (rev_iterateoi m) (\\<alpha> m)\" by simp\n    note sel_correct = iterate_sel_no_map_map_rev_linord_correct[OF iti', of P]\n\n    have A: \"g_max m P = iterate_sel_no_map (rev_iterateoi m) P\"\n      unfolding g_max_def iterate_sel_no_map_def iterate_sel_def by simp\n  \n    { assume \"rel_of (\\<alpha> m) P \\<noteq> {}\"\n      with sel_correct \n      show \"g_max m P \\<in> Some ` rel_of (\\<alpha> m) P\"\n        unfolding A\n        by (auto simp add: image_iff rel_of_def)\n    }\n\n    { assume \"rel_of (\\<alpha> m) P = {}\"        \n       with sel_correct show \"g_max m P = None\"\n        unfolding A\n        by (auto simp add: image_iff rel_of_def)\n    }\n\n    { fix k v\n      assume \"(k, v) \\<in> rel_of (\\<alpha> m) P\"\n      with sel_correct show \"fst (the (g_max m P)) \\<ge> k\"\n        unfolding A\n        by (auto simp add: image_iff rel_of_def)\n    }\n  qed\n\n  lemma g_to_sorted_list_impl: \"map_to_sorted_list \\<alpha> invar g_to_sorted_list\"\n  proof \n    fix m\n    assume I: \"invar m\"\n    note iti = rev_iterateoi_correct[OF I]\n    from iterate_to_list_map_rev_linord_correct[OF iti]\n    show \"sorted (map fst (g_to_sorted_list m))\" \n         \"distinct (map fst (g_to_sorted_list m))\"\n         \"map_of (g_to_sorted_list m) = \\<alpha> m\" \n      unfolding g_to_sorted_list_def iterate_to_list_def by simp_all\n  qed\n\n  lemma g_to_rev_list_impl: \"map_to_rev_list \\<alpha> invar g_to_rev_list\"\n  proof \n    fix m\n    assume I: \"invar m\"\n    note iti = iterateoi_correct[OF I]\n    from iterate_to_list_map_linord_correct[OF iti]\n    show \"sorted (rev (map fst (g_to_rev_list m)))\" \n         \"distinct (map fst (g_to_rev_list m))\"\n         \"map_of (g_to_rev_list m) = \\<alpha> m\" \n      unfolding g_to_rev_list_def iterate_to_list_def \n      by (simp_all add: rev_map)\n  qed\n  \n  lemma dflt_oops_impl: \"StdOMap dflt_oops\"\n  proof -\n    interpret aux!: StdMap dflt_ops by (rule dflt_ops_impl)\n\n    show ?thesis\n      apply (rule StdOMap_intro)\n      apply icf_locales\n      apply (simp_all add: icf_rec_unf)\n      apply (rule g_min_impl)\n      apply (rule g_max_impl)\n      apply (rule g_to_sorted_list_impl)\n      apply (rule g_to_rev_list_impl)\n      done\n  qed\n\nend\n\nlocale g_image_filter_defs_loc = \n  m1!: StdMapDefs ops1 + \n  m2!: StdMapDefs ops2\n  for ops1 :: \"('k1,'v1,'s1,'m1) map_ops_scheme\"\n  and ops2 :: \"('k2,'v2,'s2,'m2) map_ops_scheme\"\nbegin\n  definition \"g_image_filter f m1 \\<equiv> m1.iterate m1 (\\<lambda>kv \\<sigma>. case f kv of \n      None => \\<sigma>\n    | Some (k',v') => m2.update_dj k' v' \\<sigma>\n    ) (m2.empty ())\"\nend\n\nlocale g_image_filter_loc = g_image_filter_defs_loc ops1 ops2 + \n  m1!: StdMap ops1 + \n  m2!: StdMap ops2\n  for ops1 :: \"('k1,'v1,'s1,'m1) map_ops_scheme\"\n  and ops2 :: \"('k2,'v2,'s2,'m2) map_ops_scheme\"\nbegin\n  lemma g_image_filter_impl: \n    \"map_image_filter m1.\\<alpha> m1.invar m2.\\<alpha> m2.invar g_image_filter\"\n  proof \n    fix m k' v' and f :: \"('k1 \\<times> 'v1) \\<Rightarrow> ('k2 \\<times> 'v2) option\"\n    assume invar_m: \"m1.invar m\" and\n           unique_f: \"transforms_to_unique_keys (m1.\\<alpha> m) f\"\n    \n    have A: \"g_image_filter f m = \n      iterate_to_map m2.empty m2.update_dj (\n        set_iterator_image_filter f (m1.iteratei m))\" \n      unfolding g_image_filter_def iterate_to_map_alt_def \n        set_iterator_image_filter_def case_prod_beta\n      by simp\n  \n    from m1.iteratei_correct[OF invar_m] \n    have iti_m: \"map_iterator (m1.iteratei m) (m1.\\<alpha> m)\" by simp\n\n    from unique_f have inj_on_f: \"inj_on f (map_to_set (m1.\\<alpha> m) \\<inter> dom f)\"\n      unfolding transforms_to_unique_keys_def inj_on_def Ball_def map_to_set_def\n      by auto (metis option.inject)\n\n    def vP \\<equiv> \"\\<lambda>k v. \\<exists>k' v'. m1.\\<alpha> m k' = Some v' \\<and> f (k', v') = Some (k, v)\"\n    have vP_intro: \"\\<And>k v. (\\<exists>k' v'. m1.\\<alpha> m k' = Some v' \n        \\<and> f (k', v') = Some (k, v)) \\<longleftrightarrow> vP k v\"\n      unfolding vP_def by simp\n    { fix k v\n      have \"Eps_Opt (vP k) = Some v \\<longleftrightarrow> vP k v\"\n        using unique_f unfolding vP_def transforms_to_unique_keys_def \n        apply (rule_tac Eps_Opt_eq_Some)\n        apply (metis Pair_eq option.inject)\n      done\n    } note Eps_vP_elim[simp] = this\n    have map_intro: \"{y. \\<exists>x. x \\<in> map_to_set (m1.\\<alpha> m) \\<and> f x = Some y} \n      = map_to_set (\\<lambda>k. Eps_Opt (vP k))\"\n      by (simp add: map_to_set_def vP_intro set_eq_iff split: prod.splits)\n\n    from set_iterator_image_filter_correct [OF iti_m, OF inj_on_f, \n      unfolded map_intro] \n    have iti_filter: \"map_iterator (set_iterator_image_filter f (m1.iteratei m))\n          (\\<lambda>k. Eps_Opt (vP k))\" by auto\n\n    have upd: \"map_update_dj m2.\\<alpha> m2.invar m2.update_dj\" by unfold_locales\n    have emp: \"map_empty m2.\\<alpha> m2.invar m2.empty\" by unfold_locales\n  \n    from iterate_to_map_correct[OF upd emp iti_filter] show\n      \"map_op_invar ops2 (g_image_filter f m) \\<and>\n          (map_op_\\<alpha> ops2 (g_image_filter f m) k' = Some v') =\n          (\\<exists>k v. map_op_\\<alpha> ops1 m k = Some v \\<and> f (k, v) = Some (k', v'))\"\n      unfolding A vP_def[symmetric]\n      by (simp add: vP_intro)\n  \n  qed\nend\n\nsublocale g_image_filter_loc \n  < map_image_filter m1.\\<alpha> m1.invar m2.\\<alpha> m2.invar g_image_filter\n  by (rule g_image_filter_impl)\n\n\nlocale g_value_image_filter_defs_loc = \n  m1!: StdMapDefs ops1 + \n  m2!: StdMapDefs ops2\n  for ops1 :: \"('k,'v1,'s1,'m1) map_ops_scheme\"\n  and ops2 :: \"('k,'v2,'s2,'m2) map_ops_scheme\"\nbegin\n  definition \"g_value_image_filter f m1 \\<equiv> m1.iterate m1 (\\<lambda>(k,v) \\<sigma>. \n    case f k v of \n      None => \\<sigma>\n    | Some v' => m2.update_dj k v' \\<sigma>\n    ) (m2.empty ())\"\n  \nend\n\n(* TODO: Move to Misc *)\nlemma restrict_map_dom_subset: \"\\<lbrakk> dom m \\<subseteq> R\\<rbrakk> \\<Longrightarrow> m|`R = m\"\n  apply (rule ext)\n  apply (auto simp: restrict_map_def)\n  apply (case_tac \"m x\")\n  apply auto\n  done\n\n\nlocale g_value_image_filter_loc = g_value_image_filter_defs_loc ops1 ops2 + \n  m1!: StdMap ops1 + \n  m2!: StdMap ops2\n  for ops1 :: \"('k,'v1,'s1,'m1) map_ops_scheme\"\n  and ops2 :: \"('k,'v2,'s2,'m2) map_ops_scheme\"\nbegin\n  lemma g_value_image_filter_impl: \n    \"map_value_image_filter m1.\\<alpha> m1.invar m2.\\<alpha> m2.invar g_value_image_filter\"\n    apply unfold_locales\n    unfolding g_value_image_filter_def\n    apply (rule_tac I=\"\\<lambda>it \\<sigma>. m2.invar \\<sigma> \n      \\<and> m2.\\<alpha> \\<sigma> = (\\<lambda>k. Option.bind (map_op_\\<alpha> ops1 m k) (f k)) |` it\"\n      in m1.old_iterate_rule_insert_P)\n\n    apply auto []\n    apply (auto simp: m2.empty_correct) []\n    defer\n    apply simp []\n    apply (rule restrict_map_dom_subset)\n    apply (auto) []\n    apply (case_tac \"m1.\\<alpha> m x\")\n    apply (auto) [2]\n\n    apply (auto split: option.split simp: m2.update_dj_correct intro!: ext)\n    apply (auto simp: restrict_map_def)\n    done\nend\n\nsublocale g_value_image_filter_loc \n  < map_value_image_filter m1.\\<alpha> m1.invar m2.\\<alpha> m2.invar g_value_image_filter\n  by (rule g_value_image_filter_impl)\n\n\nend\n\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Collections/ICF/gen_algo/MapGA.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.2966962745201913}}
{"text": "section \\<open>Syntactic Criteria\\<close>\ntheory Syntactic_Criteria\n  imports Compositionality\nbegin\n\ncontext PL_Indis\nbegin\n\nlemma proper_intros[intro]:\n  \"proper Done\"\n  \"proper (Atm atm)\"\n  \"proper c1 \\<Longrightarrow> proper c2 \\<Longrightarrow> proper (Seq c1 c2)\"\n  \"proper c1 \\<Longrightarrow> proper c2 \\<Longrightarrow> proper (Ch ch c1 c2)\"\n  \"proper c \\<Longrightarrow> proper (While tst c)\"\n  \"properL cs \\<Longrightarrow> proper (Par cs)\"\n  \"properL cs \\<Longrightarrow> proper (ParT cs)\"\n  \"(\\<And>c. c \\<in> set cs \\<Longrightarrow> proper c) \\<Longrightarrow> cs \\<noteq> [] \\<Longrightarrow> properL cs\"\n  by auto\n\nlemma discr:\n  \"discr Done\"\n  \"presAtm atm \\<Longrightarrow> discr (Atm atm)\"\n  \"discr c1 \\<Longrightarrow> discr c2 \\<Longrightarrow> discr (Seq c1 c2)\"\n  \"discr c1 \\<Longrightarrow> discr c2 \\<Longrightarrow> discr (Ch ch c1 c2)\"\n  \"discr c \\<Longrightarrow> discr (While tst c)\"\n  \"properL cs \\<Longrightarrow> (\\<And>c. c \\<in> set cs \\<Longrightarrow> discr c) \\<Longrightarrow> discr (Par cs)\"\n  \"properL cs \\<Longrightarrow> (\\<And>c. c \\<in> set cs \\<Longrightarrow> discr c) \\<Longrightarrow> discr (ParT cs)\"\n  by (auto intro!: discr_Par discr_ParT)\n\nlemma siso:\n  \"compatAtm atm \\<Longrightarrow> siso (Atm atm)\"\n  \"siso c1 \\<Longrightarrow> siso c2 \\<Longrightarrow> siso (Seq c1 c2)\"\n  \"compatCh ch \\<Longrightarrow> siso c1 \\<Longrightarrow> siso c2 \\<Longrightarrow> siso (Ch ch c1 c2)\"\n  \"compatTst tst \\<Longrightarrow> siso c \\<Longrightarrow> siso (While tst c)\"\n  \"properL cs \\<Longrightarrow> (\\<And>c. c \\<in> set cs \\<Longrightarrow> siso c) \\<Longrightarrow> siso (Par cs)\"\n  \"properL cs \\<Longrightarrow> (\\<And>c. c \\<in> set cs \\<Longrightarrow> siso c) \\<Longrightarrow> siso (ParT cs)\"\n  by (auto intro!: siso_Par siso_ParT)\n\nlemma Sbis:\n  \"compatAtm atm \\<Longrightarrow> Atm atm \\<approx>s Atm atm\"\n  \"siso c1 \\<Longrightarrow> c2 \\<approx>s c2 \\<Longrightarrow> Seq c1 c2 \\<approx>s Seq c1 c2\"\n  \"proper c1 \\<Longrightarrow> proper c2 \\<Longrightarrow> c1 \\<approx>s c1 \\<Longrightarrow> discr c2 \\<Longrightarrow> Seq c1 c2 \\<approx>s Seq c1 c2\"\n  \"compatCh ch \\<Longrightarrow> c1 \\<approx>s c1 \\<Longrightarrow> c2 \\<approx>s c2 \\<Longrightarrow> Ch ch c1 c2 \\<approx>s Ch ch c1 c2\"\n  \"properL cs \\<Longrightarrow> (\\<And>c. c \\<in> set cs \\<Longrightarrow> c \\<approx>s c) \\<Longrightarrow> Par cs \\<approx>s Par cs\"\n  by (auto intro!: Par_Sbis)\n\nlemma ZObis:\n  \"compatAtm atm \\<Longrightarrow> Atm atm \\<approx>01 Atm atm\"\n  \"siso c1 \\<Longrightarrow> c2 \\<approx>01 c2 \\<Longrightarrow> Seq c1 c2 \\<approx>01 Seq c1 c2\"\n  \"proper c1 \\<Longrightarrow> proper c2 \\<Longrightarrow> c1 \\<approx>01 c1 \\<Longrightarrow> discr c2 \\<Longrightarrow> Seq c1 c2 \\<approx>01 Seq c1 c2\"\n  \"compatCh ch \\<Longrightarrow> c1 \\<approx>01 c1 \\<Longrightarrow> c2 \\<approx>01 c2 \\<Longrightarrow> Ch ch c1 c2 \\<approx>01 Ch ch c1 c2\"\n  \"properL cs \\<Longrightarrow> (\\<And>c. c \\<in> set cs \\<Longrightarrow> c \\<approx>s c) \\<Longrightarrow> ParT cs \\<approx>01 ParT cs\"\n  by (auto intro!: ParT_ZObis)\n\nlemma discr_imp_Sbis: \"proper c \\<Longrightarrow> discr c \\<Longrightarrow> c \\<approx>s c\"\n  by auto\n\nlemma siso_imp_Sbis: \"siso c \\<Longrightarrow> c \\<approx>s c\"\n  by auto\n\nlemma Sbis_imp_ZObis: \"c \\<approx>s c \\<Longrightarrow> c \\<approx>01 c\"\n  by auto\n\n\n(* The syntactic predicates: SC_\\<phi> corresponds to the paper's overlined \\<phi>: *) \n\nfun SC_discr where\n  \"SC_discr Done          \\<longleftrightarrow> True\"\n| \"SC_discr (Atm atm)     \\<longleftrightarrow> presAtm atm\"\n| \"SC_discr (Seq c1 c2)   \\<longleftrightarrow> SC_discr c1 \\<and> SC_discr c2\"\n| \"SC_discr (Ch ch c1 c2) \\<longleftrightarrow> SC_discr c1 \\<and> SC_discr c2\"\n| \"SC_discr (While tst c) \\<longleftrightarrow> SC_discr c\"\n| \"SC_discr (ParT cs) \\<longleftrightarrow> (\\<forall>c\\<in>set cs. SC_discr c)\"\n| \"SC_discr (Par cs)  \\<longleftrightarrow> (\\<forall>c\\<in>set cs. SC_discr c)\"\n\ntheorem SC_discr_discr[intro]: \"proper c \\<Longrightarrow> SC_discr c \\<Longrightarrow> discr c\"\n  by (induct c) (auto intro!: discr)\n\nfun SC_siso where\n  \"SC_siso Done           \\<longleftrightarrow> True\"\n| \"SC_siso (Atm atm)      \\<longleftrightarrow> compatAtm atm\"\n| \"SC_siso (Seq c1 c2)    \\<longleftrightarrow> SC_siso c1 \\<and> SC_siso c2\"\n| \"SC_siso (Ch ch c1 c2)  \\<longleftrightarrow> compatCh ch \\<and> SC_siso c1 \\<and> SC_siso c2\"\n| \"SC_siso (While tst c)  \\<longleftrightarrow> compatTst tst \\<and> SC_siso c\"\n| \"SC_siso (Par cs)   \\<longleftrightarrow> (\\<forall>c\\<in>set cs. SC_siso c)\"\n| \"SC_siso (ParT cs)  \\<longleftrightarrow> (\\<forall>c\\<in>set cs. SC_siso c)\"\n\ntheorem SC_siso_siso[intro]: \"proper c \\<Longrightarrow> SC_siso c \\<Longrightarrow> siso c\"\n  by (induct c) (auto intro!: siso)\n\nfun SC_Sbis where\n  \"SC_Sbis Done           \\<longleftrightarrow> True\"\n| \"SC_Sbis (Atm atm)      \\<longleftrightarrow> compatAtm atm\"\n| \"SC_Sbis (Seq c1 c2)    \\<longleftrightarrow> (SC_siso c1 \\<and> SC_Sbis c2) \\<or>\n                             (SC_Sbis c1 \\<and> SC_discr c2) \\<or>\n                             SC_discr (Seq c1 c2) \\<or> SC_siso (Seq c1 c2)\"\n| \"SC_Sbis (Ch ch c1 c2)  \\<longleftrightarrow> (if compatCh ch\n                             then SC_Sbis c1 \\<and> SC_Sbis c2\n                             else (SC_discr (Ch ch c1 c2) \\<or> SC_siso (Ch ch c1 c2)))\"\n| \"SC_Sbis (While tst c)  \\<longleftrightarrow> SC_discr (While tst c) \\<or> SC_siso (While tst c)\"\n| \"SC_Sbis (Par cs)   \\<longleftrightarrow> (\\<forall>c\\<in>set cs. SC_Sbis c)\"\n| \"SC_Sbis (ParT cs)  \\<longleftrightarrow> SC_siso (ParT cs) \\<or> SC_discr (ParT cs)\"\n\ntheorem SC_siso_SCbis[intro]: \"SC_siso c \\<Longrightarrow> SC_Sbis c\"\n  by (induct c) auto\n\ntheorem SC_discr_SCbis[intro]: \"SC_discr c \\<Longrightarrow> SC_Sbis c\"\n  by (induct c) auto\n\ndeclare SC_siso.simps[simp del]\n\ndeclare SC_discr.simps[simp del]\n\ntheorem SC_Sbis_Sbis[intro]: \"proper c \\<Longrightarrow> SC_Sbis c \\<Longrightarrow> c \\<approx>s c\"\n  by (induct c)\n     (auto intro: Sbis discr_imp_Sbis siso_imp_Sbis\n           split: if_split_asm)\n\nfun SC_ZObis where\n  \"SC_ZObis Done           \\<longleftrightarrow> True\"\n| \"SC_ZObis (Atm atm)      \\<longleftrightarrow> compatAtm atm\"\n| \"SC_ZObis (Seq c1 c2)    \\<longleftrightarrow> (SC_siso c1 \\<and> SC_ZObis c2) \\<or>\n                             (SC_ZObis c1 \\<and> SC_discr c2) \\<or>\n                             SC_Sbis (Seq c1 c2)\"\n| \"SC_ZObis (Ch ch c1 c2)  \\<longleftrightarrow> (if compatCh ch\n                             then SC_ZObis c1 \\<and> SC_ZObis c2\n                             else SC_Sbis (Ch ch c1 c2))\"\n| \"SC_ZObis (While tst c)  \\<longleftrightarrow> SC_Sbis (While tst c)\"\n| \"SC_ZObis (Par cs)   \\<longleftrightarrow> SC_Sbis (Par cs)\"\n| \"SC_ZObis (ParT cs)  \\<longleftrightarrow> (\\<forall>c\\<in>set cs. SC_Sbis c)\"\n\ntheorem SC_Sbis_SC_ZObis[intro]: \"SC_Sbis c \\<Longrightarrow> SC_ZObis c\"\n  by (induct c) (auto simp: SC_siso.simps SC_discr.simps)\n\ndeclare SC_Sbis.simps[simp del]\n\ntheorem SC_ZObis_ZObis: \"proper c \\<Longrightarrow> SC_ZObis c \\<Longrightarrow> c \\<approx>01 c\"\n  apply (induct c)\n  apply (auto intro: Sbis_imp_ZObis ZObis split: if_split_asm)\n  apply (auto intro!: ZObis(5))\n  done\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Probabilistic_Noninterference/Syntactic_Criteria.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.2966962745201913}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory spec_annotated_fn\nimports \"../CTranslation\"\nbegin\n\ndeclare sep_conj_ac [simp add]\n\ninstall_C_file \"spec_annotated_fn.c\"\n\n\nprint_locale spec_annotated_fn_global_addresses\nprint_locale Square_spec\n\nthm Square_spec_def\n\ncontext spec_annotated_fn_global_addresses\nbegin\n\nthm Square_body_def\nthm Square_impl\nthm Square_spec_def\nthm \\<Gamma>_def\n\nend\n\nlemma (in Square_spec) foo:\n  shows \"\\<Gamma> \\<turnstile> \\<lbrace> T \\<rbrace> \\<acute>ret__unsigned :== CALL Square(4) \\<lbrace> \\<acute>ret__unsigned = 16 \\<rbrace> \"\napply vcg\napply simp\ndone\n\nlemma (in spec_annotated_fn_global_addresses)\nshows \"\\<forall>n. \\<Gamma> \\<turnstile> \\<lbrace> \\<acute>n = n \\<rbrace> \\<acute>ret__unsigned :== PROC Square(\\<acute>n)\n               \\<lbrace>\\<acute>ret__unsigned = n * n \\<rbrace>\"\napply vcg\ndone\n\nend\n", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/c-parser/testfiles/spec_annotated_fn.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.2966962745201913}}
{"text": "chapter \\<open>Generated by Lem from \\<open>list.lem\\<close>.\\<close>\n\ntheory \"Lem_list\" \n\nimports\n  Main\n  \"Lem_bool\"\n  \"Lem_maybe\"\n  \"Lem_basic_classes\"\n  \"Lem_function\"\n  \"Lem_tuple\"\n  \"Lem_num\"\n  \"Lem\"\n\nbegin \n\n \n\n(*open import Bool Maybe Basic_classes Function Tuple Num*)\n\n(*open import {coq} `Coq.Lists.List`*)\n(*open import {isabelle} `$LIB_DIR/Lem`*)\n(*open import {hol} `lemTheory` `listTheory` `rich_listTheory` `sortingTheory`*)\n\n(* ========================================================================== *)\n(* Basic list functions                                                       *)\n(* ========================================================================== *)\n\n(* The type of lists as well as list literals like [], [1;2], ... are hardcoded. \n   Thus, we can directly dive into derived definitions. *)\n\n\n(* ----------------------- *)\n(* cons                    *)\n(* ----------------------- *)\n\n(*val :: : forall 'a. 'a -> list 'a -> list 'a*)\n\n\n(* ----------------------- *)\n(* Emptyness check         *)\n(* ----------------------- *)\n\n(*val null : forall 'a. list 'a -> bool*)\n(*let null l=  match l with [] -> true | _ -> false end*)\n\n(* ----------------------- *)\n(* Length                  *)\n(* ----------------------- *)\n\n(*val length : forall 'a. list 'a -> nat*)\n(*let rec length l=\n   match l with\n    | [] -> 0\n    | x :: xs -> (Instance_Num_NumAdd_nat.+) (length xs) 1\n  end*)\n\n(* ----------------------- *)\n(* Equality                *)\n(* ----------------------- *)\n\n(*val listEqual : forall 'a. Eq 'a => list 'a -> list 'a -> bool*)\n(*val listEqualBy : forall 'a. ('a -> 'a -> bool) -> list 'a -> list 'a -> bool*)\n\nfun  listEqualBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list \\<Rightarrow> bool \"  where \n     \" listEqualBy eq ([]) ([]) = ( True )\"\n|\" listEqualBy eq ([]) (_ # _) = ( False )\"\n|\" listEqualBy eq (_ # _) ([]) = ( False )\"\n|\" listEqualBy eq (x # xs) (y # ys) = ( (eq x y \\<and> listEqualBy eq xs ys))\"\n\n\n\n(* ----------------------- *)\n(* compare                 *)\n(* ----------------------- *)\n\n(*val lexicographicCompare : forall 'a. Ord 'a => list 'a -> list 'a -> ordering*)\n(*val lexicographicCompareBy : forall 'a. ('a -> 'a -> ordering) -> list 'a -> list 'a -> ordering*)\n\nfun  lexicographicCompareBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> ordering)\\<Rightarrow> 'a list \\<Rightarrow> 'a list \\<Rightarrow> ordering \"  where \n     \" lexicographicCompareBy cmp ([]) ([]) = ( EQ )\"\n|\" lexicographicCompareBy cmp ([]) (_ # _) = ( LT )\"\n|\" lexicographicCompareBy cmp (_ # _) ([]) = ( GT )\"\n|\" lexicographicCompareBy cmp (x # xs) (y # ys) = ( (\n      (case  cmp x y of \n          LT => LT\n        | GT => GT\n        | EQ => lexicographicCompareBy cmp xs ys\n      )\n    ))\"\n\n\n(*val lexicographicLess : forall 'a. Ord 'a => list 'a -> list 'a -> bool*)\n(*val lexicographicLessBy : forall 'a. ('a -> 'a -> bool) -> ('a -> 'a -> bool) -> list 'a -> list 'a -> bool*)\nfun  lexicographicLessBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow>('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list \\<Rightarrow> bool \"  where \n     \" lexicographicLessBy less1 less_eq1 ([]) ([]) = ( False )\"\n|\" lexicographicLessBy less1 less_eq1 ([]) (_ # _) = ( True )\"\n|\" lexicographicLessBy less1 less_eq1 (_ # _) ([]) = ( False )\"\n|\" lexicographicLessBy less1 less_eq1 (x # xs) (y # ys) = ( ((less1 x y) \\<or> ((less_eq1 x y) \\<and> (lexicographicLessBy less1 less_eq1 xs ys))))\"\n\n\n(*val lexicographicLessEq : forall 'a. Ord 'a => list 'a -> list 'a -> bool*)\n(*val lexicographicLessEqBy : forall 'a. ('a -> 'a -> bool) -> ('a -> 'a -> bool) -> list 'a -> list 'a -> bool*)\nfun  lexicographicLessEqBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow>('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list \\<Rightarrow> bool \"  where \n     \" lexicographicLessEqBy less1 less_eq1 ([]) ([]) = ( True )\"\n|\" lexicographicLessEqBy less1 less_eq1 ([]) (_ # _) = ( True )\"\n|\" lexicographicLessEqBy less1 less_eq1 (_ # _) ([]) = ( False )\"\n|\" lexicographicLessEqBy less1 less_eq1 (x # xs) (y # ys) = ( (less1 x y \\<or> (less_eq1 x y \\<and> lexicographicLessEqBy less1 less_eq1 xs ys)))\"\n\n\n\ndefinition instance_Basic_classes_Ord_list_dict  :: \" 'a Ord_class \\<Rightarrow>('a list)Ord_class \"  where \n     \" instance_Basic_classes_Ord_list_dict dict_Basic_classes_Ord_a = ((|\n\n  compare_method = (lexicographicCompareBy \n  (compare_method   dict_Basic_classes_Ord_a)),\n\n  isLess_method = (lexicographicLessBy \n  (isLess_method   dict_Basic_classes_Ord_a) (isLessEqual_method   dict_Basic_classes_Ord_a)),\n\n  isLessEqual_method = (lexicographicLessEqBy \n  (isLess_method   dict_Basic_classes_Ord_a) (isLessEqual_method   dict_Basic_classes_Ord_a)),\n\n  isGreater_method = (\\<lambda> x y. (lexicographicLessBy \n  (isLess_method   dict_Basic_classes_Ord_a) (isLessEqual_method   dict_Basic_classes_Ord_a) y x)),\n\n  isGreaterEqual_method = (\\<lambda> x y. (lexicographicLessEqBy \n  (isLess_method   dict_Basic_classes_Ord_a) (isLessEqual_method   dict_Basic_classes_Ord_a) y x))|) )\"\n\n\n\n(* ----------------------- *)\n(* Append                  *)\n(* ----------------------- *)\n\n(*val ++ : forall 'a. list 'a -> list 'a -> list 'a*) (* originally append *)\n(*let rec ++ xs ys=  match xs with\n                     | [] -> ys\n                     | x :: xs' -> x :: (xs' ++ ys)\n                   end*)\n\n(* ----------------------- *)\n(* snoc                    *)\n(* ----------------------- *)\n\n(*val snoc : forall 'a. 'a -> list 'a -> list 'a*)\n(*let snoc e l=  l ++ [e]*)\n\n\n(* ----------------------- *)\n(* Reverse                 *)\n(* ----------------------- *)\n\n(* First lets define the function [reverse_append], which is\n   closely related to reverse. [reverse_append l1 l2] appends the list [l2] to the reverse of [l1].\n   This can be implemented more efficienctly than appending and is\n   used to implement reverse. *)\n\n(*val reverseAppend : forall 'a. list 'a -> list 'a -> list 'a*) (* originally named rev_append *)\n(*let rec reverseAppend l1 l2=  match l1 with \n                                | [] -> l2\n                                | x :: xs -> reverseAppend xs (x :: l2)\n                               end*)\n\n(* Reversing a list *)\n(*val reverse : forall 'a. list 'a -> list 'a*) (* originally named rev *)\n(*let reverse l=  reverseAppend l []*)\n\n(* ----------------------- *)\n(* Map                     *)\n(* ----------------------- *)\n\n(*val map_tr : forall 'a 'b. list 'b -> ('a -> 'b) -> list 'a -> list 'b*)\nfunction (sequential,domintros)  map_tr  :: \" 'b list \\<Rightarrow>('a \\<Rightarrow> 'b)\\<Rightarrow> 'a list \\<Rightarrow> 'b list \"  where \n     \" map_tr rev_acc f ([]) = ( List.rev rev_acc )\"\n|\" map_tr rev_acc f (x # xs) = ( map_tr ((f x) # rev_acc) f xs )\" \nby pat_completeness auto\n\n\n(* taken from: https://blogs.janestreet.com/optimizing-list-map/ *)\n(*val count_map : forall 'a 'b. ('a -> 'b) -> list 'a -> nat -> list 'b*)\nfunction (sequential,domintros)  count_map  :: \"('a \\<Rightarrow> 'b)\\<Rightarrow> 'a list \\<Rightarrow> nat \\<Rightarrow> 'b list \"  where \n     \" count_map f ([]) ctr = ( [])\"\n|\" count_map f (hd1 # tl1) ctr = ( f hd1 # \n    (if ctr <( 5000 :: nat) then count_map f tl1 (ctr +( 1 :: nat)) \n    else map_tr [] f tl1))\" \nby pat_completeness auto\n\n \n(*val map : forall 'a 'b. ('a -> 'b) -> list 'a -> list 'b*)\n(*let map f l=  count_map f l 0*)\n\n(* ----------------------- *)\n(* Reverse Map             *)\n(* ----------------------- *)\n\n(*val reverseMap : forall 'a 'b. ('a -> 'b) -> list 'a -> list 'b*)\n\n\n(* ========================================================================== *)\n(* Folding                                                                    *)\n(* ========================================================================== *)\n\n(* ----------------------- *)\n(* fold left               *)\n(* ----------------------- *)\n\n(*val foldl : forall 'a 'b. ('a -> 'b -> 'a) -> 'a -> list 'b -> 'a*) (* originally foldl *)\n\n(*let rec foldl f b l=  match l with\n  | []      -> b\n  | x :: xs -> foldl f (f b x) xs\nend*)\n\n\n(* ----------------------- *)\n(* fold right              *)\n(* ----------------------- *)\n\n(*val foldr : forall 'a 'b. ('a -> 'b -> 'b) -> 'b -> list 'a -> 'b*) (* originally foldr with different argument order *)\n(*let rec foldr f b l=  match l with\n  | []      -> b\n  | x :: xs -> f x (foldr f b xs)\nend*)\n\n\n(* ----------------------- *)\n(* concatenating lists     *)\n(* ----------------------- *)\n\n(*val concat : forall 'a. list (list 'a) -> list 'a*) (* before also called flatten *)\n(*let concat=  foldr (++) []*)\n\n\n(* -------------------------- *)\n(* concatenating with mapping *)\n(* -------------------------- *)\n\n(*val concatMap : forall 'a 'b. ('a -> list 'b) -> list 'a -> list 'b*)\n\n\n(* ------------------------- *)\n(* universal qualification   *)\n(* ------------------------- *)\n\n(*val all : forall 'a. ('a -> bool) -> list 'a -> bool*) (* originally for_all *)\n(*let all P l=  foldl (fun r e -> P e && r) true l*)\n\n\n\n(* ------------------------- *)\n(* existential qualification *)\n(* ------------------------- *)\n\n(*val any : forall 'a. ('a -> bool) -> list 'a -> bool*) (* originally exist *)\n(*let any P l=  foldl (fun r e -> P e || r) false l*)\n\n\n(* ------------------------- *)\n(* dest_init                 *)\n(* ------------------------- *)\n\n(* get the initial part and the last element of the list in a safe way *)\n\n(*val dest_init : forall 'a. list 'a -> maybe (list 'a * 'a)*) \n\nfun  dest_init_aux  :: \" 'a list \\<Rightarrow> 'a \\<Rightarrow> 'a list \\<Rightarrow> 'a list*'a \"  where \n     \" dest_init_aux rev_init last_elem_seen ([]) = ( (List.rev rev_init, last_elem_seen))\"\n|\" dest_init_aux rev_init last_elem_seen (x # xs) = ( dest_init_aux (last_elem_seen # rev_init) x xs )\"\n\n\nfun dest_init  :: \" 'a list \\<Rightarrow>('a list*'a)option \"  where \n     \" dest_init ([]) = ( None )\"\n|\" dest_init (x # xs) = ( Some (dest_init_aux [] x xs))\"\n\n\n\n(* ========================================================================== *)\n(* Indexing lists                                                             *)\n(* ========================================================================== *)\n\n(* ------------------------- *)\n(* index / nth with maybe   *)\n(* ------------------------- *)\n\n(*val index : forall 'a. list 'a -> nat -> maybe 'a*)\n\n(*let rec index l n=  match l with \n  | []      -> Nothing\n  | x :: xs -> if (Instance_Basic_classes_Eq_nat.=) n 0 then Just x else index xs ((Instance_Num_NumMinus_nat.-)n 1)\nend*)\n\n(* ------------------------- *)\n(* findIndices               *)\n(* ------------------------- *)\n\n(* [findIndices P l] returns the indices of all elements of list [l] that satisfy predicate [P]. \n   Counting starts with 0, the result list is sorted ascendingly *)\n(*val findIndices : forall 'a. ('a -> bool) -> list 'a -> list nat*)\n\nfun  findIndices_aux  :: \" nat \\<Rightarrow>('a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow>(nat)list \"  where \n     \" findIndices_aux (i::nat) P ([]) = ( [])\"\n|\" findIndices_aux (i::nat) P (x # xs) = ( if P x then i # findIndices_aux (i +( 1 :: nat)) P xs else findIndices_aux (i +( 1 :: nat)) P xs )\"\n\n(*let findIndices P l=  findIndices_aux 0 P l*)\n\n\n\n(* ------------------------- *)\n(* findIndex                 *)\n(* ------------------------- *)\n\n(* findIndex returns the first index of a list that satisfies a given predicate. *)\n(*val findIndex : forall 'a. ('a -> bool) -> list 'a -> maybe nat*)\n(*let findIndex P l=  match findIndices P l with\n  | [] -> Nothing\n  | x :: _ -> Just x\nend*)\n\n(* ------------------------- *)\n(* elemIndices               *)\n(* ------------------------- *)\n\n(*val elemIndices : forall 'a. Eq 'a => 'a -> list 'a -> list nat*)\n\n(* ------------------------- *)\n(* elemIndex                 *)\n(* ------------------------- *)\n\n(*val elemIndex : forall 'a. Eq 'a => 'a -> list 'a -> maybe nat*)\n\n\n(* ========================================================================== *)\n(* Creating lists                                                             *)\n(* ========================================================================== *)\n\n(* ------------------------- *)\n(* genlist                   *)\n(* ------------------------- *)\n\n(* [genlist f n] generates the list [f 0; f 1; ... (f (n-1))] *)\n(*val genlist : forall 'a. (nat -> 'a) -> nat -> list 'a*)\n\n\n(*let rec genlist f n=\n   match n with\n    | 0 -> []\n    | n' + 1 -> snoc (f n') (genlist f n')\n  end*)\n\n\n(* ------------------------- *)\n(* replicate                 *)\n(* ------------------------- *)\n\n(*val replicate : forall 'a. nat -> 'a -> list 'a*)\n(*let rec replicate n x=\n   match n with\n    | 0 -> []\n    | n' + 1 -> x :: replicate n' x\n  end*)\n\n\n(* ========================================================================== *)\n(* Sublists                                                                   *)\n(* ========================================================================== *)\n\n(* ------------------------- *)\n(* splitAt                   *)\n(* ------------------------- *)\n\n(* [splitAt n xs] returns a tuple (xs1, xs2), with append xs1 xs2 = xs and \n   length xs1 = n. If there are not enough elements \n   in [xs], the original list and the empty one are returned. *)\n(*val splitAtAcc : forall 'a. list 'a -> nat -> list 'a -> (list 'a * list 'a)*)\nfunction (sequential,domintros)  splitAtAcc  :: \" 'a list \\<Rightarrow> nat \\<Rightarrow> 'a list \\<Rightarrow> 'a list*'a list \"  where \n     \" splitAtAcc revAcc n l = ( \n  (case  l of\n      []    => (List.rev revAcc, [])\n    | x # xs => if n \\<le>( 0 :: nat) then (List.rev revAcc, l) else splitAtAcc (x # revAcc) (n-( 1 :: nat)) xs\n  ))\" \nby pat_completeness auto\n\n\n(*val splitAt : forall 'a. nat -> list 'a -> (list 'a * list 'a)*)\n(*let rec splitAt n l= \n    splitAtAcc [] n l*)\n\n\n(* ------------------------- *)\n(* take                      *)\n(* ------------------------- *)\n\n(* take n xs returns the prefix of xs of length n, or xs itself if n > length xs *)\n(*val take : forall 'a. nat -> list 'a -> list 'a*)\n(*let take n l=  fst (splitAt n l)*)\n\n(* ------------------------- *)\n(* drop                      *)\n(* ------------------------- *)\n\n(* [drop n xs] drops the first [n] elements of [xs]. It returns the empty list, if [n] > [length xs]. *)\n(*val drop : forall 'a. nat -> list 'a -> list 'a*)\n(*let drop n l=  snd (splitAt n l)*)\n\n(* ------------------------------------ *)\n(* splitWhile, takeWhile, and dropWhile *)\n(* ------------------------------------ *)\n\n(*val splitWhile_tr : forall 'a. ('a -> bool) -> list 'a -> list 'a -> (list 'a * list 'a)*)\nfun  splitWhile_tr  :: \"('a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list \\<Rightarrow> 'a list*'a list \"  where \n     \" splitWhile_tr p ([]) acc1 = (\n    (List.rev acc1, []))\"\n|\" splitWhile_tr p (x # xs) acc1 = (\n    if p x then\n      splitWhile_tr p xs (x # acc1)\n    else\n      (List.rev acc1, (x # xs)))\"\n\n\n(*val splitWhile : forall 'a. ('a -> bool) -> list 'a -> (list 'a * list 'a)*)\ndefinition splitWhile  :: \"('a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list*'a list \"  where \n     \" splitWhile p xs = ( splitWhile_tr p xs [])\"\n\n\n(* [takeWhile p xs] takes the first elements of [xs] that satisfy [p]. *)\n(*val takeWhile : forall 'a. ('a -> bool) -> list 'a -> list 'a*)\ndefinition takeWhile  :: \"('a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list \"  where \n     \" takeWhile p l = ( fst (splitWhile p l))\"\n\n\n(* [dropWhile p xs] drops the first elements of [xs] that satisfy [p]. *)\n(*val dropWhile : forall 'a. ('a -> bool) -> list 'a -> list 'a*)\ndefinition dropWhile  :: \"('a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list \"  where \n     \" dropWhile p l = ( snd (splitWhile p l))\"\n\n\n(* ------------------------- *)\n(* isPrefixOf                *)\n(* ------------------------- *)\n\n(*val isPrefixOf : forall 'a. Eq 'a => list 'a -> list 'a -> bool*)\nfun  isPrefixOf  :: \" 'a list \\<Rightarrow> 'a list \\<Rightarrow> bool \"  where \n     \" isPrefixOf ([]) _ = ( True )\"\n|\" isPrefixOf (_ # _) ([]) = ( False )\"\n|\" isPrefixOf (x # xs) (y # ys) = ( (x = y) \\<and> isPrefixOf xs ys )\"\n\n\n(* ------------------------- *)\n(* update                    *)\n(* ------------------------- *)\n(*val update : forall 'a. list 'a -> nat -> 'a -> list 'a*)\n(*let rec update l n e= \n   match l with\n    | []      -> []\n    | x :: xs -> if (Instance_Basic_classes_Eq_nat.=) n 0 then e :: xs else x :: (update xs ((Instance_Num_NumMinus_nat.-) n 1) e)\nend*)\n\n\n\n(* ========================================================================== *)\n(* Searching lists                                                            *)\n(* ========================================================================== *)\n\n(* ------------------------- *)\n(* Membership test           *)\n(* ------------------------- *)\n\n(* The membership test, one of the basic list functions, is actually tricky for\n   Lem, because it is tricky, which equality to use. From Lem`s point of \n   perspective, we want to use the equality provided by the equality type - class.\n   This allows for example to check whether a set is in a list of sets.\n\n   However, in order to use the equality type class, elem essentially becomes\n   existential quantification over lists. For types, which implement semantic\n   equality (=) with syntactic equality, this is overly complicated. In\n   our theorem prover backend, we would end up with overly complicated, harder\n   to read definitions and some of the automation would be harder to apply.\n   Moreover, nearly all the old Lem generated code would change and require \n   (hopefully minor) adaptions of proofs.\n\n   For now, we ignore this problem and just demand, that all instances of\n   the equality type class do the right thing for the theorem prover backends.   \n*)\n\n(*val elem : forall 'a. Eq 'a => 'a -> list 'a -> bool*)\n(*val elemBy : forall 'a. ('a -> 'a -> bool) -> 'a -> list 'a -> bool*)\n\ndefinition elemBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow> 'a \\<Rightarrow> 'a list \\<Rightarrow> bool \"  where \n     \" elemBy eq e l = ( ((\\<exists> x \\<in> (set l).  (eq e) x)))\"\n\n(*let elem=  elemBy (=)*)\n\n(* ------------------------- *)\n(* Find                      *)\n(* ------------------------- *)\n(*val find : forall 'a. ('a -> bool) -> list 'a -> maybe 'a*) (* previously not of maybe type *)\n(*let rec find P l=  match l with \n  | []      -> Nothing\n  | x :: xs -> if P x then Just x else find P xs\nend*)\n\n\n(* ----------------------------- *)\n(* Lookup in an associative list *)\n(* ----------------------------- *)\n(*val lookup   : forall 'a 'b. Eq 'a              => 'a -> list ('a * 'b) -> maybe 'b*)\n(*val lookupBy : forall 'a 'b. ('a -> 'a -> bool) -> 'a -> list ('a * 'b) -> maybe 'b*)\n\n(* DPM: eta-expansion for Coq backend type-inference. *)\ndefinition lookupBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow> 'a \\<Rightarrow>('a*'b)list \\<Rightarrow> 'b option \"  where \n     \" lookupBy eq k m = ( map_option (\\<lambda> x .  snd x) (List.find ( \\<lambda>x .  \n  (case  x of (k', _) => eq k k' )) m))\"\n\n\n(* ------------------------- *)\n(* filter                    *)\n(* ------------------------- *)\n(*val filter : forall 'a. ('a -> bool) -> list 'a -> list 'a*)\n(*let rec filter P l=  match l with\n                       | [] -> []\n                       | x :: xs -> if (P x) then x :: (filter P xs) else filter P xs\n                     end*)\n\n\n(* ------------------------- *)\n(* partition                 *)\n(* ------------------------- *)\n(*val partition : forall 'a. ('a -> bool) -> list 'a -> list 'a * list 'a*)\n(*let partition P l=  (filter P l, filter (fun x -> not (P x)) l)*)\n\n(*val reversePartition : forall 'a. ('a -> bool) -> list 'a -> list 'a * list 'a*)\ndefinition reversePartition  :: \"('a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list*'a list \"  where \n     \" reversePartition P l = ( List.partition P (List.rev l))\"\n\n\n\n(* ------------------------- *)\n(* delete first element      *)\n(* with certain property     *)\n(* ------------------------- *)\n\n(*val deleteFirst : forall 'a. ('a -> bool) -> list 'a -> maybe (list 'a)*) \n(*let rec deleteFirst P l=  match l with\n                            | [] -> Nothing\n                            | x :: xs -> if (P x) then Just xs else Maybe.map (fun xs' -> x :: xs') (deleteFirst P xs)\n                          end*)\n\n\n(*val delete : forall 'a. Eq 'a => 'a -> list 'a -> list 'a*)\n(*val deleteBy : forall 'a. ('a -> 'a -> bool) -> 'a -> list 'a -> list 'a*)\n\ndefinition deleteBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow> 'a \\<Rightarrow> 'a list \\<Rightarrow> 'a list \"  where \n     \" deleteBy eq x l = ( case_option l id (delete_first (eq x) l))\"\n\n\n\n(* ========================================================================== *)\n(* Zipping and unzipping lists                                                *)\n(* ========================================================================== *)\n\n(* ------------------------- *)\n(* zip                       *)\n(* ------------------------- *)\n\n(* zip takes two lists and returns a list of corresponding pairs. If one input list is short, excess elements of the longer list are discarded. *)\n(*val zip : forall 'a 'b. list 'a -> list 'b -> list ('a * 'b)*) (* before combine *)\n(*let rec zip l1 l2=  match (l1, l2) with\n  | (x :: xs, y :: ys) -> (x, y) :: zip xs ys\n  | _ -> []\nend*)\n\n(* ------------------------- *)\n(* unzip                     *)\n(* ------------------------- *)\n\n(*val unzip: forall 'a 'b. list ('a * 'b) -> (list 'a * list 'b)*)\n(*let rec unzip l=  match l with\n  | [] -> ([], [])\n  | (x, y) :: xys -> let (xs, ys) = unzip xys in (x :: xs, y :: ys)\nend*)\n\n(* ------------------------- *)\n(* distinct elements         *)\n(* ------------------------- *)\n\n(*val allDistinct : forall 'a. Eq 'a => list 'a -> bool*)\nfun  allDistinct  :: \" 'a list \\<Rightarrow> bool \"  where \n     \" allDistinct ([]) = ( True )\"\n|\" allDistinct (x # l') = ( \\<not> (Set.member x (set l')) \\<and> allDistinct l' )\"\n\n\n(* some more useful functions *)\n(*val mapMaybe : forall 'a 'b. ('a -> maybe 'b) -> list 'a -> list 'b*)\nfunction (sequential,domintros)  mapMaybe  :: \"('a \\<Rightarrow> 'b option)\\<Rightarrow> 'a list \\<Rightarrow> 'b list \"  where \n     \" mapMaybe f ([]) = ( [])\"\n|\" mapMaybe f (x # xs) = (\n      (case  f x of\n        None => mapMaybe f xs\n      | Some y => y # (mapMaybe f xs)\n      ))\" \nby pat_completeness auto\n\n\n(*val mapi : forall 'a 'b. (nat -> 'a -> 'b) -> list 'a -> list 'b*)\nfunction (sequential,domintros)  mapiAux  :: \"(nat \\<Rightarrow> 'b \\<Rightarrow> 'a)\\<Rightarrow> nat \\<Rightarrow> 'b list \\<Rightarrow> 'a list \"  where \n     \" mapiAux f (n :: nat) ([]) = ( [])\"\n|\" mapiAux f (n :: nat) (x # xs) = ( (f n x) # mapiAux f (n +( 1 :: nat)) xs )\" \nby pat_completeness auto\n\ndefinition mapi  :: \"(nat \\<Rightarrow> 'a \\<Rightarrow> 'b)\\<Rightarrow> 'a list \\<Rightarrow> 'b list \"  where \n     \" mapi f l = ( mapiAux f(( 0 :: nat)) l )\"\n\n\n(*val deletes: forall 'a. Eq 'a => list 'a -> list 'a -> list 'a*)\ndefinition deletes  :: \" 'a list \\<Rightarrow> 'a list \\<Rightarrow> 'a list \"  where \n     \" deletes xs ys = (\n  List.foldl ((\\<lambda> x y. remove1 y x)) xs ys )\"\n\n\n(* ========================================================================== *)\n(* Comments (not clean yet, please ignore the rest of the file)               *)\n(* ========================================================================== *)\n\n(* ----------------------- *)\n(* skipped from Haskell Lib*)\n(* ----------------------- \n\nintersperse :: a -> [a] -> [a]\nintercalate :: [a] -> [[a]] -> [a]\ntranspose :: [[a]] -> [[a]]\nsubsequences :: [a] -> [[a]]\npermutations :: [a] -> [[a]]\nfoldl` :: (a -> b -> a) -> a -> [b] -> aSource\nfoldl1` :: (a -> a -> a) -> [a] -> aSource\n\nand\nor\nsum\nproduct\nmaximum\nminimum\nscanl\nscanr\nscanl1\nscanr1\nAccumulating maps\n\nmapAccumL :: (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])Source\nmapAccumR :: (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])Source\n\niterate :: (a -> a) -> a -> [a]\nrepeat :: a -> [a]\ncycle :: [a] -> [a]\nunfoldr\n\n\ntakeWhile :: (a -> Bool) -> [a] -> [a]Source\ndropWhile :: (a -> Bool) -> [a] -> [a]Source\ndropWhileEnd :: (a -> Bool) -> [a] -> [a]Source\nspan :: (a -> Bool) -> [a] -> ([a], [a])Source\nbreak :: (a -> Bool) -> [a] -> ([a], [a])Source\nbreak p is equivalent to span (not . p).\nstripPrefix :: Eq a => [a] -> [a] -> Maybe [a]Source\ngroup :: Eq a => [a] -> [[a]]Source\ninits :: [a] -> [[a]]Source\ntails :: [a] -> [[a]]Source\n\n\nisPrefixOf :: Eq a => [a] -> [a] -> BoolSource\nisSuffixOf :: Eq a => [a] -> [a] -> BoolSource\nisInfixOf :: Eq a => [a] -> [a] -> BoolSource\n\n\n\nnotElem :: Eq a => a -> [a] -> BoolSource\n\nzip3 :: [a] -> [b] -> [c] -> [(a, b, c)]Source\nzip4 :: [a] -> [b] -> [c] -> [d] -> [(a, b, c, d)]Source\nzip5 :: [a] -> [b] -> [c] -> [d] -> [e] -> [(a, b, c, d, e)]Source\nzip6 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [(a, b, c, d, e, f)]Source\nzip7 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [(a, b, c, d, e, f, g)]Source\n\nzipWith :: (a -> b -> c) -> [a] -> [b] -> [c]Source\nzipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]Source\nzipWith4 :: (a -> b -> c -> d -> e) -> [a] -> [b] -> [c] -> [d] -> [e]Source\nzipWith5 :: (a -> b -> c -> d -> e -> f) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f]Source\nzipWith6 :: (a -> b -> c -> d -> e -> f -> g) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g]Source\nzipWith7 :: (a -> b -> c -> d -> e -> f -> g -> h) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [h]Source\n\n\nunzip3 :: [(a, b, c)] -> ([a], [b], [c])Source\nunzip4 :: [(a, b, c, d)] -> ([a], [b], [c], [d])Source\nunzip5 :: [(a, b, c, d, e)] -> ([a], [b], [c], [d], [e])Source\nunzip6 :: [(a, b, c, d, e, f)] -> ([a], [b], [c], [d], [e], [f])Source\nunzip7 :: [(a, b, c, d, e, f, g)] -> ([a], [b], [c], [d], [e], [f], [g])Source\n\n\nlines :: String -> [String]Source\nwords :: String -> [String]Source\nunlines :: [String] -> StringSource\nunwords :: [String] -> StringSource\nnub :: Eq a => [a] -> [a]Source\ndelete :: Eq a => a -> [a] -> [a]Source\n\n() :: Eq a => [a] -> [a] -> [a]Source\nunion :: Eq a => [a] -> [a] -> [a]Source\nintersect :: Eq a => [a] -> [a] -> [a]Source\nsort :: Ord a => [a] -> [a]Source\ninsert :: Ord a => a -> [a] -> [a]Source\n\n\nnubBy :: (a -> a -> Bool) -> [a] -> [a]Source\ndeleteBy :: (a -> a -> Bool) -> a -> [a] -> [a]Source\ndeleteFirstsBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]Source\nunionBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]Source\nintersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]Source\ngroupBy :: (a -> a -> Bool) -> [a] -> [[a]]Source\nsortBy :: (a -> a -> Ordering) -> [a] -> [a]Source\ninsertBy :: (a -> a -> Ordering) -> a -> [a] -> [a]Source\nmaximumBy :: (a -> a -> Ordering) -> [a] -> aSource\nminimumBy :: (a -> a -> Ordering) -> [a] -> aSource\ngenericLength :: Num i => [b] -> iSource\ngenericTake :: Integral i => i -> [a] -> [a]Source\ngenericDrop :: Integral i => i -> [a] -> [a]Source\ngenericSplitAt :: Integral i => i -> [b] -> ([b], [b])Source\ngenericIndex :: Integral a => [b] -> a -> bSource\ngenericReplicate :: Integral i => i -> a -> [a]Source\n\n\n*)\n\n\n(* ----------------------- *)\n(* skipped from Lem Lib    *)\n(* ----------------------- \n\n\nval for_all2 : forall 'a 'b. ('a -> 'b -> bool) -> list 'a -> list 'b -> bool\nval exists2 : forall 'a 'b. ('a -> 'b -> bool) -> list 'a -> list 'b -> bool\nval map2 : forall 'a 'b 'c. ('a -> 'b -> 'c) -> list 'a -> list 'b -> list 'c \nval rev_map2 : forall 'a 'b 'c. ('a -> 'b -> 'c) -> list 'a -> list 'b -> list 'c\nval fold_left2 : forall 'a 'b 'c. ('a -> 'b -> 'c -> 'a) -> 'a -> list 'b -> list 'c -> 'a\nval fold_right2 : forall 'a 'b 'c. ('a -> 'b -> 'c -> 'c) -> list 'a -> list 'b -> 'c -> 'c\n\n\n(* now maybe result and called lookup *)\nval assoc : forall 'a 'b. 'a -> list ('a * 'b) -> 'b\nlet inline {ocaml} assoc = Ocaml.List.assoc\n\n\nval mem_assoc : forall 'a 'b. 'a -> list ('a * 'b) -> bool\nval remove_assoc : forall 'a 'b. 'a -> list ('a * 'b) -> list ('a * 'b)\n\n\n\nval stable_sort : forall 'a. ('a -> 'a -> num) -> list 'a -> list 'a\nval fast_sort : forall 'a. ('a -> 'a -> num) -> list 'a -> list 'a\n\nval merge : forall 'a. ('a -> 'a -> num) -> list 'a -> list 'a -> list 'a\nval intersect : forall 'a. list 'a -> list 'a -> list 'a\n\n\n*)\n\n(*val     catMaybes : forall 'a. list (maybe 'a) -> list 'a*)\nfunction (sequential,domintros)  catMaybes  :: \"('a option)list \\<Rightarrow> 'a list \"  where \n     \" catMaybes ([]) = (\n        [])\"\n|\" catMaybes (None # xs') = (\n        catMaybes xs' )\"\n|\" catMaybes (Some x # xs') = (\n        x # catMaybes xs' )\" \nby pat_completeness auto\n\nend\n", "meta": {"author": "rems-project", "repo": "sail", "sha": "853740ebd169dc81065c8cd076c335a7dea7fdc7", "save_path": "github-repos/isabelle/rems-project-sail", "path": "github-repos/isabelle/rems-project-sail/sail-853740ebd169dc81065c8cd076c335a7dea7fdc7/snapshots/isabelle/lib/lem/Lem_list.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.554470450236115, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.2966962666412349}}
{"text": "(*  Title:      HOL/Auth/n_mutualEx_lemma_inv__4_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n \n\ntheory n_mutualEx_lemma_inv__4_on_rules imports n_mutualEx_lemma_on_inv__4\nbegin\nsection{*All lemmas on causal relation between inv__4*}\nlemma lemma_inv__4_on_rules:\n  assumes b1: \"r \\<in> rules N\" and b2: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__4  p__Inv4)\"\n  shows \"invHoldForRule Interp s f r (invariants N)\"\n  proof -\n  have c1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n  apply (cut_tac b1, auto) done\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\"\n      have \"invHoldForRule Interp s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_TryVsinv__4) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\"\n      have \"invHoldForRule Interp s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_CritVsinv__4) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\"\n      have \"invHoldForRule Interp s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_ExitVsinv__4) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n      have \"invHoldForRule Interp s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_IdleVsinv__4) done\n    }\n\n  ultimately show \"invHoldForRule Interp s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "lyj238Gmail", "repo": "gsteProof", "sha": "3070d08e1f31a93be6fde85ab6b65d489c05f99e", "save_path": "github-repos/isabelle/lyj238Gmail-gsteProof", "path": "github-repos/isabelle/lyj238Gmail-gsteProof/gsteProof-3070d08e1f31a93be6fde85ab6b65d489c05f99e/mutualEx/n_mutualEx_lemma_inv__4_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.665410572017153, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.2964600627612183}}
{"text": "(* Title: Generative_Probabilistic_Value.thy\n  Author: Andreas Lochbihler, ETH Zurich *)\n\ntheory Generative_Probabilistic_Value imports\n  Resumption\n  Generat\n  \"HOL-Types_To_Sets.Types_To_Sets\"\nbegin\n\nhide_const (open) Done\n\nsubsection \\<open>Type definition\\<close>\n\ncontext notes [[bnf_internals]] begin\n\ncodatatype (results'_gpv: 'a, outs'_gpv: 'out, 'in) gpv\n  = GPV (the_gpv: \"('a, 'out, 'in \\<Rightarrow> ('a, 'out, 'in) gpv) generat spmf\")\n\nend\n\ndeclare gpv.rel_eq [relator_eq]\n\ntext \\<open>Reactive values are like generative, except that they take an input first.\\<close>\n\ntype_synonym ('a, 'out, 'in) rpv = \"'in \\<Rightarrow> ('a, 'out, 'in) gpv\"\nprint_translation \\<comment> \\<open>pretty printing for @{typ \"('a, 'out, 'in) rpv\"}\\<close> \\<open>\n  let\n    fun tr' [in1, Const (@{type_syntax gpv}, _) $ a $ out $ in2] =\n      if in1 = in2 then Syntax.const @{type_syntax rpv} $ a $ out $ in1\n      else raise Match;\n  in [(@{type_syntax \"fun\"}, K tr')]\n  end\n\\<close>\ntyp \"('a, 'out, 'in) rpv\"\ntext \\<open>\n  Effectively, @{typ \"('a, 'out, 'in) gpv\"} and @{typ \"('a, 'out, 'in) rpv\"} are mutually recursive.\n\\<close>\n\nlemma eq_GPV_iff: \"f = GPV g \\<longleftrightarrow> the_gpv f = g\"\nby(cases f) auto\n\ndeclare gpv.set[simp del]\n\ndeclare gpv.set_map[simp]\n\nlemma rel_gpv_def':\n  \"rel_gpv A B gpv gpv' \\<longleftrightarrow>\n  (\\<exists>gpv''. (\\<forall>(x, y) \\<in> results'_gpv gpv''. A x y) \\<and> (\\<forall>(x, y) \\<in> outs'_gpv gpv''. B x y) \\<and>\n           map_gpv fst fst gpv'' = gpv \\<and> map_gpv snd snd gpv'' = gpv')\"\nunfolding rel_gpv_def by(auto simp add: BNF_Def.Grp_def)\n\ndefinition results'_rpv :: \"('a, 'out, 'in) rpv \\<Rightarrow> 'a set\"\nwhere \"results'_rpv rpv = range rpv \\<bind> results'_gpv\"\n\ndefinition outs'_rpv :: \"('a, 'out, 'in) rpv \\<Rightarrow> 'out set\"\nwhere \"outs'_rpv rpv = range rpv \\<bind> outs'_gpv\"\n\nabbreviation rel_rpv\n  :: \"('a \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow> ('out \\<Rightarrow> 'out' \\<Rightarrow> bool)\n  \\<Rightarrow> ('in \\<Rightarrow> ('a, 'out, 'in) gpv) \\<Rightarrow> ('in \\<Rightarrow> ('b, 'out', 'in) gpv) \\<Rightarrow> bool\"\nwhere \"rel_rpv A B \\<equiv> rel_fun (=) (rel_gpv A B)\"\n\nlemma in_results'_rpv [iff]: \"x \\<in> results'_rpv rpv \\<longleftrightarrow> (\\<exists>input. x \\<in> results'_gpv (rpv input))\"\nby(simp add: results'_rpv_def)\n\nlemma in_outs_rpv [iff]: \"out \\<in> outs'_rpv rpv \\<longleftrightarrow> (\\<exists>input. out \\<in> outs'_gpv (rpv input))\"\nby(simp add: outs'_rpv_def)\n\nlemma results'_GPV [simp]:\n  \"results'_gpv (GPV r) =\n   (set_spmf r \\<bind> generat_pures) \\<union> \n   ((set_spmf r \\<bind> generat_conts) \\<bind> results'_rpv)\"\nby(auto simp add: gpv.set bind_UNION set_spmf_def)\n\nlemma outs'_GPV [simp]:\n  \"outs'_gpv (GPV r) =\n   (set_spmf r \\<bind> generat_outs) \\<union> \n   ((set_spmf r \\<bind> generat_conts) \\<bind> outs'_rpv)\"\nby(auto simp add: gpv.set bind_UNION set_spmf_def)\n\nlemma outs'_gpv_unfold:\n  \"outs'_gpv r =\n   (set_spmf (the_gpv r) \\<bind> generat_outs) \\<union> \n   ((set_spmf (the_gpv r) \\<bind> generat_conts) \\<bind> outs'_rpv)\"\nby(cases r) simp\n\nlemma outs'_gpv_induct [consumes 1, case_names Out Cont, induct set: outs'_gpv]:\n  assumes x: \"x \\<in> outs'_gpv gpv\"\n  and Out: \"\\<And>generat gpv. \\<lbrakk> generat \\<in> set_spmf (the_gpv gpv); x \\<in> generat_outs generat \\<rbrakk> \\<Longrightarrow> P gpv\"\n  and Cont: \"\\<And>generat gpv c input.\n    \\<lbrakk> generat \\<in> set_spmf (the_gpv gpv); c \\<in> generat_conts generat; x \\<in> outs'_gpv (c input); P (c input) \\<rbrakk> \\<Longrightarrow> P gpv\"\n  shows \"P gpv\"\nusing x\napply(induction y\\<equiv>\"x\" gpv)\n apply(rule Out, simp add: in_set_spmf, simp)\napply(erule imageE, rule Cont, simp add: in_set_spmf, simp, simp, simp)\n.\n\nlemma outs'_gpv_cases [consumes 1, case_names Out Cont, cases set: outs'_gpv]:\n  assumes \"x \\<in> outs'_gpv gpv\"\n  obtains (Out) generat where \"generat \\<in> set_spmf (the_gpv gpv)\" \"x \\<in> generat_outs generat\"\n    | (Cont) generat c input where \"generat \\<in> set_spmf (the_gpv gpv)\" \"c \\<in> generat_conts generat\" \"x \\<in> outs'_gpv (c input)\"\nusing assms by cases(auto simp add: in_set_spmf)\n\nlemma outs'_gpvI [intro?]:\n  shows outs'_gpv_Out: \"\\<lbrakk> generat \\<in> set_spmf (the_gpv gpv); x \\<in> generat_outs generat \\<rbrakk> \\<Longrightarrow> x \\<in> outs'_gpv gpv\"\n  and outs'_gpv_Cont: \"\\<lbrakk> generat \\<in> set_spmf (the_gpv gpv); c \\<in> generat_conts generat; x \\<in> outs'_gpv (c input) \\<rbrakk> \\<Longrightarrow> x \\<in> outs'_gpv gpv\"\nby(auto intro: gpv.set_sel simp add: in_set_spmf)\n\nlemma results'_gpv_induct [consumes 1, case_names Pure Cont, induct set: results'_gpv]:\n  assumes x: \"x \\<in> results'_gpv gpv\"\n  and Pure: \"\\<And>generat gpv. \\<lbrakk> generat \\<in> set_spmf (the_gpv gpv); x \\<in> generat_pures generat \\<rbrakk> \\<Longrightarrow> P gpv\"\n  and Cont: \"\\<And>generat gpv c input.\n    \\<lbrakk> generat \\<in> set_spmf (the_gpv gpv); c \\<in> generat_conts generat; x \\<in> results'_gpv (c input); P (c input) \\<rbrakk> \\<Longrightarrow> P gpv\"\n  shows \"P gpv\"\nusing x\napply(induction y\\<equiv>\"x\" gpv)\n apply(rule Pure; simp add: in_set_spmf)\napply(erule imageE, rule Cont, simp add: in_set_spmf, simp, simp, simp)\n.\n\nlemma results'_gpv_cases [consumes 1, case_names Pure Cont, cases set: results'_gpv]:\n  assumes \"x \\<in> results'_gpv gpv\"\n  obtains (Pure) generat where \"generat \\<in> set_spmf (the_gpv gpv)\" \"x \\<in> generat_pures generat\"\n    | (Cont) generat c input where \"generat \\<in> set_spmf (the_gpv gpv)\" \"c \\<in> generat_conts generat\" \"x \\<in> results'_gpv (c input)\"\nusing assms by cases(auto simp add: in_set_spmf)\n\nlemma results'_gpvI [intro?]:\n  shows results'_gpv_Pure: \"\\<lbrakk> generat \\<in> set_spmf (the_gpv gpv); x \\<in> generat_pures generat \\<rbrakk> \\<Longrightarrow> x \\<in> results'_gpv gpv\"\n  and results'_gpv_Cont: \"\\<lbrakk> generat \\<in> set_spmf (the_gpv gpv); c \\<in> generat_conts generat; x \\<in> results'_gpv (c input) \\<rbrakk> \\<Longrightarrow> x \\<in> results'_gpv gpv\"\nby(auto intro: gpv.set_sel simp add: in_set_spmf)\n\nlemma left_unique_rel_gpv [transfer_rule]:\n  \"\\<lbrakk> left_unique A; left_unique B \\<rbrakk> \\<Longrightarrow> left_unique (rel_gpv A B)\"\nunfolding left_unique_alt_def gpv.rel_conversep[symmetric] gpv.rel_compp[symmetric]\nby(subst gpv.rel_eq[symmetric])(rule gpv.rel_mono)\n\nlemma right_unique_rel_gpv [transfer_rule]:\n  \"\\<lbrakk> right_unique A; right_unique B \\<rbrakk> \\<Longrightarrow> right_unique (rel_gpv A B)\"\nunfolding right_unique_alt_def gpv.rel_conversep[symmetric] gpv.rel_compp[symmetric]\nby(subst gpv.rel_eq[symmetric])(rule gpv.rel_mono)\n\nlemma bi_unique_rel_gpv [transfer_rule]:\n  \"\\<lbrakk> bi_unique A; bi_unique B \\<rbrakk> \\<Longrightarrow> bi_unique (rel_gpv A B)\"\nunfolding bi_unique_alt_def by(simp add: left_unique_rel_gpv right_unique_rel_gpv)\n\nlemma left_total_rel_gpv [transfer_rule]:\n  \"\\<lbrakk> left_total A; left_total B \\<rbrakk> \\<Longrightarrow> left_total (rel_gpv A B)\"\nunfolding left_total_alt_def gpv.rel_conversep[symmetric] gpv.rel_compp[symmetric]\nby(subst gpv.rel_eq[symmetric])(rule gpv.rel_mono)\n\nlemma right_total_rel_gpv [transfer_rule]:\n  \"\\<lbrakk> right_total A; right_total B \\<rbrakk> \\<Longrightarrow> right_total (rel_gpv A B)\"\nunfolding right_total_alt_def gpv.rel_conversep[symmetric] gpv.rel_compp[symmetric]\nby(subst gpv.rel_eq[symmetric])(rule gpv.rel_mono)\n\nlemma bi_total_rel_gpv [transfer_rule]: \"\\<lbrakk> bi_total A; bi_total B \\<rbrakk> \\<Longrightarrow> bi_total (rel_gpv A B)\"\nunfolding bi_total_alt_def by(simp add: left_total_rel_gpv right_total_rel_gpv)\n\ndeclare gpv.map_transfer[transfer_rule]\n\nlemma if_distrib_map_gpv [if_distribs]:\n  \"map_gpv f g (if b then gpv else gpv') = (if b then map_gpv f g gpv else map_gpv f g gpv')\"\nby simp\n\nlemma gpv_pred_mono_strong:\n  \"\\<lbrakk> pred_gpv P Q x; \\<And>a. \\<lbrakk> a \\<in> results'_gpv x; P a \\<rbrakk> \\<Longrightarrow> P' a; \\<And>b. \\<lbrakk> b \\<in> outs'_gpv x; Q b \\<rbrakk> \\<Longrightarrow> Q' b \\<rbrakk> \\<Longrightarrow> pred_gpv P' Q' x\"\nby(simp add: pred_gpv_def)\n\nlemma pred_gpv_top [simp]:\n  \"pred_gpv (\\<lambda>_. True) (\\<lambda>_. True) = (\\<lambda>_. True)\"\nby(simp add: pred_gpv_def)\n\nlemma pred_gpv_conj [simp]:\n  shows pred_gpv_conj1: \"\\<And>P Q R. pred_gpv (\\<lambda>x. P x \\<and> Q x) R = (\\<lambda>x. pred_gpv P R x \\<and> pred_gpv Q R x)\"\n  and pred_gpv_conj2: \"\\<And>P Q R. pred_gpv P (\\<lambda>x. Q x \\<and> R x) = (\\<lambda>x. pred_gpv P Q x \\<and> pred_gpv P R x)\"\nby(auto simp add: pred_gpv_def)\n\nlemma rel_gpv_restrict_relp1I [intro?]:\n  \"\\<lbrakk> rel_gpv R R' x y; pred_gpv P P' x; pred_gpv Q Q' y \\<rbrakk> \\<Longrightarrow> rel_gpv (R \\<upharpoonleft> P \\<otimes> Q) (R' \\<upharpoonleft> P' \\<otimes> Q') x y\"\nby(erule gpv.rel_mono_strong)(simp_all add: pred_gpv_def)\n\nlemma rel_gpv_restrict_relpE [elim?]:\n  assumes \"rel_gpv (R \\<upharpoonleft> P \\<otimes> Q) (R' \\<upharpoonleft> P' \\<otimes> Q') x y\"\n  obtains \"rel_gpv R R' x y\" \"pred_gpv P P' x\" \"pred_gpv Q Q' y\"\nproof\n  show \"rel_gpv R R' x y\" using assms by(auto elim!: gpv.rel_mono_strong)\n  have \"pred_gpv (Domainp (R \\<upharpoonleft> P \\<otimes> Q)) (Domainp (R' \\<upharpoonleft> P' \\<otimes> Q')) x\" using assms by(fold gpv.Domainp_rel) blast\n  then show \"pred_gpv P P' x\" by(rule gpv_pred_mono_strong)(blast dest!: restrict_relp_DomainpD)+\n  have \"pred_gpv (Domainp (R \\<upharpoonleft> P \\<otimes> Q)\\<inverse>\\<inverse>) (Domainp (R' \\<upharpoonleft> P' \\<otimes> Q')\\<inverse>\\<inverse>) y\" using assms\n    by(fold gpv.Domainp_rel)(auto simp only: gpv.rel_conversep Domainp_conversep)\n  then show \"pred_gpv Q Q' y\" by(rule gpv_pred_mono_strong)(auto dest!: restrict_relp_DomainpD)\nqed\n\nlemma gpv_pred_map [simp]: \"pred_gpv P Q (map_gpv f g gpv) = pred_gpv (P \\<circ> f) (Q \\<circ> g) gpv\"\nby(simp add: pred_gpv_def)\n\nsubsection \\<open>Generalised mapper and relator\\<close>\n\ncontext includes lifting_syntax begin\n\nprimcorec map_gpv' :: \"('a \\<Rightarrow> 'b) \\<Rightarrow> ('out \\<Rightarrow> 'out') \\<Rightarrow> ('ret' \\<Rightarrow> 'ret) \\<Rightarrow> ('a, 'out, 'ret) gpv \\<Rightarrow> ('b, 'out', 'ret') gpv\"\nwhere\n  \"map_gpv' f g h gpv = \n   GPV (map_spmf (map_generat f g ((\\<circ>) (map_gpv' f g h))) (map_spmf (map_generat id id (map_fun h id)) (the_gpv gpv)))\"\n\ndeclare map_gpv'.sel [simp del]\n\nlemma map_gpv'_sel [simp]:\n  \"the_gpv (map_gpv' f g h gpv) = map_spmf (map_generat f g (h ---> map_gpv' f g h)) (the_gpv gpv)\"\nby(simp add: map_gpv'.sel spmf.map_comp o_def generat.map_comp map_fun_def[abs_def])\n\nlemma map_gpv'_GPV [simp]:\n  \"map_gpv' f g h (GPV p) = GPV (map_spmf (map_generat f g (h ---> map_gpv' f g h)) p)\"\nby(rule gpv.expand) simp\n\nlemma map_gpv'_id: \"map_gpv' id id id = id\"\napply(rule ext)\napply(coinduction)\napply(auto simp add: spmf_rel_map generat.rel_map rel_fun_def intro!: rel_spmf_reflI generat.rel_refl)\ndone\n\nlemma map_gpv'_comp: \"map_gpv' f g h (map_gpv' f' g' h' gpv) = map_gpv' (f \\<circ> f') (g \\<circ> g') (h' \\<circ> h) gpv\"\nby(coinduction arbitrary: gpv)(auto simp add: spmf.map_comp spmf_rel_map generat.rel_map rel_fun_def intro!: rel_spmf_reflI generat.rel_refl)\n\nfunctor gpv: map_gpv' by(simp_all add: map_gpv'_comp map_gpv'_id o_def) \n\nlemma map_gpv_conv_map_gpv': \"map_gpv f g = map_gpv' f g id\"\napply(rule ext)\napply(coinduction)\napply(auto simp add: gpv.map_sel spmf_rel_map generat.rel_map rel_fun_def intro!: generat.rel_refl_strong rel_spmf_reflI)\ndone\n\ncoinductive rel_gpv'' :: \"('a \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow> ('out \\<Rightarrow> 'out' \\<Rightarrow> bool) \\<Rightarrow> ('ret \\<Rightarrow> 'ret' \\<Rightarrow> bool) \\<Rightarrow> ('a, 'out, 'ret) gpv \\<Rightarrow> ('b, 'out', 'ret') gpv \\<Rightarrow> bool\"\n  for A C R\nwhere\n  \"rel_spmf (rel_generat A C (R ===> rel_gpv'' A C R)) (the_gpv gpv) (the_gpv gpv')\n  \\<Longrightarrow> rel_gpv'' A C R gpv gpv'\"\n\nlemma rel_gpv''_coinduct [consumes 1, case_names rel_gpv'', coinduct pred: rel_gpv'']:\n  \"\\<lbrakk>X gpv gpv';\n    \\<And>gpv gpv'. X gpv gpv'\n     \\<Longrightarrow> rel_spmf (rel_generat A C (R ===> (\\<lambda>gpv gpv'. X gpv gpv' \\<or> rel_gpv'' A C R gpv gpv')))\n           (the_gpv gpv) (the_gpv gpv') \\<rbrakk>\n   \\<Longrightarrow> rel_gpv'' A C R gpv gpv'\"\nby(erule rel_gpv''.coinduct) blast\n\nlemma rel_gpv''D:\n  \"rel_gpv'' A C R gpv gpv' \n  \\<Longrightarrow> rel_spmf (rel_generat A C (R ===> rel_gpv'' A C R)) (the_gpv gpv) (the_gpv gpv')\"\nby(simp add: rel_gpv''.simps)\n\nlemma rel_gpv''_GPV [simp]:\n  \"rel_gpv'' A C R (GPV p) (GPV q) \\<longleftrightarrow>\n   rel_spmf (rel_generat A C (R ===> rel_gpv'' A C R)) p q\"\nby(simp add: rel_gpv''.simps)\n\nlemma rel_gpv_conv_rel_gpv'': \"rel_gpv A C = rel_gpv'' A C (=)\"\nproof(rule ext iffI)+\n  show \"rel_gpv A C gpv gpv'\" if \"rel_gpv'' A C (=) gpv gpv'\" for gpv :: \"('a, 'b, 'c) gpv\" and gpv' :: \"('d, 'e, 'c) gpv\"\n    using that by(coinduct)(blast dest: rel_gpv''D)\n  show \"rel_gpv'' A C (=) gpv gpv'\" if \"rel_gpv A C gpv gpv'\" for gpv :: \"('a, 'b, 'c) gpv\" and gpv' :: \"('d, 'e, 'c) gpv\"\n    using that by(coinduct)(auto elim!: gpv.rel_cases rel_spmf_mono generat.rel_mono_strong rel_fun_mono)\nqed\n\nlemma rel_gpv''_eq (* [relator_eq] do not use this attribute unless all transfer rules for gpv have been changed to rel_gvp'' *):\n  \"rel_gpv'' (=) (=) (=) = (=)\"\nby(simp add: rel_gpv_conv_rel_gpv''[symmetric] gpv.rel_eq)\n\nlemma rel_gpv''_mono:\n  assumes \"A \\<le> A'\" \"C \\<le> C'\" \"R' \\<le> R\"\n  shows \"rel_gpv'' A C R \\<le> rel_gpv'' A' C' R'\"\nproof\n  show \"rel_gpv'' A' C' R' gpv gpv'\" if \"rel_gpv'' A C R gpv gpv'\" for gpv gpv' using that\n    by(coinduct)(auto dest: rel_gpv''D elim!: rel_spmf_mono generat.rel_mono_strong rel_fun_mono intro: assms[THEN predicate2D])\nqed\n\nlemma rel_gpv''_conversep: \"rel_gpv'' A\\<inverse>\\<inverse> C\\<inverse>\\<inverse> R\\<inverse>\\<inverse> = (rel_gpv'' A C R)\\<inverse>\\<inverse>\"\nproof(intro ext iffI; simp)\n  show \"rel_gpv'' A C R gpv gpv'\" if \"rel_gpv'' A\\<inverse>\\<inverse> C\\<inverse>\\<inverse> R\\<inverse>\\<inverse> gpv' gpv\"\n    for A :: \"'a1 \\<Rightarrow> 'a2 \\<Rightarrow> bool\" and C :: \"'c1 \\<Rightarrow> 'c2 \\<Rightarrow> bool\" and R :: \"'r1 \\<Rightarrow> 'r2 \\<Rightarrow> bool\" and gpv gpv'\n    using that apply(coinduct)\n    apply(drule rel_gpv''D)\n    apply(rewrite in \\<hole> conversep_iff[symmetric])\n    apply(subst spmf_rel_conversep[symmetric])\n    apply(erule rel_spmf_mono)\n    apply(subst generat.rel_conversep[symmetric])\n    apply(erule generat.rel_mono_strong)\n    apply(auto simp add: rel_fun_def conversep_iff[abs_def])\n    done\n  from this[of \"A\\<inverse>\\<inverse>\" \"C\\<inverse>\\<inverse>\" \"R\\<inverse>\\<inverse>\"]\n  show \"rel_gpv'' A\\<inverse>\\<inverse> C\\<inverse>\\<inverse> R\\<inverse>\\<inverse> gpv' gpv\" if \"rel_gpv'' A C R gpv gpv'\" for gpv gpv' using that by simp\nqed\n\n\nlemma rel_gpv''_pos_distr:\n  \"rel_gpv'' A C R OO rel_gpv'' A' C' R' \\<le> rel_gpv'' (A OO A') (C OO C') (R OO R')\"\nproof(rule predicate2I; erule relcomppE)\n  show \"rel_gpv'' (A OO A') (C OO C') (R OO R') gpv gpv''\"\n    if \"rel_gpv'' A C R gpv gpv'\" \"rel_gpv'' A' C' R' gpv' gpv''\"\n    for gpv gpv' gpv'' using that\n    apply(coinduction arbitrary: gpv gpv' gpv'')\n    apply(drule rel_gpv''D)+\n    apply(drule (1) rel_spmf_pos_distr[THEN predicate2D, OF relcomppI])\n    apply(erule spmf_rel_mono_strong)\n    apply(subst (asm) generat.rel_compp[symmetric])\n    apply(erule generat.rel_mono_strong, assumption, assumption)\n    apply(drule pos_fun_distr[THEN predicate2D])\n    apply(auto simp add: rel_fun_def)\n    done\nqed\n\nlemma left_unique_rel_gpv'':\n  \"\\<lbrakk> left_unique A; left_unique C; left_total R \\<rbrakk> \\<Longrightarrow> left_unique (rel_gpv'' A C R)\"\nunfolding left_unique_alt_def left_total_alt_def rel_gpv''_conversep[symmetric]\napply(subst rel_gpv''_eq[symmetric])\napply(rule order_trans[OF rel_gpv''_pos_distr])\napply(erule (2) rel_gpv''_mono)\ndone\n\nlemma right_unique_rel_gpv'':\n  \"\\<lbrakk> right_unique A; right_unique C; right_total R \\<rbrakk> \\<Longrightarrow> right_unique (rel_gpv'' A C R)\"\nunfolding right_unique_alt_def right_total_alt_def rel_gpv''_conversep[symmetric]\napply(subst rel_gpv''_eq[symmetric])\napply(rule order_trans[OF rel_gpv''_pos_distr])\napply(erule (2) rel_gpv''_mono)\ndone\n\nlemma bi_unique_rel_gpv'' [transfer_rule]:\n  \"\\<lbrakk> bi_unique A; bi_unique C; bi_total R \\<rbrakk> \\<Longrightarrow> bi_unique (rel_gpv'' A C R)\"\nunfolding bi_unique_alt_def bi_total_alt_def by(blast intro: left_unique_rel_gpv'' right_unique_rel_gpv'')\n\nlemma rel_gpv''_neg_distr:\n  assumes R: \"left_unique R\" \"right_total R\"\n  and R': \"right_unique R'\" \"left_total R'\"\n  shows \"rel_gpv'' (A OO A') (C OO C') (R OO R') \\<le> rel_gpv'' A C R OO rel_gpv'' A' C' R'\"\nproof(rule predicate2I relcomppI)+\n  fix gpv gpv''\n  assume *: \"rel_gpv'' (A OO A') (C OO C') (R OO R') gpv gpv''\"\n  let ?P_spmf = \"\\<lambda>gpv gpv'' pq. \n    (\\<forall>(generat, generat'') \\<in> set_spmf pq. rel_generat (A OO A') (C OO C') (R OO R' ===> rel_gpv'' (A OO A') (C OO C') (R OO R')) generat generat'') \\<and>\n    map_spmf fst pq = the_gpv gpv \\<and>\n    map_spmf snd pq = the_gpv gpv''\"\n  define pq where \"pq gpv gpv'' = Eps (?P_spmf gpv gpv'')\" for gpv gpv''\n  let ?P_generat = \"\\<lambda>generat generat'' gg'. \n    (\\<forall>(a, a'') \\<in> generat_pures gg'. (A OO A') a a'') \\<and> (\\<forall>(out, out'') \\<in> generat_outs gg'. (C OO C') out out'') \\<and> (\\<forall>(c, c'')\\<in>generat_conts gg'. (R OO R' ===> rel_gpv'' (A OO A') (C OO C') (R OO R')) c c'') \\<and>\n    map_generat fst fst fst gg' = generat \\<and> \n    map_generat snd snd snd gg' = generat''\"\n  define gg' where \"gg' generat generat'' = Eps (?P_generat generat generat'')\" for generat generat''\n  define middle where \"middle \\<equiv> corec_gpv (\\<lambda>(gpv, gpv''). \n     map_spmf (\\<lambda>(generat, generat''). \n       map_generat (\\<lambda>(a, a''). SOME a'. A a a' \\<and> A' a' a'') (\\<lambda>(out, out''). SOME out'. C out out' \\<and> C' out' out'')\n            (\\<lambda>(rpv, rpv'') input. Inr (rpv (THE x. R x input), rpv'' (THE z. R' input z))) (gg' generat generat'')\n     ) (pq gpv gpv''))\"\n  have sel_middle:\n    \"the_gpv (middle (gpv, gpv'')) = map_spmf (\\<lambda>(generat, generat''). map_generat\n           (\\<lambda>(a, a''). SOME a'. A a a' \\<and> A' a' a'')\n           (\\<lambda>(out, out''). SOME out'. C out out' \\<and> C' out' out'')\n           (\\<lambda>(rpv, rpv'') xa. middle (rpv (THE x. R x xa), rpv'' (THE x''. R' xa x'')))\n           (gg' generat generat''))\n       (pq gpv gpv'')\"\n    for gpv gpv'' unfolding middle_def by(simp add: spmf.map_comp split_def o_def generat.map_comp)\n  from * show \"rel_gpv'' A C R gpv (middle (gpv, gpv''))\"\n  proof(coinduction arbitrary: gpv gpv'')\n    case (rel_gpv'' gpv gpv'')\n    let ?X = \"\\<lambda>gpv gpv'. (\\<exists>gpv''. gpv' = middle (gpv, gpv'') \\<and> rel_gpv'' (A OO A') (C OO C') (R OO R') gpv gpv'') \\<or> rel_gpv'' A C R gpv gpv'\"\n    from rel_gpv''D[OF rel_gpv''] have \"Ex (?P_spmf gpv gpv'')\" by(auto simp add: rel_spmf_simps)\n    hence pq: \"?P_spmf gpv gpv'' (pq gpv gpv'')\" unfolding pq_def by(rule someI_ex)\n    hence \"rel_spmf (\\<lambda>generat (generat', generat''). generat = generat')\\<inverse>\\<inverse> (pq gpv gpv'') (the_gpv gpv)\"\n      by(fold spmf_rel_eq)(auto simp add: spmf_rel_map split_def elim: rel_spmf_mono)\n    then show ?case\n    proof(clarsimp simp add: sel_middle spmf_rel_conversep spmf_rel_map generat.rel_map prod.case_distrib[where h=\"A _\"] prod.case_distrib[where h=\"C _\"] prod.case_distrib[where h=\"rel_fun _ _ _\"] elim!: rel_spmf_mono_strong)\n      fix generat generat''\n      assume \"(generat, generat'') \\<in> set_spmf (pq gpv gpv'')\"\n      with pq have \"rel_generat (A OO A') (C OO C') (R OO R' ===> rel_gpv'' (A OO A') (C OO C') (R OO R')) generat generat''\"\n        by blast\n      hence \"Ex (?P_generat generat generat'')\" by(auto simp add: Grp_def generat.rel_compp_Grp)\n      hence gg': \"?P_generat generat generat'' (gg' generat generat'')\" unfolding gg'_def by(rule someI_ex)\n      hence \"rel_generat (\\<lambda>a aa''. a = fst aa'')\\<inverse>\\<inverse> (\\<lambda>out outout''. out = fst outout'')\\<inverse>\\<inverse> (\\<lambda>rpv rpvrpv''. rpv = fst rpvrpv'')\\<inverse>\\<inverse> (gg' generat generat'') generat\"\n        by(fold generat.rel_eq)(auto simp add: generat.rel_map elim!: generat.rel_mono_strong)\n      then show \"rel_generat (\\<lambda>a (aa, a''). A a (SOME a'. A aa a' \\<and> A' a' a''))\n                 (\\<lambda>out (outt, out''). C out (SOME out'. C outt out' \\<and> C' out' out''))\n                 (\\<lambda>rpv (rpvv, rpv''). (R ===> ?X) rpv (\\<lambda>y. middle (rpvv (THE x. R x y), rpv'' (THE z. R' y z))))\n                 generat (gg' generat generat'')\"\n        unfolding generat.rel_conversep conversep_iff apply(rule generat.rel_mono_strong)\n      proof(safe, simp_all)\n        fix a a''\n        assume \"(a, a'') \\<in> generat_pures (gg' generat generat'')\"\n        with gg' have \"\\<exists>a'. A a a' \\<and> A' a' a''\" by blast\n        from someI_ex[OF this] show \"A a (SOME a'. A a a' \\<and> A' a' a'')\" ..\n      next\n        fix out out''\n        assume \"(out, out'') \\<in> generat_outs (gg' generat generat'')\"\n        with gg' have \"\\<exists>out'. C out out' \\<and> C' out' out''\" by blast\n        from someI_ex[OF this] show \"C out (SOME out'. C out out' \\<and> C' out' out'')\" ..\n      next\n        fix rpv rpv''\n        assume \"(rpv, rpv'') \\<in> generat_conts (gg' generat generat'')\"\n        with gg' have *: \"(R OO R' ===> rel_gpv'' (A OO A') (C OO C') (R OO R')) rpv rpv''\" by blast\n        show \"(R ===> ?X) rpv (\\<lambda>y. middle (rpv (THE x. R x y), rpv'' (THE z. R' y z)))\"\n        proof(rule rel_funI)\n          fix x y\n          assume xy: \"R x y\"\n          from R' obtain z where yz: \"R' y z\" by(blast elim: left_totalE)\n          with xy have \"(R OO R') x z\" by blast\n          with * have \"rel_gpv'' (A OO A') (C OO C') (R OO R') (rpv x) (rpv'' z)\" by(rule rel_funD)\n          moreover have \"(THE x. R x y) = x\" using xy\n            by(rule the_equality)(blast dest: left_uniqueD[OF R(1) xy])\n          moreover have \"(THE z. R' y z) = z\" using yz\n            by(rule the_equality)(blast dest: right_uniqueD[OF R'(1) yz])\n          ultimately show \"?X (rpv x) (middle (rpv (THE x. R x y), rpv'' (THE z. R' y z)))\" by blast\n        qed\n      qed\n    qed\n  qed\n  from * show \"rel_gpv'' A' C' R' (middle (gpv, gpv'')) gpv''\"\n  proof(coinduction arbitrary: gpv gpv'')\n    case (rel_gpv'' gpv gpv'')\n    let ?X = \"\\<lambda>gpv' gpv''. (\\<exists>gpv. gpv' = middle (gpv, gpv'') \\<and> rel_gpv'' (A OO A') (C OO C') (R OO R') gpv gpv'') \\<or> rel_gpv'' A' C' R' gpv' gpv''\"\n    from rel_gpv''D[OF rel_gpv''] have \"Ex (?P_spmf gpv gpv'')\" by(auto simp add: rel_spmf_simps)\n    hence pq: \"?P_spmf gpv gpv'' (pq gpv gpv'')\" unfolding pq_def by(rule someI_ex)\n    hence \"rel_spmf (\\<lambda>(generat', generat'') generat. generat = generat'') (pq gpv gpv'') (the_gpv gpv'')\"\n      by(fold spmf_rel_eq)(auto simp add: spmf_rel_map split_def elim: rel_spmf_mono)\n    then show ?case\n    proof(clarsimp simp add: sel_middle spmf_rel_conversep spmf_rel_map generat.rel_map prod.case_distrib[where h=\"A'\"] prod.case_distrib[where h=\"C'\"] prod.case_distrib[where h=\"rel_fun _ _\"] elim!: rel_spmf_mono_strong)\n      fix generat generat''\n      assume \"(generat, generat'') \\<in> set_spmf (pq gpv gpv'')\"\n      with pq have \"rel_generat (A OO A') (C OO C') (R OO R' ===> rel_gpv'' (A OO A') (C OO C') (R OO R')) generat generat''\"\n        by blast\n      hence \"Ex (?P_generat generat generat'')\" by(auto simp add: Grp_def generat.rel_compp_Grp)\n      hence gg': \"?P_generat generat generat'' (gg' generat generat'')\" unfolding gg'_def by(rule someI_ex)\n      hence \"rel_generat (\\<lambda>aa'' a. a = snd aa'') (\\<lambda>outout'' out. out = snd outout'') (\\<lambda>rpvrpv'' rpv. rpv = snd rpvrpv'') (gg' generat generat'') generat''\"\n        by(fold generat.rel_eq)(auto simp add: generat.rel_map elim!: generat.rel_mono_strong)\n      then show \"rel_generat (\\<lambda>(a, aa'') a''. A' (SOME a'. A a a' \\<and> A' a' aa'') a'')\n                 (\\<lambda>(out, outt'') out''. C' (SOME out'. C out out' \\<and> C' out' outt'') out'')\n                 (\\<lambda>(rpv, rpvv'') rpv''. (R' ===> ?X) (\\<lambda>y. middle (rpv (THE x. R x y), rpvv'' (THE z. R' y z))) rpv'')\n                 (gg' generat generat'') generat''\"\n        apply(rule generat.rel_mono_strong)\n      proof(safe, simp_all)\n        fix a a''\n        assume \"(a, a'') \\<in> generat_pures (gg' generat generat'')\"\n        with gg' have \"\\<exists>a'. A a a' \\<and> A' a' a''\" by blast\n        from someI_ex[OF this] show \"A' (SOME a'. A a a' \\<and> A' a' a'') a''\" ..\n      next\n        fix out out''\n        assume \"(out, out'') \\<in> generat_outs (gg' generat generat'')\"\n        with gg' have \"\\<exists>out'. C out out' \\<and> C' out' out''\" by blast\n        from someI_ex[OF this] show \"C' (SOME out'. C out out' \\<and> C' out' out'') out''\" ..\n      next\n        fix rpv rpv''\n        assume \"(rpv, rpv'') \\<in> generat_conts (gg' generat generat'')\"\n        with gg' have *: \"(R OO R' ===> rel_gpv'' (A OO A') (C OO C') (R OO R')) rpv rpv''\" by blast\n        show \"(R' ===> ?X) (\\<lambda>y. middle (rpv (THE x. R x y), rpv'' (THE z. R' y z))) rpv''\"\n        proof(rule rel_funI)\n          fix y z\n          assume yz: \"R' y z\"\n          from R obtain x where xy: \"R x y\" by(blast elim: right_totalE)\n          with yz have \"(R OO R') x z\" by blast\n          with * have \"rel_gpv'' (A OO A') (C OO C') (R OO R') (rpv x) (rpv'' z)\" by(rule rel_funD)\n          moreover have \"(THE x. R x y) = x\" using xy\n            by(rule the_equality)(blast dest: left_uniqueD[OF R(1) xy])\n          moreover have \"(THE z. R' y z) = z\" using yz\n            by(rule the_equality)(blast dest: right_uniqueD[OF R'(1) yz])\n          ultimately show \"?X (middle (rpv (THE x. R x y), rpv'' (THE z. R' y z))) (rpv'' z)\" by blast\n        qed\n      qed\n    qed\n  qed\nqed\n\nlemma left_total_rel_gpv':\n  \"\\<lbrakk> left_total A; left_total C; left_unique R; right_total R \\<rbrakk> \\<Longrightarrow> left_total (rel_gpv'' A C R)\"\nunfolding left_unique_alt_def left_total_alt_def rel_gpv''_conversep[symmetric]\napply(subst rel_gpv''_eq[symmetric])\napply(rule order_trans[rotated])\napply(rule rel_gpv''_neg_distr; simp add: left_unique_alt_def)\napply(rule rel_gpv''_mono; assumption)\ndone\n\nlemma right_total_rel_gpv':\n  \"\\<lbrakk> right_total A; right_total C; right_unique R; left_total R \\<rbrakk> \\<Longrightarrow> right_total (rel_gpv'' A C R)\"\nunfolding right_unique_alt_def right_total_alt_def rel_gpv''_conversep[symmetric]\napply(subst rel_gpv''_eq[symmetric])\napply(rule order_trans[rotated])\napply(rule rel_gpv''_neg_distr; simp add: right_unique_alt_def)\napply(rule rel_gpv''_mono; assumption)\ndone\n\nlemma bi_total_rel_gpv' [transfer_rule]:\n  \"\\<lbrakk> bi_total A; bi_total C; bi_unique R; bi_total R \\<rbrakk> \\<Longrightarrow> bi_total (rel_gpv'' A C R)\"\nunfolding bi_total_alt_def bi_unique_alt_def by(blast intro: left_total_rel_gpv' right_total_rel_gpv')\n\nlemma rel_fun_conversep_grp_grp:\n  \"rel_fun (conversep (BNF_Def.Grp UNIV f)) (BNF_Def.Grp B g) = BNF_Def.Grp {x. (x \\<circ> f) ` UNIV \\<subseteq> B} (map_fun f g)\"\nunfolding rel_fun_def Grp_def simp_thms fun_eq_iff conversep_iff by auto\n\nlemma Quotient_gpv:\n  assumes Q1: \"Quotient R1 Abs1 Rep1 T1\"\n  and Q2: \"Quotient R2 Abs2 Rep2 T2\"\n  and Q3: \"Quotient R3 Abs3 Rep3 T3\"\n  shows \"Quotient (rel_gpv'' R1 R2 R3) (map_gpv' Abs1 Abs2 Rep3) (map_gpv' Rep1 Rep2 Abs3) (rel_gpv'' T1 T2 T3)\"\n  (is \"Quotient ?R ?abs ?rep ?T\")\nunfolding Quotient_alt_def2\nproof(intro conjI strip iffI; (elim conjE exE)?)\n  note [simp] = spmf_rel_map generat.rel_map\n    and [elim!] = rel_spmf_mono generat.rel_mono_strong\n    and [rule del] = rel_funI and [intro!] = rel_funI\n  have Abs1 [simp]: \"Abs1 x = y\" if \"T1 x y\" for x y using Q1 that by(simp add: Quotient_alt_def)\n  have Abs2 [simp]: \"Abs2 x = y\" if \"T2 x y\" for x y using Q2 that by(simp add: Quotient_alt_def)\n  have Abs3 [simp]: \"Abs3 x = y\" if \"T3 x y\" for x y using Q3 that by(simp add: Quotient_alt_def)\n  have Rep1: \"T1 (Rep1 x) x\" for x using Q1 by(simp add: Quotient_alt_def)\n  have Rep2: \"T2 (Rep2 x) x\" for x using Q2 by(simp add: Quotient_alt_def)\n  have Rep3: \"T3 (Rep3 x) x\" for x using Q3 by(simp add: Quotient_alt_def)\n  have T1: \"T1 x (Abs1 y)\" if \"R1 x y\" for x y using Q1 that by(simp add: Quotient_alt_def2)\n  have T2: \"T2 x (Abs2 y)\" if \"R2 x y\" for x y using Q2 that by(simp add: Quotient_alt_def2)\n  have T1': \"T1 x (Abs1 y)\" if \"R1 y x\" for x y using Q1 that by(simp add: Quotient_alt_def2)\n  have T2': \"T2 x (Abs2 y)\" if \"R2 y x\" for x y using Q2 that by(simp add: Quotient_alt_def2)\n  have R3: \"R3 x (Rep3 y)\" if \"T3 x y\" for x y using Q3 that by(simp add: Quotient_alt_def2 Abs3[OF Rep3])\n  have R3': \"R3 (Rep3 y) x\" if \"T3 x y\" for x y using Q3 that by(simp add: Quotient_alt_def2 Abs3[OF Rep3])\n  have r1: \"R1 = T1 OO T1\\<inverse>\\<inverse>\" using Q1 by(simp add: Quotient_alt_def4)\n  have r2: \"R2 = T2 OO T2\\<inverse>\\<inverse>\" using Q2 by(simp add: Quotient_alt_def4)\n  have r3: \"R3 = T3 OO T3\\<inverse>\\<inverse>\" using Q3 by(simp add: Quotient_alt_def4)\n  show abs: \"?abs gpv = gpv'\" if \"?T gpv gpv'\" for gpv gpv' using that\n    by(coinduction arbitrary: gpv gpv')(drule rel_gpv''D; auto 4 4 intro: Rep3 dest: rel_funD)\n  show \"?T (?rep gpv) gpv\" for gpv\n    by(coinduction arbitrary: gpv)(auto simp add: Rep1 Rep2 intro!: rel_spmf_reflI generat.rel_refl_strong)\n  show \"?T gpv (?abs gpv')\" if \"?R gpv gpv'\" for gpv gpv' using that\n    by(coinduction arbitrary: gpv gpv')(drule rel_gpv''D; auto 4 3 simp add: T1 T2 intro!: R3 dest: rel_funD)\n  show \"?T gpv (?abs gpv')\" if \"?R gpv' gpv\" for gpv gpv'\n  proof -\n    from that have \"rel_gpv'' R1\\<inverse>\\<inverse> R2\\<inverse>\\<inverse> R3\\<inverse>\\<inverse> gpv gpv'\" unfolding rel_gpv''_conversep by simp\n    then show ?thesis\n      by(coinduction arbitrary: gpv gpv')(drule rel_gpv''D; auto 4 3 simp add: T1' T2' intro!: R3' dest: rel_funD)\n  qed\n  show \"?R gpv gpv'\" if \"?T gpv (?abs gpv')\" \"?T gpv' (?abs gpv)\" for gpv gpv'\n  proof -\n    from that[THEN abs] have \"?abs gpv' = ?abs gpv\" by simp\n    with that have \"(?T OO ?T\\<inverse>\\<inverse>) gpv gpv'\" by auto\n    hence \"rel_gpv'' (T1 OO T1\\<inverse>\\<inverse>) (T2 OO T2\\<inverse>\\<inverse>) (T3 OO T3\\<inverse>\\<inverse>) gpv gpv'\"\n      unfolding rel_gpv''_conversep[symmetric]\n      by(rule rel_gpv''_pos_distr[THEN predicate2D])\n    thus ?thesis by(simp add: r1 r2 r3)\n  qed\nqed\n\nlemma rel_gpv''_Grp: (* does not hold! *)\n  \"rel_gpv'' (BNF_Def.Grp A f) (BNF_Def.Grp B g) (BNF_Def.Grp UNIV h)\\<inverse>\\<inverse> = \n   BNF_Def.Grp {x. results'_gpv x \\<subseteq> A \\<and> outs'_gpv x \\<subseteq> B} (map_gpv' f g h)\"\n   (is \"?lhs = ?rhs\")\nproof(intro ext GrpI iffI CollectI conjI subsetI)\n  fix gpv gpv'\n  assume *: \"?lhs gpv gpv'\"\n  then show \"map_gpv' f g h gpv = gpv'\"\n    apply(coinduction arbitrary: gpv gpv')\n    apply(drule rel_gpv''D)\n    apply(auto 4 5 simp add: spmf_rel_map generat.rel_map elim!: rel_spmf_mono generat.rel_mono_strong GrpE intro!: GrpI dest: rel_funD)\n    done\n  show \"x \\<in> A\" if \"x \\<in> results'_gpv gpv\" for x using that *\n  proof(induction arbitrary: gpv')\n    case (Pure generat gpv)\n    have \"pred_spmf (Domainp (rel_generat (BNF_Def.Grp A f) (BNF_Def.Grp B g) ((BNF_Def.Grp UNIV h)\\<inverse>\\<inverse> ===> rel_gpv'' (BNF_Def.Grp A f) (BNF_Def.Grp B g) (BNF_Def.Grp UNIV h)\\<inverse>\\<inverse>))) (the_gpv gpv)\"\n      using Pure.prems[THEN rel_gpv''D] unfolding spmf_Domainp_rel[symmetric] by(rule DomainPI)\n    with Pure.hyps show ?case by(simp add: generat.Domainp_rel pred_spmf_def pred_generat_def Domainp_Grp)\n  next\n    case (Cont generat gpv c input)\n    have \"pred_spmf (Domainp (rel_generat (BNF_Def.Grp A f) (BNF_Def.Grp B g) ((BNF_Def.Grp UNIV h)\\<inverse>\\<inverse> ===> rel_gpv'' (BNF_Def.Grp A f) (BNF_Def.Grp B g) (BNF_Def.Grp UNIV h)\\<inverse>\\<inverse>))) (the_gpv gpv)\"\n      using Cont.prems[THEN rel_gpv''D] unfolding spmf_Domainp_rel[symmetric] by(rule DomainPI)\n    with Cont.hyps show ?case apply(clarsimp simp add: generat.Domainp_rel pred_spmf_def pred_generat_def)\n      apply(drule (1) bspec)+\n      apply clarsimp\n      apply(drule rel_funD)\n      prefer 2\n      apply(erule Cont.IH)\n      apply(simp add: Grp_def)\n      oops\n\n\nlemma the_gpv_parametric':\n  \"(rel_gpv'' A C R ===> rel_spmf (rel_generat A C (R ===> rel_gpv'' A C R))) the_gpv the_gpv\"\nby(rule rel_funI)(auto elim: rel_gpv''.cases)\n\nlemma GPV_parametric':\n  \"(rel_spmf (rel_generat A C (R ===> rel_gpv'' A C R)) ===> rel_gpv'' A C R) GPV GPV\"\nby(rule rel_funI)(auto)\n\nlemma corec_gpv_parametric':\n  \"((S ===> rel_spmf (rel_generat A C (R ===> rel_sum (rel_gpv'' A C R) S))) ===> S ===> rel_gpv'' A C R)\n  corec_gpv corec_gpv\"\nproof(rule rel_funI)+\n  fix f g s1 s2\n  assume fg: \"(S ===> rel_spmf (rel_generat A C (R ===> rel_sum (rel_gpv'' A C R) S))) f g\"\n    and s: \"S s1 s2\"\n  from s show \"rel_gpv'' A C R (corec_gpv f s1) (corec_gpv g s2)\"\n    apply(coinduction arbitrary: s1 s2)\n    apply(drule fg[THEN rel_funD])\n    apply(simp add: spmf_rel_map)\n    apply(erule rel_spmf_mono)\n    apply(simp add: generat.rel_map)\n    apply(erule generat.rel_mono_strong; clarsimp simp add: o_def)\n    apply(rule rel_funI)\n    apply(drule (1) rel_funD)\n    apply(auto 4 3 elim!: rel_sum.cases)\n    done\nqed\n\nlemma map_gpv'_parametric [transfer_rule]:\n  \"((A ===> A') ===> (C ===> C') ===> (R' ===> R) ===> rel_gpv'' A C R ===> rel_gpv'' A' C' R') map_gpv' map_gpv'\"\n  unfolding map_gpv'_def\n  supply corec_gpv_parametric'[transfer_rule] the_gpv_parametric'[transfer_rule]\n  by(transfer_prover)\n\nlemma map_gpv_parametric': \"((A ===> A') ===> (C ===> C') ===> rel_gpv'' A C R ===> rel_gpv'' A' C' R) map_gpv map_gpv\"\n  unfolding map_gpv_conv_map_gpv'[abs_def] by transfer_prover\n\nend\n\nsubsection \\<open>Simple, derived operations\\<close>\n\nprimcorec Done :: \"'a \\<Rightarrow> ('a, 'out, 'in) gpv\"\nwhere \"the_gpv (Done a) = return_spmf (Pure a)\"\n\nprimcorec Pause :: \"'out \\<Rightarrow> ('in \\<Rightarrow> ('a, 'out, 'in) gpv) \\<Rightarrow> ('a, 'out, 'in) gpv\"\nwhere \"the_gpv (Pause out c) = return_spmf (IO out c)\"\n\nprimcorec lift_spmf :: \"'a spmf \\<Rightarrow> ('a, 'out, 'in) gpv\"\nwhere \"the_gpv (lift_spmf p) = map_spmf Pure p\"\n\ndefinition Fail :: \"('a, 'out, 'in) gpv\"\nwhere \"Fail = GPV (return_pmf None)\"\n\ndefinition React :: \"('in \\<Rightarrow> 'out \\<times> ('a, 'out, 'in) rpv) \\<Rightarrow> ('a, 'out, 'in) rpv\"\nwhere \"React f input = case_prod Pause (f input)\"\n\ndefinition rFail :: \"('a, 'out, 'in) rpv\"\nwhere \"rFail = (\\<lambda>_. Fail)\"\n\nlemma Done_inject [simp]: \"Done x = Done y \\<longleftrightarrow> x = y\"\nby(simp add: Done.ctr)\n\nlemma Pause_inject [simp]: \"Pause out c = Pause out' c' \\<longleftrightarrow> out = out' \\<and> c = c'\"\nby(simp add: Pause.ctr)\n\n\n\nlemma outs'_gpv_Done [simp]: \"outs'_gpv (Done x) = {}\"\nby(auto elim: outs'_gpv_cases)\n\nlemma results'_gpv_Done [simp]: \"results'_gpv (Done x) = {x}\"\nby(auto intro: results'_gpvI elim: results'_gpv_cases)\n\nlemma pred_gpv_Done [simp]: \"pred_gpv P Q (Done x) = P x\"\nby(simp add: pred_gpv_def)\n\nlemma outs'_gpv_Pause [simp]: \"outs'_gpv (Pause out c) = insert out (\\<Union>input. outs'_gpv (c input))\"\nby(auto 4 4 intro: outs'_gpvI elim: outs'_gpv_cases)\n\nlemma results'_gpv_Pause [simp]: \"results'_gpv (Pause out rpv) = results'_rpv rpv\"\nby(auto 4 4 intro: results'_gpvI elim: results'_gpv_cases)\n\nlemma pred_gpv_Pause [simp]: \"pred_gpv P Q (Pause x c) = (Q x \\<and> All (pred_gpv P Q \\<circ> c))\"\nby(auto simp add: pred_gpv_def o_def)\n\nlemma lift_spmf_return [simp]: \"lift_spmf (return_spmf x) = Done x\"\nby(simp add: lift_spmf.ctr Done.ctr)\n\nlemma lift_spmf_None [simp]: \"lift_spmf (return_pmf None) = Fail\"\nby(rule gpv.expand)(simp add: Fail_def)\n\nlemma the_gpv_lift_spmf [simp]: \"the_gpv (lift_spmf r) = map_spmf Pure r\"\nby(simp)\n\nlemma outs'_gpv_lift_spmf [simp]: \"outs'_gpv (lift_spmf p) = {}\"\nby(auto 4 3 elim: outs'_gpv_cases)\n\nlemma results'_gpv_lift_spmf [simp]: \"results'_gpv (lift_spmf p) = set_spmf p\"\nby(auto 4 3 elim: results'_gpv_cases intro: results'_gpvI)\n\nlemma pred_gpv_lift_spmf [simp]: \"pred_gpv P Q (lift_spmf p) = pred_spmf P p\"\nby(simp add: pred_gpv_def pred_spmf_def)\n\nlemma lift_spmf_inject [simp]: \"lift_spmf p = lift_spmf q \\<longleftrightarrow> p = q\"\nby(auto simp add: lift_spmf.code dest!: pmf.inj_map_strong[rotated] option.inj_map_strong[rotated])\n\nlemma map_lift_spmf: \"map_gpv f g (lift_spmf p) = lift_spmf (map_spmf f p)\"\nby(rule gpv.expand)(simp add: gpv.map_sel spmf.map_comp o_def)\n\nlemma lift_map_spmf: \"lift_spmf (map_spmf f p) = map_gpv f id (lift_spmf p)\"\nby(rule gpv.expand)(simp add: gpv.map_sel spmf.map_comp o_def)\n\nlemma [simp]:\n  shows Fail_neq_Pause: \"Fail \\<noteq> Pause out c\"\n  and Pause_neq_Fail: \"Pause out c \\<noteq> Fail\"\n  and Fail_neq_Done: \"Fail \\<noteq> Done x\"\n  and Done_neq_Fail: \"Done x \\<noteq> Fail\"\nby(simp_all add: Fail_def Pause.ctr Done.ctr)\n\ntext \\<open>Add @{typ unit} closure to circumvent SML value restriction\\<close>\n\ndefinition Fail' :: \"unit \\<Rightarrow> ('a, 'out, 'in) gpv\"\nwhere [code del]: \"Fail' _ = Fail\"\n\nlemma Fail_code [code_unfold]: \"Fail = Fail' ()\"\nby(simp add: Fail'_def)\n\nlemma Fail'_code [code]:\n  \"Fail' x = GPV (return_pmf None)\"\nby(simp add: Fail'_def Fail_def)\n\nlemma Fail_sel [simp]:\n  \"the_gpv Fail = return_pmf None\"\nby(simp add: Fail_def)\n\nlemma Fail_eq_GPV_iff [simp]: \"Fail = GPV f \\<longleftrightarrow> f = return_pmf None\"\nby(auto simp add: Fail_def)\n\nlemma outs'_gpv_Fail [simp]: \"outs'_gpv Fail = {}\"\nby(auto elim: outs'_gpv_cases)\n\nlemma results'_gpv_Fail [simp]: \"results'_gpv Fail = {}\"\nby(auto elim: results'_gpv_cases)\n\nlemma pred_gpv_Fail [simp]: \"pred_gpv P Q Fail\"\nby(simp add: pred_gpv_def)\n\nlemma React_inject [iff]: \"React f = React f' \\<longleftrightarrow> f = f'\"\nby(auto simp add: React_def fun_eq_iff split_def intro: prod.expand)\n\nlemma React_apply [simp]: \"f input = (out, c) \\<Longrightarrow> React f input = Pause out c\"\nby(simp add: React_def)\n\nlemma rFail_apply [simp]: \"rFail input = Fail\"\nby(simp add: rFail_def)\n\nlemma [simp]:\n  shows rFail_neq_React: \"rFail \\<noteq> React f\"\n  and React_neq_rFail: \"React f \\<noteq> rFail\"\nby(simp_all add: React_def fun_eq_iff split_beta)\n\nlemma rel_gpv_FailI [simp]: \"rel_gpv A C Fail Fail\"\nby(subst gpv.rel_sel) simp\n\nlemma rel_gpv_Done [iff]: \"rel_gpv A C (Done x) (Done y) \\<longleftrightarrow> A x y\"\nby(subst gpv.rel_sel) simp\n\nlemma rel_gpv''_Done [iff]: \"rel_gpv'' A C R (Done x) (Done y) \\<longleftrightarrow> A x y\"\nby(subst rel_gpv''.simps) simp\n\nlemma rel_gpv_Pause [iff]:\n  \"rel_gpv A C (Pause out c) (Pause out' c') \\<longleftrightarrow> C out out' \\<and> (\\<forall>x. rel_gpv A C (c x) (c' x))\"\nby(subst gpv.rel_sel)(simp add: rel_fun_def)\n\nlemma rel_gpv''_Pause [iff]:\n  \"rel_gpv'' A C R (Pause out c) (Pause out' c') \\<longleftrightarrow> C out out' \\<and> (\\<forall>x x'. R x x' \\<longrightarrow> rel_gpv'' A C R (c x) (c' x'))\"\nby(subst rel_gpv''.simps)(simp add: rel_fun_def)\n\nlemma rel_gpv_lift_spmf [iff]: \"rel_gpv A C (lift_spmf p) (lift_spmf q) \\<longleftrightarrow> rel_spmf A p q\"\nby(subst gpv.rel_sel)(simp add: spmf_rel_map)\n\nlemma rel_gpv''_lift_spmf [iff]:\n  \"rel_gpv'' A C R (lift_spmf p) (lift_spmf q) \\<longleftrightarrow> rel_spmf A p q\"\nby(subst rel_gpv''.simps)(simp add: spmf_rel_map)\n\ncontext includes lifting_syntax begin\nlemmas Fail_parametric [transfer_rule] = rel_gpv_FailI\n\nlemma Fail_parametric' [simp]: \"rel_gpv'' A C R Fail Fail\"\nunfolding Fail_def by simp\n\nlemma Done_parametric [transfer_rule]: \"(A ===> rel_gpv A C) Done Done\"\nby(rule rel_funI) simp\n\nlemma Done_parametric': \"(A ===> rel_gpv'' A C R) Done Done\"\nby(rule rel_funI) simp\n\nlemma Pause_parametric [transfer_rule]:\n  \"(C ===> ((=) ===> rel_gpv A C) ===> rel_gpv A C) Pause Pause\"\nby(simp add: rel_fun_def)\n\nlemma Pause_parametric':\n  \"(C ===> (R ===> rel_gpv'' A C R) ===> rel_gpv'' A C R) Pause Pause\"\nby(simp add: rel_fun_def)\n\nlemma lift_spmf_parametric [transfer_rule]:\n  \"(rel_spmf A ===> rel_gpv A C) lift_spmf lift_spmf\"\nby(simp add: rel_fun_def)\n\nlemma lift_spmf_parametric':\n  \"(rel_spmf A ===> rel_gpv'' A C R) lift_spmf lift_spmf\"\nby(simp add: rel_fun_def)\nend\n\nlemma map_gpv_Done [simp]: \"map_gpv f g (Done x) = Done (f x)\"\nby(simp add: Done.code)\n\nlemma map_gpv'_Done [simp]: \"map_gpv' f g h (Done x) = Done (f x)\"\nby(simp add: Done.code)\n\nlemma map_gpv_Pause [simp]: \"map_gpv f g (Pause x c) = Pause (g x) (map_gpv f g \\<circ> c)\"\nby(simp add: Pause.code)\n\nlemma map_gpv'_Pause [simp]: \"map_gpv' f g h (Pause x c) = Pause (g x) (map_gpv' f g h \\<circ> c \\<circ> h)\"\nby(simp add: Pause.code map_fun_def)\n\nlemma map_gpv_Fail [simp]: \"map_gpv f g Fail = Fail\"\nby(simp add: Fail_def)\n\nlemma map_gpv'_Fail [simp]: \"map_gpv' f g h Fail = Fail\"\nby(simp add: Fail_def)\n\nsubsection \\<open>Monad structure\\<close>\n\nprimcorec bind_gpv :: \"('a, 'out, 'in) gpv \\<Rightarrow> ('a \\<Rightarrow> ('b, 'out, 'in) gpv) \\<Rightarrow> ('b, 'out, 'in) gpv\"\nwhere\n  \"the_gpv (bind_gpv r f) =\n   map_spmf (map_generat id id ((\\<circ>) (case_sum id (\\<lambda>r. bind_gpv r f))))\n     (the_gpv r \\<bind>\n      (case_generat\n        (\\<lambda>x. map_spmf (map_generat id id ((\\<circ>) Inl)) (the_gpv (f x)))\n        (\\<lambda>out c. return_spmf (IO out (\\<lambda>input. Inr (c input))))))\"\n\ndeclare bind_gpv.sel [simp del]\n\nadhoc_overloading Monad_Syntax.bind bind_gpv\n\nlemma bind_gpv_unfold [code]:\n  \"r \\<bind> f = GPV (\n   do {\n     generat \\<leftarrow> the_gpv r;\n     case generat of Pure x \\<Rightarrow> the_gpv (f x)\n       | IO out c \\<Rightarrow> return_spmf (IO out (\\<lambda>input. c input \\<bind> f))\n   })\"\nunfolding bind_gpv_def\napply(rule gpv.expand)\napply(simp add: map_spmf_bind_spmf)\napply(rule arg_cong[where f=\"bind_spmf (the_gpv r)\"])\napply(auto split: generat.split simp add: map_spmf_bind_spmf fun_eq_iff spmf.map_comp o_def generat.map_comp id_def[symmetric] generat.map_id pmf.map_id option.map_id)\ndone\n\nlemma bind_gpv_code_cong: \"f = f' \\<Longrightarrow> bind_gpv f g = bind_gpv f' g\" by simp\nsetup \\<open>Code_Simp.map_ss (Simplifier.add_cong @{thm bind_gpv_code_cong})\\<close>\n\nlemma bind_gpv_sel:\n  \"the_gpv (r \\<bind> f) =\n   do {\n     generat \\<leftarrow> the_gpv r;\n     case generat of Pure x \\<Rightarrow> the_gpv (f x)\n       | IO out c \\<Rightarrow> return_spmf (IO out (\\<lambda>input. bind_gpv (c input) f))\n   }\"\nby(subst bind_gpv_unfold) simp\n\nlemma bind_gpv_sel' [simp]:\n  \"the_gpv (r \\<bind> f) =\n   do {\n     generat \\<leftarrow> the_gpv r;\n     if is_Pure generat then the_gpv (f (result generat))\n     else return_spmf (IO (output generat) (\\<lambda>input. bind_gpv (continuation generat input) f))\n   }\"\nunfolding bind_gpv_sel\nby(rule arg_cong[where f=\"bind_spmf (the_gpv r)\"])(simp add: fun_eq_iff split: generat.split)\n\nlemma Done_bind_gpv [simp]: \"Done a \\<bind> f = f a\"\nby(rule gpv.expand)(simp)\n\nlemma bind_gpv_Done [simp]: \"f \\<bind> Done = f\"\nproof(coinduction arbitrary: f rule: gpv.coinduct)\n  case (Eq_gpv f)\n  have *: \"the_gpv f \\<bind> (case_generat (\\<lambda>x. return_spmf (Pure x)) (\\<lambda>out c. return_spmf (IO out (\\<lambda>input. Inr (c input))))) =\n           map_spmf (map_generat id id ((\\<circ>) Inr)) (bind_spmf (the_gpv f) return_spmf)\"\n    unfolding map_spmf_bind_spmf\n    by(rule arg_cong2[where f=bind_spmf])(auto simp add: fun_eq_iff split: generat.split)\n  show ?case\n    by(auto simp add: * bind_gpv.simps pmf.rel_map option.rel_map[abs_def] generat.rel_map[abs_def] simp del: bind_gpv_sel' intro!: rel_generatI rel_spmf_reflI)\nqed\n\nlemma if_distrib_bind_gpv2 [if_distribs]:\n  \"bind_gpv gpv (\\<lambda>y. if b then f y else g y) = (if b then bind_gpv gpv f else bind_gpv gpv g)\"\nby simp\n\nlemma lift_spmf_bind: \"lift_spmf r \\<bind> f = GPV (r \\<bind> the_gpv \\<circ> f)\"\nby(coinduction arbitrary: r f rule: gpv.coinduct_strong)(auto simp add: bind_map_spmf o_def intro: rel_pmf_reflI rel_optionI rel_generatI)\n\nlemma the_gpv_bind_gpv_lift_spmf [simp]:\n  \"the_gpv (bind_gpv (lift_spmf p) f) = bind_spmf p (the_gpv \\<circ> f)\"\nby(simp add: bind_map_spmf o_def)\n\nlemma lift_spmf_bind_spmf: \"lift_spmf (p \\<bind> f) = lift_spmf p \\<bind> (\\<lambda>x. lift_spmf (f x))\"\nby(rule gpv.expand)(simp add: lift_spmf_bind o_def map_spmf_bind_spmf)\n\nlemma lift_bind_spmf: \"lift_spmf (bind_spmf p f) = bind_gpv (lift_spmf p) (lift_spmf \\<circ> f)\"\nby(rule gpv.expand)(simp add: bind_map_spmf map_spmf_bind_spmf o_def)\n\nlemma GPV_bind:\n  \"GPV f \\<bind> g = \n   GPV (f \\<bind> (\\<lambda>generat. case generat of Pure x \\<Rightarrow> the_gpv (g x) | IO out c \\<Rightarrow> return_spmf (IO out (\\<lambda>input. c input \\<bind> g))))\"\nby(subst bind_gpv_unfold) simp\n\nlemma GPV_bind':\n  \"GPV f \\<bind> g = GPV (f \\<bind> (\\<lambda>generat. if is_Pure generat then the_gpv (g (result generat)) else return_spmf (IO (output generat) (\\<lambda>input. continuation generat input \\<bind> g))))\"\nunfolding GPV_bind gpv.inject\nby(rule arg_cong[where f=\"bind_spmf f\"])(simp add: fun_eq_iff split: generat.split)\n\nlemma bind_gpv_assoc:\n  fixes f :: \"('a, 'out, 'in) gpv\"\n  shows \"(f \\<bind> g) \\<bind> h = f \\<bind> (\\<lambda>x. g x \\<bind> h)\"\nproof(coinduction arbitrary: f g h rule: gpv.coinduct_strong)\n  case (Eq_gpv f g h)\n  show ?case\n    apply(simp cong del: if_weak_cong)\n    apply(rule rel_spmf_bindI[where R=\"(=)\"])\n     apply(simp add: option.rel_eq pmf.rel_eq)\n    apply(fastforce intro: rel_pmf_return_pmfI rel_generatI rel_spmf_reflI)\n    done\nqed\n\nlemma map_gpv_bind_gpv: \"map_gpv f g (bind_gpv gpv h) = bind_gpv (map_gpv id g gpv) (\\<lambda>x. map_gpv f g (h x))\"\napply(coinduction arbitrary: gpv rule: gpv.coinduct_strong)\napply(simp add: bind_gpv.sel gpv.map_sel spmf_rel_map generat.rel_map o_def bind_map_spmf del: bind_gpv_sel')\napply(rule rel_spmf_bind_reflI)\napply(auto simp add: spmf_rel_map generat.rel_map split: generat.split del: rel_funI intro!: rel_spmf_reflI generat.rel_refl rel_funI)\ndone\n\nlemma map_gpv_id_bind_gpv: \"map_gpv f id (bind_gpv gpv g) = bind_gpv gpv (map_gpv f id \\<circ> g)\"\nby(simp add: map_gpv_bind_gpv gpv.map_id o_def)\n\nlemma map_gpv_conv_bind:\n  \"map_gpv f (\\<lambda>x. x) x = bind_gpv x (\\<lambda>x. Done (f x))\"\nusing map_gpv_bind_gpv[of f \"\\<lambda>x. x\" x Done] by(simp add: id_def[symmetric] gpv.map_id)\n\nlemma bind_map_gpv: \"bind_gpv (map_gpv f id gpv) g = bind_gpv gpv (g \\<circ> f)\"\nby(simp add: map_gpv_conv_bind id_def bind_gpv_assoc o_def)\n\nlemma outs_bind_gpv:\n  \"outs'_gpv (bind_gpv x f) = outs'_gpv x \\<union> (\\<Union>x \\<in> results'_gpv x. outs'_gpv (f x))\"\n  (is \"?lhs = ?rhs\")\nproof(rule Set.set_eqI iffI)+\n  fix out\n  assume \"out \\<in> ?lhs\"\n  then show \"out \\<in> ?rhs\"\n  proof(induction g\\<equiv>\"x \\<bind> f\" arbitrary: x)\n    case (Out generat)\n    then obtain generat' where *: \"generat' \\<in> set_spmf (the_gpv x)\"\n      and **: \"generat \\<in> set_spmf (if is_Pure generat' then the_gpv (f (result generat'))\n                                else return_spmf (IO (output generat') (\\<lambda>input. continuation generat' input \\<bind> f)))\"\n      by(auto)\n    show ?case\n    proof(cases \"is_Pure generat'\")\n      case True\n      then have \"out \\<in> outs'_gpv (f (result generat'))\" using Out(2) ** by(auto intro: outs'_gpvI)\n      moreover have \"result generat' \\<in> results'_gpv x\" using * True\n        by(auto intro: results'_gpvI generat.set_sel)\n      ultimately show ?thesis by blast\n    next\n      case False\n      hence \"out \\<in> outs'_gpv x\" using * ** Out(2) by(auto intro: outs'_gpvI generat.set_sel)\n      thus ?thesis by blast\n    qed\n  next\n    case (Cont generat c input)\n    then obtain generat' where *: \"generat' \\<in> set_spmf (the_gpv x)\"\n      and **: \"generat \\<in> set_spmf (if is_Pure generat' then the_gpv (f (generat.result generat'))\n                                 else return_spmf (IO (generat.output generat') (\\<lambda>input. continuation generat' input \\<bind> f)))\"\n      by(auto)\n    show ?case\n    proof(cases \"is_Pure generat'\")\n      case True\n      then have \"out \\<in> outs'_gpv (f (result generat'))\" using Cont(2-3) ** by(auto intro: outs'_gpvI)\n      moreover have \"result generat' \\<in> results'_gpv x\" using * True\n        by(auto intro: results'_gpvI generat.set_sel)\n      ultimately show ?thesis by blast\n    next\n      case False\n      then have generat: \"generat = IO (output generat') (\\<lambda>input. continuation generat' input \\<bind> f)\"\n        using ** by simp\n      with Cont(2) have \"c input = continuation generat' input \\<bind> f\" by auto\n      hence \"out \\<in> outs'_gpv (continuation generat' input) \\<union> (\\<Union>x\\<in>results'_gpv (continuation generat' input). outs'_gpv (f x))\"\n        by(rule Cont)\n      thus ?thesis\n      proof\n        assume \"out \\<in> outs'_gpv (continuation generat' input)\"\n        with * ** False have \"out \\<in> outs'_gpv x\" by(auto intro: outs'_gpvI generat.set_sel)\n        thus ?thesis ..\n      next\n        assume \"out \\<in> (\\<Union>x\\<in>results'_gpv (continuation generat' input). outs'_gpv (f x))\"\n        then obtain y where \"y \\<in> results'_gpv (continuation generat' input)\" \"out \\<in> outs'_gpv (f y)\" ..\n        from \\<open>y \\<in> _\\<close> * ** False have \"y \\<in> results'_gpv x\" \n          by(auto intro: results'_gpvI generat.set_sel)\n        with \\<open>out \\<in> outs'_gpv (f y)\\<close> show ?thesis by blast\n      qed\n    qed\n  qed\nnext\n  fix out\n  assume \"out \\<in> ?rhs\"\n  then show \"out \\<in> ?lhs\"\n  proof\n    assume \"out \\<in> outs'_gpv x\"\n    thus ?thesis\n    proof(induction)\n      case (Out generat gpv)\n      then show ?case\n        by(cases generat)(fastforce intro: outs'_gpvI rev_bexI)+\n    next\n      case (Cont generat gpv gpv')\n      then show ?case\n        by(cases generat)(auto 4 4 intro: outs'_gpvI rev_bexI simp add: in_set_spmf set_pmf_bind_spmf simp del: set_bind_spmf)\n    qed\n  next\n    assume \"out \\<in> (\\<Union>x\\<in>results'_gpv x. outs'_gpv (f x))\"\n    then obtain y where \"y \\<in> results'_gpv x\" \"out \\<in> outs'_gpv (f y)\" ..\n    from \\<open>y \\<in> _\\<close> show ?thesis\n    proof(induction)\n      case (Pure generat gpv)\n      thus ?case using \\<open>out \\<in> outs'_gpv _\\<close>\n        by(cases generat)(auto 4 5 intro: outs'_gpvI rev_bexI elim: outs'_gpv_cases)\n    next\n      case (Cont generat gpv gpv')\n      thus ?case\n        by(cases generat)(auto 4 4 simp add: in_set_spmf simp add: set_pmf_bind_spmf intro: outs'_gpvI rev_bexI simp del: set_bind_spmf)\n    qed\n  qed\nqed\n\nlemma bind_gpv_Fail [simp]: \"Fail \\<bind> f = Fail\"\nby(subst bind_gpv_unfold)(simp add: Fail_def)\n\nlemma bind_gpv_eq_Fail:\n  \"bind_gpv gpv f = Fail \\<longleftrightarrow> (\\<forall>x\\<in>set_spmf (the_gpv gpv). is_Pure x) \\<and> (\\<forall>x\\<in>results'_gpv gpv. f x = Fail)\"\n  (is \"?lhs = ?rhs\")\nproof(intro iffI conjI strip)\n  show ?lhs if ?rhs using that\n    by(intro gpv.expand)(auto 4 4 simp add: bind_eq_return_pmf_None intro: results'_gpv_Pure generat.set_sel dest: bspec)\n\n  assume ?lhs\n  hence *: \"the_gpv (bind_gpv gpv f) = return_pmf None\" by simp\n  from * show \"is_Pure x\" if \"x \\<in> set_spmf (the_gpv gpv)\" for x using that\n    by(simp add: bind_eq_return_pmf_None split: if_split_asm)\n  show \"f x = Fail\" if \"x \\<in> results'_gpv gpv\" for x using that *\n    by(cases)(auto 4 3 simp add: bind_eq_return_pmf_None elim!: generat.set_cases intro: gpv.expand dest: bspec)\nqed\n\ncontext includes lifting_syntax begin\n\nlemma bind_gpv_parametric [transfer_rule]:\n  \"(rel_gpv A C ===> (A ===> rel_gpv B C) ===> rel_gpv B C) bind_gpv bind_gpv\"\nunfolding bind_gpv_def by transfer_prover\n\nlemma bind_gpv_parametric':\n  \"(rel_gpv'' A C R ===> (A ===> rel_gpv'' B C R) ===> rel_gpv'' B C R) bind_gpv bind_gpv\"\nunfolding bind_gpv_def supply corec_gpv_parametric'[transfer_rule] the_gpv_parametric'[transfer_rule]\nby(transfer_prover)\n\nend\n\nlemma monad_gpv [locale_witness]: \"monad Done bind_gpv\"\nby(unfold_locales)(simp_all add: bind_gpv_assoc)\n\nlemma monad_fail_gpv [locale_witness]: \"monad_fail Done bind_gpv Fail\"\nby unfold_locales auto\n\nlemma rel_gpv_bindI:\n  \"\\<lbrakk> rel_gpv A C gpv gpv'; \\<And>x y. A x y \\<Longrightarrow> rel_gpv B C (f x) (g y) \\<rbrakk>\n  \\<Longrightarrow> rel_gpv B C (bind_gpv gpv f) (bind_gpv gpv' g)\"\nby(fact bind_gpv_parametric[THEN rel_funD, THEN rel_funD, OF _ rel_funI])\n\nlemma bind_gpv_cong:\n  \"\\<lbrakk> gpv = gpv'; \\<And>x. x \\<in> results'_gpv gpv' \\<Longrightarrow> f x = g x \\<rbrakk> \\<Longrightarrow> bind_gpv gpv f = bind_gpv gpv' g\"\napply(subst gpv.rel_eq[symmetric])\napply(rule rel_gpv_bindI[where A=\"eq_onp (\\<lambda>x. x \\<in> results'_gpv gpv')\"])\n apply(subst (asm) gpv.rel_eq[symmetric])\n apply(erule gpv.rel_mono_strong)\n  apply(simp add: eq_onp_def)\n apply simp\napply(clarsimp simp add: gpv.rel_eq eq_onp_def)\ndone\n\ndefinition bind_rpv :: \"('a, 'in, 'out) rpv \\<Rightarrow> ('a \\<Rightarrow> ('b, 'in, 'out) gpv) \\<Rightarrow> ('b, 'in, 'out) rpv\"\nwhere \"bind_rpv rpv f = (\\<lambda>input. bind_gpv (rpv input) f)\"\n\nlemma bind_rpv_apply [simp]: \"bind_rpv rpv f input = bind_gpv (rpv input) f\"\nby(simp add: bind_rpv_def fun_eq_iff)\n\nadhoc_overloading Monad_Syntax.bind bind_rpv\n\nlemma bind_rpv_code_cong: \"rpv = rpv' \\<Longrightarrow> bind_rpv rpv f = bind_rpv rpv' f\" by simp\nsetup \\<open>Code_Simp.map_ss (Simplifier.add_cong @{thm bind_rpv_code_cong})\\<close>\n\nlemma bind_rpv_rDone [simp]: \"bind_rpv rpv Done = rpv\"\nby(simp add: bind_rpv_def)\n\nlemma bind_gpv_Pause [simp]: \"bind_gpv (Pause out rpv) f = Pause out (bind_rpv rpv f)\"\nby(rule gpv.expand)(simp add: fun_eq_iff)\n\nlemma bind_rpv_React [simp]: \"bind_rpv (React f) g = React (apsnd (\\<lambda>rpv. bind_rpv rpv g) \\<circ> f)\"\nby(simp add: React_def split_beta fun_eq_iff)\n\nlemma bind_rpv_assoc: \"bind_rpv (bind_rpv rpv f) g = bind_rpv rpv ((\\<lambda>gpv. bind_gpv gpv g) \\<circ> f)\"\nby(simp add: fun_eq_iff bind_gpv_assoc o_def)\n\nlemma bind_rpv_Done [simp]: \"bind_rpv Done f = f\"\nby(simp add: bind_rpv_def)\n\nlemma results'_rpv_Done [simp]: \"results'_rpv Done = UNIV\"\nby(auto simp add: results'_rpv_def)\n\n\nsubsection \\<open> Embedding @{typ \"'a spmf\"} as a monad \\<close>\n\nlemma neg_fun_distr3:\n  includes lifting_syntax\n  assumes 1: \"left_unique R\" \"right_total R\"\n  assumes 2: \"right_unique S\" \"left_total S\"\n  shows \"(R OO R' ===> S OO S') \\<le> ((R ===> S) OO (R' ===> S'))\"\nusing functional_relation[OF 2] functional_converse_relation[OF 1]\nunfolding rel_fun_def OO_def\napply clarify\napply (subst all_comm)\napply (subst all_conj_distrib[symmetric])\napply (intro choice)\nby metis\n\nlocale spmf_to_gpv begin\n\ntext \\<open>\n  The lifting package cannot handle free term variables in the merging of transfer rules,\n  so for the embedding we define a specialised relator \\<open>rel_gpv'\\<close>\n  which acts only on the returned values.\n\\<close>\n\ndefinition rel_gpv' :: \"('a \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow> ('a, 'out, 'in) gpv \\<Rightarrow> ('b, 'out, 'in) gpv \\<Rightarrow> bool\"\nwhere \"rel_gpv' A = rel_gpv A (=)\"\n\nlemma rel_gpv'_eq [relator_eq]: \"rel_gpv' (=) = (=)\"\nunfolding rel_gpv'_def gpv.rel_eq ..\n\nlemma rel_gpv'_mono [relator_mono]: \"A \\<le> B \\<Longrightarrow> rel_gpv' A \\<le> rel_gpv' B\"\nunfolding rel_gpv'_def by(rule gpv.rel_mono; simp)\n\nlemma rel_gpv'_distr [relator_distr]: \"rel_gpv' A OO rel_gpv' B = rel_gpv' (A OO B)\"\nunfolding rel_gpv'_def by (metis OO_eq gpv.rel_compp) \n\nlemma left_unique_rel_gpv' [transfer_rule]: \"left_unique A \\<Longrightarrow> left_unique (rel_gpv' A)\"\nunfolding rel_gpv'_def by(simp add: left_unique_rel_gpv left_unique_eq)\n\nlemma right_unique_rel_gpv' [transfer_rule]: \"right_unique A \\<Longrightarrow> right_unique (rel_gpv' A)\"\nunfolding rel_gpv'_def by(simp add: right_unique_rel_gpv right_unique_eq)\n\nlemma bi_unique_rel_gpv' [transfer_rule]: \"bi_unique A \\<Longrightarrow> bi_unique (rel_gpv' A)\"\nunfolding rel_gpv'_def by(simp add: bi_unique_rel_gpv bi_unique_eq)\n\nlemma left_total_rel_gpv' [transfer_rule]: \"left_total A \\<Longrightarrow> left_total (rel_gpv' A)\"\nunfolding rel_gpv'_def by(simp add: left_total_rel_gpv left_total_eq)\n\nlemma right_total_rel_gpv' [transfer_rule]: \"right_total A \\<Longrightarrow> right_total (rel_gpv' A)\"\nunfolding rel_gpv'_def by(simp add: right_total_rel_gpv right_total_eq)\n\nlemma bi_total_rel_gpv' [transfer_rule]: \"bi_total A \\<Longrightarrow> bi_total (rel_gpv' A)\"\nunfolding rel_gpv'_def by(simp add: bi_total_rel_gpv bi_total_eq)\n\n\ntext \\<open>\n  We cannot use \\<open>setup_lifting\\<close> because @{typ \"('a, 'out, 'in) gpv\"} contains\n  type variables which do not appear in @{typ \"'a spmf\"}.\n\\<close>\n\ndefinition cr_spmf_gpv :: \"'a spmf \\<Rightarrow> ('a, 'out, 'in) gpv \\<Rightarrow> bool\"\nwhere \"cr_spmf_gpv p gpv \\<longleftrightarrow> gpv = lift_spmf p\"\n\ndefinition spmf_of_gpv :: \"('a, 'out, 'in) gpv \\<Rightarrow> 'a spmf\"\nwhere \"spmf_of_gpv gpv = (THE p. gpv = lift_spmf p)\"\n\nlemma spmf_of_gpv_lift_spmf [simp]: \"spmf_of_gpv (lift_spmf p) = p\"\nunfolding spmf_of_gpv_def by auto\n\nlemma rel_spmf_setD2:\n  \"\\<lbrakk> rel_spmf A p q; y \\<in> set_spmf q \\<rbrakk> \\<Longrightarrow> \\<exists>x\\<in>set_spmf p. A x y\"\nby(erule rel_spmfE) force\n\nlemma rel_gpv_lift_spmf1: \"rel_gpv A B (lift_spmf p) gpv \\<longleftrightarrow> (\\<exists>q. gpv = lift_spmf q \\<and> rel_spmf A p q)\"\napply(subst gpv.rel_sel)\napply(simp add: spmf_rel_map rel_generat_Pure1)\napply safe\n apply(rule exI[where x=\"map_spmf result (the_gpv gpv)\"])\n apply(clarsimp simp add: spmf_rel_map)\n apply(rule conjI)\n  apply(rule gpv.expand)\n  apply(simp add: spmf.map_comp)\n  apply(subst map_spmf_cong[OF refl, where g=id])\n   apply(drule (1) rel_spmf_setD2)\n   apply clarsimp\n  apply simp\n apply(erule rel_spmf_mono)\n apply clarsimp\napply(clarsimp simp add: spmf_rel_map)\ndone\n\nlemma rel_gpv_lift_spmf2: \"rel_gpv A B gpv (lift_spmf q) \\<longleftrightarrow> (\\<exists>p. gpv = lift_spmf p \\<and> rel_spmf A p q)\"\nby(subst gpv.rel_flip[symmetric])(simp add: rel_gpv_lift_spmf1 pmf.rel_flip option.rel_conversep)\n\ndefinition pcr_spmf_gpv :: \"('a \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow> 'a spmf \\<Rightarrow> ('b, 'out, 'in) gpv \\<Rightarrow> bool\"\nwhere \"pcr_spmf_gpv A = cr_spmf_gpv OO rel_gpv A (=)\"\n\nlemma pcr_cr_eq_spmf_gpv: \"pcr_spmf_gpv (=) = cr_spmf_gpv\"\nby(simp add: pcr_spmf_gpv_def gpv.rel_eq OO_eq)\n\nlemma left_unique_cr_spmf_gpv: \"left_unique cr_spmf_gpv\"\nby(rule left_uniqueI)(simp add: cr_spmf_gpv_def)\n\nlemma left_unique_pcr_spmf_gpv [transfer_rule]:\n  \"left_unique A \\<Longrightarrow> left_unique (pcr_spmf_gpv A)\"\nunfolding pcr_spmf_gpv_def by(intro left_unique_OO left_unique_cr_spmf_gpv left_unique_rel_gpv left_unique_eq)\n\nlemma right_unique_cr_spmf_gpv: \"right_unique cr_spmf_gpv\"\nby(rule right_uniqueI)(simp add: cr_spmf_gpv_def)\n\nlemma right_unique_pcr_spmf_gpv [transfer_rule]:\n  \"right_unique A \\<Longrightarrow> right_unique (pcr_spmf_gpv A)\"\nunfolding pcr_spmf_gpv_def by(intro right_unique_OO right_unique_cr_spmf_gpv right_unique_rel_gpv right_unique_eq)\n\nlemma bi_unique_cr_spmf_gpv: \"bi_unique cr_spmf_gpv\"\nby(simp add: bi_unique_alt_def left_unique_cr_spmf_gpv right_unique_cr_spmf_gpv)\n\nlemma bi_unique_pcr_spmf_gpv [transfer_rule]: \"bi_unique A \\<Longrightarrow> bi_unique (pcr_spmf_gpv A)\"\nby(simp add: bi_unique_alt_def left_unique_pcr_spmf_gpv right_unique_pcr_spmf_gpv)\n\nlemma left_total_cr_spmf_gpv: \"left_total cr_spmf_gpv\"\nby(rule left_totalI)(simp add: cr_spmf_gpv_def)\n\nlemma left_total_pcr_spmf_gpv [transfer_rule]: \"left_total A ==> left_total (pcr_spmf_gpv A)\"\nunfolding pcr_spmf_gpv_def by(intro left_total_OO left_total_cr_spmf_gpv left_total_rel_gpv left_total_eq)\n\ncontext includes lifting_syntax begin\n\nlemma return_spmf_gpv_transfer':\n  \"((=) ===> cr_spmf_gpv) return_spmf Done\"\nby(rule rel_funI)(simp add: cr_spmf_gpv_def)\n\nlemma return_spmf_gpv_transfer [transfer_rule]:\n  \"(A ===> pcr_spmf_gpv A) return_spmf Done\"\nunfolding pcr_spmf_gpv_def\napply(rewrite in \"(\\<hole> ===> _) _ _\" eq_OO[symmetric])\napply(rule pos_fun_distr[THEN le_funD, THEN le_funD, THEN le_boolD, THEN mp])\napply(rule relcomppI)\n apply(rule return_spmf_gpv_transfer')\napply transfer_prover\ndone\n\nlemma bind_spmf_gpv_transfer':\n  \"(cr_spmf_gpv ===> ((=) ===> cr_spmf_gpv) ===> cr_spmf_gpv) bind_spmf bind_gpv\"\napply(clarsimp simp add: rel_fun_def cr_spmf_gpv_def)\napply(rule gpv.expand)\napply(simp add: bind_map_spmf map_spmf_bind_spmf o_def)\ndone\n\nlemma bind_spmf_gpv_transfer [transfer_rule]:\n  \"(pcr_spmf_gpv A ===> (A ===> pcr_spmf_gpv B) ===> pcr_spmf_gpv B) bind_spmf bind_gpv\"\nunfolding pcr_spmf_gpv_def\napply(rewrite in \"(_ ===> (\\<hole> ===> _) ===> _) _ _\" eq_OO[symmetric])\napply(rule fun_mono[THEN le_funD, THEN le_funD, THEN le_boolD, THEN mp])\n  apply(rule order.refl)\n apply(rule fun_mono)\n  apply(rule neg_fun_distr3[OF left_unique_eq right_total_eq right_unique_cr_spmf_gpv left_total_cr_spmf_gpv])\n apply(rule order.refl)\napply(rule fun_mono[THEN le_funD, THEN le_funD, THEN le_boolD, THEN mp])\n  apply(rule order.refl)\n apply(rule pos_fun_distr)\napply(rule pos_fun_distr[THEN le_funD, THEN le_funD, THEN le_boolD, THEN mp])\napply(rule relcomppI)\n apply(rule bind_spmf_gpv_transfer')\napply transfer_prover\ndone\n\nlemma lift_spmf_gpv_transfer':\n  \"((=) ===> cr_spmf_gpv) (\\<lambda>x. x) lift_spmf\"\nby(simp add: rel_fun_def cr_spmf_gpv_def)\n\nlemma lift_spmf_gpv_transfer [transfer_rule]:\n  \"(rel_spmf A ===> pcr_spmf_gpv A) (\\<lambda>x. x) lift_spmf\"\nunfolding pcr_spmf_gpv_def\napply(rewrite in \"(\\<hole> ===> _) _ _\" eq_OO[symmetric])\napply(rule pos_fun_distr[THEN le_funD, THEN le_funD, THEN le_boolD, THEN mp])\napply(rule relcomppI)\n apply(rule lift_spmf_gpv_transfer')\napply transfer_prover\ndone\n\nlemma fail_spmf_gpv_transfer': \"cr_spmf_gpv (return_pmf None) Fail\"\nby(simp add: cr_spmf_gpv_def)\n\nlemma fail_spmf_gpv_transfer [transfer_rule]: \"pcr_spmf_gpv A (return_pmf None) Fail\"\nunfolding pcr_spmf_gpv_def\napply(rule relcomppI)\n apply(rule fail_spmf_gpv_transfer')\napply transfer_prover\ndone\n\nlemma map_spmf_gpv_transfer':\n  \"((=) ===> R ===> cr_spmf_gpv ===> cr_spmf_gpv) (\\<lambda>f g. map_spmf f) map_gpv\"\nby(simp add: rel_fun_def cr_spmf_gpv_def map_lift_spmf)\n\nlemma map_spmf_gpv_transfer [transfer_rule]:\n  \"((A ===> B) ===> R ===> pcr_spmf_gpv A ===> pcr_spmf_gpv B) (\\<lambda>f g. map_spmf f) map_gpv\"\nunfolding pcr_spmf_gpv_def\napply(rewrite in \"((\\<hole> ===> _) ===> _)  _ _\" eq_OO[symmetric])\napply(rewrite in \"((_ ===> \\<hole>) ===> _)  _ _\" eq_OO[symmetric])\napply(rewrite in \"(_ ===> \\<hole> ===> _)  _ _\" OO_eq[symmetric])\napply(rule fun_mono[THEN le_funD, THEN le_funD, THEN le_boolD, THEN mp])\n  apply(rule neg_fun_distr3[OF left_unique_eq right_total_eq right_unique_eq left_total_eq])\n apply(rule fun_mono[OF order.refl])\n apply(rule pos_fun_distr)\napply(rule fun_mono[THEN le_funD, THEN le_funD, THEN le_boolD, THEN mp])\n  apply(rule order.refl)\n apply(rule pos_fun_distr)\napply(rule pos_fun_distr[THEN le_funD, THEN le_funD, THEN le_boolD, THEN mp])\napply(rule relcomppI)\n apply(unfold rel_fun_eq)\n apply(rule map_spmf_gpv_transfer')\napply(unfold rel_fun_eq[symmetric])\napply transfer_prover\ndone\n\nend\n\nend\n\nsubsection \\<open> Embedding @{typ \"'a option\"} as a monad \\<close>\n\nlocale option_to_gpv begin\n\ninterpretation option_to_spmf .\ninterpretation spmf_to_gpv .\n\ndefinition cr_option_gpv :: \"'a option \\<Rightarrow> ('a, 'out, 'in) gpv \\<Rightarrow> bool\"\nwhere \"cr_option_gpv x gpv \\<longleftrightarrow> gpv = (lift_spmf \\<circ> return_pmf) x\"\n\nlemma cr_option_gpv_conv_OO:\n  \"cr_option_gpv = cr_spmf_option\\<inverse>\\<inverse> OO cr_spmf_gpv\"\nby(simp add: fun_eq_iff relcompp.simps cr_option_gpv_def cr_spmf_gpv_def cr_spmf_option_def)\n\ncontext includes lifting_syntax begin\n\ntext \\<open>These transfer rules should follow from merging the transfer rules, but this has not yet been implemented.\\<close>\n\nlemma return_option_gpv_transfer [transfer_rule]:\n  \"((=) ===> cr_option_gpv) Some Done\"\nby(simp add: cr_option_gpv_def rel_fun_def)\n\nlemma bind_option_gpv_transfer [transfer_rule]:\n  \"(cr_option_gpv ===> ((=) ===> cr_option_gpv) ===> cr_option_gpv) Option.bind bind_gpv\"\napply(clarsimp simp add: cr_option_gpv_def rel_fun_def)\nsubgoal for x f g by(cases x; simp)\ndone\n\nlemma fail_option_gpv_transfer [transfer_rule]: \"cr_option_gpv None Fail\"\nby(simp add: cr_option_gpv_def)\n\nlemma map_option_gpv_transfer [transfer_rule]:\n  \"((=) ===> R ===> cr_option_gpv ===> cr_option_gpv) (\\<lambda>f g. map_option f) map_gpv\"\nunfolding rel_fun_eq by(simp add: rel_fun_def cr_option_gpv_def map_lift_spmf)\n\nend\n\nend\n\nlocale option_le_gpv begin\n\ninterpretation option_le_spmf .\ninterpretation spmf_to_gpv .\n\ndefinition cr_option_le_gpv :: \"'a option \\<Rightarrow> ('a, 'out, 'in) gpv \\<Rightarrow> bool\"\nwhere \"cr_option_le_gpv x gpv \\<longleftrightarrow> gpv = (lift_spmf \\<circ> return_pmf) x \\<or> x = None\"\n\ncontext includes lifting_syntax begin\n\nlemma return_option_le_gpv_transfer [transfer_rule]:\n  \"((=) ===> cr_option_le_gpv) Some Done\"\nby(simp add: cr_option_le_gpv_def rel_fun_def)\n\nlemma bind_option_gpv_transfer [transfer_rule]:\n  \"(cr_option_le_gpv ===> ((=) ===> cr_option_le_gpv) ===> cr_option_le_gpv) Option.bind bind_gpv\"\napply(clarsimp simp add: cr_option_le_gpv_def rel_fun_def bind_eq_Some_conv)\nsubgoal for f g x y by(erule allE[where x=y]) auto\ndone\n\nlemma fail_option_gpv_transfer [transfer_rule]:\n  \"cr_option_le_gpv None Fail\"\nby(simp add: cr_option_le_gpv_def)\n\nlemma map_option_gpv_transfer [transfer_rule]:\n  \"(((=) ===> (=)) ===> cr_option_le_gpv ===> cr_option_le_gpv) map_option (\\<lambda>f. map_gpv f id)\"\nunfolding rel_fun_eq by(simp add: rel_fun_def cr_option_le_gpv_def map_lift_spmf)\n\nend\n\nend\n\nsubsection \\<open>Embedding resumptions\\<close>\n\nprimcorec lift_resumption :: \"('a, 'out, 'in) resumption \\<Rightarrow> ('a, 'out, 'in) gpv\"\nwhere\n  \"the_gpv (lift_resumption r) = \n  (case r of resumption.Done None \\<Rightarrow> return_pmf None\n    | resumption.Done (Some x') => return_spmf (Pure x')\n    | resumption.Pause out c => map_spmf (map_generat id id ((\\<circ>) lift_resumption)) (return_spmf (IO out c)))\"\n\nlemma the_gpv_lift_resumption:\n  \"the_gpv (lift_resumption r) = \n   (if is_Done r then if Option.is_none (resumption.result r) then return_pmf None else return_spmf (Pure (the (resumption.result r)))\n    else return_spmf (IO (resumption.output r) (lift_resumption \\<circ> resume r)))\"\nby(simp split: option.split resumption.split)\n\ndeclare lift_resumption.simps [simp del]\n\nlemma lift_resumption_Done [code]:\n  \"lift_resumption (resumption.Done x) = (case x of None \\<Rightarrow> Fail | Some x' \\<Rightarrow> Done x')\"\nby(rule gpv.expand)(simp add: the_gpv_lift_resumption split: option.split)\n\nlemma lift_resumption_DONE [simp]:\n  \"lift_resumption (DONE x) = Done x\"\nby(simp add: DONE_def lift_resumption_Done)\n\nlemma lift_resumption_ABORT [simp]:\n  \"lift_resumption ABORT = Fail\"\nby(simp add: ABORT_def lift_resumption_Done)\n\nlemma lift_resumption_Pause [simp, code]:\n  \"lift_resumption (resumption.Pause out c) = Pause out (lift_resumption \\<circ> c)\"\nby(rule gpv.expand)(simp add: the_gpv_lift_resumption)\n\nlemma lift_resumption_Done_Some [simp]: \"lift_resumption (resumption.Done (Some x)) = Done x\"\nusing lift_resumption_DONE unfolding DONE_def by simp\n\nlemma results'_gpv_lift_resumption [simp]:\n  \"results'_gpv (lift_resumption r) = results r\" (is \"?lhs = ?rhs\")\nproof(rule set_eqI iffI)+\n  show \"x \\<in> ?rhs\" if \"x \\<in> ?lhs\" for x using that\n    by(induction gpv\\<equiv>\"lift_resumption r\" arbitrary: r)\n      (auto intro: resumption.set_sel simp add: lift_resumption.sel split: resumption.split_asm option.split_asm)\n  show \"x \\<in> ?lhs\" if \"x \\<in> ?rhs\" for x using that by induction(auto simp add: lift_resumption.sel)\nqed\n\nlemma outs'_gpv_lift_resumption [simp]:\n  \"outs'_gpv (lift_resumption r) = outputs r\" (is \"?lhs = ?rhs\")\nproof(rule set_eqI iffI)+\n  show \"x \\<in> ?rhs\" if \"x \\<in> ?lhs\" for x using that\n    by(induction gpv\\<equiv>\"lift_resumption r\" arbitrary: r)\n      (auto simp add: lift_resumption.sel split: resumption.split_asm option.split_asm)\n  show \"x \\<in> ?lhs\" if \"x \\<in> ?rhs\" for x using that by induction auto\nqed\n\nlemma pred_gpv_lift_resumption [simp]:\n  \"\\<And>A. pred_gpv A C (lift_resumption r) = pred_resumption A C r\"\nby(simp add: pred_gpv_def pred_resumption_def)\n\nlemma lift_resumption_bind: \"lift_resumption (r \\<bind> f) = lift_resumption r \\<bind> lift_resumption \\<circ> f\"\nby(coinduction arbitrary: r rule: gpv.coinduct_strong)\n  (auto simp add: lift_resumption.sel Done_bind split: resumption.split option.split del: rel_funI intro!: rel_funI)\n\nsubsection \\<open>Assertions\\<close>\n\ndefinition assert_gpv :: \"bool \\<Rightarrow> (unit, 'out, 'in) gpv\"\nwhere \"assert_gpv b = (if b then Done () else Fail)\"\n\nlemma assert_gpv_simps [simp]:\n  \"assert_gpv True = Done ()\"\n  \"assert_gpv False = Fail\"\nby(simp_all add: assert_gpv_def)\n\nlemma [simp]:\n  shows assert_gpv_eq_Done: \"assert_gpv b = Done x \\<longleftrightarrow> b\"\n  and Done_eq_assert_gpv: \"Done x = assert_gpv b \\<longleftrightarrow> b\"\n  and Pause_neq_assert_gpv: \"Pause out rpv \\<noteq> assert_gpv b\"\n  and assert_gpv_neq_Pause: \"assert_gpv b \\<noteq> Pause out rpv\"\n  and assert_gpv_eq_Fail: \"assert_gpv b = Fail \\<longleftrightarrow> \\<not> b\"\n  and Fail_eq_assert_gpv: \"Fail = assert_gpv b \\<longleftrightarrow> \\<not> b\"\nby(simp_all add: assert_gpv_def)\n\nlemma assert_gpv_inject [simp]: \"assert_gpv b = assert_gpv b' \\<longleftrightarrow> b = b'\"\nby(simp add: assert_gpv_def)\n\nlemma assert_gpv_sel [simp]:\n  \"the_gpv (assert_gpv b) = map_spmf Pure (assert_spmf b)\"\nby(simp add: assert_gpv_def)\n\nlemma the_gpv_bind_assert [simp]:\n  \"the_gpv (bind_gpv (assert_gpv b) f) =\n   bind_spmf (assert_spmf b) (the_gpv \\<circ> f)\"\nby(cases b) simp_all\n\nlemma pred_gpv_assert [simp]: \"pred_gpv P Q (assert_gpv b) = (b \\<longrightarrow> P ())\"\nby(cases b) simp_all\n\nprimcorec try_gpv :: \"('a, 'call, 'ret) gpv \\<Rightarrow> ('a, 'call, 'ret) gpv \\<Rightarrow> ('a, 'call, 'ret) gpv\" (\"TRY _ ELSE _\" [0,60] 59)\nwhere\n  \"the_gpv (TRY gpv ELSE gpv') = \n   map_spmf (map_generat id id (\\<lambda>c input. case c input of Inl gpv \\<Rightarrow> try_gpv gpv gpv' | Inr gpv' \\<Rightarrow> gpv'))\n     (try_spmf (map_spmf (map_generat id id (map_fun id Inl)) (the_gpv gpv))\n               (map_spmf (map_generat id id (map_fun id Inr)) (the_gpv gpv')))\"\n\nlemma try_gpv_sel:\n  \"the_gpv (TRY gpv ELSE gpv') =\n   TRY map_spmf (map_generat id id (\\<lambda>c input. TRY c input ELSE gpv')) (the_gpv gpv) ELSE the_gpv gpv'\"\nby(simp add: try_gpv_def map_try_spmf spmf.map_comp o_def generat.map_comp generat.map_ident id_def)\n\nlemma try_gpv_Done [simp]: \"TRY Done x ELSE gpv' = Done x\"\nby(rule gpv.expand)(simp)\n\nlemma try_gpv_Fail [simp]: \"TRY Fail ELSE gpv' = gpv'\"\nby(rule gpv.expand)(simp add: spmf.map_comp o_def generat.map_comp generat.map_ident)\n\nlemma try_gpv_Pause [simp]: \"TRY Pause out c ELSE gpv' = Pause out (\\<lambda>input. TRY c input ELSE gpv')\"\nby(rule gpv.expand) simp\n\nlemma try_gpv_Fail2 [simp]: \"TRY gpv ELSE Fail = gpv\"\nby(coinduction arbitrary: gpv rule: gpv.coinduct_strong)\n  (auto simp add: spmf_rel_map generat.rel_map intro!: rel_spmf_reflI generat.rel_refl)\n\nlemma lift_try_spmf: \"lift_spmf (TRY p ELSE q) = TRY lift_spmf p ELSE lift_spmf q\" \nby(rule gpv.expand)(simp add: map_try_spmf spmf.map_comp o_def)\n\nlemma try_assert_gpv: \"TRY assert_gpv b ELSE gpv' = (if b then Done () else gpv')\"\nby(simp)\n\ncontext includes lifting_syntax begin\nlemma try_gpv_parametric [transfer_rule]:\n  \"(rel_gpv A C ===> rel_gpv A C ===> rel_gpv A C) try_gpv try_gpv\"\nunfolding try_gpv_def by transfer_prover\n\nlemma try_gpv_parametric':\n  \"(rel_gpv'' A C R ===> rel_gpv'' A C R ===> rel_gpv'' A C R) try_gpv try_gpv\"\nunfolding try_gpv_def\nsupply corec_gpv_parametric'[transfer_rule] the_gpv_parametric'[transfer_rule]\nby transfer_prover\nend\n\nlemma map_try_gpv: \"map_gpv f g (TRY gpv ELSE gpv') = TRY map_gpv f g gpv ELSE map_gpv f g gpv'\"\nby(simp add: gpv.rel_map try_gpv_parametric[THEN rel_funD, THEN rel_funD] gpv.rel_refl gpv.rel_eq[symmetric])\n\nlemma map'_try_gpv: \"map_gpv' f g h (TRY gpv ELSE gpv') = TRY map_gpv' f g h gpv ELSE map_gpv' f g h gpv'\"\nby(coinduction arbitrary: gpv rule: gpv.coinduct_strong)(auto 4 3 simp add: spmf_rel_map generat.rel_map intro!: rel_spmf_reflI generat.rel_refl rel_funI rel_spmf_try_spmf)\n  \n\nlemma try_bind_assert_gpv:\n  \"TRY (assert_gpv b \\<bind> f) ELSE gpv = (if b then TRY (f ()) ELSE gpv else gpv)\"\nby(simp)\n\n\n\nsubsection \\<open>Order for @{typ \"('a, 'out, 'in) gpv\"}\\<close>\n\ncoinductive ord_gpv :: \"('a, 'out, 'in) gpv \\<Rightarrow> ('a, 'out, 'in) gpv \\<Rightarrow> bool\"\nwhere\n  \"ord_spmf (rel_generat (=) (=) (rel_fun (=) ord_gpv)) f g \\<Longrightarrow> ord_gpv (GPV f) (GPV g)\"\n\ninductive_simps ord_gpv_simps [simp]:\n  \"ord_gpv (GPV f) (GPV g)\"\n\nlemma ord_gpv_coinduct [consumes 1, case_names ord_gpv, coinduct pred: ord_gpv]:\n  assumes \"X f g\"\n  and step: \"\\<And>f g. X f g \\<Longrightarrow> ord_spmf (rel_generat (=) (=) (rel_fun (=) X)) (the_gpv f) (the_gpv g)\"\n  shows \"ord_gpv f g\"\nusing \\<open>X f g\\<close>\nby(coinduct)(auto dest: step simp add: eq_GPV_iff intro: ord_spmf_mono rel_generat_mono rel_fun_mono)\n\nlemma ord_gpv_the_gpvD:\n  \"ord_gpv f g \\<Longrightarrow> ord_spmf (rel_generat (=) (=) (rel_fun (=) ord_gpv)) (the_gpv f) (the_gpv g)\"\nby(erule ord_gpv.cases) simp\n\nlemma reflp_equality: \"reflp (=)\"\nby(simp add: reflp_def)\n\nlemma ord_gpv_reflI [simp]: \"ord_gpv f f\"\nby(coinduction arbitrary: f)(auto intro: ord_spmf_reflI simp add: rel_generat_same rel_fun_def)\n\nlemma reflp_ord_gpv: \"reflp ord_gpv\"\nby(rule reflpI)(rule ord_gpv_reflI)\n\nlemma ord_gpv_trans:\n  assumes \"ord_gpv f g\" \"ord_gpv g h\"\n  shows \"ord_gpv f h\"\nusing assms\nproof(coinduction arbitrary: f g h)\n  case (ord_gpv f g h)\n  have *: \"ord_spmf (rel_generat (=) (=) (rel_fun (=) (\\<lambda>f h. \\<exists>g. ord_gpv f g \\<and> ord_gpv g h))) (the_gpv f) (the_gpv h) =\n    ord_spmf (rel_generat ((=) OO (=)) ((=) OO (=)) (rel_fun (=) (ord_gpv OO ord_gpv))) (the_gpv f) (the_gpv h)\"\n    by(simp add: relcompp.simps[abs_def])\n  then show ?case using ord_gpv\n    by(auto elim!: ord_gpv.cases simp add: generat.rel_compp ord_spmf_compp fun.rel_compp)\nqed\n\nlemma ord_gpv_compp: \"(ord_gpv OO ord_gpv) = ord_gpv\"\nby(auto simp add: fun_eq_iff intro: ord_gpv_trans)\n\nlemma transp_ord_gpv [simp]: \"transp ord_gpv\"\nby(blast intro: transpI ord_gpv_trans)\n\nlemma ord_gpv_antisym:\n  \"\\<lbrakk> ord_gpv f g; ord_gpv g f \\<rbrakk> \\<Longrightarrow> f = g\"\nproof(coinduction arbitrary: f g)\n  case (Eq_gpv f g)\n  let ?R = \"rel_generat (=) (=) (rel_fun (=) ord_gpv)\"\n  from \\<open>ord_gpv f g\\<close> have \"ord_spmf ?R (the_gpv f) (the_gpv g)\" by cases simp\n  moreover\n  from \\<open>ord_gpv g f\\<close> have \"ord_spmf ?R (the_gpv g) (the_gpv f)\" by cases simp\n  ultimately have \"rel_spmf (inf ?R ?R\\<inverse>\\<inverse>) (the_gpv f) (the_gpv g)\"\n    by(rule rel_spmf_inf)(auto 4 3 intro: transp_rel_generatI transp_ord_gpv reflp_ord_gpv reflp_equality reflp_fun1 is_equality_eq transp_rel_fun)\n  also have \"inf ?R ?R\\<inverse>\\<inverse> = rel_generat (inf (=) (=)) (inf (=) (=)) (rel_fun (=) (inf ord_gpv ord_gpv\\<inverse>\\<inverse>))\"\n    unfolding rel_generat_inf[symmetric] rel_fun_inf[symmetric]\n    by(simp add: generat.rel_conversep[symmetric] fun.rel_conversep)\n  finally show ?case by(simp add: inf_fun_def)\nqed\n\nlemma RFail_least [simp]: \"ord_gpv Fail f\"\nby(coinduction arbitrary: f)(simp add: eq_GPV_iff)\n\nsubsection \\<open>Bounds on interaction\\<close>\n\ncontext\n  fixes \"consider\" :: \"'out \\<Rightarrow> bool\"\n  notes monotone_SUP[partial_function_mono] [[function_internals]]\nbegin\ndeclaration \\<open>Partial_Function.init \"lfp_strong\" @{term lfp.fixp_fun} @{term lfp.mono_body}\n  @{thm lfp.fixp_rule_uc} @{thm lfp.fixp_induct_strong2_uc} NONE\\<close>\n\npartial_function (lfp_strong) interaction_bound :: \"('a, 'out, 'in) gpv \\<Rightarrow> enat\"\nwhere\n  \"interaction_bound gpv =\n  (SUP generat\\<in>set_spmf (the_gpv gpv). case generat of Pure _ \\<Rightarrow> 0 \n     | IO out c \\<Rightarrow> if consider out then eSuc (SUP input. interaction_bound (c input)) else (SUP input. interaction_bound (c input)))\"\n\nlemma interaction_bound_fixp_induct [case_names adm bottom step]:\n  \"\\<lbrakk> ccpo.admissible (fun_lub Sup) (fun_ord (\\<le>)) P;\n     P (\\<lambda>_. 0);\n    \\<And>interaction_bound'. \n    \\<lbrakk> P interaction_bound'; \n      \\<And>gpv. interaction_bound' gpv \\<le> interaction_bound gpv;\n      \\<And>gpv. interaction_bound' gpv \\<le> (SUP generat\\<in>set_spmf (the_gpv gpv). case generat of Pure _ \\<Rightarrow> 0 \n     | IO out c \\<Rightarrow> if consider out then eSuc (SUP input. interaction_bound' (c input)) else (SUP input. interaction_bound' (c input)))\n      \\<rbrakk>\n      \\<Longrightarrow> P (\\<lambda>gpv. \\<Squnion>generat\\<in>set_spmf (the_gpv gpv). case generat of Pure x \\<Rightarrow> 0\n         | IO out c \\<Rightarrow> if consider out then eSuc (\\<Squnion>input. interaction_bound' (c input)) else (\\<Squnion>input. interaction_bound' (c input))) \\<rbrakk>\n   \\<Longrightarrow> P interaction_bound\"\nby(erule interaction_bound.fixp_induct)(simp_all add: bot_enat_def fun_ord_def)\n\nlemma interaction_bound_IO:\n   \"IO out c \\<in> set_spmf (the_gpv gpv)\n   \\<Longrightarrow> (if consider out then eSuc (interaction_bound (c input)) else interaction_bound (c input)) \\<le> interaction_bound gpv\"\nby(rewrite in \"_ \\<le> \\<hole>\" interaction_bound.simps)(auto intro!: SUP_upper2)\n\nlemma interaction_bound_IO_consider:\n   \"\\<lbrakk> IO out c \\<in> set_spmf (the_gpv gpv); consider out \\<rbrakk>\n   \\<Longrightarrow> eSuc (interaction_bound (c input)) \\<le> interaction_bound gpv\"\nby(drule interaction_bound_IO) simp\n\nlemma interaction_bound_IO_ignore:\n   \"\\<lbrakk> IO out c \\<in> set_spmf (the_gpv gpv); \\<not> consider out \\<rbrakk>\n   \\<Longrightarrow> interaction_bound (c input) \\<le> interaction_bound gpv\"\nby(drule interaction_bound_IO) simp\n\nlemma interaction_bound_Done [simp]: \"interaction_bound (Done x) = 0\"\nby(simp add: interaction_bound.simps)\n\nlemma interaction_bound_Fail [simp]: \"interaction_bound Fail = 0\"\nby(simp add: interaction_bound.simps bot_enat_def)\n\nlemma interaction_bound_Pause [simp]:\n  \"interaction_bound (Pause out c) = \n   (if consider out then eSuc (SUP input. interaction_bound (c input)) else (SUP input. interaction_bound (c input)))\"\nby(simp add: interaction_bound.simps)\n\nlemma interaction_bound_lift_spmf [simp]: \"interaction_bound (lift_spmf p) = 0\"\nby(simp add: interaction_bound.simps SUP_constant bot_enat_def)\n\nlemma interaction_bound_assert_gpv [simp]: \"interaction_bound (assert_gpv b) = 0\"\nby(cases b) simp_all\n\nlemma interaction_bound_bind_step:\n  assumes IH: \"\\<And>p. interaction_bound' (p \\<bind> f) \\<le> interaction_bound p + (\\<Squnion>x\\<in>results'_gpv p. interaction_bound' (f x))\"\n  and unfold: \"\\<And>gpv. interaction_bound' gpv \\<le> (\\<Squnion>generat\\<in>set_spmf (the_gpv gpv). case generat of Pure x \\<Rightarrow> 0\n             | IO out c \\<Rightarrow> if consider out then eSuc (\\<Squnion>input. interaction_bound' (c input)) else \\<Squnion>input. interaction_bound' (c input))\"\n  shows \"(\\<Squnion>generat\\<in>set_spmf (the_gpv (p \\<bind> f)).\n             case generat of Pure x \\<Rightarrow> 0\n             | IO out c \\<Rightarrow>\n                 if consider out then eSuc (\\<Squnion>input. interaction_bound' (c input))\n                 else \\<Squnion>input. interaction_bound' (c input))\n         \\<le> interaction_bound p +\n            (\\<Squnion>x\\<in>results'_gpv p.\n                \\<Squnion>generat\\<in>set_spmf (the_gpv (f x)).\n                   case generat of Pure x \\<Rightarrow> 0\n                   | IO out c \\<Rightarrow>\n                       if consider out then eSuc (\\<Squnion>input. interaction_bound' (c input))\n                       else \\<Squnion>input. interaction_bound' (c input))\"\n    (is \"(SUP generat'\\<in>?bind. ?g generat') \\<le> ?p + ?f\")\nproof(rule SUP_least)\n  fix generat'\n  assume \"generat' \\<in> ?bind\"\n  then obtain generat where generat: \"generat \\<in> set_spmf (the_gpv p)\"\n    and *: \"case generat of Pure x \\<Rightarrow> generat' \\<in> set_spmf (the_gpv (f x)) \n         | IO out c \\<Rightarrow> generat' = IO out (\\<lambda>input. c input \\<bind> f)\"\n    by(clarsimp simp add: bind_gpv.sel simp del: bind_gpv_sel')\n      (clarsimp split: generat.split_asm simp add: generat.map_comp o_def generat.map_id[unfolded id_def])\n  show \"?g generat' \\<le> ?p + ?f\"\n  proof(cases generat)\n    case (Pure x)\n    have \"?g generat' \\<le> (SUP generat'\\<in>set_spmf (the_gpv (f x)). (case generat' of Pure x \\<Rightarrow> 0 | IO out c \\<Rightarrow> if consider out then eSuc (\\<Squnion>input. interaction_bound' (c input)) else \\<Squnion>input. interaction_bound' (c input)))\"\n      using * Pure by(auto intro: SUP_upper)\n    also have \"\\<dots> \\<le> 0 + ?f\" using generat Pure\n      by(auto 4 3 intro: SUP_upper results'_gpv_Pure)\n    also have \"\\<dots> \\<le> ?p + ?f\" by simp\n    finally show ?thesis .\n  next\n    case (IO out c)\n    with * have \"?g generat' = (if consider out then eSuc (SUP input. interaction_bound' (c input \\<bind> f)) else (SUP input. interaction_bound' (c input \\<bind> f)))\" by simp\n    also have \"\\<dots> \\<le> (if consider out then eSuc (SUP input. interaction_bound (c input) + (\\<Squnion>x\\<in>results'_gpv (c input). interaction_bound' (f x))) else (SUP input. interaction_bound (c input) + (\\<Squnion>x\\<in>results'_gpv (c input). interaction_bound' (f x))))\"\n      by(auto intro: SUP_mono IH)\n    also have \"\\<dots> \\<le> (case IO out c of Pure (x :: 'a) \\<Rightarrow> 0 | IO out c \\<Rightarrow> if consider out then eSuc (SUP input. interaction_bound (c input)) else (SUP input. interaction_bound (c input))) + (SUP input. SUP x\\<in>results'_gpv (c input). interaction_bound' (f x))\"\n      by(simp add: iadd_Suc SUP_le_iff)(meson SUP_upper2 UNIV_I add_mono order_refl)\n    also have \"\\<dots> \\<le> ?p + ?f\"\n      apply(rewrite in \"_ \\<le> \\<hole>\" interaction_bound.simps)\n      apply(rule add_mono SUP_least SUP_upper generat[unfolded IO])+\n      apply(rule order_trans[OF unfold])\n      apply(auto 4 3 intro: results'_gpv_Cont[OF generat] SUP_upper simp add: IO)\n      done\n    finally show ?thesis .\n  qed\nqed\n\nlemma interaction_bound_bind:\n  defines \"ib1 \\<equiv> interaction_bound\"\n  shows \"interaction_bound (p \\<bind> f) \\<le> ib1 p + (SUP x\\<in>results'_gpv p. interaction_bound (f x))\"\nproof(induction arbitrary: p rule: interaction_bound_fixp_induct)\n  case adm show ?case by simp\n  case bottom show ?case by simp\n  case (step interaction_bound') then show ?case unfolding ib1_def by -(rule interaction_bound_bind_step)\nqed\n\nlemma interaction_bound_bind_lift_spmf [simp]:\n  \"interaction_bound (lift_spmf p \\<bind> f) = (SUP x\\<in>set_spmf p. interaction_bound (f x))\"\nby(subst (1 2) interaction_bound.simps)(simp add: bind_UNION SUP_UNION)\n\nend\n\nabbreviation interaction_any_bound :: \"('a, 'out, 'in) gpv \\<Rightarrow> enat\"\nwhere \"interaction_any_bound \\<equiv> interaction_bound (\\<lambda>_. True)\"\n\nlemma interaction_any_bound_coinduct [consumes 1, case_names interaction_bound]:\n  assumes X: \"X gpv n\"\n  and *: \"\\<And>gpv n out c input. \\<lbrakk> X gpv n; IO out c \\<in> set_spmf (the_gpv gpv) \\<rbrakk> \n    \\<Longrightarrow> \\<exists>n'. (X (c input) n' \\<or> interaction_any_bound (c input) \\<le> n') \\<and> eSuc n' \\<le> n\"\n  shows \"interaction_any_bound gpv \\<le> n\"\nusing X\nproof(induction arbitrary: gpv n rule: interaction_bound_fixp_induct)\n  case adm show ?case by(intro cont_intro)\n  case bottom show ?case by simp\nnext\n  case (step interaction_bound')\n  { fix out c\n    assume IO: \"IO out c \\<in> set_spmf (the_gpv gpv)\"\n    from *[OF step.prems IO] obtain n' where n: \"n = eSuc n'\"\n      by(cases n rule: co.enat.exhaust) auto\n    moreover \n    { fix input\n      have \"\\<exists>n''. (X (c input) n'' \\<or> interaction_any_bound (c input) \\<le> n'') \\<and> eSuc n'' \\<le> n\"\n        using step.prems IO \\<open>n = eSuc n'\\<close> by(auto 4 3 dest: *)\n      then have \"interaction_bound' (c input) \\<le> n'\" using n\n        by(auto dest: step.IH intro: step.hyps[THEN order_trans] elim!: order_trans simp add: neq_zero_conv_eSuc) }\n    ultimately have \"eSuc (\\<Squnion>input. interaction_bound' (c input)) \\<le> n\"\n      by(auto intro: SUP_least) }\n  then show ?case by(auto intro!: SUP_least split: generat.split)\nqed\n\ncontext includes lifting_syntax begin\nlemma interaction_bound_parametric':\n  assumes [transfer_rule]: \"bi_total R\"\n  shows \"((C ===> (=)) ===> rel_gpv'' A C R ===> (=)) interaction_bound interaction_bound\"\nunfolding interaction_bound_def[abs_def]\napply(rule rel_funI)\napply(rule fixp_lfp_parametric_eq[OF interaction_bound.mono interaction_bound.mono])\nsubgoal premises [transfer_rule]\n  supply the_gpv_parametric'[transfer_rule] rel_gpv''_eq[relator_eq]\n  by transfer_prover\ndone\n\nlemma interaction_bound_parametric [transfer_rule]:\n  \"((C ===> (=)) ===> rel_gpv A C ===> (=)) interaction_bound interaction_bound\"\nunfolding rel_gpv_conv_rel_gpv'' by(rule interaction_bound_parametric')(rule bi_total_eq)\nend\n\ntext \\<open>\n  There is no nice @{const interaction_bound} equation for @{const bind_gpv}, as it computes\n  an exact bound, but we only need an upper bound.\n  As @{typ enat} is hard to work with (and @{term \\<infinity>} does not constrain a gpv in any way),\n  we work with @{typ nat}.\n\\<close>\n\ninductive interaction_bounded_by :: \"('out \\<Rightarrow> bool) \\<Rightarrow> ('a, 'out, 'in) gpv \\<Rightarrow> enat \\<Rightarrow> bool\"\nfor \"consider\" gpv n where\n  interaction_bounded_by: \"\\<lbrakk> interaction_bound consider gpv \\<le> n \\<rbrakk> \\<Longrightarrow> interaction_bounded_by consider gpv n\"\n\nlemmas interaction_bounded_byI = interaction_bounded_by\nhide_fact (open) interaction_bounded_by\n\ncontext includes lifting_syntax begin\nlemma interaction_bounded_by_parametric [transfer_rule]:\n  \"((C ===> (=)) ===> rel_gpv A C ===> (=) ===> (=)) interaction_bounded_by interaction_bounded_by\"\nunfolding interaction_bounded_by.simps[abs_def] by transfer_prover\n\nlemma interaction_bounded_by_parametric':\n  notes interaction_bound_parametric'[transfer_rule]\n  assumes [transfer_rule]: \"bi_total R\"\n  shows \"((C ===> (=)) ===> rel_gpv'' A C R ===> (=) ===> (=)) \n         interaction_bounded_by interaction_bounded_by\"\nunfolding interaction_bounded_by.simps[abs_def] by transfer_prover\nend\n\nlemma interaction_bounded_by_mono:\n  \"\\<lbrakk> interaction_bounded_by consider gpv n; n \\<le> m \\<rbrakk> \\<Longrightarrow> interaction_bounded_by consider gpv m\"\nunfolding interaction_bounded_by.simps by(erule order_trans) simp\n\nlemma interaction_bounded_by_contD:\n  \"\\<lbrakk> interaction_bounded_by consider gpv n; IO out c \\<in> set_spmf (the_gpv gpv); consider out \\<rbrakk>\n  \\<Longrightarrow> n > 0 \\<and> interaction_bounded_by consider (c input) (n - 1)\"\nunfolding interaction_bounded_by.simps\nby(subst (asm) interaction_bound.simps)(auto simp add: SUP_le_iff eSuc_le_iff enat_eSuc_iff dest!: bspec)\n\nlemma interaction_bounded_by_contD_ignore:\n  \"\\<lbrakk> interaction_bounded_by consider gpv n; IO out c \\<in> set_spmf (the_gpv gpv) \\<rbrakk>\n  \\<Longrightarrow> interaction_bounded_by consider (c input) n\"\nunfolding interaction_bounded_by.simps\nby(subst (asm) interaction_bound.simps)(auto 4 4 simp add: SUP_le_iff eSuc_le_iff enat_eSuc_iff dest!: bspec split: if_split_asm elim: order_trans)\n\nlemma interaction_bounded_byI_epred:\n  assumes \"\\<And>out c. \\<lbrakk> IO out c \\<in> set_spmf (the_gpv gpv); consider out \\<rbrakk> \\<Longrightarrow> n \\<noteq> 0 \\<and> (\\<forall>input. interaction_bounded_by consider (c input) (n - 1))\"\n  and \"\\<And>out c input. \\<lbrakk> IO out c \\<in> set_spmf (the_gpv gpv); \\<not> consider out \\<rbrakk> \\<Longrightarrow> interaction_bounded_by consider (c input) n\"\n  shows \"interaction_bounded_by consider gpv n\"\nunfolding interaction_bounded_by.simps\nby(subst interaction_bound.simps)(auto 4 5 intro!: SUP_least split: generat.split dest: assms simp add: eSuc_le_iff enat_eSuc_iff gr0_conv_Suc neq_zero_conv_eSuc interaction_bounded_by.simps)\n\nlemma interaction_bounded_by_IO:\n  \"\\<lbrakk> IO out c \\<in> set_spmf (the_gpv gpv); interaction_bounded_by consider gpv n; consider out \\<rbrakk>\n  \\<Longrightarrow> n \\<noteq> 0 \\<and> interaction_bounded_by consider (c input) (n - 1)\"\nby(drule interaction_bound_IO[where input=input and ?consider=\"consider\"])(auto simp add: interaction_bounded_by.simps epred_conv_minus eSuc_le_iff enat_eSuc_iff)\n\nlemma interaction_bounded_by_0: \"interaction_bounded_by consider gpv 0 \\<longleftrightarrow> interaction_bound consider gpv = 0\"\nby(simp add: interaction_bounded_by.simps zero_enat_def[symmetric])\n\nabbreviation interaction_bounded_by' :: \"('out \\<Rightarrow> bool) \\<Rightarrow> ('a, 'out, 'in) gpv \\<Rightarrow> nat \\<Rightarrow> bool\"\nwhere \"interaction_bounded_by' consider gpv n \\<equiv> interaction_bounded_by consider gpv (enat n)\"\n\nnamed_theorems interaction_bound\n\nlemmas interaction_bounded_by_start = interaction_bounded_by_mono\n\nmethod interaction_bound_start = (rule interaction_bounded_by_start)\nmethod interaction_bound_step uses add simp =\n  ((match conclusion in \"interaction_bounded_by _ _ _\" \\<Rightarrow> fail \\<bar> _ \\<Rightarrow> \\<open>solves \\<open>clarsimp simp add: simp\\<close>\\<close>) | rule add interaction_bound)\nmethod interaction_bound_rec uses add simp = \n  (interaction_bound_step add: add simp: simp; (interaction_bound_rec add: add simp: simp)?)\nmethod interaction_bound uses add simp =\n  ((* use in *) interaction_bound_start, interaction_bound_rec add: add simp: simp)\n\nlemma interaction_bounded_by_Done [simp]: \"interaction_bounded_by consider (Done x) n\"\nby(simp add: interaction_bounded_by.simps)\n\nlemma interaction_bounded_by_DoneI [interaction_bound]:\n  \"interaction_bounded_by consider (Done x) 0\"\nby simp\n\nlemma interaction_bounded_by_Fail [simp]: \"interaction_bounded_by consider Fail n\"\nby(simp add: interaction_bounded_by.simps)\n\nlemma interaction_bounded_by_FailI [interaction_bound]: \"interaction_bounded_by consider Fail 0\"\nby simp\n\nlemma interaction_bounded_by_lift_spmf [simp]: \"interaction_bounded_by consider (lift_spmf p) n\"\nby(simp add: interaction_bounded_by.simps)\n\nlemma interaction_bounded_by_lift_spmfI [interaction_bound]:\n  \"interaction_bounded_by consider (lift_spmf p) 0\"\nby simp\n\nlemma interaction_bounded_by_assert_gpv [simp]: \"interaction_bounded_by consider (assert_gpv b) n\"\nby(cases b) simp_all\n\nlemma interaction_bounded_by_assert_gpvI [interaction_bound]:\n  \"interaction_bounded_by consider (assert_gpv b) 0\"\nby simp\n\nlemma interaction_bounded_by_Pause [simp]:\n  \"interaction_bounded_by consider (Pause out c) n \\<longleftrightarrow> \n  (if consider out then 0 < n \\<and> (\\<forall>input. interaction_bounded_by consider (c input) (n - 1)) else (\\<forall>input. interaction_bounded_by consider (c input) n))\"\nby(cases n rule: co.enat.exhaust)\n  (auto 4 3 simp add: interaction_bounded_by.simps eSuc_le_iff enat_eSuc_iff gr0_conv_Suc intro: SUP_least dest: order_trans[OF SUP_upper, rotated])\n\nlemma interaction_bounded_by_PauseI [interaction_bound]:\n  \"(\\<And>input. interaction_bounded_by consider (c input) (n input))\n  \\<Longrightarrow> interaction_bounded_by consider (Pause out c) (if consider out then 1 + (SUP input. n input) else (SUP input. n input))\"\nby(auto simp add: iadd_is_0 enat_add_sub_same intro: interaction_bounded_by_mono SUP_upper)\n\nlemma interaction_bounded_by_bindI [interaction_bound]:\n  \"\\<lbrakk> interaction_bounded_by consider gpv n; \\<And>x. x \\<in> results'_gpv gpv \\<Longrightarrow> interaction_bounded_by consider (f x) (m x) \\<rbrakk>\n  \\<Longrightarrow> interaction_bounded_by consider (gpv \\<bind> f) (n + (SUP x\\<in>results'_gpv gpv. m x))\"\nunfolding interaction_bounded_by.simps plus_enat_simps(1)[symmetric]\nby(rule interaction_bound_bind[THEN order_trans])(auto intro: add_mono SUP_mono)\n\nlemma interaction_bounded_by_bind_PauseI [interaction_bound]:\n  \"(\\<And>input. interaction_bounded_by consider (c input \\<bind> f) (n input))\n  \\<Longrightarrow> interaction_bounded_by consider (Pause out c \\<bind> f) (if consider out then SUP input. n input + 1 else SUP input. n input)\"\nby(auto 4 3 simp add: interaction_bounded_by.simps SUP_enat_add_left eSuc_plus_1 intro: SUP_least SUP_upper2)\n\nlemma interaction_bounded_by_bind_lift_spmf [simp]:\n  \"interaction_bounded_by consider (lift_spmf p \\<bind> f) n \\<longleftrightarrow> (\\<forall>x\\<in>set_spmf p. interaction_bounded_by consider (f x) n)\"\nby(simp add: interaction_bounded_by.simps SUP_le_iff)\n\nlemma interaction_bounded_by_bind_lift_spmfI [interaction_bound]:\n  \"(\\<And>x. x \\<in> set_spmf p \\<Longrightarrow> interaction_bounded_by consider (f x) (n x))\n  \\<Longrightarrow> interaction_bounded_by consider (lift_spmf p \\<bind> f) (SUP x\\<in>set_spmf p. n x)\"\nby(auto intro: interaction_bounded_by_mono SUP_upper)\n\nlemma interaction_bounded_by_bind_DoneI [interaction_bound]:\n  \"interaction_bounded_by consider (f x) n \\<Longrightarrow> interaction_bounded_by consider (Done x \\<bind> f) n\"\nby(simp)\n\nlemma interaction_bounded_by_if [interaction_bound]:\n  \"\\<lbrakk> b \\<Longrightarrow> interaction_bounded_by consider gpv1 n; \\<not> b \\<Longrightarrow> interaction_bounded_by consider gpv2 m \\<rbrakk>\n  \\<Longrightarrow> interaction_bounded_by consider (if b then gpv1 else gpv2) (if b then n else m)\"\nby(auto 4 3 simp add: max_def not_le elim: interaction_bounded_by_mono)\n\nlemma interaction_bounded_by_case_bool [interaction_bound]:\n  \"\\<lbrakk> b \\<Longrightarrow> interaction_bounded_by consider t bt; \\<not> b \\<Longrightarrow> interaction_bounded_by consider f bf \\<rbrakk>\n  \\<Longrightarrow> interaction_bounded_by consider (case_bool t f b) (if b then bt else bf)\"\nby(cases b)(auto)\n\nlemma interaction_bounded_by_case_sum [interaction_bound]:\n  \"\\<lbrakk> \\<And>y. x = Inl y \\<Longrightarrow> interaction_bounded_by consider (l y) (bl y);\n     \\<And>y. x = Inr y \\<Longrightarrow> interaction_bounded_by consider (r y) (br y) \\<rbrakk>\n  \\<Longrightarrow> interaction_bounded_by consider (case_sum l r x) (case_sum bl br x)\"\nby(cases x)(auto)\n\nlemma interaction_bounded_by_case_prod [interaction_bound]:\n  \"(\\<And>a b. x = (a, b) \\<Longrightarrow> interaction_bounded_by consider (f a b) (n a b))\n  \\<Longrightarrow> interaction_bounded_by consider (case_prod f x) (case_prod n x)\"\nby(simp split: prod.split)\n\nlemma interaction_bounded_by_let [interaction_bound]: \\<comment> \\<open>This rule unfolds let's\\<close>\n  \"interaction_bounded_by consider (f t) m \\<Longrightarrow> interaction_bounded_by consider (Let t f) m\"\nby(simp add: Let_def)\n\nlemma interaction_bounded_by_map_gpv_id [interaction_bound]:\n  assumes [interaction_bound]: \"interaction_bounded_by P gpv n\"\n  shows \"interaction_bounded_by P (map_gpv f id gpv) n\"\nunfolding id_def map_gpv_conv_bind by interaction_bound simp\n\nabbreviation interaction_any_bounded_by :: \"('a, 'out, 'in) gpv \\<Rightarrow> enat \\<Rightarrow> bool\"\nwhere \"interaction_any_bounded_by \\<equiv> interaction_bounded_by (\\<lambda>_. True)\"\n\nsubsection \\<open>Typing\\<close>\n\nsubsubsection \\<open>Interface between gpvs and rpvs / callees\\<close>\n\nlemma is_empty_parametric [transfer_rule]: \"rel_fun (rel_set A) (=) Set.is_empty Set.is_empty\" (* Move *)\nby(auto simp add: rel_fun_def Set.is_empty_def dest: rel_setD1 rel_setD2)\n\ntypedef ('call, 'ret) \\<I> = \"UNIV :: ('call \\<Rightarrow> 'ret set) set\" ..\n\nsetup_lifting type_definition_\\<I>\n\nlemma outs_\\<I>_tparametric:\n  includes lifting_syntax \n  assumes [transfer_rule]: \"bi_total A\"\n  shows \"((A ===> rel_set B) ===> rel_set A) (\\<lambda>resps. {out. resps out \\<noteq> {}}) (\\<lambda>resps. {out. resps out \\<noteq> {}})\"\n  by(fold Set.is_empty_def) transfer_prover\n\nlift_definition outs_\\<I> :: \"('call, 'ret) \\<I> \\<Rightarrow> 'call set\" is \"\\<lambda>resps. {out. resps out \\<noteq> {}}\" parametric outs_\\<I>_tparametric .\nlift_definition responses_\\<I> :: \"('call, 'ret) \\<I> \\<Rightarrow> 'call \\<Rightarrow> 'ret set\" is \"\\<lambda>x. x\" parametric id_transfer[unfolded id_def] .\n\nlift_definition rel_\\<I> :: \"('call \\<Rightarrow> 'call' \\<Rightarrow> bool) \\<Rightarrow> ('ret \\<Rightarrow> 'ret' \\<Rightarrow> bool) \\<Rightarrow> ('call, 'ret) \\<I> \\<Rightarrow> ('call', 'ret') \\<I> \\<Rightarrow> bool\"\nis \"\\<lambda>C R resp1 resp2. rel_set C {out. resp1 out \\<noteq> {}} {out. resp2 out \\<noteq> {}} \\<and> rel_fun C (rel_set R) resp1 resp2\"\n.\n\nlemma rel_\\<I>I [intro?]:\n  \"\\<lbrakk> rel_set C (outs_\\<I> \\<I>1) (outs_\\<I> \\<I>2); \\<And>x y. C x y \\<Longrightarrow> rel_set R (responses_\\<I> \\<I>1 x) (responses_\\<I> \\<I>2 y) \\<rbrakk>\n  \\<Longrightarrow> rel_\\<I> C R \\<I>1 \\<I>2\"\nby transfer(auto simp add: rel_fun_def)\n\nlemma rel_\\<I>_eq [relator_eq]: \"rel_\\<I> (=) (=) = (=)\"\nunfolding fun_eq_iff by transfer(auto simp add: relator_eq)\n\nlemma rel_\\<I>_conversep [simp]: \"rel_\\<I> C\\<inverse>\\<inverse> R\\<inverse>\\<inverse> = (rel_\\<I> C R)\\<inverse>\\<inverse>\"\nunfolding fun_eq_iff conversep_iff\napply transfer\napply(rewrite in \"rel_fun \\<hole>\" conversep_iff[symmetric])\napply(rewrite in \"rel_set \\<hole>\" conversep_iff[symmetric])\napply(rewrite in \"rel_fun _ \\<hole>\" conversep_iff[symmetric])\napply(simp del: conversep_iff add: rel_fun_conversep)\napply(simp)\ndone\n\nlemma rel_\\<I>_conversep1_eq [simp]: \"rel_\\<I> C\\<inverse>\\<inverse> (=) = (rel_\\<I> C (=))\\<inverse>\\<inverse>\"\nby(rewrite in \"\\<hole> = _\" conversep_eq[symmetric])(simp del: conversep_eq)\n\nlemma rel_\\<I>_conversep2_eq [simp]: \"rel_\\<I> (=) R\\<inverse>\\<inverse> = (rel_\\<I> (=) R)\\<inverse>\\<inverse>\"\nby(rewrite in \"\\<hole> = _\" conversep_eq[symmetric])(simp del: conversep_eq)\n\nlemma responses_\\<I>_empty_iff: \"responses_\\<I> \\<I> out = {} \\<longleftrightarrow> out \\<notin> outs_\\<I> \\<I>\"\nincluding \\<I>.lifting by transfer auto\n\nlemma in_outs_\\<I>_iff_responses_\\<I>: \"out \\<in> outs_\\<I> \\<I> \\<longleftrightarrow> responses_\\<I> \\<I> out \\<noteq> {}\"\nby(simp add: responses_\\<I>_empty_iff)\n\nlift_definition \\<I>_full :: \"('call, 'ret) \\<I>\" is \"\\<lambda>_. UNIV\" .\n\nlemma \\<I>_full_sel [simp]:\n  shows outs_\\<I>_full: \"outs_\\<I> \\<I>_full = UNIV\"\n  and responses_\\<I>_full: \"responses_\\<I> \\<I>_full x = UNIV\"\nby(transfer; simp; fail)+\n\ncontext includes lifting_syntax begin\nlemma outs_\\<I>_parametric [transfer_rule]: \"(rel_\\<I> C R ===> rel_set C) outs_\\<I> outs_\\<I>\"\nunfolding rel_fun_def by transfer simp\n\nlemma responses_\\<I>_parametric [transfer_rule]: \n  \"(rel_\\<I> C R ===> C ===> rel_set R) responses_\\<I> responses_\\<I>\"\nunfolding rel_fun_def by transfer(auto dest: rel_funD)\n\nend\n\ndefinition \\<I>_trivial :: \"('out, 'in) \\<I> \\<Rightarrow> bool\"\nwhere \"\\<I>_trivial \\<I> \\<longleftrightarrow> outs_\\<I> \\<I> = UNIV\"\n\nlemma \\<I>_trivialI [intro?]: \"(\\<And>x. x \\<in> outs_\\<I> \\<I>) \\<Longrightarrow> \\<I>_trivial \\<I>\"\nby(auto simp add: \\<I>_trivial_def)\n\nlemma \\<I>_trivialD: \"\\<I>_trivial \\<I> \\<Longrightarrow> outs_\\<I> \\<I> = UNIV\"\nby(simp add: \\<I>_trivial_def)\n\nlemma \\<I>_trivial_\\<I>_full [simp]: \"\\<I>_trivial \\<I>_full\"\nby(simp add: \\<I>_trivial_def)\n\nlifting_update \\<I>.lifting\nlifting_forget \\<I>.lifting\n\n\ncontext begin\nqualified inductive resultsp_gpv :: \"('out, 'in) \\<I> \\<Rightarrow> 'a \\<Rightarrow> ('a, 'out, 'in) gpv \\<Rightarrow> bool\"\n  for \\<Gamma> x\nwhere\n  Pure: \"Pure x \\<in> set_spmf (the_gpv gpv) \\<Longrightarrow> resultsp_gpv \\<Gamma> x gpv\"\n| IO:\n  \"\\<lbrakk> IO out c \\<in> set_spmf (the_gpv gpv); input \\<in> responses_\\<I> \\<Gamma> out; resultsp_gpv \\<Gamma> x (c input) \\<rbrakk>\n  \\<Longrightarrow> resultsp_gpv \\<Gamma> x gpv\"\n\ndefinition results_gpv :: \"('out, 'in) \\<I> \\<Rightarrow> ('a, 'out, 'in) gpv \\<Rightarrow> 'a set\"\nwhere \"results_gpv \\<Gamma> gpv \\<equiv> {x. resultsp_gpv \\<Gamma> x gpv}\"\n\nlemma resultsp_gpv_results_gpv_eq [pred_set_conv]: \"resultsp_gpv \\<Gamma> x gpv \\<longleftrightarrow> x \\<in> results_gpv \\<Gamma> gpv\"\nby(simp add: results_gpv_def)\n\ncontext begin\nlocal_setup \\<open>Local_Theory.map_background_naming (Name_Space.mandatory_path \"results_gpv\")\\<close>\n\nlemmas intros [intro?] = resultsp_gpv.intros[to_set]\n  and Pure = Pure[to_set]\n  and IO = IO[to_set]\n  and induct [consumes 1, case_names Pure IO, induct set: results_gpv] = resultsp_gpv.induct[to_set]\n  and cases [consumes 1, case_names Pure IO, cases set: results_gpv] = resultsp_gpv.cases[to_set]\n  and simps = resultsp_gpv.simps[to_set]\nend\n\ninductive_simps results_gpv_GPV [to_set, simp]: \"resultsp_gpv \\<Gamma> x (GPV gpv)\"\n\nend\n\nlemma results_gpv_Done [iff]: \"results_gpv \\<Gamma> (Done x) = {x}\"\nby(auto simp add: Done.ctr)\n\nlemma results_gpv_Fail [iff]: \"results_gpv \\<Gamma> Fail = {}\"\nby(auto simp add: Fail_def)\n\nlemma results_gpv_Pause [simp]:\n  \"results_gpv \\<Gamma> (Pause out c) = (\\<Union>input\\<in>responses_\\<I> \\<Gamma> out. results_gpv \\<Gamma> (c input))\"\nby(auto simp add: Pause.ctr)\n\nlemma results_gpv_lift_spmf [iff]: \"results_gpv \\<Gamma> (lift_spmf p) = set_spmf p\"\nby(auto simp add: lift_spmf.ctr)\n\nlemma results_gpv_assert_gpv [simp]: \"results_gpv \\<Gamma> (assert_gpv b) = (if b then {()} else {})\"\nby auto\n\nlemma results_gpv_bind_gpv [simp]:\n  \"results_gpv \\<Gamma> (gpv \\<bind> f) = (\\<Union>x\\<in>results_gpv \\<Gamma> gpv. results_gpv \\<Gamma> (f x))\"\n  (is \"?lhs = ?rhs\")\nproof(intro set_eqI iffI)\n  fix x\n  assume \"x \\<in> ?lhs\"\n  then show \"x \\<in> ?rhs\"\n  proof(induction gpv'\\<equiv>\"gpv \\<bind> f\" arbitrary: gpv)\n    case Pure thus ?case\n      by(auto 4 3 split: if_split_asm intro: results_gpv.intros rev_bexI)\n  next\n    case (IO out c input)\n    from \\<open>IO out c \\<in> _\\<close>\n    obtain generat where generat: \"generat \\<in> set_spmf (the_gpv gpv)\"\n      and *: \"IO out c \\<in> set_spmf (if is_Pure generat then the_gpv (f (result generat))\n                                   else return_spmf (IO (output generat) (\\<lambda>input. continuation generat input \\<bind> f)))\"\n      by(auto)\n    thus ?case\n    proof(cases generat)\n      case (Pure y)\n      with generat have \"y \\<in> results_gpv \\<Gamma> gpv\" by(auto intro: results_gpv.intros)\n      thus ?thesis using * Pure \\<open>input \\<in> responses_\\<I> \\<Gamma> out\\<close> \\<open>x \\<in> results_gpv \\<Gamma> (c input)\\<close>\n        by(auto intro: results_gpv.IO)\n    next\n      case (IO out' c')\n      hence [simp]: \"out' = out\"\n        and c: \"\\<And>input. c input = bind_gpv (c' input) f\" using * by simp_all\n      from IO.hyps(4)[OF c] obtain y where y: \"y \\<in> results_gpv \\<Gamma> (c' input)\"\n        and \"x \\<in> results_gpv \\<Gamma> (f y)\" by blast\n      from y IO generat have \"y \\<in> results_gpv \\<Gamma> gpv\" using \\<open>input \\<in> responses_\\<I> \\<Gamma> out\\<close>\n        by(auto intro: results_gpv.IO)\n      with \\<open>x \\<in> results_gpv \\<Gamma> (f y)\\<close> show ?thesis by blast\n    qed\n  qed\nnext\n  fix x\n  assume \"x \\<in> ?rhs\"\n  then obtain y where y: \"y \\<in> results_gpv \\<Gamma> gpv\"\n    and x: \"x \\<in> results_gpv \\<Gamma> (f y)\" by blast\n  from y show \"x \\<in> ?lhs\"\n  proof(induction)\n    case (Pure gpv)\n    with x show ?case\n      by cases(auto 4 4 intro: results_gpv.intros rev_bexI)\n  qed(auto 4 4 intro: rev_bexI results_gpv.IO)\nqed\n\nlemma results_gpv_\\<I>_full: \"results_gpv \\<I>_full = results'_gpv\"\nproof(intro ext set_eqI iffI)\n  show \"x \\<in> results'_gpv gpv\" if \"x \\<in> results_gpv \\<I>_full gpv\" for x gpv\n    using that by induction(auto intro: results'_gpvI)\n  show \"x \\<in> results_gpv \\<I>_full gpv\" if \"x \\<in> results'_gpv gpv\" for x gpv\n    using that by induction(auto intro: results_gpv.intros elim!: generat.set_cases)\nqed\n\nlemma results'_bind_gpv [simp]:\n  \"results'_gpv (bind_gpv gpv f) = (\\<Union>x\\<in>results'_gpv gpv. results'_gpv (f x))\"\nunfolding results_gpv_\\<I>_full[symmetric] by simp\n\nlemma results_gpv_map_gpv_id [simp]: \"results_gpv \\<I> (map_gpv f id gpv) = f ` results_gpv \\<I> gpv\"\n  by(auto simp add: map_gpv_conv_bind id_def)\n\nlemma results_gpv_map_gpv_id' [simp]: \"results_gpv \\<I> (map_gpv f (\\<lambda>x. x) gpv) = f ` results_gpv \\<I> gpv\"\n  by(auto simp add: map_gpv_conv_bind id_def)\n\nlemma pred_gpv_bind [simp]: \"pred_gpv P Q (bind_gpv gpv f) = pred_gpv (pred_gpv P Q \\<circ> f) Q gpv\"\nby(auto simp add: pred_gpv_def outs_bind_gpv)\n\nlemma results'_gpv_bind_option [simp]:\n  \"results'_gpv (monad.bind_option Fail x f) = (\\<Union>y\\<in>set_option x. results'_gpv (f y))\"\nby(cases x) simp_all\n\nlemma bind_gpv_bind_option_assoc:\n  \"bind_gpv (monad.bind_option Fail x f) g = monad.bind_option Fail x (\\<lambda>x. bind_gpv (f x) g)\"\nby(cases x) simp_all\n\nsubsubsection \\<open>Type judgements\\<close>\n\ncoinductive WT_gpv :: \"('out, 'in) \\<I> \\<Rightarrow> ('a, 'out, 'in) gpv \\<Rightarrow> bool\" (\"((_)/ \\<turnstile>g (_) \\<surd>)\" [100, 0] 99)\n  for \\<Gamma>\nwhere\n  \"(\\<And>out c. IO out c \\<in> set_spmf gpv \\<Longrightarrow> out \\<in> outs_\\<I> \\<Gamma> \\<and> (\\<forall>input\\<in>responses_\\<I> \\<Gamma> out. \\<Gamma> \\<turnstile>g c input \\<surd>))\n  \\<Longrightarrow> \\<Gamma> \\<turnstile>g GPV gpv \\<surd>\"\n\nlemma WT_gpv_coinduct [consumes 1, case_names WT_gpv, case_conclusion WT_gpv out cont, coinduct pred: WT_gpv]:\n  assumes *: \"X gpv\"\n  and step: \"\\<And>gpv out c.\n    \\<lbrakk> X gpv; IO out c \\<in> set_spmf (the_gpv gpv) \\<rbrakk>\n    \\<Longrightarrow> out \\<in> outs_\\<I> \\<Gamma> \\<and> (\\<forall>input \\<in> responses_\\<I> \\<Gamma> out. X (c input) \\<or> \\<Gamma> \\<turnstile>g c input \\<surd>)\"\n  shows \"\\<Gamma> \\<turnstile>g gpv \\<surd>\"\nusing * by(coinduct)(auto dest: step simp add: eq_GPV_iff)\n\nlemma WT_gpv_simps:\n  \"\\<Gamma> \\<turnstile>g GPV gpv \\<surd> \\<longleftrightarrow>\n   (\\<forall>out c. IO out c \\<in> set_spmf gpv \\<longrightarrow> out \\<in> outs_\\<I> \\<Gamma> \\<and> (\\<forall>input\\<in>responses_\\<I> \\<Gamma> out. \\<Gamma> \\<turnstile>g c input \\<surd>))\"\nby(subst WT_gpv.simps) simp\n\nlemma WT_gpvI:\n  \"(\\<And>out c. IO out c \\<in> set_spmf (the_gpv gpv) \\<Longrightarrow> out \\<in> outs_\\<I> \\<Gamma> \\<and> (\\<forall>input\\<in>responses_\\<I> \\<Gamma> out. \\<Gamma> \\<turnstile>g c input \\<surd>))\n  \\<Longrightarrow> \\<Gamma> \\<turnstile>g gpv \\<surd>\"\nby(cases gpv)(simp add: WT_gpv_simps)\n\nlemma WT_gpvD:\n  assumes \"\\<Gamma> \\<turnstile>g gpv \\<surd>\"\n  shows WT_gpv_OutD: \"IO out c \\<in> set_spmf (the_gpv gpv) \\<Longrightarrow> out \\<in> outs_\\<I> \\<Gamma>\"\n  and WT_gpv_ContD: \"\\<lbrakk> IO out c \\<in> set_spmf (the_gpv gpv); input \\<in> responses_\\<I> \\<Gamma> out \\<rbrakk> \\<Longrightarrow> \\<Gamma> \\<turnstile>g c input \\<surd>\"\nusing assms by(cases, fastforce)+\n\nlemma WT_gpv_mono:\n  assumes WT: \"\\<I>1 \\<turnstile>g gpv \\<surd>\"\n  and outs: \"outs_\\<I> \\<I>1 \\<subseteq> outs_\\<I> \\<I>2\"\n  and responses: \"\\<And>x. x \\<in> outs_\\<I> \\<I>1 \\<Longrightarrow> responses_\\<I> \\<I>2 x \\<subseteq> responses_\\<I> \\<I>1 x\"\n  shows \"\\<I>2 \\<turnstile>g gpv \\<surd>\"\nusing WT\nproof coinduct\n  case (WT_gpv gpv out c)\n  with outs show ?case by(auto 6 4 dest: responses WT_gpvD)\nqed\n\nlemma WT_gpv_Done [iff]: \"\\<Gamma> \\<turnstile>g Done x \\<surd>\"\nby(rule WT_gpvI) simp_all\n\nlemma WT_gpv_Fail [iff]: \"\\<Gamma> \\<turnstile>g Fail \\<surd>\"\nby(rule WT_gpvI) simp_all\n\nlemma WT_gpv_PauseI: \n  \"\\<lbrakk> out \\<in> outs_\\<I> \\<Gamma>; \\<And>input. input \\<in> responses_\\<I> \\<Gamma> out \\<Longrightarrow> \\<Gamma> \\<turnstile>g c input \\<surd> \\<rbrakk>\n   \\<Longrightarrow> \\<Gamma> \\<turnstile>g Pause out c \\<surd>\"\nby(rule WT_gpvI) simp_all\n\nlemma WT_gpv_Pause [iff]:\n  \"\\<Gamma> \\<turnstile>g Pause out c \\<surd> \\<longleftrightarrow> out \\<in> outs_\\<I> \\<Gamma> \\<and> (\\<forall>input \\<in> responses_\\<I> \\<Gamma> out. \\<Gamma> \\<turnstile>g c input \\<surd>)\"\nby(auto intro: WT_gpv_PauseI dest: WT_gpvD)\n\nlemma WT_gpv_bindI:\n  \"\\<lbrakk> \\<Gamma> \\<turnstile>g gpv \\<surd>; \\<And>x. x \\<in> results_gpv \\<Gamma> gpv \\<Longrightarrow> \\<Gamma> \\<turnstile>g f x \\<surd> \\<rbrakk>\n  \\<Longrightarrow> \\<Gamma> \\<turnstile>g gpv \\<bind> f \\<surd>\"\nproof(coinduction arbitrary: gpv)\n  case [rule_format]: (WT_gpv out c gpv)\n  from \\<open>IO out c \\<in> _\\<close>\n  obtain generat where generat: \"generat \\<in> set_spmf (the_gpv gpv)\"\n    and *: \"IO out c \\<in> set_spmf (if is_Pure generat then the_gpv (f (result generat))\n                                 else return_spmf (IO (output generat) (\\<lambda>input. continuation generat input \\<bind> f)))\"\n    by(auto)\n  show ?case\n  proof(cases generat)\n    case (Pure y)\n    with generat have \"y \\<in> results_gpv \\<Gamma> gpv\" by(auto intro: results_gpv.Pure)\n    hence \"\\<Gamma> \\<turnstile>g f y \\<surd>\" by(rule WT_gpv)\n    with * Pure show ?thesis by(auto dest: WT_gpvD) \n  next\n    case (IO out' c')\n    hence [simp]: \"out' = out\"\n      and c: \"\\<And>input. c input = bind_gpv (c' input) f\" using * by simp_all\n    from generat IO have **: \"IO out c' \\<in> set_spmf (the_gpv gpv)\" by simp\n    with \\<open>\\<Gamma> \\<turnstile>g gpv \\<surd>\\<close> have ?out by(auto dest: WT_gpvD)\n    moreover {\n      fix input\n      assume input: \"input \\<in> responses_\\<I> \\<Gamma> out\"\n      with \\<open>\\<Gamma> \\<turnstile>g gpv \\<surd>\\<close> ** have \"\\<Gamma> \\<turnstile>g c' input \\<surd>\" by(rule WT_gpvD)\n      moreover {\n        fix y\n        assume \"y \\<in> results_gpv \\<Gamma> (c' input)\"\n        with ** input have \"y \\<in> results_gpv \\<Gamma> gpv\" by(rule results_gpv.IO)\n        hence \"\\<Gamma> \\<turnstile>g f y \\<surd>\" by(rule WT_gpv) }\n      moreover note calculation }\n    hence ?cont using c by blast\n    ultimately show ?thesis ..\n  qed\nqed\n\nlemma WT_gpv_bindD2:\n  assumes WT: \"\\<Gamma> \\<turnstile>g gpv \\<bind> f \\<surd>\"\n  and x: \"x \\<in> results_gpv \\<Gamma> gpv\"\n  shows \"\\<Gamma> \\<turnstile>g f x \\<surd>\"\nusing x WT\nproof induction\n  case (Pure gpv)\n  show ?case\n  proof(rule WT_gpvI)\n    fix out c\n    assume \"IO out c \\<in> set_spmf (the_gpv (f x))\"\n    with Pure have \"IO out c \\<in> set_spmf (the_gpv (gpv \\<bind> f))\" by(auto intro: rev_bexI)\n    with \\<open>\\<Gamma> \\<turnstile>g gpv \\<bind> f \\<surd>\\<close> show \"out \\<in> outs_\\<I> \\<Gamma> \\<and> (\\<forall>input\\<in>responses_\\<I> \\<Gamma> out. \\<Gamma> \\<turnstile>g c input \\<surd>)\"\n      by(auto dest: WT_gpvD simp del: set_bind_spmf)\n  qed\nnext\n  case (IO out c gpv input)\n  from \\<open>IO out c \\<in> _\\<close>\n  have \"IO out (\\<lambda>input. bind_gpv (c input) f) \\<in> set_spmf (the_gpv (gpv \\<bind> f))\"\n    by(auto intro: rev_bexI)\n  with IO.prems have \"\\<Gamma> \\<turnstile>g c input \\<bind> f \\<surd>\" using \\<open>input \\<in> _\\<close> by(rule WT_gpv_ContD)\n  thus ?case by(rule IO.IH)\nqed\n\nlemma WT_gpv_bindD1: \"\\<Gamma> \\<turnstile>g gpv \\<bind> f \\<surd> \\<Longrightarrow> \\<Gamma> \\<turnstile>g gpv \\<surd>\"\nproof(coinduction arbitrary: gpv)\n  case (WT_gpv out c gpv)\n  from \\<open>IO out c \\<in> _\\<close>\n  have \"IO out (\\<lambda>input. bind_gpv (c input) f) \\<in> set_spmf (the_gpv (gpv \\<bind> f))\"\n    by(auto intro: rev_bexI)\n  with \\<open>\\<Gamma> \\<turnstile>g gpv \\<bind> f \\<surd>\\<close> show ?case\n    by(auto simp del: bind_gpv_sel' dest: WT_gpvD)\nqed\n\nlemma WT_gpv_bind [simp]: \"\\<Gamma> \\<turnstile>g gpv \\<bind> f \\<surd> \\<longleftrightarrow> \\<Gamma> \\<turnstile>g gpv \\<surd> \\<and> (\\<forall>x\\<in>results_gpv \\<Gamma> gpv. \\<Gamma> \\<turnstile>g f x \\<surd>)\"\nby(blast intro: WT_gpv_bindI dest: WT_gpv_bindD1 WT_gpv_bindD2)\n\nlemma WT_gpv_full [simp, intro!]: \"\\<I>_full \\<turnstile>g gpv \\<surd>\"\nby(coinduction arbitrary: gpv)(auto)\n\nlemma WT_gpv_lift_spmf [simp, intro!]: \"\\<I> \\<turnstile>g lift_spmf p \\<surd>\"\nby(rule WT_gpvI) auto\n\nlemma WT_gpv_coinduct_bind [consumes 1, case_names WT_gpv, case_conclusion WT_gpv out cont]:\n  assumes *: \"X gpv\"\n  and step: \"\\<And>gpv out c. \\<lbrakk> X gpv; IO out c \\<in> set_spmf (the_gpv gpv) \\<rbrakk>\n    \\<Longrightarrow> out \\<in> outs_\\<I> \\<I> \\<and> (\\<forall>input\\<in>responses_\\<I> \\<I> out.\n            X (c input) \\<or>\n            \\<I> \\<turnstile>g c input \\<surd> \\<or>\n            (\\<exists>(gpv' :: ('b, 'call, 'ret) gpv) f. c input = gpv' \\<bind> f \\<and> \\<I> \\<turnstile>g gpv' \\<surd> \\<and> (\\<forall>x\\<in>results_gpv \\<I> gpv'. X (f x))))\"\n  shows \"\\<I> \\<turnstile>g gpv \\<surd>\"\nproof -\n  fix x\n  define gpv' :: \"('b, 'call, 'ret) gpv\" and f :: \"'b \\<Rightarrow> ('a, 'call, 'ret) gpv\"\n    where \"gpv' = Done x\" and \"f = (\\<lambda>_. gpv)\"\n  with * have \"\\<I> \\<turnstile>g gpv' \\<surd>\" and \"\\<And>x. x \\<in> results_gpv \\<I> gpv' \\<Longrightarrow> X (f x)\" by simp_all\n  then have \"\\<I> \\<turnstile>g gpv' \\<bind> f \\<surd>\"\n  proof(coinduction arbitrary: gpv' f rule: WT_gpv_coinduct)\n    case [rule_format]: (WT_gpv out c gpv')\n    from \\<open>IO out c \\<in> _\\<close>\n    obtain generat where generat: \"generat \\<in> set_spmf (the_gpv gpv')\"\n      and *: \"IO out c \\<in> set_spmf (if is_Pure generat\n        then the_gpv (f (result generat))\n        else return_spmf (IO (output generat) (\\<lambda>input. continuation generat input \\<bind> f)))\"\n      by(clarsimp)\n    show ?case\n    proof(cases generat)\n      case (Pure x)\n      from Pure * have IO: \"IO out c \\<in> set_spmf (the_gpv (f x))\" by simp\n      from generat Pure have \"x \\<in> results_gpv \\<I> gpv'\" by (simp add: results_gpv.Pure)\n      then have \"X (f x)\" by(rule WT_gpv)\n      from step[OF this IO] show ?thesis by(auto 4 4 intro: exI[where x=\"Done _\"])\n    next\n      case (IO out' c')\n      with * have [simp]: \"out' = out\"\n        and c: \"c = (\\<lambda>input. c' input \\<bind> f)\" by simp_all\n      from IO generat have IO: \"IO out c' \\<in> set_spmf (the_gpv gpv')\" by simp\n      then have \"\\<And>input. input \\<in> responses_\\<I> \\<I> out \\<Longrightarrow> results_gpv \\<I> (c' input) \\<subseteq> results_gpv \\<I> gpv'\"\n        by(auto intro: results_gpv.IO)\n      with WT_gpvD[OF \\<open>\\<I> \\<turnstile>g gpv' \\<surd>\\<close> IO] show ?thesis unfolding c using WT_gpv(2) by blast\n    qed\n  qed\n  then show ?thesis unfolding gpv'_def f_def by simp\nqed\n\nlemma \\<I>_trivial_WT_gpvD [simp]: \"\\<I>_trivial \\<I> \\<Longrightarrow> \\<I> \\<turnstile>g gpv \\<surd>\"\nusing WT_gpv_full by(rule WT_gpv_mono)(simp_all add: \\<I>_trivial_def)\n\nlemma \\<I>_trivial_WT_gpvI: \n  assumes \"\\<And>gpv :: ('a, 'out, 'in) gpv. \\<I> \\<turnstile>g gpv \\<surd>\"\n  shows \"\\<I>_trivial \\<I>\"\nproof\n  fix x\n  have \"\\<I> \\<turnstile>g Pause x (\\<lambda>_. Fail :: ('a, 'out, 'in) gpv) \\<surd>\" by(rule assms)\n  thus \"x \\<in> outs_\\<I> \\<I>\" by(simp)\nqed\n\nsubsection \\<open>Sub-gpvs\\<close>\n\ncontext begin\nqualified inductive sub_gpvsp :: \"('out, 'in) \\<I> \\<Rightarrow> ('a, 'out, 'in) gpv \\<Rightarrow> ('a, 'out, 'in) gpv \\<Rightarrow> bool\"\n  for \\<I> x\nwhere\n  base:\n  \"\\<lbrakk> IO out c \\<in> set_spmf (the_gpv gpv); input \\<in> responses_\\<I> \\<I> out; x = c input \\<rbrakk> \n  \\<Longrightarrow> sub_gpvsp \\<I> x gpv\"\n| cont: \n  \"\\<lbrakk> IO out c \\<in> set_spmf (the_gpv gpv); input \\<in> responses_\\<I> \\<I> out; sub_gpvsp \\<I> x (c input) \\<rbrakk>\n  \\<Longrightarrow> sub_gpvsp \\<I> x gpv\"\n\nqualified lemma sub_gpvsp_base:\n  \"\\<lbrakk> IO out c \\<in> set_spmf (the_gpv gpv); input \\<in> responses_\\<I> \\<I> out \\<rbrakk> \n  \\<Longrightarrow> sub_gpvsp \\<I> (c input) gpv\"\nby(rule base) simp_all\n\ndefinition sub_gpvs :: \"('out, 'in) \\<I> \\<Rightarrow>  ('a, 'out, 'in) gpv \\<Rightarrow> ('a, 'out, 'in) gpv set\"\nwhere \"sub_gpvs \\<I> gpv \\<equiv> {x. sub_gpvsp \\<I> x gpv}\"\n\nlemma sub_gpvsp_sub_gpvs_eq [pred_set_conv]: \"sub_gpvsp \\<I> x gpv \\<longleftrightarrow> x \\<in> sub_gpvs \\<I> gpv\"\nby(simp add: sub_gpvs_def)\n\ncontext begin\nlocal_setup \\<open>Local_Theory.map_background_naming (Name_Space.mandatory_path \"sub_gpvs\")\\<close>\n\nlemmas intros [intro?] = sub_gpvsp.intros[to_set]\n  and base = sub_gpvsp_base[to_set]\n  and cont = cont[to_set]\n  and induct [consumes 1, case_names Pure IO, induct set: sub_gpvs] = sub_gpvsp.induct[to_set]\n  and cases [consumes 1, case_names Pure IO, cases set: sub_gpvs] = sub_gpvsp.cases[to_set]\n  and simps = sub_gpvsp.simps[to_set]\nend\nend\n\nlemma WT_sub_gpvsD:\n  assumes \"\\<I> \\<turnstile>g gpv \\<surd>\" and \"gpv' \\<in> sub_gpvs \\<I> gpv\"\n  shows \"\\<I> \\<turnstile>g gpv' \\<surd>\"\nusing assms(2,1) by(induction)(auto dest: WT_gpvD)\n\nlemma WT_sub_gpvsI:\n  \"\\<lbrakk> \\<And>out c. IO out c \\<in> set_spmf (the_gpv gpv) \\<Longrightarrow> out \\<in> outs_\\<I> \\<Gamma>; \n     \\<And>gpv'. gpv' \\<in> sub_gpvs \\<Gamma> gpv \\<Longrightarrow> \\<Gamma> \\<turnstile>g gpv' \\<surd> \\<rbrakk>\n  \\<Longrightarrow> \\<Gamma> \\<turnstile>g gpv \\<surd>\"\nby(rule WT_gpvI)(auto intro: sub_gpvs.base)\n\nsubsection \\<open>Losslessness\\<close>\n\ntext \\<open>A gpv is lossless iff we are guaranteed to get a result after a finite number of interactions\n  that respect the interface. It is colossless if the interactions may go on for ever, but there is\n  no non-termination.\\<close>\n\ntext \\<open> We define both notions of losslessness simultaneously by mimicking what the (co)inductive\n  package would do internally. Thus, we get a constant which is parametrised by the choice of the\n  fixpoint, i.e., for non-recursive gpvs, we can state and prove both versions of losslessness\n  in one go.\\<close>\n\ncontext\n  fixes co :: bool and \\<I> :: \"('out, 'in) \\<I>\"\n  and F :: \"(('a, 'out, 'in) gpv \\<Rightarrow> bool) \\<Rightarrow> (('a, 'out, 'in) gpv \\<Rightarrow> bool)\"\n  and co' :: bool\n  defines \"F \\<equiv> \\<lambda>gen_lossless_gpv gpv. \\<exists>pa. gpv = GPV pa \\<and> \n     lossless_spmf pa \\<and> (\\<forall>out c input. IO out c \\<in> set_spmf pa \\<longrightarrow> input \\<in> responses_\\<I> \\<I> out \\<longrightarrow> gen_lossless_gpv (c input))\"\n  and \"co' \\<equiv> co\" \\<comment> \\<open>We use a copy of @{term co} such that we can do case distinctions on @{term co'} without\n    the simplifier rewriting the @{term co} in the local abbreviations for the constants.\\<close>\nbegin\n\nlemma gen_lossless_gpv_mono: \"mono F\"\nunfolding F_def\napply(rule monoI le_funI le_boolI')+\napply(tactic \\<open>REPEAT (resolve_tac @{context} (Inductive.get_monos @{context}) 1)\\<close>)\napply(erule le_funE)\napply(erule le_boolD)\ndone\n\ndefinition gen_lossless_gpv :: \"('a, 'out, 'in) gpv \\<Rightarrow> bool\"\nwhere \"gen_lossless_gpv = (if co' then gfp else lfp) F\"\n\nlemma gen_lossless_gpv_unfold: \"gen_lossless_gpv = F gen_lossless_gpv\"\nby(simp add: gen_lossless_gpv_def gfp_unfold[OF gen_lossless_gpv_mono, symmetric] lfp_unfold[OF gen_lossless_gpv_mono, symmetric])\n\nlemma gen_lossless_gpv_True: \"co' = True \\<Longrightarrow> gen_lossless_gpv \\<equiv> gfp F\"\n  and gen_lossless_gpv_False: \"co' = False \\<Longrightarrow> gen_lossless_gpv \\<equiv> lfp F\"\nby(simp_all add: gen_lossless_gpv_def)\n\nlemma gen_lossless_gpv_cases [elim?, cases pred]:\n  assumes \"gen_lossless_gpv gpv\"\n  obtains (gen_lossless_gpv) p where \"gpv = GPV p\" \"lossless_spmf p\" \n    \"\\<And>out c input. \\<lbrakk>IO out c \\<in> set_spmf p; input \\<in> responses_\\<I> \\<I> out\\<rbrakk> \\<Longrightarrow> gen_lossless_gpv (c input)\"\nproof -\n  from assms show ?thesis\n    by(rewrite in asm gen_lossless_gpv_unfold)(auto simp add: F_def intro: that)\nqed\n\nlemma gen_lossless_gpvD:\n  assumes \"gen_lossless_gpv gpv\"\n  shows gen_lossless_gpv_lossless_spmfD: \"lossless_spmf (the_gpv gpv)\"\n  and gen_lossless_gpv_continuationD:\n  \"\\<lbrakk> IO out c \\<in> set_spmf (the_gpv gpv); input \\<in> responses_\\<I> \\<I> out \\<rbrakk> \\<Longrightarrow> gen_lossless_gpv (c input)\"\nusing assms by(auto elim: gen_lossless_gpv_cases)\n\nlemma gen_lossless_gpv_intros:\n  \"\\<lbrakk> lossless_spmf p;\n     \\<And>out c input. \\<lbrakk>IO out c \\<in> set_spmf p; input \\<in> responses_\\<I> \\<I> out \\<rbrakk> \\<Longrightarrow> gen_lossless_gpv (c input) \\<rbrakk>\n  \\<Longrightarrow> gen_lossless_gpv (GPV p)\"\nby(rewrite gen_lossless_gpv_unfold)(simp add: F_def)\n\nlemma gen_lossless_gpvI [intro?]:\n  \"\\<lbrakk> lossless_spmf (the_gpv gpv);\n     \\<And>out c input. \\<lbrakk> IO out c \\<in> set_spmf (the_gpv gpv); input \\<in> responses_\\<I> \\<I> out \\<rbrakk>\n     \\<Longrightarrow> gen_lossless_gpv (c input) \\<rbrakk>\n  \\<Longrightarrow> gen_lossless_gpv gpv\"\nby(cases gpv)(auto intro: gen_lossless_gpv_intros)\n\nlemma gen_lossless_gpv_simps:\n  \"gen_lossless_gpv gpv \\<longleftrightarrow>\n   (\\<exists>p. gpv = GPV p \\<and> lossless_spmf p \\<and> (\\<forall>out c input.\n        IO out c \\<in> set_spmf p \\<longrightarrow> input \\<in> responses_\\<I> \\<I> out \\<longrightarrow> gen_lossless_gpv (c input)))\"\nby(rewrite gen_lossless_gpv_unfold)(simp add: F_def)\n\nlemma gen_lossless_gpv_Done [iff]: \"gen_lossless_gpv (Done x)\"\nby(rule gen_lossless_gpvI) auto\n\nlemma gen_lossless_gpv_Fail [iff]: \"\\<not> gen_lossless_gpv Fail\"\nby(auto dest: gen_lossless_gpvD)\n\nlemma gen_lossless_gpv_Pause [simp]:\n  \"gen_lossless_gpv (Pause out c) \\<longleftrightarrow> (\\<forall>input \\<in> responses_\\<I> \\<I> out. gen_lossless_gpv (c input))\"\nby(auto dest: gen_lossless_gpvD intro: gen_lossless_gpvI)\n\nlemma gen_lossless_gpv_lift_spmf [iff]: \"gen_lossless_gpv (lift_spmf p) \\<longleftrightarrow> lossless_spmf p\"\nby(auto dest: gen_lossless_gpvD intro: gen_lossless_gpvI)\n\nend\n\nlemma gen_lossless_gpv_assert_gpv [iff]: \"gen_lossless_gpv co \\<I> (assert_gpv b) \\<longleftrightarrow> b\"\nby(cases b) simp_all\n\nabbreviation lossless_gpv :: \"('out, 'in) \\<I> \\<Rightarrow> ('a, 'out, 'in) gpv \\<Rightarrow> bool\"\nwhere \"lossless_gpv \\<equiv> gen_lossless_gpv False\"\n\nabbreviation colossless_gpv :: \"('out, 'in) \\<I> \\<Rightarrow> ('a, 'out, 'in) gpv \\<Rightarrow> bool\"\nwhere \"colossless_gpv \\<equiv> gen_lossless_gpv True\"\n\nlemma lossless_gpv_induct [consumes 1, case_names lossless_gpv, induct pred]:\n  assumes *: \"lossless_gpv \\<I> gpv\"\n  and step: \"\\<And>p. \\<lbrakk> lossless_spmf p;\n     \\<And>out c input. \\<lbrakk>IO out c \\<in> set_spmf p; input \\<in> responses_\\<I> \\<I> out\\<rbrakk> \\<Longrightarrow> lossless_gpv \\<I> (c input);\n     \\<And>out c input. \\<lbrakk>IO out c \\<in> set_spmf p; input \\<in> responses_\\<I> \\<I> out\\<rbrakk> \\<Longrightarrow> P (c input) \\<rbrakk>\n     \\<Longrightarrow> P (GPV p)\"\n  shows \"P gpv\"\nproof -\n  have \"lossless_gpv \\<I> \\<le> P\"\n    by(rule def_lfp_induct[OF gen_lossless_gpv_False gen_lossless_gpv_mono])(auto intro!: le_funI step)\n  then show ?thesis using * by auto\nqed\n\nlemma colossless_gpv_coinduct \n  [consumes 1, case_names colossless_gpv, case_conclusion colossless_gpv lossless_spmf continuation, coinduct pred]:\n  assumes *: \"X gpv\"\n  and step: \"\\<And>gpv. X gpv \\<Longrightarrow> lossless_spmf (the_gpv gpv) \\<and> (\\<forall>out c input. \n       IO out c \\<in> set_spmf (the_gpv gpv) \\<longrightarrow> input \\<in> responses_\\<I> \\<I> out \\<longrightarrow> X (c input) \\<or> colossless_gpv \\<I> (c input))\"\n  shows \"colossless_gpv \\<I> gpv\"\nproof -\n  have \"X \\<le> colossless_gpv \\<I>\"\n    by(rule def_coinduct[OF gen_lossless_gpv_True gen_lossless_gpv_mono])\n      (auto 4 4 intro!: le_funI dest!: step intro: exI[where x=\"the_gpv _\"])\n  then show ?thesis using * by auto\nqed\n\nlemmas lossless_gpvI = gen_lossless_gpvI[where co=False]\n  and lossless_gpvD = gen_lossless_gpvD[where co=False]\n  and lossless_gpv_lossless_spmfD = gen_lossless_gpv_lossless_spmfD[where co=False]\n  and lossless_gpv_continuationD = gen_lossless_gpv_continuationD[where co=False]\n\nlemmas colossless_gpvI = gen_lossless_gpvI[where co=True]\n  and colossless_gpvD = gen_lossless_gpvD[where co=True]\n  and colossless_gpv_lossless_spmfD = gen_lossless_gpv_lossless_spmfD[where co=True]\n  and colossless_gpv_continuationD = gen_lossless_gpv_continuationD[where co=True]\n\nlemma gen_lossless_bind_gpvI:\n  assumes \"gen_lossless_gpv co \\<I> gpv\" \"\\<And>x. x \\<in> results_gpv \\<I> gpv \\<Longrightarrow> gen_lossless_gpv co \\<I> (f x)\"\n  shows \"gen_lossless_gpv co \\<I> (gpv \\<bind> f)\"\nproof(cases co)\n  case False\n  hence eq: \"co = False\" by simp\n  show ?thesis using assms unfolding eq\n  proof(induction)\n    case (lossless_gpv p)\n    { fix x\n      assume \"Pure x \\<in> set_spmf p\"\n      hence \"x \\<in> results_gpv \\<I> (GPV p)\" by simp\n      hence \"lossless_gpv \\<I> (f x)\" by(rule lossless_gpv.prems) }\n    with \\<open>lossless_spmf p\\<close> show ?case unfolding GPV_bind\n      apply(intro gen_lossless_gpv_intros)\n       apply(fastforce dest: lossless_gpvD split: generat.split)\n      apply(clarsimp; split generat.split_asm)\n      apply(auto dest: lossless_gpvD intro!: lossless_gpv)\n      done\n  qed\nnext\n  case True\n  hence eq: \"co = True\" by simp\n  show ?thesis using assms unfolding eq\n  proof(coinduction arbitrary: gpv rule: colossless_gpv_coinduct)\n    case * [rule_format]: (colossless_gpv gpv)\n    from *(1) have ?lossless_spmf \n      by(auto 4 3 dest: colossless_gpv_lossless_spmfD elim!: is_PureE intro: *(2)[THEN colossless_gpv_lossless_spmfD] results_gpv.Pure)\n    moreover have ?continuation\n    proof(intro strip)\n      fix out c input\n      assume IO: \"IO out c \\<in> set_spmf (the_gpv (gpv \\<bind> f))\"\n        and input: \"input \\<in> responses_\\<I> \\<I> out\"\n      from IO obtain generat where generat: \"generat \\<in> set_spmf (the_gpv gpv)\"\n        and IO: \"IO out c \\<in> set_spmf (if is_Pure generat then the_gpv (f (result generat))\n                 else return_spmf (IO (output generat) (\\<lambda>input. continuation generat input \\<bind> f)))\"\n        by(auto)\n      show \"(\\<exists>gpv. c input = gpv \\<bind> f \\<and> colossless_gpv \\<I> gpv \\<and> (\\<forall>x. x \\<in> results_gpv \\<I> gpv \\<longrightarrow> colossless_gpv \\<I> (f x))) \\<or>\n        colossless_gpv \\<I> (c input)\"\n      proof(cases generat)\n        case (Pure x)\n        hence \"x \\<in> results_gpv \\<I> gpv\" using generat by(auto intro: results_gpv.Pure)\n        from *(2)[OF this] have \"colossless_gpv \\<I> (c input)\"\n          using IO Pure input by(auto intro: colossless_gpv_continuationD)\n        thus ?thesis ..\n      next\n        case **: (IO out' c')\n        with input generat IO have \"colossless_gpv \\<I> (f x)\" if \"x \\<in> results_gpv \\<I> (c' input)\" for x\n          using that by(auto intro: * results_gpv.IO)\n        then show ?thesis using IO input ** *(1) generat by(auto dest: colossless_gpv_continuationD)\n      qed\n    qed\n    ultimately show ?case ..\n  qed\nqed\n\nlemmas lossless_bind_gpvI = gen_lossless_bind_gpvI[where co=False]\n  and colossless_bind_gpvI = gen_lossless_bind_gpvI[where co=True]\n\nlemma gen_lossless_bind_gpvD1: \n  assumes \"gen_lossless_gpv co \\<I> (gpv \\<bind> f)\"\n  shows \"gen_lossless_gpv co \\<I> gpv\"\nproof(cases co)\n  case False\n  hence eq: \"co = False\" by simp\n  show ?thesis using assms unfolding eq\n  proof(induction gpv'\\<equiv>\"gpv \\<bind> f\" arbitrary: gpv)\n    case (lossless_gpv p)\n    obtain p' where gpv: \"gpv = GPV p'\" by(cases gpv)\n    from lossless_gpv.hyps gpv have \"lossless_spmf p'\" by(simp add: GPV_bind)\n    then show ?case unfolding gpv\n    proof(rule gen_lossless_gpv_intros)\n      fix out c input\n      assume \"IO out c \\<in> set_spmf p'\" \"input \\<in> responses_\\<I> \\<I> out\"\n      hence \"IO out (\\<lambda>input. c input \\<bind> f) \\<in> set_spmf p\" using lossless_gpv.hyps gpv\n        by(auto simp add: GPV_bind intro: rev_bexI)\n      thus \"lossless_gpv \\<I> (c input)\" using \\<open>input \\<in> _\\<close> by(rule lossless_gpv.hyps) simp\n    qed\n  qed\nnext\n  case True\n  hence eq: \"co = True\" by simp\n  show ?thesis using assms unfolding eq\n    by(coinduction arbitrary: gpv)(auto 4 3 intro: rev_bexI elim!: colossless_gpv_continuationD dest: colossless_gpv_lossless_spmfD)\nqed\n\nlemmas lossless_bind_gpvD1 = gen_lossless_bind_gpvD1[where co=False]\n  and colossless_bind_gpvD1 = gen_lossless_bind_gpvD1[where co=True]\n\nlemma gen_lossless_bind_gpvD2:\n  assumes \"gen_lossless_gpv co \\<I> (gpv \\<bind> f)\"\n  and \"x \\<in> results_gpv \\<I> gpv\"\n  shows \"gen_lossless_gpv co \\<I> (f x)\"\nusing assms(2,1)\nproof(induction)\n  case (Pure gpv)\n  thus ?case\n    by -(rule gen_lossless_gpvI, auto 4 4 dest: gen_lossless_gpvD intro: rev_bexI)\nqed(auto 4 4 dest: gen_lossless_gpvD intro: rev_bexI)\n\nlemmas lossless_bind_gpvD2 = gen_lossless_bind_gpvD2[where co=False]\n  and colossless_bind_gpvD2 = gen_lossless_bind_gpvD2[where co=True]\n\nlemma gen_lossless_bind_gpv [simp]:\n  \"gen_lossless_gpv co \\<I> (gpv \\<bind> f) \\<longleftrightarrow> gen_lossless_gpv co \\<I> gpv \\<and> (\\<forall>x\\<in>results_gpv \\<I> gpv. gen_lossless_gpv co \\<I> (f x))\"\nby(blast intro: gen_lossless_bind_gpvI dest: gen_lossless_bind_gpvD1 gen_lossless_bind_gpvD2)\n\nlemmas lossless_bind_gpv = gen_lossless_bind_gpv[where co=False]\n  and colossless_bind_gpv = gen_lossless_bind_gpv[where co=True]\n\ncontext includes lifting_syntax begin\n\nlemma rel_gpv''_lossless_gpvD1:\n  assumes rel: \"rel_gpv'' A C R gpv gpv'\"\n  and gpv: \"lossless_gpv \\<I> gpv\"\n  and [transfer_rule]: \"rel_\\<I> C R \\<I> \\<I>'\"\n  shows \"lossless_gpv \\<I>' gpv'\"\nusing gpv rel\nproof(induction arbitrary: gpv')\n  case (lossless_gpv p)\n  from lossless_gpv.prems obtain q where q: \"gpv' = GPV q\"\n    and [transfer_rule]: \"rel_spmf (rel_generat A C (R ===> rel_gpv'' A C R)) p q\"\n    by(cases gpv') auto\n  show ?case\n  proof(rule lossless_gpvI)\n    have \"lossless_spmf p = lossless_spmf q\" by transfer_prover\n    with lossless_gpv.hyps(1) q show \"lossless_spmf (the_gpv gpv')\" by simp\n\n    fix out' c' input'\n    assume IO': \"IO out' c' \\<in> set_spmf (the_gpv gpv')\"\n      and input': \"input' \\<in> responses_\\<I> \\<I>' out'\"\n    have \"rel_set (rel_generat A C (R ===> rel_gpv'' A C R)) (set_spmf p) (set_spmf q)\"\n      by transfer_prover\n    with IO' q obtain out c where IO: \"IO out c \\<in> set_spmf p\"\n      and [transfer_rule]: \"C out out'\" \"(R ===> rel_gpv'' A C R) c c'\"\n      by(auto dest!: rel_setD2 elim: generat.rel_cases)\n    have \"rel_set R (responses_\\<I> \\<I> out) (responses_\\<I> \\<I>' out')\" by transfer_prover\n    moreover\n    from this[THEN rel_setD2, OF input'] obtain input\n      where [transfer_rule]: \"R input input'\" and input: \"input \\<in> responses_\\<I> \\<I> out\" by blast\n    have \"rel_gpv'' A C R (c input) (c' input')\" by transfer_prover\n    ultimately show \"lossless_gpv \\<I>' (c' input')\" using input IO by(auto intro: lossless_gpv.IH)\n  qed\nqed\n\nlemma rel_gpv''_lossless_gpvD2:\n  \"\\<lbrakk> rel_gpv'' A C R gpv gpv'; lossless_gpv \\<I>' gpv'; rel_\\<I> C R \\<I> \\<I>' \\<rbrakk>\n  \\<Longrightarrow> lossless_gpv \\<I> gpv\"\nusing rel_gpv''_lossless_gpvD1[of \"A\\<inverse>\\<inverse>\" \"C\\<inverse>\\<inverse>\" \"R\\<inverse>\\<inverse>\" gpv' gpv \\<I>' \\<I>]\nby(simp add: rel_gpv''_conversep prod.rel_conversep rel_fun_eq_conversep)\n\nlemma rel_gpv_lossless_gpvD1:\n  \"\\<lbrakk> rel_gpv A C gpv gpv'; lossless_gpv \\<I> gpv; rel_\\<I> C (=) \\<I> \\<I>' \\<rbrakk> \\<Longrightarrow> lossless_gpv \\<I>' gpv'\"\nusing rel_gpv''_lossless_gpvD1[of A C \"(=)\" gpv gpv' \\<I> \\<I>'] by(simp add: rel_gpv_conv_rel_gpv'')\n\nlemma rel_gpv_lossless_gpvD2:\n  \"\\<lbrakk> rel_gpv A C gpv gpv'; lossless_gpv \\<I>' gpv'; rel_\\<I> C (=) \\<I> \\<I>' \\<rbrakk>\n  \\<Longrightarrow> lossless_gpv \\<I> gpv\"\nusing rel_gpv_lossless_gpvD1[of \"A\\<inverse>\\<inverse>\" \"C\\<inverse>\\<inverse>\" gpv' gpv \\<I>' \\<I>]\nby(simp add: gpv.rel_conversep prod.rel_conversep rel_fun_eq_conversep)\n\nlemma rel_gpv''_colossless_gpvD1:\n  assumes rel: \"rel_gpv'' A C R gpv gpv'\"\n  and gpv: \"colossless_gpv \\<I> gpv\"\n  and [transfer_rule]: \"rel_\\<I> C R \\<I> \\<I>'\"\n  shows \"colossless_gpv \\<I>' gpv'\"\nusing gpv rel\nproof(coinduction arbitrary: gpv gpv')\n  case (colossless_gpv gpv gpv')\n  note [transfer_rule] = \\<open>rel_gpv'' A C R gpv gpv'\\<close> the_gpv_parametric'\n    and co = \\<open>colossless_gpv \\<I> gpv\\<close>\n  have \"lossless_spmf (the_gpv gpv) = lossless_spmf (the_gpv gpv')\" by transfer_prover\n  with co have \"?lossless_spmf\" by(auto dest: colossless_gpv_lossless_spmfD)\n  moreover have \"?continuation\"\n  proof(intro strip disjI1)\n    fix out' c' input'\n    assume IO': \"IO out' c' \\<in> set_spmf (the_gpv gpv')\"\n      and input': \"input' \\<in> responses_\\<I> \\<I>' out'\"\n    have \"rel_set (rel_generat A C (R ===> rel_gpv'' A C R)) (set_spmf (the_gpv gpv)) (set_spmf (the_gpv gpv'))\"\n      by transfer_prover\n    with IO' obtain out c where IO: \"IO out c \\<in> set_spmf (the_gpv gpv)\"\n      and [transfer_rule]: \"C out out'\" \"(R ===> rel_gpv'' A C R) c c'\"\n      by(auto dest!: rel_setD2 elim: generat.rel_cases)\n    have \"rel_set R (responses_\\<I> \\<I> out) (responses_\\<I> \\<I>' out')\" by transfer_prover\n    moreover \n    from this[THEN rel_setD2, OF input'] obtain input\n      where [transfer_rule]: \"R input input'\" and input: \"input \\<in> responses_\\<I> \\<I> out\" by blast\n    have \"rel_gpv'' A C R (c input) (c' input')\" by transfer_prover\n    ultimately show \"\\<exists>gpv gpv'. c' input' = gpv' \\<and> colossless_gpv \\<I> gpv \\<and> rel_gpv'' A C R gpv gpv'\"\n      using input IO co by(auto dest: colossless_gpv_continuationD)\n  qed\n  ultimately show ?case ..\nqed\n\nlemma rel_gpv''_colossless_gpvD2:\n  \"\\<lbrakk> rel_gpv'' A C R gpv gpv'; colossless_gpv \\<I>' gpv'; rel_\\<I> C R \\<I> \\<I>' \\<rbrakk>\n  \\<Longrightarrow> colossless_gpv \\<I> gpv\"\nusing rel_gpv''_colossless_gpvD1[of \"A\\<inverse>\\<inverse>\" \"C\\<inverse>\\<inverse>\" \"R\\<inverse>\\<inverse>\" gpv' gpv \\<I>' \\<I>]\nby(simp add: rel_gpv''_conversep prod.rel_conversep rel_fun_eq_conversep)\n\nlemma rel_gpv_colossless_gpvD1:\n  \"\\<lbrakk> rel_gpv A C gpv gpv'; colossless_gpv \\<I> gpv; rel_\\<I> C (=) \\<I> \\<I>' \\<rbrakk> \\<Longrightarrow> colossless_gpv \\<I>' gpv'\"\nusing rel_gpv''_colossless_gpvD1[of A C \"(=)\" gpv gpv' \\<I> \\<I>'] by(simp add: rel_gpv_conv_rel_gpv'')\n\nlemma rel_gpv_colossless_gpvD2:\n  \"\\<lbrakk> rel_gpv A C gpv gpv'; colossless_gpv \\<I>' gpv'; rel_\\<I> C (=) \\<I> \\<I>' \\<rbrakk>\n  \\<Longrightarrow> colossless_gpv \\<I> gpv\"\nusing rel_gpv_colossless_gpvD1[of \"A\\<inverse>\\<inverse>\" \"C\\<inverse>\\<inverse>\" gpv' gpv \\<I>' \\<I>]\nby(simp add: gpv.rel_conversep prod.rel_conversep rel_fun_eq_conversep)\n\nlemma gen_lossless_gpv_parametric':\n  \"((=) ===> rel_\\<I> C R ===> rel_gpv'' A C R ===> (=))\n   gen_lossless_gpv gen_lossless_gpv\"\nproof(rule rel_funI; hypsubst)\n  show \"(rel_\\<I> C R ===> rel_gpv'' A C R ===> (=)) (gen_lossless_gpv b) (gen_lossless_gpv b)\" for b\n    by(cases b)(auto intro!: rel_funI dest: rel_gpv''_colossless_gpvD1 rel_gpv''_colossless_gpvD2 rel_gpv''_lossless_gpvD1 rel_gpv''_lossless_gpvD2)\nqed\n\nlemma gen_lossless_gpv_parametric [transfer_rule]:\n  \"((=) ===> rel_\\<I> C (=) ===> rel_gpv A C ===> (=))\n   gen_lossless_gpv gen_lossless_gpv\"\nproof(rule rel_funI; hypsubst)\n  show \"(rel_\\<I> C (=) ===> rel_gpv A C ===> (=)) (gen_lossless_gpv b) (gen_lossless_gpv b)\" for b\n    by(cases b)(auto intro!: rel_funI dest: rel_gpv_colossless_gpvD1 rel_gpv_colossless_gpvD2 rel_gpv_lossless_gpvD1 rel_gpv_lossless_gpvD2)\nqed\n\nend\n\nlemma gen_lossless_gpv_map_full [simp]:\n  \"gen_lossless_gpv b \\<I>_full (map_gpv f g gpv) = gen_lossless_gpv b \\<I>_full gpv\"\n  (is \"?lhs = ?rhs\")\nproof(cases \"b = True\")\n  case True\n  show \"?lhs = ?rhs\"\n  proof\n    show ?rhs if ?lhs using that unfolding True\n      by(coinduction arbitrary: gpv)(auto 4 3 dest: colossless_gpvD simp add: gpv.map_sel intro!: rev_image_eqI)\n    show ?lhs if ?rhs using that unfolding True\n      by(coinduction arbitrary: gpv)(auto 4 4 dest: colossless_gpvD simp add: gpv.map_sel intro!: rev_image_eqI)\n  qed\nnext\n  case False\n  hence False: \"b = False\" by simp\n  show \"?lhs = ?rhs\"\n  proof\n    show ?rhs if ?lhs using that unfolding False\n      apply(induction gpv'\\<equiv>\"map_gpv f g gpv\" arbitrary: gpv)\n      subgoal for p gpv by(cases gpv)(rule lossless_gpvI; fastforce intro: rev_image_eqI)\n      done\n    show ?lhs if ?rhs using that unfolding False\n      by induction(auto 4 4 intro: lossless_gpvI)\n  qed\nqed\n\nlemma gen_lossless_gpv_map_id [simp]:\n  \"gen_lossless_gpv b \\<I> (map_gpv f id gpv) = gen_lossless_gpv b \\<I> gpv\"\n  using gen_lossless_gpv_parametric[of \"BNF_Def.Grp UNIV id\" \"BNF_Def.Grp UNIV f\"] unfolding gpv.rel_Grp\n  by(simp add: rel_fun_def eq_alt[symmetric] rel_\\<I>_eq)(auto simp add: Grp_def)\n\nlemma results_gpv_try_gpv [simp]:\n  \"results_gpv \\<I> (TRY gpv ELSE gpv') = \n   results_gpv \\<I> gpv \\<union> (if colossless_gpv \\<I> gpv then {} else results_gpv \\<I> gpv')\"\n  (is \"?lhs = ?rhs\")\nproof(intro set_eqI iffI)\n  show \"x \\<in> ?rhs\" if \"x \\<in> ?lhs\" for x using that\n  proof(induction gpv''\\<equiv>\"try_gpv gpv gpv'\" arbitrary: gpv)\n    case Pure thus ?case\n      by(auto split: if_split_asm intro: results_gpv.Pure dest: colossless_gpv_lossless_spmfD)\n  next\n    case (IO out c input)\n    then show ?case\n      apply(auto dest: colossless_gpv_lossless_spmfD split: if_split_asm)\n      apply(force intro: results_gpv.IO dest: colossless_gpv_continuationD split: if_split_asm)+\n      done\n  qed\nnext\n  fix x\n  assume \"x \\<in> ?rhs\"\n  then consider (left) \"x \\<in> results_gpv \\<I> gpv\" | (right) \"\\<not> colossless_gpv \\<I> gpv\" \"x \\<in> results_gpv \\<I> gpv'\"\n    by(auto split: if_split_asm)\n  thus \"x \\<in> ?lhs\"\n  proof cases\n    case left\n    thus ?thesis \n      by(induction)(auto 4 4 intro: results_gpv.intros rev_image_eqI split del: if_split)\n  next\n    case right\n    from right(1) show ?thesis\n    proof(rule contrapos_np)\n      assume \"x \\<notin> ?lhs\"\n      with right(2) show \"colossless_gpv \\<I> gpv\"\n      proof(coinduction arbitrary: gpv)\n        case (colossless_gpv gpv)\n        then have ?lossless_spmf\n          apply(rewrite in asm try_gpv.code)\n          apply(rule ccontr)\n          apply(erule results_gpv.cases)\n          apply(fastforce simp add: image_Un image_image generat.map_comp o_def)+\n          done\n        moreover have \"?continuation\" using colossless_gpv\n          by(auto 4 4 split del: if_split simp add: image_Un image_image generat.map_comp o_def intro: rev_image_eqI results_gpv.IO)\n        ultimately show ?case ..\n      qed\n    qed\n  qed\nqed\n\nlemma results'_gpv_try_gpv [simp]:\n  \"results'_gpv (TRY gpv ELSE gpv') = \n   results'_gpv gpv \\<union> (if colossless_gpv \\<I>_full gpv then {} else results'_gpv gpv')\"\nby(simp add: results_gpv_\\<I>_full[symmetric])\n\nlemma outs'_gpv_try_gpv [simp]:\n  \"outs'_gpv (TRY gpv ELSE gpv') =\n   outs'_gpv gpv \\<union> (if colossless_gpv \\<I>_full gpv then {} else outs'_gpv gpv')\"\n  (is \"?lhs = ?rhs\")\nproof(intro set_eqI iffI)\n  show \"x \\<in> ?rhs\" if \"x \\<in> ?lhs\" for x using that\n  proof(induction gpv''\\<equiv>\"try_gpv gpv gpv'\" arbitrary: gpv)\n    case Out thus ?case\n      by(auto 4 3 simp add: generat.map_comp o_def elim!: generat.set_cases(2) intro: outs'_gpv_Out split: if_split_asm dest: colossless_gpv_lossless_spmfD)\n  next\n    case (Cont generat c input)\n    then show ?case\n      apply(auto dest: colossless_gpv_lossless_spmfD split: if_split_asm elim!: generat.set_cases(3))\n      apply(auto 4 3 dest: colossless_gpv_continuationD split: if_split_asm intro: outs'_gpv_Cont elim!: meta_allE meta_impE[OF _ refl])+\n      done\n  qed\nnext\n  fix x\n  assume \"x \\<in> ?rhs\"\n  then consider (left) \"x \\<in> outs'_gpv gpv\" | (right) \"\\<not> colossless_gpv \\<I>_full gpv\" \"x \\<in> outs'_gpv gpv'\"\n    by(auto split: if_split_asm)\n  thus \"x \\<in> ?lhs\"\n  proof cases\n    case left\n    thus ?thesis \n      by(induction)(auto elim!: generat.set_cases(2,3) intro: outs'_gpvI intro!: rev_image_eqI split del: if_split simp add: image_Un image_image generat.map_comp o_def)\n  next\n    case right\n    from right(1) show ?thesis\n    proof(rule contrapos_np)\n      assume \"x \\<notin> ?lhs\"\n      with right(2) show \"colossless_gpv \\<I>_full gpv\"\n      proof(coinduction arbitrary: gpv)\n        case (colossless_gpv gpv)\n        then have ?lossless_spmf\n          apply(rewrite in asm try_gpv.code)\n          apply(erule contrapos_np)\n          apply(erule gpv.set_cases)\n          apply(auto 4 3 simp add: image_Un image_image generat.map_comp o_def generat.set_map in_set_spmf[symmetric] bind_UNION generat.map_id[unfolded id_def] elim!: generat.set_cases)\n          done\n        moreover have \"?continuation\" using colossless_gpv\n          by(auto simp add: image_Un image_image generat.map_comp o_def split del: if_split intro!: rev_image_eqI intro: outs'_gpv_Cont)\n        ultimately show ?case ..\n      qed\n    qed\n  qed\nqed\n\nlemma pred_gpv_try [simp]:\n  \"pred_gpv P Q (try_gpv gpv gpv') = (pred_gpv P Q gpv \\<and> (\\<not> colossless_gpv \\<I>_full gpv \\<longrightarrow> pred_gpv P Q gpv'))\"\nby(auto simp add: pred_gpv_def)\n\nlemma lossless_WT_gpv_induct [consumes 2, case_names lossless_gpv]:\n  assumes lossless: \"lossless_gpv \\<I> gpv\"\n  and WT: \"\\<I> \\<turnstile>g gpv \\<surd>\"\n  and step: \"\\<And>p. \\<lbrakk>\n       lossless_spmf p;\n       \\<And>out c. IO out c \\<in> set_spmf p \\<Longrightarrow> out \\<in> outs_\\<I> \\<I>;\n       \\<And>out c input. \\<lbrakk>IO out c \\<in> set_spmf p; out \\<in> outs_\\<I> \\<I> \\<Longrightarrow> input \\<in> responses_\\<I> \\<I> out\\<rbrakk> \\<Longrightarrow> lossless_gpv \\<I> (c input);\n       \\<And>out c input. \\<lbrakk>IO out c \\<in> set_spmf p; out \\<in> outs_\\<I> \\<I> \\<Longrightarrow> input \\<in> responses_\\<I> \\<I> out\\<rbrakk> \\<Longrightarrow> \\<I> \\<turnstile>g c input \\<surd>;\n       \\<And>out c input. \\<lbrakk>IO out c \\<in> set_spmf p; out \\<in> outs_\\<I> \\<I> \\<Longrightarrow> input \\<in> responses_\\<I> \\<I> out\\<rbrakk> \\<Longrightarrow> P (c input)\\<rbrakk>\n      \\<Longrightarrow> P (GPV p)\"\n  shows \"P gpv\"\nusing lossless WT\napply(induction)\napply(erule step)\napply(auto elim: WT_gpvD simp add: WT_gpv_simps)\ndone\n\nlemma lossless_gpv_induct_strong [consumes 1, case_names lossless_gpv]:\n  assumes gpv: \"lossless_gpv \\<I> gpv\"\n  and step:\n  \"\\<And>p. \\<lbrakk> lossless_spmf p;\n          \\<And>gpv. gpv \\<in> sub_gpvs \\<I> (GPV p) \\<Longrightarrow> lossless_gpv \\<I> gpv;\n          \\<And>gpv. gpv \\<in> sub_gpvs \\<I> (GPV p) \\<Longrightarrow> P gpv \\<rbrakk>\n       \\<Longrightarrow> P (GPV p)\"\n  shows \"P gpv\"\nproof -\n  define gpv' where \"gpv' = gpv\"\n  then have \"gpv' \\<in> insert gpv (sub_gpvs \\<I> gpv)\" by simp\n  with gpv have \"lossless_gpv \\<I> gpv' \\<and> P gpv'\"\n  proof(induction arbitrary: gpv')\n    case (lossless_gpv p)\n    from \\<open>gpv' \\<in> insert (GPV p) _\\<close> show ?case\n    proof(rule insertE)\n      assume \"gpv' = GPV p\"\n      moreover have \"lossless_gpv \\<I> (GPV p)\"\n        by(auto 4 3 intro: lossless_gpvI lossless_gpv.hyps)\n      moreover have \"P (GPV p)\" using lossless_gpv.hyps(1)\n        by(rule step)(fastforce elim: sub_gpvs.cases lossless_gpv.IH[THEN conjunct1] lossless_gpv.IH[THEN conjunct2])+\n      ultimately show ?case by simp\n    qed(fastforce elim: sub_gpvs.cases lossless_gpv.IH[THEN conjunct1] lossless_gpv.IH[THEN conjunct2])\n  qed\n  thus ?thesis by(simp add: gpv'_def)\nqed\n\nlemma lossless_sub_gpvsI:\n  assumes spmf: \"lossless_spmf (the_gpv gpv)\"\n  and sub: \"\\<And>gpv'. gpv' \\<in> sub_gpvs \\<I> gpv \\<Longrightarrow> lossless_gpv \\<I> gpv'\"\n  shows \"lossless_gpv \\<I> gpv\"\nusing spmf by(rule lossless_gpvI)(rule sub[OF sub_gpvs.base])\n\nlemma lossless_sub_gpvsD:\n  assumes \"lossless_gpv \\<I> gpv\" \"gpv' \\<in> sub_gpvs \\<I> gpv\"\n  shows \"lossless_gpv \\<I> gpv'\"\nusing assms(2,1) by(induction)(auto dest: lossless_gpvD)\n\nlemma lossless_WT_gpv_induct_strong [consumes 2, case_names lossless_gpv]:\n  assumes lossless: \"lossless_gpv \\<I> gpv\"\n  and WT: \"\\<I> \\<turnstile>g gpv \\<surd>\"\n  and step: \"\\<And>p. \\<lbrakk> lossless_spmf p;\n       \\<And>out c. IO out c \\<in> set_spmf p \\<Longrightarrow> out \\<in> outs_\\<I> \\<I>;\n       \\<And>gpv. gpv \\<in> sub_gpvs \\<I> (GPV p) \\<Longrightarrow> lossless_gpv \\<I> gpv;\n       \\<And>gpv. gpv \\<in> sub_gpvs \\<I> (GPV p) \\<Longrightarrow> \\<I> \\<turnstile>g gpv \\<surd>;\n       \\<And>gpv. gpv \\<in> sub_gpvs \\<I> (GPV p) \\<Longrightarrow> P gpv \\<rbrakk>\n      \\<Longrightarrow> P (GPV p)\"\n  shows \"P gpv\"\nusing lossless WT\napply(induction rule: lossless_gpv_induct_strong)\napply(erule step)\napply(auto elim: WT_gpvD dest: WT_sub_gpvsD)\ndone\n\nlemma try_gpv_gen_lossless: \\<comment> \\<open>TODO: generalise to arbitrary typings ?\\<close>\n  \"gen_lossless_gpv b \\<I>_full gpv \\<Longrightarrow> (TRY gpv ELSE gpv') = gpv\"\nproof(coinduction arbitrary: gpv)\n  case (Eq_gpv gpv)\n  from Eq_gpv[THEN gen_lossless_gpv_lossless_spmfD]\n  have eq: \"the_gpv gpv = (TRY the_gpv gpv ELSE the_gpv gpv')\" by(simp)\n  show ?case\n    by(subst eq)(auto simp add: spmf_rel_map generat.rel_map[abs_def] intro!: rel_spmf_try_spmf rel_spmf_reflI rel_generat_reflI elim!: generat.set_cases gen_lossless_gpv_continuationD[OF Eq_gpv] simp add: Eq_gpv[THEN gen_lossless_gpv_lossless_spmfD])\nqed\n\n\\<comment> \\<open>We instantiate the parameter @{term b} such that it can be used as a conditional simp rule.\\<close>\nlemmas try_gpv_lossless [simp] = try_gpv_gen_lossless[where b=False]\n  and try_gpv_colossless [simp] = try_gpv_gen_lossless[where b=True]\n\nlemma try_gpv_bind_gen_lossless: \\<comment> \\<open>TODO: generalise to arbitrary typings?\\<close>\n  \"gen_lossless_gpv b \\<I>_full gpv \\<Longrightarrow> TRY bind_gpv gpv f ELSE gpv' = bind_gpv gpv (\\<lambda>x. TRY f x ELSE gpv')\"\nproof(coinduction arbitrary: gpv rule: gpv.coinduct_strong)\n  case (Eq_gpv gpv)\n  note [simp] = spmf_rel_map generat.rel_map map_spmf_bind_spmf\n    and [intro!] = rel_spmf_reflI rel_generat_reflI rel_funI\n  show ?case using gen_lossless_gpvD[OF Eq_gpv]\n    by(auto 4 3 simp del: bind_gpv_sel' simp add: bind_gpv.sel try_spmf_bind_spmf_lossless split: generat.split intro!: rel_spmf_bind_reflI rel_spmf_try_spmf)\nqed\n\n\\<comment> \\<open>We instantiate the parameter @{term b} such that it can be used as a conditional simp rule.\\<close>\nlemmas try_gpv_bind_lossless = try_gpv_bind_gen_lossless[where b=False]\n  and try_gpv_bind_colossless = try_gpv_bind_gen_lossless[where b=True]\n\nlemma try_gpv_cong:\n  \"\\<lbrakk> gpv = gpv''; \\<not> colossless_gpv \\<I>_full gpv'' \\<Longrightarrow> gpv' = gpv''' \\<rbrakk>\n  \\<Longrightarrow> try_gpv gpv gpv' = try_gpv gpv'' gpv'''\"\nby(cases \"colossless_gpv \\<I>_full gpv''\") simp_all\n\n(* lemma try_gpv_bind_colossless2:\n  \"colossless_gpv \\<I>_full gpv' \\<Longrightarrow> try_gpv (bind_gpv gpv f) gpv' = try_gpv (bind_gpv gpv (\\<lambda>x. try_gpv (f x) gpv')) gpv'\"\napply(coinduction arbitrary: gpv rule: gpv.coinduct_strong)\napply(simp add: spmf_rel_map bind_gpv_sel del: bind_gpv_sel')\napply(rule rel_spmf_try_spmf)\n apply(simp add: spmf_rel_map)\n apply(rule rel_spmf_bind_reflI)\n apply(simp split: generat.split)\n apply(rule conjI; clarsimp)\n apply(simp add: spmf_rel_map generat.map_comp o_def generat.rel_map rel_fun_def)\n apply(subst map_try_spmf[symmetric])\n *)\n\nsubsection \\<open>Sequencing with failure handling included\\<close>\n\ndefinition catch_gpv :: \"('a, 'out, 'in) gpv \\<Rightarrow> ('a option, 'out, 'in) gpv\"\nwhere \"catch_gpv gpv = TRY map_gpv Some id gpv ELSE Done None\"\n\nlemma catch_gpv_Done [simp]: \"catch_gpv (Done x) = Done (Some x)\"\nby(simp add: catch_gpv_def)\n\nlemma catch_gpv_Fail [simp]: \"catch_gpv Fail = Done None\"\nby(simp add: catch_gpv_def)\n\nlemma catch_gpv_Pause [simp]: \"catch_gpv (Pause out rpv) = Pause out (\\<lambda>input. catch_gpv (rpv input))\"\nby(simp add: catch_gpv_def)\n\nlemma catch_gpv_lift_spmf [simp]: \"catch_gpv (lift_spmf p) = lift_spmf (spmf_of_pmf p)\"\nby(rule gpv.expand)(auto simp add: catch_gpv_def spmf_of_pmf_def map_lift_spmf try_spmf_def o_def map_pmf_def bind_assoc_pmf bind_return_pmf intro!: bind_pmf_cong[OF refl] split: option.split)\n\nlemma catch_gpv_assert [simp]: \"catch_gpv (assert_gpv b) = Done (assert_option b)\"\nby(cases b) simp_all\n\nlemma catch_gpv_sel [simp]:\n  \"the_gpv (catch_gpv gpv) = \n   TRY map_spmf (map_generat Some id (\\<lambda>rpv input. catch_gpv (rpv input))) (the_gpv gpv)\n   ELSE return_spmf (Pure None)\"\nby(simp add: catch_gpv_def gpv.map_sel spmf.map_comp o_def generat.map_comp map_try_spmf id_def)\n\nlemma catch_gpv_bind_gpv: \"catch_gpv (bind_gpv gpv f) = bind_gpv (catch_gpv gpv) (\\<lambda>x. case x of None \\<Rightarrow> Done None | Some x' \\<Rightarrow> catch_gpv (f x'))\"\n  using [[show_variants]]\n  apply(coinduction arbitrary: gpv rule: gpv.coinduct_strong)\n  apply(clarsimp simp add: map_bind_pmf bind_gpv.sel spmf.map_comp o_def[abs_def] map_bind_spmf generat.map_comp simp del: bind_gpv_sel')\n  apply(subst bind_spmf_def)\n  apply(subst try_spmf_bind_pmf)\n  apply(subst (2) try_spmf_def)\n  apply(subst bind_spmf_pmf_assoc)\n  apply(simp add: bind_map_pmf)\n  apply(rule rel_pmf_bind_reflI)\n  apply(auto split!: option.split generat.split simp add: spmf_rel_map spmf.map_comp o_def generat.map_comp id_def[symmetric] generat.map_id rel_spmf_reflI generat.rel_refl refl rel_fun_def)\n  done\n\ncontext includes lifting_syntax begin\nlemma catch_gpv_parametric [transfer_rule]:\n  \"(rel_gpv A C ===> rel_gpv (rel_option A) C) catch_gpv catch_gpv\"\nunfolding catch_gpv_def by transfer_prover\n\nlemma catch_gpv_parametric':\n  notes [transfer_rule] = try_gpv_parametric' map_gpv_parametric' Done_parametric'\n  shows \"(rel_gpv'' A C R ===> rel_gpv'' (rel_option A) C R) catch_gpv catch_gpv\"\nunfolding catch_gpv_def by transfer_prover\nend\n\nlemma catch_gpv_map': \"catch_gpv (map_gpv' f g h gpv) = map_gpv' (map_option f) g h (catch_gpv gpv)\"\nby(simp add: catch_gpv_def map'_try_gpv map_gpv_conv_map_gpv' map_gpv'_comp o_def)\n\nlemma catch_gpv_map: \"catch_gpv (map_gpv f g gpv) = map_gpv (map_option f) g (catch_gpv gpv)\"\n  by(simp add: map_gpv_conv_map_gpv' catch_gpv_map')\n\nlemma colossless_gpv_catch_gpv [simp]: \"colossless_gpv \\<I>_full (catch_gpv gpv)\"\nby(coinduction arbitrary: gpv) auto\n\nlemma colosless_gpv_catch_gpv_conv_map:\n  \"colossless_gpv \\<I>_full gpv \\<Longrightarrow> catch_gpv gpv = map_gpv Some id gpv\"\n  apply(coinduction arbitrary: gpv)\n  apply(frule colossless_gpv_lossless_spmfD)\n  apply(auto simp add: spmf_rel_map gpv.map_sel generat.rel_map intro!: rel_spmf_reflI generat.rel_refl_strong rel_funI elim!: colossless_gpv_continuationD generat.set_cases)\n  done\n\nlemma catch_gpv_catch_gpv [simp]: \"catch_gpv (catch_gpv gpv) = map_gpv Some id (catch_gpv gpv)\"\n  by(simp add: colosless_gpv_catch_gpv_conv_map)\n\nlemma case_map_resumption: (* Move to Resumption *)\n  \"case_resumption done pause (map_resumption f g r) = \n   case_resumption (done \\<circ> map_option f) (\\<lambda>out c. pause (g out) (map_resumption f g \\<circ> c)) r\" \nby(cases r) simp_all\n\nlemma catch_gpv_lift_resumption [simp]: \"catch_gpv (lift_resumption r) = lift_resumption (map_resumption Some id r)\"\n  apply(coinduction arbitrary: r)\n  apply(auto simp add: lift_resumption.sel case_map_resumption split: resumption.split option.split)\n  oops (* TODO: We'd need a catch_resumption for this *)\n\nlemma results_gpv_catch_gpv:\n  \"results_gpv \\<I> (catch_gpv gpv) = Some ` results_gpv \\<I> gpv \\<union> (if colossless_gpv \\<I> gpv then {} else {None})\"\n  by(simp add: catch_gpv_def)\n\nlemma Some_in_results_gpv_catch_gpv [simp]:\n  \"Some x \\<in> results_gpv \\<I> (catch_gpv gpv) \\<longleftrightarrow> x \\<in> results_gpv \\<I> gpv\"\n  by(auto simp add: results_gpv_catch_gpv)\n\nlemma None_in_results_gpv_catch_gpv [simp]:\n  \"None \\<in> results_gpv \\<I> (catch_gpv gpv) \\<longleftrightarrow> \\<not> colossless_gpv \\<I> gpv\"\n  by(auto simp add: results_gpv_catch_gpv)\n\nlemma results'_gpv_catch_gpv:\n  \"results'_gpv (catch_gpv gpv) = Some ` results'_gpv gpv \\<union> (if colossless_gpv \\<I>_full gpv then {} else {None})\"\n  by(simp add: results_gpv_\\<I>_full[symmetric] results_gpv_catch_gpv)\n\nlemma Some_in_results'_gpv_catch_gpv [simp]:\n  \"Some x \\<in> results'_gpv (catch_gpv gpv) \\<longleftrightarrow> x \\<in> results'_gpv gpv\"\n  by(simp add: results_gpv_\\<I>_full[symmetric])\n\nlemma None_in_results'_gpv_catch_gpv [simp]:\n  \"None \\<in> results'_gpv (catch_gpv gpv) \\<longleftrightarrow> \\<not> colossless_gpv \\<I>_full gpv\"\n  by(simp add: results_gpv_\\<I>_full[symmetric])\n\nlemma results'_gpv_catch_gpvE:\n  assumes \"x \\<in> results'_gpv (catch_gpv gpv)\"\n  obtains (Some) x'\n  where \"x = Some x'\" \"x' \\<in> results'_gpv gpv\"\n  | (colossless) \"x = None\" \"\\<not> colossless_gpv \\<I>_full gpv\"\n  using assms by(auto simp add: results'_gpv_catch_gpv split: if_split_asm)\n\nlemma outs'_gpv_catch_gpv [simp]: \"outs'_gpv (catch_gpv gpv) = outs'_gpv gpv\"\n  by(simp add: catch_gpv_def)\n\nlemma pred_gpv_catch_gpv [simp]: \"pred_gpv (pred_option P) Q (catch_gpv gpv) = pred_gpv P Q gpv\"\n  by(simp add: pred_gpv_def results'_gpv_catch_gpv)\n\nabbreviation bind_gpv' :: \"('a, 'call, 'ret) gpv \\<Rightarrow> ('a option \\<Rightarrow> ('b, 'call, 'ret) gpv) \\<Rightarrow> ('b, 'call, 'ret) gpv\"\nwhere \"bind_gpv' gpv \\<equiv> bind_gpv (catch_gpv gpv)\"\n\n(* lemma bind_gpv'_sel [simp]:\n  \"the_gpv (bind_gpv' gpv f) =\n   bind_pmf (the_gpv gpv) (\\<lambda>x. case x of\n     None \\<Rightarrow> the_gpv (f None)\n   | Some (Pure x) \\<Rightarrow> the_gpv (f (Some x))\n   | Some (IO out rpv) \\<Rightarrow> return_spmf (IO out (\\<lambda>input. bind_gpv' (rpv input) f)))\"\nby(auto simp add: bind_gpv'_def bind_map_spmf try_spmf_def bind_spmf_pmf_assoc bind_map_pmf gpv.map_sel intro!: bind_pmf_cong[OF refl] split: option.split generat.split)\n *)\n  \nlemma bind_gpv'_assoc [simp]: \"bind_gpv' (bind_gpv' gpv f) g = bind_gpv' gpv (\\<lambda>x. bind_gpv' (f x) g)\"\nby(simp add: catch_gpv_bind_gpv bind_map_gpv o_def bind_gpv_assoc)\n\nlemma bind_gpv'_bind_gpv: \"bind_gpv' (bind_gpv gpv f) g = bind_gpv' gpv (case_option (g None) (\\<lambda>y. bind_gpv' (f y) g))\"\n  by(clarsimp simp add: catch_gpv_bind_gpv bind_gpv_assoc intro!: bind_gpv_cong[OF refl] split: option.split)\n\nlemma bind_gpv'_cong:\n  \"\\<lbrakk> gpv = gpv'; \\<And>x. x \\<in> Some ` results'_gpv gpv' \\<or> (\\<not> colossless_gpv \\<I>_full gpv \\<and> x = None) \\<Longrightarrow> f x = f' x \\<rbrakk>\n  \\<Longrightarrow> bind_gpv' gpv f = bind_gpv' gpv' f'\"\nby(auto elim: results'_gpv_catch_gpvE split: if_split_asm intro!: bind_gpv_cong[OF refl])\n\nlemma bind_gpv'_cong2:\n  \"\\<lbrakk> gpv = gpv'; \\<And>x. x \\<in> results'_gpv gpv' \\<Longrightarrow> f (Some x) = f' (Some x); \\<not> colossless_gpv \\<I>_full gpv \\<Longrightarrow> f None = f' None \\<rbrakk>\n  \\<Longrightarrow> bind_gpv' gpv f = bind_gpv' gpv' f'\"\nby(rule bind_gpv'_cong) auto\n\nsubsection \\<open>Inlining\\<close>\n\nlemma gpv_coinduct_bind [consumes 1, case_names Eq_gpv]:\n  fixes gpv gpv' :: \"('a, 'call, 'ret) gpv\"\n  assumes *: \"R gpv gpv'\"\n  and step: \"\\<And>gpv gpv'. R gpv gpv' \n    \\<Longrightarrow> rel_spmf (rel_generat (=) (=) (rel_fun (=) (\\<lambda>gpv gpv'. R gpv gpv' \\<or> gpv = gpv' \\<or> \n      (\\<exists>gpv2 :: ('b, 'call, 'ret) gpv. \\<exists>gpv2' :: ('c, 'call, 'ret) gpv. \\<exists>f f'. gpv = bind_gpv gpv2 f \\<and> gpv' = bind_gpv gpv2' f' \\<and> \n        rel_gpv (\\<lambda>x y. R (f x) (f' y)) (=) gpv2 gpv2'))))\n      (the_gpv gpv) (the_gpv gpv')\"\n  shows \"gpv = gpv'\"\nproof -\n  fix x y\n  define gpv1 :: \"('b, 'call, 'ret) gpv\"\n    and f :: \"'b \\<Rightarrow> ('a, 'call, 'ret) gpv\"\n    and gpv1' :: \"('c, 'call, 'ret) gpv\"\n    and f' :: \"'c \\<Rightarrow> ('a, 'call, 'ret) gpv\"\n    where \"gpv1 = Done x\"\n      and \"f = (\\<lambda>_. gpv)\"\n      and \"gpv1' = Done y\"\n      and \"f' = (\\<lambda>_. gpv')\"\n  from * have \"rel_gpv (\\<lambda>x y. R (f x) (f' y)) (=) gpv1 gpv1'\"\n    by(simp add: gpv1_def gpv1'_def f_def f'_def)\n  then have \"gpv1 \\<bind> f = gpv1' \\<bind> f'\"\n  proof(coinduction arbitrary: gpv1 gpv1' f f' rule: gpv.coinduct_strong)\n    case (Eq_gpv gpv1 gpv1' f f')\n    from Eq_gpv[simplified gpv.rel_sel] show ?case unfolding bind_gpv.sel spmf_rel_map\n      apply(rule rel_spmf_bindI)\n      subgoal for generat generat'\n        apply(cases generat generat' rule: generat.exhaust[case_product generat.exhaust]; clarsimp simp add: o_def spmf_rel_map generat.rel_map)\n        subgoal premises Pure for x y\n          using step[OF \\<open>R (f x) (f' y)\\<close>] apply -\n          apply(assumption | rule rel_spmf_mono rel_generat_mono rel_fun_mono refl)+\n          apply(fastforce intro: exI[where x=\"Done _\"])+\n          done\n        subgoal by(fastforce simp add: rel_fun_def)\n        done\n      done\n  qed\n  thus ?thesis by(simp add: gpv1_def gpv1'_def f_def f'_def)\nqed\n\ntext \\<open>\n  Inlining one gpv into another. This may throw out arbitrarily many\n  interactions between the two gpvs if the inlined one does not call its callee.\n  So we define it as the coiteration of a least-fixpoint search operator.\n\\<close>\n\ncontext\n  fixes callee :: \"'s \\<Rightarrow> 'call \\<Rightarrow> ('ret \\<times> 's, 'call', 'ret') gpv\"\n  notes [[function_internals]]\nbegin\n\npartial_function (spmf) inline1\n  :: \"('a, 'call, 'ret) gpv \\<Rightarrow> 's\n  \\<Rightarrow> ('a \\<times> 's + 'call' \\<times> ('ret \\<times> 's, 'call', 'ret') rpv \\<times> ('a, 'call, 'ret) rpv) spmf\"\nwhere\n  \"inline1 gpv s =\n   the_gpv gpv \\<bind>\n   case_generat (\\<lambda>x. return_spmf (Inl (x, s)))\n     (\\<lambda>out rpv. the_gpv (callee s out) \\<bind>\n         case_generat (\\<lambda>(x, y). inline1 (rpv x) y)\n          (\\<lambda>out rpv'. return_spmf (Inr (out, rpv', rpv))))\"\n\nlemma inline1_unfold:\n  \"inline1 gpv s =\n   the_gpv gpv \\<bind>\n   case_generat (\\<lambda>x. return_spmf (Inl (x, s)))\n     (\\<lambda>out rpv. the_gpv (callee s out) \\<bind>\n         case_generat (\\<lambda>(x, y). inline1 (rpv x) y)\n          (\\<lambda>out rpv'. return_spmf (Inr (out, rpv', rpv))))\"\nby(fact inline1.simps)\n\nlemma inline1_fixp_induct [case_names adm bottom step]:\n  assumes \"ccpo.admissible (fun_lub lub_spmf) (fun_ord (ord_spmf (=))) (\\<lambda>inline1'. P (\\<lambda>gpv s. inline1' (gpv, s)))\"\n  and \"P (\\<lambda>_ _. return_pmf None)\"\n  and \"\\<And>inline1'. P inline1' \\<Longrightarrow> P (\\<lambda>gpv s. the_gpv gpv \\<bind> case_generat (\\<lambda>x. return_spmf (Inl (x, s))) (\\<lambda>out rpv. the_gpv (callee s out) \\<bind> case_generat (\\<lambda>(x, y). inline1' (rpv x) y) (\\<lambda>out rpv'. return_spmf (Inr (out, rpv', rpv)))))\"\n  shows \"P inline1\"\nusing assms by(rule inline1.fixp_induct[unfolded curry_conv[abs_def]])\n\nlemma inline1_fixp_induct_strong [case_names adm bottom step]:\n  assumes \"ccpo.admissible (fun_lub lub_spmf) (fun_ord (ord_spmf (=))) (\\<lambda>inline1'. P (\\<lambda>gpv s. inline1' (gpv, s)))\"\n  and \"P (\\<lambda>_ _. return_pmf None)\"\n  and \"\\<And>inline1'. \\<lbrakk> \\<And>gpv s. ord_spmf (=) (inline1' gpv s) (inline1 gpv s); P inline1' \\<rbrakk>\n    \\<Longrightarrow> P (\\<lambda>gpv s. the_gpv gpv \\<bind> case_generat (\\<lambda>x. return_spmf (Inl (x, s))) (\\<lambda>out rpv. the_gpv (callee s out) \\<bind> case_generat (\\<lambda>(x, y). inline1' (rpv x) y) (\\<lambda>out rpv'. return_spmf (Inr (out, rpv', rpv)))))\"\n  shows \"P inline1\"\nusing assms by(rule spmf.fixp_strong_induct_uc[where P=\"\\<lambda>f. P (curry f)\" and U=case_prod and C=curry, OF inline1.mono inline1_def, simplified curry_case_prod, simplified curry_conv[abs_def] fun_ord_def split_paired_All prod.case case_prod_eta, OF refl]) blast+\n\nlemma inline1_fixp_induct_strong2 [case_names adm bottom step]:\n  assumes \"ccpo.admissible (fun_lub lub_spmf) (fun_ord (ord_spmf (=))) (\\<lambda>inline1'. P (\\<lambda>gpv s. inline1' (gpv, s)))\"\n  and \"P (\\<lambda>_ _. return_pmf None)\"\n  and \"\\<And>inline1'. \n    \\<lbrakk> \\<And>gpv s. ord_spmf (=) (inline1' gpv s) (inline1 gpv s); \n      \\<And>gpv s. ord_spmf (=) (inline1' gpv s) (the_gpv gpv \\<bind> case_generat (\\<lambda>x. return_spmf (Inl (x, s))) (\\<lambda>out rpv. the_gpv (callee s out) \\<bind> case_generat (\\<lambda>(x, y). inline1' (rpv x) y) (\\<lambda>out rpv'. return_spmf (Inr (out, rpv', rpv)))));\n      P inline1' \\<rbrakk>\n    \\<Longrightarrow> P (\\<lambda>gpv s. the_gpv gpv \\<bind> case_generat (\\<lambda>x. return_spmf (Inl (x, s))) (\\<lambda>out rpv. the_gpv (callee s out) \\<bind> case_generat (\\<lambda>(x, y). inline1' (rpv x) y) (\\<lambda>out rpv'. return_spmf (Inr (out, rpv', rpv)))))\"\n  shows \"P inline1\"\nusing assms\nby(rule spmf.fixp_induct_strong2_uc[where P=\"\\<lambda>f. P (curry f)\" and U=case_prod and C=curry, OF inline1.mono inline1_def, simplified curry_case_prod, simplified curry_conv[abs_def] fun_ord_def split_paired_All prod.case case_prod_eta, OF refl]) blast+\n\ntext \\<open>\n  Iterate @{const inline1} over all interactions. We'd like to use @{const bind_gpv} before\n  the recursive call, but primcorec does not support this. So we emulate @{const bind_gpv}\n  by effectively defining two mutually recursive functions (sum type in the argument)\n  where the second is exactly @{const bind_gpv} specialised to call \\<open>inline\\<close> in the bind.\n\\<close>\n\nprimcorec inline_aux\n  :: \"('a, 'call, 'ret) gpv \\<times> 's + ('ret \\<Rightarrow> ('a, 'call, 'ret) gpv) \\<times> ('ret \\<times> 's, 'call', 'ret') gpv\n  \\<Rightarrow> ('a \\<times> 's, 'call', 'ret') gpv\"\nwhere\n  \"\\<And>state. the_gpv (inline_aux state) =\n  (case state of Inl (c, s) \\<Rightarrow> map_spmf (\\<lambda>result. \n     case result of Inl (x, s) \\<Rightarrow> Pure (x, s)\n     | Inr (out, oracle, rpv) \\<Rightarrow> IO out (\\<lambda>input. inline_aux (Inr (rpv, oracle input)))) (inline1 c s)\n  | Inr (rpv, c) \\<Rightarrow>  \n    map_spmf (\\<lambda>result. \n       case result of Inl (Inl (x, s)) \\<Rightarrow> Pure (x, s)\n       | Inl (Inr (out, oracle, rpv)) \\<Rightarrow> IO out (\\<lambda>input. inline_aux (Inr (rpv, oracle input)))\n       | Inr (out, c) \\<Rightarrow> IO out (\\<lambda>input. inline_aux (Inr (rpv, c input))))\n  (bind_spmf (the_gpv c) (\\<lambda>generat. case generat of Pure (x, s') \\<Rightarrow> (map_spmf Inl (inline1 (rpv x) s'))\n     | IO out c \\<Rightarrow> return_spmf (Inr (out, c)))\n     ))\"\n\ndeclare inline_aux.simps[simp del]\n\ndefinition inline :: \"('a, 'call, 'ret) gpv \\<Rightarrow> 's \\<Rightarrow> ('a \\<times> 's, 'call', 'ret') gpv\"\nwhere \"inline c s = inline_aux (Inl (c, s))\"\n\nlemma inline_aux_Inr:\n  \"inline_aux (Inr (rpv, oracl)) = bind_gpv oracl (\\<lambda>(x, s). inline (rpv x) s)\"\nunfolding inline_def\napply(coinduction arbitrary: oracl rule: gpv.coinduct_strong)\napply(simp add: inline_aux.sel bind_gpv.sel spmf_rel_map del: bind_gpv_sel')\napply(rule rel_spmf_bindI[where R=\"(=)\"])\napply(auto simp add: spmf_rel_map inline_aux.sel rel_spmf_reflI generat.rel_map generat.rel_refl rel_fun_def split: generat.split)\ndone\n\nlemma inline_sel:\n  \"the_gpv (inline c s) = \n   map_spmf (\\<lambda>result. case result of Inl xs \\<Rightarrow> Pure xs\n                       | Inr (out, oracle, rpv) \\<Rightarrow> IO out (\\<lambda>input. bind_gpv (oracle input) (\\<lambda>(x, s'). inline (rpv x) s'))) (inline1 c s)\"\nby(simp add: inline_def inline_aux.sel inline_aux_Inr cong del: sum.case_cong)\n\nlemma inline1_Fail [simp]: \"inline1 Fail s = return_pmf None\"\nby(rewrite inline1.simps) simp\n\nlemma inline_Fail [simp]: \"inline Fail s = Fail\"\nby(rule gpv.expand)(simp add: inline_sel)\n\nlemma inline1_Done [simp]: \"inline1 (Done x) s = return_spmf (Inl (x, s))\"\nby(rewrite inline1.simps) simp\n\nlemma inline_Done [simp]: \"inline (Done x) s = Done (x, s)\"\nby(rule gpv.expand)(simp add: inline_sel)\n\nlemma inline1_lift_spmf [simp]: \"inline1 (lift_spmf p) s = map_spmf (\\<lambda>x. Inl (x, s)) p\"\nby(rewrite inline1.simps)(simp add: bind_map_spmf o_def map_spmf_conv_bind_spmf)\n\nlemma inline_lift_spmf [simp]: \"inline (lift_spmf p) s = lift_spmf (map_spmf (\\<lambda>x. (x, s)) p)\"\nby(rule gpv.expand)(simp add: inline_sel spmf.map_comp o_def)\n\nlemma inline1_Pause:\n  \"inline1 (Pause out c) s = \n  the_gpv (callee s out) \\<bind> (\\<lambda>react. case react of Pure (x, s') \\<Rightarrow> inline1 (c x) s' | IO out' c' \\<Rightarrow> return_spmf (Inr (out', c', c)))\"\nby(rewrite inline1.simps) simp\n\nlemma inline_Pause [simp]:\n  \"inline (Pause out c) s = callee s out \\<bind> (\\<lambda>(x, s'). inline (c x) s')\"\nby(rule gpv.expand)(auto simp add: inline_sel inline1_Pause map_spmf_bind_spmf bind_gpv.sel o_def[abs_def] spmf.map_comp generat.map_comp id_def generat.map_id[unfolded id_def] simp del: bind_gpv_sel' intro!: bind_spmf_cong[OF refl] split: generat.split)\n\nlemma inline1_bind_gpv:\n  fixes gpv f s\n  defines [simp]: \"inline11 \\<equiv> inline1\" and [simp]: \"inline12 \\<equiv> inline1\" and [simp]: \"inline13 \\<equiv> inline1\"\n  shows \"inline11 (bind_gpv gpv f) s = bind_spmf (inline12 gpv s) \n    (\\<lambda>res. case res of Inl (x, s') \\<Rightarrow> inline13 (f x) s' | Inr (out, rpv', rpv) \\<Rightarrow> return_spmf (Inr (out, rpv', bind_rpv rpv f)))\"\n  (is \"?lhs = ?rhs\")\nproof(rule spmf.leq_antisym)\n  note [intro!] = ord_spmf_bind_reflI and [split] = generat.split\n  show \"ord_spmf (=) ?lhs ?rhs\" unfolding inline11_def\n  proof(induction arbitrary: gpv s f rule: inline1_fixp_induct)\n    case adm show ?case by simp\n    case bottom show ?case by simp\n    case (step inline1')\n    show ?case unfolding inline12_def\n      apply(rewrite inline1.simps; clarsimp simp add: bind_rpv_def)\n      apply(rule conjI; clarsimp)\n      subgoal premises Pure for x\n        apply(rewrite inline1.simps; clarsimp)\n        subgoal for out c ret s' using step.IH[of \"Done x\" \"\\<lambda>_. c ret\" s'] by simp\n        done\n      subgoal for out c ret s' using step.IH[of \"c ret\" f s'] by(simp cong del: sum.case_cong_weak)\n      done\n  qed\n  show \"ord_spmf (=) ?rhs ?lhs\" unfolding inline12_def\n  proof(induction arbitrary: gpv s rule: inline1_fixp_induct)\n    case adm show ?case by simp\n    case bottom show ?case by simp\n    case (step inline1')\n    show ?case unfolding inline11_def\n      apply(rewrite inline1.simps; clarsimp simp add: bind_rpv_def)\n      apply(rule conjI; clarsimp)\n      subgoal by(rewrite inline1.simps; simp)\n      subgoal for out c ret s' using step.IH[of \"c ret\" s'] by(simp cong del: sum.case_cong_weak)\n      done\n  qed\nqed\n\nlemma inline_bind_gpv [simp]:\n  \"inline (bind_gpv gpv f) s = bind_gpv (inline gpv s) (\\<lambda>(x, s'). inline (f x) s')\"\napply(coinduction arbitrary: gpv s rule: gpv_coinduct_bind)\napply(clarsimp simp add: map_spmf_bind_spmf o_def[abs_def] bind_gpv.sel inline_sel bind_map_spmf inline1_bind_gpv simp del: bind_gpv_sel' intro!: rel_spmf_bind_reflI split: generat.split)\napply(rule conjI)\n subgoal by(auto split: sum.split_asm simp add: spmf_rel_map spmf.map_comp o_def generat.map_comp generat.map_id[unfolded id_def] spmf.map_id[unfolded id_def] inline_sel intro!: rel_spmf_reflI generat.rel_refl fun.rel_refl)\nby(auto split: sum.split_asm simp add: bind_gpv_assoc split_def intro!: gpv.rel_refl exI disjI2 rel_funI)\n\nend\n\nlemma set_inline1_lift_spmf1: \"set_spmf (inline1 (\\<lambda>s x. lift_spmf (p s x)) gpv s) \\<subseteq> range Inl\"\napply(induction arbitrary: gpv s rule: inline1_fixp_induct)\nsubgoal by(rule cont_intro ccpo_class.admissible_leI)+\napply(auto simp add: o_def bind_UNION split: generat.split_asm)+\ndone\n\nlemma in_set_inline1_lift_spmf1: \"y \\<in> set_spmf (inline1 (\\<lambda>s x. lift_spmf (p s x)) gpv s) \\<Longrightarrow> \\<exists>r s'. y = Inl (r, s')\"\nby(drule set_inline1_lift_spmf1[THEN subsetD]) auto\n\nlemma inline_lift_spmf1:\n  fixes p defines \"callee \\<equiv> \\<lambda>s c. lift_spmf (p s c)\"\n  shows \"inline callee gpv s = lift_spmf (map_spmf projl (inline1 callee gpv s))\"\nby(rule gpv.expand)(auto simp add: inline_sel spmf.map_comp callee_def intro!: map_spmf_cong[OF refl] dest: in_set_inline1_lift_spmf1)\n\ncontext includes lifting_syntax begin\nlemma inline1_parametric':\n  \"((S ===> C ===> rel_gpv'' (rel_prod R S) C' R') ===> rel_gpv'' A C R ===> S\n   ===> rel_spmf (rel_sum (rel_prod A S) (rel_prod C' (rel_prod (R' ===> rel_gpv'' (rel_prod R S) C' R') (R ===> rel_gpv'' A C R)))))\n  inline1 inline1\"\n  (is \"(_ ===> ?R) _ _\")\nproof(rule rel_funI)\n  note [transfer_rule] = the_gpv_parametric'\n  show \"?R (inline1 callee) (inline1 callee')\" \n    if [transfer_rule]: \"(S ===> C ===> rel_gpv'' (rel_prod R S) C' R') callee callee'\"\n    for callee callee'\n    unfolding inline1_def\n    by(unfold rel_fun_curry case_prod_curry)(rule fixp_spmf_parametric[OF inline1.mono inline1.mono]; transfer_prover)\nqed\n\nlemma inline1_parametric [transfer_rule]:\n  \"((S ===> C ===> rel_gpv (rel_prod (=) S) C') ===> rel_gpv A C ===> S\n   ===> rel_spmf (rel_sum (rel_prod A S) (rel_prod C' (rel_prod (rel_rpv (rel_prod (=) S) C') (rel_rpv A C)))))\n  inline1 inline1\"\nunfolding rel_gpv_conv_rel_gpv'' by(rule inline1_parametric')\n\nlemma inline_parametric':\n  notes [transfer_rule] = inline1_parametric' the_gpv_parametric' corec_gpv_parametric'\n  shows \"((S ===> C ===> rel_gpv'' (rel_prod R S) C' R') ===> rel_gpv'' A C R ===> S ===> rel_gpv'' (rel_prod A S) C' R')\n  inline inline\"\nunfolding inline_def[abs_def] inline_aux_def\n(* apply transfer_prover raises loose bound variable *)\napply(rule rel_funI)+\nsubgoal premises [transfer_rule] by transfer_prover\ndone\n\nlemma inline_parametric [transfer_rule]:\n  \"((S ===> C ===> rel_gpv (rel_prod (=) S) C') ===> rel_gpv A C ===> S ===> rel_gpv (rel_prod A S) C')\n  inline inline\"\nunfolding rel_gpv_conv_rel_gpv'' by(rule inline_parametric')\nend\n\n\ntext \\<open>Associativity rule for @{const inline}\\<close>\n\ncontext\n  fixes callee1 :: \"'s1 \\<Rightarrow> 'c1 \\<Rightarrow> ('r1 \\<times> 's1, 'c, 'r) gpv\"\n  and callee2 :: \"'s2 \\<Rightarrow> 'c2 \\<Rightarrow> ('r2 \\<times> 's2, 'c1, 'r1) gpv\"\nbegin\n\npartial_function (spmf) inline2 :: \"('a, 'c2, 'r2) gpv \\<Rightarrow> 's2 \\<Rightarrow> 's1\n  \\<Rightarrow> ('a \\<times> ('s2 \\<times> 's1) + 'c \\<times> ('r1 \\<times> 's1, 'c, 'r) rpv \\<times> ('r2 \\<times> 's2, 'c1, 'r1) rpv \\<times> ('a, 'c2, 'r2) rpv) spmf\"\nwhere\n  \"inline2 gpv s2 s1 =\n  bind_spmf (the_gpv gpv)\n   (case_generat (\\<lambda>x. return_spmf (Inl (x, s2, s1)))\n     (\\<lambda>out rpv. bind_spmf (inline1 callee1 (callee2 s2 out) s1)\n       (case_sum (\\<lambda>((r2, s2), s1). inline2 (rpv r2) s2 s1)\n         (\\<lambda>(x, rpv'', rpv'). return_spmf (Inr (x, rpv'', rpv', rpv))))))\"\n\nlemma inline2_fixp_induct [case_names adm bottom step]:\n  assumes \"ccpo.admissible (fun_lub lub_spmf) (fun_ord (ord_spmf (=))) (\\<lambda>inline2. P (\\<lambda>gpv s2 s1. inline2 ((gpv, s2), s1)))\"\n  and \"P (\\<lambda>_ _ _. return_pmf None)\"\n  and \"\\<And>inline2'. P inline2' \\<Longrightarrow>\n       P (\\<lambda>gpv s2 s1. bind_spmf (the_gpv gpv) (\\<lambda>generat. case generat of\n           Pure x \\<Rightarrow> return_spmf (Inl (x, s2, s1))\n         | IO out rpv \\<Rightarrow> bind_spmf (inline1 callee1 (callee2 s2 out) s1) (\\<lambda>lr. case lr of\n              Inl ((r2, s2), c) \\<Rightarrow> inline2' (rpv r2) s2 c\n           | Inr (x, rpv'', rpv') \\<Rightarrow> return_spmf (Inr (x, rpv'', rpv', rpv)))))\"\n  shows \"P inline2\"\nusing assms unfolding split_def by(rule inline2.fixp_induct[unfolded curry_conv[abs_def] split_def])\n\nlemma inline1_inline_conv_inline2:\n  fixes gpv' :: \"('r2 \\<times> 's2, 'c1, 'r1) gpv\"\n  shows \"inline1 callee1 (inline callee2 gpv s2) s1 = \n  map_spmf (map_sum (\\<lambda>(x, (s2, s1)). ((x, s2), s1))\n    (\\<lambda>(x, rpv'', rpv', rpv). (x, rpv'', \\<lambda>r1. rpv' r1 \\<bind> (\\<lambda>(r2, s2). inline callee2 (rpv r2) s2))))\n  (inline2 gpv s2 s1)\"\n  (is \"?lhs = ?rhs\")\nproof(rule spmf.leq_antisym)\n  define inline1_1 :: \"('s1 \\<Rightarrow> 'c1 \\<Rightarrow> ('r1 \\<times> 's1, 'c, 'r) gpv) \\<Rightarrow> ('r2 \\<times> 's2, 'c1, 'r1) gpv \\<Rightarrow> 's1 \\<Rightarrow> _\"\n    where \"inline1_1 = inline1\"\n  have \"ord_spmf (=) ?lhs ?rhs\"\n    \\<comment> \\<open>We need in the inductive step that the approximation behaves well with @{const bind_gpv}\n         because of @{thm [source] inline_aux_Inr}. So we have to thread it through the induction\n         and do one half of the proof from @{thm [source] inline1_bind_gpv} again. We cannot inline\n         @{thm [source] inline1_bind_gpv} in this proof here because the types are too specific.\\<close>\n    and \"ord_spmf (=) (inline1 callee1 (gpv' \\<bind> f) s1') \n      (do {\n      res \\<leftarrow> inline1_1 callee1 gpv' s1';\n      case res of Inl (x, s') \\<Rightarrow> inline1 callee1 (f x) s'\n      | Inr (out, rpv', rpv) \\<Rightarrow> return_spmf (Inr (out, rpv', rpv \\<bind> f))\n    })\" for gpv' and f :: \"_ \\<Rightarrow> ('a \\<times> 's2, 'c1, 'r1) gpv\" and s1'\n  proof(induction arbitrary: gpv s2 s1 gpv' f s1' rule: inline1_fixp_induct_strong2)\n    case adm thus ?case\n      apply(rule cont_intro)+\n      subgoal for a b c d by(cases d; clarsimp)\n      done\n\n    case (step inline1')\n    note step_IH = step.IH[unfolded inline1_1_def] and step_hyps = step.hyps[unfolded inline1_1_def]\n    { case 1\n      have inline1: \"ord_spmf (=)\n         (inline1 callee2 gpv s2 \\<bind> (\\<lambda>lr. case lr of Inl as2 \\<Rightarrow> return_spmf (Inl (as2, s1))\n            | Inr (out1, rpv', rpv) \\<Rightarrow> the_gpv (callee1 s1 out1) \\<bind> (\\<lambda>generat. case generat of\n                Pure (r1, s1) \\<Rightarrow> inline1' (bind_gpv (rpv' r1) (\\<lambda>(r2, s2). inline callee2 (rpv r2) s2)) s1\n              | IO out rpv'' \\<Rightarrow> return_spmf (Inr (out, rpv'', \\<lambda>r1. bind_gpv (rpv' r1) (\\<lambda>(r2, s2). inline callee2 (rpv r2) s2)) ))))\n         (the_gpv gpv \\<bind> (\\<lambda>generat. case generat of Pure x \\<Rightarrow> return_spmf (Inl ((x, s2), s1))\n            | IO out2 rpv \\<Rightarrow> inline1_1 callee1 (callee2 s2 out2) s1 \\<bind> (\\<lambda>lr. case lr of\n                Inl ((r2, s2), s1) \\<Rightarrow>\n                   map_spmf (map_sum (\\<lambda>(x, s2, s1). ((x, s2), s1)) (\\<lambda>(x, rpv'', rpv', rpv). (x, rpv'', \\<lambda>r1. bind_gpv (rpv' r1) (\\<lambda>(r2, s2). inline callee2 (rpv r2) s2))))\n                     (inline2 (rpv r2) s2 s1)\n              | Inr (out, rpv'', rpv') \\<Rightarrow>\n                   return_spmf (Inr (out, rpv'', \\<lambda>r1. bind_gpv (rpv' r1) (\\<lambda>(r2, s2). inline callee2 (rpv r2) s2))))))\"\n      proof(induction arbitrary: gpv s2 s1 rule: inline1_fixp_induct)\n        case step2: (step inline1'')\n        note step2_IH = step2.IH[unfolded inline1_1_def]\n\n        show ?case unfolding inline1_1_def\n          apply(rewrite in \"ord_spmf _ _ \\<hole>\" inline1.simps)\n          apply(clarsimp intro!: ord_spmf_bind_reflI split: generat.split)\n          apply(rule conjI)\n          subgoal by(rewrite in \"ord_spmf _ _ \\<hole>\" inline2.simps)(clarsimp simp add: map_spmf_bind_spmf o_def split: generat.split sum.split intro!: ord_spmf_bind_reflI spmf.leq_trans[OF step2_IH])\n          subgoal by(clarsimp intro!: ord_spmf_bind_reflI step_IH[THEN spmf.leq_trans] split: generat.split sum.split simp add: bind_rpv_def)\n          done\n      qed simp_all\n      show ?case\n        apply(rewrite in \"ord_spmf _ \\<hole> _\" inline_sel)\n        apply(rewrite in \"ord_spmf _ _ \\<hole>\" inline2.simps)\n        apply(clarsimp simp add: map_spmf_bind_spmf bind_map_spmf o_def intro!: ord_spmf_bind_reflI split: generat.split)\n        apply(rule spmf.leq_trans[OF spmf.leq_trans, OF _ inline1])\n        apply(auto intro!: ord_spmf_bind_reflI split: sum.split generat.split simp add: inline1_1_def map_spmf_bind_spmf)\n        done }\n    { case 2\n      show ?case unfolding inline1_1_def\n        by(rewrite inline1.simps)(auto simp del: bind_gpv_sel' simp add: bind_gpv.sel map_spmf_bind_spmf bind_map_spmf o_def bind_rpv_def intro!: ord_spmf_bind_reflI step_IH(2)[THEN spmf.leq_trans] step_hyps(2) split: generat.split sum.split) }\n  qed simp_all\n  thus \"ord_spmf (=) ?lhs ?rhs\" by -\n\n  show \"ord_spmf (=) ?rhs ?lhs\"\n  proof(induction arbitrary: gpv s2 s1 rule: inline2_fixp_induct)\n    case adm show ?case by simp\n    case bottom show ?case by simp\n    case (step inline2')\n    show ?case\n      apply(rewrite in \"ord_spmf _ _ \\<hole>\" inline1.simps)\n      apply(rewrite inline_sel)\n      apply(rewrite in \"ord_spmf _ \\<hole> _\" inline1.simps)\n      apply(rewrite in \"ord_spmf _ _ \\<hole>\" inline1.simps)\n      apply(clarsimp simp add: map_spmf_bind_spmf bind_map_spmf intro!: ord_spmf_bind_reflI split: generat.split)\n      apply(rule conjI)\n      subgoal\n         apply clarsimp\n         apply(rule step.IH[THEN spmf.leq_trans])\n         apply(rewrite in \"ord_spmf _ \\<hole> _\" inline1.simps)\n         apply(rewrite inline_sel)\n         apply(simp add: bind_map_spmf)\n         done\n      subgoal by(clarsimp intro!: ord_spmf_bind_reflI split: generat.split sum.split simp add: o_def inline1_bind_gpv bind_rpv_def step.IH)\n      done\n  qed\nqed\n\nlemma inline1_inline_conv_inline2':\n  \"inline1 (\\<lambda>(s2, s1) c2. map_gpv (\\<lambda>((r, s2), s1). (r, s2, s1)) id (inline callee1 (callee2 s2 c2) s1)) gpv (s2, s1) =\n   map_spmf (map_sum id (\\<lambda>(x, rpv'', rpv', rpv). (x, \\<lambda>r. bind_gpv (rpv'' r)\n       (\\<lambda>(r1, s1). map_gpv (\\<lambda>((r2, s2), s1). (r2, s2, s1)) id (inline callee1 (rpv' r1) s1)), rpv)))\n     (inline2 gpv s2 s1)\"\n  (is \"?lhs = ?rhs\")\nproof(rule spmf.leq_antisym)\n  show \"ord_spmf (=) ?lhs ?rhs\"\n  proof(induction arbitrary: gpv s2 s1 rule: inline1_fixp_induct)\n    case (step inline1') show ?case\n      by(rewrite inline2.simps)(auto simp add: map_spmf_bind_spmf o_def inline_sel gpv.map_sel bind_map_spmf id_def[symmetric] gpv.map_id map_gpv_bind_gpv split_def intro!: ord_spmf_bind_reflI step.IH[THEN spmf.leq_trans] split: generat.split sum.split)\n  qed simp_all\n  show \"ord_spmf (=) ?rhs ?lhs\"\n  proof(induction arbitrary: gpv s2 s1 rule: inline2_fixp_induct)\n   case (step inline2')\n   show ?case\n     apply(rewrite in \"ord_spmf _ _ \\<hole>\" inline1.simps)\n     apply(clarsimp simp add: map_spmf_bind_spmf bind_rpv_def o_def gpv.map_sel bind_map_spmf inline_sel map_gpv_bind_gpv id_def[symmetric] gpv.map_id split_def split: generat.split sum.split intro!: ord_spmf_bind_reflI)\n     apply(rule spmf.leq_trans[OF spmf.leq_trans, OF _ step.IH])\n     apply(auto simp add: split_def id_def[symmetric] intro!: ord_spmf_reflI)\n     done\n  qed simp_all\nqed\n\nlemma inline_assoc:\n  \"inline callee1 (inline callee2 gpv s2) s1 =\n   map_gpv (\\<lambda>(r, s2, s1). ((r, s2), s1)) id (inline (\\<lambda>(s2, s1) c2. map_gpv (\\<lambda>((r, s2), s1). (r, s2, s1)) id (inline callee1 (callee2 s2 c2) s1)) gpv (s2, s1))\"\nproof(coinduction arbitrary: s2 s1 gpv rule: gpv_coinduct_bind[where ?'b = \"('r2 \\<times> 's2) \\<times> 's1\" and ?'c = \"('r2 \\<times> 's2) \\<times> 's1\"])\n  case (Eq_gpv s2 s1 gpv)\n  have \"\\<exists>gpv2 gpv2' (f :: ('r2 \\<times> 's2) \\<times> 's1 \\<Rightarrow> _) (f' :: ('r2 \\<times> 's2) \\<times> 's1 \\<Rightarrow> _).\n          bind_gpv (bind_gpv (rpv'' r) (\\<lambda>(r1, s1). inline callee1 (rpv' r1) s1)) (\\<lambda>((r2, s2), s1). inline callee1 (inline callee2 (rpv r2) s2) s1) = gpv2 \\<bind> f \\<and>\n          bind_gpv (bind_gpv (rpv'' r) (\\<lambda>(r1, s1). inline callee1 (rpv' r1) s1)) (\\<lambda>((r2, s2), s1). map_gpv (\\<lambda>(r, s2, y). ((r, s2), y)) id (inline (\\<lambda>(s2, s1) c2. map_gpv (\\<lambda>((r, s2), s1). (r, s2, s1)) id (inline callee1 (callee2 s2 c2) s1)) (rpv r2) (s2, s1))) = gpv2' \\<bind> f' \\<and>\n          rel_gpv (\\<lambda>x y. \\<exists>s2 s1 gpv. f x = inline callee1 (inline callee2 gpv s2) s1 \\<and>\n              f' y = map_gpv (\\<lambda>(r, s2, y). ((r, s2), y)) id (inline (\\<lambda>(s2, s1) c2. map_gpv (\\<lambda>((r, s2), s1). (r, s2, s1)) id (inline callee1 (callee2 s2 c2) s1)) gpv (s2, s1)))\n            (=) gpv2 gpv2'\" \n    for rpv'' :: \"('r1 \\<times> 's1, 'c, 'r) rpv\" and rpv' :: \"('r2 \\<times> 's2, 'c1, 'r1) rpv\" and rpv :: \"('a, 'c2, 'r2) rpv\" and r :: 'r\n    by(auto intro!: exI gpv.rel_refl)\n  then show ?case\n    apply(subst inline_sel)\n    apply(subst gpv.map_sel)\n    apply(subst inline_sel)\n    apply(subst inline1_inline_conv_inline2)\n    apply(subst inline1_inline_conv_inline2')\n    apply(unfold spmf.map_comp o_def case_sum_map_sum spmf_rel_map generat.rel_map)\n    apply(rule rel_spmf_reflI)\n    subgoal for lr by(cases lr)(auto del: disjCI intro!: rel_funI disjI2 simp add: split_def map_gpv_conv_bind[folded id_def] bind_gpv_assoc)\n    done\nqed\n\nend\n\nlemma set_inline2_lift_spmf1: \"set_spmf (inline2 (\\<lambda>s x. lift_spmf (p s x)) callee gpv s s') \\<subseteq> range Inl\"\napply(induction arbitrary: gpv s s' rule: inline2_fixp_induct)\nsubgoal by(rule cont_intro ccpo_class.admissible_leI)+\napply(auto simp add: o_def bind_UNION split: generat.split_asm sum.split_asm dest!: in_set_inline1_lift_spmf1)\napply blast\ndone\n\nlemma in_set_inline2_lift_spmf1: \"y \\<in> set_spmf (inline2 (\\<lambda>s x. lift_spmf (p s x)) callee gpv s s') \\<Longrightarrow> \\<exists>r s s'. y = Inl (r, s, s')\"\nby(drule set_inline2_lift_spmf1[THEN subsetD]) auto\n\ncontext\n  fixes consider' :: \"'call \\<Rightarrow> bool\" \n  and \"consider\" :: \"'call' \\<Rightarrow> bool\" \n  and callee :: \"'s \\<Rightarrow> 'call \\<Rightarrow> ('ret \\<times> 's, 'call', 'ret') gpv\" \n  notes [[function_internals]]\nbegin\n\nprivate partial_function (spmf) inline1'\n  :: \"('a, 'call, 'ret) gpv \\<Rightarrow> 's\n  \\<Rightarrow> ('a \\<times> 's + 'call \\<times> 'call' \\<times> ('ret \\<times> 's, 'call', 'ret') rpv \\<times> ('a, 'call, 'ret) rpv) spmf\"\nwhere\n  \"inline1' gpv s =\n   the_gpv gpv \\<bind>\n   case_generat (\\<lambda>x. return_spmf (Inl (x, s)))\n     (\\<lambda>out rpv. the_gpv (callee s out) \\<bind>\n         case_generat (\\<lambda>(x, y). inline1' (rpv x) y)\n          (\\<lambda>out' rpv'. return_spmf (Inr (out, out', rpv', rpv))))\"\n\nprivate lemma inline1'_fixp_induct [case_names adm bottom step]:\n  assumes \"ccpo.admissible (fun_lub lub_spmf) (fun_ord (ord_spmf (=))) (\\<lambda>inline1'. P (\\<lambda>gpv s. inline1' (gpv, s)))\"\n  and \"P (\\<lambda>_ _. return_pmf None)\"\n  and \"\\<And>inline1'. P inline1' \\<Longrightarrow> P (\\<lambda>gpv s. the_gpv gpv \\<bind> case_generat (\\<lambda>x. return_spmf (Inl (x, s))) (\\<lambda>out rpv. the_gpv (callee s out) \\<bind> case_generat (\\<lambda>(x, y). inline1' (rpv x) y) (\\<lambda>out' rpv'. return_spmf (Inr (out, out', rpv', rpv)))))\"\n  shows \"P inline1'\"\nusing assms by(rule inline1'.fixp_induct[unfolded curry_conv[abs_def]])\n\nprivate lemma inline1_conv_inline1': \"inline1 callee gpv s = map_spmf (map_sum id snd) (inline1' gpv s)\"\nproof(induction arbitrary: gpv s rule: parallel_fixp_induct_2_2[OF partial_function_definitions_spmf partial_function_definitions_spmf inline1.mono inline1'.mono inline1_def inline1'_def, unfolded lub_spmf_empty, case_names adm bottom step])\n  case adm show ?case by simp\n  case bottom show ?case by simp\n  case (step inline1 inline1')\n  thus ?case by(clarsimp simp add: map_spmf_bind_spmf o_def intro!: bind_spmf_cong[OF refl] split: generat.split)\nqed\n\ncontext\n  fixes q :: \"enat\" \n  assumes q: \"\\<And>s x. consider' x \\<Longrightarrow> interaction_bound consider (callee s x) \\<le> q\"\n  and ignore: \"\\<And>s x. \\<not> consider' x \\<Longrightarrow> interaction_bound consider (callee s x) = 0\"\nbegin\n\nprivate lemma interaction_bound_inline1'_aux:\n  \"interaction_bound consider' gpv \\<le> p\n  \\<Longrightarrow> set_spmf (inline1' gpv s) \\<subseteq> {Inr (out', out, c', rpv) | out' out c' rpv. \n        if consider' out'\n        then (\\<forall>input. (if consider out then eSuc (interaction_bound consider (c' input)) else interaction_bound consider (c' input)) \\<le> q) \\<and> \n             (\\<forall>x. eSuc (interaction_bound consider' (rpv x)) \\<le> p)\n        else \\<not> consider out \\<and> (\\<forall>input. interaction_bound consider (c' input) = 0) \\<and> (\\<forall>x. interaction_bound consider' (rpv x) \\<le> p)}\n      \\<union> range Inl\"\nproof(induction arbitrary: gpv s rule: inline1'_fixp_induct)\n  { case adm show ?case by(rule cont_intro ccpo_class.admissible_leI)+ }\n  { case bottom show ?case by simp }\n  case (step inline1')\n  have *: \"interaction_bound consider' (c input) \\<le> p\" if \"IO out c \\<in> set_spmf (the_gpv gpv)\" for out c input\n    by(cases \"consider' out\")(auto intro: interaction_bound_IO_consider[OF that, THEN order_trans, THEN order_trans[OF ile_eSuc]] interaction_bound_IO_ignore[OF that, THEN order_trans] step.prems)\n  have **: \"if consider' out'\n    then (\\<forall>input. (if consider out then eSuc (interaction_bound consider (c input))  else interaction_bound consider (c input)) \\<le> q) \\<and>\n         (\\<forall>x. eSuc (interaction_bound consider' (rpv x)) \\<le> p)\n    else \\<not> consider out \\<and> (\\<forall>input. interaction_bound consider (c input) = 0) \\<and> (\\<forall>x. interaction_bound consider' (rpv x) \\<le> p)\"\n    if \"IO out' rpv \\<in> set_spmf (the_gpv gpv)\" \"IO out c \\<in> set_spmf (the_gpv (callee s out'))\"\n    for out' rpv out c\n  proof(cases \"consider' out'\")\n    case True\n    then show ?thesis using that q\n      by(auto split del: if_split intro!: interaction_bound_IO[THEN order_trans] interaction_bound_IO_consider[THEN order_trans] step.prems)\n  next\n    case False\n    have \"\\<not> consider out\" \"interaction_bound consider (c input) = 0\" for input\n      using interaction_bound_IO[OF that(2), of \"consider\" input] ignore[OF False, of s]\n      by(auto split: if_split_asm)\n    then show ?thesis using False that\n      by(auto split del: if_split intro: interaction_bound_IO_ignore[THEN order_trans] step.prems)\n  qed\n  show ?case\n    by(auto 6 4 simp add: bind_UNION del: subsetI intro!: UN_least intro: step.IH * ** split: generat.split split del: if_split)\nqed\n\nlemma interaction_bound_inline1':\n  \"\\<lbrakk> Inr (out', out, c', rpv) \\<in> set_spmf (inline1' gpv s); interaction_bound consider' gpv \\<le> p \\<rbrakk>\n  \\<Longrightarrow> if consider' out' then\n        (if consider out then eSuc (interaction_bound consider (c' input)) else interaction_bound consider (c' input)) \\<le> q \\<and> \n        eSuc (interaction_bound consider' (rpv x)) \\<le> p\n      else \\<not> consider out \\<and> interaction_bound consider (c' input) = 0 \\<and> interaction_bound consider' (rpv x) \\<le> p\"\nusing interaction_bound_inline1'_aux[where gpv=gpv and p=p and s=s] by(auto split: if_split_asm)\n\nend\n\nlemma interaction_bounded_by_inline1:\n  \"\\<lbrakk> Inr (out', out, c', rpv) \\<in> set_spmf (inline1' gpv s); \n    interaction_bounded_by consider' gpv p;\n    \\<And>s x. consider' x \\<Longrightarrow> interaction_bounded_by consider (callee s x) q; \n    \\<And>s x. \\<not> consider' x \\<Longrightarrow> interaction_bounded_by consider (callee s x) 0 \\<rbrakk>\n  \\<Longrightarrow> if consider' out' then\n        (if consider out then q \\<noteq> 0 \\<and> interaction_bounded_by consider (c' input) (q - 1) else interaction_bounded_by consider (c' input) q) \\<and>\n        p \\<noteq> 0 \\<and> interaction_bounded_by consider' (rpv x) (p - 1)\n      else \\<not> consider out \\<and> interaction_bounded_by consider (c' input) 0 \\<and> interaction_bounded_by consider' (rpv x) p\"\nunfolding interaction_bounded_by_0 unfolding interaction_bounded_by.simps\napply(drule (1) interaction_bound_inline1'[where input=input and x=x, rotated 2], assumption, assumption)\napply(cases p q rule: co.enat.exhaust[case_product co.enat.exhaust])\napply(simp_all add: zero_enat_def[symmetric] eSuc_enat[symmetric] split: if_split_asm)\ndone\n\ndeclare enat_0_iff [simp]\n\nlemma interaction_bounded_by_inline [interaction_bound]:\n  assumes p: \"interaction_bounded_by consider' gpv p\"\n  and q: \"\\<And>s x. consider' x \\<Longrightarrow> interaction_bounded_by consider (callee s x) q\"\n  and ignore: \"\\<And>s x. \\<not> consider' x \\<Longrightarrow> interaction_bounded_by consider (callee s x) 0\"\n  shows \"interaction_bounded_by consider (inline callee gpv s) (p * q)\"\nproof\n  have \"interaction_bounded_by consider' gpv p \\<Longrightarrow> interaction_bound consider (inline callee gpv s) \\<le> p * q\"\n    and \"interaction_bound consider (bind_gpv gpv' f) \\<le> interaction_bound consider gpv' + (SUP x\\<in>results'_gpv gpv'. interaction_bound consider (f x))\"\n    for gpv' and f :: \"'ret \\<times> 's \\<Rightarrow> ('a \\<times> 's, 'call', 'ret') gpv\"\n  proof(induction arbitrary: gpv s p gpv' f rule: interaction_bound_fixp_induct)\n    case adm show ?case by simp\n    case bottom case 1 show ?case by simp\n    case (step interaction_bound') case step: 1\n    show ?case (is \"(SUP generat\\<in>?inline. ?lhs generat) \\<le> ?rhs\")\n    proof(rule SUP_least)\n      fix generat\n      assume \"generat \\<in> ?inline\"\n      then consider (Pure) ret s' where \"generat = Pure (ret, s')\"\n          and \"Inl (ret, s') \\<in> set_spmf (inline1 callee gpv s)\"\n        | (IO) out c rpv where \"generat = IO out (\\<lambda>input. bind_gpv (c input) (\\<lambda>(ret, s'). inline callee (rpv ret) s'))\"\n          and \"Inr (out, c, rpv) \\<in> set_spmf (inline1 callee gpv s)\"\n        by(clarsimp simp add: inline_sel split: sum.split_asm)\n      then show \"?lhs generat \\<le> ?rhs\"\n      proof(cases)\n        case Pure thus ?thesis by simp\n      next\n        case IO\n        from IO(2) obtain out' where out': \"Inr (out', out, c, rpv) \\<in> set_spmf (inline1' gpv s)\"\n          by(auto simp add: inline1_conv_inline1' Inr_eq_map_sum_iff)\n        show ?thesis\n        proof(cases \"consider' out'\")\n          case True\n          with interaction_bounded_by_inline1[OF out' step.prems q ignore]\n          have p: \"p \\<noteq> 0\" and rpv: \"\\<And>x. interaction_bounded_by consider' (rpv x) (p - 1)\"\n            and c: \"\\<And>input. if consider out then q \\<noteq> 0 \\<and> interaction_bounded_by consider (c input) (q - 1) else interaction_bounded_by consider (c input) q\"\n            by auto\n\n          have \"?lhs generat \\<le> (if consider out then 1 else 0) + (SUP input. interaction_bound' (bind_gpv (c input) (\\<lambda>(ret, s'). inline callee (rpv ret) s')))\"\n            (is \"_ \\<le> _ + ?sup\")\n            using IO(1) by(auto simp add: plus_1_eSuc)\n          also have \"?sup \\<le> (SUP input. interaction_bound consider (c input) + (SUP (ret, s') \\<in> results'_gpv (c input). interaction_bound' (inline callee (rpv ret) s')))\"\n            unfolding split_def by(rule SUP_mono)(blast intro: step.IH)\n          also have \"\\<dots> \\<le> (SUP input. interaction_bound consider (c input) + (SUP (ret, s') \\<in> results'_gpv (c input). (p - 1) * q))\"\n            using rpv by(auto intro!: SUP_mono rev_bexI add_mono step.IH)\n          also have \"\\<dots> \\<le> (SUP input. interaction_bound consider (c input) + (p - 1) * q)\"\n            apply(auto simp add: SUP_constant bot_enat_def intro!: SUP_mono)\n            apply(metis add.right_neutral add_mono i0_lb order_refl)+\n            done\n          also have \"\\<dots> \\<le> (SUP input :: 'ret'. (if consider out then q - 1 else q) + (p - 1) * q)\"\n            apply(rule SUP_mono rev_bexI UNIV_I add_mono)+\n            using c\n            apply(auto simp add: interaction_bounded_by.simps)\n            done\n          also have \"\\<dots> = (if consider out then q - 1 else q) + (p - 1) * q\"\n            by(simp add: SUP_constant)\n          finally show ?thesis\n            apply(rule order_trans)\n            prefer 5\n            using p c\n            apply(cases p; cases q)\n            apply(auto simp add: one_enat_def algebra_simps Suc_leI)\n            done\n        next\n          case False\n          with interaction_bounded_by_inline1[OF out' step.prems q ignore]\n          have out: \"\\<not> consider out\" and zero: \"\\<And>input. interaction_bounded_by consider (c input) 0\"\n            and rpv: \"\\<And>x. interaction_bounded_by consider' (rpv x) p\" by auto\n          have \"?lhs generat \\<le> (SUP input. interaction_bound' (bind_gpv (c input) (\\<lambda>(ret, s'). inline callee (rpv ret) s')))\"\n            using IO(1) out by auto\n          also have \"\\<dots> \\<le> (SUP input. interaction_bound consider (c input) + (SUP (ret, s') \\<in> results'_gpv (c input). interaction_bound' (inline callee (rpv ret) s')))\"\n            unfolding split_def by(rule SUP_mono)(blast intro: step.IH)\n          also have \"\\<dots> \\<le> (SUP input. (SUP (ret, s') \\<in> results'_gpv (c input). p * q))\"\n            using rpv zero by(auto intro!: SUP_mono rev_bexI add_mono step.IH simp add: interaction_bounded_by_0)\n          also have \"\\<dots> \\<le> (SUP input :: 'ret'. p * q)\"\n            by(rule SUP_mono rev_bexI)+(auto simp add: SUP_constant)\n          also have \"\\<dots> = p * q\" by(simp add: SUP_constant)\n          finally show ?thesis .\n        qed\n      qed\n    qed\n  next\n    case bottom case 2 show ?case by simp\n    case step case 2 show ?case using step by -(rule interaction_bound_bind_step)\n  qed\n  then show \"interaction_bound consider (inline callee gpv s) \\<le> p * q\" using p by -\nqed\n\nend\n\nlemma interaction_bounded_by_inline_invariant: (* TODO: augment with types *)\n  includes lifting_syntax\n  fixes consider' :: \"'call \\<Rightarrow> bool\" \n  and \"consider\" :: \"'call' \\<Rightarrow> bool\" \n  and callee :: \"'s \\<Rightarrow> 'call \\<Rightarrow> ('ret \\<times> 's, 'call', 'ret') gpv\" \n  and gpv :: \"('a, 'call, 'ret) gpv\"\n  assumes p: \"interaction_bounded_by consider' gpv p\"\n  and q: \"\\<And>s x. \\<lbrakk> I s; consider' x \\<rbrakk> \\<Longrightarrow> interaction_bounded_by consider (callee s x) q\"\n  and ignore: \"\\<And>s x. \\<lbrakk> I s; \\<not> consider' x \\<rbrakk> \\<Longrightarrow> interaction_bounded_by consider (callee s x) 0\"\n  and I: \"I s\"\n  and invariant: \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> results'_gpv (callee s x); I s \\<rbrakk> \\<Longrightarrow> I s'\"\n  shows \"interaction_bounded_by consider (inline callee gpv s) (p * q)\"\nproof -\n  { assume \"\\<exists>(Rep :: 's' \\<Rightarrow> 's) Abs. type_definition Rep Abs {s. I s}\"\n    then obtain Rep :: \"'s' \\<Rightarrow> 's\" and Abs where td: \"type_definition Rep Abs {s. I s}\" by blast\n    then interpret td: type_definition Rep Abs \"{s. I s}\" .\n    define cr where \"cr x y \\<longleftrightarrow> x = Rep y\" for x y\n    have [transfer_rule]: \"bi_unique cr\" \"right_total cr\"\n      using td cr_def[abs_def] by(rule typedef_bi_unique typedef_right_total)+\n    have [transfer_domain_rule]: \"Domainp cr = I\"\n      using type_definition_Domainp[OF td cr_def[abs_def]] by simp\n\n    define callee' where \"callee' = (Rep --->  id ---> map_gpv (map_prod id Abs) id) callee\"\n    have [transfer_rule]: \"(cr ===> (=) ===> rel_gpv (rel_prod (=) cr) (=)) callee callee'\"\n      by(auto simp add: callee'_def rel_fun_def cr_def gpv.rel_map prod.rel_map td.Abs_inverse intro!: gpv.rel_refl_strong intro: td.Rep[simplified] dest: invariant)\n\n    define s' where \"s' = Abs s\"\n    have [transfer_rule]: \"cr s s'\" using I by(simp add: cr_def s'_def td.Abs_inverse)\n\n    note p moreover\n    have \"consider' x \\<Longrightarrow> interaction_bounded_by consider (callee' s x) q\" for s x\n      by(transfer fixing: \"consider\" consider' q)(clarsimp simp add: q)\n    moreover have \"\\<not> consider' x \\<Longrightarrow> interaction_bounded_by consider (callee' s x) 0\" for s x\n      by(transfer fixing: \"consider\" consider')(clarsimp simp add: ignore)\n    ultimately have \"interaction_bounded_by consider (inline callee' gpv s') (p * q)\" \n      by(rule interaction_bounded_by_inline)\n    then have \"interaction_bounded_by consider (inline callee gpv s) (p * q)\" by transfer  }\n  from this[cancel_type_definition] I show ?thesis by blast\nqed\n\ncontext\n  fixes \\<I> :: \"('call, 'ret) \\<I>\"\n  and \\<I>' :: \"('call', 'ret') \\<I>\"\n  and callee :: \"'s \\<Rightarrow> 'call \\<Rightarrow> ('ret \\<times> 's, 'call', 'ret') gpv\"\n  assumes results: \"\\<And>s x. x \\<in> outs_\\<I> \\<I> \\<Longrightarrow> results_gpv \\<I>' (callee s x) \\<subseteq> responses_\\<I> \\<I> x \\<times> UNIV\"\nbegin\n\nlemma inline1_in_sub_gpvs_callee:\n  assumes \"Inr (out, callee', rpv') \\<in> set_spmf (inline1 callee gpv s)\"\n  and WT: \"\\<I> \\<turnstile>g gpv \\<surd>\"\n  shows \"\\<exists>call\\<in>outs_\\<I> \\<I>. \\<exists>s. \\<forall>x \\<in> responses_\\<I> \\<I>' out. callee' x \\<in> sub_gpvs \\<I>' (callee s call)\"\nproof -\n  from WT\n  have \"set_spmf (inline1 callee gpv s) \\<subseteq> {Inr (out, callee', rpv') | out callee' rpv'.\n    \\<exists>call\\<in>outs_\\<I> \\<I>. \\<exists>s. \\<forall>x \\<in> responses_\\<I> \\<I>' out. callee' x \\<in> sub_gpvs \\<I>' (callee s call)} \\<union> range Inl\"\n    (is \"?concl (inline1 callee) gpv s\")\n  proof(induction arbitrary: gpv s rule: inline1_fixp_induct)\n    case adm show ?case by(intro cont_intro ccpo_class.admissible_leI)\n    case bottom show ?case by simp\n    case (step inline1')\n    { fix out c\n      assume IO: \"IO out c \\<in> set_spmf (the_gpv gpv)\" \n      from step.prems IO have out: \"out \\<in> outs_\\<I> \\<I>\" by(rule WT_gpvD)\n      { fix x s'\n        assume Pure: \"Pure (x, s') \\<in> set_spmf (the_gpv (callee s out))\"\n        then have \"(x, s') \\<in> results_gpv \\<I>' (callee s out)\" by(rule results_gpv.Pure)\n        with out have \"x \\<in> responses_\\<I> \\<I> out\" by(auto dest: results)\n        with step.prems IO have \"\\<I> \\<turnstile>g c x \\<surd>\" by(rule WT_gpvD)\n        hence \"?concl inline1' (c x) s'\" by(rule step.IH)\n      } moreover {\n        fix out' c'\n        assume \"IO out' c' \\<in> set_spmf (the_gpv (callee s out))\"\n        hence \"\\<forall>x\\<in>responses_\\<I> \\<I>' out'. c' x \\<in> sub_gpvs \\<I>' (callee s out)\"\n          by(auto intro: sub_gpvs.base)\n        then have \"\\<exists>call\\<in>outs_\\<I> \\<I>. \\<exists>s. \\<forall>x\\<in>responses_\\<I> \\<I>' out'. c' x \\<in> sub_gpvs \\<I>' (callee s call)\"\n          using out by blast\n      } moreover note calculation }\n    then show ?case using step.prems\n      by(auto del: subsetI simp add: bind_UNION intro!: UN_least split: generat.split)\n  qed\n  thus ?thesis using assms by fastforce\nqed\n\nlemma inline1_in_sub_gpvs:\n  assumes \"Inr (out, callee', rpv') \\<in> set_spmf (inline1 callee gpv s)\"\n  and \"(x, s') \\<in> results_gpv \\<I>' (callee' input)\"\n  and \"input \\<in> responses_\\<I> \\<I>' out\"\n  and \"\\<I> \\<turnstile>g gpv \\<surd>\"\n  shows \"rpv' x \\<in> sub_gpvs \\<I> gpv\"\nproof -\n  from \\<open>\\<I> \\<turnstile>g gpv \\<surd>\\<close>\n  have \"set_spmf (inline1 callee gpv s) \\<subseteq> {Inr (out, callee', rpv') | out callee' rpv'.\n    \\<forall>input \\<in> responses_\\<I> \\<I>' out. \\<forall>(x, s')\\<in>results_gpv \\<I>' (callee' input). rpv' x \\<in> sub_gpvs \\<I> gpv}\n    \\<union> range Inl\" (is \"?concl (inline1 callee) gpv s\" is \"_ \\<subseteq> ?rhs gpv s\")\n  proof(induction arbitrary: gpv s rule: inline1_fixp_induct)\n    case adm show ?case by(intro cont_intro ccpo_class.admissible_leI)\n    case bottom show ?case by simp\n  next\n    case (step inline1')\n    { fix out c\n      assume IO: \"IO out c \\<in> set_spmf (the_gpv gpv)\" \n      from step.prems IO have out: \"out \\<in> outs_\\<I> \\<I>\" by(rule WT_gpvD)\n      { fix x s'\n        assume Pure: \"Pure (x, s') \\<in> set_spmf (the_gpv (callee s out))\"\n        then have \"(x, s') \\<in> results_gpv \\<I>' (callee s out)\" by(rule results_gpv.Pure)\n        with out have \"x \\<in> responses_\\<I> \\<I> out\" by(auto dest: results)\n        with step.prems IO have \"\\<I> \\<turnstile>g c x \\<surd>\" by(rule WT_gpvD)\n        hence \"?concl inline1' (c x) s'\" by(rule step.IH)\n        also have \"\\<dots> \\<subseteq> ?rhs gpv s'\" using IO Pure\n          by(fastforce intro: sub_gpvs.cont dest: WT_gpv_OutD[OF step.prems] results[THEN subsetD, OF _ results_gpv.Pure])\n        finally have \"set_spmf (inline1' (c x) s') \\<subseteq> \\<dots>\" .\n      } moreover {\n        fix out' c' input x s'\n        assume \"IO out' c' \\<in> set_spmf (the_gpv (callee s out))\"\n          and \"input \\<in> responses_\\<I> \\<I>' out'\" and \"(x, s') \\<in> results_gpv \\<I>' (c' input)\"\n        then have \"c x \\<in> sub_gpvs \\<I> gpv\" using IO\n          by(auto intro!: sub_gpvs.base dest: WT_gpv_OutD[OF step.prems] results[THEN subsetD, OF _ results_gpv.IO])\n      } moreover note calculation }\n    then show ?case\n      by(auto simp add: bind_UNION intro!: UN_least split: generat.split del: subsetI)\n  qed\n  with assms show ?thesis by fastforce\nqed\n\ncontext\n  assumes WT: \"\\<And>x s. x \\<in> outs_\\<I> \\<I> \\<Longrightarrow> \\<I>' \\<turnstile>g callee s x \\<surd>\"\nbegin\n\nlemma WT_gpv_inline1:\n  assumes \"Inr (out, rpv, rpv') \\<in> set_spmf (inline1 callee gpv s)\"\n  and \"\\<I> \\<turnstile>g gpv \\<surd>\"\n  shows \"out \\<in> outs_\\<I> \\<I>'\" (is \"?thesis1\")\n  and \"input \\<in> responses_\\<I> \\<I>' out \\<Longrightarrow> \\<I>' \\<turnstile>g rpv input \\<surd>\" (is \"PROP ?thesis2\")\n  and \"\\<lbrakk> input \\<in> responses_\\<I> \\<I>' out; (x, s') \\<in> results_gpv \\<I>' (rpv input) \\<rbrakk> \\<Longrightarrow> \\<I> \\<turnstile>g rpv' x \\<surd>\" (is \"PROP ?thesis3\")\nproof -\n  from \\<open>\\<I> \\<turnstile>g gpv \\<surd>\\<close>\n  have \"set_spmf (inline1 callee gpv s) \\<subseteq> {Inr (out, rpv, rpv') | out rpv rpv'. out \\<in> outs_\\<I> \\<I>'} \\<union> range Inl\"\n  proof(induction arbitrary: gpv s rule: inline1_fixp_induct)\n    { case adm show ?case by(intro cont_intro ccpo_class.admissible_leI) }\n    { case bottom show ?case by simp }\n    case (step inline1')\n    { fix out c\n      assume IO: \"IO out c \\<in> set_spmf (the_gpv gpv)\" \n      from step.prems IO have out: \"out \\<in> outs_\\<I> \\<I>\" by(rule WT_gpvD)\n      { fix x s'\n        assume Pure: \"Pure (x, s') \\<in> set_spmf (the_gpv (callee s out))\"\n        then have \"(x, s') \\<in> results_gpv \\<I>' (callee s out)\" by(rule results_gpv.Pure)\n        with out have \"x \\<in> responses_\\<I> \\<I> out\" by(auto dest: results)\n        with step.prems IO have \"\\<I> \\<turnstile>g c x \\<surd>\" by(rule WT_gpvD)\n      } moreover {\n        fix out' c'\n        from out have \"\\<I>' \\<turnstile>g callee s out \\<surd>\" by(rule WT)\n        moreover assume \"IO out' c' \\<in> set_spmf (the_gpv (callee s out))\"\n        ultimately have \"out' \\<in> outs_\\<I> \\<I>'\" by(rule WT_gpvD) \n      } moreover note calculation }\n    then show ?case \n      by(auto del: subsetI simp add: bind_UNION intro!: UN_least split: generat.split intro!: step.IH[THEN order_trans])\n  qed\n  then show ?thesis1 using assms by auto\n\n  assume \"input \\<in> responses_\\<I> \\<I>' out\"\n  with inline1_in_sub_gpvs_callee[OF \\<open>Inr _ \\<in> _\\<close>] \\<open>\\<I> \\<turnstile>g gpv \\<surd>\\<close>\n  obtain out' s where \"out' \\<in> outs_\\<I> \\<I>\" \n    and *: \"rpv input \\<in> sub_gpvs \\<I>' (callee s out')\" by auto\n  from \\<open>out' \\<in> _\\<close> have \"\\<I>' \\<turnstile>g callee s out' \\<surd>\" by(rule WT)\n  then show \"\\<I>' \\<turnstile>g rpv input \\<surd>\" using * by(rule WT_sub_gpvsD)\n\n  assume \"(x, s') \\<in> results_gpv \\<I>' (rpv input)\"\n  with \\<open>Inr _ \\<in> _\\<close> have \"rpv' x \\<in> sub_gpvs \\<I> gpv\"\n    using \\<open>input \\<in> _\\<close> \\<open>\\<I> \\<turnstile>g gpv \\<surd>\\<close> by(rule inline1_in_sub_gpvs)\n  with \\<open>\\<I> \\<turnstile>g gpv \\<surd>\\<close> show \"\\<I> \\<turnstile>g rpv' x \\<surd>\" by(rule WT_sub_gpvsD)\nqed\n\nlemma WT_gpv_inline:\n  assumes \"\\<I> \\<turnstile>g gpv \\<surd>\"\n  shows \"\\<I>' \\<turnstile>g inline callee gpv s \\<surd>\"\nusing assms\nproof(coinduction arbitrary: gpv s rule: WT_gpv_coinduct_bind)\n  case (WT_gpv out c gpv)\n  from \\<open>IO out c \\<in> _\\<close> obtain callee' rpv'\n    where Inr: \"Inr (out, callee', rpv') \\<in> set_spmf (inline1 callee gpv s)\"\n    and c: \"c = (\\<lambda>input. callee' input \\<bind> (\\<lambda>(x, s). inline callee (rpv' x) s))\"\n    by(clarsimp simp add: inline_sel split: sum.split_asm)\n  from Inr \\<open>\\<I> \\<turnstile>g gpv \\<surd>\\<close> have ?out by(rule WT_gpv_inline1)\n  moreover have \"?cont TYPE('ret \\<times> 's)\" (is \"\\<forall>input\\<in>_. _ \\<or> _ \\<or> ?case' input\")\n  proof(rule ballI disjI2)+\n    fix input\n    assume \"input \\<in> responses_\\<I> \\<I>' out\"\n    with Inr \\<open>\\<I> \\<turnstile>g gpv \\<surd> \\<close>have \"\\<I>' \\<turnstile>g callee' input \\<surd>\"\n      and \"\\<And>x s'. (x, s') \\<in> results_gpv \\<I>' (callee' input) \\<Longrightarrow> \\<I> \\<turnstile>g rpv' x \\<surd>\"\n      by(blast intro: WT_gpv_inline1)+\n    then show \"?case' input\" by(subst c)(auto 4 4)\n  qed\n  ultimately show \"?case TYPE('ret \\<times> 's)\" ..\nqed\n\nend\n\ncontext\n  fixes gpv :: \"('a, 'call, 'ret) gpv\"\n  assumes gpv: \"lossless_gpv \\<I> gpv\" \"\\<I> \\<turnstile>g gpv \\<surd>\"\nbegin\n\nlemma lossless_spmf_inline1:\n  assumes lossless: \"\\<And>s x. x \\<in> outs_\\<I> \\<I> \\<Longrightarrow> lossless_spmf (the_gpv (callee s x))\"\n  shows \"lossless_spmf (inline1 callee gpv s)\"\nusing gpv\nproof(induction arbitrary: s rule: lossless_WT_gpv_induct)\n  case (lossless_gpv p)\n  show ?case using \\<open>lossless_spmf p\\<close>\n    apply(subst inline1_unfold)\n    apply(auto split: generat.split intro: lossless lossless_gpv.hyps dest: results[THEN subsetD, rotated, OF results_gpv.Pure] intro: lossless_gpv.IH)\n    done\nqed\n\nlemma lossless_gpv_inline1:\n  assumes *: \"Inr (out, rpv, rpv') \\<in> set_spmf (inline1 callee gpv s)\"\n  and **: \"input \\<in> responses_\\<I> \\<I>' out\"\n  and lossless: \"\\<And>s x. x \\<in> outs_\\<I> \\<I> \\<Longrightarrow> lossless_gpv \\<I>' (callee s x)\"\n  shows \"lossless_gpv \\<I>' (rpv input)\"\nproof -\n  from inline1_in_sub_gpvs_callee[OF * gpv(2)] **\n  obtain out' s where \"out' \\<in> outs_\\<I> \\<I>\" and ***: \"rpv input \\<in> sub_gpvs \\<I>' (callee s out')\" by blast\n  from \\<open>out' \\<in> _\\<close> have \"lossless_gpv \\<I>' (callee s out')\" by(rule lossless)\n  thus ?thesis using *** by(rule lossless_sub_gpvsD)\nqed\n\nlemma lossless_results_inline1:\n  assumes \"Inr (out, rpv, rpv') \\<in> set_spmf (inline1 callee gpv s)\"\n  and \"(x, s') \\<in> results_gpv \\<I>' (rpv input)\"\n  and \"input \\<in> responses_\\<I> \\<I>' out\"\n  shows \"lossless_gpv \\<I> (rpv' x)\"\nproof -\n  from assms gpv(2) have \"rpv' x \\<in> sub_gpvs \\<I> gpv\" by(rule inline1_in_sub_gpvs)\n  with gpv(1) show \"lossless_gpv \\<I> (rpv' x)\" by(rule lossless_sub_gpvsD)\nqed\n\nend\n\nlemmas lossless_inline1[rotated 2] = lossless_spmf_inline1 lossless_gpv_inline1 lossless_results_inline1\n\nlemma lossless_inline[rotated]:\n  fixes gpv :: \"('a, 'call, 'ret) gpv\"\n  assumes gpv: \"lossless_gpv \\<I> gpv\" \"\\<I> \\<turnstile>g gpv \\<surd>\"\n  and lossless: \"\\<And>s x. x \\<in> outs_\\<I> \\<I> \\<Longrightarrow> lossless_gpv \\<I>' (callee s x)\"\n  shows \"lossless_gpv \\<I>' (inline callee gpv s)\"\nusing gpv\nproof(induction arbitrary: s rule: lossless_WT_gpv_induct_strong)\n  case (lossless_gpv p)\n  have lp: \"lossless_gpv \\<I> (GPV p)\" by(rule lossless_sub_gpvsI)(auto intro: lossless_gpv.hyps)\n  moreover have wp: \"\\<I> \\<turnstile>g GPV p \\<surd>\" by(rule WT_sub_gpvsI)(auto intro: lossless_gpv.hyps)\n  ultimately have \"lossless_spmf (the_gpv (inline callee (GPV p) s))\"\n    by(auto simp add: inline_sel intro: lossless_spmf_inline1 lossless_gpv_lossless_spmfD[OF lossless])\n  moreover {\n    fix out c input\n    assume IO: \"IO out c \\<in> set_spmf (the_gpv (inline callee (GPV p) s))\"\n      and \"input \\<in> responses_\\<I> \\<I>' out\"\n    from IO obtain callee' rpv\n      where Inr: \"Inr (out, callee', rpv) \\<in> set_spmf (inline1 callee (GPV p) s)\"\n      and c: \"c = (\\<lambda>input. callee' input \\<bind> (\\<lambda>(x, y). inline callee (rpv x) y))\"\n      by(clarsimp simp add: inline_sel split: sum.split_asm)\n    from Inr \\<open>input \\<in> _\\<close> lossless lp wp have \"lossless_gpv \\<I>' (callee' input)\" by(rule lossless_inline1)\n    moreover {\n      fix x s'\n      assume \"(x, s') \\<in> results_gpv \\<I>' (callee' input)\"\n      with Inr have \"rpv x \\<in> sub_gpvs \\<I> (GPV p)\" using \\<open>input \\<in> _\\<close> wp by(rule inline1_in_sub_gpvs)\n      hence \"lossless_gpv \\<I>' (inline callee (rpv x) s')\" by(rule lossless_gpv.IH)\n    } ultimately have \"lossless_gpv \\<I>' (c input)\" unfolding c by clarsimp\n  } ultimately show ?case by(rule lossless_gpvI)\nqed\n\nend\n\ndefinition id_oracle :: \"'s \\<Rightarrow> 'call \\<Rightarrow> ('ret \\<times> 's, 'call, 'ret) gpv\"\nwhere \"id_oracle s x = Pause x (\\<lambda>x. Done (x, s))\"\n\nlemma inline1_id_oracle:\n  \"inline1 id_oracle gpv s =\n   map_spmf (\\<lambda>generat. case generat of Pure x \\<Rightarrow> Inl (x, s) | IO out c \\<Rightarrow> Inr (out, \\<lambda>x. Done (x, s), c)) (the_gpv gpv)\"\nby(subst inline1.simps)(auto simp add: id_oracle_def map_spmf_conv_bind_spmf intro!: bind_spmf_cong split: generat.split)\n\nlemma inline_id_oracle [simp]: \"inline id_oracle gpv s = map_gpv (\\<lambda>x. (x, s)) id gpv\"\nby(coinduction arbitrary: gpv s)(auto 4 3 simp add: inline_sel inline1_id_oracle spmf_rel_map gpv.map_sel o_def generat.rel_map intro!: rel_spmf_reflI rel_funI split: generat.split)\n\nsubsection \\<open>Running GPVs\\<close>\n\ntype_synonym ('call, 'ret, 's) callee = \"'s \\<Rightarrow> 'call \\<Rightarrow> ('ret \\<times> 's) spmf\"\n\ncontext fixes callee :: \"('call, 'ret, 's) callee\" notes [[function_internals]] begin\n\npartial_function (spmf) exec_gpv :: \"('a, 'call, 'ret) gpv \\<Rightarrow> 's \\<Rightarrow> ('a \\<times> 's) spmf\"\nwhere\n  \"exec_gpv c s =\n   the_gpv c \\<bind>\n     case_generat (\\<lambda>x. return_spmf (x, s))\n     (\\<lambda>out c. callee s out \\<bind> (\\<lambda>(x, y). exec_gpv (c x) y))\"\n\nabbreviation run_gpv :: \"('a, 'call, 'ret) gpv \\<Rightarrow> 's \\<Rightarrow> 'a spmf\"\nwhere \"run_gpv gpv s \\<equiv> map_spmf fst (exec_gpv gpv s)\"\n\nlemma exec_gpv_fixp_induct [case_names adm bottom step]:\n  assumes \"ccpo.admissible (fun_lub lub_spmf) (fun_ord (ord_spmf (=))) (\\<lambda>f. P (\\<lambda>c s. f (c, s)))\"\n  and \"P (\\<lambda>_ _. return_pmf None)\"\n  and \"\\<And>exec_gpv. P exec_gpv \\<Longrightarrow> \n     P (\\<lambda>c s. the_gpv c \\<bind> case_generat (\\<lambda>x. return_spmf (x, s)) (\\<lambda>out c. callee s out \\<bind> (\\<lambda>(x, y). exec_gpv (c x) y)))\"\n  shows \"P exec_gpv\"\nusing assms(1)\nby(rule exec_gpv.fixp_induct[unfolded curry_conv[abs_def]])(simp_all add: assms(2-))\n\nlemma exec_gpv_fixp_induct_strong [case_names adm bottom step]:\n  assumes \"ccpo.admissible (fun_lub lub_spmf) (fun_ord (ord_spmf (=))) (\\<lambda>f. P (\\<lambda>c s. f (c, s)))\"\n  and \"P (\\<lambda>_ _. return_pmf None)\"\n  and \"\\<And>exec_gpv'. \\<lbrakk> \\<And>c s. ord_spmf (=) (exec_gpv' c s) (exec_gpv c s); P exec_gpv' \\<rbrakk>\n    \\<Longrightarrow> P (\\<lambda>c s. the_gpv c \\<bind> case_generat (\\<lambda>x. return_spmf (x, s)) (\\<lambda>out c. callee s out \\<bind> (\\<lambda>(x, y). exec_gpv' (c x) y)))\"\n  shows \"P exec_gpv\"\nusing assms\nby(rule spmf.fixp_strong_induct_uc[where P=\"\\<lambda>f. P (curry f)\" and U=case_prod and C=curry, OF exec_gpv.mono exec_gpv_def, simplified curry_case_prod, simplified curry_conv[abs_def] fun_ord_def split_paired_All prod.case case_prod_eta, OF refl]) blast\n\nlemma exec_gpv_fixp_induct_strong2 [case_names adm bottom step]:\n  assumes \"ccpo.admissible (fun_lub lub_spmf) (fun_ord (ord_spmf (=))) (\\<lambda>f. P (\\<lambda>c s. f (c, s)))\"\n  and \"P (\\<lambda>_ _. return_pmf None)\"\n  and \"\\<And>exec_gpv'.\n    \\<lbrakk> \\<And>c s. ord_spmf (=) (exec_gpv' c s) (exec_gpv c s); \n      \\<And>c s. ord_spmf (=) (exec_gpv' c s) (the_gpv c \\<bind> case_generat (\\<lambda>x. return_spmf (x, s)) (\\<lambda>out c. callee s out \\<bind> (\\<lambda>(x, y). exec_gpv' (c x) y)));\n      P exec_gpv' \\<rbrakk>\n    \\<Longrightarrow> P (\\<lambda>c s. the_gpv c \\<bind> case_generat (\\<lambda>x. return_spmf (x, s)) (\\<lambda>out c. callee s out \\<bind> (\\<lambda>(x, y). exec_gpv' (c x) y)))\"\n  shows \"P exec_gpv\"\nusing assms\nby(rule spmf.fixp_induct_strong2_uc[where P=\"\\<lambda>f. P (curry f)\" and U=case_prod and C=curry, OF exec_gpv.mono exec_gpv_def, simplified curry_case_prod, simplified curry_conv[abs_def] fun_ord_def split_paired_All prod.case case_prod_eta, OF refl]) blast+\n\nend\n\nlemma exec_gpv_conv_inline1:\n  \"exec_gpv callee gpv s = map_spmf projl (inline1 (\\<lambda>s c. lift_spmf (callee s c) :: (_, unit, unit) gpv) gpv s)\"\nby(induction arbitrary: gpv s rule: parallel_fixp_induct_2_2[OF partial_function_definitions_spmf partial_function_definitions_spmf exec_gpv.mono inline1.mono exec_gpv_def inline1_def, unfolded lub_spmf_empty, case_names adm bottom step])\n  (auto simp add: map_spmf_bind_spmf o_def spmf.map_comp bind_map_spmf split_def intro!: bind_spmf_cong[OF refl] split: generat.split)\n\nlemma exec_gpv_simps:\n  \"exec_gpv callee gpv s =\n   the_gpv gpv \\<bind>\n     case_generat (\\<lambda>x. return_spmf (x, s))\n     (\\<lambda>out rpv. callee s out \\<bind> (\\<lambda>(x, y). exec_gpv callee (rpv x) y))\"\nby(fact exec_gpv.simps)\n\nlemma exec_gpv_lift_spmf [simp]:\n  \"exec_gpv callee (lift_spmf p) s = bind_spmf p (\\<lambda>x. return_spmf (x, s))\"\nby(simp add: exec_gpv_conv_inline1 spmf.map_comp o_def map_spmf_conv_bind_spmf)\n\nlemma exec_gpv_Done [simp]: \"exec_gpv callee (Done x) s = return_spmf (x, s)\"\nby(simp add: exec_gpv_conv_inline1)\n\nlemma exec_gpv_Fail [simp]: \"exec_gpv callee Fail s = return_pmf None\"\nby(simp add: exec_gpv_conv_inline1)\n\nlemma if_distrib_exec_gpv [if_distribs]:\n  \"exec_gpv callee (if b then x else y) s = (if b then exec_gpv callee x s else exec_gpv callee y s)\"\nby simp\n\nlemmas exec_gpv_fixp_parallel_induct [case_names adm bottom step] =\n  parallel_fixp_induct_2_2[OF partial_function_definitions_spmf partial_function_definitions_spmf exec_gpv.mono exec_gpv.mono exec_gpv_def exec_gpv_def, unfolded lub_spmf_empty]\n\ncontext includes lifting_syntax begin\n\nlemma exec_gpv_parametric':\n  \"((S ===> CALL ===> rel_spmf (rel_prod R S)) ===> rel_gpv'' A CALL R ===> S ===> rel_spmf (rel_prod A S))\n  exec_gpv exec_gpv\"\napply(rule rel_funI)+\napply(unfold spmf_rel_map exec_gpv_conv_inline1)\napply(rule rel_spmf_mono_strong)\n apply(erule inline1_parametric'[THEN rel_funD, THEN rel_funD, THEN rel_funD, rotated])\n  prefer 3\n  apply(drule in_set_inline1_lift_spmf1)+\n  apply fastforce\n subgoal by simp\nsubgoal premises [transfer_rule]\n  supply lift_spmf_parametric'[transfer_rule] by transfer_prover\ndone\n\nlemma exec_gpv_parametric [transfer_rule]:\n  \"((S ===> CALL ===> rel_spmf (rel_prod ((=) :: 'ret \\<Rightarrow> _) S)) ===> rel_gpv A CALL ===> S ===> rel_spmf (rel_prod A S))\n  exec_gpv exec_gpv\"\nunfolding rel_gpv_conv_rel_gpv'' by(rule exec_gpv_parametric')\n\nend\n\nlemma exec_gpv_bind: \"exec_gpv callee (c \\<bind> f) s = exec_gpv callee c s \\<bind> (\\<lambda>(x, s') \\<Rightarrow> exec_gpv callee (f x) s')\"\nby(auto simp add: exec_gpv_conv_inline1 inline1_bind_gpv map_spmf_bind_spmf o_def bind_map_spmf intro!: bind_spmf_cong[OF refl] dest: in_set_inline1_lift_spmf1)\n\nlemma exec_gpv_map_gpv_id:\n  \"exec_gpv oracle (map_gpv f id gpv) \\<sigma> = map_spmf (apfst f) (exec_gpv oracle gpv \\<sigma>)\"\nproof(rule sym)\n  define gpv' where \"gpv' = map_gpv f id gpv\"\n  have [transfer_rule]: \"rel_gpv (\\<lambda>x y. y = f x) (=) gpv gpv'\"\n    unfolding gpv'_def by(simp add: gpv.rel_map gpv.rel_refl)\n  have \"rel_spmf (rel_prod (\\<lambda>x y. y = f x) (=)) (exec_gpv oracle gpv \\<sigma>) (exec_gpv oracle gpv' \\<sigma>)\"\n    by transfer_prover\n  thus \"map_spmf (apfst f) (exec_gpv oracle gpv \\<sigma>) = exec_gpv oracle (map_gpv f id gpv) \\<sigma>\"\n    unfolding spmf_rel_eq[symmetric] gpv'_def spmf_rel_map by(rule rel_spmf_mono) clarsimp\nqed\n\nlemma exec_gpv_Pause [simp]:\n  \"exec_gpv callee (Pause out f) s = callee s out \\<bind> (\\<lambda>(x, s'). exec_gpv callee (f x) s')\"\nby(simp add: inline1_Pause map_spmf_bind_spmf bind_map_spmf o_def exec_gpv_conv_inline1 split_def)\n\nlemma exec_gpv_bind_lift_spmf:\n  \"exec_gpv callee (bind_gpv (lift_spmf p) f) s = bind_spmf p (\\<lambda>x. exec_gpv callee (f x) s)\"\nby(simp add: exec_gpv_bind)\n\nlemma exec_gpv_bind_option [simp]:\n  \"exec_gpv oracle (monad.bind_option Fail x f) s = monad.bind_option (return_pmf None) x (\\<lambda>a. exec_gpv oracle (f a) s)\"\nby(cases x) simp_all\n\nlemma pred_spmf_exec_gpv:\n  \\<comment> \\<open>We don't get an equivalence here because states are threaded through in @{const exec_gpv}.\\<close>\n  \"\\<lbrakk> pred_gpv A C gpv; pred_fun S (pred_fun C (pred_spmf (pred_prod (\\<lambda>_. True) S))) callee; S s \\<rbrakk>\n  \\<Longrightarrow> pred_spmf (pred_prod A S) (exec_gpv callee gpv s)\"\nusing exec_gpv_parametric[of \"eq_onp S\" \"eq_onp C\" \"eq_onp A\", folded eq_onp_True]\napply(unfold prod.rel_eq_onp option.rel_eq_onp pmf.rel_eq_onp gpv.rel_eq_onp)\napply(drule rel_funD[where x=callee and y=callee])\n subgoal\n   apply(rule rel_fun_mono[where X=\"eq_onp S\"])\n     apply(rule rel_fun_eq_onpI)\n     apply(unfold eq_onp_same_args)\n     apply assumption\n    apply simp\n   apply(erule rel_fun_eq_onpI)\n   done\napply(auto dest!: rel_funD simp add: eq_onp_def)\ndone\n\nlemma exec_gpv_inline:\n  fixes callee :: \"('c, 'r, 's) callee\"\n  and gpv :: \"'s' \\<Rightarrow> 'c' \\<Rightarrow> ('r' \\<times> 's', 'c, 'r) gpv\"\n  shows \"exec_gpv callee (inline gpv c' s') s =\n    map_spmf (\\<lambda>(x, s', s). ((x, s'), s)) (exec_gpv (\\<lambda>(s', s) y. map_spmf (\\<lambda>((x, s'), s). (x, s', s)) (exec_gpv callee (gpv s' y) s)) c' (s', s))\"\n    (is \"?lhs = ?rhs\")\nproof -\n  have \"?lhs = map_spmf projl (map_spmf (map_sum (\\<lambda>(x, s2, y). ((x, s2), y))\n        (\\<lambda>(x, rpv'' :: ('r \\<times> 's, unit, unit) rpv, rpv', rpv). (x, rpv'', \\<lambda>r1. bind_gpv (rpv' r1) (\\<lambda>(r2, y). inline gpv (rpv r2) y))))\n      (inline2 (\\<lambda>s c. lift_spmf (callee s c)) gpv c' s' s))\"\n    unfolding exec_gpv_conv_inline1 by(simp add: inline1_inline_conv_inline2)\n  also have \"\\<dots> = map_spmf (\\<lambda>(x, s', s). ((x, s'), s)) (map_spmf projl (map_spmf (map_sum id\n        (\\<lambda>(x, rpv'' :: ('r \\<times> 's, unit, unit) rpv, rpv', rpv). (x, \\<lambda>r. bind_gpv (rpv'' r) (\\<lambda>(r1, s1). map_gpv (\\<lambda>((r2, s2), s1). (r2, s2, s1)) id (inline (\\<lambda>s c. lift_spmf (callee s c)) (rpv' r1) s1)), rpv)))\n      (inline2 (\\<lambda>s c. lift_spmf (callee s c)) gpv c' s' s)))\"\n   unfolding spmf.map_comp by(rule map_spmf_cong[OF refl])(auto dest!: in_set_inline2_lift_spmf1)\n  also have \"\\<dots> = ?rhs\" unfolding exec_gpv_conv_inline1\n    by(subst inline1_inline_conv_inline2'[symmetric])(simp add: spmf.map_comp split_def inline_lift_spmf1 map_lift_spmf)\n  finally show ?thesis .\nqed\n\nlemma ord_spmf_exec_gpv:\n  assumes callee: \"\\<And>s x. ord_spmf (=) (callee1 s x) (callee2 s x)\"\n  shows \"ord_spmf (=) (exec_gpv callee1 gpv s) (exec_gpv callee2 gpv s)\"\nproof(induction arbitrary: gpv s rule: exec_gpv_fixp_parallel_induct)\n  case adm show ?case by simp\n  case bottom show ?case by simp\nnext\n  case (step exec_gpv1 exec_gpv2)\n  show ?case using step.prems\n    by(clarsimp intro!: ord_spmf_bind_reflI ord_spmf_bindI[OF assms] step.IH split!: generat.split)\nqed\n\ncontext fixes callee :: \"('call, 'ret, 's) callee\" notes [[function_internals]] begin\n\npartial_function (spmf) execp_resumption :: \"('a, 'call, 'ret) resumption \\<Rightarrow> 's \\<Rightarrow> ('a \\<times> 's) spmf\"\nwhere\n  \"execp_resumption r s = (case r of resumption.Done x \\<Rightarrow> return_pmf (map_option (\\<lambda>a. (a, s)) x)\n      | resumption.Pause out c \\<Rightarrow> bind_spmf (callee s out) (\\<lambda>(input, s'). execp_resumption (c input) s'))\"\n\nsimps_of_case execp_resumption_simps [simp]: execp_resumption.simps\n\nlemma execp_resumption_ABORT [simp]: \"execp_resumption ABORT s = return_pmf None\"\nby(simp add: ABORT_def)\n\nlemma execp_resumption_DONE [simp]: \"execp_resumption (DONE x) s = return_spmf (x, s)\"\nby(simp add: DONE_def)\n\nlemma exec_gpv_lift_resumption: \"exec_gpv callee (lift_resumption r) s = execp_resumption r s\"\nproof(induction arbitrary: r s rule: parallel_fixp_induct_2_2[OF partial_function_definitions_spmf partial_function_definitions_spmf exec_gpv.mono execp_resumption.mono exec_gpv_def execp_resumption_def, case_names adm bot step])\n  case adm show ?case by(simp)\n  case bot thus ?case by simp\n  case (step exec_gpv' execp_resumption')\n  show ?case\n    by(auto split: resumption.split option.split simp add: lift_resumption.sel intro: bind_spmf_cong step)\nqed\n\nlemma mcont2mcont_execp_resumption [THEN spmf.mcont2mcont, cont_intro, simp]:\n  shows mcont_execp_resumption:\n  \"mcont resumption_lub resumption_ord lub_spmf (ord_spmf (=)) (\\<lambda>r. execp_resumption r s)\"\nproof -\n  have \"mcont (prod_lub resumption_lub the_Sup) (rel_prod resumption_ord (=)) lub_spmf (ord_spmf (=)) (case_prod execp_resumption)\"\n  proof(rule ccpo.fixp_preserves_mcont2[OF ccpo_spmf execp_resumption.mono execp_resumption_def])\n    fix execp_resumption' :: \"('b, 'call, 'ret) resumption \\<Rightarrow> 's \\<Rightarrow> ('b \\<times> 's) spmf\"\n    assume *: \"mcont (prod_lub resumption_lub the_Sup) (rel_prod resumption_ord (=)) lub_spmf (ord_spmf (=)) (\\<lambda>(r, s). execp_resumption' r s)\"\n    have [THEN spmf.mcont2mcont, cont_intro, simp]: \"mcont resumption_lub resumption_ord lub_spmf (ord_spmf (=)) (\\<lambda>r. execp_resumption' r s)\" \n      for s using * by simp\n    have \"mcont resumption_lub resumption_ord lub_spmf (ord_spmf (=))\n      (\\<lambda>r. case r of resumption.Done x \\<Rightarrow> return_pmf (map_option (\\<lambda>a. (a, s)) x)\n           | resumption.Pause out c \\<Rightarrow> bind_spmf (callee s out) (\\<lambda>(input, s'). execp_resumption' (c input) s'))\"\n      for s by(rule mcont_case_resumption)(auto simp add: ccpo_spmf intro!: mcont_bind_spmf)\n    thus \"mcont (prod_lub resumption_lub the_Sup) (rel_prod resumption_ord (=)) lub_spmf (ord_spmf (=))\n          (\\<lambda>(r, s). case r of resumption.Done x \\<Rightarrow> return_pmf (map_option (\\<lambda>a. (a, s)) x)\n              | resumption.Pause out c \\<Rightarrow> bind_spmf (callee s out) (\\<lambda>(input, s'). execp_resumption' (c input) s'))\"\n      by simp\n  qed\n  thus ?thesis by auto\nqed\n\n\nlemma execp_resumption_bind [simp]:\n  \"execp_resumption (r \\<bind> f) s = execp_resumption r s \\<bind> (\\<lambda>(x, s'). execp_resumption (f x) s')\"\nby(simp add: exec_gpv_lift_resumption[symmetric] lift_resumption_bind exec_gpv_bind)\n\nlemma pred_spmf_execp_resumption:\n  \"\\<And>A. \\<lbrakk> pred_resumption A C r; pred_fun S (pred_fun C (pred_spmf (pred_prod (\\<lambda>_. True) S))) callee; S s \\<rbrakk>\n  \\<Longrightarrow> pred_spmf (pred_prod A S) (execp_resumption r s)\"\nunfolding exec_gpv_lift_resumption[symmetric]\nby(rule pred_spmf_exec_gpv) simp_all\n\nend\n\ninductive WT_callee :: \"('call, 'ret) \\<I> \\<Rightarrow> ('call \\<Rightarrow> ('ret \\<times> 's) spmf) \\<Rightarrow> bool\" (\"(_) \\<turnstile>c/ (_) \\<surd>\" [100, 0] 99)\n  for \\<I> callee\nwhere\n  WT_callee:\n  \"\\<lbrakk> \\<And>call ret s. \\<lbrakk> call \\<in> outs_\\<I> \\<I>; (ret, s) \\<in> set_spmf (callee call) \\<rbrakk> \\<Longrightarrow> ret \\<in> responses_\\<I> \\<I> call \\<rbrakk>\n  \\<Longrightarrow> \\<I> \\<turnstile>c callee \\<surd>\"\n\nlemmas WT_calleeI = WT_callee\nhide_fact WT_callee\n\nlemma WT_calleeD: \"\\<lbrakk> \\<I> \\<turnstile>c callee \\<surd>; (ret, s) \\<in> set_spmf (callee out); out \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> ret \\<in> responses_\\<I> \\<I> out\"\nby(rule WT_callee.cases)\n\nlemma WT_callee_full [intro!, simp]: \"\\<I>_full \\<turnstile>c callee \\<surd>\"\nby(rule WT_calleeI) simp\n\nlemma WT_callee_parametric [transfer_rule]:\n  includes lifting_syntax \n  assumes [transfer_rule]: \"bi_unique R\"\n  shows \"(rel_\\<I> C R ===> (C ===> rel_spmf (rel_prod R S)) ===> (=)) WT_callee WT_callee\"\nproof -\n  have *: \"WT_callee = (\\<lambda>\\<I> callee. \\<forall>call\\<in> outs_\\<I> \\<I>. \\<forall>(ret, s) \\<in> set_spmf (callee call). ret \\<in> responses_\\<I> \\<I> call)\"\n    unfolding WT_callee.simps by blast\n  show ?thesis unfolding * by transfer_prover\nqed\n\nlocale callee_invariant_on_base =\n  fixes callee :: \"'s \\<Rightarrow> 'a \\<Rightarrow> ('b \\<times> 's) spmf\"\n  and I :: \"'s \\<Rightarrow> bool\"\n  and \\<I> :: \"('a, 'b) \\<I>\"\n\nlocale callee_invariant_on = callee_invariant_on_base callee I \\<I>\n  for callee :: \"'s \\<Rightarrow> 'a \\<Rightarrow> ('b \\<times> 's) spmf\"\n  and I :: \"'s \\<Rightarrow> bool\"\n  and \\<I> :: \"('a, 'b) \\<I>\"\n  +\n  assumes callee_invariant: \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> set_spmf (callee s x); I s; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> I s'\"\n  and WT_callee: \"\\<And>s. I s \\<Longrightarrow> \\<I> \\<turnstile>c callee s \\<surd>\"\nbegin\n\nlemma callee_invariant': \"\\<lbrakk> (y, s') \\<in> set_spmf (callee s x); I s; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> I s' \\<and> y \\<in> responses_\\<I> \\<I> x\"\nby(auto dest: WT_calleeD[OF WT_callee] callee_invariant)\n\nlemma exec_gpv_invariant':\n  \"\\<lbrakk> I s; \\<I> \\<turnstile>g gpv \\<surd> \\<rbrakk> \\<Longrightarrow> set_spmf (exec_gpv callee gpv s) \\<subseteq> {(x, s'). I s'}\"\nproof(induction arbitrary: gpv s rule: exec_gpv_fixp_induct)\n  case adm show ?case by(intro cont_intro ccpo_class.admissible_leI)\n  case bottom show ?case by simp\n  case step show ?case using step.prems\n    by(auto simp add: bind_UNION intro!: UN_least step.IH del: subsetI split: generat.split dest!: callee_invariant' elim: WT_gpvD)\nqed\n\nlemma exec_gpv_invariant:\n  \"\\<lbrakk> (x, s') \\<in> set_spmf (exec_gpv callee gpv s); I s; \\<I> \\<turnstile>g gpv \\<surd> \\<rbrakk> \\<Longrightarrow> I s'\"\nby(drule exec_gpv_invariant') blast+\n\nlemma interaction_bounded_by_exec_gpv_count':\n  fixes count\n  assumes bound: \"interaction_bounded_by consider gpv n\"\n  and count: \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> set_spmf (callee s x); I s; consider x; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> count s' \\<le> eSuc (count s)\"\n  and ignore: \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> set_spmf (callee s x); I s; \\<not> consider x; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> count s' \\<le> count s\"\n  and WT: \"\\<I> \\<turnstile>g gpv \\<surd>\"\n  and I: \"I s\"\n  shows \"set_spmf (exec_gpv callee gpv s) \\<subseteq> {(x, s'). count s' \\<le> n + count s}\"\nusing bound I WT\nproof(induction arbitrary: gpv s n rule: exec_gpv_fixp_induct)\n  case adm show ?case by(intro cont_intro ccpo_class.admissible_leI)\n  case bottom show ?case by simp\n  case (step exec_gpv')\n  have \"set_spmf (exec_gpv' (c input) s') \\<subseteq> {(x, s''). count s'' \\<le> n + count s}\"\n    if out: \"IO out c \\<in> set_spmf (the_gpv gpv)\"\n    and input: \"(input, s') \\<in> set_spmf (callee s out)\"\n    and X: \"out \\<in> outs_\\<I> \\<I>\"\n    for out c input s'\n  proof(cases \"consider out\")\n    case True\n    with step.prems out have \"n > 0\"\n      and bound': \"interaction_bounded_by consider (c input) (n - 1)\"\n      by(auto dest: interaction_bounded_by_contD)\n    note bound'\n    moreover from input \\<open>I s\\<close> X have \"I s'\" by(rule callee_invariant)\n    moreover have \"\\<I> \\<turnstile>g c input \\<surd>\" using step.prems(3) out WT_calleeD[OF WT_callee input]\n      by(rule WT_gpvD)(rule step.prems X)+\n    ultimately have \"set_spmf (exec_gpv' (c input) s') \\<subseteq> {(x, s''). count s'' \\<le> n - 1 + count s'}\"      \n      by(rule step.IH)\n    also have \"\\<dots> \\<subseteq> {(x, s''). count s'' \\<le> n + count s}\" using \\<open>n > 0\\<close> count[OF input \\<open>I s\\<close> True X]     \n      by(cases n rule: co.enat.exhaust)(auto, metis add_left_mono_trans eSuc_plus iadd_Suc_right)\n    finally show ?thesis .\n  next\n    case False\n    from step.prems out this have bound': \"interaction_bounded_by consider (c input) n\"\n      by(auto dest: interaction_bounded_by_contD_ignore)\n    from input \\<open>I s\\<close> X have \"I s'\" by(rule callee_invariant)\n    note bound'\n    moreover from input \\<open>I s\\<close> X have \"I s'\" by(rule callee_invariant)\n    moreover have \"\\<I> \\<turnstile>g c input \\<surd>\" using step.prems(3) out WT_calleeD[OF WT_callee input]\n      by(rule WT_gpvD)(rule step.prems X)+\n    ultimately have \"set_spmf (exec_gpv' (c input) s') \\<subseteq> {(x, s''). count s'' \\<le> n + count s'}\"\n      by(rule step.IH)\n    also have \"\\<dots> \\<subseteq> {(x, s''). count s'' \\<le> n + count s}\"\n      using ignore[OF input \\<open>I s\\<close> False X] by(auto elim: order_trans)\n    finally show ?thesis .\n  qed\n  then show ?case using step.prems(3)\n    by(auto 4 3 simp add: bind_UNION del: subsetI intro!: UN_least split: generat.split dest: WT_gpvD)\nqed\n\nlemma interaction_bounded_by_exec_gpv_count:\n  fixes count\n  assumes bound: \"interaction_bounded_by consider gpv n\"\n  and xs': \"(x, s') \\<in> set_spmf (exec_gpv callee gpv s)\"\n  and count: \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> set_spmf (callee s x); I s; consider x; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> count s' \\<le> eSuc (count s)\"\n  and ignore: \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> set_spmf (callee s x); I s; \\<not> consider x; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> count s' \\<le> count s\"\n  and WT: \"\\<I> \\<turnstile>g gpv \\<surd>\"\n  and I: \"I s\"\n  shows \"count s' \\<le> n + count s\"\nusing bound count ignore WT I \nby(rule interaction_bounded_by_exec_gpv_count'[THEN subsetD, OF _ _ _ _ _ xs', unfolded mem_Collect_eq prod.case])\n\nlemma interaction_bounded_by'_exec_gpv_count:\n  fixes count\n  assumes bound: \"interaction_bounded_by' consider gpv n\"\n  and xs': \"(x, s') \\<in> set_spmf (exec_gpv callee gpv s)\"\n  and count: \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> set_spmf (callee s x); I s; consider x; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> count s' \\<le> Suc (count s)\"\n  and ignore: \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> set_spmf (callee s x); I s; \\<not> consider x; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> count s' \\<le> count s\"\n  and outs: \"\\<I> \\<turnstile>g gpv \\<surd>\"\n  and I: \"I s\"\n  shows \"count s' \\<le> n + count s\"\nusing interaction_bounded_by_exec_gpv_count[OF bound xs', of count] count ignore outs I\nby(simp add: eSuc_enat)\n\nlemma pred_spmf_calleeI: \"\\<lbrakk> I s; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> pred_spmf (pred_prod (\\<lambda>_. True) I) (callee s x)\"\nby(auto simp add: pred_spmf_def dest: callee_invariant)\n\nlemma lossless_exec_gpv:\n  assumes gpv: \"lossless_gpv \\<I> gpv\"\n  and callee: \"\\<And>s out. \\<lbrakk> out \\<in> outs_\\<I> \\<I>; I s \\<rbrakk> \\<Longrightarrow> lossless_spmf (callee s out)\"\n  and WT_gpv: \"\\<I> \\<turnstile>g gpv \\<surd>\"\n  and I: \"I s\"\n  shows \"lossless_spmf (exec_gpv callee gpv s)\"\nusing gpv WT_gpv I\nproof(induction arbitrary: s rule: lossless_WT_gpv_induct)\n  case (lossless_gpv gpv)\n  show ?case using lossless_gpv.hyps lossless_gpv.prems\n    by(subst exec_gpv.simps)(fastforce split: generat.split simp add: callee intro!: lossless_gpv.IH intro: WT_calleeD[OF WT_callee] elim!: callee_invariant)\nqed\n\nlemma in_set_spmf_exec_gpv_into_results_gpv:\n  assumes *: \"(x, s') \\<in> set_spmf (exec_gpv callee gpv s)\"\n  and WT_gpv : \"\\<I> \\<turnstile>g gpv \\<surd>\"\n  and I: \"I s\"\n  shows \"x \\<in> results_gpv \\<I> gpv\"\nproof -\n  have \"set_spmf (exec_gpv callee gpv s) \\<subseteq> results_gpv \\<I> gpv \\<times> UNIV\"\n    using WT_gpv I\n  proof(induction arbitrary: gpv s rule: exec_gpv_fixp_induct)\n    { case adm show ?case by(intro cont_intro ccpo_class.admissible_leI) }\n    { case bottom show ?case by simp }\n    case (step exec_gpv')\n    { fix out c ret s'\n      assume IO: \"IO out c \\<in> set_spmf (the_gpv gpv)\"\n        and ret: \"(ret, s') \\<in> set_spmf (callee s out)\"\n      from step.prems(1) IO have \"out \\<in> outs_\\<I> \\<I>\" by(rule WT_gpvD)\n      with WT_callee[OF \\<open>I s\\<close>] ret have \"ret \\<in> responses_\\<I> \\<I> out\" by(rule WT_calleeD)\n      with step.prems(1) IO have \"\\<I> \\<turnstile>g c ret \\<surd>\" by(rule WT_gpvD)\n      moreover from ret \\<open>I s\\<close> \\<open>out \\<in> outs_\\<I> \\<I>\\<close> have \"I s'\" by(rule callee_invariant)\n      ultimately have \"set_spmf (exec_gpv' (c ret) s') \\<subseteq> results_gpv \\<I> (c ret) \\<times> UNIV\"\n        by(rule step.IH)\n      also have \"\\<dots> \\<subseteq> results_gpv \\<I> gpv \\<times> UNIV\" using IO \\<open>ret \\<in> _\\<close>\n        by(auto intro: results_gpv.IO)\n      finally have \"set_spmf (exec_gpv' (c ret) s') \\<subseteq> results_gpv \\<I> gpv \\<times> UNIV\" . }\n    then show ?case using step.prems\n      by(auto simp add: bind_UNION intro!: UN_least del: subsetI split: generat.split intro: results_gpv.Pure)\n  qed\n  thus \"x \\<in> results_gpv \\<I> gpv\" using * by blast+\nqed\n\nend\n\nlemma callee_invariant_on_alt_def:\n  \"callee_invariant_on = (\\<lambda>callee I \\<I>.\n    (\\<forall>s \\<in> Collect I. \\<forall>x \\<in> outs_\\<I> \\<I>. \\<forall>(y, s') \\<in> set_spmf (callee s x). I s') \\<and>\n    (\\<forall>s \\<in> Collect I. \\<I> \\<turnstile>c callee s \\<surd>))\"\nunfolding callee_invariant_on_def by blast\n\nlemma callee_invariant_on_parametric [transfer_rule]: includes lifting_syntax\n  assumes [transfer_rule]: \"bi_unique R\" \"bi_total S\"\n  shows \"((S ===> C ===> rel_spmf (rel_prod R S)) ===> (S ===> (=)) ===> rel_\\<I> C R ===> (=))\n    callee_invariant_on callee_invariant_on\"\nunfolding callee_invariant_on_alt_def by transfer_prover\n\nlemma callee_invariant_on_cong:\n  \"\\<lbrakk> I = I'; outs_\\<I> \\<I> = outs_\\<I> \\<I>'; \n    \\<And>s x. \\<lbrakk> I' s; x \\<in> outs_\\<I> \\<I>' \\<rbrakk> \\<Longrightarrow> set_spmf (callee s x) \\<subseteq> responses_\\<I> \\<I> x \\<times> Collect I' \\<longleftrightarrow> set_spmf (callee' s x) \\<subseteq> responses_\\<I> \\<I>' x \\<times> Collect I' \\<rbrakk>\n  \\<Longrightarrow> callee_invariant_on callee I \\<I> = callee_invariant_on callee' I' \\<I>'\"\nunfolding callee_invariant_on_def WT_callee.simps\nby safe((erule meta_allE)+, (erule (1) meta_impE)+, force)+ \n\nabbreviation callee_invariant :: \"('s \\<Rightarrow> 'a \\<Rightarrow> ('b \\<times> 's) spmf) \\<Rightarrow> ('s \\<Rightarrow> bool) \\<Rightarrow> bool\"\nwhere \"callee_invariant callee I \\<equiv> callee_invariant_on callee I \\<I>_full\"\n\ninterpretation oi_True: callee_invariant_on callee \"\\<lambda>_. True\" \\<I>_full for callee\nby unfold_locales (simp_all)\n\nlemma callee_invariant_on_return_spmf [simp]:\n  \"callee_invariant_on (\\<lambda>s x. return_spmf (f s x)) I \\<I> \\<longleftrightarrow> (\\<forall>s. \\<forall>x\\<in>outs_\\<I> \\<I>. I s \\<longrightarrow> I (snd (f s x)) \\<and> fst (f s x) \\<in> responses_\\<I> \\<I> x)\"\nby(auto simp add: callee_invariant_on_def split_pairs WT_callee.simps)\n\nlemma callee_invariant_return_spmf [simp]:\n  \"callee_invariant (\\<lambda>s x. return_spmf (f s x)) I \\<longleftrightarrow> (\\<forall>s x. I s \\<longrightarrow> I (snd (f s x)))\"\nby(auto simp add: callee_invariant_on_def split_pairs)\n\nlemma callee_invariant_restrict_relp:\n  includes lifting_syntax\n  assumes \"(S ===> C ===> rel_spmf (rel_prod R S)) callee1 callee2\"\n  and \"callee_invariant callee1 I1\"\n  and \"callee_invariant callee2 I2\"\n  shows \"((S \\<upharpoonleft> I1 \\<otimes> I2) ===> C ===> rel_spmf (rel_prod R (S \\<upharpoonleft> I1 \\<otimes> I2))) callee1 callee2\"\nproof -\n  interpret ci1: callee_invariant_on callee1 I1 \\<I>_full by fact\n  interpret ci2: callee_invariant_on callee2 I2 \\<I>_full by fact\n  show ?thesis using assms(1)\n    by(intro rel_funI)(auto simp add: restrict_rel_prod2 intro!: rel_spmf_restrict_relpI intro: ci1.pred_spmf_calleeI ci2.pred_spmf_calleeI dest: rel_funD rel_setD1 rel_setD2)\nqed\n\nlemma callee_invariant_on_True [simp]: \"callee_invariant_on callee (\\<lambda>_. True) \\<I> \\<longleftrightarrow> (\\<forall>s. \\<I> \\<turnstile>c callee s \\<surd>)\"\nby(simp add: callee_invariant_on_def)\n\nlemma lossless_exec_gpv:\n  \"\\<lbrakk> lossless_gpv \\<I> gpv;  \\<And>s out. out \\<in> outs_\\<I> \\<I> \\<Longrightarrow> lossless_spmf (callee s out);\n     \\<I> \\<turnstile>g gpv \\<surd>; \\<And>s. \\<I> \\<turnstile>c callee s \\<surd> \\<rbrakk>\n  \\<Longrightarrow> lossless_spmf (exec_gpv callee gpv s)\"\nby(rule callee_invariant_on.lossless_exec_gpv; simp)\n\nlemma in_set_spmf_exec_gpv_into_results'_gpv:\n  assumes *: \"(x, s') \\<in> set_spmf (exec_gpv callee gpv s)\"\n  shows \"x \\<in> results'_gpv gpv\"\nusing oi_True.in_set_spmf_exec_gpv_into_results_gpv[OF *] by(simp add: results_gpv_\\<I>_full)\n\n\ncontext fixes \\<I> :: \"('out, 'in) \\<I>\" begin\n\nprimcorec restrict_gpv :: \"('a, 'out, 'in) gpv \\<Rightarrow> ('a, 'out, 'in) gpv\"\nwhere\n  \"restrict_gpv gpv = GPV (\n  map_pmf (case_option None (case_generat (Some \\<circ> Pure) \n       (\\<lambda>out c. if out \\<in> outs_\\<I> \\<I> then Some (IO out (\\<lambda>input. if input \\<in> responses_\\<I> \\<I> out then restrict_gpv (c input) else Fail))\n          else None)))\n    (the_gpv gpv))\" \n\nlemma restrict_gpv_Done [simp]: \"restrict_gpv (Done x) = Done x\"\nby(rule gpv.expand)(simp)\n\nlemma restrict_gpv_Fail [simp]: \"restrict_gpv Fail = Fail\"\nby(rule gpv.expand)(simp)\n\nlemma restrict_gpv_Pause [simp]: \"restrict_gpv (Pause out c) = (if out \\<in> outs_\\<I> \\<I> then Pause out (\\<lambda>input. if input \\<in> responses_\\<I> \\<I> out then restrict_gpv (c input) else Fail) else Fail)\"\nby(rule gpv.expand)(simp)\n\nlemma restrict_gpv_bind [simp]: \"restrict_gpv (bind_gpv gpv f) = bind_gpv (restrict_gpv gpv) (\\<lambda>x. restrict_gpv (f x))\"\napply(coinduction arbitrary: gpv rule: gpv.coinduct_strong)\napply(auto 4 3 simp del: bind_gpv_sel' simp add: bind_gpv.sel bind_spmf_def pmf.rel_map bind_map_pmf rel_fun_def intro!: rel_pmf_bind_reflI rel_pmf_reflI split!: option.split generat.split split: if_split_asm)\ndone\n\nlemma WT_restrict_gpv [simp]: \"\\<I> \\<turnstile>g restrict_gpv gpv \\<surd>\"\napply(coinduction arbitrary: gpv)\napply(clarsimp split: option.split_asm)\napply(split generat.split_asm; auto split: if_split_asm)\ndone\n\nlemma exec_gpv_restrict_gpv:\n  assumes \"\\<I> \\<turnstile>g gpv \\<surd>\" and WT_callee: \"\\<And>s. \\<I> \\<turnstile>c callee s \\<surd>\"\n  shows \"exec_gpv callee (restrict_gpv gpv) s = exec_gpv callee gpv s\"\nusing assms(1)\nproof(induction arbitrary: gpv s rule: exec_gpv_fixp_induct)\n  case adm show ?case by simp\n  case bottom show ?case by simp\n  case (step exec_gpv') show ?case \n    by(auto 4 3 simp add: bind_spmf_def bind_map_pmf in_set_spmf[symmetric] WT_gpv_OutD[OF step.prems] WT_calleeD[OF WT_callee] intro!: bind_pmf_cong[OF refl] step.IH split!: option.split generat.split intro: WT_gpv_ContD[OF step.prems])\nqed\n\nlemma in_outs'_restrict_gpvD: \"x \\<in> outs'_gpv (restrict_gpv gpv) \\<Longrightarrow> x \\<in> outs_\\<I> \\<I>\"\napply(induction gpv'\\<equiv>\"restrict_gpv gpv\" arbitrary: gpv rule: outs'_gpv_induct)\napply(clarsimp split: option.split_asm; split generat.split_asm; clarsimp split: if_split_asm)+\ndone\n\nlemma outs'_restrict_gpv: \"outs'_gpv (restrict_gpv gpv) \\<subseteq> outs_\\<I> \\<I>\" by(blast intro: in_outs'_restrict_gpvD)\n\nlemma lossless_restrict_gpvI: \"\\<lbrakk> lossless_gpv \\<I> gpv; \\<I> \\<turnstile>g gpv \\<surd> \\<rbrakk> \\<Longrightarrow> lossless_gpv \\<I> (restrict_gpv gpv)\"\napply(induction rule: lossless_gpv_induct)\napply(rule lossless_gpvI)\nsubgoal by(clarsimp simp add: lossless_map_pmf lossless_iff_set_pmf_None in_set_spmf[symmetric] WT_gpv_OutD split: option.split_asm generat.split_asm if_split_asm)\nsubgoal by(clarsimp split: option.split_asm; split generat.split_asm; force simp add: fun_eq_iff in_set_spmf[symmetric] split: if_split_asm intro: WT_gpv_ContD)\ndone\n\nlemma lossless_restrict_gpvD: \"\\<lbrakk> lossless_gpv \\<I> (restrict_gpv gpv); \\<I> \\<turnstile>g gpv \\<surd> \\<rbrakk> \\<Longrightarrow> lossless_gpv \\<I> gpv\"\nproof(induction gpv'\\<equiv>\"restrict_gpv gpv\" arbitrary: gpv rule: lossless_gpv_induct)\n  case (lossless_gpv p)\n  from lossless_gpv.hyps(4) have p: \"p = the_gpv (restrict_gpv gpv)\" by(cases \"restrict_gpv gpv\") simp\n  show ?case\n  proof(rule lossless_gpvI) \n    from lossless_gpv.hyps(1) show \"lossless_spmf (the_gpv gpv)\"\n      by(auto simp add: p lossless_iff_set_pmf_None intro: rev_image_eqI)\n\n    fix out c input\n    assume IO: \"IO out c \\<in> set_spmf (the_gpv gpv)\" and input: \"input \\<in> responses_\\<I> \\<I> out\"\n    from lossless_gpv.prems(1) IO have out: \"out \\<in> outs_\\<I> \\<I>\" by(rule WT_gpv_OutD)\n    hence \"IO out (\\<lambda>input. if input \\<in> responses_\\<I> \\<I> out then restrict_gpv (c input) else Fail) \\<in> set_spmf p\" using IO\n      by(auto simp add: p in_set_spmf intro: rev_bexI)\n    from lossless_gpv.hyps(3)[OF this input, of \"c input\"] WT_gpvD[OF lossless_gpv.prems IO] input\n    show \"lossless_gpv \\<I> (c input)\" by simp\n  qed\nqed\n  \nlemma colossless_restrict_gpvD:\n  \"\\<lbrakk> colossless_gpv \\<I> (restrict_gpv gpv); \\<I> \\<turnstile>g gpv \\<surd> \\<rbrakk> \\<Longrightarrow> colossless_gpv \\<I> gpv\"\nproof(coinduction arbitrary: gpv)\n  case (colossless_gpv gpv)\n  have ?lossless_spmf using colossless_gpv(1)[THEN colossless_gpv_lossless_spmfD]\n    by(auto simp add: lossless_iff_set_pmf_None intro: rev_image_eqI)\n  moreover have ?continuation\n  proof(intro strip disjI1)\n    fix out c input\n    assume IO: \"IO out c \\<in> set_spmf (the_gpv gpv)\" and input: \"input \\<in> responses_\\<I> \\<I> out\"\n    from colossless_gpv(2) IO have out: \"out \\<in> outs_\\<I> \\<I>\" by(rule WT_gpv_OutD)\n    hence \"IO out (\\<lambda>input. if input \\<in> responses_\\<I> \\<I> out then restrict_gpv (c input) else Fail) \\<in> set_spmf (the_gpv (restrict_gpv gpv))\"\n      using IO by(auto simp add: in_set_spmf intro: rev_bexI)\n    from colossless_gpv_continuationD[OF colossless_gpv(1) this input] input WT_gpv_ContD[OF colossless_gpv(2) IO input]\n    show \"\\<exists>gpv. c input = gpv \\<and> colossless_gpv \\<I> (restrict_gpv gpv) \\<and> \\<I> \\<turnstile>g gpv \\<surd>\" by simp\n  qed\n  ultimately show ?case ..\nqed\n\nlemma colossless_restrict_gpvI:\n  \"\\<lbrakk> colossless_gpv \\<I> gpv; \\<I> \\<turnstile>g gpv \\<surd> \\<rbrakk> \\<Longrightarrow> colossless_gpv \\<I> (restrict_gpv gpv)\"\nproof(coinduction arbitrary: gpv)\n  case (colossless_gpv gpv)\n  have ?lossless_spmf using colossless_gpv(1)[THEN colossless_gpv_lossless_spmfD]\n    by(auto simp add: lossless_iff_set_pmf_None in_set_spmf[symmetric] split: option.split_asm generat.split_asm if_split_asm dest: WT_gpv_OutD[OF colossless_gpv(2)])\n  moreover have ?continuation\n  proof(intro strip disjI1)\n    fix out c input\n    assume IO: \"IO out c \\<in> set_spmf (the_gpv (restrict_gpv gpv))\" and input: \"input \\<in> responses_\\<I> \\<I> out\"\n    then obtain c' where out: \"out \\<in> outs_\\<I> \\<I>\"\n      and c: \"c = (\\<lambda>input. if input \\<in> responses_\\<I> \\<I> out then restrict_gpv (c' input) else Fail)\"\n      and IO': \"IO out c' \\<in> set_spmf (the_gpv gpv)\"\n      by(clarsimp split: option.split_asm; split generat.split_asm; clarsimp simp add: in_set_spmf split: if_split_asm)\n    with input WT_gpv_ContD[OF colossless_gpv(2) IO' input] colossless_gpv_continuationD[OF colossless_gpv(1) IO' input]\n    show \"\\<exists>gpv. c input = restrict_gpv gpv \\<and> colossless_gpv \\<I> gpv \\<and> \\<I> \\<turnstile>g gpv \\<surd>\" by(auto)\n  qed\n  ultimately show ?case ..\nqed\n\nlemma gen_colossless_restrict_gpv [simp]:\n  \"\\<I> \\<turnstile>g gpv \\<surd> \\<Longrightarrow> gen_lossless_gpv b \\<I> (restrict_gpv gpv) \\<longleftrightarrow> gen_lossless_gpv b \\<I> gpv\"\nby(cases b)(auto intro: lossless_restrict_gpvI lossless_restrict_gpvD colossless_restrict_gpvI colossless_restrict_gpvD)\n\nlemma interaction_bound_restrict_gpv:\n  \"interaction_bound consider (restrict_gpv gpv) \\<le> interaction_bound consider gpv\"\nproof(induction arbitrary: gpv rule: interaction_bound_fixp_induct)\n  case adm show ?case by simp\n  case bottom show ?case by simp\n  case (step interaction_bound')\n  show ?case using step.hyps(1)[of Fail]\n    by(fastforce simp add: SUP_UNION set_spmf_def bind_UNION intro: SUP_mono rev_bexI step.IH split: option.split generat.split)\nqed\n\nlemma interaction_bounded_by_restrict_gpvI [interaction_bound, simp]:\n  \"interaction_bounded_by consider gpv n \\<Longrightarrow> interaction_bounded_by consider (restrict_gpv gpv) n\"\nusing interaction_bound_restrict_gpv[of \"consider\" gpv] by(simp add: interaction_bounded_by.simps)\n\nend\n\nlemma restrict_gpv_parametric':\n  includes lifting_syntax\n  notes [transfer_rule] = the_gpv_parametric' Fail_parametric' corec_gpv_parametric'\n  assumes [transfer_rule]: \"bi_unique C\" \"bi_unique R\"\n  shows \"(rel_\\<I> C R ===> rel_gpv'' A C R ===> rel_gpv'' A C R) restrict_gpv restrict_gpv\"\nunfolding restrict_gpv_def by transfer_prover\n\nlemma restrict_gpv_parametric [transfer_rule]: includes lifting_syntax shows \n  \"bi_unique C \\<Longrightarrow> (rel_\\<I> C (=) ===> rel_gpv A C ===> rel_gpv A C) restrict_gpv restrict_gpv\"\nusing restrict_gpv_parametric'[of C \"(=)\" A]\nby(simp add: bi_unique_eq rel_gpv_conv_rel_gpv'')\n\nlemma map_restrict_gpv: \"map_gpv f id (restrict_gpv \\<I> gpv) = restrict_gpv \\<I> (map_gpv f id gpv)\"\n  for gpv :: \"('a, 'out, 'ret) gpv\"\nusing restrict_gpv_parametric[of \"BNF_Def.Grp UNIV (id :: 'out \\<Rightarrow> 'out)\" \"BNF_Def.Grp UNIV f\", where ?'c='ret]\nunfolding gpv.rel_Grp by(simp add: eq_alt[symmetric] rel_\\<I>_eq rel_fun_def bi_unique_eq)(simp add: Grp_def)\n\nlemma (in callee_invariant_on) exec_gpv_restrict_gpv_invariant:\n  assumes \"\\<I> \\<turnstile>g gpv \\<surd>\" and \"I s\"\n  shows \"exec_gpv callee (restrict_gpv \\<I> gpv) s = exec_gpv callee gpv s\"\nusing assms\nproof(induction arbitrary: gpv s rule: exec_gpv_fixp_induct)\n  case adm show ?case by simp\n  case bottom show ?case by simp\n  case (step exec_gpv') show ?case using step.prems(2)\n    by(auto 4 3 simp add: bind_spmf_def bind_map_pmf in_set_spmf[symmetric] WT_gpv_OutD[OF step.prems(1)] WT_calleeD[OF WT_callee[OF step.prems(2)]] intro!: bind_pmf_cong[OF refl] step.IH split!: option.split generat.split intro: WT_gpv_ContD[OF step.prems(1)] callee_invariant)\nqed\n\ncontext fixes \\<I> :: \"('out, 'in) \\<I>\" begin\n\ninductive finite_gpv :: \"('a, 'out, 'in) gpv \\<Rightarrow> bool\"\nwhere\n  finite_gpvI: \n  \"(\\<And>out c input. \\<lbrakk> IO out c \\<in> set_spmf (the_gpv gpv); input \\<in> responses_\\<I> \\<I> out \\<rbrakk> \\<Longrightarrow> finite_gpv (c input)) \\<Longrightarrow> finite_gpv gpv\"\n\nlemmas finite_gpv_induct[consumes 1, case_names finite_gpv, induct pred] = finite_gpv.induct\n\nlemma finite_gpvD: \"\\<lbrakk> finite_gpv gpv; IO out c \\<in> set_spmf (the_gpv gpv); input \\<in> responses_\\<I> \\<I> out \\<rbrakk> \\<Longrightarrow> finite_gpv (c input)\"\nby(auto elim: finite_gpv.cases)\n\nlemma finite_gpv_Fail [simp]: \"finite_gpv Fail\"\nby(auto intro: finite_gpvI)\n\nlemma finite_gpv_Done [simp]: \"finite_gpv (Done x)\"\nby(auto intro: finite_gpvI)\n\nlemma finite_gpv_Pause [simp]: \"finite_gpv (Pause x c) \\<longleftrightarrow> (\\<forall>input \\<in> responses_\\<I> \\<I> x. finite_gpv (c input))\"\nby(auto dest: finite_gpvD intro: finite_gpvI)\n\nlemma finite_gpv_lift_spmf [simp]: \"finite_gpv (lift_spmf p)\"\nby(auto intro: finite_gpvI)\n\nlemma finite_gpv_bind [simp]:\n  \"finite_gpv (gpv \\<bind> f) \\<longleftrightarrow> finite_gpv gpv \\<and> (\\<forall>x\\<in>results_gpv \\<I> gpv. finite_gpv (f x))\"\n  (is \"?lhs = ?rhs\")\nproof(intro iffI conjI ballI; (elim conjE)?)\n  show \"finite_gpv gpv\" if \"?lhs\" using that\n  proof(induction gpv'\\<equiv>\"gpv \\<bind> f\" arbitrary: gpv)\n    case finite_gpv\n    show ?case\n    proof(rule finite_gpvI)\n      fix out c input\n      assume IO: \"IO out c \\<in> set_spmf (the_gpv gpv)\"\n        and input: \"input \\<in> responses_\\<I> \\<I> out\"\n      have \"IO out (\\<lambda>input. c input \\<bind> f) \\<in> set_spmf (the_gpv (gpv \\<bind> f))\"\n        using IO by(auto intro: rev_bexI)\n      thus \"finite_gpv (c input)\" using input by(rule finite_gpv.hyps) simp\n    qed\n  qed\n  show \"finite_gpv (f x)\" if \"x \\<in> results_gpv \\<I> gpv\" ?lhs for x using that\n  proof(induction)\n    case (Pure gpv)\n    show ?case\n    proof\n      fix out c input\n      assume \"IO out c \\<in> set_spmf (the_gpv (f x))\" \"input \\<in> responses_\\<I> \\<I> out\"\n      with Pure have \"IO out c \\<in> set_spmf (the_gpv (gpv \\<bind> f))\" by(auto intro: rev_bexI)\n      with Pure.prems show \"finite_gpv (c input)\" by(rule finite_gpvD) fact\n    qed\n  next\n    case (IO out c gpv input)\n    with IO.hyps have \"IO out (\\<lambda>input. c input \\<bind> f) \\<in> set_spmf (the_gpv (gpv \\<bind> f))\"\n      by(auto intro: rev_bexI)\n    with IO.prems have \"finite_gpv (c input \\<bind> f)\" using IO.hyps(2) by(rule finite_gpvD)\n    thus ?case by(rule IO.IH)\n  qed\n  show ?lhs if \"finite_gpv gpv\" \"\\<forall>x\\<in>results_gpv \\<I> gpv. finite_gpv (f x)\" using that\n  proof induction\n    case (finite_gpv gpv)\n    show ?case\n    proof(rule finite_gpvI)\n      fix out c input\n      assume IO: \"IO out c \\<in> set_spmf (the_gpv (gpv \\<bind> f))\" and input: \"input \\<in> responses_\\<I> \\<I> out\"\n      then obtain generat where generat: \"generat \\<in> set_spmf (the_gpv gpv)\"\n        and IO: \"IO out c \\<in> set_spmf (if is_Pure generat then the_gpv (f (result generat)) else\n                   return_spmf (IO (output generat) (\\<lambda>input. continuation generat input \\<bind> f)))\"\n        by(auto)\n      show \"finite_gpv (c input)\"\n      proof(cases generat)\n        case (Pure x)\n        with generat IO have \"x \\<in> results_gpv \\<I> gpv\" \"IO out c \\<in> set_spmf (the_gpv (f x))\"\n          by(auto intro: results_gpv.Pure)\n        thus ?thesis using finite_gpv.prems input by(auto dest: finite_gpvD)\n      next\n        case *: (IO out' c')\n        with IO generat finite_gpv.prems input show ?thesis\n          by(auto 4 4 intro: finite_gpv.IH results_gpv.IO)\n      qed\n    qed\n  qed\nqed\n\nend\n\ncontext includes lifting_syntax begin\n\nlemma finite_gpv_rel''D1:\n  assumes \"rel_gpv'' A C R gpv gpv'\" and \"finite_gpv \\<I> gpv\" and \\<I>: \"rel_\\<I> C R \\<I> \\<I>'\"\n  shows \"finite_gpv \\<I>' gpv'\"\nusing assms(2,1)\nproof(induction arbitrary: gpv')\n  case (finite_gpv gpv)\n  note finite_gpv.prems[transfer_rule]\n  show ?case\n  proof(rule finite_gpvI)\n    fix out' c' input'\n    assume IO: \"IO out' c' \\<in> set_spmf (the_gpv gpv')\" and input': \"input' \\<in> responses_\\<I> \\<I>' out'\"\n    have \"rel_set (rel_generat A C (R ===> (rel_gpv'' A C R))) (set_spmf (the_gpv gpv)) (set_spmf (the_gpv gpv'))\"\n      supply the_gpv_parametric'[transfer_rule] by transfer_prover\n    with IO input' responses_\\<I>_parametric[THEN rel_funD, OF \\<I>] obtain out c input\n      where \"IO out c \\<in> set_spmf (the_gpv gpv)\" \"input \\<in> responses_\\<I> \\<I> out\" \"rel_gpv'' A C R (c input) (c' input')\"\n      by(auto 4 3 dest!: rel_setD2 elim!: generat.rel_cases dest: rel_funD)\n    then show \"finite_gpv \\<I>' (c' input')\" by(rule finite_gpv.IH)\n  qed\nqed\n\nlemma finite_gpv_relD1: \"\\<lbrakk> rel_gpv A C gpv gpv'; finite_gpv \\<I> gpv; rel_\\<I> C (=) \\<I> \\<I> \\<rbrakk> \\<Longrightarrow> finite_gpv \\<I> gpv'\"\nusing finite_gpv_rel''D1[of A C \"(=)\" gpv gpv' \\<I> \\<I>] by(simp add: rel_gpv_conv_rel_gpv'')\n\nlemma finite_gpv_rel''D2: \"\\<lbrakk> rel_gpv'' A C R gpv gpv'; finite_gpv \\<I> gpv'; rel_\\<I> C R \\<I>' \\<I> \\<rbrakk> \\<Longrightarrow> finite_gpv \\<I>' gpv\"\nusing finite_gpv_rel''D1[of \"A\\<inverse>\\<inverse>\" \"C\\<inverse>\\<inverse>\" \"R\\<inverse>\\<inverse>\" gpv' gpv \\<I> \\<I>'] by(simp add: rel_gpv''_conversep)\n\nlemma finite_gpv_relD2: \"\\<lbrakk> rel_gpv A C gpv gpv'; finite_gpv \\<I> gpv'; rel_\\<I> C (=) \\<I> \\<I> \\<rbrakk> \\<Longrightarrow> finite_gpv \\<I> gpv\"\nusing finite_gpv_rel''D2[of A C \"(=)\" gpv gpv' \\<I> \\<I>] by(simp add: rel_gpv_conv_rel_gpv'')\n\nlemma finite_gpv_parametric': \"(rel_\\<I> C R ===> rel_gpv'' A C R ===> (=)) finite_gpv finite_gpv\"\nby(blast dest: finite_gpv_rel''D2 finite_gpv_rel''D1)\n\nlemma finite_gpv_parametric [transfer_rule]: \"(rel_\\<I> C (=) ===> rel_gpv A C ===> (=)) finite_gpv finite_gpv\"\nusing finite_gpv_parametric'[of C \"(=)\" A] by(simp add: rel_gpv_conv_rel_gpv'')\n\nend\n\nlemma finite_gpv_map [simp]: \"finite_gpv \\<I> (map_gpv f id gpv) = finite_gpv \\<I> gpv\"\nusing finite_gpv_parametric[of \"BNF_Def.Grp UNIV id\" \"BNF_Def.Grp UNIV f\"]\nunfolding gpv.rel_Grp by(auto simp add: rel_fun_def BNF_Def.Grp_def eq_commute rel_\\<I>_eq)\n\nlemma finite_gpv_assert [simp]: \"finite_gpv \\<I> (assert_gpv b)\"\nby(cases b) simp_all\n\nlemma finite_gpv_try [simp]:\n  \"finite_gpv \\<I> (TRY gpv ELSE gpv') \\<longleftrightarrow> finite_gpv \\<I> gpv \\<and> (colossless_gpv \\<I> gpv \\<or> finite_gpv \\<I> gpv')\"\n  (is \"?lhs = _\")\nproof(intro iffI conjI; (elim conjE disjE)?)\n  show 1: \"finite_gpv \\<I> gpv\" if ?lhs using that\n  proof(induction gpv''\\<equiv>\"TRY gpv ELSE gpv'\" arbitrary: gpv)\n    case (finite_gpv gpv)\n    show ?case\n    proof(rule finite_gpvI)\n      fix out c input\n      assume IO: \"IO out c \\<in> set_spmf (the_gpv gpv)\" and input: \"input \\<in> responses_\\<I> \\<I> out\"\n      from IO have \"IO out (\\<lambda>input. TRY c input ELSE gpv') \\<in> set_spmf (the_gpv (TRY gpv ELSE gpv'))\"\n        by(auto simp add: image_image generat.map_comp o_def intro: rev_image_eqI)\n      thus \"finite_gpv \\<I> (c input)\" using input by(rule finite_gpv.hyps) simp\n    qed\n  qed\n  have \"finite_gpv \\<I> gpv'\" if \"?lhs\" \"\\<not> colossless_gpv \\<I> gpv\" using that\n  proof(induction gpv''\\<equiv>\"TRY gpv ELSE gpv'\" arbitrary: gpv)\n    case (finite_gpv gpv)\n    show ?case\n    proof(cases \"lossless_spmf (the_gpv gpv)\")\n      case True\n      have \"\\<exists>out c input. IO out c \\<in> set_spmf (the_gpv gpv) \\<and> input \\<in> responses_\\<I> \\<I> out \\<and> \\<not> colossless_gpv \\<I> (c input)\"\n        using finite_gpv.prems by(rule contrapos_np)(auto intro: colossless_gpvI simp add: True)\n      then obtain out c input where IO: \"IO out c \\<in> set_spmf (the_gpv gpv)\"\n        and co': \"\\<not> colossless_gpv \\<I> (c input)\" \n        and input: \"input \\<in> responses_\\<I> \\<I> out\" by blast\n      from IO have \"IO out (\\<lambda>input. TRY c input ELSE gpv') \\<in> set_spmf (the_gpv (TRY gpv ELSE gpv'))\"\n        by(auto simp add: image_image generat.map_comp o_def intro: rev_image_eqI)\n      with co' show ?thesis using input by(blast intro: finite_gpv.hyps(2))\n    next\n      case False\n      show ?thesis\n      proof(rule finite_gpvI)\n        fix out c input\n        assume IO: \"IO out c \\<in> set_spmf (the_gpv gpv')\" and input: \"input \\<in> responses_\\<I> \\<I> out\"\n        from IO False have \"IO out c \\<in> set_spmf (the_gpv (TRY gpv ELSE gpv'))\" by(auto intro: rev_image_eqI)\n        then show \"finite_gpv \\<I> (c input)\" using input by(rule finite_gpv.hyps)\n      qed\n    qed\n  qed\n  then show \"colossless_gpv \\<I> gpv \\<or> finite_gpv \\<I> gpv'\" if ?lhs using that by blast\n  \n  show ?lhs if \"finite_gpv \\<I> gpv\" \"finite_gpv \\<I> gpv'\" using that(1)\n  proof induction\n    case (finite_gpv gpv)\n    show ?case\n    proof\n      fix out c input\n      assume IO: \"IO out c \\<in> set_spmf (the_gpv (TRY gpv ELSE gpv'))\"\n        and input: \"input \\<in> responses_\\<I> \\<I> out\"\n      then consider (gpv) c' where \"IO out c' \\<in> set_spmf (the_gpv gpv)\" \"c = (\\<lambda>input. TRY c' input ELSE gpv')\"\n        | (gpv') \"IO out c \\<in> set_spmf (the_gpv gpv')\" by(auto split: if_split_asm)\n      then show \"finite_gpv \\<I> (c input)\" using input\n        by cases(auto intro: finite_gpv.IH finite_gpvD[OF that(2)])\n    qed\n  qed\n  show ?lhs if \"finite_gpv \\<I> gpv\" \"colossless_gpv \\<I> gpv\" using that\n  proof induction\n    case (finite_gpv gpv)\n    show ?case\n      by(rule finite_gpvI)(use finite_gpv.prems in \\<open>fastforce split: if_split_asm dest: colossless_gpvD intro: finite_gpv.IH\\<close>)\n  qed\nqed\n\nlemma lossless_gpv_conv_finite:\n  \"lossless_gpv \\<I> gpv \\<longleftrightarrow> finite_gpv \\<I> gpv \\<and> colossless_gpv \\<I> gpv\"\n  (is \"?loss \\<longleftrightarrow> ?fin \\<and> ?co\")\nproof(intro iffI conjI; (elim conjE)?)\n  show ?fin if ?loss using that by induction(auto intro: finite_gpvI)\n  show ?co if ?loss using that by induction(auto intro: colossless_gpvI)\n  show ?loss if ?fin ?co using that\n  proof induction\n    case (finite_gpv gpv)\n    from finite_gpv.prems finite_gpv.IH show ?case\n      by cases(auto intro: lossless_gpvI)\n  qed\nqed\n\nlemma colossless_gpv_try [simp]:\n  \"colossless_gpv \\<I> (TRY gpv ELSE gpv') \\<longleftrightarrow> colossless_gpv \\<I> gpv \\<or> colossless_gpv \\<I> gpv'\"\n  (is \"?lhs \\<longleftrightarrow> ?gpv \\<or> ?gpv'\")\nproof(intro iffI disjCI; (elim disjE)?)\n  show \"?gpv\" if ?lhs \"\\<not> ?gpv'\" using that(1)\n  proof(coinduction arbitrary: gpv)\n    case (colossless_gpv gpv)\n    have ?lossless_spmf\n    proof(rule ccontr)\n      assume loss: \"\\<not> ?lossless_spmf\"\n      with colossless_gpv_lossless_spmfD[OF colossless_gpv(1)]\n      have gpv': \"lossless_spmf (the_gpv gpv')\" by auto\n      have \"\\<exists>out c input. IO out c \\<in> set_spmf (the_gpv gpv') \\<and> input \\<in> responses_\\<I> \\<I> out \\<and> \\<not> colossless_gpv \\<I> (c input)\"\n        using that(2) by(rule contrapos_np)(auto intro: colossless_gpvI gpv')\n      then obtain out c input\n        where IO: \"IO out c \\<in> set_spmf (the_gpv gpv')\"\n        and co': \"\\<not> colossless_gpv \\<I> (c input)\" \n        and input: \"input \\<in> responses_\\<I> \\<I> out\" by blast\n      from IO loss have \"IO out c \\<in> set_spmf (the_gpv (TRY gpv ELSE gpv'))\"\n        by(auto intro: rev_image_eqI)\n      with colossless_gpv(1) have \"colossless_gpv \\<I> (c input)\" using input\n        by(rule colossless_gpv_continuationD)\n      with co' show False by contradiction\n    qed\n    moreover have ?continuation\n    proof(intro strip disjI1; simp)\n      fix out c input\n      assume IO: \"IO out c \\<in> set_spmf (the_gpv gpv)\" and input: \"input \\<in> responses_\\<I> \\<I> out\"\n      hence \"IO out (\\<lambda>input. TRY c input ELSE gpv') \\<in> set_spmf (the_gpv (TRY gpv ELSE gpv'))\"\n        by(auto intro: rev_image_eqI)\n      with colossless_gpv show \"colossless_gpv \\<I> (TRY c input ELSE gpv')\"\n        by(rule colossless_gpv_continuationD)(simp add: input)\n    qed\n    ultimately show ?case ..\n  qed\n  show ?lhs if ?gpv'\n  proof(coinduction arbitrary: gpv)\n    case colossless_gpv\n    show ?case using colossless_gpvD[OF that] by(auto 4 3)\n  qed\n  show ?lhs if ?gpv using that\n  proof(coinduction arbitrary: gpv)\n    case colossless_gpv\n    show ?case using colossless_gpvD[OF colossless_gpv] by(auto 4 3)\n  qed\nqed\n\nlemma lossless_gpv_try [simp]:\n  \"lossless_gpv \\<I> (TRY gpv ELSE gpv') \\<longleftrightarrow> \n   finite_gpv \\<I> gpv \\<and> (lossless_gpv \\<I> gpv \\<or> lossless_gpv \\<I> gpv')\"\nby(auto simp add: lossless_gpv_conv_finite)\n\nlemma interaction_any_bounded_by_imp_finite:\n  assumes \"interaction_any_bounded_by gpv (enat n)\"\n  shows \"finite_gpv \\<I>_full gpv\"\nusing assms \nproof(induction n arbitrary: gpv)\n  case 0\n  then show ?case by(auto intro: finite_gpv.intros dest: interaction_bounded_by_contD simp add: zero_enat_def[symmetric])\nnext\n  case (Suc n)\n  from Suc.prems show ?case unfolding eSuc_enat[symmetric]\n    by(auto 4 4 intro: finite_gpv.intros Suc.IH dest: interaction_bounded_by_contD)\nqed\n\nlemma finite_restrict_gpvI [simp]: \"finite_gpv \\<I>' gpv \\<Longrightarrow> finite_gpv \\<I>' (restrict_gpv \\<I> gpv)\"\nby(induction rule: finite_gpv_induct)(rule finite_gpvI; clarsimp split: option.split_asm; split generat.split_asm; clarsimp split: if_split_asm simp add: in_set_spmf)\n\nlemma interaction_bounded_by_exec_gpv_bad_count:\n  fixes count and bad and n :: enat and k :: real\n  assumes bound: \"interaction_bounded_by consider gpv n\"\n  and good: \"\\<not> bad s\"\n  and count: \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> set_spmf (callee s x); consider x; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> count s' \\<le> Suc (count s)\"\n  and ignore: \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> set_spmf (callee s x); \\<not> consider x; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> count s' \\<le> count s\"\n  and bad: \"\\<And>s' x. \\<lbrakk> \\<not> bad s'; count s' < n + count s; consider x; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> spmf (map_spmf (bad \\<circ> snd) (callee s' x)) True \\<le> k\"\n  and \"consider\": \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> set_spmf (callee s x); \\<not> bad s; bad s'; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> consider x\"\n  and k_nonneg: \"k \\<ge> 0\"\n  and WT_gpv: \"\\<I> \\<turnstile>g gpv \\<surd>\"\n  and WT_callee: \"\\<And>s. \\<I> \\<turnstile>c callee s \\<surd>\"\n  shows \"spmf (map_spmf (bad \\<circ> snd) (exec_gpv callee gpv s)) True \\<le> ennreal k * n\"\nusing bound good bad WT_gpv\nproof(induction arbitrary: gpv s n rule: exec_gpv_fixp_induct)\n  case adm show ?case by(rule cont_intro ccpo_class.admissible_leI)+\n  case bottom show ?case using k_nonneg by(simp add: zero_ereal_def[symmetric])\nnext\n  case (step exec_gpv')\n  let ?M = \"restrict_space (measure_spmf (the_gpv gpv)) {IO out c|out c. True}\"\n  have \"ennreal (spmf (map_spmf (bad \\<circ> snd) (bind_spmf (the_gpv gpv) (case_generat (\\<lambda>x. return_spmf (x, s)) (\\<lambda>out c. bind_spmf (callee s out) (\\<lambda>(x, y). exec_gpv' (c x) y))))) True) =\n    ennreal (spmf (bind_spmf (the_gpv gpv) (\\<lambda>generat. case generat of Pure x \\<Rightarrow> return_spmf (bad s) |\n       IO out rpv \\<Rightarrow> bind_spmf (callee s out) (\\<lambda>(x, s'). map_spmf (bad \\<circ> snd) (exec_gpv' (rpv x) s')))) True)\"\n    (is \"_ = ennreal (spmf (bind_spmf _ (case_generat _ ?io)) _)\")\n    by(simp add: map_spmf_bind_spmf o_def generat.case_distrib[where h=\"map_spmf _\"] split_def cong del: generat.case_cong_weak)\n  also have \"\\<dots> = \\<integral>\\<^sup>+ generat. \\<integral>\\<^sup>+ (x, s'). spmf (map_spmf (bad \\<circ> snd) (exec_gpv' (continuation generat x) s')) True \\<partial>measure_spmf (callee s (output generat)) \\<partial>?M\"\n    using step.prems(2) by(auto simp add: ennreal_spmf_bind nn_integral_restrict_space intro!: nn_integral_cong split: generat.split)\n  also have \"\\<dots> \\<le> \\<integral>\\<^sup>+ generat. \\<integral>\\<^sup>+ (x, s'). (if bad s' then 1 else ennreal k * (if consider (output generat) then n - 1 else n)) \\<partial>measure_spmf (callee s (output generat)) \\<partial>?M\"\n  proof(clarsimp intro!: nn_integral_mono_AE simp add: AE_restrict_space_iff split del: if_split cong del: if_cong)\n    show \"ennreal (spmf (map_spmf (bad \\<circ> snd) (exec_gpv' (rpv ret) s')) True)\n          \\<le> (if bad s' then 1 else ennreal k * ennreal_of_enat (if consider out then n - 1 else n))\"\n      if IO: \"IO out rpv \\<in> set_spmf (the_gpv gpv)\"\n      and call: \"(ret, s') \\<in> set_spmf (callee s out)\"\n      for out rpv ret s'\n    proof(cases \"bad s'\")\n      case True\n      then show ?thesis by(simp add: pmf_le_1)\n    next\n      case False\n      let ?n' = \"if consider out then n - 1 else n\"\n      have out: \"out \\<in> outs_\\<I> \\<I>\" using IO step.prems(4) by(simp add: WT_gpv_OutD)\n      have bound': \"interaction_bounded_by consider (rpv ret) ?n'\"\n        using interaction_bounded_by_contD[OF step.prems(1) IO]\n              interaction_bounded_by_contD_ignore[OF step.prems(1) IO] by(auto)\n      have \"ret \\<in> responses_\\<I> \\<I> out\" using WT_callee call out by(rule WT_calleeD)\n      with step.prems(4) IO have WT': \"\\<I> \\<turnstile>g rpv ret \\<surd>\" by(rule WT_gpv_ContD)\n      have bad':  \"spmf (map_pmf (map_option (bad \\<circ> snd)) (callee s'' x)) True \\<le> k\"\n        if \"\\<not> bad s''\" and count': \"count s'' < ?n' + count s'\" and \"consider x\" and \"x \\<in> outs_\\<I> \\<I>\"\n        for s'' x using \\<open>\\<not> bad s''\\<close> _ \\<open>consider x\\<close> \\<open>x \\<in> outs_\\<I> \\<I>\\<close>\n      proof(rule step.prems)\n        show \"count s'' < n + count s\"\n        proof(cases \"consider out\")\n          case True\n          with count[OF call True out] count' interaction_bounded_by_contD[OF step.prems(1) IO, of undefined]\n          show ?thesis by(cases n)(auto simp add: one_enat_def)\n        next\n          case False\n          with ignore[OF call _ out] count' show ?thesis by(cases n)auto\n        qed\n      qed\n      from step.IH[OF bound' False this] False WT' show ?thesis by(auto simp add: o_def)\n    qed\n  qed\n  also have \"\\<dots> = \\<integral>\\<^sup>+ generat. \\<integral>\\<^sup>+ b. indicator {True} b + ennreal k * (if consider (output generat) then n - 1 else n) * indicator {False} b \\<partial>measure_spmf (map_spmf (bad \\<circ> snd) (callee s (output generat))) \\<partial>?M\"\n    (is \"_ = \\<integral>\\<^sup>+ generat. \\<integral>\\<^sup>+ _. _ \\<partial>?O' generat \\<partial>_\")\n    by(auto intro!: nn_integral_cong)\n  also have \"\\<dots> = \\<integral>\\<^sup>+ generat. (\\<integral>\\<^sup>+ b. indicator {True} b \\<partial>?O' generat) + ennreal k * (if consider (output generat) then n - 1 else n) * \\<integral>\\<^sup>+ b. indicator {False} b \\<partial>?O' generat \\<partial>?M\"\n    by(subst nn_integral_add)(simp_all add: k_nonneg nn_integral_cmult o_def)\n  also have \"\\<dots> = \\<integral>\\<^sup>+ generat. ennreal (spmf (map_spmf (bad \\<circ> snd) (callee s (output generat))) True) + ennreal k * (if consider (output generat) then n - 1 else n) * spmf (map_spmf (bad \\<circ> snd) (callee s (output generat))) False \\<partial>?M\"\n    by(simp del: nn_integral_map_spmf add: emeasure_spmf_single ereal_of_enat_mult)\n  also have \"\\<dots> \\<le> \\<integral>\\<^sup>+ generat. ennreal k * n \\<partial>?M\"\n  proof(intro nn_integral_mono_AE, clarsimp intro!: nn_integral_mono_AE simp add: AE_restrict_space_iff not_is_Pure_conv split del: if_split)\n    fix out c\n    assume IO: \"IO out c \\<in> set_spmf (the_gpv gpv)\"\n    with step.prems(4) have out: \"out \\<in> outs_\\<I> \\<I>\" by(rule WT_gpv_OutD)\n    show \"spmf (map_spmf (bad \\<circ> snd) (callee s out)) True +\n           ennreal k * (if consider out then n - 1 else n) * spmf (map_spmf (bad \\<circ> snd) (callee s out)) False\n          \\<le> ennreal k * n\"\n    proof(cases \"consider out\")\n      case True\n      with IO have \"n > 0\" using interaction_bounded_by_contD[OF step.prems(1)] by(blast dest: interaction_bounded_by_contD)\n      have \"spmf (map_spmf (bad \\<circ> snd) (callee s out)) True \\<le> k\" (is \"?o True \\<le> _\")\n        using \\<open>\\<not> bad s\\<close> True \\<open>n > 0\\<close> out by(intro step.prems)(simp)\n      hence \"ennreal (?o True) \\<le> k\" using k_nonneg by(simp del: o_apply)\n      hence \"?o True + ennreal k * (n - 1) * ?o False \\<le> ennreal k + ennreal k * (n - 1) * ennreal 1\"\n        by(rule add_mono)(rule mult_left_mono, simp_all add: pmf_le_1 k_nonneg)\n      also have \"\\<dots> \\<le> ennreal k * n\" using \\<open>n > 0\\<close>\n        by(cases n)(auto simp add: zero_enat_def ennreal_top_mult gr0_conv_Suc eSuc_enat[symmetric] field_simps)\n      finally show ?thesis using True by(simp del: o_apply add: ereal_of_enat_mult)\n    next\n      case False\n      hence \"spmf (map_spmf (bad \\<circ> snd) (callee s out)) True = 0\" using \\<open>\\<not> bad s\\<close> out\n        unfolding spmf_eq_0_set_spmf by(auto dest: \"consider\")\n      with False k_nonneg pmf_le_1[of \"map_spmf (bad \\<circ> snd) (callee s out)\" \"Some False\"]\n      show ?thesis by(simp add: mult_left_mono[THEN order_trans, where ?b1=1])\n    qed\n  qed\n  also have \"\\<dots> \\<le> ennreal k * n\"\n    by(simp add: k_nonneg emeasure_restrict_space measure_spmf.emeasure_eq_measure space_restrict_space measure_spmf.subprob_measure_le_1 mult_left_mono[THEN order_trans, where ?b1=1])\n  finally show ?case by(simp del: o_apply)\nqed\n\ncontext callee_invariant_on begin\n\nlemma interaction_bounded_by_exec_gpv_bad_count:\n  includes lifting_syntax\n  fixes count and bad and n :: enat\n  assumes bound: \"interaction_bounded_by consider gpv n\"\n  and I: \"I s\"\n  and good: \"\\<not> bad s\"\n  and count: \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> set_spmf (callee s x); I s; consider x; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> count s' \\<le> Suc (count s)\"\n  and ignore: \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> set_spmf (callee s x); I s; \\<not> consider x; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> count s' \\<le> count s\"\n  and bad: \"\\<And>s' x. \\<lbrakk> I s'; \\<not> bad s'; count s' < n + count s; consider x; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> spmf (map_spmf (bad \\<circ> snd) (callee s' x)) True \\<le> k\"\n  and \"consider\": \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> set_spmf (callee s x); I s; \\<not> bad s; bad s'; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> consider x\"\n  and k_nonneg: \"k \\<ge> 0\"\n  and WT_gpv: \"\\<I> \\<turnstile>g gpv \\<surd>\"\n  shows \"spmf (map_spmf (bad \\<circ> snd) (exec_gpv callee gpv s)) True \\<le> ennreal k * n\"\nproof -\n  { assume \"\\<exists>(Rep :: 's' \\<Rightarrow> 's) Abs. type_definition Rep Abs {s. I s}\"\n    then obtain Rep :: \"'s' \\<Rightarrow> 's\" and Abs where td: \"type_definition Rep Abs {s. I s}\" by blast\n    then interpret td: type_definition Rep Abs \"{s. I s}\" .\n    define cr where \"cr \\<equiv> \\<lambda>x y. x = Rep y\"\n    have [transfer_rule]: \"bi_unique cr\" \"right_total cr\" using td cr_def by(rule typedef_bi_unique typedef_right_total)+\n    have [transfer_domain_rule]: \"Domainp cr = I\" using type_definition_Domainp[OF td cr_def] by simp\n    \n    let ?C = \"eq_onp (\\<lambda>x. x \\<in> outs_\\<I> \\<I>)\"\n\n    define callee' where \"callee' \\<equiv> (Rep ---> id ---> map_spmf (map_prod id Abs)) callee\"\n    have [transfer_rule]: \"(cr ===> ?C ===> rel_spmf (rel_prod (=) cr)) callee callee'\"\n      by(auto simp add: callee'_def rel_fun_def cr_def spmf_rel_map prod.rel_map td.Abs_inverse eq_onp_def intro!: rel_spmf_reflI intro: td.Rep[simplified] dest: callee_invariant)\n    define s' where \"s' \\<equiv> Abs s\"\n    have [transfer_rule]: \"cr s s'\" using I by(simp add: cr_def s'_def td.Abs_inverse)\n    define bad' where \"bad' \\<equiv> (Rep ---> id) bad\"\n    have [transfer_rule]: \"(cr ===> (=)) bad bad'\" by(simp add: rel_fun_def bad'_def cr_def)\n    define count' where \"count' \\<equiv> (Rep ---> id) count\"\n    have [transfer_rule]: \"(cr ===> (=)) count count'\" by(simp add: rel_fun_def count'_def cr_def)\n\n    have [transfer_rule]: \"(?C ===> (=)) consider consider\" by(simp add: eq_onp_def rel_fun_def)\n    have [transfer_rule]: \"rel_\\<I> ?C (=) \\<I> \\<I>\"\n      by(rule rel_\\<I>I)(auto simp add: rel_set_eq set_relator_eq_onp eq_onp_same_args dest: eq_onp_to_eq)\n    note [transfer_rule] = bi_unique_eq_onp bi_unique_eq\n\n    define gpv' where \"gpv' \\<equiv> restrict_gpv \\<I> gpv\"\n    have [transfer_rule]: \"rel_gpv (=) ?C gpv' gpv'\"\n      by(fold eq_onp_top_eq_eq)(auto simp add: gpv.rel_eq_onp eq_onp_same_args pred_gpv_def gpv'_def dest: in_outs'_restrict_gpvD)\n\n    have \"interaction_bounded_by consider gpv' n\" using bound by(simp add: gpv'_def)\n    moreover have \"\\<not> bad' s'\" using good by transfer\n    moreover have [rule_format, rotated]:\n      \"\\<And>s y s'. \\<forall>x \\<in> outs_\\<I> \\<I>. (y, s') \\<in> set_spmf (callee' s x) \\<longrightarrow> consider x \\<longrightarrow> count' s' \\<le> Suc (count' s)\"\n      by(transfer fixing: \"consider\")(blast intro: count)\n    moreover have [rule_format, rotated]:\n      \"\\<And>s y s'. \\<forall>x \\<in> outs_\\<I> \\<I>. (y, s') \\<in> set_spmf (callee' s x) \\<longrightarrow> \\<not> consider x \\<longrightarrow> count' s' \\<le> count' s\"\n      by(transfer fixing: \"consider\")(blast intro: ignore)\n    moreover have [rule_format, rotated]: \n      \"\\<And>s''. \\<forall>x \\<in> outs_\\<I> \\<I>. \\<not> bad' s'' \\<longrightarrow> count' s'' < n + count' s' \\<longrightarrow> consider x \\<longrightarrow> spmf (map_spmf (bad' \\<circ> snd) (callee' s'' x)) True \\<le> k\"\n      by(transfer fixing: \"consider\" k n)(blast intro: bad)\n    moreover have [rule_format, rotated]: \n      \"\\<And>s y s'. \\<forall>x \\<in> outs_\\<I> \\<I>. (y, s') \\<in> set_spmf (callee' s x) \\<longrightarrow> \\<not> bad' s \\<longrightarrow> bad' s' \\<longrightarrow> consider x\"\n      by(transfer fixing: \"consider\")(blast intro: \"consider\")\n    moreover note k_nonneg\n    moreover have \"\\<I> \\<turnstile>g gpv' \\<surd>\" by(simp add: gpv'_def)\n    moreover have \"\\<And>s. \\<I> \\<turnstile>c callee' s \\<surd>\" by transfer(rule WT_callee)\n    ultimately have **: \"spmf (map_spmf (bad' \\<circ> snd) (exec_gpv callee' gpv' s')) True \\<le> ennreal k * n\"\n      by(rule interaction_bounded_by_exec_gpv_bad_count)\n    have [transfer_rule]: \"((=) ===> ?C ===> rel_spmf (rel_prod (=) (=))) callee callee\"\n      by(simp add: rel_fun_def eq_onp_def prod.rel_eq)\n    have \"spmf (map_spmf (bad \\<circ> snd) (exec_gpv callee gpv' s)) True \\<le> ennreal k * n\" using **\n      by(transfer)\n    also have \"exec_gpv callee gpv' s = exec_gpv callee gpv s\"\n      unfolding gpv'_def using WT_gpv I by(rule exec_gpv_restrict_gpv_invariant)\n    finally have ?thesis . }\n  from this[cancel_type_definition] I show ?thesis by blast\nqed\n\nlemma interaction_bounded_by'_exec_gpv_bad_count:\n  fixes count and bad and n :: nat\n  assumes bound: \"interaction_bounded_by' consider gpv n\"\n  and I: \"I s\"\n  and good: \"\\<not> bad s\"\n  and count: \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> set_spmf (callee s x); I s; consider x; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> count s' \\<le> Suc (count s)\"\n  and ignore: \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> set_spmf (callee s x); I s; \\<not> consider x; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> count s' \\<le> count s\"\n  and bad: \"\\<And>s' x. \\<lbrakk> I s'; \\<not> bad s'; count s' < n + count s; consider x; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> spmf (map_spmf (bad \\<circ> snd) (callee s' x)) True \\<le> k\"\n  and \"consider\": \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> set_spmf (callee s x); I s; \\<not> bad s; bad s'; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> consider x\"\n  and k_nonneg: \"k \\<ge> 0\"\n  and WT_gpv: \"\\<I> \\<turnstile>g gpv \\<surd>\"\n  shows \"spmf (map_spmf (bad \\<circ> snd) (exec_gpv callee gpv s)) True \\<le> k * n\"\napply(subst ennreal_le_iff[symmetric], simp_all add: k_nonneg ennreal_mult ennreal_real_conv_ennreal_of_enat del: ennreal_of_enat_enat ennreal_le_iff)\napply(rule interaction_bounded_by_exec_gpv_bad_count[OF bound I _ count ignore bad \"consider\" k_nonneg WT_gpv, OF good])\napply simp_all\ndone\n\nlemma interaction_bounded_by_exec_gpv_bad:\n  assumes \"interaction_any_bounded_by gpv n\"\n  and \"I s\" \"\\<not> bad s\"\n  and bad: \"\\<And>s x. \\<lbrakk> I s; \\<not> bad s; x \\<in> outs_\\<I> \\<I> \\<rbrakk> \\<Longrightarrow> spmf (map_spmf (bad \\<circ> snd) (callee s x)) True \\<le> k\"\n  and k_nonneg: \"0 \\<le> k\"\n  and WT_gpv: \"\\<I> \\<turnstile>g gpv \\<surd>\"\n  shows \"spmf (map_spmf (bad \\<circ> snd) (exec_gpv callee gpv s)) True \\<le> k * n\"\nusing interaction_bounded_by_exec_gpv_bad_count[where bad=bad, OF assms(1) assms(2-3), where ?count = \"\\<lambda>_. 0\", OF _ _ bad _ k_nonneg] k_nonneg WT_gpv\nby(simp add: ennreal_real_conv_ennreal_of_enat[symmetric] ennreal_mult[symmetric] del: ennreal_of_enat_enat)\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/CryptHOL/Generative_Probabilistic_Value.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5273165382362518, "lm_q2_score": 0.5621765008857981, "lm_q1q2_score": 0.29644496632486816}}
{"text": "theory ArityAnalysisAbinds\nimports ArityAnalysisSig\nbegin\n\ncontext ArityAnalysis\nbegin\n\nsubsubsection {* Lifting arity analysis to recursive groups *}\n\ndefinition ABind :: \"var \\<Rightarrow> exp \\<Rightarrow> (AEnv \\<rightarrow> AEnv)\"\n  where \"ABind v e = (\\<Lambda> ae. fup\\<cdot>(Aexp e)\\<cdot>(ae v))\"\n\nlemma ABind_eq[simp]: \"ABind v e \\<cdot> ae = \\<A>\\<^sup>\\<bottom>\\<^bsub>ae v\\<^esub> e\"\n  unfolding ABind_def by (simp add: cont_fun)\n\nfun ABinds :: \"heap \\<Rightarrow> (AEnv \\<rightarrow> AEnv)\"\n  where \"ABinds [] = \\<bottom>\"\n     |  \"ABinds ((v,e)#binds) = ABind v e \\<squnion> ABinds (delete v binds)\"\n\nlemma ABinds_strict[simp]: \"ABinds \\<Gamma>\\<cdot>\\<bottom>=\\<bottom>\"\n  by (induct \\<Gamma> rule: ABinds.induct) auto\n\nlemma Abinds_reorder1: \"map_of \\<Gamma> v = Some e \\<Longrightarrow> ABinds \\<Gamma> = ABind v e \\<squnion> ABinds (delete v \\<Gamma>)\"\n  by (induction \\<Gamma> rule: ABinds.induct) (auto simp add: delete_twist)\n\nlemma ABind_below_ABinds: \"map_of \\<Gamma> v = Some e \\<Longrightarrow> ABind v e \\<sqsubseteq> ABinds \\<Gamma>\"\n  by (metis \"HOLCF-Join-Classes.join_above1\" ArityAnalysis.Abinds_reorder1)\n\nlemma Abinds_reorder: \"map_of \\<Gamma> = map_of \\<Delta> \\<Longrightarrow> ABinds \\<Gamma> = ABinds \\<Delta>\"\nproof (induction  \\<Gamma> arbitrary: \\<Delta> rule: ABinds.induct)\n  case 1 thus ?case by simp\nnext\n  case (2 v e \\<Gamma> \\<Delta>)\n  from `map_of ((v, e) # \\<Gamma>) = map_of \\<Delta>`\n  have \"(map_of ((v, e) # \\<Gamma>))(v := None) = (map_of \\<Delta>)(v := None)\" by simp\n  hence \"map_of (delete v \\<Gamma>) = map_of (delete v \\<Delta>)\" unfolding delete_set_none by simp\n  hence \"ABinds (delete v \\<Gamma>) = ABinds (delete v \\<Delta>)\" by (rule 2)\n  moreover\n  from `map_of ((v, e) # \\<Gamma>) = map_of \\<Delta>`\n  have \"map_of \\<Delta> v = Some e\" by (metis map_of_Cons_code(2))\n  hence \"ABinds \\<Delta> = ABind v e \\<squnion> ABinds (delete v \\<Delta>)\" by (rule Abinds_reorder1)\n  ultimately\n  show ?case by auto\nqed\n\n(*\nlemma ABinds_above_arg: \"ae \\<sqsubseteq> ABinds \\<Gamma> \\<cdot> ae\"\nproof (induction rule:ABinds.induct)\n  show \"\\<bottom> \\<sqsubseteq> ABinds []\\<cdot>ae\" by auto\nnext\n  fix v e \\<Gamma>\n  assume assm: \"ae \\<sqsubseteq> ABinds (delete v \\<Gamma>)\\<cdot>ae\"\n  also have \"\\<dots> \\<sqsubseteq> ABinds ((v, e) # \\<Gamma>)\\<cdot>ae\"  by auto\n  finally show \"ae \\<sqsubseteq> ABinds ((v, e) # \\<Gamma>)\\<cdot>ae\" by this simp\nqed\n*)\n\nlemma Abinds_env_cong: \"(\\<And> x. x\\<in>domA \\<Delta> \\<Longrightarrow> ae x = ae' x)  \\<Longrightarrow>  ABinds \\<Delta>\\<cdot>ae = ABinds \\<Delta>\\<cdot>ae'\"\n  by (induct \\<Delta> rule: ABinds.induct) auto\n\nlemma Abinds_env_restr_cong: \" ae f|` domA \\<Delta> = ae' f|` domA \\<Delta> \\<Longrightarrow>  ABinds \\<Delta>\\<cdot>ae = ABinds \\<Delta>\\<cdot>ae'\"\n  by (rule Abinds_env_cong) (metis env_restr_eqD)\n\nlemma ABinds_env_restr[simp]: \"ABinds \\<Delta>\\<cdot>(ae f|` domA \\<Delta>) = ABinds \\<Delta>\\<cdot>ae\"\n  by (rule Abinds_env_restr_cong) simp\n\nlemma Abinds_join_fresh: \"ae' ` (domA \\<Delta>) \\<subseteq> {\\<bottom>} \\<Longrightarrow>  ABinds \\<Delta>\\<cdot>(ae \\<squnion> ae') = (ABinds \\<Delta>\\<cdot>ae)\"\n  by (rule Abinds_env_cong) auto\n\nlemma ABinds_delete_bot: \"ae x = \\<bottom> \\<Longrightarrow> ABinds (delete x \\<Gamma>)\\<cdot>ae = ABinds \\<Gamma>\\<cdot>ae\"\n  by (induction \\<Gamma> rule: ABinds.induct) (auto simp add: delete_twist)\n\nlemma ABinds_restr_fresh:\n  assumes \"atom ` S \\<sharp>* \\<Gamma>\"\n  shows \"ABinds \\<Gamma>\\<cdot>ae f|` (- S) = ABinds \\<Gamma>\\<cdot>(ae  f|` (- S)) f|` (- S)\"\n  using assms\n  apply (induction \\<Gamma> rule:ABinds.induct)\n  apply simp\n  apply (auto simp del: fun_meet_simp simp add: env_restr_join fresh_star_Pair fresh_star_Cons fresh_star_delete)\n  apply (subst lookup_env_restr)\n  apply (metis (no_types, hide_lams) ComplI fresh_at_base(2) fresh_star_def imageI)\n  apply simp\n  done\n\nlemma ABinds_restr:\n  assumes \"domA \\<Gamma> \\<subseteq> S\"\n  shows \"ABinds \\<Gamma>\\<cdot>ae f|` S = ABinds \\<Gamma>\\<cdot>(ae  f|` S) f|` S\"\n  using assms\n  by (induction \\<Gamma> rule:ABinds.induct) (fastforce simp del: fun_meet_simp simp add: env_restr_join)+\n\nlemma ABinds_restr_subst:\n  assumes \"\\<And> x' e a. (x',e) \\<in> set \\<Gamma> \\<Longrightarrow> Aexp e[x::=y]\\<cdot>a f|` S = Aexp e\\<cdot>a f|` S\"\n  assumes \"x \\<notin> S\"\n  assumes \"y \\<notin> S\"\n  assumes \"domA \\<Gamma> \\<subseteq> S\"\n  shows \"ABinds \\<Gamma>[x::h=y]\\<cdot>ae f|` S = ABinds \\<Gamma>\\<cdot>(ae  f|` S) f|` S\"\n  using assms\n  apply (induction \\<Gamma> rule:ABinds.induct)\n  apply (auto simp del: fun_meet_simp join_comm simp add: env_restr_join)\n  apply (rule arg_cong2[where f = join])\n  apply (case_tac \"ae v\")\n  apply (auto dest:  set_mp[OF set_delete_subset])\n  done\n\nlemma Abinds_append_disjoint: \"domA \\<Delta> \\<inter> domA \\<Gamma> = {} \\<Longrightarrow>  ABinds (\\<Delta> @ \\<Gamma>)\\<cdot>ae = ABinds \\<Delta>\\<cdot>ae \\<squnion> ABinds \\<Gamma>\\<cdot>ae\"\nproof (induct \\<Delta> rule: ABinds.induct)\n  case 1 thus ?case by simp\nnext\n  case (2 v e \\<Delta>)\n  from 2(2)\n  have \"v \\<notin> domA \\<Gamma>\" and  \"domA (delete v \\<Delta>) \\<inter> domA \\<Gamma> = {}\" by auto\n  from 2(1)[OF this(2)]\n  have \"ABinds (delete v \\<Delta> @ \\<Gamma>)\\<cdot>ae = ABinds (delete v \\<Delta>)\\<cdot>ae \\<squnion> ABinds \\<Gamma>\\<cdot>ae\".\n  moreover\n  have \"delete v \\<Gamma> = \\<Gamma>\" by (metis `v \\<notin> domA \\<Gamma>` delete_not_domA)\n  ultimately\n  show \" ABinds (((v, e) # \\<Delta>) @ \\<Gamma>)\\<cdot>ae = ABinds ((v, e) # \\<Delta>)\\<cdot>ae \\<squnion> ABinds \\<Gamma>\\<cdot>ae\"\n    by auto\nqed\n\nlemma ABinds_restr_subset: \"S \\<subseteq> S' \\<Longrightarrow> ABinds (restrictA S \\<Gamma>)\\<cdot>ae \\<sqsubseteq> ABinds (restrictA S' \\<Gamma>)\\<cdot>ae\"\n  by (induct \\<Gamma> rule: ABinds.induct)\n     (auto simp add: join_below_iff  restr_delete_twist intro: below_trans[OF _ join_above2])\n\nlemma ABinds_restrict_edom: \"ABinds (restrictA (edom ae) \\<Gamma>)\\<cdot>ae = ABinds \\<Gamma>\\<cdot>ae\"\n  by (induct \\<Gamma> rule: ABinds.induct) (auto simp add: edom_def restr_delete_twist)\n  \nlemma ABinds_restrict_below: \"ABinds (restrictA S \\<Gamma>)\\<cdot>ae \\<sqsubseteq> ABinds \\<Gamma>\\<cdot>ae\"\n  by (induct \\<Gamma> rule: ABinds.induct)\n     (auto simp add: join_below_iff  restr_delete_twist intro: below_trans[OF _ join_above2] simp del: fun_meet_simp join_comm)\n\nlemma ABinds_delete_below: \"ABinds (delete x \\<Gamma>)\\<cdot>ae \\<sqsubseteq> ABinds \\<Gamma>\\<cdot>ae\"\n  by (induct \\<Gamma> rule: ABinds.induct)\n     (auto simp add: join_below_iff   delete_twist[where x = x] elim: below_trans simp del: fun_meet_simp)\nend\n\nlemma ABind_eqvt[eqvt]: \"\\<pi> \\<bullet> (ArityAnalysis.ABind Aexp v e) = ArityAnalysis.ABind (\\<pi> \\<bullet> Aexp) (\\<pi> \\<bullet> v) (\\<pi> \\<bullet> e)\"\n  apply (rule cfun_eqvtI)\n  unfolding ArityAnalysis.ABind_eq\n  by perm_simp rule\n\nlemma ABinds_eqvt[eqvt]: \"\\<pi> \\<bullet> (ArityAnalysis.ABinds Aexp \\<Gamma>) = ArityAnalysis.ABinds (\\<pi> \\<bullet> Aexp) (\\<pi> \\<bullet> \\<Gamma>)\"\n  apply (rule cfun_eqvtI)\n  apply (induction \\<Gamma> rule: ArityAnalysis.ABinds.induct)\n  apply (simp add: ArityAnalysis.ABinds.simps)\n  apply (simp add: ArityAnalysis.ABinds.simps)\n  apply perm_simp\n  apply simp\n  done\n\nlemma Abinds_cong[fundef_cong]:\n  \"\\<lbrakk> (\\<And> e. e \\<in> snd ` set heap2 \\<Longrightarrow> aexp1 e = aexp2 e) ; heap1 = heap2 \\<rbrakk>\n      \\<Longrightarrow> ArityAnalysis.ABinds aexp1 heap1 = ArityAnalysis.ABinds aexp2 heap2\"    \nproof (induction heap1 arbitrary:heap2 rule:ArityAnalysis.ABinds.induct)\n  case 1\n  thus ?case by (auto simp add: ArityAnalysis.ABinds.simps)\nnext\n  case prems: (2 v e as heap2)\n  have \"snd ` set (delete v as) \\<subseteq> snd ` set as\" by (rule dom_delete_subset)\n  also have \"\\<dots> \\<subseteq> snd `set ((v, e) # as)\" by auto\n  also note prems(3)\n  finally\n  have \"(\\<And>e. e \\<in> snd ` set (delete v as) \\<Longrightarrow> aexp1 e = aexp2 e)\" by -(rule prems, auto)\n  from prems prems(1)[OF this refl] show ?case\n    by (auto simp add: ArityAnalysis.ABinds.simps ArityAnalysis.ABind_def)\nqed\n\ncontext EdomArityAnalysis\nbegin\n  lemma fup_Aexp_lookup_fresh: \"atom v \\<sharp> e \\<Longrightarrow> (fup\\<cdot>(Aexp e)\\<cdot>a) v = \\<bottom>\"\n    by (cases a) auto\n  \n  lemma edom_AnalBinds: \"edom (ABinds \\<Gamma>\\<cdot>ae) \\<subseteq> fv \\<Gamma>\"\n    by (induction \\<Gamma> rule: ABinds.induct)\n       (auto simp del: fun_meet_simp dest: set_mp[OF fup_Aexp_edom] dest: set_mp[OF fv_delete_subset])\nend \n\nend\n", "meta": {"author": "nomeata", "repo": "isa-launchbury", "sha": "2caa8d7d588e218aef1c49f2f327597af06d116e", "save_path": "github-repos/isabelle/nomeata-isa-launchbury", "path": "github-repos/isabelle/nomeata-isa-launchbury/isa-launchbury-2caa8d7d588e218aef1c49f2f327597af06d116e/Call_Arity/ArityAnalysisAbinds.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5621765008857981, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.2964449579727892}}
{"text": "header {* \\isaheader{Generic Map Algorithms} *}\ntheory Gen_Map\nimports \"../Intf/Intf_Map\" \"../../Iterator/Iterator\"\nbegin\n  lemma map_to_set_distinct_conv:\n    assumes \"distinct tsl'\" and \"map_to_set m' = set tsl'\"\n    shows \"distinct (map fst tsl')\"\n    apply (rule ccontr)\n    apply (drule not_distinct_decomp)\n    using assms\n    apply (clarsimp elim!: map_eq_concE)\n    by (metis (hide_lams, no_types) insert_iff map_to_set_inj)\n\n\n  (* TODO: Make foldli explicit, such that it is seen by \n  iterator-optimizations! cf Gen_Set for how to do this! *)\n  lemma foldli_add: \"det_fold_map X \n    (\\<lambda>_. True) (\\<lambda>(k,v) m. op_map_update k v m) m (op ++ m)\"\n  proof\n    case (goal1 l) thus ?case\n      apply (induct l arbitrary: m) \n      apply (auto simp: map_of_distinct_upd[symmetric])\n      done\n  qed\n\n  definition gen_add\n    :: \"('s2 \\<Rightarrow> _) \\<Rightarrow> ('k \\<Rightarrow> 'v \\<Rightarrow> 's1 \\<Rightarrow> 's1) \\<Rightarrow> 's1 \\<Rightarrow> 's2 \\<Rightarrow> 's1\"\n    where \n    \"gen_add it upd A B \\<equiv> it B (\\<lambda>_. True) (\\<lambda>(k,v) m. upd k v m) A\"\n\n  lemma gen_add[autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes UPD: \"GEN_OP ins op_map_update (Rk\\<rightarrow>Rv\\<rightarrow>\\<langle>Rk,Rv\\<rangle>Rs1\\<rightarrow>\\<langle>Rk,Rv\\<rangle>Rs1)\"\n    assumes IT: \"SIDE_GEN_ALGO (is_map_to_list Rk Rv Rs2 tsl)\"\n    shows \"(gen_add (foldli o tsl) ins,op ++) \n      \\<in> (\\<langle>Rk,Rv\\<rangle>Rs1) \\<rightarrow> (\\<langle>Rk,Rv\\<rangle>Rs2) \\<rightarrow> (\\<langle>Rk,Rv\\<rangle>Rs1)\"\n    apply (intro fun_relI)\n    unfolding gen_add_def comp_def\n    apply (rule det_fold_map[OF foldli_add IT[unfolded autoref_tag_defs]])\n    apply (parametricity add: UPD[unfolded autoref_tag_defs])+\n    done\n\n  lemma foldli_restrict: \"det_fold_map X (\\<lambda>_. True) \n    (\\<lambda>(k,v) m. if P (k,v) then op_map_update k v m else m) Map.empty\n      (op_map_restrict P )\" (is \"det_fold_map _ _ ?f _ _\")\n  proof -\n    {\n      fix l m\n      have \"distinct (map fst l) \\<Longrightarrow>\n        foldli l (\\<lambda>_. True) ?f m = m ++ op_map_restrict P (map_of l)\"\n      proof (induction l arbitrary: m) \n        case Nil thus ?case by simp\n      next\n        case (Cons kv l)\n        obtain k v where [simp]: \"kv = (k,v)\" by fastforce\n        from Cons.prems have \n          DL: \"distinct (map fst l)\" and KNI: \"k \\<notin> set (map fst l)\" \n          by auto\n\n        show ?case proof (cases \"P (k,v)\")\n          case True[simp] \n          have \"foldli (kv#l) (\\<lambda>_. True) ?f m = foldli l (\\<lambda>_. True) ?f (m(k\\<mapsto>v))\"\n            by simp\n          also from Cons.IH[OF DL] have \n            \"\\<dots> = m(k\\<mapsto>v) ++ op_map_restrict P (map_of l)\" .\n          also have \"\\<dots> = m ++ op_map_restrict P (map_of (kv#l))\"\n            using KNI\n            by (auto\n              split: option.splits\n              intro!: ext \n              simp: Map.restrict_map_def Map.map_add_def\n              simp: map_of_eq_None_iff[symmetric])\n          finally show ?thesis .\n        next\n          case False[simp] \n          have \"foldli (kv#l) (\\<lambda>_. True) ?f m = foldli l (\\<lambda>_. True) ?f m\"\n            by simp\n          also from Cons.IH[OF DL] have \n            \"\\<dots> = m ++ op_map_restrict P (map_of l)\" .\n          also have \"\\<dots> = m ++ op_map_restrict P (map_of (kv#l))\"\n            using KNI\n            by (auto \n              intro!: ext\n              simp: Map.restrict_map_def Map.map_add_def\n              simp: map_of_eq_None_iff[symmetric]\n            )\n          finally show ?thesis .\n        qed\n      qed\n    } \n    from this[of _ Map.empty] show ?thesis\n      by (auto intro!: det_fold_mapI)\n  qed\n\n  definition gen_restrict :: \"('s1 \\<Rightarrow> _) \\<Rightarrow> _\"\n    where \"gen_restrict it upd emp P m \n    \\<equiv> it m (\\<lambda>_. True) (\\<lambda>(k,v) m. if P (k,v) then upd k v m else m) emp\"\n\n  lemma gen_restrict[autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes IT: \"SIDE_GEN_ALGO (is_map_to_list Rk Rv Rs1 tsl)\"\n    assumes INS: \n      \"GEN_OP upd op_map_update (Rk\\<rightarrow>Rv\\<rightarrow>\\<langle>Rk,Rv\\<rangle>Rs2\\<rightarrow>\\<langle>Rk,Rv\\<rangle>Rs2)\"\n    assumes EMPTY: \n      \"GEN_OP emp Map.empty (\\<langle>Rk,Rv\\<rangle>Rs2)\"\n    shows \"(gen_restrict (foldli o tsl) upd emp,op_map_restrict) \n    \\<in> (\\<langle>Rk,Rv\\<rangle>prod_rel \\<rightarrow> Id) \\<rightarrow> (\\<langle>Rk,Rv\\<rangle>Rs1) \\<rightarrow> (\\<langle>Rk,Rv\\<rangle>Rs2)\"\n    apply (intro fun_relI)\n    unfolding gen_restrict_def comp_def\n    apply (rule det_fold_map[OF foldli_restrict IT[unfolded autoref_tag_defs]])\n    using INS EMPTY unfolding autoref_tag_defs\n    apply (parametricity)+\n    done\n\n  lemma fold_map_of: \n    \"fold (\\<lambda>(k,v) s. op_map_update k v s) (rev l) Map.empty = map_of l\"\n  proof -\n    {\n      fix m\n      have \"fold (\\<lambda>(k,v) s. s(k\\<mapsto>v)) (rev l) m = m ++ map_of l\"\n        apply (induct l arbitrary: m)\n        apply auto\n        done\n    } thus ?thesis by simp\n  qed\n\n  definition gen_map_of :: \"'m \\<Rightarrow> ('k\\<Rightarrow>'v\\<Rightarrow>'m\\<Rightarrow>'m) \\<Rightarrow> _\" where \n    \"gen_map_of emp upd l \\<equiv> fold (\\<lambda>(k,v) s. upd k v s) (rev l) emp\"\n\n\n  lemma gen_map_of[autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes UPD: \"GEN_OP upd op_map_update (Rk\\<rightarrow>Rv\\<rightarrow>\\<langle>Rk,Rv\\<rangle>Rm\\<rightarrow>\\<langle>Rk,Rv\\<rangle>Rm)\"\n    assumes EMPTY: \"GEN_OP emp Map.empty (\\<langle>Rk,Rv\\<rangle>Rm)\"\n    shows \"(gen_map_of emp upd,map_of) \\<in> \\<langle>\\<langle>Rk,Rv\\<rangle>prod_rel\\<rangle>list_rel \\<rightarrow> \\<langle>Rk,Rv\\<rangle>Rm\"\n    using assms\n    apply (intro fun_relI)\n    unfolding gen_map_of_def[abs_def]\n    unfolding autoref_tag_defs\n    apply (subst fold_map_of[symmetric])\n    apply parametricity\n    done\n\n  lemma foldli_ball_aux: \n    \"distinct (map fst l) \\<Longrightarrow> foldli l (\\<lambda>x. x) (\\<lambda>x _. P x) b \n    \\<longleftrightarrow> b \\<and> op_map_ball (map_of l) P\"\n    apply (induct l arbitrary: b)\n    apply simp\n    apply (force simp: map_to_set_map_of image_def)\n    done\n  \n  lemma foldli_ball: \n    \"det_fold_map X (\\<lambda>x. x) (\\<lambda>x _. P x) True (\\<lambda>m. op_map_ball m P)\"\n    apply rule\n    using foldli_ball_aux[where b=True] by auto\n    \n  definition gen_ball :: \"('m \\<Rightarrow> _) \\<Rightarrow> _\" where\n    \"gen_ball it m P \\<equiv> it m (\\<lambda>x. x) (\\<lambda>x _. P x) True\"\n\n  lemma gen_ball[autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes IT: \"SIDE_GEN_ALGO (is_map_to_list Rk Rv Rm tsl)\"\n    shows \"(gen_ball (foldli o tsl),op_map_ball) \n    \\<in> \\<langle>Rk,Rv\\<rangle>Rm \\<rightarrow> (\\<langle>Rk,Rv\\<rangle>prod_rel \\<rightarrow> Id) \\<rightarrow> Id\"\n    apply (intro fun_relI)\n    unfolding gen_ball_def comp_def\n    apply (rule det_fold_map[OF foldli_ball IT[unfolded autoref_tag_defs]])\n    apply (parametricity)+\n    done\n\n  lemma foldli_bex_aux: \n    \"distinct (map fst l) \\<Longrightarrow> foldli l (\\<lambda>x. \\<not>x) (\\<lambda>x _. P x) b \n    \\<longleftrightarrow> b \\<or> op_map_bex (map_of l) P\"\n    apply (induct l arbitrary: b)\n    apply simp\n    apply (force simp: map_to_set_map_of image_def)\n    done\n  \n  lemma foldli_bex: \n    \"det_fold_map X (\\<lambda>x. \\<not>x) (\\<lambda>x _. P x) False (\\<lambda>m. op_map_bex m P)\"\n    apply rule\n    using foldli_bex_aux[where b=False] by auto\n\n  definition gen_bex :: \"('m \\<Rightarrow> _) \\<Rightarrow> _\" where\n    \"gen_bex it m P \\<equiv> it m (\\<lambda>x. \\<not>x) (\\<lambda>x _. P x) False\"\n\n  lemma gen_bex[autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes IT: \"SIDE_GEN_ALGO (is_map_to_list Rk Rv Rm tsl)\"\n    shows \"(gen_bex (foldli o tsl),op_map_bex) \n    \\<in> \\<langle>Rk,Rv\\<rangle>Rm \\<rightarrow> (\\<langle>Rk,Rv\\<rangle>prod_rel \\<rightarrow> Id) \\<rightarrow> Id\"\n    apply (intro fun_relI)\n    unfolding gen_bex_def comp_def\n    apply (rule det_fold_map[OF foldli_bex IT[unfolded autoref_tag_defs]])\n    apply (parametricity)+\n    done\n\n  lemma ball_isEmpty: \"op_map_isEmpty m = op_map_ball m (\\<lambda>_. False)\"\n    apply (auto intro!: ext)\n    by (metis map_to_set_simps(7) option.exhaust)\n\n  definition \"gen_isEmpty ball m \\<equiv> ball m (\\<lambda>_. False)\"\n\n  lemma gen_isEmpty[autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes BALL: \n      \"GEN_OP ball op_map_ball (\\<langle>Rk,Rv\\<rangle>Rm\\<rightarrow>(\\<langle>Rk,Rv\\<rangle>prod_rel\\<rightarrow>Id) \\<rightarrow> Id)\"\n    shows \"(gen_isEmpty ball,op_map_isEmpty) \n    \\<in> \\<langle>Rk,Rv\\<rangle>Rm \\<rightarrow> Id\"\n    apply (intro fun_relI)\n    unfolding gen_isEmpty_def using assms\n    unfolding autoref_tag_defs\n    apply -\n    apply (subst ball_isEmpty)\n    apply parametricity+\n    done\n  \n  lemma foldli_size_aux: \"distinct (map fst l) \n    \\<Longrightarrow> foldli l (\\<lambda>_. True) (\\<lambda>_ n. Suc n) n = n + op_map_size (map_of l)\"\n    apply (induct l arbitrary: n)\n    apply (auto simp: dom_map_of_conv_image_fst)\n    done\n\n  lemma foldli_size: \"det_fold_map X (\\<lambda>_. True) (\\<lambda>_ n. Suc n) 0 op_map_size\"\n    apply rule\n    using foldli_size_aux[where n=0] by simp\n\n  definition gen_size :: \"('m \\<Rightarrow> _) \\<Rightarrow> _\"\n    where \"gen_size it m \\<equiv> it m (\\<lambda>_. True) (\\<lambda>_ n. Suc n) 0\"\n\n  lemma gen_size[autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes IT: \"SIDE_GEN_ALGO (is_map_to_list Rk Rv Rm tsl)\"\n    shows \"(gen_size (foldli o tsl),op_map_size) \\<in> \\<langle>Rk,Rv\\<rangle>Rm \\<rightarrow> Id\"\n    apply (intro fun_relI)\n    unfolding gen_size_def comp_def\n    apply (rule det_fold_map[OF foldli_size IT[unfolded autoref_tag_defs]])\n    apply (parametricity)+\n    done\n  \n  lemma foldli_size_abort_aux:\n    \"\\<lbrakk>n0\\<le>m; distinct (map fst l)\\<rbrakk> \\<Longrightarrow> \n      foldli l (\\<lambda>n. n<m) (\\<lambda>_ n. Suc n) n0 = min m (n0 + card (dom (map_of l)))\"\n    apply (induct l arbitrary: n0)\n    apply (auto simp: dom_map_of_conv_image_fst)\n    done\n\n  lemma foldli_size_abort: \n    \"det_fold_map X (\\<lambda>n. n<m) (\\<lambda>_ n. Suc n) 0 (op_map_size_abort m)\"\n    apply rule\n    using foldli_size_abort_aux[where ?n0.0=0]\n    by simp\n\n  definition gen_size_abort :: \"('s \\<Rightarrow> _) \\<Rightarrow> _\" where\n    \"gen_size_abort it m s \\<equiv> it s (\\<lambda>n. n<m) (\\<lambda>_ n. Suc n) 0\"\n\n  lemma gen_size_abort[autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes IT: \"SIDE_GEN_ALGO (is_map_to_list Rk Rv Rm tsl)\"\n    shows \"(gen_size_abort (foldli o tsl),op_map_size_abort) \n      \\<in> Id \\<rightarrow> \\<langle>Rk,Rv\\<rangle>Rm \\<rightarrow> Id\"\n    apply (intro fun_relI)\n    unfolding gen_size_abort_def comp_def\n    apply (rule det_fold_map[OF foldli_size_abort \n      IT[unfolded autoref_tag_defs]])\n    apply (parametricity)+\n    done\n  \n  lemma size_abort_isSng: \"op_map_isSng s \\<longleftrightarrow> op_map_size_abort 2 s = 1\"\n    by (auto simp: dom_eq_singleton_conv min_def dest!: card_eq_SucD)\n\n  definition gen_isSng :: \"(nat \\<Rightarrow> 's \\<Rightarrow> nat) \\<Rightarrow> _\" where\n    \"gen_isSng sizea s \\<equiv> sizea 2 s = 1\"\n\n  lemma gen_isSng[autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes \"GEN_OP sizea op_map_size_abort (Id \\<rightarrow> (\\<langle>Rk,Rv\\<rangle>Rm) \\<rightarrow> Id)\"\n    shows \"(gen_isSng sizea,op_map_isSng) \n    \\<in> \\<langle>Rk,Rv\\<rangle>Rm \\<rightarrow> Id\"\n    apply (intro fun_relI)\n    unfolding gen_isSng_def using assms\n    unfolding autoref_tag_defs\n    apply -\n    apply (subst size_abort_isSng)\n    apply parametricity\n    done\n\n\n  (* TODO: Also do sel! *)\n\n  lemma foldli_pick:\n    assumes \"l\\<noteq>[]\" \n    obtains k v where \"(k,v)\\<in>set l\" \n    and \"(foldli l (case_option True (\\<lambda>_. False)) (\\<lambda>x _. Some x) None) \n      = Some (k,v)\"\n    using assms by (cases l) auto\n\n  definition gen_pick where\n    \"gen_pick it s \\<equiv> \n      (the (it s (case_option True (\\<lambda>_. False)) (\\<lambda>x _. Some x) None))\"\n\n\n\ncontext begin interpretation autoref_syn .\n\n  lemma gen_pick[autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes IT: \"SIDE_GEN_ALGO (is_map_to_list Rk Rv Rm it)\"\n    assumes SV: \"PREFER single_valued Rk\" \"PREFER single_valued Rv\"\n    assumes NE: \"SIDE_PRECOND (m'\\<noteq>Map.empty)\"\n    assumes SREF: \"(m,m')\\<in>\\<langle>Rk,Rv\\<rangle>Rm\"\n    shows \"(RETURN (gen_pick (\\<lambda>x. foldli (it x)) m), \n      (OP op_map_pick ::: \\<langle>Rk,Rv\\<rangle>Rm\\<rightarrow>\\<langle>Rk\\<times>\\<^sub>rRv\\<rangle>nres_rel)$m')\\<in>\\<langle>Rk\\<times>\\<^sub>rRv\\<rangle>nres_rel\"\n  proof -\n    thm is_map_to_list_def is_map_to_sorted_listE\n\n    obtain tsl' where\n      [param]: \"(it m,tsl') \\<in> \\<langle>Rk\\<times>\\<^sub>rRv\\<rangle>list_rel\" \n      and IT': \"RETURN tsl' \\<le> it_to_sorted_list (\\<lambda>_ _. True) (map_to_set m')\"\n      using IT[unfolded autoref_tag_defs is_map_to_list_def] SREF\n      by (auto intro: is_map_to_sorted_listE)\n\n    from IT' NE have \"tsl'\\<noteq>[]\" and [simp]: \"m'=map_of tsl'\" \n      and DIS': \"distinct (map fst tsl')\"\n      unfolding it_to_sorted_list_def \n      apply simp_all\n      apply (metis empty_set map_to_set_empty_iff(1))\n      apply (metis map_of_map_to_set map_to_set_distinct_conv)\n      apply (metis map_to_set_distinct_conv)\n      done\n\n    then obtain k v where \"m' k = Some v\" and\n      \"(foldli tsl' (case_option True (\\<lambda>_. False)) (\\<lambda>x _. Some x) None) \n        = Some (k,v)\"\n      (is \"?fld = _\")\n      by (cases rule: foldli_pick) auto\n    moreover \n    have \"(RETURN (gen_pick (\\<lambda>x. foldli (it x)) m), RETURN (the ?fld)) \n      \\<in> \\<langle>Rk\\<times>\\<^sub>rRv\\<rangle>nres_rel\"\n      unfolding gen_pick_def\n      using SV[unfolded autoref_tag_defs]\n      apply (parametricity add: the_paramR)\n      apply tagged_solver\n      using `?fld = Some (k,v)`\n      by simp\n    ultimately show ?thesis\n      apply (simp add: nres_rel_def)\n      apply (erule ref_two_step)\n      by simp\n  qed\nend\n\n\n  definition \"gen_map_pick_remove pick del m \\<equiv> do {\n    (k,v)\\<leftarrow>pick m;\n    let m = del k m;\n    RETURN ((k,v),m)\n    }\"\n  \ncontext begin interpretation autoref_syn .\n  lemma gen_map_pick_remove\n    [unfolded gen_map_pick_remove_def, autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes SV: \n      \"PREFER single_valued Rk\" \"PREFER single_valued Rv\"\n      \"PREFER single_valued (\\<langle>Rk,Rv\\<rangle>Rm)\"\n    assumes PICK: \"SIDE_GEN_OP (\n      (pick m, \n      (OP op_map_pick ::: \\<langle>Rk,Rv\\<rangle>Rm \\<rightarrow> \\<langle>Rk\\<times>\\<^sub>rRv\\<rangle>nres_rel)$m') \\<in>\n      \\<langle>Rk\\<times>\\<^sub>rRv\\<rangle>nres_rel)\"\n    assumes DEL: \"GEN_OP del op_map_delete (Rk \\<rightarrow> \\<langle>Rk,Rv\\<rangle>Rm \\<rightarrow> \\<langle>Rk,Rv\\<rangle>Rm)\"\n    assumes [param]: \"(m,m')\\<in>\\<langle>Rk,Rv\\<rangle>Rm\"\n    shows \"(gen_map_pick_remove pick del m, \n      (OP op_map_pick_remove \n        ::: \\<langle>Rk,Rv\\<rangle>Rm \\<rightarrow> \\<langle>(Rk\\<times>\\<^sub>rRv) \\<times>\\<^sub>r \\<langle>Rk,Rv\\<rangle>Rm\\<rangle>nres_rel)$m')\n      \\<in> \\<langle>(Rk\\<times>\\<^sub>rRv) \\<times>\\<^sub>r \\<langle>Rk,Rv\\<rangle>Rm\\<rangle>nres_rel\"\n  proof -\n    note [param] = \n      PICK[unfolded autoref_tag_defs] \n      DEL[unfolded autoref_tag_defs]\n\n    note [relator_props] = SV[unfolded autoref_tag_defs]\n\n    have \"(gen_map_pick_remove pick del m, \n      do {    \n        (k,v)\\<leftarrow>op_map_pick m';\n        let m' = op_map_delete k m';\n        RETURN ((k,v),m')\n      }) \\<in> \\<langle>(Rk\\<times>\\<^sub>rRv) \\<times>\\<^sub>r \\<langle>Rk,Rv\\<rangle>Rm\\<rangle>nres_rel\" (is \"(_,?h):_\")\n      unfolding gen_map_pick_remove_def[abs_def]\n      apply parametricity\n      apply tagged_solver\n      done\n    also have \"?h = op_map_pick_remove m'\"\n      by (auto simp add: pw_eq_iff refine_pw_simps)\n    finally show ?thesis by simp\n  qed\nend\n\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Collections/GenCF/Gen/Gen_Map.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5621764862150636, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.29644495023666845}}
{"text": "(*<*)\ntheory RCLogicL\n  imports RCLogic WellformedL\nbegin\n  (*>*)\n\nhide_const Syntax.dom\n\nchapter \\<open>Refinement Constraint Logic Lemmas\\<close>\n\nsection \\<open>Lemmas\\<close>\n\nlemma wfI_domi:\n  assumes \"\\<Theta> ; \\<Gamma> \\<turnstile> i\"\n  shows \"fst ` toSet \\<Gamma> \\<subseteq> dom i\"\n  using wfI_def toSet.simps assms by fastforce\n\nlemma wfI_lookup:\n  fixes G::\\<Gamma> and b::b\n  assumes \"Some (b,c) = lookup G x\" and \"P ; G \\<turnstile> i\" and \"Some s = i x\" and \"P ; B \\<turnstile>\\<^sub>w\\<^sub>f G\"\n  shows \"P \\<turnstile> s : b\"\nproof -\n  have \"(x,b,c) \\<in> toSet G\" using lookup.simps assms\n    using lookup_in_g by blast\n  then obtain s' where *:\"Some s' = i x \\<and> wfRCV P s' b\" using wfI_def assms by auto\n  hence \"s' = s\" using assms  by (metis option.inject)\n  thus ?thesis using * by auto\nqed\n\nlemma wfI_restrict_weakening:\n  assumes \"wfI \\<Theta> \\<Gamma>' i'\" and \"i =  restrict_map i' (fst `toSet \\<Gamma>)\" and \"toSet \\<Gamma> \\<subseteq> toSet \\<Gamma>'\"\n  shows  \"\\<Theta> ; \\<Gamma> \\<turnstile> i\"\nproof -\n  { fix x\n    assume \"x \\<in> toSet \\<Gamma>\"\n    have \"case x of (x, b, c) \\<Rightarrow> \\<exists>s. Some s = i x \\<and> \\<Theta> \\<turnstile> s : b\" using assms wfI_def\n    proof -\n      have \"case x of (x, b, c) \\<Rightarrow> \\<exists>s. Some s = i' x \\<and> \\<Theta> \\<turnstile> s : b\"\n        using \\<open>x \\<in> toSet \\<Gamma>\\<close>  assms wfI_def by auto\n      then have \"\\<exists>s. Some s = i (fst x) \\<and> wfRCV \\<Theta> s (fst (snd x))\"\n        by (simp add: \\<open>x \\<in> toSet \\<Gamma>\\<close> assms(2) case_prod_unfold)\n      then show ?thesis\n        by (simp add: case_prod_unfold)\n    qed\n  }\n  thus ?thesis using wfI_def assms by auto\nqed\n\nlemma wfI_suffix:\n  fixes G::\\<Gamma>\n  assumes \"wfI P (G'@G) i\" and \"P ; B \\<turnstile>\\<^sub>w\\<^sub>f G\"\n  shows \"P ; G \\<turnstile> i\"\n  using wfI_def append_g.simps assms toSet.simps by simp\n\nlemma wfI_replace_inside:\n  assumes \"wfI \\<Theta> (\\<Gamma>' @ (x, b, c) #\\<^sub>\\<Gamma> \\<Gamma>) i\"\n  shows  \"wfI \\<Theta> (\\<Gamma>' @ (x, b, c') #\\<^sub>\\<Gamma> \\<Gamma>) i\"\n  using wfI_def toSet_splitP assms by simp\n\nsection \\<open>Existence of evaluation\\<close>\n\nlemma eval_l_base:\n  \"\\<Theta> \\<turnstile> \\<lbrakk> l \\<rbrakk>  : (base_for_lit l)\"\n  apply(nominal_induct l rule:l.strong_induct)\n  using wfRCV.intros eval_l.simps  base_for_lit.simps by auto+\n\nlemma obtain_fresh_bv_dclist:\n  fixes tm::\"'a::fs\"\n  assumes \"(dc, \\<lbrace> x : b  | c \\<rbrace>) \\<in> set dclist\" \n  obtains bv1::bv and dclist1 x1 b1 c1 where \"AF_typedef_poly tyid bv dclist =  AF_typedef_poly tyid bv1 dclist1 \n      \\<and> (dc, \\<lbrace> x1 : b1  | c1 \\<rbrace>) \\<in> set dclist1 \\<and> atom bv1 \\<sharp> tm\" \nproof - \n  obtain bv1 dclist1 where \"AF_typedef_poly tyid bv dclist =  AF_typedef_poly tyid bv1 dclist1 \\<and> atom bv1 \\<sharp> tm\" \n    using obtain_fresh_bv by metis\n  moreover hence \"[[atom bv]]lst. dclist = [[atom bv1]]lst. dclist1\" using type_def.eq_iff by metis\n  moreover then obtain x1 b1 c1 where \"(dc, \\<lbrace> x1 : b1  | c1 \\<rbrace>) \\<in> set dclist1\" using td_lookup_eq_iff assms by metis\n  ultimately show ?thesis  using that by blast\nqed\n\nlemma obtain_fresh_bv_dclist_b_iff:\n  fixes tm::\"'a::fs\"\n  assumes \"(dc, \\<lbrace> x : b  | c \\<rbrace>) \\<in> set dclist\" and \"AF_typedef_poly tyid bv dclist \\<in> set P\" and \"\\<turnstile>\\<^sub>w\\<^sub>f P\"\n  obtains bv1::bv and dclist1 x1 b1 c1 where \"AF_typedef_poly tyid bv dclist =  AF_typedef_poly tyid bv1 dclist1 \n      \\<and> (dc, \\<lbrace> x1 : b1  | c1 \\<rbrace>) \\<in> set dclist1 \\<and> atom bv1 \\<sharp> tm \\<and> b[bv::=b']\\<^sub>b\\<^sub>b=b1[bv1::=b']\\<^sub>b\\<^sub>b\" \nproof - \n  obtain bv1 dclist1 x1 b1 c1 where *:\"AF_typedef_poly tyid bv dclist =  AF_typedef_poly tyid bv1 dclist1 \\<and> atom bv1 \\<sharp> tm\n    \\<and> (dc, \\<lbrace> x1 : b1  | c1 \\<rbrace>) \\<in> set dclist1\" using obtain_fresh_bv_dclist assms by metis\n\n  hence \"AF_typedef_poly tyid bv1 dclist1 \\<in> set P\" using assms by metis\n\n  hence \"b[bv::=b']\\<^sub>b\\<^sub>b = b1[bv1::=b']\\<^sub>b\\<^sub>b\" \n    using  wfTh_typedef_poly_b_eq_iff[OF assms(2) assms(1) _ _ assms(3),of bv1 dclist1 x1 b1 c1 b']  * by metis\n\n  from this that show ?thesis using * by metis  \nqed\n\nlemma eval_v_exist:\n  fixes \\<Gamma>::\\<Gamma> and v::v and b::b\n  assumes \"P ; \\<Gamma>  \\<turnstile> i\" and \"P ; B ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f v : b\"\n  shows \"\\<exists>s. i \\<lbrakk> v \\<rbrakk> ~  s \\<and> P \\<turnstile> s : b \"\n  using assms proof(nominal_induct v  arbitrary: b rule:v.strong_induct)\n  case (V_lit x)\n  then show ?case using eval_l_base eval_v.intros eval_l.simps wfV_elims rcl_val.supp pure_supp by metis\nnext\n  case (V_var x)\n  then obtain c where  *:\"Some (b,c) = lookup \\<Gamma> x\" using wfV_elims by metis\n  hence \"x \\<in> fst ` toSet \\<Gamma>\"  using lookup_x by blast\n  hence \"x \\<in> dom i\" using wfI_domi using assms by blast\n  then obtain s where \"i x = Some s\" by auto\n  moreover hence \"P \\<turnstile> s : b\" using wfRCV.intros wfI_lookup * V_var\n    by (metis wfV_wf)\n\n  ultimately show ?case using eval_v.intros rcl_val.supp b.supp  by metis\nnext\n  case (V_pair v1 v2)\n  then  obtain b1 and b2 where *:\"P ;  B ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f v1 : b1 \\<and>  P ;  B ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f v2 : b2 \\<and> b = B_pair b1 b2\" using wfV_elims by metis\n  then obtain s1 and s2 where \"eval_v i v1 s1 \\<and> wfRCV P s1 b1 \\<and> eval_v i v2 s2 \\<and> wfRCV P s2 b2\" using V_pair by metis\n  thus   ?case using eval_v.intros wfRCV.intros * by metis\nnext\n  case (V_cons tyid dc v)\n  then obtain  s and  b'::b and dclist and x::x and c::c where \"(wfV P  B  \\<Gamma> v  b') \\<and> i \\<lbrakk> v \\<rbrakk> ~  s \\<and> P \\<turnstile> s : b' \\<and> b = B_id tyid \\<and>\n                 AF_typedef tyid dclist \\<in> set P \\<and> (dc, \\<lbrace> x : b'  | c \\<rbrace>) \\<in> set dclist\" using  wfV_elims(4) by metis\n  then show ?case using eval_v.intros(4) wfRCV.intros(5) V_cons by metis\nnext\n  case (V_consp tyid dc b' v)\n\n  obtain  b'a::b and bv and dclist and x::x and c::c where *:\"(wfV P  B  \\<Gamma> v  b'a[bv::=b']\\<^sub>b\\<^sub>b) \\<and> b = B_app tyid b' \\<and>\n                 AF_typedef_poly tyid bv dclist \\<in> set P \\<and> (dc, \\<lbrace> x : b'a  | c \\<rbrace>) \\<in> set dclist \\<and> \n           atom bv \\<sharp> (P, B_app tyid b',B) \" using  wf_strong_elim(1)[OF V_consp(3)] by metis\n\n  then obtain s where **:\"i \\<lbrakk> v \\<rbrakk> ~ s  \\<and>  P  \\<turnstile> s : b'a[bv::=b']\\<^sub>b\\<^sub>b\" using V_consp by auto\n\n  have \" \\<turnstile>\\<^sub>w\\<^sub>f P\" using wfX_wfY V_consp  by metis\n  then obtain bv1::bv and dclist1 x1 b1 c1 where 3:\"AF_typedef_poly tyid bv dclist =  AF_typedef_poly tyid bv1 dclist1 \n      \\<and> (dc, \\<lbrace> x1 : b1  | c1 \\<rbrace>) \\<in> set dclist1 \\<and> atom bv1 \\<sharp>  (P, SConsp tyid dc b' s, B_app tyid b')\n          \\<and> b'a[bv::=b']\\<^sub>b\\<^sub>b = b1[bv1::=b']\\<^sub>b\\<^sub>b\" \n    using  *  obtain_fresh_bv_dclist_b_iff by blast\n\n  have \" i \\<lbrakk> V_consp tyid dc b' v \\<rbrakk> ~ SConsp tyid dc b' s\" using  eval_v.intros  by (simp add: \"**\")\n\n  moreover have \" P  \\<turnstile>  SConsp tyid dc b' s : B_app tyid b'\" proof\n    show \\<open>AF_typedef_poly tyid bv1 dclist1 \\<in> set P\\<close> using 3 * by metis\n    show \\<open>(dc, \\<lbrace> x1 : b1  | c1 \\<rbrace>) \\<in> set dclist1\\<close> using 3 by auto \n    thus \\<open>atom bv1 \\<sharp> (P, SConsp tyid dc b' s, B_app tyid b')\\<close> using * 3 fresh_prodN by metis\n    show \\<open> P  \\<turnstile> s : b1[bv1::=b']\\<^sub>b\\<^sub>b\\<close> using  3 ** by auto\n  qed\n\n  ultimately show ?case using eval_v.intros wfRCV.intros V_consp * by auto\nqed\n\nlemma eval_v_uniqueness:\n  fixes v::v\n  assumes \"i \\<lbrakk> v \\<rbrakk> ~  s\" and \"i \\<lbrakk> v \\<rbrakk> ~  s'\"\n  shows \"s=s'\"\n  using assms proof(nominal_induct v arbitrary: s s' rule:v.strong_induct)\n  case (V_lit x)\n  then show ?case using eval_v_elims eval_l.simps by metis\nnext\n  case (V_var x)\n  then show ?case using eval_v_elims   by (metis option.inject)\nnext\n  case (V_pair v1 v2)\n  obtain s1 and s2 where s:\"i \\<lbrakk> v1 \\<rbrakk> ~ s1  \\<and> i \\<lbrakk> v2 \\<rbrakk> ~ s2 \\<and> s = SPair s1 s2\" using eval_v_elims V_pair by metis\n  obtain s1' and s2' where s':\"i \\<lbrakk> v1 \\<rbrakk> ~ s1'  \\<and> i \\<lbrakk> v2 \\<rbrakk> ~ s2' \\<and> s' = SPair s1' s2'\"  using eval_v_elims V_pair by metis\n  then show ?case using eval_v_elims  using V_pair s s' by auto\nnext\n  case (V_cons tyid dc v1)\n  obtain sv1 where 1:\"i \\<lbrakk> v1 \\<rbrakk> ~ sv1 \\<and> s = SCons tyid dc sv1\" using eval_v_elims V_cons by metis\n  moreover obtain sv2 where 2:\"i \\<lbrakk> v1 \\<rbrakk> ~ sv2 \\<and> s' = SCons tyid dc sv2\" using eval_v_elims V_cons by metis\n  ultimately have \"sv1 = sv2\" using V_cons by auto\n  then show ?case  using 1 2 by auto \nnext\n  case (V_consp tyid dc b v1)\n  then show ?case using eval_v_elims  by metis\n\nqed\n\nlemma eval_v_base:\n  fixes \\<Gamma>::\\<Gamma> and v::v and b::b\n  assumes \"P ; \\<Gamma>  \\<turnstile> i\" and \"P ;  B ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f v : b\" and \"i \\<lbrakk> v \\<rbrakk> ~  s\"\n  shows \"P \\<turnstile> s : b\"\n  using eval_v_exist eval_v_uniqueness assms by metis\n\nlemma eval_e_uniqueness:\n  fixes e::ce\n  assumes \"i \\<lbrakk> e \\<rbrakk> ~ s\" and \"i \\<lbrakk> e \\<rbrakk> ~ s'\"\n  shows \"s=s'\"\n  using assms proof(nominal_induct e arbitrary: s s' rule:ce.strong_induct)\n  case (CE_val x)\n  then show ?case using eval_v_uniqueness eval_e_elims by metis\nnext\n  case (CE_op opp x1 x2)\n  consider \"opp = Plus\" | \"opp = LEq\" | \"opp = Eq\" using opp.exhaust by metis\n  thus  ?case proof(cases)\n    case 1\n    hence a1:\"eval_e i (CE_op Plus x1 x2) s\" and a2:\"eval_e i (CE_op Plus x1 x2) s'\" using CE_op by auto\n    then show ?thesis using   eval_e_elims(2)[OF a1] eval_e_elims(2)[OF a2]\n        CE_op eval_e_plusI \n      by (metis rcl_val.eq_iff(2))\n  next\n    case 2\n    hence a1:\"eval_e i (CE_op LEq x1 x2) s\" and a2:\"eval_e i (CE_op LEq x1 x2) s'\" using CE_op by auto\n    then show ?thesis using eval_v_uniqueness  eval_e_elims(3)[OF a1] eval_e_elims(3)[OF a2]\n        CE_op eval_e_plusI \n      by (metis rcl_val.eq_iff(2))\n  next\n    case 3\n    hence a1:\"eval_e i (CE_op Eq x1 x2) s\" and a2:\"eval_e i (CE_op Eq x1 x2) s'\" using CE_op by auto\n    then show ?thesis using eval_v_uniqueness  eval_e_elims(4)[OF a1] eval_e_elims(4)[OF a2]\n        CE_op eval_e_plusI \n      by (metis rcl_val.eq_iff(2))\n  qed\nnext\n  case (CE_concat x1 x2)\n  hence a1:\"eval_e i (CE_concat x1 x2) s\" and a2:\"eval_e i (CE_concat x1 x2) s'\" using CE_concat by auto\n  show ?case using  eval_e_elims(7)[OF a1] eval_e_elims(7)[OF a2] CE_concat eval_e_concatI rcl_val.eq_iff \n  proof -\n    assume \"\\<And>P. (\\<And>bv1 bv2. \\<lbrakk>s' = SBitvec (bv1 @ bv2); i \\<lbrakk> x1 \\<rbrakk> ~ SBitvec bv1 ; i \\<lbrakk> x2 \\<rbrakk> ~ SBitvec bv2 \\<rbrakk> \\<Longrightarrow> P) \\<Longrightarrow> P\"\n    obtain bbs :: \"bit list\" and bbsa :: \"bit list\" where\n      \"i \\<lbrakk> x2 \\<rbrakk> ~ SBitvec bbs \\<and> i \\<lbrakk> x1 \\<rbrakk> ~ SBitvec bbsa \\<and> SBitvec (bbsa @ bbs) = s'\"\n      by (metis \\<open>\\<And>P. (\\<And>bv1 bv2. \\<lbrakk>s' = SBitvec (bv1 @ bv2); i \\<lbrakk> x1 \\<rbrakk> ~ SBitvec bv1 ; i \\<lbrakk> x2 \\<rbrakk> ~ SBitvec bv2 \\<rbrakk> \\<Longrightarrow> P) \\<Longrightarrow> P\\<close>) (* 93 ms *)\n    then have \"s' = s\"\n      by (metis (no_types) \\<open>\\<And>P. (\\<And>bv1 bv2. \\<lbrakk>s = SBitvec (bv1 @ bv2); i \\<lbrakk> x1 \\<rbrakk> ~ SBitvec bv1 ; i \\<lbrakk> x2 \\<rbrakk> ~ SBitvec bv2 \\<rbrakk> \\<Longrightarrow> P) \\<Longrightarrow> P\\<close> \\<open>\\<And>s' s. \\<lbrakk>i \\<lbrakk> x1 \\<rbrakk> ~ s ; i \\<lbrakk> x1 \\<rbrakk> ~ s' \\<rbrakk> \\<Longrightarrow> s = s'\\<close> \\<open>\\<And>s' s. \\<lbrakk>i \\<lbrakk> x2 \\<rbrakk> ~ s ; i \\<lbrakk> x2 \\<rbrakk> ~ s' \\<rbrakk> \\<Longrightarrow> s = s'\\<close> rcl_val.eq_iff(1)) (* 125 ms *)\n    then show ?thesis\n      by metis (* 0.0 ms *)\n  qed\nnext\n  case (CE_fst x)\n  then show ?case using eval_v_uniqueness  by (meson eval_e_elims rcl_val.eq_iff)\nnext\n  case (CE_snd x)\n  then show ?case using eval_v_uniqueness  by (meson eval_e_elims rcl_val.eq_iff)\nnext\n  case (CE_len x)\n  then show ?case using  eval_e_elims rcl_val.eq_iff \n  proof -\n    obtain bbs :: \"rcl_val \\<Rightarrow> ce \\<Rightarrow> (x \\<Rightarrow> rcl_val option) \\<Rightarrow> bit list\" where\n      \"\\<forall>x0 x1 x2. (\\<exists>v3. x0 = SNum (int (length v3)) \\<and> x2 \\<lbrakk> x1 \\<rbrakk> ~ SBitvec v3 ) = (x0 = SNum (int (length (bbs x0 x1 x2))) \\<and> x2 \\<lbrakk> x1 \\<rbrakk> ~ SBitvec (bbs x0 x1 x2) )\"\n      by moura (* 0.0 ms *)\n    then have \"\\<forall>f c r. \\<not> f \\<lbrakk> [| c |]\\<^sup>c\\<^sup>e \\<rbrakk> ~ r \\<or> r = SNum (int (length (bbs r c f))) \\<and> f \\<lbrakk> c \\<rbrakk> ~ SBitvec (bbs r c f)\"\n      by (meson eval_e_elims(8)) (* 46 ms *)\n    then show ?thesis\n      by (metis (no_types) CE_len.hyps CE_len.prems(1) CE_len.prems(2) rcl_val.eq_iff(1)) (* 31 ms *)\n  qed\n\nqed\n\nlemma wfV_eval_bitvec:\n  fixes v::v\n  assumes  \"P ;  B ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f v : B_bitvec\" and \"P ; \\<Gamma>  \\<turnstile> i\"\n  shows \"\\<exists>bv. eval_v i v (SBitvec bv)\"\nproof -\n  obtain s where \"i \\<lbrakk> v \\<rbrakk> ~  s \\<and> wfRCV P s B_bitvec\" using eval_v_exist assms by metis\n  moreover then obtain bv where \"s = SBitvec bv\" using wfRCV_elims(1)[of P s] by metis\n  ultimately show  ?thesis by metis\nqed\n\nlemma wfV_eval_pair:\n  fixes v::v\n  assumes  \"P ;  B ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f v : B_pair b1 b2\" and \"P ; \\<Gamma>  \\<turnstile> i\"\n  shows \"\\<exists>s1 s2. eval_v i v (SPair s1 s2)\"\nproof -\n  obtain s  where \"i \\<lbrakk> v \\<rbrakk> ~  s \\<and> wfRCV P s (B_pair b1 b2)\" using eval_v_exist assms by metis\n  moreover then obtain s1 and s2 where \"s = SPair s1 s2\" using wfRCV_elims(2)[of P s] by metis\n  ultimately show  ?thesis by metis\nqed\n\nlemma wfV_eval_int:\n  fixes v::v\n  assumes  \"P ;  B ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f v : B_int\" and \"P ; \\<Gamma>  \\<turnstile> i\"\n  shows \"\\<exists>n. eval_v i v (SNum n)\"\nproof -\n  obtain s  where \"i \\<lbrakk> v \\<rbrakk> ~  s \\<and> wfRCV P s (B_int)\" using eval_v_exist assms by metis\n  moreover then obtain n where \"s = SNum n\" using wfRCV_elims(3)[of P s] by metis\n  ultimately show  ?thesis by metis\nqed\n\ntext \\<open>Well sorted value with a well sorted valuation evaluates\\<close>\nlemma wfI_wfV_eval_v:\n  fixes v::v and b::b\n  assumes \"\\<Theta> ;  B ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f v : b\" and \"wfI \\<Theta>  \\<Gamma> i\"\n  shows \"\\<exists>s. i \\<lbrakk> v \\<rbrakk> ~  s \\<and> \\<Theta> \\<turnstile> s : b\"\n  using eval_v_exist assms by auto\n\nlemma wfI_wfCE_eval_e:\n  fixes e::ce and b::b\n  assumes \"wfCE P B G e b\" and \"P ; G \\<turnstile> i\" \n  shows \"\\<exists>s. i \\<lbrakk> e \\<rbrakk> ~ s \\<and> P \\<turnstile> s : b\"\n  using assms proof(nominal_induct e arbitrary:  b  rule: ce.strong_induct)\n  case (CE_val v)\n  obtain s where \"i \\<lbrakk> v \\<rbrakk> ~ s \\<and> P \\<turnstile> s : b\" using wfI_wfV_eval_v[of P B G v b i]  assms wfCE_elims(1)  [of P B G v b] CE_val  by auto\n  then show ?case using CE_val   eval_e.intros(1)[of i v s ] by auto\nnext\n  case (CE_op opp v1 v2)\n\n  consider \"opp =Plus\" | \"opp=LEq\" | \"opp=Eq\" using opp.exhaust by auto\n\n  thus ?case proof(cases)\n    case 1\n    hence  \"wfCE P  B G v1 B_int \\<and> wfCE P  B G v2 B_int\" using wfCE_elims(2) CE_op\n\n      by blast\n    then obtain s1 and s2 where *: \"eval_e i v1 s1 \\<and> wfRCV P s1 B_int \\<and> eval_e i v2 s2 \\<and> wfRCV P s2 B_int\"\n      using wfI_wfV_eval_v  CE_op by metis\n    then obtain n1 and n2 where **:\"s2=SNum n2 \\<and> s1 = SNum n1\"  using wfRCV_elims  by meson\n    hence \"eval_e i (CE_op Plus v1 v2) (SNum (n1+n2))\" using eval_e_plusI * ** by simp\n    moreover have \"wfRCV P (SNum (n1+n2)) B_int\" using wfRCV.intros by auto\n    ultimately show ?thesis using 1\n      using CE_op.prems(1) wfCE_elims(2) by blast\n  next\n    case 2\n    hence  \"wfCE P  B G v1 B_int \\<and> wfCE P  B G v2 B_int\" using wfCE_elims(3) CE_op\n      by blast\n    then obtain s1 and s2 where *: \"eval_e i v1 s1 \\<and> wfRCV P s1 B_int \\<and> eval_e i v2 s2 \\<and> wfRCV P s2 B_int\"\n      using wfI_wfV_eval_v  CE_op by metis\n    then obtain n1 and n2 where **:\"s2=SNum n2 \\<and> s1 = SNum n1\"  using wfRCV_elims  by meson\n    hence \"eval_e i (CE_op LEq v1 v2) (SBool (n1 \\<le> n2))\" using eval_e_leqI * ** by simp\n    moreover have \"wfRCV P (SBool (n1\\<le>n2)) B_bool\" using wfRCV.intros by auto\n    ultimately show ?thesis using 2\n      using CE_op.prems wfCE_elims by metis\n  next\n    case 3\n    then  obtain b2 where \"wfCE P  B G v1 b2 \\<and> wfCE P  B G v2 b2\" using wfCE_elims(9) CE_op\n      by blast\n    then obtain s1 and s2 where *: \"eval_e i v1 s1 \\<and> wfRCV P s1 b2 \\<and> eval_e i v2 s2 \\<and> wfRCV P s2 b2\"\n      using wfI_wfV_eval_v  CE_op by metis\n    hence \"eval_e i (CE_op Eq v1 v2) (SBool (s1 = s2))\" using eval_e_leqI *  \n      by (simp add: eval_e_eqI)\n    moreover have \"wfRCV P (SBool (s1 = s2)) B_bool\" using wfRCV.intros by auto\n    ultimately show ?thesis using 3\n      using CE_op.prems wfCE_elims by metis\n  qed\nnext\n  case (CE_concat v1 v2)\n  then obtain s1 and s2 where *:\"b = B_bitvec \\<and> eval_e i v1 s1 \\<and> eval_e i v2 s2 \\<and>\n      wfRCV P s1 B_bitvec \\<and> wfRCV P s2 B_bitvec\" using  \n    CE_concat \n    by (meson wfCE_elims(6))\n  thus ?case using  eval_e_concatI wfRCV.intros(1) wfRCV_elims \n  proof -\n    obtain bbs :: \"type_def list \\<Rightarrow> rcl_val \\<Rightarrow> bit list\" where\n      \"\\<forall>ts s. \\<not> ts \\<turnstile> s : B_bitvec \\<or> s = SBitvec (bbs ts s)\"\n      using wfRCV_elims(1) by moura (* 156 ms *)\n    then show ?thesis\n      by (metis (no_types) \"local.*\" wfRCV_BBitvecI eval_e_concatI) (* 78 ms *)\n  qed\nnext\n  case (CE_fst v1)\n  thus ?case using  eval_e_fstI  wfRCV.intros wfCE_elims wfI_wfV_eval_v\n    by (metis wfRCV_elims(2) rcl_val.eq_iff(4))\nnext\n  case (CE_snd v1)\n  thus ?case using  eval_e_sndI  wfRCV.intros wfCE_elims wfI_wfV_eval_v\n    by (metis wfRCV_elims(2) rcl_val.eq_iff(4))\nnext\n  case (CE_len x)\n  thus ?case using  eval_e_lenI  wfRCV.intros wfCE_elims wfI_wfV_eval_v wfV_eval_bitvec \n    by (metis wfRCV_elims(1))\nqed\n\nlemma eval_e_exist:\n  fixes \\<Gamma>::\\<Gamma> and e::ce\n  assumes \"P ; \\<Gamma>  \\<turnstile> i\" and \"P ;  B ; \\<Gamma>  \\<turnstile>\\<^sub>w\\<^sub>f e : b\"\n  shows \"\\<exists>s. i \\<lbrakk> e \\<rbrakk> ~ s\"\n  using assms proof(nominal_induct e arbitrary: b rule:ce.strong_induct)\n  case (CE_val v)\n  then show ?case using eval_v_exist wfCE_elims eval_e.intros by metis\nnext\n  case (CE_op op v1 v2)\n\n  show ?case proof(rule opp.exhaust)\n    assume \\<open>op = Plus\\<close>\n    hence \"P ;  B ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f v1 : B_int \\<and> P ;  B ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f v2 : B_int \\<and> b = B_int\" using wfCE_elims CE_op by metis\n    then obtain n1 and n2 where \"eval_e i v1 (SNum n1) \\<and> eval_e i v2 (SNum n2)\" using CE_op eval_v_exist wfV_eval_int \n      by (metis wfI_wfCE_eval_e wfRCV_elims(3))\n    then show \\<open>\\<exists>a. eval_e i (CE_op op v1 v2) a\\<close> using eval_e_plusI[of i v1 _ v2] \\<open>op=Plus\\<close> by auto\n  next\n    assume \\<open>op = LEq\\<close>\n    hence \"P ;  B ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f v1 : B_int \\<and> P ;  B ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f v2 : B_int \\<and> b = B_bool\" using wfCE_elims CE_op by metis\n    then obtain n1 and n2 where \"eval_e i v1 (SNum n1) \\<and> eval_e i v2 (SNum n2)\" using CE_op eval_v_exist wfV_eval_int \n      by (metis wfI_wfCE_eval_e wfRCV_elims(3))\n    then show \\<open>\\<exists>a. eval_e i (CE_op op v1 v2) a\\<close> using eval_e_leqI[of i v1 _ v2] eval_v_exist \\<open>op=LEq\\<close> CE_op by auto\n  next\n    assume \\<open>op = Eq\\<close>\n    then obtain b1 where  \"P ;  B ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f v1 : b1 \\<and> P ;  B ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f v2 : b1 \\<and> b = B_bool\" using wfCE_elims CE_op by metis\n    then obtain s1 and s2 where \"eval_e i v1 s1 \\<and> eval_e i v2 s2\" using CE_op eval_v_exist wfV_eval_int \n      by (metis wfI_wfCE_eval_e wfRCV_elims(3))\n    then show \\<open>\\<exists>a. eval_e i (CE_op op v1 v2) a\\<close> using eval_e_eqI[of i v1 _ v2] eval_v_exist \\<open>op=Eq\\<close> CE_op by auto\n  qed\nnext\n  case (CE_concat v1 v2)\n  then obtain bv1 and bv2 where \"eval_e i v1 (SBitvec bv1) \\<and> eval_e i v2 (SBitvec bv2)\"\n    using wfV_eval_bitvec  wfCE_elims(6) \n    by (meson eval_e_elims(7) wfI_wfCE_eval_e)\n  then show ?case using  eval_e.intros by metis\nnext\n  case (CE_fst ce)\n  then obtain b2 where b:\"P ; B ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f ce : B_pair b b2\" using wfCE_elims by metis\n  then obtain s where s:\"i \\<lbrakk> ce \\<rbrakk> ~ s\" using CE_fst by auto\n  then obtain s1 and s2 where \"s = (SPair s1 s2)\" using eval_e_elims(4)  CE_fst wfI_wfCE_eval_e[of P B \\<Gamma> ce \"B_pair b b2\" i,OF b] wfRCV_elims(2)[of P s b b2]    \n    by (metis eval_e_uniqueness)\n  then show ?case using s eval_e.intros by metis\nnext\n  case (CE_snd ce)\n  then obtain b1 where b:\"P ; B ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f ce : B_pair b1 b\" using wfCE_elims by metis\n  then obtain s where s:\"i \\<lbrakk> ce \\<rbrakk> ~ s\" using CE_snd by auto\n  then obtain s1 and s2 where \"s = (SPair s1 s2)\" \n    using eval_e_elims(5)  CE_snd wfI_wfCE_eval_e[of P B \\<Gamma> ce \"B_pair b1 b\" i,OF b] wfRCV_elims(2)[of P s b b1]    \n      eval_e_uniqueness \n    by (metis wfRCV_elims(2))\n  then show ?case using s eval_e.intros by metis\nnext\n  case (CE_len v1)\n  then obtain bv1  where \"eval_e i v1 (SBitvec bv1)\"\n    using wfV_eval_bitvec  CE_len  wfCE_elims eval_e_uniqueness \n    by (metis eval_e_elims(7) wfCE_concatI wfI_wfCE_eval_e)\n  then show ?case using  eval_e.intros by metis\nqed\n\nlemma eval_c_exist:\n  fixes \\<Gamma>::\\<Gamma> and c::c\n  assumes \"P ; \\<Gamma>  \\<turnstile> i\" and \"P ; B ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f c\"\n  shows \"\\<exists>s. i \\<lbrakk> c \\<rbrakk> ~ s\"\n  using assms proof(nominal_induct c  rule: c.strong_induct)\n  case C_true\n  then show ?case using eval_c.intros wfC_elims by metis\nnext\n  case C_false\n  then show ?case using eval_c.intros wfC_elims by metis\nnext\n  case (C_conj c1 c2)\n  then show ?case using eval_c.intros wfC_elims by metis\nnext\n  case (C_disj x1 x2)\n  then show ?case using eval_c.intros wfC_elims by metis\nnext\n  case (C_not x)\n  then show ?case using eval_c.intros wfC_elims by metis\nnext\n  case (C_imp x1 x2)\n  then show ?case using eval_c.intros eval_e_exist wfC_elims by metis\nnext\n  case (C_eq x1 x2)\n  then show ?case using eval_c.intros eval_e_exist wfC_elims by metis\nqed\n\nlemma eval_c_uniqueness:\n  fixes c::c\n  assumes \"i \\<lbrakk> c \\<rbrakk> ~ s\" and \"i \\<lbrakk> c \\<rbrakk> ~ s'\"\n  shows \"s=s'\"\n  using assms proof(nominal_induct c arbitrary: s s' rule:c.strong_induct)\n  case C_true\n  then show ?case using eval_c_elims by metis\nnext\n  case C_false\n  then show ?case using eval_c_elims by metis\nnext\n  case (C_conj x1 x2)\n  then show ?case using  eval_c_elims(3) by (metis (full_types))\nnext\n  case (C_disj x1 x2)\n  then show ?case using eval_c_elims(4)  by (metis (full_types))\nnext\n  case (C_not x)\n  then show ?case using eval_c_elims(6)  by (metis (full_types))\nnext\n  case (C_imp x1 x2)\n  then show ?case using eval_c_elims(5)  by (metis (full_types))\nnext\n  case (C_eq x1 x2)\n  then show ?case using eval_e_uniqueness eval_c_elims(7) by metis\nqed\n\nlemma wfI_wfC_eval_c:\n  fixes c::c\n  assumes \"wfC P B G c\" and \"P ; G \\<turnstile> i\"\n  shows \"\\<exists>s. i \\<lbrakk> c \\<rbrakk> ~ s\"\n  using assms proof(nominal_induct c  rule: c.strong_induct)\nqed(metis wfC_elims wfI_wfCE_eval_e eval_c.intros)+\n\nsection \\<open>Satisfiability\\<close>\n\nlemma satis_reflI:\n  fixes c::c\n  assumes \"i \\<Turnstile> ((x, b, c) #\\<^sub>\\<Gamma> G)\"\n  shows \"i \\<Turnstile> c\"\n  using assms by auto\n\nlemma is_satis_mp:\n  fixes c1::c and c2::c\n  assumes \"i \\<Turnstile> (c1 IMP c2)\" and \"i \\<Turnstile> c1\"\n  shows \"i \\<Turnstile> c2\"\n  using assms proof -\n  have \"eval_c i (c1 IMP c2) True\" using is_satis.simps  using assms by blast\n  then obtain b1 and b2 where \"True = (b1 \\<longrightarrow> b2) \\<and> eval_c i c1 b1 \\<and> eval_c i c2 b2\"\n    using eval_c_elims(5) by metis\n  moreover have \"eval_c i c1 True\" using is_satis.simps  using assms by blast\n  moreover have \"b1 = True\" using calculation eval_c_uniqueness  by blast\n  ultimately have \"eval_c i c2 True\" by auto\n  thus ?thesis using is_satis.intros by auto\nqed\n\nlemma is_satis_imp:\n  fixes c1::c and c2::c\n  assumes \"i \\<Turnstile> c1 \\<longrightarrow> i \\<Turnstile> c2\" and \"i \\<lbrakk> c1 \\<rbrakk> ~ b1\" and \"i \\<lbrakk> c2 \\<rbrakk> ~ b2\"\n  shows \"i \\<Turnstile> (c1 IMP c2)\"\nproof(cases b1)\n  case True\n  hence \"i \\<Turnstile> c2\" using assms is_satis.simps by simp\n  hence \"b2 = True\" using is_satis.simps assms\n    using eval_c_uniqueness by blast\n  then show ?thesis using eval_c_impI is_satis.simps assms by force\nnext\n  case False\n  then show ?thesis using assms eval_c_impI is_satis.simps by metis\nqed\n\nlemma is_satis_iff:\n  \"i \\<Turnstile> G  = (\\<forall>x b c. (x,b,c) \\<in> toSet G \\<longrightarrow> i \\<Turnstile> c)\"\n  by(induct G,auto)\n\nlemma is_satis_g_append:\n  \"i \\<Turnstile> (G1@G2) = (i \\<Turnstile>  G1 \\<and> i \\<Turnstile>  G2)\"\n  using is_satis_g.simps  is_satis_iff by auto\n\nsection \\<open>Substitution for Evaluation\\<close>\n\nlemma eval_v_i_upd:\n  fixes v::v\n  assumes \"atom x \\<sharp> v\" and \"i \\<lbrakk> v \\<rbrakk> ~  s'\"\n  shows \"eval_v ((i ( x \\<mapsto>s))) v s' \"\n  using assms proof(nominal_induct v arbitrary: s' rule:v.strong_induct)\n  case (V_lit x)\n  then show ?case  by (metis eval_v_elims(1) eval_v_litI)\nnext\n  case (V_var y)\n  then obtain s where *: \"Some s = i y \\<and> s=s'\" using eval_v_elims by metis\n  moreover have \"x \\<noteq> y\" using \\<open>atom x \\<sharp> V_var y\\<close> v.supp by simp\n  ultimately have \"(i ( x \\<mapsto>s)) y = Some s\"\n    by (simp add: \\<open>Some s = i y \\<and> s = s'\\<close>)\n  then show ?case using eval_v_varI *  \\<open>x \\<noteq> y\\<close>\n    by (simp add: eval_v.eval_v_varI)\nnext\n  case (V_pair v1 v2)\n  hence \"atom x \\<sharp> v1 \\<and> atom x \\<sharp> v2\" using v.supp by simp\n  moreover obtain s1 and s2 where *: \"eval_v i v1 s1 \\<and> eval_v i v2 s2 \\<and> s' = SPair s1 s2\" using eval_v_elims V_pair by metis\n  ultimately have \"eval_v ((i ( x \\<mapsto>s))) v1 s1 \\<and> eval_v ((i ( x \\<mapsto>s))) v2 s2\" using V_pair by blast\n  thus ?case using eval_v_pairI * by meson\nnext\n  case (V_cons tyid dc v1)\n  hence \"atom x \\<sharp> v1\" using v.supp by simp\n  moreover obtain s1 where *: \"eval_v i v1 s1 \\<and> s' = SCons tyid dc s1\" using eval_v_elims V_cons by metis\n  ultimately have \"eval_v ((i ( x \\<mapsto>s))) v1 s1\" using V_cons by blast\n  thus ?case using eval_v_consI * by meson\nnext\n  case (V_consp tyid dc b1 v1)\n\n  hence \"atom x \\<sharp> v1\" using v.supp by simp\n  moreover obtain s1 where *: \"eval_v i v1 s1 \\<and> s' = SConsp tyid dc b1 s1\" using eval_v_elims V_consp by metis\n  ultimately have \"eval_v ((i ( x \\<mapsto>s))) v1 s1\" using V_consp by blast\n  thus ?case using eval_v_conspI * by meson\nqed\n\nlemma eval_e_i_upd:\n  fixes e::ce\n  assumes \"i \\<lbrakk> e \\<rbrakk> ~ s'\" and \"atom x \\<sharp> e\"\n  shows \" (i ( x \\<mapsto>s)) \\<lbrakk> e \\<rbrakk> ~ s'\"\n  using assms apply(induct rule: eval_e.induct) using eval_v_i_upd eval_e_elims\n  by (meson ce.fresh eval_e.intros)+\n\nlemma eval_c_i_upd:\n  fixes c::c\n  assumes \"i \\<lbrakk> c \\<rbrakk> ~ s'\" and \"atom x \\<sharp> c\"\n  shows \"((i ( x \\<mapsto>s))) \\<lbrakk> c \\<rbrakk> ~ s' \"\n  using assms proof(induct rule:eval_c.induct)\n  case (eval_c_eqI i e1 sv1 e2 sv2)\n  then show ?case using RCLogic.eval_c_eqI eval_e_i_upd c.fresh by metis\nqed(simp add: eval_c.intros)+\n\nlemma subst_v_eval_v[simp]:\n  fixes v::v and v'::v\n  assumes \"i \\<lbrakk> v \\<rbrakk> ~  s\" and \"i \\<lbrakk> (v'[x::=v]\\<^sub>v\\<^sub>v) \\<rbrakk> ~ s'\"\n  shows \"(i ( x \\<mapsto> s )) \\<lbrakk> v' \\<rbrakk> ~ s'\"\n  using assms proof(nominal_induct v' arbitrary: s' rule:v.strong_induct)\n  case (V_lit x)\n  then show ?case using subst_vv.simps\n    by (metis eval_v_elims(1) eval_v_litI)\nnext\n  case (V_var x')\n  then show ?case proof(cases \"x=x'\")\n    case True\n    hence \"(V_var x')[x::=v]\\<^sub>v\\<^sub>v = v\" using subst_vv.simps by auto\n    then show ?thesis using V_var eval_v_elims eval_v_varI eval_v_uniqueness True\n      by (simp add: eval_v.eval_v_varI)\n  next\n    case False\n    hence \"atom x \\<sharp> (V_var x')\" by simp\n    then show ?thesis using eval_v_i_upd False V_var by fastforce\n  qed\nnext\n  case (V_pair v1 v2)\n  then obtain s1 and s2 where *:\"eval_v i (v1[x::=v]\\<^sub>v\\<^sub>v) s1 \\<and> eval_v i (v2[x::=v]\\<^sub>v\\<^sub>v) s2 \\<and> s' = SPair s1 s2\" using V_pair eval_v_elims subst_vv.simps by metis\n  hence \"(i ( x \\<mapsto> s )) \\<lbrakk> v1 \\<rbrakk> ~ s1 \\<and> (i ( x \\<mapsto> s )) \\<lbrakk> v2 \\<rbrakk> ~ s2\" using V_pair by metis\n  thus  ?case  using eval_v_pairI subst_vv.simps * V_pair by metis\nnext\n  case (V_cons tyid dc v1)\n  then obtain s1 where \"eval_v i (v1[x::=v]\\<^sub>v\\<^sub>v) s1\" using eval_v_elims subst_vv.simps by metis\n  thus ?case  using eval_v_consI V_cons\n    by (metis eval_v_elims subst_vv.simps)\nnext\n  case (V_consp tyid dc b1 v1)\n\n  then obtain s1 where *:\"eval_v i (v1[x::=v]\\<^sub>v\\<^sub>v) s1 \\<and> s' = SConsp tyid dc b1 s1\" using eval_v_elims subst_vv.simps by metis\n  hence \"i ( x \\<mapsto> s ) \\<lbrakk> v1 \\<rbrakk> ~ s1\" using V_consp by metis\n  thus ?case  using * eval_v_conspI by metis \nqed\n\nlemma subst_e_eval_v[simp]:\n  fixes y::x and e::ce and v::v and e'::ce\n  assumes  \"i \\<lbrakk> e' \\<rbrakk> ~  s'\" and \"e'=(e[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v)\" and \"i \\<lbrakk> v \\<rbrakk> ~  s\"\n  shows \"(i ( y \\<mapsto> s )) \\<lbrakk> e \\<rbrakk> ~ s'\"\n  using assms proof(induct arbitrary: e rule: eval_e.induct)\n  case (eval_e_valI i v1 sv)\n  then obtain v1' where *:\"e = CE_val v1' \\<and> v1 = v1'[y::=v]\\<^sub>v\\<^sub>v\"\n    using assms by(nominal_induct e rule:ce.strong_induct,simp+)\n  hence \"eval_v i (v1'[y::=v]\\<^sub>v\\<^sub>v) sv\" using eval_e_valI by simp\n  hence \"eval_v (i ( y \\<mapsto> s )) v1' sv\" using subst_v_eval_v eval_e_valI by simp\n  then show ?case using RCLogic.eval_e_valI * by meson\nnext\n  case (eval_e_plusI i v1 n1 v2 n2)\n  then obtain v1' and v2' where *:\"e = CE_op Plus v1' v2' \\<and> v1 = v1'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v \\<and> v2 = v2'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v\"\n    using assms by(nominal_induct e rule:ce.strong_induct,simp+)\n  hence \"eval_e i (v1'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v) (SNum n1) \\<and> eval_e i (v2'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v) (SNum n2)\" using eval_e_plusI by simp\n  hence \"eval_e (i ( y \\<mapsto> s )) v1' (SNum n1) \\<and>  eval_e (i ( y \\<mapsto> s )) v2' (SNum n2)\" using subst_v_eval_v eval_e_plusI \n    using \"local.*\" by blast\n  then show ?case using RCLogic.eval_e_plusI * by meson\nnext\n  case (eval_e_leqI i v1 n1 v2 n2)\n  then obtain v1' and v2' where *:\"e = CE_op LEq v1' v2' \\<and> v1 = v1'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v \\<and> v2 = v2'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v\"\n    using assms by(nominal_induct e rule:ce.strong_induct,simp+)\n  hence \"eval_e i (v1'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v) (SNum n1) \\<and> eval_e i (v2'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v) (SNum n2)\" using eval_e_leqI by simp\n  hence \"eval_e (i ( y \\<mapsto> s )) v1' (SNum n1) \\<and>  eval_e (i ( y \\<mapsto> s )) v2' (SNum n2)\" using subst_v_eval_v eval_e_leqI \n    using * by blast\n  then show ?case using RCLogic.eval_e_leqI * by meson\nnext\n  case (eval_e_eqI i v1 n1 v2 n2)\n  then obtain v1' and v2' where *:\"e = CE_op Eq v1' v2' \\<and> v1 = v1'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v \\<and> v2 = v2'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v\"\n    using assms by(nominal_induct e rule:ce.strong_induct,simp+)\n  hence \"eval_e i (v1'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v) n1 \\<and> eval_e i (v2'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v) n2\" using eval_e_eqI by simp\n  hence \"eval_e (i ( y \\<mapsto> s )) v1' n1 \\<and>  eval_e (i ( y \\<mapsto> s )) v2' n2\" using subst_v_eval_v eval_e_eqI \n    using * by blast\n  then show ?case using RCLogic.eval_e_eqI * by meson\nnext\n  case (eval_e_fstI i v1 s1 s2)\n  then obtain v1' and v2' where *:\"e = CE_fst v1' \\<and> v1 = v1'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v\"\n    using assms by(nominal_induct e rule:ce.strong_induct,simp+)\n  hence \"eval_e i (v1'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v) (SPair s1 s2)\" using eval_e_fstI by simp\n  hence \"eval_e (i ( y \\<mapsto> s )) v1' (SPair s1 s2)\" using eval_e_fstI * by metis\n  then show ?case using RCLogic.eval_e_fstI * by meson\nnext\n  case (eval_e_sndI i v1 s1 s2)\n  then obtain v1' and v2' where *:\"e = CE_snd v1' \\<and> v1 = v1'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v\"\n    using assms by(nominal_induct e rule:ce.strong_induct,simp+)\n  hence \"eval_e i (v1'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v) (SPair s1 s2)\" using eval_e_sndI by simp\n  hence \"eval_e (i ( y \\<mapsto> s )) v1' (SPair s1 s2)\" using subst_v_eval_v eval_e_sndI * by blast\n  then show ?case using RCLogic.eval_e_sndI * by meson\nnext\n  case (eval_e_concatI i v1 bv1 v2 bv2)\n  then obtain v1' and v2' where *:\"e = CE_concat v1' v2' \\<and> v1 = v1'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v \\<and> v2 = v2'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v\"\n    using assms by(nominal_induct e rule:ce.strong_induct,simp+)\n  hence \"eval_e i (v1'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v) (SBitvec bv1) \\<and> eval_e i (v2'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v) (SBitvec bv2)\" using eval_e_concatI by simp\n  moreover hence \"eval_e (i ( y \\<mapsto> s )) v1' (SBitvec bv1) \\<and>  eval_e (i ( y \\<mapsto> s )) v2' (SBitvec bv2)\" \n    using subst_v_eval_v eval_e_concatI * by blast\n  ultimately show ?case using RCLogic.eval_e_concatI * eval_v_uniqueness  by (metis eval_e_concatI.hyps(1))\nnext\n  case (eval_e_lenI i v1 bv)\n  then obtain v1' where *:\"e = CE_len v1' \\<and> v1 = v1'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v\"\n    using assms by(nominal_induct e rule:ce.strong_induct,simp+)\n  hence \"eval_e i (v1'[y::=v]\\<^sub>c\\<^sub>e\\<^sub>v) (SBitvec bv)\" using eval_e_lenI by simp\n  hence \"eval_e (i ( y \\<mapsto> s )) v1' (SBitvec bv)\" using subst_v_eval_v eval_e_lenI * by blast\n  then show ?case using RCLogic.eval_e_lenI * by meson\nqed\n\nlemma subst_c_eval_v[simp]:\n  fixes v::v and c :: c\n  assumes \"i \\<lbrakk> v \\<rbrakk> ~  s\" and \"i \\<lbrakk> c[x::=v]\\<^sub>c\\<^sub>v \\<rbrakk> ~ s1\" and\n    \"(i ( x \\<mapsto> s)) \\<lbrakk> c \\<rbrakk> ~ s2\"\n  shows \"s1 = s2\"\n  using assms proof(nominal_induct c arbitrary: s1 s2 rule: c.strong_induct)\n  case C_true\n  hence \"s1 = True \\<and> s2 = True\" using eval_c_elims subst_cv.simps  by auto\n  then show ?case by auto\nnext\n  case C_false\n  hence \"s1 = False \\<and> s2 = False\" using eval_c_elims subst_cv.simps by metis\n  then show ?case by auto\nnext\n  case (C_conj c1 c2)\n  hence *:\"eval_c i (c1[x::=v]\\<^sub>c\\<^sub>v AND c2[x::=v]\\<^sub>c\\<^sub>v) s1\" using subst_cv.simps by auto\n  then obtain s11 and s12 where \"(s1 = (s11 \\<and> s12)) \\<and> eval_c i c1[x::=v]\\<^sub>c\\<^sub>v s11 \\<and> eval_c i c2[x::=v]\\<^sub>c\\<^sub>v s12\" using\n      eval_c_elims(3) by metis\n  moreover obtain   s21 and s22 where \"eval_c  (i ( x \\<mapsto> s)) c1 s21 \\<and> eval_c  (i ( x \\<mapsto> s)) c2 s22 \\<and> (s2 = (s21 \\<and> s22))\" using\n      eval_c_elims(3) C_conj by metis\n  ultimately show ?case using C_conj  by (meson eval_c_elims)\nnext\n  case (C_disj c1 c2)\n  hence *:\"eval_c i (c1[x::=v]\\<^sub>c\\<^sub>v OR c2[x::=v]\\<^sub>c\\<^sub>v) s1\" using subst_cv.simps by auto\n  then obtain s11 and s12 where \"(s1 = (s11 \\<or> s12)) \\<and> eval_c i c1[x::=v]\\<^sub>c\\<^sub>v s11 \\<and> eval_c i c2[x::=v]\\<^sub>c\\<^sub>v s12\" using\n      eval_c_elims(4) by metis\n  moreover obtain   s21 and s22 where \"eval_c  (i ( x \\<mapsto> s)) c1 s21 \\<and> eval_c  (i ( x \\<mapsto> s)) c2 s22 \\<and> (s2 = (s21 \\<or> s22))\" using\n      eval_c_elims(4) C_disj by metis\n  ultimately show ?case using C_disj  by (meson eval_c_elims)\nnext\n  case (C_not c1)\n  then obtain s11 where \"(s1 = (\\<not> s11)) \\<and> eval_c i c1[x::=v]\\<^sub>c\\<^sub>v s11\" using\n      eval_c_elims(6)  by (metis subst_cv.simps(7))\n  moreover obtain   s21 where \"eval_c  (i ( x \\<mapsto> s)) c1 s21 \\<and> (s2 = (\\<not>s21))\" using\n      eval_c_elims(6) C_not by metis\n  ultimately show ?case using C_not  by (meson eval_c_elims)\nnext\n  case (C_imp c1 c2)\n  hence *:\"eval_c i (c1[x::=v]\\<^sub>c\\<^sub>v IMP c2[x::=v]\\<^sub>c\\<^sub>v) s1\" using subst_cv.simps by auto\n  then obtain s11 and s12 where \"(s1 = (s11 \\<longrightarrow> s12)) \\<and> eval_c i c1[x::=v]\\<^sub>c\\<^sub>v s11 \\<and> eval_c i c2[x::=v]\\<^sub>c\\<^sub>v s12\" using\n      eval_c_elims(5) by metis\n  moreover obtain   s21 and s22 where \"eval_c  (i ( x \\<mapsto> s)) c1 s21 \\<and> eval_c  (i ( x \\<mapsto> s)) c2 s22 \\<and> (s2 = (s21 \\<longrightarrow> s22))\" using\n      eval_c_elims(5) C_imp by metis\n  ultimately show ?case using C_imp  by (meson eval_c_elims)\nnext\n  case (C_eq e1 e2)\n  hence *:\"eval_c i (e1[x::=v]\\<^sub>c\\<^sub>e\\<^sub>v == e2[x::=v]\\<^sub>c\\<^sub>e\\<^sub>v) s1\" using subst_cv.simps by auto\n  then obtain s11 and s12 where \"(s1 = (s11 = s12)) \\<and> eval_e i (e1[x::=v]\\<^sub>c\\<^sub>e\\<^sub>v) s11 \\<and> eval_e i (e2[x::=v]\\<^sub>c\\<^sub>e\\<^sub>v) s12\" using\n      eval_c_elims(7) by metis\n  moreover obtain   s21 and s22 where \"eval_e  (i ( x \\<mapsto> s)) e1 s21 \\<and> eval_e  (i ( x \\<mapsto> s)) e2 s22 \\<and> (s2 = (s21 = s22))\" using\n      eval_c_elims(7) C_eq by metis\n  ultimately show ?case using C_eq subst_e_eval_v  by (metis eval_e_uniqueness)\nqed\n\nlemma wfI_upd:\n  assumes  \"wfI \\<Theta> \\<Gamma> i\" and \"wfRCV \\<Theta> s b\" and \"wfG \\<Theta> B ((x, b, c) #\\<^sub>\\<Gamma> \\<Gamma>)\"\n  shows \"wfI \\<Theta> ((x, b, c) #\\<^sub>\\<Gamma> \\<Gamma>) (i(x \\<mapsto> s))\"\nproof(subst wfI_def,rule)\n  fix xa\n  assume as:\"xa \\<in> toSet ((x, b, c) #\\<^sub>\\<Gamma> \\<Gamma>)\"\n\n  then obtain x1::x and b1::b and c1::c where xa: \"xa = (x1,b1,c1)\" using toSet.simps\n    using prod_cases3 by blast\n\n  have \"\\<exists>sa. Some sa = (i(x \\<mapsto> s)) x1 \\<and> wfRCV \\<Theta> sa b1\" proof(cases \"x=x1\")\n    case True\n    hence \"b=b1\" using as xa wfG_unique assms by metis\n    hence \"Some s = (i(x \\<mapsto> s)) x1 \\<and> wfRCV \\<Theta> s b1\" using assms True by simp\n    then show ?thesis by auto\n  next\n    case False\n    hence \"(x1,b1,c1) \\<in> toSet \\<Gamma>\" using xa as by auto\n    then obtain sa where \"Some sa = i x1 \\<and> wfRCV \\<Theta> sa b1\" using assms wfI_def as xa by auto\n    hence \"Some sa = (i(x \\<mapsto> s)) x1 \\<and> wfRCV \\<Theta> sa b1\" using False by auto\n    then show ?thesis by auto\n  qed\n\n  thus  \"case xa of (xa, ba, ca) \\<Rightarrow> \\<exists>sa. Some sa = (i(x \\<mapsto> s)) xa \\<and> wfRCV \\<Theta> sa ba\" using xa by auto\nqed\n\nlemma wfI_upd_full:\n  fixes v::v\n  assumes  \"wfI \\<Theta> G i\" and \"G =  ((\\<Gamma>'[x::=v]\\<^sub>\\<Gamma>\\<^sub>v)@\\<Gamma>)\" and \"wfRCV \\<Theta> s b\" and \"wfG \\<Theta> B  (\\<Gamma>'@((x,b,c)#\\<^sub>\\<Gamma>\\<Gamma>))\" and \"\\<Theta> ; B  ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f v : b\"\n  shows \"wfI \\<Theta>  (\\<Gamma>'@((x,b,c)#\\<^sub>\\<Gamma>\\<Gamma>)) (i(x \\<mapsto> s))\"\nproof(subst wfI_def,rule)\n  fix xa\n  assume as:\"xa \\<in> toSet (\\<Gamma>'@((x,b,c)#\\<^sub>\\<Gamma>\\<Gamma>))\"\n\n  then obtain x1::x and b1::b and c1::c where xa: \"xa = (x1,b1,c1)\" using toSet.simps\n    using prod_cases3 by blast\n\n  have \"\\<exists>sa. Some sa = (i(x \\<mapsto> s)) x1 \\<and> wfRCV \\<Theta> sa b1\"\n  proof(cases \"x=x1\")\n    case True\n    hence \"b=b1\" using as xa wfG_unique_full assms by metis\n    hence \"Some s = (i(x \\<mapsto> s)) x1 \\<and> wfRCV \\<Theta> s b1\" using assms True by simp\n    then show ?thesis by auto\n  next\n    case False\n    hence \"(x1,b1,c1) \\<in> toSet (\\<Gamma>'@\\<Gamma>)\" using as xa by auto\n    then obtain c1' where  \"(x1,b1,c1') \\<in> toSet (\\<Gamma>'[x::=v]\\<^sub>\\<Gamma>\\<^sub>v@\\<Gamma>)\" using xa as wfG_member_subst assms  False by metis\n    then obtain sa where \"Some sa = i x1 \\<and> wfRCV \\<Theta> sa b1\" using assms wfI_def as xa by blast\n    hence \"Some sa = (i(x \\<mapsto> s)) x1 \\<and> wfRCV \\<Theta> sa b1\" using False by auto\n    then show ?thesis by auto\n  qed\n\n  thus  \"case xa of (xa, ba, ca) \\<Rightarrow> \\<exists>sa. Some sa = (i(x \\<mapsto> s)) xa \\<and> wfRCV \\<Theta> sa ba\" using xa by auto\nqed\n\nlemma subst_c_satis[simp]:\n  fixes v::v\n  assumes \"i \\<lbrakk> v \\<rbrakk> ~  s\" and \"wfC \\<Theta> B ((x,b,c')#\\<^sub>\\<Gamma>\\<Gamma>) c\" and \"wfI \\<Theta> \\<Gamma> i\" and  \"\\<Theta> ; B  ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f v : b\"\n  shows \"i \\<Turnstile> (c[x::=v]\\<^sub>c\\<^sub>v) \\<longleftrightarrow> (i ( x \\<mapsto> s)) \\<Turnstile> c\"\nproof -\n  have \"wfI \\<Theta> ((x, b, c') #\\<^sub>\\<Gamma> \\<Gamma>) (i(x \\<mapsto> s))\" using wfI_upd assms wfC_wf eval_v_base by blast\n  then obtain s1 where s1:\"eval_c (i(x \\<mapsto> s)) c s1\"  using  eval_c_exist[of \\<Theta> \"((x,b,c')#\\<^sub>\\<Gamma>\\<Gamma>)\" \"(i ( x \\<mapsto> s))\" B c ] assms by auto\n\n  have \"\\<Theta> ; B  ; \\<Gamma>  \\<turnstile>\\<^sub>w\\<^sub>f c[x::=v]\\<^sub>c\\<^sub>v\" using wf_subst1(2)[OF assms(2) _ assms(4) , of GNil x   ] subst_gv.simps by simp\n  then obtain s2 where s2:\"eval_c i c[x::=v]\\<^sub>c\\<^sub>v s2\" using eval_c_exist[of \\<Theta> \"\\<Gamma>\" \"i\" B \"c[x::=v]\\<^sub>c\\<^sub>v\"  ] assms by auto\n\n  show ?thesis using s1 s2 subst_c_eval_v[OF assms(1) s2 s1] is_satis.cases\n    using eval_c_uniqueness is_satis.simps by auto\nqed\n\ntext \\<open> Key theorem telling us we can replace a substitution with an update to the valuation \\<close>\nlemma subst_c_satis_full:\n  fixes v::v and \\<Gamma>'::\\<Gamma>\n  assumes \"i \\<lbrakk> v \\<rbrakk> ~  s\" and \"wfC \\<Theta> B  (\\<Gamma>'@((x,b,c')#\\<^sub>\\<Gamma>\\<Gamma>)) c\" and \"wfI \\<Theta>  ((\\<Gamma>'[x::=v]\\<^sub>\\<Gamma>\\<^sub>v)@\\<Gamma>) i\" and  \"\\<Theta> ; B  ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f v : b\"\n  shows \"i \\<Turnstile> (c[x::=v]\\<^sub>c\\<^sub>v) \\<longleftrightarrow> (i ( x \\<mapsto> s)) \\<Turnstile> c\"\nproof -\n  have \"wfI \\<Theta> (\\<Gamma>'@((x, b, c')) #\\<^sub>\\<Gamma> \\<Gamma>) (i(x \\<mapsto> s))\" using wfI_upd_full assms wfC_wf eval_v_base wfI_suffix wfI_def wfV_wf by fast\n  then obtain s1 where s1:\"eval_c (i(x \\<mapsto> s)) c s1\" using  eval_c_exist[of \\<Theta> \"(\\<Gamma>'@(x,b,c')#\\<^sub>\\<Gamma>\\<Gamma>)\" \"(i ( x \\<mapsto> s))\" B c ] assms by auto\n\n  have \"\\<Theta> ; B ; ((\\<Gamma>'[x::=v]\\<^sub>\\<Gamma>\\<^sub>v)@\\<Gamma>) \\<turnstile>\\<^sub>w\\<^sub>f c[x::=v]\\<^sub>c\\<^sub>v\" using wbc_subst assms by auto\n\n  then obtain s2 where s2:\"eval_c i c[x::=v]\\<^sub>c\\<^sub>v s2\" using eval_c_exist[of \\<Theta> \"((\\<Gamma>'[x::=v]\\<^sub>\\<Gamma>\\<^sub>v)@\\<Gamma>)\" \"i\" B \"c[x::=v]\\<^sub>c\\<^sub>v\" ] assms by auto\n\n  show ?thesis using s1 s2 subst_c_eval_v[OF assms(1) s2 s1] is_satis.cases\n    using eval_c_uniqueness is_satis.simps by auto\nqed\n\nsection \\<open>Validity\\<close>\n\nlemma validI[intro]:\n  fixes c::c\n  assumes  \"wfC P B G c\" and \"\\<forall>i. P ; G \\<turnstile> i \\<and> i \\<Turnstile> G \\<longrightarrow> i \\<Turnstile> c\"\n  shows \"P ; B ; G \\<Turnstile> c\"\n  using assms valid.simps by presburger\n\nlemma valid_g_wf:\n  fixes c::c and G::\\<Gamma>\n  assumes \"P ; B ; G \\<Turnstile> c\"\n  shows \"P ; B \\<turnstile>\\<^sub>w\\<^sub>f G\"\n  using assms wfC_wf valid.simps by blast\n\nlemma valid_reflI [intro]:\n  fixes b::b\n  assumes  \"P ; B ; ((x,b,c1)#\\<^sub>\\<Gamma>G) \\<turnstile>\\<^sub>w\\<^sub>f c1\" and \"c1 = c2\"\n  shows \"P ; B ; ((x,b,c1)#\\<^sub>\\<Gamma>G) \\<Turnstile> c2\"\n  using satis_reflI assms by simp\n\nsubsection \\<open>Weakening and Strengthening\\<close>\n\ntext \\<open> Adding to the domain of a valuation doesn't change the result \\<close>\n\nlemma eval_v_weakening:\n  fixes c::v and B::\"bv fset\"\n  assumes \"i = i'|` d\" and \"supp c \\<subseteq> atom ` d \\<union> supp B \"  and \"i \\<lbrakk> c \\<rbrakk> ~ s\"\n  shows \"i' \\<lbrakk> c \\<rbrakk> ~ s\"\n  using assms proof(nominal_induct c arbitrary:s rule: v.strong_induct)\n  case (V_lit x)\n  then show ?case using eval_v_elims eval_v_litI by metis\nnext\n  case (V_var x)\n  have \"atom x \\<in> atom ` d\" using x_not_in_b_set[of x B] assms v.supp(2) supp_at_base \n  proof -\n    show ?thesis\n      by (metis UnE V_var.prems(2) \\<open>atom x \\<notin> supp B\\<close> singletonI subset_iff supp_at_base v.supp(2)) (* 46 ms *)\n  qed \n  moreover have \"Some s = i x\" using assms eval_v_elims(2) \n    using V_var.prems(3) by blast\n  hence \"Some s= i' x\" using assms insert_subset restrict_in  \n  proof -\n    show ?thesis\n      by (metis (no_types) \\<open>i = i' |` d\\<close> \\<open>Some s = i x\\<close> atom_eq_iff calculation imageE restrict_in) (* 31 ms *)\n  qed\n  thus ?case using eval_v.eval_v_varI by simp\n\nnext\n  case (V_pair v1 v2)\n  then show ?case using eval_v_elims(3) eval_v_pairI v.supp\n    by (metis assms le_sup_iff)\nnext\n  case (V_cons dc v1)\n  then show ?case using eval_v_elims(4) eval_v_consI v.supp\n    by (metis assms le_sup_iff)\nnext\n  case (V_consp tyid dc b1 v1)\n\n  then obtain sv1 where *:\"i \\<lbrakk> v1 \\<rbrakk> ~ sv1 \\<and> s = SConsp tyid dc b1 sv1\" using eval_v_elims by metis\n  hence \"i' \\<lbrakk> v1 \\<rbrakk> ~ sv1\" using V_consp by auto \n  then show ?case using * eval_v_conspI v.supp eval_v.simps  assms le_sup_iff by metis\nqed\n\nlemma eval_v_restrict:\n  fixes c::v and B::\"bv fset\"\n  assumes \"i = i' |` d\" and \"supp c \\<subseteq> atom ` d \\<union> supp B \"  and \"i' \\<lbrakk> c \\<rbrakk> ~ s\"\n  shows \"i \\<lbrakk> c \\<rbrakk> ~ s\"\n  using assms proof(nominal_induct c arbitrary:s rule: v.strong_induct)\n  case (V_lit x)\n  then show ?case using eval_v_elims eval_v_litI by metis\nnext\n  case (V_var x)\n  have \"atom x \\<in> atom ` d\" using x_not_in_b_set[of x B] assms v.supp(2) supp_at_base \n  proof -\n    show ?thesis\n      by (metis UnE V_var.prems(2) \\<open>atom x \\<notin> supp B\\<close> singletonI subset_iff supp_at_base v.supp(2)) (* 46 ms *)\n  qed \n  moreover have \"Some s = i' x\" using assms eval_v_elims(2) \n    using V_var.prems(3) by blast\n  hence \"Some s= i x\" using assms insert_subset restrict_in  \n  proof -\n    show ?thesis\n      by (metis (no_types) \\<open>i = i' |` d\\<close> \\<open>Some s = i' x\\<close> atom_eq_iff calculation imageE restrict_in) (* 31 ms *)\n  qed\n  thus ?case using eval_v.eval_v_varI by simp\nnext\n  case (V_pair v1 v2)\n  then show ?case using eval_v_elims(3) eval_v_pairI v.supp\n    by (metis assms le_sup_iff)\nnext\n  case (V_cons dc v1)\n  then show ?case using eval_v_elims(4) eval_v_consI v.supp\n    by (metis assms le_sup_iff)\nnext\n  case (V_consp tyid dc b1 v1)\n  then obtain sv1 where *:\"i' \\<lbrakk> v1 \\<rbrakk> ~ sv1 \\<and> s = SConsp tyid dc b1 sv1\" using eval_v_elims by metis\n  hence \"i \\<lbrakk> v1 \\<rbrakk> ~ sv1\" using V_consp by auto \n  then show ?case using * eval_v_conspI v.supp eval_v.simps  assms le_sup_iff by metis\nqed\n\nlemma eval_e_weakening:\n  fixes e::ce and B::\"bv fset\"\n  assumes  \"i \\<lbrakk> e \\<rbrakk> ~ s\" and \"i = i' |` d\" and \"supp e \\<subseteq> atom ` d \\<union> supp B \"\n  shows \"i' \\<lbrakk> e \\<rbrakk> ~ s\"\n  using assms proof(induct rule: eval_e.induct)\n  case (eval_e_valI i v sv)\n  then show ?case using ce.supp eval_e.intros\n    using eval_v_weakening by auto\nnext\n  case (eval_e_plusI i v1 n1 v2 n2)\n  then show ?case using ce.supp eval_e.intros\n    using eval_v_weakening by auto\nnext\n  case (eval_e_leqI i v1 n1 v2 n2)\n  then show ?case using ce.supp eval_e.intros\n    using eval_v_weakening by auto\nnext\n  case (eval_e_eqI i v1 n1 v2 n2)\n  then show ?case using ce.supp eval_e.intros\n    using eval_v_weakening by auto\nnext\n  case (eval_e_fstI i v v1 v2)\n  then show ?case using ce.supp eval_e.intros\n    using eval_v_weakening by metis\nnext\n  case (eval_e_sndI i v v1 v2)\n  then show ?case using ce.supp eval_e.intros\n    using eval_v_weakening by metis\nnext\n  case (eval_e_concatI i v1 bv2 v2 bv1)\n  then show ?case using ce.supp eval_e.intros\n    using eval_v_weakening by auto\nnext\n  case (eval_e_lenI i v bv)\n  then show ?case using ce.supp eval_e.intros\n    using eval_v_weakening by auto\nqed\n\nlemma eval_e_restrict :\n  fixes e::ce and B::\"bv fset\"\n  assumes  \"i' \\<lbrakk> e \\<rbrakk> ~ s\" and \"i = i' |` d\" and \"supp e \\<subseteq> atom ` d \\<union> supp B \"\n  shows \"i \\<lbrakk> e \\<rbrakk> ~ s\"\n  using assms proof(induct rule: eval_e.induct)\n  case (eval_e_valI i v sv)\n  then show ?case using ce.supp eval_e.intros\n    using eval_v_restrict by auto\nnext\n  case (eval_e_plusI i v1 n1 v2 n2)\n  then show ?case using ce.supp eval_e.intros\n    using eval_v_restrict by auto\nnext\n  case (eval_e_leqI i v1 n1 v2 n2)\n  then show ?case using ce.supp eval_e.intros\n    using eval_v_restrict by auto\nnext\n  case (eval_e_eqI i v1 n1 v2 n2)\n  then show ?case using ce.supp eval_e.intros\n    using eval_v_restrict by auto\nnext\n  case (eval_e_fstI i v v1 v2)\n  then show ?case using ce.supp eval_e.intros\n    using eval_v_restrict by metis\nnext\n  case (eval_e_sndI i v v1 v2)\n  then show ?case using ce.supp eval_e.intros\n    using eval_v_restrict by metis\nnext\n  case (eval_e_concatI i v1 bv2 v2 bv1)\n  then show ?case using ce.supp eval_e.intros\n    using eval_v_restrict by auto\nnext\n  case (eval_e_lenI i v bv)\n  then show ?case using ce.supp eval_e.intros\n    using eval_v_restrict by auto\nqed\n\nlemma eval_c_i_weakening:\n  fixes c::c and B::\"bv fset\"\n  assumes  \"i \\<lbrakk> c \\<rbrakk> ~ s\" and \"i = i' |` d\" and \"supp c \\<subseteq> atom ` d \\<union> supp B\"\n  shows \"i' \\<lbrakk> c \\<rbrakk> ~ s\"\n  using assms proof(induct rule:eval_c.induct)\n  case (eval_c_eqI i e1 sv1 e2 sv2)\n  then show ?case  using eval_c.intros eval_e_weakening by auto\nqed(auto simp add: eval_c.intros)+\n\nlemma eval_c_i_restrict:\n  fixes c::c and B::\"bv fset\"\n  assumes  \"i' \\<lbrakk> c \\<rbrakk> ~ s\" and \"i = i' |` d\" and \"supp c \\<subseteq> atom ` d \\<union> supp B\"\n  shows \"i \\<lbrakk> c \\<rbrakk> ~ s\"\n  using assms proof(induct rule:eval_c.induct)\n  case (eval_c_eqI i e1 sv1 e2 sv2)\n  then show ?case  using eval_c.intros eval_e_restrict by auto\nqed(auto simp add: eval_c.intros)+\n\nlemma is_satis_i_weakening:\n  fixes c::c and B::\"bv fset\"\n  assumes \"i = i' |` d\" and \"supp c \\<subseteq> atom ` d  \\<union> supp B \" and  \"i \\<Turnstile> c\"\n  shows \"i' \\<Turnstile> c\"\n  using is_satis.simps eval_c_i_weakening[OF _ assms(1) assms(2) ]\n  using assms(3) by auto\n\nlemma is_satis_i_restrict:\n  fixes c::c and B::\"bv fset\"\n  assumes \"i = i' |` d\" and \"supp c \\<subseteq> atom ` d  \\<union> supp B\" and  \"i' \\<Turnstile> c\"\n  shows \"i \\<Turnstile> c\"\n  using is_satis.simps eval_c_i_restrict[OF _ assms(1) assms(2) ]\n  using assms(3) by auto\n\nlemma is_satis_g_restrict1:\n  fixes \\<Gamma>'::\\<Gamma> and  \\<Gamma>::\\<Gamma>\n  assumes \"toSet \\<Gamma> \\<subseteq> toSet \\<Gamma>'\" and \"i \\<Turnstile> \\<Gamma>'\"\n  shows \"i \\<Turnstile> \\<Gamma>\"\n  using assms proof(induct \\<Gamma> rule: \\<Gamma>.induct)\n  case GNil\n  then show ?case by auto\nnext\n  case (GCons xbc G)\n  obtain x and b and c::c where xbc: \"xbc=(x,b,c)\"\n    using prod_cases3 by blast\n  hence \"i \\<Turnstile> G\" using GCons by auto\n  moreover have \"i \\<Turnstile> c\" using GCons\n      is_satis_iff toSet.simps  subset_iff\n    using xbc by blast\n  ultimately show ?case using is_satis_g.simps GCons\n    by (simp add: xbc)\nqed\n\nlemma is_satis_g_restrict2:\n  fixes \\<Gamma>'::\\<Gamma> and  \\<Gamma>::\\<Gamma>\n  assumes \"i \\<Turnstile> \\<Gamma>\" and  \"i' = i |` d\" and \"atom_dom \\<Gamma> \\<subseteq> atom ` d\" and \"\\<Theta> ; B \\<turnstile>\\<^sub>w\\<^sub>f \\<Gamma>\"\n  shows \"i' \\<Turnstile> \\<Gamma>\"\n  using assms proof(induct \\<Gamma> rule: \\<Gamma>_induct)\n  case GNil\n  then show ?case by auto\nnext\n  case (GCons x b c G)\n\n  hence \"i' \\<Turnstile> G\" proof -\n    have \"i \\<Turnstile> G\" using GCons  by simp\n    moreover have \"atom_dom G \\<subseteq> atom ` d\" using  GCons by simp\n    ultimately show ?thesis using GCons wfG_cons2 by blast\n  qed\n\n  moreover have \"i' \\<Turnstile> c\" proof -\n    have \"i \\<Turnstile> c\" using GCons  by auto\n    moreover have \"\\<Theta> ; B ; (x, b, TRUE) #\\<^sub>\\<Gamma> G   \\<turnstile>\\<^sub>w\\<^sub>f c\"  using wfG_wfC GCons by simp\n    moreover hence \"supp c \\<subseteq> atom ` d \\<union> supp B\" using wfC_supp GCons atom_dom_eq by blast\n    ultimately show ?thesis using is_satis_i_restrict[of i' i d c] GCons by simp\n  qed\n\n  ultimately show ?case by auto\nqed\n\nlemma is_satis_g_restrict:\n  fixes \\<Gamma>'::\\<Gamma> and \\<Gamma>::\\<Gamma>\n  assumes \"toSet \\<Gamma> \\<subseteq> toSet \\<Gamma>'\" and \"i' \\<Turnstile> \\<Gamma>'\" and  \"i =   i' |` (fst ` toSet \\<Gamma>)\"  and \"\\<Theta> ; B \\<turnstile>\\<^sub>w\\<^sub>f \\<Gamma>\"\n  shows \"i \\<Turnstile> \\<Gamma>\"\n  using assms is_satis_g_restrict1[OF assms(1) assms(2)] is_satis_g_restrict2[OF _ assms(3)] by simp\n\nsubsection \\<open>Updating valuation\\<close>\n\nlemma is_satis_c_i_upd:\n  fixes c::c\n  assumes \"atom x \\<sharp> c\" and \"i \\<Turnstile> c\"\n  shows \"((i ( x \\<mapsto>s))) \\<Turnstile> c\"\n  using assms eval_c_i_upd is_satis.simps by simp\n\nlemma is_satis_g_i_upd:\n  fixes G::\\<Gamma>\n  assumes \"atom x \\<sharp> G\"  and \"i \\<Turnstile> G\"\n  shows \"((i ( x \\<mapsto>s))) \\<Turnstile> G\"\n  using assms proof(induct G rule: \\<Gamma>_induct)\n  case GNil\n  then show ?case by auto\nnext\n  case (GCons x' b' c' G')\n\n  hence *:\"atom x \\<sharp> G' \\<and> atom x \\<sharp> c'\"\n    using fresh_def fresh_GCons GCons  by force\n  moreover hence \"is_satis ((i ( x \\<mapsto>s))) c'\"\n    using is_satis_c_i_upd GCons is_satis_g.simps by auto\n  moreover have \" is_satis_g (i(x \\<mapsto> s)) G'\" using GCons * by fastforce\n  ultimately show ?case\n    using GCons is_satis_g.simps(2) by metis\nqed\n\nlemma valid_weakening:\n  assumes \"\\<Theta> ; B ; \\<Gamma> \\<Turnstile> c\" and \"toSet \\<Gamma> \\<subseteq> toSet \\<Gamma>'\" and \"wfG \\<Theta> B  \\<Gamma>'\"\n  shows  \"\\<Theta> ; B ; \\<Gamma>' \\<Turnstile> c\"\nproof -\n  have \"wfC \\<Theta> B  \\<Gamma> c\" using assms valid.simps by auto\n  hence sp: \"supp c \\<subseteq> atom `(fst `toSet \\<Gamma>) \\<union> supp B\" using wfX_wfY wfG_elims\n    using atom_dom.simps dom.simps wf_supp(2) by metis\n  have wfg: \"wfG \\<Theta> B  \\<Gamma>\" using assms valid.simps wfC_wf by auto\n\n  moreover have a1: \"(\\<forall>i. wfI \\<Theta> \\<Gamma>' i \\<and> i \\<Turnstile> \\<Gamma>' \\<longrightarrow> i \\<Turnstile> c)\" proof(rule allI, rule impI)\n    fix i\n    assume as: \"wfI \\<Theta> \\<Gamma>' i \\<and> i \\<Turnstile> \\<Gamma>'\"\n    hence as1: \"fst ` toSet \\<Gamma> \\<subseteq> dom i\" using assms wfI_domi by blast\n    obtain i' where idash: \"i' =  restrict_map i (fst `toSet \\<Gamma>)\" by blast\n    hence as2: \"dom i' = (fst `toSet \\<Gamma>)\"  using dom_restrict as1 by auto\n\n    have id2: \"\\<Theta> ; \\<Gamma> \\<turnstile> i' \\<and> i' \\<Turnstile> \\<Gamma>\" proof -\n      have \"wfI \\<Theta>  \\<Gamma> i'\" using as2 wfI_restrict_weakening[of \\<Theta> \\<Gamma>' i i' \\<Gamma>] as  assms\n        using idash by blast\n      moreover have \"i' \\<Turnstile> \\<Gamma>\" using is_satis_g_restrict[OF assms(2)] wfg as idash by auto\n      ultimately show ?thesis using idash by auto\n    qed\n    hence \"i' \\<Turnstile> c\" using assms valid.simps by auto\n    thus  \"i \\<Turnstile> c\" using assms valid.simps is_satis_i_weakening  idash sp by blast\n  qed\n  moreover have \"wfC \\<Theta> B \\<Gamma>' c\" using wf_weakening assms valid.simps\n    by (meson  wfg)\n  ultimately show  ?thesis using assms valid.simps by auto\nqed\n\nlemma is_satis_g_suffix:\n  fixes G::\\<Gamma>\n  assumes \"i \\<Turnstile> (G'@G)\"\n  shows \"i \\<Turnstile> G\"\n  using assms proof(induct G' rule:\\<Gamma>.induct)\n  case GNil\n  then show ?case by auto\nnext\n  case (GCons xbc x2)\n  obtain x and b and c::c where xbc: \"xbc=(x,b,c)\"\n    using prod_cases3 by blast\n  hence \" i \\<Turnstile> (xbc #\\<^sub>\\<Gamma> (x2 @ G))\" using append_g.simps GCons by fastforce\n  then show ?case using is_satis_g.simps GCons xbc by blast\nqed\n\nlemma wfG_inside_valid2:\n  fixes x::x and \\<Gamma>::\\<Gamma> and c0::c and c0'::c\n  assumes \"wfG \\<Theta> B  (\\<Gamma>'@((x,b0,c0')#\\<^sub>\\<Gamma>\\<Gamma>))\" and\n    \"\\<Theta> ; B ; \\<Gamma>'@(x,b0,c0)#\\<^sub>\\<Gamma>\\<Gamma> \\<Turnstile> c0'\"\n  shows \"wfG \\<Theta> B  (\\<Gamma>'@((x,b0,c0)#\\<^sub>\\<Gamma>\\<Gamma>))\"\nproof -\n  have \"wfG \\<Theta>  B  (\\<Gamma>'@(x,b0,c0)#\\<^sub>\\<Gamma>\\<Gamma>)\" using valid.simps wfC_wf assms by auto\n  thus ?thesis using wfG_replace_inside_full assms by auto\nqed\n\nlemma valid_trans:\n  assumes   \" \\<Theta> ; \\<B> ; \\<Gamma> \\<Turnstile> c0[z::=v]\\<^sub>v\"  and \" \\<Theta> ; \\<B> ; (z,b,c0)#\\<^sub>\\<Gamma>\\<Gamma> \\<Turnstile> c1\" and \"atom z \\<sharp> \\<Gamma>\" and \"wfV \\<Theta> \\<B> \\<Gamma> v b\" \n  shows \" \\<Theta> ; \\<B> ; \\<Gamma> \\<Turnstile> c1[z::=v]\\<^sub>v\"\nproof - \n  have *:\"wfC \\<Theta> \\<B> ((z,b,c0)#\\<^sub>\\<Gamma>\\<Gamma>) c1\" using valid.simps assms by auto\n  hence \"wfC \\<Theta> \\<B> \\<Gamma> (c1[z::=v]\\<^sub>v)\" using wf_subst1(2)[OF * , of GNil ]  assms subst_gv.simps subst_v_c_def by force\n\n  moreover have \"\\<forall>i. wfI  \\<Theta> \\<Gamma>   i \\<and> is_satis_g i \\<Gamma> \\<longrightarrow> is_satis i (c1[z::=v]\\<^sub>v)\" \n  proof(rule,rule)\n    fix i\n    assume  as: \"wfI  \\<Theta> \\<Gamma>   i \\<and> is_satis_g i \\<Gamma>\"\n    then obtain sv where sv: \"eval_v i v sv \\<and> wfRCV \\<Theta> sv b\" using eval_v_exist assms by metis\n    hence \"is_satis i (c0[z::=v]\\<^sub>v)\" using assms valid.simps as by metis\n    hence \"is_satis (i(z \\<mapsto> sv))  c0\" using subst_c_satis sv as assms valid.simps wfC_wf wfG_elim2 subst_v_c_def by metis\n    moreover have \"is_satis_g  (i(z \\<mapsto> sv)) \\<Gamma>\" \n      using is_satis_g_i_upd  assms  by (simp add: as)\n    ultimately have \"is_satis_g  (i(z \\<mapsto> sv)) ((z,b,c0)#\\<^sub>\\<Gamma>\\<Gamma>)\" \n      using is_satis_g.simps by simp\n    moreover have \"wfI \\<Theta> ((z,b,c0)#\\<^sub>\\<Gamma>\\<Gamma>) (i(z \\<mapsto> sv))\" using as wfI_upd sv assms valid.simps wfC_wf by metis\n    ultimately have \"is_satis (i(z \\<mapsto> sv)) c1\" using assms valid.simps by auto\n    thus \"is_satis i (c1[z::=v]\\<^sub>v)\" using subst_c_satis sv as assms valid.simps wfC_wf wfG_elim2 subst_v_c_def by metis\n  qed\n\n  ultimately show ?thesis using valid.simps by auto\nqed\n\nlemma valid_trans_full:\n  assumes  \"\\<Theta> ; \\<B> ; ((x, b, c1[z1::=V_var x]\\<^sub>v) #\\<^sub>\\<Gamma> \\<Gamma>) \\<Turnstile> c2[z2::=V_var x]\\<^sub>v\" and\n    \"\\<Theta> ; \\<B> ; ((x, b, c2[z2::=V_var x]\\<^sub>v) #\\<^sub>\\<Gamma> \\<Gamma>) \\<Turnstile> c3[z3::=V_var x]\\<^sub>v\" \n  shows  \"\\<Theta> ; \\<B> ; ((x, b, c1[z1::=V_var x]\\<^sub>v) #\\<^sub>\\<Gamma> \\<Gamma>) \\<Turnstile> c3[z3::=V_var x]\\<^sub>v\"\n  unfolding valid.simps proof\n  show \"\\<Theta> ; \\<B> ; (x, b, c1[z1::=V_var x]\\<^sub>v) #\\<^sub>\\<Gamma> \\<Gamma>   \\<turnstile>\\<^sub>w\\<^sub>f c3[z3::=V_var x]\\<^sub>v\" using wf_trans valid.simps assms by metis\n\n  show \"\\<forall>i.  ( wfI  \\<Theta> ((x, b, c1[z1::=V_var x]\\<^sub>v) #\\<^sub>\\<Gamma> \\<Gamma>) i \\<and>  (is_satis_g i ((x, b, c1[z1::=V_var x]\\<^sub>v) #\\<^sub>\\<Gamma> \\<Gamma>))  \\<longrightarrow>  (is_satis i (c3[z3::=V_var x]\\<^sub>v)) ) \"\n  proof(rule,rule)\n    fix i\n    assume as: \"\\<Theta> ; (x, b, c1[z1::=V_var x]\\<^sub>v) #\\<^sub>\\<Gamma> \\<Gamma> \\<turnstile> i \\<and>  i \\<Turnstile> (x, b, c1[z1::=V_var x]\\<^sub>v) #\\<^sub>\\<Gamma> \\<Gamma>\" \n    have \"i \\<Turnstile> c2[z2::=V_var x]\\<^sub>v\" using is_satis_g.simps as assms by simp\n    moreover have  \"i \\<Turnstile> \\<Gamma>\"  using is_satis_g.simps as by simp\n    ultimately show \"i \\<Turnstile> c3[z3::=V_var x]\\<^sub>v \" using assms is_satis_g.simps valid.simps \n      by (metis append_g.simps(1) as wfI_replace_inside)\n  qed\nqed\n\nlemma eval_v_weakening_x:\n  fixes c::v\n  assumes  \"i' \\<lbrakk> c \\<rbrakk> ~ s\" and \"atom x \\<sharp> c\" and \"i = i' (x \\<mapsto> s')\"\n  shows \"i \\<lbrakk> c \\<rbrakk> ~ s\"\n  using assms proof(induct rule: eval_v.induct)\n  case (eval_v_litI i l)\n  then show ?case using eval_v.intros by auto\nnext\n  case (eval_v_varI sv i1 x1)\n  hence \"x \\<noteq> x1\" using v.fresh fresh_at_base by auto\n  hence \"i x1 = Some sv\" using eval_v_varI by simp\n  then show ?case  using eval_v.intros by auto\nnext\n  case (eval_v_pairI i v1 s1 v2 s2)\n  then show ?case  using eval_v.intros by auto\nnext\n  case (eval_v_consI i v s tyid dc)\n  then show ?case  using eval_v.intros by auto\nnext\n  case (eval_v_conspI i v s tyid dc b)\n  then show ?case  using eval_v.intros by auto\nqed\n\nlemma eval_e_weakening_x:\n  fixes c::ce\n  assumes  \"i' \\<lbrakk> c \\<rbrakk> ~ s\" and \"atom x \\<sharp> c\" and \"i = i' (x \\<mapsto> s')\"\n  shows \"i \\<lbrakk> c \\<rbrakk> ~ s\"\n  using assms proof(induct rule: eval_e.induct)\n  case (eval_e_valI i v sv)\n  then show ?case using  eval_v_weakening_x eval_e.intros  ce.fresh by metis\nnext\n  case (eval_e_plusI i v1 n1 v2 n2)\n  then show ?case using  eval_v_weakening_x eval_e.intros  ce.fresh by metis\nnext\n  case (eval_e_leqI i v1 n1 v2 n2)\n  then show ?case using  eval_v_weakening_x eval_e.intros  ce.fresh by metis\nnext\n  case (eval_e_eqI i v1 n1 v2 n2)\n  then show ?case using  eval_v_weakening_x eval_e.intros  ce.fresh by metis\nnext\n  case (eval_e_fstI i v v1 v2)\n  then show ?case using  eval_v_weakening_x eval_e.intros  ce.fresh by metis\nnext\n  case (eval_e_sndI i v v1 v2)\n  then show ?case using  eval_v_weakening_x eval_e.intros  ce.fresh by metis\nnext\n  case (eval_e_concatI i v1 bv1 v2 bv2)\n  then show ?case using  eval_v_weakening_x eval_e.intros  ce.fresh by metis\nnext\n  case (eval_e_lenI i v bv)\n  then show ?case using  eval_v_weakening_x eval_e.intros  ce.fresh by metis\nqed\n\nlemma eval_c_weakening_x:\n  fixes c::c\n  assumes  \"i' \\<lbrakk> c \\<rbrakk> ~ s\" and \"atom x \\<sharp> c\" and \"i = i' (x \\<mapsto> s')\"\n  shows \"i \\<lbrakk> c \\<rbrakk> ~ s\"\n  using assms proof(induct rule: eval_c.induct)\n  case (eval_c_trueI i)\n  then show ?case using eval_c.intros by auto\nnext\n  case (eval_c_falseI i)\n  then show ?case using eval_c.intros by auto\nnext\n  case (eval_c_conjI i c1 b1 c2 b2)\n  then show ?case using eval_c.intros by auto\nnext\n  case (eval_c_disjI i c1 b1 c2 b2)\n  then show ?case using eval_c.intros by auto\nnext\n  case (eval_c_impI i c1 b1 c2 b2)\n  then show ?case using eval_c.intros by auto\nnext\n  case (eval_c_notI i c b)\n  then show ?case using eval_c.intros by auto\nnext\n  case (eval_c_eqI i e1 sv1 e2 sv2)\n  then show ?case using eval_e_weakening_x c.fresh eval_c.intros by metis\nqed\n\nlemma is_satis_weakening_x:\n  fixes c::c\n  assumes \"i' \\<Turnstile> c\" and \"atom x \\<sharp> c\" and \"i = i' (x \\<mapsto> s)\"\n  shows \"i \\<Turnstile> c\"\n  using eval_c_weakening_x assms is_satis.simps by simp\n\nlemma is_satis_g_weakening_x:\n  fixes G::\\<Gamma>\n  assumes \"i' \\<Turnstile> G\" and \"atom x \\<sharp> G\" and \"i = i' (x \\<mapsto> s)\"\n  shows \"i \\<Turnstile> G\"\n  using assms proof(induct G rule: \\<Gamma>_induct)\n  case GNil\n  then show ?case by auto\nnext\n  case (GCons x' b' c' \\<Gamma>')\n  hence \"atom x \\<sharp> c'\" using fresh_GCons fresh_prodN by simp\n  moreover hence \"i \\<Turnstile> c'\"  using is_satis_weakening_x  is_satis_g.simps(2) GCons by metis\n  then show ?case using   is_satis_g.simps(2)[of i x' b' c' \\<Gamma>'] GCons fresh_GCons by simp\nqed\n\nsection \\<open>Base Type Substitution\\<close>\n\ntext \\<open>The idea of boxing is to take an smt val and its base type and at nodes in the smt val that correspond to type variables we\nwrap them in an SUt smt val node. Another way of looking at it is that s' where the node for the base type variable is an 'any node'.\nIt is needed to prove subst\\_b\\_valid - the base-type variable substitution lemma for validity.\n\nThe first @{text \"rcl_val\"} is the expanded form (has type with base-variables replaced with base-type terms)\n ; the second is its corresponding form\n\nWe only have one variable so we need to ensure that in all of the  @{text \"bs_boxed_BVarI\"} cases, the s has the same\n  base type.\n\nFor example is an SMT value is (SPair (SInt 1) (SBool true)) and it has sort (BPair (BVar x) BBool)[x::=BInt] then \nthe boxed version is SPair (SUt (SInt 1)) (SBool true) and is has sort (BPair (BVar x) BBool). We need to do this \nso that we can obtain from a valuation i, that gives values like the first smt value, to a valuation i' that gives values like\nthe second.\n\\<close>\n\ninductive  boxed_b :: \"\\<Theta> \\<Rightarrow> rcl_val \\<Rightarrow> b \\<Rightarrow> bv \\<Rightarrow> b \\<Rightarrow> rcl_val \\<Rightarrow> bool\"   ( \" _  \\<turnstile> _ ~ _ [ _ ::= _ ] \\<setminus> _ \" [50,50] 50) where    \n  boxed_b_BVar1I:  \"\\<lbrakk> bv = bv' ;  wfRCV P s b \\<rbrakk> \\<Longrightarrow> boxed_b P s (B_var bv') bv b (SUt s)\"\n| boxed_b_BVar2I:  \"\\<lbrakk> bv \\<noteq> bv'; wfRCV P s  (B_var bv')  \\<rbrakk> \\<Longrightarrow> boxed_b P s (B_var bv') bv b s\"\n| boxed_b_BIntI:\"wfRCV P s B_int \\<Longrightarrow> boxed_b P s B_int _ _ s\"\n| boxed_b_BBoolI:\"wfRCV P s B_bool \\<Longrightarrow> boxed_b P s B_bool _ _ s \"\n| boxed_b_BUnitI:\"wfRCV P s B_unit \\<Longrightarrow> boxed_b P s B_unit _ _ s\"\n| boxed_b_BPairI:\"\\<lbrakk> boxed_b P s1 b1 bv b s1' ; boxed_b P s2 b2 bv b s2' \\<rbrakk> \\<Longrightarrow> boxed_b P (SPair s1 s2) (B_pair b1 b2) bv b (SPair s1' s2')\"\n\n| boxed_b_BConsI:\"\\<lbrakk>  \n      AF_typedef tyid dclist \\<in> set P;\n      (dc, \\<lbrace> x : b  | c \\<rbrace>) \\<in> set dclist ;\n      boxed_b P s1 b bv b' s1'\n      \\<rbrakk> \\<Longrightarrow>  \n     boxed_b P (SCons tyid dc s1) (B_id tyid) bv b' (SCons tyid dc s1')\"\n\n| boxed_b_BConspI:\"\\<lbrakk>  AF_typedef_poly tyid bva dclist \\<in> set P;\n      atom bva \\<sharp> (b1,bv,b',s1,s1');\n      (dc, \\<lbrace> x : b  | c \\<rbrace>) \\<in> set dclist ;\n      boxed_b P s1 (b[bva::=b1]\\<^sub>b\\<^sub>b) bv b' s1' \n      \\<rbrakk> \\<Longrightarrow>  \n      boxed_b P (SConsp tyid dc b1[bv::=b']\\<^sub>b\\<^sub>b s1) (B_app tyid b1) bv b' (SConsp tyid dc b1 s1')\"\n\n| boxed_b_Bbitvec: \"wfRCV P s B_bitvec \\<Longrightarrow> boxed_b P s B_bitvec bv b s\"\n\nequivariance boxed_b \nnominal_inductive boxed_b .\n\ninductive_cases boxed_b_elims:\n  \"boxed_b P s (B_var bv) bv' b s'\"\n  \"boxed_b P s B_int bv b s'\"\n  \"boxed_b P s B_bool bv b s'\"\n  \"boxed_b P s B_unit bv b s'\"\n  \"boxed_b P s (B_pair b1 b2) bv b s'\"\n  \"boxed_b P s (B_id dc) bv b s'\"\n  \"boxed_b P s B_bitvec bv b s'\"\n  \"boxed_b P s (B_app dc b') bv b s'\"\n\nlemma boxed_b_wfRCV:\n  assumes  \"boxed_b P s b bv b' s'\" (*and \"supp s = {}\"*) and \"\\<turnstile>\\<^sub>w\\<^sub>f P\"\n  shows \"wfRCV P s b[bv::=b']\\<^sub>b\\<^sub>b \\<and> wfRCV P s' b\"\n  using assms proof(induct rule: boxed_b.inducts)\n  case (boxed_b_BVar1I bv bv' P s b )\n  then show ?case using wfRCV.intros by auto\nnext\n  case (boxed_b_BVar2I bv bv' P s )\n  then show ?case using wfRCV.intros   by auto\nnext\n  case (boxed_b_BPairI P s1 b1 bv b s1' s2 b2 s2')\n  then show ?case using wfRCV.intros rcl_val.supp by simp\nnext\n  case (boxed_b_BConsI tyid dclist P dc x b c s1 bv b' s1')\n  hence \"supp b = {}\" using wfTh_supp_b by metis\n  hence \"b [ bv ::= b' ]\\<^sub>b\\<^sub>b = b\" using fresh_def subst_b_b_def forget_subst[of \"bv\" b b'] by auto\n  hence \" P  \\<turnstile> SCons tyid dc s1 : (B_id tyid)\" using  wfRCV.intros rcl_val.supp subst_bb.simps boxed_b_BConsI by metis\n  moreover have \"P  \\<turnstile> SCons tyid dc s1' : B_id tyid\" using boxed_b_BConsI  \n    using  wfRCV.intros rcl_val.supp subst_bb.simps boxed_b_BConsI by metis\n  ultimately show ?case using subst_bb.simps by metis\nnext\n  case (boxed_b_BConspI tyid bva dclist P b1 bv b' s1 s1' dc x b c)\n\n  obtain bva2 and dclist2 where *:\"AF_typedef_poly tyid bva dclist = AF_typedef_poly tyid bva2 dclist2 \\<and> \n             atom bva2 \\<sharp> (bv,(P, SConsp tyid dc b1[bv::=b']\\<^sub>b\\<^sub>b s1, B_app tyid b1[bv::=b']\\<^sub>b\\<^sub>b))\" \n    using  obtain_fresh_bv by metis\n\n  then obtain x2 and b2 and c2 where **:\\<open>(dc, \\<lbrace> x2 : b2  | c2 \\<rbrace>) \\<in> set dclist2\\<close>  \n    using boxed_b_BConspI td_lookup_eq_iff type_def.eq_iff by metis\n\n  have  \"P  \\<turnstile> SConsp tyid dc b1[bv::=b']\\<^sub>b\\<^sub>b s1 : (B_app tyid b1[bv::=b']\\<^sub>b\\<^sub>b)\" proof\n    show 1: \\<open>AF_typedef_poly tyid bva2 dclist2 \\<in> set P\\<close> using boxed_b_BConspI * by auto\n    show 2: \\<open>(dc, \\<lbrace> x2 : b2  | c2 \\<rbrace>) \\<in> set dclist2\\<close> using boxed_b_BConspI using ** by simp\n\n    hence \"atom bv \\<sharp> b2\" proof -\n      have \"supp b2 \\<subseteq> { atom bva2 }\" using wfTh_poly_supp_b 1 2 boxed_b_BConspI by auto\n      moreover have \"bv \\<noteq> bva2\" using  * fresh_Pair fresh_at_base by metis\n      ultimately show  ?thesis  using fresh_def by force\n    qed\n    moreover have \"b[bva::=b1]\\<^sub>b\\<^sub>b = b2[bva2::=b1]\\<^sub>b\\<^sub>b\"  using wfTh_typedef_poly_b_eq_iff * 2 boxed_b_BConspI by metis\n    ultimately show \\<open> P  \\<turnstile> s1 : b2[bva2::=b1[bv::=b']\\<^sub>b\\<^sub>b]\\<^sub>b\\<^sub>b\\<close> using boxed_b_BConspI subst_b_b_def subst_bb_commute by auto\n    show \"atom bva2 \\<sharp> (P, SConsp tyid dc b1[bv::=b']\\<^sub>b\\<^sub>b s1, B_app tyid b1[bv::=b']\\<^sub>b\\<^sub>b)\" using * fresh_Pair by metis\n  qed\n\n  moreover have \"P  \\<turnstile> SConsp tyid dc b1 s1' : B_app tyid b1\" proof\n    show \\<open>AF_typedef_poly tyid bva dclist \\<in> set P\\<close> using boxed_b_BConspI by auto\n    show \\<open>(dc, \\<lbrace> x : b  | c \\<rbrace>) \\<in> set dclist\\<close> using boxed_b_BConspI by auto\n    show \\<open> P  \\<turnstile> s1' : b[bva::=b1]\\<^sub>b\\<^sub>b\\<close> using boxed_b_BConspI by auto\n    have \"atom bva \\<sharp> P\" using boxed_b_BConspI wfTh_fresh by metis\n    thus  \"atom bva \\<sharp> (P, SConsp tyid dc b1 s1', B_app tyid b1)\" using boxed_b_BConspI rcl_val.fresh b.fresh pure_fresh fresh_prodN by metis\n  qed\n\n  ultimately show ?case using subst_bb.simps  by simp\nqed(auto)+\n\nlemma subst_b_var:\n  assumes  \"B_var bv2 = b[bv::=b']\\<^sub>b\\<^sub>b\"\n  shows  \"(b = B_var bv \\<and> b' = B_var bv2) \\<or> (b=B_var bv2 \\<and> bv \\<noteq> bv2)\"\n  using assms by(nominal_induct b rule: b.strong_induct,auto+)\n\ntext \\<open>Here the valuation i' is the conv wrap version of i. For every x in G, i' x is the conv wrap version of i x.\nThe next lemma for a clearer explanation of what this is. i produces values of sort b[bv::=b'] and i' produces values of sort b\\<close>\n\ninductive boxed_i :: \"\\<Theta> \\<Rightarrow> \\<Gamma> \\<Rightarrow> b \\<Rightarrow> bv \\<Rightarrow> valuation \\<Rightarrow> valuation \\<Rightarrow> bool\"  ( \" _  ; _ ; _ , _ \\<turnstile> _ \\<approx> _\" [50,50] 50) where\n  boxed_i_GNilI:  \"\\<Theta> ; GNil ; b , bv  \\<turnstile> i \\<approx> i\"\n| boxed_i_GConsI: \"\\<lbrakk> Some s = i x;  boxed_b \\<Theta> s b bv b' s' ;  \\<Theta> ; \\<Gamma> ; b' , bv \\<turnstile> i \\<approx> i' \\<rbrakk> \\<Longrightarrow> \\<Theta> ; ((x,b,c)#\\<^sub>\\<Gamma>\\<Gamma>) ; b' , bv \\<turnstile> i \\<approx> (i'(x \\<mapsto> s'))\"\nequivariance boxed_i\nnominal_inductive boxed_i .\n\ninductive_cases boxed_i_elims:\n  \"\\<Theta> ;GNil ; b , bv \\<turnstile> i \\<approx> i'\"\n  \"\\<Theta> ; ((x,b,c)#\\<^sub>\\<Gamma>\\<Gamma>) ; b' , bv \\<turnstile> i \\<approx> i'\"\n\nlemma wfRCV_poly_elims:\n  fixes tm::\"'a::fs\" and b::b\n  assumes \"T  \\<turnstile> SConsp typid dc bdc s : b\" \n  obtains bva dclist x1 b1 c1 where \"b = B_app typid bdc \\<and>\n    AF_typedef_poly typid bva dclist \\<in> set T \\<and> (dc, \\<lbrace> x1 : b1  | c1 \\<rbrace>) \\<in> set dclist \\<and>  T  \\<turnstile> s : b1[bva::=bdc]\\<^sub>b\\<^sub>b \\<and> atom bva \\<sharp> tm\" \n  using assms proof(nominal_induct \"SConsp typid dc bdc s\" b avoiding: tm rule:wfRCV.strong_induct)\n  case (wfRCV_BConsPI bv dclist \\<Theta> x b c)\n  then show ?case by simp\nqed\n\nlemma boxed_b_ex:\n  assumes \"wfRCV T s b[bv::=b']\\<^sub>b\\<^sub>b\" and \"wfTh T\"\n  shows \"\\<exists>s'. boxed_b T s b bv b' s'\"\n  using assms proof(nominal_induct s arbitrary: b rule: rcl_val.strong_induct)\n  case (SBitvec x)\n  have *:\"b[bv::=b']\\<^sub>b\\<^sub>b = B_bitvec\" using wfRCV_elims(9)[OF SBitvec(1)] by metis\n  show ?case proof (cases \"b = B_var bv\")\n    case True\n    moreover have \"T  \\<turnstile> SBitvec x : B_bitvec\" using wfRCV.intros by simp\n    moreover hence \"b' = B_bitvec\" using True SBitvec subst_bb.simps * by simp\n    ultimately show ?thesis using boxed_b.intros  wfRCV.intros by metis\n  next\n    case False\n    hence \"b = B_bitvec\" using subst_bb_inject *  by metis  \n    then show ?thesis using * SBitvec boxed_b.intros by metis\n  qed\nnext\n  case (SNum x)\n  have *:\"b[bv::=b']\\<^sub>b\\<^sub>b = B_int\" using wfRCV_elims(10)[OF SNum(1)] by metis\n  show ?case proof (cases \"b = B_var bv\")\n    case True\n    moreover have \"T  \\<turnstile> SNum x : B_int\" using wfRCV.intros by simp\n    moreover hence \"b' = B_int\" using True SNum subst_bb.simps(1) * by simp\n    ultimately show ?thesis using boxed_b_BVar1I  wfRCV.intros by metis\n  next\n    case False\n    hence \"b = B_int\" using subst_bb_inject(1) *  by metis  \n    then show ?thesis using * SNum boxed_b_BIntI by metis\n  qed\nnext\n  case (SBool x)\n  have *:\"b[bv::=b']\\<^sub>b\\<^sub>b = B_bool\" using wfRCV_elims(11)[OF SBool(1)] by metis\n  show ?case proof (cases \"b = B_var bv\")\n    case True\n    moreover have \"T  \\<turnstile> SBool x : B_bool\" using wfRCV.intros by simp\n    moreover hence \"b' = B_bool\" using True SBool subst_bb.simps * by simp\n    ultimately show ?thesis using boxed_b.intros  wfRCV.intros by metis\n  next\n    case False\n    hence \"b = B_bool\" using subst_bb_inject *  by metis  \n    then show ?thesis using * SBool boxed_b.intros by metis\n  qed\nnext\n  case (SPair s1 s2)\n  then obtain b1 and b2 where *:\"b[bv::=b']\\<^sub>b\\<^sub>b = B_pair b1 b2 \\<and> wfRCV T s1 b1 \\<and> wfRCV T s2 b2\" using wfRCV_elims(12)  by metis\n  show ?case proof (cases \"b = B_var bv\")\n    case True\n    moreover have \"T  \\<turnstile> SPair s1 s2 : B_pair b1 b2\" using wfRCV.intros * by simp\n    moreover hence \"b' = B_pair b1 b2\" using True SPair subst_bb.simps(1) * by simp\n    ultimately show ?thesis using boxed_b_BVar1I by metis\n  next\n    case False\n    then obtain b1' and b2' where \"b = B_pair b1' b2' \\<and> b1=b1'[bv::=b']\\<^sub>b\\<^sub>b \\<and> b2=b2'[bv::=b']\\<^sub>b\\<^sub>b\" using subst_bb_inject(5)[OF _ False ] * by metis\n    then show ?thesis using *  SPair boxed_b_BPairI by blast\n  qed\nnext\n  case (SCons tyid dc s1)\n  have *:\"b[bv::=b']\\<^sub>b\\<^sub>b = B_id tyid\" using wfRCV_elims(13)[OF SCons(2)] by metis\n  show ?case proof (cases \"b = B_var bv\")\n    case True\n    moreover have \"T  \\<turnstile> SCons tyid dc s1 : B_id tyid\" using wfRCV.intros \n      using \"local.*\" SCons.prems by auto\n    moreover hence \"b' =  B_id tyid\" using True SCons subst_bb.simps(1) * by simp\n    ultimately show ?thesis using boxed_b_BVar1I  wfRCV.intros by metis\n  next\n    case False\n    then obtain b1' where beq: \"b = B_id tyid\" using subst_bb_inject *  by metis  \n    then obtain b2 dclist x c where **:\"AF_typedef tyid dclist \\<in> set T \\<and> (dc, \\<lbrace> x : b2  | c \\<rbrace>) \\<in> set dclist \\<and> wfRCV T s1 b2\" using wfRCV_elims(13)  * SCons by metis\n    then have \"atom bv \\<sharp> b2\" using \\<open>wfTh T\\<close> wfTh_lookup_supp_empty[of tyid dclist T dc \"\\<lbrace> x : b2  | c \\<rbrace>\"] \\<tau>.fresh fresh_def by auto\n    then have \"b2 = b2[ bv ::= b']\\<^sub>b\\<^sub>b\" using forget_subst subst_b_b_def by metis\n    then obtain s1' where s1:\"T  \\<turnstile> s1 ~ b2 [ bv ::= b' ] \\<setminus> s1'\" using SCons ** by metis\n\n    have \"T  \\<turnstile> SCons tyid dc s1 ~ (B_id tyid) [ bv ::= b' ] \\<setminus> SCons tyid dc s1'\" proof(rule boxed_b_BConsI)\n      show \"AF_typedef tyid dclist \\<in> set T\" using ** by auto\n      show \"(dc, \\<lbrace> x : b2  | c \\<rbrace>) \\<in> set dclist\" using ** by auto\n      show \"T  \\<turnstile> s1 ~ b2 [ bv ::= b' ] \\<setminus> s1' \" using s1 ** by auto\n\n    qed\n    thus ?thesis using beq by metis\n  qed\nnext\n  case (SConsp typid dc bdc s)\n\n  obtain bva dclist x1 b1 c1 where **:\"b[bv::=b']\\<^sub>b\\<^sub>b = B_app typid bdc \\<and>\n    AF_typedef_poly typid bva dclist \\<in> set T \\<and> (dc, \\<lbrace> x1 : b1  | c1 \\<rbrace>) \\<in> set dclist \\<and>  T  \\<turnstile> s : b1[bva::=bdc]\\<^sub>b\\<^sub>b \\<and> atom bva \\<sharp> bv\"\n    using wfRCV_poly_elims[OF SConsp(2)]  by metis\n\n  then have *:\"B_app typid bdc = b[bv::=b']\\<^sub>b\\<^sub>b\" using wfRCV_elims(14)[OF SConsp(2)] by metis\n  show ?case proof (cases \"b = B_var bv\")\n    case True\n    moreover have \"T  \\<turnstile> SConsp typid dc bdc s  : B_app typid bdc\" using wfRCV.intros \n      using \"local.*\" SConsp.prems(1) by auto\n    moreover hence \"b' = B_app typid bdc\" using True SConsp subst_bb.simps * by simp\n    ultimately show ?thesis using boxed_b.intros  wfRCV.intros by metis\n  next\n    case False\n    then obtain bdc' where bdc: \"b = B_app typid bdc' \\<and> bdc = bdc'[bv::=b']\\<^sub>b\\<^sub>b\" using * subst_bb_inject(8)[OF *] by metis\n        (*hence beq:\"b = B_app typid bdc\" using subst_bb_inject *  sory (* going to be like the above as bdc is closed *)*)\n    have \"atom bv \\<sharp> b1\" proof -\n      have \"supp b1 \\<subseteq> { atom bva }\" using wfTh_poly_supp_b ** SConsp by metis\n      moreover have \"bv \\<noteq> bva\" using ** by auto\n      ultimately show ?thesis using fresh_def by force\n    qed      \n    have \"T  \\<turnstile> s : b1[bva::=bdc]\\<^sub>b\\<^sub>b\" using ** by auto\n    moreover have \"b1[bva::=bdc']\\<^sub>b\\<^sub>b[bv::=b']\\<^sub>b\\<^sub>b = b1[bva::=bdc]\\<^sub>b\\<^sub>b\" using bdc subst_bb_commute \\<open>atom bv \\<sharp> b1\\<close> by auto\n    ultimately  obtain s' where s':\"T  \\<turnstile> s ~ b1[bva::=bdc']\\<^sub>b\\<^sub>b [ bv ::= b' ] \\<setminus> s'\" \n      using SConsp(1)[of \"b1[bva::=bdc']\\<^sub>b\\<^sub>b\"] bdc SConsp by metis\n    have \"T  \\<turnstile> SConsp typid dc bdc'[bv::=b']\\<^sub>b\\<^sub>b s ~ (B_app typid bdc') [ bv ::= b' ] \\<setminus> SConsp typid dc bdc' s'\" \n    proof - \n\n      obtain bva3 and dclist3 where 3:\"AF_typedef_poly typid bva3 dclist3 =  AF_typedef_poly typid bva dclist \\<and> \n            atom bva3 \\<sharp> (bdc', bv, b', s, s')\" using obtain_fresh_bv  by metis\n      then obtain x3 b3 c3 where 4:\"(dc, \\<lbrace> x3 : b3  | c3 \\<rbrace>) \\<in> set dclist3\" \n        using boxed_b_BConspI td_lookup_eq_iff type_def.eq_iff \n        by (metis \"**\")\n\n      show ?thesis proof\n        show \\<open>AF_typedef_poly typid bva3 dclist3 \\<in> set T\\<close> using 3 ** by metis \n        show \\<open>atom bva3 \\<sharp> (bdc', bv, b', s, s')\\<close> using 3 by metis\n        show 4:\\<open>(dc, \\<lbrace> x3 : b3  | c3 \\<rbrace>) \\<in> set dclist3\\<close> using 4 by auto\n        have \"b3[bva3::=bdc']\\<^sub>b\\<^sub>b = b1[bva::=bdc']\\<^sub>b\\<^sub>b\" proof(rule wfTh_typedef_poly_b_eq_iff)\n          show \\<open>AF_typedef_poly typid bva3 dclist3 \\<in> set T\\<close> using 3 ** by metis\n          show \\<open>(dc, \\<lbrace> x3 : b3  | c3 \\<rbrace>) \\<in> set dclist3\\<close> using 4 by auto\n          show \\<open>AF_typedef_poly typid bva dclist \\<in> set T\\<close> using ** by auto\n          show \\<open>(dc, \\<lbrace> x1 : b1  | c1 \\<rbrace>) \\<in> set dclist\\<close> using ** by auto\n        qed(simp add: ** SConsp)\n        thus  \\<open> T  \\<turnstile> s ~ b3[bva3::=bdc']\\<^sub>b\\<^sub>b [ bv ::= b' ] \\<setminus> s' \\<close> using s' by auto\n      qed\n    qed\n    then show ?thesis using bdc by auto\n\n  qed\nnext \n  case SUnit\n  have *:\"b[bv::=b']\\<^sub>b\\<^sub>b = B_unit\" using wfRCV_elims SUnit by metis\n  show ?case proof (cases \"b = B_var bv\")\n    case True\n    moreover have \"T  \\<turnstile> SUnit : B_unit\" using wfRCV.intros by simp\n    moreover hence \"b' = B_unit\" using True SUnit subst_bb.simps * by simp\n    ultimately show ?thesis using boxed_b.intros  wfRCV.intros by metis\n  next\n    case False\n    hence \"b = B_unit\" using subst_bb_inject *  by metis  \n    then show ?thesis using * SUnit boxed_b.intros by metis\n  qed\nnext\n  case (SUt x) \n  then obtain bv' where *:\"b[bv::=b']\\<^sub>b\\<^sub>b= B_var bv'\" using wfRCV_elims by metis\n  show ?case proof (cases \"b = B_var bv\")\n    case True\n    then show ?thesis using boxed_b_BVar1I \n      using \"local.*\" wfRCV_BVarI by fastforce\n  next\n    case False\n    then show ?thesis using boxed_b_BVar1I  boxed_b_BVar2I\n      using \"local.*\" wfRCV_BVarI    by (metis subst_b_var)\n  qed\nqed\n\nlemma boxed_i_ex:\n  assumes \"wfI T \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b i\" and \"wfTh T\"\n  shows  \"\\<exists>i'. T ; \\<Gamma> ; b , bv \\<turnstile> i \\<approx> i'\"\n  using assms proof(induct \\<Gamma> arbitrary: i rule:\\<Gamma>_induct)\n  case GNil\n  then show ?case using boxed_i_GNilI by metis\nnext\n  case (GCons x' b' c' \\<Gamma>')\n  then obtain s where 1:\"Some s = i x' \\<and> wfRCV T s b'[bv::=b]\\<^sub>b\\<^sub>b\" using wfI_def subst_gb.simps by auto\n  then obtain s' where 2: \"boxed_b T s b' bv b s'\" using boxed_b_ex GCons by metis\n  then obtain i' where 3: \"boxed_i T \\<Gamma>' b bv i  i'\" using GCons wfI_def subst_gb.simps by force\n  have \"boxed_i T ((x', b', c') #\\<^sub>\\<Gamma> \\<Gamma>') b bv i  (i'(x' \\<mapsto> s'))\" proof\n    show \"Some s = i x'\" using 1 by auto\n    show \"boxed_b T s b' bv b s'\" using 2 by auto\n    show \"T  ; \\<Gamma>' ; b , bv \\<turnstile> i \\<approx> i'\"  using  \"3\" by auto\n  qed\n  thus ?case by auto\nqed\n\nlemma  boxed_b_eq:\n  assumes \"boxed_b \\<Theta> s1 b bv b' s1'\" and \"\\<turnstile>\\<^sub>w\\<^sub>f \\<Theta>\"\n  shows \"wfTh \\<Theta> \\<Longrightarrow> boxed_b \\<Theta> s2 b bv b' s2' \\<Longrightarrow> ( s1 = s2 ) = ( s1' = s2' )\"\n  using assms proof(induct arbitrary: s2 s2'  rule: boxed_b.inducts )\n  case (boxed_b_BVar1I bv bv'  P s b )  \n  then show ?case \n    using boxed_b_elims(1) rcl_val.eq_iff by metis\nnext\n  case (boxed_b_BVar2I bv bv' P s b)\n  then show ?case using boxed_b_elims(1) by metis\nnext\n  case (boxed_b_BIntI P s uu uv)\n  hence \"s2 = s2'\" using boxed_b_elims by metis\n  then show ?case by auto\nnext\n  case (boxed_b_BBoolI P s uw ux)\n  hence \"s2 = s2'\" using boxed_b_elims by metis\n  then show ?case by auto\nnext\n  case (boxed_b_BUnitI P s uy uz)\n  hence \"s2 = s2'\" using boxed_b_elims by metis\n  then show ?case by auto\nnext\n  case (boxed_b_BPairI P s1 b1 bv b s1' s2a b2 s2a')\n  then show ?case\n    by (metis boxed_b_elims(5) rcl_val.eq_iff(4))\nnext\n  case (boxed_b_BConsI tyid dclist P dc x b c s1 bv b' s1')\n  obtain s22 and s22' dclist2 dc2 x2 b2 c2 where *:\"s2 = SCons tyid dc2 s22 \\<and> s2' = SCons tyid dc2 s22' \\<and> boxed_b P s22 b2 bv b' s22' \n      \\<and> AF_typedef tyid dclist2 \\<in> set P \\<and> (dc2, \\<lbrace> x2 : b2  | c2 \\<rbrace>) \\<in> set dclist2\" using boxed_b_elims(6)[OF boxed_b_BConsI(6)] by metis\n  show ?case proof(cases \"dc = dc2\")\n    case True\n    hence \"b = b2\"  using wfTh_ctor_unique \\<tau>.eq_iff wfTh_dclist_unique wf boxed_b_BConsI * by metis\n    then show ?thesis using boxed_b_BConsI True * by auto\n  next\n    case False\n    then show ?thesis using * boxed_b_BConsI by simp\n  qed      \nnext\n  case (boxed_b_Bbitvec P s bv b)\n  hence \"s2 = s2'\" using boxed_b_elims by metis\n  then show ?case by auto\nnext\n  case (boxed_b_BConspI tyid bva dclist P b1 bv b' s1 s1' dc x b c)\n  obtain bva2 s22  s22' dclist2 dc2 x2 b2 c2 where *:\"\n     s2 = SConsp tyid dc2 b1[bv::=b']\\<^sub>b\\<^sub>b s22 \\<and> \n     s2' = SConsp tyid dc2 b1 s22' \\<and> \n     boxed_b P s22 b2[bva2::=b1]\\<^sub>b\\<^sub>b  bv b' s22'  \\<and> \n     AF_typedef_poly tyid bva2 dclist2 \\<in> set P \\<and> (dc2, \\<lbrace> x2 : b2  | c2 \\<rbrace>) \\<in> set dclist2\" using boxed_b_elims(8)[OF boxed_b_BConspI(7)] by metis\n  show ?case proof(cases \"dc = dc2\")\n    case True\n    hence \"AF_typedef_poly tyid bva2 dclist2 \\<in> set P \\<and> (dc, \\<lbrace> x2 : b2  | c2 \\<rbrace>) \\<in> set dclist2\" using * by auto\n    hence \"b[bva::=b1]\\<^sub>b\\<^sub>b = b2[bva2::=b1]\\<^sub>b\\<^sub>b\"  using wfTh_typedef_poly_b_eq_iff[OF boxed_b_BConspI(1) boxed_b_BConspI(3)] * boxed_b_BConspI by metis\n    then show ?thesis using boxed_b_BConspI True * by auto\n  next\n    case False\n    then show ?thesis using * boxed_b_BConspI by simp\n  qed    \nqed\n\nlemma bs_boxed_var:\n  assumes \"boxed_i \\<Theta> \\<Gamma> b' bv i i'\"\n  shows \"Some (b,c) = lookup \\<Gamma> x \\<Longrightarrow> Some s = i x \\<Longrightarrow> Some s' = i' x \\<Longrightarrow> boxed_b \\<Theta> s b bv b' s'\"\n  using assms proof(induct rule: boxed_i.inducts)\n  case (boxed_i_GNilI T i)\n  then show ?case using lookup.simps by auto\nnext\n  case (boxed_i_GConsI s i x1 \\<Theta> b1 bv b' s'  \\<Gamma> i' c)\n  show ?case proof (cases \"x=x1\")\n    case True\n    then show ?thesis using boxed_i_GConsI\n        fun_upd_same lookup.simps(2) option.inject prod.inject by metis\n  next\n    case False\n    then show ?thesis using boxed_i_GConsI\n        fun_upd_same lookup.simps option.inject prod.inject by auto\n  qed\nqed\n\nlemma eval_l_boxed_b:\n  assumes  \"\\<lbrakk> l \\<rbrakk> = s\"\n  shows   \"boxed_b \\<Theta> s (base_for_lit l) bv b' s\"\n  using assms proof(nominal_induct l arbitrary: s  rule:l.strong_induct)\nqed(auto simp add:  boxed_b.intros wfRCV.intros )+\n\nlemma boxed_i_eval_v_boxed_b:\n  fixes v::v\n  assumes \"boxed_i \\<Theta> \\<Gamma> b' bv i i'\" and \"i \\<lbrakk> v[bv::=b']\\<^sub>v\\<^sub>b \\<rbrakk> ~  s\" and  \"i' \\<lbrakk> v \\<rbrakk> ~ s'\" and \"wfV \\<Theta> B \\<Gamma> v b\"  and \"wfI \\<Theta>  \\<Gamma> i'\"\n  shows \"boxed_b \\<Theta> s b bv b' s'\"\n  using assms proof(nominal_induct v arbitrary: s s' b  rule:v.strong_induct)\n  case (V_lit l)\n  hence \"\\<lbrakk> l \\<rbrakk> = s \\<and> \\<lbrakk> l \\<rbrakk> = s'\" using eval_v_elims by auto\n  moreover have \"b = base_for_lit l\" using wfV_elims(2) V_lit  by metis\n  ultimately show ?case using V_lit using  eval_l_boxed_b subst_b_base_for_lit by metis\nnext\n  case (V_var x)   (* look at defn of bs_boxed *)\n  hence \"Some s = i x \\<and> Some s' = i' x\" using eval_v_elims subst_vb.simps  by metis\n  moreover obtain c1  where bc:\"Some (b,c1) = lookup \\<Gamma> x\" using wfV_elims V_var by metis\n  ultimately show ?case using bs_boxed_var V_var by metis\n\nnext\n  case (V_pair v1 v2)\n  then obtain b1 and b2 where b:\"b=B_pair b1 b2\" using wfV_elims subst_vb.simps  by metis\n  obtain s1 and s2 where s: \"eval_v i (v1[bv::=b']\\<^sub>v\\<^sub>b) s1 \\<and> eval_v i (v2[bv::=b']\\<^sub>v\\<^sub>b) s2 \\<and> s = SPair s1 s2\" using eval_v_elims V_pair subst_vb.simps by metis\n  obtain s1' and s2' where s': \"eval_v i' v1 s1' \\<and> eval_v i' v2 s2' \\<and> s' = SPair s1' s2'\" using eval_v_elims V_pair  by metis\n  have  \"boxed_b  \\<Theta> (SPair s1 s2) (B_pair b1 b2)  bv b' (SPair s1' s2') \" proof(rule boxed_b_BPairI)\n    show \"boxed_b \\<Theta> s1 b1 bv b' s1'\" using V_pair eval_v_elims wfV_elims b s s' b.eq_iff by metis\n    show \"boxed_b \\<Theta> s2 b2 bv b' s2'\" using V_pair eval_v_elims wfV_elims b s s' b.eq_iff by metis\n  qed\n  then show ?case using s s' b by auto\nnext\n  case (V_cons tyid dc v1)\n\n  obtain dclist x b1 c where *: \"b = B_id tyid \\<and> AF_typedef tyid dclist \\<in> set \\<Theta> \\<and> (dc, \\<lbrace> x : b1  | c \\<rbrace>) \\<in> set dclist \\<and>  \\<Theta> ; B ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f v1 : b1\"\n    using wfV_elims(4)[OF V_cons(5)] V_cons by metis\n  obtain s2 where s2: \"s = SCons tyid dc s2 \\<and>  i \\<lbrakk> (v1[bv::=b']\\<^sub>v\\<^sub>b) \\<rbrakk> ~ s2\" using eval_v_elims V_cons subst_vb.simps by metis\n  obtain s2' where s2': \"s' = SCons tyid dc s2' \\<and>  i' \\<lbrakk> v1 \\<rbrakk> ~ s2'\" using eval_v_elims V_cons by metis\n  have sp: \"supp \\<lbrace> x : b1  | c \\<rbrace> = {}\" using wfTh_lookup_supp_empty * wfX_wfY by metis\n\n  have \"boxed_b \\<Theta> (SCons tyid dc s2) (B_id tyid) bv b' (SCons tyid dc s2')\"\n  proof(rule boxed_b_BConsI)\n    show 1:\"AF_typedef tyid dclist \\<in> set \\<Theta>\" using * by auto\n    show 2:\"(dc, \\<lbrace> x : b1  | c \\<rbrace>) \\<in> set dclist\" using * by auto\n    have bvf:\"atom bv \\<sharp> b1\" using sp  \\<tau>.fresh fresh_def by auto    \n    show \"\\<Theta>  \\<turnstile> s2 ~ b1 [ bv ::= b' ] \\<setminus> s2'\" using V_cons s2 s2' * by metis\n  qed\n  then show ?case using * s2 s2' by simp\nnext\n  case (V_consp tyid dc b1 v1)\n\n  obtain bv2 dclist x2 b2 c2 where *: \"b = B_app tyid b1 \\<and> AF_typedef_poly tyid bv2 dclist \\<in> set \\<Theta> \\<and> \n       (dc, \\<lbrace> x2 : b2  | c2 \\<rbrace>) \\<in> set dclist \\<and>  \\<Theta> ; B ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f v1 : b2[bv2::=b1]\\<^sub>b\\<^sub>b\"\n    using wf_strong_elim(1)[OF V_consp (5)] by metis\n\n  obtain s2 where s2: \"s = SConsp tyid dc b1[bv::=b']\\<^sub>b\\<^sub>b s2 \\<and>  i \\<lbrakk> (v1[bv::=b']\\<^sub>v\\<^sub>b) \\<rbrakk> ~ s2\" \n    using eval_v_elims V_consp subst_vb.simps by metis\n\n  obtain s2' where s2': \"s' = SConsp tyid dc b1 s2' \\<and>  i' \\<lbrakk> v1 \\<rbrakk> ~ s2'\" \n    using eval_v_elims V_consp by metis\n\n  have \"\\<turnstile>\\<^sub>w\\<^sub>f \\<Theta>\" using V_consp wfX_wfY by metis\n  then obtain bv3::bv and dclist3 x3 b3 c3 where **:\" AF_typedef_poly tyid bv2 dclist =  AF_typedef_poly tyid bv3 dclist3 \\<and>\n        (dc, \\<lbrace> x3 : b3  | c3 \\<rbrace>) \\<in> set dclist3 \\<and> atom bv3 \\<sharp> (b1, bv, b', s2, s2') \\<and> b2[bv2::=b1]\\<^sub>b\\<^sub>b = b3[bv3::=b1]\\<^sub>b\\<^sub>b\"\n    using * obtain_fresh_bv_dclist_b_iff[where tm=\"(b1, bv, b', s2, s2')\"] by metis\n\n  have \"boxed_b \\<Theta> (SConsp tyid dc b1[bv::=b']\\<^sub>b\\<^sub>b s2) (B_app tyid b1) bv b' (SConsp tyid dc b1 s2')\"\n  proof(rule boxed_b_BConspI[of tyid bv3 dclist3 \\<Theta>, where x=x3 and b=b3 and c=c3])\n    show 1:\"AF_typedef_poly tyid bv3 dclist3 \\<in> set \\<Theta>\" using * ** by auto\n    show 2:\"(dc, \\<lbrace> x3 : b3  | c3 \\<rbrace>) \\<in> set dclist3\" using ** by auto\n    show \"atom bv3 \\<sharp> (b1, bv, b', s2, s2')\" using ** by auto  \n    show \" \\<Theta>  \\<turnstile> s2 ~ b3[bv3::=b1]\\<^sub>b\\<^sub>b [ bv ::= b' ] \\<setminus> s2'\" using V_consp s2 s2' * ** by metis\n  qed\n  then show ?case using * s2 s2' by simp\nqed\n\nlemma boxed_b_eq_eq:\n  assumes  \"boxed_b \\<Theta> n1 b1 bv b' n1'\" and \"boxed_b \\<Theta> n2 b1 bv b' n2'\" and \"s = SBool (n1 = n2)\" and  \"\\<turnstile>\\<^sub>w\\<^sub>f \\<Theta>\"\n    \"s' = SBool (n1' = n2')\"\n  shows  \"s=s'\" \n  using boxed_b_eq assms by auto\n\nlemma boxed_i_eval_ce_boxed_b:\n  fixes e::ce\n  assumes \"i' \\<lbrakk> e \\<rbrakk> ~  s'\" and \"i \\<lbrakk> e[bv::=b']\\<^sub>c\\<^sub>e\\<^sub>b \\<rbrakk> ~ s\" and \"wfCE \\<Theta> B \\<Gamma> e b\" and \"boxed_i \\<Theta> \\<Gamma> b' bv i i'\" and \"wfI \\<Theta> \\<Gamma> i'\"\n  shows \"boxed_b \\<Theta> s b bv b' s'\"\n  using assms proof(nominal_induct e arbitrary: s s' b b' rule: ce.strong_induct)\n  case (CE_val x)\n  then show ?case using boxed_i_eval_v_boxed_b eval_e_elims wfCE_elims subst_ceb.simps by metis\nnext\n  case (CE_op opp v1 v2)\n\n  show ?case proof(rule opp.exhaust)\n    assume \\<open>opp = Plus\\<close>\n    have 1:\"wfCE \\<Theta> B \\<Gamma> v1 (B_int)\" using wfCE_elims CE_op  \\<open>opp = Plus\\<close>  by metis\n    have 2:\"wfCE \\<Theta> B \\<Gamma> v2 (B_int)\" using wfCE_elims CE_op  \\<open>opp = Plus\\<close> by metis\n    have *:\"b = B_int\" using CE_op wfCE_elims \n      by (metis \\<open>opp = plus\\<close>)\n\n    obtain n1 and n2 where n:\"s = SNum (n1 + n2) \\<and> i \\<lbrakk> v1[bv::=b']\\<^sub>c\\<^sub>e\\<^sub>b \\<rbrakk> ~ SNum n1 \\<and> i \\<lbrakk> v2[bv::=b']\\<^sub>c\\<^sub>e\\<^sub>b \\<rbrakk> ~ SNum n2\" using eval_e_elims CE_op subst_ceb.simps \\<open>opp = plus\\<close>  by metis\n    obtain n1' and n2' where n':\"s' = SNum (n1' + n2') \\<and> i' \\<lbrakk> v1 \\<rbrakk> ~ SNum n1' \\<and> i' \\<lbrakk> v2 \\<rbrakk> ~ SNum n2'\" using eval_e_elims Plus CE_op \\<open>opp = plus\\<close> by metis\n\n    have \"boxed_b \\<Theta> (SNum n1) B_int bv b' (SNum n1')\" using boxed_i_eval_v_boxed_b 1 2 n n' CE_op \\<open>opp = plus\\<close> by metis\n    moreover have \"boxed_b \\<Theta> (SNum n2) B_int bv b' (SNum n2')\" using boxed_i_eval_v_boxed_b 1 2 n n' CE_op by metis\n    ultimately have \"s=s'\" using n' n boxed_b_elims(2)\n      by (metis rcl_val.eq_iff(2))\n    thus ?thesis using  * n n' boxed_b_BIntI CE_op wfRCV.intros Plus by simp\n  next\n    assume \\<open>opp = LEq\\<close>\n    have 1:\"wfCE \\<Theta> B \\<Gamma> v1 (B_int)\" using wfCE_elims CE_op  \\<open>opp = LEq\\<close>  by metis\n    have 2:\"wfCE \\<Theta> B \\<Gamma> v2 (B_int)\" using wfCE_elims CE_op  \\<open>opp = LEq\\<close> by metis\n    hence *:\"b = B_bool\" using CE_op wfCE_elims \\<open>opp = LEq\\<close>   by metis\n    obtain n1 and n2 where n:\"s = SBool (n1 \\<le> n2) \\<and> i \\<lbrakk> v1[bv::=b']\\<^sub>c\\<^sub>e\\<^sub>b \\<rbrakk> ~ SNum n1 \\<and> i \\<lbrakk> v2[bv::=b']\\<^sub>c\\<^sub>e\\<^sub>b \\<rbrakk> ~ SNum n2\" using eval_e_elims subst_ceb.simps CE_op \\<open>opp = LEq\\<close> by metis\n    obtain n1' and n2' where n':\"s' = SBool (n1' \\<le> n2') \\<and> i' \\<lbrakk> v1 \\<rbrakk> ~ SNum n1' \\<and> i' \\<lbrakk> v2 \\<rbrakk> ~ SNum n2'\" using eval_e_elims CE_op \\<open>opp = LEq\\<close>  by metis\n\n    have \"boxed_b \\<Theta> (SNum n1) B_int bv b' (SNum n1')\" using boxed_i_eval_v_boxed_b 1 2 n n' CE_op by metis\n    moreover have \"boxed_b \\<Theta> (SNum n2) B_int bv b' (SNum n2')\" using boxed_i_eval_v_boxed_b 1 2 n n' CE_op by metis\n    ultimately have \"s=s'\" using n' n boxed_b_elims(2)\n      by (metis rcl_val.eq_iff(2))\n    thus ?thesis using  * n n' boxed_b_BBoolI CE_op wfRCV.intros \\<open>opp = LEq\\<close> by simp\n  next\n    assume \\<open>opp = Eq\\<close>\n    obtain b1 where b1:\"wfCE \\<Theta> B \\<Gamma> v1 b1 \\<and> wfCE \\<Theta> B \\<Gamma> v2 b1\" using wfCE_elims CE_op  \\<open>opp = Eq\\<close>  by metis\n\n    hence *:\"b = B_bool\" using CE_op wfCE_elims \\<open>opp = Eq\\<close>   by metis\n    obtain n1 and n2 where n:\"s = SBool (n1 = n2) \\<and> i \\<lbrakk> v1[bv::=b']\\<^sub>c\\<^sub>e\\<^sub>b \\<rbrakk> ~ n1 \\<and> i \\<lbrakk> v2[bv::=b']\\<^sub>c\\<^sub>e\\<^sub>b \\<rbrakk> ~ n2\" using eval_e_elims subst_ceb.simps CE_op \\<open>opp = Eq\\<close> by metis\n    obtain n1' and n2' where n':\"s' = SBool (n1' = n2') \\<and> i' \\<lbrakk> v1 \\<rbrakk> ~ n1' \\<and> i' \\<lbrakk> v2 \\<rbrakk> ~ n2'\" using eval_e_elims CE_op \\<open>opp = Eq\\<close>  by metis\n\n    have \"boxed_b \\<Theta> n1 b1 bv b' n1'\" using boxed_i_eval_v_boxed_b b1  n n' CE_op by metis\n    moreover have \"boxed_b \\<Theta> n2 b1 bv b' n2'\" using boxed_i_eval_v_boxed_b b1  n n' CE_op by metis\n    moreover have \"\\<turnstile>\\<^sub>w\\<^sub>f \\<Theta>\" using b1 wfX_wfY by metis\n    ultimately have \"s=s'\" using n' n boxed_b_elims\n        boxed_b_eq_eq by metis\n    thus ?thesis using  * n n' boxed_b_BBoolI CE_op wfRCV.intros \\<open>opp = Eq\\<close> by simp\n  qed\n\nnext\n  case (CE_concat v1 v2)\n\n  obtain bv1 and bv2 where s : \"s = SBitvec (bv1 @ bv2) \\<and> (i \\<lbrakk> v1[bv::=b']\\<^sub>c\\<^sub>e\\<^sub>b \\<rbrakk> ~ SBitvec bv1)  \\<and> i \\<lbrakk> v2[bv::=b']\\<^sub>c\\<^sub>e\\<^sub>b \\<rbrakk> ~ SBitvec bv2\"\n    using eval_e_elims(7) subst_ceb.simps CE_concat.prems(2) eval_e_elims(6) subst_ceb.simps(6) by metis\n  obtain bv1' and bv2' where s' : \"s' = SBitvec (bv1' @ bv2') \\<and> i' \\<lbrakk> v1 \\<rbrakk> ~ SBitvec bv1'  \\<and> i' \\<lbrakk> v2 \\<rbrakk> ~ SBitvec bv2'\"\n    using eval_e_elims(7) CE_concat by metis\n\n  then show ?case using boxed_i_eval_v_boxed_b wfCE_elims s s' CE_concat   \n    by (metis CE_concat.prems(3) assms assms(5) wfRCV_BBitvecI boxed_b_Bbitvec boxed_b_elims(7) eval_e_concatI eval_e_uniqueness)\nnext\n  case (CE_fst ce)\n  obtain  s2 where 1:\"i \\<lbrakk> ce[bv::=b']\\<^sub>c\\<^sub>e\\<^sub>b \\<rbrakk> ~ SPair s s2\" using CE_fst eval_e_elims subst_ceb.simps by metis\n  obtain  s2' where 2:\"i' \\<lbrakk> ce \\<rbrakk> ~ SPair s' s2'\" using CE_fst eval_e_elims by metis\n  obtain b2 where 3:\"wfCE \\<Theta> B \\<Gamma> ce (B_pair b b2)\" using wfCE_elims(4) CE_fst by metis\n\n  have \"boxed_b \\<Theta> (SPair s s2) (B_pair b b2) bv b' (SPair s' s2')\" \n    using 1 2 3 CE_fst boxed_i_eval_v_boxed_b boxed_b_BPairI by auto\n  thus ?case using boxed_b_elims(5) by force\nnext\n  case (CE_snd v)\n  obtain s1  where 1:\"i \\<lbrakk> v[bv::=b']\\<^sub>c\\<^sub>e\\<^sub>b \\<rbrakk> ~ SPair s1 s\" using CE_snd eval_e_elims subst_ceb.simps by metis\n  obtain s1' where 2:\"i' \\<lbrakk> v \\<rbrakk> ~ SPair s1' s'\" using CE_snd eval_e_elims by metis\n  obtain b1 where 3:\"wfCE \\<Theta> B \\<Gamma> v (B_pair b1 b )\" using wfCE_elims(5) CE_snd by metis\n\n  have \"boxed_b \\<Theta> (SPair s1 s ) (B_pair b1 b ) bv b' (SPair s1' s')\" using 1 2 3 CE_snd boxed_i_eval_v_boxed_b by simp\n  thus ?case using boxed_b_elims(5) by force\nnext\n  case (CE_len v)\n  obtain s1 where s: \"i \\<lbrakk> v[bv::=b']\\<^sub>c\\<^sub>e\\<^sub>b \\<rbrakk> ~ SBitvec s1\" using CE_len eval_e_elims subst_ceb.simps by metis\n  obtain s1' where s': \"i' \\<lbrakk> v \\<rbrakk> ~ SBitvec s1'\" using CE_len eval_e_elims by metis\n\n  have \"\\<Theta> ; B ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f v : B_bitvec \\<and> b = B_int\"  using wfCE_elims CE_len by metis\n  then show ?case using boxed_i_eval_v_boxed_b s s' CE_len \n    by (metis boxed_b_BIntI boxed_b_elims(7) eval_e_lenI eval_e_uniqueness subst_ceb.simps(5) wfI_wfCE_eval_e)\nqed\n\nlemma eval_c_eq_bs_boxed:\n  fixes c::c\n  assumes \"i \\<lbrakk> c[bv::=b]\\<^sub>c\\<^sub>b \\<rbrakk> ~ s\" and \"i' \\<lbrakk> c \\<rbrakk> ~ s'\" and \"wfC \\<Theta> B \\<Gamma> c\" and \"wfI \\<Theta> \\<Gamma> i'\" and \"\\<Theta> ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b  \\<turnstile> i \"\n    and \"boxed_i \\<Theta> \\<Gamma> b bv i i'\"\n  shows \"s = s'\"\n  using assms proof(nominal_induct c arbitrary: s s'  rule:c.strong_induct)\n  case C_true\n  then show ?case using eval_c_elims subst_cb.simps by metis\nnext\n  case C_false\n  then show ?case using eval_c_elims  subst_cb.simps by metis\nnext\n  case (C_conj c1 c2)\n  obtain s1 and s2 where 1: \"eval_c i (c1[bv::=b]\\<^sub>c\\<^sub>b) s1 \\<and> eval_c i (c2[bv::=b]\\<^sub>c\\<^sub>b) s2 \\<and> s = (s1\\<and>s2)\" using C_conj eval_c_elims(3) subst_cb.simps(3) by metis\n  obtain s1' and s2' where 2:\"eval_c i' c1 s1' \\<and> eval_c i' c2 s2' \\<and> s' = (s1'\\<and>s2')\" using C_conj eval_c_elims(3) by metis\n  then show ?case using 1 2 wfC_elims C_conj by metis\nnext\n  case (C_disj c1 c2)\n\n  obtain s1 and s2 where 1: \"eval_c i (c1[bv::=b]\\<^sub>c\\<^sub>b) s1 \\<and> eval_c i (c2[bv::=b]\\<^sub>c\\<^sub>b) s2 \\<and> s = (s1\\<or>s2)\" using C_disj eval_c_elims(4) subst_cb.simps(4) by metis\n  obtain s1' and s2' where 2:\"eval_c i' c1 s1' \\<and> eval_c i' c2 s2' \\<and> s' = (s1'\\<or>s2')\" using C_disj eval_c_elims(4) by metis\n  then show ?case using 1 2 wfC_elims C_disj by metis\nnext\n  case (C_not c)\n  obtain s1::bool  where 1: \"(i \\<lbrakk> c[bv::=b]\\<^sub>c\\<^sub>b \\<rbrakk> ~ s1) \\<and> (s = (\\<not> s1))\" using  C_not eval_c_elims(6) subst_cb.simps(7)  by metis\n  obtain s1'::bool where 2: \"(i' \\<lbrakk> c \\<rbrakk> ~ s1') \\<and> (s' = (\\<not> s1'))\" using C_not eval_c_elims(6) by metis\n  then show ?case using 1 2 wfC_elims C_not by metis\nnext\n  case (C_imp c1 c2)\n  obtain s1 and s2 where 1: \"eval_c i (c1[bv::=b]\\<^sub>c\\<^sub>b) s1 \\<and> eval_c i (c2[bv::=b]\\<^sub>c\\<^sub>b) s2 \\<and> s = (s1 \\<longrightarrow> s2)\" using C_imp eval_c_elims(5) subst_cb.simps(5) by metis\n  obtain s1' and s2' where 2:\"eval_c i' c1 s1' \\<and> eval_c i' c2 s2' \\<and> s' = (s1' \\<longrightarrow> s2')\" using C_imp eval_c_elims(5) by metis\n  then show ?case using 1 2 wfC_elims C_imp by metis\nnext\n  case (C_eq e1 e2)\n  obtain be where be: \"wfCE \\<Theta> B \\<Gamma> e1 be \\<and> wfCE \\<Theta> B \\<Gamma> e2 be\" using C_eq wfC_elims by metis\n  obtain s1 and s2 where 1: \"eval_e i (e1[bv::=b]\\<^sub>c\\<^sub>e\\<^sub>b) s1 \\<and> eval_e i (e2[bv::=b]\\<^sub>c\\<^sub>e\\<^sub>b) s2 \\<and> s = (s1 = s2)\" using C_eq eval_c_elims(7) subst_cb.simps(6) by metis\n  obtain s1' and s2' where 2:\"eval_e i' e1 s1' \\<and> eval_e i' e2 s2' \\<and> s' = (s1' = s2' )\" using C_eq eval_c_elims(7) by metis\n  have \"\\<turnstile>\\<^sub>w\\<^sub>f \\<Theta>\" using C_eq wfX_wfY by metis\n  moreover have \"\\<Theta> ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b  \\<turnstile> i \" using C_eq by auto\n  ultimately show ?case using boxed_b_eq[of \\<Theta> s1 be bv b s1' s2 s2'] 1 2 boxed_i_eval_ce_boxed_b  C_eq wfC_elims subst_cb.simps 1 2 be by auto\nqed\n\nlemma is_satis_bs_boxed:\n  fixes c::c\n  assumes  \"boxed_i \\<Theta> \\<Gamma> b bv i i'\" and \"wfC \\<Theta> B \\<Gamma> c\" and \"wfI \\<Theta> \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b i\" and \"\\<Theta> ; \\<Gamma> \\<turnstile> i'\"\n    and  \"(i \\<Turnstile> c[bv::=b]\\<^sub>c\\<^sub>b)\"\n  shows \"(i' \\<Turnstile> c)\"\nproof -\n  have \"eval_c i (c[bv::=b]\\<^sub>c\\<^sub>b) True\" using is_satis.simps assms by auto\n  moreover obtain s where \"i' \\<lbrakk> c \\<rbrakk> ~ s\" using eval_c_exist assms by metis\n  ultimately show ?thesis using eval_c_eq_bs_boxed assms is_satis.simps by metis\nqed\n\nlemma is_satis_bs_boxed_rev:\n  fixes c::c\n  assumes  \"boxed_i \\<Theta> \\<Gamma> b bv i i'\" and \"wfC \\<Theta> B \\<Gamma> c\" and \"wfI \\<Theta> \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b i\" and \"\\<Theta> ; \\<Gamma> \\<turnstile> i'\" and  \"wfC \\<Theta> {||} \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b (c[bv::=b]\\<^sub>c\\<^sub>b)\"\n    and  \"(i' \\<Turnstile> c)\"\n  shows \"(i \\<Turnstile> c[bv::=b]\\<^sub>c\\<^sub>b)\"\nproof -\n  have \"eval_c i' c True\" using is_satis.simps assms by auto\n  moreover obtain s where \"i \\<lbrakk> c[bv::=b]\\<^sub>c\\<^sub>b \\<rbrakk> ~ s\" using eval_c_exist assms by metis\n  ultimately show ?thesis using eval_c_eq_bs_boxed assms is_satis.simps by metis\nqed\n\nlemma bs_boxed_wfi_aux:\n  fixes b::b and bv::bv and \\<Theta>::\\<Theta> and B::\\<B>\n  assumes   \"boxed_i \\<Theta> \\<Gamma> b bv i i'\" and \"wfI \\<Theta> \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b i\" and \"\\<turnstile>\\<^sub>w\\<^sub>f \\<Theta>\" and \"wfG \\<Theta> B  \\<Gamma>\"\n  shows \"\\<Theta> ; \\<Gamma> \\<turnstile> i'\"\n  using assms proof(induct rule: boxed_i.inducts)\n  case (boxed_i_GNilI T i)\n  then show ?case using wfI_def by auto\nnext\n  case (boxed_i_GConsI s i x1 T b1 bv b s' G i' c1)\n  {\n    fix x2 b2 c2\n    assume as : \"(x2,b2,c2) \\<in> toSet ((x1, b1, c1) #\\<^sub>\\<Gamma> G)\"\n\n    then consider (hd) \"(x2,b2,c2) = (x1, b1, c1)\" | (tail) \"(x2,b2,c2) \\<in> toSet G\" using toSet.simps by auto\n    hence \"\\<exists>s. Some s = (i'(x1 \\<mapsto> s')) x2 \\<and> wfRCV T s b2\" proof(cases)\n      case hd\n      hence \"b1=b2\" by auto\n      moreover have \"(x2,b2[bv::=b]\\<^sub>b\\<^sub>b,c2[bv::=b]\\<^sub>c\\<^sub>b) \\<in> toSet ((x1, b1, c1) #\\<^sub>\\<Gamma> G)[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b\"  using hd subst_gb.simps by simp\n      moreover hence \"wfRCV T s b2[bv::=b]\\<^sub>b\\<^sub>b\" using wfI_def boxed_i_GConsI hd\n      proof -\n        obtain ss :: \"b \\<Rightarrow> x \\<Rightarrow> (x \\<Rightarrow> rcl_val option) \\<Rightarrow> type_def list \\<Rightarrow> rcl_val\" where\n          \"\\<forall>x1a x2a x3 x4. (\\<exists>v5. Some v5 = x3 x2a \\<and> wfRCV x4 v5 x1a) = (Some (ss x1a x2a x3 x4) = x3 x2a \\<and> wfRCV x4 (ss x1a x2a x3 x4) x1a)\"\n          by moura (* 0.0 ms *)\n        then have f1: \"Some (ss b2[bv::=b]\\<^sub>b\\<^sub>b x1 i T) = i x1 \\<and> wfRCV T (ss b2[bv::=b]\\<^sub>b\\<^sub>b x1 i T) b2[bv::=b]\\<^sub>b\\<^sub>b\"\n          using boxed_i_GConsI.prems(1) hd wfI_def by auto (* 31 ms *)\n        then have \"ss b2[bv::=b]\\<^sub>b\\<^sub>b x1 i T = s\"\n          by (metis (no_types) boxed_i_GConsI.hyps(1) option.inject) (* 0.0 ms *)\n        then show ?thesis\n          using f1 by blast (* 0.0 ms *)\n      qed\n      ultimately have \"wfRCV T s' b2\" using boxed_i_GConsI boxed_b_wfRCV by metis\n\n      then show ?thesis using hd by simp\n    next\n      case tail\n      hence \"wfI T G i'\" using boxed_i_GConsI wfI_suffix wfG_suffix subst_gb.simps\n        by (metis (no_types, lifting) Un_iff toSet.simps(2) wfG_cons2 wfI_def)\n      then show ?thesis using wfI_def[of T G i'] tail\n        using boxed_i_GConsI.prems(3) split_G wfG_cons_fresh2 by fastforce\n    qed\n  }\n  thus ?case using wfI_def by fast\n\nqed\n\nlemma is_satis_g_bs_boxed_aux:\n  fixes G::\\<Gamma>\n  assumes  \"boxed_i \\<Theta> G1 b bv i i'\" and \"wfI \\<Theta> G1[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b i\" and \"wfI \\<Theta> G1 i'\"  and \"G1 = (G2@G)\" and  \"wfG \\<Theta> B G1\"\n    and \"(i \\<Turnstile> G[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b) \"\n  shows  \"(i' \\<Turnstile> G)\"\n  using assms proof(induct G arbitrary: G2 rule: \\<Gamma>_induct)\n  case GNil\n  then show ?case by auto\nnext\n  case (GCons x' b' c' \\<Gamma>' G2)\n  show ?case proof(subst is_satis_g.simps,rule)\n    have *:\"wfC \\<Theta> B G1 c'\" using GCons wfG_wfC_inside by force\n    show \"i' \\<Turnstile> c'\" using is_satis_bs_boxed[OF assms(1) * ] GCons by auto\n    obtain G3 where \"G1 = G3 @ \\<Gamma>'\" using GCons append_g.simps\n      by (metis append_g_assoc)\n    then show \"i' \\<Turnstile> \\<Gamma>'\" using GCons append_g.simps by simp\n  qed\nqed\n\nlemma is_satis_g_bs_boxed:\n  fixes G::\\<Gamma>\n  assumes  \"boxed_i \\<Theta> G b bv i i'\" and \"wfI \\<Theta> G[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b i\" and \"wfI \\<Theta> G i'\"  and \"wfG \\<Theta> B G\"\n    and \"(i \\<Turnstile> G[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b) \"\n  shows  \"(i' \\<Turnstile> G)\"\n  using is_satis_g_bs_boxed_aux assms\n  by (metis (full_types) append_g.simps(1))\n\nlemma subst_b_valid:\n  fixes s::s and b::b\n  assumes \"\\<Theta> ; {||} \\<turnstile>\\<^sub>w\\<^sub>f b\"  and \"B = {|bv|}\" and \"\\<Theta> ; {|bv|} ;\\<Gamma>  \\<Turnstile> c\"\n  shows \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b  \\<Turnstile> c[bv::=b]\\<^sub>c\\<^sub>b \"\nproof(rule validI)\n\n  show **:\"\\<Theta> ; {||} ;  \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b   \\<turnstile>\\<^sub>w\\<^sub>f c[bv::=b]\\<^sub>c\\<^sub>b \" using assms valid.simps wf_b_subst subst_gb.simps by metis\n  show \"\\<forall>i. (wfI \\<Theta>  \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b i \\<and> i \\<Turnstile> \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b) \\<longrightarrow> i \\<Turnstile> c[bv::=b]\\<^sub>c\\<^sub>b \"\n  proof(rule,rule)\n    fix i\n    assume *:\"wfI \\<Theta>  \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b i \\<and> i \\<Turnstile> \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b\"\n\n    obtain i' where idash: \"boxed_i \\<Theta> \\<Gamma> b bv i i'\" using boxed_i_ex wfX_wfY assms * by fastforce\n\n    have wfc: \"\\<Theta> ; {|bv|} ; \\<Gamma>  \\<turnstile>\\<^sub>w\\<^sub>f c\" using valid.simps assms by simp\n    have wfg: \"\\<Theta> ; {|bv|} \\<turnstile>\\<^sub>w\\<^sub>f \\<Gamma>\" using valid.simps wfX_wfY assms by metis\n    hence wfi: \"wfI \\<Theta> \\<Gamma> i'\" using idash * bs_boxed_wfi_aux subst_gb.simps wfX_wfY by metis\n    moreover have \"i' \\<Turnstile>  \\<Gamma>\" proof (rule is_satis_g_bs_boxed[OF idash ] wfX_wfY(2)[OF wfc])\n      show \"wfI \\<Theta> \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b i\" using subst_gb.simps * by simp\n      show \"wfI \\<Theta> \\<Gamma> i'\" using wfi by auto\n      show \"\\<Theta> ; B  \\<turnstile>\\<^sub>w\\<^sub>f \\<Gamma> \" using wfg assms by auto\n      show \"i \\<Turnstile> \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b\" using subst_gb.simps * by simp\n    qed\n    ultimately have ic:\"i' \\<Turnstile> c\" using assms valid_def   using valid.simps by blast\n\n    show  \"i \\<Turnstile> c[bv::=b]\\<^sub>c\\<^sub>b\" proof(rule is_satis_bs_boxed_rev)\n      show \"\\<Theta>  ; \\<Gamma> ; b , bv \\<turnstile> i \\<approx> i'\" using idash by auto\n      show \"\\<Theta> ; B ; \\<Gamma>  \\<turnstile>\\<^sub>w\\<^sub>f c \" using wfc assms by auto\n      show \"\\<Theta> ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> i\" using subst_gb.simps * by simp\n      show \"\\<Theta> ; \\<Gamma> \\<turnstile> i'\" using wfi by auto\n      show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b   \\<turnstile>\\<^sub>w\\<^sub>f c[bv::=b]\\<^sub>c\\<^sub>b \" using ** by auto\n      show \"i' \\<Turnstile> c\" using ic by auto\n    qed\n\n  qed\nqed\n\nsection \\<open>Expression Operator Lemmas\\<close>\n\nlemma is_satis_len_imp:\n  assumes \"i \\<Turnstile> (CE_val (V_var x)  ==  CE_val (V_lit (L_num (int (length v)))) )\" (is \"is_satis i ?c1\")\n  shows \"i \\<Turnstile> (CE_val (V_var x)  ==  CE_len [V_lit (L_bitvec v)]\\<^sup>c\\<^sup>e)\"\nproof -\n  have *:\"eval_c i ?c1 True\" using assms is_satis.simps by blast\n  then have  \"eval_e i (CE_val (V_lit (L_num (int (length v))))) (SNum (int (length v)))\"\n    using eval_e_elims(1) eval_v_elims eval_l.simps  by (metis eval_e.intros(1) eval_v_litI)\n  hence \"eval_e i (CE_val (V_var x)) (SNum (int (length v)))\" using eval_c_elims(7)[OF *]\n    by (metis eval_e_elims(1) eval_v_elims(1))\n  moreover have \"eval_e i (CE_len [V_lit (L_bitvec v)]\\<^sup>c\\<^sup>e) (SNum (int (length v)))\"\n    using eval_e_elims(7) eval_v_elims eval_l.simps  by (metis eval_e.intros eval_v_litI)\n  ultimately show ?thesis using eval_c.intros is_satis.simps by fastforce\nqed\n\nlemma is_satis_plus_imp:\n  assumes \"i \\<Turnstile> (CE_val (V_var x) ==  CE_val (V_lit (L_num (n1+n2))))\" (is \"is_satis i ?c1\")\n  shows   \"i \\<Turnstile> (CE_val (V_var x)  ==  CE_op Plus ([V_lit (L_num n1)]\\<^sup>c\\<^sup>e) ([V_lit (L_num n2)]\\<^sup>c\\<^sup>e))\"\nproof -\n  have *:\"eval_c i ?c1 True\" using assms is_satis.simps by blast\n  then have  \"eval_e i (CE_val (V_lit (L_num (n1+n2)))) (SNum (n1+n2))\"\n    using eval_e_elims(1) eval_v_elims eval_l.simps  by (metis eval_e.intros(1) eval_v_litI)\n  hence \"eval_e i (CE_val (V_var x)) (SNum (n1+n2))\" using eval_c_elims(7)[OF *]\n    by (metis eval_e_elims(1) eval_v_elims(1))\n  moreover have \"eval_e i (CE_op Plus ([V_lit (L_num n1)]\\<^sup>c\\<^sup>e) ([V_lit (L_num n2)]\\<^sup>c\\<^sup>e)) (SNum (n1+n2))\"\n    using eval_e_elims(7) eval_v_elims eval_l.simps  by (metis eval_e.intros eval_v_litI)\n  ultimately show ?thesis using eval_c.intros is_satis.simps by fastforce\nqed\n\nlemma is_satis_leq_imp:\n  assumes \"i \\<Turnstile> (CE_val (V_var x) ==  CE_val (V_lit (if (n1 \\<le> n2) then L_true else L_false)))\" (is \"is_satis i ?c1\")\n  shows   \"i \\<Turnstile> (CE_val (V_var x)  ==  CE_op LEq [(V_lit (L_num n1))]\\<^sup>c\\<^sup>e [(V_lit (L_num n2))]\\<^sup>c\\<^sup>e)\"\nproof -\n  have *:\"eval_c i ?c1 True\" using assms is_satis.simps by blast\n  then have  \"eval_e i (CE_val (V_lit ((if (n1 \\<le> n2) then L_true else L_false)))) (SBool (n1\\<le>n2))\"\n    using eval_e_elims(1) eval_v_elims eval_l.simps\n    by (metis (full_types) eval_e.intros(1) eval_v_litI)\n  hence \"eval_e i (CE_val (V_var x)) (SBool (n1\\<le>n2))\" using eval_c_elims(7)[OF *]\n    by (metis eval_e_elims(1) eval_v_elims(1))\n  moreover have \"eval_e i (CE_op LEq [(V_lit (L_num n1))]\\<^sup>c\\<^sup>e [(V_lit (L_num n2) )]\\<^sup>c\\<^sup>e) (SBool (n1\\<le>n2))\"\n    using eval_e_elims(3) eval_v_elims eval_l.simps  by (metis eval_e.intros eval_v_litI)\n  ultimately show ?thesis using eval_c.intros is_satis.simps by fastforce\nqed\n\nlemma eval_lit_inj:\n  fixes n1::l and n2::l\n  assumes \"\\<lbrakk> n1  \\<rbrakk> = s\" and \"\\<lbrakk> n2 \\<rbrakk> = s\" \n  shows \"n1=n2\" \n  using assms proof(nominal_induct s rule: rcl_val.strong_induct)\n  case (SBitvec x)\n  then show ?case using eval_l.simps \n    by (metis l.strong_exhaust rcl_val.distinct rcl_val.eq_iff)\nnext\n  case (SNum x)\n  then show ?case using eval_l.simps \n    by (metis l.strong_exhaust rcl_val.distinct rcl_val.eq_iff)\nnext\n  case (SBool x)\n  then show ?case using eval_l.simps \n    by (metis l.strong_exhaust rcl_val.distinct rcl_val.eq_iff)\nnext\n  case (SPair x1a x2a)\n  then show ?case using eval_l.simps \n    by (metis l.strong_exhaust rcl_val.distinct rcl_val.eq_iff)\nnext\n  case (SCons x1a x2a x3a)\n  then show ?case using eval_l.simps \n    by (metis l.strong_exhaust rcl_val.distinct rcl_val.eq_iff)\nnext\n  case (SConsp x1a x2a x3a x4)\n  then show ?case using eval_l.simps \n    by (metis l.strong_exhaust rcl_val.distinct rcl_val.eq_iff)\nnext\n  case SUnit\n  then show ?case using eval_l.simps \n    by (metis l.strong_exhaust rcl_val.distinct rcl_val.eq_iff)\nnext\n  case (SUt x)\n  then show ?case using eval_l.simps \n    by (metis l.strong_exhaust rcl_val.distinct rcl_val.eq_iff)\nqed\n\nlemma eval_e_lit_inj:\n  fixes n1::l and n2::l\n  assumes \"i \\<lbrakk> [ [ n1 ]\\<^sup>v ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ s\" and \"i \\<lbrakk> [ [ n2 ]\\<^sup>v ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ s\" \n  shows \"n1=n2\" \n  using eval_lit_inj assms eval_e_elims eval_v_elims by metis\n\nlemma is_satis_eq_imp:\n  assumes \"i \\<Turnstile> (CE_val (V_var x) ==  CE_val (V_lit (if (n1 =  n2) then L_true else L_false)))\" (is \"is_satis i ?c1\")\n  shows   \"i \\<Turnstile> (CE_val (V_var x)  ==  CE_op Eq [(V_lit (n1))]\\<^sup>c\\<^sup>e [(V_lit (n2))]\\<^sup>c\\<^sup>e)\"\nproof -\n  have *:\"eval_c i ?c1 True\" using assms is_satis.simps by blast\n  then have  \"eval_e i (CE_val (V_lit ((if (n1=n2) then L_true else L_false)))) (SBool (n1=n2))\"\n    using eval_e_elims(1) eval_v_elims eval_l.simps\n    by (metis (full_types) eval_e.intros(1) eval_v_litI)\n  hence \"eval_e i (CE_val (V_var x)) (SBool (n1=n2))\" using eval_c_elims(7)[OF *]\n    by (metis eval_e_elims(1) eval_v_elims(1))\n  moreover have \"eval_e i (CE_op Eq [(V_lit (n1))]\\<^sup>c\\<^sup>e [(V_lit (n2) )]\\<^sup>c\\<^sup>e) (SBool (n1=n2))\"\n  proof -\n    obtain s1 and s2 where *:\"i \\<lbrakk> [ [ n1 ]\\<^sup>v ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ s1  \\<and> i \\<lbrakk> [ [ n2 ]\\<^sup>v ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ s2\" using eval_l.simps eval_e.intros eval_v_litI by metis\n    moreover have \" SBool (n1 = n2)  =  SBool (s1 = s2)\" proof(cases \"n1=n2\")\n      case True\n      then show ?thesis using * \n        by (simp add: calculation eval_e_uniqueness)\n    next\n      case False\n      then show ?thesis using *  eval_e_lit_inj by auto\n    qed\n    ultimately show ?thesis using eval_e_eqI[of i \"[(V_lit (n1))]\\<^sup>c\\<^sup>e\"  s1 \"[(V_lit (n2))]\\<^sup>c\\<^sup>e\" s2 ] by auto\n  qed\n  ultimately show ?thesis using eval_c.intros is_satis.simps by fastforce\nqed\n\nlemma valid_eq_e:\n  assumes \"\\<forall>i s1 s2. wfG P \\<B> GNil \\<and> wfI P GNil i \\<and> eval_e i e1 s1 \\<and> eval_e i e2 s2 \\<longrightarrow> s1 = s2\"   \n    and \"wfCE P  \\<B> GNil e1 b\" and \"wfCE P \\<B> GNil e2 b\" \n  shows \"P ; \\<B> ; (x, b , CE_val (V_var x)  ==  e1 )#\\<^sub>\\<Gamma> GNil \\<Turnstile>  CE_val (V_var x)  ==  e2\"\n  unfolding valid.simps\nproof(intro conjI)\n  show \\<open> P ; \\<B> ; (x, b, [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e  ==  e1 ) #\\<^sub>\\<Gamma> GNil   \\<turnstile>\\<^sub>w\\<^sub>f [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e  ==  e2  \\<close> \n    using assms wf_intros wfX_wfY  b.eq_iff fresh_GNil wfC_e_eq2 wfV_elims  by meson\n  show \\<open>\\<forall>i.  ((P ; (x, b, [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e  ==  e1 ) #\\<^sub>\\<Gamma> GNil \\<turnstile> i) \\<and>  (i \\<Turnstile> (x, b, [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e  ==  e1 ) #\\<^sub>\\<Gamma> GNil)  \\<longrightarrow>\n             (i \\<Turnstile> [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e  ==  e2)) \\<close> proof(rule+)\n    fix i\n    assume as:\"P ; (x, b, [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e  ==  e1 ) #\\<^sub>\\<Gamma> GNil \\<turnstile> i \\<and>  i \\<Turnstile> (x, b, [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e  ==  e1 ) #\\<^sub>\\<Gamma> GNil\"\n\n    have *: \"P ; GNil \\<turnstile> i \" using wfI_def by auto\n\n    then obtain s1 where s1:\"eval_e i e1 s1\" using assms eval_e_exist  by metis\n    obtain s2 where s2:\"eval_e i e2 s2\" using assms eval_e_exist  * by metis\n    moreover have \"i x = Some s1\" proof -\n      have \"i \\<Turnstile> [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e  ==  e1\" using as is_satis_g.simps by auto\n      thus ?thesis using s1 \n        by (metis eval_c_elims(7) eval_e_elims(1) eval_e_uniqueness eval_v_elims(2) is_satis.cases)\n    qed\n    moreover have \"s1 = s2\" using s1 s2 * assms wfG_nilI wfX_wfY by metis\n\n    ultimately show \"i \\<lbrakk> [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e  ==  e2  \\<rbrakk> ~ True\" \n      using eval_c.intros eval_e.intros eval_v.intros \n    proof -\n      have \"i \\<lbrakk> e2 \\<rbrakk> ~ s1\"\n        by (metis \\<open>s1 = s2\\<close> s2) (* 0.0 ms *)\n      then show ?thesis\n        by (metis (full_types) \\<open>i x = Some s1\\<close> eval_c_eqI eval_e_valI eval_v_varI) (* 31 ms *)\n    qed\n  qed\nqed\n\nlemma valid_len:\n  assumes \" \\<turnstile>\\<^sub>w\\<^sub>f \\<Theta>\" \n  shows  \"\\<Theta> ; \\<B> ; (x, B_int, [[x]\\<^sup>v]\\<^sup>c\\<^sup>e  ==  [[ L_num (int (length v)) ]\\<^sup>v]\\<^sup>c\\<^sup>e) #\\<^sub>\\<Gamma> GNil  \\<Turnstile> [[x]\\<^sup>v]\\<^sup>c\\<^sup>e  ==  CE_len [[ L_bitvec v ]\\<^sup>v]\\<^sup>c\\<^sup>e\"  (is \"\\<Theta> ; \\<B> ; ?G \\<Turnstile> ?c\" )\nproof - \n  have *:\"\\<Theta>  \\<turnstile>\\<^sub>w\\<^sub>f ([]::\\<Phi>)  \\<and>  \\<Theta> ; \\<B> ; GNil  \\<turnstile>\\<^sub>w\\<^sub>f []\\<^sub>\\<Delta> \" using assms wfG_nilI wfD_emptyI wfPhi_emptyI by auto\n\n  moreover  hence \"\\<Theta>  ; \\<B> ; GNil \\<turnstile>\\<^sub>w\\<^sub>f CE_val (V_lit (L_num (int (length v)))) : B_int\" \n    using wfCE_valI * wfV_litI base_for_lit.simps \n    by (metis wfE_valI wfX_wfY)\n\n  moreover have \"\\<Theta>  ; \\<B> ; GNil \\<turnstile>\\<^sub>w\\<^sub>f CE_len [(V_lit (L_bitvec v))]\\<^sup>c\\<^sup>e : B_int\"       \n    using wfE_valI * wfV_litI base_for_lit.simps  wfE_valI wfX_wfY wfCE_valI\n    by (metis wfCE_lenI)\n  moreover have \"atom x \\<sharp> GNil\" by auto\n  ultimately have \"\\<Theta> ; \\<B> ; ?G \\<turnstile>\\<^sub>w\\<^sub>f ?c\" using wfC_e_eq2 assms by simp\n  moreover have \"(\\<forall>i. wfI \\<Theta> ?G i \\<and> is_satis_g i ?G \\<longrightarrow> is_satis i ?c)\" using is_satis_len_imp by auto\n  ultimately show ?thesis using valid.simps by auto\nqed\n\nlemma valid_arith_bop:\n  assumes \"wfG \\<Theta> \\<B>  \\<Gamma>\" and \"opp = Plus \\<and> ll = (L_num (n1+n2)) \\<or> (opp = LEq \\<and> ll = ( if n1\\<le>n2 then L_true else L_false))\"  \n    and \"(opp = Plus \\<longrightarrow> b = B_int) \\<and> (opp = LEq \\<longrightarrow> b = B_bool)\" and\n    \"atom x \\<sharp> \\<Gamma>\" \n  shows   \"\\<Theta>; \\<B> ; (x, b, (CE_val (V_var x)  ==  CE_val (V_lit (ll)) )) #\\<^sub>\\<Gamma> \\<Gamma>  \n                          \\<Turnstile> (CE_val (V_var x)  ==  CE_op opp ([V_lit (L_num n1)]\\<^sup>c\\<^sup>e) ([V_lit (L_num n2)]\\<^sup>c\\<^sup>e ))\" (is \"\\<Theta> ; \\<B> ; ?G \\<Turnstile> ?c\")\nproof -\n  have \"wfC \\<Theta> \\<B> ?G ?c\" proof(rule wfC_e_eq2)\n    show \"\\<Theta> ; \\<B> ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f CE_val (V_lit ll) : b\" using wfCE_valI wfV_litI assms base_for_lit.simps by metis\n    show \"\\<Theta> ; \\<B> ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f CE_op opp ([V_lit (L_num n1)]\\<^sup>c\\<^sup>e) ([V_lit (L_num n2)]\\<^sup>c\\<^sup>e) : b \" \n      using wfCE_plusI wfCE_leqI   wfCE_eqI wfV_litI wfCE_valI base_for_lit.simps assms  by metis\n    show \"\\<turnstile>\\<^sub>w\\<^sub>f \\<Theta>\" using assms wfX_wfY by auto \n    show \"atom x \\<sharp> \\<Gamma>\" using assms by auto\n  qed\n\n  moreover have \"\\<forall>i. wfI \\<Theta> ?G i \\<and> is_satis_g i ?G \\<longrightarrow> is_satis i ?c\" proof(rule allI , rule impI)\n    fix i\n    assume \"wfI \\<Theta> ?G i \\<and> is_satis_g i ?G\" \n\n    hence \"is_satis i  ((CE_val (V_var x)  ==  CE_val (V_lit (ll)) ))\"   by auto\n    thus  \"is_satis i ((CE_val (V_var x)  ==  CE_op opp ([V_lit (L_num n1)]\\<^sup>c\\<^sup>e) ([V_lit (L_num n2)]\\<^sup>c\\<^sup>e)))\" \n      using is_satis_plus_imp assms opp.exhaust is_satis_leq_imp by auto\n  qed\n  ultimately show ?thesis using valid.simps by metis\nqed\n\nlemma valid_eq_bop:\n  assumes \"wfG \\<Theta> \\<B>  \\<Gamma>\" and  \"atom x \\<sharp> \\<Gamma>\"  and  \"base_for_lit l1 = base_for_lit l2\"\n  shows   \"\\<Theta>; \\<B> ; (x, B_bool, (CE_val (V_var x)  ==  CE_val (V_lit (if l1 = l2 then L_true else L_false)) )) #\\<^sub>\\<Gamma> \\<Gamma>  \n                          \\<Turnstile> (CE_val (V_var x)  ==  CE_op Eq ([V_lit (l1)]\\<^sup>c\\<^sup>e) ([V_lit (l2)]\\<^sup>c\\<^sup>e ))\" (is \"\\<Theta> ; \\<B> ; ?G \\<Turnstile> ?c\")\nproof -\n  let ?ll = \"(if l1 = l2 then L_true else L_false)\"\n  have \"wfC \\<Theta> \\<B> ?G ?c\" proof(rule wfC_e_eq2)\n    show \"\\<Theta> ; \\<B> ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f CE_val (V_lit ?ll) : B_bool\" using wfCE_valI wfV_litI assms base_for_lit.simps by metis\n    show \"\\<Theta> ; \\<B> ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f CE_op Eq ([V_lit (l1)]\\<^sup>c\\<^sup>e) ([V_lit (l2)]\\<^sup>c\\<^sup>e) : B_bool \" \n      using wfCE_eqI wfCE_leqI   wfCE_eqI wfV_litI wfCE_valI base_for_lit.simps assms by metis\n    show \"\\<turnstile>\\<^sub>w\\<^sub>f \\<Theta>\" using assms wfX_wfY by auto \n    show \"atom x \\<sharp> \\<Gamma>\" using assms by auto\n  qed\n\n  moreover have \"\\<forall>i. wfI \\<Theta> ?G i \\<and> is_satis_g i ?G \\<longrightarrow> is_satis i ?c\" proof(rule allI , rule impI)\n    fix i\n    assume \"wfI \\<Theta> ?G i \\<and> is_satis_g i ?G\" \n\n    hence \"is_satis i  ((CE_val (V_var x)  ==  CE_val (V_lit (?ll)) ))\"   by auto\n    thus  \"is_satis i ((CE_val (V_var x)  ==  CE_op Eq ([V_lit (l1)]\\<^sup>c\\<^sup>e) ([V_lit (l2)]\\<^sup>c\\<^sup>e)))\" \n      using is_satis_eq_imp assms  by auto\n  qed\n  ultimately show ?thesis using valid.simps by metis\nqed\n\nlemma valid_fst:\n  fixes x::x and v\\<^sub>1::v and v\\<^sub>2::v\n  assumes   \"wfTh \\<Theta>\" and \"wfV \\<Theta> \\<B> GNil (V_pair v\\<^sub>1 v\\<^sub>2) (B_pair b\\<^sub>1 b\\<^sub>2)\"\n  shows \"\\<Theta> ; \\<B> ; (x, b\\<^sub>1, [[x]\\<^sup>v]\\<^sup>c\\<^sup>e  ==  [v\\<^sub>1]\\<^sup>c\\<^sup>e) #\\<^sub>\\<Gamma> GNil  \\<Turnstile> [[x]\\<^sup>v]\\<^sup>c\\<^sup>e  ==  [#1[[v\\<^sub>1,v\\<^sub>2]\\<^sup>v]\\<^sup>c\\<^sup>e]\\<^sup>c\\<^sup>e\" \nproof(rule valid_eq_e)\n  show \\<open>\\<forall>i s1 s2.  (\\<Theta> ; \\<B>  \\<turnstile>\\<^sub>w\\<^sub>f GNil)  \\<and>  (\\<Theta> ; GNil \\<turnstile> i) \\<and> (i \\<lbrakk> [ v\\<^sub>1 ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ s1)  \\<and> (i \\<lbrakk> [#1[[ v\\<^sub>1 , v\\<^sub>2 ]\\<^sup>v]\\<^sup>c\\<^sup>e]\\<^sup>c\\<^sup>e \\<rbrakk> ~ s2)  \\<longrightarrow> s1 = s2\\<close> \n  proof(rule+)\n    fix i s1 s2 \n    assume as:\"\\<Theta> ; \\<B>  \\<turnstile>\\<^sub>w\\<^sub>f GNil  \\<and>  \\<Theta> ; GNil \\<turnstile> i \\<and> (i \\<lbrakk> [ v\\<^sub>1 ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ s1)  \\<and> (i \\<lbrakk> [#1[[ v\\<^sub>1 , v\\<^sub>2 ]\\<^sup>v]\\<^sup>c\\<^sup>e]\\<^sup>c\\<^sup>e \\<rbrakk> ~ s2)\"\n    then obtain s2' where *:\"i \\<lbrakk> [ v\\<^sub>1 , v\\<^sub>2 ]\\<^sup>v \\<rbrakk> ~ SPair s2 s2'\" \n      using eval_e_elims(5)[of i \"[[ v\\<^sub>1 , v\\<^sub>2 ]\\<^sup>v]\\<^sup>c\\<^sup>e\" s2] eval_e_elims \n      by meson\n    then have \" i \\<lbrakk> v\\<^sub>1 \\<rbrakk> ~ s2\" using eval_v_elims(3)[OF *] by auto\n    then show \"s1 = s2\" using eval_v_uniqueness as \n      using eval_e_uniqueness eval_e_valI by blast\n  qed\n\n  show \\<open>  \\<Theta> ; \\<B> ; GNil \\<turnstile>\\<^sub>w\\<^sub>f [ v\\<^sub>1 ]\\<^sup>c\\<^sup>e : b\\<^sub>1 \\<close> using assms \n    by (metis b.eq_iff(4) wfV_elims(3) wfV_wfCE)\n  show \\<open>  \\<Theta> ; \\<B> ; GNil \\<turnstile>\\<^sub>w\\<^sub>f [#1[[ v\\<^sub>1 , v\\<^sub>2 ]\\<^sup>v]\\<^sup>c\\<^sup>e]\\<^sup>c\\<^sup>e : b\\<^sub>1 \\<close> using assms using wfCE_fstI \n    using wfCE_valI by blast\nqed\n\nlemma valid_snd: \n  fixes x::x and v\\<^sub>1::v and v\\<^sub>2::v\n  assumes   \"wfTh \\<Theta>\" and \"wfV \\<Theta> \\<B> GNil (V_pair v\\<^sub>1 v\\<^sub>2) (B_pair b\\<^sub>1 b\\<^sub>2)\"\n  shows \"\\<Theta> ; \\<B> ; (x, b\\<^sub>2, [[x]\\<^sup>v]\\<^sup>c\\<^sup>e  ==  [v\\<^sub>2]\\<^sup>c\\<^sup>e) #\\<^sub>\\<Gamma> GNil  \\<Turnstile> [[x]\\<^sup>v]\\<^sup>c\\<^sup>e  ==  [#2[[v\\<^sub>1,v\\<^sub>2]\\<^sup>v]\\<^sup>c\\<^sup>e]\\<^sup>c\\<^sup>e\" \nproof(rule valid_eq_e)\n  show \\<open>\\<forall>i s1 s2.  (\\<Theta> ; \\<B>  \\<turnstile>\\<^sub>w\\<^sub>f GNil)  \\<and>  (\\<Theta> ; GNil \\<turnstile> i) \\<and> (i \\<lbrakk> [ v\\<^sub>2 ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ s1)  \\<and> \n(i \\<lbrakk> [#2[[ v\\<^sub>1 , v\\<^sub>2 ]\\<^sup>v]\\<^sup>c\\<^sup>e]\\<^sup>c\\<^sup>e \\<rbrakk> ~ s2)  \\<longrightarrow> s1 = s2\\<close> \n  proof(rule+)\n    fix i s1 s2 \n    assume as:\"\\<Theta> ; \\<B>  \\<turnstile>\\<^sub>w\\<^sub>f GNil  \\<and>  \\<Theta> ; GNil \\<turnstile> i \\<and> (i \\<lbrakk> [ v\\<^sub>2 ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ s1)  \\<and> (i \\<lbrakk> [#2[[ v\\<^sub>1 , v\\<^sub>2 ]\\<^sup>v]\\<^sup>c\\<^sup>e]\\<^sup>c\\<^sup>e \\<rbrakk> ~ s2)\"\n    then obtain s2' where *:\"i \\<lbrakk> [ v\\<^sub>1 , v\\<^sub>2 ]\\<^sup>v \\<rbrakk> ~ SPair s2' s2\" \n      using eval_e_elims(5)[of i \"[[ v\\<^sub>1 , v\\<^sub>2 ]\\<^sup>v]\\<^sup>c\\<^sup>e\" s2] eval_e_elims \n      by meson\n    then have \" i \\<lbrakk> v\\<^sub>2 \\<rbrakk> ~ s2\" using eval_v_elims(3)[OF *] by auto\n    then show \"s1 = s2\" using eval_v_uniqueness as \n      using eval_e_uniqueness eval_e_valI by blast\n  qed\n\n  show \\<open>  \\<Theta> ; \\<B> ; GNil \\<turnstile>\\<^sub>w\\<^sub>f [ v\\<^sub>2 ]\\<^sup>c\\<^sup>e : b\\<^sub>2 \\<close> using assms \n    by (metis b.eq_iff wfV_elims wfV_wfCE)\n  show \\<open>  \\<Theta> ; \\<B> ; GNil \\<turnstile>\\<^sub>w\\<^sub>f [#2[[ v\\<^sub>1 , v\\<^sub>2 ]\\<^sup>v]\\<^sup>c\\<^sup>e]\\<^sup>c\\<^sup>e : b\\<^sub>2 \\<close> using assms using wfCE_sndI wfCE_valI by blast\nqed\n\nlemma valid_concat:\n  fixes v1::\"bit list\" and v2::\"bit list\"\n  assumes \" \\<turnstile>\\<^sub>w\\<^sub>f \\<Pi>\" \n  shows \"\\<Pi> ; \\<B> ; (x, B_bitvec, (CE_val (V_var x)  ==  CE_val (V_lit (L_bitvec (v1@ v2))))) #\\<^sub>\\<Gamma> GNil \\<Turnstile>\n            (CE_val (V_var x)  ==  CE_concat ([V_lit (L_bitvec v1)]\\<^sup>c\\<^sup>e ) ([V_lit (L_bitvec v2)]\\<^sup>c\\<^sup>e) )\"\nproof(rule valid_eq_e)                         \n  show \\<open>\\<forall>i s1 s2.  ((\\<Pi> ; \\<B>  \\<turnstile>\\<^sub>w\\<^sub>f GNil)  \\<and>  (\\<Pi> ; GNil \\<turnstile> i) \\<and> \n            (i \\<lbrakk> [ [ L_bitvec (v1 @ v2) ]\\<^sup>v ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ s1)  \\<and> (i \\<lbrakk> [[[ L_bitvec v1 ]\\<^sup>v]\\<^sup>c\\<^sup>e  @@ [[ L_bitvec v2 ]\\<^sup>v]\\<^sup>c\\<^sup>e ]\\<^sup>c\\<^sup>e  \\<rbrakk> ~ s2)  \\<longrightarrow>\n           s1 = s2)\\<close> \n  proof(rule+)\n    fix i s1 s2 \n    assume as: \"(\\<Pi> ; \\<B>  \\<turnstile>\\<^sub>w\\<^sub>f GNil)  \\<and>  (\\<Pi> ; GNil \\<turnstile> i) \\<and> (i \\<lbrakk> [ [ L_bitvec (v1 @ v2) ]\\<^sup>v ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ s1)  \\<and> \n            (i \\<lbrakk> [[[ L_bitvec v1 ]\\<^sup>v]\\<^sup>c\\<^sup>e @@ [[ L_bitvec v2 ]\\<^sup>v]\\<^sup>c\\<^sup>e]\\<^sup>c\\<^sup>e  \\<rbrakk> ~ s2) \"\n\n    hence *: \"i \\<lbrakk> [[[ L_bitvec v1 ]\\<^sup>v]\\<^sup>c\\<^sup>e @@ [[ L_bitvec v2 ]\\<^sup>v]\\<^sup>c\\<^sup>e]\\<^sup>c\\<^sup>e  \\<rbrakk> ~ s2\"  by auto\n    obtain bv1 bv2 where s2:\"s2 = SBitvec (bv1 @ bv2) \\<and> i \\<lbrakk> [ L_bitvec v1 ]\\<^sup>v \\<rbrakk> ~ SBitvec bv1  \\<and> (i \\<lbrakk> [ L_bitvec v2 ]\\<^sup>v \\<rbrakk> ~ SBitvec bv2)\" \n      using eval_e_elims(7)[OF *] eval_e_elims(1) by metis\n    hence \"v1 = bv1 \\<and> v2 = bv2\" using eval_v_elims(1) eval_l.simps(5) by force\n    moreover then have \"s1 = SBitvec  (bv1 @ bv2)\" using s2 using eval_v_elims(1) eval_l.simps(5) \n      by (metis as eval_e_elims(1))\n\n    then show \"s1 = s2\" using s2 by auto\n  qed  \n\n  show \\<open>  \\<Pi> ; \\<B> ; GNil \\<turnstile>\\<^sub>w\\<^sub>f [ [ L_bitvec (v1 @ v2) ]\\<^sup>v ]\\<^sup>c\\<^sup>e : B_bitvec \\<close> \n    by (metis assms base_for_lit.simps(5) wfG_nilI wfV_litI wfV_wfCE)\n  show \\<open>  \\<Pi> ; \\<B> ; GNil \\<turnstile>\\<^sub>w\\<^sub>f [[[ L_bitvec v1 ]\\<^sup>v]\\<^sup>c\\<^sup>e @@ [[ L_bitvec v2 ]\\<^sup>v]\\<^sup>c\\<^sup>e]\\<^sup>c\\<^sup>e  : B_bitvec \\<close> \n    by (metis assms base_for_lit.simps(5) wfCE_concatI wfG_nilI wfV_litI wfCE_valI)\nqed\n\nlemma valid_ce_eq:\n  fixes ce::ce\n  assumes  \"\\<Theta> ; \\<B> ; \\<Gamma> \\<turnstile>\\<^sub>w\\<^sub>f ce : b\"\n  shows \\<open>\\<Theta> ; \\<B> ; \\<Gamma>  \\<Turnstile> ce  ==  ce \\<close>\n  unfolding valid.simps proof \n  show \\<open> \\<Theta> ; \\<B> ; \\<Gamma>   \\<turnstile>\\<^sub>w\\<^sub>f ce  ==  ce  \\<close> using assms wfC_eqI by auto\n  show \\<open>\\<forall>i.  \\<Theta> ; \\<Gamma> \\<turnstile> i \\<and>  i \\<Turnstile> \\<Gamma>  \\<longrightarrow>  i \\<Turnstile> ce  ==  ce  \\<close> proof(rule+)\n    fix i\n    assume \"\\<Theta> ; \\<Gamma> \\<turnstile> i \\<and>  i \\<Turnstile> \\<Gamma>\"\n    then obtain s where \"i\\<lbrakk> ce \\<rbrakk> ~ s\" using assms eval_e_exist by metis\n    then show \"i \\<lbrakk> ce  ==  ce  \\<rbrakk> ~ True \" using eval_c_eqI by metis\n  qed\nqed\n\nlemma valid_eq_imp:\n  fixes c1::c and c2::c\n  assumes \" \\<Theta> ; \\<B> ; (x, b, c2) #\\<^sub>\\<Gamma> \\<Gamma>  \\<turnstile>\\<^sub>w\\<^sub>f c1 IMP c2\"\n  shows  \" \\<Theta> ; \\<B> ; (x, b, c2) #\\<^sub>\\<Gamma> \\<Gamma>  \\<Turnstile>  c1   IMP  c2 \"\nproof -\n  have \"\\<forall>i.  (\\<Theta> ; (x, b, c2) #\\<^sub>\\<Gamma> \\<Gamma> \\<turnstile> i \\<and>  i \\<Turnstile> (x, b, c2) #\\<^sub>\\<Gamma> \\<Gamma>)  \\<longrightarrow>  i \\<Turnstile> ( c1  IMP  c2 )\"\n  proof(rule,rule)\n    fix i\n    assume as:\"\\<Theta> ; (x, b, c2) #\\<^sub>\\<Gamma> \\<Gamma> \\<turnstile> i \\<and>  i \\<Turnstile> (x, b, c2) #\\<^sub>\\<Gamma> \\<Gamma>\"\n\n    have \"\\<Theta> ; \\<B> ; (x, b, c2) #\\<^sub>\\<Gamma> \\<Gamma>  \\<turnstile>\\<^sub>w\\<^sub>f c1\" using wfC_elims assms by metis\n\n    then obtain sc where \"i \\<lbrakk> c1 \\<rbrakk> ~ sc\" using eval_c_exist assms as by metis\n    moreover have  \"i \\<lbrakk> c2 \\<rbrakk> ~ True\" using as is_satis_g.simps is_satis.simps by auto\n\n    ultimately have \"i \\<lbrakk> c1  IMP  c2 \\<rbrakk> ~ True\" using eval_c_impI by metis\n\n    thus  \"i \\<Turnstile> c1  IMP  c2\" using is_satis.simps by auto\n  qed\n  thus ?thesis using assms by auto\nqed\n\nlemma valid_range:\n  assumes \"0 \\<le> n \\<and> n \\<le> m\" and \"\\<turnstile>\\<^sub>w\\<^sub>f \\<Theta>\"\n  shows \"\\<Theta> ; {||} ; (x, B_int  , (C_eq (CE_val (V_var x)) (CE_val (V_lit (L_num n))))) #\\<^sub>\\<Gamma>  GNil \\<Turnstile> \n                              (C_eq (CE_op LEq (CE_val (V_var x)) (CE_val (V_lit (L_num m))))  [[ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e) AND\n                             (C_eq (CE_op LEq (CE_val (V_lit (L_num 0))) (CE_val (V_var x)))  [[ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e)\"\n    (is \"\\<Theta> ; {||} ; ?G \\<Turnstile> ?c1 AND ?c2\")\nproof(rule validI)\n  have wfg: \" \\<Theta> ; {||}  \\<turnstile>\\<^sub>w\\<^sub>f (x, B_int, [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e  ==  [ [ L_num n ]\\<^sup>v ]\\<^sup>c\\<^sup>e ) #\\<^sub>\\<Gamma> GNil \" \n    using assms base_for_lit.simps wfG_nilI wfV_litI fresh_GNil wfB_intI wfC_v_eq wfG_cons1I wfG_cons2I by metis\n\n  show \"\\<Theta> ; {||} ; ?G  \\<turnstile>\\<^sub>w\\<^sub>f ?c1 AND ?c2\" \n    using wfC_conjI wfC_eqI wfCE_leqI wfCE_valI wfV_varI wfg lookup.simps base_for_lit.simps wfV_litI wfB_intI wfB_boolI \n    by metis\n\n  show \"\\<forall>i.  \\<Theta> ; ?G \\<turnstile> i \\<and>  i \\<Turnstile> ?G  \\<longrightarrow> i \\<Turnstile> ?c1 AND ?c2\" proof(rule,rule)\n    fix i\n    assume a:\"\\<Theta> ; ?G \\<turnstile> i \\<and>  i \\<Turnstile> ?G\"\n    hence *:\"i \\<lbrakk> V_var x \\<rbrakk> ~ SNum n\" \n    proof - \n      obtain sv where sv: \"i x = Some sv \\<and> \\<Theta> \\<turnstile> sv : B_int\" using a wfI_def by force\n      have \"i \\<lbrakk>  (C_eq (CE_val (V_var x)) (CE_val (V_lit (L_num n)))) \\<rbrakk> ~ True\" \n        using a is_satis_g.simps \n        using is_satis.cases by blast\n      hence \"i x = Some(SNum n)\" using sv \n        by (metis eval_c_elims(7) eval_e_elims(1) eval_l.simps(3) eval_v_elims(1) eval_v_elims(2))\n      thus ?thesis using eval_v_varI by auto\n    qed\n\n    show \"i \\<Turnstile> ?c1 AND ?c2\" \n    proof - \n      have \"i \\<lbrakk> ?c1 \\<rbrakk> ~ True\" \n      proof -\n        have \"i \\<lbrakk> [ leq [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e [ [ L_num m ]\\<^sup>v ]\\<^sup>c\\<^sup>e ]\\<^sup>c\\<^sup>e\\<rbrakk> ~ SBool True\" \n          using eval_e_leqI assms eval_v_litI eval_l.simps * \n          by (metis (full_types) eval_e_valI)\n        moreover have \"i \\<lbrakk>  [ [ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e  \\<rbrakk> ~ SBool True\" \n          using eval_v_litI eval_e_valI eval_l.simps by metis\n        ultimately show ?thesis using  eval_c_eqI by metis\n      qed\n\n      moreover have \"i \\<lbrakk> ?c2 \\<rbrakk> ~ True\" \n      proof -\n        have \"i \\<lbrakk> [ leq [ [ L_num 0 ]\\<^sup>v ]\\<^sup>c\\<^sup>e [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ SBool True\"\n          using eval_e_leqI assms eval_v_litI eval_l.simps * \n          by (metis (full_types) eval_e_valI)\n        moreover have \"i \\<lbrakk>  [ [ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e  \\<rbrakk> ~ SBool True\" \n          using eval_v_litI eval_e_valI eval_l.simps by metis\n        ultimately show ?thesis using  eval_c_eqI by metis\n      qed      \n      ultimately show ?thesis using eval_c_conjI is_satis.simps by metis\n    qed\n  qed\nqed\n\nlemma valid_range_length:\n  fixes \\<Gamma>::\\<Gamma>\n  assumes \"0 \\<le> n \\<and> n \\<le> int (length v)\" and \" \\<Theta> ; {||} \\<turnstile>\\<^sub>w\\<^sub>f \\<Gamma>\" and \"atom x \\<sharp> \\<Gamma>\"\n  shows \"\\<Theta> ; {||} ; (x, B_int  , (C_eq (CE_val (V_var x)) (CE_val (V_lit (L_num n))))) #\\<^sub>\\<Gamma>  \\<Gamma> \\<Turnstile> \n                     (C_eq (CE_op LEq (CE_val (V_lit (L_num 0))) (CE_val (V_var x)))  [[ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e) AND  \n                     (C_eq (CE_op LEq (CE_val (V_var x)) ([| [ [ L_bitvec v ]\\<^sup>v ]\\<^sup>c\\<^sup>e |]\\<^sup>c\\<^sup>e ))  [[ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e)\n                            \"\n    (is \"\\<Theta> ; {||} ; ?G \\<Turnstile> ?c1 AND ?c2\")\nproof(rule validI)\n  have wfg: \" \\<Theta> ; {||}  \\<turnstile>\\<^sub>w\\<^sub>f (x, B_int, [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e  ==  [ [ L_num n ]\\<^sup>v ]\\<^sup>c\\<^sup>e ) #\\<^sub>\\<Gamma> \\<Gamma> \" apply(rule  wfG_cons1I)\n    apply simp\n    using assms apply simp+\n    using assms base_for_lit.simps wfG_nilI wfV_litI  wfB_intI wfC_v_eq  wfB_intI wfX_wfY assms by metis+\n\n  show \"\\<Theta> ; {||} ; ?G  \\<turnstile>\\<^sub>w\\<^sub>f ?c1 AND ?c2\" \n    using wfC_conjI wfC_eqI wfCE_leqI wfCE_valI wfV_varI wfg lookup.simps base_for_lit.simps wfV_litI wfB_intI wfB_boolI     \n    by (metis (full_types) wfCE_lenI)\n\n  show \"\\<forall>i.  \\<Theta> ; ?G \\<turnstile> i \\<and>  i \\<Turnstile> ?G  \\<longrightarrow> i \\<Turnstile> ?c1 AND ?c2\" proof(rule,rule)\n    fix i\n    assume a:\"\\<Theta> ; ?G \\<turnstile> i \\<and>  i \\<Turnstile> ?G\"\n    hence *:\"i \\<lbrakk> V_var x \\<rbrakk> ~ SNum n\" \n    proof - \n      obtain sv where sv: \"i x = Some sv \\<and> \\<Theta> \\<turnstile> sv : B_int\" using a wfI_def by force\n      have \"i \\<lbrakk>  (C_eq (CE_val (V_var x)) (CE_val (V_lit (L_num n)))) \\<rbrakk> ~ True\" \n        using a is_satis_g.simps \n        using is_satis.cases by blast\n      hence \"i x = Some(SNum n)\" using sv \n        by (metis eval_c_elims(7) eval_e_elims(1) eval_l.simps(3) eval_v_elims(1) eval_v_elims(2))\n      thus ?thesis using eval_v_varI by auto\n    qed\n\n    show \"i \\<Turnstile> ?c1 AND ?c2\" \n    proof - \n      have \"i \\<lbrakk> ?c2 \\<rbrakk> ~ True\" \n      proof -\n        have \"i \\<lbrakk> [ leq [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e [| [ [ L_bitvec v ]\\<^sup>v ]\\<^sup>c\\<^sup>e |]\\<^sup>c\\<^sup>e ]\\<^sup>c\\<^sup>e\\<rbrakk> ~ SBool True\" \n          using eval_e_leqI assms eval_v_litI eval_l.simps * \n          by (metis (full_types) eval_e_lenI eval_e_valI)        \n        moreover have \"i \\<lbrakk>  [ [ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e  \\<rbrakk> ~ SBool True\" \n          using eval_v_litI eval_e_valI eval_l.simps by metis\n        ultimately show ?thesis using  eval_c_eqI by metis\n      qed\n\n      moreover have \"i \\<lbrakk> ?c1 \\<rbrakk> ~ True\" \n      proof -\n        have \"i \\<lbrakk> [ leq [ [ L_num 0 ]\\<^sup>v ]\\<^sup>c\\<^sup>e [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ SBool True\"\n          using eval_e_leqI assms eval_v_litI eval_l.simps * \n          by (metis (full_types) eval_e_valI)\n        moreover have \"i \\<lbrakk>  [ [ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e  \\<rbrakk> ~ SBool True\" \n          using eval_v_litI eval_e_valI eval_l.simps by metis\n        ultimately show ?thesis using  eval_c_eqI by metis\n      qed      \n      ultimately show ?thesis using eval_c_conjI is_satis.simps by metis\n    qed\n  qed\nqed\n\nlemma valid_range_length_inv_gnil:\n  fixes \\<Gamma>::\\<Gamma>\n  assumes  \"\\<turnstile>\\<^sub>w\\<^sub>f \\<Theta> \"\n    and  \"\\<Theta> ; {||} ; (x, B_int  , (C_eq (CE_val (V_var x)) (CE_val (V_lit (L_num n))))) #\\<^sub>\\<Gamma>  GNil \\<Turnstile> \n                     (C_eq (CE_op LEq (CE_val (V_lit (L_num 0))) (CE_val (V_var x)))  [[ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e) AND  \n                     (C_eq (CE_op LEq (CE_val (V_var x)) ([| [ [ L_bitvec v ]\\<^sup>v ]\\<^sup>c\\<^sup>e |]\\<^sup>c\\<^sup>e ))  [[ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e)\n                            \"\n    (is \"\\<Theta> ; {||} ; ?G \\<Turnstile> ?c1 AND ?c2\")\n  shows \"0 \\<le> n \\<and> n \\<le> int (length v)\" \nproof -\n  have *:\"\\<forall>i.  \\<Theta> ; ?G \\<turnstile> i \\<and>  i \\<Turnstile> ?G  \\<longrightarrow> i \\<Turnstile> ?c1 AND ?c2\" using assms valid.simps by simp\n\n  obtain i where i: \"i x = Some (SNum n)\" by auto\n  have \"\\<Theta> ; ?G \\<turnstile> i \\<and>  i \\<Turnstile> ?G\" proof \n    show  \"\\<Theta> ; ?G \\<turnstile> i\" unfolding wfI_def using wfRCV_BIntI i * by auto\n    have \"i \\<lbrakk> ([ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e  ==  [ [ L_num n ]\\<^sup>v ]\\<^sup>c\\<^sup>e )  \\<rbrakk> ~ True\" \n      using * eval_c.intros(7) eval_e.intros eval_v.intros  eval_l.simps \n      by (metis (full_types) i)\n    thus  \"i \\<Turnstile> ?G\" unfolding  is_satis_g.simps is_satis.simps by auto\n  qed     \n  hence **:\"i \\<Turnstile> ?c1 AND ?c2\" using * by auto\n\n  hence  1: \"i \\<lbrakk> ?c1 \\<rbrakk> ~ True\" using eval_c_elims(3) is_satis.simps \n    by fastforce\n  then obtain sv1 and sv2 where \"(sv1 = sv2) = True \\<and> i \\<lbrakk> [ leq [ [ L_num 0 ]\\<^sup>v ]\\<^sup>c\\<^sup>e [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ sv1 \\<and> i \\<lbrakk> [ [ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e  \\<rbrakk>  ~ sv2\" \n    using eval_c_elims(7) by metis\n  hence \"sv1 = SBool True\" using eval_e_elims eval_v_elims eval_l.simps i by metis\n  obtain n1 and n2 where \"SBool True = SBool (n1 \\<le> n2) \\<and> (i \\<lbrakk> [ [ L_num 0 ]\\<^sup>v ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ SNum n1)  \\<and> (i \\<lbrakk> [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ SNum n2)\" \n    using eval_e_elims(3)[of i \" [ [ L_num 0 ]\\<^sup>v ]\\<^sup>c\\<^sup>e\" \"[ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e \"  \"SBool True\"] \n    using \\<open>(sv1 = sv2) = True \\<and> i \\<lbrakk> [ leq [ [ L_num 0 ]\\<^sup>v ]\\<^sup>c\\<^sup>e [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ sv1 \\<and> i \\<lbrakk> [ [ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ sv2\\<close> \\<open>sv1 = SBool True\\<close> by fastforce\n  moreover hence \"n1 = 0\" and \"n2 = n\"  using eval_e_elims eval_v_elims i \n    apply (metis eval_l.simps(3) rcl_val.eq_iff(2))\n    using eval_e_elims eval_v_elims i \n    by (metis calculation option.inject rcl_val.eq_iff(2))\n  ultimately have  le1: \"0 \\<le> n \" by simp\n\n  hence  2: \"i \\<lbrakk> ?c2 \\<rbrakk> ~ True\" using ** eval_c_elims(3) is_satis.simps \n    by fastforce\n  then obtain sv1 and sv2 where sv: \"(sv1 = sv2) = True \\<and> i \\<lbrakk> [ leq [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e  [| [ [ L_bitvec v ]\\<^sup>v ]\\<^sup>c\\<^sup>e |]\\<^sup>c\\<^sup>e ]\\<^sup>c\\<^sup>e   \\<rbrakk> ~ sv1 \\<and> i \\<lbrakk> [ [ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e  \\<rbrakk>  ~ sv2\" \n    using eval_c_elims(7) by metis\n  hence \"sv1 = SBool True\" using eval_e_elims eval_v_elims eval_l.simps i by metis\n  obtain n1 and n2 where ***:\"SBool True = SBool (n1 \\<le> n2) \\<and>  (i \\<lbrakk> [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ SNum n1) \\<and> (i \\<lbrakk> [| [ [ L_bitvec v ]\\<^sup>v ]\\<^sup>c\\<^sup>e |]\\<^sup>c\\<^sup>e  \\<rbrakk> ~ SNum n2)\" \n    using eval_e_elims(3) \n    using sv \\<open>sv1 = SBool True\\<close> by metis\n  moreover hence \"n1 = n\" using eval_e_elims(1)[of i] eval_v_elims(2)[of i x \"SNum n1\"] i by auto\n  moreover  have \"n2 = int (length v)\"  using eval_e_elims(8) eval_v_elims(1) eval_l.simps i    \n    by (metis \"***\" eval_e_elims(1) rcl_val.eq_iff(1) rcl_val.eq_iff(2))    \n  ultimately have  le2: \"n \\<le> int (length v) \" by simp\n\n  show ?thesis using le1 le2 by auto\nqed\n\nlemma wfI_cons:  \n  fixes i::valuation and \\<Gamma>::\\<Gamma>\n  assumes \"i' \\<Turnstile> \\<Gamma>\" and \"\\<Theta> ; \\<Gamma> \\<turnstile> i'\" and \"i = i' ( x \\<mapsto> s)\" and \"\\<Theta>  \\<turnstile> s : b\" and \"atom x \\<sharp> \\<Gamma>\"\n  shows \"\\<Theta> ; (x,b,c) #\\<^sub>\\<Gamma> \\<Gamma> \\<turnstile> i\"  \n  unfolding wfI_def proof - \n  {  \n    fix x' b' c' \n    assume \"(x',b',c') \\<in> toSet ((x, b, c) #\\<^sub>\\<Gamma> \\<Gamma>)\"\n    then consider \"(x',b',c') = (x,b,c)\" | \"(x',b',c') \\<in> toSet \\<Gamma>\" using toSet.simps by auto\n    then have \"\\<exists>s. Some s = i x' \\<and>  \\<Theta>  \\<turnstile> s : b'\" proof(cases)\n      case 1\n      then show ?thesis using assms by auto\n    next\n      case 2\n      then obtain s where s:\"Some s = i' x' \\<and> \\<Theta>  \\<turnstile> s : b'\" using assms wfI_def by auto\n      moreover have \"x' \\<noteq> x\" using assms 2 fresh_dom_free by auto\n      ultimately have \"Some s = i x'\" using assms by auto\n      then show ?thesis using s  wfI_def by auto\n    qed\n  }\n  thus \"\\<forall>(x, b, c)\\<in>toSet ((x, b, c) #\\<^sub>\\<Gamma> \\<Gamma>). \\<exists>s. Some s = i x \\<and>  \\<Theta>  \\<turnstile> s : b\" by auto\nqed\n\nlemma valid_range_length_inv:\n  fixes \\<Gamma>::\\<Gamma>\n  assumes  \"\\<Theta> ; B \\<turnstile>\\<^sub>w\\<^sub>f \\<Gamma> \" and \"atom x \\<sharp> \\<Gamma>\" and \"\\<exists>i. i \\<Turnstile> \\<Gamma> \\<and> \\<Theta> ; \\<Gamma> \\<turnstile> i\"\n    and  \"\\<Theta> ; B ; (x, B_int  , (C_eq (CE_val (V_var x)) (CE_val (V_lit (L_num n))))) #\\<^sub>\\<Gamma>  \\<Gamma> \\<Turnstile> \n                     (C_eq (CE_op LEq (CE_val (V_lit (L_num 0))) (CE_val (V_var x)))  [[ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e) AND  \n                     (C_eq (CE_op LEq (CE_val (V_var x)) ([| [ [ L_bitvec v ]\\<^sup>v ]\\<^sup>c\\<^sup>e |]\\<^sup>c\\<^sup>e ))  [[ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e)\n                            \"\n    (is \"\\<Theta> ; ?B ; ?G \\<Turnstile> ?c1 AND ?c2\")\n  shows \"0 \\<le> n \\<and> n \\<le> int (length v)\" \nproof -\n  have *:\"\\<forall>i.  \\<Theta> ; ?G \\<turnstile> i \\<and>  i \\<Turnstile> ?G  \\<longrightarrow> i \\<Turnstile> ?c1 AND ?c2\" using assms valid.simps by simp\n\n  obtain i' where idash: \"is_satis_g i' \\<Gamma> \\<and> \\<Theta> ; \\<Gamma> \\<turnstile> i'\" using assms by auto\n  obtain i where i: \"i = i' ( x \\<mapsto> SNum n)\" by auto\n  hence ix: \"i x = Some (SNum n)\" by auto\n  have \"\\<Theta> ; ?G \\<turnstile> i \\<and>  i \\<Turnstile> ?G\" proof \n    show  \"\\<Theta> ; ?G \\<turnstile> i\" using wfI_cons i idash ix wfRCV_BIntI assms by simp\n\n    have **:\"i \\<lbrakk> ([ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e  ==  [ [ L_num n ]\\<^sup>v ]\\<^sup>c\\<^sup>e )  \\<rbrakk> ~ True\" \n      using * eval_c.intros(7) eval_e.intros eval_v.intros  eval_l.simps i \n      by (metis (full_types) ix)\n\n    show  \"i \\<Turnstile> ?G\" unfolding  is_satis_g.simps proof \n      show \\<open> i \\<Turnstile> [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e  ==  [ [ L_num n ]\\<^sup>v ]\\<^sup>c\\<^sup>e  \\<close> using ** is_satis.simps by auto\n      show \\<open> i \\<Turnstile> \\<Gamma> \\<close> using idash i assms is_satis_g_i_upd by metis\n    qed\n  qed     \n  hence **:\"i \\<Turnstile> ?c1 AND ?c2\" using * by auto\n\n  hence  1: \"i \\<lbrakk> ?c1 \\<rbrakk> ~ True\" using eval_c_elims(3) is_satis.simps \n    by fastforce\n  then obtain sv1 and sv2 where \"(sv1 = sv2) = True \\<and> i \\<lbrakk> [ leq [ [ L_num 0 ]\\<^sup>v ]\\<^sup>c\\<^sup>e [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ sv1 \\<and> i \\<lbrakk> [ [ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e  \\<rbrakk>  ~ sv2\" \n    using eval_c_elims(7) by metis\n  hence \"sv1 = SBool True\" using eval_e_elims eval_v_elims eval_l.simps i by metis\n  obtain n1 and n2 where \"SBool True = SBool (n1 \\<le> n2) \\<and> (i \\<lbrakk> [ [ L_num 0 ]\\<^sup>v ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ SNum n1)  \\<and> (i \\<lbrakk> [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ SNum n2)\" \n    using eval_e_elims(3)[of i \" [ [ L_num 0 ]\\<^sup>v ]\\<^sup>c\\<^sup>e\" \"[ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e \"  \"SBool True\"] \n    using \\<open>(sv1 = sv2) = True \\<and> i \\<lbrakk> [ leq [ [ L_num 0 ]\\<^sup>v ]\\<^sup>c\\<^sup>e [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ sv1 \\<and> i \\<lbrakk> [ [ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ sv2\\<close> \\<open>sv1 = SBool True\\<close> by fastforce\n  moreover hence \"n1 = 0\" and \"n2 = n\"  using eval_e_elims eval_v_elims i \n    apply (metis eval_l.simps(3) rcl_val.eq_iff(2))\n    using eval_e_elims eval_v_elims i \n      calculation option.inject rcl_val.eq_iff(2)\n    by (metis ix)\n  ultimately have  le1: \"0 \\<le> n \" by simp\n\n  hence  2: \"i \\<lbrakk> ?c2 \\<rbrakk> ~ True\" using ** eval_c_elims(3) is_satis.simps \n    by fastforce\n  then obtain sv1 and sv2 where sv: \"(sv1 = sv2) = True \\<and> i \\<lbrakk> [ leq [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e  [| [ [ L_bitvec v ]\\<^sup>v ]\\<^sup>c\\<^sup>e |]\\<^sup>c\\<^sup>e ]\\<^sup>c\\<^sup>e   \\<rbrakk> ~ sv1 \\<and> i \\<lbrakk> [ [ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e  \\<rbrakk>  ~ sv2\" \n    using eval_c_elims(7) by metis\n  hence \"sv1 = SBool True\" using eval_e_elims eval_v_elims eval_l.simps i by metis\n  obtain n1 and n2 where ***:\"SBool True = SBool (n1 \\<le> n2) \\<and>  (i \\<lbrakk> [ [ x ]\\<^sup>v ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ SNum n1) \\<and> (i \\<lbrakk> [| [ [ L_bitvec v ]\\<^sup>v ]\\<^sup>c\\<^sup>e |]\\<^sup>c\\<^sup>e  \\<rbrakk> ~ SNum n2)\" \n    using eval_e_elims(3) \n    using sv \\<open>sv1 = SBool True\\<close> by metis\n  moreover hence \"n1 = n\" using eval_e_elims(1)[of i] eval_v_elims(2)[of i x \"SNum n1\"] i by auto\n  moreover  have \"n2 = int (length v)\"  using eval_e_elims(8) eval_v_elims(1) eval_l.simps i    \n    by (metis \"***\" eval_e_elims(1) rcl_val.eq_iff(1) rcl_val.eq_iff(2))    \n  ultimately have  le2: \"n \\<le> int (length v) \" by simp\n\n  show ?thesis using le1 le2 by auto\nqed\n\nlemma eval_c_conj2I[intro]: \n  assumes \"i \\<lbrakk> c1 \\<rbrakk> ~ True\" and \"i \\<lbrakk> c2 \\<rbrakk> ~ True\"\n  shows \"i \\<lbrakk> (C_conj c1 c2) \\<rbrakk> ~  True\"\n  using assms eval_c_conjI by metis\n\nlemma valid_split:\n  assumes \"split n v (v1,v2)\" and \"\\<turnstile>\\<^sub>w\\<^sub>f \\<Theta>\"\n  shows \"\\<Theta> ; {||} ; (z , [B_bitvec , B_bitvec ]\\<^sup>b ,  [ [ z ]\\<^sup>v ]\\<^sup>c\\<^sup>e  ==  [ [ [ L_bitvec  v1 ]\\<^sup>v , [ L_bitvec  v2 ]\\<^sup>v ]\\<^sup>v ]\\<^sup>c\\<^sup>e) #\\<^sub>\\<Gamma> GNil  \n\\<Turnstile>  ([ [ L_bitvec v ]\\<^sup>v ]\\<^sup>c\\<^sup>e  ==  [ [#1[ [ z ]\\<^sup>v ]\\<^sup>c\\<^sup>e]\\<^sup>c\\<^sup>e @@ [#2[ [ z ]\\<^sup>v ]\\<^sup>c\\<^sup>e]\\<^sup>c\\<^sup>e ]\\<^sup>c\\<^sup>e)   AND  ([| [#1[ [ z ]\\<^sup>v ]\\<^sup>c\\<^sup>e]\\<^sup>c\\<^sup>e |]\\<^sup>c\\<^sup>e  ==  [ [ L_num n ]\\<^sup>v ]\\<^sup>c\\<^sup>e)\"\n    (is \"\\<Theta> ;  {||} ;  ?G \\<Turnstile> ?c1 AND ?c2\")\n  unfolding valid.simps proof\n\n  have wfg: \" \\<Theta> ; {||}  \\<turnstile>\\<^sub>w\\<^sub>f (z, [B_bitvec , B_bitvec ]\\<^sup>b ,  [ [ z ]\\<^sup>v ]\\<^sup>c\\<^sup>e  ==  [ [ [ L_bitvec  v1 ]\\<^sup>v , [ L_bitvec  v2 ]\\<^sup>v ]\\<^sup>v ]\\<^sup>c\\<^sup>e) #\\<^sub>\\<Gamma> GNil\" \n    using wf_intros assms base_for_lit.simps  fresh_GNil wfC_v_eq  wfG_intros2 by metis   \n\n  show \"\\<Theta> ; {||} ; ?G  \\<turnstile>\\<^sub>w\\<^sub>f ?c1 AND ?c2\" \n    apply(rule wfC_conjI)\n    apply(rule wfC_eqI)\n    apply(rule wfCE_valI)\n    apply(rule wfV_litI)\n    using wf_intros wfg lookup.simps base_for_lit.simps wfC_v_eq \n    apply (metis )+\n    done\n\n  have len:\"int (length v1) = n\" using assms split_length by auto\n\n  show \"\\<forall>i. \\<Theta> ; ?G \\<turnstile> i \\<and> i \\<Turnstile> ?G \\<longrightarrow> i \\<Turnstile> (?c1 AND ?c2)\" \n  proof(rule,rule)\n    fix i\n    assume a:\"\\<Theta> ; ?G \\<turnstile> i \\<and> i \\<Turnstile> ?G\"\n    hence \"i \\<lbrakk> [ [ z ]\\<^sup>v ]\\<^sup>c\\<^sup>e  ==  [ [ [ L_bitvec v1 ]\\<^sup>v , [ L_bitvec v2 ]\\<^sup>v ]\\<^sup>v ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ True\" \n      using is_satis_g.simps is_satis.simps by simp\n    then obtain sv where \"i \\<lbrakk> [ [ z ]\\<^sup>v ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ sv \\<and> i \\<lbrakk>  [ [ [ L_bitvec v1 ]\\<^sup>v , [ L_bitvec v2 ]\\<^sup>v ]\\<^sup>v ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ sv\" \n      using eval_c_elims by metis\n    hence \"i  \\<lbrakk> [ [ z ]\\<^sup>v ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ (SPair (SBitvec v1) (SBitvec v2))\" using eval_c_eqI eval_v.intros eval_l.simps \n      by (metis eval_e_elims(1) eval_v_uniqueness)\n    hence b:\"i z = Some (SPair (SBitvec v1) (SBitvec v2))\" using a eval_e_elims eval_v_elims by metis\n\n    have v1: \"i \\<lbrakk> [#1[ [ z ]\\<^sup>v ]\\<^sup>c\\<^sup>e]\\<^sup>c\\<^sup>e \\<rbrakk> ~ SBitvec v1 \" \n      using eval_e_fstI eval_e_valI eval_v_varI b by metis\n    have v2: \"i \\<lbrakk> [#2[ [ z ]\\<^sup>v ]\\<^sup>c\\<^sup>e]\\<^sup>c\\<^sup>e \\<rbrakk> ~ SBitvec v2\" \n      using eval_e_sndI eval_e_valI eval_v_varI b by metis\n\n    have \"i \\<lbrakk> [ [ L_bitvec v ]\\<^sup>v ]\\<^sup>c\\<^sup>e \\<rbrakk> ~ SBitvec v\" using eval_e.intros eval_v.intros eval_l.simps by metis\n    moreover have \"i \\<lbrakk>  [ [#1[ [ z ]\\<^sup>v ]\\<^sup>c\\<^sup>e]\\<^sup>c\\<^sup>e @@ [#2[ [ z ]\\<^sup>v ]\\<^sup>c\\<^sup>e]\\<^sup>c\\<^sup>e ]\\<^sup>c\\<^sup>e  \\<rbrakk> ~ SBitvec v\" \n      using assms split_concat v1 v2 eval_e_concatI by metis\n    moreover have \"i \\<lbrakk>  [| [#1[ [ z ]\\<^sup>v ]\\<^sup>c\\<^sup>e]\\<^sup>c\\<^sup>e |]\\<^sup>c\\<^sup>e \\<rbrakk> ~ SNum (int (length v1))\" \n      using v1 eval_e_lenI by auto\n    moreover have \"i \\<lbrakk>  [ [ L_num n ]\\<^sup>v ]\\<^sup>c\\<^sup>e  \\<rbrakk> ~ SNum n\" using eval_e.intros eval_v.intros eval_l.simps by metis\n    ultimately show  \"i \\<Turnstile> ?c1 AND ?c2\" using is_satis.intros eval_c_conj2I eval_c_eqI len by metis\n  qed\nqed\n\n\nlemma is_satis_eq:\n  assumes \"wfI \\<Theta> G i\" and \"wfCE \\<Theta> \\<B> G e b\"\n  shows \"is_satis i (e == e)\"\nproof(rule)\n  obtain s where \"eval_e i e s\" using eval_e_exist assms by metis\n  thus \"eval_c i (e  ==  e ) True\" using eval_c_eqI by metis\nqed\n\nlemma is_satis_g_i_upd2:\n  assumes \"eval_v i v s\" and \"is_satis ((i ( x \\<mapsto> s))) c0\" and \"atom x \\<sharp> G\" and \"wfG \\<Theta> \\<B> (G3@((x,b,c0)#\\<^sub>\\<Gamma>G))\" and \"wfV \\<Theta> \\<B> G v b\" and \"wfI \\<Theta> (G3[x::=v]\\<^sub>\\<Gamma>\\<^sub>v@G) i\" \n    and  \"is_satis_g i (G3[x::=v]\\<^sub>\\<Gamma>\\<^sub>v@G)\"\n  shows \"is_satis_g (i ( x \\<mapsto> s)) (G3@((x,b,c0)#\\<^sub>\\<Gamma>G))\"\n  using assms proof(induct G3 rule: \\<Gamma>_induct)\n  case GNil\n  hence \"is_satis_g (i(x \\<mapsto> s)) G\" using is_satis_g_i_upd by auto\n  then show ?case using GNil using is_satis_g.simps append_g.simps by metis\nnext\n  case (GCons x' b' c' \\<Gamma>')\n  hence \"x\\<noteq>x'\" using wfG_cons_append  by metis\n  hence \"is_satis_g i (((x', b', c'[x::=v]\\<^sub>c\\<^sub>v) #\\<^sub>\\<Gamma> (\\<Gamma>'[x::=v]\\<^sub>\\<Gamma>\\<^sub>v) @ G))\" using subst_gv.simps GCons by auto\n  hence *:\"is_satis i c'[x::=v]\\<^sub>c\\<^sub>v \\<and> is_satis_g i ((\\<Gamma>'[x::=v]\\<^sub>\\<Gamma>\\<^sub>v) @ G)\" using subst_gv.simps by auto\n\n  have \"is_satis_g (i(x \\<mapsto> s)) ((x', b', c') #\\<^sub>\\<Gamma> (\\<Gamma>'@  (x, b, c0) #\\<^sub>\\<Gamma> G))\" proof(subst is_satis_g.simps,rule)\n    show \"is_satis (i(x \\<mapsto> s)) c'\" proof(subst subst_c_satis_full[symmetric])\n      show \\<open>eval_v i v s\\<close> using GCons by auto\n      show \\<open> \\<Theta> ; \\<B> ; ((x', b', c') #\\<^sub>\\<Gamma>\\<Gamma>')@(x, b, c0) #\\<^sub>\\<Gamma> G \\<turnstile>\\<^sub>w\\<^sub>f c' \\<close> using GCons wfC_refl by auto\n      show \\<open>wfI \\<Theta> ((((x', b', c') #\\<^sub>\\<Gamma> \\<Gamma>')[x::=v]\\<^sub>\\<Gamma>\\<^sub>v) @ G) i\\<close> using GCons  by auto\n      show \\<open> \\<Theta> ; \\<B> ; G \\<turnstile>\\<^sub>w\\<^sub>f v : b \\<close> using GCons by auto\n      show \\<open>is_satis i c'[x::=v]\\<^sub>c\\<^sub>v\\<close> using * by auto\n    qed\n    show \"is_satis_g (i(x \\<mapsto> s)) (\\<Gamma>' @ (x, b, c0) #\\<^sub>\\<Gamma> G)\" proof(rule  GCons(1))\n      show \\<open>eval_v i v s\\<close> using GCons by auto\n      show \\<open>is_satis (i(x \\<mapsto> s)) c0\\<close> using GCons by metis\n      show \\<open>atom x \\<sharp> G\\<close> using GCons by auto\n      show \\<open> \\<Theta> ; \\<B>\\<turnstile>\\<^sub>w\\<^sub>f \\<Gamma>' @ (x, b, c0) #\\<^sub>\\<Gamma> G \\<close> using GCons wfG_elims append_g.simps by metis\n      show \\<open>is_satis_g i (\\<Gamma>'[x::=v]\\<^sub>\\<Gamma>\\<^sub>v @ G)\\<close> using * by auto\n      show \"wfI \\<Theta> (\\<Gamma>'[x::=v]\\<^sub>\\<Gamma>\\<^sub>v @ G) i\" using GCons wfI_def subst_g_assoc_cons \\<open>x\\<noteq>x'\\<close> by auto\n      show \"\\<Theta> ; \\<B> ; G \\<turnstile>\\<^sub>w\\<^sub>f v : b \"  using GCons by auto\n    qed\n  qed\n  moreover have \"((x', b', c') #\\<^sub>\\<Gamma> \\<Gamma>' @ (x, b, c0) #\\<^sub>\\<Gamma> G) = (((x', b', c') #\\<^sub>\\<Gamma> \\<Gamma>') @ (x, b, c0) #\\<^sub>\\<Gamma> G)\" by auto\n  ultimately show ?case using GCons by metis\nqed\n\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/MiniSail/RCLogicL.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5660185498374789, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.29626562686036534}}
{"text": "theory WorldSatisfaction\nimports Misc Namespace View\nbegin\n\nsubsection \\<open>Invariants\\<close>\n\nsubsubsection \\<open>World satisfaction\\<close>\ntext \\<open> \n  Impredicative invariants are formalized as propositions which are managed by the so called\n  World Satisfaction. It holds a map of named invariants and keeps track which of them are opened \n  (i.e. enabled/can be used thread-locally and might not hold) and which are closed \n  (i.e. disabled/hold for all threads).\n\\<close>\ntext \\<open>Arbitrary but unique names for singleton cameras\\<close>\ndefinition \"invariant_name :: gname \\<equiv> 1\" \ndefinition \"enabled_name :: gname \\<equiv> 2\" \ndefinition \"disabled_name :: gname \\<equiv> 3\"\n\ntype_synonym inv = \"(name, pre_iprop later) map_view \\<times> name dset \\<times> name dfset\"\n\ncontext \nfixes get_inv :: \"gname \\<Rightarrow> 'res::ucamera \\<Rightarrow> inv option\"\n  and put_inv\nassumes inv_inG: \"inG get_inv put_inv\"\nbegin\n\ndefinition own_inv :: \"gname \\<Rightarrow> inv \\<Rightarrow> 'res upred_f\" (\"Own\\<^sub>i _ _\") where\n  \"own_inv \\<gamma> i = own put_inv \\<gamma> i\"\n\ntext \\<open>Allocate new invariant map\\<close>\ndefinition ownI :: \"name \\<Rightarrow> 'res upred_f \\<Rightarrow> 'res upred_f\" where\n  \"ownI \\<iota> P = Own\\<^sub>i invariant_name (map_view_frag \\<iota> DfracDiscarded (Next (pre P)),\\<epsilon>,\\<epsilon>)\"\n\ndefinition inv_raw :: \"namespace \\<Rightarrow> 'res upred_f \\<Rightarrow>  'res upred_f\" where\n  \"inv_raw N P \\<equiv> \\<exists>\\<^sub>u \\<iota>. ((\\<upharpoonleft>(\\<iota>\\<in>\\<^sub>d dnames N)) \\<and>\\<^sub>u ownI \\<iota> P)\"\n\ntext \\<open>Allocate new enabled invariant map\\<close>\ndefinition ownE :: \"name set \\<Rightarrow> 'res upred_f\" where\n  \"ownE E = Own\\<^sub>i enabled_name (\\<epsilon>,DSet E,\\<epsilon>)\"\n\ntext \\<open>Allocate new disabled invariant map\\<close>\ndefinition ownD :: \"name fset \\<Rightarrow> 'res upred_f\" where\n  \"ownD D = Own\\<^sub>i disabled_name (\\<epsilon>,\\<epsilon>,DFSet D)\"\n  \ndefinition lift_inv_fmap :: \"(name,'res upred_f) fmap \\<Rightarrow> (name, pre_iprop later) fmap\" where\n  \"lift_inv_fmap m = Abs_fmap (map_option (Next \\<circ> pre) \\<circ> (fmlookup m))\"\n\nlemma lift_inf_fmap_finite: \"(map_option (Next \\<circ> pre) \\<circ> (fmlookup m)) \\<in> {m. finite (dom m)}\"\n  by auto\n\ntext \\<open>World satisfaction, i.e. the invariant that holds all invariants\\<close>\ndefinition wsat :: \"'res upred_f\" where\n  \"wsat \\<equiv> \\<exists>\\<^sub>u (I::(name,'res upred_f) fmap).\n    ((Own\\<^sub>i invariant_name (map_view_auth (DfracOwn 1) (lift_inv_fmap I),\\<epsilon>,\\<epsilon>))\n    \\<^emph> (sep_map_fmdom (\\<lambda>\\<iota>. (\\<triangleright>(the (fmlookup I \\<iota>))) \\<^emph> ownD {|\\<iota>|} \\<or>\\<^sub>u (ownE {\\<iota>})) I)\n  )\"\n\nlemma own_inv_ne [upred_ne_rule]: \"\\<lbrakk>n_equiv n \\<gamma>1 \\<gamma>2; n_equiv n i j\\<rbrakk> \\<Longrightarrow> n_equiv n (Own\\<^sub>i \\<gamma>1 i) (Own\\<^sub>i \\<gamma>2 j)\"\n  apply (auto simp: own_inv_def n_equiv_fun_def ofe_refl n_equiv_option_def intro!: upred_ne_rule)\n  using inG.own_ne inv_inG by blast\n\nlemma ownI_ne [upred_ne_rule]: \"\\<lbrakk>n_equiv n n1 n2; n_equiv n P Q\\<rbrakk> \\<Longrightarrow> n_equiv n (ownI n1 P) (ownI n2 Q)\"\napply (auto simp: ownI_def ofe_refl n_equiv_map_view_def map_view_auth_proj_def map_view_frag_proj_def \n  map_view_frag_def view_frag_def n_equiv_fun_def n_equiv_option_def n_equiv_ag.rep_eq to_ag.rep_eq \n  n_equiv_later_def intro!: upred_ne_rule split: map_view.splits)\n  using non_expansiveE[OF ipropIso.to_ne] diff_le_self ofe_mono by blast\n\nlemma inv_raw_ne [upred_ne_rule]: \"\\<lbrakk>n_equiv n N M; n_equiv n P Q\\<rbrakk> \\<Longrightarrow> n_equiv n (inv_raw N P) (inv_raw M Q)\"\n  by (auto simp: inv_raw_def intro!: upred_ne_rule)\n\nlemma inv_ownE_ne [upred_ne_rule]: \"n_equiv n N M \\<Longrightarrow> n_equiv n (ownE N) (ownE M)\"\n  by (auto simp: ownE_def ofe_refl n_equiv_dset_def d_equiv intro!: upred_ne_rule)\n\nlemma inv_ownD_ne [upred_ne_rule]: \"n_equiv n N M \\<Longrightarrow> n_equiv n (ownD N) (ownD M)\"\n  by (auto simp: ownD_def ofe_refl n_equiv_dfset_def d_equiv intro!: upred_ne_rule)\n  \nlemma pcore_id_inv: \"pcore_id_pred (map_view_frag \\<iota> DfracDiscarded (Next (pre P)), \\<epsilon>, \\<epsilon>)\"\n  unfolding prod_pcore_id_pred apply (simp add: \\<epsilon>_pcore_id_def)\n  by (meson discarded_core_id pcore_id_frag)\n\nlemma persistent_ownI [pers_rule,log_prog_rule]: \"persistent (ownI \\<iota> P)\"\nunfolding ownI_def own_inv_def by (rule persistent_core_own2[OF inv_inG, OF pcore_id_inv])\n\nlemma persistent_inv_raw [pers_rule,log_prog_rule]: \"persistent (inv_raw N P)\"\n  unfolding inv_raw_def\n  apply (rule persistent_exists)\n  apply (rule persistent_conj)\n  apply (rule persistent_pure)\n  by (rule persistent_ownI)\n\nlemma put_inv_valid: \"\\<lbrakk>valid mv; valid e; valid d\\<rbrakk> \\<Longrightarrow> valid (put_inv \\<gamma> (mv,e,d))\"\n  by (auto simp: valid_def inG.put_n_valid[OF inv_inG] valid_raw_prod_def sprop_conj.rep_eq)\n\nlemma ownE_singleton_twice: \"ownE {i} \\<^emph> ownE {i} \\<turnstile> \\<upharpoonleft>False\"\n  unfolding ownE_def own_inv_def\n  apply (rule upred_entails_trans[OF upred_entail_eqR[OF inG.own_op[OF inv_inG]]])\n  apply (rule upred_entails_trans[OF inG.own_valid[OF inv_inG]])\n  apply (simp add: op_prod_def \\<epsilon>_left_id op_dset_def)\n  apply transfer\n  by (auto simp: prod_n_valid_def \\<epsilon>_n_valid valid_raw_dset_def)  \n  \nlemma ownD_singleton_twice: \"ownD {|i|} \\<^emph> ownD {|i|} \\<turnstile> \\<upharpoonleft>False\"\n  unfolding ownD_def own_inv_def inG.own_def[OF inv_inG]\n  apply (auto simp: op_prod_def \\<epsilon>_left_id op_dfset_def inG.put_op[OF inv_inG, symmetric]\n    intro!: upred_entails_trans[OF upred_entail_eqR[OF upred_own_op]] upred_entails_trans[OF upred_own_valid])\n  apply (rule upred_entails_trans[OF upred_entail_eqL[OF inG.valid_get[OF inv_inG]]])\n  apply transfer\n  by (simp add: prod_n_valid_def \\<epsilon>_n_valid valid_raw_dfset_def)\n  \nlemma ownE_op: \"E1 \\<inter> E2 = {} \\<Longrightarrow> ownE (E1 \\<union> E2) \\<stileturn>\\<turnstile> ownE E1 \\<^emph> ownE E2\"\nproof -\n  assume \"E1 \\<inter> E2 = {}\"\n  then have un_op:\"DSet (E1 \\<union> E2) = DSet E1 \\<cdot> DSet E2\" unfolding op_dset_def by simp\n  from inG.own_op[OF inv_inG, of \"enabled_name\" \"(\\<epsilon>,DSet E1,\\<epsilon>)\" \"(\\<epsilon>,DSet E2,\\<epsilon>)\"]\n  show ?thesis by (auto simp: ownE_def own_inv_def un_op op_prod_def \\<epsilon>_left_id)\nqed\n\nlemma ownE_op': \"(\\<upharpoonleft>(E1 \\<inter> E2 = {})) \\<and>\\<^sub>u ownE (E1 \\<union> E2) \\<stileturn>\\<turnstile> ownE E1 \\<^emph> ownE E2\"\n  apply (auto simp: upred_entail_eq_def)\n  apply (subst upred_conj_comm)\n  apply (auto intro!: upred_pure_impl' upred_entail_eqL[OF ownE_op])\n  apply (auto simp: ownE_def own_inv_def op_prod_def \\<epsilon>_left_id inG.own_def[OF inv_inG]\n    inG.put_op[OF inv_inG,symmetric] intro!: upred_entails_trans[OF upred_entail_eqR[OF upred_own_op]])\n  apply (auto simp: upred_entails.rep_eq upred_own.rep_eq upred_pure.rep_eq upred_conj.rep_eq)\n  sorry\n  \nlemma ownE_op_minus: \"E1 \\<subseteq> E2 \\<Longrightarrow> ownE (E1 \\<union> (E2-E1)) \\<stileturn>\\<turnstile> ownE E1 \\<^emph> ownE (E2-E1)\"\nproof -\n  assume \"E1 \\<subseteq> E2\"\n  then have \"E1 \\<inter> (E2-E1) = {}\" by simp\n  from ownE_op[OF this] show ?thesis .\nqed\n  \nlemma auth_map_both_validI: \n  \"\\<V>(put_inv \\<gamma> (map_view_auth (DfracOwn 1) m,\\<epsilon>,\\<epsilon>) \\<cdot> put_inv \\<gamma> (map_view_frag k dq v,\\<epsilon>,\\<epsilon>)) \\<turnstile>\n    (fmlookup m k =\\<^sub>u Some v) \\<and>\\<^sub>u \\<upharpoonleft>(valid dq)\"\nunfolding inG.put_op[OF inv_inG,symmetric]\napply (rule upred_entails_trans[OF upred_entail_eqL[OF inG.valid_get[OF inv_inG]]])\nunfolding op_prod_def\napply (simp add: \\<epsilon>_left_id auth_comb_opL op_prod_def split: prod.splits)\napply transfer'\napply (simp add: prod_n_valid_def \\<epsilon>_n_valid valid_raw_option_def \\<epsilon>_option_def)\nusing map_view_both_valid by metis\n\nlemma invariant_lookup: \n  \"Own\\<^sub>i invariant_name (map_view_auth (DfracOwn 1) (lift_inv_fmap I),\\<epsilon>,\\<epsilon>) \\<^emph> ownI \\<iota> P \\<turnstile> \n  (\\<exists>\\<^sub>u Q. \\<upharpoonleft>(fmlookup I \\<iota> = Some Q) \\<^emph> \\<triangleright>(Q=\\<^sub>uP))\"\n  unfolding ownI_def own_inv_def inG.own_def[OF inv_inG]\n  apply (rule upred_entails_trans[OF upred_entail_eqR[OF upred_own_op]])\n  apply (rule upred_entails_trans[OF upred_own_valid])\n  apply (rule upred_entails_trans[OF auth_map_both_validI])\n  apply (auto simp: lift_inv_fmap_def valid_raw_dfrac_def valid_def n_equiv_option_def \n     Abs_fmap_inverse[OF lift_inf_fmap_finite] emp_rule)\n  apply (rule upred_entails_trans[OF upred_entail_eqL[OF option_equivI]])\n  apply (auto simp: upred_exists_eq_sep' split: option.splits)\n  apply (rule upred_entails_trans[OF upred_entail_eqL[OF later_equivI]])\n  apply (rule upred_later_mono)\n  apply transfer\n  by (auto simp: ipropIso.to_equiv)\n\nlemma lookup_pers [pers_rule,log_prog_rule]: \"persistent (\\<exists>\\<^sub>u Q. \\<upharpoonleft>(fmlookup I \\<iota> = Some Q) \\<^emph> \\<triangleright>(Q=\\<^sub>uP))\"\n  by pers_solver\n\nlemma ownI_open: \"wsat \\<^emph> ownI i P \\<^emph> ownE {i} \\<turnstile> wsat \\<^emph> (\\<triangleright>P) \\<^emph> ownD {|i|}\"\nunfolding wsat_def\napply (rule pull_exists_antecedent2)\napply (rule upred_existsE')\napply (rule upred_entails_trans[OF upred_entails_eq[OF upred_sep_comm]])\napply (rule upred_entails_trans[OF upred_sep_assoc])\napply (rule upred_entails_trans[OF upred_sep_assoc'])\napply (rule upred_entails_trans[OF upred_sep_comm3M])\napply (rule upred_entails_trans[OF upred_sep_assoc_rev])\napply (rule upred_entails_substE[OF  persistent_keep[OF lookup_pers invariant_lookup]])\napply (rule upred_entails_trans[OF upred_sep_assoc])\napply (rule pull_exists_antecedentR)\napply (rule upred_existsE')\napply (rule upred_entails_trans[OF upred_sep_assoc])\napply (rule upred_entails_trans[OF upred_entails_eq[OF upred_sep_comm]])\napply (rule upred_entails_trans[OF upred_sep_assoc])\napply (rule upred_pure_impl)\napply (rule upred_entails_trans[OF upred_sep_assoc])\napply (rule upred_entails_trans[OF upred_entails_eq[OF upred_sep_comm]])\napply (rule upred_entails_trans[OF upred_sep_assoc])+\napply (simp add: sep_map_dom_delete)\napply (rule upred_entails_trans[OF upred_sep_assoc])\napply (rule upred_entails_trans[OF upred_sep_comm2R])\napply (rule upred_disjE')\nsubgoal for I Q\n  apply (rule upred_entails_trans[OF upred_sep_assoc])\n  apply (rule upred_frame)\n  apply (rule upred_entails_trans[OF upred_sep_comm4_2])\n  apply (rule upred_entails_trans[OF upred_sep_comm3M])\n  apply (rule persistent_split[OF persistent_later[OF persistent_eq]])\n  subgoal\n    apply (rule upred_entails_trans[OF upred_entail_eqR[OF upred_later_sep]])\n    apply (rule upred_later_mono)\n    apply (rule upred_entails_trans[OF upred_entails_eq[OF upred_sep_comm]])\n    apply (simp add: upred_eq_comm)\n    apply (rule upred_eqE)\n  by simp\n  apply(rule upred_existsI[of _ _ \"I\"])\n  apply (rule upred_entails_trans[OF upred_entails_eq[OF upred_sep_comm]])\n  apply (rule upred_entails_trans[OF upred_sep_assoc])\n  apply (rule upred_entails_trans[OF upred_entails_eq[OF upred_sep_comm]])\n  apply (rule upred_entails_trans[OF upred_sep_assoc])+\n  apply (rule upred_entails_trans[OF upred_entails_eq[OF upred_sep_comm]])\n  apply (rule upred_entails_trans[OF upred_sep_assoc])+\n  apply (rule upred_entails_trans[OF upred_entails_eq[OF upred_sep_comm]])\n  apply (rule upred_entails_trans[OF upred_sep_assoc])\n  apply (rule upred_entails_trans[OF _ upred_entails_eq[OF upred_sep_comm]])\n  apply (rule upred_frame)\n  apply (simp add: sep_map_dom_delete)\n  apply (rule upred_entails_trans[OF upred_sep_assoc])+\n  apply (rule upred_entails_trans[OF upred_sep_comm2R])\n  apply (rule upred_frame)\n  apply (rule upred_disjIR)\n  apply (rule upred_entails_trans[OF upred_sep_comm2R])\nby (rule upred_weakeningR)\napply (rule upred_entails_trans[OF upred_entails_eq[OF upred_sep_comm2L]])\napply (rule upred_entails_trans[OF upred_sep_assoc'])\napply (rule upred_entails_trans[OF upred_sep_assoc_rev])\napply (rule upred_entails_substE[OF ownE_singleton_twice])\nby simp\n\nlemma ownI_close: \"wsat \\<^emph> ownI i P \\<^emph> (\\<triangleright> P) \\<^emph> ownD {|i|} \\<turnstile> wsat \\<^emph> ownE {i}\"\napply (simp add: wsat_def)\napply (auto simp: pull_exists_eq intro!: upred_existsE')\napply (rule upred_entails_trans[OF upred_sep_comm3M])\napply (rule upred_entails_trans[OF upred_sep_comm2R])\napply (rule upred_entails_trans[OF upred_entails_eq[OF upred_sep_comm2L]])\napply (auto simp: upred_sep_assoc_eq)\napply (rule upred_entails_trans[OF upred_sep_comm4_2])\napply (rule upred_entails_trans[OF upred_entails_eq[OF upred_sep_comm2L]])\napply (auto simp: upred_sep_assoc_eq)\napply (rule upred_entails_substE[OF persistent_keep[OF lookup_pers invariant_lookup], unfolded upred_sep_assoc_eq])\nsubgoal for I \napply (auto simp: upred_sep_assoc_eq intro!: upred_existsI[of _ _ I] pull_exists_antecedentR upred_existsE')\napply (rule upred_entails_trans[OF upred_sep_comm2R])\napply (auto simp: sep_map_dom_delete upred_sep_assoc_eq intro!: upred_pure_impl)\napply (rule upred_entails_trans[OF upred_entails_eq[OF upred_sep_comm]])\napply (simp add: upred_sep_assoc_eq)\napply (rule upred_entails_trans[OF upred_sep_comm4_2])\napply (rule upred_entails_trans[OF upred_sep_comm3M])\napply (rule upred_entails_trans[OF upred_sep_comm2R])\napply (auto simp: upred_sep_assoc_eq intro!: upred_disjE')\nsubgoal for Q  \n  apply (rule upred_entails_trans[OF upred_sep_comm6_2R])\n  by (auto intro!: upred_entails_substE[OF ownD_singleton_twice, unfolded upred_sep_assoc_eq])\napply (auto simp: upred_sep_assoc_eq intro!: upred_frame)\napply (rule upred_entails_trans[OF upred_entails_eq[OF upred_sep_comm2L]])\napply (rule upred_entails_trans[OF upred_sep_comm2R])\napply (auto simp: upred_sep_assoc_eq intro!: upred_frame)\napply (rule upred_entails_trans[OF upred_entails_eq[OF upred_sep_comm2L]])\napply (simp add: upred_sep_assoc_eq)\napply (rule upred_entails_trans[OF upred_sep_comm4_2])\napply (rule upred_entails_trans[OF upred_sep_comm3M])\napply (rule upred_entails_trans[OF upred_sep_comm2R])\napply (rule upred_entails_trans[OF _ upred_entails_eq[OF upred_sep_comm]])\napply (auto simp: upred_sep_assoc_eq intro!: upred_frame upred_disjIL)\napply (rule upred_entails_trans[OF upred_entails_eq[OF upred_sep_comm2L]])\nby (auto intro!: upred_entails_trans[OF upred_weakeningR2] \n  upred_entails_trans[OF upred_entail_eqR[OF upred_later_sep]] upred_later_mono upred_eqE)\ndone\n\nlemma ownI_alloc: \"(\\<forall>E::name fset. \\<exists>i. \\<not>i|\\<in>|E \\<and> \\<phi> i) \\<Longrightarrow> \n  (wsat \\<^emph> \\<triangleright> P) ==\\<^emph> (\\<exists>\\<^sub>u i. \\<upharpoonleft>(\\<phi> i) \\<^emph> wsat \\<^emph> ownI i P)\"\napply (auto simp: wsat_def pull_exists_eq intro!: upred_wand_holdsI upred_existsE')\napply (rule add_holds[OF upred_own_unit,unfolded bupd_emp[OF upred_own_nothing_emp_eq]])\napply (rule upred_entails_substE[OF upred_wand_holdsE[OF upred_own_updateP]])\nsorry (* Axiomatized as this requires too much low level ghost state reasoning for which I'd need to add\n    way more lemmata and things. *)\n\nlemma ownI_alloc_open: \"(\\<forall>E::name fset. \\<exists>i. \\<not>i|\\<in>|E \\<and> \\<phi> i) \\<Longrightarrow> \n  wsat ==\\<^emph> (\\<exists>\\<^sub>u i. \\<upharpoonleft>(\\<phi> i) \\<^emph> (ownE {i} -\\<^emph> wsat) \\<^emph> ownI i P \\<^emph> ownD {|i|})\"\napply (auto simp: wsat_def pull_exists_eq intro!: upred_wand_holdsI upred_existsE')\nsorry (* Axiomatized as this requires too much low level ghost state reasoning for which I'd need to add\n    way more lemmata and things. *)\n\nlemma wsat_alloc: \"\\<Rrightarrow>\\<^sub>b (\\<exists>\\<^sub>u _:: inv. wsat \\<^emph> ownE UNIV)\"\napply (auto simp: upred_holds_entails)\napply (rule inG.add_own[OF inv_inG, where ?\\<gamma> =\"invariant_name\" and ?a=\"(map_view_auth (DfracOwn 1) fmempty,\\<epsilon>,\\<epsilon>)\",\n  OF prod_validI[OF map_view_auth_valid prod_validI[OF \\<epsilon>_valid \\<epsilon>_valid]]])\napply (rule inG.add_own[OF inv_inG, where ?\\<gamma> = \"enabled_name\" and ?a = \"(\\<epsilon>,DSet UNIV,\\<epsilon>)\", \n  OF prod_validI[OF \\<epsilon>_valid prod_validI[OF _ \\<epsilon>_valid]]])\napply (simp add: valid_raw_dset_def valid_def)\napply (rule inG.add_own[OF inv_inG, where ?\\<gamma> = \"disabled_name\" and ?a = \"(\\<epsilon>,\\<epsilon>,DFSet {||})\", \n  OF prod_validI[OF \\<epsilon>_valid prod_validI[OF \\<epsilon>_valid _]], unfolded \\<epsilon>_dfset_def[symmetric], OF \\<epsilon>_valid])\napply (auto simp: wsat_def pull_exists_eq own_inv_def ownE_def ownD_def \n  intro!: upred_entails_trans[OF _ updI])\napply (rule upred_existsI)\napply (rule upred_existsI[of _ _ fmempty])\napply (rule upred_entails_trans[OF upred_sep_comm2R])\napply (auto intro!: upred_frame)\napply (auto simp: lift_inv_fmap_def fmempty.rep_eq fmempty_def[symmetric] sep_fold_fset_def \n  comp_fun_commute.ffold_empty[OF sep_P_comp_fun_commute]  intro!: upred_frame)\napply (rule upred_entails_trans[OF upred_entails_eq[OF upred_sep_comm2L]])\napply (rule upred_entails_trans[OF upred_sep_comm2R])\nby (auto simp: upred_weakeningL intro!: upred_frame)\nend\nend", "meta": {"author": "firefighterduck", "repo": "isariris", "sha": "d02268e1e11cf681cae70b366b52843cbd90cc49", "save_path": "github-repos/isabelle/firefighterduck-isariris", "path": "github-repos/isabelle/firefighterduck-isariris/isariris-d02268e1e11cf681cae70b366b52843cbd90cc49/IrisCore/WorldSatisfaction.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6113819732941511, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.29614125174964995}}
{"text": "theory RCU\nimports RCU_model\nbegin \n\n\nlemmas genericwfs_lemma [simp] = wfs_2_def\n\n\nlemma initial_wfs_2: assumes \"initial_state \\<sigma> I\"  shows \"wfs_2 \\<sigma>\"\n  apply(simp)\n  apply(rule conjI)\n  using assms initial_wfs apply blast\n  using assms apply (simp add: initial_state_def)\n  by blast\n\nlemma wfs_2_preserved:\n  assumes \"wfs_2 \\<sigma>\"\n      and \"OpSem.step t a \\<sigma> \\<sigma>'\"\n    shows \"wfs_2 \\<sigma>'\"\n  using assms apply(unfold wfs_2_def)\n  apply (intro conjI)\n  using wfs_preserved assms apply blast\n  apply (rule step_cases[OF assms(2)]) apply simp_all\n  using assms(1) wfs_2_def wfs_def apply auto[1]\n  apply (simp add: read_trans_def lastWr_def covered_v_def Let_def rev_app_def OpSem.step_def update_thrView_def split:if_splits)\n  using assms(1)  apply auto[1]\n     apply (unfold writes_on_def wfs_2_def wfs_def)\n  apply (simp add: var_def update_mods_def update_modView_def  )\n  apply (simp add: write_trans_def valid_fresh_ts_def lastWr_def covered_v_def Let_def rev_app_def step_def update_thrView_def split:if_splits)\n  apply (simp add: visible_writes_def update_mods_def update_modView_def )\n  \n   apply safe\n  apply (simp add: fst_def tst_def snd_def)\n  apply(case_tac \"thrView \\<sigma> t x\", simp_all add:update_trans_def Let_def rev_app_def) \n  apply(case_tac \"releasing \\<sigma> (aaa, ba)\", simp_all)\n  apply (metis assms(1) case_prod_conv less_irrefl subset_iff wfs_2_def wfs_def)\n  by (metis assms(1) case_prod_conv less_irrefl subset_iff wfs_2_def wfs_def)\n\n\nlemma lastNotCovered:\n\"wfs \\<sigma> \\<Longrightarrow> lastWr \\<sigma> x \\<notin> covered \\<sigma>  \n \\<Longrightarrow> (\\<exists> b. (x, b) \\<notin> covered \\<sigma> \\<and> lastWr \\<sigma> x \\<in> writes_on \\<sigma> x) \"\n  apply (simp add: lastWr_def)\n  apply (unfold writes_on_def)\n  by (metis lastWr_def last_write_write_on writes_on_def)\n\n\n(*\n(\\<forall> x. lastWr \\<sigma> x \\<notin> covered \\<sigma>)\"\n*)\n\n(*the following must be included in the proof:\n\ncon_assms ps                            assumed         --- concerns allocation/bounds of C and rcu_0+i for all i\n\nmain_inv ms                             *done*          --- main invariant has 3 parts\npsem_rules ps                           *done*          --- how allocation works on the inside\nallocated_addresses ms ps               *done*          --- allocation for above are defined here\nsimple - observation_inv_ms ms          *done*          --- how own\\<^sub>W affects loc status (own\\<^sub>W loc = t \\<longrightarrow> loc\\<in>{s,n,det} t)\nhard   - observation_inv_sig ms ps \\<sigma>    *done*          --- limits which values can be WM_read from C\nsimple - own\\<^sub>W_n_by_t_imp ms             *done*          --- related own\\<^sub>W of n to n_dec and n (value)\ntedious - general_structure ms          *done*          --- says how n \\<noteq> s \\<noteq> detaddrs\nlocal - preCond ms ps \\<sigma> (pc ms t) t     *done*          --- defines preconditions for t to proceed with stepping      \nglobal - preCond ms ps \\<sigma> (pc ms ta) ta  *done*          --- defines preconditions for t to proceed with stepping      \n\nlocal  - weak_mem (pre/in/post block) (t ta)\nglobal - weak_mem (pre/in/post block) (ta t)\n*)\n\n\n\n(*the following describes originally reserved addresses*)\ndefinition \"default_locs \\<equiv> {i | i a. i=C \\<or> i = rcu_0+a \\<and> a<T_max }\"\n\ndefinition \"reserved_bydef ps \\<equiv> \\<forall>i. i\\<in>default_locs \\<longrightarrow> \\<not>isfree_addr i ps\"\n\ndefinition \"reservations_differ \\<equiv> \\<forall>i. i<T_max \\<longrightarrow> C\\<noteq>rcu_0+i\"\n\ndefinition \"counters_limit ms \\<equiv> \\<forall>t. t<T_max \\<longrightarrow> CTRsync\\<^sub>1 ms t \\<le>T_max \\<and> CTRsync\\<^sub>2 ms t \\<le>T_max\"\n\ndefinition \"con_assms ms ps \\<equiv> reserved_bydef ps \\<and> reservations_differ \\<and> counters_limit ms \"\n                                    \nlemmas con_assms_lemmas [simp] = reserved_bydef_def reservations_differ_def\n                                 default_locs_def counters_limit_def\n\n\n\n\n\n\n\n\n(*----------------supporting lemmas--------------------*)\nlemma blind_isabelle_hdlist [simp]:\n  \"det ms t\\<noteq>[] \\<Longrightarrow> hd(det ms t) = det ms t!0\"\n  by (simp add: hd_conv_nth)\n\nlemma aap_supplem_1:\n  \"i<length(det ms t) \\<Longrightarrow> det ms t\\<noteq>[] \\<Longrightarrow>((det ms t @ [ya]) ! i) = (det ms t)!i\"\n  by (simp add: nth_append)\n\nlemma supportingrandomwhat1:\n  \"ms' = ms\\<lparr>v := v ms(t \\<mapsto> z), pc := (pc ms)(t := I10)\\<rparr> \\<Longrightarrow> \ns ms t = s ms' t \\<and> n ms t = n ms' t \\<and> n_dec ms t = n_dec ms' t \\<and> det ms t = det ms' t \\<and> (\\<forall>loc. (own\\<^sub>W ms loc = own\\<^sub>W ms' loc \\<and> own\\<^sub>R ms loc = own\\<^sub>R ms' loc))\"\n  by simp\n\nlemma suppotingrandom1:\n  \"ms' = ms \\<lparr>det := (det ms)(t := det ms t @ [ya]), pc := (pc ms)(t := R2),\n          s_dec := (s_dec ms)(t := False), s := (s ms)(t := None)\\<rparr> \n\\<Longrightarrow> \\<forall> loc. loc\\<in>detaddrs ms t \\<longrightarrow> loc\\<in>detaddrs ms' t\"\n  apply(clarsimp)\n  by (metis butlast_snoc less_SucI nth_butlast)\n\n\nlemma suppotingrandom2:\n  \"ms' = ms \\<lparr>det := (det ms)(t := tl (det ms t)),\n          own\\<^sub>R := (own\\<^sub>R ms)(hd (det ms t) := own\\<^sub>R ms (hd (det ms t)) - {t}),\n          own\\<^sub>W := (own\\<^sub>W ms)(hd (det ms t) := None), pc := (pc ms)(t := R4)\\<rparr>\n\\<Longrightarrow> det ms' t = tl(det ms t)\"\n  by(clarsimp) \n\nlemma suppotingrandom3:\n  \"ms' = ms \\<lparr>det := (det ms)(t := tl (det ms t)),\n          own\\<^sub>R := (own\\<^sub>R ms)(hd (det ms t) := own\\<^sub>R ms (hd (det ms t)) - {t}),\n          own\\<^sub>W := (own\\<^sub>W ms)(hd (det ms t) := None), pc := (pc ms)(t := R4)\\<rparr>\n\\<Longrightarrow> det ms t \\<noteq>[]\n\\<Longrightarrow> loc \\<in> detaddrs ms' t\\<Longrightarrow> loc\\<in>detaddrs ms t\"\n  apply(clarsimp)  \n  by (metis Nitpick.size_list_simp(2) Suc_less_eq Suc_pred length_greater_0_conv nth_tl)\n  \n\nlemma suppotingrandom4:\n  \"ms' = ms \\<lparr>det := (det ms)(t := tl (det ms t)),\n          own\\<^sub>R := (own\\<^sub>R ms)(hd (det ms t) := own\\<^sub>R ms (hd (det ms t)) - {t}),\n          own\\<^sub>W := (own\\<^sub>W ms)(hd (det ms t) := None), pc := (pc ms)(t := R4)\\<rparr>\n\\<Longrightarrow> det ms t \\<noteq>[]\n\\<Longrightarrow> loc\\<in>detaddrs ms t \\<Longrightarrow> loc\\<in> detaddrs ms' t \\<or> loc = hd(det ms t)\"\n  apply(clarsimp) \n  by (metis Nitpick.size_list_simp(2) Suc_less_eq Suc_pred less_Suc_eq_0_disj nth_tl)\n  \n\nlemma supp1:\n  \"cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  \\<sigma> [z \\<leftarrow> ya]\\<^sub>t \\<sigma>' \\<Longrightarrow>\n  cvd[C,vala] \\<sigma>'\"\n  apply(simp add:covered_v_def lastWr_def OpSem.step_def RdX_def visible_writes_def) unfolding writes_on_def\n  read_trans_def\n  by (smt (z3) Collect_cong rev_app_def surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(2) update_thrView_def value_def)\n\nlemma supp2:\n  \"cvd[C,vala] \\<sigma> \\<Longrightarrow>\nwfs \\<sigma> \\<Longrightarrow>\n  \\<sigma> [z := ya]\\<^sub>t \\<sigma>' \\<Longrightarrow>\n  z\\<noteq>C \\<Longrightarrow>\n  cvd[C,vala] \\<sigma>'\"\n  by (metis cvd_WrX_other_var_pres)\n\n\n\n\n\n\n(*******************************************************************)\n\n\n\n\n\n\n(*----------------Main Invariant Shown--------------------*)\n\nlemma main_invariant_1_preservation:\n \"main_inv ms ps \\<Longrightarrow> \n  wfs_2 \\<sigma> \\<Longrightarrow>\n  cvd[C,l] \\<sigma> \\<Longrightarrow>\n  t<T_max \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> \n  preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow>\n  psem_rules ps \\<Longrightarrow>\n  own\\<^sub>W_n_by_t_imp ms \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow>\n  main_inv_1 ms'\"\n  apply simp \n  apply(simp add: step_def preCond_def)\n  apply(case_tac \"pc ms t\", simp_all)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:new_int_def)\n  apply clarify\n  apply(subgoal_tac \"n ms t = None\") prefer 2\n  apply fastforce apply(simp add:main_inv_lemmas) \n  apply clarify \n  apply(case_tac \"ta = t\", simp_all) \n  apply(case_tac \"y = loc\", simp_all)\n  apply (metis insert_not_empty option.sel)\n  apply (metis option.sel)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(case_tac \"repeat ms t\", simp add:general_structure_lemmas)\n  apply (metis Diff_empty Diff_insert0 option.sel)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n(*FAAZ*) defer\n  apply(simp add:abbr main_inv_lemmas  Rcap_def) apply clarify \n  apply(simp add:general_structure_def)\n  apply (metis option.sel)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n(*CAS*) defer\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n  apply (metis singleton_iff)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n  apply(case_tac \"CAS_succ ms t\", simp_all)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def) apply auto[1]\n  apply(case_tac \"nondet_val ms t \", simp_all)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n  apply(case_tac \"det ms t \\<noteq> []\", simp_all)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n  apply (metis Diff_empty Diff_insert0 singleton_inject)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t = t\", simp_all)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n(*r[i] = rcu[counter]*) defer\n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def) \n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n(*load(rcu[i])*) defer\n  apply(case_tac \"reg ms t = Suc 0\", simp_all)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n  apply(simp add:abbr main_inv_lemmas  Rcap_def)\n(*dealing with FAAZ*)\n  apply(simp add:FAAZ_def get_C_val_def)\n  apply(case_tac \"\\<not>repeat ms t\", simp_all)\n  apply clarify\n  apply(case_tac \"ta = t\")\n  apply(simp add:general_structure_def own\\<^sub>W_n_by_t_imp_def observation_inv_sig_def)\n  apply (metis option.sel set_eq_subset)\n  apply(simp add:general_structure_def own\\<^sub>W_n_by_t_imp_def observation_inv_sig_def)\n  apply clarify apply(intro conjI impI) prefer 2\n  apply (metis option.sel)\n  apply(subgoal_tac \"ta < T_max \\<and> own\\<^sub>W ms (the(n ms ta)) = Some ta\") prefer 2\n  apply (metis option.sel)\n  apply(subgoal_tac \"l \\<noteq> (the(n ms ta))\") prefer 2\n  apply blast\n  apply(subgoal_tac \"l = value \\<sigma> (a,b)\")\n  apply blast \n  prefer 2\n  apply clarify\n  apply(case_tac \"ta = t\")\n  apply(simp add:general_structure_def own\\<^sub>W_n_by_t_imp_def observation_inv_sig_def)\n  apply (metis option.sel set_eq_subset)\n  apply(simp add:general_structure_def own\\<^sub>W_n_by_t_imp_def observation_inv_sig_def)\n  apply clarify apply(intro conjI impI) prefer 2\n  apply (metis option.sel)\n  apply(subgoal_tac \"ta < T_max \\<and> own\\<^sub>W ms (the(n ms ta)) = Some ta\") prefer 2\n  apply (metis option.sel)\n  apply(subgoal_tac \"l \\<noteq> (the(n ms ta))\") prefer 2 \n  apply blast\n  apply(subgoal_tac \"l = value \\<sigma> (a,b)\")\n  apply blast \n  unfolding covered_v_def lastWr_def writes_on_def\n  apply (metis (mono_tags, lifting) mem_Collect_eq subsetD visible_var visible_writes_in_writes )\n  apply (metis (mono_tags, lifting) mem_Collect_eq subsetD visible_var visible_writes_in_writes )\n(*resolving CAS*)\n  apply(simp add:cas_step_rcu_def) apply clarify\n  apply(case_tac \"ya\", simp_all)\n  apply(simp add:main_inv_lemmas)\n  apply(simp add:main_inv_lemmas)\n(*resolving load_rcu_to_r*)\n  apply(simp add:load_rcu_to_r_def)\n  apply(simp add:main_inv_lemmas)\n  apply clarify\n  apply(simp add:general_structure_def own\\<^sub>W_n_by_t_imp_def observation_inv_sig_def)\n  apply (metis option.sel)\n(*resolving load(counter)*)\n  apply(simp add:rcu_temp_copy_def)\n  apply(simp add:main_inv_lemmas)\n  apply clarify\n  apply(simp add:general_structure_def own\\<^sub>W_n_by_t_imp_def observation_inv_sig_def)\n  by (metis option.sel)\n\n\nlemma main_invariant_2_preservation:\n  \"main_inv ms ps \\<Longrightarrow> \n  wfs_2 \\<sigma> \\<Longrightarrow>\n  cvd[C,l] \\<sigma> \\<Longrightarrow>\n  t<T_max \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> \n  preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow>\n  psem_rules ps \\<Longrightarrow>\n  own\\<^sub>W_n_by_t_imp ms \\<Longrightarrow>\n  observation_inv_ms ms \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow>\n    main_inv_2 ms' ps'\"\n  apply simp \n  apply(simp add: step_def preCond_def)\n  apply(case_tac \"pc ms t\", simp_all)\n  apply(simp add:abbr main_inv_lemmas) \n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:new_int_def)\n  apply clarify\n  apply(subgoal_tac \"n ms t = None\") prefer 2\n  apply fastforce apply(simp add:main_inv_lemmas) \n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(case_tac \"repeat ms t\", simp_all)\n  apply(simp add:abbr main_inv_lemmas)\n(*FAAZ*) defer\n  apply(simp add:abbr main_inv_lemmas)\n  apply force\n  apply(simp add:abbr main_inv_lemmas)\n(*CAS*) defer\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(case_tac \"CAS_succ ms t \", simp_all)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply clarify\n  apply(simp add:abbr main_inv_lemmas)\n  apply(case_tac \"nondet_val ms t\", simp_all)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(case_tac \"det ms t = []\")\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply clarify\n  apply(case_tac \"loc = det ms t ! 0\", simp_all)\n  apply blast\n  apply(simp add:abbr main_inv_lemmas)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t = t\", simp_all)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n(*r[i] = rcu[counter]*) defer\n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n(*load(rcu[i])*) defer\n  apply(case_tac \"reg ms t = Suc 0\", simp_all)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n(*dealing with FAAZ*)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:FAAZ_def get_C_val_def)\n  apply(case_tac \"\\<not>repeat ms t\", simp_all)\n  apply clarify\n  apply(simp add:observation_inv_sig_def observation_inv_ms_def)\n  apply (metis Up_reads_cvd_v relating_step_to_update_trans_1)\n  apply clarify\n  apply(simp add:observation_inv_sig_def observation_inv_ms_def general_structure_def)\n  apply (metis Up_reads_cvd_v relating_step_to_update_trans_1)\n(*dealing with CAS*)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:cas_step_rcu_def)\n  apply clarify\n  apply(case_tac \"ya\", simp_all)\n(*dealing with load_rcu_to_r*)\n  apply(simp add:load_rcu_to_r_def main_inv_lemmas)\n  apply clarify\n  apply(simp add:observation_inv_sig_def observation_inv_ms_def)\n(*dealing with rcu_temp_copy*)\n  apply(simp add:rcu_temp_copy_def main_inv_lemmas)\n  apply clarify\n  by(simp add:observation_inv_sig_def observation_inv_ms_def)\n\n\n\nlemma main_invariant_3_preservation:\n  \"main_inv ms ps \\<Longrightarrow> \n  wfs_2 \\<sigma> \\<Longrightarrow>\n  cvd[C,l] \\<sigma> \\<Longrightarrow>\n  t<T_max \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> \n  preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow>\n  psem_rules ps \\<Longrightarrow>\n  own\\<^sub>W_n_by_t_imp ms \\<Longrightarrow>\n  observation_inv_ms ms \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow>\n    main_inv_3 ms' ps'\"\n  apply simp \n  apply(simp add: step_def preCond_def)\n  apply(case_tac \"pc ms t\", simp_all)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:new_int_def)\n  apply clarify  apply(simp add:main_inv_lemmas) \n  apply (metis insert_iff option.inject)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(case_tac \"repeat ms t\", simp_all) \n  apply clarify\n  apply(case_tac \"ta = t\", simp_all)\n  apply(subgoal_tac \"the(n ms t) \\<noteq> the(s ms t)\") prefer 2\n  apply (metis general_structure_def n_differ_from_s_inside_def option.sel)\n  apply(subgoal_tac \"\\<forall>i. i<length (det ms t) \\<longrightarrow> det ms t ! i \\<noteq> the(s ms t)\")\n  apply (smt (verit) insert_iff mem_Collect_eq names_2(2) option.sel)\n  apply (metis (no_types, lifting) general_structure_def less_zeroE list.size(3) s_differ_from_det_inside_def)\n  apply(simp add:abbr main_inv_lemmas)\n(*FAAZ*) defer\n  apply(simp add:abbr main_inv_lemmas)\n  apply force\n  apply(simp add:abbr main_inv_lemmas)\n(*CAS*) defer\n  apply(simp add:abbr main_inv_lemmas) \n  apply (metis option.sel own\\<^sub>W_n_by_t_imp_def)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(case_tac \"CAS_succ ms t \", simp_all)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply clarify\n  apply(simp add:abbr main_inv_lemmas)\n  apply(case_tac \"nondet_val ms t\", simp_all)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(case_tac \"det ms t = []\")\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t = t\", simp_all)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n(*r[i] = rcu[counter]*) defer\n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n(*load(rcu[i])*) defer\n  apply(case_tac \"reg ms t = Suc 0\", simp_all)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:abbr main_inv_lemmas)\n(*dealing with FAAZ*)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:FAAZ_def get_C_val_def)\n  apply(case_tac \"\\<not>repeat ms t\", simp_all)\n  apply clarify\n  apply(simp add:observation_inv_sig_def observation_inv_ms_def) \n  apply (metis insertCI)\n  apply clarify\n  apply(simp add:observation_inv_sig_def observation_inv_ms_def general_structure_def) \n  apply (metis insertI2)\n(*dealing with CAS*)\n  apply(simp add:abbr main_inv_lemmas)\n  apply(simp add:cas_step_rcu_def)\n  apply clarify\n  apply(case_tac \"ya\", simp_all) \n  apply (metis (no_types, lifting) Rcap_def fun_upd_apply insertCI option.discI option.inject)\n(*dealing with load_rcu_to_r*)\n  apply(simp add:load_rcu_to_r_def main_inv_lemmas)\n  apply clarify\n  apply(simp add:observation_inv_sig_def observation_inv_ms_def)\n(*dealing with rcu_temp_copy*)\n  apply(simp add:rcu_temp_copy_def main_inv_lemmas)\n  apply clarify\n  by(simp add:observation_inv_sig_def observation_inv_ms_def)\n\n\n\n\nlemma main_invariant_preservation:\n  \"main_inv ms ps \\<Longrightarrow> \n  wfs_2 \\<sigma> \\<Longrightarrow> \\<comment> \\<open>new\\<close> \n  t<T_max \\<Longrightarrow>\n  general_structure ms \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> \n  preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow>\n  observation_inv_ms ms \\<Longrightarrow> \\<comment> \\<open>new\\<close> \n  cvd[C,vala] \\<sigma> \\<Longrightarrow>  \n  psem_rules ps \\<Longrightarrow>\n  own\\<^sub>W_n_by_t_imp ms  \\<Longrightarrow> \nmain_inv ms' ps'\"\n  unfolding main_inv_def\n  apply(intro conjI impI)\n  using main_invariant_1_preservation main_inv_def apply blast\n  using main_invariant_2_preservation main_inv_def apply blast\n  using main_invariant_3_preservation main_inv_def by blast\n\n(*--------------------------------------------------------------------*)\n\n\n\n\n\n\n\n(*----------------allocated_addresses ms ps--------------------*)\n\nlemma allocated_addresses_preservation:\n  \"main_inv ms ps \\<Longrightarrow> \n  t<T_max \\<Longrightarrow>\n  wfs_2 \\<sigma> \\<Longrightarrow>\n  cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  \\<not>isfree_addr vala ps \\<Longrightarrow>          \\<comment> \\<open>this is easily shown through alloc_addr\\<close>\n  general_structure ms \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> \n  preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n  allocated_addresses ms ps \\<Longrightarrow>\n  psem_rules ps \\<Longrightarrow>\n  con_assms ms ps \\<Longrightarrow>\n  own\\<^sub>W_n_by_t_imp ms \\<Longrightarrow>\n  allocated_addresses ms' ps'\"\n  apply (simp add:step_def preCond_def)\n  apply(case_tac \" pc ms t\", simp_all add:own\\<^sub>W_n_by_t_imp_def)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(simp add:abbr allocated_addresses_lemmas) \n  apply meson\n  apply(subgoal_tac \"n ms t = None\") prefer 2\n  apply meson \n  apply clarsimp \n  apply(simp add:abbr allocated_addresses_lemmas general_structure_def)\n  apply(intro conjI impI) \n  apply clarsimp\n  apply(simp add:Rcap_def)\n  apply metis\n  apply clarsimp\n  apply(simp add:Rcap_def)\n  apply (metis option.sel)\n  apply clarsimp\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(case_tac \"repeat ms t\", simp_all)  \n  apply (metis option.sel)\n  apply(simp add:abbr allocated_addresses_lemmas)  \n  defer                                                 (*FAAZ*)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(simp add:OpSem.step_def RdX_def) \n  apply(simp add:Rcap_def Wcap_def general_structure_def con_assms_def)\n  apply clarsimp \n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(simp add:abbr allocated_addresses_lemmas cas_step_rcu_def) apply clarify\n  apply(case_tac \"ya\", simp_all)\n  apply(simp add:abbr allocated_addresses_lemmas) \n  apply (metis option.sel)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(case_tac \"CAS_succ ms t\", simp_all)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(intro conjI impI) \n  apply meson \n  apply(case_tac \"det ms t = []\", simp_all)\n  apply(simp add:general_structure_def)\n  apply (metis Rcap_def insertCI option.sel)  apply clarify\n  apply(simp add:Rcap_def)\n  apply(simp add:general_structure_def) \n  apply (metis (no_types, opaque_lifting) aap_supplem_1 less_Suc_eq nth_append_length)\n  apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(case_tac \"nondet_val ms t\", simp_all)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(case_tac \" det ms t \\<noteq> [] \", simp_all)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(simp add:abbr allocated_addresses_lemmas) \n  apply(simp add:abbr allocated_addresses_lemmas general_structure_def) \n  apply clarsimp \n  apply(intro conjI impI)\n  apply(case_tac \"det ms t = []\", simp add:Rcap_def)\n  apply clarsimp\n  apply(subgoal_tac \"hd (det ms t) = det ms t !0\") prefer 2 \n  apply (metis hd_conv_nth)\n  apply (metis empty_iff insert_iff length_0_conv not_gr_zero) \n  apply (meson length_greater_0_conv n_differ_from_det_def)\n  apply(case_tac \"det ms t = []\", simp add:Rcap_def)\n  apply clarsimp\n  apply(subgoal_tac \"hd (det ms t) = det ms t !0\") prefer 2 \n  apply (metis hd_conv_nth) \n  apply(case_tac \"t \\<noteq> ta\") \n  apply (meson det_differ_from_det_def length_greater_0_conv)\n  apply clarify \n  apply clarsimp\n  apply(case_tac \"length(det ms t) = 1\") \n  apply linarith\n  apply(subgoal_tac \"hd (det ms t) = det ms t !0\") prefer 2 \n  apply (metis hd_conv_nth)\n  apply(subgoal_tac \"tl (det ms t) ! ia = (det ms t) ! (ia+1)\") prefer 2\n  apply (metis One_nat_def Suc_eq_plus1 length_tl nth_tl) \n  apply(simp add:det_differ_from_det_def det_differ_inside_def) \n  apply (metis (no_types, lifting) Suc_less_eq Suc_pred length_greater_0_conv)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all)\n  apply(case_tac \" CTRsync\\<^sub>1 ms t = t\", simp_all)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(simp add:OpSem.step_def RdX_def) \n  apply(simp add:Rcap_def Wcap_def general_structure_def con_assms_def)\n  apply clarsimp\n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(simp add:OpSem.step_def RdX_def) \n  apply(simp add:Rcap_def Wcap_def general_structure_def con_assms_def)\n  apply clarsimp\n  apply(case_tac \"reg ms t = Suc 0\", simp_all)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  apply(simp add:abbr allocated_addresses_lemmas)\n  (*FAAZ*)\n  apply(simp add:allocated_addresses_def)\n  apply(intro conjI impI) prefer 2\n  apply(simp add:get_C_val_def allocated_n_addr_def)\n  apply(simp add:abbr allocated_addresses_lemmas FAAZ_def)\n  apply(simp add:Rcap_def Wcap_def general_structure_def con_assms_def)\n  apply clarsimp\n  apply metis  prefer 2\n  apply(simp add:get_C_val_def allocated_n_addr_def)\n  apply(simp add:abbr allocated_addresses_lemmas FAAZ_def)\n  apply(simp add:Rcap_def Wcap_def general_structure_def con_assms_def)\n  apply clarsimp\n  apply(simp add:get_C_val_def allocated_n_addr_def)\n  apply(simp add:abbr allocated_addresses_lemmas FAAZ_def)\n  apply(simp add:Rcap_def Wcap_def general_structure_def con_assms_def)\n  apply clarsimp\n  by (metis Up_reads_cvd_v map_upd_eqD1 relating_step_to_update_trans_1)\n\n\n(*--------------------------------------------------------------------*)\n\n\n\n\n\n\n\n(*---------------------observation_inv_ms ms----------------------------*)\n\n\n\n\n\nlemma Local_correctness_observation_inv_ms:\n  \"main_inv ms ps \\<Longrightarrow> \n  t<T_max \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> \n  preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n  observation_inv_ms ms \\<Longrightarrow>\n  own\\<^sub>W_n_by_t_imp ms  \\<Longrightarrow> \nobservation_inv_ms ms'\"\n  apply(simp add:observation_inv_ms_def)\n  apply(simp add:step_def preCond_def)\n  apply(case_tac \"pc ms t\", simp_all add:abbr own\\<^sub>W_n_by_t_imp_def Wcap_def Rcap_def)\n  apply(simp add:general_structure_lemmas con_assms_def observation_inv_sig_def main_inv_lemmas)\n  apply meson\n  apply metis apply clarsimp \n  apply (metis option.inject)\n  apply(case_tac \"repeat ms t\", simp_all)\n  (*FAAZ*) defer\n  apply(simp add:general_structure_lemmas con_assms_def observation_inv_sig_def main_inv_lemmas)\n  apply clarify\n  apply(simp add: step_def RdX_def)\n  apply metis\n  (*CAS*) defer\n  apply(case_tac \"CAS_succ ms t\", simp_all)\n  apply(simp add:abbr)\n  apply(simp add:abbr)\n  apply(simp add:general_structure_lemmas con_assms_def observation_inv_sig_def main_inv_lemmas)\n  apply clarify \n  apply(subgoal_tac \"det ms t @ [ya] = det ms' t\") prefer 2\n  apply clarsimp\n  apply(subgoal_tac \"\\<forall>i. own\\<^sub>W ms i = Some t \\<longrightarrow> i\\<in>detaddrs ms t \\<or> i = the(s ms t)\") prefer 2\n  apply clarsimp\n  apply meson\n  apply(case_tac \"loc \\<notin> detaddrs ms t\") \n  apply (metis lessI nth_append_length)\n  apply clarify\n  apply(case_tac \"det ms t = []\")\n  apply (metis Suc_le_length_iff detaddrs_def empty_Collect_eq inlist_def insert_absorb insert_not_empty less_eq_Suc_le list.distinct(1))\n  apply(subgoal_tac \"\\<forall> loc. loc\\<in>detaddrs ms t \\<longrightarrow> loc\\<in>detaddrs ms' t\") apply clarsimp \n  apply metis \n  apply (metis suppotingrandom1)\n  apply clarify apply(case_tac \"b\") apply(simp_all)\n  apply blast\n  apply blast\n  apply(case_tac \"nondet_val ms t\", simp_all)\n  apply(simp add:abbr)\n  apply(simp add:abbr)\n  apply(case_tac \" det ms t \\<noteq> [] \", simp_all)\n  apply(simp add:abbr)\n  apply(simp add:abbr)\n  apply(simp add:general_structure_lemmas con_assms_def observation_inv_sig_def main_inv_lemmas)\n  apply clarify \n  apply(case_tac \"det ms t=[]\") \n  apply fastforce\n  apply(case_tac \"length(det ms t) = Suc 0\")\n  apply (metis less_Suc0)\n  apply(subgoal_tac \"\\<forall> loc. loc\\<in>detaddrs ms t \\<longrightarrow> loc\\<in>detaddrs ms' t \\<or> loc = hd(det ms t)\") apply clarsimp \n  apply meson \n  apply(subgoal_tac \"hd(det ms t) = det ms t!0\") prefer 2\n  apply (meson blind_isabelle_hdlist)\n  apply (metis suppotingrandom4)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t = t\", simp_all)\n  apply(simp add:abbr)\n  apply(simp add:abbr)\n  apply(simp add:abbr)\n  apply(simp add:general_structure_lemmas con_assms_def observation_inv_sig_def main_inv_lemmas)\n  apply clarify apply(simp add:step_def RdX_def) \n  apply blast\n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all)\n  apply(simp add:abbr)\n  apply(simp add:abbr)\n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all)\n  apply(simp add:abbr)\n  apply(simp add:abbr)\n  apply(simp add:general_structure_lemmas con_assms_def observation_inv_sig_def main_inv_lemmas)\n  apply clarify apply(simp add:step_def RdX_def) \n  apply blast\n  apply(case_tac \"reg ms t = Suc 0\", simp_all)\n  apply(simp add:abbr)\n  apply(simp add:abbr)\n  defer\n  apply(clarify) apply(simp add:cas_step_rcu_def) apply clarify\n  apply(case_tac \"snd (CAS t (a, b) (the (s ms t)) (the (n ms t)) \\<sigma> ts')\", simp_all)\n  apply(case_tac \"loc = y\", simp_all) \n  apply(case_tac \"y = ya\", simp_all) \n  apply(case_tac \"loc = ya\", simp_all)\n  apply metis\n  apply blast\n  apply(simp add:get_C_val_def FAAZ_def)\n  apply(case_tac \"repeat ms t\", simp_all)\n  apply clarsimp \n  apply metis\n  apply clarsimp\n  by metis \n\n(*---------------------------------------------------------------------*)\n\n\n\n\n\n\n(*------------------------observation_inv_sig Correctness---------------------------*)\n\n\n\n\nlemma Local_correctness_observation_inv_sig:\n  \"main_inv ms ps \\<Longrightarrow> \n  t<T_max \\<Longrightarrow>\n  general_structure ms \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> \n  preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow>\n  observation_inv_ms ms \\<Longrightarrow>\n  cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  psem_rules ps \\<Longrightarrow>\n  own\\<^sub>W_n_by_t_imp ms  \\<Longrightarrow> \n  wfs_2 \\<sigma> \\<Longrightarrow>\n  con_assms ms ps \\<Longrightarrow>\n  allocated_addresses ms ps \\<Longrightarrow>\nobservation_inv_sig ms' ps' \\<sigma>'\"\n  apply(simp add:step_def preCond_def)\n  apply(case_tac \"pc ms t\")\n  apply simp_all \n  apply (simp add:abbr)\n  apply(simp add:observation_inv_sig_def)\n  apply (simp add:abbr)\n  apply(simp add:observation_inv_sig_def)\n  apply (simp add:abbr)\n  apply(simp add:observation_inv_sig_def)\n  apply (simp add:abbr)\n  apply(simp add:observation_inv_sig_def)\n  apply clarsimp apply(simp add:covered_v_def)\n  apply metis\n  apply (simp add:abbr)\n  apply(simp add:observation_inv_sig_def)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def )\n  apply (metis cvd_backwards_WrX )\n  apply (simp add:abbr)\n  apply(simp add:observation_inv_sig_def)\n  apply(simp add:observation_inv_sig_def con_assms_def abbr)\n  apply(case_tac \"repeat ms t\", simp_all)\n  apply (metis cvd_backwards_WrX)\n  apply (metis cvd_backwards_WrX )\n  apply (simp add:abbr)\n  apply(simp add:observation_inv_sig_def)\n  apply(simp add:observation_inv_sig_def con_assms_def abbr)\n  apply (metis cvd_backwards_WrX )\n  (*FAAZ*) defer \n  apply(simp add:abbr observation_inv_sig_def) apply clarify\n  apply(simp add:Wcap_def own\\<^sub>W_n_by_t_imp_def)\n  apply (metis not_cvd_RdX_pres)\n  apply(simp add:writeto_star_n_def observation_inv_sig_def con_assms_def)\n  apply (metis not_cvd_WrX_pres)  \n  (*cas_step_rcu*) defer\n  apply (simp add:abbr)\n  apply(simp add:observation_inv_sig_def)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def)\n  apply (metis cvd_backwards_WrX)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def)\n  apply(case_tac \"CAS_succ ms t\", simp_all)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def)\n  apply clarify apply(case_tac \"b\", simp_all)\n  apply auto[1]\n  apply auto[1]\n  apply(case_tac \"nondet_val ms t\", simp_all)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def)\n  apply(case_tac \"det ms t \\<noteq> []\", simp_all)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def)\n  apply(simp add:Wcap_def own\\<^sub>W_n_by_t_imp_def)\n  apply clarify\n  apply(case_tac \"loc \\<noteq> hd (det ms t)\", simp_all)\n  apply auto[1] \n  apply(simp add:Rcap_def)\n  apply (metis length_greater_0_conv)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all add:abbr)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t = t\", simp_all)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def) \n  apply(simp add:abbr observation_inv_sig_def con_assms_def) apply clarify \n  apply(simp add:Wcap_def own\\<^sub>W_n_by_t_imp_def)\n  apply(simp add:observation_inv_sig_def)\n  apply (metis not_cvd_RdX_pres)\n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all add:abbr)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def) apply clarify \n  apply(simp add:Wcap_def own\\<^sub>W_n_by_t_imp_def)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def) apply clarify \n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def) apply clarify \n  apply(simp add:abbr observation_inv_sig_def con_assms_def) apply clarify \n  apply(simp add:abbr observation_inv_sig_def con_assms_def) apply clarify \n  apply (metis not_cvd_RdX_pres)\n  apply(case_tac \"reg ms t = Suc 0\", simp_all)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def) apply clarify \n  apply(simp add:abbr observation_inv_sig_def con_assms_def) apply clarify \n(*FAAZ*)\n  apply(simp add:abbr observation_inv_sig_def con_assms_def)\n  apply(case_tac \"repeat ms t\", simp_all)\n  apply(simp add:get_C_val_def)\n  apply(subgoal_tac \"cvd[C,vala] \\<sigma>'\") prefer 2\n  using cvd_pres_by_FAAZ_unfold \n  apply (metis (no_types, lifting) wfs_2_def)\n  apply(subgoal_tac \"\\<forall>t loc. t<T_max \\<and> own\\<^sub>W ms loc = Some t \\<longrightarrow> t<T_max \\<and> own\\<^sub>W ms' loc = Some t\") prefer 2\n  apply clarsimp\n  apply(subgoal_tac \"\\<forall>loc. isfree_addr loc ps \\<longrightarrow> isfree_addr loc ps'\") prefer 2\n  apply clarsimp\n  apply clarsimp\n  apply (elim disjE) prefer 2\n  apply (meson FAAZ_is_RMW_R testtttttt wfs_2_def wfs_2_preserved)\n  apply (meson FAAZ_is_RMW_R testtttttt wfs_2_def wfs_2_preserved)\n  apply(simp add:get_C_val_def)\n  apply(subgoal_tac \"cvd[C,vala] \\<sigma>'\") prefer 2\n  using cvd_pres_by_FAAZ_unfold \n  apply (metis (no_types, lifting) wfs_2_def)\n  apply(subgoal_tac \"\\<forall>t loc. t<T_max \\<and> own\\<^sub>W ms loc = Some t \\<longrightarrow> t<T_max \\<and> own\\<^sub>W ms' loc = Some t\") prefer 2\n  apply clarsimp\n  apply(subgoal_tac \"\\<forall>loc. isfree_addr loc ps \\<longrightarrow> isfree_addr loc ps'\") prefer 2\n  apply clarsimp\n  apply clarsimp\n  apply (elim disjE) prefer 2\n  apply (meson FAAZ_is_RMW_R testtttttt wfs_2_def wfs_2_preserved)\n  apply (meson FAAZ_is_RMW_R testtttttt wfs_2_def wfs_2_preserved)\n(*cas_step_rcu*)\n  apply (simp add:cas_step_rcu_def)\n  apply (simp add:observation_inv_sig_def)\n  apply (simp add:CAS_def)\n  apply(clarify)\n  apply(case_tac \"ya\", simp_all)  prefer 2\n  apply(case_tac \"value \\<sigma> (a, b) = yb\", simp_all)\n  apply(subgoal_tac \"cvd[C,vala] \\<sigma>'\") prefer 2 \n  apply (metis CAS_def cvd_pres_by_CAS_unfold_pt1 fst_conv wfs_2_def) apply clarsimp\n  apply(simp add:covered_v_def Rcap_def main_inv_lemmas Wcap_def)\n  apply metis\n  apply(case_tac \"value \\<sigma> (a, b) = yb\", simp_all)\n  apply(case_tac \"loc = yb\", simp_all add:general_structure_lemmas)\n  apply (metis (no_types, opaque_lifting) RMW_exist_w_in_post covered_v_def relating_step_to_update_trans_1)\n  apply(case_tac \"loc = y\", simp_all add:Wcap_def)\n  apply (meson allocated_addresses_def allocated_n_addr_def isfree_addr_def)\n  by (metis (no_types, opaque_lifting) RMW_exist_w_in_post covered_v_def relating_step_to_update_trans_1)\n  \n\n(*--------------------------------------------------------------*)\n\n\n\n\n\n\n\n(*-------------------own\\<^sub>W_n_by_t_imp ms----------------------*)\n\nlemma own\\<^sub>W_n_by_t_imp_preservation:\n  \"main_inv ms ps \\<Longrightarrow> \n  t<T_max \\<Longrightarrow>\n  own\\<^sub>W_n_by_t_imp ms \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> \n  preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n  con_assms ms ps \\<Longrightarrow>\n  allocated_addresses ms ps\\<Longrightarrow>\n  general_structure ms \\<Longrightarrow>\n  own\\<^sub>W_n_by_t_imp ms'\"\n  apply(simp add:step_def preCond_def)\n  apply(case_tac \"pc ms t\", simp_all)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def) \n  apply clarify \n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def)\n  apply clarsimp apply(case_tac \"ta = t\", simp_all) \n  apply (simp add: main_inv_2_def main_inv_3_def main_inv_def)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def)\n  apply(simp split:if_splits add: allocated_addresses_lemmas)\n  apply(case_tac \"repeat ms t\", simp_all)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def)\n  defer                                         (*FAAZ*)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def)\n  apply(simp split:if_splits add: allocated_addresses_lemmas)\n  apply(simp add:Rcap_def)\n  apply clarsimp\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def)      \n  defer                                         (*CAS*)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def)\n  apply(case_tac \"CAS_succ ms t\", simp_all)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def)\n  apply clarsimp\n  apply(case_tac \"nondet_val ms t\", simp_all)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def) \n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def) \n  apply(case_tac \"det ms t = []\", simp_all)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def) \n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def) \n  defer                                   (*free(pop(detatched))*)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def) \n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t = t\", simp_all)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def)\n  apply clarsimp\n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def) \n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def) \n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def) \n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def) \n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def) defer\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def) \n  apply(case_tac \"reg ms t = Suc 0\", simp_all)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def) \n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def) \n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def get_C_val_def Rcap_def)  (*FAAZ*)\n  apply(case_tac \"repeat ms t\", simp_all)\n  apply clarsimp\n  apply clarsimp\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def cas_step_rcu_def Rcap_def)\n  apply clarsimp\n  apply(case_tac \"ya\", simp_all)\n  apply (metis (no_types, lifting) general_structure_def n_differ_from_s_inside_def n_differ_from_s_outside_def option.sel)\n  apply(simp add:abbr own\\<^sub>W_n_by_t_imp_def Rcap_def)   (*free[pop[detached[t]]]*)\n  apply (meson general_structure_def length_greater_0_conv n_differ_from_det_def)\n  apply clarify\n  by(simp add:OpSem.step_def)\n\n  \n\n\n(*--------------------------------------------------------------*)\n\n\n\n\n\n\n\n\n(*-----------------------------General Struct Supp-------------------------------------------*)\n\n(*FAAZ for n_differ*)\nlemma faaz_n_differ:\n  \" main_inv ms ps' \\<Longrightarrow>\n    t < T_max \\<Longrightarrow>\n    n_differ ms \\<Longrightarrow>\n    ms \\<sigma> s:=\\<^sup>FC t ms' \\<sigma>' \\<and> ps = ps' \\<Longrightarrow>\n    preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n    pc ms t = I8 \\<Longrightarrow>\n    psem_rules ps \\<Longrightarrow>\n    allocated_addresses ms ps' \\<Longrightarrow> n_differ ms'\"\n  unfolding general_structure_def\n  unfolding get_C_val_def FAAZ_def n_differ_def allocated_addresses_lemmas main_inv_lemmas\n  apply clarify \n  apply(case_tac \"ta\\<noteq>t\") \n  apply simp\n  apply(case_tac \"taa\\<noteq>t\") \n  apply simp\n  by meson\n  \n(*FAAZ for n_differ_from_s_outside*)\nlemma faaz_n_differ_from_s_outside:\n  \" main_inv ms ps \\<Longrightarrow>\n    general_structure ms \\<Longrightarrow>\n    t < T_max \\<Longrightarrow>\n    wfs_2 \\<sigma> \\<Longrightarrow>\n    cvd[C,l] \\<sigma> \\<Longrightarrow>\n    n_differ_from_s_outside ms \\<Longrightarrow>\n    ms \\<sigma> s:=\\<^sup>FC t ms' \\<sigma>' \\<and> ps = ps' \\<Longrightarrow>\n    preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n    pc ms t = I8 \\<Longrightarrow>\n    con_assms ms ps \\<Longrightarrow>\n    own\\<^sub>W_n_by_t_imp ms \\<Longrightarrow>\n    observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> n_differ_from_s_outside ms'\"\n  unfolding general_structure_def preCond_def own\\<^sub>W_n_by_t_imp_def\n  apply(simp add:get_C_val_def FAAZ_def n_differ_from_s_outside_def allocated_addresses_lemmas main_inv_lemmas)\n   apply clarify\n  apply(case_tac \"ta = t\")\n  apply(subgoal_tac \"n_dec ms ta\") prefer 2\n  apply meson\n  apply(subgoal_tac \"n ms ta = Some i\") prefer 2\n  apply auto[1]\n  apply clarify\n  apply(subgoal_tac \"taa \\<notin> own\\<^sub>R ms i\") prefer 2\n  apply auto[1]\n  apply(subgoal_tac \"\\<forall>loca. taa \\<notin> own\\<^sub>R ms loca \\<longrightarrow> taa\\<notin>own\\<^sub>R ms' loca\") prefer 2\n  apply auto[1]\n  apply(subgoal_tac \"\\<forall>loca. taa \\<in> own\\<^sub>R ms loca \\<longrightarrow> taa\\<in>own\\<^sub>R ms' loca\") prefer 2\n  apply auto[1]\n  apply blast\n  apply(case_tac \"taa \\<noteq> t\")\n  apply(subgoal_tac \"ta \\<noteq> t\") prefer 2 apply auto[1]\n  apply(subgoal_tac \"\\<forall>loca. taa \\<notin> own\\<^sub>R ms loca \\<longrightarrow> taa\\<notin>own\\<^sub>R ms' loca\") prefer 2\n  apply auto[1]\n  apply(subgoal_tac \"\\<forall>loca. taa \\<in> own\\<^sub>R ms loca \\<longrightarrow> taa\\<in>own\\<^sub>R ms' loca\") prefer 2\n  apply auto[1]\n  apply(subgoal_tac \"\\<forall>loca. ta \\<notin> own\\<^sub>R ms loca \\<longrightarrow> ta\\<notin>own\\<^sub>R ms' loca\") prefer 2\n  apply auto[1]\n  apply(subgoal_tac \"\\<forall>loca. ta \\<in> own\\<^sub>R ms loca \\<longrightarrow> ta\\<in>own\\<^sub>R ms' loca\") prefer 2\n  apply auto[1]\n  apply clarsimp\n  apply meson\n  apply(subgoal_tac \"taa = t\") prefer 2 apply auto[1]\n  apply(subgoal_tac \"ta \\<noteq> t\") prefer 2 apply auto[1]\n  apply clarsimp\n  apply(subgoal_tac \"\\<forall>loca. ta \\<notin> own\\<^sub>R ms loca \\<longrightarrow> ta\\<notin>own\\<^sub>R ms' loca\") prefer 2\n  apply auto[1]\n  apply(subgoal_tac \"\\<forall>loca. ta \\<in> own\\<^sub>R ms loca \\<longrightarrow> ta\\<in>own\\<^sub>R ms' loca\") prefer 2\n  apply auto[1]\n  apply(subgoal_tac \"\\<forall>loca. t \\<in> own\\<^sub>R ms loca \\<longrightarrow> t\\<in>own\\<^sub>R ms' loca\") prefer 2\n  apply auto[1]\n  apply clarsimp\n  by (smt (verit) CollectD covered_v_def observation_inv_sig_def visible_writes_def)\n\n\n\n(*FAAZ for n_differ_from_s_inside*)\nlemma faaz_n_differ_from_s_inside:\n  \" main_inv ms ps \\<Longrightarrow>\n    general_structure ms \\<Longrightarrow>\n    t < T_max \\<Longrightarrow>\n    wfs_2 \\<sigma> \\<Longrightarrow>\n    cvd[C,l] \\<sigma> \\<Longrightarrow>\n    n_differ_from_s_inside ms \\<Longrightarrow>\n    ms \\<sigma> s:=\\<^sup>FC t ms' \\<sigma>' \\<and> ps = ps' \\<Longrightarrow>\n    preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n    pc ms t = I8 \\<Longrightarrow>\n    con_assms ms ps \\<Longrightarrow>\n    own\\<^sub>W_n_by_t_imp ms \\<Longrightarrow>\n     psem_rules ps \\<Longrightarrow>\n    observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> n_differ_from_s_inside ms'\"\n  unfolding general_structure_def\n  unfolding get_C_val_def FAAZ_def n_differ_from_s_inside_def allocated_addresses_lemmas main_inv_lemmas\n  apply clarify\n  apply(subgoal_tac \"n ms t = n ms' t\") prefer 2 apply simp\n  apply(subgoal_tac \"s ms' t = Some (snd (update_trans t (a, b) (value \\<sigma> (a, b)) \\<sigma> ts', value \\<sigma> (a, b)))\") prefer 2\n  apply clarsimp apply clarsimp\n  apply(case_tac \"ta = t\", simp_all)\n  by (metis Up_reads_cvd_v observation_inv_sig_def own\\<^sub>W_n_by_t_imp_def relating_step_to_update_trans_1)\n\n\n(*FAAZ for s_differ_from_det_inside*)\nlemma faaz_s_differ_from_det_inside:\n  \" main_inv ms ps \\<Longrightarrow>\n    general_structure ms \\<Longrightarrow>\n    wfs_2 \\<sigma> \\<Longrightarrow>\n    cvd[C,l] \\<sigma> \\<Longrightarrow>\n    t < T_max \\<Longrightarrow>\n    s_differ_from_det_inside ms \\<Longrightarrow>\n    ms \\<sigma> s:=\\<^sup>FC t ms' \\<sigma>' \\<and> ps = ps' \\<Longrightarrow>\n    preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n    pc ms t = I8 \\<Longrightarrow>\n    con_assms ms ps \\<Longrightarrow>\n    own\\<^sub>W_n_by_t_imp ms \\<Longrightarrow>\n     psem_rules ps \\<Longrightarrow>\n    observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> s_differ_from_det_inside ms'\"\n  unfolding general_structure_def\n  unfolding get_C_val_def FAAZ_def s_differ_from_det_inside_def allocated_addresses_lemmas main_inv_lemmas\n  apply clarify\n  apply(case_tac \"ta\\<noteq>t\")\n  apply simp \n  apply (metis (no_types, lifting) insertE) apply clarsimp \n  by (smt (verit) CollectD covered_v_def observation_inv_sig_def own\\<^sub>W_and_det_things_def visible_writes_def)\n  \n\n(*FAAZ for n_differ_from_det*)\nlemma faaz_n_differ_from_det:\n  \" main_inv ms ps \\<Longrightarrow>\n    t < T_max \\<Longrightarrow>\n    wfs_2 \\<sigma> \\<Longrightarrow>\n    n_differ_from_det ms \\<Longrightarrow>\n    ms \\<sigma> s:=\\<^sup>FC t ms' \\<sigma>' \\<and> ps = ps' \\<Longrightarrow>\n    preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n    pc ms t = I8 \\<Longrightarrow>\n    con_assms ms ps \\<Longrightarrow>\n     psem_rules ps \\<Longrightarrow>\n    allocated_addresses ms ps \\<Longrightarrow> n_differ_from_det ms'\"\n  unfolding general_structure_def\n  unfolding get_C_val_def FAAZ_def n_differ_from_det_def allocated_addresses_lemmas main_inv_lemmas\n  apply clarify\n  apply(case_tac \"ta\\<noteq>t\")\n  apply simp\n  apply auto[1]\n  apply(case_tac \"taa\\<noteq>t\")\n  apply simp\n  apply auto[1]\n  apply clarsimp \n  by blast\n\n(*FAAZ for det_differ_from_det*)\nlemma faaz_det_differ_from_det:\n  \" main_inv ms ps \\<Longrightarrow>\n    t < T_max \\<Longrightarrow>\n    wfs_2 \\<sigma> \\<Longrightarrow>\n    det_differ_from_det ms \\<Longrightarrow>\n    ms \\<sigma> s:=\\<^sup>FC t ms' \\<sigma>' \\<and> ps = ps' \\<Longrightarrow>\n    preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n    pc ms t = I8 \\<Longrightarrow>\n    con_assms ms ps \\<Longrightarrow>\n     psem_rules ps \\<Longrightarrow>\n    allocated_addresses ms ps \\<Longrightarrow> det_differ_from_det ms'\"\n  unfolding general_structure_def\n  unfolding get_C_val_def FAAZ_def det_differ_from_det_def allocated_addresses_lemmas main_inv_lemmas\n  apply clarify\n  apply(case_tac \"ta\\<noteq>t\")\n  apply simp\n  by auto[1]\n\n(*FAAZ for det_differ_inside*)\nlemma faaz_det_differ_inside:\n  \" main_inv ms ps \\<Longrightarrow>\n    t < T_max \\<Longrightarrow>\n    wfs_2 \\<sigma> \\<Longrightarrow>\n    det_differ_inside ms \\<Longrightarrow>\n    ms \\<sigma> s:=\\<^sup>FC t ms' \\<sigma>' \\<and> ps = ps' \\<Longrightarrow>\n    preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n    pc ms t = I8 \\<Longrightarrow>\n    con_assms ms ps \\<Longrightarrow>\n    psem_rules ps \\<Longrightarrow>\n    allocated_addresses ms ps \\<Longrightarrow> det_differ_inside ms'\"\n  unfolding general_structure_def\n  unfolding get_C_val_def FAAZ_def det_differ_inside_def allocated_addresses_lemmas main_inv_lemmas\n  apply clarify\n  apply(case_tac \"ta\\<noteq>t\")\n  apply simp\n  by auto[1]\n\n(*FAAZ for own\\<^sub>W_and_det_things*)\nlemma faaz_own\\<^sub>W_and_det_things:\n  \" main_inv ms ps \\<Longrightarrow>\n    t < T_max \\<Longrightarrow>\n    wfs_2 \\<sigma> \\<Longrightarrow>\n    cvd[C,l] \\<sigma> \\<Longrightarrow> \n    own\\<^sub>W_and_det_things ms \\<Longrightarrow>\n    ms \\<sigma> s:=\\<^sup>FC t ms' \\<sigma>' \\<and> ps = ps' \\<Longrightarrow>\n    preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n    pc ms t = I8 \\<Longrightarrow>\n    con_assms ms ps \\<Longrightarrow>\n    psem_rules ps \\<Longrightarrow>\n    allocated_addresses ms ps \\<Longrightarrow>  own\\<^sub>W_and_det_things ms'\"\n  unfolding general_structure_def\n  unfolding get_C_val_def FAAZ_def own\\<^sub>W_and_det_things_def allocated_addresses_lemmas main_inv_lemmas\n  apply clarify\n  apply(case_tac \"ta\\<noteq>t\")\n  apply simp\n  by auto[1]\n\n\n\n\n\n\n\n\n(*----------------general_structure ms preservation--------------------*)\n\nlemma general_structure_preservation:\n  \"main_inv ms ps \\<Longrightarrow> \n  wfs_2 \\<sigma> \\<Longrightarrow>\n  cvd[C,l] \\<sigma> \\<Longrightarrow>\n  t<T_max \\<Longrightarrow>\n  general_structure ms \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> \n  preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n  con_assms ms ps \\<Longrightarrow>\n  own\\<^sub>W_n_by_t_imp ms \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow>\n  observation_inv_ms ms \\<Longrightarrow>\n  psem_rules ps \\<Longrightarrow>\n  allocated_addresses ms ps \\<Longrightarrow>\n  general_structure ms'\"\n  apply(simp add:step_def)\n  apply(case_tac \"pc ms t\", simp_all)\n  apply(simp add: abbr general_structure_def)\n  apply(intro conjI impI)\n  apply(simp add: n_differ_def)\n  apply blast\n  apply(simp add: n_differ_def n_differ_from_s_outside_def)\n  apply blast\n  apply (simp add: n_differ_from_s_inside_def)\n  apply (simp add: s_differ_from_det_inside_def)\n  apply(simp add:n_differ_from_det_def)\n  apply blast\n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n  apply(simp add: abbr general_structure_def)\n  apply(intro conjI impI)\n  apply(simp add: n_differ_def)\n  apply blast\n  apply(simp add: n_differ_def n_differ_from_s_outside_def)\n  apply blast\n  apply (simp add: n_differ_from_s_inside_def)\n  apply (simp add: s_differ_from_det_inside_def)\n  apply(simp add:n_differ_from_det_def)\n  apply blast\n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n  apply(simp add: abbr general_structure_def)\n  apply(intro conjI impI)\n  apply(simp add: n_differ_def)\n  apply blast\n  apply(simp add: n_differ_def n_differ_from_s_outside_def)\n  apply blast\n  apply (simp add: n_differ_from_s_inside_def)\n  apply (simp add: s_differ_from_det_inside_def)\n  apply(simp add:n_differ_from_det_def)\n  apply blast\n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n  apply(simp add: abbr general_structure_def)\n  apply(intro conjI impI)\n  apply(simp add: n_differ_def preCond_def) apply auto[1] \n  apply(case_tac \"ta = t\", simp_all) apply clarsimp\n  apply (metis (no_types, opaque_lifting) allocated_addresses_def isfree_addr_def pecpec1)\n  apply (metis (no_types, opaque_lifting) allocated_addresses_def isfree_addr_def pecpec1)\n  apply(simp add: n_differ_from_s_outside_def preCond_def) apply auto[1]\n  apply(case_tac \"ta = t\", simp add:general_structure_lemmas) apply clarsimp\n  apply (metis empty_iff isfree_addr_def main_inv_2_def main_inv_def)\n  apply(simp add:general_structure_lemmas)\n  apply (metis (no_types, opaque_lifting) allocated_addresses_def isfree_addr_def pecpec1)\n  apply(simp add:general_structure_lemmas) apply clarsimp \n  apply(case_tac \"ta = t\", simp_all)\n  apply clarsimp\n  apply(simp add:preCond_def)\n  apply(simp add:s_differ_from_det_inside_def preCond_def) apply auto[1]\n  apply (metis (no_types, lifting) insertE option.simps(3))\n  apply(simp add:n_differ_from_det_def preCond_def) apply auto[1]\n  apply (metis (no_types, opaque_lifting) allocated_addresses_def allocated_det_addr_def isfree_addr_def option.sel)\n  apply(simp add:det_differ_from_det_def preCond_def) apply auto[1]\n  apply(simp add:det_differ_inside_def) apply auto[1]\n  apply(simp add:own\\<^sub>W_and_det_things_def) apply auto[1]\n  apply (metis allocated_addresses_def allocated_det_addr_def isfree_addr_def)\n(*rcu_enter*)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n(*rcu_exit*)\n  apply(case_tac \"repeat ms t\")\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n(*rcu_enter 2*)\n  apply(case_tac \"repeat ms t\")\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n(*FAAZ*)\n  apply (metis Unique_allocs_def constant_alloc_ass_def faaz_det_differ_from_det faaz_det_differ_inside faaz_n_differ faaz_n_differ_from_det faaz_n_differ_from_s_inside faaz_n_differ_from_s_outside faaz_own\\<^sub>W_and_det_things faaz_s_differ_from_det_inside general_structure_def newran_def psem_rules_def wfs_2_def)\n(*v:=*s*)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) apply auto[1]\n  apply(simp add:s_differ_from_det_inside_def) apply auto[1] apply blast\n  apply(simp add:n_differ_from_det_def)\n  apply (metis (no_types, lifting) mstate.select_convs(3) mstate.select_convs(6) mstate.select_convs(8) mstate.surjective mstate.update_convs(1) mstate.update_convs(5))\n  apply(simp add:det_differ_from_det_def) apply auto[1]\n  apply(simp add:det_differ_inside_def) apply auto[1]\n  apply(simp add:own\\<^sub>W_and_det_things_def) apply auto[1]\n(**n:=newv*)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n(*cas_step_rcu*) \n  apply(simp add: cas_step_rcu_def general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1] apply meson apply meson\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1] apply meson apply meson\n  apply(simp add:n_differ_from_s_inside_def) apply auto[1] apply meson apply meson\n  apply(simp add:s_differ_from_det_inside_def) apply auto[1] apply blast apply blast apply blast\n  apply(simp add:n_differ_from_det_def) apply auto[1] apply blast apply (metis (no_types, lifting)) apply (metis (no_types, lifting))\n  apply(simp add:det_differ_from_det_def) apply auto[1]\n  apply(simp add:det_differ_inside_def) apply auto[1]\n  apply(simp add:own\\<^sub>W_and_det_things_def) apply auto[1]\n  apply(case_tac \"det ms ta ! i = yb\", simp_all) apply auto[1]\n  apply(simp add:observation_inv_sig_def)\n  apply(simp add:CAS_def)\n  apply(case_tac \"value \\<sigma> (a, b) = det ms ta ! i\", simp_all)\n  using visible_writes_def covered_v_def\n  apply (smt (verit) CollectD)\n  apply (simp add: n_differ_from_det_def)\n (*rcu_exit*)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n(*go_to_I14*)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def)\n  apply(simp add:n_differ_from_det_def)\n  apply(simp add:n_differ_from_det_def)\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n(*repeat?*)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:n_differ_from_s_outside_def)\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n(*CAS_succ choice*)\n  apply(case_tac \"CAS_succ ms t\", simp_all)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n(*insert[detached[t],s]*)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) \n  apply(simp add:n_differ_from_det_def own\\<^sub>W_n_by_t_imp_def) \n  apply clarsimp\n  apply(intro conjI impI)\n  apply auto[1]\n  apply (smt (verit) Wcap_def bot_nat_0.extremum_strict insertCI less_Suc_eq list.size(3) nth_append nth_append_length option.sel)\n  apply auto[1]\n  apply blast\n  apply(simp add:det_differ_from_det_def own\\<^sub>W_n_by_t_imp_def) apply auto[1]\n  apply (smt (verit) Wcap_def bot_nat_0.extremum_strict insertCI less_Suc_eq list.size(3) map_upd_eqD1 nth_append nth_append_length own\\<^sub>W_and_det_things_def)\n  apply (smt (verit) Wcap_def aap_supplem_1 diff_is_0_eq diff_zero insertCI less_Suc_eq less_Suc_eq_le list.size(3) map_upd_eqD1 nth_append_length own\\<^sub>W_and_det_things_def)\n  apply(simp add:det_differ_inside_def det_differ_from_det_def own\\<^sub>W_n_by_t_imp_def) apply auto[1]\n  apply safe\n  apply(simp add:own\\<^sub>W_and_det_things_def s_differ_from_det_inside_def)\n  apply (smt (verit) Rcap_def aap_supplem_1 bot_nat_0.extremum_strict insertCI less_Suc_eq list.size(3) nth_append_length)\n  apply(simp add:own\\<^sub>W_and_det_things_def s_differ_from_det_inside_def det_differ_inside_def)\n  apply auto[1] \n  apply(subgoal_tac \"\\<forall>i. i<length(det ms t) \\<longrightarrow> own\\<^sub>W ms ((det ms t) ! i) = Some t\") prefer 2  \n  apply (metis gr_implies_not_zero list.size(3))  \n  apply (metis (no_types, lifting) Wcap_def insertCI less_Suc_eq nth_append nth_append_length)\n(*nondet()*)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n(*nondet choice*)\n  apply(case_tac \"nondet_val ms t\", simp_all)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n(*move_to_r5 if det ms t=[]*)\n  apply(case_tac \"det ms t \\<noteq> []\", simp_all)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n(*free[pop[detached[t]]]*)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply (smt (z3) One_nat_def diff_less length_greater_0_conv length_tl lessI less_trans_Suc nth_tl)\n  apply(simp add:det_differ_from_det_def) \n  apply (simp add: less_diff_conv nth_tl)\n  apply(simp add:det_differ_inside_def) \n  apply (simp add: less_diff_conv nth_tl)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n  apply (simp add: less_diff_conv nth_tl)\n  apply (metis (no_types, lifting) Nitpick.size_list_simp(2) Suc_less_eq det_differ_from_det_def det_differ_inside_def length_greater_0_conv nat.distinct(1) nth_tl)\n(*r[N]:={0}*)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n(*if CRTsync1 then...splits*)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t = t\", simp_all)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n(*r[i]:=rcu[CTRsync\\<^sub>1 ms t]*)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) apply auto[1]\n  apply(simp add:s_differ_from_det_inside_def) apply auto[1] apply blast\n  apply(simp add:n_differ_from_det_def) apply auto[1] apply blast\n  apply(simp add:det_differ_from_det_def) apply auto[1]\n  apply(simp add:det_differ_inside_def) apply auto[1]\n  apply(simp add:own\\<^sub>W_and_det_things_def) apply auto[1]\n(*if CTRsync\\<^sub>2 ms t < T_max splits*)\n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n(*r ms t (CTRsync\\<^sub>2 ms t) = 0 splits*)\n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n(*loadCTRsync\\<^sub>2*)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) apply auto[1]\n  apply(simp add:s_differ_from_det_inside_def) apply auto[1] apply blast\n  apply(simp add:n_differ_from_det_def) apply auto[1] apply blast\n  apply(simp add:det_differ_from_det_def) apply auto[1]\n  apply(simp add:det_differ_inside_def) apply auto[1]\n  apply(simp add:own\\<^sub>W_and_det_things_def) apply auto[1]\n(*reg ms t = Suc 0 splits*)\n  apply(case_tac \"reg ms t = Suc 0\", simp_all)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  apply(simp add:own\\<^sub>W_and_det_things_def)\n  apply(simp add: abbr general_structure_def preCond_def)\n  apply(intro conjI impI)\n  apply(simp add:n_differ_def) apply auto[1]\n  apply(simp add:n_differ_from_s_outside_def) apply auto[1]\n  apply(simp add:n_differ_from_s_inside_def) \n  apply(simp add:s_differ_from_det_inside_def) apply auto[1]\n  apply(simp add:n_differ_from_det_def) \n  apply(simp add:det_differ_from_det_def)\n  apply(simp add:det_differ_inside_def)\n  by(simp add:own\\<^sub>W_and_det_things_def)\n\n\n(*--------------------------------------------------------------------*)\n\n\n\n\n\n\n\n(*----------------Local Correctness--------------------*)\n\nlemma Local_Correctness_preservation:\n  \"main_inv ms ps \\<Longrightarrow> \n  t<T_max \\<Longrightarrow>\n  wfs_2 \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> \n  preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n  con_assms ms ps \\<Longrightarrow>\n  general_structure ms \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow>\n  observation_inv_ms ms \\<Longrightarrow>\n  own\\<^sub>W_n_by_t_imp ms \\<Longrightarrow>\n  allocated_addresses ms ps \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms' t) t\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms t\", simp_all)\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(simp add:abbr Rcap_def Wcap_def) \n  apply (meson insertI1)\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(case_tac \"repeat ms t\", simp_all)\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(intro conjI impI) \n  apply clarsimp\n  apply(simp add:general_structure_lemmas) apply clarify\n  apply (metis less_nat_zero_code list.size(3))\n  apply meson\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(simp add:abbr Rcap_def Wcap_def get_C_val_def) apply clarsimp\n  apply(intro conjI impI)\n  apply(simp add:Rcap_def)\n  apply(simp add:Wcap_def) \n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(simp add:abbr Rcap_def Wcap_def) \n(*cas_step*) defer\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply (metis own\\<^sub>W_n_by_t_imp_def)\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(case_tac \"CAS_succ ms t\", simp_all) \n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(simp add:general_structure_def own\\<^sub>W_and_det_things_def)\n  apply(simp add:main_inv_lemmas) apply clarsimp\n  apply(subgoal_tac \"length(det ms t @ [ya]) = Suc(length(det ms t))\") prefer 2\n  apply (meson length_append_singleton)\n  apply (metis aap_supplem_1 bot_nat_0.extremum_strict less_Suc_eq list.size(3) nth_append_length)\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(case_tac \"nondet_val ms t\", simp_all)\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(case_tac \"det ms t \\<noteq> [] \", simp_all)\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp defer\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp defer\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all)\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(case_tac \"CTRsync\\<^sub>1 ms t = t\", simp_all)\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n(*r[i]:=rcu[counter]*) defer\n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all)\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all)\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n(*load(counter)*) defer\n  apply(case_tac \"reg ms t = Suc 0\", simp_all)\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n(*dealing with cas_step_rcu*)\n  apply(simp add:cas_step_rcu_def) apply clarsimp\n  apply(case_tac \"ya\", simp_all)\n  apply(simp add:abbr Rcap_def Wcap_def) apply clarsimp\n  apply (metis general_structure_def less_nat_zero_code list.size(3) n_differ_from_det_def)\n  apply(simp add:abbr Rcap_def Wcap_def) defer defer\n(*dealing with r[i]:=rcu[counter]*)\n  apply(simp add:load_rcu_to_r_def) apply clarsimp\n  apply(simp add:abbr Rcap_def Wcap_def)\n(*dealing with rcu_temp_copy*)\n  apply(simp add:rcu_temp_copy_def)\n  apply clarsimp \n  apply(simp add:abbr Rcap_def Wcap_def) defer\n  apply(intro conjI impI)\n  apply (simp add: det_differ_inside_def general_structure_def nth_tl)\n  apply(subgoal_tac \"\\<forall>j. j<length(det ms t) \\<longrightarrow> own\\<^sub>W ms (det ms t!j) = Some t\") prefer 2 \n  apply blast\n  apply safe\n  sledgehammer\n  sorry\n(*--------------------------------------------------------------------*)\n\n\n\n\n\n\n(*----------------- Supporting Global Correctness -----------------*)\n\nlemma Global_Correctness_preservation_S1:\n  \"pc ms t = S1 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr)\n  apply(simp_all add:abbr Rcap_def Wcap_def)\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] by auto[1]\n\n\n\nlemma Global_Correctness_preservation_S2:\n  \"pc ms t = S2 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr)\n  apply(case_tac[!] \"CTRsync\\<^sub>1 ms t < T_max\", simp_all add:abbr)\n  apply(case_tac[!] \"CTRsync\\<^sub>1 ms t = t\", simp_all add:abbr Rcap_def Wcap_def)\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] apply auto[1]\n  apply auto[1] apply auto[1] apply auto[1] by auto[1]\n\n\n\n\nlemma Global_Correctness_preservation_S3:\n  \"pc ms t = S3 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr)\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) \n  apply(simp add:Rcap_def Wcap_def) \n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify apply auto[1]\n  apply(simp add:Rcap_def Wcap_def) apply clarify by auto[1]\n\n\n\n\n\n\n\n\nlemma Global_Correctness_preservation_S4:\n  \"pc ms t = S4 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr)\n  apply(case_tac[!] \"CTRsync\\<^sub>2 ms t < T_max\", simp_all add:abbr)\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply(simp add:Rcap_def Wcap_def)\n  apply(simp add:Rcap_def Wcap_def) apply(simp add:Rcap_def Wcap_def)\n  apply(simp add:Rcap_def Wcap_def) apply(simp add:Rcap_def Wcap_def)\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) by metis\n\n\n\n\n\n\nlemma Global_Correctness_preservation_S5:\n  \"pc ms t = S5 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr)\n  apply(case_tac[!] \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all add:abbr)\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply(simp add:Rcap_def Wcap_def)\n  apply(simp add:Rcap_def Wcap_def) apply(simp add:Rcap_def Wcap_def)\n  apply(simp add:Rcap_def Wcap_def) apply(simp add:Rcap_def Wcap_def)\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) by metis\n\n\n\n\n\n\nlemma Global_Correctness_preservation_S6:\n  \"pc ms t = S6 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  apply (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n  apply(simp add:Rcap_def Wcap_def) \n  by (metis canonically_ordered_monoid_add_class.lessE con_assms_def counters_limit_def le_neq_implies_less not_add_less1)\n\n\n\n\n\nlemma Global_Correctness_preservation_S7:\n  \"pc ms t = S7 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr)\n  apply(case_tac[!] \"reg ms t = Suc 0\", simp_all add:abbr)\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply(simp add:Rcap_def Wcap_def) \n  apply(simp add:Rcap_def Wcap_def) apply(simp add:Rcap_def Wcap_def) \n  apply(simp add:Rcap_def Wcap_def) apply(simp add:Rcap_def Wcap_def) \n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) by metis\n\n\n\n\n\n\n\n\nlemma Global_Correctness_preservation_R1:\n  \"pc ms t = R1 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr)\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply(simp add:Rcap_def Wcap_def) apply(simp add:Rcap_def Wcap_def) \n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis apply(simp add:Rcap_def Wcap_def) by metis\n\n\n\n\nlemma Global_Correctness_preservation_R2:\n  \"pc ms t = R2 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) apply(case_tac \"b\", simp_all)\n  apply(simp add:Rcap_def Wcap_def) apply(clarify) by(case_tac \"b\", simp_all)\n\n\n\n\nlemma Global_Correctness_preservation_R3:\n  \"pc ms t = R3 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr)\n  apply(case_tac[!] \"nondet_val ms t\", simp_all add:abbr)\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) \n  apply(simp add:Rcap_def Wcap_def) \n  apply(simp add:Rcap_def Wcap_def) \n  apply(simp add:Rcap_def Wcap_def) \n  apply(simp add:Rcap_def Wcap_def) \n  apply(simp add:Rcap_def Wcap_def) \n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) by metis\n\n\n\n\nlemma Global_Correctness_preservation_R4:\n  \"pc ms t = R4 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr)\n  apply(case_tac[!] \"det ms t \\<noteq> []\", simp_all add:abbr)\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) \n  apply(simp add:Rcap_def Wcap_def) \n  apply(simp add:Rcap_def Wcap_def) \n  apply(simp add:Rcap_def Wcap_def) \n  apply(simp add:Rcap_def Wcap_def) \n  apply(simp add:Rcap_def Wcap_def) \n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) apply metis\n  apply(simp add:Rcap_def Wcap_def) by metis\n\n\n\n\nlemma Global_Correctness_preservation_R5:\n  \"pc ms t = R5 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr)\n  apply(intro conjI impI)\n  apply(simp add:Rcap_def Wcap_def)\n  apply(simp add:Rcap_def Wcap_def)\n  apply (metis length_greater_0_conv singleton_iff)\n  apply(intro conjI impI)\n  apply(simp add:Rcap_def Wcap_def)\n  apply(simp add:Rcap_def Wcap_def)\n  apply (metis length_greater_0_conv singleton_iff)\n  apply(intro conjI impI)\n  apply(simp add:Rcap_def Wcap_def)\n  apply(simp add:Rcap_def Wcap_def)\n  apply (metis length_greater_0_conv singleton_iff)\n  apply(intro conjI impI)\n  apply(simp add:Rcap_def Wcap_def)\n  apply(simp add:Rcap_def Wcap_def)\n  apply (metis length_greater_0_conv singleton_iff)\n  apply(intro conjI impI)\n  apply(simp add:Rcap_def Wcap_def)\n  apply(simp add:Rcap_def Wcap_def)\n  apply (metis length_greater_0_conv singleton_iff)\n  apply(case_tac \"repeat ms ta\", simp_all)\n  apply(intro conjI impI)\n  apply(simp add:Rcap_def Wcap_def)\n  apply (metis length_greater_0_conv singleton_iff)\n  apply(simp add:Rcap_def Wcap_def)\n  apply(simp add:Rcap_def Wcap_def)\n  apply (metis con_assms_def counters_limit_def leD)\n  apply(simp add:Rcap_def Wcap_def)\n  apply (metis con_assms_def counters_limit_def leD)\n  apply(simp add:Rcap_def Wcap_def)\n  apply (metis con_assms_def counters_limit_def leD)\n  apply(simp add:Rcap_def Wcap_def)\n  apply (metis length_greater_0_conv singleton_iff)\n  apply(simp add:Rcap_def Wcap_def)\n  apply (metis length_greater_0_conv singleton_iff)\n  apply(simp add:Rcap_def Wcap_def)\n  apply (metis length_greater_0_conv singleton_iff)\n  apply(simp add:Rcap_def Wcap_def)\n  apply (metis length_greater_0_conv singleton_iff)\n  apply(simp add:Rcap_def Wcap_def)\n  apply (metis length_greater_0_conv singleton_iff)\n  apply(simp add:Rcap_def Wcap_def)\n  apply (metis length_greater_0_conv singleton_iff)\n  apply(simp add:Rcap_def Wcap_def)\n  apply (metis length_greater_0_conv singleton_iff)\n  apply(simp add:Rcap_def Wcap_def)\n  apply (metis length_greater_0_conv singleton_iff)\n  apply(simp add:Rcap_def Wcap_def)\n  apply (metis length_greater_0_conv singleton_iff)\n  apply(simp add:Rcap_def Wcap_def)\n  apply (metis length_greater_0_conv singleton_iff)\n  apply(simp add:Rcap_def Wcap_def)\n  apply (metis length_greater_0_conv singleton_iff)\n  apply(intro conjI impI)\n  apply (metis con_assms_def counters_limit_def leD)\n  apply (metis con_assms_def counters_limit_def leD)\n  apply (metis con_assms_def counters_limit_def leD)\n  apply (metis con_assms_def counters_limit_def leD)\n  apply (metis con_assms_def counters_limit_def leD)\n  apply (metis con_assms_def counters_limit_def leD)\n  apply (metis con_assms_def counters_limit_def leD)\n  apply (metis con_assms_def counters_limit_def leD)\n  by (metis con_assms_def counters_limit_def leD)\n\n\n\nlemma Global_Correctness_preservation_cas_res:\n  \"pc ms t = cas_res \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr cas_step_rcu_def Rcap_def Wcap_def)\n  apply(case_tac[!] \"CAS_succ ms t\", simp_all add:abbr)\n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) by(clarify, simp) \n\n\n\n\nlemma Global_Correctness_preservation_I1:\n  \"pc ms t = I1 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr cas_step_rcu_def Rcap_def Wcap_def)\n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) by(clarify, simp) \n\n\n\nlemma Global_Correctness_preservation_I2:\n  \"pc ms t = I2 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr cas_step_rcu_def Rcap_def Wcap_def)\n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) by(clarify, simp) \n\n\nlemma Global_Correctness_preservation_I3:\n  \"pc ms t = I3 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr cas_step_rcu_def Rcap_def Wcap_def)\n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) by(clarify, simp) \n\n\n\n\n\nlemma Global_Correctness_preservation_I4:\n  \"pc ms t = I4 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr cas_step_rcu_def Rcap_def Wcap_def)\n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply(case_tac \"repeat ms ta\", simp_all)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply(case_tac \"CAS_succ ms ta\", simp_all)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject)\n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis con_assms_def counters_limit_def leD)\n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  apply (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  apply(clarify, simp add:observation_inv_ms_def allocated_addresses_lemmas)\n  by (metis insert_iff less_nat_zero_code list.size(3) option.inject) \n  \n\n\nlemma Global_Correctness_preservation_I5:\n  \"pc ms t = I5 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr cas_step_rcu_def Rcap_def Wcap_def)\n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) by(clarify, simp) \n\n\nlemma Global_Correctness_preservation_I6:\n  \"pc ms t = I6 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr cas_step_rcu_def Rcap_def Wcap_def)\n  apply(case_tac[!] \"repeat ms t\", simp_all)\n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) by(clarify, simp)\n\n\n\n\n\nlemma Global_Correctness_preservation_I7:\n  \"pc ms t = I7 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr cas_step_rcu_def Rcap_def Wcap_def)\n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) by(clarify, simp) \n\n\n\n\n\n\nlemma Global_Correctness_preservation_I8:\n  \"pc ms t = I8 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr get_C_val_def FAAZ_def cas_step_rcu_def Rcap_def Wcap_def)\n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(case_tac \"repeat ms t\", simp_all)\n  apply (metis con_assms_def counters_limit_def leD)\n  apply (metis con_assms_def counters_limit_def leD)\n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  by(clarify, simp) \n\n\n\n\n\n\n\nlemma Global_Correctness_preservation_I9:\n  \"pc ms t = I9 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr cas_step_rcu_def Rcap_def Wcap_def)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply(case_tac \"CAS_succ ms ta\", simp_all)\n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) apply(clarify, simp) apply(clarify, simp) \n  apply(clarify, simp) by(clarify, simp)\n\n\n\n\n\nlemma Global_Correctness_preservation_I10:\n  \"pc ms t = I10 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr cas_step_rcu_def Rcap_def Wcap_def)\n  apply metis apply metis apply metis apply metis apply metis\n  apply metis apply metis apply metis apply metis apply metis\n  apply metis apply metis apply metis apply metis apply metis\n  apply metis apply metis apply metis apply metis apply metis\n  apply metis apply metis apply metis by metis\n\n\n\n\nlemma Global_Correctness_preservation_I11:\n  \"pc ms t = I11 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> observation_inv_ms ms \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr cas_step_rcu_def Rcap_def Wcap_def)\n  apply(intro conjI impI)\n  apply(clarify , case_tac \"ya\", simp_all)\n  apply(clarify , case_tac \"ya\", simp_all)\n  apply auto[1]\n  apply (meson general_structure_def n_differ_from_s_outside_def)\n  apply (meson general_structure_def n_differ_from_s_outside_def)\n  apply (simp add: general_structure_lemmas)\n  apply(subgoal_tac \"n ms ta \\<noteq> Some yb\") prefer 2\n  apply (metis option.distinct(1))\n  apply(subgoal_tac \"s ms ta \\<noteq> Some yb\") prefer 2\n  apply presburger\n  apply(subgoal_tac \"\\<forall>i. i<length (det ms ta) \\<longrightarrow> det ms ta !i \\<noteq> vala\") prefer 2\n  apply(simp add:observation_inv_sig_def)\n  apply metis\n  apply(simp add:CAS_def visible_writes_def covered_v_def)\n  apply (metis Pair_inject)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(clarify)\n  apply(intro conjI impI)\n  apply (metis option.inject)\n  apply (metis option.inject)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply(case_tac \"vala = yb\", simp_all)\n  apply metis\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(clarify)\n  apply(intro conjI impI)\n  apply (metis option.inject)\n  apply (metis option.inject)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply(case_tac \"vala = yb\", simp_all)\n  apply metis\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(clarify)\n  apply(intro conjI impI)\n  apply (metis option.inject)\n  apply (metis option.inject)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply(case_tac \"vala = yb\", simp_all)\n  apply metis\n  apply(clarify, case_tac \"yb\", simp_all)\n  apply(clarify)\n  apply(intro conjI impI)\n  apply (metis option.inject)\n  apply (metis option.inject)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis Pair_inject)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis option.inject prod.inject)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis option.sel prod.inject)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis option.sel prod.inject)\n  apply(clarify, case_tac \"yb\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis option.sel prod.inject)\n  apply(clarify, case_tac \"yb\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis option.sel prod.inject)\n  apply(clarify, case_tac \"yb\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis option.sel prod.inject)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis option.sel prod.inject)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis option.sel prod.inject)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis option.sel prod.inject)\n  apply(clarify, case_tac \"yb\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply(case_tac \"vala = yd\", simp_all)\n  apply(case_tac \"CAS_succ ms ta\", simp_all)\n  apply (metis option.sel)\n  apply (metis option.sel)\n  apply metis\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis option.sel prod.inject)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis option.sel prod.inject)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis option.sel prod.inject)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis option.sel prod.inject)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis option.sel prod.inject)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis option.sel prod.inject)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis option.sel prod.inject)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis option.sel prod.inject)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis option.sel prod.inject)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis option.sel prod.inject)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  apply (metis option.sel prod.inject)\n  apply(clarify, case_tac \"ya\", simp_all)\n  apply(simp add:CAS_def visible_writes_def covered_v_def observation_inv_sig_def)\n  by (metis option.sel prod.inject)\n  \n  \n\n\n\n\nlemma Global_Correctness_preservation_I12:\n  \"pc ms t = I12 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr Rcap_def Wcap_def)\n  by metis+\n\nlemma Global_Correctness_preservation_I13:\n  \"pc ms t = I13 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr Rcap_def Wcap_def)\n  by metis+\n\n\n\nlemma Global_Correctness_preservation_I14:\n  \"pc ms t = I14 \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (simp_all add:step_def preCond_def)\n  apply(case_tac \"pc ms ta\", simp_all add:abbr Rcap_def Wcap_def)\n  by metis+\n\n\nlemma Global_Correctness_preservation_finished:\n  \"pc ms t = finished \\<Longrightarrow>\n  main_inv ms ps \\<Longrightarrow>  t<T_max \\<Longrightarrow> ta<T_max \\<Longrightarrow> t\\<noteq>ta \\<Longrightarrow> wfs_2 \\<sigma> \\<Longrightarrow> cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow> psem_rules ps \\<Longrightarrow> allocated_addresses ms ps \\<Longrightarrow> con_assms ms ps \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  by (simp_all add:step_def preCond_def)\n\n\n\n(*----------------Global Correctness--------------------*)\n\nlemma Global_Correctness_preservation:\n  \"main_inv ms ps \\<Longrightarrow> \n  t<T_max \\<Longrightarrow>\n  ta<T_max \\<Longrightarrow>\n  t\\<noteq>ta \\<Longrightarrow>\n  wfs_2 \\<sigma> \\<Longrightarrow>\n  cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> \n  preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n  preCond ms ps \\<sigma> (pc ms ta) ta \\<Longrightarrow> \n  general_structure ms \\<Longrightarrow>\n  psem_rules ps \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow> \n  observation_inv_ms ms \\<Longrightarrow>\n  allocated_addresses ms ps \\<Longrightarrow>\n  con_assms ms ps \\<Longrightarrow>\n  preCond ms' ps' \\<sigma>' (pc ms ta) ta\"\n  apply (case_tac \"pc ms t\")\n  using Global_Correctness_preservation_I1 apply blast\n  using Global_Correctness_preservation_I2 apply blast\n  using Global_Correctness_preservation_I3 apply blast\n  using Global_Correctness_preservation_I4 apply blast\n  using Global_Correctness_preservation_I5 apply blast\n  using Global_Correctness_preservation_I6 apply blast\n  using Global_Correctness_preservation_I7 apply blast\n  using Global_Correctness_preservation_I8 apply blast\n  using Global_Correctness_preservation_I9 apply blast\n  using Global_Correctness_preservation_I10 apply blast\n  using Global_Correctness_preservation_I11 apply blast\n  using Global_Correctness_preservation_I12 apply blast\n  using Global_Correctness_preservation_I13 apply blast\n  using Global_Correctness_preservation_I14 apply blast\n  using Global_Correctness_preservation_cas_res apply blast\n  using Global_Correctness_preservation_finished apply blast\n  using Global_Correctness_preservation_R1 apply blast\n  using Global_Correctness_preservation_R2 apply blast\n  using Global_Correctness_preservation_R3 apply blast\n  using Global_Correctness_preservation_R4 apply blast\n  using Global_Correctness_preservation_R5 apply blast\n  using Global_Correctness_preservation_S1 apply blast\n  using Global_Correctness_preservation_S2 apply blast\n  using Global_Correctness_preservation_S3 apply blast\n  using Global_Correctness_preservation_S4 apply blast\n  using Global_Correctness_preservation_S5 apply blast\n  using Global_Correctness_preservation_S6 apply blast\n  using Global_Correctness_preservation_S7 by blast\n\n\n\n\n(*--------------------------------------------------------------------*)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n(*=======================================================*)\n(*+++++++++++++++++++these \"MIGHT\" be useful+++++++++++++*)\n(*=======================================================*)\n\n(*---------------counter2_rule ms------------------------*)\n\nlemma Local_counter2_rule:\n  \"main_inv ms ps \\<Longrightarrow> \n  t<T_max \\<Longrightarrow>\n  wfs_2 \\<sigma> \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> \n  preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n  counter2_rule ms \\<Longrightarrow>\n  con_assms ms ps \\<Longrightarrow>\n  general_structure ms \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow>\n  observation_inv_ms ms \\<Longrightarrow>\n  psem_rules ps \\<Longrightarrow> \n  own\\<^sub>W_n_by_t_imp ms \\<Longrightarrow>\n  allocated_addresses ms ps \\<Longrightarrow>\n  counter2_rule ms'\"\n  apply (simp_all add:step_def preCond_def counter2_rule_def)\n  apply(case_tac \"pc ms t\", simp_all add:abbr)\n  apply clarsimp\n  apply(simp split: if_splits)\n  apply(simp add:general_structure_def n_differ_from_det_def Rcap_def own\\<^sub>W_and_det_things_def)\n  apply(simp add:allocated_addresses_lemmas)\n  apply (metis less_nat_zero_code list.size(3))\n  apply blast\n  apply clarsimp \n  apply(case_tac \"repeat ms t\", simp)\n  apply (metis (no_types, lifting) DiffD1)\n  apply blast  \n  defer (*FAAZ*)\n  apply clarsimp\n  apply blast\n  apply clarsimp\n  apply(case_tac \"snd (CAS t (a, b) ya y \\<sigma> ts')\", simp_all)\n  apply blast\n  apply blast\n  apply clarsimp\n  apply(case_tac \"CAS_succ ms t\", simp_all add:abbr)\n  apply blast\n  apply blast\n  apply auto[1]\n  apply clarsimp\n  apply blast\n  apply(case_tac \"nondet_val ms t\", simp_all add:abbr)\n  apply(case_tac \"det ms t \\<noteq> []\", simp_all add:abbr)\n  apply clarsimp\n  \n\n\n  sorry\n", "meta": {"author": "MSemenyuk", "repo": "PhD_Isabelle", "sha": "179f5d346a721b15940a271323e3487f4ea51338", "save_path": "github-repos/isabelle/MSemenyuk-PhD_Isabelle", "path": "github-repos/isabelle/MSemenyuk-PhD_Isabelle/PhD_Isabelle-179f5d346a721b15940a271323e3487f4ea51338/Treiber Stack C11/RCU.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6113819732941511, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.29614125174964995}}
{"text": "(*<*)\ntheory BenOr_Proofs\nimports Heard_Of.Reduction\n  Two_Step_Observing \"../HO_Transition_System\" BenOr_Defs\nbegin\n(*>*)\n\nsubsection \\<open>Proofs\\<close>\n\ntype_synonym ben_or_TS_state = \"(nat \\<times> (process \\<Rightarrow> (val pstate)))\"\n\nconsts \n  val0 :: val \n  val1 :: val\n\ntext \\<open>Ben-Or works only on binary values.\\<close>\naxiomatization where \n  val_exhaust: \"v = val0 \\<or> v = val1\"\n  and val_diff: \"val0 \\<noteq> val1\"\n\ncontext mono_quorum\nbegin\n\ndefinition BenOr_Alg :: \"(process, val pstate, val msg)CHOAlgorithm\" where\n  \"BenOr_Alg = CHOAlgorithm.truncate BenOr_M\"\n\ndefinition BenOr_TS ::\n  \"(round \\<Rightarrow> process HO) \\<Rightarrow> (round \\<Rightarrow> process HO) \\<Rightarrow> (round \\<Rightarrow> process) \\<Rightarrow> ben_or_TS_state TS\"\nwhere\n  \"BenOr_TS HOs SHOs crds = CHO_to_TS BenOr_Alg HOs SHOs (K o crds)\"\n\nlemmas BenOr_TS_defs = BenOr_TS_def CHO_to_TS_def BenOr_Alg_def CHOinitConfig_def\n  BenOr_initState_def\n\ntype_synonym rHO = \"nat \\<Rightarrow> process HO\"\n\ndefinition BenOr_trans_step \n  where\n  \"BenOr_trans_step HOs SHOs nxt_f snd_f stp \\<equiv> \\<Union>r \\<mu>.\n    {((r, cfg), (Suc r, cfg'))|cfg cfg'. two_step r = stp  \\<and> (\\<forall>p.\n      \\<mu> p \\<in> get_msgs (snd_f r) cfg (HOs r) (SHOs r) p\n      \\<and> nxt_f r p (cfg p) (\\<mu> p) (cfg' p)\n    )}\"\n\nlemma two_step_less_D:\n  \"0 < two_step r \\<Longrightarrow> two_step r = Suc 0\"\n  by(auto simp add: two_step_def)\n\nlemma BenOr_trans:\n  \"CSHO_trans_alt BenOr_sendMsg (\\<lambda>r p st msgs crd st'. BenOr_nextState r p st msgs st') HOs SHOs crds = \n  BenOr_trans_step HOs SHOs next0 send0 0\n  \\<union> BenOr_trans_step HOs SHOs  next1 send1 1\n  \"\nproof\n  show \"CSHO_trans_alt BenOr_sendMsg (\\<lambda>r p st msgs crd. BenOr_nextState r p st msgs) HOs SHOs crds\n    \\<subseteq> BenOr_trans_step HOs SHOs next0 send0 0 \\<union> BenOr_trans_step HOs SHOs next1 send1 1\"\n  by(force simp add: CSHO_trans_alt_def BenOr_sendMsg_def BenOr_nextState_def BenOr_trans_step_def \n    K_def dest!: two_step_less_D)\nnext\n  show \" BenOr_trans_step HOs SHOs next0 send0 0 \\<union>\n    BenOr_trans_step HOs SHOs next1 send1 1\n    \\<subseteq> CSHO_trans_alt BenOr_sendMsg\n        (\\<lambda>r p st msgs crd. BenOr_nextState r p st msgs) HOs SHOs crds\"\n  by(force simp add: CSHO_trans_alt_def BenOr_sendMsg_def BenOr_nextState_def BenOr_trans_step_def)\nqed\n\ndefinition \"BenOr_A = CHOAlgorithm.truncate BenOr_M\"\n\nsubsubsection \\<open>Refinement\\<close>\n(******************************************************************************)\n\ntext \\<open>Agreement for BenOr only holds if the communication predicates hold\\<close>\ncontext\n  fixes\n    HOs :: \"nat \\<Rightarrow> process \\<Rightarrow> process set\"\n    and rho :: \"nat \\<Rightarrow> process \\<Rightarrow> val pstate\"\n  assumes comm_global: \"BenOr_commGlobal HOs\"\n  and per_rd: \"\\<forall>r. BenOr_commPerRd (HOs r)\"\n  and run: \"HORun BenOr_A rho HOs\"\nbegin\n(******************************************************************************)\n\ndefinition no_vote_diff where\n  \"no_vote_diff sc p \\<equiv> vote (sc p) = None \\<longrightarrow>\n            (\\<exists>q q'. x (sc q) \\<noteq> x (sc q'))\"\n\ndefinition ref_rel :: \"(tso_state \\<times> ben_or_TS_state)set\" where\n  \"ref_rel \\<equiv> {(sa, (r, sc)).\n    r = next_round sa\n    \\<and> (two_step r = 1 \\<longrightarrow> r_votes sa = vote o sc)\n    \\<and> (two_step r = 1 \\<longrightarrow> (\\<forall>p. no_vote_diff sc p))\n    \\<and> (\\<forall>p v. x (sc p) = v \\<longrightarrow> (\\<exists>q. last_obs sa q \\<in> {None, Some v}))\n    \\<and> decisions sa = decide o sc\n  }\"\n\nlemma HOs_intersect:\n  \"HOs r p \\<inter> HOs r' q \\<noteq> {}\" using per_rd\n  apply(simp add: BenOr_commPerRd_def)\n  apply(blast dest: qintersect)\n  done\n\nlemma HOs_nonempty:\n  \"HOs r p \\<noteq> {}\" \n  using HOs_intersect\n  by blast\n\nlemma vote_origin:\n  assumes\n  send: \"\\<forall>p. \\<mu> p \\<in> get_msgs (send0 r) cfg (HOs r) (HOs r) p\"\n  and step: \"\\<forall>p. next0 r p (cfg p) (\\<mu> p) (cfg' p)\"\n  and step_r: \"two_step r = 0\"\n  shows \n    \"vote (cfg' p) = Some v \\<longleftrightarrow> (\\<forall>q \\<in> HOs r p. x (cfg q) = v)\" \n  using send[THEN spec, where x=p] step[THEN spec, where x=p] step_r HOs_nonempty\n  by(auto simp add: next0_def get_msgs_benign send0_def msgRcvd_def o_def restrict_map_def)\n  \nlemma same_new_vote:\n  assumes \n  send: \"\\<forall>p. \\<mu> p \\<in> get_msgs (send0 r) cfg (HOs r) (HOs r) p\"\n  and step: \"\\<forall>p. next0 r p (cfg p) (\\<mu> p) (cfg' p)\"\n  and step_r: \"two_step r = 0\"\n  obtains v where \"\\<forall>p w. vote (cfg' p) = Some w \\<longrightarrow> w = v\" \nproof(cases \"\\<exists>p v. vote (cfg' p) = Some v\")\n  case True\n  assume asm: \"\\<And>v. \\<forall>p w. vote (cfg' p) = Some w \\<longrightarrow> w = v \\<Longrightarrow> thesis\"\n  from True obtain p v where \"vote (cfg' p) = Some v\" by auto\n\n  hence \"\\<forall>p w. vote (cfg' p) = Some w \\<longrightarrow> w = v\" (is \"?LV(v)\")\n    using vote_origin[OF send step step_r] HOs_intersect\n    by(force)\n\n  from asm[OF this] show ?thesis .\nqed(auto)\n\nlemma no_x_change:\n  assumes\n  send: \"\\<forall>p. \\<mu> p \\<in> get_msgs (send0 r) cfg (HOs r) (HOs r) p\"\n  and step: \"\\<forall>p. next0 r p (cfg p) (\\<mu> p) (cfg' p)\"\n  and step_r: \"two_step r = 0\"\n  shows \n    \"x (cfg' p) = x (cfg p)\" \n  using send[THEN spec, where x=p] step[THEN spec, where x=p] step_r HOs_nonempty\n  by(auto simp add: next0_def get_msgs_benign send0_def msgRcvd_def o_def restrict_map_def)\n\nlemma no_vote:\n  assumes \n  send: \"\\<forall>p. \\<mu> p \\<in> get_msgs (send0 r) cfg (HOs r) (HOs r) p\"\n  and step: \"\\<forall>p. next0 r p (cfg p) (\\<mu> p) (cfg' p)\"\n  and step_r: \"two_step r = 0\"\n  shows\n    \"no_vote_diff cfg' p\" \n    unfolding no_vote_diff_def\nproof\n  assume\n    \"vote (cfg' p) = None\"\n  hence \"(\\<exists>q q'. x (cfg q) \\<noteq> x (cfg q'))\"\n   using send[THEN spec, where x=p] step[THEN spec, where x=p] step_r HOs_nonempty \n   apply(clarsimp simp add: next0_def get_msgs_benign send0_def msgRcvd_def o_def restrict_map_def)\n   by metis\n  thus \"(\\<exists>q q'. x (cfg' q) \\<noteq> x (cfg' q'))\" \n    using no_x_change[OF send step step_r]\n    by(simp)\nqed\n  \n\nlemma step0_ref:\n  \"{ref_rel} \\<Union>r S v. tso_round0 r S v, \n    BenOr_trans_step HOs HOs next0 send0 0 {> ref_rel}\"\nproof(clarsimp simp add: PO_rhoare_defs BenOr_trans_step_def all_conj_distrib)\n  fix sa r cfg \\<mu> cfg'\n  assume\n    R: \"(sa, (r, cfg)) \\<in> ref_rel\"\n    and step_r: \"two_step r = 0\" \n    and send: \"\\<forall>p. \\<mu> p \\<in> get_msgs (send0 r) cfg (HOs r) (HOs r) p\"\n    and step: \"\\<forall>p. next0 r p (cfg p) (\\<mu> p) (cfg' p)\"\n\n  from R have next_r: \"next_round sa = r\"\n    by(simp add: ref_rel_def)\n\n  from HOs_nonempty send have \"\\<forall>p. \\<exists>q. q \\<in> msgRcvd (\\<mu> p)\"\n    by(fastforce simp add: get_msgs_benign send0_def msgRcvd_def restrict_map_def)\n  with step have same_dec: \"decide o cfg' = decide o cfg\"\n    apply(simp add: next0_def o_def)\n    by (metis pstate.select_convs(3) pstate.surjective pstate.update_convs(2))\n \n  define S where \"S = {p. \\<exists>v. vote (cfg' p) = Some v}\"\n  from same_new_vote[OF send step step_r] \n  obtain v where v: \"\\<forall>p \\<in> S. vote (cfg' p) = Some v\"\n    by(simp add: S_def) (metis)\n  hence vote_const_map: \"vote o cfg' = const_map v S\"\n    by(auto simp add: S_def const_map_def restrict_map_def intro!: ext)\n\n  define sa' where \"sa' = sa\\<lparr> next_round := Suc r, r_votes := const_map v S \\<rparr>\"\n\n  have \"\\<forall>p. p \\<in> S \\<longrightarrow> opt_obs_safe (last_obs sa) v\"\n    using vote_origin[OF send step step_r] R per_rd[THEN spec, of r] v\n    apply(clarsimp simp add: BenOr_commPerRd_def opt_obs_safe_def ref_rel_def)\n    by metis\n    \n  hence \"(sa, sa') \\<in> tso_round0 r S v\" using next_r step_r v R \n    vote_origin[OF send step step_r]\n    by(auto simp add: tso_round0_def sa'_def all_conj_distrib)\n\n\n  moreover have \"(sa', Suc r, cfg') \\<in> ref_rel\" using step send v R same_dec step_r next_r\n    apply(auto simp add: ref_rel_def sa'_def  two_step_phase_Suc vote_const_map next0_def\n      all_conj_distrib no_vote[OF send step step_r])\n    by (metis pstate.select_convs(1) pstate.surjective pstate.update_convs(2))\n\n  ultimately show\n    \"\\<exists>sa'. (\\<exists>r S v. (sa, sa') \\<in> tso_round0 r S v) \\<and> (sa', Suc r, cfg') \\<in> ref_rel\"\n    by blast\nqed\n\ndefinition D where\n  \"D cfg cfg' \\<equiv> {p. decide (cfg' p) \\<noteq> decide (cfg p) }\"\n\nlemma decide_origin:\n  assumes\n  send: \"\\<forall>p. \\<mu> p \\<in> get_msgs (send1 r) cfg (HOs r) (HOs r) p\"\n  and step: \"\\<forall>p. next1 r p (cfg p) (\\<mu> p) (cfg' p)\"\n  and step_r: \"two_step r = Suc 0\"\n  shows \n    \"D cfg cfg' \\<subseteq> {p. \\<exists>v. decide (cfg' p) = Some v \\<and> (\\<forall>q \\<in> HOs r p. vote (cfg q) = Some v)}\" \n  using assms\n  by(fastforce simp add: D_def next1_def get_msgs_benign send1_def msgRcvd_def o_def restrict_map_def\n    x_update_def dec_update_def identicalVoteRcvd_def all_conj_distrib someVoteRcvd_def isVote_def)\n  \nlemma step1_ref:\n  \"{ref_rel \\<inter> (TSO_inv1 \\<inter> TSO_inv2) \\<times> UNIV} \\<Union>r d_f o_f. tso_round1 r d_f o_f, \n    BenOr_trans_step HOs HOs next1 send1 (Suc 0) {> ref_rel}\"\nproof(clarsimp simp add: PO_rhoare_defs BenOr_trans_step_def all_conj_distrib)\n  fix sa r cfg \\<mu> and cfg' :: \"process \\<Rightarrow> val pstate\"\n  assume\n    R: \"(sa, (r, cfg)) \\<in> ref_rel\"\n    and step_r: \"two_step r = Suc 0\" \n    and send: \"\\<forall>p. \\<mu> p \\<in> get_msgs (send1 r) cfg (HOs r) (HOs r) p\"\n    and step: \"\\<forall>p. next1 r p (cfg p) (\\<mu> p) (cfg' p)\"\n    and ainv: \"sa \\<in> TSO_inv1\"\n    and ainv2: \"sa \\<in> TSO_inv2\"\n\n  from R have next_r: \"next_round sa = r\"\n    by(simp add: ref_rel_def)\n\n  define S where \"S = {p. \\<exists>v. vote (cfg p) = Some v}\"\n  from R obtain v where v: \"\\<forall>p \\<in> S. vote (cfg p) = Some v\" using ainv step_r\n    by(auto simp add: ref_rel_def TSO_inv1_def S_def)\n\n  define Ob where \"Ob = {p. x (cfg' p) = v}\"\n  define o_f where \"o_f p = (if S \\<in> Quorum then Some v else None)\" for p :: process\n\n  define dec_f where \"dec_f p = (if p \\<in> D cfg cfg' then decide (cfg' p) else None)\" for p\n\n  {\n    fix p w\n    assume \"vote (cfg p) = Some w\"\n    hence \"w = v\" using v\n      by(unfold S_def, auto)\n  } note v'=this\n    \n  have d_guard: \"d_guard dec_f (vote \\<circ> cfg)\" using per_rd[THEN spec, of r]\n    by(fastforce simp add: d_guard_def locked_in_vf_def quorum_for_def dec_f_def\n      BenOr_commPerRd_def dest!: decide_origin[OF send step step_r, THEN subsetD])\n\n  have \"dom (vote \\<circ> cfg) \\<in> Quorum \\<longrightarrow> Ob = UNIV\"\n  proof(auto simp add: Ob_def)\n    fix p\n    assume Q: \"dom (vote \\<circ> cfg) \\<in> Quorum\" (is \"?Q \\<in> Quorum\")\n    hence \"?Q \\<inter> HOs r p \\<noteq> {}\"  using per_rd[THEN spec, of r]\n      by(auto simp add: BenOr_commPerRd_def dest: qintersect)\n    hence \"someVoteRcvd (\\<mu> p) \\<noteq> {}\" using send[THEN spec, of p]\n      by(force simp add: someVoteRcvd_def get_msgs_benign msgRcvd_def restrict_map_def \n        isVote_def send1_def)\n    moreover have \"\\<forall>q \\<in> someVoteRcvd (\\<mu> p). \\<exists>x'. \\<mu> p q = Some (Vote (Some v))\"\n       using send[THEN spec, of p]\n      by(auto simp add: someVoteRcvd_def get_msgs_benign msgRcvd_def restrict_map_def\n        isVote_def send1_def dest: v')\n    ultimately show \"x (cfg' p) = v\" using step[THEN spec, of p]\n      by(auto simp add: next1_def x_update_def)\n  qed\n  note Ob_UNIV=this[rule_format]\n\n  have obs_guard: \"obs_guard o_f (vote \\<circ> cfg)\"\n    apply(auto simp add: obs_guard_def o_f_def S_def dom_def\n      dest: v' Ob_UNIV quorum_non_empty) \n    apply (metis S_def all_not_in_conv  empty_not_quorum v)\n    done\n\n  define sa' where \"sa' = sa\\<lparr> \n    next_round := Suc (next_round sa)\n    , decisions := decisions sa ++ dec_f\n    , last_obs := last_obs sa ++ o_f\n    \\<rparr>\"\n\n  \\<comment> \\<open>Abstract step\\<close>\n  have abs_step: \"(sa, sa') \\<in> tso_round1 r dec_f o_f\"  using next_r step_r R d_guard obs_guard\n    by(auto simp add: tso_round1_def sa'_def ref_rel_def)\n\n  \\<comment> \\<open>Relation preserved\\<close>\n  have \"\\<forall>p. ((decide \\<circ> cfg) ++ dec_f) p = decide (cfg' p)\"\n  proof\n    fix p\n    show \"((decide \\<circ> cfg) ++ dec_f) p = decide (cfg' p)\" using step[THEN spec, of p]\n      by(auto simp add: dec_f_def D_def next1_def dec_update_def map_add_def)\n  qed\n  note dec_rel=this[rule_format]\n\n  have \"\\<forall>p. (\\<exists>q. o_f q = None \\<and> opt_obsv_state.last_obs sa q = None \n        \\<or> (opt_obsv_state.last_obs sa ++ o_f) q = Some (x (cfg' p)))\"\n  proof(intro allI impI, cases \"S \\<in> Quorum\")\n    fix p \n    case True \n    hence \"x (cfg' p) = v\" using Ob_UNIV\n      by(auto simp add: S_def Ob_def dom_def)\n    thus \"(\\<exists>q. o_f q = None \\<and> opt_obsv_state.last_obs sa q = None \n        \\<or> (opt_obsv_state.last_obs sa ++ o_f) q = Some (x (cfg' p)))\"\n      using True\n      by(auto simp add: o_f_def)\n  next\n    fix p\n    case False\n    hence empty: \"o_f = Map.empty\"\n      by(auto simp add: o_f_def)\n    from False have \"S \\<noteq> UNIV\" using UNIV_quorum\n      by auto\n    then obtain q where q: \"vote (cfg q) = None\" using False\n      by(auto simp add: o_f_def S_def)\n    then obtain q1 q2 where \n      \"x (cfg q1) \\<noteq> x (cfg q2)\" using R step_r\n      by(auto simp add: ref_rel_def no_vote_diff_def)\n    then obtain q1' q2' where\n      \"x (cfg q1') = val0\"\n      \"x (cfg q2') = val1\"\n      by (metis (poly_guards_query) val_exhaust)\n    hence \"\\<forall>v. \\<exists>q. opt_obsv_state.last_obs sa q \\<in> {None, Some v}\" using R step_r\n      apply(auto simp add: ref_rel_def)\n      by (metis (poly_guards_query) val_exhaust)\n    (* note x = x_origin2[OF send step step_r refl, of p] *)\n    thus \"(\\<exists>q. o_f q = None \\<and> opt_obsv_state.last_obs sa q = None \n        \\<or> (opt_obsv_state.last_obs sa ++ o_f) q = Some (x (cfg' p)))\" using empty\n        by(auto)\n  qed\n  note obs_rel=this[rule_format]\n\n  have post_rel: \n    \"(sa', Suc r, cfg') \\<in> ref_rel\" using step send next_r R step_r\n    by(auto simp add: sa'_def ref_rel_def \n      two_step_phase_Suc dec_rel obs_rel)\n    \n  from abs_step post_rel show\n    \"\\<exists>sa'. (\\<exists>r d_f o_f. (sa, sa') \\<in> tso_round1 r d_f o_f) \\<and> (sa', Suc r, cfg') \\<in> ref_rel\"\n    by blast\nqed\n\nlemma BenOr_Refines_Two_Step_Obs:\n  \"PO_refines (ref_rel \\<inter> (TSO_inv1 \\<inter> TSO_inv2) \\<times> UNIV)\n    tso_TS (BenOr_TS HOs HOs crds)\"\nproof(rule refine_using_invariants)\n  show \"init (BenOr_TS HOs HOs crds) \\<subseteq> ref_rel `` init tso_TS\"\n    by(auto simp add: BenOr_TS_defs BenOr_HOMachine_def CHOAlgorithm.truncate_def \n      tso_TS_defs ref_rel_def tso_init_def Let_def o_def)\nnext\n  show \n    \"{ref_rel \\<inter> (TSO_inv1 \\<inter> TSO_inv2) \\<times> UNIV} TS.trans tso_TS, \n      TS.trans (BenOr_TS HOs HOs crds) {> ref_rel}\"\n    apply(simp add: tso_TS_defs BenOr_TS_defs BenOr_HOMachine_def CHOAlgorithm.truncate_def)\n    apply(auto simp add: CHO_trans_alt BenOr_trans intro!: step0_ref step1_ref)\n    done\nqed(auto intro!: TSO_inv1_inductive TSO_inv2_inductive)\n\nsubsubsection \\<open>Termination\\<close>\n(******************************************************************************)\n\ntext \\<open>The full termination proof for Ben-Or is probabilistic, and depends on the state\nof the processes, and a \"favorable\" coin toss, where \"favorable\" is relative to this state.\nAs this termination pre-condition is state-dependent, we cannot capture it in an HO \npredicate.\n\nInstead, we prove a variant of the argument, where we assume that there exists a \nround where all the processes hear from the same set of other processes, and all toss the \nsame coin.\n\\<close>\n\n\n\n  from r1 obtain r0 where r1_def: \"r1 = Suc r0\" and step_r0: \"two_step r0 = 0\"\n    by (cases r1) (auto simp add: two_step_phase_Suc two_step_def mod_Suc)\n\n  define cfg0 where \"cfg0 = rho r0\"\n  define cfg1 where \"cfg1 = rho r1\"\n  define r2 where \"r2 = Suc r1\"\n  define cfg2 where \"cfg2 = rho r2\"\n  define r3 where \"r3 = Suc r2\"\n  define cfg3 where \"cfg3 = rho r3\"\n  define cfg4 where \"cfg4 = rho (Suc r3)\"\n\n  have step_r2: \"two_step r2 = 0\" using r1\n    by(auto simp add: r2_def two_step_phase_Suc)\n\n  from\n    run[simplified HORun_def SHORun_def, THEN CSHORun_step, THEN spec, where x=\"r0\"]\n    run[simplified HORun_def SHORun_def, THEN CSHORun_step, THEN spec, where x=\"r1\"]\n    run[simplified HORun_def SHORun_def, THEN CSHORun_step, THEN spec, where x=\"r2\"] \n    run[simplified HORun_def SHORun_def, THEN CSHORun_step, THEN spec, where x=\"r3\"]\n    obtain \\<mu>0 \\<mu>1 \\<mu>2 \\<mu>3 where\n    send0: \"\\<forall>p. \\<mu>0 p \\<in> get_msgs (send0 r0) cfg0 (HOs r0) (HOs r0) p\"\n    and step0: \"\\<forall>p. next0 r0 p (cfg0 p) (\\<mu>0 p) (cfg1 p)\"\n    and send1: \"\\<forall>p. \\<mu>1 p \\<in> get_msgs (send1 r1) cfg1 (HOs r1) (HOs r1) p\"\n    and step1: \"\\<forall>p. next1 r1 p (cfg1 p) (\\<mu>1 p) (cfg2 p)\"\n    and send2: \"\\<forall>p. \\<mu>2 p \\<in> get_msgs (send0 r2) cfg2 (HOs r2) (HOs r2) p\"\n    and step2: \"\\<forall>p. next0 r2 p (cfg2 p) (\\<mu>2 p) (cfg3 p)\"\n    and send3: \"\\<forall>p. \\<mu>3 p \\<in> get_msgs (send1 r3) cfg3 (HOs r3) (HOs r3) p\"\n    and step3: \"\\<forall>p. next1 r3 p (cfg3 p) (\\<mu>3 p) (cfg4 p)\"\n    by(auto simp add: BenOr_A_def BenOr_HOMachine_def \n      two_step_phase_Suc BenOr_nextState_def BenOr_sendMsg_def all_conj_distrib\n      CHOAlgorithm.truncate_def step_r0 r1_def r2_def r3_def\n      cfg0_def cfg1_def cfg2_def cfg3_def cfg4_def \n      )\n  \n  let ?v = \"x (cfg2 p)\"\n  from per_rd r1 have xs: \"\\<forall>q. x (cfg2 q) = ?v\"\n  proof(cases \"\\<exists>q w. q \\<in> HOs r1 p \\<and> vote (cfg1 q) = Some w\")\n    case True\n    then obtain q w where q_w: \"q \\<in> HOs r1 p \\<and> vote (cfg1 q) = Some w\"\n      by auto\n    then have \"\\<forall>q'. vote (cfg1 q') \\<in> {None, Some w}\" using  same_new_vote[OF send0 step0 step_r0]\n      by (metis insert_iff not_None_eq)\n    hence \"\\<forall>q'. x (cfg2 q') = w\"  using step1 send1 q_w\n      apply(auto simp add: next1_def all_conj_distrib dec_update_def x_update_def\n        get_msgs_benign send1_def isVote_def msgRcvd_def identicalVoteRcvd_def \n        someVoteRcvd_def restrict_map_def)\n      by (metis (erased, hide_lams) option.distinct(2) option.sel r1(1))\n    thus ?thesis\n      by auto\n  next\n    case False\n    hence \"\\<forall>q'. x (cfg2 q') = coin r1 q'\" using r1 step1 send1\n      apply(auto simp add: next1_def all_conj_distrib dec_update_def x_update_def\n        get_msgs_benign send1_def isVote_def msgRcvd_def identicalVoteRcvd_def \n        someVoteRcvd_def restrict_map_def)\n      by (metis False)\n    thus ?thesis using r1\n      by(metis)      \n  qed\n  \n  hence \"\\<forall>q. vote (cfg3 q) = Some ?v\"\n    by(simp add: vote_origin[OF send2 step2 step_r2])\n\n  hence \"decide (cfg4 p) = Some ?v\" using send3[THEN spec, of p] step3[THEN spec, of p] HOs_nonempty\n    by(auto simp add: next1_def send1_def get_msgs_benign dec_update_def\n      restrict_map_def identicalVoteRcvd_def msgRcvd_def isVote_def)\n\n  thus ?thesis\n    by(auto simp add: cfg4_def)\nqed\n\nend (* HO predicate context *)\n\nend (* mono_quorum context *)\n\nend (* theory *)\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Consensus_Refined/Observing/BenOr_Proofs.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.611381973294151, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.2961412517496499}}
{"text": "theory DeadCodeRemoval2Correct\nimports Launchbury LaunchburyAbstractTransformation DeadCodeRemoval2\nbegin\n\ndefinition rdcH :: \"var set \\<Rightarrow> heap \\<Rightarrow> heap\"\n  where \"rdcH S \\<Gamma> = restrictA (-S) (clearjunk (map_ran (\\<lambda> _ e . remove_dead_code e) \\<Gamma>))\" \n\ninductive dc_rel :: \"(heap \\<times> exp) \\<Rightarrow> var list \\<Rightarrow> (heap \\<times> exp) \\<Rightarrow>  bool\" (\"_ \\<triangleright>\\<^bsub>_\\<^esub> _\" [50,50,50] 50 )\n  where \"S \\<subseteq> domA \\<Gamma> \\<union> set L \\<Longrightarrow> S \\<inter> fv (rdcH S \\<Gamma>, remove_dead_code e, L) = {} \\<Longrightarrow> (\\<Gamma>, e) \\<triangleright>\\<^bsub>L\\<^esub> (rdcH S \\<Gamma>, remove_dead_code e)\"\n\nlemma delete_map_ran[simp]: \"delete x (map_ran f \\<Gamma>) = map_ran f (delete x \\<Gamma>)\"\n  by (induction \\<Gamma>) auto\n\nlemma map_of_rdcH: \"map_of (rdcH S \\<Gamma>) x = (if x \\<in> S then None else map_option remove_dead_code (map_of \\<Gamma> x))\"\n  apply (induction \\<Gamma> rule: clearjunk.induct)\n  apply (auto simp add: rdcH_def map_of_clearjunk  split: if_splits)\n  by (metis delete_map_ran map_of_delete)\n\nlemma delete_rdcH[simp]: \"delete x (rdcH S \\<Gamma>) = rdcH S (delete x \\<Gamma>)\"\n  by (induction \\<Gamma> rule:clearjunk.induct) \n     (auto simp add: rdcH_def  delete_twist split: if_splits)\n\nlemma restrictA_UNIV[simp]: \"restrictA UNIV \\<Gamma> = \\<Gamma>\"\n  by (induction \\<Gamma>) auto\n\nlemma restrictA_delete[simp]: \"restrictA S (delete x \\<Gamma>) = restrictA (S - {x}) \\<Gamma>\"\n  by (induction \\<Gamma>) auto\n\nlemma clearjunk_append: \"clearjunk (\\<Gamma>1 @ \\<Gamma>2) = clearjunk \\<Gamma>1 @ clearjunk (restrictA (-domA \\<Gamma>1) \\<Gamma>2)\"\n  by (induction \\<Gamma>1 arbitrary: \\<Gamma>2 rule:clearjunk.induct) (auto simp add: Compl_insert)\n\nlemma restrictA_clearjunk: \"restrictA S (clearjunk \\<Gamma>) = clearjunk (restrictA S \\<Gamma>)\"\n  by (induction \\<Gamma>  rule:clearjunk.induct) (auto simp add: Compl_insert)\n\nlemma rdcH_append[simp]: \"domA as \\<inter> domA \\<Gamma> = {} \\<Longrightarrow> rdcH S (as @ \\<Gamma>) = rdcH S as @ rdcH S \\<Gamma>\"\n  unfolding rdcH_def apply (simp add: clearjunk_append restrictA_clearjunk map_ran_append restrictA_append)\n  apply (rule arg_cong) back\n  apply (rule restrictA_cong)\n  apply auto\n  done\n\nlemma restrict_is_nil[simp]: \"restrictA S \\<Gamma> = [] \\<longleftrightarrow> S \\<inter> domA \\<Gamma> = {}\"\n  by (induction \\<Gamma>) auto\n\nlemma rdcH_nil[simp]: \"rdcH S [] = []\"\n  by (auto simp add: rdcH_def)\n\nlemma rdcH_is_nil: \"domA \\<Gamma> \\<subseteq> S \\<Longrightarrow> rdcH S \\<Gamma> = []\"\n  by (auto simp add: rdcH_def)\n\nlemma rdcH_cong_set: \"S \\<inter> domA \\<Gamma> = S' \\<inter> domA \\<Gamma> \\<Longrightarrow> rdcH S \\<Gamma> = rdcH S' \\<Gamma>\"\n  unfolding rdcH_def by (rule restrictA_cong) auto\n\ninterpretation rel_lambda_cong dc_rel\n  by default (auto elim!: dc_rel.cases simp del: exp_assn.eq_iff(4))\ninterpretation rel_app_cong dc_rel\n  by default (auto elim: dc_rel.cases)\ninterpretation rel_var_cong dc_rel\n  by default (auto elim: dc_rel.cases)\n\nlemma rdcH_eqvt[eqvt]: \"\\<pi> \\<bullet> (rdcH S \\<Gamma>) = rdcH (\\<pi> \\<bullet> S) (\\<pi> \\<bullet> \\<Gamma>)\"\n  unfolding rdcH_def by perm_simp rule\n\nlemma rdch_fresh[intro]: \"a \\<sharp> \\<Gamma> \\<Longrightarrow> a \\<sharp> rdcH S \\<Gamma>\"\n  by (induction \\<Gamma> rule: clearjunk.induct)\n     (auto simp add:  rdcH_def fresh_Nil fresh_Pair fresh_Cons  eqvt_fresh_cong1[OF remove_dead_code.eqvt] fresh_delete)\n\nlemma rdch_fv_subset: \"fv (rdcH S \\<Gamma>) \\<subseteq> fv \\<Gamma>\"\n  using rdch_fresh unfolding fresh_def fv_def by auto\n\nlemma rdch_Cons[simp]:\n  \"x \\<notin> S \\<Longrightarrow> rdcH S ((x, z) # \\<Gamma>) = (x, remove_dead_code z) # rdcH S (delete x \\<Gamma>)\"\n  unfolding rdcH_def\n  by (auto simp add: clearjunk_restrict[symmetric] delete_map_ran[symmetric] simp del: delete_map_ran)\n\ninterpretation reds_rel_fresh dc_rel\n  by default (auto elim!: dc_rel.cases intro: eqvt_fresh_cong1[OF remove_dead_code.eqvt])\n\ninterpretation rel_lambda_case dc_rel by default\n\nlemma Lam_eq_same_var[simp]: \"Lam [y]. e = Lam [y]. e' \\<longleftrightarrow>  e = e'\"\n  by auto (metis fresh_PairD(2) obtain_fresh)\n\ninterpretation rel_app_case dc_rel\nproof\n  fix \\<Gamma> e x L \\<Gamma>' e''\n  assume \"(\\<Gamma>, App e x) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', App e'' x)\"\n  thus \"(\\<Gamma>, e) \\<triangleright>\\<^bsub>x # L\\<^esub> (\\<Gamma>', e'')\" \n    by (fastforce elim!: dc_rel.cases intro!: dc_rel.intros)\nnext\n  fix \\<Gamma> y body x L \\<Gamma>' body'\n  assume \"(\\<Gamma>, Lam [y]. body) \\<triangleright>\\<^bsub>x # L\\<^esub> (\\<Gamma>', Lam [y]. body')\"\n  thus \"(\\<Gamma>, body[y::=x]) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', body'[y::=x])\"\n    apply (auto elim!: dc_rel.cases intro!: dc_rel.intros dest: set_mp  simp del: exp_assn.eq_iff(4) simp add: subst_remove_dead_code disjoint_iff_not_equal fv_subst_eq split: if_splits)\n    apply (auto simp add: subst_remove_dead_code[symmetric] fv_subst_eq  split: if_splits)\n    done\nqed\n\ninterpretation rel_var_case dc_rel\nproof\n  case (goal1 \\<Gamma> x L \\<Gamma>' e thesis)\n  show thesis\n  proof (rule goal1)\n\n    from goal1(1)\n    obtain S where \"\\<Gamma>' = rdcH S \\<Gamma>\"\n      and \"S \\<subseteq> domA \\<Gamma> \\<union> set L\" and \"S \\<inter> fv (rdcH S \\<Gamma>, Var x, L) = {}\" by (auto elim!: dc_rel.cases)\n    hence \"x \\<notin> S\" by auto\n\n    from `map_of \\<Gamma> x = Some e` and `\\<Gamma>' = _` and `x \\<notin> S`\n    show \"map_of \\<Gamma>' x = Some (remove_dead_code e)\" by (auto simp add: map_of_rdcH)\n\n    have *: \"\\<And> S . fv (rdcH S (delete x \\<Gamma>)) \\<subseteq> fv (rdcH S \\<Gamma>)\" by (metis delete_rdcH fv_delete_subset)\n\n    from `map_of \\<Gamma>' x = Some (remove_dead_code e)`\n    have **: \"fv (remove_dead_code e) \\<subseteq> fv \\<Gamma>'\" by (metis domA_from_set map_of_fv_subset map_of_is_SomeD option.sel)\n\n    from goal1(1)\n    show \"(delete x \\<Gamma>, e) \\<triangleright>\\<^bsub>x # L\\<^esub> (delete x \\<Gamma>', remove_dead_code e)\"\n      by (fastforce elim!: dc_rel.cases intro!: dc_rel.intros dest: set_mp[OF *]  set_mp[OF **]  simp add: disjoint_iff_not_equal)\n  qed\nnext\n  fix \\<Gamma> z x L \\<Gamma>' z'\n  assume \"(\\<Gamma>, z) \\<triangleright>\\<^bsub>x # L\\<^esub> (\\<Gamma>', z')\"\n  then obtain S where \"\\<Gamma>' = rdcH S \\<Gamma>\" and \"z' = remove_dead_code z\"\n      and \"S \\<subseteq> insert x (domA \\<Gamma> \\<union> set L)\" and \"S \\<inter> fv (rdcH S \\<Gamma>, remove_dead_code z, x # L) = {}\" by (auto elim!: dc_rel.cases)\n\n  from this(4)\n  have \"x \\<notin> S\" by auto\n  moreover\n  assume \"x \\<notin> domA \\<Gamma>\"\n  ultimately\n  have [simp]: \"rdcH S ((x, z) # \\<Gamma>) = (x,remove_dead_code z) # rdcH S \\<Gamma>\" by simp\n\n  have  \"((x, z) # \\<Gamma>, z) \\<triangleright>\\<^bsub>L\\<^esub> (rdcH S ((x, z) # \\<Gamma>), remove_dead_code z)\"\n    apply (rule dc_rel.intros) using `S \\<subseteq>  _` `S \\<inter> _ = _`  by auto\n  thus \"((x, z) # \\<Gamma>, z) \\<triangleright>\\<^bsub>L\\<^esub> ((x, z') # \\<Gamma>', z')\"\n    unfolding `\\<Gamma>' = _` `z' = _` by auto\nqed\n\nlocale let_removed = \n  fixes \\<Gamma> as body\n  assumes \"domA as \\<inter> fv body = {} \"\n\n\nlemma map_fst_map_ran[simp]: \"map fst (map_ran f l) = map fst l\" by (induction l) auto\n\nlemma permute_list_id: \"supp p \\<subseteq> set xs \\<Longrightarrow>  p \\<bullet> xs = xs \\<Longrightarrow> p = 0\"\nproof (induction xs)\n  case Nil\n  hence \"supp p = {}\" by auto\n  thus \"p = 0\" by (metis empty_subsetI supp_perm_singleton)\nnext\n  case (Cons x xs)\n  hence \"p \\<bullet> x = x\" by auto\n  hence \"x \\<notin> supp p\" by (metis fresh_def fresh_perm)\n  with Cons show \"p = 0\" by auto\nqed\n\nlemma Abs_lst_same[simp]: \"[xs]lst. (y::'a::fs) = [xs]lst. y' \\<longleftrightarrow> y = y'\"\n  apply rule\n  prefer 2\n  apply simp\n  unfolding Abs_eq_iff2\n  apply (erule exE)\n  apply auto\n  unfolding alpha_lst.simps\n  apply (subgoal_tac \"p = 0\")\n  apply auto[1]\n  apply (auto simp add: permute_list_id)\n  done\n\nlemma Let_eq_same_var[simp]:\n  assumes \"map fst as = map fst as'\"\n  shows \"Terms.Let as e = Terms.Let as' e' \\<longleftrightarrow> (as = as' \\<and> e = e')\"\nproof-\n  from assms have  \"map (\\<lambda>x. atom (fst x)) as = map (\\<lambda>x. atom (fst x)) as'\"\n    by (induction as as' rule: list_induct2') auto\n  thus ?thesis by auto\nqed\n\nlemma disjoint_mono: \"A \\<inter> B = {} \\<Longrightarrow>  A' \\<subseteq> A \\<Longrightarrow> B' \\<subseteq> B \\<Longrightarrow> A' \\<inter> B' = {}\" by auto\n\nlemma disjoint_Un1: \"(A \\<union> B) \\<inter> C = {} \\<longleftrightarrow> A \\<inter> C = {} \\<and> B \\<inter> C = {} \" by auto\nlemma disjoint_Un2: \"C \\<inter> (A \\<union> B) = {} \\<longleftrightarrow> C \\<inter> A = {} \\<and> C \\<inter> B = {} \" by auto\n\ntheorem DeadCodeRemovalCorrect:\n  assumes \"\\<Gamma> : e \\<Down>\\<^bsub>L\\<^esub> \\<Delta> : z\"\n  assumes \"(\\<Gamma>, e) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', e')\"\n   shows  \"\\<exists> \\<Delta>' z'. (\\<Delta>, z) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Delta>', z') \\<and> \\<Gamma>' : e' \\<Down>\\<^bsub>L\\<^esub> \\<Delta>' : z'\"\n  using assms\nproof(nominal_induct arbitrary: \\<Gamma>' e' rule:reds.strong_induct)\ncase (Lambda \\<Gamma> x e L) thus ?case by (rule lambda_case)\nnext\ncase (Application y \\<Gamma> e x L \\<Delta> \\<Theta> z body) thus ?case by (rule app_case)\nnext\ncase (Variable \\<Gamma> x e L \\<Delta> z \\<Gamma>' var) thus ?case by (rule var_case)\nnext\ncase (Let as \\<Gamma> L body \\<Delta> z \\<Gamma>' let')\n  let \"Terms.Let ?as' ?body'\" = \"Terms.Let (restrict_reachable (map_ran (\\<lambda>_. remove_dead_code) as) (remove_dead_code body)) (remove_dead_code body)\"\n\n  from `(\\<Gamma>, Terms.Let as body) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', let')` \n  obtain S where \"\\<Gamma>' = rdcH S \\<Gamma>\" and \"let' = SmartLet ?as' ?body'\"\n  and \"S \\<subseteq> domA \\<Gamma> \\<union> set L\" and S: \"S \\<inter> fv (rdcH S \\<Gamma>, SmartLet ?as' ?body', L) = {}\"  by (auto elim!: dc_rel.cases)\n\n  let \"?S'\" = \"domA as - reachable (map_ran (\\<lambda>_. remove_dead_code) as) ?body'\"\n\n  from  `S \\<subseteq> _` and fresh_distinct[OF Let(1)] and fresh_distinct_list[OF Let(2)]\n  have \"S \\<inter> domA as = {}\" by auto \n  hence [simp]: \"(rdcH (?S' \\<union> S) as) = ?as'\"\n    unfolding restrict_reachable_def rdcH_def\n    by -(rule restrictA_cong,  auto)\n  \n  have [simp]: \"(rdcH (?S' \\<union> S) \\<Gamma>) = (rdcH S \\<Gamma>)\"\n    using fresh_distinct[OF Let(1)]\n    by (auto intro: rdcH_cong_set simp add: fresh_star_at_base)\n\n  have \"(as @ \\<Gamma>, body) \\<triangleright>\\<^bsub>L\\<^esub> (rdcH (?S' \\<union> S) (as @ \\<Gamma>), ?body')\"\n  proof (rule dc_rel.intros)\n    show \"(?S' \\<union> S) \\<subseteq> domA (as @ \\<Gamma>) \\<union> set L\" using `S \\<subseteq> domA \\<Gamma> \\<union> set L` by auto\n\n    have \"?S' \\<inter> fv ?as' = {}\"\n      using fv_heap_reachable by auto\n    moreover\n    have \"?S' \\<inter> fv \\<Gamma> = {}\"\n      using Let(1) by (auto simp add: fresh_star_def fresh_def fv_def)\n    hence \"?S' \\<inter> fv (rdcH S \\<Gamma>) = {}\"\n      by (rule disjoint_mono[OF _ subset_refl rdch_fv_subset])\n    moreover\n    have \"?S' \\<inter> fv (?body') = {}\"\n      using fv_e_reachable by auto\n    moreover\n    have \"?S' \\<inter> fv L = {}\"\n      using fresh_distinct_list[OF Let(2)] by auto\n    moreover\n    have \"S \\<inter> fv ?as' = {}\"\n      using S `S \\<inter> domA as = {}` by auto\n    moreover\n    have \"S \\<inter> fv (rdcH S \\<Gamma>) = {}\"\n      using S by auto\n    moreover\n    have \"S \\<inter> fv (?body') = {}\"\n      using S `S \\<inter> domA as = {}` by auto\n    moreover\n    have \"S \\<inter> fv L = {}\"\n      using S by auto\n    ultimately\n    show \"(?S' \\<union> S) \\<inter> fv (rdcH (?S' \\<union> S) (as @ \\<Gamma>), ?body', L) = {}\" using fresh_distinct[OF Let(1)] by auto\n  qed\n  hence \"(as @ \\<Gamma>, body) \\<triangleright>\\<^bsub>L\\<^esub> (?as' @ \\<Gamma>', ?body')\" unfolding `\\<Gamma>'=_` using fresh_distinct[OF Let(1)] by simp\n  from Let(4)[OF this]\n  obtain \\<Delta>' z' where \"(\\<Delta>, z) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Delta>', z')\" and \"?as' @ \\<Gamma>' : ?body' \\<Down>\\<^bsub>L\\<^esub> \\<Delta>' : z'\" by auto\n  from reds_SmartLet[OF _ this(2)]\n  have \"\\<Gamma>' : let' \\<Down>\\<^bsub>L\\<^esub> \\<Delta>' : z'\" unfolding `\\<Gamma>'=_`  `let' = _`\n    using Let(1,2) by (auto simp add: fresh_star_def fresh_Pair)\n  with `(\\<Delta>, z) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Delta>', z')`\n  show ?case  by auto\nqed\n\n\ncorollary\n  assumes \"[] : e \\<Down>\\<^bsub>L\\<^esub> \\<Delta> : z\"\n   shows  \"\\<exists> \\<Delta>' z'. [] : remove_dead_code e \\<Down>\\<^bsub>L\\<^esub> \\<Delta>' : z'\"\nproof-\n  have \"([], e) \\<triangleright>\\<^bsub>L\\<^esub> (rdcH {} [], remove_dead_code e)\" by (rule dc_rel.intros) auto\n  hence \"([], e) \\<triangleright>\\<^bsub>L\\<^esub> ([], remove_dead_code e)\" by simp\n  from DeadCodeRemovalCorrect[OF assms this]\n  show ?thesis by auto\nqed\n\nend\n", "meta": {"author": "nomeata", "repo": "isa-launchbury", "sha": "2caa8d7d588e218aef1c49f2f327597af06d116e", "save_path": "github-repos/isabelle/nomeata-isa-launchbury", "path": "github-repos/isabelle/nomeata-isa-launchbury/isa-launchbury-2caa8d7d588e218aef1c49f2f327597af06d116e/Scratchpad/DeadCodeRemoval2Correct.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982315512489, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.2961323567379952}}
{"text": "(*  Title:      HOL/HOLCF/IOA/NTP/Impl.thy\n    Author:     Tobias Nipkow & Konrad Slind\n*)\n\nsection \\<open>The implementation\\<close>\n\ntheory Impl\nimports Sender Receiver Abschannel\nbegin\n\ntype_synonym 'm impl_state\n  = \"'m sender_state * 'm receiver_state * 'm packet multiset * bool multiset\"\n  (*  sender_state   *  receiver_state   *    srch_state      * rsch_state *)\n\n\ndefinition\n  impl_ioa :: \"('m action, 'm impl_state)ioa\" where\n  impl_def: \"impl_ioa == (sender_ioa \\<parallel> receiver_ioa \\<parallel> srch_ioa \\<parallel> rsch_ioa)\"\n\ndefinition sen :: \"'m impl_state => 'm sender_state\" where \"sen = fst\"\ndefinition rec :: \"'m impl_state => 'm receiver_state\" where \"rec = fst \\<circ> snd\"\ndefinition srch :: \"'m impl_state => 'm packet multiset\" where \"srch = fst \\<circ> snd \\<circ> snd\"\ndefinition rsch :: \"'m impl_state => bool multiset\" where \"rsch = snd \\<circ> snd \\<circ> snd\"\n\ndefinition\n  hdr_sum :: \"'m packet multiset => bool => nat\" where\n  \"hdr_sum M b == countm M (%pkt. hdr(pkt) = b)\"\n\n(* Lemma 5.1 *)\ndefinition\n  \"inv1(s) \\<equiv>\n     (\\<forall>b. count (rsent(rec s)) b = count (srcvd(sen s)) b + count (rsch s) b)\n   \\<and> (\\<forall>b. count (ssent(sen s)) b\n          = hdr_sum (rrcvd(rec s)) b + hdr_sum (srch s) b)\"\n\n(* Lemma 5.2 *)\ndefinition\n  \"inv2(s) ==\n  (rbit(rec(s)) = sbit(sen(s)) &\n   ssending(sen(s)) &\n   count (rsent(rec s)) (~sbit(sen s)) <= count (ssent(sen s)) (~sbit(sen s)) &\n   count (ssent(sen s)) (~sbit(sen s)) <= count (rsent(rec s)) (sbit(sen s)))\n   |\n  (rbit(rec(s)) = (~sbit(sen(s))) &\n   rsending(rec(s)) &\n   count (ssent(sen s)) (~sbit(sen s)) <= count (rsent(rec s)) (sbit(sen s)) &\n   count (rsent(rec s)) (sbit(sen s)) <= count (ssent(sen s)) (sbit(sen s)))\"\n\n(* Lemma 5.3 *)\ndefinition\n  \"inv3(s) \\<equiv>\n   rbit(rec(s)) = sbit(sen(s))\n   \\<longrightarrow> (\\<forall>m. sq(sen(s))=[] | m \\<noteq> hd(sq(sen(s)))\n        \\<longrightarrow>  count (rrcvd(rec s)) (sbit(sen(s)),m)\n             + count (srch s) (sbit(sen(s)),m)\n            \\<le> count (rsent(rec s)) (~sbit(sen s)))\"\n\n(* Lemma 5.4 *)\ndefinition \"inv4(s) == rbit(rec(s)) = (~sbit(sen(s))) --> sq(sen(s)) ~= []\"\n\n\nsubsection \\<open>Invariants\\<close>\n\ndeclare le_SucI [simp]\n\nlemmas impl_ioas =\n  impl_def sender_ioa_def receiver_ioa_def srch_ioa_thm [THEN eq_reflection]\n  rsch_ioa_thm [THEN eq_reflection]\n\nlemmas \"transitions\" =\n  sender_trans_def receiver_trans_def srch_trans_def rsch_trans_def\n\n\nlemmas [simp] =\n  ioa_triple_proj starts_of_par trans_of_par4 in_sender_asig\n  in_receiver_asig in_srch_asig in_rsch_asig\n\ndeclare let_weak_cong [cong]\n\n\n\nlemma [simp]:\n  \"a\\<in>actions(sender_asig)\n  \\<or> a\\<in>actions(receiver_asig)\n  \\<or> a\\<in>actions(srch_asig)\n  \\<or> a\\<in>actions(rsch_asig)\"\n  by (induct a) simp_all\n\ndeclare split_paired_All [simp del]\n\n\n(* Three Simp_sets in different sizes\n----------------------------------------------\n\n1) simpset() does not unfold the transition relations\n2) ss unfolds transition relations\n3) renname_ss unfolds transitions and the abstract channel *)\n\nML \\<open>\nval ss = simpset_of (\\<^context> addsimps @{thms \"transitions\"});\nval rename_ss = simpset_of (put_simpset ss \\<^context> addsimps @{thms unfold_renaming});\n\nfun tac ctxt =\n  asm_simp_tac (put_simpset ss ctxt\n    |> Simplifier.add_cong @{thm conj_cong} |> Splitter.add_split @{thm if_split})\nfun tac_ren ctxt =\n  asm_simp_tac (put_simpset rename_ss ctxt\n    |> Simplifier.add_cong @{thm conj_cong} |> Splitter.add_split @{thm if_split})\n\\<close>\n\n\nsubsubsection \\<open>Invariant 1\\<close>\n\nlemma raw_inv1: \"invariant impl_ioa inv1\"\n\napply (unfold impl_ioas)\napply (rule invariantI)\napply (simp add: inv1_def hdr_sum_def srcvd_def ssent_def rsent_def rrcvd_def)\n\napply (simp (no_asm) del: trans_of_par4 add: imp_conjR inv1_def)\n\ntxt \\<open>Split proof in two\\<close>\napply (rule conjI)\n\n(* First half *)\napply (simp add: Impl.inv1_def split del: if_split)\napply (induct_tac a)\n\napply (tactic \"EVERY1[tac \\<^context>, tac \\<^context>, tac \\<^context>, tac \\<^context>]\")\napply (tactic \"tac \\<^context> 1\")\napply (tactic \"tac_ren \\<^context> 1\")\n\ntxt \\<open>5 + 1\\<close>\n\napply (tactic \"tac \\<^context> 1\")\napply (tactic \"tac_ren \\<^context> 1\")\n\ntxt \\<open>4 + 1\\<close>\napply (tactic \\<open>EVERY1[tac \\<^context>, tac \\<^context>, tac \\<^context>, tac \\<^context>]\\<close>)\n\n\ntxt \\<open>Now the other half\\<close>\napply (simp add: Impl.inv1_def split del: if_split)\napply (induct_tac a)\napply (tactic \"EVERY1 [tac \\<^context>, tac \\<^context>]\")\n\ntxt \\<open>detour 1\\<close>\napply (tactic \"tac \\<^context> 1\")\napply (tactic \"tac_ren \\<^context> 1\")\napply (rule impI)\napply (erule conjE)+\napply (simp (no_asm_simp) add: hdr_sum_def Multiset.count_def Multiset.countm_nonempty_def\n  split: if_split)\ntxt \\<open>detour 2\\<close>\napply (tactic \"tac \\<^context> 1\")\napply (tactic \"tac_ren \\<^context> 1\")\napply (rule impI)\napply (erule conjE)+\napply (simp add: Impl.hdr_sum_def Multiset.count_def Multiset.countm_nonempty_def\n  Multiset.delm_nonempty_def split: if_split)\napply (rule allI)\napply (rule conjI)\napply (rule impI)\napply hypsubst\napply (rule pred_suc [THEN iffD1])\napply (drule less_le_trans)\napply (cut_tac eq_packet_imp_eq_hdr [unfolded Packet.hdr_def, THEN countm_props])\napply assumption\napply assumption\n\napply (rule countm_done_delm [THEN mp, symmetric])\napply (rule refl)\napply (simp (no_asm_simp) add: Multiset.count_def)\n\napply (rule impI)\napply (simp add: neg_flip)\napply hypsubst\napply (rule countm_spurious_delm)\napply (simp (no_asm))\n\napply (tactic \"EVERY1 [tac \\<^context>, tac \\<^context>, tac \\<^context>,\n  tac \\<^context>, tac \\<^context>, tac \\<^context>]\")\n\ndone\n\n\n\nsubsubsection \\<open>INVARIANT 2\\<close>\n\nlemma raw_inv2: \"invariant impl_ioa inv2\"\n\n  apply (rule invariantI1)\n  txt \\<open>Base case\\<close>\n  apply (simp add: inv2_def receiver_projections sender_projections impl_ioas)\n\n  apply (simp (no_asm_simp) add: impl_ioas split del: if_split)\n  apply (induct_tac \"a\")\n\n  txt \\<open>10 cases. First 4 are simple, since state doesn't change\\<close>\n\n  ML_prf \\<open>val tac2 = asm_full_simp_tac (put_simpset ss \\<^context> addsimps [@{thm inv2_def}])\\<close>\n\n  txt \\<open>10 - 7\\<close>\n  apply (tactic \"EVERY1 [tac2,tac2,tac2,tac2]\")\n  txt \\<open>6\\<close>\n  apply (tactic \\<open>forward_tac \\<^context> [rewrite_rule \\<^context> [@{thm Impl.inv1_def}]\n                               (@{thm raw_inv1} RS @{thm invariantE}) RS conjunct1] 1\\<close>)\n\n  txt \\<open>6 - 5\\<close>\n  apply (tactic \"EVERY1 [tac2,tac2]\")\n\n  txt \\<open>4\\<close>\n  apply (tactic \\<open>forward_tac \\<^context> [rewrite_rule \\<^context> [@{thm Impl.inv1_def}]\n                                (@{thm raw_inv1} RS @{thm invariantE}) RS conjunct1] 1\\<close>)\n  apply (tactic \"tac2 1\")\n\n  txt \\<open>3\\<close>\n  apply (tactic \\<open>forward_tac \\<^context> [rewrite_rule \\<^context> [@{thm Impl.inv1_def}]\n    (@{thm raw_inv1} RS @{thm invariantE})] 1\\<close>)\n\n  apply (tactic \"tac2 1\")\n  apply (tactic \\<open>fold_goals_tac \\<^context> [rewrite_rule \\<^context> [@{thm Packet.hdr_def}]\n    (@{thm Impl.hdr_sum_def})]\\<close>)\n  apply arith\n\n  txt \\<open>2\\<close>\n  apply (tactic \"tac2 1\")\n  apply (tactic \\<open>forward_tac \\<^context> [rewrite_rule \\<^context> [@{thm Impl.inv1_def}]\n                               (@{thm raw_inv1} RS @{thm invariantE}) RS conjunct1] 1\\<close>)\n  apply (intro strip)\n  apply (erule conjE)+\n  apply simp\n\n  txt \\<open>1\\<close>\n  apply (tactic \"tac2 1\")\n  apply (tactic \\<open>forward_tac \\<^context> [rewrite_rule \\<^context> [@{thm Impl.inv1_def}]\n                               (@{thm raw_inv1} RS @{thm invariantE}) RS conjunct2] 1\\<close>)\n  apply (intro strip)\n  apply (erule conjE)+\n  apply (tactic \\<open>fold_goals_tac \\<^context>\n    [rewrite_rule \\<^context> [@{thm Packet.hdr_def}] (@{thm Impl.hdr_sum_def})]\\<close>)\n  apply simp\n\n  done\n\n\nsubsubsection \\<open>INVARIANT 3\\<close>\n\nlemma raw_inv3: \"invariant impl_ioa inv3\"\n\n  apply (rule invariantI)\n  txt \\<open>Base case\\<close>\n  apply (simp add: Impl.inv3_def receiver_projections sender_projections impl_ioas)\n\n  apply (simp (no_asm_simp) add: impl_ioas split del: if_split)\n  apply (induct_tac \"a\")\n\n  ML_prf \\<open>val tac3 = asm_full_simp_tac (put_simpset ss \\<^context> addsimps [@{thm inv3_def}])\\<close>\n\n  txt \\<open>10 - 8\\<close>\n\n  apply (tactic \"EVERY1[tac3,tac3,tac3]\")\n\n  apply (tactic \"tac_ren \\<^context> 1\")\n  apply (intro strip, (erule conjE)+)\n  apply hypsubst\n  apply (erule exE)\n  apply simp\n\n  txt \\<open>7\\<close>\n  apply (tactic \"tac3 1\")\n  apply (tactic \"tac_ren \\<^context> 1\")\n  apply force\n\n  txt \\<open>6 - 3\\<close>\n\n  apply (tactic \"EVERY1[tac3,tac3,tac3,tac3]\")\n\n  txt \\<open>2\\<close>\n  apply (tactic \"asm_full_simp_tac (put_simpset ss \\<^context>) 1\")\n  apply (simp (no_asm) add: inv3_def)\n  apply (intro strip, (erule conjE)+)\n  apply (rule imp_disjL [THEN iffD1])\n  apply (rule impI)\n  apply (tactic \\<open>forward_tac \\<^context> [rewrite_rule \\<^context> [@{thm Impl.inv2_def}]\n    (@{thm raw_inv2} RS @{thm invariantE})] 1\\<close>)\n  apply simp\n  apply (erule conjE)+\n  apply (rule_tac j = \"count (ssent (sen s)) (~sbit (sen s))\" and\n    k = \"count (rsent (rec s)) (sbit (sen s))\" in le_trans)\n  apply (tactic \\<open>forward_tac \\<^context> [rewrite_rule \\<^context> [@{thm inv1_def}]\n                                (@{thm raw_inv1} RS @{thm invariantE}) RS conjunct2] 1\\<close>)\n  apply (simp add: hdr_sum_def Multiset.count_def)\n  apply (rule add_le_mono)\n  apply (rule countm_props)\n  apply (simp (no_asm))\n  apply (rule countm_props)\n  apply (simp (no_asm))\n  apply assumption\n\n  txt \\<open>1\\<close>\n  apply (tactic \"tac3 1\")\n  apply (intro strip, (erule conjE)+)\n  apply (rule imp_disjL [THEN iffD1])\n  apply (rule impI)\n  apply (tactic \\<open>forward_tac \\<^context> [rewrite_rule \\<^context> [@{thm Impl.inv2_def}]\n    (@{thm raw_inv2} RS @{thm invariantE})] 1\\<close>)\n  apply simp\n  done\n\n\nsubsubsection \\<open>INVARIANT 4\\<close>\n\nlemma raw_inv4: \"invariant impl_ioa inv4\"\n\n  apply (rule invariantI)\n  txt \\<open>Base case\\<close>\n  apply (simp add: Impl.inv4_def receiver_projections sender_projections impl_ioas)\n\n  apply (simp (no_asm_simp) add: impl_ioas split del: if_split)\n  apply (induct_tac \"a\")\n\n  ML_prf \\<open>val tac4 =  asm_full_simp_tac (put_simpset ss \\<^context> addsimps [@{thm inv4_def}])\\<close>\n\n  txt \\<open>10 - 2\\<close>\n\n  apply (tactic \"EVERY1[tac4,tac4,tac4,tac4,tac4,tac4,tac4,tac4,tac4]\")\n\n  txt \\<open>2 b\\<close>\n\n  apply (intro strip, (erule conjE)+)\n  apply (tactic \\<open>forward_tac \\<^context> [rewrite_rule \\<^context> [@{thm Impl.inv2_def}]\n                               (@{thm raw_inv2} RS @{thm invariantE})] 1\\<close>)\n  apply simp\n\n  txt \\<open>1\\<close>\n  apply (tactic \"tac4 1\")\n  apply (intro strip, (erule conjE)+)\n  apply (rule ccontr)\n  apply (tactic \\<open>forward_tac \\<^context> [rewrite_rule \\<^context> [@{thm Impl.inv2_def}]\n                               (@{thm raw_inv2} RS @{thm invariantE})] 1\\<close>)\n  apply (tactic \\<open>forward_tac \\<^context> [rewrite_rule \\<^context> [@{thm Impl.inv3_def}]\n                               (@{thm raw_inv3} RS @{thm invariantE})] 1\\<close>)\n  apply simp\n  apply (rename_tac m, erule_tac x = \"m\" in allE)\n  apply simp\n  done\n\n\ntext \\<open>rebind them\\<close>\n\nlemmas inv1 = raw_inv1 [THEN invariantE, unfolded inv1_def]\n  and inv2 = raw_inv2 [THEN invariantE, unfolded inv2_def]\n  and inv3 = raw_inv3 [THEN invariantE, unfolded inv3_def]\n  and inv4 = raw_inv4 [THEN invariantE, unfolded inv4_def]\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/HOLCF/IOA/NTP/Impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5698526514141572, "lm_q2_score": 0.5195213219520929, "lm_q1q2_score": 0.29605060278058815}}
{"text": "(* derivations on arbitrary states indexed with natural numbers to differentiate the states *)\ntheory IndexedDerivations\nimports\n  HOL_ext\n  Hints\n  Protocol\n  ExecMessage\nbegin\n\n\nchapter{* Security Proofs *}\n\n\nsection{* Networked Transition Systems *}\n\ntypes 's nts = \"'s \\<times> ('s \\<times> execmsg option \\<times> 's \\<times> execmsg option) set\"\n\nsection{* Standard Execution Model *}\n\ninductive_set \n  dy    :: \"'s nts \\<Rightarrow> ('s list \\<times> execmsg set) set\"\n  for P :: \"'s nts\"\nwhere\n  init : \"([fst P], {}) \\<in> dy P\"\n| proto: \n  \"\\<lbrakk> (tr@[s], M) \\<in> dy P;\n     Option.set inp \\<subseteq> M;\n     (s, inp, s', out) \\<in> snd P\n   \\<rbrakk> \\<Longrightarrow>\n     (tr@[s,s'], M \\<union> Option.set out) \\<in> dy P\"     \n| infer:\n  \"\\<lbrakk> (tr, M) \\<in> dy P;\n     m \\<in> infer M\n   \\<rbrakk> \\<Longrightarrow>\n     (tr, insert m M) \\<in> dy P\"\n\n\nsection{* Derivations *}\n\ndatatype 's node = Init | State \"nat \\<times> 's\" | Msg execmsg\n\ntypes 's derivation = \"('s node \\<times> 's node) set\"\n\nfun analz :: \"execmsg set \\<Rightarrow> 's node set \\<Rightarrow> execmsg \\<Rightarrow> 's derivation\"\nwhere\n  \"analz M N (Tup x y) = \n    (if (Tup x y \\<in> M) \n        then {} \n        else N \\<times> {Msg (Tup x y)} \\<union> analz M N x \\<union> analz M N y \n    )\"\n| \"analz M N (Enc m k) =\n    (if (Enc m k \\<in> M)\n       then {}\n       else\n         N \\<times> {Msg (Enc m k)} \\<union> \n         (if (inv k \\<in> M)\n            then analz M {Msg (Enc m k), Msg (inv k)} m\n            else {}\n         )\n    )\"\n| \"analz M N m = \n    (if m \\<in> M then {} else N \\<times> {Msg m})\"\n\ndefinition knows :: \"'s derivation \\<Rightarrow> execmsg set\"\nwhere \"knows D \\<equiv> {m. Msg m \\<in> Range D}\"\n\ndefinition \"states\" :: \"'s derivation \\<Rightarrow> (nat \\<times> 's) set\"\nwhere \"states D \\<equiv> {s. State s \\<in> Range D}\"\n\ninductive_set\n  derivs :: \"'s nts \\<Rightarrow> 's derivation set\"\n  for P      :: \"'s nts\"\nwhere\n  init: \"{(Init, State (0,fst P))} \\<in> derivs P\"\n\n| proto:\n  \"\\<lbrakk> D \\<in> derivs P;\n     Option.set inp \\<subseteq> knows D;\n     (i, s) \\<in> states D;\n     \\<forall> (i',s') \\<in> states D. i' \\<le> i;\n     (s, inp, s', out) \\<in> snd P\n   \\<rbrakk> \\<Longrightarrow>\n     (insert (State (i,s),State (Suc i,s')) D \\<union> \n       ((Msg ` Option.set inp) \\<times>  {State (Suc i, s')}) \\<union>\n       UNION (Option.set out) (analz (knows D) {State (Suc i, s')})\n     ) \\<in> derivs P\"\n\n| hash:\n  \"\\<lbrakk> D \\<in> derivs P;\n     m \\<in> knows D;\n     Hash m \\<notin> knows D\n   \\<rbrakk> \\<Longrightarrow> \n     insert (Msg m, Msg (Hash m)) D \\<in> derivs P\"\n\n| tuple:\n  \"\\<lbrakk> D \\<in> derivs P;\n     x \\<in> knows D;\n     y \\<in> knows D;\n     Tup x y \\<notin> knows D\n   \\<rbrakk> \\<Longrightarrow> \n     {Msg x, Msg y} \\<times> {Msg (Tup x y)} \\<union> D \\<in> derivs P\"\n\n| encr:\n  \"\\<lbrakk> D \\<in> derivs P;\n     m \\<in> knows D;\n     k \\<in> knows D;\n     Enc m k \\<notin> knows D\n   \\<rbrakk> \\<Longrightarrow> \n     {Msg m, Msg k} \\<times> {Msg (Enc m k)} \\<union> D \\<in> derivs P\"\n\n\n\nsubsection{* All derivations are orders on nodes *}\n\n\nlocale derivation =\n  fixes P :: \"'s nts\"\n  and   D :: \"'s derivation\"\n  assumes derivable: \"D \\<in> derivs P\"\nbegin\n  \ntext{* A local variant of the induction rule of @{term \"reachable\"}. *}\nlemmas derivs_induct = derivs.induct\n  [ OF derivable\n  , rule_format\n  , consumes 0\n  , case_names init proto hash tuple encr\n  ]\n\n\n    \nlemma analz_irr: \n  \"N \\<subseteq> range State \\<union> { Msg m' | m'. size m' > size m} \\<Longrightarrow>\n   (x,x) \\<notin> analz M N m\"\napply(induct m arbitrary: N)\napply(simp_all)\napply(case_tac x, simp, simp, simp)\napply(clarsimp)\napply(force)\napply(case_tac x, simp)\napply(clarsimp)\noops\n\n\nlemma derivation_irr: \"(x,x) \\<notin> D\"\nproof(induct rule: derivs_induct)\n  case init thus ?case by simp\nnext\n  case (proto D inp i s s' out) thus ?case\n    apply (clarsimp simp: image_def)\n    apply (rule conjI)\n    apply (case_tac x)\n    apply (simp, simp, simp)\n    apply (case_tac out)\n    apply(simp)\n    apply(simp)\n\n\n  apply(induct t, auto)\n  apply(case_tac x, auto)\n  apply(case_tac a, auto)\n  apply(case_tac a, auto)\n  done\n\nlemma predOrd_distinct'_trans: \n  \"\\<lbrakk> predOrd t x y; predOrd t y z; distinct' t \\<rbrakk> \n   \\<Longrightarrow> predOrd t x z\"\n  apply(induct t x y rule: predOrd.induct)\n  apply(auto dest: in_set_predOrd1 in_set_predOrd2)\n  done\n\nlemma predOrd_distinct'_asymD: \n  \"\\<lbrakk> predOrd t x y; distinct' t \\<rbrakk> \\<Longrightarrow> \\<not> predOrd t y x\"\n  apply(induct t x y rule: predOrd.induct)\n  apply(auto dest: in_set_predOrd1 in_set_predOrd2)\n  done\n\n\nlemma\n\n(*\ndefinition sound :: \"'s derivation \\<Rightarrow> bool\"\nwhere \"sound dr = (case dr of (tr, D) \\<Rightarrow>\n        (acyclic ({ (State s, State s') | s s'. listOrd tr s s' } \\<union> D) \\<and> \n         (\\<forall> m \\<in> knows D. (\\<exists> s. (State s, Msg m) \\<in> D\\<^sup>+))))\"\n\ndefinition derivs :: \"'s nts \\<Rightarrow> 's derivation set\"\nwhere \"derivs P \\<equiv> \n        { (tr, drop_msgs M D) \n        | tr D M. \n          (tr, D) \\<in> derivs P \\<and> sound (tr, drop_msgs M D)\n        }\"\n*)\n\n\nsection{* Relating the two models *}\n\n\nlemma dy_conv_derivs:\n  \"{ (tr, M)       | tr M M'. M \\<subseteq> M' \\<and> (tr, M) \\<in> dy P     } = \n   { (tr, knows D) | tr D.             (tr, D) \\<in> derivs P }\"\n  oops\n\n(* MOVE *)\nlemma acyclic_empty [iff]: \"acyclic {}\"\n  by (simp add: acyclic_def)\n\n\nlemma knows_empty [iff]: \"knows {} = {}\"\n  by (auto simp: knows_def)\n\n(*\nlemma in_derivsE [elim!]:\n  \"\\<lbrakk> (tr, D) \\<in> derivs P;\n     \\<And> M D'. \\<lbrakk> (tr, D') \\<in> derivs P;  \n                D = D' - (Msg ` M) \\<times> UNIV - UNIV \\<times> (Msg ` M); \n                sound (tr, D)\n              \\<rbrakk> \\<Longrightarrow> Q\n   \\<rbrakk> \\<Longrightarrow> Q\"\n  by(auto simp: derivs_def)\n\nlemma knows_cases: \"\\<lbrakk> (tr, D) \\<in> derivs P; m \\<in> knows D \\<rbrakk> \\<Longrightarrow> R\"\n  apply(clarsimp)\n  apply(drule derivs.cases)\n  apply(simp_all)\n  oops\n*)\n\nlemma knows_union [simp]: \"knows (M \\<union> N) = knows M \\<union> knows N\"\n  by (auto simp: knows_def)\n\nlemma knows_insert_Msg [simp]: \"knows (insert (x, Msg m) D) = insert m (knows D)\"\n  by(auto simp: knows_def)\n\nlemma knows_insert_State [simp]: \"knows (insert (x, State s) D) = knows D\"\n  by(auto simp: knows_def)\n\nlemma in_knows_times: \"M \\<noteq> {} \\<Longrightarrow> (m \\<in> knows (M \\<times> N)) = (Msg m \\<in> N)\"\n  by (auto simp: knows_def Range_iff)\n\nlemma dy_imp_derivs:\n  \"(tr, M) \\<in> dy P \\<Longrightarrow>\n   \\<exists> D. (tr, D) \\<in> derivs P \\<and> M \\<subseteq> knows D\n  \"\nproof(induct rule: dy.induct)\n  case init thus ?case by(auto intro!: derivs.init)\nnext\n  case (proto tr s M inp s' out) thus ?case\n    apply(clarsimp)\n    apply(rule exI, rule conjI)\n    apply(rule_tac inp=inp in derivs.proto)\n    apply(assumption)\n    apply(blast) \n    apply(assumption)\n    apply(rule conjI)\n    apply(fastsimp)\n    apply(clarsimp)\n    apply(rule classical)\n    apply(case_tac x)\n    apply(simp_all)\n    done\nnext\n  case (infer tr M m)\n  then obtain D where the_deriv: \"(tr, D) \\<in> derivs P\" \"M \\<subseteq> knows D\"\n    by auto\n  have \" \\<lbrakk> m \\<in> infer M; M \\<subseteq> knows D; (tr, D) \\<in> derivs P \\<rbrakk> \\<Longrightarrow>\n         \\<exists>D'. (tr, D' \\<union> D) \\<in> derivs P \\<and> m \\<in> knows (D \\<union> D') \\<and> \n              (\\<forall> x \\<in> M. m \\<notin> knows D')\"\n  proof(induct arbitrary: D rule: infer.induct)\n    case Inj thus ?case \n      apply -\n      apply(rule_tac x=\"{}\" in exI)\n      apply(auto)\n      done\n  next\n    case (Tup x y) thus ?case\n      apply(clarsimp)\n      apply(rule exI, rule conjI)\n      apply(rule derivs.tuple[of tr D _ x y], assumption+)\n      oops\n\nsection{* Properties of the derivations *}\n\nfun add_index :: \"nat \\<Rightarrow> 'a list \\<Rightarrow> (nat \\<times> 'a) list\"\nwhere\n  \"add_index i []     = []\"\n| \"add_index i (x#xs) = (i,x) # add_index (Suc i) xs\"\n\ndefinition deps :: \"'s derivation \\<Rightarrow> 's derivations\"\nwhere \"deps dr \\<equiv> case dr of (tr, D) \\<Rightarrow> \n         D \\<union> { (x,y) | x y. listOrd (add_index 0 tr) (State x) (State y)}\"\n         \n    \nsection{* Executing Protocol Scripts *}\n\ntypes threadpool = \"tid \\<rightharpoonup> (rolestep list \\<times> rolestep list)\"\n\ntypes state = \"threadpool \\<times> store\"\n\n\ndefinition proto2nts :: \"proto \\<Rightarrow> state option nts\"\nwhere \"proto2nts P =\n  ( None \n  , ({ ( None, None, Some (th, st), None)\n     | th st.\n       (\\<forall> i done todo. th i = Some (done,todo) \\<longrightarrow> \n                                done = [] \\<and> todo \\<in> P) \\<and>\n       (\\<forall> a i. st (AVar a, i) \\<in> Compromised \\<union> Uncompromised)\n     } \n     \\<union>\n     { (s, None, s, Some m) \n     | s m. \n       m \\<in> IK0\n     }\n     \\<union>\n     (\\<Union> R \\<in> P.\n       { ( Some (th, st)                          \n         , Some (inst st i pt)\n         , Some (th(i\\<mapsto> (done @ [Recv l pt], todo)), st)\n         , None \n         )\n       | th st i l pt done todo.\n         th i = Some (done, Recv l pt # todo)\n       }\n     )\n     \\<union>\n     (\\<Union> R \\<in> P.\n       { ( Some (th, st)                          \n         , None\n         , Some (th(i\\<mapsto> (done @ [Send l pt], todo)), st)\n         , Some (inst st i pt) \n         )\n       | th st i l pt done todo.\n         th i = Some (done, Send l pt # todo)\n       }\n     )\n    )\n  )\n\"\n\n\n\n(* OOOOOOOOOOOOOOOOOOOOLDDDDDDDDDDDDDDDDDDDDDDDD *)\n\nterm \"undefined\"\nthm the_def\nthm \nthm undefined_def\n\ntypes explicit_trace = \"rawevent list\"\ntypes execstep = \"tid \\<times> rolestep\"\n\n\nfun knows :: \"explicit_trace \\<Rightarrow> execmsg set\"\nwhere\n  \"knows [] = {}\"\n| \"knows (Learns M # t) = M \\<union> knows t\"\n| \"knows (Step estep # t) = knows t\"\n\nfun steps :: \"explicit_trace \\<Rightarrow> execstep set\"\nwhere\n  \"steps [] = {}\"\n| \"steps (Learns M # t) = steps t\"\n| \"steps (Step estep # t) = insert estep (steps t)\"\n\ntypes state = \"explicit_trace \\<times> threadpool \\<times> store\"\n\ninductive_set \n  reachable :: \"proto \\<Rightarrow> state set\" \n  for P     :: \"proto\"\nwhere\n  init:  \"\\<lbrakk> \\<forall> i done todo. r i = Some (done,todo) \\<longrightarrow> \n                             done = [] \\<and> todo \\<in> P;\n            \\<forall> a i. s (AVar a, i) \\<in> Compromised \\<union> Uncompromised\n          \\<rbrakk>\n          \\<Longrightarrow> ([Learns IK0], r, s) \\<in> reachable P\"\n\n| send:  \"\\<lbrakk> (t, r, s) \\<in> reachable P;\n            r i = Some (done, Send l pt # todo);\n            m = inst s i pt\n          \\<rbrakk>\n          \\<Longrightarrow> (t @ [Step (i, Send l pt), \n                    Learns (pairParts m - knows t)]\n              , r(i \\<mapsto> (done @ [Send l pt], todo))\n              , s) \\<in> reachable P\"\n            \n| recv:  \"\\<lbrakk> (t, r, s) \\<in> reachable P;\n            r i = Some (done, Recv l pt # todo);\n            inst s i pt \\<in> knows t\n          \\<rbrakk>\n          \\<Longrightarrow> (t @ [Step (i, Recv l pt)]\n              , r(i \\<mapsto> (done @ [Recv l pt], todo))\n              , s) \\<in> reachable P\"\n\n| hash:  \"\\<lbrakk> (t, r, s) \\<in> reachable P;\n            m \\<in> knows t;\n            Hash m \\<notin> knows t\n          \\<rbrakk>\n          \\<Longrightarrow> (t @ [Learns {Hash m}], r, s) \\<in> reachable P\"\n\n| tuple: \"\\<lbrakk> (t, r, s) \\<in> reachable P;\n            x \\<in> knows t;\n            y \\<in> knows t;\n            Tup x y \\<notin> knows t\n          \\<rbrakk>\n          \\<Longrightarrow> (t @ [Learns {Tup x y}], r, s) \\<in> reachable P\"\n\n| encr:  \"\\<lbrakk> (t, r, s) \\<in> reachable P;\n            m \\<in> knows t;\n            k \\<in> knows t;\n            Enc m k \\<notin> knows t\n          \\<rbrakk>\n          \\<Longrightarrow> (t @ [Learns {Enc m k}], r, s) \\<in> reachable P\"\n\n\n| decr:  \"\\<lbrakk> (t, r, s) \\<in> reachable P;\n            Enc m k \\<in> knows t;\n            inv k \\<in> knows t\n          \\<rbrakk>\n          \\<Longrightarrow> (t @ [Learns (pairParts m - knows t)], r, s) \\<in> reachable P\"\n\nlocale reachable_state =  wf_proto +\n  fixes t :: explicit_trace\n  and   r :: threadpool\n  and   s :: store\n  assumes reachable [simp,intro!]: \"(t,r,s) \\<in> reachable P\"\nbegin\n  text{* A local variant of the induction rule of @{term \"reachable\"}. *}\n  lemmas reachable_induct = reachable.induct\n    [ OF reachable\n    , rule_format\n    , consumes 0\n    , case_names init send recv hash tuple encr decr\n    ]\nend\n\ntext{* An extension of the reachable state locale denoting\n       an individual thread and its state. *}\n\nlocale reachable_thread = reachable_state +\n  fixes i      :: \"tid\"\n    and \"done\" :: \"rolestep list\"\n    and todo   :: \"rolestep list\"\n  assumes thread_exists: \"r i = Some (done, todo)\"\nbegin\n\n  text{* The thread state is built such that @{term \"done @ todo\"} is\n         always a role of @{term P}. *}\n\n  lemma role_in_P:\n    \"done @ todo \\<in> P\"\n  using thread_exists\n  proof (induct arbitrary: i \"done\" todo rule: reachable_induct)\n  qed (fastsimp split: if_splits)+\n\nend\n\ntext{* Importing all lemmas of the wellformed role locale for\nthe term @{term \"done @ todo\"}. *}\nsublocale reachable_thread \\<subseteq> wf_role \"done @ todo\"\n  by (rule wf_roles[OF role_in_P])\n\n\n\nsubsection{* Basic Properties *}\n\nlemma knowsI: \"\\<lbrakk> Learns M \\<in> set t; m \\<in> M \\<rbrakk> \\<Longrightarrow> m \\<in> knows t\"\n  by(induct t rule: knows.induct, auto)\n\nlemma knowsD: \"m \\<in> knows t \\<Longrightarrow> \\<exists> M. Learns M \\<in> set t \\<and> m \\<in> M\"\n  by(induct t rule: steps.induct, auto)\n\nlemma knows_append [simp]: \n  \"knows (xs@ys) = knows xs \\<union> knows ys\"\n  by(induct xs rule: knows.induct, auto)\n\nlemma stepsI: \"Step estep \\<in> set t \\<Longrightarrow> estep \\<in> steps t\"\n  by(induct t rule: steps.induct, auto)\n\nlemma stepsD: \"estep \\<in> steps t \\<Longrightarrow> Step estep \\<in> set t\"\n  by(induct t rule: steps.induct, auto)\n\nlemma Step_in_set_conv [simp]: \n  \"(Step estep \\<in> set t) = (estep \\<in> steps t)\"\n  by(auto intro!: stepsI stepsD)\n\nlemma steps_append [simp]: \n  \"steps (t@t') = steps t \\<union> steps t'\"\n  by(induct t rule: steps.induct, auto)\n\n\n\nsubsection{* Thread Execution *}\n\nlemma (in reachable_state) step_in_dom: \n  \"(i, step) \\<in> steps t \\<Longrightarrow> i \\<in> dom r\"\nproof (induct rule: reachable_induct) qed auto\n\ncontext reachable_thread\nbegin\n\nlemma in_dom_r [iff]: \"i \\<in> dom r\" \n  by (auto intro!: thread_exists)\n\nlemma distinct_done [iff]: \"distinct done\"\nusing distinct by auto\n\nlemma distinct_todo [iff]: \"distinct todo\"\nusing distinct by auto\n\nlemma in_steps_eq_in_done:\n  \"((i, step) \\<in> steps t) = (step \\<in> set done)\"\nproof -\n  have   \n    \"((i, step) \\<in> steps t) = \n    (\\<exists> done todo. r i = Some (done, todo) \\<and> step \\<in> set done)\"\n  proof(induct arbitrary: i \"done\" todo rule: reachable_induct)\n    case (init r s i) thus ?case by fastsimp\n  qed auto\n  thus ?thesis using thread_exists by auto\nqed\n\nlemmas steps_in_done [elim!] = iffD1[OF in_steps_eq_in_done, rule_format]\nlemmas done_in_steps [elim!] = iffD2[OF in_steps_eq_in_done, rule_format]\n\nlemma todo_notin_stepsD:\n  \"step \\<in> set todo \\<Longrightarrow> (i, step) \\<notin> steps t\"\nusing distinct by(auto dest!: steps_in_done)\n\nlemmas todo_notin_stepsE = notE[OF todo_notin_stepsD, rule_format]\n\nlemma listOrd_done_imp_listOrd_trace: \n  \"listOrd done prev step \\<Longrightarrow> \n   listOrd t (Step (i, prev)) (Step (i, step))\"\nusing thread_exists\nproof(induct arbitrary: i \"done\" todo rule: reachable_induct)\n  case (init r s i \"done\" todo) thus ?case\n    by fastsimp\nnext\n  case (send t r s i \"done\" l msg todo m i' done' todo')\n  then interpret this_thread: \n    reachable_thread P t r s i \"done\" \"Send l msg # todo\"\n    by unfold_locales auto\n  from send show ?case\n    by(auto split: if_splits)\nnext\n  case (recv t r s i \"done\" l msg todo i' done' todo')\n  then interpret this_thread: \n    reachable_thread P t r s i \"done\" \"Recv l msg # todo\"\n    by unfold_locales auto\n  from recv show ?case\n    by(auto split: if_splits)\nqed auto\n\nlemma listOrd_role_imp_listOrd_trace:\n  \"\\<lbrakk> (i, step) \\<in> steps t; listOrd (done @ todo) prev step \\<rbrakk>\n  \\<Longrightarrow> listOrd t (Step (i, prev)) (Step (i, step))\"\nusing distinct\nby (fastsimp dest: in_set_listOrd2 listOrd_done_imp_listOrd_trace)\n\nend\n\n\nsubsection{* Variable Substitutions *}\n\ncontext reachable_state\nbegin\n\nlemma inst_AVar_cases: \n  \"s (AVar v, i) \\<in> Uncompromised \\<or> s (AVar v, i) \\<in> Compromised\"\n  by (induct rule: reachable_induct) (fastsimp+)\n\nlemma inst_AVar_in_IK0: \n \"s (AVar v, i) \\<in> IK0\"\nusing inst_AVar_cases[of v i] \nby (auto simp: IK0_def Uncompromised_def Compromised_def)\n\nlemma knows_IK0: \"m \\<in> IK0 \\<Longrightarrow> m \\<in> knows t\"\n  by(induct rule: reachable_induct, auto)\n\nlemma inst_AVar_in_knows [iff]:\n  \"s (AVar a, i) \\<in> knows t\"\n  by (rule knows_IK0[OF inst_AVar_in_IK0])\n\nend (* reachable_state *)\n\n(* TODO: Move *)\nlemma MVar_in_FV_conv_FMV [iff]:\n  \"(MVar v \\<in> FV pt) = (v \\<in> FMV pt)\"\n  by(induct pt, auto, case_tac varid, auto)\n\n\ncontext reachable_state\nbegin\n\nlemma send_step_FV:\n  assumes thread_exists: \"r i = Some (done, Send l msg # todo)\"\n  and FV: \"MVar n \\<in> FV msg\"\n  shows \"\\<exists> l' msg'. (i, Recv l' msg') \\<in> steps t \\<and>  MVar n \\<in> FV msg'\"\nproof -\n  interpret this_thread: reachable_thread P t r s i \"done\" \"Send l msg # todo\"\n    using thread_exists by unfold_locales auto\n  let ?role = \"done @ Send l msg # todo\"\n  have \"Send l msg \\<in> set ?role\" by simp\n  then obtain l' msg' \n    where \"listOrd ?role (Recv l' msg') (Send l msg)\"\n    and \"MVar n \\<in> FV msg'\"\n    using FV by(fast dest!: this_thread.Send_FV)\n  thus ?thesis using this_thread.distinct\n    by(auto dest: in_set_listOrd1 in_set_listOrd2)\nqed\n\nend\n\n\nsubsubsection{* The Effect of a Step on the Intruder Knowledge *}\n\n\ncontext reachable_state\nbegin\n\nlemma SendD: \n  \"(i, Send lbl pt) \\<in> steps t \\<Longrightarrow> \n   inst s i pt \\<in> knows t\"\nproof(induct rule: reachable_induct)\nqed auto\n\nend\n\n\nsubsection{* Almost Distinct Traces *}\n\nfun distinct' :: \"explicit_trace \\<Rightarrow> bool\"\nwhere\n  \"distinct' [] = True\"\n| \"distinct' (Learns M # t) =\n     ((\\<forall> m \\<in> M. m \\<notin> knows t) \\<and> distinct' t)\"\n| \"distinct' (Step estep # t) =\n     ((estep \\<notin> steps t) \\<and> distinct' t)\"\n\n\nlemma distinct'_append [simp]:\n  \"distinct' (t@t') = \n   (distinct' t \\<and> distinct' t' \\<and> \n    (knows t \\<inter> knows t' = {}) \\<and> (steps t \\<inter> steps t' = {}))\"\nproof (induct t rule: distinct'.induct)\nqed (auto intro!: knowsI)\n\nlemma distinct'_singleton [iff]: \"distinct' [x]\"\nby (cases x) auto\n\nlemma (in reachable_state) distinct'_trace [iff]:\n  \"distinct' t\"\nproof(induct rule: reachable_induct)\n  case (recv t r s i \"done\" l msg todo)\n  then interpret this_thread: \n    reachable_thread P t r s i \"done\" \"Recv l msg # todo\"\n    by unfold_locales auto\n  show ?case using `distinct' t` and this_thread.distinct\n    by(auto dest!: this_thread.steps_in_done)\nnext\n  case (send t r s i \"done\" l msg todo m)\n  then interpret this_thread: \n    reachable_thread P t r s i \"done\" \"Send l msg # todo\"\n    by unfold_locales auto\n  show ?case using `distinct' t` and this_thread.distinct\n    by(auto dest!: this_thread.steps_in_done)\nqed auto\n\n\nsubsection{* Happens-Before Order *}\n\ndatatype event = St \"tid \\<times> rolestep\" | Ln execmsg\n\nfun predOrd :: \"explicit_trace \\<Rightarrow> event \\<Rightarrow> event \\<Rightarrow> bool\"\nwhere\n  \"predOrd []             x y = False\"\n| \"predOrd (Learns M # xs) x y =\n     ((x \\<in> Ln ` M \\<and> (y \\<in> Ln ` knows xs \\<or> y \\<in> St ` steps xs)) \\<or>\n      predOrd xs x y)\"\n| \"predOrd (Step estep # xs) x y =\n     ((x = St estep \\<and> (y \\<in> Ln ` knows xs \\<or> y \\<in> St ` steps xs)) \\<or>\n      predOrd xs x y)\"\n\n\ndefinition predEqOrd :: \"explicit_trace \\<Rightarrow> event \\<Rightarrow> event \\<Rightarrow> bool\"\nwhere \"predEqOrd t x y = ((x = y) \\<or> predOrd t x y)\"\n\n\nlemma predOrd_singleton [simp]: \"\\<not> predOrd [a] x y\"\nby (cases a) auto\n\nlemma in_knows_predOrd1: \"predOrd t (Ln x) y \\<Longrightarrow> x \\<in> knows t\"\nproof (induct t)\n  case (Cons e t) thus ?case by (cases e) auto\nqed auto\n\n\nlemma in_knows_predOrd2: \"predOrd t x (Ln y) \\<Longrightarrow> y \\<in> knows t\"\nproof (induct t)\n  case (Cons e t) thus ?case by (cases e) auto\nqed auto\n\nlemma in_steps_predOrd1: \"predOrd t (St x) y \\<Longrightarrow> x \\<in> steps t\"\nproof (induct t)\n  case (Cons e t) thus ?case by (cases e) auto\nqed auto\n\nlemma in_steps_predOrd2: \"predOrd t x (St y) \\<Longrightarrow> y \\<in> steps t\"\nproof (induct t)\n  case (Cons e t) thus ?case by (cases e) auto\nqed auto\n\nlemmas event_predOrdI = \n  in_knows_predOrd1 in_knows_predOrd2 \n  in_steps_predOrd1 in_steps_predOrd2\n\nlemma in_set_predOrd1: \n  \"predOrd t x y \\<Longrightarrow> x \\<in> Ln ` knows t \\<or> x \\<in> St ` steps t\"\nby (induct t x y rule: predOrd.induct) auto\n\nlemma in_set_predOrd2: \n  \"predOrd t x y \\<Longrightarrow> y \\<in> Ln ` knows t \\<or> y \\<in> St ` steps t\"\nby (induct t x y rule: predOrd.induct) auto\n\nlemma listOrd_imp_predOrd:\n  \"listOrd t (Step e) (Step e') \\<Longrightarrow> predOrd t (St e) (St e')\"\nby (induct t rule: steps.induct) (auto dest!: stepsI)\n\nlemma predOrd_append [simp]:\n  \"predOrd (xs@ys) x y = \n   (predOrd xs x y \\<or> predOrd ys x y \\<or>\n   ((x \\<in> Ln ` knows xs \\<or> x \\<in> St ` steps xs) \\<and> \n    (y \\<in> Ln ` knows ys \\<or> y \\<in> St ` steps ys)))\"\n  apply(induct xs x y rule: predOrd.induct)\n  apply(simp_all)\n  apply(blast+)\n  done\n\nlemma predOrd_distinct'_irr [simp]: \n  \"distinct' t \\<Longrightarrow> \\<not>predOrd t x x\"\n  apply(induct t, auto)\n  apply(case_tac x, auto)\n  apply(case_tac a, auto)\n  apply(case_tac a, auto)\n  done\n\nlemma predOrd_distinct'_trans: \n  \"\\<lbrakk> predOrd t x y; predOrd t y z; distinct' t \\<rbrakk> \n   \\<Longrightarrow> predOrd t x z\"\n  apply(induct t x y rule: predOrd.induct)\n  apply(auto dest: in_set_predOrd1 in_set_predOrd2)\n  done\n\nlemma predOrd_distinct'_asymD: \n  \"\\<lbrakk> predOrd t x y; distinct' t \\<rbrakk> \\<Longrightarrow> \\<not> predOrd t y x\"\n  apply(induct t x y rule: predOrd.induct)\n  apply(auto dest: in_set_predOrd1 in_set_predOrd2)\n  done\n\n\nsublocale reachable_state \\<subseteq> beforeOrd: order \"predEqOrd t\" \"predOrd t\"\n  apply(unfold_locales)\n  apply(auto simp: predEqOrd_def\n          dest: predOrd_distinct'_asymD \n         intro: predOrd_distinct'_trans)\n  done\n\nabbreviation (in reachable_state)\n  \"pred'\"   (infixl \"\\<prec>\" 50) where \"pred' \\<equiv> predOrd t\"\n\nabbreviation (in reachable_state) \n  \"predEq'\" (infixl \"\\<preceq>\" 50) where \"predEq' \\<equiv>  predEqOrd t\"\n\nlemma predOrd_conv:\n  \"predOrd xs x y = \n  (\\<exists> ys zs. xs = ys @ zs \\<and> \n            (x \\<in> Ln ` knows ys \\<or> x \\<in> St ` steps ys) \\<and>\n            (y \\<in> Ln ` knows zs \\<or> y \\<in> St ` steps zs))\"\n  (is \"?pred xs = (\\<exists> ys zs. ?decomp xs ys zs)\")\nproof -\n  { assume \"?pred xs\"\n    hence \"\\<exists> ys zs. ?decomp xs ys zs\"\n    proof (induct xs)\n      case Nil thus ?case by simp\n    next\n      case (Cons e xs) thus ?case\n      proof(cases e)\n\tcase (Step st) thus ?thesis\n\tproof(cases \"x = St st\")\n\t  case True hence \"?decomp (e#xs) [e] xs\" \n\t    using Step Cons by auto\n\t  thus ?thesis by blast\n\tnext\n\t  case False\n\t  hence \"predOrd xs x y\"\n\t    using Step Cons by auto\n\t  then obtain ys zs where \"?decomp xs ys zs\"\n\t    using Cons by auto\n\t  hence \"?decomp (e#xs) (e#ys) zs\"\n\t    using Step Cons by auto\n\t  thus ?thesis by blast\n\tqed\n      next\n\tcase (Learns M) thus ?thesis\n\tproof(cases \"\\<exists> m \\<in> M. x = Ln m\")\n\t  case True \n\t  then obtain m where \"m \\<in> M\" and \"x = Ln m\"\n\t    by auto\n\t  hence \"?decomp (e#xs) [e] xs\" \n\t    using Learns Cons by auto\n\t  thus ?thesis by blast\n\tnext\n\t  case False\n\t  hence \"predOrd xs x y\"\n\t    using Learns Cons by auto\n\t  then obtain ys zs where \"?decomp xs ys zs\"\n\t    using Cons by auto\n\t  hence \"?decomp (e#xs) (e#ys) zs\"\n\t    using Learns Cons by auto\n\t  thus ?thesis by blast\n\tqed\n      qed\n    qed\n  }\n  moreover\n  { assume \"\\<exists> ys zs. ?decomp xs ys zs\"\n    hence \"?pred xs\"\n    proof (induct xs)\n      case Nil thus ?case by simp\n    next\n      case (Cons e xs)\n      then obtain ys zs where decomp1: \"?decomp (e#xs) ys zs\"\n\tby blast\n      hence \"ys = [] \\<and> e # xs = zs \\<or> (\\<exists>ys'. e # ys' = ys \\<and> xs = ys' @ zs)\"\n\t(is \"?nil \\<or> ?non_nil\")\n\tby (simp add: Cons_eq_append_conv)\n      moreover\n      { assume ?nil hence ?case using decomp1 by auto }\n      moreover\n      { assume ?non_nil\n\tthen obtain ys' where decomp2: \"ys = e # ys'\" and \"xs = ys' @ zs\"\n\t  by auto\n\thence ?case\n\tproof(cases e)\n\t  case (Step st) thus ?thesis\n\t  proof(cases \"x = St st\")\n\t    case True thus ?thesis\n\t      using Step decomp1 decomp2 by auto\n\t  next\n\t    case False\n\t    hence \"?decomp xs ys' zs\"\n\t      using Step decomp1 decomp2 by auto\n\t    hence \"predOrd xs x y\"\n\t      using Cons by auto\n\t    thus ?thesis\n\t      using Step by auto\n\t  qed\n\tnext\n\t  case (Learns M) thus ?thesis\n\t  proof(cases \"\\<exists> m \\<in> M. x = Ln m\")\n\t    case True thus ?thesis\n\t      using Learns decomp1 decomp2 by auto\n\t  next\n\t    case False\n\t    hence \"?decomp xs ys' zs\"\n\t      using Learns decomp1 decomp2 by auto\n\t    hence \"predOrd xs x y\"\n\t      using Cons by auto\n\t    thus ?thesis\n\t      using Learns by auto\n\t  qed\n\tqed\n      }\n      ultimately show ?case by fast\n    qed\n  }\n  ultimately show ?thesis by fast\nqed\n\n\nsubsection{* Input Terms *}\n\n\ncontext reachable_state\nbegin\n\nlemma knows_pairParts_closed:\n  \"m \\<in> knows t \\<Longrightarrow> pairParts m \\<subseteq> knows t\"\nproof(induct arbitrary: m rule: reachable_induct)\n  case init thus ?case by(auto simp: IK0_def) \nnext\n  case send thus ?case by(auto dest: pairParts_idemD)\nnext\n  case decr thus ?case by(auto dest: pairParts_idemD)\nnext\n  case tuple thus ?case by fastsimp\nqed auto\n\n\nlemmas knows_pairParts_closedD =\n  subsetD[OF knows_pairParts_closed, rule_format]\n\nlemmas rev_knows_pairParts_closedD =\n  rev_subsetD[OF _ knows_pairParts_closed, rule_format]\n\n\nlemma pairParts_before:\n  \"\\<lbrakk> predOrd t (Ln m) y; m' \\<in> pairParts m \\<rbrakk> \\<Longrightarrow>\n   predOrd t (Ln m') y\"\nproof(induct rule: reachable_induct)\n  case (hash t r s msg)\n  then interpret s1: reachable_state P t r s\n    by unfold_locales\n  from hash show ?case\n    by (fastsimp dest: s1.rev_knows_pairParts_closedD)\nnext\n  case (encr t r s msg key)\n  then interpret s1: reachable_state P t r s\n    by unfold_locales\n  from encr show ?case\n    by (fastsimp dest: s1.rev_knows_pairParts_closedD)\nnext\n  case (tuple t r s msg1 msg2)\n  then interpret s1: reachable_state P t r s\n    by unfold_locales\n  from tuple show ?case\n    by (fastsimp dest: s1.rev_knows_pairParts_closedD)\nnext\n  case (decr t r s msg key)\n  then interpret s1: reachable_state P t r s\n    by unfold_locales\n  from decr show ?case\n    by (fastsimp dest: s1.rev_knows_pairParts_closedD)\nnext\n  case (send t r s i \"done\" l msg todo msg)\n  then interpret s1: reachable_state P t r s\n    by unfold_locales\n  from send show ?case\n    by (fastsimp dest: s1.rev_knows_pairParts_closedD)\nnext\n  case (recv t r s i \"done\" l msg todo)\n  then interpret s1: reachable_state P t r s\n    by unfold_locales\n  from recv show ?case\n    by (fastsimp dest: s1.rev_knows_pairParts_closedD)\nnext\n  case (init r s) thus ?case by simp\nqed\n\nlemma Ln_before_inp:\n  \"(i, Recv l pt) \\<in> steps t \\<Longrightarrow> \n   Ln (inst s i pt) \\<prec> St (i, Recv l pt)\"\nproof(induct arbitrary: i l pt rule: reachable_induct)\nqed auto\n\nlemmas knows_inp = in_knows_predOrd1[OF Ln_before_inp, rule_format]\n\ntext{* Three of the lemmas for the reasoning technique. *}\nlemmas Input = Ln_before_inp\n\nlemma split_before:\n  \"Ln (Tup m m') \\<prec> y \\<Longrightarrow> Ln m \\<prec> y \\<and> Ln m' \\<prec> y\"\n  by (fastsimp intro: pairParts_before)\n\nlemma split_knows:\n  \"Tup m m' \\<in> knows t \\<Longrightarrow> m \\<in> knows t \\<and> m' \\<in> knows t\"\n  by (fastsimp intro: knows_pairParts_closedD)\n\nend\n\n\nsubsection{* Case Distinction on Learning Messages *}\n\ntext{* Note that the hints are logically equal to true. Thus they have no logical\n  content. However they are placed here to track the individual cases when \n  computing the decryption chains for a concrete message and protocol.\n*}\nfun decrChain :: \"string \\<Rightarrow> explicit_trace \\<Rightarrow> event set \\<Rightarrow> execmsg \\<Rightarrow> execmsg \\<Rightarrow> bool\"\nwhere\n  \"decrChain path t from (Enc msg key) m = \n   ( ( m = Enc msg key \\<and> (\\<forall> f \\<in> from. predOrd t f (Ln m)) \\<and> \n       hint ''decrChainPath'' path\n     ) \\<or>\n     ( (\\<forall> f \\<in> from. predOrd t f (Ln (Enc msg key))) \\<and> \n       decrChain (path@''E'') t {Ln (Enc msg key), Ln (inv key)} msg m  )\n   )\"\n| \"decrChain path t from (Tup x y) m = \n   ( ( m = Tup x y \\<and> (\\<forall> f \\<in> from. predOrd t f (Ln m)) \\<and>\n       hint ''decrChainPath'' path\n     ) \\<or>\n     decrChain (path@''L'') t from x m \\<or>\n     decrChain (path@''R'') t from y m\n   )\"\n| \"decrChain path t from msg m =\n   ( m = msg \\<and> (\\<forall> f \\<in> from. predOrd t f (Ln m)) \\<and>\n     hint ''decrChainPath'' path\n   )\"\n\nlemma decrChain_append:\n  \"decrChain path t from msg m \\<Longrightarrow> decrChain path (t@t') from msg m\"\n  by (induct path t \"from\" msg m rule: decrChain.induct) auto\n\nlemma decrChain_unpair:\n  \"\\<lbrakk> m' \\<in> pairParts m; m' \\<in> M;\n     \\<forall> f \\<in> from. f \\<in> Ln ` knows t \\<or> f \\<in> St ` steps t\n   \\<rbrakk> \\<Longrightarrow> decrChain path (t@[Learns M]) from m m'\"\nby (induct m arbitrary: path M) (auto simp: remove_hints)\n\nlemma decrChain_decrypt:\n  \"\\<lbrakk> decrChain path t from msg (Enc m k);\n     Enc m k \\<in> knows t; inv k \\<in> knows t;\n     m' \\<in> pairParts m; m' \\<notin> knows t \\<rbrakk> \\<Longrightarrow>\n   decrChain path' (t @ [Learns (pairParts m - knows t)]) from msg m'\"\nproof(induct msg arbitrary: path path' \"from\")\n  case (Enc msg key)\n  hence from_before [simp]: \n    \"\\<forall>f\\<in>from. predOrd t f (Ln (Enc msg key))\" by auto\n  have \"m = msg \\<and> k = key \\<or> \n    decrChain (path@''E'') t {Ln (Enc msg key), Ln (Message.inv key)} msg (Enc m k)\"\n    (is \"?here \\<or> ?nested\")\n    using Enc by auto\n  moreover\n  { assume \"?here\"\n    hence \"?case\"\n    proof(cases \"m' = Enc m k\")\n      case True thus ?thesis\n\tusing `?here` Enc by fastsimp\n    next\n      case False thus ?thesis\n\tusing `?here` Enc\n\tby(auto intro!: decrChain_unpair)\n    qed\n  }\n  moreover\n  { assume \"?nested\"\n    hence \"?case\" using Enc\n      by (fastsimp dest!: Enc(2))\n  }\n  ultimately show ?case by fast\nqed auto\n\n\nlemma (in reachable_state) knows_cases_raw:\n  assumes knows: \"m' \\<in> knows t\"\n  shows \n   \"(m' \\<in> IK0) \\<or>\n    (\\<exists> m.   m' = Hash m   \\<and> Ln m \\<prec> Ln (Hash m)) \\<or>\n    (\\<exists> m k. m' = Enc  m k \\<and> Ln m \\<prec> Ln (Enc m k) \\<and> Ln k \\<prec> Ln (Enc m k)) \\<or>\n    (\\<exists> x y. m' = Tup  x y \\<and> Ln x \\<prec> Ln (Tup x y) \\<and> Ln y \\<prec> Ln (Tup x y)) \\<or>\n    (\\<exists> i done todo. r i = Some (done, todo) \\<and> \n       (\\<exists> l pt. \n          Send l pt \\<in> set done \\<and>\n          decrChain [] t {St (i, Send l pt)} (inst s i pt) m'\n       )\n    )\"\n  (is \"?cases m' t r s\")\nproof -\n  --{* Prove cases transfer lemma for trace extension *}\n  { fix m' t t' r s\n    let ?thesis = \"?cases m' (t@t') r s\"\n    assume \"?cases m' t r s\" (is \"?ik0 \\<or> ?hash \\<or> ?enc \\<or> ?tup \\<or> ?chain t r s\")\n    moreover\n    { assume \"?ik0\"  hence \"?thesis\" by blast }    moreover\n    { assume \"?hash\" hence \"?thesis\" by fastsimp } moreover\n    { assume \"?enc\"  hence \"?thesis\" by fastsimp } moreover\n    { assume \"?tup\"  hence \"?thesis\" by fastsimp } moreover\n    { assume \"?chain t r s\"\n      hence \"?chain (t@t') r s\" \n\tby (fastsimp intro!: decrChain_append)\n      hence \"?thesis\" by blast\n    }\n    ultimately have ?thesis by fast\n  }\n  note cases_appendI_trace = this\n\n  --{* Prove actual thesis *}\n  from knows show ?thesis\n  proof (induct arbitrary: m' rule: reachable_induct)\n    case init thus ?case by simp\n  next\n    case (hash t r s m)\n    let ?t' = \"t @ [Learns {Hash m}]\"\n    note IH = hash(2)\n    have \"m' \\<in> knows t \\<or> m' = Hash m\" (is \"?old \\<or> ?new\")\n      using hash by fastsimp\n    moreover\n    { assume \"?new\" hence ?case \n\tusing `m \\<in> knows t` by fastsimp \n    }\n    moreover\n    { assume \"?old\" \n      hence ?case by (fastsimp intro!: IH cases_appendI_trace)\n    }\n    ultimately show ?case by fast\n  next\n    case (encr t r s m k)\n    let ?t' = \"t @ [Learns {Enc m k}]\"\n    note IH = encr(2)\n    have \"m' \\<in> knows t \\<or> m' = Enc m k\" (is \"?old \\<or> ?new\")\n      using encr by fastsimp\n    moreover\n    { assume \"?new\" hence ?case \n\tusing `m \\<in> knows t` and `k \\<in> knows t` by fastsimp \n    }\n    moreover\n    { assume \"?old\" \n      hence ?case by (fast intro!: IH cases_appendI_trace)\n    }\n    ultimately show ?case by fast\n  next\n    case (tuple t r s x y)\n    let ?t' = \"t @ [Learns {Tup x y}]\"\n    note IH = tuple(2)\n    have \"m' \\<in> knows t \\<or> m' = Tup x y\" (is \"?old \\<or> ?new\")\n      using tuple by fastsimp\n    moreover\n    { assume \"?new\" hence ?case \n\tusing `x \\<in> knows t` and `y \\<in> knows t` by fastsimp \n    }\n    moreover\n    { assume \"?old\" \n      hence ?case by (fast intro!: IH cases_appendI_trace)\n    }\n    ultimately show ?case by fast\n  next\n    case (recv t r s i \"done\" l pt todo)\n    hence \"?cases m' t r s\" (is \"?ik0 \\<or> ?hash \\<or> ?enc \\<or> ?tup \\<or> ?chain t r s\")\n      by clarsimp\n    moreover\n    { assume \"?ik0\"  hence \"?case\" by blast    } moreover\n    { assume \"?hash\" hence \"?case\" by fastsimp } moreover\n    { assume \"?enc\"  hence \"?case\" by fastsimp } moreover\n    { assume \"?tup\"  hence \"?case\" by fastsimp } moreover\n    { let ?t' = \"t@[Step (i, Recv l pt)]\"\n      and ?r' = \"r(i \\<mapsto> (done @ [Recv l pt], todo))\"\n      assume \"?chain t r s\" then\n      obtain i' done' todo' l' pt'\n\twhere thread': \"r i' = Some (done', todo')\"\n\tand send: \"Send l' pt' \\<in> set done'\"\n\tand chain: \"decrChain [] t {St (i', Send l' pt')} (inst s i' pt') m'\"\n\tby auto\n      then interpret th1: reachable_thread P t r s i' done' todo'\n\tusing recv by unfold_locales auto\n      moreover\n      obtain done'' todo'' \n\twhere \"Send l' pt' \\<in> set done''\"\n\tand \"?r' i' = Some (done'', todo'')\"\n\tusing `r i = Some (done, Recv l pt # todo)` thread' send\n\tby (cases \"i = i'\") (fastsimp+)\n      ultimately\n      have \"?chain ?t' ?r' s\"\n\tusing chain\n\tapply-\n\tapply(rule exI)+\n\tapply(rule conjI, assumption)\n\tby(fastsimp intro!: decrChain_append)+\n      hence \"?case\" by auto\n    }\n    ultimately show ?case by fast\n  next\n    case (send t r s i \"done\" l pt todo m)\n    then interpret th1: \n      reachable_thread P t r s i \"done\" \"Send l pt # todo\"\n      by unfold_locales\n    let ?r' = \"r(i \\<mapsto> (done @ [Send l pt], todo))\"\n    let ?m  = \"inst s i pt\"\n    let ?t' = \"(t @ [Step (i, Send l pt)]) @ [Learns (pairParts ?m - knows t)]\"\n    have \"m' \\<in> knows t \\<or> m' \\<in> pairParts m \\<and> m' \\<notin> knows t\" (is \"?old \\<or> ?new\")\n      using send by fastsimp\n    moreover\n    { assume \"?new\"\n      hence \"m' \\<in> pairParts (inst s i pt)\" and \"m' \\<notin> knows t\" \n\tusing `m = inst s i pt` by auto\n      hence \"decrChain [] ?t' {St (i, Send l pt)} ?m m'\"\n\tby (fastsimp intro!: decrChain_unpair)\n      moreover\n      have \"?r' i = Some (done @ [Send l pt], todo)\"\n\tusing th1.thread_exists by auto\n      ultimately\n      have ?case using `m = inst s i pt`\n\tapply-\n\tapply(rule disjI2)+\n\tapply(rule exI)+\n\tapply(rule conjI, assumption)\n\tapply(auto)\n\tdone\n    }\n    moreover\n    { assume \"?old\" \n      hence \"?cases m' t r s\" (is \"?ik0 \\<or> ?hash \\<or> ?enc \\<or> ?tup \\<or> ?chain t r s\")\n\tusing send by clarsimp\n      moreover\n      { assume \"?ik0\"  hence \"?case\" by blast    } moreover\n      { assume \"?hash\" hence \"?case\" by fastsimp } moreover\n      { assume \"?enc\"  hence \"?case\" by fastsimp } moreover\n      { assume \"?tup\"  hence \"?case\" by fastsimp } moreover\n      { assume \"?chain t r s\" then\n\tobtain i' done' todo' l' pt'\n\t  where thread': \"r i' = Some (done', todo')\"\n\t  and send: \"Send l' pt' \\<in> set done'\"\n\t  and chain: \"decrChain [] t {St (i', Send l' pt')} (inst s i' pt') m'\"\n\t  by auto\n\tobtain done'' todo'' \n\t  where \"Send l' pt' \\<in> set done''\"\n\t  and \"(r(i \\<mapsto> (done @ [Send l pt], todo))) i' = Some (done'', todo'')\"\n\t  using `r i = Some (done, Send l pt # todo)` thread' send\n\t  by (cases \"i = i'\") (fastsimp+)\n\thence \"?chain ?t' ?r' s\"\n\t  using chain\n\t  apply-\n\t  apply(rule exI)+\n\t  apply(rule conjI, assumption)\n\t  by(fastsimp intro!: decrChain_append)+\n\thence \"?case\" using `m = inst s i pt` by auto\n      }\n      ultimately have ?case by fast\n    }\n    ultimately show ?case by fast\n  next\n    case (decr t r s m k)\n    then interpret s1: reachable_state P t r s\n      by unfold_locales\n    let ?t' = \"t @ [Learns (pairParts m - knows t)]\"\n    note IH = decr(2)\n    have \"m' \\<in> knows t \\<or> m' \\<in> pairParts m \\<and> m' \\<notin> knows t\" (is \"?old \\<or> ?new\")\n      using decr by fastsimp\n    moreover\n    { assume \"?new\"\n      hence \"m' \\<in> pairParts m\" and \"m' \\<notin> knows t\" by auto\n      have \n\t\"predOrd t (Ln m) (Ln (Enc m k)) \\<and> predOrd t (Ln k) (Ln (Enc m k)) \\<or>\n        (\\<exists>i done todo. r i = Some (done, todo) \\<and>\n          (\\<exists>l pt. Send l pt \\<in> set done \\<and>\n                  decrChain [] t {St (i, Send l pt)} (inst s i pt) (Enc m k)))\"\n\t(is \"?fake_enc \\<or> ?chain t (Enc m k)\")\n\tusing IH[OF `Enc m k \\<in> knows t`] by auto\n      moreover\n      { assume \"?fake_enc\"\n\thence \"?case\" using `?new`\n\t  by (auto dest!: in_knows_predOrd1 s1.rev_knows_pairParts_closedD)\n      }\n      moreover\n      { assume \"?chain t (Enc m k)\" then\n\tobtain i' done' todo' l' pt'\n\t  where thread': \"r i' = Some (done', todo')\"\n\t  and send: \"Send l' pt' \\<in> set done'\"\n\t  and chain: \"decrChain [] t {St (i', Send l' pt')} (inst s i' pt') (Enc m k)\"\n\t  by auto\n\tmoreover\n\thence \"decrChain [] ?t' {St (i', Send l' pt')} (inst s i' pt') m'\"\n\t  using `?new` `Enc m k \\<in> knows t` `inv k \\<in> knows t`\n\t  by (fastsimp intro!: decrChain_decrypt)\n\tultimately\n\thave \"?chain ?t' m'\" by fastsimp\n\thence \"?case\" by blast\n      }\n      ultimately have ?case by fast\n    }\n    moreover\n    { assume \"?old\" \n      hence ?case by (fast intro!: IH cases_appendI_trace)\n    }\n    ultimately show ?case by fast thm decr\n  qed\nqed\n\nend", "meta": {"author": "meiersi", "repo": "scyther-proof", "sha": "84e42366a46f66f1b090651be3bfaa3497696280", "save_path": "github-repos/isabelle/meiersi-scyther-proof", "path": "github-repos/isabelle/meiersi-scyther-proof/scyther-proof-84e42366a46f66f1b090651be3bfaa3497696280/data/isabelle/src/experiments/protocol_semantics/IndexedDerivations.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5698526514141571, "lm_q2_score": 0.5195213219520929, "lm_q1q2_score": 0.29605060278058803}}
{"text": "theory ConditionalMode\n\nimports  Complex_Main FaultModellingTypes\n\nbegin\n\ndatatype_new ('a, 'b) ConditionalValue = \n  CVC (V: 'b)\n  | CVIF 'a \"('a, 'b) ConditionalValue\" \"('a, 'b) ConditionalValue\" \n\ndatatype_new ('FMode, 'vv) OperationalMode = \n  NominalMode real \n  | FailureMode \"'FMode\"\n  | VarMode (var: 'vv)\n\ntype_synonym ('a, 'FMode, 'vv) ConditionalMode = \n  \"('a, ('FMode, 'vv) OperationalMode) ConditionalValue\"\n\nnotation (output) NominalMode (\"N\\<langle>_\\<rangle>\" 40)\nnotation (output) FailureMode (\"F\\<langle>_\\<rangle>\" 41)\nnotation (output) VarMode (\"_\" 41)\nnotation (output) CVC  (\"\\<guillemotleft>_\\<guillemotright>\" 50)\nnotation (output) CVIF (\"_ \\<surd> _ \\<oslash> _\" 80)\n\nprimrec val_ConditionalValue :: \"('a \\<Rightarrow> bool) \\<Rightarrow> ('a, 'b) ConditionalValue \\<Rightarrow> 'b\" where\n\"val_ConditionalValue _ (CVC b) = b\" |\n\"val_ConditionalValue s (CVIF a t1 t2) = \n  (if s a then val_ConditionalValue s t1 else val_ConditionalValue s t2)\"\n\ntype_synonym 'a ConditionalValueEnv = \"('a * bool) list\"\n\ndefinition agree :: \"('a \\<Rightarrow> bool) \\<Rightarrow> 'a ConditionalValueEnv \\<Rightarrow> bool\" where\n\"agree s env = (\\<forall>x b. map_of env x = Some b \\<longrightarrow> s x = b)\"\n\nlemma agree_Nil: \"agree s []\"\nby(simp add: agree_def)\n\nlemma agree_Cons: \"distinct(map fst env) \\<Longrightarrow> x \\<notin> set(map fst env)\n  \\<Longrightarrow> agree s ((x,b) # env) = ((if b then s x else \\<not> s x) \\<and> agree s env)\"\nby(auto simp: agree_def image_iff)\n\nlemma agreeDT:\n  \"\\<lbrakk> agree s env; distinct (map fst env) \\<rbrakk> \\<Longrightarrow> (x,True) \\<in> set env \\<Longrightarrow> s x\"\nby(simp add: agree_def)\n\nlemma agreeDF:\n  \"\\<lbrakk> agree s env; distinct (map fst env) \\<rbrakk> \\<Longrightarrow> (x,False) \\<in> set env \\<Longrightarrow> \\<not> s x\"\nby(simp add: agree_def)\n\ndefinition mkIF :: \"'a \\<Rightarrow> ('a, 'b) ConditionalValue \\<Rightarrow> ('a, 'b) ConditionalValue \\<Rightarrow> \n  ('a, 'b) ConditionalValue\" where\n\"mkIF x t1 t2 = (if t1 = t2 then t1 else CVIF x t1 t2)\"\n\nfun reduce :: \"'a ConditionalValueEnv \\<Rightarrow> ('a, 'b) ConditionalValue \\<Rightarrow> \n  ('a, 'b) ConditionalValue\" where\n\"reduce env (CVIF x t1 t2) = (case map_of env x of\n     None \\<Rightarrow> mkIF x (reduce ((x,True)#env) t1) (reduce ((x,False)#env) t2) |\n     Some b \\<Rightarrow> reduce env (if b then t1 else t2))\" |\n\"reduce _ t = t\"\n\nprimrec normif :: \"'a ConditionalValueEnv \\<Rightarrow> ('a, 'b) ConditionalValue \\<Rightarrow> \n  ('a, 'b) ConditionalValue \\<Rightarrow> ('a, 'b) ConditionalValue \\<Rightarrow> ('a, 'b) ConditionalValue\" where\n\"normif env (CVC b) t1 t2 = CVC b\" |\n\"normif env (CVIF x t1 t2) t3 t4 =\n  (case map_of env x of\n     None \\<Rightarrow> mkIF x (normif ((x,True) # env) t1 t3 t4) (normif ((x,False) # env) t2 t3 t4) |\n     Some b \\<Rightarrow> if b then normif env t1 t3 t4 else normif env t2 t3 t4)\"\n\nlemma val_mkIF: \"val_ConditionalValue s (mkIF x t1 t2) = val_ConditionalValue s (CVIF x t1 t2)\"\napply (auto simp: mkIF_def Let_def)\ndone\n\ntheorem val_reduce: \"agree s env \\<Longrightarrow> distinct(map fst env) \\<Longrightarrow>\n  val_ConditionalValue s (reduce env t) = val_ConditionalValue s t\"\napply(induct t arbitrary: s env)\napply(auto simp: map_of_eq_None_iff val_mkIF agree_Cons Let_def\n  dest: agreeDT agreeDF split: option.splits)\ndone\n\nfun reduced :: \"('a, 'b) ConditionalValue \\<Rightarrow> 'a set \\<Rightarrow> bool\" where\n\"reduced (CVIF x t1 t2) X =\n  (x \\<notin> X \\<and> t1 \\<noteq> t2 \\<and> reduced t1 (insert x X) \\<and> reduced t2 (insert x X))\" |\n\"reduced _ _ = True\"\n\nlemma reduced_antimono: \"X \\<subseteq> Y \\<Longrightarrow> reduced t Y \\<Longrightarrow> reduced t X\"\napply(induction t arbitrary: X Y)\nby auto (metis insert_mono)+\n\nlemma reduced_mkIF: \"x \\<notin> X \\<Longrightarrow>\n  reduced t1 (insert x X) \\<Longrightarrow> reduced t2 (insert x X) \\<Longrightarrow> reduced (mkIF x t1 t2) X\"\nby(auto simp: mkIF_def intro:reduced_antimono)\n\nlemma reduced_reduce:\n  \"distinct(map fst env) \\<Longrightarrow> reduced (reduce env t) (fst ` set env)\"\nproof(induction t arbitrary: env)\n  case (CVIF x t1 t2)\n  thus ?case using CVIF.IH(1)[of \"(x, True) # env\"] CVIF.IH(2)[of \"(x, False) # env\"]\n    by(auto simp: map_of_eq_None_iff image_iff reduced_mkIF split: option.split)\nqed auto\n\nlemma reduced_normif:\n  \"distinct(map fst env) \\<Longrightarrow> reduced (normif env t t1 t2) (fst ` set env)\"\nproof(induction t arbitrary: t1 t2 env)\n  case (CVIF x s1 s2)\n  thus ?case using CVIF.IH(1)[of \"(x, True) # env\"] CVIF.IH(2)[of \"(x, False) # env\"]\n    by(auto simp: reduced_mkIF map_of_eq_None_iff split: option.split)\nqed (auto simp: reduced_reduce)\n\nlemma same_val_if_reduced:\n  \"reduced t X \\<Longrightarrow> \\<forall>x. x \\<notin> X \\<longrightarrow> s1 x = s2 x \\<Longrightarrow> \n  val_ConditionalValue s1 t = val_ConditionalValue s2 t\"\nby(induction t arbitrary: X) auto\n\n(*\ndatatype 'a ConditionalValuePredicateEvaluation =\n  CVPTrue | CVPFalse | CVPVar 'a | CVPNotVar 'a \n  | CVPAnd \"'a ConditionalValuePredicateEvaluation\" \"'a ConditionalValuePredicateEvaluation\"\n*)\n\nend\n", "meta": {"author": "andredidier", "repo": "phd", "sha": "113f7c8b360a3914a571db13d9513e313954f4b2", "save_path": "github-repos/isabelle/andredidier-phd", "path": "github-repos/isabelle/andredidier-phd/phd-113f7c8b360a3914a571db13d9513e313954f4b2/thesis/fault-modelling-theory/ConditionalMode.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.626124191181315, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.29595855948374056}}
{"text": "(*  Title:      HOL/Bali/Type.thy\n    Author:     David von Oheimb\n*)\n\nsubsection {* Java types *}\n\ntheory Type imports Name begin\n\ntext {*\nsimplifications:\n\\begin{itemize}\n\\item only the most important primitive types\n\\item the null type is regarded as reference type\n\\end{itemize}\n*}\n\ndatatype prim_ty        --{* primitive type, cf. 4.2 *}\n        = Void          --{* result type of void methods *}\n        | Boolean\n        | Integer\n\n\ndatatype ref_ty         --{* reference type, cf. 4.3 *}\n        = NullT         --{* null type, cf. 4.1 *}\n        | IfaceT qtname --{* interface type *}\n        | ClassT qtname --{* class type *}\n        | ArrayT ty     --{* array type *}\n\nand ty                  --{* any type, cf. 4.1 *}\n        = PrimT prim_ty --{* primitive type *}\n        | RefT  ref_ty  --{* reference type *}\n\nabbreviation \"NT == RefT NullT\"\nabbreviation \"Iface I == RefT (IfaceT I)\"\nabbreviation \"Class C == RefT (ClassT C)\"\nabbreviation Array :: \"ty \\<Rightarrow> ty\"  (\"_.[]\" [90] 90)\n  where \"T.[] == RefT (ArrayT T)\"\n\ndefinition\n  the_Class :: \"ty \\<Rightarrow> qtname\"\n  where \"the_Class T = (SOME C. T = Class C)\" (** primrec not possible here **)\n \nlemma the_Class_eq [simp]: \"the_Class (Class C)= C\"\nby (auto simp add: the_Class_def)\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/Bali/Type.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6261241772283034, "lm_q2_score": 0.4726834766204329, "lm_q1q2_score": 0.2959585528883825}}
{"text": "theory Strong_CRef\nimports Main \"CRef\" \nbegin\n\n\ncoinductive \"RGSimStrong\"::\"[('g\\<times>'l,'p,'f,'e) body,('g,'l,'p,'f,'e) config_p, (('g,'l) c_state) rel1, \n                           (('g,'l) c_state) rel1,\n                     (('g,'l) c_state,('g1,'l1) c_state) rel,\n                     (('g,'l) c_state,('g1,'l1) c_state) rel,\n                     (('g,'l) c_state,('g1,'l1) c_state)  rel,\n                     ('g1\\<times>'l1,'p,'f,'e) body,('g1,'l1,'p,'f,'e) config_p, (('g1,'l1) c_state) rel1, \n                            (('g1,'l1) c_state) rel1\n                    ] \\<Rightarrow> bool\" \n(\"'(_,_,_,_')/ \\<succeq>\\<^sub>s\\<^sub>'(\\<^sub>_\\<^sub>;\\<^sub>_\\<^sub>;\\<^sub>_\\<^sub>')/ '(_,_,_,_')\" [81,81,81,81,81,81,81,81,81,81,81] 100)\nwhere\n  srgsim: \"\\<lbrakk>(((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls))\\<in>\\<alpha>;                    \n           \\<forall>c\\<^sub>c' \\<sigma>g' \\<sigma>l'. \\<Gamma>\\<^sub>c\\<turnstile>\\<^sub>c\\<^sub>\\<tau> (c\\<^sub>c,(\\<sigma>g,\\<sigma>l)) \\<rightarrow> (c\\<^sub>c', (\\<sigma>g',\\<sigma>l'))  \\<longrightarrow> \n             (\\<exists>c\\<^sub>s' \\<Sigma>g' \\<Sigma>l'.  \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s, (\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (c\\<^sub>s', (\\<Sigma>g', \\<Sigma>l'))) \\<and> \n             (\\<forall>c\\<^sub>s' \\<Sigma>g' \\<Sigma>l'.  \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s, (\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (c\\<^sub>s', (\\<Sigma>g', \\<Sigma>l')) \\<longrightarrow>\n                (((\\<sigma>g',\\<sigma>l'),\\<sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))\\<in>\\<alpha> \\<and> \n                ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g',\\<sigma>l'),\\<sigma>ls)),\n                  (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))) \\<in> ((G\\<^sub>c,G\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<and>\n                (\\<Gamma>\\<^sub>c,(c\\<^sub>c', ((\\<sigma>g',\\<sigma>l'),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s', ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s)) ;           \n           \\<forall>v c\\<^sub>c' \\<sigma>g' \\<sigma>l' e. e=Some v \\<and> \\<Gamma>\\<^sub>c\\<turnstile>\\<^sub>c\\<^sub>e (c\\<^sub>c, (\\<sigma>g,\\<sigma>l)) \\<rightarrow> (c\\<^sub>c', (\\<sigma>g',\\<sigma>l'))  \\<longrightarrow> \n             (\\<exists> c\\<^sub>s' \\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c\\<^sub>v (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sup>+  (c\\<^sub>s', (\\<Sigma>g', \\<Sigma>l'))) \\<and>\n             (\\<forall> c\\<^sub>s' \\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c\\<^sub>v (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sup>+  (c\\<^sub>s', (\\<Sigma>g', \\<Sigma>l')) \\<longrightarrow> \n               (((\\<sigma>g',\\<sigma>l'),\\<sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))\\<in>\\<alpha> \\<and> \n               (((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g',\\<sigma>l'),\\<sigma>ls)),\n                 (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))) \\<in> (G\\<^sub>c,G\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<and>  \n               (\\<Gamma>\\<^sub>c,(c\\<^sub>c', ((\\<sigma>g',\\<sigma>l'),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s', ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s)) ;          \n           \\<forall>\\<sigma>g' \\<sigma>l' \\<sigma>ls' \\<Sigma>g' \\<Sigma>l'  \\<Sigma>ls'. \n             ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g',\\<sigma>l'),\\<sigma>ls')),\n               (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls'))) \\<in> ((R\\<^sub>c,R\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>)  \\<longrightarrow> \n             (\\<Gamma>\\<^sub>c,(c\\<^sub>c, ((\\<sigma>g',\\<sigma>l'),\\<sigma>ls')),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s, ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls')),R\\<^sub>s,G\\<^sub>s);           \n           c\\<^sub>c = Skip \\<longrightarrow> \n             (\\<exists>\\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (Skip, (\\<Sigma>g', \\<Sigma>l'))) \\<and>\n               (\\<forall>\\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (Skip, (\\<Sigma>g', \\<Sigma>l')) \\<longrightarrow>\n             ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),  (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))) \\<in> ((G\\<^sub>c,G\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<and> \n               (((\\<sigma>g,\\<sigma>l),\\<sigma>ls), ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))\\<in>\\<gamma>\\<^sub>q \\<and> \\<gamma>\\<^sub>q\\<subseteq>\\<alpha>);           \n           c\\<^sub>c = Throw \\<longrightarrow> \n             (\\<exists>\\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (Throw, (\\<Sigma>g', \\<Sigma>l'))) \\<and>\n             (\\<forall>\\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (Throw, (\\<Sigma>g', \\<Sigma>l')) \\<longrightarrow>\n             ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g,\\<sigma>l),\\<sigma>ls)), (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))) \\<in> ((G\\<^sub>c,G\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<and> \n               (((\\<sigma>g,\\<sigma>l),\\<sigma>ls), ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))\\<in>\\<gamma>\\<^sub>a \\<and> \\<gamma>\\<^sub>a\\<subseteq>\\<alpha>);\n           \\<forall>f. c\\<^sub>c = Fault f  \\<longrightarrow> \n             (\\<exists>\\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (Fault f, (\\<Sigma>g', \\<Sigma>l'))) \\<and> \n               (\\<forall>\\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (Fault f, (\\<Sigma>g', \\<Sigma>l')) \\<longrightarrow> \n             ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g,\\<sigma>l),\\<sigma>ls)), (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))) \\<in> ((G\\<^sub>c,G\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<and> \n               (((\\<sigma>g,\\<sigma>l),\\<sigma>ls), ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))\\<in>\\<alpha>);\n           c\\<^sub>c = Stuck  \\<longrightarrow> \n             (\\<exists>\\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (Stuck, (\\<Sigma>g', \\<Sigma>l'))) \\<and> \n               (\\<forall>\\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (Stuck, (\\<Sigma>g', \\<Sigma>l')) \\<longrightarrow> \n             ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g,\\<sigma>l),\\<sigma>ls)), (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))) \\<in> ((G\\<^sub>c,G\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<and> \n               (((\\<sigma>g,\\<sigma>l),\\<sigma>ls), ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))\\<in>\\<alpha>)\n          \\<rbrakk> \\<Longrightarrow> (\\<Gamma>\\<^sub>c,(c\\<^sub>c, ((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s, ((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s)\"\n    \ninductive_cases s_sim_elim_cases:\n  \"(\\<Gamma>\\<^sub>c,(c,((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>n\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c',((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s)\" \n \n \ninductive_cases s_sim_elim_cases_c[split_format (complete)]:\n  \"(\\<Gamma>\\<^sub>c,(Skip,((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>n\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c',((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s)\"  \n  \"(\\<Gamma>\\<^sub>c,(Throw, ((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>n\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c',((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s)\"        \n  \"(\\<Gamma>\\<^sub>c,(Fault f, ((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>n\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c',((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s)\"        \n  \"(\\<Gamma>\\<^sub>c,(Stuck, ((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>n\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c',((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s)\"\n\nlemma dest_s_sim_ev_step:\n  \"(\\<Gamma>\\<^sub>c,(c\\<^sub>c,((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s,((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s) \\<Longrightarrow>\n    \\<Gamma>\\<^sub>c\\<turnstile>\\<^sub>c\\<^sub>(Some v) (c\\<^sub>c, (\\<sigma>g,\\<sigma>l)) \\<rightarrow> (c\\<^sub>c', (\\<sigma>g',\\<sigma>l')) \\<Longrightarrow> \n    (\\<exists> c\\<^sub>s' \\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c\\<^sub>v (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sup>+  (c\\<^sub>s', (\\<Sigma>g', \\<Sigma>l'))) \\<and>\n    (\\<forall> c\\<^sub>s' \\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c\\<^sub>v (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sup>+  (c\\<^sub>s', (\\<Sigma>g', \\<Sigma>l')) \\<longrightarrow>\n        (((\\<sigma>g',\\<sigma>l'),\\<sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))\\<in>\\<alpha> \\<and> \n        ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g',\\<sigma>l'),\\<sigma>ls)),\n          (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))) \\<in> ((G\\<^sub>c,G\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<and>\n        (\\<Gamma>\\<^sub>c,(c\\<^sub>c', ((\\<sigma>g',\\<sigma>l'),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s', ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s))\"  \n  apply (erule s_sim_elim_cases)\n  by auto\n\nlemma dest_s_sim_ev_step':\n  \"(\\<Gamma>\\<^sub>c,(c\\<^sub>c,((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s,((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s) \\<Longrightarrow>\n    \\<Gamma>\\<^sub>c\\<turnstile>\\<^sub>c\\<^sub>(Some v) (c\\<^sub>c, (\\<sigma>g,\\<sigma>l)) \\<rightarrow> (c\\<^sub>c', (\\<sigma>g',\\<sigma>l')) \\<Longrightarrow> \n    (\\<exists> c\\<^sub>s' \\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c\\<^sub>v (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sup>+  (c\\<^sub>s', (\\<Sigma>g', \\<Sigma>l')) \\<and>    \n        (((\\<sigma>g',\\<sigma>l'),\\<sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))\\<in>\\<alpha> \\<and> \n        ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g',\\<sigma>l'),\\<sigma>ls)),\n          (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))) \\<in> ((G\\<^sub>c,G\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<and>\n        (\\<Gamma>\\<^sub>c,(c\\<^sub>c', ((\\<sigma>g',\\<sigma>l'),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s', ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s))\"  \n  using dest_s_sim_ev_step by fast\n  \n \nlemma dest_s_sim_ev_step1:\n  \"(\\<Gamma>\\<^sub>c,(c\\<^sub>c,((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s,((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s) \\<Longrightarrow>\n    \\<Gamma>\\<^sub>c\\<turnstile>\\<^sub>c\\<^sub>(Some v) (c\\<^sub>c, (\\<sigma>g,\\<sigma>l)) \\<rightarrow> (c\\<^sub>c', (\\<sigma>g',\\<sigma>l')) \\<longrightarrow> \n    (\\<exists> c\\<^sub>s' \\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c\\<^sub>v (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sup>+  (c\\<^sub>s', (\\<Sigma>g', \\<Sigma>l'))) \\<and>\n    (\\<forall> c\\<^sub>s' \\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c\\<^sub>v (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sup>+  (c\\<^sub>s', (\\<Sigma>g', \\<Sigma>l')) \\<longrightarrow>\n        (((\\<sigma>g',\\<sigma>l'),\\<sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))\\<in>\\<alpha> \\<and> \n        ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g',\\<sigma>l'),\\<sigma>ls)),\n          (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))) \\<in> ((G\\<^sub>c,G\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<and>\n        (\\<Gamma>\\<^sub>c,(c\\<^sub>c', ((\\<sigma>g',\\<sigma>l'),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s', ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s))\"  \n  by (erule s_sim_elim_cases, auto)\n\nlemma dest_s_sim_ev_step1':\n  \"(\\<Gamma>\\<^sub>c,(c\\<^sub>c,((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s,((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s) \\<Longrightarrow>\n    \\<Gamma>\\<^sub>c\\<turnstile>\\<^sub>c\\<^sub>(Some v) (c\\<^sub>c, (\\<sigma>g,\\<sigma>l)) \\<rightarrow> (c\\<^sub>c', (\\<sigma>g',\\<sigma>l')) \\<longrightarrow> \n    (\\<exists> c\\<^sub>s' \\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c\\<^sub>v (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sup>+  (c\\<^sub>s', (\\<Sigma>g', \\<Sigma>l')) \\<and>    \n        (((\\<sigma>g',\\<sigma>l'),\\<sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))\\<in>\\<alpha> \\<and> \n        ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g',\\<sigma>l'),\\<sigma>ls)),\n          (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))) \\<in> ((G\\<^sub>c,G\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<and>\n        (\\<Gamma>\\<^sub>c,(c\\<^sub>c', ((\\<sigma>g',\\<sigma>l'),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s', ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s))\"  \n  using dest_s_sim_ev_step1 by fast\n\n   \nlemma dest_s_sim_tau_step:\n  \"(\\<Gamma>\\<^sub>c,(c\\<^sub>c,((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s,((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s) \\<Longrightarrow>\n    \\<Gamma>\\<^sub>c\\<turnstile>\\<^sub>c\\<^sub>\\<tau> (c\\<^sub>c, (\\<sigma>g,\\<sigma>l)) \\<rightarrow> (c\\<^sub>c', (\\<sigma>g',\\<sigma>l')) \\<Longrightarrow> \n    (\\<exists> c\\<^sub>s' \\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>*  (c\\<^sub>s', (\\<Sigma>g', \\<Sigma>l'))) \\<and>\n    (\\<forall> c\\<^sub>s' \\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>*  (c\\<^sub>s', (\\<Sigma>g', \\<Sigma>l')) \\<longrightarrow>\n        (((\\<sigma>g',\\<sigma>l'),\\<sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))\\<in>\\<alpha> \\<and> \n        ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g',\\<sigma>l'),\\<sigma>ls)),\n          (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))) \\<in> ((G\\<^sub>c,G\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<and>\n        (\\<Gamma>\\<^sub>c,(c\\<^sub>c', ((\\<sigma>g',\\<sigma>l'),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s', ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s))\"\n  by (erule s_sim_elim_cases, force)\n\nlemma dest_s_sim_tau_step':\n  \"(\\<Gamma>\\<^sub>c,(c\\<^sub>c,((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s,((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s) \\<Longrightarrow>\n    \\<Gamma>\\<^sub>c\\<turnstile>\\<^sub>c\\<^sub>\\<tau> (c\\<^sub>c, (\\<sigma>g,\\<sigma>l)) \\<rightarrow> (c\\<^sub>c', (\\<sigma>g',\\<sigma>l')) \\<Longrightarrow> \n    (\\<exists> c\\<^sub>s' \\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>*  (c\\<^sub>s', (\\<Sigma>g', \\<Sigma>l')) \\<and>\n    (((\\<sigma>g',\\<sigma>l'),\\<sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))\\<in>\\<alpha> \\<and> \n    ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g',\\<sigma>l'),\\<sigma>ls)),\n      (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))) \\<in> ((G\\<^sub>c,G\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<and>\n    (\\<Gamma>\\<^sub>c,(c\\<^sub>c', ((\\<sigma>g',\\<sigma>l'),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s', ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s))\"\n  using dest_s_sim_tau_step by fast\n\nlemma dest_s_sim_env_step:  \n  \"(\\<Gamma>\\<^sub>c,(c\\<^sub>c,((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s,((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s) \\<Longrightarrow>\n   ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g',\\<sigma>l'),\\<sigma>ls')),\n          (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls'))) \\<in> ((R\\<^sub>c,R\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<Longrightarrow>\n    (\\<Gamma>\\<^sub>c,(c\\<^sub>c, ((\\<sigma>g',\\<sigma>l'),\\<sigma>ls')),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s, ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls')),R\\<^sub>s,G\\<^sub>s)\"  \n  by (erule s_sim_elim_cases, auto)\n  \n lemma dest_s_sim_alpha:  \n \"(\\<Gamma>\\<^sub>c,(c\\<^sub>c,((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s,((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s) \\<Longrightarrow>\n   (((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls))  \\<in> \\<alpha>\" \n   by (erule s_sim_elim_cases,auto)\n\nlemma dest_s_final_skip:\n\"(\\<Gamma>\\<^sub>c,(Skip,((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s,((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s) \\<Longrightarrow>\n (\\<exists>\\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (Skip, (\\<Sigma>g', \\<Sigma>l'))) \\<and>\n  (\\<forall>\\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (Skip, (\\<Sigma>g', \\<Sigma>l')) \\<longrightarrow>\n ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),  (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))) \\<in> ((G\\<^sub>c,G\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<and> \n   (((\\<sigma>g,\\<sigma>l),\\<sigma>ls), ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))\\<in>\\<gamma>\\<^sub>q \\<and> \\<gamma>\\<^sub>q\\<subseteq>\\<alpha>)\"\n  by (erule s_sim_elim_cases,auto)\n\nlemma dest_s_final_skip':\n\"(\\<Gamma>\\<^sub>c,(Skip,((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s,((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s) \\<Longrightarrow>\n (\\<exists>\\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (Skip, (\\<Sigma>g', \\<Sigma>l')) \\<and> \n ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),  (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))) \\<in> ((G\\<^sub>c,G\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<and> \n   (((\\<sigma>g,\\<sigma>l),\\<sigma>ls), ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))\\<in>\\<gamma>\\<^sub>q \\<and> \\<gamma>\\<^sub>q\\<subseteq>\\<alpha>)\"\n  using dest_s_final_skip by fast\n\nlemma dest_s_final_Throw:\n\"(\\<Gamma>\\<^sub>c,(Throw,((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s,((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s) \\<Longrightarrow>\n (\\<exists>\\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (Throw, (\\<Sigma>g', \\<Sigma>l'))) \\<and>\n (\\<forall>\\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (Throw, (\\<Sigma>g', \\<Sigma>l')) \\<longrightarrow>\n ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g,\\<sigma>l),\\<sigma>ls)), (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))) \\<in> ((G\\<^sub>c,G\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<and> \n (((\\<sigma>g,\\<sigma>l),\\<sigma>ls), ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))\\<in>\\<gamma>\\<^sub>a \\<and> \\<gamma>\\<^sub>a\\<subseteq>\\<alpha>)\"\n  by (erule s_sim_elim_cases,auto)\n\nlemma dest_s_final_Throw':\n\"(\\<Gamma>\\<^sub>c,(Throw,((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s,((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s) \\<Longrightarrow>\n (\\<exists>\\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (Throw, (\\<Sigma>g', \\<Sigma>l')) \\<and>\n ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g,\\<sigma>l),\\<sigma>ls)), (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))) \\<in> ((G\\<^sub>c,G\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<and> \n (((\\<sigma>g,\\<sigma>l),\\<sigma>ls), ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))\\<in>\\<gamma>\\<^sub>a \\<and> \\<gamma>\\<^sub>a\\<subseteq>\\<alpha>)\"\n  using dest_s_final_Throw by fast\n\nlemma dest_s_final_Fault:\n\"(\\<Gamma>\\<^sub>c,(Fault f,((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s,((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s) \\<Longrightarrow>\n (\\<exists>\\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (Fault f, (\\<Sigma>g', \\<Sigma>l'))) \\<and> \n               (\\<forall>\\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (Fault f, (\\<Sigma>g', \\<Sigma>l')) \\<longrightarrow> \n             ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g,\\<sigma>l),\\<sigma>ls)), (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))) \\<in> ((G\\<^sub>c,G\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<and> \n               (((\\<sigma>g,\\<sigma>l),\\<sigma>ls), ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))\\<in>\\<alpha>)\"\n  by (erule s_sim_elim_cases, auto)\n\nlemma dest_s_final_Fault':\n\"(\\<Gamma>\\<^sub>c,(Fault f,((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s,((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s) \\<Longrightarrow>\n (\\<exists>\\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (Fault f, (\\<Sigma>g', \\<Sigma>l')) \\<and>\n ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g,\\<sigma>l),\\<sigma>ls)), (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))) \\<in> ((G\\<^sub>c,G\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<and> \n   (((\\<sigma>g,\\<sigma>l),\\<sigma>ls), ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))\\<in>\\<alpha>)\"\n  using dest_s_final_Fault by fast\n\n\nlemma dest_s_final_Stuck:\n\"(\\<Gamma>\\<^sub>c,(Stuck,((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s,((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s) \\<Longrightarrow>\n (\\<exists>\\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (Stuck, (\\<Sigma>g', \\<Sigma>l'))) \\<and> \n (\\<forall>\\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (Stuck, (\\<Sigma>g', \\<Sigma>l')) \\<longrightarrow> \n ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g,\\<sigma>l),\\<sigma>ls)), (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))) \\<in> ((G\\<^sub>c,G\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<and> \n (((\\<sigma>g,\\<sigma>l),\\<sigma>ls), ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))\\<in>\\<alpha>)\"\n   by (erule s_sim_elim_cases, auto)\n\nlemma dest_s_final_Stuck':\n\"(\\<Gamma>\\<^sub>c,(Stuck,((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s,((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s) \\<Longrightarrow>\n (\\<exists>\\<Sigma>g' \\<Sigma>l'. \\<Gamma>\\<^sub>s\\<turnstile>\\<^sub>c (c\\<^sub>s,(\\<Sigma>g, \\<Sigma>l)) \\<rightarrow>\\<^sub>\\<tau>\\<^sup>* (Stuck, (\\<Sigma>g', \\<Sigma>l')) \\<and>  \n ((((\\<sigma>g,\\<sigma>l),\\<sigma>ls),((\\<sigma>g,\\<sigma>l),\\<sigma>ls)), (((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls),((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))) \\<in> ((G\\<^sub>c,G\\<^sub>s\\<^sup>*)\\<^sub>\\<alpha>) \\<and> \n (((\\<sigma>g,\\<sigma>l),\\<sigma>ls), ((\\<Sigma>g', \\<Sigma>l'), \\<Sigma>ls))\\<in>\\<alpha>)\"\n  using dest_s_final_Stuck by fast\n\n\nlemma sim_strong_weak:\"(\\<Gamma>\\<^sub>c,(c\\<^sub>c,((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s,((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s) \\<Longrightarrow> \n       (\\<Gamma>\\<^sub>c,(c\\<^sub>c,((\\<sigma>g,\\<sigma>l),\\<sigma>ls)),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>q\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c\\<^sub>s,((\\<Sigma>g, \\<Sigma>l), \\<Sigma>ls)),R\\<^sub>s,G\\<^sub>s)\"\n  apply(coinduction arbitrary: \\<sigma>g \\<sigma>l \\<sigma>ls \\<Sigma>g \\<Sigma>l \\<Sigma>ls c\\<^sub>c c\\<^sub>s, clarsimp) \n  apply (auto simp add: toSeq_def)\n         apply (auto intro: dest_s_sim_alpha)[1]  \n        apply (fast dest: dest_s_sim_tau_step')\n       apply (drule dest_s_sim_ev_step1', fast)   \n  by (fast dest: dest_s_sim_env_step dest_s_final_skip \n                dest_s_final_Throw dest_s_final_Fault dest_s_final_Stuck)+\n\ndefinition \"SRGSim_pre\"::  \n  \"[('g\\<times>'l,'p,'f,'e) body,('g \\<times> 'l,'p,'f,'e)com, \n    (('g,'l) c_state) rel1, (('g,'l) c_state) rel1,\n     (('g,'l) c_state,('g1,'l1) c_state) rel, (('g,'l) c_state,('g1,'l1) c_state) rel,\n      (('g,'l) c_state,('g1,'l1) c_state) rel,  (('g,'l) c_state,('g1,'l1) c_state) rel,\n    ('g1\\<times>'l1,'p,'f,'e) body,('g1 \\<times> 'l1,'p,'f,'e) com, \n     (('g1,'l1) c_state) rel1, (('g1,'l1) c_state) rel1] \\<Rightarrow> bool \" \n  (\"'(_,_,_,_')/ \\<succeq>\\<^sub>s\\<^sub>'(\\<^sub>_\\<^sub>;\\<^sub>_\\<^sub>\\<rhd>\\<^sub>_\\<^sub>;\\<^sub>_\\<^sub>')/ '(_,_,_,_')\" [81,81,81,81,81,81,81,81,81,81,81,81] 100)\n  where\n\" (\\<Gamma>\\<^sub>c,c,R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<xi>\\<^sub>\\<rhd>\\<^sub>\\<gamma>\\<^sub>n\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,c',R\\<^sub>s,G\\<^sub>s) \\<equiv> \n  \\<forall>\\<sigma> \\<Sigma>. (\\<sigma>,\\<Sigma>)\\<in>\\<xi> \\<longrightarrow> (\\<Gamma>\\<^sub>c,(c, \\<sigma>),R\\<^sub>c,G\\<^sub>c) \\<succeq>\\<^sub>s\\<^sub>(\\<^sub>\\<alpha>\\<^sub>;\\<^sub>\\<gamma>\\<^sub>n\\<^sub>;\\<^sub>\\<gamma>\\<^sub>a\\<^sub>) (\\<Gamma>\\<^sub>s,(c', \\<Sigma>),R\\<^sub>s,G\\<^sub>s)\n\"\n\n  \nend\n", "meta": {"author": "CompSoftVer", "repo": "CSim2", "sha": "b09a4d77ea089168b1805db5204ac151df2b9eff", "save_path": "github-repos/isabelle/CompSoftVer-CSim2", "path": "github-repos/isabelle/CompSoftVer-CSim2/CSim2-b09a4d77ea089168b1805db5204ac151df2b9eff/Conc_Refinement/Strong_CRef.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6584175139669997, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.29588798117936765}}
{"text": "(*  Title:      HOL/Auth/Guard/Proto.thy\n    Author:     Frederic Blanqui, University of Cambridge Computer Laboratory\n    Copyright   2002  University of Cambridge\n*)\n\nsection\\<open>Other Protocol-Independent Results\\<close>\n\ntheory Proto imports Guard_Public begin\n\nsubsection\\<open>protocols\\<close>\n\ntype_synonym rule = \"event set * event\"\n\nabbreviation\n  msg' :: \"rule => msg\" where\n  \"msg' R == msg (snd R)\"\n\ntype_synonym proto = \"rule set\"\n\ndefinition wdef :: \"proto => bool\" where\n\"wdef p == ALL R k. R:p --> Number k:parts {msg' R}\n--> Number k:parts (msg`(fst R))\"\n\nsubsection\\<open>substitutions\\<close>\n\nrecord subs =\n  agent   :: \"agent => agent\"\n  nonce :: \"nat => nat\"\n  nb    :: \"nat => msg\"\n  key   :: \"key => key\"\n\nprimrec apm :: \"subs => msg => msg\" where\n  \"apm s (Agent A) = Agent (agent s A)\"\n| \"apm s (Nonce n) = Nonce (nonce s n)\"\n| \"apm s (Number n) = nb s n\"\n| \"apm s (Key K) = Key (key s K)\"\n| \"apm s (Hash X) = Hash (apm s X)\"\n| \"apm s (Crypt K X) = (\nif (EX A. K = pubK A) then Crypt (pubK (agent s (agt K))) (apm s X)\nelse if (EX A. K = priK A) then Crypt (priK (agent s (agt K))) (apm s X)\nelse Crypt (key s K) (apm s X))\"\n| \"apm s \\<lbrace>X,Y\\<rbrace> = \\<lbrace>apm s X, apm s Y\\<rbrace>\"\n\nlemma apm_parts: \"X:parts {Y} ==> apm s X:parts {apm s Y}\"\napply (erule parts.induct, simp_all, blast)\napply (erule parts.Fst)\napply (erule parts.Snd)\nby (erule parts.Body)+\n\nlemma Nonce_apm [rule_format]: \"Nonce n:parts {apm s X} ==>\n(ALL k. Number k:parts {X} --> Nonce n ~:parts {nb s k}) -->\n(EX k. Nonce k:parts {X} & nonce s k = n)\"\nby (induct X, simp_all, blast)\n\nlemma wdef_Nonce: \"[| Nonce n:parts {apm s X}; R:p; msg' R = X; wdef p;\nNonce n ~:parts (apm s `(msg `(fst R))) |] ==>\n(EX k. Nonce k:parts {X} & nonce s k = n)\"\napply (erule Nonce_apm, unfold wdef_def)\napply (drule_tac x=R in spec, drule_tac x=k in spec, clarsimp)\napply (drule_tac x=x in bspec, simp)\napply (drule_tac Y=\"msg x\" and s=s in apm_parts, simp)\nby (blast dest: parts_parts)\n\nprimrec ap :: \"subs => event => event\" where\n  \"ap s (Says A B X) = Says (agent s A) (agent s B) (apm s X)\"\n| \"ap s (Gets A X) = Gets (agent s A) (apm s X)\"\n| \"ap s (Notes A X) = Notes (agent s A) (apm s X)\"\n\nabbreviation\n  ap' :: \"subs => rule => event\" where\n  \"ap' s R == ap s (snd R)\"\n\nabbreviation\n  apm' :: \"subs => rule => msg\" where\n  \"apm' s R == apm s (msg' R)\"\n\nabbreviation\n  priK' :: \"subs => agent => key\" where\n  \"priK' s A == priK (agent s A)\"\n\nabbreviation\n  pubK' :: \"subs => agent => key\" where\n  \"pubK' s A == pubK (agent s A)\"\n\nsubsection\\<open>nonces generated by a rule\\<close>\n\ndefinition newn :: \"rule => nat set\" where\n\"newn R == {n. Nonce n:parts {msg (snd R)} & Nonce n ~:parts (msg`(fst R))}\"\n\nlemma newn_parts: \"n:newn R ==> Nonce (nonce s n):parts {apm' s R}\"\nby (auto simp: newn_def dest: apm_parts)\n\nsubsection\\<open>traces generated by a protocol\\<close>\n\ndefinition ok :: \"event list => rule => subs => bool\" where\n\"ok evs R s == ((ALL x. x:fst R --> ap s x:set evs)\n& (ALL n. n:newn R --> Nonce (nonce s n) ~:used evs))\"\n\ninductive_set\n  tr :: \"proto => event list set\"\n  for p :: proto\nwhere\n\n  Nil [intro]: \"[]:tr p\"\n\n| Fake [intro]: \"[| evsf:tr p; X:synth (analz (spies evsf)) |]\n  ==> Says Spy B X # evsf:tr p\"\n\n| Proto [intro]: \"[| evs:tr p; R:p; ok evs R s |] ==> ap' s R # evs:tr p\"\n\nsubsection\\<open>general properties\\<close>\n\nlemma one_step_tr [iff]: \"one_step (tr p)\"\napply (unfold one_step_def, clarify)\nby (ind_cases \"ev # evs:tr p\" for ev evs, auto)\n\ndefinition has_only_Says' :: \"proto => bool\" where\n\"has_only_Says' p == ALL R. R:p --> is_Says (snd R)\"\n\nlemma has_only_Says'D: \"[| R:p; has_only_Says' p |]\n==> (EX A B X. snd R = Says A B X)\"\nby (unfold has_only_Says'_def is_Says_def, blast)\n\nlemma has_only_Says_tr [simp]: \"has_only_Says' p ==> has_only_Says (tr p)\"\napply (unfold has_only_Says_def)\napply (rule allI, rule allI, rule impI)\napply (erule tr.induct)\napply (auto simp: has_only_Says'_def ok_def)\nby (drule_tac x=a in spec, auto simp: is_Says_def)\n\nlemma has_only_Says'_in_trD: \"[| has_only_Says' p; list @ ev # evs1 \\<in> tr p |]\n==> (EX A B X. ev = Says A B X)\"\nby (drule has_only_Says_tr, auto)\n\nlemma ok_not_used: \"[| Nonce n ~:used evs; ok evs R s;\nALL x. x:fst R --> is_Says x |] ==> Nonce n ~:parts (apm s `(msg `(fst R)))\"\napply (unfold ok_def, clarsimp)\napply (drule_tac x=x in spec, drule_tac x=x in spec)\nby (auto simp: is_Says_def dest: Says_imp_spies not_used_not_spied parts_parts)\n\nlemma ok_is_Says: \"[| evs' @ ev # evs:tr p; ok evs R s; has_only_Says' p;\nR:p; x:fst R |] ==> is_Says x\"\napply (unfold ok_def is_Says_def, clarify)\napply (drule_tac x=x in spec, simp)\napply (subgoal_tac \"one_step (tr p)\")\napply (drule trunc, simp, drule one_step_Cons, simp)\napply (drule has_only_SaysD, simp+)\nby (clarify, case_tac x, auto)\n\nsubsection\\<open>types\\<close>\n\ntype_synonym keyfun = \"rule => subs => nat => event list => key set\"\n\ntype_synonym secfun = \"rule => nat => subs => key set => msg\"\n\nsubsection\\<open>introduction of a fresh guarded nonce\\<close>\n\ndefinition fresh :: \"proto => rule => subs => nat => key set => event list\n=> bool\" where\n\"fresh p R s n Ks evs == (EX evs1 evs2. evs = evs2 @ ap' s R # evs1\n& Nonce n ~:used evs1 & R:p & ok evs1 R s & Nonce n:parts {apm' s R}\n& apm' s R:guard n Ks)\"\n\nlemma freshD: \"fresh p R s n Ks evs ==> (EX evs1 evs2.\nevs = evs2 @ ap' s R # evs1 & Nonce n ~:used evs1 & R:p & ok evs1 R s\n& Nonce n:parts {apm' s R} & apm' s R:guard n Ks)\"\nby (unfold fresh_def, blast)\n\nlemma freshI [intro]: \"[| Nonce n ~:used evs1; R:p; Nonce n:parts {apm' s R};\nok evs1 R s; apm' s R:guard n Ks |]\n==> fresh p R s n Ks (list @ ap' s R # evs1)\"\nby (unfold fresh_def, blast)\n\nlemma freshI': \"[| Nonce n ~:used evs1; (l,r):p;\nNonce n:parts {apm s (msg r)}; ok evs1 (l,r) s; apm s (msg r):guard n Ks |]\n==> fresh p (l,r) s n Ks (evs2 @ ap s r # evs1)\"\nby (drule freshI, simp+)\n\nlemma fresh_used: \"[| fresh p R' s' n Ks evs; has_only_Says' p |]\n==> Nonce n:used evs\"\napply (unfold fresh_def, clarify)\napply (drule has_only_Says'D)\nby (auto intro: parts_used_app)\n\nlemma fresh_newn: \"[| evs' @ ap' s R # evs:tr p; wdef p; has_only_Says' p;\nNonce n ~:used evs; R:p; ok evs R s; Nonce n:parts {apm' s R} |]\n==> EX k. k:newn R & nonce s k = n\"\napply (drule wdef_Nonce, simp+)\napply (frule ok_not_used, simp+)\napply (clarify, erule ok_is_Says, simp+)\napply (clarify, rule_tac x=k in exI, simp add: newn_def)\napply (clarify, drule_tac Y=\"msg x\" and s=s in apm_parts)\napply (drule ok_not_used, simp+)\nby (clarify, erule ok_is_Says, simp_all)\n\nlemma fresh_rule: \"[| evs' @ ev # evs:tr p; wdef p; Nonce n ~:used evs;\nNonce n:parts {msg ev} |] ==> EX R s. R:p & ap' s R = ev\"\napply (drule trunc, simp, ind_cases \"ev # evs:tr p\", simp)\nby (drule_tac x=X in in_sub, drule parts_sub, simp, simp, blast+)\n\nlemma fresh_ruleD: \"[| fresh p R' s' n Ks evs; keys R' s' n evs <= Ks; wdef p;\nhas_only_Says' p; evs:tr p; ALL R k s. nonce s k = n --> Nonce n:used evs -->\nR:p --> k:newn R --> Nonce n:parts {apm' s R} --> apm' s R:guard n Ks -->\napm' s R:parts (spies evs) --> keys R s n evs <= Ks --> P |] ==> P\"\napply (frule fresh_used, simp)\napply (unfold fresh_def, clarify)\napply (drule_tac x=R' in spec)\napply (drule fresh_newn, simp+, clarify)\napply (drule_tac x=k in spec)\napply (drule_tac x=s' in spec)\napply (subgoal_tac \"apm' s' R':parts (spies (evs2 @ ap' s' R' # evs1))\")\napply (case_tac R', drule has_only_Says'D, simp, clarsimp)\napply (case_tac R', drule has_only_Says'D, simp, clarsimp)\napply (rule_tac Y=\"apm s' X\" in parts_parts, blast)\nby (rule parts.Inj, rule Says_imp_spies, simp, blast)\n\nsubsection\\<open>safe keys\\<close>\n\ndefinition safe :: \"key set => msg set => bool\" where\n\"safe Ks G == ALL K. K:Ks --> Key K ~:analz G\"\n\nlemma safeD [dest]: \"[| safe Ks G; K:Ks |] ==> Key K ~:analz G\"\nby (unfold safe_def, blast)\n\nlemma safe_insert: \"safe Ks (insert X G) ==> safe Ks G\"\nby (unfold safe_def, blast)\n\nlemma Guard_safe: \"[| Guard n Ks G; safe Ks G |] ==> Nonce n ~:analz G\"\nby (blast dest: Guard_invKey)\n\nsubsection\\<open>guardedness preservation\\<close>\n\ndefinition preserv :: \"proto => keyfun => nat => key set => bool\" where\n\"preserv p keys n Ks == (ALL evs R' s' R s. evs:tr p -->\nGuard n Ks (spies evs) --> safe Ks (spies evs) --> fresh p R' s' n Ks evs -->\nkeys R' s' n evs <= Ks --> R:p --> ok evs R s --> apm' s R:guard n Ks)\"\n\nlemma preservD: \"[| preserv p keys n Ks; evs:tr p; Guard n Ks (spies evs);\nsafe Ks (spies evs); fresh p R' s' n Ks evs; R:p; ok evs R s;\nkeys R' s' n evs <= Ks |] ==> apm' s R:guard n Ks\"\nby (unfold preserv_def, blast)\n\nlemma preservD': \"[| preserv p keys n Ks; evs:tr p; Guard n Ks (spies evs);\nsafe Ks (spies evs); fresh p R' s' n Ks evs; (l,Says A B X):p;\nok evs (l,Says A B X) s; keys R' s' n evs <= Ks |] ==> apm s X:guard n Ks\"\nby (drule preservD, simp+)\n\nsubsection\\<open>monotonic keyfun\\<close>\n\ndefinition monoton :: \"proto => keyfun => bool\" where\n\"monoton p keys == ALL R' s' n ev evs. ev # evs:tr p -->\nkeys R' s' n evs <= keys R' s' n (ev # evs)\"\n\nlemma monotonD [dest]: \"[| keys R' s' n (ev # evs) <= Ks; monoton p keys;\nev # evs:tr p |] ==> keys R' s' n evs <= Ks\"\nby (unfold monoton_def, blast)\n\nsubsection\\<open>guardedness theorem\\<close>\n\nlemma Guard_tr [rule_format]: \"[| evs:tr p; has_only_Says' p;\npreserv p keys n Ks; monoton p keys; Guard n Ks (initState Spy) |] ==>\nsafe Ks (spies evs) --> fresh p R' s' n Ks evs --> keys R' s' n evs <= Ks -->\nGuard n Ks (spies evs)\"\napply (erule tr.induct)\n(* Nil *)\napply simp\n(* Fake *)\napply (clarify, drule freshD, clarsimp)\napply (case_tac evs2)\n(* evs2 = [] *)\napply (frule has_only_Says'D, simp)\napply (clarsimp, blast)\n(* evs2 = aa # list *)\napply (clarsimp, rule conjI)\napply (blast dest: safe_insert)\n(* X:guard n Ks *)\napply (rule in_synth_Guard, simp, rule Guard_analz)\napply (blast dest: safe_insert)\napply (drule safe_insert, simp add: safe_def)\n(* Proto *)\napply (clarify, drule freshD, clarify)\napply (case_tac evs2)\n(* evs2 = [] *)\napply (frule has_only_Says'D, simp)\napply (frule_tac R=R' in has_only_Says'D, simp)\napply (case_tac R', clarsimp, blast)\n(* evs2 = ab # list *)\napply (frule has_only_Says'D, simp)\napply (clarsimp, rule conjI)\napply (drule Proto, simp+, blast dest: safe_insert)\n(* apm s X:guard n Ks *)\napply (frule Proto, simp+)\napply (erule preservD', simp+)\napply (blast dest: safe_insert)\napply (blast dest: safe_insert)\nby (blast, simp, simp, blast)\n\nsubsection\\<open>useful properties for guardedness\\<close>\n\nlemma newn_neq_used: \"[| Nonce n:used evs; ok evs R s; k:newn R |]\n==> n ~= nonce s k\"\nby (auto simp: ok_def)\n\nlemma ok_Guard: \"[| ok evs R s; Guard n Ks (spies evs); x:fst R; is_Says x |]\n==> apm s (msg x):parts (spies evs) & apm s (msg x):guard n Ks\"\napply (unfold ok_def is_Says_def, clarify)\napply (drule_tac x=\"Says A B X\" in spec, simp)\nby (drule Says_imp_spies, auto intro: parts_parts)\n\nlemma ok_parts_not_new: \"[| Y:parts (spies evs); Nonce (nonce s n):parts {Y};\nok evs R s |] ==> n ~:newn R\"\nby (auto simp: ok_def dest: not_used_not_spied parts_parts)\n\nsubsection\\<open>unicity\\<close>\n\ndefinition uniq :: \"proto => secfun => bool\" where\n\"uniq p secret == ALL evs R R' n n' Ks s s'. R:p --> R':p -->\nn:newn R --> n':newn R' --> nonce s n = nonce s' n' -->\nNonce (nonce s n):parts {apm' s R} --> Nonce (nonce s n):parts {apm' s' R'} -->\napm' s R:guard (nonce s n) Ks --> apm' s' R':guard (nonce s n) Ks -->\nevs:tr p --> Nonce (nonce s n) ~:analz (spies evs) -->\nsecret R n s Ks:parts (spies evs) --> secret R' n' s' Ks:parts (spies evs) -->\nsecret R n s Ks = secret R' n' s' Ks\"\n\nlemma uniqD: \"[| uniq p secret; evs: tr p; R:p; R':p; n:newn R; n':newn R';\nnonce s n = nonce s' n'; Nonce (nonce s n) ~:analz (spies evs);\nNonce (nonce s n):parts {apm' s R}; Nonce (nonce s n):parts {apm' s' R'};\nsecret R n s Ks:parts (spies evs); secret R' n' s' Ks:parts (spies evs);\napm' s R:guard (nonce s n) Ks; apm' s' R':guard (nonce s n) Ks |] ==>\nsecret R n s Ks = secret R' n' s' Ks\"\nby (unfold uniq_def, blast)\n\ndefinition ord :: \"proto => (rule => rule => bool) => bool\" where\n\"ord p inff == ALL R R'. R:p --> R':p --> ~ inff R R' --> inff R' R\"\n\nlemma ordD: \"[| ord p inff; ~ inff R R'; R:p; R':p |] ==> inff R' R\"\nby (unfold ord_def, blast)\n\ndefinition uniq' :: \"proto => (rule => rule => bool) => secfun => bool\" where\n\"uniq' p inff secret == ALL evs R R' n n' Ks s s'. R:p --> R':p -->\ninff R R' --> n:newn R --> n':newn R' --> nonce s n = nonce s' n' -->\nNonce (nonce s n):parts {apm' s R} --> Nonce (nonce s n):parts {apm' s' R'} -->\napm' s R:guard (nonce s n) Ks --> apm' s' R':guard (nonce s n) Ks -->\nevs:tr p --> Nonce (nonce s n) ~:analz (spies evs) -->\nsecret R n s Ks:parts (spies evs) --> secret R' n' s' Ks:parts (spies evs) -->\nsecret R n s Ks = secret R' n' s' Ks\"\n\nlemma uniq'D: \"[| uniq' p inff secret; evs: tr p; inff R R'; R:p; R':p; n:newn R;\nn':newn R'; nonce s n = nonce s' n'; Nonce (nonce s n) ~:analz (spies evs);\nNonce (nonce s n):parts {apm' s R}; Nonce (nonce s n):parts {apm' s' R'};\nsecret R n s Ks:parts (spies evs); secret R' n' s' Ks:parts (spies evs);\napm' s R:guard (nonce s n) Ks; apm' s' R':guard (nonce s n) Ks |] ==>\nsecret R n s Ks = secret R' n' s' Ks\"\nby (unfold uniq'_def, blast)\n\nlemma uniq'_imp_uniq: \"[| uniq' p inff secret; ord p inff |] ==> uniq p secret\"\napply (unfold uniq_def)\napply (rule allI)+\napply (case_tac \"inff R R'\")\napply (blast dest: uniq'D)\nby (auto dest: ordD uniq'D intro: sym)\n\nsubsection\\<open>Needham-Schroeder-Lowe\\<close>\n\ndefinition a :: agent where \"a == Friend 0\"\ndefinition b :: agent where \"b == Friend 1\"\ndefinition a' :: agent where \"a' == Friend 2\"\ndefinition b' :: agent where \"b' == Friend 3\"\ndefinition Na :: nat where \"Na == 0\"\ndefinition Nb :: nat where \"Nb == 1\"\n\nabbreviation\n  ns1 :: rule where\n  \"ns1 == ({}, Says a b (Crypt (pubK b) \\<lbrace>Nonce Na, Agent a\\<rbrace>))\"\n\nabbreviation\n  ns2 :: rule where\n  \"ns2 == ({Says a' b (Crypt (pubK b) \\<lbrace>Nonce Na, Agent a\\<rbrace>)},\n    Says b a (Crypt (pubK a) \\<lbrace>Nonce Na, Nonce Nb, Agent b\\<rbrace>))\"\n\nabbreviation\n  ns3 :: rule where\n  \"ns3 == ({Says a b (Crypt (pubK b) \\<lbrace>Nonce Na, Agent a\\<rbrace>),\n    Says b' a (Crypt (pubK a) \\<lbrace>Nonce Na, Nonce Nb, Agent b\\<rbrace>)},\n    Says a b (Crypt (pubK b) (Nonce Nb)))\"\n\ninductive_set ns :: proto where\n  [iff]: \"ns1:ns\"\n| [iff]: \"ns2:ns\"\n| [iff]: \"ns3:ns\"\n\nabbreviation (input)\n  ns3a :: event where\n  \"ns3a == Says a b (Crypt (pubK b) \\<lbrace>Nonce Na, Agent a\\<rbrace>)\"\n\nabbreviation (input)\n  ns3b :: event where\n  \"ns3b == Says b' a (Crypt (pubK a) \\<lbrace>Nonce Na, Nonce Nb, Agent b\\<rbrace>)\"\n\ndefinition keys :: \"keyfun\" where\n\"keys R' s' n evs == {priK' s' a, priK' s' b}\"\n\nlemma \"monoton ns keys\"\nby (simp add: keys_def monoton_def)\n\ndefinition secret :: \"secfun\" where\n\"secret R n s Ks ==\n(if R=ns1 then apm s (Crypt (pubK b) \\<lbrace>Nonce Na, Agent a\\<rbrace>)\nelse if R=ns2 then apm s (Crypt (pubK a) \\<lbrace>Nonce Na, Nonce Nb, Agent b\\<rbrace>)\nelse Number 0)\"\n\ndefinition inf :: \"rule => rule => bool\" where\n\"inf R R' == (R=ns1 | (R=ns2 & R'~=ns1) | (R=ns3 & R'=ns3))\"\n\nlemma inf_is_ord [iff]: \"ord ns inf\"\napply (unfold ord_def inf_def)\napply (rule allI)+\napply (rule impI)\napply (simp add: split_paired_all)\nby (rule impI, erule ns.cases, simp_all)+\n\nsubsection\\<open>general properties\\<close>\n\nlemma ns_has_only_Says' [iff]: \"has_only_Says' ns\"\napply (unfold has_only_Says'_def)\napply (rule allI, rule impI)\napply (simp add: split_paired_all)\nby (erule ns.cases, auto)\n\nlemma newn_ns1 [iff]: \"newn ns1 = {Na}\"\nby (simp add: newn_def)\n\nlemma newn_ns2 [iff]: \"newn ns2 = {Nb}\"\nby (auto simp: newn_def Na_def Nb_def)\n\nlemma newn_ns3 [iff]: \"newn ns3 = {}\"\nby (auto simp: newn_def)\n\nlemma ns_wdef [iff]: \"wdef ns\"\nby (auto simp: wdef_def elim: ns.cases)\n\nsubsection\\<open>guardedness for NSL\\<close>\n\nlemma \"uniq ns secret ==> preserv ns keys n Ks\"\napply (unfold preserv_def)\napply (rule allI)+\napply (rule impI, rule impI, rule impI, rule impI, rule impI)\napply (erule fresh_ruleD, simp, simp, simp, simp)\napply (rule allI)+\napply (rule impI, rule impI, rule impI)\napply (simp add: split_paired_all)\napply (erule ns.cases)\n(* fresh with NS1 *)\napply (rule impI, rule impI, rule impI, rule impI, rule impI, rule impI)\napply (erule ns.cases)\n(* NS1 *)\napply clarsimp\napply (frule newn_neq_used, simp, simp)\napply (rule No_Nonce, simp)\n(* NS2 *)\napply clarsimp\napply (frule newn_neq_used, simp, simp)\napply (case_tac \"nonce sa Na = nonce s Na\")\napply (frule Guard_safe, simp)\napply (frule Crypt_guard_invKey, simp)\napply (frule ok_Guard, simp, simp, simp, clarsimp)\napply (frule_tac K=\"pubK' s b\" in Crypt_guard_invKey, simp)\napply (frule_tac R=ns1 and R'=ns1 and Ks=Ks and s=sa and s'=s in uniqD, simp+)\napply (simp add: secret_def, simp add: secret_def, force, force)\napply (simp add: secret_def keys_def, blast)\napply (rule No_Nonce, simp)\n(* NS3 *)\napply clarsimp\napply (case_tac \"nonce sa Na = nonce s Nb\")\napply (frule Guard_safe, simp)\napply (frule Crypt_guard_invKey, simp)\napply (frule_tac x=ns3b in ok_Guard, simp, simp, simp, clarsimp)\napply (frule_tac K=\"pubK' s a\" in Crypt_guard_invKey, simp)\napply (frule_tac R=ns1 and R'=ns2 and Ks=Ks and s=sa and s'=s in uniqD, simp+)\napply (simp add: secret_def, simp add: secret_def, force, force)\napply (simp add: secret_def, rule No_Nonce, simp)\n(* fresh with NS2 *)\napply (rule impI, rule impI, rule impI, rule impI, rule impI, rule impI)\napply (erule ns.cases)\n(* NS1 *)\napply clarsimp\napply (frule newn_neq_used, simp, simp)\napply (rule No_Nonce, simp)\n(* NS2 *)\napply clarsimp\napply (frule newn_neq_used, simp, simp)\napply (case_tac \"nonce sa Nb = nonce s Na\")\napply (frule Guard_safe, simp)\napply (frule Crypt_guard_invKey, simp)\napply (frule ok_Guard, simp, simp, simp, clarsimp)\napply (frule_tac K=\"pubK' s b\" in Crypt_guard_invKey, simp)\napply (frule_tac R=ns2 and R'=ns1 and Ks=Ks and s=sa and s'=s in uniqD, simp+)\napply (simp add: secret_def, simp add: secret_def, force, force)\napply (simp add: secret_def, rule No_Nonce, simp)\n(* NS3 *)\napply clarsimp\napply (case_tac \"nonce sa Nb = nonce s Nb\")\napply (frule Guard_safe, simp)\napply (frule Crypt_guard_invKey, simp)\napply (frule_tac x=ns3b in ok_Guard, simp, simp, simp, clarsimp)\napply (frule_tac K=\"pubK' s a\" in Crypt_guard_invKey, simp)\napply (frule_tac R=ns2 and R'=ns2 and Ks=Ks and s=sa and s'=s in uniqD, simp+)\napply (simp add: secret_def, simp add: secret_def, force, force)\napply (simp add: secret_def keys_def, blast)\napply (rule No_Nonce, simp)\n(* fresh with NS3 *)\nby simp\n\nsubsection\\<open>unicity for NSL\\<close>\n\nlemma \"uniq' ns inf secret\"\napply (unfold uniq'_def)\napply (rule allI)+\napply (simp add: split_paired_all)\napply (rule impI, erule ns.cases)\n(* R = ns1 *)\napply (rule impI, erule ns.cases)\n(* R' = ns1 *)\napply (rule impI, rule impI, rule impI, rule impI)\napply (rule impI, rule impI, rule impI, rule impI)\napply (rule impI, erule tr.induct)\n(* Nil *)\napply (simp add: secret_def)\n(* Fake *)\napply (clarify, simp add: secret_def)\napply (drule notin_analz_insert)\napply (drule Crypt_insert_synth, simp, simp, simp)\napply (drule Crypt_insert_synth, simp, simp, simp, simp)\n(* Proto *)\napply (erule_tac P=\"ok evsa R sa\" in rev_mp)\napply (simp add: split_paired_all)\napply (erule ns.cases)\n(* ns1 *)\napply (clarify, simp add: secret_def)\napply (erule disjE, erule disjE, clarsimp)\napply (drule ok_parts_not_new, simp, simp, simp)\napply (clarify, drule ok_parts_not_new, simp, simp, simp)\n(* ns2 *)\napply (simp add: secret_def)\n(* ns3 *)\napply (simp add: secret_def)\n(* R' = ns2 *)\napply (rule impI, rule impI, rule impI, rule impI)\napply (rule impI, rule impI, rule impI, rule impI)\napply (rule impI, erule tr.induct)\n(* Nil *)\napply (simp add: secret_def)\n(* Fake *)\napply (clarify, simp add: secret_def)\napply (drule notin_analz_insert)\napply (drule Crypt_insert_synth, simp, simp, simp)\napply (drule_tac n=\"nonce s' Nb\" in Crypt_insert_synth, simp, simp, simp, simp)\n(* Proto *)\napply (erule_tac P=\"ok evsa R sa\" in rev_mp)\napply (simp add: split_paired_all)\napply (erule ns.cases)\n(* ns1 *)\napply (clarify, simp add: secret_def)\napply (drule_tac s=sa and n=Na in ok_parts_not_new, simp, simp, simp)\n(* ns2 *)\napply (clarify, simp add: secret_def)\napply (drule_tac s=sa and n=Nb in ok_parts_not_new, simp, simp, simp)\n(* ns3 *)\napply (simp add: secret_def)\n(* R' = ns3 *)\napply simp\n(* R = ns2 *)\napply (rule impI, erule ns.cases)\n(* R' = ns1 *)\napply (simp only: inf_def, blast)\n(* R' = ns2 *)\napply (rule impI, rule impI, rule impI, rule impI)\napply (rule impI, rule impI, rule impI, rule impI)\napply (rule impI, erule tr.induct)\n(* Nil *)\napply (simp add: secret_def)\n(* Fake *)\napply (clarify, simp add: secret_def)\napply (drule notin_analz_insert)\napply (drule_tac n=\"nonce s' Nb\" in Crypt_insert_synth, simp, simp, simp)\napply (drule_tac n=\"nonce s' Nb\" in Crypt_insert_synth, simp, simp, simp, simp)\n(* Proto *)\napply (erule_tac P=\"ok evsa R sa\" in rev_mp)\napply (simp add: split_paired_all)\napply (erule ns.cases)\n(* ns1 *)\napply (simp add: secret_def)\n(* ns2 *)\napply (clarify, simp add: secret_def)\napply (erule disjE, erule disjE, clarsimp, clarsimp)\napply (drule_tac s=sa and n=Nb in ok_parts_not_new, simp, simp, simp)\napply (erule disjE, clarsimp)\napply (drule_tac s=sa and n=Nb in ok_parts_not_new, simp, simp, simp)\nby (simp_all add: secret_def)\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/HOL/Auth/Guard/Proto.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.596433160611502, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.29588681067120404}}
{"text": "theory flash9Bra  imports flash9Rev\n \n  begin\nlemma onInv9:\n\n   assumes  a1:\"iInv1 \\<le> N\" and \n\n     b1:\"r \\<in> rules N\" and b2:\"invf=inv9  iInv1 \"\n   shows  \"invHoldForRule' s invf r (invariants   N)\" \n   proof - \nhave c1:\"ex1P N (% iRule1 .  r=NI_Local_GetX_PutX1 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_GetX  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Replace  iRule1 )\\<or>ex0P N (  r=NI_ShWb N )\\<or>ex0P N (  r=PI_Local_GetX_GetX2 )\\<or>ex0P N (  r=NI_Local_PutXAcksDone )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX7 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Nak2  iRule1 )\\<or>ex0P N (  r=NI_ReplaceHomeShrVld )\\<or>ex1P N (% iRule1 .  r=NI_Remote_Put  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX5 N  iRule1 )\\<or>ex0P N (  r=NI_Wb )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Get  iRule1 )\\<or>ex0P N (  r=PI_Local_Replace )\\<or>ex1P N (% iRule1 .  r=NI_ReplaceShrVld  iRule1 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Local_GetX_PutX8 N  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=NI_InvAck_2 N  iRule1 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Remote_Get_Nak2  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=PI_Remote_Replace  iRule1 )\\<or>ex0P N (  r=NI_Nak_Home )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Put2  iRule1 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_InvAck_1  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX11 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX6 N  iRule1 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Remote_Get_Put2  iRule1  iRule2 )\\<or>ex0P N (  r=PI_Local_Get_Put )\\<or>ex0P N (  r=PI_Local_GetX_PutX1 N )\\<or>ex1P N (% iRule1 .  r=NI_InvAck_1_Home  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Remote_Get_Nak1  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Nak1  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_Nak2  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX10_home N  iRule1 )\\<or>ex1P N (% iRule1 .  r=PI_Remote_Get  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_Nak3  iRule1 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Local_GetX_PutX10 N  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX2 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Remote_Get_Put1  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Remote_PutX  iRule1 )\\<or>ex1P N (% iRule1 .  r=Store  iRule1 )\\<or>ex0P N (  r=NI_FAck )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX3 N  iRule1 )\\<or>ex0P N (  r=PI_Local_GetX_PutX3 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Remote_GetX_PutX  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX8_home N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Put1 N  iRule1 )\\<or>ex0P N (  r=PI_Local_GetX_GetX1 )\\<or>ex0P N (  r=StoreHome )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Remote_GetX_Nak  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=NI_Inv  iRule1 )\\<or>ex1P N (% iRule1 .  r=PI_Remote_PutX  iRule1 )\\<or>ex0P N (  r=PI_Local_GetX_PutX4 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX4 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Nak  iRule1 )\\<or>ex0P N (  r=PI_Local_GetX_PutX2 N )\\<or>ex0P N (  r=NI_Local_Put )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_Nak1  iRule1 )\\<or>ex0P N (  r=NI_Nak_Clear )\\<or>ex0P N (  r=PI_Local_PutX )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Nak3  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Remote_GetX_Nak_Home  iRule1 )\\<or>ex0P N (  r=PI_Local_Get_Get )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX9 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=PI_Remote_GetX  iRule1 )\\<or>ex0P N (  r=NI_ReplaceHome )\\<or>ex1P N (% iRule1 .  r=NI_Remote_GetX_PutX_Home  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Put3  iRule1 )\" \n\n        apply(cut_tac  b1)\n        apply auto\n        done      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX1 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX1 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_GetX_PutX1VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_GetX  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_GetX  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_GetX  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_GetX_GetXVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Replace  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Replace  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Replace  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_ReplaceVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_ShWb N )\n\"\n         \n         from c1 have c2:\" r= NI_ShWb N \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_ShWb N ) (invariants N) \"\n            apply(cut_tac   a1   b2 c2 )\n            by (metis NI_ShWbVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_GetX2 )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_GetX2 \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (PI_Local_GetX_GetX2 ) (invariants N) \"\n            apply(cut_tac   a1   b2 c2 )\n            by (metis PI_Local_GetX_GetX2VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= NI_Local_PutXAcksDone )\n\"\n         \n         from c1 have c2:\" r= NI_Local_PutXAcksDone \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_PutXAcksDone ) (invariants N) \"\n            apply(cut_tac   a1   b2 c2 )\n            by (metis NI_Local_PutXAcksDoneVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX7 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX7 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_GetX_PutX7VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Nak2  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Nak2  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_Get_Nak2  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_Get_Nak2VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_ReplaceHomeShrVld )\n\"\n         \n         from c1 have c2:\" r= NI_ReplaceHomeShrVld \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_ReplaceHomeShrVld ) (invariants N) \"\n            apply(cut_tac   a1   b2 c2 )\n            by (metis NI_ReplaceHomeShrVldVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_Put  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_Put  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Remote_Put  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Remote_PutVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX5 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX5 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_GetX_PutX5VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_Wb )\n\"\n         \n         from c1 have c2:\" r= NI_Wb \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Wb ) (invariants N) \"\n            apply(cut_tac   a1   b2 c2 )\n            by (metis NI_WbVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Get  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Get  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_Get_Get  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_Get_GetVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_Replace )\n\"\n         \n         from c1 have c2:\" r= PI_Local_Replace \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (PI_Local_Replace ) (invariants N) \"\n            apply(cut_tac   a1   b2 c2 )\n            by (metis PI_Local_ReplaceVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_ReplaceShrVld  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_ReplaceShrVld  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_ReplaceShrVld  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_ReplaceShrVldVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Local_GetX_PutX8 N  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Local_GetX_PutX8 N  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_GetX_PutX8VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_InvAck_2 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_InvAck_2 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_InvAck_2 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_InvAck_2VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Remote_Get_Nak2  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Remote_Get_Nak2  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Remote_Get_Nak2VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= PI_Remote_Replace  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= PI_Remote_Replace  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (PI_Remote_Replace  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis PI_Remote_ReplaceVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_Nak_Home )\n\"\n         \n         from c1 have c2:\" r= NI_Nak_Home \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Nak_Home ) (invariants N) \"\n            apply(cut_tac   a1   b2 c2 )\n            by (metis NI_Nak_HomeVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Put2  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Put2  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_Get_Put2  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_Get_Put2VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_InvAck_1  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_InvAck_1  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_InvAck_1VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX11 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX11 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_GetX_PutX11VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX6 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX6 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_GetX_PutX6VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Remote_Get_Put2  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Remote_Get_Put2  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Remote_Get_Put2VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_Get_Put )\n\"\n         \n         from c1 have c2:\" r= PI_Local_Get_Put \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (PI_Local_Get_Put ) (invariants N) \"\n            apply(cut_tac   a1   b2 c2 )\n            by (metis PI_Local_Get_PutVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_PutX1 N )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_PutX1 N \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (PI_Local_GetX_PutX1 N ) (invariants N) \"\n            apply(cut_tac   a1   b2 c2 )\n            by (metis PI_Local_GetX_PutX1VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_InvAck_1_Home  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_InvAck_1_Home  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_InvAck_1_Home  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_InvAck_1_HomeVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_Get_Nak1  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_Get_Nak1  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Remote_Get_Nak1VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Nak1  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Nak1  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_Get_Nak1  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_Get_Nak1VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_Nak2  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_Nak2  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_GetX_Nak2VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX10_home N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX10_home N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_GetX_PutX10_homeVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= PI_Remote_Get  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= PI_Remote_Get  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (PI_Remote_Get  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis PI_Remote_GetVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_Nak3  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_Nak3  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_GetX_Nak3VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Local_GetX_PutX10 N  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Local_GetX_PutX10 N  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_GetX_PutX10VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX2 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX2 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_GetX_PutX2VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_Get_Put1  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_Get_Put1  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Remote_Get_Put1  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Remote_Get_Put1VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_PutX  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_PutX  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Remote_PutX  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Remote_PutXVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= Store  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= Store  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (Store  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis StoreVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_FAck )\n\"\n         \n         from c1 have c2:\" r= NI_FAck \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_FAck ) (invariants N) \"\n            apply(cut_tac   a1   b2 c2 )\n            by (metis NI_FAckVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX3 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX3 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_GetX_PutX3VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_PutX3 )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_PutX3 \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (PI_Local_GetX_PutX3 ) (invariants N) \"\n            apply(cut_tac   a1   b2 c2 )\n            by (metis PI_Local_GetX_PutX3VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Remote_GetX_PutX  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Remote_GetX_PutX  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Remote_GetX_PutXVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX8_home N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX8_home N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_GetX_PutX8_homeVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Put1 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Put1 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_Get_Put1VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_GetX1 )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_GetX1 \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (PI_Local_GetX_GetX1 ) (invariants N) \"\n            apply(cut_tac   a1   b2 c2 )\n            by (metis PI_Local_GetX_GetX1VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= StoreHome )\n\"\n         \n         from c1 have c2:\" r= StoreHome \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (StoreHome ) (invariants N) \"\n            apply(cut_tac   a1   b2 c2 )\n            by (metis StoreHomeVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Remote_GetX_Nak  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Remote_GetX_Nak  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Remote_GetX_NakVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Inv  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Inv  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Inv  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_InvVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= PI_Remote_PutX  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= PI_Remote_PutX  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (PI_Remote_PutX  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis PI_Remote_PutXVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_PutX4 )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_PutX4 \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (PI_Local_GetX_PutX4 ) (invariants N) \"\n            apply(cut_tac   a1   b2 c2 )\n            by (metis PI_Local_GetX_PutX4VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX4 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX4 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_GetX_PutX4VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Nak  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Nak  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Nak  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_NakVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_PutX2 N )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_PutX2 N \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (PI_Local_GetX_PutX2 N ) (invariants N) \"\n            apply(cut_tac   a1   b2 c2 )\n            by (metis PI_Local_GetX_PutX2VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= NI_Local_Put )\n\"\n         \n         from c1 have c2:\" r= NI_Local_Put \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_Put ) (invariants N) \"\n            apply(cut_tac   a1   b2 c2 )\n            by (metis NI_Local_PutVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_Nak1  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_Nak1  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_GetX_Nak1VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_Nak_Clear )\n\"\n         \n         from c1 have c2:\" r= NI_Nak_Clear \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Nak_Clear ) (invariants N) \"\n            apply(cut_tac   a1   b2 c2 )\n            by (metis NI_Nak_ClearVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_PutX )\n\"\n         \n         from c1 have c2:\" r= PI_Local_PutX \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (PI_Local_PutX ) (invariants N) \"\n            apply(cut_tac   a1   b2 c2 )\n            by (metis PI_Local_PutXVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Nak3  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Nak3  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_Get_Nak3  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_Get_Nak3VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_GetX_Nak_Home  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_GetX_Nak_Home  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Remote_GetX_Nak_HomeVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_Get_Get )\n\"\n         \n         from c1 have c2:\" r= PI_Local_Get_Get \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (PI_Local_Get_Get ) (invariants N) \"\n            apply(cut_tac   a1   b2 c2 )\n            by (metis PI_Local_Get_GetVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX9 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX9 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_GetX_PutX9VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= PI_Remote_GetX  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= PI_Remote_GetX  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (PI_Remote_GetX  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis PI_Remote_GetXVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_ReplaceHome )\n\"\n         \n         from c1 have c2:\" r= NI_ReplaceHome \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_ReplaceHome ) (invariants N) \"\n            apply(cut_tac   a1   b2 c2 )\n            by (metis NI_ReplaceHomeVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_GetX_PutX_Home  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_GetX_PutX_Home  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Remote_GetX_PutX_HomeVsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Put3  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Put3  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_Get_Put3  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1 )\n            by (metis NI_Local_Get_Put3VsInv9 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }ultimately show \"invHoldForRule' s invf r (invariants N) \"\n          by blast \n     qed\nend", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash9Bra.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6757646010190476, "lm_q2_score": 0.43782349911420193, "lm_q1q2_score": 0.295865622195672}}
{"text": "(*  Title:      JinjaThreads/BV/BVSpec.thy\n    Author:     Cornelia Pusch, Gerwin Klein, Andreas Lochbihler\n\n    Based on the theory Jinja/BV/BVSpec\n*)\n\nheader {* \\isaheader{The Bytecode Verifier}\\label{sec:BVSpec} *}\n\ntheory BVSpec\nimports\n  Effect\nbegin\n\ntext {*\n  This theory contains a specification of the BV. The specification\n  describes correct typings of method bodies; it corresponds \n  to type \\emph{checking}.\n*}\n\n-- \"The method type only contains declared classes:\"\ndefinition check_types :: \"'m prog \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> ty\\<^sub>i' err list \\<Rightarrow> bool\"\nwhere  \n  \"check_types P mxs mxl \\<tau>s \\<equiv> set \\<tau>s \\<subseteq> states P mxs mxl\"\n\n-- \"An instruction is welltyped if it is applicable and its effect\"\n-- \"is compatible with the type at all successor instructions:\"\ndefinition wt_instr :: \"['m prog,ty,nat,pc,ex_table,'addr instr,pc,ty\\<^sub>m] \\<Rightarrow> bool\"\n  (\"_,_,_,_,_ \\<turnstile> _,_ :: _\" [60,0,0,0,0,0,0,61] 60)\nwhere\n  \"P,T,mxs,mpc,xt \\<turnstile> i,pc :: \\<tau>s \\<equiv>\n  app i P mxs T pc mpc xt (\\<tau>s!pc) \\<and> \n  (\\<forall>(pc',\\<tau>') \\<in> set (eff i P pc xt (\\<tau>s!pc)). P \\<turnstile> \\<tau>' \\<le>' \\<tau>s!pc')\"\n\n-- {* The type at @{text \"pc=0\"} conforms to the method calling convention: *}\ndefinition wt_start :: \"['m prog,cname,ty list,nat,ty\\<^sub>m] \\<Rightarrow> bool\"\nwhere\n  \"wt_start P C Ts mxl\\<^sub>0 \\<tau>s \\<equiv>\n  P \\<turnstile> Some ([],OK (Class C)#map OK Ts@replicate mxl\\<^sub>0 Err) \\<le>' \\<tau>s!0\"\n\n-- \"A method is welltyped if the body is not empty,\"\n-- \"if the method type covers all instructions and mentions\"\n-- \"declared classes only, if the method calling convention is respected, and\"\n-- \"if all instructions are welltyped.\"\ndefinition wt_method :: \"['m prog,cname,ty list,ty,nat,nat,'addr instr list, ex_table,ty\\<^sub>m] \\<Rightarrow> bool\"\nwhere\n  \"wt_method P C Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt \\<tau>s \\<equiv>\n  0 < size is \\<and> size \\<tau>s = size is \\<and>\n  check_types P mxs (1+size Ts+mxl\\<^sub>0) (map OK \\<tau>s) \\<and>\n  wt_start P C Ts mxl\\<^sub>0 \\<tau>s \\<and>\n  (\\<forall>pc < size is. P,T\\<^sub>r,mxs,size is,xt \\<turnstile> is!pc,pc :: \\<tau>s)\"\n\n-- \"A program is welltyped if it is wellformed and all methods are welltyped\"\ndefinition wf_jvm_prog_phi :: \"ty\\<^sub>P \\<Rightarrow> 'addr jvm_prog \\<Rightarrow> bool\" (\"wf'_jvm'_prog\\<^bsub>_\\<^esub>\")\nwhere\n  \"wf_jvm_prog\\<^bsub>\\<Phi>\\<^esub> \\<equiv>\n    wf_prog (\\<lambda>P C (M,Ts,T\\<^sub>r,(mxs,mxl\\<^sub>0,is,xt)). \n      wt_method P C Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt (\\<Phi> C M))\"\n\ndefinition wf_jvm_prog :: \"'addr jvm_prog \\<Rightarrow> bool\"\nwhere\n  \"wf_jvm_prog P \\<equiv> \\<exists>\\<Phi>. wf_jvm_prog\\<^bsub>\\<Phi>\\<^esub> P\"\n\nlemma wt_jvm_progD:\n  \"wf_jvm_prog\\<^bsub>\\<Phi>\\<^esub> P \\<Longrightarrow> \\<exists>wt. wf_prog wt P\"\n(*<*) by (unfold wf_jvm_prog_phi_def, blast) (*>*)\n\nlemma wt_jvm_prog_impl_wt_instr:\n  \"\\<lbrakk> wf_jvm_prog\\<^bsub>\\<Phi>\\<^esub> P; \n      P \\<turnstile> C sees M:Ts \\<rightarrow> T = \\<lfloor>(mxs,mxl\\<^sub>0,ins,xt)\\<rfloor> in C; pc < size ins \\<rbrakk> \n  \\<Longrightarrow> P,T,mxs,size ins,xt \\<turnstile> ins!pc,pc :: \\<Phi> C M\"\n(*<*)\n  apply (unfold wf_jvm_prog_phi_def)\n  apply (drule (1) sees_wf_mdecl)\n  apply (simp add: wf_mdecl_def wt_method_def)\n  done\n(*>*)\n\nlemma wt_jvm_prog_impl_wt_start:\n  \"\\<lbrakk> wf_jvm_prog\\<^bsub>\\<Phi>\\<^esub> P; \n     P \\<turnstile> C sees M:Ts \\<rightarrow> T = \\<lfloor>(mxs,mxl\\<^sub>0,ins,xt)\\<rfloor> in C \\<rbrakk> \\<Longrightarrow> \n  0 < size ins \\<and> wt_start P C Ts mxl\\<^sub>0 (\\<Phi> C M)\"\n(*<*)\n  apply (unfold wf_jvm_prog_phi_def)\n  apply (drule (1) sees_wf_mdecl)\n  apply (simp add: wf_mdecl_def wt_method_def)\n  done\n(*>*)\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/JinjaThreads/BV/BVSpec.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6757646010190476, "lm_q2_score": 0.43782349911420193, "lm_q1q2_score": 0.295865622195672}}
{"text": "theory \"isoiec-9798_cert_auto\"\nimports\n  \"ESPLogic\"\nbegin\n\nrole A\nwhere \"A =\n  [ Recv ''1'' <| sMV ''B'', sAV ''A'', sMV ''Rb'', sMV ''Text1'' |>\n  , Recv ''text2'' ( sMV ''Text2'' )\n  , Send ''2'' <| sAV ''A'', sAV ''P'', sN ''Ra'', sMV ''Rb'', sMV ''B'',\n                  sMV ''Text2''\n               |>\n  , Recv ''3'' <| sAV ''P'', sAV ''A'', sMV ''Text5'',\n                  PEnc <| sC ''isoiec_9798_2_6_enc_3_1'', sN ''Ra'', sMV ''Kab'',\n                          sMV ''B'', sMV ''Text4''\n                       |>\n                       ( sK ''A'' ''P'' ),\n                  sMV ''TokenPA_for_B''\n               |>\n  , Recv ''text4'' <| sMV ''Text6'', sMV ''Text7'' |>\n  , Send ''4'' <| sAV ''A'', sMV ''B'', sMV ''Text7'', sAV ''P'',\n                  sMV ''TokenPA_for_B'',\n                  PEnc <| sC ''isoiec_9798_2_6_enc_4'', sN ''Rpa'', sMV ''Rb'',\n                          sMV ''Text6''\n                       |>\n                       ( sMV ''Kab'' )\n               |>\n  , Recv ''5'' <| sMV ''B'', sAV ''A'', sMV ''Text9'',\n                  PEnc <| sC ''isoiec_9798_2_6_enc_5'', sMV ''Rb'', sN ''Rpa'',\n                          sMV ''Text8''\n                       |>\n                       ( sMV ''Kab'' )\n               |>\n  ]\"\n\nrole Abd\nwhere \"Abd =\n  [ Recv ''1'' <| sMV ''Bbd'', sAV ''Abd'', sMV ''Rb'', sMV ''Text1'' |>\n  , Recv ''text2'' ( sMV ''Text2'' )\n  , Send ''2'' <| sAV ''Abd'', sAV ''Pbd'', sN ''Ra'', sMV ''Rb'',\n                  sMV ''Bbd'', sMV ''Text2''\n               |>\n  , Recv ''3'' <| sAV ''Pbd'', sAV ''Abd'', sMV ''Text5'',\n                  PEnc <| sC ''isoiec_9798_2_6_enc_3_1'', sN ''Ra'', sMV ''Kab'',\n                          sAV ''Abd'', sMV ''Bbd'', sMV ''Text4''\n                       |>\n                       ( sKbd (AVar ''Abd'') (AVar ''Pbd'') ),\n                  sMV ''TokenPA_for_B''\n               |>\n  , Recv ''text4'' <| sMV ''Text6'', sMV ''Text7'' |>\n  , Send ''4'' <| sAV ''Abd'', sMV ''Bbd'', sMV ''Text7'', sAV ''Pbd'',\n                  sMV ''TokenPA_for_B'',\n                  PEnc <| sC ''isoiec_9798_2_6_enc_4'', sN ''Rpa'', sMV ''Rb'',\n                          sMV ''Text6''\n                       |>\n                       ( sMV ''Kab'' )\n               |>\n  , Recv ''5'' <| sMV ''Bbd'', sAV ''Abd'', sMV ''Text9'',\n                  PEnc <| sC ''isoiec_9798_2_6_enc_5'', sMV ''Rb'', sN ''Rpa'',\n                          sMV ''Text8''\n                       |>\n                       ( sMV ''Kab'' )\n               |>\n  ]\"\n\nrole B\nwhere \"B =\n  [ Recv ''text1'' ( sMV ''Text1'' )\n  , Send ''1'' <| sAV ''B'', sAV ''A'', sN ''Rb'', sMV ''Text1'' |>\n  , Recv ''4'' <| sAV ''A'', sAV ''B'', sMV ''Text7'', sMV ''P'',\n                  PEnc <| sC ''isoiec_9798_2_6_enc_3_2'', sN ''Rb'', sMV ''Kab'',\n                          sAV ''A'', sMV ''Text3''\n                       |>\n                       ( PSymK ( sAV ''B'' ) ( sMV ''P'' ) ),\n                  PEnc <| sC ''isoiec_9798_2_6_enc_4'', sMV ''Rpa'', sN ''Rb'',\n                          sMV ''Text6''\n                       |>\n                       ( sMV ''Kab'' )\n               |>\n  , Recv ''text5'' <| sMV ''Text8'', sMV ''Text9'' |>\n  , Send ''5'' <| sAV ''B'', sAV ''A'', sMV ''Text9'',\n                  PEnc <| sC ''isoiec_9798_2_6_enc_5'', sN ''Rb'', sMV ''Rpa'',\n                          sMV ''Text8''\n                       |>\n                       ( sMV ''Kab'' )\n               |>\n  ]\"\n\nrole Bbd\nwhere \"Bbd =\n  [ Recv ''text1'' ( sMV ''Text1'' )\n  , Send ''1'' <| sAV ''Bbd'', sAV ''Abd'', sN ''Rb'', sMV ''Text1'' |>\n  , Recv ''4'' <| sAV ''Abd'', sAV ''Bbd'', sMV ''Text7'', sMV ''Pbd'',\n                  PEnc <| sC ''isoiec_9798_2_6_enc_3_2'', sN ''Rb'', sMV ''Kab'',\n                          sAV ''Abd'', sAV ''Bbd'', sMV ''Text3''\n                       |>\n                       ( sKbd (AVar ''Bbd'') (MVar ''Pbd'') ),\n                  PEnc <| sC ''isoiec_9798_2_6_enc_4'', sMV ''Rpa'', sN ''Rb'',\n                          sMV ''Text6''\n                       |>\n                       ( sMV ''Kab'' )\n               |>\n  , Recv ''text5'' <| sMV ''Text8'', sMV ''Text9'' |>\n  , Send ''5'' <| sAV ''Bbd'', sAV ''Abd'', sMV ''Text9'',\n                  PEnc <| sC ''isoiec_9798_2_6_enc_5'', sN ''Rb'', sMV ''Rpa'',\n                          sMV ''Text8''\n                       |>\n                       ( sMV ''Kab'' )\n               |>\n  ]\"\n\nrole P\nwhere \"P =\n  [ Recv ''2'' <| sMV ''A'', sAV ''P'', sMV ''Ra'', sMV ''Rb'', sMV ''B'',\n                  sMV ''Text2''\n               |>\n  , Recv ''text3'' <| sMV ''Text3'', sMV ''Text4'', sMV ''Text5'' |>\n  , Send ''3'' <| sAV ''P'', sMV ''A'', sMV ''Text5'',\n                  PEnc <| sC ''isoiec_9798_2_6_enc_3_1'', sMV ''Ra'', sN ''Kab'',\n                          sMV ''B'', sMV ''Text4''\n                       |>\n                       ( PSymK ( sMV ''A'' ) ( sAV ''P'' ) ),\n                  PEnc <| sC ''isoiec_9798_2_6_enc_3_2'', sMV ''Rb'', sN ''Kab'',\n                          sMV ''A'', sMV ''Text3''\n                       |>\n                       ( PSymK ( sMV ''B'' ) ( sAV ''P'' ) )\n               |>\n  ]\"\n\nrole Pbd\nwhere \"Pbd =\n  [ Recv ''2'' <| sMV ''Abd'', sAV ''Pbd'', sMV ''Ra'', sMV ''Rb'',\n                  sMV ''Bbd'', sMV ''Text2''\n               |>\n  , Recv ''text3'' <| sMV ''Text3'', sMV ''Text4'', sMV ''Text5'' |>\n  , Send ''3'' <| sAV ''Pbd'', sMV ''Abd'', sMV ''Text5'',\n                  PEnc <| sC ''isoiec_9798_2_6_enc_3_1'', sMV ''Ra'', sN ''Kab'',\n                          sMV ''Abd'', sMV ''Bbd'', sMV ''Text4''\n                       |>\n                       ( sKbd (MVar ''Abd'') (AVar ''Pbd'') ),\n                  PEnc <| sC ''isoiec_9798_2_6_enc_3_2'', sMV ''Rb'', sN ''Kab'',\n                          sMV ''Abd'', sMV ''Bbd'', sMV ''Text3''\n                       |>\n                       ( sKbd (MVar ''Bbd'') (AVar ''Pbd'') )\n               |>\n  ]\"\n\nprotocol isoiec_9798_2_6\nwhere \"isoiec_9798_2_6 = { A, Abd, B, Bbd, P, Pbd }\"\n\nlocale restricted_isoiec_9798_2_6_state = isoiec_9798_2_6_state\n\ntype_invariant typing_2_6 for isoiec_9798_2_6\nwhere \"typing_2_6 = mk_typing\n  [ ((P, ''A''), (KnownT P_2))\n  , ((Pbd, ''Abd''), (KnownT Pbd_2))\n  , ((A, ''B''), (KnownT A_1))\n  , ((P, ''B''), (KnownT P_2))\n  , ((Abd, ''Bbd''), (KnownT Abd_1))\n  , ((Pbd, ''Bbd''), (KnownT Pbd_2))\n  , ((A, ''Kab''), (SumT (KnownT A_3) (NonceT P ''Kab'')))\n  , ((Abd, ''Kab''), (SumT (KnownT Abd_3) (NonceT Pbd ''Kab'')))\n  , ((B, ''Kab''), (SumT (KnownT B_4) (NonceT P ''Kab'')))\n  , ((Bbd, ''Kab''), (SumT (KnownT Bbd_4) (NonceT Pbd ''Kab'')))\n  , ((B, ''P''), (KnownT B_4))\n  , ((Bbd, ''Pbd''), (KnownT Bbd_4))\n  , ((P, ''Ra''), (KnownT P_2))\n  , ((Pbd, ''Ra''), (KnownT Pbd_2))\n  , ((A, ''Rb''), (KnownT A_1))\n  , ((Abd, ''Rb''), (KnownT Abd_1))\n  , ((P, ''Rb''), (KnownT P_2))\n  , ((Pbd, ''Rb''), (KnownT Pbd_2))\n  , ((B, ''Rpa''),\n     (SumT (KnownT B_4) (SumT (NonceT A ''Rpa'') (NonceT Abd ''Rpa''))))\n  , ((Bbd, ''Rpa''),\n     (SumT (KnownT Bbd_4) (SumT (NonceT A ''Rpa'') (NonceT Abd ''Rpa''))))\n  , ((A, ''Text1''), (KnownT A_1))\n  , ((Abd, ''Text1''), (KnownT Abd_1))\n  , ((B, ''Text1''), (KnownT B_text1))\n  , ((Bbd, ''Text1''), (KnownT Bbd_text1))\n  , ((A, ''Text2''), (KnownT A_text2))\n  , ((Abd, ''Text2''), (KnownT Abd_text2))\n  , ((P, ''Text2''), (KnownT P_2))\n  , ((Pbd, ''Text2''), (KnownT Pbd_2))\n  , ((B, ''Text3''), (KnownT B_4))\n  , ((Bbd, ''Text3''), (KnownT Bbd_4))\n  , ((P, ''Text3''), (KnownT P_text3))\n  , ((Pbd, ''Text3''), (KnownT Pbd_text3))\n  , ((A, ''Text4''), (KnownT A_3))\n  , ((Abd, ''Text4''), (KnownT Abd_3))\n  , ((P, ''Text4''), (KnownT P_text3))\n  , ((Pbd, ''Text4''), (KnownT Pbd_text3))\n  , ((A, ''Text5''), (KnownT A_3))\n  , ((Abd, ''Text5''), (KnownT Abd_3))\n  , ((P, ''Text5''), (KnownT P_text3))\n  , ((Pbd, ''Text5''), (KnownT Pbd_text3))\n  , ((A, ''Text6''), (KnownT A_text4))\n  , ((Abd, ''Text6''), (KnownT Abd_text4))\n  , ((B, ''Text6''), (KnownT B_4))\n  , ((Bbd, ''Text6''), (KnownT Bbd_4))\n  , ((A, ''Text7''), (KnownT A_text4))\n  , ((Abd, ''Text7''), (KnownT Abd_text4))\n  , ((B, ''Text7''), (KnownT B_4))\n  , ((Bbd, ''Text7''), (KnownT Bbd_4))\n  , ((A, ''Text8''), (KnownT A_5))\n  , ((Abd, ''Text8''), (KnownT Abd_5))\n  , ((B, ''Text8''), (KnownT B_text5))\n  , ((Bbd, ''Text8''), (KnownT Bbd_text5))\n  , ((A, ''Text9''), (KnownT A_5))\n  , ((Abd, ''Text9''), (KnownT Abd_5))\n  , ((B, ''Text9''), (KnownT B_text5))\n  , ((Bbd, ''Text9''), (KnownT Bbd_text5))\n  , ((A, ''TokenPA_for_B''), (KnownT A_3))\n  , ((Abd, ''TokenPA_for_B''), (KnownT Abd_3))\n  ]\"\n\nsublocale isoiec_9798_2_6_state < typing_2_6_state\nproof -\n  have \"(t,r,s) : approx typing_2_6\"\n  proof(cases rule: reachable_in_approxI_ext\n        [OF typing_2_6.monoTyp, completeness_cases_rule])\n    case (A_1_B t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = A_1_B\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (A_1_Rb t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = A_1_Rb\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (A_1_Text1 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = A_1_Text1\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (A_3_Kab t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = A_3_Kab\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''isoiec_9798_2_6_enc_3_1'', LN ''Ra'' tid0,\n               s(MV ''Kab'' tid0), s(MV ''B'' tid0), s(MV ''Text4'' tid0)\n            |}\n            ( K ( s(AV ''A'' tid0) ) ( s(AV ''P'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (A_3_Text4 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = A_3_Text4\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''isoiec_9798_2_6_enc_3_1'', LN ''Ra'' tid0,\n               s(MV ''Kab'' tid0), s(MV ''B'' tid0), s(MV ''Text4'' tid0)\n            |}\n            ( K ( s(AV ''A'' tid0) ) ( s(AV ''P'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (A_3_Text5 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = A_3_Text5\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (A_3_TokenPA_for_B t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = A_3_TokenPA_for_B\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (A_text4_Text6 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = A_text4_Text6\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (A_text4_Text7 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = A_text4_Text7\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (A_5_Text8 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = A_5_Text8\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''isoiec_9798_2_6_enc_5'', s(MV ''Rb'' tid0), LN ''Rpa'' tid0,\n               s(MV ''Text8'' tid0)\n            |}\n            ( s(MV ''Kab'' tid0) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (A_5_Text9 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = A_5_Text9\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (Abd_1_Bbd t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Abd_1_Bbd\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (Abd_1_Rb t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Abd_1_Rb\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (Abd_1_Text1 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Abd_1_Text1\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (Abd_3_Kab t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Abd_3_Kab\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''isoiec_9798_2_6_enc_3_1'', LN ''Ra'' tid0,\n               s(MV ''Kab'' tid0), s(AV ''Abd'' tid0), s(MV ''Bbd'' tid0),\n               s(MV ''Text4'' tid0)\n            |}\n            ( Kbd ( s(AV ''Abd'' tid0) ) ( s(AV ''Pbd'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (Abd_3_Text4 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Abd_3_Text4\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''isoiec_9798_2_6_enc_3_1'', LN ''Ra'' tid0,\n               s(MV ''Kab'' tid0), s(AV ''Abd'' tid0), s(MV ''Bbd'' tid0),\n               s(MV ''Text4'' tid0)\n            |}\n            ( Kbd ( s(AV ''Abd'' tid0) ) ( s(AV ''Pbd'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (Abd_3_Text5 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Abd_3_Text5\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (Abd_3_TokenPA_for_B t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Abd_3_TokenPA_for_B\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (Abd_text4_Text6 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Abd_text4_Text6\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (Abd_text4_Text7 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Abd_text4_Text7\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (Abd_5_Text8 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Abd_5_Text8\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''isoiec_9798_2_6_enc_5'', s(MV ''Rb'' tid0), LN ''Rpa'' tid0,\n               s(MV ''Text8'' tid0)\n            |}\n            ( s(MV ''Kab'' tid0) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (Abd_5_Text9 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Abd_5_Text9\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (B_4_Kab t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = B_4_Kab\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''isoiec_9798_2_6_enc_3_2'', LN ''Rb'' tid0,\n               s(MV ''Kab'' tid0), s(AV ''A'' tid0), s(MV ''Text3'' tid0)\n            |}\n            ( K ( s(AV ''B'' tid0) ) ( s(MV ''P'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (B_4_P t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = B_4_P\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (B_4_Rpa t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = B_4_Rpa\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''isoiec_9798_2_6_enc_4'', s(MV ''Rpa'' tid0), LN ''Rb'' tid0,\n               s(MV ''Text6'' tid0)\n            |}\n            ( s(MV ''Kab'' tid0) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (B_4_Text3 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = B_4_Text3\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''isoiec_9798_2_6_enc_3_2'', LN ''Rb'' tid0,\n               s(MV ''Kab'' tid0), s(AV ''A'' tid0), s(MV ''Text3'' tid0)\n            |}\n            ( K ( s(AV ''B'' tid0) ) ( s(MV ''P'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (B_4_Text6 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = B_4_Text6\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''isoiec_9798_2_6_enc_4'', s(MV ''Rpa'' tid0), LN ''Rb'' tid0,\n               s(MV ''Text6'' tid0)\n            |}\n            ( s(MV ''Kab'' tid0) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (B_4_Text7 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = B_4_Text7\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (B_text5_Text8 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = B_text5_Text8\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (B_text5_Text9 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = B_text5_Text9\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (Bbd_4_Kab t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Bbd_4_Kab\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''isoiec_9798_2_6_enc_3_2'', LN ''Rb'' tid0,\n               s(MV ''Kab'' tid0), s(AV ''Abd'' tid0), s(AV ''Bbd'' tid0),\n               s(MV ''Text3'' tid0)\n            |}\n            ( Kbd ( s(AV ''Bbd'' tid0) ) ( s(MV ''Pbd'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (Bbd_4_Pbd t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Bbd_4_Pbd\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (Bbd_4_Rpa t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Bbd_4_Rpa\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''isoiec_9798_2_6_enc_4'', s(MV ''Rpa'' tid0), LN ''Rb'' tid0,\n               s(MV ''Text6'' tid0)\n            |}\n            ( s(MV ''Kab'' tid0) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (Bbd_4_Text3 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Bbd_4_Text3\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''isoiec_9798_2_6_enc_3_2'', LN ''Rb'' tid0,\n               s(MV ''Kab'' tid0), s(AV ''Abd'' tid0), s(AV ''Bbd'' tid0),\n               s(MV ''Text3'' tid0)\n            |}\n            ( Kbd ( s(AV ''Bbd'' tid0) ) ( s(MV ''Pbd'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (Bbd_4_Text6 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Bbd_4_Text6\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''isoiec_9798_2_6_enc_4'', s(MV ''Rpa'' tid0), LN ''Rb'' tid0,\n               s(MV ''Text6'' tid0)\n            |}\n            ( s(MV ''Kab'' tid0) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (Bbd_4_Text7 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Bbd_4_Text7\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (Bbd_text5_Text8 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Bbd_text5_Text8\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (Bbd_text5_Text9 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Bbd_text5_Text9\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (P_2_A t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = P_2_A\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (P_2_B t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = P_2_B\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (P_2_Ra t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = P_2_Ra\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (P_2_Rb t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = P_2_Rb\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (P_2_Text2 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = P_2_Text2\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (P_text3_Text3 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = P_text3_Text3\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (P_text3_Text4 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = P_text3_Text4\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (P_text3_Text5 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = P_text3_Text5\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (Pbd_2_Abd t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Pbd_2_Abd\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (Pbd_2_Bbd t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Pbd_2_Bbd\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (Pbd_2_Ra t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Pbd_2_Ra\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (Pbd_2_Rb t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Pbd_2_Rb\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (Pbd_2_Text2 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Pbd_2_Text2\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (Pbd_text3_Text3 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Pbd_text3_Text3\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (Pbd_text3_Text4 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Pbd_text3_Text4\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (Pbd_text3_Text5 t r s tid0)\n    then interpret state: typing_2_6_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = Pbd_text3_Text5\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  qed\n  thus \"typing_2_6_state t r s\" by unfold_locales auto\nqed\n\ntext{* Prove secrecy of long-term keys. *}\ncontext isoiec_9798_2_6_state begin\n\n  (* This rule is unsafe in general, but OK here, \n     as we are only reasoning about static compromise. \n  *)\n  lemma static_longterm_key_reveal[dest!]:\n    \"predOrd t (LKR a) e ==> RLKR a : reveals t\"\n    by (auto intro: compr_predOrdI)\n\n  lemma longterm_private_key_secrecy:\n    assumes facts:\n      \"SK m : knows t\"\n      \"RLKR m ~: reveals t\"\n    shows \"False\"\n  using facts by (sources \"SK m\")\n\n  lemma longterm_sym_ud_key_secrecy:\n    assumes facts:\n      \"K m1 m2 : knows t\"\n      \"RLKR m1 ~: reveals t\"\n      \"RLKR m2 ~: reveals t\"\n    shows \"False\"\n  using facts by (sources \"K m1 m2\")\n\n  lemma longterm_sym_bd_key_secrecy:\n    assumes facts:\n      \"Kbd m1 m2 : knows t\"\n      \"RLKR m1 ~: reveals t\"\n      \"RLKR m2 ~: reveals t\"\n      \"m1 : Agent\"\n      \"m2 : Agent\"\n    shows \"False\"\n  proof -\n    from facts \n    have \"KShr (agents {m1, m2}) : knows t\"\n      by (auto simp: Kbd_def)\n    thus ?thesis using facts\n    proof (sources \"KShr (agents {m1, m2})\")\n    qed (auto simp: agents_def Agent_def)\n  qed\n\n  lemmas ltk_secrecy =\n    longterm_sym_ud_key_secrecy\n    longterm_sym_ud_key_secrecy[OF in_knows_predOrd1]\n    longterm_sym_bd_key_secrecy\n    longterm_sym_bd_key_secrecy[OF in_knows_predOrd1]\n    longterm_private_key_secrecy\n    longterm_private_key_secrecy[OF in_knows_predOrd1]\n\nend\n\nend", "meta": {"author": "meiersi", "repo": "scyther-proof", "sha": "84e42366a46f66f1b090651be3bfaa3497696280", "save_path": "github-repos/isabelle/meiersi-scyther-proof", "path": "github-repos/isabelle/meiersi-scyther-proof/scyther-proof-84e42366a46f66f1b090651be3bfaa3497696280/examples/iso9798/isabelle-proofs/isoiec-9798_cert_auto.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5774953797290153, "lm_q2_score": 0.5117166047041652, "lm_q1q2_score": 0.2955139749472743}}
{"text": "(* Title: Misc_CryptHOL.thy\n  Author: Andreas Lochbihler, ETH Zurich *)\n\nsection \\<open>Miscellaneous library additions\\<close>\n\ntheory Misc_CryptHOL imports \n  Probabilistic_While.While_SPMF\n  \"HOL-Library.Rewrite\"\n  \"HOL-Library.Simps_Case_Conv\"\n  \"HOL-Library.Type_Length\"\n  \"HOL-Eisbach.Eisbach\"\n  Coinductive.TLList\n  Monad_Normalisation.Monad_Normalisation\n  Monomorphic_Monad.Monomorphic_Monad\n  Applicative_Lifting.Applicative\nbegin\n\nhide_const (open) Henstock_Kurzweil_Integration.negligible\n\ndeclare eq_on_def [simp del]\n\nsubsection \\<open>HOL\\<close>\n\nlemma asm_rl_conv: \"(PROP P \\<Longrightarrow> PROP P) \\<equiv> Trueprop True\"\nby(rule equal_intr_rule) iprover+\n\nnamed_theorems if_distribs \"Distributivity theorems for If\"\n\nlemma if_mono_cong: \"\\<lbrakk>b \\<Longrightarrow> x \\<le> x'; \\<not> b \\<Longrightarrow> y \\<le> y' \\<rbrakk> \\<Longrightarrow> If b x y \\<le> If b x' y'\"\nby simp\n\n\n\nlemma if_False_eq: \"\\<lbrakk> b \\<Longrightarrow> False; e = e' \\<rbrakk> \\<Longrightarrow> If b t e = e'\"\nby auto\n\nlemma imp_OO_imp [simp]: \"(\\<longrightarrow>) OO (\\<longrightarrow>) = (\\<longrightarrow>)\"\nby auto\n\nlemma inj_on_fun_updD: \"\\<lbrakk> inj_on (f(x := y)) A; x \\<notin> A \\<rbrakk> \\<Longrightarrow> inj_on f A\"\nby(auto simp add: inj_on_def split: if_split_asm)\n\nlemma disjoint_notin1: \"\\<lbrakk> A \\<inter> B = {}; x \\<in> B \\<rbrakk> \\<Longrightarrow> x \\<notin> A\" by auto\n\nlemma Least_le_Least:\n  fixes x :: \"'a :: wellorder\"\n  assumes \"Q x\"\n  and Q: \"\\<And>x. Q x \\<Longrightarrow> \\<exists>y\\<le>x. P y\"\n  shows \"Least P \\<le> Least Q\"\nproof -\n  obtain f :: \"'a \\<Rightarrow> 'a\" where \"\\<forall>a. \\<not> Q a \\<or> f a \\<le> a \\<and> P (f a)\" using Q by moura\n  moreover have \"Q (Least Q)\" using \\<open>Q x\\<close> by(rule LeastI)\n  ultimately show ?thesis by (metis (full_types) le_cases le_less less_le_trans not_less_Least)\nqed\n\nlemma is_empty_image [simp]: \"Set.is_empty (f ` A) = Set.is_empty A\"\n  by(auto simp add: Set.is_empty_def)\n\nsubsection \\<open>Relations\\<close>\n\ninductive Imagep :: \"('a \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow> ('a \\<Rightarrow> bool) \\<Rightarrow> 'b \\<Rightarrow> bool\"\n  for R P\nwhere ImagepI: \"\\<lbrakk> P x; R x y \\<rbrakk> \\<Longrightarrow> Imagep R P y\"\n\nlemma r_r_into_tranclp: \"\\<lbrakk> r x y; r y z \\<rbrakk> \\<Longrightarrow> r^++ x z\"\nby(rule tranclp.trancl_into_trancl)(rule tranclp.r_into_trancl)\n\nlemma transp_tranclp_id:\n  assumes \"transp R\"\n  shows \"tranclp R = R\"\nproof(intro ext iffI)\n  fix x y\n  assume \"R^++ x y\"\n  thus \"R x y\" by induction(blast dest: transpD[OF assms])+\nqed simp\n\nlemma transp_inv_image: \"transp r \\<Longrightarrow> transp (\\<lambda>x y. r (f x) (f y))\"\nusing trans_inv_image[where r=\"{(x, y). r x y}\" and f = f]\nby(simp add: transp_trans inv_image_def)\n\nlemma Domainp_conversep: \"Domainp R\\<inverse>\\<inverse> = Rangep R\"\nby(auto)\n\nlemma bi_unique_rel_set_bij_betw:\n  assumes unique: \"bi_unique R\"\n  and rel: \"rel_set R A B\"\n  shows \"\\<exists>f. bij_betw f A B \\<and> (\\<forall>x\\<in>A. R x (f x))\"\nproof -\n  from assms obtain f where f: \"\\<And>x. x \\<in> A \\<Longrightarrow> R x (f x)\" and B: \"\\<And>x. x \\<in> A \\<Longrightarrow> f x \\<in> B\"\n    apply(atomize_elim)\n    apply(fold all_conj_distrib)\n    apply(subst choice_iff[symmetric])\n    apply(auto dest: rel_setD1)\n    done\n  have \"inj_on f A\" by(rule inj_onI)(auto dest!: f dest: bi_uniqueDl[OF unique])\n  moreover have \"f ` A = B\" using rel\n    by(auto 4 3 intro: B dest: rel_setD2 f bi_uniqueDr[OF unique])\n  ultimately have \"bij_betw f A B\" unfolding bij_betw_def ..\n  thus ?thesis using f by blast\nqed\n\ndefinition restrict_relp :: \"('a \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow> ('a \\<Rightarrow> bool) \\<Rightarrow> ('b \\<Rightarrow> bool) \\<Rightarrow> 'a \\<Rightarrow> 'b \\<Rightarrow> bool\"\n  (\"_ \\<upharpoonleft> (_ \\<otimes> _)\" [53, 54, 54] 53)\nwhere \"restrict_relp R P Q = (\\<lambda>x y. R x y \\<and> P x \\<and> Q y)\"\n\nlemma restrict_relp_apply [simp]: \"(R \\<upharpoonleft> P \\<otimes> Q) x y \\<longleftrightarrow> R x y \\<and> P x \\<and> Q y\"\nby(simp add: restrict_relp_def)\n\nlemma restrict_relpI [intro?]: \"\\<lbrakk> R x y; P x; Q y \\<rbrakk> \\<Longrightarrow> (R \\<upharpoonleft> P \\<otimes> Q) x y\"\nby(simp add: restrict_relp_def)\n\nlemma restrict_relpE [elim?, cases pred]:\n  assumes \"(R \\<upharpoonleft> P \\<otimes> Q) x y\"\n  obtains (restrict_relp) \"R x y\" \"P x\" \"Q y\"\nusing assms by(simp add: restrict_relp_def)\n\nlemma conversep_restrict_relp [simp]: \"(R \\<upharpoonleft> P \\<otimes> Q)\\<inverse>\\<inverse> = R\\<inverse>\\<inverse> \\<upharpoonleft> Q \\<otimes> P\"\nby(auto simp add: fun_eq_iff)\n\nlemma restrict_relp_restrict_relp [simp]: \"R \\<upharpoonleft> P \\<otimes> Q \\<upharpoonleft> P' \\<otimes> Q' = R \\<upharpoonleft> inf P P' \\<otimes> inf Q Q'\"\nby(auto simp add: fun_eq_iff)\n\nlemma restrict_relp_cong:\n  \"\\<lbrakk> P = P'; Q = Q'; \\<And>x y. \\<lbrakk> P x; Q y \\<rbrakk> \\<Longrightarrow> R x y = R' x y \\<rbrakk> \\<Longrightarrow> R \\<upharpoonleft> P \\<otimes> Q = R' \\<upharpoonleft> P' \\<otimes> Q'\"\nby(auto simp add: fun_eq_iff)\n\nlemma restrict_relp_cong_simp:\n  \"\\<lbrakk> P = P'; Q = Q'; \\<And>x y. P x =simp=> Q y =simp=> R x y = R' x y \\<rbrakk> \\<Longrightarrow> R \\<upharpoonleft> P \\<otimes> Q = R' \\<upharpoonleft> P' \\<otimes> Q'\"\nby(rule restrict_relp_cong; simp add: simp_implies_def)\n\nlemma restrict_relp_parametric [transfer_rule]:\n  includes lifting_syntax shows\n  \"((A ===> B ===> (=)) ===> (A ===> (=)) ===> (B ===> (=)) ===> A ===> B ===> (=)) restrict_relp restrict_relp\"\nunfolding restrict_relp_def[abs_def] by transfer_prover\n\nlemma restrict_relp_mono: \"\\<lbrakk> R \\<le> R'; P \\<le> P'; Q \\<le> Q' \\<rbrakk> \\<Longrightarrow> R \\<upharpoonleft> P \\<otimes> Q \\<le> R' \\<upharpoonleft> P' \\<otimes> Q'\"\nby(simp add: le_fun_def)\n\nlemma restrict_relp_mono': \n  \"\\<lbrakk> (R \\<upharpoonleft> P \\<otimes> Q) x y; \\<lbrakk> R x y; P x; Q y \\<rbrakk> \\<Longrightarrow> R' x y &&& P' x &&& Q' y \\<rbrakk>\n  \\<Longrightarrow> (R' \\<upharpoonleft> P' \\<otimes> Q') x y\"\nby(auto dest: conjunctionD1 conjunctionD2)\n\nlemma restrict_relp_DomainpD: \"Domainp (R \\<upharpoonleft> P \\<otimes> Q) x \\<Longrightarrow> Domainp R x \\<and> P x\"\nby(auto simp add: Domainp.simps)\n\nlemma restrict_relp_True: \"R \\<upharpoonleft> (\\<lambda>_. True) \\<otimes> (\\<lambda>_. True) = R\"\nby(simp add: fun_eq_iff)\n\nlemma restrict_relp_False1: \"R \\<upharpoonleft> (\\<lambda>_. False) \\<otimes> Q = bot\"\nby(simp add: fun_eq_iff)\n\nlemma restrict_relp_False2: \"R \\<upharpoonleft> P \\<otimes> (\\<lambda>_. False) = bot\"\nby(simp add: fun_eq_iff)\n\ndefinition rel_prod2 :: \"('a \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow> 'a \\<Rightarrow> ('c \\<times> 'b) \\<Rightarrow> bool\"\nwhere \"rel_prod2 R a = (\\<lambda>(c, b). R a b)\"\n\nlemma rel_prod2_simps [simp]: \"rel_prod2 R a (c, b) \\<longleftrightarrow> R a b\"\nby(simp add: rel_prod2_def)\n\nlemma restrict_rel_prod:\n  \"rel_prod (R \\<upharpoonleft> I1 \\<otimes> I2) (S \\<upharpoonleft> I1' \\<otimes> I2') = rel_prod R S \\<upharpoonleft> pred_prod I1 I1' \\<otimes> pred_prod I2 I2'\"\nby(auto simp add: fun_eq_iff)\n\nlemma restrict_rel_prod1:\n  \"rel_prod (R \\<upharpoonleft> I1 \\<otimes> I2) S = rel_prod R S \\<upharpoonleft> pred_prod I1 (\\<lambda>_. True) \\<otimes> pred_prod I2 (\\<lambda>_. True)\"\nby(simp add: restrict_rel_prod[symmetric] restrict_relp_True)\n\nlemma restrict_rel_prod2:\n  \"rel_prod R (S \\<upharpoonleft> I1 \\<otimes> I2) = rel_prod R S \\<upharpoonleft> pred_prod (\\<lambda>_. True) I1 \\<otimes> pred_prod (\\<lambda>_. True) I2\"\nby(simp add: restrict_rel_prod[symmetric] restrict_relp_True)\n\nconsts relcompp_witness :: \"('a \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow> ('b \\<Rightarrow> 'c \\<Rightarrow> bool) \\<Rightarrow> 'a \\<times> 'c \\<Rightarrow> 'b\"\nspecification (relcompp_witness)\n  relcompp_witness1: \"(A OO B) (fst xy) (snd xy) \\<Longrightarrow> A (fst xy) (relcompp_witness A B xy)\"\n  relcompp_witness2: \"(A OO B) (fst xy) (snd xy) \\<Longrightarrow> B (relcompp_witness A B xy) (snd xy)\"\n  apply(fold all_conj_distrib)\n  apply(rule choice allI)+\n  by(auto intro: choice allI)\n\nlemmas relcompp_witness[of _ _ \"(x, y)\" for x y, simplified] = relcompp_witness1 relcompp_witness2\n\nhide_fact (open) relcompp_witness1 relcompp_witness2\n\nlemma relcompp_witness_eq [simp]: \"relcompp_witness (=) (=) (x, x) = x\"\n  using relcompp_witness(1)[of \"(=)\" \"(=)\" x x] by(simp add: eq_OO)\n\nsubsection \\<open>Pairs\\<close>\n\nlemma split_apfst [simp]: \"case_prod h (apfst f xy) = case_prod (h \\<circ> f) xy\"\nby(cases xy) simp\n\ndefinition corec_prod :: \"('s \\<Rightarrow> 'a) \\<Rightarrow> ('s \\<Rightarrow> 'b) \\<Rightarrow> 's \\<Rightarrow> 'a \\<times> 'b\"\nwhere \"corec_prod f g = (\\<lambda>s. (f s, g s))\"\n\nlemma corec_prod_apply: \"corec_prod f g s = (f s, g s)\"\nby(simp add: corec_prod_def)\n\nlemma corec_prod_sel [simp]:\n  shows fst_corec_prod: \"fst (corec_prod f g s) = f s\"\n  and snd_corec_prod: \"snd (corec_prod f g s) = g s\"\nby(simp_all add: corec_prod_apply)\n\nlemma apfst_corec_prod [simp]: \"apfst h (corec_prod f g s) = corec_prod (h \\<circ> f) g s\"\nby(simp add: corec_prod_apply)\n\nlemma apsnd_corec_prod [simp]: \"apsnd h (corec_prod f g s) = corec_prod f (h \\<circ> g) s\"\nby(simp add: corec_prod_apply)\n\nlemma map_corec_prod [simp]: \"map_prod f g (corec_prod h k s) = corec_prod (f \\<circ> h) (g \\<circ> k) s\"\nby(simp add: corec_prod_apply)\n\nlemma split_corec_prod [simp]: \"case_prod h (corec_prod f g s) = h (f s) (g s)\"\nby(simp add: corec_prod_apply)\n\nlemma Pair_fst_Unity: \"(fst x, ()) = x\"\n  by(cases x) simp\n\ndefinition rprodl :: \"('a \\<times> 'b) \\<times> 'c \\<Rightarrow> 'a \\<times> ('b \\<times> 'c)\" where \"rprodl = (\\<lambda>((a, b), c). (a, (b, c)))\"\n\nlemma rprodl_simps [simp]: \"rprodl ((a, b), c) = (a, (b, c))\"\n  by(simp add: rprodl_def)\n\nlemma rprodl_parametric [transfer_rule]: includes lifting_syntax shows\n  \"(rel_prod (rel_prod A B) C ===> rel_prod A (rel_prod B C)) rprodl rprodl\"\n  unfolding rprodl_def by transfer_prover\n\ndefinition lprodr :: \"'a \\<times> ('b \\<times> 'c) \\<Rightarrow> ('a \\<times> 'b) \\<times> 'c\" where \"lprodr = (\\<lambda>(a, b, c). ((a, b), c))\"\n\nlemma lprodr_simps [simp]: \"lprodr (a, b, c) = ((a, b), c)\"\n  by(simp add: lprodr_def)\n\nlemma lprodr_parametric [transfer_rule]: includes lifting_syntax shows\n  \"(rel_prod A (rel_prod B C) ===> rel_prod (rel_prod A B) C) lprodr lprodr\"\n  unfolding lprodr_def by transfer_prover\n\nlemma lprodr_inverse [simp]: \"rprodl (lprodr x) = x\"\n  by(cases x) auto\n\nlemma rprodl_inverse [simp]: \"lprodr (rprodl x) = x\"\n  by(cases x) auto\n\nlemma pred_prod_mono' [mono]:\n  \"pred_prod A B xy \\<longrightarrow> pred_prod A' B' xy\"\n  if \"\\<And>x. A x \\<longrightarrow> A' x\" \"\\<And>y. B y \\<longrightarrow> B' y\"\n  using that by(cases xy) auto\n\nfun rel_witness_prod :: \"('a \\<times> 'b) \\<times> ('c \\<times> 'd) \\<Rightarrow> (('a \\<times> 'c) \\<times> ('b \\<times> 'd))\" where\n  \"rel_witness_prod ((a, b), (c, d)) = ((a, c), (b, d))\"\n\nsubsection \\<open>Sums\\<close>\n\nlemma islE:\n  assumes \"isl x\"\n  obtains l where \"x = Inl l\"\nusing assms by(cases x) auto\n\nlemma Inl_in_Plus [simp]: \"Inl x \\<in> A <+> B \\<longleftrightarrow> x \\<in> A\"\nby auto\n\nlemma Inr_in_Plus [simp]: \"Inr x \\<in> A <+> B \\<longleftrightarrow> x \\<in> B\"\nby auto\n\nlemma Inl_eq_map_sum_iff: \"Inl x = map_sum f g y \\<longleftrightarrow> (\\<exists>z. y = Inl z \\<and> x = f z)\"\nby(cases y) auto\n\nlemma Inr_eq_map_sum_iff: \"Inr x = map_sum f g y \\<longleftrightarrow> (\\<exists>z. y = Inr z \\<and> x = g z)\"\nby(cases y) auto\n\nlemma inj_on_map_sum [simp]:\n  \"\\<lbrakk> inj_on f A; inj_on g B \\<rbrakk> \\<Longrightarrow> inj_on (map_sum f g) (A <+> B)\"\nproof(rule inj_onI, goal_cases)\n  case (1 x y)\n  then show ?case by(cases x; cases y; auto simp add: inj_on_def)\nqed\n\nlemma inv_into_map_sum:\n  \"inv_into (A <+> B) (map_sum f g) x = map_sum (inv_into A f) (inv_into B g) x\"\n  if \"x \\<in> f ` A <+> g ` B\" \"inj_on f A\" \"inj_on g B\"\n  using that by(cases rule: PlusE[consumes 1])(auto simp add: inv_into_f_eq f_inv_into_f)\n\nfun rsuml :: \"('a + 'b) + 'c \\<Rightarrow> 'a + ('b + 'c)\" where\n  \"rsuml (Inl (Inl a)) = Inl a\"\n| \"rsuml (Inl (Inr b)) = Inr (Inl b)\"\n| \"rsuml (Inr c) = Inr (Inr c)\"\n\nfun lsumr :: \"'a + ('b + 'c) \\<Rightarrow> ('a + 'b) + 'c\" where\n  \"lsumr (Inl a) = Inl (Inl a)\"\n| \"lsumr (Inr (Inl b)) = Inl (Inr b)\"\n| \"lsumr (Inr (Inr c)) = Inr c\"\n\nlemma rsuml_lsumr [simp]: \"rsuml (lsumr x) = x\"\n  by(cases x rule: lsumr.cases) simp_all\n\nlemma lsumr_rsuml [simp]: \"lsumr (rsuml x) = x\"\n  by(cases x rule: rsuml.cases) simp_all\n\nsubsection \\<open>Option\\<close>\n\ndeclare is_none_bind [simp]\n\nlemma case_option_collapse: \"case_option x (\\<lambda>_. x) y = x\"\nby(simp split: option.split)\n\nlemma indicator_single_Some: \"indicator {Some x} (Some y) = indicator {x} y\"\nby(simp split: split_indicator)\n\nsubsubsection \\<open>Predicator and relator\\<close>\n\nlemma option_pred_mono_strong:\n  \"\\<lbrakk> pred_option P x; \\<And>a. \\<lbrakk> a \\<in> set_option x; P a \\<rbrakk> \\<Longrightarrow> P' a \\<rbrakk> \\<Longrightarrow> pred_option P' x\"\nby(fact option.pred_mono_strong)\n\nlemma option_pred_map [simp]: \"pred_option P (map_option f x) = pred_option (P \\<circ> f) x\"\nby(fact option.pred_map)\n\nlemma option_pred_o_map [simp]: \"pred_option P \\<circ> map_option f = pred_option (P \\<circ> f)\"\nby(simp add: fun_eq_iff)\n\nlemma option_pred_bind [simp]: \"pred_option P (Option.bind x f) = pred_option (pred_option P \\<circ> f) x\"\nby(simp add: pred_option_def)\n\nlemma pred_option_conj [simp]:\n  \"pred_option (\\<lambda>x. P x \\<and> Q x) = (\\<lambda>x. pred_option P x \\<and> pred_option Q x)\"\nby(auto simp add: pred_option_def)\n\nlemma pred_option_top [simp]:\n  \"pred_option (\\<lambda>_. True) = (\\<lambda>_. True)\"\nby(fact option.pred_True)\n\nlemma rel_option_restrict_relpI [intro?]:\n  \"\\<lbrakk> rel_option R x y; pred_option P x; pred_option Q y \\<rbrakk> \\<Longrightarrow> rel_option (R \\<upharpoonleft> P \\<otimes> Q) x y\"\nby(erule option.rel_mono_strong) simp\n\nlemma rel_option_restrict_relpE [elim?]:\n  assumes \"rel_option (R \\<upharpoonleft> P \\<otimes> Q) x y\"\n  obtains \"rel_option R x y\" \"pred_option P x\" \"pred_option Q y\"\nproof\n  show \"rel_option R x y\" using assms by(auto elim!: option.rel_mono_strong)\n  have \"pred_option (Domainp (R \\<upharpoonleft> P \\<otimes> Q)) x\" using assms by(fold option.Domainp_rel) blast\n  then show \"pred_option P x\" by(rule option_pred_mono_strong)(blast dest!: restrict_relp_DomainpD)\n  have \"pred_option (Domainp (R \\<upharpoonleft> P \\<otimes> Q)\\<inverse>\\<inverse>) y\" using assms\n    by(fold option.Domainp_rel)(auto simp only: option.rel_conversep Domainp_conversep)\n  then show \"pred_option Q y\" by(rule option_pred_mono_strong)(auto dest!: restrict_relp_DomainpD)\nqed\n\nlemma rel_option_restrict_relp_iff:\n  \"rel_option (R \\<upharpoonleft> P \\<otimes> Q) x y \\<longleftrightarrow> rel_option R x y \\<and> pred_option P x \\<and> pred_option Q y\"\nby(blast intro: rel_option_restrict_relpI elim: rel_option_restrict_relpE)\n\nlemma option_rel_map_restrict_relp:\n  shows option_rel_map_restrict_relp1:\n  \"rel_option (R \\<upharpoonleft> P \\<otimes> Q) (map_option f x) = rel_option (R \\<circ> f \\<upharpoonleft> P \\<circ> f \\<otimes> Q) x\"\n  and option_rel_map_restrict_relp2:\n  \"rel_option (R \\<upharpoonleft> P \\<otimes> Q) x (map_option g y) = rel_option ((\\<lambda>x. R x \\<circ> g) \\<upharpoonleft> P \\<otimes> Q \\<circ> g) x y\"\nby(simp_all add: option.rel_map restrict_relp_def fun_eq_iff)\n\nfun rel_witness_option :: \"'a option \\<times> 'b option \\<Rightarrow> ('a \\<times> 'b) option\" where\n  \"rel_witness_option (Some x, Some y) = Some (x, y)\"\n| \"rel_witness_option (None, None) = None\"\n| \"rel_witness_option _ = None\" \\<comment> \\<open>Just to make the definition complete\\<close>\n\nlemma rel_witness_option:\n  shows set_rel_witness_option: \"\\<lbrakk> rel_option A x y; (a, b) \\<in> set_option (rel_witness_option (x, y)) \\<rbrakk> \\<Longrightarrow> A a b\"\n    and map1_rel_witness_option: \"rel_option A x y \\<Longrightarrow> map_option fst (rel_witness_option (x, y)) = x\"\n    and map2_rel_witness_option: \"rel_option A x y \\<Longrightarrow> map_option snd (rel_witness_option (x, y)) = y\"\n  by(cases \"(x, y)\" rule: rel_witness_option.cases; simp; fail)+\n\nlemma rel_witness_option1:\n  assumes \"rel_option A x y\"\n  shows \"rel_option (\\<lambda>a (a', b). a = a' \\<and> A a' b) x (rel_witness_option (x, y))\"\n  using map1_rel_witness_option[OF assms, symmetric]\n  unfolding option.rel_eq[symmetric] option.rel_map\n  by(rule option.rel_mono_strong)(auto intro: set_rel_witness_option[OF assms])\n\nlemma rel_witness_option2:\n  assumes \"rel_option A x y\"\n  shows \"rel_option (\\<lambda>(a, b') b. b = b' \\<and> A a b') (rel_witness_option (x, y)) y\"\n  using map2_rel_witness_option[OF assms]\n  unfolding option.rel_eq[symmetric] option.rel_map\n  by(rule option.rel_mono_strong)(auto intro: set_rel_witness_option[OF assms])\n\nsubsubsection \\<open>Orders on option\\<close>\n\nabbreviation le_option :: \"'a option \\<Rightarrow> 'a option \\<Rightarrow> bool\"\nwhere \"le_option \\<equiv> ord_option (=)\"\n\nlemma le_option_bind_mono:\n  \"\\<lbrakk> le_option x y; \\<And>a. a \\<in> set_option x \\<Longrightarrow> le_option (f a) (g a) \\<rbrakk>\n  \\<Longrightarrow> le_option (Option.bind x f) (Option.bind y g)\"\nby(cases x) simp_all\n\nlemma le_option_refl [simp]: \"le_option x x\"\nby(cases x) simp_all\n\n\nlemma le_option_conv_option_ord: \"le_option = option_ord\"\nby(auto simp add: fun_eq_iff flat_ord_def elim: ord_option.cases)\n\ndefinition pcr_Some :: \"('a \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow> 'a \\<Rightarrow> 'b option \\<Rightarrow> bool\"\nwhere \"pcr_Some R x y \\<longleftrightarrow> (\\<exists>z. y = Some z \\<and> R x z)\"\n\nlemma pcr_Some_simps [simp]: \"pcr_Some R x (Some y) \\<longleftrightarrow> R x y\"\nby(simp add: pcr_Some_def)\n\nlemma pcr_SomeE [cases pred]:\n  assumes \"pcr_Some R x y\"\n  obtains (pcr_Some) z where \"y = Some z\" \"R x z\"\nusing assms by(auto simp add: pcr_Some_def)\n\nsubsubsection \\<open>Filter for option\\<close>\n\nfun filter_option :: \"('a \\<Rightarrow> bool) \\<Rightarrow> 'a option \\<Rightarrow> 'a option\"\nwhere\n  \"filter_option P None = None\"\n| \"filter_option P (Some x) = (if P x then Some x else None)\"\n\nlemma set_filter_option [simp]: \"set_option (filter_option P x) = {y \\<in> set_option x. P y}\"\nby(cases x) auto\n\nlemma filter_map_option: \"filter_option P (map_option f x) = map_option f (filter_option (P \\<circ> f) x)\"\nby(cases x) simp_all\n\nlemma is_none_filter_option [simp]: \"Option.is_none (filter_option P x) \\<longleftrightarrow> Option.is_none x \\<or> \\<not> P (the x)\"\nby(cases x) simp_all\n\nlemma filter_option_eq_Some_iff [simp]: \"filter_option P x = Some y \\<longleftrightarrow> x = Some y \\<and> P y\"\nby(cases x) auto\n\nlemma Some_eq_filter_option_iff [simp]: \"Some y = filter_option P x \\<longleftrightarrow> x = Some y \\<and> P y\"\nby(cases x) auto\n\nlemma filter_conv_bind_option: \"filter_option P x = Option.bind x (\\<lambda>y. if P y then Some y else None)\"\nby(cases x) simp_all\n\nsubsubsection \\<open>Assert for option\\<close>\n\nprimrec assert_option :: \"bool \\<Rightarrow> unit option\" where\n  \"assert_option True = Some ()\"\n| \"assert_option False = None\"\n\nlemma set_assert_option_conv: \"set_option (assert_option b) = (if b then {()} else {})\"\nby(simp)\n\nlemma in_set_assert_option [simp]: \"x \\<in> set_option (assert_option b) \\<longleftrightarrow> b\"\nby(cases b) simp_all\n\n\nsubsubsection \\<open>Join on options\\<close>\n\ndefinition join_option :: \"'a option option \\<Rightarrow> 'a option\"\nwhere \"join_option x = (case x of Some y \\<Rightarrow> y | None \\<Rightarrow> None)\"\n\nsimps_of_case join_simps [simp, code]: join_option_def\n\nlemma set_join_option [simp]: \"set_option (join_option x) = \\<Union>(set_option ` set_option x)\"\nby(cases x)(simp_all)\n\nlemma in_set_join_option: \"x \\<in> set_option (join_option (Some (Some x)))\"\nby simp\n\nlemma map_join_option: \"map_option f (join_option x) = join_option (map_option (map_option f) x)\"\nby(cases x) simp_all\n\nlemma bind_conv_join_option: \"Option.bind x f = join_option (map_option f x)\"\nby(cases x) simp_all\n\nlemma join_conv_bind_option: \"join_option x = Option.bind x id\"\nby(cases x) simp_all\n\nlemma join_option_parametric [transfer_rule]:\n  includes lifting_syntax shows\n  \"(rel_option (rel_option R) ===> rel_option R) join_option join_option\"\nunfolding join_conv_bind_option[abs_def] by transfer_prover\n\nlemma join_option_eq_Some [simp]: \"join_option x = Some y \\<longleftrightarrow> x = Some (Some y)\"\nby(cases x) simp_all\n\nlemma Some_eq_join_option [simp]: \"Some y = join_option x \\<longleftrightarrow> x = Some (Some y)\"\nby(cases x) auto\n\nlemma join_option_eq_None: \"join_option x = None \\<longleftrightarrow> x = None \\<or> x = Some None\"\nby(cases x) simp_all\n\nlemma None_eq_join_option: \"None = join_option x \\<longleftrightarrow> x = None \\<or> x = Some None\"\nby(cases x) auto\n\nsubsubsection \\<open>Zip on options\\<close>\n\nfunction zip_option :: \"'a option \\<Rightarrow> 'b option \\<Rightarrow> ('a \\<times> 'b) option\"\nwhere\n  \"zip_option (Some x) (Some y) = Some (x, y)\"\n| \"zip_option _ None = None\"\n| \"zip_option None _ = None\"\nby pat_completeness auto\ntermination by lexicographic_order\n\nlemma zip_option_eq_Some_iff [iff]:\n  \"zip_option x y = Some (a, b) \\<longleftrightarrow> x = Some a \\<and> y = Some b\"\nby(cases \"(x, y)\" rule: zip_option.cases) simp_all\n\nlemma set_zip_option [simp]:\n  \"set_option (zip_option x y) = set_option x \\<times> set_option y\"\nby auto\n\nlemma zip_map_option1: \"zip_option (map_option f x) y = map_option (apfst f) (zip_option x y)\"\nby(cases \"(x, y)\" rule: zip_option.cases) simp_all\n\nlemma zip_map_option2: \"zip_option x (map_option g y) = map_option (apsnd g) (zip_option x y)\"\nby(cases \"(x, y)\" rule: zip_option.cases) simp_all\n\nlemma map_zip_option:\n  \"map_option (map_prod f g) (zip_option x y) = zip_option (map_option f x) (map_option g y)\"\nby(simp add: zip_map_option1 zip_map_option2 option.map_comp apfst_def apsnd_def o_def prod.map_comp)\n\nlemma zip_conv_bind_option:\n  \"zip_option x y = Option.bind x (\\<lambda>x. Option.bind y (\\<lambda>y. Some (x, y)))\"\nby(cases \"(x, y)\" rule: zip_option.cases) simp_all\n\nlemma zip_option_parametric [transfer_rule]:\n  includes lifting_syntax shows\n  \"(rel_option R ===> rel_option Q ===> rel_option (rel_prod R Q)) zip_option zip_option\"\nunfolding zip_conv_bind_option[abs_def] by transfer_prover\n\nlemma rel_option_eqI [simp]: \"rel_option (=) x x\"\nby(simp add: option.rel_eq)\n\nsubsubsection \\<open>Binary supremum on @{typ \"'a option\"}\\<close>\n\nprimrec sup_option :: \"'a option \\<Rightarrow> 'a option \\<Rightarrow> 'a option\"\nwhere\n  \"sup_option x None = x\"\n| \"sup_option x (Some y) = (Some y)\"\n\nlemma sup_option_idem [simp]: \"sup_option x x = x\"\nby(cases x) simp_all\n\nlemma sup_option_assoc: \"sup_option (sup_option x y) z = sup_option x (sup_option y z)\"\nby(cases z) simp_all\n\nlemma sup_option_left_idem: \"sup_option x (sup_option x y) = sup_option x y\"\nby(rewrite sup_option_assoc[symmetric])(simp)\n\nlemmas sup_option_ai = sup_option_assoc sup_option_left_idem\n\nlemma sup_option_None [simp]: \"sup_option None y = y\"\nby(cases y) simp_all\n\nsubsubsection \\<open>Restriction on @{typ \"'a option\"}\\<close>\n\nprimrec (transfer) enforce_option :: \"('a \\<Rightarrow> bool) \\<Rightarrow> 'a option \\<Rightarrow> 'a option\" where\n  \"enforce_option P (Some x) = (if P x then Some x else None)\"\n| \"enforce_option P None = None\"\n\nlemma set_enforce_option [simp]: \"set_option (enforce_option P x) = {a \\<in> set_option x. P a}\"\n  by(cases x) auto\n\nlemma enforce_map_option: \"enforce_option P (map_option f x) = map_option f (enforce_option (P \\<circ> f) x)\"\n  by(cases x) auto\n\nlemma enforce_bind_option [simp]:\n  \"enforce_option P (Option.bind x f) = Option.bind x (enforce_option P \\<circ> f)\"\n  by(cases x) auto\n\nlemma enforce_option_alt_def:\n  \"enforce_option P x = Option.bind x (\\<lambda>a. Option.bind (assert_option (P a)) (\\<lambda>_ :: unit. Some a))\"\n  by(cases x) simp_all\n\nlemma enforce_option_eq_None_iff [simp]:\n  \"enforce_option P x = None \\<longleftrightarrow> (\\<forall>a. x = Some a \\<longrightarrow> \\<not> P a)\"\n  by(cases x) auto\n\nlemma enforce_option_eq_Some_iff [simp]:\n  \"enforce_option P x = Some y \\<longleftrightarrow> x = Some y \\<and> P y\"\n  by(cases x) auto\n\nlemma Some_eq_enforce_option_iff [simp]:\n  \"Some y = enforce_option P x \\<longleftrightarrow> x = Some y \\<and> P y\"\n  by(cases x) auto\n\nlemma enforce_option_top [simp]: \"enforce_option \\<top> = id\"\n  by(rule ext; rename_tac x; case_tac x; simp)\n\nlemma enforce_option_K_True [simp]: \"enforce_option (\\<lambda>_. True) x = x\"\n  by(cases x) simp_all\n\nlemma enforce_option_bot [simp]: \"enforce_option \\<bottom> = (\\<lambda>_. None)\"\n  by(simp add: fun_eq_iff)\n\nlemma enforce_option_K_False [simp]: \"enforce_option (\\<lambda>_. False) x = None\"\n  by simp\n\nlemma enforce_pred_id_option: \"pred_option P x \\<Longrightarrow> enforce_option P x = x\"\n  by(cases x) auto\n\nsubsubsection \\<open>Maps\\<close>\n\nlemma map_add_apply: \"(m1 ++ m2) x = sup_option (m1 x) (m2 x)\"\nby(simp add: map_add_def split: option.split)\n\nlemma map_le_map_upd2: \"\\<lbrakk> f \\<subseteq>\\<^sub>m g; \\<And>y'. f x = Some y' \\<Longrightarrow> y' = y \\<rbrakk> \\<Longrightarrow> f \\<subseteq>\\<^sub>m g(x \\<mapsto> y)\"\nby(cases \"x \\<in> dom f\")(auto simp add: map_le_def Ball_def)\n\nlemma eq_None_iff_not_dom: \"f x = None \\<longleftrightarrow> x \\<notin> dom f\"\nby auto\n\nlemma card_ran_le_dom: \"finite (dom m) \\<Longrightarrow> card (ran m) \\<le> card (dom m)\"\nby(simp add: ran_alt_def card_image_le)\n\nlemma dom_subset_ran_iff:\n  assumes \"finite (ran m)\"\n  shows \"dom m \\<subseteq> ran m \\<longleftrightarrow> dom m = ran m\"\nproof\n  assume le: \"dom m \\<subseteq> ran m\"\n  then have \"card (dom m) \\<le> card (ran m)\" by(simp add: card_mono assms)\n  moreover have \"card (ran m) \\<le> card (dom m)\" by(simp add: finite_subset[OF le assms] card_ran_le_dom)\n  ultimately show \"dom m = ran m\" using card_subset_eq[OF assms le] by simp\nqed simp\n\ntext \\<open>\n  We need a polymorphic constant for the empty map such that \\<open>transfer_prover\\<close>\n  can use a custom transfer rule for @{const Map.empty}\n\\<close>\ndefinition Map_empty where [simp]: \"Map_empty \\<equiv> Map.empty\"\n\n\n\nlemma map_le_fun_upd2: \"\\<lbrakk> f \\<subseteq>\\<^sub>m g; x \\<notin> dom f \\<rbrakk> \\<Longrightarrow> f \\<subseteq>\\<^sub>m g(x := y)\"\nby(auto simp add: map_le_def)\n\nlemma map_eqI: \"\\<forall>x\\<in>dom m \\<union> dom m'. m x = m' x \\<Longrightarrow> m = m'\"\nby(auto simp add: fun_eq_iff domIff intro: option.expand)\n\n\nsubsection \\<open>Countable\\<close>\n\nlemma countable_lfp:\n  assumes step: \"\\<And>Y. countable Y \\<Longrightarrow> countable (F Y)\"\n  and cont: \"Order_Continuity.sup_continuous F\"\n  shows \"countable (lfp F)\"\nby(subst sup_continuous_lfp[OF cont])(simp add: countable_funpow[OF step])\n\nlemma countable_lfp_apply:\n  assumes step: \"\\<And>Y x. (\\<And>x. countable (Y x)) \\<Longrightarrow> countable (F Y x)\"\n  and cont: \"Order_Continuity.sup_continuous F\"\n  shows \"countable (lfp F x)\"\nproof -\n  { fix n\n    have \"\\<And>x. countable ((F ^^ n) bot x)\"\n      by(induct n)(auto intro: step) }\n  thus ?thesis using cont by(simp add: sup_continuous_lfp)\nqed\n\n\nsubsection \\<open> Extended naturals \\<close>\n\nlemma idiff_enat_eq_enat_iff: \"x - enat n = enat m \\<longleftrightarrow> (\\<exists>k. x = enat k \\<and> k - n = m)\"\n  by (cases x) simp_all\n\nlemma eSuc_SUP: \"A \\<noteq> {} \\<Longrightarrow> eSuc (\\<Squnion> (f ` A)) = (\\<Squnion>x\\<in>A. eSuc (f x))\"\n  by (subst eSuc_Sup) (simp_all add: image_comp)\n\nlemma ereal_of_enat_1: \"ereal_of_enat 1 = ereal 1\"\n  by (simp add: one_enat_def)\n\nlemma ennreal_real_conv_ennreal_of_enat: \"ennreal (real n) = ennreal_of_enat n\"\n  by (simp add: ennreal_of_nat_eq_real_of_nat)\n\nlemma enat_add_sub_same2: \"b \\<noteq> \\<infinity> \\<Longrightarrow> a + b - b = (a :: enat)\"\n  by (cases a; cases b) simp_all\n\nlemma enat_sub_add: \"y \\<le> x \\<Longrightarrow> x - y + z = x + z - (y :: enat)\"\n  by (cases x; cases y; cases z) simp_all\n\nlemma SUP_enat_eq_0_iff [simp]: \"\\<Squnion> (f ` A) = (0 :: enat) \\<longleftrightarrow> (\\<forall>x\\<in>A. f x = 0)\"\n  by (simp add: bot_enat_def [symmetric])\n\nlemma SUP_enat_add_left:\n  assumes \"I \\<noteq> {}\"\n  shows \"(SUP i\\<in>I. f i + c :: enat) = (SUP i\\<in>I. f i) + c\" (is \"?lhs = ?rhs\")\nproof(cases \"c\", rule antisym)\n  case (enat n)\n  show \"?lhs \\<le> ?rhs\" by(auto 4 3 intro: SUP_upper intro: SUP_least)\n  have \"(SUP i\\<in>I. f i) \\<le> ?lhs - c\" using enat \n    by(auto simp add: enat_add_sub_same2 intro!: SUP_least order_trans[OF _ SUP_upper[THEN enat_minus_mono1]])\n  note add_right_mono[OF this, of c]\n  also have \"\\<dots> + c \\<le> ?lhs\" using assms\n    by(subst enat_sub_add)(auto intro: SUP_upper2 simp add: enat_add_sub_same2 enat)\n  finally show \"?rhs \\<le> ?lhs\" .\nqed(simp add: assms SUP_constant)\n\nlemma SUP_enat_add_right:\n  assumes \"I \\<noteq> {}\"\n  shows \"(SUP i\\<in>I. c + f i :: enat) = c + (SUP i\\<in>I. f i)\"\nusing SUP_enat_add_left[OF assms, of f c]\nby(simp add: add.commute)\n\nlemma iadd_SUP_le_iff: \"n + (SUP x\\<in>A. f x :: enat) \\<le> y \\<longleftrightarrow> (if A = {} then n \\<le> y else \\<forall>x\\<in>A. n + f x \\<le> y)\"\nby(simp add: bot_enat_def SUP_enat_add_right[symmetric] SUP_le_iff)\n\nlemma SUP_iadd_le_iff: \"(SUP x\\<in>A. f x :: enat) + n \\<le> y \\<longleftrightarrow> (if A = {} then n \\<le> y else \\<forall>x\\<in>A. f x + n \\<le> y)\"\nusing iadd_SUP_le_iff[of n f A y] by(simp add: add.commute)\n\n\nsubsection \\<open>Extended non-negative reals\\<close>\n\nlemma (in finite_measure) nn_integral_indicator_neq_infty: \n  \"f -` A \\<in> sets M \\<Longrightarrow> (\\<integral>\\<^sup>+ x. indicator A (f x) \\<partial>M) \\<noteq> \\<infinity>\"\nunfolding ennreal_indicator[symmetric]\napply(rule integrableD)\napply(rule integrable_const_bound[where B=1])\napply(simp_all add: indicator_vimage[symmetric])\ndone\n\nlemma (in finite_measure) nn_integral_indicator_neq_top: \n  \"f -` A \\<in> sets M \\<Longrightarrow> (\\<integral>\\<^sup>+ x. indicator A (f x) \\<partial>M) \\<noteq> \\<top>\"\nby(drule nn_integral_indicator_neq_infty) simp\n\nlemma nn_integral_indicator_map:\n  assumes [measurable]: \"f \\<in> measurable M N\" \"{x\\<in>space N. P x} \\<in> sets N\"\n  shows \"(\\<integral>\\<^sup>+x. indicator {x\\<in>space N. P x} (f x) \\<partial>M) = emeasure M {x\\<in>space M. P (f x)}\"\n  using assms(1)[THEN measurable_space] \n  by (subst nn_integral_indicator[symmetric])\n     (auto intro!: nn_integral_cong split: split_indicator simp del: nn_integral_indicator)\n\n\nsubsection \\<open>BNF material\\<close>\n\nlemma transp_rel_fun: \"\\<lbrakk> is_equality Q; transp R \\<rbrakk> \\<Longrightarrow> transp (rel_fun Q R)\"\nby(rule transpI)(auto dest: transpD rel_funD simp add: is_equality_def)\n\nlemma rel_fun_inf: \"inf (rel_fun Q R) (rel_fun Q R') = rel_fun Q (inf R R')\"\nby(rule antisym)(auto elim: rel_fun_mono dest: rel_funD)\n\nlemma reflp_fun1: includes lifting_syntax shows \"\\<lbrakk> is_equality A; reflp B \\<rbrakk> \\<Longrightarrow> reflp (A ===> B)\"\nby(simp add: reflp_def rel_fun_def is_equality_def)\n\nlemma type_copy_id': \"type_definition (\\<lambda>x. x) (\\<lambda>x. x) UNIV\"\nby unfold_locales simp_all\n\nlemma type_copy_id: \"type_definition id id UNIV\"\nby(simp add: id_def type_copy_id')\n\nlemma GrpE [cases pred]:\n  assumes \"BNF_Def.Grp A f x y\"\n  obtains (Grp) \"y = f x\" \"x \\<in> A\"\nusing assms\nby(simp add: Grp_def)\n\nlemma rel_fun_Grp_copy_Abs:\n  includes lifting_syntax\n  assumes \"type_definition Rep Abs A\"\n  shows \"rel_fun (BNF_Def.Grp A Abs) (BNF_Def.Grp B g) = BNF_Def.Grp {f. f ` A \\<subseteq> B} (Rep ---> g)\"\nproof -\n  interpret type_definition Rep Abs A by fact\n  show ?thesis\n    by(auto simp add: rel_fun_def Grp_def fun_eq_iff Abs_inverse Rep_inverse intro!: Rep)\nqed\n\nlemma rel_set_Grp:\n  \"rel_set (BNF_Def.Grp A f) = BNF_Def.Grp {B. B \\<subseteq> A} (image f)\"\nby(auto simp add: rel_set_def BNF_Def.Grp_def fun_eq_iff)\n\nlemma rel_set_comp_Grp:\n  \"rel_set R = (BNF_Def.Grp {x. x \\<subseteq> {(x, y). R x y}} ((`) fst))\\<inverse>\\<inverse> OO BNF_Def.Grp {x. x \\<subseteq> {(x, y). R x y}} ((`) snd)\"\napply(auto 4 4 del: ext intro!: ext simp add: BNF_Def.Grp_def intro!: rel_setI intro: rev_bexI)\napply(simp add: relcompp_apply)\nsubgoal for A B\n  apply(rule exI[where x=\"A \\<times> B \\<inter> {(x, y). R x y}\"])\n  apply(auto 4 3 dest: rel_setD1 rel_setD2 intro: rev_image_eqI)\n  done\ndone\n\nlemma Domainp_Grp: \"Domainp (BNF_Def.Grp A f) = (\\<lambda>x. x \\<in> A)\"\nby(auto simp add: fun_eq_iff Grp_def)\n\nlemma pred_prod_conj [simp]:\n  shows pred_prod_conj1: \"\\<And>P Q R. pred_prod (\\<lambda>x. P x \\<and> Q x) R = (\\<lambda>x. pred_prod P R x \\<and> pred_prod Q R x)\"\n  and pred_prod_conj2: \"\\<And>P Q R. pred_prod P (\\<lambda>x. Q x \\<and> R x) = (\\<lambda>x. pred_prod P Q x \\<and> pred_prod P R x)\"\nby(auto simp add: pred_prod.simps)\n\nlemma pred_sum_conj [simp]:\n  shows pred_sum_conj1: \"\\<And>P Q R. pred_sum (\\<lambda>x. P x \\<and> Q x) R = (\\<lambda>x. pred_sum P R x \\<and> pred_sum Q R x)\"\n  and pred_sum_conj2: \"\\<And>P Q R. pred_sum P (\\<lambda>x. Q x \\<and> R x) = (\\<lambda>x. pred_sum P Q x \\<and> pred_sum P R x)\"\nby(auto simp add: pred_sum.simps fun_eq_iff)\n\nlemma pred_list_conj [simp]: \"list_all (\\<lambda>x. P x \\<and> Q x) = (\\<lambda>x. list_all P x \\<and> list_all Q x)\"\nby(auto simp add: list_all_def)\n\nlemma pred_prod_top [simp]:\n  \"pred_prod (\\<lambda>_. True) (\\<lambda>_. True) = (\\<lambda>_. True)\"\nby(simp add: pred_prod.simps fun_eq_iff)\n\nlemma rel_fun_conversep: includes lifting_syntax shows\n  \"(A^--1 ===> B^--1) = (A ===> B)^--1\"\nby(auto simp add: rel_fun_def fun_eq_iff)\n\nlemma left_unique_Grp [iff]:\n  \"left_unique (BNF_Def.Grp A f) \\<longleftrightarrow> inj_on f A\"\nunfolding Grp_def left_unique_def by(auto simp add: inj_on_def)\n\nlemma right_unique_Grp [simp, intro!]: \"right_unique (BNF_Def.Grp A f)\"\nby(simp add: Grp_def right_unique_def)\n\nlemma bi_unique_Grp [iff]:\n  \"bi_unique (BNF_Def.Grp A f) \\<longleftrightarrow> inj_on f A\"\nby(simp add: bi_unique_alt_def)\n\nlemma left_total_Grp [iff]:\n  \"left_total (BNF_Def.Grp A f) \\<longleftrightarrow> A = UNIV\"\nby(auto simp add: left_total_def Grp_def)\n\nlemma right_total_Grp [iff]:\n  \"right_total (BNF_Def.Grp A f) \\<longleftrightarrow> f ` A = UNIV\"\nby(auto simp add: right_total_def BNF_Def.Grp_def image_def)\n\nlemma bi_total_Grp [iff]:\n  \"bi_total (BNF_Def.Grp A f) \\<longleftrightarrow> A = UNIV \\<and> surj f\"\nby(auto simp add: bi_total_alt_def)\n\nlemma left_unique_vimage2p [simp]:\n  \"\\<lbrakk> left_unique P; inj f \\<rbrakk> \\<Longrightarrow> left_unique (BNF_Def.vimage2p f g P)\"\nunfolding vimage2p_Grp by(intro left_unique_OO) simp_all\n\nlemma right_unique_vimage2p [simp]:\n  \"\\<lbrakk> right_unique P; inj g \\<rbrakk> \\<Longrightarrow> right_unique (BNF_Def.vimage2p f g P)\"\nunfolding vimage2p_Grp by(intro right_unique_OO) simp_all\n\nlemma bi_unique_vimage2p [simp]:\n  \"\\<lbrakk> bi_unique P; inj f; inj g \\<rbrakk> \\<Longrightarrow> bi_unique (BNF_Def.vimage2p f g P)\"\nunfolding bi_unique_alt_def by simp\n\nlemma left_total_vimage2p [simp]:\n  \"\\<lbrakk> left_total P; surj g \\<rbrakk> \\<Longrightarrow> left_total (BNF_Def.vimage2p f g P)\"\nunfolding vimage2p_Grp by(intro left_total_OO) simp_all\n\nlemma right_total_vimage2p [simp]:\n  \"\\<lbrakk> right_total P; surj f \\<rbrakk> \\<Longrightarrow> right_total (BNF_Def.vimage2p f g P)\"\nunfolding vimage2p_Grp by(intro right_total_OO) simp_all\n\nlemma bi_total_vimage2p [simp]:\n  \"\\<lbrakk> bi_total P; surj f; surj g \\<rbrakk> \\<Longrightarrow> bi_total (BNF_Def.vimage2p f g P)\"\nunfolding bi_total_alt_def by simp\n\nlemma vimage2p_eq [simp]:\n  \"inj f \\<Longrightarrow> BNF_Def.vimage2p f f (=) = (=)\"\nby(auto simp add: vimage2p_def fun_eq_iff inj_on_def)\n\nlemma vimage2p_conversep: \"BNF_Def.vimage2p f g R^--1 = (BNF_Def.vimage2p g f R)^--1\"\nby(simp add: vimage2p_def fun_eq_iff)\n\nlemma rel_fun_refl: \"\\<lbrakk> A \\<le> (=); (=) \\<le> B \\<rbrakk> \\<Longrightarrow> (=) \\<le> rel_fun A B\"\n  by(subst fun.rel_eq[symmetric])(rule fun_mono)\n\nlemma rel_fun_mono_strong:\n  \"\\<lbrakk> rel_fun A B f g; A' \\<le> A; \\<And>x y. \\<lbrakk> x \\<in> f ` {x. Domainp A' x}; y \\<in> g ` {x. Rangep A' x}; B x y \\<rbrakk> \\<Longrightarrow> B' x y \\<rbrakk> \\<Longrightarrow> rel_fun A' B' f g\"\n  by(auto simp add: rel_fun_def) fastforce\n\nlemma rel_fun_refl_strong: \n  assumes \"A \\<le> (=)\" \"\\<And>x. x \\<in> f ` {x. Domainp A x} \\<Longrightarrow> B x x\"\n  shows \"rel_fun A B f f\"\nproof -\n  have \"rel_fun (=) (=) f f\" by(simp add: rel_fun_eq)\n  then show ?thesis using assms(1)\n    by(rule rel_fun_mono_strong) (auto intro: assms(2))\nqed\n\nlemma Grp_iff: \"BNF_Def.Grp B g x y \\<longleftrightarrow> y = g x \\<and> x \\<in> B\" by(simp add: Grp_def)\n\nlemma Rangep_Grp: \"Rangep (BNF_Def.Grp A f) = (\\<lambda>x. x \\<in> f ` A)\"\n  by(auto simp add: fun_eq_iff Grp_iff)\n\nlemma rel_fun_Grp:\n  \"rel_fun (BNF_Def.Grp UNIV h)\\<inverse>\\<inverse> (BNF_Def.Grp A g) = BNF_Def.Grp {f. f ` range h \\<subseteq> A} (map_fun h g)\"\n  by(auto simp add: rel_fun_def fun_eq_iff Grp_iff)\n\nsubsection \\<open>Transfer and lifting material\\<close>\n\ncontext includes lifting_syntax begin\n\nlemma monotone_parametric [transfer_rule]:\n  assumes [transfer_rule]: \"bi_total A\"\n  shows \"((A ===> A ===> (=)) ===> (B ===> B ===> (=)) ===> (A ===> B) ===> (=)) monotone monotone\"\nunfolding monotone_def[abs_def] by transfer_prover\n\nlemma fun_ord_parametric [transfer_rule]:\n  assumes [transfer_rule]: \"bi_total C\"\n  shows \"((A ===> B ===> (=)) ===> (C ===> A) ===> (C ===> B) ===> (=)) fun_ord fun_ord\"\nunfolding fun_ord_def[abs_def] by transfer_prover\n\nlemma Plus_parametric [transfer_rule]:\n  \"(rel_set A ===> rel_set B ===> rel_set (rel_sum A B)) (<+>) (<+>)\"\nunfolding Plus_def[abs_def] by transfer_prover\n\nlemma pred_fun_parametric [transfer_rule]:\n  assumes [transfer_rule]: \"bi_total A\"\n  shows \"((A ===> (=)) ===> (B ===> (=)) ===> (A ===> B) ===> (=)) pred_fun pred_fun\"\nunfolding pred_fun_def by(transfer_prover)\n\nlemma rel_fun_eq_OO: \"((=) ===> A) OO ((=) ===> B) = ((=) ===> A OO B)\"\nby(clarsimp simp add: rel_fun_def fun_eq_iff relcompp.simps) metis\n\nend\n\nlemma Quotient_set_rel_eq:\n  includes lifting_syntax\n  assumes \"Quotient R Abs Rep T\"\n  shows \"(rel_set T ===> rel_set T ===> (=)) (rel_set R) (=)\"\nproof(rule rel_funI iffI)+\n  fix A B C D\n  assume AB: \"rel_set T A B\" and CD: \"rel_set T C D\"\n  have *: \"\\<And>x y. R x y = (T x (Abs x) \\<and> T y (Abs y) \\<and> Abs x = Abs y)\"\n    \"\\<And>a b. T a b \\<Longrightarrow> Abs a = b\"\n    using assms unfolding Quotient_alt_def by simp_all\n\n  { assume [simp]: \"B = D\"\n    thus \"rel_set R A C\"\n      by(auto 4 4 intro!: rel_setI dest: rel_setD1[OF AB, simplified] rel_setD2[OF AB, simplified] rel_setD2[OF CD] rel_setD1[OF CD] simp add: * elim!: rev_bexI)\n  next\n    assume AC: \"rel_set R A C\"\n    show \"B = D\"\n      apply safe\n       apply(drule rel_setD2[OF AB], erule bexE)\n       apply(drule rel_setD1[OF AC], erule bexE)\n       apply(drule rel_setD1[OF CD], erule bexE)\n       apply(simp add: *)\n      apply(drule rel_setD2[OF CD], erule bexE)\n      apply(drule rel_setD2[OF AC], erule bexE)\n      apply(drule rel_setD1[OF AB], erule bexE)\n      apply(simp add: *)\n      done\n  }\nqed\n\nlemma Domainp_eq: \"Domainp (=) = (\\<lambda>_. True)\"\nby(simp add: Domainp.simps fun_eq_iff)\n\nlemma rel_fun_eq_onpI: \"eq_onp (pred_fun P Q) f g \\<Longrightarrow> rel_fun (eq_onp P) (eq_onp Q) f g\"\nby(auto simp add: eq_onp_def rel_fun_def)\n\nlemma bi_unique_eq_onp: \"bi_unique (eq_onp P)\"\nby(simp add: bi_unique_def eq_onp_def)\n\nlemma rel_fun_eq_conversep: includes lifting_syntax shows \"(A\\<inverse>\\<inverse> ===> (=)) = (A ===> (=))\\<inverse>\\<inverse>\"\nby(auto simp add: fun_eq_iff rel_fun_def)\n\n\n\nlemma rel_fun_map_fun1: \"rel_fun (BNF_Def.Grp UNIV h)\\<inverse>\\<inverse> A f g \\<Longrightarrow> rel_fun (=) A (map_fun h id f) g\"\n  by(auto simp add: rel_fun_def Grp_def)\n\nlemma map_fun2_id: \"map_fun f g x = g \\<circ> map_fun f id x\"\n  by(simp add: map_fun_def o_assoc)\n\nlemma map_fun_id2_in: \"map_fun g h f = map_fun g id (h \\<circ> f)\"\n  by(simp add: map_fun_def)\n\nlemma Domainp_rel_fun_le: \"Domainp (rel_fun A B) \\<le> pred_fun (Domainp A) (Domainp B)\"\n  by(auto dest: rel_funD)\n\ndefinition rel_witness_fun :: \"('a \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow> ('b \\<Rightarrow> 'c \\<Rightarrow> bool) \\<Rightarrow> ('a \\<Rightarrow> 'd) \\<times> ('c \\<Rightarrow> 'e) \\<Rightarrow> ('b \\<Rightarrow> 'd \\<times> 'e)\" where\n  \"rel_witness_fun A A' = (\\<lambda>(f, g) b. (f (THE a. A a b), g (THE c. A' b c)))\"\n\nlemma\n  assumes fg: \"rel_fun (A OO A') B f g\"\n    and A: \"left_unique A\" \"right_total A\"\n    and A': \"right_unique A'\" \"left_total A'\"\n  shows rel_witness_fun1: \"rel_fun A (\\<lambda>x (x', y). x = x' \\<and> B x' y) f (rel_witness_fun A A' (f, g))\"\n    and rel_witness_fun2: \"rel_fun A' (\\<lambda>(x, y') y. y = y' \\<and> B x y') (rel_witness_fun A A' (f, g)) g\"\nproof (goal_cases)\n  case 1\n  have \"A x y \\<Longrightarrow> f x = f (THE a. A a y) \\<and> B (f (THE a. A a y)) (g (The (A' y)))\" for x y \n    by(rule left_totalE[OF A'(2)]; erule meta_allE[of _ y]; erule exE; frule (1) fg[THEN rel_funD, OF relcomppI])\n      (auto intro!: arg_cong[where f=f] arg_cong[where f=g] rel_funI the_equality the_equality[symmetric] dest: left_uniqueD[OF A(1)] right_uniqueD[OF A'(1)] elim!: arg_cong2[where f=B, THEN iffD2, rotated -1])\n\n  with 1 show ?case by(clarsimp simp add: rel_fun_def rel_witness_fun_def)\nnext\n  case 2\n  have \"A' x y \\<Longrightarrow> g y = g (The (A' x)) \\<and> B (f (THE a. A a x)) (g (The (A' x)))\" for x y\n    by(rule right_totalE[OF A(2), of x]; frule (1) fg[THEN rel_funD, OF relcomppI])\n      (auto intro!: arg_cong[where f=f] arg_cong[where f=g] rel_funI the_equality the_equality[symmetric] dest: left_uniqueD[OF A(1)] right_uniqueD[OF A'(1)] elim!: arg_cong2[where f=B, THEN iffD2, rotated -1])\n\n  with 2 show ?case by(clarsimp simp add: rel_fun_def rel_witness_fun_def)    \nqed\n\nlemma rel_witness_fun_eq [simp]: \"rel_witness_fun (=) (=) (f, g) = (\\<lambda>x. (f x, g x))\"\n  by(simp add: rel_witness_fun_def)\n\nsubsection \\<open>Arithmetic\\<close>\n\nlemma abs_diff_triangle_ineq2: \"\\<bar>a - b :: _ :: ordered_ab_group_add_abs\\<bar> \\<le> \\<bar>a - c\\<bar> + \\<bar>c - b\\<bar>\"\nby(rule order_trans[OF _ abs_diff_triangle_ineq]) simp\n\nlemma (in ordered_ab_semigroup_add) add_left_mono_trans:\n  \"\\<lbrakk> x \\<le> a + b; b \\<le> c \\<rbrakk> \\<Longrightarrow> x \\<le> a + c\"\nby(erule order_trans)(rule add_left_mono)\n\nlemma of_nat_le_one_cancel_iff [simp]:\n  fixes n :: nat shows \"real n \\<le> 1 \\<longleftrightarrow> n \\<le> 1\"\nby linarith\n\nlemma (in linordered_semidom) mult_right_le: \"c \\<le> 1 \\<Longrightarrow> 0 \\<le> a \\<Longrightarrow> c * a \\<le> a\"\nby(subst mult.commute)(rule mult_left_le)\n\nsubsection \\<open>Chain-complete partial orders and \\<open>partial_function\\<close>\\<close>\n\nlemma fun_ordD: \"fun_ord ord f g \\<Longrightarrow> ord (f x) (g x)\"\nby(simp add: fun_ord_def)\n\nlemma parallel_fixp_induct_strong:\n  assumes ccpo1: \"class.ccpo luba orda (mk_less orda)\"\n  and ccpo2: \"class.ccpo lubb ordb (mk_less ordb)\"\n  and adm: \"ccpo.admissible (prod_lub luba lubb) (rel_prod orda ordb) (\\<lambda>x. P (fst x) (snd x))\"\n  and f: \"monotone orda orda f\"\n  and g: \"monotone ordb ordb g\"\n  and bot: \"P (luba {}) (lubb {})\"\n  and step: \"\\<And>x y. \\<lbrakk> orda x (ccpo.fixp luba orda f); ordb y (ccpo.fixp lubb ordb g); P x y \\<rbrakk> \\<Longrightarrow> P (f x) (g y)\"\n  shows \"P (ccpo.fixp luba orda f) (ccpo.fixp lubb ordb g)\"\nproof -\n  let ?P=\"\\<lambda>x y. orda x (ccpo.fixp luba orda f) \\<and> ordb y (ccpo.fixp lubb ordb g) \\<and> P x y\"\n  show ?thesis using ccpo1 ccpo2 _ f g\n  proof(rule parallel_fixp_induct[where P=\"?P\", THEN conjunct2, THEN conjunct2])\n    note [cont_intro] = \n      admissible_leI[OF ccpo1] ccpo.mcont_const[OF ccpo1]\n      admissible_leI[OF ccpo2] ccpo.mcont_const[OF ccpo2]\n    show \"ccpo.admissible (prod_lub luba lubb) (rel_prod orda ordb) (\\<lambda>xy. ?P (fst xy) (snd xy))\"\n      using adm by simp\n    show \"?P (luba {}) (lubb {})\" using bot by(auto intro: ccpo.ccpo_Sup_least ccpo1 ccpo2 chain_empty)\n    show \"?P (f x) (g y)\" if \"?P x y\" for x y using that\n      apply(subst ccpo.fixp_unfold[OF ccpo1 f])\n      apply(subst ccpo.fixp_unfold[OF ccpo2 g])\n      apply(auto intro: step monotoneD[OF f] monotoneD[OF g])\n      done\n  qed\nqed\n\nlemma parallel_fixp_induct_strong_uc:\n  assumes a: \"partial_function_definitions orda luba\"\n  and b: \"partial_function_definitions ordb lubb\"\n  and F: \"\\<And>x. monotone (fun_ord orda) orda (\\<lambda>f. U1 (F (C1 f)) x)\"\n  and G: \"\\<And>y. monotone (fun_ord ordb) ordb (\\<lambda>g. U2 (G (C2 g)) y)\"\n  and eq1: \"f \\<equiv> C1 (ccpo.fixp (fun_lub luba) (fun_ord orda) (\\<lambda>f. U1 (F (C1 f))))\"\n  and eq2: \"g \\<equiv> C2 (ccpo.fixp (fun_lub lubb) (fun_ord ordb) (\\<lambda>g. U2 (G (C2 g))))\"\n  and inverse: \"\\<And>f. U1 (C1 f) = f\"\n  and inverse2: \"\\<And>g. U2 (C2 g) = g\"\n  and adm: \"ccpo.admissible (prod_lub (fun_lub luba) (fun_lub lubb)) (rel_prod (fun_ord orda) (fun_ord ordb)) (\\<lambda>x. P (fst x) (snd x))\"\n  and bot: \"P (\\<lambda>_. luba {}) (\\<lambda>_. lubb {})\"\n  and step: \"\\<And>f' g'. \\<lbrakk> \\<And>x. orda (U1 f' x) (U1 f x); \\<And>y. ordb (U2 g' y) (U2 g y); P (U1 f') (U2 g') \\<rbrakk> \\<Longrightarrow> P (U1 (F f')) (U2 (G g'))\"\n  shows \"P (U1 f) (U2 g)\"\napply(unfold eq1 eq2 inverse inverse2)\napply(rule parallel_fixp_induct_strong[OF partial_function_definitions.ccpo[OF a] partial_function_definitions.ccpo[OF b] adm])\nusing F apply(simp add: monotone_def fun_ord_def)\nusing G apply(simp add: monotone_def fun_ord_def)\napply(simp add: fun_lub_def bot)\napply(rule step; simp add: inverse inverse2 eq1 eq2 fun_ordD)\ndone\n\nlemmas parallel_fixp_induct_strong_1_1 = parallel_fixp_induct_strong_uc[\n  of _ _ _ _ \"\\<lambda>x. x\" _ \"\\<lambda>x. x\" \"\\<lambda>x. x\" _ \"\\<lambda>x. x\",\n  OF _ _ _ _ _ _ refl refl]\n\nlemmas parallel_fixp_induct_strong_2_2 = parallel_fixp_induct_strong_uc[\n  of _ _ _ _ \"case_prod\" _ \"curry\" \"case_prod\" _ \"curry\",\n  where P=\"\\<lambda>f g. P (curry f) (curry g)\",\n  unfolded case_prod_curry curry_case_prod curry_K,\n  OF _ _ _ _ _ _ refl refl,\n  split_format (complete), unfolded prod.case]\n  for P\n\nlemma fixp_induct_option': \\<comment> \\<open>Stronger induction rule\\<close>\n  fixes F :: \"'c \\<Rightarrow> 'c\" and\n    U :: \"'c \\<Rightarrow> 'b \\<Rightarrow> 'a option\" and\n    C :: \"('b \\<Rightarrow> 'a option) \\<Rightarrow> 'c\" and\n    P :: \"'b \\<Rightarrow> 'a \\<Rightarrow> bool\"\n  assumes mono: \"\\<And>x. mono_option (\\<lambda>f. U (F (C f)) x)\"\n  assumes eq: \"f \\<equiv> C (ccpo.fixp (fun_lub (flat_lub None)) (fun_ord option_ord) (\\<lambda>f. U (F (C f))))\"\n  assumes inverse2: \"\\<And>f. U (C f) = f\"\n  assumes step: \"\\<And>g x y. \\<lbrakk> \\<And>x y. U g x = Some y \\<Longrightarrow> P x y; U (F g) x = Some y; \\<And>x. option_ord (U g x) (U f x) \\<rbrakk> \\<Longrightarrow> P x y\"\n  assumes defined: \"U f x = Some y\"\n  shows \"P x y\"\nusing step defined option.fixp_strong_induct_uc[of U F C, OF mono eq inverse2 option_admissible, of P]\nunfolding fun_lub_def flat_lub_def fun_ord_def\nby(simp (no_asm_use)) blast\n\ndeclaration \\<open>Partial_Function.init \"option'\" @{term option.fixp_fun}\n  @{term option.mono_body} @{thm option.fixp_rule_uc} @{thm option.fixp_induct_uc}\n  (SOME @{thm fixp_induct_option'})\\<close>\n\nlemma bot_fun_least [simp]: \"(\\<lambda>_. bot :: 'a :: order_bot) \\<le> x\"\nby(fold bot_fun_def) simp\n\nlemma fun_ord_conv_rel_fun: \"fun_ord = rel_fun (=)\"\nby(simp add: fun_ord_def fun_eq_iff rel_fun_def)\n\ninductive finite_chains :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool) \\<Rightarrow> bool\"\n  for ord\nwhere finite_chainsI: \"(\\<And>Y. Complete_Partial_Order.chain ord Y \\<Longrightarrow> finite Y) \\<Longrightarrow> finite_chains ord\"\n\nlemma finite_chainsD: \"\\<lbrakk> finite_chains ord; Complete_Partial_Order.chain ord Y \\<rbrakk> \\<Longrightarrow> finite Y\"\nby(rule finite_chains.cases)\n\nlemma finite_chains_flat_ord [simp, intro!]: \"finite_chains (flat_ord x)\"\nproof\n  fix Y\n  assume chain: \"Complete_Partial_Order.chain (flat_ord x) Y\"\n  show \"finite Y\"\n  proof(cases \"\\<exists>y \\<in> Y. y \\<noteq> x\")\n    case True\n    then obtain y where y: \"y \\<in> Y\" and yx: \"y \\<noteq> x\" by blast\n    hence \"Y \\<subseteq> {x, y}\" by(auto dest: chainD[OF chain] simp add: flat_ord_def)\n    thus ?thesis by(rule finite_subset) simp\n  next\n    case False\n    hence \"Y \\<subseteq> {x}\" by auto\n    thus ?thesis by(rule finite_subset) simp\n  qed\nqed    \n\nlemma mcont_finite_chains:\n  assumes finite: \"finite_chains ord\"\n  and mono: \"monotone ord ord' f\"\n  and ccpo: \"class.ccpo lub ord (mk_less ord)\"\n  and ccpo': \"class.ccpo lub' ord' (mk_less ord')\"\n  shows \"mcont lub ord lub' ord' f\"\nproof(intro mcontI contI)\n  fix Y\n  assume chain: \"Complete_Partial_Order.chain ord Y\" and Y: \"Y \\<noteq> {}\"\n  from finite chain have fin: \"finite Y\" by(rule finite_chainsD)\n  from ccpo chain fin Y have lub: \"lub Y \\<in> Y\" by(rule ccpo.in_chain_finite)\n\n  interpret ccpo': ccpo lub' ord' \"mk_less ord'\" by(rule ccpo')\n\n  have chain': \"Complete_Partial_Order.chain ord' (f ` Y)\" using chain\n    by(rule chain_imageI)(rule monotoneD[OF mono])\n\n  have \"ord' (f (lub Y)) (lub' (f ` Y))\" using chain'\n    by(rule ccpo'.ccpo_Sup_upper)(simp add: lub)\n  moreover\n  have \"ord' (lub' (f ` Y)) (f (lub Y))\" using chain'\n    by(rule ccpo'.ccpo_Sup_least)(blast intro: monotoneD[OF mono] ccpo.ccpo_Sup_upper[OF ccpo chain])\n  ultimately show \"f (lub Y) = lub' (f ` Y)\" by(rule ccpo'.order.antisym)\nqed(fact mono)  \n\nlemma rel_fun_curry: includes lifting_syntax shows\n  \"(A ===> B ===> C) f g \\<longleftrightarrow> (rel_prod A B ===> C) (case_prod f) (case_prod g)\"\nby(auto simp add: rel_fun_def)\n\nlemma (in ccpo) Sup_image_mono:\n  assumes ccpo: \"class.ccpo luba orda lessa\"\n  and mono: \"monotone orda (\\<le>) f\"\n  and chain: \"Complete_Partial_Order.chain orda A\"\n  and \"A \\<noteq> {}\"\n  shows \"Sup (f ` A) \\<le> (f (luba A))\"\nproof(rule ccpo_Sup_least)\n  from chain show \"Complete_Partial_Order.chain (\\<le>) (f ` A)\"\n    by(rule chain_imageI)(rule monotoneD[OF mono])\n  fix x\n  assume \"x \\<in> f ` A\"\n  then obtain y where \"x = f y\" \"y \\<in> A\" by blast\n  from \\<open>y \\<in> A\\<close> have \"orda y (luba A)\" by(rule ccpo.ccpo_Sup_upper[OF ccpo chain])\n  hence \"f y \\<le> f (luba A)\" by(rule monotoneD[OF mono])\n  thus \"x \\<le> f (luba A)\" using \\<open>x = f y\\<close> by simp\nqed\n\nlemma (in ccpo) admissible_le_mono:\n  assumes \"monotone (\\<le>) (\\<le>) f\"\n  shows \"ccpo.admissible Sup (\\<le>) (\\<lambda>x. x \\<le> f x)\"\nproof(rule ccpo.admissibleI)\n  fix Y\n  assume chain: \"Complete_Partial_Order.chain (\\<le>) Y\"\n    and Y: \"Y \\<noteq> {}\"\n    and le [rule_format]: \"\\<forall>x\\<in>Y. x \\<le> f x\"\n  have \"\\<Squnion>Y \\<le> \\<Squnion>(f ` Y)\" using chain\n    by(rule ccpo_Sup_least)(rule order_trans[OF le]; blast intro!: ccpo_Sup_upper chain_imageI[OF chain] intro: monotoneD[OF assms])\n  also have \"\\<dots> \\<le> f (\\<Squnion>Y)\"\n    by(rule Sup_image_mono[OF _ assms chain Y, where lessa=\"(<)\"]) unfold_locales\n  finally show \"\\<Squnion>Y \\<le> \\<dots>\" .\nqed\n\nlemma (in ccpo) fixp_induct_strong2:\n  assumes adm: \"ccpo.admissible Sup (\\<le>) P\"\n  and mono: \"monotone (\\<le>) (\\<le>) f\"\n  and bot: \"P (\\<Squnion>{})\"\n  and step: \"\\<And>x. \\<lbrakk> x \\<le> ccpo_class.fixp f; x \\<le> f x; P x \\<rbrakk> \\<Longrightarrow> P (f x)\"\n  shows \"P (ccpo_class.fixp f)\"\nproof(rule fixp_strong_induct[where P=\"\\<lambda>x. x \\<le> f x \\<and> P x\", THEN conjunct2])\n  show \"ccpo.admissible Sup (\\<le>) (\\<lambda>x. x \\<le> f x \\<and> P x)\"\n    using admissible_le_mono adm by(rule admissible_conj)(rule mono)\nnext\n  show \"\\<Squnion>{} \\<le> f (\\<Squnion>{}) \\<and> P (\\<Squnion>{})\"\n    by(auto simp add: bot chain_empty intro: ccpo_Sup_least)\nnext\n  fix x\n  assume \"x \\<le> ccpo_class.fixp f\" \"x \\<le> f x \\<and> P x\"\n  thus \"f x \\<le> f (f x) \\<and> P (f x)\"\n    by(auto dest: monotoneD[OF mono] intro: step)\nqed(rule mono)\n\ncontext partial_function_definitions begin\n\nlemma fixp_induct_strong2_uc:\n  fixes F :: \"'c \\<Rightarrow> 'c\"\n    and U :: \"'c \\<Rightarrow> 'b \\<Rightarrow> 'a\"\n    and C :: \"('b \\<Rightarrow> 'a) \\<Rightarrow> 'c\"\n    and P :: \"('b \\<Rightarrow> 'a) \\<Rightarrow> bool\"\n  assumes mono: \"\\<And>x. mono_body (\\<lambda>f. U (F (C f)) x)\"\n    and eq: \"f \\<equiv> C (fixp_fun (\\<lambda>f. U (F (C f))))\"\n    and inverse: \"\\<And>f. U (C f) = f\"\n    and adm: \"ccpo.admissible lub_fun le_fun P\"\n    and bot: \"P (\\<lambda>_. lub {})\"\n    and step: \"\\<And>f'. \\<lbrakk> le_fun (U f') (U f); le_fun (U f') (U (F f')); P (U f') \\<rbrakk> \\<Longrightarrow> P (U (F f'))\"\n  shows \"P (U f)\"\nunfolding eq inverse\napply (rule ccpo.fixp_induct_strong2[OF ccpo adm])\napply (insert mono, auto simp: monotone_def fun_ord_def bot fun_lub_def)[2]\napply (rule_tac f'5=\"C x\" in step)\napply (simp_all add: inverse eq)\ndone\n\nend\n\nlemmas parallel_fixp_induct_2_4 = parallel_fixp_induct_uc[\n  of _ _ _ _ \"case_prod\" _ \"curry\" \"\\<lambda>f. case_prod (case_prod (case_prod f))\" _ \"\\<lambda>f. curry (curry (curry f))\",\n  where P=\"\\<lambda>f g. P (curry f) (curry (curry (curry g)))\",\n  unfolded case_prod_curry curry_case_prod curry_K,\n  OF _ _ _ _ _ _ refl refl]\n  for P\n  \nlemma (in ccpo) fixp_greatest:\n  assumes f: \"monotone (\\<le>) (\\<le>) f\"\n    and ge: \"\\<And>y. f y \\<le> y \\<Longrightarrow> x \\<le> y\"\n  shows \"x \\<le> ccpo.fixp Sup (\\<le>) f\"\n  by(rule ge)(simp add: fixp_unfold[OF f, symmetric])\n\nlemma fixp_rolling:\n  assumes \"class.ccpo lub1 leq1 (mk_less leq1)\"\n    and \"class.ccpo lub2 leq2 (mk_less leq2)\"\n    and f: \"monotone leq1 leq2 f\"\n    and g: \"monotone leq2 leq1 g\"\n  shows \"ccpo.fixp lub1 leq1 (\\<lambda>x. g (f x)) = g (ccpo.fixp lub2 leq2 (\\<lambda>x. f (g x)))\"\nproof -\n  interpret c1: ccpo lub1 leq1 \"mk_less leq1\" by fact\n  interpret c2: ccpo lub2 leq2 \"mk_less leq2\" by fact\n  show ?thesis\n  proof(rule c1.order.antisym)\n    have fg: \"monotone leq2 leq2 (\\<lambda>x. f (g x))\" using f g by(rule monotone2monotone) simp_all\n    have gf: \"monotone leq1 leq1 (\\<lambda>x. g (f x))\" using g f by(rule monotone2monotone) simp_all\n    show \"leq1 (c1.fixp (\\<lambda>x. g (f x))) (g (c2.fixp (\\<lambda>x. f (g x))))\" using gf\n      by(rule c1.fixp_lowerbound)(subst (2) c2.fixp_unfold[OF fg], simp)\n    show \"leq1 (g (c2.fixp (\\<lambda>x. f (g x)))) (c1.fixp (\\<lambda>x. g (f x)))\" using gf\n    proof(rule c1.fixp_greatest)\n      fix u\n      assume u: \"leq1 (g (f u)) u\"\n      have \"leq1 (g (c2.fixp (\\<lambda>x. f (g x)))) (g (f u))\"\n        by(intro monotoneD[OF g] c2.fixp_lowerbound[OF fg] monotoneD[OF f u])\n      then show \"leq1 (g (c2.fixp (\\<lambda>x. f (g x)))) u\" using u by(rule c1.order_trans)\n    qed\n  qed\nqed\n\nlemma fixp_lfp_parametric_eq:\n  includes lifting_syntax\n  assumes f: \"\\<And>x. lfp.mono_body (\\<lambda>f. F f x)\"\n  and g: \"\\<And>x. lfp.mono_body (\\<lambda>f. G f x)\"\n  and param: \"((A ===> (=)) ===> A ===> (=)) F G\"\n  shows \"(A ===> (=)) (lfp.fixp_fun F) (lfp.fixp_fun G)\"\nusing f g\nproof(rule parallel_fixp_induct_1_1[OF complete_lattice_partial_function_definitions complete_lattice_partial_function_definitions _ _ reflexive reflexive, where P=\"(A ===> (=))\"])\n  show \"ccpo.admissible (prod_lub lfp.lub_fun lfp.lub_fun) (rel_prod lfp.le_fun lfp.le_fun) (\\<lambda>x. (A ===> (=)) (fst x) (snd x))\"\n    unfolding rel_fun_def by simp\n  show \"(A ===> (=)) (\\<lambda>_. \\<Squnion>{}) (\\<lambda>_. \\<Squnion>{})\" by auto\n  show \"(A ===> (=)) (F f) (G g)\" if \"(A ===> (=)) f g\" for f g\n    using that by(rule rel_funD[OF param])\nqed\n\nlemma mono2mono_map_option[THEN option.mono2mono, simp, cont_intro]:\n  shows monotone_map_option: \"monotone option_ord option_ord (map_option f)\"\nby(rule monotoneI)(auto simp add: flat_ord_def)\n\nlemma mcont2mcont_map_option[THEN option.mcont2mcont, simp, cont_intro]:\n  shows mcont_map_option: \"mcont (flat_lub None) option_ord (flat_lub None) option_ord (map_option f)\"\nby(rule mcont_finite_chains[OF _ _ flat_interpretation[THEN ccpo] flat_interpretation[THEN ccpo]]) simp_all\n\nlemma mono2mono_set_option [THEN lfp.mono2mono]:\n  shows monotone_set_option: \"monotone option_ord (\\<subseteq>) set_option\"\nby(auto intro!: monotoneI simp add: option_ord_Some1_iff)\n\n\n\nlemma eadd_gfp_partial_function_mono [partial_function_mono]:\n  \"\\<lbrakk> monotone (fun_ord (\\<ge>)) (\\<ge>) f; monotone (fun_ord (\\<ge>)) (\\<ge>) g \\<rbrakk>\n  \\<Longrightarrow> monotone (fun_ord (\\<ge>)) (\\<ge>) (\\<lambda>x. f x + g x :: enat)\"\nby(rule mono2mono_gfp_eadd)\n\nlemma map_option_mono [partial_function_mono]:\n  \"mono_option B \\<Longrightarrow> mono_option (\\<lambda>f. map_option g (B f))\"\nunfolding map_conv_bind_option by(rule bind_mono) simp_all\n\n\nsubsection \\<open>Folding over finite sets\\<close>\n\nlemma (in comp_fun_commute) fold_invariant_remove [consumes 1, case_names start step]:\n  assumes fin: \"finite A\"\n  and start: \"I A s\"\n  and step: \"\\<And>x s A'. \\<lbrakk> x \\<in> A'; I A' s; A' \\<subseteq> A \\<rbrakk> \\<Longrightarrow> I (A' - {x}) (f x s)\"\n  shows \"I {} (Finite_Set.fold f s A)\"\nproof -\n  define A' where \"A' == A\"\n  with fin start have \"finite A'\" \"A' \\<subseteq> A\" \"I A' s\" by simp_all\n  thus \"I {} (Finite_Set.fold f s A')\"\n  proof(induction arbitrary: s)\n    case empty thus ?case by simp\n  next\n    case (insert x A')\n    let ?A' = \"insert x A'\"\n    have \"x \\<in> ?A'\" \"I ?A' s\" \"?A' \\<subseteq> A\" using insert by auto\n    hence \"I (?A' - {x}) (f x s)\" by(rule step)\n    with insert have \"A' \\<subseteq> A\" \"I A' (f x s)\" by auto\n    hence \"I {} (Finite_Set.fold f (f x s) A')\" by(rule insert.IH)\n    thus ?case using insert by(simp add: fold_insert2 del: fold_insert)\n  qed\nqed\n\nlemma (in comp_fun_commute) fold_invariant_insert [consumes 1, case_names start step]:\n  assumes fin: \"finite A\"\n  and start: \"I {} s\"\n  and step: \"\\<And>x s A'. \\<lbrakk> I A' s; x \\<notin> A'; x \\<in> A; A' \\<subseteq> A \\<rbrakk> \\<Longrightarrow> I (insert x A') (f x s)\"\n  shows \"I A (Finite_Set.fold f s A)\"\nusing fin start\nproof(rule fold_invariant_remove[where I=\"\\<lambda>A'. I (A - A')\" and A=A and s=s, simplified])\n  fix x s A'\n  assume *: \"x \\<in> A'\" \"I (A - A') s\" \"A' \\<subseteq> A\"\n  hence \"x \\<notin> A - A'\" \"x \\<in> A\" \"A - A' \\<subseteq> A\" by auto\n  with \\<open>I (A - A') s\\<close> have \"I (insert x (A - A')) (f x s)\" by(rule step)\n  also have \"insert x (A - A') = A - (A' - {x})\" using * by auto\n  finally show \"I \\<dots> (f x s)\" .\nqed\n\nlemma (in comp_fun_idem) fold_set_union:\n  assumes \"finite A\" \"finite B\"\n  shows \"Finite_Set.fold f z (A \\<union> B) = Finite_Set.fold f (Finite_Set.fold f z A) B\"\nusing assms(2,1) by induction simp_all\n\n\nsubsection \\<open>Parametrisation of transfer rules\\<close>\n\nattribute_setup transfer_parametric = \\<open> \n  Attrib.thm >> (fn parametricity =>\n    Thm.rule_attribute [] (fn context => fn transfer_rule =>\n      let\n        val ctxt = Context.proof_of context;\n        val thm' = Lifting_Term.parametrize_transfer_rule ctxt transfer_rule\n      in Lifting_Def.generate_parametric_transfer_rule ctxt thm' parametricity\n      end\n      handle Lifting_Term.MERGE_TRANSFER_REL msg => error (Pretty.string_of msg)\n      ))\n\\<close> \"combine transfer rule with parametricity theorem\"\n\nsubsection \\<open>Lists\\<close>\n\nlemma nth_eq_tlI: \"xs ! n = z \\<Longrightarrow> (x # xs) ! Suc n = z\"\nby simp\n\nlemma list_all2_append':\n  \"length us = length vs \\<Longrightarrow> list_all2 P (xs @ us) (ys @ vs) \\<longleftrightarrow> list_all2 P xs ys \\<and> list_all2 P us vs\"\nby(auto simp add: list_all2_append1 list_all2_append2 dest: list_all2_lengthD)\n\ndefinition disjointp :: \"('a \\<Rightarrow> bool) list \\<Rightarrow> bool\"\nwhere \"disjointp xs = disjoint_family_on (\\<lambda>n. {x. (xs ! n) x}) {0..<length xs}\"\n\nlemma disjointpD:\n  \"\\<lbrakk> disjointp xs; (xs ! n) x; (xs ! m) x; n < length xs; m < length xs \\<rbrakk> \\<Longrightarrow> n = m\"\nby(auto 4 3 simp add: disjointp_def disjoint_family_on_def)\n\nlemma disjointpD':\n  \"\\<lbrakk> disjointp xs; P x; Q x; xs ! n = P; xs ! m = Q; n < length xs; m < length xs \\<rbrakk> \\<Longrightarrow> n = m\"\nby(auto 4 3 simp add: disjointp_def disjoint_family_on_def)\n\nlemma wf_strict_prefix: \"wfP strict_prefix\"\nproof -\n  from wf have \"wf (inv_image {(x, y). x < y} length)\" by(rule wf_inv_image)\n  moreover have \"{(x, y). strict_prefix x y} \\<subseteq> inv_image {(x, y). x < y} length\" by(auto intro: prefix_length_less)\n  ultimately show ?thesis unfolding wfP_def by(rule wf_subset)\nqed\n\nlemma strict_prefix_setD:\n  \"strict_prefix xs ys \\<Longrightarrow> set xs \\<subseteq> set ys\"\n  by(auto simp add: strict_prefix_def prefix_def)\n\nsubsubsection \\<open>List of a given length\\<close>\n\ninductive_set nlists :: \"'a set \\<Rightarrow> nat \\<Rightarrow> 'a list set\" for A n\nwhere nlists: \"\\<lbrakk> set xs \\<subseteq> A; length xs = n \\<rbrakk> \\<Longrightarrow> xs \\<in> nlists A n\"\nhide_fact (open) nlists\n\nlemma nlists_alt_def: \"nlists A n = {xs. set xs \\<subseteq> A \\<and> length xs = n}\"\nby(auto simp add: nlists.simps)\n\nlemma nlists_empty: \"nlists {} n = (if n = 0 then {[]} else {})\"\nby(auto simp add: nlists_alt_def)\n\nlemma nlists_empty_gt0 [simp]: \"n > 0 \\<Longrightarrow> nlists {} n = {}\"\nby(simp add: nlists_empty)\n\nlemma nlists_0 [simp]: \"nlists A 0 = {[]}\"\nby(auto simp add: nlists_alt_def)\n\n\n\nlemma Nil_in_nlists [simp]: \"[] \\<in> nlists A n \\<longleftrightarrow> n = 0\"\nby(auto simp add: nlists_alt_def)\n\nlemma Cons_in_nlists_iff: \"x # xs \\<in> nlists A n \\<longleftrightarrow> (\\<exists>n'. n = Suc n' \\<and> x \\<in> A \\<and> xs \\<in> nlists A n')\"\nby(cases n) simp_all\n\nlemma in_nlists_Suc_iff: \"xs \\<in> nlists A (Suc n) \\<longleftrightarrow> (\\<exists>x xs'. xs = x # xs' \\<and> x \\<in> A \\<and> xs' \\<in> nlists A n)\"\nby(cases xs) simp_all\n\nlemma nlists_Suc: \"nlists A (Suc n) = (\\<Union>x\\<in>A. (#) x ` nlists A n)\"\nby(auto 4 3 simp add: in_nlists_Suc_iff intro: rev_image_eqI)\n\nlemma replicate_in_nlists [simp, intro]: \"x \\<in> A \\<Longrightarrow> replicate n x \\<in> nlists A n\"\nby(simp add: nlists_alt_def set_replicate_conv_if)\n\nlemma nlists_eq_empty_iff [simp]: \"nlists A n = {} \\<longleftrightarrow> n > 0 \\<and> A = {}\"\nusing replicate_in_nlists by(cases n)(auto)\n\nlemma finite_nlists [simp]: \"finite A \\<Longrightarrow> finite (nlists A n)\"\nby(induction n)(simp_all add: nlists_Suc)\n\nlemma finite_nlistsD: \n  assumes \"finite (nlists A n)\"\n  shows \"finite A \\<or> n = 0\"\nproof(rule disjCI)\n  assume \"n \\<noteq> 0\"\n  then obtain n' where n: \"n = Suc n'\" by(cases n)auto\n  then have \"A = hd ` nlists A n\" by(auto 4 4 simp add: nlists_Suc intro: rev_image_eqI rev_bexI)\n  also have \"finite \\<dots>\" using assms ..\n  finally show \"finite A\" .\nqed\n\nlemma finite_nlists_iff: \"finite (nlists A n) \\<longleftrightarrow> finite A \\<or> n = 0\"\nby(auto dest: finite_nlistsD)\n\nlemma card_nlists: \"card (nlists A n) = card A ^ n\"\nproof(induction n)\n  case (Suc n)\n  have \"card (\\<Union>x\\<in>A. (#) x ` nlists A n) = card A * card (nlists A n)\"\n  proof(cases \"finite A\")\n    case True\n    then show ?thesis by(subst card_UN_disjoint)(auto simp add: card_image inj_on_def)\n  next\n    case False\n    hence \"\\<not> finite (\\<Union>x\\<in>A. (#) x ` nlists A n)\"\n      unfolding nlists_Suc[symmetric] by(auto dest: finite_nlistsD)\n    then show ?thesis using False by simp\n  qed\n  then show ?case using Suc.IH by(simp add: nlists_Suc)\nqed simp\n\nlemma in_nlists_UNIV: \"xs \\<in> nlists UNIV n \\<longleftrightarrow> length xs = n\"\nby(simp add: nlists_alt_def)\n\nsubsubsection \\<open> The type of lists of a given length \\<close>\n\ntypedef (overloaded) ('a, 'b :: len0) nlist = \"nlists (UNIV :: 'a set) (LENGTH('b))\"\nproof\n  show \"replicate LENGTH('b) undefined \\<in> ?nlist\" by simp\nqed\n\nsetup_lifting type_definition_nlist\n\nsubsection \\<open>Streams and infinite lists\\<close>\n\nprimrec sprefix :: \"'a list \\<Rightarrow> 'a stream \\<Rightarrow> bool\" where\n  sprefix_Nil: \"sprefix [] ys = True\"\n| sprefix_Cons: \"sprefix (x # xs) ys \\<longleftrightarrow> x = shd ys \\<and> sprefix xs (stl ys)\"\n\nlemma sprefix_append: \"sprefix (xs @ ys) zs \\<longleftrightarrow> sprefix xs zs \\<and> sprefix ys (sdrop (length xs) zs)\"\nby(induct xs arbitrary: zs) simp_all\n\nlemma sprefix_stake_same [simp]: \"sprefix (stake n xs) xs\"\nby(induct n arbitrary: xs) simp_all\n\nlemma sprefix_same_imp_eq:\n  assumes \"sprefix xs ys\" \"sprefix xs' ys\"\n  and \"length xs = length xs'\"\n  shows \"xs = xs'\"\nusing assms(3,1,2) by(induct arbitrary: ys rule: list_induct2) auto\n\nlemma sprefix_shift_same [simp]:\n  \"sprefix xs (xs @- ys)\"\nby(induct xs) simp_all\n\nlemma sprefix_shift [simp]:\n  \"length xs \\<le> length ys \\<Longrightarrow> sprefix xs (ys @- zs) \\<longleftrightarrow> prefix xs ys\"\nby(induct xs arbitrary: ys)(simp, case_tac ys, auto)\n\nlemma prefixeq_stake2 [simp]: \"prefix xs (stake n ys) \\<longleftrightarrow> length xs \\<le> n \\<and> sprefix xs ys\"\nproof(induct xs arbitrary: n ys)\n  case (Cons x xs)\n  thus ?case by(cases ys n rule: stream.exhaust[case_product nat.exhaust]) auto\nqed simp\n\nlemma tlength_eq_infinity_iff: \"tlength xs = \\<infinity> \\<longleftrightarrow> \\<not> tfinite xs\"\nincluding tllist.lifting by transfer(simp add: llength_eq_infty_conv_lfinite)\n\nsubsection \\<open>Monomorphic monads\\<close>\n\ncontext includes lifting_syntax begin\nlocal_setup \\<open>Local_Theory.map_background_naming (Name_Space.mandatory_path \"monad\")\\<close>\n\ndefinition bind_option :: \"'m fail \\<Rightarrow> 'a option \\<Rightarrow> ('a \\<Rightarrow> 'm) \\<Rightarrow> 'm\"\nwhere \"bind_option fail x f = (case x of None \\<Rightarrow> fail | Some x' \\<Rightarrow> f x')\" for fail\n\nsimps_of_case bind_option_simps [simp]: bind_option_def\n\nlemma bind_option_parametric [transfer_rule]:\n  \"(M ===> rel_option B ===> (B ===> M) ===> M) bind_option bind_option\"\nunfolding bind_option_def by transfer_prover\n\nlemma bind_option_K:\n  \"\\<And>monad. (x = None \\<Longrightarrow> m = fail) \\<Longrightarrow> bind_option fail x (\\<lambda>_. m) = m\"\nby(cases x) simp_all\n\nend\n\nlemma bind_option_option [simp]: \"monad.bind_option None = Option.bind\"\nby(simp add: monad.bind_option_def fun_eq_iff split: option.split)\n\ncontext monad_fail_hom begin\n\nlemma hom_bind_option: \"h (monad.bind_option fail1 x f) = monad.bind_option fail2 x (h \\<circ> f)\"\nby(cases x)(simp_all)\n\nend\n\nlemma bind_option_set [simp]: \"monad.bind_option fail_set = (\\<lambda>x f. \\<Union> (f ` set_option x))\"\nby(simp add: monad.bind_option_def fun_eq_iff split: option.split)\n\nlemma run_bind_option_stateT [simp]:\n  \"\\<And>more. run_state (monad.bind_option (fail_state fail) x f) s = \n  monad.bind_option fail x (\\<lambda>y. run_state (f y) s)\"\nby(cases x) simp_all\n\nlemma run_bind_option_envT [simp]:\n  \"\\<And>more. run_env (monad.bind_option (fail_env fail) x f) s = \n  monad.bind_option fail x (\\<lambda>y. run_env (f y) s)\"\nby(cases x) simp_all\n\n\nsubsection \\<open>Measures\\<close>\n\ndeclare sets_restrict_space_count_space [measurable_cong]\n\nlemma (in sigma_algebra) sets_Collect_countable_Ex1:\n  \"(\\<And>i :: 'i :: countable. {x \\<in> \\<Omega>. P i x} \\<in> M) \\<Longrightarrow> {x \\<in> \\<Omega>. \\<exists>!i. P i x} \\<in> M\"\nusing sets_Collect_countable_Ex1'[of \"UNIV :: 'i set\"] by simp\n\nlemma pred_countable_Ex1 [measurable]:\n  \"(\\<And>i :: _ :: countable. Measurable.pred M (\\<lambda>x. P i x))\n  \\<Longrightarrow> Measurable.pred M (\\<lambda>x. \\<exists>!i. P i x)\"\nunfolding pred_def by(rule sets.sets_Collect_countable_Ex1)\n\nlemma measurable_snd_count_space [measurable]: \n  \"A \\<subseteq> B \\<Longrightarrow> snd \\<in> measurable (M1 \\<Otimes>\\<^sub>M count_space A) (count_space B)\"\nby(auto simp add: measurable_def space_pair_measure snd_vimage_eq_Times Times_Int_Times)\n\nlemma integrable_scale_measure [simp]:\n  \"\\<lbrakk> integrable M f; r < \\<top> \\<rbrakk> \\<Longrightarrow> integrable (scale_measure r M) f\" \n  for f :: \"'a \\<Rightarrow> 'b::{banach, second_countable_topology}\"\n  by(auto simp add: integrable_iff_bounded nn_integral_scale_measure ennreal_mult_less_top)\n\nlemma integral_scale_measure:\n  assumes \"integrable M f\" \"r < \\<top>\"\n  shows \"integral\\<^sup>L (scale_measure r M) f = enn2real r * integral\\<^sup>L M f\"\n  using assms\n  apply(subst (1 2) real_lebesgue_integral_def)\n    apply(simp_all add: nn_integral_scale_measure ennreal_enn2real_if)\n  by(auto simp add: ennreal_mult_less_top ennreal_less_top_iff ennreal_mult_eq_top_iff enn2real_mult right_diff_distrib elim!: integrableE)\n\nsubsection \\<open>Sequence space\\<close>\n\nlemma (in sequence_space) nn_integral_split:\n  assumes f[measurable]: \"f \\<in> borel_measurable S\"\n  shows \"(\\<integral>\\<^sup>+\\<omega>. f \\<omega> \\<partial>S) = (\\<integral>\\<^sup>+\\<omega>. (\\<integral>\\<^sup>+\\<omega>'. f (comb_seq i \\<omega> \\<omega>') \\<partial>S) \\<partial>S)\"\nby (subst PiM_comb_seq[symmetric, where i=i])\n   (simp add: nn_integral_distr P.nn_integral_fst[symmetric])\n\nlemma (in sequence_space) prob_Collect_split:\n  assumes f[measurable]: \"{x\\<in>space S. P x} \\<in> sets S\"\n  shows \"\\<P>(x in S. P x) = (\\<integral>\\<^sup>+x. \\<P>(x' in S. P (comb_seq i x x')) \\<partial>S)\"\nproof -\n  have \"\\<P>(x in S. P x) = (\\<integral>\\<^sup>+x. (\\<integral>\\<^sup>+x'. indicator {x\\<in>space S. P x} (comb_seq i x x') \\<partial>S) \\<partial>S)\"\n    using nn_integral_split[of \"indicator {x\\<in>space S. P x}\"] by (auto simp: emeasure_eq_measure)\n  also have \"\\<dots> = (\\<integral>\\<^sup>+x. \\<P>(x' in S. P (comb_seq i x x')) \\<partial>S)\"\n    by (intro nn_integral_cong) (auto simp: emeasure_eq_measure nn_integral_indicator_map)\n  finally show ?thesis .\nqed\n\nsubsection \\<open>Probability mass functions\\<close>\n\nlemma measure_map_pmf_conv_distr:\n  \"measure_pmf (map_pmf f p) = distr (measure_pmf p) (count_space UNIV) f\"\nby(fact map_pmf_rep_eq)\n\nabbreviation coin_pmf :: \"bool pmf\" where \"coin_pmf \\<equiv> pmf_of_set UNIV\"\n\ntext \\<open>The rule @{thm [source] rel_pmf_bindI} is not complete as a program logic.\\<close>\nnotepad begin\n  define x where \"x = pmf_of_set {True, False}\"\n  define y where \"y = pmf_of_set {True, False}\"\n  define f where \"f x = pmf_of_set {True, False}\" for x :: bool\n  define g :: \"bool \\<Rightarrow> bool pmf\" where \"g = return_pmf\"\n  define P :: \"bool \\<Rightarrow> bool \\<Rightarrow> bool\" where \"P = (=)\"\n  have \"rel_pmf P (bind_pmf x f) (bind_pmf y g)\"\n    by(simp add: P_def f_def[abs_def] g_def y_def bind_return_pmf' pmf.rel_eq)\n  have \"\\<not> R x y\" if \"\\<And>x y. R x y \\<Longrightarrow> rel_pmf P (f x) (g y)\" for R x y\n    \\<comment> \\<open>Only the empty relation satisfies @{thm [source] rel_pmf_bindI}'s second premise.\\<close>\n  proof\n    assume \"R x y\"\n    hence \"rel_pmf P (f x) (g y)\" by(rule that)\n    thus False by(auto simp add: P_def f_def g_def rel_pmf_return_pmf2)\n  qed\n  define R where \"R x y = False\" for x y :: bool\n  have \"\\<not> rel_pmf R x y\" by(simp add: R_def[abs_def])\nend\n\nlemma pred_rel_pmf:\n  \"\\<lbrakk> pred_pmf P p; rel_pmf R p q \\<rbrakk> \\<Longrightarrow> pred_pmf (Imagep R P) q\"\nunfolding pred_pmf_def\napply(rule ballI)\napply(unfold rel_pmf.simps)\napply(erule exE conjE)+\napply hypsubst\napply(unfold pmf.set_map)\napply(erule imageE, hypsubst)\napply(drule bspec)\n apply(erule rev_image_eqI)\n apply(rule refl)\napply(erule Imagep.intros)\napply(erule allE)+\n apply(erule mp)\napply(unfold prod.collapse)\napply assumption\ndone\n\nlemma pmf_rel_mono': \"\\<lbrakk> rel_pmf P x y; P \\<le> Q \\<rbrakk> \\<Longrightarrow> rel_pmf Q x y\"\nby(drule pmf.rel_mono) (auto)\n\nlemma rel_pmf_eqI [simp]: \"rel_pmf (=) x x\"\nby(simp add: pmf.rel_eq)\n\nlemma rel_pmf_bind_reflI:\n  \"(\\<And>x. x \\<in> set_pmf p \\<Longrightarrow> rel_pmf R (f x) (g x))\n  \\<Longrightarrow> rel_pmf R (bind_pmf p f) (bind_pmf p g)\"\nby(rule rel_pmf_bindI[where R=\"\\<lambda>x y. x = y \\<and> x \\<in> set_pmf p\"])(auto intro: rel_pmf_reflI)\n\nlemma pmf_pred_mono_strong:\n  \"\\<lbrakk> pred_pmf P p; \\<And>a. \\<lbrakk> a \\<in> set_pmf p; P a \\<rbrakk> \\<Longrightarrow> P' a \\<rbrakk> \\<Longrightarrow> pred_pmf P' p\"\nby(simp add: pred_pmf_def)\n\nlemma rel_pmf_restrict_relpI [intro?]:\n  \"\\<lbrakk> rel_pmf R x y; pred_pmf P x; pred_pmf Q y \\<rbrakk> \\<Longrightarrow> rel_pmf (R \\<upharpoonleft> P \\<otimes> Q) x y\"\nby(erule pmf.rel_mono_strong)(simp add: pred_pmf_def)\n\nlemma rel_pmf_restrict_relpE [elim?]:\n  assumes \"rel_pmf (R \\<upharpoonleft> P \\<otimes> Q) x y\"\n  obtains \"rel_pmf R x y\" \"pred_pmf P x\" \"pred_pmf Q y\"\nproof\n  show \"rel_pmf R x y\" using assms by(auto elim!: pmf.rel_mono_strong)\n  have \"pred_pmf (Domainp (R \\<upharpoonleft> P \\<otimes> Q)) x\" using assms by(fold pmf.Domainp_rel) blast\n  then show \"pred_pmf P x\" by(rule pmf_pred_mono_strong)(blast dest!: restrict_relp_DomainpD)\n  have \"pred_pmf (Domainp (R \\<upharpoonleft> P \\<otimes> Q)\\<inverse>\\<inverse>) y\" using assms\n    by(fold pmf.Domainp_rel)(auto simp only: pmf.rel_conversep Domainp_conversep)\n  then show \"pred_pmf Q y\" by(rule pmf_pred_mono_strong)(auto dest!: restrict_relp_DomainpD)\nqed\n\nlemma rel_pmf_restrict_relp_iff:\n  \"rel_pmf (R \\<upharpoonleft> P \\<otimes> Q) x y \\<longleftrightarrow> rel_pmf R x y \\<and> pred_pmf P x \\<and> pred_pmf Q y\"\nby(blast intro: rel_pmf_restrict_relpI elim: rel_pmf_restrict_relpE)\n\nlemma rel_pmf_OO_trans [trans]:\n  \"\\<lbrakk> rel_pmf R p q; rel_pmf S q r \\<rbrakk> \\<Longrightarrow> rel_pmf (R OO S) p r\"\nunfolding pmf.rel_compp by blast\n\nlemma pmf_pred_map [simp]: \"pred_pmf P (map_pmf f p) = pred_pmf (P \\<circ> f) p\"\nby(simp add: pred_pmf_def)\n\nlemma pred_pmf_bind [simp]: \"pred_pmf P (bind_pmf p f) = pred_pmf (pred_pmf P \\<circ> f) p\"\nby(simp add: pred_pmf_def)\n\nlemma pred_pmf_return [simp]: \"pred_pmf P (return_pmf x) = P x\"\nby(simp add: pred_pmf_def)\n\nlemma pred_pmf_of_set [simp]: \"\\<lbrakk> finite A; A \\<noteq> {} \\<rbrakk> \\<Longrightarrow> pred_pmf P (pmf_of_set A) = Ball A P\"\nby(simp add: pred_pmf_def)\n\nlemma pred_pmf_of_multiset [simp]: \"M \\<noteq> {#} \\<Longrightarrow> pred_pmf P (pmf_of_multiset M) = Ball (set_mset M) P\"\nby(simp add: pred_pmf_def)\n\nlemma pred_pmf_cond [simp]:\n  \"set_pmf p \\<inter> A \\<noteq> {} \\<Longrightarrow> pred_pmf P (cond_pmf p A) = pred_pmf (\\<lambda>x. x \\<in> A \\<longrightarrow> P x) p\"\nby(auto simp add: pred_pmf_def)\n\nlemma pred_pmf_pair [simp]:\n  \"pred_pmf P (pair_pmf p q) = pred_pmf (\\<lambda>x. pred_pmf (P \\<circ> Pair x) q) p\"\nby(simp add: pred_pmf_def)\n\nlemma pred_pmf_join [simp]: \"pred_pmf P (join_pmf p) = pred_pmf (pred_pmf P) p\"\nby(simp add: pred_pmf_def)\n\nlemma pred_pmf_bernoulli [simp]: \"\\<lbrakk> 0 < p; p < 1 \\<rbrakk> \\<Longrightarrow> pred_pmf P (bernoulli_pmf p) = All P\"\nby(simp add: pred_pmf_def)\n\nlemma pred_pmf_geometric [simp]: \"\\<lbrakk> 0 < p; p < 1 \\<rbrakk> \\<Longrightarrow> pred_pmf P (geometric_pmf p) = All P\"\nby(simp add: pred_pmf_def set_pmf_geometric)\n\nlemma pred_pmf_poisson [simp]: \"0 < rate \\<Longrightarrow> pred_pmf P (poisson_pmf rate) = All P\"\nby(simp add: pred_pmf_def)\n\nlemma pmf_rel_map_restrict_relp: \n  shows pmf_rel_map_restrict_relp1: \"rel_pmf (R \\<upharpoonleft> P \\<otimes> Q) (map_pmf f p) = rel_pmf (R \\<circ> f \\<upharpoonleft> P \\<circ> f \\<otimes> Q) p\"\n  and pmf_rel_map_restrict_relp2: \"rel_pmf (R \\<upharpoonleft> P \\<otimes> Q) p (map_pmf g q) = rel_pmf ((\\<lambda>x. R x \\<circ> g) \\<upharpoonleft> P \\<otimes> Q \\<circ> g) p q\"\nby(simp_all add: pmf.rel_map restrict_relp_def fun_eq_iff)\n\nlemma pred_pmf_conj [simp]: \"pred_pmf (\\<lambda>x. P x \\<and> Q x) = (\\<lambda>x. pred_pmf P x \\<and> pred_pmf Q x)\"\nby(auto simp add: pred_pmf_def)\n\nlemma pred_pmf_top [simp]:\n  \"pred_pmf (\\<lambda>_. True) = (\\<lambda>_. True)\"\nby(simp add: pred_pmf_def)\n\nlemma rel_pmf_of_setI:\n  assumes A: \"A \\<noteq> {}\" \"finite A\"\n  and B: \"B \\<noteq> {}\" \"finite B\"\n  and card: \"\\<And>X. X \\<subseteq> A \\<Longrightarrow> card B * card X \\<le> card A * card {y\\<in>B. \\<exists>x\\<in>X. R x y}\"\n  shows \"rel_pmf R (pmf_of_set A) (pmf_of_set B)\"\napply(rule rel_pmf_measureI)\nusing assms\napply(clarsimp simp add: measure_pmf_of_set card_gt_0_iff field_simps of_nat_mult[symmetric] simp del: of_nat_mult)\napply(subst mult.commute)\napply(erule meta_allE)\napply(erule meta_impE)\n prefer 2\n apply(erule order_trans)\napply(auto simp add: card_gt_0_iff intro: card_mono)\ndone\n\nconsts rel_witness_pmf :: \"('a \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow> 'a pmf \\<times> 'b pmf \\<Rightarrow> ('a \\<times> 'b) pmf\"\nspecification (rel_witness_pmf)\n  set_rel_witness_pmf': \"rel_pmf A (fst xy) (snd xy) \\<Longrightarrow> set_pmf (rel_witness_pmf A xy) \\<subseteq> {(a, b). A a b}\"\n  map1_rel_witness_pmf': \"rel_pmf A (fst xy) (snd xy) \\<Longrightarrow> map_pmf fst (rel_witness_pmf A xy) = fst xy\"\n  map2_rel_witness_pmf': \"rel_pmf A (fst xy) (snd xy) \\<Longrightarrow> map_pmf snd (rel_witness_pmf A xy) = snd xy\"\n  apply(fold all_conj_distrib imp_conjR)\n  apply(rule choice allI)+\n  apply(unfold pmf.in_rel)\n  by blast\n\nlemmas set_rel_witness_pmf = set_rel_witness_pmf'[of _ \"(x, y)\" for x y, simplified]\nlemmas map1_rel_witness_pmf = map1_rel_witness_pmf'[of _ \"(x, y)\" for x y, simplified]\nlemmas map2_rel_witness_pmf = map2_rel_witness_pmf'[of _ \"(x, y)\" for x y, simplified]\nlemmas rel_witness_pmf = set_rel_witness_pmf map1_rel_witness_pmf map2_rel_witness_pmf\n\nlemma rel_witness_pmf1:\n  assumes \"rel_pmf A p q\" \n  shows \"rel_pmf (\\<lambda>a (a', b). a = a' \\<and> A a' b) p (rel_witness_pmf A (p, q))\"\n  using map1_rel_witness_pmf[OF assms, symmetric]\n  unfolding pmf.rel_eq[symmetric] pmf.rel_map\n  by(rule pmf.rel_mono_strong)(auto dest: set_rel_witness_pmf[OF assms, THEN subsetD])\n\nlemma rel_witness_pmf2:\n  assumes \"rel_pmf A p q\" \n  shows \"rel_pmf (\\<lambda>(a, b') b. b = b' \\<and> A a b') (rel_witness_pmf A (p, q)) q\"\n  using map2_rel_witness_pmf[OF assms]\n  unfolding pmf.rel_eq[symmetric] pmf.rel_map\n  by(rule pmf.rel_mono_strong)(auto dest: set_rel_witness_pmf[OF assms, THEN subsetD])\n\nlemma cond_pmf_of_set:\n  assumes fin: \"finite A\" and nonempty: \"A \\<inter> B \\<noteq> {}\"\n  shows \"cond_pmf (pmf_of_set A) B = pmf_of_set (A \\<inter> B)\" (is \"?lhs = ?rhs\")\nproof(rule pmf_eqI)\n  from nonempty have A: \"A \\<noteq> {}\" by auto\n  show \"pmf ?lhs x = pmf ?rhs x\" for x\n    by(subst pmf_cond; clarsimp simp add: fin A nonempty measure_pmf_of_set split: split_indicator)\nqed\n\nlemma pair_pmf_of_set:\n  assumes A: \"finite A\" \"A \\<noteq> {}\"\n    and B: \"finite B\" \"B \\<noteq> {}\"\n  shows \"pair_pmf (pmf_of_set A) (pmf_of_set B) = pmf_of_set (A \\<times> B)\"\n  by(rule pmf_eqI)(clarsimp simp add: pmf_pair assms split: split_indicator)\n\nlemma emeasure_cond_pmf:\n  fixes p A\n  defines \"q \\<equiv> cond_pmf p A\"\n  assumes \"set_pmf p \\<inter> A \\<noteq> {}\"\n  shows \"emeasure (measure_pmf q) B = emeasure (measure_pmf p) (A \\<inter> B) / emeasure (measure_pmf p) A\"\nproof -\n  note [transfer_rule] = cond_pmf.transfer[OF assms(2), folded q_def]\n  interpret pmf_as_measure .\n  show ?thesis by transfer simp\nqed\n\nlemma measure_cond_pmf:\n  \"measure (measure_pmf (cond_pmf p A)) B = measure (measure_pmf p) (A \\<inter> B) / measure (measure_pmf p) A\"\n  if \"set_pmf p \\<inter> A \\<noteq> {}\"\n  using emeasure_cond_pmf[OF that, of B] that \n  by(auto simp add: measure_pmf.emeasure_eq_measure measure_pmf_posI divide_ennreal)\n\nlemma emeasure_measure_pmf_zero_iff: \"emeasure (measure_pmf p) s = 0 \\<longleftrightarrow> set_pmf p \\<inter> s = {}\" (is \"?lhs = ?rhs\")\nproof -\n  have \"?lhs \\<longleftrightarrow> (AE x in measure_pmf p. x \\<notin> s)\"\n    by(subst AE_iff_measurable)(auto)\n  also have \"\\<dots> = ?rhs\" by(auto simp add: AE_measure_pmf_iff)\n  finally show ?thesis .\nqed\n\nsubsection \\<open>Subprobability mass functions\\<close>\n\nlemma ord_spmf_return_spmf1: \"ord_spmf R (return_spmf x) p \\<longleftrightarrow> lossless_spmf p \\<and> (\\<forall>y\\<in>set_spmf p. R x y)\"\nby(auto simp add: rel_pmf_return_pmf1 ord_option.simps in_set_spmf lossless_iff_set_pmf_None Ball_def) (metis option.exhaust)\n\nlemma ord_spmf_conv:\n  \"ord_spmf R = rel_spmf R OO ord_spmf (=)\"\napply(subst pmf.rel_compp[symmetric])\napply(rule arg_cong[where f=\"rel_pmf\"])  \napply(rule ext)+\napply(auto elim!: ord_option.cases option.rel_cases intro: option.rel_intros)\ndone\n\nlemma ord_spmf_expand:\n  \"NO_MATCH (=) R \\<Longrightarrow> ord_spmf R = rel_spmf R OO ord_spmf (=)\"\nby(rule ord_spmf_conv)\n\nlemma ord_spmf_eqD_measure: \"ord_spmf (=) p q \\<Longrightarrow> measure (measure_spmf p) A \\<le> measure (measure_spmf q) A\"\nby(drule ord_spmf_eqD_measure_spmf)(simp add: le_measure measure_spmf.emeasure_eq_measure)\n\nlemma ord_spmf_measureD:\n  assumes \"ord_spmf R p q\"\n  shows \"measure (measure_spmf p) A \\<le> measure (measure_spmf q) {y. \\<exists>x\\<in>A. R x y}\"\n    (is \"?lhs \\<le> ?rhs\")\nproof -\n  from assms obtain p' where *: \"rel_spmf R p p'\" and **: \"ord_spmf (=) p' q\"\n    by(auto simp add: ord_spmf_expand)\n  have \"?lhs \\<le> measure (measure_spmf p') {y. \\<exists>x\\<in>A. R x y}\" using * by(rule rel_spmf_measureD)\n  also have \"\\<dots> \\<le> ?rhs\" using ** by(rule ord_spmf_eqD_measure)\n  finally show ?thesis .\nqed\n\nlemma ord_spmf_bind_pmfI1:\n  \"(\\<And>x. x \\<in> set_pmf p \\<Longrightarrow> ord_spmf R (f x) q) \\<Longrightarrow> ord_spmf R (bind_pmf p f) q\"\n  apply(rewrite at \"ord_spmf _ _ \\<hole>\" bind_return_pmf[symmetric, where f=\"\\<lambda>_ :: unit. q\"])\n  apply(rule rel_pmf_bindI[where R=\"\\<lambda>x y. x \\<in> set_pmf p\"])\n  apply(simp_all add: rel_pmf_return_pmf2)\n  done\n  \nlemma ord_spmf_bind_spmfI1:\n  \"(\\<And>x. x \\<in> set_spmf p \\<Longrightarrow> ord_spmf R (f x) q) \\<Longrightarrow> ord_spmf R (bind_spmf p f) q\"\nunfolding bind_spmf_def by(rule ord_spmf_bind_pmfI1)(auto split: option.split simp add: in_set_spmf)\n\nlemma spmf_of_set_empty: \"spmf_of_set {} = return_pmf None\"\nby(simp add: spmf_of_set_def)\n\nlemma rel_spmf_of_setI:\n  assumes card: \"\\<And>X. X \\<subseteq> A \\<Longrightarrow> card B * card X \\<le> card A * card {y\\<in>B. \\<exists>x\\<in>X. R x y}\"\n  and eq: \"(finite A \\<and> A \\<noteq> {}) \\<longleftrightarrow> (finite B \\<and> B \\<noteq> {})\"\n  shows \"rel_spmf R (spmf_of_set A) (spmf_of_set B)\"\nusing eq by(clarsimp simp add: spmf_of_set_def card rel_pmf_of_setI simp del: spmf_of_pmf_pmf_of_set cong: conj_cong)\n\nlemmas map_bind_spmf = map_spmf_bind_spmf\n\nlemma nn_integral_measure_spmf_conv_measure_pmf:\n  assumes [measurable]: \"f \\<in> borel_measurable (count_space UNIV)\"\n  shows \"nn_integral (measure_spmf p) f = nn_integral (restrict_space (measure_pmf p) (range Some)) (f \\<circ> the)\"\nby(simp add: measure_spmf_def nn_integral_distr o_def)\n\nlemma nn_integral_spmf_neq_infinity: \"(\\<integral>\\<^sup>+ x. spmf p x \\<partial>count_space UNIV) \\<noteq> \\<infinity>\"\nusing nn_integral_measure_spmf[where f=\"\\<lambda>_. 1\", of p, symmetric] by simp\n\nlemma return_pmf_bind_option:\n  \"return_pmf (Option.bind x f) = bind_spmf (return_pmf x) (return_pmf \\<circ> f)\"\nby(cases x) simp_all\n\nlemma rel_spmf_pos_distr: \"rel_spmf A OO rel_spmf B \\<le> rel_spmf (A OO B)\"\nunfolding option.rel_compp pmf.rel_compp ..\n\nlemma rel_spmf_OO_trans [trans]:\n  \"\\<lbrakk> rel_spmf R p q; rel_spmf S q r \\<rbrakk> \\<Longrightarrow> rel_spmf (R OO S) p r\"\nby(rule rel_spmf_pos_distr[THEN predicate2D]) auto\n\nlemma map_spmf_eq_map_spmf_iff: \"map_spmf f p = map_spmf g q \\<longleftrightarrow> rel_spmf (\\<lambda>x y. f x = g y) p q\"\nby(simp add: spmf_rel_eq[symmetric] spmf_rel_map)\n\nlemma map_spmf_eq_map_spmfI: \"rel_spmf (\\<lambda>x y. f x = g y) p q \\<Longrightarrow> map_spmf f p = map_spmf g q\"\nby(simp add: map_spmf_eq_map_spmf_iff)\n\nlemma spmf_rel_mono_strong:\n  \"\\<lbrakk>rel_spmf A f g; \\<And>x y. \\<lbrakk> x \\<in> set_spmf f; y \\<in> set_spmf g; A x y \\<rbrakk> \\<Longrightarrow> B x y \\<rbrakk> \\<Longrightarrow> rel_spmf B f g\"\napply(erule pmf.rel_mono_strong)\napply(erule option.rel_mono_strong)\nby(clarsimp simp add: in_set_spmf)\n\nlemma set_spmf_eq_empty: \"set_spmf p = {} \\<longleftrightarrow> p = return_pmf None\"\nby auto (metis restrict_spmf_empty restrict_spmf_trivial)\n\n\nlemma measure_pair_spmf_times:\n  \"measure (measure_spmf (pair_spmf p q)) (A \\<times> B) = measure (measure_spmf p) A * measure (measure_spmf q) B\"\nproof -\n  have \"emeasure (measure_spmf (pair_spmf p q)) (A \\<times> B) = (\\<integral>\\<^sup>+ x. ennreal (spmf (pair_spmf p q) x) * indicator (A \\<times> B) x \\<partial>count_space UNIV)\"\n    by(simp add: nn_integral_spmf[symmetric] nn_integral_count_space_indicator)\n  also have \"\\<dots> = (\\<integral>\\<^sup>+ x. (\\<integral>\\<^sup>+ y. (ennreal (spmf p x) * indicator A x) * (ennreal (spmf q y) * indicator B y) \\<partial>count_space UNIV) \\<partial>count_space UNIV)\"\n    by(subst nn_integral_fst_count_space[symmetric])(auto intro!: nn_integral_cong split: split_indicator simp add: ennreal_mult)\n  also have \"\\<dots> = (\\<integral>\\<^sup>+ x. ennreal (spmf p x) * indicator A x * emeasure (measure_spmf q) B \\<partial>count_space UNIV)\"\n    by(simp add: nn_integral_cmult nn_integral_spmf[symmetric] nn_integral_count_space_indicator)\n  also have \"\\<dots> = emeasure (measure_spmf p) A * emeasure (measure_spmf q) B\"\n    by(simp add: nn_integral_multc)(simp add: nn_integral_spmf[symmetric] nn_integral_count_space_indicator)\n  finally show ?thesis by(simp add: measure_spmf.emeasure_eq_measure ennreal_mult[symmetric])\nqed\n\nlemma lossless_spmfD_set_spmf_nonempty: \"lossless_spmf p \\<Longrightarrow> set_spmf p \\<noteq> {}\"\nusing set_pmf_not_empty[of p] by(auto simp add: set_spmf_def bind_UNION lossless_iff_set_pmf_None)\n\nlemma set_spmf_return_pmf: \"set_spmf (return_pmf x) = set_option x\"\nby(cases x) simp_all\n\nlemma bind_spmf_pmf_assoc: \"bind_spmf (bind_pmf p f) g = bind_pmf p (\\<lambda>x. bind_spmf (f x) g)\"\nby(simp add: bind_spmf_def bind_assoc_pmf)\n\nlemma bind_spmf_of_set:  \"\\<lbrakk> finite A; A \\<noteq> {} \\<rbrakk> \\<Longrightarrow> bind_spmf (spmf_of_set A) f = bind_pmf (pmf_of_set A) f\"\nby(simp add: spmf_of_set_def del: spmf_of_pmf_pmf_of_set)\n\nlemma bind_spmf_map_pmf:\n  \"bind_spmf (map_pmf f p) g = bind_pmf p (\\<lambda>x. bind_spmf (return_pmf (f x)) g)\"\nby(simp add: map_pmf_def bind_spmf_def bind_assoc_pmf)\n\nlemma rel_spmf_eqI [simp]: \"rel_spmf (=) x x\"\nby(simp add: option.rel_eq)\n\nlemma set_spmf_map_pmf: \"set_spmf (map_pmf f p) = (\\<Union>x\\<in>set_pmf p. set_option (f x))\" (* Move up *)\nby(simp add: set_spmf_def bind_UNION)\n\nlemma ord_spmf_return_spmf [simp]: \"ord_spmf (=) (return_spmf x) p \\<longleftrightarrow> p = return_spmf x\"\nproof -\n  have \"p = return_spmf x \\<Longrightarrow> ord_spmf (=) (return_spmf x) p\" by simp\n  thus ?thesis\n    by (metis (no_types) ord_option_eq_simps(2) rel_pmf_return_pmf1 rel_pmf_return_pmf2 spmf.leq_antisym)\nqed\n\ndeclare\n  set_bind_spmf [simp]\n  set_spmf_return_pmf [simp]\n\nlemma bind_spmf_pmf_commute:\n  \"bind_spmf p (\\<lambda>x. bind_pmf q (f x)) = bind_pmf q (\\<lambda>y. bind_spmf p (\\<lambda>x. f x y))\"\nunfolding bind_spmf_def \nby(subst bind_commute_pmf)(auto intro: bind_pmf_cong[OF refl] split: option.split)\n\nlemma return_pmf_map_option_conv_bind:\n  \"return_pmf (map_option f x) = bind_spmf (return_pmf x) (return_spmf \\<circ> f)\"\nby(cases x) simp_all\n\nlemma lossless_return_pmf_iff [simp]: \"lossless_spmf (return_pmf x) \\<longleftrightarrow> x \\<noteq> None\"\nby(cases x) simp_all\n\nlemma lossless_map_pmf: \"lossless_spmf (map_pmf f p) \\<longleftrightarrow> (\\<forall>x \\<in> set_pmf p. f x \\<noteq> None)\"\nusing image_iff by(fastforce simp add: lossless_iff_set_pmf_None)\n\nlemma bind_pmf_spmf_assoc:\n  \"g None = return_pmf None\n  \\<Longrightarrow> bind_pmf (bind_spmf p f) g = bind_spmf p (\\<lambda>x. bind_pmf (f x) g)\"\nby(auto simp add: bind_spmf_def bind_assoc_pmf bind_return_pmf fun_eq_iff intro!: arg_cong2[where f=bind_pmf] split: option.split)\n\nabbreviation pred_spmf :: \"('a \\<Rightarrow> bool) \\<Rightarrow> 'a spmf \\<Rightarrow> bool\"\nwhere \"pred_spmf P \\<equiv> pred_pmf (pred_option P)\"\n\nlemma pred_spmf_def: \"pred_spmf P p \\<longleftrightarrow> (\\<forall>x\\<in>set_spmf p. P x)\"\nby(auto simp add: pred_pmf_def pred_option_def set_spmf_def)\n\nlemma spmf_pred_mono_strong:\n  \"\\<lbrakk> pred_spmf P p; \\<And>a. \\<lbrakk> a \\<in> set_spmf p; P a \\<rbrakk> \\<Longrightarrow> P' a \\<rbrakk> \\<Longrightarrow> pred_spmf P' p\"\nby(simp add: pred_spmf_def)\n\nlemma spmf_Domainp_rel: \"Domainp (rel_spmf R) = pred_spmf (Domainp R)\"\nby(simp add: pmf.Domainp_rel option.Domainp_rel)\n\nlemma rel_spmf_restrict_relpI [intro?]:\n  \"\\<lbrakk> rel_spmf R p q; pred_spmf P p; pred_spmf Q q \\<rbrakk> \\<Longrightarrow> rel_spmf (R \\<upharpoonleft> P \\<otimes> Q) p q\"\nby(erule spmf_rel_mono_strong)(simp add: pred_spmf_def)\n\nlemma rel_spmf_restrict_relpE [elim?]:\n  assumes \"rel_spmf (R \\<upharpoonleft> P \\<otimes> Q) x y\"\n  obtains \"rel_spmf R x y\" \"pred_spmf P x\" \"pred_spmf Q y\"\nproof\n  show \"rel_spmf R x y\" using assms by(auto elim!: spmf_rel_mono_strong)\n  have \"pred_spmf (Domainp (R \\<upharpoonleft> P \\<otimes> Q)) x\" using assms by(fold spmf_Domainp_rel) blast\n  then show \"pred_spmf P x\" by(rule spmf_pred_mono_strong)(blast dest!: restrict_relp_DomainpD)\n  have \"pred_spmf (Domainp (R \\<upharpoonleft> P \\<otimes> Q)\\<inverse>\\<inverse>) y\" using assms\n    by(fold spmf_Domainp_rel)(auto simp only: spmf_rel_conversep Domainp_conversep)\n  then show \"pred_spmf Q y\" by(rule spmf_pred_mono_strong)(auto dest!: restrict_relp_DomainpD)\nqed\n\nlemma rel_spmf_restrict_relp_iff:\n  \"rel_spmf (R \\<upharpoonleft> P \\<otimes> Q) x y \\<longleftrightarrow> rel_spmf R x y \\<and> pred_spmf P x \\<and> pred_spmf Q y\"\nby(blast intro: rel_spmf_restrict_relpI elim: rel_spmf_restrict_relpE)\n\nlemma spmf_pred_map: \"pred_spmf P (map_spmf f p) = pred_spmf (P \\<circ> f) p\"\nby(simp)\n\nlemma pred_spmf_bind [simp]: \"pred_spmf P (bind_spmf p f) = pred_spmf (pred_spmf P \\<circ> f) p\"\nby(simp add: pred_spmf_def bind_UNION)\n\nlemma pred_spmf_return: \"pred_spmf P (return_spmf x) = P x\"\nby simp\n\nlemma pred_spmf_return_pmf_None: \"pred_spmf P (return_pmf None)\"\nby simp\n\nlemma pred_spmf_spmf_of_pmf [simp]: \"pred_spmf P (spmf_of_pmf p) = pred_pmf P p\"\nunfolding pred_spmf_def by(simp add: pred_pmf_def)\n\nlemma pred_spmf_of_set [simp]: \"pred_spmf P (spmf_of_set A) = (finite A \\<longrightarrow> Ball A P)\"\nby(auto simp add: pred_spmf_def set_spmf_of_set)\n\nlemma pred_spmf_assert_spmf [simp]: \"pred_spmf P (assert_spmf b) = (b \\<longrightarrow> P ())\"\nby(cases b) simp_all\n\nlemma pred_spmf_pair [simp]:\n  \"pred_spmf P (pair_spmf p q) = pred_spmf (\\<lambda>x. pred_spmf (P \\<circ> Pair x) q) p\"\nby(simp add: pred_spmf_def)\n\nlemma set_spmf_try [simp]:\n  \"set_spmf (try_spmf p q) = set_spmf p \\<union> (if lossless_spmf p then {} else set_spmf q)\"\nby(auto simp add: try_spmf_def set_spmf_bind_pmf in_set_spmf lossless_iff_set_pmf_None split: option.splits)(metis option.collapse)\n\nlemma try_spmf_bind_out1:\n  \"(\\<And>x. lossless_spmf (f x)) \\<Longrightarrow> bind_spmf (TRY p ELSE q) f = TRY (bind_spmf p f) ELSE (bind_spmf q f)\"\n  apply(clarsimp simp add: bind_spmf_def try_spmf_def bind_assoc_pmf bind_return_pmf intro!: bind_pmf_cong[OF refl] split: option.split)\n  apply(rewrite in \"\\<hole> = _\" bind_return_pmf'[symmetric])\n  apply(rule bind_pmf_cong[OF refl])\n  apply(clarsimp split: option.split simp add: lossless_iff_set_pmf_None)\n  done\n\nlemma pred_spmf_try [simp]:\n  \"pred_spmf P (try_spmf p q) = (pred_spmf P p \\<and> (\\<not> lossless_spmf p \\<longrightarrow> pred_spmf P q))\"\nby(auto simp add: pred_spmf_def)\n\nlemma pred_spmf_cond [simp]:\n  \"pred_spmf P (cond_spmf p A) = pred_spmf (\\<lambda>x. x \\<in> A \\<longrightarrow> P x) p\"\nby(auto simp add: pred_spmf_def)\n\nlemma spmf_rel_map_restrict_relp: \n  shows spmf_rel_map_restrict_relp1: \"rel_spmf (R \\<upharpoonleft> P \\<otimes> Q) (map_spmf f p) = rel_spmf (R \\<circ> f \\<upharpoonleft> P \\<circ> f \\<otimes> Q) p\"\n  and spmf_rel_map_restrict_relp2: \"rel_spmf (R \\<upharpoonleft> P \\<otimes> Q) p (map_spmf g q) = rel_spmf ((\\<lambda>x. R x \\<circ> g) \\<upharpoonleft> P \\<otimes> Q \\<circ> g) p q\"\nby(simp_all add: spmf_rel_map restrict_relp_def)\n\nlemma pred_spmf_conj: \"pred_spmf (\\<lambda>x. P x \\<and> Q x) = (\\<lambda>x. pred_spmf P x \\<and> pred_spmf Q x)\"\nby simp\n\nlemma spmf_of_pmf_parametric [transfer_rule]: \n  includes lifting_syntax shows\n  \"(rel_pmf A ===> rel_spmf A) spmf_of_pmf spmf_of_pmf\"\nunfolding spmf_of_pmf_def[abs_def] by transfer_prover\n\nlemma mono2mono_return_pmf[THEN spmf.mono2mono, simp, cont_intro]: (* Move to SPMF *)\n  shows monotone_return_pmf: \"monotone option_ord (ord_spmf (=)) return_pmf\"\nby(rule monotoneI)(auto simp add: flat_ord_def)\n\nlemma mcont2mcont_return_pmf[THEN spmf.mcont2mcont, simp, cont_intro]:  (* Move to SPMF *)\n  shows mcont_return_pmf: \"mcont (flat_lub None) option_ord lub_spmf (ord_spmf (=)) return_pmf\"\nby(rule mcont_finite_chains[OF _ _ flat_interpretation[THEN ccpo] ccpo_spmf]) simp_all\n\nlemma pred_spmf_top: (* Move up *)\n  \"pred_spmf (\\<lambda>_. True) = (\\<lambda>_. True)\"\nby(simp)\n\nlemma rel_spmf_restrict_relpI' [intro?]:\n  \"\\<lbrakk> rel_spmf (\\<lambda>x y. P x \\<longrightarrow> Q y \\<longrightarrow> R x y) p q; pred_spmf P p; pred_spmf Q q \\<rbrakk> \\<Longrightarrow> rel_spmf (R \\<upharpoonleft> P \\<otimes> Q) p q\"\nby(erule spmf_rel_mono_strong)(simp add: pred_spmf_def)\n\nlemma set_spmf_map_pmf_MATCH [simp]:\n  assumes \"NO_MATCH (map_option g) f\"\n  shows \"set_spmf (map_pmf f p) = (\\<Union>x\\<in>set_pmf p. set_option (f x))\"\nby(rule set_spmf_map_pmf)\n\nlemma rel_spmf_bindI':\n  \"\\<lbrakk> rel_spmf A p q; \\<And>x y. \\<lbrakk> A x y; x \\<in> set_spmf p; y \\<in> set_spmf q \\<rbrakk> \\<Longrightarrow> rel_spmf B (f x) (g y) \\<rbrakk>\n  \\<Longrightarrow> rel_spmf B (p \\<bind> f) (q \\<bind> g)\"\napply(rule rel_spmf_bindI[where R=\"\\<lambda>x y. A x y \\<and> x \\<in> set_spmf p \\<and> y \\<in> set_spmf q\"])\n apply(erule spmf_rel_mono_strong; simp)\napply simp\ndone\n\ndefinition rel_witness_spmf :: \"('a \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow> 'a spmf \\<times> 'b spmf \\<Rightarrow> ('a \\<times> 'b) spmf\" where\n  \"rel_witness_spmf A = map_pmf rel_witness_option \\<circ> rel_witness_pmf (rel_option A)\"\n\nlemma assumes \"rel_spmf A p q\"\n  shows rel_witness_spmf1: \"rel_spmf (\\<lambda>a (a', b). a = a' \\<and> A a' b) p (rel_witness_spmf A (p, q))\"\n    and rel_witness_spmf2: \"rel_spmf (\\<lambda>(a, b') b. b = b' \\<and> A a b') (rel_witness_spmf A (p, q)) q\"\n  by(auto simp add: pmf.rel_map rel_witness_spmf_def intro: pmf.rel_mono_strong[OF rel_witness_pmf1[OF assms]] rel_witness_option1 pmf.rel_mono_strong[OF rel_witness_pmf2[OF assms]] rel_witness_option2)\n\nlemma weight_assert_spmf [simp]: \"weight_spmf (assert_spmf b) = indicator {True} b\"\n  by(simp split: split_indicator)\n\ndefinition enforce_spmf :: \"('a \\<Rightarrow> bool) \\<Rightarrow> 'a spmf \\<Rightarrow> 'a spmf\" where\n  \"enforce_spmf P = map_pmf (enforce_option P)\"\n\nlemma enforce_spmf_parametric [transfer_rule]: includes lifting_syntax shows\n  \"((A ===> (=)) ===> rel_spmf A ===> rel_spmf A) enforce_spmf enforce_spmf\"\n  unfolding enforce_spmf_def by transfer_prover\n\nlemma enforce_return_spmf [simp]:\n  \"enforce_spmf P (return_spmf x) = (if P x then return_spmf x else return_pmf None)\"\n  by(simp add: enforce_spmf_def)\n\nlemma enforce_return_pmf_None [simp]:\n  \"enforce_spmf P (return_pmf None) = return_pmf None\"\n  by(simp add: enforce_spmf_def)\n\nlemma enforce_map_spmf:\n  \"enforce_spmf P (map_spmf f p) = map_spmf f (enforce_spmf (P \\<circ> f) p)\"\n  by(simp add: enforce_spmf_def pmf.map_comp o_def enforce_map_option)\n\nlemma enforce_bind_spmf [simp]:\n  \"enforce_spmf P (bind_spmf p f) = bind_spmf p (enforce_spmf P \\<circ> f)\"\n  by(auto simp add: enforce_spmf_def bind_spmf_def map_bind_pmf intro!: bind_pmf_cong split: option.split)\n\nlemma set_enforce_spmf [simp]: \"set_spmf (enforce_spmf P p) = {a \\<in> set_spmf p. P a}\"\n  by(auto simp add: enforce_spmf_def in_set_spmf)\n\nlemma enforce_spmf_alt_def:\n  \"enforce_spmf P p = bind_spmf p (\\<lambda>a. bind_spmf (assert_spmf (P a)) (\\<lambda>_ :: unit. return_spmf a))\"\n  by(auto simp add: enforce_spmf_def assert_spmf_def map_pmf_def bind_spmf_def bind_return_pmf intro!: bind_pmf_cong split: option.split)\n\nlemma bind_enforce_spmf [simp]:\n  \"bind_spmf (enforce_spmf P p) f = bind_spmf p (\\<lambda>x. if P x then f x else return_pmf None)\"\n  by(auto simp add: enforce_spmf_alt_def assert_spmf_def intro!: bind_spmf_cong)\n\nlemma weight_enforce_spmf:\n  \"weight_spmf (enforce_spmf P p) = weight_spmf p - measure (measure_spmf p) {x. \\<not> P x}\" (is \"?lhs = ?rhs\")\nproof -\n  have \"?lhs = LINT x|measure_spmf p. indicator {x. P x} x\"\n    by(auto simp add: enforce_spmf_alt_def weight_bind_spmf o_def simp del: Bochner_Integration.integral_indicator intro!: Bochner_Integration.integral_cong split: split_indicator)\n  also have \"\\<dots> = ?rhs\"\n    by(subst measure_spmf.finite_measure_Diff[symmetric])(auto simp add: space_measure_spmf intro!: arg_cong2[where f=measure])\n  finally show ?thesis .\nqed\n\nlemma lossless_enforce_spmf [simp]:\n  \"lossless_spmf (enforce_spmf P p) \\<longleftrightarrow> lossless_spmf p \\<and> set_spmf p \\<subseteq> {x. P x}\"\n  by(auto simp add: enforce_spmf_alt_def)\n\nlemma enforce_spmf_top [simp]: \"enforce_spmf \\<top> = id\"\n  by(simp add: enforce_spmf_def)\n\nlemma enforce_spmf_K_True [simp]: \"enforce_spmf (\\<lambda>_. True) p = p\"\n  using enforce_spmf_top[THEN fun_cong, of p] by(simp add: top_fun_def)\n\nlemma enforce_spmf_bot [simp]: \"enforce_spmf \\<bottom> = (\\<lambda>_. return_pmf None)\"\n  by(simp add: enforce_spmf_def fun_eq_iff)\n\nlemma enforce_spmf_K_False [simp]: \"enforce_spmf (\\<lambda>_. False) p = return_pmf None\"\n  using enforce_spmf_bot[THEN fun_cong, of p] by(simp add: bot_fun_def)\n\nlemma enforce_pred_id_spmf: \"enforce_spmf P p = p\" if \"pred_spmf P p\"\nproof -\n  have \"enforce_spmf P p = map_pmf id p\" using that\n    by(auto simp add: enforce_spmf_def enforce_pred_id_option simp del: map_pmf_id intro!: pmf.map_cong_pred[OF refl] elim!: pmf_pred_mono_strong)\n  then show ?thesis by simp\nqed\n\nlemma map_the_spmf_of_pmf [simp]: \"map_pmf the (spmf_of_pmf p) = p\"\n  by(simp add: spmf_of_pmf_def pmf.map_comp o_def)\n\nlemma bind_bind_conv_pair_spmf:\n  \"bind_spmf p (\\<lambda>x. bind_spmf q (f x)) = bind_spmf (pair_spmf p q) (\\<lambda>(x, y). f x y)\"\n  by(simp add: pair_spmf_alt_def)\n\nlemma cond_spmf_spmf_of_set:\n  \"cond_spmf (spmf_of_set A) B = spmf_of_set (A \\<inter> B)\" if \"finite A\"\n  by(rule spmf_eqI)(auto simp add: spmf_of_set measure_spmf_of_set that split: split_indicator)\n\nlemma pair_spmf_of_set:\n  \"pair_spmf (spmf_of_set A) (spmf_of_set B) = spmf_of_set (A \\<times> B)\"\n  by(rule spmf_eqI)(clarsimp simp add: spmf_of_set card_cartesian_product split: split_indicator)\n\nlemma emeasure_cond_spmf:\n  \"emeasure (measure_spmf (cond_spmf p A)) B = emeasure (measure_spmf p) (A \\<inter> B) / emeasure (measure_spmf p) A\"\n  apply(clarsimp simp add: cond_spmf_def emeasure_measure_spmf_conv_measure_pmf emeasure_measure_pmf_zero_iff set_pmf_Int_Some split!: if_split)\n   apply blast\n  apply(subst (asm) emeasure_cond_pmf)\n  by(auto simp add: set_pmf_Int_Some image_Int)\n\nlemma measure_cond_spmf:\n  \"measure (measure_spmf (cond_spmf p A)) B = measure (measure_spmf p) (A \\<inter> B) / measure (measure_spmf p) A\"\n  apply(clarsimp simp add: cond_spmf_def measure_measure_spmf_conv_measure_pmf measure_pmf_zero_iff set_pmf_Int_Some split!: if_split)\n  apply(subst (asm) measure_cond_pmf)\n  by(auto simp add: image_Int set_pmf_Int_Some)\n\n\nlemma lossless_cond_spmf [simp]: \"lossless_spmf (cond_spmf p A) \\<longleftrightarrow> set_spmf p \\<inter> A \\<noteq> {}\"\n  by(clarsimp simp add: cond_spmf_def lossless_iff_set_pmf_None set_pmf_Int_Some)\n\nlemma measure_spmf_eq_density: \"measure_spmf p = density (count_space UNIV) (spmf p)\"\n  by(rule measure_eqI)(simp_all add: emeasure_density nn_integral_spmf[symmetric] nn_integral_count_space_indicator)\n\nlemma integral_measure_spmf:\n  fixes f :: \"'a \\<Rightarrow> 'b::{banach, second_countable_topology}\"\n  assumes A: \"finite A\"\n  shows \"(\\<And>a. a \\<in> set_spmf M \\<Longrightarrow> f a \\<noteq> 0 \\<Longrightarrow> a \\<in> A) \\<Longrightarrow> (LINT x|measure_spmf M. f x) = (\\<Sum>a\\<in>A. spmf M a *\\<^sub>R f a)\"\n  unfolding measure_spmf_eq_density\n  apply (simp add: integral_density)\n  apply (subst lebesgue_integral_count_space_finite_support)\n  by (auto intro!: finite_subset[OF _ \\<open>finite A\\<close>] sum.mono_neutral_left simp: spmf_eq_0_set_spmf)\n\n\nlemma image_set_spmf_eq:\n  \"f ` set_spmf p = g ` set_spmf q\" if \"ASSUMPTION (map_spmf f p = map_spmf g q)\"\n  using that[unfolded ASSUMPTION_def, THEN arg_cong[where f=set_spmf]] by simp\n\nlemma map_spmf_const: \"map_spmf (\\<lambda>_. x) p = scale_spmf (weight_spmf p) (return_spmf x)\"\n  by(simp add: map_spmf_conv_bind_spmf bind_spmf_const)\n\nlemma cond_return_pmf [simp]: \"cond_pmf (return_pmf x) A = return_pmf x\" if \"x \\<in> A\"\n  using that by(intro pmf_eqI)(auto simp add: pmf_cond split: split_indicator)\n\nlemma cond_return_spmf [simp]: \"cond_spmf (return_spmf x) A = (if x \\<in> A then return_spmf x else return_pmf None)\"\n  by(simp add: cond_spmf_def)\n\nlemma measure_range_Some_eq_weight:\n  \"measure (measure_pmf p) (range Some) = weight_spmf p\"\n  by (simp add: measure_measure_spmf_conv_measure_pmf space_measure_spmf)\n\nlemma restrict_spmf_eq_return_pmf_None [simp]:\n  \"restrict_spmf p A = return_pmf None \\<longleftrightarrow> set_spmf p \\<inter> A = {}\"\n  by(auto 4 3 simp add: restrict_spmf_def map_pmf_eq_return_pmf_iff bind_UNION in_set_spmf bind_eq_None_conv option.the_def dest: bspec split: if_split_asm option.split_asm)\n\ndefinition mk_lossless :: \"'a spmf \\<Rightarrow> 'a spmf\" where\n  \"mk_lossless p = scale_spmf (inverse (weight_spmf p)) p\"\n\nlemma mk_lossless_idem [simp]: \"mk_lossless (mk_lossless p) = mk_lossless p\"\n  by(simp add: mk_lossless_def weight_scale_spmf min_def max_def inverse_eq_divide) \n\nlemma mk_lossless_return [simp]: \"mk_lossless (return_pmf x) = return_pmf x\"\n  by(cases x)(simp_all add: mk_lossless_def)\n\n\n\nlemma spmf_mk_lossless [simp]: \"spmf (mk_lossless p) x = spmf p x / weight_spmf p\"\n  by(simp add: mk_lossless_def spmf_scale_spmf inverse_eq_divide max_def)\n\nlemma set_spmf_mk_lossless [simp]: \"set_spmf (mk_lossless p) = set_spmf p\"\n  by(simp add: mk_lossless_def set_scale_spmf measure_spmf_zero_iff zero_less_measure_iff)\n\n\n\nlemma mk_lossless_eq_return_pmf_None [simp]: \"mk_lossless p = return_pmf None \\<longleftrightarrow> p = return_pmf None\"\nproof -\n  have aux: \"weight_spmf p = 0 \\<Longrightarrow> spmf p i = 0\" for i\n    by(rule antisym, rule order_trans[OF spmf_le_weight]) (auto intro!: order_trans[OF spmf_le_weight])\n\n  have[simp]: \" spmf (scale_spmf (inverse (weight_spmf p)) p) = spmf (return_pmf None) \\<Longrightarrow> spmf p i = 0\" for i\n    by(drule fun_cong[where x=i]) (auto simp add: aux spmf_scale_spmf max_def)\n\n  show ?thesis by(auto simp add: mk_lossless_def intro: spmf_eqI)\nqed\n\nlemma return_pmf_None_eq_mk_lossless [simp]: \"return_pmf None = mk_lossless p \\<longleftrightarrow> p = return_pmf None\"\n  by(metis mk_lossless_eq_return_pmf_None)\n\nlemma mk_lossless_spmf_of_set [simp]: \"mk_lossless (spmf_of_set A) = spmf_of_set A\"\n  by(simp add: spmf_of_set_def del: spmf_of_pmf_pmf_of_set)\n\nlemma weight_mk_lossless: \"weight_spmf (mk_lossless p) = (if p = return_pmf None then 0 else 1)\"\n  by(simp add: mk_lossless_def weight_scale_spmf min_def max_def inverse_eq_divide weight_spmf_eq_0)\n\nlemma mk_lossless_parametric [transfer_rule]: includes lifting_syntax shows\n  \"(rel_spmf A ===> rel_spmf A) mk_lossless mk_lossless\"\n  by(simp add: mk_lossless_def rel_fun_def rel_spmf_weightD rel_spmf_scaleI)\n\nlemma rel_spmf_mk_losslessI:\n  \"rel_spmf A p q \\<Longrightarrow> rel_spmf A (mk_lossless p) (mk_lossless q)\"\n  by(rule mk_lossless_parametric[THEN rel_funD])\n\nlemma rel_spmf_restrict_spmfI:\n  \"rel_spmf (\\<lambda>x y. (x \\<in> A \\<and> y \\<in> B \\<and> R x y) \\<or> x \\<notin> A \\<and> y \\<notin> B) p q\n   \\<Longrightarrow> rel_spmf R (restrict_spmf p A) (restrict_spmf q B)\"\n  by(auto simp add: restrict_spmf_def pmf.rel_map elim!: option.rel_cases pmf.rel_mono_strong)\n\nlemma cond_spmf_alt: \"cond_spmf p A = mk_lossless (restrict_spmf p A)\"\nproof(cases \"set_spmf p \\<inter> A = {}\")\n  case True\n  then show ?thesis by(simp add: cond_spmf_def measure_spmf_zero_iff)\nnext\n  case False\n  show ?thesis\n    by(rule spmf_eqI)(simp add: False cond_spmf_def pmf_cond set_pmf_Int_Some image_iff measure_measure_spmf_conv_measure_pmf[symmetric] spmf_scale_spmf max_def inverse_eq_divide)\nqed\n\nlemma cond_spmf_bind:\n  \"cond_spmf (bind_spmf p f) A = mk_lossless (p \\<bind> (\\<lambda>x. f x \\<upharpoonleft> A))\"\n  by(simp add: cond_spmf_alt restrict_bind_spmf scale_bind_spmf)\n\nlemma cond_spmf_UNIV [simp]: \"cond_spmf p UNIV = mk_lossless p\"\n  by(clarsimp simp add: cond_spmf_alt)\n\nlemma cond_pmf_singleton:\n  \"cond_pmf p A = return_pmf x\" if \"set_pmf p \\<inter> A = {x}\"\nproof -\n  have[simp]: \"set_pmf p \\<inter> A = {x} \\<Longrightarrow> x \\<in> A \\<Longrightarrow> measure_pmf.prob p A = pmf p x\"\n    by(auto simp add: measure_pmf_single[symmetric] AE_measure_pmf_iff intro!: measure_pmf.finite_measure_eq_AE)\n\n  have \"pmf (cond_pmf p A) i = pmf (return_pmf x) i\" for i\n    using that by(auto simp add: pmf_cond measure_pmf_zero_iff pmf_eq_0_set_pmf split: split_indicator)\n\n  then show ?thesis by(rule pmf_eqI)\nqed\n\n\ndefinition cond_spmf_fst :: \"('a \\<times> 'b) spmf \\<Rightarrow> 'a \\<Rightarrow> 'b spmf\" where\n  \"cond_spmf_fst p a = map_spmf snd (cond_spmf p ({a} \\<times> UNIV))\"\n\nlemma cond_spmf_fst_return_spmf [simp]:\n  \"cond_spmf_fst (return_spmf (x, y)) x = return_spmf y\"\n  by(simp add: cond_spmf_fst_def)\n\nlemma cond_spmf_fst_map_Pair [simp]: \"cond_spmf_fst (map_spmf (Pair x) p) x = mk_lossless p\"\n  by(clarsimp simp add: cond_spmf_fst_def spmf.map_comp o_def)\n\nlemma cond_spmf_fst_map_Pair' [simp]: \"cond_spmf_fst (map_spmf (\\<lambda>y. (x, f y)) p) x = map_spmf f (mk_lossless p)\"\n  by(subst spmf.map_comp[where f=\"Pair x\", symmetric, unfolded o_def]) simp\n\nlemma cond_spmf_fst_eq_return_None [simp]: \"cond_spmf_fst p x = return_pmf None \\<longleftrightarrow> x \\<notin> fst ` set_spmf p\"\n  by(auto 4 4 simp add: cond_spmf_fst_def map_pmf_eq_return_pmf_iff in_set_spmf[symmetric] dest: bspec[where x=\"Some _\"] intro: ccontr rev_image_eqI)\n\nlemma cond_spmf_fst_map_Pair1:\n  \"cond_spmf_fst (map_spmf (\\<lambda>x. (f x, g x)) p) (f x) = return_spmf (g (inv_into (set_spmf p) f (f x)))\"\n  if \"x \\<in> set_spmf p\" \"inj_on f (set_spmf p)\"\nproof -\n  let ?foo=\"\\<lambda>y. map_option (\\<lambda>x. (f x, g x)) -` Some ` ({f y} \\<times> UNIV)\"\n  have[simp]: \"y \\<in> set_spmf p \\<Longrightarrow> f x = f y \\<Longrightarrow> set_pmf p \\<inter> (?foo y) \\<noteq> {}\" for y\n    by(auto simp add: vimage_def image_def in_set_spmf)\n\n  have[simp]: \"y \\<in> set_spmf p \\<Longrightarrow> f x = f y \\<Longrightarrow>  map_spmf snd (map_spmf (\\<lambda>x. (f x, g x)) (cond_pmf p (?foo y))) = return_spmf (g x)\" for y\n    using that by(subst cond_pmf_singleton[where x=\"Some x\"]) (auto simp add: in_set_spmf elim: inj_onD)\n\n  show ?thesis\n    using that\n    by(auto simp add: cond_spmf_fst_def cond_spmf_def)\n      (erule notE, subst cond_map_pmf, simp_all)\nqed\n\nlemma lossless_cond_spmf_fst [simp]: \"lossless_spmf (cond_spmf_fst p x) \\<longleftrightarrow> x \\<in> fst ` set_spmf p\"\n  by(auto simp add: cond_spmf_fst_def intro: rev_image_eqI)\n\nlemma cond_spmf_fst_inverse:\n  \"bind_spmf (map_spmf fst p) (\\<lambda>x. map_spmf (Pair x) (cond_spmf_fst p x)) = p\"\n  (is \"?lhs = ?rhs\")\nproof(rule spmf_eqI)\n  fix i :: \"'a \\<times> 'b\"\n  have *: \"({x} \\<times> UNIV \\<inter> (Pair x \\<circ> snd) -` {i}) = (if x = fst i then {i} else {})\" for x by(cases i)auto\n  have \"spmf ?lhs i = LINT x|measure_spmf (map_spmf fst p). spmf (map_spmf (Pair x \\<circ> snd) (cond_spmf p ({x} \\<times> UNIV))) i\"\n    by(auto simp add: spmf_bind spmf.map_comp[symmetric] cond_spmf_fst_def intro!: integral_cong_AE)\n  also have \"\\<dots> = LINT x|measure_spmf (map_spmf fst p). measure (measure_spmf (cond_spmf p ({x} \\<times> UNIV))) ((Pair x \\<circ> snd) -` {i})\"\n    by(rule integral_cong_AE)(auto simp add: spmf_map)\n  also have \"\\<dots> = LINT x|measure_spmf (map_spmf fst p). measure (measure_spmf p) ({x} \\<times> UNIV \\<inter> (Pair x \\<circ> snd) -` {i}) /\n       measure (measure_spmf p) ({x} \\<times> UNIV)\"\n    by(rule integral_cong_AE; clarsimp simp add: measure_cond_spmf)\n  also have \"\\<dots> = spmf (map_spmf fst p) (fst i) * spmf p i / measure (measure_spmf p) ({fst i} \\<times> UNIV)\"\n    by(simp add: * if_distrib[where f=\"measure (measure_spmf _)\"] cong: if_cong)\n      (subst integral_measure_spmf[where A=\"{fst i}\"]; auto split: if_split_asm simp add: spmf_conv_measure_spmf)\n  also have \"\\<dots> = spmf p i\"\n    by(clarsimp simp add: spmf_map vimage_fst)(metis (no_types, lifting) Int_insert_left_if1 in_set_spmf_iff_spmf insertI1 insert_UNIV insert_absorb insert_not_empty measure_spmf_zero_iff mem_Sigma_iff prod.collapse)\n  finally show \"spmf ?lhs i = spmf ?rhs i\" .\nqed\n\nsubsubsection \\<open>Embedding of @{typ \"'a option\"} into @{typ \"'a spmf\"}\\<close>\n\ntext \\<open>This theoretically follows from the embedding between @{typ \"_ id\"} into @{typ \"_ prob\"} and the isomorphism\n  between @{typ \"(_, _ prob) optionT\"} and @{typ \"_ spmf\"}, but we would only get the monomorphic\n  version via this connection. So we do it directly.\n\\<close>\n\nlemma bind_option_spmf_monad [simp]: \"monad.bind_option (return_pmf None) x = bind_spmf (return_pmf x)\"\nby(cases x)(simp_all add: fun_eq_iff)\n\nlocale option_to_spmf begin\n\ntext \\<open>\n  We have to get the embedding into the lifting package such that we can use the parametrisation of transfer rules.\n\\<close>\n\ndefinition the_pmf :: \"'a pmf \\<Rightarrow> 'a\" where \"the_pmf p = (THE x. p = return_pmf x)\"\n\nlemma the_pmf_return [simp]: \"the_pmf (return_pmf x) = x\"\nby(simp add: the_pmf_def)\n\nlemma type_definition_option_spmf: \"type_definition return_pmf the_pmf {x. \\<exists>y :: 'a option. x = return_pmf y}\"\nby unfold_locales(auto)\n\ncontext begin\nprivate setup_lifting type_definition_option_spmf\nabbreviation cr_spmf_option where \"cr_spmf_option \\<equiv> cr_option\"\nabbreviation pcr_spmf_option where \"pcr_spmf_option \\<equiv> pcr_option\"\nlemmas Quotient_spmf_option = Quotient_option\n  and cr_spmf_option_def = cr_option_def\n  and pcr_spmf_option_bi_unique = option.bi_unique\n  and Domainp_pcr_spmf_option = option.domain\n  and Domainp_pcr_spmf_option_eq = option.domain_eq\n  and Domainp_pcr_spmf_option_par = option.domain_par\n  and Domainp_pcr_spmf_option_left_total = option.domain_par_left_total\n  and pcr_spmf_option_left_unique = option.left_unique\n  and pcr_spmf_option_cr_eq = option.pcr_cr_eq\n  and pcr_spmf_option_return_pmf_transfer = option.rep_transfer\n  and pcr_spmf_option_right_total = option.right_total\n  and pcr_spmf_option_right_unique = option.right_unique\n  and pcr_spmf_option_def = pcr_option_def\nbundle spmf_option_lifting = [[Lifting.lifting_restore_internal \"Misc_CryptHOL.option.lifting\"]]\nend\n\n\ncontext includes lifting_syntax begin\n\nlemma return_option_spmf_transfer [transfer_parametric return_spmf_parametric, transfer_rule]:\n  \"((=) ===> cr_spmf_option) return_spmf Some\"\nby(rule rel_funI)(simp add: cr_spmf_option_def)\n\nlemma map_option_spmf_transfer [transfer_parametric map_spmf_parametric, transfer_rule]:\n  \"(((=) ===> (=)) ===> cr_spmf_option ===> cr_spmf_option) map_spmf map_option\"\nunfolding rel_fun_eq by(auto simp add: rel_fun_def cr_spmf_option_def)\n\nlemma fail_option_spmf_transfer [transfer_parametric return_spmf_None_parametric, transfer_rule]:\n  \"cr_spmf_option (return_pmf None) None\"\nby(simp add: cr_spmf_option_def)\n\nlemma bind_option_spmf_transfer [transfer_parametric bind_spmf_parametric, transfer_rule]:\n  \"(cr_spmf_option ===> ((=) ===> cr_spmf_option) ===> cr_spmf_option) bind_spmf Option.bind\"\napply(clarsimp simp add: rel_fun_def cr_spmf_option_def)\nsubgoal for x f g by(cases x; simp)\ndone\n\nlemma set_option_spmf_transfer [transfer_parametric set_spmf_parametric, transfer_rule]:\n  \"(cr_spmf_option ===> rel_set (=)) set_spmf set_option\"\nby(clarsimp simp add: rel_fun_def cr_spmf_option_def rel_set_eq)\n\nlemma rel_option_spmf_transfer [transfer_parametric rel_spmf_parametric, transfer_rule]:\n  \"(((=) ===> (=) ===> (=)) ===> cr_spmf_option ===> cr_spmf_option ===> (=)) rel_spmf rel_option\"\nunfolding rel_fun_eq by(simp add: rel_fun_def cr_spmf_option_def)\n\nend\n\nend\n\nlocale option_le_spmf begin\n\ntext \\<open>\n  Embedding where only successful computations in the option monad are related to Dirac spmf.\n\\<close>\n\ndefinition cr_option_le_spmf :: \"'a option \\<Rightarrow> 'a spmf \\<Rightarrow> bool\"\nwhere \"cr_option_le_spmf x p \\<longleftrightarrow> ord_spmf (=) (return_pmf x) p\"\n\ncontext includes lifting_syntax begin\n\nlemma return_option_le_spmf_transfer [transfer_rule]:\n  \"((=) ===> cr_option_le_spmf) (\\<lambda>x. x) return_pmf\"\nby(rule rel_funI)(simp add: cr_option_le_spmf_def ord_option_reflI)\n\nlemma map_option_le_spmf_transfer [transfer_rule]:\n  \"(((=) ===> (=)) ===> cr_option_le_spmf ===> cr_option_le_spmf) map_option map_spmf\"\nunfolding rel_fun_eq\napply(clarsimp simp add: rel_fun_def cr_option_le_spmf_def rel_pmf_return_pmf1 ord_option_map1 ord_option_map2)\nsubgoal for f x p y by(cases x; simp add: ord_option_reflI)\ndone\n\nlemma bind_option_le_spmf_transfer [transfer_rule]:\n  \"(cr_option_le_spmf ===> ((=) ===> cr_option_le_spmf) ===> cr_option_le_spmf) Option.bind bind_spmf\"\napply(clarsimp simp add: rel_fun_def cr_option_le_spmf_def)\nsubgoal for x p f g by(cases x; auto 4 3 simp add: rel_pmf_return_pmf1 set_pmf_bind_spmf)\ndone\n\nend\n\nend\n\ninterpretation rel_spmf_characterisation by unfold_locales(rule rel_pmf_measureI)\n\nlemma if_distrib_bind_spmf1 [if_distribs]:\n  \"bind_spmf (if b then x else y) f = (if b then bind_spmf x f else bind_spmf y f)\"\nby simp\n\nlemma if_distrib_bind_spmf2 [if_distribs]:\n  \"bind_spmf x (\\<lambda>y. if b then f y else g y) = (if b then bind_spmf x f else bind_spmf x g)\"\nby simp\n\nlemma rel_spmf_if_distrib [if_distribs]:\n  \"rel_spmf R (if b then x else y) (if b then x' else y') \\<longleftrightarrow>\n  (b \\<longrightarrow> rel_spmf R x x') \\<and> (\\<not> b \\<longrightarrow> rel_spmf R y y')\"\nby(simp)\n\nlemma if_distrib_map_spmf [if_distribs]:\n  \"map_spmf f (if b then p else q) = (if b then map_spmf f p else map_spmf f q)\"\nby simp\n\nlemma if_distrib_restrict_spmf1 [if_distribs]:\n  \"restrict_spmf (if b then p else q) A = (if b then restrict_spmf p A else restrict_spmf q A)\"\nby simp\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/CryptHOL/Misc_CryptHOL.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5117166047041654, "lm_q2_score": 0.5774953651858117, "lm_q1q2_score": 0.2955139675052756}}
{"text": "(*\nTiTitle: Value-Dependent SIFUM-Type-Systems\nAuthors: Toby Murray, Robert Sison, Edward Pierzchalski, Christine Rizkallah\n(Based on the SIFUM-Type-Systems AFP entry, whose authors\n are: Sylvia Grewe, Heiko Mantel, Daniel Schoepe)\n*)\nsection \\<open>Type System for Ensuring Locally Sound Use of Modes\\<close>\n\ntheory LocallySoundModeUse\nimports Security Language\nbegin\n\nsubsection \\<open>Typing Rules\\<close>\n\nlocale sifum_modes = \n  sifum_lang_no_dma ev\\<^sub>A ev\\<^sub>B aexp_vars bexp_vars + sifum_security dma \\<C>_vars \\<C> eval\\<^sub>w undefined\n  for ev\\<^sub>A :: \"('Var, 'Val) Mem \\<Rightarrow> 'AExp \\<Rightarrow> 'Val\"\n  and ev\\<^sub>B :: \"('Var, 'Val) Mem \\<Rightarrow> 'BExp \\<Rightarrow> bool\"\n  and aexp_vars :: \"'AExp \\<Rightarrow> 'Var set\"\n  and bexp_vars :: \"'BExp \\<Rightarrow> 'Var set\"\n  and dma :: \"('Var,'Val) Mem \\<Rightarrow> 'Var \\<Rightarrow> Sec\"\n  and \\<C>_vars :: \"'Var \\<Rightarrow> 'Var set\"\n  and \\<C> :: \"'Var set\"\n\ncontext sifum_modes\nbegin\n\nabbreviation \n  eval_abv_modes :: \"(_, 'Var, 'Val) LocalConf \\<Rightarrow> (_, _, _) LocalConf \\<Rightarrow> bool\"\n  (infixl \"\\<leadsto>\" 70)\nwhere\n  \"x \\<leadsto> y \\<equiv> (x, y) \\<in> eval\\<^sub>w\"\n\nfun \n  update_annos :: \"'Var Mds \\<Rightarrow> 'Var ModeUpd list \\<Rightarrow> 'Var Mds\"\n  (infix \"\\<oplus>\" 140)\nwhere\n  \"update_annos mds [] = mds\" |\n  \"update_annos mds (a # as) = update_annos (update_modes a mds) as\"\n\nfun \n  annotate :: \"('Var, 'AExp, 'BExp) Stmt \\<Rightarrow> 'Var ModeUpd list \\<Rightarrow> ('Var, 'AExp, 'BExp) Stmt\"\n  (infix \"\\<otimes>\" 140)\nwhere\n  \"annotate c [] = c\" |\n  \"annotate c (a # as) = (annotate c as)@[a]\"\n\ninductive \n  mode_type :: \"'Var Mds \\<Rightarrow> ('Var, 'AExp, 'BExp) Stmt \\<Rightarrow> 'Var Mds \\<Rightarrow> bool\" (\"\\<turnstile> _ { _ } _\")\nwhere\n  skip: \"\\<turnstile> mds { Skip \\<otimes> annos } (mds \\<oplus> annos)\" |\n  assign: \"\\<lbrakk> x \\<notin> mds GuarNoWrite \\<union> mds GuarNoReadOrWrite ; aexp_vars e \\<inter> mds GuarNoReadOrWrite = {};\n             \\<forall>v. (x \\<in> \\<C>_vars v \\<longrightarrow> v \\<notin> mds GuarNoWrite \\<union> mds GuarNoReadOrWrite) \\<and>\n                 (\\<C>_vars v \\<inter> aexp_vars e \\<noteq> {} \\<longrightarrow> v \\<notin> mds GuarNoReadOrWrite)\\<rbrakk> \\<Longrightarrow>\n  \\<turnstile> mds { (x \\<leftarrow> e) \\<otimes> annos } (mds \\<oplus> annos)\" |\n  if_: \"\\<lbrakk> \\<turnstile> (mds \\<oplus> annos) { c\\<^sub>1 } mds'' ;\n          \\<turnstile> (mds \\<oplus> annos) { c\\<^sub>2 } mds'' ;\n          bexp_vars e \\<inter> mds GuarNoReadOrWrite = {};\n          \\<forall> v. \\<C>_vars v \\<inter> bexp_vars e \\<noteq> {} \\<longrightarrow> v \\<notin> mds GuarNoReadOrWrite\\<rbrakk> \\<Longrightarrow>\n        \\<turnstile> mds { If e c\\<^sub>1 c\\<^sub>2 \\<otimes> annos } mds''\" |\n  while: \"\\<lbrakk> mds' = mds \\<oplus> annos ; \\<turnstile> mds' { c } mds' ; bexp_vars e \\<inter> mds' GuarNoReadOrWrite = {};\n            \\<forall> v. \\<C>_vars v \\<inter> bexp_vars e \\<noteq> {} \\<longrightarrow> v \\<notin> mds' GuarNoReadOrWrite\\<rbrakk> \\<Longrightarrow>\n  \\<turnstile> mds { While e c \\<otimes> annos } mds'\" |\n  seq: \"\\<lbrakk> \\<turnstile> mds { c\\<^sub>1 } mds' ; \\<turnstile> mds' { c\\<^sub>2 } mds'' \\<rbrakk> \\<Longrightarrow> \\<turnstile> mds { c\\<^sub>1 ;; c\\<^sub>2 } mds''\" |\n  sub: \"\\<lbrakk> \\<turnstile> mds\\<^sub>2 { c } mds\\<^sub>2' ; mds\\<^sub>1 \\<le> mds\\<^sub>2 ; mds\\<^sub>2' \\<le> mds\\<^sub>1' \\<rbrakk> \\<Longrightarrow>\n  \\<turnstile> mds\\<^sub>1 { c } mds\\<^sub>1'\"\n\nsubsection \\<open>Soundness of the Type System\\<close>\n\n(* Special case for evaluation with an empty context *)\n\n\nlemma update_preserves_le:\n  \"mds\\<^sub>1 \\<le> mds\\<^sub>2 \\<Longrightarrow> (mds\\<^sub>1 \\<oplus> annos) \\<le> (mds\\<^sub>2 \\<oplus> annos)\"\nproof (induct annos arbitrary: mds\\<^sub>1 mds\\<^sub>2)\n  case Nil\n  thus ?case by simp\nnext\n  case (Cons a annos mds\\<^sub>1 mds\\<^sub>2)\n  hence \"update_modes a mds\\<^sub>1 \\<le> update_modes a mds\\<^sub>2\"\n    by (case_tac a, auto simp: le_fun_def)\n  with Cons show ?case\n    by auto\nqed\n\n(* Annotations do not affect doesnt_read and doesnt_modify: *)\nlemma doesnt_read_annos:\n  \"doesnt_read_or_modify c x \\<Longrightarrow> doesnt_read_or_modify (c \\<otimes> annos) x\"\n  unfolding doesnt_read_or_modify_def doesnt_read_or_modify_vars_def\n  apply clarify\n  apply (induct annos)\n   apply simp\n   apply (metis (lifting))\n  apply clarsimp\n  apply (rule cxt_eval)\n  apply (rule eval\\<^sub>w.decl)\n  apply (metis cxt_eval eval\\<^sub>w.decl upd_elim)+\n  done\n\nlemma doesnt_modify_annos:\n  \"doesnt_modify c x \\<Longrightarrow> doesnt_modify (c \\<otimes> annos) x\"\n  unfolding doesnt_modify_def\n  apply clarsimp\n   apply (induct annos)\n    apply simp \n   by (metis annotate.simps(2) upd_elim)\n  \n(* The following part contains some lemmas about evaluation of\n   commands annotated using \\<otimes> and characterisations of loc_reach for\n   commands. *)\n\nlemma stop_loc_reach:\n  \"\\<lbrakk> \\<langle>c', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>Stop, mds, mem\\<rangle> \\<rbrakk> \\<Longrightarrow>\n  c' = Stop \\<and> mds' = mds\"\n  apply (induct rule: loc_reach.induct)\n  by (auto simp: stop_no_eval)\n\nlemma stop_doesnt_access:\n  \"doesnt_modify Stop x \\<and> doesnt_read_or_modify Stop x\"\n  unfolding doesnt_modify_def and doesnt_read_or_modify_def doesnt_read_or_modify_vars_def\n  using stop_no_eval\n  by auto\n\nlemma skip_eval_step:\n  \"\\<langle>Skip \\<otimes> annos, mds, mem\\<rangle> \\<leadsto> \\<langle>Stop, mds \\<oplus> annos, mem\\<rangle>\"\n  apply (induct annos arbitrary: mds)\n   apply simp\n   apply (metis cxt_to_stmt.simps(1) eval\\<^sub>w.unannotated eval\\<^sub>w_simple.skip)\n  apply simp\n  apply (insert eval\\<^sub>w.decl)\n  apply (rule cxt_eval)\n  apply (rule eval\\<^sub>w.decl)\n  by auto\n\nlemma skip_eval_elim:\n  \"\\<lbrakk> \\<langle>Skip \\<otimes> annos, mds, mem\\<rangle> \\<leadsto> \\<langle>c', mds', mem'\\<rangle> \\<rbrakk> \\<Longrightarrow> c' = Stop \\<and> mds' = mds \\<oplus> annos \\<and> mem' = mem\"\n  apply (rule ccontr)\n  apply (insert skip_eval_step deterministic)\n  apply clarify\n  apply clarsimp\n    by metis+\n\nlemma skip_doesnt_read:\n  \"doesnt_read_or_modify (Skip \\<otimes> annos) x\"\n  apply (rule doesnt_read_annos)\n  apply (clarsimp simp: doesnt_read_or_modify_def doesnt_read_or_modify_vars_def)\n  by (metis annotate.simps(1) skip_elim skip_eval_step)+\n\nlemma skip_doesnt_write:\n  \"doesnt_modify (Skip \\<otimes> annos) x\"\n  apply (rule doesnt_modify_annos)\n  apply (clarsimp simp: doesnt_modify_def)\n  by (metis skip_elim)+\n\nlemma skip_loc_reach:\n  \"\\<lbrakk> \\<langle>c', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>Skip \\<otimes> annos, mds, mem\\<rangle> \\<rbrakk> \\<Longrightarrow>\n  (c' = Stop \\<and> mds' = (mds \\<oplus> annos)) \\<or> (c' = Skip \\<otimes> annos \\<and> mds' = mds)\"\n  apply (induct rule: loc_reach.induct)\n    apply (metis fst_conv snd_conv)\n   apply (metis skip_eval_elim stop_no_eval)\n  by metis\n\nlemma skip_doesnt_access:\n  \"\\<lbrakk> lc \\<in> loc_reach \\<langle>Skip \\<otimes> annos, mds, mem\\<rangle> ; lc = \\<langle>c', mds', mem'\\<rangle> \\<rbrakk> \\<Longrightarrow> doesnt_read_or_modify c' x \\<and> doesnt_modify c' x\"\n  apply (subgoal_tac \"(c' = Stop \\<and> mds' = (mds \\<oplus> annos)) \\<or> (c' = Skip \\<otimes> annos \\<and> mds' = mds)\")\n   apply (rule conjI, erule disjE)\n     apply (simp add: doesnt_read_or_modify_def doesnt_read_or_modify_vars_def stop_no_eval)\n    apply (metis (lifting) annotate.simps skip_doesnt_read)\n   apply (erule disjE)\n    apply (simp add: doesnt_modify_def stop_no_eval)\n   apply (metis (lifting) annotate.simps skip_doesnt_write)\n  by (metis skip_loc_reach)\n\nlemma assign_doesnt_modify:\n  \"\\<lbrakk> x \\<noteq> y; x \\<notin> \\<C>_vars y \\<rbrakk> \\<Longrightarrow> doesnt_modify ((x \\<leftarrow> e) \\<otimes> annos) y\"\n  apply (rule doesnt_modify_annos)\n  apply (simp add: doesnt_modify_def)\n  by (metis assign_elim fun_upd_apply dma_\\<C>_vars)\n  \nlemma assign_annos_eval:\n  \"\\<langle>(x \\<leftarrow> e) \\<otimes> annos, mds, mem\\<rangle> \\<leadsto> \\<langle>Stop, mds \\<oplus> annos, mem (x := ev\\<^sub>A mem e)\\<rangle>\"\n  apply (induct annos arbitrary: mds)\n   apply (simp only: annotate.simps update_annos.simps)\n   apply (rule cxt_eval)\n   apply (rule eval\\<^sub>w.unannotated)\n   apply (rule eval\\<^sub>w_simple.assign)\n  apply (rule cxt_eval)\n  apply (simp del: cxt_to_stmt.simps)\n  apply (rule eval\\<^sub>w.decl)\n  by auto\n\nlemma assign_annos_eval_elim:\n  \"\\<lbrakk> \\<langle>(x \\<leftarrow> e) \\<otimes> annos, mds, mem\\<rangle> \\<leadsto> \\<langle>c', mds', mem'\\<rangle> \\<rbrakk> \\<Longrightarrow>\n  c' = Stop \\<and> mds' = mds \\<oplus> annos\"\n  apply (rule ccontr)\n  apply (insert deterministic assign_annos_eval)\n  apply clarsimp\n  by (metis (lifting))\n\nlemma mem_upd_commute:\n  \"\\<lbrakk> x \\<noteq> y \\<rbrakk> \\<Longrightarrow> mem (x := v\\<^sub>1, y := v\\<^sub>2) = mem (y := v\\<^sub>2, x := v\\<^sub>1)\"\n  by (metis fun_upd_twist)\n\nlemma assign_doesnt_read:\n  \"\\<lbrakk> y \\<noteq> x; y \\<notin> aexp_vars e; x \\<notin> \\<C>_vars y; \\<C>_vars y \\<inter> aexp_vars e = {} \\<rbrakk> \\<Longrightarrow> doesnt_read_or_modify ((x \\<leftarrow> e) \\<otimes> annos) y\"\n  apply (rule doesnt_read_annos)\nproof -\n  assume  \"y \\<noteq> x\"\n          \"y \\<notin> aexp_vars e\"\n          \"x \\<notin> \\<C>_vars y\"\n          \"\\<C>_vars y \\<inter> aexp_vars e = {}\"\n  thus \"doesnt_read_or_modify (x \\<leftarrow> e) y\"\n    unfolding doesnt_read_or_modify_def doesnt_read_or_modify_vars_def\n    apply -\n    apply (rule allI)+\n    apply (rename_tac mds mem c' mds' mem')\n    apply (rule impI)\n    apply (subgoal_tac \"c' = Stop \\<and> mds' = mds \\<and> mem' = mem (x := ev\\<^sub>A mem e)\")\n     apply simp\n     apply clarify\n     apply (rule conjI)\n      apply clarify\n      apply (subgoal_tac \"mem (x := ev\\<^sub>A mem e, y := v) = mem (y := v, x := ev\\<^sub>A mem e)\")\n       apply simp\n       apply (rule cxt_eval)\n       apply (rule eval\\<^sub>w.unannotated)      \n       apply (metis eval\\<^sub>w_simple.assign eval_vars_det\\<^sub>A fun_upd_apply)\n      apply (metis mem_upd_commute)\n     apply clarify\n     apply (rename_tac va v)\n     apply (subgoal_tac \"mem (x := ev\\<^sub>A mem e, va := v) = mem (va := v, x := ev\\<^sub>A mem e)\")\n      apply simp\n      apply (rule cxt_eval)\n      apply (rule eval\\<^sub>w.unannotated)\n      apply (subgoal_tac \"va \\<notin> aexp_vars e\")\n       apply (metis eval\\<^sub>w_simple.assign eval_vars_det\\<^sub>A fun_upd_apply)\n      apply blast\n     apply (metis mem_upd_commute)\n    apply (metis assign_elim)\n    done\nqed\n\nlemma assign_loc_reach:\n  \"\\<lbrakk> \\<langle>c', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>(x \\<leftarrow> e) \\<otimes> annos, mds, mem\\<rangle> \\<rbrakk> \\<Longrightarrow>\n  (c' = Stop \\<and> mds' = (mds \\<oplus> annos)) \\<or> (c' = (x \\<leftarrow> e) \\<otimes> annos \\<and> mds' = mds)\"\n  apply (induct rule: loc_reach.induct)\n    apply simp_all\n  by (metis assign_annos_eval_elim stop_no_eval)\n\nlemma if_doesnt_modify:\n  \"doesnt_modify (If e c\\<^sub>1 c\\<^sub>2 \\<otimes> annos) x\"\n  apply (rule doesnt_modify_annos)\n  by (auto simp: doesnt_modify_def)\n\nlemma vars_eval\\<^sub>B:\n  \"x \\<notin> bexp_vars e \\<Longrightarrow> ev\\<^sub>B mem e = ev\\<^sub>B (mem (x := v)) e\"\n  by (metis (lifting) eval_vars_det\\<^sub>B fun_upd_other)\n\nlemma if_doesnt_read:\n  \"x \\<notin> bexp_vars e \\<Longrightarrow> \\<C>_vars x \\<inter> bexp_vars e = {} \\<Longrightarrow> doesnt_read_or_modify (If e c\\<^sub>1 c\\<^sub>2 \\<otimes> annos) x\"\n  apply (rule doesnt_read_annos)\n  apply (clarsimp simp: doesnt_read_or_modify_def doesnt_read_or_modify_vars_def, safe)\n   apply (rename_tac mds mem c' mds' mem' v)\n   apply (case_tac \"ev\\<^sub>B mem e\")\n    apply (subgoal_tac \"c' = c\\<^sub>1 \\<and> mds' = mds \\<and> mem' = mem\")\n     prefer 2\n     apply auto[1]\n    apply clarsimp\n    apply (rule cxt_eval)\n    apply (rule eval\\<^sub>w.unannotated)\n    apply (rule eval\\<^sub>w_simple.if_true)\n    apply (metis (lifting) vars_eval\\<^sub>B)\n   apply (subgoal_tac \"c' = c\\<^sub>2 \\<and> mds' = mds \\<and> mem' = mem\")\n    prefer 2\n    apply auto[1]\n   apply clarsimp\n   apply (rule cxt_eval)\n   apply (rule eval\\<^sub>w.unannotated)\n   apply (rule eval\\<^sub>w_simple.if_false)\n   apply (metis (lifting) vars_eval\\<^sub>B)\n  apply (rename_tac mds mem c' mds' mem' va v)\n  apply (case_tac \"ev\\<^sub>B mem e\")\n   apply (subgoal_tac \"c' = c\\<^sub>1 \\<and> mds' = mds \\<and> mem' = mem\")\n    prefer 2\n    apply auto[1]\n   apply clarsimp\n   apply (rule cxt_eval)\n   apply (rule eval\\<^sub>w.unannotated)\n   apply (rule eval\\<^sub>w_simple.if_true)\n   apply (subgoal_tac \"va \\<notin> bexp_vars e\")\n    apply (metis (lifting) vars_eval\\<^sub>B)\n   apply blast\n  apply (subgoal_tac \"c' = c\\<^sub>2 \\<and> mds' = mds \\<and> mem' = mem\")\n   prefer 2\n   apply auto[1]\n  apply clarsimp\n  apply (rule cxt_eval)\n  apply (rule eval\\<^sub>w.unannotated)\n  apply (rule eval\\<^sub>w_simple.if_false)\n  apply (subgoal_tac \"va \\<notin> bexp_vars e\")\n   apply (metis (lifting) vars_eval\\<^sub>B)\n  apply blast\n  done\n  \nlemma if_eval_true:\n  \"\\<lbrakk> ev\\<^sub>B mem e \\<rbrakk> \\<Longrightarrow>\n  \\<langle>If e c\\<^sub>1 c\\<^sub>2 \\<otimes> annos, mds, mem\\<rangle> \\<leadsto> \\<langle>c\\<^sub>1, mds \\<oplus> annos, mem\\<rangle>\"\n  apply (induct annos arbitrary: mds)\n   apply simp\n   apply (metis cxt_eval eval\\<^sub>w.unannotated eval\\<^sub>w_simple.if_true)\n  by (metis annotate.simps(2) cxt_eval eval\\<^sub>w.decl update_annos.simps(2))\n\nlemma if_eval_false:\n  \"\\<lbrakk> \\<not> ev\\<^sub>B mem e \\<rbrakk> \\<Longrightarrow>\n  \\<langle>If e c\\<^sub>1 c\\<^sub>2 \\<otimes> annos, mds, mem\\<rangle> \\<leadsto> \\<langle>c\\<^sub>2, mds \\<oplus> annos, mem\\<rangle>\"\n  apply (induct annos arbitrary: mds)\n   apply simp\n   apply (metis cxt_eval eval\\<^sub>w.unannotated eval\\<^sub>w_simple.if_false)\n  by (metis annotate.simps(2) cxt_eval eval\\<^sub>w.decl update_annos.simps(2))\n\nlemma if_eval_elim:\n  \"\\<lbrakk> \\<langle>If e c\\<^sub>1 c\\<^sub>2 \\<otimes> annos, mds, mem\\<rangle> \\<leadsto> \\<langle>c', mds', mem'\\<rangle> \\<rbrakk> \\<Longrightarrow>\n  ((c' = c\\<^sub>1 \\<and> ev\\<^sub>B mem e) \\<or> (c' = c\\<^sub>2 \\<and> \\<not> ev\\<^sub>B mem e)) \\<and> mds' = mds \\<oplus> annos \\<and> mem' = mem\"\n  apply (rule ccontr)\n  apply (cases \"ev\\<^sub>B mem e\")\n   apply (insert if_eval_true deterministic)\n   apply blast\n  using if_eval_false deterministic\n  by blast\n\nlemma if_eval_elim':\n  \"\\<lbrakk> \\<langle>If e c\\<^sub>1 c\\<^sub>2, mds, mem\\<rangle> \\<leadsto> \\<langle>c', mds', mem'\\<rangle> \\<rbrakk> \\<Longrightarrow>\n  ((c' = c\\<^sub>1 \\<and> ev\\<^sub>B mem e) \\<or> (c' = c\\<^sub>2 \\<and> \\<not> ev\\<^sub>B mem e)) \\<and> mds' = mds \\<and> mem' = mem\"\n  using if_eval_elim [where annos = \"[]\"]\n  by auto\n\nlemma loc_reach_refl':\n  \"\\<langle>c, mds, mem\\<rangle> \\<in> loc_reach \\<langle>c, mds, mem\\<rangle>\"\n  apply (subgoal_tac \"\\<exists> lc. lc \\<in> loc_reach lc \\<and> lc = \\<langle>c, mds, mem\\<rangle>\")\n   apply blast\n  by (metis loc_reach.refl fst_conv snd_conv)\n\nlemma if_loc_reach:\n  \"\\<lbrakk> \\<langle>c', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>If e c\\<^sub>1 c\\<^sub>2 \\<otimes> annos, mds, mem\\<rangle> \\<rbrakk> \\<Longrightarrow>\n  (c' = If e c\\<^sub>1 c\\<^sub>2 \\<otimes> annos \\<and> mds' = mds) \\<or>\n  (\\<exists> mem''. \\<langle>c', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>c\\<^sub>1, mds \\<oplus> annos, mem''\\<rangle>) \\<or>\n  (\\<exists> mem''. \\<langle>c', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>c\\<^sub>2, mds \\<oplus> annos, mem''\\<rangle>)\"\n  apply (induct rule: loc_reach.induct)\n    apply (metis fst_conv snd_conv)\n   apply (erule disjE)\n    apply (erule conjE)\n    apply simp\n    apply (drule if_eval_elim)\n    apply (erule conjE)+\n    apply (erule disjE)\n     apply (erule conjE)\n     apply simp\n     apply (metis loc_reach_refl')\n    apply (metis loc_reach_refl')\n   apply (metis loc_reach.step)\n  by (metis loc_reach.mem_diff)\n\nlemma if_loc_reach':\n  \"\\<lbrakk> \\<langle>c', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>If e c\\<^sub>1 c\\<^sub>2, mds, mem\\<rangle> \\<rbrakk> \\<Longrightarrow>\n  (c' = If e c\\<^sub>1 c\\<^sub>2 \\<and> mds' = mds) \\<or>\n  (\\<exists> mem''. \\<langle>c', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>c\\<^sub>1, mds, mem''\\<rangle>) \\<or>\n  (\\<exists> mem''. \\<langle>c', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>c\\<^sub>2, mds, mem''\\<rangle>)\"\n  using if_loc_reach [where annos = \"[]\"]\n  by simp\n\nlemma seq_loc_reach:\n  \"\\<lbrakk> \\<langle>c', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>c\\<^sub>1 ;; c\\<^sub>2, mds, mem\\<rangle> \\<rbrakk> \\<Longrightarrow>\n  (\\<exists> c''. c' = c'' ;; c\\<^sub>2 \\<and> \\<langle>c'', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>c\\<^sub>1, mds, mem\\<rangle>) \\<or>\n  (\\<exists> c'' mds'' mem''. \\<langle>Stop, mds'', mem''\\<rangle> \\<in> loc_reach \\<langle>c\\<^sub>1, mds, mem\\<rangle> \\<and> \n                      \\<langle>c', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>c\\<^sub>2, mds'', mem''\\<rangle>)\"\n  apply (induct rule: loc_reach.induct)\n    apply simp\n    apply (metis  loc_reach_refl')\n   apply simp\n   apply (metis (no_types) loc_reach.step loc_reach_refl' seq_elim seq_stop_elim)\n  by (metis (lifting) loc_reach.mem_diff)\n\nlemma seq_doesnt_read:\n  \"\\<lbrakk> doesnt_read_or_modify c x \\<rbrakk> \\<Longrightarrow> doesnt_read_or_modify (c ;; c') x\"\n  apply (clarsimp simp: doesnt_read_or_modify_def doesnt_read_or_modify_vars_def | safe)+\n   apply (rename_tac mds mem c'a mds' mem' v)\n   apply (case_tac \"c = Stop\")\n    apply clarsimp\n    apply (subgoal_tac \"c'a = c' \\<and> mds' = mds \\<and> mem' = mem\")\n     apply simp\n     apply (metis cxt_eval eval\\<^sub>w.unannotated eval\\<^sub>w_simple.seq_stop)\n    apply (metis (lifting) seq_stop_elim)\n   apply (metis (lifting, no_types) eval\\<^sub>w.seq seq_elim)\n  apply (rename_tac mds mem c'a mds' mem' va v)\n  apply (case_tac \"c = Stop\")\n   apply clarsimp\n   apply (subgoal_tac \"c'a = c' \\<and> mds' = mds \\<and> mem' = mem\")\n    apply simp\n    apply (metis cxt_eval eval\\<^sub>w.unannotated eval\\<^sub>w_simple.seq_stop)\n   apply (metis (lifting) seq_stop_elim)\n  apply (metis (lifting, no_types) eval\\<^sub>w.seq seq_elim)\n  done\n  \n\n\n\n\nlemma seq_split:\n  \"\\<lbrakk> \\<langle>Stop, mds', mem'\\<rangle> \\<in> loc_reach \\<langle>c\\<^sub>1 ;; c\\<^sub>2, mds, mem\\<rangle> \\<rbrakk> \\<Longrightarrow>\n  \\<exists> mds'' mem''. \\<langle>Stop, mds'', mem''\\<rangle> \\<in> loc_reach \\<langle>c\\<^sub>1, mds, mem\\<rangle> \\<and>\n                 \\<langle>Stop, mds', mem'\\<rangle> \\<in> loc_reach \\<langle>c\\<^sub>2, mds'', mem''\\<rangle>\"\n  apply (drule seq_loc_reach)\n  by (metis Stmt.simps(49))\n\nlemma while_eval:\n  \"\\<langle>While e c \\<otimes> annos, mds, mem\\<rangle> \\<leadsto> \\<langle>(If e (c ;; While e c) Stop), mds \\<oplus> annos, mem\\<rangle>\"\n  apply (induct annos arbitrary: mds)\n   apply simp\n   apply (rule cxt_eval)\n   apply (rule eval\\<^sub>w.unannotated)\n   apply (metis (lifting) eval\\<^sub>w_simple.while)\n  apply simp\n  by (metis cxt_eval eval\\<^sub>w.decl)\n\nlemma while_eval':\n  \"\\<langle>While e c, mds, mem\\<rangle> \\<leadsto> \\<langle>If e (c ;; While e c) Stop, mds, mem\\<rangle>\"\n  using while_eval [where annos = \"[]\"]\n  by auto\n\nlemma while_eval_elim:\n  \"\\<lbrakk> \\<langle>While e c \\<otimes> annos, mds, mem\\<rangle> \\<leadsto> \\<langle>c', mds', mem'\\<rangle> \\<rbrakk> \\<Longrightarrow>\n   (c' = If e (c ;; While e c) Stop \\<and> mds' = mds \\<oplus> annos \\<and> mem' = mem)\"\n  apply (rule ccontr)\n  apply (insert while_eval deterministic)\n  by blast\n\nlemma while_eval_elim':\n  \"\\<lbrakk> \\<langle>While e c, mds, mem\\<rangle> \\<leadsto> \\<langle>c', mds', mem'\\<rangle> \\<rbrakk> \\<Longrightarrow>\n   (c' = If e (c ;; While e c) Stop \\<and> mds' = mds \\<and> mem' = mem)\"\n  using while_eval_elim [where annos = \"[]\"]\n  by auto\n\nlemma while_doesnt_read:\n  \"\\<lbrakk> x \\<notin> bexp_vars e \\<rbrakk> \\<Longrightarrow> doesnt_read_or_modify (While e c \\<otimes> annos) x\"\n  unfolding doesnt_read_or_modify_def doesnt_read_or_modify_vars_def\n  using while_eval while_eval_elim\n  by metis\n\nlemma while_doesnt_modify:\n  \"doesnt_modify (While e c \\<otimes> annos) x\"\n  unfolding doesnt_modify_def\n  using while_eval_elim\n  by metis\n\n(* TODO: try to find a better solution to this: *)\nlemma disjE3:\n  \"\\<lbrakk> A \\<or> B \\<or> C ; A \\<Longrightarrow> P ; B \\<Longrightarrow> P ; C \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P\"\n  by auto\n\nlemma disjE5:\n  \"\\<lbrakk> A \\<or> B \\<or> C \\<or> D \\<or> E ; A \\<Longrightarrow> P ; B \\<Longrightarrow> P ; C \\<Longrightarrow> P ; D \\<Longrightarrow> P ; E \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P\"\n  by auto\n\nlemma if_doesnt_read':\n  \"x \\<notin> bexp_vars e \\<Longrightarrow> \\<C>_vars x \\<inter> bexp_vars e = {} \\<Longrightarrow> doesnt_read_or_modify (If e c\\<^sub>1 c\\<^sub>2) x\"\n  using if_doesnt_read [where annos = \"[]\"]\n  by auto\n\ntheorem mode_type_sound:\n  assumes typeable: \"\\<turnstile> mds\\<^sub>1 { c } mds\\<^sub>1'\"\n  assumes mode_le: \"mds\\<^sub>2 \\<le> mds\\<^sub>1\"\n  shows \"\\<forall> mem. (\\<langle>Stop, mds\\<^sub>2', mem'\\<rangle> \\<in> loc_reach \\<langle>c, mds\\<^sub>2, mem\\<rangle> \\<longrightarrow> mds\\<^sub>2' \\<le> mds\\<^sub>1') \\<and> \n                locally_sound_mode_use \\<langle>c, mds\\<^sub>2, mem\\<rangle>\"\n  using typeable mode_le\nproof (induct arbitrary: mds\\<^sub>2 mds\\<^sub>2' mem' mem rule: mode_type.induct)\n  case (skip mds annos)\n  thus ?case\n    apply (clarsimp, intro conjI)\n     apply (metis (lifting) skip_eval_step skip_loc_reach stop_no_eval update_preserves_le)\n    apply (simp add: locally_sound_mode_use_def)\n    by (metis annotate.simps skip_doesnt_access)\nnext\n  case (assign x mds e annos)\n  hence \"\\<forall> mem. locally_sound_mode_use \\<langle>(x \\<leftarrow> e) \\<otimes> annos, mds\\<^sub>2, mem\\<rangle>\"\n    unfolding locally_sound_mode_use_def\n  proof (clarify)\n    fix mem c' mds' mem' y\n    assume asm: \"\\<langle>c', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>(x \\<leftarrow> e) \\<otimes> annos, mds\\<^sub>2, mem\\<rangle>\"\n    hence \"c' = (x \\<leftarrow> e) \\<otimes> annos \\<and> mds' = mds\\<^sub>2 \\<or> c' = Stop \\<and> mds' = mds\\<^sub>2 \\<oplus> annos\"\n      using assign_loc_reach by blast\n    thus \"(y \\<in> mds' GuarNoReadOrWrite \\<longrightarrow> doesnt_read_or_modify c' y) \\<and>\n          (y \\<in> mds' GuarNoWrite \\<longrightarrow> doesnt_modify c' y)\"\n    proof\n      assume \"c' = (x \\<leftarrow> e) \\<otimes> annos \\<and> mds' = mds\\<^sub>2\"\n      thus ?thesis\n      proof (safe)\n        assume nin: \"y \\<in> mds\\<^sub>2 GuarNoReadOrWrite\"\n        hence nin: \"y \\<in> mds GuarNoReadOrWrite\"\n          using assign.prems unfolding le_fun_def by blast\n        hence \"y \\<notin> aexp_vars e\"\n          by (metis IntD2 IntI assign.hyps(2) assign.prems empty_iff inf_apply le_iff_inf)\n        moreover from nin assign.hyps(3) have \"\\<C>_vars y \\<inter> aexp_vars e = {}\"\n          by (meson contra_subsetD)\n        moreover from nin assign.hyps have \"x \\<notin> \\<C>_vars y \\<and> x \\<noteq> y\"\n          by blast\n        ultimately show \"doesnt_read_or_modify ((x \\<leftarrow> e) \\<otimes> annos) y\"\n          using assign_doesnt_read\n          by fastforce\n      next\n        assume \"y \\<in> mds\\<^sub>2 GuarNoWrite\"\n        hence nin: \"y \\<in> mds GuarNoWrite\"\n          using assign.prems unfolding le_fun_def by blast\n        hence \"x \\<noteq> y \\<and> x \\<notin> \\<C>_vars y\"\n          using assign by blast\n        with assign_doesnt_modify show \"doesnt_modify ((x \\<leftarrow> e) \\<otimes> annos) y\"\n          by blast\n      qed\n    next\n      assume \"c' = Stop \\<and> mds' = mds\\<^sub>2 \\<oplus> annos\"\n      with stop_doesnt_access show ?thesis by blast\n    qed\n  qed\n  thus ?case\n    apply clarsimp\n    by (metis assign.prems assign_annos_eval assign_loc_reach stop_no_eval update_preserves_le)\nnext\n  case (if_ mds annos c\\<^sub>1 mds'' c\\<^sub>2 e)\n    let ?c = \"(If e c\\<^sub>1 c\\<^sub>2) \\<otimes> annos\"\n  from if_ have modes_le': \"mds\\<^sub>2 \\<oplus> annos \\<le> mds \\<oplus> annos\"\n    by (metis (lifting) update_preserves_le)\n  from if_ show ?case\n    apply (simp add: locally_sound_mode_use_def)\n    apply clarify\n    apply (rule conjI)\n     apply clarify\n     prefer 2\n     apply clarify\n  proof -\n    fix mem\n    assume \"\\<langle>Stop, mds\\<^sub>2', mem'\\<rangle> \\<in> loc_reach \\<langle>If e c\\<^sub>1 c\\<^sub>2 \\<otimes> annos, mds\\<^sub>2, mem\\<rangle>\"\n    with modes_le' and if_ show \"mds\\<^sub>2' \\<le> mds''\"\n      by (metis if_eval_false if_eval_true if_loc_reach stop_no_eval)\n  next\n    fix mem c' mds' mem' x\n    assume \"\\<langle>c', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>If e c\\<^sub>1 c\\<^sub>2 \\<otimes> annos, mds\\<^sub>2, mem\\<rangle>\"\n    hence \"(c' = If e c\\<^sub>1 c\\<^sub>2 \\<otimes> annos \\<and> mds' = mds\\<^sub>2) \\<or>\n           (\\<exists> mem''. \\<langle>c', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>c\\<^sub>1, mds\\<^sub>2 \\<oplus> annos, mem''\\<rangle>) \\<or>\n           (\\<exists> mem''. \\<langle>c', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>c\\<^sub>2, mds\\<^sub>2 \\<oplus> annos, mem''\\<rangle>)\"\n      using if_loc_reach by blast\n    thus \"(x \\<in> mds' GuarNoReadOrWrite \\<longrightarrow> doesnt_read_or_modify c' x) \\<and>\n          (x \\<in> mds' GuarNoWrite \\<longrightarrow> doesnt_modify c' x)\"\n    proof\n      assume \"c' = If e c\\<^sub>1 c\\<^sub>2 \\<otimes> annos \\<and> mds' = mds\\<^sub>2\"\n      thus ?thesis\n      proof (safe)\n        assume \"x \\<in> mds\\<^sub>2 GuarNoReadOrWrite\"\n        hence nin: \"x \\<in> mds GuarNoReadOrWrite\"\n          using if_ unfolding le_fun_def by auto\n        with \\<open>bexp_vars e \\<inter> mds GuarNoReadOrWrite = {}\\<close> have \"x \\<notin> bexp_vars e\"\n          by (metis IntD2 disjoint_iff_not_equal)\n        moreover from if_(6) nin have \"\\<C>_vars x \\<inter> bexp_vars e = {}\"\n          by blast\n        ultimately show \"doesnt_read_or_modify (If e c\\<^sub>1 c\\<^sub>2 \\<otimes> annos) x\"\n          using if_doesnt_read by blast\n      next\n        assume \"x \\<in> mds\\<^sub>2 GuarNoWrite\"\n        thus \"doesnt_modify (If e c\\<^sub>1 c\\<^sub>2 \\<otimes> annos) x\"\n          using if_doesnt_modify by blast\n      qed\n    next\n      assume \"(\\<exists>mem''. \\<langle>c', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>c\\<^sub>1, mds\\<^sub>2 \\<oplus> annos, mem''\\<rangle>) \\<or>\n              (\\<exists>mem''. \\<langle>c', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>c\\<^sub>2, mds\\<^sub>2 \\<oplus> annos, mem''\\<rangle>)\"\n      with if_ show ?thesis\n        by (metis locally_sound_mode_use_def modes_le')\n    qed\n  qed\nnext\n  case (while mdsa mds annos c e)\n  hence \"mds\\<^sub>2 \\<oplus> annos \\<le> mds \\<oplus> annos\"\n    by (metis (lifting) update_preserves_le)\n  have while_loc_reach: \"\\<And> c' mds' mem' mem.\n  \\<langle>c', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>While e c \\<otimes> annos, mds\\<^sub>2, mem\\<rangle> \\<Longrightarrow>\n  c' = While e c \\<otimes> annos \\<and> mds' = mds\\<^sub>2 \\<or>\n  c' = While e c \\<and> mds' \\<le> mdsa \\<or>\n  c' = Stmt.If e (c ;; While e c) Stop \\<and> mds' \\<le> mdsa \\<or>\n  c' = Stop \\<and> mds' \\<le> mdsa \\<or>\n  (\\<exists>c'' mem'' mds\\<^sub>3.\n      c' = c'' ;; While e c \\<and>\n      mds\\<^sub>3 \\<le> mdsa \\<and> \\<langle>c'', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>c, mds\\<^sub>3, mem''\\<rangle>)\"\n  proof -\n    fix mem c' mds' mem'\n    assume \"\\<langle>c', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>While e c \\<otimes> annos, mds\\<^sub>2, mem\\<rangle>\"\n    thus \"?thesis c' mds' mem' mem\"\n      apply (induct rule: loc_reach.induct)\n        apply simp_all\n       apply (erule disjE)\n        apply simp\n        apply (metis \\<open>mds\\<^sub>2 \\<oplus> annos \\<le> mds \\<oplus> annos\\<close> while.hyps(1) while_eval_elim)\n       apply (erule disjE)\n        apply (metis while_eval_elim')\n       apply (erule disjE)\n        apply simp\n        apply (metis if_eval_elim' loc_reach_refl')\n       apply (erule disjE)\n        apply (metis stop_no_eval)\n       apply (erule exE)\n       apply (rename_tac c' mds' mem' c'' mds'' mem'' c''a)\n       apply (case_tac \"c''a = Stop\")\n        apply (insert while.hyps(3))\n        apply (metis seq_stop_elim while.hyps(3))\n       apply (metis loc_reach.step seq_elim)\n      by (metis (full_types) loc_reach.mem_diff)\n  qed\n  from while show ?case\n  proof (safe)\n    fix mem\n    assume \"\\<langle>Stop, mds\\<^sub>2', mem'\\<rangle> \\<in> loc_reach \\<langle>While e c \\<otimes> annos, mds\\<^sub>2, mem\\<rangle>\"\n    thus \"mds\\<^sub>2' \\<le> mds \\<oplus> annos\"\n      by (metis Stmt.distinct(35) Stmt.distinct(43) annotate.elims update_annos.simps(1) while.hyps(1) while.prems while_loc_reach)\n  next\n    fix mem\n    from while have a: \"bexp_vars e \\<inter> (mds\\<^sub>2 \\<oplus> annos) GuarNoReadOrWrite = {}\"\n      by (metis (lifting, no_types) Int_empty_right Int_left_commute \\<open>mds\\<^sub>2 \\<oplus> annos \\<le> mds \\<oplus> annos\\<close> inf_fun_def le_iff_inf)\n    from while have b: \"\\<forall>v.  \\<C>_vars v \\<inter> bexp_vars e \\<noteq> {} \\<longrightarrow> v \\<notin> (mds\\<^sub>2 \\<oplus> annos) GuarNoReadOrWrite\"\n      by (meson \\<open>mds\\<^sub>2 \\<oplus> annos \\<le> mds \\<oplus> annos\\<close> le_fun_def subsetCE)    \n    show \"locally_sound_mode_use \\<langle>While e c \\<otimes> annos, mds\\<^sub>2, mem\\<rangle>\"\n      unfolding locally_sound_mode_use_def\n      apply (rule allI)+\n      apply (rule impI)\n    proof -\n      fix c' mds' mem'\n      define lc where \"lc = \\<langle>While e c \\<otimes> annos, mds\\<^sub>2, mem\\<rangle>\"\n      assume \"\\<langle>c', mds', mem'\\<rangle> \\<in> loc_reach lc\"\n      thus \"\\<forall>x. (x \\<in> mds' GuarNoReadOrWrite \\<longrightarrow> doesnt_read_or_modify c' x) \\<and>\n                 (x \\<in> mds' GuarNoWrite \\<longrightarrow> doesnt_modify c' x)\"\n        apply (simp add: lc_def)\n        apply (drule while_loc_reach)\n        apply (rule allI)\n        apply (erule disjE5)\n      proof (clarsimp)\n        fix x\n        show \"(x \\<in> mds\\<^sub>2 GuarNoReadOrWrite \\<longrightarrow> doesnt_read_or_modify (While e c \\<otimes> annos) x) \\<and>\n              (x \\<in> mds\\<^sub>2 GuarNoWrite \\<longrightarrow> doesnt_modify (While e c \\<otimes> annos) x)\"\n          unfolding doesnt_read_or_modify_def doesnt_read_or_modify_vars_def and doesnt_modify_def\n          using while_eval and while_eval_elim\n          by blast\n      next\n        fix x\n        assume a: \"c' = Stmt.If e (c ;; While e c) Stop \\<and> mds' \\<le> mdsa\"\n        hence \"mds' \\<le> mdsa\" by blast\n        let ?c' = \"If e (c ;; While e c) Stop\"\n        have \"x \\<in> mds' GuarNoReadOrWrite \\<longrightarrow> doesnt_read_or_modify ?c' x\"\n          apply clarify\n          apply (rule if_doesnt_read')\n           apply (metis IntI \\<open>mds' \\<le> mdsa\\<close> empty_iff le_fun_def rev_subsetD while.hyps(1) while.hyps(4))\n          by (metis IntI \\<open>mds' \\<le> mdsa\\<close> empty_iff le_fun_def rev_subsetD while.hyps(1) while.hyps(5))\n        moreover\n        have \"x \\<in> mds' GuarNoWrite \\<longrightarrow> doesnt_modify ?c' x\"\n          by (metis annotate.simps(1) if_doesnt_modify)\n        ultimately show \"(x \\<in> mds' GuarNoReadOrWrite \\<longrightarrow> doesnt_read_or_modify c' x) \\<and>\n                         (x \\<in> mds' GuarNoWrite \\<longrightarrow> doesnt_modify c' x)\"\n          using a by simp \n      next\n        fix x\n        assume \"c' = Stop \\<and> mds' \\<le> mdsa\"\n        thus \"(x \\<in> mds' GuarNoReadOrWrite \\<longrightarrow> doesnt_read_or_modify c' x) \\<and>\n              (x \\<in> mds' GuarNoWrite \\<longrightarrow> doesnt_modify c' x)\"\n          by (simp, metis stop_doesnt_access)\n      next\n        fix x\n        assume \"\\<exists>c'' mem'' mds\\<^sub>3.\n            c' = c'' ;; While e c \\<and>\n            mds\\<^sub>3 \\<le> mdsa \\<and>\n            \\<langle>c'', mds', mem'\\<rangle>\n            \\<in> loc_reach \\<langle>c, mds\\<^sub>3, mem''\\<rangle>\"\n        from this obtain\n         c'' mem'' mds\\<^sub>3\n        where \"mds\\<^sub>3 \\<le> mdsa\" and [simp]: \"c' = c'' ;; While e c\"\n        and \"\\<langle>c'', mds', mem'\\<rangle> \\<in> loc_reach \\<langle>c, mds\\<^sub>3, mem''\\<rangle>\" by blast\n        thus \"(x \\<in> mds' GuarNoReadOrWrite \\<longrightarrow> doesnt_read_or_modify c' x) \\<and>\n              (x \\<in> mds' GuarNoWrite \\<longrightarrow> doesnt_modify c' x)\"\n          apply (clarsimp, safe)\n           apply (rule seq_doesnt_read)\n           apply (insert while(3))\n           apply (metis \\<open>mds\\<^sub>3 \\<le> mdsa\\<close> locally_sound_mode_use_def while.hyps(1))\n          apply (rule seq_doesnt_modify)\n          by (metis \\<open>mds\\<^sub>3 \\<le> mdsa\\<close> locally_sound_mode_use_def while.hyps(1))\n      next\n        fix x\n        assume \"c' = While e c \\<and> mds' \\<le> mdsa\"\n        thus \"(x \\<in> mds' GuarNoReadOrWrite \\<longrightarrow> doesnt_read_or_modify c' x) \\<and>\n              (x \\<in> mds' GuarNoWrite \\<longrightarrow> doesnt_modify c' x)\"\n          unfolding doesnt_read_or_modify_def doesnt_read_or_modify_vars_def and doesnt_modify_def\n          using while_eval' and while_eval_elim'\n          by blast\n      qed\n    qed\n  qed\nnext\n  case (seq mds c\\<^sub>1 mds' c\\<^sub>2 mds'')\n  thus ?case\n  proof (safe)\n    fix mem\n    assume \"\\<langle>Stop, mds\\<^sub>2', mem'\\<rangle> \\<in> loc_reach \\<langle>c\\<^sub>1 ;; c\\<^sub>2, mds\\<^sub>2, mem\\<rangle>\"\n    then obtain mds\\<^sub>2'' mem'' where \"\\<langle>Stop, mds\\<^sub>2'', mem''\\<rangle> \\<in> loc_reach \\<langle>c\\<^sub>1, mds\\<^sub>2, mem\\<rangle>\" and\n      \"\\<langle>Stop, mds\\<^sub>2', mem'\\<rangle> \\<in> loc_reach \\<langle>c\\<^sub>2, mds\\<^sub>2'', mem''\\<rangle>\"\n      using seq_split by blast\n    thus \"mds\\<^sub>2' \\<le> mds''\"\n      using seq by blast\n  next\n    fix mem\n    from seq show \"locally_sound_mode_use \\<langle>c\\<^sub>1 ;; c\\<^sub>2, mds\\<^sub>2, mem\\<rangle>\"\n      apply (simp add: locally_sound_mode_use_def)\n      apply clarify\n      apply (drule seq_loc_reach)\n      apply (erule disjE)\n       apply (metis seq_doesnt_modify seq_doesnt_read)\n      by metis\n  qed\nnext\n  case (sub mds\\<^sub>2'' c mds\\<^sub>2' mds\\<^sub>1 mds\\<^sub>1' c\\<^sub>1)\n  thus ?case\n    apply clarsimp\n    by (metis (hide_lams, no_types) inf_absorb2 le_infI1)\nqed\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Dependent_SIFUM_Type_Systems/LocallySoundModeUse.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5813030906443133, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.2951926061713521}}
{"text": "section \\<open>Options and Maps with Default Value for None\\<close>\ntheory Array_Map_Default\nimports Dynamic_Array DRAT_Misc\nbegin\n  text \\<open>Implements maps from natural numbers to any value type that has an \n    unused default value in its implementation type. \n    Internally, uses a dynamic array.\n    \\<close>\n  definition \"is_unused_elem dflt A \\<equiv> \\<forall>x. A x dflt = false\"\n  lemma is_unused_elem_pure[simp]: \n    \"is_unused_elem dflt (pure R) \\<longleftrightarrow> dflt \\<notin> Domain R\"\n    unfolding is_unused_elem_def\n    by (auto simp: pure_rel_eq_false_iff)\n  \n  \n  definition \"dflt_option_rel_aux dflt \n    \\<equiv> { (dflt,None) } \\<union> { (x, Some x) | x. x\\<noteq>dflt }\"\n  definition [to_relAPP]: \"dflt_option_assn dflt A \n    \\<equiv> pure (dflt_option_rel_aux dflt O \\<langle>the_pure A\\<rangle>option_rel)\"\n  \n  subsection \\<open>Function-Level Map Operations\\<close>  \n  text \\<open>We justify the map operations implemented by a function\\<close>\n  lemma amd1_empty_refine: \n    \"(uncurry0 (\\<lambda>_. dflt), uncurry0 op_map_empty) \n    \\<in> Id \\<rightarrow>\\<^sub>f (Id \\<rightarrow> dflt_option_rel_aux dflt)\"\n    by (auto simp: dflt_option_rel_aux_def fref_def)\n  \n  lemma amd1_lookup_refine: \n    \"(\\<lambda>x f. f x, op_map_lookup) \n    \\<in> Id \\<rightarrow> (Id \\<rightarrow> dflt_option_rel_aux dflt) \\<rightarrow> dflt_option_rel_aux dflt\"\n    apply simp by parametricity\n  \n  lemma amd1_update_refine: \n    \"(uncurry2 (\\<lambda>k v f. f(k:=v)), uncurry2 op_map_update) \n    \\<in> [\\<lambda>((k,v),m). v\\<noteq>dflt]\\<^sub>f \n      ((Id \\<times>\\<^sub>r Id) \\<times>\\<^sub>r (Id \\<rightarrow> dflt_option_rel_aux dflt)) \n      \\<rightarrow> (Id \\<rightarrow> dflt_option_rel_aux dflt)\"\n    unfolding op_map_update_def\n    apply (rule frefI)\n    apply auto\n    applyS (auto simp: dflt_option_rel_aux_def)\n    applyS (parametricity; simp)\n    done\n  \n  definition [simp]: \"amd1_delete dflt k f \\<equiv> fun_upd f k dflt\"\n  lemma amd1_delete_refine: \n    \"(uncurry (amd1_delete dflt), uncurry op_map_delete) \n    \\<in> Id \\<times>\\<^sub>r (Id \\<rightarrow> dflt_option_rel_aux dflt) \\<rightarrow>\\<^sub>f (Id \\<rightarrow> dflt_option_rel_aux dflt)\"\n    unfolding op_map_delete_def PR_CONST_def amd1_delete_def\n    apply (rule frefI)\n    apply parametricity\n    apply (auto simp: dflt_option_rel_aux_def)\n    done\n\n  subsection \\<open>Map Operations, array-level\\<close>\n  text \\<open>We use dynamic arrays to implement the function, and combine both to \n      implement the map interface.\\<close>\n  definition [code_unfold]: \"amd_empty dflt \\<equiv> dyn_array_new_sz dflt 16\"\n  definition [code_unfold]: \"amd_lookup dflt k a \\<equiv> array_get_dyn dflt a k\"\n  definition [code_unfold]: \"amd_update dflt k v a \\<equiv> array_set_dyn dflt a k v\"\n  definition [code_unfold]: \"amd_delete dflt k a \\<equiv> array_set_dyn dflt a k dflt\"\n \n  definition \"amd_assn dflt K V \n    \\<equiv> hr_comp (hr_comp \n        (is_nff dflt) \n        (nat_rel \\<rightarrow>\\<^sub>f dflt_option_rel_aux dflt)) \n        (\\<langle>the_pure K, the_pure V\\<rangle>map_rel)\"\n    \n  lemma amd_assn_fold2: \"hr_comp (hr_comp \n      (is_nff dflt) \n      (nat_rel \\<rightarrow> dflt_option_rel_aux dflt)) \n      (\\<langle>the_pure K, the_pure V\\<rangle>map_rel) \n    = amd_assn dflt K V\"\n    unfolding amd_assn_def\n    apply (fo_rule fun_cong arg_cong)+\n    unfolding fref_def fun_rel_def by auto\n  \n  (* TODO: Move *)\n  lemmas [intf_of_assn] \n    = intf_of_assnI[where R=\"amd_assn dflt K V\" \n                      and 'a=\"(nat,'vv) i_map\" for dflt K V]\n  \n  lemmas [safe_constraint_rules] \n    = CN_FALSEI[of is_pure \"amd_assn dflt K V\" for dflt K V]\n    \n    \ncontext \n  notes [fcomp_norm_unfold] = \n    amd_assn_def[symmetric] dflt_option_assn_def[symmetric] amd_assn_fold2\n  notes [intro!] = hfrefI hn_refineI[THEN hn_refine_preI]\n  notes [simp] = pure_def hn_ctxt_def invalid_assn_def \n  fixes dflt :: \"'a::heap\"\nbegin  \n  lemma amd2_empty_refine: \n    \"(uncurry0 (amd_empty dflt), uncurry0 (RETURN (\\<lambda>_. dflt))) \n    \\<in> unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a is_nff dflt\"\n    by (sep_auto simp: amd_empty_def)\n\n  lemma amd2_lookup_refine: \n    \"(uncurry (amd_lookup dflt), uncurry (RETURN oo (\\<lambda>x f. f x))) \n    \\<in> id_assn\\<^sup>k*\\<^sub>a(is_nff dflt)\\<^sup>k \\<rightarrow>\\<^sub>a id_assn\"  \n    by (sep_auto simp: amd_lookup_def)\n\n  lemma amd2_update_refine: \n    \"(uncurry2 (amd_update dflt), uncurry2 (RETURN ooo (\\<lambda>k v f. f(k:=v)))) \n    \\<in> id_assn\\<^sup>k*\\<^sub>aid_assn\\<^sup>k*\\<^sub>a(is_nff dflt)\\<^sup>d \\<rightarrow>\\<^sub>a is_nff dflt\"\n    by (sep_auto simp: amd_update_def)\n\n  lemma amd2_delete_refine: \n    \"(uncurry (amd_delete dflt), uncurry (RETURN oo (amd1_delete dflt))) \n    \\<in> id_assn\\<^sup>k*\\<^sub>a(is_nff dflt)\\<^sup>d \\<rightarrow>\\<^sub>a is_nff dflt\"\n    by (sep_auto simp: amd_delete_def)\n  \n  sepref_decl_impl (no_register) amd_empty: \n    amd2_empty_refine[FCOMP amd1_empty_refine[where dflt=dflt]] .\n      \n  definition [simp]: \"op_amd_empty \\<equiv> op_map_empty\"    \n    \n  sepref_decl_impl \n    amd2_lookup_refine[FCOMP amd1_lookup_refine[where dflt=dflt]] .\n  sepref_decl_impl \n    amd2_delete_refine[FCOMP amd1_delete_refine[where dflt=dflt]] .\n\n  text \\<open>The only complication arises for the update operation, where we have \n    to use the fact that the default element is invalid, which forces us to do\n    a manual composition proof.\\<close>\n  lemma amd2_update_hnr_aux:\n    assumes \"CONSTRAINT (IS_PURE single_valued) K\"\n      and \"CONSTRAINT (IS_PURE IS_LEFT_UNIQUE) K\"\n      and \"CONSTRAINT is_pure V\"\n      and \"CONSTRAINT (is_unused_elem dflt) V\"\n    shows \"(uncurry2 (amd_update dflt), uncurry2 (RETURN \\<circ>\\<circ>\\<circ> op_map_update))\n           \\<in>  K\\<^sup>k *\\<^sub>a V\\<^sup>k *\\<^sub>a (amd_assn dflt K V)\\<^sup>d \\<rightarrow>\\<^sub>a amd_assn dflt K V\"    \n    apply (rule \n        hfref_cons[\n          OF amd2_update_refine[\n                FCOMP amd1_update_refine[where dflt=dflt], \n                FCOMP (no_prenorm) op_map_update.fref, of K V]])\n    subgoal using assms by (simp add: IS_PURE_def)\n    subgoal using assms by (simp add: IS_PURE_def)\n    subgoal using assms by (simp add: IS_PURE_def)\n    subgoal using assms by (simp add: IS_PURE_def IS_LEFT_UNIQUE_def)\n    subgoal\n      using assms\n      by (auto \n          simp del: pure_def\n          simp: comp_PRE_def IS_PURE_def is_unused_elem_def is_pure_conv \n          simp: pure_rel_eq_false_iff \n          elim!: prod_relE)\n    applyS simp\n    applyS simp\n    applyS simp\n    done\n\n  (* TODO: Somewhat of a hack. Perhaps add a flag to switch of \n      automatic parameterization on sepref_decl_impl? *)\n  private lemma op_map_update_id_param: \n    \"(uncurry2 (RETURN \\<circ>\\<circ>\\<circ> op_map_update), uncurry2 (RETURN \\<circ>\\<circ>\\<circ> op_map_update)) \n    \\<in> (Id\\<times>\\<^sub>rId)\\<times>\\<^sub>rId \\<rightarrow>\\<^sub>f \\<langle>Id\\<rangle>nres_rel\" \n    by (simp add: fref_def nres_rel_def)\n  \n  sepref_decl_impl amd2_update_hnr_aux uses op_map_update_id_param .\n\nend  \n\ninterpretation amd: map_custom_empty op_amd_empty apply unfold_locales by auto \nlemmas [sepref_fr_rules] = amd_empty_hnr[folded op_amd_empty_def]\n  \n  \nsubsection \\<open>Operations on Options\\<close>\n\ntext \\<open>We give own names to constructors, otherwise, we will get confusions \n  with the default option refinement.\\<close>\ndefinition [simp]: \"dflt_None \\<equiv> None\"\ndefinition [simp]: \"dflt_Some \\<equiv> Some\"\nsepref_register dflt_None dflt_Some\n\nlemma doa_None_hnr: \n  \"(uncurry0 (return dflt), uncurry0 (RETURN dflt_None)) \n  \\<in> unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a dflt_option_assn dflt A\"\n  apply (sepref_to_hoare)\n  apply (sep_auto simp: pure_def dflt_option_rel_aux_def dflt_option_assn_def)\n  done  \n\nlemma doa_Some_hnr: \"\\<lbrakk>CONSTRAINT (is_unused_elem dflt) A; CONSTRAINT is_pure A\\<rbrakk> \n  \\<Longrightarrow> (return o (\\<lambda>x. x), RETURN o dflt_Some) \\<in> A\\<^sup>k \\<rightarrow>\\<^sub>a dflt_option_assn dflt A\"\n  apply (sepref_to_hoare)\n  apply (clarsimp simp: is_pure_conv dflt_option_assn_def)\n  apply (sep_auto simp: pure_def)\n  apply (fastforce simp: dflt_option_rel_aux_def)\n  done  \n\nlemma doa_is_None_hnr[sepref_fr_rules]: \n  \"(return o ((=) dflt), RETURN o is_None) \n  \\<in> (dflt_option_assn dflt A)\\<^sup>k \\<rightarrow>\\<^sub>a bool_assn\"\n  apply (sepref_to_hoare)\n  by (sep_auto \n        simp: dflt_option_assn_def pure_def dflt_option_rel_aux_def \n        split: option.split)\n\nlemma doa_the_hnr[sepref_fr_rules]: \"\\<lbrakk>CONSTRAINT is_pure A\\<rbrakk> \n  \\<Longrightarrow> (return o (\\<lambda>x. x), RETURN o the) \n      \\<in> [\\<lambda>x. x\\<noteq>None]\\<^sub>a (dflt_option_assn dflt A)\\<^sup>k \\<rightarrow> A\"\n  apply (sepref_to_hoare)\n  apply (clarsimp simp: is_pure_conv dflt_option_assn_def)\n  apply (sep_auto simp: pure_def dflt_option_rel_aux_def)\n  done\n\n(* TODO: Add proper rule for case distinction *)\n\n(* Workaround for case-distinction: Rewrite with abstract-level rule: *)\nlemma cnv_option_case_2_if: \"(case x of None \\<Rightarrow> fn | Some v \\<Rightarrow> fv v) \n  \\<longleftrightarrow> (if is_None x then fn else fv (the x))\" by (cases x) auto\n\n\n(* TODO: Hack:\n  Due to lack of recursive generic algorithms with specialization, \n  we have instantiated equality on options as combinator rule. \n  This allows no backtracking or alternatives.\n  Thus, we do a type-based rewriting of option-equalities for dflt-option \n  types in operator-id phase.\n*)\ndefinition [simp]: \"dflt_option_eq \\<equiv> (=)\"\n\nlocale dflt_option =\n  fixes A :: \"'a \\<Rightarrow> 'c \\<Rightarrow> assn\"\n  fixes dflt :: \"'c\"\n  fixes eq :: \"'c \\<Rightarrow> 'c \\<Rightarrow> bool Heap\"\n  assumes unused_dflt[safe_constraint_rules]: \"(is_unused_elem dflt) A\"\n\n  assumes eq_op: \"(uncurry eq, uncurry (RETURN oo (=))) \\<in> A\\<^sup>k*\\<^sub>aA\\<^sup>k\\<rightarrow>\\<^sub>abool_assn\"\n  assumes eq_dflt: \"\\<And>a b. \\<lbrakk> a=dflt \\<or> b=dflt \\<rbrakk> \\<Longrightarrow> <emp> eq a b <\\<lambda>r. \\<up>(r \\<longleftrightarrow> a=b)>\\<^sub>t\"\nbegin\n  (* Type-based rewrites. \n      TODO: We would prefer type-based specializations in translate-phase! *)\n  lemma fold_dflt_option[def_pat_rules]: \n    \"(None::'a option) \\<equiv> dflt_None\"\n    \"(Some::'a\\<Rightarrow>_) \\<equiv> dflt_Some\"\n    \"((=)::'a option \\<Rightarrow> _) \\<equiv> dflt_option_eq\"\n     by auto\n\n  (* Constructors *)\n  lemmas [sepref_fr_rules] = \n    doa_None_hnr[where dflt = dflt and A=A]\n    doa_Some_hnr[where dflt = dflt and A=A]\n\n  lemma eq_option_refine[sepref_fr_rules]:\n    assumes \"CONSTRAINT is_pure A\"\n    shows \"(uncurry eq,uncurry (RETURN oo dflt_option_eq)) \n      \\<in> (dflt_option_assn dflt A)\\<^sup>k *\\<^sub>a (dflt_option_assn dflt A)\\<^sup>k \\<rightarrow>\\<^sub>a bool_assn\"\n  proof -\n    from assms obtain R where [simp]: \"A = pure R\" by (auto simp: is_pure_conv)\n    \n    from eq_op have [sep_heap_rules]: \n      \"\\<lbrakk> (x,x')\\<in>R; (y,y')\\<in>R \\<rbrakk> \n      \\<Longrightarrow> <emp> eq x y <\\<lambda>r. \\<up>(r \\<longleftrightarrow> x'=y')>\\<^sub>t\" for x x' y y'\n      apply (drule_tac hfrefD[where a=\"(x',y')\" and c=\"(x,y)\"])\n      apply simp\n      apply (drule hn_refineD)\n      apply simp\n      apply (sep_auto simp: pure_def)\n      apply (rule Hoare_Triple.cons_post_rule)\n      apply assumption\n      apply sep_auto\n      done\n  \n    note [simplified,sep_heap_rules] \n      = eq_dflt[of dflt dflt] eq_dflt[of dflt] eq_dflt[of _ dflt] \n    \n    show ?thesis\n      apply sepref_to_hoare\n      apply (simp add: dflt_option_assn_def)\n      apply (auto simp: pure_def dflt_option_rel_aux_def elim!: option_relE)\n      apply (sep_auto)\n      apply (sep_auto)\n      apply (sep_auto)\n      apply (sep_auto)\n      done\n  qed  \n    \n    \n    \nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/VerifyThis2018/lib/Array_Map_Default.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5078118642792044, "lm_q2_score": 0.5813030906443133, "lm_q1q2_score": 0.2951926061713521}}
{"text": "theory FurtherLogicExperimental\nimports DerivedConstructions Frac BaseLogicDeepExperimental2 Namespace \"../HeapLang/PrimitiveLaws\"\n  \"../SpanningTree/SpanningTreeCameras\" \"../HeapLang/State\"\nbegin\n\ndatatype inv = Inv \"(name, iprop later) map_view \\<times> name dset \\<times> name dfset\"\n  and iprop = iProp (pred: \"(graphUR auth \\<times> markingUR auth \\<times> inv \\<times> heap_lang_heap) cmra_pred\")\n\ninstance inv :: ucamera sorry\ninstance iprop :: ofe sorry\n\ndeclare [[coercion pred, coercion Inv]]\n  \nabbreviation own_heap :: \"heap_lang_heap \\<Rightarrow> iprop\" (\"Own\\<^sub>h _\") where\n  \"own_heap h \\<equiv> iProp (Atom (Own (ConstC (\\<epsilon>,\\<epsilon>,\\<epsilon>,h))))\"\n\ndefinition points_to :: \"loc \\<Rightarrow> dfrac \\<Rightarrow> val \\<Rightarrow> iprop\" where\n  \"points_to l dq v = Own\\<^sub>h(view_frag [l\\<mapsto>(dq, to_ag (Some v))])\"\nabbreviation points_to_disc :: \"loc \\<Rightarrow> val \\<Rightarrow> iprop\" where \n  \"points_to_disc \\<equiv> \\<lambda>l v. points_to l DfracDiscarded v\"\nabbreviation points_to_own :: \"loc \\<Rightarrow> frac \\<Rightarrow> val \\<Rightarrow> iprop\" where\n  \"points_to_own \\<equiv> \\<lambda>l p v. points_to l (DfracOwn p) v\"\nabbreviation points_to_full :: \"loc \\<Rightarrow> val \\<Rightarrow> iprop\" where\n  \"points_to_full \\<equiv> \\<lambda>l v. points_to_own l 1 v\"\n\ndefinition \"iprop_holds iP \\<equiv> case iP of iProp P \\<Rightarrow> pred_holds P\"\n  \nlemma points_to_valid: \n  \"iprop_holds (iProp (Wand (pred (points_to l dq v)) (Pure (valid dq))))\"\n  unfolding pred_holds_def upred_holds_def points_to_def iprop_holds_def\n  apply auto\n  sorry\n\ndefinition own_inv :: \"inv \\<Rightarrow> iprop\" (\"Own\\<^sub>i _\") where\n  \"own_inv i = iProp (Atom (Own(ConstC (\\<epsilon>,\\<epsilon>,i,\\<epsilon>))))\"\n\ndefinition own_state_heap :: \"state \\<Rightarrow> iprop\" where\n  \"own_state_heap s = Own\\<^sub>h (view_auth_full (heap s))\"\n\ndefinition sep_map_set :: \"('b\\<Rightarrow>iprop) \\<Rightarrow> 'b set \\<Rightarrow> iprop\" where\n  \"sep_map_set f s = iProp (folding_on.F (\\<lambda>x a. Sep a (pred (f x))) (Pure True) s)\"\n  \ncontext assumes \"SORT_CONSTRAINT('c::ucamera)\" and \"SORT_CONSTRAINT('v::ofe)\"\nbegin\n\ndefinition ownI :: \"name \\<Rightarrow> iprop \\<Rightarrow> iprop\" where\n  \"ownI \\<iota> P = Own\\<^sub>i (Inv (view_frag [\\<iota>\\<mapsto>(DfracDiscarded,to_ag (Next P))],\\<epsilon>,\\<epsilon>))\"\n\ndefinition inv :: \"namespace \\<Rightarrow> iprop \\<Rightarrow> iprop\" where\n  \"inv N P = iProp (\\<exists>\\<^sub>u \\<iota>. (Conj (Pure (uname \\<iota>\\<in>names N)) (pred (ownI (uname \\<iota>) P))))\"\n  \ndefinition ownE :: \"name dset \\<Rightarrow> iprop\" where\n  \"ownE E = Own\\<^sub>i (Inv (\\<epsilon>,E,\\<epsilon>))\"\n\ndefinition ownD :: \"name dfset \\<Rightarrow> iprop\" where\n  \"ownD D = Own\\<^sub>i (Inv (\\<epsilon>,\\<epsilon>,D))\"\n  \ndefinition lift_inv_fmap :: \"(name,iprop) fmap \\<Rightarrow> (name,iprop later) fmap\" where\n  \"lift_inv_fmap m = Abs_fmap (map_option Next \\<circ> (fmlookup m))\"\n  \ndefinition wsat :: iprop where\n  \"wsat \\<equiv> \\<exists>\\<^sub>u (I::(name,iprop) fmap).\n    (Sep (pred (Own\\<^sub>i (Inv(view_auth_full(lift_inv_fmap I),\\<epsilon>,\\<epsilon>))))\n     (pred (sep_map_set (\\<lambda>\\<iota>. iProp (Disj (Sep (Later((pred \\<circ> the \\<circ> (fmlookup I)) \\<iota>)) (pred (ownD (DFSet {|\\<iota>|})))) \n      (pred (ownE (DSet {\\<iota>}))))) (fmdom' I))))\"\nend\n  \nfunction wp :: \"expr \\<Rightarrow> (val \\<Rightarrow> iprop) \\<Rightarrow> iprop\" where\n  \"wp e \\<Phi> = iProp (case to_val e of Some v \\<Rightarrow> BUpd (pred (\\<Phi> v))\n    | None \\<Rightarrow> (\\<forall>\\<^sub>u \\<sigma>. (Wand (pred (own_state_heap (ustate \\<sigma>)))\n      (BUpd (Conj (Pure(red e (ustate \\<sigma>))) (Later (\\<forall>\\<^sub>u \\<kappa> e2 \\<sigma>2 efs. Wand \n      (Pure(e (ustate \\<sigma>) (ulist uobs \\<kappa>) \\<Rightarrow>\\<^sub>h (uexpr e2) (ustate \\<sigma>2) (ulist uexpr efs)))\n        (BUpd (Sep (pred (own_state_heap (ustate \\<sigma>2))) \n        (Sep (pred (wp (uexpr e2) \\<Phi>)) \n        (pred (sep_map_set (\\<lambda>e'. (wp e' (\\<lambda>_. iProp (Pure True)))) (set (ulist uexpr efs)\n        )))))))))))))\"\n  by fast auto\n  \nend", "meta": {"author": "firefighterduck", "repo": "isariris", "sha": "d02268e1e11cf681cae70b366b52843cbd90cc49", "save_path": "github-repos/isabelle/firefighterduck-isariris", "path": "github-repos/isabelle/firefighterduck-isariris/isariris-d02268e1e11cf681cae70b366b52843cbd90cc49/IrisCore/FurtherLogicExperimental.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7310585786300049, "lm_q2_score": 0.4035668537353746, "lm_q1q2_score": 0.295031010473966}}
{"text": "theory InfrastructureOne\n  imports CoronaApp\nbegin\n\ntext \\<open>This is the new element for refining the Ephemeral Id -- a list\n     of ephemeral ids repreented as a function from nat to the efid type. \n     This function needs to be unique and reversible so it must be injective and\n     also for all actors the ranges should be disjoint. These properties are\n     not part of the actual type but are proved as invariants. In applications\n     (e.g. CoronaApp) they need to be shown for initial states and then the\n     invariants can be applied to show that they hold in any reachable state.\\<close>\ndatatype efidlist = Efids \"efid\" \"nat\" \"nat \\<Rightarrow> efid\"\n\nprimrec efids_root :: \"efidlist \\<Rightarrow> efid\"\n  where \"efids_root (Efids e n el) = e\"\nprimrec efids_index :: \"efidlist \\<Rightarrow> nat\"\n  where \"efids_index (Efids e n el) = n\"\nprimrec efids_inc_ind :: \"efidlist \\<Rightarrow> efidlist\"\n  where \"efids_inc_ind (Efids e n ef) = (Efids e (Suc n) ef) \"\nprimrec efids_cur:: \"efidlist \\<Rightarrow> efid\"\n  where \"efids_cur (Efids e n ef) = ef n\"\nprimrec efids_list :: \"efidlist \\<Rightarrow> nat \\<Rightarrow> efid\"\n  where \"efids_list (Efids e n ef) = ef\"\ndefinition repl_efr :: \"efidlist \\<Rightarrow> efid\"\n  where \"repl_efr el \\<equiv> efids_root el\" \n\ndatatype igraph = Lgraph \"(location * location)set\" \"location \\<Rightarrow> identity set\"\n                           \"identity \\<Rightarrow> efidlist\"  \n                           \"location \\<Rightarrow> string * (dlm * data) set\"\n                           \"location \\<Rightarrow> efid set\"\n                           \"identity \\<Rightarrow> location \\<Rightarrow> (identity * efid)set\"\n\ndatatype infrastructure = \n         Infrastructure \"igraph\" \n                        \"[igraph, location] \\<Rightarrow> policy set\" \n                       \nprimrec loc :: \"location \\<Rightarrow> nat\"\nwhere  \"loc(Location n) = n\"\nprimrec gra :: \"igraph \\<Rightarrow> (location * location)set\"\nwhere  \"gra(Lgraph g a c l e k) = g\"\nprimrec agra :: \"igraph \\<Rightarrow> (location \\<Rightarrow> identity set)\"\nwhere  \"agra(Lgraph g a c l e k) = a\"\nprimrec cgra :: \"igraph \\<Rightarrow> identity \\<Rightarrow> efidlist\"\nwhere  \"cgra(Lgraph g a c l e k) = c\"\nprimrec lgra :: \"igraph \\<Rightarrow> (location \\<Rightarrow> string * (dlm * data) set)\"\n  where  \"lgra(Lgraph g a c l e k) = l\"\nprimrec egra :: \"igraph \\<Rightarrow> location \\<Rightarrow> efid set\"\n  where  \"egra(Lgraph g a c l e k) = e\"\nprimrec kgra:: \"[igraph, identity, location] \\<Rightarrow> (identity * efid)set\"\n  where \"kgra(Lgraph g a c l e k) = k\"\n\ndefinition nodes :: \"igraph \\<Rightarrow> location set\" \nwhere \"nodes g == { x. (? y. ((x,y): gra g) | ((y,x): gra g))}\"\n\ndefinition actors_graph :: \"igraph \\<Rightarrow> identity set\"  \nwhere  \"actors_graph g == {x. ? y. y : nodes g \\<and> x \\<in> (agra g y)}\"\n\nprimrec graphI :: \"infrastructure \\<Rightarrow> igraph\"\nwhere \"graphI (Infrastructure g d) = g\"\nprimrec delta :: \"[infrastructure, igraph, location] \\<Rightarrow> policy set\"\nwhere \"delta (Infrastructure g d) = d\"\nprimrec tspace :: \"[infrastructure, identity ] \\<Rightarrow> efidlist\"\n  where \"tspace (Infrastructure g d) = cgra g\"\nprimrec lspace :: \"[infrastructure, location ] \\<Rightarrow> string * (dlm * data)set\"\n  where \"lspace (Infrastructure g d) = lgra g\"\n\n\n\ntext \\<open>Predicates and projections for the labels to encode their meaning.\\<close>\ndefinition owner :: \"dlm * data \\<Rightarrow> actor\" where \"owner d \\<equiv> fst(fst d)\"\ndefinition owns :: \"[igraph, location, actor, dlm * data] \\<Rightarrow> bool\"\n  where \"owns G l a d \\<equiv> owner d = a\"\ndefinition readers :: \"dlm * data \\<Rightarrow> actor set\"\n  where \"readers d \\<equiv> snd (fst d)\"\n\ntext \\<open>The predicate @{text \\<open>has_access\\<close>} is true for owners or readers.\\<close> \ndefinition has_access :: \"[igraph, location, actor, dlm * data] \\<Rightarrow> bool\"    \nwhere \"has_access G l a d \\<equiv> owns G l a d \\<or> a \\<in> readers d\"\n\ntypedef label_fun = \"{f :: dlm * data \\<Rightarrow> dlm * data. \n                        \\<forall> x:: dlm * data. fst x = fst (f x)}\"  \n  by (fastforce)\n\ndefinition secure_process :: \"label_fun \\<Rightarrow> dlm * data \\<Rightarrow> dlm * data\" (infixr \"\\<Updown>\" 50)\n  where \"f  \\<Updown> d \\<equiv> (Rep_label_fun f) d\" \n\ndefinition atI :: \"[identity, igraph, location] \\<Rightarrow> bool\" (\"_ @\\<^bsub>(_)\\<^esub> _\" 50)\nwhere \"a @\\<^bsub>G\\<^esub> l \\<equiv> a \\<in> (agra G l)\"\n\ndefinition enables :: \"[infrastructure, location, actor, action] \\<Rightarrow> bool\"\nwhere\n\"enables I l a a' \\<equiv>  (\\<exists> (p,e) \\<in> delta I (graphI I) l. a' \\<in> e \\<and> p a)\"\n\ndefinition behaviour :: \"infrastructure \\<Rightarrow> (location * actor * action)set\"\nwhere \"behaviour I \\<equiv> {(t,a,a'). enables I t a a'}\"\n\ndefinition misbehaviour :: \"infrastructure \\<Rightarrow> (location * actor * action)set\"\nwhere \"misbehaviour I \\<equiv> -(behaviour I)\"\n\nprimrec jonce :: \"['a, 'a list] \\<Rightarrow> bool\"\nwhere\njonce_nil: \"jonce a [] = False\" |\njonce_cons: \"jonce a (x#ls) = (if x = a then (a \\<notin> (set ls)) else jonce a ls)\"\n\ndefinition move_graph_a :: \"[identity, location, location, igraph] \\<Rightarrow> igraph\"\nwhere \"move_graph_a n l l' g \\<equiv> Lgraph (gra g) \n                    (if n \\<in> ((agra g) l) &  n \\<notin> ((agra g) l') then \n                     ((agra g)(l := (agra g l) - {n}))(l' := (insert n (agra g l')))\n                     else (agra g))\n                    (cgra g) \n                    (lgra g)\n                    (if n \\<in> ((agra g) l) &  n \\<notin> ((agra g) l') then\n                       ((egra g)(l := (egra g l) - {efids_cur(cgra g n)}))\n                                (l' := insert (efids_cur(cgra g n))(egra g l'))\n                      else egra g)(kgra g)\"\n\ndefinition put_graph_efid :: \"[identity, location, igraph] \\<Rightarrow> igraph\"\n  where \\<open>put_graph_efid n l g  \\<equiv> Lgraph (gra g)(agra g)\n                            ((cgra g)(n := efids_inc_ind(cgra g n)))\n                               (lgra g)\n                             ((egra g)(l := insert (efids_cur(efids_inc_ind(cgra g n)))\n                                           ((egra g l) - {efids_cur(cgra g n)})))\n                              (kgra g)\\<close>\n\ninductive state_transition_in :: \"[infrastructure, infrastructure] \\<Rightarrow> bool\" (\"(_ \\<rightarrow>\\<^sub>n _)\" 50)\nwhere\n  move: \"\\<lbrakk> G = graphI I; a @\\<^bsub>G\\<^esub> l; l \\<in> nodes G; l' \\<in> nodes G;\n          (a) \\<in> actors_graph(graphI I); enables I l' (Actor a) move;\n         I' = Infrastructure (move_graph_a a l l' (graphI I))(delta I) \\<rbrakk> \\<Longrightarrow> I \\<rightarrow>\\<^sub>n I'\" \n| get : \"\\<lbrakk> G = graphI I; a @\\<^bsub>G\\<^esub> l; l \\<in> nodes G;\n        enables I l (Actor a) get;\n        I' = Infrastructure \n                   (Lgraph (gra G)(agra G)(cgra G)(lgra G)(egra G)\n                       ((kgra G)(a := ((kgra G a)(l:= {(x,y). x \\<in> agra G l \\<and> y \\<in> egra G l})))))\n                   (delta I)\n         \\<rbrakk> \\<Longrightarrow> I \\<rightarrow>\\<^sub>n I'\"\n| put : \"G = graphI I \\<Longrightarrow> a @\\<^bsub>G\\<^esub> l \\<Longrightarrow> enables I l (Actor a) put \\<Longrightarrow>\n        I' = Infrastructure (put_graph_efid a l G)(delta I)\n          \\<Longrightarrow> I \\<rightarrow>\\<^sub>n I'\"\n\ntext \\<open>Note that the type infrastructure can now be instantiated to the axiomatic type class \n      @{text\\<open>state\\<close>} which enables the use of the underlying Kripke structures and CTL.\\<close>\ninstantiation \"infrastructure\" :: state\nbegin\ndefinition \n   state_transition_infra_def: \"(i \\<rightarrow>\\<^sub>i i') =  (i \\<rightarrow>\\<^sub>n (i' :: infrastructure))\"\n\ninstance\n  by (rule MC.class.MC.state.of_class.intro)\n\ndefinition state_transition_in_refl (\"(_ \\<rightarrow>\\<^sub>n* _)\" 50)\nwhere \"s \\<rightarrow>\\<^sub>n* s' \\<equiv> ((s,s') \\<in> {(x,y). state_transition_in x y}\\<^sup>*)\"\n\nend\n\n\nlemma move_graph_eq: \"move_graph_a a l l g = g\"  \n  by (simp add: move_graph_a_def, case_tac g, force)\n\ndefinition anonymous_actor :: \"infrastructure \\<Rightarrow> efid \\<Rightarrow> identity\"\n  where\n\"anonymous_actor I e = (SOME a :: identity. a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I) \\<and>\n                       e \\<in> range(efids_list (InfrastructureOne.cgra (graphI I) a)))\"\n\nlemma anonymous_actor_defO: \"InfrastructureOne.actors_graph (InfrastructureOne.graphI I) \\<noteq> {} \\<Longrightarrow>\n(\\<forall> a \\<in> actors_graph (graphI I). inj (efids_list (InfrastructureOne.cgra (graphI I) a))) \\<Longrightarrow>\n(\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI I). (\\<forall> a' \\<in> actors_graph(InfrastructureOne.graphI I). a \\<noteq> a' \\<longrightarrow>\n     ((range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<inter> \n      (range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a')))) = {}))) \\<Longrightarrow>\n    l \\<in> nodes (graphI I) \\<Longrightarrow> \n    e \\<in> (\\<Union> a \\<in> actors_graph (InfrastructureOne.graphI I). \n            range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a))) \n             \\<Longrightarrow>\n    \\<exists>! a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I). e \\<in> range (efids_list (InfrastructureOne.cgra (graphI I) a))\"\n  apply (rule ex_ex1I)\n  apply blast\n by blast\n\nlemma anonymous_actor_def1a: \"InfrastructureOne.actors_graph (InfrastructureOne.graphI I) \\<noteq> {} \\<Longrightarrow>\n(\\<forall> a \\<in> actors_graph (graphI I). inj (efids_list (InfrastructureOne.cgra (graphI I) a))) \\<Longrightarrow>\n(\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI I). (\\<forall> a' \\<in> actors_graph(InfrastructureOne.graphI I). a \\<noteq> a' \\<longrightarrow>\n     ((range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<inter> \n      (range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a')))) = {}))) \\<Longrightarrow>\n    l \\<in> nodes (graphI I) \\<Longrightarrow> \n    e \\<in> (\\<Union> a \\<in> actors_graph (InfrastructureOne.graphI I). \n            range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a))) \n             \\<Longrightarrow>\n    anonymous_actor I e \\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I)\n    \\<and> e \\<in> range (efids_list (InfrastructureOne.cgra (graphI I)(anonymous_actor I e)))\"\n  apply (drule anonymous_actor_defO, assumption+)\n   apply (simp add: anonymous_actor_def)\n  by (metis (mono_tags, lifting) someI)\n\nlemma anonymous_actor_def1b: \"InfrastructureOne.actors_graph (InfrastructureOne.graphI I) \\<noteq> {} \\<Longrightarrow>\n(\\<forall> a \\<in> actors_graph (graphI I). inj (efids_list (InfrastructureOne.cgra (graphI I) a))) \\<Longrightarrow>\n(\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI I). (\\<forall> a' \\<in> actors_graph(InfrastructureOne.graphI I). a \\<noteq> a' \\<longrightarrow>\n     ((range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<inter> \n      (range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a')))) = {}))) \\<Longrightarrow>\n    l \\<in> nodes (graphI I) \\<Longrightarrow> \n    e \\<in> (\\<Union> a \\<in> actors_graph (InfrastructureOne.graphI I). \n            range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a))) \n             \\<Longrightarrow>\n    a' \\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I)\n    \\<and> e \\<in> range (efids_list (InfrastructureOne.cgra (graphI I) a'))\n   \\<Longrightarrow> a' = anonymous_actor I e\"\n  apply (drule anonymous_actor_defO, assumption+)\n   apply (simp add: anonymous_actor_def)\n  by (metis (no_types, lifting) someI)\n\n\ndefinition ref_map :: \"[InfrastructureOne.infrastructure, \n                        [Infrastructure.igraph, Infrastructure.location] \\<Rightarrow> policy set]\n                        \\<Rightarrow> Infrastructure.infrastructure\"\n  where \"ref_map I lp = Infrastructure.Infrastructure \n                                 (Infrastructure.Lgraph\n                                        (InfrastructureOne.gra (graphI I))\n                                        (InfrastructureOne.agra (graphI I))\n                                        (\\<lambda> h:: identity. repl_efr \n                                           ((InfrastructureOne.cgra (graphI I)) h))\n                                        (InfrastructureOne.lgra (graphI I))\n                                        (\\<lambda> l :: Infrastructure.location. \n                                           (\\<lambda> a. \n                                              efids_root (InfrastructureOne.cgra (graphI I) a)) ` \n                                                     (InfrastructureOne.agra (graphI I) l))\n                                        (\\<lambda> a :: identity. \\<lambda> l :: Infrastructure.location.\n                                            if (a \\<in> (InfrastructureOne.actors_graph(graphI I)) \\<and> l \\<in> (InfrastructureOne.nodes (graphI I)))\n                                            then ((\\<lambda> (x,y).(x, efids_root(InfrastructureOne.cgra (graphI I)(anonymous_actor I y))))\n                                                             `(InfrastructureOne.kgra (graphI I)) a l)\n                                            else {}))   \n                                                         lp\"\n\nlemma delta_invariant: \"\\<forall> z z'. z \\<rightarrow>\\<^sub>n z' \\<longrightarrow>  delta(z) = delta(z')\"\n  apply clarify\n  apply (erule state_transition_in.cases)\n  by simp+\n\nlemma same_actors0[rule_format]: \"\\<forall> z z'.  z \\<rightarrow>\\<^sub>n z' \\<longrightarrow> actors_graph (graphI z) = actors_graph (graphI z')\"\nproof (clarify, erule state_transition_in.cases)\n  show \"\\<And>z z' G I a l l' I'.\n       z = I \\<Longrightarrow>\n       z' = I' \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       a @\\<^bsub>G\\<^esub> l \\<Longrightarrow>\n       l \\<in> InfrastructureOne.nodes G \\<Longrightarrow>\n       l' \\<in> InfrastructureOne.nodes G \\<Longrightarrow>\n       a \\<in> InfrastructureOne.actors_graph (InfrastructureOne.graphI I) \\<Longrightarrow>\n       InfrastructureOne.enables I l' (Actor a) move \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure\n        (InfrastructureOne.move_graph_a a l l' (InfrastructureOne.graphI I)) (InfrastructureOne.delta I) \\<Longrightarrow>\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z) =\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z')\"\n    apply (simp add: InfrastructureOne.actors_graph_def)\n    apply (rule equalityI)\n     apply (rule subsetI)\n     apply (rule CollectI)\n     apply (drule CollectD)\n     apply (erule exE, erule conjE)+\n    apply (simp add: move_graph_a_def)\n  proof -\n  fix z :: InfrastructureOne.infrastructure and z' :: InfrastructureOne.infrastructure and G :: InfrastructureOne.igraph and I :: InfrastructureOne.infrastructure and a :: \"char list\" and l :: location and l' :: location and I' :: InfrastructureOne.infrastructure and x :: \"char list\" and y :: location and ya :: location\n  assume a1: \"G = InfrastructureOne.graphI I\"\n    assume a2: \"l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I)\"\n    assume a3: \"l' \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I)\"\n    assume a4: \"ya \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I)\"\nassume \"x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) ya\"\nthen have f5: \"x \\<in> InfrastructureOne.agra G ya\"\nusing a1 by meson\n  have f6: \"ya \\<in> {l. \\<exists>la. (l, la) \\<in> InfrastructureOne.gra G \\<or> (la, l) \\<in> InfrastructureOne.gra G}\"\n    using a4 a1 InfrastructureOne.nodes_def by blast\n  { assume \"x \\<in> InfrastructureOne.agra G l\"\n    moreover\n    { assume \"\\<exists>la. x \\<in> InfrastructureOne.agra G l \\<and> la = l \\<and> x \\<noteq> a\"\n      then have \"(\\<exists>la. x \\<in> InfrastructureOne.agra G l \\<and> la = l \\<and> x \\<noteq> a \\<and> l' \\<noteq> l) \\<or> (\\<exists>la lb. x \\<in> InfrastructureOne.agra G la \\<and> x \\<in> InfrastructureOne.agra G l \\<and> x \\<in> InfrastructureOne.agra G l' \\<and> lb = l \\<and> la \\<in> {l. \\<exists>la. (l, la) \\<in> InfrastructureOne.gra G \\<or> (la, l) \\<in> InfrastructureOne.gra G} \\<and> l' \\<in> {l. \\<exists>la. (l, la) \\<in> InfrastructureOne.gra (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra G) ((InfrastructureOne.agra G) (l' := insert a (InfrastructureOne.agra G l'))) (InfrastructureOne.cgra G) (InfrastructureOne.lgra G) ((InfrastructureOne.egra G) (l' := insert (efids_cur (InfrastructureOne.cgra G a)) (InfrastructureOne.egra G l'))) (InfrastructureOne.kgra G)) \\<or> (la, l) \\<in> InfrastructureOne.gra (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra G) ((InfrastructureOne.agra G) (l' := insert a (InfrastructureOne.agra G l'))) (InfrastructureOne.cgra G) (InfrastructureOne.lgra G) ((InfrastructureOne.egra G) (l' := insert (efids_cur (InfrastructureOne.cgra G a)) (InfrastructureOne.egra G l'))) (InfrastructureOne.kgra G))} \\<and> l \\<in> {la. \\<exists>lb. (la, lb) \\<in> InfrastructureOne.gra (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra G) ((InfrastructureOne.agra G) (l := InfrastructureOne.agra G l - {a}, l' := insert a (InfrastructureOne.agra G l'))) (InfrastructureOne.cgra G) (InfrastructureOne.lgra G) ((InfrastructureOne.egra G) (l := InfrastructureOne.egra G l - {efids_cur (InfrastructureOne.cgra G a)}, l' := insert (efids_cur (InfrastructureOne.cgra G a)) (InfrastructureOne.egra G l'))) (InfrastructureOne.kgra G)) \\<or> (lb, la) \\<in> InfrastructureOne.gra (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra G) ((InfrastructureOne.agra G) (l := InfrastructureOne.agra G l - {a}, l' := insert a (InfrastructureOne.agra G l'))) (InfrastructureOne.cgra G) (InfrastructureOne.lgra G) ((InfrastructureOne.egra G) (l := InfrastructureOne.egra G l - {efids_cur (InfrastructureOne.cgra G a)}, l' := insert (efids_cur (InfrastructureOne.cgra G a)) (InfrastructureOne.egra G l'))) (InfrastructureOne.kgra G))} \\<and> x \\<noteq> a)\"\n        using a2 a1 InfrastructureOne.nodes_def by auto\n      moreover\n      { assume \"\\<exists>la lb. x \\<in> InfrastructureOne.agra G la \\<and> x \\<in> InfrastructureOne.agra G l \\<and> x \\<in> InfrastructureOne.agra G l' \\<and> lb = l \\<and> la \\<in> {l. \\<exists>la. (l, la) \\<in> InfrastructureOne.gra G \\<or> (la, l) \\<in> InfrastructureOne.gra G} \\<and> l' \\<in> {l. \\<exists>la. (l, la) \\<in> InfrastructureOne.gra (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra G) ((InfrastructureOne.agra G) (l' := insert a (InfrastructureOne.agra G l'))) (InfrastructureOne.cgra G) (InfrastructureOne.lgra G) ((InfrastructureOne.egra G) (l' := insert (efids_cur (InfrastructureOne.cgra G a)) (InfrastructureOne.egra G l'))) (InfrastructureOne.kgra G)) \\<or> (la, l) \\<in> InfrastructureOne.gra (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra G) ((InfrastructureOne.agra G) (l' := insert a (InfrastructureOne.agra G l'))) (InfrastructureOne.cgra G) (InfrastructureOne.lgra G) ((InfrastructureOne.egra G) (l' := insert (efids_cur (InfrastructureOne.cgra G a)) (InfrastructureOne.egra G l'))) (InfrastructureOne.kgra G))} \\<and> l \\<in> {la. \\<exists>lb. (la, lb) \\<in> InfrastructureOne.gra (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra G) ((InfrastructureOne.agra G) (l := InfrastructureOne.agra G l - {a}, l' := insert a (InfrastructureOne.agra G l'))) (InfrastructureOne.cgra G) (InfrastructureOne.lgra G) ((InfrastructureOne.egra G) (l := InfrastructureOne.egra G l - {efids_cur (InfrastructureOne.cgra G a)}, l' := insert (efids_cur (InfrastructureOne.cgra G a)) (InfrastructureOne.egra G l'))) (InfrastructureOne.kgra G)) \\<or> (lb, la) \\<in> InfrastructureOne.gra (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra G) ((InfrastructureOne.agra G) (l := InfrastructureOne.agra G l - {a}, l' := insert a (InfrastructureOne.agra G l'))) (InfrastructureOne.cgra G) (InfrastructureOne.lgra G) ((InfrastructureOne.egra G) (l := InfrastructureOne.egra G l - {efids_cur (InfrastructureOne.cgra G a)}, l' := insert (efids_cur (InfrastructureOne.cgra G a)) (InfrastructureOne.egra G l'))) (InfrastructureOne.kgra G))} \\<and> x \\<noteq> a\"\n        then have \"(a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> (\\<exists>la. (la = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and> (la \\<noteq> l \\<longrightarrow> (la = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (la \\<noteq> l' \\<longrightarrow> la \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) la)))) \\<and> ((a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<longrightarrow> a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l') \\<longrightarrow> (a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> (\\<exists>la. (la = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and> (la \\<noteq> l \\<longrightarrow> (la = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (la \\<noteq> l' \\<longrightarrow> la \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) la)))) \\<and> (\\<exists>l. l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) (InfrastructureOne.agra (InfrastructureOne.graphI I)) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) (InfrastructureOne.egra (InfrastructureOne.graphI I)) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l))\"\n          using a1 InfrastructureOne.nodes_def by auto }\n      moreover\n      { assume \"\\<exists>la. x \\<in> InfrastructureOne.agra G l \\<and> la = l \\<and> x \\<noteq> a \\<and> l' \\<noteq> l\"\n        then have \"(a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> (\\<exists>la. (la = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and> (la \\<noteq> l \\<longrightarrow> (la = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (la \\<noteq> l' \\<longrightarrow> la \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) la)))) \\<and> ((a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<longrightarrow> a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l') \\<longrightarrow> (a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> (\\<exists>la. (la = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and> (la \\<noteq> l \\<longrightarrow> (la = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (la \\<noteq> l' \\<longrightarrow> la \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) la)))) \\<and> (\\<exists>l. l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) (InfrastructureOne.agra (InfrastructureOne.graphI I)) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) (InfrastructureOne.egra (InfrastructureOne.graphI I)) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l))\"\n          using a2 a1 InfrastructureOne.nodes_def by auto }\n      ultimately have \"(a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> (\\<exists>la. (la = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and> (la \\<noteq> l \\<longrightarrow> (la = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (la \\<noteq> l' \\<longrightarrow> la \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) la)))) \\<and> ((a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<longrightarrow> a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l') \\<longrightarrow> (a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> (\\<exists>la. (la = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and> (la \\<noteq> l \\<longrightarrow> (la = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (la \\<noteq> l' \\<longrightarrow> la \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) la)))) \\<and> (\\<exists>l. l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) (InfrastructureOne.agra (InfrastructureOne.graphI I)) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) (InfrastructureOne.egra (InfrastructureOne.graphI I)) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l))\"\n        by fastforce }\n    moreover\n    { assume \"x = a\"\n      moreover\n      { assume \"x = a \\<and> a \\<notin> InfrastructureOne.agra G l'\"\n        moreover\n        { assume \"a \\<notin> InfrastructureOne.agra G l\"\n          then have \"\\<exists>la. x \\<in> InfrastructureOne.agra G la \\<and> la \\<in> {l. \\<exists>la. (l, la) \\<in> InfrastructureOne.gra G \\<or> (la, l) \\<in> InfrastructureOne.gra G} \\<and> a \\<notin> InfrastructureOne.agra G l\"\n            using f6 f5 by blast }\n        ultimately have \"(\\<exists>la. x \\<in> InfrastructureOne.agra G la \\<and> la \\<in> {l. \\<exists>la. (l, la) \\<in> InfrastructureOne.gra G \\<or> (la, l) \\<in> InfrastructureOne.gra G} \\<and> a \\<notin> InfrastructureOne.agra G l) \\<or> (a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> (\\<exists>la. (la = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and> (la \\<noteq> l \\<longrightarrow> (la = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (la \\<noteq> l' \\<longrightarrow> la \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) la)))) \\<and> ((a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<longrightarrow> a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l') \\<longrightarrow> (a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> (\\<exists>la. (la = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and> (la \\<noteq> l \\<longrightarrow> (la = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (la \\<noteq> l' \\<longrightarrow> la \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) la)))) \\<and> (\\<exists>l. l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) (InfrastructureOne.agra (InfrastructureOne.graphI I)) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) (InfrastructureOne.egra (InfrastructureOne.graphI I)) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l))\"\n          using a3 a1 InfrastructureOne.nodes_def by fastforce }\n      moreover\n      { assume \"a \\<in> InfrastructureOne.agra G l'\"\n        then have \"\\<exists>l. x \\<in> InfrastructureOne.agra G l \\<and> a \\<in> InfrastructureOne.agra G l' \\<and> l \\<in> {l. \\<exists>la. (l, la) \\<in> InfrastructureOne.gra G \\<or> (la, l) \\<in> InfrastructureOne.gra G}\"\n          using f6 f5 by blast }\n      ultimately have \"(\\<exists>la. x \\<in> InfrastructureOne.agra G la \\<and> la \\<in> {l. \\<exists>la. (l, la) \\<in> InfrastructureOne.gra G \\<or> (la, l) \\<in> InfrastructureOne.gra G} \\<and> a \\<notin> InfrastructureOne.agra G l) \\<or> (\\<exists>l. x \\<in> InfrastructureOne.agra G l \\<and> a \\<in> InfrastructureOne.agra G l' \\<and> l \\<in> {l. \\<exists>la. (l, la) \\<in> InfrastructureOne.gra G \\<or> (la, l) \\<in> InfrastructureOne.gra G}) \\<or> (a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> (\\<exists>la. (la = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and> (la \\<noteq> l \\<longrightarrow> (la = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (la \\<noteq> l' \\<longrightarrow> la \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) la)))) \\<and> ((a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<longrightarrow> a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l') \\<longrightarrow> (a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> (\\<exists>la. (la = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and> (la \\<noteq> l \\<longrightarrow> (la = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (la \\<noteq> l' \\<longrightarrow> la \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) la)))) \\<and> (\\<exists>l. l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) (InfrastructureOne.agra (InfrastructureOne.graphI I)) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) (InfrastructureOne.egra (InfrastructureOne.graphI I)) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l))\"\n        by fastforce }\n    ultimately have \"(\\<exists>la. x \\<in> InfrastructureOne.agra G la \\<and> la \\<in> {l. \\<exists>la. (l, la) \\<in> InfrastructureOne.gra G \\<or> (la, l) \\<in> InfrastructureOne.gra G} \\<and> a \\<notin> InfrastructureOne.agra G l) \\<or> (\\<exists>l. x \\<in> InfrastructureOne.agra G l \\<and> a \\<in> InfrastructureOne.agra G l' \\<and> l \\<in> {l. \\<exists>la. (l, la) \\<in> InfrastructureOne.gra G \\<or> (la, l) \\<in> InfrastructureOne.gra G}) \\<or> (a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> (\\<exists>la. (la = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and> (la \\<noteq> l \\<longrightarrow> (la = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (la \\<noteq> l' \\<longrightarrow> la \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) la)))) \\<and> ((a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<longrightarrow> a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l') \\<longrightarrow> (a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> (\\<exists>la. (la = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and> (la \\<noteq> l \\<longrightarrow> (la = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (la \\<noteq> l' \\<longrightarrow> la \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) la)))) \\<and> (\\<exists>l. l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) (InfrastructureOne.agra (InfrastructureOne.graphI I)) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) (InfrastructureOne.egra (InfrastructureOne.graphI I)) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l))\"\n      by fastforce }\n  moreover\n  { assume \"x \\<notin> InfrastructureOne.agra G l\"\n    then have \"ya \\<noteq> l\"\n      using f5 by meson\n    moreover\n    { assume \"ya \\<noteq> l \\<and> x \\<notin> InfrastructureOne.agra G l'\"\n      then have \"(\\<exists>la. x \\<in> InfrastructureOne.agra G la \\<and> la \\<in> {l. \\<exists>la. (l, la) \\<in> InfrastructureOne.gra G \\<or> (la, l) \\<in> InfrastructureOne.gra G} \\<and> a \\<notin> InfrastructureOne.agra G l) \\<or> (\\<exists>l. x \\<in> InfrastructureOne.agra G l \\<and> a \\<in> InfrastructureOne.agra G l' \\<and> l \\<in> {l. \\<exists>la. (l, la) \\<in> InfrastructureOne.gra G \\<or> (la, l) \\<in> InfrastructureOne.gra G}) \\<or> (a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> (\\<exists>la. (la = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and> (la \\<noteq> l \\<longrightarrow> (la = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (la \\<noteq> l' \\<longrightarrow> la \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) la)))) \\<and> ((a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<longrightarrow> a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l') \\<longrightarrow> (a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> (\\<exists>la. (la = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and> (la \\<noteq> l \\<longrightarrow> (la = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (la \\<noteq> l' \\<longrightarrow> la \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) la)))) \\<and> (\\<exists>l. l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) (InfrastructureOne.agra (InfrastructureOne.graphI I)) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) (InfrastructureOne.egra (InfrastructureOne.graphI I)) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l))\"\n        using f6 f5 a1 InfrastructureOne.nodes_def by auto }\n    ultimately have \"(\\<exists>la. x \\<in> InfrastructureOne.agra G la \\<and> la \\<in> {l. \\<exists>la. (l, la) \\<in> InfrastructureOne.gra G \\<or> (la, l) \\<in> InfrastructureOne.gra G} \\<and> a \\<notin> InfrastructureOne.agra G l) \\<or> (\\<exists>l. x \\<in> InfrastructureOne.agra G l \\<and> a \\<in> InfrastructureOne.agra G l' \\<and> l \\<in> {l. \\<exists>la. (l, la) \\<in> InfrastructureOne.gra G \\<or> (la, l) \\<in> InfrastructureOne.gra G}) \\<or> (a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> (\\<exists>la. (la = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and> (la \\<noteq> l \\<longrightarrow> (la = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (la \\<noteq> l' \\<longrightarrow> la \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) la)))) \\<and> ((a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<longrightarrow> a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l') \\<longrightarrow> (a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> (\\<exists>la. (la = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and> (la \\<noteq> l \\<longrightarrow> (la = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (la \\<noteq> l' \\<longrightarrow> la \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) la)))) \\<and> (\\<exists>l. l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) (InfrastructureOne.agra (InfrastructureOne.graphI I)) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) (InfrastructureOne.egra (InfrastructureOne.graphI I)) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l))\"\n      using a3 a1 InfrastructureOne.nodes_def by fastforce }\n  ultimately have \"(\\<exists>la. x \\<in> InfrastructureOne.agra G la \\<and> la \\<in> {l. \\<exists>la. (l, la) \\<in> InfrastructureOne.gra G \\<or> (la, l) \\<in> InfrastructureOne.gra G} \\<and> a \\<notin> InfrastructureOne.agra G l) \\<or> (\\<exists>l. x \\<in> InfrastructureOne.agra G l \\<and> a \\<in> InfrastructureOne.agra G l' \\<and> l \\<in> {l. \\<exists>la. (l, la) \\<in> InfrastructureOne.gra G \\<or> (la, l) \\<in> InfrastructureOne.gra G}) \\<or> (a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> (\\<exists>la. (la = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and> (la \\<noteq> l \\<longrightarrow> (la = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (la \\<noteq> l' \\<longrightarrow> la \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) la)))) \\<and> ((a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<longrightarrow> a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l') \\<longrightarrow> (a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> (\\<exists>la. (la = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and> (la \\<noteq> l \\<longrightarrow> (la = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (la \\<noteq> l' \\<longrightarrow> la \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) la)))) \\<and> (\\<exists>l. l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) (InfrastructureOne.agra (InfrastructureOne.graphI I)) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) (InfrastructureOne.egra (InfrastructureOne.graphI I)) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l))\"\n    by fastforce\n  then show \"(a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> (\\<exists>la. (la = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and> (la \\<noteq> l \\<longrightarrow> (la = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (la \\<noteq> l' \\<longrightarrow> la \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) la)))) \\<and> ((a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<longrightarrow> a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l') \\<longrightarrow> (a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> (\\<exists>la. (la = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and> (la \\<noteq> l \\<longrightarrow> (la = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (la \\<noteq> l' \\<longrightarrow> la \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) la)))) \\<and> (\\<exists>l. l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) (InfrastructureOne.agra (InfrastructureOne.graphI I)) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) (InfrastructureOne.egra (InfrastructureOne.graphI I)) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l))\"\n    using a1 InfrastructureOne.nodes_def by auto\nnext show \" \\<And>z z' G I a l l' I'.\n       z = I \\<Longrightarrow>\n       z' =\n       InfrastructureOne.infrastructure.Infrastructure\n        (InfrastructureOne.move_graph_a a l l' (InfrastructureOne.graphI I)) (InfrastructureOne.delta I) \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       a @\\<^bsub>InfrastructureOne.graphI I\\<^esub> l \\<Longrightarrow>\n       l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I) \\<Longrightarrow>\n       l' \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I) \\<Longrightarrow>\n       \\<exists>y. y \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I) \\<and>\n           a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) y \\<Longrightarrow>\n       InfrastructureOne.enables I l' (Actor a) move \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure\n        (InfrastructureOne.move_graph_a a l l' (InfrastructureOne.graphI I)) (InfrastructureOne.delta I) \\<Longrightarrow>\n       {x. \\<exists>y. y \\<in> InfrastructureOne.nodes (InfrastructureOne.move_graph_a a l l' (InfrastructureOne.graphI I)) \\<and>\n               x \\<in> InfrastructureOne.agra (InfrastructureOne.move_graph_a a l l' (InfrastructureOne.graphI I)) y}\n       \\<subseteq> {x. \\<exists>y. y \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I) \\<and>\n                  x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) y}\"\n\n    apply (simp add: InfrastructureOne.enables_def move_graph_a_def)\n    apply (rule conjI)\n     apply (rule impI)+\n     apply (rule subsetI)\n     apply (rule CollectI)\n     apply (drule CollectD)\n     apply (erule exE)+\n    apply (erule conjE)+\n  proof -\nfix z :: InfrastructureOne.infrastructure and z' :: InfrastructureOne.infrastructure and G :: InfrastructureOne.igraph and I :: InfrastructureOne.infrastructure and a :: \"char list\" and l :: location and l' :: location and I' :: InfrastructureOne.infrastructure and x :: \"char list\" and y :: location and ya :: location\nassume a1: \"G = InfrastructureOne.graphI I\"\n  assume a2: \"ya = l \\<longrightarrow> (l = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (l \\<noteq> l' \\<longrightarrow> l \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)\"\nassume a3: \"l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I)\"\nassume a4: \"l' \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I)\"\nassume a5: \"a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) y\"\n  assume a6: \"ya \\<noteq> l \\<longrightarrow> (ya = l' \\<longrightarrow> l' \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and> (ya \\<noteq> l' \\<longrightarrow> ya \\<in> InfrastructureOne.nodes (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I)) ((InfrastructureOne.agra (InfrastructureOne.graphI I)) (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a}, l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I)) ((InfrastructureOne.egra (InfrastructureOne.graphI I)) (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l - {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)}, l' := insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))) (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) ya)\"\n  assume a7: \"y \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I)\"\n  have \"ya = l' \\<or> ya = l \\<or> (\\<exists>l. x \\<in> InfrastructureOne.agra G l \\<and> l \\<in> InfrastructureOne.nodes G)\"\n    using a6 a1 InfrastructureOne.nodes_def by force\n  then show \"\\<exists>l. l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I) \\<and> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l\"\n    using a7 a6 a5 a4 a3 a2 a1 by (metis (no_types))\nnext show \"\\<And>z z' G I a l l' I'.\n       z = I \\<Longrightarrow>\n       z' =\n       InfrastructureOne.infrastructure.Infrastructure\n        (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I))\n          (if a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and>\n              a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l'\n           then (InfrastructureOne.agra (InfrastructureOne.graphI I))\n                (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a},\n                 l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))\n           else InfrastructureOne.agra (InfrastructureOne.graphI I))\n          (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I))\n          (if a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and>\n              a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l'\n           then (InfrastructureOne.egra (InfrastructureOne.graphI I))\n                (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l -\n                      {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)},\n                 l' :=\n                   insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a))\n                    (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))\n           else InfrastructureOne.egra (InfrastructureOne.graphI I))\n          (InfrastructureOne.kgra (InfrastructureOne.graphI I)))\n        (InfrastructureOne.delta I) \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       a @\\<^bsub>InfrastructureOne.graphI I\\<^esub> l \\<Longrightarrow>\n       l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I) \\<Longrightarrow>\n       l' \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I) \\<Longrightarrow>\n       \\<exists>y. y \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I) \\<and>\n           a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) y \\<Longrightarrow>\n       \\<exists>x\\<in>InfrastructureOne.delta I (InfrastructureOne.graphI I) l'. case x of (p, e) \\<Rightarrow> move \\<in> e \\<and> p (Actor a) \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure\n        (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I))\n          (if a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and>\n              a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l'\n           then (InfrastructureOne.agra (InfrastructureOne.graphI I))\n                (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a},\n                 l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l'))\n           else InfrastructureOne.agra (InfrastructureOne.graphI I))\n          (InfrastructureOne.cgra (InfrastructureOne.graphI I)) (InfrastructureOne.lgra (InfrastructureOne.graphI I))\n          (if a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and>\n              a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l'\n           then (InfrastructureOne.egra (InfrastructureOne.graphI I))\n                (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l -\n                      {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)},\n                 l' :=\n                   insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a))\n                    (InfrastructureOne.egra (InfrastructureOne.graphI I) l'))\n           else InfrastructureOne.egra (InfrastructureOne.graphI I))\n          (InfrastructureOne.kgra (InfrastructureOne.graphI I)))\n        (InfrastructureOne.delta I) \\<Longrightarrow>\n       (a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<longrightarrow>\n        a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l') \\<longrightarrow>\n       (a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and>\n        a \\<notin> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow>\n        {x. \\<exists>y. (y = l \\<longrightarrow>\n                 (l = l' \\<longrightarrow>\n                  l' \\<in> InfrastructureOne.nodes\n                         (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I))\n                           ((InfrastructureOne.agra (InfrastructureOne.graphI I))\n                            (l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l')))\n                           (InfrastructureOne.cgra (InfrastructureOne.graphI I))\n                           (InfrastructureOne.lgra (InfrastructureOne.graphI I))\n                           ((InfrastructureOne.egra (InfrastructureOne.graphI I))\n                            (l' :=\n                               insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a))\n                                (InfrastructureOne.egra (InfrastructureOne.graphI I) l')))\n                           (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and>\n                  (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and>\n                 (l \\<noteq> l' \\<longrightarrow>\n                  l \\<in> InfrastructureOne.nodes\n                        (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I))\n                          ((InfrastructureOne.agra (InfrastructureOne.graphI I))\n                           (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a},\n                            l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l')))\n                          (InfrastructureOne.cgra (InfrastructureOne.graphI I))\n                          (InfrastructureOne.lgra (InfrastructureOne.graphI I))\n                          ((InfrastructureOne.egra (InfrastructureOne.graphI I))\n                           (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l -\n                                 {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)},\n                            l' :=\n                              insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a))\n                               (InfrastructureOne.egra (InfrastructureOne.graphI I) l')))\n                          (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and>\n                  x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<and> x \\<noteq> a)) \\<and>\n                (y \\<noteq> l \\<longrightarrow>\n                 (y = l' \\<longrightarrow>\n                  l' \\<in> InfrastructureOne.nodes\n                         (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I))\n                           ((InfrastructureOne.agra (InfrastructureOne.graphI I))\n                            (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a},\n                             l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l')))\n                           (InfrastructureOne.cgra (InfrastructureOne.graphI I))\n                           (InfrastructureOne.lgra (InfrastructureOne.graphI I))\n                           ((InfrastructureOne.egra (InfrastructureOne.graphI I))\n                            (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l -\n                                  {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)},\n                             l' :=\n                               insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a))\n                                (InfrastructureOne.egra (InfrastructureOne.graphI I) l')))\n                           (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and>\n                  (x = a \\<or> x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l')) \\<and>\n                 (y \\<noteq> l' \\<longrightarrow>\n                  y \\<in> InfrastructureOne.nodes\n                        (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I))\n                          ((InfrastructureOne.agra (InfrastructureOne.graphI I))\n                           (l := InfrastructureOne.agra (InfrastructureOne.graphI I) l - {a},\n                            l' := insert a (InfrastructureOne.agra (InfrastructureOne.graphI I) l')))\n                          (InfrastructureOne.cgra (InfrastructureOne.graphI I))\n                          (InfrastructureOne.lgra (InfrastructureOne.graphI I))\n                          ((InfrastructureOne.egra (InfrastructureOne.graphI I))\n                           (l := InfrastructureOne.egra (InfrastructureOne.graphI I) l -\n                                 {efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)},\n                            l' :=\n                              insert (efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a))\n                               (InfrastructureOne.egra (InfrastructureOne.graphI I) l')))\n                          (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and>\n                  x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) y))}\n        \\<subseteq> {x. \\<exists>y. y \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I) \\<and>\n                   x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) y}) \\<and>\n       {x. \\<exists>y. y \\<in> InfrastructureOne.nodes\n                     (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra (InfrastructureOne.graphI I))\n                       (InfrastructureOne.agra (InfrastructureOne.graphI I))\n                       (InfrastructureOne.cgra (InfrastructureOne.graphI I))\n                       (InfrastructureOne.lgra (InfrastructureOne.graphI I))\n                       (InfrastructureOne.egra (InfrastructureOne.graphI I))\n                       (InfrastructureOne.kgra (InfrastructureOne.graphI I))) \\<and>\n               x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) y}\n       \\<subseteq> {x. \\<exists>y. y \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I) \\<and>\n                  x \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) y}\"\n    using InfrastructureOne.nodes_def by auto\nqed\nqed\nnext show \"\\<And>z z' G I a l I'.\n       z = I \\<Longrightarrow>\n       z' = I' \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       a @\\<^bsub>G\\<^esub> l \\<Longrightarrow>\n       l \\<in> InfrastructureOne.nodes G \\<Longrightarrow>\n       InfrastructureOne.enables I l (Actor a) get \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure\n        (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra G) (InfrastructureOne.agra G) (InfrastructureOne.cgra G)\n          (InfrastructureOne.lgra G) (InfrastructureOne.egra G)\n          ((InfrastructureOne.kgra G)\n           (a := (InfrastructureOne.kgra G a)\n              (l := {(x, y). x \\<in> InfrastructureOne.agra G l \\<and> y \\<in> InfrastructureOne.egra G l}))))\n        (InfrastructureOne.delta I) \\<Longrightarrow>\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z) =\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z')\"\n    by (simp add: InfrastructureOne.actors_graph_def InfrastructureOne.nodes_def)\nnext show \"\\<And>z z' G I a l I'.\n       z = I \\<Longrightarrow>\n       z' = I' \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       a @\\<^bsub>G\\<^esub> l \\<Longrightarrow>\n       InfrastructureOne.enables I l (Actor a) put \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure (InfrastructureOne.put_graph_efid a l G)\n        (InfrastructureOne.delta I) \\<Longrightarrow>\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z) =\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z')\"\n    by (simp add: InfrastructureOne.actors_graph_def InfrastructureOne.nodes_def InfrastructureOne.put_graph_efid_def)\nqed\n\nlemma same_actors: \"(I, y) \\<in> {(x::infrastructure, y::infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \n              \\<Longrightarrow> actors_graph(graphI I) = actors_graph(graphI y)\"\nproof (erule rtrancl_induct)\n  show \"actors_graph (graphI I) = actors_graph (graphI I)\"\n    by (rule refl)\nnext show \"\\<And>(y::infrastructure) z::infrastructure.\n       (I, y) \\<in> {(x::infrastructure, y::infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n       (y, z) \\<in> {(x::infrastructure, y::infrastructure). x \\<rightarrow>\\<^sub>n y} \\<Longrightarrow>\n       actors_graph (graphI I) = actors_graph (graphI y) \\<Longrightarrow>\n       actors_graph (graphI I) = actors_graph (graphI z)\"\n    by (drule CollectD, simp, drule same_actors0, simp)  \nqed\n\n(* locations invariants *)\n lemma same_nodes0[rule_format]: \"\\<forall> z z'. z \\<rightarrow>\\<^sub>n z' \\<longrightarrow> nodes(graphI z) = nodes(graphI z')\"   \n    apply clarify\n  apply (erule InfrastructureOne.state_transition_in.cases)\n  by (simp add: move_graph_a_def atI_def actors_graph_def nodes_def put_graph_efid_def)+\n\nlemma same_nodes: \"(c, s) \\<in> {(x::InfrastructureOne.infrastructure, y::InfrastructureOne.infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>*\n\\<Longrightarrow> InfrastructureOne.nodes (graphI c) = InfrastructureOne.nodes (graphI s)\"\n  apply (erule rtrancl_induct)\n   apply (rule refl)\n  apply (drule CollectD)\n    apply simp\n    apply (drule same_nodes0)\n  by simp  \n\n(* delta invariants *)\nlemma init_state_policy0: \"\\<lbrakk> \\<forall> z z'. z \\<rightarrow>\\<^sub>n z' \\<longrightarrow>  delta(z) = delta(z'); \n                          (x,y) \\<in> {(x::infrastructure, y::infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<rbrakk> \\<Longrightarrow> \n                          delta(x) = delta(y)\"  \n  apply (rule mp)\n  prefer 2\n   apply (rotate_tac 1)\n    apply assumption\n  thm rtrancl_induct\n  apply (erule rtrancl_induct)  \n    apply (rule impI)\n   apply (rule refl)\n    apply (subgoal_tac \"delta y = delta z\")\n   apply (erule impE)\n    apply assumption\n    apply (rule impI)\n   apply (rule trans)\n    apply assumption+\n  apply (drule_tac x = y in spec)\n  apply (drule_tac x = z in spec)\n    apply (rotate_tac -1)\n  apply (erule impE)\n    apply simp\nby assumption\n \nlemma init_state_policy: \"\\<lbrakk> (x,y) \\<in> {(x::infrastructure, y::infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<rbrakk> \\<Longrightarrow> \n                          delta(x) = delta(y)\"  \n  apply (rule init_state_policy0)\n    apply (rule delta_invariant)\n  by assumption\n\n(* anonymous actor invariant, i.e. we show that any efid that appears in a state, that is, either in  \n  the egra component or in the kgra component, is in the range of an efidlist for some actor a\n  in the set of actors of the infrastructure. Typical for invariants, we first show that the invariant \n  is preserved in a step, and this is then simply extrapolated by induction to any reachable I has the \n  property if it is reached from an initial I that already had that property.*)\nlemma efids_list_eq[rule_format]: \"(\\<forall> z z'. (z \\<rightarrow>\\<^sub>n z') \\<longrightarrow> \nefids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a) =\nefids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a))\"\n\nproof (clarify, frule same_actors0, frule same_nodes0, erule state_transition_in.cases)\n  show \"\\<And>z z' G I aa l l' I'.\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z) =\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z') \\<Longrightarrow>\n       InfrastructureOne.nodes (InfrastructureOne.graphI z) = InfrastructureOne.nodes (InfrastructureOne.graphI z') \\<Longrightarrow>\n       z = I \\<Longrightarrow>\n       z' = I' \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       aa @\\<^bsub>G\\<^esub> l \\<Longrightarrow>\n       l \\<in> InfrastructureOne.nodes G \\<Longrightarrow>\n       l' \\<in> InfrastructureOne.nodes G \\<Longrightarrow>\n       aa \\<in> InfrastructureOne.actors_graph (InfrastructureOne.graphI I) \\<Longrightarrow>\n       InfrastructureOne.enables I l' (Actor aa) move \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure\n        (InfrastructureOne.move_graph_a aa l l' (InfrastructureOne.graphI I)) (InfrastructureOne.delta I) \\<Longrightarrow>\n       efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a) =\n       efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a)\"\n    using InfrastructureOne.cgra.simps InfrastructureOne.graphI.simps InfrastructureOne.move_graph_a_def by presburger\nnext show \"\\<And>z z' G I aa l I'.\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z) =\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z') \\<Longrightarrow>\n       InfrastructureOne.nodes (InfrastructureOne.graphI z) = InfrastructureOne.nodes (InfrastructureOne.graphI z') \\<Longrightarrow>\n       z = I \\<Longrightarrow>\n       z' = I' \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       aa @\\<^bsub>G\\<^esub> l \\<Longrightarrow>\n       l \\<in> InfrastructureOne.nodes G \\<Longrightarrow>\n       InfrastructureOne.enables I l (Actor aa) get \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure\n        (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra G) (InfrastructureOne.agra G) (InfrastructureOne.cgra G)\n          (InfrastructureOne.lgra G) (InfrastructureOne.egra G)\n          ((InfrastructureOne.kgra G)\n           (aa := (InfrastructureOne.kgra G aa)\n              (l := {(x, y). x \\<in> InfrastructureOne.agra G l \\<and> y \\<in> InfrastructureOne.egra G l}))))\n        (InfrastructureOne.delta I) \\<Longrightarrow>\n       efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a) =\n       efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a)\"\n    by force\nnext show \"\\<And>z z' G I aa l I'.\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z) =\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z') \\<Longrightarrow>\n       InfrastructureOne.nodes (InfrastructureOne.graphI z) = InfrastructureOne.nodes (InfrastructureOne.graphI z') \\<Longrightarrow>\n       z = I \\<Longrightarrow>\n       z' = I' \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       aa @\\<^bsub>G\\<^esub> l \\<Longrightarrow>\n       InfrastructureOne.enables I l (Actor aa) put \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure (InfrastructureOne.put_graph_efid aa l G)\n        (InfrastructureOne.delta I) \\<Longrightarrow>\n       efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a) =\n       efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a) \"\n    by (metis InfrastructureOne.cgra.simps InfrastructureOne.graphI.simps InfrastructureOne.put_graph_efid_def efidlist.exhaust efids_inc_ind.simps efids_list.simps fun_upd_apply)\nqed\n\nlemma efids_list_eq0: \"\\<And> z z'. (z \\<rightarrow>\\<^sub>n z') \\<Longrightarrow>\n\\<forall> a. efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a) =\nefids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a)\"\n  by (simp add: efids_list_eq)\n\n\nlemma efid_in_range_invariantO: \"(\\<forall> z z'. (z \\<rightarrow>\\<^sub>n z') \\<longrightarrow> \n         (\\<forall> l \\<in> nodes (graphI z).\n         (\\<forall> e \\<in> (egra (InfrastructureOne.graphI z) l).\n         (\\<exists> a \\<in> actors_graph (graphI z). e \\<in> range (efids_list (InfrastructureOne.cgra (graphI z) a)))))\n          \\<longrightarrow>  (\\<forall> l \\<in> nodes (graphI z').\n         (\\<forall> e \\<in> (egra (InfrastructureOne.graphI z') l). \n         (\\<exists> a \\<in> actors_graph (graphI z'). e \\<in> range (efids_list (InfrastructureOne.cgra (graphI z') a))))))\"\nproof (clarify, frule same_actors0, frule same_nodes0, frule efids_list_eq0, erule state_transition_in.cases)\n  show \"\\<And>z z' l e G I a la l' I'.\n       \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI z).\n          \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI z) l.\n             \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z).\n                e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \\<Longrightarrow>\n       l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI z') \\<Longrightarrow>\n       e \\<in> InfrastructureOne.egra (InfrastructureOne.graphI z') l \\<Longrightarrow>\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z) =\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z') \\<Longrightarrow>\n       InfrastructureOne.nodes (InfrastructureOne.graphI z) = InfrastructureOne.nodes (InfrastructureOne.graphI z') \\<Longrightarrow>\n       z = I \\<Longrightarrow>\n       z' = I' \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       a @\\<^bsub>G\\<^esub> la \\<Longrightarrow>\n       la \\<in> InfrastructureOne.nodes G \\<Longrightarrow>\n       l' \\<in> InfrastructureOne.nodes G \\<Longrightarrow>\n       a \\<in> InfrastructureOne.actors_graph (InfrastructureOne.graphI I) \\<Longrightarrow>\n       InfrastructureOne.enables I l' (Actor a) move \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure\n        (InfrastructureOne.move_graph_a a la l' (InfrastructureOne.graphI I)) (InfrastructureOne.delta I) \\<Longrightarrow>\n       \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z').\n          e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a))\"\n    apply (case_tac \"a \\<in> ((agra (InfrastructureOne.graphI I)) la) &  a \\<notin> ((agra (InfrastructureOne.graphI I)) l')\")\n     prefer 2\n     apply (simp add: move_graph_a_def)+\n    by (metis (mono_tags, hide_lams) Diff_iff UNIV_I efidlist.exhaust efids_cur.simps efids_list.simps fun_upd_apply image_eqI insert_iff)\n     (* for Isabelle 2021-1 ...(mono_tags, opaque_lifting)... *)\nnext show \" \\<And>z z' l e G I a la I'.\n       \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI z).\n          \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI z) l.\n             \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z).\n                e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \\<Longrightarrow>\n       l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI z') \\<Longrightarrow>\n       e \\<in> InfrastructureOne.egra (InfrastructureOne.graphI z') l \\<Longrightarrow>\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z) =\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z') \\<Longrightarrow>\n       InfrastructureOne.nodes (InfrastructureOne.graphI z) = InfrastructureOne.nodes (InfrastructureOne.graphI z') \\<Longrightarrow>\n       z = I \\<Longrightarrow>\n       z' = I' \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       a @\\<^bsub>G\\<^esub> la \\<Longrightarrow>\n       la \\<in> InfrastructureOne.nodes G \\<Longrightarrow>\n       InfrastructureOne.enables I la (Actor a) get \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure\n        (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra G) (InfrastructureOne.agra G) (InfrastructureOne.cgra G)\n          (InfrastructureOne.lgra G) (InfrastructureOne.egra G)\n          ((InfrastructureOne.kgra G)\n           (a := (InfrastructureOne.kgra G a)\n              (la := {(x, y). x \\<in> InfrastructureOne.agra G la \\<and> y \\<in> InfrastructureOne.egra G la}))))\n        (InfrastructureOne.delta I) \\<Longrightarrow>\n       \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z').\n          e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a))\"\n    by simp\nnext show \"\\<And>z z' l e G I a la I'.\n       \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI z).\n          \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI z) l.\n             \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z).\n                e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \\<Longrightarrow>\n       l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI z') \\<Longrightarrow>\n       e \\<in> InfrastructureOne.egra (InfrastructureOne.graphI z') l \\<Longrightarrow>\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z) =\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z') \\<Longrightarrow>\n       InfrastructureOne.nodes (InfrastructureOne.graphI z) = InfrastructureOne.nodes (InfrastructureOne.graphI z') \\<Longrightarrow>\n       \\<forall>a. efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a) =\n           efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a) \\<Longrightarrow>\n       z = I \\<Longrightarrow>\n       z' = I' \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       a @\\<^bsub>G\\<^esub> la \\<Longrightarrow>\n       InfrastructureOne.enables I la (Actor a) put \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure (InfrastructureOne.put_graph_efid a la G)\n        (InfrastructureOne.delta I) \\<Longrightarrow>\n       \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z').\n          e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a))\"\n    by (smt (z3) Diff_iff InfrastructureOne.actors_graph_def InfrastructureOne.atI_def InfrastructureOne.egra.simps InfrastructureOne.graphI.simps InfrastructureOne.put_graph_efid_def UNIV_I efidlist.exhaust efids_cur.simps efids_inc_ind.simps efids_list.simps fun_upd_apply image_eqI insert_iff mem_Collect_eq)\nqed\n\n(* variation for applicability*)\nlemma efid_in_range_invariantOa: \"(z \\<rightarrow>\\<^sub>n z') \\<Longrightarrow> \n         (\\<forall> l \\<in> nodes (graphI z).\n         (\\<forall> e \\<in> (egra (InfrastructureOne.graphI z) l).\n         (\\<exists> a \\<in> actors_graph (graphI z). e \\<in> range (efids_list (InfrastructureOne.cgra (graphI z) a)))))\n          \\<Longrightarrow>  (\\<forall> l \\<in> nodes (graphI z').\n         (\\<forall> e \\<in> (egra (InfrastructureOne.graphI z') l). \n         (\\<exists> a \\<in> actors_graph (graphI z'). e \\<in> range (efids_list (InfrastructureOne.cgra (graphI z') a)))))\"\n  using efid_in_range_invariantO by presburger\n\n(*\nlemma efid_in_range_invariant: \"(\\<forall> z z'. (z \\<rightarrow>\\<^sub>n z') \\<longrightarrow>\n         (l \\<in> nodes (graphI z) \\<longrightarrow>\n         e \\<in> (egra (InfrastructureOne.graphI z) l) \\<longrightarrow> \n         (\\<exists> a \\<in> actors_graph (graphI z). e \\<in> range (efids_list (InfrastructureOne.cgra (graphI z) a))))\n          \\<longrightarrow>  (l \\<in> nodes (graphI z') \\<longrightarrow>\n         e \\<in> (egra (InfrastructureOne.graphI z') l) \\<longrightarrow> \n         (\\<exists> a \\<in> actors_graph (graphI z'). e \\<in> range (efids_list (InfrastructureOne.cgra (graphI z') a)))))\"\n  sorry\n*)\n\nlemma efids_in_range_invariantOO[rule_format]: \"(I, y) \\<in> {(x::infrastructure, y::infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \n        \\<Longrightarrow> (\\<forall> l \\<in> nodes (graphI I).\n            \\<forall> e \\<in> (egra (InfrastructureOne.graphI I) l).\n         \\<exists> a \\<in> actors_graph (graphI I). e \\<in> range (efids_list (InfrastructureOne.cgra (graphI I) a)))\n       \\<Longrightarrow> (\\<forall> l \\<in> nodes (graphI y).\n           \\<forall> e \\<in> (egra (InfrastructureOne.graphI y) l).\n         \\<exists> a \\<in> actors_graph (graphI y). e \\<in> range (efids_list (InfrastructureOne.cgra (graphI y) a)))\"\nproof (erule rtrancl_induct)\n  show \"\\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI I).\n       \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI I) l.\n          \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n             e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<Longrightarrow>\n    \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI I).\n       \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI I) l.\n          \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n             e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a))\"\n    by blast\nnext show \"\\<And>y z. \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI I).\n              \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI I) l.\n                 \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n                    e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<Longrightarrow>\n           (I, y) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n           (y, z) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y} \\<Longrightarrow>\n           \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI y).\n              \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI y) l.\n                 \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI y).\n                    e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI y) a)) \\<Longrightarrow>\n           \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI z).\n              \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI z) l.\n                 \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z).\n                    e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \"\n    using efid_in_range_invariantO by auto\nqed\n\n(*\nlemma efid_in_range_invariantOOO: \"(\\<forall> z z'. (z \\<rightarrow>\\<^sub>n z') \\<longrightarrow> \n         (\\<forall> l \\<in> nodes (graphI z).\n         (\\<forall> e \\<in> (egra (InfrastructureOne.graphI z) l).\n         (\\<exists> a \\<in> agra (graphI z) l. e \\<in> range (efids_list (InfrastructureOne.cgra (graphI z) a)))))\n          \\<longrightarrow>  (\\<forall> l \\<in> nodes (graphI z').\n         (\\<forall> e \\<in> (egra (InfrastructureOne.graphI z') l). \n         (\\<exists> a \\<in> agra (graphI z') l. e \\<in> range (efids_list (InfrastructureOne.cgra (graphI z') a))))))\"\n    sorry\n\nproof (clarify, frule same_actors0, frule same_nodes0, frule efids_list_eq0, erule state_transition_in.cases)\n  show \"\\<And>z z' l e G I a la l' I'.\n       \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI z).\n          \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI z) l.\n             \\<exists>a\\<in>InfrastructureOne.agra (InfrastructureOne.graphI z) l.\n                e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \\<Longrightarrow>\n       l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI z') \\<Longrightarrow>\n       e \\<in> InfrastructureOne.egra (InfrastructureOne.graphI z') l \\<Longrightarrow>\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z) =\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z') \\<Longrightarrow>\n       InfrastructureOne.nodes (InfrastructureOne.graphI z) = InfrastructureOne.nodes (InfrastructureOne.graphI z') \\<Longrightarrow>\n       \\<forall>a. efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a) =\n           efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a) \\<Longrightarrow>\n       z = I \\<Longrightarrow>\n       z' = I' \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       a @\\<^bsub>G\\<^esub> la \\<Longrightarrow>\n       la \\<in> InfrastructureOne.nodes G \\<Longrightarrow>\n       l' \\<in> InfrastructureOne.nodes G \\<Longrightarrow>\n       a \\<in> InfrastructureOne.actors_graph (InfrastructureOne.graphI I) \\<Longrightarrow>\n       InfrastructureOne.enables I l' (Actor a) move \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure\n        (InfrastructureOne.move_graph_a a la l' (InfrastructureOne.graphI I)) (InfrastructureOne.delta I) \\<Longrightarrow>\n       \\<exists>a\\<in>InfrastructureOne.agra (InfrastructureOne.graphI z') l.\n          e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a))\"\n    apply (case_tac \"a \\<in> ((agra (InfrastructureOne.graphI I)) la) &  a \\<notin> ((agra (InfrastructureOne.graphI I)) l')\")\n     prefer 2\n     apply (simp add: move_graph_a_def)+\n    apply (rule conjI)\n     apply (rule impI)+\n     apply (rule conjI)\n    apply (rule impI)+\n      apply fastforce\n     apply (rule impI)\n*)\n\n(*\nlemma efids_in_range_invariantOOOO[rule_format]: \"(I, y) \\<in> {(x::infrastructure, y::infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \n        \\<Longrightarrow> (\\<forall> l \\<in> nodes (graphI I).\n            \\<forall> e \\<in> (egra (InfrastructureOne.graphI I) l).\n         \\<exists> a \\<in> agra (graphI I) l. e \\<in> range (efids_list (InfrastructureOne.cgra (graphI I) a)))\n       \\<Longrightarrow> (\\<forall> l \\<in> nodes (graphI y).\n           \\<forall> e \\<in> (egra (InfrastructureOne.graphI y) l).\n         \\<exists> a \\<in> agra (graphI y) l. e \\<in> range (efids_list (InfrastructureOne.cgra (graphI y) a)))\"\n  sorry\n*)\n\nlemma anonymous_actor_eq: \"(z \\<rightarrow>\\<^sub>n z') \\<Longrightarrow> \nInfrastructureOne.actors_graph (InfrastructureOne.graphI z) \\<noteq> {} \\<Longrightarrow>\n(\\<forall> a \\<in> actors_graph (graphI z). inj (efids_list (InfrastructureOne.cgra (graphI z) a))) \\<Longrightarrow>\n(\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI z). (\\<forall> a' \\<in> actors_graph(InfrastructureOne.graphI z). a \\<noteq> a' \\<longrightarrow>\n     ((range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \\<inter> \n      (range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a')))) = {}))) \\<Longrightarrow>\n    e \\<in> (\\<Union> a \\<in> actors_graph (InfrastructureOne.graphI z). \n            range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)))\n\\<Longrightarrow>    anonymous_actor z e = anonymous_actor z' e\"\n  by (smt (verit, ccfv_threshold) InfrastructureOne.actors_graph_def InfrastructureOne.same_actors0 UN_iff anonymous_actor_def1b efids_list_eq0 mem_Collect_eq)\n\n\n\n\n(* This version is too special because ot the missing quantification \nlemma anonymous_actor: \"(I, y) \\<in> {(x::infrastructure, y::infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \n        \\<Longrightarrow> l \\<in> nodes (graphI I) \\<Longrightarrow>\n         e \\<in> (egra (InfrastructureOne.graphI I) l) \\<Longrightarrow> \n         \\<exists> a \\<in> actors_graph (graphI I). e \\<in> range (efids_list (InfrastructureOne.cgra (graphI I) a))\n       \\<Longrightarrow> l \\<in> nodes (graphI y) \\<Longrightarrow>\n         e \\<in> (egra (InfrastructureOne.graphI y) l) \\<Longrightarrow> \n         \\<exists> a \\<in> actors_graph (graphI y). e \\<in> range (efids_list (InfrastructureOne.cgra (graphI y) a))\"\nproof (erule rtrancl_induct)\n  show \" l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I) \\<Longrightarrow>\n    e \\<in> InfrastructureOne.egra (InfrastructureOne.graphI I) l \\<Longrightarrow>\n    \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n       e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<Longrightarrow>\n    l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI y) \\<Longrightarrow>\n    e \\<in> InfrastructureOne.egra (InfrastructureOne.graphI y) l \\<Longrightarrow>\n    \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n       e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a))\"\n    by blast\nnext show \"\\<And>ya z.\n       l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I) \\<Longrightarrow>\n       e \\<in> InfrastructureOne.egra (InfrastructureOne.graphI I) l \\<Longrightarrow>\n       \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n          e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<Longrightarrow>\n       l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI y) \\<Longrightarrow>\n       e \\<in> InfrastructureOne.egra (InfrastructureOne.graphI y) l \\<Longrightarrow>\n       (I, ya) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n       (ya, z) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y} \\<Longrightarrow>\n       \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI ya).\n          e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI ya) a)) \\<Longrightarrow>\n       \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z).\n          e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \"\n    using InfrastructureOne.same_actors efids_list_eq by auto\nqed\n*)\n\n(* Same as for egra also for kgra *)\nlemma efid_kgra_in_range_invariantO: \n\"\\<forall> (z :: InfrastructureOne.infrastructure)(z' ::InfrastructureOne.infrastructure). (z \\<rightarrow>\\<^sub>n z') \\<longrightarrow> \n         (\\<forall> l \\<in> nodes (graphI z).\n         (\\<forall> e \\<in> (egra (InfrastructureOne.graphI z) l).\n         (\\<exists> a \\<in> actors_graph (graphI z). e \\<in> range (efids_list (InfrastructureOne.cgra (graphI z) a))))) \\<longrightarrow>\n         (\\<forall> l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI z). \n         (\\<forall> h \\<in> InfrastructureOne.actors_graph(InfrastructureOne.graphI z).\n         (\\<forall> e \\<in> (snd`((InfrastructureOne.kgra (InfrastructureOne.graphI z) h l))).\n         (\\<exists> a \\<in> InfrastructureOne.actors_graph (InfrastructureOne.graphI z). \n           e \\<in> range (InfrastructureOne.efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a))))))\n          \\<longrightarrow>  \n         (\\<forall> l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI z'). \n         (\\<forall> h' \\<in> InfrastructureOne.actors_graph (InfrastructureOne.graphI z').\n         (\\<forall> e \\<in> (snd `((InfrastructureOne.kgra (InfrastructureOne.graphI z') h' l))). \n         (\\<exists> a \\<in> InfrastructureOne.actors_graph (InfrastructureOne.graphI z'). \n              e \\<in> range (InfrastructureOne.efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a))))))\"\nproof (clarify, frule same_actors0, erule state_transition_in.cases)\n  show \"\\<And>z z' l h' e a b G I aa la l' I'.\n       \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI z).\n          \\<forall>h\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z).\n             \\<forall>e\\<in>snd ` InfrastructureOne.kgra (InfrastructureOne.graphI z) h l.\n                \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z).\n                   e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \\<Longrightarrow>\n       l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI z') \\<Longrightarrow>\n       h' \\<in> InfrastructureOne.actors_graph (InfrastructureOne.graphI z') \\<Longrightarrow>\n       (a, b) \\<in> InfrastructureOne.kgra (InfrastructureOne.graphI z') h' l \\<Longrightarrow>\n       z = I \\<Longrightarrow>\n       z' = I' \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       aa @\\<^bsub>G\\<^esub> la \\<Longrightarrow>\n       la \\<in> InfrastructureOne.nodes G \\<Longrightarrow>\n       l' \\<in> InfrastructureOne.nodes G \\<Longrightarrow>\n       aa \\<in> InfrastructureOne.actors_graph (InfrastructureOne.graphI I) \\<Longrightarrow>\n       InfrastructureOne.enables I l' (Actor aa) move \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure\n        (InfrastructureOne.move_graph_a aa la l' (InfrastructureOne.graphI I)) (InfrastructureOne.delta I) \\<Longrightarrow>\n       \\<exists>aa\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z').\n          snd (a, b) \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') aa))\"\n    apply (simp add: move_graph_a_def)\n    by (smt (z3) Collect_cong Diff_iff InfrastructureOne.actors_graph_def InfrastructureOne.agra.simps InfrastructureOne.gra.simps InfrastructureOne.nodes_def fun_upd_apply insert_iff singletonD snd_conv)\nnext show \"\\<And>z z' l h' e a b G I aa la I'.\n       \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI z).\n          \\<forall>h\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z).\n             \\<forall>e\\<in>snd ` InfrastructureOne.kgra (InfrastructureOne.graphI z) h l.\n                \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z).\n                   e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \\<Longrightarrow>\n       l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI z') \\<Longrightarrow>\n       h' \\<in> InfrastructureOne.actors_graph (InfrastructureOne.graphI z') \\<Longrightarrow>\n       (a, b) \\<in> InfrastructureOne.kgra (InfrastructureOne.graphI z') h' l \\<Longrightarrow>\n       z = I \\<Longrightarrow>\n       z' = I' \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       aa @\\<^bsub>G\\<^esub> la \\<Longrightarrow>\n       InfrastructureOne.enables I la (Actor aa) put \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure (InfrastructureOne.put_graph_efid aa la G)\n        (InfrastructureOne.delta I) \\<Longrightarrow>\n       \\<exists>aa\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z').\n          snd (a, b) \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') aa)) \"\n    apply (simp add: put_graph_efid_def)\n    by (metis (no_types, opaque_lifting) InfrastructureOne.graphI.simps InfrastructureOne.put_graph_efid_def InfrastructureOne.same_actors0 InfrastructureOne.same_nodes0 InfrastructureOne.state_transition_in.put efidlist.exhaust efids_inc_ind.simps efids_list.simps snd_conv)\nnext show \"\\<And>z z' l h' e a b G I aa la I'.\n       \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI z).\n          \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI z) l.\n             \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z).\n                e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \\<Longrightarrow>\n       \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI z).\n          \\<forall>h\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z).\n             \\<forall>e\\<in>snd ` InfrastructureOne.kgra (InfrastructureOne.graphI z) h l.\n                \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z).\n                   e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \\<Longrightarrow>\n       l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI z') \\<Longrightarrow>\n       h' \\<in> InfrastructureOne.actors_graph (InfrastructureOne.graphI z') \\<Longrightarrow>\n       (a, b) \\<in> InfrastructureOne.kgra (InfrastructureOne.graphI z') h' l \\<Longrightarrow>\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z) =\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z') \\<Longrightarrow>\n       z = I \\<Longrightarrow>\n       z' = I' \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       aa @\\<^bsub>G\\<^esub> la \\<Longrightarrow>\n       la \\<in> InfrastructureOne.nodes G \\<Longrightarrow>\n       InfrastructureOne.enables I la (Actor aa) get \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure\n        (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra G) (InfrastructureOne.agra G) (InfrastructureOne.cgra G)\n          (InfrastructureOne.lgra G) (InfrastructureOne.egra G)\n          ((InfrastructureOne.kgra G)\n           (aa := (InfrastructureOne.kgra G aa)\n              (la := {(x, y). x \\<in> InfrastructureOne.agra G la \\<and> y \\<in> InfrastructureOne.egra G la}))))\n        (InfrastructureOne.delta I) \\<Longrightarrow>\n       \\<exists>aa\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z').\n          snd (a, b) \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') aa))\"\n    apply (subgoal_tac \" \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI z').\n          \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI z') l.\n             \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z').\n                e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a))\")\n     prefer 2\n    using InfrastructureOne.nodes_def apply force\n    apply (case_tac \"l = la\")\n     apply (case_tac \"h' = aa\")\n      apply fastforce\n     apply (subgoal_tac \"(a, b) \\<in> InfrastructureOne.kgra (InfrastructureOne.graphI (InfrastructureOne.infrastructure.Infrastructure\n        (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra G) (InfrastructureOne.agra G) (InfrastructureOne.cgra G)\n          (InfrastructureOne.lgra G) (InfrastructureOne.egra G)\n          ((InfrastructureOne.kgra G)))\n        (InfrastructureOne.delta I))) h' l\")\n      apply (subgoal_tac \"(a, b) \\<in> InfrastructureOne.kgra (InfrastructureOne.graphI z) h' l \")\n    prefer 2\n       apply (metis InfrastructureOne.graphI.simps InfrastructureOne.kgra.simps)\n    apply (rotate_tac 1)\n      apply (drule_tac x = l in bspec)\n       apply simp\n      apply (rotate_tac -1)\n      apply (drule_tac x = h' in bspec)\n       apply simp\n      apply (rotate_tac -1)\n      apply (drule_tac x = b in bspec)\n    apply (metis image_iff snd_conv)\n      apply simp\n     apply simp\n(* *)\n      apply (subgoal_tac \"(a, b) \\<in> InfrastructureOne.kgra (InfrastructureOne.graphI (InfrastructureOne.infrastructure.Infrastructure\n        (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra G) (InfrastructureOne.agra G) (InfrastructureOne.cgra G)\n          (InfrastructureOne.lgra G) (InfrastructureOne.egra G)\n          ((InfrastructureOne.kgra G)))\n        (InfrastructureOne.delta I))) h' l\")\n      apply (subgoal_tac \"(a, b) \\<in> InfrastructureOne.kgra (InfrastructureOne.graphI z) h' l \")\n    prefer 2\n       apply (metis InfrastructureOne.graphI.simps InfrastructureOne.kgra.simps)\n    apply (rotate_tac 1)\n      apply (drule_tac x = l in bspec)\n    apply (simp add: InfrastructureOne.nodes_def)\n      apply (rotate_tac -1)\n      apply (rotate_tac -1)\n      apply (drule_tac x = h' in bspec)\n       apply simp\n      apply (rotate_tac -1)\n      apply (drule_tac x = b in bspec)\n    apply (metis image_iff snd_conv)\n      apply simp\n    by (metis (no_types, lifting) InfrastructureOne.graphI.simps InfrastructureOne.kgra.simps fun_upd_apply)\nqed\n\nlemma efid_kgra_in_range_invariantOO[rule_format]: \n     \"(I, y) \\<in> {(x::infrastructure, y::infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \n \\<Longrightarrow>  (\\<forall> l \\<in> nodes (graphI I).\n         (\\<forall> e \\<in> (egra (InfrastructureOne.graphI I) l).\n         (\\<exists> a \\<in> actors_graph (graphI I). e \\<in> range (efids_list (InfrastructureOne.cgra (graphI I) a)))))\n \\<Longrightarrow>  (\\<forall> l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I). \n         (\\<forall> h \\<in> InfrastructureOne.actors_graph(InfrastructureOne.graphI I).\n         (\\<forall> e \\<in> (snd`((InfrastructureOne.kgra (InfrastructureOne.graphI I) h l))).\n         (\\<exists> a \\<in> InfrastructureOne.actors_graph (InfrastructureOne.graphI I). \n           e \\<in> range (InfrastructureOne.efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a))))))\n          \\<Longrightarrow> \n         (\\<forall> l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI y). \n         (\\<forall> h' \\<in> InfrastructureOne.actors_graph (InfrastructureOne.graphI y).\n         (\\<forall> e \\<in> (snd `((InfrastructureOne.kgra (InfrastructureOne.graphI y) h' l))). \n         (\\<exists> a \\<in> InfrastructureOne.actors_graph (InfrastructureOne.graphI y). \n              e \\<in> range (InfrastructureOne.efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI y) a))))))\"\nproof (erule rtrancl_induct)\n  show \" \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI I).\n       \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI I) l.\n          \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n             e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<Longrightarrow>\n    \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI I).\n       \\<forall>h\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n          \\<forall>e\\<in>snd ` InfrastructureOne.kgra (InfrastructureOne.graphI I) h l.\n             \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n                e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<Longrightarrow>\n    \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI I).\n       \\<forall>h'\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n          \\<forall>e\\<in>snd ` InfrastructureOne.kgra (InfrastructureOne.graphI I) h' l.\n             \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n                e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a))\"\n    by blast\nnext show \" \\<And>y z. \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI I).\n              \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI I) l.\n                 \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n                    e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<Longrightarrow>\n           \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI I).\n              \\<forall>h\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n                 \\<forall>e\\<in>snd ` InfrastructureOne.kgra (InfrastructureOne.graphI I) h l.\n                    \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n                       e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<Longrightarrow>\n           (I, y) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n           (y, z) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y} \\<Longrightarrow>\n           \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI y).\n              \\<forall>h'\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI y).\n                 \\<forall>e\\<in>snd ` InfrastructureOne.kgra (InfrastructureOne.graphI y) h' l.\n                    \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI y).\n                       e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI y) a)) \\<Longrightarrow>\n           \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI z).\n              \\<forall>h'\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z).\n                 \\<forall>e\\<in>snd ` InfrastructureOne.kgra (InfrastructureOne.graphI z) h' l.\n                    \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z).\n                       e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \"\n    using efid_kgra_in_range_invariantO efids_in_range_invariantOO by auto\nqed\n\n\n\nlemma efids_root_efids_inc_lem: \"efids_root (efids_inc_ind el) = efids_root el\"\n  by (case_tac el, simp add: efids_inc_ind_def efids_root_def)\n\ntext \\<open> similar to same_nodes we need to prove invariant for reachable states:\n       xa \\<noteq> a \\<Longrightarrow>\n       efids_root (InfrastructureOne.cgra (InfrastructureOne.graphI I) xa) \\<noteq>\n       efids_root (InfrastructureOne.cgra (InfrastructureOne.graphI I) a) \\<close>\n(* efids invariants *)\nlemma eroots_inj_inv0: \"(\\<forall> z. (\\<forall> z'. (z \\<rightarrow>\\<^sub>n z') \\<longrightarrow>  \n(inj(\\<lambda> x. efids_root(InfrastructureOne.cgra (InfrastructureOne.graphI z) x)) \\<longrightarrow> \ninj(\\<lambda> x. efids_root(InfrastructureOne.cgra (InfrastructureOne.graphI z') x)))))\"\n    apply clarify\n  apply (erule InfrastructureOne.state_transition_in.cases)\n  apply (simp add: InfrastructureOne.move_graph_a_def)\n  apply simp\n  by (smt InfrastructureOne.cgra.simps InfrastructureOne.graphI.simps InfrastructureOne.put_graph_efid_def efids_root_efids_inc_lem fun_upd_apply inj_on_cong)\n\nlemma eroots_inj_inv[rule_format]: \"(I, y) \\<in> {(x::infrastructure, y::infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \n\\<Longrightarrow> (inj(\\<lambda> x. efids_root(InfrastructureOne.cgra (InfrastructureOne.graphI I) x)) \\<longrightarrow> \n     inj(\\<lambda> x. efids_root(InfrastructureOne.cgra (InfrastructureOne.graphI y) x)))\"\nproof (erule rtrancl_induct)\n  show \"inj (\\<lambda>x. efids_root (InfrastructureOne.cgra (InfrastructureOne.graphI I) x)) \\<longrightarrow>\n    inj (\\<lambda>x. efids_root (InfrastructureOne.cgra (InfrastructureOne.graphI I) x))\" by simp\nnext show \"\\<And>y z. (I, y) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n           (y, z) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y} \\<Longrightarrow>\n           inj (\\<lambda>x. efids_root (InfrastructureOne.cgra (InfrastructureOne.graphI I) x)) \\<longrightarrow>\n           inj (\\<lambda>x. efids_root (InfrastructureOne.cgra (InfrastructureOne.graphI y) x)) \\<Longrightarrow>\n           inj (\\<lambda>x. efids_root (InfrastructureOne.cgra (InfrastructureOne.graphI I) x)) \\<longrightarrow>\n           inj (\\<lambda>x. efids_root (InfrastructureOne.cgra (InfrastructureOne.graphI z) x)) \"\n    using eroots_inj_inv0 by auto\nqed\n\nlemma eroots_inj_on_inv0: \"(\\<forall> z. (\\<forall> z'. (z \\<rightarrow>\\<^sub>n z') \\<longrightarrow>  \n(inj_on(\\<lambda> x. efids_root(InfrastructureOne.cgra (InfrastructureOne.graphI z) x)) \n           (actors_graph (InfrastructureOne.graphI z)) \\<longrightarrow> \n     inj_on(\\<lambda> x. efids_root(InfrastructureOne.cgra (InfrastructureOne.graphI z') x))\n           (actors_graph (InfrastructureOne.graphI z')))))\"\n    apply clarify\n  apply (erule InfrastructureOne.state_transition_in.cases)\n    apply (simp add: InfrastructureOne.move_graph_a_def actors_graph_def inj_on_def\n                    InfrastructureOne.gra.simps InfrastructureOne.nodes_def)\n    apply (erule exE)+\n    apply (rule impI)+\n  apply (rule allI)\n    apply (rule impI)+\n    apply (rule allI)\n  apply (rule impI)+\n    apply (erule exE)+\n    apply (erule conjE)+\n    apply (erule exE)+\n(* update to Isabelle 2021 solved remaining subgoals automatically (sledgehammer) *)\n  apply metis\n   apply (simp add: InfrastructureOne.actors_graph_def InfrastructureOne.nodes_def)\n  by (smt (z3) InfrastructureOne.cgra.simps InfrastructureOne.graphI.simps InfrastructureOne.put_graph_efid_def InfrastructureOne.same_actors0 InfrastructureOne.state_transition_in.put efids_root_efids_inc_lem fun_upd_apply inj_on_def)\n\nlemma eroots_inj_on_inv[rule_format]: \"(I, y) \\<in> {(x::infrastructure, y::infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \n\\<Longrightarrow> (inj_on(\\<lambda> x. efids_root(InfrastructureOne.cgra (InfrastructureOne.graphI I) x)) \n           (actors_graph (InfrastructureOne.graphI I)) \\<longrightarrow> \n     inj_on(\\<lambda> x. efids_root(InfrastructureOne.cgra (InfrastructureOne.graphI y) x))\n           (actors_graph (InfrastructureOne.graphI y)))\"\nproof (erule rtrancl_induct)\nshow \"inj_on (\\<lambda>x. efids_root (InfrastructureOne.cgra (InfrastructureOne.graphI I) x))\n     (InfrastructureOne.actors_graph (InfrastructureOne.graphI I)) \\<longrightarrow>\n    inj_on (\\<lambda>x. efids_root (InfrastructureOne.cgra (InfrastructureOne.graphI I) x))\n     (InfrastructureOne.actors_graph (InfrastructureOne.graphI I))\"\n  by simp\nnext show \"\\<And>y z. (I, y) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n           (y, z) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y} \\<Longrightarrow>\n           inj_on (\\<lambda>x. efids_root (InfrastructureOne.cgra (InfrastructureOne.graphI I) x))\n            (InfrastructureOne.actors_graph (InfrastructureOne.graphI I)) \\<longrightarrow>\n           inj_on (\\<lambda>x. efids_root (InfrastructureOne.cgra (InfrastructureOne.graphI y) x))\n            (InfrastructureOne.actors_graph (InfrastructureOne.graphI y)) \\<Longrightarrow>\n           inj_on (\\<lambda>x. efids_root (InfrastructureOne.cgra (InfrastructureOne.graphI I) x))\n            (InfrastructureOne.actors_graph (InfrastructureOne.graphI I)) \\<longrightarrow>\n           inj_on (\\<lambda>x. efids_root (InfrastructureOne.cgra (InfrastructureOne.graphI z) x))\n            (InfrastructureOne.actors_graph (InfrastructureOne.graphI z))\"\n    by (simp add: eroots_inj_on_inv0)\nqed\n\n(* *)\nlemma efids_list_disjoint: \"(\\<forall> (z :: InfrastructureOne.infrastructure). (\\<forall> z'. (z \\<rightarrow>\\<^sub>n z') \\<longrightarrow>\n(\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI z). (\\<forall> a' \\<in> actors_graph(InfrastructureOne.graphI z). a \\<noteq> a' \\<longrightarrow> \n(range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \\<inter> \n range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a'))) = {}))\n\\<longrightarrow>\n(\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI z'). (\\<forall> a' \\<in> actors_graph(InfrastructureOne.graphI z'). a \\<noteq> a' \\<longrightarrow> \n((range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a)) \\<inter> \n (range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a')))) = {})))\n))\"\n    apply clarify\n  apply (erule InfrastructureOne.state_transition_in.cases)\n  apply (smt (verit, ccfv_SIG) InfrastructureOne.cgra.simps InfrastructureOne.graphI.simps InfrastructureOne.move_graph_a_def InfrastructureOne.same_actors0 InfrastructureOne.state_transition_in.move)\n   apply (simp add: InfrastructureOne.actors_graph_def InfrastructureOne.nodes_def)\n  apply (simp add: put_graph_efid_def)\n  by (metis InfrastructureOne.graphI.simps InfrastructureOne.put_graph_efid_def InfrastructureOne.same_actors0 InfrastructureOne.state_transition_in.put efidlist.exhaust efids_inc_ind.simps efids_list.simps)\n\n\n(* efids_cur inj_on*)\nlemma efids_cur_in_efids_listO: \"a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I) \\<Longrightarrow>\n           efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)\n         \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a))\"\n  apply (case_tac \"(InfrastructureOne.cgra (InfrastructureOne.graphI I) a)\")\n  by simp\n\n\nlemma efids_cur_in_efids_list: \"a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I) \\<Longrightarrow>\n           efids_cur (efids_inc_ind (InfrastructureOne.cgra (InfrastructureOne.graphI I) a))\n         \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a))\"\n  apply (case_tac \"(InfrastructureOne.cgra (InfrastructureOne.graphI I) a)\")\n  by simp\n\nlemma inj_on_put_preserve0: \"\\<forall>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n          \\<forall>a'\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n             a \\<noteq> a' \\<longrightarrow>\n             range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<inter>\n             range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a')) =\n             {} \\<Longrightarrow>\n             \\<forall>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n             efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a) \\<noteq>\n              efids_cur(efids_inc_ind (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<Longrightarrow>\n             inj_on (\\<lambda>x. efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) x))\n                    (InfrastructureOne.actors_graph (InfrastructureOne.graphI I)) \\<Longrightarrow>\n            a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I) \\<Longrightarrow>\n              inj_on ((\\<lambda>x. efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) x))\n                      (a:= efids_cur (efids_inc_ind ((InfrastructureOne.cgra (InfrastructureOne.graphI I) a)))))\n        (InfrastructureOne.actors_graph (InfrastructureOne.graphI I))\"\n  apply (rule Fun.inj_on_fun_updI)\n   apply blast\n  apply (unfold image_def)\n  apply (rule notI)\n  apply (drule CollectD)\n  apply (erule bexE)\n  apply (case_tac \"x = a\")\n   apply fastforce\n  apply (drule_tac x = a in bspec)\n   apply assumption\n  apply (rotate_tac -1)\n  apply (drule_tac x = x in bspec)\n    apply assumption\n   apply (subgoal_tac \"efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) x) \\<in>\n                       range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) x))\")\n   apply (subgoal_tac \"efids_cur (efids_inc_ind (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<in>\n                     range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a))\")\n    apply fastforce\n  apply (simp add: efids_list_def)\n   prefer 2\n  apply (case_tac \"InfrastructureOne.cgra (InfrastructureOne.graphI I) x\")\n  apply simp\n  by (metis efidlist.exhaust efidlist.simps(3) efids_cur_in_efids_list efids_list.simps)\n\n\nlemma inj_on_put_preserve: \"\\<forall>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n          \\<forall>a'\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n             a \\<noteq> a' \\<longrightarrow>\n             range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<inter>\n             range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a')) =\n             {} \\<Longrightarrow>\n       \\<forall>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n             efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a) \\<noteq>\n          efids_cur(efids_inc_ind (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<Longrightarrow>\n       inj_on (\\<lambda>x. efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) x))\n        (InfrastructureOne.actors_graph (InfrastructureOne.graphI I)) \\<Longrightarrow>\n      inj_on (\\<lambda>x. efids_cur\n              (if x = a then efids_inc_ind (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)\n               else InfrastructureOne.cgra (InfrastructureOne.graphI I) x))\n        (InfrastructureOne.actors_graph (InfrastructureOne.graphI I))\"\n  by (smt (verit, ccfv_SIG) fun_upd_apply inj_on_cong inj_on_put_preserve0)\n\n\n\n\nlemma efids_cur_inj_on_inv0[rule_format]: \"(\\<forall> z. (\\<forall> z'. (z \\<rightarrow>\\<^sub>n z') \\<longrightarrow>\n(\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI z). (\\<forall> a' \\<in> actors_graph(InfrastructureOne.graphI z). a \\<noteq> a' \\<longrightarrow> \n((range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \\<inter> \n (range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a')))) = {}))) \\<longrightarrow>\n (\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI z). \n      efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI z) a) \\<noteq>\n              efids_cur(efids_inc_ind (InfrastructureOne.cgra (InfrastructureOne.graphI z) a))) \\<longrightarrow>\n(inj_on(\\<lambda> x. efids_cur(InfrastructureOne.cgra (InfrastructureOne.graphI z) x)) \n           (actors_graph (InfrastructureOne.graphI z)) \\<longrightarrow> \n     inj_on(\\<lambda> x. efids_cur(InfrastructureOne.cgra (InfrastructureOne.graphI z') x))\n           (actors_graph (InfrastructureOne.graphI z')))))\"\n    apply clarify\n  apply (erule InfrastructureOne.state_transition_in.cases)\n    apply (simp add: InfrastructureOne.move_graph_a_def actors_graph_def inj_on_def\n                    InfrastructureOne.gra.simps InfrastructureOne.nodes_def)\n    apply (erule exE)+\n    apply (rule impI)+\n  apply (rule allI)\n    apply (rule impI)+\n    apply (rule allI)\n  apply (rule impI)+\n    apply (erule exE)+\n    apply (erule conjE)+\n    apply (erule exE)+\n(* update to Isabelle 2021 solved remaining subgoals automatically (sledgehammer) *)\n    apply metis\n(* get *)\n  using InfrastructureOne.same_actors0 InfrastructureOne.state_transition_in.get apply fastforce\n(* put *)\n  by (smt (z3) InfrastructureOne.cgra.simps InfrastructureOne.graphI.simps InfrastructureOne.put_graph_efid_def InfrastructureOne.same_actors0 InfrastructureOne.state_transition_in.put fun_upd_apply inj_on_cong inj_on_put_preserve0)\n\n\n(* additional invariants for applying/generalizing efids_cur_inj_on_inv0*)\nlemma ran_efidslist_disjoint:\n\"(\\<forall> z. (\\<forall> z'. (z \\<rightarrow>\\<^sub>n z') \\<longrightarrow>\n(\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI z). (\\<forall> a' \\<in> actors_graph(InfrastructureOne.graphI z). a \\<noteq> a' \\<longrightarrow> \n((range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \\<inter> \n (range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a')))) = {})))\n\\<longrightarrow>\n(\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI z'). (\\<forall> a' \\<in> actors_graph(InfrastructureOne.graphI z'). a \\<noteq> a' \\<longrightarrow> \n((range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a)) \\<inter> \n (range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a')))) = {})))\n))\"\n  by (rule efids_list_disjoint)\n\nlemma ran_efids_list_disjoint_refl: \"(I, y) \\<in> {(x::infrastructure, y::infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n(\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI I). (\\<forall> a' \\<in> actors_graph(InfrastructureOne.graphI I). a \\<noteq> a' \\<longrightarrow>\n((range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<inter> \n (range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a')))) = {}))) \\<Longrightarrow>\n(\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI y). (\\<forall> a' \\<in> actors_graph(InfrastructureOne.graphI y). a \\<noteq> a' \\<longrightarrow>\n((range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI y) a)) \\<inter> \n (range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI y) a')))) = {})))\"\nproof (erule rtrancl_induct, simp)\n  show \"\\<And>y z. \\<forall>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n              \\<forall>a'\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n                 a \\<noteq> a' \\<longrightarrow>\n                 range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<inter>\n                 range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a')) =\n                 {} \\<Longrightarrow>\n           (I, y) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n           (y, z) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y} \\<Longrightarrow>\n           \\<forall>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI y).\n              \\<forall>a'\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI y).\n                 a \\<noteq> a' \\<longrightarrow>\n                 range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI y) a)) \\<inter>\n                 range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI y) a')) =\n                 {} \\<Longrightarrow>\n           \\<forall>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z).\n              \\<forall>a'\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z).\n                 a \\<noteq> a' \\<longrightarrow>\n                 range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \\<inter>\n                 range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a')) =\n                 {}\"\n    by (simp add: ran_efidslist_disjoint)\nqed\n\n\n(* injectivity of efids_list is preserved and implies \n (\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI z). \n      efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI z) a) \\<noteq>\n              efids_cur(efids_inc_ind (InfrastructureOne.cgra (InfrastructureOne.graphI z) a))) \n*)\n\nlemma efids_list_inj: \"(\\<forall> z. (\\<forall> z'. (z \\<rightarrow>\\<^sub>n z') \\<longrightarrow>\n (\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI z). \n      inj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \\<longrightarrow>\n       inj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a)))))\"\n\nproof (clarify, erule InfrastructureOne.state_transition_in.cases)\n  show \"\\<And>z z' a G I aa l l' I'.\n       a \\<in> InfrastructureOne.actors_graph (InfrastructureOne.graphI z) \\<Longrightarrow>\n       inj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \\<Longrightarrow>\n       z = I \\<Longrightarrow>\n       z' = I' \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       aa @\\<^bsub>G\\<^esub> l \\<Longrightarrow>\n       l \\<in> InfrastructureOne.nodes G \\<Longrightarrow>\n       l' \\<in> InfrastructureOne.nodes G \\<Longrightarrow>\n       aa \\<in> InfrastructureOne.actors_graph (InfrastructureOne.graphI I) \\<Longrightarrow>\n       InfrastructureOne.enables I l' (Actor aa) move \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure\n        (InfrastructureOne.move_graph_a aa l l' (InfrastructureOne.graphI I)) (InfrastructureOne.delta I) \\<Longrightarrow>\n       inj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a))\"\n    using InfrastructureOne.move_graph_a_def by force\nnext show \"\\<And>z z' a G I aa l I'.\n       a \\<in> InfrastructureOne.actors_graph (InfrastructureOne.graphI z) \\<Longrightarrow>\n       inj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \\<Longrightarrow>\n       z = I \\<Longrightarrow>\n       z' = I' \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       aa @\\<^bsub>G\\<^esub> l \\<Longrightarrow>\n       l \\<in> InfrastructureOne.nodes G \\<Longrightarrow>\n       InfrastructureOne.enables I l (Actor aa) get \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure\n        (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra G) (InfrastructureOne.agra G) (InfrastructureOne.cgra G)\n          (InfrastructureOne.lgra G) (InfrastructureOne.egra G)\n          ((InfrastructureOne.kgra G)\n           (aa := (InfrastructureOne.kgra G aa)\n              (l := {(x, y). x \\<in> InfrastructureOne.agra G l \\<and> y \\<in> InfrastructureOne.egra G l}))))\n        (InfrastructureOne.delta I) \\<Longrightarrow>\n       inj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a))\"\n    by simp\nnext show \"\\<And>z z' a G I aa l I'.\n       a \\<in> InfrastructureOne.actors_graph (InfrastructureOne.graphI z) \\<Longrightarrow>\n       inj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \\<Longrightarrow>\n       z = I \\<Longrightarrow>\n       z' = I' \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       aa @\\<^bsub>G\\<^esub> l \\<Longrightarrow>\n       InfrastructureOne.enables I l (Actor aa) put \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure (InfrastructureOne.put_graph_efid aa l G)\n        (InfrastructureOne.delta I) \\<Longrightarrow>\n       inj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z') a))\"\n    by (metis InfrastructureOne.cgra.simps InfrastructureOne.graphI.simps InfrastructureOne.put_graph_efid_def efidlist.exhaust efids_inc_ind.simps efids_list.simps fun_upd_apply)\nqed\n\n\nlemma efids_list_inj_refl: \"(I, y) \\<in> {(x::infrastructure, y::infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\na \\<in> actors_graph(InfrastructureOne.graphI I) \\<Longrightarrow>\ninj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<Longrightarrow>\ninj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI y) a))\"\nproof (erule rtrancl_induct, simp)\n  show \"\\<And>y z. a \\<in> InfrastructureOne.actors_graph (InfrastructureOne.graphI I) \\<Longrightarrow>\n           inj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<Longrightarrow>\n           (I, y) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n           (y, z) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y} \\<Longrightarrow>\n           inj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI y) a)) \\<Longrightarrow>\n           inj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a))\"\n    by (simp add: InfrastructureOne.same_actors efids_list_inj)\nqed\n\nlemma efids_list_inj_imp_inc_ind_not_eq[rule_format]: \" (\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI z). \n inj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \\<longrightarrow>\n      efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI z) a) \\<noteq>\n              efids_cur(efids_inc_ind (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)))\"\nproof (clarify, simp add: efids_inc_ind_def efids_cur_def efids_list_def, case_tac \"InfrastructureOne.graphI z\", simp)\n  show \"\\<And>a x1 x2 x3 x4 x5 x6.\n       a \\<in> InfrastructureOne.actors_graph (InfrastructureOne.igraph.Lgraph x1 x2 x3 x4 x5 x6) \\<Longrightarrow>\n       inj (rec_efidlist (\\<lambda>e n ef. ef) (x3 a)) \\<Longrightarrow>\n       rec_efidlist (\\<lambda>e n ef. ef n) (x3 a) = rec_efidlist (\\<lambda>e n ef. ef n) (rec_efidlist (\\<lambda>e n. Efids e (Suc n)) (x3 a)) \\<Longrightarrow>\n       InfrastructureOne.graphI z = InfrastructureOne.igraph.Lgraph x1 x2 x3 x4 x5 x6 \\<Longrightarrow> False\"\n    by (smt (z3) efidlist.exhaust efidlist.rec n_not_Suc_n the_inv_f_f)\nqed\n\n\nlemma efids_cur_inj_on_inv: \"(I, y) \\<in> {(x::infrastructure, y::infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n(\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI I). (\\<forall> a' \\<in> actors_graph(InfrastructureOne.graphI I). a \\<noteq> a' \\<longrightarrow>\n((range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<inter> \n (range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a')))) = {}))) \\<Longrightarrow>\n \\<forall> a \\<in> actors_graph(InfrastructureOne.graphI I). \n     inj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<Longrightarrow>\n(inj_on(\\<lambda> x. efids_cur(InfrastructureOne.cgra (InfrastructureOne.graphI I) x)) \n           (actors_graph (InfrastructureOne.graphI I))) \\<Longrightarrow>\n(inj_on(\\<lambda> x. efids_cur(InfrastructureOne.cgra (InfrastructureOne.graphI y) x)) \n           (actors_graph (InfrastructureOne.graphI y)))\"\nproof (erule rtrancl_induct, simp)\n  show \"\\<And>y z. \\<forall>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n              \\<forall>a'\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n                 a \\<noteq> a' \\<longrightarrow>\n                 range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<inter>\n                 range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a')) =\n                 {} \\<Longrightarrow>\n           \\<forall>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n              inj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<Longrightarrow>\n           inj_on (\\<lambda>x. efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) x))\n            (InfrastructureOne.actors_graph (InfrastructureOne.graphI I)) \\<Longrightarrow>\n           (I, y) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n           (y, z) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y} \\<Longrightarrow>\n           inj_on (\\<lambda>x. efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI y) x))\n            (InfrastructureOne.actors_graph (InfrastructureOne.graphI y)) \\<Longrightarrow>\n           inj_on (\\<lambda>x. efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI z) x))\n            (InfrastructureOne.actors_graph (InfrastructureOne.graphI z))\"\n    apply (rule_tac z = y in efids_cur_inj_on_inv0, simp)\n      apply (simp add: ran_efids_list_disjoint_refl)\n    apply (rule efids_list_inj_imp_inc_ind_not_eq, assumption)\n    apply (rule efids_list_inj_refl, simp)\n    using InfrastructureOne.same_actors apply presburger\n     apply (metis InfrastructureOne.same_actors)\n    by blast\nqed\n\n(* agra \\<longrightarrow> egra invariants *) \nlemma actor_unique_loc_lem00[rule_format]: \"\\<forall> z z'. z \\<rightarrow>\\<^sub>n z' \\<longrightarrow>  nodes (graphI z) = nodes (graphI z') \\<longrightarrow>\n         (\\<forall> a.\n             (\\<forall> l l'. l \\<in> nodes (graphI z) \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI z) l \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI z) l' \\<longrightarrow> l = l')) \n        \\<longrightarrow> (\\<forall> a.\n             (\\<forall> l l'. l \\<in> nodes (graphI z') \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI z') l \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI z') l' \\<longrightarrow> l = l'))\"\n  apply (rule allI)+\n  apply (rule impI)+\n  apply (erule InfrastructureOne.state_transition_in.cases)\n    apply (simp add: move_graph_a_def)\n  apply auto[1]\n  using InfrastructureOne.agra.simps InfrastructureOne.graphI.simps apply presburger\n  using InfrastructureOne.agra.simps InfrastructureOne.graphI.simps InfrastructureOne.put_graph_efid_def by presburger\n\n\n\nlemma actor_unique_loc_lem0[rule_format]: \"\\<forall> z z'. z \\<rightarrow>\\<^sub>n z' \\<longrightarrow>  nodes (graphI z) = nodes (graphI z') \\<longrightarrow>\n         (\\<forall> a.\n             (\\<forall> l. l \\<in> nodes (graphI z) \\<longrightarrow>  (\\<forall> l'. l' \\<in> nodes (graphI z) \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI z) l \\<longrightarrow> \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI z) l' \\<longrightarrow> l = l'))) \n        \\<longrightarrow> (\\<forall> a.\n             (\\<forall> l. l \\<in> nodes (graphI z') \\<longrightarrow>  (\\<forall> l'. l' \\<in> nodes (graphI z') \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI z') l \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI z') l' \\<longrightarrow> l = l')))\"\n  apply (rule allI)+\n  apply (rule impI)+\n  apply (erule InfrastructureOne.state_transition_in.cases)\n    apply (simp add: move_graph_a_def)\n  using InfrastructureOne.atI_def apply force\n  using InfrastructureOne.agra.simps InfrastructureOne.graphI.simps apply presburger\n  using InfrastructureOne.agra.simps InfrastructureOne.graphI.simps InfrastructureOne.put_graph_efid_def by presburger\nthm actor_unique_loc_lem0\n\nlemma actor_unique_loc_lem0a: \"z \\<rightarrow>\\<^sub>n z' \\<Longrightarrow>  nodes (graphI z) = nodes (graphI z') \\<Longrightarrow>\n         (\\<forall> a.\n             (\\<forall> l l'. l \\<in> nodes (graphI z) \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI z) l \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI z) l' \\<longrightarrow> l = l'))\n        \\<Longrightarrow> l \\<in> nodes (graphI z') \\<Longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI z') l \\<Longrightarrow> \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI z') l' \\<Longrightarrow> l = l'\"\n  using actor_unique_loc_lem00 by presburger\n\n\nlemma actor_unique_loc_lem[rule_format]: \"(I, y) \\<in> {(x::infrastructure, y::infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n         (\\<forall> a.\n             (\\<forall> l l'. l \\<in> nodes (graphI I) \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> l = l')) \\<Longrightarrow>\n         (\\<forall> a.\n             (\\<forall> l l'. l \\<in> nodes (graphI y) \\<longrightarrow> \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI y) l \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI y) l' \\<longrightarrow> l = l'))\"\nproof (erule rtrancl_induct, simp)\n  show \"\\<And>y z. \\<forall>a l l'.\n              l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I) \\<longrightarrow>\n              a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<longrightarrow>\n              a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> l = l' \\<Longrightarrow>\n           (I, y) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n           (y, z) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y} \\<Longrightarrow>\n           \\<forall>a l l'.\n              l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI y) \\<longrightarrow>\n              a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI y) l \\<longrightarrow>\n              a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI y) l' \\<longrightarrow> l = l' \\<Longrightarrow>\n           \\<forall>a l l'.\n              l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI z) \\<longrightarrow>\n              a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI z) l \\<longrightarrow>\n              a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI z) l' \\<longrightarrow> l = l'\"\n    by (metis CollectD InfrastructureOne.same_nodes actor_unique_loc_lem0a case_prodD rtrancl.rtrancl_into_rtrancl)\nqed\n\nlemma isthere_lem0: \"\\<forall> z z'. z \\<rightarrow>\\<^sub>n z' \\<longrightarrow>  nodes (graphI z) = nodes (graphI z') \\<longrightarrow>\n           (inj_on(\\<lambda> x. efids_cur(InfrastructureOne.cgra (InfrastructureOne.graphI z) x)) \n                     (actors_graph (InfrastructureOne.graphI z))) \\<longrightarrow>\n (\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI z). \n      efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI z) a) \\<noteq>\n              efids_cur(efids_inc_ind (InfrastructureOne.cgra (InfrastructureOne.graphI z) a))) \\<longrightarrow>\n(\\<forall> a.\n             (\\<forall> l l'. l \\<in> nodes (graphI z) \\<longrightarrow>\n                a \\<in>  agra (graphI z) l \\<longrightarrow>  a \\<in>  agra (graphI z) l' \\<longrightarrow> l = l')) \\<longrightarrow>\n         (\\<forall> a.\n             (\\<forall> l. l \\<in> nodes (graphI z) \\<longrightarrow>  a \\<in>  agra (graphI z) l \\<longrightarrow>\n            efids_cur ((InfrastructureOne.cgra (graphI z) a)) \\<in> egra (graphI z) l)) \n        \\<longrightarrow> (\\<forall> a. \n           (\\<forall> l'. l' \\<in> nodes (graphI z') \\<longrightarrow>  a \\<in>  agra (graphI z') l' \\<longrightarrow>\n          efids_cur ((InfrastructureOne.cgra (graphI z') a)) \\<in> egra (graphI z') l'))\"\n  apply (rule allI)+\n  apply (rule impI)\n  apply (rule InfrastructureOne.state_transition_in.cases, assumption)\n    apply (simp add: move_graph_a_def)\n    apply (rule conjI)\n     apply (rule impI)+\n     apply (rule allI)\n      apply (rule impI)+\n      apply (erule conjE)+\n  apply (metis (no_types, lifting) InfrastructureOne.actors_graph_def inj_on_contraD mem_Collect_eq)\n  apply (rule impI)+\n    apply fastforce\n(* get *)\n      apply (rule impI)+\n  using InfrastructureOne.agra.simps InfrastructureOne.cgra.simps InfrastructureOne.egra.simps InfrastructureOne.graphI.simps apply presburger\n(* put *)\n  apply (rule impI)+\n  apply (rule allI)+\n  apply (rule impI)+\n  apply simp\n  apply (simp add: put_graph_efid_def)\n  apply (rule conjI)\n  prefer 2\n  apply (metis (mono_tags, lifting) InfrastructureOne.actors_graph_def InfrastructureOne.atI_def inj_on_def mem_Collect_eq)\n  apply (rule impI)+\n  apply (subgoal_tac \"l' = l\")\n   apply simp\n  apply (rule_tac z = z and z' = z' and a = a in actor_unique_loc_lem0a)\n       prefer 5\n  apply simp\n  apply force\n  apply (meson InfrastructureOne.same_nodes0)\n  apply presburger\n  apply (metis InfrastructureOne.same_nodes0)\nby (simp add: atI_def)\n\nlemma isthere_lem0a: \"z \\<rightarrow>\\<^sub>n z' \\<Longrightarrow>  nodes (graphI z) = nodes (graphI z') \\<Longrightarrow>\n           (inj_on(\\<lambda> x. efids_cur(InfrastructureOne.cgra (InfrastructureOne.graphI z) x)) \n                     (actors_graph (InfrastructureOne.graphI z))) \\<Longrightarrow>\n (\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI z). \n      efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI z) a) \\<noteq>\n              efids_cur(efids_inc_ind (InfrastructureOne.cgra (InfrastructureOne.graphI z) a))) \\<Longrightarrow>\n(\\<forall> a.\n             (\\<forall> l l'. l \\<in> nodes (graphI z) \\<longrightarrow>\n                a \\<in>  agra (graphI z) l \\<longrightarrow>  a \\<in>  agra (graphI z) l' \\<longrightarrow> l = l')) \\<Longrightarrow>\n         (\\<forall> a.\n             (\\<forall> l. l \\<in> nodes (graphI z) \\<longrightarrow>  a \\<in>  agra (graphI z) l \\<longrightarrow>\n            efids_cur ((InfrastructureOne.cgra (graphI z) a)) \\<in> egra (graphI z) l)) \\<Longrightarrow>\n         (\\<forall> a. \n           (\\<forall> l'. l' \\<in> nodes (graphI z') \\<longrightarrow>  a \\<in>  agra (graphI z') l' \\<longrightarrow>\n          efids_cur ((InfrastructureOne.cgra (graphI z') a)) \\<in> egra (graphI z') l'))\"\n  using isthere_lem0 by presburger\n\n\nlemma isthere_lem00: \"\\<forall> z z'. z \\<rightarrow>\\<^sub>n z' \\<longrightarrow>  nodes (graphI z) = nodes (graphI z') \\<longrightarrow>\n           (inj_on(\\<lambda> x. efids_cur(InfrastructureOne.cgra (InfrastructureOne.graphI z) x)) \n                     (actors_graph (InfrastructureOne.graphI z))) \\<longrightarrow>\n (\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI z). \n      inj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a))) \\<longrightarrow>\n(\\<forall> a.\n             (\\<forall> l l'. l \\<in> nodes (graphI z) \\<longrightarrow>\n                a \\<in>  agra (graphI z) l \\<longrightarrow>  a \\<in>  agra (graphI z) l' \\<longrightarrow> l = l')) \\<longrightarrow>\n         (\\<forall> a.\n             (\\<forall> l. l \\<in> nodes (graphI z) \\<longrightarrow>  a \\<in>  agra (graphI z) l \\<longrightarrow>\n            efids_cur ((InfrastructureOne.cgra (graphI z) a)) \\<in> egra (graphI z) l)) \n        \\<longrightarrow> (\\<forall> a. \n           (\\<forall> l'. l' \\<in> nodes (graphI z') \\<longrightarrow>  a \\<in>  agra (graphI z') l' \\<longrightarrow>\n          efids_cur ((InfrastructureOne.cgra (graphI z') a)) \\<in> egra (graphI z') l'))\"\n  apply (rule allI)+\n  apply (rule impI)\n  apply (rule InfrastructureOne.state_transition_in.cases, assumption)\n    apply (simp add: move_graph_a_def)\n    apply (rule conjI)\n     apply (rule impI)+\n     apply (rule allI)\n      apply (rule impI)+\n      apply (erule conjE)+\n  apply (metis (no_types, lifting) InfrastructureOne.actors_graph_def inj_on_contraD mem_Collect_eq)\n  apply (rule impI)+\n    apply fastforce\n(* get *)\n      apply (rule impI)+\n  using InfrastructureOne.agra.simps InfrastructureOne.cgra.simps InfrastructureOne.egra.simps InfrastructureOne.graphI.simps apply presburger\n(* put *)\n  apply (rule impI)+\n  apply (rule allI)+\n  apply (rule impI)+\n  apply simp\n  apply (simp add: put_graph_efid_def)\n  apply (rule conjI)\n  prefer 2\n  apply (metis (mono_tags, lifting) InfrastructureOne.actors_graph_def InfrastructureOne.atI_def inj_on_def mem_Collect_eq)\n  apply (rule impI)+\n  apply (subgoal_tac \"l' = l\")\n   apply simp\n  apply (rule_tac z = z and z' = z' and a = a in actor_unique_loc_lem0a)\n       prefer 5\n  apply simp\n  apply force\n  apply (meson InfrastructureOne.same_nodes0)\n  apply presburger\n  apply (metis InfrastructureOne.same_nodes0)\nby (simp add: atI_def)\n\nlemma isthere_lem00a: \"z \\<rightarrow>\\<^sub>n z' \\<Longrightarrow> nodes (graphI z) = nodes (graphI z') \\<Longrightarrow>\n           (inj_on(\\<lambda> x. efids_cur(InfrastructureOne.cgra (InfrastructureOne.graphI z) x)) \n                     (actors_graph (InfrastructureOne.graphI z))) \\<Longrightarrow>\n (\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI z). \n      inj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a))) \\<Longrightarrow>\n(\\<forall> a.\n             (\\<forall> l l'. l \\<in> nodes (graphI z) \\<longrightarrow>\n                a \\<in>  agra (graphI z) l \\<longrightarrow>  a \\<in>  agra (graphI z) l' \\<longrightarrow> l = l')) \\<Longrightarrow>\n         (\\<forall> a.\n             (\\<forall> l. l \\<in> nodes (graphI z) \\<longrightarrow>  a \\<in>  agra (graphI z) l \\<longrightarrow>\n            efids_cur ((InfrastructureOne.cgra (graphI z) a)) \\<in> egra (graphI z) l)) \\<Longrightarrow>\n         (\\<forall> a. \n           (\\<forall> l'. l' \\<in> nodes (graphI z') \\<longrightarrow>  a \\<in>  agra (graphI z') l' \\<longrightarrow>\n          efids_cur ((InfrastructureOne.cgra (graphI z') a)) \\<in> egra (graphI z') l'))\"\n  using isthere_lem00 by presburger\n\n\n\n\n\nlemma is_there_lem[rule_format]: \"(I, y) \\<in> {(x::infrastructure, y::infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n     (\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI I). (\\<forall> a' \\<in> actors_graph(InfrastructureOne.graphI I). a \\<noteq> a' \\<longrightarrow>\n     ((range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<inter> \n      (range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a')))) = {}))) \\<Longrightarrow>\n        (inj_on(\\<lambda> x. efids_cur(InfrastructureOne.cgra (InfrastructureOne.graphI I) x)) \n                     (actors_graph (InfrastructureOne.graphI I))) \\<Longrightarrow>\n        (\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI I). \n               inj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a))) \\<Longrightarrow>\n           (\\<forall> a.\n             (\\<forall> l l'. l \\<in> nodes (graphI I) \\<longrightarrow>\n                a \\<in>  agra (graphI I) l \\<longrightarrow>  a \\<in>  agra (graphI I) l' \\<longrightarrow> l = l')) \\<Longrightarrow>\n(\\<forall> a.\n             (\\<forall> l. l \\<in> nodes (graphI I) \\<longrightarrow>  a \\<in>  agra (graphI I) l \\<longrightarrow>\n            efids_cur ((InfrastructureOne.cgra (graphI I) a)) \\<in> egra (graphI I) l)) \\<longrightarrow>\n        (\\<forall> a. \n           (\\<forall> l'. l' \\<in> nodes (graphI y) \\<longrightarrow>  a \\<in>  agra (graphI y) l' \\<longrightarrow>\n                  efids_cur ((InfrastructureOne.cgra (graphI y) a)) \\<in> egra (graphI y) l'))\"\nproof (erule rtrancl_induct, simp)\n  show \"\\<And>y z. \\<forall>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n              \\<forall>a'\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n                 a \\<noteq> a' \\<longrightarrow>\n                 range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<inter>\n                 range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a')) =\n                 {} \\<Longrightarrow>\n           inj_on (\\<lambda>x. efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) x))\n            (InfrastructureOne.actors_graph (InfrastructureOne.graphI I)) \\<Longrightarrow>\n           \\<forall>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n              inj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<Longrightarrow>\n           \\<forall>a l l'.\n              l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I) \\<longrightarrow>\n              a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<longrightarrow>\n              a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> l = l' \\<Longrightarrow>\n           (I, y) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n           (y, z) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y} \\<Longrightarrow>\n           (\\<forall>a l. l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I) \\<longrightarrow>\n                  a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<longrightarrow>\n                  efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)\n                  \\<in> InfrastructureOne.egra (InfrastructureOne.graphI I) l) \\<longrightarrow>\n           (\\<forall>a l'.\n               l' \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI y) \\<longrightarrow>\n               a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI y) l' \\<longrightarrow>\n               efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI y) a)\n               \\<in> InfrastructureOne.egra (InfrastructureOne.graphI y) l') \\<Longrightarrow>\n           (\\<forall>a l. l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I) \\<longrightarrow>\n                  a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<longrightarrow>\n                  efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)\n                  \\<in> InfrastructureOne.egra (InfrastructureOne.graphI I) l) \\<longrightarrow>\n           (\\<forall>a l'.\n               l' \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI z) \\<longrightarrow>\n               a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI z) l' \\<longrightarrow>\n               efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)\n               \\<in> InfrastructureOne.egra (InfrastructureOne.graphI z) l') \"\n    apply (rule impI)\n  apply (rule_tac z = y in isthere_lem00a)\n    apply force\n    apply (meson InfrastructureOne.same_nodes r_into_rtrancl)\n    using efids_cur_inj_on_inv apply presburger\n    apply (metis InfrastructureOne.same_actors efids_list_inj_refl)\n    using actor_unique_loc_lem apply presburger\n    by meson\nqed\n\n\nlemma ext_image: \"\\<forall> x \\<in> A. f x = g x \\<Longrightarrow> f ` A = g ` A\"\n  by simp\n\nlemma ext_ifte[rule_format]: \"(\\<forall> a l. P a l = Q a l) \\<Longrightarrow> (\\<forall> a l. Q a l \\<longrightarrow> t a l = r a l) \\<Longrightarrow> \n           (\\<lambda> x y. if P x y then t x y else t') = (\\<lambda> x y. if Q x y then r x y else t')\"\n  by meson\n\nlemma ext_ifte'[rule_format]: \"(\\<forall> a l. P a l = Q a l) \\<Longrightarrow> (\\<forall> a l. Q a l \\<longrightarrow> t a l = r a l) \\<Longrightarrow> \n           (\\<lambda> x. if P x y then t x y else t') = (\\<lambda> x. if Q x y then r x y else t')\"\n  by meson\n\nlemma ext_ifte''[rule_format]: \"(\\<forall> l. P l = Q l) \\<Longrightarrow> (\\<forall> l. Q l \\<longrightarrow> t l = r l) \\<Longrightarrow> \n           (\\<lambda> x. if P x then t x else t') = (\\<lambda> x. if Q x then r x else t')\"\n  by meson\n\n\n(* *)\nthm actor_unique_loc_lem\n\nlemma actors_loc_unique: \n\"z \\<rightarrow>\\<^sub>n z' \\<Longrightarrow>  (\\<forall> a.\n             (\\<forall> l l'. l \\<in> nodes (graphI z) \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI z) l \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI z) l' \\<longrightarrow> l = l')) \\<Longrightarrow>\n l \\<in> nodes (graphI z') \\<Longrightarrow> l \\<noteq> la \\<Longrightarrow>\naa \\<in> InfrastructureOne.agra (InfrastructureOne.graphI z') l \\<Longrightarrow>\na \\<in> InfrastructureOne.agra (InfrastructureOne.graphI z') la \\<Longrightarrow> aa \\<noteq> a\"\n  apply (erule contrapos_nn)\n  apply (rule actor_unique_loc_lem0a, assumption)\n  using InfrastructureOne.same_nodes0 apply presburger\n  apply assumption\n    apply assumption\n   apply assumption\n  by (erule ssubst)\n\n\n(* attempt with agra instead of actors_graph (more specific) *)\nlemma efids_cur_eq_egra[rule_format]: \"(\\<forall> z. (\\<forall> z'. (z \\<rightarrow>\\<^sub>n z') \\<longrightarrow>\n(\\<forall> a.\n             (\\<forall> l l'. l \\<in> nodes (graphI z) \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI z) l \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI z) l' \\<longrightarrow> l = l')) \\<longrightarrow>\n(\\<forall> l \\<in> nodes(InfrastructureOne.graphI z).\n\\<forall> e \\<in> (InfrastructureOne.egra (InfrastructureOne.graphI z) l).\n (\\<exists> a \\<in> agra (InfrastructureOne.graphI z) l. \n     e = efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI z) a))) \\<longrightarrow>\n(\\<forall> l \\<in> nodes(InfrastructureOne.graphI z').\n\\<forall> e \\<in> (InfrastructureOne.egra (InfrastructureOne.graphI z') l).\n (\\<exists> a \\<in> agra (InfrastructureOne.graphI z') l. \n     e = efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI z') a)))))\"\nproof (clarify, frule same_actors0, frule same_nodes0, rule state_transition_in.cases, assumption)\n  show \"\\<And>z z' l e G I a la l' I'.\n       z \\<rightarrow>\\<^sub>n z' \\<Longrightarrow>\n       \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI z).\n          \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI z) l.\n             \\<exists>a\\<in>InfrastructureOne.agra (InfrastructureOne.graphI z) l.\n                e = efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI z) a) \\<Longrightarrow>\n       l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI z') \\<Longrightarrow>\n       e \\<in> InfrastructureOne.egra (InfrastructureOne.graphI z') l \\<Longrightarrow>\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z) =\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z') \\<Longrightarrow>\n       InfrastructureOne.nodes (InfrastructureOne.graphI z) = InfrastructureOne.nodes (InfrastructureOne.graphI z') \\<Longrightarrow>\n       z = I \\<Longrightarrow>\n       z' = I' \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       a @\\<^bsub>G\\<^esub> la \\<Longrightarrow>\n       la \\<in> InfrastructureOne.nodes G \\<Longrightarrow>\n       l' \\<in> InfrastructureOne.nodes G \\<Longrightarrow>\n       a \\<in> InfrastructureOne.actors_graph (InfrastructureOne.graphI I) \\<Longrightarrow>\n       InfrastructureOne.enables I l' (Actor a) move \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure\n        (InfrastructureOne.move_graph_a a la l' (InfrastructureOne.graphI I)) (InfrastructureOne.delta I) \\<Longrightarrow>\n       \\<exists>a\\<in>InfrastructureOne.agra (InfrastructureOne.graphI z') l.\n          e = efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI z') a)\"\n    apply (simp add: move_graph_a_def)\n    by fastforce\nnext show \"\\<And>z z' l e G I a la I'.\n       z \\<rightarrow>\\<^sub>n z' \\<Longrightarrow>\n       \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI z).\n          \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI z) l.\n             \\<exists>a\\<in>InfrastructureOne.agra (InfrastructureOne.graphI z) l.\n                e = efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI z) a) \\<Longrightarrow>\n       l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI z') \\<Longrightarrow>\n       e \\<in> InfrastructureOne.egra (InfrastructureOne.graphI z') l \\<Longrightarrow>\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z) =\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z') \\<Longrightarrow>\n       InfrastructureOne.nodes (InfrastructureOne.graphI z) = InfrastructureOne.nodes (InfrastructureOne.graphI z') \\<Longrightarrow>\n       z = I \\<Longrightarrow>\n       z' = I' \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       a @\\<^bsub>G\\<^esub> la \\<Longrightarrow>\n       la \\<in> InfrastructureOne.nodes G \\<Longrightarrow>\n       InfrastructureOne.enables I la (Actor a) get \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure\n        (InfrastructureOne.igraph.Lgraph (InfrastructureOne.gra G) (InfrastructureOne.agra G) (InfrastructureOne.cgra G)\n          (InfrastructureOne.lgra G) (InfrastructureOne.egra G)\n          ((InfrastructureOne.kgra G)\n           (a := (InfrastructureOne.kgra G a)\n              (la := {(x, y). x \\<in> InfrastructureOne.agra G la \\<and> y \\<in> InfrastructureOne.egra G la}))))\n        (InfrastructureOne.delta I) \\<Longrightarrow>\n       \\<exists>a\\<in>InfrastructureOne.agra (InfrastructureOne.graphI z') l.\n          e = efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI z') a)\"\n    by simp\nnext show \"\\<And>z z' l e G I a la I'.\n       z \\<rightarrow>\\<^sub>n z' \\<Longrightarrow>\n       \\<forall>a l l'.\n          l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI z) \\<longrightarrow>\n          a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI z) l \\<longrightarrow>\n          a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI z) l' \\<longrightarrow> l = l' \\<Longrightarrow>\n       \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI z).\n          \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI z) l.\n             \\<exists>a\\<in>InfrastructureOne.agra (InfrastructureOne.graphI z) l.\n                e = efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI z) a) \\<Longrightarrow>\n       l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI z') \\<Longrightarrow>\n       e \\<in> InfrastructureOne.egra (InfrastructureOne.graphI z') l \\<Longrightarrow>\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z) =\n       InfrastructureOne.actors_graph (InfrastructureOne.graphI z') \\<Longrightarrow>\n       InfrastructureOne.nodes (InfrastructureOne.graphI z) = InfrastructureOne.nodes (InfrastructureOne.graphI z') \\<Longrightarrow>\n       z = I \\<Longrightarrow>\n       z' = I' \\<Longrightarrow>\n       G = InfrastructureOne.graphI I \\<Longrightarrow>\n       a @\\<^bsub>G\\<^esub> la \\<Longrightarrow>\n       InfrastructureOne.enables I la (Actor a) put \\<Longrightarrow>\n       I' =\n       InfrastructureOne.infrastructure.Infrastructure (InfrastructureOne.put_graph_efid a la G)\n        (InfrastructureOne.delta I) \\<Longrightarrow>\n       \\<exists>a\\<in>InfrastructureOne.agra (InfrastructureOne.graphI z') l.\n          e = efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI z') a)\"\n    apply (unfold put_graph_efid_def)\n    apply (case_tac \"l = la\")\n    apply (smt (z3) DiffE InfrastructureOne.agra.simps InfrastructureOne.atI_def InfrastructureOne.cgra.simps InfrastructureOne.egra.simps InfrastructureOne.graphI.simps fun_upd_apply insertCI insertE)\n    apply (drule_tac x = l in bspec)\n     apply metis\n    apply (subgoal_tac \"e \\<in> InfrastructureOne.egra (InfrastructureOne.graphI z) l \")\n    prefer 2\n    apply fastforce\n    apply (drule_tac x = e in bspec, assumption)\n    apply (erule bexE)\n    apply (rule_tac x = aa in bexI)\n     apply (simp add: atI_def)\n     apply (subgoal_tac \"aa \\<noteq> a\")\n      apply simp\n    prefer 2\n    using InfrastructureOne.agra.simps InfrastructureOne.graphI.simps apply presburger\n    by meson\nqed\n\nlemma efids_cur_eq_egra_refl[rule_format]: \"(I, y) \\<in> {(x::infrastructure, y::infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n(\\<forall> a.\n             (\\<forall> l l'. l \\<in> nodes (graphI I) \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> l = l')) \\<Longrightarrow>\n(\\<forall> l \\<in> nodes(InfrastructureOne.graphI I).\n\\<forall> e \\<in> (InfrastructureOne.egra (InfrastructureOne.graphI I) l).\n (\\<exists> a \\<in> agra (InfrastructureOne.graphI I) l. \n     e = efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a))) \\<longrightarrow>\n(\\<forall> l \\<in> nodes(InfrastructureOne.graphI y).\n\\<forall> e \\<in> (InfrastructureOne.egra (InfrastructureOne.graphI y) l).\n (\\<exists> a \\<in> agra (InfrastructureOne.graphI y) l. \n     e = efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI y) a)))\"\nproof (erule rtrancl_induct, simp)\n  show \"\\<And>y z. \\<forall>a l l'.\n              l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I) \\<longrightarrow>\n              a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<longrightarrow>\n              a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> l = l' \\<Longrightarrow>\n           (I, y) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n           (y, z) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y} \\<Longrightarrow>\n           (\\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI I).\n               \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI I) l.\n                  \\<exists>a\\<in>InfrastructureOne.agra (InfrastructureOne.graphI I) l.\n                     e = efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<longrightarrow>\n           (\\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI y).\n               \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI y) l.\n                  \\<exists>a\\<in>InfrastructureOne.agra (InfrastructureOne.graphI y) l.\n                     e = efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI y) a)) \\<Longrightarrow>\n           (\\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI I).\n               \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI I) l.\n                  \\<exists>a\\<in>InfrastructureOne.agra (InfrastructureOne.graphI I) l.\n                     e = efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<longrightarrow>\n           (\\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI z).\n               \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI z) l.\n                  \\<exists>a\\<in>InfrastructureOne.agra (InfrastructureOne.graphI z) l.\n                     e = efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI z) a))\"\n    by (simp add: Pair_inject actor_unique_loc_lem case_prodE efids_cur_eq_egra)\nqed\n\n\nlemma efids_cur_efids_list_actor_unique: \n\"(\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI z). (\\<forall> a' \\<in> actors_graph(InfrastructureOne.graphI z). a \\<noteq> a' \\<longrightarrow>\n     ((range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \\<inter> \n      (range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a')))) = {}))) \\<Longrightarrow>\n a \\<in> actors_graph (InfrastructureOne.graphI z) \\<Longrightarrow> a' \\<in> actors_graph (InfrastructureOne.graphI z) \\<Longrightarrow>\nefids_cur (cgra (graphI z) a) \\<in> range(efids_list (cgra (graphI z) a')) \\<Longrightarrow> a = a'\"\n  by (smt (verit, ccfv_threshold) IntI UNIV_I efidlist.exhaust efids_cur.simps efids_list.simps empty_iff imageE image_eqI)\n\nlemma anonymous_actor_in_agra[rule_format]: \"\\<forall> z z'. z \\<rightarrow>\\<^sub>n z' \\<longrightarrow>\nInfrastructureOne.actors_graph (InfrastructureOne.graphI z) \\<noteq> {} \\<longrightarrow>\n(\\<forall> a \\<in> actors_graph (graphI z). inj (efids_list (InfrastructureOne.cgra (graphI z) a))) \\<longrightarrow>\n(\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI z). (\\<forall> a' \\<in> actors_graph(InfrastructureOne.graphI z). a \\<noteq> a' \\<longrightarrow>\n     ((range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a)) \\<inter> \n      (range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI z) a')))) = {}))) \\<longrightarrow>\n(\\<forall> l \\<in> nodes (graphI z).\n         (\\<forall> e \\<in> (egra (InfrastructureOne.graphI z) l).\n         (\\<exists> a \\<in> actors_graph (InfrastructureOne.graphI z) . e \\<in> range (efids_list (InfrastructureOne.cgra (graphI z) a))))) \\<longrightarrow>\n(\\<forall> a.\n             (\\<forall> l l'. l \\<in> nodes (graphI z) \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI z) l \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI z) l' \\<longrightarrow> l = l')) \\<longrightarrow>\n(\\<forall> l \\<in> nodes(InfrastructureOne.graphI z).\n\\<forall> e \\<in> (InfrastructureOne.egra (InfrastructureOne.graphI z) l).\n (\\<exists> a \\<in> agra (InfrastructureOne.graphI z) l. \n     e = efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI z) a))) \\<longrightarrow>\n(\\<forall> l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI z).\n  \\<forall> y \\<in> InfrastructureOne.egra (InfrastructureOne.graphI z) l.\n  anonymous_actor z y \\<in> InfrastructureOne.agra (InfrastructureOne.graphI z) l)  \\<longrightarrow>\n(\\<forall> l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI z').\n  \\<forall> y \\<in> InfrastructureOne.egra (InfrastructureOne.graphI z') l.\n  anonymous_actor z' y \\<in> InfrastructureOne.agra (InfrastructureOne.graphI z') l)\"\n  apply (rule allI)+\n  apply (rule impI)+\n  apply (rule ballI)+\n  apply (subgoal_tac \"(\\<forall> l \\<in> nodes(InfrastructureOne.graphI z').\n\\<forall> e \\<in> (InfrastructureOne.egra (InfrastructureOne.graphI z') l).\n (\\<exists> a \\<in> agra (InfrastructureOne.graphI z') l. \n     e = efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI z') a)))\")\n   prefer 2\n   apply (simp add: efids_cur_eq_egra)\n  apply (subgoal_tac \"\\<exists> a' \\<in> agra(graphI z') l. y = efids_cur(cgra (graphI z') a')\")\n  prefer 2\n   apply fastforce\n  apply (erule bexE)\n  apply (subgoal_tac \"(\\<forall> l \\<in> nodes (graphI z').\n         (\\<forall> e \\<in> (egra (InfrastructureOne.graphI z') l).\n         (\\<exists> a \\<in> actors_graph (InfrastructureOne.graphI z') .\n          e \\<in> range (efids_list (InfrastructureOne.cgra (graphI z') a)))))\")\n  prefer 2\n  using efid_in_range_invariantO apply presburger\n  apply (subgoal_tac \"(\\<exists> a \\<in> actors_graph (InfrastructureOne.graphI z') .\n          efids_cur(cgra (graphI z') a') \\<in> range (efids_list (InfrastructureOne.cgra (graphI z') a)))\")\n  prefer 2\n   apply fastforce\n  apply (erule bexE)\n  apply (subgoal_tac \"a = a'\")\n  prefer 2\n  apply (smt (verit, ccfv_SIG) InfrastructureOne.actors_graph_def InfrastructureOne.same_actors0 efids_cur_efids_list_actor_unique efids_list_eq mem_Collect_eq)\n  apply (subgoal_tac \"a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI z') l \")\n   prefer 2\n  apply simp\napply (subgoal_tac \"\\<forall> a'. a' \\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI z')\n    \\<and> y \\<in> range (efids_list (InfrastructureOne.cgra (graphI z') a'))\n   \\<longrightarrow> a' = anonymous_actor z' y\")\n  prefer 2\n   apply (simp add: InfrastructureOne.same_actors0 anonymous_actor_def1b efids_list_eq)\n  apply (subgoal_tac \"a = anonymous_actor z' y \")\n  prefer 2\n   apply presburger\n  apply (rotate_tac -1)\n  apply (erule subst)\n  by assumption\n\n\nlemma anonymous_actor_invOO[rule_format]: \"(I, y) \\<in> {(x::infrastructure, y::infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\nInfrastructureOne.actors_graph (InfrastructureOne.graphI I) \\<noteq> {} \\<Longrightarrow>\n(\\<forall> a \\<in> actors_graph (graphI I). inj (efids_list (InfrastructureOne.cgra (graphI I) a))) \\<Longrightarrow>\n(\\<forall> a \\<in> actors_graph (InfrastructureOne.graphI I). (\\<forall> a' \\<in> actors_graph(InfrastructureOne.graphI I). a \\<noteq> a' \\<longrightarrow>\n     ((range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<inter> \n      (range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a')))) = {}))) \\<Longrightarrow>\n(\\<forall> l \\<in> nodes (graphI I).\n         (\\<forall> e \\<in> (egra (InfrastructureOne.graphI I) l).\n         (\\<exists> a \\<in> actors_graph (graphI I). e \\<in> range (efids_list (InfrastructureOne.cgra (graphI I) a))))) \\<Longrightarrow>\n(\\<forall> a.\n             (\\<forall> l l'. l \\<in> nodes (graphI I) \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<longrightarrow>  \n                a \\<in>  InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> l = l')) \\<Longrightarrow>\n(\\<forall> l \\<in> nodes(InfrastructureOne.graphI I).\n\\<forall> e \\<in> (InfrastructureOne.egra (InfrastructureOne.graphI I) l).\n (\\<exists> a \\<in> agra(InfrastructureOne.graphI I) l. \n     e = efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a))) \\<Longrightarrow>\n(\\<forall> l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I).\n  \\<forall> e \\<in> InfrastructureOne.egra (InfrastructureOne.graphI I) l.\n  anonymous_actor I e \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l)  \\<longrightarrow>\n(\\<forall> l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI y).\n  \\<forall> e \\<in> InfrastructureOne.egra (InfrastructureOne.graphI y) l.\n  anonymous_actor y e \\<in> InfrastructureOne.agra (InfrastructureOne.graphI y) l)\"\nproof (erule rtrancl_induct, simp)\n  show \"\\<And>y z. InfrastructureOne.actors_graph (InfrastructureOne.graphI I) \\<noteq> {} \\<Longrightarrow>\n           \\<forall>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n              inj (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<Longrightarrow>\n           \\<forall>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n              \\<forall>a'\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n                 a \\<noteq> a' \\<longrightarrow>\n                 range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<inter>\n                 range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a')) =\n                 {} \\<Longrightarrow>\n           \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI I).\n              \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI I) l.\n                 \\<exists>a\\<in>InfrastructureOne.actors_graph (InfrastructureOne.graphI I).\n                    e \\<in> range (efids_list (InfrastructureOne.cgra (InfrastructureOne.graphI I) a)) \\<Longrightarrow>\n           \\<forall>a l l'.\n              l \\<in> InfrastructureOne.nodes (InfrastructureOne.graphI I) \\<longrightarrow>\n              a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l \\<longrightarrow>\n              a \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l' \\<longrightarrow> l = l' \\<Longrightarrow>\n           \\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI I).\n              \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI I) l.\n                 \\<exists>a\\<in> agra (InfrastructureOne.graphI I) l.\n                    e = efids_cur (InfrastructureOne.cgra (InfrastructureOne.graphI I) a) \\<Longrightarrow>\n           (I, y) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n           (y, z) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y} \\<Longrightarrow>\n           (\\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI I).\n               \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI I) l.\n                  anonymous_actor I e \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l) \\<longrightarrow>\n           (\\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI y).\n               \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI y) l.\n                  anonymous_actor y e \\<in> InfrastructureOne.agra (InfrastructureOne.graphI y) l) \\<Longrightarrow>\n           (\\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI I).\n               \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI I) l.\n                  anonymous_actor I e \\<in> InfrastructureOne.agra (InfrastructureOne.graphI I) l) \\<longrightarrow>\n           (\\<forall>l\\<in>InfrastructureOne.nodes (InfrastructureOne.graphI z).\n               \\<forall>e\\<in>InfrastructureOne.egra (InfrastructureOne.graphI z) l.\n                  anonymous_actor z e \\<in> InfrastructureOne.agra (InfrastructureOne.graphI z) l)\"\n    apply (rule impI)\n    apply (rule ballI)+\n    thm anonymous_actor_in_agra\n    apply (rule_tac z' = z in anonymous_actor_in_agra)\n    apply simp\n    using InfrastructureOne.same_actors apply force\n    apply (metis InfrastructureOne.same_actors efids_list_inj_refl)\n    apply (metis ran_efids_list_disjoint_refl)\n    apply (metis efids_in_range_invariantOO)\n    using actor_unique_loc_lem apply presburger\n    apply (simp add: efids_cur_eq_egra_refl)\n    apply fastforce\nby assumption+\nqed\n\nend\n\n ", "meta": {"author": "flokam", "repo": "CoronaApp", "sha": "6258178b8f9d10f43e0825d99cbb0126ee51612c", "save_path": "github-repos/isabelle/flokam-CoronaApp", "path": "github-repos/isabelle/flokam-CoronaApp/CoronaApp-6258178b8f9d10f43e0825d99cbb0126ee51612c/IsabelleCorona/InfrastructureOne.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6619228758499942, "lm_q2_score": 0.44552953503957266, "lm_q1q2_score": 0.29490619110950467}}
{"text": "theory utp_rea_core\n  imports \"UTP-Designs.utp_des_core\" \"UTP2.utp\" \"UTP2.utp_pred\" \"Shallow-Expressions.Shallow_Expressions\" \"Z_Toolkit.Trace_Algebra\"\nbegin\n\nalphabet 't::trace rea_vars = des_vars +\n  wait :: bool\n  tr   :: 't\n\ntype_synonym ('t, '\\<alpha>) rp = \"('t, '\\<alpha>) rea_vars_scheme\"\n\ntype_synonym ('t,'\\<alpha>,'\\<beta>) rel_rp  = \"(('t,'\\<alpha>) rea_vars_scheme, ('t,'\\<beta>) rea_vars_scheme) urel\"\n\ntype_synonym ('t, '\\<alpha>) hrel_rp = \"(('t,'\\<alpha>) rea_vars_scheme, ('t,'\\<alpha>) rea_vars_scheme) urel\"\n\ntranslations\n  (type) \"('t,'\\<alpha>) rp\" <= (type) \"('t, '\\<alpha>) rea_vars_scheme\"\n  (type) \"('t,'\\<alpha>) rp\" <= (type) \"('t, '\\<alpha>) rea_vars_ext\"\n  (type) \"('t,'\\<alpha>,'\\<beta>) rel_rp\" <= (type) \"(('t,'\\<alpha>) rea_vars_scheme, ('\\<gamma>,'\\<beta>) rea_vars_scheme) urel\"\n  (type) \"('t,'\\<alpha>) hrel_rp\"  <= (type) \"(('t,'\\<alpha>) rea_vars_scheme, ('\\<gamma>,'\\<beta>) rea_vars_scheme) urel\"\n\n(* Now denoted as v\\<^sub>R rather than \\<Sigma>\\<^sub>R *)\n\nnotation rea_vars.more\\<^sub>L (\"\\<^bold>v\\<^sub>R\")\n\nterm \"\\<^bold>v\\<^sub>R\"\n\n\nsyntax\n  \"_svid_rea_alpha\"  :: \"svid\" (\"\\<^bold>v\\<^sub>R\")\n\ntranslations\n  \"_svid_rea_alpha\" => \"CONST rea_vars.more\\<^sub>L\"\n\n(*declare zero_list_def [upred_defs]\ndeclare plus_list_def [upred_defs]*)\ndeclare prefixE [elim]\n\nabbreviation wait_f::\"('t::trace, '\\<alpha>, '\\<beta>) rel_rp \\<Rightarrow> ('t, '\\<alpha>, '\\<beta>) rel_rp\" (\"_\\<^sub>f\" [1000] 1000)\nwhere \"wait_f R \\<equiv> R\\<lbrakk>False/wait\\<^sup><\\<rbrakk>\"\n\nabbreviation wait_t::\"('t::trace, '\\<alpha>, '\\<beta>) rel_rp \\<Rightarrow> ('t, '\\<alpha>, '\\<beta>) rel_rp\" (\"_\\<^sub>t\" [1000] 1000)\n  where \"wait_t R \\<equiv> R\\<lbrakk>True/wait\\<^sup><\\<rbrakk>\"\n\n(*\nsyntax\n  \"_wait_f\"  :: \"logic \\<Rightarrow> logic\" (\"_\\<^sub>f\" [1000] 1000)\n  \"_wait_t\"  :: \"logic \\<Rightarrow> logic\" (\"_\\<^sub>t\" [1000] 1000)\n\ntranslations\n  \"P \\<^sub>f\" \\<rightleftharpoons> \"CONST usubst (CONST subst_upd id\\<^sub>s (CONST in_var CONST wait) false) P\"\n  \"P \\<^sub>t\" \\<rightleftharpoons> \"CONST usubst (CONST subst_upd id\\<^sub>s (CONST in_var CONST wait) true) P\"\n*)\n\nabbreviation lift_rea :: \"('\\<alpha>, '\\<beta>) urel \\<Rightarrow> ('t::trace, '\\<alpha>, '\\<beta>) rel_rp\" (\"\\<lceil>_\\<rceil>\\<^sub>R\") where\n\"\\<lceil>P\\<rceil>\\<^sub>R \\<equiv> P \\<up> (\\<^bold>v\\<^sub>R\\<^sup>2)\"\n\ndefinition drop_rea :: \"('t::trace, '\\<alpha>, '\\<beta>) rel_rp \\<Rightarrow> ('\\<alpha>, '\\<beta>) urel\" (\"\\<lfloor>_\\<rfloor>\\<^sub>R\") where\n\"\\<lfloor>P\\<rfloor>\\<^sub>R \\<equiv> P \\<down> (\\<^bold>v\\<^sub>R\\<^sup>2)\"\n\n(*\nabbreviation rea_pre_lift :: \"('d \\<Rightarrow> 'e) \\<Rightarrow> ('a, 'b, 'c) rel_rp\"  (\"\\<lceil>_\\<rceil>\\<^sub>R\\<^sub><\") where \"\\<lceil>n\\<rceil>\\<^sub>R\\<^sub>< \\<equiv> \\<lceil>n\\<^sup><\\<rceil>\\<^sub>R\"\n\nlemma unrest_ok_lift_rea [unrest]:\n  \"$ok\\<^sup>< \\<sharp> \\<lceil>P\\<rceil>\\<^sub>R\" \"$ok\\<^sup>> \\<sharp> \\<lceil>P\\<rceil>\\<^sub>R\"\n  unfolding lift_rea_def\n  apply (simp add: unrest_aext_expr_lens)\n  apply (simp add: unrest_aext_expr_lens) \n  done\n*)\n\nsubsection \\<open> Reactive Lemmas \\<close>\n\nlemma des_lens_equiv_wait_tr_rest: \"\\<^bold>v\\<^sub>D \\<approx>\\<^sub>L (wait +\\<^sub>L tr +\\<^sub>L \\<^bold>v\\<^sub>R)\"\n  by simp\n\ntext \\<open> Pairing the reactive alphabet with its control variables forms a bijective lens. \\<close>\nlemma rea_lens_bij: \"bij_lens (ok +\\<^sub>L wait +\\<^sub>L tr +\\<^sub>L \\<^bold>v\\<^sub>R)\"\nproof -\n  have \"ok +\\<^sub>L wait +\\<^sub>L tr +\\<^sub>L \\<^bold>v\\<^sub>R \\<approx>\\<^sub>L ok +\\<^sub>L \\<^bold>v\\<^sub>D\"\n    using des_lens_equiv_wait_tr_rest des_vars.indeps lens_equiv_sym lens_plus_eq_right by blast\n  also have \"... \\<approx>\\<^sub>L 1\\<^sub>L\"\n    using bij_lens_equiv_id[of \"ok +\\<^sub>L \\<^bold>v\\<^sub>D\"]\n    using des_vars.bij_lenses by blast\n  finally show ?thesis\n    by (simp add: bij_lens_equiv_id)\nqed\n\nlemma seqr_wait_true [usubst]: \"(P ;; Q) \\<^sub>t = (P \\<^sub>t ;; Q)\"\n  by pred_simp\n\nlemma seqr_wait_false [usubst]: \"(P ;; Q) \\<^sub>f = (P \\<^sub>f ;; Q)\"\n  by pred_simp\n\ndefinition tcontr :: \"'t::trace \\<Longrightarrow> ('t, '\\<alpha>) rp \\<times> ('t, '\\<alpha>) rp\" (\"tt\") where\n  [lens_defs]:\n  \"tcontr = \\<lparr> lens_get = (\\<lambda> s. get\\<^bsub>ns_alpha snd\\<^sub>L tr\\<^esub> s - get\\<^bsub>ns_alpha fst\\<^sub>L tr\\<^esub> s) , \n              lens_put = (\\<lambda> s v. put\\<^bsub>ns_alpha snd\\<^sub>L tr\\<^esub> s (get\\<^bsub>ns_alpha fst\\<^sub>L tr\\<^esub> s + v)) \\<rparr>\"\n\ndefinition itrace :: \"'t::trace \\<Longrightarrow> ('t, '\\<alpha>) rp \\<times> ('t, '\\<alpha>) rp\" (\"\\<^bold>i\\<^bold>t\") where\n  [lens_defs]:\n  \"itrace = \\<lparr> lens_get = get\\<^bsub>ns_alpha fst\\<^sub>L tr\\<^esub>, \n              lens_put = (\\<lambda> s v. put\\<^bsub>ns_alpha snd\\<^sub>L tr\\<^esub> (put\\<^bsub>ns_alpha fst\\<^sub>L tr\\<^esub> s v) v) \\<rparr>\"\n\nsyntax\n  \"_svid_tcontr\"  :: \"svid\" (\"tt\")\n  \"_svid_itrace\"  :: \"svid\" (\"\\<^bold>i\\<^bold>t\")\n  \"_utr_iter\"     :: \"logic \\<Rightarrow> logic \\<Rightarrow> logic\" (\"iter[_]'(_')\")\n\n\ntranslations\n  \"_svid_tcontr\" == \"CONST tcontr\"\n  \"_svid_itrace\" == \"CONST itrace\"\n  \"iter[n](P)\"   == \"CONST uop (CONST tr_iter n) P\"\n\n\nlemma tcontr_alt_def: \"(tt)\\<^sub>e = (tr\\<^sup>> - tr\\<^sup><)\"\n  by pred_auto\n\nlemma tcontr_alt_def': \"var tt = (tr\\<^sup>> - tr\\<^sup><)\"\n  by pred_auto\n\nlemma tt_indeps [simp]:\n  assumes \"x \\<bowtie> (ns_alpha fst\\<^sub>L tr)\" \"x \\<bowtie> (ns_alpha snd\\<^sub>L tr)\"\n  shows \"x \\<bowtie> tt\" \"tt \\<bowtie> x\"\n  using assms\n  by (unfold lens_indep_def, safe, simp_all add: tcontr_def)\n  \nlemma itrace_indeps [simp]:\n  assumes \"x \\<bowtie> (ns_alpha fst\\<^sub>L tr)\" \"x \\<bowtie> (ns_alpha snd\\<^sub>L tr)\"\n  shows \"x \\<bowtie> \\<^bold>i\\<^bold>t\" \"\\<^bold>i\\<^bold>t \\<bowtie> x\"\n  using assms by (unfold lens_indep_def, safe, simp_all add: lens_defs)\n\n(* Thomas: these lemmata are not applicable unless we want to lift trace operations\n * to expressions as in UTP1 *)\n(*\ntext \\<open> We lift a few trace properties from the trace class using \\emph{transfer}. \\<close>\n\nlemma uexpr_diff_zero [simp]:\n  fixes a :: \"('\\<alpha>::trace, 'a) expr\"\n  shows \"a - 0 = a\"\n  by (simp add: minus_uexpr_def zero_uexpr_def, transfer, auto)\n\nlemma uexpr_add_diff_cancel_left [simp]:\n  fixes a b :: \"('\\<alpha>::trace, 'a) expr\"\n  shows \"(a + b) - a = b\"\n  by (simp add: minus_uexpr_def plus_uexpr_def, transfer, auto)\n\nlemma iter_0 [simp]: \"iter[0](t) = U([])\"\n  by (transfer, simp)\n*)\n\nend\n", "meta": {"author": "isabelle-utp", "repo": "UTP-Reactive", "sha": "d09fc006152794f02cfb5871060658b93757836b", "save_path": "github-repos/isabelle/isabelle-utp-UTP-Reactive", "path": "github-repos/isabelle/isabelle-utp-UTP-Reactive/UTP-Reactive-d09fc006152794f02cfb5871060658b93757836b/utp_rea_core.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6187804337438502, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.2948981631986742}}
{"text": "theory ComputationCon imports \"SmallStepCon\" \"HOL-Eisbach.Eisbach_Tools\"\nbegin\ntype_synonym ('g,'l) c_state = \"('g\\<times>'l)\\<times>('l list)\"\ntype_synonym ('g, 'l, 'p,'f,'e) config_gs = \"('g\\<times>'l,'p,'f,'e)com  \\<times> ('g,'l) c_state\"\n\n(* inductive \n      \"step_e\"::\"[('g\\<times>'l,'p,'f,'e) body,('g, 'l,  'p,'f,'e) config_gs,('g, 'l,  'p,'f,'e) config_gs] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>c (_ \\<rightarrow>\\<^sub>e/ _)\" [81,81,81] 100)  \n  for \\<Gamma>::\"('g\\<times>'l,'p,'f,'e) body\"\nwhere\nEnv:\"(\\<forall>ns'. t'\\<noteq>Normal ns' \\<or> (snd (fst ns) =snd (fst ns') \\<and> \n            length (snd ns) = length (snd ns'))) \\<Longrightarrow> \n      \\<Gamma>\\<turnstile>\\<^sub>c (Ps, Normal ns) \\<rightarrow>\\<^sub>e (Ps, t')\"\n|Env_n: \"(\\<forall>ns. t\\<noteq>Normal ns) \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c (Ps, t) \\<rightarrow>\\<^sub>e (Ps, t)\"\n\n inductive \n      \"step_e1\"::\"[('g\\<times>'l,'p,'f,'e) body,('g, 'l,  'p,'f,'e) config_gs,('g, 'l,  'p,'f,'e) config_gs] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>c (_ \\<rightarrow>\\<^sub>e\\<^sub>1/ _)\" [81,81,81] 100)  \n  for \\<Gamma>::\"('g\\<times>'l,'p,'f,'e) body\"\nwhere\nEnv1:\"(\\<forall>ns'. t'\\<noteq>Normal ns') \\<or> (\\<exists>ns'. t'=Normal ns' \\<and> (snd (fst ns) =snd (fst ns') \\<and> \n            length (snd ns) = length (snd ns'))) \\<Longrightarrow> \n      \\<Gamma>\\<turnstile>\\<^sub>c (Ps, Normal ns) \\<rightarrow>\\<^sub>e\\<^sub>1 (Ps, t')\"\n|Env_n1: \"(\\<forall>ns. t\\<noteq>Normal ns) \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c (Ps, t) \\<rightarrow>\\<^sub>e\\<^sub>1 (Ps, t)\"\n\ninductive \n      \"step_e2\"::\"[('g\\<times>'l,'p,'f,'e) body,('g, 'l,  'p,'f,'e) config_gs,('g, 'l,  'p,'f,'e) config_gs] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>c (_ \\<rightarrow>\\<^sub>e\\<^sub>2/ _)\" [81,81,81] 100)  \n  for \\<Gamma>::\"('g\\<times>'l,'p,'f,'e) body\"\nwhere\nEnv:\"(\\<forall>ns'. t'\\<noteq>Normal ns' \\<or> t'\\<noteq>Abrupt ns') \\<or> \n            (\\<exists>ns'. t'=Normal ns' \\<and> snd (fst ns) =snd (fst ns') \\<and> \n                               length (snd ns) = length (snd ns')) \\<or> \n           (\\<exists>ns'. t'=Abrupt ns' \\<and> length (snd ns) = length (snd ns')) \\<Longrightarrow> \n      \\<Gamma>\\<turnstile>\\<^sub>c (Ps, Normal ns) \\<rightarrow>\\<^sub>e\\<^sub>2 (Ps, t')\"\n|Env_n: \"(\\<forall>ns. t\\<noteq>Normal ns) \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c (Ps, t) \\<rightarrow>\\<^sub>e\\<^sub>2 (Ps, t)\"\n\ninductive \n      \"step_e3\"::\"[('g\\<times>'l,'p,'f,'e) body,('g, 'l,  'p,'f,'e) config_gs,('g, 'l,  'p,'f,'e) config_gs] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>c (_ \\<rightarrow>\\<^sub>e\\<^sub>3/ _)\" [81,81,81] 100)  \n  for \\<Gamma>::\"('g\\<times>'l,'p,'f,'e) body\"\nwhere\nEnv:\"(\\<forall>ns'. (t'\\<noteq>Normal ns' \\<and> t'\\<noteq>Abrupt ns') \\<or> (t'=Normal ns' \\<and> snd (fst ns) =snd (fst ns') \\<and> \n            length (snd ns) = length (snd ns')) \\<or> \n           (t'=Abrupt ns' \\<and> length (snd ns) = length (snd ns'))) \\<Longrightarrow> \n      \\<Gamma>\\<turnstile>\\<^sub>c (Ps, Normal ns) \\<rightarrow>\\<^sub>e\\<^sub>3 (Ps, t')\"\n|Env_n: \"(\\<forall>ns. t\\<noteq>Normal ns) \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c (Ps, t) \\<rightarrow>\\<^sub>e\\<^sub>3 (Ps, t)\" *)\n\ninductive \n      \"step_e\"::\"[('g\\<times>'l,'p,'f,'e) body,('g, 'l,  'p,'f,'e) config_gs,('g, 'l,  'p,'f,'e) config_gs] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>c (_ \\<rightarrow>\\<^sub>e/ _)\" [81,81,81] 100)  \n  for \\<Gamma>::\"('g\\<times>'l,'p,'f,'e) body\"\nwhere\nEnv:\"snd (fst s) =snd (fst t) \\<and> length (snd s) = length (snd t) \\<Longrightarrow> \n      \\<Gamma>\\<turnstile>\\<^sub>c (Ps, s) \\<rightarrow>\\<^sub>e (Ps, t)\"\n\n\nlemma etranE: \"\\<Gamma>\\<turnstile>\\<^sub>c c \\<rightarrow>\\<^sub>e c' \\<Longrightarrow> (\\<And>P s t. c = (P, s) \\<Longrightarrow> c' = (P, t) \\<Longrightarrow> Q) \\<Longrightarrow> Q\"\n  by (induct c, induct c', erule  step_e.cases, blast)\n\ninductive_cases stepe_elim_cases1 [cases set]:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Ps,s) \\<rightarrow>\\<^sub>e (Ps',t)\"\n\ninductive_cases stepe_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Ps,s) \\<rightarrow>\\<^sub>e (Ps,t)\"\n\n\nlemma env_c_c'_false:\n   assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c', s')\" \n   shows \"~(c=c')  \\<Longrightarrow> P\"\nusing step_m etranE by blast\n\n(* lemma eenv_normal_s'_normal_s:\n   assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c', Normal s')\" \n   shows \"(\\<And>s1. s\\<noteq>Normal s1)  \\<Longrightarrow> P\"\n  using step_m\n  using env_c_c'_false stepe_not_norm_elim_cases(4) by blast *)\n\nlemma eenv_eq_length:\n  assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c,  s) \\<rightarrow>\\<^sub>e (c',  s')\" and\n          normal_s:\"s= ((g,l),ls)\" and normal_s':\"s'= ((g',l'),ls')\"\n   shows \"(length ls \\<noteq> length ls')  \\<Longrightarrow> P\"\n  using step_m normal_s normal_s'\n  using env_c_c'_false  stepe_elim_cases1 by fastforce\n\n(* lemma env_normal_s'_normal_s:\n   assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c', Normal s') \" \n   shows \"\\<exists>s1. s= Normal s1\"\n  using step_m \n  using env_c_c'_false stepe_not_norm_elim_cases(4) by blast\n  *)\n\nlemma env_c_c':\n   assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c', s')\" \n   shows \"(c=c')\"\nusing env_c_c'_false step_m by fastforce \n\n\nlemma env_normal_same_local_length:\n   assumes a1:\"\\<Gamma>\\<turnstile>\\<^sub>c (c,  ((g,l),ls)) \\<rightarrow>\\<^sub>e (c',  ((g',l'),ls'))\" \n   shows \"l=l' \\<and> length ls = length ls'\"\n  using a1 \n  by (cases rule:step_e.cases,auto)\n\n\nlemma env_normal_same_local:\n   assumes a1:\"\\<Gamma>\\<turnstile>\\<^sub>c (c,  ((g,l),ls)) \\<rightarrow>\\<^sub>e (c',  ((g',l'),ls'))\" \n   shows \"l=l'\"\n  using a1 env_normal_same_local_length\n  by fast\n\nlemma env_normal_same_length:\n   assumes a1:\"\\<Gamma>\\<turnstile>\\<^sub>c (c,  ((g,l),ls)) \\<rightarrow>\\<^sub>e (c',  ((g',l'),ls'))\" \n   shows \"length ls = length ls'\"\n   using a1 env_normal_same_local_length\n  by fast\n\nlemma env_intro:\n  assumes a1:\"length ls = length ls'\"\n  shows \"\\<Gamma>\\<turnstile>\\<^sub>c (c,  ((g,l),ls)) \\<rightarrow>\\<^sub>e (c,  ((g',l),ls'))\"      \n  using a1 by (auto intro: step_e.intros)\n\nlemma env_intro_diff_p:\"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow>\\<^sub>e (P, t) \\<Longrightarrow>\n      \\<Gamma>\\<turnstile>\\<^sub>c (Q, s) \\<rightarrow>\\<^sub>e (Q, t)\"\n  by (auto elim: stepe_elim_cases simp add: Env )\n  \n\nlemma snormal_enviroment:\n   \" snd (fst s) =snd (fst t) \\<and>  length (snd s) = length (snd t)  \\<Longrightarrow>\n        \\<Gamma>\\<turnstile>\\<^sub>c (x, s) \\<rightarrow>\\<^sub>e (x, t)\"\n  by (simp add: step_e.intros)\n\n \n(* definition final_glob:: \"('g,'l,'p,'f,'e) config_gs \\<Rightarrow> bool\" where\n  \"final_glob cfg \\<equiv>   (fst cfg=Skip \\<or> ((fst cfg=Throw) \\<and> (\\<exists>s. snd cfg=Normal s)))\"\n                                           \nlemma final_eq:\"snd cfg = Normal s \\<Longrightarrow> final_glob cfg = SmallStepCon.final (fst cfg, Normal (fst s))\"\n  unfolding final_def final_glob_def SmallStepCon.final_def\n  by auto\n*)\n\nsection \\<open> computation with enviroment \\<close>\n\nfun toSeq ::\"(('g\\<times>'l)\\<times>('l list)) \\<Rightarrow> (('g\\<times>'l)) \"\n  where\n\"toSeq ns = (fst ns)\"\n\nlemma \n  assumes \n    a0:\"snd s = snd s'\" and \n    a1:\"toSeq s = toSeq s'\"\n  shows eq_toSeq:\"s = s'\" using a0 a1\n  by (cases s, simp)\n\ninductive\n      \"step_ce\"::\"[('g\\<times>'l,'p,'f,'e) body,('g, 'l, 'p,'f,'e) config_gs,('g, 'l, 'p,'f,'e) config_gs] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>c (_ \\<rightarrow>\\<^sub>c\\<^sub>e/ _)\" [81,81,81] 100)  \n  for \\<Gamma>::\"('g\\<times>'l,'p,'f,'e) body\"\n  where\nc_step: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c (c, (toSeq s)) \\<rightarrow> (c', toSeq s'); snd s = snd s'\\<rbrakk> \\<Longrightarrow> \n         \\<Gamma>\\<turnstile>\\<^sub>c (c,s) \\<rightarrow>\\<^sub>c\\<^sub>e (c',s')\"\n|e_step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c,s) \\<rightarrow>\\<^sub>e (c',s') \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c (c,s) \\<rightarrow>\\<^sub>c\\<^sub>e (c',s') \" \n\nlemmas step_ce_induct = step_ce.induct [of _ \"(c,s)\" \"(c',s')\", split_format (complete), case_names\nc_step e_step, induct set]\n\n           \ninductive_cases step_ce_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sub>c\\<^sub>e cf1\"\n\ninductive_cases step_ce_elim_cases_eq_locals [cases set]:\n \"\\<Gamma>\\<turnstile>\\<^sub>c (c,((g,l),ls)) \\<rightarrow>\\<^sub>c\\<^sub>e (c', ((g',l),ls'))\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c (c,((g,l),ls)) \\<rightarrow>\\<^sub>c\\<^sub>e (c', ((g',l'),ls))\"\n\n\nlemma step_dest:\n  assumes a0:\"\\<Gamma>\\<turnstile>\\<^sub>c(P, s) \\<rightarrow>\\<^sub>c\\<^sub>e (Q,t)\"\n  shows \"\\<Gamma>\\<turnstile>\\<^sub>c(P, s) \\<rightarrow>\\<^sub>e (Q,t) \\<or> \n        (\\<Gamma>\\<turnstile>\\<^sub>c (P, toSeq s) \\<rightarrow> (Q, toSeq t) \\<and> (snd s) =  (snd t))\"   \n  using a0 apply clarsimp\n  apply (erule step_ce_elim_cases)   \n  by auto  \n\nlemma step_dest1:\n  assumes a0:\"\\<Gamma>\\<turnstile>\\<^sub>c(P, s) \\<rightarrow>\\<^sub>c\\<^sub>e (Q,t)\" and\n  a1:\"\\<Gamma>\\<turnstile>\\<^sub>c (P, toSeq s) \\<rightarrow> (Q, toSeq t)\"\nshows\"((snd s) =  (snd t))\"   \n  using a0 a1 apply clarsimp\n  apply (erule step_ce_elim_cases)   \n  apply auto\n  by (metis (no_types) mod_env_not_component stepe_elim_cases1)  \n  \n\nlemma transfer_normal:\"\n      \\<Gamma>\\<turnstile>\\<^sub>c (c,  s) \\<rightarrow> (c',  s') \\<Longrightarrow>\n      \\<Gamma>\\<turnstile>\\<^sub>c (c,  (s, ls)) \\<rightarrow>\\<^sub>c\\<^sub>e (c',  (s', ls))\"  \n  by (auto intro: c_step)\n  \nlemma step_c_normal_normal: assumes a1: \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow> cf1\"\n      shows \"\\<And> c\\<^sub>1 s s'. \\<lbrakk>cf0 = (c\\<^sub>1,Normal s);cf1=(c\\<^sub>1,s');(\\<forall>sa. \\<not>(s'=Normal sa))\\<rbrakk>\n          \\<Longrightarrow> P\"\nusing a1 \nby (induct rule: stepc.induct, induct, auto)\n\n\nlemma call_f_step_ce_not_s_eq_t_env_step:\n  assumes \n     a0:\"\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow>\\<^sub>c\\<^sub>e (Q,t)\" and\n     a1:\"(redex P = Call fn \\<and> \\<Gamma> fn = Some bdy \\<and>  (s\\<noteq>t)) \\<or>\n         (redex P = Call fn \\<and> \\<Gamma> fn = Some bdy \\<and>  s=t \\<and> P=Q \\<and> \\<Gamma> fn \\<noteq> Some (Call fn)) \"\n   shows \"\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow>\\<^sub>e (Q,t)\"\nby (metis (no_types, hide_lams) a0 a1 call_f_step_not_s_eq_t_false eq_toSeq step_dest)\n\nabbreviation \n \"stepce_rtrancl\" :: \"[('g\\<times>'l,'p,'f,'e) body,('g, 'l, 'p,'f,'e) config_gs,('g, 'l, 'p,'f,'e) config_gs] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>c (_ \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>*/ _)\" [81,81,81] 100)\n where                                \n  \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* cf1 \\<equiv> ((CONST step_ce \\<Gamma>))\\<^sup>*\\<^sup>* cf0 cf1\" \n  (* \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sup>* cf1 \\<equiv> (CONST ((stepc \\<Gamma>) \\<union> (step_e \\<Gamma>)))\\<^sup>*\\<^sup>* cf0 cf1\" *)\n\nabbreviation \n \"stepce_trancl\" :: \"[('g\\<times>'l,'p,'f,'e) body,('g, 'l, 'p,'f,'e) config_gs,('g, 'l, 'p,'f,'e) config_gs] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>c (_ \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>+/ _)\" [81,81,81] 100)\n where\n  \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>+ cf1 \\<equiv> (CONST step_ce \\<Gamma>)\\<^sup>+\\<^sup>+ cf0 cf1\"\n\ntext \\<open> lemmas about single step computation \\<close> \n\n(* lemma ce_not_normal_s:\n   assumes a1:\"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sub>c\\<^sub>e cf1\"\n   shows \"\\<And> c\\<^sub>1 c\\<^sub>2 s s'. \\<lbrakk>cf0 = (c\\<^sub>1,s);cf1=(c\\<^sub>2,s');(\\<forall>sa. (s\\<noteq>Normal sa))\\<rbrakk>\n                     \\<Longrightarrow> s=s'\"\nusing a1\n  apply (clarify, cases rule:step_ce.cases)  \n  apply (metis eq_toSeq prod.sel(1) prod.sel(2) step_not_normal_s_eq_t toSeq.simps xstate.simps(5))\n  using env_not_normal_s by blast *)\n\nlemma not_eq_not_env:\n   assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>c\\<^sub>e (c', s')\" \n   shows \"~(c=c') \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c', s') \\<Longrightarrow> P\"\nusing step_m etranE by blast\n\n\nlemma step_ce_not_step_e_step_c:\n   assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>c\\<^sub>e (c', s')\" \n   shows \"\\<not> (\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c', s')) \\<Longrightarrow>(\\<Gamma>\\<turnstile>\\<^sub>c (c, toSeq s) \\<rightarrow> (c', toSeq s'))\"\n  using step_m  \n  by (meson step_dest) \n\nlemma step_ce_step_c_eq_c:\nassumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>c\\<^sub>e (c', s')\" \n   shows \"(\\<Gamma>\\<turnstile>\\<^sub>c (c, toSeq s) \\<rightarrow> (c', toSeq s')) \\<Longrightarrow> c=c' \\<Longrightarrow> P\"\n  using step_m  step_ce_elim_cases step_ce_not_step_e_step_c\n  by (simp add: mod_env_not_component)\n\n(* lemma step_ce_notNormal:   \n   assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>c\\<^sub>e (c', s')\" \n   shows \"(\\<forall>sa. \\<not>(s=Normal sa)) \\<Longrightarrow> s'=s\"\nusing step_m\nproof (induct rule:step_ce_induct) \n  case (e_step a b a' b')\n  thus ?case\n    using env_not_normal_s by blast\nnext\n  case (c_step a b a' b')\n  thus ?case\n    using ce_not_normal_s step_ce.c_step by blast\nqed *)\n\n(* lemma steps_ce_not_Normal:  \n   assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (c', s')\" \n   shows \"\\<forall>sa. \\<not>(s=Normal sa) \\<Longrightarrow> s'=s\"\nusing step_m\nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl then show ?case by auto\nnext\n  case (Trans a b a' b') \n  thus ?case using step_ce_notNormal by blast \nqed *)\n\nlemma step_ce_Normal_eq_l:   \n  assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, (s,l)) \\<rightarrow>\\<^sub>c\\<^sub>e (c',  (s',l'))\" and\n          step_ce:\"\\<Gamma>\\<turnstile>\\<^sub>c (c,  s) \\<rightarrow> (c',  s')\"\n   shows \"l=l'\"  \n  by (metis  env_c_c' mod_env_not_component snd_conv step_ce step_dest step_m)\n\nlemma step_ce_dest:   \n  assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>c\\<^sub>e (c', s')\" \n  shows \"\\<Gamma>\\<turnstile>\\<^sub>c (c, toSeq s) \\<rightarrow> (c', toSeq s') \\<or> \\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c', s')\"\n  using step_ce_not_step_e_step_c step_m by blast\n\n\n(* lemma steps_not_normal_ce_c: \n  assumes steps: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (c', s')\"\n  shows         \"( \\<forall>sa. \\<not>(s=Normal sa)) \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c (c, toSeq s) \\<rightarrow>\\<^sup>* (c', toSeq s')\"\nusing steps\nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl thus ?case by auto\nnext\n  case (Trans a b a' b') then show ?case \n    by (metis (no_types, hide_lams) converse_rtranclp_into_rtranclp env_c_c' \n           step_ce_notNormal step_ce_not_step_e_step_c)\nqed *)\n\nlemma ce_eq_length: assumes a0:\"\\<Gamma>\\<turnstile>\\<^sub>c (P,s) \\<rightarrow>\\<^sub>c\\<^sub>e (Q,t)\"\n            shows \"length (snd s) = length (snd t)\"\n  by (metis assms step_dest stepe_elim_cases1)\n\n\n\n\n\nlemma ce_Throw_toSkip: \n  assumes a0:\"\\<Gamma>\\<turnstile>\\<^sub>c (LanguageCon.com.Throw, s) \\<rightarrow>\\<^sub>c\\<^sub>e x\"\n  shows \"fst x = Throw\"\nproof-\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Throw, toSeq s) \\<rightarrow> (fst x, toSeq (snd x)) \n        \\<or> \\<Gamma>\\<turnstile>\\<^sub>c (Throw, s) \\<rightarrow>\\<^sub>e x\" using a0 step_ce_dest\n    by (metis prod.collapse)\n  thus ?thesis\n    by (metis env_c_c' prod.collapse prod.inject stepc_elim_cases(11))\nqed\n\n\nsubsection \\<open>Computations\\<close>\nsubsubsection \\<open>Sequential computations\\<close>\n\ntype_synonym ('g,'l,'p,'f,'e) confs = \n  \"('g\\<times>'l,'p,'f,'e) body \\<times> (('g, 'l, 'p,'f,'e) config_gs) list\"\n\n\ninductive_set cptn :: \"(('g,'l,'p,'f,'e) confs) set\"\nwhere\n  CptnOne: \" (\\<Gamma>, [(P,s)]) \\<in> cptn\"\n| Cptn: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow>\\<^sub>c\\<^sub>e (Q,t); (\\<Gamma>,(Q, t)#xs) \\<in> cptn \\<rbrakk> \\<Longrightarrow>\n             (\\<Gamma>,(P,s)#(Q,t)#xs) \\<in> cptn\"\n\n\ninductive_cases cptn_elim_cases [cases set]:\n\"(\\<Gamma>, [(P,s)]) \\<in> cptn\"\n\"(\\<Gamma>,(P,s)#(Q,t)#xs) \\<in> cptn\"\n\n\ninductive_cases cptn_elim_cases_pair [cases set]:\n\"(\\<Gamma>, [x]) \\<in> cptn\"\n\"(\\<Gamma>, x#x1#xs) \\<in> cptn\"\n\nlemma cptn_dest:\"(\\<Gamma>,(P,s)#(Q,t)#xs) \\<in> cptn \\<Longrightarrow> (\\<Gamma>,(Q,t)#xs)\\<in> cptn\"\nby (auto dest: cptn_elim_cases)\n\nlemma cptn_dest_pair:\"(\\<Gamma>,x#x1#xs) \\<in> cptn \\<Longrightarrow> (\\<Gamma>,x1#xs)\\<in> cptn\"\nproof -\n  assume \"(\\<Gamma>,x#x1#xs) \\<in> cptn\"\n  thus ?thesis using cptn_dest prod.collapse by metis\nqed\n\nlemma cptn_dest1:\"(\\<Gamma>,(P,s)#(Q,t)#xs) \\<in> cptn \\<Longrightarrow> (\\<Gamma>,(P,s)#[(Q,t)])\\<in> cptn\"\nproof -\n  assume a1: \"(\\<Gamma>, (P, s) # (Q, t) # xs) \\<in> cptn\"\n  have \"(\\<Gamma>, [(Q, t)]) \\<in> cptn\"\n    by (meson cptn.CptnOne)\n  thus ?thesis\n    using a1 cptn.Cptn cptn_elim_cases(2) by blast\n \nqed\n\nlemma cptn_dest1_pair:\"(\\<Gamma>,x#x1#xs) \\<in> cptn \\<Longrightarrow> (\\<Gamma>,x#[x1])\\<in> cptn\"\nproof -\n  assume \"(\\<Gamma>,x#x1#xs) \\<in> cptn\"\n  thus ?thesis using cptn_dest1 prod.collapse by metis\nqed\n\nlemma cptn_append_is_cptn [rule_format]: \n \"\\<forall>b a. (\\<Gamma>,b#c1)\\<in>cptn \\<longrightarrow>  (\\<Gamma>,a#c2)\\<in>cptn \\<longrightarrow> (b#c1)!length c1=a \\<longrightarrow> (\\<Gamma>,b#c1@c2)\\<in>cptn\"\napply(induct c1)\n apply simp\napply clarify\napply(erule cptn.cases,simp_all)\n  using cptn.Cptn by blast\n(* apply (simp add: cptn.CptnEnv)\nby (simp add: cptn.CptnComp) *)\n\nlemma cptn_dest_2:\n  \"(\\<Gamma>,a#xs@ys) \\<in> cptn  \\<Longrightarrow> (\\<Gamma>,a#xs)\\<in> cptn\"\nproof (induct \"xs\" arbitrary: a)\n  case Nil \n    then have \"\\<exists>p. [p] = [a]\"\n      by blast\n    then show ?case\n      using cptn.simps by fastforce  \nnext\n  case (Cons x xs')\n  then have \"(\\<Gamma>,a#[x])\\<in>cptn\" by (simp add: cptn_dest1_pair)\n  also have \"(\\<Gamma>, x # xs') \\<in> cptn\"     \n    by (metis (no_types) Cons.hyps Cons.prems append_Cons cptn_dest_pair)    \n  ultimately show ?case using cptn_append_is_cptn [of \\<Gamma> a \"[x]\" x xs']\n    by force    \nqed   \n\nlemma tl_in_cptn: \"\\<lbrakk> (g,a#xs) \\<in>cptn; xs\\<noteq>[] \\<rbrakk> \\<Longrightarrow> (g,xs)\\<in>cptn\"\n  by (force elim: cptn.cases)\n\nlemma sublist_in_cptn:\"(\\<Gamma>, ys@ xs) \\<in> cptn \\<Longrightarrow> xs\\<noteq> [] \\<Longrightarrow> (\\<Gamma>, xs) \\<in> cptn\"\nproof(induct ys)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons a ys)\n  then have \"(\\<Gamma>, a # (ys @ xs)) \\<in> cptn \" by auto\n  then show ?case \n    by (metis Cons.hyps Cons.prems(2) Nil_is_append_conv tl_in_cptn)  \nqed\n\nsubsection {* Relation between @{term \"stepc_rtrancl\"} and @{term \"cptn\"} *}\n\nlemma stepc_rtrancl_cptn:\n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c,s) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (cf,sf)\"           \n  shows \"\\<exists>xs. (\\<Gamma>,(c, s)#xs) \\<in> cptn \\<and>(cf,sf) = (last ((c,s)#xs))\"\nusing step \nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans]) \n  case Refl thus ?case using cptn.CptnOne\n    by (metis last_ConsL)\nnext\n  case (Trans c s c' s')  \n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c', s') \\<or> \\<Gamma>\\<turnstile>\\<^sub>c (c, toSeq s) \\<rightarrow> (c', toSeq s')\"\n    using Trans.hyps(1) step_ce_not_step_e_step_c by blast    \n  then show ?case  \n    by (metis (no_types) Trans.hyps(1) Trans.hyps(3) cptn.Cptn \n         last_ConsR list.simps(3))\nqed\n\n\n\nlemma cptn_stepc_rtrancl:\n  assumes cptn_step: \"(\\<Gamma>,(c, s)#xs) \\<in> cptn\" and\n          cf_last:\"(cf,sf) = (last ((c,s)#xs))\"\n  shows \"\\<Gamma>\\<turnstile>\\<^sub>c (c,s) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (cf,sf)\"\nusing cptn_step cf_last\nproof (induct xs arbitrary: c s) \n  case Nil\n  thus ?case by simp \nnext\n  case (Cons a xs c s)   \n  then obtain ca sa where eq_pair: \"a=(ca,sa)\" and \"(cf, sf) = last ((ca,sa) # xs) \" \n    using Cons\n    by (metis last.simps list.distinct(1) surj_pair)     \n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c (ca,sa) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (cf, sf)\" using Cons\n    using cptn_dest_pair by blast\n  moreover have \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>c\\<^sub>e (ca, sa)\" using Cons eq_pair\n    using cptn_elim_cases(2) by blast\n  ultimately show ?case\n    by auto\nqed\n\nlemma cptn_stepc_rtran:\n  assumes cptn_step: \"(\\<Gamma>,x#xs) \\<in> cptn\" and          \n          a1:\"Suc i < length (x#xs)\"\n  shows \"\\<Gamma>\\<turnstile>\\<^sub>c ((x#xs)!i) \\<rightarrow>\\<^sub>c\\<^sub>e ((x#xs)!(Suc i))\"\nusing cptn_step a1\nproof (induct i arbitrary: x xs)\n  case 0\n    then obtain x1 xs1 where xs:\"xs=x1#xs1\"\n      by (metis length_Cons less_not_refl list.exhaust list.size(3))    \n    then have \"\\<Gamma>\\<turnstile>\\<^sub>c x \\<rightarrow>\\<^sub>c\\<^sub>e x1\"\n        using \"0.prems\"(1) cptn_elim_cases_pair(2) by blast\n    then show ?case\n        by (simp add: xs)    \nnext\n  case (Suc i)  \n  then have \"Suc i < length xs\" by auto\n  moreover obtain x1 xs1 where xs:\"xs=x1#xs1\"\n    by (metis (full_types) calculation list.exhaust list.size(3) not_less0)  \n  moreover have \"\\<Gamma>\\<turnstile>\\<^sub>c ((x1 # xs1) ! i) \\<rightarrow>\\<^sub>c\\<^sub>e ((x1 # xs1) ! Suc i)\" \n    using Suc\n    using calculation(1) cptn_dest_pair xs by blast\n  thus ?case using xs by auto\nqed \n     \n      \nlemma cptn_stepconf_rtrancl:\n  assumes cptn_step: \"(\\<Gamma>,cfg1#xs) \\<in> cptn\" and\n          cf_last:\"cfg2 = (last (cfg1#xs))\"\n  shows \"\\<Gamma>\\<turnstile>\\<^sub>c cfg1 \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* cfg2\"\nusing cptn_step cf_last\nby (metis cptn_stepc_rtrancl prod.collapse)\n\nlemma cptn_all_steps_rtrancl:\n  assumes cptn_step: \"(\\<Gamma>,cfg1#xs) \\<in> cptn\"          \n  shows \"\\<forall>i<length (cfg1#xs). \\<Gamma>\\<turnstile>\\<^sub>c cfg1 \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* ((cfg1#xs)!i)\"\nusing cptn_step \nproof (induct xs arbitrary: cfg1)\n  case Nil thus ?case by auto\nnext\n  case (Cons x xs1) thus ?case\n  proof -\n     have hyp:\"\\<forall>i<length (x # xs1). \\<Gamma>\\<turnstile>\\<^sub>c x \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* ((x # xs1) ! i)\"\n       using Cons.hyps Cons.prems cptn_dest_pair by blast      \n     thus ?thesis\n     proof\n     {\n        fix i\n        assume a0:\"i<length (cfg1 # x # xs1)\"\n        then have \"Suc 0 < length (cfg1 # x # xs1)\"\n          by simp\n        hence \"\\<Gamma>\\<turnstile>\\<^sub>c (cfg1 # x # xs1) ! 0 \\<rightarrow>\\<^sub>c\\<^sub>e ((cfg1 # x # xs1) ! Suc 0)\"\n          using Cons.prems cptn_stepc_rtran by blast\n        then have \"\\<Gamma>\\<turnstile>\\<^sub>c cfg1 \\<rightarrow>\\<^sub>c\\<^sub>e x\" using Cons by simp\n        also have  \"i < Suc (Suc (length xs1))\"\n          using a0 by force\n        ultimately have \"\\<Gamma>\\<turnstile>\\<^sub>c cfg1 \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (cfg1 # x # xs1) ! i\" using hyp Cons\n         using converse_rtranclp_into_rtranclp hyp less_Suc_eq_0_disj \n         by auto \n     } thus ?thesis by auto qed\n  qed\nqed\n\n\n(* lemma last_not_F:\nassumes \n  a0:\"(\\<Gamma>,xs)\\<in>cptn\"  \nshows \"snd (last xs) \\<notin> Fault ` F \\<Longrightarrow> \\<forall>i < length xs. snd (xs!i) \\<notin> Fault ` F\"\nusing a0\nproof(induct) print_cases\n  case (CptnOne \\<Gamma> p s) thus ?case by auto\nnext\n  case (Cptn  \\<Gamma> P s t xs) \n  thus ?case \n    by (metis (no_types, hide_lams) ce_not_normal_s image_iff last_ConsR length_Cons less_Suc_eq_0_disj list.simps(3) nth_Cons_0 \n            nth_Cons_Suc snd_conv xstate.distinct(3)) \nqed *)\n\n(* lemma Normal_Normal: \nassumes p1:\"(\\<Gamma>, (P, Normal s) # a # as) \\<in> cptn\" and       \n        p2:\"(\\<exists>sb. snd (last ((P, Normal s) # a # as))  = Normal sb)\"\nshows \"\\<exists>sa. snd a = Normal sa\"\nproof -\n   obtain la1 la2 where last_prod:\"last ((P, Normal s)# a#as) = (la1,la2)\" by fastforce\n   obtain a1 a2 where a_prod:\"a=(a1,a2)\" by fastforce\n   from p1 have clos_p_a:\"\\<Gamma>\\<turnstile>\\<^sub>c (P,Normal s) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (a1, a2)\" \n     using a_prod cptn_elim_cases(2)\n     by blast  \n   then have \"\\<Gamma>\\<turnstile>\\<^sub>c (fst a, snd a) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>*  (la1,la2)\"\n     by (metis cptn_stepconf_rtrancl last_ConsR last_prod list.distinct(1) \n          p1 prod.exhaust_sel tl_in_cptn)  \n   moreover obtain bb where \"Normal bb = la2\" using last_prod p2 by auto\n   ultimately show ?thesis by (metis (no_types)  steps_ce_not_Normal)\nqed *)\n\nlemma cptn_eq_length:\"(\\<Gamma>,l)\\<in>cptn \\<Longrightarrow> \n       \\<forall>i. Suc i< length l \\<longrightarrow> length (snd (snd (l!i))) = length (snd (snd (l!(i+1))))\"\nproof-\n  assume a0:\"(\\<Gamma>,l)\\<in>cptn\"\n  {\n    fix i\n    assume a00:\"Suc i< length l\"\n    moreover obtain a as where \"l = a#as\"\n      using a0 calculation by (metis list.exhaust list.size(3) not_less_zero)\n    ultimately have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!i) \\<rightarrow>\\<^sub>c\\<^sub>e (l!Suc i)\" \n      using a0\n      using cptn_stepc_rtran by blast\n    then have \"length (snd (snd (l!i))) = length (snd (snd (l!(i+1))))\"\n      by (metis Suc_eq_plus1 ce_eq_length prod.exhaust_sel)\n  }\n  then show ?thesis by auto\nqed\n\nlemma cptn_all_len_eq_0:\n \"(\\<Gamma>,l)\\<in>cptn \\<Longrightarrow> snd ( (l!0)) = s \\<Longrightarrow>\n   i<length l \\<Longrightarrow>length (snd (snd (l!i))) =length (snd s)\"\nproof(induct i)\n  case 0\n  then show ?case\n    by simp \nnext \n  case (Suc i)\n  then have \"length (snd (snd (l!i))) =length (snd s) \" by auto  \n  then show ?case using cptn_eq_length Suc by fastforce\nqed\n\nlemma skip_all_skip:\n  assumes a0:\"(\\<Gamma>,cfg)\\<in>cptn\" and\n          a1:\"cfg = (Skip,s)#cfg1\"\n  shows \"\\<forall>i<length cfg. fst(cfg!i) = Skip\"\nusing a0 a1\nproof(induct cfg1 arbitrary:cfg s)\n  case Nil thus ?case by auto\nnext\n  case (Cons x xs)  \n  have cptn:\"(\\<Gamma>,x#xs)\\<in>cptn\"\n    using Cons.prems(1) Cons.prems(2) cptn_dest_pair by blast\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c(Skip,s) \\<rightarrow>\\<^sub>e x\" using cptn_elim_cases_pair(2)[OF Cons(2)[simplified Cons(3)]]\n    by (metis step_ce_dest stepc_elim_cases(1))   \n  then obtain s' where x:\"x = (Skip,s')\"\n    by (metis env_c_c' prod.exhaust_sel)    \n  moreover have cptn:\"(\\<Gamma>,x#xs)\\<in>cptn\"\n    using Cons.prems(1) Cons.prems(2) cptn_dest_pair by blast\n  moreover have \n    xs:\"x # xs = (LanguageCon.com.Skip, s') # xs\" using x by auto\n  ultimately show ?case using Cons(1)[OF cptn xs] Cons(3)\n    using diff_Suc_1 fstI length_Cons less_Suc_eq_0_disj nth_Cons' by auto \nqed\n\nlemma skip_all_skip_throw:\n  assumes a0:\"(\\<Gamma>,cfg)\\<in>cptn\" and\n          a1:\"cfg = (Throw,s)#cfg1\"\n  shows \"\\<forall>i<length cfg.  fst(cfg!i) = Throw\"\nusing a0 a1\nproof(induct cfg1 arbitrary:cfg s)\n  case Nil thus ?case by auto\nnext\n  case (Cons x xs)\n  have cptn:\"(\\<Gamma>,x#xs)\\<in>cptn\"\n    using Cons.prems(1) Cons.prems(2) cptn_dest_pair by blast\n  have ce:\"\\<Gamma>\\<turnstile>\\<^sub>c(Throw,s) \\<rightarrow>\\<^sub>c\\<^sub>e x\" \n    by (auto intro:cptn_elim_cases_pair(2)[OF Cons(2)[simplified Cons(3)]])\n  then obtain s' where x:\"x = (Throw, s')\"\n    using ce_Throw_toSkip \n    by (metis eq_fst_iff)      \n  show ?case using x\n    by (metis (no_types, lifting) Cons.hyps Cons.prems(2) cptn diff_Suc_1 \n         fstI length_Cons less_Suc_eq_0_disj nth_Cons')  \nqed\n\n\nlemma cptn_env_same_prog:\nassumes a0: \"(\\<Gamma>, l) \\<in> cptn\" and\n        a1:  \"\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))\" and\n        a2: \"Suc j < length l\"\nshows \"fst (l!j) =  fst (l!0)\"\nusing a0 a1 a2\nproof (induct j arbitrary: l)\n  case 0 thus ?case by auto\nnext\n  case (Suc j) \n    then have \"fst (l!j) =  fst (l!0)\" by fastforce\n    thus ?case using Suc \n      by (metis (no_types) env_c_c' lessI prod.collapse)\n  qed\n\n\n\nlemma takecptn_is_cptn [rule_format, elim!]:\n  \"\\<forall>j. (\\<Gamma>,c) \\<in> cptn \\<longrightarrow> (\\<Gamma>, take (Suc j) c) \\<in> cptn\"\napply(induct \"c\")\n apply(force elim: cptn.cases)\napply clarify\napply(case_tac j)\n apply simp\n apply(rule CptnOne)\napply simp\napply(force intro:cptn.intros elim:cptn.cases)\ndone\n\n\n\nlemma dropcptn_is_cptn [rule_format,elim!]:\n  \"\\<forall>j<length c. (\\<Gamma>,c) \\<in> cptn \\<longrightarrow> (\\<Gamma>, drop j c) \\<in> cptn\"\napply(induct \"c\")\n apply(force elim: cptn.cases)\napply clarify\napply(case_tac j,simp+)\napply(erule cptn.cases)\n  apply simp\n apply force\n  done\n\nsubsection\\<open>Modular Definition of Computation\\<close>\ndefinition lift :: \"('g\\<times>'l,'p,'f,'e)com  \\<Rightarrow> ('g, 'l, 'p,'f,'e) config_gs \\<Rightarrow> ('g, 'l, 'p,'f,'e) config_gs\" where\n  \"lift Q \\<equiv> \\<lambda>(P, s).  ((Seq P Q), s)\" \n\ndefinition lift_catch :: \"('g\\<times>'l,'p,'f,'e)com  \\<Rightarrow> ('g, 'l, 'p,'f,'e) config_gs \\<Rightarrow> ('g, 'l, 'p,'f,'e) config_gs\" where\n  \"lift_catch Q \\<equiv> \\<lambda>(P, s).  (Catch P Q, s)\"     \n\nlemma map_lift_eq_xs_xs':\"map (lift a) xs = map (lift a) xs' \\<Longrightarrow> xs=xs'\" \nproof (induct xs arbitrary: xs')\n  case Nil thus ?case by auto\nnext\n  case (Cons x xsa)\n  then have a0:\"(lift a) x # map (lift a) xsa = map (lift a) (x # xsa)\"\n    by fastforce \n  also obtain x' xsa' where xs':\"xs' = x'#xsa'\" \n    using Cons by auto\n  ultimately have a1:\"map (lift a) (x # xsa) =map (lift a) (x' # xsa')\"\n    using Cons by auto\n  then have xs:\"xsa=xsa'\" using a0 a1 Cons by fastforce\n  then have \"(lift a) x' = (lift a) x\" using a0 a1  by auto\n  then have \"x' = x\" unfolding lift_def\n    by (metis (no_types, lifting) LanguageCon.com.inject(3) \n               case_prod_beta old.prod.inject prod.collapse)   \n  thus ?case using xs xs' by auto\nqed\n\nlemma map_lift_catch_eq_xs_xs':\"map (lift_catch a) xs = map (lift_catch a) xs' \\<Longrightarrow> xs=xs'\" \nproof (induct xs arbitrary: xs')\n  case Nil thus ?case by auto\nnext\n  case (Cons x xsa)\n  then have a0:\"(lift_catch a) x # map (lift_catch a) xsa = map (lift_catch a) (x # xsa)\"\n    by auto \n  also obtain x' xsa' where xs':\"xs' = x'#xsa'\" \n    using Cons by auto\n  ultimately have a1:\"map (lift_catch a) (x # xsa) =map (lift_catch a) (x' # xsa')\"\n    using Cons by auto  \n  then have xs:\"xsa=xsa'\" using a0 a1 Cons by fastforce  \n  then have \"(lift_catch a) x' = (lift_catch a) x\" using a0 a1  by auto\n  then have \"x' = x\" unfolding lift_catch_def\n    by (simp add: prod.case_eq_if prod_eq_iff)\n  thus ?case using xs xs' by auto\nqed\n\nlemma map_lift_all_seq:\n assumes a0:\"zs=map (lift a) xs\" and\n         a1:\"i<length zs\"\n shows \"\\<exists>b. fst (zs!i) = Seq b a\"\nusing a0 a1\nproof (induct zs arbitrary: xs i)\n  case Nil thus ?case by auto\nnext\n  case (Cons z1 zsa) thus ?case unfolding lift_def\n  proof -\n    assume a1: \"z1 # zsa = map (\\<lambda>b. case b of (P, s) \\<Rightarrow> (LanguageCon.com.Seq P a, s)) xs\"\n    have \"\\<forall>p c. \\<exists>x. \\<forall>pa ca xa. \n            (pa \\<noteq> (ca::('a, 'b, 'c, 'd) LanguageCon.com, xa::('a, 'c) xstate) \\<or> ca = fst pa) \\<and> \n            ((c::('a, 'b, 'c, 'd) LanguageCon.com) \\<noteq> fst p \\<or> (c, x::('a, 'c) xstate) = p)\"\n      by fastforce\n    then obtain xx :: \"('a, 'b, 'c, 'd) LanguageCon.com \\<times> ('a, 'c) xstate \\<Rightarrow> ('a, 'b, 'c, 'd) LanguageCon.com \\<Rightarrow> ('a, 'c) xstate\" where\n      \"\\<And>p c x ca pa. (p \\<noteq> (c::('a, 'b, 'c, 'd) LanguageCon.com, x::('a, 'c) xstate) \\<or> c = fst p) \\<and> (ca \\<noteq> fst pa \\<or> (ca, xx pa ca) = pa)\"\n      by (metis (full_types))  \n    then show ?thesis\n      using a1 \\<open>i < length (z1 # zsa)\\<close>\n      by (simp add: Cons.hyps Cons.prems(1) case_prod_beta')\n  qed\nqed\n\nlemma map_lift_catch_all_catch:\n assumes a0:\"zs=map (lift_catch a) xs\" and\n         a1:\"i<length zs\"\n shows \"\\<exists>b. fst (zs!i) = Catch b a\"\nusing a0 a1\nproof (induct zs arbitrary: xs i)\n  case Nil thus ?case by auto\nnext\n  case (Cons z1 zsa) thus ?case unfolding lift_catch_def\n  proof -\n    assume a1: \"z1 # zsa = map (\\<lambda>b. case b of (P, s) \\<Rightarrow> (LanguageCon.com.Catch P a, s)) xs\"\n    have \"\\<forall>p c. \\<exists>x. \\<forall>pa ca xa. \n            (pa \\<noteq> (ca::('a, 'b, 'c, 'd) LanguageCon.com, xa::('a, 'c) xstate) \\<or> ca = fst pa) \\<and> \n            ((c::('a, 'b, 'c, 'd) LanguageCon.com) \\<noteq> fst p \\<or> (c, x::('a, 'c) xstate) = p)\"\n      by fastforce\n    then obtain xx :: \"('a, 'b, 'c, 'd) LanguageCon.com \\<times> ('a, 'c) xstate \\<Rightarrow> ('a, 'b, 'c, 'd) LanguageCon.com \\<Rightarrow> ('a, 'c) xstate\" where\n      \"\\<And>p c x ca pa. (p \\<noteq> (c::('a, 'b, 'c, 'd) LanguageCon.com, x::('a, 'c) xstate) \\<or> c = fst p) \\<and> (ca \\<noteq> fst pa \\<or> (ca, xx pa ca) = pa)\"\n      by (metis (full_types))  \n    then show ?thesis\n      using a1 \\<open>i < length (z1 # zsa)\\<close>\n      by (simp add: Cons.hyps Cons.prems(1) case_prod_beta')\n  qed\nqed\n\nlemma map_lift_some_eq_pos:\n assumes a0:\"map (lift P) xs @ (P1, s1)#ys = \n             map (lift P) xs'@ (P2, s2)#ys'\" and\n         a1:\"\\<forall>p0. P1\\<noteq>Seq p0 P\" and\n         a2:\"\\<forall>p0. P2\\<noteq>Seq p0 P\" \n shows \"length xs = length xs'\"\nproof -\n  {assume ass:\"length xs \\<noteq> length xs'\"\n   { assume ass:\"length xs < length xs'\"\n     then have False using a0  map_lift_all_seq a1 a2\n     by (metis (no_types, lifting) fst_conv length_map nth_append nth_append_length)\n   }note l=this\n   { assume ass:\"length xs > length xs'\"\n     then have False using a0  map_lift_all_seq a1 a2\n     by (metis (no_types, lifting) fst_conv length_map nth_append nth_append_length)\n   }  then have False using l ass by fastforce\n  }\n  thus ?thesis by auto\nqed\n\nlemma map_lift_some_eq:\n assumes a0:\"map (lift P) xs @ (P1, s1)#ys = \n             map (lift P) xs'@ (P2, s2)#ys'\" and\n        a1:\"\\<forall>p0. P1\\<noteq>Seq p0 P\" and\n        a2:\"\\<forall>p0. P2\\<noteq>Seq p0 P\" \n shows \"xs' = xs \\<and> ys = ys'\"\nproof -\n  have \"length xs = length xs'\" using a0 map_lift_some_eq_pos a1 a2 by blast\n  also have \"xs' = xs\" using a0 assms calculation map_lift_eq_xs_xs' by fastforce\n  ultimately show ?thesis using a0 by fastforce\nqed\n\nlemma map_lift_catch_some_eq_pos:\n assumes a0:\"map (lift_catch P) xs @ (P1, s1)#ys = \n             map (lift_catch P) xs'@ (P2, s2)#ys'\" and\n         a1:\"\\<forall>p0. P1\\<noteq>Catch p0 P\" and\n         a2:\"\\<forall>p0. P2\\<noteq>Catch p0 P\" \n shows \"length xs = length xs'\"\nproof -\n  {assume ass:\"length xs \\<noteq> length xs'\"\n   { assume ass:\"length xs < length xs'\"\n     then have False using a0  map_lift_catch_all_catch a1 a2\n     by (metis (no_types, lifting) fst_conv length_map nth_append nth_append_length)\n   }note l=this\n   { assume ass:\"length xs > length xs'\"\n     then have False using a0  map_lift_catch_all_catch a1 a2\n     by (metis (no_types, lifting) fst_conv length_map nth_append nth_append_length)\n   }  then have False using l ass by fastforce\n  }\n  thus ?thesis by auto\nqed\n\nlemma map_lift_catch_some_eq:\n assumes a0:\"map (lift_catch P) xs @ (P1, s1)#ys = \n             map (lift_catch P) xs'@ (P2, s2)#ys'\" and\n        a1:\"\\<forall>p0. P1\\<noteq>Catch p0 P\" and\n        a2:\"\\<forall>p0. P2\\<noteq>Catch p0 P\" \n shows \"xs' = xs \\<and> ys = ys'\"\nproof -\n  have \"length xs = length xs'\" using a0 map_lift_catch_some_eq_pos a1 a2 by blast\n  also have \"xs' = xs\" using a0 assms calculation map_lift_catch_eq_xs_xs' by fastforce\n  ultimately show ?thesis using a0 by fastforce\nqed\n\n\n\ninductive_set cptn_mod :: \"(('g,'l,'p,'f,'e) confs) set\"\nwhere\n  CptnModOne: \"(\\<Gamma>,[(P, s)]) \\<in> cptn_mod\"\n| CptnModEnv: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow>\\<^sub>e (P,t);(\\<Gamma>,(P, t)#xs) \\<in> cptn_mod \\<rbrakk> \\<Longrightarrow> \n               (\\<Gamma>,(P, s)#(P, t)#xs) \\<in> cptn_mod\"\n| CptnModSkip: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(P,toSeq s) \\<rightarrow> (Skip,toSeq t); redex P = P;\n                snd s = snd t;\n                (\\<Gamma>,(Skip, t)#xs) \\<in> cptn_mod \\<rbrakk> \\<Longrightarrow> \n                (\\<Gamma>,(P,s)#(Skip, t)#xs) \\<in>cptn_mod\"\n| CptnModThrow: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(P,toSeq s) \\<rightarrow> (Throw,toSeq t); redex P = P;\n                snd s = snd t; (\\<Gamma>,(Throw, t)#xs) \\<in> cptn_mod \\<rbrakk> \\<Longrightarrow> \n                (\\<Gamma>,(P,s)#(Throw, t)#xs) \\<in>cptn_mod\" \n| CptnModStuck: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(P,toSeq s) \\<rightarrow> (Stuck,toSeq t); redex P = P;\n                snd s = snd t; (\\<Gamma>,(Stuck, t)#xs) \\<in> cptn_mod \\<rbrakk> \\<Longrightarrow> \n                (\\<Gamma>,(P,s)#(Stuck, t)#xs) \\<in>cptn_mod\"\n| CptnModFault: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(P,toSeq s) \\<rightarrow> (Fault f,toSeq t); redex P = P;\n                snd s = snd t; (\\<Gamma>,(Fault f, t)#xs) \\<in> cptn_mod \\<rbrakk> \\<Longrightarrow> \n                (\\<Gamma>,(P,s)#(Fault f, t)#xs) \\<in>cptn_mod\"\n| CptnModCondT: \"\\<lbrakk>(\\<Gamma>,(P0, s)#ys) \\<in> cptn_mod; fst s \\<in> b \\<rbrakk> \\<Longrightarrow> \n                (\\<Gamma>,((Cond b P0 P1), s)#(P0, s)#ys) \\<in> cptn_mod\"\n| CptnModCondF: \"\\<lbrakk>(\\<Gamma>,(P1,  s)#ys) \\<in> cptn_mod; fst s \\<notin> b \\<rbrakk> \\<Longrightarrow> \n                (\\<Gamma>,((Cond b P0 P1),  s)#(P1,  s)#ys) \\<in> cptn_mod\"\n| CptnModSeq1: \n  \"\\<lbrakk>(\\<Gamma>,(P0, s)#xs) \\<in> cptn_mod; zs=map (lift P1) xs \\<rbrakk> \\<Longrightarrow> \n   (\\<Gamma>,((Seq P0 P1), s)#zs) \\<in> cptn_mod\"\n\n| CptnModSeq2: \n  \"\\<lbrakk>(\\<Gamma>, (P0, s)#xs) \\<in> cptn_mod; fst(last ((P0, s)#xs)) = Skip;\n    (\\<Gamma>,(P1, snd(last ((P0, s)#xs)))#ys) \\<in> cptn_mod;\n    zs=(map (lift P1) xs)@((P1, snd(last ((P0, s)#xs)))#ys) \\<rbrakk> \\<Longrightarrow> \n   (\\<Gamma>,((Seq P0 P1), s)#zs) \\<in> cptn_mod\"\n(*| CptnModSeq3:\n  \"\\<lbrakk> (\\<Gamma>,(P1, s)#xs) \\<in> cptn_mod\\<rbrakk> \\<Longrightarrow> (\\<Gamma>,((Seq Skip P1), s)#(P1, s)#xs) \\<in> cptn_mod\"*)\n\n| CptnModSeq3: \n  \"\\<lbrakk>(\\<Gamma>, (P0, s)#xs) \\<in> cptn_mod; \n    fst(last ((P0, s)#xs)) = t; \n    t = Fault f \\<or> t = Stuck \\<or> t = Throw;\n    snd(last ((P0, s)#xs)) = s'; \n    (\\<Gamma>,(t, s')#ys) \\<in> cptn_mod; \n    zs=(map (lift P1) xs)@((t, s')#ys) \\<rbrakk> \\<Longrightarrow>\n   (\\<Gamma>,((Seq P0 P1),  s)#zs) \\<in> cptn_mod\"\n\n| CptnModWhile1: \n  \"\\<lbrakk>(\\<Gamma>, (P, s)#xs) \\<in> cptn_mod; fst s \\<in> b; \n    zs=map (lift (While b P)) xs \\<rbrakk> \\<Longrightarrow> \n    (\\<Gamma>, ((While b P),  s)#\n      ((Seq P (While b P)), s)#zs) \\<in> cptn_mod\"\n\n| CptnModWhile2: \n  \"\\<lbrakk> (\\<Gamma>, (P,  s)#xs) \\<in> cptn_mod; \n     fst(last ((P,  s)#xs))=Skip; fst s \\<in> b; \n     zs=(map (lift (While b P)) xs)@\n      (While b P, snd(last ((P,  s)#xs)))#ys; \n      (\\<Gamma>,(While b P, snd(last ((P,  s)#xs)))#ys) \\<in> cptn_mod\\<rbrakk> \\<Longrightarrow> \n   (\\<Gamma>,(While b P, s)#\n     (Seq P (While b P), s)#zs) \\<in> cptn_mod\"\n\n| CptnModWhile3: \n  \"\\<lbrakk> (\\<Gamma>, (P,  s)#xs) \\<in> cptn_mod; \n     fst(last ((P, s)#xs))=t; t=Throw \\<or> t= Fault f \\<or> t = Stuck; fst s \\<in> b;\n     snd(last ((P, s)#xs)) =  s'; \n    (\\<Gamma>,(t, s')#ys) \\<in> cptn_mod;  \n     zs=(map (lift (While b P)) xs)@((t, s')#ys)\\<rbrakk> \\<Longrightarrow> \n   (\\<Gamma>,(While b P,  s)#\n     (Seq P (While b P),  s)#zs) \\<in> cptn_mod\"\n\n| CptnModCall: \"\\<lbrakk>(\\<Gamma>,(bdy,  s)#ys) \\<in> cptn_mod;\\<Gamma> p = Some bdy; bdy\\<noteq>Call p \\<rbrakk> \\<Longrightarrow> \n                (\\<Gamma>,((Call p),  s)#(bdy,  s)#ys) \\<in> cptn_mod\" \n\n| CptnModDynCom: \"\\<lbrakk>(\\<Gamma>,(c (fst s),  s)#ys) \\<in> cptn_mod \\<rbrakk> \\<Longrightarrow> \n                  (\\<Gamma>,(DynCom c,  s)#(c (fst s),  s)#ys) \\<in> cptn_mod\"\n\n| CptnModGuard: \"\\<lbrakk>(\\<Gamma>,(c, s)#ys) \\<in> cptn_mod; fst s \\<in> g \\<rbrakk> \\<Longrightarrow> \n                 (\\<Gamma>,(Guard f g c,  s)#(c,  s)#ys) \\<in> cptn_mod\"\n\n| CptnModCatch1: \"\\<lbrakk>(\\<Gamma>,(P0, s)#xs) \\<in> cptn_mod; zs=map (lift_catch P1) xs \\<rbrakk>\n                 \\<Longrightarrow> (\\<Gamma>,((Catch P0 P1), s)#zs) \\<in> cptn_mod\"\n\n| CptnModCatch2: \n  \"\\<lbrakk>(\\<Gamma>, (P0, s)#xs) \\<in> cptn_mod; fst(last ((P0, s)#xs)) = t; \n    t = Skip \\<or> t = Fault f \\<or> t=Stuck; \n    (\\<Gamma>,(t,snd(last ((P0, s)#xs)))#ys) \\<in> cptn_mod;  \n    zs=(map (lift_catch P1) xs)@((t,snd(last ((P0, s)#xs)))#ys) \\<rbrakk> \\<Longrightarrow> \n   (\\<Gamma>,((Catch P0 P1), s)#zs) \\<in> cptn_mod\"\n\n| CptnModCatch3: \n  \"\\<lbrakk>(\\<Gamma>, (P0,  s)#xs) \\<in> cptn_mod; fst(last ((P0,  s)#xs)) = Throw; \n  snd(last ((P0,  s)#xs)) =  s';\n  (\\<Gamma>,(P1, snd(last ((P0,  s)#xs)))#ys) \\<in> cptn_mod; \n  zs=(map (lift_catch P1) xs)@((P1, snd(last ((P0,  s)#xs)))#ys) \\<rbrakk> \\<Longrightarrow> \n   (\\<Gamma>,((Catch P0 P1),  s)#zs) \\<in> cptn_mod\"\n\n\nlemmas CptnMod_induct = cptn_mod.induct [of _ \"[(c,s)]\", split_format (complete), case_names\nCptnModOne CptnModEnv CptnModSkip CptnModThrow CptnModStuck CptnModFault\n CptnModCondT CptnModCondF CptnModSeq1 CptnModSeq2 CptnModSeq3  CptnModWhile1 \nCptnModWhile2 CptnModWhile3 CptnModCall CptnModDynCom CptnModGuard \nCptnModCatch1 CptnModCatch2 CptnModCatch3, induct set]\n\ninductive_cases CptnMod_elim_cases [cases set]:\n\"(\\<Gamma>,(Skip, s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Guard f g c, s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Basic f e, s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Spec r e, s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Seq c1 c2, s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Cond b c1 c2, s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Await b c2 e, s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Call p, s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(DynCom c,s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Throw,s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Catch c1 c2,s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Fault f,s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Stuck,s)#u#xs) \\<in> cptn_mod\"\n\ninductive_cases CptnMod_env_elim_cases [cases set]:\n\"(\\<Gamma>,(P, s)#(P,s')#xs) \\<in> cptn_mod\"\n\nsubsection \\<open>Equivalence of small semantics and computational\\<close>\n\ndefinition catch_cond \nwhere\n\"catch_cond zs Q xs P s s'' s' \\<Gamma> \\<equiv> (zs=(map (lift_catch Q) xs) \\<or>\n             ((fst(((P, s)#xs)!length xs)=Throw \\<and>\n               snd(last ((P, s)#xs)) =  s' \\<and> s= s''\\<and>\n               (\\<exists>ys. (\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod \\<and> \n                zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n                (\\<exists>t. (fst(((P, s)#xs)!length xs)=t \\<and> (t=Skip \\<or> (\\<exists>f. t = Fault f) \\<or> t = Stuck) \\<and>\n                 (\\<exists>ys. (\\<Gamma>,(t,snd(last ((P, s)#xs)))#ys) \\<in> cptn_mod \\<and>                   \n                 zs=(map (lift_catch Q) xs)@((t,snd(last ((P, s)#xs)))#ys)))))\n\"\n\nlemma div_catch: assumes cptn_m:\"(\\<Gamma>,list) \\<in> cptn_mod\"\nshows \"(\\<forall>s P Q zs. list=(Catch P Q, s)#zs \\<longrightarrow>\n       (\\<exists>xs s' s''. \n          (\\<Gamma>,(P, s)#xs) \\<in> cptn_mod  \\<and> \n             catch_cond zs Q xs P s s'' s' \\<Gamma>))\"\nunfolding catch_cond_def\nusing cptn_m\nproof (induct rule: cptn_mod.induct)\ncase (CptnModOne \\<Gamma> P s)\n  thus ?case using cptn_mod.CptnModOne by blast \nnext\n  case (CptnModSkip  \\<Gamma> P s t xs) \n  from CptnModSkip.hyps\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, toSeq s) \\<rightarrow> (Skip, toSeq t)\" by auto\n  thus ?case \n    using CptnModSkip.hyps(2) redex_not_Catch by fast\nnext\n  case (CptnModThrow  \\<Gamma> P s t xs) \n  from CptnModThrow.hyps\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, toSeq s) \\<rightarrow> (Throw, toSeq t)\" by auto \n  thus ?case\n    using CptnModThrow.hyps(2) redex_not_Catch by fast    \nnext\n  case (CptnModFault \\<Gamma> P s f t xs)\n  thus ?case\n    using redex_not_Catch by force\nnext\n  case (CptnModStuck \\<Gamma> P s t xs)\n  thus ?case  using redex_not_Catch by force  \nnext\n  case (CptnModCondT \\<Gamma> P0 s ys b P1)\n  thus ?case using CptnModOne by fast\nnext\n  case (CptnModCondF \\<Gamma> P0 s ys b P1)\n  thus ?case using CptnModOne by fast\nnext\n  case (CptnModCatch1 sa P Q zs)\n  thus ?case by fast\nnext\n  case (CptnModCatch2 \\<Gamma> P0 s xs t f ys zs P1) \n  from CptnModCatch2.hyps(3) \n  have last:\"fst (((P0, s) # xs) ! length xs) = Skip \\<or>\n             fst (((P0, s) # xs) ! length xs) = Stuck \\<or>\n            (\\<exists>f. fst (((P0, s) # xs) ! length xs) = Fault f)\"\n    by (metis CptnModCatch2.hyps(4) last_length)\n  have P0cptn:\"(\\<Gamma>, (P0, s) # xs) \\<in> cptn_mod\" by fact            \n  then have \"zs = map (lift_catch P1) xs @((Skip, (snd(last ((P0, s)#xs))))#ys) \\<or> \n             zs = map (lift_catch P1) xs @((Stuck, (snd(last ((P0, s)#xs))))#ys)\\<or>\n             (\\<exists>f. zs = map (lift_catch P1) xs @((Fault f, (snd(last ((P0, s)#xs))))#ys))\"\n    using CptnModCatch2.hyps(4) CptnModCatch2.hyps(7) by auto\n  show ?case\n  proof -{\n    fix sa P Q zsa    \n    assume eq:\"(Catch P0 P1, s) # zs = (Catch P Q, sa) # zsa\"\n    then have \"P0 =P \\<and> P1 = Q \\<and> s=sa \\<and> zs=zsa\" by auto\n    then have \"(P0, s) = (P, sa)\" by auto \n    have \"last ((P0, s) # xs) = ((P, sa) # xs) ! length xs\"\n      by (simp add: `P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa` last_length)\n    then have \"zs = (map (lift_catch Q) xs)@((t,snd(last ((P0, s)#xs)))#ys)\"\n      by (simp add: CptnModCatch2.hyps(7) \\<open>P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa\\<close>)         \n    then have \"\\<exists>xs s' s''.\n           (\\<Gamma>, (P, s) # xs) \\<in> cptn_mod \\<and>\n           (zs = map (lift_catch Q) xs \\<or>\n            fst (((P, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n            snd (last ((P, s) # xs)) = s' \\<and>\n            s = s'' \\<and>\n            (\\<exists>ys. (\\<Gamma>, (Q, snd (((P, s) # xs) ! length xs)) # ys) \\<in> cptn_mod \\<and>\n                  zs =\n                  map (lift_catch Q) xs @ (Q, snd (((P, s) # xs) ! length xs)) # ys) \\<or>\n            (\\<exists>t. fst (((P, s) # xs) ! length xs) = t \\<and>\n                 (t = LanguageCon.com.Skip \\<or> (\\<exists>f. t = com.Fault f) \\<or> t = com.Stuck) \\<and>\n                 (\\<exists>ys. (\\<Gamma>, (t, snd (last ((P, s) # xs))) # ys) \\<in> cptn_mod \\<and>\n                       zs =\n                       map (lift_catch Q) xs @\n                       (t, snd (last ((P, s) # xs))) # ys)))\"\n      using P0cptn  `P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa`  \n           last  CptnModCatch2.hyps(4)\n      by (metis CptnModCatch2.hyps(3) CptnModCatch2.hyps(5) last_length)       \n   } \n   thus ?thesis by auto\n  qed\nnext\n  case (CptnModCatch3 \\<Gamma> P0 s xs s' P1 ys zs)  \n    from CptnModCatch3.hyps(3)\n    have last:\"fst (((P0,  s) # xs) ! length xs) = Throw\" \n      by (simp add: last_length) \n    from CptnModCatch3.hyps(4) \n    have lastnormal:\"snd (last ((P0,  s) # xs)) = s'\"\n      by (simp add: last_length)\n    have P0cptn:\"(\\<Gamma>, (P0,  s) # xs) \\<in> cptn_mod\" by fact\n    from CptnModCatch3.hyps(5) have P1cptn:\"(\\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod\"\n      by (simp add: last_length)              \n    then have \"zs = map (lift_catch P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys\"\n      by (simp add:CptnModCatch3.hyps)\n    show ?case\n      by (metis CptnModCatch3.hyps(3) CptnModCatch3.hyps(5) CptnModCatch3.hyps(7) \n                LanguageCon.com.inject(10) P0cptn fst_conv last_length \n              lastnormal list.inject snd_conv)   \nnext\n  case (CptnModEnv \\<Gamma> P s t xs)  \n  then have step:\"(\\<Gamma>, (P, t) # xs) \\<in> cptn_mod\" by auto  \n  have step_e: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow>\\<^sub>e (P, t)\" using CptnModEnv by auto\n  show ?case     \n    proof (cases P)\n      case (Catch P1 P2) \n      then have eq_P_Catch:\"(P, t) # xs = (LanguageCon.com.Catch P1 P2, t) # xs\" by auto            \n      then  obtain xsa t' t'' where \n         p1:\"(\\<Gamma>, (P1, t) # xsa) \\<in> cptn_mod\" and p2:\"\n     (xs = map (lift_catch P2) xsa \\<or>\n      fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \\<and>\n      snd (last ((P1, t) # xsa)) =  t' \\<and>\n      t =  t'' \\<and>\n      (\\<exists>ys. (\\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<in> cptn_mod \\<and>\n            xs = map (lift_catch P2) xsa @ \n                  (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<or>\n            (\\<exists>c. fst (((P1, t) # xsa) ! length xsa) = c \\<and> \n                 (c = Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n            (\\<exists>ys.(\\<Gamma>,(c,snd(last ((P1, t)#xsa)))#ys) \\<in> cptn_mod \\<and> \n            xs = map (lift_catch P2) xsa @\n            ((c, snd (last ((P1, t) # xsa)))#ys))))\" \n        using CptnModEnv(3) by fastforce\n      have all_step:\"(\\<Gamma>, (P1, s)#((P1, t) # xsa)) \\<in> cptn_mod\"              \n          using cptn_mod.CptnModEnv  p1 step_e by (metis env_intro_diff_p)                           \n      show ?thesis using p2 \n      proof  \n        assume \"xs = map (lift_catch P2) xsa\"\n        have \"(P, t) # xs = map (lift_catch P2) ((P1, t) # xsa)\"\n          by (simp add: `xs = map (lift_catch P2) xsa` lift_catch_def local.Catch)\n        thus ?thesis using all_step eq_P_Catch by fastforce\n      next \n        assume \n         \"fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \\<and> snd (last ((P1, t) # xsa)) =  t' \\<and>\n           t =  t'' \\<and> (\\<exists>ys. (\\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<in> cptn_mod \\<and>\n            xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<or>\n            (\\<exists>c. fst (((P1, t) # xsa) ! length xsa) = c \\<and> \n                 (c = Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n            (\\<exists>ys.(\\<Gamma>,(c,snd(last ((P1, t)#xsa)))#ys) \\<in> cptn_mod \\<and> \n            xs = map (lift_catch P2) xsa @ ((c, snd (last ((P1, t) # xsa)))#ys)))\"      \n         then show ?thesis \n         proof\n           assume \n            a1:\"fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \\<and> snd (last ((P1, t) # xsa)) =  t' \\<and>\n           t =  t'' \\<and> (\\<exists>ys. (\\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<in> cptn_mod \\<and>\n            xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys)\"\n            then obtain ys where p2_exec:\"(\\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<in> cptn_mod \\<and>\n                xs = map (lift_catch P2) xsa @\n                       (P2, snd (((P1, t) # xsa) ! length xsa)) # ys\" \n            by fastforce\n            from a1 obtain t1 where t_normal: \"t= t1\" by blast\n            have f1:\"fst (((P1, s)#(P1, t) # xsa) ! length ((P1, t)#xsa)) = LanguageCon.com.Throw\"\n              using a1 by fastforce\n             from a1 have last_normal: \"snd (last ((P1, s)#(P1, t) # xsa)) =  t'\"\n               by fastforce \n             then have p2_long_exec: \"(\\<Gamma>, (P2, snd (((P1, s)#(P1, t) # xsa) ! length ((P1, s)#xsa))) # ys) \\<in> cptn_mod \\<and>\n                (P, t)#xs = map (lift_catch P2) ((P1, t) # xsa) @\n                       (P2, snd (((P1, s)#(P1, t) # xsa) ! length ((P1, s)#xsa))) # ys\" using p2_exec \n                by (simp add: lift_catch_def local.Catch)                  \n             thus ?thesis using  a1 f1 last_normal all_step eq_P_Catch by fastforce               \n           next              \n             assume  as1:\"\\<exists>c. fst (((P1, t) # xsa) ! length xsa) = c \\<and> \n                             (c = Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n                          (\\<exists>ys.(\\<Gamma>,(c,snd(last ((P1, t)#xsa)))#ys) \\<in> cptn_mod \\<and> \n                           xs = map (lift_catch P2) xsa @ ((c, snd (last ((P1, t) # xsa)))#ys))\"               \n             then obtain c where as1:\"fst (((P1, t) # xsa) ! length xsa) = c \\<and> \n                             (c = Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n                          (\\<exists>ys.(\\<Gamma>,(c,snd(last ((P1, t)#xsa)))#ys) \\<in> cptn_mod \\<and> \n                           xs = map (lift_catch P2) xsa @ ((c, snd (last ((P1, t) # xsa)))#ys))\"\n               by auto\n             then have c:\"c = Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck\" by auto\n            then obtain ys where p1:\"(\\<Gamma>,(c,snd(last ((P1, t)#xsa)))#ys) \\<in> cptn_mod \\<and> \n                         (P, t)#xs = map (lift_catch P2) ((P1, t) # xsa) @\n                          ((c, snd (last ((P1, t) # xsa)))#ys)\"\n            proof -\n              assume a1: \"\\<And>ys. (\\<Gamma>, (c, snd (last ((P1, t) # xsa))) # ys) \\<in> cptn_mod \\<and> (P, t) # xs = map (lift_catch P2) ((P1, t) # xsa) @ (c, snd (last ((P1, t) # xsa))) # ys \\<Longrightarrow> thesis\"\n              have \"(LanguageCon.com.Catch P1 P2, t) # map (lift_catch P2) xsa = map (lift_catch P2) ((P1, t) # xsa)\"\n                by (simp add: lift_catch_def)\n              thus ?thesis\n                using a1 as1 eq_P_Catch by fastforce\n            qed                                  \n            show ?thesis using p1 as1 all_step eq_P_Catch   \n              by fastforce\n          qed\n      qed\n    qed (auto)\nqed(force+)\n\n\ndefinition seq_cond \nwhere\n\"seq_cond zs Q xs P s s'' s' \\<Gamma> \\<equiv> (zs=(map (lift Q) xs) \\<or>\n             ((fst(((P, s)#xs)!length xs)=Skip \\<and> \n               (\\<exists>ys. (\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod \\<and> \n                zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n             (\\<exists>t. (fst(((P, s)#xs)!length xs)=t \\<and> (t=Throw \\<or> t=Stuck \\<or> (\\<exists>f. t = Fault f)) \\<and>\n                 snd(last ((P, s)#xs)) = s' \\<and>  s= s''\\<and>\n                 (\\<exists>ys.  (\\<Gamma>,(t, s')#ys) \\<in> cptn_mod \\<and> zs=(map (lift Q) xs)@((t, s')#ys)))))\n\"\n\nlemma div_seq: assumes cptn_m:\"(\\<Gamma>,list) \\<in> cptn_mod\"\nshows \"(\\<forall>s P Q zs. list=(Seq P Q, s)#zs \\<longrightarrow>\n       (\\<exists>xs s' s''. \n          (\\<Gamma>,(P, s)#xs) \\<in> cptn_mod  \\<and> \n             seq_cond zs Q xs P s s'' s' \\<Gamma>))  \n            \"\nunfolding seq_cond_def\nusing cptn_m\nproof (induct rule: cptn_mod.induct)\n  case (CptnModOne \\<Gamma> P s)\n  thus ?case using cptn_mod.CptnModOne by blast \nnext\n  case (CptnModSkip  \\<Gamma> P s t xs) \n  from CptnModSkip.hyps\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, toSeq s) \\<rightarrow> (Skip, toSeq t)\" by auto\n  from CptnModSkip.hyps\n  have noskip: \"~(P=Skip)\" using stepc_elim_cases(1)\n    by (metis (no_types) local.step stepc_elim_cases(1))    \n  have x: \"\\<forall>c c1 c2. redex c = Seq c1 c2 \\<Longrightarrow> False\"\n          using redex_not_Seq by blast\n  from CptnModSkip.hyps\n  have in_cptn_mod: \"(\\<Gamma>, (Skip, t) # xs) \\<in> cptn_mod\" by auto  \n  then show ?case using CptnModSkip.hyps(2) SmallStepCon.redex_not_Seq\n    by (metis fst_conv list.inject)  \nnext\n  case (CptnModThrow  \\<Gamma> P s t xs)\n  from CptnModThrow.hyps\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, toSeq s) \\<rightarrow> (Throw, toSeq t)\" by auto \n  moreover from CptnModThrow.hyps\n  have in_cptn_mod: \"(\\<Gamma>, (Throw, t) # xs) \\<in> cptn_mod\" by auto \n  have no_seq: \"\\<forall>p1 p2. \\<not>(P=Seq p1 p2)\" \n    using CptnModThrow.hyps(2) redex_not_Seq by auto\n  ultimately show ?case by auto  \nnext case (CptnModStuck \\<Gamma> P s t xs) \n  thus ?case\n    by (metis Pair_inject SmallStepCon.redex_not_Seq list.inject)\nnext case (CptnModFault \\<Gamma> P s f t xs) \n  thus ?case    \n    by (metis Pair_inject SmallStepCon.redex_not_Seq list.inject)\nnext \n  case (CptnModCondT \\<Gamma> P0 s ys b P1)\n  thus ?case by auto\nnext\n  case (CptnModCondF \\<Gamma> P0 s ys b P1)\n  thus ?case by auto\nnext\n  case (CptnModSeq1 \\<Gamma> P0 s xs zs P1)\n  thus ?case by blast\nnext \n  case (CptnModSeq2 \\<Gamma> P0 s xs P1 ys zs) \n  from CptnModSeq2.hyps(3) last_length have last:\"fst (((P0, s) # xs) ! length xs) = Skip\" \n       by (simp add: last_length) \n  have P0cptn:\"(\\<Gamma>, (P0, s) # xs) \\<in> cptn_mod\" by fact\n  from CptnModSeq2.hyps(4) have P1cptn:\"(\\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod\"\n      by (simp add: last_length)          \n  then have \"zs = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys\" by (simp add:CptnModSeq2.hyps)\n  show ?case\n  proof -{\n    fix sa P Q zsa    \n    assume eq:\"(Seq P0 P1, s) # zs = (Seq P Q, sa) # zsa\"\n    then have \"P0 =P \\<and> P1 = Q \\<and> s=sa \\<and> zs=zsa\" by auto \n     have \"last ((P0, s) # xs) = ((P, sa) # xs) ! length xs\"\n            by (simp add: `P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa` last_length)\n    then have \"zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys\"\n         using `P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa` `zs = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys` \n         by force    \n    then have \"\\<exists>xs s' s''.\n           (\\<Gamma>, (P, s) # xs) \\<in> cptn_mod \\<and>\n           (zs = map (lift Q) xs \\<or>\n            fst (((P, s) # xs) ! length xs) = LanguageCon.com.Skip \\<and>\n            (\\<exists>ys. (\\<Gamma>, (Q, snd (((P, s) # xs) ! length xs)) # ys) \\<in> cptn_mod \\<and>\n                  zs = map (lift Q) xs @ (Q, snd (((P, s) # xs) ! length xs)) # ys) \\<or>\n            (\\<exists>t. fst (((P, s) # xs) ! length xs) = t \\<and>\n                 (t = LanguageCon.com.Throw \\<or> t = com.Stuck \\<or> (\\<exists>f. t = com.Fault f)) \\<and>\n                 snd (last ((P, s) # xs)) = s' \\<and>\n                 s = s'' \\<and>\n                 (\\<exists>ys. (\\<Gamma>, (t, s') # ys) \\<in> cptn_mod \\<and>\n                       zs = map (lift Q) xs @ (t, s') # ys)))\" \n        using P0cptn P1cptn  `P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa` last \n        by blast                 \n   }  \n   thus ?case by auto qed     \nnext\n  case (CptnModSeq3 \\<Gamma> P0 s xs t f s' ys zs P1) \n  from CptnModSeq3.hyps(3) \n   obtain c where \n        last:\"fst (((P0,  s) # xs) ! length xs) = c \\<and> \n               (c = Throw \\<or> c = Stuck \\<or> (\\<exists>f. c = Fault f))\"\n     by (metis CptnModSeq3.hyps(4) last_length)\n  have P0cptn:\"(\\<Gamma>, (P0,  s) # xs) \\<in> cptn_mod\" by fact\n  from CptnModSeq3.hyps(5) \n  have lastnormal:\"snd (last ((P0,  s) # xs)) =  s'\"\n    by blast    \n  then have \"zs = map (lift P1) xs @ ((c,  s')#ys)\"    \n    by (metis CptnModSeq3.hyps(3) CptnModSeq3.hyps(8) last last_length)\n  show ?case\n  proof -{\n    fix sa P Q zsa    \n    assume eq:\"(Seq P0 P1,  s) # zs = (Seq P Q,  sa) # zsa\"\n    then have \"P0 =P \\<and> P1 = Q \\<and>  s= sa \\<and> zs=zsa\" by auto\n    then have \"(P0,  s) = (P,  sa)\" by auto \n    have \"last ((P0,  s) # xs) = ((P,  sa) # xs) ! length xs\"                   \n      by (simp add: `P0 = P \\<and> P1 = Q \\<and>  s =  sa \\<and> zs = zsa` last_length)\n    then have zsa:\"zsa = (map (lift Q) xs)@((c, s')#ys)\"                    \n      using `P0 = P \\<and> P1 = Q \\<and>  s =  sa \\<and> zs = zsa` \n          `zs = map (lift P1) xs @ ((c,  s')#ys)`\n    by force\n    then have a1:\"(\\<Gamma>,(c, s')#ys) \\<in> cptn_mod\" using CptnModSeq3.hyps(6)\n      using CptnModSeq3.hyps(3) \\<open>(P0, s) = (P, sa)\\<close> \n        \\<open>last ((P0, s) # xs) = ((P, sa) # xs) ! length xs\\<close> last by auto  \n    \n    then have \"(\\<exists>xs s' s''. (\\<Gamma>, (P, sa) # xs) \\<in> cptn_mod \\<and>\n           (zsa = map (lift Q) xs \\<or>\n            fst (((P, sa) # xs) ! length xs) = LanguageCon.com.Skip \\<and>\n            (\\<exists>ys. (\\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<in> cptn_mod \\<and>\n                  zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<or>\n            (\\<exists>t. fst (((P, sa) # xs) ! length xs) = t \\<and>\n                 (t = LanguageCon.com.Throw \\<or> t = com.Stuck \\<or> (\\<exists>f. t = com.Fault f)) \\<and>\n                 snd (last ((P, sa) # xs)) = s' \\<and>\n                 sa = s'' \\<and>\n                 (\\<exists>ys. (\\<Gamma>, (t, s') # ys) \\<in> cptn_mod \\<and>\n                       zsa = map (lift Q) xs @ (t, s') # ys))))\"\n     using P0cptn zsa a1 last lastnormal\n     using \\<open>P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa\\<close> by blast     \n   }  \n   thus ?thesis by fastforce qed  \nnext \n  case (CptnModEnv \\<Gamma> P s t zs) \n  then have step:\"(\\<Gamma>, (P, t) # zs) \\<in> cptn_mod\" by auto\n  have step_e: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow>\\<^sub>e (P, t)\" using CptnModEnv by auto  \n  show ?case     \n    proof (cases P)\n      case (Seq P1 P2) \n      then have eq_P:\"(P, t) # zs = (LanguageCon.com.Seq P1 P2, t) # zs\" by auto      \n      then  obtain xs t' t'' c where \n         p1:\"(\\<Gamma>, (P1, t) # xs) \\<in> cptn_mod\" and \n         p2:\"(zs = map (lift P2) xs \\<or> \n             fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \\<and>      \n            (\\<exists>ys. (\\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<in> cptn_mod \\<and>\n            zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<or>\n            fst (((P1, t) # xs) ! length xs) =c \\<and> (c = Throw \\<or> c = Stuck \\<or> (\\<exists>f. c = Fault f)) \\<and>\n             snd (last ((P1, t) # xs)) =  t' \\<and>\n            t =  t'' \\<and> (\\<exists>ys. (\\<Gamma>,(c, t')#ys) \\<in> cptn_mod \\<and> \n            zs = map (lift P2) xs @  ((c,  t')#ys))) \" \n        using CptnModEnv(3) by fastforce\n      have all_step:\"(\\<Gamma>, (P1, s)#((P1, t) # xs)) \\<in> cptn_mod\"\n        using cptn_mod.CptnModEnv  p1 step_e\n        by (metis env_intro_diff_p)          \n      show ?thesis using p2 \n      proof  \n        assume \"zs = map (lift P2) xs\"\n        have \"(P, t) # zs = map (lift P2) ((P1, t) # xs)\"\n          by (simp add: `zs = map (lift P2) xs` lift_def local.Seq)\n        thus ?thesis using all_step eq_P by fastforce\n      next \n        assume  \n         \"(fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \\<and>      \n            (\\<exists>ys. (\\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<in> cptn_mod \\<and>\n            zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<or>\n            fst (((P1, t) # xs) ! length xs) =c \\<and> (c = Throw \\<or> c = Stuck \\<or> (\\<exists>f. c = Fault f)) \\<and>\n             snd (last ((P1, t) # xs)) =  t' \\<and> t =  t'' \\<and> (\\<exists>ys. (\\<Gamma>,(c, t')#ys) \\<in> cptn_mod \\<and> \n            zs = map (lift P2) xs @  ((c,  t')#ys))) \"\n         then show ?thesis \n         proof\n           assume \n            a1:\"fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \\<and>      \n               (\\<exists>ys. (\\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<in> cptn_mod \\<and>\n               zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys)\"\n               from a1 obtain ys where \n                   p2_exec:\"(\\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<in> cptn_mod \\<and>\n                       zs = map (lift P2) xs @\n                       (P2, snd (((P1, t) # xs) ! length xs)) # ys\" \n                by auto \n               have f1:\"fst (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs)) = LanguageCon.com.Skip\"\n                 using a1 by fastforce             \n               then have p2_long_exec: \n                 \"(\\<Gamma>, (P2, snd (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs))) # ys) \\<in> cptn_mod \\<and>\n                  (P, t)#zs = map (lift P2) ((P1, t) # xs) @\n                       (P2, snd (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs))) # ys\" \n             using p2_exec by (simp add: lift_def local.Seq)     \n             thus ?thesis using a1 f1 all_step eq_P by blast            \n           next\n           assume \n            a1:\"fst (((P1, t) # xs) ! length xs) =c \\<and> (c = Throw \\<or> c = Stuck \\<or> (\\<exists>f. c = Fault f)) \\<and>\n             snd (last ((P1, t) # xs)) =  t' \\<and> t =  t'' \\<and> (\\<exists>ys. (\\<Gamma>,(c, t')#ys) \\<in> cptn_mod \\<and> \n            zs = map (lift P2) xs @  ((c,  t')#ys))\"             \n             then have last_throw:\n               \"fst (((P1, s)#(P1, t) # xs) ! length ((P1, t) #xs)) = c\" \n               by fastforce\n             from a1 have last_normal: \"snd (last ((P1, s)#(P1, t) # xs)) =  t'\"\n               by fastforce\n             have seq_lift:\n               \"(LanguageCon.com.Seq P1 P2, t) # map (lift P2) xs = map (lift P2) ((P1, t) # xs)\"\n                by (simp add: a1 lift_def)             \n            thus  ?thesis using a1 last_throw last_normal all_step eq_P          \n              by (clarify, metis (no_types, lifting) append_Cons )                 \n          qed\n      qed\n    qed (auto) \nqed (force)+\n\n\n\nlemma cptn_onlyif_cptn_mod_aux:\n  assumes vars:\"v = toSeq s\" and vars1:\"w = toSeq t\" and stepseq:\"\\<Gamma>\\<turnstile>\\<^sub>c (P,v) \\<rightarrow> (Q,w)\" and\n          normal_eq_l:\"snd s = snd t\" and\n        stepmod:\"(\\<Gamma>,(Q,t)#xs) \\<in> cptn_mod\"\nshows \"(\\<Gamma>,(P,s)#(Q,t)#xs) \\<in> cptn_mod\"\nusing  stepseq normal_eq_l stepmod vars vars1\nproof (induct arbitrary: xs)\n  case (Basicc f e s1)     \n  thus ?case  using stepc.Basicc[of \\<Gamma> f e s1]  \n    by (simp add: cptn_mod.CptnModSkip)    \nnext\n  case (Specc s1 t1 r)\n  thus ?case using stepc.Specc[of s1 t1 r \\<Gamma>] by (simp add: cptn_mod.CptnModSkip)\nnext\n  case (SpecStuckc s1 r)\n  thus ?case using stepc.SpecStuckc[of s1 _ \\<Gamma>] by (simp add: cptn_mod.CptnModStuck)    \nnext\n  case (Guardc s1 g f c)\n  thus ?case\n    by (metis cptn_modp.CptnModGuard cptn_modp_cptn_mod_eq prod.exhaust_sel toSeq.simps)\nnext\n  case (GuardFaultc)\n  thus ?case\n    by (simp add: cptn_mod.CptnModFault stepc.GuardFaultc) \nnext\n  case (Seqc c1 s1 c1' t1 c2)  \n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c1, s1) \\<rightarrow> (c1', t1)\" by (simp add: Seqc.hyps(1))\n  then have nsc1: \"c1\\<noteq>Skip\" \n    using stepc_elim_cases(1) by auto\n  have assum: \"(\\<Gamma>, (Seq c1' c2, t) # xs) \\<in> cptn_mod\" using Seqc.prems by blast\n  have divseq:\"(\\<forall>s P Q zs. (Seq c1' c2, t) # xs=(Seq P Q, s)#zs \\<longrightarrow>\n                (\\<exists>xs sv' sv''. \n                  ((\\<Gamma>,(P, s)#xs) \\<in> cptn_mod  \\<and> \n                  (zs=(map (lift Q) xs) \\<or> \n                    ((fst(((P, s)#xs)!length xs)=Skip \\<and> \n                       (\\<exists>ys. (\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod \\<and> \n                       zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n                    (\\<exists>c. (fst(((P, s)#xs)!length xs)=c \\<and> (c=Throw \\<or> c=Stuck \\<or> (\\<exists>f. c = Fault f)) \\<and>\n                       snd(last ((P, s)#xs)) =  sv' \\<and>  t= sv''\\<and>\n                      (\\<exists>ys.  (\\<Gamma>,(c, sv')#ys) \\<in> cptn_mod \\<and> zs=(map (lift Q) xs)@((c, sv')#ys))))))))\"  \n    using div_seq [OF assum] unfolding seq_cond_def by auto\n  { fix sa P Q zsa\n    assume ass:\"(Seq c1' c2, t) # xs = (Seq P Q, sa) # zsa\"\n    then have eqs:\"c1' = P \\<and> c2 = Q \\<and> t = sa \\<and> xs = zsa\" by auto\n    then have \"\\<exists>xs sv' sv''. \n                (\\<Gamma>, (P, sa) # xs) \\<in> cptn_mod \\<and>\n                (zsa = map (lift Q) xs \\<or>              \n                 fst (((P, sa) # xs) ! length xs) = Skip \\<and>\n                   (\\<exists>ys. (\\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<in> cptn_mod \\<and>\n                     zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<or>\n                 (\\<exists>c. (fst(((P, sa)#xs)!length xs)=c \\<and> (c=Throw \\<or> c=Stuck \\<or> (\\<exists>f. c = Fault f))\\<and>\n                    snd(last ((P, sa)#xs)) =  sv' \\<and>  t= sv''\\<and>\n                      (\\<exists>ys.  (\\<Gamma>,(c, sv')#ys) \\<in> cptn_mod \\<and>  zsa=(map (lift Q) xs)@((c, sv')#ys)))))\" \n       using ass divseq   by blast\n  } note conc=this [of c1' c2 t xs]        \n  then obtain xs' sa' sa''\n  where split:\"(\\<Gamma>, (c1', t) # xs') \\<in> cptn_mod \\<and>\n               (xs = map (lift c2) xs' \\<or>                   \n                fst (((c1', t) # xs') ! length xs') = Skip \\<and>\n                  (\\<exists>ys. (\\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n                   xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<or>\n                (\\<exists>c. (fst(((c1', t)#xs')!length xs')=c \\<and> (c=Throw \\<or> c=Stuck \\<or> (\\<exists>f. c = Fault f)) \\<and>\n                      snd(last ((c1', t)#xs')) =  sa' \\<and> t= sa''\\<and>\n                         (\\<exists>ys.  (\\<Gamma>,(c, sa')#ys) \\<in> cptn_mod \\<and>\n                              xs=(map (lift c2) xs')@((c, sa')#ys)))))\"  by blast\n  then have \"xs = map (lift c2) xs' \\<or>                   \n             fst (((c1', t) # xs') ! length xs') = Skip \\<and>\n               (\\<exists>ys. (\\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n                xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<or>\n             (\\<exists>c. (fst(((c1', t)#xs')!length xs')=c \\<and> (c=Throw \\<or> c=Stuck \\<or> (\\<exists>f. c = Fault f)) \\<and>\n                  snd(last ((c1',t)#xs')) =  sa' \\<and> t= sa''\\<and>\n                  (\\<exists>ys.  (\\<Gamma>,(c, sa')#ys) \\<in> cptn_mod \\<and>\n                              xs=(map (lift c2) xs')@((c, sa')#ys))))\" by auto\n  thus ?case \n  proof{           \n    assume c1'nonf:\"xs = map (lift c2) xs'\"\n    then have c1'cptn:\"(\\<Gamma>, (c1', t) # xs') \\<in> cptn_mod\" using split by blast\n    then have induct_step: \"(\\<Gamma>, (c1, s) # (c1', t)#xs') \\<in> cptn_mod\"\n      using Seqc.hyps(2)\n      using Seqc.prems(3) Seqc.prems(4) normal_eq_l by blast  \n    then have \"(Seq c1' c2, t)#xs = map (lift c2) ((c1', t)#xs')\"\n      using c1'nonf\n      by (simp add: CptnModSeq1 lift_def)\n    thus ?thesis \n      using c1'nonf c1'cptn induct_step by (auto simp add: CptnModSeq1)\n  next\n    assume \"fst (((c1', t) # xs') ! length xs') = Skip \\<and>\n              (\\<exists>ys. (\\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n              xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<or>\n            (\\<exists>c. (fst(((c1', t)#xs')!length xs')=c \\<and> (c=Throw \\<or> c=Stuck \\<or> (\\<exists>f. c = Fault f)) \\<and>\n              snd(last ((c1', t)#xs')) =  sa' \\<and>  t= sa''\\<and>\n              (\\<exists>ys.  (\\<Gamma>,(c, sa')#ys) \\<in> cptn_mod \\<and> xs=(map (lift c2) xs')@((c, sa')#ys))))\"  \n    thus ?thesis\n    proof\n      assume assth:\n       \"fst (((c1', t) # xs') ! length xs') = Skip \\<and>\n        (\\<exists>ys. (\\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n        xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys)\"\n      then obtain ys where split':\n        \"(\\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n          xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys\"\n         by auto    \n      then have c1'cptn:\"(\\<Gamma>, (c1', t) # xs') \\<in> cptn_mod\" using split by blast\n      then have induct_step: \"(\\<Gamma>, (c1, s) # (c1', t)#xs') \\<in> cptn_mod\"\n        using Seqc.hyps(2)\n        using Seqc.prems(3) Seqc.prems(4) normal_eq_l by blast                  \n      then have seqmap:\"(Seq c1 c2, s)#(Seq c1' c2, t)#xs = map (lift c2) ((c1,s)#(c1', t)#xs') @ (c2, snd (((c1', t) # xs') ! length xs')) # ys\"\n        using split'   \n        by (simp add: CptnModSeq2 lift_def) \n      then have lastc1:\"last ((c1, s) # (c1', t) # xs') = ((c1', t) # xs') ! length xs'\"\n        by (simp add: last_length) \n      then have lastc1skip:\"fst (last ((c1, s) # (c1', t) # xs')) = Skip\" \n        using assth by fastforce          \n      thus ?thesis \n        using seqmap split' last_length cptn_mod.CptnModSeq2 induct_step lastc1 lastc1skip\n        by (smt append_Cons list.inject list.simps(9))         \n  next\n    assume assm: \n      \"\\<exists>c. (fst(((c1', t)#xs')!length xs')=c \\<and> (c=Throw \\<or> c=Stuck \\<or> (\\<exists>f. c = Fault f)) \\<and>\n       snd(last ((c1', t)#xs')) =  sa' \\<and> t= sa''\\<and>\n      (\\<exists>ys.  (\\<Gamma>,(c, sa')#ys) \\<in> cptn_mod \\<and> xs=(map (lift c2) xs')@((c, sa')#ys)))\"\n    then obtain c where \n      c:\"(fst(((c1', t)#xs')!length xs')=c \\<and> (c=Throw \\<or> c=Stuck \\<or> (\\<exists>f. c = Fault f)) \\<and>\n       snd(last ((c1', t)#xs')) =  sa' \\<and> t= sa''\\<and>\n       (\\<exists>ys.  (\\<Gamma>,(c, sa')#ys) \\<in> cptn_mod \\<and> xs=(map (lift c2) xs')@((c, sa')#ys)))\" by auto\n    then have s'eqsa'': \"t= sa''\" by auto\n    then have snormal: \"\\<exists>ns. s= ns\" using c_step normal_eq_l  by blast\n    then have c1'cptn:\"(\\<Gamma>, (c1', t) # xs') \\<in> cptn_mod\" using split by blast        \n    then have induct_step: \"(\\<Gamma>, (c1, s) # (c1', t)#xs') \\<in> cptn_mod\"\n      using Seqc.hyps(2) Seqc.prems(3) Seqc.prems(4) normal_eq_l by blast  \n    then obtain ys where seqmap:\n      \"(Seq c1' c2, t)#xs = (map (lift c2) ((c1', t)#xs'))@((c, sa')#ys)\"\n      using assm using c unfolding lift_def by auto    \n    moreover have \"fst (last ((c1, s) # (c1', t) # xs')) = c\" \n      using  c by (simp add: c last_length)  \n    moreover have \"snd (last ((c1, s) # (c1', t) # xs')) =  sa'\" using c by (auto simp add: last_length)      \n    ultimately show ?thesis\n      using assm c1'cptn induct_step  snormal seqmap s'eqsa'' \n      by (auto simp add:cptn_mod.CptnModSeq3)\n   qed\n }qed  \nnext\n  case (SeqSkipc c2 s1 xs)\n  then have c2incptn:\"(\\<Gamma>, (c2, s) # xs) \\<in> cptn_mod\"\n    using eq_toSeq by blast\n  moreover have 1:\"(\\<Gamma>, [(Skip, s)]) \\<in> cptn_mod\" by (simp add: cptn_mod.CptnModOne)\n  moreover have 2:\"fst(last ([(Skip, s)])) = Skip\" by fastforce\n  moreover have 3:\"(\\<Gamma>,(c2, snd(last [(Skip, s)]))#xs) \\<in> cptn_mod\" \n    using c2incptn by auto  \n  moreover have \"(c2,s)#xs=(map (lift c2) [])@(c2, snd(last [(Skip, s)]))#xs\"\n    by (auto simp add:lift_def)\n  moreover have \"s=t\" using eq_toSeq SeqSkipc by blast\n  ultimately show ?case        \n    by (simp add:  CptnModSeq2)\nnext\n  case (SeqThrowc c2 s1 xs)  \n  have eq_st:\"s=t\" using eq_toSeq[OF SeqThrowc(1)] SeqThrowc by auto\n  obtain ns where normals:\"s= ns\" using SeqThrowc by auto  \n  have \"(\\<Gamma>, [(Throw,  ns)]) \\<in> cptn_mod\" by (simp add: cptn_mod.CptnModOne) \n  then obtain ys where ys_nil:\"ys=[]\" and last:\"(\\<Gamma>, (Throw, s)#ys)\\<in> cptn_mod\" \n   using normals by auto\n  moreover have \"fst (last ((Throw,  ns)#ys)) = Throw\" using ys_nil last by auto\n  moreover have \"snd (last ((Throw,  ns)#ys)) =  ns\" using ys_nil last by auto\n  moreover from ys_nil have \"(map (lift c2) ys) = []\" by auto  \n  ultimately show ?case using SeqThrowc.prems cptn_mod.CptnModSeq3 eq_st normals\n    by (metis append_Nil)\nnext \n  case (SeqFaultc f c2 sa xs)\n  have eq_st:\"s=t\" \n    using SeqFaultc.prems(3) SeqFaultc.prems(4) eq_toSeq normal_eq_l by blast\n  obtain ns where normals:\"s= ns\"  by auto  \n  have \"(\\<Gamma>, [(Fault f,  ns)]) \\<in> cptn_mod\" by (simp add: cptn_mod.CptnModOne) \n  then obtain ys where ys_nil:\"ys=[]\" and last:\"(\\<Gamma>, (Fault f, s)#ys)\\<in> cptn_mod\" \n   using normals by auto\n  moreover have \"fst (last ((Fault f,  ns)#ys)) = Fault f\" using ys_nil last by auto\n  moreover have \"snd (last ((Fault f,  ns)#ys)) =  ns\" using ys_nil last by auto\n  moreover from ys_nil have \"(map (lift c2) ys) = []\" by auto  \n  ultimately show ?case using SeqFaultc.prems cptn_mod.CptnModSeq3 eq_st normals\n    by (metis append_Nil)\nnext \n  case (SeqStuckc  c2 sa xs)\n  have eq_st:\"s=t\" \n    using SeqStuckc.prems(3) SeqStuckc.prems(4) eq_toSeq normal_eq_l by blast\n  obtain ns where normals:\"s= ns\"  by auto  \n  have \"(\\<Gamma>, [(Stuck,  ns)]) \\<in> cptn_mod\" by (simp add: cptn_mod.CptnModOne) \n  then obtain ys where ys_nil:\"ys=[]\" and last:\"(\\<Gamma>, (Stuck, s)#ys)\\<in> cptn_mod\" \n   using normals by auto\n  moreover have \"fst (last ((Stuck,  ns)#ys)) = Stuck\" using ys_nil last by auto\n  moreover have \"snd (last ((Stuck,  ns)#ys)) =  ns\" using ys_nil last by auto\n  moreover from ys_nil have \"(map (lift c2) ys) = []\" by auto  \n  ultimately show ?case using SeqStuckc.prems cptn_mod.CptnModSeq3 eq_st normals\n    by (metis append_Nil)\nnext\n  case (CondTruec s1 b c1 c2)\n  moreover obtain ns where normals:\"s= ns\" by fastforce    \n  moreover have \"s=t\"\n    using calculation(4,5) eq_toSeq[OF calculation(2)]  by auto\n  ultimately show ?case by (simp add: cptn_mod.CptnModCondT)\nnext\n  case (CondFalsec s1 b c1 c2)\n  moreover obtain ns where normals:\"s= ns\" by fastforce\n  moreover have \"s=t\"\n    using calculation(4,5) eq_toSeq[OF calculation(2)]  by auto\n  ultimately show ?case\n     by (simp add: cptn_mod.CptnModCondF)\nnext\n  case (WhileTruec s1 b c)\n  have sinb: \"s1\\<in>b\" by fact\n  obtain ns where normals:\"s= ns\" by fastforce\n  have eq_st:\"s=t\" using eq_toSeq[OF WhileTruec(2)] WhileTruec by fastforce\n  have SeqcWhile: \"(\\<Gamma>, (Seq c (While b c),  ns) # xs) \\<in> cptn_mod\" \n    using sinb normals eq_st WhileTruec by blast  \n  have divseq:\n  \"(\\<forall>s P Q zs. (Seq c (While b c),  ns) # xs=(Seq P Q, s)#zs \\<longrightarrow>\n     (\\<exists>xs s'. ((\\<Gamma>,(P, s)#xs) \\<in> cptn_mod  \\<and> \n              (zs=(map (lift Q) xs) \\<or>\n              ((fst(((P, s)#xs)!length xs)=Skip \\<and> \n                 (\\<exists>ys. (\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod \\<and> \n                 zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n              (\\<exists>c. (fst(((P, s)#xs)!length xs)=c \\<and> (c=Throw \\<or> c=Stuck \\<or> (\\<exists>f. c = Fault f)) \\<and>\n                 snd(last ((P, s)#xs)) =  s' \\<and>\n                 (\\<exists>ys.  (\\<Gamma>,(c, s')#ys) \\<in> cptn_mod \\<and> zs=(map (lift Q) xs)@((c, s')#ys))))))                            \n                 ))\" \n    using div_seq [OF SeqcWhile] eq_st normals unfolding seq_cond_def by fastforce\n  { fix sa P Q zsa\n    assume ass:\"(Seq c (While b c), ns) # xs = (Seq P Q, sa) # zsa\"\n    then have eqs:\"c = P \\<and> (While b c) = Q \\<and>  ns = sa \\<and> xs = zsa\" by auto\n    then have \n      \"(\\<exists>xs s'. (\\<Gamma>, (P, sa) # xs) \\<in> cptn_mod \\<and>\n         (zsa = map (lift Q) xs \\<or>              \n          fst (((P, sa) # xs) ! length xs) = Skip \\<and>\n          (\\<exists>ys. (\\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<in> cptn_mod \\<and>\n             zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<or>\n          (\\<exists>c. (fst(((P, sa)#xs)!length xs)=c \\<and>  (c=Throw \\<or> c=Stuck \\<or> (\\<exists>f. c = Fault f)) \\<and>\n          snd(last ((P, sa)#xs)) =  s' \\<and> \n          (\\<exists>ys.  (\\<Gamma>,(c, s')#ys) \\<in> cptn_mod \\<and> zsa=(map (lift Q) xs)@((c, s')#ys))))))\" \n             using ass divseq by fastforce\n    } note conc=this [of c \"While b c\" \" ns\" xs] \n   then obtain xs' s' \n     where  split:\n        \"(\\<Gamma>, (c,  ns) # xs') \\<in> cptn_mod \\<and>\n         (xs = map (lift (While b c)) xs' \\<or>\n         fst (((c, ns) # xs') ! length xs') = Skip \\<and>\n         (\\<exists>ys. (\\<Gamma>, (While b c, snd (((c,  ns) # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n            xs = map (lift (While b c)) xs' @ (While b c, snd (((c,  ns) # xs') ! length xs')) # ys) \\<or>\n         (\\<exists>t. fst (((c,  ns) # xs') ! length xs') = t \\<and> (t=Throw \\<or> t=Stuck \\<or> (\\<exists>f. t = Fault f)) \\<and>\n          snd (last ((c,  ns) # xs')) =  s' \\<and> \n         (\\<exists>ys.  (\\<Gamma>, ((t,  s')#ys)) \\<in> cptn_mod \\<and> xs = map (lift (While b c)) xs' @ ((t,  s')#ys))))\"\n      by blast\n   then have \n     \"xs = map (lift (While b c)) xs' \\<or>\n      fst (((c,  ns) # xs') ! length xs') = Skip \\<and>\n      (\\<exists>ys. (\\<Gamma>, (While b c, snd (((c,  ns) # xs') ! length xs')) # ys)\\<in> cptn_mod \\<and>\n         xs = map (lift (While b c)) xs' @ (While b c, snd (((c,  ns) # xs') ! length xs')) # ys) \\<or>\n      (\\<exists>t. fst (((c,  ns) # xs') ! length xs') = t \\<and> (t=Throw \\<or> t=Stuck \\<or> (\\<exists>f. t = Fault f)) \\<and>\n            snd (last ((c,  ns) # xs')) =  s' \\<and>\n            (\\<exists>ys.  (\\<Gamma>, ((t,  s')#ys)) \\<in> cptn_mod \\<and>\n          xs = map (lift (While b c)) xs' @ ((t,  s')#ys)))\" ..\n   thus ?case\n   proof{ \n     assume 1:\"xs = map (lift (While b c)) xs'\"  \n     have 3:\"(\\<Gamma>, (c,  ns) # xs') \\<in> cptn_mod\" using split by auto   \n     then show ?thesis using \"1\" cptn_mod.CptnModWhile1 sinb normals eq_st  WhileTruec.prems(3)  \n       by fastforce        \n   next\n     assume \n      \"fst (((c,  ns) # xs') ! length xs') = Skip \\<and>\n       (\\<exists>ys. (\\<Gamma>, (While b c, snd (((c,  ns) # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n        xs = map (lift (While b c)) xs' @ (While b c, snd (((c,  ns) # xs') ! length xs')) # ys) \\<or>\n       (\\<exists>t. fst (((c,  ns) # xs') ! length xs') = t \\<and> (t=Throw \\<or> t=Stuck \\<or> (\\<exists>f. t = Fault f)) \\<and>\n          snd (last ((c,  ns) # xs')) =  s' \\<and>\n          (\\<exists>ys.  (\\<Gamma>, ((t,  s')#ys)) \\<in> cptn_mod \\<and> xs = map (lift (While b c)) xs' @ ((t,  s')#ys)))\"\n   thus ?case\n   proof\n     assume asm:\"fst (((c,  ns) # xs') ! length xs') = Skip \\<and>\n       (\\<exists>ys. (\\<Gamma>, (While b c, snd (((c,  ns) # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n        xs = map (lift (While b c)) xs' @ (While b c, snd (((c,  ns) # xs') ! length xs')) # ys)\"\n     then obtain ys where asm':\n     \"(\\<Gamma>, (While b c, snd (((c,  ns) # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n        xs = map (lift (While b c)) xs' @ (While b c, snd (((c,  ns) # xs') ! length xs')) # ys\" \n       by (auto simp add: last_length)\n     moreover have 3:\"(\\<Gamma>, (c,  ns) # xs') \\<in> cptn_mod\" using split by auto\n     moreover from asm have \"fst (last ((c,  ns) # xs'))  = Skip\"\n       by (simp add: last_length)        \n     ultimately show ?case using sinb normals eq_st WhileTruec.prems(3)\n       by (metis cptn_mod.CptnModWhile2 last_length toSeq.simps)       \n   next\n     assume asm:\n      \"\\<exists>t. fst (((c,  ns) # xs') ! length xs') = t \\<and> (t=Throw \\<or> t=Stuck \\<or> (\\<exists>f. t = Fault f)) \\<and>\n          snd (last ((c,  ns) # xs')) =  s' \\<and>\n          (\\<exists>ys.  (\\<Gamma>, ((t, s')#ys)) \\<in> cptn_mod \\<and> xs = map (lift (While b c)) xs' @ ((t,  s')#ys))\"   \n     moreover have 3:\"(\\<Gamma>, (c,  ns) # xs') \\<in> cptn_mod\" using split by auto\n     moreover from asm obtain v \n       where \"fst (last ((c,  ns) # xs'))  = v \\<and> (v=Throw \\<or> v=Stuck \\<or> (\\<exists>f. v = Fault f))\"\n       by (metis last_length) \n     ultimately show ?case using sinb normals eq_st WhileTruec.prems(3) CptnModWhile3\n       by (metis (no_types, lifting) last_length toSeq.simps)        \n   qed\n }qed  \nnext\n  case (WhileFalsec s1 b c)\n  thus ?case  using stepc.WhileFalsec[of s1 b \\<Gamma> c]  \n    by (simp add: cptn_mod.CptnModSkip) \nnext\n  case (Awaitc s1 b \\<Gamma>a c t1)\n  thus ?case using stepc.Awaitc[of s1 b \\<Gamma>a \\<Gamma>]\n    by (simp add: cptn_mod.CptnModSkip)\nnext\n  case (AwaitAbruptc s1 b \\<Gamma>a c t1 ta)\n  thus ?case using stepc.AwaitAbruptc[of s1 b \\<Gamma>a \\<Gamma> c t1 ta] by (simp add: cptn_mod.CptnModThrow) \nnext \n  case (AwaitFaultc s1 b \\<Gamma>a c f t1 ta)\n  thus ?case using stepc.AwaitFaultc\n    by (simp add: stepc.AwaitFaultc cptn_mod.CptnModFault) \nnext \n  case (AwaitStuckc s1 b \\<Gamma>a c  t1 ta)\n  thus ?case using stepc.AwaitStuckc\n    by (simp add: stepc.AwaitStuckc cptn_mod.CptnModStuck) \nnext\n  case (Callc p bdy s1)\n  moreover have eq_st:\"s=t\" using eq_toSeq[OF Callc(3)] Callc by auto\n  then show ?case using cptn_mod.CptnModCall\n    by (simp add: cptn_mod.CptnModCall calculation(1) calculation(2) calculation(4)) \nnext\n  case (CallUndefinedc p s1)  \n  thus ?case using stepc.CallUndefinedc[of \\<Gamma> p s1,OF CallUndefinedc(1)]\n    by (simp add: cptn_mod.CptnModStuck)\nnext\n  case (DynComc c s1)\n  moreover obtain ns where \"s= ns\" by auto \n  moreover have \"fst ns = s1\"\n    using calculation(3) calculation(5) by auto\n  moreover have \"s=t\"\n    using  calculation(3,4) eq_toSeq[OF DynComc(1)] by force \n  ultimately show ?case       \n  proof -\n    show ?thesis\n      using \\<open>(\\<Gamma>, (c s1, t) # xs) \\<in> cptn_mod\\<close> \\<open>fst ns = s1\\<close> \\<open>s = ns\\<close> \\<open>s = t\\<close> \n            cptn_mod.CptnModDynCom by blast\n  qed     \nnext\n  case (Catchc c1 s1 c1' t1 c2)\n   have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c1, s1) \\<rightarrow> (c1', t1)\" by (simp add: Catchc.hyps(1))\n  then have nsc1: \"c1\\<noteq>Skip\" using stepc_elim_cases(1)\n    by fastforce \n  have assum: \"(\\<Gamma>, (Catch c1' c2, t) # xs) \\<in> cptn_mod\" \n    using Catchc.prems by blast\n  have divcatch:\n  \"(\\<forall>s P Q zs. (Catch c1' c2, t) # xs=(Catch P Q, s)#zs \\<longrightarrow>\n    (\\<exists>xs s' s''. ((\\<Gamma>,(P, s)#xs) \\<in> cptn_mod  \\<and> \n                 (zs=(map (lift_catch Q) xs) \\<or>\n                 ((fst(((P, s)#xs)!length xs)=Throw \\<and> snd(last ((P, s)#xs)) = s' \\<and>  s= s''\\<and>\n                    (\\<exists>ys. (\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod \\<and> \n                    zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n                  (\\<exists>t. (fst(((P, s)#xs)!length xs)=t \\<and> (t=Skip \\<or> (\\<exists>f. t = Fault f) \\<or> t = Stuck) \\<and> \n                    (\\<exists>ys. (\\<Gamma>,(t,snd(last ((P, s)#xs)))#ys) \\<in> cptn_mod \\<and>                   \n                    zs=(map (lift_catch Q) xs)@((t,snd(last ((P, s)#xs)))#ys))))))))\" \n    using div_catch [OF assum] by (auto simp add: catch_cond_def)\n   {fix sa P Q zsa\n     assume ass:\"(Catch c1' c2, t) # xs = (Catch P Q, sa) # zsa\"\n     then have eqs:\"c1' = P \\<and> c2 = Q \\<and> t = sa \\<and> xs = zsa\" by auto\n     then have \"(\\<exists>xs sv' sv''. ((\\<Gamma>,(P, sa)#xs) \\<in> cptn_mod  \\<and> \n             (zsa=(map (lift_catch Q) xs) \\<or>\n             ((fst(((P, sa)#xs)!length xs)=Throw \\<and>\n               snd(last ((P, sa)#xs)) =  sv' \\<and>  t= sv''\\<and>\n               (\\<exists>ys. (\\<Gamma>,(Q, snd(((P, sa)#xs)!length xs))#ys) \\<in> cptn_mod \\<and> \n                zsa=(map (lift_catch Q) xs)@((Q, snd(((P, sa)#xs)!length xs))#ys)))) \\<or>\n                (\\<exists>c. (fst(((P, sa)#xs)!length xs)=c \\<and> (c=Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>                 \n                 (\\<exists>ys. (\\<Gamma>,(c,snd(last ((P, sa)#xs)))#ys) \\<in> cptn_mod \\<and>                   \n                 zsa=(map (lift_catch Q) xs)@((c,snd(last ((P, sa)#xs)))#ys)))))))\"   \n       using ass divcatch by fastforce\n   } note conc=this [of c1' c2 t xs]    \n   then obtain xs' sa' sa'' where split:\n     \"(\\<Gamma>, (c1', t) # xs') \\<in> cptn_mod \\<and> \n      (xs = map (lift_catch c2) xs' \\<or>\n        fst (((c1', t) # xs') ! length xs') = Throw \\<and>\n        snd (last ((c1', t) # xs')) =  sa' \\<and> t =  sa'' \\<and>\n        (\\<exists>ys. (\\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n            xs = map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<or>\n        (\\<exists>c. fst (((c1', t) # xs') ! length xs') = c \\<and> (c=Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n          (\\<exists>ys. (\\<Gamma>,(c,snd(last ((c1', t)#xs')))#ys) \\<in> cptn_mod \\<and>                   \n             xs=(map (lift_catch c2) xs')@((c,snd(last ((c1', t)#xs')))#ys))))\"          \n     by blast\n  note conjunct2[OF split]  \n  thus ?case   \n  proof{\n    assume c1'nonf:\"xs = map (lift_catch c2) xs'\"       \n    then have c1'cptn:\"(\\<Gamma>, (c1', t) # xs') \\<in> cptn_mod\" using split by blast\n    then have induct_step: \"(\\<Gamma>, (c1, s) # (c1', t)#xs') \\<in> cptn_mod\"\n      using Catchc.hyps(2)  Catchc.prems(3) Catchc.prems(4) normal_eq_l by blast\n    then have \"(Catch c1' c2, t)#xs = map (lift_catch c2) ((c1', t)#xs')\"\n      using c1'nonf\n      by (simp add: CptnModCatch1 lift_catch_def)\n    thus ?thesis \n      using c1'nonf c1'cptn induct_step by (auto simp add: CptnModCatch1)\n  next\n    assume \"fst (((c1', t) # xs') ! length xs') = Throw \\<and>\n           snd (last ((c1', t) # xs')) =  sa' \\<and> t =  sa'' \\<and>\n          (\\<exists>ys. (\\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n             xs = map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<or>\n          (\\<exists>c. fst (((c1', t) # xs') ! length xs') = c  \\<and> (c=Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n            (\\<exists>ys. (\\<Gamma>,(c,snd(last ((c1', t)#xs')))#ys) \\<in> cptn_mod \\<and>                   \n            xs=(map (lift_catch c2) xs')@((c,snd(last ((c1', t)#xs')))#ys)))\"  \n    thus ?thesis\n    proof\n      assume assth:\n       \"fst (((c1', t) # xs') ! length xs') = Throw \\<and>\n           snd (last ((c1', t) # xs')) =  sa' \\<and> t =  sa'' \\<and>\n          (\\<exists>ys. (\\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n             xs = map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys)\"     \n      then have snormal: \"\\<exists>ns. s= ns\" by auto\n      then obtain ys \n        where split':\"(\\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n                xs =map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys\"\n        using assth by auto    \n      then have c1'cptn:\"(\\<Gamma>, (c1',t) # xs') \\<in> cptn_mod\" \n        using split by blast\n      then have induct_step: \"(\\<Gamma>, (c1, s) # (c1', t)#xs') \\<in> cptn_mod\"\n        using Catchc.hyps(2) Catchc.prems(3) Catchc.prems(4) normal_eq_l by blast\n      then have seqmap:\"(Catch c1 c2, s)#(Catch c1' c2, t)#xs = \n                             map (lift_catch c2) ((c1,s)#(c1', t)#xs') @ \n                                (c2, snd (((c1', t) # xs') ! length xs')) # ys\"\n        using split' by (simp add: CptnModCatch3 lift_catch_def) \n      then have lastc1:\"last ((c1, s) # (c1', t) # xs') = ((c1', t) # xs') ! length xs'\"\n        by (simp add: last_length) \n      then have lastc1skip:\"fst (last ((c1, s) # (c1', t) # xs')) = Throw\" \n        using assth by fastforce\n      then have \"snd (last ((c1, s) # (c1', t) # xs')) =  sa'\"             \n        using assth by force\n      thus ?thesis \n        using snormal seqmap  split'   \n         cptn_mod.CptnModCatch3 induct_step lastc1 lastc1skip by fastforce\n        \n    next        \n      assume assm:\n       \"(\\<exists>c. fst (((c1', t) # xs') ! length xs') = c \\<and>  (c=Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n         (\\<exists>ys. (\\<Gamma>,(c,snd(last ((c1', t)#xs')))#ys) \\<in> cptn_mod \\<and>                   \n         xs=(map (lift_catch c2) xs')@((c,snd(last ((c1', t)#xs')))#ys)))\" \n      then obtain c where assm:\n        \"fst (((c1', t) # xs') ! length xs') = c \\<and>  (c=Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n         (\\<exists>ys. (\\<Gamma>,(c,snd(last ((c1', t)#xs')))#ys) \\<in> cptn_mod \\<and>                   \n         xs=(map (lift_catch c2) xs')@((c,snd(last ((c1', t)#xs')))#ys))\" by auto\n      then have c1'cptn:\"(\\<Gamma>, (c1', t) # xs') \\<in> cptn_mod\" using split by blast\n      then have induct_step: \"(\\<Gamma>, (c1, s) # (c1', t)#xs') \\<in> cptn_mod\"\n        using Catchc.hyps(2) Catchc.prems(3) Catchc.prems(4) normal_eq_l by blast  \n      then have \"map (lift_catch c2) ((c1', t) # xs') = \n                  (Catch c1' c2, t) # map (lift_catch c2) xs'\" \n        by (auto simp add: lift_catch_def)\n      then obtain ys\n        where seqmap:\"(Catch c1' c2, t)#xs = \n          (map (lift_catch c2) ((c1', t)#xs'))@((c,snd(last ((c1', t)#xs')))#ys)\"        \n        using assm by fastforce\n      then have lastc1:\"last ((c1, s) # (c1', t) # xs') = ((c1', t) # xs') ! length xs'\"\n        by (simp add: last_length) \n      then have lastc1skip:\"fst (last ((c1, s) # (c1', t) # xs')) = c\" \n        using assm by fastforce\n      then have \"snd (last ((c1, s) # (c1', t) # xs')) = snd (last ((c1',t) # xs'))\"\n        using assm by force\n      thus ?thesis             \n        using assm c1'cptn   seqmap \n         cptn_mod.CptnModCatch2[OF induct_step lastc1skip]        \n        by fastforce\n    qed\n  }qed              \nnext\n  case (CatchThrowc c2 s1)\n  then obtain ns where ns:\"s =  ns\"\n    by auto\n  then have eq_st: \"s=t\" using  eq_toSeq[OF CatchThrowc(1)] CatchThrowc(3,4) by auto\n  then have c2incptn:\"(\\<Gamma>, (c2,  ns) # xs) \\<in> cptn_mod\" using ns CatchThrowc\n    by auto\n  then have 1:\"(\\<Gamma>, [(Throw,  ns)]) \\<in> cptn_mod\" by (simp add: cptn_mod.CptnModOne)\n  then have 2:\"fst(last ([(Throw,  ns)])) = Throw\" by fastforce\n  then have 3:\"(\\<Gamma>,(c2, snd(last [(Throw,  ns)]))#xs) \\<in> cptn_mod\" \n      using c2incptn by auto  \n  then have \"(c2, ns)#xs=(map (lift c2) [])@(c2, snd(last [(Throw,  ns)]))#xs\" \n       by (auto simp add:lift_def)\n  thus ?case using eq_st ns CptnModCatch3 1 2 3\n    by fastforce    \nnext\n  case (CatchSkipc c2 s1)\n  have \"(\\<Gamma>, [(Skip, s)]) \\<in> cptn_mod\" by (simp add: cptn_mod.CptnModOne)\n  then obtain ys where ys_nil:\"ys=[]\" and last:\"(\\<Gamma>, (Skip,  s)#ys)\\<in> cptn_mod\"\n    by auto\n  moreover have \"fst (last ((Skip,  s)#ys)) = Skip\" using ys_nil last by auto\n  moreover have \"snd (last ((Skip,  s)#ys)) = s\" using ys_nil last by auto\n  moreover from ys_nil have \"(map (lift_catch c2) ys) = []\" by auto \n  moreover have \"s=t\"\n    using CatchSkipc.prems(3) CatchSkipc.prems(4) eq_toSeq normal_eq_l by blast \n  ultimately show ?case using CatchSkipc.prems by (simp add: cptn_mod.CptnModCatch2 ys_nil)\nnext\n  case (CatchFaultc f c2 sa xs) \n  have \"(\\<Gamma>, [(Fault f, s)]) \\<in> cptn_mod\" by (simp add: cptn_mod.CptnModOne)\n  then obtain ys where ys_nil:\"ys=[]\" and last:\"(\\<Gamma>, (Fault f,  s)#ys)\\<in> cptn_mod\"\n    by auto\n  moreover have \"fst (last ((Fault f,  s)#ys)) = Fault f\" using ys_nil last by auto\n  moreover have \"snd (last ((Fault f ,  s)#ys)) = s\" using ys_nil last by auto\n  moreover from ys_nil have \"(map (lift_catch c2) ys) = []\" by auto \n  moreover have \"s=t\"\n    using CatchFaultc.prems(3) CatchFaultc.prems(4) eq_toSeq normal_eq_l by blast \n  ultimately show ?case\n    by (metis CatchFaultc.prems(2) append_Nil cptn_modp.CptnModCatch2 cptn_modp_cptn_mod_eq)\nnext\n  case (CatchStuckc  c2 sa xs) \n  have \"(\\<Gamma>, [(Stuck, s)]) \\<in> cptn_mod\" by (simp add: cptn_mod.CptnModOne)\n  then obtain ys where ys_nil:\"ys=[]\" and last:\"(\\<Gamma>, (Stuck,  s)#ys)\\<in> cptn_mod\"\n    by auto\n  moreover have \"fst (last ((Stuck,  s)#ys)) = Stuck\" using ys_nil last by auto\n  moreover have \"snd (last ((Stuck ,  s)#ys)) = s\" using ys_nil last by auto\n  moreover from ys_nil have \"(map (lift_catch c2) ys) = []\" by auto \n  moreover have \"s=t\"\n    using CatchStuckc.prems(3) CatchStuckc.prems(4) eq_toSeq normal_eq_l by blast \n  ultimately show ?case\n    by (metis CatchStuckc.prems(2) append_Nil cptn_modp.CptnModCatch2 cptn_modp_cptn_mod_eq)\nqed\n\nlemma cptn_onlyif_cptn_mod: \nassumes cptn_asm:\"(\\<Gamma>,c) \\<in> cptn\"\nshows  \"(\\<Gamma>,c) \\<in> cptn_mod\"\nusing cptn_asm\nproof (induct) \n case CptnOne thus ?case by (rule CptnModOne)\nnext\n  case (Cptn \\<Gamma> P s Q t xs)\n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow>\\<^sub>e (Q, t) \\<or> \\<Gamma>\\<turnstile>\\<^sub>c (P, toSeq s) \\<rightarrow> (Q, toSeq t)\"\n    using step_ce_not_step_e_step_c by blast\n  moreover{\n    assume \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow>\\<^sub>e (Q, t)\"\n    then have ?case\n      using Cptn.hyps(3) cptn_mod.CptnModEnv env_c_c' by blast\n  }\n  moreover{\n    assume a00:\"\\<Gamma>\\<turnstile>\\<^sub>c (P, toSeq s) \\<rightarrow> (Q, toSeq t)\"   \n    moreover have \"\\<not> \\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow>\\<^sub>e (Q, t)\"\n      using env_c_c' mod_env_not_component calculation by fast    \n    ultimately have ?case using cptn_onlyif_cptn_mod_aux[OF _ _ a00 _ Cptn(3)] Cptn\n      using  step_dest1 by fast\n  }\n  ultimately show ?case by auto \nqed\n\nlemma lift_is_cptn: \nassumes cptn_asm:\"(\\<Gamma>,c)\\<in>cptn\"\nshows \"(\\<Gamma>,map (lift P) c) \\<in> cptn\"\nusing cptn_asm\nproof (induct)  \n  case CptnOne\n  have \"\\<forall>p f. (f, [p]) \\<in> cptn\"\n    using cptn.simps by fastforce\n  then show ?case by fastforce\nnext\n  case (Cptn \\<Gamma> Pa s Q t xs)\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Pa, s) \\<rightarrow>\\<^sub>e (Q, t) \\<or> \\<Gamma>\\<turnstile>\\<^sub>c (Pa, toSeq s) \\<rightarrow> (Q, toSeq t)\"\n    using Cptn.hyps(1) step_ce_not_step_e_step_c by blast\n  moreover{\n    assume \"\\<Gamma>\\<turnstile>\\<^sub>c (Pa, s) \\<rightarrow>\\<^sub>e (Q, t)\" \n    then have ?case using Cptn unfolding lift_def      \n      by (cases rule: step_e.cases, (simp add: Env cptn.Cptn e_step)) \n  }\n  moreover {\n    assume \"\\<Gamma>\\<turnstile>\\<^sub>c (Pa, toSeq s) \\<rightarrow> (Q, toSeq t)\"\n    moreover have \"\\<Gamma>\\<turnstile>\\<^sub>c (LanguageCon.com.Seq Pa P, toSeq s) \\<rightarrow> (LanguageCon.com.Seq Q P, toSeq t)\"\n      using Seqc calculation\n      by (simp add: Seqc)\n    ultimately have \"\\<Gamma>\\<turnstile>\\<^sub>c (LanguageCon.com.Seq Pa P, s) \\<rightarrow>\\<^sub>c\\<^sub>e (LanguageCon.com.Seq Q P, t)\"\n      using Cptn.hyps(1) c_step[of \\<Gamma> \"LanguageCon.com.Seq Pa P\" s \"LanguageCon.com.Seq Q P\" t] \n      env_c_c'  step_ce_step_c_eq_c step_dest by blast\n    then have ?case using  Cptn by (simp add:  cptn.Cptn lift_def)\n  }\n  ultimately show ?case by auto\nqed\n\nlemma lift_catch_is_cptn:\nassumes cptn_asm:\"(\\<Gamma>,c)\\<in>cptn\"\nshows \"(\\<Gamma>,map (lift_catch P) c) \\<in> cptn\"\nusing cptn_asm\nproof (induct)\n  case CptnOne\n  have \"\\<forall>p f. (f, [p]) \\<in> cptn\"\n    using cptn.simps by fastforce\n  then show ?case by fastforce \nnext\n  case (Cptn \\<Gamma> Pa s Q t xs)\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Pa, s) \\<rightarrow>\\<^sub>e (Q, t) \\<or> \\<Gamma>\\<turnstile>\\<^sub>c (Pa, toSeq s) \\<rightarrow> (Q, toSeq t)\"\n    using Cptn.hyps(1) step_ce_not_step_e_step_c by blast\n  moreover{\n    assume \"\\<Gamma>\\<turnstile>\\<^sub>c (Pa, s) \\<rightarrow>\\<^sub>e (Q, t)\" \n    then have ?case using Cptn unfolding lift_catch_def\n      by (cases rule: step_e.cases, (simp add: Env cptn.Cptn e_step)) \n  }\n  moreover {\n    assume \"\\<Gamma>\\<turnstile>\\<^sub>c (Pa, toSeq s) \\<rightarrow> (Q, toSeq t)\"\n    moreover have \"\\<Gamma>\\<turnstile>\\<^sub>c (LanguageCon.com.Catch Pa P, toSeq s) \\<rightarrow> (LanguageCon.com.Catch Q P, toSeq t)\"\n      using Catchc calculation by auto\n    ultimately have \"\\<Gamma>\\<turnstile>\\<^sub>c (LanguageCon.com.Catch Pa P, s) \\<rightarrow>\\<^sub>c\\<^sub>e (LanguageCon.com.Catch Q P, t)\"\n      using Cptn.hyps(1) c_step[of \\<Gamma> \"LanguageCon.com.Catch Pa P\" s \"LanguageCon.com.Catch Q P\" t] \n      env_c_c'  step_ce_step_c_eq_c step_dest by blast      \n    then have ?case using  Cptn by (simp add:  cptn.Cptn lift_catch_def)\n  }\n  ultimately show ?case by auto  \nqed\n\nlemma last_lift: \"\\<lbrakk>xs\\<noteq>[]; fst(xs!(length xs - (Suc 0)))=Q\\<rbrakk> \n \\<Longrightarrow> fst((map (lift P) xs)!(length (map (lift P) xs)- (Suc 0)))=Seq Q P\"\n  by (cases \"(xs ! (length xs - (Suc 0)))\") (simp add:lift_def)\n\nlemma last_lift_catch: \"\\<lbrakk>xs\\<noteq>[]; fst(xs!(length xs - (Suc 0)))=Q\\<rbrakk> \n \\<Longrightarrow> fst((map (lift_catch P) xs)!(length (map (lift_catch P) xs)- (Suc 0)))=Catch Q P\"\n  by (cases \"(xs ! (length xs - (Suc 0)))\") (simp add:lift_catch_def)\n\nlemma last_fst [rule_format]: \"P((a#x)!length x) \\<longrightarrow> \\<not>P a \\<longrightarrow> P (x!(length x - (Suc 0)))\" \n  by (induct x) simp_all\n\n\nlemma last_fst_esp: \n \"fst(((P,s)#xs)!(length xs))=Skip \\<Longrightarrow> P\\<noteq>Skip \\<Longrightarrow> fst(xs!(length xs - (Suc 0)))=Skip\" \napply(erule last_fst)\napply simp\ndone\n\nlemma last_snd: \"xs\\<noteq>[] \\<Longrightarrow> \n  snd(((map (lift P) xs))!(length (map (lift P) xs) - (Suc 0)))=snd(xs!(length xs - (Suc 0)))\"\n  by (cases \"(xs ! (length xs - (Suc 0)))\") (simp_all add:lift_def)\n\nlemma last_snd_catch: \"xs\\<noteq>[] \\<Longrightarrow> \n  snd(((map (lift_catch P) xs))!(length (map (lift_catch P) xs) - (Suc 0)))=snd(xs!(length xs - (Suc 0)))\"\n  by (cases \"(xs ! (length xs - (Suc 0)))\") (simp_all add:lift_catch_def)\n\nlemma Cons_lift: \"((Seq P Q), s) # (map (lift Q) xs) = map (lift Q) ((P, s) # xs)\"\n  by (simp add:lift_def)\nthm last_map eq_snd_iff list.inject list.simps(9) last_length\nlemma Cons_lift_catch: \"((Catch P Q), s) # (map (lift_catch Q) xs) = map (lift_catch Q) ((P, s) # xs)\"\n  by (simp add:lift_catch_def)\n\nlemma Cons_lift_append: \n  \"((Seq P Q), s) # (map (lift Q) xs) @ ys = map (lift Q) ((P, s) # xs)@ ys \"\n  by (simp add:lift_def)\n\nlemma Cons_lift_catch_append: \n  \"((Catch P Q), s) # (map (lift_catch Q) xs) @ ys = map (lift_catch Q) ((P, s) # xs)@ ys \"\n  by (simp add:lift_catch_def)\n\nlemma lift_nth: \"i<length xs \\<Longrightarrow> map (lift Q) xs ! i = lift Q  (xs! i)\"\n  by (simp add:lift_def)\n\nlemma lift_catch_nth: \"i<length xs \\<Longrightarrow> map (lift_catch Q) xs ! i = lift_catch Q  (xs! i)\"\n  by (simp add:lift_catch_def)\nthm list.simps(9) last_length lift_catch_def Cons_lift_catch\nlemma snd_lift: \"i< length xs \\<Longrightarrow> snd(lift Q (xs ! i))= snd (xs ! i)\"\n  by (cases \"xs!i\") (simp add:lift_def)\n\nlemma snd_lift_catch: \"i< length xs \\<Longrightarrow> snd(lift_catch Q (xs ! i))= snd (xs ! i)\"\n  by (cases \"xs!i\") (simp add:lift_catch_def)\n\n\nlemma lift_P1: \n assumes map_cptn:\"(\\<Gamma>, map (lift Q) ((P, s) # xs)) \\<in> cptn\" and\n         P_ends:\"fst (last ((P, s) # xs)) = Skip\"\n shows \"(\\<Gamma>, map (lift Q) ((P, s) # xs) @ [(Q, snd (last ((P, s) # xs)))]) \\<in> cptn\"\nusing map_cptn P_ends\nproof (induct xs arbitrary: P s) \n  case Nil\n  have P0_skips: \"P=Skip\" using Nil.prems(2) by auto   \n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c (LanguageCon.com.Seq LanguageCon.com.Skip Q, s) \\<rightarrow>\\<^sub>c\\<^sub>e (Q, s)\" \n    by (metis SeqSkipc c_step)\n  then have \"(\\<Gamma>,[(Seq Skip Q, s), (Q, s)]) \\<in> cptn\"       \n    by (simp add: cptn.Cptn cptn.CptnOne)\n  then show ?case using P0_skips by (simp add: lift_def)\nnext\n  case (Cons a xs)\n  have \"(\\<Gamma>, map (lift Q) ((P, s) # a # xs)) \\<in> cptn\"\n    using Cons.prems(1) by blast  \n  have \"fst (last ( a # xs)) = Skip\" using Cons.prems(2) by auto\n  also have seq_PQ:\"(\\<Gamma>,(Seq P Q,s) # (map (lift Q) (a#xs))) \\<in> cptn\"\n    by (metis Cons.prems(1) Cons_lift)\n  then have \"(\\<Gamma>,(map (lift Q) (a#xs))) \\<in> cptn\"\n    by (simp add: tl_in_cptn)\n  then have \"(\\<Gamma>, map (lift Q) (a#xs) @ [(Q, snd (last ((a#xs))))]) \\<in> cptn\" \n   by (metis Cons.hyps(1) calculation prod.collapse)   \n  then have t1:\"(\\<Gamma>, (Seq (fst a) Q, (snd a))#map (lift Q) xs @ [(Q, snd (last ((P, s)#(a#xs))))]) \\<in> cptn\"\n   by (simp add: Cons_lift_append)\n  then have \"(\\<Gamma>,(Seq P Q,s) # (Seq (fst a) Q, (snd a))#map (lift Q) xs)\\<in> cptn\"\n   using seq_PQ by (simp add: Cons_lift)  \n  then have t2: \"(\\<Gamma>,(Seq P Q,s) # [(Seq (fst a) Q, (snd a))]) \\<in> cptn\"\n   using cptn_dest1 by blast\n  then have\"((Seq P Q,s) # [(Seq (fst a) Q, (snd a))])!length [(Seq (fst a) Q, (snd a))] = (Seq (fst a) Q, (snd a))\"\n   by auto  \n  then have \"(\\<Gamma>,(Seq P Q,s) # [(Seq (fst a) Q, (snd a))]@map (lift Q) xs @ [(Q, snd (last ((P, s)#(a#xs))))])\\<in> cptn\"\n   using cptn_append_is_cptn t1 t2 by blast   \n  then have \"(\\<Gamma>, map (lift Q) ((P,s)#(fst a, snd a)#xs) @[(Q, snd (last ((P, s)#(a#xs))))])\\<in>cptn\"\n   using Cons_lift_append append_Cons append_Nil by metis\n  thus ?case by auto    \nqed\n\n\nlemma lift_catch_P1: \n assumes map_cptn:\"(\\<Gamma>, map (lift_catch Q) ((P,  s) # xs)) \\<in> cptn\" and\n         P_ends:\"fst (last ((P,  s) # xs)) = Throw\" and\n         P_ends_normal:\"\\<exists>p. snd(last ((P,  s) # xs)) =  p\"\n shows \"(\\<Gamma>, map (lift_catch Q) ((P,  s) # xs) @ [(Q, snd (last ((P,  s) # xs)))]) \\<in> cptn\"\nusing map_cptn P_ends P_ends_normal\nproof (induct xs arbitrary: P s) \n  case Nil\n  have P0_skips: \"P=Throw\" using Nil.prems(2) by auto   \n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c (LanguageCon.com.Catch LanguageCon.com.Throw Q,  s) \\<rightarrow>\\<^sub>c\\<^sub>e (Q,  s)\"\n     by (metis CatchThrowc surj_pair transfer_normal)\n  then have \"(\\<Gamma>,[(Catch Throw Q,  s), (Q,  s)]) \\<in> cptn\"\n    by (simp add: cptn.Cptn CatchThrowc cptn.CptnOne)\n  then show ?case using P0_skips by (simp add: lift_catch_def)\nnext\n  case (Cons a xs) \n  have s1:\"(\\<Gamma>, map (lift_catch Q) ((P,  s) # a # xs)) \\<in> cptn\"\n    using Cons.prems(1) by blast \n  have s2:\"fst (last ( a # xs)) = Throw\" using Cons.prems(2) by auto\n  then obtain p where s3:\"snd(last (a #xs)) =  p\" using Cons.prems(3) by auto\n  also have seq_PQ:\"(\\<Gamma>,(Catch P Q, s) # (map (lift_catch Q) (a#xs))) \\<in> cptn\"\n    by (metis Cons.prems(1) Cons_lift_catch) thm Cons.hyps\n  then have axs_in_cptn:\"(\\<Gamma>,(map (lift_catch Q) (a#xs))) \\<in> cptn\"\n    by (simp add: tl_in_cptn)\n  then have \"(\\<Gamma>, map (lift_catch Q) (a#xs) @ [(Q, snd (last ((a#xs))))]) \\<in> cptn\"\n    by (metis Cons.hyps prod.exhaust_sel s2)\n  then have t1:\"(\\<Gamma>, (Catch (fst a) Q, (snd a))#map (lift_catch Q) xs @ [(Q, snd (last ((P,  s)#(a#xs))))]) \\<in> cptn\"\n    by (simp add: Cons_lift_catch_append)\n  then have \"(\\<Gamma>,(Catch P Q, s) # (Catch (fst a) Q, (snd a))#map (lift_catch Q) xs)\\<in> cptn\"\n    using seq_PQ by (simp add: Cons_lift_catch)  \n  then have t2: \"(\\<Gamma>,(Catch P Q, s) # [(Catch (fst a) Q, (snd a))]) \\<in> cptn\"\n    using cptn_dest1 by blast\n  then have\"((Catch P Q, s) # [(Catch (fst a) Q, (snd a))])!length [(Catch (fst a) Q, (snd a))] = \n             (Catch (fst a) Q, (snd a))\"\n    by auto  \n  then have \"(\\<Gamma>,(Catch P Q, s) # [(Catch (fst a) Q, (snd a))]@\n                  map (lift_catch Q) xs @ [(Q, snd (last ((P,  s)#(a#xs))))])\\<in> cptn\"\n    using cptn_append_is_cptn t1 t2 by blast\n  then have \"(\\<Gamma>, map (lift_catch Q) ((P, s)#(fst a, snd a)#xs) @[(Q, snd (last ((P, s)#(a#xs))))])\\<in>cptn\"\n    using Cons_lift_catch_append append_Cons append_Nil by metis\n  thus ?case by auto    \nqed\n\nlemma seq2:\nassumes \n    p1:\"(\\<Gamma>, (P0, s) # xs) \\<in> cptn_mod\" and\n    p2:\"(\\<Gamma>, (P0, s) # xs) \\<in> cptn\" and\n    p3:\"fst (last ((P0, s) # xs)) = Skip\" and\n    p4:\"(\\<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod\" and\n    p5:\"(\\<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \\<in> cptn\" and\n    p6:\"zs = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys\"\nshows \"(\\<Gamma>, (Seq P0 P1, s) # zs) \\<in> cptn\"\nusing p1 p2 p3 p4 p5 p6\nproof -\nhave last_skip:\"fst (last ((P0, s) # xs)) = Skip\" using p3 by blast \n  have \"(\\<Gamma>, (map (lift P1) ((P0, s) # xs))@(P1, snd (last ((P0, s) # xs))) # ys) \\<in> cptn\"\n  proof -\n    have \"(\\<Gamma>,map (lift P1) ((P0, s) #xs)) \\<in> cptn\"\n      using p2 lift_is_cptn by blast \n    then have \"(\\<Gamma>,map (lift P1) ((P0, s) #xs)@[(P1, snd (last ((P0, s) # xs)))]) \\<in> cptn\" \n      using last_skip lift_P1 by blast \n    then have \"(\\<Gamma>,(Seq P0 P1, s) # map (lift P1) xs@[(P1, snd (last ((P0, s) # xs)))]) \\<in> cptn\"\n         by (simp add: Cons_lift_append)\n    moreover have \"last ((Seq P0 P1, s) # map (lift P1) xs @[(P1, snd (last ((P0, s) # xs)))]) = (P1, snd (last ((P0, s) # xs)))\" \n      by auto  \n    moreover have \"last ((Seq P0 P1, s) # map (lift P1) xs @[(P1, snd (last ((P0, s) # xs)))]) =\n                   ((Seq P0 P1, s) # map (lift P1) xs @[(P1, snd (last ((P0, s) # xs)))])!length (map (lift P1) xs @[(P1, snd (last ((P0, s) # xs)))])\" \n      by (metis last_length)             \n    ultimately have \"(\\<Gamma>, (Seq P0 P1, s) # map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys)\\<in> cptn\" \n      using cptn_append_is_cptn p5 by fastforce\n    thus ?thesis by (simp add: Cons_lift_append)\n  qed \n  thus ?thesis  \n    by (simp add: Cons_lift_append p6)\nqed\n\nlemma seq3:\nassumes\n    p1:\"(\\<Gamma>, (P0,  s) # xs) \\<in> cptn_mod\" and\n    p2:\"(\\<Gamma>, (P0,  s) # xs) \\<in> cptn\" and\n    p3:\"fst (last ((P0,  s) # xs)) = c\" and p3':\"c = Throw \\<or> c = Stuck \\<or> (\\<exists>f. c = Fault f)\" and\n    p4:\"snd (last ((P0,  s) # xs)) =  s'\" and\n    p5:\"(\\<Gamma>,(c, s')#ys) \\<in> cptn_mod\" and\n    p6:\"(\\<Gamma>,(c, s')#ys) \\<in> cptn\" and\n    p7:\"zs = map (lift P1) xs @((c, s')#ys)\" \nshows \"(\\<Gamma>, (Seq P0 P1,  s) # zs) \\<in> cptn\"\nusing p1 p2 p3 p4 p5 p6 p7\nproof (induct xs arbitrary: zs P0 s)   \n  case Nil \n  have h:\"\\<Gamma>\\<turnstile>\\<^sub>c (LanguageCon.com.Seq c P1,  s') \\<rightarrow>\\<^sub>c\\<^sub>e (c,  s')\"\n    using SeqThrowc\n    by (metis SeqFaultc SeqStuckc c_step p3')    \n  show ?case using cptn.Cptn[OF h,of ys] Nil\n    by simp\nnext\n  case (Cons a as)\n  then obtain sa where \"snd a =  sa\" by meson\n  obtain a1 a2 where a_prod:\"a=(a1,a2)\"\n    using prod.exhaust_sel by blast\n  obtain la1 la2 where last_prod:\"last (a#as) = (la1,la2)\"\n    using prod.exhaust_sel by blast \n  then have lasst_aas_last: \"last (a#as) = (last ((P0,  s) # a # as))\" by auto    \n  then have \"la1 = c\" using Cons.prems(3) last_prod by force\n  have \"la2 =  s'\" using Cons.prems(4) last_prod lasst_aas_last by force\n  have f1: \"(\\<Gamma>, (a1, a2) # as) \\<in> cptn\"\n    using Cons.prems(2) a_prod cptn_dest by blast\n  have f2: \" sa = a2\"\n    using `snd a =  sa` a_prod by force\n  have \"(\\<Gamma>, a # as) \\<in> cptn_mod\"\n    using f1 a_prod cptn_onlyif_cptn_mod by blast\n  then have hyp:\"(\\<Gamma>, (Seq a1 P1,  sa) # \n            map (lift P1) as @ ((c, s')#ys)) \\<in> cptn\"\n    using Cons.hyps Cons.prems(3) Cons.prems(4)  \n           Cons.prems(5) Cons.prems(6) a_prod f1 f2 by fastforce\n  thus ?case\n  proof -\n  have f1: \"(LanguageCon.com.Seq a1 P1, a2) # map (lift P1) as = map (lift P1) (a # as)\"\n    using Cons_lift a_prod by blast\n    have f2: \"(LanguageCon.com.Seq a1 P1, a2) # map (lift P1) as @ (c, s') # ys = zs\"\n      by (simp add: Cons.prems(7) Cons_lift_append a_prod)\n    have \"[(LanguageCon.com.Seq a1 P1, a2)] \\<noteq> []\"\n      by fastforce\n    then have \"\\<Gamma>\\<turnstile>\\<^sub>c (LanguageCon.com.Seq P0 P1, s) \\<rightarrow>\\<^sub>c\\<^sub>e (LanguageCon.com.Seq a1 P1, a2)\"\n      using f1 by (metis (no_types) Cons.prems(2) Cons_lift cptn_dest1\n              cptn_stepc_rtran last.simps last_length length_Cons \n                lessI lift_is_cptn list.size(3) nth_Cons_0)\n    then show ?thesis\n      using f2 cptn.Cptn f2 hyp\n      by (metis \\<open>snd a = sa\\<close> a_prod snd_conv)\n  qed  \nqed\n\nlemma cptn_if_cptn_mod: \nassumes cptn_mod_asm:\"(\\<Gamma>,c) \\<in> cptn_mod\"\nshows  \"(\\<Gamma>,c) \\<in> cptn\"\nusing cptn_mod_asm\nproof (induct)\n  case (CptnModOne) thus ?case using cptn.CptnOne by blast\nnext\n  case CptnModSkip thus ?case\n    by (simp add: c_step cptn.Cptn) \nnext\n  case CptnModThrow thus ?case by (simp add: c_step cptn.Cptn) \nnext \n  case CptnModStuck thus ?case by (simp add: c_step cptn.Cptn) \nnext \n  case CptnModFault thus ?case by (simp add: c_step cptn.Cptn)\nnext \n  case CptnModCondT thus ?case\n    by (metis CondTruec cptn.Cptn prod.exhaust_sel transfer_normal) \nnext\n  case CptnModCondF thus ?case\n    by (metis CondFalsec cptn.Cptn prod.exhaust_sel transfer_normal)\nnext\n  case (CptnModSeq1 \\<Gamma> P0 s xs zs P1) \n  have \"(\\<Gamma>, map (lift P1) ((P0, s) # xs)) \\<in> cptn\"\n    using CptnModSeq1.hyps(2) lift_is_cptn by blast\n  thus ?case by (simp add: Cons_lift CptnModSeq1.hyps(3))\nnext\n  case (CptnModSeq2 \\<Gamma> P0 s xs P1 ys zs)   \n  thus ?case by (simp add:seq2)\nnext\n  case (CptnModSeq3 \\<Gamma> P0 s xs t f s' ys zs P1) \n  thus ?case using seq3 by blast\nnext\n  case (CptnModWhile1  \\<Gamma> P s xs b zs) thus ?case \n    by (metis Cons_lift WhileTruec cptn.Cptn lift_is_cptn prod.collapse transfer_normal)\nnext \n  case (CptnModWhile2  \\<Gamma> P s xs b zs ys)    \n  then have \"(\\<Gamma>, (Seq P (While b P),  s) # zs) \\<in> cptn\" \n    by (simp add:seq2)  \n  moreover have \"\\<Gamma>\\<turnstile>\\<^sub>c(While b P,toSeq ( s)) \\<rightarrow> (Seq P (While b P),toSeq( s))\" \n    by (simp add: CptnModWhile2.hyps(4) WhileTruec)\n  ultimately show ?case\n    by (metis  cptn.Cptn prod.collapse toSeq.simps(1) transfer_normal)\nnext\n  case (CptnModWhile3  \\<Gamma> P s xs t f b s' ys zs) \n  then have \"(\\<Gamma>,(Seq P (While b P),  s) # zs) \\<in> cptn\"\n    using seq3 by blast        \n  moreover have \"\\<Gamma>\\<turnstile>\\<^sub>c(While b P,toSeq ( s)) \\<rightarrow> (Seq P (While b P),toSeq ( s))\"\n    by (simp add: CptnModWhile3.hyps(5) WhileTruec)\n  ultimately show ?case  by (metis  cptn.Cptn prod.collapse toSeq.simps(1) transfer_normal)\nnext \n  case (CptnModCall \\<Gamma> bdy s ys p) thus ?case\n    by (metis Callc cptn.Cptn prod.exhaust_sel transfer_normal) \nnext\n  case (CptnModDynCom \\<Gamma> c s ys) thus ?case\n    by (metis DynComc cptn.Cptn prod.exhaust_sel transfer_normal)\nnext\n  case (CptnModGuard \\<Gamma> c s ys g f) thus ?case\n    by (metis Guardc cptn.Cptn prod.exhaust_sel transfer_normal)\nnext\n  case (CptnModCatch1 \\<Gamma> P0 s xs zs P1)\n  have \"(\\<Gamma>, map (lift_catch P1) ((P0, s) # xs)) \\<in> cptn\"\n    using CptnModCatch1.hyps(2) lift_catch_is_cptn by blast\n  thus ?case by (simp add: Cons_lift_catch CptnModCatch1.hyps(3))\nnext\n  case (CptnModCatch2 \\<Gamma> P0 s xs t f ys zs P1)\n  thus ?case\n  proof (induct xs arbitrary: zs P0 s) \n    case Nil \n    then have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (Catch t P1, s) \\<rightarrow>\\<^sub>c\\<^sub>e (t, s)\"\n      by (metis CatchFaultc CatchSkipc CatchStuckc c_step)\n    have \"\\<exists>c p. (c, p) # zs = (LanguageCon.com.Catch P0 P1, s) # zs \\<and> \\<Gamma>\\<turnstile>\\<^sub>c (c, p) \\<rightarrow>\\<^sub>c\\<^sub>e (P0, s)\"\n        using step  Nil.prems(3) by force\n    then show ?case\n        using Nil.prems(7) Nil.prems(3)  Nil.prems(6) cptn.simps by fastforce     \n  next\n    case (Cons a as)\n    then obtain sa where \"snd a = sa\" by auto\n    then obtain a1 a2 where a_prod:\"a=(a1,a2)\" and sa_a2: \"a2 =sa\"\n      using prod.exhaust_sel by blast\n    obtain la1 la2 where last_prod:\"last (a#as) = (la1,la2)\"\n      using prod.exhaust_sel by blast \n    then have lasst_aas_last: \"last (a#as) = (last ((P0, s) # a # as))\" by auto    \n    then have \"la1 = t\" using Cons.prems(3) last_prod by force\n    have f1: \"(\\<Gamma>, (a1, a2) # as) \\<in> cptn\"\n      using Cons.prems(2) a_prod cptn_dest by blast\n    have \"(\\<Gamma>, a # as) \\<in> cptn_mod\"\n      using f1 a_prod cptn_onlyif_cptn_mod by blast\n    then have hyp:\"(\\<Gamma>, (Catch a1 P1, a2) # \n              map (lift_catch P1) as @ ((t, la2)#ys)) \\<in> cptn\"\n          using  Cons.prems a_prod f1 last_prod\n          by (simp add: Cons.hyps)\n    thus ?case\n    proof -\n      have \"(a1, sa) # as = a # as\"\n        using a_prod sa_a2 by fastforce\n      then have f1: \"(LanguageCon.com.Catch a1 P1, sa) # map (lift_catch P1) as @ (t, la2) # ys = zs\"\n        using Cons.prems(7) Cons_lift_catch_append last_prod by fastforce\n      have f2: \"((LanguageCon.com.Catch P0 P1, s) # map (lift_catch P1) (a # as)) ! Suc 0 = lift_catch P1 (a1, a2)\"\n        by (simp add: a_prod)\n      have f3: \"lift_catch P1 (a1, a2) = (LanguageCon.com.Catch a1 P1, a2)\"\n        by (metis (no_types) Cons_lift_catch list.inject list.simps(9))\n      have \"Suc 0 < length ((LanguageCon.com.Catch P0 P1, s) # map (lift_catch P1) (a # as))\"\n        by simp\n      then show ?thesis\n        using f3 f2 f1 by (metis (no_types) Cons.prems(2) Cons_lift_catch cptn.Cptn cptn_stepc_rtran hyp lift_catch_is_cptn nth_Cons_0 sa_a2)\n    qed\n   qed\nnext \n  case (CptnModCatch3  \\<Gamma> P0 s xs s' P1 ys zs)\n  thus ?case\n  proof (induct xs arbitrary: zs P0 s) \n    case Nil \n    then have \"\\<Gamma>\\<turnstile>\\<^sub>c (LanguageCon.com.Catch LanguageCon.com.Throw P1,  s) \\<rightarrow>\\<^sub>c\\<^sub>e (P1,  s)\"\n      by (metis CatchThrowc prod.exhaust_sel transfer_normal)\n    then  have \"\\<exists>c p. (c, p) # zs = (LanguageCon.com.Catch LanguageCon.com.Throw P1, s) # zs \\<and> \\<Gamma>\\<turnstile>\\<^sub>c (c, p) \\<rightarrow>\\<^sub>c\\<^sub>e (P1, s)\"\n        by auto\n    thus ?case using  cptn.simps\n      using Nil.prems(3) Nil.prems(6) Nil.prems(7) by fastforce    \n  next\n    case (Cons a as)\n    then obtain sa where \"snd a =  sa\" by auto\n    obtain a1 a2 where a_prod:\"a=(a1,a2)\" \n    by (meson prod.exhaust_sel)\n    obtain la1 la2 where last_prod:\"last (a#as) = (la1,la2)\"\n      by (meson prod.exhaust_sel) \n    then have lasst_aas_last: \"last (a#as) = (last ((P0,  s) # a # as))\" by auto    \n    then have \"la1 = Throw\" using Cons.prems(3) last_prod by force\n    have \"la2 =  s'\" using Cons.prems(4) last_prod lasst_aas_last by force\n    have f1: \"(\\<Gamma>, (a1, a2) # as) \\<in> cptn\"\n      using Cons.prems(2) a_prod cptn_dest by blast\n    have f2: \"sa = a2\"\n      using `snd a =  sa` a_prod by force\n    have \"(\\<Gamma>, a # as) \\<in> cptn_mod\"\n      using f1 a_prod cptn_onlyif_cptn_mod by blast\n    then have hyp:\"(\\<Gamma>, (Catch a1 P1,  sa) # \n              map (lift_catch P1) as @ (P1, snd (last ((a1,  sa) # as))) # ys) \\<in> cptn\"\n          using Cons.hyps Cons.prems a_prod f1 f2\n          by (metis lasst_aas_last)\n    thus ?case\n    proof -\n(*      have \"\\<Gamma>\\<turnstile>\\<^sub>c (P0, Normal s) \\<rightarrow>\\<^sub>e (P0, a2)\"\n        by (fastforce intro: step_e.intros) \n      then *) \n      have transit:\"\\<Gamma>\\<turnstile>\\<^sub>c(P0, s) \\<rightarrow>\\<^sub>c\\<^sub>e (a1, sa)\"             \n        by (metis (no_types) Cons.prems(2) a_prod  cptn_elim_cases(2)  f2)\n      then have transit_catch:\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch P0 P1, s) \\<rightarrow>\\<^sub>c\\<^sub>e (Catch a1 P1, sa)\"          \n      proof -\n        have f1: \"P0 = a1 \\<or> \\<not> \\<Gamma>\\<turnstile>\\<^sub>c (P0,  s) \\<rightarrow>\\<^sub>e (a1,  sa)\"\n          using not_eq_not_env transit by blast\n        have \"\\<Gamma>\\<turnstile>\\<^sub>c (a1,  s) \\<rightarrow>\\<^sub>e (a1,  sa) \\<longrightarrow> \n               \\<Gamma>\\<turnstile>\\<^sub>c (Catch a1 P1,  s) \\<rightarrow>\\<^sub>e (Catch a1 P1,  sa)\"\n          using env_intro\n          by (simp add: env_intro_diff_p)\n        then show ?thesis\n          using f1 by (metis (no_types) Catchc e_step prod.collapse \n              step_dest toSeq.simps(1) transfer_normal transit)\n      qed              \n      have \"a=(a1,  sa)\" using a_prod f2 by auto\n      then have \"snd (last ((a1,  sa) # as)) =  s'\"\n        using  Cons lasst_aas_last by fastforce\n      hence f1: \"snd (last ((a1,  sa) # as)) = la2\"\n        using `la2 =  s'` by blast\n      have \"(Catch a1 P1, a2) # map (lift_catch P1) as @ (P1, la2) # ys = zs\"\n        using Cons.prems Cons_lift_catch_append a_prod last_prod\n        by (simp add: Cons_lift_catch_append)\n      moreover have \"\\<Gamma>\\<turnstile>\\<^sub>c (LanguageCon.com.Catch P0 P1,  s) \\<rightarrow>\\<^sub>c\\<^sub>e (LanguageCon.com.Catch a1 P1, a2)\"\n         using f2 transit_catch by blast\n       ultimately show ?thesis\n        using f1 cptn.Cptn  f2 hyp by metis\n    qed\n  qed\nnext \n  case (CptnModEnv) thus ?case\n    by (simp add: cptn.Cptn e_step)\nqed\n\nlemma cptn_eq_cptn_mod: \nshows  \"(x \\<in>cptn_mod)  = (x\\<in>cptn)\"\nby (cases x, auto simp add: cptn_if_cptn_mod cptn_onlyif_cptn_mod)\n\nlemma cptn_eq_cptn_mod_set: \nshows  \"cptn_mod  = cptn\"\nby (auto simp add: cptn_if_cptn_mod cptn_onlyif_cptn_mod)\n\nsubsection \\<open>Computational modular semantic for nested calls\\<close>\ninductive_set cptn_mod_nest_call :: \"(nat\\<times>('g,'l,'p,'f,'e) confs) set\"\nwhere\n  CptnModNestOne: \"(n,\\<Gamma>,[(P, s)]) \\<in> cptn_mod_nest_call\"\n| CptnModNestEnv: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow>\\<^sub>e (P,t);(n,\\<Gamma>,(P, t)#xs) \\<in> cptn_mod_nest_call\\<rbrakk> \\<Longrightarrow> \n                     (n,\\<Gamma>,(P, s)#(P, t)#xs) \\<in> cptn_mod_nest_call\"\n| CptnModNestSkip: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(P,toSeq s) \\<rightarrow> (Skip,toSeq t); redex P = P; \n                    snd s= snd t;\n                     \\<forall>f. ((\\<Gamma> f) = Some Skip \\<longrightarrow> P  \\<noteq> Call f  );\n                      (n,\\<Gamma>,(Skip, t)#xs) \\<in> cptn_mod_nest_call \\<rbrakk> \\<Longrightarrow> \n                      (n,\\<Gamma>,(P,s)#(Skip, t)#xs) \\<in>cptn_mod_nest_call\"\n\n| CptnModNestThrow: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(P,toSeq s) \\<rightarrow> (Throw,toSeq t); redex P = P; \n                     \\<forall>f. ((\\<Gamma> f) = Some Throw \\<longrightarrow> P  \\<noteq> Call f  );  snd s = snd t;\n                      (n,\\<Gamma>,(Throw, t)#xs) \\<in> cptn_mod_nest_call \\<rbrakk> \\<Longrightarrow> \n                      (n,\\<Gamma>,(P,s)#(Throw, t)#xs) \\<in>cptn_mod_nest_call\"\n\n| CptnModNestStuck: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(P,toSeq s) \\<rightarrow> (Stuck,toSeq t); redex P = P; \n                     \\<forall>f. ((\\<Gamma> f) = Some Stuck \\<longrightarrow> P  \\<noteq> Call f  );  snd s = snd t;\n                      (n,\\<Gamma>,(Stuck, t)#xs) \\<in> cptn_mod_nest_call \\<rbrakk> \\<Longrightarrow> \n                      (n,\\<Gamma>,(P,s)#(Stuck, t)#xs) \\<in>cptn_mod_nest_call\"\n\n| CptnModNestFault: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(P,toSeq s) \\<rightarrow> (Fault f,toSeq t); redex P = P; \n                      \\<forall>fn. ((\\<Gamma> fn) = Some (Fault f) \\<longrightarrow> P  \\<noteq> Call fn);  snd s = snd t;\n                      (n,\\<Gamma>,((Fault f), t)#xs) \\<in> cptn_mod_nest_call \\<rbrakk> \\<Longrightarrow> \n                      (n,\\<Gamma>,(P,s)#(Fault f, t)#xs) \\<in>cptn_mod_nest_call\"\n\n| CptnModNestCondT: \"\\<lbrakk>(n,\\<Gamma>,(P0,  s)#ys) \\<in> cptn_mod_nest_call; fst s \\<in> b \\<rbrakk> \\<Longrightarrow> \n                    (n,\\<Gamma>,((Cond b P0 P1),  s)#(P0,  s)#ys) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestCondF: \"\\<lbrakk>(n,\\<Gamma>,(P1,  s)#ys) \\<in> cptn_mod_nest_call; fst s \\<notin> b \\<rbrakk> \\<Longrightarrow> \n                     (n,\\<Gamma>,((Cond b P0 P1),  s)#(P1,  s)#ys) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestSeq1: \n  \"\\<lbrakk>(n,\\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call; zs=map (lift P1) xs \\<rbrakk> \\<Longrightarrow> \n   (n,\\<Gamma>,((Seq P0 P1), s)#zs) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestSeq2: \n  \"\\<lbrakk>(n,\\<Gamma>, (P0, s)#xs) \\<in> cptn_mod_nest_call; fst(last ((P0, s)#xs)) = Skip;\n    (n,\\<Gamma>,(P1, snd(last ((P0, s)#xs)))#ys) \\<in> cptn_mod_nest_call;\n    zs=(map (lift P1) xs)@((P1, snd(last ((P0, s)#xs)))#ys) \\<rbrakk> \\<Longrightarrow> \n   (n,\\<Gamma>,((Seq P0 P1), s)#zs) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestSeq3: \n  \"\\<lbrakk>(n,\\<Gamma>, (P0,  s)#xs) \\<in> cptn_mod_nest_call; \n    fst(last ((P0,  s)#xs)) = t; t = Fault f \\<or> t = Stuck \\<or> t = Throw;\n    snd(last ((P0,  s)#xs)) =  s'; \n    (n,\\<Gamma>,(t, s')#ys) \\<in> cptn_mod_nest_call; \n    zs=(map (lift P1) xs)@((t, s')#ys) \\<rbrakk> \\<Longrightarrow>\n   (n,\\<Gamma>,((Seq P0 P1),  s)#zs) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestWhile1: \n  \"\\<lbrakk>(n,\\<Gamma>, (P,  s)#xs) \\<in> cptn_mod_nest_call; fst s \\<in> b; \n    zs=map (lift (While b P)) xs \\<rbrakk> \\<Longrightarrow> \n    (n,\\<Gamma>, ((While b P),  s)#\n      ((Seq P (While b P)), s)#zs) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestWhile2: \n  \"\\<lbrakk> (n,\\<Gamma>, (P,  s)#xs) \\<in> cptn_mod_nest_call; \n     fst(last ((P,  s)#xs))=Skip; fst s \\<in> b; \n     zs=(map (lift (While b P)) xs)@\n      (While b P, snd(last ((P,  s)#xs)))#ys; \n      (n,\\<Gamma>,(While b P, snd(last ((P,  s)#xs)))#ys) \\<in> \n        cptn_mod_nest_call\\<rbrakk> \\<Longrightarrow> \n   (n,\\<Gamma>,(While b P,  s)#\n     (Seq P (While b P),  s)#zs) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestWhile3: \n  \"\\<lbrakk> (n,\\<Gamma>, (P,  s)#xs) \\<in> cptn_mod_nest_call; \n     fst(last ((P,  s)#xs))=t;  t=Throw \\<or> t= Fault f \\<or> t = Stuck; fst s \\<in> b;\n     snd(last ((P,  s)#xs)) = s'; \n    (n,\\<Gamma>,(t, s')#ys) \\<in> cptn_mod_nest_call;  \n     zs=(map (lift (While b P)) xs)@((t, s')#ys)\\<rbrakk> \\<Longrightarrow> \n   (n,\\<Gamma>,(While b P,  s)#\n     (Seq P (While b P),  s)#zs) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestCall: \"\\<lbrakk>(n,\\<Gamma>,(bdy,  s)#ys) \\<in> cptn_mod_nest_call;\\<Gamma> p = Some bdy; bdy\\<noteq>Call p \\<rbrakk> \\<Longrightarrow> \n                 (Suc n, \\<Gamma>,((Call p),  s)#(bdy,  s)#ys) \\<in> cptn_mod_nest_call\" \n\n| CptnModNestDynCom: \"\\<lbrakk>(n,\\<Gamma>,(c (fst s),  s)#ys) \\<in> cptn_mod_nest_call \\<rbrakk> \\<Longrightarrow> \n                 (n,\\<Gamma>,(DynCom c,  s)#(c (fst s),  s)#ys) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestGuard: \"\\<lbrakk>(n,\\<Gamma>,(c,  s)#ys) \\<in> cptn_mod_nest_call; fst s \\<in> g \\<rbrakk> \\<Longrightarrow> \n                  (n,\\<Gamma>,(Guard f g c,  s)#(c,  s)#ys) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestCatch1: \"\\<lbrakk>(n,\\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call; zs=map (lift_catch P1) xs \\<rbrakk>\n                 \\<Longrightarrow> (n,\\<Gamma>,((Catch P0 P1), s)#zs) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestCatch2: \n  \"\\<lbrakk>(n,\\<Gamma>, (P0, s)#xs) \\<in> cptn_mod_nest_call; fst(last ((P0, s)#xs)) = t; \n    t = Skip \\<or> t = Fault f \\<or> t=Stuck; \n    (n,\\<Gamma>,(t,snd(last ((P0, s)#xs)))#ys) \\<in> cptn_mod_nest_call;  \n    zs=(map (lift_catch P1) xs)@((t,snd(last ((P0, s)#xs)))#ys) \\<rbrakk> \\<Longrightarrow> \n   (n,\\<Gamma>,((Catch P0 P1), s)#zs) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestCatch3: \n  \"\\<lbrakk>(n,\\<Gamma>, (P0,  s)#xs) \\<in> cptn_mod_nest_call; fst(last ((P0,  s)#xs)) = Throw; \n  snd(last ((P0,  s)#xs)) =  s';\n  (n,\\<Gamma>,(P1, snd(last ((P0,  s)#xs)))#ys) \\<in> cptn_mod_nest_call; \n  zs=(map (lift_catch P1) xs)@((P1, snd(last ((P0,  s)#xs)))#ys) \\<rbrakk> \\<Longrightarrow> \n   (n,\\<Gamma>,((Catch P0 P1),  s)#zs) \\<in> cptn_mod_nest_call\"\n\nlemmas CptnMod_nest_call_induct = cptn_mod_nest_call.induct [of _ _ \"[(c,s)]\", split_format (complete), case_names\nCptnModOne CptnModEnv CptnModSkip CptnModThrow   CptnModNestStuck  CptnModNestFault CptnModCondT CptnModCondF \nCptnModSeq1 CptnModSeq2 CptnModSeq3 CptnModSeq4 CptnModWhile1 CptnModWhile2 CptnModWhile3 CptnModCall CptnModDynCom CptnModGuard \nCptnModCatch1 CptnModCatch2 CptnModCatch3, induct set]\n\ninductive_cases CptnModNest_elim_cases [cases set]:\n\"(n,\\<Gamma>,(Skip, s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(Fault f, s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(Stuck, s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(Guard f g c, s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(Basic f e, s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(Spec r e, s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(Seq c1 c2, s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(Cond b c1 c2, s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(Await b c2 e, s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(Call p, s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(DynCom c,s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(Throw,s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(Catch c1 c2,s)#u#xs) \\<in> cptn_mod_nest_call\"\n\ninductive_cases stepc_elim_cases_Seq_Seq':\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Seq c1 c2,s) \\<rightarrow> (Seq c1' c2',s')\" \n\ninductive_cases stepc_elim_cases_Catch_Catch':\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,s) \\<rightarrow> (Catch c1' c2',s')\" \n\ninductive_cases CptnModNest_same_elim_cases [cases set]:\n\"(n,\\<Gamma>,(u, s)#(u,t)#xs) \\<in> cptn_mod_nest_call\"\n\ninductive_cases  CptnModNest_elim_cases_Call_Skip [cases set]:\n\"(n,\\<Gamma>,(Call p, s)#(Skip, s)#xs) \\<in> cptn_mod_nest_call\"\n\ninductive_cases  CptnModNest_elim_cases_Call_Stuck [cases set]:\n\"(n,\\<Gamma>,(Call p, s)#(Stuck, s)#xs) \\<in> cptn_mod_nest_call\"\n\ninductive_cases  CptnModNest_elim_cases_Call_Fault [cases set]:\n\"(n,\\<Gamma>,(Call p, s)#(Fault f, s)#xs) \\<in> cptn_mod_nest_call\"\n\ninductive_cases  CptnModNest_elim_cases_Call_Throw [cases set]:\n\"(n,\\<Gamma>,(Call p, s)#(Throw, s)#xs) \\<in> cptn_mod_nest_call\"\n\ninductive_cases  CptnModNest_elim_cases_Call [cases set]:\n\"(0, \\<Gamma>,((Call p),  s)#(bdy,  s)#ys) \\<in> cptn_mod_nest_call\"\n\ninductive_cases  CptnEmpty [cases set]:\n\"(n, \\<Gamma>,[]) \\<in> cptn_mod_nest_call\"\n\ninductive_cases  CptnModNest_elim_cases_Call_normal [cases set]:\n\"(Suc n, \\<Gamma>,((Call p),  s)#(bdy,  s)#ys) \\<in> cptn_mod_nest_call\"\n\nlemma cptn_mod_nest_mono1: \"(n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call  \\<Longrightarrow> (Suc n,\\<Gamma>,cfs)\\<in> cptn_mod_nest_call\"\nproof (induct rule:cptn_mod_nest_call.induct)\n  case (CptnModNestOne) thus ?case using cptn_mod_nest_call.CptnModNestOne by blast\nnext\n  case (CptnModNestEnv) thus ?case using cptn_mod_nest_call.CptnModNestEnv by blast\nnext\n   case (CptnModNestSkip) thus ?case using cptn_mod_nest_call.CptnModNestSkip by blast\nnext\n  case (CptnModNestThrow) thus ?case using cptn_mod_nest_call.intros(4) by blast\nnext\n  case (CptnModNestFault) thus ?case using cptn_mod_nest_call.intros(6) by fast\nnext\n  case (CptnModNestStuck) thus ?case using cptn_mod_nest_call.intros(5) by fast\nnext\n   case (CptnModNestCondT n) thus ?case \n     using cptn_mod_nest_call.CptnModNestCondT[of \"Suc n\"] by blast\nnext\n  case (CptnModNestCondF n) thus ?case \n    using cptn_mod_nest_call.CptnModNestCondF[of \"Suc n\"] by blast\nnext\n  case (CptnModNestSeq1 n) thus ?case \n    using cptn_mod_nest_call.CptnModNestSeq1[of \"Suc n\"] by blast\nnext\n  case (CptnModNestSeq2 n) thus ?case \n     using cptn_mod_nest_call.CptnModNestSeq2[of \"Suc n\"] by blast\nnext\n  case (CptnModNestSeq3 n) thus ?case \n     using cptn_mod_nest_call.CptnModNestSeq3[of \"Suc n\"]by fast\nnext\n  case (CptnModNestWhile1 n) thus ?case \n     using cptn_mod_nest_call.CptnModNestWhile1[of \"Suc n\"] by blast\nnext\n  case (CptnModNestWhile2 n) thus ?case \n     using cptn_mod_nest_call.CptnModNestWhile2[of \"Suc n\"] by blast\nnext\n  case (CptnModNestWhile3 n \\<Gamma> P s xs t f b s' ys zs) thus ?case \n     using cptn_mod_nest_call.CptnModNestWhile3[of \"Suc n\" \\<Gamma>] by blast\nnext\n case (CptnModNestCall) thus ?case \n     using cptn_mod_nest_call.CptnModNestCall by fastforce\nnext \n case (CptnModNestDynCom) thus ?case \n     using cptn_mod_nest_call.CptnModNestDynCom by blast\nnext\n case (CptnModNestGuard n) thus ?case \n     using cptn_mod_nest_call.CptnModNestGuard[of \"Suc n\"] by fastforce\nnext\n case (CptnModNestCatch1 n) thus ?case \n     using cptn_mod_nest_call.CptnModNestCatch1[of \"Suc n\"] by fastforce\nnext\n case (CptnModNestCatch2 n) thus ?case \n     using cptn_mod_nest_call.CptnModNestCatch2[of \"Suc n\"] by fast\nnext\n case (CptnModNestCatch3 n) thus ?case \n     using cptn_mod_nest_call.CptnModNestCatch3[of \"Suc n\"] by fast\nqed\n\nlemma cptn_mod_nest_mono2: \n  \"(n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call  \\<Longrightarrow> m>n \\<Longrightarrow>\n   (m,\\<Gamma>,cfs)\\<in> cptn_mod_nest_call\"\nproof (induct \"m-n\" arbitrary: m n)\n  case 0 thus ?case by auto\nnext\n  case (Suc k) \n  have \"m - Suc n = k\"\n    using Suc.hyps(2) Suc.prems(2) Suc_diff_Suc Suc_inject by presburger\n  then show ?case\n    using Suc.hyps(1) Suc.prems(1) Suc.prems(2) cptn_mod_nest_mono1 less_Suc_eq by blast   \nqed\n\nlemma cptn_mod_nest_mono: \n  \"(n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call  \\<Longrightarrow> m\\<ge>n \\<Longrightarrow>\n   (m,\\<Gamma>,cfs)\\<in> cptn_mod_nest_call\"\nproof (cases \"n=m\")\n  assume \"(n, \\<Gamma>, cfs) \\<in> cptn_mod_nest_call\" and  \n          \"n = m\"  thus ?thesis by auto\nnext\n  assume \"(n, \\<Gamma>, cfs) \\<in> cptn_mod_nest_call\" and  \n         \"n\\<le>m\" and\n         \"n \\<noteq> m\"  \n   thus ?thesis by (auto simp add: cptn_mod_nest_mono2)\n qed\n\n\n\nsubsection \\<open>Equivalence of comp mod semantics and comp mod nested\\<close>\n\ndefinition catch_cond_nest\nwhere\n\"catch_cond_nest zs Q xs P s s'' s' \\<Gamma> n \\<equiv> (zs=(map (lift_catch Q) xs) \\<or>\n             ((fst(((P, s)#xs)!length xs)=Throw \\<and>\n               snd(last ((P, s)#xs)) =  s' \\<and> s= s''\\<and>\n               (\\<exists>ys. (n,\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod_nest_call \\<and> \n                zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n                (\\<exists>t. (fst(((P, s)#xs)!length xs)=t \\<and> (t=Skip \\<or> (\\<exists>f. t = Fault f) \\<or> t = Stuck) \\<and> \n                 (\\<exists>ys. (n,\\<Gamma>,(t,snd(last ((P, s)#xs)))#ys) \\<in> cptn_mod_nest_call \\<and>                   \n                 zs=(map (lift_catch Q) xs)@((t,snd(last ((P, s)#xs)))#ys)))))\n\"\n\nlemma div_catch_nest: assumes cptn_m:\"(n,\\<Gamma>,list) \\<in> cptn_mod_nest_call\"\nshows \"(\\<forall>s P Q zs. list=(Catch P Q, s)#zs \\<longrightarrow>\n       (\\<exists>xs s' s''. \n          (n, \\<Gamma>,(P, s)#xs) \\<in> cptn_mod_nest_call  \\<and> \n             catch_cond_nest zs Q xs P s s'' s' \\<Gamma> n))  \n            \"\nunfolding catch_cond_nest_def\nusing cptn_m\nproof (induct rule: cptn_mod_nest_call.induct)\ncase (CptnModNestOne \\<Gamma> P s)\n  thus ?case using cptn_mod_nest_call.CptnModNestOne by blast \nnext\n  case (CptnModNestSkip  \\<Gamma> P s t n xs) \n  from CptnModNestSkip.hyps\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, toSeq s) \\<rightarrow> (Skip, toSeq t)\" by auto\n  from CptnModNestSkip.hyps\n  have noskip: \"~(P=Skip)\" using stepc_elim_cases(1) by auto  \n  have no_catch: \"\\<forall>p1 p2. \\<not>(P=Catch p1 p2)\" using CptnModNestSkip.hyps(2) redex_not_Catch by auto\n  from CptnModNestSkip.hyps\n  have in_cptn_mod: \"(n,\\<Gamma>, (Skip, t) # xs) \\<in> cptn_mod_nest_call\" by auto  \n  then show ?case using no_catch by simp\nnext\n  case (CptnModNestThrow  \\<Gamma> P s t n xs) \n  from CptnModNestThrow.hyps\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, toSeq s) \\<rightarrow> (Throw, toSeq t)\" by auto \n  from CptnModNestThrow.hyps\n  have in_cptn_mod: \"(n,\\<Gamma>, (Throw, t) # xs) \\<in> cptn_mod_nest_call\" by auto \n  have no_catch: \"\\<forall>p1 p2. \\<not>(P=Catch p1 p2)\" using CptnModNestThrow.hyps(2) redex_not_Catch by auto\n  then show ?case by auto\nnext\n  case (CptnModNestStuck  \\<Gamma> P s t n xs) \n  from CptnModNestStuck.hyps\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, toSeq s) \\<rightarrow> (Stuck, toSeq t)\" by auto \n  from CptnModNestStuck.hyps \n  have in_cptn_mod: \"(n,\\<Gamma>, (Stuck, t) # xs) \\<in> cptn_mod_nest_call\" by auto \n  have no_catch: \"\\<forall>p1 p2. \\<not>(P=Catch p1 p2)\" using CptnModNestStuck.hyps(2) redex_not_Catch by auto\n  then show ?case by auto\nnext\n  case (CptnModNestFault  \\<Gamma> P s f  t n xs) \n  from CptnModNestFault.hyps\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, toSeq s) \\<rightarrow> (Fault f, toSeq t)\" by auto \n  from CptnModNestFault.hyps\n  have in_cptn_mod: \"(n,\\<Gamma>, (Fault f, t) # xs) \\<in> cptn_mod_nest_call\" by auto \n  have no_catch: \"\\<forall>p1 p2. \\<not>(P=Catch p1 p2)\" using CptnModNestFault.hyps(2) redex_not_Catch by auto\n  then show ?case by auto\nnext\n  case (CptnModNestCondT \\<Gamma> P0 s ys b P1)\n  thus ?case using CptnModOne by blast\nnext\n  case (CptnModNestCondF \\<Gamma> P0 s ys b P1)\n  thus ?case using CptnModOne by blast\nnext\n  case (CptnModNestCatch1 sa P Q zs)\n  thus ?case by blast\nnext\n  case (CptnModNestCatch2 n \\<Gamma> P0 s xs t f ys zs P1) \n  from CptnModNestCatch2.hyps(3) \n  have last:\"fst (((P0, s) # xs) ! length xs) = t\" \n       by (simp add: last_length) \n  have P0cptn:\"(n,\\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call\" by fact          \n  then have \"zs = map (lift_catch P1) xs @((t,snd(last ((P0, s)#xs)))#ys)\" \n    by (simp add:CptnModNestCatch2.hyps)\n  show ?case\n  proof -{\n    fix sa P Q zsa    \n    assume eq:\"(Catch P0 P1, s) # zs = (Catch P Q, sa) # zsa\"\n    then have \"P0 =P \\<and> P1 = Q \\<and> s=sa \\<and> zs=zsa\" by auto\n    then have \"(P0, s) = (P, sa)\" by auto \n    have \"last ((P0, s) # xs) = ((P, sa) # xs) ! length xs\"\n      by (simp add: `P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa` last_length)\n    then have \"zs = (map (lift_catch Q) xs)@((t,snd(last ((P0, s)#xs)))#ys)\"\n      using `P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa` `zs = map (lift_catch P1) xs @ ((t,snd(last ((P0, s)#xs)))#ys)` \n      by force    \n    then have \"(\\<exists>xs s' s''. ((n,\\<Gamma>,(P, s)#xs) \\<in> cptn_mod_nest_call  \\<and> \n             ((zs=(map (lift_catch Q) xs) \\<or>\n             ((fst(((P, s)#xs)!length xs)=Throw \\<and>\n               snd(last ((P, s)#xs)) =  s' \\<and>  s= s''\\<and>\n               (\\<exists>ys. (n,\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod_nest_call \\<and> \n                zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n                (\\<exists>t. ((fst(((P, s)#xs)!length xs)=t \\<and> (t = LanguageCon.com.Skip \\<or> (\\<exists>f. t = com.Fault f) \\<or> t = com.Stuck) \\<and> \n               (\\<exists>ys. (n,\\<Gamma>,(t,snd(last ((P, s)#xs)))#ys) \\<in> cptn_mod_nest_call \\<and>                 \n                 zs=(map (lift_catch Q) xs)@((t,snd(last ((P0, s)#xs)))#ys)))))))))\"\n      using P0cptn  `P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa`  \n           last  CptnModNestCatch2.hyps(4,5) \n      by blast \n   } \n   thus ?thesis by blast\n  qed\nnext\n  case (CptnModNestCatch3 n \\<Gamma> P0 s xs s' P1 ys zs)\n  from CptnModNestCatch3.hyps(3)  \n  have last:\"fst (((P0,  s) # xs) ! length xs) = Throw\" \n    by (simp add: last_length) \n  from CptnModNestCatch3.hyps(4) \n  have lastnormal:\"snd (last ((P0,  s) # xs)) =  s'\"\n    by (simp add: last_length)\n  have P0cptn:\"(n,\\<Gamma>, (P0,  s) # xs) \\<in> cptn_mod_nest_call\" by fact\n  from CptnModNestCatch3.hyps(5) \n  have P1cptn:\"(n,\\<Gamma>, (P1, snd (((P0,  s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call\"\n      by (simp add: last_length)          \n  then have \"zs = map (lift_catch P1) xs @ (P1, snd (last ((P0,  s) # xs))) # ys\" \n    by (simp add:CptnModNestCatch3.hyps)\n  show ?case\n    by (metis CptnModNestCatch3.hyps(3) CptnModNestCatch3.hyps(5) CptnModNestCatch3.hyps(7)\n             LanguageCon.com.inject(10) P0cptn fst_conv last_length list.sel(3) nth_Cons_0 snd_conv)  \nnext\n  case (CptnModNestEnv \\<Gamma> P s t n xs)  \n  then have step:\"(n, \\<Gamma>, (P, t) # xs) \\<in> cptn_mod_nest_call\" by auto  \n  have step_e: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow>\\<^sub>e (P, t)\" using CptnModNestEnv by auto\n  show ?case     \n  proof (cases P)\n    case (Catch P1 P2) \n    then have eq_P_Catch:\"(P, t) # xs = (LanguageCon.com.Catch P1 P2, t) # xs\" by auto      \n    then  obtain xsa t' t'' where \n     p1:\"(n,\\<Gamma>, (P1, t) # xsa) \\<in> cptn_mod_nest_call\" and \n     p2:\" (xs = map (lift_catch P2) xsa \\<or>\n        fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \\<and>\n        snd (last ((P1, t) # xsa)) =  t' \\<and>\n        t =  t'' \\<and>\n        (\\<exists>ys. (n,\\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<in> cptn_mod_nest_call \\<and>\n          xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<or>\n            (\\<exists>c. fst (((P1, t) # xsa) ! length xsa) = c \\<and> (c = Skip \\<or> c = Stuck \\<or> (\\<exists>f. c = Fault f))\\<and>\n            (\\<exists>ys.(n,\\<Gamma>,(c,snd(last ((P1, t)#xsa)))#ys) \\<in> cptn_mod_nest_call \\<and> \n            xs = map (lift_catch P2) xsa @\n            ((c, snd (last ((P1, t) # xsa)))#ys))))\" \n    using CptnModNestEnv(3) by fastforce\n  have all_step:\"(n,\\<Gamma>, (P1, s)#((P1, t) # xsa)) \\<in> cptn_mod_nest_call\"\n  proof -\n    have \"\\<Gamma>\\<turnstile>\\<^sub>c (P1, s) \\<rightarrow>\\<^sub>e (P1, t)\"\n      using  step_e\n      by (metis env_intro_diff_p)\n    then show ?thesis\n      by (simp add: cptn_mod_nest_call.CptnModNestEnv p1)\n  qed\n  show ?thesis using p2 \n  proof  \n    assume \"xs = map (lift_catch P2) xsa\"\n    have \"(P, t) # xs = map (lift_catch P2) ((P1, t) # xsa)\"\n      by (simp add: `xs = map (lift_catch P2) xsa` lift_catch_def local.Catch)\n    thus ?thesis using all_step eq_P_Catch by fastforce\n  next \n    assume \n     \"fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \\<and>\n      snd (last ((P1, t) # xsa)) =  t' \\<and>\n      t =  t'' \\<and>\n      (\\<exists>ys. (n,\\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<in> cptn_mod_nest_call \\<and>\n        xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<or>\n        (\\<exists>c. fst (((P1, t) # xsa) ! length xsa) = c \\<and>  (c = Skip \\<or> c = Stuck \\<or> (\\<exists>f. c = Fault f)) \\<and> \n      (\\<exists>ys. (n,\\<Gamma>,(c,snd(last ((P1, t)#xsa)))#ys) \\<in> cptn_mod_nest_call \\<and> \n        xs = map (lift_catch P2) xsa @ ((c, snd (last ((P1, t) # xsa)))#ys)))\"      \n     then show ?thesis \n     proof\n       assume \n        a1:\"fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \\<and>\n         snd (last ((P1, t) # xsa)) =  t' \\<and> t =  t'' \\<and>\n         (\\<exists>ys. (n,\\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<in> cptn_mod_nest_call \\<and>\n            xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys)\"\n       then obtain ys where p2_exec:\n          \"(n,\\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<in> cptn_mod_nest_call \\<and>\n            xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys\" \n        by fastforce\n        from a1 obtain t1 where t_normal: \"t= t1\" \n          by blast\n        have f1:\"fst (((P1, s)#(P1, t) # xsa) ! length ((P1, t)#xsa)) = LanguageCon.com.Throw\"\n          using a1 by fastforce\n         from a1 have last_normal: \"snd (last ((P1, s)#(P1, t) # xsa)) =  t'\"\n           by fastforce \n         then have p2_long_exec: \n           \"(n,\\<Gamma>, (P2, snd (((P1, s)#(P1, t) # xsa) ! length ((P1, s)#xsa))) # ys) \\<in> \n                cptn_mod_nest_call \\<and>\n            (P, t)#xs = map (lift_catch P2) ((P1, t) # xsa) @\n                   (P2, snd (((P1, s)#(P1, t) # xsa) ! length ((P1, s)#xsa))) # ys\" \n           using p2_exec by (simp add: lift_catch_def local.Catch)                  \n         thus ?thesis using  a1 f1 last_normal all_step eq_P_Catch by fastforce                  \n     next\n       assume \n       as1:\n         \"\\<exists>c. fst (((P1, t) # xsa) ! length xsa) =c \\<and> (c = Skip \\<or> c = Stuck \\<or> (\\<exists>f. c = Fault f)) \\<and>\n             (\\<exists>ys. (n,\\<Gamma>,(c,snd(last ((P1, t)#xsa)))#ys) \\<in> cptn_mod_nest_call \\<and> \n             xs = map (lift_catch P2) xsa @ ((c, snd (last ((P1, t) # xsa)))#ys))\"   \n       then obtain c where \n         as1:\"fst (((P1, t) # xsa) ! length xsa) =c \\<and> (c = Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck ) \\<and>\n             (\\<exists>ys. (n,\\<Gamma>,(c,snd(last ((P1, t)#xsa)))#ys) \\<in> cptn_mod_nest_call \\<and> \n             xs = map (lift_catch P2) xsa @ ((c, snd (last ((P1, t) # xsa)))#ys))\"\n         by auto\n       then obtain ys where p1:\n         \"(n,\\<Gamma>,(c,snd(last ((P1, t)#xsa)))#ys) \\<in> cptn_mod_nest_call \\<and> \n          (P, t)#xs = map (lift_catch P2) ((P1, t) # xsa) @ ((c, snd (last ((P1, t) # xsa)))#ys)\"\n       proof -\n         assume a1: \"\\<And>ys. (n,\\<Gamma>, (c, snd (last ((P1, t) # xsa))) # ys) \\<in> cptn_mod_nest_call \\<and> \n                   (P, t) # xs = map (lift_catch P2) ((P1, t) # xsa) @ \n                   (c, snd (last ((P1, t) # xsa))) # ys \\<Longrightarrow> thesis\"\n         have \"(LanguageCon.com.Catch P1 P2, t) # map (lift_catch P2) xsa = \n                map (lift_catch P2) ((P1, t) # xsa)\"\n           by (simp add: lift_catch_def)\n         thus ?thesis\n           using a1 as1 eq_P_Catch as1 by auto \n       qed            \n       from as1 have p2: \"fst (((P1, s)#(P1, t) # xsa) ! length ((P1, t) #xsa)) =c\"\n         by fastforce                              \n       moreover have \" (c = Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck )\" using as1 by auto\n       ultimately show ?thesis using  p1 all_step eq_P_Catch by fastforce   \n      qed\n  qed\nqed (auto)\nqed(force+)\n\n\ndefinition seq_cond_nest\nwhere\n\"seq_cond_nest zs Q xs P s s'' s' \\<Gamma> n \\<equiv> \n   (zs=(map (lift Q) xs) \\<or>\n   ((fst(((P, s)#xs)!length xs)=Skip \\<and> \n     (\\<exists>ys. (n,\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod_nest_call \\<and> \n      zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n   (\\<exists>c. (fst(((P, s)#xs)!length xs)=c \\<and> (c = Throw \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and> \n        snd(last ((P, s)#xs)) =  s' \\<and>  s= s''\\<and>\n        (\\<exists>ys.  (n,\\<Gamma>,(c, s')#ys) \\<in> cptn_mod_nest_call \\<and> zs=(map (lift Q) xs)@((c, s')#ys)))))\"\n\nlemma Seq_P_Not_finish:\n assumes\n   a0:\"zs = map (lift Q) xs\" and\n   a1:\"(m, \\<Gamma>,(LanguageCon.com.Seq P Q, s) # zs) \\<in> cptn_mod_nest_call\" and\n   a2:\"seq_cond_nest zs Q xs' P s s'' s' \\<Gamma> m\" \nshows \"xs=xs'\"\nusing a2 unfolding seq_cond_nest_def \nproof\n  assume \"zs= map (lift Q) xs'\"\n  then have  \"map (lift Q) xs' = \n              map (lift Q) xs\" using a0 by auto \n  thus ?thesis using map_lift_eq_xs_xs' by fastforce\nnext\n  assume \n    ass:\"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n           zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<or>\n         (\\<exists>c. fst (((P, s) # xs') ! length xs') = c \\<and> (c = Throw \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n           snd (last ((P, s) # xs')) =  s' \\<and> s = s'' \\<and>\n           (\\<exists>ys. (m, \\<Gamma>, (c, s') # ys) \\<in> cptn_mod_nest_call \\<and> zs = map (lift Q) xs' @ (c, s') # ys))\"\n   {assume \n     ass:\"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \\<and>\n        (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)\"\n     then obtain ys where \n         zs:\"zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys\" \n       by auto \n     then have zs_while:\"fst (zs!(length (map (lift Q) xs'))) = Q\"  \n       by (metis fstI nth_append_length) \n     have \"length zs = length (map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)\" \n       using zs by auto\n     then have \"(length (map (lift Q) xs')) < length zs\" by auto       \n     then have ?thesis using a0 zs_while map_lift_all_seq\n       using seq_and_if_not_eq(4) by fastforce     \n   }note l = this\n   {assume ass:\n     \"\\<exists>c. fst (((P, s) # xs') ! length xs') = c \\<and> (c = Throw \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n         snd (last ((P, s) # xs')) =  s' \\<and> s =  s'' \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (c, s') # ys) \\<in> cptn_mod_nest_call \\<and> zs = map (lift Q) xs' @ (c,  s') # ys)\"\n     then obtain c ys where zs:\n       \"zs = map (lift Q) xs' @ (c,  s') # ys \\<and> (c = Throw \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck)\" by auto\n     then have zs_while:\n       \"fst (zs!(length (map (lift Q) xs'))) = c\"  by (metis fstI nth_append_length) \n     have \"length zs = length (map (lift Q) xs' @(c,  s') # ys)\" \n       using zs by auto\n     then have \"(length (map (lift Q) xs')) < length zs\" by auto       \n     then have ?thesis using a0 zs_while map_lift_all_seq        \n       by (metis LanguageCon.com.distinct(79) LanguageCon.com.distinct(85) \n           LanguageCon.com.distinct(87) zs)  \n   } thus ?thesis using l ass by auto\nqed\n\nlemma Seq_P_Ends_Normal:\n assumes\n   a0:\"zs = map (lift Q) xs @ (Q, snd (last ((P, s) # xs))) # ys\" and\n   a0':\"fst (last ((P, s) # xs)) = Skip\" and\n   a1:\"(m, \\<Gamma>,(LanguageCon.com.Seq P Q, s) # zs) \\<in> cptn_mod_nest_call\" and\n   a2:\"seq_cond_nest zs Q xs' P s s'' s' \\<Gamma> m\" \nshows \"xs=xs' \\<and> (m,\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod_nest_call\"\nusing a2 unfolding seq_cond_nest_def \nproof\n  assume ass:\"zs= map (lift Q) xs'\"\n  then have  \"map (lift Q) xs' = \n              map (lift Q) xs @ (Q, snd (last ((P, s) # xs))) # ys\" using a0 by auto \n  then have zs_while:\"fst (zs!(length (map (lift Q) xs))) = Q\"  \n    by (metis a0 fstI nth_append_length) \n  also have \"length zs = \n             length (map (lift Q) xs @ (Q, snd (last ((P, s) # xs))) # ys)\" \n    using a0 by auto\n  then have \"(length (map (lift Q) xs)) < length zs\" by auto       \n  then show ?thesis using ass zs_while map_lift_all_seq\n           using seq_and_if_not_eq(4)\n  by metis   \nnext\n  assume \n    ass:\"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n           zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<or>\n         (\\<exists>c. fst (((P, s) # xs') ! length xs') =c \\<and> (c = Throw \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n           snd (last ((P, s) # xs')) =  s' \\<and> s =  s'' \\<and>\n           (\\<exists>ys. (m, \\<Gamma>, (c,  s') # ys) \\<in> cptn_mod_nest_call \\<and>\n           zs = map (lift Q) xs' @ (c,  s') # ys))\"\n   {assume \n     ass:\"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \\<and>\n        (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)\"\n     then obtain ys' where zs:\n       \"zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys' \\<and>\n        (m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys') \\<in> cptn_mod_nest_call\" \n       by auto \n     then have ?thesis \n       using  map_lift_some_eq[of Q xs Q _ ys xs' Q _ ys'] a0 seq_and_if_not_eq(4)[of Q] \n       by fast               \n   }note l = this\n   {assume ass:\n      \"\\<exists>c. fst (((P, s) # xs') ! length xs') = c \\<and> (c = Throw \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n         snd (last ((P, s) # xs')) =  s' \\<and> s = s'' \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (c,  s') # ys) \\<in> cptn_mod_nest_call \\<and> zs = map (lift Q) xs' @ (c,  s') # ys)\"             \n     then have \"xs =xs'\" \n        using  a0 a0'  map_lift_some_eq seq_and_if_not_eq(4)\n        by (metis (no_types) LanguageCon.com.distinct(79) LanguageCon.com.distinct(85) \n           LanguageCon.com.distinct(87))\n      then have False  using  a0' ass\n        by (metis LanguageCon.com.distinct(13) \n          LanguageCon.com.distinct(19) LanguageCon.com.distinct(21) last_length)\n      then have ?thesis by auto\n   } thus ?thesis using l ass by auto\nqed\n\nlemma Seq_P_Ends_Abort:\n assumes\n   a0:\"zs = map (lift Q) xs @ (c,  s') # ys\" and an:\"c =  Throw \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck\" and\n   a0':\"fst (last ((P,  s) # xs)) = c\" and\n   a0'':\"snd(last ((P,  s) # xs)) = s'\" and\n   a1:\"(m, \\<Gamma>,(LanguageCon.com.Seq P Q,  s) # zs) \\<in> cptn_mod_nest_call\" and\n   a2:\"seq_cond_nest zs Q xs' P s ns'' ns' \\<Gamma> m\" \nshows \"xs=xs' \\<and> (m,\\<Gamma>,(c, s')#ys) \\<in> cptn_mod_nest_call\"\nusing a2 unfolding seq_cond_nest_def \nproof\n  assume ass:\"zs= map (lift Q) xs'\"\n  then have  \"map (lift Q) xs' = \n              map (lift Q) xs @ (c,  s') # ys\" using a0 by auto \n  then have zs_while:\"fst (zs!(length (map (lift Q) xs))) = c\"  \n    by (metis a0  fstI nth_append_length) \n  also have \"length zs = \n             length (map (lift Q) xs @ (c,  s') # ys)\" \n    using a0 by auto\n  then have \"(length (map (lift Q) xs)) < length zs\" by auto       \n  then show ?thesis using ass zs_while map_lift_all_seq  an\n    by (metis LanguageCon.com.distinct(79) LanguageCon.com.distinct(85) LanguageCon.com.simps(99))\nnext\n  assume \n    ass:\"fst (((P,  s) # xs') ! length xs') = LanguageCon.com.Skip \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P,  s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift Q) xs' @ (Q, snd (((P,  s) # xs') ! length xs')) # ys) \\<or>\n         (\\<exists>c. fst (((P,  s) # xs') ! length xs') = c \\<and> (c = Throw \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n         snd (last ((P,  s) # xs')) =  ns' \\<and> s =  ns'' \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (c,  ns') # ys) \\<in> cptn_mod_nest_call \\<and> zs = map (lift Q) xs' @ (c,  ns') # ys))\"\n   {assume \n     ass:\"fst (((P,  s) # xs') ! length xs') = LanguageCon.com.Skip \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P,  s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift Q) xs' @ (Q, snd (((P,  s) # xs') ! length xs')) # ys)\"\n      then obtain ys' where \n         zs:\" (m, \\<Gamma>, (Q, snd (((P,  s) # xs') ! length xs')) # ys') \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift Q) xs' @ (Q, snd (((P,  s) # xs') ! length xs')) # ys'\" \n        by auto \n      then have \"xs = xs'\" and \"ys = ys'\"\n        using a0 a0' seq_and_if_not_eq(4)[of Q]   ass map_lift_some_eq\n        by (metis LanguageCon.com.distinct(79) \n                LanguageCon.com.distinct(85) LanguageCon.com.distinct(87) an)+      \n      then have ?thesis\n        using a0 ass by blast                        \n   }note l = this\n   {assume ass:\"\\<exists>c. fst (((P,  s) # xs') ! length xs') = c \\<and> (c = Throw \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n         snd (last ((P,  s) # xs')) =  ns' \\<and> s =  ns'' \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (c,  ns') # ys) \\<in> cptn_mod_nest_call \\<and> zs = map (lift Q) xs' @ (c,  ns') # ys)\"\n     then obtain c1 where  \n        ass:\"fst (((P,  s) # xs') ! length xs') = c1 \\<and> (c1 = Throw \\<or> (\\<exists>f. c1 = Fault f) \\<or> c1 = Stuck) \\<and>\n         snd (last ((P,  s) # xs')) =  ns' \\<and> s =  ns'' \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (c1,  ns') # ys) \\<in> cptn_mod_nest_call \\<and> zs = map (lift Q) xs' @ (c1,  ns') # ys)\"\n       by auto\n      then obtain ys' where \n         zs:\"(m, \\<Gamma>, (c1,  ns') # ys') \\<in> cptn_mod_nest_call \\<and>\n            zs = map (lift Q) xs' @ (c1,  ns') # ys'\" \n         by auto\n      then have zs_while:\n          \"fst (zs!(length (map (lift Q) xs'))) = c1\"  \n        by (metis fstI nth_append_length)       \n      then have \"xs=xs' \\<and> ys = ys'\" \n        using a0 zs map_lift_some_eq[of Q xs c s' ys xs' c1 ns' ys'] an ass\n        by (metis LanguageCon.com.distinct(79) \n              LanguageCon.com.distinct(85) LanguageCon.com.distinct(87))        \n      then have ?thesis using a0 ass map_lift_some_eq an  by blast        \n   } thus ?thesis using l ass by auto\n qed\n\n\nlemma Catch_P_Not_finish:\n assumes\n   a0:\"zs = map (lift_catch Q) xs\" and   \n   a1:\"catch_cond_nest zs Q xs' P s s'' s' \\<Gamma> m\" \nshows \"xs=xs'\"\nusing a1 unfolding catch_cond_nest_def \nproof\n  assume \"zs= map (lift_catch Q) xs'\"\n  then have  \"map (lift_catch Q) xs' = \n              map (lift_catch Q) xs\" using a0 by auto \n  thus ?thesis using map_lift_catch_eq_xs_xs' by fastforce\nnext\n  assume \n    ass:\"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n           snd (last ((P, s) # xs')) =  s' \\<and> s =  s'' \\<and>\n           (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n           zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<or>\n         (\\<exists>c. fst (((P, s) # xs') ! length xs') = c \\<and> (c = Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n           (\\<exists>ys. (m, \\<Gamma>, (c, snd (last ((P, s) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n           zs = map (lift_catch Q) xs' @ (c, snd (last ((P, s) # xs'))) # ys))\"\n   {assume \n     ass:\"\\<exists>c. fst (((P, s) # xs') ! length xs') = c \\<and> (c = Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (c, snd (last ((P, s) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift_catch Q) xs' @ (c, snd (last ((P, s) # xs'))) # ys)\"\n     then obtain c where ass:\n        \"fst (((P, s) # xs') ! length xs') = c \\<and> (c = Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (c, snd (last ((P, s) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift_catch Q) xs' @ (c, snd (last ((P, s) # xs'))) # ys)\"\n       by auto\n      then obtain ys where \n         zs:\"(m, \\<Gamma>, (c, snd (last ((P, s) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n            zs = map (lift_catch Q) xs' @ (c, snd (last ((P, s) # xs'))) # ys\" \n             by auto \n      then have zs_while:\"fst (zs!(length (map (lift_catch Q) xs'))) = c \"  \n        by (metis fstI nth_append_length) \n      have \"length zs = length (map (lift Q) xs' @\n         (Q, snd (((P, s) # xs') ! length xs')) # ys)\" \n          using zs by auto\n      then have \"(length (map (lift Q) xs')) < length zs\" by auto       \n      then have ?thesis using a0 zs_while map_lift_catch_all_catch ass         \n         by (metis com.distinct(149) com.distinct(173) com.distinct(23) length_map) \n   }note l = this\n   {assume ass:\"fst (((P, s) # xs') ! length xs') =Throw \\<and>\n         snd (last ((P, s) # xs')) =  s' \\<and> s =  s'' \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)\"\n      then obtain ys where \n            zs:\"zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys\" by auto\n      then have zs_while:\n        \"fst (zs!(length (map (lift Q) xs'))) = Q\"\n         by (metis (no_types) eq_fst_iff length_map nth_append_length zs) \n       have \"length zs = length (map (lift Q) xs' @(LanguageCon.com.Throw, s') # ys)\" \n           using zs by auto\n       then have \"(length (map (lift Q) xs')) < \n                  length zs\" by auto       \n       then have ?thesis using a0 zs_while map_lift_catch_all_catch\n         by fastforce\n   } thus ?thesis using l ass by auto\nqed\n\nlemma Catch_P_Ends_Normal:\n assumes\n   a0:\"zs = map (lift_catch Q) xs @ (Q, snd (last ((P,  s) # xs))) # ys\" and\n   a0':\"fst (last ((P,  s) # xs)) = Throw\" and\n   a1:\"catch_cond_nest zs Q xs' P ( s) s'' s' \\<Gamma> m\" \nshows \"xs=xs' \\<and> (m,\\<Gamma>,(Q, snd(((P,  s)#xs)!length xs))#ys) \\<in> cptn_mod_nest_call\"\nusing a1 unfolding catch_cond_nest_def \nproof\n  assume ass:\"zs= map (lift_catch Q) xs'\"\n  then have  \"map (lift_catch Q) xs' = \n              map (lift_catch Q) xs @ (Q, snd (last ((P,  s) # xs))) # ys\" \n    using a0 by auto \n  then have zs_while:\"fst (zs!(length (map (lift_catch Q) xs))) = Q\"\n    by (metis a0 fstI nth_append_length)      \n  also have \"length zs =  length (map (lift_catch Q) xs @ (Q, snd (last ((P,  s) # xs))) # ys)\" \n    using a0 by auto\n  then have \"(length (map (lift_catch Q) xs)) < length zs\" by auto       \n  then show ?thesis using ass zs_while map_lift_catch_all_catch\n           using seq_and_if_not_eq(12)\n  by metis\nnext \n  assume ass: \"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n           snd (last ((P, s) # xs')) =  s' \\<and> s =  s'' \\<and>\n           (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n           zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<or>\n         (\\<exists>c. fst (((P, s) # xs') ! length xs') = c \\<and> (c = Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n           (\\<exists>ys. (m, \\<Gamma>, (c, snd (last ((P, s) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n           zs = map (lift_catch Q) xs' @ (c, snd (last ((P, s) # xs'))) # ys))\" \n    (* ass:\"fst (((P, Normal s) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n         snd (last ((P, Normal s) # xs')) =  ns' \\<and>\n          s =  ns'' \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, Normal s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift_catch Q) xs' @ (Q, snd (((P, Normal s) # xs') ! length xs')) # ys) \\<or>\n         fst (((P, Normal s) # xs') ! length xs') = LanguageCon.com.Skip \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (LanguageCon.com.Skip, snd (last ((P, Normal s) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift_catch Q) xs' @ (LanguageCon.com.Skip, snd (last ((P, Normal s) # xs'))) # ys)\" *)\n   {assume \n     ass:\"(\\<exists>c. fst (((P, s) # xs') ! length xs') = c \\<and> (c = Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n           (\\<exists>ys. (m, \\<Gamma>, (c, snd (last ((P, s) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n           zs = map (lift_catch Q) xs' @ (c, snd (last ((P, s) # xs'))) # ys))\" \n     then obtain c where ass:\"fst (((P, s) # xs') ! length xs') = c \\<and> (c = Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n           (\\<exists>ys. (m, \\<Gamma>, (c, snd (last ((P, s) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n           zs = map (lift_catch Q) xs' @ (c, snd (last ((P, s) # xs'))) # ys)\"\n       by auto\n     then obtain ys' where \n         zs:\"(m, \\<Gamma>, (c, snd (last ((P,  s) # xs'))) # ys') \\<in> cptn_mod_nest_call \\<and>\n             zs = map (lift_catch Q) xs' @ (c, snd (last ((P,  s) # xs'))) # ys'\"              \n       by auto\n      then have ?thesis\n        using  map_lift_catch_some_eq[of Q xs Q _ ys xs' c _ ys'] \n               zs  a0 seq_and_if_not_eq(12)[of Q] a0' ass\n        by (metis com.distinct(147)  com.distinct(149) com.distinct(171) com.distinct(173) \n                  com.distinct(21) com.distinct(23) last_length)                        \n   }note l = this\n   {assume ass:\"fst (((P,  s) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n                snd (last ((P,  s) # xs')) =  s' \\<and> s =  s'' \\<and>\n                (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P,  s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n                zs = map (lift_catch Q) xs' @ (Q, snd (((P,  s) # xs') ! length xs')) # ys)\"\n      then obtain ys' where \n         zs:\"(m, \\<Gamma>, (Q, snd (((P,  s) # xs') ! length xs')) # ys') \\<in> cptn_mod_nest_call \\<and>\n                zs = map (lift_catch Q) xs' @ (Q, snd (((P,  s) # xs') ! length xs')) # ys'\" \n         by auto\n      then have zs_while:\n          \"fst (zs!(length (map (lift_catch Q) xs'))) = Q\"  by (metis fstI nth_append_length)       \n\n      then have ?thesis \n        using LanguageCon.com.distinct(17) LanguageCon.com.distinct(71) \n            a0 a0' ass last_length map_lift_catch_some_eq[of Q xs Q _ ys xs' Q _ ys']  \n            seq_and_if_not_eq(12) zs\n        by blast        \n   } thus ?thesis using l ass by auto\n qed\n\nlemma Catch_P_Ends_Skip:\n assumes\n   a0:\"zs = map (lift_catch Q) xs @ (c, snd (last ((P, s) # xs))) # ys\" and\n   a0':\"fst (last ((P,s) # xs)) = c\" and an:\"c = Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck\" and\n   a1:\"catch_cond_nest zs Q xs' P s s'' s' \\<Gamma> m\" \nshows \"xs=xs' \\<and> (m,\\<Gamma>,(c,snd(last ((P,s) # xs)))#ys) \\<in> cptn_mod_nest_call\"\nusing a1 unfolding catch_cond_nest_def \nproof\n  assume ass:\"zs= map (lift_catch Q) xs'\"\n  then have  \"map (lift_catch Q) xs' = \n              map (lift_catch Q) xs @ (c, snd (last ((P, s) # xs))) # ys\" using a0 by auto \n  then have zs_while:\"fst (zs!(length (map (lift_catch Q) xs))) = c\"  \n    by (metis a0  fstI nth_append_length) \n  also have \"length zs = \n             length (map (lift_catch Q) xs @ (c, snd (last ((P, s) # xs))) # ys)\" \n    using a0 by auto\n  then have \"(length (map (lift_catch Q) xs)) < length zs\" by auto       \n  then show ?thesis using ass zs_while map_lift_catch_all_catch an\n    by (metis com.distinct(149) com.distinct(173) com.distinct(23))    \nnext   \n    assume ass: \"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n           snd (last ((P, s) # xs')) =  s' \\<and> s =  s'' \\<and>\n           (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n           zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<or>\n         (\\<exists>c. fst (((P, s) # xs') ! length xs') = c \\<and> (c = Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n           (\\<exists>ys. (m, \\<Gamma>, (c, snd (last ((P, s) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n           zs = map (lift_catch Q) xs' @ (c, snd (last ((P, s) # xs'))) # ys))\"\n   {assume \n     ass:\"\\<exists>c. fst (((P, s) # xs') ! length xs') = c \\<and> (c = Skip \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n           (\\<exists>ys. (m, \\<Gamma>, (c, snd (last ((P, s) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n           zs = map (lift_catch Q) xs' @ (c, snd (last ((P, s) # xs'))) # ys)\"\n     then obtain c1 where ass: \"fst (((P, s) # xs') ! length xs') = c1 \\<and> (c1 = Skip \\<or> (\\<exists>f. c1 = Fault f) \\<or> c1 = Stuck) \\<and>\n           (\\<exists>ys. (m, \\<Gamma>, (c1, snd (last ((P, s) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n           zs = map (lift_catch Q) xs' @ (c1, snd (last ((P, s) # xs'))) # ys)\"\n       by auto\n     then obtain ys' where \n         zs:\"(m, \\<Gamma>, (c1, snd (last ((P, s) # xs'))) # ys') \\<in> cptn_mod_nest_call \\<and>\n           zs = map (lift_catch Q) xs' @ (c1, snd (last ((P, s) # xs'))) # ys'\" \n       by auto \n     then have \"xs = xs' \\<and> ys = ys'\" using map_lift_catch_some_eq \n       by (metis com.distinct(149) com.distinct(173) com.distinct(23) a0 an ass)\n     then have ?thesis\n       by (metis a0' ass last_length zs)                    \n   }note l = this\n   {assume ass:\"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n         snd (last ((P, s) # xs')) = s' \\<and> s = s'' \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)\"\n      then obtain ys' where \n         zs:\"(m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys') \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys'\" \n         by auto\n      then have zs_while:\n          \"fst (zs!(length (map (lift_catch Q) xs'))) = Q\"  \n        by (metis fstI nth_append_length)     \n      then have \"xs = xs' \\<and> ys = ys'\" \n        using map_lift_catch_some_eq a0 zs a0' ass \n        by (metis com.distinct(149) com.distinct(173) com.distinct(23) an seq_and_if_not_eq(12))  \n      then have ?thesis        \n        using a0 zs by auto      \n   } thus ?thesis using l ass by fast\nqed\n\n\nlemma div_seq_nest: \n  assumes cptn_m:\"(n,\\<Gamma>,list) \\<in> cptn_mod_nest_call\"\n  shows \"(\\<forall>s P Q zs. list=(Seq P Q, s)#zs \\<longrightarrow>\n       (\\<exists>xs s' s''. \n          (n,\\<Gamma>,(P, s)#xs) \\<in> cptn_mod_nest_call  \\<and> \n             seq_cond_nest zs Q xs P s s'' s' \\<Gamma> n))\"\nunfolding seq_cond_nest_def\nusing cptn_m\nproof (induct rule: cptn_mod_nest_call.induct)\n  case (CptnModNestOne \\<Gamma> P s)\n  thus ?case using cptn_mod_nest_call.CptnModNestOne \n   by blast\nnext\n  case (CptnModNestSkip  \\<Gamma> P s t n xs) \n  from CptnModNestSkip.hyps\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, toSeq s) \\<rightarrow> (Skip, toSeq t)\" by auto\n  from CptnModNestSkip.hyps\n  have noskip: \"~(P=Skip)\" using stepc_elim_cases(1)\n     by auto\n  have x: \"\\<forall>c c1 c2. redex c = Seq c1 c2 \\<Longrightarrow> False\"\n          using redex_not_Seq by blast\n  from CptnModNestSkip.hyps\n  have in_cptn_mod: \"(n,\\<Gamma>, (Skip, t) # xs) \\<in> cptn_mod_nest_call\" by auto  \n  then show ?case using CptnModNestSkip.hyps(2) SmallStepCon.redex_not_Seq by blast\nnext\n  case (CptnModNestThrow  \\<Gamma> P s t xs)\n  from CptnModNestThrow.hyps\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, toSeq s) \\<rightarrow> (Throw, toSeq t)\" by auto \n  moreover from CptnModNestThrow.hyps \n  have no_seq: \"\\<forall>p1 p2. \\<not>(P=Seq p1 p2)\" using CptnModNestThrow.hyps(2) redex_not_Seq by auto\n  ultimately show ?case by auto   \nnext \n case (CptnModNestFault  \\<Gamma> P s f t n xs)\n  from CptnModNestFault.hyps\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, toSeq s) \\<rightarrow> (Fault f, toSeq t)\" by auto \n  moreover from CptnModNestFault.hyps \n  have no_seq: \"\\<forall>p1 p2. \\<not>(P=Seq p1 p2)\" using CptnModNestFault.hyps(2) redex_not_Seq by auto\n  ultimately show ?case by auto  \nnext\n  case (CptnModNestStuck  \\<Gamma> P s t xs)\n  from CptnModNestStuck.hyps\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, toSeq s) \\<rightarrow> (Stuck, toSeq t)\" by auto \n  moreover from CptnModNestStuck.hyps \n  have no_seq: \"\\<forall>p1 p2. \\<not>(P=Seq p1 p2)\" using CptnModNestStuck.hyps(2) redex_not_Seq by auto\n  ultimately show ?case by auto\nnext \n  case (CptnModNestCondT \\<Gamma> P0 s ys b P1)\n  thus ?case by auto\nnext\n  case (CptnModNestCondF \\<Gamma> P0 s ys b P1)\n  thus ?case by auto\nnext\n  case (CptnModNestSeq1 n \\<Gamma> P0 s xs zs P1) thus ?case \n    by blast   \nnext \n  case (CptnModNestSeq2 n \\<Gamma> P0 s xs P1 ys zs) \n  from CptnModNestSeq2.hyps(3) last_length have last:\"fst (((P0, s) # xs) ! length xs) = Skip\" \n       by (simp add: last_length) \n  have P0cptn:\"(n,\\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call\" by fact\n  from CptnModNestSeq2.hyps(4) \n  have P1cptn:\"(n,\\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call\"\n      by (simp add: last_length)          \n    then have \"zs = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys\" \n      by (simp add:CptnModNestSeq2.hyps)\n  show ?case\n    by (metis CptnModNestSeq2.hyps(3) CptnModNestSeq2.hyps(4) CptnModNestSeq2.hyps(6) \n              LanguageCon.com.inject(3) P0cptn fst_conv last_length list.inject snd_conv)   \nnext\n  case (CptnModNestSeq3 n \\<Gamma> P0 s xs t f s' ys zs P1) \n  from CptnModNestSeq3.hyps(3) \n  have last:\"fst (((P0,  s) # xs) ! length xs) = t\" \n       by (simp add: last_length) \n  have P0cptn:\"(n,\\<Gamma>, (P0,  s) # xs) \\<in> cptn_mod_nest_call\" by fact\n  from CptnModNestSeq3.hyps(5) \n  have lastnormal:\"snd (last ((P0,  s) # xs)) =  s'\"\n      by (simp add: last_length)          \n  then have \"zs = map (lift P1) xs @ ((t,  s')#ys)\" by (simp add:CptnModNestSeq3.hyps)\n  show ?case\n    by (metis  CptnModNestSeq3.hyps(3) CptnModNestSeq3.hyps(4) CptnModNestSeq3.hyps(6) CptnModNestSeq3.hyps(8)\n       LanguageCon.com.inject(3) P0cptn \n      fst_conv last_length lastnormal list.inject snd_conv)         \nnext \n  case (CptnModNestEnv  \\<Gamma> P s t n zs) \n  then have step:\"(n,\\<Gamma>, (P, t) # zs) \\<in> cptn_mod_nest_call\" by auto\n  have step_e: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow>\\<^sub>e (P, t)\" using CptnModNestEnv by auto  \n  show ?case     \n    proof (cases P)\n      case (Seq P1 P2) \n      then have eq_P:\"(P, t) # zs = (LanguageCon.com.Seq P1 P2, t) # zs\" by auto      \n      then  obtain xs t' t'' where \n         p1:\"(n,\\<Gamma>, (P1, t) # xs) \\<in> cptn_mod_nest_call\" and \n         p2:\"(zs = map (lift P2) xs \\<or>\n             fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \\<and>      \n               (\\<exists>ys. (n,\\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n               zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<or>\n             (\\<exists>c. fst (((P1, t) # xs) ! length xs) =c \\<and> (c = Throw \\<or> (\\<exists>f. Fault f = c) \\<or> c = Stuck) \\<and>\n               snd (last ((P1, t) # xs)) =  t' \\<and> t =  t'' \\<and> \n               (\\<exists>ys. (n,\\<Gamma>,(c, t')#ys) \\<in> cptn_mod_nest_call \\<and> zs = map (lift P2) xs @ ((c,  t')#ys)))) \" \n        using CptnModNestEnv(3) by fastforce\n      have all_step:\"(n,\\<Gamma>, (P1, s)#((P1, t) # xs)) \\<in> cptn_mod_nest_call\" \n        using p1 cptn_mod_nest_call.CptnModNestEnv step_e\n        using env_intro_diff_p by blast\n      show ?thesis using p2 \n      proof  \n        assume \"zs = map (lift P2) xs\"\n        have \"(P, t) # zs = map (lift P2) ((P1, t) # xs)\"\n          by (simp add: `zs = map (lift P2) xs` lift_def local.Seq)\n        thus ?thesis using all_step eq_P by fastforce\n      next \n        assume \n         \"fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \\<and>      \n               (\\<exists>ys. (n,\\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n               zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<or>\n             (\\<exists>c. fst (((P1, t) # xs) ! length xs) =c \\<and> (c = Throw \\<or> (\\<exists>f. Fault f = c) \\<or> c = Stuck) \\<and>\n               snd (last ((P1, t) # xs)) =  t' \\<and> t =  t'' \\<and> \n               (\\<exists>ys. (n,\\<Gamma>,(c, t')#ys) \\<in> cptn_mod_nest_call \\<and> zs = map (lift P2) xs @ ((c,  t')#ys)))\"\n         then show ?thesis \n         proof\n           assume \n            a1:\"fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \\<and>      \n               (\\<exists>ys. (n,\\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n               zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys)\"\n               from a1 obtain ys where \n                   p2_exec:\"(n,\\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n                       zs = map (lift P2) xs @\n                       (P2, snd (((P1, t) # xs) ! length xs)) # ys\" \n                by auto \n               have f1:\"fst (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs)) = LanguageCon.com.Skip\"\n                 using a1 by fastforce             \n               then have p2_long_exec: \n                 \"(n,\\<Gamma>, (P2, snd (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                  (P, t)#zs = map (lift P2) ((P1, t) # xs) @\n                       (P2, snd (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs))) # ys\" \n             using p2_exec by (simp add: lift_def local.Seq)     \n             thus ?thesis using a1 f1 all_step eq_P by blast            \n         next\n           assume \n            a1:\"\\<exists>c. fst (((P1, t) # xs) ! length xs) =c \\<and> (c = Throw \\<or> (\\<exists>f. Fault f = c) \\<or> c = Stuck) \\<and>\n               snd (last ((P1, t) # xs)) =  t' \\<and> t =  t'' \\<and> \n               (\\<exists>ys. (n,\\<Gamma>,(c, t')#ys) \\<in> cptn_mod_nest_call \\<and> zs = map (lift P2) xs @ ((c,  t')#ys))\"\n           then obtain c where a1:\n              \"fst (((P1, t) # xs) ! length xs) =c \\<and> (c = Throw \\<or> (\\<exists>f. Fault f = c) \\<or> c = Stuck) \\<and>\n               snd (last ((P1, t) # xs)) =  t' \\<and> t =  t'' \\<and> \n               (\\<exists>ys. (n,\\<Gamma>,(c, t')#ys) \\<in> cptn_mod_nest_call \\<and> zs = map (lift P2) xs @ ((c,  t')#ys))\"\n             by auto\n           then have last_throw:\n             \"fst (((P1, s)#(P1, t) # xs) ! length ((P1, t) #xs)) = c\"                \n             by fastforce\n           from a1 have last_normal: \"snd (last ((P1, s)#(P1, t) # xs)) =  t'\"\n             by fastforce\n           have seq_lift:\n             \"(LanguageCon.com.Seq P1 P2, t) # map (lift P2) xs = map (lift P2) ((P1, t) # xs)\"\n                by (simp add: a1 lift_def)             \n           thus  ?thesis using a1 last_throw last_normal all_step eq_P       \n              by (clarify, metis (no_types, lifting) append_Cons  )                 \n          qed\n      qed\n    qed (auto) \nqed (force)+\n\nlemma exD: assumes a0:\"\\<exists>x. P x\" obtains x where \"P x\"\n  using exE[OF a0] by auto\n\n\n\nlemma not_func_redex_cptn_mod_nest_n': \n  assumes  \n       vars:\"v = toSeq s\" and vars1:\"w = toSeq t\" and \n       a0:\"\\<Gamma>\\<turnstile>\\<^sub>c (P, v) \\<rightarrow> (Q, w)\" and\n        a0':\"snd s = snd t\" and\n        a1:\"(n,\\<Gamma>,(Q,t)#xs) \\<in>  cptn_mod_nest_call\" and \n        a2:\"(\\<forall>fn. redex P \\<noteq> Call fn) \\<or> \n            (redex P = Call fn \\<and> \\<Gamma> fn = None) \"\nshows \"(n,\\<Gamma>,(P,s)#(Q,t)#xs) \\<in>  cptn_mod_nest_call\"\nusing a0 a1 a2 a0' vars vars1\nproof (induct arbitrary: xs) \n  case (Basicc f e s1)    \n  thus ?case  using stepc.Basicc[of \\<Gamma> f e s1]\n   by (simp add: Basicc cptn_mod_nest_call.CptnModNestSkip)\nnext\n  case (Specc s1 t1 r)\n  thus ?case using stepc.Specc[of s1 t1 r \\<Gamma>]  \n    by (simp add: Specc cptn_mod_nest_call.CptnModNestSkip)\nnext\n  case (SpecStuckc s1 r)\n  thus ?case using stepc.SpecStuckc[of s1 _ \\<Gamma>]  \n    by (metis LanguageCon.com.distinct(57) SmallStepCon.redex.simps(3) CptnModNestStuck )\nnext\n  case (Guardc s1 g f c) \n    thus ?case\n      by (metis (mono_tags, lifting) cptn_mod_nest_call.CptnModNestGuard prod_eqI toSeq.simps(1) ) \n  next\n    case (GuardFaultc s1 g f c)        \n    thus ?case using  stepc.GuardFaultc[of s1 g \\<Gamma> f]\n      by (simp add: cptn_mod_nest_call.CptnModNestFault)\nnext\ncase (Seqc c1 s1 c1' t1 c2)\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c1, s1) \\<rightarrow> (c1', t1)\" by (simp add: Seqc.hyps(1))\n  then have nsc1: \"c1\\<noteq>Skip\"\n    by (meson stepc_elim_cases(1)) \n  have assum: \"(n, \\<Gamma>, (Seq c1' c2, t) # xs) \\<in> cptn_mod_nest_call\" using Seqc.prems by blast\n  have divseq:\n    \"(\\<forall>s P Q zs. (Seq c1' c2, t) # xs=(Seq P Q, s)#zs \\<longrightarrow>\n      (\\<exists>xs sv' sv''. \n        ((n,\\<Gamma>,(P, s)#xs) \\<in> cptn_mod_nest_call  \\<and> \n        (zs=(map (lift Q) xs) \\<or> \n        ((fst(((P, s)#xs)!length xs)=Skip \\<and> \n          (\\<exists>ys. (n,\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod_nest_call \\<and> \n           zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n         (\\<exists>c. (fst(((P, s)#xs)!length xs)=c \\<and> (c = Throw \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n             snd(last ((P, s)#xs)) =  sv' \\<and>  t= sv''\\<and>\n            (\\<exists>ys.  (n,\\<Gamma>,(c, sv')#ys) \\<in> cptn_mod_nest_call \\<and>\n          zs=(map (lift Q) xs)@((c, sv')#ys)))))) ))\"  \n    using div_seq_nest [OF assum] unfolding seq_cond_nest_def by auto\n   {fix sa P Q zsa\n     assume ass:\"(Seq c1' c2, t) # xs = (Seq P Q, sa) # zsa\"\n     then have eqs:\"c1' = P \\<and> c2 = Q \\<and> t = sa \\<and> xs = zsa\" by auto\n     then have \n       \"(\\<exists>xs sv' sv''. (n,\\<Gamma>, (P, sa) # xs) \\<in> cptn_mod_nest_call \\<and>\n        (zsa = map (lift Q) xs \\<or>              \n         fst (((P, sa) # xs) ! length xs) = Skip \\<and>\n           (\\<exists>ys. (n,\\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n           zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<or>\n        (\\<exists>c. (fst(((P, sa)#xs)!length xs)=c \\<and> (c = Throw \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n          snd(last ((P, sa)#xs)) =  sv' \\<and>  t= sv''\\<and>\n          (\\<exists>ys.  (n,\\<Gamma>,(c, sv')#ys) \\<in> cptn_mod_nest_call \\<and> zsa=(map (lift Q) xs)@((c, sv')#ys))))))\" \n           using ass divseq by blast\n    } note conc=this [of c1' c2 t xs]    \n    then obtain xs' sa' sa'' where  \n    split:\"(n,\\<Gamma>, (c1',t) # xs') \\<in> cptn_mod_nest_call \\<and>\n           (xs = map (lift c2) xs' \\<or>                   \n           fst (((c1', t) # xs') ! length xs') = Skip \\<and>\n              (\\<exists>ys. (n,\\<Gamma>, (c2, snd (((c1',t) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n               xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<or>\n           (\\<exists>c. (fst(((c1', t)#xs')!length xs')=c \\<and> (c= Throw \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n               snd(last ((c1', t)#xs')) =  sa' \\<and> t= sa''\\<and>\n               (\\<exists>ys.  (n,\\<Gamma>,(c, sa')#ys) \\<in> cptn_mod_nest_call \\<and>\n                    xs=(map (lift c2) xs')@((c, sa')#ys)))))\"  \n      by blast\n  then have \"xs = map (lift c2) xs' \\<or>                   \n           fst (((c1', t) # xs') ! length xs') = Skip \\<and>\n              (\\<exists>ys. (n,\\<Gamma>, (c2, snd (((c1',t) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n               xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<or>\n           (\\<exists>c. (fst(((c1', t)#xs')!length xs')=c \\<and> (c= Throw \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n               snd(last ((c1', t)#xs')) =  sa' \\<and> t= sa''\\<and>\n               (\\<exists>ys.  (n,\\<Gamma>,(c, sa')#ys) \\<in> cptn_mod_nest_call \\<and>\n                    xs=(map (lift c2) xs')@((c, sa')#ys))))\" \n    by auto\n  thus ?case \n  proof{           \n       assume c1'nonf:\"xs = map (lift c2) xs'\"\n       then have c1'cptn:\"(n,\\<Gamma>, (c1', t) # xs') \\<in> cptn_mod_nest_call\" using split by blast\n       then have induct_step: \"(n,\\<Gamma>, (c1, s) # (c1', t)#xs') \\<in> cptn_mod_nest_call\"\n         using Seqc.hyps(2) Seqc.prems(2) Seqc.prems(4) a0' \n         by (simp add: Seqc.prems(5))\n       then have \"(Seq c1' c2, t)#xs = map (lift c2) ((c1', t)#xs')\"\n         using c1'nonf\n         by (simp add: lift_def)\n       thus ?thesis \n         using c1'nonf c1'cptn induct_step by (auto simp add: CptnModNestSeq1)\n    next\n      assume \"                  \n           fst (((c1', t) # xs') ! length xs') = Skip \\<and>\n              (\\<exists>ys. (n,\\<Gamma>, (c2, snd (((c1',t) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n               xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<or>\n           (\\<exists>c. (fst(((c1', t)#xs')!length xs')=c \\<and> (c= Throw \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n               snd(last ((c1', t)#xs')) =  sa' \\<and> t= sa''\\<and>\n               (\\<exists>ys.  (n,\\<Gamma>,(c, sa')#ys) \\<in> cptn_mod_nest_call \\<and>\n                    xs=(map (lift c2) xs')@((c, sa')#ys))))\"  \n      thus ?thesis\n      proof\n        assume assth:\"fst (((c1', t) # xs') ! length xs') = Skip \\<and>\n            (\\<exists>ys. (n,\\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n                xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys)\"\n        then obtain ys \n           where split':\"(n,\\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n                xs = map (lift c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys\"\n           by auto    \n        then have c1'cptn:\"(n,\\<Gamma>, (c1', t) # xs') \\<in> cptn_mod_nest_call\" using split by blast\n        then have induct_step: \"(n,\\<Gamma>, (c1, s) # (c1', t)#xs') \\<in> cptn_mod_nest_call\"\n          using Seqc.hyps(2) Seqc.prems(2)\n          by (simp add: Seqc.prems(4) Seqc.prems(5) a0')                         \n        then have seqmap:\"(Seq c1 c2, s)#(Seq c1' c2, t)#xs =\n            map (lift c2) ((c1,s)#(c1', t)#xs') @ (c2, snd (((c1', t) # xs') ! length xs')) # ys\"\n          using split' by (simp add:  lift_def)       \n        then have lastc1:\"last ((c1, s) # (c1', t) # xs') = ((c1', t) # xs') ! length xs'\"\n          by (simp add: last_length) \n        then have lastc1skip:\"fst (last ((c1, s) # (c1', t) # xs')) = Skip\" \n          using assth by fastforce                \n        thus ?thesis\n          using seqmap split' cptn_mod_nest_call.CptnModNestSeq2 induct_step lastc1 lastc1skip\n          by (metis (no_types) Cons_lift_append )                  \n      next      \n        assume assm:\n        \"\\<exists>c. (fst(((c1', t)#xs')!length xs')=c \\<and> (c= Throw \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n               snd(last ((c1', t)#xs')) =  sa' \\<and> t= sa''\\<and>\n               (\\<exists>ys.  (n,\\<Gamma>,(c, sa')#ys) \\<in> cptn_mod_nest_call \\<and>\n                    xs=(map (lift c2) xs')@((c, sa')#ys)))\"\n        then obtain c where assm:\n          \"(fst(((c1', t)#xs')!length xs')=c \\<and> (c= Throw \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n               snd(last ((c1', t)#xs')) =  sa' \\<and> t= sa''\\<and>\n               (\\<exists>ys.  (n,\\<Gamma>,(c, sa')#ys) \\<in> cptn_mod_nest_call \\<and>\n                    xs=(map (lift c2) xs')@((c, sa')#ys)))\"\n          by auto\n        then have s'eqsa'': \"t= sa''\" by auto\n        then have snormal: \"\\<exists>ns. s= ns\" by auto\n        then have c1'cptn:\"(n,\\<Gamma>, (c1', t) # xs') \\<in> cptn_mod_nest_call\" using split by blast        \n        then have induct_step: \"(n,\\<Gamma>, (c1, s) # (c1', t)#xs') \\<in> cptn_mod_nest_call\"\n          using Seqc.hyps(2) Seqc.prems(2) \n          by (simp add: Seqc.prems(4) Seqc.prems(5) a0')       \n        then obtain ys where\n          seqmap:\"(Seq c1' c2, t)#xs = \n                    (map (lift c2) ((c1', t)#xs'))@((c, sa')#ys)\"\n        using assm\n        using Cons_lift_append by blast          \n        then have lastc1:\"last ((c1, s) # (c1',t) # xs') = ((c1', t) # xs') ! length xs'\"\n                   by (simp add: last_length) \n        then have lastc1skip:\"fst (last ((c1, s) # (c1', t) # xs')) = c\" \n             using assm by fastforce\n        then have \"snd (last ((c1, s) # (c1', t) # xs')) =  sa'\"\n             using assm by force        \n        thus ?thesis\n            using assm c1'cptn induct_step lastc1skip snormal seqmap s'eqsa'' \n            by (auto simp add:cptn_mod_nest_call.CptnModNestSeq3)\n        qed\n      }qed   \n  next\n    case (SeqSkipc c2 s1 xs)  \n    have c2incptn:\"(n,\\<Gamma>, (c2, s) # xs) \\<in> cptn_mod_nest_call\"    \n      using SeqSkipc.prems(1) SeqSkipc.prems(4) SeqSkipc.prems(5) a0' eq_toSeq by blast\n    moreover have 1:\"(n,\\<Gamma>, [(Skip, s)]) \\<in> cptn_mod_nest_call\"\n      by (simp add: cptn_mod_nest_call.CptnModNestOne)\n    moreover have 2:\"fst(last ([(Skip, s)])) = Skip\" by fastforce\n    moreover have 3:\"(n,\\<Gamma>,(c2, snd(last [(Skip, s)]))#xs) \\<in> cptn_mod_nest_call\" \n      using c2incptn by auto  \n    moreover have \"(c2,s)#xs=(map (lift c2) [])@(c2, snd(last [(Skip, s)]))#xs\" \n      by (auto simp add:lift_def)\n    moreover have \"s=t\" using eq_toSeq SeqSkipc by blast\n      ultimately show ?case by (simp add: CptnModNestSeq2)   \nnext\n  case (SeqThrowc c2 s1 xs)  \n  have eq_st:\"s=t\" using eq_toSeq[OF SeqThrowc(3)] SeqThrowc by auto\n  obtain ns where normals:\"s= ns\" using SeqThrowc by auto\n  have \"(n,\\<Gamma>, [(Throw,  ns)]) \\<in> cptn_mod_nest_call\" \n    by (simp add: cptn_mod_nest_call.CptnModNestOne) \n  then obtain ys where \n    ys_nil:\"ys=[]\" and \n    last:\"(n, \\<Gamma>, (Throw,  s)#ys)\\<in> cptn_mod_nest_call\"\n    using normals \n   by auto\n  moreover have \"fst (last ((Throw,  ns)#ys)) = Throw\" using ys_nil last by auto\n  moreover have \"snd (last ((Throw,  ns)#ys)) =  ns\" using ys_nil last by auto\n  moreover from ys_nil have \"(map (lift c2) ys) = []\" by auto  \n  ultimately show ?case \n    using SeqThrowc.prems cptn_mod_nest_call.CptnModNestSeq3 eq_st normals\n    by (metis append_Nil)   \nnext\n  case (SeqFaultc f c2 s1 xs)  \n  have eq_st:\"s=t\" using eq_toSeq[OF SeqFaultc(3)] SeqFaultc by auto\n  obtain ns where normals:\"s= ns\" using SeqThrowc by auto\n  have f:\"(n,\\<Gamma>, [(Fault f,  ns)]) \\<in> cptn_mod_nest_call\" \n    by (simp add: cptn_mod_nest_call.CptnModNestOne) \n  then obtain ys where \n    ys_nil:\"ys=[]\" and \n    last:\"(n, \\<Gamma>, (Fault f,  s)#ys)\\<in> cptn_mod_nest_call\"\n    using normals \n   by auto\n  moreover have \"fst (last ((Fault f,  ns)#ys)) = Fault f\" using ys_nil last by auto\n  moreover have \"snd (last ((Fault f,  ns)#ys)) =  ns\" using ys_nil last by auto\n  moreover from ys_nil have \"(map (lift c2) ys) = []\" by auto  \n  ultimately show ?case \n    using SeqFaultc.prems cptn_mod_nest_call.CptnModNestSeq3 eq_st normals f \n    by (metis append_Nil)      \nnext\n  case (SeqStuckc c2 s1 xs)  \n  have eq_st:\"s=t\" using eq_toSeq[OF SeqStuckc(3)] SeqStuckc by auto\n  obtain ns where normals:\"s= ns\" using SeqThrowc by auto\n  have f:\"(n,\\<Gamma>, [(Stuck,  ns)]) \\<in> cptn_mod_nest_call\" \n    by (simp add: cptn_mod_nest_call.CptnModNestOne) \n  then obtain ys where \n    ys_nil:\"ys=[]\" and \n    last:\"(n, \\<Gamma>, (Stuck,  s)#ys)\\<in> cptn_mod_nest_call\"\n    using normals \n   by auto\n  moreover have \"fst (last ((Stuck,  ns)#ys)) = Stuck\" using ys_nil last by auto\n  moreover have \"snd (last ((Stuck,  ns)#ys)) =  ns\" using ys_nil last by auto\n  moreover from ys_nil have \"(map (lift c2) ys) = []\" by auto  \n  ultimately show ?case \n    using SeqStuckc.prems cptn_mod_nest_call.CptnModNestSeq3 eq_st normals f \n    by (metis append_Nil)      \nnext\n  case (CondTruec s1 b c1 c2)\n  moreover obtain ns where normals:\"s= ns\" by auto\n  moreover have \"s=t\"\n    using calculation(5,6) eq_toSeq[OF calculation(4)]  by auto\n  ultimately show ?case by (simp add: cptn_mod_nest_call.CptnModNestCondT)\nnext\n  case (CondFalsec s1 b c1 c2)\n  moreover obtain ns where normals:\"s= ns\" by auto\n  moreover have \"s=t\"\n    using calculation(5,6) eq_toSeq[OF calculation(4)]  by auto\n  ultimately show ?case by (simp add: cptn_mod_nest_call.CptnModNestCondF)\nnext \n  case (WhileTruec s1 b c) \n  have sinb: \"s1\\<in>b\" by fact\n  obtain ns where normals:\"s= ns\" by auto\n  have eq_st:\"s=t\" using eq_toSeq[OF WhileTruec(4)] WhileTruec by blast\n  have SeqcWhile: \"(n,\\<Gamma>, (Seq c (While b c),  ns) # xs) \\<in> cptn_mod_nest_call\"\n    using WhileTruec.prems(1) eq_st normals by force\n  have divseq:\n    \"(\\<forall>s P Q zs. (Seq c (While b c),  ns) # xs=(Seq P Q, s)#zs \\<longrightarrow>\n        (\\<exists>xs s'. ((n,\\<Gamma>,(P, s)#xs) \\<in> cptn_mod_nest_call  \\<and> \n        (zs=(map (lift Q) xs) \\<or>\n        ((fst(((P, s)#xs)!length xs)=Skip \\<and> \n           (\\<exists>ys. (n,\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod_nest_call \\<and> \n            zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n         (\\<exists>c. (fst(((P, s)#xs)!length xs)=c \\<and> (c = Throw \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n           snd(last ((P, s)#xs)) =  s' \\<and>\n           (\\<exists>ys.  (n,\\<Gamma>,(c, s')#ys) \\<in> cptn_mod_nest_call \\<and> zs=(map (lift Q) xs)@((c, s')#ys))))))))\" \n    using div_seq_nest [OF SeqcWhile] eq_st normals \n   unfolding seq_cond_nest_def by fastforce\n  { fix sa P Q zsa\n    assume ass:\"(Seq c (While b c),  ns) # xs = (Seq P Q, sa) # zsa\"\n    then have eqs:\"c = P \\<and> (While b c) = Q \\<and>  ns = sa \\<and> xs = zsa\" by auto\n    then have \"(\\<exists>xs s'. (n,\\<Gamma>, (P, sa) # xs) \\<in> cptn_mod_nest_call \\<and>\n                (zsa = map (lift Q) xs \\<or>              \n                 fst (((P, sa) # xs) ! length xs) = Skip \\<and>\n                   (\\<exists>ys. (n,\\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n                   zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<or>\n                (\\<exists>c. (fst(((P, sa)#xs)!length xs)=c \\<and> (c = Throw \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n                  snd(last ((P, sa)#xs)) =  s' \\<and>\n                  (\\<exists>ys.  (n,\\<Gamma>,(c, s')#ys) \\<in> cptn_mod_nest_call \\<and> zsa=(map (lift Q) xs)@((c, s')#ys))))))\"         \n      using ass divseq by auto     \n  } note conc=this [of c \"While b c\" \" ns\" xs]   \n  then obtain xs' s' where  split:\"(n,\\<Gamma>, (c,  ns) # xs') \\<in> cptn_mod_nest_call \\<and>\n   (xs = map (lift (While b c)) xs' \\<or>\n    fst (((c,  ns) # xs') ! length xs') = Skip \\<and>\n      (\\<exists>ys. (n,\\<Gamma>, (While b c, snd (((c,  ns) # xs') ! length xs')) # ys)\n      \\<in> cptn_mod_nest_call \\<and>\n      xs = map (lift (While b c)) xs' @\n      (While b c, snd (((c,  ns) # xs') ! length xs')) # ys) \\<or>\n    (\\<exists>c1. fst (((c,  ns) # xs') ! length xs') = c1 \\<and>(c1 = Throw \\<or> (\\<exists>f. c1 = Fault f) \\<or> c1 = Stuck) \\<and>\n      snd (last ((c,  ns) # xs')) =  s' \\<and> \n      (\\<exists>ys.  (n,\\<Gamma>, ((c1,  s')#ys)) \\<in> cptn_mod_nest_call \\<and> \n      xs = map (lift (While b c)) xs' @ ((c1,  s')#ys))))\"  \n    by blast\n then have \"(xs = map (lift (While b c)) xs' \\<or>\n      fst (((c,  ns) # xs') ! length xs') = Skip \\<and>\n        (\\<exists>ys. (n,\\<Gamma>, (While b c, snd (((c,  ns) # xs') ! length xs')) # ys)\n        \\<in> cptn_mod_nest_call \\<and>\n        xs = map (lift (While b c)) xs' @\n        (While b c, snd (((c,  ns) # xs') ! length xs')) # ys) \\<or>\n      (\\<exists>c1. fst (((c,  ns) # xs') ! length xs') = c1 \\<and>(c1 = Throw \\<or> (\\<exists>f. c1 = Fault f) \\<or> c1 = Stuck) \\<and>\n        snd (last ((c,  ns) # xs')) =  s' \\<and> \n        (\\<exists>ys.  (n,\\<Gamma>, ((c1,  s')#ys)) \\<in> cptn_mod_nest_call \\<and> \n        xs = map (lift (While b c)) xs' @ ((c1,  s')#ys))))\" .. \n  thus ?case \n  proof{         \n    assume 1:\"xs = map (lift (While b c)) xs'\"\n    have 3:\"(n, \\<Gamma>, (c,  ns) # xs') \\<in> cptn_mod_nest_call\" using split by auto   \n    then show ?thesis \n      using \"1\" cptn_mod_nest_call.CptnModNestWhile1 sinb normals eq_st WhileTruec.prems(4) \n      by fastforce     \n next\n   assume \"fst (((c,  ns) # xs') ! length xs') = Skip \\<and>\n        (\\<exists>ys. (n,\\<Gamma>, (While b c, snd (((c,  ns) # xs') ! length xs')) # ys)\n        \\<in> cptn_mod_nest_call \\<and>\n        xs = map (lift (While b c)) xs' @\n        (While b c, snd (((c,  ns) # xs') ! length xs')) # ys) \\<or>\n      (\\<exists>c1. fst (((c,  ns) # xs') ! length xs') = c1 \\<and>(c1 = Throw \\<or> (\\<exists>f. c1 = Fault f) \\<or> c1 = Stuck) \\<and>\n        snd (last ((c,  ns) # xs')) =  s' \\<and> \n        (\\<exists>ys.  (n,\\<Gamma>, ((c1,  s')#ys)) \\<in> cptn_mod_nest_call \\<and> \n        xs = map (lift (While b c)) xs' @ ((c1,  s')#ys)))\"\n   thus ?case\n   proof\n     assume asm:\"fst (((c,  ns) # xs') ! length xs') = Skip \\<and>\n        (\\<exists>ys. (n,\\<Gamma>, (While b c, snd (((c,  ns) # xs') ! length xs')) # ys)\n        \\<in> cptn_mod_nest_call \\<and>\n        xs = map (lift (While b c)) xs' @\n        (While b c, snd (((c,  ns) # xs') ! length xs')) # ys)\"\n     then obtain ys where \n       asm':\"(n,\\<Gamma>, (While b c, snd (last ((c,  ns) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>  \n              xs = map (lift (While b c)) xs' @ (While b c, snd (last ((c,  ns) # xs'))) # ys\"               \n       by (auto simp add: last_length)\n     moreover have 3:\"(n,\\<Gamma>, (c,  ns) # xs') \\<in> cptn_mod_nest_call\" using split by auto\n     moreover from asm have \"fst (last ((c,  ns) # xs'))  = Skip\"\n          by (simp add: last_length) \n        ultimately show ?case using sinb normals eq_st  WhileTruec.prems(4)\n          by (auto simp add:CptnModNestWhile2)\n   next\n     assume asm:\n      \"(\\<exists>c1. fst (((c,  ns) # xs') ! length xs') = c1 \\<and>(c1 = Throw \\<or> (\\<exists>f. c1 = Fault f) \\<or> c1 = Stuck) \\<and>\n        snd (last ((c,  ns) # xs')) =  s' \\<and> \n        (\\<exists>ys.  (n,\\<Gamma>, ((c1,  s')#ys)) \\<in> cptn_mod_nest_call \\<and> xs = \n          map (lift (While b c)) xs' @ ((c1,  s')#ys)))\"   \n     then obtain c1 where asm:\n       \"fst (((c,  ns) # xs') ! length xs') = c1 \\<and> (c1 = Throw \\<or> (\\<exists>f. c1 = Fault f) \\<or> c1 = Stuck) \\<and>\n        snd (last ((c,  ns) # xs')) =  s' \\<and> \n       (\\<exists>ys.  (n,\\<Gamma>, ((c1,  s')#ys)) \\<in> cptn_mod_nest_call \\<and> xs = \n          map (lift (While b c)) xs' @ ((c1,  s')#ys))\"   \n       by auto     \n     moreover from asm have h:\"fst (last ((c,  ns) # xs'))  = c1\"\n       by (simp add: last_length)           \n     ultimately show ?case \n       using sinb normals split eq_st asm WhileTruec.prems(4) CptnModNestWhile3[OF ] \n          by (auto simp add:CptnModNestWhile3)\n   qed\n }qed  \nnext\n  case (WhileFalsec s1 b c) \n  thus ?case   using stepc.WhileFalsec[of s1 b \\<Gamma> c] \n    by (simp add: cptn_mod_nest_call.CptnModNestSkip)\nnext\n  case (Awaitc s1 b \\<Gamma>a c t1)\n  thus ?case using  stepc.Awaitc[of s1 b \\<Gamma>a \\<Gamma>] \n    by (simp add: cptn_mod_nest_call.CptnModNestSkip)\nnext\n  case (AwaitAbruptc s1 b \\<Gamma>a c t1 ta)\n  thus ?case using stepc.AwaitAbruptc[of s1 b \\<Gamma>a \\<Gamma> c t1 ta] \n    by (simp add: cptn_mod_nest_call.CptnModNestThrow) \nnext \n  case (AwaitFaultc s1 b \\<Gamma>a c f e ta)\n  thus ?case using stepc.AwaitFaultc\n    by (simp add: stepc.AwaitFaultc cptn_mod_nest_call.CptnModNestFault)\nnext \n  case (AwaitStuckc s1 b \\<Gamma>a c e ta)\n  thus ?case using stepc.AwaitStuckc\n    by (simp add: stepc.AwaitStuckc cptn_mod_nest_call.CptnModNestStuck)\nnext\n  case (Callc p bdy s1)\n  moreover have eq_st:\"s=t\" using eq_toSeq[OF Callc(5)] Callc by auto\n  moreover obtain ns where normals:\"s= ns\" by auto\n  ultimately show ?case\n    by (metis LanguageCon.com.inject(6) SmallStepCon.redex.simps(7) option.distinct(1))         \nnext\n  case (CallUndefinedc p s1)    \n  then have seq:\"\\<Gamma>\\<turnstile>\\<^sub>c( (LanguageCon.com.Call p),toSeq s) \\<rightarrow> (Stuck,toSeq t)\" \n    using stepc.CallUndefinedc[of \\<Gamma> p s1] by auto\n  thus ?case \n    using  CallUndefinedc CptnModNestStuck[OF seq _ _ _ CallUndefinedc(2)] \n    by force\nnext\n  case (DynComc c s1)  \n  moreover have eq_st:\"s=t\"\n    using calculation(4) calculation(5) eq_toSeq[OF calculation(3)] by force\n  moreover obtain ns where normals:\"s= ns\" by auto    \n  moreover have \"(n, \\<Gamma>, (LanguageCon.com.DynCom c,  ns) # \n                          (c (fst ns), ns) # xs) \\<in> cptn_mod_nest_call\"\n    using DynComc.prems(1) DynComc.prems(4) \n      cptn_mod_nest_call.CptnModNestDynCom eq_st normals by fastforce\n  then show ?case\n    using DynComc.prems(4) eq_st normals by fastforce\nnext (* (\\<forall>s P Q zs. (Catch c1' c2, t) # xs=(Catch P Q, s)#zs \\<longrightarrow>\n  (\\<exists>xs s' s''. ((n,\\<Gamma>,(P, s)#xs) \\<in> cptn_mod_nest_call  \\<and> \n             (zs=(map (lift_catch Q) xs) \\<or>\n             ((fst(((P, s)#xs)!length xs)=Throw \\<and>\n               snd(last ((P, s)#xs)) = Normal s' \\<and>  s=Normal s''\\<and>\n               (\\<exists>ys. (n,\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod_nest_call \\<and> \n                zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n                ((fst(((P, s)#xs)!length xs)=Skip \\<and>  \n                  (\\<exists>ys. (n,\\<Gamma>,(Skip,snd(last ((P, s)#xs)))#ys) \\<in> cptn_mod_nest_call \\<and>                   \n                 zs=(map (lift_catch Q) xs)@((Skip,snd(last ((P, s)#xs)))#ys))                \n                 ))))\n   )) *)\n  case (Catchc c1 s1 c1' t1 c2 xs)\n   have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c1, s1) \\<rightarrow> (c1', t1)\" by (simp add: Catchc.hyps(1))\n  then have nsc1: \"c1\\<noteq>Skip\" using stepc_elim_cases(1) by fastforce \n  have assum: \"(n,\\<Gamma>, (Catch c1' c2, t) # xs) \\<in> cptn_mod_nest_call\" \n    using Catchc.prems by blast\n  note div = div_catch_nest[OF assum, simplified catch_cond_nest_def]  \n  { fix sa P Q zsa\n    assume ass:\"(Catch c1' c2,t) # xs = (Catch P Q, sa) # zsa\"\n    then have eqs:\"c1' = P \\<and> c2 = Q \\<and> t = sa \\<and> xs = zsa\" by auto\n    note univ = spec[OF spec[OF spec[OF spec[OF div, of sa], of P ], of Q], of zsa] \n    note cond = mp[OF univ ass]    \n  } note conc=this [of c1' c2 t xs] \n  have ass:\"(LanguageCon.com.Catch c1' c2, t) # xs = (LanguageCon.com.Catch c1' c2, t) # xs\"\n    by auto\n  note body =conc[OF ass] \n  then obtain xs' sa' sa''  \n   where split:\n   \"(n, \\<Gamma>, (c1', t) # xs') \\<in> cptn_mod_nest_call \\<and>\n     (xs = map (lift_catch c2) xs' \\<or>\n      fst (((c1', t) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n      snd (last ((c1', t) # xs')) = sa' \\<and>\n      t = sa'' \\<and>\n      (\\<exists>ys. (n, \\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys)\n            \\<in> cptn_mod_nest_call \\<and>\n            xs = map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<or>\n      (\\<exists>ta. fst (((c1', t) # xs') ! length xs') = ta \\<and>\n            (ta = LanguageCon.com.Skip \\<or> (\\<exists>f. ta = com.Fault f) \\<or> ta = com.Stuck) \\<and>\n            (\\<exists>ys. (n, \\<Gamma>, (ta, snd (last ((c1', t) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                  xs = map (lift_catch c2) xs' @ (ta, snd (last ((c1', t) # xs'))) # ys)))\"          \n    by blast\n  note c1 = conjunct2[OF this]  \n  thus ?case \n  proof{           \n       assume c1'nonf:\"xs = map (lift_catch c2) xs'\"\n       then have c1'cptn:\"(n,\\<Gamma>, (c1', t) # xs') \\<in> cptn_mod_nest_call\" using split by blast\n       then have induct_step: \"(n, \\<Gamma>, (c1, s) # (c1',t)#xs') \\<in> cptn_mod_nest_call\"\n         using Catchc.hyps(2) Catchc.prems(2) \n         by (simp add: Catchc.prems(4) Catchc.prems(5) a0')  \n       then have \"(Catch c1' c2, t)#xs = map (lift_catch c2) ((c1', t)#xs')\"\n            using c1'nonf\n            by (simp add: CptnModCatch1 lift_catch_def)\n       thus ?thesis \n            using c1'nonf c1'cptn induct_step \n       by (auto simp add: CptnModNestCatch1)\n   next       \n      assume \"fst (((c1', t) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n              snd (last ((c1', t) # xs')) = sa' \\<and>  t = sa'' \\<and>\n                (\\<exists>ys. (n, \\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n                xs = map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<or>\n              (\\<exists>ta. fst (((c1', t) # xs') ! length xs') = ta \\<and>\n                (ta = LanguageCon.com.Skip \\<or> (\\<exists>f. ta = com.Fault f) \\<or> ta = com.Stuck) \\<and>\n                (\\<exists>ys. (n, \\<Gamma>, (ta, snd (last ((c1', t) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                xs = map (lift_catch c2) xs' @ (ta, snd (last ((c1', t) # xs'))) # ys))\"  \n      thus ?thesis\n      proof\n         assume assth:\n               \"fst (((c1', t) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n              snd (last ((c1', t) # xs')) = sa' \\<and>  t = sa'' \\<and>\n                (\\<exists>ys. (n, \\<Gamma>, (c2, snd (((c1', t) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n                xs = map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys)\"\n             then have s'eqsa'': \"t= sa''\" by auto\n             then have snormal: \"\\<exists>ns. s= ns\"\n               using Catchc.prems(4) Catchc.prems(5) a0' c_step local.step  by blast\n             then obtain ys \n             where split':\"(n,\\<Gamma>, (c2, snd (((c1',t) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n                xs =map (lift_catch c2) xs' @ (c2, snd (((c1', t) # xs') ! length xs')) # ys\"\n                using assth by auto    \n         then have c1'cptn:\"(n,\\<Gamma>, (c1', t) # xs') \\<in> cptn_mod_nest_call\" \n              using split by blast\n         then have induct_step: \"(n,\\<Gamma>, (c1, s) # (c1', t)#xs') \\<in> cptn_mod_nest_call\"\n           using Catchc.hyps(2) Catchc.prems(2) SmallStepCon.redex.simps(11)\n           by (simp add: Catchc.prems(4) Catchc.prems(5) a0')\n         then have seqmap:\"(Catch c1 c2, s)#(Catch c1' c2, t)#xs = \n                           map (lift_catch c2) ((c1,s)#(c1', t)#xs') @ \n                            (c2, snd (((c1', t) # xs') ! length xs')) # ys\"\n              using split' by (simp add: CptnModCatch3 lift_catch_def) \n        then have lastc1:\"last ((c1, s) # (c1', t) # xs') = ((c1', t) # xs') ! length xs'\"\n             by (simp add: last_length) \n        then have lastc1skip:\"fst (last ((c1, s) # (c1', t) # xs')) = Throw\" \n             using assth by fastforce\n        then have \"snd (last ((c1, s) # (c1', t) # xs')) =  sa'\"\n             using assth by fastforce\n        thus ?thesis using snormal seqmap s'eqsa'' split' \n               cptn_mod_nest_call.CptnModNestCatch3 \n              induct_step lastc1 lastc1skip\n              using Cons_lift_catch_append\n              by (metis)           \n    next\n        assume assm:\"(\\<exists>ta. fst (((c1', t) # xs') ! length xs') = ta \\<and>\n                           (ta = LanguageCon.com.Skip \\<or> (\\<exists>f. ta = com.Fault f) \\<or> ta = com.Stuck) \\<and>\n                          (\\<exists>ys. (n, \\<Gamma>, (ta, snd (last ((c1', t) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                          xs = map (lift_catch c2) xs' @ (ta, snd (last ((c1', t) # xs'))) # ys))\"\n        then obtain c where assm:\"fst (((c1', t) # xs') ! length xs') = c \\<and>\n                           (c = LanguageCon.com.Skip \\<or> (\\<exists>f. c = com.Fault f) \\<or> c = com.Stuck) \\<and>\n                          (\\<exists>ys. (n, \\<Gamma>, (c, snd (last ((c1', t) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                          xs = map (lift_catch c2) xs' @ (c, snd (last ((c1', t) # xs'))) # ys)\"\n          by auto\n        then have c1'cptn:\"(n,\\<Gamma>, (c1', t) # xs') \\<in> cptn_mod_nest_call\" \n          using split by blast\n        then have induct_step: \"(n,\\<Gamma>, (c1, s) # (c1', t)#xs') \\<in> cptn_mod_nest_call\"\n          using Catchc.hyps(2) Catchc.prems(2) SmallStepCon.redex.simps(11)        \n          by (simp add: Catchc.prems(4) Catchc.prems(5) a0')\n        then have \"map (lift_catch c2) ((c1', t) # xs') = (Catch c1' c2, t) # map (lift_catch c2) xs'\" \n          by (auto simp add: lift_catch_def)\n        then obtain ys \n             where seqmap:\"(Catch c1' c2, t)#xs = (map (lift_catch c2) ((c1', t)#xs'))@((c,snd(last ((c1', t)#xs')))#ys)\"\n        using assm by fastforce\n        then have lastc1:\"last ((c1, s) # (c1', t) # xs') = ((c1', t) # xs') ! length xs'\"\n                   by (simp add: last_length) \n        then have lastc1skip:\"fst (last ((c1, s) # (c1', t) # xs')) = c\" \n             using assm by fastforce\n        then have \"snd (last ((c1, s) # (c1', t) # xs')) = snd (last ((c1', t) # xs'))\"\n          using assm by force\n        then obtain f where  c:\"(c = LanguageCon.com.Skip \\<or>  (c = com.Fault f) \\<or> c = com.Stuck)\" using assm by auto\n        thus ?thesis \n          using assm c1'cptn induct_step lastc1skip seqmap \n                cptn_mod_nest_call.CptnModNestCatch2[OF induct_step lastc1skip c]\n          by auto\n    qed\n  }qed              \nnext\n  case (CatchThrowc c2 s1)\n  then obtain ns where ns:\"s = ns\" by auto\n  then have eq_st: \"s=t\" using  eq_toSeq[OF CatchThrowc(3)] CatchThrowc(4,5) by auto\n  have c2incptn:\"(n,\\<Gamma>, (c2,  ns) # xs) \\<in> cptn_mod_nest_call\"\n    using CatchThrowc.prems(1) eq_st ns by fastforce\n  have 1:\"(n,\\<Gamma>, [(Throw,  ns)]) \\<in> cptn_mod_nest_call\" \n    by (simp add: cptn_mod_nest_call.CptnModNestOne)\n  have 2:\"fst(last ([(Throw,  ns)])) = Throw\" by fastforce\n  have 3:\"(n,\\<Gamma>,(c2, snd(last [(Throw,  ns)]))#xs) \\<in> cptn_mod_nest_call\"       \n    using c2incptn by auto\n  moreover have \"(c2, ns)#xs=\n                (map (lift c2) [])@(c2, snd(last [(Throw,  ns)]))#xs\" \n    by (auto simp add:lift_def)     \n  ultimately show ?case using eq_st ns CptnModNestCatch3[OF 1 2] by fastforce\nnext\n  case (CatchSkipc c2 s1)\n  have \"(n,\\<Gamma>, [(Skip, s)]) \\<in> cptn_mod_nest_call\" \n    by (simp add: cptn_mod_nest_call.CptnModNestOne)\n  then obtain ys where \n    ys_nil:\"ys=[]\" and \n    last:\"(n,\\<Gamma>, (Skip,  s)#ys)\\<in> cptn_mod_nest_call\"\n    by auto\n  moreover have \"fst (last ((Skip,  s)#ys)) = Skip\" using ys_nil last by auto\n  moreover have \"snd (last ((Skip,  s)#ys)) = s\" using ys_nil last by auto\n  moreover from ys_nil have \"(map (lift_catch c2) ys) = []\" by auto\n  moreover have \"s=t\"\n    using CatchSkipc.prems(4) CatchSkipc.prems(5) a0' eq_toSeq by blast\n  ultimately show ?case using CatchSkipc.prems \n    by simp (simp add: cptn_mod_nest_call.CptnModNestCatch2 ys_nil)\nnext\n  case (CatchFaultc f c2 s1)\n  have \"(n,\\<Gamma>, [(Fault f, s)]) \\<in> cptn_mod_nest_call\" \n    by (simp add: cptn_mod_nest_call.CptnModNestOne)\n  then obtain ys where \n    ys_nil:\"ys=[]\" and \n    last:\"(n,\\<Gamma>, (Fault f,  s)#ys)\\<in> cptn_mod_nest_call\"\n    by auto\n  moreover have \"fst (last ((Fault f,  s)#ys)) = Fault f\" using ys_nil last by auto\n  moreover have \"snd (last ((Fault f,  s)#ys)) = s\" using ys_nil last by auto\n  moreover from ys_nil have \"(map (lift_catch c2) ys) = []\" by auto\n  moreover have \"s=t\"\n    using CatchFaultc.prems(4) CatchFaultc.prems(5) a0' eq_toSeq by blast\n  ultimately show ?case using CatchFaultc.prems \n    by simp (simp add: cptn_mod_nest_call.CptnModNestCatch2 ys_nil)\nnext\n  case (CatchStuckc  c2 s1)\n  have \"(n,\\<Gamma>, [(Stuck, s)]) \\<in> cptn_mod_nest_call\" \n    by (simp add: cptn_mod_nest_call.CptnModNestOne)\n  then obtain ys where \n    ys_nil:\"ys=[]\" and \n    last:\"(n,\\<Gamma>, (Stuck,  s)#ys)\\<in> cptn_mod_nest_call\"\n    by auto\n  moreover have \"fst (last ((Stuck,  s)#ys)) = Stuck\" using ys_nil last by auto\n  moreover have \"snd (last ((Stuck,  s)#ys)) = s\" using ys_nil last by auto\n  moreover from ys_nil have \"(map (lift_catch c2) ys) = []\" by auto\n  moreover have \"s=t\"\n    using CatchStuckc.prems(4) CatchStuckc.prems(5) a0' eq_toSeq by blast\n  ultimately show ?case using CatchStuckc.prems \n     by simp (simp add: cptn_mod_nest_call.CptnModNestCatch2 ys_nil)\nqed\n\n\nlemma not_func_redex_cptn_mod_nest_n_env: \nassumes a0:\"\\<Gamma>\\<turnstile>\\<^sub>c (P,s) \\<rightarrow>\\<^sub>e (P, t)\" and\n        a1:\"(n,\\<Gamma>,(P,t)#xs) \\<in>  cptn_mod_nest_call\"         \nshows \"(n,\\<Gamma>,(P,s)#(P,t)#xs) \\<in>  cptn_mod_nest_call\"\n  by (simp add: a0 a1 cptn_mod_nest_call.CptnModNestEnv)\n\n\nlemma cptn_mod_nest_cptn_mod:\"(n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call  \\<Longrightarrow> (\\<Gamma>,cfs)\\<in> cptn_mod\"\n  by (induct rule:cptn_mod_nest_call.induct, (auto simp:cptn_mod.intros )+)\n \n\nlemma cptn_mod_cptn_mod_nest: \"(\\<Gamma>,cfs)\\<in> cptn_mod \\<Longrightarrow> \\<exists>n. (n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call\"\nproof (induct rule:cptn_mod.induct)\n   case (CptnModSkip \\<Gamma> P s t xs) \n   then obtain n where cptn_nest:\"(n, \\<Gamma>, (Skip, t) # xs) \\<in> cptn_mod_nest_call\" by auto      \n    {assume asm:\"\\<forall>f. ((\\<exists>sn. s =  sn) \\<and> (\\<Gamma> f) = Some Skip \\<longrightarrow> P  \\<noteq> Call f  )\"     \n     then have ?case\n       by (meson CptnModSkip.hyps(1) CptnModSkip.hyps(2) CptnModSkip.hyps(3) \n                cptn_nest cptn_mod_nest_callp.CptnModNestSkip\n                cptn_mod_nest_callp_cptn_mod_nest_call_eq) \n    }note t1=this\n    {assume asm:\"\\<not> (\\<forall>f. ((\\<exists>sn. s =  sn) \\<and> (\\<Gamma> f) = Some Skip \\<longrightarrow> P  \\<noteq> Call f))\"\n     then obtain f where asm:\"((\\<exists>sn. s =  sn) \\<and> (\\<Gamma> f) = Some Skip \\<and> P  = Call f)\" by auto \n      then obtain sn where normal_s:\"s= sn\" by auto\n      then have t_eq_s:\"t=s\" \n        using asm cptn_nest normal_s call_f_step_not_s_eq_t_false[OF CptnModSkip(1)] \n              eq_toSeq[OF CptnModSkip.hyps(3)] CptnModSkip.hyps(2) toSeq.simps(1) \n        by blast \n     then have \"(Suc n, \\<Gamma>,((Call f),  sn)#(Skip,  sn)#xs) \\<in> cptn_mod_nest_call\"\n       using asm cptn_nest normal_s CptnModNestCall by fastforce        \n     then have ?case using asm normal_s t_eq_s by fastforce\n    }note t2 = this\n    then show ?case using t1 t2 by fastforce  \nnext\n   case (CptnModThrow \\<Gamma> P s t xs)  \n   then obtain n where cptn_nest:\"(n, \\<Gamma>, (Throw, t) # xs) \\<in> cptn_mod_nest_call\" by auto   \n    {assume asm:\"\\<forall>f. ((\\<exists>sn. s =  sn) \\<and> (\\<Gamma> f) = Some Throw \\<longrightarrow> P  \\<noteq> Call f  )\"     \n      then have ?case \n        using CptnModNestThrow[OF CptnModThrow(1) CptnModThrow(2) ] asm CptnModThrow(3)\n        using cptn_nest by blast\n    }note t1=this\n    { assume asm:\"\\<not> (\\<forall>f. ((\\<exists>sn. s =  sn) \\<and> (\\<Gamma> f) = Some Throw \\<longrightarrow> P  \\<noteq> Call f))\"\n      then obtain f where asm:\"((\\<exists>sn. s =  sn) \\<and> (\\<Gamma> f) = Some Throw \\<and> P  = Call f)\" by auto \n      then obtain sn where normal_s:\"s= sn\" by auto\n      then have t_eq_s:\"t=s\" \n        using asm cptn_nest normal_s eq_toSeq[OF CptnModThrow.hyps(3)]\n          CptnModThrow.hyps(1) \n          call_f_step_not_s_eq_t_false[OF CptnModThrow.hyps(1)]  \n        by fastforce       \n     then have \"(Suc n, \\<Gamma>,((Call f),  sn)#(Throw,  sn)#xs) \\<in> cptn_mod_nest_call\"\n       using asm cptn_nest normal_s CptnModNestCall by fastforce        \n     then have ?case using asm normal_s t_eq_s by fastforce\n    }note t2 = this\n    then show ?case using t1 t2 by fastforce\nnext\n   case (CptnModFault \\<Gamma> P s f1 t xs)  \n   then obtain n where cptn_nest:\"(n, \\<Gamma>, (Fault f1, t) # xs) \\<in> cptn_mod_nest_call\" by auto   \n    {assume asm:\"\\<forall>f. ((\\<exists>sn. s =  sn) \\<and> (\\<Gamma> f) = Some (Fault f1) \\<longrightarrow> P  \\<noteq> Call f  )\"     \n      then have ?case \n        using CptnModNestFault[OF CptnModFault(1) CptnModFault(2) ] asm CptnModFault(3)\n        using cptn_nest by blast\n    }note t1=this\n    { assume asm:\"\\<not> (\\<forall>f. ((\\<exists>sn. s =  sn) \\<and> (\\<Gamma> f) = Some (Fault f1) \\<longrightarrow> P  \\<noteq> Call f))\"\n      then obtain f where asm:\"((\\<exists>sn. s =  sn) \\<and> (\\<Gamma> f) = Some (Fault f1) \\<and> P  = Call f)\" by auto \n      then obtain sn where normal_s:\"s= sn\" by auto\n      then have t_eq_s:\"t=s\" \n        using asm cptn_nest normal_s eq_toSeq[OF CptnModFault.hyps(3)]\n          CptnModFault.hyps(1) \n          call_f_step_not_s_eq_t_false[OF CptnModFault.hyps(1)]  \n        by fastforce       \n     then have \"(Suc n, \\<Gamma>,((Call f),  sn)#(Fault f1,  sn)#xs) \\<in> cptn_mod_nest_call\"\n       using asm cptn_nest normal_s CptnModNestCall by fastforce        \n     then have ?case using asm normal_s t_eq_s by fastforce\n    }note t2 = this\n    then show ?case using t1 t2 by fastforce\nnext\n   case (CptnModStuck \\<Gamma> P s t xs)  \n   then obtain n where cptn_nest:\"(n, \\<Gamma>, (Stuck, t) # xs) \\<in> cptn_mod_nest_call\" by auto   \n    {assume asm:\"\\<forall>f. ((\\<exists>sn. s =  sn) \\<and> (\\<Gamma> f) = Some Stuck \\<longrightarrow> P  \\<noteq> Call f  )\"     \n      then have ?case \n        using CptnModNestStuck[OF CptnModStuck(1) CptnModStuck(2) ] asm CptnModStuck(3)\n        using cptn_nest by blast\n    }note t1=this\n    { assume asm:\"\\<not> (\\<forall>f. ((\\<exists>sn. s =  sn) \\<and> (\\<Gamma> f) = Some Stuck \\<longrightarrow> P  \\<noteq> Call f))\"\n      then obtain f where asm:\"((\\<exists>sn. s =  sn) \\<and> (\\<Gamma> f) = Some Stuck \\<and> P  = Call f)\" by auto \n      then obtain sn where normal_s:\"s= sn\" by auto\n      then have t_eq_s:\"t=s\" \n        using asm cptn_nest normal_s eq_toSeq[OF CptnModStuck.hyps(3)]\n          CptnModStuck.hyps(1) \n          call_f_step_not_s_eq_t_false[OF CptnModStuck.hyps(1)]  \n        by fastforce       \n     then have \"(Suc n, \\<Gamma>,((Call f),  sn)#(Stuck,  sn)#xs) \\<in> cptn_mod_nest_call\"\n       using asm cptn_nest normal_s CptnModNestCall by fastforce        \n     then have ?case using asm normal_s t_eq_s by fastforce\n    }note t2 = this\n    then show ?case using t1 t2 by fastforce\nnext\n   case (CptnModSeq2 \\<Gamma> P0 s xs P1 ys zs) \n   obtain n where n:\"(n, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call\" using CptnModSeq2(2) by auto\n   also obtain m where m:\"(m, \\<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n     using CptnModSeq2(5) by auto\n   ultimately show ?case\n   proof (cases \"n\\<ge>m\") \n     case True thus ?thesis  \n       using cptn_mod_nest_mono[of m \\<Gamma> _ n] m n CptnModSeq2 cptn_mod_nest_call.CptnModNestSeq2 by blast\n   next  \n     case False \n     thus ?thesis\n       using cptn_mod_nest_mono[of n \\<Gamma> _ m] m n CptnModSeq2 \n             cptn_mod_nest_call.CptnModNestSeq2 le_cases3 by blast      \n   qed\nnext\n   case (CptnModSeq3 \\<Gamma> P0 s xs t f s' ys zs P1) \n   obtain n where n:\"(n, \\<Gamma>, (P0,  s) # xs) \\<in> cptn_mod_nest_call\" using CptnModSeq3(2) by auto\n   also obtain m  where m:\"(m, \\<Gamma>, (t,  s') # ys) \\<in> cptn_mod_nest_call\"\n     using CptnModSeq3.hyps(7) by blast     \n   ultimately show ?case\n   proof (cases \"n\\<ge>m\") \n     case True thus ?thesis  \n       using cptn_mod_nest_mono[of m \\<Gamma> _ n] m n CptnModSeq3 cptn_mod_nest_call.CptnModNestSeq3\n       by fast\n   next  \n     case False \n     thus ?thesis\n       using cptn_mod_nest_mono[of n \\<Gamma> _ m] m n CptnModSeq3\n             cptn_mod_nest_call.CptnModNestSeq3 le_cases3\n      by (smt cptn_mod_nest_mono) \n   qed\nnext\n   case (CptnModWhile2 \\<Gamma> P s xs b zs ys) \n   obtain n where n:\"(n, \\<Gamma>, (P,  s) # xs) \\<in> cptn_mod_nest_call\" using CptnModWhile2(2) by auto\n   also obtain m where \n     m:\" (m, \\<Gamma>, (LanguageCon.com.While b P, snd (last ((P,  s) # xs))) # ys) \\<in> \n          cptn_mod_nest_call\"\n     using CptnModWhile2(7) by auto\n   ultimately show ?case\n   proof (cases \"n\\<ge>m\") \n     case True thus ?thesis  \n       using cptn_mod_nest_mono[of m \\<Gamma> _ n] m n \n             CptnModWhile2 cptn_mod_nest_call.CptnModNestWhile2 by metis\n   next  \n     case False \n     thus ?thesis       \n    proof -\n      have f1: \"\\<not> n \\<le> m \\<or> (m, \\<Gamma>, (P,  s) # xs) \\<in> cptn_mod_nest_call\"\n        using cptn_mod_nest_mono[of n \\<Gamma> _ m] n by presburger\n      have \"n \\<le> m\"\n        using False by linarith\n      then have \"(m, \\<Gamma>, (P,  s) # xs) \\<in> cptn_mod_nest_call\"\n        using f1 by metis\n      then show ?thesis\n        by (metis (no_types) CptnModWhile2(3) CptnModWhile2(4) CptnModWhile2(5) \n                  cptn_mod_nest_call.CptnModNestWhile2 m)\n    qed \n   qed\nnext\n   case (CptnModWhile3 \\<Gamma> P s xs t f b s' ys zs)\n   obtain n where n:\"(n, \\<Gamma>, (P,  s) # xs) \\<in> cptn_mod_nest_call\" \n     using CptnModWhile3(2) by auto\n   also obtain m where \n     m:\" (m, \\<Gamma>, (t,  s') # ys) \\<in> cptn_mod_nest_call\"\n     using CptnModWhile3(8) by auto\n   ultimately show ?case \n   proof (cases \"n\\<ge>m\") \n     case True thus ?thesis  \n     proof -\n      have \"(n, \\<Gamma>, (t,  s') # ys) \\<in> cptn_mod_nest_call\"\n        using True cptn_mod_nest_mono[of m \\<Gamma> _ n] m by presburger\n      then show ?thesis        \n        by (metis (no_types)  local.CptnModWhile3(3) local.CptnModWhile3(4) \n                local.CptnModWhile3(6) local.CptnModWhile3(9)\n            CptnModWhile3.hyps(5) cptn_mod_nest_call.CptnModNestWhile3 n)\n     qed \n   next  \n     case False \n     thus ?thesis  \n       using m n cptn_mod_nest_call.CptnModNestWhile3[OF n] cptn_mod_nest_mono[of n \\<Gamma> _ m]\n       by (smt  CptnModWhile3.hyps(3) CptnModWhile3.hyps(4) CptnModWhile3.hyps(5) \n        CptnModWhile3.hyps(6) CptnModWhile3.hyps(9) cptn_mod_nest_call.CptnModNestWhile3 le_cases3)\n   qed\nnext\n  case (CptnModCatch2 \\<Gamma> P0 s xs t f ys zs P1) \n  obtain n where n:\"(n, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call\" \n    using CptnModCatch2(2) by auto\n   also obtain m where m:\"(m, \\<Gamma>, (t, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n     using CptnModCatch2(6) by auto\n   ultimately show ?case\n   proof (cases \"n\\<ge>m\") \n     case True thus ?thesis  \n       using cptn_mod_nest_mono[of m \\<Gamma> _ n] m n \n             CptnModCatch2 cptn_mod_nest_call.CptnModNestCatch2 by fast\n   next  \n     case False\n     then have \"n\\<le>m\" by auto\n     thus ?thesis\n       using  False cptn_mod_nest_mono[OF n] m n CptnModCatch2 \n             CptnModNestCatch2[OF _ CptnModCatch2(3)] \n       by blast\n   qed\nnext\n  case (CptnModCatch3 \\<Gamma> P0 s xs s' ys zs P1) \n   obtain n where n:\"(n, \\<Gamma>, (P0,  s) # xs) \\<in> cptn_mod_nest_call\" \n     using CptnModCatch3(2) by auto\n   also obtain m where m:\"(m, \\<Gamma>, (ys, snd (last ((P0,  s) # xs))) # zs) \\<in> cptn_mod_nest_call\"\n     using CptnModCatch3(6) by auto\n   ultimately show ?case\n   proof (cases \"n\\<ge>m\") \n     case True thus ?thesis  \n       using cptn_mod_nest_mono[of m \\<Gamma> _ n] m n CptnModCatch3 cptn_mod_nest_call.CptnModNestCatch3\n       by blast\n   next  \n     case False \n     have f1: \"\\<not> n \\<le> m \\<or> (m, \\<Gamma>, (P0,  s) # xs) \\<in> cptn_mod_nest_call\"\n       using cptn_mod_nest_mono[of n \\<Gamma> _ m] n by presburger\n     have \"n \\<le> m\"\n       using False by auto\n     then have \"(m, \\<Gamma>, (P0,  s) # xs) \\<in> cptn_mod_nest_call\"\n       using f1 by meson\n     then show ?thesis\n       by (metis (no_types) CptnModCatch3(3,4,7) cptn_mod_nest_call.CptnModNestCatch3 m)            \n   qed\n qed(fastforce intro: cptn_mod_nest_call.intros)+\n\nlemma cptn_mod_same_n:\n  assumes a0:\"(\\<Gamma>,cfs)\\<in> cptn_mod\" \n  shows \"\\<exists>n. (n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call\"\nproof -\n show ?thesis using  cptn_mod_cptn_mod_nest\n by (metis a0 )\nqed\n\nlemma cptn_mod_same_n1:\n  assumes a0:\"(\\<Gamma>,cfs)\\<in> cptn_mod\" and \n          a1:\"(\\<Gamma>,cfs1)\\<in> cptn_mod\"\n  shows \"\\<exists>n. (n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call \\<and> (n,\\<Gamma>,cfs1) \\<in>  cptn_mod_nest_call\"\nproof -\n show ?thesis using cptn_mod_nest_mono cptn_mod_cptn_mod_nest\n by (metis a0 a1 cptn_mod_nest_mono2 leI)\nqed\n\nlemma cptn_mod_eq_cptn_mod_nest:\n  \"(\\<Gamma>,cfs)\\<in> cptn_mod \\<longleftrightarrow> (\\<exists>n. (n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call)\"\n  using cptn_mod_cptn_mod_nest cptn_mod_nest_cptn_mod by auto\n\nlemma cptn_mod_eq_cptn_mod_nest':\n  \"\\<exists>n. ((\\<Gamma>,cfs)\\<in> cptn_mod \\<longleftrightarrow> (n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call)\"\n  using cptn_mod_eq_cptn_mod_nest by auto\n\nlemma cptn_mod_eq_cptn_mod_nest1:\n  \"(\\<Gamma>,cfs)\\<in> cptn_mod = (\\<exists>n. (n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call)\"\n  using cptn_mod_cptn_mod_nest cptn_mod_nest_cptn_mod by auto\n\n\nlemma cptn_eq_cptn_mod_nest:\n  \"(\\<Gamma>,cfs)\\<in> cptn = (\\<exists>n. (n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call)\"\n  using cptn_eq_cptn_mod_set cptn_mod_cptn_mod_nest cptn_mod_nest_cptn_mod by blast\n\nsubsection \\<open>computation on nested calls limit\\<close>\nsubsection \\<open>Elimination theorems\\<close>\nlemma elim_cptn_mod_nest_step_c:\n assumes a0:\"(n,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" and\n         a1:\"cfg = (P,s)#(Q,t)#cfg1\"         \n shows \"\\<Gamma>\\<turnstile>\\<^sub>c (P,toSeq s) \\<rightarrow> (Q,toSeq t) \\<or> \\<Gamma>\\<turnstile>\\<^sub>c (P,s) \\<rightarrow>\\<^sub>e (Q,t)\"\nproof-\n  have \"(\\<Gamma>,cfg) \\<in>  cptn\" using a0 cptn_mod_nest_cptn_mod\n    using cptn_eq_cptn_mod_set by auto \n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c (P,s) \\<rightarrow>\\<^sub>c\\<^sub>e (Q,t)\" using a1\n    by (metis cptn_elim_cases(2))\n  thus ?thesis\n    using step_ce_not_step_e_step_c by blast  \nqed\n\nlemma elim_cptn_mod_nest_call_env:\n assumes a0:\"(n,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" and\n         a1:\"cfg = (P,s)#(P,t)#cfg1\"  and\n         a2:\"\\<forall>f. \\<Gamma> f = Some (LanguageCon.com.Call f) \\<and> \n                  s = t \\<longrightarrow> SmallStepCon.redex P \\<noteq> LanguageCon.com.Call f\"\n shows \"(n,\\<Gamma>,(P,t)#cfg1) \\<in>  cptn_mod_nest_call\"\n using a0 a1 a2\nproof (induct arbitrary: P cfg1 s t rule:cptn_mod_nest_call.induct ) \ncase (CptnModNestSeq1 n \\<Gamma> P0 sa xs zs P1)\n   then obtain xs' where \"xs =  (P0, t)#xs'\" unfolding lift_def by fastforce\n   then have step:\"(n, \\<Gamma>, (P0, t) # xs') \\<in> cptn_mod_nest_call\" using CptnModNestSeq1\n     apply auto\n     using CptnModNestSeq1.hyps(2) by blast             \n   have \"(P, t) = lift P1 (P0, t) \\<and> cfg1 = map (lift P1) xs'\"\n      using CptnModNestSeq1.hyps(3) CptnModNestSeq1.prems(1) \\<open>xs = (P0, t) # xs'\\<close> by auto\n    then have \"(n, \\<Gamma>, (LanguageCon.com.Seq P0 P1, t) # cfg1) \\<in> cptn_mod_nest_call\"\n      by (meson cptn_mod_nest_call.CptnModNestSeq1 local.step)\n    then show ?case\n      using CptnModNestSeq1.prems(1) by fastforce  \nnext\n  case (CptnModNestSeq2 n \\<Gamma> P0 sa xs P1 ys zs) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by fastforce\n  next\n    case (Cons x xs') \n    have x:\"x=(P0,t) \\<and> s=sa  \\<and> P = Seq P0 P1\"\n    proof-\n      have \"zs=(Seq P0 P1,t)#cfg1\" using Cons by fastforce\n      thus ?thesis using Cons(7) unfolding lift_def\n      proof -\n        assume \"zs = map (\\<lambda>a. case a of (P, s) \\<Rightarrow> (LanguageCon.com.Seq P P1, s)) (x # xs') @ \n                     (P1, snd (last ((P0, sa) # x # xs'))) # ys\"\n        then have \"LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0 P1 \\<and> snd x = t\"\n          by (simp add: \\<open>zs = (LanguageCon.com.Seq P0 P1, t) # cfg1\\<close> case_prod_beta)\n        then show ?thesis using CptnModNestSeq2.prems(1)\n          by fastforce\n      qed \n    qed\n    then have step:\"(n, \\<Gamma>, (P0, t) # xs') \\<in> cptn_mod_nest_call\" using Cons x by auto    \n    have \"fst (last ((P0, t) # xs')) = LanguageCon.com.Skip\"\n      using Cons.prems(3) x by force\n    then show ?case\n      using Cons.prems(4) Cons.prems(6) CptnModNestSeq2.prems(1) x \n            cptn_mod_nest_call.CptnModNestSeq2[OF step] by fastforce\n  qed          \nnext \n  case (CptnModNestSeq3 n \\<Gamma> P0 sa xs ta f s' ys zs P1) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs') \n    then have x:\"x=(P0,t)\" \n    proof-\n      have zs:\"zs=(Seq P0 P1,t)#cfg1\" using Cons by fastforce\n      have \"(LanguageCon.com.Seq (fst x) P1, snd x) = lift P1 x\"\n         by (simp add: lift_def prod.case_eq_if)\n      then have \"LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0 P1 \\<and> snd x = t\"\n         using Cons.prems(8) zs by fastforce\n      then show ?thesis\n        by fastforce                      \n    qed            \n    have s:\"s=sa\" using CptnModNestSeq3.prems(1) by auto\n    have P:\"P= Seq P0 P1\" using CptnModNestSeq3.prems(1) by auto\n    then have step:\"(n, \\<Gamma>, (P0, t) # xs') \\<in> cptn_mod_nest_call\" using Cons x s P by auto         \n    then obtain t' where t:\"t= t'\" by auto\n    then show ?case using x Cons(5) Cons(6) cptn_mod_nest_call.CptnModNestSeq3 step\n    proof -\n      have \"last ((P0,  t') # xs') = last ((P0,  sa) # x # xs')\"\n        using t x by force\n      then have h:\"fst (last ((P0,  t') # xs')) = ta\"\n        using Cons.prems(3) by presburger\n      show ?thesis\n        using Cons.prems(4) Cons.prems(5) Cons.prems(7) \n              CptnModNestSeq3.prems(1)  Cons.prems(6) Cons.prems(8) \n              cptn_mod_nest_call.CptnModNestSeq3[OF local.step[simplified t] h] \n              t x s P\n        by fastforce\n    qed       \n  qed       \nnext\n  case (CptnModNestCatch1 n \\<Gamma> P0 s xs zs P1) \n  then obtain xs' where \"xs =  (P0, t)#xs' \" unfolding lift_catch_def by fastforce\n  then have step:\"(n, \\<Gamma>, (P0, t) # xs') \\<in> cptn_mod_nest_call\" using CptnModNestCatch1\n    by (metis SmallStepCon.redex.simps(11) fst_conv nth_Cons_0 snd_conv)       \n  have \"(P, t) = lift_catch P1 (P0, t) \\<and> cfg1 = map (lift_catch P1) xs'\"\n    using CptnModNestCatch1.hyps(3) CptnModNestCatch1.prems(1) \\<open>xs = (P0, t) # xs'\\<close> by auto\n  then have \"(n, \\<Gamma>, (Catch P0 P1, t) # cfg1) \\<in> cptn_mod_nest_call\"\n    by (meson cptn_mod_nest_call.CptnModNestCatch1 local.step)\n  then show ?case\n    using CptnModNestCatch1.prems(1) by fastforce  \nnext\n  case (CptnModNestCatch2 n \\<Gamma> P0 sa xs ta f ys zs P1) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs') \n    then have x:\"x=(P0,t)\" \n    proof-\n      have zs:\"zs=(Catch P0 P1,t)#cfg1\" using Cons by fastforce\n      have \"(LanguageCon.com.Catch (fst x) P1, snd x) = lift_catch P1 x\"\n        by (simp add: lift_catch_def prod.case_eq_if)\n      then have \"LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0 P1 \\<and> snd x = t\"\n        using Cons.prems(7) zs by fastforce           \n      then show ?thesis\n        by fastforce                    \n    qed\n    moreover have \"s=sa \\<and> P = Catch P0 P1\"  using CptnModNestCatch2.prems(1) by auto    \n    ultimately have step:\"(n, \\<Gamma>, (P0, t) # xs') \\<in> cptn_mod_nest_call\" using Cons(3,9,10) by auto  \n    have \"fst (last ((P0, t) # xs')) = ta\"\n      using Cons.prems(3) x CptnModNestCatch2.prems(1) by auto\n    then show ?case\n      using Cons.prems(4,5) Cons.prems(7) CptnModNestCatch2.prems(1) \n            cptn_mod_nest_call.CptnModNestCatch2[OF step]  x by auto \n  qed          \nnext\n  case (CptnModNestCatch3 n \\<Gamma> P0 sa xs s' P1 ys zs) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs')\n    then have x:\"x=(P0,t) \\<and> s = sa \\<and> P = Catch P0 P1\" \n    proof-\n      have zs:\"zs=(Catch P0 P1,t)#cfg1\" using Cons by fastforce\n      thus ?thesis using Cons(8) lift_catch_def unfolding lift_def\n      proof -\n        assume \"zs = map (lift_catch P1) (x # xs') @ (P1, snd (last ((P0,  sa) # x # xs'))) # ys\"\n        then have \"LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0 P1 \\<and> snd x = t\"\n          by (simp add: case_prod_unfold lift_catch_def zs)          \n        then show ?thesis\n          using CptnModNestCatch3.prems(1) by auto\n      qed \n    qed\n    then have step:\"(n, \\<Gamma>, (P0, t) # xs') \\<in> cptn_mod_nest_call\" using Cons by auto\n    then obtain t' where t:\"t= t'\" by auto      \n    then show ?case \n      using cptn_mod_nest_call.CptnModNestCatch3[OF local.step[simplified t]]\n          Cons.prems(3,4,7) CptnModNestCatch3.hyps(4,5) CptnModNestCatch3.prems(1) x by fastforce\n  qed   \nqed(fastforce+)\n\n\nlemma elim_cptn_mod_nest_not_env_call:\n assumes a0:\"(n,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" and\n         a1:\"cfg = (P,s)#(Q,t)#cfg1\" and\n         a2:\"(\\<forall>f. redex P \\<noteq> Call f) \\<or>  \n             SmallStepCon.redex P = LanguageCon.com.Call fn \\<and> \\<Gamma> fn = None\"  \n shows \"(n,\\<Gamma>,(Q,t)#cfg1) \\<in>  cptn_mod_nest_call\"\n using a0 a1 a2\nproof (induct arbitrary: P Q cfg1 s t rule:cptn_mod_nest_call.induct )\ncase (CptnModNestSeq1 n \\<Gamma> P0 s xs zs P1)\n   then obtain P0' xs' where \"xs =  (P0', t)#xs'\" unfolding lift_def by fastforce\n   then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\" using CptnModNestSeq1 by fastforce        \n   have Q:\"(Q, t) = lift P1 (P0', t) \\<and> cfg1 = map (lift P1) xs'\"\n     using CptnModNestSeq1.hyps(3) CptnModNestSeq1.prems(1) \\<open>xs = (P0', t) # xs'\\<close> by auto\n   also then have \"(n, \\<Gamma>, (LanguageCon.com.Seq P0' P1, t) # cfg1) \\<in> cptn_mod_nest_call\"\n     by (meson cptn_mod_nest_call.CptnModNestSeq1 local.step)\n   ultimately show ?case\n     using CptnModNestSeq1.prems(1)\n     by (simp add: Cons_lift Q)   \nnext\n  case (CptnModNestSeq2 n \\<Gamma> P0 sa xs P1 ys zs) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs')\n    then have x:\"\\<exists>P0'. x=(P0',t)\" \n    proof-\n      obtain P0'' where zs: \"zs=(Seq P0'' P1,t)#cfg1\" using Cons(7) Cons(8) \n        unfolding lift_def by (simp add: Cons_eq_append_conv case_prod_beta') \n      thus ?thesis using Cons(7) unfolding lift_def\n      proof -\n        assume \"zs = map (\\<lambda>a. case a of (P, s) \\<Rightarrow> (LanguageCon.com.Seq P P1, s)) (x # xs') @ \n                     (P1, snd (last ((P0, sa) # x # xs'))) # ys\"\n        then have \"LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0'' P1 \\<and> snd x = t\"\n          by (simp add: zs case_prod_beta)\n        also have \"sa=s\" using Cons by fastforce\n        ultimately show ?thesis by (meson eq_snd_iff)           \n      qed \n    qed\n    then obtain P0' where x:\"x=(P0',t) \\<and>  s = sa \\<and> P = Seq P0 P1\"\n      using CptnModNestSeq2.prems(1) by blast \n    then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\" using Cons  by auto\n    have \"fst (last ((P0', t) # xs')) = LanguageCon.com.Skip\"\n      using Cons.prems(3) x by force\n    then show ?case\n      using Cons.prems(4) Cons.prems(6) CptnModNestSeq2.prems(1) x \n           local.step cptn_mod_nest_call.CptnModNestSeq2[of n \\<Gamma> P0' t xs' P1 ys] Cons_lift_append\n           by (metis (no_types, lifting) last_ConsR list.inject list.simps(3))        \n  qed          \nnext \n  case (CptnModNestSeq3 n \\<Gamma> P0 sa  xs c f s' ys zs P1) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs') \n    then have x:\"\\<exists>P0'. x=(P0',t)\"\n    proof-\n      obtain P0' where zs:\"zs=(Seq P0' P1,t)#cfg1\" using Cons(8) Cons(9) \n        unfolding lift_def\n        by (smt CptnModNestSeq3.prems(1) append_Cons list.sel(3) \n              list.simps(9) nth_Cons_0 prod.case_eq_if snd_conv)        \n      have \"(LanguageCon.com.Seq (fst x) P1, snd x) = lift P1 x\"\n         by (simp add: lift_def prod.case_eq_if)\n      then have \"LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0' P1 \\<and> snd x = t\"\n        using Cons.prems(8) zs by force \n      then show ?thesis by (meson eq_snd_iff)                        \n    qed\n    then obtain P0' where x:\"x=(P0',t)\" by auto\n    then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\"\n    proof -\n      have f1: \"LanguageCon.com.Seq P0 P1 = P \\<and>  sa = s\"\n        using CptnModNestSeq3.prems(1) by blast\n      then have \"SmallStepCon.redex P = SmallStepCon.redex P0\"\n        by (metis SmallStepCon.redex.simps(4))\n      then show ?thesis\n        using f1 Cons.prems(2) CptnModNestSeq3.prems(2) x by presburger\n    qed      \n    then obtain t' where t:\"t= t'\" by auto\n    then show ?case using x Cons(5) Cons(6) cptn_mod_nest_call.CptnModNestSeq3 step\n    proof -\n      have \"last ((P0',  t') # xs') = last ((P0,  sa) # x # xs')\"\n        using t x by force\n      also then have \"fst (last ((P0',  t') # xs')) = c\"\n        using Cons.prems(3) by presburger\n      ultimately show ?thesis\n        using Cons.prems(4,5,6,8) \n              CptnModNestSeq3.prems(1) cptn_mod_nest_call.CptnModNestSeq3[of n \\<Gamma> P0' t' xs' c f s' ys] \n              local.step t x  Cons_lift_append\n      by (metis (no_types, lifting) list.sel(3))               \n    qed       \n  qed       \nnext\n  case (CptnModNestCatch1 n \\<Gamma> P0 s xs zs P1) \n   then obtain P0' xs' where xs:\"xs =  (P0', t)#xs'\" unfolding lift_catch_def by fastforce\n   then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\" using CptnModNestCatch1 by fastforce        \n   have Q:\"(Q, t) = lift_catch P1 (P0', t) \\<and> cfg1 = map (lift_catch P1) xs'\"\n      using CptnModNestCatch1.hyps(3) CptnModNestCatch1.prems(1) xs by auto\n    then have \"(n, \\<Gamma>, (Catch P0' P1, t) # cfg1) \\<in> cptn_mod_nest_call\"\n      by (meson cptn_mod_nest_call.CptnModNestCatch1 local.step)\n    then show ?case\n      using CptnModNestCatch1.prems(1) by (simp add:Cons_lift_catch Q)\nnext\n  case (CptnModNestCatch2 n \\<Gamma> P0 sa xs c f ys zs P1) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs') \n    then have x:\"\\<exists>P0'. x=(P0',t)\" \n    proof-\n      obtain P0' where zs:\"zs=(Catch P0' P1,t)#cfg1\" using Cons unfolding lift_catch_def\n        by (simp add: case_prod_unfold)\n      have \"(LanguageCon.com.Catch (fst x) P1, snd x) = lift_catch P1 x\"\n         by (simp add: lift_catch_def prod.case_eq_if)\n      then have \"LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0' P1 \\<and> snd x = t\"\n         using Cons.prems(7) zs by fastforce           \n      then show ?thesis by (meson eq_snd_iff)          \n    qed\n    then obtain P0' where x:\"x=(P0',t) \\<and> s = sa \\<and> P = Catch P0 P1\" using CptnModNestCatch2.prems(1) by auto\n    then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\"     \n      using Cons.prems(2) CptnModNestCatch2.prems(1) CptnModNestCatch2.prems(2) x by auto\n    have skip:\"fst (last ((P0', t) # xs')) = c\"\n      using Cons.prems(3) x by auto\n    show ?case\n    proof -\n      have \"(P, s) # (Q, t) # cfg1 = (LanguageCon.com.Catch P0 P1, sa) # map (lift_catch P1) (x # xs') @ \n              (c, snd (last ((P0, sa) # x # xs'))) # ys\"\n        using CptnModNestCatch2.prems  Cons.prems(7) by auto\n      then show ?thesis \n        using Cons_lift_catch_append Cons.prems(4,5) \n              cptn_mod_nest_call.CptnModNestCatch2[OF local.step skip] last.simps list.distinct(1)\n              x\n        by (smt list.inject) \n    qed\n  qed          \nnext\n  case (CptnModNestCatch3 n \\<Gamma> P0 sa xs s' P1 ys zs) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs')\n    then have x:\"\\<exists>P0'. x=(P0',t)\" \n    proof-\n      obtain P0' where zs:\"zs=(Catch P0' P1,t)#cfg1\" using Cons unfolding lift_catch_def\n        by (simp add: case_prod_unfold)\n      thus ?thesis using Cons(8) lift_catch_def unfolding lift_def\n      proof -\n        assume \"zs = map (lift_catch P1) (x # xs') @ (P1, snd (last ((P0,  sa) # x # xs'))) # ys\"\n        then have \"LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0' P1 \\<and> snd x = t\"\n          by (simp add: case_prod_unfold lift_catch_def zs)          \n        then show ?thesis by (meson eq_snd_iff)  \n      qed \n    qed\n    then obtain P0' where x:\"x=(P0',t) \\<and>  s = sa \\<and>  P = Catch P0 P1\"\n      using CptnModNestCatch3.prems(1) by blast\n    then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\" using Cons\n      using Cons.prems(2) CptnModNestCatch3.prems(1) CptnModNestCatch3.prems(2) x by simp    \n    then show ?case \n    proof -\n      have \"last ((P0',  t) # xs') = last ((P0,  sa) # x # xs')\"\n        using x by force\n      also then have \"fst (last ((P0', t) # xs')) = LanguageCon.com.Throw\"\n        using Cons.prems(3) by presburger\n      ultimately show ?thesis\n        using Cons.prems(4) Cons.prems(5) Cons.prems(7) \n              CptnModNestCatch3.prems(1) cptn_mod_nest_call.CptnModNestCatch3[of n \\<Gamma> P0' t xs' s' P1] \n              local.step  x by (metis Cons_lift_catch_append list.sel(3)) \n    qed\n  qed\nnext\ncase (CptnModNestWhile1 n \\<Gamma> P0 s' xs b zs) \n  thus ?case\n   using cptn_mod_nest_call.CptnModNestSeq1 list.inject by blast   \nnext\n  case (CptnModNestWhile2 n \\<Gamma> P0 s' xs b zs ys)  \n  have \"(LanguageCon.com.While b P0,  s') = (P, s) \\<and> \n        (LanguageCon.com.Seq P0 (LanguageCon.com.While b P0),  s') # zs = (Q, t) # cfg1\"\n    using CptnModNestWhile2.prems by fastforce\n  then show ?case\n    using CptnModNestWhile2.hyps(1) CptnModNestWhile2.hyps(3) \n          CptnModNestWhile2.hyps(5) CptnModNestWhile2.hyps(6) \n          cptn_mod_nest_call.CptnModNestSeq2 by blast\nnext\n  case (CptnModNestWhile3 n \\<Gamma> P0 s' xs b zs) thus ?case\n    by (metis (no_types) CptnModNestWhile3.hyps(1,3,6) CptnModNestWhile3.prems(1)\n                         cptn_mod_nest_call.CptnModNestSeq3 list.inject)  \nqed(fastforce+)\n\nlemma elim_cptn_mod_nest_call_n_greater_zero:\n assumes a0:\"(n,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" and\n         a1:\"cfg = (P, s)#(Q,t)#cfg1 \\<and> P = Call f \\<and> \\<Gamma> f = Some Q \\<and> P\\<noteq>Q\"\n shows  \"n>0\" \n  using a0 a1 by (induct rule:cptn_mod_nest_call.induct, fast+)\n\n\nlemma elim_cptn_mod_nest_call_0_False:\n assumes a0:\"(0,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" and\n         a1:\"cfg = (P, s)#(Q,t)#cfg1 \\<and> P = Call f \\<and> \\<Gamma> f = Some Q \\<and> P\\<noteq>Q\"\nshows \"PP\"\nusing a0 a1 elim_cptn_mod_nest_call_n_greater_zero \nby fast\n\nlemma elim_cptn_mod_nest_call_n_dec1:\n assumes a0:\"(n,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" and\n         a1:\"cfg = (P, s)#(Q,t)#cfg1 \\<and> P = Call f \\<and> \\<Gamma> f = Some Q \\<and> t=  s \\<and> P\\<noteq>Q\"\n shows \"(n-1,\\<Gamma>,(Q,t)#cfg1) \\<in>  cptn_mod_nest_call\"\n using a0 a1 \n  by (induct rule:cptn_mod_nest_call.induct,force+)\n\nlemma elim_cptn_mod_nest_call_n_dec:\n assumes a0:\"(n,\\<Gamma>,(Call f, s)#(the (\\<Gamma> f), s)#cfg1) \\<in>  cptn_mod_nest_call\" and\n         a1:\"\\<Gamma> f = Some Q \" and a2:\"Call f\\<noteq>the (\\<Gamma> f)\"\n       shows \"(n-1,\\<Gamma>,(the (\\<Gamma> f), s)#cfg1) \\<in>  cptn_mod_nest_call\"\n  using elim_cptn_mod_nest_call_n_dec1[OF a0] a1 a2\n  by fastforce\n\n\nlemma elim_cptn_mod_nest_call_n:\n assumes a0:\"(n,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" and\n         a1:\"cfg = (P, s)#(Q,t)#cfg1\"          \n shows \"(n,\\<Gamma>,(Q,t)#cfg1) \\<in>  cptn_mod_nest_call\"\n using a0 a1 \nproof (induct arbitrary: P Q cfg1 s t rule:cptn_mod_nest_call.induct )\ncase (CptnModNestCall n \\<Gamma> bdy sa ys p)\n  thus ?case using cptn_mod_nest_mono1 list.inject by blast\nnext \ncase (CptnModNestSeq1 n \\<Gamma> P0 s xs zs P1) \n   then obtain P0' xs' where \"xs =  (P0', t)#xs'\" unfolding lift_def by fastforce\n   then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\" using CptnModNestSeq1 by fastforce        \n   have Q:\"(Q, t) = lift P1 (P0', t) \\<and> cfg1 = map (lift P1) xs'\"\n     using CptnModNestSeq1.hyps(3) CptnModNestSeq1.prems(1) \\<open>xs = (P0', t) # xs'\\<close> by auto\n   also then have \"(n, \\<Gamma>, (LanguageCon.com.Seq P0' P1, t) # cfg1) \\<in> cptn_mod_nest_call\"\n     by (meson cptn_mod_nest_call.CptnModNestSeq1 local.step)\n   ultimately show ?case\n     using CptnModNestSeq1.prems(1)\n     by (simp add: Cons_lift Q)   \nnext\n  case (CptnModNestSeq2 n \\<Gamma> P0 sa xs P1 ys zs) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs')\n    then have x:\"\\<exists>P0'. x=(P0',t)\" \n    proof-\n      obtain P0'' where zs: \"zs=(Seq P0'' P1,t)#cfg1\" using Cons(7) Cons(8) \n        unfolding lift_def by (simp add: Cons_eq_append_conv case_prod_beta') \n      thus ?thesis using Cons(7) unfolding lift_def\n      proof -\n        assume \"zs = map (\\<lambda>a. case a of (P, s) \\<Rightarrow> (LanguageCon.com.Seq P P1, s)) (x # xs') @ \n                     (P1, snd (last ((P0, sa) # x # xs'))) # ys\"\n        then have \"LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0'' P1 \\<and> snd x = t\"\n          by (simp add: zs case_prod_beta)\n        also have \"sa=s\" using Cons by fastforce\n        ultimately show ?thesis by (meson eq_snd_iff)           \n      qed \n    qed\n    then obtain P0' where x:\"x=(P0',t)\" by auto\n    then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\" using Cons\n      by blast \n    have \"fst (last ((P0', t) # xs')) = LanguageCon.com.Skip\"\n      using Cons.prems(3) x by force\n    then show ?case\n      using Cons.prems(4) Cons.prems(6) CptnModNestSeq2.prems(1) x \n           local.step cptn_mod_nest_call.CptnModNestSeq2[of n \\<Gamma> P0' t xs' P1 ys] Cons_lift_append\n           by (metis (no_types, lifting) last_ConsR list.inject list.simps(3))        \n  qed          \nnext \n  case (CptnModNestSeq3 n \\<Gamma> P0 sa xs c f s' ys zs P1) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs') \n    then have x:\"\\<exists>P0'. x=(P0',t)\"\n    proof-\n      obtain P0' where zs:\"zs=(Seq P0' P1,t)#cfg1\" using Cons(8) Cons(9) CptnModNestSeq3.prems\n        unfolding lift_def  \n        by (smt  append_Cons list.sel(3) \n              list.simps(9) nth_Cons_0 prod.case_eq_if snd_conv)\n      have \"(LanguageCon.com.Seq (fst x) P1, snd x) = lift P1 x\"\n         by (simp add: lift_def prod.case_eq_if)\n      then have \"LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0' P1 \\<and> snd x = t\"\n         using zs by (simp add: Cons.prems(8)) \n      then show ?thesis by (meson eq_snd_iff)                        \n    qed\n    then obtain P0' where x:\"x=(P0',t) \\<and>  s = sa \\<and> P = Seq P0 P1\"\n      using CptnModNestSeq3.prems by blast\n    then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\" using Cons by auto         \n    then show ?case using x Cons(5) Cons(6) cptn_mod_nest_call.CptnModNestSeq3 step\n    proof -\n      have \"last ((P0', t) # xs') = last ((P0,  sa) # x # xs')\"\n        using  x by force\n      also then have \"fst (last ((P0', t) # xs')) = c\"\n        using Cons.prems(3) by presburger\n      ultimately show ?thesis\n        using Cons.prems(4,5,6,8)\n              CptnModNestSeq3.prems(1) cptn_mod_nest_call.CptnModNestSeq3[of n \\<Gamma> P0' t xs' c f s' ys] \n              local.step  x  Cons_lift_append\n      by (metis (no_types, lifting) list.sel(3))               \n    qed       \n  qed       \nnext\n  case (CptnModNestCatch1 n \\<Gamma> P0 s xs zs P1) \n   then obtain P0' xs' where xs:\"xs =  (P0', t)#xs'\" unfolding lift_catch_def by fastforce\n   then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\" using CptnModNestCatch1 by fastforce        \n   have Q:\"(Q, t) = lift_catch P1 (P0', t) \\<and> cfg1 = map (lift_catch P1) xs'\"\n      using CptnModNestCatch1.hyps(3) CptnModNestCatch1.prems(1) xs by auto\n    then have \"(n, \\<Gamma>, (Catch P0' P1, t) # cfg1) \\<in> cptn_mod_nest_call\"\n      by (meson cptn_mod_nest_call.CptnModNestCatch1 local.step)\n    then show ?case\n      using CptnModNestCatch1.prems(1) by (simp add:Cons_lift_catch Q)\nnext\n  case (CptnModNestCatch2 n \\<Gamma> P0 sa xs c f ys zs P1) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs') \n    then have x:\"\\<exists>P0'. x=(P0',t)\" \n    proof-\n      obtain P0' where zs:\"zs=(Catch P0' P1,t)#cfg1\" using Cons unfolding lift_catch_def\n        by (simp add: case_prod_unfold)\n      have \"(LanguageCon.com.Catch (fst x) P1, snd x) = lift_catch P1 x\"\n         by (simp add: lift_catch_def prod.case_eq_if)\n      then have \"LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0' P1 \\<and> snd x = t\"\n         using Cons.prems(6,7) zs by fastforce           \n      then show ?thesis by (meson eq_snd_iff)          \n    qed\n    then obtain P0' where x:\"x=(P0',t) \\<and>  s = sa \\<and> P = Catch P0 P1\" using CptnModNestCatch2.prems by auto\n    then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\" using Cons by auto             \n    have skip:\"fst (last ((P0', t) # xs')) = c\"\n      using Cons.prems(3) x by auto\n    show ?case\n    proof -\n      have \"(P, s) # (Q, t) # cfg1 = (LanguageCon.com.Catch P0 P1, sa) # map (lift_catch P1) (x # xs') @ \n              (c, snd (last ((P0, sa) # x # xs'))) # ys\"\n        using CptnModNestCatch2.prems  Cons.prems(6,7) by auto\n      then show ?thesis \n        using Cons_lift_catch_append Cons.prems(5,6,7) \n              cptn_mod_nest_call.CptnModNestCatch2[OF local.step skip Cons.prems(4) _ ] last.simps list.distinct(1)\n              x\n        by (metis (no_types)  list.sel(3) )\n    qed\n  qed          \nnext\n  case (CptnModNestCatch3 n \\<Gamma> P0 sa xs s' P1 ys zs) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs')\n    then have x:\"\\<exists>P0'. x=(P0',t)\" \n    proof-\n      obtain P0' where zs:\"zs=(Catch P0' P1,t)#cfg1\" using Cons unfolding lift_catch_def\n        by (simp add: case_prod_unfold)\n      thus ?thesis using Cons(8) lift_catch_def unfolding lift_def\n      proof -\n        assume \"zs = map (lift_catch P1) (x # xs') @ (P1, snd (last ((P0,  sa) # x # xs'))) # ys\"\n        then have \"LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0' P1 \\<and> snd x = t\"\n          by (simp add: case_prod_unfold lift_catch_def zs)          \n        then show ?thesis by (meson eq_snd_iff)  \n      qed \n    qed\n    then obtain P0' where x:\"x=(P0',t)\" by auto\n    then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\" using Cons by simp    \n    then show ?case \n    proof -\n      have \"last ((P0', t) # xs') = last ((P0,  sa) # x # xs')\"\n        using  x by force\n      also then have \"fst (last ((P0', t) # xs')) = LanguageCon.com.Throw\"\n        using Cons.prems(3) by presburger\n      ultimately show ?thesis\n        using Cons.prems(4,5,7) \n              CptnModNestCatch3.prems(1) cptn_mod_nest_call.CptnModNestCatch3[of n \\<Gamma> P0' t xs' s' P1] \n              local.step x by (metis Cons_lift_catch_append list.sel(3)) \n    qed\n  qed\nnext\ncase (CptnModNestWhile1 n \\<Gamma> P0 s' xs b zs) \n  thus ?case\n   using cptn_mod_nest_call.CptnModNestSeq1 list.inject by blast   \nnext\n  case (CptnModNestWhile2 n \\<Gamma> P0 s' xs b zs ys)  \n  have \"(LanguageCon.com.While b P0,  s') = (P, s) \\<and> \n        (LanguageCon.com.Seq P0 (LanguageCon.com.While b P0),  s') # zs = (Q, t) # cfg1\"\n    using CptnModNestWhile2.prems by fastforce\n  then show ?case\n    using CptnModNestWhile2.hyps(1) CptnModNestWhile2.hyps(3) \n          CptnModNestWhile2.hyps(5) CptnModNestWhile2.hyps(6) \n          cptn_mod_nest_call.CptnModNestSeq2 by blast\nnext\n  case (CptnModNestWhile3 n \\<Gamma> P0 s' xs b zs) thus ?case\n    by (metis (no_types) CptnModNestWhile3.hyps(1,3,6) CptnModNestWhile3.prems \n                         cptn_mod_nest_call.CptnModNestSeq3 list.inject)  \nqed (fastforce+) \n\nlemma dropcptn_is_cptn1 [rule_format,elim!]:\n  \"\\<forall>j<length c. (n,\\<Gamma>,c) \\<in> cptn_mod_nest_call \\<longrightarrow> (n,\\<Gamma>, drop j c) \\<in> cptn_mod_nest_call\"\nproof -\n  {fix j\n   assume \"j<length c \\<and> (n,\\<Gamma>,c) \\<in> cptn_mod_nest_call\"\n   then have \"(n,\\<Gamma>, drop j c) \\<in> cptn_mod_nest_call\" \n   proof(induction j arbitrary: c)\n     case 0 then show ?case by auto\n   next\n     case (Suc j) \n     then obtain a b c' where \"c=a#b#c'\"\n       by (metis (no_types, hide_lams) Suc_less_eq length_Cons list.exhaust list.size(3) not_less0)\n     then also have \"j<length (b#c')\" using Suc by auto\n     ultimately moreover have \"(n, \\<Gamma>, drop j (b # c')) \\<in> cptn_mod_nest_call\" using elim_cptn_mod_nest_call_n[of n \\<Gamma> c] Suc\n       by (metis surj_pair) \n     ultimately show ?case by auto  \n   qed\n } thus ?thesis by auto \nqed\n\ndefinition min_call where\n\"min_call n \\<Gamma> cfs \\<equiv> (n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call \\<and> (\\<forall>m<n. \\<not>((m,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call))\"\n\nlemma minimum_nest_call:\n  \"(m,\\<Gamma>,cfs) \\<in> cptn_mod_nest_call \\<Longrightarrow>\n   \\<exists>n. min_call n \\<Gamma> cfs\"\nunfolding min_call_def\nproof (induct arbitrary: m rule:cptn_mod_nest_call.induct) \n case (CptnModNestOne) thus ?case using cptn_mod_nest_call.CptnModNestOne by blast \nnext\n  case (CptnModNestEnv \\<Gamma> P s t n xs) \n  then have \"\\<not> \\<Gamma>\\<turnstile>\\<^sub>c (P, toSeq s) \\<rightarrow> (P, toSeq t)\" \n   using mod_env_not_component step_change_p_or_eq_s by fastforce \n  then obtain min_n where min:\"(min_n, \\<Gamma>, (P, t) # xs) \\<in> cptn_mod_nest_call \\<and> \n                             (\\<forall>m<min_n.  (m, \\<Gamma>, (P, t) # xs) \\<notin> cptn_mod_nest_call)\" \n    using CptnModNestEnv by blast\n  then have  \"(min_n, \\<Gamma>, (P,s)#(P, t) # xs) \\<in> cptn_mod_nest_call\"     \n    using cptn_mod_nest_call.CptnModNestEnv CptnModNestEnv by blast\n  also have \"(\\<forall>m<min_n. (m, \\<Gamma>, (P, s)#(P, t) # xs) \\<notin> cptn_mod_nest_call)\"\n    using elim_cptn_mod_nest_call_n min by blast    \n  ultimately show ?case by auto  \nnext\n  case (CptnModNestSkip \\<Gamma> P s t n xs)    \n  then obtain min_n where \n     min:\"(min_n, \\<Gamma>, (LanguageCon.com.Skip, t) # xs) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_n. (m, \\<Gamma>, (LanguageCon.com.Skip, t) # xs) \\<notin> cptn_mod_nest_call)\" \n    by auto\n  then have \"(min_n, \\<Gamma>, (P,s)#(LanguageCon.com.Skip, t) # xs) \\<in> cptn_mod_nest_call\"\n    using cptn_mod_nest_call.CptnModNestSkip CptnModNestSkip by blast\n  also have \"(\\<forall>m<min_n. (m, \\<Gamma>, (P, s)#(LanguageCon.com.Skip, t) # xs) \\<notin> cptn_mod_nest_call)\"\n    using elim_cptn_mod_nest_call_n min by blast      \n  ultimately show ?case by fastforce   \nnext\n  case (CptnModNestThrow \\<Gamma> P s t n xs) thus ?case    \n    using elim_cptn_mod_nest_call_n[OF CptnModNestThrow(5)] \n    by (metis (no_types, lifting) cptn_mod_nest_call.CptnModNestThrow elim_cptn_mod_nest_call_n)    \nnext\n  case (CptnModNestStuck \\<Gamma> P s t n xs) thus ?case    \n    using elim_cptn_mod_nest_call_n[OF CptnModNestStuck(5)] \n    by (metis (no_types, lifting) cptn_mod_nest_call.CptnModNestStuck elim_cptn_mod_nest_call_n)\nnext\n  case (CptnModNestFault \\<Gamma> P s f t n xs) thus ?case    \n    using elim_cptn_mod_nest_call_n[OF CptnModNestFault(5)] \n     by (metis (no_types, lifting) cptn_mod_nest_call.CptnModNestFault elim_cptn_mod_nest_call_n)\nnext\n  case (CptnModNestCondT n \\<Gamma> P0 s xs b P1) thus ?case\n    by (meson cptn_mod_nest_call.CptnModNestCondT elim_cptn_mod_nest_call_n)\nnext\n  case (CptnModNestCondF n \\<Gamma> P1 s xs b P0) thus ?case\n    by (meson cptn_mod_nest_call.CptnModNestCondF elim_cptn_mod_nest_call_n)\nnext\n  case (CptnModNestSeq1 n \\<Gamma> P s xs zs Q) thus ?case\n    by (metis (no_types, lifting) Seq_P_Not_finish cptn_mod_nest_call.CptnModNestSeq1 div_seq_nest)\nnext\n  case (CptnModNestSeq2 n \\<Gamma> P s xs Q ys zs) \n  then obtain min_p where \n     min_p:\"(min_p, \\<Gamma>, (P,  s) # xs) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_p. (m, \\<Gamma>, (P, s) # xs) \\<notin> cptn_mod_nest_call)\" \n    by auto \n  from CptnModNestSeq2(5) obtain min_q where\n    min_q:\"(min_q, \\<Gamma>, (Q, snd (last ((P, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_q. (m, \\<Gamma>, (Q, snd (last ((P, s) # xs))) # ys) \\<notin> cptn_mod_nest_call)\"\n  by auto\n  thus ?case\n  proof(cases \"min_p\\<ge>min_q\")\n    case True\n    then have \"(min_p, \\<Gamma>, (Q, snd (last ((P,s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n      using min_q using cptn_mod_nest_mono by blast \n    then have \"(min_p, \\<Gamma>, (Seq P Q, s) # zs) \\<in> cptn_mod_nest_call\"\n      using conjunct1[OF min_p] cptn_mod_nest_call.CptnModNestSeq2[of min_p \\<Gamma> P s xs Q ys zs] \n            CptnModNestSeq2(6)  CptnModNestSeq2(3)\n    by blast\n    also have \"\\<forall>m<min_p. (m, \\<Gamma>,(Seq P Q,s) # zs) \\<notin> cptn_mod_nest_call\"\n      by (metis CptnModNestSeq2.hyps(3) CptnModNestSeq2.hyps(6) Seq_P_Ends_Normal div_seq_nest min_p)      \n    ultimately show ?thesis by auto                                                    \n  next\n    case False \n    then have \"(min_q, \\<Gamma>, (P,  s) # xs) \\<in> cptn_mod_nest_call\"\n      using min_p cptn_mod_nest_mono by force \n    then have \"(min_q, \\<Gamma>, (Seq P Q, s) # zs) \\<in> cptn_mod_nest_call\"\n      using conjunct1[OF min_q] cptn_mod_nest_call.CptnModNestSeq2[of min_q \\<Gamma> P s xs Q ys zs] \n            CptnModNestSeq2(6)  CptnModNestSeq2(3)\n    by blast\n    also have \"\\<forall>m<min_q. (m, \\<Gamma>,(Seq P Q,s) # zs) \\<notin> cptn_mod_nest_call\"\n     proof -\n      {fix m\n      assume min_m:\"m<min_q\"\n      then have \"(m, \\<Gamma>,(Seq P Q, s) # zs) \\<notin> cptn_mod_nest_call\"\n      proof -\n      {assume ass:\"(m, \\<Gamma>, (Seq P Q, s) # zs) \\<in> cptn_mod_nest_call\"\n       then obtain xs' s' s'' where \n          m_cptn:\"(m, \\<Gamma>, (P, s) # xs') \\<in> cptn_mod_nest_call \\<and> \n                   seq_cond_nest zs Q xs' P s s'' s' \\<Gamma> m\" \n         using  \n          div_seq_nest[of m \\<Gamma> \"(LanguageCon.com.Seq P Q, s) # zs\"]\n          by fastforce\n       then have \"seq_cond_nest zs Q xs' P s s'' s' \\<Gamma> m\" by auto\n       then have ?thesis\n         using Seq_P_Ends_Normal[OF CptnModNestSeq2(6) CptnModNestSeq2(3) ass]\n               min_m min_q \n         by (metis last_length)          \n      } thus ?thesis by auto\n      qed\n      }thus ?thesis by auto\n    qed  \n    ultimately show ?thesis by auto\n  qed\nnext\n  case (CptnModNestSeq3 n \\<Gamma> P s xs c f s' ys zs Q) \n  then obtain min_p where \n     min_p:\"(min_p, \\<Gamma>, (P,  s) # xs) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_p. (m, \\<Gamma>, (P,  s) # xs) \\<notin> cptn_mod_nest_call)\" \n    by auto \n  from CptnModNestSeq3(6,7) obtain min_q where\n    min_q:\"(min_q, \\<Gamma>, (c,  s') # ys) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_q. (m, \\<Gamma>, (c,  s') # ys) \\<notin> cptn_mod_nest_call)\"\n  by auto\n  thus ?case\n  proof(cases \"min_p\\<ge>min_q\")\n    case True \n    then have \"(min_p, \\<Gamma>, (c,  s') # ys) \\<in> cptn_mod_nest_call\"\n      using min_q using cptn_mod_nest_mono by blast \n    then have \"(min_p, \\<Gamma>, (Seq P Q,  s) # zs) \\<in> cptn_mod_nest_call\"\n      using conjunct1[OF min_p] cptn_mod_nest_call.CptnModNestSeq3[of min_p \\<Gamma> P s xs c f s' ys zs Q] \n            CptnModNestSeq3(3,4,5,6,8)\n    by blast\n    also have \"\\<forall>m<min_p. (m, \\<Gamma>,(Seq P Q, s) # zs) \\<notin> cptn_mod_nest_call\"\n      by (metis CptnModNestSeq3.hyps(3,4,5,8) Seq_P_Ends_Abort div_seq_nest min_p)\n    ultimately show ?thesis by auto\n  next\n    case False\n    then have \"(min_q, \\<Gamma>, (P,   s) # xs) \\<in> cptn_mod_nest_call\"\n      using min_p cptn_mod_nest_mono by force \n    then have \"(min_q, \\<Gamma>, (Seq P Q,  s) # zs) \\<in> cptn_mod_nest_call\"\n      using conjunct1[OF min_q] cptn_mod_nest_call.CptnModNestSeq3[of min_q \\<Gamma> P s xs c f s' ys zs Q] \n            CptnModNestSeq3(3,4,5,8)\n    by blast\n    also have \"\\<forall>m<min_q. (m, \\<Gamma>,(Seq P Q, s) # zs) \\<notin> cptn_mod_nest_call\"\n      by (metis CptnModNestSeq3.hyps(3,4,5,8) Seq_P_Ends_Abort div_seq_nest min_q)     \n    ultimately show ?thesis by auto\n  qed \nnext\n  case (CptnModNestWhile1 n \\<Gamma> P s xs b zs) \n  then obtain min_n where \n     min:\"(min_n, \\<Gamma>, (P,  s) # xs) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_n. (m, \\<Gamma>, (P,  s) # xs) \\<notin> cptn_mod_nest_call)\" \n    by auto\n  then have \"(min_n, \\<Gamma>, (While b P,  s) # (Seq P (While b P),  s) # zs) \\<in> cptn_mod_nest_call\"\n    using cptn_mod_nest_call.CptnModNestWhile1[of min_n \\<Gamma> P s xs  b zs] CptnModNestWhile1\n    by meson \n  also have \"\\<forall>m<min_n. (m, \\<Gamma>,(While b P,  s) # (Seq P (While b P),  s) # zs) \\<notin> cptn_mod_nest_call\"\n    by (metis CptnModNestWhile1.hyps(4) Seq_P_Not_finish div_seq_nest elim_cptn_mod_nest_call_n min) \n  ultimately show ?case by auto\nnext\n  case (CptnModNestWhile2 n \\<Gamma> P s xs b zs ys) \n  then obtain min_n_p where \n     min_p:\"(min_n_p, \\<Gamma>, (P,  s) # xs) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_n_p. (m, \\<Gamma>, (P,  s) # xs) \\<notin> cptn_mod_nest_call)\" \n    by auto\n  from CptnModNestWhile2 obtain min_n_w where\n     min_w:\"(min_n_w, \\<Gamma>, (LanguageCon.com.While b P, snd (last ((P,  s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_n_w. (m, \\<Gamma>, (LanguageCon.com.While b P, snd (last ((P,  s) # xs))) # ys)\n               \\<notin> cptn_mod_nest_call)\"\n    by auto\n  thus ?case \n  proof (cases \"min_n_p\\<ge>min_n_w\")\n    case True \n    then have \"(min_n_p, \\<Gamma>, \n      (LanguageCon.com.While b P, snd (last ((P,  s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n      using min_w using cptn_mod_nest_mono by blast \n    then have \"(min_n_p, \\<Gamma>, (While b P,  s) # (Seq P (While b P),  s) # zs) \\<in> cptn_mod_nest_call\"\n      using min_p cptn_mod_nest_call.CptnModNestWhile2[of min_n_p \\<Gamma> P s xs b zs] CptnModNestWhile2\n      by blast\n    also have \"\\<forall>m<min_n_p. (m, \\<Gamma>,(While b P,  s) # (Seq P (While b P),  s) # zs) \\<notin> cptn_mod_nest_call\"\n      by (metis CptnModNestWhile2.hyps(3) CptnModNestWhile2.hyps(5) \n                Seq_P_Ends_Normal div_seq_nest elim_cptn_mod_nest_call_n min_p)    \n    ultimately show ?thesis by auto  \n  next\n    case False\n    then have False:\"min_n_p<min_n_w\" by auto\n    then have \"(min_n_w, \\<Gamma>, (P,  s) # xs) \\<in> cptn_mod_nest_call\"\n      using min_p  cptn_mod_nest_mono by force \n    then have \"(min_n_w, \\<Gamma>, (While b P, s) # (Seq P (While b P),  s) # zs) \\<in> cptn_mod_nest_call\"\n      using min_w min_p cptn_mod_nest_call.CptnModNestWhile2[of min_n_w \\<Gamma> P s xs b zs] CptnModNestWhile2\n      by blast\n    also have \"\\<forall>m<min_n_w. (m, \\<Gamma>,(While b P,  s) # (Seq P (While b P),  s) # zs) \\<notin> cptn_mod_nest_call\"      \n    proof -\n      {fix m\n      assume min_m:\"m<min_n_w\"\n      then have \"(m, \\<Gamma>,(While b P,  s) # (Seq P (While b P),  s) # zs) \\<notin> cptn_mod_nest_call\"\n      proof -\n      {assume \"(m, \\<Gamma>,(While b P,  s) # (Seq P (While b P),  s) # zs) \\<in> cptn_mod_nest_call\"\n       then have a1:\"(m, \\<Gamma>,(Seq P (While b P),  s) # zs) \\<in> cptn_mod_nest_call\"               \n         by (meson elim_cptn_mod_nest_call_n)\n       then obtain xs' s' s'' where \n          m_cptn:\"(m, \\<Gamma>, (P,  s) # xs') \\<in> cptn_mod_nest_call  \\<and> \n                   seq_cond_nest zs (While b P) xs' P ( s) s'' s' \\<Gamma> m\" \n         using  \n          div_seq_nest[of m \\<Gamma> \"(LanguageCon.com.Seq P (LanguageCon.com.While b P),  s) # zs\"]\n          by fastforce\n       then have \"seq_cond_nest zs (While b P) xs' P ( s) s'' s' \\<Gamma> m\" by auto\n       then have ?thesis unfolding seq_cond_nest_def\n         by (metis CptnModNestWhile2.hyps(3) CptnModNestWhile2.hyps(5) Seq_P_Ends_Normal a1 last_length m_cptn min_m min_w)           \n     } thus ?thesis by auto\n     qed\n     }thus ?thesis by auto\n    qed\n    ultimately show ?thesis by auto\n  qed\nnext\n  case (CptnModNestWhile3 n \\<Gamma> P s xs c f b s' ys zs) \n  then obtain min_n_p where \n     min_p:\"(min_n_p, \\<Gamma>, (P,  s) # xs) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_n_p. (m, \\<Gamma>, (P,  s) # xs) \\<notin> cptn_mod_nest_call)\" \n    by auto\n  from CptnModNestWhile3 obtain min_n_w where\n     min_w:\"(min_n_w, \\<Gamma>, (c, snd (last ((P,  s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_n_w. (m, \\<Gamma>, (c, snd (last ((P,  s) # xs))) # ys)\n               \\<notin> cptn_mod_nest_call)\"\n    by auto\n  thus ?case \n  proof (cases \"min_n_p\\<ge>min_n_w\")\n    case True \n    then have \"(min_n_p, \\<Gamma>, \n      (c, snd (last ((P,  s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n      using min_w using cptn_mod_nest_mono by blast \n    then have \"(min_n_p, \\<Gamma>, (While b P,  s) # (Seq P (While b P),  s) # zs) \\<in> cptn_mod_nest_call\"\n      using min_p cptn_mod_nest_call.CptnModNestWhile3[of min_n_p \\<Gamma> P s xs c f b s' ys zs] \n            CptnModNestWhile3\n      by fastforce\n    also have \"\\<forall>m<min_n_p. (m, \\<Gamma>,(While b P,  s) # (Seq P (While b P),  s) # zs) \\<notin> cptn_mod_nest_call\"\n      by (metis CptnModNestWhile3.hyps(3,4,6,9) \n            Seq_P_Ends_Abort div_seq_nest elim_cptn_mod_nest_call_n min_p)    \n    ultimately show ?thesis by auto  \n  next\n    case False\n    then have False:\"min_n_p<min_n_w\" by auto\n    then have \"(min_n_w, \\<Gamma>, (P,  s) # xs) \\<in> cptn_mod_nest_call\"\n      using min_p  cptn_mod_nest_mono by force \n    then have \"(min_n_w, \\<Gamma>, (While b P,  s) # (Seq P (While b P),  s) # zs) \\<in> cptn_mod_nest_call\"\n      using min_w min_p cptn_mod_nest_call.CptnModNestWhile3[of min_n_w \\<Gamma> P s xs c f b s' ys zs] \n            CptnModNestWhile3\n      by fastforce      \n    also have \"\\<forall>m<min_n_w. (m, \\<Gamma>,(While b P, s) # (Seq P (While b P),  s) # zs) \\<notin> cptn_mod_nest_call\"\n    proof -\n      {fix m\n      assume min_m:\"m<min_n_w\"\n      then have \"(m, \\<Gamma>,(While b P,  s) # (Seq P (While b P),  s) # zs) \\<notin> cptn_mod_nest_call\"\n      proof -\n      {assume \"(m, \\<Gamma>,(While b P,  s) # (Seq P (While b P),  s) # zs) \\<in> cptn_mod_nest_call\"\n       then have s1:\"(m, \\<Gamma>,(Seq P (While b P),  s) # zs) \\<in> cptn_mod_nest_call\"      \n         using elim_cptn_mod_nest_not_env_call\n         by (meson elim_cptn_mod_nest_call_n) \n       then obtain xs' s' s'' where \n          m_cptn:\"(m, \\<Gamma>, (P,  s) # xs') \\<in> cptn_mod_nest_call  \\<and> \n                   seq_cond_nest zs (While b P) xs' P ( s) s'' s' \\<Gamma> m\" \n         using  \n          div_seq_nest[of m \\<Gamma> \"(LanguageCon.com.Seq P (LanguageCon.com.While b P),  s) # zs\"]\n          by fastforce\n       then have \"seq_cond_nest zs (While b P) xs' P s s'' s' \\<Gamma> m\" by auto\n       then have ?thesis unfolding seq_cond_nest_def\n         by (metis CptnModNestWhile3.hyps(3,4,6,9) Seq_P_Ends_Abort s1 m_cptn min_m min_w)       \n     } thus ?thesis by auto\n     qed\n     }thus ?thesis by auto\n    qed\n    ultimately show ?thesis by auto\n  qed\nnext\n  case (CptnModNestCall n \\<Gamma> bdy s xs f) thus ?case\n  proof -\n    { fix nn :: \"nat \\<Rightarrow> nat\"\n     obtain nna :: nat where\n      ff1: \"(nna, \\<Gamma>, (bdy,  s) # xs) \\<in> cptn_mod_nest_call \\<and> (\\<forall>n. \\<not> n < nna \\<or> (n, \\<Gamma>, (bdy,  s) # xs) \\<notin> cptn_mod_nest_call)\"\n      by (meson CptnModNestCall.hyps(2))\n    moreover\n    { assume \"(nn (nn (Suc nna)), \\<Gamma>, (bdy,  s) # xs) \\<in> cptn_mod_nest_call\"\n      then have \"\\<not> Suc (nn (nn (Suc nna))) < Suc nna\"\n        using ff1 by blast\n      then have \"(nn (Suc nna), \\<Gamma>, (LanguageCon.com.Call f,  s) # (bdy,  s) # xs) \\<in> cptn_mod_nest_call \\<longrightarrow> (\\<exists>n. (n, \\<Gamma>, (LanguageCon.com.Call f,  s) # (bdy,  s) # xs) \\<in> cptn_mod_nest_call \\<and> \n                (\\<not> nn n < n \\<or> (nn n, \\<Gamma>, (LanguageCon.com.Call f,  s) # (bdy,  s) # xs) \\<notin> cptn_mod_nest_call))\"\n        using ff1 by (meson CptnModNestCall.hyps(3) CptnModNestCall.hyps(4) cptn_mod_nest_call.CptnModNestCall less_trans_Suc) }\n    ultimately have \"\\<exists>n. (n, \\<Gamma>, (LanguageCon.com.Call f,  s) # (bdy,  s) # xs) \\<in> cptn_mod_nest_call \\<and> (\\<not> nn n < n \\<or> (nn n, \\<Gamma>, (LanguageCon.com.Call f,  s) # (bdy,  s) # xs) \\<notin> cptn_mod_nest_call)\"\n      by (metis (no_types) CptnModNestCall.hyps(3) CptnModNestCall.hyps(4) cptn_mod_nest_call.CptnModNestCall elim_cptn_mod_nest_call_n) }\n   then show ?thesis\n     by meson\n  qed     \nnext \n case (CptnModNestDynCom n \\<Gamma> c s xs) thus ?case\n   by (meson cptn_mod_nest_call.CptnModNestDynCom elim_cptn_mod_nest_call_n)\nnext\n  case (CptnModNestGuard n \\<Gamma> c s xs g f) thus ?case \n    by (meson cptn_mod_nest_call.CptnModNestGuard elim_cptn_mod_nest_call_n)   \nnext\n case (CptnModNestCatch1 n \\<Gamma> P s xs  zs Q) thus ?case\n   by (metis (no_types, lifting) Catch_P_Not_finish cptn_mod_nest_call.CptnModNestCatch1 div_catch_nest)\nnext\n case (CptnModNestCatch2 n \\<Gamma> P s xs c f ys zs Q) \n then obtain min_p where \n     min_p:\"(min_p, \\<Gamma>, (P,  s) # xs) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_p. (m, \\<Gamma>, (P, s) # xs) \\<notin> cptn_mod_nest_call)\" \n    by auto \n  from CptnModNestCatch2(5) obtain min_q where\n    min_q:\"(min_q, \\<Gamma>, (c, snd (last ((P, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_q. (m, \\<Gamma>, (c, snd (last ((P, s) # xs))) # ys) \\<notin> cptn_mod_nest_call)\"\n    using CptnModNestCatch2.hyps(6) by blast \n  thus ?case\n  proof(cases \"min_p\\<ge>min_q\")\n    case True\n    then have \"(min_p, \\<Gamma>, (c, snd (last ((P,s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n      using min_q using cptn_mod_nest_mono by blast \n    then have \"(min_p, \\<Gamma>, (Catch P Q, s) # zs) \\<in> cptn_mod_nest_call\"\n      using conjunct1[OF min_p] cptn_mod_nest_call.CptnModNestCatch2[of min_p \\<Gamma> P s xs] \n            CptnModNestCatch2(3,4,7)\n    by blast\n    also have \"\\<forall>m<min_p. (m, \\<Gamma>,(Catch P Q,s) # zs) \\<notin> cptn_mod_nest_call\"\n     proof -\n      {fix m\n      assume min_m:\"m<min_p\"\n      then have \"(m, \\<Gamma>,(Catch P Q, s) # zs) \\<notin> cptn_mod_nest_call\"\n      proof -\n      {assume ass:\"(m, \\<Gamma>, (Catch P Q, s) # zs) \\<in> cptn_mod_nest_call\"\n       then obtain xs' s' s'' where \n          m_cptn:\"(m, \\<Gamma>, (P, s) # xs') \\<in> cptn_mod_nest_call \\<and> \n                   catch_cond_nest zs Q xs' P s s'' s' \\<Gamma> m\" \n         using  \n          div_catch_nest[of m \\<Gamma> \"(Catch P Q, s) # zs\"]\n          by fastforce\n       then have \"catch_cond_nest zs Q xs' P s s'' s' \\<Gamma> m\" by auto\n       then have \"xs=xs'\" \n         using Catch_P_Ends_Skip[OF CptnModNestCatch2(7)  CptnModNestCatch2(3)]\n         using CptnModNestCatch2.hyps(4) by blast\n       then have \"(m, \\<Gamma>, (P,s) # xs) \\<in> cptn_mod_nest_call\"\n         using m_cptn by auto\n       then have False using min_p min_m by fastforce\n    } thus ?thesis by auto\n    qed\n    }thus ?thesis by auto\n  qed\n  ultimately show ?thesis by auto\n  next\n    case False\n    then have \"(min_q, \\<Gamma>, (P,  s) # xs) \\<in> cptn_mod_nest_call\"\n      using min_p cptn_mod_nest_mono by force \n    then have \"(min_q, \\<Gamma>, (Catch P Q, s) # zs) \\<in> cptn_mod_nest_call\"\n      using conjunct1[OF min_q] cptn_mod_nest_call.CptnModNestCatch2[of min_q \\<Gamma> P s xs ] \n            CptnModNestCatch2(3,4,7)\n    by blast\n    also have \"\\<forall>m<min_q. (m, \\<Gamma>,(Catch P Q,s) # zs) \\<notin> cptn_mod_nest_call\"\n     proof -\n      {fix m\n      assume min_m:\"m<min_q\"\n      then have \"(m, \\<Gamma>,(Catch P Q, s) # zs) \\<notin> cptn_mod_nest_call\"\n      proof -\n      {assume ass:\"(m, \\<Gamma>, (Catch P Q, s) # zs) \\<in> cptn_mod_nest_call\"\n       then obtain xs' s' s'' where \n          m_cptn:\"(m, \\<Gamma>, (P, s) # xs') \\<in> cptn_mod_nest_call \\<and> \n                   catch_cond_nest zs Q xs' P s s'' s' \\<Gamma> m\" \n         using  \n          div_catch_nest[of m \\<Gamma> \"(Catch P Q, s) # zs\"]\n          by fastforce\n       then have \"catch_cond_nest zs Q xs' P s s'' s' \\<Gamma> m\" by auto\n       then have ?thesis\n         using Catch_P_Ends_Skip[OF CptnModNestCatch2(7) CptnModNestCatch2(3)]\n               min_m min_q\n         using CptnModNestCatch2.hyps(4) by blast\n      } thus ?thesis by auto\n      qed\n      }thus ?thesis by auto\n    qed  \n    ultimately show ?thesis by auto\n  qed\nnext\n case (CptnModNestCatch3 n \\<Gamma> P s xs s' Q ys zs ) then obtain min_p where \n     min_p:\"(min_p, \\<Gamma>, (P,  s) # xs) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_p. (m, \\<Gamma>, (P, s) # xs) \\<notin> cptn_mod_nest_call)\" \n    by auto \n  from CptnModNestCatch3(6)  CptnModNestCatch3(4) obtain min_q where\n    min_q:\"(min_q, \\<Gamma>, (Q,  snd (last ((P,  s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_q. (m, \\<Gamma>, (Q,  snd (last ((P,  s) # xs))) # ys) \\<notin> cptn_mod_nest_call)\"\n  by auto\n  thus ?case\n  proof(cases \"min_p\\<ge>min_q\")\n    case True\n    then have \"(min_p, \\<Gamma>, (Q,  snd (last ((P,  s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n      using min_q using cptn_mod_nest_mono by blast \n    then have \"(min_p, \\<Gamma>, (Catch P Q,  s) # zs) \\<in> cptn_mod_nest_call\"\n      using conjunct1[OF min_p] cptn_mod_nest_call.CptnModNestCatch3[of min_p \\<Gamma> P s xs s' Q ys zs] \n            CptnModNestCatch3(4)  CptnModNestCatch3(3) CptnModNestCatch3(7)\n    by fastforce\n    also have \"\\<forall>m<min_p. (m, \\<Gamma>,(Catch P Q, s) # zs) \\<notin> cptn_mod_nest_call\"\n     proof -\n      {fix m\n      assume min_m:\"m<min_p\"\n      then have \"(m, \\<Gamma>,(Catch P Q,  s) # zs) \\<notin> cptn_mod_nest_call\"\n      proof -\n      {assume ass:\"(m, \\<Gamma>, (Catch P Q, s) # zs) \\<in> cptn_mod_nest_call\"\n       then obtain xs' ns' ns'' where \n          m_cptn:\"(m, \\<Gamma>, (P,  s) # xs') \\<in> cptn_mod_nest_call \\<and> \n                   catch_cond_nest zs Q xs' P ( s) ns'' ns' \\<Gamma> m\" \n         using  \n          div_catch_nest[of m \\<Gamma> \"(Catch P Q,  s) # zs\"]\n          by fastforce\n       then have \"catch_cond_nest zs Q xs' P ( s) ns'' ns' \\<Gamma> m\" by auto       \n       then have \"xs=xs'\" \n         using  Catch_P_Ends_Normal[OF CptnModNestCatch3(7)  CptnModNestCatch3(3) ]  \n         by fastforce\n       then have \"(m, \\<Gamma>, (P, s) # xs) \\<in> cptn_mod_nest_call\"\n         using m_cptn by auto\n       then have False using min_p min_m by fastforce\n    } thus ?thesis by auto\n    qed\n    }thus ?thesis by auto\n  qed\n  ultimately show ?thesis by auto\n  next\n    case False\n    then have \"(min_q, \\<Gamma>, (P,   s) # xs) \\<in> cptn_mod_nest_call\"\n      using min_p cptn_mod_nest_mono by force \n    then have \"(min_q, \\<Gamma>, (Catch P Q,  s) # zs) \\<in> cptn_mod_nest_call\"\n      using conjunct1[OF min_q] cptn_mod_nest_call.CptnModNestCatch3[of min_q \\<Gamma> P s xs s' ] \n            CptnModNestCatch3(4)  CptnModNestCatch3(3) CptnModNestCatch3(7)\n    by blast\n    also have \"\\<forall>m<min_q. (m, \\<Gamma>,(Catch P Q, s) # zs) \\<notin> cptn_mod_nest_call\"\n     proof -\n      {fix m\n      assume min_m:\"m<min_q\"\n      then have \"(m, \\<Gamma>,(Catch P Q,  s) # zs) \\<notin> cptn_mod_nest_call\"\n      proof -\n      {assume ass:\"(m, \\<Gamma>, (Catch P Q,  s) # zs) \\<in> cptn_mod_nest_call\"\n       then obtain xs' ns' ns'' where \n          m_cptn:\"(m, \\<Gamma>, (P,  s) # xs') \\<in> cptn_mod_nest_call \\<and> \n                   catch_cond_nest zs Q xs' P ( s) ns'' ns' \\<Gamma> m\" \n         using  \n          div_catch_nest[of m \\<Gamma> \"(Catch P Q,  s) # zs\"]\n          by fastforce\n       then have \"catch_cond_nest zs Q xs' P ( s) ns'' ns' \\<Gamma> m\" by auto\n       then have ?thesis\n         using Catch_P_Ends_Normal[OF CptnModNestCatch3(7) CptnModNestCatch3(3) ]\n               min_m min_q \n         by (metis last_length)                                \n      } thus ?thesis by auto\n      qed\n      }thus ?thesis by auto\n    qed  \n    ultimately show ?thesis by auto\n  qed  \nqed\n\n  lemma elim_cptn_mod_min_nest_call:\n assumes a0:\"min_call n \\<Gamma> cfg\" and\n         a1:\"cfg = (P,s)#(Q,t)#cfg1\" and\n         a2:\"(\\<forall>f. redex P \\<noteq> Call f) \\<or>  \n             SmallStepCon.redex P = LanguageCon.com.Call fn \\<and> \\<Gamma> fn = None \\<or>            \n            (redex P = Call fn \\<and> P=Q)\"     \n shows \"min_call n \\<Gamma> ((Q,t)#cfg1)\"\nproof -\n  have a0: \"(n,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" and\n       a0': \"(\\<forall>m<n. (m, \\<Gamma>, cfg) \\<notin> cptn_mod_nest_call)\"\n  using a0 unfolding min_call_def by auto\n  then have \"(n,\\<Gamma>,(Q,t)#cfg1) \\<in>  cptn_mod_nest_call\"  \n    using a0 a1 elim_cptn_mod_nest_call_n by blast\n  also have \"(\\<forall>m<n. (m, \\<Gamma>, (Q,t)#cfg1) \\<notin> cptn_mod_nest_call)\"      \n  proof-\n  { assume \"\\<not>(\\<forall>m<n. (m, \\<Gamma>, (Q,t)#cfg1) \\<notin> cptn_mod_nest_call)\"\n    then obtain m where \n      asm0:\"m<n\" and \n      asm1:\"(m, \\<Gamma>, (Q,t)#cfg1) \\<in> cptn_mod_nest_call\"\n      by auto\n    have ce:\"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow>\\<^sub>c\\<^sub>e (Q, t)\"\n      using a0 a1 cptn_elim_cases(2) cptn_eq_cptn_mod_nest by blast\n    then have \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow>\\<^sub>e (Q, t) \\<or> \\<Gamma>\\<turnstile>\\<^sub>c (P, toSeq s) \\<rightarrow> (Q, toSeq t)\"\n      using step_ce_dest by blast  \n    then have \"(m, \\<Gamma>, cfg) \\<in> cptn_mod_nest_call\"     \n    proof\n      assume \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow>\\<^sub>e (Q, t)\"\n      then show ?thesis          \n        using  a0 a1 a2 cptn_mod_nest_call.CptnModNestEnv          \n        by (metis asm1 env_c_c')\n    next\n      assume a00:\"\\<Gamma>\\<turnstile>\\<^sub>c (P, toSeq s) \\<rightarrow> (Q, toSeq t)\"\n      moreover have \"P\\<noteq>Q\" using mod_env_not_component calculation\n        by fastforce\n      moreover have norm:\"snd s = snd t\"\n        using calculation ce  step_dest1 by blast  \n      then show ?thesis using mod_env_not_component a2 not_func_redex_cptn_mod_nest_n'[OF _ _ a00 norm]\n        by (simp add: a1 asm1 calculation(2)) \n    qed      \n    then have False using a0' asm0 by auto\n  } thus ?thesis by auto qed\n  ultimately show ?thesis unfolding min_call_def by auto\nqed \n\nlemma elim_call_cptn_mod_min_nest_call:\n assumes a0:\"min_call n \\<Gamma> cfg\" and\n         a1:\"cfg = (P,s)#(Q,t)#cfg1\" and\n         a2:\"P = Call f \\<and>  \n             \\<Gamma> f = Some Q \\<and>  P\\<noteq>Q\"          \n shows \"min_call (n-1) \\<Gamma> ((Q,t)#cfg1)\"\nproof -\n  have a0: \"(n,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" and\n       a0': \"(\\<forall>m<n. (m, \\<Gamma>, cfg) \\<notin> cptn_mod_nest_call)\"\n    using a0 a2 unfolding min_call_def by auto  \n  then have \"(n-1,\\<Gamma>,(Q,t)#cfg1) \\<in>  cptn_mod_nest_call\" \n    using a1 a2  elim_cptn_mod_nest_call_n_dec[of n \\<Gamma> f s cfg1 Q]\n    by (metis (no_types, lifting) SmallStepCon.redex.simps(7) call_f_step_ce_not_s_eq_t_env_step \n           cptn_elim_cases(2) cptn_if_cptn_mod cptn_mod_nest_cptn_mod \n           elim_cptn_mod_nest_call_n_dec1 not_eq_not_env) \n  moreover have \"(\\<forall>m<n - 1. (m, \\<Gamma>, (Q, t) # cfg1) \\<notin> cptn_mod_nest_call)\"\n  proof -\n    { fix m\n      assume \"m<n-1\"\n      then have \"(m, \\<Gamma>, (Q, t) # cfg1) \\<notin> cptn_mod_nest_call\"\n        by (smt SmallStepCon.redex.simps(7) Suc_eq_plus1 a0 a0' a1 a2 \n        call_f_step_ce_not_s_eq_t_env_step cptn_elim_cases_pair(2) cptn_if_cptn_mod \n                cptn_mod_nest_call.CptnModNestCall cptn_mod_nest_cptn_mod \n                 less_diff_conv not_eq_not_env)\n     \n      }\n      thus ?thesis by auto\n    qed\n    ultimately show ?thesis unfolding min_call_def by auto\nqed\n\nlemma term_all_skip:\n  assumes a0:\"(\\<Gamma>,cfg)\\<in>cptn\" and\n          a1:\"cfg = (c,s)#cfg1\" and a1':\"(c=Skip \\<or> c=Throw \\<or> c=Stuck \\<or> (\\<exists>f. c = Fault f))\"\n  shows \"\\<forall>i<length cfg. fst(cfg!i) = c\"\nusing a0 a1 a1'\nproof(induct cfg1 arbitrary:cfg s)\n  case Nil thus ?case by auto\nnext\n  case (Cons x xs)  \n  have cptn:\"(\\<Gamma>,x#xs)\\<in>cptn\"\n    using Cons.prems(1) Cons.prems(2) cptn_dest_pair by blast\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c(c,s) \\<rightarrow>\\<^sub>e x\" using cptn_elim_cases_pair(2)[OF Cons(2)[simplified Cons(3)]] a1'\n    by (metis SmallStepCon.final_def SmallStepCon.no_step_final fst_conv step_ce_not_step_e_step_c) \n  then obtain s' where x:\"x = (c,s')\"\n    by (metis env_c_c' prod.exhaust_sel)    \n  moreover have cptn:\"(\\<Gamma>,x#xs)\\<in>cptn\"\n    using Cons.prems(1) Cons.prems(2) cptn_dest_pair by blast\n  moreover have \n    xs:\"x # xs = (c, s') # xs\" using x by auto\n  ultimately show ?case using Cons(1)[OF cptn xs] Cons(3)\n    using diff_Suc_1 fstI length_Cons less_Suc_eq_0_disj nth_Cons' a1' by auto \nqed\n\nlemma term_min_nested_call_0:\n  assumes a0:\"min_call n \\<Gamma> cfg\" and\n          a1:\"cfg = (c,s)#cfg1\" and a1':\"(c=Skip \\<or> c=Throw \\<or> c=Stuck \\<or> (\\<exists>f. c = Fault f))\"\n  shows \"n=0\"\nproof -\n  have asm0:\"(n, \\<Gamma>, cfg) \\<in> cptn_mod_nest_call\" and \n       asm1:\"(\\<forall>m<n. (m, \\<Gamma>, cfg) \\<notin> cptn_mod_nest_call)\"  \n       using a0 unfolding min_call_def by auto  \n  show ?thesis using a1 asm0 asm1\n  proof (induct cfg1 arbitrary: cfg s n)\n    case Nil thus ?case\n      using cptn_mod_nest_call.CptnModNestOne neq0_conv by blast\n  next\n    case (Cons x xs)\n      then obtain Q s' where cfg:\"cfg = (c, s) # (Q,s') # xs\"\n        using prod.exhaust_sel by blast\n      then have min_call:\"min_call n \\<Gamma> cfg\" using Cons unfolding min_call_def by auto\n      then have \"(\\<forall>f. SmallStepCon.redex c \\<noteq> LanguageCon.com.Call f)\" using a1' by auto\n      then have \"min_call n \\<Gamma> ((Q, s')#xs)\" \n        using elim_cptn_mod_min_nest_call[OF min_call cfg] cfg\n        by simp\n      thus ?case using Cons cfg unfolding min_call_def\n      proof -\n        assume a1: \"(n, \\<Gamma>, (Q, s') # xs) \\<in> cptn_mod_nest_call \\<and> \n                      (\\<forall>m<n. (m, \\<Gamma>, (Q, s') # xs) \\<notin> cptn_mod_nest_call)\"\n        have \"c = Q\" using term_all_skip\n        proof -\n          have \"Suc 0 < length ((c, s) # (Q, s') # xs)\"\n            by auto\n          then have \"fst (((c, s) # (Q, s') # xs) ! Suc 0) = c\"\n            using Cons.prems(2) a1' cfg cptn_if_cptn_mod cptn_mod_nest_cptn_mod term_all_skip by blast\n          then show ?thesis\n            by simp\n        qed\n        then show ?thesis\n          using a1 Cons.hyps by blast\n      qed      \n  qed\nqed\n\n\ntext \\<open> function to calculate that there is not any subsequent where the nested call is n \\<close>\ndefinition cond_seq_1\nwhere \n\"cond_seq_1 n \\<Gamma> c1 s xs c2 zs ys \\<equiv> ((n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call \\<and> \n                       fst(last((c1,s)#xs)) = Skip \\<and>\n                        (n,\\<Gamma>,((c2, snd(last ((c1, s)#xs)))#ys)) \\<in> cptn_mod_nest_call \\<and>\n                       zs=(map (lift c2) xs)@((c2, snd(last ((c1, s)#xs)))#ys))\"\n\ndefinition cond_seq_2\nwhere\n\"cond_seq_2 n \\<Gamma> c1 s xs c2 zs ys s' s'' \\<equiv>  s =  s'' \\<and> \n                    (n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call \\<and>                     \n                    snd(last ((c1, s)#xs)) =  s' \\<and> \n                    (\\<exists>c. fst(last ((c1, s)#xs)) = c \\<and> (c=Throw \\<or> c=Stuck \\<or> (\\<exists>f. c = Fault f)) \\<and>\n                    (n,\\<Gamma>,(c, s')#ys) \\<in> cptn_mod_nest_call \\<and> \n                     zs=(map (lift c2) xs)@((c, s')#ys))\"\n\ndefinition cond_catch_1\nwhere \n\"cond_catch_1 n \\<Gamma> c1 s xs c2 zs ys \\<equiv> ((n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call \\<and> \n                       (\\<exists>c. fst(last((c1,s)#xs)) = c \\<and> (c=Skip \\<or> c=Stuck \\<or> (\\<exists>f. c = Fault f)) \\<and>\n                        (n,\\<Gamma>,((c, snd(last ((c1, s)#xs)))#ys)) \\<in> cptn_mod_nest_call \\<and>\n                       zs=(map (lift_catch c2) xs)@((c, snd(last ((c1, s)#xs)))#ys)))\"\n\ndefinition cond_catch_2\nwhere\n\"cond_catch_2 n \\<Gamma> c1 s xs c2 zs ys s' s'' \\<equiv> s=  s'' \\<and> \n                    (n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call \\<and> \n                    fst(last ((c1, s)#xs)) = Throw \\<and>\n                    snd(last ((c1, s)#xs)) =  s' \\<and> \n                    (n,\\<Gamma>,(c2, s')#ys) \\<in> cptn_mod_nest_call \\<and> \n                     zs=(map (lift_catch c2) xs)@((c2, s')#ys)\"\n\n(* fun biggest_nest_call :: \"('s,'p,'f,'e)com \\<Rightarrow> \n                         ('s,'f) xstate \\<Rightarrow> \n                         (('s,'p,'f,'e) config) list \\<Rightarrow> \n                         ('s,'p,'f,'e) body \\<Rightarrow> \n                         nat \\<Rightarrow> bool\"\nwhere\n \"biggest_nest_call (Seq c1 c2) s zs \\<Gamma> n  = \n   (if (\\<exists>xs. ((min_call n \\<Gamma> ((c1,s)#xs)) \\<and> (zs=map (lift c2) xs))) then\n       let xsa = (SOME xs. (min_call n \\<Gamma> ((c1,s)#xs)) \\<and> (zs=map (lift c2) xs)) in\n       (biggest_nest_call c1 s xsa \\<Gamma> n)\n    else if (\\<exists>xs ys. cond_seq_1 n \\<Gamma> c1 s xs c2 zs ys) then\n         let xsa = (SOME xs. \\<exists>ys. cond_seq_1 n \\<Gamma> c1 s xs c2 zs ys);\n             ysa = (SOME ys. cond_seq_1 n \\<Gamma> c1 s xsa c2 zs ys) in\n         if (min_call n \\<Gamma> ((c2, snd(last ((c1, s)#xsa)))#ysa)) then True\n         else (biggest_nest_call c1 s xsa \\<Gamma> n)            \n   else let xsa = (SOME xs. \\<exists>ys s' s''. cond_seq_2 n \\<Gamma> c1 s xs c2 zs ys s' s'') in\n           (biggest_nest_call c1 s xsa \\<Gamma> n))\"      \n|\"biggest_nest_call (Catch c1 c2) s zs \\<Gamma> n  = \n  (if (\\<exists>xs. ((min_call n \\<Gamma> ((c1,s)#xs)) \\<and> (zs=map (lift_catch c2) xs))) then\n    let xsa = (SOME xs. (min_call n \\<Gamma> ((c1,s)#xs)) \\<and> (zs=map (lift_catch c2) xs)) in\n       (biggest_nest_call c1 s xsa \\<Gamma> n)\n    else if (\\<exists>xs ys. cond_catch_1 n \\<Gamma> c1 s xs c2 zs ys) then\n         let xsa = (SOME xs. \\<exists>ys. cond_catch_1 n \\<Gamma> c1 s xs c2 zs ys) in            \n                 (biggest_nest_call c1 s xsa \\<Gamma> n)\n   else let xsa = (SOME xs. \\<exists>ys s' s''. cond_catch_2 n \\<Gamma> c1 s xs c2 zs ys s' s'');\n            ysa = (SOME ys. \\<exists>s' s''. cond_catch_2 n \\<Gamma> c1 s xsa c2 zs ys s' s'') in\n         if (min_call n \\<Gamma> ((c2, snd(last ((c1, s)#xsa)))#ysa)) then True\n         else (biggest_nest_call c1 s xsa \\<Gamma> n))\"\n|\"biggest_nest_call _ _ _ _ _ = False\"\n*)\n\nlemma min_call_less_eq_n:\n  \"(n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call \\<Longrightarrow>     \n   (n,\\<Gamma>,(c2, snd(last ((c1, s)#xs)))#ys) \\<in> cptn_mod_nest_call \\<Longrightarrow>\n   min_call p \\<Gamma> ((c1, s)#xs) \\<and> min_call q \\<Gamma> ((c2, snd(last ((c1, s)#xs)))#ys) \\<Longrightarrow>\n   p\\<le>n \\<and> q\\<le>n\"\nunfolding min_call_def\nusing le_less_linear by blast\n\nlemma min_call_seq_less_eq_n':\n  \"(n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call \\<Longrightarrow>     \n   min_call p \\<Gamma> ((c1, s)#xs)  \\<Longrightarrow>\n   p\\<le>n\"\nunfolding min_call_def\nusing le_less_linear by blast\n\nlemma min_call_seq2:\n  \"min_call n \\<Gamma> ((Seq c1 c2,s)#zs) \\<Longrightarrow>\n   (n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call \\<Longrightarrow> \n    fst(last ((c1, s)#xs)) = Skip \\<Longrightarrow>\n   (n,\\<Gamma>,(c2, snd(last ((c1, s)#xs)))#ys) \\<in> cptn_mod_nest_call \\<Longrightarrow>\n    zs=(map (lift c2) xs)@((c2, snd(last ((c1, s)#xs)))#ys) \\<Longrightarrow>\n   min_call n \\<Gamma> ((c1, s)#xs) \\<or> min_call n \\<Gamma> ((c2, snd(last ((c1, s)#xs)))#ys)\n   \"\nproof -\n  assume a0:\"min_call n \\<Gamma> ((Seq c1 c2,s)#zs)\" and\n         a1:\"(n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call\" and\n         a2:\"fst(last ((c1, s)#xs)) = Skip\" and\n         a3:\"(n,\\<Gamma>,(c2, snd(last ((c1, s)#xs)))#ys) \\<in> cptn_mod_nest_call\" and\n         a4:\"zs=(map (lift c2) xs)@((c2, snd(last ((c1, s)#xs)))#ys)\"\n  then obtain p q where min_calls: \n    \"min_call p \\<Gamma> ((c1, s)#xs) \\<and> min_call q \\<Gamma> ((c2, snd(last ((c1, s)#xs)))#ys)\"\n    using a1 a3 minimum_nest_call by blast\n  then have p_q:\"p\\<le>n \\<and> q\\<le>n\" using a0 a1  a3 a4 min_call_less_eq_n by blast\n  {\n    assume ass0:\"p<n \\<and> q <n\"     \n    then have \"(p,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call\" and\n              \"(q,\\<Gamma>,(c2, snd(last ((c1, s)#xs)))#ys) \\<in> cptn_mod_nest_call\"\n      using min_calls unfolding min_call_def by auto\n    then have ?thesis\n    proof (cases \"p\\<le>q\")\n      case True \n      then have q_cptn_c1:\"(q, \\<Gamma>, (c1, s) # xs) \\<in> cptn_mod_nest_call\" \n        using cptn_mod_nest_mono min_calls unfolding min_call_def  \n        by blast\n      have q_cptn_c2:\"(q, \\<Gamma>, (c2, snd (last ((c1, s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n       using min_calls unfolding min_call_def by auto\n      then have \"(q,\\<Gamma>,((Seq c1 c2,s)#zs)) \\<in>cptn_mod_nest_call\"\n        using True min_calls a2 a4  CptnModNestSeq2[OF q_cptn_c1 a2 q_cptn_c2 a4] \n        by auto\n      thus ?thesis using ass0 a0 unfolding min_call_def by auto\n    next\n      case False\n      then have q_cptn_c1:\"(p, \\<Gamma>, (c1, s) # xs) \\<in> cptn_mod_nest_call\" \n        using  min_calls unfolding min_call_def  \n        by blast\n      have q_cptn_c2:\"(p, \\<Gamma>, (c2, snd (last ((c1, s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n       using min_calls False unfolding min_call_def\n       by (metis (no_types, lifting) cptn_mod_nest_mono2 not_less)\n      then have \"(p,\\<Gamma>,((Seq c1 c2,s)#zs)) \\<in>cptn_mod_nest_call\"\n        using False min_calls a2 a4  CptnModNestSeq2[OF q_cptn_c1 a2 q_cptn_c2 a4] \n        by auto\n      thus ?thesis using ass0 a0 unfolding min_call_def by auto\n    qed\n  }note l=this\n  {\n    assume ass0:\"p\\<ge>n \\<or> q \\<ge>n\" \n    then have ?thesis using p_q min_calls by fastforce\n  }\n  thus ?thesis using l by fastforce\nqed\n\nlemma min_call_seq3:\n  \"min_call n \\<Gamma> ((Seq c1 c2,s)#zs) \\<Longrightarrow>\n   s=  s'' \\<Longrightarrow>\n   (n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call \\<Longrightarrow> \n    fst(last ((c1, s)#xs)) = c \\<Longrightarrow> (c=Throw \\<or> c=Stuck \\<or> (\\<exists>f. c = Fault f)) \\<Longrightarrow>\n    snd(last ((c1, s)#xs)) =  s' \\<Longrightarrow>\n   (n,\\<Gamma>,(c, snd(last ((c1, s)#xs)))#ys) \\<in> cptn_mod_nest_call \\<Longrightarrow>\n    zs=(map (lift c2) xs)@((c, snd(last ((c1, s)#xs)))#ys) \\<Longrightarrow>\n   min_call n \\<Gamma> ((c1, s)#xs)\n   \"\nproof -\n  assume a0:\"min_call n \\<Gamma> ((Seq c1 c2,s)#zs)\" and\n         a0':\"s=  s''\" and\n         a1:\"(n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call\" and\n         a2:\"fst(last ((c1, s)#xs)) = c\" and a2'':\"(c=Throw \\<or> c=Stuck \\<or> (\\<exists>f. c = Fault f))\" and\n         a2':\"snd(last ((c1, s)#xs)) =  s'\" and\n         a3:\"(n,\\<Gamma>,(c, snd(last ((c1, s)#xs)))#ys) \\<in> cptn_mod_nest_call\" and\n         a4:\"zs=(map (lift c2) xs)@((c, snd(last ((c1, s)#xs)))#ys)\"\n  then obtain p where min_calls: \n    \"min_call p \\<Gamma> ((c1, s)#xs) \\<and> min_call 0 \\<Gamma> ((c, snd(last ((c1, s)#xs)))#ys)\"\n    using a1 a3 minimum_nest_call term_min_nested_call_0  a2' by metis\n  then have p_q:\"p\\<le>n \\<and> 0\\<le>n\" using a0 a1  a3 a4 min_call_less_eq_n by blast\n  {\n    assume ass0:\"p<n \\<and> 0 <n\"     \n    then have \"(p,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call\" and\n              \"(0,\\<Gamma>,(c, snd(last ((c1, s)#xs)))#ys) \\<in> cptn_mod_nest_call\"\n      using min_calls unfolding min_call_def by auto\n    then have ?thesis\n    proof (cases \"p\\<le>0\")\n      case True \n      then have q_cptn_c1:\"(0, \\<Gamma>, (c1,  s'') # xs) \\<in> cptn_mod_nest_call\" \n        using cptn_mod_nest_mono min_calls a0' unfolding min_call_def  \n        by blast\n      have q_cptn_c2:\"(0, \\<Gamma>, (c, snd (last ((c1, s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n       using min_calls unfolding min_call_def by auto\n      then have \"(0,\\<Gamma>,((Seq c1 c2,s)#zs)) \\<in>cptn_mod_nest_call\"\n        using True min_calls a2 a4 a2' a0' a2'' CptnModNestSeq3[OF q_cptn_c1 _ ] \n        by blast\n      thus ?thesis using ass0 a0 unfolding min_call_def by auto\n    next\n      case False\n      then have q_cptn_c1:\"(p, \\<Gamma>, (c1,  s'') # xs) \\<in> cptn_mod_nest_call\" \n        using  min_calls a0' unfolding min_call_def  \n        by blast\n      have q_cptn_c2:\"(p, \\<Gamma>, (c, snd (last ((c1, s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n       using min_calls False unfolding min_call_def\n       by (metis (no_types, lifting) cptn_mod_nest_mono2 not_less)\n      then have \"(p,\\<Gamma>,((Seq c1 c2,s)#zs)) \\<in>cptn_mod_nest_call\"\n        using False min_calls a2 a4 a0' a2' a2''  CptnModNestSeq3[OF q_cptn_c1]\n        by blast\n      thus ?thesis using ass0 a0 unfolding min_call_def by auto\n    qed\n  }note l=this\n  {\n    assume ass0:\"p\\<ge>n \\<or> 0 \\<ge>n\" \n    then have ?thesis using p_q min_calls by fastforce\n  }\n  thus ?thesis using l by fastforce\nqed\n\nlemma min_call_catch2:\n  \"min_call n \\<Gamma> ((Catch c1 c2,s)#zs) \\<Longrightarrow>   \n   (n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call \\<Longrightarrow> \n    fst(last ((c1, s)#xs)) = c \\<Longrightarrow> (c=Skip \\<or> c=Stuck \\<or> (\\<exists>f. c = Fault f)) \\<Longrightarrow>   \n   (n,\\<Gamma>,(c, snd(last ((c1, s)#xs)))#ys) \\<in> cptn_mod_nest_call \\<Longrightarrow>\n    zs=(map (lift_catch c2) xs)@((c, snd(last ((c1, s)#xs)))#ys) \\<Longrightarrow>\n   min_call n \\<Gamma> ((c1, s)#xs)\n   \"\nproof -\n  assume a0:\"min_call n \\<Gamma> ((Catch c1 c2,s)#zs)\" and        \n         a1:\"(n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call\" and\n         a2:\"fst(last ((c1, s)#xs)) = c\" and  a2':\"(c=Skip \\<or> c=Stuck \\<or> (\\<exists>f. c = Fault f))\" and      \n         a3:\"(n,\\<Gamma>,(c, snd(last ((c1, s)#xs)))#ys) \\<in> cptn_mod_nest_call\" and\n         a4:\"zs=(map (lift_catch c2) xs)@((c, snd(last ((c1, s)#xs)))#ys)\"\n  then obtain p where min_calls: \n    \"min_call p \\<Gamma> ((c1, s)#xs) \\<and> min_call 0 \\<Gamma> ((c, snd(last ((c1, s)#xs)))#ys)\"\n    using a1 a3 minimum_nest_call term_min_nested_call_0  by metis\n  then have p_q:\"p\\<le>n \\<and> 0\\<le>n\" using a0 a1  a3 a4 min_call_less_eq_n by blast\n  {\n    assume ass0:\"p<n \\<and> 0 <n\"     \n    then have \"(p,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call\" and\n              \"(0,\\<Gamma>,(c, snd(last ((c1, s)#xs)))#ys) \\<in> cptn_mod_nest_call\"\n      using min_calls unfolding min_call_def by auto\n    then have ?thesis\n    proof (cases \"p\\<le>0\")\n      case True \n      then have q_cptn_c1:\"(0, \\<Gamma>, (c1, s) # xs) \\<in> cptn_mod_nest_call\" \n        using cptn_mod_nest_mono min_calls  unfolding min_call_def  \n        by blast\n      have q_cptn_c2:\"(0, \\<Gamma>, (c, snd (last ((c1, s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n       using min_calls unfolding min_call_def by auto\n      then have \"(0,\\<Gamma>,((Catch c1 c2,s)#zs)) \\<in>cptn_mod_nest_call\"\n        using True min_calls a2 a4 a2'   CptnModNestCatch2[OF q_cptn_c1 ] \n        by blast\n      thus ?thesis using ass0 a0 unfolding min_call_def by auto\n    next\n      case False\n      then have q_cptn_c1:\"(p, \\<Gamma>, (c1, s) # xs) \\<in> cptn_mod_nest_call\" \n        using  min_calls  unfolding min_call_def  \n        by blast\n      have q_cptn_c2:\"(p, \\<Gamma>, (c, snd (last ((c1, s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n       using min_calls False unfolding min_call_def\n       by (metis (no_types, lifting) cptn_mod_nest_mono2 not_less)\n      then have \"(p,\\<Gamma>,((Catch c1 c2,s)#zs)) \\<in>cptn_mod_nest_call\"\n        using False min_calls a2 a4 a2'  CptnModNestCatch2[OF q_cptn_c1]\n        by blast       \n      thus ?thesis using ass0 a0 unfolding min_call_def by auto\n    qed\n  }note l=this\n  {\n    assume ass0:\"p\\<ge>n \\<or> 0 \\<ge>n\" \n    then have ?thesis using p_q min_calls by fastforce\n  }\n  thus ?thesis using l by fastforce\nqed\n\nlemma min_call_catch_less_eq_n:\n  \"(n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call \\<Longrightarrow>        \n   (n,\\<Gamma>,(c2, snd(last ((c1,  s)#xs)))#ys) \\<in> cptn_mod_nest_call \\<Longrightarrow>    \n   min_call p \\<Gamma> ((c1,  s)#xs) \\<and> min_call q \\<Gamma> ((c2, snd(last ((c1,  s)#xs)))#ys) \\<Longrightarrow>\n   p\\<le>n \\<and> q\\<le>n\"\nunfolding min_call_def\nusing le_less_linear by blast\n\nlemma min_call_catch3:\n  \"min_call n \\<Gamma> ((Catch c1 c2, s)#zs) \\<Longrightarrow>\n   (n,\\<Gamma>, (c1,  s)#xs) \\<in> cptn_mod_nest_call \\<Longrightarrow> \n    fst(last ((c1,  s)#xs)) = Throw \\<Longrightarrow>\n    snd(last ((c1,  s)#xs)) =  s' \\<Longrightarrow>\n   (n,\\<Gamma>,(c2, snd(last ((c1,  s)#xs)))#ys) \\<in> cptn_mod_nest_call \\<Longrightarrow>\n    zs=(map (lift_catch c2) xs)@((c2, snd(last ((c1,  s)#xs)))#ys) \\<Longrightarrow>\n   min_call n \\<Gamma> ((c1,  s)#xs) \\<or> min_call n \\<Gamma> ((c2, snd(last ((c1,  s)#xs)))#ys)\n   \"\nproof -\n  assume a0:\"min_call n \\<Gamma> ((Catch c1 c2, s)#zs)\" and\n         a1:\"(n,\\<Gamma>, (c1,  s)#xs) \\<in> cptn_mod_nest_call\" and\n         a2:\"fst(last ((c1,  s)#xs)) = Throw\" and\n         a2':\"snd(last ((c1,  s)#xs)) =  s'\" and\n         a3:\"(n,\\<Gamma>,(c2, snd(last ((c1,  s)#xs)))#ys) \\<in> cptn_mod_nest_call\" and\n         a4:\"zs=(map (lift_catch c2) xs)@((c2, snd(last ((c1,  s)#xs)))#ys)\"\n  then obtain p q where min_calls: \n    \"min_call p \\<Gamma> ((c1,  s)#xs) \\<and> min_call q \\<Gamma> ((c2, snd(last ((c1,  s)#xs)))#ys)\"\n    using a1 a3 minimum_nest_call by blast\n  then have p_q:\"p\\<le>n \\<and> q\\<le>n\" \n    using a1 a2 a2' a3 a4 min_call_less_eq_n by blast\n  {\n    assume ass0:\"p<n \\<and> q <n\"     \n    then have \"(p,\\<Gamma>, (c1,  s)#xs) \\<in> cptn_mod_nest_call\" and\n              \"(q,\\<Gamma>,(c2, snd(last ((c1,  s)#xs)))#ys) \\<in> cptn_mod_nest_call\"\n      using min_calls unfolding min_call_def by auto\n    then have ?thesis\n    proof (cases \"p\\<le>q\")\n      case True \n      then have q_cptn_c1:\"(q, \\<Gamma>, (c1, s) # xs) \\<in> cptn_mod_nest_call\" \n        using cptn_mod_nest_mono min_calls unfolding min_call_def  \n        by blast\n      have q_cptn_c2:\"(q, \\<Gamma>, (c2, snd (last ((c1,  s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n       using min_calls unfolding min_call_def by auto\n      then have \"(q,\\<Gamma>,((Catch c1 c2,  s)#zs)) \\<in>cptn_mod_nest_call\"\n        using True min_calls a2 a2' a4  CptnModNestCatch3[OF q_cptn_c1 a2 a2' q_cptn_c2 a4] \n        by auto\n      thus ?thesis using ass0 a0 unfolding min_call_def by auto\n    next\n      case False\n      then have q_cptn_c1:\"(p, \\<Gamma>, (c1,  s) # xs) \\<in> cptn_mod_nest_call\" \n        using  min_calls unfolding min_call_def  \n        by blast\n      have q_cptn_c2:\"(p, \\<Gamma>, (c2, snd (last ((c1,  s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n       using min_calls False unfolding min_call_def\n       by (metis (no_types, lifting) cptn_mod_nest_mono2 not_less)\n      then have \"(p,\\<Gamma>,((Catch c1 c2, s)#zs)) \\<in>cptn_mod_nest_call\"\n        using False min_calls a2 a4  CptnModNestCatch3[OF q_cptn_c1 a2 a2' q_cptn_c2 a4] \n        by auto\n      thus ?thesis using ass0 a0 unfolding min_call_def by auto\n    qed\n  }note l=this\n  {\n    assume ass0:\"p\\<ge>n \\<or> q \\<ge>n\" \n    then have ?thesis using p_q min_calls by fastforce\n  }\n  thus ?thesis using l by fastforce\nqed\n\nlemma min_call_seq_c1_not_finish:\n  \"min_call n \\<Gamma> cfg \\<Longrightarrow>\n   cfg = (LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1 \\<Longrightarrow>\n   (n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call \\<Longrightarrow>\n   (Q, t) # cfg1 = map (lift P1) xs \\<Longrightarrow>\n   min_call  n \\<Gamma> ((P0, s)#xs)\n   \"\nproof -\n  assume a0:\"min_call n \\<Gamma> cfg\" and\n        a1:\" cfg = (LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1\" and\n        a2:\"(n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call\" and\n        a3:\"(Q, t) # cfg1 = map (lift P1) xs\" \n  then have \"(n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call\" using a2 by auto\n  moreover have \"\\<forall>m<n. (m, \\<Gamma>,(P0, s)#xs) \\<notin> cptn_mod_nest_call\"\n  proof-\n    {fix m\n     assume ass:\"m<n\"\n     {  assume ass1:\"(m, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call\"\n       then have \"(m,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" \n         using a1 a3 CptnModNestSeq1[OF ass1] by auto\n       then have False using ass a0 unfolding min_call_def by auto\n     }\n     then have \"(m, \\<Gamma>, (P0, s) # xs) \\<notin> cptn_mod_nest_call\" by auto\n    } then show ?thesis by auto\n  qed\n  ultimately show ?thesis unfolding min_call_def by auto\nqed\n\nlemma min_call_seq_not_finish:\n  \" min_call  n \\<Gamma> ((P0, s)#xs) \\<Longrightarrow>\n   cfg = (LanguageCon.com.Seq P0 P1, s) #  cfg1 \\<Longrightarrow>  \n    cfg1 = map (lift P1) xs \\<Longrightarrow>\n   min_call n \\<Gamma> cfg \n   \"\nproof -\n  assume a0:\"min_call  n \\<Gamma> ((P0, s)#xs)\" and\n        a1:\" cfg = (LanguageCon.com.Seq P0 P1, s) #  cfg1\" and        \n        a2:\" cfg1 = map (lift P1) xs\" \n  then have \"(n, \\<Gamma>,cfg) \\<in> cptn_mod_nest_call\" \n    using a0 a1 a2 CptnModNestSeq1[of n \\<Gamma> P0 s xs \"cfg1\" P1] unfolding min_call_def \n    by auto\n  moreover have \"\\<forall>m<n. (m, \\<Gamma>,cfg) \\<notin> cptn_mod_nest_call\"\n  proof-\n    {fix m\n     assume ass:\"m<n\"\n     {  assume ass1:\"(m, \\<Gamma>, cfg) \\<in> cptn_mod_nest_call\"\n       then have \"(m,\\<Gamma>,(P0, s)#xs) \\<in>  cptn_mod_nest_call\" \n         using a1 a2 by (metis (no_types) Seq_P_Not_finish div_seq_nest) \n       then have False using ass a0 unfolding min_call_def by auto\n     }\n     then have \"(m, \\<Gamma>, cfg) \\<notin> cptn_mod_nest_call\" by auto\n    } then show ?thesis by auto\n  qed\n  ultimately show ?thesis unfolding min_call_def by auto\nqed\n\nlemma min_call_catch_c1_not_finish:\n  \"min_call n \\<Gamma> cfg \\<Longrightarrow>\n   cfg = (LanguageCon.com.Catch P0 P1, s) # (Q, t) # cfg1 \\<Longrightarrow>\n   (n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call \\<Longrightarrow>\n   (Q, t) # cfg1 = map (lift_catch P1) xs \\<Longrightarrow>\n   min_call  n \\<Gamma> ((P0, s)#xs)\n   \"\nproof -\n  assume a0:\"min_call n \\<Gamma> cfg\" and\n        a1:\" cfg = (LanguageCon.com.Catch P0 P1, s) # (Q, t) # cfg1\" and\n        a2:\"(n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call\" and\n        a3:\"(Q, t) # cfg1 = map (lift_catch P1) xs\" \n  then have \"(n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call\" using a2 by auto\n  moreover have \"\\<forall>m<n. (m, \\<Gamma>,(P0, s)#xs) \\<notin> cptn_mod_nest_call\"\n  proof-\n    {fix m\n     assume ass:\"m<n\"\n     {  assume ass1:\"(m, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call\"\n       then have \"(m,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" \n         using a1 a3 CptnModNestCatch1[OF ass1] by auto\n       then have False using ass a0 unfolding min_call_def by auto\n     }\n     then have \"(m, \\<Gamma>, (P0, s) # xs) \\<notin> cptn_mod_nest_call\" by auto\n    } then show ?thesis by auto\n  qed\n  ultimately show ?thesis unfolding min_call_def by auto\nqed\n\nlemma min_call_catch_not_finish:\n  \" min_call  n \\<Gamma> ((P0, s)#xs) \\<Longrightarrow>\n   cfg = (LanguageCon.com.Catch P0 P1, s) #  cfg1 \\<Longrightarrow>  \n    cfg1 = map (lift_catch P1) xs \\<Longrightarrow>\n   min_call n \\<Gamma> cfg \n   \"\nproof -\n  assume a0:\"min_call  n \\<Gamma> ((P0, s)#xs)\" and\n        a1:\" cfg = (Catch P0 P1, s) #  cfg1\" and        \n        a2:\" cfg1 = map (lift_catch P1) xs\" \n  then have \"(n, \\<Gamma>,cfg) \\<in> cptn_mod_nest_call\" \n    using a0 a1 a2 CptnModNestCatch1[of n \\<Gamma> P0 s xs \"cfg1\" P1] unfolding min_call_def \n    by auto\n  moreover have \"\\<forall>m<n. (m, \\<Gamma>,cfg) \\<notin> cptn_mod_nest_call\"\n  proof-\n    {fix m\n     assume ass:\"m<n\"\n     {  assume ass1:\"(m, \\<Gamma>, cfg) \\<in> cptn_mod_nest_call\"\n       then have \"(m,\\<Gamma>,(P0, s)#xs) \\<in>  cptn_mod_nest_call\" \n         using a1 a2 by (metis (no_types) Catch_P_Not_finish div_catch_nest) \n       then have False using ass a0 unfolding min_call_def by auto\n     }\n     then have \"(m, \\<Gamma>, cfg) \\<notin> cptn_mod_nest_call\" by auto\n    } then show ?thesis by auto\n  qed\n  ultimately show ?thesis unfolding min_call_def by auto\nqed\n\nlemma seq_xs_no_empty: assumes\n     seq:\"seq_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \\<Gamma> n\" and\n     cfg:\"cfg = (LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1\" and\n     a0:\"SmallStepCon.redex (LanguageCon.com.Seq P0 P1) = LanguageCon.com.Call f\"\n     shows\"\\<exists>Q' xs'. Q=Seq Q' P1 \\<and> xs=(Q',t)#xs'\"\nusing seq\nunfolding lift_def seq_cond_nest_def\nproof\n    assume \"(Q, t) # cfg1 = map (\\<lambda>(P, s). (LanguageCon.com.Seq P P1, s)) xs\"\n    thus ?thesis by auto\nnext\n  assume \"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \\<and>\n        (\\<exists>ys. (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n              (Q, t) # cfg1 =\n              map (\\<lambda>(P, s). (LanguageCon.com.Seq P P1, s)) xs @\n              (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<or>\n        (\\<exists>c. fst (((P0, s) # xs) ! length xs) = c \\<and> (c = Throw \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n        snd (last ((P0, s) # xs)) =  s' \\<and>\n        s =  s'' \\<and> (\\<exists>ys. (n, \\<Gamma>, (c,  s') # ys) \\<in> cptn_mod_nest_call \\<and>\n                        (Q, t) # cfg1 = map (\\<lambda>(P, s). (Seq P P1, s)) xs @(c,  s') # ys))\"\n  thus ?thesis\n  proof \n    assume ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \\<and>\n        (\\<exists>ys. (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n              (Q, t) # cfg1 =\n              map (\\<lambda>(P, s). (LanguageCon.com.Seq P P1, s)) xs @\n              (P1, snd (((P0, s) # xs) ! length xs)) # ys)\"\n    show ?thesis \n    proof (cases xs)\n      case Nil thus ?thesis using cfg a0 ass by auto\n    next\n      case (Cons xa xsa)\n      then obtain a b where xa:\"xa = (a,b)\"\n        using prod.exhaust_sel by blast\n      obtain pps where\n           \"(Q, t) = (Seq a P1, b) \\<and> \n            cfg1 = map (\\<lambda>(c, y). (Seq c P1, y)) xsa @ \n                      (P1, snd (((P0, s) # xs) ! length xs)) # pps\"  \n        using ass local.Cons xa by moura         \n      then show ?thesis\n        using local.Cons xa by auto\n    qed      \n  next\n    assume ass:\"\\<exists>c. fst (((P0, s) # xs) ! length xs) = c \\<and> (c = Throw \\<or> (\\<exists>f. c = Fault f) \\<or> c = Stuck) \\<and>\n        snd (last ((P0, s) # xs)) =  s' \\<and>\n        s =  s'' \\<and> (\\<exists>ys. (n, \\<Gamma>, (c,  s') # ys) \\<in> cptn_mod_nest_call \\<and>\n                        (Q, t) # cfg1 = map (\\<lambda>(P, s). (Seq P P1, s)) xs @(c,  s') # ys)\"\n    thus ?thesis\n    proof (cases xs)\n      case Nil thus ?thesis using cfg a0 ass by auto\n    next\n      case (Cons xa xsa)      \n      then obtain a b where xa:\"xa = (a,b)\" using prod.exhaust_sel Cons by blast\n      obtain c where c:\" fst (((P0, s) # xs) ! length xs) = c \\<and>\n            (c = LanguageCon.com.Throw \\<or> (\\<exists>f. c = com.Fault f) \\<or> c = com.Stuck) \\<and>\n            snd (last ((P0, s) # xs)) = s' \\<and>\n            s = s'' \\<and>\n            (\\<exists>ys. (n, \\<Gamma>, (c, s') # ys) \\<in> cptn_mod_nest_call \\<and>\n                  (Q, t) # cfg1 = map (\\<lambda>(P, s). (LanguageCon.com.Seq P P1, s)) xs @ (c, s') # ys)\" \n        using ass by fastforce\n      then obtain pps  where\n        \"(Q, t) = (Seq a P1, b) \\<and> \n            cfg1 = map (\\<lambda>(c, y). (Seq c P1, y)) xsa @ (c,  s') # pps\"\n          using ass local.Cons xa by auto\n      then show ?thesis\n        using local.Cons xa by auto\n      qed           \n  qed\nqed\n\nlemma catch_xs_no_empty: assumes\n     seq:\"catch_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \\<Gamma> n\" and\n     cfg:\"cfg = (LanguageCon.com.Catch P0 P1, s) # (Q, t) # cfg1\" and\n     a0:\"SmallStepCon.redex (LanguageCon.com.Catch P0 P1) = LanguageCon.com.Call f\"\n     shows\"\\<exists>Q' xs'. Q=Catch Q' P1 \\<and> xs=(Q',t)#xs'\"\nusing seq\nunfolding lift_catch_def catch_cond_nest_def\nproof\n    assume \"(Q, t) # cfg1 = map (\\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs\"\n    thus ?thesis by auto\nnext\n  assume \"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n    snd (last ((P0, s) # xs)) =  s' \\<and>\n    s =  s'' \\<and>\n    (\\<exists>ys. (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n          (Q, t) # cfg1 = map (\\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @ \n                                          (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<or>\n    (\\<exists>c. fst (((P0, s) # xs) ! length xs) = c \\<and> (c=Skip  \\<or> (\\<exists>f. c = Fault f)\\<or> c=Stuck) \\<and>\n    (\\<exists>ys. (n, \\<Gamma>, (c, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n          (Q, t) # cfg1 =\n          map (\\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @ \n                         (c, snd (last ((P0, s) # xs))) # ys))\"\n  thus ?thesis\n  proof \n    assume ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n                snd (last ((P0, s) # xs)) =  s' \\<and>\n                s =  s'' \\<and>\n                (\\<exists>ys. (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n                  (Q, t) # cfg1 = map (\\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @ \n                                          (P1, snd (((P0, s) # xs) ! length xs)) # ys)\"\n    show ?thesis \n    proof (cases xs)\n      case Nil thus ?thesis using cfg a0 ass by auto\n    next\n      case (Cons xa xsa)\n      then obtain a b where xa:\"xa = (a,b)\"\n        using prod.exhaust_sel by blast        \n      obtain pps  where\n        \"(Q, t) = (Catch a P1, b) \\<and> \n             cfg1 = map (\\<lambda>(c, y). (Catch c P1, y)) xsa @ \n              (P1, snd (((P0, s) # xs) ! length xs)) # pps\"\n        using ass local.Cons xa by moura\n      then show ?thesis\n        using local.Cons xa by auto\n      qed\n  next\n    assume ass:\"(\\<exists>c. fst (((P0, s) # xs) ! length xs) = c \\<and> (c=Skip  \\<or> (\\<exists>f. c = Fault f)\\<or> c=Stuck) \\<and>\n    (\\<exists>ys. (n, \\<Gamma>, (c, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n          (Q, t) # cfg1 =\n          map (\\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @ \n                         (c, snd (last ((P0, s) # xs))) # ys))\"\n    thus ?thesis\n    proof (cases xs)\n      case Nil thus ?thesis using cfg a0 ass by auto\n    next\n      case (Cons xa xsa)\n      then obtain a b where xa:\"xa = (a,b)\" \n        using prod.exhaust_sel by blast    \n      obtain c where \"fst (((P0, s) # xs) ! length xs) = c \\<and> (c=Skip  \\<or> (\\<exists>f. c = Fault f)\\<or> c=Stuck) \\<and>\n                      (\\<exists>ys. (n, \\<Gamma>, (c, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                      (Q, t) # cfg1 =  map (\\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @ \n                         (c, snd (last ((P0, s) # xs))) # ys)\"\n        using ass by auto\n      then obtain pps where\n          \"(Q, t) = (Catch a P1, b) \\<and> \n           cfg1 = map (\\<lambda>(c, y). (Catch c P1, y)) xsa @ (c, snd (last ((P0, s) # xs))) # pps\"\n        using ass local.Cons xa by auto      \n      then show ?thesis\n        using local.Cons xa by auto\n    qed        \n  qed\nqed\n\nlemma redex_call_cptn_mod_min_nest_call_gr_zero:\n assumes a0:\"min_call n \\<Gamma> cfg\" and\n         a1:\"cfg = (P,s)#(Q,t)#cfg1\" and\n         a2:\"redex P = Call f \\<and>  \n             \\<Gamma> f = Some bdy \\<and> t=s\" and\n         a3:\"\\<Gamma>\\<turnstile>\\<^sub>c(P,toSeq s)\\<rightarrow>(Q,toSeq t)\"\n shows \"n>0\"\nusing a0 a1 a2 a3\nproof (induct P arbitrary: Q cfg1 cfg s t n)\n  case (Call f1)\n  then show ?case using Call stepc_not_normal_elim_cases\n     elim_cptn_mod_nest_call_n_greater_zero unfolding min_call_def\n    by (metis SmallStepCon.redex.simps(7) option.distinct(1) )\nnext\n  case (Seq P0 P1) \n  then obtain xs s' s'' where \n          p0_cptn:\"(n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call\"  and \n          seq:\"seq_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \\<Gamma> n\"\n  using div_seq_nest[of n \\<Gamma> cfg] unfolding min_call_def by blast\n  then obtain m where min:\"min_call m \\<Gamma> ((P0, s)#xs)\"\n    using minimum_nest_call by blast \n  have xs':\"\\<exists>Q' xs'. Q=Seq Q' P1 \\<and> xs=(Q',t)#xs'\"\n     using seq Seq seq_xs_no_empty\n     by meson \n  then have \"0<m\" using Seq(1,5,6) min\n    using SmallStepCon.redex.simps(4) stepc_elim_cases_Seq_Seq by metis\n  thus ?case by (metis min min_call_def not_gr0 p0_cptn) \nnext\n  case (Catch P0 P1)\n then obtain xs s' s'' where \n          p0_cptn:\"(n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call\"  and \n          seq:\"catch_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \\<Gamma> n\"\n  using div_catch_nest[of n \\<Gamma> cfg] unfolding min_call_def by blast\n  then obtain m where min:\"min_call m \\<Gamma> ((P0, s)#xs)\"\n    using minimum_nest_call by blast \n  obtain Q' xs' where xs':\"Q=Catch Q' P1 \\<and> xs=(Q',t)#xs'\"\n     using catch_xs_no_empty[OF seq Catch(4)] Catch by blast\n  then have \"0<m\" using Catch(1,5,6) min\n    using  stepc_elim_cases_Catch_Catch\n    by (metis SmallStepCon.redex.simps(11))\n  thus ?case by (metis min min_call_def not_gr0 p0_cptn)\nqed(auto)\n\n  \n\n(* lemma elim_redex_call_cptn_mod_min_nest_call:\n assumes a0:\"min_call n \\<Gamma> cfg\" and\n         a1:\"cfg = (P,s)#(Q,t)#cfg1\" and\n         a2:\"redex P = Call f \\<and>  \n             \\<Gamma> f = Some bdy \\<and> (\\<exists>sa. s=Normal sa) \\<and> t=s \" and\n         a3:\"biggest_nest_call P s ((Q,t)#cfg1) \\<Gamma> n\"  \n shows \"min_call n \\<Gamma> ((Q,t)#cfg1)\"\nusing a0 a1 a2 a3 \nproof (induct P arbitrary: Q cfg1 cfg s t n)  \n  case Cond thus ?case by fastforce\nnext\n  case (Seq P0 P1) \n  then obtain xs s' s'' where \n          p0_cptn:\"(n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call\"  and \n          seq:\"seq_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \\<Gamma> n\"\n  using div_seq_nest[of n \\<Gamma> cfg] unfolding min_call_def by blast\n  \n  show ?case using seq unfolding seq_cond_nest_def \n  proof\n    assume ass:\"(Q, t) # cfg1 = map (lift P1) xs\"   \n    then obtain Q' xs' where xs':\"Q=Seq Q' P1 \\<and> xs=(Q',t)#xs'\"\n      unfolding lift_def by fastforce\n    then have ctpn_P0:\"(P0, s) # xs = (P0, s) # (Q', t) # xs'\" by auto\n    then have min_p0:\"min_call n \\<Gamma> ((P0, s)#xs)\"\n      using min_call_seq_c1_not_finish[OF Seq(3) Seq(4) p0_cptn] ass by auto\n    then have ex_xs:\"\\<exists>xs. min_call n \\<Gamma> ((P0, s)#xs) \\<and> (Q, t) # cfg1 = map (lift P1) xs\" \n      using ass by auto\n    then have min_xs:\"min_call n \\<Gamma> ((P0, s)#xs) \\<and> (Q, t) # cfg1 = map (lift P1) xs\" \n      using min_p0 ass by auto\n    have \"xs= (SOME xs. (min_call n \\<Gamma> ((P0, s)#xs) \\<and> (Q, t) # cfg1 = map (lift P1) xs))\"\n    proof -\n      have \"\\<forall>xsa. min_call n \\<Gamma> ((P0, s)#xsa) \\<and> (Q, t) # cfg1 = map (lift P1) xsa \\<longrightarrow> xsa = xs\"\n        using xs' ass by (metis map_lift_eq_xs_xs')\n      thus ?thesis using min_xs some_equality by (metis (mono_tags, lifting))\n    qed\n    then have big:\"biggest_nest_call P0 s ((Q', t) # xs') \\<Gamma> n\" \n      using biggest_nest_call.simps(1)[of P0 P1 s \"((Q, t) # cfg1)\" \\<Gamma> n] \n            Seq(6) xs' ex_xs by auto         \n    have reP0:\"redex P0 = (Call f) \\<and> \\<Gamma> f = Some bdy \\<and> \n              (\\<exists>saa. s = Normal saa) \\<and> t = s \" using Seq(5) xs' by auto    \n    have min_call:\"min_call n \\<Gamma> ((Q', t) # xs')\" \n       using Seq(1)[OF min_p0 ctpn_P0 reP0] big xs' ass by auto\n    thus ?thesis using min_call_seq_not_finish[OF min_call] ass xs' by blast\n  next\n    assume ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \\<and>\n                  (\\<exists>ys. (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n                  (Q, t) # cfg1 = map (lift P1) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<or>\n                fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n                  snd (last ((P0, s) # xs)) = Normal s' \\<and>\n                  s = Normal s'' \\<and>\n                  (\\<exists>ys. (n, \\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and>\n                     (Q, t) # cfg1 = map (lift P1) xs @ (LanguageCon.com.Throw, Normal s') # ys)\"\n    {assume ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \\<and>\n            (\\<exists>ys. (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n            (Q, t) # cfg1 = map (lift P1) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys)\"     \n     have ?thesis \n     proof (cases xs)\n       case Nil thus ?thesis using Seq ass by fastforce\n     next\n       case (Cons xa xsa)\n       then obtain ys where \n         seq2_ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \\<and> \n          (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n          (Q, t) # cfg1 = map (lift P1) (xa#xsa) @ (P1, snd (((P0, s) # xs) ! length xs)) # ys\"\n          using ass by auto \n        then obtain mq mp1 where \n         min_call_q:\"min_call mq \\<Gamma> ((P0, s) # xs)\" and\n         min_call_p1:\"min_call mp1 \\<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)\"         \n       using seq2_ass minimum_nest_call p0_cptn by fastforce               \n       then have mp: \"mq\\<le>n \\<and> mp1 \\<le>n\"\n         using seq2_ass min_call_less_eq_n[of n \\<Gamma> P0 s xs P1 ys  mq mp1] \n             Seq(3,4) p0_cptn by (simp add: last_length)\n       have min_call:\"min_call n \\<Gamma> ((P0, s) # xs) \\<or> \n             min_call n \\<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)\"\n         using seq2_ass min_call_seq2[of n \\<Gamma> P0 P1 s \"(Q, t) # cfg1\" xs ys] \n             Seq(3,4) p0_cptn by (simp add: last_length local.Cons)       \n       from seq2_ass obtain Q' where Q':\"Q=Seq Q' P1 \\<and> xa=(Q',t)\"          \n       unfolding lift_def   \n         by (metis (mono_tags, lifting) fst_conv length_greater_0_conv \n             list.simps(3) list.simps(9) nth_Cons_0 nth_append prod.case_eq_if prod.collapse snd_conv)  \n       then have q'_n_cptn:\"(n,\\<Gamma>,(Q',t)#xsa)\\<in>cptn_mod_nest_call\" using p0_cptn Q' Cons\n         using elim_cptn_mod_nest_call_n by blast \n       show ?thesis\n       proof(cases \"mp1=n\")\n         case True\n         then have \"min_call n \\<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)\"\n           using min_call_p1 by auto\n         then have min_P1:\"min_call n \\<Gamma> ((P1, snd ((xa # xsa) ! length xsa)) # ys)\"\n           using Cons seq2_ass by fastforce         \n         then have p1_n_cptn:\"(n, \\<Gamma>,  (Q, t) # cfg1) \\<in> cptn_mod_nest_call\"\n           using Seq.prems(1) Seq.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast\n         also then have \"(\\<forall>m<n. (m, \\<Gamma>, (Q, t) # cfg1) \\<notin> cptn_mod_nest_call)\" \n         proof-\n         { fix m\n           assume ass:\"m<n\" \n           { assume Q_m:\"(m, \\<Gamma>, (Q, t) # cfg1) \\<in> cptn_mod_nest_call\"             \n            then have False using min_P1 ass Q' Cons unfolding min_call_def\n            proof -\n              assume a1: \"(n, \\<Gamma>, (P1, snd ((xa # xsa) ! length xsa)) # ys) \\<in> cptn_mod_nest_call \\<and> (\\<forall>m<n. (m, \\<Gamma>, (P1, snd ((xa # xsa) ! length xsa)) # ys) \\<notin> cptn_mod_nest_call)\"\n              have f2: \"\\<forall>n f ps. (n, f, ps) \\<notin> cptn_mod_nest_call \\<or> (\\<forall>x c ca psa. ps \\<noteq> (LanguageCon.com.Seq (c::('b, 'a, 'c,'d) LanguageCon.com) ca, x) # psa \\<or> (\\<exists>ps b ba. (n, f, (c, x) # ps) \\<in> cptn_mod_nest_call \\<and> seq_cond_nest psa ca ps c x ba b f n))\"\n                using div_seq_nest by blast\n              have f3: \"(P1, snd (last ((Q', t) # xsa))) # ys = (P1, snd (((P0, s) # xs) ! length xs)) # ys\"\n                by (simp add: Q' last_length local.Cons)\n              have \"fst (last ((Q', t) # xsa)) = LanguageCon.com.Skip\"\n                by (metis (no_types) Q' last_ConsR last_length list.distinct(1) local.Cons seq2_ass)\n              then show ?thesis\n                using f3 f2 a1 by (metis (no_types) Cons_lift_append Q' Seq_P_Ends_Normal Q_m ass seq2_ass)\n            qed\n           } \n         } then show ?thesis by auto\n         qed           \n         ultimately show ?thesis unfolding min_call_def by auto\n       next\n         case False\n         then have \"mp1<n\" using mp by auto\n         then have not_min_call_p1_n:\"\\<not> min_call n \\<Gamma> ((P1, snd (last ((P0, s) # xs))) # ys)\"\n           using min_call_p1 last_length unfolding min_call_def by metis\n         then have min_call:\"min_call n \\<Gamma> ((P0, s) # xs)\" \n           using min_call last_length unfolding min_call_def by metis\n         then have \"(P0, s) # xs = (P0, s) # xa#xsa\"\n           using Cons by auto\n         then have big:\"biggest_nest_call P0 s (((Q',t))#xsa) \\<Gamma> n\"\n         proof-\n           have \"\\<not>(\\<exists>xs. min_call n \\<Gamma> ((P0, s)#xs) \\<and> (Q, t) # cfg1 = map (lift P1) xs)\"\n             using min_call seq2_ass Cons\n            proof -\n              have \"min_call n \\<Gamma> ((LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1)\"\n                using Seq.prems(1) Seq.prems(2) by blast\n              then show ?thesis\n                by (metis (no_types) Seq_P_Not_finish append_Nil2 list.simps(3) \n                          local.Cons min_call_def same_append_eq seq seq2_ass)\n            qed\n            moreover have \"\\<exists>xs ys. cond_seq_1 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys\"\n              using seq2_ass p0_cptn unfolding cond_seq_1_def \n              by (metis last_length local.Cons) \n            moreover have \"(SOME xs. \\<exists>ys. cond_seq_1 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys) = xs\"  \n            proof -\n              let ?P = \"\\<lambda>xsa. \\<exists>ys. (n, \\<Gamma>, (P0, s) # xsa) \\<in> cptn_mod_nest_call \\<and>\n                   fst (last ((P0, s) # xsa)) = LanguageCon.com.Skip \\<and>\n                   (n, \\<Gamma>, (P1, snd (last ((P0, s) # xsa))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                   (Q, t) # cfg1 = map (lift P1) xsa @ (P1, snd (last ((P0, s) # xsa))) # ys\"             \n              have \"(\\<And>x. \\<exists>ys. (n, \\<Gamma>, (P0, s) # x) \\<in> cptn_mod_nest_call \\<and>\n               fst (last ((P0, s) # x)) = LanguageCon.com.Skip \\<and>\n               (n, \\<Gamma>, (P1, snd (last ((P0, s) # x))) # ys) \\<in> cptn_mod_nest_call \\<and>\n               (Q, t) # cfg1 = map (lift P1) x @ (P1, snd (last ((P0, s) # x))) # ys \\<Longrightarrow>\n                   x = xs)\"              \n              by (metis Seq_P_Ends_Normal cptn_mod_nest_call.CptnModNestSeq2 seq)\n              moreover have \"\\<exists>ys. (n, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call \\<and>\n                   fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \\<and>\n                   (n, \\<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                   (Q, t) # cfg1 = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys\"\n                using ass  p0_cptn by (simp add: last_length)               \n              ultimately show ?thesis using some_equality[of ?P xs]\n                 unfolding cond_seq_1_def by blast \n            qed\n            moreover have \"(SOME ys. cond_seq_1 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys) = ys\"\n            proof -\n               let ?P = \"\\<lambda>ys. (n, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call \\<and>\n                   fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \\<and>\n                   (n, \\<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                   (Q, t) # cfg1 = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys\"\n                have \"(n, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call \\<and>\n                   fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \\<and>\n                   (n, \\<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                   (Q, t) # cfg1 = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys\"\n                 using p0_cptn seq2_ass Cons   by (simp add: last_length) \n                then show ?thesis using some_equality[of ?P ys]\n                 unfolding cond_seq_1_def by fastforce      \n            qed\n            ultimately have \"biggest_nest_call P0 s xs \\<Gamma> n\"\n              using not_min_call_p1_n Seq(6) \n                    biggest_nest_call.simps(1)[of P0 P1 s \"(Q, t) # cfg1\" \\<Gamma> n]\n              by presburger\n            then show ?thesis  using Cons Q' by auto\n          qed\n          have C:\"(P0, s) # xs = (P0, s) # (Q', t) # xsa\" using Cons Q' by auto\n          have reP0:\"redex P0 = (Call f) \\<and> \\<Gamma> f = Some bdy \\<and> \n            (\\<exists>saa. s = Normal saa) \\<and> t = s\" using Seq(5) Q' by auto\n          then have min_call:\"min_call n \\<Gamma> ((Q', t) # xsa)\" using Seq(1)[OF min_call C reP0 big]\n            by auto\n          have p1_n_cptn:\"(n, \\<Gamma>,  (Q, t) # cfg1) \\<in> cptn_mod_nest_call\"\n            using Seq.prems(1) Seq.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast\n          also then have \"(\\<forall>m<n. (m, \\<Gamma>, (Q, t) # cfg1) \\<notin> cptn_mod_nest_call)\" \n          proof-\n           { fix m\n             assume ass:\"m<n\" \n             { assume Q_m:\"(m, \\<Gamma>, (Q, t) # cfg1) \\<in> cptn_mod_nest_call\" \n               then obtain xsa' s1 s1' where \n                  p0_cptn:\"(m, \\<Gamma>,(Q', t)#xsa') \\<in> cptn_mod_nest_call\"  and\n                  seq:\"seq_cond_nest cfg1 P1 xsa' Q' t s1 s1' \\<Gamma> m\"\n               using div_seq_nest[of m \\<Gamma> \"(Q, t) # cfg1\"] Q' by blast\n               then have \"xsa=xsa'\" \n                 using seq2_ass \n                 Seq_P_Ends_Normal[of cfg1 P1 xsa Q' t ys m \\<Gamma> xsa' s1 s1'] Cons\n                 by (metis Cons_lift_append Q' Q_m last.simps last_length list.inject list.simps(3)) \n               then have False using min_call p0_cptn ass unfolding min_call_def by auto \n             } \n           } then show ?thesis by auto qed\n             \n         ultimately show ?thesis unfolding min_call_def by auto\n       qed    \n     qed\n    }note l=this\n    {assume ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n             snd (last ((P0, s) # xs)) = Normal s' \\<and>\n            s = Normal s'' \\<and> (\\<exists>ys. (n, \\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and>\n          (Q, t) # cfg1 = map (lift P1) xs @ (LanguageCon.com.Throw, Normal s') # ys)\"          \n     have ?thesis\n     proof (cases \"\\<Gamma>\\<turnstile>\\<^sub>c(LanguageCon.com.Seq P0 P1, s) \\<rightarrow> (Q,t)\")\n       case True \n       thus  ?thesis\n       proof (cases xs)\n          case Nil thus ?thesis using Seq ass by fastforce\n       next\n         case (Cons xa xsa)\n         then obtain ys where \n           seq2_ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n             snd (last ((P0, s) # xs)) = Normal s' \\<and>\n            s = Normal s'' \\<and>  (n, \\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and>\n           (Q, t) # cfg1 = map (lift P1) xs @ (LanguageCon.com.Throw, Normal s') # ys\"\n            using ass by auto \n         then have t_eq:\"t=Normal s''\" using Seq by fastforce\n         obtain mq mp1 where \n           min_call_q:\"min_call mq \\<Gamma> ((P0, s) # xs)\" and\n           min_call_p1:\"min_call mp1 \\<Gamma> ((Throw, snd (((P0, s) # xs) ! length xs)) # ys)\"         \n         using seq2_ass minimum_nest_call p0_cptn by (metis last_length)\n         then have mp1_zero:\"mp1=0\" by (simp add: throw_min_nested_call_0)\n         then have min_call: \"min_call n \\<Gamma> ((P0, s) # xs)\"  \n           using seq2_ass min_call_seq3[of n \\<Gamma> P0 P1 s \"(Q, t) # cfg1\" s'' xs s' ys]\n             Seq(3,4) p0_cptn by (metis last_length)      \n         have n_z:\"n>0\" using redex_call_cptn_mod_min_nest_call_gr_zero[OF Seq(3) Seq(4) Seq(5) True]\n           by auto          \n         from seq2_ass obtain Q' where Q':\"Q=Seq Q' P1 \\<and> xa=(Q',t)\"          \n           unfolding lift_def using Cons\n          proof -\n            assume a1: \"\\<And>Q'. Q = LanguageCon.com.Seq Q' P1 \\<and> xa = (Q', t) \\<Longrightarrow> thesis\"\n            have \"(LanguageCon.com.Seq (fst xa) P1, snd xa) = ((Q, t) # cfg1) ! 0\"\n             using seq2_ass unfolding lift_def\n              by (simp add: Cons case_prod_unfold)\n            then show ?thesis\n              using a1 by fastforce\n          qed  \n         have big_call:\"biggest_nest_call P0 s ((Q',t)#xsa) \\<Gamma> n\"\n         proof-\n           have \"\\<not>(\\<exists>xs. min_call n \\<Gamma> ((P0, s)#xs) \\<and> (Q, t) # cfg1 = map (lift P1) xs)\"\n             using min_call seq2_ass Cons Seq.prems(1) Seq.prems(2)\n           by (metis Seq_P_Not_finish append_Nil2 list.simps(3) min_call_def same_append_eq seq)\n           moreover have \"\\<not>(\\<exists>xs ys. cond_seq_1 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys)\" \n             using min_call seq2_ass p0_cptn Cons Seq.prems(1) Seq.prems(2) \n             unfolding cond_seq_1_def\n            by (metis com.distinct(17) com.distinct(71) last_length \n                      map_lift_some_eq seq_and_if_not_eq(4))\n           moreover have \"(SOME xs. \\<exists>ys s' s''. cond_seq_2 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys s' s'') = xs\"\n           proof-\n             let ?P=\"\\<lambda>xsa. \\<exists>ys s' s''. s= Normal s'' \\<and> \n                    (n,\\<Gamma>, (P0, s)#xs) \\<in> cptn_mod_nest_call \\<and> \n                    fst(last ((P0, s)#xs)) = Throw \\<and>\n                    snd(last ((P0, s)#xs)) = Normal s' \\<and> \n                    (n,\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod_nest_call \\<and> \n                     ((Q, t) # cfg1)=(map (lift P1) xs)@((Throw,Normal s')#ys)\"\n             have \"(\\<And>x. \\<exists>ys s' s''. s= Normal s'' \\<and> \n                    (n,\\<Gamma>, (P0, s)#x) \\<in> cptn_mod_nest_call \\<and> \n                    fst(last ((P0, s)#x)) = Throw \\<and>\n                    snd(last ((P0, s)#x)) = Normal s' \\<and> \n                    (n,\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod_nest_call \\<and> \n                     ((Q, t) # cfg1)=(map (lift P1) x)@((Throw,Normal s')#ys) \\<Longrightarrow>\n                    x=xs)\" using map_lift_some_eq seq2_ass by fastforce\n             moreover have \"\\<exists>ys s' s''. s= Normal s'' \\<and> \n                    (n,\\<Gamma>, (P0, s)#xs) \\<in> cptn_mod_nest_call \\<and> \n                    fst(last ((P0, s)#xs)) = Throw \\<and>\n                    snd(last ((P0, s)#xs)) = Normal s' \\<and> \n                    (n,\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod_nest_call \\<and> \n                     ((Q, t) # cfg1)=(map (lift P1) xs)@((Throw,Normal s')#ys)\" \n                using ass p0_cptn by (simp add: last_length Cons)\n            ultimately show ?thesis using some_equality[of ?P xs]\n                 unfolding cond_seq_2_def by blast\n         qed\n           ultimately have \"biggest_nest_call P0 s xs \\<Gamma> n\"\n            using  Seq(6) \n                  biggest_nest_call.simps(1)[of P0 P1 s \"(Q, t) # cfg1\" \\<Gamma> n]\n            by presburger\n           then show ?thesis  using Cons Q' by auto\n         qed         \n         have min_call:\"min_call n \\<Gamma> ((Q',t)#xsa)\" \n           using Seq(1)[OF min_call _ _ big_call] Seq(5) Cons Q' by fastforce   \n         then have p1_n_cptn:\"(n, \\<Gamma>,  (Q, t) # cfg1) \\<in> cptn_mod_nest_call\"\n            using Seq.prems(1) Seq.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast   \n         also then have \"(\\<forall>m<n. (m, \\<Gamma>, (Q, t) # cfg1) \\<notin> cptn_mod_nest_call)\" \n          proof-\n           { fix m\n             assume ass:\"m<n\" \n             { assume Q_m:\"(m, \\<Gamma>, (Q, t) # cfg1) \\<in> cptn_mod_nest_call\" \n               then obtain xsa' s1 s1' where \n                  p0_cptn:\"(m, \\<Gamma>,(Q', t)#xsa') \\<in> cptn_mod_nest_call\"  and\n                  seq:\"seq_cond_nest cfg1 P1 xsa' Q' (Normal s'') s1 s1' \\<Gamma> m\"\n               using div_seq_nest[of m \\<Gamma> \"(Q, t) # cfg1\"] Q' t_eq by blast\n               then have \"xsa=xsa'\" \n                 using seq2_ass \n                 Seq_P_Ends_Abort[of cfg1 P1 xsa s' ys Q' s'' m \\<Gamma> xsa' s1 s1' ] Cons Q' Q_m\n                 by (simp add: Cons_lift_append last_length t_eq)                 \n               then have False using min_call p0_cptn ass unfolding min_call_def by auto \n             } \n           } then show ?thesis by auto qed          \n         ultimately show ?thesis unfolding min_call_def by auto\n       qed\n     next\n       case False \n       then have env:\"\\<Gamma>\\<turnstile>\\<^sub>c(LanguageCon.com.Seq P0 P1, s) \\<rightarrow>\\<^sub>e (Q,t)\" using Seq\n         by (meson elim_cptn_mod_nest_step_c min_call_def)\n       moreover then have Q:\"Q=Seq P0 P1\" using env_c_c' by blast        \n       ultimately show ?thesis using Seq\n        proof -\n          obtain nn :: \"(('b, 'a, 'c,'d) LanguageCon.com \\<times> ('b, 'c) xstate) list \\<Rightarrow> \n                         ('a \\<Rightarrow> ('b, 'a, 'c,'d) LanguageCon.com option) \\<Rightarrow> nat \\<Rightarrow> nat\" where\n            f1: \"\\<forall>x0 x1 x2. (\\<exists>v3<x2. (v3, x1, x0) \\<in> cptn_mod_nest_call) = (nn x0 x1 x2 < x2 \\<and> (nn x0 x1 x2, x1, x0) \\<in> cptn_mod_nest_call)\"\n            by moura\n          have f2: \"(n, \\<Gamma>, (LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1) \\<in> cptn_mod_nest_call \\<and> (\\<forall>n. \\<not> n < n \\<or> (n, \\<Gamma>, (LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1) \\<notin> cptn_mod_nest_call)\"\n            using local.Seq(3) local.Seq(4) min_call_def by blast\n          then have \"\\<not> nn ((Q, t) # cfg1) \\<Gamma> n < n \\<or> (nn ((Q, t) # cfg1) \\<Gamma> n, \\<Gamma>, (Q, t) # cfg1) \\<notin> cptn_mod_nest_call\"\n            using False env env_c_c'  not_func_redex_cptn_mod_nest_n_env \n            by (metis Seq.prems(1) Seq.prems(2) min_call_def)\n          then show ?thesis\n            using f2 f1 by (meson elim_cptn_mod_nest_call_n min_call_def)\n        qed\n     qed          \n    }\n    thus ?thesis using l ass by fastforce\n  qed\nnext\n  case (Catch P0 P1) \nthen obtain xs s' s'' where \n          p0_cptn:\"(n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call\"  and \n          catch:\"catch_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \\<Gamma> n\"\n  using div_catch_nest[of n \\<Gamma> cfg] unfolding min_call_def by blast\n  \n  show ?case using catch unfolding catch_cond_nest_def \n  proof\n    assume ass:\"(Q, t) # cfg1 = map (lift_catch P1) xs\"   \n    then obtain Q' xs' where xs':\"Q=Catch Q' P1 \\<and> xs=(Q',t)#xs'\"\n      unfolding lift_catch_def by fastforce\n    then have ctpn_P0:\"(P0, s) # xs = (P0, s) # (Q', t) # xs'\" by auto\n    then have min_p0:\"min_call n \\<Gamma> ((P0, s)#xs)\"\n      using min_call_catch_c1_not_finish[OF Catch(3) Catch(4) p0_cptn] ass by auto\n    then have ex_xs:\"\\<exists>xs. min_call n \\<Gamma> ((P0, s)#xs) \\<and> (Q, t) # cfg1 = map (lift_catch P1) xs\" \n      using ass by auto\n    then have min_xs:\"min_call n \\<Gamma> ((P0, s)#xs) \\<and> (Q, t) # cfg1 = map (lift_catch P1) xs\" \n      using min_p0 ass by auto\n    have \"xs= (SOME xs. (min_call n \\<Gamma> ((P0, s)#xs) \\<and> (Q, t) # cfg1 = map (lift_catch P1) xs))\"\n    proof -\n      have \"\\<forall>xsa. min_call n \\<Gamma> ((P0, s)#xsa) \\<and> (Q, t) # cfg1 = map (lift_catch P1) xsa \\<longrightarrow> xsa = xs\"\n        using xs' ass by (metis map_lift_catch_eq_xs_xs')\n      thus ?thesis using min_xs some_equality by (metis (mono_tags, lifting))\n    qed\n    then have big:\"biggest_nest_call P0 s ((Q', t) # xs') \\<Gamma> n\" \n      using biggest_nest_call.simps(2)[of P0 P1 s \"((Q, t) # cfg1)\" \\<Gamma> n] \n            Catch(6) xs' ex_xs by auto          \n    have reP0:\"redex P0 = (Call f) \\<and> \\<Gamma> f = Some bdy \\<and> \n              (\\<exists>saa. s = Normal saa) \\<and> t = s \" using Catch(5) xs' by auto    \n    have min_call:\"min_call n \\<Gamma> ((Q', t) # xs')\" \n       using Catch(1)[OF min_p0 ctpn_P0 reP0] big xs' ass by auto\n    thus ?thesis using min_call_catch_not_finish[OF min_call] ass xs' by blast\n  next\n    assume ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n                snd (last ((P0, s) # xs)) = Normal s' \\<and>\n                s = Normal s'' \\<and>\n               (\\<exists>ys. (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n                  (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<or>\n                   fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \\<and>\n                  (\\<exists>ys. (n, \\<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                (Q, t) # cfg1 = map (lift_catch P1) xs @ (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys)\" \n    {assume ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n                snd (last ((P0, s) # xs)) = Normal s' \\<and>\n                s = Normal s'' \\<and>\n               (\\<exists>ys. (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n                  (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys)\"     \n     have ?thesis \n     proof (cases xs)\n       case Nil thus ?thesis using Catch ass by fastforce\n     next\n       case (Cons xa xsa)\n       then obtain ys where \n         catch2_ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n                snd (last ((P0, s) # xs)) = Normal s' \\<and>\n                s = Normal s'' \\<and>\n                (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n                (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys\"\n          using ass by auto \n        then obtain mq mp1 where \n         min_call_q:\"min_call mq \\<Gamma> ((P0, s) # xs)\" and\n         min_call_p1:\"min_call mp1 \\<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)\"         \n       using catch2_ass minimum_nest_call p0_cptn by fastforce               \n       then have mp: \"mq\\<le>n \\<and> mp1 \\<le>n\"\n         using catch2_ass min_call_less_eq_n \n             Catch(3,4) p0_cptn by (metis last_length) \n       have min_call:\"min_call n \\<Gamma> ((P0, s) # xs) \\<or> \n             min_call n \\<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)\"\n         using catch2_ass min_call_catch3[of n \\<Gamma> P0 P1 s'' \"(Q, t) # cfg1\" xs s' ys] \n             Catch(3,4) p0_cptn by (metis last_length)       \n       from catch2_ass obtain Q' where Q':\"Q=Catch Q' P1 \\<and> xa=(Q',t)\"          \n       unfolding lift_catch_def\n        proof -\n          assume a1: \"\\<And>Q'. Q = LanguageCon.com.Catch Q' P1 \\<and> xa = (Q', t) \\<Longrightarrow> thesis\"\n          assume \"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and> snd (last ((P0, s) # xs)) = Normal s' \\<and> s = Normal s'' \\<and> (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and> (Q, t) # cfg1 = map (\\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys\"\n          then have \"(LanguageCon.com.Catch (fst xa) P1, snd xa) = ((Q, t) # cfg1) ! 0\"\n            by (simp add: local.Cons prod.case_eq_if)\n          then show ?thesis\n            using a1 by force\n        qed            \n       then have q'_n_cptn:\"(n,\\<Gamma>,(Q',t)#xsa)\\<in>cptn_mod_nest_call\" using p0_cptn Q' Cons\n         using elim_cptn_mod_nest_call_n by blast \n       show ?thesis\n       proof(cases \"mp1=n\")\n         case True\n         then have \"min_call n \\<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)\"\n           using min_call_p1 by auto\n         then have min_P1:\"min_call n \\<Gamma> ((P1, snd ((xa # xsa) ! length xsa)) # ys)\"\n           using Cons catch2_ass by fastforce         \n         then have p1_n_cptn:\"(n, \\<Gamma>,  (Q, t) # cfg1) \\<in> cptn_mod_nest_call\"\n           using Catch.prems(1) Catch.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast\n         also then have \"(\\<forall>m<n. (m, \\<Gamma>, (Q, t) # cfg1) \\<notin> cptn_mod_nest_call)\" \n         proof-\n         { fix m\n           assume ass:\"m<n\" \n           { assume Q_m:\"(m, \\<Gamma>, (Q, t) # cfg1) \\<in> cptn_mod_nest_call\"   \n             then have t_eq_s:\"t=Normal s''\" using Catch catch2_ass by fastforce                      \n            then obtain xsa' s1 s1' where \n                  p0_cptn:\"(m, \\<Gamma>,(Q', t)#xsa') \\<in> cptn_mod_nest_call\"  and\n                  catch_cond:\"catch_cond_nest cfg1 P1 xsa' Q' (Normal s'') s1 s1' \\<Gamma> m\"\n              using Q_m div_catch_nest[of m \\<Gamma> \"(Q, t) # cfg1\"] Q' by blast\n            have fst:\"fst (last ((Q', Normal s'') # xsa)) = LanguageCon.com.Throw\" \n              using catch2_ass Cons Q' by (simp add: last_length  t_eq_s)\n            have cfg:\"cfg1 = map (lift_catch P1) xsa @ (P1, snd (last ((Q', Normal s'') # xsa))) # ys\"\n              using catch2_ass Cons Q' by (simp add: last_length  t_eq_s)\n            have snd:\"snd (last ((Q', Normal s'') # xsa)) = Normal s'\"\n              using catch2_ass Cons Q' by (simp add: last_length  t_eq_s)\n            then have \"xsa=xsa' \\<and> \n                   (m, \\<Gamma>, (P1, snd (((Q', Normal s'') # xsa) ! length xsa)) # ys) \\<in> cptn_mod_nest_call\" \n              using catch2_ass Catch_P_Ends_Normal[OF cfg fst snd catch_cond] Cons\n              by auto \n            then have False using min_P1 ass Q' t_eq_s unfolding min_call_def by auto              \n           } \n         } then show ?thesis by auto\n         qed           \n         ultimately show ?thesis unfolding min_call_def by auto\n       next\n         case False\n         then have \"mp1<n\" using mp by auto\n         then have not_min_call_p1_n:\"\\<not> min_call n \\<Gamma> ((P1, snd (last ((P0, s) # xs))) # ys)\"\n           using min_call_p1 last_length unfolding min_call_def by metis\n         then have min_call:\"min_call n \\<Gamma> ((P0, s) # xs)\" \n           using min_call last_length unfolding min_call_def by metis\n         then have \"(P0, s) # xs = (P0, s) # xa#xsa\"\n           using Cons by auto\n         then have big:\"biggest_nest_call P0 s (((Q',t))#xsa) \\<Gamma> n\"\n         proof-\n           have \"\\<not>(\\<exists>xs. min_call n \\<Gamma> ((P0, s)#xs) \\<and> (Q, t) # cfg1 = map (lift_catch P1) xs)\"\n             using min_call catch2_ass Cons\n            proof -\n              have \"min_call n \\<Gamma> ((Catch P0 P1, s) # (Q, t) # cfg1)\"\n                using Catch.prems(1) Catch.prems(2) by blast\n              then show ?thesis\n                by (metis (no_types) Catch_P_Not_finish append_Nil2 list.simps(3) \n                     same_append_eq catch catch2_ass)\n            qed\n            moreover have \"\\<not>(\\<exists>xs ys. cond_catch_1 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys)\"\n              unfolding cond_catch_1_def using catch2_ass \n              by (metis Catch_P_Ends_Skip LanguageCon.com.distinct(17) catch last_length)\n            moreover have \"\\<exists>xs ys. cond_catch_2 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys s' s''\"\n              using catch2_ass p0_cptn unfolding cond_catch_2_def last_length\n              by metis \n            moreover have \"(SOME xs. \\<exists>ys s' s''. cond_catch_2 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys s' s'') = xs\"  \n            proof -\n              let ?P = \"\\<lambda>xsa. s = Normal s'' \\<and>\n                              (n, \\<Gamma>, (P0, s) # xsa) \\<in> cptn_mod_nest_call \\<and>\n                              fst (last ((P0, s) # xsa)) = LanguageCon.com.Throw \\<and>\n                              snd (last ((P0, s) # xsa)) = Normal s' \\<and>\n                               (n, \\<Gamma>, (P1, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and> \n                               (Q, t) # cfg1 = map (lift_catch P1) xsa @ (P1, Normal s') # ys\"             \n              have \"(\\<And>x. \\<exists>ys s' s''. s = Normal s'' \\<and>\n                              (n, \\<Gamma>, (P0, s) # x) \\<in> cptn_mod_nest_call \\<and>\n                              fst (last ((P0, s) # x)) = LanguageCon.com.Throw \\<and>\n                              snd (last ((P0, s) # x)) = Normal s' \\<and>\n                               (n, \\<Gamma>, (P1, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and> \n                               (Q, t) # cfg1 = map (lift_catch P1) x @ (P1, Normal s') # ys \\<Longrightarrow>\n                   x = xs)\"              \n              by (metis Catch_P_Ends_Normal catch)\n              moreover have \"\\<exists>ys. s = Normal s'' \\<and>\n                              (n, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call \\<and>\n                              fst (last ((P0, s) # xs)) = LanguageCon.com.Throw \\<and>\n                              snd (last ((P0, s) # xs)) = Normal s' \\<and>\n                               (n, \\<Gamma>, (P1, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and> \n                               (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, Normal s') # ys\"\n                using ass  p0_cptn   by (metis (full_types) last_length )             \n              ultimately show ?thesis using some_equality[of ?P xs]\n                 unfolding cond_catch_2_def by blast \n            qed\n            moreover have \"(SOME ys. \\<exists>s' s''. cond_catch_2 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys s' s'') = ys\"\n            proof -\n               let ?P = \"\\<lambda>ysa. s = Normal s'' \\<and>\n                              (n, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call \\<and>\n                              fst (last ((P0, s) # xs)) = LanguageCon.com.Throw \\<and>\n                              snd (last ((P0, s) # xs)) = Normal s' \\<and>\n                               (n, \\<Gamma>, (P1, Normal s') # ysa) \\<in> cptn_mod_nest_call \\<and> \n                               (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, Normal s') # ysa\"\n                have \"(\\<And>x.  \\<exists>s' s''. s = Normal s'' \\<and>\n                          (n, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call \\<and>\n                          fst (last ((P0, s) # xs)) = LanguageCon.com.Throw \\<and>\n                          snd (last ((P0, s) # xs)) = Normal s' \\<and>\n                          (n, \\<Gamma>, (P1, Normal s') # x) \\<in> cptn_mod_nest_call \\<and> (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, Normal s') # x \\<Longrightarrow>\n                          x = ys)\" using catch2_ass by auto \n                moreover have \"s = Normal s'' \\<and>\n                      (n, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call \\<and>\n                       fst (last ((P0, s) # xs)) = LanguageCon.com.Throw \\<and>\n                       snd (last ((P0, s) # xs)) = Normal s' \\<and>\n                      (n, \\<Gamma>, (P1, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and> \n                       (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, Normal s') # ys\"\n                using ass  p0_cptn by (metis (full_types) catch2_ass last_length p0_cptn)             \n                ultimately show ?thesis using some_equality[of ?P ys]\n                 unfolding cond_catch_2_def by blast\n            qed            \n            ultimately have \"biggest_nest_call P0 s xs \\<Gamma> n\"\n              using not_min_call_p1_n Catch(6) \n                    biggest_nest_call.simps(2)[of P0 P1 s \"(Q, t) # cfg1\" \\<Gamma> n]\n              by presburger\n            then show ?thesis  using Cons Q' by auto\n          qed\n          have C:\"(P0, s) # xs = (P0, s) # (Q', t) # xsa\" using Cons Q' by auto\n          have reP0:\"redex P0 = (Call f) \\<and> \\<Gamma> f = Some bdy \\<and> \n            (\\<exists>saa. s = Normal saa) \\<and> t = s \" using Catch(5) Q' by auto\n          then have min_call:\"min_call n \\<Gamma> ((Q', t) # xsa)\" using Catch(1)[OF min_call C reP0 big]\n            by auto\n          have p1_n_cptn:\"(n, \\<Gamma>,  (Q, t) # cfg1) \\<in> cptn_mod_nest_call\"\n            using Catch.prems(1) Catch.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast\n          also then have \"(\\<forall>m<n. (m, \\<Gamma>, (Q, t) # cfg1) \\<notin> cptn_mod_nest_call)\" \n          proof-\n           { fix m\n             assume ass:\"m<n\" \n             { assume Q_m:\"(m, \\<Gamma>, (Q, t) # cfg1) \\<in> cptn_mod_nest_call\" \n               then have t_eq_s:\"t=Normal s''\" using Catch catch2_ass by fastforce\n               then obtain xsa' s1 s1' where \n                  p0_cptn:\"(m, \\<Gamma>,(Q', t)#xsa') \\<in> cptn_mod_nest_call\"  and\n                  catch_cond:\"catch_cond_nest cfg1 P1 xsa' Q' (Normal s'') s1 s1' \\<Gamma> m\"\n               using Q_m div_catch_nest[of m \\<Gamma> \"(Q, t) # cfg1\"] Q' by blast\n               have fst:\"fst (last ((Q', Normal s'') # xsa)) = LanguageCon.com.Throw\" \n                 using catch2_ass Cons Q' by (simp add: last_length  t_eq_s)\n              have cfg:\"cfg1 = map (lift_catch P1) xsa @ (P1, snd (last ((Q', Normal s'') # xsa))) # ys\"\n                 using catch2_ass Cons Q' by (simp add: last_length  t_eq_s)\n              have snd:\"snd (last ((Q', Normal s'') # xsa)) = Normal s'\"\n                using catch2_ass Cons Q' by (simp add: last_length  t_eq_s)\n               then have \"xsa=xsa'\" \n                 using catch2_ass Catch_P_Ends_Normal[OF cfg fst snd catch_cond] Cons\n                 by auto \n               then have False using min_call p0_cptn ass unfolding min_call_def by auto \n             } \n           } then show ?thesis by auto qed\n         ultimately show ?thesis unfolding min_call_def by auto\n       qed    \n     qed\n    }note l=this\n    {assume ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \\<and>\n             (\\<exists>ys. (n, \\<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n             (Q, t) # cfg1 = map (lift_catch P1) xs @ (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys)\"\n     have ?thesis\n     proof (cases \"\\<Gamma>\\<turnstile>\\<^sub>c(Catch P0 P1, s) \\<rightarrow> (Q,t)\")\n       case True \n       thus  ?thesis\n       proof (cases xs)\n          case Nil thus ?thesis using Catch ass by fastforce\n       next\n         case (Cons xa xsa)\n         then obtain ys where \n           catch2_ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \\<and>\n             (n, \\<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n             (Q, t) # cfg1 = map (lift_catch P1) xs @ (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys\"\n            using ass by auto \n         then have t_eq:\"t=s\" using Catch by fastforce\n         obtain mq mp1 where \n           min_call_q:\"min_call mq \\<Gamma> ((P0, s) # xs)\" and\n           min_call_p1:\"min_call mp1 \\<Gamma> ((Skip, snd (((P0, s) # xs) ! length xs)) # ys)\"         \n         using catch2_ass minimum_nest_call p0_cptn by (metis last_length)\n         then have mp1_zero:\"mp1=0\" by (simp add: skip_min_nested_call_0)\n         then have min_call: \"min_call n \\<Gamma> ((P0, s) # xs)\"  \n           using catch2_ass min_call_catch2[of n \\<Gamma> P0 P1 s \"(Q, t) # cfg1\" xs ys]\n             Catch(3,4) p0_cptn by (metis last_length)      \n         have n_z:\"n>0\" using redex_call_cptn_mod_min_nest_call_gr_zero[OF Catch(3) Catch(4) Catch(5) True]\n           by auto          \n         from catch2_ass obtain Q' where Q':\"Q=Catch Q' P1 \\<and> xa=(Q',t)\"          \n           unfolding lift_catch_def using Cons\n          proof -\n            assume a1: \"\\<And>Q'. Q = Catch Q' P1 \\<and> xa = (Q', t) \\<Longrightarrow> thesis\"\n            have \"(Catch (fst xa) P1, snd xa) = ((Q, t) # cfg1) ! 0\"\n             using catch2_ass unfolding lift_catch_def\n              by (simp add: Cons case_prod_unfold)\n            then show ?thesis\n              using a1 by fastforce\n          qed  \n         have big_call:\"biggest_nest_call P0 s ((Q',t)#xsa) \\<Gamma> n\"\n         proof-\n           have \"\\<not>(\\<exists>xs. min_call n \\<Gamma> ((P0, s)#xs) \\<and> (Q, t) # cfg1 = map (lift_catch P1) xs)\"\n             using min_call catch2_ass Cons\n           proof -\n             have \"min_call n \\<Gamma> ((Catch P0 P1, s) # (Q, t) # cfg1)\"\n               using Catch.prems(1) Catch.prems(2) by blast\n             then show ?thesis\n               by (metis (no_types) Catch_P_Not_finish append_Nil2 list.simps(3) \n                     same_append_eq catch catch2_ass)\n           qed\n           moreover have \"(\\<exists>xs ys. cond_catch_1 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys)\"\n             using catch2_ass p0_cptn unfolding cond_catch_1_def last_length\n             by metis\n           moreover have \"(SOME xs. \\<exists>ys. cond_catch_1 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys) = xs\"\n           proof -\n             let ?P = \"\\<lambda>xsa. \\<exists>ys. (n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call \\<and> \n                            fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \\<and>\n                             (n, \\<Gamma>, (LanguageCon.com.Skip, \n                                snd (last ((P0, s) # xsa))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                             (Q, t) # cfg1 = map (lift_catch P1) xsa @ \n                               (LanguageCon.com.Skip, snd (last ((P0, s) # xsa))) # ys\"\n             have \"\\<And>xsa. \\<exists>ys. (n, \\<Gamma>,(P0, s)#xsa) \\<in> cptn_mod_nest_call \\<and> \n                             fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \\<and>\n                             (n, \\<Gamma>, (LanguageCon.com.Skip, \n                                snd (last ((P0, s) # xsa))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                             (Q, t) # cfg1 = map (lift_catch P1) xsa @ \n                               (LanguageCon.com.Skip, snd (last ((P0, s) # xsa))) # ys \\<Longrightarrow>\n                           xsa = xs\"\n             using Catch_P_Ends_Skip catch  catch2_ass map_lift_catch_some_eq by fastforce  \n             moreover have \"\\<exists>ys. (n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call \\<and>\n                               fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \\<and>\n                             (n, \\<Gamma>, (LanguageCon.com.Skip, \n                                snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                             (Q, t) # cfg1 = map (lift_catch P1) xs @ \n                               (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys\" \n               using ass p0_cptn by (simp add: last_length) \n             ultimately show ?thesis using some_equality[of ?P xs]\n                 unfolding cond_catch_1_def by blast \n           qed           \n           ultimately have \"biggest_nest_call P0 s xs \\<Gamma> n\"\n            using  Catch(6) \n                  biggest_nest_call.simps(2)[of P0 P1 s \"(Q, t) # cfg1\" \\<Gamma> n]\n            by presburger\n           then show ?thesis  using Cons Q' by auto\n         qed         \n         have min_call:\"min_call n \\<Gamma> ((Q',t)#xsa)\" \n           using Catch(1)[OF min_call _ _  big_call] Catch(5) Cons Q' by fastforce   \n         then have p1_n_cptn:\"(n, \\<Gamma>,  (Q, t) # cfg1) \\<in> cptn_mod_nest_call\"\n            using Catch.prems(1) Catch.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast   \n         also then have \"(\\<forall>m<n. (m, \\<Gamma>, (Q, t) # cfg1) \\<notin> cptn_mod_nest_call)\" \n          proof-\n           { fix m\n             assume ass:\"m<n\" \n             { assume Q_m:\"(m, \\<Gamma>, (Q, t) # cfg1) \\<in> cptn_mod_nest_call\" \n               then obtain xsa' s1 s1' where \n                  p0_cptn:\"(m, \\<Gamma>,(Q', t)#xsa') \\<in> cptn_mod_nest_call\"  and\n                  seq:\"catch_cond_nest cfg1 P1 xsa' Q' t s1 s1' \\<Gamma> m\"\n               using div_catch_nest[of m \\<Gamma> \"(Q, t) # cfg1\"] Q' t_eq by blast\n               then have \"xsa=xsa'\" \n                 using catch2_ass \n                 Catch_P_Ends_Skip[of cfg1 P1 xsa Q' t ys xsa' s1 s1']  \n                 Cons Q' Q_m \n                 by (simp add:  last_length)                 \n               then have False using min_call p0_cptn ass unfolding min_call_def by auto \n             } \n           } then show ?thesis by auto qed          \n         ultimately show ?thesis unfolding min_call_def by auto\n       qed\n     next\n       case False \n       then have env:\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch P0 P1, s) \\<rightarrow>\\<^sub>e (Q,t)\" using Catch\n         by (meson elim_cptn_mod_nest_step_c min_call_def)\n       moreover then have Q:\"Q=Catch P0 P1\" using env_c_c' by blast        \n       ultimately show ?thesis using Catch\n        proof -\n          obtain nn :: \"(('b, 'a, 'c,'d) LanguageCon.com \\<times> ('b, 'c) xstate) list \\<Rightarrow> ('a \\<Rightarrow> ('b, 'a, 'c,'d) LanguageCon.com option) \\<Rightarrow> nat \\<Rightarrow> nat\" where\n            f1: \"\\<forall>x0 x1 x2. (\\<exists>v3<x2. (v3, x1, x0) \\<in> cptn_mod_nest_call) = (nn x0 x1 x2 < x2 \\<and> (nn x0 x1 x2, x1, x0) \\<in> cptn_mod_nest_call)\"\n            by moura\n          have f2: \"(n, \\<Gamma>, (LanguageCon.com.Catch P0 P1, s) # (Q, t) # cfg1) \\<in> cptn_mod_nest_call \\<and> (\\<forall>n. \\<not> n < n \\<or> (n, \\<Gamma>, (LanguageCon.com.Catch P0 P1, s) # (Q, t) # cfg1) \\<notin> cptn_mod_nest_call)\"\n            using local.Catch(3) local.Catch(4) min_call_def by blast\n          then have \"\\<not> nn ((Q, t) # cfg1) \\<Gamma> n < n \\<or> (nn ((Q, t) # cfg1) \\<Gamma> n, \\<Gamma>, (Q, t) # cfg1) \\<notin> cptn_mod_nest_call\"\n            using False env env_c_c'  not_func_redex_cptn_mod_nest_n_env \n            by (metis Catch.prems(1) Catch.prems(2) min_call_def)\n          then show ?thesis\n            using f2 f1 by (meson elim_cptn_mod_nest_call_n min_call_def)\n        qed\n     qed   \n    }\n    thus ?thesis using l ass by fastforce\n  qed   \nqed (fastforce)+\n*)\n\nlemma cptn_mod_nest_n_1:\n  assumes a0:\"(n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call\" and\n          a1:\"cfs=(p,s)#cfs'\" and\n          a2:\"\\<not> (min_call n \\<Gamma> cfs)\"\n  shows \"(n-1,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call\"\nusing a0 a1 a2 \nby (metis (no_types, lifting) Suc_diff_1 Suc_leI cptn_mod_nest_mono less_nat_zero_code min_call_def not_less)\n\nlemma cptn_mod_nest_tl_n_1:\n  assumes a0:\"(n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call\" and\n          a1:\"cfs=(p,s)#(q,t)#cfs'\" and\n          a2:\"\\<not> (min_call n \\<Gamma> cfs)\"\n  shows \"(n-1,\\<Gamma>,(q,t)#cfs') \\<in>  cptn_mod_nest_call\"\n  using a0 a1 a2\nby (meson elim_cptn_mod_nest_call_n cptn_mod_nest_n_1) \n\nlemma cptn_mod_nest_tl_not_min:\n  assumes a0:\"(n,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" and\n          a1:\"cfg=(p,s)#cfg'\" and\n          a2:\"\\<not> (min_call n \\<Gamma> cfg)\"\n  shows \"\\<not> (min_call n \\<Gamma> cfg')\"\nproof (cases cfg')\n  case Nil \n  have \"(\\<Gamma>, []) \\<notin> cptn\"\n    using cptn.simps by blast\n  then show ?thesis unfolding min_call_def\n    using cptn_eq_cptn_mod_set cptn_mod_nest_cptn_mod local.Nil by blast  \nnext\n  case (Cons xa cfga)\n  then obtain q t where \"xa = (q,t)\" \n  using prod.exhaust_sel by blast\n  then have \"(n-1,\\<Gamma>,cfg') \\<in>  cptn_mod_nest_call\"\n    using a0 a1 a2 cptn_mod_nest_tl_n_1 Cons by blast\n  also then have \"(n,\\<Gamma>,cfg') \\<in>  cptn_mod_nest_call\"\n    using cptn_mod_nest_mono Nat.diff_le_self by blast\n  ultimately show ?thesis unfolding min_call_def\n    using a0 a2 min_call_def by force \nqed\n\ndefinition cp :: \"('g\\<times>'l,'p,'f,'e) body \\<Rightarrow> ('g\\<times>'l,'p,'f,'e)com  \\<Rightarrow>\n                  ('g\\<times>'l)\\<times>('l list)  \\<Rightarrow> (('g,'l,'p,'f,'e) confs) set\" where\n  \"cp \\<Gamma> P s \\<equiv> {(\\<Gamma>1,l). l!0=(P,s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>1=\\<Gamma>}\"  \n\n \n\nlemma cp_sub: \n  assumes a0: \"(\\<Gamma>,(x#l0)@l1) \\<in> cp \\<Gamma> P s\"\n  shows \"(\\<Gamma>,(x#l0)) \\<in> cp \\<Gamma> P s\"\nproof -\n  have \"(x#l0)!0 = (P,s)\" using a0 unfolding cp_def by auto\n  also have \"(\\<Gamma>,(x#l0))\\<in>cptn\" using a0 unfolding cp_def\n  using cptn_dest_2 by fastforce\n  ultimately show ?thesis using a0 unfolding cp_def by blast\nqed\n\n\ndefinition cpn :: \"nat \\<Rightarrow> ('g\\<times>'l,'p,'f,'e) body \\<Rightarrow> ('g\\<times>'l,'p,'f,'e)com  \\<Rightarrow> \n                  ('g\\<times>'l)\\<times>('l list) \\<Rightarrow> (('g,'l,'p,'f,'e) confs) set\" \nwhere\n \"cpn n \\<Gamma> P s \\<equiv> {(\\<Gamma>1,l). l!0=(P,s) \\<and> (n,\\<Gamma>,l) \\<in> cptn_mod_nest_call \\<and> \\<Gamma>1=\\<Gamma>}\"\n\n\nend\n", "meta": {"author": "CompSoftVer", "repo": "CSim2", "sha": "b09a4d77ea089168b1805db5204ac151df2b9eff", "save_path": "github-repos/isabelle/CompSoftVer-CSim2", "path": "github-repos/isabelle/CompSoftVer-CSim2/CSim2-b09a4d77ea089168b1805db5204ac151df2b9eff/ConCSimpl/ComputationCon.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6187804337438501, "lm_q2_score": 0.476579651063676, "lm_q1q2_score": 0.2948981631986741}}
{"text": "section \\<open>Generation of Verification Conditions\\<close>\n\ntheory OG_Tactics\nimports OG_Hoare\nbegin\n\nlemmas ann_hoare_intros=AnnBasic AnnSeq AnnCond1 AnnCond2 AnnWhile AnnAwait AnnConseq\nlemmas oghoare_intros=Parallel Basic Seq Cond While Conseq\n\nlemma ParallelConseqRule:\n \"\\<lbrakk> p \\<subseteq> (\\<Inter>i\\<in>{i. i<length Ts}. pre(the(com(Ts ! i))));\n  \\<parallel>- (\\<Inter>i\\<in>{i. i<length Ts}. pre(the(com(Ts ! i))))\n      (Parallel Ts)\n     (\\<Inter>i\\<in>{i. i<length Ts}. post(Ts ! i));\n  (\\<Inter>i\\<in>{i. i<length Ts}. post(Ts ! i)) \\<subseteq> q \\<rbrakk>\n  \\<Longrightarrow> \\<parallel>- p (Parallel Ts) q\"\napply (rule Conseq)\nprefer 2\n apply fast\napply assumption+\ndone\n\nlemma SkipRule: \"p \\<subseteq> q \\<Longrightarrow> \\<parallel>- p (Basic id) q\"\napply(rule oghoare_intros)\n  prefer 2 apply(rule Basic)\n prefer 2 apply(rule subset_refl)\napply(simp add:Id_def)\ndone\n\nlemma BasicRule: \"p \\<subseteq> {s. (f s)\\<in>q} \\<Longrightarrow> \\<parallel>- p (Basic f) q\"\napply(rule oghoare_intros)\n  prefer 2 apply(rule oghoare_intros)\n prefer 2 apply(rule subset_refl)\napply assumption\ndone\n\nlemma SeqRule: \"\\<lbrakk> \\<parallel>- p c1 r; \\<parallel>- r c2 q \\<rbrakk> \\<Longrightarrow> \\<parallel>- p (Seq c1 c2) q\"\napply(rule Seq)\napply fast+\ndone\n\nlemma CondRule:\n \"\\<lbrakk> p \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>w) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>w')}; \\<parallel>- w c1 q; \\<parallel>- w' c2 q \\<rbrakk>\n  \\<Longrightarrow> \\<parallel>- p (Cond b c1 c2) q\"\napply(rule Cond)\n apply(rule Conseq)\n prefer 4 apply(rule Conseq)\napply simp_all\napply force+\ndone\n\nlemma WhileRule: \"\\<lbrakk> p \\<subseteq> i; \\<parallel>- (i \\<inter> b) c i ; (i \\<inter> (-b)) \\<subseteq> q \\<rbrakk>\n        \\<Longrightarrow> \\<parallel>- p (While b i c) q\"\napply(rule Conseq)\n prefer 2 apply(rule While)\napply assumption+\ndone\n\ntext \\<open>Three new proof rules for special instances of the \\<open>AnnBasic\\<close> and the \\<open>AnnAwait\\<close> commands when the transformation\nperformed on the state is the identity, and for an \\<open>AnnAwait\\<close>\ncommand where the boolean condition is \\<open>{s. True}\\<close>:\\<close>\n\nlemma AnnatomRule:\n  \"\\<lbrakk> atom_com(c); \\<parallel>- r c q \\<rbrakk>  \\<Longrightarrow> \\<turnstile> (AnnAwait r {s. True} c) q\"\napply(rule AnnAwait)\napply simp_all\ndone\n\nlemma AnnskipRule:\n  \"r \\<subseteq> q \\<Longrightarrow> \\<turnstile> (AnnBasic r id) q\"\napply(rule AnnBasic)\napply simp\ndone\n\nlemma AnnwaitRule:\n  \"\\<lbrakk> (r \\<inter> b) \\<subseteq> q \\<rbrakk> \\<Longrightarrow> \\<turnstile> (AnnAwait r b (Basic id)) q\"\napply(rule AnnAwait)\n apply simp\napply(rule BasicRule)\napply simp\ndone\n\ntext \\<open>Lemmata to avoid using the definition of \\<open>map_ann_hoare\\<close>, \\<open>interfree_aux\\<close>, \\<open>interfree_swap\\<close> and\n\\<open>interfree\\<close> by splitting it into different cases:\\<close>\n\nlemma interfree_aux_rule1: \"interfree_aux(co, q, None)\"\nby(simp add:interfree_aux_def)\n\nlemma interfree_aux_rule2:\n  \"\\<forall>(R,r)\\<in>(atomics a). \\<parallel>- (q \\<inter> R) r q \\<Longrightarrow> interfree_aux(None, q, Some a)\"\napply(simp add:interfree_aux_def)\napply(force elim:oghoare_sound)\ndone\n\nlemma interfree_aux_rule3:\n  \"(\\<forall>(R, r)\\<in>(atomics a). \\<parallel>- (q \\<inter> R) r q \\<and> (\\<forall>p\\<in>(assertions c). \\<parallel>- (p \\<inter> R) r p))\n  \\<Longrightarrow> interfree_aux(Some c, q, Some a)\"\napply(simp add:interfree_aux_def)\napply(force elim:oghoare_sound)\ndone\n\nlemma AnnBasic_assertions:\n  \"\\<lbrakk>interfree_aux(None, r, Some a); interfree_aux(None, q, Some a)\\<rbrakk> \\<Longrightarrow>\n    interfree_aux(Some (AnnBasic r f), q, Some a)\"\napply(simp add: interfree_aux_def)\nby force\n\nlemma AnnSeq_assertions:\n  \"\\<lbrakk> interfree_aux(Some c1, q, Some a); interfree_aux(Some c2, q, Some a)\\<rbrakk>\\<Longrightarrow>\n   interfree_aux(Some (AnnSeq c1 c2), q, Some a)\"\napply(simp add: interfree_aux_def)\nby force\n\nlemma AnnCond1_assertions:\n  \"\\<lbrakk> interfree_aux(None, r, Some a); interfree_aux(Some c1, q, Some a);\n  interfree_aux(Some c2, q, Some a)\\<rbrakk>\\<Longrightarrow>\n  interfree_aux(Some(AnnCond1 r b c1 c2), q, Some a)\"\napply(simp add: interfree_aux_def)\nby force\n\nlemma AnnCond2_assertions:\n  \"\\<lbrakk> interfree_aux(None, r, Some a); interfree_aux(Some c, q, Some a)\\<rbrakk>\\<Longrightarrow>\n  interfree_aux(Some (AnnCond2 r b c), q, Some a)\"\napply(simp add: interfree_aux_def)\nby force\n\nlemma AnnWhile_assertions:\n  \"\\<lbrakk> interfree_aux(None, r, Some a); interfree_aux(None, i, Some a);\n  interfree_aux(Some c, q, Some a)\\<rbrakk>\\<Longrightarrow>\n  interfree_aux(Some (AnnWhile r b i c), q, Some a)\"\napply(simp add: interfree_aux_def)\nby force\n\nlemma AnnAwait_assertions:\n  \"\\<lbrakk> interfree_aux(None, r, Some a); interfree_aux(None, q, Some a)\\<rbrakk>\\<Longrightarrow>\n  interfree_aux(Some (AnnAwait r b c), q, Some a)\"\napply(simp add: interfree_aux_def)\nby force\n\nlemma AnnBasic_atomics:\n  \"\\<parallel>- (q \\<inter> r) (Basic f) q \\<Longrightarrow> interfree_aux(None, q, Some (AnnBasic r f))\"\nby(simp add: interfree_aux_def oghoare_sound)\n\nlemma AnnSeq_atomics:\n  \"\\<lbrakk> interfree_aux(Any, q, Some a1); interfree_aux(Any, q, Some a2)\\<rbrakk>\\<Longrightarrow>\n  interfree_aux(Any, q, Some (AnnSeq a1 a2))\"\napply(simp add: interfree_aux_def)\nby force\n\nlemma AnnCond1_atomics:\n  \"\\<lbrakk> interfree_aux(Any, q, Some a1); interfree_aux(Any, q, Some a2)\\<rbrakk>\\<Longrightarrow>\n   interfree_aux(Any, q, Some (AnnCond1 r b a1 a2))\"\napply(simp add: interfree_aux_def)\nby force\n\nlemma AnnCond2_atomics:\n  \"interfree_aux (Any, q, Some a)\\<Longrightarrow> interfree_aux(Any, q, Some (AnnCond2 r b a))\"\nby(simp add: interfree_aux_def)\n\nlemma AnnWhile_atomics: \"interfree_aux (Any, q, Some a)\n     \\<Longrightarrow> interfree_aux(Any, q, Some (AnnWhile r b i a))\"\nby(simp add: interfree_aux_def)\n\nlemma Annatom_atomics:\n  \"\\<parallel>- (q \\<inter> r) a q \\<Longrightarrow> interfree_aux (None, q, Some (AnnAwait r {x. True} a))\"\nby(simp add: interfree_aux_def oghoare_sound)\n\nlemma AnnAwait_atomics:\n  \"\\<parallel>- (q \\<inter> (r \\<inter> b)) a q \\<Longrightarrow> interfree_aux (None, q, Some (AnnAwait r b a))\"\nby(simp add: interfree_aux_def oghoare_sound)\n\ndefinition interfree_swap :: \"('a ann_triple_op * ('a ann_triple_op) list) \\<Rightarrow> bool\" where\n  \"interfree_swap == \\<lambda>(x, xs). \\<forall>y\\<in>set xs. interfree_aux (com x, post x, com y)\n  \\<and> interfree_aux(com y, post y, com x)\"\n\nlemma interfree_swap_Empty: \"interfree_swap (x, [])\"\nby(simp add:interfree_swap_def)\n\nlemma interfree_swap_List:\n  \"\\<lbrakk> interfree_aux (com x, post x, com y);\n  interfree_aux (com y, post y ,com x); interfree_swap (x, xs) \\<rbrakk>\n  \\<Longrightarrow> interfree_swap (x, y#xs)\"\nby(simp add:interfree_swap_def)\n\nlemma interfree_swap_Map: \"\\<forall>k. i\\<le>k \\<and> k<j \\<longrightarrow> interfree_aux (com x, post x, c k)\n \\<and> interfree_aux (c k, Q k, com x)\n \\<Longrightarrow> interfree_swap (x, map (\\<lambda>k. (c k, Q k)) [i..<j])\"\nby(force simp add: interfree_swap_def less_diff_conv)\n\nlemma interfree_Empty: \"interfree []\"\nby(simp add:interfree_def)\n\nlemma interfree_List:\n  \"\\<lbrakk> interfree_swap(x, xs); interfree xs \\<rbrakk> \\<Longrightarrow> interfree (x#xs)\"\napply(simp add:interfree_def interfree_swap_def)\napply clarify\napply(case_tac i)\n apply(case_tac j)\n  apply simp_all\napply(case_tac j,simp+)\ndone\n\nlemma interfree_Map:\n  \"(\\<forall>i j. a\\<le>i \\<and> i<b \\<and> a\\<le>j \\<and> j<b  \\<and> i\\<noteq>j \\<longrightarrow> interfree_aux (c i, Q i, c j))\n  \\<Longrightarrow> interfree (map (\\<lambda>k. (c k, Q k)) [a..<b])\"\nby(force simp add: interfree_def less_diff_conv)\n\ndefinition map_ann_hoare :: \"(('a ann_com_op * 'a assn) list) \\<Rightarrow> bool \" (\"[\\<turnstile>] _\" [0] 45) where\n  \"[\\<turnstile>] Ts == (\\<forall>i<length Ts. \\<exists>c q. Ts!i=(Some c, q) \\<and> \\<turnstile> c q)\"\n\nlemma MapAnnEmpty: \"[\\<turnstile>] []\"\nby(simp add:map_ann_hoare_def)\n\nlemma MapAnnList: \"\\<lbrakk> \\<turnstile> c q ; [\\<turnstile>] xs \\<rbrakk> \\<Longrightarrow> [\\<turnstile>] (Some c,q)#xs\"\napply(simp add:map_ann_hoare_def)\napply clarify\napply(case_tac i,simp+)\ndone\n\nlemma MapAnnMap:\n  \"\\<forall>k. i\\<le>k \\<and> k<j \\<longrightarrow> \\<turnstile> (c k) (Q k) \\<Longrightarrow> [\\<turnstile>] map (\\<lambda>k. (Some (c k), Q k)) [i..<j]\"\napply(simp add: map_ann_hoare_def less_diff_conv)\ndone\n\nlemma ParallelRule:\"\\<lbrakk> [\\<turnstile>] Ts ; interfree Ts \\<rbrakk>\n  \\<Longrightarrow> \\<parallel>- (\\<Inter>i\\<in>{i. i<length Ts}. pre(the(com(Ts!i))))\n          Parallel Ts\n        (\\<Inter>i\\<in>{i. i<length Ts}. post(Ts!i))\"\napply(rule Parallel)\n apply(simp add:map_ann_hoare_def)\napply simp\ndone\n(*\nlemma ParamParallelRule:\n \"\\<lbrakk> \\<forall>k<n. \\<turnstile> (c k) (Q k);\n   \\<forall>k l. k<n \\<and> l<n  \\<and> k\\<noteq>l \\<longrightarrow> interfree_aux (Some(c k), Q k, Some(c l)) \\<rbrakk>\n  \\<Longrightarrow> \\<parallel>- (\\<Inter>i\\<in>{i. i<n} . pre(c i)) COBEGIN SCHEME [0\\<le>i<n] (c i) (Q i) COEND  (\\<Inter>i\\<in>{i. i<n} . Q i )\"\napply(rule ParallelConseqRule)\n  apply simp\n  apply clarify\n  apply force\n apply(rule ParallelRule)\n  apply(rule MapAnnMap)\n  apply simp\n apply(rule interfree_Map)\n apply simp\napply simp\napply clarify\napply force\ndone\n*)\n\ntext \\<open>The following are some useful lemmas and simplification\ntactics to control which theorems are used to simplify at each moment,\nso that the original input does not suffer any unexpected\ntransformation.\\<close>\n\nlemma Compl_Collect: \"-(Collect b) = {x. \\<not>(b x)}\"\n  by fast\n\nlemma list_length: \"length []=0\" \"length (x#xs) = Suc(length xs)\"\n  by simp_all\nlemma list_lemmas: \"length []=0\" \"length (x#xs) = Suc(length xs)\"\n    \"(x#xs) ! 0 = x\" \"(x#xs) ! Suc n = xs ! n\"\n  by simp_all\nlemma le_Suc_eq_insert: \"{i. i <Suc n} = insert n {i. i< n}\"\n  by auto\nlemmas primrecdef_list = \"pre.simps\" \"assertions.simps\" \"atomics.simps\" \"atom_com.simps\"\nlemmas my_simp_list = list_lemmas fst_conv snd_conv\nnot_less0 refl le_Suc_eq_insert Suc_not_Zero Zero_not_Suc nat.inject\nCollect_mem_eq ball_simps option.simps primrecdef_list\nlemmas ParallelConseq_list = INTER_eq Collect_conj_eq length_map length_upt length_append\n\nML \\<open>\nfun before_interfree_simp_tac ctxt =\n  simp_tac (put_simpset HOL_basic_ss ctxt addsimps [@{thm com.simps}, @{thm post.simps}])\n\nfun interfree_simp_tac ctxt =\n  asm_simp_tac (put_simpset HOL_ss ctxt\n    addsimps [@{thm split}, @{thm ball_Un}, @{thm ball_empty}] @ @{thms my_simp_list})\n\nfun ParallelConseq ctxt =\n  simp_tac (put_simpset HOL_basic_ss ctxt\n    addsimps @{thms ParallelConseq_list} @ @{thms my_simp_list})\n\\<close>\n\ntext \\<open>The following tactic applies \\<open>tac\\<close> to each conjunct in a\nsubgoal of the form \\<open>A \\<Longrightarrow> a1 \\<and> a2 \\<and> .. \\<and> an\\<close>  returning\n\\<open>n\\<close> subgoals, one for each conjunct:\\<close>\n\nML \\<open>\nfun conjI_Tac ctxt tac i st = st |>\n       ( (EVERY [resolve_tac ctxt [conjI] i,\n          conjI_Tac ctxt tac (i+1),\n          tac i]) ORELSE (tac i) )\n\\<close>\n\n\nsubsubsection \\<open>Tactic for the generation of the verification conditions\\<close>\n\ntext \\<open>The tactic basically uses two subtactics:\n\n\\begin{description}\n\n\\item[HoareRuleTac] is called at the level of parallel programs, it\n uses the ParallelTac to solve parallel composition of programs.\n This verification has two parts, namely, (1) all component programs are\n correct and (2) they are interference free.  \\<open>HoareRuleTac\\<close> is\n also called at the level of atomic regions, i.e.  \\<open>\\<langle> \\<rangle>\\<close> and\n \\<open>AWAIT b THEN _ END\\<close>, and at each interference freedom test.\n\n\\item[AnnHoareRuleTac] is for component programs which\n are annotated programs and so, there are not unknown assertions\n (no need to use the parameter precond, see NOTE).\n\n NOTE: precond(::bool) informs if the subgoal has the form \\<open>\\<parallel>- ?p c q\\<close>,\n in this case we have precond=False and the generated  verification\n condition would have the form \\<open>?p \\<subseteq> \\<dots>\\<close> which can be solved by\n \\<open>rtac subset_refl\\<close>, if True we proceed to simplify it using\n the simplification tactics above.\n\n\\end{description}\n\\<close>\n\nML \\<open>\n\nfun WlpTac ctxt i = resolve_tac ctxt @{thms SeqRule} i THEN HoareRuleTac ctxt false (i + 1)\nand HoareRuleTac ctxt precond i st = st |>\n    ( (WlpTac ctxt i THEN HoareRuleTac ctxt precond i)\n      ORELSE\n      (FIRST[resolve_tac ctxt @{thms SkipRule} i,\n             resolve_tac ctxt @{thms BasicRule} i,\n             EVERY[resolve_tac ctxt @{thms ParallelConseqRule} i,\n                   ParallelConseq ctxt (i+2),\n                   ParallelTac ctxt (i+1),\n                   ParallelConseq ctxt i],\n             EVERY[resolve_tac ctxt @{thms CondRule} i,\n                   HoareRuleTac ctxt false (i+2),\n                   HoareRuleTac ctxt false (i+1)],\n             EVERY[resolve_tac ctxt @{thms WhileRule} i,\n                   HoareRuleTac ctxt true (i+1)],\n             K all_tac i ]\n       THEN (if precond then (K all_tac i) else resolve_tac ctxt @{thms subset_refl} i)))\n\nand AnnWlpTac ctxt i = resolve_tac ctxt @{thms AnnSeq} i THEN AnnHoareRuleTac ctxt (i + 1)\nand AnnHoareRuleTac ctxt i st = st |>\n    ( (AnnWlpTac ctxt i THEN AnnHoareRuleTac ctxt i )\n     ORELSE\n      (FIRST[(resolve_tac ctxt @{thms AnnskipRule} i),\n             EVERY[resolve_tac ctxt @{thms AnnatomRule} i,\n                   HoareRuleTac ctxt true (i+1)],\n             (resolve_tac ctxt @{thms AnnwaitRule} i),\n             resolve_tac ctxt @{thms AnnBasic} i,\n             EVERY[resolve_tac ctxt @{thms AnnCond1} i,\n                   AnnHoareRuleTac ctxt (i+3),\n                   AnnHoareRuleTac ctxt (i+1)],\n             EVERY[resolve_tac ctxt @{thms AnnCond2} i,\n                   AnnHoareRuleTac ctxt (i+1)],\n             EVERY[resolve_tac ctxt @{thms AnnWhile} i,\n                   AnnHoareRuleTac ctxt (i+2)],\n             EVERY[resolve_tac ctxt @{thms AnnAwait} i,\n                   HoareRuleTac ctxt true (i+1)],\n             K all_tac i]))\n\nand ParallelTac ctxt i = EVERY[resolve_tac ctxt @{thms ParallelRule} i,\n                          interfree_Tac ctxt (i+1),\n                           MapAnn_Tac ctxt i]\n\nand MapAnn_Tac ctxt i st = st |>\n    (FIRST[resolve_tac ctxt @{thms MapAnnEmpty} i,\n           EVERY[resolve_tac ctxt @{thms MapAnnList} i,\n                 MapAnn_Tac ctxt (i+1),\n                 AnnHoareRuleTac ctxt i],\n           EVERY[resolve_tac ctxt @{thms MapAnnMap} i,\n                 resolve_tac ctxt @{thms allI} i,\n                 resolve_tac ctxt @{thms impI} i,\n                 AnnHoareRuleTac ctxt i]])\n\nand interfree_swap_Tac ctxt i st = st |>\n    (FIRST[resolve_tac ctxt @{thms interfree_swap_Empty} i,\n           EVERY[resolve_tac ctxt @{thms interfree_swap_List} i,\n                 interfree_swap_Tac ctxt (i+2),\n                 interfree_aux_Tac ctxt (i+1),\n                 interfree_aux_Tac ctxt i ],\n           EVERY[resolve_tac ctxt @{thms interfree_swap_Map} i,\n                 resolve_tac ctxt @{thms allI} i,\n                 resolve_tac ctxt @{thms impI} i,\n                 conjI_Tac ctxt (interfree_aux_Tac ctxt) i]])\n\nand interfree_Tac ctxt i st = st |>\n   (FIRST[resolve_tac ctxt @{thms interfree_Empty} i,\n          EVERY[resolve_tac ctxt @{thms interfree_List} i,\n                interfree_Tac ctxt (i+1),\n                interfree_swap_Tac ctxt i],\n          EVERY[resolve_tac ctxt @{thms interfree_Map} i,\n                resolve_tac ctxt @{thms allI} i,\n                resolve_tac ctxt @{thms allI} i,\n                resolve_tac ctxt @{thms impI} i,\n                interfree_aux_Tac ctxt i ]])\n\nand interfree_aux_Tac ctxt i = (before_interfree_simp_tac ctxt i ) THEN\n        (FIRST[resolve_tac ctxt @{thms interfree_aux_rule1} i,\n               dest_assertions_Tac ctxt i])\n\nand dest_assertions_Tac ctxt i st = st |>\n    (FIRST[EVERY[resolve_tac ctxt @{thms AnnBasic_assertions} i,\n                 dest_atomics_Tac ctxt (i+1),\n                 dest_atomics_Tac ctxt i],\n           EVERY[resolve_tac ctxt @{thms AnnSeq_assertions} i,\n                 dest_assertions_Tac ctxt (i+1),\n                 dest_assertions_Tac ctxt i],\n           EVERY[resolve_tac ctxt @{thms AnnCond1_assertions} i,\n                 dest_assertions_Tac ctxt (i+2),\n                 dest_assertions_Tac ctxt (i+1),\n                 dest_atomics_Tac ctxt i],\n           EVERY[resolve_tac ctxt @{thms AnnCond2_assertions} i,\n                 dest_assertions_Tac ctxt (i+1),\n                 dest_atomics_Tac ctxt i],\n           EVERY[resolve_tac ctxt @{thms AnnWhile_assertions} i,\n                 dest_assertions_Tac ctxt (i+2),\n                 dest_atomics_Tac ctxt (i+1),\n                 dest_atomics_Tac ctxt i],\n           EVERY[resolve_tac ctxt @{thms AnnAwait_assertions} i,\n                 dest_atomics_Tac ctxt (i+1),\n                 dest_atomics_Tac ctxt i],\n           dest_atomics_Tac ctxt i])\n\nand dest_atomics_Tac ctxt i st = st |>\n    (FIRST[EVERY[resolve_tac ctxt @{thms AnnBasic_atomics} i,\n                 HoareRuleTac ctxt true i],\n           EVERY[resolve_tac ctxt @{thms AnnSeq_atomics} i,\n                 dest_atomics_Tac ctxt (i+1),\n                 dest_atomics_Tac ctxt i],\n           EVERY[resolve_tac ctxt @{thms AnnCond1_atomics} i,\n                 dest_atomics_Tac ctxt (i+1),\n                 dest_atomics_Tac ctxt i],\n           EVERY[resolve_tac ctxt @{thms AnnCond2_atomics} i,\n                 dest_atomics_Tac ctxt i],\n           EVERY[resolve_tac ctxt @{thms AnnWhile_atomics} i,\n                 dest_atomics_Tac ctxt i],\n           EVERY[resolve_tac ctxt @{thms Annatom_atomics} i,\n                 HoareRuleTac ctxt true i],\n           EVERY[resolve_tac ctxt @{thms AnnAwait_atomics} i,\n                 HoareRuleTac ctxt true i],\n                 K all_tac i])\n\\<close>\n\n\ntext \\<open>The final tactic is given the name \\<open>oghoare\\<close>:\\<close>\n\nML \\<open>\nfun oghoare_tac ctxt = SUBGOAL (fn (_, i) => HoareRuleTac ctxt true i)\n\\<close>\n\ntext \\<open>Notice that the tactic for parallel programs \\<open>oghoare_tac\\<close> is initially invoked with the value \\<open>true\\<close> for\nthe parameter \\<open>precond\\<close>.\n\nParts of the tactic can be also individually used to generate the\nverification conditions for annotated sequential programs and to\ngenerate verification conditions out of interference freedom tests:\\<close>\n\nML \\<open>\nfun annhoare_tac ctxt = SUBGOAL (fn (_, i) => AnnHoareRuleTac ctxt i)\n\nfun interfree_aux_tac ctxt = SUBGOAL (fn (_, i) => interfree_aux_Tac ctxt i)\n\\<close>\n\ntext \\<open>The so defined ML tactics are then ``exported'' to be used in\nIsabelle proofs.\\<close>\n\nmethod_setup oghoare = \\<open>\n  Scan.succeed (SIMPLE_METHOD' o oghoare_tac)\\<close>\n  \"verification condition generator for the oghoare logic\"\n\nmethod_setup annhoare = \\<open>\n  Scan.succeed (SIMPLE_METHOD' o annhoare_tac)\\<close>\n  \"verification condition generator for the ann_hoare logic\"\n\nmethod_setup interfree_aux = \\<open>\n  Scan.succeed (SIMPLE_METHOD' o interfree_aux_tac)\\<close>\n  \"verification condition generator for interference freedom tests\"\n\ntext \\<open>Tactics useful for dealing with the generated verification conditions:\\<close>\n\nmethod_setup conjI_tac = \\<open>\n  Scan.succeed (fn ctxt => SIMPLE_METHOD' (conjI_Tac ctxt (K all_tac)))\\<close>\n  \"verification condition generator for interference freedom tests\"\n\nML \\<open>\nfun disjE_Tac ctxt tac i st = st |>\n       ( (EVERY [eresolve_tac ctxt [disjE] i,\n          disjE_Tac ctxt tac (i+1),\n          tac i]) ORELSE (tac i) )\n\\<close>\n\nmethod_setup disjE_tac = \\<open>\n  Scan.succeed (fn ctxt => SIMPLE_METHOD' (disjE_Tac ctxt (K all_tac)))\\<close>\n  \"verification condition generator for interference freedom tests\"\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/Hoare_Parallel/OG_Tactics.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.585101139733739, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.29483607469542883}}
{"text": "theory IMP_Minus_Minus_Subprograms_Nat\n  imports Primitives IMP_Minus_Minus_Subprograms \nbegin \n\n\n\n\nfun map_all_subprograms:: \"nat \\<Rightarrow> nat \\<Rightarrow> nat\" where \n\"map_all_subprograms c n = (if n =0 then 0 else ( 2## (hd_nat n) ## c ## 0) ## map_all_subprograms c (tl_nat n) )\"\n\n\nlemma submap_all_subprograms:\n\"map_all_subprograms c n = map_nat (\\<lambda>x. 2## x ## c ## 0) n\"\n  apply (induct c n rule: map_all_subprograms.induct)\n  apply auto\n  done\n\nfun map_all_subprograms_acc:: \"nat \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> nat\" where \n\"map_all_subprograms_acc  c acc n = (if n =0 then acc else \nmap_all_subprograms_acc c (( 2## (hd_nat n) ## c ## 0) ## acc) (tl_nat n) )\"\n\nlemma  map_all_subprograms_induct:\n\" map_all_subprograms_acc c acc n = map_acc  (\\<lambda>x. 2## x ## c ## 0) acc n\"\n  apply(induct c acc n rule:map_all_subprograms_acc.induct)\n  apply auto\n  done\n\ndefinition map_all_subprograms_tail :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat\" where \n\"map_all_subprograms_tail c n = reverse_nat (map_all_subprograms_acc c 0 n)\"\n\nlemma subtail_map_all_subprograms:\n\"map_all_subprograms_tail c n = map_all_subprograms c n\"\n  using submap_all_subprograms map_all_subprograms_tail_def  map_all_subprograms_induct[of c 0 n]\n  subtail_map by presburger\n\ndatatype all_sub = Bot  \"com list\" |\n                   SKIP|\n                   Assign vname bit |\n                   Seq_0 com com|\n                   Seq_m com com \"com list\"|\n                   Seq_f com com \"com list\" \"com list\"|\n                   If_0 \"vname list\" com com |\n                   If_m  \"vname list\" com com \"com list\"|\n                   If_f  \"vname list\" com com \"com list\" \"com list\"|\n                   While_0  \"vname list\" com |\n                   While_f  \"vname list\" com \"com list\"\n\n\nfun all_sub_encode :: \"all_sub \\<Rightarrow> nat\" where \n\"all_sub_encode SKIP = list_encode [0] \"|\n\"all_sub_encode (Assign v b) = list_encode [1, vname_encode v, bit_encode b]\"|\n\"all_sub_encode (Seq_0 c1 c2) = list_encode[2 , comm_encode c1 , comm_encode c2]\"|\n\"all_sub_encode (If_0 v c1 c2) = list_encode [3, vname_list_encode v, comm_encode c1, comm_encode c2]\"|\n\"all_sub_encode (While_0 v c) = list_encode [4,vname_list_encode v, comm_encode c]\"|\n\"all_sub_encode (Seq_m  c1 c2 c3) = list_encode[5, comm_encode c1 ,comm_encode c2, list_encode (map comm_encode c3) ]\"|\n\"all_sub_encode (Seq_f c1 c2 c3 c4) = list_encode [6, comm_encode c1 ,comm_encode c2 , list_encode (map comm_encode c3) , list_encode (map comm_encode c4)]\"|\n\"all_sub_encode (If_m v c1 c2 c3) = list_encode[7, vname_list_encode v, comm_encode c1 ,comm_encode c2, list_encode (map comm_encode c3)]\"|\n\"all_sub_encode (If_f v c1 c2 c3 c4) = list_encode [8, vname_list_encode v, comm_encode c1, comm_encode c2, list_encode (map comm_encode c3), list_encode (map comm_encode c4)]\"|\n\"all_sub_encode (While_f v c c') = list_encode [9, vname_list_encode v, comm_encode c, list_encode (map comm_encode c')]\"|\n\"all_sub_encode (Bot x) = list_encode [10, list_encode (map comm_encode x)]\"\n\nfun push_stack :: \"com \\<Rightarrow> all_sub list \\<Rightarrow> all_sub list\" where \n\"push_stack com.SKIP s = SKIP#s \"|\n\"push_stack (com.Assign v b) s = Assign v b # s\"|\n\"push_stack (com.Seq c1 c2) s = Seq_0 c1 c2 # s\"|\n\"push_stack (com.If v c1 c2) s = If_0 v c1 c2 # s\"|\n\"push_stack (com.While v c) s = While_0 v c #s\"\n\nfun push_stack_nat :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat\" where \n\"push_stack_nat c s = (c ##s )\"\n\nlemma sub_push_stack:\n\"push_stack_nat (comm_encode c) (list_encode (map all_sub_encode s)) \n= list_encode (map all_sub_encode (push_stack c s))\"\n  apply( cases c)\n  apply (auto simp add: sub_cons simp del: list_encode.simps)\n  done\n\nlemma push_stack_not_Nil:\n\"push_stack c s \\<noteq> []\"\n  apply(cases c)\n      apply auto\n  done\n\n\n\nfun add_res :: \"com list \\<Rightarrow> all_sub list \\<Rightarrow> all_sub list\" where \n\"add_res c [] = [Bot c] \"|\n\"add_res c (Seq_0 c1 c2 # s) = Seq_m c1 c2 c #s \"|\n\"add_res c (Seq_m c1 c2 c3 # s) = Seq_f c1 c2 c3 c # s\"|\n\"add_res c (If_0 v c1 c2 # s) = If_m v c1 c2 c # s \"|\n\"add_res c (If_m v c1 c2 c3 #s) = If_f v c1 c2 c3 c # s\"|\n\"add_res c (While_0 v c'#s) = While_f v c' c # s\"|\n\"add_res c s = s\"\n\nlemma add_res_not_Nil:\n\"add_res c s \\<noteq> []\"\n  apply(cases s)\n   apply auto\n  subgoal for a xs\n    apply (cases a)\n    apply auto\n    done\n  done\n\nfun add_res_nat :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat\" where \n\"add_res_nat c s = (if s =0 then (10##c##0)##0 else \n(let h = hd_nat s; con = hd_nat h ; fs = nth_nat (Suc 0) h ; sn = nth_nat (Suc (Suc 0)) h;\n       th = nth_nat (Suc (Suc (Suc 0))) h; ft = nth_nat (Suc (Suc (Suc (Suc 0)))) h; t = tl_nat s in\n    if con = 2 then (5## fs ## sn ## c ## 0) ## t\nelse if con = 5 then(6 ## fs ## sn ## th ## c ## 0) ## t\nelse if con = 3 then (7 ## fs ## sn ## th ## c ## 0) ## t\nelse if con = 7 then (8 ## fs ## sn ## th ## ft ## c ## 0)## t\nelse if con = 4 then (9 ## fs ## sn ## c ## 0) ## t else s \n  ))\"\n\nlemma sub_add_res:\n\"add_res_nat (list_encode (map comm_encode c)) (list_encode  (map all_sub_encode s))\n= list_encode (map all_sub_encode (add_res c s))\"\n  apply (cases s)\n   apply (simp add: cons0 sub_cons  flip: list_encode.simps)\n  subgoal for a xs \n    apply(cases a)\n       apply (auto simp add:cons0 sub_cons list_encode_eq sub_hd sub_tl  simp flip: list_encode.simps)\n                   apply(auto simp add: Let_def sub_hd sub_tl simp flip: list_encode.simps(2)) \n    done\n  done\n\nfunction (sequential, domintros) all_subprograms_stack :: \"all_sub list \\<Rightarrow> com list\" where \n\"all_subprograms_stack (Bot x#s) = x\"|\n\"all_subprograms_stack (SKIP # s) = all_subprograms_stack (add_res  [com.SKIP] s )\"|\n\"all_subprograms_stack (Assign v b # s) = all_subprograms_stack (add_res [(com.Assign v b), com.SKIP] s )\"|\n\"all_subprograms_stack (Seq_0 c1 c2 # s) = all_subprograms_stack (push_stack c1 (Seq_0 c1 c2 # s) )\"|\n\"all_subprograms_stack (Seq_m c1 c2 c3 # s) = all_subprograms_stack (push_stack c2 (Seq_m c1 c2 c3 # s))\"|\n\"all_subprograms_stack (Seq_f c1 c2 c3 c4 #s) = all_subprograms_stack (add_res ((map (\\<lambda> c. c ;; c2) c3 ) @ c3 \n  @ c4) s) \"|\n\"all_subprograms_stack (If_0 v c1 c2 # s) = all_subprograms_stack (push_stack c1 (If_0 v c1 c2 # s))\"|\n\"all_subprograms_stack (If_m v c1 c2 c3 # s) = all_subprograms_stack (push_stack c2 (If_m v c1 c2 c3 # s)) \"|\n\"all_subprograms_stack (If_f v c1 c2 c3 c4 # s) = all_subprograms_stack (add_res (\n[(com.If v c1 c2)] @ c3 @ c4 ) s )\"|\n\"all_subprograms_stack (While_0 v c # s) = all_subprograms_stack (push_stack c (While_0 v c # s) )\"|\n\"all_subprograms_stack (While_f v c c' # s) = all_subprograms_stack (add_res ([(While v c), com.SKIP] @ c' @ \n  (map (\\<lambda> x. x ;; (While v c))  c')) s)\"\n  by pat_completeness auto\ntermination sorry \n\nfunction all_subprograms_stack_nat :: \"nat  \\<Rightarrow> nat\" where \n\"all_subprograms_stack_nat s = (let h = hd_nat s; con = hd_nat h ; fs = nth_nat (Suc 0) h ; sn = nth_nat (Suc (Suc 0)) h;\n       th = nth_nat (Suc (Suc (Suc 0))) h; ft = nth_nat (Suc (Suc (Suc (Suc 0)))) h; v = nth_nat (Suc (Suc (Suc (Suc (Suc 0))))) h;  t = tl_nat s in\nif con = 10 then  fs else \nif con = 0 then  all_subprograms_stack_nat (add_res_nat  ((0##0)##0) t ) else\nif con = 1 then  all_subprograms_stack_nat (add_res_nat   (h##(0##0)##0)  t ) else \nif con = 2 then all_subprograms_stack_nat (push_stack_nat fs s) else \nif con = 5 then all_subprograms_stack_nat (push_stack_nat sn s) else \nif con = 6 then all_subprograms_stack_nat (add_res_nat (append_nat ( append_nat (map_all_subprograms_tail sn th ) th \n  ) ft) t) else\nif con = 3 then all_subprograms_stack_nat (push_stack_nat sn s) else\nif con = 7 then all_subprograms_stack_nat (push_stack_nat th s) else\nif con = 8 then all_subprograms_stack_nat (add_res_nat (append_nat ((3##fs##sn##th##0)## ft )v) t) else\nif con = 4 then all_subprograms_stack_nat (push_stack_nat sn s) else\nall_subprograms_stack_nat (add_res_nat ((4##fs##sn##0) ## (0##0) ## append_nat th (map_all_subprograms_tail (4##fs##sn##0) th)) t)\n) \"\n  sorry\ntermination sorry \n\nlemma map_singleton:\n\"[f x] = map f [x]\" by auto\nlemma sub_all_programs_stack:\n\"s \\<noteq> [] \\<Longrightarrow> all_subprograms_stack_nat (list_encode (map all_sub_encode s))\n = list_encode (map comm_encode (all_subprograms_stack s))\"\n  apply (cases s)\n   apply simp\n  subgoal  for a xs\n    apply(induct s  arbitrary : a xs rule:all_subprograms_stack.induct)\n    using push_stack_not_Nil add_res_not_Nil   apply (auto simp only:)\n              apply (subst all_subprograms_stack_nat.simps)\n   apply (simp add: Let_def sub_nth sub_hd sub_cons\n              del: all_subprograms_stack_nat.simps \n                list_encode.simps nth_nat.simps add_res_nat.simps push_stack.simps )\n   apply (subst all_subprograms_stack_nat.simps)\n   apply (simp add: Let_def sub_nth sub_hd sub_cons sub_tl  cons0\n              del: all_subprograms_stack_nat.simps \n                list_encode.simps nth_nat.simps add_res_nat.simps push_stack.simps ) \n             apply(simp only:  add_res.simps sub_add_res map_singleton[of comm_encode]  flip: comm_encode.simps list.map )\n    apply (metis neq_Nil_conv)\n apply (subst all_subprograms_stack_nat.simps)\n   apply (simp add: Let_def sub_nth sub_hd sub_cons sub_tl  cons0\n              del: all_subprograms_stack_nat.simps \n                list_encode.simps nth_nat.simps add_res_nat.simps push_stack.simps ) \n             apply(simp only:  add_res.simps sub_add_res map_singleton[of comm_encode]  flip: One_nat_def comm_encode.simps list.map )\n    apply (metis neq_Nil_conv)\n     apply (subst all_subprograms_stack_nat.simps)\n   apply (simp add: Let_def sub_nth sub_hd sub_cons sub_tl  cons0\n              del: all_subprograms_stack_nat.simps \n                list_encode.simps nth_nat.simps add_res_nat.simps push_stack_nat.simps ) \n             apply(simp only:  sub_push_stack   flip: One_nat_def all_sub_encode.simps list.map )\n           apply (metis list.exhaust)\n  apply (subst all_subprograms_stack_nat.simps)\n   apply (simp add: Let_def sub_nth sub_hd sub_cons sub_tl  cons0\n              del: all_subprograms_stack_nat.simps \n                list_encode.simps nth_nat.simps add_res_nat.simps push_stack_nat.simps ) \n          apply(simp only:  sub_push_stack   flip: One_nat_def all_sub_encode.simps list.map )\n               apply (metis list.exhaust)\n apply (subst all_subprograms_stack_nat.simps)\n   apply (simp add: Let_def sub_nth sub_hd sub_cons sub_tl  cons0\n              del: all_subprograms_stack_nat.simps \n                list_encode.simps nth_nat.simps add_res_nat.simps push_stack_nat.simps ) \n         apply(simp only: subtail_map_all_subprograms submap_all_subprograms\n        sub_map sub_append map_map comp_def sub_cons cons0\n  add_res.simps sub_add_res  flip: One_nat_def comm_encode.simps list.map )\n    apply (simp only: sub_add_res flip: map_append comp_def[of comm_encode \"\\<lambda>x. (com.Seq x  _ )\"] map_map)\n         apply (metis append.assoc neq_Nil_conv)\n  apply (subst all_subprograms_stack_nat.simps)\n   apply (simp add: Let_def sub_nth sub_hd sub_cons sub_tl  cons0\n              del: all_subprograms_stack_nat.simps \n                list_encode.simps nth_nat.simps add_res_nat.simps push_stack_nat.simps ) \n          apply(simp only:  sub_push_stack   flip: One_nat_def all_sub_encode.simps list.map )\n        apply (metis list.exhaust)\n  apply (subst all_subprograms_stack_nat.simps)\n   apply (simp add: Let_def sub_nth sub_hd sub_cons sub_tl  cons0\n              del: all_subprograms_stack_nat.simps \n                list_encode.simps nth_nat.simps add_res_nat.simps push_stack_nat.simps ) \n          apply(simp only:  sub_push_stack   flip: One_nat_def all_sub_encode.simps list.map )\n       apply (metis list.exhaust)\n apply (subst all_subprograms_stack_nat.simps)\n   apply (simp add: Let_def sub_nth sub_hd sub_cons sub_tl  cons0\n              del: all_subprograms_stack_nat.simps \n                list_encode.simps nth_nat.simps add_res_nat.simps push_stack_nat.simps ) \n         apply(simp only: subtail_map_all_subprograms submap_all_subprograms\n        sub_map sub_append map_map comp_def sub_cons cons0\n  add_res.simps sub_add_res  flip: One_nat_def comm_encode.simps list.map map_append)\n      apply (metis append_Cons neq_Nil_conv)\n  apply (subst all_subprograms_stack_nat.simps)\n   apply (simp add: Let_def sub_nth sub_hd sub_cons sub_tl  cons0\n              del: all_subprograms_stack_nat.simps \n                list_encode.simps nth_nat.simps add_res_nat.simps push_stack_nat.simps ) \n          apply(simp only:  sub_push_stack   flip: One_nat_def all_sub_encode.simps list.map )\n     apply (metis list.exhaust)\n apply (subst all_subprograms_stack_nat.simps)\n   apply (simp add: Let_def sub_nth sub_hd sub_cons sub_tl  cons0\n              del: all_subprograms_stack_nat.simps \n                list_encode.simps nth_nat.simps add_res_nat.simps push_stack_nat.simps ) \n         apply(simp only: subtail_map_all_subprograms submap_all_subprograms\n        sub_map sub_append map_map comp_def sub_cons cons0\n  add_res.simps sub_add_res  flip: One_nat_def comm_encode.simps list.map map_append)\n    apply (simp only: sub_add_res flip: comp_def [of comm_encode \"\\<lambda>x. (com.Seq x  (com.While _ _))\" ]\n          map_map map_append list.map )\n    apply (metis list.exhaust)\n    done\n  done\n\nlemma all_subprograms_stack_correct:\n\"all_subprograms_stack (push_stack c s) = all_subprograms_stack (add_res (all_subprograms c) s)\"\n  apply (induct c arbitrary: s )\n      apply auto\n  done\n\ndefinition all_subprograms_t :: \"com \\<Rightarrow> com list\" where\n\"all_subprograms_t c = all_subprograms_stack (push_stack c [] )\"\n\ndefinition all_subprograms_nat :: \"nat \\<Rightarrow> nat\" where \n\"all_subprograms_nat c = all_subprograms_stack_nat (push_stack_nat c 0)\"\n\nlemma subtailnat_all_subprograms:\n\"all_subprograms_nat (comm_encode c) = list_encode (map comm_encode (all_subprograms_t c))\"\n  by (metis all_subprograms_nat_def all_subprograms_t_def list.simps(8) list_encode.simps(1)\n push_stack_not_Nil sub_all_programs_stack sub_push_stack)\n\nlemma sub_all_subprograms_t:\n\"all_subprograms_t c = all_subprograms c\"\n  by (simp add: all_subprograms_stack_correct all_subprograms_t_def)\n\nlemma sub_all_subprograms:\n \"all_subprograms_nat (comm_encode c) = list_encode(map comm_encode (all_subprograms c))\"\n  by (simp add: sub_all_subprograms_t subtailnat_all_subprograms)\n\ndefinition all_subprograms_tail :: \"nat \\<Rightarrow> nat\" where \n\"all_subprograms_tail c = all_subprograms_nat c\"\n\nlemma subtail_all_subprograms:\n\"all_subprograms_tail c = all_subprograms_nat c\"\n  by (simp add: all_subprograms_tail_def)\n\ndefinition enumerate_subprograms_nat :: \"nat \\<Rightarrow>nat\" where\n\"enumerate_subprograms_nat c = remdups_nat (all_subprograms_nat c)\"\n\ndefinition enumerate_subprograms_tail :: \"nat \\<Rightarrow>nat\" where\n\"enumerate_subprograms_tail c = remdups_tail (all_subprograms_tail c)\"\n\nlemma subtail_enumerate_subprograms:\n\"enumerate_subprograms_tail c = enumerate_subprograms_nat c\"\n  using all_subprograms_tail_def enumerate_subprograms_nat_def \nenumerate_subprograms_tail_def subtail_remdups by auto\n\nlemma sub_enumerate_subprograms:\n\"enumerate_subprograms_nat (comm_encode c) = list_encode (map comm_encode (enumerate_subprograms c))\"\n  using comm_inj\n  apply (auto simp only: enumerate_subprograms_nat_def enumerate_subprograms_def remdups_map sub_all_subprograms sub_remdups list_encode_eq)\n  done\n\nfun all_variables_nat :: \"nat \\<Rightarrow>nat\" where\n\"all_variables_nat n = (if n=0 \\<or> hd_nat n =0 \\<or> hd_nat n =2  then 0 else\nif hd_nat n = 1 then (nth_nat (Suc 0) n) ## 0 else\nnth_nat (Suc 0) n )\"\n\ndefinition all_variables_tail where \"all_variables_tail = all_variables_nat\"\n\nlemma subtail_all_variables : \"all_variables_tail = all_variables_nat\" using  all_variables_tail_def by meson\n\nlemma sub_all_variables: \"all_variables_nat (comm_encode c) = vname_list_encode (all_variables c)\"\n  apply (cases c)\n      apply (auto simp only:all_variables_nat.simps sub_hd comm_encode.simps head.simps \n              vname_list_encode_def cons0 sub_cons sub_nth nth.simps)\n      apply auto\n  done\n\nfun map_all_variables:: \"nat \\<Rightarrow> nat\" where \n\"map_all_variables n = (if n =0 then 0 else (all_variables_nat (hd_nat n)) ## map_all_variables (tl_nat n) )\"\n\nfun map_all_variables_acc :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat\" where \n\"map_all_variables_acc acc n = (if n =0 then acc else map_all_variables_acc ((all_variables_tail (hd_nat n)) ## acc) (tl_nat n) )\"\n\nlemma submap_all_variables:\n\"map_all_variables n = map_nat all_variables_nat n\"\n  apply (induct n rule:map_all_variables.induct)\n  apply auto\n  done\nlemma  map_all_variables_induct:\n\" map_all_variables_acc acc n = map_acc all_variables_nat acc n\"\n  apply(induct acc n rule: map_all_variables_acc.induct)\n  apply (auto simp add: subtail_all_variables )\n  done\n\ndefinition map_all_variables_tail :: \"nat \\<Rightarrow> nat\" where \n\" map_all_variables_tail n = reverse_nat (map_all_variables_acc 0 n)\"\n\nlemma subtail_map_all_variables:\n\" map_all_variables_tail n  =  map_all_variables n \"\n  using map_all_variables_tail_def  map_all_variables_induct[of 0 n]\n  submap_all_variables subtail_map by presburger\n\n\ndefinition enumerate_variables_nat :: \"nat \\<Rightarrow> nat\" where\n\"enumerate_variables_nat c =\n     remdups_nat (concat_nat (map_all_variables (enumerate_subprograms_nat c)))\"\n\ndefinition enumerate_variables_tail :: \"nat \\<Rightarrow> nat\" where\n\"enumerate_variables_tail c =\n     remdups_tail (concat_tail (map_all_variables_tail (enumerate_subprograms_tail c)))\"\n\n\nlemma subtail_enumerate_variables:\n\"enumerate_variables_tail c = enumerate_variables_nat c \"\n  by (simp add: enumerate_variables_nat_def enumerate_variables_tail_def subtail_concat \nsubtail_enumerate_subprograms subtail_map_all_variables subtail_remdups)\n\nlemma sub_enumerate_variables:\n  \"enumerate_variables_nat (comm_encode c) = vname_list_encode ( enumerate_variables c)\"\n  apply \n   (simp only:  submap_all_variables enumerate_variables_nat_def enumerate_variables_def sub_enumerate_subprograms \n                sub_map  map_map)\n  apply (simp only: comp_def)\n  apply (simp only: sub_all_variables)\n  apply (simp only: flip:comp_def) \n  apply (simp only: flip:map_map)\n  apply (simp only: vname_list_encode_as_comp)\n  apply (simp only: flip:map_map)\n  using vname_inj\n  apply (simp only: sub_concat sub_remdups comp_apply map_concat flip:remdups_map )\n  done\n\n\nend ", "meta": {"author": "AlexiosFan", "repo": "BA_NP_Reduction", "sha": "0e37ddc58cb822b0a09b2ce7c15e7b88652e154c", "save_path": "github-repos/isabelle/AlexiosFan-BA_NP_Reduction", "path": "github-repos/isabelle/AlexiosFan-BA_NP_Reduction/BA_NP_Reduction-0e37ddc58cb822b0a09b2ce7c15e7b88652e154c/poly-reductions/Cook_Levin/IMP-_To_SAS+/IMP--_To_SAS++/IMP_Minus_Minus_Subprograms_Nat.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.679178699175393, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.2947509667317434}}
{"text": "section {* ICF-setup for Automatic Refinement *}\ntheory ICF_Autoref\nimports \n  ICF_Refine_Monadic \n  \"../GenCF/Intf/Intf_Set\"\n  \"../GenCF/Intf/Intf_Map\"\nbegin\n\nsubsection {* Unique Priority Queue *}\nconsts i_prio :: \"interface \\<Rightarrow> interface \\<Rightarrow> interface\"\ndefinition [simp]: \"op_uprio_empty \\<equiv> Map.empty\"\ndefinition [simp]: \"op_uprio_is_empty x \\<equiv> x = Map.empty\"\ndefinition [simp]: \"op_uprio_insert s e a \\<equiv> s(e \\<mapsto> a)\"\ndefinition op_uprio_prio :: \"('e\\<rightharpoonup>'a)\\<Rightarrow>'e\\<rightharpoonup>'a\"\n  where [simp]: \"op_uprio_prio s e \\<equiv> s e\"\n\n(* FIXME: Tune id-op phase such that it can distinguish those patterns!\n  For now: Only include this patterns on demand!\n*)\ncontext begin interpretation autoref_syn .\n\nlemma uprio_pats:\n  fixes s :: \"'e\\<rightharpoonup>'a\"\n  shows\n  \"Map.empty::'e\\<rightharpoonup>'a \\<equiv> op_uprio_empty\"\n  \"s e \\<equiv> op_uprio_prio$s$e\"\n  \"s(e\\<mapsto>a) \\<equiv> op_uprio_insert$s$e$a\"\n\n  \"dom s = {} \\<equiv> op_uprio_is_empty$s\"\n  \"{} = dom s \\<equiv> op_uprio_is_empty$s\"\n  \"s=Map.empty \\<equiv> op_uprio_is_empty$s\"\n  \"Map.empty=s \\<equiv> op_uprio_is_empty$s\"\n  by (auto intro!: eq_reflection)\n\nend\n\nterm prio_pop_min\n\nlemma [autoref_itype]:\n  \"op_uprio_empty ::\\<^sub>i \\<langle>Ie,Ia\\<rangle>\\<^sub>ii_prio\"\n  \"op_uprio_prio ::\\<^sub>i \\<langle>Ie,Ia\\<rangle>\\<^sub>ii_prio \\<rightarrow>\\<^sub>i Ie \\<rightarrow>\\<^sub>i \\<langle>Ia\\<rangle>\\<^sub>ii_option\"\n  \"op_uprio_is_empty ::\\<^sub>i \\<langle>Ie,Ia\\<rangle>\\<^sub>ii_prio \\<rightarrow>\\<^sub>i i_bool\"\n  \"op_uprio_insert ::\\<^sub>i \\<langle>Ie,Ia\\<rangle>\\<^sub>ii_prio \\<rightarrow>\\<^sub>i Ie \\<rightarrow>\\<^sub>i Ia \\<rightarrow>\\<^sub>i \\<langle>Ie,Ia\\<rangle>\\<^sub>ii_prio\"\n  \"prio_pop_min ::\\<^sub>i \\<langle>Ie,Ia\\<rangle>\\<^sub>ii_prio \\<rightarrow>\\<^sub>i \\<langle>\\<langle>Ie,\\<langle>Ia,\\<langle>Ie,Ia\\<rangle>\\<^sub>ii_prio\\<rangle>\\<^sub>ii_prod\\<rangle>\\<^sub>ii_prod\\<rangle>\\<^sub>ii_nres\"\n  by simp_all\n\ncontext uprio begin\n  definition rel_def_internal: \n    \"rel Re Ra \\<equiv> br \\<alpha> invar O (Re \\<rightarrow> \\<langle>Ra\\<rangle> option_rel)\"\n  lemma rel_def:\n    \"\\<langle>Re,Ra\\<rangle>rel \\<equiv> br \\<alpha> invar O (Re \\<rightarrow> \\<langle>Ra\\<rangle> option_rel)\" \n    by (simp add: rel_def_internal relAPP_def)\n    \n  \n\n  lemma rel_sv[relator_props]: \n    \"\\<lbrakk>Range Re = UNIV; single_valued Ra\\<rbrakk> \\<Longrightarrow> single_valued (\\<langle>Re,Ra\\<rangle>rel)\"\n    unfolding rel_def by tagged_solver\n\n  lemmas [autoref_rel_intf] = REL_INTFI[of rel i_prio]\nend\n\n\nlemma (in uprio) rel_alt: \"\\<langle>Id,Rv\\<rangle>rel = \n  { (c,a). \\<forall>x. (\\<alpha> c x,a x)\\<in>\\<langle>Rv\\<rangle>option_rel \\<and> invar c }\"\n  by (auto simp: rel_def br_def dest: fun_relD)\n\nlemma (in uprio_empty) autoref_empty[autoref_rules]:\n  \"PREFER_id Re \\<Longrightarrow> (empty (),op_uprio_empty)\\<in>\\<langle>Re,Ra\\<rangle>rel\"\n  by (auto simp: empty_correct rel_alt)\n\nlemma (in uprio_isEmpty) autoref_is_empty[autoref_rules]:\n  \"PREFER_id Re \\<Longrightarrow> (isEmpty,op_uprio_is_empty)\\<in>\\<langle>Re,Ra\\<rangle>rel\\<rightarrow>bool_rel\"\n  by (auto simp: isEmpty_correct rel_alt intro!: ext)\n\nlemma (in uprio_prio) autoref_prio[autoref_rules]:\n  \"PREFER_id Re \\<Longrightarrow> (prio,op_uprio_prio)\\<in>\\<langle>Re,Ra\\<rangle>rel\\<rightarrow>Re\\<rightarrow>\\<langle>Ra\\<rangle>option_rel\"\n  by (auto simp: prio_correct rel_alt intro!: ext)\n\nlemma (in uprio_insert) autoref_insert[autoref_rules]:\n  \"PREFER_id Re \\<Longrightarrow> (insert,op_uprio_insert)\\<in>\\<langle>Re,Ra\\<rangle>rel\\<rightarrow>Re\\<rightarrow>Ra\\<rightarrow>\\<langle>Re,Ra\\<rangle>rel\"\n  by (auto simp: insert_correct rel_alt intro!: ext)\n\nlemma (in uprio_pop) autoref_prio_pop_min[autoref_rules]:\n  \"\\<lbrakk>PREFER_id Re; PREFER_id Ra \\<rbrakk> \n  \\<Longrightarrow> (\\<lambda>s. RETURN (pop s),prio_pop_min)\\<in>\\<langle>Re,Ra\\<rangle>rel\\<rightarrow>\\<langle>\\<langle>Re,\\<langle>Ra,\\<langle>Re,Ra\\<rangle>rel\\<rangle>prod_rel\\<rangle>prod_rel\\<rangle>nres_rel\"\n  apply simp\n  apply (intro fun_relI nres_relI)\n  by (rule prio_pop_min_refine)\n\n\n\n\ncontext set begin\n  definition rel_def_internal: \"rel R \\<equiv> br \\<alpha> invar O \\<langle>R\\<rangle>set_rel\"\n  lemma rel_def: \"\\<langle>R\\<rangle>rel \\<equiv> br \\<alpha> invar O \\<langle>R\\<rangle>set_rel\" \n    by (simp add: rel_def_internal relAPP_def)\n    \n  lemma rel_id[simp]: \"\\<langle>Id\\<rangle>rel = br \\<alpha> invar\" by (simp add: rel_def)\n\n  lemma rel_sv[relator_props]: \"single_valued R \\<Longrightarrow> single_valued (\\<langle>R\\<rangle>rel)\"\n    unfolding rel_def by tagged_solver\n\n  lemmas [autoref_rel_intf] = REL_INTFI[of rel i_set]\n\nend\n\ncontext map begin\n  definition rel_def_internal: \n    \"rel Rk Rv \\<equiv> br \\<alpha> invar O (Rk \\<rightarrow> \\<langle>Rv\\<rangle> option_rel)\"\n  lemma rel_def: \n    \"\\<langle>Rk,Rv\\<rangle>rel \\<equiv> br \\<alpha> invar O (Rk \\<rightarrow> \\<langle>Rv\\<rangle> option_rel)\" \n    by (simp add: rel_def_internal relAPP_def)\n    \n  lemma rel_id[simp]: \"\\<langle>Id,Id\\<rangle>rel = br \\<alpha> invar\" \n    by (simp add: rel_def)\n\n  lemma rel_sv[relator_props]: \n    \"\\<lbrakk>Range Rk = UNIV; single_valued Rv\\<rbrakk> \\<Longrightarrow> single_valued (\\<langle>Rk,Rv\\<rangle>rel)\"\n    unfolding rel_def \n    by (tagged_solver (trace))\n\n  lemmas [autoref_rel_intf] = REL_INTFI[of rel i_map]\n\nend\n\n\n(*\ncontext list begin\n  definition rel_def_internal: \n    \"rel R \\<equiv> br \\<alpha> invar O R\"\n  lemma rel_def: \"\\<langle>R\\<rangle>rel \\<equiv> br \\<alpha> invar O R\" \n    by (simp add: rel_def_internal relAPP_def)\n    \n  lemma rel_id[simp]: \"\\<langle>Id\\<rangle>rel = br \\<alpha> invar\" \n    by (simp add: rel_def)\n\n  lemma rel_sv[relator_props]: \"single_valued R \\<Longrightarrow> single_valued (\\<langle>R\\<rangle>rel)\"\n    unfolding rel_def by refine_post\nend\n\ncontext al begin\n  definition rel_def_internal: \n    \"rel Re Ra \\<equiv> br \\<alpha> invar O \\<langle>\\<langle>Re,Ra\\<rangle> prod_rel\\<rangle>list_rel\"\n  lemma rel_def: \n    \"\\<langle>Re,Ra\\<rangle>rel \\<equiv> br \\<alpha> invar O \\<langle>\\<langle>Re,Ra\\<rangle> prod_rel\\<rangle>list_rel\" \n    by (simp add: rel_def_internal relAPP_def)\n    \n  lemma rel_id[simp]: \"\\<langle>Id,Id\\<rangle>rel = br \\<alpha> invar\" \n    by (simp add: rel_def)\n\n  lemma rel_sv[relator_props]: \n    \"\\<lbrakk>single_valued Re; single_valued Ra\\<rbrakk> \\<Longrightarrow> single_valued (\\<langle>Re,Ra\\<rangle>rel)\"\n    unfolding rel_def by refine_post\n\nend\n\ncontext prio begin\n  (* TODO: Fix that to use multiset_rel! *)\n  definition rel_def[simp]: \"rel \\<equiv> br \\<alpha> invar\"\n  lemma rel_sv: \"single_valued rel\" unfolding rel_def by refine_post\nend\n\ncontext uprio begin\n  definition rel_def_internal: \n    \"rel Re Ra \\<equiv> br \\<alpha> invar O (Re \\<rightarrow> \\<langle>Ra\\<rangle> option_rel)\"\n  lemma rel_def:\n    \"\\<langle>Re,Ra\\<rangle>rel \\<equiv> br \\<alpha> invar O (Re \\<rightarrow> \\<langle>Ra\\<rangle> option_rel)\" \n    by (simp add: rel_def_internal relAPP_def)\n    \n  lemma rel_id[simp]: \"\\<langle>Id,Id\\<rangle>rel = br \\<alpha> invar\" \n    by (simp add: rel_def)\n\n  lemma rel_sv[relator_props]: \n    \"\\<lbrakk>Range Re = UNIV; single_valued Ra\\<rbrakk> \\<Longrightarrow> single_valued (\\<langle>Re,Ra\\<rangle>rel)\"\n    unfolding rel_def by refine_post\n\nend\n*)\n\n\nsetup {* Revert_Abbrev.revert_abbrev \"Autoref_Binding_ICF.*.rel\" *}\n\n\n\n\n(* TODO: Move *)\nlemma Collect_x_x_pairs_rel_image[simp]: \"{p. \\<exists>x. p = (x, x)}``x = x\" \n    by auto\n\n\nsubsection \"Set\"\n\nlemma (in set_empty) empty_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (empty (), {}) \\<in> \\<langle>Rk\\<rangle>rel\"\n  by (simp add: br_def empty_correct)\n\nlemma (in set_memb) memb_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (memb,op \\<in>)\\<in>Rk\\<rightarrow>\\<langle>Rk\\<rangle>rel\\<rightarrow>Id\"\n  apply simp\n  by (auto simp add: memb_correct br_def)\n\nlemma (in set_ins) ins_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (ins,Set.insert)\\<in>Rk\\<rightarrow>\\<langle>Rk\\<rangle>rel\\<rightarrow>\\<langle>Rk\\<rangle>rel\"\n  by simp (auto simp add: ins_correct br_def)\n\ncontext set_ins_dj begin\ncontext begin interpretation autoref_syn .\nlemma ins_dj_autoref[autoref_rules]: \n  assumes \"SIDE_PRECOND_OPT (x'\\<notin>s')\"\n  assumes \"PREFER_id Rk\"\n  assumes \"(x,x')\\<in>Rk\"\n  assumes \"(s,s')\\<in>\\<langle>Rk\\<rangle>rel\"\n  shows \"(ins_dj x s,(OP Set.insert ::: Rk \\<rightarrow> \\<langle>Rk\\<rangle>rel \\<rightarrow> \\<langle>Rk\\<rangle>rel)$x'$s')\\<in>\\<langle>Rk\\<rangle>rel\"\n  using assms \n  apply simp\n  apply (auto simp add: ins_dj_correct br_def)\n  done\nend\nend\n\nlemma (in set_delete) delete_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (delete,op_set_delete)\\<in>Rk\\<rightarrow>\\<langle>Rk\\<rangle>rel\\<rightarrow>\\<langle>Rk\\<rangle>rel\"\n  by simp (auto simp add: delete_correct op_set_delete_def br_def)\n \nlemma (in set_isEmpty) isEmpty_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (isEmpty,op_set_isEmpty) \\<in> \\<langle>Rk\\<rangle>rel\\<rightarrow>Id\"\n  apply (simp add: br_def)\n  apply (fastforce simp: isEmpty_correct)\n  done\n\nlemma (in set_isSng) isSng_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (isSng,op_set_isSng) \\<in> \\<langle>Rk\\<rangle>rel\\<rightarrow>Id\"\n  by simp\n    (auto simp add: isSng_correct op_set_isSng_def br_def card_Suc_eq)\n\nlemma (in set_ball) ball_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (ball,Set.Ball) \\<in> \\<langle>Rk\\<rangle>rel\\<rightarrow>(Rk\\<rightarrow>Id)\\<rightarrow>Id\"\n  by simp (auto simp add: ball_correct fun_rel_def br_def)\n\nlemma (in set_bex) bex_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (bex,Set.Bex) \\<in> \\<langle>Rk\\<rangle>rel\\<rightarrow>(Rk\\<rightarrow>Id)\\<rightarrow>Id\"\n  apply simp\n  apply (auto simp: bex_correct fun_rel_def br_def intro!: ext)\n  done\n\nlemma (in set_size) size_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (size,card) \\<in> \\<langle>Rk\\<rangle>rel \\<rightarrow> Id\"\n  by simp (auto simp add: size_correct br_def)\n\nlemma (in set_size_abort) size_abort_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (size_abort,op_set_size_abort) \\<in> Id \\<rightarrow> \\<langle>Rk\\<rangle>rel \\<rightarrow> Id\"\n  by simp\n    (auto simp add: size_abort_correct op_set_size_abort_def br_def)\n\nlemma (in set_union) union_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (union,op \\<union>)\\<in>\\<langle>Rk\\<rangle>s1.rel\\<rightarrow>\\<langle>Rk\\<rangle>s2.rel\\<rightarrow>\\<langle>Rk\\<rangle>s3.rel\"\n  by simp (auto simp add: union_correct br_def)\n\ncontext set_union_dj begin\ncontext begin interpretation autoref_syn .\n\nlemma union_dj_autoref[autoref_rules]:\n  assumes \"PREFER_id Rk\"\n  assumes \"SIDE_PRECOND_OPT (a'\\<inter>b'={})\"\n  assumes \"(a,a')\\<in>\\<langle>Rk\\<rangle>s1.rel\"\n  assumes \"(b,b')\\<in>\\<langle>Rk\\<rangle>s2.rel\"\n  shows \"(union_dj a b,(OP op \\<union> ::: \\<langle>Rk\\<rangle>s1.rel \\<rightarrow> \\<langle>Rk\\<rangle>s2.rel \\<rightarrow> \\<langle>Rk\\<rangle>s3.rel)$a'$b')\n    \\<in>\\<langle>Rk\\<rangle>s3.rel\"\n  using assms \n  by simp (auto simp: union_dj_correct br_def)\nend \nend\n\nlemma (in set_diff) diff_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (diff,op -)\\<in>\\<langle>Rk\\<rangle>s1.rel\\<rightarrow>\\<langle>Rk\\<rangle>s2.rel\\<rightarrow>\\<langle>Rk\\<rangle>s1.rel\"\n  by simp (auto simp add: diff_correct br_def)\n\nlemma (in set_filter) filter_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (filter,op_set_filter)\\<in>(Rk \\<rightarrow> Id) \\<rightarrow> \\<langle>Rk\\<rangle>s1.rel\\<rightarrow>\\<langle>Rk\\<rangle>s2.rel\"\n  by simp (auto simp add: filter_correct op_set_filter_def fun_rel_def \n    br_def)\n\nlemma (in set_inter) inter_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (inter,op \\<inter>)\\<in>\\<langle>Rk\\<rangle>s1.rel\\<rightarrow>\\<langle>Rk\\<rangle>s2.rel\\<rightarrow>\\<langle>Rk\\<rangle>s3.rel\"\n  by simp (auto simp add: inter_correct br_def)\n\nlemma (in set_subset) subset_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (subset,op \\<subseteq>)\\<in>\\<langle>Rk\\<rangle>s1.rel\\<rightarrow>\\<langle>Rk\\<rangle>s2.rel\\<rightarrow>Id\"\n  by simp (auto simp add: subset_correct br_def)\n\nlemma (in set_equal) equal_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (equal,op =)\\<in>\\<langle>Rk\\<rangle>s1.rel\\<rightarrow>\\<langle>Rk\\<rangle>s2.rel\\<rightarrow>Id\"\n  by simp (auto simp add: equal_correct br_def)\n\nlemma (in set_disjoint) disjoint_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (disjoint,op_set_disjoint)\\<in>\\<langle>Rk\\<rangle>s1.rel\\<rightarrow>\\<langle>Rk\\<rangle>s2.rel\\<rightarrow>Id\"\n  by simp (auto simp add: disjoint_correct op_set_disjoint_def br_def)\n\nlemma (in list_to_set) to_set_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (to_set,set)\\<in>\\<langle>Rk\\<rangle>list_rel \\<rightarrow> \\<langle>Rk\\<rangle>rel\"\n  apply simp\n  apply (auto simp add: to_set_correct br_def)\n  done\n\ncontext set_sel' begin\ncontext begin interpretation autoref_syn .\n\nlemma autoref_op_set_pick[autoref_rules]: \n  assumes \"SIDE_PRECOND (s'\\<noteq>{})\"\n  assumes \"PREFER_id Rk\"\n  assumes \"(s,s')\\<in>\\<langle>Rk\\<rangle>rel\"\n  shows \"(RETURN (the (sel' s (\\<lambda>_. True))), \n          (OP op_set_pick ::: \\<langle>Rk\\<rangle>rel \\<rightarrow> \\<langle>Rk\\<rangle>nres_rel) $ s')\n    \\<in> \\<langle>Rk\\<rangle>nres_rel\"\n  using assms\n  apply (clarsimp simp add: br_def nres_rel_def ex_in_conv[symmetric])\n  apply (erule (1) sel'E[OF _ _ TrueI])\n  apply (auto intro: RES_refine)\n  done\nend\nend\n\nlemma (in poly_set_iteratei) proper[proper_it]:\n  \"proper_it' iteratei iteratei\"\n  apply (rule proper_it'I)\n  by (rule pi_iteratei)\n\nlemma (in poly_set_iteratei) autoref_iteratei[autoref_ga_rules]: \n  \"REL_IS_ID Rk \\<Longrightarrow> is_set_to_list Rk rel (it_to_list iteratei)\"\n  unfolding is_set_to_list_def is_set_to_sorted_list_def it_to_list_def \n    it_to_sorted_list_def\n  apply (simp add: br_def, intro allI impI)\n  apply (drule iteratei_correct)\n  unfolding set_iterator_def set_iterator_genord_foldli_conv\n  apply (elim exE)\n  apply clarsimp\n  apply (drule fun_cong[where x=\"\\<lambda>_::'x list. True\"])\n  apply simp\n  done\n\nlemma (in poly_set_iterateoi) proper_o[proper_it]:\n  \"proper_it' iterateoi iterateoi\"\n  apply (rule proper_it'I)\n  by (rule pi_iterateoi)\n\n\n\nlemma (in poly_set_rev_iterateoi) autoref_rev_iterateoi[autoref_ga_rules]: \n  \"REL_IS_ID Rk \\<Longrightarrow> \n    is_set_to_sorted_list op \\<ge> Rk rel (it_to_list rev_iterateoi)\"\n  unfolding is_set_to_sorted_list_def it_to_list_def it_to_sorted_list_def\n  apply (simp add: br_def, intro allI impI)\n  apply (drule rev_iterateoi_correct)\n  unfolding set_iterator_rev_linord_def set_iterator_genord_foldli_conv\n  apply (elim exE)\n  apply clarsimp\n  apply (drule fun_cong[where x=\"\\<lambda>_::'x list. True\"])\n  apply simp\n  done\n\nlemma (in poly_set_rev_iterateoi) proper_ro[proper_it]:\n  \"proper_it' rev_iterateoi rev_iterateoi\"\n  apply (rule proper_it'I)\n  by (rule pi_rev_iterateoi)\n\nsubsection \"Map\"\n\nlemma (in map) rel_alt: \"\\<langle>Id,Rv\\<rangle>rel = \n  { (c,a). \\<forall>x. (\\<alpha> c x,a x)\\<in>\\<langle>Rv\\<rangle>option_rel \\<and> invar c }\"\n  by (auto simp: rel_def br_def dest: fun_relD)\n\nlemma (in map_empty) empty_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (empty (),op_map_empty)\\<in>\\<langle>Rk,Rv\\<rangle>rel\"\n  by (auto simp: empty_correct rel_alt)\n  \nlemma (in map_lookup) lookup_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (lookup,op_map_lookup)\\<in>Rk\\<rightarrow>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>\\<langle>Rv\\<rangle>option_rel\"\n  apply (intro fun_relI option_relI)\n  apply (auto simp: lookup_correct rel_alt\n    dest: fun_relD2)\n  done\n\nlemma (in map_update) update_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (update,op_map_update)\\<in>Rk\\<rightarrow>Rv\\<rightarrow>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>\\<langle>Rk,Rv\\<rangle>rel\"\n  apply (intro fun_relI)\n  apply (simp add: update_correct rel_alt)\n  done\n\ncontext map_update_dj begin\ncontext begin interpretation autoref_syn .\n\nlemma update_dj_autoref[autoref_rules]: \n  assumes \"SIDE_PRECOND_OPT (k'\\<notin>dom m')\"\n  assumes \"PREFER_id Rk\"\n  assumes \"(k,k')\\<in>Rk\"\n  assumes \"(v,v')\\<in>Rv\"\n  assumes \"(m,m')\\<in>\\<langle>Rk,Rv\\<rangle>rel\"\n  shows \"(update_dj k v m,\n    (OP op_map_update ::: Rk \\<rightarrow> Rv \\<rightarrow> \\<langle>Rk,Rv\\<rangle>rel \\<rightarrow> \\<langle>Rk,Rv\\<rangle>rel)$k'$v'$m'\n  )\\<in>\\<langle>Rk,Rv\\<rangle>rel\"\n  using assms\n  apply (subgoal_tac \"k\\<notin>dom (\\<alpha> m)\")\n  apply (simp add: update_dj_correct rel_alt)\n  apply (auto simp add: rel_alt option_rel_def)\n  apply (metis option.simps(3))\n  done\nend\nend\n\nlemma (in map_delete) delete_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (delete,op_map_delete)\\<in>Rk\\<rightarrow>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>\\<langle>Rk,Rv\\<rangle>rel\"\n  apply (intro fun_relI)\n  apply (simp add: delete_correct restrict_map_def rel_alt)\n  done\n\nlemma (in map_restrict) restrict_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> \n    (restrict,op_map_restrict) \n    \\<in> (\\<langle>Rk,Rv\\<rangle>prod_rel \\<rightarrow> Id) \\<rightarrow> \\<langle>Rk,Rv\\<rangle>m1.rel \\<rightarrow> \\<langle>Rk,Rv\\<rangle>m2.rel\"\n  apply (intro fun_relI)\n  apply (simp add: restrict_correct br_comp_alt m1.rel_def m2.rel_def )\n  apply (intro fun_relI)\n  apply (auto simp: restrict_map_def split: split_if_asm)\n  apply (drule (1) fun_relD1)\n  apply (auto simp: option_rel_def) []\n  apply (drule (1) fun_relD1)\n  apply (auto simp: option_rel_def) []\n  apply (drule (1) fun_relD1)\n  apply (auto simp: option_rel_def prod_rel_def fun_rel_def) []\n  apply (drule (1) fun_relD2)\n  apply (auto simp: option_rel_def prod_rel_def fun_rel_def) []\n  done\n\nlemma (in map_add) add_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (add,op ++)\\<in>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>\\<langle>Rk,Rv\\<rangle>rel\"\n  apply (auto simp add: add_correct rel_alt Map.map_add_def\n    split: option.split)\n  apply (drule_tac x=x in spec)+\n  apply simp\n  apply (metis option.simps(3) option_rel_simp(2))\n  by (metis (lifting) option_rel_simp(3))\n\n\ncontext map_add_dj begin\ncontext begin interpretation autoref_syn .\n\nlemma add_dj_autoref[autoref_rules]: \n  assumes \"PREFER_id Rk\"\n  assumes \"SIDE_PRECOND_OPT (dom a' \\<inter> dom b' = {})\"\n  assumes \"(a,a')\\<in>\\<langle>Rk,Rv\\<rangle>rel\"\n  assumes \"(b,b')\\<in>\\<langle>Rk,Rv\\<rangle>rel\"\n  shows \"(add_dj a b, (OP op ++ ::: \\<langle>Rk,Rv\\<rangle>rel \\<rightarrow> \\<langle>Rk,Rv\\<rangle>rel \\<rightarrow> \\<langle>Rk,Rv\\<rangle>rel) $ a' $ b')\\<in>\\<langle>Rk,Rv\\<rangle>rel\"\n  using assms\n  apply simp\n  apply (subgoal_tac \"dom (\\<alpha> a) \\<inter> dom (\\<alpha> b) = {}\")\n  apply (clarsimp simp add: add_dj_correct rel_def br_comp_alt)\n  apply (auto \n    simp add: rel_def br_comp_alt Map.map_add_def\n    split: option.split\n    elim: fun_relE1 dest: fun_relD1 intro: option_relI\n  ) []\n\n  apply (clarsimp simp add: rel_def br_comp_alt)\n\n  apply (auto simp: dom_def)\n  apply (drule (1) fun_relD1)\n  apply (drule (1) fun_relD1)\n  apply (auto simp: option_rel_def)\n  done\nend\nend\n\nlemma (in map_isEmpty) isEmpty_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (isEmpty,op_map_isEmpty)\\<in>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>Id\"\n  by (auto simp: isEmpty_correct rel_alt\n    intro!: ext)\n\nlemma sngI: \n  assumes \"m k = Some v\"\n  assumes \"\\<forall>k'. k'\\<noteq>k \\<longrightarrow> m k' = None\"\n  shows \"m = [k\\<mapsto>v]\"\n  using assms\n  by (auto intro!: ext)\n\nlemma (in map_isSng) isSng_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (isSng,op_map_isSng)\\<in>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>Id\"\n  (* TODO: Clean up this mess *)\n  apply (auto simp add: isSng_correct rel_alt)\n  apply (rule_tac x=k in exI)\n  apply (rule_tac x=\"the (a' k)\" in exI)\n  apply (rule sngI)\n  apply (drule_tac x=k in spec)\n  apply (auto elim: option_relE) []\n  apply (force elim: option_relE) []\n\n  apply (rule_tac x=k in exI)\n  apply (rule_tac x=\"the (\\<alpha> a k)\" in exI)\n  apply (rule sngI)\n  apply (drule_tac x=k in spec)\n  apply (auto elim: option_relE) []\n  apply (force elim: option_relE) []\n  done\n\nlemma (in map_ball) ball_autoref[autoref_rules]:\n  \"PREFER_id Rk \\<Longrightarrow> (ball,op_map_ball)\\<in>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>(\\<langle>Rk,Rv\\<rangle>prod_rel\\<rightarrow>Id)\\<rightarrow>Id\"\n  apply (auto simp: ball_correct rel_alt map_to_set_def\n    option_rel_def prod_rel_def fun_rel_def)\n  apply (metis option.inject option.simps(3))+\n  done\n\nlemma (in map_bex) bex_autoref[autoref_rules]:\n  \"PREFER_id Rk \\<Longrightarrow> (bex,op_map_bex)\\<in>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>(\\<langle>Rk,Rv\\<rangle>prod_rel\\<rightarrow>Id)\\<rightarrow>Id\"\n  apply (auto simp: bex_correct map_to_set_def rel_alt \n    option_rel_def prod_rel_def fun_rel_def)\n  apply (metis option.inject option.simps(3))+\n  done\n\nlemma (in map_size) size_autoref[autoref_rules]:\n  \"PREFER_id Rk \\<Longrightarrow> (size,op_map_size)\\<in>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>Id\"\n  apply (auto simp: size_correct rel_alt option_rel_def dom_def \n    intro!: arg_cong[where f=card])\n  apply (metis option.simps(3))+\n  done\n\nlemma (in map_size_abort) size_abort_autoref[autoref_rules]:\n  \"PREFER_id Rk \\<Longrightarrow> (size_abort,op_map_size_abort)\\<in>Id\\<rightarrow>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>Id\"\n  apply (auto simp: size_abort_correct  \n    rel_alt option_rel_def\n    dom_def intro!: arg_cong[where f=card] cong[OF arg_cong[where f=min]])\n  apply (metis option.simps(3))+\n  done\n\nlemma (in list_to_map) to_map_autoref[autoref_rules]:\n  \"PREFER_id Rk \\<Longrightarrow> (to_map,map_of)\\<in> \\<langle>\\<langle>Rk,Rv\\<rangle>prod_rel\\<rangle>list_rel \\<rightarrow> \\<langle>Rk,Rv\\<rangle>rel\"\nproof (intro fun_relI)\n  fix l :: \"('u\\<times>'v) list\" and l' :: \"('u\\<times>'a) list\"\n  assume \"PREFER_id Rk\" hence [simp]: \"Rk=Id\" by simp\n  assume \"(l,l')\\<in>\\<langle>\\<langle>Rk,Rv\\<rangle>prod_rel\\<rangle>list_rel\"\n  thus \"(to_map l, map_of l') \\<in> \\<langle>Rk,Rv\\<rangle>rel\"\n    apply (simp add: list_rel_def)\n  proof (induct rule: list_all2_induct)\n    case Nil thus ?case \n      by (auto simp add: to_map_correct rel_alt)\n  next\n    case (Cons x x' l l') thus ?case\n      by (auto simp add: to_map_correct \n        rel_alt prod_rel_def)\n  qed\nqed\n\n(* TODO: Move *)\nlemma key_rel_true[simp]: \"key_rel (\\<lambda>_ _. True) = (\\<lambda>_ _. True)\"\n  by (auto intro!: ext simp: key_rel_def)\n\n\nlemma (in poly_map_iteratei) proper[proper_it]:\n  \"proper_it' iteratei iteratei\"\n  apply (rule proper_it'I)\n  by (rule pi_iteratei)\n\nlemma (in poly_map_iteratei) autoref_iteratei[autoref_ga_rules]: \n  assumes ID: \"REL_IS_ID Rk\"\n    \"REL_IS_ID Rv\" (* TODO: Unnecessary*)\n  shows \"is_map_to_list Rk Rv rel (it_to_list iteratei)\"\nproof -\n  from ID have [simp]: \"Rk=Id\" \"Rv = Id\" by simp_all\n\n  show ?thesis\n    unfolding is_map_to_sorted_list_def is_map_to_list_def\n      it_to_sorted_list_def\n    apply simp\n    apply (intro allI impI conjI)\n  proof -\n    fix m m'\n    assume \"(m, m') \\<in> br \\<alpha> invar\"\n    hence I: \"invar m\" and M': \"m' = \\<alpha> m\" by (simp_all add: br_def)\n\n    have [simp]: \"\\<And>c. (\\<lambda>(_,_). c) = (\\<lambda>_. c)\" by auto\n\n    from map_it_to_list_genord_correct[where it = iteratei, \n      where R=\"\\<lambda>_ _. True\", simplified, OF \n      iteratei_correct[OF I, unfolded set_iterator_def]\n    ] have \n        M: \"Map.map_of (it_to_list iteratei m) = \\<alpha> m\"\n        and D: \"distinct (List.map fst (it_to_list iteratei m))\"\n      by (simp_all)\n\n    from D show \"distinct (it_to_list iteratei m)\"\n      by (rule distinct_mapI)\n\n    from M show \"map_to_set m' = set (it_to_list iteratei m)\"\n      by (simp add: M' map_of_map_to_set[OF D])\n  qed\nqed\n\nlemma (in poly_map_iterateoi) proper_o[proper_it]:\n  \"proper_it' iterateoi iterateoi\"\n  apply (rule proper_it'I)\n  by (rule pi_iterateoi)\n\nlemma (in poly_map_iterateoi) autoref_iterateoi[autoref_ga_rules]: \n  assumes ID: \"REL_IS_ID Rk\"\n    \"REL_IS_ID Rv\" (* TODO: Unnecessary*)\n  shows \"is_map_to_sorted_list op \\<le> Rk Rv rel (it_to_list iterateoi)\"\nproof -\n  from ID have [simp]: \"Rk=Id\" \"Rv = Id\" by simp_all\n\n  show ?thesis\n    unfolding is_map_to_sorted_list_def\n      it_to_sorted_list_def\n    apply simp\n    apply (intro allI impI conjI)\n  proof -\n    fix m m'\n    assume \"(m, m') \\<in> br \\<alpha> invar\"\n    hence I: \"invar m\" and M': \"m' = \\<alpha> m\" by (simp_all add: br_def)\n\n    have [simp]: \"\\<And>c. (\\<lambda>(_,_). c) = (\\<lambda>_. c)\" by auto\n\n    from map_it_to_list_linord_correct[where it = iterateoi, \n      OF iterateoi_correct[OF I]\n    ] have \n        M: \"map_of (it_to_list iterateoi m) = \\<alpha> m\"\n        and D: \"distinct (map fst (it_to_list iterateoi m))\"\n        and S: \"sorted (map fst (it_to_list iterateoi m))\"\n      by (simp_all)\n\n    from D show \"distinct (it_to_list iterateoi m)\"\n      by (rule distinct_mapI)\n\n    from M show \"map_to_set m' = set (it_to_list iterateoi m)\"\n      by (simp add: M' map_of_map_to_set[OF D])\n\n    from S show \"sorted_by_rel (key_rel op \\<le>) (it_to_list iterateoi m)\"\n      by (simp add: key_rel_def[abs_def])\n\n  qed\nqed\n\nlemma (in poly_map_rev_iterateoi) proper_ro[proper_it]:\n  \"proper_it' rev_iterateoi rev_iterateoi\"\n  apply (rule proper_it'I)\n  by (rule pi_rev_iterateoi)\n\nlemma (in poly_map_rev_iterateoi) autoref_rev_iterateoi[autoref_ga_rules]: \n  assumes ID: \"REL_IS_ID Rk\"\n    \"REL_IS_ID Rv\" (* TODO: Unnecessary*)\n  shows \"is_map_to_sorted_list op \\<ge> Rk Rv rel (it_to_list rev_iterateoi)\"\nproof -\n  from ID have [simp]: \"Rk=Id\" \"Rv = Id\" by simp_all\n\n  show ?thesis\n    unfolding is_map_to_sorted_list_def\n      it_to_sorted_list_def\n    apply simp\n    apply (intro allI impI conjI)\n  proof -\n    fix m m'\n    assume \"(m, m') \\<in> br \\<alpha> invar\"\n    hence I: \"invar m\" and M': \"m' = \\<alpha> m\" by (simp_all add: br_def)\n\n    have [simp]: \"\\<And>c. (\\<lambda>(_,_). c) = (\\<lambda>_. c)\" by auto\n\n    from map_it_to_list_rev_linord_correct[where it = rev_iterateoi, \n      OF rev_iterateoi_correct[OF I]\n    ] have \n        M: \"map_of (it_to_list rev_iterateoi m) = \\<alpha> m\"\n        and D: \"distinct (map fst (it_to_list rev_iterateoi m))\"\n        and S: \"sorted (rev (map fst (it_to_list rev_iterateoi m)))\"\n      by (simp_all)\n\n    from D show \"distinct (it_to_list rev_iterateoi m)\"\n      by (rule distinct_mapI)\n\n    from M show \"map_to_set m' = set (it_to_list rev_iterateoi m)\"\n      by (simp add: M' map_of_map_to_set[OF D])\n\n    from S show \"sorted_by_rel (key_rel op \\<ge>) (it_to_list rev_iterateoi m)\"\n      by (simp add: key_rel_def[abs_def])\n\n  qed\nqed\n\n\n\n\n\n\nend\n", "meta": {"author": "andredidier", "repo": "phd", "sha": "113f7c8b360a3914a571db13d9513e313954f4b2", "save_path": "github-repos/isabelle/andredidier-phd", "path": "github-repos/isabelle/andredidier-phd/phd-113f7c8b360a3914a571db13d9513e313954f4b2/thesis/Collections/ICF/ICF_Autoref.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.2946826900294997}}
{"text": "(*  Title:      ZF/Inductive.thy\n    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory\n    Copyright   1993  University of Cambridge\n\nInductive definitions use least fixedpoints with standard products and sums\nCoinductive definitions use greatest fixedpoints with Quine products and sums\n\nSums are used only for mutual recursion;\nProducts are used only to derive \"streamlined\" induction rules for relations\n*)\n\nsection\\<open>Inductive and Coinductive Definitions\\<close>\n\ntheory Inductive\nimports Fixedpt QPair Nat\nkeywords\n  \"inductive\" \"coinductive\" \"inductive_cases\" \"rep_datatype\" \"primrec\" :: thy_decl and\n  \"domains\" \"intros\" \"monos\" \"con_defs\" \"type_intros\" \"type_elims\"\n    \"elimination\" \"induction\" \"case_eqns\" \"recursor_eqns\" :: quasi_command\nbegin\n\nlemma def_swap_iff: \"a == b ==> a = c \\<longleftrightarrow> c = b\"\n  by blast\n\nlemma def_trans: \"f == g ==> g(a) = b ==> f(a) = b\"\n  by simp\n\nlemma refl_thin: \"!!P. a = a ==> P ==> P\" .\n\nML_file \\<open>ind_syntax.ML\\<close>\nML_file \\<open>Tools/ind_cases.ML\\<close>\nML_file \\<open>Tools/cartprod.ML\\<close>\nML_file \\<open>Tools/inductive_package.ML\\<close>\nML_file \\<open>Tools/induct_tacs.ML\\<close>\nML_file \\<open>Tools/primrec_package.ML\\<close>\n\nML \\<open>\nstructure Lfp =\n  struct\n  val oper      = \\<^const>\\<open>lfp\\<close>\n  val bnd_mono  = \\<^const>\\<open>bnd_mono\\<close>\n  val bnd_monoI = @{thm bnd_monoI}\n  val subs      = @{thm def_lfp_subset}\n  val Tarski    = @{thm def_lfp_unfold}\n  val induct    = @{thm def_induct}\n  end;\n\nstructure Standard_Prod =\n  struct\n  val sigma     = \\<^const>\\<open>Sigma\\<close>\n  val pair      = \\<^const>\\<open>Pair\\<close>\n  val split_name = \\<^const_name>\\<open>split\\<close>\n  val pair_iff  = @{thm Pair_iff}\n  val split_eq  = @{thm split}\n  val fsplitI   = @{thm splitI}\n  val fsplitD   = @{thm splitD}\n  val fsplitE   = @{thm splitE}\n  end;\n\nstructure Standard_CP = CartProd_Fun (Standard_Prod);\n\nstructure Standard_Sum =\n  struct\n  val sum       = \\<^const>\\<open>sum\\<close>\n  val inl       = \\<^const>\\<open>Inl\\<close>\n  val inr       = \\<^const>\\<open>Inr\\<close>\n  val elim      = \\<^const>\\<open>case\\<close>\n  val case_inl  = @{thm case_Inl}\n  val case_inr  = @{thm case_Inr}\n  val inl_iff   = @{thm Inl_iff}\n  val inr_iff   = @{thm Inr_iff}\n  val distinct  = @{thm Inl_Inr_iff}\n  val distinct' = @{thm Inr_Inl_iff}\n  val free_SEs  = Ind_Syntax.mk_free_SEs\n            [distinct, distinct', inl_iff, inr_iff, Standard_Prod.pair_iff]\n  end;\n\n\nstructure Ind_Package =\n    Add_inductive_def_Fun\n      (structure Fp=Lfp and Pr=Standard_Prod and CP=Standard_CP\n       and Su=Standard_Sum val coind = false);\n\n\nstructure Gfp =\n  struct\n  val oper      = \\<^const>\\<open>gfp\\<close>\n  val bnd_mono  = \\<^const>\\<open>bnd_mono\\<close>\n  val bnd_monoI = @{thm bnd_monoI}\n  val subs      = @{thm def_gfp_subset}\n  val Tarski    = @{thm def_gfp_unfold}\n  val induct    = @{thm def_Collect_coinduct}\n  end;\n\nstructure Quine_Prod =\n  struct\n  val sigma     = \\<^const>\\<open>QSigma\\<close>\n  val pair      = \\<^const>\\<open>QPair\\<close>\n  val split_name = \\<^const_name>\\<open>qsplit\\<close>\n  val pair_iff  = @{thm QPair_iff}\n  val split_eq  = @{thm qsplit}\n  val fsplitI   = @{thm qsplitI}\n  val fsplitD   = @{thm qsplitD}\n  val fsplitE   = @{thm qsplitE}\n  end;\n\nstructure Quine_CP = CartProd_Fun (Quine_Prod);\n\nstructure Quine_Sum =\n  struct\n  val sum       = \\<^const>\\<open>qsum\\<close>\n  val inl       = \\<^const>\\<open>QInl\\<close>\n  val inr       = \\<^const>\\<open>QInr\\<close>\n  val elim      = \\<^const>\\<open>qcase\\<close>\n  val case_inl  = @{thm qcase_QInl}\n  val case_inr  = @{thm qcase_QInr}\n  val inl_iff   = @{thm QInl_iff}\n  val inr_iff   = @{thm QInr_iff}\n  val distinct  = @{thm QInl_QInr_iff}\n  val distinct' = @{thm QInr_QInl_iff}\n  val free_SEs  = Ind_Syntax.mk_free_SEs\n            [distinct, distinct', inl_iff, inr_iff, Quine_Prod.pair_iff]\n  end;\n\n\nstructure CoInd_Package =\n  Add_inductive_def_Fun(structure Fp=Gfp and Pr=Quine_Prod and CP=Quine_CP\n    and Su=Quine_Sum val coind = true);\n\n\\<close>\n\nend\n", "meta": {"author": "landonf", "repo": "isabelle-legacy", "sha": "e40f3ca7e9a42bb91e57fd15f969388e6e83f692", "save_path": "github-repos/isabelle/landonf-isabelle-legacy", "path": "github-repos/isabelle/landonf-isabelle-legacy/isabelle-legacy-e40f3ca7e9a42bb91e57fd15f969388e6e83f692/src/ZF/Inductive.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5389832058771035, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.2946826819319902}}
{"text": "(* Copyright 2021 (C) Mihails Milehins *)\n\nsection\\<open>Universal arrow\\<close>\ntheory CZH_UCAT_Universal\n  imports \n    CZH_UCAT_Introduction\n    CZH_Elementary_Categories.CZH_ECAT_FUNCT\n    CZH_Elementary_Categories.CZH_ECAT_Hom\nbegin\n\n\n\nsubsection\\<open>Background\\<close>\n\n\ntext\\<open>\nThe following section is based, primarily, on the elements of the content \nof Chapter III-1 in \\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>.\n\\<close>\n\nnamed_theorems ua_field_simps\n\ndefinition UObj :: V where [ua_field_simps]: \"UObj = 0\"\ndefinition UArr :: V where [ua_field_simps]: \"UArr = 1\\<^sub>\\<nat>\"\n\nlemma [cat_cs_simps]:\n  shows UObj_simp: \"[a, b]\\<^sub>\\<circ>\\<lparr>UObj\\<rparr> = a\"\n    and UArr_simp: \"[a, b]\\<^sub>\\<circ>\\<lparr>UArr\\<rparr> = b\"\n  unfolding ua_field_simps by (simp_all add: nat_omega_simps)\n\n\n\nsubsection\\<open>Universal map\\<close>\n\n\ntext\\<open>\nThe universal map is a convenience utility that allows treating \na part of the definition of the universal arrow as an arrow in the\ncategory \\<open>Set\\<close>.\n\\<close>\n\n\nsubsubsection\\<open>Definition and elementary properties\\<close>\n\ndefinition umap_of :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V\"\n  where \"umap_of \\<FF> c r u d =\n    [\n      (\\<lambda>f'\\<in>\\<^sub>\\<circ>Hom (\\<FF>\\<lparr>HomDom\\<rparr>) r d. \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<FF>\\<lparr>HomCod\\<rparr>\\<^esub> u),\n      Hom (\\<FF>\\<lparr>HomDom\\<rparr>) r d,\n      Hom (\\<FF>\\<lparr>HomCod\\<rparr>) c (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>d\\<rparr>)\n    ]\\<^sub>\\<circ>\"\n\ndefinition umap_fo :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V\"\n  where \"umap_fo \\<FF> c r u d = umap_of (op_cf \\<FF>) c r u d\"\n\n\ntext\\<open>Components.\\<close>\n\nlemma (in is_functor) umap_of_components:\n  assumes \"u : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\" (*do not remove*)\n  shows \"umap_of \\<FF> c r u d\\<lparr>ArrVal\\<rparr> = (\\<lambda>f'\\<in>\\<^sub>\\<circ>Hom \\<AA> r d. \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> u)\"\n    and \"umap_of \\<FF> c r u d\\<lparr>ArrDom\\<rparr> = Hom \\<AA> r d\"\n    and \"umap_of \\<FF> c r u d\\<lparr>ArrCod\\<rparr> = Hom \\<BB> c (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>d\\<rparr>)\"\n  unfolding umap_of_def arr_field_simps\n  by (simp_all add: cat_cs_simps nat_omega_simps)\n\nlemma (in is_functor) umap_fo_components:\n  assumes \"u : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\"\n  shows \"umap_fo \\<FF> c r u d\\<lparr>ArrVal\\<rparr> = (\\<lambda>f'\\<in>\\<^sub>\\<circ>Hom \\<AA> d r. u \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr>)\"\n    and \"umap_fo \\<FF> c r u d\\<lparr>ArrDom\\<rparr> = Hom \\<AA> d r\"\n    and \"umap_fo \\<FF> c r u d\\<lparr>ArrCod\\<rparr> = Hom \\<BB> (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>d\\<rparr>) c\"\n  unfolding \n    umap_fo_def \n    is_functor.umap_of_components[\n      OF is_functor_op, unfolded cat_op_simps, OF assms\n      ] \nproof(rule vsv_eqI)\n  fix f' assume \"f' \\<in>\\<^sub>\\<circ> \\<D>\\<^sub>\\<circ> (\\<lambda>f'\\<in>\\<^sub>\\<circ>Hom \\<AA> d r. \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>op_cat \\<BB>\\<^esub> u)\"\n  then have f': \"f' : d \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r\" by simp\n  then have \\<FF>f': \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>d\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\" \n    by (auto intro: cat_cs_intros)\n  from f' show \n    \"(\\<lambda>f'\\<in>\\<^sub>\\<circ>Hom \\<AA> d r. \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>op_cat \\<BB>\\<^esub> u)\\<lparr>f'\\<rparr> = \n      (\\<lambda>f'\\<in>\\<^sub>\\<circ>Hom \\<AA> d r. u \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr>)\\<lparr>f'\\<rparr>\"\n    by (simp add: HomCod.op_cat_Comp[OF assms \\<FF>f'])\nqed simp_all\n\n\ntext\\<open>Universal maps for the opposite functor.\\<close>\n\nlemma (in is_functor) op_umap_of[cat_op_simps]: \"umap_of (op_cf \\<FF>) = umap_fo \\<FF>\"\n  unfolding umap_fo_def by simp \n\nlemma (in is_functor) op_umap_fo[cat_op_simps]: \"umap_fo (op_cf \\<FF>) = umap_of \\<FF>\"\n  unfolding umap_fo_def by (simp add: cat_op_simps)\n\nlemmas [cat_op_simps] = \n  is_functor.op_umap_of\n  is_functor.op_umap_fo\n\n\nsubsubsection\\<open>Arrow value\\<close>\n\nlemma umap_of_ArrVal_vsv[cat_cs_intros]: \"vsv (umap_of \\<FF> c r u d\\<lparr>ArrVal\\<rparr>)\"\n  unfolding umap_of_def arr_field_simps by (simp add: nat_omega_simps)\n\nlemma umap_fo_ArrVal_vsv[cat_cs_intros]: \"vsv (umap_fo \\<FF> c r u d\\<lparr>ArrVal\\<rparr>)\"\n  unfolding umap_fo_def by (rule umap_of_ArrVal_vsv)\n\nlemma (in is_functor) umap_of_ArrVal_vdomain: \n  assumes \"u : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\"\n  shows \"\\<D>\\<^sub>\\<circ> (umap_of \\<FF> c r u d\\<lparr>ArrVal\\<rparr>) = Hom \\<AA> r d\"\n  unfolding umap_of_components[OF assms] by simp\n\nlemmas [cat_cs_simps] = is_functor.umap_of_ArrVal_vdomain\n\nlemma (in is_functor) umap_fo_ArrVal_vdomain:\n  assumes \"u : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\"\n  shows \"\\<D>\\<^sub>\\<circ> (umap_fo \\<FF> c r u d\\<lparr>ArrVal\\<rparr>) = Hom \\<AA> d r\"\n  unfolding umap_fo_components[OF assms] by simp\n\nlemmas [cat_cs_simps] = is_functor.umap_fo_ArrVal_vdomain\n\nlemma (in is_functor) umap_of_ArrVal_app: \n  assumes \"f' : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> d\" and \"u : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\"\n  shows \"umap_of \\<FF> c r u d\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr> = \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> u\"\n  using assms(1) unfolding umap_of_components[OF assms(2)] by simp\n\nlemmas [cat_cs_simps] = is_functor.umap_of_ArrVal_app\n\nlemma (in is_functor) umap_fo_ArrVal_app: \n  assumes \"f' : d \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r\" and \"u : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\"\n  shows \"umap_fo \\<FF> c r u d\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr> = u \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr>\"\nproof-\n  from assms have \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>d\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\" \n    by (auto intro: cat_cs_intros)\n  from this assms(2) have \\<FF>f'[simp]:\n    \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>op_cat \\<BB>\\<^esub> u = u \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr>\"\n    by (simp add: cat_op_simps)\n  from\n    is_functor_axioms\n    is_functor.umap_of_ArrVal_app[\n      OF is_functor_op, unfolded cat_op_simps, \n      OF assms\n      ] \n  show ?thesis\n    by (simp add: cat_op_simps cat_cs_simps)\nqed\n\nlemmas [cat_cs_simps] = is_functor.umap_fo_ArrVal_app\n\nlemma (in is_functor) umap_of_ArrVal_vrange: \n  assumes \"u : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\"\n  shows \"\\<R>\\<^sub>\\<circ> (umap_of \\<FF> c r u d\\<lparr>ArrVal\\<rparr>) \\<subseteq>\\<^sub>\\<circ> Hom \\<BB> c (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>d\\<rparr>)\"\nproof(intro vsubset_antisym vsubsetI)\n  interpret vsv \\<open>umap_of \\<FF> c r u d\\<lparr>ArrVal\\<rparr>\\<close> \n    unfolding umap_of_components[OF assms] by simp\n  fix g assume \"g \\<in>\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (umap_of \\<FF> c r u d\\<lparr>ArrVal\\<rparr>)\"\n  then obtain f' \n    where g_def: \"g = umap_of \\<FF> c r u d\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\" \n      and f': \"f' \\<in>\\<^sub>\\<circ> \\<D>\\<^sub>\\<circ> (umap_of \\<FF> c r u d\\<lparr>ArrVal\\<rparr>)\"\n    unfolding umap_of_components[OF assms] by auto\n  then have f': \"f' : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> d\" \n    unfolding umap_of_ArrVal_vdomain[OF assms] by simp\n  then have \\<FF>f': \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>d\\<rparr>\" \n    by (auto intro!: cat_cs_intros)\n  have g_def: \"g = \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> u\"\n    unfolding g_def umap_of_ArrVal_app[OF f' assms]..\n  from \\<FF>f' assms show \"g \\<in>\\<^sub>\\<circ> Hom \\<BB> c (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>d\\<rparr>)\" \n    unfolding g_def by (auto intro: cat_cs_intros)\nqed\n\nlemma (in is_functor) umap_fo_ArrVal_vrange: \n  assumes \"u : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\"\n  shows \"\\<R>\\<^sub>\\<circ> (umap_fo \\<FF> c r u d\\<lparr>ArrVal\\<rparr>) \\<subseteq>\\<^sub>\\<circ> Hom \\<BB> (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>d\\<rparr>) c\"\n  by \n    (\n      rule is_functor.umap_of_ArrVal_vrange[\n        OF is_functor_op, unfolded cat_op_simps, OF assms, folded umap_fo_def\n        ]\n    )\n\n\nsubsubsection\\<open>Universal map is an arrow in the category \\<open>Set\\<close>\\<close>\n\nlemma (in is_functor) cf_arr_Set_umap_of: \n  assumes \"category \\<alpha> \\<AA>\" \n    and \"category \\<alpha> \\<BB>\" \n    and r: \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n    and d: \"d \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n    and u: \"u : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\"\n  shows \"arr_Set \\<alpha> (umap_of \\<FF> c r u d)\"\nproof(intro arr_SetI)\n  interpret HomDom: category \\<alpha> \\<AA> by (rule assms(1))\n  interpret HomCod: category \\<alpha> \\<BB> by (rule assms(2))\n  note umap_of_components = umap_of_components[OF u]\n  from u d have c: \"c \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" and \\<FF>d: \"(\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>d\\<rparr>) \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" \n    by (auto intro: cat_cs_intros)\n  show \"vfsequence (umap_of \\<FF> c r u d)\" unfolding umap_of_def by simp\n  show \"vcard (umap_of \\<FF> c r u d) = 3\\<^sub>\\<nat>\"\n    unfolding umap_of_def by (simp add: nat_omega_simps)\n  from umap_of_ArrVal_vrange[OF u] show \n    \"\\<R>\\<^sub>\\<circ> (umap_of \\<FF> c r u d\\<lparr>ArrVal\\<rparr>) \\<subseteq>\\<^sub>\\<circ> umap_of \\<FF> c r u d\\<lparr>ArrCod\\<rparr>\"\n    unfolding umap_of_components by simp\n  from r d show \"umap_of \\<FF> c r u d\\<lparr>ArrDom\\<rparr> \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n    unfolding umap_of_components by (intro HomDom.cat_Hom_in_Vset)\n  from c \\<FF>d show \"umap_of \\<FF> c r u d\\<lparr>ArrCod\\<rparr> \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n    unfolding umap_of_components by (intro HomCod.cat_Hom_in_Vset)\nqed (auto simp: umap_of_components[OF u])\n\nlemma (in is_functor) cf_arr_Set_umap_fo: \n  assumes \"category \\<alpha> \\<AA>\" \n    and \"category \\<alpha> \\<BB>\" \n    and r: \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n    and d: \"d \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n    and u: \"u : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\"\n  shows \"arr_Set \\<alpha> (umap_fo \\<FF> c r u d)\"\nproof-\n  from assms(1) have \\<AA>: \"category \\<alpha> (op_cat \\<AA>)\" \n    by (auto intro: cat_cs_intros)\n  from assms(2) have \\<BB>: \"category \\<alpha> (op_cat \\<BB>)\" \n    by (auto intro: cat_cs_intros)\n  show ?thesis\n    by \n      (\n        rule \n          is_functor.cf_arr_Set_umap_of[\n            OF is_functor_op, unfolded cat_op_simps, OF \\<AA> \\<BB> r d u\n            ]\n      )\nqed\n\nlemma (in is_functor) cf_umap_of_is_arr:\n  assumes \"category \\<alpha> \\<AA>\" \n    and \"category \\<alpha> \\<BB>\" \n    and \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n    and \"d \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n    and \"u : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\"\n  shows \"umap_of \\<FF> c r u d : Hom \\<AA> r d \\<mapsto>\\<^bsub>cat_Set \\<alpha>\\<^esub> Hom \\<BB> c (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>d\\<rparr>)\"\nproof(intro cat_Set_is_arrI)\n  show \"arr_Set \\<alpha> (umap_of \\<FF> c r u d)\" \n    by (rule cf_arr_Set_umap_of[OF assms])\nqed (simp_all add: umap_of_components[OF assms(5)])\n\nlemma (in is_functor) cf_umap_of_is_arr':\n  assumes \"category \\<alpha> \\<AA>\" \n    and \"category \\<alpha> \\<BB>\" \n    and \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n    and \"d \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n    and \"u : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\"\n    and \"A = Hom \\<AA> r d\"\n    and \"B = Hom \\<BB> c (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>d\\<rparr>)\"\n    and \"\\<CC> = cat_Set \\<alpha>\"\n  shows \"umap_of \\<FF> c r u d : A \\<mapsto>\\<^bsub>\\<CC>\\<^esub> B\"\n  using assms(1-5) unfolding assms(6-8) by (rule cf_umap_of_is_arr)\n\nlemmas [cat_cs_intros] = is_functor.cf_umap_of_is_arr'\n\nlemma (in is_functor) cf_umap_fo_is_arr:\n  assumes \"category \\<alpha> \\<AA>\" \n    and \"category \\<alpha> \\<BB>\" \n    and \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n    and \"d \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n    and \"u : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\"\n  shows \"umap_fo \\<FF> c r u d : Hom \\<AA> d r \\<mapsto>\\<^bsub>cat_Set \\<alpha>\\<^esub> Hom \\<BB> (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>d\\<rparr>) c\"\nproof(intro cat_Set_is_arrI)\n  show \"arr_Set \\<alpha> (umap_fo \\<FF> c r u d)\" \n    by (rule cf_arr_Set_umap_fo[OF assms])\nqed (simp_all add: umap_fo_components[OF assms(5)])\n\nlemma (in is_functor) cf_umap_fo_is_arr':\n  assumes \"category \\<alpha> \\<AA>\" \n    and \"category \\<alpha> \\<BB>\" \n    and \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n    and \"d \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n    and \"u : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\"\n    and \"A = Hom \\<AA> d r\"\n    and \"B = Hom \\<BB> (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>d\\<rparr>) c\"\n    and \"\\<CC> = cat_Set \\<alpha>\"\n  shows \"umap_fo \\<FF> c r u d : A \\<mapsto>\\<^bsub>\\<CC>\\<^esub> B\"\n  using assms(1-5) unfolding assms(6-8) by (rule cf_umap_fo_is_arr)\n\nlemmas [cat_cs_intros] = is_functor.cf_umap_fo_is_arr'\n\n\n\nsubsection\\<open>Universal arrow: definition and elementary properties\\<close>\n\n\ntext\\<open>See Chapter III-1 in \\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>.\\<close>\n\ndefinition universal_arrow_of :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> bool\"\n  where \"universal_arrow_of \\<FF> c r u \\<longleftrightarrow>\n    (\n      r \\<in>\\<^sub>\\<circ> \\<FF>\\<lparr>HomDom\\<rparr>\\<lparr>Obj\\<rparr> \\<and>\n      u : c \\<mapsto>\\<^bsub>\\<FF>\\<lparr>HomCod\\<rparr>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> \\<and>\n      (\n        \\<forall>r' u'.\n          r' \\<in>\\<^sub>\\<circ> \\<FF>\\<lparr>HomDom\\<rparr>\\<lparr>Obj\\<rparr> \\<longrightarrow>\n          u' : c \\<mapsto>\\<^bsub>\\<FF>\\<lparr>HomCod\\<rparr>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr> \\<longrightarrow>\n          (\\<exists>!f'. f' : r \\<mapsto>\\<^bsub>\\<FF>\\<lparr>HomDom\\<rparr>\\<^esub> r' \\<and> u' = umap_of \\<FF> c r u r'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>)\n      )\n    )\"\n\ndefinition universal_arrow_fo :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> bool\"\n  where \"universal_arrow_fo \\<FF> c r u \\<equiv> universal_arrow_of (op_cf \\<FF>) c r u\"\n\n\ntext\\<open>Rules.\\<close>\n\nmk_ide (in is_functor) rf \n  universal_arrow_of_def[where \\<FF>=\\<FF>, unfolded cf_HomDom cf_HomCod]\n  |intro universal_arrow_ofI|\n  |dest universal_arrow_ofD[dest]|\n  |elim universal_arrow_ofE[elim]|\n\nlemma (in is_functor) universal_arrow_foI:\n  assumes \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n    and \"u : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\" \n    and \"\\<And>r' u'. \\<lbrakk> r' \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>; u' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c \\<rbrakk> \\<Longrightarrow> \n      \\<exists>!f'. f' : r' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r \\<and> u' = umap_fo \\<FF> c r u r'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\n  shows \"universal_arrow_fo \\<FF> c r u\"\n  by \n    (\n      simp add: \n        is_functor.universal_arrow_ofI\n          [\n            OF is_functor_op, \n            folded universal_arrow_fo_def, \n            unfolded cat_op_simps, \n            OF assms\n          ]\n    )\n\nlemma (in is_functor) universal_arrow_foD[dest]:\n  assumes \"universal_arrow_fo \\<FF> c r u\"\n  shows \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n    and \"u : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\" \n    and \"\\<And>r' u'. \\<lbrakk> r' \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>; u' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c \\<rbrakk> \\<Longrightarrow> \n      \\<exists>!f'. f' : r' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r \\<and> u' = umap_fo \\<FF> c r u r'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\n  by\n    (\n      auto simp: \n        is_functor.universal_arrow_ofD\n          [\n            OF is_functor_op, \n            folded universal_arrow_fo_def, \n            unfolded cat_op_simps,\n            OF assms\n          ]\n    )\n\nlemma (in is_functor) universal_arrow_foE[elim]:\n  assumes \"universal_arrow_fo \\<FF> c r u\"\n  obtains \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n    and \"u : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\" \n    and \"\\<And>r' u'. \\<lbrakk> r' \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>; u' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c \\<rbrakk> \\<Longrightarrow> \n      \\<exists>!f'. f' : r' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r \\<and> u' = umap_fo \\<FF> c r u r'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\n  using assms by (auto simp: universal_arrow_foD)\n\n\ntext\\<open>Elementary properties.\\<close>\n\nlemma (in is_functor) op_cf_universal_arrow_of[cat_op_simps]: \n  \"universal_arrow_of (op_cf \\<FF>) c r u \\<longleftrightarrow> universal_arrow_fo \\<FF> c r u\"\n  unfolding universal_arrow_fo_def ..\n\nlemma (in is_functor) op_cf_universal_arrow_fo[cat_op_simps]: \n  \"universal_arrow_fo (op_cf \\<FF>) c r u \\<longleftrightarrow> universal_arrow_of \\<FF> c r u\"\n  unfolding universal_arrow_fo_def cat_op_simps ..\n\nlemmas (in is_functor) [cat_op_simps] = \n  is_functor.op_cf_universal_arrow_of\n  is_functor.op_cf_universal_arrow_fo\n\n\n\nsubsection\\<open>Uniqueness\\<close>\n\n\ntext\\<open>\nThe following properties are related to the uniqueness of the \nuniversal arrow. These properties can be inferred from the content of\nChapter III-1 in \\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>.\n\\<close>\n\nlemma (in is_functor) cf_universal_arrow_of_ex_is_iso_arr:\n  \\<comment>\\<open>The proof is based on the ideas expressed in the proof of Theorem 5.2 \n  in Chapter Introduction in \\cite{hungerford_algebra_2003}.\\<close>\n  assumes \"universal_arrow_of \\<FF> c r u\" and \"universal_arrow_of \\<FF> c r' u'\"\n  obtains f where \"f : r \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<AA>\\<^esub> r'\" and \"u' = umap_of \\<FF> c r u r'\\<lparr>ArrVal\\<rparr>\\<lparr>f\\<rparr>\"\nproof-\n\n  note ua1 = universal_arrow_ofD[OF assms(1)]\n  note ua2 = universal_arrow_ofD[OF assms(2)]\n\n  from ua1(1) have \\<AA>r: \"\\<AA>\\<lparr>CId\\<rparr>\\<lparr>r\\<rparr> : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r\" by (auto intro: cat_cs_intros)\n  from ua1(1) have \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>\\<AA>\\<lparr>CId\\<rparr>\\<lparr>r\\<rparr>\\<rparr> = \\<BB>\\<lparr>CId\\<rparr>\\<lparr>\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\\<rparr>\"\n    by (auto intro: cat_cs_intros)\n  with ua1(1,2) have u_def: \"u = umap_of \\<FF> c r u r\\<lparr>ArrVal\\<rparr>\\<lparr>\\<AA>\\<lparr>CId\\<rparr>\\<lparr>r\\<rparr>\\<rparr>\"\n    unfolding umap_of_ArrVal_app[OF \\<AA>r ua1(2)] by (auto simp: cat_cs_simps)\n\n  from ua2(1) have \\<AA>r': \"\\<AA>\\<lparr>CId\\<rparr>\\<lparr>r'\\<rparr> : r' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r'\" by (auto intro: cat_cs_intros)\n  from ua2(1) have \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>\\<AA>\\<lparr>CId\\<rparr>\\<lparr>r'\\<rparr>\\<rparr> = \\<BB>\\<lparr>CId\\<rparr>\\<lparr>\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr>\\<rparr>\" \n    by (auto intro: cat_cs_intros)\n  with ua2(1,2) have u'_def: \"u' = umap_of \\<FF> c r' u' r'\\<lparr>ArrVal\\<rparr>\\<lparr>\\<AA>\\<lparr>CId\\<rparr>\\<lparr>r'\\<rparr>\\<rparr>\"\n    unfolding umap_of_ArrVal_app[OF \\<AA>r' ua2(2)] by (auto simp: cat_cs_simps)\n\n  from \\<AA>r u_def universal_arrow_ofD(3)[OF assms(1) ua1(1,2)] have eq_CId_rI: \n    \"\\<lbrakk> f' : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r; u = umap_of \\<FF> c r u r\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr> \\<rbrakk> \\<Longrightarrow> f' = \\<AA>\\<lparr>CId\\<rparr>\\<lparr>r\\<rparr>\" \n    for f'\n    by blast\n  from \\<AA>r' u'_def universal_arrow_ofD(3)[OF assms(2) ua2(1,2)] have eq_CId_r'I: \n    \"\\<lbrakk> f' : r' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r'; u' = umap_of \\<FF> c r' u' r'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr> \\<rbrakk> \\<Longrightarrow>\n      f' = \\<AA>\\<lparr>CId\\<rparr>\\<lparr>r'\\<rparr>\" \n    for f'\n    by blast\n\n  from ua1(3)[OF ua2(1,2)] obtain f \n    where f: \"f : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r'\" \n      and u'_def: \"u' = umap_of \\<FF> c r u r'\\<lparr>ArrVal\\<rparr>\\<lparr>f\\<rparr>\"\n      and \"g : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r' \\<Longrightarrow> u' = umap_of \\<FF> c r u r'\\<lparr>ArrVal\\<rparr>\\<lparr>g\\<rparr> \\<Longrightarrow> f = g\" \n    for g\n    by metis\n  from ua2(3)[OF ua1(1,2)] obtain f' \n    where f': \"f' : r' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r\" \n      and u_def: \"u = umap_of \\<FF> c r' u' r\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\n      and \"g : r' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r \\<Longrightarrow> u = umap_of \\<FF> c r' u' r\\<lparr>ArrVal\\<rparr>\\<lparr>g\\<rparr> \\<Longrightarrow> f' = g\" \n    for g\n    by metis\n\n  have \"f : r \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<AA>\\<^esub> r'\"\n  proof(intro is_iso_arrI is_inverseI)\n    show f: \"f : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r'\" by (rule f)\n    show f': \"f' : r' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r\" by (rule f')\n    show \"f : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r'\" by (rule f)\n    from f' have \\<FF>f': \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\" \n      by (auto intro: cat_cs_intros)\n    from f have \\<FF>f: \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr>\" \n      by (auto intro: cat_cs_intros)\n    note u'_def' = u'_def[symmetric, unfolded umap_of_ArrVal_app[OF f ua1(2)]] \n      and u_def' = u_def[symmetric, unfolded umap_of_ArrVal_app[OF f' ua2(2)]]\n    show \"f' \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f = \\<AA>\\<lparr>CId\\<rparr>\\<lparr>r\\<rparr>\"\n    proof(rule eq_CId_rI)\n      from f f' show f'f: \"f' \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r\" \n        by (auto intro: cat_cs_intros)\n      from ua1(2) \\<FF>f' \\<FF>f show \"u = umap_of \\<FF> c r u r\\<lparr>ArrVal\\<rparr>\\<lparr>f' \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f\\<rparr>\"\n        unfolding umap_of_ArrVal_app[OF f'f ua1(2)] cf_ArrMap_Comp[OF f' f]\n        by (simp add: HomCod.cat_Comp_assoc u'_def' u_def')\n    qed\n    show \"f \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f' = \\<AA>\\<lparr>CId\\<rparr>\\<lparr>r'\\<rparr>\"\n    proof(rule eq_CId_r'I)\n      from f f' show ff': \"f \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f' : r' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r'\" \n        by (auto intro: cat_cs_intros)\n      from ua2(2) \\<FF>f' \\<FF>f show \"u' = umap_of \\<FF> c r' u' r'\\<lparr>ArrVal\\<rparr>\\<lparr>f \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f'\\<rparr>\"\n        unfolding umap_of_ArrVal_app[OF ff' ua2(2)] cf_ArrMap_Comp[OF f f']\n        by (simp add: HomCod.cat_Comp_assoc u'_def' u_def')\n    qed\n  qed\n  \n  with u'_def that show ?thesis by auto\n\nqed\n\nlemma (in is_functor) cf_universal_arrow_fo_ex_is_iso_arr:\n  assumes \"universal_arrow_fo \\<FF> c r u\"\n    and \"universal_arrow_fo \\<FF> c r' u'\"\n  obtains f where \"f : r' \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<AA>\\<^esub> r\" and \"u' = umap_fo \\<FF> c r u r'\\<lparr>ArrVal\\<rparr>\\<lparr>f\\<rparr>\"\n  by \n    (\n      elim \n        is_functor.cf_universal_arrow_of_ex_is_iso_arr[\n          OF is_functor_op, unfolded cat_op_simps, OF assms\n          ]\n    )\n\nlemma (in is_functor) cf_universal_arrow_of_unique:\n  assumes \"universal_arrow_of \\<FF> c r u\"\n    and \"universal_arrow_of \\<FF> c r' u'\"\n  shows \"\\<exists>!f'. f' : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r' \\<and> u' = umap_of \\<FF> c r u r'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\nproof-\n  note ua1 = universal_arrow_ofD[OF assms(1)]\n  note ua2 = universal_arrow_ofD[OF assms(2)]\n  from ua1(3)[OF ua2(1,2)] show ?thesis .\nqed\n\nlemma (in is_functor) cf_universal_arrow_fo_unique:\n  assumes \"universal_arrow_fo \\<FF> c r u\"\n    and \"universal_arrow_fo \\<FF> c r' u'\"\n  shows \"\\<exists>!f'. f' : r' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r \\<and> u' = umap_fo \\<FF> c r u r'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\nproof-\n  note ua1 = universal_arrow_foD[OF assms(1)]\n  note ua2 = universal_arrow_foD[OF assms(2)]\n  from ua1(3)[OF ua2(1,2)] show ?thesis .\nqed\n\nlemma (in is_functor) cf_universal_arrow_of_is_iso_arr:\n  assumes \"universal_arrow_of \\<FF> c r u\"\n    and \"universal_arrow_of \\<FF> c r' u'\"\n    and \"f : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r'\" \n    and \"u' = umap_of \\<FF> c r u r'\\<lparr>ArrVal\\<rparr>\\<lparr>f\\<rparr>\"\n  shows \"f : r \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<AA>\\<^esub> r'\"\nproof-\n  from assms(3,4) cf_universal_arrow_of_unique[OF assms(1,2)] have eq: \n    \"g : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r' \\<Longrightarrow> u' = umap_of \\<FF> c r u r'\\<lparr>ArrVal\\<rparr>\\<lparr>g\\<rparr> \\<Longrightarrow> f = g\" for g\n    by blast\n  from assms(1,2) obtain f' \n    where iso_f': \"f' : r \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<AA>\\<^esub> r'\" \n      and u'_def: \"u' = umap_of \\<FF> c r u r'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\n    by (auto elim: cf_universal_arrow_of_ex_is_iso_arr)\n  then have f': \"f' : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r'\" by auto\n  from iso_f' show ?thesis unfolding eq[OF f' u'_def, symmetric].\nqed\n\nlemma (in is_functor) cf_universal_arrow_fo_is_iso_arr:\n  assumes \"universal_arrow_fo \\<FF> c r u\"\n    and \"universal_arrow_fo \\<FF> c r' u'\"\n    and \"f : r' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r\" \n    and \"u' = umap_fo \\<FF> c r u r'\\<lparr>ArrVal\\<rparr>\\<lparr>f\\<rparr>\"\n  shows \"f : r' \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<AA>\\<^esub> r\"\n  by \n    (\n      rule \n        is_functor.cf_universal_arrow_of_is_iso_arr[\n          OF is_functor_op, unfolded cat_op_simps, OF assms\n          ]\n    )\n\nlemma (in is_functor) universal_arrow_of_if_universal_arrow_of:\n  assumes \"universal_arrow_of \\<FF> c r u\" \n    and \"f : r \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<AA>\\<^esub> r'\"\n    and \"u' = umap_of \\<FF> c r u r'\\<lparr>ArrVal\\<rparr>\\<lparr>f\\<rparr>\"\n  shows \"universal_arrow_of \\<FF> c r' u'\"\nproof(intro universal_arrow_ofI assms(2))\n\n  note ua = universal_arrow_ofD[OF assms(1)]\n  note f = is_iso_arrD(1)[OF assms(2)]\n  from assms(3) ua(1,2) f have u'_def: \"u' = \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> u\"\n    by (cs_prems cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  from  ua(2) f show u': \"u' : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr>\"\n    unfolding u'_def by (cs_concl cs_intro: cat_cs_intros)\n\n  from f(1) show  \"r' \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" by auto\n\n  fix r'' u'' assume prems: \"r'' \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \"u'' : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r''\\<rparr>\"\n\n  from ua(3)[OF prems] obtain f' \n    where f': \"f' : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r''\"\n      and u''_def: \"u'' = umap_of \\<FF> c r u r''\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\n      and f'_unique: \"\\<And>f''.\n        \\<lbrakk> f'' : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r''; u'' = umap_of \\<FF> c r u r''\\<lparr>ArrVal\\<rparr>\\<lparr>f''\\<rparr> \\<rbrakk> \\<Longrightarrow>\n          f'' = f'\"\n    by metis\n\n  from u''_def f' ua(2) have [cat_cs_simps]: \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> u = u''\"\n    by (cs_prems cs_simp: cat_cs_simps cs_intro: cat_cs_intros) simp\n\n  show \"\\<exists>!f'. f' : r' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r'' \\<and> u'' = umap_of \\<FF> c r' u' r''\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\n  proof(intro ex1I conjI; (elim conjE)?)\n    from f' assms(2) f show \"f' \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f\\<inverse>\\<^sub>C\\<^bsub>\\<AA>\\<^esub> : r' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r''\"\n      by (cs_concl cs_intro: cat_cs_intros cat_arrow_cs_intros)\n    have \n      \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> (\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<inverse>\\<^sub>C\\<^bsub>\\<AA>\\<^esub>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> u') =\n        \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> (\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<inverse>\\<^sub>C\\<^bsub>\\<AA>\\<^esub>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> (\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> u))\"\n      unfolding u'_def ..\n    also from f' assms(2) u' f ua(2) have \n      \"\\<dots> = \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> (\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<inverse>\\<^sub>C\\<^bsub>\\<AA>\\<^esub> \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f\\<rparr>) \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> u\"\n      by\n        (\n          cs_concl \n            cs_simp: cat_cs_simps cs_intro: cat_arrow_cs_intros cat_cs_intros\n        )\n    also from f' assms(2) f ua(2) have \"\\<dots> = u''\"\n      by (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n    finally have [cat_cs_simps]: \n      \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> (\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<inverse>\\<^sub>C\\<^bsub>\\<AA>\\<^esub>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> u') = u''\".\n    from f' assms(2) u' f show \n      \"u'' = umap_of \\<FF> c r' u' r''\\<lparr>ArrVal\\<rparr>\\<lparr>f' \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f\\<inverse>\\<^sub>C\\<^bsub>\\<AA>\\<^esub>\\<rparr>\"\n      by\n        (\n          cs_concl\n            cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_arrow_cs_intros\n        )\n    fix g assume prems': \n      \"g : r' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r''\" \"u'' = umap_of \\<FF> c r' u' r''\\<lparr>ArrVal\\<rparr>\\<lparr>g\\<rparr>\"\n    from prems'(1) f have gf: \"g \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r''\"\n      by (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n    from prems'(2,1) assms(2) u' have \"u'' = \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> u'\"\n      by (cs_prems cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n    also from prems'(1) f ua(2) have \n      \"\\<dots> = \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> u\"\n      by (cs_concl cs_simp: cat_cs_simps u'_def u''_def cs_intro: cat_cs_intros)\n    also from prems'(1) f ua(2) have \n      \"\\<dots> = umap_of \\<FF> c r u r''\\<lparr>ArrVal\\<rparr>\\<lparr>g \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f\\<rparr>\"\n      by (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n    finally have \"u'' = umap_of \\<FF> c r u r''\\<lparr>ArrVal\\<rparr>\\<lparr>g \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f\\<rparr>\".\n    from f'_unique[OF gf this] have \"g \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f = f'\".\n    then have \"(g \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f) \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f\\<inverse>\\<^sub>C\\<^bsub>\\<AA>\\<^esub> = f' \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f\\<inverse>\\<^sub>C\\<^bsub>\\<AA>\\<^esub>\" by simp\n    from this assms(2) prems'(1) u' f ua(2) show \"g = f' \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f\\<inverse>\\<^sub>C\\<^bsub>\\<AA>\\<^esub>\"\n      by\n        (\n          cs_prems\n            cs_simp: cat_cs_simps cs_intro: cat_arrow_cs_intros cat_cs_intros\n        )\n  qed\n\nqed\n\nlemma (in is_functor) universal_arrow_fo_if_universal_arrow_fo:\n  assumes \"universal_arrow_fo \\<FF> c r u\" \n    and \"f : r' \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<AA>\\<^esub> r\"\n    and \"u' = umap_fo \\<FF> c r u r'\\<lparr>ArrVal\\<rparr>\\<lparr>f\\<rparr>\"\n  shows \"universal_arrow_fo \\<FF> c r' u'\"\n  by \n    (\n      rule is_functor.universal_arrow_of_if_universal_arrow_of[\n        OF is_functor_op, unfolded cat_op_simps, OF assms\n        ]\n    )\n\n\n\nsubsection\\<open>Universal natural transformation\\<close>\n\n\nsubsubsection\\<open>Definition and elementary properties\\<close>\n\n\ntext\\<open>\nThe concept of the universal natural transformation is introduced for the \nstatement of the elements of a variant of Proposition 1 in Chapter III-2\nin \\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>.\n\\<close>\n\ndefinition ntcf_ua_of :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V\"\n  where \"ntcf_ua_of \\<alpha> \\<FF> c r u =\n    [\n      (\\<lambda>d\\<in>\\<^sub>\\<circ>\\<FF>\\<lparr>HomDom\\<rparr>\\<lparr>Obj\\<rparr>. umap_of \\<FF> c r u d),\n      Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<FF>\\<lparr>HomDom\\<rparr>(r,-),\n      Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<FF>\\<lparr>HomCod\\<rparr>(c,-) \\<circ>\\<^sub>C\\<^sub>F \\<FF>,\n      \\<FF>\\<lparr>HomDom\\<rparr>,\n      cat_Set \\<alpha>\n    ]\\<^sub>\\<circ>\"\n\ndefinition ntcf_ua_fo :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V\"\n  where \"ntcf_ua_fo \\<alpha> \\<FF> c r u = ntcf_ua_of \\<alpha> (op_cf \\<FF>) c r u\"\n\n\ntext\\<open>Components.\\<close>\n\nlemma ntcf_ua_of_components:\n  shows \"ntcf_ua_of \\<alpha> \\<FF> c r u\\<lparr>NTMap\\<rparr> = (\\<lambda>d\\<in>\\<^sub>\\<circ>\\<FF>\\<lparr>HomDom\\<rparr>\\<lparr>Obj\\<rparr>. umap_of \\<FF> c r u d)\"\n    and \"ntcf_ua_of \\<alpha> \\<FF> c r u\\<lparr>NTDom\\<rparr> = Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<FF>\\<lparr>HomDom\\<rparr>(r,-)\"\n    and \"ntcf_ua_of \\<alpha> \\<FF> c r u\\<lparr>NTCod\\<rparr> = Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<FF>\\<lparr>HomCod\\<rparr>(c,-) \\<circ>\\<^sub>C\\<^sub>F \\<FF>\"\n    and \"ntcf_ua_of \\<alpha> \\<FF> c r u\\<lparr>NTDGDom\\<rparr> = \\<FF>\\<lparr>HomDom\\<rparr>\"\n    and \"ntcf_ua_of \\<alpha> \\<FF> c r u\\<lparr>NTDGCod\\<rparr> = cat_Set \\<alpha>\"\n  unfolding ntcf_ua_of_def nt_field_simps by (simp_all add: nat_omega_simps) \n\nlemma ntcf_ua_fo_components:\n  shows \"ntcf_ua_fo \\<alpha> \\<FF> c r u\\<lparr>NTMap\\<rparr> = (\\<lambda>d\\<in>\\<^sub>\\<circ>\\<FF>\\<lparr>HomDom\\<rparr>\\<lparr>Obj\\<rparr>. umap_fo \\<FF> c r u d)\"\n    and \"ntcf_ua_fo \\<alpha> \\<FF> c r u\\<lparr>NTDom\\<rparr> = Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>op_cat (\\<FF>\\<lparr>HomDom\\<rparr>)(r,-)\"\n    and \"ntcf_ua_fo \\<alpha> \\<FF> c r u\\<lparr>NTCod\\<rparr> =\n      Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>op_cat (\\<FF>\\<lparr>HomCod\\<rparr>)(c,-) \\<circ>\\<^sub>C\\<^sub>F op_cf \\<FF>\"\n    and \"ntcf_ua_fo \\<alpha> \\<FF> c r u\\<lparr>NTDGDom\\<rparr> = op_cat (\\<FF>\\<lparr>HomDom\\<rparr>)\"\n    and \"ntcf_ua_fo \\<alpha> \\<FF> c r u\\<lparr>NTDGCod\\<rparr> = cat_Set \\<alpha>\"\n  unfolding ntcf_ua_fo_def ntcf_ua_of_components umap_fo_def cat_op_simps \n  by simp_all\n\ncontext is_functor\nbegin\n\nlemmas ntcf_ua_of_components' = \n  ntcf_ua_of_components[where \\<alpha>=\\<alpha> and \\<FF>=\\<FF>, unfolded cat_cs_simps]\n\nlemmas [cat_cs_simps] = ntcf_ua_of_components'(2-5)\n\nlemma ntcf_ua_fo_components':\n  assumes \"c \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" and \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n  shows \"ntcf_ua_fo \\<alpha> \\<FF> c r u\\<lparr>NTMap\\<rparr> = (\\<lambda>d\\<in>\\<^sub>\\<circ>\\<AA>\\<lparr>Obj\\<rparr>. umap_fo \\<FF> c r u d)\"\n    and [cat_cs_simps]: \n      \"ntcf_ua_fo \\<alpha> \\<FF> c r u\\<lparr>NTDom\\<rparr> = Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<AA>(-,r)\"\n    and [cat_cs_simps]: \n      \"ntcf_ua_fo \\<alpha> \\<FF> c r u\\<lparr>NTCod\\<rparr> = Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<BB>(-,c) \\<circ>\\<^sub>C\\<^sub>F op_cf \\<FF>\"\n    and [cat_cs_simps]: \"ntcf_ua_fo \\<alpha> \\<FF> c r u\\<lparr>NTDGDom\\<rparr> = op_cat \\<AA>\"\n    and [cat_cs_simps]: \"ntcf_ua_fo \\<alpha> \\<FF> c r u\\<lparr>NTDGCod\\<rparr> = cat_Set \\<alpha>\"\n  unfolding\n    ntcf_ua_fo_components cat_cs_simps\n    HomDom.cat_op_cat_cf_Hom_snd[OF assms(2)] \n    HomCod.cat_op_cat_cf_Hom_snd[OF assms(1)]\n  by simp_all\n\nend\n\nlemmas [cat_cs_simps] = \n  is_functor.ntcf_ua_of_components'(2-5)\n  is_functor.ntcf_ua_fo_components'(2-5)\n\n\nsubsubsection\\<open>Natural transformation map\\<close>\n\nmk_VLambda (in is_functor) \n  ntcf_ua_of_components(1)[where \\<alpha>=\\<alpha> and \\<FF>=\\<FF>, unfolded cf_HomDom]\n  |vsv ntcf_ua_of_NTMap_vsv|\n  |vdomain ntcf_ua_of_NTMap_vdomain|\n  |app ntcf_ua_of_NTMap_app|\n\ncontext is_functor\nbegin\n\ncontext\n  fixes c r\n  assumes r: \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" and c: \"c \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" \nbegin\n\nmk_VLambda ntcf_ua_fo_components'(1)[OF c r]\n  |vsv ntcf_ua_fo_NTMap_vsv|\n  |vdomain ntcf_ua_fo_NTMap_vdomain|\n  |app ntcf_ua_fo_NTMap_app|\n\nend\n\nend\n\nlemmas [cat_cs_intros] = \n  is_functor.ntcf_ua_fo_NTMap_vsv\n  is_functor.ntcf_ua_of_NTMap_vsv\n\nlemmas [cat_cs_simps] = \n  is_functor.ntcf_ua_fo_NTMap_vdomain\n  is_functor.ntcf_ua_fo_NTMap_app\n  is_functor.ntcf_ua_of_NTMap_vdomain\n  is_functor.ntcf_ua_of_NTMap_app\n\nlemma (in is_functor) ntcf_ua_of_NTMap_vrange:\n  assumes \"category \\<alpha> \\<AA>\" \n    and \"category \\<alpha> \\<BB>\" \n    and \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n    and \"u : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\"\n  shows \"\\<R>\\<^sub>\\<circ> (ntcf_ua_of \\<alpha> \\<FF> c r u\\<lparr>NTMap\\<rparr>) \\<subseteq>\\<^sub>\\<circ> cat_Set \\<alpha>\\<lparr>Arr\\<rparr>\"\nproof(rule vsv.vsv_vrange_vsubset, unfold ntcf_ua_of_NTMap_vdomain)\n  show \"vsv (ntcf_ua_of \\<alpha> \\<FF> c r u\\<lparr>NTMap\\<rparr>)\" by (rule ntcf_ua_of_NTMap_vsv)\n  fix d assume prems: \"d \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n  with category_cat_Set is_functor_axioms assms show \n    \"ntcf_ua_of \\<alpha> \\<FF> c r u\\<lparr>NTMap\\<rparr>\\<lparr>d\\<rparr> \\<in>\\<^sub>\\<circ> cat_Set \\<alpha>\\<lparr>Arr\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\nqed\n\n\nsubsubsection\\<open>Commutativity of the universal maps and \\<open>hom\\<close>-functions\\<close>\n\nlemma (in is_functor) cf_umap_of_cf_hom_commute: \n  assumes \"category \\<alpha> \\<AA>\"\n    and \"category \\<alpha> \\<BB>\"\n    and \"c \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n    and \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n    and \"u : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\"\n    and \"f : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b\"\n  shows \n    \"umap_of \\<FF> c r u b \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> cf_hom \\<AA> [\\<AA>\\<lparr>CId\\<rparr>\\<lparr>r\\<rparr>, f]\\<^sub>\\<circ> =\n      cf_hom \\<BB> [\\<BB>\\<lparr>CId\\<rparr>\\<lparr>c\\<rparr>, \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr>]\\<^sub>\\<circ> \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> umap_of \\<FF> c r u a\"\n  (is \\<open>?uof_b \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?rf = ?cf \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?uof_a\\<close>)\nproof-\n\n  from is_functor_axioms category_cat_Set assms(1,2,4-6) have b_rf: \n    \"?uof_b \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?rf : Hom \\<AA> r a \\<mapsto>\\<^bsub>cat_Set \\<alpha>\\<^esub> Hom \\<BB> c (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>)\"\n    by \n      (\n        cs_concl cs_shallow \n          cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros\n      )\n  from is_functor_axioms category_cat_Set assms(1,2,4-6) have cf_a: \n    \"?cf \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?uof_a : Hom \\<AA> r a \\<mapsto>\\<^bsub>cat_Set \\<alpha>\\<^esub> Hom \\<BB> c (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>)\"\n    by (cs_concl cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros)\n\n  show ?thesis\n  proof(rule arr_Set_eqI[of \\<alpha>])\n    from b_rf show arr_Set_b_rf: \"arr_Set \\<alpha> (?uof_b \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?rf)\"\n      by (auto dest: cat_Set_is_arrD(1))\n    from b_rf have dom_lhs: \n      \"\\<D>\\<^sub>\\<circ> ((?uof_b \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?rf)\\<lparr>ArrVal\\<rparr>) = Hom \\<AA> r a\"\n      by (cs_concl cs_shallow cs_simp: cat_cs_simps)+\n    from cf_a show arr_Set_cf_a: \"arr_Set \\<alpha> (?cf \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?uof_a)\"\n      by (auto dest: cat_Set_is_arrD(1))\n    from cf_a have dom_rhs: \n      \"\\<D>\\<^sub>\\<circ> ((?cf \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?uof_a)\\<lparr>ArrVal\\<rparr>) = Hom \\<AA> r a\"\n      by (cs_concl cs_shallow cs_simp: cat_cs_simps)\n    show \"(?uof_b \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?rf)\\<lparr>ArrVal\\<rparr> = (?cf \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?uof_a)\\<lparr>ArrVal\\<rparr>\"\n    proof(rule vsv_eqI, unfold dom_lhs dom_rhs in_Hom_iff)\n      fix q assume \"q : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a\"\n      with is_functor_axioms category_cat_Set assms show \n        \"(?uof_b \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?rf)\\<lparr>ArrVal\\<rparr>\\<lparr>q\\<rparr> =\n          (?cf \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?uof_a)\\<lparr>ArrVal\\<rparr>\\<lparr>q\\<rparr>\"\n        by\n          (\n            cs_concl cs_shallow\n              cs_simp: cat_cs_simps cat_op_simps\n              cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros\n         )\n    qed (use arr_Set_b_rf arr_Set_cf_a in auto)\n  \n  qed (use b_rf cf_a in \\<open>cs_concl cs_shallow cs_simp: cat_cs_simps\\<close>)+\n\nqed\n\nlemma cf_umap_of_cf_hom_unit_commute:\n  assumes \"category \\<alpha> \\<CC>\"\n    and \"category \\<alpha> \\<DD>\"\n    and \"\\<FF> : \\<CC> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<DD>\"\n    and \"\\<GG> : \\<DD> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<eta> : cf_id \\<CC> \\<mapsto>\\<^sub>C\\<^sub>F \\<GG> \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<CC> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"g : c' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c\" \n    and \"f : d \\<mapsto>\\<^bsub>\\<DD>\\<^esub> d'\"\n  shows \n    \"umap_of \\<GG> c' (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>c'\\<rparr>) (\\<eta>\\<lparr>NTMap\\<rparr>\\<lparr>c'\\<rparr>) d' \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub>\n      cf_hom \\<DD> [\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr>, f]\\<^sub>\\<circ> =\n        cf_hom \\<CC> [g, \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr>]\\<^sub>\\<circ> \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub>\n          umap_of \\<GG> c (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>c\\<rparr>) (\\<eta>\\<lparr>NTMap\\<rparr>\\<lparr>c\\<rparr>) d\"\n  (is \\<open>?uof_c'd' \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?\\<FF>gf = ?g\\<GG>f \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?uof_cd\\<close>)\nproof-\n\n  interpret \\<eta>: is_ntcf \\<alpha> \\<CC> \\<CC> \\<open>cf_id \\<CC>\\<close> \\<open>\\<GG> \\<circ>\\<^sub>C\\<^sub>F \\<FF>\\<close> \\<eta> by (rule assms(5))\n\n  from assms have c'd'_\\<FF>gf: \"?uof_c'd' \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?\\<FF>gf :\n    Hom \\<DD> (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>c\\<rparr>) d \\<mapsto>\\<^bsub>cat_Set \\<alpha>\\<^esub> Hom \\<CC> c' (\\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>d'\\<rparr>)\"\n    by\n      (\n        cs_concl \n          cs_simp: cat_cs_simps \n          cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros\n      )\n  then have dom_lhs:\n    \"\\<D>\\<^sub>\\<circ> ((?uof_c'd' \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?\\<FF>gf)\\<lparr>ArrVal\\<rparr>) = Hom \\<DD> (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>c\\<rparr>) d\"\n    by (cs_concl cs_shallow cs_simp: cat_cs_simps)\n  from assms have g\\<GG>f_cd: \"?g\\<GG>f \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?uof_cd :\n    Hom \\<DD> (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>c\\<rparr>) d \\<mapsto>\\<^bsub>cat_Set \\<alpha>\\<^esub> Hom \\<CC> c' (\\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>d'\\<rparr>)\"\n    by \n      (\n        cs_concl \n          cs_simp: cat_cs_simps \n          cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros\n      )\n  then have dom_rhs: \n    \"\\<D>\\<^sub>\\<circ> ((?g\\<GG>f \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?uof_cd)\\<lparr>ArrVal\\<rparr>) = Hom \\<DD> (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>c\\<rparr>) d\"\n    by (cs_concl cs_shallow cs_simp: cat_cs_simps)\n\n  show ?thesis\n  proof(rule arr_Set_eqI[of \\<alpha>])\n    from c'd'_\\<FF>gf show arr_Set_c'd'_\\<FF>gf: \n      \"arr_Set \\<alpha> (?uof_c'd' \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?\\<FF>gf)\"\n      by (auto dest: cat_Set_is_arrD(1))\n    from g\\<GG>f_cd show arr_Set_g\\<GG>f_cd:\n      \"arr_Set \\<alpha> (?g\\<GG>f \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?uof_cd)\"\n      by (auto dest: cat_Set_is_arrD(1))\n    show \n      \"(?uof_c'd' \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?\\<FF>gf)\\<lparr>ArrVal\\<rparr> =\n        (?g\\<GG>f \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?uof_cd)\\<lparr>ArrVal\\<rparr>\"\n    proof(rule vsv_eqI, unfold dom_lhs dom_rhs in_Hom_iff)\n      fix h assume prems: \"h : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>c\\<rparr> \\<mapsto>\\<^bsub>\\<DD>\\<^esub> d\"\n      from \\<eta>.ntcf_Comp_commute[OF assms(6)] assms have [cat_cs_simps]:\n        \"\\<eta>\\<lparr>NTMap\\<rparr>\\<lparr>c\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> g = \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<eta>\\<lparr>NTMap\\<rparr>\\<lparr>c'\\<rparr>\"\n        by \n          (\n            cs_prems cs_shallow \n              cs_simp: cat_cs_simps cat_op_simps cs_intro: cat_cs_intros\n          )\n      from assms prems show \n        \"(?uof_c'd' \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?\\<FF>gf)\\<lparr>ArrVal\\<rparr>\\<lparr>h\\<rparr> =\n          (?g\\<GG>f \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?uof_cd)\\<lparr>ArrVal\\<rparr>\\<lparr>h\\<rparr>\"\n        by \n          (\n            cs_concl\n              cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros  \n              cs_simp: cat_cs_simps\n          )\n    qed (use arr_Set_c'd'_\\<FF>gf arr_Set_g\\<GG>f_cd in auto)\n \n  qed (use c'd'_\\<FF>gf g\\<GG>f_cd in \\<open>cs_concl cs_shallow cs_simp: cat_cs_simps\\<close>)+\n\nqed\n\n\nsubsubsection\\<open>Universal natural transformation is a natural transformation\\<close>\n\nlemma (in is_functor) cf_ntcf_ua_of_is_ntcf:\n  assumes \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n    and \"u : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\"\n  shows \"ntcf_ua_of \\<alpha> \\<FF> c r u :\n    Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<AA>(r,-) \\<mapsto>\\<^sub>C\\<^sub>F Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<BB>(c,-) \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> cat_Set \\<alpha>\"\nproof(intro is_ntcfI')\n  let ?ua = \\<open>ntcf_ua_of \\<alpha> \\<FF> c r u\\<close>\n  show \"vfsequence (ntcf_ua_of \\<alpha> \\<FF> c r u)\" unfolding ntcf_ua_of_def by simp\n  show \"vcard ?ua = 5\\<^sub>\\<nat>\" unfolding ntcf_ua_of_def by (simp add: nat_omega_simps)\n  from assms(1) show \"Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<AA>(r,-) : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> cat_Set \\<alpha>\"\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros)\n  from is_functor_axioms assms(2) show \n    \"Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<BB>(c,-) \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> cat_Set \\<alpha>\"\n    by (cs_concl cs_intro: cat_cs_intros)\n  from is_functor_axioms assms show \"\\<D>\\<^sub>\\<circ> (?ua\\<lparr>NTMap\\<rparr>) = \\<AA>\\<lparr>Obj\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: cat_cs_simps)\n  show \"?ua\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> :\n    Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<AA>(r,-)\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>cat_Set \\<alpha>\\<^esub> (Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<BB>(c,-) \\<circ>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n    if \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" for a\n    using is_functor_axioms assms that \n    by (cs_concl cs_simp: cat_cs_simps cat_op_simps cs_intro: cat_cs_intros)\n  show \"?ua\\<lparr>NTMap\\<rparr>\\<lparr>b\\<rparr> \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<AA>(r,-)\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> =\n    (Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<BB>(c,-) \\<circ>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> ?ua\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr>\"\n    if \"f : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b\" for a b f\n    using is_functor_axioms assms that \n    by \n      ( \n        cs_concl \n          cs_simp: cf_umap_of_cf_hom_commute cat_cs_simps cat_op_simps \n          cs_intro: cat_cs_intros cat_op_intros\n      )\nqed (auto simp: ntcf_ua_of_components cat_cs_simps)\n\nlemma (in is_functor) cf_ntcf_ua_fo_is_ntcf:\n  assumes \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" and \"u : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\"\n  shows \"ntcf_ua_fo \\<alpha> \\<FF> c r u :\n    Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<AA>(-,r) \\<mapsto>\\<^sub>C\\<^sub>F Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<BB>(-,c) \\<circ>\\<^sub>C\\<^sub>F op_cf \\<FF> :\n    op_cat \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> cat_Set \\<alpha>\"\nproof-\n  from assms(2) have c: \"c \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" by auto\n  show ?thesis\n    by \n      (\n        rule is_functor.cf_ntcf_ua_of_is_ntcf\n          [\n            OF is_functor_op, \n            unfolded cat_op_simps, \n            OF assms(1,2),\n            unfolded \n              HomDom.cat_op_cat_cf_Hom_snd[OF assms(1)] \n              HomCod.cat_op_cat_cf_Hom_snd[OF c]\n              ntcf_ua_fo_def[symmetric]\n          ]\n      )\nqed\n\n\nsubsubsection\\<open>Universal natural transformation and universal arrow\\<close>\n\n\ntext\\<open>\nThe lemmas in this subsection correspond to \nvariants of elements of Proposition 1 in Chapter III-2 in \n\\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>.\n\\<close>\n\nlemma (in is_functor) cf_ntcf_ua_of_is_iso_ntcf:\n  assumes \"universal_arrow_of \\<FF> c r u\"\n  shows \"ntcf_ua_of \\<alpha> \\<FF> c r u :\n    Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<AA>(r,-) \\<mapsto>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>i\\<^sub>s\\<^sub>o Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<BB>(c,-) \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> cat_Set \\<alpha>\"\nproof-\n\n  have r: \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n    and u: \"u : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\"\n    and bij: \"\\<And>r' u'.\n      \\<lbrakk>\n        r' \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>; \n        u' : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr>\n      \\<rbrakk> \\<Longrightarrow> \\<exists>!f'. f' : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r' \\<and> u' = umap_of \\<FF> c r u r'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\n    by (auto intro!: universal_arrow_ofD[OF assms(1)])\n\n  show ?thesis\n  proof(intro is_iso_ntcfI)\n    show \"ntcf_ua_of \\<alpha> \\<FF> c r u :\n      Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<AA>(r,-) \\<mapsto>\\<^sub>C\\<^sub>F Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<BB>(c,-) \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> cat_Set \\<alpha>\"\n      by (rule cf_ntcf_ua_of_is_ntcf[OF r u])\n    fix a assume prems: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n    from is_functor_axioms prems r u have [simp]:\n      \"umap_of \\<FF> c r u a : Hom \\<AA> r a \\<mapsto>\\<^bsub>cat_Set \\<alpha>\\<^esub> Hom \\<BB> c (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>)\"\n      by (cs_concl cs_shallow cs_intro: cat_cs_intros)\n    then have dom: \"\\<D>\\<^sub>\\<circ> (umap_of \\<FF> c r u a\\<lparr>ArrVal\\<rparr>) = Hom \\<AA> r a\"\n      by (cs_concl cs_simp: cat_cs_simps)\n    have \"umap_of \\<FF> c r u a : Hom \\<AA> r a \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>cat_Set \\<alpha>\\<^esub> Hom \\<BB> c (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>)\"\n    proof(intro cat_Set_is_iso_arrI, unfold dom)\n \n      show umof_a: \"v11 (umap_of \\<FF> c r u a\\<lparr>ArrVal\\<rparr>)\"\n      proof(intro vsv.vsv_valeq_v11I, unfold dom in_Hom_iff)\n        fix g f assume prems': \n          \"g : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a\"\n          \"f : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a\" \n          \"umap_of \\<FF> c r u a\\<lparr>ArrVal\\<rparr>\\<lparr>g\\<rparr> = umap_of \\<FF> c r u a\\<lparr>ArrVal\\<rparr>\\<lparr>f\\<rparr>\"\n        from is_functor_axioms r u prems'(1) have \\<FF>g:\n          \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> u : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n          by (cs_concl cs_shallow cs_intro: cat_cs_intros)\n        from bij[OF prems \\<FF>g] have unique:\n          \"\\<lbrakk>\n            f' : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a;\n            \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> u = umap_of \\<FF> c r u a\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr> \n           \\<rbrakk> \\<Longrightarrow> g = f'\"\n          for f' by (metis prems'(1) u umap_of_ArrVal_app)\n        from is_functor_axioms prems'(1,2) u have \\<FF>g_u:\n          \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> u = umap_of \\<FF> c r u a\\<lparr>ArrVal\\<rparr>\\<lparr>f\\<rparr>\"\n          by (cs_concl cs_simp: prems'(3)[symmetric] cat_cs_simps)\n        show \"g = f\" by (rule unique[OF prems'(2) \\<FF>g_u])\n      qed (auto simp: cat_cs_simps cat_cs_intros)\n\n      interpret umof_a: v11 \\<open>umap_of \\<FF> c r u a\\<lparr>ArrVal\\<rparr>\\<close> by (rule umof_a)\n\n      show \"\\<R>\\<^sub>\\<circ> (umap_of \\<FF> c r u a\\<lparr>ArrVal\\<rparr>) = Hom \\<BB> c (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>)\"\n      proof(intro vsubset_antisym)\n        from u show \"\\<R>\\<^sub>\\<circ> (umap_of \\<FF> c r u a\\<lparr>ArrVal\\<rparr>) \\<subseteq>\\<^sub>\\<circ> Hom \\<BB> c (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>)\"\n          by (rule umap_of_ArrVal_vrange)\n        show \"Hom \\<BB> c (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (umap_of \\<FF> c r u a\\<lparr>ArrVal\\<rparr>)\"\n        proof(rule vsubsetI, unfold in_Hom_iff )\n          fix f assume prems': \"f : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n          from bij[OF prems prems'] obtain f' \n            where f': \"f' : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a\" \n              and f_def: \"f = umap_of \\<FF> c r u a\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\n            by auto\n          from is_functor_axioms prems prems' u f' have \n            \"f' \\<in>\\<^sub>\\<circ> \\<D>\\<^sub>\\<circ> (umap_of \\<FF> c r u a\\<lparr>ArrVal\\<rparr>)\"\n            by (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n          from this show \"f \\<in>\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (umap_of \\<FF> c r u a\\<lparr>ArrVal\\<rparr>)\"\n            unfolding f_def by (rule umof_a.vsv_vimageI2)\n        qed\n\n      qed\n\n    qed simp_all\n\n    from is_functor_axioms prems r u this show \n      \"ntcf_ua_of \\<alpha> \\<FF> c r u\\<lparr>NTMap\\<rparr>\\<lparr>a\\<rparr> :\n        Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<AA>(r,-)\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>cat_Set \\<alpha>\\<^esub>\n        (Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<BB>(c,-) \\<circ>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n      by \n        (\n          cs_concl  \n            cs_simp: cat_cs_simps cat_op_simps \n            cs_intro: cat_cs_intros cat_op_intros\n        )\n  qed\n\nqed\n\nlemmas [cat_cs_intros] = is_functor.cf_ntcf_ua_of_is_iso_ntcf\n\nlemma (in is_functor) cf_ntcf_ua_fo_is_iso_ntcf:\n  assumes \"universal_arrow_fo \\<FF> c r u\"\n  shows \"ntcf_ua_fo \\<alpha> \\<FF> c r u :\n    Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<AA>(-,r) \\<mapsto>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>i\\<^sub>s\\<^sub>o Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<BB>(-,c) \\<circ>\\<^sub>C\\<^sub>F op_cf \\<FF> :\n    op_cat \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> cat_Set \\<alpha>\"\nproof-\n  from universal_arrow_foD[OF assms] have r: \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" and c: \"c \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n    by auto\n  show ?thesis\n    by \n      (\n        rule is_functor.cf_ntcf_ua_of_is_iso_ntcf\n          [\n            OF is_functor_op, \n            unfolded cat_op_simps, \n            OF assms,\n            unfolded \n              HomDom.cat_op_cat_cf_Hom_snd[OF r] \n              HomCod.cat_op_cat_cf_Hom_snd[OF c]\n              ntcf_ua_fo_def[symmetric]\n          ]\n      ) \nqed\n\nlemmas [cat_cs_intros] = is_functor.cf_ntcf_ua_fo_is_iso_ntcf\n\nlemma (in is_functor) cf_ua_of_if_ntcf_ua_of_is_iso_ntcf:\n  assumes \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n    and \"u : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\"\n    and \"ntcf_ua_of \\<alpha> \\<FF> c r u :\n      Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<AA>(r,-) \\<mapsto>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>i\\<^sub>s\\<^sub>o Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<BB>(c,-) \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> cat_Set \\<alpha>\"\n  shows \"universal_arrow_of \\<FF> c r u\"\nproof(rule universal_arrow_ofI)\n  interpret ua_of_u: is_iso_ntcf \n    \\<alpha> \n    \\<AA> \n    \\<open>cat_Set \\<alpha>\\<close>\n    \\<open>Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<AA>(r,-)\\<close> \n    \\<open>Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<BB>(c,-) \\<circ>\\<^sub>C\\<^sub>F \\<FF>\\<close> \n    \\<open>ntcf_ua_of \\<alpha> \\<FF> c r u\\<close>\n    by (rule assms(3))\n  fix r' u' assume prems: \"r' \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \"u' : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr>\"  \n  have \"ntcf_ua_of \\<alpha> \\<FF> c r u\\<lparr>NTMap\\<rparr>\\<lparr>r'\\<rparr> :\n    Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<AA>(r,-)\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr> \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>cat_Set \\<alpha>\\<^esub>\n    (Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<BB>(c,-) \\<circ>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr>\"\n    by (rule is_iso_ntcf.iso_ntcf_is_iso_arr[OF assms(3) prems(1)])\n  from this is_functor_axioms assms(1-2) prems have uof_r':\n    \"umap_of \\<FF> c r u r' : Hom \\<AA> r r' \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>cat_Set \\<alpha>\\<^esub> Hom \\<BB> c (\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr>)\"\n    by (cs_prems cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_op_intros)\n  note uof_r' = cat_Set_is_iso_arrD[OF uof_r']  \n  interpret uof_r': v11 \\<open>umap_of \\<FF> c r u r'\\<lparr>ArrVal\\<rparr>\\<close> by (rule uof_r'(2))  \n  from \n    uof_r'.v11_vrange_ex1_eq[\n      THEN iffD1, unfolded uof_r'(3,4) in_Hom_iff, OF prems(2)\n      ] \n  show \"\\<exists>!f'. f' : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r' \\<and> u' = umap_of \\<FF> c r u r'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\n    by metis\nqed (intro assms)+\n\nlemma (in is_functor) cf_ua_fo_if_ntcf_ua_fo_is_iso_ntcf:\n  assumes \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n    and \"u : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\"\n    and \"ntcf_ua_fo \\<alpha> \\<FF> c r u :\n      Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<AA>(-,r) \\<mapsto>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>i\\<^sub>s\\<^sub>o Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<BB>(-,c) \\<circ>\\<^sub>C\\<^sub>F op_cf \\<FF> :\n      op_cat \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> cat_Set \\<alpha>\"\n  shows \"universal_arrow_fo \\<FF> c r u\"\nproof-\n  from assms(2) have c: \"c \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" by auto\n  show ?thesis\n    by \n      (\n        rule is_functor.cf_ua_of_if_ntcf_ua_of_is_iso_ntcf\n          [\n            OF is_functor_op, \n            unfolded cat_op_simps,\n            OF assms(1,2),\n            unfolded \n              HomDom.cat_op_cat_cf_Hom_snd[OF assms(1)] \n              HomCod.cat_op_cat_cf_Hom_snd[OF c]\n              ntcf_ua_fo_def[symmetric],\n            OF assms(3)\n          ]\n      )\nqed\n\nlemma (in is_functor) cf_universal_arrow_of_if_is_iso_ntcf:\n  assumes \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n    and \"c \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n    and \"\\<phi> :\n      Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<AA>(r,-) \\<mapsto>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>i\\<^sub>s\\<^sub>o Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<BB>(c,-) \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> cat_Set \\<alpha>\"\n  shows \"universal_arrow_of \\<FF> c r (\\<phi>\\<lparr>NTMap\\<rparr>\\<lparr>r\\<rparr>\\<lparr>ArrVal\\<rparr>\\<lparr>\\<AA>\\<lparr>CId\\<rparr>\\<lparr>r\\<rparr>\\<rparr>)\"\n    (is \\<open>universal_arrow_of \\<FF> c r ?u\\<close>)\nproof-\n\n  interpret \\<phi>: is_iso_ntcf \n    \\<alpha> \\<AA> \\<open>cat_Set \\<alpha>\\<close> \\<open>Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<AA>(r,-)\\<close> \\<open>Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<BB>(c,-) \\<circ>\\<^sub>C\\<^sub>F \\<FF>\\<close> \\<phi>\n    by (rule assms(3))\n\n  show ?thesis\n  proof(intro universal_arrow_ofI assms)\n \n    from assms(1,2) show u: \"?u : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\"\n      by \n        (\n          cs_concl cs_shallow  \n            cs_simp: cat_cs_simps cat_op_simps cs_intro: cat_cs_intros\n        )\n    fix r' u' assume prems: \"r' \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \"u' : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr>\"\n    have \\<phi>r'_ArrVal_app[symmetric, cat_cs_simps]:\n      \"\\<phi>\\<lparr>NTMap\\<rparr>\\<lparr>r'\\<rparr>\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr> =\n        \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<phi>\\<lparr>NTMap\\<rparr>\\<lparr>r\\<rparr>\\<lparr>ArrVal\\<rparr>\\<lparr>\\<AA>\\<lparr>CId\\<rparr>\\<lparr>r\\<rparr>\\<rparr>\"\n      if \"f' : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r'\" for f'\n    proof-\n      have \"\\<phi>\\<lparr>NTMap\\<rparr>\\<lparr>r'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<AA>(r,-)\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> =\n        (Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<BB>(c,-) \\<circ>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> \\<phi>\\<lparr>NTMap\\<rparr>\\<lparr>r\\<rparr>\"\n        using that by (intro \\<phi>.ntcf_Comp_commute)\n      then have \n        \"\\<phi>\\<lparr>NTMap\\<rparr>\\<lparr>r'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> cf_hom \\<AA> [\\<AA>\\<lparr>CId\\<rparr>\\<lparr>r\\<rparr>, f']\\<^sub>\\<circ> =\n          cf_hom \\<BB> [\\<BB>\\<lparr>CId\\<rparr>\\<lparr>c\\<rparr>, \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr>]\\<^sub>\\<circ> \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub> \\<phi>\\<lparr>NTMap\\<rparr>\\<lparr>r\\<rparr>\" \n        using assms(1,2) that prems\n        by \n          (\n            cs_prems cs_shallow \n              cs_simp: cat_cs_simps cat_op_simps cs_intro: cat_cs_intros\n          )\n      then have\n        \"(\\<phi>\\<lparr>NTMap\\<rparr>\\<lparr>r'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub>\n        cf_hom \\<AA> [\\<AA>\\<lparr>CId\\<rparr>\\<lparr>r\\<rparr>, f']\\<^sub>\\<circ>)\\<lparr>ArrVal\\<rparr>\\<lparr>\\<AA>\\<lparr>CId\\<rparr>\\<lparr>r\\<rparr>\\<rparr> =\n          (cf_hom \\<BB> [\\<BB>\\<lparr>CId\\<rparr>\\<lparr>c\\<rparr>, \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr>]\\<^sub>\\<circ> \\<circ>\\<^sub>A\\<^bsub>cat_Set \\<alpha>\\<^esub>\n          \\<phi>\\<lparr>NTMap\\<rparr>\\<lparr>r\\<rparr>)\\<lparr>ArrVal\\<rparr>\\<lparr>\\<AA>\\<lparr>CId\\<rparr>\\<lparr>r\\<rparr>\\<rparr>\"\n         by simp\n      from this assms(1,2) u that show ?thesis\n        by\n          (\n            cs_prems cs_shallow\n              cs_simp: cat_cs_simps cat_op_simps \n              cs_intro: cat_cs_intros cat_op_intros cat_prod_cs_intros\n          )\n    qed \n    \n    show \"\\<exists>!f'. f' : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r' \\<and> u' = umap_of \\<FF> c r ?u r'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\n    proof(intro ex1I conjI; (elim conjE)?)\n      from assms prems show \n        \"(\\<phi>\\<lparr>NTMap\\<rparr>\\<lparr>r'\\<rparr>)\\<inverse>\\<^sub>C\\<^bsub>cat_Set \\<alpha>\\<^esub>\\<lparr>ArrVal\\<rparr>\\<lparr>u'\\<rparr> : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r'\"\n        by\n          (\n            cs_concl \n              cs_simp: cat_cs_simps cat_op_simps\n              cs_intro: cat_cs_intros cat_arrow_cs_intros\n          )\n      with assms(1,2) prems show \"u' =\n        umap_of \\<FF> c r ?u r'\\<lparr>ArrVal\\<rparr>\\<lparr>(\\<phi>\\<lparr>NTMap\\<rparr>\\<lparr>r'\\<rparr>)\\<inverse>\\<^sub>C\\<^bsub>cat_Set \\<alpha>\\<^esub>\\<lparr>ArrVal\\<rparr>\\<lparr>u'\\<rparr>\\<rparr>\"\n        by\n          (\n            cs_concl cs_shallow\n              cs_simp: cat_cs_simps cat_op_simps\n              cs_intro: cat_arrow_cs_intros cat_cs_intros cat_op_intros\n          )\n      fix f' assume prems': \n        \"f' : r \\<mapsto>\\<^bsub>\\<AA>\\<^esub> r'\"\n        \"u' = umap_of \\<FF> c r (\\<phi>\\<lparr>NTMap\\<rparr>\\<lparr>r\\<rparr>\\<lparr>ArrVal\\<rparr>\\<lparr>\\<AA>\\<lparr>CId\\<rparr>\\<lparr>r\\<rparr>\\<rparr>) r'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\n      from prems'(2,1) assms(1,2) have u'_def: \n        \"u' = \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<phi>\\<lparr>NTMap\\<rparr>\\<lparr>r\\<rparr>\\<lparr>ArrVal\\<rparr>\\<lparr>\\<AA>\\<lparr>CId\\<rparr>\\<lparr>r\\<rparr>\\<rparr>\"\n        by\n          (\n            cs_prems cs_shallow\n              cs_simp: cat_cs_simps cat_op_simps\n              cs_intro: cat_cs_intros cat_op_intros\n          )\n      from prems' show \"f' = (\\<phi>\\<lparr>NTMap\\<rparr>\\<lparr>r'\\<rparr>)\\<inverse>\\<^sub>C\\<^bsub>cat_Set \\<alpha>\\<^esub>\\<lparr>ArrVal\\<rparr>\\<lparr>u'\\<rparr>\"\n        unfolding u'_def \\<phi>r'_ArrVal_app[OF prems'(1)]\n        by\n          (\n            cs_concl \n              cs_simp: cat_cs_simps\n              cs_intro: cat_arrow_cs_intros cat_cs_intros cat_op_intros\n          )\n\n    qed\n\n  qed\n\nqed\n\nlemma (in is_functor) cf_universal_arrow_fo_if_is_iso_ntcf:\n  assumes \"r \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n    and \"c \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n    and \"\\<phi> :\n      Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<AA>(-,r) \\<mapsto>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>i\\<^sub>s\\<^sub>o Hom\\<^sub>O\\<^sub>.\\<^sub>C\\<^bsub>\\<alpha>\\<^esub>\\<BB>(-,c) \\<circ>\\<^sub>C\\<^sub>F op_cf \\<FF> :\n      op_cat \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> cat_Set \\<alpha>\"\n  shows \"universal_arrow_fo \\<FF> c r (\\<phi>\\<lparr>NTMap\\<rparr>\\<lparr>r\\<rparr>\\<lparr>ArrVal\\<rparr>\\<lparr>\\<AA>\\<lparr>CId\\<rparr>\\<lparr>r\\<rparr>\\<rparr>)\"\n  by\n    (\n      rule is_functor.cf_universal_arrow_of_if_is_iso_ntcf\n        [\n          OF is_functor_op,\n          unfolded cat_op_simps,\n          OF assms(1,2),\n          unfolded \n            HomDom.cat_op_cat_cf_Hom_snd[OF assms(1)] \n            HomCod.cat_op_cat_cf_Hom_snd[OF assms(2)]\n            ntcf_ua_fo_def[symmetric],\n          OF assms(3)\n        ]\n  )\n\ntext\\<open>\\newpage\\<close>\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/CZH_Universal_Constructions/czh_ucategories/CZH_UCAT_Universal.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5506073802837478, "lm_q2_score": 0.5350984286266116, "lm_q1q2_score": 0.29462914398004864}}
{"text": "(*<*)\n(*\n * Knowledge-based programs.\n * (C)opyright 2011, Peter Gammie, peteg42 at gmail.com.\n * License: BSD\n *)\n\ntheory KBPs\nimports Kripke Traces\nbegin\n(*>*)\n\nsection\\<open>Knowledge-based Programs\\<close>\n\ntext \\<open>\n\n\\label{sec:kbps-theory-kbps-semantics}\n\nA knowledge-based programs (KBPs) encodes the dependency of action on\nknowledge by a sequence of guarded commands, and a \\emph{joint\nknowledge-based program} (JKBP) assigns a KBP to each agent:\n\n\\<close>\n\nrecord ('a, 'p, 'aAct) GC =\n  guard  :: \"('a, 'p) Kform\"\n  action :: \"'aAct\"\n\ntype_synonym ('a, 'p, 'aAct) KBP = \"('a, 'p, 'aAct) GC list\"\ntype_synonym ('a, 'p, 'aAct) JKBP = \"'a \\<Rightarrow> ('a, 'p, 'aAct) KBP\"\n\ntext\\<open>\n\nWe use a list of guarded commands just so we can reuse this definition\nand others in algorithmic contexts; we would otherwise use a set as\nthere is no problem with infinite programs or actions, and we always\nignore the sequential structure.\n\nIntuitively a KBP for an agent cannot directly evaluate the truth of\nan arbitrary formula as it may depend on propositions that the agent\nhas no certainty about. For example, a card-playing agent cannot\ndetermine which cards are in the deck, despite being sure that those\nin her hand are not. Conversely agent $a$ can evaluate formulas of the\nform @{term \"\\<^bold>K\\<^sub>a \\<phi>\"} as these depend only on the worlds the agent thinks\nis possible.\n\nThus we restrict the guards of the JKBP to be boolean combinations of\n\\emph{subjective} formulas:\n\n\\<close>\n\nfun subjective :: \"'a \\<Rightarrow> ('a, 'p) Kform \\<Rightarrow> bool\" where\n  \"subjective a (Kprop p)      = False\"\n| \"subjective a (Knot f)       = subjective a f\"\n| \"subjective a (Kand f g)     = (subjective a f \\<and> subjective a g)\"\n| \"subjective a (Kknows a' f)  = (a = a')\"\n| \"subjective a (Kcknows as f) = (a \\<in> set as)\"\n\ntext\\<open>\n\nAll JKBPs in the following sections are assumed to be subjective.\n\nThis syntactic restriction implies the desired semantic property, that\nwe can evaluate a guard at an arbitrary world that is compatible with\na given observation \\citep[\\S3]{DBLP:journals/dc/FaginHMV97}.\n\n\\<close>\n\nlemma S5n_subjective_eq:\n  assumes S5n: \"S5n M\"\n  assumes subj: \"subjective a \\<phi>\"\n  assumes ww': \"(w, w') \\<in> relations M a\"\n  shows \"M, w \\<Turnstile> \\<phi> \\<longleftrightarrow> M, w' \\<Turnstile> \\<phi>\"\n(*<*)\nusing subj ww'\nproof(induct \\<phi> rule: subjective.induct[case_names Kprop Knot Kand Kknows Kcknows])\n  case (Kcknows a as \\<phi>)\n  hence \"(w, w') \\<in> (\\<Union>a\\<in>set as. relations M a)\\<^sup>+\" by auto\n  with Kcknows S5n show ?case by (auto dest: S5n_tc_rels_eq)\nqed (auto dest: S5n_rels_eq[OF S5n])\n\n(*>*)\ntext\\<open>\n\nThe proof is by induction over the formula @{term \"\\<phi>\"}, using the\nproperties of $S5_n$ Kripke structures in the knowledge cases.\n\nWe capture the fixed but arbitrary JKBP using a locale, and work in\nthis context for the rest of this section.\n\n\\<close>\n\nlocale JKBP =\n  fixes jkbp :: \"('a, 'p, 'aAct) JKBP\"\n  assumes subj: \"\\<forall>a gc. gc \\<in> set (jkbp a) \\<longrightarrow> subjective a (guard gc)\"\n\ncontext JKBP\nbegin\n\ntext\\<open>\n\nThe action of the JKBP at a world is the list of all actions that are\nenabled at that world:\n\n\\<close>\n\ndefinition jAction :: \"('a, 'p, 'w) KripkeStructure \\<Rightarrow> 'w \\<Rightarrow> 'a \\<Rightarrow> 'aAct list\"\nwhere \"jAction \\<equiv> \\<lambda>M w a. [ action gc. gc \\<leftarrow> jkbp a, M, w \\<Turnstile> guard gc ]\"\n\ntext\\<open>\n\nAll of our machinery on Kripke structures lifts from the models\nrelation of \\S\\ref{sec:kbps-logic-of-knowledge} through @{term\n\"jAction\"}, due to the subjectivity requirement. In particular, the\nKBP for agent $a$ behaves the same at worlds that $a$ cannot\ndistinguish amongst:\n\n\\<close>\n\nlemma S5n_jAction_eq:\n  assumes S5n: \"S5n M\"\n  assumes ww': \"(w, w') \\<in> relations M a\"\n  shows \"jAction M w a = jAction M w' a\"\n(*<*)\nproof -\n  { fix gc assume \"gc \\<in> set (jkbp a)\"\n    with subj have \"subjective a (guard gc)\" by auto\n    with S5n ww' have \"M, w \\<Turnstile> guard gc = M, w' \\<Turnstile> guard gc\"\n      by - (rule S5n_subjective_eq, simp_all) }\n  thus ?thesis\n    unfolding jAction_def\n    by - (rule arg_cong[where f=concat], simp)\nqed\n(*>*)\n\ntext\\<open>\n\nAlso the JKBP behaves the same on relevant generated models for all\nagents:\n\n\\<close>\n\nlemma gen_model_jAction_eq:\n  assumes S: \"gen_model M w = gen_model M' w\"\n  assumes w': \"w' \\<in> worlds (gen_model M' w)\"\n  assumes M: \"kripke M\"\n  assumes M': \"kripke M'\"\n  shows \"jAction M w' = jAction M' w'\"\n(*<*)\n  unfolding jAction_def\n  by (auto iff: gen_model_eq[OF M M' S w'])\n(*>*)\n\ntext\\<open>\n\nFinally, @{term \"jAction\"} is invariant under simulations:\n\n\\<close>\n\nlemma simulation_jAction_eq:\n  assumes M: \"kripke M\"\n  assumes sim: \"sim M M' f\"\n  assumes w: \"w \\<in> worlds M\"\n  shows \"jAction M w = jAction M' (f w)\"\n(*<*)\n  unfolding jAction_def\n  using assms by (auto iff: sim_semantic_equivalence)\n(*>*)\n\nend\n\nsection\\<open>Environments and Views\\<close>\n\ntext\\<open>\n\n\\label{sec:kbps-theory-environments}\n\nThe previous section showed how a JKBP can be interpreted statically,\nwith respect to a fixed Kripke structure. As we also wish to capture\nhow agents interact, we adopt the \\emph{interpreted systems} and\n\\emph{contexts} of \\cite{FHMV:1995}, which we term \\emph{environments}\nfollowing \\cite{Ron:1996}.\n\nA \\emph{pre-environment} consists of the following:\n\\begin{itemize}\n\n\\item @{term \"envInit\"}, an arbitrary set of initial states;\n\n\\item The protocol of the environment @{term \"envAction\"}, which\n  depends on the current state;\n\n\\item A transition function @{term \"envTrans\"}, which incorporates the\n  environment's action and agents' behaviour into a state change; and\n\n\\item A propositional evaluation function @{term \"envVal\"}.\n\n\\end{itemize}\nWe extend the @{term \"JKBP\"} locale with these constants:\n\n\\<close>\n\nlocale PreEnvironment = JKBP jkbp for jkbp :: \"('a, 'p, 'aAct) JKBP\"\n+ fixes envInit :: \"'s list\"\n    and envAction :: \"'s \\<Rightarrow> 'eAct list\"\n    and envTrans :: \"'eAct \\<Rightarrow> ('a \\<Rightarrow> 'aAct) \\<Rightarrow> 's \\<Rightarrow> 's\"\n    and envVal :: \"'s \\<Rightarrow> 'p \\<Rightarrow> bool\"\n\ntext\\<open>\n\n\\label{sec:kbps-views}\n\nWe represent the possible evolutions of the system as finite sequences\nof states, represented by a left-recursive type @{typ \"'s Trace\"} with\nconstructors @{term \"tInit s\"} and @{term \"t \\<leadsto> s\"}, equipped with\n@{term \"tFirst\"}, @{term \"tLast\"}, @{term \"tLength\"} and @{term\n\"tMap\"} functions.\n\nConstructing these traces requires us to determine the agents' actions\nat a given state. To do so we need to find an appropriate S$5_n$\nstructure for interpreting @{term \"jkbp\"}.\n\nGiven that we want the agents to make optimal use of the information\nthey have access to, we allow these structures to depend on the entire\nhistory of the system, suitably conditioned by what the agents can\nobserve. We capture this notion of observation with a \\emph{view}\n\\citep{Ron:1996}, which is an arbitrary function of a trace:\n\n\\<close>\n\ntype_synonym ('s, 'tview) View = \"'s Trace \\<Rightarrow> 'tview\"\ntype_synonym ('a, 's, 'tview) JointView = \"'a \\<Rightarrow> 's Trace \\<Rightarrow> 'tview\"\n\ntext\\<open>\n\n\\label{sec:kbps-synchrony}\n\nWe require views to be \\emph{synchronous}, i.e. that agents be able to\ntell the time using their view by distinguishing two traces of\ndifferent lengths. As we will see in the next section, this guarantees\nthat the JKBP has an essentially unique implementation.\n\nWe extend the @{term \"PreEnvironment\"} locale with a view:\n\n\\<close>\n\nlocale PreEnvironmentJView =\n  PreEnvironment jkbp envInit envAction envTrans envVal\n    for jkbp :: \"('a, 'p, 'aAct) JKBP\"\n    and envInit :: \"'s list\"\n    and envAction :: \"'s \\<Rightarrow> 'eAct list\"\n    and envTrans :: \"'eAct \\<Rightarrow> ('a \\<Rightarrow> 'aAct) \\<Rightarrow> 's \\<Rightarrow> 's\"\n    and envVal :: \"'s \\<Rightarrow> 'p \\<Rightarrow> bool\"\n+ fixes jview :: \"('a, 's, 'tview) JointView\"\n  assumes sync: \"\\<forall>a t t'. jview a t = jview a t' \\<longrightarrow> tLength t = tLength t'\"\n\ntext\\<open>\n\nThe two principle synchronous views are the clock view and the\nperfect-recall view which we discuss further in\n\\S\\ref{sec:kbps-theory-views}. We will later derive an agent's\nconcrete view from an instantaneous observation of the global state in\n\\S\\ref{sec:kbps-environments}.\n\nWe build a Kripke structure from a set of traces by relating traces\nthat yield the same view. To obtain an S$5_n$ structure we also need a\nway to evaluate propositions: we apply @{term \"envVal\"} to the final\nstate of a trace:\n\n\\<close>\n\ndefinition (in PreEnvironmentJView)\n  mkM :: \"'s Trace set \\<Rightarrow> ('a, 'p, 's Trace) KripkeStructure\"\nwhere\n  \"mkM T \\<equiv>\n      \\<lparr> worlds = T,\n        relations = \\<lambda>a. { (t, t') . {t, t'} \\<subseteq> T \\<and> jview a t = jview a t' },\n        valuation = envVal \\<circ> tLast \\<rparr>\"\n(*<*)\n\ncontext PreEnvironmentJView\nbegin\n\nlemma mkM_kripke[intro, simp]: \"kripke (mkM T)\"\n  unfolding mkM_def by (rule kripkeI) fastforce\n\nlemma mkM_S5n[intro, simp]: \"S5n (mkM T)\"\n  unfolding mkM_def\n  by (intro S5nI equivI)\n     (bestsimp intro: equivI refl_onI symI transI)+\n\nlemma mkM_simps[simp]:\n  \"worlds (mkM T) = T\"\n  \"\\<lbrakk> (t, t') \\<in> relations (mkM T) a \\<rbrakk> \\<Longrightarrow> jview a t = jview a t'\"\n  \"\\<lbrakk> (t, t') \\<in> relations (mkM T) a \\<rbrakk> \\<Longrightarrow> t \\<in> T\"\n  \"\\<lbrakk> (t, t') \\<in> relations (mkM T) a \\<rbrakk> \\<Longrightarrow> t' \\<in> T\"\n  \"valuation (mkM T) = envVal \\<circ> tLast\"\n  unfolding mkM_def by simp_all\n\nlemma mkM_rel_length[simp]:\n  assumes tt': \"(t, t') \\<in> relations (mkM T) a\"\n  shows \"tLength t' = tLength t\"\nproof -\n  from tt' have \"jview a t = jview a t'\" by simp\n  thus ?thesis by (bestsimp dest: sync[rule_format])\nqed\n\n(*>*)\ntext\\<open>\n\nThis construction supplants the role of the \\emph{local states} of\n\\citet{FHMV:1995}.\n\nThe following section shows how we can canonically interpret the JKBP\nwith respect to this structure.\n\n\\<close>\n\nsection\\<open>Canonical Structures\\<close>\n\ntext\\<open>\n\n\\label{sec:kbps-canonical-kripke}\n\nOur goal in this section is to find the canonical set of traces for a\ngiven JKBP in a particular environment. As we will see, this always\nexists with respect to synchronous views.\n\nWe inductively define an \\emph{interpretation} of a JKBP with respect\nto an arbitrary set of traces @{term \"T\"} by constructing a sequence\nof sets of traces of increasing length:\n\n\\<close>\n\nfun jkbpTn :: \"nat \\<Rightarrow> 's Trace set \\<Rightarrow> 's Trace set\"(*<*)(\"jkbpT\\<^bsub>_\\<^esub>\")(*>*) where\n  \"jkbpT\\<^bsub>0\\<^esub> T     = { tInit s |s. s \\<in> set envInit }\"\n| \"jkbpT\\<^bsub>Suc n\\<^esub> T = { t \\<leadsto> envTrans eact aact (tLast t) |t eact aact.\n                             t \\<in> jkbpT\\<^bsub>n\\<^esub> T \\<and> eact \\<in> set (envAction (tLast t))\n                          \\<and> (\\<forall>a. aact a \\<in> set (jAction (mkM T) t a)) }\"\n\ntext\\<open>\n\nThis model reflects the failure of any agent to provide an action as\nfailure of the entire system. In general @{term \"envTrans\"} may\nincorporate a scheduler and communication failure models.\n\nThe union of this sequence gives us a closure property:\n\n\\<close>\n\ndefinition jkbpT :: \"'s Trace set \\<Rightarrow> 's Trace set\" where\n  \"jkbpT T \\<equiv> \\<Union>n. jkbpT\\<^bsub>n\\<^esub> T\"\n(*<*)\n\nlemma jkbpTn_length:\n  \"t \\<in> jkbpTn n T \\<Longrightarrow> tLength t = n\"\n  by (induct n arbitrary: t, auto)\n\nlemma jkbpT_tLength_inv:\n  \"\\<lbrakk> t \\<in> jkbpT T; tLength t = n \\<rbrakk> \\<Longrightarrow> t \\<in> jkbpTn n T\"\n  unfolding jkbpT_def\n  by (induct n arbitrary: t) (fastforce simp: jkbpTn_length)+\n\nlemma jkbpT_traces_of_length:\n   \"{ t \\<in> jkbpT T . tLength t = n } = jkbpTn n T\"\n  using jkbpT_tLength_inv\n  unfolding jkbpT_def by (bestsimp simp: jkbpTn_length)\n\n(*>*)\ntext\\<open>\n\nWe say that a set of traces @{term \"T\"} \\emph{represents} a JKBP if it\nis closed under @{term \"jkbpT\"}:\n\n\\<close>\n\ndefinition represents :: \"'s Trace set \\<Rightarrow> bool\" where\n  \"represents T \\<equiv> jkbpT T = T\"\n(*<*)\n\nlemma representsI:\n  \"jkbpT T = T \\<Longrightarrow> represents T\"\n  unfolding represents_def by simp\n\nlemma representsD:\n  \"represents T \\<Longrightarrow> jkbpT T = T\"\n  unfolding represents_def by simp\n\n(*>*)\ntext\\<open>\n\nThis is the vicious cycle that we break using our assumption that the\nview is synchronous. The key property of such views is that the\nsatisfaction of an epistemic formula is determined by the set of\ntraces in the model that have the same length. Lifted to @{term\n\"jAction\"}, we have:\n\n\\<close>\n\n(*<*)\nlemma sync_tLength_eq_trc:\n  assumes \"(t, t') \\<in> (\\<Union>a\\<in>as. relations (mkM T) a)\\<^sup>*\"\n  shows \"tLength t = tLength t'\"\n  using assms by (induct rule: rtrancl_induct) auto\n\nlemma sync_gen_model_tLength:\n  assumes traces: \"{ t \\<in> T . tLength t = n } = { t \\<in> T' . tLength t = n }\"\n      and tT: \"t \\<in> { t \\<in> T . tLength t = n }\"\n  shows \"gen_model (mkM T) t = gen_model (mkM T') t\"\n  apply(rule gen_model_subset[where T=\"{ t \\<in> T . tLength t = n }\"])\n  apply simp_all\n\n  (* t \\<in> T and t \\<in> T' *)\n  prefer 4\n  using tT\n  apply simp\n  prefer 4\n  using tT traces\n  apply simp\n\n  apply (unfold mkM_def)[1]\n  using tT traces\n  apply (auto)[1]\n\n  using tT\n  apply (auto dest: sync_tLength_eq_trc[where as=UNIV] kripke_rels_trc_worlds)[1]\n\n  using tT traces\n  apply (auto dest: sync_tLength_eq_trc[where as=UNIV] kripke_rels_trc_worlds)[1]\n\n  done\n\n(*>*)\nlemma sync_jview_jAction_eq:\n  assumes traces: \"{ t \\<in> T . tLength t = n } = { t \\<in> T' . tLength t = n }\"\n  assumes tT: \"t \\<in> { t \\<in> T . tLength t = n }\"\n  shows \"jAction (mkM T) t = jAction (mkM T') t\"\n(*<*)\n  apply (rule gen_model_jAction_eq[where w=t])\n  apply (rule sync_gen_model_tLength)\n  using assms\n  apply (auto intro: gen_model_world_refl)\n  done\n\n(*>*)\ntext\\<open>\n\nThis implies that for a synchronous view we can inductively define the\n\\emph{canonical traces} of a JKBP. These are the traces that a JKBP\ngenerates when it is interpreted with respect to those very same\ntraces. We do this by constructing the sequence \\<open>jkbpC\\<^sub>n\\<close> of\n\\emph{(canonical) temporal slices} similarly to @{term \"jkbpT\\<^bsub>n\\<^esub>\"}:\n\n\\<close>\n\nfun jkbpCn :: \"nat \\<Rightarrow> 's Trace set\"(*<*)(\"jkbpC\\<^bsub>_\\<^esub>\")(*>*) where\n  \"jkbpC\\<^bsub>0\\<^esub>      = { tInit s |s. s \\<in> set envInit }\"\n| \"jkbpC\\<^bsub>Suc n\\<^esub> = { t \\<leadsto> envTrans eact aact (tLast t) |t eact aact.\n                             t \\<in> jkbpC\\<^bsub>n\\<^esub> \\<and> eact \\<in> set (envAction (tLast t))\n                          \\<and> (\\<forall>a. aact a \\<in> set (jAction (mkM jkbpC\\<^bsub>n\\<^esub>) t a)) }\"\n\nabbreviation MCn :: \"nat \\<Rightarrow> ('a, 'p, 's Trace) KripkeStructure\"(*<*)(\"MC\\<^bsub>_\\<^esub>\")(*>*) where\n  \"MC\\<^bsub>n\\<^esub> \\<equiv> mkM jkbpC\\<^bsub>n\\<^esub>\"\n(*<*)\n\nlemma jkbpCn_step_inv:\n  \"t \\<leadsto> s \\<in> jkbpCn (Suc n) \\<Longrightarrow> t \\<in> jkbpCn n\"\n  by (induct n arbitrary: t, (fastforce simp add: Let_def)+)\n\nlemma jkbpCn_length[simp]:\n  \"t \\<in> jkbpCn n \\<Longrightarrow> tLength t = n\"\n  by (induct n arbitrary: t, (fastforce simp add: Let_def)+)\n\nlemma jkbpCn_init_inv[intro]:\n  \"tInit s \\<in> jkbpCn n \\<Longrightarrow> s \\<in> set envInit\"\n   by (frule jkbpCn_length) auto\n\nlemma jkbpCn_tFirst_init_inv[intro]:\n \"t \\<in> jkbpCn n \\<Longrightarrow> tFirst t \\<in> set envInit\"\n  by (induct n arbitrary: t) (auto iff: Let_def)\n\n(*>*)\ntext\\<open>\n\nThe canonical set of traces for a JKBP with respect to a joint view is\nthe set of canonical traces of all lengths.\n\n\\<close>\n\ndefinition jkbpC :: \"'s Trace set\" where\n  \"jkbpC \\<equiv> \\<Union>n. jkbpC\\<^bsub>n\\<^esub>\"\n\nabbreviation MC :: \"('a, 'p, 's Trace) KripkeStructure\" where\n  \"MC \\<equiv> mkM jkbpC\"\n(*<*)\n\nlemma jkbpCn_jkbpC_subset:\n  \"jkbpCn n \\<subseteq> jkbpC\"\n  unfolding jkbpC_def by blast\n\nlemma jkbpCn_jkbpC_inc[intro]:\n  \"t \\<in> jkbpCn n \\<Longrightarrow> t \\<in> jkbpC\"\n  unfolding jkbpC_def by best\n\nlemma jkbpC_tLength_inv[intro]:\n  \"\\<lbrakk> t \\<in> jkbpC; tLength t = n \\<rbrakk> \\<Longrightarrow> t \\<in> jkbpCn n\"\n  unfolding jkbpC_def\n  by (induct n arbitrary: t, (fastforce simp add: Let_def)+)\n\nlemma jkbpC_traces_of_length:\n   \"{ t \\<in> jkbpC . tLength t = n } = jkbpCn n\"\n  unfolding jkbpC_def by bestsimp\n\nlemma jkbpC_prefix_closed[dest]:\n  \"t \\<leadsto> s \\<in> jkbpC \\<Longrightarrow> t \\<in> jkbpC\"\n  apply (drule jkbpC_tLength_inv)\n   apply simp\n  apply (auto iff: Let_def jkbpC_def)\n  done\n\nlemma jkbpC_init[iff]:\n  \"tInit s \\<in> jkbpC \\<longleftrightarrow> s \\<in> set envInit\"\n  unfolding jkbpC_def\n  apply rule\n   apply fast\n  apply (subgoal_tac \"tInit s \\<in> jkbpCn 0\")\n   apply simp\n  apply (rule_tac x=0 in exI)\n  apply simp_all\n  done\n\nlemma jkbpC_jkbpCn_rels:\n  \"\\<lbrakk> (u, v) \\<in> relations MC a; tLength u = n \\<rbrakk>\n    \\<Longrightarrow> (u, v) \\<in> relations (MC\\<^bsub>n\\<^esub>) a\"\n  unfolding mkM_def by (fastforce dest: sync[rule_format])\n\nlemma jkbpC_tFirst_init_inv[intro]:\n  \"t \\<in> jkbpC \\<Longrightarrow> tFirst t \\<in> set envInit\"\n  unfolding jkbpC_def by blast\n\n(*>*)\ntext\\<open>\n\nWe can show that @{term \"jkbpC\"} represents the joint knowledge-based\nprogram @{term \"jkbp\"} with respect to @{term \"jview\"}:\n\n\\<close>\n\nlemma jkbpC_jkbpCn_jAction_eq:\n  assumes tCn: \"t \\<in> jkbpC\\<^bsub>n\\<^esub>\"\n  shows \"jAction MC t = jAction MC\\<^bsub>n\\<^esub> t\"\n(*<*)\n  using assms\n  by - (rule sync_jview_jAction_eq, auto iff: jkbpC_traces_of_length)\n\n(*>*)\ntext\\<open>\\<close>\n\n\n\ntext\\<open>\\<close>\n\ntheorem jkbpC_represents: \"represents jkbpC\"\n(*<*)\n  using jkbpTn_jkbpCn_represents\n  by (simp add: representsI jkbpC_def jkbpT_def)\n\n(*>*)\ntext\\<open>\n\nWe can show uniqueness too, by a similar argument:\n\n\\<close>\n\ntheorem jkbpC_represents_uniquely:\n  assumes repT: \"represents T\"\n  shows \"T = jkbpC\"\n(*<*)\nproof -\n  { fix n\n    have \"{ t \\<in> T . tLength t = n } = { t \\<in> jkbpC . tLength t = n }\"\n    proof(induct n)\n      case 0\n      from repT have F: \"{t \\<in> T. tLength t = 0} = jkbpTn 0 T\"\n        by - (subst jkbpT_traces_of_length[symmetric], simp add: representsD)\n      thus ?case by (simp add: jkbpC_traces_of_length)\n    next\n      case (Suc n)\n      hence indhyp: \"{t \\<in> T. tLength t = n} = jkbpCn n\"\n        by (simp add: jkbpC_traces_of_length)\n\n        (* F and H are very similar. *)\n      from repT have F: \"\\<And>n. jkbpTn n T = {t \\<in> T. tLength t = n}\"\n        by - (subst jkbpT_traces_of_length[symmetric], simp add: representsD)\n      from indhyp F have G: \"jkbpTn n T = jkbpCn n\"\n        by simp\n      from repT have H: \"\\<And>n. {t \\<in> T. tLength t = n} = {t \\<in> jkbpTn n T. tLength t = n}\"\n        by (subst representsD[OF repT, symmetric], auto iff: jkbpT_traces_of_length jkbpTn_length)\n      from F indhyp have ACTS:\n        \"\\<And>t. t \\<in> jkbpTn n T\n          \\<Longrightarrow> jAction (mkM T) t = jAction (MCn n) t\"\n        by - (rule sync_jview_jAction_eq[where n=\"n\"], auto)\n      show ?case\n        apply (auto iff: Let_def ACTS G H jkbpC_traces_of_length)\n        apply blast+\n        done\n    qed }\n  thus ?thesis by auto\nqed\n(*>*)\n\nend (* context PreEnvironmentJView *)\n\ntext\\<open>\n\nThus, at least with synchronous views, we are justified in talking\nabout \\emph{the} representation of a JKBP in a given environment. More\ngenerally these results are also valid for the more general notion of\n\\emph{provides witnesses} as shown by \\citet[Lemma 7.2.4]{FHMV:1995}\nand \\citet{DBLP:journals/dc/FaginHMV97}: it requires only that if a\nsubjective knowledge formula is false on a trace then there is a trace\nof the same length or less that bears witness to that effect. This is\na useful generalisation in asynchronous settings.\n\nThe next section shows how we can construct canonical representations\nof JKBPs using automata.\n\n\\<close>\n\n(*<*)\nend\n(*>*)\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Evaluation/KBPs/KBPs.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5506073655352404, "lm_q2_score": 0.5350984286266116, "lm_q1q2_score": 0.29462913608814545}}
{"text": "theory ReduceExp\n  imports SRRead\nbegin\n\n    (*\n        --- OVERVIEW ---\n          1. expression syntax\n          2. free variables / reduction\n          4. type system for expressions\n          4. disjoint environments [disj_env]\n          5. well-typed value lemmas [is_value, env_level, max_env_level]\n          6. well-typed s-expression lemmas [is_sexp, env_level, max_env_level]\n          7. well-typed free var lemmas [well_typed, free_vars]\n          8. well-typed manipulation lemmas [well_typed, add_env, rem_env, comb_env]\n    *)\n\n  \n    (* \n      ####################################\n        P3. reduction\n      ####################################\n    *)  \n \n    (* memory values *)\n  \ndatatype mem_value =\n  ArrValue \"p_exp list\"\n  | ChanSValue\n  | ChanRValue string\n    (* true if unique, false otherwise *)\n  (*| PairValue p_exp p_exp*) (*p_aff*)  \n  \ntype_synonym p_state = \"mem_value gen_env\"  \n  \nfun app_op :: \"p_op \\<Rightarrow> p_const \\<Rightarrow> p_exp \\<Rightarrow> bool\" where\n  \"app_op (I2Op f2) c e' = (\\<exists> i. c = IConst i \\<and> e' = OpExp (I1Op (f2 i)))\"\n| \"app_op (I1Op f1) c e' = (\\<exists> i. c = IConst i \\<and> e' = ConstExp (IConst (f1 i)))\"\n| \"app_op (C2Op f2) c e' = (\\<exists> i. c = IConst i \\<and> e' = OpExp (C1Op (f2 i)))\"\n| \"app_op (C1Op f1) c e' = (\\<exists> i. c = IConst i \\<and> e' = ConstExp (BConst (f1 i)))\"\n| \"app_op (R2Op f2) c e' = (\\<exists> b. c = BConst b \\<and> e' = OpExp (R1Op (f2 b)))\"\n| \"app_op (R1Op f1) c e' = (\\<exists> b. c = BConst b \\<and> e' = ConstExp (BConst (f1 b)))\"\n  \nfun new_array_dat :: \"int \\<Rightarrow> 'a \\<Rightarrow> 'a list\" where\n  \"new_array_dat i v = (if i \\<le> 0 then [] else v # (new_array_dat (i - 1) v))\"  \n  \ndefinition new_array :: \"int \\<Rightarrow> p_exp \\<Rightarrow> mem_value\" where\n  \"new_array i v = (ArrValue (new_array_dat i v))\"    \n  \nfun read_array where\n  \"read_array [] i = None\"\n| \"read_array (v # t) i = (if i = 0 then Some v else read_array t (i - 1))\"\n  \nfun write_array where\n  \"write_array [] i v' = None\"\n| \"write_array (v # t) i v' = (if i = 0 then Some (v' # t) else (case (write_array t (i - 1) v') of\n    None \\<Rightarrow> None\n  | Some t' \\<Rightarrow> Some (v # t')\n  ))\"\n  \n    (* in order to ensure that ownership transfer is safe, we require aggressive removal of permissions once\n      they are no longer needed. for this reason, every use is tracked as an action.  *)\ndatatype p_act =\n    (* - nothing *)\n  NoAct\n    (* - new resource, ##resources consumed to create the resource *)\n  | MakeAct string (*\"string set\"*)\n  | Mk2Act string string\n    (* - resource used, ##resources transferred to the resource *)\n  | UseAct string (*\"string set\"*)\n  \nfun ext_list where\n  \"ext_list [] v = [v]\"\n| \"ext_list (v' # t) v = v' # (ext_list t v)\"  \n  \n  \nfun app_con :: \"p_state \\<Rightarrow> p_const \\<Rightarrow> p_exp \\<Rightarrow> p_act \\<Rightarrow> p_state \\<times> p_exp \\<Rightarrow> bool\" where\n  \"app_con s EmptyArrayConst v ax (s', e') = (\\<exists> a. ax = MakeAct a \\<and> v = ConstExp UnitConst \\<and>\n    e' = VarExp a SelfRef \\<and> s' = add_env s a (ArrValue []) \\<and> fresh_var s a\n  )\"\n| \"app_con s NewChanConst v ax (s', e') = (\\<exists> c_s c_r. ax = Mk2Act c_s c_r \\<and> v = ConstExp UnitConst \\<and>\n    e' = (PairExp (VarExp c_s SelfRef) (VarExp c_r SelfRef)) \\<and> s' = add_env (add_env s c_s ChanSValue) c_r (ChanRValue c_s) \\<and>\n    fresh_var s c_s \\<and> fresh_var s c_r \\<and> c_s \\<noteq> c_r)\"\n| \"app_con s UnpackConst v ax (s', e') = (\\<exists> v1 v2 f. ax = NoAct \\<and> v = PairExp v1 v2 \\<and> s' = s \\<and>\n    e' = (LamExp f (AppExp (AppExp (VarExp f NoRef) v1) v2)) \\<and> f \\<notin> free_vars v \\<and> f \\<notin> ref_vars v)\"\n(*\n| \"app_con s ReadConst e ax (s', e') = (\\<exists> x a i v arr. ax = UseAct x \\<and> ack_full_exp x v e' \\<and>\n    e = PairExp (VarExp x a) (ConstExp (IConst i)) \\<and>\n    s (deref_name x a) = Some (ArrValue arr) \\<and> read_array arr i = Some v \\<and> s' = s\n  )\"\n| \"app_con s ExtArrayConst e ax (s', e') = (\\<exists> x a v arr. ax = UseAct x \\<and>\n    e = PairExp (VarExp x a) v \\<and> is_value v \\<and> s (deref_name x a) = Some (ArrValue arr) \\<and>\n    e' = VarExp x a \\<and> s' = add_env s (deref_name x a) (ArrValue (ext_list arr v))\n  )\"  *)\n  \n  (*\n| \"app_con s PairConst v ax (s', e') = (\\<exists> p. ax = MakeAct p \\<and>\n    e' = VarExp p True \\<and> s' = add_mem s p (LValue v) \\<and> fresh_var s p)\"\n\n\n| \"app_con s WriteConst (VarExp x True) NoAct (s', e') = (\\<exists> x2 a i v arr arr'. e' = ConstExp UnitConst \\<and>\n    s x = Some (PairValue (VarExp x2 True) v) \\<and> s x2 = Some (PairValue (VarExp a True) (ConstExp (IConst i))) \\<and>\n    s a = Some (ArrValue arr) \\<and> Some arr' = write_array arr i v \\<and> s' = add_mem s a (ArrValue arr')\n  )\"*)\n| \"app_con s c v a (s', e') = False\"\n  \ndefinition unit_exp where\n  \"unit_exp = ConstExp UnitConst\"  \n  \nfun app_cv :: \"p_state \\<Rightarrow> p_const \\<Rightarrow> p_exp \\<Rightarrow> p_exp \\<Rightarrow> p_act \\<Rightarrow> p_state \\<times> p_exp \\<Rightarrow> bool\" where\n  \"app_cv s ReadConst e ix ax (s', e') = (\\<exists> x a i v arr. e = VarExp x a \\<and> ix = ConstExp (IConst i) \\<and>\n    ax = UseAct x \\<and> s (deref_name x a) = Some (ArrValue arr) \\<and>\n    read_array arr i = Some v \\<and> ack_full_exp x v e' \\<and> s' = s)\"\n| \"app_cv s ExtArrayConst e v ax (s', e') = (\\<exists> x a arr. e = VarExp x a \\<and>\n    ax = UseAct x \\<and> s (deref_name x a) = Some (ArrValue arr) \\<and>\n    e' = e \\<and> s' = add_env s (deref_name x a) (ArrValue (ext_list arr v)))\"\n| \"app_cv s WriteConst e p ax (s', e') = (\\<exists> x a i v arr arr'. e = VarExp x a \\<and>\n    p = PairExp (ConstExp (IConst i)) v \\<and> ax = UseAct x \\<and>\n    s (deref_name x a) = Some (ArrValue arr) \\<and> Some arr' = write_array arr i v \\<and>\n    e' = unit_exp \\<and> s' = add_env s (deref_name x a) (ArrValue arr'))\"(*\n| \"app_cv s UnpackConst f p ax (s', e') = (\\<exists> v1 v2. v1 = f \\<and> p = PairExp v1 v2 \\<and>\n    ax = NoAct \\<and> s' = s \\<and> e' = AppExp (AppExp f v1) v2)\"*)\n\n| \"app_cv s c v1 v2 ax (s', e') = False\"  \n  \n  \ndatatype app_act =\n  LamApp\n  | FixApp\n  | ConstApp\n  | OpApp\n  | IfApp1\n  | IfApp2\n  | CVApp\n  (*| UnpackApp*)\n  \nfun app_red_exp :: \"app_act \\<Rightarrow> p_state \\<times> p_exp \\<Rightarrow> p_act \\<Rightarrow> p_state \\<times> p_exp \\<Rightarrow> bool\" where\n  \"app_red_exp LamApp (s, e) a (s', e') = (\\<exists> x ex v.\n    e = AppExp (LamExp x ex) v \\<and> a = NoAct \\<and> is_value v \\<and> safe_subst_exp ex x v e' \\<and> s = s')\"\n| \"app_red_exp FixApp (s, e) a (s', e') = (\\<exists> x ex. e = AppExp (ConstExp FixConst) (LamExp x ex) \\<and>\n  a = NoAct \\<and> safe_subst_exp ex x (AppExp (ConstExp FixConst) (LamExp x ex)) e' \\<and> s = s')\"\n| \"app_red_exp OpApp (s, e) a (s', e') = (\\<exists> xop c. e = AppExp (OpExp xop) (ConstExp c) \\<and>\n  a = NoAct \\<and> app_op xop c e' \\<and> s = s')\"\n| \"app_red_exp ConstApp (s, e) a (s', e') = (\\<exists> c v. e = AppExp (ConstExp c) v \\<and>\n  is_value v \\<and> app_con s c v a (s', e'))\"\n| \"app_red_exp CVApp (s, e) a (s', e') = (\\<exists> c v1 v2. e = AppExp (AppExp (ConstExp c) v1) v2 \\<and>\n  bin_const c \\<and> is_value v1 \\<and> is_value v2 \\<and> app_cv s c v1 v2 a (s', e'))\"\n  (*\n| \"app_red_exp UnpackApp (s, e) a (s', e') = (\\<exists> f v1 v2. e = AppExp (AppExp (ConstExp UnpackConst) f) (PairExp v1 v2) \\<and>\n    a = NoAct \\<and> is_value f \\<and> is_value v1 \\<and> is_value v2 \\<and> s' = s \\<and> e' = AppExp (AppExp f v1) v2)\"  *)\n| \"app_red_exp IfApp1 (s, e) a (s', e') = (\\<exists> e1 e2. e = IfExp (ConstExp (BConst True)) e1 e2 \\<and>\n  a = NoAct \\<and> e' = e1 \\<and> s = s')\"\n| \"app_red_exp IfApp2 (s, e) a (s', e') = (\\<exists> e1 e2. e = IfExp (ConstExp (BConst False)) e1 e2 \\<and>\n  a = NoAct \\<and> e' = e2 \\<and> s = s')\"\n  \n  (*\nfun red_exp :: \"p_state \\<times> p_exp \\<Rightarrow> p_act \\<Rightarrow> p_state \\<times> p_exp \\<Rightarrow> bool\" where\n  \"red_exp (s, e) a (s', e') = (app_red_exp (s, e) a (s', e') \\<or> (case e of\n    AppExp e1 e2 \\<Rightarrow> (\\<exists> e2'. AppExp e1 e2' = e' \\<and> red_exp (s, e2) a (s', e2')) \\<or>\n      (\\<exists> e1'. AppExp e1' e2 = e' \\<and> red_exp (s, e1) a (s', e1'))\n    | other \\<Rightarrow> False\n  ))\"*)  \n  \n    (* ##### basic reduction lemmas ##### *)\n  (*\nlemma app_red_exp_contain_env: \"\\<lbrakk> app_red_exp are (s1, e1) ax (s2, e2) \\<rbrakk> \\<Longrightarrow> contain_env s2 s1\"\n  apply (case_tac are)\n        apply (auto)\n        apply (rule_tac id_contain_env)\n       apply (rule_tac id_contain_env)\n      apply (case_tac c)\n                  apply (auto)\n        apply (rule_tac add_contain_env)\n        apply (simp add: fresh_var_def)\n       apply (rule_tac add_contain_env)\n    \n    \n      apply (rule_tac id_contain_env)\n     apply (rule_tac id_contain_env)\n    apply (rule_tac id_contain_env)\n   apply (rule_tac id_contain_env)\n  apply (rule_tac id_contain_env)\n  done  *)\n  \nend", "meta": {"author": "dcco", "repo": "perm_lang_ax1", "sha": "5742edc2c5db417002ed6b8acd159c522b3e6e38", "save_path": "github-repos/isabelle/dcco-perm_lang_ax1", "path": "github-repos/isabelle/dcco-perm_lang_ax1/perm_lang_ax1-5742edc2c5db417002ed6b8acd159c522b3e6e38/perm_unsafe_lift/ReduceExp.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.2945399082458839}}
{"text": "section \\<open> Designs parallel-by-merge \\<close>\n\ntheory utp_des_parallel\n  imports utp_des_prog\nbegin\n\nsubsection \\<open> Definitions \\<close>\n\ntext \\<open> We introduce the parametric design merge, which handles merging of the $ok$ variables, and\n  leaves the other variables to the parametrised \"inner\" merge predicate. As expected, a parallel\n  composition of designs can diverge whenever one of its arguments can. \\<close>\n\ndefinition des_merge :: \"(('\\<alpha>, '\\<beta>, '\\<gamma>) mrg, '\\<delta>) urel \\<Rightarrow> (('\\<alpha> des, '\\<beta> des, '\\<gamma> des) mrg, '\\<delta> des) urel\" (\"\\<^bold>D\\<^bold>M'(_')\") where\n[upred_defs]: \"\\<^bold>D\\<^bold>M(M) \\<equiv> (($0:ok \\<and> $1:ok \\<Rightarrow> $ok\\<acute> \\<and> $\\<^bold>v\\<^sub>D:0\\<acute> =\\<^sub>u $0:\\<^bold>v\\<^sub>D \\<and> $\\<^bold>v\\<^sub>D:1\\<acute> =\\<^sub>u $1:\\<^bold>v\\<^sub>D \\<and> $\\<^bold>v\\<^sub>D:<\\<acute> =\\<^sub>u $<:\\<^bold>v\\<^sub>D) ;; (true \\<turnstile>\\<^sub>n M))\"\n\ntext \\<open> Parallel composition is then defined via the above merge predicate and the standard UTP\n  parallel-by-merge operator. \\<close>\n\nabbreviation\n  dpar_by_merge :: \"('\\<alpha>, '\\<beta>) rel_des \\<Rightarrow> (('\\<alpha>, '\\<beta>, '\\<gamma>) mrg, '\\<delta>) urel \\<Rightarrow> ('\\<alpha>, '\\<gamma>) rel_des \\<Rightarrow> ('\\<alpha>, '\\<delta>) rel_des\" \n  (\"_ \\<parallel>\\<^sup>D\\<^bsub>_\\<^esub> _\" [85,0,86] 85)\n  where \"P \\<parallel>\\<^sup>D\\<^bsub>M\\<^esub> Q \\<equiv> P \\<parallel>\\<^bsub>\\<^bold>D\\<^bold>M(M)\\<^esub> Q\"\n\nsubsection \\<open> Theorems \\<close>\n\ntext \\<open> The design merge predicate is symmetric up to the inner merge predicate. \\<close>\n\nlemma swap_des_merge: \"swap\\<^sub>m ;; \\<^bold>D\\<^bold>M(M) = \\<^bold>D\\<^bold>M(swap\\<^sub>m ;; M)\"\n  by (rel_auto)\n\ntext \\<open> The following laws explain the meaning of a merge of two normal (@{term H3}) designs. \n  The postcondition is straightforward: we simply distribute the inner merge. However, the \n  precondition is more complex. We'd be forgiven for thinking it would simply be $p \\wedge q$, but\n  this does not account for the possibility of miraculous behaviour in either argument. When this\n  occurs, divergence is effectively overshadowed by miraculous behaviour, and so the precondition\n  needs to involve the relational preconditions of both the design commitments ($P$ and $Q$). \\<close>\n\nlemma ndes_par_aux: \n  \"(p \\<turnstile>\\<^sub>n P) \\<parallel>\\<^sup>D\\<^bsub>M\\<^esub> (q \\<turnstile>\\<^sub>n Q) =(\\<not> Pre(\\<not> p\\<^sup>< \\<and> (q\\<^sup>< \\<Rightarrow> Q)) \\<and> \\<not> Pre(\\<not> q\\<^sup>< \\<and> (p\\<^sup>< \\<Rightarrow> P))) \\<turnstile>\\<^sub>n (P \\<parallel>\\<^bsub>M\\<^esub> Q)\"\nproof -\n  have p2: \"(\\<lceil>p \\<turnstile>\\<^sub>n P\\<rceil>\\<^sub>0 \\<and> \\<lceil>q \\<turnstile>\\<^sub>n Q\\<rceil>\\<^sub>1 \\<and> $<\\<acute> =\\<^sub>u $\\<^bold>v) ;; \n            ($0:ok \\<and> $1:ok \\<Rightarrow> $ok\\<acute> \\<and> $\\<^bold>v\\<^sub>D:0\\<acute> =\\<^sub>u $0:\\<^bold>v\\<^sub>D \\<and> $\\<^bold>v\\<^sub>D:1\\<acute> =\\<^sub>u $1:\\<^bold>v\\<^sub>D \\<and> $\\<^bold>v\\<^sub>D:<\\<acute> =\\<^sub>u $<:\\<^bold>v\\<^sub>D)\n            = (\\<not> Pre(\\<not> p\\<^sup>< \\<and> (q\\<^sup>< \\<Rightarrow> Q)) \\<and> \\<not> Pre(\\<not> q\\<^sup>< \\<and> (p\\<^sup>< \\<Rightarrow> P))) \\<turnstile>\\<^sub>n (\\<lceil>P\\<rceil>\\<^sub>0 \\<and> \\<lceil>Q\\<rceil>\\<^sub>1 \\<and> $<:\\<^bold>v\\<acute> =\\<^sub>u $\\<^bold>v)\"\n    by (rel_auto, metis+)\n  show ?thesis    \n    by (simp add: des_merge_def par_by_merge_alt_def seqr_assoc[THEN sym] ndesign_composition_wp wp p2)\nqed\n\nlemma ndes_par [ndes_simp]: \n  \"(p \\<turnstile>\\<^sub>n P) \\<parallel>\\<^sup>D\\<^bsub>M\\<^esub> (q \\<turnstile>\\<^sub>n Q) =((p \\<or> q \\<and> \\<not>Pre(Q)) \\<and> (q \\<or> p \\<and> \\<not>Pre(P))) \\<turnstile>\\<^sub>n (P \\<parallel>\\<^bsub>M\\<^esub> Q)\"\n  by (simp add: ndes_par_aux, rel_auto)\n\nlemma ndes_par_wlp: \n  \"(p \\<turnstile>\\<^sub>n P) \\<parallel>\\<^sup>D\\<^bsub>M\\<^esub> (q \\<turnstile>\\<^sub>n Q) =((p \\<or> q \\<and> Q wlp false) \\<and> (q \\<or> p \\<and> P wlp false)) \\<turnstile>\\<^sub>n (P \\<parallel>\\<^bsub>M\\<^esub> Q)\"\n  by (simp add: ndes_par_aux, rel_auto)\n\ntext \\<open> If the commitments are both total relations, then we do indeed get a precondition of simply\n  $p \\wedge q$. \\<close>\n\nlemma ndes_par_total: \n  assumes \"Pre(P) = true\" \"Pre(Q) = true\"\n  shows \"(p \\<turnstile>\\<^sub>n P) \\<parallel>\\<^sup>D\\<^bsub>M\\<^esub> (q \\<turnstile>\\<^sub>n Q) =(p \\<and> q) \\<turnstile>\\<^sub>n (P \\<parallel>\\<^bsub>M\\<^esub> Q)\"\n  by (simp add: ndes_par assms)\n\nlemma ndes_par_assigns: \"(p\\<^sub>1 \\<turnstile>\\<^sub>n \\<langle>\\<sigma>\\<rangle>\\<^sub>a) \\<parallel>\\<^sup>D\\<^bsub>M\\<^esub> (q\\<^sub>1 \\<turnstile>\\<^sub>n \\<langle>\\<rho>\\<rangle>\\<^sub>a) = (p\\<^sub>1 \\<and> q\\<^sub>1) \\<turnstile>\\<^sub>n (\\<langle>\\<sigma>\\<rangle>\\<^sub>a \\<parallel>\\<^bsub>M\\<^esub> \\<langle>\\<rho>\\<rangle>\\<^sub>a)\" (is \"?lhs = ?rhs\")\n  by (rule ndes_par_total, simp_all add: Pre_assigns)\n\nlemma ndes_par_H1_H3_closed [closure]: \n  assumes \"P is \\<^bold>N\" \"Q is \\<^bold>N\"\n  shows \"P \\<parallel>\\<^sup>D\\<^bsub>M\\<^esub> Q is \\<^bold>N\"\n  by (metis assms ndes_par ndesign_H1_H3 ndesign_form)\n\nlemma ndes_par_commute:\n  \"P \\<parallel>\\<^sup>D\\<^bsub>swap\\<^sub>m ;; M\\<^esub> Q = Q \\<parallel>\\<^sup>D\\<^bsub>M\\<^esub> P\"\n  by (metis par_by_merge_commute_swap swap_des_merge)\n\nlemma ndes_merge_miracle:\n  assumes \"P is \\<^bold>N\"\n  shows \"P \\<parallel>\\<^sup>D\\<^bsub>M\\<^esub> \\<top>\\<^sub>D = \\<top>\\<^sub>D\"\n  by (ndes_simp cls: assms, simp add: prepost)\n\nlemma ndes_merge_chaos:\n  assumes \"P is \\<^bold>N\" \"Pre(post\\<^sub>D(P)) = true\"\n  shows \"P \\<parallel>\\<^sup>D\\<^bsub>M\\<^esub> \\<bottom>\\<^sub>D = \\<bottom>\\<^sub>D\"\nproof -\n  obtain p\\<^sub>1 P\\<^sub>2 where \"P = p\\<^sub>1 \\<turnstile>\\<^sub>n P\\<^sub>2\"\n    by (metis assms(1) ndesign_form)\n  with assms(2) show ?thesis\n    by (simp add: ndes_simp, rel_auto)\nqed\n\nend", "meta": {"author": "isabelle-utp", "repo": "utp-main", "sha": "27bdf3aee6d4fc00c8fe4d53283d0101857e0d41", "save_path": "github-repos/isabelle/isabelle-utp-utp-main", "path": "github-repos/isabelle/isabelle-utp-utp-main/utp-main-27bdf3aee6d4fc00c8fe4d53283d0101857e0d41/theories/designs/utp_des_parallel.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5312093733737563, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.2945399082458839}}
{"text": "(*  Title:      JinjaThreads/JVM/JVMExceptions.thy\n    Author:     Gerwin Klein, Martin Strecker, Andreas Lochbihler\n*)\n\nsection \\<open>Exception handling in the JVM\\<close>\n\ntheory JVMExceptions\nimports\n  JVMInstructions\nbegin\n\nabbreviation Any :: \"cname option\"\nwhere \"Any \\<equiv> None\"\n\ndefinition matches_ex_entry :: \"'m prog \\<Rightarrow> cname \\<Rightarrow> pc \\<Rightarrow> ex_entry \\<Rightarrow> bool\"\nwhere\n \"matches_ex_entry P C pc xcp \\<equiv>\n                 let (s, e, C', h, d) = xcp in\n                 s \\<le> pc \\<and> pc < e \\<and> (case C' of None \\<Rightarrow> True | \\<lfloor>C''\\<rfloor> \\<Rightarrow> P \\<turnstile> C \\<preceq>\\<^sup>* C'')\"\n\n\nprimrec\n  match_ex_table :: \"'m prog \\<Rightarrow> cname \\<Rightarrow> pc \\<Rightarrow> ex_table \\<Rightarrow> (pc \\<times> nat) option\"\nwhere\n  \"match_ex_table P C pc []     = None\"\n| \"match_ex_table P C pc (e#es) = (if matches_ex_entry P C pc e\n                                   then Some (snd(snd(snd e)))\n                                   else match_ex_table P C pc es)\"\n\nabbreviation ex_table_of :: \"'addr jvm_prog \\<Rightarrow> cname \\<Rightarrow> mname \\<Rightarrow> ex_table\"\nwhere \"ex_table_of P C M == snd (snd (snd (the (snd (snd (snd(method P C M)))))))\"\n\nlemma match_ex_table_SomeD:\n  \"match_ex_table P C pc xt = Some (pc',d') \\<Longrightarrow> \n  \\<exists>(f,t,D,h,d) \\<in> set xt. matches_ex_entry P C pc (f,t,D,h,d) \\<and> h = pc' \\<and> d=d'\"\n  by (induct xt) (auto split: if_split_asm)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/JinjaThreads/JVM/JVMExceptions.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6442251064863697, "lm_q2_score": 0.45713671682749485, "lm_q1q2_score": 0.29449895007702226}}
{"text": "theory IMP_Minus_To_SAT\n  imports \"IMP_Minus_To_SAS_Plus\" \"Verified_SAT_Based_AI_Planning.SAT_Solve_SAS_Plus\"\n    \"../Complexity_classes/Cook_Levin\" \"IMP_Minus.Max_Constant\"\nbegin\n\nsection \\<open>Translation from IMP- to SAT\\<close>\n\ntext \\<open>In this theory the translations `from IMP- to SAS+`\n      and `SAS+ to SAT` are composed and the `main_lemma` for\n      the Cook_Levin theorem is proven correct.\\<close>\n\n\nsubsection \\<open>The partial steps:\\<close>\n\ntext \\<open>theorems about the translation from IMP- to SAS+\\<close>\nthm SAS_Plus_to_IMP_Minus_correctness\n\nthm IMP_Minus_to_SAS_Plus_correctness\n\n\ntext \\<open>theorem about the translation from SAS+ to SAT\\<close>\nthm sas_plus_problem_has_serial_solution_iff\n\n(* TODO: use that *)\nterm Sema.sat\n\n\nsubsection \\<open>Putting things together\\<close>\n\ntext \\<open>Putting things together works in three steps:\n  \\<^item> first we put together the transformations on the HOL level\n  \\<^item> then we synthesize a IMP- program that refines the HOL algorithm\n  \\<^item> then we instantiate the Cook_Levin locale\\<close>\n\nsubsubsection \\<open>Putting things together on the HOL level\\<close>\n\ndefinition encode_sat :: \"_ \\<Rightarrow> nat\"  where\n  \"encode_sat F = undefined\"\n\n\nlemma valid_problem: \"is_valid_problem_sas_plus (IMP_Minus_to_SAS_Plus c I r G t)\"\n  using SAS_Plus_Plus_To_SAS_Plus_valid[OF imp_minus_minus_to_sas_plus_valid]\n  by (auto simp: IMP_Minus_to_SAS_Plus_def Let_def)\n\nlemma while_program_has_model:\n  assumes \n    \"I \\<subseteq>\\<^sub>m Some \\<circ> s1\"\n    \"finite (range s1)\"\n    (*Mohammad: The next assumption has to be fixed in IMP_Minus_to_SAS_Plus_correctness*)\n    \"Max (range s1) < r\"\n    \"G \\<subseteq>\\<^sub>m Some \\<circ> s2\"\n    \"(c, s1) \\<Rightarrow>\\<^bsup> t \\<^esup> s2\"\n    \"t \\<le> t'\"\n  shows \n  (*Mohammad: there is still a problem with this theorem, namely, the generated formula is still\n              parameterised by the specific running time 't'.\n              This can only be fixed by generalising IMP_Minus_to_SAS_Plus_correctness *)\n  \"\\<exists>\\<A>. \\<A> \\<Turnstile> \\<Phi>\\<^sub>\\<forall> (\\<phi> prob_with_noop (IMP_Minus_to_SAS_Plus c I r G t'))\n                100 * (max_input_bits c I r + t' + 1) * (t' - 1) +\n                   (max_input_bits c I r + t' + 2) *\n                      (num_variables c + 2) + 52\"\n  (is \"\\<exists>_. _ \\<Turnstile> \\<Phi>\\<^sub>\\<forall> _ (?b::nat)\")\nproof-\n  obtain plan where plan:\n    \"length plan \\<le> ?b\"\n    \"SAS_Plus_Semantics.is_serial_solution_for_problem (IMP_Minus_to_SAS_Plus c I r G t') plan\"\n    using assms(6) le_trans IMP_Minus_to_SAS_Plus_correctness[OF assms(1-5)]\n    by (smt group_cancel.add1 one_add_one)\n  thus ?thesis\n    using sas_plus_problem_has_serial_solution_iff_ii'[OF valid_problem plan(2,1)]\n    by auto\nqed\n\nlemma if_there_is_model_then_program_terminates:\n  assumes \n    \"dom I \\<subseteq> set (Max_Constant.all_variables c)\"\n    \"dom G \\<subseteq> set (Max_Constant.all_variables c)\"\n    \"Max (ran G) < 2 ^ (t + max_input_bits c I r)\"\n    (* Mohammad: The following assumption cannot be true for many verifiers. s1 has to depend on I \n                 , otherwise the assumption is vacuous.*)\n    \"\\<And>s1. I \\<subseteq>\\<^sub>m Some \\<circ> s1 \\<Longrightarrow> \\<exists>s2. \\<exists>t' \\<le> t. (c, s1) \\<Rightarrow>\\<^bsup>t'\\<^esup> s2\"\n    \"\\<A> \\<Turnstile> \\<Phi>\\<^sub>\\<forall> (\\<phi> prob_with_noop (IMP_Minus_to_SAS_Plus c I r G t))\n            100 * (max_input_bits c I r + t + 1) * (t - 1) +\n               (max_input_bits c I r + t + 2) *\n                  (num_variables c + 2) + 52\"\n  shows \"\\<exists>s1 s2 t'. t' \\<le> t \\<and> I \\<subseteq>\\<^sub>m Some \\<circ> s1 \\<and> G \\<subseteq>\\<^sub>m Some \\<circ> s2 \\<and> (c, s1)  \\<Rightarrow>\\<^bsup>t'\\<^esup> s2\"\nproof-\n  obtain plan\n    where \"SAS_Plus_Semantics.is_serial_solution_for_problem (IMP_Minus_to_SAS_Plus c I r G t) plan\"\n    using sas_plus_problem_has_serial_solution_iff_i'[OF valid_problem assms(5)]    \n    by rule\n  thus ?thesis\n    using assms\n    by(auto intro: SAS_Plus_to_IMP_Minus_correctness)\nqed\n\ndefinition t' ::\"(nat \\<Rightarrow> nat) \\<Rightarrow> (nat\\<Rightarrow> nat) \\<Rightarrow> nat \\<Rightarrow> nat\"\n  where \"t' pt p_cer x = (make_mono pt) (bit_length x + (make_mono p_cer) (bit_length x)) + 1\"\n\n definition imp_to_sat :: \"Com.com \\<Rightarrow> (nat \\<Rightarrow> nat) \\<Rightarrow> (nat\\<Rightarrow> nat) \\<Rightarrow> nat \\<Rightarrow> sat_plan_formula\" where\n    \"imp_to_sat c pt p_cer x =\n      (let I = (Map.empty)(''input'' \\<mapsto> x); \n          G = (Map.empty)(''input'' \\<mapsto> 0);\n          guess_range = x + 1 + 2 * 2 ^ (p_cer (bit_length x));\n          max_bits = max_input_bits c I guess_range\n      in\n        \\<Phi>\\<^sub>\\<forall> (\\<phi> prob_with_noop (IMP_Minus_to_SAS_Plus c I guess_range G (t' pt p_cer x)))\n           100 * (max_bits + (t' pt p_cer x) + 1) * ((t' pt p_cer  x) - 1) +\n             (max_bits + (t' pt p_cer x) + 2) * (num_variables c + 2) + 52)\"\n\nlemma main_lemma_hol:\n  fixes c pt p_cer in_lang\n  assumes \"poly pt\"\n  assumes \"poly p_cer\"\n  assumes verifier_tbounded:\n  (*Mohammad: I don't think we need the time to bounded by the cert length since the cert length\n              is bounded by input length.*)\n    \"\\<And>s. \\<exists>t s'. (c, s) \\<Rightarrow>\\<^bsup> t \\<^esup> s' \\<and>\n                   t \\<le> pt (bit_length (s ''input''))\"\n  assumes verifier_terminates: \n          (*\"\\<And>x z. \\<forall>s. s ''input'' = x \\<and> s ''certificate'' = z \\<longrightarrow>\n                         (\\<exists>t s'. (c, s) \\<Rightarrow>\\<^bsup> t \\<^esup> s' \\<and> s' ''input'' = in_lang x)\"*)\n          (*Mohammad: The TM needs no access to the certificate since it is non-deterministic, i.e. it can\n            assume it is guessed.*)\n          (*Mohammad: The computation output should depend on the state, otherwise the theorem\n                      statement does not hold*)\n          (*Mohammad: We need to specify what it means for c to be a verifier for the certificates*)\n          \"\\<And>x s. \\<lbrakk>in_lang x = 0 ; s ''input'' = x\\<rbrakk> \\<Longrightarrow>\n                    (\\<exists>z t s'. bit_length z \\<le> p_cer (bit_length x) \\<and>\n                              (c, s(''certificate'' := z)) \\<Rightarrow>\\<^bsup> t \\<^esup> s' \\<and>\n                              s' ''input'' = in_lang x)\"\n          \"\\<And>x s s' t. \\<lbrakk>in_lang x \\<noteq> 0; s ''input'' = x; (c, s) \\<Rightarrow>\\<^bsup> t \\<^esup> s'\\<rbrakk> \\<Longrightarrow>\n                         s' ''input'' = in_lang x\"\n  assumes verifier_has_registers:\n    \"''input'' \\<in> set (Max_Constant.all_variables c)\"\n  shows \"\\<exists>t_red s_red.\n         poly t_red \n       \\<and> poly s_red\n       \\<and> (\\<forall>x. \\<exists>f.  bit_length (encode_sat f) \\<le> s_red ( bit_length x ) \\<and> imp_to_sat c pt p_cer x = f\n                   \\<and> (Sema.sat {f}  \\<longleftrightarrow> in_lang x = 0))\"\nproof -\n  define t''::\"(char list \\<Rightarrow> nat) \\<Rightarrow> nat\" where\n    \"t'' s = (make_mono pt) (bit_length (s ''input''))\" for s\n\n\n  have t_bound: \"\\<exists>t s'. (c, s) \\<Rightarrow>\\<^bsup> t \\<^esup> s' \\<and> t \\<le> t'' s\" for s\n    using verifier_tbounded[of s] order.trans\n    by (auto 5 1 simp: t''_def)\n\n\n  text\\<open>Upper bound on the time\\<close>\n\n  have t_bound_2: \"\\<exists>s' t. t \\<le> t' pt p_cer  x \\<and> (c, s) \\<Rightarrow>\\<^bsup> t \\<^esup> s'\"\n    if \"s ''input'' = x\"\n    for s x\n  proof-    \n    obtain t s' where \n      \"(c, s) \\<Rightarrow>\\<^bsup> t \\<^esup> s'\"\n      \"t \\<le> pt (bit_length (s ''input''))\"\n      using verifier_tbounded\n      by blast+\n    have \"t'' s \\<le> t' pt p_cer (s ''input'')\"\n      by (auto simp: t'_def t''_def le_make_mono order_trans\n               intro!: le_SucI monoD[OF mono_make_mono])\n    hence \"t \\<le> t' pt p_cer (s ''input'')\"\n      using t_bound \\<open>(c, s) \\<Rightarrow>\\<^bsup> t \\<^esup> s'\\<close>\n      by (smt bigstepT_the_cost less_le_trans not_le)\n    thus ?thesis\n      using \\<open>(c, s) \\<Rightarrow>\\<^bsup> t \\<^esup> s'\\<close> that\n      by auto\n  qed\n\n  have \"Sema.sat {imp_to_sat c pt p_cer x}\"\n    if init: \"in_lang x = 0\"\n    for x\n  proof-\n    define s where \"s \\<equiv> (\\<lambda>_. 0) (''input'' := x)\"\n    have \"s ''input'' = x\"\n      by (auto simp add: s_def)\n    then obtain z t s'\n      where \"bit_length z \\<le> p_cer (bit_length x)\"\n            \"(c, s(''certificate'' := z)) \\<Rightarrow>\\<^bsup> t \\<^esup> s'\"\n            \"s' ''input'' = in_lang x\"\n      using verifier_terminates(1)[of x s, OF init]\n      by auto\n    moreover hence \"t'' (s(''certificate'' := z)) \\<le> t' pt p_cer x\"\n      by (auto simp: \\<open>s ''input'' = x\\<close> t'_def t''_def bit_length_def le_make_mono order_trans\n               intro!: le_SucI monoD[OF mono_make_mono])\n    hence \"t \\<le> t' pt p_cer x\"\n      using t_bound \\<open>(c, s(''certificate'' := z)) \\<Rightarrow>\\<^bsup> t \\<^esup> s'\\<close>\n      by (smt bigstepT_the_cost less_le_trans not_le)\n    moreover have \"[''input'' \\<mapsto> x] \\<subseteq>\\<^sub>m Some \\<circ> s(''certificate'' := z)\"\n      by (auto simp: s_def map_le_def)\n    moreover have \"finite (range (s(''certificate'' := z)))\"\n      by (auto simp: image_def s_def)\n    moreover have \"z \\<le> 2 * 2 ^ p_cer (Discrete.log x)\"\n      using \\<open>bit_length z \\<le> p_cer (bit_length x)\\<close>\n      apply(simp add: bit_length_def)\n      by (metis le_iff_add log_exp2_ge mult.commute not_less power_of_two_increase_exponent_le)\n    ultimately have \"\\<exists>\\<A>. \\<A> \\<Turnstile> imp_to_sat c pt p_cer x\"\n      unfolding Sema.sat_def imp_to_sat_def Let_def\n      by (fastforce simp add: s_def bit_length_def map_le_def init\n                    intro!: while_program_has_model[of _ \"s(''certificate'' := z)\" _ _ s' _ t])\n    thus ?thesis\n      by (auto simp: Sema.sat_def)\n  qed\n\n  moreover have \"in_lang x = 0\"\n    if \"Sema.sat {imp_to_sat c pt p_cer x}\"\n    for x\n  proof-\n    obtain \\<A> where \"\\<A> \\<Turnstile> imp_to_sat c pt p_cer x\"\n      using \\<open>Sema.sat {imp_to_sat c pt p_cer x}\\<close>\n      by (auto simp: Sema.sat_def)\n    hence \"\\<exists>s1 s2 t''. t'' \\<le> t' pt p_cer  x \\<and> [''input'' \\<mapsto> x] \\<subseteq>\\<^sub>m Some \\<circ> s1 \\<and>\n                       [''input'' \\<mapsto> 0] \\<subseteq>\\<^sub>m Some \\<circ> s2 \\<and> (c, s1) \\<Rightarrow>\\<^bsup> t'' \\<^esup> s2\"\n      apply(intro if_there_is_model_then_program_terminates \n                    [where \\<A> = \\<A> and r = \"x + 1 + 2 * 2 ^ (p_cer (bit_length x))\"])\n      using verifier_has_registers\n      by (auto simp: map_le_def imp_to_sat_def Let_def intro: t_bound_2 )\n    then obtain s1 s2 t'' \n      where \"t'' \\<le> t' pt p_cer x\" \"[''input'' \\<mapsto> x] \\<subseteq>\\<^sub>m Some \\<circ> s1\"\n            \"[''input'' \\<mapsto> 0] \\<subseteq>\\<^sub>m Some \\<circ> s2\" \"(c, s1) \\<Rightarrow>\\<^bsup> t'' \\<^esup> s2\"\n      by auto\n    moreover hence \"s2 ''input'' = 0\" \"s1 ''input'' = x\"\n      by (auto simp: map_le_def)\n    ultimately show \"in_lang x = 0\"\n      using verifier_terminates(2)\n      by fastforce\n  qed\n\n  ultimately show ?thesis\n    sorry\nqed\n\ndefinition decode_sat :: \"nat \\<Rightarrow> nat three_sat\" where\n  \"decode_sat n = undefined\"\n\ninterpretation encode_decode_sat encode_sat decode_sat\n  sorry\n\nsubsubsection \\<open>Synthesizing the IMP- Program\\<close>\n\nlemma main_lemma_synth : \n  fixes c pt p_cer\n  assumes \"poly pt\"\n  assumes \"poly p_cer\"\n  assumes \"\\<forall>s. \\<exists>t. Ex (big_step_t (c, s) t) \\<and> t \\<le> \n                      pt (bit_length (s ''input'') + bit_length (s ''certificate''))\"\n  assumes \"\\<forall>x z. \\<exists>r. \\<forall>s. s ''input'' = x \\<and> s ''certificate'' = z \\<longrightarrow>\n                         (\\<exists>t s'. (c, s) \\<Rightarrow>\\<^bsup> t \\<^esup> s' \\<and> s' ''input'' = r)\"\n  shows \"\\<exists>imp_to_sat t_red s_red.\n         poly t_red \n       \\<and> poly s_red\n       \\<and> (\\<forall>s t s'. (imp_to_sat,s) \\<Rightarrow>\\<^bsup> t \\<^esup> s' \\<longrightarrow> s ''certificate'' = s' ''certificate'')\n       \\<and> (\\<forall>x. \\<exists>f.    bit_length f \\<le> s_red ( bit_length x )\n                   \\<and> (\\<forall>s. s ''input'' = x \\<longrightarrow> (\\<exists>t s'. (imp_to_sat,s) \\<Rightarrow>\\<^bsup> t \\<^esup> s' \\<and> \n                                          s' ''input'' = f \\<and> t \\<le> t_red(bit_length x)))\n                   \\<and> ( f \\<in> IMP_SAT \\<longleftrightarrow>\n                                        (\\<exists>z. bit_length z \\<le> p_cer (bit_length x) \\<and>\n                                                      (\\<forall>s t s'. s ''input'' = x \n                                                      \\<and> s ''certificate'' = z \n                                                      \\<and>(c, s) \\<Rightarrow>\\<^bsup> t \\<^esup> s' \\<longrightarrow> s' ''input'' = 0))\n                                        )\n                      )\"\n  sorry\n\n\nsubsubsection \\<open>Instantiating the Cook_Levin locale\\<close>\n\n(*interpretation Cook_Levin_assumes_Main_lemma encode_sat decode_sat\n  apply standard\n  by (fact main_lemma_synth) \n   \nterm strict_sorted*)\n\nend", "meta": {"author": "AlexiosFan", "repo": "BA_NP_Reduction", "sha": "0e37ddc58cb822b0a09b2ce7c15e7b88652e154c", "save_path": "github-repos/isabelle/AlexiosFan-BA_NP_Reduction", "path": "github-repos/isabelle/AlexiosFan-BA_NP_Reduction/BA_NP_Reduction-0e37ddc58cb822b0a09b2ce7c15e7b88652e154c/poly-reductions/Cook_Levin/IMP-_To_SAS+/IMP_Minus_To_SAT.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6442251064863697, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.29449895007702226}}
{"text": "section {* Simulink Blocks Examples *}\n\ntheory simu_contract_real_example\n  imports\n    simu_contract_real\nbegin\n\nsubsection {* inps and outps *}\nlemma \n  fixes ok and inouts\n  shows \"\\<lbrakk>(true \\<turnstile>\\<^sub>r II)\\<rbrakk>\\<^sub>e\n   (\\<lparr>ok\\<^sub>v = ok, inouts\\<^sub>v = inouts\\<rparr>, \\<lparr>ok\\<^sub>v = ok, inouts\\<^sub>v = inouts\\<rparr>)\"\n  apply (rel_auto)\ndone\n\nlemma \n  fixes ok and inouts\n  assumes \"\\<lbrakk>(true \\<turnstile>\\<^sub>r II)\\<rbrakk>\\<^sub>e\n   (\\<lparr>ok\\<^sub>v = ok, inouts\\<^sub>v = inouts\\<rparr>, \\<lparr>ok\\<^sub>v = ok1, inouts\\<^sub>v = inouts\\<rparr>)\"\n  shows \"(ok1 = ok) \\<or> \\<not>ok\"\n  using assms apply (simp add: urel_defs)\n  apply (rel_simp)\ndone\n\nlemma \n  fixes ok and inouts\n  assumes \"\\<lbrakk>(true \\<turnstile>\\<^sub>r II)\\<rbrakk>\\<^sub>e\n   (\\<lparr>ok\\<^sub>v = ok, inouts\\<^sub>v = inouts\\<rparr>, \\<lparr>ok\\<^sub>v = ok1, inouts\\<^sub>v = inouts\\<rparr>)\"\n  shows \"ok1 = ok\"\n  using assms apply (simp add: urel_defs)\n  apply (rel_simp)\n  (*\n    \"e\": The prover derived \"False\" from \"SimBlock_def\", \"impl_mp1\", \"inps_outps\", \"rdesign_post\", \"rdesign_pre\", and \"utp_pred_laws.inf_top_left\", which could be due to a bug in Sledgehammer or to inconsistent axioms (including \"sorry\"s) \n    \"z3\": Timed out \n    \"cvc4\": Timed out \n    \"spass\": Timed out\n  *)\nsorry\n\ndeclare [[show_types]]\nlemma \n  fixes ok and inouts\n  assumes \"\\<forall>x . length(inouts x) = Suc 0\"\n  shows \"\\<lbrakk>Id\\<rbrakk>\\<^sub>e\n   (\\<lparr>ok\\<^sub>v = ok, inouts\\<^sub>v = inouts\\<rparr>, \\<lparr>ok\\<^sub>v = ok, inouts\\<^sub>v = inouts\\<rparr>)\"\n  apply (simp add: sim_blocks)\n  apply (rel_simp)\n  by (simp add: assms)\n\nlemma \n  fixes ok and inouts\n  assumes \"\\<forall>x . length(inouts x) = 2\"\n  shows \"\\<lbrakk>takem 2 1\\<rbrakk>\\<^sub>e\n   (\\<lparr>ok\\<^sub>v = ok, inouts\\<^sub>v = inouts\\<rparr>, \\<lparr>ok\\<^sub>v = ok, inouts\\<^sub>v = \\<lambda>na . [hd(inouts na)]\\<rparr>)\"\n  apply (simp add: sim_blocks)\n  apply (rel_simp)\n  by (metis assms length_0_conv take_0 take_Suc zero_not_eq_two)\n\nlemma \n  fixes ok\\<^sub>v0 and inouts\\<^sub>v0\n  assumes \"\\<forall>x . length(inouts\\<^sub>v0 x) = (m1 + m2 + m3)\"\n  shows \"\\<lbrakk>takem (m1 + m2 + m3) (m1 + m2)\\<rbrakk>\\<^sub>e\n          (\\<lparr>ok\\<^sub>v = ok\\<^sub>v0, inouts\\<^sub>v = inouts\\<^sub>v0\\<rparr>, \\<lparr>ok\\<^sub>v = ok\\<^sub>v0, inouts\\<^sub>v = \\<lambda>na . take (m1+m2) (inouts\\<^sub>v0 na)\\<rparr>)\"\n  apply (simp add: sim_blocks)\n  apply (rel_simp)\n  using assms by auto\n\nlemma \n  fixes m and n\n  assumes a2: \"n \\<le> m\"\n  assumes a1: \"\\<lbrakk>takem m n\\<rbrakk>\\<^sub>e\n          (\\<lparr>ok\\<^sub>v = ok\\<^sub>v0, inouts\\<^sub>v = inouts\\<^sub>v0\\<rparr>, \\<lparr>ok\\<^sub>v = ok\\<^sub>v1, inouts\\<^sub>v = inouts\\<^sub>v1\\<rparr>)\"\n  (* shows \"(ok\\<^sub>v0 \\<longrightarrow> ok\\<^sub>v1)\"*)\n  (* shows \"(ok\\<^sub>v1 = ok\\<^sub>v0) \\<or> ok\\<^sub>v1)\" *)\n  shows \"ok\\<^sub>v0 \\<longrightarrow> (\\<forall>x . length(inouts\\<^sub>v0 x) = (m))\"\n  proof -\n    show ?thesis\n      using a1 a2 apply (simp add: sim_blocks)\n      apply (rel_simp)\n    done\n  qed\n\nlemma \n  fixes m and n\n  assumes a2: \"n \\<le> m\"\n  assumes a1: \"\\<lbrakk>takem m n\\<rbrakk>\\<^sub>e\n          (\\<lparr>ok\\<^sub>v = ok\\<^sub>v0, inouts\\<^sub>v = inouts\\<^sub>v0\\<rparr>, \\<lparr>ok\\<^sub>v = ok\\<^sub>v1, inouts\\<^sub>v = inouts\\<^sub>v1\\<rparr>)\"\n  (* shows \"(ok\\<^sub>v0 \\<longrightarrow> ok\\<^sub>v1)\"*)\n  (* shows \"(ok\\<^sub>v1 = ok\\<^sub>v0) \\<or> ok\\<^sub>v1)\" *)\n  shows \"ok\\<^sub>v0 \\<and> n \\<noteq> 0 \\<longrightarrow> (inouts\\<^sub>v1 = (\\<lambda>na. (take n (inouts\\<^sub>v0 na))))\"\n  proof -\n    show ?thesis\n      using a1 a2 apply (simp add: sim_blocks)\n      apply (rel_simp)\n      proof -\n        fix x\n        assume \"\\<forall>x::nat.\n          length(inouts\\<^sub>v0 x) = m \\<and>\n          length(inouts\\<^sub>v1 x) = n \\<and>\n          \\<lbrakk>bop op = (\\<guillemotleft>take n\\<guillemotright>($inouts(\\<guillemotleft>x\\<guillemotright>)\\<^sub>a)\\<^sub>a) ($inouts\\<acute>(\\<guillemotleft>x\\<guillemotright>)\\<^sub>a)\\<rbrakk>\\<^sub>e\n           (get\\<^bsub>\\<Sigma>\\<^sub>D \\<times> \\<Sigma>\\<^sub>D\\<^esub> (\\<lparr>ok\\<^sub>v = True, inouts\\<^sub>v = inouts\\<^sub>v0\\<rparr>, \\<lparr>ok\\<^sub>v = True, inouts\\<^sub>v = inouts\\<^sub>v1\\<rparr>))\"\n        show \"inouts\\<^sub>v1 x = take n (inouts\\<^sub>v0 x)\"\n    done\n  qed\n\nlemma \n  fixes m and n\n  assumes a2: \"n \\<le> m\"\n  assumes a1: \"\\<lbrakk>takem m n\\<rbrakk>\\<^sub>e\n          (\\<lparr>ok\\<^sub>v = ok\\<^sub>v0, inouts\\<^sub>v = inouts\\<^sub>v0\\<rparr>, \\<lparr>ok\\<^sub>v = ok\\<^sub>v1, inouts\\<^sub>v = inouts\\<^sub>v1\\<rparr>)\"\n  (* shows \"(ok\\<^sub>v0 \\<longrightarrow> ok\\<^sub>v1)\"*)\n  (* shows \"(ok\\<^sub>v1 = ok\\<^sub>v0) \\<or> ok\\<^sub>v1)\" *)\n  shows \"ok\\<^sub>v0 \\<longrightarrow> (\\<forall>x . length(inouts\\<^sub>v1 x) = (n))\"\n  proof -\n    show ?thesis\n      using a1 a2 apply (simp add: sim_blocks)\n      apply (rel_simp)\n    done\n  qed\n\n\nsubsubsection {* SimBlock *}\nparagraph {* Illustration *}\n\nlemma \"(pre\\<^sub>D(Id) \\<and> post\\<^sub>D(Id)) = \n  (\\<^bold>\\<forall> n \\<bullet> #\\<^sub>u($inouts(\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u 1 \\<and> #\\<^sub>u($inouts\\<acute>(\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u 1 \\<and> \n         head\\<^sub>u($inouts(\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u head\\<^sub>u($inouts\\<acute>(\\<guillemotleft>n\\<guillemotright>)\\<^sub>a))\"\napply (simp add: sim_blocks)\ndone\n\nlemma Dom_Id: \"Dom(pre\\<^sub>D(Id) \\<and> post\\<^sub>D(Id)) = (\\<^bold>\\<forall> n \\<bullet> #\\<^sub>u(&inouts(\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u 1)\"\napply (simp add: sim_blocks Dom_def)\napply (rel_auto)\ndone\n\nlemma Ran_Id: \"Ran(pre\\<^sub>D(Id) \\<and> post\\<^sub>D(Id)) = (\\<^bold>\\<forall> n \\<bullet> #\\<^sub>u(&inouts(\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u 1)\"\napply (simp add: sim_blocks Ran_def)\napply (rel_auto)\ndone\n\nlemma \"(\\<^bold>\\<forall> n \\<bullet> #\\<^sub>u(&inouts(\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u 1) \\<sqsubseteq> Dom(pre\\<^sub>D(Id) \\<and> post\\<^sub>D(Id))\"\napply (simp add: Dom_Id)\ndone\n\nsubsubsection {* inps and outps *}\n\nsubsection {* Experiments *}\n\nparagraph {* Example *}\nlemma takem_simp2:\n\"(takem (Suc (Suc 0)) (Suc 0)) ;; Id = \n true \\<turnstile>\\<^sub>r (\\<^bold>\\<forall> n \\<bullet> #\\<^sub>u($inouts(\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u \\<guillemotleft>2\\<guillemotright> \\<and>\n               #\\<^sub>u($inouts\\<acute>(\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u \\<guillemotleft>1\\<guillemotright> \\<and>\n               head\\<^sub>u($inouts(\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u head\\<^sub>u($inouts\\<acute>(\\<guillemotleft>n\\<guillemotright>)\\<^sub>a))\"\napply (simp add: sim_blocks)\napply (rel_auto)\napply (metis list.sel(1) list.size(3) numeral_2_eq_2 take_Suc zero_not_eq_two)\nby (metis Cons_nth_drop_Suc Suc_1 Suc_leI append.simps(1) drop_0 drop_all hd_drop_conv_nth take_0 take_hd_drop zero_less_Suc)\n\nlemma dropm_simp2:\n\"(dropm (Suc (Suc 0)) (Suc 0)) ;; Id = \n true \\<turnstile>\\<^sub>r (\\<^bold>\\<forall> n \\<bullet> #\\<^sub>u($inouts(\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u \\<guillemotleft>2\\<guillemotright> \\<and>\n               #\\<^sub>u($inouts\\<acute>(\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u \\<guillemotleft>1\\<guillemotright> \\<and>\n               last\\<^sub>u($inouts(\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u head\\<^sub>u($inouts\\<acute>(\\<guillemotleft>n\\<guillemotright>)\\<^sub>a))\"\napply (simp add: sim_blocks)\napply (rel_auto)\napply (metis One_nat_def add_Suc_right cancel_ab_semigroup_add_class.add_diff_cancel_left' hd_drop_conv_nth last_conv_nth lessI list.size(3) numeral_2_eq_2 of_nat_1 of_nat_Suc semiring_1_class.of_nat_0 zero_not_eq_two)\nby (smt Cons_nth_drop_Suc One_nat_def Suc_less_eq add_2_eq_Suc add_Suc cancel_ab_semigroup_add_class.add_diff_cancel_left' drop_0 drop_all hd_drop_conv_nth last_conv_nth neq0_conv neq_Nil_conv not_less_zero numeral_2_eq_2 order_refl)\n\nlemma lem_parallel_1 : \"\\<And>(ok\\<^sub>v::bool) inouts\\<^sub>v more (ok\\<^sub>v'::bool) inouts\\<^sub>v'.\n       \\<not> ok\\<^sub>v \\<Longrightarrow>\n       \\<exists>ok\\<^sub>v inouts\\<^sub>v'' morea ok\\<^sub>v'' inouts\\<^sub>v'''.\n          (\\<exists>inouts\\<^sub>v. \\<forall>x. inouts\\<^sub>v''' x = inouts\\<^sub>v x) \\<and>\n          (\\<exists>ok\\<^sub>v''' inouts\\<^sub>v''''.\n              (\\<exists>inouts\\<^sub>v. \\<forall>x. inouts\\<^sub>v'''' x = inouts\\<^sub>v x) \\<and>\n              \\<not> ok\\<^sub>v \\<and>\n              (\\<forall>x. inouts\\<^sub>v'' x = inouts\\<^sub>v x) \\<and>\n              morea = more \\<and> ok\\<^sub>v' = (ok\\<^sub>v'' \\<and> ok\\<^sub>v''') \\<and> (\\<forall>x. inouts\\<^sub>v' x = inouts\\<^sub>v''' x @ inouts\\<^sub>v'''' x))\"\nproof -\n  -- {* use fix to fix variables in \\<And> *}\n  fix ok\\<^sub>v :: \"bool\" and \n      inouts\\<^sub>v and \n      more and \n      ok\\<^sub>v':: \"bool\" and \n      inouts\\<^sub>v'\n  assume \"\\<not> ok\\<^sub>v\"\n  show \"\\<exists>ok1\\<^sub>v inouts\\<^sub>v'' morea ok\\<^sub>v'' inouts\\<^sub>v'''.\n          (\\<exists>inouts1\\<^sub>v. \\<forall>x. inouts\\<^sub>v''' x = inouts1\\<^sub>v x) \\<and>\n          (\\<exists>ok\\<^sub>v''' inouts\\<^sub>v''''.\n              (\\<exists>inouts1\\<^sub>v. \\<forall>x. inouts\\<^sub>v'''' x = inouts1\\<^sub>v x) \\<and>\n              \\<not> ok1\\<^sub>v \\<and>\n              (\\<forall>x. inouts\\<^sub>v'' x = inouts\\<^sub>v x) \\<and>\n              morea = more \\<and>\n              ok\\<^sub>v' = (ok\\<^sub>v'' \\<and> ok\\<^sub>v''') \\<and> \n              (\\<forall>x. inouts\\<^sub>v' x = inouts\\<^sub>v''' x @ inouts\\<^sub>v'''' x))\"\n  proof -\n    -- {* use obtain to fix local variables in \\<exists> *}\n    obtain ok1\\<^sub>v and inouts\\<^sub>v'' and morea and ok\\<^sub>v'' and inouts\\<^sub>v''' \n    where p: \"ok1\\<^sub>v = ok\\<^sub>v\" and \"inouts\\<^sub>v'' = inouts\\<^sub>v\" and \"morea = more\" and \"ok\\<^sub>v''= ok\\<^sub>v'\" and\n      \"inouts\\<^sub>v''' = inouts\\<^sub>v'\" \n      apply blast\n    done\n    (* P(x) *)\n    have 1: \"(\\<exists>inouts1\\<^sub>v. \\<forall>x. inouts\\<^sub>v' x = inouts1\\<^sub>v x) \\<and>\n          (\\<exists>ok\\<^sub>v''' inouts\\<^sub>v''''.\n              (\\<exists>inouts1\\<^sub>v. \\<forall>x. inouts\\<^sub>v'''' x = inouts1\\<^sub>v x) \\<and>\n              \\<not> ok\\<^sub>v \\<and>\n              (\\<forall>x. inouts\\<^sub>v x = inouts\\<^sub>v x) \\<and>\n              more = more \\<and>\n              ok\\<^sub>v' = (ok\\<^sub>v' \\<and> ok\\<^sub>v''') \\<and> \n              (\\<forall>x. inouts\\<^sub>v' x = inouts\\<^sub>v' x @ inouts\\<^sub>v'''' x))\"\n      proof -\n        have c1: \"(\\<exists>inouts1\\<^sub>v. \\<forall>x. inouts\\<^sub>v' x = inouts1\\<^sub>v x)\" \n          by blast\n        have c2: \"(\\<exists>ok\\<^sub>v''' inouts\\<^sub>v''''.\n              (\\<exists>inouts1\\<^sub>v. \\<forall>x. inouts\\<^sub>v'''' x = inouts1\\<^sub>v x) \\<and>\n              \\<not> ok\\<^sub>v \\<and>\n              (\\<forall>x. inouts\\<^sub>v x = inouts\\<^sub>v x) \\<and>\n              more = more \\<and>\n              ok\\<^sub>v' = (ok\\<^sub>v' \\<and> ok\\<^sub>v''') \\<and> \n              (\\<forall>x. inouts\\<^sub>v' x = inouts\\<^sub>v' x @ inouts\\<^sub>v'''' x))\"\n          proof -\n            obtain ok\\<^sub>v''' and inouts\\<^sub>v'''' where \"ok\\<^sub>v''' = ok\\<^sub>v'\" and \"inouts\\<^sub>v'''' = (\\<lambda>x.[])\"\n              by auto\n            have c3: \"(\\<exists>inouts1\\<^sub>v. \\<forall>x. [] = inouts1\\<^sub>v x) \\<and>\n              \\<not> ok\\<^sub>v \\<and>\n              (\\<forall>x. inouts\\<^sub>v x = inouts\\<^sub>v x) \\<and>\n              more = more \\<and>\n              ok\\<^sub>v' = (ok\\<^sub>v' \\<and> ok\\<^sub>v') \\<and> \n              (\\<forall>x. inouts\\<^sub>v' x = inouts\\<^sub>v' x @ [])\"\n              using \\<open>\\<not> ok\\<^sub>v\\<close> by fastforce\n            from c3 show ?thesis\n              by metis\n          qed\n        from c1 and c2 show ?thesis\n          by auto\n      qed\n    (* \\<exists>x. P(x) *)\n    then show ?thesis\n      by metis\n  qed\nqed\n\ntext {* Parallel of two @{term \"Id\"}s equal to a @{term \"Idm\"} with two inputs and ouptuts. *}\nlemma parallel_id_equal_idm2: \"sim_parallel Id Id = Idm 2\"\napply (simp add: sim_parallel_def inps_id mergeB_def par_by_merge_def)\napply (simp add: takem_simp2)\napply (simp add: dropm_simp2)\napply (simp add: Idm_def)\napply (simp add: U0_def U1_def)\napply (rel_auto+)\napply (metis Cons_nth_drop_Suc One_nat_def Suc_1 add.right_neutral add_Suc_right append.simps(1) append_Cons cancel_ab_semigroup_add_class.add_diff_cancel_left' drop_0 drop_all hd_drop_conv_nth last_conv_nth lessI neq0_conv neq_Nil_conv order_refl zero_neq_numeral)\n-- {* Subgoal 2: *}\napply (simp add: lem_parallel_1)\nproof -\n  (*\n  -- {* use fix to fix variables in \\<And> *}\n  fix ok\\<^sub>v :: \"bool\" and \n      inouts\\<^sub>v and \n      more and \n      ok\\<^sub>v':: \"bool\" and \n      inouts\\<^sub>v'\n  assume \"\\<not> ok\\<^sub>v\"\n  show \"\\<exists>ok1\\<^sub>v inouts\\<^sub>v'' morea ok\\<^sub>v'' inouts\\<^sub>v'''.\n          (\\<exists>inouts1\\<^sub>v. \\<forall>x. inouts\\<^sub>v''' x = inouts1\\<^sub>v x) \\<and>\n          (\\<exists>ok\\<^sub>v''' inouts\\<^sub>v''''.\n              (\\<exists>inouts1\\<^sub>v. \\<forall>x. inouts\\<^sub>v'''' x = inouts1\\<^sub>v x) \\<and>\n              \\<not> ok1\\<^sub>v \\<and>\n              (\\<forall>x. inouts\\<^sub>v'' x = inouts\\<^sub>v x) \\<and>\n              morea = more \\<and>\n              ok\\<^sub>v' = (ok\\<^sub>v'' \\<and> ok\\<^sub>v''') \\<and> \n              (\\<forall>x. inouts\\<^sub>v' x = inouts\\<^sub>v''' x @ inouts\\<^sub>v'''' x))\"\n  proof -\n    -- {* use obtain to fix local variables in \\<exists> *}\n    obtain ok1\\<^sub>v and inouts\\<^sub>v'' and morea and ok\\<^sub>v'' and inouts\\<^sub>v''' \n    where p: \"ok1\\<^sub>v = ok\\<^sub>v\" and \"inouts\\<^sub>v'' = inouts\\<^sub>v\" and \"morea = more\" and \"ok\\<^sub>v''= ok\\<^sub>v'\" and\n      \"inouts\\<^sub>v''' = inouts\\<^sub>v'\" \n      apply blast\n    done\n    (* P(x) *)\n    have 1: \"(\\<exists>inouts1\\<^sub>v. \\<forall>x. inouts\\<^sub>v' x = inouts1\\<^sub>v x) \\<and>\n          (\\<exists>ok\\<^sub>v''' inouts\\<^sub>v''''.\n              (\\<exists>inouts1\\<^sub>v. \\<forall>x. inouts\\<^sub>v'''' x = inouts1\\<^sub>v x) \\<and>\n              \\<not> ok\\<^sub>v \\<and>\n              (\\<forall>x. inouts\\<^sub>v x = inouts\\<^sub>v x) \\<and>\n              more = more \\<and>\n              ok\\<^sub>v' = (ok\\<^sub>v' \\<and> ok\\<^sub>v''') \\<and> \n              (\\<forall>x. inouts\\<^sub>v' x = inouts\\<^sub>v' x @ inouts\\<^sub>v'''' x))\"\n      proof -\n        have c1: \"(\\<exists>inouts1\\<^sub>v. \\<forall>x. inouts\\<^sub>v' x = inouts1\\<^sub>v x)\" \n          by blast\n        have c2: \"(\\<exists>ok\\<^sub>v''' inouts\\<^sub>v''''.\n              (\\<exists>inouts1\\<^sub>v. \\<forall>x. inouts\\<^sub>v'''' x = inouts1\\<^sub>v x) \\<and>\n              \\<not> ok\\<^sub>v \\<and>\n              (\\<forall>x. inouts\\<^sub>v x = inouts\\<^sub>v x) \\<and>\n              more = more \\<and>\n              ok\\<^sub>v' = (ok\\<^sub>v' \\<and> ok\\<^sub>v''') \\<and> \n              (\\<forall>x. inouts\\<^sub>v' x = inouts\\<^sub>v' x @ inouts\\<^sub>v'''' x))\"\n          proof -\n            obtain ok\\<^sub>v''' and inouts\\<^sub>v'''' where \"ok\\<^sub>v''' = ok\\<^sub>v'\" and \"inouts\\<^sub>v'''' = (\\<lambda>x.[])\"\n              by auto\n            have c3: \"(\\<exists>inouts1\\<^sub>v. \\<forall>x. [] = inouts1\\<^sub>v x) \\<and>\n              \\<not> ok\\<^sub>v \\<and>\n              (\\<forall>x. inouts\\<^sub>v x = inouts\\<^sub>v x) \\<and>\n              more = more \\<and>\n              ok\\<^sub>v' = (ok\\<^sub>v' \\<and> ok\\<^sub>v') \\<and> \n              (\\<forall>x. inouts\\<^sub>v' x = inouts\\<^sub>v' x @ [])\"\n              using \\<open>\\<not> ok\\<^sub>v\\<close> by fastforce\n            from c3 show ?thesis\n              by metis\n          qed\n        from c1 and c2 show ?thesis\n          by auto\n      qed\n    (* \\<exists>x. P(x) *)\n    then show ?thesis\n      by metis\n  qed\nnext\n*)\n  fix ok\\<^sub>v :: \"bool\" and \n      inouts\\<^sub>v and \n      more and \n      ok\\<^sub>v':: \"bool\" and \n      inouts\\<^sub>v'\n  assume s1: \" ok\\<^sub>v'\"\n  assume s2: \"\\<forall>x. length(inouts\\<^sub>v x) = 2 \\<and> length(inouts\\<^sub>v' x) = 2 \\<and> inouts\\<^sub>v x = inouts\\<^sub>v' x\"\n  show \"\\<exists>ok0\\<^sub>v' inouts0\\<^sub>v morea ok\\<^sub>v'' inouts\\<^sub>v''.\n          (\\<exists>inouts1\\<^sub>v.\n              (ok\\<^sub>v \\<longrightarrow> ok\\<^sub>v'' \\<and> (\\<forall>x. length(inouts1\\<^sub>v x) = Suc 0 \\<and> hd (inouts\\<^sub>v' x) = hd (inouts1\\<^sub>v x))) \\<and>\n              (\\<forall>x. inouts\\<^sub>v'' x = inouts1\\<^sub>v x)) \\<and>\n          (\\<exists>ok\\<^sub>v''' inouts\\<^sub>v'''.\n              (\\<exists>inouts\\<^sub>v.\n                  (ok\\<^sub>v \\<longrightarrow> ok\\<^sub>v''' \\<and> (\\<forall>x. length(inouts\\<^sub>v x) = Suc 0 \\<and> last (inouts\\<^sub>v' x) = hd (inouts\\<^sub>v x))) \\<and>\n                  (\\<forall>x. inouts\\<^sub>v''' x = inouts\\<^sub>v x)) \\<and>\n              ok0\\<^sub>v' = ok\\<^sub>v \\<and>\n              (\\<forall>x. inouts0\\<^sub>v x = inouts\\<^sub>v' x) \\<and>\n              morea = more \\<and> ok\\<^sub>v'' \\<and> ok\\<^sub>v''' \\<and> (\\<forall>x. inouts\\<^sub>v' x = inouts\\<^sub>v'' x @ inouts\\<^sub>v''' x))\"\n    proof -\n      obtain ok0\\<^sub>v' and inouts0\\<^sub>v and morea and ok\\<^sub>v'' and inouts\\<^sub>v'' \n      where p: \"ok0\\<^sub>v' = ok\\<^sub>v\" and \"inouts0\\<^sub>v = inouts\\<^sub>v'\" and \"morea = more\" and \"ok\\<^sub>v''= True\" and\n        \"inouts\\<^sub>v'' = (\\<lambda>x. [hd(inouts\\<^sub>v' x)])\"\n        apply auto\n      done\n      have Px: \"(\\<exists>inouts1\\<^sub>v.\n              (ok\\<^sub>v \\<longrightarrow> True \\<and> (\\<forall>x. length(inouts1\\<^sub>v x) = Suc 0 \\<and> hd (inouts\\<^sub>v' x) = hd (inouts1\\<^sub>v x))) \\<and>\n              (\\<forall>x. [hd(inouts\\<^sub>v' x)] = inouts1\\<^sub>v x)) \\<and>\n          (\\<exists>ok\\<^sub>v''' inouts\\<^sub>v'''.\n              (\\<exists>inouts\\<^sub>v.\n                  (ok\\<^sub>v \\<longrightarrow> ok\\<^sub>v''' \\<and> (\\<forall>x. length(inouts\\<^sub>v x) = Suc 0 \\<and> last (inouts\\<^sub>v' x) = hd (inouts\\<^sub>v x))) \\<and>\n                  (\\<forall>x. inouts\\<^sub>v''' x = inouts\\<^sub>v x)) \\<and>\n              ok\\<^sub>v = ok\\<^sub>v \\<and>\n              (\\<forall>x. inouts\\<^sub>v' x = inouts\\<^sub>v' x) \\<and>\n              more = more \\<and> True \\<and> ok\\<^sub>v''' \\<and> (\\<forall>x. inouts\\<^sub>v' x = [hd(inouts\\<^sub>v' x)] @ inouts\\<^sub>v''' x))\"\n        proof -\n          have c1: \"(\\<exists>inouts1\\<^sub>v.\n              (ok\\<^sub>v \\<longrightarrow> True \\<and> (\\<forall>x. length(inouts1\\<^sub>v x) = Suc 0 \\<and> hd (inouts\\<^sub>v' x) = hd (inouts1\\<^sub>v x))) \\<and>\n              (\\<forall>x. [hd(inouts\\<^sub>v' x)] = inouts1\\<^sub>v x))\"\n            by (metis \\<open>inouts\\<^sub>v'' = (\\<lambda>x. [hd (inouts\\<^sub>v' x)])\\<close> length_Cons list.sel(1) list.size(3))\n          have c2: \"(\\<exists>ok\\<^sub>v''' inouts\\<^sub>v'''.\n              (\\<exists>inouts\\<^sub>v.\n                  (ok\\<^sub>v \\<longrightarrow> ok\\<^sub>v''' \\<and> (\\<forall>x. length(inouts\\<^sub>v x) = Suc 0 \\<and> last (inouts\\<^sub>v' x) = hd (inouts\\<^sub>v x))) \\<and>\n                  (\\<forall>x. inouts\\<^sub>v''' x = inouts\\<^sub>v x)) \\<and>\n              ok\\<^sub>v = ok\\<^sub>v \\<and>\n              (\\<forall>x. inouts\\<^sub>v' x = inouts\\<^sub>v' x) \\<and>\n              more = more \\<and> True \\<and> ok\\<^sub>v''' \\<and> (\\<forall>x. inouts\\<^sub>v' x = [hd(inouts\\<^sub>v' x)] @ inouts\\<^sub>v''' x))\"\n            proof -\n              obtain ok\\<^sub>v''' and inouts\\<^sub>v''' where \n                \"ok\\<^sub>v''' = True\" and \"inouts\\<^sub>v''' =  (\\<lambda>x. [last(inouts\\<^sub>v' x)])\"\n                by auto \n              have Px: \"(\\<exists>inouts\\<^sub>v.\n                  (ok\\<^sub>v \\<longrightarrow> True \\<and> (\\<forall>x. length(inouts\\<^sub>v x) = Suc 0 \\<and> last (inouts\\<^sub>v' x) = hd (inouts\\<^sub>v x))) \\<and>\n                  (\\<forall>x. [last(inouts\\<^sub>v' x)] = inouts\\<^sub>v x)) \\<and>\n                ok\\<^sub>v = ok\\<^sub>v \\<and>\n                (\\<forall>x. inouts\\<^sub>v' x = inouts\\<^sub>v' x) \\<and>\n                more = more \\<and> True \\<and> True \\<and> (\\<forall>x. inouts\\<^sub>v' x = [hd(inouts\\<^sub>v' x)] @ [last(inouts\\<^sub>v' x)])\"\n                proof -\n                  have c1: \"(\\<exists>inouts\\<^sub>v.\n                    (ok\\<^sub>v \\<longrightarrow> True \\<and> (\\<forall>x. length(inouts\\<^sub>v x) = Suc 0 \\<and> last (inouts\\<^sub>v' x) = hd (inouts\\<^sub>v x))) \\<and>\n                    (\\<forall>x. [last(inouts\\<^sub>v' x)] = inouts\\<^sub>v x))\"\n                    by force\n                  have c2: \"(\\<forall>x. inouts\\<^sub>v' x = [hd(inouts\\<^sub>v' x)] @ [last(inouts\\<^sub>v' x)])\"\n                    using list_equal_size2 s2 by blast\n                  from c1 and c2 show ?thesis\n                    by auto\n                qed\n              then show ?thesis \n                by metis\n            qed\n          from c1 and c2 show ?thesis by auto\n        qed\n      then show ?thesis\n        by metis\n    qed\nqed\n\nparagraph {* Example *}\ntext {* For example, *}\ndefinition IntegratorWOFeedback :: \"(dummyT sim_state_scheme, dummyT sim_state_scheme) rel_des\" where\n\"IntegratorWOFeedback = (true \\<turnstile>\\<^sub>r\n        (\\<^bold>\\<forall> n::nat \\<bullet> \n          (((#\\<^sub>u($inouts (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) =\\<^sub>u 2) \\<and> ((#\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) =\\<^sub>u 2) \\<and> \n          (head\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u head\\<^sub>u($inouts (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) + \n                (if n = 0 then 0 else head\\<^sub>u(tail\\<^sub>u($inouts (\\<guillemotleft>n-1\\<guillemotright>)\\<^sub>a)))) \\<and>\n          head\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u head\\<^sub>u(tail\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)))\n        ))\"\n\ndefinition PreFD1 :: \"(nat \\<Rightarrow> real) \\<Rightarrow> (dummyT sim_state_scheme, dummyT sim_state_scheme) rel_des\" where\n\"PreFD1 x = (true \\<turnstile>\\<^sub>r\n        (\\<^bold>\\<forall> n::nat \\<bullet> \n          (((#\\<^sub>u($inouts (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) =\\<^sub>u 1) \\<and> ((#\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) =\\<^sub>u 2) \\<and> \n          (head\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u head\\<^sub>u($inouts (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) \\<and> \n          (head\\<^sub>u(tail\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) =\\<^sub>u (\\<guillemotleft>x n\\<guillemotright>))) ))\"\n\ndefinition PostFD1 :: \"(nat \\<Rightarrow> real) \\<Rightarrow> (dummyT sim_state_scheme, dummyT sim_state_scheme) rel_des\" where\n\"PostFD1 x = (true \\<turnstile>\\<^sub>r\n        (\\<^bold>\\<forall> n::nat \\<bullet> \n          (((#\\<^sub>u($inouts (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) =\\<^sub>u 2) \\<and> ((#\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) =\\<^sub>u 1) \\<and> \n          (head\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u head\\<^sub>u($inouts (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) \\<and> \n          (head\\<^sub>u(tail\\<^sub>u($inouts (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) =\\<^sub>u (\\<guillemotleft>x n\\<guillemotright>))) ))\"\n\ndefinition Integrator :: \"(dummyT sim_state_scheme, dummyT sim_state_scheme) rel_des\" where \n\"Integrator = (true \\<turnstile>\\<^sub>r\n        (\\<^bold>\\<forall> n::nat \\<bullet> \n          (((#\\<^sub>u($inouts (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) =\\<^sub>u 1) \\<and> ((#\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) =\\<^sub>u 1) \\<and> \n          (head\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u head\\<^sub>u($inouts (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) + \n                (if n = 0 then 0 else head\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n-1\\<guillemotright>)\\<^sub>a))))\n        ))\"\n\ndefinition IntegratorWCFeedback :: \"(dummyT sim_state_scheme, dummyT sim_state_scheme) rel_des\" where\n\"IntegratorWCFeedback = (\\<^bold>\\<exists> (x) \\<bullet> ((PreFD1 x) ;; IntegratorWOFeedback ;; (PostFD1 x)))\"\n\n(*\nlemma \"IntegratorWCFeedback = Integrator\"\napply (simp add: IntegratorWCFeedback_def Integrator_def)\napply (simp add: PreFD1_def PostFD1_def IntegratorWOFeedback_def)\napply (rel_auto)\napply (metis not_gr0)\n-- {* Goal 2: *}\nproof - (* 2 *)\n  fix inouts\\<^sub>v :: \"nat \\<Rightarrow> real list\" and inouts\\<^sub>v':: \"nat \\<Rightarrow> real list\" and ok\\<^sub>v and ok\\<^sub>v'\n  assume s1: \"ok\\<^sub>v\" and \"ok\\<^sub>v'\"\n  assume s2: \"\\<forall>x. (x = 0 \\<longrightarrow> length(inouts\\<^sub>v 0) = Suc 0 \\<and> length(inouts\\<^sub>v' 0) = Suc 0 \\<and> \n                  hd (inouts\\<^sub>v' 0) = hd (inouts\\<^sub>v 0)) \\<and>\n           (0 < x \\<longrightarrow>  length(inouts\\<^sub>v x) = Suc 0 \\<and> length(inouts\\<^sub>v' x) = Suc 0 \\<and> \n                  hd (inouts\\<^sub>v' x) = hd (inouts\\<^sub>v x) + hd (inouts\\<^sub>v' (x - Suc 0)))\"\n  show \"\\<exists>x inouts\\<^sub>v''.\n          (\\<forall>xa. length(inouts\\<^sub>v xa) = Suc 0 \\<and> length(inouts\\<^sub>v'' xa) = 2 \\<and> \n              hd (inouts\\<^sub>v'' xa) = hd (inouts\\<^sub>v xa) \\<and> hd (tl (inouts\\<^sub>v'' xa)) = x xa) \\<and>\n          (\\<exists>inouts\\<^sub>v.\n              (\\<forall>x. (x = 0 \\<longrightarrow> length(inouts\\<^sub>v'' 0) = 2 \\<and> length(inouts\\<^sub>v 0) = 2 \\<and> \n                        hd (inouts\\<^sub>v 0) = hd (inouts\\<^sub>v'' 0) \\<and> hd (inouts\\<^sub>v 0) = hd (tl (inouts\\<^sub>v 0))) \\<and>\n                   (0 < x \\<longrightarrow> length(inouts\\<^sub>v'' x) = 2 \\<and> length(inouts\\<^sub>v x) = 2 \\<and>\n                      hd (inouts\\<^sub>v x) = hd (inouts\\<^sub>v'' x) + hd (tl (inouts\\<^sub>v'' (x - Suc 0))) \\<and>\n                      hd (inouts\\<^sub>v x) = hd (tl (inouts\\<^sub>v x)))) \\<and>\n              (\\<forall>xa. length(inouts\\<^sub>v xa) = 2 \\<and> length(inouts\\<^sub>v' xa) = Suc 0 \\<and> \n                  hd (inouts\\<^sub>v' xa) = hd (inouts\\<^sub>v xa) \\<and> hd (tl (inouts\\<^sub>v xa)) = x xa))\"\n  -- {* Goal 2.1: unroll forall*}\n  proof - (* 2.1 *)\n    let ?x = \"(\\<lambda>n. (if n = 0 then hd (inouts\\<^sub>v n) else hd (inouts\\<^sub>v n) + hd (inouts\\<^sub>v' (n - Suc 0))))\"\n    obtain x and inouts\\<^sub>v'' where \n      p: \"x = ?x\"  and \"inouts\\<^sub>v'' = (\\<lambda>n.[hd (inouts\\<^sub>v n), ?x n])\"\n        by auto\n    (* P(x) *)\n    let ?P = \"\\<lambda>u v . (\\<forall>xa. length(inouts\\<^sub>v xa) = Suc 0 \\<and> length(u xa) = 2 \\<and> \n            hd (u xa) = hd (inouts\\<^sub>v xa) \\<and> hd (tl (u xa)) = v xa) \\<and>\n        (\\<exists>inouts\\<^sub>v.\n            (\\<forall>x. (x = 0 \\<longrightarrow> length(u 0) = 2 \\<and> length(inouts\\<^sub>v 0) = 2 \\<and> \n                      hd (inouts\\<^sub>v 0) = hd (u 0) \\<and> hd (inouts\\<^sub>v 0) = hd (tl (inouts\\<^sub>v 0))) \\<and>\n                 (0 < x \\<longrightarrow> length(u x) = 2 \\<and> length(inouts\\<^sub>v x) = 2 \\<and>\n                    hd (inouts\\<^sub>v x) = hd (u x) + hd (tl (u (x - Suc 0))) \\<and>\n                    hd (inouts\\<^sub>v x) = hd (tl (inouts\\<^sub>v x)))) \\<and>\n            (\\<forall>xa. length(inouts\\<^sub>v xa) = 2 \\<and> length(inouts\\<^sub>v' xa) = Suc 0 \\<and> \n                hd (inouts\\<^sub>v' xa) = hd (inouts\\<^sub>v xa) \\<and> hd (tl (inouts\\<^sub>v xa)) = v xa))\"\n    -- {* Goal 2.1.1 : unroll exists *}\n    have Px: \"?P (\\<lambda>n.[hd (inouts\\<^sub>v n), ?x n]) (?x)\"\n      proof - (* 2.1.1 *)\n        have 0: \"\\<forall>xa. length(inouts\\<^sub>v xa) = Suc 0\"\n          using neq0_conv s2 by blast\n        -- {* Goal 2.1.1.1 : 1st conjunction *}\n        then have 1: \"(\\<forall>xa. length(inouts\\<^sub>v xa) = Suc 0 \\<and>\n          length([hd (inouts\\<^sub>v xa), ?x xa]) = 2 \\<and> hd [hd (inouts\\<^sub>v xa), ?x xa] =\n          hd (inouts\\<^sub>v xa) \\<and>\n          hd (tl [hd (inouts\\<^sub>v xa), ?x xa]) = ?x xa)\"\n          by simp\n        -- {* Goal 2.1.1.2 : 2nd conjunction *}\n        let ?P2 = \"(\\<lambda>inouts\\<^sub>v'' :: nat\\<Rightarrow>real list.\n          (\\<forall>x. (x = 0 \\<longrightarrow>\n            length([hd (inouts\\<^sub>v 0), ?x 0]) = 2 \\<and>\n            length(inouts\\<^sub>v'' 0) = 2 \\<and>\n            hd (inouts\\<^sub>v'' 0) = hd [hd (inouts\\<^sub>v 0), ?x 0] \\<and>\n            hd (inouts\\<^sub>v'' 0) = hd (tl (inouts\\<^sub>v'' 0))) \\<and>\n           (0 < x \\<longrightarrow>\n            length([hd (inouts\\<^sub>v x), ?x x]) = 2 \\<and>\n            length(inouts\\<^sub>v'' x) = 2 \\<and>\n            hd (inouts\\<^sub>v'' x) = hd [hd (inouts\\<^sub>v x), ?x x] +\n            hd (tl [hd (inouts\\<^sub>v (x - Suc 0)),\n                    if x - Suc 0 = 0 then hd (inouts\\<^sub>v (x - Suc 0))\n                    else hd (inouts\\<^sub>v (x - Suc 0)) + hd (inouts\\<^sub>v' (x - Suc 0 - Suc 0))]) \\<and>\n            hd (inouts\\<^sub>v'' x) = hd (tl (inouts\\<^sub>v'' x)))) \\<and>\n          (\\<forall>xa. length(inouts\\<^sub>v'' xa) = 2 \\<and>\n            length(inouts\\<^sub>v' xa) = Suc 0 \\<and>\n            hd (inouts\\<^sub>v' xa) = hd (inouts\\<^sub>v'' xa) \\<and>\n            hd (tl (inouts\\<^sub>v'' xa)) =\n            (if xa = 0 then hd (inouts\\<^sub>v xa) else hd (inouts\\<^sub>v xa) + hd (inouts\\<^sub>v' (xa - Suc 0)))))\"\n        -- {* Goal 2.1.1.2 : 2nd conjunction *}\n        have 2: \"(\\<exists>inouts\\<^sub>v''. (?P2 inouts\\<^sub>v''))\"\n          proof - (* 2.1.1 *)\n            -- {* Goal 2.1.1.2.1 : unroll exists *}\n            let ?t = \"\\<lambda>n.(hd (inouts\\<^sub>v n) + (\n                  if n = 0 then 0 else \n                    if n = 1 then hd (inouts\\<^sub>v (n-1)) else \n                      hd (inouts\\<^sub>v (n-1)) + hd (inouts\\<^sub>v' (n - 2))))\"\n            obtain inouts\\<^sub>v'' where p: \"inouts\\<^sub>v''= (\\<lambda>n.[?t n,?t n])\"\n              by auto\n            have P2x: \"?P2 (\\<lambda>n.[?t n,?t n])\"\n              proof - (* 2.1.1.1 *)\n                -- {* Goal 2.1.1.2.1.1 : 1st conjunction *}\n                have 11: \"\\<forall>x. (x = 0 \\<longrightarrow>\n                  length([hd (inouts\\<^sub>v 0), ?x 0]) = 2 \\<and>\n                  length([?t 0, ?t 0]) = 2 \\<and>\n                  hd [?t 0, ?t 0] = hd [hd (inouts\\<^sub>v 0), ?x 0] \\<and>\n                  hd [?t 0, ?t 0] = hd (tl [?t 0, ?t 0]))\"\n                  by simp\n                -- {* Goal 2.1.1.2.1.2 : 2st conjunction *}\n                have 12: \"(\\<forall>x.(0 < x \\<longrightarrow>\n                  length([hd (inouts\\<^sub>v x), ?x 0]) = 2 \\<and>\n                  length([?t x, ?t x]) = 2 \\<and>\n                  hd [?t x, ?t x] = hd [hd (inouts\\<^sub>v x), ?x x] +\n                      hd (tl [hd (inouts\\<^sub>v (x - Suc 0)),\n                          if x - Suc 0 = 0 then hd (inouts\\<^sub>v (x - Suc 0))\n                          else hd (inouts\\<^sub>v (x - Suc 0)) + hd (inouts\\<^sub>v' (x - Suc 0 - Suc 0))]) \\<and>\n                  hd [?t x, ?t x] = hd (tl [?t x, ?t x])))\"\n                  by (smt Suc_1 Suc_diff_eq_diff_pred diff_Suc_1 length_Cons less_imp_Suc_add list.sel(1) list.sel(3) list.size(3) neq0_conv numeral_1_eq_Suc_0 numeral_One pos2)\n                -- {* Goal 2.1.1.2.1.3 : 3rd conjunction *}\n                have 13: \"(\\<forall>xa. length([?t xa, ?t xa]) =  2 \\<and>\n                    length(inouts\\<^sub>v' xa) = Suc 0 \\<and>\n                    hd (inouts\\<^sub>v' xa) = hd [?t xa, ?t xa] \\<and>\n                    hd (tl [?t xa, ?t xa]) = (?x xa))\"\n                  using \"12\" s2 by auto\n                show ?thesis using 11 12 13\n                  by simp\n              qed -- {* Goal 2.1.1.2.1 : 1st conjunction *} (* 2.1.1.1 *)\n            show ?thesis using P2x \n              sorry (* proof found but slow *)\n          qed -- {* Goal 2.1.1.2 *} (* 2.1.1 *)\n        then show ?thesis using 1 2\n          by blast\n      qed  -- {* Goal 2.1.1 *} (* 2.1 *)\n    then show ?thesis using Px \n      by (metis \\<open>\\<And>thesis. (\\<And>x inouts\\<^sub>v''. \\<lbrakk>x = (\\<lambda>n. if n = 0 then hd (inouts\\<^sub>v n) else hd (inouts\\<^sub>v n) + hd (inouts\\<^sub>v' (n - Suc 0))); inouts\\<^sub>v'' = (\\<lambda>n. [hd (inouts\\<^sub>v n), if n = 0 then hd (inouts\\<^sub>v n) else hd (inouts\\<^sub>v n) + hd (inouts\\<^sub>v' (n - Suc 0))])\\<rbrakk> \\<Longrightarrow> thesis) \\<Longrightarrow> thesis\\<close>)\n  qed (* 2 *)\nqed\n*)\n\n(*\nlemma \"(inps IntegratorWOFeedback) = 2\"\nproof -\n  have 1: \"IntegratorWOFeedback is HDim 2\"\n    apply (simp add: IntegratorWOFeedback_def Healthy_def sim_blocks)\n    apply (ndes_simp) \n    sorry\n  then show ?thesis\n    apply (simp add: inps_dim)\n  done\nqed\n*)\n(*\nlemma \"IntegratorWOFeedback f\\<^sub>D [(1,1)] = Integrator\"\napply (simp add: sim_blocks IntegratorWOFeedback_def Integrator_def)\napply (rel_auto)\n  apply blast\n  apply blast\n  apply blast\n(*  apply blast\n  apply blast\n  apply blast *)\nsorry\n\nlemma \"IntegratorWCFeedback = IntegratorWOFeedback f\\<^sub>D [(1,1)]\"\napply (simp add: sim_blocks IntegratorWCFeedback_def PreFD1_def PostFD1_def IntegratorWOFeedback_def)\napply (rel_auto)\n  apply blast\n  apply blast\n  apply blast\n(*  apply blast\n  apply blast\n  apply blast *)\nsorry\n*)\n\nsubsection {* Examples *}\n\nsubsubsection {* PID Integrator *}\nfun listsum :: \"real list \\<Rightarrow> real\" where\n  \"listsum [] = 0\" |\n  \"listsum (x # xs) = x + listsum xs\" \n\nterm \"(map nat [0..n])\"\nterm \"head\\<^sub>u($inouts (\\<guillemotleft>x\\<guillemotright>)\\<^sub>a)\"\nterm \"(\\<lambda>x \\<bullet> head\\<^sub>u($inouts (\\<guillemotleft>x\\<guillemotright>)\\<^sub>a))\"\nterm \"(\\<guillemotleft>map\\<guillemotright> (\\<lambda>x \\<bullet> head\\<^sub>u($inouts (\\<guillemotleft>x\\<guillemotright>)\\<^sub>a))\\<^sub>a (\\<guillemotleft>(map nat [0..n])\\<guillemotright>)\\<^sub>a)\"\nterm \"(\\<guillemotleft>list_sum\\<guillemotright> (\\<guillemotleft>map\\<guillemotright> (\\<lambda>x \\<bullet> head\\<^sub>u($inouts (\\<guillemotleft>x\\<guillemotright>)\\<^sub>a))\\<^sub>a (\\<guillemotleft>(map nat [0..n])\\<guillemotright>)\\<^sub>a)\\<^sub>a) + 0\"\nterm \"head\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)\"\nterm \"head\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u head\\<^sub>u($inouts (\\<guillemotleft>x\\<guillemotright>)\\<^sub>a)\"\n(*\nterm \"(head\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u \n  ((\\<guillemotleft>list_sum\\<guillemotright> (\\<guillemotleft>map\\<guillemotright> (\\<lambda>x \\<bullet> head\\<^sub>u($inouts (\\<guillemotleft>x\\<guillemotright>)\\<^sub>a))\\<^sub>a (\\<guillemotleft>(map nat [0..n])\\<guillemotright>)\\<^sub>a)\\<^sub>a) + 0))\"\n*)\n\nlemma sum_1:\n  fixes n :: \"nat\" and x :: \"nat \\<Rightarrow> real\" and y :: \"nat \\<Rightarrow> real\"\n  assumes \"\\<forall>n. (x(n) = y(n) + (if (n = 0) then 1 else x(n-1)))\"\n  shows \"(x(n) = list_sum (map (\\<lambda>x. y(x)) (map nat [0..n])) + 1)\"\nproof (induction n)\n  case 0\n  then show ?case \n    proof -\n      from assms have 0: \"x(0) = y(0) + 1\"\n        by simp\n      have 1: \"list_sum (map (\\<lambda>x. y(x)) (map nat [0..0])) = y(0)\"\n        by (simp add: upto.simps)\n      from 0 1 show ?thesis \n        by auto\n    qed\nnext\n  case (Suc n)\n  then show ?case \n    proof -\n      have 00: \"(map y (map nat [0..int (Suc n)])) = (map y (map nat [0..int n])) @ [y(Suc n)]\"\n        by (smt list.simps(8) list.simps(9) map_append nat_int of_nat_0_le_iff of_nat_Suc upto_rec2)\n      then have 01: \"(foldr op + (map y (map nat [0..int (Suc n)])) 0) = \n                     (foldr op + (map y (map nat [0..int (n)])) 0) + y(Suc n)\"\n        sorry\n      from assms have 0: \"x (Suc n) = y(Suc n) + x(n)\"\n        by simp\n      then have 1: \"... = y(Suc n) + (foldr op + (map y (map nat [0..int n])) 0 + 1)\"\n        by (simp add: Suc.IH)\n      then have 2: \"... = (foldr op + (map y (map nat [0..int (Suc n)])) 0 + 1)\"\n        using \"01\" by auto\n      show ?thesis\n       using \"0\" \"2\" Suc.IH by linarith\n    qed\nqed\n\n(*\nlemma pid_int_l1:\n  shows \"\n  (true \\<turnstile>\\<^sub>r\n        (\\<^bold>\\<forall> n::nat \\<bullet> \n          (((#\\<^sub>u($inouts (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) =\\<^sub>u 1) \\<and> ((#\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) =\\<^sub>u 1) \\<and> \n          (head\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u head\\<^sub>u($inouts (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) + \n                (if n = 0 then 0 else head\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n-1\\<guillemotright>)\\<^sub>a))))\n        )\n  )\n   = \n  (true \\<turnstile>\\<^sub>r\n        (\\<^bold>\\<forall> n::nat \\<bullet> \n          (((#\\<^sub>u($inouts (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) =\\<^sub>u 1) \\<and> ((#\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) =\\<^sub>u 1) \\<and> \n          (head\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u ((\\<guillemotleft>list_sum\\<guillemotright> (\\<guillemotleft>map\\<guillemotright> (\\<lambda>x \\<bullet> head\\<^sub>u($inouts (\\<guillemotleft>x\\<guillemotright>)\\<^sub>a))\\<^sub>a (\\<guillemotleft>(map nat [0..n])\\<guillemotright>)\\<^sub>a)\\<^sub>a) + 0)))\n        )\n      )\"\nsorry\n\n(* (head\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u ((\\<guillemotleft>sum_list\\<guillemotright> (\\<guillemotleft>map\\<guillemotright> (\\<lambda>x \\<bullet> head\\<^sub>u($inouts (\\<guillemotleft>x\\<guillemotright>)\\<^sub>a))\\<^sub>a (\\<guillemotleft>[0..n]\\<guillemotright>)\\<^sub>a)) + 0) *)\n\nlemma pid_int:\n  shows \"((Id \\<parallel>\\<^sub>D (UnitDelay 0)) ;; Sum) =\n      (true \\<turnstile>\\<^sub>r\n        (\\<^bold>\\<forall> n::nat \\<bullet> \n          (((#\\<^sub>u($inouts (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) =\\<^sub>u 2) \\<and> ((#\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) =\\<^sub>u 1) \\<and> \n          (head\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u head\\<^sub>u($inouts (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) + \n                (if n = 0 then 0 else (\\<guillemotleft>nth\\<guillemotright> ($inouts (\\<guillemotleft>n-1\\<guillemotright>)\\<^sub>a)\\<^sub>a (1)\\<^sub>a))))\n        )\n      )\"\nsorry\n\nterm \" (\\<lambda>x. head\\<^sub>u($inouts (\\<guillemotleft>x\\<guillemotright>)\\<^sub>a))\"\nterm \"map (\\<lambda>x. head\\<^sub>u($inouts (\\<guillemotleft>x\\<guillemotright>)\\<^sub>a)) (map nat [0..n])\"\n\nlemma pid_int_feed:\n  shows \"(true \\<turnstile>\\<^sub>r\n        (\\<^bold>\\<forall> n::nat \\<bullet> \n          (((#\\<^sub>u($inouts (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) =\\<^sub>u 1) \\<and> ((#\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) =\\<^sub>u 1) \\<and> \n          (head\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u head\\<^sub>u($inouts (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) + \n                (if n = 0 then 1 else head\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n-1\\<guillemotright>)\\<^sub>a))))\n        )\n      ) = (true \\<turnstile>\\<^sub>r\n        (\\<^bold>\\<forall> n::nat \\<bullet> \n          (((#\\<^sub>u($inouts (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) =\\<^sub>u 1) \\<and> ((#\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a)) =\\<^sub>u 1) \\<and> \n          (head\\<^sub>u($inouts\\<acute> (\\<guillemotleft>n\\<guillemotright>)\\<^sub>a) =\\<^sub>u (\\<guillemotleft>list_sum\\<guillemotright> (map (\\<lambda>x. head\\<^sub>u($inouts (\\<guillemotleft>x\\<guillemotright>)\\<^sub>a)) (map (nat) ([0..n])))\\<^sub>a) + 1))\n        )\n      )\"\napply (rel_auto)\n*)\n\n\nend", "meta": {"author": "RandallYe", "repo": "Compositional_AG_Reasoning_Simulink_UTP", "sha": "2fd13e1b22d18855093f15969c761644c8cf4cb6", "save_path": "github-repos/isabelle/RandallYe-Compositional_AG_Reasoning_Simulink_UTP", "path": "github-repos/isabelle/RandallYe-Compositional_AG_Reasoning_Simulink_UTP/Compositional_AG_Reasoning_Simulink_UTP-2fd13e1b22d18855093f15969c761644c8cf4cb6/simu_contract_real_example.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.5, "lm_q1q2_score": 0.294444565383916}}
{"text": "theory Tools \nimports \"HOL.HOL\"\nkeywords \"close\" :: \"prf_script\" % \"proof\"\nbegin\n\nsubsection {* \"close\" keyword *}\n\ntxt \\<open>See @{file \"tools.ML\"}\\<close>\n\nsubsection {* Simplifier modulo equivalence relation *}\n\ntxt {* See also @{url \"http://stackoverflow.com/q/30573837/2646248\"} *}\n\ndefinition fun_equiv :: \"('a \\<Rightarrow> 'b) \\<Rightarrow> 'a \\<Rightarrow> 'a \\<Rightarrow> bool\" where \"fun_equiv f x y == f x = f y\"\nlemma fun_equiv_refl: \"fun_equiv f x x\" by(simp add: fun_equiv_def)\n\nML_file \"tools.ML\"\n\nend\n", "meta": {"author": "dominique-unruh", "repo": "IsaCrypt", "sha": "1abc2041871af7b758adcc914b83f0d9135ec129", "save_path": "github-repos/isabelle/dominique-unruh-IsaCrypt", "path": "github-repos/isabelle/dominique-unruh-IsaCrypt/IsaCrypt-1abc2041871af7b758adcc914b83f0d9135ec129/Tools.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5273165233795672, "lm_q2_score": 0.5583269943353745, "lm_q1q2_score": 0.294415049561893}}
{"text": "theory Monitor_Code\n  imports \"HOL-Library.Code_Target_Nat\" \"Containers.Containers\" Monitor Preliminaries\nbegin\n\nderive (eq) ceq enat\n\ninstantiation enat :: ccompare begin\n\ndefinition ccompare_enat :: \"enat comparator option\" where\n  \"ccompare_enat = Some (\\<lambda>x y. if x = y then order.Eq else if x < y then order.Lt else order.Gt)\"\n\ninstance by intro_classes\n    (auto simp: ccompare_enat_def split: if_splits intro!: comparator.intro)\n\nend\n\ncode_printing\n  code_module \"IArray\" \\<rightharpoonup> (OCaml)\n\\<open>module IArray : sig\n  val length' : 'a array -> Z.t\n  val sub' : 'a array * Z.t -> 'a\nend = struct\n\nlet length' xs = Z.of_int (Array.length xs);;\n\nlet sub' (xs, i) = Array.get xs (Z.to_int i);;\n\nend\\<close> for type_constructor iarray constant IArray.length' IArray.sub'\n\ncode_reserved OCaml IArray\n\ncode_printing\n  type_constructor iarray \\<rightharpoonup> (OCaml) \"_ array\"\n| constant iarray_of_list \\<rightharpoonup> (OCaml) \"Array.of'_list\"\n| constant IArray.list_of \\<rightharpoonup> (OCaml) \"Array.to'_list\"\n| constant IArray.length' \\<rightharpoonup> (OCaml) \"IArray.length'\"\n| constant IArray.sub' \\<rightharpoonup> (OCaml) \"IArray.sub'\"\n\nlemma iarray_list_of_inj: \"IArray.list_of xs = IArray.list_of ys \\<Longrightarrow> xs = ys\"\n  by (cases xs; cases ys) auto\n\ninstantiation iarray :: (ccompare) ccompare\nbegin\n\ndefinition ccompare_iarray :: \"('a iarray \\<Rightarrow> 'a iarray \\<Rightarrow> order) option\" where\n  \"ccompare_iarray = (case ID CCOMPARE('a list) of None \\<Rightarrow> None\n  | Some c \\<Rightarrow> Some (\\<lambda>xs ys. c (IArray.list_of xs) (IArray.list_of ys)))\"\n\ninstance\n  apply standard\n  apply unfold_locales\n  using comparator.sym[OF ID_ccompare'] comparator.weak_eq[OF ID_ccompare']\n    comparator.comp_trans[OF ID_ccompare'] iarray_list_of_inj\n    apply (auto simp: ccompare_iarray_def split: option.splits)\n   apply blast+\n  done\n\nend\n\nderive (rbt) mapping_impl iarray\n\ndefinition mk_db :: \"String.literal list \\<Rightarrow> String.literal set\" where \"mk_db = set\"\n\ndefinition init_vydra_string_enat :: \"_ \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> (String.literal, enat, 'e) vydra\" where\n  \"init_vydra_string_enat = init_vydra\"\ndefinition run_vydra_string_enat :: \" _  \\<Rightarrow> (String.literal, enat, 'e) vydra \\<Rightarrow> _\" where\n  \"run_vydra_string_enat = run_vydra\"\ndefinition progress_enat :: \"(String.literal, enat) formula \\<Rightarrow> enat list \\<Rightarrow> nat\" where\n  \"progress_enat = progress\"\ndefinition bounded_future_fmla_enat :: \"(String.literal, enat) formula \\<Rightarrow> bool\" where\n  \"bounded_future_fmla_enat = bounded_future_fmla\"\ndefinition wf_fmla_enat :: \"(String.literal, enat) formula \\<Rightarrow> bool\" where\n  \"wf_fmla_enat = wf_fmla\"\ndefinition mdl2mdl'_enat :: \"(String.literal, enat) formula \\<Rightarrow> (String.literal, enat) Preliminaries.formula\" where\n  \"mdl2mdl'_enat = mdl2mdl'\"\ndefinition interval_enat :: \"enat \\<Rightarrow> enat \\<Rightarrow> bool \\<Rightarrow> bool \\<Rightarrow> enat \\<I>\" where\n  \"interval_enat = interval\"\ndefinition rep_interval_enat :: \"enat \\<I> \\<Rightarrow> enat \\<times> enat \\<times> bool \\<times> bool\" where\n  \"rep_interval_enat = Rep_\\<I>\"\n\ndefinition init_vydra_string_ereal :: \"_ \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> (String.literal, ereal, 'e) vydra\" where\n  \"init_vydra_string_ereal = init_vydra\"\ndefinition run_vydra_string_ereal :: \" _  \\<Rightarrow> (String.literal, ereal, 'e) vydra \\<Rightarrow> _\" where\n  \"run_vydra_string_ereal = run_vydra\"\ndefinition progress_ereal :: \"(String.literal, ereal) formula \\<Rightarrow> ereal list \\<Rightarrow> real\" where\n  \"progress_ereal = progress\"\ndefinition bounded_future_fmla_ereal :: \"(String.literal, ereal) formula \\<Rightarrow> bool\" where\n  \"bounded_future_fmla_ereal = bounded_future_fmla\"\ndefinition wf_fmla_ereal :: \"(String.literal, ereal) formula \\<Rightarrow> bool\" where\n  \"wf_fmla_ereal = wf_fmla\"\ndefinition mdl2mdl'_ereal :: \"(String.literal, ereal) formula \\<Rightarrow> (String.literal, ereal) Preliminaries.formula\" where\n  \"mdl2mdl'_ereal = mdl2mdl'\"\ndefinition interval_ereal :: \"ereal \\<Rightarrow> ereal \\<Rightarrow> bool \\<Rightarrow> bool \\<Rightarrow> ereal \\<I>\" where\n  \"interval_ereal = interval\"\ndefinition rep_interval_ereal :: \"ereal \\<I> \\<Rightarrow> ereal \\<times> ereal \\<times> bool \\<times> bool\" where\n  \"rep_interval_ereal = Rep_\\<I>\"\n\nlemma tfin_enat_code[code]: \"(tfin :: enat set) = Collect_set (\\<lambda>x. x \\<noteq> \\<infinity>)\"\n  by (auto simp: tfin_enat_def)\n\nlemma tfin_ereal_code[code]: \"(tfin :: ereal set) = Collect_set (\\<lambda>x. x \\<noteq> -\\<infinity> \\<and> x \\<noteq> \\<infinity>)\"\n  by (auto simp: tfin_ereal_def)\n\nlemma Ball_atms[code_unfold]: \"Ball (atms r) P = list_all P (collect_subfmlas r [])\"\n  using collect_subfmlas_atms[where ?phis=\"[]\"]\n  by (auto simp: list_all_def)\n\nlemma MIN_fold: \"(MIN x\\<in>set (z # zs). f x) = fold min (map f zs) (f z)\"\n  by (metis Min.set_eq_fold list.set_map list.simps(9))\n\ndeclare progress.simps(1-8)[code]\n\nlemma progress_matchP_code[code]:\n  \"progress (MatchP I r) ts = (case collect_subfmlas r [] of x # xs \\<Rightarrow> fold min (map (\\<lambda>f. progress f ts) xs) (progress x ts))\"\n  using collect_subfmlas_atms[where ?r=r and ?phis=\"[]\"] atms_nonempty[of r]\n  by (auto split: list.splits) (smt (z3) MIN_fold[where ?f=\"\\<lambda>f. progress f ts\"] list.simps(15))\n\nlemma progress_matchF_code[code]:\n  \"progress (MatchF I r) ts = (if length ts = 0 then 0 else\n  (let k = min (length ts - 1) (case collect_subfmlas r [] of x # xs \\<Rightarrow> fold min (map (\\<lambda>f. progress f ts) xs) (progress x ts)) in\n   Min {j \\<in> {..k}. memR (ts ! j) (ts ! k) I}))\"\n  by (auto simp: progress_matchP_code[unfolded progress.simps])\n\nexport_code init_vydra_string_enat run_vydra_string_enat progress_enat bounded_future_fmla_enat wf_fmla_enat mdl2mdl'_enat\n  Bool Preliminaries.Bool enat interval_enat rep_interval_enat nat_of_integer integer_of_nat mk_db\n  in OCaml module_name VYDRA file_prefix \"verified\"\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/VYDRA_MDL/Monitor_Code.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5583269943353745, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.29441504956189296}}
{"text": "theory NP4_Optimising_Action_Semantics\n  imports\n  NP4_Optimising_Action_Values\n(*\n    This file contains the semantics and progression rules to capture the behaviour of\n    P4's action constructs. This mostly includes the statements present in P4, and the\n    way these statements alter the state.\n\n    Note: the state is a mapping from vnames to values (vals)\n*)\n\nbegin\n(* ============================================================================================================== *)\n(*                                      SMALL STEP SEMANTICS RULES                                                *)\n(* ============================================================================================================== *)\n\n(* The way P4 statements update the state and progress. The natural number included is to prove\n   that computation always progresses. With every step of the computation this number always\n   decreases, indicating progression and ultimately termination. Note that method invocations and\n   switch statements are omitted as these can be modelled with the present statements as well. *)\ninductive small_step :: \"(statOrDecl * state * nat) \\<Rightarrow> (statOrDecl * state * nat) \\<Rightarrow> bool\" (infix \"\\<leadsto>\" 55)\n  where\n    Exit:       \"(ExitStat, s, n) \\<leadsto> (EmptyStat, s, n-1)\"\n  | CondTrue:   \"eval e s (BOOL True) \\<Longrightarrow> ((ConditionalStat e stmt1 stmt2), s, n) \\<leadsto> (stmt1, s, n-1)\"\n  | CondFalse:  \"eval e s (BOOL False) \\<Longrightarrow> ((ConditionalStat e stmt1 stmt2), s, n) \\<leadsto> (stmt2, s, n-1)\"\n  | EmptyBlock: \"(BlockStat [], s, n) \\<leadsto> (EmptyStat, s, n-1)\" \n  | EmptyFirst: \"(BlockStat (EmptyStat # rest), s, n) \\<leadsto> (BlockStat rest, s, n-1)\"\n  | FullBlock:  \"(stmt, s, n) \\<leadsto> (stmt', s', n') \\<Longrightarrow> n' \\<le> n \\<Longrightarrow> (BlockStat (stmt # rest), s, n) \\<leadsto> (BlockStat (stmt' # rest), s', n')\"\n  | Assign:     \"eval e s v \\<Longrightarrow> (AssignmentStat vName e, s, n) \\<leadsto> (EmptyStat, s (vName := v), n-1)\"\n  | VarDecl:    \"(VariableDecl vName None, s, n) \\<leadsto> (EmptyStat, s, n-1)\"\n  | VarInit:    \"eval e s v \\<Longrightarrow> (VariableDecl vName (Some e), s, n) \\<leadsto> (EmptyStat, s (vName := v), n-1)\"\n  | ConstInit:  \"eval e s v \\<Longrightarrow> (ConstantDecl vName e, s, n) \\<leadsto> (EmptyStat, s (vName := v), n-1)\"\n\ndeclare small_step.intros[simp, intro]\n\ninductive_cases [elim!]: \"(EmptyStat, s, n) \\<leadsto> ct\" \"(ExitStat, s, n) \\<leadsto> ct\" \"(ConditionalStat e stmt1 stmt2, s, n) \\<leadsto> ct\"\n  \"(BlockStat stmts, s, n) \\<leadsto> ct\" \"(AssignmentStat l e, s, n) \\<leadsto> ct\" \"(VariableDecl l e, s, n) \\<leadsto> ct\" \"(ConstantDecl l e, s, n) \\<leadsto> ct\"\n\nlemmas small_step_induct = small_step.induct[split_format(complete)]\n\nlemma small_step_deterministic: \"cs \\<leadsto> cs' \\<Longrightarrow> cs \\<leadsto> cs'' \\<Longrightarrow> cs' = cs''\"\nproof (induction arbitrary: cs'' rule: small_step.induct)\nnext case (CondTrue e s stmt1 stmt2 n) thus ?case using eval_deterministic by auto\nnext case (CondFalse e s stmt1 stm2 n stmt2) thus ?case using eval_deterministic by auto\nnext case (Assign e s v vName n) thus ?case using eval_deterministic by auto\nnext case (VarDecl vName s n) thus ?case using eval_deterministic by auto\nnext case (VarInit e s v vName n) thus ?case using eval_deterministic by auto\nnext case (ConstInit e s v vName n) thus ?case using eval_deterministic by auto\nqed auto\n\nlemma step_equal_or_smaller: \"(c, s, n) \\<leadsto> (c', s', n') \\<Longrightarrow> n' \\<le> n\"\n  apply (induction c rule: statOrDecl.induct)\n  apply (auto)\n  done\n\nabbreviation equiv_stmt :: \"statOrDecl \\<Rightarrow> statOrDecl \\<Rightarrow> bool\" (infix \"~\" 50) where\n  \"stmt1 ~ stmt2 \\<equiv> (\\<forall>s t n. ((stmt1, s, n) \\<leadsto> t) = ((stmt2, s, n) \\<leadsto> t))\"\n\nlemma equiv_refl:  \"c ~ c\" by simp\nlemma equiv_sym:   \"(c ~ c') = (c' ~ c)\" by auto\nlemma equiv_trans: \"(c ~ c') \\<Longrightarrow> (c' ~ c'') \\<Longrightarrow> (c ~ c'')\" by simp\n\n(* ============================================================================================================== *)\n(*                                        REFLEXIVE TRANSITIVE CLOSURE                                            *)\n(* ============================================================================================================== *)\n\n(* Define the reflexive transitive closure on the signature of the small-step semantics. *)\ninductive star :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool) \\<Rightarrow> 'a \\<Rightarrow> 'a \\<Rightarrow> bool\"\n  for r :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool)\" where\nrefl:   \"star r x x\" |\nstep:   \"r x y \\<Longrightarrow> star r y z \\<Longrightarrow> star r x z\"\n\nhide_fact (open) refl step\n\nlemma star_trans: \"star r x y \\<Longrightarrow> star r y z \\<Longrightarrow> star r x z\"\n  apply (induction rule: star.induct)\n   apply (assumption)\n  apply (metis star.step)\n  done\n\nlemmas star_induct = star.induct[of \"r:: 'a*'b*'c \\<Rightarrow> 'a*'b*'c \\<Rightarrow> bool\", split_format(complete)]\n\ndeclare star.refl[simp, intro]\n\nlemma star_step1[simp, intro]: \"r x y \\<Longrightarrow> star r x y\"\n  by (metis star.refl star.step)\n\ncode_pred star .\n\n(* The reflexive transitive closure of the small step function yields whether a state is reachable in any number of\n   steps from the starting state and thereby models complete execution. *)\nabbreviation small_steps :: \"(statOrDecl * state * nat) \\<Rightarrow> (statOrDecl * state * nat) \\<Rightarrow> bool\" (infix \"\\<leadsto>*\" 55)\n  where \"x \\<leadsto>* y \\<equiv> star small_step x y\"\n\nlemma star_equal_or_smaller: \"(c, s, n) \\<leadsto>* (c', s', n') \\<Longrightarrow> n' \\<le> n\"\nproof (induction rule: star_induct)\n     case (refl a a b) thus ?case by simp\nnext case (step a a b a a b a a b) thus ?case by (meson dual_order.trans step_equal_or_smaller)\nqed\n\n(* ============================================================================================================== *)\n(*                                     CONDITIONAL EQUIVALENCE PROOFS                                             *)\n(* ============================================================================================================== *)\n\ntype_synonym assn = \"state \\<Rightarrow> bool\"\n\n(*definition equiv_up_to :: \"assn \\<Rightarrow> statOrDecl \\<Rightarrow> statOrDecl \\<Rightarrow> bool\" where \"\"*)\n\ndefinition equiv_up_to :: \"assn \\<Rightarrow> statOrDecl \\<Rightarrow> statOrDecl \\<Rightarrow> bool\" (\"_ \\<Turnstile> _ ~ _\" [50, 0, 10] 50)\n  where\n  \"P \\<Turnstile> stmt1 ~ stmt2 \\<equiv> (\\<forall>s t n. P s \\<longrightarrow> ((stmt1, s, n) \\<leadsto> t) \\<longleftrightarrow> ((stmt2, s, n) \\<leadsto> t))\"\n\nlemma equiv_up_to_True: \"((\\<lambda>_. True) \\<Turnstile> stmt1 ~ stmt2) = (stmt1 ~ stmt2)\"\n  by (simp add: equiv_up_to_def)\n  \nlemma equiv_up_to_weaken: \"P \\<Turnstile> stmt1 ~ stmt2 \\<Longrightarrow> (\\<And>s. P' s \\<Longrightarrow> P s) \\<Longrightarrow> P' \\<Turnstile> stmt1 ~ stmt2\"\n  by (simp add: equiv_up_to_def)\n\nlemma equiv_to_toI: \"(\\<And>s t n. P s \\<Longrightarrow> (stmt1, s, n) \\<leadsto> t = (stmt2, s, n) \\<leadsto> t) \\<Longrightarrow> P \\<Turnstile> stmt1 ~ stmt2\"\n  by (simp add: equiv_up_to_def)\n\nlemma equiv_up_toD1: \"P \\<Turnstile> stmt1 ~ stmt2 \\<Longrightarrow> (stmt1, s, n) \\<leadsto> t \\<Longrightarrow> P s \\<Longrightarrow> (stmt2, s, n) \\<leadsto> t\"\n  by (unfold equiv_up_to_def) blast\nlemma equiv_up_toD2: \"P \\<Turnstile> stmt1 ~ stmt2 \\<Longrightarrow> (stmt2, s, n) \\<leadsto> t \\<Longrightarrow> P s \\<Longrightarrow> (stmt1, s, n) \\<leadsto> t\"\n  by (unfold equiv_up_to_def) blast\n\nlemma equiv_up_to_refl [simp, intro!]: \"P \\<Turnstile> stmt ~ stmt\"\n  by (auto simp: equiv_up_to_def)\nlemma equiv_up_to_sym: \"(P \\<Turnstile> stmt1 ~ stmt2) = (P \\<Turnstile> stmt2 ~ stmt1)\"\n  by (auto simp: equiv_up_to_def)\nlemma equiv_up_to_trans: \"P \\<Turnstile> stmt1 ~ stmt2 \\<Longrightarrow> P \\<Turnstile> stmt2 ~ stmt3 \\<Longrightarrow> P \\<Turnstile> stmt1 ~ stmt3\"\n  by (auto simp: equiv_up_to_def)\n\n(* ============================================================================================================== *)\n(*                                OPTIMISATION SEMANTIC EQUIVALENCE PROOFS                                        *)\n(* ============================================================================================================== *)\n\ndefinition\n  \"merge t1 t2 = (\\<lambda>m. if t1 m = t2 m then t1 m else None)\"\n\nlemma approx_merge:\n  \"approx t1 s \\<or> approx t2 s \\<Longrightarrow> approx (merge t1 t2) s\"\n  by (smt approx_def merge_def option.distinct(1))\n\nfun defs :: \"statOrDecl \\<Rightarrow> tab \\<Rightarrow> tab\" where\n    \"defs EmptyStat t = t\"\n  | \"defs ExitStat t = t\"\n  | \"defs (ConditionalStat expr stmt1 stmt2) t = merge (defs stmt1 t) (defs stmt2 t)\"\n  | \"defs (BlockStat []) t = t\"\n  | \"defs (BlockStat (stmt # xs)) t = (defs stmt \\<circ> defs (BlockStat xs)) t\"\n  | \"defs (AssignmentStat vName expr) t = (case efold expr t of\n              (BASE bVal) \\<Rightarrow> t (vName := Some (baseToVal bVal))\n            | _ \\<Rightarrow> t (vName := None))\"\n  | \"defs (VariableDecl vName None) t = t\"\n  | \"defs (VariableDecl vName (Some expr)) t = (case efold expr t of\n              (BASE bVal) \\<Rightarrow> t (vName := Some (baseToVal bVal))\n            | _ \\<Rightarrow> t (vName := None))\"\n  | \"defs (ConstantDecl vName expr) t = (case efold expr t of\n              (BASE bVal) \\<Rightarrow> t (vName := Some (baseToVal bVal))\n            | _ \\<Rightarrow> t (vName := None))\"\n\nfun\n  folds :: \"statOrDecl list \\<Rightarrow> tab \\<Rightarrow> statOrDecl list\"\nand\n  fold :: \"statOrDecl \\<Rightarrow> tab \\<Rightarrow> statOrDecl\"\nwhere\n    \"folds [] t = []\"\n  | \"folds (stmt # stmts) t = ((fold stmt t) # (folds stmts (defs stmt t)))\"\n  | \"fold EmptyStat t = EmptyStat\"\n  | \"fold ExitStat t = ExitStat\"\n  | \"fold (ConditionalStat expr stmt1 stmt2) t = (ConditionalStat expr (fold stmt1 t) (fold stmt2 t))\"\n  | \"fold (BlockStat stmts) t = (BlockStat (folds stmts t))\"\n  | \"fold (AssignmentStat vName expr) t = (AssignmentStat vName (efold expr t))\"\n  | \"fold (VariableDecl vName None) t = (VariableDecl vName None)\"\n  | \"fold (VariableDecl vName (Some expr)) t = (VariableDecl vName (Some (efold expr t)))\"\n  | \"fold (ConstantDecl vName expr) t = (ConstantDecl vName (efold expr t))\"\n\nlemma small_step_pres_approx:\n  \"(stmt, s, n) \\<leadsto> (stmt', s', n') \\<Longrightarrow> approx t s \\<Longrightarrow> approx (defs stmt t) s'\"\nproof (induction arbitrary: t rule: small_step_induct)\n  case (Exit s n)\n  then show ?case\n    by simp\nnext\n  case (CondTrue e s stmt1 stmt2 n)\n  then show ?case sorry\nnext\n  case (CondFalse e s stmt1 stmt2 n)\n  then show ?case sorry\nnext\n  case (EmptyBlock s n)\n  then show ?case\n    by simp\nnext\n  case (EmptyFirst rest s n)\n  then show ?case sorry\nnext\n  case (FullBlock stmt s n stmt' s' n' rest)\n  then show ?case sorry\nnext\n  case (Assign e s v vName n)\n  then show ?case sorry\nnext\n  case (VarDecl vName s n)\n  then show ?case sorry\nnext\n  case (VarInit e s v vName n)\n  then show ?case sorry\nnext\n  case (ConstInit e s v vName n)\n  then show ?case sorry\nqed\n\nlemma approx_eq:\n  \"approx t \\<Turnstile> c ~ (fold c t)\"\nproof (induction c arbitrary: t)\n  case EmptyStat\n  then show ?case\n    by simp\nnext\n  case ExitStat\n  then show ?case\n    by simp\nnext\n  case (ConditionalStat x1 c1 c2)\n  then show ?case sorry\nnext\n  case (BlockStat x)\n  then show ?case sorry\nnext\n  case (AssignmentStat x1 x2)\n  then show ?case sorry\nnext\n  case (VariableDecl x1 x2)\n  then show ?case sorry\nnext\n  case (ConstantDecl x1 x2)\n  then show ?case sorry\nqed\n\ntheorem constant_folding_equiv:\n  \"fold c Map.empty ~ c\"\n  by (metis approx_empty approx_eq equiv_up_to_def)\n\n(* ============================================================================================================== *)\n(*                                          TYPING SYSTEM DEFINITION                                              *)\n(* ============================================================================================================== *)\n\ndatatype ty = UINTty | SINTty | IINTty | VINTty | BOOLty | STRINGty | ERRORty | MATCHty\n\n(* Helper function to yield type from val object *)\nfun getValType :: \"val \\<Rightarrow> ty\" where\n    \"getValType (UINT n) = UINTty\"\n  | \"getValType (SINT n) = SINTty\"\n  | \"getValType (IINT n) = IINTty\"\n  | \"getValType (VINT n) = VINTty\"\n  | \"getValType (BOOL b) = BOOLty\"\n  | \"getValType (STRING s) = STRINGty\"\n  | \"getValType (ERROR e) = ERRORty\"\n  | \"getValType (MATCH m) = MATCHty\"\n\nfun getBaseType :: \"baseType \\<Rightarrow> ty\" where\n    \"getBaseType (BUINT n) = UINTty\"\n  | \"getBaseType (BSINT n) = SINTty\"\n  | \"getBaseType (BIINT n) = IINTty\"\n  | \"getBaseType (BVINT n) = VINTty\"\n  | \"getBaseType (BBOOL b) = BOOLty\"\n  | \"getBaseType (BSTRING s) = STRINGty\"\n  | \"getBaseType (BERROR e) = ERRORty\"\n  | \"getBaseType (BMATCH m) = MATCHty\"\n\n(* Mapping from a variable name to a type symbol *)\ntype_synonym typeEnv = \"vname \\<Rightarrow> ty\"\n\n(* The typing environment for expressions. If a case is defined it implies the expression is well-typed\n   given the context of the typing environment. *)\ninductive exprTyping :: \"typeEnv \\<Rightarrow> expression \\<Rightarrow> ty \\<Rightarrow> bool\" (\"(1_/ \\<turnstile>/ (_ ::/ _))\" [50,0,50] 50) where\n(* =============== Base types =============== *)\n    UINT_ty:   \"\\<Gamma> \\<turnstile> (BASE (BUINT n))   :: UINTty\"\n  | SINT_ty:   \"\\<Gamma> \\<turnstile> (BASE (BSINT n))   :: SINTty\"\n  | IINT_ty:   \"\\<Gamma> \\<turnstile> (BASE (BIINT n))   :: IINTty\"\n  | VINT_ty:   \"\\<Gamma> \\<turnstile> (BASE (BVINT n))   :: VINTty\"\n  | BOOL_ty:   \"\\<Gamma> \\<turnstile> (BASE (BBOOL b))   :: BOOLty\"\n  | STRING_ty: \"\\<Gamma> \\<turnstile> (BASE (BSTRING s)) :: STRINGty\"\n  | ERROR_ty:  \"\\<Gamma> \\<turnstile> (BASE (BERROR e))  :: ERRORty\"\n  | MATCH_ty:  \"\\<Gamma> \\<turnstile> (BASE (BMATCH m))  :: MATCHty\"\n(* =============== Miscellaneous expressions =============== *)\n  | TERNEXPR_ty: \"\\<Gamma> \\<turnstile> e1 :: BOOLty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: \\<tau> \\<Longrightarrow> \\<Gamma> \\<turnstile> e3 :: \\<tau> \\<Longrightarrow> \\<Gamma> \\<turnstile> TernExpr e1 e2 e3 :: \\<tau>\"\n(* =============== Variable mapping  =============== *)\n  | VAR_ty: \"\\<Gamma> \\<turnstile> NamedVar vName :: \\<Gamma> vName\"\n(* =============== Operations that yield a single bit (SBIT)  =============== *)\n          (* Empty for now *)\n(* =============== Operations that yield a boolean (BOOL)  =============== *)\n    (* Boolean operations *)\n  | ULNEB_ty: \"\\<Gamma> \\<turnstile> e1 :: BOOLty \\<Longrightarrow> \\<Gamma> \\<turnstile> UNA_LNE e1 :: BOOLty\"\n  | BEQUB_ty: \"\\<Gamma> \\<turnstile> e1 :: BOOLty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: BOOLty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_EQU e1 e2 :: BOOLty\"\n  | BNEQB_ty: \"\\<Gamma> \\<turnstile> e1 :: BOOLty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: BOOLty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_NEQ e1 e2 :: BOOLty\"\n  | BFANB_ty: \"\\<Gamma> \\<turnstile> e1 :: BOOLty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: BOOLty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_FAN e1 e2 :: BOOLty\"\n  | BFORB_ty: \"\\<Gamma> \\<turnstile> e1 :: BOOLty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: BOOLty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_FOR e1 e2 :: BOOLty\"\n    (* Signed integer operations *)\n  | BEQUS_ty: \"\\<Gamma> \\<turnstile> e1 :: SINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: SINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_EQU e1 e2 :: BOOLty\"\n  | BNEQS_ty: \"\\<Gamma> \\<turnstile> e1 :: SINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: SINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_NEQ e1 e2 :: BOOLty\"\n  | BLEQS_ty: \"\\<Gamma> \\<turnstile> e1 :: SINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: SINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_LEQ e1 e2 :: BOOLty\"\n  | BGEQS_ty: \"\\<Gamma> \\<turnstile> e1 :: SINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: SINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_GEQ e1 e2 :: BOOLty\"\n  | BLESS_ty: \"\\<Gamma> \\<turnstile> e1 :: SINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: SINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_LES e1 e2 :: BOOLty\"\n  | BGRES_ty: \"\\<Gamma> \\<turnstile> e1 :: SINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: SINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_GRE e1 e2 :: BOOLty\"\n    (* Unsigned integer operations *)\n  | BEQUU_ty: \"\\<Gamma> \\<turnstile> e1 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_EQU e1 e2 :: BOOLty\"\n  | BNEQU_ty: \"\\<Gamma> \\<turnstile> e1 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_NEQ e1 e2 :: BOOLty\"\n  | BLEQU_ty: \"\\<Gamma> \\<turnstile> e1 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_LEQ e1 e2 :: BOOLty\"\n  | BGEQU_ty: \"\\<Gamma> \\<turnstile> e1 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_GEQ e1 e2 :: BOOLty\"\n  | BLESU_ty: \"\\<Gamma> \\<turnstile> e1 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_LES e1 e2 :: BOOLty\"\n  | BGREU_ty: \"\\<Gamma> \\<turnstile> e1 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_GRE e1 e2 :: BOOLty\"\n    (* Infinite precision integer operations *)\n  | BEQUI_ty: \"\\<Gamma> \\<turnstile> e1 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_EQU e1 e2 :: BOOLty\"\n  | BNEQI_ty: \"\\<Gamma> \\<turnstile> e1 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_NEQ e1 e2 :: BOOLty\"\n  | BLEQI_ty: \"\\<Gamma> \\<turnstile> e1 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_LEQ e1 e2 :: BOOLty\"\n  | BGEQI_ty: \"\\<Gamma> \\<turnstile> e1 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_GEQ e1 e2 :: BOOLty\"\n  | BLESI_ty: \"\\<Gamma> \\<turnstile> e1 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_LES e1 e2 :: BOOLty\"\n  | BGREI_ty: \"\\<Gamma> \\<turnstile> e1 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_GRE e1 e2 :: BOOLty\"\n    (* Variable size bitstring operations *)\n  | BEQUV_ty: \"\\<Gamma> \\<turnstile> e1 :: VINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: VINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_EQU e1 e2 :: BOOLty\"\n  | BNEQV_ty: \"\\<Gamma> \\<turnstile> e1 :: VINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: VINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_NEQ e1 e2 :: BOOLty\"\n(* =============== Operations that yield an unsigned integer (UINT)  =============== *)\n  | UNEGU_ty: \"\\<Gamma> \\<turnstile> e1 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> UNA_NEG e1 :: UINTty\"\n  | UPOSU_ty: \"\\<Gamma> \\<turnstile> e1 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> UNA_POS e1 :: UINTty\"\n  | UCOMU_ty: \"\\<Gamma> \\<turnstile> e1 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> UNA_COM e1 :: UINTty\"\n  | BADDU_ty: \"\\<Gamma> \\<turnstile> e1 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_ADD e1 e2 :: UINTty\"\n  | BMINU_ty: \"\\<Gamma> \\<turnstile> e1 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_MIN e1 e2 :: UINTty\"\n  | BANDU_ty: \"\\<Gamma> \\<turnstile> e1 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_AND e1 e2 :: UINTty\"\n  | BXORU_ty: \"\\<Gamma> \\<turnstile> e1 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_XOR e1 e2 :: UINTty\"\n  | BLORU_ty: \"\\<Gamma> \\<turnstile> e1 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: UINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_LOR e1 e2 :: UINTty\"\n(* =============== Operations that yield a signed integer (SINT)  =============== *)\n  | UNEGS_ty: \"\\<Gamma> \\<turnstile> e1 :: SINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> UNA_NEG e1 :: SINTty\"\n  | UPOSS_ty: \"\\<Gamma> \\<turnstile> e1 :: SINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> UNA_POS e1 :: SINTty\"\n  | BADDS_ty: \"\\<Gamma> \\<turnstile> e1 :: SINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: SINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_ADD e1 e2 :: SINTty\"\n  | BMINS_ty: \"\\<Gamma> \\<turnstile> e1 :: SINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: SINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_MIN e1 e2 :: SINTty\"\n(* =============== Operations that yield an infinite-precision integer (IINT)  =============== *)\n  | UNEGI_ty: \"\\<Gamma> \\<turnstile> e1 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> UNA_NEG e1 :: IINTty\"\n  | UPOSI_ty: \"\\<Gamma> \\<turnstile> e1 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> UNA_POS e1 :: IINTty\"\n  | BADDI_ty: \"\\<Gamma> \\<turnstile> e1 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_ADD e1 e2 :: IINTty\"\n  | BMINI_ty: \"\\<Gamma> \\<turnstile> e1 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_MIN e1 e2 :: IINTty\"\n  | BMULI_ty: \"\\<Gamma> \\<turnstile> e1 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_MUL e1 e2 :: IINTty\"\n  | BDIVI_ty: \"\\<Gamma> \\<turnstile> e1 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_DIV e1 e2 :: IINTty\"\n  | BMODI_ty: \"\\<Gamma> \\<turnstile> e1 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> e2 :: IINTty \\<Longrightarrow> \\<Gamma> \\<turnstile> BIN_MOD e1 e2 :: IINTty\"\n(* =============== Operations that yield a variable-width integer (VINT)  =============== *)\n          (* Empty for now *)\n\ndeclare exprTyping.intros [intro!]\ninductive_cases [elim!]:\n  \"\\<Gamma> \\<turnstile> BASE b :: \\<tau>\" \"\\<Gamma> \\<turnstile> UNA_LNE e1 :: \\<tau>\" \"\\<Gamma> \\<turnstile> UNA_COM e1 :: \\<tau>\" \"\\<Gamma> \\<turnstile> UNA_NEG e1 :: \\<tau>\" \"\\<Gamma> \\<turnstile> UNA_POS e1 :: \\<tau>\"\n  \"\\<Gamma> \\<turnstile> BIN_DIV e1 e2 :: \\<tau>\" \"\\<Gamma> \\<turnstile> BIN_MOD e1 e2 :: \\<tau>\" \"\\<Gamma> \\<turnstile> BIN_ADD e1 e2 :: \\<tau>\" \"\\<Gamma> \\<turnstile> BIN_MIN e1 e2 :: \\<tau>\" \"\\<Gamma> \\<turnstile> BIN_AND e1 e2 :: \\<tau>\"\n  \"\\<Gamma> \\<turnstile> BIN_XOR e1 e2 :: \\<tau>\" \"\\<Gamma> \\<turnstile> BIN_LOR e1 e2 :: \\<tau>\" \"\\<Gamma> \\<turnstile> BIN_LEQ e1 e2 :: \\<tau>\" \"\\<Gamma> \\<turnstile> BIN_GEQ e1 e2 :: \\<tau>\" \"\\<Gamma> \\<turnstile> BIN_LES e1 e2 :: \\<tau>\"\n  \"\\<Gamma> \\<turnstile> BIN_GRE e1 e2 :: \\<tau>\" \"\\<Gamma> \\<turnstile> BIN_NEQ e1 e2 :: \\<tau>\" \"\\<Gamma> \\<turnstile> BIN_EQU e1 e2 :: \\<tau>\" \"\\<Gamma> \\<turnstile> BIN_FAN e1 e2 :: \\<tau>\" \"\\<Gamma> \\<turnstile> BIN_FOR e1 e2 :: \\<tau>\"\n  \"\\<Gamma> \\<turnstile> BIN_MUL e1 e2 :: \\<tau>\" \"\\<Gamma> \\<turnstile> TernExpr e1 e2 e3 :: \\<tau>\" \"\\<Gamma> \\<turnstile> NamedVar v :: \\<tau>\"\n\nlemma expr_typing_deterministic: \"\\<Gamma> \\<turnstile> e :: t \\<Longrightarrow> \\<Gamma> \\<turnstile> e :: t' \\<Longrightarrow> t' = t\"\n  apply (induction arbitrary: t' rule: exprTyping.induct)\n    apply (blast+)\n  done\n\n(* The typing environment for statements. If a case is defined it implies the statement is well-typed\n   given the context of the typing environment. *)\ninductive stmtTyping :: \"typeEnv \\<Rightarrow> statOrDecl \\<Rightarrow> bool\" (infix \"\\<Turnstile>\" 50) where\n    Empty_ty: \"\\<Gamma> \\<Turnstile> EmptyStat\"\n  | Exit_ty: \"\\<Gamma> \\<Turnstile> ExitStat\"\n  | Conditional_ty: \"\\<Gamma> \\<turnstile> e :: (BOOLty) \\<Longrightarrow> \\<Gamma> \\<Turnstile> stmt1 \\<Longrightarrow> \\<Gamma> \\<Turnstile> stmt2 \\<Longrightarrow> \\<Gamma> \\<Turnstile> (ConditionalStat e stmt1 stmt2)\"\n  | Block_Empty_ty: \"\\<Gamma> \\<Turnstile> (BlockStat [])\"\n  | BlockFull_ty: \"\\<Gamma> \\<Turnstile> stmt \\<Longrightarrow> \\<Gamma> \\<Turnstile> (BlockStat rest) \\<Longrightarrow> \\<Gamma> \\<Turnstile> (BlockStat (stmt # rest))\"\n  | Assign_ty: \"\\<Gamma> \\<turnstile> e :: \\<Gamma> vName \\<Longrightarrow> \\<Gamma> \\<Turnstile> (AssignmentStat vName e)\"\n  | VarDecl_ty: \"\\<Gamma> \\<Turnstile> (VariableDecl vName None)\"\n(* Remove \\<Gamma> (vName) in below with just \\<tau> because they should allow to change the type *)\n  | VarInit_ty: \"\\<Gamma> \\<turnstile> e :: \\<Gamma> vName \\<Longrightarrow> \\<Gamma> \\<Turnstile> (VariableDecl vName (Some e))\"\n  | ConstInit_ty: \"\\<Gamma> \\<turnstile> e :: \\<Gamma> vName \\<Longrightarrow> \\<Gamma> \\<Turnstile> (ConstantDecl vName e)\"\n\ndeclare stmtTyping.intros [intro!]\ninductive_cases [elim!]:\n  \"\\<Gamma> \\<Turnstile> ExitStat\" \"\\<Gamma> \\<Turnstile> ConditionalStat e stmt1 stmt2\" \"\\<Gamma> \\<Turnstile> BlockStat l\" \"\\<Gamma> \\<Turnstile> AssignmentStat n e\" \"\\<Gamma> \\<Turnstile> VariableDecl n e\"\n  \"\\<Gamma> \\<Turnstile> ConstantDecl n e\"\n\n(* The typing environment for the state. It states that a state is correctly typed if and only if the type\n   of all variables in the state correspond with the typing environment. *)\ndefinition stateTyping :: \"typeEnv \\<Rightarrow> state \\<Rightarrow> bool\" (infix \"\\<TTurnstile>\" 50)\n  where \"\\<Gamma> \\<TTurnstile> s \\<longleftrightarrow> (\\<forall>x. getValType (s x) = \\<Gamma> x)\"\n\n(* ============================================================================================================== *)\n(*                                            TYPING SYSTEM PROOF                                                 *)\n(* ============================================================================================================== *)\n\n(* Prove that if the type of a particular variable is a given type, there always exists a concrete value with the\n   matching type to satisfy the constraint. *)\nlemma type_eq_UINT[simp]:   \"getValType v = UINTty    \\<longleftrightarrow> (\\<exists>i. v = UINT i)\" by   (cases v) simp_all\nlemma type_eq_SINT[simp]:   \"getValType v = SINTty    \\<longleftrightarrow> (\\<exists>i. v = SINT i)\" by   (cases v) simp_all\nlemma type_eq_IINT[simp]:   \"getValType v = IINTty    \\<longleftrightarrow> (\\<exists>i. v = IINT i)\" by   (cases v) simp_all\nlemma type_eq_VINT[simp]:   \"getValType v = VINTty    \\<longleftrightarrow> (\\<exists>i. v = VINT i)\" by   (cases v) simp_all\nlemma type_eq_BOOL[simp]:   \"getValType v = BOOLty    \\<longleftrightarrow> (\\<exists>i. v = BOOL i)\" by   (cases v) simp_all\nlemma type_eq_STRING[simp]: \"getValType v = STRINGty  \\<longleftrightarrow> (\\<exists>i. v = STRING i)\" by (cases v) simp_all\nlemma type_eq_ERROR[simp]:  \"getValType v = ERRORty   \\<longleftrightarrow> (\\<exists>i. v = ERROR i)\" by  (cases v) simp_all\nlemma type_eq_MATCH[simp]:  \"getValType v = MATCHty   \\<longleftrightarrow> (\\<exists>i. v = MATCH i)\" by  (cases v) simp_all\n\n(* Theorem to state that if expression are well-typed, the result is necessarily also well-typed. *)\ntheorem expr_preservation: \"\\<Gamma> \\<turnstile> expr :: \\<tau> \\<Longrightarrow> eval expr s v \\<Longrightarrow> \\<Gamma> \\<TTurnstile> s \\<Longrightarrow> getValType v = \\<tau>\"\n  apply (induction arbitrary: v rule: exprTyping.induct)\n    apply (fastforce simp: stateTyping_def)+\n  done\n\nlemma expr_progress: \"\\<Gamma> \\<turnstile> e :: \\<tau> \\<Longrightarrow> \\<Gamma> \\<TTurnstile> s \\<Longrightarrow> \\<exists>v. eval e s v\"\nproof (induction rule: exprTyping.induct)\n     case (UINT_ty \\<Gamma> n) thus ?case using RUINT by blast\nnext case (SINT_ty \\<Gamma> n) thus ?case using RSINT by blast\nnext case (IINT_ty \\<Gamma> n) thus ?case using RIINT by blast\nnext case (VINT_ty \\<Gamma> n) thus ?case using RVINT by blast\nnext case (BOOL_ty \\<Gamma> b) thus ?case using RBOOL by blast\nnext case (STRING_ty \\<Gamma> s) thus ?case using RSTRING by blast\nnext case (ERROR_ty \\<Gamma> e) thus ?case using RERROR by blast\nnext case (MATCH_ty \\<Gamma> m) thus ?case using RMATCH by blast\nnext case (TERNEXPR_ty \\<Gamma> e1 e2 \\<tau> e3) thus ?case by (metis TERNFALSE TERNTRUE expr_preservation type_eq_BOOL)\nnext case (VAR_ty \\<Gamma> vName) thus ?case using NAMEDVAR by blast \nnext case (ULNEB_ty \\<Gamma> e1) thus ?case by (metis ULNEB expr_preservation type_eq_BOOL)\nnext case (BEQUB_ty \\<Gamma> e1 e2) thus ?case by (metis BEQUB expr_preservation type_eq_BOOL)\nnext case (BNEQB_ty \\<Gamma> e1 e2) thus ?case by (metis BNEQB expr_preservation type_eq_BOOL)\nnext case (BFANB_ty \\<Gamma> e1 e2) thus ?case by (metis BFANB expr_preservation type_eq_BOOL)\nnext case (BFORB_ty \\<Gamma> e1 e2) thus ?case by (metis BFORB expr_preservation type_eq_BOOL)\nnext case (BEQUS_ty \\<Gamma> e1 e2) thus ?case by (metis BEQUS expr_preservation type_eq_SINT)\nnext case (BNEQS_ty \\<Gamma> e1 e2) thus ?case by (metis BNEQS expr_preservation type_eq_SINT)\nnext case (BLEQS_ty \\<Gamma> e1 e2) thus ?case by (metis BLEQS expr_preservation type_eq_SINT)\nnext case (BGEQS_ty \\<Gamma> e1 e2) thus ?case by (metis BGEQS expr_preservation type_eq_SINT)\nnext case (BLESS_ty \\<Gamma> e1 e2) thus ?case by (metis BLESS expr_preservation type_eq_SINT)\nnext case (BGRES_ty \\<Gamma> e1 e2) thus ?case by (metis BGRES expr_preservation type_eq_SINT)\nnext case (BEQUU_ty \\<Gamma> e1 e2) thus ?case by (metis BEQUU expr_preservation type_eq_UINT)\nnext case (BNEQU_ty \\<Gamma> e1 e2) thus ?case by (metis BNEQU expr_preservation type_eq_UINT)\nnext case (BLEQU_ty \\<Gamma> e1 e2) thus ?case by (metis BLEQU expr_preservation type_eq_UINT)\nnext case (BGEQU_ty \\<Gamma> e1 e2) thus ?case by (metis BGEQU expr_preservation type_eq_UINT)\nnext case (BLESU_ty \\<Gamma> e1 e2) thus ?case by (metis BLESU expr_preservation type_eq_UINT)\nnext case (BGREU_ty \\<Gamma> e1 e2) thus ?case by (metis BGREU expr_preservation type_eq_UINT)\nnext case (BEQUI_ty \\<Gamma> e1 e2) thus ?case by (metis BEQUI expr_preservation type_eq_IINT)\nnext case (BNEQI_ty \\<Gamma> e1 e2) thus ?case by (metis BNEQI expr_preservation type_eq_IINT)\nnext case (BLEQI_ty \\<Gamma> e1 e2) thus ?case by (metis BLEQI expr_preservation type_eq_IINT)\nnext case (BGEQI_ty \\<Gamma> e1 e2) thus ?case by (metis BGEQI expr_preservation type_eq_IINT)\nnext case (BLESI_ty \\<Gamma> e1 e2) thus ?case by (metis BLESI expr_preservation type_eq_IINT)\nnext case (BGREI_ty \\<Gamma> e1 e2) thus ?case by (metis BGREI expr_preservation type_eq_IINT)\nnext case (BEQUV_ty \\<Gamma> e1 e2) thus ?case by (metis BEQUV expr_preservation type_eq_VINT)\nnext case (BNEQV_ty \\<Gamma> e1 e2) thus ?case by (metis BNEQV expr_preservation type_eq_VINT)\nnext case (UNEGS_ty \\<Gamma> e1) thus ?case by (metis UNEGS expr_preservation type_eq_SINT)\nnext case (UPOSS_ty \\<Gamma> e1) thus ?case by (metis UPOSS expr_preservation type_eq_SINT)\nnext case (BADDS_ty \\<Gamma> e1 e2) thus ?case by (metis BADDS expr_preservation type_eq_SINT)\nnext case (BMINS_ty \\<Gamma> e1 e2) thus ?case by (metis BMINS expr_preservation type_eq_SINT)\nnext case (UNEGU_ty \\<Gamma> e1) thus ?case by (metis UNEGU expr_preservation type_eq_UINT)\nnext case (UPOSU_ty \\<Gamma> e1) thus ?case by (metis UPOSU expr_preservation type_eq_UINT)\nnext case (UCOMU_ty \\<Gamma> e1) thus ?case by (metis UCOMU expr_preservation type_eq_UINT)\nnext case (BADDU_ty \\<Gamma> e1 e2) thus ?case by (metis BADDU expr_preservation type_eq_UINT)\nnext case (BMINU_ty \\<Gamma> e1 e2) thus ?case by (metis BMINU expr_preservation type_eq_UINT)\nnext case (BANDU_ty \\<Gamma> e1 e2) thus ?case by (metis BANDU expr_preservation type_eq_UINT)\nnext case (BXORU_ty \\<Gamma> e1 e2) thus ?case by (metis BXORU expr_preservation type_eq_UINT)\nnext case (BLORU_ty \\<Gamma> e1 e2) thus ?case by (metis BLORU expr_preservation type_eq_UINT)\nnext case (UNEGI_ty \\<Gamma> e1) thus ?case by (metis UNEGI expr_preservation type_eq_IINT)\nnext case (UPOSI_ty \\<Gamma> e1) thus ?case by (metis UPOSI expr_preservation type_eq_IINT)\nnext case (BADDI_ty \\<Gamma> e1 e2) thus ?case by (metis BADDI expr_preservation type_eq_IINT)\nnext case (BMINI_ty \\<Gamma> e1 e2) thus ?case by (metis BMINI expr_preservation type_eq_IINT)\nnext case (BMULI_ty \\<Gamma> e1 e2) thus ?case by (metis BMULI expr_preservation type_eq_IINT)\nnext case (BDIVI_ty \\<Gamma> e1 e2) thus ?case by (metis BDIVI expr_preservation type_eq_IINT)\nnext case (BMODI_ty \\<Gamma> e1 e2) thus ?case by (metis BMODI expr_preservation type_eq_IINT)\nqed\n\ntheorem progress: \"\\<Gamma> \\<Turnstile> c \\<Longrightarrow> \\<Gamma> \\<TTurnstile> s \\<Longrightarrow> c \\<noteq> EmptyStat \\<Longrightarrow> \\<exists>cs'. (c, s, n) \\<leadsto> cs'\"\nproof (induction rule: stmtTyping.induct)\n     case (Conditional_ty \\<Gamma> e stmnt1 stmnt2) thus ?case by (smt CondFalse CondTrue expr_preservation expr_progress type_eq_BOOL)\nnext case (BlockFull_ty \\<Gamma> firstStat remainder) thus ?case by (metis (full_types) EmptyFirst FullBlock old.prod.exhaust step_equal_or_smaller)\nnext case (Block_Empty_ty \\<Gamma>) thus ?case using expr_progress by blast\nnext case (Assign_ty \\<Gamma> e vName) thus ?case using expr_progress by blast\nnext case (VarInit_ty \\<Gamma> e vName) thus ?case using expr_progress by blast\nnext case (ConstInit_ty \\<Gamma> e vName) thus ?case using expr_progress by blast\nqed blast+\n\ntheorem state_preservation: \"(c, s, n) \\<leadsto> (c', s', n') \\<Longrightarrow> \\<Gamma> \\<Turnstile> c \\<Longrightarrow> \\<Gamma> \\<TTurnstile> s \\<Longrightarrow> \\<Gamma> \\<TTurnstile> s'\"\nproof (induct rule: small_step_induct)\n     case (Assign e s v vName n) thus ?case using expr_preservation stateTyping_def by fastforce\nnext case (VarDecl vName s n) thus ?case using expr_preservation stateTyping_def by fastforce\nnext case (VarInit e s v vName n) thus ?case using expr_preservation stateTyping_def by fastforce\nnext case (ConstInit e s v vName n) thus ?case using expr_preservation stateTyping_def by fastforce\nqed blast+\n\ntheorem stmt_preservation: \"(c, s, n) \\<leadsto> (c', s', n') \\<Longrightarrow> \\<Gamma> \\<Turnstile> c \\<Longrightarrow> \\<Gamma> \\<Turnstile> c'\"\nproof (induction rule: small_step_induct)\n  case (FullBlock stmt s n stmt' s' n' rest) thus ?case\n  proof -\n    have \"\\<Gamma> \\<Turnstile> stmt\" using FullBlock.prems by blast\n    then have \"\\<Gamma> \\<Turnstile> stmt'\" by (simp add: FullBlock.IH \\<open>\\<Gamma> \\<Turnstile> stmt\\<close>)\n    then have \"\\<Gamma> \\<Turnstile> (BlockStat (stmt # rest))\" by (simp add: FullBlock.prems)\n    then have \"\\<Gamma> \\<Turnstile> (BlockStat (stmt' # rest))\" using \\<open>\\<Gamma> \\<Turnstile> stmt'\\<close> by blast\n    thus ?case by auto\n  qed\nqed auto\n\ntheorem type_sound: \"(c, s, n) \\<leadsto>* (c', s', n') \\<Longrightarrow> \\<Gamma> \\<Turnstile> c \\<Longrightarrow> \\<Gamma> \\<TTurnstile> s \\<Longrightarrow> c' \\<noteq> EmptyStat \\<Longrightarrow> \\<exists>cs''. (c', s', n') \\<leadsto> cs''\"\nproof (induction rule: star_induct)\n     case (refl a a b) thus ?case using progress by auto\nnext case (step a a b a a b a a b) thus ?case using state_preservation stmt_preservation by auto\nqed\n\n(* ============================================================================================================== *)\n(*                                           FINAL STATE PROPERTIES                                               *)\n(* ============================================================================================================== *)\n\ndefinition \"final cs \\<longleftrightarrow> (\\<nexists>cs'. cs \\<leadsto> cs')\"\n\nlemma EmptyFinal: \"c = EmptyStat \\<Longrightarrow> final (c, s, n)\" using final_def by blast\nlemma FinalEmpty: \"final (c, s, n) \\<Longrightarrow> \\<Gamma> \\<Turnstile> c \\<Longrightarrow> \\<Gamma> \\<TTurnstile> s \\<Longrightarrow> c = EmptyStat\" using final_def progress by blast\n\n(* ============================================================================================================== *)\n(*                                          REACHABILITY PROPERTIES                                               *)\n(* ============================================================================================================== *)\n\ndefinition reachable :: \"statOrDecl \\<Rightarrow> statOrDecl set\" where\n  \"reachable c = {c'. \\<exists>s s' n n'. (c, s, n) \\<leadsto>* (c', s', n')}\"\n\nfun small_steps_n :: \"(statOrDecl * state * nat) \\<Rightarrow> nat \\<Rightarrow> (statOrDecl * state * nat) \\<Rightarrow> bool\" (\"_ \\<leadsto>'(_') _\" [55,0,55] 55)\n  where\n    \"(cs \\<leadsto>(0) cs') = (cs' = cs)\"\n  | \"(cs \\<leadsto>(Suc n) cs'') = (\\<exists>cs'. cs \\<leadsto> cs' \\<and> cs' \\<leadsto>(n) cs'')\"\n\nlemma steps_n_if_star: \"cs \\<leadsto>* cs' \\<Longrightarrow> \\<exists>n. cs \\<leadsto>(n) cs'\"\nproof (induction rule: star.induct)\n  case (refl x) thus ?case using small_steps_n.simps(1) by blast\nnext\n  case (step x y z) thus ?case using small_steps_n.simps(2) by blast\nqed\n\nlemma star_if_steps_n: \"cs \\<leadsto>(n) cs' \\<Longrightarrow> cs \\<leadsto>* cs'\"\n  apply (induction n arbitrary: cs)\n  apply (simp)\n  apply (meson small_steps_n.simps(2) star.simps)\n  done\n\nlemma steps_n_decreases: \"(c, s, n) \\<leadsto>(x) (c', s', n') \\<Longrightarrow> n' \\<le> n\"\n  using star_equal_or_smaller star_if_steps_n by blast\n\nend", "meta": {"author": "Johanmyst", "repo": "Nano-P4", "sha": "fc3720d7115d0bac5d719cfe6c73a024aae7f9c4", "save_path": "github-repos/isabelle/Johanmyst-Nano-P4", "path": "github-repos/isabelle/Johanmyst-Nano-P4/Nano-P4-fc3720d7115d0bac5d719cfe6c73a024aae7f9c4/Theory_Files/Optimisation_Verification/NP4_Optimising_Action_Semantics.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631840431539, "lm_q2_score": 0.4843800842769844, "lm_q1q2_score": 0.2943399442988436}}
{"text": "(*\n * Copyright 2014, General Dynamics C4 Systems\n *\n * This software may be distributed and modified according to the terms of\n * the GNU General Public License version 2. Note that NO WARRANTY is provided.\n * See \"LICENSE_GPLv2.txt\" for details.\n *\n * @TAG(GD_GPL)\n *)\n\ntheory Deterministic_AI\nimports AInvs\nbegin\n\ncontext begin interpretation Arch .\nrequalify_facts\n  update_work_units_empty_fail\n  reset_work_units_empty_fail\n  get_cap_kheap\n  set_domain_empty_fail\n  thread_set_domain_empty_fail\nend\n\nlemmas [wp] =\n  update_work_units_empty_fail\n  reset_work_units_empty_fail\n  get_cap_kheap\n  set_domain_empty_fail\n  thread_set_domain_empty_fail\n\ndeclare dxo_wp_weak[wp del]\n\n(** This theory shows that the cdt_list operations\n        correctly correspond to the existing cdt operations\n        and demonstrates their effect on the traversal order\n        of the tree. *)\n\n(* An unspecified invariant is given from the state\n        extension's type class, which is assumed to hold over\n        all the capability operations. We show here that it\n        therefore holds over the whole kernel. This will\n        later be instantiated to valid_list. *)\n\n(* a valid cdt_list for a node is a list that contains all of its children\n        (from the mdb) exactly once *)\n\n (*Some nasty hackery to get around lack of polymorphic type class operations*)\n\nlemma and_assoc: \"(A and (B and C)) = (A and B and C)\"\n  apply (rule ext)\n  apply simp\ndone\n\nlemma no_children_empty_desc:\n  \"(\\<forall>c. m c \\<noteq> Some slot) = (descendants_of slot m = {})\"\n  apply(rule iffI)\n   apply(simp add: descendants_of_def cdt_parent_defs)\n   apply(intro allI notI)\n   apply(drule tranclD)\n   apply(simp)\n  apply(fastforce simp: descendants_of_def cdt_parent_defs)\n  done\n\nlemma next_childD:\n  \"\\<lbrakk>next_child slot t = Some child; valid_list_2 t m\\<rbrakk>\n   \\<Longrightarrow> (\\<exists>xs. t slot = child # xs) \\<and> m child = Some slot\"\n  apply(simp only: valid_list_2_def)\n  apply(erule conjE)\n  apply(erule_tac x=slot in allE)\n  apply(clarsimp simp: next_child_def valid_list_2_def)\n  apply(case_tac \"t slot\")\n   apply(simp)\n  apply(fastforce)\n  done\n\nlemma next_child_NoneD:\n  notes split_paired_All[simp del]\n  shows \"next_child slot t = None \\<Longrightarrow> t slot = []\"\n  apply(simp add: next_child_def)\n  apply(case_tac \"t slot\")\n   apply(simp)\n  apply(simp)\n  done\n\nlemma next_child_None_empty_desc:\n  notes split_paired_All[simp del]\n  shows \"valid_list_2 t m\n    \\<Longrightarrow> (next_child slot t = None) = (descendants_of slot m = {})\"\n  apply(simp add: valid_list_2_def)\n  apply(erule conjE)\n  apply(erule_tac x=slot in allE)\n  apply(clarsimp simp: next_child_def)\n  apply(case_tac \"t slot\")\n   apply(simp add: no_children_empty_desc)\n  apply(fastforce simp: descendants_of_def cdt_parent_defs)\n  done\n\nlemma next_sibD:\n  \"next_sib slot t m = Some child\n   \\<Longrightarrow> (\\<exists>p. m slot = Some p \\<and> after_in_list (t p) slot = Some child)\"\n  apply(clarsimp simp: next_sib_def)\n  apply(case_tac \"m slot\")\n   apply(simp)\n  apply(clarsimp)\n  done\n\nlemma next_sib_NoneD:\n  \"next_sib slot t m = None\n   \\<Longrightarrow> m slot = None \\<or> (\\<exists>p. m slot = Some p \\<and> after_in_list (t p) slot = None)\"\n  apply(clarsimp simp: next_sib_def)\n  apply(case_tac \"m slot\")\n   apply(fastforce)+\n   done\n\nlemma desc_not_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"valid_mdb s \\<Longrightarrow> slot \\<notin> descendants_of slot (cdt s)\"\n  apply(fastforce simp: valid_mdb_def no_mloop_def descendants_of_def cdt_parent_defs)\n  done\n\nlemma next_childI:\n  \"t slot = child # xs\n  \\<Longrightarrow> next_child slot t = Some child\"\n  by (simp add: next_child_def)\n\nlemma next_childI':\n  \"\\<lbrakk>t slot = child # xs; x = Some child\\<rbrakk>\n  \\<Longrightarrow> next_child slot t = x\"\n  by (simp add: next_child_def)\n\nlemma next_sibI:\n  \"\\<lbrakk>m slot = Some p; after_in_list (t p) slot = Some sib\\<rbrakk>\n  \\<Longrightarrow> next_sib slot t m = Some sib\"\n  by (simp add: next_sib_def)\n\nlemma next_sibI':\n  \"\\<lbrakk>m slot = Some p; after_in_list (t p) slot = Some sib; x = Some sib\\<rbrakk>\n  \\<Longrightarrow> next_sib slot t m = x\"\n  by (simp add: next_sib_def)\n\nlemma next_child_NoneI:\n  \"t slot = [] \\<Longrightarrow> next_child slot t = None\"\n  by (simp add: next_child_def)\n\nlemma next_sib_NoneI:\n  \"m slot = None \\<or> (m slot = Some p \\<and> after_in_list (t p) slot = None) \\<Longrightarrow> next_sib slot t m = None\"\n  by (fastforce simp: next_sib_def)\n\nlemma not_child_not_sib:\n  \"\\<lbrakk>m slot = None; valid_list_2 t m\\<rbrakk> \\<Longrightarrow> next_sib p t m \\<noteq> Some slot\"\n  apply(simp add: next_sib_def)\n  apply(case_tac \"m p\")\n   apply(simp)\n  apply(simp)\n  apply(rule notI)\n  apply(simp only: valid_list_2_def)\n  apply(erule conjE)\n  apply(erule_tac x=a in allE)\n  apply(fastforce dest: after_in_list_in_list)\n  done\n\nlemma not_child_no_sibs:\n  \"m slot = None \\<Longrightarrow> next_sib slot t m = None\"\n  by (simp add: next_sib_def)\n\nlemma descendants_linear:\n  \"\\<lbrakk>a \\<in> descendants_of b m; a \\<in> descendants_of c m; b \\<noteq> c\\<rbrakk>\n    \\<Longrightarrow> b \\<in> descendants_of c m \\<or> c \\<in> descendants_of b m\"\n  apply(clarsimp)\n  apply(simp add: descendants_of_def cdt_parent_rel_def is_cdt_parent_def)\n  apply(induct b a rule: trancl.induct)\n   apply(simp)\n   apply(erule tranclE)\n    apply(simp)\n   apply(simp)\n  apply(simp)\n  apply(subgoal_tac \"(c, b) \\<in> {(p, c). m c = Some p}\\<^sup>+\")\n   apply(simp)\n  apply(subgoal_tac \"b \\<noteq> c\")\n   apply(erule_tac a=c and b=ca in tranclE)\n    apply(simp)\n   apply(simp)\n  apply(fastforce)\n  done\n\nlemma descendants_trans:\n  \"\\<lbrakk>a \\<in> descendants_of b m; b \\<in> descendants_of c m\\<rbrakk> \\<Longrightarrow> a \\<in> descendants_of c m\"\n  by (simp add: descendants_of_def)\n\ndefinition finite_depth :: \"cdt \\<Rightarrow> bool\" where\n  \"finite_depth m \\<equiv>\n    \\<forall>slot. \\<exists>p. (slot \\<in> descendants_of p m \\<or> p = slot) \\<and> m p = None\"\n\nlemma sib_not_desc:\n  \"\\<lbrakk>no_mloop m; m x = Some p; m y = Some p\\<rbrakk>\n    \\<Longrightarrow> x \\<notin> descendants_of y m\"\n  apply(rule notI)\n  apply(simp add: descendants_of_def cdt_parent_defs)\n  apply(drule tranclD2)\n  apply(elim conjE exE)\n  apply(simp)\n  apply(drule rtranclD)\n  apply(erule disjE)\n   apply(fastforce simp: no_mloop_def cdt_parent_defs)\n  apply(erule conjE)\n  apply(subgoal_tac \"(z, z) \\<in> {(p, c). m c = Some p}\\<^sup>+\")\n   prefer 2\n   apply(rule_tac b=y in trancl_into_trancl2)\n    apply(simp)\n   apply(simp)\n  apply(fastforce simp: no_mloop_def cdt_parent_defs)\n  done\n\nlemma finite_depth:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"valid_mdb s \\<Longrightarrow> finite_depth (cdt s)\"\n  apply(simp add: finite_depth_def)\n  apply(intro allI)\n  apply(subgoal_tac \"{x. slot \\<in> descendants_of x (cdt s)} \\<subseteq> {x. cte_wp_at (\\<lambda>_. True) x s}\")\n   prefer 2\n   apply(fastforce simp: descendants_of_cte_at2)\n  apply(drule finite_subset)\n   apply(simp add: cte_wp_at_set_finite)\n  apply(case_tac \"cdt s slot\")\n   apply(fastforce)\n  apply(rule ccontr)\n  apply(simp)\n  apply(frule_tac f=\"\\<lambda>x. THE y. cdt s x = Some y\" in inj_on_iff_eq_card)\n  apply(subgoal_tac \"inj_on (\\<lambda>x. THE y. cdt s x = Some y) {x. slot \\<in> descendants_of x (cdt s)}\")\n   prefer 2\n   apply(simp(no_asm) add: inj_on_def)\n   apply(intro allI impI)\n   apply(rule ccontr)\n   apply(frule_tac b=x and c=y in descendants_linear)\n     apply(simp)\n    apply(simp)\n   apply(case_tac \"cdt s x\")\n    apply(fastforce)\n   apply(case_tac \"cdt s y\")\n    apply(fastforce)\n   apply(fastforce simp: valid_mdb_def sib_not_desc)\n  apply(simp)\n  apply(subgoal_tac \"((\\<lambda>x. THE y. cdt s x = Some y) ` {x. slot \\<in> descendants_of x (cdt s)})\n                      \\<subset> {x. slot \\<in> descendants_of x (cdt s)}\")\n   prefer 2\n   apply(rule psubsetI)\n    apply(rule subsetI)\n    apply(simp)\n    apply(erule imageE)\n    apply(case_tac \"cdt s xa\")\n     apply(fastforce)\n    apply(rule_tac b=xa in descendants_trans)\n     apply(simp)\n    apply(fastforce simp: descendants_of_def cdt_parent_defs)\n   apply(rule_tac x=a in set_neqI[symmetric])\n    apply(fastforce simp: descendants_of_def cdt_parent_defs)\n   apply(rule notI)\n   apply(erule imageE)\n   apply(case_tac \"cdt s x\")\n    apply(fastforce)\n   apply(fastforce simp: sib_not_desc valid_mdb_def)\n  apply(drule psubset_card_mono)\n   apply(assumption)\n  apply(simp)\n  done\n\nlemma cdt_power:\n  \"\\<lbrakk>\\<forall>i. m (f i) = Some (f (Suc i)); (p, f 0) \\<in> {(p, c). m c = Some p} ^^ n\\<rbrakk>\n    \\<Longrightarrow> p = f n\"\n  apply(induct n arbitrary: p)\n   apply(simp)\n  apply (metis (lifting, full_types) mem_Collect_eq option.inject prod.simps(2) relpow_Suc_D2)\n  done\n\nlemma wf_cdt_parent_rel:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"finite_depth m \\<Longrightarrow> wf (cdt_parent_rel m)\"\n  apply(subst wf_iff_no_infinite_down_chain)\n  apply(rule notI)\n  apply(clarsimp simp: finite_depth_def descendants_of_def cdt_parent_defs)\n  apply(erule_tac x=\"f 0\" in allE)\n  apply(elim exE conjE)\n  apply(erule disjE)\n   apply(simp add: trancl_power)\n   apply(elim exE conjE)\n   apply(frule cdt_power)\n    apply(assumption)\n   apply(clarsimp)\n  apply(simp)\n  done\n\nlemma cdt_induct:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>\\<And>x. m x = None \\<Longrightarrow> P x; \\<And>x y. \\<lbrakk>m x = Some y; P y\\<rbrakk> \\<Longrightarrow> P x; finite_depth m\\<rbrakk>\n    \\<Longrightarrow> P slot\"\n  apply(induct_tac rule: wf_induct[where r=\"cdt_parent_rel m\"])\n   apply(simp add: wf_cdt_parent_rel)\n  apply(simp add: cdt_parent_defs)\n  apply(case_tac \"m x\")\n   apply(simp)\n  apply(erule_tac x=a in allE)\n  apply(simp)\n  done\n\nlemma next_not_child_domintros:\n  \"(\\<And>x. \\<lbrakk>next_sib slot t m = None; m slot = Some x\\<rbrakk>\n    \\<Longrightarrow> next_not_child_dom (x, t, m))\n      \\<Longrightarrow> next_not_child_dom (slot, t, m)\"\n  apply(rule accpI)\n  apply(erule next_not_child_rel.cases)\n  apply(simp)\n  done\n\nlemma next_not_child_termination:\n  \"finite_depth m \\<Longrightarrow> next_not_child_dom (slot, t, m)\"\n  apply(induct_tac rule: cdt_induct[where m=m])\n    apply(rule next_not_child_domintros)\n    apply(simp)\n   apply(rule next_not_child_domintros)\n   apply(simp)\n  apply(simp)\n  done\n\nlemma next_not_child_pinduct':\n  \"\\<lbrakk>next_not_child_dom (slot, t, m);\n   \\<And>slot.\n      \\<lbrakk>next_not_child_dom (slot, t, m);\n       \\<And>a. \\<lbrakk>next_sib slot t m = None; m slot = Some a\\<rbrakk> \\<Longrightarrow> P a t m\\<rbrakk>\n      \\<Longrightarrow> P slot t m\\<rbrakk>\n  \\<Longrightarrow> P slot t m\"\n  apply(induct rule: next_not_child.pinduct)\n  apply(simp)\n  done\n\nlemma next_not_child_pinduct:\n  \"\\<lbrakk>\\<And>slot. \\<lbrakk>\\<And>a. \\<lbrakk>next_sib slot t m = None; m slot = Some a\\<rbrakk> \\<Longrightarrow> P a\\<rbrakk>\n    \\<Longrightarrow> P slot; finite_depth m\\<rbrakk>\n      \\<Longrightarrow> P slot\"\n  apply(rule_tac t=t and m=m in next_not_child_pinduct')\n   apply(rule next_not_child_termination)\n   apply(assumption)\n  apply(fastforce)\n  done\n\ndeclare next_not_child.psimps[simp]\n\nlemma next_not_child_pinduct2':\n  \"\\<lbrakk>next_not_child_dom (p, t, m);\n  \\<And>a slot. \\<lbrakk>next_sib a t m = None; m a = Some slot; P a\\<rbrakk> \\<Longrightarrow> P slot;\n  next_not_child p t m = Some n; P p;\n  \\<forall>a slot. next_sib a t m = Some slot \\<longrightarrow> P slot\\<rbrakk>\n    \\<Longrightarrow> P n\"\n  apply(induct rule: next_not_child.pinduct)\n  apply(simp split: if_split_asm del: split_paired_All)\n  apply(case_tac \"m slot\")\n   apply simp\n  apply simp\n  done\n\nlemma next_not_child_pinduct2:\n  \"\\<lbrakk>\\<And>a slot. \\<lbrakk>next_sib a t m = None; m a = Some slot; P a\\<rbrakk> \\<Longrightarrow> P slot;\n    next_not_child p t m = Some n; P p;\n    \\<forall>a slot. next_sib a t m = Some slot \\<longrightarrow> P slot; finite_depth m\\<rbrakk>\n    \\<Longrightarrow> P n\"\n  by (rule next_not_child_pinduct2', simp_all add: next_not_child_termination)\n\nlemma next_not_child_linearI:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  assumes f_d: \"finite_depth m\" shows\n  \"\\<lbrakk>m p = m' p; next_sib p t m = next_sib p t' m';\n     \\<forall>q. p \\<in> descendants_of q m \\<longrightarrow> m q = m' q\n     \\<and> next_sib q t m = next_sib q t' m'; finite_depth m; finite_depth m'\\<rbrakk>\n    \\<Longrightarrow> next_not_child p t' m' = next_not_child p t m\"\n  apply(induct rule: next_not_child_pinduct[where t=t and m=m])\n   apply(simp)\n   apply(case_tac \"m slot\")\n    apply(simp add: next_not_child_termination)\n   apply(case_tac \"next_sib slot t m\")\n    apply(simp add: next_not_child_termination)\n    apply(case_tac \"m' slot\")\n     apply(simp)\n    apply(simp)\n    apply(atomize)\n    apply(erule_tac x=aa in allE)\n    apply(simp split: if_split_asm)\n     apply(case_tac \"m' aa\")\n      apply(simp)\n      apply(simp add: next_not_child_termination)\n      apply(intro conjI impI)\n       apply(case_tac \"m aa\")\n        apply(simp)\n       apply(erule_tac x=aa in allE)\n       apply(erule impE)\n        apply(fastforce simp: cdt_parent_defs descendants_of_def)\n       apply(simp)\n      apply(erule exE)\n      apply(erule_tac x=aa in allE)(* condense *)\n      apply(erule impE)\n       apply(fastforce simp: cdt_parent_defs descendants_of_def)\n      apply(simp)\n     apply(simp)\n     apply(erule impE)\n      apply(erule_tac x=aa in allE)\n      apply(fastforce simp: cdt_parent_defs descendants_of_def)\n     apply(erule impE)\n      apply(erule_tac x=aa in allE)\n      apply(fastforce simp: cdt_parent_defs descendants_of_def)\n     apply(erule impE)\n      apply(intro allI impI)\n      apply(erule_tac x=q in allE)\n      apply(erule impE)\n       apply(simp add: cdt_parent_defs descendants_of_def)\n       apply(rule_tac b=aa in trancl_into_trancl)\n        apply(simp, simp)\n      apply(simp)\n     apply(erule_tac x= aa in allE)\n     apply(erule impE)\n      apply(fastforce simp: cdt_parent_defs descendants_of_def)\n     apply(simp add: next_not_child_termination) (* condense *)\n    apply(erule_tac x=aa in allE)\n    apply(erule impE)\n     apply(fastforce simp: cdt_parent_defs descendants_of_def)\n    apply(simp add: next_not_child_termination)\n   apply(simp)\n   apply(fastforce simp: next_not_child_termination)\n  using f_d\n  apply(assumption)\n  done\n\nlemma next_not_child_linearI':\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  assumes f_d: \"finite_depth m\" shows\n  \"\\<lbrakk>finite_depth m'; m p = m' p; next_sib p t m = next_sib p t' m';\n     \\<forall>q. p \\<in> descendants_of q m \\<longrightarrow> m q = m' q\n     \\<and> (m q = m' q \\<longrightarrow> next_sib q t m = next_sib q t' m')\\<rbrakk>\n    \\<Longrightarrow> next_not_child p t' m' = next_not_child p t m\"\n  using f_d\n  apply (rule next_not_child_linearI,simp+)\n  done\n\nlemma next_not_childI':\n    notes split_paired_All[simp del] split_paired_Ex[simp del]\n  assumes f_d: \"finite_depth m\" shows\n  \"\\<lbrakk>next_sib p t m = Some n \\<or>\n   (next_sib p t m = None \\<and>\n     (\\<exists>q. next_sib q t m = Some n \\<and> p \\<in> descendants_of q m\n     \\<and> (\\<forall>q'. q' \\<in> descendants_of q m \\<and> p \\<in> descendants_of q' m\n        \\<longrightarrow> next_sib q' t m = None))); finite_depth m\\<rbrakk>\n    \\<Longrightarrow> next_not_child p t m = Some n\"\n  apply(induct p rule: next_not_child_pinduct[where t=t and m=m])\n   apply(simp)\n   apply(erule disjE)\n    apply(simp add: next_not_child_termination)\n   apply(simp)\n   apply(elim conjE exE)\n   apply(subst next_not_child.psimps, simp add: next_not_child_termination)\n   apply(simp)\n   apply(case_tac \"m slot\")\n    apply(simp)\n    apply(simp add: descendants_of_def cdt_parent_defs)\n    apply(drule tranclD2)\n    apply(fastforce)\n   apply(atomize)\n   apply(erule_tac x=a in allE)\n   apply(simp)\n   apply(case_tac \"next_sib a t m\")\n    apply(simp)\n    apply(case_tac \"a=q\")\n     apply(simp)\n    apply(erule impE)\n     apply(rule_tac x=q in exI)\n     apply(simp add: descendants_of_def cdt_parent_defs)\n     apply(drule tranclD2)\n     apply(elim exE conjE, simp)\n     apply(drule rtranclD, simp)\n     apply(intro allI impI)\n     apply(erule_tac x=q' in allE)\n     apply(simp)\n     apply(elim impE conjE)\n      apply(drule_tac x=q' and y=z in tranclD2)\n      apply(elim exE conjE)\n      apply(simp)\n      apply(rule_tac b=z in trancl_into_trancl)\n       apply(rule_tac b=za in rtrancl_into_trancl1)\n        apply(simp)\n       apply(simp)\n      apply(simp)\n     apply(simp)\n    apply(simp)\n   apply(simp)\n   apply(case_tac \"a=q\")\n    apply(simp)\n   apply(erule_tac x=a in allE)\n   apply(erule_tac Q=\"next_sib a t m = None\" in impE)\n    apply(simp add: descendants_of_def cdt_parent_defs)\n    apply(rule conjI)\n    apply(drule tranclD2)\n    apply(elim conjE exE)\n    apply(simp)\n    apply(drule rtranclD)\n    apply(simp)\n   apply(fastforce)\n  apply(simp)\n  using f_d apply(simp)\n  done\n\nlemma next_not_childI:\n  \"\\<lbrakk>next_sib p t m = Some n \\<or>\n   (next_sib p t m = None \\<and>\n     (\\<exists>q. next_sib q t m = Some n \\<and> p \\<in> descendants_of q m\n     \\<and> (\\<forall>q'. q' \\<in> descendants_of q m \\<and> p \\<in> descendants_of q' m\n        \\<longrightarrow> next_sib q' t m = None))); finite_depth m\\<rbrakk>\n    \\<Longrightarrow> next_not_child p t m = Some n\"\n  by(simp add: next_not_childI')\n\nlemma next_not_child_NoneI':\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  assumes f_d: \"finite_depth m\"\n  shows\n  \"\\<lbrakk>\\<forall>q. p \\<in> descendants_of q m \\<longrightarrow> next_sib q t m = None;\n    next_sib p t m = None; finite_depth m\\<rbrakk>\n    \\<Longrightarrow> next_not_child p t m = None\"\n  apply(induct p rule: next_not_child_pinduct[where t=t and m=m])\n   apply(simp)\n   apply(case_tac \"m slot\")\n    apply(simp add: next_not_child_termination)\n   apply(atomize)\n   apply(erule_tac x=a in allE)\n   apply(simp)\n   apply(erule impE)\n    apply(intro allI impI)\n    apply(erule_tac x=q in allE)\n    apply(erule impE)\n     apply(simp add: descendants_of_def cdt_parent_defs)\n     apply(rule_tac b=a in trancl_into_trancl)\n      apply(simp)\n     apply(simp)\n    apply(simp)\n   apply(erule impE)\n    apply(erule_tac x=a in allE)\n    apply(erule impE)\n     apply(fastforce simp: descendants_of_def cdt_parent_defs)\n    apply(simp)\n   apply(subst next_not_child.psimps)\n    apply(simp add: next_not_child_termination)\n   apply(simp)\n  using f_d apply(simp)\n  done\n\nlemma next_not_child_NoneI:\n  \"\\<lbrakk>\\<forall>q. p \\<in> descendants_of q m \\<longrightarrow> next_sib q t m = None;\n    next_sib p t m = None; finite_depth m\\<rbrakk>\n    \\<Longrightarrow> next_not_child p t m = None\"\n  by(simp add: next_not_child_NoneI')\n\nlemma next_not_childD':\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  assumes f_d: \"finite_depth m\" shows\n  \"\\<lbrakk>next_not_child p t m = Some n; finite_depth m; no_mloop m\\<rbrakk>\n    \\<Longrightarrow> next_sib p t m = Some n \\<or>\n       (next_sib p t m = None \\<and>\n         (\\<exists>q. next_sib q t m = Some n \\<and> p \\<in> descendants_of q m\n          \\<and> (\\<forall>q'. q' \\<in> descendants_of q m \\<and> p \\<in> descendants_of q' m\n           \\<longrightarrow> next_sib q' t m = None)))\"\n  apply(induct p rule: next_not_child_pinduct[where t=t and m=m])\n   apply(simp)\n   apply(case_tac \"m slot\")\n    apply(simp)\n    apply(rule disjCI)\n    apply(simp)\n    apply(erule disjE)\n     apply(erule exE, drule next_sibD)\n     apply(simp add: next_sib_def)\n    apply(simp add: next_not_child_termination split: if_split_asm)\n   apply(atomize)\n   apply(erule_tac x=a in allE)\n   apply(simp)\n   apply(case_tac \"next_sib slot t m\")\n    apply(simp)\n    apply(case_tac \"next_not_child a t m = Some n\")\n     apply(simp)\n     apply(erule disjE)\n      apply(rule_tac x=a in exI)\n      apply(simp)\n      apply(rule conjI)\n       apply(fastforce simp: descendants_of_def cdt_parent_defs)\n      apply(intro impI allI)\n      apply(simp add: descendants_of_def cdt_parent_defs)\n      apply(erule conjE)\n      apply(drule_tac x=q' in tranclD2)\n      apply(elim exE conjE)\n      apply(simp)\n      apply(drule_tac b=q' and c=z in trancl_rtrancl_trancl)\n       apply(simp)\n      apply(simp add: no_mloop_def cdt_parent_defs)\n     apply(elim conjE exE)\n     apply(rule_tac x=q in exI)\n     apply(simp)\n     apply(rule conjI)\n      apply(simp add: descendants_of_def cdt_parent_defs)\n      apply(rule_tac b=a in trancl_into_trancl)\n       apply(simp)\n      apply(simp)\n     apply(intro allI impI)\n     apply(case_tac \"a=q'\")\n      apply(simp)\n     apply(erule_tac x=q' in allE)\n     apply(erule impE)\n      apply(simp add: descendants_of_def cdt_parent_defs)\n      apply(erule conjE)\n      apply(drule_tac y=slot in tranclD2)\n      apply(elim conjE exE)\n      apply(simp)\n      apply(drule rtranclD)\n      apply(simp)\n     apply(simp)\n    apply(simp add: next_not_child_termination)\n   apply(simp add: next_not_child_termination)\n  using f_d apply(simp)\n  done\n\nlemma next_not_childD:\n   notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>next_not_child p t m = Some n; finite_depth m; no_mloop m\\<rbrakk>\n    \\<Longrightarrow> next_sib p t m = Some n \\<or>\n       (next_sib p t m = None \\<and>\n         (\\<exists>q. next_sib q t m = Some n \\<and> p \\<in> descendants_of q m\n          \\<and> (\\<forall>q'. q' \\<in> descendants_of q m \\<and> p \\<in> descendants_of q' m\n           \\<longrightarrow> next_sib q' t m = None)))\"\n  by (simp add: next_not_childD')\n\nlemma next_not_child_NoneD':\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  assumes f_d: \"finite_depth m\" shows\n  \"\\<lbrakk>next_not_child p t m = None; finite_depth m\\<rbrakk>\n    \\<Longrightarrow> (\\<forall>q. p \\<in> descendants_of q m \\<longrightarrow> next_sib q t m = None) \\<and>\n        next_sib p t m = None\"\n  apply(induct p rule: next_not_child_pinduct[where t=t and m=m])\n   apply(subgoal_tac \"next_sib slot t m = None\")\n    prefer 2\n    apply(subst(asm)(2) next_not_child.psimps)\n     apply(simp add: next_not_child_termination)\n    apply(case_tac \"next_sib slot t m\")\n     apply(simp)\n    apply(simp)\n   apply(simp)\n   apply(intro allI impI)\n   apply(case_tac \"m slot\")\n    apply(subst(asm)(2) next_not_child.psimps)\n     apply(simp add: next_not_child_termination)\n    apply(case_tac \"next_sib slot t m\")\n     apply(simp add: descendants_of_def cdt_parent_defs)\n     apply(drule tranclD2)\n     apply(fastforce)\n    apply(simp)\n   apply(atomize)\n   apply(erule_tac x=a in allE)\n   apply(simp)\n   apply(erule impE)\n    apply(simp add: next_not_child_termination)\n   apply(case_tac \"q=a\")\n    apply(simp add: next_not_child_termination split: if_split_asm)\n   apply(erule conjE)\n   apply(erule_tac x=q in allE)\n   apply(erule impE)\n    apply(simp add: descendants_of_def cdt_parent_defs)\n    apply(drule tranclD2)\n    apply(elim conjE exE)\n    apply(simp)\n    apply(drule rtranclD)\n    apply(simp)\n   apply(simp)\n  using f_d apply(simp)\n  done\n\nlemma next_not_child_NoneD:\n  \"\\<lbrakk>next_not_child p t m = None; finite_depth m\\<rbrakk>\n    \\<Longrightarrow> (\\<forall>q. p \\<in> descendants_of q m \\<longrightarrow> next_sib q t m = None) \\<and>\n        next_sib p t m = None\"\n  by (simp add: next_not_child_NoneD')\n\nlemma slot_in_one_list:\n  \"\\<lbrakk>c \\<in> set (t p); c \\<in> set (t p'); valid_list_2 t m\\<rbrakk> \\<Longrightarrow> p = p'\"\n  by (simp only: valid_list_2_def, simp)\n\n\nlemma next_sib_inj:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>next_sib a t m = Some y; next_sib b t m = Some y; valid_list_2 t m\\<rbrakk>\n    \\<Longrightarrow> a = b\"\n  apply(drule next_sibD)+\n  apply(simp add: valid_list_2_def)\n  apply(elim exE conjE)\n  apply(frule_tac a=a in after_in_list_in_list)\n  apply(frule_tac a=b in after_in_list_in_list)\n  apply(rule_tac list=\"t pa\" and x=y in after_in_list_inj)\n    apply(simp)\n   apply(simp)\n  apply(simp)\n  done\n\nlemma no_mloop_descendants:\n  \"no_mloop m = (\\<forall>x. x \\<notin> descendants_of x m)\"\n  by (clarsimp simp: no_mloop_def descendants_of_def)\n\nlemma no_mloop_descendants':\n  \"no_mloop m \\<Longrightarrow> x \\<notin> descendants_of x m\"\n  by (simp add: no_mloop_descendants del: split_paired_All)\n\nlemma valid_list_2D:\n  notes split_paired_All[simp del]\n  shows\n  \"valid_list_2 t m \\<Longrightarrow> src \\<in> set (t p) \\<Longrightarrow> m src = Some p\"\n  apply (simp add: valid_list_2_def)\n  done\n\n\nlemma replace_parent_ignore:\n  notes split_paired_All[simp del]\n  shows\n  \"valid_list_2 t m \\<Longrightarrow> m src \\<noteq> Some src_p \\<Longrightarrow> (list_replace (t src_p) src dest) = (t src_p)\"\n  apply (rule list_replace_ignore)\n  apply (clarsimp simp add: valid_list_2_def)\n  done\n\nlemma after_in_list_not_parent:\n  notes split_paired_All[simp del]\n  shows\n  \"valid_list_2 t m \\<Longrightarrow> no_mloop m \\<Longrightarrow> after_in_list (t x) z \\<noteq> Some x\"\n  apply (rule notI)\n  apply (frule(1) valid_list_2D[OF _ after_in_list_in_list])\n  apply (frule(1) no_mloop_neq,simp)\n  done\n\nlemma ancestor_not_descendant:\nnotes split_paired_All[simp del]\nshows\n\"no_mloop m \\<Longrightarrow> src \\<in> descendants_of src_p m \\<Longrightarrow> src_p \\<notin> descendants_of src m\"\n  apply (rule notI)\n  apply (frule(1) descendants_trans)\n   apply (simp add: no_mloop_def descendants_of_def)\n  done\n\nlemma child_descendant:\n\"m src = Some src_p \\<Longrightarrow> src \\<in> descendants_of src_p m\"\n  apply (simp add: descendants_of_def cdt_parent_rel_def is_cdt_parent_def)\n  apply (rule r_into_trancl')\n  apply simp\n  done\n\nlemmas parent_not_descendant = ancestor_not_descendant[OF _ child_descendant]\n\nlemma next_sib_not_self:\nnotes split_paired_All[simp del]\nshows\n\"valid_list_2 t m \\<Longrightarrow> next_sib src t m \\<noteq> Some src\"\n  apply (rule notI)\n  apply (simp add: next_sib_def split: option.splits)\n  apply (subgoal_tac \"distinct (t (the (m src)))\")\n   apply (frule distinct_after_in_list_not_self[where src=src])\n   apply simp\n  apply (simp add: valid_list_2_def)\n  done\n\nlemma next_sib_same_parent:\nnotes split_paired_All[simp del] split_paired_Ex[simp del]\nshows\n\"valid_list_2 t m \\<Longrightarrow> next_sib sib t m = Some me \\<Longrightarrow> \\<exists>p. m sib = Some p \\<and> m me = Some p\"\n  apply (simp add: next_sib_def split: option.splits)\n  apply (drule after_in_list_in_list)\n  apply (simp add: valid_list_2_def)\n  done\n\nlemma next_not_child_not_self:\nnotes split_paired_All[simp del] split_paired_Ex[simp del]\nshows\n\"valid_list_2 t m \\<Longrightarrow> finite_depth m \\<Longrightarrow> no_mloop m \\<Longrightarrow> next_not_child src t m \\<noteq> Some src\"\n  apply (rule notI)\n  apply (drule next_not_childD,simp+)\n  apply (elim disjE)\n   apply (frule next_sib_not_self[where src=src],simp)\n  apply (elim conjE exE)\n  apply (frule_tac me=src and sib=q in next_sib_same_parent,assumption)\n  apply (elim exE conjE)\n  apply (subgoal_tac \"src \\<notin> descendants_of q m\")\n   apply simp\n  apply (rule sib_not_desc,simp+)\n  done\n\nlemma empty_list_empty_desc:\n  \"valid_list_2 t m \\<Longrightarrow> (t p = []) = (descendants_of p m = {})\"\n  apply(drule_tac slot=p in next_child_None_empty_desc)\n  apply(simp add: next_child_def)\n  apply(case_tac \"t p\", simp+)\n  done\n\n\nlemma after_in_list_not_self_helper:\n  \"\\<lbrakk>distinct list;\n        after_in_list list c = Some c;\n        (list, c) = (x # y # xs, a)\\<rbrakk>\n       \\<Longrightarrow> False\"\n  apply (induct list arbitrary: x y xs a,simp)\n  apply atomize\n  apply (case_tac xs)\n  apply (case_tac \"aa =x\")\n   apply (case_tac \"x = y\",simp,simp)\n   apply (simp split: if_split_asm)+\n   done\n\nlemma after_in_list_not_self:\n  \"\\<lbrakk>m c = Some p; valid_list_2 t m\\<rbrakk> \\<Longrightarrow> after_in_list (t p) c \\<noteq> Some c\"\n  apply (simp only: valid_list_2_def)\n  apply (erule conjE)\n  apply (drule_tac x = p in spec)+\n  apply (thin_tac \"set (t p) = {c. m c = Some p}\")\n  apply (rule notI)\n  apply (rule_tac x = \"(t p, c)\" in after_in_list.cases, simp, simp)\n  apply (blast intro: after_in_list_not_self_helper)\n  done\n\nlemma not_sib_self:\n  \"valid_list_2 t m \\<Longrightarrow> next_sib slot t m \\<noteq> Some slot\"\n  by (case_tac \"m slot\", auto simp: next_sib_def after_in_list_not_self)\n\n\nlemma next_not_child_eq_next_sib_None:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"\\<lbrakk>next_not_child p t m = next_not_child q t m; p \\<in> descendants_of a m \\<or> p = a;\n           a \\<in> descendants_of q m; valid_list_2 t m; finite_depth m; no_mloop m\\<rbrakk>\n    \\<Longrightarrow> next_sib a t m = None\"\n  apply(case_tac \"next_not_child p t m\")\n   apply(drule(1) next_not_child_NoneD)\n   apply(fastforce)\n  apply(case_tac \"next_not_child q t m\")\n   apply(simp)\n  apply(subgoal_tac \"aa=aaa\")\n   prefer 2\n   apply(simp)\n  apply(drule(2) next_not_childD)+\n  apply(erule_tac P=\"next_sib p t m = Some aa\" in disjE)\n   apply(erule_tac P=\"next_sib q t m = Some aaa\" in disjE)\n    apply(simp)\n    apply(drule(2) next_sib_inj)\n    apply(simp)\n    apply(erule disjE)\n     apply(drule_tac a=q and c=q in descendants_trans)\n      apply(simp)\n     apply(simp add: no_mloop_descendants)\n    apply(simp add: no_mloop_descendants)\n   apply(elim exE conjE)\n   apply(drule_tac a=p and b=qa in next_sib_inj)\n     apply(simp)\n    apply(simp)\n   apply(simp)\n   apply(erule disjE)\n    apply(drule_tac a=qa and c=q in descendants_trans, simp)\n    apply(drule_tac a=qa and c=qa in descendants_trans, simp)\n    apply(simp add: no_mloop_descendants)\n   apply(simp)\n   apply(drule_tac a=a and c=a in descendants_trans, simp)\n   apply(simp add: no_mloop_descendants)\n  apply(erule_tac P=\"next_sib q t m = Some aaa\" in disjE)\n   apply(elim exE conjE, simp)\n   apply(drule(2) next_sib_inj, fastforce)\n  apply(elim exE conjE, simp)\n  apply(drule(2) next_sib_inj, simp)\n  apply(erule_tac x=a in allE)+\n  apply(erule disjE)\n   apply(simp)\n   apply(erule impE)\n    apply(rule_tac b=q in descendants_trans, simp+)\n    done\n\nlemma remove_collect: \"{y. P y} - {x} = {y. P y \\<and> y \\<noteq> x}\"\n  apply blast\n  done\n\n\nlocale mdb_insert_abs_simple =\nfixes m :: cdt\nfixes t :: cdt_list\nfixes dest :: cslot_ptr\nassumes valid_list : \"valid_list_2 t m\"\n\n\nlocale mdb_insert_abs_simple_parent = mdb_insert_abs_simple +\nfixes dest_p :: cslot_ptr\nfixes t' :: cdt_list\n\ndefines \"t' \\<equiv> t(dest_p := list_remove (t dest_p) dest)\"\n\nassumes dest: \"m dest = Some dest_p\"\nbegin\n\nlemma valid_list_post:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n    \"\n   valid_list_2 (t'(src := dest # (t' src)))\n        (m(dest \\<mapsto> src))\"\n  apply (insert valid_list dest)\n  apply (simp add: valid_list_2_def t'_def)\n  apply (simp add: list_remove_removed insert_Collect remove_collect)\n  apply (intro impI conjI allI)\n  apply (fastforce simp: list_remove_distinct cong: Collect_cong)+\n  done\n\n  lemma valid_list_post':\n  \"\\<lbrakk> t' src = []\\<rbrakk> \\<Longrightarrow>\n      valid_list_2 (t'(src := [dest]))\n        (m(dest \\<mapsto> src))\"\n\n  by (insert valid_list_post[where src=src],simp)\n\n\nend\n\nlocale mdb_insert_abs_simple_no_parent = mdb_insert_abs_simple +\nassumes dest: \"m dest = None\"\n\ncontext mdb_insert_abs_simple_no_parent\nbegin\n\nlemma valid_list_post:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n   \"valid_list_2 (t(src := dest # (t src)))\n        (m(dest \\<mapsto> src))\"\n  apply (insert valid_list dest)\n  apply (fastforce simp: valid_list_2_def)\n  done\n\n\nlemma valid_list_post':\n  \"\\<lbrakk> t src = []\\<rbrakk> \\<Longrightarrow>\n      valid_list_2 (t(src := [dest]))\n        (m(dest \\<mapsto> src))\"\n  by (insert valid_list_post[where src=src],simp)\nend\n\nlocale mdb_insert_abs_sib_simple_no_parent = mdb_insert_abs_simple_no_parent +\n\nfixes src :: cslot_ptr\nfixes n\ndefines \"n \\<equiv> m(dest := m src)\"\nassumes neq: \"dest \\<noteq> src\"\nbegin\n\nlemma valid_list_post_no_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>m src = None\\<rbrakk> \\<Longrightarrow> valid_list_2 t n\"\n  apply (insert valid_list dest)\n  apply (simp add: valid_list_2_def n_def)\n  apply fastforce\n  done\n\n\nlemma valid_list_post:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>m src = Some p\\<rbrakk>\n    \\<Longrightarrow> valid_list_2 (t(p := list_insert_after (t p) src dest)) n\"\n  apply (insert valid_list dest neq)\n  apply (simp add: valid_list_2_def n_def)\n  apply (fastforce simp: distinct_list_insert_after  set_list_insert_after)\n  done\n\nend\n\n\nlocale mdb_insert_abs_sib_simple_parent = mdb_insert_abs_simple_parent +\n\nfixes src :: cslot_ptr\nfixes n\ndefines \"n \\<equiv> m(dest := m src)\"\nassumes neq: \"dest \\<noteq> src\"\n\ncontext mdb_insert_abs_sib_simple_parent\nbegin\n\nlemma valid_list_post_no_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>m src = None\\<rbrakk> \\<Longrightarrow> valid_list_2 t' n\"\n  apply (insert valid_list dest)\n  apply (simp add: valid_list_2_def t'_def n_def)\n  apply (simp add: list_remove_removed insert_Collect remove_collect)\n  apply (fastforce simp: list_remove_distinct cong: Collect_cong)\n  done\n\n\nlemma valid_list_post:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>m src = Some p\\<rbrakk>\n    \\<Longrightarrow> valid_list_2 (t'(p := list_insert_after (t' p) src dest)) n\"\n  apply (insert valid_list dest neq)\n  apply (simp add: valid_list_2_def t'_def n_def)\n  apply (fastforce simp: distinct_list_insert_after list_remove_distinct set_list_insert_after list_remove_removed)\n  done\n\nend\n\n\ncontext mdb_insert_abs\nbegin\n\nlemma finite_depth_insert_child:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"finite_depth m \\<Longrightarrow> finite_depth (m(dest \\<mapsto> src))\"\n  apply(simp add: finite_depth_def descendants_child split del: if_split)\n  apply(rule allI)\n  apply(case_tac \"slot=dest\")\n   apply(case_tac \"m src\")\n    apply(rule_tac x=src in exI)\n    apply(simp add: neq)\n   apply(erule_tac x=src in allE)\n   apply(elim exE conjE)\n   apply(rule_tac x=p in exI)\n   apply(simp)\n   apply(rule notI)\n   apply(simp add: desc neq)\n  apply(erule_tac x=slot in allE)\n  apply(elim conjE exE)\n  apply(rule_tac x=p in exI)\n  apply(simp add: neq)\n  apply(intro conjI impI notI)\n   apply(simp add: desc)\n  apply(simp add: desc)\n  done\n\nlemma valid_list_post:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"valid_list_2 t m\n    \\<Longrightarrow> valid_list_2 (t(src := dest # t src))\n        (m(dest \\<mapsto> src))\"\n  apply (insert dest)\n  apply(fastforce simp: valid_list_2_def)\n  done\n\nlemma valid_list_post':\n  \"\\<lbrakk>valid_list_2 t m; t src = []\\<rbrakk>\n    \\<Longrightarrow> valid_list_2 (t(src := [dest]))\n        (m(dest \\<mapsto> src))\"\n  by (drule valid_list_post, simp)\n\nlemma next_child:\n  \"next_child p (t(src := dest # t src))\n     = (if p = src then Some dest else next_child p t)\"\n  apply(fastforce simp: next_child_def)\n  done\n\nlemma next_child':\n  \"t src = []\n    \\<Longrightarrow> next_child p (t(src := [dest])) = (if p = src then Some dest else next_child p t)\"\n  by (fastforce simp: next_child_def)\n\nlemma next_sib:\n  \"valid_list_2 t m\n    \\<Longrightarrow> next_sib p (t(src := dest # t src))\n        (m(dest \\<mapsto> src))\n     = (if p = dest then next_child src t else next_sib p t m)\"\n  apply(case_tac \"next_child src t\")\n   apply(simp)\n   apply(drule next_child_NoneD)\n   apply(safe)[1]\n    apply(rule_tac p=src in next_sib_NoneI)\n    apply(simp)\n   apply(case_tac \"next_sib p t m\")\n    apply(simp)\n    apply(drule next_sib_NoneD)\n    apply(erule disjE)\n     apply(rule next_sib_NoneI)\n     apply(simp)\n    apply(elim exE conjE)\n    apply(rule_tac p=pa in next_sib_NoneI)\n    apply(simp)\n   apply(simp)\n   apply(drule next_sibD)\n   apply(elim exE conjE)\n   apply(rule_tac p=pa in next_sibI)\n    apply(simp)\n   apply(fastforce simp: valid_list_2_def)\n  apply(drule (1) next_childD)\n  apply(simp, safe)\n   apply(case_tac \"next_child src t\")\n    apply(fastforce dest: next_child_NoneD)\n   apply(simp)\n   apply(fastforce dest: next_childD intro: next_sibI)\n  apply(case_tac \"next_sib p t m\")\n   apply(fastforce dest: next_sib_NoneD next_sibD intro: next_sib_NoneI next_sibI)+\n   done\n\nlemma next_sib':\n  \"\\<lbrakk>valid_list_2 t m; t src = []\\<rbrakk>\n    \\<Longrightarrow> next_sib p (t(src := [dest]))\n        (m(dest \\<mapsto> src))\n     = (if p = dest then None else next_sib p t m)\"\n  by (fastforce dest: next_sib[where p=p] intro: next_child_NoneI)\n\nlemma next_not_child:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"\\<lbrakk>valid_list_2 t m; finite_depth m; no_mloop m\\<rbrakk>\n  \\<Longrightarrow> next_not_child p (t(src := dest # t src)) (m(dest \\<mapsto> src))\n          = (if p = dest then next_slot src t m\n            else next_not_child p t m)\"\n  apply(simp)\n  apply(intro conjI impI)\n   apply(case_tac \"next_slot src t m\")\n    apply(simp add: next_slot_def split: if_split_asm)\n     apply(case_tac \"t src\", simp, simp add: next_child_def)\n    apply(drule(1) next_not_child_NoneD)\n    apply(rule next_not_child_NoneI)\n      apply(simp add: next_sib' descendants_child no_mloop_descendants desc)\n      apply(simp add: descendants_of_def)\n     apply(simp add: next_sib')\n    apply(simp add: finite_depth_insert_child)\n   apply(simp add: next_slot_def split: if_split_asm)\n    apply(rule next_not_childI)\n     apply(simp add: next_sib)\n    apply(simp add: finite_depth_insert_child)\n   apply(drule(2) next_not_childD)\n   apply(rule next_not_childI)\n    apply(simp add: next_sib' descendants_child)\n    apply(erule disjE)\n     apply(rule_tac x=src in exI)\n     apply(simp add: no_mloop_descendants desc neq)\n     apply(intro allI impI conjI)\n      apply(drule_tac a=src and b=q' and c=src in descendants_trans, simp)\n      apply(simp)\n     apply(simp add: descendants_of_def)\n    apply(elim exE conjE)\n    apply(rule_tac x=q in exI)\n    apply(simp)\n    apply(intro conjI impI notI allI)\n      apply(simp add: desc)\n     apply(simp add: descendants_of_def)\n    apply(simp)\n   apply(simp add: finite_depth_insert_child)\n  apply(case_tac \"next_not_child p t m\")\n   apply(simp)\n   apply(drule(1) next_not_child_NoneD)\n   apply(rule next_not_child_NoneI)\n     apply(simp add: next_sib descendants_child neq desc)\n    apply(simp add: next_sib)\n   apply(simp add: finite_depth_insert_child)\n  apply(simp)\n  apply(drule(2) next_not_childD)\n  apply(rule next_not_childI)\n   apply(simp add: next_sib descendants_child split del: if_split)\n   apply(erule disjE, simp, simp split del: if_split)\n   apply(elim exE conjE)\n   apply(rule_tac x=q in exI)\n   apply(simp add: desc neq)\n   apply(intro conjI impI notI)\n    apply(simp add: desc)\n   apply(simp add: desc)\n  apply(simp add: finite_depth_insert_child)\n  done\n\nlemma next_not_child':\n  \"\\<lbrakk>valid_list_2 t m; finite_depth m; no_mloop m; t src = []\\<rbrakk>\n    \\<Longrightarrow> next_not_child p (t(src := [dest])) (m(dest \\<mapsto> src))\n          = (if p = dest then next_not_child src t m\n            else next_not_child p t m)\"\n  apply(drule(2) next_not_child[where p=p])\n  apply(simp add: next_slot_def)\n  done\n\nlemma next_slot:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; finite_depth m; no_mloop m\\<rbrakk>\n    \\<Longrightarrow> next_slot p (t(src := dest # t src)) (m(dest \\<mapsto> src))\n     = (if p = src then Some dest\n        else if p = dest then next_slot src t m\n        else next_slot p t m)\"\n  apply(simp add: next_slot_def next_not_child next_child next_not_child' next_child')\n  apply(rule impI)\n  apply(drule next_child_None_empty_desc[where slot=dest])\n  apply(simp add: next_child_def)\n  apply(case_tac \"t dest\", simp, simp add: desc)\n  done\nend\n\n\n\n\ncontext mdb_insert_abs_sib\nbegin\n\nlemma finite_depth:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"finite_depth m \\<Longrightarrow> finite_depth n\"\n  apply(simp add: finite_depth_def descendants)\n  apply(simp add: n_def)\n  apply(rule allI)\n  apply(case_tac \"slot=dest\")\n   apply(erule_tac x=src in allE)\n   apply(elim exE conjE)\n   apply(erule disjE)\n    apply(rule_tac x=p in exI)\n    apply(simp)\n    apply(rule impI, simp add: desc)\n   apply(rule_tac x=dest in exI)\n   apply(simp)\n  apply(erule_tac x=slot in allE)\n  apply(elim exE conjE)\n  apply(rule_tac x=p in exI)\n  apply(simp)\n  apply(rule impI)\n  apply(simp add: desc)\n  done\n\nlemma valid_list_post_no_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; m src = None\\<rbrakk> \\<Longrightarrow> valid_list_2 t n\"\n  apply(insert dest)\n  apply(fastforce simp: n_def valid_list_2_def)\n  done\n\nlemma valid_list_post:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; m src = Some p\\<rbrakk>\n    \\<Longrightarrow> valid_list_2 (t(p := list_insert_after (t p) src dest)) n\"\n  apply(insert dest)\n  apply(fastforce simp: n_def valid_list_2_def set_list_insert_after distinct_list_insert_after)\n  done\n\nlemma next_child:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; m src = Some src_p\\<rbrakk>\n    \\<Longrightarrow> next_child p (t(src_p := list_insert_after (t src_p) src dest)) = next_child p t\"\n  apply(simp add: next_child_def)\n  apply(case_tac \"list_insert_after (t src_p) src dest\")\n   apply(simp)\n   apply(case_tac \"t src_p\")\n    apply(simp)\n   apply(simp split: if_split_asm)\n  apply(simp)\n  apply(case_tac \"t src_p\")\n   apply(simp)\n  apply(simp split: if_split_asm)\n  done\n\nlemma next_sib_no_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; m src = None\\<rbrakk>\n    \\<Longrightarrow> next_sib p t n\n    = (if p = src \\<and> m src \\<noteq> None then Some dest\n       else if p = dest then next_sib src t m\n       else next_sib p t m)\"\n  apply(simp add: n_def next_sib_def)\n  done\n\nlemma next_sib:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; m src = Some src_p\\<rbrakk>\n    \\<Longrightarrow> next_sib p (t(src_p := list_insert_after (t src_p) src dest)) n\n    = (if p = src \\<and> m src \\<noteq> None then Some dest\n       else if p = dest then next_sib src t m\n       else next_sib p t m)\"\n  apply(subgoal_tac \"dest \\<notin> set (t src_p) \\<and> src \\<in> set (t src_p)\")\n   prefer 2\n   apply(simp add: valid_list_2_def)\n  apply(simp add: next_sib_def n_def neq list_insert_after_after valid_list_2_def)\n  apply(case_tac \"m p\")\n   apply(simp)\n  apply(simp add: list_insert_after_after)\n  done\n\nlemma next_not_child_no_parent:\n    notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; finite_depth m; no_mloop m; m src = None\\<rbrakk>\n    \\<Longrightarrow> next_not_child p t n\n    = (if p = src then (if m src = None then None else Some dest)\n       else if p = dest then next_not_child src t m\n       else if p \\<in> descendants_of src m\n         \\<and> next_not_child p t m = next_not_child src t m then\n           (if m src = None then None else Some dest)\n       else next_not_child p t m)\"\n  apply(simp)\n  apply(intro conjI impI)\n       apply(simp add: descendants_of_def)\n      apply(simp add: no_mloop_def descendants_of_def)\n     apply(subgoal_tac \"next_not_child src t m = None\")\n      prefer 2\n      apply(rule next_not_child_NoneI)\n        apply(fastforce dest: descendants_of_NoneD)\n       apply(simp add: next_sib_def)\n      apply(simp)\n     apply(erule conjE, simp)\n     apply(drule(1) next_not_child_NoneD[where p=p])\n     apply(rule next_not_child_NoneI)\n       apply(simp add: next_sib_no_parent descendants desc)\n      apply(simp add: next_sib_no_parent)\n     apply(simp add: finite_depth)\n    apply(case_tac \"next_not_child src t m\")\n     apply(simp)\n     apply(drule(1) next_not_child_NoneD, rule next_not_child_NoneI)\n       apply(simp add: descendants next_sib_no_parent)\n       apply(simp add: descendants_of_def )\n      apply(simp add: next_sib_no_parent)\n     apply(simp add: finite_depth)\n    apply(simp)\n    apply(drule(2) next_not_childD, rule next_not_childI)\n     apply(erule disjE)\n      apply(simp add: next_sib_no_parent descendants)\n     apply(rule disjI2)\n     apply(simp add: next_sib_no_parent descendants)\n     apply(elim exE conjE)\n     apply(rule_tac x=q in exI)\n     apply(simp)\n     apply(intro allI conjI impI notI)\n      apply(simp add: desc)\n     apply(simp add: descendants_of_def)\n    apply(simp add: finite_depth)\n   apply(rule next_not_child_NoneI)\n     apply(intro allI impI)\n     apply(fastforce simp: descendants split: if_split_asm dest: descendants_of_NoneD)\n    apply(simp add: next_sib_no_parent)\n    apply(simp add: next_sib_def)\n   apply(simp add: finite_depth)\n  apply(case_tac \"next_not_child p t m\")\n   apply(simp add: next_sib_no_parent descendants desc finite_depth\n        | drule next_not_child_NoneD | rule next_not_child_NoneI)+\n  apply(simp add: next_sib_no_parent descendants desc\n       | drule next_not_childD | rule next_not_childI | erule disjE)+\n   apply(elim exE conjE)\n   apply(rule_tac x=q in exI)\n   apply(case_tac \"m dest\")\n    apply(fastforce simp: next_sib_def)\n   apply(fastforce simp: next_sib_def dest)\n  apply(simp add: finite_depth)\n  done\n\nlemma next_not_child:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; finite_depth m; no_mloop m; m src = Some src_p\\<rbrakk>\n    \\<Longrightarrow> next_not_child p (t(src_p := list_insert_after (t src_p) src dest)) n\n    = (if p = src then (if m src = None then None else Some dest)\n       else if p = dest then next_not_child src t m\n       else if p \\<in> descendants_of src m\n         \\<and> next_not_child p t m = next_not_child src t m then\n           (if m src = None then None else Some dest)\n       else next_not_child p t m)\"\n  apply(simp)\n  apply(intro conjI impI)\n       apply(simp add: descendants_of_def)\n      apply(simp add: no_mloop_def descendants_of_def)\n     apply(erule conjE)\n     apply(rule next_not_childI)\n      apply(rule disjI2)\n      apply(rule conjI)\n       apply(simp add: next_sib)\n       apply(rule_tac p=p and q=src in next_not_child_eq_next_sib_None)\n            apply(simp_all)[6]\n      apply(rule_tac x=src in exI)\n      apply(simp add: next_sib descendants no_mloop_descendants desc)\n      apply(intro allI impI)\n      apply(rule_tac p=p and q=src in next_not_child_eq_next_sib_None)\n           apply(simp_all add: no_mloop_descendants)[6]\n     apply(simp add: finite_depth)\n    apply(case_tac \"next_not_child src t m\")\n     apply(simp)\n     apply(drule(1) next_not_child_NoneD, rule next_not_child_NoneI)\n       apply(simp add: descendants next_sib)\n       apply(simp add: descendants_of_def no_mloop_def)\n      apply(simp add: next_sib)\n     apply(simp add: finite_depth)\n    apply(simp)\n    apply(drule(2) next_not_childD, rule next_not_childI)\n     apply(erule disjE)\n      apply(simp add: next_sib descendants)\n     apply(rule disjI2)\n     apply(simp add: next_sib descendants no_mloop_descendants)\n     apply(simp add: descendants_of_def)\n     apply(elim exE conjE)\n     apply(rule_tac x=q in exI)\n     apply(simp)\n     apply(intro conjI impI notI)\n      apply(simp add: desc)\n     apply(simp add: descendants_of_def)\n    apply(simp add: finite_depth)\n   apply(rule next_not_childI)\n    apply(rule disjI1)\n    apply(simp add: next_sib)\n   apply(simp add: finite_depth)\n  apply(case_tac \"next_not_child p t m\")\n   apply(frule(1) next_not_child_NoneD)\n   apply(simp add: next_sib descendants desc finite_depth\n        | rule next_not_child_NoneI)+\n     apply(intro impI notI)\n     apply(simp)\n     apply(case_tac \"next_not_child src t m\")\n      apply(simp)\n     apply(drule(2) next_not_childD)\n     apply(erule disjE, simp)\n     apply(elim exE conjE)\n     apply(drule_tac a=p and c=q in descendants_trans, simp, simp)\n    apply(simp add: next_sib)\n   apply(simp add: finite_depth)\n  apply(simp add: next_sib descendants desc no_mloop_descendants\n       | drule next_not_childD | rule next_not_childI | erule disjE)+\n   apply(elim exE conjE)\n   apply(rule_tac x=q in exI)\n   apply(simp)\n   apply(intro conjI impI notI)\n         apply(simp_all add: desc finite_depth)\n   apply(erule notE)\n   apply(rule next_not_childI[symmetric])\n    apply(simp)\n    apply(rule_tac x=q in exI)\n     apply(fastforce simp: descendants_of_def cdt_parent_defs)\n   apply(simp add: finite_depth)\n  apply(erule notE)\n  apply(rule next_not_childI[symmetric])\n   apply(simp)\n  apply(simp add: finite_depth)\n  done\n\nlemma next_slot_no_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; finite_depth m; no_mloop m; m src = None\\<rbrakk>\n    \\<Longrightarrow> next_slot p t n\n    = next_slot p t m\"\n  apply(subgoal_tac \"next_not_child dest t m = None\")\n   prefer 2\n   apply((rule next_not_child_NoneI | intro allI impI\n    | simp add: descendants_of_def next_sib_def finite_depth dest)+)[1]\n  apply(subgoal_tac \"next_not_child src t m = None\")\n   prefer 2\n   apply((rule next_not_child_NoneI | intro allI impI |\n         drule(1) descendants_of_NoneD | simp add: next_sib_def finite_depth)+)[1]\n  apply(simp add: next_slot_def next_not_child_no_parent)\n  done\n\nlemma next_slot:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; finite_depth m; no_mloop m; m src = Some src_p; t src = []\\<rbrakk>\n    \\<Longrightarrow> next_slot p (t(src_p := list_insert_after (t src_p) src dest)) n\n    = (if p = src then Some dest\n       else if p = dest then next_slot src t m\n       else next_slot p t m)\"\n  apply(simp)\n  apply(intro impI conjI)\n    apply(simp add: next_slot_def next_child next_not_child empty_list_empty_desc desc)\n    apply(rule impI, insert dest_no_parent_d, simp)[1]\n   apply(simp add: next_slot_def next_child next_not_child)\n   apply(rule impI, simp add: no_mloop_weaken)\n  apply(simp add: next_slot_def next_child next_not_child)\n  apply(intro conjI impI)\n             apply(simp_all)\n      apply(erule conjE, drule_tac a=src_p and c=src_p in descendants_trans,\n            simp add: child_descendant, simp add: no_mloop_descendants)+\n   apply(simp add: empty_list_empty_desc)\n  apply(simp only: set_empty[symmetric])\n  apply(simp add: set_list_insert_after)\n  done\nend\n\ncrunch exst[wp]: set_cap \"(\\<lambda>s. P (exst s))\" (wp: crunch_wps simp: crunch_simps)\n\nlemma set_cap_caps_of_state3:\n  \"\\<lbrace>\\<lambda>s. P (caps_of_state s (p \\<mapsto> cap)) (cdt s)  (exst s) (is_original_cap s)\\<rbrace>\n  set_cap cap p\n  \\<lbrace>\\<lambda>rv s. P (caps_of_state s) (cdt s) (exst s) (is_original_cap s)\\<rbrace>\"\n  apply (rule_tac Q=\"\\<lambda>rv s. \\<exists>m mr t. P (caps_of_state s) m t mr\n                    \\<and> (cdt s = m) \\<and> (exst s = t) \\<and> (is_original_cap s = mr)\"\n           in hoare_post_imp)\n   apply simp\n  apply (wp hoare_vcg_ex_lift)\n  apply (rule_tac x=\"cdt s\" in exI)\n  apply (rule_tac x=\"is_original_cap s\" in exI)\n  apply (simp add: fun_upd_def)\n  done\n\n\nlemma exst_cdt_update[iff]:\n  \"exst (s\\<lparr>cdt := a\\<rparr>) = exst s\"\n  by simp\n\ndefinition valid_mdb_weak where\n\"valid_mdb_weak s \\<equiv> mdb_cte_at (swp (cte_wp_at (op \\<noteq> NullCap)) s) (cdt s) \\<and> no_mloop (cdt s)\"\n\nlemma self_parent_eq: \"m src = Some src \\<Longrightarrow> m(dest \\<mapsto> src) = m (dest := m src)\"\n  by simp\n\nlemma ex1_False: \"(\\<And>x. \\<not>P x) \\<Longrightarrow> \\<not> (\\<exists>!x. P x)\" by auto\n\nlemma set_cap_match: \"(\\<And>s x. P s = P (s\\<lparr>kheap := x\\<rparr>)) \\<Longrightarrow> \\<lbrace>P\\<rbrace> set_cap a b \\<lbrace>\\<lambda>_.P\\<rbrace>\"\n  apply (simp add: set_cap_def split_def set_object_def get_object_def)\n  apply wpsimp\n  done\n\ncrunch all_but_exst[wp]: cap_insert_ext \"all_but_exst P\"\n\ncrunch (empty_fail) empty_fail[wp]: cap_insert_ext\n\ninterpretation cap_insert_ext_extended: is_extended \"cap_insert_ext a b c d e\"\n  by (unfold_locales; wp)\n\n\nlemma cap_insert_valid_list [wp]:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrace>valid_list\\<rbrace>\n    cap_insert cap src dest\n   \\<lbrace>\\<lambda>_ s. valid_list s\\<rbrace>\"\n  apply (simp add: cap_insert_def)\n  apply(simp add: set_untyped_cap_as_full_def update_cdt_def set_cdt_def update_cdt_list_def set_cdt_list_def bind_assoc cap_insert_ext_def)\n  apply (rule hoare_pre)\n   apply (fold revokable_def)\n   apply (wp | simp cong: option.case_cong if_cong del: fun_upd_apply split del: if_split)+\n       apply(wp set_cap_caps_of_state3)[1]\n      apply (case_tac \"is_untyped_cap src_cap \\<and>\n         is_untyped_cap cap \\<and>\n         obj_ref_of src_cap = obj_ref_of cap \\<and>\n         cap_bits_untyped src_cap = cap_bits_untyped cap\")\n\n       apply (simp del: fun_upd_apply split del: if_split)\n       apply (wp set_cap_caps_of_state3)\n      apply (simp only:)\n      apply (simp del: fun_upd_apply split del: if_split)\n     apply (wp get_cap_wp)+\n  apply(intro allI impI conjI)\n  apply (case_tac \"src = dest\")\n   apply (simp add: cte_wp_at_caps_of_state fun_upd_idem del: fun_upd_apply)\n   apply (case_tac \"cdt s dest\")\n    apply (simp del: fun_upd_apply split del: if_split  cong: option.case_cong)\n   apply (simp add: del: fun_upd_apply split del: if_split  cong: option.case_cong)\n\n   apply (fastforce simp add: valid_list_2_def list_remove_removed list_remove_distinct)\n  apply (case_tac \"cdt s dest\")\n\n   apply (subgoal_tac \"mdb_insert_abs_simple_no_parent (cdt s) (cdt_list s) dest\")\n    prefer 2\n    apply (rule mdb_insert_abs_simple_no_parent.intro[OF mdb_insert_abs_simple.intro])\n    apply simp\n    apply (rule mdb_insert_abs_simple_no_parent_axioms.intro)\n    apply simp\n\n   apply (subgoal_tac \"mdb_insert_abs_sib_simple_no_parent (cdt s) (cdt_list s) dest src\")\n    prefer 2\n    apply (rule mdb_insert_abs_sib_simple_no_parent.intro,assumption)\n    apply (rule mdb_insert_abs_sib_simple_no_parent_axioms.intro,simp)\n   apply(case_tac\"should_be_parent_of capa (is_original_cap s src) cap (revokable capa cap)\")\n    apply (case_tac \"cdt s src\")\n     apply (simp del: fun_upd_apply)\n     apply (rule mdb_insert_abs_simple_no_parent.valid_list_post,simp)\n    apply (case_tac \"a = src\")\n     apply (simp del: fun_upd_apply)\n     apply (subst self_parent_eq,assumption)\n     apply (rule mdb_insert_abs_sib_simple_no_parent.valid_list_post,simp,simp)\n    apply (simp add: fun_upd_twist del: fun_upd_apply)\n    apply (rule mdb_insert_abs_simple_no_parent.valid_list_post,simp)\n   apply (case_tac \"cdt s src\")\n    apply (frule(1) mdb_insert_abs_sib_simple_no_parent.valid_list_post_no_parent)\n    apply (simp del: fun_upd_apply)\n   apply (simp del: fun_upd_apply)\n   apply (frule(1) mdb_insert_abs_sib_simple_no_parent.valid_list_post)\n   apply (simp del: fun_upd_apply)\n\n  apply (subgoal_tac \"mdb_insert_abs_simple_parent (cdt s) (cdt_list s) dest a\")\n   prefer 2\n   apply (rule mdb_insert_abs_simple_parent.intro[OF mdb_insert_abs_simple.intro])\n    apply simp\n   apply (rule mdb_insert_abs_simple_parent_axioms.intro)\n   apply simp\n  apply (subgoal_tac \"mdb_insert_abs_sib_simple_parent (cdt s) (cdt_list s) dest a src\")\n   prefer 2\n   apply (rule mdb_insert_abs_sib_simple_parent.intro,assumption)\n   apply (rule mdb_insert_abs_sib_simple_parent_axioms.intro,simp)\n  apply(case_tac\"should_be_parent_of capa (is_original_cap s src) cap (revokable capa cap)\")\n   apply (case_tac \"cdt s src\")\n    apply (simp del: fun_upd_apply)\n    apply (rule mdb_insert_abs_simple_parent.valid_list_post,simp)\n   apply (case_tac \"aa = src\")\n    apply (simp del: fun_upd_apply)\n    apply (subst self_parent_eq,assumption)\n    apply (rule mdb_insert_abs_sib_simple_parent.valid_list_post,simp,simp)\n   apply (simp add: fun_upd_twist del: fun_upd_apply)\n   apply (rule mdb_insert_abs_simple_parent.valid_list_post,simp)\n  apply (case_tac \"cdt s src\")\n   apply (frule(1) mdb_insert_abs_sib_simple_parent.valid_list_post_no_parent)\n   apply (simp del: fun_upd_apply)\n  apply (simp del: fun_upd_apply)\n  apply (frule(1) mdb_insert_abs_sib_simple_parent.valid_list_post)\n  apply (simp del: fun_upd_apply)\n  done\n\nlemma cte_at_next_slot:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"\\<lbrakk>valid_list s; valid_mdb s; finite_depth (cdt s)\\<rbrakk>\n    \\<Longrightarrow> next_slot p (cdt_list s) (cdt s) = Some n \\<Longrightarrow> cte_at p s\"\n  apply(simp add: next_slot_def)\n  apply(simp split: if_split_asm)\n   apply(drule next_childD, simp)\n   apply(rule_tac p=n in descendants_of_cte_at2)\n    apply(simp add: child_descendant)\n   apply(simp)\n  apply(subgoal_tac \"next_not_child_dom (p, cdt_list s, cdt s)\")\n   prefer 2\n   apply(simp add: next_not_child_termination valid_mdb_def valid_list_2_def)\n  apply(simp split: if_split_asm)\n   apply(case_tac \"cdt s p\")\n    apply(simp)\n   apply(rule descendants_of_cte_at)\n    apply(simp add: descendants_of_def cdt_parent_defs)\n    apply(rule r_into_trancl, simp)\n   apply(simp)\n  apply(drule next_sibD)\n  apply(elim exE conjE)\n  apply(drule after_in_list_in_list)\n  apply(rule descendants_of_cte_at)\n   apply(simp add: descendants_of_def cdt_parent_defs)\n   apply(rule r_into_trancl, simp)\n  apply(simp)\n  done\n\nlemma cte_at_next_slot':\n  \"\\<lbrakk>valid_list s; valid_mdb s; finite_depth (cdt s)\\<rbrakk>\n    \\<Longrightarrow> next_slot p (cdt_list s) (cdt s) = Some n \\<Longrightarrow> cte_at n s\"\n  apply(simp add: next_slot_def)\n  apply(simp split: if_split_asm)\n   apply(drule next_childD, simp)\n   apply(rule_tac x=p in descendants_of_cte_at, simp add: child_descendant, simp)\n  apply(rule next_not_child_pinduct2[where t=\"cdt_list s\" and p=p\n                                             and m=\"cdt s\"])\n      apply(rule_tac p=a in descendants_of_cte_at2)\n       apply(fastforce simp: descendants_of_def cdt_parent_defs)\n      apply(simp)\n     apply(assumption)\n    apply(simp add: next_not_child_termination valid_mdb_def valid_list_2_def\n               split: if_split_asm)\n     apply(case_tac \"cdt s p\")\n      apply(simp)\n     apply(simp)\n     apply(rule descendants_of_cte_at)\n      apply(fastforce simp: descendants_of_def cdt_parent_defs)\n     apply(simp add: valid_mdb_def)\n    apply(drule next_sibD)\n    apply(case_tac \"cdt s p\")\n     apply(simp)\n    apply(rule descendants_of_cte_at)\n     apply(fastforce simp: descendants_of_def cdt_parent_defs)\n    apply(simp add: valid_mdb_def)\n   apply(intro allI impI, drule next_sibD)\n    apply(simp)\n   apply(elim exE conjE)\n   apply(drule_tac after_in_list_in_list)\n   apply(simp add: valid_list_2_def)\n   apply(rule_tac x=\"(aa, b)\" in descendants_of_cte_at, simp add: child_descendant, simp)\n  apply(simp)\n  done\n\nlemma Collect_union: \"{c. P c} \\<union> {c. Q c} = {c. P c \\<or> Q c}\"\n  apply blast\n  done\n\nlocale mdb_move_abs_simple =\nfixes m m' m'' :: cdt\nfixes t t' t''\nfixes src dest\nfixes valid_list_post\nassumes neq : \"src \\<noteq> dest\"\nassumes valid_list: \"valid_list_2 t m\"\ndefines \"t' \\<equiv> case m dest of Some dest_p \\<Rightarrow> t(dest_p := list_remove (t dest_p) dest) | None \\<Rightarrow> t\"\ndefines \"t'' \\<equiv> case m src of Some src_p \\<Rightarrow> t'(src_p := list_replace (t' src_p) src dest) | None \\<Rightarrow> t'\"\n\ndefines \"m'' \\<equiv> \\<lambda>r. if r = src then None else (m(dest := m src)) r\"\ndefines \"m' \\<equiv>\n     \\<lambda>r. if m'' r = Some src then Some dest\n         else (m(dest := m src, src := None)) r\"\nbegin\n\nlemma \"{c. m c = Some ab} - {dest} \\<union> {c. m c = Some dest} =\n          {c. c \\<noteq> dest \\<and>\n              (c \\<noteq> dest \\<longrightarrow> c \\<noteq> ab \\<and> (c \\<noteq> ab \\<longrightarrow> m c \\<noteq> Some ab \\<longrightarrow> m c = Some dest))}\"\n  oops\n\nlemma valid_list_post_no_parents:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  notes replace_distinct[simplified list_replace_def,simp]\n  shows\n  \"m src = None \\<Longrightarrow> m dest = None \\<Longrightarrow> valid_list_2 (t''(src := [], dest := (t'' src) @ (t'' dest))) m'\"\n  apply (insert valid_list neq)\n  apply (simp add: m'_def m''_def t'_def t''_def valid_list_2_def list_replace_def)\n  apply (intro impI conjI allI)\n  apply fastforce\n  apply fastforce\n  apply fastforce\n  done\n\nlemma valid_list_post_src_no_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  notes replace_distinct[simplified list_replace_def,simp]\n  notes list_remove_distinct[simp]\n  shows\n  \"m src = None \\<Longrightarrow> m dest = Some dest_p \\<Longrightarrow> valid_list_2 (t''(src := [], dest := (t'' src) @ (t'' dest))) m'\"\n  apply (insert valid_list neq)\n  apply (simp add: m'_def m''_def t'_def t''_def valid_list_2_def list_replace_def list_remove_removed)\n  apply (intro impI conjI allI)\n  apply fastforce+\n  done\n\nlemma valid_list_post_dest_no_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  notes replace_distinct[simplified list_replace_def,simp]\n  notes list_remove_distinct[simp]\n  shows\n  \"m src = Some src_p \\<Longrightarrow> m dest = None \\<Longrightarrow> valid_list_2 (t''(src := [], dest := (t'' src) @ (t'' dest))) m'\"\n  apply (insert valid_list neq)\n  apply (simp add: m'_def m''_def t'_def t''_def valid_list_2_def list_replace_def list_remove_removed)\n  apply (intro impI conjI allI)\n  apply fastforce+\n  done\n\nlemma valid_list_post_parents:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  notes replace_distinct[simplified list_replace_def,simp]\n  notes list_remove_distinct[simp]\n  shows\n  \"m src = Some src_p \\<Longrightarrow> m dest = Some dest_p \\<Longrightarrow> valid_list_2 (t''(src := [], dest := (t'' src) @ (t'' dest))) m'\"\n  apply (insert valid_list neq)\n  apply (simp add: m'_def m''_def t'_def t''_def )\n  apply (intro impI conjI allI)\n  apply (simp_all add: valid_list_2_def)\n  apply (simp_all add: list_replace_def list_remove_removed)\n  apply (intro impI conjI allI | fastforce)+\n  done\n\n\nlemma valid_list_post:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  notes replace_distinct[simplified list_replace_def,simp]\n  shows \"valid_list_2 (t''(src := [], dest := (t'' src) @ (t'' dest))) m'\"\n  apply (case_tac \"m src\")\n  apply (case_tac \"m dest\")\n  apply (simp add: valid_list_post_no_parents)\n  apply (simp add: valid_list_post_src_no_parent)\n  apply (case_tac \"m dest\")\n  apply (simp add: valid_list_post_dest_no_parent)\n  apply (simp add: valid_list_post_parents)\n  done\n\nend\n\n\n\n\nlocale mdb_move_abs' = mdb_move_abs + constrains s::\"det_ext state\"\n\ncontext mdb_move_abs'\nbegin\n\nlemma findepth : \"finite_depth m\"\n  apply (simp add: m)\n  apply (rule Deterministic_AI.finite_depth)\n  apply (rule valid_mdb)\n  done\n\nlemma finite_depth:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"finite_depth m'\"\n  apply (insert findepth)\n  apply(simp add: finite_depth_def descendants)\n  apply(rule allI)\n  apply(case_tac \"slot=dest\")\n   apply(erule_tac x=src in allE)\n   apply(elim exE conjE)\n   apply(erule disjE)\n    apply(rule_tac x=p in exI)\n    apply(simp add: m'_def m''_def)\n    apply(rule conjI)\n     apply(rule impI, simp add: dest_desc)\n    apply(intro impI notI)\n    apply(insert valid_mdb)[1]\n    apply(drule_tac slot=src in desc_not_parent, simp add: m)\n   apply(simp add: m'_def m''_def)\n   apply(fastforce)\n  apply(simp add: m'_def m''_def)\n  apply(erule_tac x=slot in allE)\n  apply(elim exE conjE)\n  apply(case_tac \"p=src\")\n   apply(erule disjE)\n    apply(rule_tac x=dest in exI)\n    apply(simp)\n   apply(rule_tac x=src in exI)\n   apply(simp)\n  apply(case_tac \"slot=src\")\n   apply(rule_tac x=src in exI)\n   apply(simp)\n  apply(rule_tac x=p in exI)\n  apply(simp)\n  apply(intro conjI impI)\n   apply(simp add: dest_desc)\n  apply(simp add: dest_desc)\n  done\n\nlemma valid_list_post_helper:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>dest \\<notin> set list;\n     distinct list\\<rbrakk>\n    \\<Longrightarrow> distinct\n        (map (\\<lambda>x. if x = src then dest else x) list)\"\n  apply (induct list)\n  apply force+\n  done\n\n\nlemma valid_list_post:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; m src = Some src_p\\<rbrakk>\n    \\<Longrightarrow> valid_list_2 (t(src_p := list_replace (t src_p) src dest, src := [], dest := t src)) m'\"\n  apply (simp add: valid_list_2_def)\n  apply (rule Collect_cong | simp add: list_replace_def m'_def m''_def split: if_split_asm | intro iffI impI conjI notI allI | force | fastforce)+\n  apply clarsimp\n  apply (subgoal_tac \"dest \\<notin> set (t src_p)\")\n   apply (blast intro: valid_list_post_helper)\n  apply simp\n  done\n\nlemma valid_list_post_no_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; m src = None\\<rbrakk>\\<Longrightarrow> valid_list_2 (t(src := [], dest := t src)) m'\"\n  apply(simp add: valid_list_2_def)\n  apply (rule Collect_cong | simp add: list_replace_def m'_def m''_def split: if_split_asm | intro iffI impI conjI notI allI | fastforce)+\n  done\n\n\nlemma next_child:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"valid_list_2 t m \\<Longrightarrow> m src = Some src_p\n    \\<Longrightarrow> next_child p (t(src_p := list_replace (t src_p) src dest, src := [], dest := t src))\n      = (if p = src then None\n         else if p = dest then next_child src t\n         else if next_child p t = Some src then Some dest\n         else next_child p t)\"\n  apply (simp split: if_split)\n  apply (clarsimp simp: next_child_def list_replace_def)\n  apply (intro impI conjI)\n    apply (fold next_child_def)[1]\n    apply (frule(1) next_childD)\n    apply clarsimp\n   apply (case_tac \"t src_p\",simp+)\n  apply (case_tac \"t p\",simp)\n  apply (simp add: valid_list_2_def)\n  apply (subgoal_tac \"src \\<in> set (t p)\")\n   apply (thin_tac \"t p = src # list\")\n   apply simp+\n  done\n\n\nlemma next_child_no_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"valid_list_2 t m \\<Longrightarrow> m src = None\n    \\<Longrightarrow> next_child p (t(src := [], dest := t src))\n      = (if p = src then None\n         else if p = dest then next_child src t\n         else if next_child p t = Some src then Some dest\n         else next_child p t)\"\n  apply (simp split: if_split)\n  apply (clarsimp simp add: next_child_def)\n  apply (fold next_child_def)\n  apply (frule(1) next_childD,clarsimp)\n  done\n\nlemma next_sib_no_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"valid_list_2 t m \\<Longrightarrow> m src = None\n    \\<Longrightarrow> next_sib p (t(src := [], dest := t src)) m'\n      = (if p = src then None\n         else if p = dest then next_sib src t m\n         else if next_sib p t m = Some src then Some dest\n         else next_sib p t m)\"\n  apply (simp add: next_sib_def m'_def m''_def split: if_split)\n  apply (intro impI conjI)\n    apply (simp split: option.splits  | drule(1) valid_list_2D[OF _ after_in_list_in_list])+\n   done\n\n\n\n\n\n\nlemma next_sib:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"valid_list_2 t m \\<Longrightarrow> m src = Some src_p\n    \\<Longrightarrow> next_sib p (t(src_p := list_replace (t src_p) src dest, src := [], dest := t src)) m'\n      = (if p = src then None\n         else if p = dest then next_sib src t m\n         else if next_sib p t m = Some src then Some dest\n         else next_sib p t m)\"\n  apply (simp add: next_sib_def m'_def m''_def split: if_split)\n  apply (intro impI conjI)\n    apply (intro impI | simp split: option.splits  | drule(1) valid_list_2D[OF _ after_in_list_in_list] | rule after_in_list_list_replace | rule replace_list_preserve_after replace_list_preserve_after' | simp add: valid_list_2_def)+\n    done\n\nlemma next_not_child_root:\n  assumes findepth: \"finite_depth k\"\n  shows\n  \"k p = None \\<Longrightarrow> next_not_child p t k = None\"\n  apply (subst next_not_child.psimps[OF next_not_child_termination[OF findepth]])\n  apply (simp add: next_sib_def)\n  done\n\n\n\nlemma next_not_child_no_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  notes nnext = next_not_child.psimps[OF next_not_child_termination[OF findepth]]\n  notes nnext' = next_not_child.psimps[OF next_not_child_termination[OF finite_depth]]\n  notes nnext'' = nnext'[simplified m'_def m''_def]\n  shows\n  \"valid_list_2 t m \\<Longrightarrow> m src = None\n    \\<Longrightarrow> next_not_child p (t(src := [], dest := t src)) m'\n      = (if p = src then None\n         else if p = dest then next_not_child src t m\n         else if next_not_child p t m = Some src then Some dest\n         else next_not_child p t m)\"\n  apply (induct p rule: next_not_child_pinduct[where t=t and m=m, OF _ findepth])\n  apply (case_tac \"m slot\")\n   apply (subst next_not_child_root[OF findepth],assumption)+\n   apply (subst next_not_child_root[OF finite_depth])\n    apply ((simp add: m'_def m''_def)+)[2]\n  apply (case_tac \"next_sib slot t m\")\n   apply (drule_tac x=\"a\" in meta_spec)\n   apply (simp add: m'_def m''_def next_sib_def nnext nnext'' cong: if_weak_cong split: if_split_asm)\n  apply (simp split del: if_split)\n  apply (thin_tac \"\\<And>a. \\<lbrakk>False; Q a\\<rbrakk> \\<Longrightarrow> P a\" for Q P)\n  apply (simp add: m'_def m''_def next_sib_def nnext nnext'' cong: if_weak_cong split: if_split_asm | intro impI conjI)+\n    apply (simp add: valid_list_2_def | drule after_in_list_in_list | clarsimp)+\n    done\n\nlemma m'_helper: \"m src = k \\<Longrightarrow> m' dest = k\"\n  apply (clarsimp simp: m'_def m''_def)+\n  done\n\nlemma m'_helper2: \"x \\<noteq> src \\<Longrightarrow> x \\<noteq> dest \\<Longrightarrow> m x \\<noteq> Some src \\<Longrightarrow> m' x = m x\"\n  apply (clarsimp simp: m'_def m''_def)\n  done\n\nlemma m'_helper3: \"x \\<noteq> dest \\<Longrightarrow> m x = Some src \\<Longrightarrow> m' x = Some dest\"\n  apply (clarsimp simp: m'_def m''_def)\n  done\n\nlemma m'_helper4: \"m' src = None\"\n  apply (clarsimp simp: m'_def m''_def)\n  done\n\nlemmas m'_helpers = m'_helper m'_helper2 m'_helper3 m'_helper4\n\nlemma not_self[simp]: \"m x \\<noteq> Some x\"\n  apply clarsimp\n  apply (insert no_mloop)\n  apply (frule no_mloop_neq)\n  apply simp+\n  done\n\nlemma src_loop_facts:  \"m src = Some src_p \\<Longrightarrow> m src_p \\<noteq> Some src\" \"m src = Some src_p \\<Longrightarrow> src_p \\<noteq> src\"\n  apply -\n  apply (rule notI)\n   apply (frule child_descendant)\n   apply (frule parent_not_descendant[OF no_mloop],simp)\n  apply (rule notI)\n  apply simp\n  done\n\n\n\n\nlemma next_not_child_parent:\nnotes split_paired_All[simp del] split_paired_Ex[simp del]\nshows\n\"\\<lbrakk>valid_list_2 t m; m src = Some src_p\\<rbrakk>\n    \\<Longrightarrow> next_not_child src_p (t(src_p := list_replace (t src_p) src dest, src := [], dest := t src)) m' =\n       next_not_child src_p t m\"\n  apply (case_tac \"src_p = dest\",simp)\n  apply (insert src_loop_facts[where src_p=src_p])\n  apply (rule next_not_child_linearI'[OF findepth finite_depth])\n    apply (simp add: m'_def m''_def)\n   apply (simp add: next_sib)\n   apply (rule notI)\n   apply (frule(1) next_sib_same_parent,simp)\n  apply (intro impI allI conjI)\n   apply (simp add: m'_def m''_def)\n   apply (intro impI conjI)\n     apply (rule notI)\n     apply simp\n     apply (cut_tac dest_desc,simp)\n    apply (rule notI)\n    apply simp\n    apply (frule parent_not_descendant[OF no_mloop],simp)\n   apply (rule notI)\n   apply (subgoal_tac \"q \\<in> descendants_of src_p m\")\n    apply (frule ancestor_not_descendant[OF no_mloop],simp)\n   apply (rule descendants_trans)\n    apply (rule child_descendant)\n    apply simp\n   apply (rule child_descendant)\n   apply simp\n  apply (simp add: next_sib)\n  apply (intro impI conjI)\n    apply (simp add:  m'_helpers)+\n    apply (frule(1) next_sib_same_parent,simp)\n    apply (frule parent_not_descendant[OF no_mloop],simp)\n   apply (simp add: m'_def m''_def)+\n  done\n\n\n\nlemma next_not_child_helper':\nnotes split_paired_All[simp del] split_paired_Ex[simp del]\n  notes nnext = next_not_child.psimps[OF next_not_child_termination[OF findepth]]\n  notes nnext' = next_not_child.psimps[OF next_not_child_termination[OF finite_depth]]\nshows\n\"\\<lbrakk>valid_list_2 t m; m src = Some src_p; m slot = None\\<rbrakk>\n           \\<Longrightarrow> next_not_child slot (t(src_p := list_replace (t src_p) src dest, src := [], dest := t src))\n               m' =\n              (if slot = src then None\n               else if slot = dest then next_not_child src t m\n                    else if next_not_child slot t m = Some src then Some dest\n                         else next_not_child slot t m)\"\n  apply (simp add: next_sib m'_helpers\n          nnext[where slot=slot]\n          nnext[where slot=dest]\n          nnext[where slot=src]\n          nnext'[where slot=slot]\n          nnext'[where slot=dest]\n          nnext'[where slot=src])\n  apply (intro impI conjI,simp_all)\n  apply (rule next_not_child_parent,simp+)+\n  done\n\nlemma next_not_child_helper'':\nnotes split_paired_All[simp del] split_paired_Ex[simp del]\n  notes nnext = next_not_child.psimps[OF next_not_child_termination[OF findepth]]\n  notes nnext' = next_not_child.psimps[OF next_not_child_termination[OF finite_depth]]\n\nshows\n  \"\\<lbrakk>valid_list_2 t m; m src = Some src_p; m slot = Some a;\n        next_sib slot t m = Some aa\\<rbrakk>\n       \\<Longrightarrow> next_not_child slot (t(src_p := list_replace (t src_p) src dest, src := [], dest := t src)) m' =\n          (if slot = src then None\n           else if slot = dest then next_not_child src t m\n                else if next_not_child slot t m = Some src then Some dest else next_not_child slot t m)\"\n  apply (simp add: next_sib m'_helpers\n          nnext[where slot=slot]\n          nnext'[where slot=slot] )\n  apply (intro impI conjI,simp_all)\n  done\n\nlemma next_not_child_helper''':\nnotes split_paired_All[simp del] split_paired_Ex[simp del]\n  notes nnext = next_not_child.psimps[OF next_not_child_termination[OF findepth]]\n  notes nnext' = next_not_child.psimps[OF next_not_child_termination[OF finite_depth]]\n\nshows\n\"\\<lbrakk>valid_list_2 t m; m src = Some src_p; src_p \\<noteq> src; m src_p \\<noteq> Some src; m slot = Some a;\n        next_not_child a (t(src_p := list_replace (t src_p) src dest, src := [], dest := t src)) m' =\n        (if a = src then None\n         else if a = dest then next_not_child src t m\n              else if next_not_child a t m = Some src then Some dest else next_not_child a t m);\n        next_sib slot t m = None\\<rbrakk>\n       \\<Longrightarrow> next_not_child slot (t(src_p := list_replace (t src_p) src dest, src := [], dest := t src)) m' =\n          (if slot = src then None\n           else if slot = dest then next_not_child src t m\n                else if next_not_child slot t m = Some src then Some dest else next_not_child slot t m)\"\n  apply (case_tac \"src_p = dest\")\n  apply simp\n  apply (simp add: next_sib m'_helpers\n          nnext[where slot=slot]\n          nnext[where slot=dest]\n          nnext[where slot=src]\n\n          nnext'[where slot=slot]\n          nnext'[where slot=dest]\n          nnext'[where slot=src]\nsplit: if_split_asm)\n    apply (intro impI conjI,simp_all)\n      apply (drule next_not_childD[OF _ findepth no_mloop])\n      apply (elim disjE)\n       apply (frule(1) next_sib_same_parent,simp)\n      apply (elim conjE exE)\n      apply (frule (1) next_sib_same_parent,simp)\n      apply (frule parent_not_descendant[OF no_mloop],simp)\n     apply (rule next_not_child_parent,simp+)\n    apply (frule next_sib_not_self[where src=src],simp)\n   apply (intro impI conjI)\n    apply (rule next_not_child_parent,simp+)\n  apply (intro impI conjI)\n   apply (rule next_not_child_parent,simp+)\n  done\n\n\nlemma next_not_child:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  notes nnext = next_not_child.psimps[OF next_not_child_termination[OF findepth]]\n  notes nnext' = next_not_child.psimps[OF next_not_child_termination[OF finite_depth]]\n  assumes misc: \"valid_list_2 t m\" \"m src = Some src_p\"\n  shows\n  \"next_not_child p (t(src_p := list_replace (t src_p) src dest, src := [], dest := t src)) m'\n      = (if p = src then None\n         else if p = dest then next_not_child src t m\n         else if next_not_child p t m = Some src then Some dest\n         else next_not_child p t m)\"\n  apply (insert misc)\n  apply (insert src_loop_facts[where src_p=src_p],simp split del: if_split)\n  apply (induct p rule: next_not_child_pinduct[where t=t and m=m, OF _ findepth])\n  apply (case_tac \"m slot\")\n   apply (rule next_not_child_helper',(simp split del: if_split)+)\n  apply (drule_tac x=a in meta_spec)\n  apply (simp split del: if_split)\n  apply (case_tac \"next_sib slot t m\")\n   apply (rule next_not_child_helper''',(simp split del: if_split)+)\n  apply (rule next_not_child_helper'',(simp split del: if_split)+)\n  done\n\n\nlemma next_slot_no_parent:\n  \"valid_list_2 t m \\<Longrightarrow> m src = None\n    \\<Longrightarrow> next_slot p (t(src := [], dest := t src)) m'\n      = (if p = src then None\n         else if p = dest then next_slot src t m\n         else if next_slot p t m = Some src then Some dest\n         else next_slot p t m)\"\n  apply (simp only: next_slot_def split: if_split)\n  apply (intro impI conjI)\n  apply (subst next_child_no_parent| subst next_not_child_no_parent | simp)+\n  done\n\n\n\nlemma next_slot:\n  \"valid_list_2 t m \\<Longrightarrow> m src = Some src_p\n    \\<Longrightarrow> next_slot p (t(src_p := list_replace (t src_p) src dest, src := [], dest := t src)) m'\n      = (if p = src then None\n         else if p = dest then next_slot src t m\n         else if next_slot p t m = Some src then Some dest\n         else next_slot p t m)\"\n  apply (simp only: next_slot_def split: if_split)\n  apply (intro impI conjI)\n  apply (subst next_child | subst next_not_child | (simp split: if_split_asm) | intro impI conjI)+\n  done\n\nend\n\nlemma\nnotes split_paired_All[simp del]\nshows\n\"\\<lbrakk>valid_list_2 t m\\<rbrakk>\n        \\<Longrightarrow> valid_list_2\n            (case m dest of None \\<Rightarrow> t\n             | Some a \\<Rightarrow> t\n                 (a := list_remove (t a) dest))\n            (m(dest := None))\"\n\n  apply (case_tac \"m dest\")\n  apply (fastforce simp: valid_list_2_def list_remove_removed intro: list_remove_distinct)+\n  done\n\nlemma cap_move_valid_list [wp]:\n\n  notes split_paired_All[simp del]\n  shows\n  \"\\<lbrace>valid_list\\<rbrace>\n  cap_move cap src dest\n  \\<lbrace>\\<lambda>_. valid_list\\<rbrace>\"\n  apply (case_tac \"src = dest\")\n   apply (simp add: cap_move_def)\n   apply(simp add: set_cdt_def cap_move_ext_def\n                    update_cdt_list_def set_cdt_list_def del: fun_upd_apply split del: if_split)\n   apply(wp)\n    apply (simp del: fun_upd_apply cong: option.case_cong)\n    apply (wp set_cap_caps_of_state3)+\n   apply (case_tac \"cdt s dest\")\n    apply (fastforce simp: valid_list_2_def list_remove_removed intro: list_remove_distinct)+\n  apply (simp add: cap_move_def)\n  apply(simp add: cap_move_def set_cdt_def cap_move_ext_def bind_assoc\n                  update_cdt_list_def set_cdt_list_def del: fun_upd_apply split del: if_split)\n  apply(wp)\n   apply (simp del: fun_upd_apply split del: if_split)\n   apply (unfold valid_list_2_def)\n   apply (simp del: fun_upd_apply cong: option.case_cong split del: if_split)\n   apply (wp set_cap_caps_of_state3)+\n  apply (fold valid_list_2_def)\n  apply (rule mdb_move_abs_simple.valid_list_post)\n  apply (rule mdb_move_abs_simple.intro; simp)\n  done\n\ndeclare if_cong[cong]\n\n\nlemma next_sib_share_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"\\<lbrakk>next_sib a t m = Some b; valid_list_2 t m\\<rbrakk>\n    \\<Longrightarrow> a \\<in> descendants_of c m = (b \\<in> descendants_of c m)\"\n  apply(drule next_sibD)\n  apply(case_tac \"m a\", simp, simp)\n  apply(subgoal_tac \"m b = Some aa\")\n   prefer 2\n   apply(fastforce simp: after_in_list_in_list valid_list_2_def)\n  apply(simp add: descendants_of_def cdt_parent_defs)\n  apply(case_tac \"c=aa\")\n   apply(fastforce)\n  apply(rule iffI)\n   apply(rule_tac b=aa in trancl_into_trancl)\n    apply(drule tranclD2)\n    apply(simp)\n    apply(drule rtranclD)\n    apply(simp)\n   apply(simp)\n  apply(rule_tac b=aa in trancl_into_trancl)\n   apply(drule tranclD2)\n   apply(simp)\n   apply(drule rtranclD)\n   apply(simp)\n  apply(simp)\n  done\n\nlemma desc_sib_ne:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"\\<lbrakk>a \\<in> descendants_of b m; next_sib b t m = Some c; valid_list_2 t m;\n    no_mloop m\\<rbrakk>\n    \\<Longrightarrow> a \\<noteq> c\"\n  apply(rule notI)\n  apply(drule next_sibD)\n  apply(case_tac \"m b\", simp, simp)\n  apply(subgoal_tac \"aa \\<in> descendants_of aa m\")\n   prefer 2\n   apply(simp add: descendants_of_def cdt_parent_defs)\n   apply(rule_tac b=b in trancl_into_trancl2)\n    apply(simp)\n   apply(drule tranclD2)\n   apply(simp)\n   apply(drule after_in_list_in_list)\n   apply(simp add: valid_list_2_def)\n   apply(drule rtranclD)\n   apply(fastforce)\n  apply(simp add: no_mloop_descendants)\n  done\n\nlemma (in mdb_empty_abs) finite_depth:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"finite_depth m \\<Longrightarrow> finite_depth n\"\n  apply(simp add: finite_depth_def descendants)\n  apply(rule allI)\n  apply(simp add: n_def)\n  apply(case_tac \"slota=slot\")\n   apply(simp)\n  apply(simp)\n  apply(erule_tac x=slota in allE)\n  apply(elim exE conjE)\n  apply(case_tac \"p=slot\")\n   apply(simp)\n   apply(subgoal_tac \"\\<exists>a. m a = Some slot \\<and>\n               (slota \\<in> descendants_of a m \\<or> slota = a)\")\n    prefer 2\n    apply(simp add: descendants_of_def cdt_parent_defs)\n    apply(drule tranclD)\n    apply(elim exE conjE)\n    apply(simp)\n    apply(rule_tac x=z in exI)\n    apply(simp)\n    apply(drule rtranclD)\n    apply(erule disjE)\n     apply(simp)\n    apply(simp)\n   apply(erule exE)\n   apply(rule_tac x=a in exI)\n   apply(simp)\n   apply(fastforce)\n  apply(rule_tac x=p in exI)\n  apply(simp)\n  done\n\n\n\nlemma distinct_list_replace_list:\n \"\\<lbrakk>distinct list; distinct list'; set list \\<inter> set list' = {}; slot \\<in> set list\\<rbrakk>\n    \\<Longrightarrow> distinct (list_replace_list list slot list')\"\n  apply(induct list)\n   apply(simp)\n  apply(simp)\n  apply(intro conjI impI)\n    apply(fastforce)\n   apply(subst set_list_replace_list)\n      apply(simp)\n     apply(simp)\n    apply(fastforce)\n   apply(simp)\n  apply(simp)\n  done\n\n\nlocale mdb_empty_abs_simple =\nfixes m n t slot\nassumes valid_list: \"valid_list_2 t m\"\ndefines \"n \\<equiv> (\\<lambda>p. if m p = Some slot then m slot else m p)(slot := None)\"\nbegin\n\nlemma valid_list_post_no_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>m slot = None\\<rbrakk> \\<Longrightarrow> valid_list_2 (t(slot := [])) n\"\n  apply (insert valid_list)\n  apply(simp add: valid_list_2_def n_def)\n  apply(intro conjI impI allI notI)\n  apply(fastforce)\n  done\n\nlemma valid_list_post_self_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>m slot = Some slot_p; slot_p = slot\\<rbrakk>\n    \\<Longrightarrow> valid_list_2 (t(slot_p := list_remove (t slot_p) slot)) n\"\n  apply (insert valid_list)\n  apply (simp add: valid_list_2_def n_def list_remove_removed list_remove_distinct)\n  apply fastforce\n  done\n\nlemma valid_list_post:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>m slot = Some slot_p; slot_p \\<noteq> slot\\<rbrakk>\n    \\<Longrightarrow> valid_list_2 (t(slot_p := list_replace_list (t slot_p) slot (t slot), slot := [])) n\"\n  apply (insert valid_list)\n  apply(simp add: valid_list_2_def n_def)\n  apply(intro conjI impI allI)\n  apply (fastforce simp: set_list_replace_list intro!: distinct_list_replace_list)+\n  done\nend\n\nlocale mdb_empty_abs' = mdb_empty_abs + constrains s::\"det_ext state\"\n\n\n\nlemma (in mdb_empty_abs') valid_list_post_no_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; m slot = None\\<rbrakk> \\<Longrightarrow> valid_list_2 (t(slot := [])) n\"\n  apply(simp add: valid_list_2_def)\n  apply(intro conjI impI allI notI)\n   apply(simp add: n_def split: if_split_asm)\n  apply(fastforce simp: n_def split: if_split_asm)\n  done\n\n\n\nlemma (in mdb_empty_abs') valid_list_post:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; m slot = Some slot_p\\<rbrakk>\n    \\<Longrightarrow> valid_list_2 (t(slot_p := list_replace_list (t slot_p) slot (t slot), slot := [])) n\"\n  apply(simp add: valid_list_2_def)\n  apply(intro conjI impI allI)\n      apply(simp)\n     apply(simp add: n_def)\n     apply(fastforce simp: set_list_replace_list n_def)\n    apply(simp add: n_def)\n   apply(simp add: n_def, fastforce)\n  apply(rule distinct_list_replace_list)\n     apply(simp)+\n   apply(rule ccontr)\n   apply(fastforce dest: int_not_emptyD)\n  apply(simp)\n  done\n\nlemma (in mdb_empty_abs') next_child_no_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; m slot = None\\<rbrakk>\n    \\<Longrightarrow> next_child p (t(slot := []))\n    = (if p = slot then None\n      else next_child p t)\"\n  apply(simp, intro conjI impI)\n   apply(rule next_child_NoneI)\n   apply(simp)\n  apply(case_tac \"next_child p t\")\n   apply(simp)\n   apply(rule next_child_NoneI, drule next_child_NoneD)\n   apply(simp)\n  apply(simp)\n  apply(drule(1) next_childD)\n  apply(elim exE conjE)\n  apply(rule next_childI)\n  apply(simp)\n  done\n\nlemma (in mdb_empty_abs') next_child:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; m slot = Some slot_p\\<rbrakk>\n    \\<Longrightarrow> next_child p (t(slot_p := list_replace_list (t slot_p) slot (t slot), slot := []))\n     = (if p = slot then None\n       else if next_child p t = Some slot then\n         if t slot = [] then\n           if t p = [slot] then None\n           else if hd (t p) = slot then after_in_list (t p) slot\n           else Some (hd (t p))\n         else next_child slot t\n       else next_child p t)\"\n  apply(case_tac \"p=slot\")\n   apply(fastforce intro: next_child_NoneI dest: next_child_NoneD)\n  apply(case_tac \"next_child p t = Some slot\")\n   apply(simp split del: if_split)\n   apply(drule(1) next_childD)\n   apply(elim exE conjE)\n   apply(case_tac \"t slot\")\n    apply(simp)\n    apply(intro conjI impI)\n     apply(rule next_child_NoneI)\n     apply(simp)\n    apply(case_tac xs, simp, simp)\n    apply(rule next_childI)\n    apply(simp)\n   apply(simp)\n   apply(fastforce simp: next_child_def intro: next_childI next_child_NoneI)\n  apply(simp)\n  apply(case_tac \"next_child p t\")\n   apply(simp)\n   apply(drule next_child_NoneD)\n   apply(rule next_child_NoneI)\n   apply(fastforce)\n  apply(simp)\n  apply(fastforce intro: next_childI dest: next_childD simp: next_child_def)\n  done\n\nlemma (in mdb_empty_abs') next_sib_no_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; m slot = None\\<rbrakk>\n    \\<Longrightarrow> next_sib p (t(slot := [])) n\n    = (if m p = Some slot then None\n      else next_sib p t m)\"\n  apply(simp, intro conjI impI)\n   apply(rule next_sib_NoneI)\n   apply(simp add: n_def)\n  apply(case_tac \"next_sib p t m\")\n   apply(simp)\n   apply(drule next_sib_NoneD)\n   apply(erule disjE)\n    apply(rule next_sib_NoneI)\n    apply(simp add: n_def)\n   apply(elim exE conjE)\n   apply(rule next_sib_NoneI)\n   apply(rule disjI2)\n   apply(fastforce simp: n_def)\n  apply(fastforce dest: next_sibD intro: next_sibI simp: n_def)\n  done\n\n\nlemma (in mdb_empty_abs') next_sib:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; m slot = Some slot_p\\<rbrakk>\n    \\<Longrightarrow> next_sib p (t(slot_p := list_replace_list (t slot_p) slot (t slot), slot := [])) n\n     = (if p = slot then None\n       else if next_sib p t m = Some slot then\n         if t slot = [] then next_sib slot t m\n         else next_child slot t\n       else if m p = Some slot \\<and> after_in_list (t slot) p = None then\n         next_sib slot t m\n       else next_sib p t m)\"\n  apply(case_tac \"p=slot\")\n   apply(simp)\n   apply(fastforce simp: n_def intro: next_sib_NoneI)\n  apply(case_tac \"next_sib p t m = Some slot\")\n   apply(simp, intro conjI impI)\n    apply(case_tac \"next_sib slot t m\")\n     apply(simp)\n     apply(drule next_sib_NoneD)\n     apply(erule disjE)\n      apply(fastforce intro: next_sib_NoneI)\n     apply(drule next_sibD)\n     apply(elim exE conjE)\n     apply(rule next_sib_NoneI)\n     apply(rule disjI2)\n     apply(rule conjI)\n      apply(fastforce simp: n_def)\n     apply(simp, intro conjI impI)\n      apply(simp add: list_replace_empty_after_empty valid_list_2_def)\n     apply(drule after_in_list_in_list)\n     apply(simp add: valid_list_2_def)\n    apply(simp)\n    apply(drule next_sibD)+\n    apply(elim exE conjE)\n    apply(rule next_sibI)\n     apply(fastforce simp: n_def)\n    apply(simp)\n    apply(intro conjI impI notI)\n       apply(simp)\n      apply(simp add: list_replace_empty_after_empty valid_list_2_def)\n     apply(simp)\n    apply(drule after_in_list_in_list, simp add: valid_list_2_def)\n   apply(drule next_sibD, elim exE conjE)\n   apply(case_tac \"next_child slot t\")\n    apply(simp, drule next_child_NoneD)\n    apply(rule next_sib_NoneI, simp add: n_def)\n   apply(simp, drule(1) next_childD)\n   apply(elim exE conjE)\n   apply(rule next_sibI)\n    apply(simp add: n_def)\n    apply(intro conjI impI)\n     apply(simp)\n    apply(drule after_in_list_in_list)\n    apply(simp add: valid_list_2_def)\n   apply(simp)\n   apply(intro conjI impI notI, simp)\n   apply(subst list_replace_after_fst_list)\n     apply(frule after_in_list_in_list)\n     apply(simp add: valid_list_2_def)\n    apply(simp add: valid_list_2_def)\n   apply(simp)\n  apply(simp)\n  apply(intro conjI impI)\n   apply(case_tac \"next_sib slot t m\")\n    apply(simp)\n    apply(drule next_sib_NoneD)\n    apply(erule disjE)\n     apply(fastforce simp: n_def intro: next_sib_NoneI)\n    apply(elim exE conjE)\n    apply(rule next_sib_NoneI)\n    apply(rule disjI2)\n    apply(rule conjI)\n     apply(fastforce simp: n_def)\n    apply(simp)\n    apply(rule impI)\n    apply(drule_tac list=\"t slot_p\" and slot=slot in list_replace_after_None_notin_old)\n      apply(simp add: valid_list_2_def)\n     apply(simp add: valid_list_2_def)\n    apply(simp)\n   apply(simp)\n   apply(drule next_sibD)\n   apply(elim exE conjE)\n   apply(rule next_sibI)\n    apply(simp add: n_def)\n   apply(simp)\n   apply(intro conjI impI notI)\n    apply simp\n   apply(drule_tac list=\"t slot_p\" and slot=slot in list_replace_after_None_notin_old)\n     apply(simp add: valid_list_2_def)\n    apply(simp add: valid_list_2_def)\n   apply(simp)\n  apply(case_tac \"next_sib p t m\")\n   apply(simp)\n   apply(drule next_sib_NoneD)\n   apply(erule disjE)\n    apply(fastforce intro: next_sib_NoneI simp: n_def)\n   apply(elim exE conjE)\n   apply(case_tac \"pa=slot\")\n    apply(fastforce intro: next_sib_NoneI)\n   apply(rule_tac p=pa in next_sib_NoneI)\n   apply(rule disjI2)\n   apply(fastforce simp add: valid_list_2_def n_def list_replace_after_None_notin_new)\n  apply(simp)\n  apply(drule next_sibD)\n  apply(elim exE conjE)\n  apply(case_tac \"pa=slot\")\n   apply(rule next_sibI)\n    apply(simp add: n_def)\n   apply(simp)\n   apply(fastforce intro: list_replace_after_notin_old simp: valid_list_2_def)\n  apply(simp)\n  apply(rule next_sibI)\n   apply(simp add: n_def)\n  apply(fastforce intro: list_replace_after_notin_new simp: valid_list_2_def)\n  done\n\nlemma (in mdb_empty_abs') next_not_child_no_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"\\<lbrakk>valid_list_2 t m; finite_depth m; m slot = None\\<rbrakk>\n    \\<Longrightarrow> next_not_child p (t(slot := [])) n\n    = (if (\\<exists>sl. next_not_child p t m = Some sl \\<and> m sl = Some slot)\n        then None\n      else next_not_child p t m)\"\n  apply(simp)\n  apply(intro conjI impI)\n   apply(elim exE conjE)\n   apply(drule(1) next_not_childD, simp add: no_mloop)\n   apply(rule next_not_child_NoneI)\n     apply(simp add: next_sib_no_parent descendants)\n     apply(intro allI impI)\n     apply(erule disjE)\n      apply(drule next_sibD)\n      apply(elim exE conjE)\n      apply(drule after_in_list_in_list)\n      apply(simp add: valid_list_2_def)\n      apply(simp add: descendants_of_def cdt_parent_defs)\n      apply(drule tranclD2, simp)\n      apply(drule rtranclD, simp)\n      apply(drule tranclD2, simp)\n     apply(elim conjE exE)\n     apply(erule_tac x=q in allE)\n     apply(erule impE)\n      apply(simp)\n      apply(drule next_sibD)\n      apply(elim exE conjE)\n      apply(drule after_in_list_in_list)\n      apply(simp add: valid_list_2_def)\n      apply(drule_tac a=p and b=q and c=qa in descendants_linear)\n        apply(simp)\n       apply(fastforce)\n      apply(erule disjE)\n       apply(simp)\n      apply(simp add: descendants_of_def cdt_parent_defs)\n      apply(drule_tac x=q in tranclD2, simp)\n      apply(drule rtranclD, simp)\n      apply(drule_tac x=q in tranclD2, simp)\n     apply(simp)\n    apply(simp add: next_sib_no_parent)\n    apply(rule impI)\n    apply(erule disjE)\n     apply(drule next_sibD)\n     apply(elim exE conjE)\n     apply(drule after_in_list_in_list)\n     apply(simp add: valid_list_2_def)\n    apply(simp)\n   apply(simp add: finite_depth)\n  apply(case_tac \"next_not_child p t m\")\n   apply(simp)\n   apply(drule(1) next_not_child_NoneD)\n   apply(rule next_not_child_NoneI)\n     apply(intro allI impI)\n     apply(simp add: next_sib_no_parent descendants split: if_split_asm)\n    apply(simp add: next_sib_no_parent)\n   apply(simp add: finite_depth)\n  apply(simp)\n  apply(drule(1) next_not_childD, simp add: no_mloop)\n  apply(rule next_not_childI)\n   apply(erule disjE)\n    apply(rule disjI1)\n    apply(simp add: next_sib_no_parent)\n    apply(drule next_sibD)\n    apply(elim exE conjE, drule after_in_list_in_list)\n    apply(simp add: valid_list_2_def)\n   apply(rule disjI2)\n   apply(rule conjI)\n    apply(simp add: next_sib_no_parent)\n   apply(elim conjE exE)\n   apply(rule_tac x=q in exI)\n   apply(intro conjI)\n     apply(simp add: next_sib_no_parent)\n     apply(drule next_sibD)\n     apply(elim exE conjE, drule after_in_list_in_list)\n     apply(simp add: valid_list_2_def)\n    apply(simp add: descendants)\n    apply(drule next_sibD)\n    apply(elim exE conjE, drule after_in_list_in_list)\n    apply(simp add: valid_list_2_def)\n    apply(rule conjI)\n     apply(fastforce)\n    apply(intro notI impI)\n    apply(simp)\n    apply(simp add: descendants_of_def cdt_parent_defs)\n    apply(drule tranclD2, simp)\n   apply(intro allI impI)\n   apply(simp add: next_sib_no_parent descendants split: if_split_asm)\n  apply(simp add: finite_depth)\n  done\n\nlemma (in mdb_empty_abs') next_sib':\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; m slot = Some slot_p; t slot = []\\<rbrakk>\n    \\<Longrightarrow> next_sib p (t(slot_p := list_replace_list (t slot_p) slot [], slot := [])) n\n     = (if p = slot then None\n       else if next_sib p t m = Some slot then\n         next_sib slot t m\n       else next_sib p t m)\"\n  apply(insert next_sib)\n  apply(atomize)\n  apply(erule_tac x=t in allE, erule_tac x=slot_p in allE, erule_tac x=p in allE)\n  apply(simp split: if_split_asm)\n  apply(simp add: valid_list_2_def)\n  apply(erule conjE)\n  apply(erule_tac x=slot in allE)\n  apply(fastforce)\n  done\n\nlemma (in mdb_empty_abs') next_not_child:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"\\<lbrakk>valid_list_2 t m; m slot = Some slot_p; finite_depth m\\<rbrakk>\n    \\<Longrightarrow> next_not_child p (t(slot_p := list_replace_list (t slot_p) slot (t slot), slot := [])) n\n     = (if p = slot then None\n       else if next_not_child p t m = Some slot then next_slot slot t m\n       else next_not_child p t m)\"\n  apply(case_tac \"p=slot\")\n   apply(simp)\n   apply(rule next_not_child_NoneI)\n     apply(fastforce simp: next_sib descendants)\n    apply(simp add: next_sib)\n   apply(simp add: finite_depth)\n  apply(case_tac \"next_not_child p t m = Some slot\")\n   apply(simp)\n   apply(simp add: next_slot_def)\n   apply(intro conjI impI)\n    apply(subgoal_tac \"\\<exists>c. next_child slot t = Some c\")\n     prefer 2\n     apply(case_tac \"t slot\")\n      apply(simp add: next_child_def)\n     apply(simp add: next_child_def)\n    apply(erule exE)\n    apply(simp)\n    apply(drule(1) next_not_childD, simp add: no_mloop)\n    apply(rule next_not_childI)\n     apply(erule disjE)\n      apply(simp add: next_sib)\n     apply(rule disjI2)\n     apply(elim exE conjE)\n     apply(subgoal_tac \"p \\<notin> descendants_of slot m\")\n      prefer 2\n      apply(rule notI)\n      apply(drule next_sibD)\n      apply(elim exE conjE)\n      apply(drule_tac a=p and b=slot and c=q in descendants_linear)\n        apply(simp)\n       apply(rule notI, simp add: after_in_list_not_self valid_list_2_def)\n      apply(drule after_in_list_in_list)\n      apply(simp add: valid_list_2_def)\n      apply(subgoal_tac \"pa \\<in> descendants_of pa m\")\n       prefer 2\n       apply(simp add: descendants_of_def cdt_parent_defs)\n       apply(erule disjE)\n        apply(rule_tac b=q in trancl_into_trancl2)\n         apply(simp)\n        apply(drule_tac x=q and y=slot in tranclD2)\n        apply(simp)\n        apply(drule rtranclD)\n        apply(fastforce)\n       apply(rule_tac b=slot in trancl_into_trancl2)\n        apply(simp)\n       apply(drule_tac x=slot and y=q in tranclD2)\n       apply(simp)\n       apply(drule rtranclD)\n       apply(fastforce)\n      apply(insert valid_mdb)[1]\n      apply(drule_tac slot=pa in desc_not_parent, simp add: m_def)\n     apply(subgoal_tac \"m p \\<noteq> Some slot\")\n      prefer 2\n      apply(rule notI)\n      apply(fastforce simp: descendants_of_def cdt_parent_defs)\n     apply(rule conjI)\n      apply(simp add: next_sib)\n     apply(rule_tac x=q in exI)\n     apply(simp add: descendants)\n     apply(intro conjI impI notI)\n       apply(simp)\n      apply(simp add: next_sib)\n     apply(intro allI impI)\n     apply(subgoal_tac \"m q' \\<noteq> Some slot\")\n      prefer 2\n      apply(rule notI)\n      apply(drule next_sibD)\n      apply(elim exE conjE, drule after_in_list_in_list)\n      apply(simp add: valid_list_2_def)\n      apply(subgoal_tac \"pa \\<in> descendants_of pa m\")\n       prefer 2\n       apply(simp add: descendants_of_def cdt_parent_defs)\n       apply(rule_tac b=q in trancl_into_trancl2)\n        apply(simp)\n       apply(elim conjE)\n       apply(drule_tac x=q and y=q' in tranclD2)\n       apply(simp)\n       apply(drule rtranclD)\n       apply(simp)\n       apply(drule_tac x=q and y=slot in tranclD2)\n       apply(simp)\n       apply(drule rtranclD)\n       apply(fastforce)\n      apply(insert valid_mdb)[1]\n      apply(drule_tac slot=pa in desc_not_parent, simp add: m_def)\n     apply(simp add: next_sib)\n    apply(simp add: finite_depth)\n   apply(case_tac \"next_not_child slot t m\")\n    apply(simp)\n    apply(drule(1) next_not_child_NoneD)\n    apply(drule(1) next_not_childD, simp add: no_mloop)\n    apply(rule next_not_child_NoneI)\n      apply(intro impI allI)\n      apply(simp add: next_sib' descendants split: if_split_asm)\n      apply(erule disjE)\n       apply(drule_tac c=q in next_sib_share_parent, simp)\n       apply(fastforce)\n      apply(elim conjE exE)\n      apply(rule impI)\n      apply(drule_tac a=p and b=qa and c=q in descendants_linear)\n        apply(simp)\n       apply(fastforce)\n      apply(erule disjE)\n       apply(drule_tac c=q in next_sib_share_parent, simp)\n       apply(fastforce)\n      apply(fastforce)\n     apply(fastforce simp: next_sib')\n    apply(simp add: finite_depth)\n   apply(simp)\n   apply(drule(1) next_not_childD, simp add: no_mloop)+\n   apply(elim disjE conjE exE)\n      apply(rule next_not_childI)\n       apply(simp add: next_sib')\n      apply(simp add: finite_depth)\n     apply(frule_tac a=p and c=q in next_sib_share_parent, simp)\n     apply(rule next_not_childI)\n      apply(simp add: next_sib' descendants)\n      apply(rule_tac x=q in exI)\n      apply(simp)\n      apply(frule_tac a=slot and c=a in desc_sib_ne)\n         apply(simp)\n        apply(simp)\n       apply(simp add: no_mloop)\n      apply(simp)\n      apply(rule conjI)\n       apply(rule notI)\n       apply(simp add: no_mloop no_mloop_descendants)\n      apply(intro impI allI)\n      apply(elim conjE)\n      apply(drule_tac a=p and c=q' in next_sib_share_parent, simp)\n      apply(simp)\n     apply(simp add: finite_depth)\n    apply(rule next_not_childI)\n     apply(simp add: next_sib')\n     apply(rule_tac x=q in exI)\n     apply(simp add: descendants)\n     apply(intro conjI impI allI notI)\n      apply(frule next_sibD)\n      apply(simp add: not_sib_self)\n     apply(simp)\n    apply(simp add: finite_depth)\n   apply(rule next_not_childI)\n    apply(simp add: next_sib')\n    apply(rule_tac x=qa in exI)\n    apply(simp add: descendants)\n    apply(frule_tac a=slot and b=qa and c=a in desc_sib_ne)\n       apply(simp)\n      apply(simp)\n     apply(simp add: no_mloop)\n    apply(simp)\n    apply(frule_tac a=q and c=qa in next_sib_share_parent)\n     apply(simp)\n    apply(simp)\n    apply(intro conjI impI allI notI)\n      apply(simp)\n     apply(rule_tac b=q in descendants_trans)\n      apply(simp)\n     apply(simp)\n    apply(erule conjE)\n    apply(case_tac \"q=q'\")\n     apply(simp)\n    apply(frule_tac a=p and b=q and c=q' in descendants_linear)\n      apply(simp)\n     apply(simp)\n    apply(erule disjE)\n     apply(drule_tac a=q and c=q' in next_sib_share_parent)\n      apply(simp)\n     apply(fastforce)\n    apply(fastforce)\n   apply(simp add: finite_depth)\n  apply(simp)\n  apply(case_tac \"next_not_child p t m\")\n   apply(simp)\n   apply(drule(1) next_not_child_NoneD)\n   apply(erule conjE)\n   apply(rule next_not_child_NoneI)\n     apply(intro allI impI)\n     apply(simp add: next_sib descendants split: if_split_asm)\n     apply(intro impI conjI)\n      apply(simp add: valid_list_2_def)\n      apply(erule conjE)\n      apply(erule_tac x=slot in allE)+\n      apply(fastforce)\n     apply(drule_tac a=p and b=q and c=slot in descendants_trans)\n      apply(fastforce simp: descendants_of_def cdt_parent_defs)\n     apply(simp)\n    apply(simp add: next_sib)\n    apply(erule_tac x=slot in allE)\n    apply(fastforce simp: descendants_of_def cdt_parent_defs)\n   apply(simp add: finite_depth)\n  apply(simp)\n  apply(drule(1) next_not_childD, simp add: no_mloop)\n  apply(erule disjE)\n   apply(frule next_sibD)\n   apply(rule next_not_childI)\n    apply(rule disjI1)\n    apply(fastforce simp: next_sib)\n   apply(simp add: finite_depth)\n  apply(elim conjE exE)\n  apply(rule next_not_childI)\n   apply(case_tac \"q=slot \\<and> m p = Some slot\")\n    apply(rule disjI1)\n    apply(simp add: next_sib)\n    apply(drule next_sib_NoneD, simp, simp)\n   apply(rule disjI2)\n   apply(rule conjI)\n    apply(simp add: next_sib)\n    apply(rule impI)\n    apply(erule conjE)\n    apply(frule_tac a=p and b=q and c=slot in descendants_linear)\n      apply(simp add: child_descendant)\n     apply(simp)\n    apply(erule disjE)\n     apply(simp add: descendants_of_def cdt_parent_defs)\n     apply(drule tranclD2, simp)\n     apply(drule rtranclD, simp)\n     apply(drule_tac x=slot and y=q and z=slot in trancl_trans)\n      apply(simp)\n     apply(insert no_mloop)[1]\n     apply(simp add: no_mloop_def cdt_parent_defs)\n    apply(simp add: child_descendant)\n   apply(case_tac \"q=slot\")\n    apply(simp)\n    apply(subgoal_tac \"\\<exists>c. m c = Some slot \\<and> p \\<in> descendants_of c m\")\n     prefer 2\n     apply(simp add: descendants_of_def cdt_parent_defs)\n     apply(drule tranclD)\n     apply(elim exE conjE)\n     apply(rule_tac x=z in exI)\n     apply(simp)\n     apply(drule rtranclD)\n     apply(fastforce)\n    apply(elim exE conjE)\n    apply(rule_tac x=c in exI)\n    apply(rule conjI)\n     apply(simp add: next_sib)\n     apply(subgoal_tac \"next_sib c t m = None\")\n      prefer 2\n      apply(erule_tac x=c in allE)\n      apply(erule_tac Q=\"next_sib c t m = None\" in impE)\n       apply(simp add: child_descendant)\n      apply(simp)\n     apply(simp)\n     apply(intro conjI impI)\n       apply(fastforce)\n      apply(fastforce)\n     apply(frule_tac slot=c in next_sib_NoneD, simp)\n    apply(rule conjI)\n     apply(simp add: descendants)\n     apply(fastforce)\n    apply(intro allI impI)\n    apply(simp add: next_sib descendants split: if_split_asm)\n    apply(subgoal_tac \"next_sib q' t m = None\")\n     prefer 2\n     apply(erule_tac x=q' in allE)\n     apply(erule_tac Q=\"next_sib q' t m = None\" in impE)\n      apply(simp)\n      apply(rule_tac b=c in descendants_trans)\n       apply(simp)\n      apply(simp add: child_descendant)\n     apply(simp)\n    apply(simp)\n    apply(intro conjI impI notI)\n     apply(simp add: valid_list_2_def, erule conjE)\n     apply(erule_tac x=slot in allE)+\n     apply(fastforce)\n    apply(erule conjE)\n    apply(simp add: descendants_of_def cdt_parent_defs)\n    apply(drule_tac x=c and y=q' in tranclD2)\n    apply(simp)\n    apply(drule rtranclD)\n    apply(simp)\n    apply(drule_tac a=c and b=slot and c=c in trancl_into_trancl)\n     apply(simp)\n    apply(insert no_mloop)[1]\n    apply(simp add: no_mloop_def cdt_parent_defs)\n   apply(rule_tac x=q in exI)\n   apply(intro conjI)\n     apply(simp add: next_sib)\n     apply(frule next_sibD)\n     apply(intro conjI impI)\n     apply(simp)\n    apply(simp add: descendants)\n   apply(intro allI impI)\n   apply(simp add: next_sib descendants split: if_split_asm)\n   apply(intro conjI impI)\n    apply(simp add: valid_list_2_def, erule conjE)\n    apply(erule_tac x=slot in allE)+\n    apply(fastforce)\n   apply(elim conjE)\n   apply(erule_tac x=slot in allE)\n   apply(erule impE)\n    apply(rule conjI)\n     apply(simp add: descendants_of_def cdt_parent_defs)\n     apply(drule_tac x=q and y=q' in tranclD2, simp)\n     apply(drule rtranclD, simp)\n    apply(rule_tac b=q' in descendants_trans)\n     apply(simp)\n    apply(simp add: child_descendant)\n   apply(simp)\n  apply(simp add: finite_depth)\n  done\n\nlemma (in mdb_empty_abs') next_slot_no_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; m slot = None; no_mloop m; finite_depth m\\<rbrakk>\n    \\<Longrightarrow> next_slot p (t(slot := [])) n\n     = (if p = slot then None\n       else if (\\<exists>sl. next_slot p t m = Some sl \\<and> m sl = Some slot)\n         then None\n       else next_slot p t m)\"\n  apply(case_tac \"p=slot\")\n   apply(simp add: next_slot_def next_not_child_no_parent)\n   apply(rule impI)\n   apply(simp add: next_not_child_termination next_sib_def)\n  apply(case_tac \"\\<exists>sl. next_slot p t m = Some sl \\<and> m sl = Some slot\")\n   apply(simp add: next_slot_def)\n   apply(intro conjI impI)\n    apply(elim exE conjE)\n    apply(simp split: if_split_asm)\n    apply(drule(1) next_childD)\n    apply(simp)\n   apply(simp add: next_not_child_no_parent)\n  apply(simp only:, simp)\n  apply(simp add: next_slot_def next_child_no_parent next_not_child_no_parent)\n  apply(fastforce split: if_split_asm)\n  done\n\nlemma (in mdb_empty_abs') next_slot:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_list_2 t m; m slot = Some slot_p; no_mloop m; finite_depth m\\<rbrakk>\n    \\<Longrightarrow> next_slot p (t(slot_p := list_replace_list (t slot_p) slot (t slot), slot := [])) n\n     = (if p = slot then None\n       else if next_slot p t m = Some slot then next_slot slot t m\n       else next_slot p t m)\"\n  apply(case_tac \"p=slot\")\n   apply(simp add: next_slot_def next_not_child next_child)\n  apply(case_tac \"next_slot p t m = Some slot\")\n   apply(simp only: next_slot_def next_not_child next_child)\n   apply(case_tac \"t slot = []\")\n    apply(simp split del: if_split)\n    apply(case_tac \"t p = []\")\n     apply(fastforce)\n    apply(case_tac \"p=slot_p \\<and> t slot_p = [slot]\")\n     apply(simp)\n     apply(rule impI)\n     apply(subgoal_tac \"next_not_child_dom (slot, t, m)\")\n      prefer 2\n      apply(simp add: next_not_child_termination valid_list_2_def)\n     apply(simp)\n     apply(rule impI, erule exE)\n     apply(frule_tac src=slot in next_sib_not_self)\n     apply(drule next_sibD)\n     apply(fastforce)\n    apply(simp split del: if_split)\n    apply(case_tac \"p = slot_p\")\n     apply(subgoal_tac \"list_replace_list (t slot_p) slot [] \\<noteq> []\")\n      prefer 2\n      apply(case_tac \"t slot_p\")\n       apply(simp)\n      apply(simp add: valid_list_2_def)\n     apply(simp split del: if_split)\n     apply(simp)\n     apply(intro conjI impI)\n      apply(case_tac \"t slot_p\")\n       apply(simp)\n      apply(simp)\n      apply(case_tac list)\n       apply(simp)\n      apply(simp)\n      apply(rule next_not_childI[symmetric])\n       apply(simp add: next_sib_def)\n      apply(simp)\n     apply(case_tac \"t slot_p\")\n      apply(simp)\n     apply(simp add: next_child_def)\n    apply(simp)\n    apply(rule conjI)\n     apply(rule impI)\n     apply(case_tac \"t p\")\n      apply(simp)\n     apply(simp add: valid_list_2_def)\n     apply(erule conjE)\n     apply(erule_tac x=p in allE)\n     apply(simp add: set_eq_subset)\n    apply(intro conjI impI)\n     apply(fastforce simp: valid_list_2_def)\n    apply(case_tac \"t p\")\n     apply(simp)\n    apply(simp add: next_child_def)\n   apply(simp split del: if_split)\n   apply(case_tac \"t p\")\n    apply(fastforce)\n   apply(case_tac \"t p = [slot]\")\n    apply(fastforce)\n   apply(fastforce split: if_split_asm)\n  apply(simp)\n  apply(simp add: next_slot_def split del: if_split)\n  apply(case_tac \"t p\")\n   apply(fastforce simp: next_not_child next_child)\n  apply(case_tac \"t p = [slot]\")\n   apply(simp add: next_not_child next_child next_child_def)\n  apply(simp add: next_child next_not_child)\n  apply(fastforce split: if_split_asm)\n  done\n\ncrunch valid_list[wp]: deleted_irq_handler,set_cap valid_list\n\ncrunch all_but_exst[wp]: empty_slot_ext \"all_but_exst P\"\n\ncrunch (empty_fail) empty_fail[wp]: empty_slot_ext\n\ninterpretation empty_slot_extended: is_extended \"empty_slot_ext a b\"\n  by (unfold_locales; wp)\n\n\nlemma empty_slot_valid_list[wp]:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrace>valid_list\\<rbrace>\n     empty_slot sl irqopt\n   \\<lbrace>\\<lambda>rv. valid_list\\<rbrace>\"\n  apply (simp add: empty_slot_def)\n  apply (simp add: set_cdt_def update_cdt_list_def set_cdt_list_def\n                   empty_slot_ext_def bind_assoc cong: if_cong)\n  apply (wp get_cap_wp static_imp_wp | wpc | wp_once hoare_vcg_all_lift)+\n  apply (clarsimp simp del: fun_upd_apply)\n  apply (frule mdb_empty_abs_simple.intro)\n  apply(case_tac \"cdt s sl\")\n   apply (frule(1) mdb_empty_abs_simple.valid_list_post_no_parent)\n   apply simp\n  apply (case_tac \"a = sl\")\n   apply (frule(2) mdb_empty_abs_simple.valid_list_post_self_parent)\n   apply simp\n  apply (frule(2) mdb_empty_abs_simple.valid_list_post)\n  apply simp\n  done\n\nlemma set_cap_exst_update:\n  \"((),s') \\<in> fst (set_cap c p s) \\<Longrightarrow> ((),exst_update f s') \\<in> fst (set_cap c p (exst_update f s))\"\n  apply (cases p)\n  apply (clarsimp simp add: set_cap_def in_monad get_object_def)\n  apply (case_tac y)\n      apply (auto simp add: in_monad set_object_def split: if_split_asm)\n  done\n\nlemma no_parent_not_next_slot:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"\\<lbrakk>m slot = None; valid_list_2 t m; finite_depth m; no_mloop m\\<rbrakk>\n          \\<Longrightarrow> next_slot p t m \\<noteq> Some slot\"\n  apply(rule notI)\n  apply(simp add: next_slot_def split: if_split_asm)\n   apply(drule(1) next_childD)\n   apply(simp)\n  apply(drule(2) next_not_childD)\n  apply(erule disjE)\n   apply(drule next_sibD)\n   apply(elim exE conjE)\n   apply(drule after_in_list_in_list)\n   apply(simp add: valid_list_2_def)\n  apply(elim conjE exE)\n  apply(drule next_sibD)\n  apply(elim exE conjE)\n  apply(drule after_in_list_in_list)\n  apply(simp add: valid_list_2_def)\n  done\n\n\ndefinition descendants_prop where\n \"descendants_prop P t \\<equiv> (\\<forall>p. \\<forall>c \\<in> set (t p). P c)\"\n\nlocale mdb_swap_abs_simple =\n fixes m :: cdt\n fixes t t' t'' n' n dest src\n defines \"n' \\<equiv>\n     \\<lambda>n. if m n = Some src then Some dest\n         else if m n = Some dest then Some src else m n\"\n    and \"n \\<equiv> n'(src := n' dest, dest := n' src)\"\n defines \"t' \\<equiv> (case n src of\n      None \\<Rightarrow> (case n dest of\n        None \\<Rightarrow> t'' |\n        Some dest_p \\<Rightarrow> t'' (dest_p := list_replace (t'' dest_p) src dest)) |\n      Some src_p \\<Rightarrow> (case n dest of\n        None \\<Rightarrow> t'' (src_p := list_replace (t'' src_p) dest src) |\n        Some dest_p \\<Rightarrow> if src_p = dest_p\n          then t'' (src_p := list_swap (t'' src_p) src dest)\n          else t'' (src_p := list_replace (t'' src_p) dest src,\n                     dest_p := list_replace (t'' dest_p) src dest)))\"\n  defines \"t'' \\<equiv> t(src := t dest, dest := t src)\"\n assumes valid_list: \"valid_list_2 t m\"\nbegin\n\n\n\nlemma valid_list_post_no_parents:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"m src = None \\<Longrightarrow> m dest = None \\<Longrightarrow> valid_list_2 t' n\"\n  apply (insert valid_list)\n  apply (simp add: t'_def t''_def n_def n'_def valid_list_2_def)\n  apply (intro impI conjI allI)\n  apply fastforce+\n  done\n\nlemma valid_list_post_src_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"m src = Some src_p \\<Longrightarrow> m dest = None \\<Longrightarrow> valid_list_2 t' n\"\n  apply (insert valid_list)\n  apply (simp add: t'_def t''_def n_def n'_def)\n  apply (intro impI conjI allI)\n  apply (fastforce simp: valid_list_2_def replace_distinct list_replace_set)+\n  done\n\nlemma valid_list_post_dest_parent:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"m src = None \\<Longrightarrow> m dest = Some dest_p \\<Longrightarrow> valid_list_2 t' n\"\n  apply (insert valid_list)\n  apply (simp add: t'_def t''_def n_def n'_def)\n  apply (intro impI conjI allI)\n  apply (fastforce simp: valid_list_2_def replace_distinct list_replace_set)+\n  done\n\nlemma valid_list_post_parents:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"m src = Some src_p \\<Longrightarrow> m dest = Some dest_p \\<Longrightarrow> valid_list_2 t' n\"\n  apply (insert valid_list)\n  apply (simp add: t'_def t''_def n_def n'_def)\n  apply (intro impI conjI allI)\n  apply (simp add: valid_list_2_def list_swap_def swap_distinct[simplified list_swap_def] list_replace_def replace_distinct[simplified list_replace_def]| intro impI conjI allI | fastforce)+\n  done\n\nlemma valid_list_post:\n  \"valid_list_2 t' n\"\n  apply (case_tac \"m src\")\n  apply (case_tac \"m dest\")\n    apply (simp add: valid_list_post_no_parents)\n   apply (simp add: valid_list_post_dest_parent)\n  apply (case_tac \"m dest\")\n   apply (simp add: valid_list_post_src_parent)\n  apply (simp add: valid_list_post_parents)\n  done\n\nend\n\nlocale mdb_swap_abs'' = mdb_swap_abs + constrains s::\"det_state\"\n\nlocale mdb_swap_abs' = mdb_swap_abs'' +\n  fixes t t' t''\n  defines \"t' \\<equiv> (case n src of\n      None \\<Rightarrow> (case n dest of\n        None \\<Rightarrow> t'' |\n        Some dest_p \\<Rightarrow> t'' (dest_p := list_replace (t'' dest_p) src dest)) |\n      Some src_p \\<Rightarrow> (case n dest of\n        None \\<Rightarrow> t'' (src_p := list_replace (t'' src_p) dest src) |\n        Some dest_p \\<Rightarrow> if src_p = dest_p\n          then t'' (src_p := list_swap (t'' src_p) src dest)\n          else t'' (src_p := list_replace (t'' src_p) dest src,\n                     dest_p := list_replace (t'' dest_p) src dest)))\"\n  defines \"t'' \\<equiv> t(src := t dest, dest := t src)\"\n  assumes \"t = cdt_list s\"\n  assumes valid_list: \"valid_list_2 t m\"\n\ncontext mdb_swap_abs'\nbegin\n\nlemma findepth:\n  \"finite_depth m\"\n  apply (simp add: m)\n  apply (rule Deterministic_AI.finite_depth)\n  apply (rule valid_mdb)\n  done\n\nlemma finite_depth:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"finite_depth n\"\n  apply (insert findepth)\n  apply(simp add: finite_depth_def descendants split del: if_split)\n  apply(simp add: n_def n'_def split del: if_split)\n  apply(rule allI)\n  apply(case_tac \"slot=src\")\n   apply(erule_tac x=dest in allE)\n   apply(elim exE conjE)\n   apply(case_tac \"p=src\")\n    apply(rule_tac x=dest in exI, simp add: s_d_swap_def)\n   apply(case_tac \"p = dest\")\n    apply(rule_tac x =\"src\" in exI, simp add: s_d_swap_def)\n   apply(rule_tac x=p in exI, simp add: s_d_swap_def)\n  apply (case_tac \"slot=dest\")\n   apply(erule_tac x=src in allE)\n   apply (elim exE conjE)\n   apply (case_tac \"p=src\")\n    apply (rule_tac x =dest in exI, simp add: s_d_swap_def)\n   apply (case_tac \"p=dest\")\n    apply (simp add: descendants_of_def)\n    apply (intro conjI impI)\n     apply (rule_tac x = \"src\" in exI, intro conjI, rule impI, simp+)\n    apply (rule_tac x = \"src\" in exI)\n    apply (intro conjI impI; simp)\n   apply (rule_tac x = \"p\" in exI)\n   apply (simp add: descendants_of_def s_d_swap_def)\n  apply (erule_tac x = slot in allE)\n  apply (elim exE conjE)\n  apply (case_tac \"p = dest\")\n   apply (rule_tac x = \"src\" in exI, simp add: descendants_of_def s_d_swap_def)\n  apply (case_tac \"p = src\")\n   apply (rule_tac x = \"dest\" in exI, simp add: descendants_of_def s_d_swap_def)\n  apply (rule_tac x =\"p\" in exI, simp add: descendants_of_def s_d_swap_def)\n  done\n\nlemma parency_antisym: \"\\<And>x y. m x = Some y \\<Longrightarrow> m y \\<noteq> Some x\"\n  apply (frule parent_not_descendant[OF no_mloop])\n  apply (rule notI)\n  apply (frule_tac src=y and src_p=x in child_descendant,simp)\n  done\n\nlemma parent_not_next_child: \"x \\<notin> set (t x)\"\n  apply (insert no_mloop valid_list)\n  apply (simp add: valid_list_2_def no_mloop_def del: split_paired_All)\n  done\n\nlemma valid_list_post:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  notes parency_antisym[where x=src and y = dest,simp]\n  notes parent_not_next_child[simp]\n  shows \"valid_list_2 t' n\"\n  proof -\n    from valid_list show ?thesis\n    apply (simp add: t'_def t''_def n_def n'_def cong: option.case_cong)\n    by (simp add: replace_distinct[OF parent_not_next_child]\n                     replace_distinct list_replace_set\n                     list_swap_both insert_Collect remove_collect\n                     swap_distinct\n           | intro impI conjI iffI allI\n           | (intro impI conjI iffI notI,simp_all)\n           | rule Collect_cong\n           | simp split: option.splits\n           | (rule ccontr,simp,elim impE,rule notI)\n           | simp only: valid_list_2_def  )+ (*slow*)\nqed\n\nlemma next_child_antisym: \"next_child x t = Some y \\<Longrightarrow> next_child y t \\<noteq> Some x\"\n  apply (rule notI)\n  apply (clarsimp dest!: next_childD[OF _ valid_list])\n  apply (simp add: parency_antisym)\n  done\n\nlemma next_childI'': \"(\\<exists>xs. t''' slot = child # xs) \\<Longrightarrow> next_child slot t''' = Some child\"\n  apply (elim exE)\n  apply (rule next_childI,simp)\n  done\n\nlemma next_childD'':\n notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n\"next_child slot t''' \\<noteq> Some child \\<Longrightarrow> t''' slot = [] \\<or> (\\<exists>xs a. t''' slot = a#xs \\<and> a \\<noteq> child)\"\n  apply (simp add: next_child_def)\n  apply (case_tac \"t''' slot\")\n  apply simp+\n  done\n\nlemma next_child_eq_ignore: \"g p = g' p \\<Longrightarrow> next_child p g = next_child p g'\"\n  by(simp add: next_child_def)\n\nlemma next_child:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  notes parency_antisym[where x=src and y = dest,simp]\n  notes next_child_antisym[where x=src and y = dest,simp]\n  notes next_childD' = next_childD[OF _ valid_list]\n  notes rdefs = t'_def t''_def n_def n'_def\n  shows \n  \"next_child p t'\n    = (if p = src then\n        (if next_child dest t = Some src then Some dest\n         else next_child dest t)\n      else if p = dest then\n        (if next_child src t = Some dest then Some src\n         else next_child src t)\n      else if next_child p t = Some src then Some dest\n      else if next_child p t = Some dest then Some src\n      else next_child p t)\"\n  apply (simp add: rdefs split: option.splits)\n  apply (intro impI conjI,simp_all)\n  by ((intro impI conjI allI | drule next_child_NoneD next_childD'  next_childD'' | \n       rule next_childI'' | simp add: list_replace_def list_swap_def | elim exE conjE disjE |\n       simp add: next_child_def)+) (*slow*)\n\n\nlemma next_sib_antisym:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"next_sib x t m = Some y \\<Longrightarrow> next_sib y t m \\<noteq> Some x\"\n  apply (rule notI)\n  apply (frule next_sib_same_parent[OF valid_list])\n  apply (elim exE conjE)\n  apply (drule next_sibD)+\n  apply (elim exE conjE)\n  apply (simp add: valid_list[simplified valid_list_2_def] distinct_after_in_list_antisym)\n  done\n\n\nlemma after_in_listD': \"after_in_list (t p) x = Some y \\<Longrightarrow> (\\<exists>xs ys. xs @ (x # y # ys) = (t p) \\<and> x \\<notin> set xs) \\<and> (m y = Some p \\<and> m x = Some p) \\<and> x \\<noteq> y\"\n  apply (rule conjI)\n  apply (drule after_in_listD)\n  apply force\n  apply (drule after_in_listD)\n  apply (elim exE conjE)\n  apply (rule conjI)\n  apply (subgoal_tac \"x \\<in> set (t p) \\<and> y \\<in> set (t p)\")\n  apply (thin_tac \"t p = Q\" for Q)\n  apply (simp add: valid_list[simplified valid_list_2_def])+\n  apply (subgoal_tac \"distinct (t p)\")\n  apply simp\n  apply (thin_tac \"t p = Q\" for Q)\n  apply (simp add: valid_list[simplified valid_list_2_def])+\n  done\n\nlemma optionD: \"x \\<noteq> Some y \\<Longrightarrow> x = None \\<or> (\\<exists>z. x = Some z \\<and> z \\<noteq> y)\"\n  by (case_tac \"x\"; simp)\n\nlemma t_distinct: \"distinct (t x)\"\n  by (simp add: valid_list[simplified valid_list_2_def])\n\nlemma t_some[simp]: \"set (t x) = {c. m c = Some x}\"\n  by (simp add: valid_list[simplified valid_list_2_def])\n\ndeclare t_distinct [simp]\n\nlemmas list_swap_preservation_t = \n  list_swap_preserve_after list_swap_preserve_after'\n  list_swap_preserve_after'' list_swap_preserve_None list_swap_preserve_None'\n  list_swap_preserve_Some_other' list_swap_preserve_Some_other_distinct[OF t_distinct]\n  list_swap_preserve_Some_other_distinct[OF t_distinct, simplified list_swap_symmetric]\n  list_swap_does_swap[OF t_distinct]\n  list_swap_does_swap[OF t_distinct,simplified list_swap_symmetric] \n  list_swap_preserve_after_None list_swap_preserve_separate list_swap_does_swap'\n\nlemma next_sibD':\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"next_sib slot t m = Some child \\<Longrightarrow>\n         \\<exists>p. m slot = Some p \\<and> m child = Some p \\<and> after_in_list (t p) slot = Some child\"\n  apply (frule next_sib_same_parent[OF valid_list])\n  apply (drule next_sibD)\n  apply clarsimp\n  done\n\nlemma next_sib:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  notes parency_antisym[where x=src and y = dest,simp]\n  notes next_sib_antisym[where x=src and y = dest,simp]\n  notes distinct_after_in_list_not_self[OF t_distinct,simp]\n  notes rdefs = t'_def t''_def n_def n'_def\n  notes parent_not_next_child[simp]\n  shows\n  \"next_sib p t' n\n    = (if p = src then\n        (if next_sib dest t m = Some src then Some dest\n         else next_sib dest t m)\n      else if p = dest then\n        (if next_sib src t m = Some dest then Some src\n         else next_sib src t m)\n      else if next_sib p t m = Some src then Some dest\n      else if next_sib p t m = Some dest then Some src\n      else next_sib p t m)\"\n  apply simp\n  apply (intro impI conjI allI,simp_all)\n  by ((intro impI conjI allI\n   | drule next_sib_NoneD next_sibD'\n   | simp add: next_sib_def rdefs split: option.splits\n   | simp add: after_in_list_append_notin_hd replace_list_preserve_after replace_list_preserve_after'\n               list_swap_preservation_t replace_distinct swap_distinct\n   | rule after_in_list_list_replace\n   | drule optionD after_in_listD'\n   | elim exE conjE disjE | force )+) (*slow*)\n\nlemma next_not_child:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"next_not_child p t' n\n    = (if p = src then\n        (if next_not_child dest t m = Some src then Some dest\n         else next_not_child dest t m)\n      else if p = dest then\n        (if next_not_child src t m = Some dest then Some src\n         else next_not_child src t m)\n      else if next_not_child p t m = Some src then Some dest\n      else if next_not_child p t m = Some dest then Some src\n      else next_not_child p t m)\"\n  apply(case_tac \"p=src\")\n   apply(case_tac \"next_not_child dest t m = Some src\")\n    apply(simp)\n    apply(drule next_not_childD, simp add: findepth, simp add: no_mloop)\n    apply(rule next_not_childI)\n     apply(erule disjE)\n      apply(simp add: next_sib)\n     apply(elim conjE exE)\n     apply(rule disjI2)\n     apply(simp add: next_sib)\n     apply(intro impI conjI)\n      apply(drule next_sibD')+\n      apply(simp add: descendants_of_def cdt_parent_defs)\n      apply(case_tac \"m q\", simp)\n      apply(case_tac \"m src\", simp)\n      apply(simp)\n      apply(drule tranclD2)\n      apply(simp)\n      apply(drule_tac a=q and b=a and c=q in rtrancl_into_trancl1)\n       apply(simp)\n      apply(insert no_mloop)[1]\n      apply(simp add: no_mloop_def cdt_parent_defs)\n     apply(case_tac \"q=src\")\n      apply(rule_tac x=dest in exI)\n      apply(simp)\n      apply(simp add: not_sib_self valid_list)\n     apply(rule_tac x=q in exI)\n     apply(simp)\n     apply(intro conjI impI notI allI)\n            apply(simp add: descendants s_d_swap_def split: if_split_asm)+\n    apply(simp add: finite_depth)\n   apply(simp)\n   apply(case_tac \"next_not_child dest t m\")\n    apply(simp)\n    apply(drule next_not_child_NoneD, simp add: findepth)\n    apply(rule next_not_child_NoneI)\n      apply(simp add: next_sib descendants s_d_swap_def)\n     apply(simp add: next_sib)\n    apply(simp add: finite_depth)\n   apply(simp)\n   apply(drule next_not_childD, simp add: findepth, simp add: no_mloop)\n   apply(rule next_not_childI)\n    apply(erule disjE)\n     apply(simp add: next_sib)\n    apply(elim conjE exE)\n    apply(rule disjI2)\n    apply(simp add: next_sib split del: if_split)\n    apply(case_tac \"q=src\")\n     apply(rule_tac x=dest in exI)\n     apply(simp add: descendants s_d_swap_def)\n     apply(insert no_mloop)[1]\n     apply(intro conjI impI notI allI)\n              apply((simp add: no_mloop_def descendants_of_def)+)[7]\n       apply(drule(1) desc_sib_ne, simp add: valid_list, simp, simp)\n      apply(simp)\n     apply(simp)\n    apply(rule_tac x=q in exI)\n    apply(subgoal_tac \"q\\<noteq>dest\")\n     prefer 2\n     apply(rule notI)\n     apply(insert valid_mdb)[1]\n     apply(drule_tac slot=dest in desc_not_parent, simp)\n    apply(subgoal_tac \"a\\<noteq>dest\")\n     prefer 2\n     apply(rule notI, simp)\n     apply(drule(1) desc_sib_ne, simp add: valid_list, simp add: no_mloop, simp)\n    apply(simp add: descendants s_d_swap_def split del: if_split)\n    apply(simp)\n    apply(intro conjI impI allI notI, simp+)\n   apply(simp add: finite_depth)\n  apply(case_tac \"p=dest\")\n   apply(case_tac \"next_not_child src t m = Some dest\")\n    apply(simp)\n    apply(drule next_not_childD, simp add: findepth, simp add: no_mloop)\n    apply(rule next_not_childI)\n     apply(erule disjE)\n      apply(simp add: next_sib)\n     apply(elim conjE exE)\n     apply(rule disjI2)\n     apply(simp add: next_sib)\n     apply(intro impI conjI)\n      apply(drule next_sibD')+\n      apply(simp add: descendants_of_def cdt_parent_defs)\n      apply(case_tac \"m q\", simp)\n      apply(case_tac \"m dest\", simp)\n      apply(simp)\n      apply(drule tranclD2)\n      apply(simp)\n      apply(drule_tac a=q and b=a and c=q in rtrancl_into_trancl1)\n       apply(simp)\n      apply(insert no_mloop)[1]\n      apply(simp add: no_mloop_def cdt_parent_defs)\n     apply(case_tac \"q=dest\")\n      apply(rule_tac x=src in exI)\n      apply(simp add: not_sib_self valid_list)\n     apply(rule_tac x=q in exI)\n     apply(simp)\n     apply(intro conjI impI notI allI)\n            apply(simp add: descendants s_d_swap_def split: if_split_asm)+\n    apply(simp add: finite_depth)\n   apply(simp)\n   apply(case_tac \"next_not_child src t m\")\n    apply(simp)\n    apply(drule next_not_child_NoneD, simp add: findepth)\n    apply(rule next_not_child_NoneI)\n      apply(simp add: next_sib descendants s_d_swap_def)\n     apply(simp add: next_sib)\n    apply(simp add: finite_depth)\n   apply(simp)\n   apply(drule next_not_childD, simp add: findepth, simp add: no_mloop)\n   apply(rule next_not_childI)\n    apply(erule disjE)\n     apply(simp add: next_sib)\n    apply(elim conjE exE)\n    apply(rule disjI2)\n    apply(simp add: next_sib split del: if_split)\n    apply(case_tac \"q=dest\")\n     apply(rule_tac x=src in exI)\n     apply(simp add: descendants s_d_swap_def)\n     apply(insert no_mloop)[1]\n     apply(intro conjI impI notI allI)\n              apply((simp add: no_mloop_def descendants_of_def)+)[7]\n       apply(drule(1) desc_sib_ne, simp add: valid_list, simp, simp)\n      apply(simp)\n     apply(simp)\n    apply(rule_tac x=q in exI)\n    apply(subgoal_tac \"q\\<noteq>src\")\n     prefer 2\n     apply(rule notI)\n     apply(insert valid_mdb)[1]\n     apply(drule_tac slot=src in desc_not_parent, simp)\n    apply(subgoal_tac \"a\\<noteq>src\")\n     prefer 2\n     apply(rule notI, simp)\n     apply(drule(1) desc_sib_ne, simp add: valid_list, simp add: no_mloop, simp)\n    apply(simp add: descendants s_d_swap_def split del: if_split)\n    apply(simp)\n    apply(intro conjI impI allI notI, simp+)\n   apply(simp add: finite_depth)\n  apply(case_tac \"next_not_child p t m = Some src\")\n   apply(simp)\n   apply(drule next_not_childD, simp add: findepth, simp add: no_mloop)\n   apply(rule next_not_childI)\n    apply(erule disjE)\n     apply(simp add: next_sib)\n    apply(rule disjI2)\n    apply(elim conjE exE)\n    apply(subst next_sib, simp)\n    apply(case_tac \"q=dest\")\n     apply(rule_tac x=src in exI)\n     apply(simp add: next_sib descendants s_d_swap_def split del: if_split)\n     apply(intro allI impI)\n     apply(simp)\n     apply(simp split: if_split_asm)\n    apply(rule_tac x=q in exI)\n    apply(subgoal_tac \"q\\<noteq>src\")\n     prefer 2\n     apply(rule notI)\n     apply(simp add: not_sib_self valid_list)\n    apply(intro conjI allI impI)\n      apply(simp add: next_sib)\n     apply(simp add: descendants s_d_swap_def)\n    apply(simp add: next_sib)\n    apply(subgoal_tac \"next_sib dest t m \\<noteq> Some src\")\n     prefer 2\n     apply(rule notI)\n     apply(drule_tac a=q and b=dest in next_sib_inj, simp, simp add: valid_list, simp)\n    apply(case_tac \"q'=dest\")\n     apply(simp add: descendants s_d_swap_def split: if_split_asm)\n    apply(simp add: descendants s_d_swap_def split: if_split_asm)\n   apply(simp add: finite_depth)\n  apply(case_tac \"next_not_child p t m = Some dest\")\n   apply(simp)\n   apply(drule next_not_childD, simp add: findepth, simp add: no_mloop)\n   apply(rule next_not_childI)\n    apply(erule disjE)\n     apply(simp add: next_sib)\n    apply(rule disjI2)\n    apply(elim conjE exE)\n    apply(subst next_sib, simp)\n    apply(case_tac \"q=src\")\n     apply(rule_tac x=dest in exI)\n     apply(simp add: next_sib descendants s_d_swap_def split del: if_split)\n     apply(intro allI impI)\n     apply(simp)\n     apply(simp split: if_split_asm)\n    apply(rule_tac x=q in exI)\n    apply(subgoal_tac \"q\\<noteq>dest\")\n     prefer 2\n     apply(rule notI)\n     apply(simp add: not_sib_self valid_list)\n    apply(intro conjI allI impI)\n      apply(simp add: next_sib)\n     apply(simp add: descendants s_d_swap_def)\n    apply(simp add: next_sib)\n    apply(subgoal_tac \"next_sib src t m \\<noteq> Some dest\")\n     prefer 2\n     apply(rule notI)\n     apply(drule_tac a=q and b=src in next_sib_inj, simp, simp add: valid_list, simp)\n    apply(case_tac \"q'=src\")\n     apply(simp add: descendants s_d_swap_def split: if_split_asm)\n    apply(simp add: descendants s_d_swap_def split: if_split_asm)\n   apply(simp add: finite_depth)\n  apply(simp)\n  apply(case_tac \"next_not_child p t m\")\n   apply(simp)\n   apply(drule next_not_child_NoneD, simp add: findepth)\n   apply(rule next_not_child_NoneI)\n     apply(simp add: descendants s_d_swap_def next_sib split del: if_split)\n     apply(intro allI conjI)\n       apply(simp_all)[3]\n    apply(simp add: next_sib)\n   apply(simp add: finite_depth)\n  apply(simp)\n  apply(drule next_not_childD, simp add: findepth, simp add: no_mloop)\n  apply(rule next_not_childI)\n   apply(erule disjE)\n    apply(simp add: next_sib)\n   apply(rule disjI2)\n   apply(rule conjI)\n    apply(simp add: next_sib)\n   apply(elim conjE exE)\n   apply(case_tac \"q=dest\")\n    apply(rule_tac x=src in exI)\n    apply(intro conjI impI allI)\n      apply(simp add: next_sib)\n     apply(simp add: descendants s_d_swap_def)\n    apply(simp add: next_sib descendants s_d_swap_def split: if_split_asm)\n   apply(case_tac \"q=src\")\n    apply(rule_tac x=dest in exI)\n    apply(intro conjI impI allI)\n      apply(simp add: next_sib)\n     apply(simp add: descendants s_d_swap_def)\n    apply(simp add: next_sib descendants s_d_swap_def split: if_split_asm)\n   apply(rule_tac x=q in exI)\n   apply(intro conjI impI allI)\n     apply(simp add: next_sib)\n    apply(simp add: descendants s_d_swap_def)\n   apply(simp add: next_sib descendants s_d_swap_def split: if_split_asm)\n  apply(simp add: finite_depth)\n  done\n\nlemma t'_empty:\n  \"(t' src = []) = (t dest = [])\"\n  \"(t' dest = []) = (t src = [])\"\n  \"p\\<noteq>src \\<and> p\\<noteq>dest \\<Longrightarrow> (t' p = []) = (t p = [])\"\n  by(fastforce simp: n_def n'_def t''_def t'_def list_swap_def\n              split: option.splits split: if_split_asm)+\n\nlemma next_slot:\n  \"next_slot p t' n\n    = (if p = src then\n        (if next_slot dest t m = Some src then Some dest\n         else next_slot dest t m)\n      else if p = dest then\n        (if next_slot src t m = Some dest then Some src\n         else next_slot src t m)\n      else if next_slot p t m = Some src then Some dest\n      else if next_slot p t m = Some dest then Some src\n      else next_slot p t m)\"\n  apply(case_tac \"p=src\")\n   apply(simp add: next_slot_def next_child next_not_child valid_list t'_empty)\n  apply(case_tac \"p=dest\")\n   apply(simp add: next_slot_def next_child next_not_child valid_list t'_empty\n         split: if_split_asm)\n  apply(case_tac \"next_slot p t m = Some src\")\n   apply(simp add: next_slot_def next_child next_not_child s_d_swap_def t'_empty\n         split: if_split_asm)\n  apply(case_tac \"next_slot p t m = Some dest\")\n   apply(simp add: next_slot_def next_child next_not_child s_d_swap_def  t'_empty\n         split: if_split_asm)\n  apply(simp add: next_slot_def next_child next_not_child s_d_swap_def t'_empty\n        split: if_split_asm)\n  done\n\nend\n\n\ncrunch all_but_exst[wp]: cap_swap_ext \"all_but_exst P\"\n\ncrunch (empty_fail) empty_fail[wp]: cap_swap_ext\n\ninterpretation cap_swap_ext_extended: is_extended \"cap_swap_ext a b c d\"\n  by (unfold_locales; wp cap_swap_ext_all_but_exst)\n\n\nlemma cap_swap_valid_list [wp]:\n  \"\\<lbrace>valid_list\\<rbrace>\n  cap_swap c a c' b\n  \\<lbrace>\\<lambda>_. valid_list\\<rbrace>\"\n  apply (simp only: cap_swap_def cap_swap_ext_extended.dxo_eq)\n  apply (simp only: cap_swap_ext_def update_cdt_list_def set_cdt_list_def set_cdt_def bind_assoc)\n  apply wp\n  apply (simp del: fun_upd_apply split del: if_split cong: option.case_cong)\n        apply (wp set_cap_caps_of_state3)+\n  apply (case_tac \"a = b\")\n   apply (simp split: option.splits)\n  apply(subgoal_tac \"mdb_swap_abs_simple (cdt s) (cdt_list s)\")\n   prefer 2\n   apply(rule mdb_swap_abs_simple.intro)\n   apply simp\n  apply(frule mdb_swap_abs_simple.valid_list_post[where src=a and dest=b])\n  apply(simp add: fun_upd_def split del: if_split cong: option.case_cong)\n  done\n\n\nlemma exst_set_cap:\n  \"(x,s') \\<in> fst (set_cap p c s) \\<Longrightarrow> exst s' = exst s\"\n  by (erule use_valid[OF _ set_cap_exst],simp)\n\ncrunch all_but_exst[wp]: create_cap_ext \"all_but_exst P\"\n\ncrunch (empty_fail) empty_fail[wp]: create_cap_ext\n\ninterpretation create_cap_extended: is_extended \"create_cap_ext a b c\"\n  by (unfold_locales; wp)\n\nlemma create_cap_valid_list[wp]:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrace>valid_list \\<rbrace>\n      create_cap tp sz p dev x \\<lbrace>\\<lambda>rv. valid_list\\<rbrace>\"\n  apply (case_tac x)\n  apply (simp add: create_cap_def)\n  apply(simp add: set_cdt_def update_cdt_list_def set_cdt_list_def create_cap_ext_def bind_assoc)\n  apply (rule hoare_pre)\n   apply (simp add: valid_list_2_def)\n   apply (wp | simp cong: option.case_cong if_cong del: fun_upd_apply split del: if_split)+\n         apply(wp set_cap_caps_of_state3 get_cap_wp)+\n  apply(simp del: fun_upd_apply split: option.splits split del: if_split cong:if_weak_cong)\n  apply (intro impI conjI allI)\n     apply (simp add: valid_list_2_def | intro impI conjI allI | fastforce simp: list_remove_removed list_remove_distinct)+\n  done\n\n\ncrunch valid_list[wp]: set_extra_badge valid_list\n\nlemmas transfer_caps_loop_ext_valid[wp] =\n  transfer_caps_loop_pres[OF cap_insert_valid_list set_extra_badge_valid_list]\n\ncrunch valid_list[wp]: tcb_sched_action,reschedule_required,set_thread_state_ext \"valid_list\"\n  (simp: unless_def)\n\ncrunch all_but_exst[wp]: set_thread_state_ext \"all_but_exst P\"\n\ncrunch (empty_fail) empty_fail[wp]: set_thread_state_ext\n\ninterpretation set_thread_state_ext_extended: is_extended \"set_thread_state_ext a\"\n  by (unfold_locales; wp)\n\ncrunch all_but_exst[wp]: reschedule_required \"all_but_exst P\"\n\ninterpretation reschedule_required_ext_extended: is_extended \"reschedule_required\"\n  by (unfold_locales; wp)\n\ncrunch valid_list[wp]: fast_finalise valid_list (wp: crunch_wps)\n\nlemma cap_delete_one_valid_list[wp]: \"\\<lbrace>valid_list\\<rbrace> cap_delete_one a \\<lbrace>\\<lambda>_.valid_list\\<rbrace>\"\n  unfolding cap_delete_one_def by (wpsimp simp: unless_def)\n\ncrunch valid_list[wp]: thread_set valid_list\n\nlemma reply_cancel_ipc_valid_list[wp]: \"\\<lbrace>valid_list\\<rbrace> reply_cancel_ipc a \\<lbrace>\\<lambda>_. valid_list\\<rbrace>\"\n  unfolding reply_cancel_ipc_def\n  by (wp select_wp hoare_drop_imps thread_set_mdb | simp)+\n\ncrunch all_but_exst[wp]: update_work_units \"all_but_exst P\"\n\ncrunch all_but_exst[wp]: reset_work_units \"all_but_exst P\"\n\nglobal_interpretation update_work_units_ext_extended: is_extended \"update_work_units\"\n  by (unfold_locales; wp)\n \nglobal_interpretation reset_work_units_ext_extended: is_extended \"reset_work_units\"\n  by (unfold_locales; wp)\n\nlemma preemption_point_inv':\n  \"\\<lbrakk>irq_state_independent_A P; \\<And>f s. P (work_units_completed_update f s) = P s\\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> preemption_point \\<lbrace>\\<lambda>_. P\\<rbrace>\"\n  apply (intro impI conjI | simp add: preemption_point_def o_def\n       | wp hoare_post_imp[OF _ getActiveIRQ_wp] OR_choiceE_weak_wp alternative_wp[where P=P]\n       | wpc | simp add: update_work_units_def reset_work_units_def)+\n  done\n\n\nlocale Deterministic_AI_1 =\n  assumes cap_swap_for_delete_valid_list[wp]:\n    \"\\<And>param_a param_b. \\<lbrace>valid_list\\<rbrace> cap_swap_for_delete param_a param_b \\<lbrace>\\<lambda>_. valid_list\\<rbrace>\"\n  assumes finalise_cap_valid_list:\n    \"\\<And>param_a param_b. \\<lbrace>valid_list\\<rbrace> finalise_cap param_a param_b \\<lbrace>\\<lambda>_. valid_list\\<rbrace>\"\n  assumes get_cap_valid_list[wp]:\n    \"\\<And>param_a. \\<lbrace>valid_list\\<rbrace> get_cap param_a \\<lbrace>\\<lambda>_. valid_list\\<rbrace>\"\n  assumes arch_tcb_set_ipc_buffer_valid_list[wp]:\n    \"\\<And>t ptr. \\<lbrace>valid_list\\<rbrace> arch_tcb_set_ipc_buffer t ptr \\<lbrace>\\<lambda>_. valid_list\\<rbrace>\"\n\n\ncontext Deterministic_AI_1 begin\n\nlemmas rec_del_valid_list[wp] = rec_del_preservation\n  [OF cap_swap_for_delete_valid_list\n      set_cap_valid_list\n      empty_slot_valid_list\n      finalise_cap_valid_list]\n\ncrunch valid_list[wp]: cap_delete valid_list\n  (wp: preemption_point_inv')\n\nend\n\nlemma irq_state_independent_A_valid_list[simp]: \"irq_state_independent_A valid_list\"\n  by (simp add: irq_state_independent_A_def)\n\ncontext Deterministic_AI_1 begin\n\nlemma cap_revoke_valid_list[wp]:\"\\<lbrace>valid_list\\<rbrace> cap_revoke a \\<lbrace>\\<lambda>_. valid_list\\<rbrace>\"\n  apply (rule cap_revoke_preservation2)\n  apply (wp preemption_point_inv'|simp)+\n  done\n\ncrunch valid_list[wp]: ethread_set \"valid_list\"\n\nend\n\ncrunch all_but_exst[wp]: ethread_set \"all_but_exst P\"\n\ncrunch (empty_fail) empty_fail[wp]: ethread_set\n\nglobal_interpretation ethread_set_extended: is_extended \"ethread_set a b\"\n  by (unfold_locales; wp)\n\ncrunch valid_list[wp]: cancel_badged_sends valid_list\n  (wp: crunch_wps preemption_point_inv' simp: crunch_simps filterM_mapM unless_def\n   ignore: without_preemption filterM )\n\ncontext Deterministic_AI_1 begin\n\nlemma invoke_cnode_valid_list[wp]: \n  \"\\<lbrace>valid_list\\<rbrace> invoke_cnode ci \\<lbrace>\\<lambda>_.valid_list\\<rbrace>\"\n  apply (rule hoare_pre)\n   apply (wp crunch_wps cap_move_src_slot_Null hoare_drop_imps hoare_vcg_all_lift | wpc | simp add: invoke_cnode_def crunch_simps split del: if_split)+\n  done\n\nend\n\ncrunch valid_list[wp]: switch_if_required_to,set_priority,set_mcpriority \"valid_list\"\n  (wp: crunch_wps)\n\ncrunch all_but_exst[wp]: switch_if_required_to \"all_but_exst P\" (simp: ethread_get_def)\n\nlemma empty_fail_possible_switch_to[wp]: \"empty_fail (possible_switch_to a b)\"\n  apply (simp add: possible_switch_to_def)\n  apply (wp | clarsimp split: scheduler_action.splits)+\n  done\n\ncrunch (empty_fail)empty_fail[wp]: switch_if_required_to\n\nglobal_interpretation possible_switch_to_extended: is_extended \"possible_switch_to a b\"\n  by (unfold_locales; wp)\n\nglobal_interpretation switch_if_required_to_extended: is_extended \"switch_if_required_to a\"\n  by (unfold_locales; wp)\n\ncrunch all_but_exst[wp]: set_priority \"all_but_exst P\" (simp: ethread_get_def)\n\ncrunch (empty_fail)empty_fail[wp]: set_priority,set_mcpriority\n\nglobal_interpretation set_priority_extended: is_extended \"set_priority a b\"\n  by (unfold_locales; wp)\n\ncrunch all_but_exst[wp]: set_domain \"all_but_exst P\" (simp: ethread_get_def)\n\nglobal_interpretation set_domain_extended: is_extended \"set_domain a b\"\n  by (unfold_locales; wp)\n\nglobal_interpretation thread_set_domain_extended: is_extended \"thread_set_domain a b\"\n  by (unfold_locales; wp)\n\ncrunch all_but_exst[wp]: dec_domain_time \"all_but_exst P\" (simp: ethread_get_def)\n\ncrunch (empty_fail) empty_fail[wp]: dec_domain_time\n\nglobal_interpretation dec_domain_time_extended: is_extended \"dec_domain_time\"\n  by (unfold_locales; wp)\n\ncontext Deterministic_AI_1 begin\ncrunch valid_list[wp]: invoke_tcb valid_list\n  (wp: mapM_x_wp' ignore: check_cap_at simp: check_cap_at_def)\nend\n\nlemma delete_objects_valid_list[wp]: \"\\<lbrace>valid_list\\<rbrace> delete_objects ptr bits \\<lbrace>\\<lambda>_.valid_list\\<rbrace>\"\n  unfolding delete_objects_def\n  apply (wp | simp add: detype_def detype_ext_def wrap_ext_det_ext_ext_def)+\n  done\n\nlemmas mapM_x_def_bak = mapM_x_def[symmetric]\n\nlemma retype_region_ext_valid_list_ext[wp]: \"\\<lbrace>valid_list\\<rbrace> retype_region_ext a b \\<lbrace>\\<lambda>_.valid_list\\<rbrace>\"\n  by (wpsimp simp: retype_region_ext_def)\n\ncrunch all_but_exst[wp]: retype_region_ext \"all_but_exst P\" (simp: ethread_get_def)\n\ncrunch (empty_fail)empty_fail[wp]: retype_region_ext\n\nglobal_interpretation retype_region_ext_extended: is_extended \"retype_region_ext a b\"\n  by (unfold_locales; wp)\n\ncrunch valid_list[wp]: invoke_irq_handler valid_list\n\ncrunch valid_list[wp]: attempt_switch_to \"valid_list\"\n\nglobal_interpretation attempt_switch_to_extended: is_extended \"attempt_switch_to a\"\n  apply (simp add: attempt_switch_to_def)\n  apply (unfold_locales)\n  done\n\ncrunch valid_list[wp]: thread_set_time_slice,timer_tick \"valid_list\" (simp: Let_def)\n\ncrunch all_but_exst[wp]: timer_tick \"all_but_exst P\" (simp: ethread_get_def crunch_simps)\n\ncrunch (empty_fail)empty_fail[wp]: timer_tick\n  (simp: thread_state.splits)\n\nglobal_interpretation timer_tick_extended: is_extended \"timer_tick\"\n  by (unfold_locales; wp)\n\nlocale Deterministic_AI_2 = Deterministic_AI_1 +\n  assumes handle_interrupt_valid_list[wp]:\n    \"\\<And>irq. \\<lbrace>valid_list\\<rbrace> handle_interrupt irq \\<lbrace>\\<lambda>_.valid_list\\<rbrace>\"\n  assumes handle_call_valid_list[wp]:\n    \"\\<lbrace>valid_list\\<rbrace> handle_call \\<lbrace>\\<lambda>_. valid_list\\<rbrace>\"\n  assumes handle_fault_valid_list[wp]:\n    \"\\<And>param_a param_b. \\<lbrace>valid_list\\<rbrace> handle_fault param_a param_b \\<lbrace>\\<lambda>_. valid_list\\<rbrace>\"\n  assumes handle_recv_valid_list[wp]:\n    \"\\<And>param_a. \\<lbrace>valid_list\\<rbrace> handle_recv param_a \\<lbrace>\\<lambda>_. valid_list\\<rbrace>\"\n  assumes handle_reply_valid_list[wp]:\n    \"\\<lbrace>valid_list\\<rbrace> handle_reply \\<lbrace>\\<lambda>_. valid_list\\<rbrace>\"\n  assumes handle_send_valid_list[wp]:\n    \"\\<And>param_a. \\<lbrace>valid_list\\<rbrace> handle_send param_a \\<lbrace>\\<lambda>_. valid_list\\<rbrace>\"\n  assumes handle_vm_fault_valid_list[wp]:\n    \"\\<And>thread fault. \\<lbrace>valid_list\\<rbrace> handle_vm_fault thread fault \\<lbrace>\\<lambda>_. valid_list\\<rbrace>\"\n  assumes handle_yield_valid_list[wp]:\n    \"\\<lbrace>valid_list\\<rbrace> handle_yield \\<lbrace>\\<lambda>_. valid_list\\<rbrace>\"\n  assumes handle_hypervisor_fault_valid_list[wp]:\n    \"\\<lbrace>valid_list\\<rbrace> handle_hypervisor_fault thread fault \\<lbrace>\\<lambda>_. valid_list\\<rbrace>\"\n\n\ncontext Deterministic_AI_2 begin\n\nlemma handle_event_valid_list[wp]:\n  \"\\<lbrace>valid_list\\<rbrace> handle_event e \\<lbrace>\\<lambda>_.valid_list\\<rbrace>\"\n  by (case_tac e; wpsimp wp: hoare_drop_imps)\n\nend\n\n\n(* Recovering cdt_list operations that only consider sane cases.\n   This is to recover the current refinement proofs.*)\n\nlemma (in mdb_move_abs') dest_empty_list:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"valid_list_2 t m \\<Longrightarrow> t dest = []\"\n  apply (insert dest_desc)\n  apply (subgoal_tac \"set (t dest) = {}\")\n   apply simp\n  apply (simp add: valid_list_2_def)\n  done\n\nlemma update_cdt_list_bind: \"do y \\<leftarrow> (update_cdt_list f); update_cdt_list f' od =\n       update_cdt_list (\\<lambda>s. f' (f s))\"\n  apply (simp add: bind_def update_cdt_list_def gets_def\n                   return_def get_def set_cdt_list_def\n                   put_def)\n  done\n\nlemma update_list_eq: \"(f (cdt_list e)) = (f' (cdt_list e)) \\<Longrightarrow>\n        update_cdt_list f e = update_cdt_list f' e\"\n  apply (simp add: update_cdt_list_def gets_def\n                   get_def set_cdt_list_def put_def\n                   bind_def return_def)\n  done\n\nlemma (in mdb_move_abs') cap_move_ext_det_def2:\n notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n \"valid_list_2 (cdt_list e) m \\<Longrightarrow> src_p = (m src) \\<Longrightarrow> dest_p = (m dest) \\<Longrightarrow>\n       cap_move_ext src dest src_p dest_p e =\n    (update_cdt_list (\\<lambda>list. case (m src) of\n      None \\<Rightarrow> list (src := [], dest := list src) |\n      Some p \\<Rightarrow> list (p := list_replace (list p) src dest,\n                      src := [], dest := list src))) e\"\n  apply (simp add: cap_move_ext_def update_cdt_list_bind)\n  apply (rule update_list_eq)\n  apply (insert dest_None neq)\n  apply (case_tac \"m src\")\n    apply (simp add: dest_empty_list)\n   apply simp\n  apply (insert no_mloop)\n  apply (frule no_mloop_weaken[where a=src])\n  apply simp\n  apply (insert dest_desc)\n  apply (intro impI conjI)\n   apply (simp add: no_children_empty_desc[symmetric])\n  apply (simp add: dest_empty_list)\n  done\n\nlemma (in mdb_insert_abs) cap_insert_ext_det_def2:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n \"valid_list_2 (cdt_list e) m \\<Longrightarrow> no_mloop m \\<Longrightarrow> src_p = (m src) \\<Longrightarrow> dest_p = (m dest) \\<Longrightarrow>\n       cap_insert_ext src_parent src dest src_p dest_p e = (\\<lambda> src_parent src_slot dest_slot src_p dest_p.\n    update_cdt_list (\\<lambda>list. case (m src_slot) of\n      None \\<Rightarrow> list (\n        src_slot := if src_parent then [dest_slot] @ (list src_slot) else list src_slot) |\n      Some p \\<Rightarrow> list (\n        src_slot := if src_parent then [dest_slot] @ (list src_slot) else list src_slot,\n        p := if src_parent then list p else list_insert_after (list p) src_slot dest_slot))) src_parent src dest src_p dest_p e\"\n  apply (simp add: cap_insert_ext_def update_cdt_list_bind)\n  apply (rule update_list_eq)\n  apply (simp split del: if_split cong: option.case_cong)\n  apply (insert dest neq)\n  apply (case_tac \"m src\")\n   apply simp+\n  apply (frule no_mloop_weaken[where a=src])\n  apply simp\n  done\n\n\nlemma (in mdb_empty_abs') empty_slot_ext_det_def2:\n notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n \"valid_list_2 (cdt_list e) m \\<Longrightarrow> slot_p = (m slot) \\<Longrightarrow>\n       empty_slot_ext slot slot_p e = (\n    update_cdt_list (\\<lambda>list. case (m slot) of None \\<Rightarrow> list (slot := []) |\n      Some p \\<Rightarrow> list (p := list_replace_list (list p) slot (list slot), slot := []))) e\"\n  apply (simp add: empty_slot_ext_def update_cdt_list_bind)\n  apply (rule update_list_eq)\n  apply (simp cong: option.case_cong)\n  apply (case_tac \"m slot\")\n   apply simp\n  apply (cut_tac no_mloop_weaken[OF no_mloop, where a=slot])\n  apply simp\n  done\n\n\nlemma (in mdb_insert_abs) create_cap_ext_det_def2:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n \"valid_list_2 (cdt_list e) m \\<Longrightarrow> dest_p = (m dest) \\<Longrightarrow>\n       create_cap_ext untyped dest dest_p e = (\n    update_cdt_list (\\<lambda>list. list (untyped := [dest] @ list untyped))) e\"\n  apply (simp add: create_cap_ext_def update_cdt_list_bind)\n  apply (rule update_list_eq)\n  apply (insert dest neq)\n  apply (case_tac \"m src\")\n   apply simp+\n  done\n\n(* next_sib_2 will give the same result as next_sib, which can\n   be used to define the cdt_list of a node. next_sib_2 is introduced\n   as it is comparable to functions (mdb_next) in the Haskell spec\n   for use in the projection. next_sib_2 traverses the tree until\n   it finds a sibling, rather than directly using the cdt_list. *)\n\nfunction (domintros) next_sib_2 where\n  \"next_sib_2 slot p s =\n  (if slot \\<in> descendants_of p (cdt s) then\n    case next_slot slot (cdt_list s) (cdt s) of Some next \\<Rightarrow>\n      if cdt s next = Some p then\n        Some next\n      else next_sib_2 next p s\n    | None \\<Rightarrow> None\n  else None)\"\n  by (auto | atomize)+\n\nlemma next_sib_2_domintros:\n  \"(\\<And>x. \\<lbrakk>slot \\<in> descendants_of p (cdt s);\n      next_slot slot (cdt_list s) (cdt s) = Some x;  cdt s x \\<noteq> Some p\\<rbrakk>\n    \\<Longrightarrow> next_sib_2_dom (x, p, s))\n      \\<Longrightarrow> next_sib_2_dom (slot, p, s)\"\n  apply(rule accpI)\n  apply(erule next_sib_2_rel.cases)\n  apply(simp)\n  done\n\ndefinition next_slot_set :: \"cslot_ptr \\<Rightarrow> cdt_list \\<Rightarrow> cdt \\<Rightarrow> cslot_ptr set\" where\n  \"next_slot_set slot t m \\<equiv> {next. (next, slot) \\<in> {(next, p). next_slot p t m = Some next}\\<^sup>+}\"\n\ndefinition next_sib_set :: \"cslot_ptr \\<Rightarrow> cdt_list \\<Rightarrow> cdt \\<Rightarrow> cslot_ptr set\" where\n  \"next_sib_set slot t m \\<equiv> {next. (next, slot) \\<in> {(next, p). next_sib p t m = Some next}\\<^sup>+}\"\n\nlemma next_sib_set_same_parent:\n  \"\\<lbrakk>next \\<in> next_sib_set slot t m; valid_list_2 t m\\<rbrakk>\n    \\<Longrightarrow> \\<exists>p. m slot = Some p \\<and> m next = Some p\"\n  apply (simp add: next_sib_set_def)\n  by (induct \"next\" slot rule: trancl.induct; fastforce dest: next_sib_same_parent)\n\nlemma next_slot_setD:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"\\<lbrakk>next \\<in> next_slot_set slot t m; valid_list_2 t m; no_mloop m; finite_depth m\\<rbrakk>\n    \\<Longrightarrow> next \\<in> descendants_of slot m \\<or> next \\<in> next_sib_set slot t m \\<or>\n  (\\<exists>p q. (slot \\<in> descendants_of p m \\<or> p = slot) \\<and> q \\<in> next_sib_set p t m \\<and> next \\<in> descendants_of q m \\<union> {q})\"\n  apply(subst(asm) next_slot_set_def)\n  apply(simp)\n  apply(induct_tac \"next\" slot rule: trancl.induct)\n    apply(assumption)\n   apply(simp add: next_slot_def split: if_split_asm)\n    apply(simp add: next_child_def valid_list_2_def descendants_of_def cdt_parent_defs)\n    apply(case_tac \"t b\", simp, fastforce)\n   apply(drule(2) next_not_childD)\n   apply(erule disjE)\n    apply(fastforce simp: next_sib_set_def)\n   apply(fastforce simp: next_sib_set_def)\n  apply(simp)\n  apply(erule disjE)\n   apply(simp add: next_slot_def split: if_split_asm)\n    apply(rule disjI1)\n    apply(rule_tac b=b in descendants_trans)\n     apply(simp)\n    apply(fastforce dest: next_childD simp: descendants_of_def cdt_parent_defs)\n   apply(drule(2) next_not_childD)\n   apply(fastforce simp: next_sib_set_def)\n  apply(erule disjE)\n   apply(simp add: next_slot_def split: if_split_asm)\n    apply(rule disjI1)\n    apply(fastforce intro: child_descendant dest: next_childD next_sib_set_same_parent)\n   apply(drule(2) next_not_childD)\n   apply(erule disjE, rule disjI2, rule disjI1)\n    apply(fastforce simp: next_sib_set_def intro: trancl_into_trancl)\n   apply(intro disjI2, elim exE conjE)\n   apply(rule_tac x=q in exI)\n   apply(fastforce simp: next_sib_set_def intro: trancl_into_trancl)\n  apply(simp add: next_slot_def split: if_split_asm)\n   apply(erule disjE)\n    apply(rule disjI2)+\n    apply(rule_tac x=p in exI)\n    apply(rule conjI)\n     apply(simp add: descendants_of_def cdt_parent_defs)\n     apply(drule(1) next_childD)\n     apply(drule_tac x=p in tranclD2)\n     apply(elim exE conjE, simp)\n     apply(fastforce dest: rtranclD)\n    apply(fastforce)\n   apply(rule disjI1)\n   apply(frule(1) next_sib_set_same_parent)\n   apply(drule(1) next_childD)\n   apply(fastforce simp: descendants_of_def cdt_parent_defs intro: trancl_into_trancl2)\n  apply(drule(2) next_not_childD)\n  apply(rule disjI2)+\n  apply(case_tac \"next_sib c t m = Some b\")\n   apply(erule disjE)\n    apply(simp)\n    apply(rule_tac x=p in exI)\n    apply(fastforce dest: next_sib_share_parent)\n   apply(rule_tac x=c in exI)\n   apply(simp)\n   apply(rule_tac x=q in exI)\n   apply(fastforce simp: next_sib_set_def intro: trancl_into_trancl)\n  apply(simp | elim conjE exE)+\n  apply(erule disjE)\n   apply(rule_tac x=p in exI)\n   apply(rule conjI)\n    apply(rule disjI1)\n    apply(drule_tac c=p in next_sib_share_parent, simp)\n    apply(rule_tac b=qa in descendants_trans, simp, simp)\n   apply(fastforce)\n  apply(fastforce simp: next_sib_set_def intro: trancl_into_trancl)\n  done\n\nlemma list_eq_after_in_list:\n  \"\\<lbrakk>valid_list_2 t m; m x = Some p\\<rbrakk>\n    \\<Longrightarrow> \\<exists>list. t p = list @ x # after_in_list_list (t p) x\"\n  apply(simp only:valid_list_2_def)\n  apply (erule conjE)\n  apply (drule_tac x = p in spec)+\n  apply (subgoal_tac \"x \\<in> set (t p)\")\n   apply (drule_tac in_set_conv_nth[THEN iffD1], erule exE)\n   apply (auto simp: in_set_conv_nth list_eq_after_in_list')\n  done\n\nlemma next_sib_set_eq_after_in_list_set_Some:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"\\<lbrakk>valid_list_2 t m; m x = Some p\\<rbrakk>\n    \\<Longrightarrow> next_sib_set x t m = {a. (a, x) \\<in> {(next, c). after_in_list (t p) c = Some next}\\<^sup>+}\"\n  apply(intro equalityI subsetI)\n   apply(simp add: next_sib_set_def)\n   apply(drule trancl_Collect_rev)\n   apply(rule trancl_Collect_rev)\n   apply(erule trancl_induct)\n    apply(fastforce simp: next_sib_def split: option.splits)\n   apply(rule trancl_into_trancl)\n    apply(simp)\n   apply(subgoal_tac \"y \\<in> next_sib_set x t m\") (* bad *)\n    prefer 2\n    apply(fastforce simp: next_sib_set_def intro: trancl_Collect_rev)\n   apply(fastforce simp: next_sib_def split: option.splits dest: next_sib_set_same_parent)\n  apply(simp)\n  apply(drule trancl_Collect_rev)\n  apply(erule trancl_induct)\n   apply(fastforce simp: next_sib_set_def next_sib_def split: option.splits)\n  apply(simp add: next_sib_set_def)\n  apply(subgoal_tac \"y \\<in> next_sib_set x t m\")\n   prefer 2\n   apply(fastforce simp: next_sib_set_def intro: trancl_Collect_rev)\n  apply(drule(1) next_sib_set_same_parent)\n  apply(rule trancl_into_trancl2)\n   apply(fastforce simp: next_sib_def split: option.splits)\n  apply(simp)\n  done\n\nlemma next_sib_set_eq_after_in_list_set:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"valid_list_2 t m \\<Longrightarrow> next_sib_set x t m = (case m x of None \\<Rightarrow> {}\n    | Some q \\<Rightarrow> {a. (a, x) \\<in> {(next, p). after_in_list (t q) p = Some next}\\<^sup>+})\"\n  apply(simp add: next_sib_set_eq_after_in_list_set_Some split: option.splits)\n  apply(fastforce simp: next_sib_set_def next_sib_def split: option.splits dest: tranclD2)\n  done\n\n\nlemma valid_list_distinct:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"\\<lbrakk>valid_list_2 t m; m x = Some p\\<rbrakk> \\<Longrightarrow> distinct (t p)\"\nby (simp add:valid_list_2_def)\n\nlemma next_sib_set_not_self:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"valid_list_2 t m \\<Longrightarrow> x \\<notin> next_sib_set x t m\"\n  apply(simp add: next_sib_set_eq_after_in_list_set valid_list_distinct after_in_list_list_set[symmetric] split: option.splits)\n  apply(intro allI impI)\n  apply(frule_tac p=\"the (m x)\" in list_eq_after_in_list)\n   apply(simp)\n  apply(clarsimp simp add: valid_list_2_def)\n  apply(erule_tac x=\"the (m x)\" in allE)+\n  apply(drule_tac x=\"t x\" and f=distinct for x in arg_cong)\n  apply(simp)\ndone\n\nlemma next_slot_set_after_in_list:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"\\<lbrakk>next \\<in> next_slot_set slot t m; m slot = Some p; m next = Some p; valid_list_2 t m; no_mloop m; finite_depth m\\<rbrakk>\n    \\<Longrightarrow> next \\<in> next_sib_set slot t m\"\n  apply(drule(3) next_slot_setD)\n  apply(elim disjE)\n    apply(simp add: descendants_of_def cdt_parent_defs no_mloop_def)\n    apply(drule tranclD2)\n    apply(fastforce dest: trancl_into_trancl rtranclD)\n   apply(simp)\n  apply(elim exE conjE)\n  apply(frule(1) next_sib_set_same_parent)\n  apply(simp)\n  apply(elim conjE exE disjE)\n     apply(fastforce dest: sib_not_desc)\n    apply(simp add: descendants_of_def cdt_parent_defs)\n    apply(drule tranclD2)+\n    apply(elim exE conjE)\n    apply(drule rtranclD)+\n    apply(elim disjE)\n       apply(simp add: next_sib_set_not_self)\n      apply(simp)\n      apply(drule_tac x=za and y=q in sib_not_desc)\n        apply(assumption)+\n      apply(simp add: descendants_of_def cdt_parent_defs)\n     apply(simp)\n     apply(drule_tac x=za and y=pa in sib_not_desc)\n       apply(assumption)+\n     apply(simp add: descendants_of_def cdt_parent_defs)\n    apply(simp)\n    apply(subgoal_tac \"za \\<in> descendants_of pa m \\<and> za \\<in> descendants_of q m\")\n     prefer 2\n     apply(simp add: descendants_of_def cdt_parent_defs)\n    apply(erule conjE, drule(1) descendants_linear)\n     apply(fastforce simp: next_sib_set_not_self)\n    apply(simp add: sib_not_desc)\n   apply(simp)\n  apply(simp add: sib_not_desc)\n  done\n\nlemma next_slot_no_loop:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"\\<lbrakk>valid_list_2 t m; no_mloop m; finite_depth m\\<rbrakk>\n    \\<Longrightarrow> x \\<notin> next_slot_set x t m\"\n  apply(rule notI)\n  apply(case_tac \"m x\")\n   apply(drule(2) next_slot_setD, simp)\n   apply(simp add: next_sib_set_not_self)\n   apply(erule disjE)\n    apply(simp add: no_mloop_def descendants_of_def)\n   apply(elim exE conjE)\n   apply(erule disjE)\n    apply(fastforce simp: descendants_of_def cdt_parent_defs dest: tranclD2)\n   apply(fastforce simp: next_sib_set_def next_sib_def split: option.splits dest: tranclD2)\n  apply(drule next_slot_set_after_in_list)\n       apply(assumption)+\n  apply(simp add: next_sib_set_not_self)\n  done\n\nlemma wf_next_slot:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>valid_mdb s; valid_list s\\<rbrakk>\n    \\<Longrightarrow> wf {(next, p). next_slot p (cdt_list s) (cdt s) = Some next}\"\n  apply(rule finite_acyclic_wf)\n   apply(insert cte_wp_at_set_finite)[1]\n   apply(rule_tac B=\"{p. cte_wp_at \\<top> p s} \\<times> {p. cte_wp_at \\<top> p s}\" in finite_subset)\n    apply(fastforce dest: cte_at_next_slot cte_at_next_slot' simp: finite_depth)\n   apply(fastforce intro: finite_cartesian_product)\n  apply(rule acyclicI)\n  apply(frule finite_depth)\n  apply(rule allI)\n  apply(drule next_slot_no_loop, simp add: valid_mdb_def, simp add: finite_depth)\n  apply(fastforce simp: next_slot_set_def)\n  done\n\nlemma next_slot_induct:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows\n  \"\\<lbrakk>\\<And>x. next_slot x (cdt_list s) (cdt s) = None \\<Longrightarrow> P x; \\<And>x y. \\<lbrakk>next_slot x (cdt_list s) (cdt s) = Some y; P y\\<rbrakk> \\<Longrightarrow> P x;\n    valid_mdb s; valid_list s\\<rbrakk>\n    \\<Longrightarrow> P slot\"\n  apply(induct_tac rule: wf_induct[where r=\"{(next, p). next_slot p (cdt_list s) (cdt s) = Some next}\"])\n   apply(simp add: wf_next_slot)\n  apply(fastforce split: if_split_asm)\n  done\n\nlemma next_sib_2_termination:\n  \"\\<lbrakk>valid_mdb s; valid_list s\\<rbrakk> \\<Longrightarrow> next_sib_2_dom (slot, p, s)\"\n  apply(induct_tac slot rule: next_slot_induct[where s=s])\n     apply(fastforce intro: next_sib_2_domintros)+\n  done\n\nlemma next_sib_2_pinduct':\n  \"\\<lbrakk>next_sib_2_dom (slot, p, s);\n   \\<And>slot.\n      \\<lbrakk>next_sib_2_dom (slot, p, s);\n       \\<And>a. \\<lbrakk>slot \\<in> descendants_of p (cdt s);\n          next_slot slot (cdt_list s) (cdt s) = Some a; cdt s a \\<noteq> Some p\\<rbrakk> \\<Longrightarrow> P a t m\\<rbrakk>\n      \\<Longrightarrow> P slot t m\\<rbrakk>\n  \\<Longrightarrow> P slot t m\"\n  apply(induct rule: next_sib_2.pinduct)\n  apply(simp)\n  done\n\nlemma next_sib_2_pinduct:\n  \"\\<lbrakk>\\<And>slot. \\<lbrakk>\\<And>a. \\<lbrakk>slot \\<in> descendants_of p (cdt s);\n          next_slot slot (cdt_list s) (cdt s) = Some a; cdt s a \\<noteq> Some p\\<rbrakk> \\<Longrightarrow> P a\\<rbrakk>\n    \\<Longrightarrow> P slot; valid_mdb s; valid_list s\\<rbrakk>\n      \\<Longrightarrow> P slot\"\n  apply(rule_tac t=t and m=m in next_sib_2_pinduct')\n   apply(rule next_sib_2_termination)\n    apply(assumption)+\n  apply(fastforce)\n  done\n\nlemma next_slot_set_in_desc:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"\\<lbrakk>next \\<in> next_slot_set slot (cdt_list s) (cdt s); cdt s next = Some p;\n    slot \\<in> descendants_of p (cdt s); next_slot slot (cdt_list s) (cdt s) = Some a;\n    valid_list s; valid_mdb s\\<rbrakk>\n    \\<Longrightarrow> a \\<in> descendants_of p (cdt s)\"\n  apply(frule finite_depth)\n  apply(subgoal_tac \"no_mloop (cdt s)\")\n   prefer 2\n   apply(simp add: valid_mdb_def)\n  apply(frule(1) next_slot_setD)\n    apply(simp add: valid_mdb_def, simp+)\n  apply(elim disjE)\n    apply(simp add: descendants_of_def cdt_parent_defs)\n    apply(drule_tac x=slot in tranclD2)\n    apply(simp)\n    apply(drule(1) rtrancl_trancl_trancl)\n    apply(simp add: no_mloop_def cdt_parent_defs)\n   apply(frule(1) next_sib_set_same_parent)\n   apply(simp add: next_slot_def split: if_split_asm)\n    apply(drule(1) next_childD)\n    apply(simp add: descendants_of_def cdt_parent_defs)\n    apply(rule_tac b=slot in r_r_into_trancl)\n     apply(simp)\n    apply(simp)\n   apply(simp add: next_not_child_termination)\n   apply(simp split: if_split_asm option.splits)\n    apply(fastforce dest: tranclD2 simp: next_sib_set_def)+\n   apply(drule(1) next_sib_same_parent, simp add: child_descendant)\n  apply(elim exE conjE)\n  apply(subgoal_tac \"q = next\")\n   prefer 2\n   apply(subgoal_tac \"pa \\<in> descendants_of p (cdt s)\")\n    prefer 2\n    apply(erule disjE)\n     apply(frule_tac b=p and c=pa in descendants_linear, simp)\n      apply(frule(1) next_sib_set_same_parent)\n      apply(elim exE conjE)\n      apply(rule notI, simp)\n      apply(erule disjE)\n       apply(simp add: no_mloop_weaken)\n      apply(frule_tac a=\"next\" and c=pa in descendants_linear)\n        apply(simp add: child_descendant)\n       apply(fastforce simp: next_sib_set_not_self)\n      apply(simp add: sib_not_desc)\n     apply(frule(1) next_sib_set_same_parent)\n     apply(erule disjE)+\n       apply(simp add: child_descendant)\n      apply(simp)\n     apply(erule disjE)\n      apply(frule_tac a=p and c=q in descendants_linear)\n        apply(simp add: descendants_of_def cdt_parent_defs)\n        apply(drule_tac x=q in tranclD2)\n        apply(simp)\n        apply(drule rtranclD)\n        apply(elim disjE exE conjE)\n         apply(fastforce dest: sib_not_desc[simplified descendants_of_def cdt_parent_defs])\n        apply(simp)\n       apply(fastforce simp: next_sib_set_not_self)\n      apply(fastforce dest: sib_not_desc)\n     apply(simp)\n    apply(simp)\n   apply(erule_tac P=\"next = q\" in disjE, simp)\n   apply(simp add: descendants_of_def cdt_parent_defs)\n   apply(drule_tac x=q in tranclD2)\n   apply(simp)\n   apply(drule_tac x=q and z=pa in rtrancl_trancl_trancl, simp)\n   apply(fastforce dest: sib_not_desc[simplified descendants_of_def cdt_parent_defs]\n               next_sib_set_same_parent)\n  apply(simp)\n  apply(simp add: next_slot_def split: if_split_asm)\n   apply(drule(1) next_childD)\n   apply(rule descendants_trans)\n    apply(rule child_descendant)\n    apply(simp)\n   apply(simp)\n  apply(drule(2) next_not_childD)\n  apply(erule_tac P=\"next_sib slot (cdt_list s) (cdt s) = Some a\" in disjE)\n   apply(simp add: next_sib_share_parent)\n  apply(elim exE conjE)\n  apply(case_tac \"qa=pa\")\n   apply(fastforce intro: child_descendant dest: next_sib_same_parent next_sib_set_same_parent)\n  apply(erule disjE)\n   apply(frule_tac a=slot and b=pa and c=qa in descendants_linear)\n     apply(simp)+\n   apply(erule disjE)\n    apply(fastforce simp: next_sib_set_def dest: tranclD2)\n   apply(drule_tac a=qa and c=p in descendants_trans)\n    apply(fastforce dest: next_sib_set_same_parent simp: child_descendant)\n   apply(fastforce dest: next_sib_share_parent)\n  apply(simp)\n  apply(fastforce simp: next_sib_set_def dest: tranclD2)\n  done\n\ndeclare next_sib_2.psimps[simp]\n\nlemma next_sib_2_NoneD:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  assumes \"next_sib_2 slot p s = None\" \"slot \\<in> descendants_of p (cdt s)\" \"valid_mdb s\"\n     \"valid_list s\" \"q \\<in> next_slot_set slot (cdt_list s) (cdt s)\"\n  shows \"cdt s q \\<noteq> Some p\"\n  apply(insert assms)\n  apply(rule notI)\n  apply(case_tac \"next_slot slot (cdt_list s) (cdt s)\")\n   apply(fastforce simp: next_slot_set_def dest: tranclD2)\n  apply(frule(5) next_slot_set_in_desc)\n  apply(erule notE[rotated])\n  apply(simp)\n  apply(induct slot rule: next_sib_2_pinduct[where s=s and p=p])\n    apply(simp)\n    apply(atomize)\n    apply(simp)\n    apply(elim impCE)\n      apply(fastforce simp: next_sib_2_termination)\n     apply(simp add: next_slot_set_def)\n     apply(drule tranclD2, simp)\n     apply(drule rtranclD)\n     apply(fastforce simp: next_sib_2_termination)\n    apply(case_tac \"next_slot a (cdt_list s) (cdt s)\")\n     apply(simp add: next_slot_set_def)\n     apply(drule tranclD2, simp)\n     apply(drule rtranclD)\n     apply(erule disjE)\n      apply(fastforce simp: next_sib_2_termination)\n     apply(fastforce dest: tranclD2)\n    apply(case_tac \"q=a\")\n     apply(fastforce simp: next_sib_2_termination)\n    apply(subgoal_tac \"q \\<in> next_slot_set a (cdt_list s) (cdt s)\")\n     prefer 2\n     apply(simp add: next_slot_set_def)\n     apply(drule tranclD2, simp)\n     apply(drule rtranclD)\n     apply(fastforce simp: next_sib_2_termination)\n    apply(frule_tac slot=a in next_slot_set_in_desc) (* rename *)\n         apply(simp_all)\n    apply(simp)\n    apply(erule exE)\n    apply(case_tac \"cdt s a = Some p\")\n     apply(fastforce simp: next_sib_2_termination)\n    apply(rule_tac x=y in exI)\n    apply(fastforce simp: next_sib_2_termination)\n   apply(simp_all add: assms)\n   done\n\ndefinition last_child where\n  \"last_child slot t = (if t slot = [] then None else Some (last (t slot)))\"\n\ndefinition last_child_set where\n  \"last_child_set slot t = {p. (p, slot) \\<in> {(next, c). last_child c t = Some next}\\<^sup>+}\"\n\nfunction (domintros) last_last_child where\n  \"last_last_child slot t = (case last_child slot t of None \\<Rightarrow> None\n                          | Some child \\<Rightarrow> (if last_child child t = None then Some child\n                                     else last_last_child child t))\"\n  by auto\n\n\nlemma last_childD:\n  notes split_paired_All[simp del]\n  shows \"\\<lbrakk>last_child slot t = Some child; valid_list_2 t m\\<rbrakk>\n    \\<Longrightarrow> m child = Some slot \\<and> next_sib child t m = None\"\n  apply(rule context_conjI)\n   apply(fastforce simp: valid_list_2_def last_child_def split: if_split_asm)\n  apply(rule next_sib_NoneI[where p=slot])\n  apply(case_tac \"t slot\")\n   apply(simp)\n  apply(simp add: valid_list_2_def last_child_def split: if_split_asm)\n  apply(erule_tac x=slot in allE)+\n  apply(drule after_in_list_last_None)\n  apply(simp)\n  done\n\n\nlemma last_child_set_in_desc:\n  \"\\<lbrakk>valid_list_2 t m; c \\<in> last_child_set p t\\<rbrakk> \\<Longrightarrow> c \\<in> descendants_of p m\"\n  apply(simp add: last_child_set_def)\n  apply(erule trancl_induct)\n   apply(fastforce simp: child_descendant dest: last_childD)\n  apply(simp)\n  apply(drule(1) last_childD)\n  apply(erule conjE)\n  apply(drule child_descendant)\n  apply(rule descendants_trans)\n   apply(simp)+\n  done\n\nlemma last_child_no_loop:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"\\<lbrakk>valid_list_2 t m; no_mloop m\\<rbrakk>\n    \\<Longrightarrow> x \\<notin> last_child_set x t\"\n  apply(rule notI)\n  apply(drule(1) last_child_set_in_desc)\n  apply(simp add: no_mloop_descendants)\n  done\n\n\nlemma wf_last_child:\n  \"\\<lbrakk>valid_mdb s; valid_list s\\<rbrakk> \\<Longrightarrow> wf {(next, p). last_child p (cdt_list s) = Some next}\"\n  apply(rule finite_acyclic_wf)\n   apply(insert cte_wp_at_set_finite)[1]\n   apply(rule_tac B=\"{p. cte_wp_at \\<top> p s} \\<times> {p. cte_wp_at \\<top> p s}\" in finite_subset)\n    apply(fastforce dest: last_childD child_descendant descendants_of_cte_at\n                         descendants_of_cte_at2)\n   apply(fastforce intro: finite_cartesian_product)\n  apply(rule acyclicI)\n  apply(rule allI)\n  apply(drule_tac x=x in last_child_no_loop, simp add: valid_mdb_def)\n  apply(simp add: last_child_set_def)\n  done\n\nlemma last_child_induct:\n  \"\\<lbrakk>\\<And>x. last_child x (cdt_list s) = None \\<Longrightarrow> P x; \\<And>x y. \\<lbrakk>last_child x (cdt_list s) = Some y; P y\\<rbrakk> \\<Longrightarrow> P x;\n    valid_mdb s; valid_list s\\<rbrakk>\n    \\<Longrightarrow> P slot\"\n  apply(induct_tac rule: wf_induct[where r=\"{(next, p). last_child p (cdt_list s) = Some next}\"])\n   apply(simp add: wf_last_child)\n  apply(fastforce split: if_split_asm)\n  done\n\nlemma last_last_child_termination:\n  \"\\<lbrakk>valid_mdb s; valid_list s\\<rbrakk> \\<Longrightarrow> last_last_child_dom (slot, (cdt_list s))\"\n  apply(induct_tac slot rule: last_child_induct[where s=s])\n     apply(fastforce intro: last_last_child.domintros)+\n  done\n\ndeclare last_last_child.psimps[simp]\n\nlemma last_child_NoneD:\n  \"\\<lbrakk>last_child x t = None; valid_list_2 t m\\<rbrakk> \\<Longrightarrow> descendants_of x m = {}\"\n  by(simp add: last_child_def empty_list_empty_desc split: if_split_asm)\n\nlemma last_last_child_NoneD:\n  notes split_paired_Ex[simp del]\n  assumes \"last_last_child slot (cdt_list s) = None\" \"valid_list s\" \"valid_mdb s\"\n  shows \"descendants_of slot (cdt s) = {}\"\n  apply(insert assms)\n  apply(simp add: last_last_child_termination)\n  apply(simp split: if_split_asm option.splits)\n   apply(simp add:last_child_NoneD)\n  apply(erule exE)\n  apply(induct slot rule: last_child_induct[where s=s])\n     apply(fastforce dest: last_child_NoneD)\n    apply(simp)\n    apply(case_tac \"last_child ya (cdt_list s)\")\n     apply(simp add: last_last_child_termination)\n    apply(atomize, simp)\n    apply(erule impE)\n     apply(simp add: last_last_child_termination)\n    apply(drule_tac slot=y in last_childD, simp)\n    apply(fastforce dest: child_descendant)\n   using assms\n   apply(simp+)\n  done\n\nlemma last_child_None_empty_desc:\n  \"\\<lbrakk>last_child slot t = None; valid_list_2 t m\\<rbrakk> \\<Longrightarrow> descendants_of slot m = {}\"\n  by (simp add: last_child_def empty_list_empty_desc split: if_split_asm)\n\nlemma last_last_child_empty_desc:\n  assumes \"last_last_child slot (cdt_list s) = Some child\" \"valid_mdb s\" \"valid_list s\"\n  shows \"descendants_of child (cdt s) = {}\"\n  apply(insert assms)\n  apply(induct slot rule: last_child_induct[where s=s])\n     apply(simp add: last_last_child_termination)\n    apply(case_tac \"y=child\")\n     apply(simp add: last_last_child_termination last_child_None_empty_desc\n              split: if_split_asm)\n    apply(simp)\n    apply(atomize, erule impE)\n     apply(subst(asm) last_last_child.psimps)\n      apply(simp add: last_last_child_termination)\n     apply(simp split: option.splits if_split_asm)\n    apply(simp)\n   using assms\n   apply(simp+)\n   done\n\nlemma last_last_child_next_sib:\n  assumes \"last_last_child slot (cdt_list s) = Some child\" \"valid_mdb s\" \"valid_list s\"\n  shows \"next_sib child (cdt_list s) (cdt s) = None\"\n  apply(insert assms)\n  apply(induct slot rule: last_child_induct[where s=s])\n     apply(simp add: last_last_child_termination)\n    apply(case_tac \"y=child\")\n     apply(fastforce dest: last_childD)\n    apply(simp)\n    apply(atomize, erule impE)\n     apply(subst(asm) last_last_child.psimps)\n      apply(simp add: last_last_child_termination)\n     apply(simp split: option.splits if_split_asm)\n    apply(simp)\n   using assms\n   apply(simp+)\n   done\n\nlemma last_last_child_in_desc:\n  assumes \"last_last_child slot (cdt_list s) = Some child\" \"valid_mdb s\" \"valid_list s\"\n  shows \"child \\<in> descendants_of slot (cdt s)\"\n  apply(insert assms)\n  apply(induct slot rule: last_child_induct[where s=s])\n     apply(simp add: last_last_child_termination)\n    apply(case_tac \"y=child\")\n     apply(simp add: last_last_child_termination)\n     apply(drule last_childD, simp)\n     apply(fastforce dest: child_descendant intro: descendants_trans split: option.splits)\n    apply(simp)\n    apply(atomize, erule impE)\n     apply(subst(asm) last_last_child.psimps)\n      apply(simp add: last_last_child_termination)\n     apply(simp split: option.splits if_split_asm)\n    apply(drule last_childD, simp)\n    apply(fastforce dest: child_descendant descendants_trans)\n   using assms\n   apply(simp+)\n   done\n\nlemma last_last_child_next_not_child:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  assumes \"last_last_child slot (cdt_list s) = Some child\" \"valid_mdb s\" \"valid_list s\"\n  shows \"next_not_child child (cdt_list s) (cdt s) = next_not_child slot (cdt_list s) (cdt s)\"\n  apply(insert assms)\n  apply(frule(2) last_last_child_empty_desc)\n  apply(frule(2) last_last_child_next_sib)\n  apply(frule(2) last_last_child_in_desc)\n  apply(induct slot rule: last_child_induct[where s=s])\n     apply(simp add: last_last_child_termination)\n    apply(case_tac \"y=child\")\n     apply(subst next_not_child.psimps)\n      apply(simp add: next_not_child_termination finite_depth)\n     apply(drule last_childD, simp,simp)\n    apply(simp, atomize)\n    apply(elim impE)\n      apply(subst(asm) last_last_child.psimps)\n       apply(simp add: last_last_child_termination)\n      apply(simp split: option.splits if_split_asm)\n     apply(subst(asm) last_last_child.psimps)\n      apply(simp add: last_last_child_termination)\n     apply(simp split: if_split_asm)\n     apply(rule last_last_child_in_desc, simp+)\n    apply(drule last_childD, simp)\n    apply(simp add: next_not_child_termination finite_depth)\n   using assms\n   apply(simp+)\n   done\n\nlemma last_child_NoneI:\n  \"\\<lbrakk>descendants_of slot m = {}; valid_list_2 t m\\<rbrakk>\n    \\<Longrightarrow> last_child slot t = None\"\n  by (simp add: last_child_def empty_list_empty_desc)\n\nlemma last_last_childI:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  assumes \"child \\<in> last_child_set slot (cdt_list s)\"\n   \"descendants_of child (cdt s) = {}\" \"valid_mdb s\" \"valid_list s\"\n  shows \"last_last_child slot (cdt_list s) = Some child\"\n  apply(insert assms)\n  apply(induct slot rule: last_child_induct[where s=s])\n     apply(fastforce simp: last_child_set_def dest: tranclD2)\n    apply(simp)\n    apply(case_tac \"y=child\")\n     apply(simp add: last_last_child_termination last_child_NoneI)\n    apply(atomize)\n    apply(erule impE)\n     apply(fastforce simp: last_child_set_def dest: tranclD2 rtranclD)\n    apply(simp add: last_last_child_termination split: option.splits)\n   using assms\n   apply(simp+)\n   done\n\nlemma desc_next_slot_desc_or_sib:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  assumes \"p \\<in> descendants_of slot (cdt s)\"\"valid_list s\" \"valid_mdb s\"\n  shows \"(\\<exists>q. next_slot p (cdt_list s) (cdt s) = Some q \\<and>\n    q \\<in> descendants_of slot (cdt s))\n      \\<or> last_last_child slot (cdt_list s) = Some p\n        \\<and> next_not_child p (cdt_list s) (cdt s) = next_not_child slot (cdt_list s) (cdt s)\"\n  apply(insert assms)\n  apply(case_tac \"last_last_child slot (cdt_list s) = Some p\")\n   apply(frule(2) last_last_child_empty_desc)\n   apply(frule(2) last_last_child_next_not_child)\n   apply(rule disjI2)\n   apply(simp add: next_slot_def empty_list_empty_desc split: if_split_asm)\n  apply(rule disjI1)\n  apply(case_tac \"next_slot p (cdt_list s) (cdt s)\")\n   apply(simp)\n   apply(erule notE)\n   apply(rule last_last_childI)\n      apply(simp add: next_slot_def split: if_split_asm)\n       apply(drule next_child_NoneD)\n       apply(simp add: empty_list_empty_desc )\n      apply(simp add: empty_list_empty_desc)\n      apply(drule next_not_child_NoneD, simp add: finite_depth)\n      apply(erule conjE)\n      apply(induct slot rule: last_child_induct[where s=s])\n         apply(simp add: last_child_None_empty_desc)\n        apply(case_tac \"y=p\")\n         apply(fastforce simp: last_child_set_def)\n        apply(simp)\n        apply(atomize)\n        apply(erule impE)\n         apply(simp add: descendants_of_def cdt_parent_defs)\n         apply(frule tranclD, simp)\n         apply(elim exE conjE)\n         apply(drule rtranclD)\n         apply(erule_tac P=\"z=p\" in disjE)\n          apply(simp add: valid_list_2_def)\n          apply(erule conjE)\n          apply(erule_tac x=x in allE)+\n          apply(simp add: next_sib_def)\n          apply(drule after_in_list_last_None)\n          apply(drule after_in_list_None_last, simp)\n          apply(simp add: last_child_def split: if_split_asm)\n         apply(erule_tac x=z and P=\"\\<lambda>q. (q, p) \\<in> {(p, c). cdt s c = Some p}\\<^sup>+ \\<longrightarrow>\n            next_sib q (cdt_list s) (cdt s) = None\" in allE)\n         apply(erule impE)\n          apply(simp)\n         apply(simp add: next_sib_def valid_list_2_def)\n         apply(erule conjE)\n         apply(erule_tac x=x in allE)+\n         apply(drule after_in_list_last_None)\n         apply(drule after_in_list_None_last, simp)\n         apply(simp add: last_child_def split: if_split_asm)\n        apply(fastforce simp: last_child_set_def intro: trancl_into_trancl)\n       using assms\n       apply(simp_all add: empty_list_empty_desc)\n   apply(simp add: next_slot_def empty_list_empty_desc next_child_def split: if_split_asm list.splits)\n  apply(simp add: next_slot_def split: if_split_asm)\n   apply(fastforce dest: next_childD child_descendant descendants_trans)\n  apply(drule next_not_childD, simp add: finite_depth, simp add: valid_mdb_def)\n  apply(erule disjE)\n   apply(fastforce dest: next_sib_share_parent)\n  apply(rule ccontr)\n  apply(elim exE conjE)\n  apply(erule notE)\n  apply(rule last_last_childI)\n     apply(induct slot rule: last_child_induct[where s=s])\n        apply(simp add: last_child_None_empty_desc)\n       apply(case_tac \"y=p\")\n        apply(fastforce simp: last_child_set_def)\n       apply(simp)\n       apply(atomize)\n       apply(erule_tac x=a in allE)\n       apply(erule_tac x=q and P=\"\\<lambda>q. p \\<in> descendants_of y (cdt s) \\<longrightarrow>\n            a \\<notin> descendants_of y (cdt s) \\<longrightarrow>\n            next_sib q (cdt_list s) (cdt s) = Some a \\<longrightarrow>\n            p \\<in> descendants_of q (cdt s) \\<longrightarrow>\n            (\\<forall>q'. q' \\<in> descendants_of q (cdt s) \\<and> p \\<in> descendants_of q' (cdt s) \\<longrightarrow>\n                  next_sib q' (cdt_list s) (cdt s) = None) \\<longrightarrow>\n            p \\<in> last_child_set y (cdt_list s)\" in allE)\n       apply(simp)\n       apply(elim impE)\n         apply(subgoal_tac \"x \\<in> descendants_of q (cdt s) \\<union> {q}\")\n          prefer 2\n          apply(rule ccontr)\n          apply(erule notE)\n          apply(simp)\n          apply(drule_tac c=x in next_sib_share_parent, simp)\n          apply(drule(1) descendants_linear, simp)\n          apply(simp)\n         apply(simp add: descendants_of_def cdt_parent_defs)\n         apply(frule tranclD, simp)\n         apply(elim exE conjE)\n         apply(drule rtranclD)\n         apply(erule_tac P=\"z=p\" in disjE)\n          apply(simp add: valid_list_2_def)\n          apply(erule conjE)\n          apply(erule_tac x=x in allE)+\n          apply(simp add: next_sib_def)\n          apply(drule after_in_list_last_None)\n          apply(drule after_in_list_None_last, simp)\n          apply(simp add: last_child_def split: if_split_asm)\n         apply(erule_tac x=z in allE)\n         apply(erule impE)\n          apply(rule conjI)\n           apply(fastforce intro: trancl_into_trancl)\n          apply(fastforce dest: rtranclD)\n         apply(simp add: next_sib_def valid_list_2_def)\n         apply(erule conjE)\n         apply(erule_tac x=x in allE)+\n         apply(drule after_in_list_last_None)\n         apply(drule after_in_list_None_last, simp)\n         apply(simp add: last_child_def split: if_split_asm)\n        apply(rule notI, erule notE)\n        apply(drule(1) last_childD)\n        apply(fastforce dest: child_descendant intro: descendants_trans)\n       apply(fastforce simp: last_child_set_def intro: trancl_into_trancl)\n      using assms\n      apply(simp_all add: empty_list_empty_desc)\n      done\n\nlemma finite_descendants:\n  \"valid_mdb s \\<Longrightarrow> finite (descendants_of slot (cdt s))\"\n  apply(rule_tac B=\"{p. cte_at p s}\" in finite_subset)\n   apply(rule subsetI)\n   apply(simp add: descendants_of_cte_at)\n  apply(simp add: cte_wp_at_set_finite)\n  done\n\nlemma next_slot_linear:\n  \"\\<lbrakk>a \\<in> next_slot_set c t m; b \\<in> next_slot_set c t m; a \\<noteq> b\\<rbrakk>\n    \\<Longrightarrow> a \\<in> next_slot_set b t m \\<or> b \\<in> next_slot_set a t m\"\n  apply(clarsimp)\n  apply(simp add: next_slot_set_def)\n  apply(induct a c rule: trancl.induct)\n   apply(simp)\n   apply(erule tranclE)\n    apply(simp)\n   apply(simp)\n  apply(simp)\n  apply(case_tac \"ba=b\")\n   apply(simp)\n  apply(subgoal_tac \"(b, ba) \\<in> {(next, p). next_slot p t m = Some next}\\<^sup>+\")\n   apply(simp)\n  apply(erule_tac a=b and b=c in tranclE)\n   apply(simp)\n  apply(simp)\n  done\n\nlemma next_sib_in_next_slot_set:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"\\<lbrakk>next_sib slot (cdt_list s) (cdt s) = Some next; valid_list s; valid_mdb s\\<rbrakk>\n    \\<Longrightarrow> next \\<in> next_slot_set slot (cdt_list s) (cdt s)\"\n  apply(subgoal_tac \"finite (descendants_of slot (cdt s))\")\n   prefer 2\n   apply(rule finite_subset[OF _ cte_wp_at_set_finite[where P=\"\\<top>\\<top>\" and s=s]])\n   apply(fastforce simp: descendants_of_cte_at)\n  apply(frule finite_depth)\n  apply(subgoal_tac \"no_mloop (cdt s)\")\n   prefer 2\n   apply(simp add: valid_mdb_def)\n  apply(case_tac \"descendants_of slot (cdt s) = {}\")\n   apply(fastforce simp: next_slot_set_def next_slot_def empty_list_empty_desc next_not_child_termination)\n  apply(case_tac \"last_last_child slot (cdt_list s)\")\n   apply(drule(2) last_last_child_NoneD, simp)\n  apply(case_tac \"a \\<in> next_slot_set slot (cdt_list s) (cdt s)\")\n   apply(frule(2) last_last_child_empty_desc)\n   apply(drule(2) last_last_child_next_not_child)\n   apply(simp add: next_slot_set_def)\n   apply(rule_tac b=a in trancl_into_trancl2)\n    apply(simp add: next_slot_def empty_list_empty_desc next_not_child_termination)\n   apply(simp)\n  apply(subgoal_tac \"next_slot_set slot (cdt_list s) (cdt s) \\<subseteq> descendants_of slot (cdt s)\")\n   prefer 2\n   apply(rule subsetI)\n   apply(simp add: next_slot_set_def)\n   apply(drule trancl_Collect_rev)\n   apply(erule trancl_induct)\n    apply(simp add: empty_list_empty_desc next_slot_def)\n    apply(drule(1) next_childD, simp add: child_descendant)\n   apply(simp)\n   apply(drule(2) desc_next_slot_desc_or_sib)\n   apply(erule disjE, simp)\n   apply(drule_tac b=y in trancl_Collect_rev)\n   apply(simp)\n  apply(subgoal_tac \"(\\<lambda>p. the (next_slot p (cdt_list s) (cdt s))) ` (next_slot_set slot (cdt_list s) (cdt s)) \\<subset> next_slot_set slot (cdt_list s) (cdt s)\")\n   prefer 2\n   apply(simp add: image_def)\n   apply(rule psubsetI)\n    apply(rule subsetI)\n    apply(simp)\n    apply(erule bexE)\n    apply(simp add: next_slot_set_def)\n    apply(case_tac \"next_slot xa (cdt_list s) (cdt s)\")\n     apply(drule_tac c=xa in subsetD)\n      apply(simp)\n     apply(drule(2) desc_next_slot_desc_or_sib, simp)\n    apply(drule trancl_Collect_rev)\n    apply(drule_tac c=x in trancl_into_trancl)\n     apply(case_tac \"next_slot xa (cdt_list s) (cdt s)\")\n      apply(simp)\n     apply(simp add: the_def)\n    apply(simp)\n    apply(drule trancl_Collect_rev, simp)\n   apply(case_tac \"next_slot slot (cdt_list s) (cdt s)\")\n    apply(fastforce simp: next_slot_def empty_list_empty_desc next_child_def split: if_split_asm list.splits)\n   apply(rule_tac x=aa in set_neqI[symmetric])\n    apply(fastforce simp: next_slot_set_def)\n   apply(rule ccontr, simp)\n   apply(erule bexE)\n   apply(simp)\n   apply(subgoal_tac \"\\<exists>y. next_slot x (cdt_list s) (cdt s) = Some y\")\n    prefer 2\n    apply(rule ccontr)\n    apply(simp)\n    apply(drule_tac c=x in subsetD)\n     apply(simp)\n    apply(drule(2) desc_next_slot_desc_or_sib, simp)\n   apply(erule exE, simp)\n   apply(frule_tac x=y in next_slot_no_loop, assumption+)\n   apply(erule notE)+\n   apply(simp add: next_slot_set_def)\n   apply(drule tranclD2, simp)\n   apply(drule rtranclD)\n   apply(erule disjE, fastforce)\n   apply(rule_tac b=x in trancl_into_trancl2)\n    apply(simp)\n   apply(simp)\n  apply(frule finite_subset)\n   apply(simp add: finite_descendants)\n  apply(frule(1) psubset_card_mono)\n  apply(drule_tac f=\"(\\<lambda>p. the (next_slot p (cdt_list s) (cdt s)))\" and A=\"next_slot_set slot (cdt_list s) (cdt s)\" in inj_on_iff_eq_card)\n  apply(erule iffE)\n  apply(erule impE)\n   apply(simp)\n   apply(rule inj_onI)\n   apply(frule_tac c=x in subsetD, simp)\n   apply(frule_tac c=y in subsetD, simp)\n   apply(case_tac \"next_slot x (cdt_list s) (cdt s)\")\n    apply(drule(2) desc_next_slot_desc_or_sib)+\n    apply(simp)\n   apply(case_tac \"next_slot y (cdt_list s) (cdt s)\")\n    apply(drule(2) desc_next_slot_desc_or_sib)+\n    apply(simp)\n   apply(simp)\n   apply(rule ccontr)\n   apply(drule(2) next_slot_linear)\n   apply(erule disjE)\n    apply(drule_tac x=x in next_slot_no_loop, assumption+)\n    apply(simp add: next_slot_set_def)\n    apply(drule_tac x=x in tranclD2, simp)\n    apply(drule_tac x=x and z=x in rtrancl_trancl_trancl)\n     apply(rule r_into_trancl, simp+)\n   apply(drule_tac x=y in next_slot_no_loop, assumption+)\n   apply(simp add: next_slot_set_def)\n   apply(drule_tac x=y and y=x in tranclD2, simp)\n   apply(drule_tac x=y and z=y in rtrancl_trancl_trancl)\n    apply(rule r_into_trancl, simp+)\n    done\n\n\nlemma next_sib_2_None_next_sib:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"\\<lbrakk>next_sib_2 slot p s = None; valid_mdb s; valid_list s; cdt s slot = Some p\\<rbrakk>\n    \\<Longrightarrow> next_sib slot (cdt_list s) (cdt s) = None\"\n  apply(rule ccontr, simp, erule exE)\n  apply(frule(2) next_sib_in_next_slot_set)\n  apply(frule child_descendant)\n  apply(drule(4) next_sib_2_NoneD)\n  apply(fastforce dest: next_sibD next_sib_same_parent)\n  done\n\nlemma next_sib_2_in_next_slot_set:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  assumes \"next_sib_2 slot p s = Some next\" \"valid_list s\" \"valid_mdb s\"\n  shows \"next \\<in> next_slot_set slot (cdt_list s) (cdt s)\"\n  using assms\n  apply(induct rule: next_slot_induct[where s=s])\n     apply(simp add: next_sib_2_termination split: if_splits)\n    apply(simp add: next_sib_2_termination split: if_splits)\n     apply(fastforce simp: next_slot_set_def intro: trancl_into_trancl)\n    apply(fastforce simp: next_slot_set_def intro: trancl_into_trancl)\n   apply(insert assms, simp+)\n   done\n\nlemma next_sib_2_sib':\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  assumes \"next_sib_2 slot p s = Some next\" \"cdt s slot \\<noteq> Some p\" \"valid_list s\" \"valid_mdb s\"\n  shows \"cdt s next = Some p\"\n  apply(insert assms)\n  apply(induct slot rule: next_sib_2_pinduct[where s=s and p=p])\n    apply(simp)\n    apply(frule(2) next_sib_2_in_next_slot_set)\n    apply(case_tac \"next_slot slot (cdt_list s) (cdt s)\")\n     apply(fastforce simp: next_slot_set_def dest: tranclD2)\n    apply(simp)\n    apply(atomize)\n    apply(erule_tac x=a in allE, simp)\n    apply(case_tac \"a=next\")\n     apply(simp add: next_sib_2_termination split: if_split_asm | erule impE)+\n   apply(insert assms, simp+)\n   done\n\nlemma next_sib_2_sib:\n  \"\\<lbrakk>next_sib_2 slot p s = Some next; valid_list s; valid_mdb s\\<rbrakk>\n    \\<Longrightarrow> cdt s next = Some p\"\n  apply(case_tac \"cdt s slot = Some p\")\n   apply(simp add: next_sib_2_termination split: if_split_asm)\n   apply(simp split: option.splits if_split_asm)\n   apply(fastforce intro: next_sib_2_sib')+\n   done\n\nlemma ex_imp:\n  \"\\<lbrakk>\\<forall>x. P x \\<longrightarrow> Q x; \\<exists>x. P x\\<rbrakk> \\<Longrightarrow> \\<exists>x. Q x\"\n  by auto\n\nlemma next_sib_2I:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  assumes \"cdt s next = Some p\" \"next \\<in> next_slot_set slot (cdt_list s) (cdt s)\"\n    \"\\<forall>q. q \\<in> next_slot_set slot (cdt_list s) (cdt s) \\<and>\n     next \\<in> next_slot_set q (cdt_list s) (cdt s) \\<longrightarrow> cdt s q \\<noteq> Some p\"\n    \"slot \\<in> descendants_of p (cdt s)\" \"valid_mdb s\" \"valid_list s\"\n  shows \"next_sib_2 slot p s = Some next\"\n  using assms\n  apply(induct slot rule: next_sib_2_pinduct[where s=s and p=p])\n    apply(simp)\n    apply(case_tac \"next_slot slot (cdt_list s) (cdt s)\")\n     apply(fastforce simp: next_slot_set_def dest: tranclD2)\n    apply(atomize)\n    apply(erule_tac x=a in allE)\n    apply(simp)\n    apply(case_tac \"a=next\")\n     apply(simp add: next_sib_2_termination)\n    apply(erule impE)\n     apply(rule notI)\n     apply(erule_tac x=a in allE)\n     apply(erule impE)\n      apply(rule conjI)\n       apply(fastforce simp: next_slot_set_def)\n      apply(fastforce dest: rtranclD tranclD2 simp: next_slot_set_def)\n     apply(simp)\n    apply(elim impE)\n       apply(fastforce simp: next_slot_set_def dest: rtranclD tranclD2)\n      apply(intro allI impI notI)\n      apply(erule_tac x=q in allE)\n      apply(erule impE)\n       apply(fastforce intro: trancl_into_trancl simp: next_slot_set_def)\n      apply(simp)\n     apply(drule(5) next_slot_set_in_desc, simp)\n    apply(simp add: next_sib_2_termination)\n    apply(erule_tac x=a in allE, erule impE)\n     apply(rule conjI)\n      apply(fastforce simp: next_slot_set_def)\n     apply(fastforce simp: next_slot_set_def dest: tranclD2 rtranclD)\n    using assms\n    apply(simp)+\n    done\n\nlemma between_next_sib_2_not_sib:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  assumes\n  \"next_sib_2 slot p s = Some next\" \"q \\<in> next_slot_set slot (cdt_list s) (cdt s)\"\n  \"next \\<in> next_slot_set q (cdt_list s) (cdt s)\" \"valid_list s\" \"valid_mdb s\"\n  shows \"cdt s q \\<noteq> Some p\"\n  using assms\n  apply(subgoal_tac \"no_mloop (cdt s)\")\n   prefer 2\n   apply(simp add: valid_mdb_def)\n  apply(frule finite_depth)\n  apply(rule notI)\n  apply(case_tac \"next_sib_2 slot p s = Some q\")\n   apply(simp add: next_slot_no_loop)\n  apply(subgoal_tac \"\\<exists>q'. next_sib_2 slot p s = Some q' \\<and>\n                   q \\<in> next_slot_set q' (cdt_list s) (cdt s)\")\n   prefer 2\n   apply(rule_tac P=\"\\<lambda>q'. cdt s q' = Some p \\<and>\n    q' \\<in> next_slot_set slot (cdt_list s) (cdt s) \\<and>\n    (\\<forall>q. q \\<in> next_slot_set slot (cdt_list s) (cdt s) \\<and>\n    q' \\<in> next_slot_set q (cdt_list s) (cdt s) \\<longrightarrow> cdt s q \\<noteq> Some p) \\<and>\n    q \\<in> next_slot_set q' (cdt_list s) (cdt s)\" in ex_imp)\n    apply(simp)\n    apply(intro allI impI)\n    apply(elim conjE)\n    apply(drule(2) next_sib_2I)\n       apply(simp add: next_sib_2_termination split: if_split_asm)\n      apply(simp)\n     apply(simp)\n    apply(simp)\n   apply(simp)\n   apply(induct slot rule: next_slot_induct[where s=s])\n      apply(fastforce simp: next_slot_set_def dest: tranclD2)\n     apply(simp)\n     apply(case_tac \"y=next\")\n      apply(simp add: next_slot_set_def)\n      apply(drule_tac x=q in tranclD2)\n      apply(simp)\n      apply(drule(1) rtrancl_trancl_trancl)\n      apply(drule(2) next_slot_no_loop[simplified next_slot_set_def, where x=q])\n      apply(simp)\n     apply(case_tac \"y=q\")\n      apply(simp add: next_sib_2_termination split: if_split_asm)\n     apply(atomize)\n     apply(elim impE)\n       apply(simp add: next_sib_2_termination split: if_split_asm)\n      apply(fastforce simp: next_slot_set_def dest: rtranclD tranclD2)\n     apply(elim exE conjE)\n     apply(rule_tac x=xa in exI)\n     apply(simp)\n     apply(rule conjI)\n      apply(simp add: next_slot_set_def)\n      apply(rule trancl_into_trancl)\n       apply(simp)+\n     apply(intro allI impI)\n     apply(erule_tac x=qa in allE)\n     apply(simp)\n     apply(case_tac \"qa=y\")\n      apply(simp add: next_sib_2_termination split: if_split_asm)\n     apply(simp add: next_slot_set_def)\n     apply(erule conjE)\n     apply(drule_tac x=qa and y=x in tranclD2, simp)\n     apply(drule rtranclD, simp)\n    using assms\n    apply(simp_all add: next_slot_set_def)\n  apply(drule(1) trancl_trans[where y=\"next\"])\n  apply(fastforce dest: next_slot_no_loop simp: next_slot_set_def)\n  done\n\nlemma next_sib_set_in_next_slot_set:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"\\<lbrakk>next \\<in> next_sib_set slot (cdt_list s) (cdt s); valid_list s; valid_mdb s\\<rbrakk>\n    \\<Longrightarrow> next \\<in> next_slot_set slot (cdt_list s) (cdt s)\"\n  apply(simp add: next_sib_set_def)\n  apply(induct \"next\" slot rule: trancl.induct)\n   apply(simp add: next_sib_in_next_slot_set)\n  apply(simp add: next_slot_set_def)\n  apply(rule trancl_trans)\n   apply(simp)\n  apply(drule(2) next_sib_in_next_slot_set)\n  apply(simp add: next_slot_set_def)\n  done\n\nlemma next_sib_2_eq_next_sib:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"\\<lbrakk>next_sib_2 slot p s = Some next; valid_list s; valid_mdb s; cdt s slot = Some p\\<rbrakk>\n    \\<Longrightarrow> next_sib slot (cdt_list s) (cdt s) = Some next\"\n  apply(frule finite_depth, subgoal_tac \"no_mloop (cdt s)\")\n   prefer 2\n   apply(simp add: valid_mdb_def)\n  apply(frule(2) next_sib_2_in_next_slot_set)\n  apply(frule(2) next_sib_2_sib)\n  apply(frule(5) next_slot_set_after_in_list)\n  apply(simp add: next_sib_set_def)\n  apply(drule tranclD2)\n  apply(elim exE conjE)\n  apply(simp)\n  apply(drule rtranclD)\n  apply(erule disjE, simp)\n  apply(frule_tac q=z in between_next_sib_2_not_sib)\n      apply(rule next_sib_in_next_slot_set)\n        apply(simp, simp, simp)\n     apply(rule next_sib_set_in_next_slot_set)\n       apply(fastforce simp: next_sib_set_def, simp, simp)\n    apply(simp, simp)\n  apply(fastforce dest: next_sib_same_parent)\n  done\n\nlemma next_sib_def2:\n  notes split_paired_All[simp del] split_paired_Ex[simp del]\n  shows \"\\<lbrakk>valid_mdb s; valid_list s; cdt s slot = Some p\\<rbrakk>\n    \\<Longrightarrow> next_sib_2 slot p s = next_sib slot (cdt_list s) (cdt s)\"\n  apply(case_tac \"next_sib_2 slot p s\")\n   apply(fastforce dest: next_sib_2_None_next_sib)\n  apply(fastforce dest: next_sib_2_eq_next_sib)\n  done\n\nend\n\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/l4v/proof/invariant-abstract/Deterministic_AI.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6076631698328916, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.2943399374156755}}
{"text": "theory Fused_Resource imports\n  Fold_Spmf\nbegin\n\n(* TODO: move these somewhere *)\ncontext includes \\<I>.lifting begin\nlift_definition e\\<I> :: \"('a, 'b) \\<I> \\<Rightarrow> ('a, 'b \\<times> 'c) \\<I>\" is \"\\<lambda>\\<I> x. \\<I> x \\<times> UNIV\" .\n\nlemma outs_\\<I>_e\\<I>[simp]: \"outs_\\<I> (e\\<I> \\<I>) = outs_\\<I> \\<I>\"\n  by transfer simp\n\nlemma responses_\\<I>_e\\<I> [simp]: \"responses_\\<I> (e\\<I> \\<I>) x = responses_\\<I> \\<I> x \\<times> UNIV\"\n  by transfer simp\n\nlemma e\\<I>_map_\\<I>: \"e\\<I> (map_\\<I> f g \\<I>) = map_\\<I> f (apfst g) (e\\<I> \\<I>)\"\n  by transfer(auto simp add: fun_eq_iff intro: rev_image_eqI)\n\nlemma e\\<I>_inverse [simp]: \"map_\\<I> id fst (e\\<I> \\<I>) = \\<I>\"\n  by transfer auto\nend\nlifting_update \\<I>.lifting\nlifting_forget \\<I>.lifting\n\n\nsection \\<open>Fused Resource\\<close>\n\nsubsection \\<open>Event Oracles -- they generate events\\<close>\n\ntype_synonym \n  ('state, 'event, 'input, 'output) eoracle = \"('state, 'input, 'output \\<times> 'event list) oracle'\" \n\ndefinition\n  parallel_eoracle :: \"\n    ('s1, 'e1, 'i1, 'o1) eoracle \\<Rightarrow> ('s2, 'e2, 'i2, 'o2) eoracle \\<Rightarrow>\n      ('s1 \\<times> 's2, 'e1 + 'e2, 'i1 + 'i2, 'o1 + 'o2) eoracle\"\n  where\n    \"parallel_eoracle eoracle1 eoracle2 state \\<equiv>\n       comp\n        (map_spmf \n          (map_prod \n            (case_sum \n              (map_prod Inl (map Inl)) \n              (map_prod Inr (map Inr))) \n            id))\n        (parallel_oracle eoracle1 eoracle2 state)\"\n\ndefinition\n  plus_eoracle :: \"\n    ('s, 'e1, 'i1, 'o1) eoracle \\<Rightarrow> ('s, 'e2, 'i2, 'o2) eoracle \\<Rightarrow>\n      ('s, 'e1 + 'e2, 'i1 + 'i2, 'o1 + 'o2) eoracle\"\n  where\n    \"plus_eoracle eoracle1 eoracle2 state \\<equiv>\n       comp\n        (map_spmf \n          (map_prod \n            (case_sum \n              (map_prod Inl (map Inl)) \n              (map_prod Inr (map Inr))) \n            id))\n        (plus_oracle eoracle1 eoracle2 state)\"\n\ndefinition\n  translate_eoracle :: \"\n    ('s_event, 'e1, 'e2 list) oracle' \\<Rightarrow> ('s_event \\<times> 's, 'e1, 'i, 'o) eoracle \\<Rightarrow>\n      ('s_event \\<times> 's, 'e2, 'i, 'o) eoracle\"\n  where\n    \"translate_eoracle translator eoracle state inp \\<equiv> \n      bind_spmf\n        (eoracle state inp)\n        (\\<lambda>((out, e_in), s).\n          let conc = (\\<lambda>(es, st) e. map_spmf (map_prod ((@) es) id) (translator st e)) in do {\n          (e_out, s_event) \\<leftarrow> foldl_spmf conc (return_spmf ([], fst s)) e_in;\n          return_spmf ((out, e_out), s_event, snd s)\n        })\"\n\n\nsubsection \\<open>Event Handlers -- they absorb (and silently handle) events\\<close>\n\ntype_synonym\n  ('state, 'event) handler = \"'state \\<Rightarrow> 'event \\<Rightarrow> 'state spmf\"\n\nfun\n  parallel_handler :: \"('s1, 'e1) handler \\<Rightarrow> ('s2, 'e2) handler \\<Rightarrow> ('s1 \\<times> 's2, 'e1 + 'e2) handler\"\n  where\n    \"parallel_handler left _ s (Inl e1) = map_spmf (\\<lambda>s1'. (s1', snd s)) (left (fst s) e1)\"\n  | \"parallel_handler _ right s (Inr e2) = map_spmf (\\<lambda>s2'. (fst s, s2')) (right (snd s) e2)\"\n\ndefinition\n  plus_handler :: \"('s, 'e1) handler \\<Rightarrow> ('s, 'e2) handler \\<Rightarrow> ('s, 'e1 + 'e2) handler\"\n  where\n    \"plus_handler left right s \\<equiv> case_sum (left s) (right s)\"\n\nlemma parallel_handler_left:\n  \"map_fun id (map_fun Inl id) (parallel_handler left right) = \n    (\\<lambda>(s_l, s_r) q. map_spmf (\\<lambda>s_l'. (s_l', s_r)) (left s_l q))\"\n  by force\n\nlemma parallel_handler_right:\n  \"map_fun id (map_fun Inr id) (parallel_handler left right) = \n    (\\<lambda>(s_l, s_r) q. map_spmf (\\<lambda>s_r'. (s_l, s_r')) (right s_r q))\"\n  by force\n\nlemma in_set_spmf_parallel_handler:\n  \"s' \\<in> set_spmf (parallel_handler left right s x) \\<longleftrightarrow>\n  (case x of Inl e \\<Rightarrow> fst s' \\<in> set_spmf (left (fst s) e) \\<and> snd s' = snd s\n    | Inr e \\<Rightarrow> snd s' \\<in> set_spmf (right (snd s) e) \\<and> fst s' = fst s)\"\n  by(cases s; cases s'; auto split: sum.split)\n\nsubsection \\<open>Fused Resource Construction\\<close>\n\ncodatatype \n  ('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core =\n    Core\n      (cpoke: \"('s_core, 'event) handler\")\n      (cfunc_adv: \"('s_core, 'iadv_core, 'oadv_core) oracle'\")\n      (cfunc_usr: \"('s_core, 'iusr_core, 'ousr_core) oracle'\")\n\ndeclare core.sel_transfer[transfer_rule del]\ndeclare core.ctr_transfer[transfer_rule del]\ndeclare core.case_transfer[transfer_rule del]\n\ncontext \n  includes lifting_syntax \nbegin\n\ninductive \n  rel_core':: \"\n    ('s_core \\<Rightarrow> 's_core' \\<Rightarrow> bool) \\<Rightarrow> \n    ('event \\<Rightarrow> 'event' \\<Rightarrow> bool) \\<Rightarrow> \n    ('iadv_core \\<Rightarrow> 'iadv_core' \\<Rightarrow> bool) \\<Rightarrow>\n    ('iusr_core \\<Rightarrow> 'iusr_core' \\<Rightarrow> bool) \\<Rightarrow> \n    ('oadv_core \\<Rightarrow> 'oadv_core' \\<Rightarrow> bool) \\<Rightarrow> \n    ('ousr_core \\<Rightarrow> 'ousr_core' \\<Rightarrow> bool) \\<Rightarrow>\n    ('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core \\<Rightarrow> \n    ('s_core', 'event', 'iadv_core', 'iusr_core', 'oadv_core', 'ousr_core') core \\<Rightarrow> bool\"\n  for S E IA IU OA OU\n  where \"rel_core' S E IA IU OA OU (Core cpoke cfunc_adv cfunc_usr) (Core cpoke' cfunc_adv' cfunc_usr')\"\n  if \n    \"(S ===> E ===> rel_spmf S) cpoke cpoke'\" and \n    \"(S ===> IA ===> rel_spmf (rel_prod OA S)) cfunc_adv cfunc_adv'\" and \n    \"(S ===> IU ===> rel_spmf (rel_prod OU S)) cfunc_usr cfunc_usr'\"\n  for cpoke cfunc_adv cfunc_usr\n\ninductive_simps \n  rel_core'_simps [simp]: \n    \"rel_core' S E IA IU OA OU (Core cpoke' cfunc_adv' cfunc_usr') (Core cpoke'' cfunc_adv'' cfunc_usr'')\"\n\nlemma \n  rel_core'_eq [relator_eq]:\n    \"rel_core' (=) (=) (=) (=) (=) (=) = (=)\"\n  apply(intro ext)\n  subgoal for x y by(cases x; cases y)(auto simp add: fun_eq_iff rel_fun_def relator_eq)\n  done\n\nlemma \n  rel_core'_mono [relator_mono]:\n    \"rel_core' S E IA IU OA OU \\<le> rel_core' S E' IA' IU' OA' OU'\"\n  if \"E' \\<le> E\" \"IA' \\<le> IA\" \"IU' \\<le> IU\" \"OA \\<le> OA'\" \"OU \\<le> OU'\"\n  apply(rule predicate2I)\n  subgoal for x y\n    apply(cases x; cases y; clarsimp; intro conjI)\n      apply(erule rel_fun_mono rel_spmf_mono prod.rel_mono[THEN predicate2D, rotated -1] |\n        rule impI that order_refl | erule that[THEN predicate2D] | erule rel_spmf_mono | assumption)+\n    done\n  done\n\nlemma \n  cpoke_parametric [transfer_rule]:\n    \"(rel_core' S E IA IU OA OU ===> S ===> E ===> rel_spmf S) cpoke cpoke\"\n  by(rule rel_funI; erule rel_core'.cases; simp)\n\nlemma \n  cfunc_adv_parametric [transfer_rule]:\n    \"(rel_core' S E IA IU OA OU ===> S ===> IA ===> rel_spmf (rel_prod OA S)) cfunc_adv cfunc_adv\"\n  by(rule rel_funI; erule rel_core'.cases; simp)\n\nlemma \n  cfunc_usr_parametric [transfer_rule]:\n    \"(rel_core' S E IA IU OA OU ===> S ===> IU ===> rel_spmf (rel_prod OU S)) cfunc_usr cfunc_usr\"\n  by(rule rel_funI; erule rel_core'.cases; simp)\n\nlemma \n  Core_parametric [transfer_rule]:\n    \"((S ===> E ===> rel_spmf S) ===> (S ===> IA ===> rel_spmf (rel_prod OA S)) ===> (S ===> IU ===> rel_spmf (rel_prod OU S))\n   ===> rel_core' S E IA IU OA OU) Core Core\"\n  by(rule rel_funI)+ simp\n\nlemma \n  case_core_parametric [transfer_rule]:\n    \"(((S ===> E ===> rel_spmf S) ===> \n        (S ===> IA ===> rel_spmf (rel_prod OA S)) ===> \n        (S ===> IU ===> rel_spmf (rel_prod OU S)) ===> X) ===> \n      rel_core' S E IA IU OA OU ===> X) case_core case_core\"\n  by(rule rel_funI)+(auto 4 4 split: core.split dest: rel_funD)\n\nlemma \n  corec_core_parametric [transfer_rule]:\n    \"((X ===> S ===> E ===> rel_spmf S) ===> \n      (X ===> S ===> IA ===> rel_spmf (rel_prod OA S)) ===> \n      (X ===> S ===> IU ===> rel_spmf (rel_prod OU S)) ===> \n      X ===> rel_core' S E IA IU OA OU) corec_core corec_core\"\n  by(rule rel_funI)+(auto simp add: core.corec dest: rel_funD)\n\nprimcorec map_core' ::\n   \"('event' \\<Rightarrow> 'event) \\<Rightarrow> \n    ('iadv_core' \\<Rightarrow> 'iadv_core) \\<Rightarrow>\n    ('iusr_core' \\<Rightarrow> 'iusr_core) \\<Rightarrow> \n    ('oadv_core \\<Rightarrow> 'oadv_core') \\<Rightarrow> \n    ('ousr_core \\<Rightarrow> 'ousr_core') \\<Rightarrow>\n    ('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core \\<Rightarrow> \n    ('s_core, 'event', 'iadv_core', 'iusr_core', 'oadv_core', 'ousr_core') core\"\n   where\n  \"cpoke (map_core' e ia iu oa ou core) = (id ---> e ---> id) (cpoke core)\"\n| \"cfunc_adv (map_core' e ia iu oa ou core) = (id ---> ia ---> map_spmf (map_prod oa id)) (cfunc_adv core)\"\n| \"cfunc_usr (map_core' e ia iu oa ou core) = (id ---> iu ---> map_spmf (map_prod ou id)) (cfunc_usr core)\"\n\nlemmas map_core'_simps [simp] = map_core'.ctr[where core=\"Core _ _ _\", simplified]\n\nparametric_constant map_core'_parametric[transfer_rule]: map_core'_def\n\nlemma core'_rel_Grp:\n  \"rel_core' (=) (BNF_Def.Grp UNIV e)\\<inverse>\\<inverse> (BNF_Def.Grp UNIV ia)\\<inverse>\\<inverse> (BNF_Def.Grp UNIV iu)\\<inverse>\\<inverse> (BNF_Def.Grp UNIV oa) (BNF_Def.Grp UNIV ou)\n   = BNF_Def.Grp UNIV (map_core' e ia iu oa ou)\"\n  apply(intro ext)\n  subgoal for x y\n    apply(cases x; cases y; clarsimp)\n    apply(subst (2 4 6) eq_alt_conversep)\n    apply(subst (2 3 4) eq_alt)\n    apply(simp add: pmf.rel_Grp option.rel_Grp prod.rel_Grp rel_fun_conversep_grp_grp)\n    apply(auto simp add: Grp_def spmf.map_id[abs_def] id_def[symmetric])\n    done\n  done\n\nend\n\ninductive WT_core :: \"('iadv, 'oadv) \\<I> \\<Rightarrow> ('iusr, 'ousr) \\<I> \\<Rightarrow> ('s \\<Rightarrow> bool) \\<Rightarrow> ('s, 'event, 'iadv, 'iusr, 'oadv, 'ousr) core \\<Rightarrow> bool\"\n  for \\<I>_adv \\<I>_usr I core where\n  \"WT_core \\<I>_adv \\<I>_usr I core\" if\n  \"\\<And>s e s'. \\<lbrakk> s' \\<in> set_spmf (cpoke core s e); I s \\<rbrakk> \\<Longrightarrow> I s'\"\n  \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> set_spmf (cfunc_adv core s x); x \\<in> outs_\\<I> \\<I>_adv; I s \\<rbrakk> \\<Longrightarrow> y \\<in> responses_\\<I> \\<I>_adv x \\<and> I s'\"\n  \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> set_spmf (cfunc_usr core s x); x \\<in> outs_\\<I> \\<I>_usr; I s \\<rbrakk> \\<Longrightarrow> y \\<in> responses_\\<I> \\<I>_usr x \\<and> I s'\"\n\nlemma WT_coreD:\n  assumes \"WT_core \\<I>_adv \\<I>_usr I core\"\n  shows WT_coreD_cpoke: \"\\<And>s e s'. \\<lbrakk> s' \\<in> set_spmf (cpoke core s e); I s \\<rbrakk> \\<Longrightarrow> I s'\"\n    and WT_coreD_cfunc_adv: \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> set_spmf (cfunc_adv core s x); x \\<in> outs_\\<I> \\<I>_adv; I s \\<rbrakk> \\<Longrightarrow> y \\<in> responses_\\<I> \\<I>_adv x \\<and> I s'\"\n    and WT_coreD_cfund_usr: \"\\<And>s x y s'. \\<lbrakk> (y, s') \\<in> set_spmf (cfunc_usr core s x); x \\<in> outs_\\<I> \\<I>_usr; I s \\<rbrakk> \\<Longrightarrow> y \\<in> responses_\\<I> \\<I>_usr x \\<and> I s'\"\n  using assms by(auto elim!: WT_core.cases)\n\nlemma WT_coreD_foldl_spmf_cpoke:\n  assumes \"WT_core \\<I>_adv \\<I>_usr I core\"\n    and \"s' \\<in> set_spmf (foldl_spmf (cpoke core) p es)\"\n    and \"\\<forall>s \\<in> set_spmf p. I s\"\n  shows \"I s'\"\n  using assms(2, 3)\n  by(induction es arbitrary: p)(fastforce dest: WT_coreD_cpoke[OF assms(1)] simp add: bind_UNION)+\n\nlemma WT_core_trivial:\n  assumes adv: \"\\<And>s. \\<I>_adv \\<turnstile>c cfunc_adv core s \\<surd>\"\n    and usr: \"\\<And>s. \\<I>_usr \\<turnstile>c cfunc_usr core s \\<surd>\"\n  shows \"WT_core \\<I>_adv \\<I>_usr (\\<lambda>_. True) core\"\n  by(rule WT_core.intros)(auto dest: assms[THEN WT_calleeD])\n\ncodatatype \n  ('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme =\n    Rest\n      (rinit: \"'more\")\n      (rfunc_adv: \"('s_rest, 'event, 'iadv_rest, 'oadv_rest) eoracle\")\n      (rfunc_usr: \"('s_rest, 'event, 'iusr_rest, 'ousr_rest) eoracle\")\n\ndeclare rest_scheme.sel_transfer[transfer_rule del]\ndeclare rest_scheme.ctr_transfer[transfer_rule del]\ndeclare rest_scheme.case_transfer[transfer_rule del]\n\ncontext \n  includes lifting_syntax \nbegin\n\ninductive \n  rel_rest':: \"\n    ('s_rest \\<Rightarrow> 's_rest' \\<Rightarrow> bool) \\<Rightarrow> \n    ('event \\<Rightarrow> 'event' \\<Rightarrow> bool) \\<Rightarrow> \n    ('iadv_rest \\<Rightarrow> 'iadv_rest' \\<Rightarrow> bool) \\<Rightarrow>\n    ('iusr_rest \\<Rightarrow> 'iusr_rest' \\<Rightarrow> bool) \\<Rightarrow> \n    ('oadv_rest \\<Rightarrow> 'oadv_rest' \\<Rightarrow> bool) \\<Rightarrow> \n    ('ousr_rest \\<Rightarrow> 'ousr_rest' \\<Rightarrow> bool) \\<Rightarrow>\n    ('more \\<Rightarrow> 'more' \\<Rightarrow> bool) \\<Rightarrow> \n    ('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme \\<Rightarrow> \n    ('s_rest', 'event', 'iadv_rest', 'iusr_rest', 'oadv_rest', 'ousr_rest', 'more') rest_scheme \\<Rightarrow> bool\"\n  for S E IA IU OA OU M\n  where \"rel_rest' S E IA IU OA OU M (Rest rinit rfunc_adv rfunc_usr) (Rest rinit' rfunc_adv' rfunc_usr')\"\n  if \n    \"M rinit rinit'\" and \n    \"(S ===> IA ===> rel_spmf (rel_prod (rel_prod OA (list_all2 E)) S)) rfunc_adv rfunc_adv'\" and \n    \"(S ===> IU ===> rel_spmf (rel_prod (rel_prod OU (list_all2 E)) S)) rfunc_usr rfunc_usr'\"\n  for rinit rfunc_adv rfunc_usr\n\ninductive_simps \n  rel_rest'_simps [simp]: \n    \"rel_rest' S E IA IU OA OU M (Rest rinit' rfunc_adv' rfunc_usr') (Rest rinit'' rfunc_adv'' rfunc_usr'')\"\n\nlemma \n  rel_rest'_eq [relator_eq]:\n    \"rel_rest' (=) (=) (=) (=) (=) (=) (=) = (=)\"\n  apply(intro ext)\n  subgoal for x y by(cases x; cases y)(auto simp add: fun_eq_iff rel_fun_def relator_eq)\n  done\n\nlemma \n  rel_rest'_mono [relator_mono]:\n    \"rel_rest' S E IA IU OA OU M \\<le> rel_rest' S E' IA' IU' OA' OU' M'\"\n  if \"E \\<le> E'\" \"IA' \\<le> IA\" \"IU' \\<le> IU\" \"OA \\<le> OA'\" \"OU \\<le> OU'\" \"M \\<le> M'\"\n  apply(rule predicate2I)\n  subgoal for x y\n    apply(cases x; cases y; clarsimp; intro conjI)\n      apply(erule rel_fun_mono rel_spmf_mono prod.rel_mono[THEN predicate2D, rotated -1] |\n        rule impI that order_refl prod.rel_mono list.rel_mono | erule that[THEN predicate2D] | erule rel_spmf_mono | assumption)+\n    done\n  done\n\nlemma rel_rest'_sel: \"rel_rest' S E IA IU OA OU M rest1 rest2\"\n  if \"M (rinit rest1) (rinit rest2)\"\n  and \"(S ===> IA ===> rel_spmf (rel_prod (rel_prod OA (list_all2 E)) S)) (rfunc_adv rest1) (rfunc_adv rest2)\" \n  and \"(S ===> IU ===> rel_spmf (rel_prod (rel_prod OU (list_all2 E)) S)) (rfunc_usr rest1) (rfunc_usr rest2)\"\n  using that by(cases rest1; cases rest2) simp\n\nlemma rinit_parametric [transfer_rule]: \"(rel_rest' S E IA IU OA OU M ===> M) rinit rinit\"\n  by(rule rel_funI; erule rel_rest'.cases; simp)\n\nlemma rfunc_adv_parametric [transfer_rule]:\n  \"(rel_rest' S E IA IU OA OU M ===> S ===> IA ===> rel_spmf (rel_prod (rel_prod OA (list_all2 E)) S)) rfunc_adv rfunc_adv\"\n  by(rule rel_funI; erule rel_rest'.cases; simp)\n\nlemma rfunc_usr_parametric [transfer_rule]:\n  \"(rel_rest' S E IA IU OA OU M ===> S ===> IU ===> rel_spmf (rel_prod (rel_prod OU (list_all2 E)) S)) rfunc_usr rfunc_usr\"\n  by(rule rel_funI; erule rel_rest'.cases; simp)\n\nlemma Rest_parametric [transfer_rule]:\n  \"(M ===> (S ===> IA ===> rel_spmf (rel_prod (rel_prod OA (list_all2 E)) S))\n    ===> (S ===> IU ===> rel_spmf (rel_prod (rel_prod OU (list_all2 E)) S))\n   ===> rel_rest' S E IA IU OA OU M) Rest Rest\"\n  by(rule rel_funI)+ simp\n\nlemma case_rest_scheme_parametric [transfer_rule]:\n  \"((M ===> \n    (S ===> IA ===> rel_spmf (rel_prod (rel_prod OA (list_all2 E)) S)) ===> \n    (S ===> IU ===> rel_spmf (rel_prod (rel_prod OU (list_all2 E)) S)) ===> X) ===> \n  rel_rest' S E IA IU OA OU M ===> X) case_rest_scheme case_rest_scheme\"\n  by(rule rel_funI)+(auto 4 4 split: rest_scheme.split dest: rel_funD)\n\nlemma corec_rest_scheme_parametric [transfer_rule]:\n    \"((X ===> M) ===> \n      (X ===> S ===> IA ===> rel_spmf (rel_prod (rel_prod OA (list_all2 E)) S)) ===> \n      (X ===> S ===> IU ===> rel_spmf (rel_prod (rel_prod OU (list_all2 E)) S)) ===> \n      X ===> rel_rest' S E IA IU OA OU M) corec_rest_scheme corec_rest_scheme\"\n  by(rule rel_funI)+(auto simp add: rest_scheme.corec dest: rel_funD)\n\nprimcorec map_rest' ::\n   \"('event \\<Rightarrow> 'event') \\<Rightarrow> \n    ('iadv_rest' \\<Rightarrow> 'iadv_rest) \\<Rightarrow>\n    ('iusr_rest' \\<Rightarrow> 'iusr_rest) \\<Rightarrow> \n    ('oadv_rest \\<Rightarrow> 'oadv_rest') \\<Rightarrow> \n    ('ousr_rest \\<Rightarrow> 'ousr_rest') \\<Rightarrow>\n    ('more \\<Rightarrow> 'more') \\<Rightarrow>\n    ('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme \\<Rightarrow> \n    ('s_rest, 'event', 'iadv_rest', 'iusr_rest', 'oadv_rest', 'ousr_rest', 'more') rest_scheme\"\n   where\n  \"rinit (map_rest' e ia iu oa ou m rest) = m (rinit rest)\"\n| \"rfunc_adv (map_rest' e ia iu oa ou m rest) =\n   (id ---> ia ---> map_spmf (map_prod (map_prod oa (map e)) id)) (rfunc_adv rest)\"\n| \"rfunc_usr (map_rest' e ia iu oa ou m rest) =\n   (id ---> iu ---> map_spmf (map_prod (map_prod ou (map e)) id)) (rfunc_usr rest)\"\n\nlemmas map_rest'_simps [simp] = map_rest'.ctr[where rest=\"Rest _ _ _\", simplified]\n\nparametric_constant map_rest'_parametric[transfer_rule]: map_rest'_def\n\nlemma rest'_rel_Grp:\n  \"rel_rest' (=) (BNF_Def.Grp UNIV e) (BNF_Def.Grp UNIV ia)\\<inverse>\\<inverse> (BNF_Def.Grp UNIV iu)\\<inverse>\\<inverse> (BNF_Def.Grp UNIV oa) (BNF_Def.Grp UNIV ou) (BNF_Def.Grp UNIV m)\n   = BNF_Def.Grp UNIV (map_rest' e ia iu oa ou m)\"\n  apply(intro ext)\n  subgoal for x y\n    apply(cases x; cases y; clarsimp)\n    apply(subst (2 4) eq_alt_conversep)\n    apply(subst (2 3) eq_alt)\n    apply(simp add: pmf.rel_Grp list.rel_Grp option.rel_Grp prod.rel_Grp rel_fun_conversep_grp_grp)\n    apply(auto simp add: Grp_def spmf.map_id[abs_def] id_def[symmetric])\n    done\n  done\n\nend\n\ntype_synonym \n  ('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest) rest_wstate =\n    \"('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 's_rest) rest_scheme\"\n\ninductive WT_rest :: \"('iadv, 'oadv) \\<I> \\<Rightarrow> ('iusr, 'ousr) \\<I> \\<Rightarrow> ('s \\<Rightarrow> bool) \\<Rightarrow> ('s, 'event, 'iadv, 'iusr, 'oadv, 'ousr) rest_wstate \\<Rightarrow> bool\"\n  for \\<I>_adv \\<I>_usr I rest where\n  \"WT_rest \\<I>_adv \\<I>_usr I rest\" if\n  \"\\<And>s x y es s'. \\<lbrakk> ((y, es), s') \\<in> set_spmf (rfunc_adv rest s x); x \\<in> outs_\\<I> \\<I>_adv; I s \\<rbrakk> \\<Longrightarrow> y \\<in> responses_\\<I> \\<I>_adv x \\<and> I s'\"\n  \"\\<And>s x y es s'. \\<lbrakk> ((y, es), s') \\<in> set_spmf (rfunc_usr rest s x); x \\<in> outs_\\<I> \\<I>_usr; I s \\<rbrakk> \\<Longrightarrow> y \\<in> responses_\\<I> \\<I>_usr x \\<and> I s'\"\n  \"I (rinit rest)\"\n\nlemma WT_restD:\n  assumes \"WT_rest \\<I>_adv \\<I>_usr I rest\"\n  shows WT_restD_rfunc_adv: \"\\<And>s x y es s'. \\<lbrakk> ((y, es), s') \\<in> set_spmf (rfunc_adv rest s x); x \\<in> outs_\\<I> \\<I>_adv; I s \\<rbrakk> \\<Longrightarrow> y \\<in> responses_\\<I> \\<I>_adv x \\<and> I s'\"\n    and WT_restD_rfunc_usr: \"\\<And>s x y es s'. \\<lbrakk> ((y, es), s') \\<in> set_spmf (rfunc_usr rest s x); x \\<in> outs_\\<I> \\<I>_usr; I s \\<rbrakk> \\<Longrightarrow> y \\<in> responses_\\<I> \\<I>_usr x \\<and> I s'\"\n    and WT_restD_rinit: \"I (rinit rest)\"\n  using assms by(auto elim!: WT_rest.cases)\n\nabbreviation\n  fuse_cfunc :: \"\n    ('o \\<Rightarrow> 'x) \\<Rightarrow> ('s_core, 'i, 'o) oracle' \\<Rightarrow> ('s_core \\<times> 's_rest, 'i , 'x) oracle'\"\n  where\n  \"fuse_cfunc redirect cfunc state inp  \\<equiv> do {\n    let handle = map_prod redirect (prod.swap o Pair (snd state));\n    (os_cfunc :: 'o \\<times> 's_core) \\<leftarrow> cfunc (fst state) inp;\n    return_spmf (handle os_cfunc)\n  }\"\n\nabbreviation\n  fuse_rfunc :: \"\n    ('o \\<Rightarrow> 'x) \\<Rightarrow> ('s_rest, 'e, 'i, 'o) eoracle \\<Rightarrow> ('s_core, 'e) handler \\<Rightarrow> \n      ('s_core \\<times> 's_rest, 'i , 'x) oracle'\"\n  where\n  \"fuse_rfunc redirect rfunc notify state inp \\<equiv> \n    bind_spmf \n      (rfunc (snd state) inp)\n      (\\<lambda>((o_rfunc, e_lst), s_rfunc). \n        bind_spmf \n          (foldl_spmf notify (return_spmf (fst state)) e_lst)\n          (\\<lambda>s_notify. return_spmf (redirect o_rfunc, s_notify, s_rfunc)))\n  \"\n\n\nlocale fused_resource =\n  fixes \n    core :: \"('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core\" and \n    core_init :: 's_core\nbegin\n\nfun\n  fuse :: \"\n    ('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'm) rest_scheme \\<Rightarrow>\n    ('s_core \\<times> 's_rest, \n      ('iadv_core + 'iadv_rest) + ('iusr_core + 'iusr_rest),  \n      ('oadv_core + 'oadv_rest) + ('ousr_core + 'ousr_rest)) oracle'\" \n  where\n    \"fuse rest state (Inl (Inl iadv_core)) = \n      fuse_cfunc (Inl o Inl) (cfunc_adv core) state iadv_core\"\n  | \"fuse rest state (Inl (Inr iadv_rest)) = \n      fuse_rfunc (Inl o Inr) (rfunc_adv rest) (cpoke core) state iadv_rest\"\n  | \"fuse rest state (Inr (Inl iusr_core)) = \n      fuse_cfunc (Inr o Inl) (cfunc_usr core) state iusr_core\"\n  | \"fuse rest state (Inr (Inr iusr_rest)) = \n      fuse_rfunc (Inr o Inr) (rfunc_usr rest) (cpoke core) state iusr_rest\"\n\ncase_of_simps fuse_case: fused_resource.fuse.simps\n\nlemma callee_invariant_on_fuse:\n  assumes \"WT_core \\<I>_adv_core \\<I>_usr_core I_core core\" \n    and \"WT_rest \\<I>_adv_rest \\<I>_usr_rest I_rest rest\"\n  shows \"callee_invariant_on (fuse rest) (pred_prod I_core I_rest) ((\\<I>_adv_core \\<oplus>\\<^sub>\\<I> \\<I>_adv_rest) \\<oplus>\\<^sub>\\<I> (\\<I>_usr_core \\<oplus>\\<^sub>\\<I> \\<I>_usr_rest))\"\nproof(unfold_locales, goal_cases)\n  case (1 s x y s')\n  then show ?case using assms\n    by(cases s; cases s')(auto 4 4 dest: WT_restD WT_coreD WT_coreD_foldl_spmf_cpoke)\nnext\n  case (2 s)\n  show ?case\n    apply(rule WT_calleeI)\n    subgoal for x y s' using 2 assms\n      by (cases \"(rest, s, x)\" rule: fuse.cases) (auto simp add: pred_prod_beta dest: WT_restD WT_coreD )\n    done\nqed\n\ndefinition \n  resource :: \"\n    ('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest) rest_wstate \\<Rightarrow>\n    (('iadv_core + 'iadv_rest) + ('iusr_core + 'iusr_rest),\n      ('oadv_core + 'oadv_rest) + ('ousr_core + 'ousr_rest)) resource\" \n  where\n    \"resource rest = resource_of_oracle (fuse rest) (core_init, rinit rest)\"\n\nlemma WT_resource [WT_intro]:\n  assumes \"WT_core \\<I>_adv_core \\<I>_usr_core I_core core\"\n    and \"WT_rest \\<I>_adv_rest \\<I>_usr_rest I_rest rest\"\n    and \"I_core core_init\"\n  shows \"(\\<I>_adv_core \\<oplus>\\<^sub>\\<I> \\<I>_adv_rest) \\<oplus>\\<^sub>\\<I> (\\<I>_usr_core \\<oplus>\\<^sub>\\<I> \\<I>_usr_rest) \\<turnstile>res resource rest \\<surd>\"\nproof -\n  interpret callee_invariant_on \"fuse rest\" \"pred_prod I_core I_rest\" \"(\\<I>_adv_core \\<oplus>\\<^sub>\\<I> \\<I>_adv_rest) \\<oplus>\\<^sub>\\<I> (\\<I>_usr_core \\<oplus>\\<^sub>\\<I> \\<I>_usr_rest)\"\n    using assms(1,2) by(rule callee_invariant_on_fuse)\n  show ?thesis unfolding resource_def\n    by(rule WT_resource_of_oracle)(simp add: assms(3) WT_restD_rinit[OF assms(2)])\nqed\n\nend\n\nparametric_constant \n  fuse_parametric [transfer_rule]: fused_resource.fuse_case\n\nsubsection \\<open>More helpful construction functions\\<close>\n\ncontext\n  fixes\n    core1 :: \"('s_core1, 'event1, 'iadv_core1, 'iusr_core1, 'oadv_core1, 'ousr_core1) core\" and\n    core2 :: \"('s_core2, 'event2, 'iadv_core2, 'iusr_core2, 'oadv_core2, 'ousr_core2) core\"\nbegin\n\nprimcorec parallel_core :: \"\n  ('s_core1 \\<times> 's_core2, 'event1 + 'event2, \n   'iadv_core1 + 'iadv_core2, 'iusr_core1 + 'iusr_core2,\n   'oadv_core1 + 'oadv_core2, 'ousr_core1 + 'ousr_core2) core\" \n  where\n    \"cpoke parallel_core = parallel_handler (cpoke core1) (cpoke core2)\"\n  | \"cfunc_adv parallel_core = parallel_oracle (cfunc_adv core1) (cfunc_adv core2)\"\n  | \"cfunc_usr parallel_core = parallel_oracle (cfunc_usr core1) (cfunc_usr core2)\"\n\nend\n\n\ncontext\n  fixes\n    cnv_adv :: \"'s_adv \\<Rightarrow> 'iadv \\<Rightarrow> ('oadv \\<times> 's_adv, 'iadv_core, 'oadv_core) gpv\" and\n    cnv_usr :: \"'s_usr \\<Rightarrow> 'iusr \\<Rightarrow> ('ousr \\<times> 's_usr, 'iusr_core, 'ousr_core) gpv\" and\n    core :: \"('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core\"\nbegin\n\nprimcorec \n  attach_core :: \"(('s_adv \\<times> 's_usr) \\<times> 's_core, 'event, 'iadv, 'iusr, 'oadv, 'ousr) core\"\n  where\n    \"cpoke attach_core = (\\<lambda>(s_advusr, s_core) event. \n      map_spmf (\\<lambda>s_core'. (s_advusr, s_core')) (cpoke core s_core event))\"\n  | \"cfunc_adv attach_core = (\\<lambda>((s_adv, s_usr), s_core) iadv. \n      map_spmf \n        (\\<lambda>((oadv, s_adv'), s_core'). (oadv, ((s_adv', s_usr), s_core'))) \n        (exec_gpv (cfunc_adv core) (cnv_adv s_adv iadv) s_core))\"\n  | \"cfunc_usr attach_core = (\\<lambda>((s_adv, s_usr), s_core) iusr. \n      map_spmf \n        (\\<lambda>((ousr, s_usr'), s_core'). (ousr, ((s_adv, s_usr'), s_core'))) \n        (exec_gpv (cfunc_usr core) (cnv_usr s_usr iusr) s_core))\"\n\nend\n\n\nlemma \n  attach_core_id_oracle_adv: \"cfunc_adv (attach_core 1\\<^sub>I cnv core) = \n    (\\<lambda>(s_cnv, s_core) q. map_spmf (\\<lambda>(out, s_core'). (out, s_cnv, s_core')) (cfunc_adv core s_core q))\"\n  by(simp add: id_oracle_def split_def map_spmf_conv_bind_spmf)\n\nlemma \n  attach_core_id_oracle_usr: \"cfunc_usr (attach_core cnv 1\\<^sub>I core) = \n    (\\<lambda>(s_cnv, s_core) q. map_spmf (\\<lambda>(out, s_core'). (out, s_cnv, s_core')) (cfunc_usr core s_core q))\"\n  by(simp add: id_oracle_def split_def map_spmf_conv_bind_spmf)\n\n\ncontext\n  fixes\n    rest1 :: \"('s_rest1, 'event1, 'iadv_rest1, 'iusr_rest1, 'oadv_rest1, 'ousr_rest1, 'more1) rest_scheme\" and\n    rest2 :: \"('s_rest2, 'event2, 'iadv_rest2, 'iusr_rest2, 'oadv_rest2, 'ousr_rest2, 'more2) rest_scheme\"\nbegin\n\nprimcorec parallel_rest :: \"\n    ('s_rest1 \\<times> 's_rest2, 'event1 + 'event2, 'iadv_rest1 + 'iadv_rest2, 'iusr_rest1 + 'iusr_rest2, \n     'oadv_rest1 + 'oadv_rest2, 'ousr_rest1 + 'ousr_rest2, 'more1 \\<times> 'more2) rest_scheme\" \n  where\n    \"rinit parallel_rest = (rinit rest1, rinit rest2)\"\n  | \"rfunc_adv parallel_rest = parallel_eoracle (rfunc_adv rest1) (rfunc_adv rest2)\"\n  | \"rfunc_usr parallel_rest = parallel_eoracle (rfunc_usr rest1) (rfunc_usr rest2)\"\n\nend\n\nlemma WT_parallel_rest [WT_intro]:\n  \"WT_rest (\\<I>_adv1 \\<oplus>\\<^sub>\\<I> \\<I>_adv2) (\\<I>_usr1 \\<oplus>\\<^sub>\\<I> \\<I>_usr2) (pred_prod I1 I2) (parallel_rest rest1 rest2)\"\n  if \"WT_rest \\<I>_adv1 \\<I>_usr1 I1 rest1\"\n  and \"WT_rest \\<I>_adv2 \\<I>_usr2 I2 rest2\"\n  by(rule WT_rest.intros)\n    (auto 4 3 simp add: parallel_eoracle_def simp add: that[THEN WT_restD_rinit] dest: that[THEN WT_restD_rfunc_adv] that[THEN WT_restD_rfunc_usr])\n\ncontext\n  fixes\n    cnv_adv :: \"'s_adv \\<Rightarrow> 'iadv \\<Rightarrow> ('oadv \\<times> 's_adv, 'iadv_rest, 'oadv_rest) gpv\" and\n    cnv_usr :: \"'s_usr \\<Rightarrow> 'iusr \\<Rightarrow> ('ousr \\<times> 's_usr, 'iusr_rest, 'ousr_rest) gpv\" and\n    f_init :: \"'more \\<Rightarrow> 'more'\" and\n    rest :: \"('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme\"\nbegin\n\nprimcorec \n  attach_rest :: \"\n    (('s_adv \\<times> 's_usr) \\<times> 's_rest, 'event, 'iadv, 'iusr, 'oadv, 'ousr, 'more') rest_scheme\"\n  where\n    \"rinit attach_rest = f_init (rinit rest)\"\n  | \"rfunc_adv attach_rest = (\\<lambda>((s_adv, s_usr), s_rest) iadv.\n      let orc_of = \\<lambda>orc (s, es) q. map_spmf (\\<lambda> ((out, e), s'). (out, s', es @ e)) (orc s q) in\n      let eorc_of = \\<lambda>((oadv, s_adv'), (s_rest', es)). ((oadv, es), ((s_adv', s_usr), s_rest')) in\n      map_spmf eorc_of (exec_gpv (orc_of (rfunc_adv rest)) (cnv_adv s_adv iadv) (s_rest, [])))\"\n  | \"rfunc_usr attach_rest = (\\<lambda>((s_adv, s_usr), s_rest) iusr. \n      let orc_of = \\<lambda>orc (s, es) q. map_spmf (\\<lambda> ((out, e), s'). (out, s', es @ e)) (orc s q) in\n      let eorc_of = \\<lambda>((ousr, s_usr'), (s_rest', es)). ((ousr, es), ((s_adv, s_usr'), s_rest')) in\n      map_spmf eorc_of (exec_gpv (orc_of (rfunc_usr rest)) (cnv_usr s_usr iusr) (s_rest, [])))\"\n  \nend\n\n\nlemma \n  attach_rest_id_oracle_adv: \"rfunc_adv (attach_rest 1\\<^sub>I cnv f_init rest) = \n    (\\<lambda>(s_cnv, s_core) q. map_spmf (\\<lambda>(out, s_core'). (out, s_cnv, s_core')) (rfunc_adv rest s_core q))\"\n  by(simp add: id_oracle_def split_def map_spmf_conv_bind_spmf fun_eq_iff)  \n\nlemma\n  attach_rest_id_oracle_usr: \"rfunc_usr (attach_rest cnv 1\\<^sub>I f_init rest) = \n    (\\<lambda>(s_cnv, s_core) q. map_spmf (\\<lambda>(out, s_core'). (out, s_cnv, s_core')) (rfunc_usr rest s_core q))\"\n  by(simp add: id_oracle_def split_def map_spmf_conv_bind_spmf)  \n\n\n\nsection \\<open>Traces\\<close>\n\ntype_synonym ('event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) trace_core =\n  \"('event + 'iadv_core \\<times> 'oadv_core + 'iusr_core \\<times> 'ousr_core) list \n  \\<Rightarrow> ('event \\<Rightarrow> real)\n  \\<times> ('iadv_core \\<Rightarrow> 'oadv_core spmf) \n  \\<times> ('iusr_core \\<Rightarrow> 'ousr_core spmf)\"\n\ncontext \n  fixes core :: \"('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core\"\nbegin\n\nprimrec trace_core' :: \"'s_core spmf \\<Rightarrow> ('event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) trace_core\" where\n  \"trace_core' S [] = \n   (\\<lambda>e. weight_spmf' (bind_spmf S (\\<lambda>s. cpoke core s e)),\n    \\<lambda>ia. bind_spmf S (\\<lambda>s. map_spmf fst (cfunc_adv core s ia)),\n    \\<lambda>iu. bind_spmf S (\\<lambda>s. map_spmf fst (cfunc_usr core s iu)))\"\n| \"trace_core' S (obs # tr) = (case obs of\n     Inl e \\<Rightarrow> trace_core' (mk_lossless (bind_spmf S (\\<lambda>s. cpoke core s e))) tr\n   | Inr (Inl (ia, oa)) \\<Rightarrow> trace_core' (cond_spmf_fst (bind_spmf S (\\<lambda>s. cfunc_adv core s ia)) oa) tr\n   | Inr (Inr (iu, ou)) \\<Rightarrow> trace_core' (cond_spmf_fst (bind_spmf S (\\<lambda>s. cfunc_usr core s iu)) ou) tr\n   )\"\n\nend\n\ndeclare trace_core'.simps [simp del]\ncase_of_simps trace_core'_unfold: trace_core'.simps[unfolded weight_spmf'_def]\nsimps_of_case trace_core'_simps [simp]: trace_core'_unfold\n\ncontext includes lifting_syntax begin\n\nlemma trace_core'_parametric [transfer_rule]:\n  \"(rel_core' S E IA IU (=) (=) ===>\n      rel_spmf S ===>\n      list_all2 (rel_sum E (rel_sum (rel_prod IA (=)) (rel_prod IU (=)))) ===>\n      rel_prod (E ===> (=)) (rel_prod (IA ===> (=)) (IU ===> (=))))\n      trace_core' trace_core'\"\n  unfolding trace_core'_def by transfer_prover\n\ndefinition trace_core_eq \n  :: \"('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core\n  \\<Rightarrow> ('s_core', 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core\n  \\<Rightarrow> 'event set \\<Rightarrow> 'iadv_core set \\<Rightarrow> 'iusr_core set\n  \\<Rightarrow> 's_core spmf \\<Rightarrow> 's_core' spmf \\<Rightarrow> bool\" where\n  \"trace_core_eq core1 core2 E IA IU p q \\<longleftrightarrow>\n  (\\<forall>tr. set tr \\<subseteq> E <+> (IA \\<times> UNIV) <+> (IU \\<times> UNIV) \\<longrightarrow> \n   rel_prod (eq_onp (\\<lambda>e. e \\<in> E) ===> (=)) (rel_prod (eq_onp (\\<lambda>ia. ia \\<in> IA) ===> (=)) (eq_onp (\\<lambda>iu. iu \\<in> IU) ===> (=)))\n     (trace_core' core1 p tr) (trace_core' core2 q tr))\"\n\nend\n\nlemma trace_core_eqD:\n  assumes \"trace_core_eq core1 core2 E IA IU p q\"\n    and \"set tr \\<subseteq> E <+> (IA \\<times> UNIV) <+> (IU \\<times> UNIV)\"\n  shows trace_core_eqD_cpoke: \n      \"e \\<in> E \\<Longrightarrow> fst (trace_core' core1 p tr) e = fst (trace_core' core2 q tr) e\"\n    and trace_core_eqD_cfunc_adv: \n      \"ia \\<in> IA \\<Longrightarrow> fst (snd (trace_core' core1 p tr)) ia = fst (snd (trace_core' core2 q tr)) ia\"\n    and trace_core_eqD_cfunc_usr:\n      \"iu \\<in> IU \\<Longrightarrow> snd (snd (trace_core' core1 p tr)) iu = snd (snd (trace_core' core2 q tr)) iu\"\n  using assms by(auto simp add: trace_core_eq_def rel_fun_def eq_onp_def rel_prod_sel)\n\nlemma trace_core_eqI:\n  assumes \"\\<And>tr e. \\<lbrakk> set tr \\<subseteq> E <+> (IA \\<times> UNIV) <+> (IU \\<times> UNIV); e \\<in> E \\<rbrakk> \n     \\<Longrightarrow> fst (trace_core' core1 p tr) e = fst (trace_core' core2 q tr) e\"\n    and \"\\<And>tr ia. \\<lbrakk> set tr \\<subseteq> E <+> (IA \\<times> UNIV) <+> (IU \\<times> UNIV); ia \\<in> IA \\<rbrakk>\n     \\<Longrightarrow> fst (snd (trace_core' core1 p tr)) ia = fst (snd (trace_core' core2 q tr)) ia\"\n    and \"\\<And>tr iu. \\<lbrakk> set tr \\<subseteq> E <+> (IA \\<times> UNIV) <+> (IU \\<times> UNIV); iu \\<in> IU \\<rbrakk>\n     \\<Longrightarrow> snd (snd (trace_core' core1 p tr)) iu = snd (snd (trace_core' core2 q tr)) iu\"\n  shows \"trace_core_eq core1 core2 E IA IU p q\"\n  using assms by(auto simp add: trace_core_eq_def rel_fun_def eq_onp_def rel_prod_sel)\n\nlemma trace_core_return_pmf_None [simp]:\n  \"trace_core' core (return_pmf None) tr = (\\<lambda>_. 0, \\<lambda>_. return_pmf None, \\<lambda>_. return_pmf None)\"\n  by(induction tr)(simp_all add: trace_core'.simps split: sum.split)\n\nlemma rel_core'_into_trace_core_eq: \"trace_core_eq core core' E IA IU p q\" \n  if \"rel_core' S (eq_onp (\\<lambda>e. e \\<in> E)) (eq_onp (\\<lambda>ia. ia \\<in> IA)) (eq_onp (\\<lambda>iu. iu \\<in> IU)) (=) (=) core core'\"\n     \"rel_spmf S p q\"\n  using trace_core'_parametric[THEN rel_funD, THEN rel_funD, OF that]\n  unfolding trace_core_eq_def\n  apply(intro strip)\n  subgoal for tr\n    apply(simp add: eq_onp_True[symmetric] prod.rel_eq_onp sum.rel_eq_onp list.rel_eq_onp)\n    apply(auto 4 3 simp add: eq_onp_def list_all_iff dest: rel_funD[where x=tr and y=tr])\n    done\n  done\n\nlemma trace_core_eq_simI:\n  fixes core1 :: \"('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core\"\n    and core2 :: \"('s_core', 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core\"\n    and S :: \"'s_core spmf \\<Rightarrow> 's_core' spmf \\<Rightarrow> bool\"\n  assumes start: \"S p q\"\n    and step_cpoke: \"\\<And>p q e. \\<lbrakk> S p q; e \\<in> E \\<rbrakk> \\<Longrightarrow> \n      weight_spmf (bind_spmf p (\\<lambda>s. cpoke core1 s e)) = weight_spmf (bind_spmf q (\\<lambda>s. cpoke core2 s e))\"\n    and sim_cpoke: \"\\<And>p q e. \\<lbrakk> S p q; e \\<in> E \\<rbrakk> \\<Longrightarrow> \n      S (mk_lossless (bind_spmf p (\\<lambda>s. cpoke core1 s e))) (mk_lossless (bind_spmf q (\\<lambda>s. cpoke core2 s e)))\"\n    and step_cfunc_adv: \"\\<And>p q ia. \\<lbrakk> S p q; ia \\<in> IA \\<rbrakk> \\<Longrightarrow> \n      bind_spmf p (\\<lambda>s1. map_spmf fst (cfunc_adv core1 s1 ia)) = bind_spmf q (\\<lambda>s2. map_spmf fst (cfunc_adv core2 s2 ia))\"\n    and sim_cfunc_adv: \"\\<And>p q ia s1 s2 s1' s2' oa. \\<lbrakk> S p q; ia \\<in> IA; \n      s1 \\<in> set_spmf p; s2 \\<in> set_spmf q; (oa, s1') \\<in> set_spmf (cfunc_adv core1 s1 ia); (oa, s2') \\<in> set_spmf (cfunc_adv core2 s2 ia) \\<rbrakk>\n      \\<Longrightarrow> S (cond_spmf_fst (bind_spmf p (\\<lambda>s1. cfunc_adv core1 s1 ia)) oa) (cond_spmf_fst (bind_spmf q (\\<lambda>s2. cfunc_adv core2 s2 ia)) oa)\"\n    and step_cfunc_usr: \"\\<And>p q iu. \\<lbrakk> S p q; iu \\<in> IU \\<rbrakk> \\<Longrightarrow> \n      bind_spmf p (\\<lambda>s1. map_spmf fst (cfunc_usr core1 s1 iu)) = bind_spmf q (\\<lambda>s2. map_spmf fst (cfunc_usr core2 s2 iu))\"\n    and sim_cfunc_usr: \"\\<And>p q iu s1 s2 s1' s2' ou. \\<lbrakk> S p q; iu \\<in> IU; \n      s1 \\<in> set_spmf p; s2 \\<in> set_spmf q; (ou, s1') \\<in> set_spmf (cfunc_usr core1 s1 iu); (ou, s2') \\<in> set_spmf (cfunc_usr core2 s2 iu) \\<rbrakk>\n      \\<Longrightarrow> S (cond_spmf_fst (bind_spmf p (\\<lambda>s1. cfunc_usr core1 s1 iu)) ou) (cond_spmf_fst (bind_spmf q (\\<lambda>s2. cfunc_usr core2 s2 iu)) ou)\"\n  shows \"trace_core_eq core1 core2 E IA IU p q\"\nproof(rule trace_core_eqI)\n  fix tr :: \" ('event + 'iadv_core \\<times> 'oadv_core + 'iusr_core \\<times> 'ousr_core) list\"\n  assume \"set tr \\<subseteq> E <+> IA \\<times> UNIV <+> IU \\<times> UNIV\"\n  then have \"(\\<forall>e\\<in>E. fst (trace_core' core1 p tr) e = fst (trace_core' core2 q tr) e) \\<and>\n     (\\<forall>ia\\<in>IA. fst (snd (trace_core' core1 p tr)) ia = fst (snd (trace_core' core2 q tr)) ia) \\<and>\n     (\\<forall>iu\\<in>IU. snd (snd (trace_core' core1 p tr)) iu = snd (snd (trace_core' core2 q tr)) iu)\"\n    using start\n  proof(induction tr arbitrary: p q)\n    case Nil\n    then show ?case by(simp add: step_cpoke step_cfunc_adv step_cfunc_usr)\n  next\n    case (Cons a tr)\n    from Cons.prems(1) have tr: \"set tr \\<subseteq> E <+> IA \\<times> UNIV <+> IU \\<times> UNIV\" by simp\n    from Cons.prems(1)\n    consider (cpoke) e where \"a = Inl e\" \"e \\<in> E\"\n      | (cfunc_adv) ia oa where \"a = Inr (Inl (ia, oa))\" \"ia \\<in> IA\"\n      | (cfunc_usr) iu ou where \"a = Inr (Inr (iu, ou))\" \"iu \\<in> IU\" by auto\n    then show ?case\n    proof cases\n      case cpoke\n      then show ?thesis using tr Cons.prems(2) by(auto simp add: sim_cpoke intro!: Cons.IH)\n    next\n      case cfunc_adv\n      let ?p = \"bind_spmf p (\\<lambda>s1. cfunc_adv core1 s1 ia)\"\n      let ?q = \"bind_spmf q (\\<lambda>s2. cfunc_adv core2 s2 ia)\"\n      show ?thesis\n      proof(cases \"oa \\<in> fst ` set_spmf ?p\")\n        case True\n        with step_cfunc_adv[OF Cons.prems(2) cfunc_adv(2), THEN arg_cong[where f=set_spmf]]\n        have \"oa \\<in> fst ` set_spmf ?q\"\n          unfolding set_map_spmf[symmetric] by(simp only: map_bind_spmf o_def)\n        then show ?thesis using True Cons.prems cfunc_adv\n          by(clarsimp)(rule Cons.IH; blast intro: sim_cfunc_adv)\n      next\n        case False\n        hence \"cond_spmf_fst ?p oa = return_pmf None\" by simp\n        moreover\n        from step_cfunc_adv[OF Cons.prems(2) cfunc_adv(2), THEN arg_cong[where f=set_spmf]] False\n        have oa': \"oa \\<notin> fst ` set_spmf ?q\"\n          unfolding set_map_spmf[symmetric] by(simp only: map_bind_spmf o_def) simp\n        hence \"cond_spmf_fst ?q oa = return_pmf None\" by simp\n        ultimately show ?thesis using cfunc_adv by(simp del: cond_spmf_fst_eq_return_None)\n      qed\n    next\n      case cfunc_usr\n      let ?p = \"bind_spmf p (\\<lambda>s1. cfunc_usr core1 s1 iu)\"\n      let ?q = \"bind_spmf q (\\<lambda>s2. cfunc_usr core2 s2 iu)\"\n      show ?thesis\n      proof(cases \"ou \\<in> fst ` set_spmf ?p\")\n        case True\n        with step_cfunc_usr[OF Cons.prems(2) cfunc_usr(2), THEN arg_cong[where f=set_spmf]]\n        have \"ou \\<in> fst ` set_spmf ?q\"\n          unfolding set_map_spmf[symmetric] by(simp only: map_bind_spmf o_def)\n        then show ?thesis using True Cons.prems cfunc_usr\n          by(clarsimp)(rule Cons.IH; blast intro: sim_cfunc_usr)\n      next\n        case False\n        hence \"cond_spmf_fst ?p ou = return_pmf None\" by simp\n        moreover\n        from step_cfunc_usr[OF Cons.prems(2) cfunc_usr(2), THEN arg_cong[where f=set_spmf]] False\n        have oa': \"ou \\<notin> fst ` set_spmf ?q\"\n          unfolding set_map_spmf[symmetric] by(simp only: map_bind_spmf o_def) simp\n        hence \"cond_spmf_fst ?q ou = return_pmf None\" by simp\n        ultimately show ?thesis using cfunc_usr by(simp del: cond_spmf_fst_eq_return_None)\n      qed\n    qed\n  qed\n  then show \"e \\<in> E \\<Longrightarrow> fst (trace_core' core1 p tr) e = fst (trace_core' core2 q tr) e\"\n    and \"ia \\<in> IA \\<Longrightarrow> fst (snd (trace_core' core1 p tr)) ia = fst (snd (trace_core' core2 q tr)) ia\"\n    and \"iu \\<in> IU \\<Longrightarrow> snd (snd (trace_core' core1 p tr)) iu = snd (snd (trace_core' core2 q tr)) iu\"\n    for e ia iu by blast+\nqed\n\ncontext \n  fixes core :: \"('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core\"\nbegin\n\nfun trace_core_aux \n  :: \"'s_core spmf \\<Rightarrow> ('event + 'iadv_core \\<times> 'oadv_core + 'iusr_core \\<times> 'ousr_core) list \\<Rightarrow> 's_core spmf\" where\n  \"trace_core_aux p [] = p\"\n| \"trace_core_aux p (Inl e # tr) = trace_core_aux (mk_lossless (bind_spmf p (\\<lambda>s. cpoke core s e))) tr\"\n| \"trace_core_aux p (Inr (Inl (ia, oa)) # tr) = trace_core_aux (cond_spmf_fst (bind_spmf p (\\<lambda>s. cfunc_adv core s ia)) oa) tr\"\n| \"trace_core_aux p (Inr (Inr (iu, ou)) # tr) = trace_core_aux (cond_spmf_fst (bind_spmf p (\\<lambda>s. cfunc_usr core s iu)) ou) tr\"\n\nend\n\nlemma trace_core_conv_trace_core_aux:\n  \"trace_core' core p tr = \n   (\\<lambda>e. weight_spmf (bind_spmf (trace_core_aux core p tr) (\\<lambda>s. cpoke core s e)),\n    \\<lambda>ia. bind_spmf (trace_core_aux core p tr) (\\<lambda>s. map_spmf fst (cfunc_adv core s ia)),\n    \\<lambda>iu. bind_spmf (trace_core_aux core p tr) (\\<lambda>s. map_spmf fst (cfunc_usr core s iu)))\"\n  by(induction p tr rule: trace_core_aux.induct) simp_all\n\nlemma trace_core_aux_append:\n  \"trace_core_aux core p (tr @ tr') = trace_core_aux core (trace_core_aux core p tr) tr'\"\n  by(induction p tr rule: trace_core_aux.induct) auto\n\ninductive trace_core_closure \n  :: \"('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core\n  \\<Rightarrow> ('s_core', 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core\n  \\<Rightarrow> 'event set \\<Rightarrow> 'iadv_core set \\<Rightarrow> 'iusr_core set\n  \\<Rightarrow> 's_core spmf \\<Rightarrow> 's_core' spmf \\<Rightarrow> 's_core spmf \\<Rightarrow> 's_core' spmf \\<Rightarrow> bool\"\n  for core1 core2 E IA IU p q where\n  \"trace_core_closure core1 core2 E IA IU p q (trace_core_aux core1 p tr) (trace_core_aux core2 q tr)\"\n  if \"set tr \\<subseteq> E <+> IA \\<times> UNIV <+> IU \\<times> UNIV\"\n\nlemma trace_core_closure_start: \"trace_core_closure core1 core2 E IA IU p q p q\"\n  by(simp add: trace_core_closure.simps exI[where x=\"[]\"])\n\nlemma trace_core_closure_step:\n  assumes \"trace_core_eq core1 core2 E IA IU p q\"\n    and \"trace_core_closure core1 core2 E IA IU p q p' q'\"\n  shows trace_core_closure_step_cpoke:\n    \"e \\<in> E \\<Longrightarrow> weight_spmf (bind_spmf p' (\\<lambda>s. cpoke core1 s e)) = weight_spmf (bind_spmf q' (\\<lambda>s. cpoke core2 s e))\"\n    (is \"PROP ?thesis1\")\n    and trace_core_closure_step_cfunc_adv: \n    \"ia \\<in> IA \\<Longrightarrow> bind_spmf p' (\\<lambda>s1. map_spmf fst (cfunc_adv core1 s1 ia)) = bind_spmf q' (\\<lambda>s2. map_spmf fst (cfunc_adv core2 s2 ia))\"\n    (is \"PROP ?thesis2\")\n    and trace_core_closure_step_cfunc_usr:\n    \"iu \\<in> IU \\<Longrightarrow> bind_spmf p' (\\<lambda>s1. map_spmf fst (cfunc_usr core1 s1 iu)) = bind_spmf q' (\\<lambda>s2. map_spmf fst (cfunc_usr core2 s2 iu))\"\n    (is \"PROP ?thesis3\")\nproof -\n  from assms(2) obtain tr where p: \"p' = trace_core_aux core1 p tr\"\n    and q: \"q' = trace_core_aux core2 q tr\"\n    and tr: \"set tr \\<subseteq> E <+> IA \\<times> UNIV <+> IU \\<times> UNIV\" by cases\n  from trace_core_eqD[OF assms(1) tr] p q\n  show \"PROP ?thesis1\" and \"PROP ?thesis2\" \"PROP ?thesis3\"\n    by(simp_all add: trace_core_conv_trace_core_aux)\nqed\n\nlemma trace_core_closure_sim:\n  fixes core1 core2 E IA IU p q\n  defines \"S \\<equiv> trace_core_closure core1 core2 E IA IU p q\"\n  assumes \"S p' q'\"\n  shows trace_core_closure_sim_cpoke:\n    \"e \\<in> E \\<Longrightarrow> S (mk_lossless (bind_spmf p' (\\<lambda>s. cpoke core1 s e))) (mk_lossless (bind_spmf q' (\\<lambda>s. cpoke core2 s e)))\"\n    (is \"PROP ?thesis1\")\n    and trace_core_closure_sim_cfunc_adv: \"ia \\<in> IA \n    \\<Longrightarrow> S (cond_spmf_fst (bind_spmf p' (\\<lambda>s1. cfunc_adv core1 s1 ia)) oa) \n          (cond_spmf_fst (bind_spmf q' (\\<lambda>s2. cfunc_adv core2 s2 ia)) oa)\"\n    (is \"PROP ?thesis2\")\n    and trace_core_closure_sim_cfunc_usr: \"iu \\<in> IU \n    \\<Longrightarrow> S (cond_spmf_fst (bind_spmf p' (\\<lambda>s1. cfunc_usr core1 s1 iu)) ou)\n          (cond_spmf_fst (bind_spmf q' (\\<lambda>s2. cfunc_usr core2 s2 iu)) ou)\"\n    (is \"PROP ?thesis3\")\nproof -\n  from assms(2) obtain tr where p: \"p' = trace_core_aux core1 p tr\"\n    and q: \"q' = trace_core_aux core2 q tr\"\n    and tr: \"set tr \\<subseteq> E <+> IA \\<times> UNIV <+> IU \\<times> UNIV\" unfolding S_def by cases\n  show \"PROP ?thesis1\" using p q tr\n    by(auto simp add: S_def trace_core_closure.simps trace_core_aux_append intro!: exI[where x=\"tr @ [Inl _]\"])\n  show \"PROP ?thesis2\" using p q tr\n    by(auto simp add: S_def trace_core_closure.simps trace_core_aux_append intro!: exI[where x=\"tr @ [Inr (Inl (_, _))]\"])\n  show \"PROP ?thesis3\" using p q tr\n    by(auto simp add: S_def trace_core_closure.simps trace_core_aux_append intro!: exI[where x=\"tr @ [Inr (Inr (_, _))]\"])\nqed\n\nproposition trace_core_eq_complete:\n  assumes \"trace_core_eq core1 core2 E IA IU p q\"\n  obtains S\n  where \"S p q\"\n    and \"\\<And>p q e. \\<lbrakk> S p q; e \\<in> E \\<rbrakk> \\<Longrightarrow> \n      weight_spmf (bind_spmf p (\\<lambda>s. cpoke core1 s e)) = weight_spmf (bind_spmf q (\\<lambda>s. cpoke core2 s e))\"\n    and \"\\<And>p q e. \\<lbrakk> S p q; e \\<in> E \\<rbrakk> \\<Longrightarrow> \n      S (mk_lossless (bind_spmf p (\\<lambda>s. cpoke core1 s e))) (mk_lossless (bind_spmf q (\\<lambda>s. cpoke core2 s e)))\"\n    and \"\\<And>p q ia. \\<lbrakk> S p q; ia \\<in> IA \\<rbrakk> \\<Longrightarrow> \n      bind_spmf p (\\<lambda>s1. map_spmf fst (cfunc_adv core1 s1 ia)) = bind_spmf q (\\<lambda>s2. map_spmf fst (cfunc_adv core2 s2 ia))\"\n    and \"\\<And>p q ia oa. \\<lbrakk> S p q; ia \\<in> IA \\<rbrakk>\n      \\<Longrightarrow> S (cond_spmf_fst (bind_spmf p (\\<lambda>s1. cfunc_adv core1 s1 ia)) oa) (cond_spmf_fst (bind_spmf q (\\<lambda>s2. cfunc_adv core2 s2 ia)) oa)\"\n    and \"\\<And>p q iu. \\<lbrakk> S p q; iu \\<in> IU \\<rbrakk> \\<Longrightarrow> \n      bind_spmf p (\\<lambda>s1. map_spmf fst (cfunc_usr core1 s1 iu)) = bind_spmf q (\\<lambda>s2. map_spmf fst (cfunc_usr core2 s2 iu))\"\n    and \"\\<And>p q iu ou. \\<lbrakk> S p q; iu \\<in> IU \\<rbrakk>\n      \\<Longrightarrow> S (cond_spmf_fst (bind_spmf p (\\<lambda>s1. cfunc_usr core1 s1 iu)) ou) (cond_spmf_fst (bind_spmf q (\\<lambda>s2. cfunc_usr core2 s2 iu)) ou)\"\nproof -\n  show thesis\n    by(rule that[where S=\"trace_core_closure core1 core2 E IA IU p q\"])\n      (auto intro: trace_core_closure_start trace_core_closure_step[OF assms] trace_core_closure_sim (* trace_core_closure_weight[OF assms] *))\nqed\n\n\n\ntype_synonym ('event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest) trace_rest =\n  \"('iadv_rest \\<times> 'oadv_rest \\<times> 'event list + 'iusr_rest \\<times> 'ousr_rest \\<times> 'event list) list\n  \\<Rightarrow> ('iadv_rest \\<Rightarrow> ('oadv_rest \\<times> 'event list) spmf) \n  \\<times> ('iusr_rest \\<Rightarrow> ('ousr_rest \\<times> 'event list) spmf)\"\n\ncontext\n  fixes rest :: \"('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme\"\nbegin\n\nprimrec trace_rest' :: \"'s_rest spmf \\<Rightarrow> ('event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest) trace_rest\" where\n  \"trace_rest' S [] =\n  (\\<lambda>ia. bind_spmf S (\\<lambda>s. map_spmf fst (rfunc_adv rest s ia)),\n   \\<lambda>iu. bind_spmf S (\\<lambda>s. map_spmf fst (rfunc_usr rest s iu)))\"\n| \"trace_rest' S (obs # tr) = (case obs of\n     Inl (ia, oa) \\<Rightarrow> trace_rest' (cond_spmf_fst (bind_spmf S (\\<lambda>s. rfunc_adv rest s ia)) oa) tr\n   | Inr (iu, ou) \\<Rightarrow> trace_rest' (cond_spmf_fst (bind_spmf S (\\<lambda>s. rfunc_usr rest s iu)) ou) tr)\"\n\nend\n\ndeclare trace_rest'.simps [simp del]\ncase_of_simps trace_rest'_unfold: trace_rest'.simps\nsimps_of_case trace_rest'_simps [simp]: trace_rest'_unfold\n\ncontext includes lifting_syntax begin\n\nlemma trace_rest'_parametric [transfer_rule]:\n  \"(rel_rest' S (=) IA IU (=) (=) M ===> rel_spmf S ===>\n      list_all2 (rel_sum (rel_prod IA (=)) (rel_prod IU (=))) ===>\n      rel_prod (IA ===> (=)) (IU ===> (=)))\n      trace_rest' trace_rest'\"\n  unfolding trace_rest'_def by transfer_prover\n\ndefinition trace_rest_eq\n  :: \"('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more1) rest_scheme\n  \\<Rightarrow> ('s_rest', 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more2) rest_scheme\n  \\<Rightarrow> 'iadv_rest set \\<Rightarrow> 'iusr_rest set\n  \\<Rightarrow> 's_rest spmf \\<Rightarrow> 's_rest' spmf \\<Rightarrow> bool\" where\n  \"trace_rest_eq rest1 rest2 IA IU p q \\<longleftrightarrow>\n  (\\<forall>tr. set tr \\<subseteq> (IA \\<times> UNIV) <+> (IU \\<times> UNIV) \\<longrightarrow>\n   rel_prod (eq_onp (\\<lambda>ia. ia \\<in> IA) ===> (=)) (eq_onp (\\<lambda>iu. iu \\<in> IU) ===> (=))\n     (trace_rest' rest1 p tr) (trace_rest' rest2 q tr))\"\n\nend\n\nlemma trace_rest_eqD:\n  assumes \"trace_rest_eq rest1 rest2 IA IU p q\"\n    and \"set tr \\<subseteq> (IA \\<times> UNIV) <+> (IU \\<times> UNIV)\"\n  shows trace_rest_eqD_rfunc_adv:\n     \"ia \\<in> IA \\<Longrightarrow> fst (trace_rest' rest1 p tr) ia = fst (trace_rest' rest2 q tr) ia\"\n    and trace_rest_eqD_rfunc_usr:\n     \"iu \\<in> IU \\<Longrightarrow> snd (trace_rest' rest1 p tr) iu = snd (trace_rest' rest2 q tr) iu\"\n  using assms by(auto simp add: trace_rest_eq_def rel_fun_def rel_prod_sel eq_onp_def)\n\nlemma trace_rest_eqI:\n  assumes \"\\<And>tr ia. \\<lbrakk> set tr \\<subseteq> (IA \\<times> UNIV) <+> (IU \\<times> UNIV); ia \\<in> IA \\<rbrakk>\n     \\<Longrightarrow> fst (trace_rest' rest1 p tr) ia = fst (trace_rest' rest2 q tr) ia\"\n    and \"\\<And>tr iu. \\<lbrakk> set tr \\<subseteq> (IA \\<times> UNIV) <+> (IU \\<times> UNIV); iu \\<in> IU \\<rbrakk>\n      \\<Longrightarrow> snd (trace_rest' rest1 p tr) iu = snd (trace_rest' rest2 q tr) iu\"\n  shows \"trace_rest_eq rest1 rest2 IA IU p q\"\n  using assms by(auto simp add: trace_rest_eq_def rel_fun_def eq_onp_def rel_prod_sel)\n\nlemma trace_rest_return_pmf_None [simp]:\n  \"trace_rest' rest (return_pmf None) tr = (\\<lambda>_. return_pmf None, \\<lambda>_. return_pmf None)\"\n  by(induction tr)(simp_all add: trace_rest'.simps split: sum.split)\n\nlemma rel_rest'_into_trace_rest_eq: \"trace_rest_eq rest rest' IA IU p q\" \n  if \"rel_rest' S (=) (eq_onp (\\<lambda>ia. ia \\<in> IA)) (eq_onp (\\<lambda>iu. iu \\<in> IU)) (=) (=) M rest rest'\"\n     \"rel_spmf S p q\"\n  using trace_rest'_parametric[THEN rel_funD, THEN rel_funD, OF that]\n  unfolding trace_rest_eq_def\n  apply(intro strip)\n  subgoal for tr\n    apply(simp add: eq_onp_True[symmetric] prod.rel_eq_onp sum.rel_eq_onp list.rel_eq_onp)\n    apply(auto 4 3 simp add: eq_onp_def list_all_iff dest: rel_funD[where x=tr and y=tr])\n    done\n  done\n\nlemma trace_rest_eq_simI:\n  fixes rest1 :: \"('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme\"\n    and rest2 :: \"('s_rest', 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme\"\n    and S :: \"'s_rest spmf \\<Rightarrow> 's_rest' spmf \\<Rightarrow> bool\"\n  assumes start: \"S p q\"\n    and step_rfunc_adv: \"\\<And>p q ia. \\<lbrakk> S p q; ia \\<in> IA \\<rbrakk> \\<Longrightarrow> \n      bind_spmf p (\\<lambda>s1. map_spmf fst (rfunc_adv rest1 s1 ia)) = bind_spmf q (\\<lambda>s2. map_spmf fst (rfunc_adv rest2 s2 ia))\"\n    and sim_rfunc_adv: \"\\<And>p q ia s1 s2 s1' s2' oa. \\<lbrakk> S p q; ia \\<in> IA; \n      s1 \\<in> set_spmf p; s2 \\<in> set_spmf q; (oa, s1') \\<in> set_spmf (rfunc_adv rest1 s1 ia); (oa, s2') \\<in> set_spmf (rfunc_adv rest2 s2 ia) \\<rbrakk>\n      \\<Longrightarrow> S (cond_spmf_fst (bind_spmf p (\\<lambda>s1. rfunc_adv rest1 s1 ia)) oa) (cond_spmf_fst (bind_spmf q (\\<lambda>s2. rfunc_adv rest2 s2 ia)) oa)\"\n    and step_rfunc_usr: \"\\<And>p q iu. \\<lbrakk> S p q; iu \\<in> IU \\<rbrakk> \\<Longrightarrow> \n      bind_spmf p (\\<lambda>s1. map_spmf fst (rfunc_usr rest1 s1 iu)) = bind_spmf q (\\<lambda>s2. map_spmf fst (rfunc_usr rest2 s2 iu))\"\n    and sim_rfunc_usr: \"\\<And>p q iu s1 s2 s1' s2' ou. \\<lbrakk> S p q; iu \\<in> IU; \n      s1 \\<in> set_spmf p; s2 \\<in> set_spmf q; (ou, s1') \\<in> set_spmf (rfunc_usr rest1 s1 iu); (ou, s2') \\<in> set_spmf (rfunc_usr rest2 s2 iu) \\<rbrakk>\n      \\<Longrightarrow> S (cond_spmf_fst (bind_spmf p (\\<lambda>s1. rfunc_usr rest1 s1 iu)) ou) (cond_spmf_fst (bind_spmf q (\\<lambda>s2. rfunc_usr rest2 s2 iu)) ou)\"\n  shows \"trace_rest_eq rest1 rest2 IA IU p q\"\nproof(rule trace_rest_eqI)\n  fix tr :: \"('iadv_rest \\<times> 'oadv_rest \\<times> 'event list + 'iusr_rest \\<times> 'ousr_rest \\<times> 'event list) list\"\n  assume \"set tr \\<subseteq> IA \\<times> UNIV <+> IU \\<times> UNIV\"\n  then have \"(\\<forall>ia\\<in>IA. fst (trace_rest' rest1 p tr) ia = fst (trace_rest' rest2 q tr) ia) \\<and>\n       (\\<forall>iu\\<in>IU. snd (trace_rest' rest1 p tr) iu = snd (trace_rest' rest2 q tr) iu)\"\n    using start\n  proof(induction tr arbitrary: p q)\n    case Nil\n    then show ?case by(simp add: step_rfunc_adv step_rfunc_usr)\n  next\n    case (Cons a tr)\n    from Cons.prems(1) have tr: \"set tr \\<subseteq> IA \\<times> UNIV <+> IU \\<times> UNIV\" by simp\n    from Cons.prems(1)\n    consider (rfunc_adv) ia oa where \"a = Inl (ia, oa)\" \"ia \\<in> IA\"\n      | (rfunc_usr) iu ou where \"a = Inr (iu, ou)\" \"iu \\<in> IU\" by auto\n    then show ?case\n    proof cases\n      case rfunc_adv\n      let ?p = \"bind_spmf p (\\<lambda>s1. rfunc_adv rest1 s1 ia)\"\n      let ?q = \"bind_spmf q (\\<lambda>s2. rfunc_adv rest2 s2 ia)\"\n      show ?thesis\n      proof(cases \"oa \\<in> fst ` set_spmf ?p\")\n        case True\n        with step_rfunc_adv[OF Cons.prems(2) rfunc_adv(2), THEN arg_cong[where f=set_spmf]]\n        have \"oa \\<in> fst ` set_spmf ?q\"\n          unfolding set_map_spmf[symmetric] by(simp only: map_bind_spmf o_def)\n        then show ?thesis using True Cons.prems rfunc_adv\n          by(clarsimp)(rule Cons.IH; blast intro: sim_rfunc_adv)\n      next\n        case False\n        hence \"cond_spmf_fst ?p oa = return_pmf None\" by simp\n        moreover\n        from step_rfunc_adv[OF Cons.prems(2) rfunc_adv(2), THEN arg_cong[where f=set_spmf]] False\n        have oa': \"oa \\<notin> fst ` set_spmf ?q\"\n          unfolding set_map_spmf[symmetric] by(simp only: map_bind_spmf o_def) simp\n        hence \"cond_spmf_fst ?q oa = return_pmf None\" by simp\n        ultimately show ?thesis using rfunc_adv by(simp del: cond_spmf_fst_eq_return_None)\n      qed\n    next\n      case rfunc_usr\n      let ?p = \"bind_spmf p (\\<lambda>s1. rfunc_usr rest1 s1 iu)\"\n      let ?q = \"bind_spmf q (\\<lambda>s2. rfunc_usr rest2 s2 iu)\"\n      show ?thesis\n      proof(cases \"ou \\<in> fst ` set_spmf ?p\")\n        case True\n        with step_rfunc_usr[OF Cons.prems(2) rfunc_usr(2), THEN arg_cong[where f=set_spmf]]\n        have \"ou \\<in> fst ` set_spmf ?q\"\n          unfolding set_map_spmf[symmetric] by(simp only: map_bind_spmf o_def)\n        then show ?thesis using True Cons.prems rfunc_usr\n          by(clarsimp)(rule Cons.IH; blast intro: sim_rfunc_usr)\n      next\n        case False\n        hence \"cond_spmf_fst ?p ou = return_pmf None\" by simp\n        moreover\n        from step_rfunc_usr[OF Cons.prems(2) rfunc_usr(2), THEN arg_cong[where f=set_spmf]] False\n        have oa': \"ou \\<notin> fst ` set_spmf ?q\"\n          unfolding set_map_spmf[symmetric] by(simp only: map_bind_spmf o_def) simp\n        hence \"cond_spmf_fst ?q ou = return_pmf None\" by simp\n        ultimately show ?thesis using rfunc_usr by(simp del: cond_spmf_fst_eq_return_None)\n      qed\n    qed\n  qed\n  then show \"ia \\<in> IA \\<Longrightarrow> fst (trace_rest' rest1 p tr) ia = fst (trace_rest' rest2 q tr) ia\"\n    and \"iu \\<in> IU \\<Longrightarrow> snd (trace_rest' rest1 p tr) iu = snd (trace_rest' rest2 q tr) iu\"\n    for ia iu by blast+\nqed\n\ncontext \n  fixes rest :: \"('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme\"\nbegin\n\nfun trace_rest_aux \n  :: \"'s_rest spmf \\<Rightarrow> ('iadv_rest \\<times> 'oadv_rest \\<times> 'event list + 'iusr_rest \\<times> 'ousr_rest \\<times> 'event list) list \\<Rightarrow> 's_rest spmf\" where\n  \"trace_rest_aux p [] = p\"\n| \"trace_rest_aux p (Inl (ia, oaes) # tr) = trace_rest_aux (cond_spmf_fst (bind_spmf p (\\<lambda>s. rfunc_adv rest s ia)) oaes) tr\"\n| \"trace_rest_aux p (Inr (iu, oues) # tr) = trace_rest_aux (cond_spmf_fst (bind_spmf p (\\<lambda>s. rfunc_usr rest s iu)) oues) tr\"\n\nend\n\nlemma trace_rest_conv_trace_rest_aux:\n  \"trace_rest' rest p tr = \n   (\\<lambda>ia. bind_spmf (trace_rest_aux rest p tr) (\\<lambda>s. map_spmf fst (rfunc_adv rest s ia)),\n    \\<lambda>iu. bind_spmf (trace_rest_aux rest p tr) (\\<lambda>s. map_spmf fst (rfunc_usr rest s iu)))\"\n  by(induction p tr rule: trace_rest_aux.induct) simp_all\n\nlemma trace_rest_aux_append:\n  \"trace_rest_aux rest p (tr @ tr') = trace_rest_aux rest (trace_rest_aux rest p tr) tr'\"\n  by(induction p tr rule: trace_rest_aux.induct) auto\n\ninductive trace_rest_closure \n  :: \"('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme\n  \\<Rightarrow> ('s_rest', 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more') rest_scheme\n  \\<Rightarrow> 'iadv_rest set \\<Rightarrow> 'iusr_rest set\n  \\<Rightarrow> 's_rest spmf \\<Rightarrow> 's_rest' spmf \\<Rightarrow> 's_rest spmf \\<Rightarrow> 's_rest' spmf \\<Rightarrow> bool\"\n  for rest1 rest2 IA IU p q where\n  \"trace_rest_closure rest1 rest2 IA IU p q (trace_rest_aux rest1 p tr) (trace_rest_aux rest2 q tr)\"\n  if \"set tr \\<subseteq> IA \\<times> UNIV <+> IU \\<times> UNIV\"\n\nlemma trace_rest_closure_start: \"trace_rest_closure rest1 rest2 IA IU p q p q\"\n  by(simp add: trace_rest_closure.simps exI[where x=\"[]\"])\n\nlemma trace_rest_closure_step:\n  assumes \"trace_rest_eq rest1 rest2 IA IU p q\"\n    and \"trace_rest_closure rest1 rest2 IA IU p q p' q'\"\n  shows trace_rest_closure_step_rfunc_adv: \n    \"ia \\<in> IA \\<Longrightarrow> bind_spmf p' (\\<lambda>s1. map_spmf fst (rfunc_adv rest1 s1 ia)) = bind_spmf q' (\\<lambda>s2. map_spmf fst (rfunc_adv rest2 s2 ia))\"\n    (is \"PROP ?thesis1\")\n    and trace_rest_closure_step_rfunc_usr:\n    \"iu \\<in> IU \\<Longrightarrow> bind_spmf p' (\\<lambda>s1. map_spmf fst (rfunc_usr rest1 s1 iu)) = bind_spmf q' (\\<lambda>s2. map_spmf fst (rfunc_usr rest2 s2 iu))\"\n    (is \"PROP ?thesis2\")\nproof -\n  from assms(2) obtain tr where p: \"p' = trace_rest_aux rest1 p tr\"\n    and q: \"q' = trace_rest_aux rest2 q tr\"\n    and tr: \"set tr \\<subseteq> IA \\<times> UNIV <+> IU \\<times> UNIV\" by cases\n  from trace_rest_eqD[OF assms(1) tr] p q\n  show \"PROP ?thesis1\" and \"PROP ?thesis2\"\n    by(simp_all add: trace_rest_conv_trace_rest_aux)\nqed\n\nlemma trace_rest_closure_sim:\n  fixes rest1 rest2 IA IU p q\n  defines \"S \\<equiv> trace_rest_closure rest1 rest2 IA IU p q\"\n  assumes \"S p' q'\"\n  shows trace_rest_closure_sim_rfunc_adv: \"ia \\<in> IA \n    \\<Longrightarrow> S (cond_spmf_fst (bind_spmf p' (\\<lambda>s1. rfunc_adv rest1 s1 ia)) oa) \n          (cond_spmf_fst (bind_spmf q' (\\<lambda>s2. rfunc_adv rest2 s2 ia)) oa)\"\n    (is \"PROP ?thesis1\")\n    and trace_rest_closure_sim_rfunc_usr: \"iu \\<in> IU \n    \\<Longrightarrow> S (cond_spmf_fst (bind_spmf p' (\\<lambda>s1. rfunc_usr rest1 s1 iu)) ou)\n          (cond_spmf_fst (bind_spmf q' (\\<lambda>s2. rfunc_usr rest2 s2 iu)) ou)\"\n    (is \"PROP ?thesis2\")\nproof -\n  from assms(2) obtain tr where p: \"p' = trace_rest_aux rest1 p tr\"\n    and q: \"q' = trace_rest_aux rest2 q tr\"\n    and tr: \"set tr \\<subseteq> IA \\<times> UNIV <+> IU \\<times> UNIV\" unfolding S_def by cases\n  show \"PROP ?thesis1\" using p q tr\n    by(auto simp add: S_def trace_rest_closure.simps trace_rest_aux_append intro!: exI[where x=\"tr @ [Inl (_, _)]\"])\n  show \"PROP ?thesis2\" using p q tr\n    by(auto simp add: S_def trace_rest_closure.simps trace_rest_aux_append intro!: exI[where x=\"tr @ [Inr (_, _)]\"])\nqed\n\nproposition trace_rest_eq_complete:\n  assumes \"trace_rest_eq rest1 rest2 IA IU p q\"\n  obtains S\n  where \"S p q\"\n    and \"\\<And>p q ia. \\<lbrakk> S p q; ia \\<in> IA \\<rbrakk> \\<Longrightarrow> \n      bind_spmf p (\\<lambda>s1. map_spmf fst (rfunc_adv rest1 s1 ia)) = bind_spmf q (\\<lambda>s2. map_spmf fst (rfunc_adv rest2 s2 ia))\"\n    and \"\\<And>p q ia oa. \\<lbrakk> S p q; ia \\<in> IA \\<rbrakk>\n      \\<Longrightarrow> S (cond_spmf_fst (bind_spmf p (\\<lambda>s1. rfunc_adv rest1 s1 ia)) oa) (cond_spmf_fst (bind_spmf q (\\<lambda>s2. rfunc_adv rest2 s2 ia)) oa)\"\n    and \"\\<And>p q iu. \\<lbrakk> S p q; iu \\<in> IU \\<rbrakk> \\<Longrightarrow> \n      bind_spmf p (\\<lambda>s1. map_spmf fst (rfunc_usr rest1 s1 iu)) = bind_spmf q (\\<lambda>s2. map_spmf fst (rfunc_usr rest2 s2 iu))\"\n    and \"\\<And>p q iu ou. \\<lbrakk> S p q; iu \\<in> IU \\<rbrakk>\n      \\<Longrightarrow> S (cond_spmf_fst (bind_spmf p (\\<lambda>s1. rfunc_usr rest1 s1 iu)) ou) (cond_spmf_fst (bind_spmf q (\\<lambda>s2. rfunc_usr rest2 s2 iu)) ou)\"\nproof -\n  show thesis\n    by(rule that[where S=\"trace_rest_closure rest1 rest2 IA IU p q\"])\n      (auto intro: trace_rest_closure_start trace_rest_closure_step[OF assms] trace_rest_closure_sim (* trace_rest_closure_weight[OF assms] *))\nqed\n\ndefinition callee_of_core\n  :: \"('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core\n    \\<Rightarrow> ('s_core, 'event + 'iadv_core + 'iusr_core, unit + 'oadv_core + 'ousr_core) oracle'\" where\n  \"callee_of_core core =\n   map_fun id (map_fun id (map_spmf (Pair ()))) (cpoke core) \\<oplus>\\<^sub>O cfunc_adv core \\<oplus>\\<^sub>O cfunc_usr core\"\n\nlemma callee_of_core_simps [simp]:\n  \"callee_of_core core s (Inl e) = map_spmf (Pair (Inl ())) (cpoke core s e)\"\n  \"callee_of_core core s (Inr (Inl iadv_core)) = map_spmf (apfst (Inr \\<circ> Inl)) (cfunc_adv core s iadv_core)\"\n  \"callee_of_core core s (Inr (Inr iusr_core)) = map_spmf (apfst (Inr \\<circ> Inr)) (cfunc_usr core s iusr_core)\"\n  by(simp_all add: callee_of_core_def spmf.map_comp o_def apfst_def prod.map_comp id_def)\n\nlemma WT_callee_of_core [WT_intro]:\n  assumes WT: \"WT_core \\<I>_adv \\<I>_usr I core\"\n     and I: \"I s\"\n   shows \"\\<I>_full \\<oplus>\\<^sub>\\<I> (\\<I>_adv \\<oplus>\\<^sub>\\<I> \\<I>_usr) \\<turnstile>c callee_of_core core s \\<surd>\"\n  apply(rule WT_calleeI)\n  subgoal for x y s' using I WT_coreD[OF WT]\n    by(auto simp add: callee_of_core_def plus_oracle_def split!: sum.splits)\n  done\n\nlemma WT_core_callee_invariant_on [WT_intro]:\n  assumes WT: \"WT_core \\<I>_adv \\<I>_usr I core\"\n  shows \"callee_invariant_on (callee_of_core core) I (\\<I>_full \\<oplus>\\<^sub>\\<I> (\\<I>_adv \\<oplus>\\<^sub>\\<I> \\<I>_usr))\"\n  apply unfold_locales\n  subgoal for s x y s' by(auto simp add: callee_of_core_def plus_oracle_def split!: sum.splits dest: WT_coreD[OF assms])\n  subgoal by(rule WT_callee_of_core[OF WT])\n  done\n\ndefinition callee_of_rest\n  :: \"('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme\n    \\<Rightarrow> ('s_rest, 'iadv_rest + 'iusr_rest, 'oadv_rest \\<times> 'event list + 'ousr_rest \\<times> 'event list) oracle'\" where\n  \"callee_of_rest rest = rfunc_adv rest \\<oplus>\\<^sub>O rfunc_usr rest\"\n\nlemma callee_of_rest_simps [simp]:\n  \"callee_of_rest rest s (Inl iadv_rest) = map_spmf (apfst Inl) (rfunc_adv rest s iadv_rest)\"\n  \"callee_of_rest rest s (Inr iusr_rest) = map_spmf (apfst Inr) (rfunc_usr rest s iusr_rest)\"\n  by(simp_all add: callee_of_rest_def)\n\nlemma WT_callee_of_rest [WT_intro]:\n  assumes WT: \"WT_rest \\<I>_adv \\<I>_usr I rest\"\n    and I: \"I s\"\n  shows \"e\\<I> \\<I>_adv \\<oplus>\\<^sub>\\<I> e\\<I> \\<I>_usr \\<turnstile>c callee_of_rest rest s \\<surd>\"\n  apply(rule WT_calleeI)\n  subgoal for x y s' using I WT_restD[OF WT]\n    by(auto simp add: callee_of_core_def plus_oracle_def split!: sum.splits)\n  done\n\nfun fuse_callee \n  :: \"('iadv_core + 'iadv_rest) + ('iusr_core + 'iusr_rest) \\<Rightarrow>\n      (('oadv_core + 'oadv_rest) + ('ousr_core + 'ousr_rest),\n       ('event + 'iadv_core + 'iusr_core) + ('iadv_rest + 'iusr_rest),\n       (unit + 'oadv_core + 'ousr_core) + ('oadv_rest \\<times> 'event list + 'ousr_rest \\<times> 'event list)) gpv\"\n  where\n  \"fuse_callee (Inl (Inl iadv_core)) = Pause (Inl (Inr (Inl iadv_core))) (\\<lambda>x. case x of\n       Inl (Inr (Inl oadv_core)) \\<Rightarrow> Done (Inl (Inl oadv_core))\n     | _ \\<Rightarrow> Fail)\"\n| \"fuse_callee (Inl (Inr iadv_rest)) = Pause (Inr (Inl iadv_rest)) (\\<lambda>x. case x of\n       Inr (Inl (oadv_rest, es)) \\<Rightarrow> bind_gpv (pauses (map (Inl \\<circ> Inl) es)) (\\<lambda>_. Done (Inl (Inr oadv_rest)))\n     | _ \\<Rightarrow> Fail)\"\n| \"fuse_callee (Inr (Inl iusr_core)) = Pause (Inl (Inr (Inr iusr_core))) (\\<lambda>x. case x of\n       Inl (Inr (Inr oadv_core)) \\<Rightarrow> Done (Inr (Inl oadv_core)))\"\n| \"fuse_callee (Inr (Inr iusr_rest)) = Pause (Inr (Inr iusr_rest)) (\\<lambda>x. case x of\n       Inr (Inr (ousr_rest, es)) \\<Rightarrow> bind_gpv (pauses (map (Inl \\<circ> Inl) es)) (\\<lambda>_. Done (Inr (Inr ousr_rest))))\"\n\ncase_of_simps fuse_callee_case: fuse_callee.simps\n\n(* parametric_constant fuse_callee_parametric [transfer_rule]: fuse_callee_case *)\n\ndefinition fuse_converter \n  :: \"(('iadv_core + 'iadv_rest) + ('iusr_core + 'iusr_rest), \n       ('oadv_core + 'oadv_rest) + ('ousr_core + 'ousr_rest),\n       ('event + 'iadv_core + 'iusr_core) + ('iadv_rest + 'iusr_rest),\n       (unit + 'oadv_core + 'ousr_core) + ('oadv_rest \\<times> 'event list + 'ousr_rest \\<times> 'event list)) converter\"\n  where\n  \"fuse_converter = converter_of_callee (stateless_callee fuse_callee) ()\"\n\nlemma fuse_converter:\n  \"resource_of_oracle (fused_resource.fuse core rest) (s_core, s_rest) = \n  fuse_converter \\<rhd> (resource_of_oracle (callee_of_core core) s_core \\<parallel> resource_of_oracle (callee_of_rest rest) s_rest)\"\n  unfolding fuse_converter_def resource_of_parallel_oracle[symmetric] attach_CNV_RES attach_stateless_callee resource_of_oracle_extend_state_oracle\nproof(rule arg_cong2[where f=resource_of_oracle]; clarsimp simp add: fun_eq_iff)\n  interpret fused_resource core core_init for core_init .\n  have \"foldl_spmf (map_fun id (map_fun (Inl \\<circ> Inl) id) (map_fun id (map_fun id (map_spmf snd)) (callee_of_core core \\<ddagger>\\<^sub>O callee_of_rest rest))) (return_spmf (s_core, s_rest)) xs\n     = map_spmf (\\<lambda>s_core. (s_core, s_rest)) (foldl_spmf (cpoke core) (return_spmf s_core) xs)\" for s_core s_rest xs\n    by(induction xs arbitrary: s_core)\n      (simp_all add: spmf.map_comp foldl_spmf_Cons' map_bind_spmf bind_map_spmf o_def del: foldl_spmf_Cons)\n  then show \"fuse rest (s_core, s_rest) q = exec_gpv (callee_of_core core \\<ddagger>\\<^sub>O callee_of_rest rest) (fuse_callee q) (s_core, s_rest)\"\n    for s_core s_rest q\n    by(cases q rule: fuse_callee.cases; clarsimp simp add: map_bind_spmf bind_map_spmf exec_gpv_bind exec_gpv_pauses intro!: bind_spmf_cong[OF refl]; simp add: map_spmf_conv_bind_spmf[symmetric])\nqed\n\nlemma trace_eq_callee_of_coreI:\n  \"trace_callee_eq (callee_of_core core1) (callee_of_core core2) (E <+> IA <+> IU) p q\"\n  if \"trace_core_eq core1 core2 E IA IU p q\"\nproof -\n  from that obtain S_core \n    where core_start: \"S_core p q\"\n      and step_cpoke: \"\\<And>p q e. S_core p q \\<Longrightarrow> e \\<in> E\n        \\<Longrightarrow> weight_spmf (bind_spmf p (\\<lambda>s. cpoke core1 s e)) = weight_spmf (bind_spmf q (\\<lambda>s. cpoke core2 s e))\"\n      and sim_cpoke: \"\\<And>p q e. S_core p q \\<Longrightarrow> e \\<in> E \n       \\<Longrightarrow> S_core (mk_lossless (bind_spmf p (\\<lambda>s. cpoke core1 s e))) (mk_lossless (bind_spmf q (\\<lambda>s. cpoke core2 s e)))\"\n      and step_cfunc_adv: \"\\<And>p q ia. \\<lbrakk> S_core p q; ia \\<in> IA \\<rbrakk>\n       \\<Longrightarrow> bind_spmf p (\\<lambda>s1. map_spmf fst (cfunc_adv core1 s1 ia)) = bind_spmf q (\\<lambda>s2. map_spmf fst (cfunc_adv core2 s2 ia))\"\n      and sim_cfunc_adv: \"\\<And>p q ia oa. \\<lbrakk> S_core p q; ia \\<in> IA \\<rbrakk> \\<Longrightarrow>\n        S_core (cond_spmf_fst (bind_spmf p (\\<lambda>s1. cfunc_adv core1 s1 ia)) oa)\n               (cond_spmf_fst (bind_spmf q (\\<lambda>s2. cfunc_adv core2 s2 ia)) oa)\"\n      and step_cfunc_usr: \"\\<And>p q iu. \\<lbrakk> S_core p q; iu \\<in> IU \\<rbrakk>\n        \\<Longrightarrow> bind_spmf p (\\<lambda>s1. map_spmf fst (cfunc_usr core1 s1 iu)) = bind_spmf q (\\<lambda>s2. map_spmf fst (cfunc_usr core2 s2 iu))\"\n      and sim_cfunc_usr: \"\\<And>p q iu ou. \\<lbrakk> S_core p q; iu \\<in> IU \\<rbrakk> \\<Longrightarrow>\n        S_core (cond_spmf_fst (bind_spmf p (\\<lambda>s1. cfunc_usr core1 s1 iu)) ou)\n               (cond_spmf_fst (bind_spmf q (\\<lambda>s2. cfunc_usr core2 s2 iu)) ou)\"\n    by(rule trace_core_eq_complete) blast\n\n  show ?thesis using core_start\n  proof(coinduct rule: trace'_eqI_sim[consumes 1, case_names step sim])\n    case (step p q a)\n    then consider (cpoke) e where \"a = Inl e\" \"e \\<in> E\"\n      | (cfunc_adv) ia where \"a = Inr (Inl ia)\" \"ia \\<in> IA\"\n      | (cfunc_usr) iu where \"a = Inr (Inr iu)\" \"iu \\<in> IU\" by auto\n    then show ?case\n    proof cases\n      case cpoke\n      with step_cpoke[OF step(1), of e] show ?thesis \n        by(simp add: spmf.map_comp o_def map_spmf_const weight_bind_spmf)\n          (auto intro!: spmf_eqI simp add: spmf_bind spmf_scale_spmf max_def min_absorb2 weight_spmf_le_1)\n    next\n      case cfunc_adv\n      with step_cfunc_adv[OF step(1) cfunc_adv(2)] show ?thesis\n        by(simp add: spmf.map_comp)(simp add: spmf.map_comp[symmetric] map_bind_spmf[unfolded o_def, symmetric])\n    next\n      case cfunc_usr\n      with step_cfunc_usr[OF step(1) cfunc_usr(2)] show ?thesis\n        by(simp add: spmf.map_comp)(simp add: spmf.map_comp[symmetric] map_bind_spmf[unfolded o_def, symmetric])\n    qed \n  next\n    case (sim p q a res b s')\n    then consider (cpoke) e where \"a = Inl e\" \"e \\<in> E\"\n      | (cfunc_adv) ia where \"a = Inr (Inl ia)\" \"ia \\<in> IA\"\n      | (cfunc_usr) iu where \"a = Inr (Inr iu)\" \"iu \\<in> IU\" by auto\n    then show ?case\n    proof cases\n      case cpoke\n      with sim_cpoke[OF sim(1) , of e] sim show ?thesis \n        by(clarsimp simp add: map_bind_spmf[unfolded o_def, symmetric])\n    next\n      case cfunc_adv\n      with sim_cfunc_adv[OF sim(1) cfunc_adv(2)] sim show ?thesis\n        apply(clarsimp simp add: map_bind_spmf[unfolded o_def, symmetric] apfst_def map_prod_def)\n        apply(subst (1 2) cond_spmf_fst_map_prod_inj)\n         apply(simp_all add: o_def[symmetric] inj_compose del: o_apply)\n        done\n    next\n      case cfunc_usr\n      with sim_cfunc_usr[OF sim(1) cfunc_usr(2)] sim show ?thesis\n        apply(clarsimp simp add: map_bind_spmf[unfolded o_def, symmetric] apfst_def map_prod_def)\n        apply(subst (1 2) cond_spmf_fst_map_prod_inj)\n         apply(simp_all add: o_def[symmetric] inj_compose del: o_apply)\n        done\n    qed\n  qed\nqed\n\nlemma trace_eq_callee_of_restI:\n  \"trace_callee_eq (callee_of_rest rest1) (callee_of_rest rest2) (IA <+> IU) p q\"\n  if \"trace_rest_eq rest1 rest2 IA IU p q\"\nproof -\n  from that obtain S_rest \n    where rest_start: \"S_rest p q\"\n      and step_rfunc_adv: \"\\<And>p q ia. \\<lbrakk> S_rest p q; ia \\<in> IA \\<rbrakk>\n       \\<Longrightarrow> bind_spmf p (\\<lambda>s1. map_spmf fst (rfunc_adv rest1 s1 ia)) = bind_spmf q (\\<lambda>s2. map_spmf fst (rfunc_adv rest2 s2 ia))\"\n      and sim_rfunc_adv: \"\\<And>p q ia oa. \\<lbrakk> S_rest p q; ia \\<in> IA \\<rbrakk> \\<Longrightarrow>\n        S_rest (cond_spmf_fst (bind_spmf p (\\<lambda>s1. rfunc_adv rest1 s1 ia)) oa)\n               (cond_spmf_fst (bind_spmf q (\\<lambda>s2. rfunc_adv rest2 s2 ia)) oa)\"\n      and step_rfunc_usr: \"\\<And>p q iu. \\<lbrakk> S_rest p q; iu \\<in> IU \\<rbrakk>\n        \\<Longrightarrow> bind_spmf p (\\<lambda>s1. map_spmf fst (rfunc_usr rest1 s1 iu)) = bind_spmf q (\\<lambda>s2. map_spmf fst (rfunc_usr rest2 s2 iu))\"\n      and sim_rfunc_usr: \"\\<And>p q iu ou. \\<lbrakk> S_rest p q; iu \\<in> IU \\<rbrakk> \\<Longrightarrow>\n        S_rest (cond_spmf_fst (bind_spmf p (\\<lambda>s1. rfunc_usr rest1 s1 iu)) ou)\n               (cond_spmf_fst (bind_spmf q (\\<lambda>s2. rfunc_usr rest2 s2 iu)) ou)\"\n    by(rule trace_rest_eq_complete) blast\n\n  show ?thesis using rest_start\n  proof(coinduct rule: trace'_eqI_sim[consumes 1, case_names step sim])\n    case (step p q a)\n    then consider (rfunc_adv) ia where \"a = Inl ia\" \"ia \\<in> IA\"\n      | (rfunc_usr) iu where \"a = Inr iu\" \"iu \\<in> IU\" by auto\n    then show ?case\n    proof cases\n      case rfunc_adv\n      with step_rfunc_adv[OF step(1) rfunc_adv(2)] show ?thesis\n        by(simp add: spmf.map_comp)(simp add: spmf.map_comp[symmetric] map_bind_spmf[unfolded o_def, symmetric])\n    next\n      case rfunc_usr\n      with step_rfunc_usr[OF step(1) rfunc_usr(2)] show ?thesis\n        by(simp add: spmf.map_comp)(simp add: spmf.map_comp[symmetric] map_bind_spmf[unfolded o_def, symmetric])\n    qed \n  next\n    case (sim p q a res b s')\n    then consider (rfunc_adv) ia where \"a = Inl ia\" \"ia \\<in> IA\"\n      | (rfunc_usr) iu where \"a = Inr iu\" \"iu \\<in> IU\" by auto\n    then show ?case\n    proof cases\n      case rfunc_adv\n      with sim_rfunc_adv[OF sim(1) rfunc_adv(2)] sim show ?thesis\n        by(clarsimp simp add: map_bind_spmf[unfolded o_def, symmetric] apfst_def map_prod_def)\n          (subst (1 2) cond_spmf_fst_map_prod_inj; simp)\n    next\n      case rfunc_usr\n      with sim_rfunc_usr[OF sim(1) rfunc_usr(2)] sim show ?thesis\n        by(clarsimp simp add: map_bind_spmf[unfolded o_def, symmetric] apfst_def map_prod_def)\n          (subst (1 2) cond_spmf_fst_map_prod_inj; simp)\n    qed\n  qed\nqed\n\nlemma trace_callee_resource_of_oracle:\n  \"trace_callee run_resource (map_spmf (resource_of_oracle callee) p) = trace_callee callee p\"\n  (is \"?lhs = ?rhs\")\nproof(intro ext)\n  show \"?lhs tr x = ?rhs tr x\" for tr x\n  proof(induction tr arbitrary: p)\n    case Nil show ?case by(simp add: bind_map_spmf o_def spmf.map_comp)\n  next\n    case (Cons a tr)\n    obtain y z where a [simp]: \"a = (y, z)\" by(cases a)\n    have \"trace_callee run_resource (map_spmf (RES callee) p) (a # tr) x =\n      trace_callee run_resource (cond_spmf_fst (map_spmf (\\<lambda>(x, y). (x, RES callee y)) (p \\<bind> (\\<lambda>x. (callee x y)))) z) tr x\"\n      by(clarsimp simp add: bind_map_spmf o_def map_prod_def map_bind_spmf)\n    also have \"\\<dots> = trace_callee run_resource (map_spmf (RES callee) (cond_spmf_fst (p \\<bind> (\\<lambda>x. (callee x y))) z)) tr x\"\n      by(subst cond_spmf_fst_map_prod_inj) simp_all\n    finally show ?case using Cons.IH by simp\n  qed\nqed\n\nlemma trace_callee_resource_of_oracle':\n  \"trace_callee run_resource (return_spmf (resource_of_oracle callee s)) = trace_callee callee (return_spmf s)\"\n  using trace_callee_resource_of_oracle[where p=\"return_spmf s\"]\n  by simp\n\nlemma trace_eq_resource_of_oracle:\n  \"trace_eq A (map_spmf (resource_of_oracle callee1) p) (map_spmf (resource_of_oracle callee2) q) =\n   trace_callee_eq callee1 callee2 A p q\"\n  unfolding trace_callee_eq_def trace_callee_resource_of_oracle by(rule refl)\n\nlemma WT_fuse_converter [WT_intro]:\n  \"(\\<I>AC \\<oplus>\\<^sub>\\<I> map_\\<I> id fst \\<I>AR) \\<oplus>\\<^sub>\\<I> (\\<I>UC \\<oplus>\\<^sub>\\<I> map_\\<I> id fst \\<I>UR), (\\<I>E \\<oplus>\\<^sub>\\<I> (\\<I>AC \\<oplus>\\<^sub>\\<I> \\<I>UC)) \\<oplus>\\<^sub>\\<I> (\\<I>AR \\<oplus>\\<^sub>\\<I> \\<I>UR) \\<turnstile>\\<^sub>C fuse_converter \\<surd>\"\n  if \"\\<forall>x. \\<forall>(y, es)\\<in>responses_\\<I> \\<I>AR x. set es \\<subseteq> outs_\\<I> \\<I>E\" \"\\<forall>x. \\<forall>(y, es)\\<in>responses_\\<I> \\<I>UR x. set es \\<subseteq> outs_\\<I> \\<I>E\"\n  unfolding fuse_converter_def using that\n  by(intro WT_converter_of_callee)\n    (fastforce simp add: stateless_callee_def image_image intro: rev_image_eqI intro!: WT_gpv_pauses split: if_split_asm)+\n\ntheorem fuse_trace_eq:\n  fixes core1 :: \"('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core\"\n    and core2 :: \"('s_core', 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core\"\n    and rest1 :: \"('s_rest, 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more1) rest_scheme\"\n    and rest2 :: \"('s_rest', 'event, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more2) rest_scheme\"\n  assumes core: \"trace_core_eq core1 core2 (outs_\\<I> \\<I>E) (outs_\\<I> \\<I>CA) (outs_\\<I> \\<I>CU) (return_spmf s_core) (return_spmf s_core')\"\n    and rest: \"trace_rest_eq rest1 rest2 (outs_\\<I> \\<I>RA) (outs_\\<I> \\<I>RU) (return_spmf s_rest) (return_spmf s_rest')\"\n    and IC1: \"callee_invariant_on (callee_of_core core1) IC1 (\\<I>E \\<oplus>\\<^sub>\\<I> (\\<I>CA \\<oplus>\\<^sub>\\<I> \\<I>CU))\" \"IC1 s_core\"\n    and IC2: \"callee_invariant_on (callee_of_core core2) IC2 (\\<I>E \\<oplus>\\<^sub>\\<I> (\\<I>CA \\<oplus>\\<^sub>\\<I> \\<I>CU))\" \"IC2 s_core'\"\n    and IR1: \"callee_invariant_on (callee_of_rest rest1) IR1 (\\<I>RA \\<oplus>\\<^sub>\\<I> \\<I>RU)\" \"IR1 s_rest\"\n    and IR2: \"callee_invariant_on (callee_of_rest rest2) IR2 (\\<I>RA \\<oplus>\\<^sub>\\<I> \\<I>RU)\" \"IR2 s_rest'\"\n    and E1 [WT_intro]: \"\\<forall>x. \\<forall>(y, es)\\<in>responses_\\<I> \\<I>RA x. set es \\<subseteq> outs_\\<I> \\<I>E\"\n    and E2 [WT_intro]: \"\\<forall>x. \\<forall>(y, es)\\<in>responses_\\<I> \\<I>RU x. set es \\<subseteq> outs_\\<I> \\<I>E\"\n  shows \"trace_callee_eq (fused_resource.fuse core1 rest1) (fused_resource.fuse core2 rest2)\n    ((outs_\\<I> \\<I>CA <+> outs_\\<I> \\<I>RA) <+> (outs_\\<I> \\<I>CU <+> outs_\\<I> \\<I>RU)) (return_spmf (s_core, s_rest)) (return_spmf (s_core', s_rest'))\"\nproof -\n  let ?\\<I>C = \"\\<I>E \\<oplus>\\<^sub>\\<I> (\\<I>CA \\<oplus>\\<^sub>\\<I> \\<I>CU)\"\n  let ?\\<I>R = \"\\<I>RA \\<oplus>\\<^sub>\\<I> \\<I>RU\"\n  let ?\\<I>' = \"?\\<I>C \\<oplus>\\<^sub>\\<I> ?\\<I>R\"\n  let ?\\<I> = \"(\\<I>CA \\<oplus>\\<^sub>\\<I> map_\\<I> id fst \\<I>RA) \\<oplus>\\<^sub>\\<I> (\\<I>CU \\<oplus>\\<^sub>\\<I> map_\\<I> id fst \\<I>RU)\"\n\n  interpret fuse1: fused_resource core1 s1 for s1 .\n  interpret fuse2: fused_resource core2 s2 for s2 .\n  interpret IC1: callee_invariant_on \"callee_of_core core1\" IC1 ?\\<I>C by fact\n  interpret IC2: callee_invariant_on \"callee_of_core core2\" IC2 ?\\<I>C by fact\n  interpret IR1: callee_invariant_on \"callee_of_rest rest1\" IR1 ?\\<I>R by fact\n  interpret IR2: callee_invariant_on \"callee_of_rest rest2\" IR2 ?\\<I>R by fact\n\n  from core have \"outs_\\<I> ?\\<I>C \\<turnstile>\\<^sub>C callee_of_core core1(s_core) \\<approx> callee_of_core core2(s_core')\"\n    by(simp add: trace_eq_callee_of_coreI)\n  hence \"outs_\\<I> ?\\<I>C \\<turnstile>\\<^sub>R RES (callee_of_core core1) s_core \\<approx> RES (callee_of_core core2) s_core'\" by simp\n  moreover have \"outs_\\<I> ?\\<I>R \\<turnstile>\\<^sub>C callee_of_rest rest1(s_rest) \\<approx> callee_of_rest rest2(s_rest')\" using rest\n    by(simp add: trace_eq_callee_of_restI)\n  hence \"outs_\\<I> ?\\<I>R \\<turnstile>\\<^sub>R RES (callee_of_rest rest1) s_rest \\<approx> RES (callee_of_rest rest2) s_rest'\" by simp\n  ultimately have \"outs_\\<I> ?\\<I>' \\<turnstile>\\<^sub>R\n    RES (callee_of_core core1) s_core \\<parallel> RES (callee_of_rest rest1) s_rest \\<approx>\n    RES (callee_of_core core2) s_core' \\<parallel> RES (callee_of_rest rest2) s_rest'\"\n    by(simp add: trace_eq'_parallel_resource)\n  hence \"outs_\\<I> ?\\<I> \\<turnstile>\\<^sub>R fuse_converter \\<rhd> (RES (callee_of_core core1) s_core \\<parallel> RES (callee_of_rest rest1) s_rest) \\<approx>\n                      fuse_converter \\<rhd> (RES (callee_of_core core2) s_core' \\<parallel> RES (callee_of_rest rest2) s_rest')\"\n    by(rule attach_trace_eq')(intro WT_intro IC1.WT_resource_of_oracle IC1 IC2.WT_resource_of_oracle IC2 IR1.WT_resource_of_oracle IR1 IR2.WT_resource_of_oracle IR2)+\n  hence \"trace_eq' (outs_\\<I> ?\\<I>) (resource_of_oracle (fuse1.fuse rest1) (s_core, s_rest)) (resource_of_oracle (fuse2.fuse rest2) (s_core', s_rest'))\"\n    unfolding fuse_converter by simp\n  then show ?thesis by simp\nqed\n\n\ninductive trace_eq_simcl :: \"('s1 spmf \\<Rightarrow> 's2 spmf \\<Rightarrow> bool) \\<Rightarrow> 's1 spmf \\<Rightarrow> 's2 spmf \\<Rightarrow> bool\"\n  for S where\n  base: \"trace_eq_simcl S p q\" if \"S p q\" for p q\n| bind_nat: \"trace_eq_simcl S (bind_spmf p f) (bind_spmf p g)\" \nif \"\\<And>x :: nat. x \\<in> set_spmf p \\<Longrightarrow> S (f x) (g x)\"\n\nlemma trace_eq_simcl_bindI [intro?]: \"trace_eq_simcl S (bind_spmf p f) (bind_spmf p g)\"\n  if \"\\<And>x. x \\<in> set_spmf p \\<Longrightarrow> S (f x) (g x)\"\n  by(subst (1 2) bind_spmf_to_nat_on[symmetric])(auto intro!: trace_eq_simcl.bind_nat simp add: that)\n\nlemma trace_eq_simcl_bind: \"trace_eq_simcl S (bind_spmf p f) (bind_spmf p g)\"\n  if *: \"\\<And>x :: 'a. x \\<in> set_spmf p \\<Longrightarrow> trace_eq_simcl S (f x) (g x)\"\nproof -\n  obtain P :: \"'a \\<Rightarrow> nat spmf\" and F G where\n    **: \"\\<And>x. x \\<in> set_spmf p \\<Longrightarrow> f x = bind_spmf (P x) (F x) \\<and> g x = bind_spmf (P x) (G x) \\<and> (\\<forall>y\\<in>set_spmf (P x). S (F x y) (G x y))\"\n    apply(atomize_elim)\n    apply(subst choice_iff[symmetric])+\n    apply(fastforce dest!: * elim!: trace_eq_simcl.cases intro: exI[where x=\"return_spmf _\"])\n    done\n  have \"bind_spmf p f = bind_spmf (bind_spmf p (\\<lambda>x. map_spmf (Pair x) (P x))) (\\<lambda>(x, y). F x y)\"\n    by(simp add: bind_map_spmf o_def ** cong: bind_spmf_cong)\n  moreover have \"bind_spmf p g = bind_spmf (bind_spmf p (\\<lambda>x. map_spmf (Pair x) (P x))) (\\<lambda>(x, y). G x y)\"\n    by(simp add: bind_map_spmf o_def ** cong: bind_spmf_cong)\n  ultimately show ?thesis  by(simp only:)(rule trace_eq_simcl_bindI; clarsimp simp add: **)\nqed\n\nlemma trace_eq_simcl_bind1_scale: \"trace_eq_simcl S (bind_spmf p f) (scale_spmf (weight_spmf p) q)\"\n  if \"\\<forall>x\\<in>set_spmf p. trace_eq_simcl S (f x) q\"\nproof -\n  have \"trace_eq_simcl S (bind_spmf p f) (bind_spmf p (\\<lambda>_. q))\"\n    by(rule trace_eq_simcl_bind)(simp add: that)\n  thus ?thesis by(simp add: bind_spmf_const)\nqed\n\nlemma trace_eq_simcl_bind1: \"trace_eq_simcl S (bind_spmf p f) q\"\n  if \"\\<forall>x\\<in>set_spmf p. trace_eq_simcl S (f x) q\" \"lossless_spmf p\"\n  using trace_eq_simcl_bind1_scale[OF that(1)] that(2) by(simp add: lossless_weight_spmfD)\n\nlemma trace_eq_simcl_bind2_scale: \"trace_eq_simcl S (scale_spmf (weight_spmf q) p) (bind_spmf q f)\"\n  if \"\\<forall>x\\<in>set_spmf q. trace_eq_simcl S p (f x)\"\nproof -\n  have \"trace_eq_simcl S (bind_spmf q (\\<lambda>_. p)) (bind_spmf q f)\"\n    by(rule trace_eq_simcl_bind)(simp add: that)\n  thus ?thesis by(simp add: bind_spmf_const)\nqed\n\nlemma trace_eq_simcl_bind2: \"trace_eq_simcl S p (bind_spmf q f)\"\n  if \"\\<forall>x\\<in>set_spmf q. trace_eq_simcl S p (f x)\" \"lossless_spmf q\"\n  using trace_eq_simcl_bind2_scale[OF that(1)] that(2) by(simp add: lossless_weight_spmfD)\n\nlemma trace_eq_simcl_return_pmf_None [simp, intro!]: \"trace_eq_simcl S (return_pmf None) (return_pmf None)\" \n  for S :: \"'s1 spmf \\<Rightarrow> 's2 spmf \\<Rightarrow> bool\"\nproof -\n  have \"trace_eq_simcl S (bind_spmf (return_pmf None) (undefined :: nat \\<Rightarrow> 's1 spmf)) (bind_spmf (return_pmf None) (undefined :: nat \\<Rightarrow> 's2 spmf))\"\n    by(rule trace_eq_simcl_bindI) simp\n  then show ?thesis by simp\nqed\n\nlemma trace_eq_simcl_map: \"trace_eq_simcl S (map_spmf f p) (map_spmf g p)\"\n  if \"\\<forall>x\\<in>set_spmf p. S (return_spmf (f x)) (return_spmf (g x))\"\n  unfolding map_spmf_conv_bind_spmf\n  by(rule trace_eq_simcl_bindI)(simp add: that)\n\nlemma trace_eq_simcl_map1: \"trace_eq_simcl S (map_spmf f p) q\"\n  if \"\\<forall>x\\<in>set_spmf p. trace_eq_simcl S (return_spmf (f x)) q\" \"lossless_spmf p\"\n  unfolding map_spmf_conv_bind_spmf\n  by(rule trace_eq_simcl_bind1)(simp_all add: that)\n\nlemma trace_eq_simcl_map2: \"trace_eq_simcl S p (map_spmf f q)\"\n  if \"\\<forall>x\\<in>set_spmf q. trace_eq_simcl S p (return_spmf (f x))\" \"lossless_spmf q\"\n  unfolding map_spmf_conv_bind_spmf\n  by(rule trace_eq_simcl_bind2)(simp_all add: that)\n\nlemma trace_eq_simcl_return_spmf [simp]: \"trace_eq_simcl S (return_spmf x) (return_spmf y) \\<longleftrightarrow> S (return_spmf x) (return_spmf y)\"\n  apply(rule iffI)\n  subgoal by(erule trace_eq_simcl.cases; clarsimp dest!: sym[where s=\"return_spmf _\"])(auto 4 4 simp add: bind_eq_return_spmf dest!: lossless_spmfD_set_spmf_nonempty)\n  by(simp add: trace_eq_simcl.base)\n\nlemma trace_eq_simcl_callee:\n  fixes callee1 :: \"('a, 'b, 's1) callee\" and callee2 :: \"('a, 'b, 's2) callee\"\n  assumes step: \"\\<And>p q a. \\<lbrakk> S p q; a \\<in> A \\<rbrakk> \\<Longrightarrow>\n      bind_spmf p (\\<lambda>s. map_spmf fst (callee1 s a)) = bind_spmf q (\\<lambda>s. map_spmf fst (callee2 s a))\"\n    and sim: \"\\<And>p q a res b s'. \\<lbrakk> S p q; a \\<in> A; res \\<in> set_spmf q; (b, s') \\<in> set_spmf (callee2 res a) \\<rbrakk>\n      \\<Longrightarrow> trace_eq_simcl S (cond_spmf_fst (bind_spmf p (\\<lambda>s. callee1 s a)) b)\n            (cond_spmf_fst (bind_spmf q (\\<lambda>s. callee2 s a)) b)\"\n    and start: \"trace_eq_simcl S p q\" and a: \"a \\<in> A\"\n  shows trace_eq_simcl_callee_step: \"bind_spmf p (\\<lambda>s. map_spmf fst (callee1 s a)) = bind_spmf q (\\<lambda>s. map_spmf fst (callee2 s a))\" (is \"?step\")\n    and trace_eq_simcl_callee_sim: \"\\<And>res b s'. \\<lbrakk> res \\<in> set_spmf q; (b, s') \\<in> set_spmf (callee2 res a) \\<rbrakk>\n      \\<Longrightarrow> trace_eq_simcl S (cond_spmf_fst (bind_spmf p (\\<lambda>s. callee1 s a)) b)\n                            (cond_spmf_fst (bind_spmf q (\\<lambda>s. callee2 s a)) b)\" (is \"\\<And>res b s'. \\<lbrakk> ?res res; ?b res b s' \\<rbrakk> \\<Longrightarrow> ?sim res b s'\")\nproof -\n  show eq: ?step using start a by cases(auto intro!: bind_spmf_cong intro: step)\n  show \"?sim res b s'\" if \"?res res\" \"?b res b s'\" for res b s' using start\n  proof cases\n    case base then show ?thesis using a that by(rule sim)\n  next\n    case (bind_nat X f g)\n    let ?Y = \"cond_bind_spmf_fst X (\\<lambda>y. map_spmf fst (bind_spmf (f y) (\\<lambda>s. callee1 s a))) b\"\n    let ?Y' = \"cond_bind_spmf_fst X (\\<lambda>y. map_spmf fst (bind_spmf (g y) (\\<lambda>s. callee2 s a))) b\"\n    have \"cond_spmf_fst (bind_spmf p (\\<lambda>s. callee1 s a)) b = bind_spmf ?Y (\\<lambda>x. cond_spmf_fst (bind_spmf (f x) (\\<lambda>s. callee1 s a)) b)\"\n      unfolding bind_nat by(simp add: cond_spmf_fst_bind o_def)\n    moreover have \"cond_spmf_fst (bind_spmf q (\\<lambda>s. callee2 s a)) b = bind_spmf ?Y' (\\<lambda>x. cond_spmf_fst (bind_spmf (g x) (\\<lambda>s. callee2 s a)) b)\"\n      unfolding bind_nat by(simp add: cond_spmf_fst_bind o_def)\n    moreover have \"?Y = ?Y'\" using bind_nat eq\n      by(intro spmf_eqI)(fastforce simp add: map_bind_spmf o_def spmf_eq_0_set_spmf dest: step[OF _ a])\n    ultimately \n    show \"trace_eq_simcl S (cond_spmf_fst (bind_spmf p (\\<lambda>s. callee1 s a)) b)\n        (cond_spmf_fst (bind_spmf q (\\<lambda>s. callee2 s a)) b)\" using bind_nat a\n      by(simp)(rule trace_eq_simcl_bind; auto intro!: sim simp add: bind_UNION)\n  qed\nqed\n\nproposition trace'_eqI_sim_upto:\n  fixes callee1 :: \"('a, 'b, 's1) callee\" and callee2 :: \"('a, 'b, 's2) callee\"\n  assumes start: \"S p q\"\n    and step: \"\\<And>p q a. \\<lbrakk> S p q; a \\<in> A \\<rbrakk> \\<Longrightarrow>\n      bind_spmf p (\\<lambda>s. map_spmf fst (callee1 s a)) = bind_spmf q (\\<lambda>s. map_spmf fst (callee2 s a))\"\n    and sim: \"\\<And>p q a res b s'. \\<lbrakk> S p q; a \\<in> A; res \\<in> set_spmf q; (b, s') \\<in> set_spmf (callee2 res a) \\<rbrakk>\n      \\<Longrightarrow> trace_eq_simcl S (cond_spmf_fst (bind_spmf p (\\<lambda>s. callee1 s a)) b)\n            (cond_spmf_fst (bind_spmf q (\\<lambda>s. callee2 s a)) b)\"\n  shows \"trace_callee_eq callee1 callee2 A p q\"\nproof -\n  let ?S = \"trace_eq_simcl S\"\n  from start have \"?S p q\" by(rule trace_eq_simcl.base)\n  then show ?thesis by(rule trace'_eqI_sim)(rule trace_eq_simcl_callee[OF step sim]; assumption)+\nqed\n\nlemma trace_core_eq_simI_upto:\n  fixes core1 :: \"('s_core, 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core\"\n    and core2 :: \"('s_core', 'event, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core\"\n    and S :: \"'s_core spmf \\<Rightarrow> 's_core' spmf \\<Rightarrow> bool\"\n  assumes start: \"S p q\"\n    and step_cpoke: \"\\<And>p q e. \\<lbrakk> S p q; e \\<in> E \\<rbrakk> \\<Longrightarrow> \n      weight_spmf (bind_spmf p (\\<lambda>s. cpoke core1 s e)) = weight_spmf (bind_spmf q (\\<lambda>s. cpoke core2 s e))\"\n    and sim_cpoke: \"\\<And>p q e. \\<lbrakk> S p q; e \\<in> E \\<rbrakk> \\<Longrightarrow> \n      trace_eq_simcl S (mk_lossless (bind_spmf p (\\<lambda>s. cpoke core1 s e))) (mk_lossless (bind_spmf q (\\<lambda>s. cpoke core2 s e)))\"\n    and step_cfunc_adv: \"\\<And>p q ia. \\<lbrakk> S p q; ia \\<in> IA \\<rbrakk> \\<Longrightarrow> \n      bind_spmf p (\\<lambda>s1. map_spmf fst (cfunc_adv core1 s1 ia)) = bind_spmf q (\\<lambda>s2. map_spmf fst (cfunc_adv core2 s2 ia))\"\n    and sim_cfunc_adv: \"\\<And>p q ia s1 s2 s1' s2' oa. \\<lbrakk> S p q; ia \\<in> IA; \n      s1 \\<in> set_spmf p; s2 \\<in> set_spmf q; (oa, s1') \\<in> set_spmf (cfunc_adv core1 s1 ia); (oa, s2') \\<in> set_spmf (cfunc_adv core2 s2 ia) \\<rbrakk>\n      \\<Longrightarrow> trace_eq_simcl S (cond_spmf_fst (bind_spmf p (\\<lambda>s1. cfunc_adv core1 s1 ia)) oa) (cond_spmf_fst (bind_spmf q (\\<lambda>s2. cfunc_adv core2 s2 ia)) oa)\"\n    and step_cfunc_usr: \"\\<And>p q iu. \\<lbrakk> S p q; iu \\<in> IU \\<rbrakk> \\<Longrightarrow> \n      bind_spmf p (\\<lambda>s1. map_spmf fst (cfunc_usr core1 s1 iu)) = bind_spmf q (\\<lambda>s2. map_spmf fst (cfunc_usr core2 s2 iu))\"\n    and sim_cfunc_usr: \"\\<And>p q iu s1 s2 s1' s2' ou. \\<lbrakk> S p q; iu \\<in> IU; \n      s1 \\<in> set_spmf p; s2 \\<in> set_spmf q; (ou, s1') \\<in> set_spmf (cfunc_usr core1 s1 iu); (ou, s2') \\<in> set_spmf (cfunc_usr core2 s2 iu) \\<rbrakk>\n      \\<Longrightarrow> trace_eq_simcl S (cond_spmf_fst (bind_spmf p (\\<lambda>s1. cfunc_usr core1 s1 iu)) ou) (cond_spmf_fst (bind_spmf q (\\<lambda>s2. cfunc_usr core2 s2 iu)) ou)\"\n  shows \"trace_core_eq core1 core2 E IA IU p q\"\nproof -\n  let ?S = \"trace_eq_simcl S\"\n  from start have \"?S p q\" by(rule trace_eq_simcl.base)\n  then show ?thesis \n  proof(rule trace_core_eq_simI, goal_cases Step_cpoke Sim_cpoke Step_cfunc_adv Sim_cfunc_adv Step_cfunc_usr Sim_cfunc_usr)\n    { case (Step_cpoke p q e)\n      then show ?case using step_cpoke\n        by cases(auto simp add: weight_bind_spmf o_def intro!: Bochner_Integration.integral_cong_AE) }\n    note eq = this\n\n    case (Sim_cpoke p q e) then show ?case\n    proof cases\n      case base then show ?thesis using Sim_cpoke(2) by(rule sim_cpoke)\n    next\n      case (bind_nat X f g)\n      then have \"cond_bind_spmf X (\\<lambda>y. f y \\<bind> (\\<lambda>s. cpoke core1 s e)) UNIV = cond_bind_spmf X (\\<lambda>y. g y \\<bind> (\\<lambda>s. cpoke core2 s e)) UNIV\"\n        using eq[OF Sim_cpoke] step_cpoke Sim_cpoke\n        by(intro spmf_eqI)(simp add: weight_spmf_def measure_spmf_zero_iff bind_UNION spmf_eq_0_set_spmf)\n      then show ?thesis using bind_nat Sim_cpoke sim_cpoke\n        by(auto simp add: cond_bind_spmf cond_spmf_UNIV[symmetric] simp del: cond_spmf_UNIV intro: trace_eq_simcl_bind)\n    qed\n  next \n    { case (Step_cfunc_adv p q ia)\n      then show ?case using step_cfunc_adv by cases(auto intro!: bind_spmf_cong) }\n    note eq = this\n\n    case (Sim_cfunc_adv p q ia s1 s2 s1' s2' oa) then show ?case \n    proof cases\n      case base then show ?thesis using Sim_cfunc_adv(2-) by(rule sim_cfunc_adv)\n    next\n      case (bind_nat X f g)\n      then have \"cond_bind_spmf_fst X (\\<lambda>y. map_spmf fst (f y \\<bind> (\\<lambda>s1. cfunc_adv core1 s1 ia))) oa =\n            cond_bind_spmf_fst X (\\<lambda>y. map_spmf fst (g y \\<bind> (\\<lambda>s2. cfunc_adv core2 s2 ia))) oa\"\n        using eq[OF Sim_cfunc_adv(1,2)]\n        by(intro spmf_eqI)(fastforce simp add: map_bind_spmf o_def spmf_eq_0_set_spmf dest: step_cfunc_adv[OF _ Sim_cfunc_adv(2)])\n      then show ?thesis using bind_nat(3-) Sim_cfunc_adv(1-2)\n        unfolding bind_nat(1,2) bind_spmf_assoc\n        apply(subst (1 2) cond_spmf_fst_bind)\n        apply(simp add: o_def)\n        apply(rule trace_eq_simcl_bind)\n        apply clarsimp\n        apply(frule step_cfunc_adv[OF bind_nat(3) Sim_cfunc_adv(2), THEN arg_cong[where f=\"set_spmf\"], THEN equalityD2])\n        apply(clarsimp simp add: o_def bind_UNION)\n        apply(drule subsetD)\n         apply fastforce\n        apply(auto intro: sim_cfunc_adv)\n        done\n    qed\n  next\n    { case (Step_cfunc_usr p q iu)\n      then show ?case using step_cfunc_usr by cases(auto intro!: bind_spmf_cong) }\n    note eq = this\n\n    case (Sim_cfunc_usr p q iu s1 s2 s1' s2' ou) then show ?case\n    proof cases\n      case base then show ?thesis using Sim_cfunc_usr(2-) by(rule sim_cfunc_usr)\n    next\n      case (bind_nat X f g)\n      then have \"cond_bind_spmf_fst X (\\<lambda>y. map_spmf fst (f y \\<bind> (\\<lambda>s1. cfunc_usr core1 s1 iu))) ou =\n            cond_bind_spmf_fst X (\\<lambda>y. map_spmf fst (g y \\<bind> (\\<lambda>s2. cfunc_usr core2 s2 iu))) ou\"\n        using eq[OF Sim_cfunc_usr(1,2)]\n        by(intro spmf_eqI)(fastforce simp add: map_bind_spmf o_def spmf_eq_0_set_spmf dest: step_cfunc_usr[OF _ Sim_cfunc_usr(2)])\n      then show ?thesis using bind_nat(3-) Sim_cfunc_usr(1-2)\n        unfolding bind_nat(1,2) bind_spmf_assoc\n        apply(subst (1 2) cond_spmf_fst_bind)\n        apply(simp add: o_def)\n        apply(rule trace_eq_simcl_bind)\n        apply clarsimp\n        apply(frule step_cfunc_usr[OF bind_nat(3) Sim_cfunc_usr(2), THEN arg_cong[where f=\"set_spmf\"], THEN equalityD2])\n        apply(clarsimp simp add: o_def bind_UNION)\n        apply(drule subsetD)\n         apply fastforce\n        apply(auto intro: sim_cfunc_usr)\n        done\n    qed\n  qed\nqed\n\n\n\ncontext\n  fixes core :: \"('s_core, 'event1 + 'event2, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core\"\n    and rest :: \"('s_rest, 'event2, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest, 'more) rest_scheme\" \nbegin\n\nprimcorec core_with_rest :: \n  \"('s_core \\<times> 's_rest, 'event1, 'iadv_core + 'iadv_rest, 'iusr_core + 'iusr_rest, 'oadv_core + 'oadv_rest, 'ousr_core + 'ousr_rest) core\" \n  where\n    \"cpoke core_with_rest = (\\<lambda>(s_core, s_rest) e. map_spmf (\\<lambda>s_core'. (s_core', s_rest)) (cpoke core s_core (Inl e)))\"\n  | \"cfunc_adv core_with_rest = (\\<lambda>(s_core, s_rest) iadv. case iadv of\n       Inl iadv_core \\<Rightarrow> map_spmf (\\<lambda>(oadv_core, s_core'). (Inl oadv_core, (s_core', s_rest))) (cfunc_adv core s_core iadv_core)\n     | Inr iadv_rest \\<Rightarrow> \n       bind_spmf (rfunc_adv rest s_rest iadv_rest) (\\<lambda>((oadv_rest, es), s_rest'). \n         map_spmf (\\<lambda>s_core'. (Inr oadv_rest, (s_core', s_rest'))) (foldl_spmf (cpoke core) (return_spmf s_core) (map Inr es))))\"\n  | \"cfunc_usr core_with_rest = (\\<lambda>(s_core, s_rest) iusr. case iusr of\n       Inl iusr_core \\<Rightarrow> map_spmf (\\<lambda>(ousr_core, s_core'). (Inl ousr_core, (s_core', s_rest))) (cfunc_usr core s_core iusr_core)\n     | Inr iusr_rest \\<Rightarrow>\n       bind_spmf (rfunc_usr rest s_rest iusr_rest) (\\<lambda>((ousr_rest, es), s_rest').\n         map_spmf (\\<lambda>s_core'. (Inr ousr_rest, (s_core', s_rest'))) (foldl_spmf (cpoke core) (return_spmf s_core) (map Inr es))))\"\n\nend\n\nlemma fuse_core_with_rest:\n  fixes core :: \"('s_core, 'event1 + 'event2, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core\"\n    and rest1 :: \"('s_rest1, 'event1, 'iadv_rest1, 'iusr_rest1, 'oadv_rest1, 'ousr_rest1, 'more1) rest_scheme\"\n    and rest2 :: \"('s_rest2, 'event2, 'iadv_rest2, 'iusr_rest2, 'oadv_rest2, 'ousr_rest2, 'more2) rest_scheme\"\n  shows\n  \"fused_resource.fuse core (parallel_rest rest1 rest2) (s_core, (s_rest1, s_rest2)) = \n   map_fun (map_sum (lsumr \\<circ> map_sum id swap_sum) (lsumr \\<circ> map_sum id swap_sum)) (map_spmf (map_prod (map_sum (map_sum id swap_sum \\<circ> rsuml) (map_sum id swap_sum \\<circ> rsuml)) (map_prod id prod.swap \\<circ> rprodl)))\n   (fused_resource.fuse (core_with_rest core rest2) rest1 ((s_core, s_rest2), s_rest1))\"\n  apply(rule ext)\n  subgoal for x\n    apply(cases \"(parallel_rest rest1 rest2, (s_core, (s_rest1, s_rest2)), x)\" rule: fused_resource.fuse.cases)\n       apply(auto simp add: fused_resource.fuse.simps map_bind_spmf bind_map_spmf map_prod_def split_def o_def parallel_eoracle_def parallel_oracle_def split!: sum.split intro!: bind_spmf_cong)\n     apply(subst foldl_spmf_pair_left[simplified split_def]; simp add: map_fun_def o_def bind_map_spmf)+\n    done\n  done\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Constructive_Cryptography_CM/Fused_Resource.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5621764862150636, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.2942546125784851}}
{"text": "theory Kruskal_Impl\n  imports Kruskal_Refine\n    \"../../Refine_Imperative_HOL/IICF/Impl/IICF_DArray_List\"\n        UnionFind_Impl\nbegin\n\ncontext\n  fixes t ::  \"nat \\<Rightarrow> nat\"\nbegin\n  definition mop_sortEdges   where\n    \"mop_sortEdges l = (SPECT (emb (\\<lambda>(L,n). n= Max (insert 0 (set (map fst L) \\<union> set (map (snd o snd) L))) \\<and> sorted_wrt edges_less_eq L \\<and> distinct L \\<and> set L = set l) (enat (t (length l)))))\"\n  \n    sepref_register \"mop_sortEdges\"  \nend\n\nlocale sortMaxnode = \n  fixes sortEdges_impl :: \"(nat \\<times> int \\<times> nat) list \\<Rightarrow> ((nat \\<times> int \\<times> nat) list * nat) Heap\" \n    and sort_time' :: \"nat \\<Rightarrow> nat\"\n  assumes   \n      sortEdges_impl[sepref_fr_rules]: \"\\<And>t. (sortEdges_impl, PR_CONST (mop_sortEdges t)) \\<in>\n        [\\<lambda>l. sort_time' (length l) \\<le> t (length l)]\\<^sub>a\n      (list_assn (nat_assn \\<times>\\<^sub>a int_assn \\<times>\\<^sub>a nat_assn))\\<^sup>k \\<rightarrow> (list_assn (nat_assn \\<times>\\<^sub>a int_assn \\<times>\\<^sub>a nat_assn)\\<times>\\<^sub>a nat_assn)\"\n\n\n\n \n\n  \nlemma set_uprod_nonempty[simp]: \"set_uprod x \\<noteq> {}\"\n  apply(cases x) by auto\n\n\nlocale Kruskal_intermediate_Impl0 = Kruskal_intermediate E forest connected path weight for E forest connected path \n      and weight :: \"nat uprod \\<Rightarrow> int\"  +\n    fixes getEdges  :: \"(nat \\<times> int \\<times> nat) list nrest\"\n      and getEdges_impl :: \"(nat \\<times> int \\<times> nat) list Heap\" \n      and getEdges_time sort_time :: nat\n(*      and sortEdges  :: \"(nat \\<times> int \\<times> nat) list \\<Rightarrow> ((nat \\<times> int \\<times> nat) list * nat) nrest\"\n      and sortEdges_impl :: \"(nat \\<times> int \\<times> nat) list \\<Rightarrow> ((nat \\<times> int \\<times> nat) list * nat) Heap\" *)\n      and empty_uf_time indep_test_time insert_uf_time :: nat\n    assumes           \n        E_nonempty: \"E\\<noteq>{}\"\n      and  \n        getEdges_refine: \"getEdges \\<le> \\<Down> Id (SPECT (emb (\\<lambda>L. lst_graph_P' weight L E) (enat getEdges_time)))\"\n      and\n        getEdges_impl[sepref_fr_rules]: \"(uncurry0 getEdges_impl, uncurry0 getEdges) \\<in> unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a list_assn (nat_assn \\<times>\\<^sub>a int_assn \\<times>\\<^sub>a nat_assn)\"\n(*       and\n        sortEdges_refine': \"sortEdges l \\<le> (SPECT (emb (\\<lambda>(L,n). n= Max (set (map fst l) \\<union> set (map (snd o snd) l)) \\<and> sorted_wrt edges_less_eq L \\<and> distinct L \\<and> set L = set l) (enat sort_time)))\"\n     and\n        sortEdges_impl[sepref_fr_rules]: \"(sortEdges_impl, sortEdges) \\<in>\n                (list_assn (nat_assn \\<times>\\<^sub>a int_assn \\<times>\\<^sub>a nat_assn))\\<^sup>k \\<rightarrow>\\<^sub>a (list_assn (nat_assn \\<times>\\<^sub>a int_assn \\<times>\\<^sub>a nat_assn)\\<times>\\<^sub>a nat_assn)\"\n     \n*)\n                                                   \nbegin\n\nthm conc_fun_br\n\nabbreviation \"sortEdges \\<equiv> mop_sortEdges (\\<lambda>_. sort_time)\"\n\n\n(*\nlemma sortEdges_refine: \n  assumes a: \"V = set (map fst l) \\<union> set (map (snd o snd) l)\"\n    shows \"sortEdges l = \\<Down> (br fst (\\<lambda>(l,n). n= Max V)) (SPECT (emb (\\<lambda>L. sorted_wrt edges_less_eq L \\<and> distinct L \\<and> set L = set l) (enat sort_time)))\"\nproof -\n  have gg: \"(\\<lambda>x. (case x of (l, n) \\<Rightarrow> n = Max V) \\<and> sorted_wrt edges_less_eq (fst x) \\<and> distinct (fst x) \\<and> set (fst x) = set l)\n        =(\\<lambda>(L, n). n = Max (set (map fst l) \\<union> set (map (snd o snd) l)) \\<and> sorted_wrt edges_less_eq L \\<and> distinct L \\<and> set L = set l)\"\n    unfolding a by auto\n  show ?thesis \n    apply(simp only: conc_fun_br gg) by(rule sortEdges_refine')\nqed *)\n\nabbreviation \"insert_time \\<equiv> 23\"\nabbreviation \"empty_forest_time \\<equiv> 12\"\n\n\nsublocale Kruskal_intermediate_time  E forest connected  path weight\n        empty_forest_time empty_uf_time indep_test_time insert_time insert_uf_time getEdges_time sort_time\n  apply unfold_locales .\n\n\n\nterm obtain_sorted_carrier''\n       \ndefinition (in -) obtain_sorted_carrier'''_aux  where\n  \"obtain_sorted_carrier'''_aux gE sE c =\n      do {\n    l \\<leftarrow> gE;\n    ASSERT (length l = card c);\n    sE l\n}\" \n\nabbreviation \"obtain_sorted_carrier''' \\<equiv> obtain_sorted_carrier'''_aux getEdges sortEdges E\"\n \nlemma distinct_mset_eq:\"distinct a \\<Longrightarrow> mset a = mset b \\<Longrightarrow> distinct b\"\n  by (metis card_distinct distinct_card set_mset_mset size_mset)\n\nlemma quicksort_by_rel_distinct: \"distinct l \\<Longrightarrow> distinct (quicksort_by_rel edges_less_eq [] l)\"\n  by (auto intro: distinct_mset_eq)\n\ndefinition \"add_size_rel   = br fst (\\<lambda>(l,n). n= Max V)\"\n\n\n\nlemma max_node_is_Max_V: \" E = (\\<lambda>(a, _, y). Upair a y) ` set la \\<Longrightarrow> max_node la = Max V\"\nproof -\n  assume E: \"E = (\\<lambda>(a, _, y). Upair a y) ` set la\"\n  have pff: \"fst ` set la \\<union>  (\\<lambda>x. snd (snd x)) ` set la = (\\<Union>x\\<in>set la. case x of (x1, x1a, x2a) \\<Rightarrow> {x1, x2a})\"\n    by (auto simp add: rev_image_eqI)  \n  have \"V \\<noteq> {}\" using E_nonempty V_def by auto\n  then have Mo: \"Max V = Max (insert 0 V)\" by auto \n  show ?thesis unfolding Mo unfolding V_def\n  unfolding E apply simp \n  by (auto simp add:  max_node_def prod.case_distrib pff ) \nqed\n\nlemma lst_graph_P_V: \"lst_graph_P la E \\<Longrightarrow> V = (fst ` set la \\<union> (\\<lambda>x. snd (snd x)) ` set la)\" \n  by (auto simp: emb_eq_Some_conv lst_graph_P_def V_def rev_image_eqI) \n\n \n\nlemma  k: \"\\<And>V::nat set. finite V \\<Longrightarrow> V \\<noteq> {} \\<Longrightarrow> Max V = Max (insert 0 V)\" by auto\n\nlemma *: \"(la::((nat*int*nat) list)) \\<noteq> [] \\<Longrightarrow> Max (insert 0 (fst ` set la \\<union> (\\<lambda>x. snd (snd x)) ` set la)) = Max (fst ` set la \\<union> (\\<lambda>x. snd (snd x)) ` set la)\"\nproof -\n  assume \"la \\<noteq> []\"\n  then have \"fst ` set la \\<union> (snd \\<circ> snd) ` set la \\<noteq> {}\" by auto\n  then show ?thesis apply(intro k[symmetric])  apply simp by simp\nqed\n\n\nlemma obtain_sorted_carrier'''_refine: \"obtain_sorted_carrier''' \\<le> \\<Down>add_size_rel obtain_sorted_carrier''\"\n  unfolding obtain_sorted_carrier'''_aux_def  add_size_rel_def\n  apply(rule bindT_refine')      \n   apply(rule getEdges_refine) apply safe\n  apply(auto simp: emb_eq_Some_conv  dest!:  split: if_splits)\n  unfolding conc_fun_br  mop_sortEdges_def \n  apply(auto  simp: le_fun_def emb'_def dest: lst_graph_P_V split: if_splits)\n  apply(rule le_R_ASSERTI)\n  apply(rule ASSERT_leI) apply simp\n  apply(rule SPECT_refine) apply (auto split: if_splits)    \n  apply(subst * ) subgoal apply auto using E_nonempty by auto \n  by (metis (mono_tags) fst_conv in_br_conv lst_graph_P_V prod_case_simp) \n   \n    \n\ndefinition (in -) initState''_aux where\n  \"initState''_aux mn eft eut\\<equiv> do {\n    initial_union_find \\<leftarrow> mop_per_init (\\<lambda>_. eut) (mn + 1);\n    ASSERT ( card (Domain initial_union_find) = mn + 1);\n    e \\<leftarrow> mop_empty_list (\\<lambda>_. eft);\n    RETURNT (initial_union_find, e)      \n    }\" \n\n\nabbreviation \"initState'' mn == initState''_aux mn empty_forest_time empty_uf_time\"\n\n definition (in -) \"addEdge''_aux uf a w b T iut it = do {\n  uf \\<leftarrow> mop_per_union (\\<lambda>_. iut) uf a b;\n  T' \\<leftarrow> mop_push_list (\\<lambda>_.  it) (a,w,b) T;\n  RETURNT (uf, T')\n  }\"\n\nabbreviation \"addEdge'' uf a w b T == addEdge''_aux uf a w b T insert_uf_time insert_time\"\n\ndefinition (in -) \"notcompare uf a b itt = do {\n      i \\<leftarrow> mop_per_compare (\\<lambda>_. itt) uf a b;\n      RETURNT (\\<not>i)\n     }\"\n\n\n definition (in -) kruskal3_aux \n   where \"kruskal3_aux E gE sE eft eut iut it   itt \\<equiv> do {\n    (sl,mn) \\<leftarrow> obtain_sorted_carrier'''_aux gE sE E;\n    ASSERT (mn = Max (Kruskal_intermediate_defs.V E));\n    s \\<leftarrow> initState''_aux mn eft eut ;\n    (per, spanning_forest) \\<leftarrow> nfoldli sl (\\<lambda>_. True)\n        (\\<lambda>(a,w,b) (uf, T). do { \n            ASSERT (a \\<in> Domain uf \\<and> b \\<in> Domain uf);\n            ASSERT ( card (Domain uf) = Max (Kruskal_intermediate_defs.V E) + 1);\n            i \\<leftarrow> notcompare uf a b itt;\n            if i then\n              do { \n                ASSERT ((a,w,b)\\<notin>set T);\n                addEdge''_aux uf a w b T iut it\n              }\n            else \n              RETURNT (uf,T)\n        }) s;\n        RETURNT spanning_forest\n      }\"\n\nabbreviation \"kruskal3 \\<equiv> kruskal3_aux E getEdges sortEdges  empty_forest_time empty_uf_time\n                      insert_uf_time  insert_time  indep_test_time\"\n\n  definition per_supset_rel :: \"('a per \\<times> 'a per) set\" where\n    \"per_supset_rel\n      \\<equiv> {(p1,p2). p1 \\<inter> Domain p2 \\<times> Domain p2 = p2 \\<and> p1 - (Domain p2 \\<times> Domain p2) \\<subseteq> Id}\"\n\n definition \"kk_rel n \\<equiv> per_supset_rel \\<inter> ({p. Domain p = {0..<n}} \\<times> UNIV)\"\n\nlemma kk_relD: \"x\\<in> kk_rel n \\<Longrightarrow> x\\<in>per_supset_rel\" unfolding kk_rel_def by auto\n\n  lemma per_supset_rel_dom: \"(p1, p2) \\<in> per_supset_rel \\<Longrightarrow> Domain p1 \\<supseteq> Domain p2\"\n    by (auto simp: per_supset_rel_def)\n  \n  lemma per_supset_compare:\n    \"(p1, p2) \\<in> per_supset_rel \\<Longrightarrow> x1\\<in>Domain p2 \\<Longrightarrow> x2\\<in>Domain p2 \\<Longrightarrow> per_compare p1 x1 x2 \\<longleftrightarrow> per_compare p2 x1 x2\"\n    by (auto simp: per_supset_rel_def)\n  \n  lemma per_supset_union: \"(p1, p2) \\<in> per_supset_rel \\<Longrightarrow> x1\\<in>Domain p2 \\<Longrightarrow> x2\\<in>Domain p2 \\<Longrightarrow>\n    (per_union p1 x1 x2, per_union p2 x1 x2) \\<in> per_supset_rel\"\n    apply (clarsimp simp: per_supset_rel_def per_union_def Domain_unfold )\n    apply (intro subsetI conjI)\n    apply blast\n    apply force\n    done\n\n  lemma per_kk_rel_union: \n    assumes \"(p1, p2) \\<in> kk_rel n\" and inDom: \"x1\\<in>Domain p2\" \"x2\\<in>Domain p2\"\n    shows \"(per_union p1 x1 x2, per_union p2 x1 x2) \\<in> kk_rel n\"\n  proof -\n    from assms(1) have \"(p1, p2) \\<in> per_supset_rel\" by(auto dest: kk_relD)\n    with inDom have ss: \"(per_union p1 x1 x2, per_union p2 x1 x2) \\<in> per_supset_rel\" \n      by(auto intro: per_supset_union)\n\n    from assms(1) have \"Domain p1 = {0..<n}\" by (auto simp: kk_rel_def)\n    then have \"Domain (per_union p1 x1 x2) = {0..<n}\" by simp\n    with ss show ?thesis unfolding kk_rel_def by auto\n  qed\n\nlemma per_initN_refine: \"(per_init' (Max V + 1), per_init V) \\<in> per_supset_rel\"\n  unfolding per_supset_rel_def per_init'_def per_init_def max_node_def\n  by (auto simp: less_Suc_eq_le  ) \n\nlemma per_init'_refine: \"SPECT [per_init' (Max V  + 1) \\<mapsto> enat empty_uf_time] \\<le> \\<Down> per_supset_rel (SPECT [per_init V \\<mapsto> enat empty_uf_time])\"\n  apply(rule SPECT_refine)   using per_initN_refine by (auto split: if_splits)\n  \nlemma gg: \"{(i, i) |i. i < X} = (\\<lambda>i. (i,i)) ` {i. i < X}\" by auto\n   \n\nlemma ff: \"\\<And>X. card (Domain {(i, i) |i. i < X}) = X\"\n  unfolding Domain_fst apply(subst card_image)\n  subgoal by (smt fst_conv inj_onI mem_Collect_eq) \n  subgoal unfolding gg apply(subst card_image) by auto  \n  done\n\n\nlemma initState''_refine: \"initState'' (Max V) \\<le> \\<Down>(kk_rel (Max V + 1) \\<times>\\<^sub>r Id) initState'\"\n  unfolding initState'_aux_def initState''_aux_def mop_empty_list_def  kk_rel_def\n  unfolding mop_per_init_def\n  apply(rule bindT_refine') apply(rule per_init'_refine)\n\n  apply(refine_rcg  ) \n  subgoal by (auto split: if_splits simp: ff   per_init'_def )   \n  unfolding conc_fun_RES \n    apply(rule T_specifies_I)               \n  apply(vcg' \\<open>-\\<close>  )  \n  apply(rule Sup_upper)  by (auto simp: per_init'_def numeral_eq_enat split: if_splits)  \n\n   \n\nlemma SPECT_bind_RETURNT: \"SPECT [x \\<mapsto> t] \\<bind> (\\<lambda>i. RETURNT (f i)) = SPECT [f x \\<mapsto> t]\"\n  unfolding bindT_def by(auto split: nrest.split)\n\ntheorem kruskal3_refine: \"kruskal3 \\<le> \\<Down> Id kruskal2\"\n  unfolding kruskal2_aux_def kruskal3_aux_def Let_def\n  apply (refine_rcg obtain_sorted_carrier'''_refine   )\n            (*supply RELATESI[where R=\"per_supset_rel::(nat per \\<times> _) set\", refine_dref_RELATES]*)\n            supply RELATESI[where R=\"kk_rel (Max V + 1)::(nat per \\<times> _) set\", refine_dref_RELATES]\n             apply refine_dref_type \n  subgoal unfolding add_size_rel_def by (auto simp: in_br_conv)\n  subgoal apply (simp add: add_size_rel_def in_br_conv  )\n    using initState''_refine  by simp  \n          apply (auto simp add: add_size_rel_def in_br_conv per_supset_compare\n                        per_supset_union \n                      dest: per_supset_rel_dom\n                      simp del: per_compare_def )\n  subgoal by(auto dest!: kk_relD per_supset_rel_dom)    \n  subgoal by(auto dest!: kk_relD per_supset_rel_dom)  \n  subgoal by(auto simp: kk_rel_def) \n  subgoal apply(auto dest!: kk_relD simp: SPECT_bind_RETURNT le_fun_def notcompare_def mop_per_compare_def)\n    by (meson Domain.simps local.per_supset_compare per_compare_def)+  \n  subgoal unfolding addEdge'_aux_def addEdge''_aux_def mop_per_union_def mop_push_list_def\n    apply(refine_rcg)\n     apply refine_dref_type            \n    subgoal apply (rule SPECT_refine) by (auto  split: if_splits intro: per_kk_rel_union)\n    subgoal apply (rule RETURNT_refine) by(auto split: if_splits)   \n    done\n  done\n\nend\n\n\n       \n\nlocale Kruskal_intermediate_Impl = Kruskal_intermediate_Impl0\n  + UnionFind_Impl + sortMaxnode   +\n  assumes \n  [simp]:  \"uf_init_time (Suc (Max V)) \\<le> empty_uf_time\" \n    \"uf_cmp_time (Suc (Max V)) \\<le> indep_test_time\" \n    \"uf_union_time (Suc (Max V)) \\<le> insert_uf_time\" \n    \"sort_time' (card E) \\<le> sort_time\"\nbegin\n\nsection \\<open>Kruskal\\<close>\n\n\n  lemma [fcomp_norm_simps]: \"list_assn (nat_assn \\<times>\\<^sub>a int_assn \\<times>\\<^sub>a nat_assn) = id_assn\"\n    by (auto simp: list_assn_pure_conv)\n  lemma [fcomp_norm_simps]: \" (nat_assn \\<times>\\<^sub>a int_assn \\<times>\\<^sub>a nat_assn) = id_assn\"\n    by (auto simp: )\n\n  lemma [sepref_import_param]: \"(sort_edges,sort_edges)\\<in>\\<langle>Id\\<times>\\<^sub>rId\\<times>\\<^sub>rId\\<rangle>list_rel \\<rightarrow>\\<langle>Id\\<times>\\<^sub>rId\\<times>\\<^sub>rId\\<rangle>list_rel\" by simp\n  lemma [sepref_import_param]: \"(max_node, max_node) \\<in> \\<langle>Id\\<times>\\<^sub>rId\\<times>\\<^sub>rId\\<rangle>list_rel \\<rightarrow> nat_rel\" by simp\n\n  sepref_register \"getEdges\" :: \"(nat \\<times> int \\<times> nat) list nrest\"\n  sepref_register uf_init :: \"nat \\<Rightarrow> uf Heap\"\n  sepref_register uf_cmp :: \"uf \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> bool Heap\"\n  sepref_register uf_union :: \"uf \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> uf Heap\"\n \ndeclare getEdges_impl [sepref_fr_rules]\n\n \n\nsepref_definition kruskal is\n  \"uncurry0 kruskal3\" :: \"(unit_assn)\\<^sup>k \\<rightarrow>\\<^sub>a da_assn (nat_assn \\<times>\\<^sub>a int_assn \\<times>\\<^sub>a nat_assn)\"\n  unfolding kruskal3_aux_def obtain_sorted_carrier'''_aux_def initState''_aux_def\n      addEdge''_aux_def notcompare_def nfoldli_def\n  using [[goals_limit = 2]]\n   \n  apply sepref_dbg_preproc\n  apply sepref_dbg_cons_init\n  apply sepref_dbg_id \n     apply sepref_dbg_monadify\n\n         apply sepref_dbg_opt_init\n\n  apply sepref_dbg_trans \n \n  apply sepref_dbg_opt\n  apply sepref_dbg_cons_solve \\<comment> \\<open>Frame rule, recovering the invalidated list \n    or pure elements, propagating recovery over the list structure\\<close>\n  apply sepref_dbg_cons_solve \\<comment> \\<open>Trivial frame rule\\<close>\n  apply sepref_dbg_constraints\n      done  \n\n\n  concrete_definition (in -) kruskal' \n    uses Kruskal_intermediate_Impl.kruskal_def\n\n\nthm kruskal3_refine kruskal2_refine   kruskal1_refine kruskal0_refine minWeightBasis3_refine\n \nthm kruskal.refine kruskal3_refine kruskal2_refine   kruskal1_refine kruskal0_refine minWeightBasis3_refine\n\n\nabbreviation \"MST == minBasis\"\n\nterm minWeightBasis3\n\n(* TODO: *) \n\nlemma k3: \"(kruskal3,kruskal2) \\<in> \\<langle>Id\\<rangle>nrest_rel\"\n  apply(rule nrest_relI) by (rule kruskal3_refine) \nlemma k2: \"(kruskal2,kruskal1) \\<in> \\<langle>lst_graph_rel\\<rangle>nrest_rel\"\n  apply(rule nrest_relI) by (rule kruskal2_refine) \nlemma k1: \"(kruskal1,kruskal0) \\<in> \\<langle>Id\\<rangle>nrest_rel\"\n  apply(rule nrest_relI) by (rule kruskal1_refine) \nlemma k0: \"(kruskal0,minWeightBasis3) \\<in> \\<langle>Id\\<rangle>nrest_rel\"\n  apply(rule nrest_relI) by (rule kruskal0_refine) \nlemma kmw: \"(minWeightBasis3,SPECT (emb minBasis (enat minBasis_time))) \\<in> \\<langle>Id\\<rangle>nrest_rel\"\n  apply(rule nrest_relI)  \n  by (rule minWeightBasis3_refine)\n\nlemmas k_ref_spec = k3[FCOMP k2, FCOMP k1, FCOMP k0, FCOMP kmw]\n\n\n  lemma [fcomp_norm_simps]: \"list_assn (nat_assn \\<times>\\<^sub>a int_assn \\<times>\\<^sub>a nat_assn) = id_assn\"\n    by (auto simp: list_assn_pure_conv)\nlemmas kruskal_ref_spec = kruskal.refine[FCOMP k_ref_spec]\n\nthm minBasis_time_def\nlemma kruskal_correct_forest:\n  shows \"<$ minBasis_time> kruskal <\\<lambda>r. (\\<exists>\\<^sub>Ara. hr_comp (da_assn id_assn) lst_graph_rel ra r * \\<up> (MST ra))>\\<^sub>t\"\nproof -\n  thm extract_cost_ub \n  note l= hn_refine_ref[OF _  kruskal_ref_spec[to_hnr] ]\n  thm extract_cost_ub[OF l, where Cost_ub=\"minBasis_time\", simplified in_ran_emb_special_case]\n  have ht: \"<emp * $ minBasis_time> kruskal <\\<lambda>r. emp * (\\<exists>\\<^sub>Ara. hr_comp (da_assn id_assn) lst_graph_rel ra r * \\<up> (ra \\<in> dom ((emb MST (enat minBasis_time)))))>\\<^sub>t\"\n    apply(rule extract_cost_ub[OF l, where Cost_ub=\"minBasis_time\" ])\n    by (auto simp: in_ran_emb_special_case)  \n\n  from ht show ?thesis by auto        \nqed\nthm minBasis_time_def \nend\n(*\nthm extract_cost_ub[where M= \"(emb Pr t)\", no_vars]\n\nlemma \"hn_refine \\<Gamma> c \\<Gamma>' R (SPECT (emb Pr t))  \\<Longrightarrow>\n<\\<Gamma> * $ t> c <\\<lambda>r. \\<Gamma>' * (\\<exists>\\<^sub>Ara. R ra r * \\<up> (Pr ra))>\\<^sub>t\"\nproof -\n  assume \"hn_refine \\<Gamma> c \\<Gamma>' R (SPECT (emb Pr t))\"\n  from extract_cost_ub[OF this, of t]\n  show ?thesis by (simp add: ran_emb')\nqed\n \n\nlemma array_length_rule_raw [hoare_triple]:\n  \"<dyn_array_raw (xs, n) p * $1>\n   array_length p\n   <\\<lambda>r. dyn_array_raw (xs, n) p * \\<up>(r = n)>\"\n  unfolding dyn_array'_def array_length_def \n  apply(cases p)\n  by (sep_auto simp: zero_time)  \n \n\nlemma array_max_rule_raw [hoare_triple]:\n  \"<dyn_array_raw (xs, n) p * $1>\n   array_max p\n   <\\<lambda>r. dyn_array_raw (xs, n) p * \\<up>(r = length xs)>\"\n  unfolding array_max_def \n  apply (cases p)\n  by (sep_auto heap: length_rule simp: zero_time)  \n\n\nlemma double_length_raw_rule2 [hoare_triple]:\n  \"length xs = n \\<Longrightarrow>\n   <dyn_array_raw (xs, length xs) p * $(length xs * 5 + 5)>\n   double_length p\n   <dyn_array_raw (double_length_fun (xs, n))>\\<^sub>t\" \n  using double_length_raw_rule[of xs n p] by(simp add: mult.commute) \n\nlemma push_array_raw_rule [hoare_triple]:\n  \"n \\<le> length xs \\<Longrightarrow>\n   <dyn_array_raw (xs, n) p * $( length xs *5+9)>\n   push_array x p\n   <dyn_array_raw (push_array_fun x (xs, n))>\\<^sub>t\" \n  unfolding  \n    push_array_def  \n  apply(sep_auto heap: array_max_rule_raw push_array_basic_raw_rule\n          array_length_rule_raw  double_length_raw_rule2)\n  subgoal apply(subst array_copy_length) by simp_all\n  by sep_auto\n\nlemma push_array_rule''' [hoare_triple]:\n  \"n \\<le> length xs \\<Longrightarrow>\n   <dyn_array' (xs, n) p * $19>\n   push_array x p\n   <dyn_array' (push_array_fun x (xs, n))>\\<^sub>t\" \n  unfolding  \n    push_array_def\n  apply(sep_auto heap: array_max_rule' array_length_rule' push_array_basic_rule')\n   apply(sep_auto heap: double_length_rule' )\n  using push_array_basic_rule'\n  unfolding double_length_fun.simps\n  apply(sep_auto simp only: heap: push_array_basic_rule')\n  subgoal apply(subst array_copy_length) by simp_all\n  by sep_auto\n   \nthm array_max_rule'\n\n*)\nend", "meta": {"author": "maxhaslbeck", "repo": "Sepreftime", "sha": "c1c987b45ec886d289ba215768182ac87b82f20d", "save_path": "github-repos/isabelle/maxhaslbeck-Sepreftime", "path": "github-repos/isabelle/maxhaslbeck-Sepreftime/Sepreftime-c1c987b45ec886d289ba215768182ac87b82f20d/Examples/Kruskal/Kruskal_Impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6224593452091672, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.29422624734834735}}
{"text": "(*\n   Copyright 2017 Myriam Begel\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n*)\n\ntheory \"BasicBlocks\"\n\nimports \"../lem/Evm\"\n\"Apply_Trace_Cmd\"\n\nbegin\n(* Types definitions *)\ndatatype tblock =\nNext | Jump | Jumpi | Terminal\n\ntype_synonym position = \"int\"\ntype_synonym pos_inst = \"position * inst\"\ntype_synonym vert = \"pos_inst list * tblock\"\ntype_synonym vertex = \"int * vert\"\ntype_synonym basic_blocks = \"vertex list\"\n\ntype_synonym stack_value = \"w256 option\"\n\n(* Auxiliary functions *)\n\nabbreviation block_lookup :: \"basic_blocks \\<Rightarrow> int \\<Rightarrow> vert option\" where\n\"block_lookup bb == map_of bb\"\n\nabbreviation v_ind :: \"vertex \\<Rightarrow> int\" where\n\"v_ind v == fst v\"\n\nabbreviation v_ty :: \"vertex \\<Rightarrow> tblock\" where\n\"v_ty v == snd (snd v)\"\n\nabbreviation v_insts :: \"vertex \\<Rightarrow> pos_inst list\" where\n\"v_insts v == fst (snd v)\"\n\ndefinition byteListInt :: \"8 word list \\<Rightarrow> int\" where\n\"byteListInt l = uint ((word_rcat l):: 32 word)\"\n\ndefinition next_i :: \"basic_blocks \\<Rightarrow> int \\<Rightarrow> int\" where\n \"next_i v n = v_ind (hd (dropWhile (\\<lambda>u. (v_ind u)\\<le>n) v))\"\n(*  \"next_i (i#j#l) n = (if fst i=n then fst j else next_i (j#l) n)\"*)\n\ndefinition find_block :: \"int \\<Rightarrow> vertex \\<Rightarrow> bool\" where\n\"find_block n bl ==  n=v_ind bl\"\n\nfun good_dest :: \"int \\<Rightarrow> basic_blocks \\<Rightarrow> bool\" where\n  \"good_dest m [] = False\"\n| \"good_dest m ((n,[],_)#l) = good_dest m l\"\n| \"good_dest m ((n,(_,i)#inst,_)#l) = (if m = n then (i = Pc JUMPDEST) else good_dest m l )\"\n\ndefinition blocks_indexes :: \"basic_blocks \\<Rightarrow> int list\" where\n\"blocks_indexes xs = map v_ind xs\"\n\nfun extract_blocks :: \"basic_blocks \\<Rightarrow> int \\<Rightarrow> vert option\" where\n\"extract_blocks [] = Map.empty\"\n|\"extract_blocks (x#xs) = (extract_blocks xs)(fst x:= Some (snd x))\"\n\nfun rebuild_basic_blocks :: \"int list \\<Rightarrow> (int \\<Rightarrow> vert option) \\<Rightarrow> basic_blocks\" where\n\"rebuild_basic_blocks [] m = []\"\n|\"rebuild_basic_blocks (x#xs) m = (x,the (m x)) # (rebuild_basic_blocks xs m)\"\n\n(* Stack manipulations *)\n\ndefinition stack_swap :: \"stack_value list \\<Rightarrow> nat \\<Rightarrow> stack_value list\" where\n\"stack_swap st n = (let first = hd st in\n  let unchanged = take (n -2) (tl st) in\n  let to_swap = hd (drop (max (n-1) 1) st) in\n  (to_swap # unchanged) @ (first # (drop n st))\n)\"\n\nvalue \"stack_swap [Value 1, Value 2, Value 3, Value 4] 2\"\n\ndefinition stack_dup :: \"stack_value list \\<Rightarrow> nat \\<Rightarrow> stack_value list\" where\n\"stack_dup st n = (st ! (n-1)) # st\"\n\nvalue \"stack_dup [Value 1, Value 2, Value 3, Value 4] 2\"\n\ndefinition block_pt :: \"pos_inst list \\<Rightarrow> pos_inst \\<Rightarrow> int\" where\n \"block_pt bl pt = (case bl of\n   [] \\<Rightarrow> fst pt\n  | _ \\<Rightarrow> fst (hd bl))\"\n\n(* Main functions *)\n\n(* Add the address of each instruction *)\n\nfun add_address' :: \"inst list \\<Rightarrow> int \\<Rightarrow> pos_inst list\" where\n\"add_address' [] n = []\"\n| \"add_address' (x#xs) n = (n,x)#(add_address' xs (n + inst_size x))\"\n\ndefinition add_address :: \"inst list \\<Rightarrow> pos_inst list\" where\n\"add_address xs = add_address' xs 0\"\n\n(* The execution of a basic block must be sequential. *)\n(* We remove JUMP and JUMPI instructions and cut after them or a stopping instruction *)\n(* and before a Jump destination. *)\nfun aux_basic_block :: \"pos_inst list \\<Rightarrow> pos_inst list \\<Rightarrow> basic_blocks\" where\n \"aux_basic_block [] [] = []\"\n|\"aux_basic_block [] block = [(fst (hd block), block, Next)]\"\n|\"aux_basic_block ((i)#tl1) block =\n\t(let bl_pt = block_pt block i in\n  (case snd i of\n    Pc JUMPDEST \\<Rightarrow> (if block = [] then (aux_basic_block tl1 [i])\n    else (bl_pt, block, Next) # (aux_basic_block tl1 [i]))\n  | Pc JUMP \\<Rightarrow>(bl_pt, block, Jump) # ( aux_basic_block tl1 [])\n  | Pc JUMPI \\<Rightarrow>(bl_pt, block, Jumpi) # ( aux_basic_block tl1 [])\n  | Misc _ \\<Rightarrow>(bl_pt, block @ [i], Terminal) # ( aux_basic_block tl1 [])\n  | Unknown a \\<Rightarrow> (bl_pt, block @ [i], Terminal) # ( aux_basic_block tl1 [])\n  | _ \\<Rightarrow> aux_basic_block tl1 (block@[i])))\"\ndeclare aux_basic_block.simps[simp del]\n\ndefinition build_basic_blocks :: \"inst list \\<Rightarrow> basic_blocks\" where\n\"build_basic_blocks prog == aux_basic_block (add_address prog) []\"\n\ndefinition build_blocks :: \"inst list \\<Rightarrow> basic_blocks\" where\n\"build_blocks prog = build_basic_blocks prog\"\n\n(* Verification *)\nlemmas reg_inst_splits = inst.splits misc_inst.splits pc_inst.splits\n\n(* Define how BLOCKSs should be for the program logic to be sound *)\n\nfun reg_inst :: \"inst \\<Rightarrow> bool\" where\n \"reg_inst (Pc JUMP) = False\"\n| \"reg_inst (Pc JUMPI) = False\"\n|\"reg_inst (Pc _) = True\"\n|\"reg_inst (Misc _) = False\"\n|\"reg_inst (Unknown a) = False\"\n|\"reg_inst _ = True\"\n\ndefinition reg_block :: \"pos_inst list \\<Rightarrow> bool\" where\n\"reg_block xs = list_all reg_inst (map snd xs)\"\n\ndefinition reg_vertex :: \"vertex \\<Rightarrow> bool\" where\n\"reg_vertex v = (case v_ty v of\nTerminal \\<Rightarrow> reg_block (butlast (v_insts v))\n| _ \\<Rightarrow> reg_block (v_insts v))\"\n\ndefinition reg_basic_blocks :: \"basic_blocks \\<Rightarrow> bool\" where\n\"reg_basic_blocks xs = list_all reg_vertex xs\"\n\nfun seq_block :: \"pos_inst list \\<Rightarrow> bool\" where \n\"seq_block [] = True\"\n| \"seq_block [x] = True\"\n| \"seq_block (x#y#ys) = (fst y = fst x + inst_size (snd x) \\<and> seq_block (y#ys))\"\ndeclare seq_block.simps[simp del]\n\ndefinition last_no::\"pos_inst list \\<Rightarrow> bool\" where\n\"last_no insts == (\\<exists>a. snd (last insts) = Misc a) \\<or> (\\<exists>a. snd (last insts) = Unknown a)\"\n\ndefinition wf_blocks:: \"basic_blocks \\<Rightarrow> bool\" where\n\"wf_blocks c == \n(\\<forall>n insts ty.\n(block_lookup c n = Some (insts, ty) \\<longrightarrow>\n\tn \\<in> set (blocks_indexes c) \\<and> reg_vertex (n, insts, ty) \\<and>\n  (insts \\<noteq> [] \\<longrightarrow> (fst (hd insts) = n)) \\<and> seq_block insts \\<and>\n  0 \\<le> n \\<and> n < 2 ^ 256) \\<and>\n(block_lookup c n = Some (insts, Next) \\<longrightarrow>\n\t insts \\<noteq> []) \\<and>\n(block_lookup c n = Some (insts, Terminal) \\<longrightarrow>\n\t insts \\<noteq> [] \\<and> last_no insts)\n)\"\n\n(* Proof that we build well formed BLOCKSs *)\n\nlemma index_have_blocks:\n\"c = build_blocks bytecode \\<Longrightarrow>\n \\<not> block_lookup c n = None \\<Longrightarrow>\n n \\<in> set (blocks_indexes c)\"\nby(simp add: Let_def build_blocks_def blocks_indexes_def map_of_eq_None_iff)\n\nlemma index_block_eq:\n\"(n, (j,i)#b, t)#xs = aux_basic_block insts block \\<Longrightarrow>\nj=n\"\napply(induction insts arbitrary: block n j i t xs b)\n apply(case_tac block)\n  apply(simp add: aux_basic_block.simps block_pt_def split:if_splits list.splits)\n  apply(clarsimp)\n apply(simp add: aux_basic_block.simps block_pt_def split:if_splits list.splits)\n apply(clarsimp)\napply(simp add: aux_basic_block.simps Let_def)\napply(simp split: inst.splits add: inst_size_def inst_code.simps)\n  apply(clarsimp simp add: block_pt_def split: list.splits)\n apply(clarsimp simp add: block_pt_def split: pc_inst.splits list.splits if_splits)\napply(clarsimp simp add: block_pt_def split: misc_inst.splits list.splits)\ndone\n\nlemma seq_block_compose:\n\"seq_block bl \\<Longrightarrow>\n \\<forall>i j. bl \\<noteq> [] \\<longrightarrow> last bl = (j, i) \\<longrightarrow> m = j + inst_size i \\<Longrightarrow>\n seq_block (bl @ [(m, a)])\"\napply(induction bl)\n apply(simp add: seq_block.simps)\napply(case_tac bl; simp)\n apply(simp add: seq_block.simps)\napply(simp add: seq_block.simps)\ndone\n\nlemma in_aux_bb_intermediate:\n\"(n, b, t) \\<in> set (aux_basic_block insts block) \\<Longrightarrow>\n\\<exists>ys bl xs. (n, b, t)#xs = aux_basic_block ys bl\"\napply(induction insts arbitrary: block)\n apply(rule_tac x=\"[]\" in exI)\n apply(case_tac block)\n apply(simp add: aux_basic_block.simps split: if_splits)+\n apply(rule_tac x=block in exI, simp add: aux_basic_block.simps)\napply(subgoal_tac \"(n, b, t) \\<in> set\n\t\t\t(aux_basic_block (a # insts) block)\")\n apply(drule subst[OF aux_basic_block.simps(3)])\n apply(simp add: Let_def)\n  apply(clarsimp split: inst.splits simp add: inst_size_def inst_code.simps)\n   apply(erule disjE, rule_tac x=\"(a,Unknown x1) # insts\" in exI, rule_tac x=block in exI,\n\t\t\t\tsimp add: aux_basic_block.simps Let_def, fastforce)\n  apply(simp split: pc_inst.splits if_splits add: inst_size_def inst_code.simps;\n\t\t\t\terule disjE, rule_tac x=\"(a,Pc x9) # insts\" in exI, rule_tac x=block in exI,\n\t\t\t\tsimp add: aux_basic_block.simps Let_def, fastforce)\n apply(erule disjE, rule_tac x=\"(a,Misc x13) # insts\" in exI, rule_tac x=block in exI,\n\t\t\t\tsimp add: aux_basic_block.simps Let_def, fastforce)\napply(assumption)\ndone\n\n(* Lemmas to show that build blocks are regular *)\nlemma list_all_in:\n\"x \\<in> set xs \\<Longrightarrow> list_all P xs \\<Longrightarrow> P x\"\n apply(induction xs)\n  apply(simp)\n apply(case_tac \"x=a\"; simp)\ndone\n\nlemma reg_block_butlast:\n\"reg_block xs \\<Longrightarrow> reg_block (butlast xs)\"\n apply(induction xs)\n  apply(simp)\n apply(simp add: reg_block_def List.List.list.pred_map)\ndone\n\nlemmas reg_simps =\nreg_basic_blocks_def reg_vertex_def reg_block_def\n\nlemma reg_aux_bb:\n\"reg_block block \\<Longrightarrow>\n reg_basic_blocks (aux_basic_block insts block)\"\n apply(induction insts arbitrary: block)\n  apply(case_tac block)\n   apply(simp add: reg_simps aux_basic_block.simps)\n  apply(simp add: reg_basic_blocks_def reg_vertex_def aux_basic_block.simps)\n apply(simp add:Let_def aux_basic_block.simps)\n apply(case_tac block; clarsimp)\n  apply(simp split: inst.split pc_inst.split misc_inst.split)\n  apply(simp add:reg_simps)\n apply(simp split: inst.split pc_inst.split misc_inst.split)\n apply(simp add:reg_simps)\ndone\n\nlemma reg_bb:\n\"reg_basic_blocks (build_basic_blocks insts)\"\n apply(simp add: build_basic_blocks_def)\n apply(rule reg_aux_bb)\n apply(simp add: reg_simps)\ndone\nvalue \"sum_list (map inst_size [Pc JUMP, Pc PC])\"\n\nlemma seq_block_tl:\n\"seq_block (x#xs) \\<Longrightarrow> seq_block xs\"\napply(case_tac xs)\n apply(simp add: seq_block.simps)+\ndone\n\nlemma seq_block_append:\n\"seq_block bl \\<Longrightarrow>\nbl \\<noteq> [] \\<longrightarrow> fst a = fst (last bl) + inst_size (snd (last bl))\\<Longrightarrow>\nseq_block (bl@[a])\"\napply(induction bl; simp add: seq_block.simps)\napply(simp add: seq_block_tl)\napply(case_tac bl; simp add: seq_block.simps)\ndone\n\nlemma seq_block_tl':\n\"seq_block (xs@ys) \\<Longrightarrow> seq_block ys\"\napply(induction xs; simp add: seq_block.simps)\napply(simp add: seq_block_tl)\ndone\n\nlemma inst_size_pos:\n\"inst_size x > 0\"\napply(simp add: inst_size_def)\napply(case_tac x; clarsimp simp add: inst_code.simps)\napply(case_tac x10; clarsimp simp add: stack_inst_code.simps)\napply(simp split: if_splits)\ndone\n\nabbreviation bound where\n\"bound mini maxi n == mini \\<le> (fst n) \\<and> (fst n) < maxi\"\n\nlemma sequential_basic_blocks:\n\"seq_block ys \\<Longrightarrow>\n seq_block bl \\<Longrightarrow>\n list_all (bound 0 m) ys \\<Longrightarrow>\n list_all (bound 0 m) bl \\<Longrightarrow>\n ys \\<noteq> [] \\<and> bl \\<noteq> [] \\<longrightarrow> fst (hd ys) = fst (last bl) + inst_size (snd (last bl))\\<Longrightarrow>\n (n, insts, ty) \\<in> set (aux_basic_block ys bl) \\<Longrightarrow>\n seq_block insts \\<and> 0 \\<le> n \\<and> n < m\"\napply(induction ys arbitrary: bl)\n apply(case_tac bl; simp add: aux_basic_block.simps)\napply(simp add: aux_basic_block.simps Let_def)\n apply(case_tac \"reg_inst (snd a) \\<and> (snd a) \\<noteq> Pc JUMPDEST\")\n apply(drule_tac x=\"bl@[a]\" in meta_spec)\n apply(simp add: seq_block_tl seq_block_append)\n apply(drule meta_mp; clarsimp; case_tac ys; simp add: seq_block.simps;\n       simp split: reg_inst_splits)\napply(case_tac \"(snd a) = Pc JUMPDEST\")\n apply(clarsimp)\n apply(drule_tac x=\"[(a, Pc JUMPDEST)]\" in meta_spec)\n apply(simp add: seq_block_tl seq_block.simps)\n apply(drule meta_mp; case_tac ys; simp add: seq_block.simps)\n  apply(case_tac \"bl=[]\"; simp split: if_splits)\n  apply(erule disjE; clarsimp simp add: block_pt_def split: list.splits)\n apply(case_tac \"bl=[]\"; simp split: if_splits)\n apply(erule disjE; clarsimp simp add: block_pt_def split: list.splits)\napply(drule meta_spec[where x=\"[]\"])\napply(simp add: seq_block_tl seq_block_append seq_block.simps)\napply(simp split: reg_inst_splits)\n    apply(erule disjE; clarsimp simp add: block_pt_def seq_block_append split: list.splits)+\ndone\n\nlemma seq_block_add_address:\n\"seq_block (add_address' insts k)\"\napply(induction insts arbitrary:k)\n apply(simp add: seq_block.simps)\napply(simp)\napply(case_tac insts; simp add: seq_block.simps)\ndone\n\nlemma bound_add_address':\n\"(x,y) \\<in> set (add_address' xs k) \\<Longrightarrow>\nk \\<le> x \\<and> x \\<le> fst (last (add_address' xs k))\"\napply(induction xs arbitrary: k x y)\n apply(simp)\napply(simp)\napply(erule disjE; simp)\n apply(case_tac \"add_address' xs (k + inst_size a)\"; clarsimp)\n apply(drule_tac x=\"k + inst_size a\" in meta_spec; drule_tac x=\"aa\" and y=\"b\" in meta_spec2)\n apply(simp split: list.splits if_splits)\n  apply(case_tac xs; simp)\n  apply(drule conjunct1; drule sym[where s=\"_ + _\"]; simp add: inst_size_pos Orderings.order_class.order.strict_implies_order)\n apply(erule conjE)\n apply(subgoal_tac \"k \\<le> k + inst_size a\"; simp)\n apply(simp add: inst_size_pos Orderings.order_class.order.strict_implies_order)\napply(drule_tac x=\"k + inst_size a\" in meta_spec; drule_tac x=\"x\" and y=\"y\" in meta_spec2)\napply(simp)\napply(erule conjE)\napply(rule conjI; clarsimp)\napply(subgoal_tac \"k \\<le> k + inst_size a\"; simp)\napply(simp add: inst_size_pos Orderings.order_class.order.strict_implies_order)\ndone\n\nlemma non_empty_block_next:\n\"(n, [], Next) # xs = aux_basic_block ys bl \\<Longrightarrow> False\"\napply(induction ys arbitrary:bl)\n apply(case_tac bl; simp add: aux_basic_block.simps)\napply(simp add: aux_basic_block.simps Let_def)\napply(simp split: reg_inst_splits if_splits; fastforce)\ndone\n\nlemma block_no:\n\"(n, insts, Terminal) \\<in> set (aux_basic_block ys bl) \\<Longrightarrow>\n reg_block bl \\<Longrightarrow>\n insts \\<noteq> [] \\<and> last_no insts\"\napply(induction ys arbitrary:bl)\n apply(case_tac bl; simp add: aux_basic_block.simps last_no_def)\napply(simp add: aux_basic_block.simps Let_def)\napply(case_tac \"reg_inst (snd a) \\<and> snd a \\<noteq> Pc JUMPDEST\")\n apply(drule_tac x=\"bl @ [a]\" in meta_spec; simp add: reg_block_def)\n apply(simp split: reg_inst_splits if_splits)\napply(case_tac \"snd a = Pc JUMPDEST\")\n apply(simp; case_tac bl; simp split: if_splits)\n  apply(drule_tac x=\"[a]\" in meta_spec; simp add: reg_block_def)\n apply(drule_tac x=\"[a]\" in meta_spec; simp add: reg_block_def)\napply(drule_tac x=\"[]\" in meta_spec; simp add: reg_block_def)\napply(simp split: reg_inst_splits if_splits)\n  apply(erule disjE; simp add: last_no_def)+\ndone\n\n(* Main theorem *)\n\nlemma wf_build_blocks:\n\"fst (last (add_address bytecode)) < 2^256 \\<Longrightarrow>\nwf_blocks (build_blocks bytecode)\"\n apply(simp add: wf_blocks_def)\n apply(clarsimp)\n apply(rule conjI)\n  apply(clarsimp; rule conjI)\n   apply(case_tac \"\\<not> block_lookup (build_blocks bytecode) n = None\")\n    apply(simp add: index_have_blocks)\n   apply(simp)\n  apply(simp add: build_blocks_def Let_def)\n  apply(drule map_of_SomeD)\n  apply(rule conjI)\n    apply(cut_tac reg_bb[where insts=bytecode])\n     apply(simp add: reg_basic_blocks_def list_all_in)\n  apply(rule conjI)\n\t apply(simp add: build_basic_blocks_def)\n\t apply(drule in_aux_bb_intermediate, clarify)\n\t apply(case_tac insts; clarsimp simp add: index_block_eq)\n\tapply(simp add: build_basic_blocks_def)\n  apply(rule_tac ty=ty in sequential_basic_blocks[where ys=\"add_address bytecode\" and bl=\"[]\"])\n       apply(simp add: seq_block_add_address add_address_def)\n      apply(simp add: seq_block.simps)\n     apply(clarsimp simp add: list_all_def add_address_def)\n     apply(cut_tac x=a and y=b in bound_add_address'[where xs=bytecode and k=0]; simp)\n    apply(simp)+\n apply(thin_tac \"_ < _\")\n apply(rule conjI)\n  apply(simp add: build_blocks_def Let_def build_basic_blocks_def)\n  apply(rule impI)\n  apply(drule map_of_SomeD)\n  apply(drule in_aux_bb_intermediate, clarify)\n  apply(drule non_empty_block_next; simp)\n apply(rule impI)\n apply(simp add: build_blocks_def Let_def build_basic_blocks_def)\n apply(drule map_of_SomeD)\n apply(drule block_no; simp add: reg_block_def)\ndone\n\n(* Check that we can rebuild the initial list of instructions from basic blocks *)\nfun inst_size_list::\"pos_inst list \\<Rightarrow> int\" where\n\"inst_size_list [] = 0\"\n| \"inst_size_list (x#xs) = inst_size (snd x) + inst_size_list xs\"\n\nlemma seq_block_sumC:\n\"seq_block ((i,j) # list @ (a, b) # xs) \\<Longrightarrow>\n i + (inst_size j + inst_size_list list) = a\"\napply(induction list arbitrary: i j; clarsimp)\n apply(simp add: seq_block.simps)\napply(simp add: seq_block.simps)\napply(fastforce)\ndone\n\nfun rebuild_with_add :: \"basic_blocks \\<Rightarrow> pos_inst list\" where\n \"rebuild_with_add [] = []\"\n| \"rebuild_with_add ((n,b,Jump)#q) = b@[(n+inst_size_list b,Pc JUMP)] @ (rebuild_with_add q)\"\n| \"rebuild_with_add ((n,b,Jumpi)#q) = b@[(n+inst_size_list b,Pc JUMPI)] @ (rebuild_with_add q)\"\n| \"rebuild_with_add ((n,b,_)#q) = b @ (rebuild_with_add q)\"\n\nlemma rev_rebuild_with_add_aux:\nnotes if_split[split del]\nshows\n\"seq_block (b@c) \\<Longrightarrow>\nrebuild_with_add (aux_basic_block c b) =\n    b@c\"\napply(induction c arbitrary: b)\n  apply(case_tac b; simp add: aux_basic_block.simps)\napply(simp add: aux_basic_block.simps Let_def)\napply(case_tac \"reg_inst (snd a) \\<and> snd a \\<noteq> Pc JUMPDEST\")\n apply(simp split: reg_inst_splits)\n apply(drule conjunct1; rule conjI, clarsimp)\n apply(rule conjI)\n  apply(rule allI; clarify; rule conjI; clarsimp)\n apply(clarsimp)\napply(case_tac \"snd a = Pc JUMPDEST\"; clarsimp)\n apply(simp split: if_splits)\n apply(drule_tac x=\"[(a, Pc JUMPDEST)]\" in meta_spec)\n apply(simp add: seq_block_tl')\napply(drule_tac x=\"[]\" in meta_spec)\napply(drule meta_mp)\napply(simp add: seq_block_tl'[where xs=\"_ @ [(_,_)]\"])\napply(case_tac b; simp)\n apply(rename_tac x; case_tac x; simp add: block_pt_def; case_tac ba; simp add: seq_block_sumC)+\ndone\n  \nlemma rev_rebuild_with_add:\n\"rebuild_with_add (build_blocks c) = add_address c\"\napply(simp add: build_blocks_def Let_def)\napply(simp add: build_basic_blocks_def)\napply(subst rev_rebuild_with_add_aux)\n apply(simp add: seq_block_add_address add_address_def)\napply(simp)\ndone\n\nfun reconstruct_bytecode :: \"basic_blocks \\<Rightarrow> inst list\" where\n \"reconstruct_bytecode [] = []\"\n| \"reconstruct_bytecode ((n,b,Jump)#q) = (map snd b)@[Pc JUMP] @ (reconstruct_bytecode q)\"\n| \"reconstruct_bytecode ((n,b,Jumpi)#q) = (map snd b)@[Pc JUMPI] @ (reconstruct_bytecode q)\"\n| \"reconstruct_bytecode ((n,b,_)#q) = (map snd b) @ (reconstruct_bytecode q)\"\n\nlemma rev_basic_blocks: \"reconstruct_bytecode (aux_basic_block i b) = (map snd b)@(map snd i)\"\napply(induction i arbitrary: b)\napply(case_tac b)\napply(auto simp: Let_def aux_basic_block.simps split: reg_inst_splits)\ndone\n\nlemma remove_address:\n\"map snd (add_address' i k) = i\"\nby(induction i arbitrary: k; simp)\n\nlemma reverse_basic_blocks: \"reconstruct_bytecode (build_basic_blocks i) = i\"\napply(simp add: rev_basic_blocks build_basic_blocks_def add_address_def remove_address)\ndone\n\ndefinition blocks_insts :: \"basic_blocks \\<Rightarrow> pos_inst set\" where\n\"blocks_insts b = set (rebuild_with_add b)\"\n\nend\n", "meta": {"author": "pirapira", "repo": "eth-isabelle", "sha": "d0bb02b3e64a2046a7c9670545d21f10bccd7b27", "save_path": "github-repos/isabelle/pirapira-eth-isabelle", "path": "github-repos/isabelle/pirapira-eth-isabelle/eth-isabelle-d0bb02b3e64a2046a7c9670545d21f10bccd7b27/attic/BasicBlocks.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6224593452091672, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.29422624734834735}}
{"text": "theory Proof_1_500\n  imports Proofs1\nbegin\n\nabbreviation s where \" s s0 PdOut'value paid'value opened'value \\<equiv>\n(toEnv\n   (setPstate\n     (setVarBool (setVarBool (setVarBool s0 PdOut' PdOut'value) paid' paid'value) opened' opened'value)\n     Init'init' Controller'isOpened'))\"\n\ntheorem proof_1_500: \"VC500 inv1 env s0 PdOut_value paid_value opened_value\"\n  apply(unfold VC500_def inv1_def R1_def)\n apply(rule impI)\n  apply(rule conjI)\n   apply(rule conjI)\n    apply simp\n   apply(unfold extraInv_def)\n   apply(erule conjE)\n   apply(erule conjE)\n   apply((rule allI)+)\n  subgoal premises vc_prems for s1 s2\n    apply(insert vc_prems(2))\n    apply(erule conjE)\n    subgoal premises invs0\n      apply(rule impI)\n      apply((erule conjE)+)\n      apply(erule le_imp_less_or_eq[THEN disjE])\n      apply(rule cut_rl[of \"    \\<exists>s4. toEnvP s4 \\<and>\n         substate s2 s4 \\<and>\n         substate s4 s0 \\<and>\n         toEnvNum s2 s4 \\<le> 10 - 1 \\<and>\n         \\<not> getVarBool s4 Controller'minimalOpened' \\<and>\n         (\\<forall>s3. toEnvP s3 \\<and> substate s2 s3 \\<and> substate s3 s4 \\<and> s3 \\<noteq> s4 \\<longrightarrow> getVarBool s3 Controller'minimalOpened')\"])\n      apply(erule exE)\n    subgoal for s4\n      apply(rule exI[of _ s4])\n      by simp\n     apply(insert invs0(1))[1]\n     apply(erule conjE)\n     apply(erule allE[of _ s1])\n     apply(erule allE[of _ s2])\n     apply(simp split: if_splits)\n      apply(rule cut_rl[of \"\\<forall> s5. toEnvP s5 \\<and> substate s2 s5 \\<and> substate s5 (s s0 PdOut_value paid_value opened_value) \\<longrightarrow>\npred1 s1 s2 (s s0 PdOut_value paid_value opened_value) s5\"])\n     apply(erule allE[of _ s2])\n     apply(erule impE)\n    using substate_refl apply blast\n     apply(unfold pred1_def)\n     apply(erule impE)\n      apply(insert substate_refl substate_trans substate_antisym)[1]\n     apply blast\n     apply assumption\n      apply(rule allI)\n      subgoal premises prems for s5\n        apply(induction rule: state_ind)\n        using prems apply simp\n         apply(rule impI)\n\n         apply(rule impE[OF minimalOpened_not_passed_R1[of s1 s2 s0 s0]])\n        using vc_prems(1) apply(simp split: if_splits)\n        using invs0(2) substate_refl\n          apply (smt (verit))\n         apply(erule exE)\n        subgoal for s3\n          apply((erule conjE)+)\n          apply(erule allE[of _ s3])\n          apply(erule impE)\n          using substate_antisym[of s3 s0] substate_refl  apply auto[1]\n          by blast\n\n        subgoal for s5\n          apply(rule impI)\n          apply(cases \"getVarBool (predEnv s5) open' = False\")\n           apply(rule exI[of _ \"predEnv s5\"])\n           apply(rule conjI)\n        apply(rule toEnvP_substate_pred_imp_toEnvP_pred[of s2])\n            apply blast\n       apply(rule conjI)\n          using substate_refl apply simp\n       apply(rule conjI)\n      using predEnv_substate substate_trans apply blast\n       apply(rule conjI)\n      using toEnvNum3[of s2 \"predEnv s5\"\n \"(s s0 PdOut_value paid_value opened_value) \"] \n       apply fastforce\n     apply(rule conjI)\n        apply blast\n      using substate_antisym apply blast\n      apply(drule impE)\n        prefer 3\n        apply assumption\n       apply(((rule conjI),blast)+)\n      using substate_imp_substatete_predEnv_or_eq apply blast\n      apply(drule exE)\n       prefer 2\n       apply assumption\n      subgoal for s4\n        apply(rule exI[of _ s4])\n       apply(rule conjI)\n         apply blast\n        apply(rule conjI)\n        using predEnv_substate substate_trans apply blast\n        apply(((rule conjI),blast)+)\n        using predEnv_substate_imp_substate_or_eq by blast\n      done\n    done\n  done\n  done\n     \n", "meta": {"author": "ivchernenko", "repo": "post_vcgenerator", "sha": "fadfff131086870a027d6bd1c78b8d5a3baf183b", "save_path": "github-repos/isabelle/ivchernenko-post_vcgenerator", "path": "github-repos/isabelle/ivchernenko-post_vcgenerator/post_vcgenerator-fadfff131086870a027d6bd1c78b8d5a3baf183b/case-studies/turnstile/Proof_1_500.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6224593452091672, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.29422624734834735}}
{"text": "theory Finite_Linear_Priority_Tick\n\nimports\n  Finite_Linear_Priority\n  Finite_Linear_Tick_Param\n  Finite_Linear_Induction\nbegin\n\nlemma prirelacc_not_in_imp [simp]:\n  assumes \"prirelacc p A Z\" \"e \\<notin>\\<^sub>\\<F>\\<^sub>\\<L> Z\"\n  shows \"e \\<notin>\\<^sub>\\<F>\\<^sub>\\<L> A\"\n  using assms by(induct p A Z rule:prirelacc.induct, auto)\n\nlemma pri_tickWF:\n  assumes \"prirel p x Z\" \"tickWF tick Z\"\n  shows \"tickWF tick x\"\n  using assms apply (induct p x Z arbitrary:tick rule:prirel.induct, auto)\n  by (case_tac aa, auto, case_tac x1, auto)\n\nlemma FLTick0_pri:\n  assumes \"FLTick0 tick P\"\n  shows \"FLTick0 tick (Pri p P)\"\n  using assms unfolding FLTick0_def Pri_def apply auto\n  by (simp add: pri_tickWF)\n\nlemma prirel_extend_both_last_null_imp:\n  assumes \"prirel p (\\<beta> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>A\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) (\\<Gamma> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>A\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>)\" \"length \\<beta> = length \\<Gamma>\" \"a \\<in>\\<^sub>\\<F>\\<^sub>\\<L> A\" \"last \\<beta> = \\<bullet>\" \"last \\<Gamma> = \\<bullet>\"\n  shows \"prirel p (\\<beta> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(A,a)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) (\\<Gamma> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(A,a)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>)\"\n  using assms by (induct \\<beta> \\<Gamma> rule:prirel.induct, auto)\n\nlemma prirel_extend_both_last_null_imp2:\n  assumes \"prirel p (\\<beta> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>A\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) (\\<Gamma> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>B\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>)\" \"length \\<beta> = length \\<Gamma>\" \"a \\<in>\\<^sub>\\<F>\\<^sub>\\<L> A\" \"last \\<beta> = \\<bullet>\" \"last \\<Gamma> = \\<bullet>\" \"\\<forall>e. e \\<in>\\<^sub>\\<F>\\<^sub>\\<L> A  \\<longrightarrow> e \\<in>\\<^sub>\\<F>\\<^sub>\\<L> B\"\n  shows \"prirel p (\\<beta> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(A,a)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) (\\<Gamma> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(B,a)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>)\"\n  using assms by (induct \\<beta> \\<Gamma> rule:prirel.induct, auto)\n\nlemma prirel_eq_length_imp_last_member:\n  assumes \"length xs = length ys\" \"last xs = \\<bullet>\" \"last ys \\<noteq> \\<bullet>\" \"prirel p (xs &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>x\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) ys\"\n  shows  \"\\<forall>e. e \\<in>\\<^sub>\\<F>\\<^sub>\\<L> x  \\<longrightarrow> e \\<in>\\<^sub>\\<F>\\<^sub>\\<L> last ys\"\n  using assms\nproof(induct p xs ys rule:prirel.induct)\n  case (1 p A Z)\n  then show ?case apply auto\n    apply (cases x, auto)\n    apply (cases A, auto)\n    by (cases Z, auto)\nnext\n  case (2 p A Z zz)\nthen show ?case by auto\nnext\n  case (3 p A aa Z)\n  then show ?case by auto\nnext\n  case (4 p A aa Z zz)\n  then show ?case by auto\nqed\n \nlemma pri_FL2:\n  assumes \"FL2 P\" \"a \\<in>\\<^sub>\\<F>\\<^sub>\\<L> A\" \"prirel p (\\<beta> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>A\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) Z\" \"Z \\<in> P\"\n  shows \"\\<exists>Z. prirel p (\\<beta> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(A,a)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) Z \\<and> Z \\<in> P\"\n  using assms\nproof (cases \"last \\<beta> = \\<bullet>\")\n  case True\n  then obtain \\<Gamma> where pGama:\"prirel p (\\<beta> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>A\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) (\\<Gamma> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>A\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) \\<and> \\<Gamma> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>A\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L> = Z \\<and> length \\<beta> = length \\<Gamma>\"\n    using assms \n    by (metis Finite_Linear_Model.last.simps(1) acceptance.distinct(1) add_cancel_right_right amember.elims(2) concat_FL_last_not_bullet_absorb last_bullet_then_last_cons length.simps(1) length_cons prirel_cons_eq_length_imp_prirel_acceptances_last_bullet_eq prirel_cons_eq_length_imp_prirel_acceptances_last_not_bullet prirel_same_length)\n  then show ?thesis\n  proof (cases \"last \\<Gamma> = \\<bullet>\")\n    case True\n    then show ?thesis \n      by (metis FL2_def pGama assms(1) assms(2) assms(4) concat_FL_last_not_bullet_absorb prirel_extend_both_last_null_imp)\n  next\n    case False\n    then have \"\\<Gamma> = Z\"\n      using concat_FL_last_not_bullet_absorb pGama by fastforce\n    then have \"\\<forall>e. e \\<in>\\<^sub>\\<F>\\<^sub>\\<L> A \\<longrightarrow> e \\<in>\\<^sub>\\<F>\\<^sub>\\<L> last \\<Gamma>\"\n      using True pGama False assms(3) prirel_eq_length_imp_last_member by blast\n    then have \"\\<Gamma> = butlast \\<Gamma> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>last \\<Gamma>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>\"\n      by (simp add: butlast_last_cons2_FL)\n    then have \"butlast \\<Gamma> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(last \\<Gamma>,a)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L> \\<in> P\"\n      by (metis FL2_def \\<open>\\<Gamma> = Z\\<close> \\<open>\\<forall>e. e \\<in>\\<^sub>\\<F>\\<^sub>\\<L> A \\<longrightarrow> e \\<in>\\<^sub>\\<F>\\<^sub>\\<L> Finite_Linear_Model.last \\<Gamma>\\<close> assms(1) assms(2) assms(4))\n\n    have \"prirel p (\\<beta> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>A\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) \\<Gamma>\"\n      using pGama \\<open>\\<Gamma> = Z\\<close> by auto\n    then have \"prirel p (\\<beta> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>A\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) (butlast \\<Gamma> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>last \\<Gamma>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>)\"\n      by (simp add: butlast_last_cons2_FL)\n    have \"length \\<beta> = length (butlast \\<Gamma>)\"\n      by (metis butlast_last_cons2_FL pGama rev_rev_butlast strong_less_eq_fltrace_cons_imp_lhs strong_less_eq_fltrace_eq_length strong_less_eq_fltrace_refl)\n\n    then have \"prirel p (\\<beta> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(A,a)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) (butlast \\<Gamma> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(last \\<Gamma>,a)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>)\"\n      using True \\<open>\\<forall>e. e \\<in>\\<^sub>\\<F>\\<^sub>\\<L> A \\<longrightarrow> e \\<in>\\<^sub>\\<F>\\<^sub>\\<L> Finite_Linear_Model.last \\<Gamma>\\<close> \\<open>prirel p (\\<beta> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>A\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) (Finite_Linear_Model.butlast \\<Gamma> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>Finite_Linear_Model.last \\<Gamma>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>)\\<close> assms(2) last_butlast_cons_bullet prirel_extend_both_last_null_imp2 by fastforce\n    then show ?thesis\n      using \\<open>Finite_Linear_Model.butlast \\<Gamma> &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(Finite_Linear_Model.last \\<Gamma>,a)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L> \\<in> P\\<close> by blast\n  qed\nnext\ncase False\n  then show ?thesis \n    using assms\n    by (metis concat_FL_last_not_bullet_absorb)\nqed\n\nlemma FL2_pri:\n  assumes \"FL2 P\"\n  shows \"FL2 (Pri p P)\"\n  using assms unfolding FL2_def Pri_def apply auto\n  by (simp add: assms pri_FL2)\n\ntext \\<open>Does Pri distribute through sequential composition in this model?\\<close>\n\nlemma prirel_consFL_both_imp:\n  assumes \"prirel p (x &\\<^sub>\\<F>\\<^sub>\\<L>y) (s &\\<^sub>\\<F>\\<^sub>\\<L> t)\" \"length x = length s\" \"last x = \\<bullet>\" \"last s = \\<bullet>\"\n  shows \"prirel p x s\"\n  using assms by(induct x s rule:prirel.induct, auto)\n\nlemma prirel_consFL_both_imp':\n  assumes \"prirel p x s\" \"prirel p y t\" \n  shows \"prirel p (x &\\<^sub>\\<F>\\<^sub>\\<L>y) (s &\\<^sub>\\<F>\\<^sub>\\<L> t)\" \n  using assms apply(induct x s rule:prirel.induct, auto)\n   apply (case_tac A, auto, case_tac Z, auto)\n  apply (smt Collect_cong Finite_Linear_Model.last.simps(1) acceptance.distinct(1) concat_FL_last_not_bullet_absorb prirel.simps(1) prirelacc.simps(2))\n  by (case_tac A, auto)\n\nlemma prirel_consFL_exists:\n  assumes \"prirel p x (s &\\<^sub>\\<F>\\<^sub>\\<L> t)\"\n  shows \"\\<exists>y. prirel p y s\"\n  using assms apply(induct x s rule:prirel.induct, auto)     \n        apply (metis Finite_Linear_Model.last.simps(1) concat_FL_last_not_bullet_absorb prirelAlt_bullet_refl prirelAlt_imp_prirel)\n       apply (metis Finite_Linear_Model.last.simps(1) concat_FL_last_not_bullet_absorb prirelAlt_bullet_refl prirelAlt_imp_prirel)\n  using prirel.simps(4) apply fastforce\n     apply (metis prirel.simps(4))\n  using prirel.simps(4) apply fastforce\n  using prirel.simps(4) apply fastforce\n  by (metis prirel.simps(4) prirelacc.simps(1))\n  \n\nlemma prirel_consFL_last_bullet_exists:\n  assumes \"prirel p x (s &\\<^sub>\\<F>\\<^sub>\\<L> t)\" \"last s = \\<bullet>\"\n  shows \"\\<exists>s0 t0. x = s0 &\\<^sub>\\<F>\\<^sub>\\<L> t0 \\<and> prirel p s0 s \\<and> prirel p t0 t\"\n  using assms apply(induct x s rule:prirel.induct, auto)\n        apply (metis bullet_left_zero2 prirelAlt_bullet_refl prirelAlt_imp_prirel)\n       apply (metis bullet_left_zero2 prirelAlt_bullet_refl prirelAlt_imp_prirel)\n      apply (metis fltrace_concat2.simps(2) prirel.simps(4))\n     apply (metis acceptance.rep_eq amember.simps(1) event.rep_eq fltrace_concat2.simps(2) prirel.simps(4))\n    apply (metis acceptance.rep_eq event.rep_eq fltrace_concat2.simps(2) prirel.simps(4))\n   apply (metis acceptance.rep_eq fltrace_concat2.simps(2) prirel.simps(4) prirelacc.simps(1))\n  by (metis fltrace_concat2.simps(2) prirel.simps(4) prirelacc.simps(1))\n\nlemma prirel_consFL_last_bullet_exists':\n  assumes \"prirel p (s &\\<^sub>\\<F>\\<^sub>\\<L> t) x\" \"last s = \\<bullet>\"\n  shows \"\\<exists>s0 t0. x = s0 &\\<^sub>\\<F>\\<^sub>\\<L> t0 \\<and> prirel p s s0 \\<and> prirel p t t0\"\n  using assms apply(induct x s rule:prirel.induct, auto)\n  apply (metis bullet_left_zero2 prirelAlt_bullet_refl prirelAlt_imp_prirel)\n       apply (metis bullet_left_zero2 prirelAlt_bullet_refl prirelAlt_imp_prirel)\n      apply (metis fltrace_concat2.simps(2) prirel.simps(4))\n     apply (metis acceptance.rep_eq amember.simps(1) event.rep_eq fltrace_concat2.simps(2) prirel.simps(4))\n    apply (metis acceptance.rep_eq event.rep_eq fltrace_concat2.simps(2) prirel.simps(4))\n   apply (metis acceptance.rep_eq fltrace_concat2.simps(2) prirel.simps(4) prirelacc.simps(1))\n  by (metis fltrace_concat2.simps(2) prirel.simps(4) prirelacc.simps(1))\n(* non trivial *)\n\nlemma prirel_not_events:\n  assumes \"prirel p x s\" \"tick \\<notin> events s\"\n  shows \"tick \\<notin> events x\"\n  using assms by (induct p x s rule:prirel.induct, auto)\n\nlemma prirel_not_events':\n  assumes \"prirel p x s\" \"tick \\<notin> events x\"\n  shows \"tick \\<notin> events s\"\n  using assms by (induct p x s rule:prirel.induct, auto)\n\nlemma prirel_consFL_both_imp_prirel:\n  assumes \"prirel p (s &\\<^sub>\\<F>\\<^sub>\\<L> t) (u &\\<^sub>\\<F>\\<^sub>\\<L> v)\" \"last s = \\<bullet>\" \"last u = \\<bullet>\" \"length s = length u\"\n  shows \"prirel p t v\"\n  using assms by(induct p s u rule:prirel.induct, auto)\n\nlemma prirel_consFL_last_bullet_both:\n  assumes \"prirel p (s &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(\\<bullet>,b)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) (ys &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(a,c)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>)\" \"last s = \\<bullet>\" \"last ys = \\<bullet>\" \"maximal(p,b)\" \"c \\<in>\\<^sub>\\<F>\\<^sub>\\<L> a \\<or> a = \\<bullet>\"\n  shows \"b = c\"\n  using assms apply(induct p s ys rule:prirel.induct, auto)\n         apply (case_tac Z, auto)\n          apply (metis (no_types, hide_lams) Finite_Linear_Model.butlast.simps(1) butlast_last_cons2_FL concat_FL_last_not_bullet_absorb fltrace.exhaust prirel.simps(1) prirel.simps(2) rev3.simps(1) rev3_little_more_extra)\n         apply (metis fltrace.distinct(1) fltrace.exhaust prirel.simps(2) rev3.simps(1) rev3_little_more_extra)\n  apply (metis Finite_Linear_Model.butlast.simps(1) bullet_left_zero2 butlast_last_cons2_FL fltrace.exhaust fltrace_concat2.simps(2) prirel.simps(2))\n  by (metis Finite_Linear_Model.butlast.simps(1) bullet_right_zero2 butlast_last_cons2_FL fltrace.exhaust fltrace_concat2.simps(2) prirel.simps(3) s_and_tick_iff)+\n\nlemma tickWF_consFL_tick_imp_bullet:\n  assumes \"tickWF tick (ys &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(y,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>)\" \"last ys = \\<bullet>\" \"tick \\<in>\\<^sub>\\<F>\\<^sub>\\<L> y \\<or> y = \\<bullet>\"\n  shows \"y = \\<bullet>\"\n  using assms apply (induct ys rule:tickWF.induct, auto)\n  by (metis fltrace.distinct(1) rev3.simps(1) rev3_little_more)\n\nlemma prirel_exists_tick_max:\n  assumes \"prirel p S Z\" \"last s = \\<bullet>\" \"maximal(p,tick)\" \"S = (s &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(\\<bullet>,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>)\" \"tickWF tick Z\"\n  shows \"\\<exists>z. last z = \\<bullet> \\<and> Z = (z &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(\\<bullet>,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) \\<and> length s = length z\"\n  using assms \nproof (induct S Z rule:ftrace_cons_induct_both_eq_length)\n  case 1\n  then show ?case \n    using assms(1) prirel_same_length by blast\nnext\n  case (2 x y)\n  then show ?case \n    by (metis fltrace.distinct(1) rev3.simps(1) rev3_little_more)\nnext\n  case (3 x y xs ys)\n  then show ?case \n    by (metis Finite_Linear_Model.last.simps(1) bullet_right_zero2 last_bullet_then_last_cons last_cons_bullet_iff prirel.simps(1) prirel_consFL_both_imp_prirel)\nnext\n  case (4 x y xs ys)\n  then have \"prirel p (s &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(\\<bullet>,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) (ys &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>y,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>)\"\n    by auto\n  then obtain yA yEvent where yA:\"y = (yA,yEvent)\\<^sub>\\<F>\\<^sub>\\<L> \\<and> (yEvent \\<in>\\<^sub>\\<F>\\<^sub>\\<L> yA \\<or> yA = \\<bullet>)\"\n    proof -\n      assume a1: \"\\<And>yA yEvent. y = (yA,yEvent)\\<^sub>\\<F>\\<^sub>\\<L> \\<and> (yEvent \\<in>\\<^sub>\\<F>\\<^sub>\\<L> yA \\<or> yA = \\<bullet>) \\<Longrightarrow> thesis\"\n      have \"y \\<le> (acceptance y,event y)\\<^sub>\\<F>\\<^sub>\\<L>\"\n        by (simp add: less_eq_aevent_def)\n      then show ?thesis\n        using a1 by (metis aevent_less_eq_iff_components event_in_acceptance)\n    qed\n  then have \"prirel p (s &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(\\<bullet>,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) (ys &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(yA,yEvent)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>)\"\n    using \"4.prems\"(1) \"4.prems\"(4) by auto\n  then have \"yEvent = tick\"\n            \"yA = \\<bullet>\"\n    using prirel_consFL_last_bullet_both \"4.hyps\"(4) yA assms(2) assms(3) apply fastforce\n    using 4 tickWF_consFL_tick_imp_bullet \n    by (metis prirel_consFL_last_bullet_both yA)\n  then have \"ys &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>y,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L> = ys &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(\\<bullet>,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L> \\<and> Finite_Linear_Model.length s = Finite_Linear_Model.length ys\"\n    by (metis \"4.hyps\"(2) \"4.hyps\"(3) \"4.prems\"(4) assms(2) fltrace.inject(2) rev3_little_more rev3_rev3_const2_last yA)\n  then show ?case\n    using \"4.hyps\"(4) by blast\nqed\n\nlemma pri_dist_SeqComp:\n  assumes \"FLTick0 tick P\" \"maximal(p,tick)\"\n  shows \"Pri p (P (tick);\\<^sub>\\<F>\\<^sub>\\<L> Q) = ((Pri p P) (tick);\\<^sub>\\<F>\\<^sub>\\<L> (Pri p Q))\"\n  using assms unfolding Pri_def SeqComp_def\nproof (auto)\n  fix \"x\" \"s\" \"t\"\n  assume  assm0:\"FLTick0 tick P\"\n      and assm1:\"prirel p x (s &\\<^sub>\\<F>\\<^sub>\\<L> t)\"\n      and assm2:\"s &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(\\<bullet>,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L> \\<in> P\"\n      and assm3:\"t \\<in> Q\"\n  show \"\\<exists>s. (\\<exists>Z. prirel p (s &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(\\<bullet>,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) Z \\<and> Z \\<in> P) \\<and> (\\<exists>t. (\\<exists>Z. prirel p t Z \\<and> Z \\<in> Q) \\<and> x = s &\\<^sub>\\<F>\\<^sub>\\<L> t) \\<or>\n           (\\<exists>Z. prirel p s Z \\<and> Z \\<in> P) \\<and> tick \\<notin> events s \\<and> x = s\"\n  proof (cases \"last s = \\<bullet>\")\n    case True\n    then obtain s0 t0 where s0t0:\"x = s0 &\\<^sub>\\<F>\\<^sub>\\<L> t0 \\<and> prirel p s0 s \\<and> prirel p t0 t\"\n      using assm1 prirel_consFL_last_bullet_exists by blast\n    then have \"prirel p \\<langle>(\\<bullet>,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(\\<bullet>,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>\"\n      using assms(2) by auto\n    then have \"prirel p (s0 &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(\\<bullet>,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) (s &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(\\<bullet>,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>)\"\n      using s0t0 prirel_consFL_both_imp' by blast    \n    then show ?thesis\n      using assm2 assm3 s0t0 by blast\n  next\n    case False\n    then show ?thesis\n      by (smt FLTick0_def assm1 assm2 assms bullet_right_zero2 concat_FL_last_not_bullet_absorb last_rev3_is_bullet length.simps(1) length_cons pri_tickWF prirel.simps(1) prirel_cons_eq_length_imp_prirel_acceptances_eq prirel_same_length rev3_rev3_const2_last tickWF_last_x_is_emptyset)\n  qed\nnext\n  fix \"x\" \"s\"\n  assume  assm0:\"FLTick0 tick P\"\n    and   assm1:\"maximal(p,tick)\"\n    and   assm2:\"prirel p x s\"\n    and   assm3:\"s \\<in> P\"\n    and   assm4:\"tick \\<notin> events s\"\n  show \"\\<exists>s. (\\<exists>Z. prirel p (s &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(\\<bullet>,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) Z \\<and> Z \\<in> P) \\<and> (\\<exists>t. (\\<exists>Z. prirel p t Z \\<and> Z \\<in> Q) \\<and> x = s &\\<^sub>\\<F>\\<^sub>\\<L> t) \\<or>\n            (\\<exists>Z. prirel p s Z \\<and> Z \\<in> P) \\<and> tick \\<notin> events s \\<and> x = s\"\n  proof -\n    have \"tick \\<notin> events x\"\n      using assm2 assm4 prirel_not_events\n      by fastforce\n    then show ?thesis\n      using assm2 assm3 by blast\n  qed\nnext\n  fix \"s\" \"t\" \"Z\" \"Za\"\n  assume \n      assm0: \"FLTick0 tick P\"\n  and assm1: \"maximal(p,tick)\"\n  and assm2: \"prirel p (s &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(\\<bullet>,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) Z\"\n  and assm3: \"Z \\<in> P\"\n  and assm4: \"prirel p t Za\"\n  and assm5: \"Za \\<in> Q\"\n  show \"\\<exists>Z. prirel p (s &\\<^sub>\\<F>\\<^sub>\\<L> t) Z \\<and> (\\<exists>s. s &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(\\<bullet>,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L> \\<in> P \\<and> (\\<exists>t. t \\<in> Q \\<and> Z = s &\\<^sub>\\<F>\\<^sub>\\<L> t) \\<or> s \\<in> P \\<and> tick \\<notin> events s \\<and> Z = s)\"\n  proof (cases \"last s = \\<bullet>\")\n    case True\n    then obtain s0 where s0:\"prirel p (s &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(\\<bullet>,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) (s0 &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(\\<bullet>,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) \\<and> last s0 = \\<bullet> \\<and> length s = length s0 \\<and> Z = (s0 &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(\\<bullet>,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>)\"\n      by (metis FLTick0_def assm0 assm1 assm2 assm3 prirel_exists_tick_max)\n    then have \"prirel p s s0\"\n      using True prirel_consFL_both_imp by blast\n    then have \"prirel p (s &\\<^sub>\\<F>\\<^sub>\\<L> t) (s0 &\\<^sub>\\<F>\\<^sub>\\<L> Za)\"\n      by (simp add: assm4 prirel_consFL_both_imp')\n    then have \"\\<exists>Z. prirel p (s &\\<^sub>\\<F>\\<^sub>\\<L> t) (s0 &\\<^sub>\\<F>\\<^sub>\\<L> Za) \\<and> s0 &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(\\<bullet>,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L> \\<in> P \\<and> Za \\<in> Q \\<and> Z = s0 &\\<^sub>\\<F>\\<^sub>\\<L> Za\"\n      using s0 assm5 assm3 by blast\n    then show ?thesis\n      by blast\n  next\n    case False\n    then show ?thesis \n      by (metis FLTick0_def \\<open>Z \\<in> P\\<close> \\<open>prirel p (s &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(\\<bullet>,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L>) Z\\<close> assms(1) concat_FL_last_not_bullet_absorb prirel_cons_eq_length_imp_prirel_acceptances_last_bullet_eq prirel_cons_eq_length_imp_prirel_acceptances_last_not_bullet prirel_same_length tickWF_last_x_is_emptyset)\n  qed\nnext\n  fix \"s\" \"Z\"\n  assume \n       assm0: \"FLTick0 tick P\"\n  and  assm1: \"maximal(p,tick)\"\n  and  assm2: \"tick \\<notin> events s\"\n  and  assm3: \"prirel p s Z\"\n  and  assm4: \"Z \\<in> P\"\n  show \"\\<exists>Z. prirel p s Z \\<and> (\\<exists>s. s &\\<^sub>\\<F>\\<^sub>\\<L> \\<langle>(\\<bullet>,tick)\\<^sub>\\<F>\\<^sub>\\<L>,\\<bullet>\\<rangle>\\<^sub>\\<F>\\<^sub>\\<L> \\<in> P \\<and> (\\<exists>t. t \\<in> Q \\<and> Z = s &\\<^sub>\\<F>\\<^sub>\\<L> t) \\<or> s \\<in> P \\<and> tick \\<notin> events s \\<and> Z = s)\"\n    using assm3 assm4 assm2 apply (rule_tac x=\"Z\" in exI, auto)\n    apply (rule_tac x=\"Z\" in exI, auto)\n    by (simp add: prirel_not_events')+\nqed\n\nend", "meta": {"author": "UoY-RoboStar", "repo": "tick-tock-CSP", "sha": "7186d2e7f70116589850112a7353bc521372c913", "save_path": "github-repos/isabelle/UoY-RoboStar-tick-tock-CSP", "path": "github-repos/isabelle/UoY-RoboStar-tick-tock-CSP/tick-tock-CSP-7186d2e7f70116589850112a7353bc521372c913/FL/Finite_Linear_Priority_Tick.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5660185351961015, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.2940586976544659}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: GPL-2.0-only\n *)\n\ntheory Sep_Tactic_Examples\nimports\n  \"SepDSpec.Sep_Tactic_Helper\"\n  KHeap_DP\nbegin\n\n\n(* Thesis : Automated Tactics for Seperation Logic *)\n\n(* seperation logic *)\n\n(* after we show that addition and disjointedness on our heap obeys certain laws, we get a seperation algebra *)\n\n(* connectives *)\n\nterm \"P \\<and>* Q\"\n\nterm \"P \\<longrightarrow>* Q\"\n\nlemma frame_rule:\n  \"\\<And>R. \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>_. Q\\<rbrace> \\<Longrightarrow> \\<lbrace>P \\<and>* R\\<rbrace> f \\<lbrace>\\<lambda>_. Q \\<and>* R\\<rbrace>\"\n  oops\n\nthm swap_cap_wp[no_vars]\n\nlemma\n \"\\<lbrace><dest \\<mapsto>c - \\<and>* src \\<mapsto>c cap \\<and>* R>\\<rbrace>\n    move_cap cap' src dest\n  \\<lbrace>\\<lambda>_. <dest \\<mapsto>c cap'  \\<and>* src \\<mapsto>c NullCap \\<and>* R>\\<rbrace>\"\n  apply (simp add: move_cap_def)\n  apply (wp swap_parents_wp set_cap_wp) (* set_cap doesn't apply *)\nthm set_cap_wp[no_vars]\n   apply (rule hoare_strengthen_post)\n    apply (wp set_cap_wp)\n   apply (clarsimp simp: sep_conj_ac )\noops\n\n\n(* tactics we had pre-thesis *)\n\nlemma \"(A \\<and>* B \\<and>* C \\<and>* D) s  \\<Longrightarrow>  (A \\<and>* B \\<and>* C \\<and>* D) s\"\n  apply (sep_select 4)\n  apply (sep_select_asm 3)\n  apply (sep_select 2)\n  apply (sep_cancel)\n  apply (sep_cancel)\n  apply (sep_cancel)\ndone\n\n(* forward reasoning *)\n\n\nlemma example_drule:\n  \"(ptr \\<mapsto>o obj) s\n  \\<Longrightarrow> (ptr \\<mapsto>S obj \\<and>* ptr \\<mapsto>f obj) s\"\n  by (metis sep_conj_commute sep_map_o_decomp)\n\nlemma sep_drule_example:\n  \"(ptr \\<mapsto>o obj \\<and>* A \\<and>* B ) s\n  \\<Longrightarrow> (A \\<and>* B \\<and>* ptr \\<mapsto>f obj \\<and>* ptr \\<mapsto>S obj) s\"\n  apply (sep_drule  example_drule)\n  apply (sep_solve)\ndone\n\n(* backwards reasoning *)\n\nlemma example_rule:\n  \"(ptr \\<mapsto>f obj \\<and>* ptr \\<mapsto>S obj) s\n  \\<Longrightarrow> (ptr \\<mapsto>o obj) s\"\n  by (metis sep_map_o_decomp)\n\nlemma sep_rule_example: \"(ptr \\<mapsto>f obj \\<and>* A \\<and>* B \\<and>* ptr \\<mapsto>S obj ) s \\<Longrightarrow> (ptr \\<mapsto>o obj \\<and>* A \\<and>* B) s\"\n  apply (sep_rule example_rule)\n  apply (sep_solve)\ndone\n\n\n\n(* the state of proving before new stuff *)\n\nlemma swap_cap_wp_old:\n  \"\\<lbrace><dest \\<mapsto>c cap \\<and>*  src \\<mapsto>c cap' \\<and>* R>\\<rbrace>\n    swap_cap cap' src cap dest\n   \\<lbrace>\\<lambda>_.<dest \\<mapsto>c cap' \\<and>* src \\<mapsto>c cap \\<and>* R>\\<rbrace>\"\n  apply (clarsimp simp add: swap_cap_def)\n  apply (wp swap_parents_wp set_cap_wp)\n  apply (rule hoare_chain)\n    apply (rule set_cap_wp)\n    apply (sep_solve)+\ndone\n\n\nlemma move_cap_wp_old:\n \"\\<lbrace><dest \\<mapsto>c - \\<and>* src \\<mapsto>c cap \\<and>* R>\\<rbrace>\n    move_cap cap' src dest\n  \\<lbrace>\\<lambda>_. <dest \\<mapsto>c cap'  \\<and>* src \\<mapsto>c NullCap \\<and>* R>\\<rbrace>\"\n  including no_pre\n  apply (simp add: move_cap_def)\n  apply (wp swap_parents_wp)\n   apply (rule hoare_strengthen_post)\n    apply (rule set_cap_wp)\n   apply (sep_select 2)\n   apply (sep_solve)\n  apply (rule hoare_chain)\n    apply (rule insert_cap_orphan_wp)\n   apply (sep_solve)\n  apply (sep_solve)\ndone\n\nlemma invoke_cnode_rotate2_wp_old:\n  \"(dest) \\<noteq> (rnd) \\<Longrightarrow>\n  \\<lbrace><dest \\<mapsto>c cap1 \\<and>* src \\<mapsto>c cap2 \\<and>*\n    rnd \\<mapsto>c - \\<and>* R>\\<rbrace>\n     invoke_cnode (RotateCall cap1 cap2 dest src rnd)\n  \\<lbrace>\\<lambda>_. <dest \\<mapsto>c NullCap \\<and>* src \\<mapsto>c cap1 \\<and>*\n    rnd \\<mapsto>c cap2 \\<and>* R>\\<rbrace>\"\n  including no_pre\n  apply (clarsimp simp: invoke_cnode_def)\n  apply (wp)\n   apply (rule hoare_strengthen_post)\n    apply (rule move_cap_wp)\n   apply (sep_solve )\n  apply (rule hoare_chain)\n    apply (rule move_cap_wp)\n   apply (sep_select_asm 2, sep_select_asm 3)\n   apply (sep_solve)\n  apply (sep_solve)\ndone\n\n(* new sep_select/asm *)\n\nlemma \"(A \\<and>* B \\<and>* C \\<and>* D) s  \\<Longrightarrow>  (A \\<and>* B \\<and>* C \\<and>* D) s\"\n  apply (sep_select 4 3 2 1)\n  apply (sep_select_asm 4 3 2 1)\n  apply (sep_select_asm 2 4)\noops\n\n\n(* sep_select_pre/post *)\n\nlemma \"\\<lbrace>A \\<and>* B \\<and>* C \\<and>* D\\<rbrace> f \\<lbrace>\\<lambda>_. A \\<and>* B \\<and>* C \\<and>* D\\<rbrace>\"\n  apply (sep_select_pre 4 1 2 3)\n  apply (sep_select_post 3 4 2 1)\n  apply (sep_select_post 3 4)\noops\n\n(* can be made to work for arbitrary monads *)\n\nlemma \"\\<lbrace>A \\<and>* B \\<and>* C \\<and>* D\\<rbrace> f \\<lbrace>\\<lambda>_. A \\<and>* B \\<and>* C \\<and>* D\\<rbrace>, \\<lbrace>E\\<rbrace>\"\n  apply (sep_select_pre 4 1 2 3)\n  apply (sep_select_post 3 4 2 1)\n  apply (sep_select_post 3 4)\noops\n\nlemma \"\\<lbrace>A \\<and>* B \\<and>* C \\<and>* D\\<rbrace> f \\<lbrace>\\<lambda>_. A \\<and>* B \\<and>* C \\<and>* D\\<rbrace>, -\"\n  apply (sep_select_pre 4 1 2 3)\n  apply (sep_select_post 3 4 2 1)\n  apply (sep_select_post 3 4)\noops\n\nlemma \"(P \\<and>* (P \\<longrightarrow>* Q)) s \\<Longrightarrow> Q s\"\n  apply (sep_mp, assumption )\n  done\n\nlemma \"P s \\<Longrightarrow> (Q \\<longrightarrow>* (P \\<and>* Q)) s\"\n  apply (erule sep_curry[rotated])\n  apply (assumption)\n  done\n\nthm sep_mp[no_vars] sep_curry[rotated, no_vars]\n\n\n(* wp tactic testing *)\n\n\n(* sep_wand approach *)\n\nmethod_setup debug = \\<open>\n  Attrib.thms >> (fn _ => fn ctxt =>\n   let\n     val wp_pre_tac = SELECT_GOAL (Method.NO_CONTEXT_TACTIC ctxt\n                      (Method_Closure.apply_method ctxt @{method wp_pre} [] [] [] ctxt []))\n   in\n     SIMPLE_METHOD' (CHANGED o wp_pre_tac)\n   end\n)\n\\<close>\n\nlemma move_cap_wp2:\n \"\\<lbrace><dest \\<mapsto>c - \\<and>* src \\<mapsto>c cap \\<and>* R>\\<rbrace>\n    move_cap cap' src dest\n  \\<lbrace>\\<lambda>_. <dest \\<mapsto>c cap'  \\<and>* src \\<mapsto>c NullCap \\<and>* R>\\<rbrace>\"\n  apply (simp add: move_cap_def)\n  apply (sep_wp set_cap_wp swap_parents_wp insert_cap_orphan_wp)+\n  apply (sep_solve)\n  done\n\nlemma swap_cap_wp2:\n  \"\\<lbrace><dest \\<mapsto>c cap \\<and>*  src \\<mapsto>c cap' \\<and>* R>\\<rbrace>\n    swap_cap cap' src cap dest\n   \\<lbrace>\\<lambda>_.<dest \\<mapsto>c cap' \\<and>* src \\<mapsto>c cap \\<and>* R>\\<rbrace>\"\n  apply (clarsimp simp: swap_cap_def)\n  apply (sep_wp swap_parents_wp set_cap_wp)+\n  apply (sep_solve)\n  done\n\nlemma invoke_cnode_rotate2_wp:\n  \"(dest) \\<noteq> (rnd) \\<Longrightarrow>\n  \\<lbrace><dest \\<mapsto>c cap1 \\<and>* src \\<mapsto>c cap2 \\<and>*\n    rnd \\<mapsto>c - \\<and>* R>\\<rbrace>\n     invoke_cnode (RotateCall cap1 cap2 dest src rnd)\n  \\<lbrace>\\<lambda>_. <dest \\<mapsto>c NullCap \\<and>* src \\<mapsto>c cap1 \\<and>*\n    rnd \\<mapsto>c cap2 \\<and>* R>\\<rbrace>\"\n  apply (clarsimp simp: invoke_cnode_def)\n  apply (sep_wp move_cap_wp)+\n  apply (sep_solve)\n  done\n\n\n(* sep_drule/rule *)\n\nlemma sep_rule_example2:\n \"\\<lbrakk>(ptr \\<mapsto>o obj) s; finite (dom (object_slots obj))\\<rbrakk> \\<Longrightarrow>\n   (ptr \\<mapsto>E obj \\<and>* ptr \\<mapsto>f obj \\<and>* (\\<And>* slot\\<in>dom (object_slots obj). (ptr, slot) \\<mapsto>s obj)) s\"\n  apply (subst (asm) sep_map_o_decomp)\n  apply (subst (asm) sep_map_S_decomp, simp+)\n  apply sep_solve\n  done\n\nlemma sep_drule_example2:\n \"\\<lbrakk>(ptr \\<mapsto>f obj \\<and>* (\\<And>* slot\\<in>dom (object_slots obj). (ptr, slot) \\<mapsto>s obj) \\<and>* ptr \\<mapsto>E obj) s;\n   finite (dom (object_slots obj))\\<rbrakk>\n    \\<Longrightarrow>\n  (ptr \\<mapsto>o obj) s\"\n  by (metis sep_map_S_decomp sep_map_o_decomp)\n\n(* sep_curry *)\n\nlemma sep_drule_example_lemma:\n  \"\\<lbrakk>(H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* ptr \\<mapsto>f obj \\<and>* A \\<and>* B \\<and>*\n    (\\<And>* slot\\<in>dom (object_slots obj). (ptr, slot) \\<mapsto>s obj) \\<and>* D \\<and>* G \\<and>* E \\<and>* F \\<and>* ptr \\<mapsto>E obj ) s;\n    finite (dom (object_slots obj))\\<rbrakk>\n  \\<Longrightarrow>\n   (D \\<and>* G \\<and>* E \\<and>* F  \\<and>* ptr \\<mapsto>o obj \\<and>* H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* A \\<and>* B) s\"\n  apply (sep_drule sep_drule_example2)\n   apply assumption\n  apply sep_solve\n  done\n\n\n(* sep_back *)\n\n\nlemma sep_rule_example_lemma:\n \"\\<lbrakk>(H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* ptr \\<mapsto>o obj \\<and>* A \\<and>* B \\<and>* D \\<and>* G \\<and>* E \\<and>* F ) s;\n  finite (dom (object_slots obj))\\<rbrakk> \\<Longrightarrow>\n  (D \\<and>* G \\<and>* E \\<and>* F  \\<and>* ptr \\<mapsto>f obj \\<and>* H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* ptr \\<mapsto>E obj \\<and>*\n   A \\<and>* B \\<and>* (\\<And>* slot\\<in>dom (object_slots obj). (ptr, slot) \\<mapsto>s obj)) s\"\n  apply (sep_rule sep_rule_example2)\n   apply sep_solve\n  apply assumption\n  done\n\n\n(* works even with multiple conjuncts in assumptions and conclusions *)\nlemma sep_rule_double_conjunct_example:\n  \"\\<lbrakk>((obj_id, slot) \\<mapsto>c cap \\<and>* obj_id \\<mapsto>f obj) s;\n    object_slots obj slot = Some cap\\<rbrakk>\n  \\<Longrightarrow> ((obj_id, slot) \\<mapsto>s obj \\<and>* obj_id \\<mapsto>f obj) s\"\n  apply (sep_drule sep_map_s_sep_map_c)\n   apply assumption\n  apply (sep_cancel)+\n  done\n\nlemma sep_rule_double_conjunct_lemma:\n  \"\\<lbrakk>(H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* obj_id \\<mapsto>f obj \\<and>* A \\<and>* B \\<and>* D \\<and>* G \\<and>* E \\<and>* F \\<and>* (obj_id, slot) \\<mapsto>c cap ) s;\n    object_slots obj slot = Some cap\\<rbrakk> \\<Longrightarrow>\n   (D \\<and>* G \\<and>* E \\<and>* F  \\<and>*(obj_id, slot) \\<mapsto>s obj \\<and>* H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* A \\<and>* B \\<and>*  obj_id \\<mapsto>f obj) s\"\n  apply (sep_rule sep_rule_double_conjunct_example)\n   apply sep_solve\n  apply assumption\n  done\n\n(* side-conditions*)\n\n\nlemma sep_drule_side_condition_lemma:\n \"\\<lbrakk>(H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* obj_id \\<mapsto>f obj \\<and>* A \\<and>* B \\<and>* D \\<and>* G \\<and>* E \\<and>* F \\<and>* (obj_id, slot) \\<mapsto>c cap ) s;\n    object_slots obj slot = Some cap\\<rbrakk> \\<Longrightarrow>\n   (D \\<and>* G \\<and>* E \\<and>* F  \\<and>*(obj_id, slot) \\<mapsto>s obj \\<and>* H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* A \\<and>* B \\<and>*  obj_id \\<mapsto>f obj) s\"\n  apply (sep_drule sep_rule_double_conjunct_example, assumption)\n  apply (sep_solve)\n  done\n\nschematic_goal \"(P \\<and>* ?A) s \\<Longrightarrow> (A \\<and>* B \\<and>* P) s\"\n  apply (sep_solve)\n  done\n\n\nend\n", "meta": {"author": "NICTA", "repo": "l4v", "sha": "3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b", "save_path": "github-repos/isabelle/NICTA-l4v", "path": "github-repos/isabelle/NICTA-l4v/l4v-3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b/proof/capDL-api/Sep_Tactic_Examples.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5660185351961015, "lm_q2_score": 0.5195213219520929, "lm_q1q2_score": 0.29405869765446585}}
{"text": "(* SPDX-License-Identifier: BSD-3-Clause *)\n(*\n * Copyright (C) 2002 Tobias Nipkow (TUM)\n * Copyright (C) 2013--2014 Japheth Lim (NICTA)\n * Copyright (C) 2013--2014 David Greenaway (NICTA)\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are\n * met:\n *\n * * Redistributions of source code must retain the above copyright\n * notice, this list of conditions and the following disclaimer.\n *\n * * Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in the\n * documentation and/or other materials provided with the distribution.\n *\n * * Neither the name of the University of Cambridge or the Technische\n * Universitaet Muenchen nor the names of their contributors may be used\n * to endorse or promote products derived from this software without\n * specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS\n * IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\n * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A\n * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n *)\n\ntheory CList imports\n  \"AutoCorres.AutoCorres\"\nbegin\n\nexternal_file \"list.c\"\ninstall_C_file \"list.c\"\nautocorres \"list.c\"\n\ncontext list begin\n\nthm reverse'_def\nthm revappend'_def\n\nsection \"The heap\"\n\nsubsection \"Paths in the heap\"\n\ndefinition node_next where \"node_next s p = next_C (heap_node_C s p)\"\ndefinition node_exists where \"node_exists s p = (p \\<noteq> NULL \\<and> is_valid_node_C s p)\"\n\ndefinition node_next_upd where\n  \"node_next_upd s p q = heap_node_C_update (\\<lambda>old. old(p := next_C_update (\\<lambda>_. q) (old p))) s\"\n\nlemma \"p \\<noteq> x \\<Longrightarrow> heap_node_C (node_next_upd s x q) p = heap_node_C s p\"\nby (simp add: node_next_def node_next_upd_def fun_upd_apply)\n\n\nprimrec Path :: \"lifted_globals \\<Rightarrow> node_C ptr \\<Rightarrow> node_C ptr list \\<Rightarrow> node_C ptr \\<Rightarrow> bool\" where\n  \"Path s x [] y \\<longleftrightarrow> x = y\"\n| \"Path s x (a#as) y \\<longleftrightarrow> node_exists s x \\<and> x = a \\<and> Path s (node_next s x) as y\"\n\n\n\nlemma [simp]: \"node_exists s a \\<Longrightarrow> Path s a as z =\n(as = [] \\<and> a = z   \\<or>   (\\<exists>bs. as = a # bs \\<and> Path s (node_next s a) bs z))\"\nby (case_tac as, fastforce, fastforce simp: node_exists_def)\n\nlemma [simp]: \"\\<And>x. Path s x (as@bs) z =\n(\\<exists>y. Path s x as y \\<and> Path s y bs z)\"\nby (induct as, simp+)\n\nlemma Path_upd[simp]:\n\"\\<And>x. u \\<notin> set as \\<Longrightarrow>\nPath (node_next_upd s u v) x as y = Path s x as y\"\napply (induct as, simp)\napply (simp add: node_exists_def node_next_def node_next_upd_def fun_upd_apply)\ndone\n\nlemma Path_snoc:\n\"\\<lbrakk> node_exists s a; Path (node_next_upd s a q) p as a \\<rbrakk> \\<Longrightarrow> Path (node_next_upd s a q) p (as @ [a]) q\"\nby simp\n\n\nsubsection \"Non-repeating paths\"\n\ndefinition distPath ::\n  \"lifted_globals \\<Rightarrow> node_C ptr \\<Rightarrow> node_C ptr list \\<Rightarrow> node_C ptr \\<Rightarrow> bool\"\n  where \"distPath s x as y \\<longleftrightarrow> Path s x as y \\<and> distinct as\"\n\ntext\\<open>The term @{term \"distPath s x as y\"} expresses the fact that a\nnon-repeating path @{term as} connects location @{term x} to location\n@{term y} over the heap @{term s}. In the case where @{text \"x = y\"},\nand there is a cycle from @{term x} to itself, @{term as} can\nbe both @{term \"[]\"} and the non-repeating list of nodes in the\ncycle.\\<close>\n\nlemma neq_dP: \"p \\<noteq> q \\<Longrightarrow> Path s p Ps q \\<Longrightarrow> distinct Ps \\<Longrightarrow>\n \\<exists> a Qs. p = a & Ps = a#Qs & a \\<notin> set Qs\"\nby (case_tac Ps, auto)\n\n\nlemma neq_dP_disp: \"\\<lbrakk> p \\<noteq> q; distPath s p Ps q \\<rbrakk> \\<Longrightarrow>\n \\<exists> a Qs. p = a \\<and> Ps = a#Qs \\<and> a \\<notin> set Qs\"\napply (simp only:distPath_def)\nby (case_tac Ps, auto)\n\n\nsubsection \"Lists on the heap\"\n\nsubsubsection \"Relational abstraction\"\n\ndefinition List :: \"lifted_globals \\<Rightarrow> node_C ptr \\<Rightarrow> node_C ptr list \\<Rightarrow> bool\"\n  where \"List s x as = Path s x as NULL\"\n\nlemma [simp]: \"List s x [] = (x = NULL)\"\nby(simp add:List_def)\n\nlemma List_case [simp]: \"List s x (a#as) = (x = a \\<and> node_exists s a \\<and> List s (node_next s a) as)\"\nby(auto simp:List_def)\n\nlemma [simp]: \"List s NULL as = (as = [])\"\nby(case_tac as, simp_all add: node_exists_def)\n\nlemma List_Ref[simp]: \"node_exists s a \\<Longrightarrow> List s a as = (\\<exists>bs. as = a#bs \\<and> List s (node_next s a) bs)\"\nby(case_tac as, simp_all add: node_exists_def, fast)\n\n\n\nlemma List_unique: \"\\<And>x bs. List s x as \\<Longrightarrow> List s x bs \\<Longrightarrow> as = bs\"\nby(induct as, simp, clarsimp)\n\nlemma List_unique1: \"List s p as \\<Longrightarrow> \\<exists>!as. List s p as\"\nby(blast intro:List_unique)\n\nlemma List_app: \"\\<And>x. List s x (as@bs) = (\\<exists>y. Path s x as y \\<and> List s y bs)\"\nby(induct as, simp, auto)\n\nlemma List_hd_not_in_tl[simp]: \"List s (node_next s a) as \\<Longrightarrow> a \\<notin> set as\"\napply(clarsimp simp add:in_set_conv_decomp)\napply(frule List_app[THEN iffD1])\napply(fastforce dest: List_unique)\ndone\n\nlemma List_distinct[simp]: \"\\<And>x. List s x as \\<Longrightarrow> distinct as\"\napply(induct as, simp)\napply(fastforce dest:List_hd_not_in_tl)\ndone\n\nlemma Path_is_List:\n  \"\\<lbrakk>node_exists s a; Path s b Ps a; a \\<notin> set Ps\\<rbrakk> \\<Longrightarrow> List (node_next_upd s a NULL) b (Ps @ [a])\"\napply (induct Ps arbitrary: b)\napply (auto simp: node_exists_def node_next_upd_def node_next_def fun_upd_apply)\ndone\n\n\n\nsubsection \"Functional abstraction\"\n\ndefinition islist :: \"lifted_globals \\<Rightarrow> node_C ptr \\<Rightarrow> bool\"\n  where \"islist s p \\<longleftrightarrow> (\\<exists>as. List s p as)\"\n\ndefinition list :: \"lifted_globals \\<Rightarrow> node_C ptr \\<Rightarrow> node_C ptr list\"\n  where \"list s p = (SOME as. List s p as)\"\n\nlemma List_conv_islist_list: \"List s p as = (islist s p \\<and> as = list s p)\"\napply(simp add:islist_def list_def)\napply(rule iffI)\napply(rule conjI)\napply blast\napply(subst some1_equality)\n  apply(erule List_unique1)\n apply assumption\napply(rule refl)\napply simp\napply(rule someI_ex)\napply fast\ndone\n\nlemma [simp]: \"islist s NULL\"\nby(simp add:islist_def)\n\nlemma [simp]: \"node_exists s a \\<Longrightarrow> islist s a = islist s (node_next s a)\"\nby(simp add:islist_def)\n\nlemma [simp]: \"\\<lbrakk> node_exists s a; islist s a \\<rbrakk> \\<Longrightarrow> islist s (node_next s a)\"\napply (clarsimp simp: islist_def)\ndone\n\nlemma [simp]: \"list s NULL = []\"\nby(simp add:list_def)\n\nlemma list_Ref_conv[simp]:\n \"\\<lbrakk> node_exists s a; islist s (node_next s a) \\<rbrakk> \\<Longrightarrow> list s a = a # list s (node_next s a)\"\napply(insert List_Ref[of s])\napply(metis List_conv_islist_list)\ndone\n\nlemma [simp]: \"\\<lbrakk> node_exists s a; islist s (node_next s a) \\<rbrakk> \\<Longrightarrow> a \\<notin> set(list s (node_next s a))\"\napply(insert List_hd_not_in_tl[of s])\napply(metis List_conv_islist_list)\ndone\n\nlemma list_upd_conv[simp]:\n \"islist s p \\<Longrightarrow> y \\<notin> set(list s p) \\<Longrightarrow> list (node_next_upd s y q) p = list s p\"\n  apply (clarsimp simp: islist_def node_next_upd_def)\n  by (metis (mono_tags) list.List_def list.List_unique list.Path_upd list.list_def list.node_next_upd_def some_eq_ex)\n\nlemma islist_upd[simp]:\n \"islist s p \\<Longrightarrow> y \\<notin> set(list s p) \\<Longrightarrow> islist (node_next_upd s y q) p\"\n  apply (clarsimp simp: islist_def node_next_upd_def)\n  by (metis (mono_tags) list.List_def list.List_unique list.Path_upd list.list_def list.node_next_upd_def some_eq_ex)\n\n\nsubsection \"List reversal\"\n\nsubsubsection \"Program representation\"\ntext \\<open>This is AutoCorres's representation of revappend.\\<close>\nthm revappend'_def\n\ntext \\<open>The heap operations are a bit too low level,\n        so let's lift them using our heap accessors.\\<close>\nschematic_goal revappend'_abstract: \"revappend' p q = ?new_definition\"\n  apply (subst revappend'_def)\n  unfolding node_next_def[symmetric]\n            node_next_upd_def[symmetric]\n            modify_def\n  apply (rule refl)\n  done\n\n\ntext \\<open>node_exists is a prerequisite for most of our abstraction rules.\n        But we cannot extract this prerequisite from the program text because it is\n        implied by our Hoare preconditions (below) which are not a part of the program\n        text. Here we arrange for Isabelle's tactics to infer it when needed.\\<close>\n\n(* FIXME: figure out why we need to take this out of the simpset for\n          the loop termination subgoals. *)\nlemma node_exists_imp_valid[simp]: \"node_exists s b \\<Longrightarrow> is_valid_node_C s b\"\n  by (simp add: node_exists_def)\n\nlemma List_node_exists [dest!]: \"\\<lbrakk> p \\<noteq> NULL; List s p as \\<rbrakk> \\<Longrightarrow> node_exists s p\"\nby (case_tac as, auto simp: node_exists_def)\n\nlemma islist_node_exists [simp]: \"\\<lbrakk> p \\<noteq> NULL; islist s p \\<rbrakk> \\<Longrightarrow> node_exists s p\"\n  apply (clarsimp simp: islist_def)\n  apply (rename_tac a, case_tac a, simp_all add: node_exists_def)\n  done\n\n\n\nsubsubsection \"Verification with relational abstraction\"\ntext \\<open>Almost automatic proof using the relational abstraction.\n        (The termination proof uses functional abstraction.)\\<close>\n\nlemma\n\"\\<lbrace> \\<lambda>s. List s p Ps \\<and> List s q Qs \\<and> set Ps \\<inter> set Qs = {} \\<rbrace>\n   revappend' p q\n \\<lbrace> \\<lambda>r s. List s r (rev Ps @ Qs) \\<rbrace>!\"\n  txt \\<open>We verify the abstracted version of the program.\\<close>\n  unfolding revappend'_abstract\n\n  txt \\<open>Add the loop invariant and measure.\\<close>\n  apply (subst whileLoop_add_inv\n    [where I = \"\\<lambda>(dest', list') s.\n                 \\<exists>ps qs. List s list' ps \\<and> List s dest' qs \\<and> set ps \\<inter> set qs = {} \\<and>\n                         rev ps @ qs = rev Ps @ Qs\"\n       and M = \" (\\<lambda>((_, list'), s). length (list s list'))\"])\n  apply (wp validNF_whileLoop_inv_measure_twosteps)\n\n  txt \\<open>Loop invariant.\\<close>\n    apply (fastforce intro: notin_List_update[THEN iffD2])\n\n  txt \\<open>Loop measure.\\<close>\n    apply wp\n    apply (fastforce simp: List_conv_islist_list simp del: node_exists_imp_valid)\n\n  txt \\<open>Loop entrance and exit.\\<close>\n   apply fastforce+\n  done\n\n\n\nsubsubsection \"Verification with functional abstraction\"\ntext \\<open>Fully automatic proof using the functional abstraction.\\<close>\nlemma\n\"\\<lbrace> \\<lambda>s. islist s p \\<and> islist s q \\<and> Ps = list s p \\<and> Qs = list s q \\<and> set Ps \\<inter> set Qs = {} \\<rbrace>\n   revappend' p q\n \\<lbrace> \\<lambda>r s. islist s r \\<and> list s r = rev Ps @ Qs \\<rbrace>!\"\n  unfolding revappend'_abstract\n\n  apply (subst whileLoop_add_inv\n    [where I = \"\\<lambda>(q, p) s. islist s p \\<and> islist s q \\<and>\n                           set(list s p) \\<inter> set(list s q) = {} \\<and>\n                           rev(list s p) @ (list s q) = rev Ps @ Qs\"\n       and M = \"(\\<lambda>((q, p), s). length (list s p))\"])\n  apply (wp validNF_whileLoop_inv_measure_twosteps)\n\n  txt \\<open>Loop invariant.\\<close>\n     apply clarsimp\n\n  txt \\<open>Loop measure.\\<close>\n    apply wp\n    apply (clarsimp simp del: node_exists_imp_valid)\n\n  txt \\<open>Loop entrance and exit.\\<close>\n   apply clarsimp+\n  done\n\ntext \\<open>Provide the node_exists condition manually.\\<close>\nlemma\n\"\\<lbrace> \\<lambda>s. islist s p \\<and> islist s q \\<and> Ps = list s p \\<and> Qs = list s q \\<and> set Ps \\<inter> set Qs = {} \\<rbrace>\n   revappend' p q\n \\<lbrace> \\<lambda>r s. islist s r \\<and> list s r = rev Ps @ Qs \\<rbrace>!\"\n  unfolding revappend'_abstract\n\n  apply (subst whileLoop_add_inv\n    [where I = \"\\<lambda>(q, p) s. islist s p \\<and> islist s q \\<and>\n                           set(list s p) \\<inter> set(list s q) = {} \\<and>\n                           rev(list s p) @ (list s q) = rev Ps @ Qs\"\n       and M = \"(\\<lambda>((q, p), s). length (list s p))\"])\n  apply (wp validNF_whileLoop_inv_measure_twosteps)\n     apply (clarsimp simp del: islist_node_exists)\n     apply (frule islist_node_exists, assumption)\n     apply (clarsimp simp del: islist_node_exists)\n\n    apply wp\n    apply (clarsimp simp del: node_exists_imp_valid)\n\n   apply clarsimp+\n  done\n\nend (* context list *)\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/autocorres/tests/examples/CList.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.519521307073646, "lm_q2_score": 0.5660185351961015, "lm_q1q2_score": 0.2940586892329891}}
{"text": "(*  Title:      HOL/Bali/AxSem.thy\n    Author:     David von Oheimb\n*)\n\nsubsection {* Axiomatic semantics of Java expressions and statements \n          (see also Eval.thy)\n        *}\ntheory AxSem imports Evaln TypeSafe begin\n\ntext {*\ndesign issues:\n\\begin{itemize}\n\\item a strong version of validity for triples with premises, namely one that \n      takes the recursive depth needed to complete execution, enables \n      correctness proof\n\\item auxiliary variables are handled first-class (-> Thomas Kleymann)\n\\item expressions not flattened to elementary assignments (as usual for \n      axiomatic semantics) but treated first-class => explicit result value \n      handling\n\\item intermediate values not on triple, but on assertion level \n      (with result entry)\n\\item multiple results with semantical substitution mechnism not requiring a \n      stack \n\\item because of dynamic method binding, terms need to be dependent on state.\n  this is also useful for conditional expressions and statements\n\\item result values in triples exactly as in eval relation (also for xcpt \n      states)\n\\item validity: additional assumption of state conformance and well-typedness,\n  which is required for soundness and thus rule hazard required of completeness\n\\end{itemize}\n\nrestrictions:\n\\begin{itemize}\n\\item all triples in a derivation are of the same type (due to weak \n      polymorphism)\n\\end{itemize}\n*}\n\ntype_synonym  res = vals --{* result entry *}\n\nabbreviation (input)\n  Val where \"Val x == In1 x\"\n\nabbreviation (input)\n  Var where \"Var x == In2 x\"\n\nabbreviation (input)\n  Vals where \"Vals x == In3 x\"\n\nsyntax\n  \"_Val\"    :: \"[pttrn] => pttrn\"     (\"Val:_\"  [951] 950)\n  \"_Var\"    :: \"[pttrn] => pttrn\"     (\"Var:_\"  [951] 950)\n  \"_Vals\"   :: \"[pttrn] => pttrn\"     (\"Vals:_\" [951] 950)\n\ntranslations\n  \"\\<lambda>Val:v . b\"  == \"(\\<lambda>v. b) \\<circ> CONST the_In1\"\n  \"\\<lambda>Var:v . b\"  == \"(\\<lambda>v. b) \\<circ> CONST the_In2\"\n  \"\\<lambda>Vals:v. b\"  == \"(\\<lambda>v. b) \\<circ> CONST the_In3\"\n\n  --{* relation on result values, state and auxiliary variables *}\ntype_synonym 'a assn = \"res \\<Rightarrow> state \\<Rightarrow> 'a \\<Rightarrow> bool\"\ntranslations\n  (type) \"'a assn\" <= (type) \"vals \\<Rightarrow> state \\<Rightarrow> 'a \\<Rightarrow> bool\"\n\ndefinition\n  assn_imp :: \"'a assn \\<Rightarrow> 'a assn \\<Rightarrow> bool\" (infixr \"\\<Rightarrow>\" 25)\n  where \"(P \\<Rightarrow> Q) = (\\<forall>Y s Z. P Y s Z \\<longrightarrow> Q Y s Z)\"\n  \nlemma assn_imp_def2 [iff]: \"(P \\<Rightarrow> Q) = (\\<forall>Y s Z. P Y s Z \\<longrightarrow> Q Y s Z)\"\napply (unfold assn_imp_def)\napply (rule HOL.refl)\ndone\n\n\nsubsubsection \"assertion transformers\"\n\nsubsection \"peek-and\"\n\ndefinition\n  peek_and :: \"'a assn \\<Rightarrow> (state \\<Rightarrow>  bool) \\<Rightarrow> 'a assn\" (infixl \"\\<and>.\" 13)\n  where \"(P \\<and>. p) = (\\<lambda>Y s Z. P Y s Z \\<and> p s)\"\n\nlemma peek_and_def2 [simp]: \"peek_and P p Y s = (\\<lambda>Z. (P Y s Z \\<and> p s))\"\napply (unfold peek_and_def)\napply (simp (no_asm))\ndone\n\nlemma peek_and_Not [simp]: \"(P \\<and>. (\\<lambda>s. \\<not> f s)) = (P \\<and>. Not \\<circ> f)\"\napply (rule ext)\napply (rule ext)\napply (simp (no_asm))\ndone\n\nlemma peek_and_and [simp]: \"peek_and (peek_and P p) p = peek_and P p\"\napply (unfold peek_and_def)\napply (simp (no_asm))\ndone\n\nlemma peek_and_commut: \"(P \\<and>. p \\<and>. q) = (P \\<and>. q \\<and>. p)\"\napply (rule ext)\napply (rule ext)\napply (rule ext)\napply auto\ndone\n\nabbreviation\n  Normal :: \"'a assn \\<Rightarrow> 'a assn\"\n  where \"Normal P == P \\<and>. normal\"\n\nlemma peek_and_Normal [simp]: \"peek_and (Normal P) p = Normal (peek_and P p)\"\napply (rule ext)\napply (rule ext)\napply (rule ext)\napply auto\ndone\n\nsubsection \"assn-supd\"\n\ndefinition\n  assn_supd :: \"'a assn \\<Rightarrow> (state \\<Rightarrow> state) \\<Rightarrow> 'a assn\" (infixl \";.\" 13)\n  where \"(P ;. f) = (\\<lambda>Y s' Z. \\<exists>s. P Y s Z \\<and> s' = f s)\"\n\nlemma assn_supd_def2 [simp]: \"assn_supd P f Y s' Z = (\\<exists>s. P Y s Z \\<and> s' = f s)\"\napply (unfold assn_supd_def)\napply (simp (no_asm))\ndone\n\nsubsection \"supd-assn\"\n\ndefinition\n  supd_assn :: \"(state \\<Rightarrow> state) \\<Rightarrow> 'a assn \\<Rightarrow> 'a assn\" (infixr \".;\" 13)\n  where \"(f .; P) = (\\<lambda>Y s. P Y (f s))\"\n\n\nlemma supd_assn_def2 [simp]: \"(f .; P) Y s = P Y (f s)\"\napply (unfold supd_assn_def)\napply (simp (no_asm))\ndone\n\nlemma supd_assn_supdD [elim]: \"((f .; Q) ;. f) Y s Z \\<Longrightarrow> Q Y s Z\"\napply auto\ndone\n\nlemma supd_assn_supdI [elim]: \"Q Y s Z \\<Longrightarrow> (f .; (Q ;. f)) Y s Z\"\napply (auto simp del: split_paired_Ex)\ndone\n\nsubsection \"subst-res\"\n\ndefinition\n  subst_res :: \"'a assn \\<Rightarrow> res \\<Rightarrow> 'a assn\" (\"_\\<leftarrow>_\"  [60,61] 60)\n  where \"P\\<leftarrow>w = (\\<lambda>Y. P w)\"\n\nlemma subst_res_def2 [simp]: \"(P\\<leftarrow>w) Y = P w\"\napply (unfold subst_res_def)\napply (simp (no_asm))\ndone\n\nlemma subst_subst_res [simp]: \"P\\<leftarrow>w\\<leftarrow>v = P\\<leftarrow>w\"\napply (rule ext)\napply (simp (no_asm))\ndone\n\nlemma peek_and_subst_res [simp]: \"(P \\<and>. p)\\<leftarrow>w = (P\\<leftarrow>w \\<and>. p)\"\napply (rule ext)\napply (rule ext)\napply (simp (no_asm))\ndone\n\n(*###Do not work for some strange (unification?) reason\nlemma subst_res_Val_beta [simp]: \"(\\<lambda>Y. P (the_In1 Y))\\<leftarrow>Val v = (\\<lambda>Y. P v)\"\napply (rule ext)\nby simp\n\nlemma subst_res_Var_beta [simp]: \"(\\<lambda>Y. P (the_In2 Y))\\<leftarrow>Var vf = (\\<lambda>Y. P vf)\";\napply (rule ext)\nby simp\n\nlemma subst_res_Vals_beta [simp]: \"(\\<lambda>Y. P (the_In3 Y))\\<leftarrow>Vals vs = (\\<lambda>Y. P vs)\";\napply (rule ext)\nby simp\n*)\n\nsubsection \"subst-Bool\"\n\ndefinition\n  subst_Bool :: \"'a assn \\<Rightarrow> bool \\<Rightarrow> 'a assn\" (\"_\\<leftarrow>=_\" [60,61] 60)\n  where \"P\\<leftarrow>=b = (\\<lambda>Y s Z. \\<exists>v. P (Val v) s Z \\<and> (normal s \\<longrightarrow> the_Bool v=b))\"\n\nlemma subst_Bool_def2 [simp]: \n\"(P\\<leftarrow>=b) Y s Z = (\\<exists>v. P (Val v) s Z \\<and> (normal s \\<longrightarrow> the_Bool v=b))\"\napply (unfold subst_Bool_def)\napply (simp (no_asm))\ndone\n\nlemma subst_Bool_the_BoolI: \"P (Val b) s Z \\<Longrightarrow> (P\\<leftarrow>=the_Bool b) Y s Z\"\napply auto\ndone\n\nsubsection \"peek-res\"\n\ndefinition\n  peek_res :: \"(res \\<Rightarrow> 'a assn) \\<Rightarrow> 'a assn\"\n  where \"peek_res Pf = (\\<lambda>Y. Pf Y Y)\"\n\nsyntax\n  \"_peek_res\" :: \"pttrn \\<Rightarrow> 'a assn \\<Rightarrow> 'a assn\"            (\"\\<lambda>_:. _\" [0,3] 3)\ntranslations\n  \"\\<lambda>w:. P\"   == \"CONST peek_res (\\<lambda>w. P)\"\n\nlemma peek_res_def2 [simp]: \"peek_res P Y = P Y Y\"\napply (unfold peek_res_def)\napply (simp (no_asm))\ndone\n\nlemma peek_res_subst_res [simp]: \"peek_res P\\<leftarrow>w = P w\\<leftarrow>w\"\napply (rule ext)\napply (simp (no_asm))\ndone\n\n(* unused *)\nlemma peek_subst_res_allI: \n \"(\\<And>a. T a (P (f a)\\<leftarrow>f a)) \\<Longrightarrow> \\<forall>a. T a (peek_res P\\<leftarrow>f a)\"\napply (rule allI)\napply (simp (no_asm))\napply fast\ndone\n\nsubsection \"ign-res\"\n\ndefinition\n  ign_res :: \"'a assn \\<Rightarrow> 'a assn\" (\"_\\<down>\" [1000] 1000)\n  where \"P\\<down> = (\\<lambda>Y s Z. \\<exists>Y. P Y s Z)\"\n\nlemma ign_res_def2 [simp]: \"P\\<down> Y s Z = (\\<exists>Y. P Y s Z)\"\napply (unfold ign_res_def)\napply (simp (no_asm))\ndone\n\nlemma ign_ign_res [simp]: \"P\\<down>\\<down> = P\\<down>\"\napply (rule ext)\napply (rule ext)\napply (rule ext)\napply (simp (no_asm))\ndone\n\nlemma ign_subst_res [simp]: \"P\\<down>\\<leftarrow>w = P\\<down>\"\napply (rule ext)\napply (rule ext)\napply (rule ext)\napply (simp (no_asm))\ndone\n\nlemma peek_and_ign_res [simp]: \"(P \\<and>. p)\\<down> = (P\\<down> \\<and>. p)\"\napply (rule ext)\napply (rule ext)\napply (rule ext)\napply (simp (no_asm))\ndone\n\nsubsection \"peek-st\"\n\ndefinition\n  peek_st :: \"(st \\<Rightarrow> 'a assn) \\<Rightarrow> 'a assn\"\n  where \"peek_st P = (\\<lambda>Y s. P (store s) Y s)\"\n\nsyntax\n  \"_peek_st\"   :: \"pttrn \\<Rightarrow> 'a assn \\<Rightarrow> 'a assn\"            (\"\\<lambda>_.. _\" [0,3] 3)\ntranslations\n  \"\\<lambda>s.. P\"   == \"CONST peek_st (\\<lambda>s. P)\"\n\nlemma peek_st_def2 [simp]: \"(\\<lambda>s.. Pf s) Y s = Pf (store s) Y s\"\napply (unfold peek_st_def)\napply (simp (no_asm))\ndone\n\nlemma peek_st_triv [simp]: \"(\\<lambda>s.. P) = P\"\napply (rule ext)\napply (rule ext)\napply (simp (no_asm))\ndone\n\nlemma peek_st_st [simp]: \"(\\<lambda>s.. \\<lambda>s'.. P s s') = (\\<lambda>s.. P s s)\"\napply (rule ext)\napply (rule ext)\napply (simp (no_asm))\ndone\n\nlemma peek_st_split [simp]: \"(\\<lambda>s.. \\<lambda>Y s'. P s Y s') = (\\<lambda>Y s. P (store s) Y s)\"\napply (rule ext)\napply (rule ext)\napply (simp (no_asm))\ndone\n\nlemma peek_st_subst_res [simp]: \"(\\<lambda>s.. P s)\\<leftarrow>w = (\\<lambda>s.. P s\\<leftarrow>w)\"\napply (rule ext)\napply (simp (no_asm))\ndone\n\nlemma peek_st_Normal [simp]: \"(\\<lambda>s..(Normal (P s))) = Normal (\\<lambda>s.. P s)\"\napply (rule ext)\napply (rule ext)\napply (simp (no_asm))\ndone\n\nsubsection \"ign-res-eq\"\n\ndefinition\n  ign_res_eq :: \"'a assn \\<Rightarrow> res \\<Rightarrow> 'a assn\" (\"_\\<down>=_\"  [60,61] 60)\n  where \"P\\<down>=w \\<equiv> (\\<lambda>Y:. P\\<down> \\<and>. (\\<lambda>s. Y=w))\"\n\nlemma ign_res_eq_def2 [simp]: \"(P\\<down>=w) Y s Z = ((\\<exists>Y. P Y s Z) \\<and> Y=w)\"\napply (unfold ign_res_eq_def)\napply auto\ndone\n\nlemma ign_ign_res_eq [simp]: \"(P\\<down>=w)\\<down> = P\\<down>\"\napply (rule ext)\napply (rule ext)\napply (rule ext)\napply (simp (no_asm))\ndone\n\n(* unused *)\nlemma ign_res_eq_subst_res: \"P\\<down>=w\\<leftarrow>w = P\\<down>\"\napply (rule ext)\napply (rule ext)\napply (rule ext)\napply (simp (no_asm))\ndone\n\n(* unused *)\nlemma subst_Bool_ign_res_eq: \"((P\\<leftarrow>=b)\\<down>=x) Y s Z = ((P\\<leftarrow>=b) Y s Z  \\<and> Y=x)\"\napply (simp (no_asm))\ndone\n\nsubsection \"RefVar\"\n\ndefinition\n  RefVar :: \"(state \\<Rightarrow> vvar \\<times> state) \\<Rightarrow> 'a assn \\<Rightarrow> 'a assn\" (infixr \"..;\" 13)\n  where \"(vf ..; P) = (\\<lambda>Y s. let (v,s') = vf s in P (Var v) s')\"\n \nlemma RefVar_def2 [simp]: \"(vf ..; P) Y s =  \n  P (Var (fst (vf s))) (snd (vf s))\"\napply (unfold RefVar_def Let_def)\napply (simp (no_asm) add: split_beta)\ndone\n\nsubsection \"allocation\"\n\ndefinition\n  Alloc :: \"prog \\<Rightarrow> obj_tag \\<Rightarrow> 'a assn \\<Rightarrow> 'a assn\"\n  where \"Alloc G otag P = (\\<lambda>Y s Z. \\<forall>s' a. G\\<turnstile>s \\<midarrow>halloc otag\\<succ>a\\<rightarrow> s'\\<longrightarrow> P (Val (Addr a)) s' Z)\"\n\ndefinition\n  SXAlloc :: \"prog \\<Rightarrow> 'a assn \\<Rightarrow> 'a assn\"\n  where \"SXAlloc G P = (\\<lambda>Y s Z. \\<forall>s'. G\\<turnstile>s \\<midarrow>sxalloc\\<rightarrow> s' \\<longrightarrow> P Y s' Z)\"\n\n\nlemma Alloc_def2 [simp]: \"Alloc G otag P Y s Z =  \n       (\\<forall>s' a. G\\<turnstile>s \\<midarrow>halloc otag\\<succ>a\\<rightarrow> s'\\<longrightarrow> P (Val (Addr a)) s' Z)\"\napply (unfold Alloc_def)\napply (simp (no_asm))\ndone\n\nlemma SXAlloc_def2 [simp]: \n  \"SXAlloc G P Y s Z = (\\<forall>s'. G\\<turnstile>s \\<midarrow>sxalloc\\<rightarrow> s' \\<longrightarrow> P Y s' Z)\"\napply (unfold SXAlloc_def)\napply (simp (no_asm))\ndone\n\nsubsubsection \"validity\"\n\ndefinition\n  type_ok :: \"prog \\<Rightarrow> term \\<Rightarrow> state \\<Rightarrow> bool\" where\n  \"type_ok G t s =\n    (\\<exists>L T C A. (normal s \\<longrightarrow> \\<lparr>prg=G,cls=C,lcl=L\\<rparr>\\<turnstile>t\\<Colon>T \\<and> \n                             \\<lparr>prg=G,cls=C,lcl=L\\<rparr>\\<turnstile>dom (locals (store s))\\<guillemotright>t\\<guillemotright>A )\n               \\<and> s\\<Colon>\\<preceq>(G,L))\"\n\ndatatype    'a triple = triple \"('a assn)\" \"term\" \"('a assn)\" (** should be\nsomething like triple = \\<forall>'a. triple ('a assn) term ('a assn)   **)\n                                        (\"{(1_)}/ _>/ {(1_)}\"      [3,65,3]75)\ntype_synonym 'a triples = \"'a triple set\"\n\nabbreviation\n  var_triple   :: \"['a assn, var         ,'a assn] \\<Rightarrow> 'a triple\"\n                                         (\"{(1_)}/ _=>/ {(1_)}\"    [3,80,3] 75)\n  where \"{P} e=> {Q} == {P} In2  e> {Q}\"\n\nabbreviation\n  expr_triple  :: \"['a assn, expr        ,'a assn] \\<Rightarrow> 'a triple\"\n                                         (\"{(1_)}/ _->/ {(1_)}\"    [3,80,3] 75)\n  where \"{P} e-> {Q} == {P} In1l e> {Q}\"\n\nabbreviation\n  exprs_triple :: \"['a assn, expr list   ,'a assn] \\<Rightarrow> 'a triple\"\n                                         (\"{(1_)}/ _#>/ {(1_)}\"    [3,65,3] 75)\n  where \"{P} e#> {Q} == {P} In3  e> {Q}\"\n\nabbreviation\n  stmt_triple  :: \"['a assn, stmt,        'a assn] \\<Rightarrow> 'a triple\"\n                                         (\"{(1_)}/ ._./ {(1_)}\"     [3,65,3] 75)\n  where \"{P} .c. {Q} == {P} In1r c> {Q}\"\n\nnotation (xsymbols)\n  triple  (\"{(1_)}/ _\\<succ>/ {(1_)}\"     [3,65,3] 75) and\n  var_triple  (\"{(1_)}/ _=\\<succ>/ {(1_)}\"    [3,80,3] 75) and\n  expr_triple  (\"{(1_)}/ _-\\<succ>/ {(1_)}\"    [3,80,3] 75) and\n  exprs_triple  (\"{(1_)}/ _\\<doteq>\\<succ>/ {(1_)}\"    [3,65,3] 75)\n\nlemma inj_triple: \"inj (\\<lambda>(P,t,Q). {P} t\\<succ> {Q})\"\napply (rule inj_onI)\napply auto\ndone\n\nlemma triple_inj_eq: \"({P} t\\<succ> {Q} = {P'} t'\\<succ> {Q'} ) = (P=P' \\<and> t=t' \\<and> Q=Q')\"\napply auto\ndone\n\ndefinition mtriples :: \"('c \\<Rightarrow> 'sig \\<Rightarrow> 'a assn) \\<Rightarrow> ('c \\<Rightarrow> 'sig \\<Rightarrow> expr) \\<Rightarrow> \n                ('c \\<Rightarrow> 'sig \\<Rightarrow> 'a assn) \\<Rightarrow> ('c \\<times>  'sig) set \\<Rightarrow> 'a triples\" (\"{{(1_)}/ _-\\<succ>/ {(1_)} | _}\"[3,65,3,65]75) where\n \"{{P} tf-\\<succ> {Q} | ms} = (\\<lambda>(C,sig). {Normal(P C sig)} tf C sig-\\<succ> {Q C sig})`ms\"\n  \ndefinition\n  triple_valid :: \"prog \\<Rightarrow> nat \\<Rightarrow> 'a triple  \\<Rightarrow> bool\"  (\"_\\<Turnstile>_:_\" [61,0, 58] 57)\n  where\n    \"G\\<Turnstile>n:t =\n      (case t of {P} t\\<succ> {Q} \\<Rightarrow>\n        \\<forall>Y s Z. P Y s Z \\<longrightarrow> type_ok G t s \\<longrightarrow>\n        (\\<forall>Y' s'. G\\<turnstile>s \\<midarrow>t\\<succ>\\<midarrow>n\\<rightarrow> (Y',s') \\<longrightarrow> Q Y' s' Z))\"\n\nabbreviation\n  triples_valid:: \"prog \\<Rightarrow> nat \\<Rightarrow> 'a triples \\<Rightarrow> bool\"  (  \"_||=_:_\" [61,0, 58] 57)\n  where \"G||=n:ts == Ball ts (triple_valid G n)\"\n\nnotation (xsymbols)\n  triples_valid  (\"_|\\<Turnstile>_:_\" [61,0, 58] 57)\n\n\ndefinition\n  ax_valids :: \"prog \\<Rightarrow> 'b triples \\<Rightarrow> 'a triples \\<Rightarrow> bool\"  (\"_,_|\\<Turnstile>_\" [61,58,58] 57)\n  where \"(G,A|\\<Turnstile>ts) = (\\<forall>n. G|\\<Turnstile>n:A \\<longrightarrow> G|\\<Turnstile>n:ts)\"\n\nabbreviation\n  ax_valid :: \"prog \\<Rightarrow> 'b triples \\<Rightarrow> 'a triple \\<Rightarrow> bool\"  ( \"_,_|=_\"   [61,58,58] 57)\n  where \"G,A |=t == G,A|\\<Turnstile>{t}\"\n\nnotation (xsymbols)\n  ax_valid  (\"_,_\\<Turnstile>_\" [61,58,58] 57)\n\n\nlemma triple_valid_def2: \"G\\<Turnstile>n:{P} t\\<succ> {Q} =  \n (\\<forall>Y s Z. P Y s Z \n  \\<longrightarrow> (\\<exists>L. (normal s \\<longrightarrow> (\\<exists> C T A. \\<lparr>prg=G,cls=C,lcl=L\\<rparr>\\<turnstile>t\\<Colon>T \\<and> \n                   \\<lparr>prg=G,cls=C,lcl=L\\<rparr>\\<turnstile>dom (locals (store s))\\<guillemotright>t\\<guillemotright>A)) \\<and> \n           s\\<Colon>\\<preceq>(G,L))\n  \\<longrightarrow> (\\<forall>Y' s'. G\\<turnstile>s \\<midarrow>t\\<succ>\\<midarrow>n\\<rightarrow> (Y',s')\\<longrightarrow> Q Y' s' Z))\"\napply (unfold triple_valid_def type_ok_def)\napply (simp (no_asm))\ndone\n\n\ndeclare split_paired_All [simp del] split_paired_Ex [simp del] \ndeclare split_if     [split del] split_if_asm     [split del] \n        option.split [split del] option.split_asm [split del]\nsetup {* map_theory_simpset (fn ctxt => ctxt delloop \"split_all_tac\") *}\nsetup {* map_theory_claset (fn ctxt => ctxt delSWrapper \"split_all_tac\") *}\n\ninductive\n  ax_derivs :: \"prog \\<Rightarrow> 'a triples \\<Rightarrow> 'a triples \\<Rightarrow> bool\" (\"_,_|\\<turnstile>_\" [61,58,58] 57)\n  and ax_deriv :: \"prog \\<Rightarrow> 'a triples \\<Rightarrow> 'a triple  \\<Rightarrow> bool\" (\"_,_\\<turnstile>_\" [61,58,58] 57)\n  for G :: prog\nwhere\n\n  \"G,A \\<turnstile>t \\<equiv> G,A|\\<turnstile>{t}\"\n\n| empty: \" G,A|\\<turnstile>{}\"\n| insert:\"\\<lbrakk>G,A\\<turnstile>t; G,A|\\<turnstile>ts\\<rbrakk> \\<Longrightarrow>\n          G,A|\\<turnstile>insert t ts\"\n\n| asm:   \"ts\\<subseteq>A \\<Longrightarrow> G,A|\\<turnstile>ts\"\n\n(* could be added for convenience and efficiency, but is not necessary\n  cut:   \"\\<lbrakk>G,A'|\\<turnstile>ts; G,A|\\<turnstile>A'\\<rbrakk> \\<Longrightarrow>\n           G,A |\\<turnstile>ts\"\n*)\n| weaken:\"\\<lbrakk>G,A|\\<turnstile>ts'; ts \\<subseteq> ts'\\<rbrakk> \\<Longrightarrow> G,A|\\<turnstile>ts\"\n\n| conseq:\"\\<forall>Y s Z . P  Y s Z  \\<longrightarrow> (\\<exists>P' Q'. G,A\\<turnstile>{P'} t\\<succ> {Q'} \\<and> (\\<forall>Y' s'. \n         (\\<forall>Y   Z'. P' Y s Z' \\<longrightarrow> Q' Y' s' Z') \\<longrightarrow>\n                                 Q  Y' s' Z ))\n                                         \\<Longrightarrow> G,A\\<turnstile>{P } t\\<succ> {Q }\"\n\n| hazard:\"G,A\\<turnstile>{P \\<and>. Not \\<circ> type_ok G t} t\\<succ> {Q}\"\n\n| Abrupt:  \"G,A\\<turnstile>{P\\<leftarrow>(undefined3 t) \\<and>. Not \\<circ> normal} t\\<succ> {P}\"\n\n  --{* variables *}\n| LVar:  \" G,A\\<turnstile>{Normal (\\<lambda>s.. P\\<leftarrow>Var (lvar vn s))} LVar vn=\\<succ> {P}\"\n\n| FVar: \"\\<lbrakk>G,A\\<turnstile>{Normal P} .Init C. {Q};\n          G,A\\<turnstile>{Q} e-\\<succ> {\\<lambda>Val:a:. fvar C stat fn a ..; R}\\<rbrakk> \\<Longrightarrow>\n                                 G,A\\<turnstile>{Normal P} {accC,C,stat}e..fn=\\<succ> {R}\"\n\n| AVar:  \"\\<lbrakk>G,A\\<turnstile>{Normal P} e1-\\<succ> {Q};\n          \\<forall>a. G,A\\<turnstile>{Q\\<leftarrow>Val a} e2-\\<succ> {\\<lambda>Val:i:. avar G i a ..; R}\\<rbrakk> \\<Longrightarrow>\n                                 G,A\\<turnstile>{Normal P} e1.[e2]=\\<succ> {R}\"\n  --{* expressions *}\n\n| NewC: \"\\<lbrakk>G,A\\<turnstile>{Normal P} .Init C. {Alloc G (CInst C) Q}\\<rbrakk> \\<Longrightarrow>\n                                 G,A\\<turnstile>{Normal P} NewC C-\\<succ> {Q}\"\n\n| NewA: \"\\<lbrakk>G,A\\<turnstile>{Normal P} .init_comp_ty T. {Q};  G,A\\<turnstile>{Q} e-\\<succ>\n          {\\<lambda>Val:i:. abupd (check_neg i) .; Alloc G (Arr T (the_Intg i)) R}\\<rbrakk> \\<Longrightarrow>\n                                 G,A\\<turnstile>{Normal P} New T[e]-\\<succ> {R}\"\n\n| Cast: \"\\<lbrakk>G,A\\<turnstile>{Normal P} e-\\<succ> {\\<lambda>Val:v:. \\<lambda>s..\n          abupd (raise_if (\\<not>G,s\\<turnstile>v fits T) ClassCast) .; Q\\<leftarrow>Val v}\\<rbrakk> \\<Longrightarrow>\n                                 G,A\\<turnstile>{Normal P} Cast T e-\\<succ> {Q}\"\n\n| Inst: \"\\<lbrakk>G,A\\<turnstile>{Normal P} e-\\<succ> {\\<lambda>Val:v:. \\<lambda>s..\n                  Q\\<leftarrow>Val (Bool (v\\<noteq>Null \\<and> G,s\\<turnstile>v fits RefT T))}\\<rbrakk> \\<Longrightarrow>\n                                 G,A\\<turnstile>{Normal P} e InstOf T-\\<succ> {Q}\"\n\n| Lit:                          \"G,A\\<turnstile>{Normal (P\\<leftarrow>Val v)} Lit v-\\<succ> {P}\"\n\n| UnOp: \"\\<lbrakk>G,A\\<turnstile>{Normal P} e-\\<succ> {\\<lambda>Val:v:. Q\\<leftarrow>Val (eval_unop unop v)}\\<rbrakk>\n          \\<Longrightarrow>\n          G,A\\<turnstile>{Normal P} UnOp unop e-\\<succ> {Q}\"\n\n| BinOp:\n   \"\\<lbrakk>G,A\\<turnstile>{Normal P} e1-\\<succ> {Q};\n     \\<forall>v1. G,A\\<turnstile>{Q\\<leftarrow>Val v1} \n               (if need_second_arg binop v1 then (In1l e2) else (In1r Skip))\\<succ>\n               {\\<lambda>Val:v2:. R\\<leftarrow>Val (eval_binop binop v1 v2)}\\<rbrakk>\n    \\<Longrightarrow>\n    G,A\\<turnstile>{Normal P} BinOp binop e1 e2-\\<succ> {R}\" \n\n| Super:\" G,A\\<turnstile>{Normal (\\<lambda>s.. P\\<leftarrow>Val (val_this s))} Super-\\<succ> {P}\"\n\n| Acc:  \"\\<lbrakk>G,A\\<turnstile>{Normal P} va=\\<succ> {\\<lambda>Var:(v,f):. Q\\<leftarrow>Val v}\\<rbrakk> \\<Longrightarrow>\n                                 G,A\\<turnstile>{Normal P} Acc va-\\<succ> {Q}\"\n\n| Ass:  \"\\<lbrakk>G,A\\<turnstile>{Normal P} va=\\<succ> {Q};\n     \\<forall>vf. G,A\\<turnstile>{Q\\<leftarrow>Var vf} e-\\<succ> {\\<lambda>Val:v:. assign (snd vf) v .; R}\\<rbrakk> \\<Longrightarrow>\n                                 G,A\\<turnstile>{Normal P} va:=e-\\<succ> {R}\"\n\n| Cond: \"\\<lbrakk>G,A \\<turnstile>{Normal P} e0-\\<succ> {P'};\n          \\<forall>b. G,A\\<turnstile>{P'\\<leftarrow>=b} (if b then e1 else e2)-\\<succ> {Q}\\<rbrakk> \\<Longrightarrow>\n                                 G,A\\<turnstile>{Normal P} e0 ? e1 : e2-\\<succ> {Q}\"\n\n| Call: \n\"\\<lbrakk>G,A\\<turnstile>{Normal P} e-\\<succ> {Q}; \\<forall>a. G,A\\<turnstile>{Q\\<leftarrow>Val a} args\\<doteq>\\<succ> {R a};\n  \\<forall>a vs invC declC l. G,A\\<turnstile>{(R a\\<leftarrow>Vals vs \\<and>.\n (\\<lambda>s. declC=invocation_declclass G mode (store s) a statT \\<lparr>name=mn,parTs=pTs\\<rparr> \\<and>\n      invC = invocation_class mode (store s) a statT \\<and>\n         l = locals (store s)) ;.\n      init_lvars G declC \\<lparr>name=mn,parTs=pTs\\<rparr> mode a vs) \\<and>.\n      (\\<lambda>s. normal s \\<longrightarrow> G\\<turnstile>mode\\<rightarrow>invC\\<preceq>statT)}\n Methd declC \\<lparr>name=mn,parTs=pTs\\<rparr>-\\<succ> {set_lvars l .; S}\\<rbrakk> \\<Longrightarrow>\n         G,A\\<turnstile>{Normal P} {accC,statT,mode}e\\<cdot>mn({pTs}args)-\\<succ> {S}\"\n\n| Methd:\"\\<lbrakk>G,A\\<union> {{P} Methd-\\<succ> {Q} | ms} |\\<turnstile> {{P} body G-\\<succ> {Q} | ms}\\<rbrakk> \\<Longrightarrow>\n                                 G,A|\\<turnstile>{{P} Methd-\\<succ>  {Q} | ms}\"\n\n| Body: \"\\<lbrakk>G,A\\<turnstile>{Normal P} .Init D. {Q}; \n  G,A\\<turnstile>{Q} .c. {\\<lambda>s.. abupd (absorb Ret) .; R\\<leftarrow>(In1 (the (locals s Result)))}\\<rbrakk> \n    \\<Longrightarrow>\n                                 G,A\\<turnstile>{Normal P} Body D c-\\<succ> {R}\"\n  \n  --{* expression lists *}\n\n| Nil:                          \"G,A\\<turnstile>{Normal (P\\<leftarrow>Vals [])} []\\<doteq>\\<succ> {P}\"\n\n| Cons: \"\\<lbrakk>G,A\\<turnstile>{Normal P} e-\\<succ> {Q};\n          \\<forall>v. G,A\\<turnstile>{Q\\<leftarrow>Val v} es\\<doteq>\\<succ> {\\<lambda>Vals:vs:. R\\<leftarrow>Vals (v#vs)}\\<rbrakk> \\<Longrightarrow>\n                                 G,A\\<turnstile>{Normal P} e#es\\<doteq>\\<succ> {R}\"\n\n  --{* statements *}\n\n| Skip:                         \"G,A\\<turnstile>{Normal (P\\<leftarrow>\\<diamondsuit>)} .Skip. {P}\"\n\n| Expr: \"\\<lbrakk>G,A\\<turnstile>{Normal P} e-\\<succ> {Q\\<leftarrow>\\<diamondsuit>}\\<rbrakk> \\<Longrightarrow>\n                                 G,A\\<turnstile>{Normal P} .Expr e. {Q}\"\n\n| Lab: \"\\<lbrakk>G,A\\<turnstile>{Normal P} .c. {abupd (absorb l) .; Q}\\<rbrakk> \\<Longrightarrow>\n                           G,A\\<turnstile>{Normal P} .l\\<bullet> c. {Q}\"\n\n| Comp: \"\\<lbrakk>G,A\\<turnstile>{Normal P} .c1. {Q};\n          G,A\\<turnstile>{Q} .c2. {R}\\<rbrakk> \\<Longrightarrow>\n                                 G,A\\<turnstile>{Normal P} .c1;;c2. {R}\"\n\n| If:   \"\\<lbrakk>G,A \\<turnstile>{Normal P} e-\\<succ> {P'};\n          \\<forall>b. G,A\\<turnstile>{P'\\<leftarrow>=b} .(if b then c1 else c2). {Q}\\<rbrakk> \\<Longrightarrow>\n                                 G,A\\<turnstile>{Normal P} .If(e) c1 Else c2. {Q}\"\n(* unfolding variant of Loop, not needed here\n  LoopU:\"\\<lbrakk>G,A \\<turnstile>{Normal P} e-\\<succ> {P'};\n          \\<forall>b. G,A\\<turnstile>{P'\\<leftarrow>=b} .(if b then c;;While(e) c else Skip).{Q}\\<rbrakk>\n         \\<Longrightarrow>              G,A\\<turnstile>{Normal P} .While(e) c. {Q}\"\n*)\n| Loop: \"\\<lbrakk>G,A\\<turnstile>{P} e-\\<succ> {P'}; \n          G,A\\<turnstile>{Normal (P'\\<leftarrow>=True)} .c. {abupd (absorb (Cont l)) .; P}\\<rbrakk> \\<Longrightarrow>\n                            G,A\\<turnstile>{P} .l\\<bullet> While(e) c. {(P'\\<leftarrow>=False)\\<down>=\\<diamondsuit>}\"\n  \n| Jmp: \"G,A\\<turnstile>{Normal (abupd (\\<lambda>a. (Some (Jump j))) .; P\\<leftarrow>\\<diamondsuit>)} .Jmp j. {P}\"\n\n| Throw:\"\\<lbrakk>G,A\\<turnstile>{Normal P} e-\\<succ> {\\<lambda>Val:a:. abupd (throw a) .; Q\\<leftarrow>\\<diamondsuit>}\\<rbrakk> \\<Longrightarrow>\n                                 G,A\\<turnstile>{Normal P} .Throw e. {Q}\"\n\n| Try:  \"\\<lbrakk>G,A\\<turnstile>{Normal P} .c1. {SXAlloc G Q};\n          G,A\\<turnstile>{Q \\<and>. (\\<lambda>s.  G,s\\<turnstile>catch C) ;. new_xcpt_var vn} .c2. {R};\n              (Q \\<and>. (\\<lambda>s. \\<not>G,s\\<turnstile>catch C)) \\<Rightarrow> R\\<rbrakk> \\<Longrightarrow>\n                                 G,A\\<turnstile>{Normal P} .Try c1 Catch(C vn) c2. {R}\"\n\n| Fin:  \"\\<lbrakk>G,A\\<turnstile>{Normal P} .c1. {Q};\n      \\<forall>x. G,A\\<turnstile>{Q \\<and>. (\\<lambda>s. x = fst s) ;. abupd (\\<lambda>x. None)}\n              .c2. {abupd (abrupt_if (x\\<noteq>None) x) .; R}\\<rbrakk> \\<Longrightarrow>\n                                 G,A\\<turnstile>{Normal P} .c1 Finally c2. {R}\"\n\n| Done:                       \"G,A\\<turnstile>{Normal (P\\<leftarrow>\\<diamondsuit> \\<and>. initd C)} .Init C. {P}\"\n\n| Init: \"\\<lbrakk>the (class G C) = c;\n          G,A\\<turnstile>{Normal ((P \\<and>. Not \\<circ> initd C) ;. supd (init_class_obj G C))}\n              .(if C = Object then Skip else Init (super c)). {Q};\n      \\<forall>l. G,A\\<turnstile>{Q \\<and>. (\\<lambda>s. l = locals (store s)) ;. set_lvars empty}\n              .init c. {set_lvars l .; R}\\<rbrakk> \\<Longrightarrow>\n                               G,A\\<turnstile>{Normal (P \\<and>. Not \\<circ> initd C)} .Init C. {R}\"\n\n-- {* Some dummy rules for the intermediate terms @{text Callee},\n@{text InsInitE}, @{text InsInitV}, @{text FinA} only used by the smallstep \nsemantics.\n*}\n| InsInitV: \" G,A\\<turnstile>{Normal P} InsInitV c v=\\<succ> {Q}\"\n| InsInitE: \" G,A\\<turnstile>{Normal P} InsInitE c e-\\<succ> {Q}\"\n| Callee:    \" G,A\\<turnstile>{Normal P} Callee l e-\\<succ> {Q}\"\n| FinA:      \" G,A\\<turnstile>{Normal P} .FinA a c. {Q}\"\n(*\naxioms \n*)\n\ndefinition\n  adapt_pre :: \"'a assn \\<Rightarrow> 'a assn \\<Rightarrow> 'a assn \\<Rightarrow> 'a assn\"\n  where \"adapt_pre P Q Q' = (\\<lambda>Y s Z. \\<forall>Y' s'. \\<exists>Z'. P Y s Z' \\<and> (Q Y' s' Z' \\<longrightarrow> Q' Y' s' Z))\"\n\n\nsubsubsection \"rules derived by induction\"\n\nlemma cut_valid: \"\\<lbrakk>G,A'|\\<Turnstile>ts; G,A|\\<Turnstile>A'\\<rbrakk> \\<Longrightarrow> G,A|\\<Turnstile>ts\"\napply (unfold ax_valids_def)\napply fast\ndone\n\n(*if cut is available\nGoal \"\\<lbrakk>G,A'|\\<turnstile>ts; A' \\<subseteq> A; \\<forall>P Q t. {P} t\\<succ> {Q} \\<in> A' \\<longrightarrow> (\\<exists>T. (G,L)\\<turnstile>t\\<Colon>T) \\<rbrakk> \\<Longrightarrow>  \n       G,A|\\<turnstile>ts\"\nb y etac ax_derivs.cut 1;\nb y eatac ax_derivs.asm 1 1;\nqed \"ax_thin\";\n*)\nlemma ax_thin [rule_format (no_asm)]: \n  \"G,(A'::'a triple set)|\\<turnstile>(ts::'a triple set) \\<Longrightarrow> \\<forall>A. A' \\<subseteq> A \\<longrightarrow> G,A|\\<turnstile>ts\"\napply (erule ax_derivs.induct)\napply                (tactic \"ALLGOALS (EVERY'[clarify_tac @{context}, REPEAT o smp_tac @{context} 1])\")\napply                (rule ax_derivs.empty)\napply               (erule (1) ax_derivs.insert)\napply              (fast intro: ax_derivs.asm)\n(*apply           (fast intro: ax_derivs.cut) *)\napply            (fast intro: ax_derivs.weaken)\napply           (rule ax_derivs.conseq, intro strip, tactic \"smp_tac @{context} 3 1\",clarify,\n  tactic \"smp_tac @{context} 1 1\",rule exI, rule exI, erule (1) conjI) \n(* 37 subgoals *)\nprefer 18 (* Methd *)\napply (rule ax_derivs.Methd, drule spec, erule mp, fast) \napply (tactic {* TRYALL (resolve_tac ((funpow 5 tl) @{thms ax_derivs.intros})) *})\napply auto\ndone\n\nlemma ax_thin_insert: \"G,(A::'a triple set)\\<turnstile>(t::'a triple) \\<Longrightarrow> G,insert x A\\<turnstile>t\"\napply (erule ax_thin)\napply fast\ndone\n\nlemma subset_mtriples_iff: \n  \"ts \\<subseteq> {{P} mb-\\<succ> {Q} | ms} = (\\<exists>ms'. ms'\\<subseteq>ms \\<and>  ts = {{P} mb-\\<succ> {Q} | ms'})\"\napply (unfold mtriples_def)\napply (rule subset_image_iff)\ndone\n\nlemma weaken: \n \"G,(A::'a triple set)|\\<turnstile>(ts'::'a triple set) \\<Longrightarrow> !ts. ts \\<subseteq> ts' \\<longrightarrow> G,A|\\<turnstile>ts\"\napply (erule ax_derivs.induct)\n(*42 subgoals*)\napply       (tactic \"ALLGOALS strip_tac\")\napply       (tactic {* ALLGOALS(REPEAT o (EVERY'[dtac @{thm subset_singletonD},\n         etac disjE, fast_tac (@{context} addSIs @{thms ax_derivs.empty})]))*})\napply       (tactic \"TRYALL (hyp_subst_tac @{context})\")\napply       (simp, rule ax_derivs.empty)\napply      (drule subset_insertD)\napply      (blast intro: ax_derivs.insert)\napply     (fast intro: ax_derivs.asm)\n(*apply  (blast intro: ax_derivs.cut) *)\napply   (fast intro: ax_derivs.weaken)\napply  (rule ax_derivs.conseq, clarify, tactic \"smp_tac @{context} 3 1\", blast(* unused *))\n(*37 subgoals*)\napply (tactic {* TRYALL (resolve_tac ((funpow 5 tl) @{thms ax_derivs.intros}) \n                   THEN_ALL_NEW fast_tac @{context}) *})\n(*1 subgoal*)\napply (clarsimp simp add: subset_mtriples_iff)\napply (rule ax_derivs.Methd)\napply (drule spec)\napply (erule impE)\napply  (rule exI)\napply  (erule conjI)\napply  (rule HOL.refl)\noops (* dead end, Methd is to blame *)\n\n\nsubsubsection \"rules derived from conseq\"\n\ntext {* In the following rules we often have to give some type annotations like:\n @{term \"G,(A::'a triple set)\\<turnstile>{P::'a assn} t\\<succ> {Q}\"}.\nGiven only the term above without annotations, Isabelle would infer a more \ngeneral type were we could have \ndifferent types of auxiliary variables in the assumption set (@{term A}) and \nin the triple itself (@{term P} and @{term Q}). But \n@{text \"ax_derivs.Methd\"} enforces the same type in the inductive definition of\nthe derivation. So we have to restrict the types to be able to apply the\nrules. \n*}\nlemma conseq12: \"\\<lbrakk>G,(A::'a triple set)\\<turnstile>{P'::'a assn} t\\<succ> {Q'};  \n \\<forall>Y s Z. P Y s Z \\<longrightarrow> (\\<forall>Y' s'. (\\<forall>Y Z'. P' Y s Z' \\<longrightarrow> Q' Y' s' Z') \\<longrightarrow>  \n  Q Y' s' Z)\\<rbrakk>  \n  \\<Longrightarrow>  G,A\\<turnstile>{P ::'a assn} t\\<succ> {Q }\"\napply (rule ax_derivs.conseq)\napply clarsimp\napply blast\ndone\n\n-- {* Nice variant, since it is so symmetric we might be able to memorise it. *}\nlemma conseq12': \"\\<lbrakk>G,(A::'a triple set)\\<turnstile>{P'::'a assn} t\\<succ> {Q'}; \\<forall>s Y' s'.  \n       (\\<forall>Y Z. P' Y s Z \\<longrightarrow> Q' Y' s' Z) \\<longrightarrow>  \n       (\\<forall>Y Z. P  Y s Z \\<longrightarrow> Q  Y' s' Z)\\<rbrakk>  \n  \\<Longrightarrow>  G,A\\<turnstile>{P::'a assn } t\\<succ> {Q }\"\napply (erule conseq12)\napply fast\ndone\n\nlemma conseq12_from_conseq12': \"\\<lbrakk>G,(A::'a triple set)\\<turnstile>{P'::'a assn} t\\<succ> {Q'};  \n \\<forall>Y s Z. P Y s Z \\<longrightarrow> (\\<forall>Y' s'. (\\<forall>Y Z'. P' Y s Z' \\<longrightarrow> Q' Y' s' Z') \\<longrightarrow>  \n  Q Y' s' Z)\\<rbrakk>  \n  \\<Longrightarrow>  G,A\\<turnstile>{P::'a assn} t\\<succ> {Q }\"\napply (erule conseq12')\napply blast\ndone\n\nlemma conseq1: \"\\<lbrakk>G,(A::'a triple set)\\<turnstile>{P'::'a assn} t\\<succ> {Q}; P \\<Rightarrow> P'\\<rbrakk> \n \\<Longrightarrow> G,A\\<turnstile>{P::'a assn} t\\<succ> {Q}\"\napply (erule conseq12)\napply blast\ndone\n\nlemma conseq2: \"\\<lbrakk>G,(A::'a triple set)\\<turnstile>{P::'a assn} t\\<succ> {Q'}; Q' \\<Rightarrow> Q\\<rbrakk> \n\\<Longrightarrow> G,A\\<turnstile>{P::'a assn} t\\<succ> {Q}\"\napply (erule conseq12)\napply blast\ndone\n\nlemma ax_escape: \n \"\\<lbrakk>\\<forall>Y s Z. P Y s Z \n   \\<longrightarrow> G,(A::'a triple set)\\<turnstile>{\\<lambda>Y' s' (Z'::'a). (Y',s') = (Y,s)} \n                             t\\<succ> \n                            {\\<lambda>Y s Z'. Q Y s Z}\n\\<rbrakk> \\<Longrightarrow>  G,A\\<turnstile>{P::'a assn} t\\<succ> {Q::'a assn}\"\napply (rule ax_derivs.conseq)\napply force\ndone\n\n(* unused *)\nlemma ax_constant: \"\\<lbrakk> C \\<Longrightarrow> G,(A::'a triple set)\\<turnstile>{P::'a assn} t\\<succ> {Q}\\<rbrakk> \n\\<Longrightarrow> G,A\\<turnstile>{\\<lambda>Y s Z. C \\<and> P Y s Z} t\\<succ> {Q}\"\napply (rule ax_escape (* unused *))\napply clarify\napply (rule conseq12)\napply  fast\napply auto\ndone\n(*alternative (more direct) proof:\napply (rule ax_derivs.conseq) *)(* unused *)(*\napply (fast)\n*)\n\n\nlemma ax_impossible [intro]: \n  \"G,(A::'a triple set)\\<turnstile>{\\<lambda>Y s Z. False} t\\<succ> {Q::'a assn}\"\napply (rule ax_escape)\napply clarify\ndone\n\n(* unused *)\nlemma ax_nochange_lemma: \"\\<lbrakk>P Y s; All (op = w)\\<rbrakk> \\<Longrightarrow> P w s\"\napply auto\ndone\n\nlemma ax_nochange:\n \"G,(A::(res \\<times> state) triple set)\\<turnstile>{\\<lambda>Y s Z. (Y,s)=Z} t\\<succ> {\\<lambda>Y s Z. (Y,s)=Z} \n  \\<Longrightarrow> G,A\\<turnstile>{P::(res \\<times> state) assn} t\\<succ> {P}\"\napply (erule conseq12)\napply auto\napply (erule (1) ax_nochange_lemma)\ndone\n\n(* unused *)\nlemma ax_trivial: \"G,(A::'a triple set)\\<turnstile>{P::'a assn}  t\\<succ> {\\<lambda>Y s Z. True}\"\napply (rule ax_derivs.conseq(* unused *))\napply auto\ndone\n\n(* unused *)\nlemma ax_disj: \n \"\\<lbrakk>G,(A::'a triple set)\\<turnstile>{P1::'a assn} t\\<succ> {Q1}; G,A\\<turnstile>{P2::'a assn} t\\<succ> {Q2}\\<rbrakk> \n  \\<Longrightarrow>  G,A\\<turnstile>{\\<lambda>Y s Z. P1 Y s Z \\<or> P2 Y s Z} t\\<succ> {\\<lambda>Y s Z. Q1 Y s Z \\<or> Q2 Y s Z}\"\napply (rule ax_escape (* unused *))\napply safe\napply  (erule conseq12, fast)+\ndone\n\n(* unused *)\nlemma ax_supd_shuffle: \n \"(\\<exists>Q. G,(A::'a triple set)\\<turnstile>{P::'a assn} .c1. {Q} \\<and> G,A\\<turnstile>{Q ;. f} .c2. {R}) =  \n       (\\<exists>Q'. G,A\\<turnstile>{P} .c1. {f .; Q'} \\<and> G,A\\<turnstile>{Q'} .c2. {R})\"\napply (best elim!: conseq1 conseq2)\ndone\n\nlemma ax_cases: \"\n \\<lbrakk>G,(A::'a triple set)\\<turnstile>{P \\<and>.       C} t\\<succ> {Q::'a assn};  \n                   G,A\\<turnstile>{P \\<and>. Not \\<circ> C} t\\<succ> {Q}\\<rbrakk> \\<Longrightarrow> G,A\\<turnstile>{P} t\\<succ> {Q}\"\napply (unfold peek_and_def)\napply (rule ax_escape)\napply clarify\napply (case_tac \"C s\")\napply  (erule conseq12, force)+\ndone\n(*alternative (more direct) proof:\napply (rule rtac ax_derivs.conseq) *)(* unused *)(*\napply clarify\napply (case_tac \"C s\")\napply  force+\n*)\n\nlemma ax_adapt: \"G,(A::'a triple set)\\<turnstile>{P::'a assn} t\\<succ> {Q} \n  \\<Longrightarrow> G,A\\<turnstile>{adapt_pre P Q Q'} t\\<succ> {Q'}\"\napply (unfold adapt_pre_def)\napply (erule conseq12)\napply fast\ndone\n\nlemma adapt_pre_adapts: \"G,(A::'a triple set)\\<Turnstile>{P::'a assn} t\\<succ> {Q} \n\\<longrightarrow> G,A\\<Turnstile>{adapt_pre P Q Q'} t\\<succ> {Q'}\"\napply (unfold adapt_pre_def)\napply (simp add: ax_valids_def triple_valid_def2)\napply fast\ndone\n\n\nlemma adapt_pre_weakest: \n\"\\<forall>G (A::'a triple set) t. G,A\\<Turnstile>{P} t\\<succ> {Q} \\<longrightarrow> G,A\\<Turnstile>{P'} t\\<succ> {Q'} \\<Longrightarrow>  \n  P' \\<Rightarrow> adapt_pre P Q (Q'::'a assn)\"\napply (unfold adapt_pre_def)\napply (drule spec)\napply (drule_tac x = \"{}\" in spec)\napply (drule_tac x = \"In1r Skip\" in spec)\napply (simp add: ax_valids_def triple_valid_def2)\noops\n\nlemma peek_and_forget1_Normal: \n \"G,(A::'a triple set)\\<turnstile>{Normal P} t\\<succ> {Q::'a assn} \n \\<Longrightarrow> G,A\\<turnstile>{Normal (P \\<and>. p)} t\\<succ> {Q}\"\napply (erule conseq1)\napply (simp (no_asm))\ndone\n\nlemma peek_and_forget1: \n\"G,(A::'a triple set)\\<turnstile>{P::'a assn} t\\<succ> {Q} \n \\<Longrightarrow> G,A\\<turnstile>{P \\<and>. p} t\\<succ> {Q}\"\napply (erule conseq1)\napply (simp (no_asm))\ndone\n\nlemmas ax_NormalD = peek_and_forget1 [of _ _ _ _ _ normal] \n\nlemma peek_and_forget2: \n\"G,(A::'a triple set)\\<turnstile>{P::'a assn} t\\<succ> {Q \\<and>. p} \n\\<Longrightarrow> G,A\\<turnstile>{P} t\\<succ> {Q}\"\napply (erule conseq2)\napply (simp (no_asm))\ndone\n\nlemma ax_subst_Val_allI: \n\"\\<forall>v. G,(A::'a triple set)\\<turnstile>{(P'               v )\\<leftarrow>Val v} t\\<succ> {(Q v)::'a assn}\n \\<Longrightarrow>  \\<forall>v. G,A\\<turnstile>{(\\<lambda>w:. P' (the_In1 w))\\<leftarrow>Val v} t\\<succ> {Q v}\"\napply (force elim!: conseq1)\ndone\n\nlemma ax_subst_Var_allI: \n\"\\<forall>v. G,(A::'a triple set)\\<turnstile>{(P'               v )\\<leftarrow>Var v} t\\<succ> {(Q v)::'a assn}\n \\<Longrightarrow>  \\<forall>v. G,A\\<turnstile>{(\\<lambda>w:. P' (the_In2 w))\\<leftarrow>Var v} t\\<succ> {Q v}\"\napply (force elim!: conseq1)\ndone\n\nlemma ax_subst_Vals_allI: \n\"(\\<forall>v. G,(A::'a triple set)\\<turnstile>{(     P'          v )\\<leftarrow>Vals v} t\\<succ> {(Q v)::'a assn})\n \\<Longrightarrow>  \\<forall>v. G,A\\<turnstile>{(\\<lambda>w:. P' (the_In3 w))\\<leftarrow>Vals v} t\\<succ> {Q v}\"\napply (force elim!: conseq1)\ndone\n\n\nsubsubsection \"alternative axioms\"\n\nlemma ax_Lit2: \n  \"G,(A::'a triple set)\\<turnstile>{Normal P::'a assn} Lit v-\\<succ> {Normal (P\\<down>=Val v)}\"\napply (rule ax_derivs.Lit [THEN conseq1])\napply force\ndone\nlemma ax_Lit2_test_complete: \n  \"G,(A::'a triple set)\\<turnstile>{Normal (P\\<leftarrow>Val v)::'a assn} Lit v-\\<succ> {P}\"\napply (rule ax_Lit2 [THEN conseq2])\napply force\ndone\n\nlemma ax_LVar2: \"G,(A::'a triple set)\\<turnstile>{Normal P::'a assn} LVar vn=\\<succ> {Normal (\\<lambda>s.. P\\<down>=Var (lvar vn s))}\"\napply (rule ax_derivs.LVar [THEN conseq1])\napply force\ndone\n\nlemma ax_Super2: \"G,(A::'a triple set)\\<turnstile>\n  {Normal P::'a assn} Super-\\<succ> {Normal (\\<lambda>s.. P\\<down>=Val (val_this s))}\"\napply (rule ax_derivs.Super [THEN conseq1])\napply force\ndone\n\nlemma ax_Nil2: \n  \"G,(A::'a triple set)\\<turnstile>{Normal P::'a assn} []\\<doteq>\\<succ> {Normal (P\\<down>=Vals [])}\"\napply (rule ax_derivs.Nil [THEN conseq1])\napply force\ndone\n\n\nsubsubsection \"misc derived structural rules\"\n\n(* unused *)\nlemma ax_finite_mtriples_lemma: \"\\<lbrakk>F \\<subseteq> ms; finite ms; \\<forall>(C,sig)\\<in>ms. \n    G,(A::'a triple set)\\<turnstile>{Normal (P C sig)::'a assn} mb C sig-\\<succ> {Q C sig}\\<rbrakk> \\<Longrightarrow> \n       G,A|\\<turnstile>{{P} mb-\\<succ> {Q} | F}\"\napply (frule (1) finite_subset)\napply (erule rev_mp)\napply (erule thin_rl)\napply (erule finite_induct)\napply  (unfold mtriples_def)\napply  (clarsimp intro!: ax_derivs.empty ax_derivs.insert)+\napply force\ndone\nlemmas ax_finite_mtriples = ax_finite_mtriples_lemma [OF subset_refl]\n\nlemma ax_derivs_insertD: \n \"G,(A::'a triple set)|\\<turnstile>insert (t::'a triple) ts \\<Longrightarrow> G,A\\<turnstile>t \\<and> G,A|\\<turnstile>ts\"\napply (fast intro: ax_derivs.weaken)\ndone\n\nlemma ax_methods_spec: \n\"\\<lbrakk>G,(A::'a triple set)|\\<turnstile>split f ` ms; (C,sig) \\<in> ms\\<rbrakk>\\<Longrightarrow> G,A\\<turnstile>((f C sig)::'a triple)\"\napply (erule ax_derivs.weaken)\napply (force del: image_eqI intro: rev_image_eqI)\ndone\n\n(* this version is used to avoid using the cut rule *)\nlemma ax_finite_pointwise_lemma [rule_format]: \"\\<lbrakk>F \\<subseteq> ms; finite ms\\<rbrakk> \\<Longrightarrow>  \n  ((\\<forall>(C,sig)\\<in>F. G,(A::'a triple set)\\<turnstile>(f C sig::'a triple)) \\<longrightarrow> (\\<forall>(C,sig)\\<in>ms. G,A\\<turnstile>(g C sig::'a triple))) \\<longrightarrow>  \n      G,A|\\<turnstile>split f ` F \\<longrightarrow> G,A|\\<turnstile>split g ` F\"\napply (frule (1) finite_subset)\napply (erule rev_mp)\napply (erule thin_rl)\napply (erule finite_induct)\napply  clarsimp+\napply (drule ax_derivs_insertD)\napply (rule ax_derivs.insert)\napply  (simp (no_asm_simp) only: split_tupled_all)\napply  (auto elim: ax_methods_spec)\ndone\nlemmas ax_finite_pointwise = ax_finite_pointwise_lemma [OF subset_refl]\n \nlemma ax_no_hazard: \n  \"G,(A::'a triple set)\\<turnstile>{P \\<and>. type_ok G t} t\\<succ> {Q::'a assn} \\<Longrightarrow> G,A\\<turnstile>{P} t\\<succ> {Q}\"\napply (erule ax_cases)\napply (rule ax_derivs.hazard [THEN conseq1])\napply force\ndone\n\nlemma ax_free_wt: \n \"(\\<exists>T L C. \\<lparr>prg=G,cls=C,lcl=L\\<rparr>\\<turnstile>t\\<Colon>T) \n  \\<longrightarrow> G,(A::'a triple set)\\<turnstile>{Normal P} t\\<succ> {Q::'a assn} \\<Longrightarrow> \n  G,A\\<turnstile>{Normal P} t\\<succ> {Q}\"\napply (rule ax_no_hazard)\napply (rule ax_escape)\napply clarify\napply (erule mp [THEN conseq12])\napply  (auto simp add: type_ok_def)\ndone\n\nML {* ML_Thms.bind_thms (\"ax_Abrupts\", sum3_instantiate @{context} @{thm ax_derivs.Abrupt}) *}\ndeclare ax_Abrupts [intro!]\n\nlemmas ax_Normal_cases = ax_cases [of _ _ _ normal]\n\nlemma ax_Skip [intro!]: \"G,(A::'a triple set)\\<turnstile>{P\\<leftarrow>\\<diamondsuit>} .Skip. {P::'a assn}\"\napply (rule ax_Normal_cases)\napply  (rule ax_derivs.Skip)\napply fast\ndone\nlemmas ax_SkipI = ax_Skip [THEN conseq1]\n\n\nsubsubsection \"derived rules for methd call\"\n\nlemma ax_Call_known_DynT: \n\"\\<lbrakk>G\\<turnstile>IntVir\\<rightarrow>C\\<preceq>statT; \n  \\<forall>a vs l. G,A\\<turnstile>{(R a\\<leftarrow>Vals vs \\<and>. (\\<lambda>s. l = locals (store s)) ;.\n  init_lvars G C \\<lparr>name=mn,parTs=pTs\\<rparr> IntVir a vs)} \n    Methd C \\<lparr>name=mn,parTs=pTs\\<rparr>-\\<succ> {set_lvars l .; S}; \n  \\<forall>a. G,A\\<turnstile>{Q\\<leftarrow>Val a} args\\<doteq>\\<succ>  \n       {R a \\<and>. (\\<lambda>s. C = obj_class (the (heap (store s) (the_Addr a))) \\<and>\n                     C = invocation_declclass \n                            G IntVir (store s) a statT \\<lparr>name=mn,parTs=pTs\\<rparr> )};  \n       G,(A::'a triple set)\\<turnstile>{Normal P} e-\\<succ> {Q::'a assn}\\<rbrakk>  \n   \\<Longrightarrow> G,A\\<turnstile>{Normal P} {accC,statT,IntVir}e\\<cdot>mn({pTs}args)-\\<succ> {S}\"\napply (erule ax_derivs.Call)\napply  safe\napply  (erule spec)\napply (rule ax_escape, clarsimp)\napply (drule spec, drule spec, drule spec,erule conseq12)\napply force\ndone\n\n\nlemma ax_Call_Static: \n \"\\<lbrakk>\\<forall>a vs l. G,A\\<turnstile>{R a\\<leftarrow>Vals vs \\<and>. (\\<lambda>s. l = locals (store s)) ;.  \n               init_lvars G C \\<lparr>name=mn,parTs=pTs\\<rparr> Static any_Addr vs}  \n              Methd C \\<lparr>name=mn,parTs=pTs\\<rparr>-\\<succ> {set_lvars l .; S}; \n  G,A\\<turnstile>{Normal P} e-\\<succ> {Q};\n  \\<forall> a. G,(A::'a triple set)\\<turnstile>{Q\\<leftarrow>Val a} args\\<doteq>\\<succ> {(R::val \\<Rightarrow> 'a assn)  a \n  \\<and>. (\\<lambda> s. C=invocation_declclass \n                G Static (store s) a statT \\<lparr>name=mn,parTs=pTs\\<rparr>)}\n\\<rbrakk>  \\<Longrightarrow>  G,A\\<turnstile>{Normal P} {accC,statT,Static}e\\<cdot>mn({pTs}args)-\\<succ> {S}\"\napply (erule ax_derivs.Call)\napply  safe\napply  (erule spec)\napply (rule ax_escape, clarsimp)\napply (erule_tac V = \"?P \\<longrightarrow> ?Q\" in thin_rl)\napply (drule spec,drule spec,drule spec, erule conseq12)\napply (force simp add: init_lvars_def Let_def)\ndone\n\nlemma ax_Methd1: \n \"\\<lbrakk>G,A\\<union>{{P} Methd-\\<succ> {Q} | ms}|\\<turnstile> {{P} body G-\\<succ> {Q} | ms}; (C,sig)\\<in> ms\\<rbrakk> \\<Longrightarrow> \n       G,A\\<turnstile>{Normal (P C sig)} Methd C sig-\\<succ> {Q C sig}\"\napply (drule ax_derivs.Methd)\napply (unfold mtriples_def)\napply (erule (1) ax_methods_spec)\ndone\n\nlemma ax_MethdN: \n\"G,insert({Normal P} Methd  C sig-\\<succ> {Q}) A\\<turnstile> \n          {Normal P} body G C sig-\\<succ> {Q} \\<Longrightarrow>  \n      G,A\\<turnstile>{Normal P} Methd   C sig-\\<succ> {Q}\"\napply (rule ax_Methd1)\napply  (rule_tac [2] singletonI)\napply (unfold mtriples_def)\napply clarsimp\ndone\n\nlemma ax_StatRef: \n  \"G,(A::'a triple set)\\<turnstile>{Normal (P\\<leftarrow>Val Null)} StatRef rt-\\<succ> {P::'a assn}\"\napply (rule ax_derivs.Cast)\napply (rule ax_Lit2 [THEN conseq2])\napply clarsimp\ndone\n\nsubsubsection \"rules derived from Init and Done\"\n\n  lemma ax_InitS: \"\\<lbrakk>the (class G C) = c; C \\<noteq> Object;  \n     \\<forall>l. G,A\\<turnstile>{Q \\<and>. (\\<lambda>s. l = locals (store s)) ;. set_lvars empty}  \n            .init c. {set_lvars l .; R};   \n         G,A\\<turnstile>{Normal ((P \\<and>. Not \\<circ> initd C) ;. supd (init_class_obj G C))}  \n  .Init (super c). {Q}\\<rbrakk> \\<Longrightarrow>  \n  G,(A::'a triple set)\\<turnstile>{Normal (P \\<and>. Not \\<circ> initd C)} .Init C. {R::'a assn}\"\napply (erule ax_derivs.Init)\napply  (simp (no_asm_simp))\napply assumption\ndone\n\nlemma ax_Init_Skip_lemma: \n\"\\<forall>l. G,(A::'a triple set)\\<turnstile>{P\\<leftarrow>\\<diamondsuit> \\<and>. (\\<lambda>s. l = locals (store s)) ;. set_lvars l'}\n  .Skip. {(set_lvars l .; P)::'a assn}\"\napply (rule allI)\napply (rule ax_SkipI)\napply clarsimp\ndone\n\nlemma ax_triv_InitS: \"\\<lbrakk>the (class G C) = c;init c = Skip; C \\<noteq> Object; \n       P\\<leftarrow>\\<diamondsuit> \\<Rightarrow> (supd (init_class_obj G C) .; P);  \n       G,A\\<turnstile>{Normal (P \\<and>. initd C)} .Init (super c). {(P \\<and>. initd C)\\<leftarrow>\\<diamondsuit>}\\<rbrakk> \\<Longrightarrow>  \n       G,(A::'a triple set)\\<turnstile>{Normal P\\<leftarrow>\\<diamondsuit>} .Init C. {(P \\<and>. initd C)::'a assn}\"\napply (rule_tac C = \"initd C\" in ax_cases)\napply  (rule conseq1, rule ax_derivs.Done, clarsimp)\napply (simp (no_asm))\napply (erule (1) ax_InitS)\napply  simp\napply  (rule ax_Init_Skip_lemma)\napply (erule conseq1)\napply force\ndone\n\nlemma ax_Init_Object: \"wf_prog G \\<Longrightarrow> G,(A::'a triple set)\\<turnstile>\n  {Normal ((supd (init_class_obj G Object) .; P\\<leftarrow>\\<diamondsuit>) \\<and>. Not \\<circ> initd Object)} \n       .Init Object. {(P \\<and>. initd Object)::'a assn}\"\napply (rule ax_derivs.Init)\napply   (drule class_Object, force)\napply (simp_all (no_asm))\napply (rule_tac [2] ax_Init_Skip_lemma)\napply (rule ax_SkipI, force)\ndone\n\nlemma ax_triv_Init_Object: \"\\<lbrakk>wf_prog G;  \n       (P::'a assn) \\<Rightarrow> (supd (init_class_obj G Object) .; P)\\<rbrakk> \\<Longrightarrow>  \n  G,(A::'a triple set)\\<turnstile>{Normal P\\<leftarrow>\\<diamondsuit>} .Init Object. {P \\<and>. initd Object}\"\napply (rule_tac C = \"initd Object\" in ax_cases)\napply  (rule conseq1, rule ax_derivs.Done, clarsimp)\napply (erule ax_Init_Object [THEN conseq1])\napply force\ndone\n\n\nsubsubsection \"introduction rules for Alloc and SXAlloc\"\n\nlemma ax_SXAlloc_Normal: \n \"G,(A::'a triple set)\\<turnstile>{P::'a assn} .c. {Normal Q} \n \\<Longrightarrow> G,A\\<turnstile>{P} .c. {SXAlloc G Q}\"\napply (erule conseq2)\napply (clarsimp elim!: sxalloc_elim_cases simp add: split_tupled_all)\ndone\n\nlemma ax_Alloc: \n  \"G,(A::'a triple set)\\<turnstile>{P::'a assn} t\\<succ> \n     {Normal (\\<lambda>Y (x,s) Z. (\\<forall>a. new_Addr (heap s) = Some a \\<longrightarrow>  \n      Q (Val (Addr a)) (Norm(init_obj G (CInst C) (Heap a) s)) Z)) \\<and>. \n      heap_free (Suc (Suc 0))}\n   \\<Longrightarrow> G,A\\<turnstile>{P} t\\<succ> {Alloc G (CInst C) Q}\"\napply (erule conseq2)\napply (auto elim!: halloc_elim_cases)\ndone\n\nlemma ax_Alloc_Arr: \n \"G,(A::'a triple set)\\<turnstile>{P::'a assn} t\\<succ> \n   {\\<lambda>Val:i:. Normal (\\<lambda>Y (x,s) Z. \\<not>the_Intg i<0 \\<and>  \n    (\\<forall>a. new_Addr (heap s) = Some a \\<longrightarrow>  \n    Q (Val (Addr a)) (Norm (init_obj G (Arr T (the_Intg i)) (Heap a) s)) Z)) \\<and>.\n    heap_free (Suc (Suc 0))} \n \\<Longrightarrow>  \n G,A\\<turnstile>{P} t\\<succ> {\\<lambda>Val:i:. abupd (check_neg i) .; Alloc G (Arr T(the_Intg i)) Q}\"\napply (erule conseq2)\napply (auto elim!: halloc_elim_cases)\ndone\n\nlemma ax_SXAlloc_catch_SXcpt: \n \"\\<lbrakk>G,(A::'a triple set)\\<turnstile>{P::'a assn} t\\<succ> \n     {(\\<lambda>Y (x,s) Z. x=Some (Xcpt (Std xn)) \\<and>  \n      (\\<forall>a. new_Addr (heap s) = Some a \\<longrightarrow>  \n      Q Y (Some (Xcpt (Loc a)),init_obj G (CInst (SXcpt xn)) (Heap a) s) Z))  \n      \\<and>. heap_free (Suc (Suc 0))}\\<rbrakk> \n \\<Longrightarrow>  \n G,A\\<turnstile>{P} t\\<succ> {SXAlloc G (\\<lambda>Y s Z. Q Y s Z \\<and> G,s\\<turnstile>catch SXcpt xn)}\"\napply (erule conseq2)\napply (auto elim!: sxalloc_elim_cases halloc_elim_cases)\ndone\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/Bali/AxSem.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926666143433998, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.29401825030918183}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory WhileLoopVarsPreserved imports\n  \"../../AutoCorres\"\nbegin\n\ninstall_C_file \"while_loop_vars_preserved.c\"\n\nautocorres [ts_force nondet = loop] \"while_loop_vars_preserved.c\"\n\ncontext while_loop_vars_preserved begin\n\nlemma \"\\<lbrace> \\<lambda>s. True \\<rbrace> loop' var1 var2 var3 var4  \\<lbrace> \\<lambda>r s. r = var1 + var2 + var3 + var4 \\<rbrace>\"\n  apply (unfold loop'_def)\n  apply (subst whileLoop_add_inv [where I=\"\\<lambda>(meow, woof, neigh, ii, squeek) s.\n              ii = (var1 + var2 + var3 + var4 - (meow + woof + neigh + squeek))\"\n       and M=\"\\<lambda>((meow, woof, neigh, ii, squeek), s).\n                   unat meow + unat woof + unat neigh + unat squeek\"])\n  apply wp\n  apply (auto simp: word_gt_0)\n  done\n\nend\n\nend\n", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/autocorres/tests/proof-tests/WhileLoopVarsPreserved.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926665999540698, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.29401824317072395}}
{"text": "header {* \\isaheader{Static Weak Control Dependence} *}\n\ntheory WeakControlDependence imports \n  \"../Basic/Postdomination\" \n  \"../Basic/DynWeakControlDependence\"\nbegin\n\ncontext StrongPostdomination begin\n\ndefinition \n  weak_control_dependence :: \"'node \\<Rightarrow> 'node \\<Rightarrow> bool\" \n  (\"_ weakly controls _\" [51,0])\nwhere weak_control_dependences_eq:\n    \"n weakly controls n' \\<equiv> \\<exists>as. n weakly controls n' via as\"\n\nlemma \n  weak_control_dependence_def:\"n weakly controls n' = \n    (\\<exists>a a' as. (n' \\<notin> set(sourcenodes (a#as))) \\<and> (n -a#as\\<rightarrow>* n') \\<and>\n                   (n' strongly-postdominates (targetnode a)) \\<and>\n                   (valid_edge a') \\<and> (sourcenode a' = n) \\<and> \n                   (\\<not> n' strongly-postdominates (targetnode a')))\"\nby(auto simp:weak_control_dependences_eq dyn_weak_control_dependence_def)\n\n\nlemma Exit_not_weak_control_dependent:\n  \"n weakly controls (_Exit_) \\<Longrightarrow> False\"\nby(auto simp:weak_control_dependences_eq \n        intro:Exit_not_dyn_weak_control_dependent)\n\nend\n\nend", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Slicing/StaticIntra/WeakControlDependence.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6654105454764747, "lm_q2_score": 0.44167300566462553, "lm_q1q2_score": 0.2938938756215326}}
{"text": "(*  Title:      HOL/HOLCF/IOA/TLS.thy\n    Author:     Olaf Müller\n*)\n\nsection \\<open>Temporal Logic of Steps -- tailored for I/O automata\\<close>\n\ntheory TLS\nimports IOA TL\nbegin\n\ndefault_sort type\n\ntype_synonym ('a, 's) ioa_temp  = \"('a option, 's) transition temporal\"\n\ntype_synonym ('a, 's) step_pred = \"('a option, 's) transition predicate\"\n\ntype_synonym 's state_pred = \"'s predicate\"\n\ndefinition mkfin :: \"'a Seq \\<Rightarrow> 'a Seq\"\n  where \"mkfin s = (if Partial s then SOME t. Finite t \\<and> s = t @@ UU else s)\"\n\ndefinition option_lift :: \"('a \\<Rightarrow> 'b) \\<Rightarrow> 'b \\<Rightarrow> 'a option \\<Rightarrow> 'b\"\n  where \"option_lift f s y = (case y of None \\<Rightarrow> s | Some x \\<Rightarrow> f x)\"\n\ndefinition plift :: \"('a \\<Rightarrow> bool) \\<Rightarrow> 'a option \\<Rightarrow> bool\"\n(* plift is used to determine that None action is always false in\n   transition predicates *)\n  where \"plift P = option_lift P False\"\n\ndefinition xt1 :: \"'s predicate \\<Rightarrow> ('a, 's) step_pred\"\n  where \"xt1 P tr = P (fst tr)\"\n\ndefinition xt2 :: \"'a option predicate \\<Rightarrow> ('a, 's) step_pred\"\n  where \"xt2 P tr = P (fst (snd tr))\"\n\ndefinition ex2seqC :: \"('a, 's) pairs \\<rightarrow> ('s \\<Rightarrow> ('a option, 's) transition Seq)\"\n  where \"ex2seqC =\n    (fix \\<cdot> (LAM h ex. (\\<lambda>s. case ex of\n      nil \\<Rightarrow> (s, None, s) \\<leadsto> nil\n    | x ## xs \\<Rightarrow> (flift1 (\\<lambda>pr. (s, Some (fst pr), snd pr) \\<leadsto> (h \\<cdot> xs) (snd pr)) \\<cdot> x))))\"\n\ndefinition ex2seq :: \"('a, 's) execution \\<Rightarrow> ('a option, 's) transition Seq\"\n  where \"ex2seq ex = (ex2seqC \\<cdot> (mkfin (snd ex))) (fst ex)\"\n\ndefinition temp_sat :: \"('a, 's) execution \\<Rightarrow> ('a, 's) ioa_temp \\<Rightarrow> bool\"  (infixr \"\\<TTurnstile>\" 22)\n  where \"(ex \\<TTurnstile> P) \\<longleftrightarrow> ((ex2seq ex) \\<Turnstile> P)\"\n\ndefinition validTE :: \"('a, 's) ioa_temp \\<Rightarrow> bool\"\n  where \"validTE P \\<longleftrightarrow> (\\<forall>ex. (ex \\<TTurnstile> P))\"\n\ndefinition validIOA :: \"('a, 's) ioa \\<Rightarrow> ('a, 's) ioa_temp \\<Rightarrow> bool\"\n  where \"validIOA A P \\<longleftrightarrow> (\\<forall>ex \\<in> executions A. (ex \\<TTurnstile> P))\"\n\n\nlemma IMPLIES_temp_sat [simp]: \"(ex \\<TTurnstile> P \\<^bold>\\<longrightarrow> Q) \\<longleftrightarrow> ((ex \\<TTurnstile> P) \\<longrightarrow> (ex \\<TTurnstile> Q))\"\n  by (simp add: IMPLIES_def temp_sat_def satisfies_def)\n\nlemma AND_temp_sat [simp]: \"(ex \\<TTurnstile> P \\<^bold>\\<and> Q) \\<longleftrightarrow> ((ex \\<TTurnstile> P) \\<and> (ex \\<TTurnstile> Q))\"\n  by (simp add: AND_def temp_sat_def satisfies_def)\n\nlemma OR_temp_sat [simp]: \"(ex \\<TTurnstile> P \\<^bold>\\<or> Q) \\<longleftrightarrow> ((ex \\<TTurnstile> P) \\<or> (ex \\<TTurnstile> Q))\"\n  by (simp add: OR_def temp_sat_def satisfies_def)\n\nlemma NOT_temp_sat [simp]: \"(ex \\<TTurnstile> \\<^bold>\\<not> P) \\<longleftrightarrow> (\\<not> (ex \\<TTurnstile> P))\"\n  by (simp add: NOT_def temp_sat_def satisfies_def)\n\n\naxiomatization\nwhere mkfin_UU [simp]: \"mkfin UU = nil\"\n  and mkfin_nil [simp]: \"mkfin nil = nil\"\n  and mkfin_cons [simp]: \"mkfin (a \\<leadsto> s) = a \\<leadsto> mkfin s\"\n\n\nlemmas [simp del] = HOL.ex_simps HOL.all_simps split_paired_Ex\n\nsetup \\<open>map_theory_claset (fn ctxt => ctxt delSWrapper \"split_all_tac\")\\<close>\n\n\nsubsection \\<open>ex2seqC\\<close>\n\nlemma ex2seqC_unfold:\n  \"ex2seqC =\n    (LAM ex. (\\<lambda>s. case ex of\n      nil \\<Rightarrow> (s, None, s) \\<leadsto> nil\n    | x ## xs \\<Rightarrow>\n        (flift1 (\\<lambda>pr. (s, Some (fst pr), snd pr) \\<leadsto> (ex2seqC \\<cdot> xs) (snd pr)) \\<cdot> x)))\"\n  apply (rule trans)\n  apply (rule fix_eq4)\n  apply (rule ex2seqC_def)\n  apply (rule beta_cfun)\n  apply (simp add: flift1_def)\n  done\n\nlemma ex2seqC_UU [simp]: \"(ex2seqC \\<cdot> UU) s = UU\"\n  apply (subst ex2seqC_unfold)\n  apply simp\n  done\n\nlemma ex2seqC_nil [simp]: \"(ex2seqC \\<cdot> nil) s = (s, None, s) \\<leadsto> nil\"\n  apply (subst ex2seqC_unfold)\n  apply simp\n  done\n\nlemma ex2seqC_cons [simp]: \"(ex2seqC \\<cdot> ((a, t) \\<leadsto> xs)) s = (s, Some a,t ) \\<leadsto> (ex2seqC \\<cdot> xs) t\"\n  apply (rule trans)\n  apply (subst ex2seqC_unfold)\n  apply (simp add: Consq_def flift1_def)\n  apply (simp add: Consq_def flift1_def)\n  done\n\n\nlemma ex2seq_UU: \"ex2seq (s, UU) = (s, None, s) \\<leadsto> nil\"\n  by (simp add: ex2seq_def)\n\nlemma ex2seq_nil: \"ex2seq (s, nil) = (s, None, s) \\<leadsto> nil\"\n  by (simp add: ex2seq_def)\n\nlemma ex2seq_cons: \"ex2seq (s, (a, t) \\<leadsto> ex) = (s, Some a, t) \\<leadsto> ex2seq (t, ex)\"\n  by (simp add: ex2seq_def)\n\ndeclare ex2seqC_UU [simp del] ex2seqC_nil [simp del] ex2seqC_cons [simp del]\ndeclare ex2seq_UU [simp] ex2seq_nil [simp] ex2seq_cons [simp]\n\n\nlemma ex2seq_nUUnnil: \"ex2seq exec \\<noteq> UU \\<and> ex2seq exec \\<noteq> nil\"\n  apply (pair exec)\n  apply (Seq_case_simp x2)\n  apply (pair a)\n  done\n\n\nsubsection \\<open>Interface TL -- TLS\\<close>\n\n(* uses the fact that in executions states overlap, which is lost in\n   after the translation via ex2seq !! *)\n\nlemma TL_TLS:\n  \"\\<forall>s a t. (P s) \\<and> s \\<midarrow>a\\<midarrow>A\\<rightarrow> t \\<longrightarrow> (Q t)\n    \\<Longrightarrow> ex \\<TTurnstile> (Init (\\<lambda>(s, a, t). P s) \\<^bold>\\<and> Init (\\<lambda>(s, a, t). s \\<midarrow>a\\<midarrow>A\\<rightarrow> t)\n              \\<^bold>\\<longrightarrow> (\\<circle>(Init (\\<lambda>(s, a, t). Q s))))\"\n  apply (unfold Init_def Next_def temp_sat_def satisfies_def IMPLIES_def AND_def)\n  apply clarify\n  apply (simp split: if_split)\n  text \\<open>\\<open>TL = UU\\<close>\\<close>\n  apply (rule conjI)\n  apply (pair ex)\n  apply (Seq_case_simp x2)\n  apply (pair a)\n  apply (Seq_case_simp s)\n  apply (pair a)\n  text \\<open>\\<open>TL = nil\\<close>\\<close>\n  apply (rule conjI)\n  apply (pair ex)\n  apply (Seq_case x2)\n  apply (simp add: unlift_def)\n  apply (simp add: unlift_def)\n  apply (simp add: unlift_def)\n  apply (pair a)\n  apply (Seq_case_simp s)\n  apply (pair a)\n  text \\<open>\\<open>TL = cons\\<close>\\<close>\n  apply (simp add: unlift_def)\n  apply (pair ex)\n  apply (Seq_case_simp x2)\n  apply (pair a)\n  apply (Seq_case_simp s)\n  apply (pair a)\n  done\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/HOLCF/IOA/TLS.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5698526514141571, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.29382737609670473}}
{"text": "(*  File:       Parallel_Composition.thy\n    Copyright   2021  Karlsruhe Institute of Technology (KIT)\n*)\n\\<^marker>\\<open>creator \"Karsten Diekhoff, Karlsruhe Institute of Technology (KIT)\"\\<close>\n\\<^marker>\\<open>contributor \"Jonas Kraemer, Karlsruhe Institute of Technology (KIT)\"\\<close>\n\\<^marker>\\<open>contributor \"Michael Kirsten, Karlsruhe Institute of Technology (KIT)\"\\<close>\n\nsection \\<open>Parallel Composition\\<close>\n\ntheory Parallel_Composition\n  imports \"Basic_Modules/Component_Types/Aggregator\"\n          \"Basic_Modules/Component_Types/Electoral_Module\"\nbegin\n\ntext \\<open>\n  The parallel composition composes a new electoral module from\n  two electoral modules combined with an aggregator.\n  Therein, the two modules each make a decision and the aggregator combines\n  them to a single (aggregated) result.\n\\<close>\n\nsubsection \\<open>Definition\\<close>\n\nfun parallel_composition :: \"'a Electoral_Module \\<Rightarrow> 'a Electoral_Module \\<Rightarrow>\n        'a Aggregator \\<Rightarrow> 'a Electoral_Module\" where\n  \"parallel_composition m n agg A p = agg A (m A p) (n A p)\"\n\nabbreviation parallel :: \"'a Electoral_Module \\<Rightarrow> 'a Aggregator \\<Rightarrow>\n        'a Electoral_Module \\<Rightarrow> 'a Electoral_Module\"\n      (\"_ \\<parallel>\\<^sub>_ _\" [50, 1000, 51] 50) where\n  \"m \\<parallel>\\<^sub>a n == parallel_composition m n a\"\n\nsubsection \\<open>Soundness\\<close>\n\ntheorem par_comp_sound[simp]:\n  assumes\n    mod_m: \"electoral_module m\" and\n    mod_n: \"electoral_module n\" and\n    agg_a: \"aggregator a\"\n  shows \"electoral_module (m \\<parallel>\\<^sub>a n)\"\nproof (unfold electoral_module_def, safe)\n  fix\n    A :: \"'a set\" and\n    p :: \"'a Profile\"\n  assume\n    fin_A: \"finite A\" and\n    prof_A: \"profile A p\"\n  have wf_quant:\n    \"\\<forall> a. aggregator a =\n      (\\<forall> A' e r d e' r' d'.\n        (\\<not> well_formed (A'::'a set) (e, r', d) \\<or>\n          \\<not> well_formed A' (r, d', e')) \\<or>\n        well_formed A'\n          (a A' (e, r', d) (r, d', e')))\"\n    unfolding aggregator_def\n    by blast\n  have wf_imp:\n    \"\\<forall> m' A' p'.\n      (electoral_module m' \\<and> finite (A'::'a set) \\<and>\n        profile A' p') \\<longrightarrow>\n        well_formed A' (m' A' p')\"\n    using par_comp_result_sound\n    by (metis (no_types))\n  from mod_m mod_n fin_A prof_A agg_a\n  have \"well_formed A (a A (m A p) (n A p))\"\n    using agg_a combine_ele_rej_def fin_A\n          mod_m mod_n prof_A wf_imp wf_quant\n    by metis\n  thus \"well_formed A ((m \\<parallel>\\<^sub>a n) A p)\"\n    by simp\nqed\n\nsubsection \\<open>Composition Rule\\<close>\n\ntext \\<open>\n  Using a conservative aggregator, the parallel composition\n  preserves the property non-electing.\n\\<close>\n\ntheorem conserv_agg_presv_non_electing[simp]:\n  assumes\n    non_electing_m: \"non_electing m\" and\n    non_electing_n: \"non_electing n\" and\n    conservative: \"agg_conservative a\"\n  shows \"non_electing (m \\<parallel>\\<^sub>a n)\"\nproof (unfold non_electing_def, safe)\n  have emod_m: \"electoral_module m\"\n    using non_electing_m\n    unfolding non_electing_def\n    by simp\n  have emod_n: \"electoral_module n\"\n    using non_electing_n\n    unfolding non_electing_def\n    by simp\n  have agg_a: \"aggregator a\"\n    using conservative\n    unfolding agg_conservative_def\n    by simp\n  thus \"electoral_module (m \\<parallel>\\<^sub>a n)\"\n    using emod_m emod_n agg_a par_comp_sound\n    by simp\nnext\n  fix\n    A :: \"'a set\" and\n    p :: \"'a Profile\" and\n    x :: \"'a\"\n  assume\n    fin_A: \"finite A\" and\n    prof_A: \"profile A p\" and\n    x_wins: \"x \\<in> elect (m \\<parallel>\\<^sub>a n) A p\"\n  have emod_m: \"electoral_module m\"\n    using non_electing_m\n    unfolding non_electing_def\n    by simp\n  have emod_n: \"electoral_module n\"\n    using non_electing_n\n    unfolding non_electing_def\n    by simp\n  have\n    \"\\<forall> r r' d d' e e' A' f.\n      (well_formed (A'::'a set) (e', r', d') \\<and> well_formed A' (e, r, d) \\<longrightarrow>\n        elect_r (f A' (e', r', d') (e, r, d)) \\<subseteq> e' \\<union> e \\<and>\n          reject_r (f A' (e', r', d') (e, r, d)) \\<subseteq> r' \\<union> r \\<and>\n          defer_r (f A' (e', r', d') (e, r, d)) \\<subseteq> d' \\<union> d) =\n            ((\\<not> well_formed A' (e', r', d') \\<or> \\<not> well_formed A' (e, r, d)) \\<or>\n              elect_r (f A' (e', r', d') (e, r, d)) \\<subseteq> e' \\<union> e \\<and>\n                reject_r (f A' (e', r', d') (e, r, d)) \\<subseteq> r' \\<union> r \\<and>\n                defer_r (f A' (e', r', d') (e, r, d)) \\<subseteq> d' \\<union> d)\"\n    by linarith\n  hence\n    \"\\<forall> a. agg_conservative a =\n      (aggregator a \\<and>\n        (\\<forall> A' e e' d d' r r'. (\\<not> well_formed (A'::'a set) (e, r, d) \\<or>\n            \\<not> well_formed A' (e', r', d')) \\<or>\n          elect_r (a A' (e, r, d) (e', r', d')) \\<subseteq> e \\<union> e' \\<and>\n            reject_r (a A' (e, r, d) (e', r', d')) \\<subseteq> r \\<union> r' \\<and>\n            defer_r (a A' (e, r, d) (e', r', d')) \\<subseteq> d \\<union> d'))\"\n    unfolding agg_conservative_def\n    by simp\n  hence\n    \"aggregator a \\<and>\n      (\\<forall> A' e e' d d' r r'. \\<not> well_formed A' (e, r, d) \\<or>\n          \\<not> well_formed A' (e', r', d') \\<or>\n          elect_r (a A' (e, r, d) (e', r', d')) \\<subseteq> e \\<union> e' \\<and>\n            reject_r (a A' (e, r, d) (e', r', d')) \\<subseteq> r \\<union> r' \\<and>\n            defer_r (a A' (e, r, d) (e', r', d')) \\<subseteq> d \\<union> d')\"\n    using conservative\n    by presburger\n  hence\n    \"let c = (a A (m A p) (n A p)) in\n      (elect_r c \\<subseteq> ((elect m A p) \\<union> (elect n A p)))\"\n    using emod_m emod_n fin_A par_comp_result_sound\n          prod.collapse prof_A\n    by metis\n  hence \"x \\<in> ((elect m A p) \\<union> (elect n A p))\"\n    using x_wins\n    by auto\n  thus \"x \\<in> {}\"\n    using sup_bot_right fin_A prof_A\n          non_electing_m non_electing_n\n    unfolding non_electing_def\n    by (metis (no_types, lifting))\nqed\n\nend\n", "meta": {"author": "VeriVote", "repo": "verifiedVotingRuleConstruction", "sha": "17bf689350c733dc7b419f4924d099a0e65de036", "save_path": "github-repos/isabelle/VeriVote-verifiedVotingRuleConstruction", "path": "github-repos/isabelle/VeriVote-verifiedVotingRuleConstruction/verifiedVotingRuleConstruction-17bf689350c733dc7b419f4924d099a0e65de036/theories/Compositional_Structures/Parallel_Composition.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5698526514141571, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.2938273760967047}}
{"text": "section \\<open>Entry-Point to Word Library and additional lemmas for Isabelle-LLVM\\<close>\ntheory LLVM_More_Word\nimports \"HOL-Library.Word\" (*\"HOL-Library.Bit_Operations\"*) Bits_Natural \"Word_Lib.Word_Lib_Sumo\"\nbegin\n(* TODO: Fix in Word.thy! \n  Introducing proper infix-syntax for signed comparisons. So, also (<s) and (<=s) get available.\n*)\n(*\nno_notation word_sle (\"(_/ <=s _)\" [50, 51] 50)\nno_notation word_sless  (\"(_/ <s _)\" [50, 51] 50)\nnotation word_sle (infix \"<=s\" 50)\nnotation word_sless (infix \"<s\" 50)\n*)\n\n(* Try to remove some useless stuff that Word_Lemmas imported via Complex_Main. *)\n\ndeclare [[coercion_enabled = false]]\n\nsubsection \\<open>Additional Lemmas\\<close>\n\nclass len2 = len +\n  assumes len2_not_1 [simp]: \"LENGTH('a) \\<noteq> Suc 0\"\n\nlemma len2_simps[simp]:\n  \"LENGTH('a::len2) > Suc 0\"\n  \"LENGTH('a::len2) \\<ge> 2\"\n  subgoal by (metis Suc_lessI len2_not_1 len_gt_0)\n  subgoal using \\<open>Suc 0 < LENGTH('a)\\<close> by linarith\n  done\n  \nlemma len2E: obtains n where \"LENGTH('a::len2) = 2+n\"\n  apply (cases \"LENGTH('a)\"; simp)\n  subgoal for k by (cases k; simp)\n  done\n  \ninstance bit0 :: (len) len2 \n  by standard simp\n  \ninstance bit1 :: (len) len2 \n  by standard simp\n  \ndefinition \"len2 (TYPE('a::len2)) \\<equiv> True\"  \n\n\n(* Original theorem is in simpset, but useless due to non-normalized LHS *)\nlemmas [simp] = word_sbin.norm_Rep[simplified]\n\n\nlemma to_bl_scast_down: \"is_down SCAST('a::len \\<rightarrow> 'b::len) \\<Longrightarrow> to_bl (SCAST('a \\<rightarrow> 'b) w) = drop (LENGTH('a)-LENGTH('b)) (to_bl w)\"  \n  by (simp add: is_down scast_down_drop source_size target_size)\n  \n\n\ndeclare word_unat.Rep_inject[simp del]\ndeclare word_uint.Rep_inject[simp del]\n\nlemma msb_uint_big: \"msb (w::'a::len word) \\<longleftrightarrow> uint w \\<ge> 2^(LENGTH('a)-1)\"      \n  apply (simp add: msb_big) \n  by (metis One_nat_def Suc_pred' diff_le_self le_antisym len_gt_0 n_not_Suc_n p2_eq_0 uint_2p word_le_def word_neq_0_conv)\n\nlemma msb_unat_big: \"msb (w::'a::len word) \\<longleftrightarrow> unat w \\<ge> 2^(LENGTH('a)-1)\"      \n  by (simp add: msb_big word_le_nat_alt)\n\n(* TODO: Move *)  \nlemma word1_neqZ_is_one: \"(a::1 word) \\<noteq> 0 \\<longleftrightarrow> a=1\"  \n  apply transfer\n  subgoal for a\n    apply (cases \"bin_last a\")\n    by auto\n  done\n  \nlemma word1_cases[cases type]: \n  fixes a :: \"1 word\" obtains (zero) \"a=0\" | (one) \"a=1\"\n  apply (cases \"a=0\")\n  by (auto simp: word1_neqZ_is_one)\n  \n(* TODO: Move *)  \nlemma word1_NOT_eq: \"~~(x::1 word) = x+1\"\n  by (auto simp: NOT_eq)\n\nlemma upcast_no_msb[simp]: \"LENGTH('small::len) < LENGTH('big::len) \\<Longrightarrow> \\<not>msb (UCAST('small \\<rightarrow> 'big) x)\" \n  by (simp add: bit_word_ucast_iff msb_word_eq)\n\nsubsection \\<open>Integer Division with Rounding Towards Zero\\<close>\n\ntext \\<open>Division with rounding towards zero\\<close>\n\nlemma int_sgn_cases: fixes a::int obtains (negative) \"a<0\" | (zero) \"a=0\" | (positive) \"a>0\"\n  by (rule linorder_cases)\n\ntext \\<open>Lemmas to match original definitions from this development to \n  definitions from Word-Library, to which we switched at some point.\\<close>\nlemma sdiv_int_original_def: \"(a::int) sdiv b = (if a\\<ge>0 \\<longleftrightarrow> b\\<ge>0 then \\<bar>a\\<bar> div \\<bar>b\\<bar> else - ( \\<bar>a\\<bar> div \\<bar>b\\<bar>))\"\n  apply (cases a rule: int_sgn_cases; cases b rule: int_sgn_cases)\n  apply (auto simp: sdiv_int_def sgn_mult)\n  done\n  \nlemma srem_int_original_def: \"(a::int) smod b = (if a\\<ge>0 then \\<bar>a\\<bar> mod \\<bar>b\\<bar> else - (\\<bar>a\\<bar> mod \\<bar>b\\<bar>))\"\n  apply (cases a rule: int_sgn_cases; cases b rule: int_sgn_cases)\n  apply (auto \n    simp: smod_int_def sdiv_int_def sgn_mult algebra_simps \n    simp flip: minus_mod_eq_mult_div mult_minus_left)\n  done  \n  \n  \ntext \\<open>Standard properties of remainders\\<close>\nlemma div_rem_rtz_id: \"(a::int) sdiv b * b + a smod b = a\"\n  by (simp add: smod_int_def)\n\nlemma abs_rem_rtz_lt: \"b\\<noteq>0 \\<Longrightarrow> \\<bar>a smod b\\<bar> < \\<bar>b::int\\<bar>\"\n  using srem_int_original_def by auto\n  \ntext \\<open>LLVM documentation: The remainder is either zero, or has the same sign as the dividend\\<close>\nlemma rem_rtz_sign: \"(a::int) smod b = 0 \\<or> sgn ((a::int) smod b) = sgn a\"\n  apply (clarsimp simp: srem_int_original_def)\n  by (metis (no_types, hide_lams) Euclidean_Division.pos_mod_sign abs_le_zero_iff abs_of_nonneg add.inverse_neutral mod_0 mod_by_0 neg_le_0_iff_le not_le sgn_pos)\n  (*by (smt Euclidean_Division.pos_mod_sign sgn_pos zmod_trival_iff)*)\n  \n\nlemma sdiv_positive[simp]: \"(a::int)\\<ge>0 \\<Longrightarrow> b\\<ge>0 \\<Longrightarrow> a sdiv b = a div b\"\n  by (simp add: sdiv_int_original_def)\n\nlemma smod_positive[simp]: \"(a::int)\\<ge>0 \\<Longrightarrow> b\\<ge>0 \\<Longrightarrow> a smod b = a mod b\"\n  by (auto simp: srem_int_original_def)\n\n\nsubsection \\<open>Additions to Bits-Int\\<close>\ndeclare bin_to_bl_def[simp del]\n\n(* TODO: Move *)\nlemma map2_eq_Nil_conv[simp]: \"map2 f a b = [] \\<longleftrightarrow> a=[] \\<or> b=[]\"\n  by (cases a; cases b; auto)\n  \nlemma bin_to_bl_eq_Nil_conv[simp]: \"bin_to_bl w i = [] \\<longleftrightarrow> w=0\"\n  by (metis bin_to_bl_aux.Z bin_to_bl_def size_bin_to_bl)\n\nlemma bin_to_bl_aux_eq_Nil_conv[simp]: \"bin_to_bl_aux w i acc = [] \\<longleftrightarrow> w=0 \\<and> acc=[]\"\n  by (metis bin_to_bl_aux.Z bin_to_bl_eq_Nil_conv take.simps(1) take_bin2bl_lem1)\n\nlemma \"bl_to_bin_aux bl (1+n) = bl_to_bin_aux bl n + 2 ^ length bl\"\n  apply (induction bl arbitrary: n)\n  apply (simp_all add: algebra_simps)\n  by smt\n\nlemma bl_to_bin_True [simp]: \"bl_to_bin (True # bl) = bl_to_bin bl + 2^length bl\"\nproof -\n  have \"bl_to_bin_aux bl (1+n) = bl_to_bin_aux bl n + 2 ^ length bl\" for n\n    apply (induction bl arbitrary: n)\n    apply (simp_all add: algebra_simps)\n    by smt\n  from this[of 0] show ?thesis\n    unfolding bl_to_bin_def\n    by simp\nqed\n\nlemma bl_to_bin_append_num: \"bl_to_bin (a@b) = 2^length b * bl_to_bin a + bl_to_bin b\"\n  by (simp add: bin_cat_num bl_to_bin_app_cat)\n\nlemma bl_to_bin_rep_True: \"bl_to_bin (replicate n True) = 2 ^ n - 1\"\n  by (metis bin_bl_bin bin_to_bl_minus1 bintr_Min)\n\nlemma bl_to_bin_rep_T: \"bl_to_bin (replicate n True @ bl) = 2 ^ length bl * (2 ^ n - 1) + bl_to_bin bl\"\n  by (simp add: bl_to_bin_append_num bl_to_bin_rep_True algebra_simps)\n\nlemma bin_to_bl_strunc[simp]: \n  \"w\\<^sub>1 \\<le> w\\<^sub>2 + 1 \\<Longrightarrow> bin_to_bl w\\<^sub>1 (sbintrunc w\\<^sub>2 i) = bin_to_bl w\\<^sub>1 i\"\n  by (simp add: bintrunc_sbintrunc_le bl_to_bin_inj)\n\nlemma bin_last_x2[simp]: \"bin_last (2*n) = False\" by (auto)\nlemma bin_rest_x2[simp]: \"bin_rest (2*n) = n\" by simp\n\nlemma bin_to_bl_x2[simp]: \"w\\<noteq>0 \\<Longrightarrow> bin_to_bl w (2*n) = bin_to_bl (w-1) n @ [False]\"\n  by (cases w) (auto simp: bin_to_bl_def bin_to_bl_aux_append)\n\nlemma bin_to_bl_xp2[simp]:\n  assumes \"n\\<le>w\" \n  shows \"bin_to_bl w (x * 2^n) = bin_to_bl (w-n) x @ replicate n False\"\nproof -\n  have [simp]: \"x * (2 * 2 ^ n) = 2 * (x*2^n)\" for n by auto\n\n  show ?thesis using assms\n    by (induction n) (auto simp: drop_bin2bl[symmetric] replicate_append_same)\nqed\n\nlemma bintrunc_eq_if_in_range: \"bintrunc w i = i \\<longleftrightarrow> i\\<in>uints w\"\n  by (simp add: bintrunc_mod2p int_mod_lem uints_num)\n\nlemma sbintrunc_eq_if_in_range: \"sbintrunc (w-Suc 0) i = i \\<longleftrightarrow> i\\<in>sints w\"\n  by (clarsimp simp: sints_def sbintrunc_eq_in_range)\n\nlemma bl_to_bin_in_uints: \"bl_to_bin x \\<in> uints (length x)\"\n  using bl_to_bin_def bintrunc_eq_if_in_range by fastforce\n\n\n(* TODO: This is probably a special case of a more general scheme! *)\n\nmethod_setup pull_mods = \\<open>Scan.succeed (fn ctxt =>  SIMPLE_METHOD' (\n  CONVERSION (Conv.top_conv (K (Conv.try_conv (Conv.rewrs_conv @{thms pull_mods}))) ctxt)\n))\\<close>\n\nmethod_setup pull_push_mods = \\<open>Scan.succeed (fn ctxt => SIMPLE_METHOD' (\n  CONVERSION (Conv.top_conv (K (Conv.try_conv (Conv.rewrs_conv @{thms pull_mods}))) ctxt)\n  THEN' (full_simp_tac (put_simpset HOL_basic_ss ctxt addsimps @{thms mod_mod_trivial push_mods}))\n))\\<close> \\<open>Pull in, then push out modulos\\<close>\n\n\nsubsection \\<open>Signed integers in Two's Complement Representation\\<close>\n\ndefinition bl_to_sbin :: \"bool list \\<Rightarrow> int\" \n  where \"bl_to_sbin bl = sbintrunc (length bl - 1) (bl_to_bin bl)\"\n\nlemma bl_to_sbin_alt:\n  \"bl_to_sbin bl = (case bl of [] \\<Rightarrow> 0 | b#bl \\<Rightarrow> (if b then -(2^length bl) else 0) + bl_to_bin bl)\"\n  apply (auto simp: bl_to_sbin_def sbintrunc_mod2p bl_to_bin_ge0 bl_to_bin_lt2p split: list.splits)\n  by (smt bl_to_bin_ge0 bl_to_bin_lt2p int_mod_eq')\n\nlemma bl_sbin_bl[simp]: \"bin_to_bl (length bs) (bl_to_sbin bs) = bs\"\n  unfolding bl_to_sbin_def by auto\n\nlemma sbin_bl_bin[simp]:\n  \"0<w \\<Longrightarrow> bl_to_sbin (bin_to_bl w i) = sbintrunc (w-1) i\"\n  unfolding bl_to_sbin_def by auto\n\nlemma bl_to_sbin_in_sints: \"bl_to_sbin x \\<in> sints (length x)\"\n  using bl_to_sbin_def sbintrunc_eq_if_in_range by fastforce\n\n\n\nend\n", "meta": {"author": "lammich", "repo": "isabelle_llvm", "sha": "6be37a9c3cae74a1134dbef2979e312abb5f7f42", "save_path": "github-repos/isabelle/lammich-isabelle_llvm", "path": "github-repos/isabelle/lammich-isabelle_llvm/isabelle_llvm-6be37a9c3cae74a1134dbef2979e312abb5f7f42/thys/lib/LLVM_More_Word.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5156199157230156, "lm_q2_score": 0.5698526514141571, "lm_q1q2_score": 0.2938273760967047}}
{"text": "(*  Title:      HOL/HOLCF/IOA/NTP/Abschannel.thy\n    Author:     Olaf Müller\n*)\n\nsection \\<open>The (faulty) transmission channel (both directions)\\<close>\n\ntheory Abschannel\nimports \"../IOA\" Action\nbegin\n\ndatatype 'a abs_action = S 'a | R 'a\n\ndefinition\n  ch_asig :: \"'a abs_action signature\" where\n  \"ch_asig = (UN b. {S(b)}, UN b. {R(b)}, {})\"\n\ndefinition\n  ch_trans :: \"('a abs_action, 'a multiset)transition set\" where\n  \"ch_trans =\n    {tr. let s = fst(tr);\n             t = snd(snd(tr))\n         in\n         case fst(snd(tr))\n           of S(b) => t = addm s b |\n              R(b) => count s b ~= 0 & t = delm s b}\"\n\ndefinition\n  ch_ioa :: \"('a abs_action, 'a multiset)ioa\" where\n  \"ch_ioa = (ch_asig, {{|}}, ch_trans,{},{})\"\n\ndefinition\n  rsch_actions :: \"'m action => bool abs_action option\" where\n  \"rsch_actions (akt) =\n          (case akt of\n           S_msg(m) => None |\n            R_msg(m) => None |\n           S_pkt(packet) => None |\n            R_pkt(packet) => None |\n            S_ack(b) => Some(S(b)) |\n            R_ack(b) => Some(R(b)) |\n           C_m_s =>  None  |\n           C_m_r =>  None |\n           C_r_s =>  None  |\n           C_r_r(m) => None)\"\n\ndefinition\n  srch_actions :: \"'m action =>(bool * 'm) abs_action option\" where\n  \"srch_actions (akt) =\n          (case akt of\n           S_msg(m) => None |\n            R_msg(m) => None |\n           S_pkt(p) => Some(S(p)) |\n            R_pkt(p) => Some(R(p)) |\n            S_ack(b) => None |\n            R_ack(b) => None |\n           C_m_s => None |\n           C_m_r => None |\n           C_r_s => None |\n           C_r_r(m) => None)\"\n\ndefinition\n  srch_ioa :: \"('m action, 'm packet multiset)ioa\" where\n  \"srch_ioa = rename ch_ioa srch_actions\"\n\ndefinition\n  rsch_ioa :: \"('m action, bool multiset)ioa\" where\n  \"rsch_ioa = rename ch_ioa rsch_actions\"\n\ndefinition\n  srch_asig :: \"'m action signature\" where\n  \"srch_asig = asig_of(srch_ioa)\"\n\ndefinition\n  rsch_asig :: \"'m action signature\" where\n  \"rsch_asig = asig_of(rsch_ioa)\"\n\ndefinition\n  srch_wfair :: \"('m action)set set\" where\n  \"srch_wfair = wfair_of(srch_ioa)\"\ndefinition\n  srch_sfair :: \"('m action)set set\" where\n  \"srch_sfair = sfair_of(srch_ioa)\"\ndefinition\n  rsch_sfair :: \"('m action)set set\" where\n  \"rsch_sfair = sfair_of(rsch_ioa)\"\ndefinition\n  rsch_wfair :: \"('m action)set set\" where\n  \"rsch_wfair = wfair_of(rsch_ioa)\"\n\ndefinition\n  srch_trans :: \"('m action, 'm packet multiset)transition set\" where\n  \"srch_trans = trans_of(srch_ioa)\"\ndefinition\n  rsch_trans :: \"('m action, bool multiset)transition set\" where\n  \"rsch_trans = trans_of(rsch_ioa)\"\n\n\nlemmas unfold_renaming =\n  srch_asig_def rsch_asig_def rsch_ioa_def srch_ioa_def ch_ioa_def\n  ch_asig_def srch_actions_def rsch_actions_def rename_def rename_set_def asig_of_def\n  actions_def srch_trans_def rsch_trans_def ch_trans_def starts_of_def\n  trans_of_def asig_projections\n\nlemma in_srch_asig: \n     \"S_msg(m) ~: actions(srch_asig)        &     \n       R_msg(m) ~: actions(srch_asig)        &     \n       S_pkt(pkt) : actions(srch_asig)    &     \n       R_pkt(pkt) : actions(srch_asig)    &     \n       S_ack(b) ~: actions(srch_asig)     &     \n       R_ack(b) ~: actions(srch_asig)     &     \n       C_m_s ~: actions(srch_asig)           &     \n       C_m_r ~: actions(srch_asig)           &     \n       C_r_s ~: actions(srch_asig)  & C_r_r(m) ~: actions(srch_asig)\"\n  by (simp add: unfold_renaming)\n\nlemma in_rsch_asig: \n      \"S_msg(m) ~: actions(rsch_asig)         &  \n       R_msg(m) ~: actions(rsch_asig)         &  \n       S_pkt(pkt) ~: actions(rsch_asig)    &  \n       R_pkt(pkt) ~: actions(rsch_asig)    &  \n       S_ack(b) : actions(rsch_asig)       &  \n       R_ack(b) : actions(rsch_asig)       &  \n       C_m_s ~: actions(rsch_asig)            &  \n       C_m_r ~: actions(rsch_asig)            &  \n       C_r_s ~: actions(rsch_asig)            &  \n       C_r_r(m) ~: actions(rsch_asig)\"\n  by (simp add: unfold_renaming)\n\nlemma srch_ioa_thm: \"srch_ioa =  \n    (srch_asig, {{|}}, srch_trans,srch_wfair,srch_sfair)\"\napply (simp (no_asm) add: srch_asig_def srch_trans_def asig_of_def trans_of_def wfair_of_def sfair_of_def srch_wfair_def srch_sfair_def)\napply (simp (no_asm) add: unfold_renaming)\ndone\n\nlemma rsch_ioa_thm: \"rsch_ioa =  \n     (rsch_asig, {{|}}, rsch_trans,rsch_wfair,rsch_sfair)\"\napply (simp (no_asm) add: rsch_asig_def rsch_trans_def asig_of_def trans_of_def wfair_of_def sfair_of_def rsch_wfair_def rsch_sfair_def)\napply (simp (no_asm) add: unfold_renaming)\ndone\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/HOL/HOLCF/IOA/NTP/Abschannel.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6113819874558604, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.29375600911509386}}
{"text": "(*******************************************************************************\n\n  Project: Development of Security Protocols by Refinement\n\n  Module:  Key_establish/m2_ds.thy (Isabelle/HOL 2016-1)\n  ID:      $Id: m2_ds.thy 132890 2016-12-24 10:25:57Z csprenge $\n  Author:  Ivano Somaini, ETH Zurich <somainii@student.ethz.ch>\n           Christoph Sprenger, ETH Zurich <sprenger@inf.ethz.ch>\n\n  Key distribution protocols\n  Level 2: channel protocol, parallel version of Denning-Sacco\n\n  Copyright (c) 2009-2016 Ivano Somaini and Christoph Sprenger\n  Licence: LGPL\n\n*******************************************************************************)\n\nsection \\<open>Abstract Denning-Sacco protocol (L2)\\<close>\n\ntheory m2_ds imports m1_ds \"../Refinement/Channels\"\nbegin\n\ntext \\<open>\nWe model an abstract version of the Denning-Sacco protocol:\n\\[\n\\begin{array}{lll}\n  \\mathrm{M1.} & A \\rightarrow S: & A, B \\\\ \n  \\mathrm{M2.} & S \\rightarrow A: & \\{B, Kab, T,\\{Kab, A, T\\}_{Kbs} \\}_{Kas} \\\\\n  \\mathrm{M3.} & A \\rightarrow B: & \\{Kab, A, T\\}_{Kbs} \\\\\n\\end{array}\n\\]\n\nThis refinement introduces channels with security properties.  We model \na parallel version of the DS protocol:\n\\[\n\\begin{array}{lll}\n  \\mathrm{M1.} & A \\rightarrow S: & A, B \\\\ \n  \\mathrm{M2a.} & S \\rightarrow A: & \\{B, Kab, T\\}_{Kas} \\\\\n  \\mathrm{M2b.} & S \\rightarrow B: & \\{Kab, A, T\\}_{Kbs} \\\\\n\\end{array}\n\\]\nMessage 1 is sent over an insecure channel, the other two message over\nsecure channels.\n\\<close>\n\ndeclare domIff [simp, iff del]\n\n\n(******************************************************************************)\nsubsection \\<open>State\\<close>\n(******************************************************************************)\n\ntext \\<open>State and observations\\<close>\n\nrecord m2_state = \"m1_state\" +\n  chan :: \"chmsg set\"              \\<comment> \\<open>channel messages\\<close>\n\ntype_synonym \n  m2_obs = \"m1_state\" \n\ndefinition \n  m2_obs :: \"m2_state \\<Rightarrow> m2_obs\" where\n  \"m2_obs s \\<equiv> \\<lparr> \n     runs = runs s,\n     leak = leak s,\n     clk = clk s\n  \\<rparr>\"\n\ntype_synonym\n  m2_pred = \"m2_state set\"\n\ntype_synonym\n  m2_trans = \"(m2_state \\<times> m2_state) set\"\n\n\n(******************************************************************************)\nsubsection \\<open>Events\\<close>\n(******************************************************************************)\n\ntext \\<open>Protocol events.\\<close>\n\ndefinition     \\<comment> \\<open>by @{term \"A\"}, refines @{term \"m1a_step1\"}\\<close>\n  m2_step1 :: \"[rid_t, agent, agent] \\<Rightarrow> m2_trans\"\nwhere\n  \"m2_step1 Ra A B \\<equiv> {(s, s1).\n\n     \\<comment> \\<open>guards:\\<close>\n     Ra \\<notin> dom (runs s) \\<and>                                \\<comment> \\<open>\\<open>Ra\\<close> is fresh\\<close>\n\n     \\<comment> \\<open>actions:\\<close>\n     \\<comment> \\<open>create initiator thread and send message 1\\<close>\n     s1 = s\\<lparr>\n       runs := (runs s)(Ra \\<mapsto> (Init, [A, B], [])),\n       chan := insert (Insec A B (Msg [])) (chan s)     \\<comment> \\<open>send M1\\<close>\n     \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by @{term \"B\"}, refines @{term \"m1e_step2\"}\\<close>\n  m2_step2 :: \"[rid_t, agent, agent] \\<Rightarrow> m2_trans\"\nwhere\n  \"m2_step2 \\<equiv> m1_step2\"\n\ndefinition     \\<comment> \\<open>by @{text \"Server\"}, refines @{term m1e_step3}\\<close>\n  m2_step3 :: \"[rid_t, agent, agent, key, time] \\<Rightarrow> m2_trans\"\nwhere\n  \"m2_step3 Rs A B Kab Ts \\<equiv> {(s, s1). \n\n     \\<comment> \\<open>guards:\\<close>\n     Rs \\<notin> dom (runs s) \\<and>                           \\<comment> \\<open>fresh server run\\<close>\n     Kab = sesK (Rs$sk) \\<and>                          \\<comment> \\<open>fresh session key\\<close>\n     Ts = clk s \\<and>                                  \\<comment> \\<open>fresh timestamp\\<close> \n\n     Insec A B (Msg []) \\<in> chan s \\<and>                 \\<comment> \\<open>recv M1\\<close>\n   \n     \\<comment> \\<open>actions:\\<close>\n     \\<comment> \\<open>record key and send messages 2 and 3\\<close>\n     s1 = s\\<lparr>\n       runs := (runs s)(Rs \\<mapsto> (Serv, [A, B], [aNum Ts])), \n       chan := {Secure Sv A (Msg [aAgt B, aKey Kab, aNum Ts]),    \\<comment> \\<open>send \\<open>M2a/b\\<close>\\<close>\n                Secure Sv B (Msg [aKey Kab, aAgt A, aNum Ts])} \\<union> chan s\n     \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by @{term \"A\"}, refines @{term m1e_step4}\\<close>\n  m2_step4 :: \"[rid_t, agent, agent, key, time] \\<Rightarrow> m2_trans\"\nwhere\n  \"m2_step4 Ra A B Kab Ts \\<equiv> {(s, s1).\n\n     \\<comment> \\<open>guards:\\<close>\n     runs s Ra = Some (Init, [A, B], []) \\<and> \n     Secure Sv A (Msg [aAgt B, aKey Kab, aNum Ts]) \\<in> chan s \\<and>  \\<comment> \\<open>recv \\<open>M2a\\<close>\\<close>\n\n     clk s < Ts + Ls \\<and>                              \\<comment> \\<open>ensure key freshness\\<close>\n\n     \\<comment> \\<open>actions:\\<close>\n     \\<comment> \\<open>record session key\\<close>\n     s1 = s\\<lparr>\n       runs := (runs s)(Ra \\<mapsto> (Init, [A, B], [aKey Kab, aNum Ts]))\n     \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by @{term \"B\"}, refines @{term m1e_step5}\\<close>\n  m2_step5 :: \"[rid_t, agent, agent, key, time] \\<Rightarrow> m2_trans\"\nwhere\n  \"m2_step5 Rb A B Kab Ts \\<equiv> {(s, s1). \n\n     \\<comment> \\<open>guards:\\<close>\n     runs s Rb = Some (Resp, [A, B], []) \\<and>\n     Secure Sv B (Msg [aKey Kab, aAgt A, aNum Ts]) \\<in> chan s \\<and>  \\<comment> \\<open>recv \\<open>M2b\\<close>\\<close>\n\n     \\<comment> \\<open>ensure freshness of session key\\<close>\n     clk s < Ts + Ls \\<and>\n\n     \\<comment> \\<open>actions:\\<close>\n     \\<comment> \\<open>record session key\\<close>\n     s1 = s\\<lparr>\n       runs := (runs s)(Rb \\<mapsto> (Resp, [A, B], [aKey Kab, aNum Ts]))\n     \\<rparr>\n  }\"\n\ntext \\<open>Clock tick event\\<close>\n\ndefinition     \\<comment> \\<open>refines @{term m1_tick}\\<close>\n  m2_tick :: \"time \\<Rightarrow> m2_trans\" \nwhere\n  \"m2_tick \\<equiv> m1_tick\"\n\n\ntext \\<open>Session key compromise.\\<close>\n\ndefinition     \\<comment> \\<open>refines @{term m1_leak}\\<close> \n  m2_leak :: \"rid_t \\<Rightarrow> m2_trans\"\nwhere\n  \"m2_leak Rs \\<equiv> {(s, s1).\n    \\<comment> \\<open>guards:\\<close>\n    Rs \\<in> dom (runs s) \\<and>\n    fst (the (runs s Rs)) = Serv \\<and>         \\<comment> \\<open>compromise server run \\<open>Rs\\<close>\\<close>\n\n    \\<comment> \\<open>actions:\\<close>\n    \\<comment> \\<open>record session key as leaked;\\<close>\n    \\<comment> \\<open>intruder sends himself an insecure channel message containing the key\\<close>\n    s1 = s\\<lparr> leak := insert (sesK (Rs$sk)) (leak s), \n            chan := insert (Insec undefined undefined (Msg [aKey (sesK (Rs$sk))])) (chan s) \\<rparr> \n  }\"\n\n\ntext \\<open>Intruder fake event (new).\\<close>\n\ndefinition     \\<comment> \\<open>refines @{term Id}\\<close> \n  m2_fake :: \"m2_trans\"\nwhere\n  \"m2_fake \\<equiv> {(s, s1). \n\n     \\<comment> \\<open>actions:\\<close>\n     s1 = s\\<lparr>\n       \\<comment> \\<open>close under fakeable messages\\<close>\n       chan := fake ik0 (dom (runs s)) (chan s) \n     \\<rparr>\n  }\"\n\n\n(******************************************************************************)\nsubsection \\<open>Transition system\\<close>\n(******************************************************************************)\n\ndefinition \n  m2_init :: \"m2_pred\"\nwhere\n  \"m2_init \\<equiv> { \\<lparr>\n     runs = Map.empty,\n     leak = corrKey,\n     clk = 0,\n     chan = {}              \\<comment> \\<open>\\<open>Channels.ik0\\<close> contains \\<open>aKey`corrKey\\<close>\\<close>\n  \\<rparr> }\"\n\ndefinition \n  m2_trans :: \"m2_trans\" where\n  \"m2_trans \\<equiv> (\\<Union>A B Ra Rb Rs Kab Ts T.\n     m2_step1 Ra A B \\<union>\n     m2_step2 Rb A B \\<union>\n     m2_step3 Rs A B Kab Ts \\<union>\n     m2_step4 Ra A B Kab Ts \\<union>\n     m2_step5 Rb A B Kab Ts \\<union>\n     m2_tick T \\<union>\n     m2_leak Rs \\<union>\n     m2_fake \\<union>\n     Id\n  )\"\n\ndefinition \n  m2 :: \"(m2_state, m2_obs) spec\" where\n  \"m2 \\<equiv> \\<lparr>\n    init = m2_init,\n    trans = m2_trans,\n    obs = m2_obs\n  \\<rparr>\"\n\nlemmas m2_loc_defs = \n  m2_def m2_init_def m2_trans_def m2_obs_def\n  m2_step1_def m2_step2_def m2_step3_def m2_step4_def m2_step5_def \n  m2_tick_def m2_leak_def m2_fake_def \n\nlemmas m2_defs = m2_loc_defs m1_defs\n\n\n(******************************************************************************)\nsubsection \\<open>Invariants and simulation relation\\<close>\n(******************************************************************************)\n\n(*\nsubsubsection {* inv1: Key definedness [UNUSED] *}\n(******************************************************************************)\n\ntext {* All session keys in channel messages stem from existing runs. *}\n\ndefinition \n  m2_inv1_keys :: \"m2_state set\"\nwhere \n  \"m2_inv1_keys \\<equiv> {s. \\<forall>R.\n     aKey (sesK (R$sk)) \\<in> atoms (chan s) (* \\<or> sesK (R$sk) \\<in> leak s *) \\<longrightarrow> \n       R \\<in> dom (runs s)\n  }\"\n\nlemmas m2_inv1_keysI = \n  m2_inv1_keys_def [THEN setc_def_to_intro, rule_format]\nlemmas m2_inv1_keysE [elim] = \n  m2_inv1_keys_def [THEN setc_def_to_elim, rule_format]\nlemmas m2_inv1_keysD = \n  m2_inv1_keys_def [THEN setc_def_to_dest, rule_format]\n\n\ntext {* Invariance proof. *}\n\nlemma PO_m2_inv1_keys_init [iff]:\n  \"init m2 \\<subseteq> m2_inv1_keys\"\nby (auto simp add: m2_defs intro!: m2_inv1_keysI)\n\nlemma PO_m2_inv1_keys_trans [iff]:\n  \"{m2_inv1_keys} trans m2 {> m2_inv1_keys}\"\nby (auto simp add: PO_hoare_defs m2_defs intro!: m2_inv1_keysI)\n   (auto simp add: ik0_def dest: m2_inv1_keysD dom_lemmas)\n\nlemma PO_m2_inv1_keys [iff]: \"reach m2 \\<subseteq> m2_inv1_keys\"\nby (rule inv_rule_basic) (auto)\n\n\nsubsubsection {* inv2: Definedness of used keys [UNUSED] *}\n(******************************************************************************)\n\ndefinition \n  m2_inv2_keys_for :: \"m2_state set\"\nwhere \n  \"m2_inv2_keys_for \\<equiv> {s. \\<forall>R.\n     sesK (R$sk) \\<in> keys_for (chan s) \\<longrightarrow> R \\<in> dom (runs s)\n  }\"\n\nlemmas m2_inv2_keys_forI = \n  m2_inv2_keys_for_def [THEN setc_def_to_intro, rule_format]\nlemmas m2_inv2_keys_forE [elim] = \n  m2_inv2_keys_for_def [THEN setc_def_to_elim, rule_format]\nlemmas m2_inv2_keys_forD = \n  m2_inv2_keys_for_def [THEN setc_def_to_dest, rule_format, rotated 1]\n\n\ntext {* Invariance proof. *}\n\nlemma PO_m2_inv2_keys_for_init [iff]:\n  \"init m2 \\<subseteq> m2_inv2_keys_for\"\nby (auto simp add: m2_defs intro!: m2_inv2_keys_forI)\n\nlemma PO_m2_inv2_keys_for_trans [iff]:\n  \"{m2_inv2_keys_for \\<inter> m2_inv1_keys} trans m2 {> m2_inv2_keys_for}\"\napply (auto simp add: PO_hoare_defs m2_defs intro!: m2_inv2_keys_forI) \n-- {* 1 subgoal, from fake *}\napply (auto simp add: keys_for_def ik0_def, erule fake.cases, fastforce+)\ndone\n\nlemma PO_m2_inv2_keys_for [iff]: \"reach m2 \\<subseteq> m2_inv2_keys_for\"\nby (rule inv_rule_incr) (auto del: subsetI)\n\n\ntext {* Useful application of invariant. *}\n\nlemma m2_inv2_keys_for__extr_insert_key:                   (* OBSOLETE?! *)\n  \"\\<lbrakk> R \\<notin> dom (runs s); s \\<in> m2_inv2_keys_for \\<rbrakk>\n \\<Longrightarrow> extr (insert (aKey (sesK (R$sk))) T) (chan s) \n     = insert (aKey (sesK (R$sk))) (extr T (chan s))\"\nby (subgoal_tac \"sesK (R$sk) \\<notin> keys_for (chan s)\") \n   (auto)\n*)\n\nsubsubsection \\<open>inv3a: Session key compromise\\<close>\n(******************************************************************************)\n\ntext \\<open>A L2 version of a session key comprise invariant. Roughly, it states\nthat adding a set of keys @{term KK} to the parameter \\<open>T\\<close> of @{term extr} \ndoes not help the intruder to extract keys other than those in @{term KK} or\nextractable without adding @{term KK}.\n\\<close>\n\ndefinition \n  m2_inv3a_sesK_compr :: \"m2_state set\"\nwhere \n  \"m2_inv3a_sesK_compr \\<equiv> {s. \\<forall>K KK.\n     aKey K \\<in> extr (aKey`KK \\<union> ik0) (chan s) \\<longleftrightarrow> (K \\<in> KK \\<or> aKey K \\<in> extr ik0 (chan s)) \n  }\"\n\nlemmas m2_inv3a_sesK_comprI = \n  m2_inv3a_sesK_compr_def [THEN setc_def_to_intro, rule_format]\nlemmas m2_inv3a_sesK_comprE [elim] = \n  m2_inv3a_sesK_compr_def [THEN setc_def_to_elim, rule_format]\nlemmas m2_inv3a_sesK_comprD = \n  m2_inv3a_sesK_compr_def [THEN setc_def_to_dest, rule_format]\n\ntext \\<open>Additional lemma\\<close>\nlemmas insert_commute_aKey = insert_commute [where x=\"aKey K\" for K] \n\nlemmas m2_inv3a_sesK_compr_simps = \n  m2_inv3a_sesK_comprD\n  m2_inv3a_sesK_comprD [where KK=\"insert Kab KK\" for Kab KK, simplified]\n  m2_inv3a_sesK_comprD [where KK=\"{Kab}\" for Kab, simplified]\n  insert_commute_aKey   \\<comment> \\<open>to get the keys to the front\\<close>\n\nlemma PO_m2_inv3a_sesK_compr_init [iff]:\n  \"init m2 \\<subseteq> m2_inv3a_sesK_compr\"\nby (auto simp add: m2_defs intro!: m2_inv3a_sesK_comprI)\n\nlemma PO_m2_inv3a_sesK_compr_trans [iff]:\n  \"{m2_inv3a_sesK_compr} trans m2 {> m2_inv3a_sesK_compr}\"\nby (auto simp add: PO_hoare_defs m2_defs m2_inv3a_sesK_compr_simps intro!: m2_inv3a_sesK_comprI)\n\nlemma PO_m2_inv3a_sesK_compr [iff]: \"reach m2 \\<subseteq> m2_inv3a_sesK_compr\"\nby (rule inv_rule_basic) (auto) \n\n\nsubsubsection \\<open>inv3: Extracted session keys\\<close>\n(******************************************************************************)\n\ntext \\<open>inv3: Extracted non-leaked session keys were generated by the server \nfor at least one bad agent. This invariant is needed in the proof of the \nstrengthening of the authorization guards in steps 4 and 5 \n(e.g., @{term \"(Kab, A) \\<in> azC (runs s)\"} for the initiator's step4).\\<close>\n\ndefinition \n  m2_inv3_extrKey :: \"m2_state set\"\nwhere\n  \"m2_inv3_extrKey \\<equiv> {s. \\<forall>K.\n     aKey K \\<in> extr ik0 (chan s) \\<longrightarrow>  K \\<notin> leak s \\<longrightarrow> \\<comment> \\<open>was: \\<open>K \\<notin> corrKey \\<longrightarrow>\\<close>\\<close>\n       (\\<exists>R A' B' Ts'. K = sesK (R$sk) \\<and>\n          runs s R = Some (Serv, [A', B'], [aNum Ts']) \\<and> \n                    (A' \\<in> bad \\<or> B' \\<in> bad))\n  }\"\n\nlemmas m2_inv3_extrKeyI = \n  m2_inv3_extrKey_def [THEN setc_def_to_intro, rule_format]\nlemmas m2_inv3_extrKeyE [elim] = \n  m2_inv3_extrKey_def [THEN setc_def_to_elim, rule_format]\nlemmas m2_inv3_extrKeyD = \n  m2_inv3_extrKey_def [THEN setc_def_to_dest, rule_format, rotated 1]\n\nlemma PO_m2_inv3_extrKey_init [iff]:\n  \"init m2 \\<subseteq> m2_inv3_extrKey\"\nby (auto simp add: m2_defs ik0_def intro!: m2_inv3_extrKeyI)\n\nlemma PO_m2_inv3_extrKey_trans [iff]:\n  \"{m2_inv3_extrKey \\<inter> m2_inv3a_sesK_compr} \n      trans m2 \n   {> m2_inv3_extrKey}\"\nproof (simp add: m2_def m2_trans_def, safe)\n  fix Rs A B Kab Ts\n  show\n    \"{m2_inv3_extrKey \\<inter> m2_inv3a_sesK_compr} m2_step3 Rs A B Kab Ts {> m2_inv3_extrKey}\"\n  apply (auto simp add: PO_hoare_defs m2_defs intro!: m2_inv3_extrKeyI)\n  apply (auto simp add: m2_inv3a_sesK_compr_simps \n              dest!: m2_inv3_extrKeyD dest: dom_lemmas)\n  done\nnext\n  fix Ra A B Kab Ts\n  show \n    \"{m2_inv3_extrKey \\<inter> m2_inv3a_sesK_compr} m2_step4 Ra A B Kab Ts {> m2_inv3_extrKey}\"\n  apply (auto simp add: PO_hoare_defs m2_defs intro!: m2_inv3_extrKeyI)\n  apply (auto simp add: dest!: m2_inv3_extrKeyD dest: dom_lemmas) \n  apply (auto intro!: exI)\n  done\nnext \n  fix Rb A B Kab Ts\n  show \n    \"{m2_inv3_extrKey \\<inter> m2_inv3a_sesK_compr} m2_step5 Rb A B Kab Ts {> m2_inv3_extrKey}\"\n  apply (auto simp add: PO_hoare_defs m2_defs intro!: m2_inv3_extrKeyI)\n  apply (auto dest!: m2_inv3_extrKeyD dest: dom_lemmas) \n  apply (auto intro!: exI)\n  done\nnext \n  fix Rs\n  show\n    \"{m2_inv3_extrKey \\<inter> m2_inv3a_sesK_compr} m2_leak Rs {> m2_inv3_extrKey}\"\n  apply (auto simp add: PO_hoare_defs m2_defs intro!: m2_inv3_extrKeyI)\n  apply (auto simp add: m2_inv3a_sesK_compr_simps)\n  done\nqed (auto simp add: PO_hoare_defs m2_defs intro!: m2_inv3_extrKeyI,\n     auto dest!: m2_inv3_extrKeyD dest: dom_lemmas)\n\n\nlemma PO_m2_inv3_extrKey [iff]: \"reach m2 \\<subseteq> m2_inv3_extrKey\"\nby (rule_tac J=\"m2_inv3a_sesK_compr\" in inv_rule_incr) (auto) \n\n\n\nsubsubsection \\<open>inv4: Messages M2a/M2b for good agents and server state\\<close>\n(******************************************************************************)\n\ntext \\<open>inv4: Secure messages to honest agents and server state; one variant \nfor each of M2a and M2b. These invariants establish guard strengthening for\nserver authentication by the initiator and the responder.\\<close>\n\ndefinition \n  m2_inv4_M2a :: \"m2_state set\"\nwhere\n  \"m2_inv4_M2a \\<equiv> {s. \\<forall>A B Kab Ts.\n     Secure Sv A (Msg [aAgt B, aKey Kab, aNum Ts]) \\<in> chan s \\<longrightarrow> A \\<in> good \\<longrightarrow>\n       (\\<exists>Rs. Kab = sesK (Rs$sk) \\<and>\n          runs s Rs = Some (Serv, [A, B], [aNum Ts]))\n  }\"\n\ndefinition \n  m2_inv4_M2b :: \"m2_state set\"\nwhere\n  \"m2_inv4_M2b \\<equiv> {s. \\<forall>A B Kab Ts.\n     Secure Sv B (Msg [aKey Kab, aAgt A, aNum Ts]) \\<in> chan s \\<longrightarrow> B \\<in> good \\<longrightarrow>\n        (\\<exists>Rs. Kab = sesK (Rs$sk) \\<and>\n           runs s Rs = Some (Serv, [A, B], [aNum Ts]))\n  }\"\n\nlemmas m2_inv4_M2aI = \n  m2_inv4_M2a_def [THEN setc_def_to_intro, rule_format]\nlemmas m2_inv4_M2aE [elim] = \n  m2_inv4_M2a_def [THEN setc_def_to_elim, rule_format]\nlemmas m2_inv4_M2aD = \n  m2_inv4_M2a_def [THEN setc_def_to_dest, rule_format, rotated 1]\n\nlemmas m2_inv4_M2bI = m2_inv4_M2b_def [THEN setc_def_to_intro, rule_format]\nlemmas m2_inv4_M2bE [elim] = \n  m2_inv4_M2b_def [THEN setc_def_to_elim, rule_format]\nlemmas m2_inv4_M2bD = \n  m2_inv4_M2b_def [THEN setc_def_to_dest, rule_format, rotated 1]\n\n\ntext \\<open>Invariance proofs.\\<close>\n\nlemma PO_m2_inv4_M2a_init [iff]:\n  \"init m2 \\<subseteq> m2_inv4_M2a\"\nby (auto simp add: m2_defs intro!: m2_inv4_M2aI)\n\nlemma PO_m2_inv4_M2a_trans [iff]:\n  \"{m2_inv4_M2a} trans m2 {> m2_inv4_M2a}\"\napply (auto simp add: PO_hoare_defs m2_defs intro!: m2_inv4_M2aI)\napply (auto dest!: m2_inv4_M2aD dest: dom_lemmas)\n\\<comment> \\<open>3 subgoals\\<close>\napply (force dest!: spec)+\ndone\n\nlemma PO_m2_inv4_M2a [iff]: \"reach m2 \\<subseteq> m2_inv4_M2a\"\nby (rule inv_rule_basic) (auto)\n\n\nlemma PO_m2_inv4_M2b_init [iff]:\n  \"init m2 \\<subseteq> m2_inv4_M2b\"\nby (auto simp add: m2_defs intro!: m2_inv4_M2bI)\n\nlemma PO_m2_inv4_M2b_trans [iff]:\n  \"{m2_inv4_M2b} trans m2 {> m2_inv4_M2b}\"\napply (auto simp add: PO_hoare_defs m2_defs intro!: m2_inv4_M2bI) \napply (auto dest!: m2_inv4_M2bD dest: dom_lemmas)\n\\<comment> \\<open>3 subgoals\\<close>\napply (force dest!: spec)+\ndone\n\nlemma PO_m2_inv4_M2b [iff]: \"reach m2 \\<subseteq> m2_inv4_M2b\"\nby (rule inv_rule_incr) (auto del: subsetI)\n\n\ntext \\<open>Consequence needed in proof of inv8/step5 and inv9/step4: The \nsession key uniquely identifies other fields in M2a and M2b, provided it \nis secret.\\<close>\n\nlemma m2_inv4_M2a_M2b_match:\n  \"\\<lbrakk> Secure Sv A' (Msg [aAgt B', aKey Kab, aNum Ts']) \\<in> chan s; \n     Secure Sv B (Msg [aKey Kab, aAgt A, aNum Ts]) \\<in> chan s; \n     aKey Kab \\<notin> extr ik0 (chan s); s \\<in> m2_inv4_M2a; s \\<in> m2_inv4_M2b \\<rbrakk>\n  \\<Longrightarrow> A = A' \\<and> B = B' \\<and> Ts = Ts'\"\napply (subgoal_tac \"A' \\<notin> bad \\<and> B \\<notin> bad\", auto)\napply (auto dest!: m2_inv4_M2aD m2_inv4_M2bD)\ndone\n\n\ntext \\<open>More consequences of invariants. Needed in ref/step4 and ref/step5 \nrespectively to show the strengthening of the authorization guards.\\<close>\n\nlemma m2_inv34_M2a_authorized:\n  assumes \"Secure Sv A (Msg [aAgt B, aKey K, aNum T]) \\<in> chan s\" \n          \"s \\<in> m2_inv3_extrKey\" \"s \\<in> m2_inv4_M2a\" \"K \\<notin> leak s\"  \n  shows   \"(K, A) \\<in> azC (runs s)\"\nproof (cases \"A \\<in> bad\")\n  case True \n  from assms(1) \\<open>A \\<in> bad\\<close> have \"aKey K \\<in> extr ik0 (chan s)\" by auto\n  with \\<open>s \\<in> m2_inv3_extrKey\\<close> \\<open>K \\<notin> leak s\\<close> show ?thesis by auto \nnext\n  case False \n  with assms show ?thesis by (auto dest: m2_inv4_M2aD) \nqed\n\nlemma m2_inv34_M2b_authorized:\n  assumes \"Secure Sv B (Msg [aKey K, aAgt A, aNum T]) \\<in> chan s\" \n          \"s \\<in> m2_inv3_extrKey\" \"s \\<in> m2_inv4_M2b\" \"K \\<notin> leak s\"  \n  shows  \"(K, B) \\<in> azC (runs s)\"\nproof (cases \"B \\<in> bad\")\n  case True \n  from assms(1) \\<open>B \\<in> bad\\<close> have \"aKey K \\<in> extr ik0 (chan s)\" by auto\n  with \\<open>s \\<in> m2_inv3_extrKey\\<close> \\<open>K \\<notin> leak s\\<close> show ?thesis by auto \nnext\n  case False \n  with assms show ?thesis by (auto dest: m2_inv4_M2bD) \nqed\n\n\nsubsubsection \\<open>inv5: Key secrecy for server\\<close>\n(******************************************************************************)\n\ntext \\<open>inv5: Key secrecy from server perspective. This invariant links the \nabstract notion of key secrecy to the intruder key knowledge.\\<close>\n\ndefinition \n  m2_inv5_ikk_sv :: \"m2_state set\"\nwhere\n  \"m2_inv5_ikk_sv \\<equiv> {s. \\<forall>R A B al.\n     runs s R = Some (Serv, [A, B], al) \\<longrightarrow> A \\<in> good \\<longrightarrow> B \\<in> good \\<longrightarrow>\n     aKey (sesK (R$sk)) \\<in> extr ik0 (chan s) \\<longrightarrow>\n       sesK (R$sk) \\<in> leak s\n  }\"\n\nlemmas m2_inv5_ikk_svI = \n  m2_inv5_ikk_sv_def [THEN setc_def_to_intro, rule_format]\nlemmas m2_inv5_ikk_svE [elim] = \n  m2_inv5_ikk_sv_def [THEN setc_def_to_elim, rule_format]\nlemmas m2_inv5_ikk_svD = \n  m2_inv5_ikk_sv_def [THEN setc_def_to_dest, rule_format, rotated 1]\n\n\ntext \\<open>Invariance proof.\\<close>\n\nlemma PO_m2_inv5_ikk_sv_init [iff]:\n  \"init m2 \\<subseteq> m2_inv5_ikk_sv\"\nby (auto simp add: m2_defs intro!: m2_inv5_ikk_svI)\n\nlemma PO_m2_inv5_ikk_sv_trans [iff]:\n  \"{m2_inv5_ikk_sv \\<inter> m2_inv3a_sesK_compr \\<inter> m2_inv3_extrKey} \n     trans m2 \n   {> m2_inv5_ikk_sv}\"\nby (simp add: PO_hoare_defs m2_defs, safe intro!: m2_inv5_ikk_svI)\n   (auto simp add: m2_inv3a_sesK_compr_simps dest: dom_lemmas)\n\nlemma PO_m2_inv5_ikk_sv [iff]: \"reach m2 \\<subseteq> m2_inv5_ikk_sv\"\nby (rule_tac J=\"m2_inv3_extrKey \\<inter> m2_inv3a_sesK_compr\" in inv_rule_incr) (auto)\n\n\nsubsubsection \\<open>inv6/7: Key secrecy for initiator and responder\\<close>\n(******************************************************************************)\n\ntext \\<open>These invariants are derivable.\\<close>\n\ndefinition \n  m2_inv6_ikk_init :: \"m2_state set\"\nwhere\n  \"m2_inv6_ikk_init \\<equiv> {s. \\<forall>A B Ra K Ts nl.\n     runs s Ra = Some (Init, [A, B], aKey K # aNum Ts # nl) \\<longrightarrow> \n     A \\<in> good \\<longrightarrow> B \\<in> good \\<longrightarrow> aKey K \\<in> extr ik0 (chan s) \\<longrightarrow> \n       K \\<in> leak s\n  }\"\n\nlemmas m2_inv6_ikk_initI = m2_inv6_ikk_init_def [THEN setc_def_to_intro, rule_format]\nlemmas m2_inv6_ikk_initE [elim] = m2_inv6_ikk_init_def [THEN setc_def_to_elim, rule_format]\nlemmas m2_inv6_ikk_initD = m2_inv6_ikk_init_def [THEN setc_def_to_dest, rule_format, rotated 1]\n\n\ndefinition \n  m2_inv7_ikk_resp :: \"m2_state set\"\nwhere\n  \"m2_inv7_ikk_resp \\<equiv> {s. \\<forall>A B Rb K Ts nl.\n     runs s Rb = Some (Resp, [A, B], aKey K # aNum Ts # nl) \\<longrightarrow> \n     A \\<in> good \\<longrightarrow> B \\<in> good \\<longrightarrow> aKey K \\<in> extr ik0 (chan s) \\<longrightarrow>\n       K \\<in> leak s\n  }\"\n\nlemmas m2_inv7_ikk_respI = m2_inv7_ikk_resp_def [THEN setc_def_to_intro, rule_format]\nlemmas m2_inv7_ikk_respE [elim] = m2_inv7_ikk_resp_def [THEN setc_def_to_elim, rule_format]\nlemmas m2_inv7_ikk_respD = m2_inv7_ikk_resp_def [THEN setc_def_to_dest, rule_format, rotated 1]\n\n\n(******************************************************************************)\nsubsection \\<open>Refinement\\<close>\n(******************************************************************************)\n\ntext \\<open>The simulation relation. This is a pure superposition refinement.\\<close>\n\ndefinition\n  R12 :: \"(m1_state \\<times> m2_state) set\" where\n  \"R12 \\<equiv> {(s, t). runs s = runs t \\<and> leak s = leak t \\<and> clk s = clk t}\"\n\ntext \\<open>The mediator function is the identity.\\<close>\n\ndefinition \n  med21 :: \"m2_obs \\<Rightarrow> m1_obs\" where\n  \"med21 = id\"\n\n\ntext \\<open>Refinement proof.\\<close>\n\nlemma PO_m2_step1_refines_m1_step1:\n  \"{R12} \n     (m1_step1 Ra A B), (m2_step1 Ra A B) \n   {> R12}\"\nby (simp add: PO_rhoare_defs R12_def m2_defs, safe, auto)\n\nlemma PO_m2_step2_refines_m1_step2:\n  \"{R12} \n     (m1_step2 Rb A B), (m2_step2 Rb A B)\n   {> R12}\"\nby (simp add: PO_rhoare_defs R12_def m2_defs, safe, auto)\n\nlemma PO_m2_step3_refines_m1_step3:\n  \"{R12} \n     (m1_step3 Rs A B Kab Ts), (m2_step3 Rs A B Kab Ts)\n   {> R12}\"\nby (simp add: PO_rhoare_defs R12_def m2_defs, safe, auto)\n\nlemma PO_m2_step4_refines_m1_step4:\n  \"{R12 \\<inter> UNIV \\<times> (m2_inv4_M2a \\<inter> m2_inv3_extrKey)} \n     (m1_step4 Ra A B Kab Ts), (m2_step4 Ra A B Kab Ts)  \n   {> R12}\"\nby (simp add: PO_rhoare_defs R12_def m2_defs, safe, simp_all)\n   (auto dest: m2_inv34_M2a_authorized)\n\nlemma PO_m2_step5_refines_m1_step5:\n  \"{R12 \\<inter> UNIV \\<times> (m2_inv4_M2b \\<inter> m2_inv3_extrKey)}          \\<comment> \\<open>REMOVED!: \\<open>m2_inv5_ikk_sv\\<close>\\<close>\n     (m1_step5 Rb A B Kab Ts), (m2_step5 Rb A B Kab Ts) \n   {> R12}\"\nby (simp add: PO_rhoare_defs R12_def m2_defs, safe, simp_all)\n   (auto dest: m2_inv34_M2b_authorized)\n\nlemma PO_m2_tick_refines_m1_tick:\n  \"{R12}\n    (m1_tick T), (m2_tick T)\n   {> R12}\"\nby (simp add: PO_rhoare_defs R12_def m2_defs, safe, simp_all)\n\nlemma PO_m2_leak_refines_m1_leak:\n  \"{R12} \n     (m1_leak Rs), (m2_leak Rs)\n   {> R12}\"\nby (simp add: PO_rhoare_defs R12_def m2_defs, safe, auto)\n\nlemma PO_m2_fake_refines_skip:\n  \"{R12} \n     Id, m2_fake\n   {> R12}\"\nby (simp add: PO_rhoare_defs R12_def m2_defs, safe, auto)\n\n\ntext \\<open>All together now...\\<close>\n\nlemmas PO_m2_trans_refines_m1_trans = \n  PO_m2_step1_refines_m1_step1 PO_m2_step2_refines_m1_step2\n  PO_m2_step3_refines_m1_step3 PO_m2_step4_refines_m1_step4\n  PO_m2_step5_refines_m1_step5 PO_m2_tick_refines_m1_tick \n  PO_m2_leak_refines_m1_leak PO_m2_fake_refines_skip \n\nlemma PO_m2_refines_init_m1 [iff]:\n  \"init m2 \\<subseteq> R12``(init m1)\"\nby (auto simp add: R12_def m1_defs m2_loc_defs)\n\nlemma PO_m2_refines_trans_m1 [iff]:\n  \"{R12 \\<inter> \n    UNIV \\<times> (m2_inv4_M2b \\<inter> m2_inv4_M2a \\<inter> m2_inv3_extrKey)} \n     (trans m1), (trans m2) \n   {> R12}\"\nby (auto simp add: m2_def m2_trans_def m1_def m1_trans_def)\n   (blast intro!: PO_m2_trans_refines_m1_trans)+\n\n\nlemma PO_obs_consistent_R12 [iff]: \n  \"obs_consistent R12 med21 m1 m2\"\nby (auto simp add: obs_consistent_def R12_def med21_def m2_defs)\n\n\ntext \\<open>Refinement result.\\<close>\n\nlemma m2_refines_m1 [iff]:\n  \"refines \n     (R12 \\<inter> \n      (UNIV \\<times> (m2_inv4_M2b \\<inter> m2_inv4_M2a \\<inter> m2_inv3_extrKey \\<inter> m2_inv3a_sesK_compr)))\n     med21 m1 m2\"\nby (rule Refinement_using_invariants) (auto)\n\nlemma m2_implements_m1 [iff]:\n  \"implements med21 m1 m2\"\nby (rule refinement_soundness) (auto)\n\n\n(******************************************************************************)\nsubsection \\<open>Inherited and derived invariants\\<close>\n(******************************************************************************)\n(*\ntext {* Show preservation of invariants @{term \"m1_inv2i_serv\"} and\n@{term \"m1_inv2r_serv\"} from @{text \"m1\"}. *}\n\nlemma PO_m2_sat_m1_inv2i_serv [iff]: \"reach m2 \\<subseteq> m1_inv2i_serv\"\nby (rule_tac Pa=m1_inv2i_serv and Qa=m1_inv2i_serv and Q=m1_inv2i_serv \n       in m2_implements_m1 [THEN [5] internal_invariant_translation])\n   (auto simp add: m2_loc_defs med21_def intro!: m1_inv2i_servI)\n\nlemma PO_m2_sat_m1_inv2r_serv [iff]: \"reach m2 \\<subseteq> m1_inv2r_serv\"\nby (rule_tac Pa=m1_inv2r_serv and Qa=m1_inv2r_serv and Q=m1_inv2r_serv\n       in m2_implements_m1 [THEN [5] internal_invariant_translation])\n   (fastforce simp add: m2_loc_defs med21_def intro!: m1_inv2r_servI)+\n\n\ntext {* Now we derive the L2 key secrecy invariants for the initiator \nand the responder (for definition, see above). *}\n\nlemma PO_m2_inv6_init_ikk [iff]: \"reach m2 \\<subseteq> m2_inv6_ikk_init\"\napply (rule_tac B=\" m1_inv2i_serv \\<inter> m2_inv5_ikk_sv\" in subset_trans, auto)\napply (rule m2_inv6_ikk_initI, auto)\napply (blast dest!: m1_inv2i_servD) \ndone\n\nlemma PO_m2_inv6_resp_ikk [iff]: \"reach m2 \\<subseteq> m2_inv7_ikk_resp\"\napply (rule_tac B=\" m1_inv2r_serv \\<inter> m2_inv5_ikk_sv\" in subset_trans, auto)\napply (rule m2_inv7_ikk_respI, auto)\napply (blast dest!: m1_inv2r_servD) \ndone\n*)\n\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Security_Protocol_Refinement/Key_establish/m2_ds.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6370307944803832, "lm_q2_score": 0.46101677931231594, "lm_q1q2_score": 0.29368188519411215}}
{"text": "theory FunctionalImplementation\nimports Initialization SolveLoop\nbegin\n\n(******************************************************************************)\nsubsection{* Total correctness theorem *}\n(******************************************************************************)\n\ntheorem correctness:\nshows \n\"(solve F0 = TRUE \\<and> satisfiable F0) \\<or> (solve F0 = FALSE \\<and> \\<not> satisfiable F0)\"\nproof-\n  let ?istate = \"initialize F0 initialState\"\n  let ?F0' = \"filter (\\<lambda> c. \\<not> clauseTautology c) F0\"\n  have\n  \"InvariantConsistent (getM ?istate)\"\n  \"InvariantUniq (getM ?istate)\"\n  \"InvariantWatchesEl (getF ?istate) (getWatch1 ?istate) (getWatch2 ?istate)\" and \n  \"InvariantWatchesDiffer (getF ?istate) (getWatch1 ?istate) (getWatch2 ?istate)\" and \n  \"InvariantWatchCharacterization (getF ?istate) (getWatch1 ?istate) (getWatch2 ?istate) (getM ?istate)\" and \n  \"InvariantWatchListsContainOnlyClausesFromF (getWatchList ?istate) (getF ?istate)\" and\n  \"InvariantWatchListsUniq (getWatchList ?istate)\" and\n  \"InvariantWatchListsCharacterization (getWatchList ?istate) (getWatch1 ?istate) (getWatch2 ?istate)\" and\n  \"InvariantUniqQ (getQ ?istate)\" and\n  \"InvariantQCharacterization (getConflictFlag ?istate) (getQ ?istate) (getF ?istate) (getM ?istate)\" and\n  \"InvariantConflictFlagCharacterization (getConflictFlag ?istate) (getF ?istate) (getM ?istate)\" and\n  \"InvariantNoDecisionsWhenConflict (getF ?istate) (getM ?istate) (currentLevel (getM ?istate))\" and\n  \"InvariantNoDecisionsWhenUnit (getF ?istate) (getM ?istate) (currentLevel (getM ?istate))\" and\n  \"InvariantGetReasonIsReason (getReason ?istate) (getF ?istate) (getM ?istate) (set (getQ ?istate))\" and\n  \"InvariantConflictClauseCharacterization (getConflictFlag ?istate) (getConflictClause ?istate) (getF ?istate) (getM ?istate)\"\n  \"InvariantVarsM (getM ?istate) F0 (vars F0)\"\n  \"InvariantVarsQ (getQ ?istate) F0 (vars F0)\"\n  \"InvariantVarsF (getF ?istate) F0 (vars F0)\"\n  \"getSATFlag ?istate = UNDEF \\<longrightarrow> InvariantEquivalentZL (getF ?istate) (getM ?istate) ?F0'\" and\n  \"getSATFlag ?istate = FALSE \\<longrightarrow> \\<not> satisfiable ?F0'\"\n  \"getSATFlag ?istate = TRUE  \\<longrightarrow> satisfiable F0\"\n    using assms\n    using InvariantsAfterInitialization[of \"F0\"]\n    using InvariantEquivalentZLAfterInitialization[of \"F0\"]\n    unfolding InvariantVarsM_def\n    unfolding InvariantVarsF_def\n    unfolding InvariantVarsQ_def\n    by (auto simp add: Let_def)\n  moreover\n  hence \"solve_loop_dom ?istate (vars F0)\"\n    using SolveLoopTermination[of \"?istate\" \"?F0'\" \"vars F0\" \"F0\"]\n    using finiteVarsFormula[of \"F0\"]\n    using varsSubsetFormula[of \"?F0'\" \"F0\"]\n    by auto\n  ultimately\n  show ?thesis\n    using finiteVarsFormula[of \"F0\"]\n    using SATFlagAfterSolveLoop[of \"?istate\" \"vars F0\" \"?F0'\" \"F0\"]\n    using satisfiableFilterTautologies[of \"F0\"]\n    unfolding solve_def\n    using varsSubsetFormula[of \"?F0'\" \"F0\"]\n    by (auto simp add: Let_def)\nqed\n\nend", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/SATSolverVerification/FunctionalImplementation.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.4532618480153861, "lm_q1q2_score": 0.2936222174100474}}
{"text": "\nsection \"Algebraic laws for abrupt designs\"\ntheory algebraic_laws_fault\nimports algebraic_laws_fault_aux\n\nbegin\n(*TODO: add laws for assigns when composed with try catch...*)\nsubsection\"Simpset configuration\"\n\ndeclare urel_comp [uflt_comp]\ndeclare urel_cond [uflt_cond]\n\nsubsection\"Skip\"\n\ntext{*In this section we introduce the algebraic laws of programming related to the SKIP\n      statement.*}\n\nlemma true_left_zero_skip_cpf_abr[uflt_comp]:\n  \"(SKIP\\<^sub>F\\<^sub>L\\<^sub>T ;; true) = (true)\"\n  by rel_auto\n\nlemma true_lift_flt_right_zero_skip_flt[uflt_comp]:\n  \"(SKIP\\<^sub>F\\<^sub>L\\<^sub>T ;; \\<lceil>true\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T) = (\\<lceil>true\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T)\"\n  by rel_auto\n\nlemma false_lift_flt_right_zero[uflt_comp]:\n  \"(P ;; \\<lceil>false\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T) = (\\<lceil>false\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T)\"\n  by rel_auto\n\nlemma skip_flt_left_unit_assigns_flt[uflt_comp]:\n  \"(SKIP\\<^sub>F\\<^sub>L\\<^sub>T ;; \\<langle>\\<sigma>\\<rangle>\\<^sub>F\\<^sub>L\\<^sub>T) = (\\<langle>\\<sigma>\\<rangle>\\<^sub>F\\<^sub>L\\<^sub>T)\"\n  by rel_auto\n\nlemma top_flt_right_zero_skip_flt[uflt_comp]:\n  \"(SKIP\\<^sub>F\\<^sub>L\\<^sub>T ;; \\<top>\\<^sub>F\\<^sub>L\\<^sub>T) = (\\<top>\\<^sub>F\\<^sub>L\\<^sub>T)\"\n  by rel_auto\n\nlemma ivar_left_zero_skip_flt[uflt_comp]: \n  \"($x ;; SKIP\\<^sub>F\\<^sub>L\\<^sub>T) = $x\" \n  by rel_auto \n\nlemma top_flt_left_zero_skip_flt[uflt_comp]: \n  \"(\\<top>\\<^sub>F\\<^sub>L\\<^sub>T ;; SKIP\\<^sub>F\\<^sub>L\\<^sub>T) = (\\<top>\\<^sub>F\\<^sub>L\\<^sub>T)\" \n  by rel_auto\n\nlemma skip_flt_idem [uflt_comp]:\n  \"(SKIP\\<^sub>F\\<^sub>L\\<^sub>T ;; SKIP\\<^sub>F\\<^sub>L\\<^sub>T) = SKIP\\<^sub>F\\<^sub>L\\<^sub>T\"\n  by rel_auto\n\nlemma skip_flt_alpha_eq:\n  \"SKIP\\<^sub>F\\<^sub>L\\<^sub>T = Simpl\\<^sub>F\\<^sub>L\\<^sub>T (\\<not>$fault\\<acute> \\<and> ($\\<Sigma>\\<^sub>F\\<^sub>L\\<^sub>T\\<acute> =\\<^sub>u $\\<Sigma>\\<^sub>F\\<^sub>L\\<^sub>T))\"\n  by rel_auto\n\nlemma simpl_pre_skip_flt_post:\n  \"(Simpl\\<^sub>F\\<^sub>L\\<^sub>T \\<lceil>b\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\\<^sub>< \\<and> SKIP\\<^sub>F\\<^sub>L\\<^sub>T) = (SKIP\\<^sub>F\\<^sub>L\\<^sub>T \\<and> Simpl\\<^sub>F\\<^sub>L\\<^sub>T \\<lceil>b\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\\<^sub>>)\"\n  by rel_auto \n\nlemma simpl_pre_skip_flt_var:\n  fixes x :: \"(bool,  ('b) cpf) uvar\"\n  shows \"(Simpl\\<^sub>F\\<^sub>L\\<^sub>T $x \\<and> SKIP\\<^sub>F\\<^sub>L\\<^sub>T) = (SKIP\\<^sub>F\\<^sub>L\\<^sub>T \\<and> Simpl\\<^sub>F\\<^sub>L\\<^sub>T $x\\<acute>)\"\n  by rel_auto\n\nlemma skip_flt_post_left_unit[uflt_comp]:\n  \"(S \\<turnstile> (SKIP\\<^sub>F\\<^sub>L\\<^sub>T;; Q)) = (S \\<turnstile> Q)\"\n  apply pred_simp \n  apply rel_simp\n  apply fastforce\ndone\n\nlemma simpl_flt_post_left_unit[uflt_comp]:\n  \"(S \\<turnstile> (Simpl\\<^sub>F\\<^sub>L\\<^sub>T (\\<not>$fault\\<acute> \\<and> \\<lceil>II\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T);; Q)) = (S \\<turnstile> Q)\"\n  apply pred_simp \n  apply rel_simp\n  apply transfer\n  apply auto\ndone\n\n\nsubsection {*Assignment Laws*}\ntext{*In this section we introduce the algebraic laws of programming related to the assignment\n      statement.*}\n\n\nlemma design_post_seqr_assigns_flt_condr_fault_L6_left[urel_cond]:\n  \"((S \\<turnstile> (\\<langle>a\\<rangle>\\<^sub>F\\<^sub>L\\<^sub>T;; (P \\<triangleleft> $fault \\<triangleright> Q))) \\<triangleleft> \\<not> $fault \\<triangleright> R) = \n   ((S \\<turnstile> (\\<langle>a\\<rangle>\\<^sub>F\\<^sub>L\\<^sub>T;; Q)) \\<triangleleft> \\<not> $fault \\<triangleright> R)\"\n  unfolding assigns_flt_def \n  apply pred_simp \n  apply fastforce\ndone\n\nlemma  design_post_seqr_assigns_flt_condr_not_fault_L6_left[urel_cond]:\n  \"((S \\<turnstile> (\\<langle>a\\<rangle>\\<^sub>F\\<^sub>L\\<^sub>T;; (P \\<triangleleft> \\<not> $fault \\<triangleright> Q))) \\<triangleleft> $fault \\<triangleright> R) = \n   ((S \\<turnstile> (\\<langle>a\\<rangle>\\<^sub>F\\<^sub>L\\<^sub>T;; Q)) \\<triangleleft> $fault \\<triangleright> R)\"\n  unfolding assigns_flt_def \n  apply pred_simp \n  apply rel_simp\n  apply fastforce\ndone\n\nlemma design_post_seqr_assigns_flt_condr_fault_L6_right[urel_cond]:\n  \"(R \\<triangleleft> \\<not> $fault \\<triangleright> (S \\<turnstile> (\\<langle>a\\<rangle>\\<^sub>F\\<^sub>L\\<^sub>T;; (P \\<triangleleft> $fault \\<triangleright> Q)))) = \n   (R \\<triangleleft> \\<not> $fault \\<triangleright> (S \\<turnstile> (\\<langle>a\\<rangle>\\<^sub>F\\<^sub>L\\<^sub>T;; P)))\"\n  unfolding assigns_flt_def \n  apply pred_simp \n  apply rel_simp\n  apply fastforce\ndone\n\nlemma design_post_seqr_assigns_flt_condr_not_fault_L6_right[urel_cond]:\n \"(R \\<triangleleft> $fault \\<triangleright> (S \\<turnstile> (\\<langle>a\\<rangle>\\<^sub>F\\<^sub>L\\<^sub>T;; (P \\<triangleleft> \\<not> $fault \\<triangleright> Q)))) = \n  (R \\<triangleleft> $fault \\<triangleright> (S \\<turnstile> (\\<langle>a\\<rangle>\\<^sub>F\\<^sub>L\\<^sub>T;; P)) )\"\n  apply pred_simp \n  apply rel_simp\n  apply fastforce\ndone\n\nlemma rcond_not_fault_subst_cancel_design_post_right[urel_cond]:\n  \"R \\<triangleleft> \\<not> $fault \\<triangleright> (S \\<turnstile> (\\<langle>a\\<rangle>\\<^sub>F\\<^sub>L\\<^sub>T;; P))  = \n   R \\<triangleleft> \\<not> $fault \\<triangleright> (S \\<turnstile> (\\<lceil>true\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<turnstile> (\\<lceil>II\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<and> $fault\\<acute>) ;; P))\"\n  apply pred_simp \n  apply rel_simp\ndone\n\nlemma usubst_flt_cancel [usubst]: \n  assumes 1:\"weak_lens v\" \n  shows \"($v)\\<lbrakk>\\<lceil>expr\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\\<^sub></$v\\<rbrakk>= \\<lceil>expr\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\\<^sub><\"\n  using 1\n  by  rel_auto\n\nlemma usubst_flt_lift_cancel[usubst]: \n  assumes 1:\"weak_lens v\" \n  shows \"\\<lceil>($v)\\<lbrakk>\\<lceil>expr\\<rceil>\\<^sub></$v\\<rbrakk>\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T= \\<lceil>expr\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\\<^sub><\"\n  using 1\n  by  rel_auto\n\nlemma assigns_flt_id [uflt_simpl]: \n  \"SKIP\\<^sub>F\\<^sub>L\\<^sub>T = \\<langle>id\\<rangle>\\<^sub>F\\<^sub>L\\<^sub>T\"\n  by (rel_auto)\n\nlemma assign_test[uflt_comp]:\n  assumes 1:\"mwb_lens x\" \n  shows     \"(x \\<Midarrow> \\<guillemotleft>u\\<guillemotright> ;; x \\<Midarrow> \\<guillemotleft>v\\<guillemotright>) = (x \\<Midarrow> \\<guillemotleft>v\\<guillemotright>)\"\n  using 1   \n  by (simp add: usubst uflt_comp )\n\nlemma assign_flt_left_comp_subst[uflt_comp]: \n  \"(x \\<Midarrow> u ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T(\\<lceil>P\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<turnstile> \\<lceil>Q\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T)) = Simpl\\<^sub>F\\<^sub>L\\<^sub>T(\\<lceil>P\\<lbrakk>\\<lceil>u\\<rceil>\\<^sub></$x\\<rbrakk>\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<turnstile> \\<lceil>Q\\<lbrakk>\\<lceil>u\\<rceil>\\<^sub></$x\\<rbrakk>\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T)\" \n  by (simp add: uflt_comp usubst)\n\nlemma assign_flt_twice[uflt_comp]: \n  assumes \"mwb_lens x\" and  \"x \\<sharp> f\" \n  shows \"(x \\<Midarrow> e ;; x \\<Midarrow> f) = (x \\<Midarrow> f)\" \n  using assms\n  by (simp add: uflt_comp usubst)\n   \nlemma assign_flt_commute:\n  assumes \"x \\<bowtie> y\" \"x \\<sharp> f\" \"y \\<sharp> e\"\n  shows \"(x \\<Midarrow> e ;; y \\<Midarrow> f) = (y \\<Midarrow> f ;; x \\<Midarrow> e)\"\n  using assms\n  by (simp add: uflt_comp usubst usubst_upd_comm)\n\nlemma assign_flt_cond_flt[uflt_comp]: (*needs more laws to be automatic*)\n  fixes x :: \"('a, '\\<alpha>) uvar\"\n  shows \"(x \\<Midarrow> e ;; (bif b then Simpl\\<^sub>F\\<^sub>L\\<^sub>T P else Simpl\\<^sub>F\\<^sub>L\\<^sub>T Q eif)) = \n         (bif (b\\<lbrakk>e/x\\<rbrakk>) then (x \\<Midarrow> e ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T P)  else (x \\<Midarrow> e ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T Q) eif)\"\n  apply (simp add: usubst uflt_comp)\n  apply rel_auto\ndone\n\nlemma assign_flt_uop1[uflt_comp]: \n  assumes 1: \"mwb_lens v\"\n  shows \"(v \\<Midarrow> e1 ;; v \\<Midarrow> (uop F (&v))) = (v \\<Midarrow> (uop F e1))\"\n  by (simp add: usubst  uflt_comp assms)\n\nlemma assign_flt_bop1[uflt_comp]: \n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\"\n  shows \"(v \\<Midarrow> e1 ;; v \\<Midarrow>(bop bp (&v) e2)) = (v \\<Midarrow> (bop bp e1 e2))\"\n  by (simp add: usubst uflt_comp assms)\n \nlemma assign_flt_bop2[uflt_comp]: \n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\"\n  shows \"(v \\<Midarrow> e1 ;; v \\<Midarrow> (bop bp e2 (&v))) = (v \\<Midarrow> (bop bp e2 e1))\"\n  by (simp add: usubst uflt_comp assms)\n\nlemma assign_flt_trop1[uflt_comp]: \n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\"\n  shows \"(v \\<Midarrow> e1 ;; v \\<Midarrow> (trop tp (&v) e2 e3)) = \n         (v \\<Midarrow> (trop tp e1 e2 e3))\"\n  by (simp add: usubst uflt_comp assms)\n\nlemma assign_flt_trop2[uflt_comp]: \n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\"\n  shows \"(v \\<Midarrow> e1 ;; v \\<Midarrow> (trop tp e2 (&v) e3)) = \n         (v \\<Midarrow> (trop tp e2 e1 e3))\"\n  by (simp add: usubst uflt_comp assms)\n\nlemma assign_flt_trop3[uflt_comp]: \n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\"\n  shows \"(v \\<Midarrow> e1 ;; v \\<Midarrow> (trop tp e2 e3 (&v))) = \n         (v \\<Midarrow> (trop tp e2 e3 e1))\"\n  by (simp add: usubst uflt_comp assms)\n\nlemma assign_flt_qtop1[uflt_comp]: \n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\" and 4:\"v \\<sharp> e4\"\n  shows \"(v \\<Midarrow> e1 ;; v \\<Midarrow> (qtop tp (&v) e2 e3 e4)) = \n         (v \\<Midarrow> (qtop tp e1 e2 e3 e4))\"\n  by (simp add: usubst uflt_comp assms)\n\nlemma assign_flt_qtop2[uflt_comp]: \n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\" and 4:\"v \\<sharp> e4\"\n  shows \"(v \\<Midarrow> e1 ;; v \\<Midarrow> (qtop tp e2 (&v) e3 e4)) = \n         (v \\<Midarrow> (qtop tp e2 e1 e3 e4))\"\n  by (simp add: usubst uflt_comp assms)\n\nlemma assign_flt_qtop3[uflt_comp]: \n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\" and 4:\"v \\<sharp> e4\"\n  shows \"(v \\<Midarrow> e1 ;; v \\<Midarrow> (qtop tp e2 e3 (&v) e4)) = \n         (v \\<Midarrow> (qtop tp e2 e3 e1 e4))\"\n  by (simp add: usubst uflt_comp assms)\n\nlemma assign_flt_qtop4[uflt_comp]: \n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\" and 4:\"v \\<sharp> e4\"\n  shows \"(v \\<Midarrow> e1 ;; v \\<Midarrow> (qtop tp e2 e3 e4 (&v))) = \n         (v \\<Midarrow> (qtop tp e2 e3 e4 e1))\"\n  by (simp add: usubst uflt_comp assms)\n                   \ntext {*In the sequel we define assignment laws proposed by Hoare*}\n\nlemma assign_flt_vwb_skip_flt[uflt_comp]:\n  assumes 1: \"vwb_lens v\"\n  shows \"(v \\<Midarrow> &v) = SKIP\\<^sub>F\\<^sub>L\\<^sub>T\"\n  by (simp add: assms usubst uflt_simpl)\n\nlemma assign_flt_simultaneous:\n  assumes  1: \"vwb_lens var2\"\n  and      2: \"var1 \\<bowtie> var2\"\n  shows \"var1, var2 \\<Midarrow> exp, &var2 = var1 \\<Midarrow> exp\"\n  by (simp add: assms usubst_upd_comm usubst)\n\nlemma assign_flt_seq[uflt_comp]:\n  assumes  1: \"vwb_lens var2\"\n  shows\"(var1 \\<Midarrow> exp);; (var2 \\<Midarrow> &var2) = (var1 \\<Midarrow> exp)\"\n  by (simp add: assms usubst uflt_comp)\n\nlemma assign_flt_cond_flt_uop[uflt_comp]: (*needs more laws to be automatic*)\n  assumes 1: \"weak_lens v\"\n  shows \"bif uop F exp then (v \\<Midarrow> exp ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T C1) else (v \\<Midarrow> exp ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T C2) eif = \n          v \\<Midarrow> exp ;; bif uop F (&v) then Simpl\\<^sub>F\\<^sub>L\\<^sub>T C1 else  Simpl\\<^sub>F\\<^sub>L\\<^sub>T C2 eif\"\n  apply (simp add: assms usubst uflt_comp uflt_simpl )\n  apply pred_simp\n  apply rel_simp\n  apply auto\n  apply (metis assms weak_lens.put_get)+\ndone\n\nlemma assign_flt_cond_bop1[uflt_comp]: (*needs more laws to be automatic*)\n  assumes 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\"\n  shows \"bif bop bp exp exp2 then (v \\<Midarrow> exp ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T C1) else (v \\<Midarrow> exp ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T C2) eif = \n          v \\<Midarrow> exp ;; bif bop bp (&v) exp2 then Simpl\\<^sub>F\\<^sub>L\\<^sub>T C1 else Simpl\\<^sub>F\\<^sub>L\\<^sub>T C2 eif\"\n  apply (simp add: assms usubst uflt_comp uflt_simpl )\n  apply pred_simp\n  apply rel_simp\n  apply auto\n  apply (metis assms unrest_upred.rep_eq weak_lens.put_get)+\ndone\n\nlemma assign_flt_cond_bop2[uflt_comp]: (*needs more laws to be automatic*)\n  assumes 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\"\n  shows \"bif bop bp exp2 exp then (v \\<Midarrow> exp ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T C1) else (v \\<Midarrow> exp ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T C2) eif = \n          v \\<Midarrow> exp ;; bif bop bp  exp2 (&v) then Simpl\\<^sub>F\\<^sub>L\\<^sub>T C1 else Simpl\\<^sub>F\\<^sub>L\\<^sub>T C2 eif\"\n  apply (simp add: assms usubst uflt_comp uflt_simpl )\n  apply pred_simp\n  apply rel_simp\n  apply auto\n  apply (metis assms unrest_upred.rep_eq weak_lens.put_get)+\ndone\n\nlemma assign_flt_cond_trop1[uflt_comp]: (*needs more laws to be automatic*)\n  assumes 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\"\n  shows \"bif trop bp exp exp2 exp3 then (v \\<Midarrow> exp ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T C1) else (v \\<Midarrow> exp ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T C2) eif = \n         v \\<Midarrow> exp ;; bif trop bp (&v) exp2 exp3 then Simpl\\<^sub>F\\<^sub>L\\<^sub>T C1 else Simpl\\<^sub>F\\<^sub>L\\<^sub>T C2 eif\"\n  apply (simp add: assms usubst uflt_comp uflt_simpl )\n  apply pred_simp\n  apply rel_simp\n  apply auto\n  apply (metis assms unrest_upred.rep_eq weak_lens.put_get)+\ndone\n\nlemma assign_flt_cond_trop2[uflt_comp]: (*needs more laws to be automatic*)\n  assumes 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\"\n  shows \"bif trop bp exp2 exp  exp3 then (v \\<Midarrow> exp ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T C1) else (v \\<Midarrow> exp ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T C2) eif = \n         v \\<Midarrow> exp ;; bif trop bp  exp2 (&v) exp3 then Simpl\\<^sub>F\\<^sub>L\\<^sub>T C1 else Simpl\\<^sub>F\\<^sub>L\\<^sub>T C2 eif\"\n  apply (simp add: assms usubst uflt_comp uflt_simpl )\n  apply pred_simp\n  apply rel_simp\n  apply auto\n  apply (metis assms unrest_upred.rep_eq weak_lens.put_get)+\ndone\n\nlemma assign_flt_cond_trop3[uflt_comp]: (*needs more laws to be automatic*)\n  assumes 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\"\n  shows \"bif trop bp exp2 exp3 exp then (v \\<Midarrow> exp ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T C1) else (v \\<Midarrow> exp ;;Simpl\\<^sub>F\\<^sub>L\\<^sub>T C2) eif = \n         v \\<Midarrow> exp ;; bif trop bp exp2 exp3 (&v)  then Simpl\\<^sub>F\\<^sub>L\\<^sub>T C1 else Simpl\\<^sub>F\\<^sub>L\\<^sub>T C2 eif\"\n  apply (simp add: assms usubst uflt_comp uflt_simpl )\n  apply pred_simp\n  apply rel_simp\n  apply auto\n  apply (metis assms unrest_upred.rep_eq weak_lens.put_get)+\ndone\n\nlemma assign_flt_cond_qtop1[uflt_comp]: (*needs more laws to be automatic*)\n  assumes 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\" and 4: \"v \\<sharp> exp4\"\n  shows \"bif qtop bp exp exp2 exp3 exp4 then (v \\<Midarrow> exp ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T C1) else (v \\<Midarrow> exp ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T C2) eif = \n         v \\<Midarrow> exp ;; bif qtop bp (&v) exp2 exp3 exp4 then Simpl\\<^sub>F\\<^sub>L\\<^sub>T C1 else Simpl\\<^sub>F\\<^sub>L\\<^sub>T C2 eif\"\n  apply (simp add: assms usubst uflt_comp uflt_simpl )\n  apply pred_simp\n  apply rel_simp\n  apply auto\n  apply (metis assms unrest_upred.rep_eq weak_lens.put_get)+\ndone\n\nlemma assign_flt_cond_qtop2[uflt_comp]: (*needs more laws to be automatic*)\n  assumes 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\" and 4:\"v \\<sharp> exp4\"\n  shows \"bif qtop bp exp2 exp  exp3 exp4 then (v \\<Midarrow> exp ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T C1) else (v \\<Midarrow> exp ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T C2) eif = \n         v \\<Midarrow> exp ;; bif qtop bp exp2 (&v) exp3 exp4 then Simpl\\<^sub>F\\<^sub>L\\<^sub>T C1 else Simpl\\<^sub>F\\<^sub>L\\<^sub>T C2 eif\"\n  apply (simp add: assms usubst uflt_comp uflt_simpl )\n  apply pred_simp\n  apply rel_simp\n  apply auto\n  apply (metis assms unrest_upred.rep_eq weak_lens.put_get)+\ndone\n\nlemma assign_flt_cond_qtop3[uflt_comp]: (*needs more laws to be automatic*)\n  assumes 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\" and 4: \"v \\<sharp> exp4\"\n  shows \"bif qtop bp exp2 exp3 exp exp4 then (v \\<Midarrow> exp ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T C1) else (v \\<Midarrow> exp ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T C2) eif = \n         v \\<Midarrow> exp ;; bif qtop bp exp2  exp3 (&v) exp4 then Simpl\\<^sub>F\\<^sub>L\\<^sub>T C1 else Simpl\\<^sub>F\\<^sub>L\\<^sub>T C2 eif\"\n  apply (simp add: assms usubst uflt_comp uflt_simpl )\n  apply pred_simp\n  apply rel_simp\n  apply auto\n  apply (metis assms unrest_upred.rep_eq weak_lens.put_get)+\ndone\n\nlemma assign_flt_cond_qtop4[uflt_comp]: (*needs more laws to be automatic*)\n  assumes 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\" and 4: \"v \\<sharp> exp4\"\n  shows \"bif qtop bp exp2 exp3 exp4 exp then (v \\<Midarrow> exp ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T C1) else (v \\<Midarrow> exp ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T C2) eif = \n         v \\<Midarrow> exp ;; bif qtop bp exp2  exp3 exp4 (&v)  then Simpl\\<^sub>F\\<^sub>L\\<^sub>T C1 else Simpl\\<^sub>F\\<^sub>L\\<^sub>T C2 eif\"\n  apply (simp add: assms usubst uflt_comp uflt_simpl)\n  apply pred_simp\n  apply rel_simp\n  apply auto\n  apply (metis assms unrest_upred.rep_eq weak_lens.put_get)+\ndone\n\nlemma assign_flt_cond_If [uflt_cond]: \n  \"(bif bexp then (v \\<Midarrow> exp1) else (v \\<Midarrow> exp2) eif) = \n   (v \\<Midarrow> (exp1 \\<triangleleft> bexp \\<triangleright> exp2))\" \n  by rel_auto\n\nsubsection {*While laws*}\ntext{*In this section we introduce the algebraic laws of programming related to the while\n      statement.*}\n\ntheorem while_unfold:\n  \"while b do P od = (bif b then (P ;; while b do P od) else SKIP\\<^sub>F\\<^sub>L\\<^sub>T eif)\"\nproof -\n  have m:\"mono (\\<lambda>X. bif b then (P ;; X) else SKIP\\<^sub>F\\<^sub>L\\<^sub>T eif)\"\n    by (auto intro: monoI seqr_mono if_mono)\n  have \"(while b do P od) = (\\<nu> X \\<bullet> bif b then (P ;; X) else SKIP\\<^sub>F\\<^sub>L\\<^sub>T eif)\"\n    by (simp add: While_def)\n  also have \"... = (bif b then (P ;; (\\<nu> X \\<bullet> bif b then (P ;; X) else SKIP\\<^sub>F\\<^sub>L\\<^sub>T eif)) else SKIP\\<^sub>F\\<^sub>L\\<^sub>T eif)\"\n    by (subst lfp_unfold,simp_all add:m )\n  also have \"... = (bif b then (P ;; while b do P od) else SKIP\\<^sub>F\\<^sub>L\\<^sub>T eif)\"\n    by (simp add: While_def)\n  finally show ?thesis .\nqed\n\n\n(*lemma while_true:\n  shows \"(while true do P od) = \\<top>\\<^sub>A\\<^sub>B\\<^sub>R\"\n  apply (simp add: While_def alpha)\n  apply (rule antisym)\n  apply (simp_all)\n  apply (rule conjI)\n  apply (rule lfp_lowerbound)\n  apply (simp add: C3_abr_def design_def cond_def)\n  apply rel_auto\n  apply (frule cond_mono)\ndone*)\n\nlemma while_false:\n  shows \"(while false do P od) = SKIP\\<^sub>F\\<^sub>L\\<^sub>T\"\nproof -\n  have \"(while false do P od) = bif false then (P ;; while false do P od) else SKIP\\<^sub>F\\<^sub>L\\<^sub>T eif\" \n    using while_unfold[of _ P] by simp\n  also have \"... = SKIP\\<^sub>F\\<^sub>L\\<^sub>T\" by rel_blast\n  finally show ?thesis . \nqed\n\nlemma while_inv_unfold:\n  \"while b invr p do P od = (bif b then (P ;; while b invr p do P od) else SKIP\\<^sub>F\\<^sub>L\\<^sub>T eif)\"\n  unfolding While_inv_def using while_unfold\n  by auto\n\ntheorem while_bot_unfold:\n  \"while\\<^sub>\\<bottom> b do P od = (bif b then (P ;; while\\<^sub>\\<bottom> b do P od) else SKIP\\<^sub>F\\<^sub>L\\<^sub>T eif)\"\nproof -\n  have m:\"mono (\\<lambda>X. bif b then (P ;; X) else SKIP\\<^sub>F\\<^sub>L\\<^sub>T eif)\"\n    by (auto intro: monoI seqr_mono if_mono)\n  have \"(while\\<^sub>\\<bottom> b do P od) = (\\<mu> X \\<bullet> bif b then (P ;; X) else SKIP\\<^sub>F\\<^sub>L\\<^sub>T eif)\"\n    by (simp add: While_bot_def)\n  also have \"... = (bif b then (P ;; (\\<mu> X \\<bullet> bif b then (P ;; X) else SKIP\\<^sub>F\\<^sub>L\\<^sub>T eif)) else SKIP\\<^sub>F\\<^sub>L\\<^sub>T eif)\"\n    by (subst gfp_unfold, simp_all add: m)\n  also have \"... = (bif b then (P ;; while\\<^sub>\\<bottom> b do P od) else SKIP\\<^sub>F\\<^sub>L\\<^sub>T eif)\"\n    by (simp add: While_bot_def)\n  finally show ?thesis .\nqed\n\ntheorem while_bot_false: \"while\\<^sub>\\<bottom> false do P od = SKIP\\<^sub>F\\<^sub>L\\<^sub>T\"\n  by (simp add: While_bot_def mu_const alpha)\n\ntheorem while_bot_true: \"while\\<^sub>\\<bottom> true do P od = (\\<mu> X \\<bullet> (P ;; X))\"\n  by (simp add: While_bot_def alpha)\n\nsubsection {*assume laws*}\n\nlemma assume_twice[uflt_comp]: \"(b\\<^sup>\\<top>\\<^sup>C ;; c\\<^sup>\\<top>\\<^sup>C) = (b \\<and> c)\\<^sup>\\<top>\\<^sup>C\"\n  apply pred_simp \n  apply auto\n  apply (rel_simp)+\n  apply blast\n  apply (rel_simp)+\n  apply (metis (full_types))\ndone\n\nlemma assert_twice[uflt_comp]: \"(b\\<^sub>\\<bottom>\\<^sub>C ;; c\\<^sub>\\<bottom>\\<^sub>C) = (b \\<and> c)\\<^sub>\\<bottom>\\<^sub>C\" \n  apply pred_simp \n  apply auto\n  apply (rel_simp)+\n  apply blast\n  apply (rel_simp)+\n  apply (metis (full_types))\ndone\n\nsubsection {*Try Catch laws*}\n(*see utp_hoare_helper*)\n\n\nend", "meta": {"author": "git-vt", "repo": "orca", "sha": "92bda0f9cfe5cc680b9c405fc38f07a960087a36", "save_path": "github-repos/isabelle/git-vt-orca", "path": "github-repos/isabelle/git-vt-orca/orca-92bda0f9cfe5cc680b9c405fc38f07a960087a36/Archive/Programming-Languages-Semantics/WP11-C-semantics/src/IMP-Lenses/hoare/AlgebraicLaws/Fault/algebraic_laws_fault.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5736784220301064, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.2935607743132893}}
{"text": "section \\<open> Procedures \\<close>\n\ntheory ITree_Procedure\n  imports ITree_Circus ITree_Hoare\n  keywords \"over\"\nbegin\n\ndatatype (discs_sels) ('inp, 'outp) methop = Call_C 'inp | Return_C 'outp\n\ndefinition [lens_defs]: \"Call = ctor_prism Call_C is_Call_C un_Call_C\"\ndefinition [lens_defs]: \"Return = ctor_prism Return_C (Not \\<circ> is_Call_C) un_Return_C\"\n\nrecord ('val, 'st) valst =\n  vval :: 'val\n  vst  :: 'st\n\ntype_synonym ('e, 'inp, 'outp, 'st) \"procedure\" = \"('e, ('inp, 'st) valst, ('outp, 'st) valst) ktree\"\n\ntranslations\n  (type) \"('e, 'inp, 'outp, 'st) procedure\" <= (type) \"('inp, 'st) valst \\<Rightarrow> ('e, ('outp, 'st') valst) itree\" \n\ndefinition procproc :: \"(_, 'inp, 'outp, 'st::default) procedure \\<Rightarrow> ('inp, 'outp) methop process\" where\n\"procproc P = process [\\<leadsto>] (\\<lambda> s. inp Call \\<bind> (\\<lambda> inp. P \\<lparr> vval = inp, vst = s \\<rparr> \\<bind> (\\<lambda> vst. outp Return (vval vst) \\<bind> Ret)))\"\n\ndefinition promote_proc :: \"('e, 'inp, 'outp, 'ls) procedure \\<Rightarrow> ('i \\<Rightarrow> ('ls \\<Longrightarrow> 's)) \\<Rightarrow> ('e, 'i \\<times> 'inp, 'outp, 's) procedure\" where\n\"promote_proc P a = (\\<lambda> v. P \\<lparr> vval = snd (vval v), vst = get\\<^bsub>a (fst (vval v))\\<^esub> (vst v) \\<rparr> \\<bind> (\\<lambda> v'. Ret \\<lparr> vval = vval v', vst = put\\<^bsub>a (fst (vval v))\\<^esub> (vst v) (vst v')\\<rparr>))\"\n\nlemma Call_wb_prism [simp, code_unfold]: \"wb_prism Call\" by (unfold_locales, auto simp add: lens_defs)\nlemma Return_wb_prism [simp, code_unfold]: \"wb_prism Return\" by (unfold_locales, auto simp add: lens_defs)\n\ndefinition \"proc_ret e = (\\<lambda> s. Ret \\<lparr> vval = e s, vst = s \\<rparr>)\"\n\ndefinition \"procedure\" :: \"('inp \\<Rightarrow> 'st \\<Rightarrow> ('e, ('outp, 'st) valst) itree) \\<Rightarrow> ('e, 'inp, 'outp, 'st) procedure\" where\n\"procedure P = (\\<lambda> vs. P (vval vs) (vst vs))\"\n\ndefinition proc_call :: \"('o \\<Longrightarrow> 's) \\<Rightarrow> ('e, 'i, 'o, 'ls::default) procedure \\<Rightarrow> ('i, 's) expr \\<Rightarrow> ('e, 's) htree\" \n  where \"proc_call x P e = (\\<lambda> s. P \\<lparr> vval = e s, vst = default \\<rparr> \\<bind> (\\<lambda> vs. Ret (put\\<^bsub>x\\<^esub> s (vval vs))))\"\n\ndefinition exec_proc :: \"(unit, 'inp, 'out, 'st::default) procedure \\<Rightarrow> 'inp \\<Rightarrow> (unit, 'out) itree\" where\n\"exec_proc P i = P \\<lparr> vval = i, vst = default \\<rparr> \\<bind> (\\<lambda> x. Ret (vval x))\"\n\nsyntax \n  \"_procedure\" :: \"pttrn \\<Rightarrow> logic \\<Rightarrow> logic\" (\"proc _./ _\" [0, 20] 20)\n  \"_call\" :: \"svid \\<Rightarrow> logic \\<Rightarrow> logic \\<Rightarrow> logic\" (\"_ := call _ _\" [61, 0, 61] 61)\n  \"_return\" :: \"logic \\<Rightarrow> logic\" (\"return\")\n\ntranslations \n  \"_procedure x P\" == \"CONST procedure (\\<lambda> x. P)\"\n  \"_return e\" == \"CONST proc_ret (e)\\<^sub>e\"\n  \"_call x P e\" == \"CONST proc_call x P (e)\\<^sub>e\"\n\nML_file \\<open>ITree_Procedure.ML\\<close>\n\nend", "meta": {"author": "isabelle-utp", "repo": "interaction-trees", "sha": "90510d119364f534d2ab61daf2f274060f0a040e", "save_path": "github-repos/isabelle/isabelle-utp-interaction-trees", "path": "github-repos/isabelle/isabelle-utp-interaction-trees/interaction-trees-90510d119364f534d2ab61daf2f274060f0a040e/UTP/ITree_Procedure.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5736784074525098, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.29356076685369104}}
{"text": "(*  Title:       CoreC++\n    Author:      Daniel Wasserrab\n    Maintainer:  Daniel Wasserrab <wasserra at fmi.uni-passau.de>\n*)\n\nheader {* \\isaheader{Determinism Proof} *}\n\ntheory Determinism\nimports TypeSafe\nbegin\n\nsection{* Some lemmas *}\n\nlemma maps_nth:\n  \"\\<lbrakk>(E(xs [\\<mapsto>] ys)) x = Some y; length xs = length ys; distinct xs\\<rbrakk> \n  \\<Longrightarrow> \\<forall>i. x = xs!i \\<and> i < length xs \\<longrightarrow> y = ys!i\"\nproof (induct xs arbitrary: ys E)\n  case Nil thus ?case by simp\nnext\n  case (Cons x' xs')\n  have map:\"(E(x' # xs' [\\<mapsto>] ys)) x = Some y\"\n    and length:\"length (x'#xs') = length ys\"\n    and dist:\"distinct (x'#xs')\"\n    and IH:\"\\<And>ys E. \\<lbrakk>(E(xs' [\\<mapsto>] ys)) x = Some y; length xs' = length ys; \n                     distinct xs'\\<rbrakk> \n         \\<Longrightarrow> \\<forall>i. x = xs'!i \\<and> i < length xs' \\<longrightarrow> y = ys!i\" by fact+\n  from length obtain y' ys' where ys:\"ys = y'#ys'\" by(cases ys) auto\n  { fix i assume x:\"x = (x'#xs')!i\" and i:\"i < length(x'#xs')\"\n    have \"y = ys!i\"\n    proof(cases i)\n      case 0 with x map ys dist show ?thesis by simp\n    next\n      case (Suc n)\n      with x i have x':\"x = xs'!n\" and n:\"n < length xs'\" by simp_all\n      from map ys have map':\"(E(x' \\<mapsto> y')(xs' [\\<mapsto>] ys')) x = Some y\" by simp\n      from length ys have length':\"length xs' = length ys'\" by simp\n      from dist have dist':\"distinct xs'\" by simp\n      from IH[OF map' length' dist'] \n      have \"\\<forall>i. x = xs'!i \\<and> i < length xs' \\<longrightarrow> y = ys'!i\" .\n      with x' n have \"y = ys'!n\" by simp\n      with ys n Suc show ?thesis by simp\n    qed }\n  thus ?case by simp\nqed\n\n\nlemma nth_maps:\"\\<lbrakk>length pns = length Ts; distinct pns; i < length Ts\\<rbrakk> \n  \\<Longrightarrow> (E(pns [\\<mapsto>] Ts)) (pns!i) = Some (Ts!i)\"\nproof (induct i arbitrary: E pns Ts)\n  case 0\n  have dist:\"distinct pns\" and length:\"length pns = length Ts\"\n    and i_length:\"0 < length Ts\" by fact+\n  from i_length obtain T' Ts' where Ts:\"Ts = T'#Ts'\" by(cases Ts) auto\n  with length obtain p' pns' where \"pns = p'#pns'\" by(cases pns) auto\n  with Ts dist show ?case by simp\nnext\n  case (Suc n)\n  have i_length:\"Suc n < length Ts\" and dist:\"distinct pns\"\n    and length:\"length pns = length Ts\" by fact+\n  from Suc obtain T' Ts' where Ts:\"Ts = T'#Ts'\" by(cases Ts) auto\n  with length obtain p' pns' where pns:\"pns = p'#pns'\" by(cases pns) auto\n  with Ts length dist have length':\"length pns' = length Ts'\" \n    and dist':\"distinct pns'\" and notin:\"p' \\<notin> set pns'\" by simp_all\n  from i_length Ts have n_length:\"n < length Ts'\" by simp\n  with length' dist' have map:\"(E(p' \\<mapsto> T')(pns' [\\<mapsto>] Ts')) (pns'!n) = Some(Ts'!n)\" by fact\n  with notin have \"(E(p' \\<mapsto> T')(pns' [\\<mapsto>] Ts')) p' = Some T'\" by simp\n  with pns Ts map show ?case by simp\nqed\n\nlemma casts_casts_eq_result:\n  fixes s :: state\n  assumes casts:\"P \\<turnstile> T casts v to v'\" and casts':\"P \\<turnstile> T casts v to w'\" \n  and type:\"is_type P T\" and wte:\"P,E \\<turnstile> e :: T'\" and leq:\"P \\<turnstile> T' \\<le> T\"\n  and eval:\"P,E \\<turnstile> \\<langle>e,s\\<rangle> \\<Rightarrow> \\<langle>Val v,(h,l)\\<rangle>\" and sconf:\"P,E \\<turnstile> s \\<surd>\"\n  and wf:\"wf_C_prog P\"\n  shows \"v' = w'\"\nproof(cases \"\\<forall>C. T \\<noteq> Class C\")\n  case True\n  with casts casts' show ?thesis\n    by(auto elim:casts_to.cases)\nnext\n  case False\n  then obtain C where T:\"T = Class C\" by auto\n  with type have \"is_class P C\" by simp\n  with wf T leq have \"T' = NT \\<or> (\\<exists>D. T' = Class D \\<and> P \\<turnstile> Path D to C unique)\"\n    by(simp add:widen_Class)\n  thus ?thesis\n  proof(rule disjE)\n    assume \"T' = NT\"\n    with wf eval sconf wte have \"v = Null\"\n      by(fastforce dest:eval_preserves_type)\n    with casts casts' show ?thesis by(fastforce elim:casts_to.cases)\n  next\n    assume \"\\<exists>D. T' = Class D \\<and> P \\<turnstile> Path D to C unique\"\n    then obtain D where T':\"T' = Class D\" \n      and path_unique:\"P \\<turnstile> Path D to C unique\" by auto\n    with wf eval sconf wte\n    have \"P,E,h \\<turnstile> Val v : T' \\<or> P,E,h \\<turnstile> Val v : NT\"\n      by(fastforce dest:eval_preserves_type)\n    thus ?thesis\n    proof(rule disjE)\n      assume \"P,E,h \\<turnstile> Val v : T'\"\n      with T' obtain a Cs C' S where h:\"h a = Some(C',S)\" and v:\"v = Ref(a,Cs)\"\n        and last:\"last Cs = D\"\n        by(fastforce dest:typeof_Class_Subo)\n      from casts' v last T obtain Cs' Ds where \"P \\<turnstile> Path D to C via Cs'\"\n        and \"Ds = Cs@\\<^sub>pCs'\" and \"w' = Ref(a,Ds)\"\n        by(auto elim:casts_to.cases)\n      with casts T v last path_unique show ?thesis\n        by auto(erule casts_to.cases,auto simp:path_via_def path_unique_def)\n    next\n      assume \"P,E,h \\<turnstile> Val v : NT\"\n      with wf eval sconf wte have \"v = Null\"\n        by(fastforce dest:eval_preserves_type)\n      with casts casts' show ?thesis by(fastforce elim:casts_to.cases)\n    qed\n  qed\nqed\n\nlemma Casts_Casts_eq_result:\n  assumes wf:\"wf_C_prog P\"\n  shows \"\\<lbrakk>P \\<turnstile> Ts Casts vs to vs'; P \\<turnstile> Ts Casts vs to ws'; \\<forall>T \\<in> set Ts. is_type P T;\n          P,E \\<turnstile> es [::] Ts'; P \\<turnstile> Ts' [\\<le>] Ts; P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs,(h,l)\\<rangle>;\n          P,E \\<turnstile> s \\<surd>\\<rbrakk>\n      \\<Longrightarrow> vs' = ws'\"\nproof (induct vs arbitrary: vs' ws' Ts Ts' es s)\n  case Nil thus ?case by (auto elim!:Casts_to.cases)\nnext\n  case (Cons x xs)\n  have CastsCons:\"P \\<turnstile> Ts Casts x # xs to vs'\" \n    and CastsCons':\"P \\<turnstile> Ts Casts x # xs to ws'\"\n    and type:\"\\<forall>T \\<in> set Ts. is_type P T\" \n    and wtes:\"P,E \\<turnstile> es [::] Ts'\" and subs:\"P \\<turnstile> Ts' [\\<le>] Ts\"\n    and evals:\"P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val (x#xs),(h,l)\\<rangle>\"\n    and sconf:\"P,E \\<turnstile> s \\<surd>\"\n    and IH:\"\\<And>vs' ws' Ts Ts' es s. \n    \\<lbrakk>P \\<turnstile> Ts Casts xs to vs'; P \\<turnstile> Ts Casts xs to ws'; \\<forall>T \\<in> set Ts. is_type P T; \n     P,E \\<turnstile> es [::] Ts'; P \\<turnstile> Ts' [\\<le>] Ts; P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val xs,(h,l)\\<rangle>;\n     P,E \\<turnstile> s \\<surd>\\<rbrakk> \n     \\<Longrightarrow> vs' = ws'\" by fact+\n  from CastsCons obtain y ys S Ss where vs':\"vs' = y#ys\" and Ts:\"Ts = S#Ss\"\n    apply -\n    apply(frule length_Casts_vs,cases Ts,auto)\n    apply(frule length_Casts_vs',cases vs',auto)\n    done\n  with CastsCons have casts:\"P \\<turnstile> S casts x to y\" and Casts:\"P \\<turnstile> Ss Casts xs to ys\"\n    by(auto elim:Casts_to.cases)\n  from Ts type have type':\"is_type P S\" and types':\"\\<forall>T \\<in> set Ss. is_type P T\"\n    by auto\n  from Ts CastsCons' obtain z zs where ws':\"ws' = z#zs\"\n    by simp(frule length_Casts_vs',cases ws',auto)\n  with Ts CastsCons' have casts':\"P \\<turnstile> S casts x to z\" \n    and Casts':\"P \\<turnstile> Ss Casts xs to zs\"\n    by(auto elim:Casts_to.cases)\n  from Ts subs obtain U Us where Ts':\"Ts' = U#Us\" and subs':\"P \\<turnstile> Us [\\<le>] Ss\"\n    and sub:\"P \\<turnstile> U \\<le> S\" by(cases Ts',auto simp:fun_of_def)\n  from wtes Ts' obtain e' es' where es:\"es = e'#es'\" and wte':\"P,E \\<turnstile> e' :: U\"\n    and wtes':\"P,E \\<turnstile> es' [::] Us\" by(cases es) auto\n  with evals obtain h' l' where eval:\"P,E \\<turnstile> \\<langle>e',s\\<rangle> \\<Rightarrow> \\<langle>Val x,(h',l')\\<rangle>\"\n    and evals':\"P,E \\<turnstile> \\<langle>es',(h',l')\\<rangle> [\\<Rightarrow>] \\<langle>map Val xs,(h,l)\\<rangle>\"\n    by (auto elim:evals.cases)\n  from wf eval wte' sconf have \"P,E \\<turnstile> (h',l') \\<surd>\" by(rule eval_preserves_sconf)\n  from IH[OF Casts Casts' types' wtes' subs' evals' this] have eq:\"ys = zs\" .\n  from casts casts' type' wte' sub eval sconf wf have \"y = z\"\n    by(rule casts_casts_eq_result)\n  with eq vs' ws' show ?case by simp\nqed\n\n\n\nlemma Casts_conf: assumes wf: \"wf_C_prog P\"\n  shows \"P \\<turnstile> Ts Casts vs to vs' \\<Longrightarrow> \n  (\\<And>es s Ts'. \\<lbrakk> P,E \\<turnstile> es [::] Ts'; P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs,(h,l)\\<rangle>; P,E \\<turnstile> s \\<surd>;\n             P \\<turnstile> Ts' [\\<le>] Ts\\<rbrakk> \\<Longrightarrow> \n     \\<forall>i < length Ts. P,h \\<turnstile> vs'!i :\\<le> Ts!i)\"\nproof(induct rule:Casts_to.induct)\n  case Casts_Nil thus ?case by simp\nnext\n  case (Casts_Cons T v v' Ts vs vs')\n  have casts:\"P \\<turnstile> T casts v to v'\" and wtes:\"P,E \\<turnstile> es [::] Ts'\" \n    and evals:\"P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val (v#vs),(h,l)\\<rangle>\"\n    and subs:\"P \\<turnstile> Ts' [\\<le>] (T#Ts)\" and sconf:\"P,E \\<turnstile> s \\<surd>\"\n    and IH:\"\\<And>es s Ts'.\\<lbrakk>P,E \\<turnstile> es [::] Ts'; P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs,(h,l)\\<rangle>; \n                   P,E \\<turnstile> s \\<surd>; P \\<turnstile> Ts' [\\<le>] Ts\\<rbrakk>\n               \\<Longrightarrow> \\<forall>i<length Ts. P,h \\<turnstile> vs' ! i :\\<le> Ts ! i\" by fact+\n  from subs obtain U Us where Ts':\"Ts' = U#Us\" by(cases Ts') auto\n  with subs have sub':\"P \\<turnstile> U \\<le> T\" and subs':\"P \\<turnstile> Us [\\<le>] Ts\" \n    by (simp_all add:fun_of_def)\n  from wtes Ts' obtain e' es' where es:\"es = e'#es'\" by(cases es) auto\n  with Ts' wtes have wte':\"P,E \\<turnstile> e' :: U\" and wtes':\"P,E \\<turnstile> es' [::] Us\" by auto\n  from es evals obtain s' where eval':\"P,E \\<turnstile> \\<langle>e',s\\<rangle> \\<Rightarrow> \\<langle>Val v,s'\\<rangle>\"\n    and evals':\"P,E \\<turnstile> \\<langle>es',s'\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs,(h,l)\\<rangle>\" \n    by(auto elim:evals.cases)\n  from wf eval' wte' sconf have sconf':\"P,E \\<turnstile> s' \\<surd>\" by(rule eval_preserves_sconf)\n  from evals' have hext:\"hp s' \\<unlhd> h\" by(cases s',auto intro:evals_hext)\n  from wf eval' sconf wte' have \"P,E,(hp s') \\<turnstile> Val v :\\<^bsub>NT\\<^esub> U\"\n    by(rule eval_preserves_type)\n  with hext have wtrt:\"P,E,h \\<turnstile> Val v :\\<^bsub>NT\\<^esub> U\"\n    by(cases U,auto intro:hext_typeof_mono)\n  from casts wtrt sub' have \"P,h \\<turnstile> v' :\\<le> T\"\n  proof(induct rule:casts_to.induct)\n    case (casts_prim T'' v'')\n    have \"\\<forall>C. T'' \\<noteq> Class C\" and \"P,E,h \\<turnstile> Val v'' :\\<^bsub>NT\\<^esub> U\" and \"P \\<turnstile> U \\<le> T''\" by fact+\n    thus ?case by(cases T'') auto\n  next\n    case (casts_null C) thus ?case by simp\n  next\n    case (casts_ref Cs C Cs' Ds a)\n    have path:\"P \\<turnstile> Path last Cs to C via Cs'\"\n      and Ds:\"Ds = Cs @\\<^sub>p Cs'\"\n      and wtref:\"P,E,h \\<turnstile> ref (a, Cs) :\\<^bsub>NT\\<^esub> U\" by fact+\n    from wtref obtain D S where subo:\"Subobjs P D Cs\" and h:\"h a = Some(D,S)\"\n      by(cases U,auto split:split_if_asm)\n    from path Ds have last:\"C = last Ds\"  \n      by(fastforce intro!:appendPath_last Subobjs_nonempty simp:path_via_def)\n    from subo path Ds wf have \"Subobjs P D Ds\"\n      by(fastforce intro:Subobjs_appendPath simp:path_via_def)\n    with last h show ?case by simp\n  qed\n  with IH[OF wtes' evals' sconf' subs'] show ?case\n    by(auto simp:nth_Cons,case_tac i,auto)\nqed\n\n\nlemma map_Val_throw_False:\"map Val vs = map Val ws @ throw ex # es \\<Longrightarrow> False\"\nproof (induct vs arbitrary: ws)\n  case Nil thus ?case by simp\nnext\n  case (Cons v' vs')\n  have eq:\"map Val (v'#vs') = map Val ws @ throw ex # es\"\n    and IH:\"\\<And>ws'. map Val vs' = map Val ws' @ throw ex # es \\<Longrightarrow> False\" by fact+\n  from eq obtain w' ws' where ws:\"ws = w'#ws'\" by(cases ws) auto\n  from eq have \"tl(map Val (v'#vs')) = tl(map Val ws @ throw ex # es)\" by simp\n  hence \"map Val vs' = tl(map Val ws @ throw ex # es)\" by simp\n  with ws have \"map Val vs' = map Val ws' @ throw ex # es\" by simp\n  from IH[OF this] show ?case .\nqed\n\nlemma map_Val_throw_eq:\"map Val vs @ throw ex # es = map Val ws @ throw ex' # es' \n  \\<Longrightarrow> vs = ws \\<and> ex = ex' \\<and> es = es'\"\n  apply(clarsimp simp:append_eq_append_conv2)\n  apply(erule disjE)\n   apply(case_tac us)\n    apply(fastforce elim:map_injective simp:inj_on_def)\n   apply(fastforce dest:map_Val_throw_False)\n  apply(case_tac us)\n   apply(fastforce elim:map_injective simp:inj_on_def)\n  apply(fastforce dest:sym[THEN map_Val_throw_False])\n  done\n\n\nsection {* The proof *}\n\nlemma deterministic_big_step:\nassumes wf:\"wf_C_prog P\"\nshows \"P,E \\<turnstile> \\<langle>e,s\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>1,s\\<^sub>1\\<rangle> \\<Longrightarrow> \n       (\\<And>e\\<^sub>2 s\\<^sub>2 T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s \\<surd>\\<rbrakk> \n       \\<Longrightarrow> e\\<^sub>1 = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2)\"\n  and \"P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>es\\<^sub>1,s\\<^sub>1\\<rangle> \\<Longrightarrow> \n       (\\<And>es\\<^sub>2 s\\<^sub>2 Ts. \\<lbrakk>P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>es\\<^sub>2,s\\<^sub>2\\<rangle>; P,E \\<turnstile> es [::] Ts; P,E \\<turnstile> s \\<surd>\\<rbrakk> \n        \\<Longrightarrow> es\\<^sub>1 = es\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2)\"\nproof (induct rule:eval_evals.inducts)\n  case New thus ?case by(auto elim: eval_cases)\nnext\n  case NewFail thus ?case by(auto elim: eval_cases)\nnext\n  case (StaticUpCast E e s\\<^sub>0 a Cs s\\<^sub>1 C Cs' Ds e\\<^sub>2 s\\<^sub>2)\n  have eval:\"P,E \\<turnstile> \\<langle>\\<lparr>C\\<rparr>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and path_via:\"P \\<turnstile> Path last Cs to C via Cs'\" and Ds:\"Ds = Cs @\\<^sub>p Cs'\" \n    and wt:\"P,E \\<turnstile> \\<lparr>C\\<rparr>e :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>e\\<^sub>2 s\\<^sub>2 T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk> \n            \\<Longrightarrow> ref (a,Cs) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by fact+\n  from wt obtain D where \"class\":\"is_class P C\" and wte:\"P,E \\<turnstile> e :: Class D\"\n    and disj:\"P \\<turnstile> Path D to C unique \\<or> \n              (P \\<turnstile> C \\<preceq>\\<^sup>* D \\<and> (\\<forall>Cs. P \\<turnstile> Path C to D via Cs \\<longrightarrow> Subobjs\\<^sub>R P C Cs))\"\n    by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref (a',Xs),s\\<^sub>2\\<rangle>\" \n      and path_via':\"P \\<turnstile> Path last Xs to C via Xs'\"\n      and ref:\"e\\<^sub>2 = ref (a',Xs@\\<^sub>pXs')\"\n    from IH[OF eval_ref wte sconf] have eq:\"a = a' \\<and> Cs = Xs \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n    with wf eval_ref sconf wte have last:\"last Cs = D\"\n      by(auto dest:eval_preserves_type split:split_if_asm)\n    from disj show \"ref (a,Ds) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\"\n    proof (rule disjE)\n      assume \"P \\<turnstile> Path D to C unique\"\n      with path_via path_via' eq last have \"Cs' = Xs'\"\n        by(fastforce simp add:path_via_def path_unique_def)\n      with eq ref Ds show ?thesis by simp\n    next\n      assume \"P \\<turnstile> C \\<preceq>\\<^sup>* D \\<and> (\\<forall>Cs. P \\<turnstile> Path C to D via Cs  \\<longrightarrow> Subobjs\\<^sub>R P C Cs)\"\n      with \"class\" wf obtain Cs'' where \"P \\<turnstile> Path C to D via Cs''\"\n        by(auto dest:leq_implies_path)\n      with path_via path_via' wf eq last have \"Cs' = Xs'\"\n        by(auto dest:path_via_reverse)\n      with eq ref Ds show ?thesis by simp\n    qed\n  next\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs@C#Xs'),s\\<^sub>2\\<rangle>\"\n      and ref:\"e\\<^sub>2 = ref (a',Xs@[C])\"\n    from IH[OF eval_ref wte sconf] have eq:\"a = a' \\<and> Cs = Xs@C#Xs' \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n    with wf eval_ref sconf wte obtain C' where \n      last:\"last Cs = D\" and \"Subobjs P C' (Xs@C#Xs')\"\n      by(auto dest:eval_preserves_type split:split_if_asm)\n    hence subo:\"Subobjs P C (C#Xs')\" by(fastforce intro:Subobjs_Subobjs)\n    with eq last have leq:\"P \\<turnstile> C \\<preceq>\\<^sup>* D\" by(fastforce dest:Subobjs_subclass)\n    from path_via last have \"P \\<turnstile> D \\<preceq>\\<^sup>* C\"\n      by(auto dest:Subobjs_subclass simp:path_via_def)\n    with leq wf have CeqD:\"C = D\" by(rule subcls_asym2)\n    with last path_via wf have \"Cs' = [D]\" by(fastforce intro:path_via_C)\n    with Ds last have Ds':\"Ds = Cs\" by(simp add:appendPath_def)\n    from subo CeqD last eq wf have \"Xs' = []\" by(auto dest:mdc_eq_last)\n    with eq Ds' ref show \"ref (a,Ds) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_null wte sconf] show \"ref (a,Ds) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix Xs a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<^sub>2\\<rangle>\" and notin:\"C \\<notin> set Xs\"\n      and notleq:\"\\<not> P \\<turnstile> last Xs \\<preceq>\\<^sup>* C\" and throw:\"e\\<^sub>2 = THROW ClassCast\"\n    from IH[OF eval_ref wte sconf] have eq:\"a = a' \\<and> Cs = Xs \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n    with wf eval_ref sconf wte have last:\"last Cs = D\" and notempty:\"Cs \\<noteq> []\"\n      by(auto dest!:eval_preserves_type Subobjs_nonempty split:split_if_asm)\n    from disj have \"C = D\"\n    proof(rule disjE)\n      assume path_unique:\"P \\<turnstile> Path D to C unique\"\n      with last have \"P \\<turnstile> D \\<preceq>\\<^sup>* C\" \n        by(fastforce dest:Subobjs_subclass simp:path_unique_def)\n      with notleq last eq show ?thesis by simp\n    next\n      assume ass:\"P \\<turnstile> C \\<preceq>\\<^sup>* D \\<and> \n                  (\\<forall>Cs. P \\<turnstile> Path C to D via Cs  \\<longrightarrow> Subobjs\\<^sub>R P C Cs)\"\n      with \"class\" wf obtain Cs'' where path_via':\"P \\<turnstile> Path C to D via Cs''\"\n        by(auto dest:leq_implies_path)\n      with path_via wf eq last have \"Cs'' = [D]\"\n        by(fastforce dest:path_via_reverse)\n      with ass path_via' have \"Subobjs\\<^sub>R P C [D]\" by simp\n      thus ?thesis by(fastforce dest:hd_SubobjsR)\n    qed\n    with last notin eq notempty show \"ref (a,Ds) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\"\n      by(fastforce intro:last_in_set)\n  next\n    fix e' assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_throw wte sconf] show \"ref (a,Ds) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nnext\n  case (StaticDownCast E e s\\<^sub>0 a Cs C Cs' s\\<^sub>1 e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>\\<lparr>C\\<rparr>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\" \n    and eval':\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a,Cs@[C]@Cs'),s\\<^sub>1\\<rangle>\"\n    and wt:\"P,E \\<turnstile> \\<lparr>C\\<rparr>e :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>e\\<^sub>2 s\\<^sub>2 T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                      \\<Longrightarrow> ref(a,Cs@[C]@Cs') = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by fact+\n  from wt obtain D where wte:\"P,E \\<turnstile> e :: Class D\"\n    and disj:\"P \\<turnstile> Path D to C unique \\<or> \n              (P \\<turnstile> C \\<preceq>\\<^sup>* D \\<and> (\\<forall>Cs. P \\<turnstile> Path C to D via Cs \\<longrightarrow> Subobjs\\<^sub>R P C Cs))\"\n    by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<^sub>2\\<rangle>\" \n      and path_via:\"P \\<turnstile> Path last Xs to C via Xs'\"\n      and ref:\"e\\<^sub>2 = ref (a',Xs@\\<^sub>pXs')\"\n    from IH[OF eval_ref wte sconf] have eq:\"a = a' \\<and> Cs@[C]@Cs' = Xs \\<and> s\\<^sub>1 = s\\<^sub>2\"\n      by simp\n    with wf eval_ref sconf wte obtain C' where \n      last:\"last(C#Cs') = D\" and \"Subobjs P C' (Cs@[C]@Cs')\"\n      by(auto dest:eval_preserves_type split:split_if_asm)\n    hence \"P \\<turnstile> Path C to D via C#Cs'\" \n      by(fastforce intro:Subobjs_Subobjs simp:path_via_def)\n    with eq last path_via wf have \"Xs' = [C] \\<and> Cs' = [] \\<and> C = D\"\n      apply clarsimp\n      apply(split split_if_asm)\n      by(simp,drule path_via_reverse,simp,simp)+\n    with ref eq show \"ref(a,Cs@[C]) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by(fastforce simp:appendPath_def)\n  next\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs@C#Xs'),s\\<^sub>2\\<rangle>\"\n      and ref:\"e\\<^sub>2 = ref (a',Xs@[C])\"\n    from IH[OF eval_ref wte sconf] have eq:\"a = a' \\<and> Cs@[C]@Cs' = Xs@C#Xs' \\<and> s\\<^sub>1 = s\\<^sub>2\"\n      by simp\n    with wf eval_ref sconf wte obtain C' where \n      last:\"last(C#Xs') = D\" and subo:\"Subobjs P C' (Cs@[C]@Cs')\"\n      by(auto dest:eval_preserves_type split:split_if_asm)\n    from subo wf have notin:\"C \\<notin> set Cs\" by -(rule unique2,simp)\n    from subo wf have \"C \\<notin> set Cs'\"  by -(rule unique1,simp,simp)\n    with notin eq have \"Cs = Xs \\<and> Cs' = Xs'\"\n      by -(rule only_one_append,simp+)\n    with eq ref show \"ref(a,Cs@[C]) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_null wte sconf] show \"ref (a,Cs@[C]) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix Xs a' \n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<^sub>2\\<rangle>\" and notin:\"C \\<notin> set Xs\"\n    from IH[OF eval_ref wte sconf] have \"a = a' \\<and> Cs@[C]@Cs' = Xs \\<and> s\\<^sub>1 = s\\<^sub>2\" \n      by simp\n    with notin show \"ref(a,Cs@[C]) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by fastforce\n  next\n    fix e' assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_throw wte sconf] show \"ref (a,Cs@[C]) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nnext\n  case (StaticCastNull E e s\\<^sub>0 s\\<^sub>1 C e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>\\<lparr>C\\<rparr>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and wt:\"P,E \\<turnstile> \\<lparr>C\\<rparr>e :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>e\\<^sub>2 s\\<^sub>2 T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk> \n                    \\<Longrightarrow> null = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by fact+\n  from wt obtain D where wte:\"P,E \\<turnstile> e :: Class D\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref (a',Xs),s\\<^sub>2\\<rangle>\" \n    from IH[OF eval_ref wte sconf] show \"null = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs@C#Xs'),s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_ref wte sconf] show \"null = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>2\\<rangle>\" and \"e\\<^sub>2 = null\"\n    with IH[OF eval_null wte sconf] show \"null = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix Xs a' \n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_ref wte sconf] show \"null = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix e' assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_throw wte sconf] show \"null = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nnext\n  case (StaticCastFail E e s\\<^sub>0 a Cs s\\<^sub>1 C e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>\\<lparr>C\\<rparr>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and notleq:\"\\<not> P \\<turnstile> last Cs \\<preceq>\\<^sup>* C\" and notin:\"C \\<notin> set Cs\"\n    and wt:\"P,E \\<turnstile> \\<lparr>C\\<rparr>e :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>e\\<^sub>2 s\\<^sub>2 T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk> \n                    \\<Longrightarrow>ref (a, Cs) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by fact+\n  from wt obtain D where wte:\"P,E \\<turnstile> e :: Class D\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref (a',Xs),s\\<^sub>2\\<rangle>\" \n      and path_via:\"P \\<turnstile> Path last Xs to C via Xs'\"\n    from IH[OF eval_ref wte sconf] have eq:\"a = a' \\<and> Cs = Xs \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n    with path_via wf have \"P \\<turnstile> last Cs \\<preceq>\\<^sup>* C\" \n      by(auto dest:Subobjs_subclass simp:path_via_def)\n    with notleq show \"THROW ClassCast = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs@C#Xs'),s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_ref wte sconf] have \"a = a' \\<and> Cs = Xs@C#Xs' \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n    with notin show \"THROW ClassCast = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_null wte sconf] show \"THROW ClassCast = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix Xs a' \n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<^sub>2\\<rangle>\"\n      and throw:\"e\\<^sub>2 = THROW ClassCast\"\n    from IH[OF eval_ref wte sconf] have \"a = a' \\<and> Cs = Xs \\<and> s\\<^sub>1 = s\\<^sub>2\"\n      by simp\n    with throw show \"THROW ClassCast = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix e' assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_throw wte sconf] show \"THROW ClassCast = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed \nnext\n  case (StaticCastThrow E e s\\<^sub>0 e' s\\<^sub>1 C e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>\\<lparr>C\\<rparr>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and wt:\"P,E \\<turnstile> \\<lparr>C\\<rparr>e :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>e\\<^sub>2 s\\<^sub>2 T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                   \\<Longrightarrow> throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by fact+\n  from wt obtain D where wte:\"P,E \\<turnstile> e :: Class D\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref (a',Xs),s\\<^sub>2\\<rangle>\" \n    from IH[OF eval_ref wte sconf] show \" throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs@C#Xs'),s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_ref wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_null wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix Xs a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_ref wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix e'' assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e'',s\\<^sub>2\\<rangle>\"\n      and throw:\"e\\<^sub>2 = throw e''\"\n    from IH[OF eval_throw wte sconf] throw show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nnext\n  case (StaticUpDynCast E e s\\<^sub>0 a Cs s\\<^sub>1 C Cs' Ds e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>Cast C e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and path_via:\"P \\<turnstile> Path last Cs to C via Cs'\" \n    and path_unique:\"P \\<turnstile> Path last Cs to C unique\"\n    and Ds:\"Ds = Cs@\\<^sub>pCs'\" and wt:\"P,E \\<turnstile> Cast C e :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>e\\<^sub>2 s\\<^sub>2 T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> ref(a,Cs) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by fact+\n  from wt obtain D where wte:\"P,E \\<turnstile> e :: Class D\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref (a',Xs),s\\<^sub>2\\<rangle>\" \n      and path_via':\"P \\<turnstile> Path last Xs to C via Xs'\"\n      and ref:\"e\\<^sub>2 = ref (a',Xs@\\<^sub>pXs')\"\n    from IH[OF eval_ref wte sconf] have eq:\"a = a' \\<and> Cs = Xs \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n    with wf eval_ref sconf wte have last:\"last Cs = D\"\n      by(auto dest:eval_preserves_type split:split_if_asm)\n    with path_unique path_via path_via' eq have \"Xs' = Cs'\"\n      by(fastforce simp:path_via_def path_unique_def)\n    with eq Ds ref show \"ref (a, Ds) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs@C#Xs'),s\\<^sub>2\\<rangle>\"\n      and ref:\"e\\<^sub>2 = ref (a',Xs@[C])\"\n    from IH[OF eval_ref wte sconf] have eq:\"a = a' \\<and> Cs = Xs@C#Xs' \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n    with wf eval_ref sconf wte obtain C' where \n      last:\"last Cs = D\" and \"Subobjs P C' (Xs@C#Xs')\"\n      by(auto dest:eval_preserves_type split:split_if_asm)\n    hence \"Subobjs P C (C#Xs')\" by(fastforce intro:Subobjs_Subobjs)\n    with last eq have \"P \\<turnstile> Path C to D via C#Xs'\" \n      by(simp add:path_via_def)\n    with path_via wf last have \"Xs' = [] \\<and> Cs' = [C] \\<and> C = D\" \n      by(fastforce dest:path_via_reverse)\n    with eq Ds ref show \"ref (a, Ds) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by (simp add:appendPath_def)\n  next\n    fix Xs Xs' D' S a' h l\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),(h,l)\\<rangle>\"\n      and h:\"h a' = Some(D',S)\" and path_via':\"P \\<turnstile> Path D' to C via Xs'\"\n      and path_unique':\"P \\<turnstile> Path D' to C unique\" and s2:\"s\\<^sub>2 = (h,l)\"\n      and ref:\"e\\<^sub>2 = ref(a',Xs')\"\n    from IH[OF eval_ref wte sconf] s2 have eq:\"a = a' \\<and> Cs = Xs \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n    with wf eval_ref sconf wte h have \"last Cs = D\"\n      and \"Subobjs P D' Cs\"\n      by(auto dest:eval_preserves_type split:split_if_asm)\n    with path_via wf have \"P \\<turnstile> Path D' to C via Cs@\\<^sub>pCs'\"\n      by(fastforce intro:Subobjs_appendPath appendPath_last[THEN sym] \n                   dest:Subobjs_nonempty simp:path_via_def)\n    with path_via' path_unique' Ds have \"Xs' = Ds\"\n      by(fastforce simp:path_via_def path_unique_def)\n    with eq ref show \"ref (a, Ds) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_null wte sconf] show \"ref (a, Ds) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix Xs D' S a' h l\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),(h,l)\\<rangle>\"\n      and not_unique:\"\\<not> P \\<turnstile> Path last Xs to C unique\" and s2:\"s\\<^sub>2 = (h,l)\"\n    from IH[OF eval_ref wte sconf] s2 have eq:\"a = a' \\<and> Cs = Xs \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n    with path_unique not_unique show \"ref (a, Ds) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix e' assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_throw wte sconf] show \"ref (a, Ds) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nnext\n  case (StaticDownDynCast E e s\\<^sub>0 a Cs C Cs' s\\<^sub>1 e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>Cast C e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and wt:\"P,E \\<turnstile> Cast C e :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>e\\<^sub>2 s\\<^sub>2 T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> ref(a,Cs@[C]@Cs') = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by fact+\n  from wt obtain D where wte:\"P,E \\<turnstile> e :: Class D\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<^sub>2\\<rangle>\" \n      and path_via:\"P \\<turnstile> Path last Xs to C via Xs'\"\n      and ref:\"e\\<^sub>2 = ref (a',Xs@\\<^sub>pXs')\"\n    from IH[OF eval_ref wte sconf] have eq:\"a = a' \\<and> Cs@[C]@Cs' = Xs \\<and> s\\<^sub>1 = s\\<^sub>2\"\n      by simp\n    with wf eval_ref sconf wte obtain C' where \n      last:\"last(C#Cs') = D\" and \"Subobjs P C' (Cs@[C]@Cs')\"\n      by(auto dest:eval_preserves_type split:split_if_asm)\n    hence \"P \\<turnstile> Path C to D via C#Cs'\" \n      by(fastforce intro:Subobjs_Subobjs simp:path_via_def)\n    with eq last path_via wf have \"Xs' = [C] \\<and> Cs' = [] \\<and> C = D\"\n      apply clarsimp\n      apply(split split_if_asm)\n      by(simp,drule path_via_reverse,simp,simp)+\n    with ref eq show \"ref(a,Cs@[C]) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by(fastforce simp:appendPath_def)\n  next\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs@C#Xs'),s\\<^sub>2\\<rangle>\"\n      and ref:\"e\\<^sub>2 = ref (a',Xs@[C])\"\n    from IH[OF eval_ref wte sconf] have eq:\"a = a' \\<and> Cs@[C]@Cs' = Xs@C#Xs' \\<and> s\\<^sub>1 = s\\<^sub>2\"\n      by simp\n    with wf eval_ref sconf wte obtain C' where \n      last:\"last(C#Xs') = D\" and subo:\"Subobjs P C' (Cs@[C]@Cs')\"\n      by(auto dest:eval_preserves_type split:split_if_asm)\n    from subo wf have notin:\"C \\<notin> set Cs\" by -(rule unique2,simp)\n    from subo wf have \"C \\<notin> set Cs'\"  by -(rule unique1,simp,simp)\n    with notin eq have \"Cs = Xs \\<and> Cs' = Xs'\"\n      by -(rule only_one_append,simp+)\n    with eq ref show \"ref(a,Cs@[C]) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix Xs Xs' D' S a' h l\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),(h,l)\\<rangle>\"\n      and h:\"h a' = Some(D',S)\" and path_via:\"P \\<turnstile> Path D' to C via Xs'\"\n      and path_unique:\"P \\<turnstile> Path D' to C unique\" and s2:\"s\\<^sub>2 = (h,l)\"\n      and ref:\"e\\<^sub>2 = ref(a',Xs')\"\n    from IH[OF eval_ref wte sconf] s2 have eq:\"a = a' \\<and> Cs@[C]@Cs' = Xs \\<and> s\\<^sub>1 = s\\<^sub>2\"\n      by simp\n    with wf eval_ref sconf wte h have \"Subobjs P D' (Cs@[C]@Cs')\"\n      by(auto dest:eval_preserves_type split:split_if_asm)\n    hence \"Subobjs P D' (Cs@[C])\" by(fastforce intro:appendSubobj)\n    with path_via path_unique have \"Xs' = Cs@[C]\" \n      by(fastforce simp:path_via_def path_unique_def)\n    with eq ref show \"ref(a,Cs@[C]) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_null wte sconf] show \"ref (a,Cs@[C]) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix Xs D' S a' h l\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),(h,l)\\<rangle>\"\n      and notin:\"C \\<notin> set Xs\" and s2:\"s\\<^sub>2 = (h,l)\"\n    from IH[OF eval_ref wte sconf] s2 have \"a = a' \\<and> Cs@[C]@Cs' = Xs \\<and> s\\<^sub>1 = s\\<^sub>2\"\n      by simp\n    with notin show \"ref (a,Cs@[C]) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by fastforce\n  next\n    fix e' assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_throw wte sconf] show \"ref (a,Cs@[C]) = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nnext\n  case (DynCast E e s\\<^sub>0 a Cs h l D S C Cs' e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>Cast C e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and path_via:\"P \\<turnstile> Path D to C via Cs'\" and path_unique:\"P \\<turnstile> Path D to C unique\"\n    and h:\"h a = Some(D,S)\" and wt:\"P,E \\<turnstile> Cast C e :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>e\\<^sub>2 s\\<^sub>2 T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> ref(a,Cs) = e\\<^sub>2 \\<and> (h,l) = s\\<^sub>2\" by fact+\n  from wt obtain D' where wte:\"P,E \\<turnstile> e :: Class D'\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<^sub>2\\<rangle>\"\n      and path_via':\"P \\<turnstile> Path last Xs to C via Xs'\"\n      and ref:\"e\\<^sub>2 = ref (a',Xs@\\<^sub>pXs')\"\n    from IH[OF eval_ref wte sconf] have eq:\"a = a' \\<and> Cs = Xs \\<and> (h,l) = s\\<^sub>2\" by simp\n    with wf eval_ref sconf wte h have \"last Cs = D'\"\n      and \"Subobjs P D Cs\"\n      by(auto dest:eval_preserves_type split:split_if_asm)\n    with path_via' wf eq have \"P \\<turnstile> Path D to C via Xs@\\<^sub>pXs'\"\n      by(fastforce intro:Subobjs_appendPath appendPath_last[THEN sym] \n                   dest:Subobjs_nonempty simp:path_via_def)\n    with path_via path_unique have \"Cs' = Xs@\\<^sub>pXs'\"\n      by(fastforce simp:path_via_def path_unique_def)\n    with ref eq show \"ref(a,Cs') = e\\<^sub>2 \\<and> (h, l) = s\\<^sub>2\" by simp\n  next\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs@C#Xs'),s\\<^sub>2\\<rangle>\"\n      and ref:\"e\\<^sub>2 = ref (a',Xs@[C])\"\n    from IH[OF eval_ref wte sconf] have eq:\"a = a' \\<and> Cs = Xs@C#Xs' \\<and> (h,l) = s\\<^sub>2\"\n      by simp\n    with wf eval_ref sconf wte h have \"Subobjs P D (Xs@[C]@Xs')\"\n      by(auto dest:eval_preserves_type split:split_if_asm)\n    hence \"Subobjs P D (Xs@[C])\" by(fastforce intro:appendSubobj)\n    with path_via path_unique have \"Cs' = Xs@[C]\" \n      by(fastforce simp:path_via_def path_unique_def)\n    with eq ref show \"ref(a,Cs') = e\\<^sub>2 \\<and> (h, l) = s\\<^sub>2\" by simp\n  next\n    fix Xs Xs' D'' S' a' h' l'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),(h',l')\\<rangle>\"\n      and h':\"h' a' = Some(D'',S')\" and path_via':\"P \\<turnstile> Path D'' to C via Xs'\"\n      and s2:\"s\\<^sub>2 = (h',l')\" and ref:\"e\\<^sub>2 = ref(a',Xs')\"\n    from IH[OF eval_ref wte sconf] have eq:\"a = a' \\<and> Cs = Xs \\<and> h = h' \\<and> l = l'\"\n      by simp\n    with h h' path_via path_via' path_unique s2 ref\n    show \"ref(a,Cs') = e\\<^sub>2 \\<and> (h,l) = s\\<^sub>2\"\n      by(fastforce simp:path_via_def path_unique_def)\n  next\n    assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_null wte sconf] show \"ref(a,Cs') = e\\<^sub>2 \\<and> (h,l) = s\\<^sub>2\" by simp\n  next\n    fix Xs D'' S' a' h' l'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),(h',l')\\<rangle>\"\n      and h':\"h' a' = Some(D'',S')\" and not_unique:\"\\<not> P \\<turnstile> Path D'' to C unique\"\n    from IH[OF eval_ref wte sconf] have eq:\"a = a' \\<and> Cs = Xs \\<and> h = h' \\<and> l = l'\"\n      by simp\n    with h h' path_unique not_unique show \"ref(a,Cs') = e\\<^sub>2 \\<and> (h,l) = s\\<^sub>2\" by simp\n  next\n    fix e' assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_throw wte sconf] show \"ref (a,Cs') = e\\<^sub>2 \\<and> (h,l) = s\\<^sub>2\" by simp\n  qed\nnext\n  case (DynCastNull E e s\\<^sub>0 s\\<^sub>1 C e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>Cast C e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and wt:\"P,E \\<turnstile> Cast C e :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>e\\<^sub>2 s\\<^sub>2 T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk> \n                    \\<Longrightarrow> null = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by fact+\n  from wt obtain D where wte:\"P,E \\<turnstile> e :: Class D\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref (a',Xs),s\\<^sub>2\\<rangle>\" \n    from IH[OF eval_ref wte sconf] show \"null = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs@C#Xs'),s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_ref wte sconf] show \"null = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix Xs Xs' D' S a' h l\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),(h,l)\\<rangle>\"\n    from IH[OF eval_ref wte sconf] show \"null = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>2\\<rangle>\" and \"e\\<^sub>2 = null\"\n    with IH[OF eval_null wte sconf] show \"null = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix Xs D' S a' h l\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),(h,l)\\<rangle>\" and s2:\"s\\<^sub>2 = (h,l)\"\n    from IH[OF eval_ref wte sconf] s2 show \"null = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix e' assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_throw wte sconf] show \"null = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nnext\n  case (DynCastFail E e s\\<^sub>0 a Cs h l D S C e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>Cast C e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and h:\"h a = Some(D,S)\" and not_unique1:\"\\<not> P \\<turnstile> Path D to C unique\"\n    and not_unique2:\"\\<not> P \\<turnstile> Path last Cs to C unique\" and notin:\"C \\<notin> set Cs\"\n    and wt:\"P,E \\<turnstile> Cast C e :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>e\\<^sub>2 s\\<^sub>2 T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                   \\<Longrightarrow> ref (a, Cs) = e\\<^sub>2 \\<and> (h,l) = s\\<^sub>2\" by fact+\n  from wt obtain D' where wte:\"P,E \\<turnstile> e :: Class D'\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<^sub>2\\<rangle>\"\n      and path_unique:\"P \\<turnstile> Path last Xs to C unique\"\n    from IH[OF eval_ref wte sconf] have eq:\"a = a' \\<and> Cs = Xs \\<and> (h,l) = s\\<^sub>2\" by simp\n    with path_unique not_unique2 show \"null = e\\<^sub>2 \\<and> (h,l) = s\\<^sub>2\" by simp\n  next\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs@C#Xs'),s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_ref wte sconf] have eq:\"a = a' \\<and> Cs = Xs@C#Xs' \\<and> (h,l) = s\\<^sub>2\"\n      by simp\n    with notin show \"null = e\\<^sub>2 \\<and> (h,l) = s\\<^sub>2\" by fastforce\n  next\n    fix Xs Xs' D'' S' a' h' l'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),(h',l')\\<rangle>\"\n      and h':\"h' a' = Some(D'',S')\" and path_unique:\"P \\<turnstile> Path D'' to C unique\"\n    from IH[OF eval_ref wte sconf] have \"a = a' \\<and> Cs = Xs \\<and> h = h' \\<and> l = l'\"\n      by simp\n    with h h' not_unique1 path_unique show \"null = e\\<^sub>2 \\<and> (h,l) = s\\<^sub>2\" by simp\n  next\n    assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_null wte sconf] show \"null = e\\<^sub>2 \\<and> (h,l) = s\\<^sub>2\" by simp\n  next\n    fix Xs D'' S' a' h' l'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),(h',l')\\<rangle>\"\n      and null:\"e\\<^sub>2 = null\" and s2:\"s\\<^sub>2 = (h',l')\"\n    from IH[OF eval_ref wte sconf] null s2 show \"null = e\\<^sub>2 \\<and> (h,l) = s\\<^sub>2\" by simp\n  next\n    fix e' assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_throw wte sconf] show \"null = e\\<^sub>2 \\<and> (h,l) = s\\<^sub>2\" by simp\n  qed\nnext\n  case (DynCastThrow E e s\\<^sub>0 e' s\\<^sub>1 C e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>Cast C e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and wt:\"P,E \\<turnstile> Cast C e :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>e\\<^sub>2 s\\<^sub>2 T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                   \\<Longrightarrow> throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by fact+\n  from wt obtain D where wte:\"P,E \\<turnstile> e :: Class D\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref (a',Xs),s\\<^sub>2\\<rangle>\" \n    from IH[OF eval_ref wte sconf] show \" throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix Xs Xs' a'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs@C#Xs'),s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_ref wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix Xs Xs' D'' S' a' h' l'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),(h',l')\\<rangle>\"\n    from IH[OF eval_ref wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_null wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix Xs D'' S' a' h' l'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),(h',l')\\<rangle>\"\n    from IH[OF eval_ref wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix e'' assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e'',s\\<^sub>2\\<rangle>\"\n      and throw:\"e\\<^sub>2 = throw e''\"\n    from IH[OF eval_throw wte sconf] throw show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nnext\n  case Val thus ?case by(auto elim: eval_cases)\nnext\n  case (BinOp E e\\<^sub>1 s\\<^sub>0 v\\<^sub>1 s\\<^sub>1 e\\<^sub>2 v\\<^sub>2 s\\<^sub>2 bop v e\\<^sub>2' s\\<^sub>2' T)\n  have eval:\"P,E \\<turnstile> \\<langle>e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2',s\\<^sub>2'\\<rangle>\"\n    and binop:\"binop (bop, v\\<^sub>1, v\\<^sub>2) = Some v\"\n    and wt:\"P,E \\<turnstile> e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2 :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH1:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e\\<^sub>1 :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                     \\<Longrightarrow> Val v\\<^sub>1 = ei \\<and> s\\<^sub>1 = si\"\n    and IH2:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e\\<^sub>2 :: T; P,E \\<turnstile> s\\<^sub>1 \\<surd>\\<rbrakk>\n                     \\<Longrightarrow> Val v\\<^sub>2 = ei \\<and> s\\<^sub>2 = si\" by fact+\n  from wt obtain T\\<^sub>1 T\\<^sub>2 where wte1:\"P,E \\<turnstile> e\\<^sub>1 :: T\\<^sub>1\" and wte2:\"P,E \\<turnstile> e\\<^sub>2 :: T\\<^sub>2\"\n    by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix s w w\\<^sub>1 w\\<^sub>2\n    assume eval_val1:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w\\<^sub>1,s\\<rangle>\"\n      and eval_val2:\"P,E \\<turnstile> \\<langle>e\\<^sub>2,s\\<rangle> \\<Rightarrow> \\<langle>Val w\\<^sub>2,s\\<^sub>2'\\<rangle>\"\n      and binop':\"binop(bop,w\\<^sub>1,w\\<^sub>2) = Some w\" and e2':\"e\\<^sub>2' = Val w\"\n    from IH1[OF eval_val1 wte1 sconf] have w1:\"v\\<^sub>1 = w\\<^sub>1\" and s:\"s = s\\<^sub>1\" by simp_all\n    with wf eval_val1 wte1 sconf have \"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n    from IH2[OF eval_val2[simplified s] wte2 this] have \"v\\<^sub>2 = w\\<^sub>2\" and s2:\"s\\<^sub>2 = s\\<^sub>2'\"\n      by simp_all\n    with w1 binop binop' have \"w = v\" by simp\n    with e2' s2 show \"Val v = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n  next\n    fix e assume eval_throw:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e,s\\<^sub>2'\\<rangle>\"\n    from IH1[OF eval_throw wte1 sconf] show \"Val v = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n  next\n    fix e s w \n    assume eval_val:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<rangle>\"\n      and eval_throw:\"P,E \\<turnstile> \\<langle>e\\<^sub>2,s\\<rangle> \\<Rightarrow> \\<langle>throw e,s\\<^sub>2'\\<rangle>\"\n    from IH1[OF eval_val wte1 sconf] have s:\"s = s\\<^sub>1\" by simp_all\n    with wf eval_val wte1 sconf have \"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n    from IH2[OF eval_throw[simplified s] wte2 this] show \"Val v = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\"\n      by simp\n  qed\nnext\n  case (BinOpThrow1 E e\\<^sub>1 s\\<^sub>0 e s\\<^sub>1 bop e\\<^sub>2 e\\<^sub>2' s\\<^sub>2 T)\n   have eval:\"P,E \\<turnstile> \\<langle>e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2',s\\<^sub>2\\<rangle>\"\n     and wt:\"P,E \\<turnstile> e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2 :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n     and IH:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e\\<^sub>1 :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                     \\<Longrightarrow> throw e = ei \\<and> s\\<^sub>1 = si\" by fact+\n   from wt obtain T\\<^sub>1 T\\<^sub>2 where wte1:\"P,E \\<turnstile> e\\<^sub>1 :: T\\<^sub>1\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix s w w\\<^sub>1 w\\<^sub>2\n    assume eval_val:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w\\<^sub>1,s\\<rangle>\"\n    from IH[OF eval_val wte1 sconf] show \"throw e = e\\<^sub>2' \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix e' \n    assume eval_throw:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2\\<rangle>\" and throw:\"e\\<^sub>2' = throw e'\"\n    from IH[OF eval_throw wte1 sconf] throw show \"throw e = e\\<^sub>2' \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix e s w \n    assume eval_val:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<rangle>\"\n    from IH[OF eval_val wte1 sconf] show \"throw e = e\\<^sub>2' \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nnext\n  case (BinOpThrow2 E e\\<^sub>1 s\\<^sub>0 v\\<^sub>1 s\\<^sub>1 e\\<^sub>2 e s\\<^sub>2 bop e\\<^sub>2' s\\<^sub>2' T)\n  have eval:\"P,E \\<turnstile> \\<langle>e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2',s\\<^sub>2'\\<rangle>\"\n    and wt:\"P,E \\<turnstile> e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2 :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH1:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e\\<^sub>1 :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> Val v\\<^sub>1 = ei \\<and> s\\<^sub>1 = si\"\n    and IH2:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e\\<^sub>2 :: T; P,E \\<turnstile> s\\<^sub>1 \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> throw e = ei \\<and> s\\<^sub>2 = si\" by fact+\n  from wt obtain T\\<^sub>1 T\\<^sub>2 where wte1:\"P,E \\<turnstile> e\\<^sub>1 :: T\\<^sub>1\" and wte2:\"P,E \\<turnstile> e\\<^sub>2 :: T\\<^sub>2\"\n    by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix s w w\\<^sub>1 w\\<^sub>2\n    assume eval_val1:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w\\<^sub>1,s\\<rangle>\"\n      and eval_val2:\"P,E \\<turnstile> \\<langle>e\\<^sub>2,s\\<rangle> \\<Rightarrow> \\<langle>Val w\\<^sub>2,s\\<^sub>2'\\<rangle>\"\n    from IH1[OF eval_val1 wte1 sconf] have s:\"s = s\\<^sub>1\" by simp_all\n    with wf eval_val1 wte1 sconf have \"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n    from IH2[OF eval_val2[simplified s] wte2 this] show \"throw e = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\"\n      by simp\n  next\n    fix e' \n    assume eval_throw:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2'\\<rangle>\"\n    from IH1[OF eval_throw wte1 sconf] show \"throw e = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n  next\n    fix e' s w \n    assume eval_val:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<rangle>\"\n      and eval_throw:\"P,E \\<turnstile> \\<langle>e\\<^sub>2,s\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2'\\<rangle>\"\n      and throw:\"e\\<^sub>2' = throw e'\"\n    from IH1[OF eval_val wte1 sconf] have s:\"s = s\\<^sub>1\" by simp_all\n    with wf eval_val wte1 sconf have \"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n    from IH2[OF eval_throw[simplified s] wte2 this] throw\n    show \"throw e = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\"\n      by simp\n  qed\nnext\n  case Var thus ?case by(auto elim: eval_cases)    \nnext\n  case (LAss E e s\\<^sub>0 v h l V T v' l' e\\<^sub>2 s\\<^sub>2 T')\n  have eval:\"P,E \\<turnstile> \\<langle>V:=e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and env:\"E V = Some T\" and casts:\"P \\<turnstile> T casts v to v'\" and l':\"l' = l(V \\<mapsto> v')\"\n    and wt:\"P,E \\<turnstile> V:=e :: T'\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>e\\<^sub>2 s\\<^sub>2 T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> Val v = e\\<^sub>2 \\<and> (h,l) = s\\<^sub>2\" by fact+\n  from wt env obtain T'' where wte:\"P,E \\<turnstile> e :: T''\" and leq:\"P \\<turnstile> T'' \\<le> T\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix U h' l'' w w'\n    assume eval_val:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,(h',l'')\\<rangle>\" and env':\"E V = Some U\"\n      and casts':\"P \\<turnstile> U casts w to w'\" and e2:\"e\\<^sub>2 = Val w'\" \n      and s2:\"s\\<^sub>2 = (h',l''(V \\<mapsto> w'))\"\n    from env env' have UeqT:\"U = T\" by simp\n    from IH[OF eval_val wte sconf] have eq:\"v = w \\<and> h = h' \\<and> l = l''\" by simp\n    from sconf env have \"is_type P T\"\n      by(clarsimp simp:sconf_def envconf_def)\n    with casts casts' eq UeqT wte leq eval_val sconf wf have \"v' = w'\"\n      by(auto intro:casts_casts_eq_result)\n    with e2 s2 l' eq show \"Val v' = e\\<^sub>2 \\<and> (h, l') = s\\<^sub>2\" by simp\n  next\n    fix e' assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_throw wte sconf] show \"Val v' = e\\<^sub>2 \\<and> (h, l') = s\\<^sub>2\" by simp\n  qed\nnext\n  case (LAssThrow E e s\\<^sub>0 e' s\\<^sub>1 V e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>V:=e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and wt:\"P,E \\<turnstile> V:=e :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>e\\<^sub>2 s\\<^sub>2 T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by fact+\n  from wt obtain T'' where wte:\"P,E \\<turnstile> e :: T''\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix U h' l'' w w'\n    assume eval_val:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,(h',l'')\\<rangle>\"\n    from IH[OF eval_val wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix ex \n    assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2\\<rangle>\" and e2:\"e\\<^sub>2 = throw ex\"\n    from IH[OF eval_throw wte sconf] e2 show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nnext\n  case (FAcc E e s\\<^sub>0 a Cs' h l D S Ds Cs fs F v e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>e\\<bullet>F{Cs},s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and eval':\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref (a, Cs'),(h,l)\\<rangle>\"\n    and h:\"h a = Some(D,S)\" and Ds:\"Ds = Cs'@\\<^sub>pCs\"\n    and S:\"(Ds,fs) \\<in> S\" and fs:\"fs F = Some v\"\n    and wt:\"P,E \\<turnstile> e\\<bullet>F{Cs} :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>e\\<^sub>2 s\\<^sub>2 T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> ref (a, Cs') = e\\<^sub>2 \\<and> (h,l) = s\\<^sub>2\" by fact+\n  from wt obtain C where wte:\"P,E \\<turnstile> e :: Class C\" by auto\n  from eval_preserves_sconf[OF wf eval' wte sconf] h have oconf:\"P,h \\<turnstile> (D,S) \\<surd>\"\n    by(simp add:sconf_def hconf_def)\n  from eval show ?case\n  proof(rule eval_cases)\n    fix Xs' D' S' a' fs' h' l' v'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs'),(h',l')\\<rangle>\"\n    and h':\"h' a' = Some(D',S')\" and S':\"(Xs'@\\<^sub>pCs,fs') \\<in> S'\"\n    and fs':\"fs' F = Some v'\" and e2:\"e\\<^sub>2 = Val v'\" and s2:\"s\\<^sub>2 = (h',l')\"\n    from IH[OF eval_ref wte sconf] h h'\n    have eq:\"a = a' \\<and> Cs' = Xs' \\<and> h = h' \\<and> l = l' \\<and> D = D' \\<and> S = S'\" by simp\n    with oconf S S' Ds have \"fs = fs'\" by (auto simp:oconf_def)\n    with fs fs' have \"v = v'\" by simp\n    with e2 s2 eq show \"Val v = e\\<^sub>2 \\<and> (h,l) = s\\<^sub>2\" by simp\n  next\n    assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_null wte sconf] show \"Val v = e\\<^sub>2 \\<and> (h,l) = s\\<^sub>2\" by simp\n  next\n    fix e' assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_throw wte sconf] show \"Val v = e\\<^sub>2 \\<and> (h,l) = s\\<^sub>2\" by simp\n  qed\nnext\n  case (FAccNull E e s\\<^sub>0 s\\<^sub>1 F Cs e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>e\\<bullet>F{Cs},s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and wt:\"P,E \\<turnstile> e\\<bullet>F{Cs} :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>e\\<^sub>2 s\\<^sub>2 T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk> \n                    \\<Longrightarrow> null = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by fact+\n  from wt obtain C where wte:\"P,E \\<turnstile> e :: Class C\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix Xs' D' S' a' fs' h' l' v'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs'),(h',l')\\<rangle>\"\n    from IH[OF eval_ref wte sconf] show \"THROW NullPointer = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>2\\<rangle>\" and e2:\"e\\<^sub>2 = THROW NullPointer\"\n    from IH[OF eval_null wte sconf] e2 show \"THROW NullPointer = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" \n      by simp\n  next\n    fix e' assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw e',s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_throw wte sconf] show \"THROW NullPointer = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nnext\n  case (FAccThrow E e s\\<^sub>0 e' s\\<^sub>1 F Cs e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>e\\<bullet>F{Cs},s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and wt:\"P,E \\<turnstile> e\\<bullet>F{Cs} :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>e\\<^sub>2 s\\<^sub>2 T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by fact+\n  from wt obtain C where wte:\"P,E \\<turnstile> e :: Class C\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix Xs' D' S' a' fs' h' l' v'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs'),(h',l')\\<rangle>\"\n    from IH[OF eval_ref wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_null wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix ex \n    assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2\\<rangle>\" and e2:\"e\\<^sub>2 = throw ex\"\n    from IH[OF eval_throw wte sconf] e2 show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nnext\n  case (FAss E e\\<^sub>1 s\\<^sub>0 a Cs' s\\<^sub>1 e\\<^sub>2 v h\\<^sub>2 l\\<^sub>2 D S F T Cs v' Ds fs fs' S' h\\<^sub>2' e\\<^sub>2' s\\<^sub>2 T')\n  have eval:\"P,E \\<turnstile> \\<langle>e\\<^sub>1\\<bullet>F{Cs} := e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2',s\\<^sub>2\\<rangle>\"\n    and eval':\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a,Cs'),s\\<^sub>1\\<rangle>\"\n    and eval'':\"P,E \\<turnstile> \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>Val v,(h\\<^sub>2,l\\<^sub>2)\\<rangle>\"\n    and h2:\"h\\<^sub>2 a = Some(D, S)\"\n    and has_least:\"P \\<turnstile> last Cs' has least F:T via Cs\"\n    and casts:\"P \\<turnstile> T casts v to v'\" and Ds:\"Ds = Cs'@\\<^sub>pCs\"\n    and S:\"(Ds, fs) \\<in> S\" and fs':\"fs' = fs(F \\<mapsto> v')\"\n    and S':\"S' = S - {(Ds, fs)} \\<union> {(Ds, fs')}\"\n    and h2':\"h\\<^sub>2' = h\\<^sub>2(a \\<mapsto> (D, S'))\"\n    and wt:\"P,E \\<turnstile> e\\<^sub>1\\<bullet>F{Cs} := e\\<^sub>2 :: T'\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH1:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e\\<^sub>1 :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                     \\<Longrightarrow> ref(a,Cs') = ei \\<and> s\\<^sub>1 = si\"\n    and IH2:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e\\<^sub>2 :: T; P,E \\<turnstile> s\\<^sub>1 \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> Val v = ei \\<and> (h\\<^sub>2,l\\<^sub>2) = si\" by fact+\n  from wt obtain C T'' where wte1:\"P,E \\<turnstile> e\\<^sub>1 :: Class C\" \n    and has_least':\"P \\<turnstile> C has least F:T' via Cs\"\n    and wte2:\"P,E \\<turnstile> e\\<^sub>2 :: T''\" and leq:\"P \\<turnstile> T'' \\<le> T'\"\n    by auto\n  from wf eval' wte1 sconf have \"last Cs' = C\"\n    by(auto dest!:eval_preserves_type split:split_if_asm)\n  with has_least has_least' have TeqT':\"T = T'\" by (fastforce intro:sees_field_fun)\n  from eval show ?case\n  proof(rule eval_cases)\n    fix Xs D' S'' U a' fs'' h l s w w'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<rangle>\"\n      and eval_val:\"P,E \\<turnstile> \\<langle>e\\<^sub>2,s\\<rangle> \\<Rightarrow> \\<langle>Val w,(h,l)\\<rangle>\"\n      and h:\"h a' = Some(D',S'')\"\n      and has_least'':\"P \\<turnstile> last Xs has least F:U via Cs\"\n      and casts':\"P \\<turnstile> U casts w to w'\"\n      and S'':\"(Xs@\\<^sub>pCs,fs'') \\<in> S''\" and e2':\"e\\<^sub>2' = Val w'\"\n      and s2:\"s\\<^sub>2 = (h(a'\\<mapsto>(D',insert (Xs@\\<^sub>pCs,fs''(F \\<mapsto> w')) \n                                     (S''-{(Xs@\\<^sub>pCs,fs'')}))),l)\"\n    from IH1[OF eval_ref wte1 sconf] have eq:\"a = a' \\<and> Cs' = Xs \\<and> s\\<^sub>1 = s\" by simp\n    with wf eval_ref wte1 sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n    from IH2[OF _ wte2 this] eval_val eq have eq':\"v = w \\<and> h = h\\<^sub>2 \\<and> l = l\\<^sub>2\" by auto\n    from has_least'' eq has_least have UeqT:\"U = T\" by (fastforce intro:sees_field_fun)\n    from has_least wf have \"is_type P T\" by(rule least_field_is_type)\n    with casts casts' eq eq' UeqT TeqT' wte2 leq eval_val sconf' wf have v':\"v' = w'\"\n      by(auto intro!:casts_casts_eq_result)\n    from eval_preserves_sconf[OF wf eval'' wte2 sconf'] h2\n    have oconf:\"P,h\\<^sub>2 \\<turnstile> (D,S) \\<surd>\"\n      by(simp add:sconf_def hconf_def)\n    from eq eq' h2 h have \"S = S''\" by simp\n    with oconf eq S S' S'' Ds have \"fs = fs''\" by (auto simp:oconf_def)\n    with h2' h h2 eq eq' s2 S' Ds fs' v' e2' show \"Val v' = e\\<^sub>2' \\<and> (h\\<^sub>2',l\\<^sub>2) = s\\<^sub>2\"\n      by simp\n  next\n    fix s w assume eval_null:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<rangle>\"\n    from IH1[OF eval_null wte1 sconf] show \"Val v' = e\\<^sub>2' \\<and> (h\\<^sub>2',l\\<^sub>2) = s\\<^sub>2\" by simp\n  next\n    fix ex assume eval_throw:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2\\<rangle>\"\n    from IH1[OF eval_throw wte1 sconf] show \"Val v' = e\\<^sub>2' \\<and> (h\\<^sub>2',l\\<^sub>2) = s\\<^sub>2\" by simp\n  next\n    fix ex s w\n    assume eval_val:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<rangle>\" \n      and eval_throw:\"P,E \\<turnstile> \\<langle>e\\<^sub>2,s\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2\\<rangle>\"\n    from IH1[OF eval_val wte1 sconf] have eq:\"s = s\\<^sub>1\" by simp\n    with wf eval_val wte1 sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n    from IH2[OF eval_throw[simplified eq] wte2 this]\n    show \"Val v' = e\\<^sub>2' \\<and> (h\\<^sub>2',l\\<^sub>2) = s\\<^sub>2\" by simp\n  qed\nnext\n  case (FAssNull E e\\<^sub>1 s\\<^sub>0 s\\<^sub>1 e\\<^sub>2 v s\\<^sub>2 F Cs e\\<^sub>2' s\\<^sub>2' T)\n  have eval:\"P,E \\<turnstile> \\<langle>e\\<^sub>1\\<bullet>F{Cs} := e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2',s\\<^sub>2'\\<rangle>\"\n    and wt:\"P,E \\<turnstile> e\\<^sub>1\\<bullet>F{Cs} := e\\<^sub>2 :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH1:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e\\<^sub>1 :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                     \\<Longrightarrow> null = ei \\<and> s\\<^sub>1 = si\"\n    and IH2:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e\\<^sub>2 :: T; P,E \\<turnstile> s\\<^sub>1 \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> Val v = ei \\<and> s\\<^sub>2 = si\" by fact+\n  from wt obtain C T'' where wte1:\"P,E \\<turnstile> e\\<^sub>1 :: Class C\" \n    and wte2:\"P,E \\<turnstile> e\\<^sub>2 :: T''\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix Xs D' S'' U a' fs'' h l s w w'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<rangle>\"\n    from IH1[OF eval_ref wte1 sconf] show \"THROW NullPointer = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\"\n      by simp\n  next\n    fix s w \n    assume eval_null:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<rangle>\"\n      and eval_val:\"P,E \\<turnstile> \\<langle>e\\<^sub>2,s\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<^sub>2'\\<rangle>\"\n      and e2':\"e\\<^sub>2' = THROW NullPointer\"\n    from IH1[OF eval_null wte1 sconf] have eq:\"s = s\\<^sub>1\" by simp\n    with wf eval_null wte1 sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n    from IH2[OF eval_val[simplified eq] wte2 this] e2'\n    show \"THROW NullPointer = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n  next\n    fix ex assume eval_throw:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2'\\<rangle>\"\n    from IH1[OF eval_throw wte1 sconf] show \"THROW NullPointer = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\" \n      by simp\n  next\n    fix ex s w\n    assume eval_val:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<rangle>\"\n      and eval_throw:\"P,E \\<turnstile> \\<langle>e\\<^sub>2,s\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2'\\<rangle>\"\n    from IH1[OF eval_val wte1 sconf] have eq:\"s = s\\<^sub>1\" by simp\n    with wf eval_val wte1 sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n    from IH2[OF eval_throw[simplified eq] wte2 this] \n    show \"THROW NullPointer = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n  qed\nnext\n  case (FAssThrow1 E e\\<^sub>1 s\\<^sub>0 e' s\\<^sub>1 F Cs e\\<^sub>2 e\\<^sub>2' s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>e\\<^sub>1\\<bullet>F{Cs} := e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2',s\\<^sub>2\\<rangle>\" \n    and wt:\"P,E \\<turnstile> e\\<^sub>1\\<bullet>F{Cs} := e\\<^sub>2 :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e\\<^sub>1 :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> throw e' = ei \\<and> s\\<^sub>1 = si\" by fact+\n  from wt obtain C T'' where wte1:\"P,E \\<turnstile> e\\<^sub>1 :: Class C\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix Xs D' S'' U a' fs'' h l s w w'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<rangle>\"\n    from IH[OF eval_ref wte1 sconf] show \"throw e' = e\\<^sub>2' \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix s w \n    assume eval_null:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<rangle>\"\n    from IH[OF eval_null wte1 sconf] show \"throw e' = e\\<^sub>2' \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix ex\n    assume eval_throw:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2\\<rangle>\" and e2':\"e\\<^sub>2' = throw ex\"\n    from IH[OF eval_throw wte1 sconf] e2' show \"throw e' = e\\<^sub>2' \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix ex s w assume eval_val:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<rangle>\"\n    from IH[OF eval_val wte1 sconf] show \"throw e' = e\\<^sub>2' \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nnext\n  case (FAssThrow2 E e\\<^sub>1 s\\<^sub>0 v s\\<^sub>1 e\\<^sub>2 e' s\\<^sub>2 F Cs e\\<^sub>2' s\\<^sub>2' T)\n  have eval:\"P,E \\<turnstile> \\<langle>e\\<^sub>1\\<bullet>F{Cs} := e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2',s\\<^sub>2'\\<rangle>\" \n    and wt:\"P,E \\<turnstile> e\\<^sub>1\\<bullet>F{Cs} := e\\<^sub>2 :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH1:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e\\<^sub>1 :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> Val v = ei \\<and> s\\<^sub>1 = si\"\n    and IH2:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e\\<^sub>2 :: T; P,E \\<turnstile> s\\<^sub>1 \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> throw e' = ei \\<and> s\\<^sub>2 = si\" by fact+\n  from wt obtain C T'' where wte1:\"P,E \\<turnstile> e\\<^sub>1 :: Class C\" \n    and wte2:\"P,E \\<turnstile> e\\<^sub>2 :: T''\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix Xs D' S'' U a' fs'' h l s w w'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<rangle>\"\n      and eval_val:\"P,E \\<turnstile> \\<langle>e\\<^sub>2,s\\<rangle> \\<Rightarrow> \\<langle>Val w,(h,l)\\<rangle>\"\n    from IH1[OF eval_ref wte1 sconf] have eq:\"s = s\\<^sub>1\" by simp\n    with wf eval_ref wte1 sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n    from IH2[OF eval_val[simplified eq] wte2 this] show \"throw e' = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\"\n      by simp\n  next\n    fix s w \n    assume eval_null:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<rangle>\"\n      and eval_val:\"P,E \\<turnstile> \\<langle>e\\<^sub>2,s\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<^sub>2'\\<rangle>\"\n    from IH1[OF eval_null wte1 sconf] have eq:\"s = s\\<^sub>1\" by simp\n    with wf eval_null wte1 sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n    from IH2[OF eval_val[simplified eq] wte2 this] show \"throw e' = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\"\n      by simp\n  next\n    fix ex assume eval_throw:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2'\\<rangle>\"\n    from IH1[OF eval_throw wte1 sconf] show \"throw e' = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n  next\n    fix ex s w\n    assume eval_val:\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<rangle>\"\n      and eval_throw:\"P,E \\<turnstile> \\<langle>e\\<^sub>2,s\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2'\\<rangle>\" and e2':\"e\\<^sub>2' = throw ex\"\n    from IH1[OF eval_val wte1 sconf] have eq:\"s = s\\<^sub>1\" by simp\n    with wf eval_val wte1 sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n    from IH2[OF eval_throw[simplified eq] wte2 this] e2' \n    show \"throw e' = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n  qed\nnext\n  case (CallObjThrow E e s\\<^sub>0 e' s\\<^sub>1 Copt M es e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>Call e Copt M es,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and wt:\"P,E \\<turnstile> Call e Copt M es :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>e\\<^sub>2 s\\<^sub>2 T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by fact+\n  from wt obtain C where wte:\"P,E \\<turnstile> e :: Class C\" by(cases Copt)auto\n  show ?case\n  proof(cases Copt)\n    assume \"Copt = None\"\n    with eval have \"P,E \\<turnstile> \\<langle>e\\<bullet>M(es),s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\" by simp\n    thus ?thesis\n    proof(rule eval_cases)\n      fix ex\n      assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2\\<rangle>\" and e2:\"e\\<^sub>2 = throw ex\"\n      from IH[OF eval_throw wte sconf] e2 show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n    next\n      fix es' ex' s w ws assume eval_val:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<rangle>\"\n      from IH[OF eval_val wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n    next\n      fix C' Xs Xs' Ds' S' U U' Us Us' a' body'' body''' h h' l l' pns'' pns''' \n          s ws ws'\n      assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<rangle>\"\n      from IH[OF eval_ref wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n    next\n      fix s ws\n      assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<rangle>\"\n      from IH[OF eval_null wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n    qed\n  next\n    fix C' assume \"Copt = Some C'\"\n    with eval have \"P,E \\<turnstile> \\<langle>e\\<bullet>(C'::)M(es),s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\" by simp\n    thus ?thesis\n    proof(rule eval_cases)\n      fix ex\n      assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2\\<rangle>\" and e2:\"e\\<^sub>2 = throw ex\"\n      from IH[OF eval_throw wte sconf] e2 show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n    next\n      fix es' ex' s w ws assume eval_val:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<rangle>\"\n      from IH[OF eval_val wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n    next\n      fix C'' Xs Xs' Ds' S' U U' Us Us' a' body'' body''' h h' l l' pns'' pns''' \n          s ws ws'\n      assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<rangle>\"\n      from IH[OF eval_ref wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n    next\n      fix s ws\n      assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<rangle>\"\n      from IH[OF eval_null wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n    qed\n  qed\nnext\n  case (CallParamsThrow E e s\\<^sub>0 v s\\<^sub>1 es vs ex es' s\\<^sub>2 Copt M e\\<^sub>2 s\\<^sub>2' T)\n  have eval:\"P,E \\<turnstile> \\<langle>Call e Copt M es,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2'\\<rangle>\"\n    and wt:\"P,E \\<turnstile> Call e Copt M es :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH1:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk> \n                    \\<Longrightarrow> Val v = ei \\<and> s\\<^sub>1 = si\"\n    and IH2:\"\\<And>esi si Ts. \\<lbrakk>P,E \\<turnstile> \\<langle>es,s\\<^sub>1\\<rangle> [\\<Rightarrow>] \\<langle>esi,si\\<rangle>; P,E \\<turnstile> es [::] Ts; P,E \\<turnstile> s\\<^sub>1 \\<surd>\\<rbrakk>\n                      \\<Longrightarrow> map Val vs @ throw ex # es' = esi \\<and> s\\<^sub>2 = si\" by fact+\n  from wt obtain C Ts where wte:\"P,E \\<turnstile> e :: Class C\" and wtes:\"P,E \\<turnstile> es [::] Ts\" \n    by(cases Copt)auto\n  show ?case\n  proof(cases Copt)\n    assume \"Copt = None\"\n    with eval have \"P,E \\<turnstile> \\<langle>e\\<bullet>M(es),s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2'\\<rangle>\" by simp\n    thus ?thesis\n    proof(rule eval_cases)\n      fix ex' assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex',s\\<^sub>2'\\<rangle>\"\n      from IH1[OF eval_throw wte sconf] show \"throw ex = e\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n    next\n      fix es'' ex' s w ws\n      assume eval_val:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<rangle>\" \n        and evals_throw:\"P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val ws@throw ex'#es'',s\\<^sub>2'\\<rangle>\"\n        and e2:\"e\\<^sub>2 = throw ex'\"\n      from IH1[OF eval_val wte sconf] have eq:\"s = s\\<^sub>1\" by simp\n      with wf eval_val wte sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n        by(fastforce intro:eval_preserves_sconf)\n      from IH2[OF evals_throw[simplified eq] wtes this] e2\n      have \"vs = ws \\<and> ex = ex' \\<and> es' = es'' \\<and> s\\<^sub>2 = s\\<^sub>2'\"\n        by(fastforce dest:map_Val_throw_eq)\n      with e2 show \"throw ex = e\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n    next\n      fix C' Xs Xs' Ds' S' U U' Us Us' a' body'' body''' h h' l l' pns'' pns''' \n          s ws ws'\n      assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<rangle>\"\n        and evals_vals:\"P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val ws,(h,l)\\<rangle>\"\n      from IH1[OF eval_ref wte sconf] have eq:\"s = s\\<^sub>1\" by simp\n      with wf eval_ref wte sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n        by(fastforce intro:eval_preserves_sconf)\n      from IH2[OF evals_vals[simplified eq] wtes this]\n      show \"throw ex = e\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\"\n        by(fastforce dest:sym[THEN map_Val_throw_False])\n    next\n      fix s ws\n      assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<rangle>\"\n        and evals_vals:\"P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val ws,s\\<^sub>2'\\<rangle>\"\n        and e2:\"e\\<^sub>2 = THROW NullPointer\"\n      from IH1[OF eval_null wte sconf] have eq:\"s = s\\<^sub>1\" by simp\n      with wf eval_null wte sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n        by(fastforce intro:eval_preserves_sconf)\n      from IH2[OF evals_vals[simplified eq] wtes this] \n      show \"throw ex = e\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\"\n        by(fastforce dest:sym[THEN map_Val_throw_False])\n    qed\n  next\n    fix C' assume \"Copt = Some C'\"\n    with eval have \"P,E \\<turnstile> \\<langle>e\\<bullet>(C'::)M(es),s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2'\\<rangle>\" by simp\n    thus ?thesis\n    proof(rule eval_cases)\n      fix ex' assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex',s\\<^sub>2'\\<rangle>\"\n      from IH1[OF eval_throw wte sconf] show \"throw ex = e\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n    next\n      fix es'' ex' s w ws\n      assume eval_val:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<rangle>\" \n        and evals_throw:\"P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val ws@throw ex'#es'',s\\<^sub>2'\\<rangle>\"\n        and e2:\"e\\<^sub>2 = throw ex'\"\n      from IH1[OF eval_val wte sconf] have eq:\"s = s\\<^sub>1\" by simp\n      with wf eval_val wte sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n        by(fastforce intro:eval_preserves_sconf)\n      from IH2[OF evals_throw[simplified eq] wtes this] e2\n      have \"vs = ws \\<and> ex = ex' \\<and> es' = es'' \\<and> s\\<^sub>2 = s\\<^sub>2'\"\n        by(fastforce dest:map_Val_throw_eq)\n      with e2 show \"throw ex = e\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n    next\n      fix C' Xs Xs' Ds' S' U U' Us Us' a' body'' body''' h h' l l' pns'' pns''' \n          s ws ws'\n      assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<rangle>\"\n        and evals_vals:\"P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val ws,(h,l)\\<rangle>\"\n      from IH1[OF eval_ref wte sconf] have eq:\"s = s\\<^sub>1\" by simp\n      with wf eval_ref wte sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n        by(fastforce intro:eval_preserves_sconf)\n      from IH2[OF evals_vals[simplified eq] wtes this]\n      show \"throw ex = e\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\"\n        by(fastforce dest:sym[THEN map_Val_throw_False])\n    next\n      fix s ws\n      assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<rangle>\"\n        and evals_vals:\"P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val ws,s\\<^sub>2'\\<rangle>\"\n        and e2:\"e\\<^sub>2 = THROW NullPointer\"\n      from IH1[OF eval_null wte sconf] have eq:\"s = s\\<^sub>1\" by simp\n      with wf eval_null wte sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n        by(fastforce intro:eval_preserves_sconf)\n      from IH2[OF evals_vals[simplified eq] wtes this] \n      show \"throw ex = e\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\"\n        by(fastforce dest:sym[THEN map_Val_throw_False])\n    qed\n  qed\nnext\n  case (Call E e s\\<^sub>0 a Cs s\\<^sub>1 es vs h\\<^sub>2 l\\<^sub>2 C S M Ts' T' pns' body' Ds Ts T pns\n             body Cs' vs' l\\<^sub>2' new_body e' h\\<^sub>3 l\\<^sub>3 e\\<^sub>2 s\\<^sub>2 T'')\n  have eval:\"P,E \\<turnstile> \\<langle>e\\<bullet>M(es),s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and eval':\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a,Cs),s\\<^sub>1\\<rangle>\"\n    and eval'':\"P,E \\<turnstile> \\<langle>es,s\\<^sub>1\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs,(h\\<^sub>2,l\\<^sub>2)\\<rangle>\" and h2:\"h\\<^sub>2 a = Some(C,S)\"\n    and has_least:\"P \\<turnstile> last Cs has least M = (Ts',T',pns',body') via Ds\"\n    and selects:\"P \\<turnstile> (C,Cs@\\<^sub>pDs) selects M = (Ts,T,pns,body) via Cs'\"\n    and length:\"length vs = length pns\" and Casts:\"P \\<turnstile> Ts Casts vs to vs'\"\n    and l2':\"l\\<^sub>2' = [this \\<mapsto> Ref (a, Cs'), pns [\\<mapsto>] vs']\"\n    and new_body:\"new_body = (case T' of Class D \\<Rightarrow> \\<lparr>D\\<rparr>body | _ \\<Rightarrow> body)\"\n    and eval_body:\"P,E(this \\<mapsto> Class (last Cs'), pns [\\<mapsto>] Ts) \\<turnstile> \n                                            \\<langle>new_body,(h\\<^sub>2,l\\<^sub>2')\\<rangle> \\<Rightarrow> \\<langle>e',(h\\<^sub>3,l\\<^sub>3)\\<rangle>\"\n    and wt:\"P,E \\<turnstile> e\\<bullet>M(es) :: T''\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH1:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                     \\<Longrightarrow> ref (a,Cs) = ei \\<and> s\\<^sub>1 = si\"\n    and IH2:\"\\<And>esi si Ts. \\<lbrakk>P,E \\<turnstile> \\<langle>es,s\\<^sub>1\\<rangle> [\\<Rightarrow>] \\<langle>esi,si\\<rangle>; P,E \\<turnstile> es [::] Ts; P,E \\<turnstile> s\\<^sub>1 \\<surd>\\<rbrakk>\n                      \\<Longrightarrow> map Val vs = esi \\<and> (h\\<^sub>2,l\\<^sub>2) = si\"\n    and IH3:\"\\<And>ei si T. \n    \\<lbrakk>P,E(this \\<mapsto> Class (last Cs'), pns [\\<mapsto>] Ts) \\<turnstile> \\<langle>new_body,(h\\<^sub>2,l\\<^sub>2')\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>;\n     P,E(this \\<mapsto> Class (last Cs'), pns [\\<mapsto>] Ts) \\<turnstile> new_body :: T;\n     P,E(this \\<mapsto> Class (last Cs'), pns [\\<mapsto>] Ts) \\<turnstile> (h\\<^sub>2,l\\<^sub>2') \\<surd>\\<rbrakk>\n  \\<Longrightarrow> e' = ei \\<and> (h\\<^sub>3, l\\<^sub>3) = si\" by fact+\n  from wt obtain D Ss Ss' m Cs'' where wte:\"P,E \\<turnstile> e :: Class D\" \n    and has_least':\"P \\<turnstile> D has least M = (Ss,T'',m) via Cs''\"\n    and wtes:\"P,E \\<turnstile> es [::] Ss'\" and subs:\"P \\<turnstile> Ss' [\\<le>] Ss\" by auto\n  from eval_preserves_type[OF wf eval' sconf wte]\n  have last:\"last Cs = D\" by (auto split:split_if_asm)\n  with has_least has_least' wf\n  have eq:\"Ts' = Ss \\<and> T' = T'' \\<and> (pns',body') = m \\<and> Ds = Cs''\"\n    by(fastforce dest:wf_sees_method_fun)\n  from wf selects have param_type:\"\\<forall>T \\<in> set Ts. is_type P T\" \n    and return_type:\"is_type P T\" and TnotNT:\"T \\<noteq> NT\"\n    by(auto dest:select_method_wf_mdecl simp:wf_mdecl_def)\n  from selects wf have subo:\"Subobjs P C Cs'\"\n    by(induct rule:SelectMethodDef.induct,\n       auto simp:FinalOverriderMethodDef_def OverriderMethodDefs_def \n                 MinimalMethodDefs_def LeastMethodDef_def MethodDefs_def)\n  with wf have \"class\":\"is_class P (last Cs')\" by(auto intro!:Subobj_last_isClass)\n  from eval'' have hext:\"hp s\\<^sub>1 \\<unlhd> h\\<^sub>2\" by (cases s\\<^sub>1,auto intro: evals_hext)\n  from wf eval' sconf wte last have \"P,E,(hp s\\<^sub>1) \\<turnstile> ref(a,Cs) :\\<^bsub>NT\\<^esub> Class(last Cs)\"\n    by -(rule eval_preserves_type,simp_all)\n  with hext have \"P,E,h\\<^sub>2 \\<turnstile> ref(a,Cs) :\\<^bsub>NT\\<^esub> Class(last Cs)\"\n    by(auto intro:WTrt_hext_mono dest:hext_objD split:split_if_asm)\n  with h2 have \"Subobjs P C Cs\" by (auto split:split_if_asm)\n  hence \"P \\<turnstile> Path C to (last Cs) via Cs\"\n    by (auto simp:path_via_def split:split_if_asm)\n  with selects has_least wf have param_types:\"Ts' = Ts \\<and> P \\<turnstile> T \\<le> T'\"\n    by -(rule select_least_methods_subtypes,simp_all)\n  from wf selects have wt_body:\"P,[this\\<mapsto>Class(last Cs'),pns[\\<mapsto>]Ts] \\<turnstile> body :: T\"\n    and this_not_pns:\"this \\<notin> set pns\" and length:\"length pns = length Ts\"\n    and dist:\"distinct pns\"\n    by(auto dest!:select_method_wf_mdecl simp:wf_mdecl_def)\n  have \"P,[this\\<mapsto>Class(last Cs'),pns[\\<mapsto>]Ts] \\<turnstile> new_body :: T'\"\n  proof(cases \"\\<exists>C. T' = Class C\")\n    case False with wt_body new_body param_types show ?thesis by(cases T') auto\n  next\n    case True\n    then obtain D' where T':\"T' = Class D'\" by auto\n    with wf has_least have \"class\":\"is_class P D'\"\n      by(fastforce dest:has_least_wf_mdecl simp:wf_mdecl_def)\n    with wf T' TnotNT param_types obtain D'' where T:\"T = Class D''\"\n      by(fastforce dest:widen_Class)\n    with wf return_type T' param_types have \"P \\<turnstile> Path D'' to D' unique\"\n      by(simp add:Class_widen_Class)\n    with wt_body \"class\" T T' new_body show ?thesis by auto\n  qed\n  hence wt_new_body:\"P,E(this\\<mapsto>Class(last Cs'),pns[\\<mapsto>]Ts) \\<turnstile> new_body :: T'\"\n    by(fastforce intro:wt_env_mono)\n  from eval show ?case\n  proof(rule eval_cases)\n    fix ex' assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex',s\\<^sub>2\\<rangle>\"\n    from IH1[OF eval_throw wte sconf] show \"e' = e\\<^sub>2 \\<and> (h\\<^sub>3, l\\<^sub>2) = s\\<^sub>2\" by simp\n  next\n    fix es'' ex' s w ws\n    assume eval_val:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<rangle>\" \n      and evals_throw:\"P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val ws@throw ex'#es'',s\\<^sub>2\\<rangle>\"\n    from IH1[OF eval_val wte sconf] have eq:\"s = s\\<^sub>1\" by simp\n    with wf eval_val wte sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n    from IH2[OF evals_throw[simplified eq] wtes this] show \"e' = e\\<^sub>2 \\<and> (h\\<^sub>3, l\\<^sub>2) = s\\<^sub>2\"\n      by(fastforce dest:map_Val_throw_False)\n  next\n    fix C' Xs Xs' Ds' S' U U' Us Us' a' body'' body''' h h' l l' pns'' pns''' s ws ws'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<rangle>\"\n      and evals_vals:\"P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val ws,(h,l)\\<rangle>\"\n      and h:\"h a' = Some(C',S')\" \n      and has_least'':\"P \\<turnstile> last Xs has least M = (Us',U',pns''',body''') via Ds'\"\n      and selects':\"P \\<turnstile> (C',Xs@\\<^sub>pDs') selects M = (Us,U,pns'',body'') via Xs'\"\n      and length':\"length ws = length pns''\" and Casts':\"P \\<turnstile> Us Casts ws to ws'\"\n      and eval_body':\"P,E(this \\<mapsto> Class (last Xs'), pns'' [\\<mapsto>] Us) \\<turnstile> \n      \\<langle>case U' of Class D \\<Rightarrow> \\<lparr>D\\<rparr>body'' | _ \\<Rightarrow> body'',\n        (h,[this \\<mapsto> Ref(a',Xs'), pns'' [\\<mapsto>] ws'])\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,(h',l')\\<rangle>\"\n      and s2:\"s\\<^sub>2 = (h',l)\"\n    from IH1[OF eval_ref wte sconf] have eq1:\"a = a' \\<and> Cs = Xs\" and s:\"s = s\\<^sub>1\" \n      by simp_all\n    with has_least has_least'' wf have eq2:\"T' = U' \\<and> Ts' = Us' \\<and> Ds = Ds'\"\n      by(fastforce dest:wf_sees_method_fun)\n    from s wf eval_ref wte sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n    from IH2[OF evals_vals[simplified s] wtes this]\n    have eq3:\"vs = ws \\<and> h\\<^sub>2 = h \\<and> l\\<^sub>2 = l\"\n      by(fastforce elim:map_injective simp:inj_on_def)\n    with eq1 h2 h have eq4:\"C = C' \\<and> S = S'\" by simp\n    with eq1 eq2 selects selects' wf\n    have eq5:\"Ts = Us \\<and> T = U \\<and> pns'' = pns \\<and> body'' = body \\<and> Cs' = Xs'\"\n      by simp(drule_tac mthd'=\"(Us,U,pns'',body'')\" in wf_select_method_fun,auto)\n    with subs eq param_types have \"P \\<turnstile> Ss' [\\<le>] Us\" by simp\n    with wf Casts Casts' param_type wtes evals_vals sconf' s eq eq2 eq3 eq5\n    have eq6:\"vs' = ws'\"\n      by(fastforce intro:Casts_Casts_eq_result)\n    with eval_body' l2' eq1 eq2 eq3 eq5 new_body  \n    have eval_body'':\"P,E(this \\<mapsto> Class(last Cs'), pns [\\<mapsto>] Ts) \\<turnstile> \n                           \\<langle>new_body,(h\\<^sub>2,l\\<^sub>2')\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,(h',l')\\<rangle>\"\n      by fastforce\n    from wf evals_vals wtes sconf' s eq3 have sconf'':\"P,E \\<turnstile> (h\\<^sub>2,l\\<^sub>2) \\<surd>\"\n      by(fastforce intro:evals_preserves_sconf)\n    have \"P,E(this \\<mapsto> Class (last Cs'), pns [\\<mapsto>] Ts) \\<turnstile> (h\\<^sub>2,l\\<^sub>2') \\<surd>\"\n    proof(auto simp:sconf_def)\n      from sconf'' show \"P \\<turnstile> h\\<^sub>2 \\<surd>\" by(simp add:sconf_def)\n    next\n      { fix V v assume map:\"[this \\<mapsto> Ref (a,Cs'), pns [\\<mapsto>] vs'] V = Some v\"\n        have \"\\<exists>T. (E(this \\<mapsto> Class (last Cs'), pns [\\<mapsto>] Ts)) V = Some T \\<and> \n                   P,h\\<^sub>2 \\<turnstile> v :\\<le> T\"\n        proof(cases \"V \\<in> set (this#pns)\")\n          case False with map show ?thesis by simp\n        next\n          case True\n          hence \"V = this \\<or> V \\<in> set pns\" by simp\n          thus ?thesis\n          proof(rule disjE)\n            assume V:\"V = this\"\n            with map this_not_pns have \"v = Ref(a,Cs')\" by simp\n            with V h2 subo this_not_pns have \n              \"(E(this \\<mapsto> Class (last Cs'),pns [\\<mapsto>] Ts)) V = Some(Class (last Cs'))\"\n              and \"P,h\\<^sub>2 \\<turnstile> v :\\<le> Class (last Cs')\" by simp_all\n            thus ?thesis by simp\n          next\n            assume \"V \\<in> set pns\"\n            then obtain i where V:\"V = pns!i\" and length_i:\"i < length pns\"\n              by(auto simp:in_set_conv_nth)\n            from Casts have \"length Ts = length vs'\"\n              by(induct rule:Casts_to.induct,auto)\n            with length have \"length pns = length vs'\" by simp\n            with map dist V length_i have v:\"v = vs'!i\" by(fastforce dest:maps_nth)\n            from length dist length_i\n            have env:\"(E(this \\<mapsto> Class (last Cs'))(pns [\\<mapsto>] Ts)) (pns!i) = Some(Ts!i)\"\n              by(rule_tac E=\"E(this \\<mapsto> Class (last Cs'))\" in nth_maps,simp_all)\n            from wf Casts wtes subs eq param_types eval'' sconf'\n            have \"\\<forall>i < length Ts. P,h\\<^sub>2 \\<turnstile> vs'!i :\\<le> Ts!i\"\n              by simp(rule Casts_conf,auto)\n            with length_i length env V v show ?thesis by simp\n          qed\n        qed }\n      thus \"P,h\\<^sub>2 \\<turnstile> l\\<^sub>2' (:\\<le>)\\<^sub>w E(this \\<mapsto> Class (last Cs'), pns [\\<mapsto>] Ts)\"\n        using l2' by(simp add:lconf_def)\n    next\n      { fix V Tx assume env:\"(E(this \\<mapsto> Class (last Cs'), pns [\\<mapsto>] Ts)) V = Some Tx\"\n        have \"is_type P Tx\"\n        proof(cases \"V \\<in> set (this#pns)\")\n          case False\n          with env sconf'' show ?thesis\n            by(clarsimp simp:sconf_def envconf_def)\n        next\n          case True\n          hence \"V = this \\<or> V \\<in> set pns\" by simp\n          thus ?thesis\n          proof(rule disjE)\n            assume \"V = this\"\n            with env this_not_pns have \"Tx = Class(last Cs')\" by simp\n            with \"class\" show ?thesis by simp\n          next\n            assume \"V \\<in> set pns\"\n            then obtain i where V:\"V = pns!i\" and length_i:\"i < length pns\"\n              by(auto simp:in_set_conv_nth)\n            with dist length env have \"Tx = Ts!i\" by(fastforce dest:maps_nth)\n            with length_i length have \"Tx \\<in> set Ts\"\n              by(fastforce simp:in_set_conv_nth)\n            with param_type show ?thesis by simp\n          qed\n        qed }\n      thus \"P \\<turnstile> E(this \\<mapsto> Class (last Cs'), pns [\\<mapsto>] Ts) \\<surd>\" by (simp add:envconf_def)\n    qed\n    from IH3[OF eval_body'' wt_new_body this] have \"e' = e\\<^sub>2 \\<and> (h\\<^sub>3, l\\<^sub>3) = (h',l')\" .\n    with eq3 s2 show \"e' = e\\<^sub>2 \\<and> (h\\<^sub>3,l\\<^sub>2) = s\\<^sub>2\" by simp\n  next\n    fix s ws\n    assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<rangle>\"\n    from IH1[OF eval_null wte sconf] show \"e' = e\\<^sub>2 \\<and> (h\\<^sub>3,l\\<^sub>2) = s\\<^sub>2\" by simp\n  qed\nnext\n  case (StaticCall E e s\\<^sub>0 a Cs s\\<^sub>1 es vs h\\<^sub>2 l\\<^sub>2 C Cs'' M Ts T pns body  Cs'\n                   Ds vs' l\\<^sub>2' e' h\\<^sub>3 l\\<^sub>3 e\\<^sub>2 s\\<^sub>2 T')\n  have eval:\"P,E \\<turnstile> \\<langle>e\\<bullet>(C::)M(es),s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and eval':\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a,Cs),s\\<^sub>1\\<rangle>\"\n    and eval'':\"P,E \\<turnstile> \\<langle>es,s\\<^sub>1\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs,(h\\<^sub>2, l\\<^sub>2)\\<rangle>\"\n    and path_unique:\"P \\<turnstile> Path last Cs to C unique\" \n    and path_via:\"P \\<turnstile> Path last Cs to C via Cs''\"\n    and has_least:\"P \\<turnstile> C has least M = (Ts,T,pns,body) via Cs'\"\n    and Ds:\"Ds = (Cs@\\<^sub>pCs'')@\\<^sub>pCs'\" and length:\"length vs = length pns\"\n    and Casts:\"P \\<turnstile> Ts Casts vs to vs'\"\n    and l2':\"l\\<^sub>2' = [this \\<mapsto> Ref (a, Ds), pns [\\<mapsto>] vs']\"\n    and eval_body:\"P,E(this \\<mapsto> Class (last Ds), pns [\\<mapsto>] Ts) \\<turnstile> \n                                             \\<langle>body,(h\\<^sub>2,l\\<^sub>2')\\<rangle> \\<Rightarrow> \\<langle>e',(h\\<^sub>3,l\\<^sub>3)\\<rangle>\"\n    and wt:\"P,E \\<turnstile> e\\<bullet>(C::)M(es) :: T'\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH1:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> ref (a,Cs) = ei \\<and> s\\<^sub>1 = si\"\n    and IH2:\"\\<And>esi si Ts. \n             \\<lbrakk>P,E \\<turnstile> \\<langle>es,s\\<^sub>1\\<rangle> [\\<Rightarrow>] \\<langle>esi,si\\<rangle>; P,E \\<turnstile> es [::] Ts; P,E \\<turnstile> s\\<^sub>1 \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> map Val vs = esi \\<and> (h\\<^sub>2,l\\<^sub>2) = si\"\n    and IH3:\"\\<And>ei si T.\n   \\<lbrakk>P,E(this \\<mapsto> Class (last Ds), pns [\\<mapsto>] Ts) \\<turnstile> \\<langle>body,(h\\<^sub>2,l\\<^sub>2')\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>;\n    P,E(this \\<mapsto> Class (last Ds), pns [\\<mapsto>] Ts) \\<turnstile> body :: T;\n    P,E(this \\<mapsto> Class (last Ds), pns [\\<mapsto>] Ts) \\<turnstile> (h\\<^sub>2,l\\<^sub>2') \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> e' = ei \\<and> (h\\<^sub>3, l\\<^sub>3) = si\" by fact+\n  from wt has_least wf obtain C' Ts' where wte:\"P,E \\<turnstile> e :: Class C'\"\n      and wtes:\"P,E \\<turnstile> es [::] Ts'\" and subs:\"P \\<turnstile> Ts' [\\<le>] Ts\"\n    by(auto dest:wf_sees_method_fun)\n  from eval_preserves_type[OF wf eval' sconf wte]\n  have last:\"last Cs = C'\" by (auto split:split_if_asm)\n  from wf has_least have param_type:\"\\<forall>T \\<in> set Ts. is_type P T\" \n    and return_type:\"is_type P T\" and TnotNT:\"T \\<noteq> NT\"\n    by(auto dest:has_least_wf_mdecl simp:wf_mdecl_def)\n  from path_via have last':\"last Cs'' = last(Cs@\\<^sub>pCs'')\"\n    by(fastforce intro!:appendPath_last Subobjs_nonempty simp:path_via_def)\n  from eval'' have hext:\"hp s\\<^sub>1 \\<unlhd> h\\<^sub>2\" by (cases s\\<^sub>1,auto intro: evals_hext)\n  from wf eval' sconf wte last have \"P,E,(hp s\\<^sub>1) \\<turnstile> ref(a,Cs) :\\<^bsub>NT\\<^esub> Class(last Cs)\"\n    by -(rule eval_preserves_type,simp_all)\n  with hext have \"P,E,h\\<^sub>2 \\<turnstile> ref(a,Cs) :\\<^bsub>NT\\<^esub> Class(last Cs)\"\n    by(auto intro:WTrt_hext_mono dest:hext_objD split:split_if_asm)\n  then obtain D S where h2:\"h\\<^sub>2 a = Some(D,S)\" and \"Subobjs P D Cs\"\n    by (auto split:split_if_asm)\n  with path_via wf have \"Subobjs P D (Cs@\\<^sub>pCs'')\" and \"last Cs'' = C\"\n    by(auto intro:Subobjs_appendPath simp:path_via_def)\n  with has_least wf last' Ds have subo:\"Subobjs P D Ds\"\n    by(fastforce intro:Subobjs_appendPath simp:LeastMethodDef_def MethodDefs_def)\n  with wf have \"class\":\"is_class P (last Ds)\" by(auto intro!:Subobj_last_isClass)\n  from has_least wf obtain D' where \"Subobjs P D' Cs'\"\n    by(auto simp:LeastMethodDef_def MethodDefs_def)\n  with Ds have last_Ds:\"last Cs' = last Ds\"\n    by(fastforce intro!:appendPath_last Subobjs_nonempty)\n  with wf has_least have \"P,[this\\<mapsto>Class(last Ds),pns[\\<mapsto>]Ts] \\<turnstile> body :: T\"\n    and this_not_pns:\"this \\<notin> set pns\" and length:\"length pns = length Ts\"\n    and dist:\"distinct pns\"\n    by(auto dest!:has_least_wf_mdecl simp:wf_mdecl_def)\n  hence wt_body:\"P,E(this\\<mapsto>Class(last Ds),pns[\\<mapsto>]Ts) \\<turnstile> body :: T\"\n    by(fastforce intro:wt_env_mono)\n  from eval show ?case\n  proof(rule eval_cases)\n    fix ex' assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex',s\\<^sub>2\\<rangle>\"\n    from IH1[OF eval_throw wte sconf] show \"e' = e\\<^sub>2 \\<and> (h\\<^sub>3, l\\<^sub>2) = s\\<^sub>2\" by simp\n  next\n    fix es'' ex' s w ws\n    assume eval_val:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<rangle>\" \n      and evals_throw:\"P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val ws@throw ex'#es'',s\\<^sub>2\\<rangle>\"\n    from IH1[OF eval_val wte sconf] have eq:\"s = s\\<^sub>1\" by simp\n    with wf eval_val wte sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n    from IH2[OF evals_throw[simplified eq] wtes this] show \"e' = e\\<^sub>2 \\<and> (h\\<^sub>3, l\\<^sub>2) = s\\<^sub>2\"\n      by(fastforce dest:map_Val_throw_False)\n  next\n    fix Xs Xs' Xs'' U Us a' body' h h' l l' pns' s ws ws'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<rangle>\"\n      and evals_vals:\"P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val ws,(h,l)\\<rangle>\"\n      and path_unique':\"P \\<turnstile> Path last Xs to C unique\"\n      and path_via':\"P \\<turnstile> Path last Xs to C via Xs''\"\n      and has_least':\"P \\<turnstile> C has least M = (Us,U,pns',body') via Xs'\"\n      and length':\"length ws = length pns'\"\n      and Casts':\"P \\<turnstile> Us Casts ws to ws'\"\n      and eval_body':\"P,E(this \\<mapsto> Class(last((Xs@\\<^sub>pXs'')@\\<^sub>pXs')),pns' [\\<mapsto>] Us) \\<turnstile> \n      \\<langle>body',(h,[this \\<mapsto> Ref(a',(Xs@\\<^sub>pXs'')@\\<^sub>pXs'),pns' [\\<mapsto>] ws'])\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,(h',l')\\<rangle>\"\n      and s2:\"s\\<^sub>2 = (h',l)\"\n    from IH1[OF eval_ref wte sconf] have eq1:\"a = a' \\<and> Cs = Xs\" and s:\"s = s\\<^sub>1\" \n      by simp_all\n    from has_least has_least' wf \n    have eq2:\"T = U \\<and> Ts = Us \\<and> Cs' = Xs' \\<and> pns = pns' \\<and> body = body'\"\n      by(fastforce dest:wf_sees_method_fun)\n    from s wf eval_ref wte sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n    from IH2[OF evals_vals[simplified s] wtes this]\n    have eq3:\"vs = ws \\<and> h\\<^sub>2 = h \\<and> l\\<^sub>2 = l\"\n      by(fastforce elim:map_injective simp:inj_on_def)\n    from path_unique path_via path_via' eq1 have \"Cs'' = Xs''\" \n      by(fastforce simp:path_unique_def path_via_def)\n    with Ds eq1 eq2 have Ds':\"Ds = (Xs@\\<^sub>pXs'')@\\<^sub>pXs'\" by simp\n    from wf Casts Casts' param_type wtes subs evals_vals sconf' s eq2 eq3\n    have eq4:\"vs' = ws'\"\n      by(fastforce intro:Casts_Casts_eq_result)\n    with eval_body' Ds' l2' eq1 eq2 eq3\n    have eval_body'':\"P,E(this \\<mapsto> Class(last Ds),pns [\\<mapsto>] Ts) \\<turnstile> \n                            \\<langle>body,(h\\<^sub>2,l\\<^sub>2')\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,(h',l')\\<rangle>\"\n      by simp\n    from wf evals_vals wtes sconf' s eq3 have sconf'':\"P,E \\<turnstile> (h\\<^sub>2,l\\<^sub>2) \\<surd>\"\n      by(fastforce intro:evals_preserves_sconf)\n    have \"P,E(this \\<mapsto> Class (last Ds), pns [\\<mapsto>] Ts) \\<turnstile> (h\\<^sub>2,l\\<^sub>2') \\<surd>\"\n    proof(auto simp:sconf_def)\n      from sconf'' show \"P \\<turnstile> h\\<^sub>2 \\<surd>\" by(simp add:sconf_def)\n    next\n      { fix V v assume map:\"[this \\<mapsto> Ref (a,Ds), pns [\\<mapsto>] vs'] V = Some v\"\n        have \"\\<exists>T. (E(this \\<mapsto> Class (last Ds), pns [\\<mapsto>] Ts)) V = Some T \\<and> \n                   P,h\\<^sub>2 \\<turnstile> v :\\<le> T\"\n        proof(cases \"V \\<in> set (this#pns)\")\n          case False with map show ?thesis by simp\n        next\n          case True\n          hence \"V = this \\<or> V \\<in> set pns\" by simp\n          thus ?thesis\n          proof(rule disjE)\n            assume V:\"V = this\"\n            with map this_not_pns have \"v = Ref(a,Ds)\" by simp\n            with V h2 subo this_not_pns have\n              \"(E(this \\<mapsto> Class (last Ds),pns [\\<mapsto>] Ts)) V = Some(Class (last Ds))\"\n              and \"P,h\\<^sub>2 \\<turnstile> v :\\<le> Class (last Ds)\" by simp_all\n            thus ?thesis by simp\n          next\n            assume \"V \\<in> set pns\"\n            then obtain i where V:\"V = pns!i\" and length_i:\"i < length pns\"\n              by(auto simp:in_set_conv_nth)\n            from Casts have \"length Ts = length vs'\"\n              by(induct rule:Casts_to.induct,auto)\n            with length have \"length pns = length vs'\" by simp\n            with map dist V length_i have v:\"v = vs'!i\" by(fastforce dest:maps_nth)\n            from length dist length_i\n            have env:\"(E(this \\<mapsto> Class (last Ds))(pns [\\<mapsto>] Ts)) (pns!i) = Some(Ts!i)\"\n              by(rule_tac E=\"E(this \\<mapsto> Class (last Ds))\" in nth_maps,simp_all)\n            from wf Casts wtes subs eval'' sconf'\n            have \"\\<forall>i < length Ts. P,h\\<^sub>2 \\<turnstile> vs'!i :\\<le> Ts!i\"\n              by -(rule Casts_conf,auto)\n            with length_i length env V v show ?thesis by simp\n          qed\n        qed }\n      thus \"P,h\\<^sub>2 \\<turnstile> l\\<^sub>2' (:\\<le>)\\<^sub>w E(this \\<mapsto> Class (last Ds), pns [\\<mapsto>] Ts)\"\n        using l2' by(simp add:lconf_def)\n    next\n      { fix V Tx assume env:\"(E(this \\<mapsto> Class (last Ds), pns [\\<mapsto>] Ts)) V = Some Tx\"\n        have \"is_type P Tx\"\n        proof(cases \"V \\<in> set (this#pns)\")\n          case False\n          with env sconf'' show ?thesis\n            by(clarsimp simp:sconf_def envconf_def)\n        next\n          case True\n          hence \"V = this \\<or> V \\<in> set pns\" by simp\n          thus ?thesis\n          proof(rule disjE)\n            assume \"V = this\"\n            with env this_not_pns have \"Tx = Class(last Ds)\" by simp\n            with \"class\" show ?thesis by simp\n          next\n            assume \"V \\<in> set pns\"\n            then obtain i where V:\"V = pns!i\" and length_i:\"i < length pns\"\n              by(auto simp:in_set_conv_nth)\n            with dist length env have \"Tx = Ts!i\" by(fastforce dest:maps_nth)\n            with length_i length have \"Tx \\<in> set Ts\"\n              by(fastforce simp:in_set_conv_nth)\n            with param_type show ?thesis by simp\n          qed\n        qed }\n      thus \"P \\<turnstile> E(this \\<mapsto> Class (last Ds), pns [\\<mapsto>] Ts) \\<surd>\" by (simp add:envconf_def)\n    qed\n    from IH3[OF eval_body'' wt_body this] have \"e' = e\\<^sub>2 \\<and> (h\\<^sub>3, l\\<^sub>3) = (h',l')\" .\n    with eq3 s2 show \"e' = e\\<^sub>2 \\<and> (h\\<^sub>3, l\\<^sub>2) = s\\<^sub>2\" by simp\n  next\n    fix s ws\n    assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<rangle>\"\n    from IH1[OF eval_null wte sconf] show \"e' = e\\<^sub>2 \\<and> (h\\<^sub>3,l\\<^sub>2) = s\\<^sub>2\" by simp\n  qed\nnext\n  case (CallNull E e s\\<^sub>0 s\\<^sub>1 es vs s\\<^sub>2 Copt M e\\<^sub>2 s\\<^sub>2' T)\n  have eval:\"P,E \\<turnstile> \\<langle>Call e Copt M es,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2'\\<rangle>\"\n    and wt:\"P,E \\<turnstile> Call e Copt M es :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH1:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk> \n    \\<Longrightarrow> null = ei \\<and> s\\<^sub>1 = si\"\n    and IH2:\"\\<And>esi si Ts. \\<lbrakk>P,E \\<turnstile> \\<langle>es,s\\<^sub>1\\<rangle> [\\<Rightarrow>] \\<langle>esi,si\\<rangle>; P,E \\<turnstile> es [::] Ts; P,E \\<turnstile> s\\<^sub>1 \\<surd>\\<rbrakk>\n    \\<Longrightarrow> map Val vs = esi \\<and> s\\<^sub>2 = si\" by fact+\n  from wt obtain C Ts where wte:\"P,E \\<turnstile> e :: Class C\" and wtes:\"P,E \\<turnstile> es [::] Ts\" \n    by(cases Copt)auto\n  show ?case\n  proof(cases Copt)\n    assume \"Copt = None\"\n    with eval have \"P,E \\<turnstile> \\<langle>e\\<bullet>M(es),s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2'\\<rangle>\" by simp\n    thus ?thesis\n    proof(rule eval_cases)\n      fix ex' assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex',s\\<^sub>2'\\<rangle>\"\n      from IH1[OF eval_throw wte sconf] show \"THROW NullPointer = e\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\" \n        by simp\n    next\n      fix es' ex' s w ws\n      assume eval_val:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<rangle>\"\n        and evals_throw:\"P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val ws@throw ex'#es',s\\<^sub>2'\\<rangle>\"\n      from IH1[OF eval_val wte sconf] have eq:\"s = s\\<^sub>1\" by simp\n      with wf eval_val wte sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n        by(fastforce intro:eval_preserves_sconf)\n      from IH2[OF evals_throw[simplified eq] wtes this] \n      show \"THROW NullPointer = e\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\" by(fastforce dest:map_Val_throw_False)\n    next\n      fix C' Xs Xs' Ds' S' U U' Us Us' a' body'' body''' h h' l l' pns'' pns''' \n          s ws ws'\n      assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<rangle>\"\n      from IH1[OF eval_ref wte sconf] show \"THROW NullPointer = e\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\" \n        by simp\n    next\n      fix s ws\n      assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<rangle>\"\n        and evals_vals:\"P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val ws,s\\<^sub>2'\\<rangle>\"\n        and e2:\"e\\<^sub>2 = THROW NullPointer\"\n      from IH1[OF eval_null wte sconf] have eq:\"s = s\\<^sub>1\" by simp\n      with wf eval_null wte sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n        by(fastforce intro:eval_preserves_sconf)\n      from IH2[OF evals_vals[simplified eq] wtes this] e2\n      show \"THROW NullPointer = e\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n    qed\n  next\n    fix C' assume \"Copt = Some C'\"\n    with eval have \"P,E \\<turnstile> \\<langle>e\\<bullet>(C'::)M(es),s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2'\\<rangle>\" by simp\n    thus ?thesis\n    proof(rule eval_cases)\n      fix ex' assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex',s\\<^sub>2'\\<rangle>\"\n      from IH1[OF eval_throw wte sconf] show \"THROW NullPointer = e\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\" \n        by simp\n    next\n      fix es' ex' s w ws\n      assume eval_val:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<rangle>\"\n        and evals_throw:\"P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val ws@throw ex'#es',s\\<^sub>2'\\<rangle>\"\n      from IH1[OF eval_val wte sconf] have eq:\"s = s\\<^sub>1\" by simp\n      with wf eval_val wte sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n        by(fastforce intro:eval_preserves_sconf)\n      from IH2[OF evals_throw[simplified eq] wtes this] \n      show \"THROW NullPointer = e\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\" by(fastforce dest:map_Val_throw_False)\n    next\n      fix C' Xs Xs' Ds' S' U U' Us Us' a' body'' body''' h h' l l' pns'' pns''' \n          s ws ws'\n      assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref(a',Xs),s\\<rangle>\"\n      from IH1[OF eval_ref wte sconf] show \"THROW NullPointer = e\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\" \n        by simp\n    next\n      fix s ws\n      assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<rangle>\"\n        and evals_vals:\"P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val ws,s\\<^sub>2'\\<rangle>\"\n        and e2:\"e\\<^sub>2 = THROW NullPointer\"\n      from IH1[OF eval_null wte sconf] have eq:\"s = s\\<^sub>1\" by simp\n      with wf eval_null wte sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n        by(fastforce intro:eval_preserves_sconf)\n      from IH2[OF evals_vals[simplified eq] wtes this] e2\n      show \"THROW NullPointer = e\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n    qed\n  qed\nnext\n  case (Block E V T e\\<^sub>0 h\\<^sub>0 l\\<^sub>0 e\\<^sub>1 h\\<^sub>1 l\\<^sub>1 e\\<^sub>2 s\\<^sub>2 T')\n  have eval:\"P,E \\<turnstile> \\<langle>{V:T; e\\<^sub>0},(h\\<^sub>0, l\\<^sub>0)\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and wt:\"P,E \\<turnstile> {V:T; e\\<^sub>0} :: T'\" and sconf:\"P,E \\<turnstile> (h\\<^sub>0, l\\<^sub>0) \\<surd>\"\n    and IH:\"\\<And>e\\<^sub>2 s\\<^sub>2 T'. \\<lbrakk>P,E(V \\<mapsto> T) \\<turnstile> \\<langle>e\\<^sub>0,(h\\<^sub>0, l\\<^sub>0(V := None))\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>; \n               P,E(V \\<mapsto> T) \\<turnstile> e\\<^sub>0 :: T'; P,E(V \\<mapsto> T) \\<turnstile> (h\\<^sub>0, l\\<^sub>0(V := None)) \\<surd>\\<rbrakk>\n    \\<Longrightarrow> e\\<^sub>1 = e\\<^sub>2 \\<and> (h\\<^sub>1, l\\<^sub>1) = s\\<^sub>2\" by fact+\n  from wt have type:\"is_type P T\" and wte:\"P,E(V \\<mapsto> T) \\<turnstile> e\\<^sub>0 :: T'\" by auto\n  from sconf type have sconf':\"P,E(V \\<mapsto> T) \\<turnstile> (h\\<^sub>0, l\\<^sub>0(V := None)) \\<surd>\"\n    by(auto simp:sconf_def lconf_def envconf_def)\n  from eval obtain h l where \n    eval':\"P,E(V \\<mapsto> T) \\<turnstile> \\<langle>e\\<^sub>0,(h\\<^sub>0,l\\<^sub>0(V:=None))\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,(h,l)\\<rangle>\"\n    and s2:\"s\\<^sub>2 = (h,l(V:=l\\<^sub>0 V))\" by (auto elim:eval_cases)\n  from IH[OF eval' wte sconf'] s2 show ?case by simp\nnext\n  case (Seq E e\\<^sub>0 s\\<^sub>0 v s\\<^sub>1 e\\<^sub>1 e\\<^sub>2 s\\<^sub>2 e\\<^sub>2' s\\<^sub>2' T)\n  have eval:\"P,E \\<turnstile> \\<langle>e\\<^sub>0;; e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2',s\\<^sub>2'\\<rangle>\"\n    and wt:\"P,E \\<turnstile> e\\<^sub>0;; e\\<^sub>1 :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH1:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e\\<^sub>0,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e\\<^sub>0 :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                     \\<Longrightarrow> Val v = ei \\<and> s\\<^sub>1 = si\"\n    and IH2:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e\\<^sub>1 :: T; P,E \\<turnstile> s\\<^sub>1 \\<surd>\\<rbrakk> \n                     \\<Longrightarrow> e\\<^sub>2 = ei \\<and> s\\<^sub>2 = si\" by fact+\n  from wt obtain T' where wte0:\"P,E \\<turnstile> e\\<^sub>0 :: T'\" and wte1:\"P,E \\<turnstile> e\\<^sub>1 :: T\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix s w \n    assume eval_val:\"P,E \\<turnstile> \\<langle>e\\<^sub>0,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<rangle>\" \n      and eval':\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2',s\\<^sub>2'\\<rangle>\"\n    from IH1[OF eval_val wte0 sconf] have eq:\"s = s\\<^sub>1\" by simp\n    with wf eval_val wte0 sconf have \"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n    from IH2[OF eval'[simplified eq] wte1 this] show \"e\\<^sub>2 = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\" .\n  next\n    fix ex assume eval_throw:\"P,E \\<turnstile> \\<langle>e\\<^sub>0,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2'\\<rangle>\"\n    from IH1[OF eval_throw wte0 sconf] show \"e\\<^sub>2 = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n  qed\nnext\n  case (SeqThrow E e\\<^sub>0 s\\<^sub>0 e s\\<^sub>1 e\\<^sub>1 e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>e\\<^sub>0;; e\\<^sub>1,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and wt:\"P,E \\<turnstile> e\\<^sub>0;; e\\<^sub>1 :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e\\<^sub>0,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e\\<^sub>0 :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                     \\<Longrightarrow> throw e = ei \\<and> s\\<^sub>1 = si\" by fact+\n  from wt obtain T' where wte0:\"P,E \\<turnstile> e\\<^sub>0 :: T'\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix s w \n    assume eval_val:\"P,E \\<turnstile> \\<langle>e\\<^sub>0,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<rangle>\"\n    from IH[OF eval_val wte0 sconf] show \"throw e = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix ex \n    assume eval_throw:\"P,E \\<turnstile> \\<langle>e\\<^sub>0,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2\\<rangle>\" and e2:\"e\\<^sub>2 = throw ex\"\n    from IH[OF eval_throw wte0 sconf] e2 show \"throw e = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nnext\n  case (CondT E e s\\<^sub>0 s\\<^sub>1 e\\<^sub>1 e' s\\<^sub>2 e\\<^sub>2 e\\<^sub>2' s\\<^sub>2' T)\n  have eval:\"P,E \\<turnstile> \\<langle>if (e) e\\<^sub>1 else e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2',s\\<^sub>2'\\<rangle>\"\n    and wt:\"P,E \\<turnstile> if (e) e\\<^sub>1 else e\\<^sub>2 :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH1:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk> \n                    \\<Longrightarrow> true = ei \\<and> s\\<^sub>1 = si\"\n    and IH2:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e\\<^sub>1 :: T; P,E \\<turnstile> s\\<^sub>1 \\<surd>\\<rbrakk> \n                    \\<Longrightarrow> e' = ei \\<and> s\\<^sub>2 = si\" by fact+\n  from wt have wte:\"P,E \\<turnstile> e :: Boolean\" and wte1:\"P,E \\<turnstile> e\\<^sub>1 :: T\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix s \n    assume eval_true:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>true,s\\<rangle>\" and eval':\"P,E \\<turnstile> \\<langle>e\\<^sub>1,s\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2',s\\<^sub>2'\\<rangle>\"\n    from IH1[OF eval_true wte sconf] have eq:\"s = s\\<^sub>1\" by simp\n    with wf eval_true wte sconf have \"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n    from IH2[OF eval'[simplified eq] wte1 this] show \"e' = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\" .\n  next\n    fix s assume eval_false:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>false,s\\<rangle>\"\n    from IH1[OF eval_false wte sconf] show \"e' = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n  next\n    fix ex assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2'\\<rangle>\"\n    from IH1[OF eval_throw wte sconf] show \"e' = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n  qed\nnext\n  case (CondF E e s\\<^sub>0 s\\<^sub>1 e\\<^sub>2 e' s\\<^sub>2 e\\<^sub>1 e\\<^sub>2' s\\<^sub>2' T)\n  have eval:\"P,E \\<turnstile> \\<langle>if (e) e\\<^sub>1 else e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2',s\\<^sub>2'\\<rangle>\"\n    and wt:\"P,E \\<turnstile> if (e) e\\<^sub>1 else e\\<^sub>2 :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH1:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk> \n                    \\<Longrightarrow> false = ei \\<and> s\\<^sub>1 = si\"\n    and IH2:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e\\<^sub>2 :: T; P,E \\<turnstile> s\\<^sub>1 \\<surd>\\<rbrakk> \n                    \\<Longrightarrow> e' = ei \\<and> s\\<^sub>2 = si\" by fact+\n  from wt have wte:\"P,E \\<turnstile> e :: Boolean\" and wte2:\"P,E \\<turnstile> e\\<^sub>2 :: T\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix s \n    assume eval_true:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>true,s\\<rangle>\"\n    from IH1[OF eval_true wte sconf] show \"e' = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n  next\n    fix s\n    assume eval_false:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>false,s\\<rangle>\"\n      and eval':\"P,E \\<turnstile> \\<langle>e\\<^sub>2,s\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2',s\\<^sub>2'\\<rangle>\"\n    from IH1[OF eval_false wte sconf] have eq:\"s = s\\<^sub>1\" by simp\n    with wf eval_false wte sconf have \"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n    from IH2[OF eval'[simplified eq] wte2 this] show \"e' = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\" .\n  next\n    fix ex assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2'\\<rangle>\"\n    from IH1[OF eval_throw wte sconf] show \"e' = e\\<^sub>2' \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n  qed\nnext\n  case (CondThrow E e s\\<^sub>0 e' s\\<^sub>1 e\\<^sub>1 e\\<^sub>2 e\\<^sub>2' s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>if (e) e\\<^sub>1 else e\\<^sub>2,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2',s\\<^sub>2\\<rangle>\"\n    and wt:\"P,E \\<turnstile> if (e) e\\<^sub>1 else e\\<^sub>2 :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk> \n                    \\<Longrightarrow> throw e' = ei \\<and> s\\<^sub>1 = si\" by fact+\n  from wt have wte:\"P,E \\<turnstile> e :: Boolean\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix s \n    assume eval_true:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>true,s\\<rangle>\"\n    from IH[OF eval_true wte sconf] show \"throw e' = e\\<^sub>2' \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix s assume eval_false:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>false,s\\<rangle>\"\n    from IH[OF eval_false wte sconf] show \"throw e' = e\\<^sub>2' \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix ex\n    assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2\\<rangle>\" and e2':\"e\\<^sub>2' = throw ex\"\n    from IH[OF eval_throw wte sconf] e2' show \"throw e' = e\\<^sub>2' \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nnext\n  case (WhileF E e s\\<^sub>0 s\\<^sub>1 c e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>while (e) c,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and wt:\"P,E \\<turnstile> while (e) c :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>e\\<^sub>2 s\\<^sub>2 T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk> \n                    \\<Longrightarrow> false = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by fact+\n  from wt have wte:\"P,E \\<turnstile> e :: Boolean\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    assume eval_false:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>false,s\\<^sub>2\\<rangle>\" and e2:\"e\\<^sub>2 = unit\"\n    from IH[OF eval_false wte sconf] e2 show \"unit = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix s s' w\n    assume eval_true:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>true,s\\<rangle>\"\n    from IH[OF eval_true wte sconf] show \"unit = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix ex assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_throw wte sconf] show \"unit = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix ex s\n    assume eval_true:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>true,s\\<rangle>\"\n    from IH[OF eval_true wte sconf] show \"unit = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nnext\n  case (WhileT E e s\\<^sub>0 s\\<^sub>1 c v\\<^sub>1 s\\<^sub>2 e\\<^sub>3 s\\<^sub>3 e\\<^sub>2 s\\<^sub>2' T)\n  have eval:\"P,E \\<turnstile> \\<langle>while (e) c,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2'\\<rangle>\"\n    and wt:\"P,E \\<turnstile> while (e) c :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH1:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk> \n                    \\<Longrightarrow> true = ei \\<and> s\\<^sub>1 = si\"\n    and IH2:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>c,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> c :: T; P,E \\<turnstile> s\\<^sub>1 \\<surd>\\<rbrakk> \n                    \\<Longrightarrow> Val v\\<^sub>1 = ei \\<and> s\\<^sub>2 = si\"\n    and IH3:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>while (e) c,s\\<^sub>2\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> while (e) c :: T; \n                         P,E \\<turnstile> s\\<^sub>2 \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> e\\<^sub>3 = ei \\<and> s\\<^sub>3 = si\" by fact+\n  from wt obtain T' where wte:\"P,E \\<turnstile> e :: Boolean\" and wtc:\"P,E \\<turnstile> c :: T'\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    assume eval_false:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>false,s\\<^sub>2'\\<rangle>\"\n    from IH1[OF eval_false wte sconf] show \"e\\<^sub>3 = e\\<^sub>2 \\<and> s\\<^sub>3 = s\\<^sub>2'\" by simp\n  next\n    fix s s' w\n    assume eval_true:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>true,s\\<rangle>\" \n      and eval_val:\"P,E \\<turnstile> \\<langle>c,s\\<rangle> \\<Rightarrow> \\<langle>Val w,s'\\<rangle>\"\n      and eval_while:\"P,E \\<turnstile> \\<langle>while (e) c,s'\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2'\\<rangle>\"\n    from IH1[OF eval_true wte sconf] have eq:\"s = s\\<^sub>1\" by simp\n    with wf eval_true wte sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n   from IH2[OF eval_val[simplified eq] wtc this] have eq':\"s' = s\\<^sub>2\" by simp\n   with wf eval_val wtc sconf' eq have \"P,E \\<turnstile> s\\<^sub>2 \\<surd>\"\n     by(fastforce intro:eval_preserves_sconf)\n   from IH3[OF eval_while[simplified eq'] wt this] show \"e\\<^sub>3 = e\\<^sub>2 \\<and> s\\<^sub>3 = s\\<^sub>2'\" .\n next\n   fix ex assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2'\\<rangle>\"\n   from IH1[OF eval_throw wte sconf] show \"e\\<^sub>3 = e\\<^sub>2 \\<and> s\\<^sub>3 = s\\<^sub>2'\" by simp\n next\n   fix ex s\n   assume eval_true:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>true,s\\<rangle>\" \n     and eval_throw:\"P,E \\<turnstile> \\<langle>c,s\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2'\\<rangle>\"\n    from IH1[OF eval_true wte sconf] have eq:\"s = s\\<^sub>1\" by simp\n    with wf eval_true wte sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n   from IH2[OF eval_throw[simplified eq] wtc this] show \"e\\<^sub>3 = e\\<^sub>2 \\<and> s\\<^sub>3 = s\\<^sub>2'\" by simp\n qed\nnext\n  case (WhileCondThrow E e s\\<^sub>0 e' s\\<^sub>1 c e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>while (e) c,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and wt:\"P,E \\<turnstile> while (e) c :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> throw e' = ei \\<and> s\\<^sub>1 = si\" by fact+\n  from wt have wte:\"P,E \\<turnstile> e :: Boolean\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    assume eval_false:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>false,s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_false wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix s s' w\n    assume eval_true:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>true,s\\<rangle>\"\n    from IH[OF eval_true wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix ex \n    assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2\\<rangle>\" and e2:\"e\\<^sub>2 = throw ex\"\n    from IH[OF eval_throw wte sconf] e2 show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix ex s\n    assume eval_true:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>true,s\\<rangle>\"\n    from IH[OF eval_true wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nnext\n  case (WhileBodyThrow E e s\\<^sub>0 s\\<^sub>1 c e' s\\<^sub>2 e\\<^sub>2 s\\<^sub>2' T)\n  have eval:\"P,E \\<turnstile> \\<langle>while (e) c,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2'\\<rangle>\"\n    and wt:\"P,E \\<turnstile> while (e) c :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH1:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk> \n                    \\<Longrightarrow> true = ei \\<and> s\\<^sub>1 = si\"\n    and IH2:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>c,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> c :: T; P,E \\<turnstile> s\\<^sub>1 \\<surd>\\<rbrakk>\n                   \\<Longrightarrow> throw e' = ei \\<and> s\\<^sub>2 = si\" by fact+\n  from wt obtain T' where wte:\"P,E \\<turnstile> e :: Boolean\" and wtc:\"P,E \\<turnstile> c :: T'\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    assume eval_false:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>false,s\\<^sub>2'\\<rangle>\"\n    from IH1[OF eval_false wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n  next\n    fix s s' w\n    assume eval_true:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>true,s\\<rangle>\" \n      and eval_val:\"P,E \\<turnstile> \\<langle>c,s\\<rangle> \\<Rightarrow> \\<langle>Val w,s'\\<rangle>\"\n    from IH1[OF eval_true wte sconf] have eq:\"s = s\\<^sub>1\" by simp\n    with wf eval_true wte sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n   from IH2[OF eval_val[simplified eq] wtc this] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\"\n     by simp\n next\n   fix ex assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2'\\<rangle>\"\n   from IH1[OF eval_throw wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n next\n   fix ex s\n   assume eval_true:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>true,s\\<rangle>\" \n     and eval_throw:\"P,E \\<turnstile> \\<langle>c,s\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2'\\<rangle>\" and e2:\"e\\<^sub>2 = throw ex\"\n   from IH1[OF eval_true wte sconf] have eq:\"s = s\\<^sub>1\" by simp\n    with wf eval_true wte sconf have sconf':\"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n   from IH2[OF eval_throw[simplified eq] wtc this] e2 show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\"\n     by simp\n qed\nnext\n  case (Throw E e s\\<^sub>0 r s\\<^sub>1 e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>throw e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and wt:\"P,E \\<turnstile> throw e :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk> \n                   \\<Longrightarrow> ref r = ei \\<and> s\\<^sub>1 = si\" by fact+\n  from wt obtain C where wte:\"P,E \\<turnstile> e :: Class C\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix r'\n    assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref r',s\\<^sub>2\\<rangle>\" and e2:\"e\\<^sub>2 = Throw r'\"\n    from IH[OF eval_ref wte sconf] e2 show \"Throw r = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_null wte sconf] show \"Throw r = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix ex assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_throw wte sconf] show \"Throw r = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nnext\n  case (ThrowNull E e s\\<^sub>0 s\\<^sub>1 e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>throw e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and wt:\"P,E \\<turnstile> throw e :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk> \n                   \\<Longrightarrow> null = ei \\<and> s\\<^sub>1 = si\" by fact+\n  from wt obtain C where wte:\"P,E \\<turnstile> e :: Class C\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix r' assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref r',s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_ref wte sconf] show \"THROW NullPointer = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>2\\<rangle>\" and e2:\"e\\<^sub>2 = THROW NullPointer\"\n    from IH[OF eval_null wte sconf] e2 show \"THROW NullPointer = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" \n      by simp\n  next\n    fix ex assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_throw wte sconf] show \"THROW NullPointer = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nnext\n  case (ThrowThrow E e s\\<^sub>0 e' s\\<^sub>1 e\\<^sub>2 s\\<^sub>2 T)\n  have eval:\"P,E \\<turnstile> \\<langle>throw e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and wt:\"P,E \\<turnstile> throw e :: T\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk> \n                    \\<Longrightarrow> throw e' = ei \\<and> s\\<^sub>1 = si\" by fact+\n  from wt obtain C where wte:\"P,E \\<turnstile> e :: Class C\" by auto\n  from eval show ?case\n  proof(rule eval_cases)\n    fix r' assume eval_ref:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ref r',s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_ref wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    assume eval_null:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>null,s\\<^sub>2\\<rangle>\"\n    from IH[OF eval_null wte sconf] show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix ex \n    assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2\\<rangle>\" and e2:\"e\\<^sub>2 = throw ex\"\n    from IH[OF eval_throw wte sconf] e2 show \"throw e' = e\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nnext\n  case Nil thus ?case by (auto elim:evals_cases)\nnext\n  case (Cons E e s\\<^sub>0 v s\\<^sub>1 es es' s\\<^sub>2 es\\<^sub>2 s\\<^sub>2' Ts)\n  have evals:\"P,E \\<turnstile> \\<langle>e#es,s\\<^sub>0\\<rangle> [\\<Rightarrow>] \\<langle>es\\<^sub>2,s\\<^sub>2'\\<rangle>\"\n    and wt:\"P,E \\<turnstile> e#es [::] Ts\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH1:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk> \n                    \\<Longrightarrow> Val v = ei \\<and> s\\<^sub>1 = si\"\n    and IH2:\"\\<And>esi si Ts. \\<lbrakk>P,E \\<turnstile> \\<langle>es,s\\<^sub>1\\<rangle> [\\<Rightarrow>] \\<langle>esi,si\\<rangle>; P,E \\<turnstile> es [::] Ts; P,E \\<turnstile> s\\<^sub>1 \\<surd>\\<rbrakk>\n                    \\<Longrightarrow> es' = esi \\<and> s\\<^sub>2 = si\" by fact+\n  from wt obtain T' Ts' where Ts:\"Ts = T'#Ts'\" by(cases Ts) auto\n  with wt have wte:\"P,E \\<turnstile> e :: T'\" and wtes:\"P,E \\<turnstile> es [::] Ts'\" by auto\n  from evals show ?case\n  proof(rule evals_cases)\n    fix es'' s w\n    assume eval_val:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<rangle>\"\n      and evals_vals:\"P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>es'',s\\<^sub>2'\\<rangle>\" and es2:\"es\\<^sub>2 = Val w#es''\"\n    from IH1[OF eval_val wte sconf] have s:\"s = s\\<^sub>1\" and v:\"v = w\" by simp_all\n    with wf eval_val wte sconf have \"P,E \\<turnstile> s\\<^sub>1 \\<surd>\"\n      by(fastforce intro:eval_preserves_sconf)\n    from IH2[OF evals_vals[simplified s] wtes this] have \"es' = es'' \\<and> s\\<^sub>2 = s\\<^sub>2'\" .\n    with es2 v show \"Val v # es' = es\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n  next\n    fix ex assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2'\\<rangle>\"\n    from IH1[OF eval_throw wte sconf] show \"Val v # es' = es\\<^sub>2 \\<and> s\\<^sub>2 = s\\<^sub>2'\" by simp\n  qed\nnext\n  case (ConsThrow E e s\\<^sub>0 e' s\\<^sub>1 es es\\<^sub>2 s\\<^sub>2 Ts)\n  have evals:\"P,E \\<turnstile> \\<langle>e#es,s\\<^sub>0\\<rangle> [\\<Rightarrow>] \\<langle>es\\<^sub>2,s\\<^sub>2\\<rangle>\"\n    and wt:\"P,E \\<turnstile> e#es [::] Ts\" and sconf:\"P,E \\<turnstile> s\\<^sub>0 \\<surd>\"\n    and IH:\"\\<And>ei si T. \\<lbrakk>P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>ei,si\\<rangle>; P,E \\<turnstile> e :: T; P,E \\<turnstile> s\\<^sub>0 \\<surd>\\<rbrakk> \n                    \\<Longrightarrow> throw e' = ei \\<and> s\\<^sub>1 = si\" by fact+\n  from wt obtain T' Ts' where Ts:\"Ts = T'#Ts'\" by(cases Ts) auto\n  with wt have wte:\"P,E \\<turnstile> e :: T'\" by auto\n  from evals show ?case\n  proof(rule evals_cases)\n    fix es'' s w\n    assume eval_val:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>Val w,s\\<rangle>\"\n    from IH[OF eval_val wte sconf] show \"throw e'#es = es\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  next\n    fix ex \n    assume eval_throw:\"P,E \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<Rightarrow> \\<langle>throw ex,s\\<^sub>2\\<rangle>\" and es2:\"es\\<^sub>2 = throw ex#es\"\n    from IH[OF eval_throw wte sconf] es2 show \"throw e'#es = es\\<^sub>2 \\<and> s\\<^sub>1 = s\\<^sub>2\" by simp\n  qed\nqed\n\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/CoreC++/Determinism.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.293560766853691}}
{"text": "section \\<open>Lifting theorems onto filters\\<close>\ntheory Eventuallize\n  imports Complex_Main\nbegin\n\ntext \\<open>\n  The following attribute and ML function lift a given theorem of the form\n    \\<^prop>\\<open>\\<forall>x. A x \\<longrightarrow> B x \\<longrightarrow> C x\\<close>\n  to\n    \\<^prop>\\<open>eventually A F \\<Longrightarrow> eventually B F \\<Longrightarrow> eventually C F\\<close> .\n\\<close>\n\nML \\<open>\nsignature EVENTUALLIZE =\nsig\nval eventuallize : Proof.context -> thm -> int option -> thm\nend\n\nstructure Eventuallize : EVENTUALLIZE =\nstruct\n\nfun dest_All (Const (\\<^const_name>\\<open>HOL.All\\<close>, _) $ Abs (x, T, t)) = (x, T, t)\n  | dest_All (Const (\\<^const_name>\\<open>HOL.All\\<close>, T) $ f) =\n      (\"x\", T |> dest_funT |> fst |> dest_funT |> fst, f $ Bound 0)\n  | dest_All t = raise TERM (\"dest_All\", [t])\n\nfun strip_imp (\\<^term>\\<open>(\\<longrightarrow>)\\<close> $ a $ b) = apfst (cons a) (strip_imp b)\n  | strip_imp t = ([], t)\n\nfun eventuallize ctxt thm n =\n  let\n    fun err n = raise THM (\"Invalid index in eventuallize: \" ^ Int.toString n, 0, [thm])\n    val n_max =\n      thm |> Thm.concl_of |> HOLogic.dest_Trueprop |> dest_All |> #3 |> strip_imp |> fst |> length\n    val _ = case n of NONE => () | SOME n =>\n      if n >= 0 andalso n <= n_max then () else err n\n    val n = case n of SOME n => n | NONE => n_max\n    fun conv n =\n      if n < 2 then Conv.all_conv else Conv.arg_conv (conv (n - 1)) then_conv\n        Conv.rewr_conv @{thm eq_reflection[OF imp_conjL [symmetric]]}\n    val conv = Conv.arg_conv (Conv.binder_conv (K (conv n)) ctxt)\n    val thm' = Conv.fconv_rule conv thm\n    fun go n = if n < 2 then @{thm _} else @{thm eventually_conj} OF [@{thm _}, go (n - 1)]\n  in\n    @{thm eventually_rev_mp[OF _ always_eventually]} OF [go n, thm']\n  end\n\nend\n\\<close>\n\nattribute_setup eventuallized = \\<open>\n  Scan.lift (Scan.option Parse.nat) >>\n    (fn n => fn (ctxt, thm) =>\n      (NONE, SOME (Eventuallize.eventuallize (Context.proof_of ctxt) thm n)))\n\\<close>\n\nend", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/Real_Asymp/Eventuallize.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5117166047041652, "lm_q2_score": 0.5736784074525098, "lm_q1q2_score": 0.293560766853691}}
{"text": "section\\<open>PTA Generalisation\\<close>\ntext\\<open>The problem with the simplistic heuristics of \\<^cite>\\<open>\"foster2019\"\\<close> is that the performance of the\nInference technique is almost entirely dependent on the quality and applicability of the heuristics\nprovided to it. Producing high quality heuristics often requires some inside knowledge of the system\nunder inference. If the user has this knowledge already, they are unlikely to require automated\ninference. Ideally, we would like something more generally applicable. This theory presents a more\nabstract \\emph{metaheuristic} which can be implemented with genetic programming.\\<close>\n\ntheory PTA_Generalisation\n  imports \"../Inference\" Same_Register Group_By\nbegin\n\nhide_const I\n\ndatatype value_type = N | S\n\ninstantiation value_type :: linorder begin\nfun less_value_type :: \"value_type \\<Rightarrow> value_type \\<Rightarrow> bool\" where\n  \"less_value_type N S = True\" |\n  \"less_value_type _ _ = False\"\n\ndefinition less_eq_value_type :: \"value_type \\<Rightarrow> value_type \\<Rightarrow> bool\" where\n \"less_eq_value_type v1 v2 \\<equiv> (v1 < v2 \\<or> v1 = v2)\"\n\ninstance\n  apply standard\n  using less_eq_value_type_def less_value_type.elims(2) apply blast\n     apply (simp add: less_eq_value_type_def)\n    apply (metis less_eq_value_type_def value_type.exhaust)\n  using less_eq_value_type_def less_value_type.elims(2) apply blast\n  by (metis less_eq_value_type_def less_value_type.elims(3) value_type.simps(2))\n\nend\n\n\\<comment> \\<open>This is a very hacky way of making sure that things with differently typed outputs don't get\n    lumped together.\\<close>\nfun typeSig :: \"output_function \\<Rightarrow> value_type\" where\n  \"typeSig (L (value.Str _)) = S\" |\n  \"typeSig _ = N\"\n\ndefinition same_structure :: \"transition \\<Rightarrow> transition \\<Rightarrow> bool\" where\n  \"same_structure t1 t2 = (\n    Label t1 = Label t2 \\<and>\n    Arity t1 = Arity t2 \\<and>\n    map typeSig (Outputs t1) = map typeSig (Outputs t2)\n  )\"\n\nlemma same_structure_equiv:\n  \"Outputs t1 = [L (Num m)] \\<Longrightarrow> Outputs t2 = [L (Num n)] \\<Longrightarrow>\n   same_structure t1 t2 = Transition.same_structure t1 t2\"\n  by (simp add: same_structure_def Transition.same_structure_def)\n\ntype_synonym transition_group = \"(tids \\<times> transition) list\"\n\nfun observe_all :: \"iEFSM \\<Rightarrow>  cfstate \\<Rightarrow> registers \\<Rightarrow> trace \\<Rightarrow> transition_group\" where\n  \"observe_all _ _ _ [] = []\" |\n  \"observe_all e s r ((l, i, _)#es)  =\n    (case random_member (i_possible_steps e s r l i)  of\n      (Some (ids, s', t)) \\<Rightarrow> (((ids, t)#(observe_all e s' (evaluate_updates t i r) es))) |\n      _ \\<Rightarrow> []\n    )\"\n\ndefinition transition_groups_exec :: \"iEFSM \\<Rightarrow> trace \\<Rightarrow> (nat \\<times> tids \\<times> transition) list list\" where\n  \"transition_groups_exec e t = group_by (\\<lambda>(_, _, t1) (_, _, t2). same_structure t1 t2) (enumerate 0 (observe_all e 0 <> t))\"\n\ntype_synonym struct = \"(label \\<times> arity \\<times> value_type list)\"\n\ntext\\<open>We need to take the list of transition groups and tag them with the last transition that was\ntaken which had a different structure.\\<close>\nfun tag :: \"struct option \\<Rightarrow> (nat \\<times> tids \\<times> transition) list list \\<Rightarrow> (struct option \\<times> struct \\<times> (nat \\<times> tids \\<times> transition) list) list\" where\n  \"tag _ [] = []\" |\n  \"tag t (g#gs) = (\n    let\n      (_, _, head) = hd g;\n      struct = (Label head, Arity head, map typeSig (Outputs head))\n    in\n    (t, struct, g)#(tag (Some struct) gs)\n  )\"\n\ntext\\<open>We need to group transitions not just by their structure but also by their history - i.e. the\nlast transition which was taken which had a different structure. We need to order these groups by\ntheir relative positions within the traces such that output and update functions can be inferred in\nthe correct order.\\<close>\ndefinition transition_groups :: \"iEFSM \\<Rightarrow> log \\<Rightarrow> transition_group list\" where\n  \"transition_groups e l = (\n    let\n      trace_groups = map (transition_groups_exec e) l;\n      tagged = map (tag None) trace_groups;\n      flat =  sort (fold (@) tagged []);\n      group_fun = fold (\\<lambda>(tag, s, gp) f. f((tag, s) $:= gp@(f$(tag, s)))) flat (K$ []);\n      grouped = map (\\<lambda>x. group_fun $ x) (finfun_to_list group_fun);\n      inx_groups = map (\\<lambda>gp. (Min (set (map fst gp)), map snd gp)) grouped\n    in\n      map snd (sort inx_groups)\n  )\"\n\ntext\\<open>For a given trace group, log, and EFSM, we want to build the training set for that group. That\nis, the set of inputs, registers, and expected outputs from those transitions. To do this, we must\nwalk the traces in the EFSM to obtain the register values.\\<close>\nfun trace_group_training_set :: \"transition_group \\<Rightarrow> iEFSM \\<Rightarrow> cfstate \\<Rightarrow> registers \\<Rightarrow> trace \\<Rightarrow> (inputs \\<times> registers \\<times> value list) list \\<Rightarrow> (inputs \\<times> registers \\<times> value list) list\" where\n  \"trace_group_training_set _ _ _ _ [] train = train\" |\n  \"trace_group_training_set gp e s r ((l, i, p)#t) train = (\n    let\n      (id, s', transition) = fthe_elem (i_possible_steps e s r l i)\n    in\n    if \\<exists>(id', _) \\<in> set gp. id' = id then\n      trace_group_training_set gp e s' (evaluate_updates transition i r) t ((i, r, p)#train)\n    else\n      trace_group_training_set gp e s' (evaluate_updates transition i r) t train\n  )\"\n\ndefinition make_training_set :: \"iEFSM \\<Rightarrow> log \\<Rightarrow> transition_group \\<Rightarrow> (inputs \\<times> registers \\<times> value list) list\" where\n  \"make_training_set e l gp = fold (\\<lambda>h a. trace_group_training_set gp e 0 <> h a) l []\"\n\nprimrec replace_groups :: \"transition_group list \\<Rightarrow> iEFSM \\<Rightarrow> iEFSM\" where\n  \"replace_groups [] e = e\" |\n  \"replace_groups (h#t) e = replace_groups t (fold (\\<lambda>(id, t) acc. replace_transition acc id t) h e)\"\n\nlemma replace_groups_fold [code]:\n  \"replace_groups xs e = fold (\\<lambda>h acc'. (fold (\\<lambda>(id, t) acc. replace_transition acc id t) h acc')) xs e\"\n  by (induct xs arbitrary: e,  auto)\n\ndefinition insert_updates :: \"transition \\<Rightarrow> update_function list \\<Rightarrow> transition\" where\n  \"insert_updates t u = (\n    let\n      \\<comment> \\<open>Want to filter out null updates of the form rn := rn. It doesn't affect anything but it  \\<close>\n      \\<comment> \\<open>does make things look cleaner                                                            \\<close>\n      necessary_updates = filter (\\<lambda>(r, u). u \\<noteq> V (R r)) u\n    in\n    t\\<lparr>Updates := (filter (\\<lambda>(r, _). r \\<notin> set (map fst u)) (Updates t))@necessary_updates\\<rparr>\n  )\"\n\nfun add_groupwise_updates_trace :: \"trace  \\<Rightarrow> (tids \\<times> update_function list) list \\<Rightarrow> iEFSM \\<Rightarrow> cfstate \\<Rightarrow> registers \\<Rightarrow> iEFSM\" where\n  \"add_groupwise_updates_trace [] _ e _ _ = e\" |\n  \"add_groupwise_updates_trace ((l, i, _)#trace) funs e s r = (\n    let\n      (id, s', t) = fthe_elem (i_possible_steps e s r l i);\n      updated = evaluate_updates t i r;\n      newUpdates = List.maps snd (filter (\\<lambda>(tids, _). set id \\<subseteq> set tids) funs);\n      t' = insert_updates t newUpdates;\n      updated' = apply_updates (Updates t') (join_ir i r) r;\n      necessaryUpdates = filter (\\<lambda>(r, _). updated $ r \\<noteq> updated' $ r) newUpdates;\n      t'' = insert_updates t necessaryUpdates;\n      e' = replace_transition e id t''\n    in\n    add_groupwise_updates_trace trace funs e' s' updated'\n  )\"\n\nprimrec add_groupwise_updates :: \"log  \\<Rightarrow> (tids \\<times> update_function list) list \\<Rightarrow> iEFSM \\<Rightarrow> iEFSM\" where\n  \"add_groupwise_updates [] _ e = e\" |\n  \"add_groupwise_updates (h#t) funs e = add_groupwise_updates t funs (add_groupwise_updates_trace h funs e 0 <>)\"\n\nlemma fold_add_groupwise_updates [code]:\n  \"add_groupwise_updates log funs e = fold (\\<lambda>trace acc. add_groupwise_updates_trace trace funs acc 0 <>) log e\"\n  by (induct log arbitrary: e, auto)\n\n\\<comment> \\<open>This will be replaced to calls to Z3 in the executable\\<close>\ndefinition get_regs :: \"(vname \\<Rightarrow>f String.literal) \\<Rightarrow> inputs \\<Rightarrow> vname aexp \\<Rightarrow> value \\<Rightarrow> registers\" where\n  \"get_regs types inputs expression output = Eps (\\<lambda>r. aval expression (join_ir inputs r) = Some output)\"\n\ndeclare get_regs_def [code del]\ncode_printing constant get_regs \\<rightharpoonup> (Scala) \"Dirties.getRegs\"\n\ntype_synonym action_info = \"(cfstate \\<times> registers \\<times> registers \\<times> inputs \\<times> tids \\<times> transition)\"\ntype_synonym run_info = \"action_info list\"\ntype_synonym targeted_run_info = \"(registers \\<times> action_info) list\"\n\nfun everything_walk :: \"output_function \\<Rightarrow> nat \\<Rightarrow> (vname \\<Rightarrow>f String.literal) \\<Rightarrow> trace \\<Rightarrow> iEFSM \\<Rightarrow> cfstate \\<Rightarrow> registers \\<Rightarrow> transition_group \\<Rightarrow> run_info\" where\n  \"everything_walk _ _ _ [] _ _ _ _ = []\" |\n  \"everything_walk f fi types ((label, inputs, outputs)#t) oPTA s regs gp  = (\n    let (tid, s', ta) = fthe_elem (i_possible_steps oPTA s regs label inputs) in\n     \\<comment> \\<open>Possible steps with a transition we need to modify\\<close>\n    if \\<exists>(tid', _) \\<in> set gp. tid = tid' then\n      (s, regs, get_regs types inputs f (outputs!fi), inputs, tid, ta)#(everything_walk f fi types t oPTA s' (evaluate_updates ta inputs regs) gp)\n    else\n      let empty = <> in\n      (s, regs, empty, inputs, tid, ta)#(everything_walk f fi types t oPTA s' (evaluate_updates ta inputs regs) gp)\n  )\"\n\ndefinition everything_walk_log :: \"output_function \\<Rightarrow> nat \\<Rightarrow> (vname \\<Rightarrow>f String.literal) \\<Rightarrow> log \\<Rightarrow> iEFSM \\<Rightarrow> transition_group \\<Rightarrow> run_info list\" where\n  \"everything_walk_log f fi types log e gp = map (\\<lambda>t. everything_walk f fi types t e 0 <> gp) log\"\n\nfun target :: \"registers \\<Rightarrow> run_info \\<Rightarrow> targeted_run_info\" where\n  \"target _ [] = []\" |\n  \"target tRegs ((s, oldregs, regs, inputs, tid, ta)#t) = (\n    let newTarget = if finfun_to_list regs = [] then tRegs else regs in\n    (tRegs, s, oldregs, regs, inputs, tid, ta)#target newTarget t\n  )\"\n\nfun target_tail :: \"registers \\<Rightarrow> run_info \\<Rightarrow> targeted_run_info \\<Rightarrow> targeted_run_info\" where\n  \"target_tail _ [] tt = rev tt\" |\n  \"target_tail tRegs ((s, oldregs, regs, inputs, tid, ta)#t) tt = (\n    let newTarget = if finfun_to_list regs = [] then tRegs else regs in\n    target_tail newTarget t ((tRegs, s, oldregs, regs, inputs, tid, ta)#tt)\n  )\"\n\nlemma target_tail: \"(rev bs)@(target tRegs ts) = target_tail tRegs ts bs\"\nproof(induct ts arbitrary: bs tRegs)\n  case (Cons a ts)\n  then show ?case\n    apply (cases a)\n    apply simp\n    apply standard\n    by (metis (no_types, lifting) append_eq_append_conv2 rev.simps(2) rev_append rev_swap self_append_conv2)+\nqed simp\n\ndefinition \"target_fold tRegs ts b = fst (fold (\\<lambda>(s, oldregs, regs, inputs, tid, ta) (acc, tRegs).\nlet newTarget = if finfun_to_list regs = [] then tRegs else regs in\n    (acc@[(tRegs, s, oldregs, regs, inputs, tid, ta)], newTarget)\n) ts (rev b, tRegs))\"\n\nlemma target_tail_fold: \"target_tail tRegs ts b = target_fold tRegs ts b\"\nproof(induct ts arbitrary: tRegs b)\n  case Nil\n  then show ?case\n    by (simp add: target_fold_def)\nnext\n  case (Cons a ts)\n  then show ?case\n    apply (cases a)\n    by (simp add: target_fold_def)\nqed\n\nlemma target_fold [code]: \"target tRegs ts = target_fold tRegs ts []\"\n  by (metis append_self_conv2 rev.simps(1) target_tail_fold target_tail)\n\n\\<comment> \\<open>This will be replaced by symbolic regression in the executable\\<close>\ndefinition get_update :: \"label \\<Rightarrow> nat \\<Rightarrow> value list \\<Rightarrow> (inputs \\<times> registers \\<times> registers) list \\<Rightarrow> vname aexp option\" where\n  \"get_update _ reg values train = (let\n    possible_funs = {a. \\<forall>(i, r, r') \\<in> set train. aval a (join_ir i r) = r' $ reg}\n    in\n    if possible_funs = {} then None else Some (Eps (\\<lambda>x. x \\<in> possible_funs))\n  )\"\n\ndeclare get_update_def [code del]\ncode_printing constant get_update \\<rightharpoonup> (Scala) \"Dirties.getUpdate\"\n\ndefinition get_updates_opt :: \"label \\<Rightarrow> value list \\<Rightarrow> (inputs \\<times> registers \\<times> registers) list \\<Rightarrow> (nat \\<times> vname aexp option) list\" where\n  \"get_updates_opt l values train = (let\n    updated_regs = fold List.union (map (finfun_to_list \\<circ> snd \\<circ> snd) train) [] in\n    map (\\<lambda>r.\n      let targetValues = remdups (map (\\<lambda>(_, _, regs). regs $ r) train) in\n      if  (\\<forall>(_, anteriorRegs, posteriorRegs) \\<in> set train. anteriorRegs $ r = posteriorRegs $ r) then\n        (r, Some (V (R r)))\n      else if length targetValues = 1 \\<and> (\\<forall>(inputs, anteriorRegs, _) \\<in> set train. finfun_to_list anteriorRegs = []) then\n        case hd targetValues of Some v \\<Rightarrow>\n        (r, Some (L v))\n      else\n        (r, get_update l r values train)\n    ) updated_regs\n  )\"\n\ndefinition finfun_add :: \"(('a::linorder) \\<Rightarrow>f 'b) \\<Rightarrow> ('a \\<Rightarrow>f 'b) \\<Rightarrow> ('a \\<Rightarrow>f 'b)\" where\n  \"finfun_add a b = fold (\\<lambda>k f. f(k $:= b $ k)) (finfun_to_list b) a\"\n\ndefinition group_update :: \"value list \\<Rightarrow> targeted_run_info \\<Rightarrow> (tids \\<times> (nat \\<times> vname aexp) list) option\" where\n  \"group_update values l = (\n    let\n      (_, (_, _, _, _, _, t)) = hd l;\n      targeted = filter (\\<lambda>(regs, _). finfun_to_list regs \\<noteq> []) l;\n      maybe_updates = get_updates_opt (Label t) values (map (\\<lambda>(tRegs, s, oldRegs, regs, inputs, tid, ta). (inputs, finfun_add oldRegs regs, tRegs)) targeted)\n    in\n    if \\<exists>(_, f_opt) \\<in> set maybe_updates. f_opt = None then\n      None\n    else\n      Some (fold List.union (map (\\<lambda>(tRegs, s, oldRegs, regs, inputs, tid, ta). tid) l) [], map (\\<lambda>(r, f_o). (r, the f_o)) maybe_updates)\n  )\"\n\nfun groupwise_put_updates :: \"transition_group list \\<Rightarrow> log \\<Rightarrow> value list \\<Rightarrow> run_info list \\<Rightarrow> (nat \\<times> (vname aexp \\<times> vname \\<Rightarrow>f String.literal)) \\<Rightarrow> iEFSM \\<Rightarrow> iEFSM\" where\n  \"groupwise_put_updates [] _ _ _ _  e = e\" |\n  \"groupwise_put_updates (gp#gps) log values walked (o_inx, (op, types)) e = (\n    let\n      targeted = map (\\<lambda>x. filter (\\<lambda>(_, _, _, _, _, id, tran). (id, tran) \\<in> set gp) x) (map (\\<lambda>w. rev (target <> (rev w))) walked);\n      group = fold List.union targeted []\n    in\n    case group_update values group of\n      None \\<Rightarrow> groupwise_put_updates gps log values walked (o_inx, (op, types)) e |\n      Some u \\<Rightarrow> groupwise_put_updates gps log values walked (o_inx, (op, types)) (make_distinct (add_groupwise_updates log [u] e))\n  )\"\n\ndefinition updates_for_output :: \"log \\<Rightarrow> value list \\<Rightarrow> transition_group \\<Rightarrow> nat \\<Rightarrow> vname aexp \\<Rightarrow> vname \\<Rightarrow>f String.literal \\<Rightarrow> iEFSM \\<Rightarrow> iEFSM\" where\n\"updates_for_output log values current o_inx op types e = (\n  if AExp.enumerate_regs op = {} then e\n  else\n    let\n      walked = everything_walk_log op o_inx types log e current;\n      groups = transition_groups e log\n    in\n    groupwise_put_updates groups log values walked (o_inx, (op, types)) e\n  )\"\n\ntype_synonym output_types = \"(vname aexp \\<times> vname \\<Rightarrow>f String.literal)\"\n\nfun put_updates :: \"log \\<Rightarrow> value list \\<Rightarrow> transition_group \\<Rightarrow> (nat \\<times> output_types option) list \\<Rightarrow> iEFSM \\<Rightarrow> iEFSM\" where\n  \"put_updates _ _ _ [] e = e\" |\n  \"put_updates log values gp ((_, None)#ops) e = put_updates log values gp ops e\" |\n  \"put_updates log values gp ((o_inx, Some (op, types))#ops) e = (\n    let\n      gp' = map (\\<lambda>(id, t). (id, t\\<lparr>Outputs := list_update (Outputs t) o_inx op\\<rparr>)) gp;\n      generalised_model = fold (\\<lambda>(id, t) acc. replace_transition acc id t) gp' e;\n      e' = updates_for_output log values gp o_inx op types generalised_model\n    in\n    if accepts_log (set log) (tm e') then\n     put_updates log values gp' ops e'\n    else\n     put_updates log values gp ops e\n  )\"\n\nfun unzip_3 :: \"('a \\<times> 'b \\<times> 'c) list \\<Rightarrow> ('a list \\<times> 'b list \\<times> 'c list)\" where\n  \"unzip_3 [] = ([], [], [])\" |\n  \"unzip_3 ((a, b, c)#l) = (\n    let (as, bs, cs) = unzip_3 l in\n    (a#as, b#bs, c#cs)\n  )\"\n\nlemma unzip_3: \"unzip_3 l = (map fst l, map (fst \\<circ> snd) l, map (snd \\<circ> snd) l)\"\n  by (induct l, auto)\n\nfun unzip_3_tailrec_rev :: \"('a \\<times> 'b \\<times> 'c) list \\<Rightarrow> ('a list \\<times> 'b list \\<times> 'c list) \\<Rightarrow> ('a list \\<times> 'b list \\<times> 'c list)\" where\n  \"unzip_3_tailrec_rev [] (as, bs, cs) = (as, bs, cs)\" |\n  \"unzip_3_tailrec_rev ((a, b, c)#t) (as, bs, cs) = unzip_3_tailrec_rev t (a#as, b#bs, c#cs)\"\n\nlemma unzip_3_tailrec_rev: \"unzip_3_tailrec_rev l (as, bs, cs) = ((map_tailrec_rev fst l as), (map_tailrec_rev (fst \\<circ> snd) l bs), (map_tailrec_rev (snd \\<circ> snd) l cs))\"\n  by (induct l arbitrary: as bs cs, auto)\n\ndefinition \"unzip_3_tailrec l = (let (as, bs, cs) = unzip_3_tailrec_rev l ([],[],[]) in (rev as, rev bs, rev cs))\"\n\nlemma unzip_3_tailrec [code]: \"unzip_3 l = unzip_3_tailrec l\"\n  apply (simp only: unzip_3_tailrec_def unzip_3_tailrec_rev)\n  by (simp add: Let_def map_tailrec_rev unzip_3 map_eq_map_tailrec)\n\ntext\\<open>We want to return an aexp which, when evaluated in the correct context accounts for the literal\ninput-output pairs within the training set. This will be replaced by symbolic regression in the\nexecutable\\<close>\ndefinition get_output :: \"label \\<Rightarrow> nat \\<Rightarrow> value list \\<Rightarrow> (inputs \\<times> registers \\<times> value) list \\<Rightarrow> (vname aexp \\<times> (vname \\<Rightarrow>f String.literal)) option\" where\n  \"get_output _ maxReg values train = (let\n    possible_funs = {a. \\<forall>(i, r, p) \\<in> set train. aval a (join_ir i r) = Some p}\n    in\n    if possible_funs = {} then None else Some (Eps (\\<lambda>x. x \\<in> possible_funs), (K$ STR ''int''))\n  )\"\ndeclare get_output_def [code del]\ncode_printing constant get_output \\<rightharpoonup> (Scala) \"Dirties.getOutput\"\n\ndefinition get_outputs :: \"label \\<Rightarrow> nat \\<Rightarrow> value list \\<Rightarrow> inputs list \\<Rightarrow> registers list \\<Rightarrow> value list list \\<Rightarrow> (vname aexp \\<times> (vname \\<Rightarrow>f String.literal)) option list\" where\n  \"get_outputs l maxReg values I r outputs = map_tailrec (\\<lambda>(maxReg, ps). get_output l maxReg values (zip I (zip r ps))) (enumerate maxReg (transpose outputs))\"\n\ndefinition enumerate_exec_values :: \"trace \\<Rightarrow> value list\" where\n  \"enumerate_exec_values vs = fold (\\<lambda>(_, i, p) I. List.union (List.union i p) I) vs []\"\n\ndefinition enumerate_log_values :: \"log \\<Rightarrow> value list\" where\n  \"enumerate_log_values l = fold (\\<lambda>e I. List.union (enumerate_exec_values e) I) l []\"\n\n(*This is where the types stuff originates*)\ndefinition generalise_and_update :: \"log \\<Rightarrow> iEFSM \\<Rightarrow> transition_group \\<Rightarrow> iEFSM\" where\n  \"generalise_and_update log e gp = (\n    let\n      label = Label (snd (hd gp));\n      values = enumerate_log_values log;\n      new_gp_ts = make_training_set e log gp;\n      (I, R, P) = unzip_3 new_gp_ts;\n      max_reg = max_reg_total e;\n      outputs = get_outputs label max_reg values I R P\n    in\n      put_updates log values gp (enumerate 0 outputs) e\n  )\"\n\ntext \\<open>Splitting structural groups up into subgroups by previous transition can cause different\nsubgroups to get different updates. We ideally want structural groups to have the same output and\nupdate functions, as structural groups are likely to be instances of the same underlying behaviour.\\<close>\ndefinition standardise_group :: \"iEFSM \\<Rightarrow> log \\<Rightarrow> transition_group \\<Rightarrow> (iEFSM \\<Rightarrow> log \\<Rightarrow> transition_group \\<Rightarrow> transition_group) \\<Rightarrow> iEFSM\" where\n  \"standardise_group e l gp s = (\n    let\n      standardised = s e l gp;\n      e' = replace_transitions e standardised\n    in\n      if e' = e then e else\n      if accepts_log (set l) (tm e') then e' else e\n)\"\n\nprimrec find_outputs :: \"output_function list list \\<Rightarrow> iEFSM \\<Rightarrow> log \\<Rightarrow> transition_group \\<Rightarrow> output_function list option\" where\n  \"find_outputs [] _ _ _ = None\" |\n  \"find_outputs (h#t) e l g = (\n    let\n      outputs = fold (\\<lambda>(tids, t) acc. replace_transition acc tids (t\\<lparr>Outputs := h\\<rparr>)) g e\n    in\n      if accepts_log (set l) (tm outputs) then\n        Some h\n      else\n        find_outputs t e l g\n  )\"\n\nprimrec find_updates_outputs :: \"update_function list list \\<Rightarrow> output_function list list \\<Rightarrow> iEFSM \\<Rightarrow> log \\<Rightarrow> transition_group \\<Rightarrow> (output_function list \\<times> update_function list) option\" where\n  \"find_updates_outputs [] _ _ _ _ = None\" |\n  \"find_updates_outputs (h#t) p e l g = (\n    let\n      updates = fold (\\<lambda>(tids, t) acc. replace_transition acc tids (t\\<lparr>Updates := h\\<rparr>)) g e\n    in\n      case find_outputs p updates l (map (\\<lambda>(id, t). (id,t\\<lparr>Updates := h\\<rparr>))  g) of\n        Some pp \\<Rightarrow> Some (pp, h) |\n        None \\<Rightarrow> find_updates_outputs t p e l g\n  )\"\n\ndefinition updates_for :: \"update_function list \\<Rightarrow> update_function list list\" where\n  \"updates_for U = (\n    let uf = fold (\\<lambda>(r, u) f. f(r $:= u#(f $ r))) U (K$ []) in\n    map (\\<lambda>r. map (\\<lambda>u. (r, u)) (uf $ r)) (finfun_to_list uf)\n  )\"\n\ndefinition standardise_group_outputs_updates :: \"iEFSM \\<Rightarrow> log \\<Rightarrow> transition_group \\<Rightarrow> transition_group\" where\n  \"standardise_group_outputs_updates e l g = (\n    let\n      update_groups = product_lists (updates_for (remdups (List.maps (Updates \\<circ> snd) g)));\n      update_groups_subs = fold (List.union \\<circ> subseqs) update_groups [];\n      output_groups = product_lists (transpose (remdups (map (Outputs \\<circ> snd) g)))\n    in\n    case find_updates_outputs update_groups_subs output_groups e l g of\n      None \\<Rightarrow> g |\n      Some (p, u) \\<Rightarrow> map (\\<lambda>(id, t). (id, t\\<lparr>Outputs := p, Updates := u\\<rparr>)) g\n  )\"\n\nfun find_first_use_of_trace :: \"nat \\<Rightarrow> trace \\<Rightarrow> iEFSM \\<Rightarrow> cfstate \\<Rightarrow> registers \\<Rightarrow> tids option\" where\n  \"find_first_use_of_trace _ [] _ _ _ = None\" |\n  \"find_first_use_of_trace rr ((l, i, _)#es) e s r = (\n    let\n      (id, s', t) = fthe_elem (i_possible_steps e s r l i)\n    in\n      if (\\<exists>p \\<in> set (Outputs t). aexp_constrains p (V (R rr))) then\n        Some id\n      else\n        find_first_use_of_trace rr es e s' (evaluate_updates t i r)\n  )\"\n\ndefinition find_first_uses_of :: \"nat \\<Rightarrow> log \\<Rightarrow> iEFSM \\<Rightarrow> tids list\" where\n  \"find_first_uses_of r l e = List.maps (\\<lambda>x. case x of None \\<Rightarrow> [] | Some x \\<Rightarrow> [x]) (map (\\<lambda>t. find_first_use_of_trace r t e 0 <>) l)\"\n\nfun find_initialisation_of_trace :: \"nat \\<Rightarrow> trace \\<Rightarrow> iEFSM \\<Rightarrow> cfstate \\<Rightarrow> registers \\<Rightarrow> (tids \\<times> transition) option\" where\n  \"find_initialisation_of_trace _ [] _ _ _ = None\" |\n  \"find_initialisation_of_trace r' ((l, i, _)#es) e s r = (\n    let\n      (tids, s', t) = fthe_elem (i_possible_steps e s r l i)\n    in\n    if (\\<exists>(rr, u) \\<in> set (Updates t). rr = r' \\<and> is_lit u) then\n      Some (tids, t)\n    else\n      find_initialisation_of_trace r' es e s' (evaluate_updates t i r)\n  )\"\n\nprimrec find_initialisation_of :: \"nat \\<Rightarrow> iEFSM \\<Rightarrow> log \\<Rightarrow> (tids \\<times> transition) option list\" where\n  \"find_initialisation_of _ _ [] = []\" |\n  \"find_initialisation_of r e (h#t) = (\n    case find_initialisation_of_trace r h e 0 <> of\n      None \\<Rightarrow> find_initialisation_of r e t |\n      Some thing \\<Rightarrow> Some thing#(find_initialisation_of r e t)\n  )\"\n\ndefinition delay_initialisation_of :: \"nat \\<Rightarrow> log \\<Rightarrow> iEFSM \\<Rightarrow> tids list \\<Rightarrow> iEFSM\" where\n  \"delay_initialisation_of r l e tids = fold (\\<lambda>x e. case x of\n      None \\<Rightarrow> e |\n    Some (i_tids, t) \\<Rightarrow>\n      let\n        origins = map (\\<lambda>id. origin id e) tids;\n        init_val = snd (hd (filter (\\<lambda>(r', _). r = r') (Updates t)));\n        e' = fimage (\\<lambda>(id, (origin', dest), tr).\n        \\<comment> \\<open>Add the initialisation update to incoming transitions\\<close>\n        if dest \\<in> set origins then\n          (id, (origin', dest), tr\\<lparr>Updates := List.insert (r, init_val) (Updates tr)\\<rparr>)\n        \\<comment> \\<open>Strip the initialisation update from the original initialising transition\\<close>\n        else if id = i_tids then\n          (id, (origin', dest), tr\\<lparr>Updates := filter (\\<lambda>(r', _). r \\<noteq> r') (Updates tr)\\<rparr>)\n        else\n          (id, (origin', dest), tr)\n      ) e\n      in\n      \\<comment> \\<open>We don't want to update a register twice so just leave it\\<close>\n      if accepts_log (set l) (tm e') then\n        e'\n      else\n        e\n  ) (find_initialisation_of r e l) e\"\n\nfun groupwise_generalise_and_update :: \"log \\<Rightarrow> iEFSM \\<Rightarrow> transition_group list \\<Rightarrow> iEFSM\" where\n  \"groupwise_generalise_and_update _ e [] = e\" |\n  \"groupwise_generalise_and_update log e (gp#t) = (\n        let\n          e' = generalise_and_update log e gp;\n          rep = snd (hd (gp));\n          structural_group = fimage (\\<lambda>(i, _, t). (i, t)) (ffilter (\\<lambda>(_, _, t). same_structure rep t) e');\n          delayed = fold (\\<lambda>r acc. delay_initialisation_of r log acc (find_first_uses_of r log acc)) (sorted_list_of_set (all_regs e')) e';\n          standardised = standardise_group delayed log (sorted_list_of_fset structural_group) standardise_group_outputs_updates;\n          structural_group2 = fimage (\\<lambda>(_, _, t). (Outputs t, Updates t)) (ffilter (\\<lambda>(_, _, t).  Label rep = Label t \\<and> Arity rep = Arity t \\<and> length (Outputs rep) = length (Outputs t)) standardised)\n        in\n        \\<comment> \\<open>If we manage to standardise a structural group, we do not need to evolve outputs and\n            updates for the other historical subgroups so can filter them out.\\<close>\n        if fis_singleton structural_group2 then\n          groupwise_generalise_and_update log (merge_regs standardised (accepts_log (set log))) (filter (\\<lambda>g. set g \\<inter> fset structural_group = {}) t)\n        else\n          groupwise_generalise_and_update log (merge_regs standardised (accepts_log (set log))) t\n  )\"\n\ndefinition drop_all_guards :: \"iEFSM \\<Rightarrow> iEFSM \\<Rightarrow> log \\<Rightarrow> update_modifier \\<Rightarrow> (iEFSM \\<Rightarrow> nondeterministic_pair fset) \\<Rightarrow> iEFSM\" where\n\"drop_all_guards e pta log m np = (let\n      derestricted = fimage (\\<lambda>(id, tf, tran). (id, tf, tran\\<lparr>Guards := []\\<rparr>)) e;\n      nondeterministic_pairs = sorted_list_of_fset (np derestricted)\n    in\n    case resolve_nondeterminism {} nondeterministic_pairs pta derestricted m (accepts_log (set log)) np of\n      (None, _) \\<Rightarrow> pta |\n      (Some resolved, _) \\<Rightarrow> resolved\n  )\"\n\ndefinition updated_regs :: \"transition \\<Rightarrow> nat set\" where\n  \"updated_regs t = set (map fst (Updates t))\"\n\ndefinition fewer_updates :: \"transition \\<Rightarrow> transition fset \\<Rightarrow> transition option\" where\n  \"fewer_updates t tt = (\n    let p = ffilter (\\<lambda>t'. same_structure t t' \\<and> Outputs t = Outputs t' \\<and> updated_regs t' \\<subset> updated_regs t) tt in\n    if p = {||} then None else Some (snd (fMin (fimage (\\<lambda>t. (length (Updates t), t)) p))))\"\n\nfun remove_spurious_updates_aux :: \"iEFSM \\<Rightarrow> transition_group \\<Rightarrow> transition fset \\<Rightarrow> log \\<Rightarrow> iEFSM\" where\n  \"remove_spurious_updates_aux e [] _ _ = e\" |\n  \"remove_spurious_updates_aux e ((tid, t)#ts) tt l = (\n    case fewer_updates t tt of\n      None \\<Rightarrow> remove_spurious_updates_aux e ts tt l |\n      Some t' \\<Rightarrow> (\n        let e' = replace_transition e tid t' in\n        if accepts_log (set l) (tm e') then\n          remove_spurious_updates_aux e' ts tt l\n        else\n          remove_spurious_updates_aux e ts tt l\n      )\n  )\"\n\n(* This goes through and tries to remove spurious updates that get introduced during preprocessing *)\ndefinition remove_spurious_updates :: \"iEFSM \\<Rightarrow> log \\<Rightarrow> iEFSM\" where\n  \"remove_spurious_updates e l = (\n    let transitions = fimage (\\<lambda>(tid, _, t). (tid, t)) e in\n      remove_spurious_updates_aux e (sorted_list_of_fset transitions) (fimage snd transitions) l\n  )\"\n\ndefinition derestrict :: \"iEFSM \\<Rightarrow> log \\<Rightarrow> update_modifier \\<Rightarrow> (iEFSM \\<Rightarrow> nondeterministic_pair fset) \\<Rightarrow> iEFSM\" where\n  \"derestrict pta log m np = (\n    let\n      normalised = groupwise_generalise_and_update log pta (transition_groups pta log)\n    in\n      drop_all_guards normalised pta log m np\n  )\"\n\ndefinition \"drop_pta_guards pta log m np = drop_all_guards pta pta log m np\"\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Extended_Finite_State_Machine_Inference/heuristics/PTA_Generalisation.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331606115021, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.29355732540343704}}
{"text": "section \\<open> Idle and Active Relations \\<close>\n\ntheory tcircus_idle\n  imports tcircus_rel\nbegin\n\ndefinition filter_idle :: \"('s, 'e) taction \\<Rightarrow> ('s, 'e) taction\" (\"idle'(_')\") where\n[upred_defs]: \"filter_idle P = U(R1(P \\<and> &tt \\<in> tocks UNIV))\"\n\ndefinition filter_time :: \"('s, 'e) taction \\<Rightarrow> ('s, 'e) taction\" (\"time'(_')\") where\n[upred_defs]: \"filter_time P = U(R1(\\<exists> $st\\<acute> \\<bullet> \\<exists> $pat\\<acute> \\<bullet> \\<exists> $ref\\<acute> \\<bullet> P\\<lbrakk>idleprefix(&tt)/&tt\\<rbrakk>))\"\n\ndefinition filter_active :: \"('s, 'e) taction \\<Rightarrow> ('s, 'e) taction\" (\"active'(_')\") where \n[upred_defs]: \"filter_active(P) = U(R1(\\<exists> t e t'. P \\<and> \\<guillemotleft>t\\<guillemotright> \\<in> tocks UNIV \\<and> &tt = \\<guillemotleft>t @ (Evt e # t')\\<guillemotright>))\"\n\nutp_const filter_idle filter_active\n\nlemma idle_TRR [closure]: assumes \"P is TRR\" shows \"idle(P) is TRR\"\nproof -\n  have \"TRR(idle(TRR(P))) = idle(TRR(P))\" by rel_blast\n  thus \"idle(P) is TRR\" by (metis Healthy_def assms)\nqed\n\nlemma active_TRR [closure]: assumes \"P is TRR\" shows \"active(P) is TRR\"\nproof -\n  have \"TRR(active(TRR(P))) = active(TRR(P))\" by rel_blast\n  thus \"active(P) is TRR\" by (metis Healthy_def assms)\nqed\n\nlemma time_TRR [closure]: assumes \"P is TRR\" shows \"time(P) is TRR\"\nproof -\n  have \"TRR(time(TRR(P))) = time(TRR(P))\" by rel_blast\n  thus \"time(P) is TRR\" by (metis Healthy_def assms)\nqed\n\nlemma \n  assumes \"P is TRR\"\n  shows \"(P \\<and> time(P)) is TIP\"\n  apply (simp add: Healthy_def)\n  apply (trr_auto cls: assms)\n  oops\n\nlemma active_disj [rpred]: \"active(P \\<or> Q) = (active(P) \\<or> active(Q))\"\n  by rel_auto\n\nlemma idle_conj [rpred]: \"idle(P \\<and> Q) = (idle(P) \\<and> idle(Q))\"\n  by (rel_auto)\n\nlemma idle_disj [rpred]: \"idle(P \\<or> Q) = (idle(P) \\<or> idle(Q))\"\n  by (rel_auto)\n\nlemma idle_idem [rpred]: \"idle(idle(P)) = idle(P)\"\n  by rel_auto\n\nlemma idle_true': \"idle(true) = U(R1(&tt \\<in> tocks UNIV))\"\n  by rel_auto\n\nlemma active_idem [rpred]: \"active(active(P)) = active(P)\"\n  by rel_auto\n\nlemma TRR_idle_or_active [rpred]:\n  assumes \"P is TRR\"\n  shows \"(idle(P) \\<or> active(P)) = P\"\n  by (trr_auto cls: assms)\n     (metis hd_Cons_tl hd_activesuffix idle_active_decomp idleprefix_tocks rangeE tocks_Nil tocks_append)\n \nlemma refine_eval_dest: \"P \\<sqsubseteq> Q \\<Longrightarrow> \\<lbrakk>Q\\<rbrakk>\\<^sub>e s \\<Longrightarrow> \\<lbrakk>P\\<rbrakk>\\<^sub>e s\"\n  by (rel_auto)\n\nlemma Healthy_after: \"\\<lbrakk> \\<And> i. P i is H \\<rbrakk> \\<Longrightarrow> H \\<circ> P = P\"\n  by (metis (mono_tags, lifting) Healthy_if fun.map_cong fun.map_id0 id_apply image_iff)\n    \nlemma idle_skip [rpred]: \"idle(II\\<^sub>t) = II\\<^sub>t\"\n  by (rel_auto)\n\nlemma idle_false [rpred]: \"idle(false) = false\"\n  by (rel_auto)\n\nlemma time_disj [rpred]: \"time(P \\<or> Q) = (time(P) \\<or> time(Q))\"\n  by (rel_auto)\n\nlemma TIP_has_time [rpred]:\n  assumes \"P is TRR\" \"P is TIP\"\n  shows \"(P \\<and> time(P)) = P\"\n  apply (trr_auto cls: assms)\n  apply (drule refine_eval_dest[OF TIP_prop[OF assms(1) assms(2)]])\n  apply (rel_blast)\n  done\n\nlemma TIP_time_active [rpred]:\n  assumes \"P is TRR\" \"P is TIP\"\n  shows \"(active(P) \\<and> time(P)) = active(P)\"\n  apply (trr_auto cls: assms)\n  apply (drule refine_eval_dest[OF TIP_prop[OF assms(1) assms(2)]])\n  apply (rel_blast)\n  done\n\nlemma TRF_time [closure]:\n  \"P is TRR \\<Longrightarrow> time(P) is TRF\"\n  by (rule TRF_intro, simp add: closure unrest, simp_all add: filter_time_def unrest)\n\nend", "meta": {"author": "isabelle-utp", "repo": "utp-main", "sha": "27bdf3aee6d4fc00c8fe4d53283d0101857e0d41", "save_path": "github-repos/isabelle/isabelle-utp-utp-main", "path": "github-repos/isabelle/isabelle-utp-utp-main/utp-main-27bdf3aee6d4fc00c8fe4d53283d0101857e0d41/theories/tockcircus/tcircus_idle.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331462646254, "lm_q2_score": 0.4921881357207955, "lm_q1q2_score": 0.29355731834207455}}
{"text": "theory Failures_TickTock_Hiding\n\nimports\n  Failures_TickTock\nbegin\n(*\nlemma\n  assumes \"\\<forall> P Q. (s2w (opS P Q)) = (opW (s2w P) (s2w Q))\"\n          \"\\<forall> P. s2w (w2s P) = P\"\n    shows \"(w2s (opW P Q)) = (opS (w2s P) (w2s Q))\"\nproof -\n  have \"\\<forall>P Q. (s2w (opS P Q)) = (opW (s2w P) (s2w Q))\"\n    using assms by auto\n  then have \"(s2w (opS (w2s P) (w2s Q))) = (opW (s2w (w2s P)) (s2w (w2s Q)))\"\n    by auto\n  then have \"(s2w (opS (w2s P) (w2s Q))) = (opW P Q)\"\n    using assms by auto\n  then have \"(w2s (s2w (opS (w2s P) (w2s Q)))) = (w2s (opW P Q))\"\n    by auto\n  then have \"(opS (w2s P) (w2s Q)) = (w2s (opW P Q))\"\n    using assms\n\n  obtain p where p:\"p = (w2s P)\n\n  then have \"\\<forall> P Q. s2w (opS (w2s P) (w2s Q)) = (opW (s2w (w2s P)) (s2w (w2s Q)))\"\n    using *)\n\n\n\nlemma ttproc2F_HideF_failures_subseteq_HidingTT:\n  assumes TTwf_P: \"TTwf P\" and TT0_P: \"TT0 P\" and TT1_P: \"TT1 P\" \n  shows \"fst ((ttproc2F P) \\<setminus>\\<^sub>F HS) \\<subseteq> fst (ttproc2F (P \\<setminus>\\<^sub>C (ttevt2F`HS)))\" \n  using assms unfolding ttproc2F_def HidingTT_def HideF_def\nproof (auto)\n  fix b s y\n  assume assm1:\"Some (s, b \\<union> HS) = tt2F y\"\n  and    assm2:\"y \\<in> P\"\n\n  text \\<open> To proceed with the proof we need to remove HS, and keep b.\n         This exists in P so long as P is TT1, because it is a subset refusal. \\<close>\n\n  then obtain z2 where z2:\"Some (s, b) = tt2F z2 \\<and> z2 \\<in> P\"\n    using assm1 assm2 apply auto\n    using Some_tt2F_subset TT1_P TT1_def by blast\n  then have Some_z2:\"Some (s, b) = tt2F z2\"\n    by auto\n\n  text \\<open> Then we can pick any z, where filtering the trace based on Some(s,b)\n         is equivalent to getting a failure via tt2F. \\<close>\n\n  then obtain z where z:\"tt2F z = Some (filter (\\<lambda>e. e \\<notin> HS) s, b)\"\n    using Some_tt2F_exists_filter assm1 z2\n    by metis\n\n  text \\<open> Then it is sufficient to induce over the original hide_trace rule for the \n         following predicate that doesn't mention P at all. \\<close>\n                                            \n  have \"\\<exists>z. z \\<in> hide_trace (ttevt2F ` HS) y \\<and> Some (filter (\\<lambda>e. e \\<notin> HS) s, b) = tt2F z\"\n    using assm1 z\n  proof (induct \"(ttevt2F `HS)\" y arbitrary:b s z rule:hide_trace.induct)\n    case 1\n    then show ?case by auto\n  next\n    case (2 e xs) (* {t.  (Event e \\<in> X \\<and> t \\<in> hide_trace X s) \n                        \\<or> (\\<exists>s'. Event e \\<notin> X \\<and> s' \\<in> hide_trace X s \\<and> t = [Event e]\\<^sub>E # s')} *)\n    have \"Some (s, b \\<union> HS) = tt2F ([Event e]\\<^sub>E # xs)\"\n      using 2 by auto\n    then have tt2F_xs:\"Some(tl s,b \\<union> HS) = tt2F xs\"\n      by (simp add: Some_tt2F_event_tl)\n    then have tt2T_tl_s:\"tt2T xs = tl s\"\n       using Some_tt2F_imp_tt2T' by blast\n\n    have \"s = tt2T ([Event e]\\<^sub>E # xs)\"\n      using \"2.prems\"(1) Some_tt2F_imp_tt2T' by blast\n\n    then have \"tt2T z = filter (\\<lambda>e. e \\<notin> HS) (tt2T ([Event e]\\<^sub>E # xs))\"\n      using 2\n      by (simp add: Some_tt2F_imp_tt2T')\n    then have tt2T_z:\"tt2T z = filter (\\<lambda>e. e \\<notin> HS) (evt e # tt2T xs)\"\n      by auto\n     \n    then show ?case using 2 \n      proof (cases \"Event e \\<in> (ttevt2F ` HS)\")\n        case True\n        then have \"evt e \\<in> HS\"\n          apply auto\n          by (metis evt.exhaust ttevent.distinct(3) ttevent.inject ttevt2F.simps(1) ttevt2F.simps(2))\n        then have \"tt2T z = filter (\\<lambda>e. e \\<notin> HS) (tt2T xs)\"\n          using tt2T_z by simp\n        then have \"tt2T z = filter (\\<lambda>e. e \\<notin> HS) (tl s)\"\n          using tt2T_tl_s by simp\n        then have \"\\<exists>z. z \\<in> hide_trace (ttevt2F ` HS) xs \\<and> Some (filter (\\<lambda>e. e \\<notin> HS) s, b) = tt2F z\"\n          using 2 tt2F_xs \n          using \\<open>s = tt2T ([Event e]\\<^sub>E # xs)\\<close> \\<open>tt2T z = filter (\\<lambda>e. e \\<notin> HS) (tt2T ([Event e]\\<^sub>E # xs))\\<close> by auto\n        then show ?thesis\n          by (simp add: True)\n      next\n        case False\n        then have \"evt e \\<notin> HS\"\n          using image_iff by fastforce\n        then have \"tt2T z = (evt e # (filter (\\<lambda>e. e \\<notin> HS) (tt2T xs)))\"\n          by (simp add: tt2T_z)\n        then have \"tt2T (tl z) = (filter (\\<lambda>e. e \\<notin> HS) (tt2T xs))\" and\n                  hd_z:\"hd z = [Event e]\\<^sub>E\"\n          apply (simp add: tt2T_tl_evt)\n          by (simp add: \\<open>tt2T z = evt e # filter (\\<lambda>e. e \\<notin> HS) (tt2T xs)\\<close> tt2T_hd_evt)\n        then have \"\\<exists>z. z \\<in> hide_trace (ttevt2F ` HS) xs \\<and> Some (filter (\\<lambda>e. e \\<notin> HS) (tl s), b) = tt2F z\"\n          using 2 tt2F_xs tt2T_tl_s\n          by (smt Some_tt2F_tail \\<open>s = tt2T ([Event e]\\<^sub>E # xs)\\<close> \\<open>tt2T z = evt e # filter (\\<lambda>e. e \\<notin> HS) (tt2T xs)\\<close> \\<open>tt2T z = filter (\\<lambda>e. e \\<notin> HS) (tt2T ([Event e]\\<^sub>E # xs))\\<close>)\n        then have \"\\<exists>z. [Event e]\\<^sub>E # z \\<in> hide_trace (ttevt2F ` HS) ([Event e]\\<^sub>E # xs) \\<and> Some (filter (\\<lambda>e. e \\<notin> HS) s, b) = tt2F ([Event e]\\<^sub>E # z)\"\n          using hd_z apply auto\n          using False\n          by (metis (mono_tags, lifting) \\<open>s = tt2T ([Event e]\\<^sub>E # xs)\\<close> \\<open>tt2T z = evt e # filter (\\<lambda>e. e \\<notin> HS) (tt2T xs)\\<close> \\<open>tt2T z = filter (\\<lambda>e. e \\<notin> HS) (tt2T ([Event e]\\<^sub>E # xs))\\<close> eq_fst_iff eq_snd_iff option.simps(5) tt2T_tl_s)\n        then have \"\\<exists>z. z \\<in> hide_trace (ttevt2F ` HS) ([Event e]\\<^sub>E # xs) \\<and> Some (filter (\\<lambda>e. e \\<notin> HS) s, b) = tt2F z\"\n          by (metis \\<open>tt2T z = evt e # filter (\\<lambda>e. e \\<notin> HS) (tt2T xs)\\<close> hd_z list.distinct(1) list.exhaust_sel tt2T.simps(3))\n        then show ?thesis \n          using hd_z by auto\n      qed\n  next\n    case 3\n    then show ?case by auto\n  next\n    case (4 Y s)\n    then show ?case by auto\n  next\n    case (5 Y)\n    then have \"s = []\"\n      using Some_tt2F_imp_tt2T' tt2T.simps(5) by blast\n    then obtain Z where Z:\"z = [[Z]\\<^sub>R] \\<and> ttevt2F`b \\<subseteq> Z\"\n      using 5 apply auto\n      by (metis (no_types, lifting) image_Collect_subsetI old.prod.inject option.inject tt2F.simps(1) tt2F_some_exists)\n  show ?case using 5\n  proof (cases \"(ttevt2F ` (b \\<union> HS)) \\<subseteq> Y\")\n      case True\n      then show ?thesis using 5 Z\n        apply auto\n        by (rule_tac x=\"[[(ttevt2F`b)]\\<^sub>R]\" in exI, auto)\n    next\n      case False\n      then show ?thesis using 5 Z  \n        by auto\n    qed\n  next\n    case (6 t)\n    then show ?case by auto\n  next\n    case (7 Y e t)\n    then show ?case by auto\n  next\n    case (8 Y t)\n    then show ?case by auto\n  next\n    case (9 Y Z t)\n    then show ?case by auto\n  next\n    case (10 x t)\n    then show ?case by auto\n  qed\n\n  then have \"\\<exists>z. Some (filter (\\<lambda>e. e \\<notin> HS) s, b) = tt2F z \\<and> (\\<exists>x. x = hide_trace (ttevt2F ` HS) y \\<and> y \\<in> P \\<and> z \\<in> x)\"\n    using assm2 assm1 z\n    by blast\n  then show \"\\<exists>y. Some (filter (\\<lambda>e. e \\<notin> HS) s, b) = tt2F y \\<and> (\\<exists>x. (\\<exists>p. x = hide_trace (ttevt2F ` HS) p \\<and> p \\<in> P) \\<and> y \\<in> x)\"\n    by auto\nqed\n\nlemma ttproc2F_HidingTT_failures_subseteq_HideF:\n  assumes TTwf_P: \"TTwf P\" and TT0_P: \"TT0 P\" and TT1_P: \"TT1 P\"\n  shows \"fst (ttproc2F (P \\<setminus>\\<^sub>C (ttevt2F`HS))) \\<subseteq> fst ((ttproc2F P) \\<setminus>\\<^sub>F HS)\" \n  using assms unfolding ttproc2F_def HidingTT_def HideF_def\nproof (auto)\n  fix a b y p\n  assume assm1:\"Some (a, b) = tt2F y\"\n  and    assm2:\"y \\<in> hide_trace (ttevt2F ` HS) p\"\n  and    assm3:\"p \\<in> P\"\n\n  text \\<open> Key to doing this proof without using p \\<in> P is to use p\n         and focus on showing that some prefix of it exists that\n         satisfies the condition. \\<close>\n \n  have \"\\<exists>s. (\\<exists>r. Some (s, b \\<union> HS) = tt2F r \\<and> r \\<lesssim>\\<^sub>C p) \\<and> a = filter (\\<lambda>e. e \\<notin> HS) s\"\n    using assm1 assm2\n  proof (induct \"(ttevt2F ` HS)\" p arbitrary:y a b rule:hide_trace.induct)\n    case (1 X)\n    then show ?case by auto\n  next\n    case (2 X e s)\n    then show ?case\n    proof (cases \"Event X \\<in> (ttevt2F ` HS)\")\n      case True\n      then have evt_X:\"evt X \\<in> HS\"\n        by (metis (no_types, hide_lams) evt.exhaust imageE ttevent.inject ttevent.simps(5) ttevt2F.simps(1) ttevt2F.simps(2))\n      then have \"s \\<in> hide_trace (ttevt2F ` HS) e\"\n        using 2 True by auto\n      then have \"\\<exists>s. (\\<exists>r.  Some (s, b \\<union> HS) = tt2F r \\<and> r \\<lesssim>\\<^sub>C e) \\<and> a = filter (\\<lambda>e. e \\<notin> HS) s\"\n        using 2 by auto\n      then have \"\\<exists>s. (\\<exists>r. Some (evt X # s, b \\<union> HS) = tt2F ([Event X]\\<^sub>E # r) \\<and> r \\<lesssim>\\<^sub>C e) \\<and> a = filter (\\<lambda>e. e \\<notin> HS) (evt X # s)\"\n        using True evt_X apply auto\n        by (metis (no_types, lifting) fst_conv option.simps(5) snd_conv)\n      then show ?thesis \n        using tt_prefix_subset.simps(3) by blast\n    next\n      case False \n      then have \"evt X \\<notin> HS\"\n        using image_iff by fastforce\n      then have tl_s:\"(tl s) \\<in> hide_trace (ttevt2F ` HS) e\"\n        using 2 False by auto\n\n      then obtain ax where ax_bx:\"Some (ax, b) = tt2F (tl s) \\<and> evt X # ax = a\"\n        using \"2.prems\"(1) \"2.prems\"(2) False Some_tt2F_event_tl\n        proof -\n          assume a1: \"\\<And>ax. Some (ax, b) = tt2F (tl s) \\<and> evt X # ax = a \\<Longrightarrow> thesis\"\n          have \"tt2T s = a\"\n            using \"2.prems\"(1) Some_tt2F_imp_tt2T' by blast\n          then show ?thesis\n            using a1 \"2.prems\"(1) \"2.prems\"(2) False Some_tt2F_event_tl by fastforce\n        qed\n      then have \"\\<exists>s. (\\<exists>r. Some (s, b \\<union> HS) = tt2F r \\<and> r \\<lesssim>\\<^sub>C e) \\<and> ax = filter (\\<lambda>e. e \\<notin> HS) s\"\n        using 2 tl_s by auto\n      then have \"\\<exists>s. (\\<exists>r. Some (s, b \\<union> HS) = tt2F ([Event X]\\<^sub>E # r) \\<and> r \\<lesssim>\\<^sub>C e) \\<and> (evt X # ax) = filter (\\<lambda>e. e \\<notin> HS) s\"\n        using 2 False\n        by (smt \\<open>evt X \\<notin> HS\\<close> filter.simps(2) fst_conv option.simps(5) snd_conv tt2F.simps(2))\n      then show ?thesis using ax_bx\n        using tt_prefix_subset.simps(3) by blast\n    qed\n  next\n    case (3 X)\n    then show ?case by auto\n  next\n    case (4 X Y s)\n    have \"Tock \\<notin> (ttevt2F ` HS)\"\n      apply auto\n      by (metis evt.exhaust ttevent.distinct(1) ttevent.distinct(5) ttevt2F.simps(1) ttevt2F.simps(2))\n    then have \"tt2F s = None\"\n      using 4 by auto\n    then show ?case\n      using 4 by auto\n  next\n    case (5 X Y)\n    then have \"a = []\"\n      using 5 by auto\n    then obtain Z where Z:\"Y = [[Z]\\<^sub>R] \\<and> ttevt2F`(b) \\<subseteq> Z\" (* {t. \\<exists> Z\\<subseteq>Y. X \\<subseteq> Y \\<and> t = [[Z]\\<^sub>R]} *)\n      using 5 apply simp\n      apply safe \n      by auto\n    then show ?case using 5\n    proof (cases \"(ttevt2F ` HS) \\<subseteq> X\")\n      case True\n      have \"(ttevt2F ` (b \\<union> HS)) \\<subseteq> X\"\n        using 5 Z by auto\n      have \"Some (a, b) = tt2F [[Z]\\<^sub>R] \\<and> a = filter (\\<lambda>e. e \\<notin> HS) a\"\n        using 5 Z by auto\n      then have \"Some (a, (b \\<union> HS)) = tt2F [[Z \\<union> ttevt2F`HS]\\<^sub>R] \\<and> a = filter (\\<lambda>e. e \\<notin> HS) a\"\n       using 5 Z apply auto\n       using Some_tt2F_set by fastforce\n      then show ?thesis using 5 Z\n        apply auto\n        by (metis (no_types, lifting) \\<open>Some (a, b \\<union> HS) = tt2F [[Z \\<union> ttevt2F ` HS]\\<^sub>R] \\<and> a = filter (\\<lambda>e. e \\<notin> HS) a\\<close> sup.absorb_iff2 sup_assoc tt_prefix_subset.simps(2) tt_prefix_subset_refl)\n    next\n      case False\n      then show ?thesis using 5 by auto\n    qed  \n  next\n    case (6 X t)\n    then show ?case by auto\n  next\n    case (7 X Y e t)\n    then show ?case by auto\n  next\n    case (8 X Y t)\n    then show ?case by auto\n  next\n    case (9 X Y Z t)\n    then show ?case by auto\n  next\n    case (10 X x t)\n    then show ?case by auto\n  qed\n\n  then show \"\\<exists>s. (\\<exists>y. Some (s, b \\<union> HS) = tt2F y \\<and> y \\<in> P) \\<and> a = filter (\\<lambda>e. e \\<notin> HS) s\"\n    using assm3 TT1_P TT1_def by blast\nqed\n\nlemma ttproc2F_HideF_traces_subseteq_HidingTT:\n  assumes TTwf_P: \"TTwf P\" and TT0_P: \"TT0 P\" and TT1_P: \"TT1 P\"\n  shows \"snd ((ttproc2F P) \\<setminus>\\<^sub>F HS) \\<subseteq> snd (ttproc2F (P \\<setminus>\\<^sub>C (ttevt2F`HS)))\" \n  using assms unfolding ttproc2F_def HidingTT_def HideF_def\nproof(auto)\n  fix y\n  assume assm1:\"y \\<in> P\"\n\n  have \"ttWF y\"\n    using TTwf_P TTwf_def assm1 by blast\n\n  then have \"\\<exists>z r. filter (\\<lambda>e. e \\<notin> HS) (tt2T y) = tt2T z \\<and> z \\<in> hide_trace (ttevt2F ` HS) r \\<and> r \\<lesssim>\\<^sub>C y\"\n  proof (induct \"(ttevt2F `HS)\" y rule:hide_trace.induct)\n    case 1\n    then show ?case   \n      by (rule_tac x=\"[]\" in exI, auto)+\n  next\n    case (2 e s)\n    then have hyp:\"\\<exists>z r. filter (\\<lambda>e. e \\<notin> HS) (tt2T s) = tt2T z \\<and> z \\<in> hide_trace (ttevt2F ` HS) r \\<and> r \\<lesssim>\\<^sub>C s\"\n      by auto\n      \n    then show ?case\n    proof (cases \"Event e \\<in> (ttevt2F ` HS)\")\n      case True\n      then have \"\\<exists>z r. filter (\\<lambda>e. e \\<notin> HS) (tt2T s) = tt2T z \\<and> z \\<in> hide_trace (ttevt2F ` HS) ([Event e]\\<^sub>E # r) \\<and> [Event e]\\<^sub>E # r \\<lesssim>\\<^sub>C [Event e]\\<^sub>E # s\"\n        using hyp by auto\n      then have \"\\<exists>z r. filter (\\<lambda>e. e \\<notin> HS) (tt2T ([Event e]\\<^sub>E # s)) = tt2T z \\<and> z \\<in> hide_trace (ttevt2F ` HS) ([Event e]\\<^sub>E # r) \\<and> [Event e]\\<^sub>E # r \\<lesssim>\\<^sub>C [Event e]\\<^sub>E # s\"\n        using True\n        by (smt evt.exhaust filter.simps(2) imageE tt2T.simps(2) ttevent.distinct(3) ttevt2F.simps(1) ttevt2F.simps(2))\n      then show ?thesis using 2 by blast\n    next\n      case False\n      then have \"\\<exists>z r. filter (\\<lambda>e. e \\<notin> HS) (tt2T ([Event e]\\<^sub>E # s)) = tt2T ([Event e]\\<^sub>E # z) \\<and> ([Event e]\\<^sub>E # z) \\<in> hide_trace (ttevt2F ` HS) ([Event e]\\<^sub>E # r) \\<and> [Event e]\\<^sub>E # r \\<lesssim>\\<^sub>C [Event e]\\<^sub>E # s\"\n        using hyp apply auto\n        by (simp add: rev_image_eqI)\n      then show ?thesis by blast\n    qed\n  next\n    case 3\n    then show ?case\n      apply auto\n      apply (smt evt.exhaust hide_trace.simps(3) image_iff mem_Collect_eq tt2T.simps(1) tt_prefix_subset_refl ttevent.distinct(3) ttevt2F.simps(1))\n      by (metis filter.simps(1) hide_trace.simps(1) lists.Nil lists_empty tt2T.simps(3) tt_prefix_subset.simps(1))\n    \n  next\n    case (4 Y s)\n    then show ?case\n    proof (cases \"Tock \\<in> (ttevt2F ` HS)\")\n      case True\n      then show ?thesis\n        by (metis evt.exhaust image_iff ttevent.distinct(1) ttevent.distinct(5) ttevt2F.simps(1) ttevt2F.simps(2))\n    next\n      case False\n      then show ?thesis \n        using 4 False apply auto\n        apply (rule_tac x=\"[]\" in exI, simp)\n        by (rule_tac x=\"[]\" in exI, simp)\n    qed\n    \n  next\n    case (5 Y)\n    then show ?case\n      by (rule_tac x=\"[]\" in exI, simp)+\n  next\n    case (6 t)\n    then show ?case by auto\n  next\n    case (7 Y e t)\n    then show ?case by auto\n  next\n    case (8 Y t)\n    then show ?case by auto\n  next\n    case (9 Y Z t)\n    then show ?case by auto\n  next\n    case (10 x t)\n    then show ?case by auto\n  qed\n\n  then show \"\\<exists>ya. filter (\\<lambda>e. e \\<notin> HS) (tt2T y) = tt2T ya \\<and> (\\<exists>x. (\\<exists>p. x = hide_trace (ttevt2F ` HS) p \\<and> p \\<in> P) \\<and> ya \\<in> x)\"\n    using assm1  \n    using TT1_P TT1_def by blast\nqed   \n\nlemma ttproc2F_HidingTT_traces_subseteq_HideF:\n  assumes TTwf_P: \"TTwf P\" and TT0_P: \"TT0 P\" and TT1_P: \"TT1 P\"\n  shows \"snd (ttproc2F (P \\<setminus>\\<^sub>C (ttevt2F`HS))) \\<subseteq> snd ((ttproc2F P) \\<setminus>\\<^sub>F HS)\" \n  using assms unfolding ttproc2F_def HidingTT_def HideF_def\nproof (auto)\n  fix y p\n  assume assm1:\"y \\<in> hide_trace (ttevt2F ` HS) p\"\n    and  assm2:\"p \\<in> P\"\n\n  have \"\\<exists>r. tt2T y = filter (\\<lambda>e. e \\<notin> HS) (tt2T r) \\<and> r \\<lesssim>\\<^sub>C p\"\n    using assm1\n  proof (induct \"(ttevt2F ` HS)\" p arbitrary:y rule:hide_trace.induct)\n    case 1\n    then show ?case\n      apply auto\n      by (rule_tac x=\"[]\" in exI, auto)+\n  next\n    case (2 e s)\n    then show ?case\n    proof (cases \"Event e \\<in> (ttevt2F ` HS)\")\n      case True\n      then have evt_HS:\"evt e \\<in> HS\"\n        by (metis (no_types, hide_lams) evt.exhaust imageE ttevent.inject ttevent.simps(5) ttevt2F.simps(1) ttevt2F.simps(2))\n      then have \"y \\<in> hide_trace (ttevt2F ` HS) s\"\n        using 2 True by auto\n \n      then have \"\\<exists>r. tt2T y = filter (\\<lambda>e. e \\<notin> HS) (tt2T r) \\<and> r \\<lesssim>\\<^sub>C s\"\n        using 2 by auto\n      then have \"\\<exists>r. tt2T y = filter (\\<lambda>e. e \\<notin> HS) (tt2T ([Event e]\\<^sub>E # r)) \\<and> ([Event e]\\<^sub>E # r) \\<lesssim>\\<^sub>C [Event e]\\<^sub>E # s\"\n        by (simp add: evt_HS)\n      then show ?thesis by blast\n    next\n      case False\n      then have evt_no_HS:\"evt e \\<notin> HS\"\n        using image_iff by fastforce\n      then have tl_s:\"(tl y) \\<in> hide_trace (ttevt2F ` HS) s\"\n        using 2 False by auto\n      then have \"\\<exists>r. tt2T (tl y) = filter (\\<lambda>e. e \\<notin> HS) (tt2T r) \\<and> r \\<lesssim>\\<^sub>C s\"\n        using 2 by auto\n      then have \"\\<exists>r. tt2T ([Event e]\\<^sub>E # (tl y)) = filter (\\<lambda>e. e \\<notin> HS) (tt2T ([Event e]\\<^sub>E # r)) \\<and> ([Event e]\\<^sub>E # r) \\<lesssim>\\<^sub>C ([Event e]\\<^sub>E # s)\"\n        by (simp add: evt_no_HS)\n      then show ?thesis\n      proof -\n        have \"y = [Event e]\\<^sub>E # tl y\"\n          using \"2.prems\" False by auto\n        then show ?thesis\n          by (metis (full_types) \\<open>\\<exists>r. tt2T ([Event e]\\<^sub>E # tl y) = filter (\\<lambda>e. e \\<notin> HS) (tt2T ([Event e]\\<^sub>E # r)) \\<and> [Event e]\\<^sub>E # r \\<lesssim>\\<^sub>C [Event e]\\<^sub>E # s\\<close>)\n      qed\n    qed\n  next\n    case 3\n    then show ?case\n      by (smt filter.simps(1) filter.simps(2) hide_trace.simps(3) image_eqI mem_Collect_eq tt2T.simps(1) tt2T.simps(3) tt_prefix_subset.simps(1) tt_prefix_subset_refl ttevt2F.simps(2))\n  next\n    case (4 Y s)\n    then show ?case\n      apply auto\n       apply (metis evt.exhaust ttevent.distinct(1) ttevent.distinct(5) ttevt2F.simps(1) ttevt2F.simps(2))\n      by (rule_tac x=\"[]\" in exI, auto)\n  next\n    case (5 Y)\n    then show ?case\n      apply auto\n      by (rule_tac x=\"[]\" in exI, auto)\n  next\n    case (6 t)\n    then show ?case by auto\n  next\n    case (7 Y e t)\n    then show ?case by auto\n  next\n    case (8 Y t)\n    then show ?case by auto\n  next\n    case (9 Y Z t)\n    then show ?case by auto\n  next\n    case (10 x t)\n    then show ?case by auto\n  qed\n\n  then show \"\\<exists>z. tt2T y = filter (\\<lambda>e. e \\<notin> HS) z \\<and> (\\<exists>y. z = tt2T y \\<and> y \\<in> P)\"\n    using TT1_P TT1_def assm2 by blast\nqed\n\nlemma ttproc2F_HidingTT_eq_HideF:\n  assumes TTwf_P: \"TTwf P\" and TT0_P: \"TT0 P\" and TT1_P: \"TT1 P\"\n  shows \"ttproc2F (P \\<setminus>\\<^sub>C (ttevt2F`HS)) = (ttproc2F P) \\<setminus>\\<^sub>F HS\" \n  by (metis (no_types, lifting) HideF_def TT0_P TT1_P TTwf_P fst_conv snd_conv subset_antisym ttproc2F_HideF_failures_subseteq_HidingTT ttproc2F_HideF_traces_subseteq_HidingTT ttproc2F_HidingTT_failures_subseteq_HideF ttproc2F_HidingTT_traces_subseteq_HideF ttproc2F_def)\n\nend", "meta": {"author": "UoY-RoboStar", "repo": "tick-tock-CSP", "sha": "7186d2e7f70116589850112a7353bc521372c913", "save_path": "github-repos/isabelle/UoY-RoboStar-tick-tock-CSP", "path": "github-repos/isabelle/UoY-RoboStar-tick-tock-CSP/tick-tock-CSP-7186d2e7f70116589850112a7353bc521372c913/Failures/Failures_TickTock_Hiding.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331319177487, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.29355731128071205}}
{"text": "section \\<open>Implementation of Heaps by Arrays\\<close>\ntheory IICF_Impl_Heapmap\nimports IICF_Abs_Heapmap \"../IICF_Indexed_Array_List\"\nbegin\n\n(* TODO/FIXME: Division setup of the code generator is a mess.\n  TODO: Why does [code_unfold] not work to rewrite \"x div 2\"?\n*)\ntext \\<open>Some setup to circumvent the really inefficient implementation \n  of division in the code generator, which has to consider several\n  cases for negative divisors and dividends. \\<close>\ndefinition [code_unfold]: \n  \"efficient_nat_div2 n     \n    \\<equiv> nat_of_integer (fst (Code_Numeral.divmod_abs (integer_of_nat n) 2))\"\n\nlemma efficient_nat_div2[simp]: \"efficient_nat_div2 n = n div 2\"\n  by (simp add: efficient_nat_div2_def nat_of_integer.rep_eq)\n\n  type_synonym 'v hma = \"nat list \\<times> ('v list)\"\n  sepref_decl_intf 'v i_hma is \"nat list \\<times> (nat \\<rightharpoonup> 'v)\"\n\n  locale hmstruct_impl = hmstruct prio for prio :: \"'v::heap \\<Rightarrow> 'p::linorder\"\n  begin\n    lemma param_prio: \"(prio,prio) \\<in> Id \\<rightarrow> Id\" by simp\n    lemmas [sepref_import_param] = param_prio\n    sepref_register prio\n  end\n\n  context\n    fixes maxsize :: nat\n    fixes prio :: \"'v::heap \\<Rightarrow> 'p::linorder\"\n    notes [map_type_eqs] = map_type_eqI[Pure.of \"TYPE((nat,'v) ahm)\" \"TYPE('v i_hma)\"]\n  begin\n\n    interpretation hmstruct .\n    interpretation hmstruct_impl .\n  \n    definition \"hm_impl1_\\<alpha> \\<equiv> \\<lambda>(pq,ml). \n      (pq,\\<lambda>k. if k\\<in>set pq then Some (ml!k) else None)\"\n\n    definition \"hm_impl1_invar \\<equiv> \\<lambda>(pq,ml). \n        hmr_invar (hm_impl1_\\<alpha> (pq,ml))\n      \\<and> set pq \\<subseteq> {0..<maxsize}  \n      \\<and> ((pq=[] \\<and> ml=[]) \\<or> (length ml = maxsize))\"  \n\n    definition \"hm_impl1_weak_invar \\<equiv> \\<lambda>(pq,ml). \n        set pq \\<subseteq> {0..<maxsize}  \n      \\<and> ((pq=[] \\<and> ml=[]) \\<or> (length ml = maxsize))\"  \n\n    definition \"hm_impl1_rel \\<equiv> br hm_impl1_\\<alpha> hm_impl1_invar\"\n    definition \"hm_weak_impl'_rel \\<equiv> br hm_impl1_\\<alpha> hm_impl1_weak_invar\"\n\n\n    lemmas hm_impl1_rel_defs = \n      hm_impl1_rel_def hm_weak_impl'_rel_def hm_impl1_weak_invar_def hm_impl1_invar_def hm_impl1_\\<alpha>_def in_br_conv\n    \n\n    lemma hm_impl_\\<alpha>_fst_eq: \n        \"(x1, x2) = hm_impl1_\\<alpha> (x1a, x2a) \\<Longrightarrow> x1 = x1a\"\n      unfolding hm_impl1_\\<alpha>_def by (auto split: if_split_asm)\n\n\n    term hm_empty_op  \n    definition hm_empty_op' :: \"'v hma nres\" \n      where \"hm_empty_op' \\<equiv> do {\n        let pq = op_ial_empty_sz maxsize;\n        let ml = op_list_empty;\n        RETURN (pq,ml)\n      }\"\n\n\n    lemma hm_empty_op'_refine: \"(hm_empty_op', hm_empty_op) \\<in> \\<langle>hm_impl1_rel\\<rangle>nres_rel\"  \n      apply (intro fun_relI nres_relI)\n      unfolding hm_empty_op'_def hm_empty_op_def hm_impl1_rel_defs \n      by (auto simp: in_br_conv)\n\n    definition hm_length' :: \"'v hma \\<Rightarrow> nat\" where \"hm_length' \\<equiv> \\<lambda>(pq,ml). length pq\"\n\n    lemma hm_length'_refine: \"(RETURN o hm_length',RETURN o hm_length) \\<in> hm_impl1_rel \\<rightarrow> \\<langle>nat_rel\\<rangle>nres_rel\"\n      apply (intro fun_relI nres_relI)\n      unfolding hm_length'_def hm_length_def hm_impl1_rel_defs\n      by (auto)\n      \n    term hm_key_of_op  \n    definition \"hm_key_of_op' \\<equiv> \\<lambda>(pq,ml) i. ASSERT (i>0) \\<then> mop_list_get pq (i - 1)\"\n    lemma hm_key_of_op'_refine: \"(hm_key_of_op', hm_key_of_op) \\<in> hm_impl1_rel \\<rightarrow> nat_rel \\<rightarrow> \\<langle>nat_rel\\<rangle>nres_rel\"\n      apply (intro fun_relI nres_relI)\n      unfolding hm_key_of_op'_def hm_key_of_op_def hm_impl1_rel_defs\n      by (auto)\n\n    term hm_lookup  \n    definition \"hm_lookup_op' \\<equiv> \\<lambda>(pq,ml) k. do {\n      if (k<maxsize) then do {    \\<comment> \\<open>TODO: This check can be eliminated, but this will complicate refinement of keys in basic ops\\<close>\n        let c = op_list_contains k pq;\n        if c then do {\n          v \\<leftarrow> mop_list_get ml k;\n          RETURN (Some v)\n        } else RETURN None\n      } else RETURN None  \n    }\"\n      \n    lemma hm_lookup_op'_refine: \"(uncurry hm_lookup_op', uncurry (RETURN oo hm_lookup)) \n      \\<in> (hm_impl1_rel \\<times>\\<^sub>r nat_rel) \\<rightarrow>\\<^sub>f \\<langle>\\<langle>Id\\<rangle>option_rel\\<rangle>nres_rel\"\n      apply (intro frefI nres_relI)\n      unfolding hm_lookup_op_def hm_lookup_op'_def o_def uncurry_def\n      apply refine_vcg\n      apply (auto simp: hm_impl1_rel_defs heapmap_\\<alpha>_def hmr_invar_def)\n      done\n\n    term hm_contains_key_op  \n    definition \"hm_contains_key_op' \\<equiv> \\<lambda>k (pq,ml). do {\n      if (k<maxsize) then do {    \\<comment> \\<open>TODO: This check can be eliminated, but this will complicate refinement of keys in basic ops\\<close>\n        RETURN (op_list_contains k pq)\n      } else RETURN False  \n    }\"\n      \n    lemma hm_contains_key_op'_refine: \"(uncurry hm_contains_key_op', uncurry hm_contains_key_op) \n      \\<in> (nat_rel \\<times>\\<^sub>r hm_impl1_rel) \\<rightarrow>\\<^sub>f \\<langle>bool_rel\\<rangle>nres_rel\"\n      apply (intro frefI nres_relI)\n      unfolding hm_contains_key_op_def hm_contains_key_op'_def o_def uncurry_def PR_CONST_def\n      apply refine_vcg\n      apply (auto simp: hm_impl1_rel_defs heapmap_\\<alpha>_def hmr_invar_def)\n      done\n\n\n    term hm_valid \n\n    definition \"hm_exch_op' \\<equiv> \\<lambda>(pq,ml) i j. do {\n      ASSERT (hm_valid (hm_impl1_\\<alpha> (pq,ml)) i);\n      ASSERT (hm_valid (hm_impl1_\\<alpha> (pq,ml)) j);\n      pq \\<leftarrow> mop_list_swap pq (i - 1) (j - 1);\n      RETURN (pq,ml)\n    }\"\n\n    lemma hm_impl1_relI:\n      assumes \"hmr_invar b\"\n      assumes \"(a,b)\\<in>hm_weak_impl'_rel\"\n      shows \"(a,b)\\<in>hm_impl1_rel\"\n      using assms\n      unfolding hmr_rel_def hm_impl1_rel_def hm_weak_impl'_rel_def in_br_conv\n        hm_impl1_weak_invar_def hm_impl1_invar_def\n      by auto\n\n    lemma hm_impl1_nres_relI:\n      assumes \"b \\<le>\\<^sub>n SPEC hmr_invar\"\n      assumes \"(a,b)\\<in>\\<langle>hm_weak_impl'_rel\\<rangle>nres_rel\"\n      shows \"(a,b)\\<in>\\<langle>hm_impl1_rel\\<rangle>nres_rel\"\n      using assms hm_impl1_relI\n      apply (auto simp: pw_le_iff pw_leof_iff refine_pw_simps in_br_conv nres_rel_def)\n      apply blast\n      done\n\n\n    lemma hm_exch_op'_refine: \"(hm_exch_op', hm_exch_op) \\<in> hm_impl1_rel \\<rightarrow> nat_rel \\<rightarrow> nat_rel \\<rightarrow> \\<langle>hm_impl1_rel\\<rangle>nres_rel\"\n      apply (intro fun_relI hm_impl1_nres_relI[OF hm_exch_op_invar])\n      unfolding hm_exch_op'_def hm_exch_op_def\n      apply (auto simp: pw_le_iff refine_pw_simps nres_rel_def\n          hm_impl1_rel_def in_br_conv split: prod.splits)\n      apply (auto simp: hm_impl1_\\<alpha>_def)\n      unfolding hm_impl1_rel_defs\n      apply auto\n      done\n\n\n    term hm_index_op  \n\n    definition \"hm_index_op' \\<equiv> \\<lambda>(pq,ml) k. \n      do {\n        ASSERT (hm_impl1_invar (pq,ml) \\<and> heapmap_\\<alpha> (hm_impl1_\\<alpha> (pq,ml)) k \\<noteq> None \\<and> k\\<in>set pq);\n        i \\<leftarrow> mop_list_index pq k;\n        RETURN (i+1)\n      }\"\n    lemma hm_index_op'_refine: \"(hm_index_op',hm_index_op) \n      \\<in> hm_impl1_rel \\<rightarrow> nat_rel \\<rightarrow> \\<langle>nat_rel\\<rangle>nres_rel\"  \n      apply (intro fun_relI nres_relI)\n      unfolding hm_index_op'_def hm_index_op_def hm_impl1_rel_defs\n      apply (auto simp: pw_le_iff refine_pw_simps heapmap_\\<alpha>_def split: if_split_asm)\n      done\n\n    definition hm_update_op' where\n      \"hm_update_op' \\<equiv> \\<lambda>(pq,ml) i v. do {\n        ASSERT (hm_valid (hm_impl1_\\<alpha> (pq,ml)) i \\<and> hm_impl1_invar (pq,ml));\n        k \\<leftarrow> mop_list_get pq (i - 1);\n        ml \\<leftarrow> mop_list_set ml k v;\n        RETURN (pq, ml)\n      }\"\n    lemma hm_update_op'_refine: \"(hm_update_op', hm_update_op) \\<in> hm_impl1_rel \\<rightarrow> nat_rel \\<rightarrow> Id \\<rightarrow> \\<langle>hm_impl1_rel\\<rangle>nres_rel\"  \n      apply (intro fun_relI hm_impl1_nres_relI[OF hm_update_op_invar])\n      unfolding hm_update_op'_def hm_update_op_def\n      apply (auto simp: pw_le_iff refine_pw_simps nres_rel_def\n          hm_impl1_rel_def in_br_conv split: prod.splits)\n      apply (auto simp: hm_impl1_\\<alpha>_def)\n      unfolding hm_impl1_rel_defs\n      apply (auto simp: subset_code(1))\n      done\n      \n          \n    term hm_butlast_op  \n\n    lemma hm_butlast_op_invar: \"hm_butlast_op hm \\<le>\\<^sub>n SPEC hmr_invar\"\n      unfolding hm_butlast_op_def h.butlast_op_def\n      apply refine_vcg\n      apply (clarsimp_all simp: hmr_rel_defs map_butlast distinct_butlast)\n      apply safe\n\n      apply (auto simp: in_set_conv_nth nth_butlast) []\n      apply (metis Suc_pred len_greater_imp_nonempty length_greater_0_conv less_antisym)\n      \n      apply (auto dest: in_set_butlastD) []\n\n      apply (metis One_nat_def append_butlast_last_id distinct_butlast last_conv_nth not_distinct_conv_prefix)\n      done\n\n\n    definition hm_butlast_op' where\n      \"hm_butlast_op' \\<equiv> \\<lambda>(pq,ml). do {\n        ASSERT (hmr_invar (hm_impl1_\\<alpha> (pq,ml)));\n        pq \\<leftarrow> mop_list_butlast pq;\n        RETURN (pq,ml)\n      }\"\n\n    lemma set_butlast_distinct_conv: \n      \"\\<lbrakk>distinct l\\<rbrakk> \\<Longrightarrow> set (butlast l) = set l - {last l}\"  \n      by (cases l rule: rev_cases; auto)\n\n    lemma hm_butlast_op'_refine: \"(hm_butlast_op', hm_butlast_op) \\<in> hm_impl1_rel \\<rightarrow> \\<langle>hm_impl1_rel\\<rangle>nres_rel\"  \n      apply (intro fun_relI hm_impl1_nres_relI[OF hm_butlast_op_invar])\n      unfolding hm_butlast_op'_def hm_butlast_op_def\n      apply (auto simp: pw_le_iff refine_pw_simps nres_rel_def\n          hm_impl1_rel_def in_br_conv split: prod.splits)\n      apply (auto simp: hm_impl1_\\<alpha>_def)\n      unfolding hm_impl1_rel_defs\n      apply (auto simp: restrict_map_def) []\n\n      defer\n\n      apply (auto dest: in_set_butlastD) []\n      apply (auto intro!: ext \n        simp: hmr_invar_def set_butlast_distinct_conv last_conv_nth\n        dest: in_set_butlastD) []\n      done\n\n    definition hm_append_op' \n      where \"hm_append_op' \\<equiv> \\<lambda>(pq,ml) k v. do {\n        ASSERT (k \\<notin> set pq \\<and> k<maxsize);\n        ASSERT (hm_impl1_invar (pq,ml));\n        pq \\<leftarrow> mop_list_append pq k;\n        ml \\<leftarrow> (if length ml = 0 then mop_list_replicate maxsize v else RETURN ml);\n        ml \\<leftarrow> mop_list_set ml k v;\n        RETURN (pq,ml)\n      }\"\n\n    lemma hm_append_op'_refine: \"(uncurry2 hm_append_op', uncurry2 hm_append_op) \n      \\<in> [\\<lambda>((hm,k),v). k<maxsize]\\<^sub>f (hm_impl1_rel \\<times>\\<^sub>r nat_rel) \\<times>\\<^sub>r Id \\<rightarrow> \\<langle>hm_impl1_rel\\<rangle>nres_rel\"  \n      apply (intro frefI hm_impl1_nres_relI[OF hm_append_op_invar])\n      unfolding hm_append_op'_def hm_append_op_def\n      apply (auto simp: pw_le_iff refine_pw_simps nres_rel_def\n          hm_impl1_rel_def in_br_conv split: prod.splits)\n      unfolding hm_impl1_rel_defs\n      apply (auto simp: restrict_map_def hmr_invar_def split: prod.splits if_split_asm) \n      done\n      \n    definition \"hm_impl2_rel \\<equiv> prod_assn (ial_assn maxsize id_assn) (array_assn id_assn)\"\n    definition \"hm_impl_rel \\<equiv> hr_comp hm_impl2_rel hm_impl1_rel\"\n\n    lemmas [fcomp_norm_unfold] = hm_impl_rel_def[symmetric]\n\n    (*lemma hm_impl_rel_precise[constraint_rules]: \"precise hm_impl_rel\"\n      unfolding hm_impl_rel_def hm_impl1_rel_def hm_impl2_rel_def\n      by (constraint_rules)*)\n\n\n    subsection \\<open>Implement Basic Operations\\<close>  \n\n\n    lemma param_parent: \"(efficient_nat_div2,h.parent) \\<in> Id \\<rightarrow> Id\" \n      by (intro fun_relI) (simp add: h.parent_def)\n    lemmas [sepref_import_param] = param_parent\n    sepref_register h.parent\n\n    lemma param_left: \"(h.left,h.left) \\<in> Id \\<rightarrow> Id\" by simp\n    lemmas [sepref_import_param] = param_left\n    sepref_register h.left\n\n    lemma param_right: \"(h.right,h.right) \\<in> Id \\<rightarrow> Id\" by simp\n    lemmas [sepref_import_param] = param_right\n    sepref_register h.right\n\n    abbreviation (input) \"prio_rel \\<equiv> (Id::('p\\<times>'p) set)\"\n\n    lemma param_prio_le: \"((\\<le>), (\\<le>)) \\<in> prio_rel \\<rightarrow> prio_rel \\<rightarrow> bool_rel\" by simp\n    lemmas [sepref_import_param] = param_prio_le\n    \n    lemma param_prio_lt: \"((<), (<)) \\<in> prio_rel \\<rightarrow> prio_rel \\<rightarrow> bool_rel\" by simp\n    lemmas [sepref_import_param] = param_prio_lt\n\n    abbreviation \"I_HM_UNF \\<equiv> TYPE(nat list \\<times> 'v list)\"\n\n    sepref_definition hm_length_impl is \"RETURN o hm_length'\" :: \"hm_impl2_rel\\<^sup>k\\<rightarrow>\\<^sub>anat_assn\"\n      unfolding hm_length'_def hm_impl2_rel_def\n      by sepref\n    lemmas [sepref_fr_rules] = hm_length_impl.refine[FCOMP hm_length'_refine]\n    sepref_register \"hm_length::(nat,'v) ahm \\<Rightarrow> _\"\n\n    sepref_definition hm_key_of_op_impl is \"uncurry hm_key_of_op'\" :: \"hm_impl2_rel\\<^sup>k*\\<^sub>anat_assn\\<^sup>k \\<rightarrow>\\<^sub>anat_assn\"\n      unfolding hm_key_of_op'_def hm_impl2_rel_def\n      by sepref\n    lemmas [sepref_fr_rules] = hm_key_of_op_impl.refine[FCOMP hm_key_of_op'_refine]\n    sepref_register \"hm_key_of_op::(nat,'v) ahm \\<Rightarrow> _\"\n\n    context \n      notes [id_rules] = itypeI[Pure.of maxsize \"TYPE(nat)\"]\n      notes [sepref_import_param] = IdI[of maxsize]\n    begin\n\n\n    sepref_definition hm_lookup_impl is \"uncurry hm_lookup_op'\" :: \"(hm_impl2_rel\\<^sup>k*\\<^sub>anat_assn\\<^sup>k \\<rightarrow>\\<^sub>aoption_assn id_assn)\"\n      unfolding hm_lookup_op'_def hm_impl2_rel_def\n      by sepref\n    lemmas [sepref_fr_rules] = \n      hm_lookup_impl.refine[FCOMP hm_lookup_op'_refine]\n    sepref_register \"hm_lookup::(nat,'v) ahm \\<Rightarrow> _\" \n\n    sepref_definition hm_exch_op_impl is \"uncurry2 hm_exch_op'\" :: \"hm_impl2_rel\\<^sup>d*\\<^sub>anat_assn\\<^sup>k*\\<^sub>anat_assn\\<^sup>k \\<rightarrow>\\<^sub>a hm_impl2_rel\"\n      unfolding hm_exch_op'_def hm_impl2_rel_def\n      by sepref\n    lemmas [sepref_fr_rules] = hm_exch_op_impl.refine[FCOMP hm_exch_op'_refine]\n    sepref_register \"hm_exch_op::(nat,'v) ahm \\<Rightarrow> _\" \n\n    sepref_definition hm_index_op_impl is \"uncurry hm_index_op'\" :: \"hm_impl2_rel\\<^sup>k*\\<^sub>aid_assn\\<^sup>k \\<rightarrow>\\<^sub>a id_assn\"\n      unfolding hm_index_op'_def hm_impl2_rel_def \n      by sepref\n    lemmas [sepref_fr_rules] = hm_index_op_impl.refine[FCOMP hm_index_op'_refine]\n    sepref_register \"hm_index_op::(nat,'v) ahm \\<Rightarrow> _\" \n\n    sepref_definition hm_update_op_impl is \"uncurry2 hm_update_op'\" :: \"hm_impl2_rel\\<^sup>d*\\<^sub>aid_assn\\<^sup>k*\\<^sub>aid_assn\\<^sup>k \\<rightarrow>\\<^sub>a hm_impl2_rel\"\n      unfolding hm_update_op'_def hm_impl2_rel_def \n      by sepref\n    lemmas [sepref_fr_rules] = hm_update_op_impl.refine[FCOMP hm_update_op'_refine]\n    sepref_register \"hm_update_op::(nat,'v) ahm \\<Rightarrow> _\" \n\n\n    sepref_definition hm_butlast_op_impl is \"hm_butlast_op'\" :: \"hm_impl2_rel\\<^sup>d \\<rightarrow>\\<^sub>a hm_impl2_rel\"\n      unfolding hm_butlast_op'_def hm_impl2_rel_def by sepref\n    lemmas [sepref_fr_rules] = hm_butlast_op_impl.refine[FCOMP hm_butlast_op'_refine]\n    sepref_register \"hm_butlast_op::(nat,'v) ahm \\<Rightarrow> _\"\n\n    sepref_definition hm_append_op_impl is \"uncurry2 hm_append_op'\" :: \"hm_impl2_rel\\<^sup>d *\\<^sub>a id_assn\\<^sup>k *\\<^sub>a id_assn\\<^sup>k \\<rightarrow>\\<^sub>a hm_impl2_rel\"\n      unfolding hm_append_op'_def hm_impl2_rel_def \n      apply (rewrite array_fold_custom_replicate)\n      by sepref\n    lemmas [sepref_fr_rules] = hm_append_op_impl.refine[FCOMP hm_append_op'_refine]\n    sepref_register \"hm_append_op::(nat,'v) ahm \\<Rightarrow> _\" \n\n\n    subsection \\<open>Auxiliary Operations\\<close>\n\n    lemmas [intf_of_assn] = intf_of_assnI[where R=\"hm_impl_rel :: (nat,'v) ahm \\<Rightarrow> _\" and 'a=\"'v i_hma\"]\n\n    sepref_definition hm_valid_impl is \"uncurry (RETURN oo hm_valid)\" :: \"hm_impl_rel\\<^sup>k*\\<^sub>anat_assn\\<^sup>k \\<rightarrow>\\<^sub>a bool_assn \"\n      unfolding hm_valid_def[abs_def]\n      by sepref\n    lemmas [sepref_fr_rules] = hm_valid_impl.refine\n    sepref_register \"hm_valid::(nat,'v) ahm \\<Rightarrow> _\"\n\n\n    (* Optimization *)\n    definition \"hm_the_lookup_op' hm k \\<equiv> do {\n      let (pq,ml) = hm;\n      ASSERT (heapmap_\\<alpha> (hm_impl1_\\<alpha> hm) k \\<noteq> None \\<and> hm_impl1_invar hm);\n      v \\<leftarrow> mop_list_get ml k;\n      RETURN v\n    }\"\n    lemma hm_the_lookup_op'_refine: \n      \"(hm_the_lookup_op', hm_the_lookup_op) \\<in> hm_impl1_rel \\<rightarrow> nat_rel \\<rightarrow> \\<langle>Id\\<rangle>nres_rel\"\n      apply (intro fun_relI nres_relI)\n      unfolding hm_the_lookup_op'_def hm_the_lookup_op_def\n      apply refine_vcg\n      apply (auto simp: hm_impl1_rel_defs heapmap_\\<alpha>_def hmr_invar_def split: if_split_asm)\n      done\n\n    sepref_definition hm_the_lookup_op_impl is \"uncurry hm_the_lookup_op'\" :: \"hm_impl2_rel\\<^sup>k*\\<^sub>aid_assn\\<^sup>k \\<rightarrow>\\<^sub>aid_assn\"  \n      unfolding hm_the_lookup_op'_def[abs_def] hm_impl2_rel_def\n      by sepref\n    lemmas hm_the_lookup_op_impl[sepref_fr_rules] = hm_the_lookup_op_impl.refine[FCOMP hm_the_lookup_op'_refine]\n    sepref_register \"hm_the_lookup_op::(nat,'v) ahm \\<Rightarrow> _\"\n\n    sepref_definition hm_val_of_op_impl is \"uncurry hm_val_of_op\" :: \"hm_impl_rel\\<^sup>k*\\<^sub>aid_assn\\<^sup>k \\<rightarrow>\\<^sub>a id_assn\"\n      unfolding hm_val_of_op_def by sepref\n    lemmas [sepref_fr_rules] = hm_val_of_op_impl.refine\n    sepref_register \"hm_val_of_op::(nat,'v) ahm \\<Rightarrow> _\"\n\n    sepref_definition hm_prio_of_op_impl is \"uncurry (PR_CONST hm_prio_of_op)\" :: \"hm_impl_rel\\<^sup>k*\\<^sub>aid_assn\\<^sup>k \\<rightarrow>\\<^sub>a id_assn\"\n      unfolding hm_prio_of_op_def[abs_def] PR_CONST_def by sepref\n    lemmas [sepref_fr_rules] = hm_prio_of_op_impl.refine\n    sepref_register \"PR_CONST hm_prio_of_op::(nat,'v) ahm \\<Rightarrow> _\"\n    \n\n    text \\<open>No code theorem preparation, as we define optimized version later\\<close>  \n    sepref_definition (no_prep_code) hm_swim_op_impl is \"uncurry (PR_CONST hm_swim_op)\" :: \"hm_impl_rel\\<^sup>d*\\<^sub>anat_assn\\<^sup>k \\<rightarrow>\\<^sub>a hm_impl_rel\"\n      unfolding hm_swim_op_def[abs_def] PR_CONST_def\n      using [[goals_limit = 1]]\n      by sepref\n    lemmas [sepref_fr_rules] = hm_swim_op_impl.refine\n    sepref_register \"PR_CONST hm_swim_op::(nat,'v) ahm \\<Rightarrow> _\"\n    lemma [def_pat_rules]: \"hmstruct.hm_swim_op$prio \\<equiv> PR_CONST hm_swim_op\" by simp\n\n    text \\<open>No code theorem preparation, as we define optimized version later\\<close>  \n    sepref_definition (no_prep_code) hm_sink_op_impl is \"uncurry (PR_CONST hm_sink_op)\" :: \"hm_impl_rel\\<^sup>d*\\<^sub>anat_assn\\<^sup>k \\<rightarrow>\\<^sub>a hm_impl_rel\"\n      unfolding hm_sink_op_def[abs_def] PR_CONST_def\n      by sepref\n    lemmas [sepref_fr_rules] = hm_sink_op_impl.refine\n    sepref_register \"PR_CONST hm_sink_op::(nat,'v) ahm \\<Rightarrow> _\"\n    lemma [def_pat_rules]: \"hmstruct.hm_sink_op$prio \\<equiv> PR_CONST hm_sink_op\" by simp\n\n    sepref_definition hm_repair_op_impl is \"uncurry (PR_CONST hm_repair_op)\" :: \"hm_impl_rel\\<^sup>d*\\<^sub>anat_assn\\<^sup>k \\<rightarrow>\\<^sub>a hm_impl_rel\"\n      unfolding hm_repair_op_def[abs_def] PR_CONST_def\n      by sepref\n    lemmas [sepref_fr_rules] = hm_repair_op_impl.refine\n    sepref_register \"PR_CONST hm_repair_op::(nat,'v) ahm \\<Rightarrow> _\"\n    lemma [def_pat_rules]: \"hmstruct.hm_repair_op$prio \\<equiv> PR_CONST hm_repair_op\" by simp\n\n  subsection \\<open>Interface Operations\\<close>\n  definition hm_rel_np where \n    \"hm_rel_np \\<equiv> hr_comp hm_impl_rel heapmap_rel\"\n  lemmas [fcomp_norm_unfold] = hm_rel_np_def[symmetric]  \n\n  definition hm_rel where\n    \"hm_rel K V \\<equiv> hr_comp hm_rel_np (\\<langle>the_pure K,the_pure V\\<rangle>map_rel)\"\n  lemmas [fcomp_norm_unfold] = hm_rel_def[symmetric]  \n\n  lemmas [intf_of_assn] = intf_of_assnI[where R=\"hm_rel K V\" and 'a=\"('kk,'vv) i_map\" for K V]\n\n  lemma hm_rel_id_conv: \"hm_rel id_assn id_assn = hm_rel_np\"\n    \\<comment> \\<open>Used for generic algorithms: Unfold with this, then let decl-impl compose with \\<open>map_rel\\<close> again.\\<close>\n    unfolding hm_rel_def by simp\n\n\n  subsubsection \\<open>Synthesis\\<close>\n  definition op_hm_empty_sz :: \"nat \\<Rightarrow> 'kk\\<rightharpoonup>'vv\"\n    where [simp]: \"op_hm_empty_sz sz \\<equiv> op_map_empty\"\n  sepref_register \"PR_CONST (op_hm_empty_sz maxsize)\" :: \"('k,'v) i_map\"\n  lemma [def_pat_rules]: \"op_hm_empty_sz$maxsize \\<equiv> UNPROTECT (op_hm_empty_sz maxsize)\" by simp\n\n  lemma hm_fold_custom_empty_sz: \n    \"op_map_empty = op_hm_empty_sz sz\"\n    \"Map.empty = op_hm_empty_sz sz\"\n    by auto\n\n  sepref_definition hm_empty_op_impl is \"uncurry0 hm_empty_op'\" :: \"unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a hm_impl2_rel\"  \n    unfolding hm_empty_op'_def hm_impl2_rel_def array.fold_custom_empty\n    by sepref\n    \n  sepref_definition hm_insert_op_impl is \"uncurry2 hm_insert_op\" :: \"[\\<lambda>((k,_),_). k<maxsize]\\<^sub>a id_assn\\<^sup>k*\\<^sub>aid_assn\\<^sup>k*\\<^sub>ahm_impl_rel\\<^sup>d \\<rightarrow> hm_impl_rel\"\n    unfolding hm_insert_op_def\n    by sepref\n\n  sepref_definition hm_is_empty_op_impl is \"hm_is_empty_op\" :: \"hm_impl_rel\\<^sup>k \\<rightarrow>\\<^sub>a bool_assn\"\n    unfolding hm_is_empty_op_def\n    by sepref\n\n  sepref_definition hm_lookup_op_impl is \"uncurry hm_lookup_op\" :: \"id_assn\\<^sup>k*\\<^sub>ahm_impl_rel\\<^sup>k \\<rightarrow>\\<^sub>a option_assn id_assn\"\n    unfolding hm_lookup_op_def by sepref\n\n  sepref_definition hm_contains_key_impl is \"uncurry hm_contains_key_op'\" :: \"id_assn\\<^sup>k*\\<^sub>ahm_impl2_rel\\<^sup>k \\<rightarrow>\\<^sub>a bool_assn\"\n    unfolding hm_contains_key_op'_def hm_impl2_rel_def\n    by sepref\n\n  sepref_definition hm_decrease_key_op_impl is \"uncurry2 hm_decrease_key_op\" :: \"id_assn\\<^sup>k*\\<^sub>aid_assn\\<^sup>k*\\<^sub>ahm_impl_rel\\<^sup>d \\<rightarrow>\\<^sub>a hm_impl_rel\"\n    unfolding hm_decrease_key_op_def by sepref\n\n  sepref_definition hm_increase_key_op_impl is \"uncurry2 hm_increase_key_op\" :: \"id_assn\\<^sup>k*\\<^sub>aid_assn\\<^sup>k*\\<^sub>ahm_impl_rel\\<^sup>d \\<rightarrow>\\<^sub>a hm_impl_rel\"\n    unfolding hm_increase_key_op_def by sepref\n\n  sepref_definition hm_change_key_op_impl is \"uncurry2 hm_change_key_op\" :: \"id_assn\\<^sup>k*\\<^sub>aid_assn\\<^sup>k*\\<^sub>ahm_impl_rel\\<^sup>d \\<rightarrow>\\<^sub>a hm_impl_rel\"\n    unfolding hm_change_key_op_def by sepref\n\n  sepref_definition hm_pop_min_op_impl is hm_pop_min_op :: \"hm_impl_rel\\<^sup>d \\<rightarrow>\\<^sub>a prod_assn (prod_assn nat_assn id_assn) hm_impl_rel \"\n    unfolding hm_pop_min_op_def[abs_def]\n    by sepref\n\n  sepref_definition hm_remove_op_impl is \"uncurry hm_remove_op\" :: \"id_assn\\<^sup>k *\\<^sub>a hm_impl_rel\\<^sup>d \\<rightarrow>\\<^sub>a hm_impl_rel\"\n    unfolding hm_remove_op_def[abs_def] by sepref\n\n  sepref_definition hm_peek_min_op_impl is \"hm_peek_min_op\" :: \"hm_impl_rel\\<^sup>k \\<rightarrow>\\<^sub>a prod_assn nat_assn id_assn\"\n    unfolding hm_peek_min_op_def[abs_def] hm_kv_of_op_def\n    by sepref\n\n\n\n  subsubsection \\<open>Setup of Refinements\\<close>\n\n  sepref_decl_impl (no_register) hm_empty: \n    hm_empty_op_impl.refine[FCOMP hm_empty_op'_refine, FCOMP hm_empty_aref] .\n\n  context fixes K assumes \"IS_BELOW_ID K\" begin\n    lemmas mop_map_update_new_fref' = mop_map_update_new.fref[of K] \n    lemmas op_map_update_fref' = op_map_update.fref[of K] \n  end  \n\n  sepref_decl_impl (ismop) hm_insert: hm_insert_op_impl.refine[FCOMP hm_insert_op_aref]\n    uses mop_map_update_new_fref'\n    unfolding IS_BELOW_ID_def\n    apply (parametricity; auto simp: single_valued_below_Id)\n    done\n\n  sepref_decl_impl hm_is_empty: hm_is_empty_op_impl.refine[FCOMP hm_is_empty_op_aref] .\n  sepref_decl_impl hm_lookup: hm_lookup_op_impl.refine[FCOMP hm_lookup_op_aref] .\n\n  sepref_decl_impl hm_contains_key: \n    hm_contains_key_impl.refine[FCOMP hm_contains_key_op'_refine, FCOMP hm_contains_key_op_aref]\n    .\n\n  sepref_decl_impl (ismop) hm_decrease_key: hm_decrease_key_op_impl.refine[FCOMP hm_decrease_key_op_aref] .\n  sepref_decl_impl (ismop) hm_increase_key: hm_increase_key_op_impl.refine[FCOMP hm_increase_key_op_aref] .\n  sepref_decl_impl (ismop) hm_change_key: hm_change_key_op_impl.refine[FCOMP hm_change_key_op_aref] .\n    \n  sepref_decl_impl (ismop) hm_remove: hm_remove_op_impl.refine[FCOMP hm_remove_op_aref] .\n\n  sepref_decl_impl (ismop) hm_pop_min: hm_pop_min_op_impl.refine[FCOMP hm_pop_min_op_aref] .\n  sepref_decl_impl (ismop) hm_peek_min: hm_peek_min_op_impl.refine[FCOMP hm_peek_min_op_aref] .\n\n  \\<comment> \\<open>Realized as generic algorithm. Note that we use @{term id_assn} for the elements.\\<close>\n  sepref_definition hm_upd_op_impl is \"uncurry2 (RETURN ooo op_map_update)\" :: \"[\\<lambda>((k,_),_). k<maxsize]\\<^sub>a id_assn\\<^sup>k *\\<^sub>a id_assn\\<^sup>k *\\<^sub>a (hm_rel id_assn id_assn)\\<^sup>d \\<rightarrow> hm_rel id_assn id_assn\"\n    unfolding op_pm_set_gen_impl by sepref\n\n  sepref_decl_impl hm_upd_op_impl.refine[unfolded hm_rel_id_conv] uses op_map_update_fref'\n    unfolding IS_BELOW_ID_def\n    apply (parametricity; auto simp: single_valued_below_Id)\n    done\n\nend  \nend\n\ninterpretation hm: map_custom_empty \"PR_CONST (op_hm_empty_sz maxsize)\"\n  apply unfold_locales by simp\n\nlemma op_hm_empty_sz_hnr[sepref_fr_rules]:\n  \"(uncurry0 (hm_empty_op_impl maxsize), uncurry0 (RETURN (PR_CONST (op_hm_empty_sz maxsize)))) \\<in> unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a hm_rel maxsize prio K V\"\n  using hm_empty_hnr by simp\n\n\nsubsection \\<open>Manual fine-tuning of code-lemmas\\<close>\n(* TODO: Integrate into Sepref-tool optimization phase! *)\n\ncontext\nnotes [simp del] = CNV_def efficient_nat_div2\nbegin\n\nlemma nested_case_bind: \n  \"(case p of (a,b) \\<Rightarrow> bind (case a of (a1,a2) \\<Rightarrow> m a b a1 a2) (f a b)) \n  = (case p of ((a1,a2),b) \\<Rightarrow> bind (m (a1,a2) b a1 a2) (f (a1,a2) b))\"\n  \"(case p of (a,b) \\<Rightarrow> bind (case b of (b1,b2) \\<Rightarrow> m a b b1 b2) (f a b)) \n  = (case p of (a,b1,b2) \\<Rightarrow> bind (m a (b1,b2) b1 b2) (f a (b1,b2)))\"\n  by (simp_all split: prod.splits)\n\nlemma it_case: \"(case p of (a,b) \\<Rightarrow> f p a b) = (case p of (a,b) \\<Rightarrow> f (a,b) a b)\"\n  by (auto split: prod.split)\n\nlemma c2l: \"(case p of (a,b) \\<Rightarrow> bind (m a b) (f a b)) = \n  do { let (a,b) = p; bind (m a b) (f a b)}\" by simp\n\nlemma bind_Let: \"do { x \\<leftarrow> do { let y = v; (f y :: 'a Heap)}; g x } = do { let y=v; x \\<leftarrow> f y; g x }\" by auto\nlemma bind_case: \"do { x \\<leftarrow> (case y of (a,b) \\<Rightarrow> f a b); (g x :: 'a Heap) } = do { let (a,b) = y; x \\<leftarrow> f a b; g x }\"\n  by (auto split: prod.splits)\n\nlemma bind_case_mvup: \"do { x \\<leftarrow> f; case y of (a,b) \\<Rightarrow> g a b x } \n  = do { let (a,b) = y; x \\<leftarrow> f; (g a b x :: 'a Heap) }\"\n  by (auto split: prod.splits)\n\nlemma if_case_mvup: \"(if b then case p of (x1,x2) \\<Rightarrow> f x1 x2 else e)\n  = (case p of (x1,x2) \\<Rightarrow> if b then f x1 x2 else e)\" by auto\n\nlemma nested_case: \"(case p of (a,b) \\<Rightarrow> (case p of (c,d) \\<Rightarrow> f a b c d)) =\n  (case p of (a,b) \\<Rightarrow> f a b a b)\"\n  by (auto split: prod.split)\n\nlemma split_prod_bound: \"(\\<lambda>p. f p) = (\\<lambda>(a,b). f (a,b))\" by auto\n\nlemma bpc_conv: \"do { (a,b) \\<leftarrow> (m::(_*_) Heap); f a b } = do {\n  ab \\<leftarrow> (m);\n  f (fst ab) (snd ab)\n}\" \n  apply (subst (2) split_prod_bound)\n  by simp\n\nlemma it_case_pp: \"(case p of ((p1,p2)) \\<Rightarrow> case p of ((p1',p2')) \\<Rightarrow> f p1 p2 p1' p2')\n  = (case p of ((p1,p2)) \\<Rightarrow> f p1 p2 p1 p2)\"\n  by (auto split: prod.split)\n\n\nlemma it_case_ppp: \"(case p of ((p1,p2),p3) \\<Rightarrow> case p of ((p1',p2'),p3') \\<Rightarrow> f p1 p2 p3 p1' p2' p3')\n  = (case p of ((p1,p2),p3) \\<Rightarrow> f p1 p2 p3 p1 p2 p3)\"\n  by (auto split: prod.split)\n\nlemma it_case_pppp: \"(case a1 of\n              (((a, b), c), d) \\<Rightarrow>\n                case a1 of\n                (((a', b'), c'), d') \\<Rightarrow> f a b c d a' b' c' d') =\n       (case a1 of\n              (((a, b), c), d) \\<Rightarrow> f a b c d a b c d)\"\n  by (auto split: prod.splits)\n\nprivate lemmas inlines = hm_append_op_impl_def ial_append_def\n    marl_length_def marl_append_def hm_length_impl_def ial_length_def\n    hm_valid_impl_def hm_prio_of_op_impl_def hm_val_of_op_impl_def hm_key_of_op_impl_def\n    ial_get_def hm_the_lookup_op_impl_def heap_array_set_def marl_get_def\n    it_case_ppp it_case_pppp bind_case bind_case_mvup nested_case if_case_mvup\n    it_case_pp\n\nschematic_goal [code]: \"hm_insert_op_impl maxsize prio hm k v = ?f\"\n  unfolding hm_insert_op_impl_def\n  apply (rule CNV_eqD)\n  apply (simp add: inlines  cong: if_cong)\n  by (rule CNV_I)\n  \n\nschematic_goal \"hm_swim_op_impl prio hm i \\<equiv> ?f\"\n  unfolding hm_swim_op_impl_def \n  apply (rule eq_reflection)\n  apply (rule CNV_eqD)\n  apply (simp add: inlines efficient_nat_div2  \n    cong: if_cong)\n  by (rule CNV_I)\n\n\nlemma hm_swim_op_impl_code[code]: \"hm_swim_op_impl prio hm i \\<equiv> ccpo.fixp (fun_lub Heap_lub) (fun_ord Heap_ord)\n       (\\<lambda>cf (a1, a2).\n           case a1 of\n           ((a1b, a2b), a2a) \\<Rightarrow>\n             case a1b of\n             (a, b) \\<Rightarrow> do {\n               let d2 = efficient_nat_div2 a2; \n               if 0 < d2 \\<and> d2 \\<le> b\n               then do {\n                      x \\<leftarrow> (case a1b of (a, n) \\<Rightarrow> Array.nth a) (d2 - Suc 0);\n                      x \\<leftarrow> Array.nth a2a x;\n                      xa \\<leftarrow> (case a1b of (a, n) \\<Rightarrow> Array.nth a) (a2 - Suc 0);\n                      xa \\<leftarrow> Array.nth a2a xa;\n                      if prio x \\<le> prio xa then return a1\n                      else do {\n                             x'g \\<leftarrow> hm_exch_op_impl a1 a2 (d2);\n                             cf (x'g, d2)\n                           }\n                    }\n               else return a1\n             })\n       (hm, i)\"\n  unfolding hm_swim_op_impl_def \n  apply (rule eq_reflection)\n  apply (simp add: inlines efficient_nat_div2 Let_def \n    cong: if_cong)\n  done\n\nprepare_code_thms hm_swim_op_impl_code\n\nschematic_goal hm_sink_opt_impl_code[code]: \"hm_sink_op_impl prio hm i \\<equiv> ?f\"\n  unfolding hm_sink_op_impl_def \n  apply (rule eq_reflection)\n  apply (rule CNV_eqD)\n  apply (simp add: inlines \n    cong: if_cong)\n  by (rule CNV_I)\n\nprepare_code_thms hm_sink_opt_impl_code\n\nexport_code hm_swim_op_impl in SML_imp module_name Test\n\n\nschematic_goal hm_change_key_opt_impl_code[code]: \"\n  hm_change_key_op_impl prio k v hm \\<equiv> ?f\"\n  unfolding hm_change_key_op_impl_def \n  apply (rule eq_reflection)\n  apply (rule CNV_eqD)\n  apply (simp add: inlines hm_contains_key_impl_def ial_contains_def\n    hm_change_key_op_impl_def hm_index_op_impl_def hm_update_op_impl_def\n    ial_index_def\n    cong: if_cong split: prod.splits)\n  oops\n\n\nschematic_goal hm_change_key_opt_impl_code[code]: \"\n  hm_change_key_op_impl prio k v hm \\<equiv> case hm of (((a, b), ba), x2) \\<Rightarrow>\n       (do {\n              x \\<leftarrow> Array.nth ba k;\n              xa \\<leftarrow> Array.nth a x;\n              xa \\<leftarrow> Array.upd xa v x2;\n              hm_repair_op_impl prio (((a, b), ba), xa) (Suc x)\n            })\"\n  unfolding hm_change_key_op_impl_def \n  apply (rule eq_reflection)\n  apply (simp add: inlines hm_contains_key_impl_def ial_contains_def\n    hm_change_key_op_impl_def hm_index_op_impl_def hm_update_op_impl_def\n    ial_index_def\n    cong: if_cong split: prod.splits)\n  done\n\n\nschematic_goal hm_set_opt_impl_code[code]: \"hm_upd_op_impl maxsize prio hm k v \\<equiv> ?f\"\n  unfolding hm_upd_op_impl_def \n  apply (rule eq_reflection)\n  apply (rule CNV_eqD)\n  apply (simp add: inlines hm_contains_key_impl_def ial_contains_def\n    hm_change_key_op_impl_def hm_index_op_impl_def hm_update_op_impl_def\n    ial_index_def\n    cong: if_cong)\n  by (rule CNV_I)\n\nschematic_goal hm_pop_min_opt_impl_code[code]: \"hm_pop_min_op_impl prio hm \\<equiv> ?f\"\n  unfolding hm_pop_min_op_impl_def \n  apply (rule eq_reflection)\n  apply (rule CNV_eqD)\n  apply (simp add: inlines hm_contains_key_impl_def ial_contains_def\n    hm_change_key_op_impl_def hm_index_op_impl_def hm_update_op_impl_def\n    hm_butlast_op_impl_def ial_butlast_def\n    ial_index_def\n    cong: if_cong)\n  by (rule CNV_I)\n  \nend\n\nexport_code \n  hm_empty_op_impl \n  hm_insert_op_impl\n  hm_is_empty_op_impl\n  hm_lookup_op_impl\n  hm_contains_key_impl\n  hm_decrease_key_op_impl\n  hm_increase_key_op_impl\n  hm_change_key_op_impl\n  hm_upd_op_impl\n  hm_pop_min_op_impl\n  hm_remove_op_impl\n  hm_peek_min_op_impl\n  checking SML_imp\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Evaluation/Refine_Imperative_HOL/IICF/Impl/Heaps/IICF_Impl_Heapmap.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.626124191181315, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.2935211519297387}}
{"text": "section \\<open>Exploration of Deterministic Rabin Automata\\<close>\n\ntheory DRA_Nodes\nimports\n  DFS_Framework.Reachable_Nodes\n  DRA_Implement\nbegin\n\n  definition dra_G :: \"('label, 'state) dra \\<Rightarrow> 'state graph_rec\" where\n    \"dra_G A \\<equiv> \\<lparr> g_V = UNIV, g_E = E_of_succ (successors A), g_V0 = {initial A} \\<rparr>\"\n\n  lemma dra_G_graph[simp]: \"graph (dra_G A)\" unfolding dra_G_def graph_def by simp\n  lemma dra_G_reachable_nodes: \"op_reachable (dra_G A) = nodes A\"\n  unfolding op_reachable_def dra_G_def graph_rec.simps E_of_succ_def\n  proof safe\n    show \"p \\<in> nodes A\" if \"(initial A, p) \\<in> {(u, v). v \\<in> successors A u}\\<^sup>*\" for p\n      using that by induct auto\n    show \"(initial A, p) \\<in> {(u, v). v \\<in> successors A u}\\<^sup>*\" if \"p \\<in> nodes A\" for p\n      using that by (induct) (auto intro: rtrancl_into_rtrancl)\n  qed\n\n  context\n  begin\n\n    interpretation autoref_syn by this\n\n    lemma dra_G_ahs: \"dra_G A = \\<lparr> g_V = UNIV, g_E = E_of_succ (\\<lambda> p. CAST\n      ((\\<lambda> a. transition A a p ::: S) ` alphabet A ::: \\<langle>S\\<rangle> ahs_rel bhc)), g_V0 = {initial A} \\<rparr>\"\n      unfolding dra_G_def CAST_def id_apply E_of_succ_def autoref_tag_defs by auto\n\n    schematic_goal drai_Gi:\n      notes map2set_to_list[autoref_ga_rules]\n      fixes S :: \"('statei \\<times> 'state) set\"\n      assumes [autoref_ga_rules]: \"is_bounded_hashcode S seq bhc\"\n      assumes [autoref_ga_rules]: \"is_valid_def_hm_size TYPE('statei) hms\"\n      assumes [autoref_rules]: \"(seq, HOL.eq) \\<in> S \\<rightarrow> S \\<rightarrow> bool_rel\"\n      assumes [autoref_rules]: \"(Ai, A) \\<in> \\<langle>L, S\\<rangle> drai_dra_rel\"\n      shows \"(?f :: ?'a, RETURN (dra_G A)) \\<in> ?A\"\n      unfolding dra_G_ahs[where S = S and bhc = bhc] by (autoref_monadic (plain))\n    concrete_definition drai_Gi uses drai_Gi\n    (* TODO: why are term local.drai_Gi and term BA_Nodes.drai_Gi not the same *)\n    lemma drai_Gi_refine[autoref_rules]:\n      fixes S :: \"('statei \\<times> 'state) set\"\n      assumes \"SIDE_GEN_ALGO (is_bounded_hashcode S seq bhc)\"\n      assumes \"SIDE_GEN_ALGO (is_valid_def_hm_size TYPE('statei) hms)\"\n      assumes \"GEN_OP seq HOL.eq (S \\<rightarrow> S \\<rightarrow> bool_rel)\"\n      shows \"(DRA_Nodes.drai_Gi seq bhc hms, dra_G) \\<in> \\<langle>L, S\\<rangle> drai_dra_rel \\<rightarrow> \\<langle>unit_rel, S\\<rangle> g_impl_rel_ext\"\n      using drai_Gi.refine[THEN RETURN_nres_relD] assms unfolding autoref_tag_defs by blast\n\n    schematic_goal dra_nodes:\n      fixes S :: \"('statei \\<times> 'state) set\"\n      assumes [simp]: \"finite ((g_E (dra_G A))\\<^sup>* `` g_V0 (dra_G A))\"\n      assumes [autoref_ga_rules]: \"is_bounded_hashcode S seq bhc\"\n      assumes [autoref_ga_rules]: \"is_valid_def_hm_size TYPE('statei) hms\"\n      assumes [autoref_rules]: \"(seq, HOL.eq) \\<in> S \\<rightarrow> S \\<rightarrow> bool_rel\"\n      assumes [autoref_rules]: \"(Ai, A) \\<in> \\<langle>L, S\\<rangle> drai_dra_rel\"\n      shows \"(?f :: ?'a, op_reachable (dra_G A)) \\<in> ?R\" by autoref\n    concrete_definition dra_nodes uses dra_nodes\n    lemma dra_nodes_refine[autoref_rules]:\n      fixes S :: \"('statei \\<times> 'state) set\"\n      assumes \"SIDE_PRECOND (finite (nodes A))\"\n      assumes \"SIDE_GEN_ALGO (is_bounded_hashcode S seq bhc)\"\n      assumes \"SIDE_GEN_ALGO (is_valid_def_hm_size TYPE('statei) hms)\"\n      assumes \"GEN_OP seq HOL.eq (S \\<rightarrow> S \\<rightarrow> bool_rel)\"\n      assumes \"(Ai, A) \\<in> \\<langle>L, S\\<rangle> drai_dra_rel\"\n      shows \"(DRA_Nodes.dra_nodes seq bhc hms Ai,\n        (OP nodes ::: \\<langle>L, S\\<rangle> drai_dra_rel \\<rightarrow> \\<langle>S\\<rangle> ahs_rel bhc) $ A) \\<in> \\<langle>S\\<rangle> ahs_rel bhc\"\n    proof -\n      have \"finite ((g_E (dra_G A))\\<^sup>* `` g_V0 (dra_G A))\"\n        using assms(1) unfolding autoref_tag_defs dra_G_reachable_nodes[symmetric] by simp\n      then show ?thesis using dra_nodes.refine assms\n        unfolding autoref_tag_defs dra_G_reachable_nodes[symmetric] by blast\n    qed\n\n  end\n\nend", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Transition_Systems_and_Automata/Automata/DRA/DRA_Nodes.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6261241772283034, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.29352114538869767}}
{"text": "theory TrivialArityAnal\nimports ArityAnalysisSpec \"../Launchbury/Env-Nominal\"\nbegin\n\ndefinition Trivial_Aexp :: \"exp \\<Rightarrow> Arity \\<rightarrow> AEnv\"\n  where \"Trivial_Aexp e = (\\<Lambda> n. (\\<lambda> x. up\\<cdot>0) f|` fv e)\"\n\nlemma Trivial_Aexp_simp: \"Trivial_Aexp e \\<cdot> n = (\\<lambda> x. up\\<cdot>0) f|` fv e\"\n  unfolding Trivial_Aexp_def by simp\n\nlemma edom_Trivial_Aexp[simp]: \"edom (Trivial_Aexp e \\<cdot> n) = fv e\"\n  by (auto simp add: edom_def env_restr_def Trivial_Aexp_def) \n\nlemma Trivial_Aexp_eq[iff]: \"Trivial_Aexp e \\<cdot> n = Trivial_Aexp e' \\<cdot> n' \\<longleftrightarrow> fv e = (fv e' :: var set)\"\n  apply (auto simp add: Trivial_Aexp_simp env_restr_def)\n  apply (metis up_defined)+\n  done\n  \nlemma below_Trivial_Aexp[simp]: \"(ae \\<sqsubseteq> Trivial_Aexp e \\<cdot> n) \\<longleftrightarrow> edom ae \\<subseteq> fv e\"\n  by (auto dest:fun_belowD intro!: fun_belowI  simp add: Trivial_Aexp_def env_restr_def edom_def split:if_splits)\n\n\ninterpretation ArityAnalysis Trivial_Aexp.\ninterpretation EdomArityAnalysis Trivial_Aexp\n  by standard simp\n\n\ninterpretation ArityAnalysisSafe Trivial_Aexp\nproof\n(*\n  fix \\<pi>\n  show \"\\<pi> \\<bullet> Trivial_Aexp = Trivial_Aexp\" by perm_simp rule\nnext\n*)\n  fix n x\n  show \"up\\<cdot>n \\<sqsubseteq> (Trivial_Aexp (Var x)\\<cdot>n) x\"\n    by (simp add: Trivial_Aexp_simp)\nnext\n  fix e x n\n  show \"Trivial_Aexp e\\<cdot>(inc\\<cdot>n) \\<squnion> esing x\\<cdot>(up\\<cdot>0) \\<sqsubseteq> Trivial_Aexp (App e x)\\<cdot>n\"\n    by (auto intro: fun_belowI simp add: Trivial_Aexp_def env_restr_def )\nnext\n  fix y e n\n  show \"env_delete y (Trivial_Aexp e\\<cdot>(pred\\<cdot>n)) \\<sqsubseteq> Trivial_Aexp (Lam [y]. e)\\<cdot>n\"\n    by (auto simp add: Trivial_Aexp_simp env_delete_restr Diff_eq inf_commute)\nnext\n  fix x y :: var and S e a\n  assume \"x \\<notin> S\" and \"y \\<notin> S\"\n  thus \"Trivial_Aexp e[x::=y]\\<cdot>a f|` S = Trivial_Aexp e\\<cdot>a f|` S\"\n    by (auto simp add: Trivial_Aexp_simp fv_subst_eq intro!: arg_cong[where f = \"\\<lambda> S. env_restr S e\" for e])\nnext\n  fix scrut e1 a e2\n  show \"Trivial_Aexp scrut\\<cdot>0 \\<squnion> Trivial_Aexp e1\\<cdot>a \\<squnion> Trivial_Aexp e2\\<cdot>a \\<sqsubseteq> Trivial_Aexp (scrut ? e1 : e2)\\<cdot>a\"\n    by (auto intro: env_restr_mono2 simp add: Trivial_Aexp_simp join_below_iff )\nqed\n\ndefinition Trivial_Aheap :: \"heap \\<Rightarrow> exp \\<Rightarrow> Arity \\<rightarrow> AEnv\" where\n  \"Trivial_Aheap \\<Gamma> e = (\\<Lambda> a. (\\<lambda> x. up\\<cdot>0) f|` domA \\<Gamma>)\"\n\nlemma Trivial_Aheap_eqvt[eqvt]: \"\\<pi> \\<bullet>  (Trivial_Aheap \\<Gamma> e) = Trivial_Aheap (\\<pi> \\<bullet> \\<Gamma>) (\\<pi> \\<bullet> e)\"\n  unfolding Trivial_Aheap_def\n  apply perm_simp\n  apply (simp add: Abs_cfun_eqvt)\n  done\n\nlemma Trivial_Aheap_simp: \"Trivial_Aheap \\<Gamma> e\\<cdot> a = (\\<lambda> x. up\\<cdot>0) f|` domA \\<Gamma>\"\n  unfolding Trivial_Aheap_def by simp\n\nlemma Trivial_fup_Aexp_below_fv: \"fup\\<cdot>(Trivial_Aexp e)\\<cdot>a \\<sqsubseteq> (\\<lambda> x . up\\<cdot>0) f|` fv e\"\n  by (cases a)(auto simp add: Trivial_Aexp_simp)\n\nlemma Trivial_Abinds_below_fv: \"ABinds \\<Gamma>\\<cdot>ae \\<sqsubseteq> (\\<lambda> x . up\\<cdot>0) f|` fv \\<Gamma>\"\n  by (induction \\<Gamma> rule:ABinds.induct)\n     (auto simp add: join_below_iff intro!: below_trans[OF Trivial_fup_Aexp_below_fv] env_restr_mono2 elim: below_trans dest: set_mp[OF fv_delete_subset] simp del: fun_meet_simp)\n\ninterpretation ArityAnalysisLetSafe Trivial_Aexp Trivial_Aheap\nproof\n  fix \\<pi>\n  show \"\\<pi> \\<bullet> Trivial_Aheap = Trivial_Aheap\" by perm_simp rule  \nnext\n  fix \\<Gamma> e ae show \"edom (Trivial_Aheap \\<Gamma> e\\<cdot>ae) \\<subseteq> domA \\<Gamma>\"\n  by (simp add: Trivial_Aheap_simp)\nnext\n  fix \\<Gamma> :: heap and e and a\n  show \"ABinds \\<Gamma>\\<cdot>(Trivial_Aheap \\<Gamma> e\\<cdot>a) \\<squnion> Trivial_Aexp e\\<cdot>a \\<sqsubseteq> Trivial_Aheap \\<Gamma> e\\<cdot>a \\<squnion> Trivial_Aexp (Terms.Let \\<Gamma> e)\\<cdot>a\"\n    by (auto simp add: Trivial_Aheap_simp Trivial_Aexp_simp join_below_iff env_restr_join2 intro!: env_restr_mono2 below_trans[OF Trivial_Abinds_below_fv])\nnext\n  fix x y :: var and \\<Gamma> :: heap and e\n  assume \"x \\<notin> domA \\<Gamma>\" and \"y \\<notin> domA \\<Gamma>\"\n  thus \"Trivial_Aheap \\<Gamma>[x::h=y] e[x::=y] = Trivial_Aheap \\<Gamma> e\"\n    by (auto intro: cfun_eqI simp add: Trivial_Aheap_simp)\nqed\n\nend\n\n", "meta": {"author": "nomeata", "repo": "isa-launchbury", "sha": "2caa8d7d588e218aef1c49f2f327597af06d116e", "save_path": "github-repos/isabelle/nomeata-isa-launchbury", "path": "github-repos/isabelle/nomeata-isa-launchbury/isa-launchbury-2caa8d7d588e218aef1c49f2f327597af06d116e/Call_Arity/TrivialArityAnal.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6261241632752915, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.29352113884765646}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      StateSpace.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer\nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection \\<open>State Space Template\\<close>\ntheory StateSpace imports Hoare\nbegin\n\nrecord 'g state = \"globals\"::'g\n\ndefinition\n  upd_globals:: \"('g \\<Rightarrow> 'g) \\<Rightarrow> ('g,'z) state_scheme \\<Rightarrow> ('g,'z) state_scheme\"\nwhere\n  \"upd_globals upd s = s\\<lparr>globals := upd (globals s)\\<rparr>\"\n\nrecord ('g, 'n, 'val) stateSP = \"'g state\" +\n  locals :: \"'n \\<Rightarrow> 'val\"\n\nlemma upd_globals_conv: \"upd_globals f = (\\<lambda>s. s\\<lparr>globals := f (globals s)\\<rparr>)\"\n  by (rule ext) (simp add: upd_globals_def)\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/c-parser/Simpl/StateSpace.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6584175139669997, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.29334444885962874}}
{"text": "(*******************************************************************************\n\n  Project: Development of Security Protocols by Refinement\n\n  Module:  Refinement/a0n_agree.thy (Isabelle/HOL 2016-1)\n  ID:      $Id: a0n_agree.thy 134924 2017-05-24 17:23:15Z csprenge $\n  Author:  Christoph Sprenger, ETH Zurich <sprenger@inf.ethz.ch>\n  \n  One-Way authentication protocols\n  Initial Model: Non-injective agreement \n\n  Copyright (c) 2009-2016 Christoph Sprenger\n  Licence: LGPL\n\n*******************************************************************************)\n\nsection \\<open>Non-injective Agreement\\<close>\n\ntheory a0n_agree imports Refinement Agents\nbegin\n\ntext \\<open>The initial model abstractly specifies entity authentication, where \none agent/role authenticates another. More precisely, this property corresponds \nto non-injective agreement on a data set \\<open>ds\\<close>. We use Running and Commit \nsignals to obtain a protocol-independent extensional specification.\\<close>\n\ntext \\<open>Proof tool configuration. Avoid annoying automatic unfolding of\n\\<open>dom\\<close>.\\<close>\n\ndeclare domIff [simp, iff del]\n\n\n(******************************************************************************)\nsubsection \\<open>State\\<close>\n(******************************************************************************)\n\ntext \\<open>Signals. At this stage there are no protocol runs yet. All we model\nare the signals that indicate a certain progress of a protocol run by one \nagent/role (Commit signal) and the other role (Running signal). The signals \ncontain a list of agents that are assumed to be honest and a polymorphic data \nset to be agreed upon, which is instantiated later. \n\nUsually, the agent list will contain the names of the two agents who want to\nagree on the data, but sometimes one of the agents is honest by assumption \n(e.g., the server) or the honesty of additional agents needs to be assumed\nfor the agreement to hold.\\<close>\n\ndatatype 'ds signal =\n  Running \"agent list\" \"'ds\" \n| Commit \"agent list\" \"'ds\"\n\nrecord 'ds a0n_state = \n  signals :: \"'ds signal \\<Rightarrow> nat\"    \\<comment> \\<open>multi-set of signals\\<close>\n  corrupted :: \"'ds set\"            \\<comment> \\<open>set of corrupted data\\<close>\n\ntype_synonym \n  'ds a0n_obs = \"'ds a0n_state\"\n\n\n(******************************************************************************)\nsubsection \\<open>Events\\<close>\n(******************************************************************************)\n\ndefinition \n  a0n_init :: \"'ds a0n_state set\"\nwhere\n  \"a0n_init \\<equiv> {s. \\<exists>ds. s = \\<lparr>\n     signals = \\<lambda>s. 0,\n     corrupted = ds\n  \\<rparr> }\"\n\ntext \\<open>Running signal, indicating end of responder run.\\<close>\n\ndefinition \n  a0n_running :: \"[agent list, 'ds] \\<Rightarrow> ('ds a0n_state \\<times> 'ds a0n_state) set\"\nwhere \n  \"a0n_running h d \\<equiv> {(s, s').\n    \\<comment> \\<open>actions:\\<close>\n    s' = s\\<lparr> \n      signals := (signals s)(Running h d := signals s (Running h d) + 1) \n    \\<rparr>\n  }\"\n\n\ntext \\<open>Commit signal, marking end of initiator run.\\<close>\n\ndefinition \n  a0n_commit :: \"[agent list, 'ds] \\<Rightarrow> ('ds a0n_state \\<times> 'ds a0n_state) set\"\nwhere \n  \"a0n_commit h d \\<equiv> {(s, s').\n    \\<comment> \\<open>guards:\\<close>\n    (set h \\<subseteq> good \\<longrightarrow> d \\<notin> corrupted s \\<longrightarrow> signals s (Running h d) > 0) \\<and>\n\n    \\<comment> \\<open>actions:\\<close>\n    s' = s\\<lparr> \n      signals := (signals s)(Commit h d := signals s (Commit h d) + 1) \n    \\<rparr>\n  }\"\n\ntext \\<open>Data corruption.\\<close>\n\ndefinition \n  a0n_corrupt :: \"'ds set \\<Rightarrow> ('ds a0n_state \\<times> 'ds a0n_state) set\"\nwhere\n  \"a0n_corrupt ds \\<equiv> {(s, s').\n    \\<comment> \\<open>actions:\\<close>\n    s' = s\\<lparr> \n      corrupted := corrupted s \\<union> ds \n    \\<rparr>   \n  }\"\n\n\ntext \\<open>Transition system.\\<close>\n\ndefinition \n  a0n_trans :: \"('ds a0n_state \\<times> 'ds a0n_state) set\" where\n  \"a0n_trans \\<equiv> (\\<Union>h d ds.\n     a0n_running h d \\<union>\n     a0n_commit h d \\<union> \n     a0n_corrupt ds \\<union> \n     Id\n  )\"\n\ndefinition \n  a0n :: \"('ds a0n_state, 'ds a0n_obs) spec\" where\n  \"a0n \\<equiv> \\<lparr>\n    init = a0n_init,\n    trans = a0n_trans, \n    obs = id\n  \\<rparr>\"\n\nlemmas a0n_defs = \n  a0n_def a0n_init_def a0n_trans_def \n  a0n_running_def a0n_commit_def a0n_corrupt_def\n\n\ntext \\<open>Any property is trivially observable.\\<close>\n\nlemma a0n_obs [simp]: \"obs a0n= id\"\nby (simp add: a0n_def)  \n\nlemma a0n_anyP_observable [iff]: \"observable (obs a0n) P\"\nby (auto)  \n\n\n(******************************************************************************)\nsubsection \\<open>Invariants\\<close>\n(******************************************************************************)\n\nsubsection \\<open>inv1: non-injective agreement\\<close>\n(******************************************************************************)\n\ntext \\<open>This is an extensional variant of Lowe's \\emph{non-injective agreement}\nof the first with the second agent (by convention) in \\<open>h\\<close> on data \n\\<open>d\\<close> [Lowe97]. \n\\<close>\n\ndefinition \n  a0n_inv1_niagree :: \"'ds a0n_state set\" \nwhere\n  \"a0n_inv1_niagree \\<equiv> {s. \\<forall>h d.\n     set h \\<subseteq> good \\<longrightarrow> d \\<notin> corrupted s \\<longrightarrow>\n       signals s (Commit h d) > 0 \\<longrightarrow> signals s (Running h d) > 0\n  }\"\n\nlemmas a0n_inv1_niagreeI = \n  a0n_inv1_niagree_def [THEN setc_def_to_intro, rule_format]\nlemmas a0n_inv1_niagreeE [elim] = \n  a0n_inv1_niagree_def [THEN setc_def_to_elim, rule_format]\nlemmas a0n_inv1_niagreeD = \n  a0n_inv1_niagree_def [THEN setc_def_to_dest, rule_format, rotated 2]\n\n\ntext \\<open>Invariance proof.\\<close>\n\nlemma PO_a0n_inv1_niagree_init [iff]:\n  \"init a0n \\<subseteq> a0n_inv1_niagree\"\nby (auto simp add: a0n_defs intro!: a0n_inv1_niagreeI)\n\nlemma PO_a0n_inv1_niagree_trans [iff]:\n  \"{a0n_inv1_niagree} trans a0n {> a0n_inv1_niagree}\"\napply (auto simp add: PO_hoare_defs a0n_defs intro!: a0n_inv1_niagreeI)\napply (auto dest!: a0n_inv1_niagreeD dest: dom_lemmas)\ndone\n\nlemma PO_a0n_inv1_niagree [iff]: \"reach a0n \\<subseteq> a0n_inv1_niagree\"\nby (rule inv_rule_basic) (auto)\n\n\ntext \\<open>This is also an external invariant.\\<close>\n\nlemma a0n_obs_inv1_niagree [iff]:\n  \"oreach a0n \\<subseteq> a0n_inv1_niagree\"\napply (rule external_from_internal_invariant, fast) \napply (subst a0n_def, auto)\ndone\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Security_Protocol_Refinement/Refinement/a0n_agree.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6584175139669997, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.29334444885962874}}
{"text": "subsection \\<open>CISK (Controlled Interruptible Separation Kernel)\\<close>\n\ntheory CISK\n  imports ISK\nbegin\n\ntext \\<open>\n  This section presents a generic model of a Controlled Interruptible Separation Kernel (CISK).\n  It formulates security, i.e., intransitive noninterference.\n  For a presentation of this model, see Section 2 of~\\cite{Verbeek2013}.\n\\<close>\n\ntext \\<open>\n  First, a locale is defined that defines all generic functions and all proof obligations (see Section 2.3 of ~\\cite{Verbeek2013}).\n\\<close>\nlocale Controllable_Interruptible_Separation_Kernel = \\<comment> \\<open>CISK\\<close>\nfixes kstep :: \"'state_t \\<Rightarrow> 'action_t \\<Rightarrow> 'state_t\" \\<comment> \\<open>Executes one atomic kernel action\\<close>\n  and output_f :: \"'state_t \\<Rightarrow> 'action_t \\<Rightarrow> 'output_t\" \\<comment> \\<open>Returns the observable behavior\\<close>\n  and s0 :: \"'state_t\" \\<comment> \\<open>The initial state\\<close>\n  and current :: \"'state_t => 'dom_t\" \\<comment> \\<open>Returns the currently active domain\\<close>\n  and cswitch :: \"time_t \\<Rightarrow> 'state_t \\<Rightarrow> 'state_t\" \\<comment> \\<open>Performs a context switch\\<close>\n  and interrupt :: \"time_t \\<Rightarrow> bool\" \\<comment> \\<open>Returns t iff an interrupt occurs in the given state at the given time\\<close>\n  and kinvolved :: \"'action_t \\<Rightarrow> 'dom_t set\" \\<comment> \\<open>Returns the set of domains that are involved in the given action\\<close>\n  and ifp :: \"'dom_t \\<Rightarrow> 'dom_t \\<Rightarrow> bool\" \\<comment> \\<open>The security policy.\\<close>\n  and vpeq :: \"'dom_t \\<Rightarrow> 'state_t \\<Rightarrow> 'state_t \\<Rightarrow> bool\" \\<comment> \\<open>View partitioning equivalence\\<close>\n  and AS_set :: \"('action_t list) set\" \\<comment> \\<open>Returns a set of valid action sequences, i.e., the attack surface\\<close>\n  and invariant :: \"'state_t \\<Rightarrow> bool\" \\<comment> \\<open>Returns an inductive state-invariant\\<close>\n  and AS_precondition :: \"'state_t \\<Rightarrow> 'dom_t \\<Rightarrow> 'action_t \\<Rightarrow> bool\" \\<comment> \\<open>Returns the preconditions under which the given action can be executed.\\<close>  \n  and aborting :: \"'state_t \\<Rightarrow> 'dom_t \\<Rightarrow> 'action_t \\<Rightarrow> bool\" \\<comment> \\<open>Returns true iff the action is aborted.\\<close>\n  and waiting :: \"'state_t \\<Rightarrow> 'dom_t \\<Rightarrow> 'action_t \\<Rightarrow> bool\" \\<comment> \\<open>Returns true iff execution of the given action is delayed.\\<close>\n  and set_error_code :: \"'state_t \\<Rightarrow> 'action_t \\<Rightarrow> 'state_t\" \\<comment> \\<open>Sets an error code when actions are aborted.\\<close>\nassumes vpeq_transitive: \" \\<forall> a b c u. (vpeq u a b \\<and> vpeq u b c) \\<longrightarrow> vpeq u a c\"\n    and vpeq_symmetric: \"\\<forall> a b u. vpeq u a b \\<longrightarrow> vpeq u b a\"\n    and vpeq_reflexive: \"\\<forall> a u. vpeq u a a\"\n    and ifp_reflexive: \"\\<forall> u . ifp u u\"     \n    and weakly_step_consistent: \"\\<forall> s t u a. vpeq u s t \\<and> vpeq (current s) s t \\<and> invariant s \\<and> AS_precondition s (current s) a \\<and> invariant t \\<and> AS_precondition t (current t) a \\<and> current s = current t  \\<longrightarrow> vpeq u (kstep s a) (kstep t a)\"\n    and locally_respects: \"\\<forall> a s u. \\<not>ifp (current s) u  \\<and> invariant s \\<and> AS_precondition s (current s) a \\<longrightarrow> vpeq u s (kstep s a)\"\n    and output_consistent: \"\\<forall> a s t. vpeq (current s) s t \\<and> current s = current t \\<longrightarrow> (output_f s a) = (output_f t a)\"\n    and step_atomicity: \"\\<forall> s a . current (kstep s a) = current s\"\n    and cswitch_independent_of_state: \"\\<forall> n s t . current s = current t \\<longrightarrow> current (cswitch n s) = current (cswitch n t)\"\n    and cswitch_consistency: \"\\<forall> u s t n . vpeq u s t \\<longrightarrow> vpeq u (cswitch n s) (cswitch n t)\"\n    and empty_in_AS_set: \"[] \\<in> AS_set\"\n    and invariant_s0: \"invariant s0\"\n    and invariant_after_cswitch: \"\\<forall> s n . invariant s \\<longrightarrow> invariant (cswitch n s)\"\n    and precondition_after_cswitch: \"\\<forall> s d n a. AS_precondition s d a \\<longrightarrow> AS_precondition (cswitch n s) d a\"\n    and AS_prec_first_action: \"\\<forall> s d aseq . invariant s \\<and> aseq \\<in> AS_set \\<and> aseq \\<noteq> [] \\<longrightarrow> AS_precondition s d (hd aseq)\"\n    and AS_prec_after_step: \"\\<forall> s a a' . (\\<exists> aseq \\<in> AS_set . is_sub_seq a a' aseq) \\<and> invariant s \\<and> AS_precondition s (current s) a \\<and> \\<not>aborting s (current s) a \\<and> \\<not> waiting s (current s) a\\<longrightarrow> AS_precondition (kstep s a) (current s) a'\"\n    and AS_prec_dom_independent: \"\\<forall> s d a a' . current s \\<noteq> d \\<and> AS_precondition s d a \\<longrightarrow> AS_precondition (kstep s a') d a\"\n    and spec_of_invariant: \"\\<forall> s a . invariant s \\<longrightarrow> invariant (kstep s a)\"\n    and aborting_switch_independent: \"\\<forall> n s . aborting (cswitch n s) = aborting s\"\n    and aborting_error_update: \"\\<forall> s d a' a . current s \\<noteq> d \\<and> aborting s d a \\<longrightarrow> aborting (set_error_code s a') d a\"\n    and aborting_after_step: \"\\<forall> s a d . current s \\<noteq> d \\<longrightarrow> aborting (kstep s a) d = aborting s d\" (* TODO: I think this PO can be removed *)\n    and aborting_consistent: \"\\<forall> s t u . vpeq u s t \\<longrightarrow> aborting s u = aborting t u\"\n    and waiting_switch_independent: \"\\<forall> n s . waiting (cswitch n s) = waiting s\"\n    and waiting_error_update: \"\\<forall> s d a' a . current s \\<noteq> d \\<and> waiting s d a \\<longrightarrow> waiting (set_error_code s a') d a\"\n    and waiting_consistent: \"\\<forall>s t u a . vpeq (current s) s t \\<and> (\\<forall> d \\<in> kinvolved a . vpeq d s t) \\<and> vpeq u s t \\<longrightarrow> waiting s u a = waiting t u a\"\n    and spec_of_waiting: \"\\<forall> s a . waiting s (current s) a \\<longrightarrow> kstep s a = s\"\n    and set_error_consistent: \"\\<forall> s t u a . vpeq u s t \\<longrightarrow> vpeq u (set_error_code s a) (set_error_code t a)\"\n    and set_error_locally_respects: \"\\<forall> s u a . \\<not>ifp (current s) u \\<longrightarrow> vpeq u s (set_error_code s a)\"\n    and current_set_error_code: \"\\<forall> s a . current (set_error_code s a) = current s\"\n    and precondition_after_set_error_code: \"\\<forall> s d a a'. AS_precondition s d a \\<and> aborting s (current s) a' \\<longrightarrow> AS_precondition (set_error_code s a') d a\"\n    and invariant_after_set_error_code: \"\\<forall> s a . invariant s \\<longrightarrow> invariant (set_error_code s a)\"\n    and involved_ifp: \"\\<forall> s a . \\<forall> d \\<in> (kinvolved a) . AS_precondition s (current s) a \\<longrightarrow> ifp d (current s)\"  \nbegin  \n\nsubsubsection\\<open>Execution semantics\\<close>\n\ntext\\<open>\n  Control is based on generic functions \\emph{aborting}, \\emph{waiting} and \\emph{set\\_error\\_code}.\n  Function \\emph{aborting} decides whether a certain action is aborting, given its domain and the state.\n  If so, then function set\\_error\\_code will be used to update the state, possibly communicating to other domains that an action has been aborted.\n  Function \\emph{waiting} can delay the execution of an action.\n  This behavior is implemented in function CISK\\_control.\n\\<close>\nfunction CISK_control :: \"'state_t \\<Rightarrow> 'dom_t \\<Rightarrow> 'action_t execution \\<Rightarrow> ('action_t option \\<times> 'action_t execution \\<times> 'state_t)\"\nwhere \"CISK_control s d []                = (None,[],s)\" \\<comment> \\<open>The thread is empty\\<close>\n    | \"CISK_control s d ([]#[])           = (None,[],s)\" \\<comment> \\<open>The current action sequence has been finished and the thread has no next action sequences to execute\\<close>\n    | \"CISK_control s d ([]#(as'#execs')) = (None,as'#execs',s)\" \\<comment> \\<open>The current action sequence has been finished. Skip to the next sequence\\<close>\n    | \"CISK_control s d ((a#as)#execs')   = (if aborting s d a then \n                                                  (None, execs',set_error_code s a)\n                                               else if waiting s d a then\n                                                  (Some a, (a#as)#execs',s)\n                                               else\n                                                  (Some a, as#execs',s))\" \\<comment> \\<open>Executing an action sequence\\<close>\nby pat_completeness auto\ntermination by lexicographic_order\n\ntext\\<open>\n  Function \\emph{run} defines the execution semantics.\n  This function is presented in ~\\cite{Verbeek2013} by pseudo code (see Algorithm 1).\n  Before defining the run function, we define accessor functions for the control mechanism.\n  Functions next\\_action, next\\_execs and next\\_state correspond to ``control.a'', ``control.x'' and ``control.s'' in ~\\cite{Verbeek2013}.\n\\<close>\nabbreviation next_action::\"'state_t \\<Rightarrow> ('dom_t \\<Rightarrow> 'action_t execution) \\<Rightarrow> 'action_t option\"\nwhere \"next_action \\<equiv> Kernel.next_action current CISK_control\"\nabbreviation next_execs::\"'state_t \\<Rightarrow> ('dom_t \\<Rightarrow> 'action_t execution) \\<Rightarrow> ('dom_t \\<Rightarrow> 'action_t execution)\"\nwhere \"next_execs  \\<equiv> Kernel.next_execs current CISK_control\"\nabbreviation next_state::\"'state_t \\<Rightarrow> ('dom_t \\<Rightarrow> 'action_t execution) \\<Rightarrow> 'state_t\"\nwhere \"next_state  \\<equiv> Kernel.next_state current CISK_control\"\ntext \\<open>\n\\<close>\ntext \\<open>\n  A thread is empty iff either it has no further action sequences to execute, or when the current action sequence is finished and there are no further action sequences to execute.\n\\<close>\nabbreviation thread_empty::\"'action_t execution \\<Rightarrow> bool\"\nwhere \"thread_empty exec \\<equiv> exec = [] \\<or> exec = [[]]\"\n\ntext\\<open>\n  The following function defines the execution semantics of CISK, using function CISK\\_control.\n\\<close>\nfunction run :: \"time_t \\<Rightarrow> 'state_t \\<Rightarrow> ('dom_t \\<Rightarrow> 'action_t execution) \\<Rightarrow> 'state_t\"\nwhere \"run 0 s execs = s\"\n| \"interrupt (Suc n) \\<Longrightarrow> run (Suc n) s execs = run n (cswitch (Suc n) s) execs\"\n| \"\\<not>interrupt (Suc n) \\<Longrightarrow> thread_empty(execs (current s)) \\<Longrightarrow> run (Suc n) s execs = run n s execs\"\n| \"\\<not>interrupt (Suc n) \\<Longrightarrow> \\<not>thread_empty(execs (current s)) \\<Longrightarrow>\n      run (Suc n) s execs = (let control_a = next_action s execs;\n                                 control_s = next_state s execs;\n                                 control_x = next_execs s execs in\n                             case control_a of None \\<Rightarrow> run n control_s control_x\n                                         | (Some a) \\<Rightarrow> run n (kstep control_s a) control_x)\"\nusing not0_implies_Suc by (metis prod_cases3,auto)\ntermination by lexicographic_order\n\nsubsubsection \\<open>Formulations of security\\<close>\n\ntext\\<open>\n  The definitions of security as presented in Section 2.2 of~\\cite{Verbeek2013}.\n\\<close>\n\nabbreviation kprecondition\n  where \"kprecondition s a \\<equiv> invariant s \\<and> AS_precondition s (current s) a\"\ndefinition realistic_execution\nwhere \"realistic_execution aseq \\<equiv> set aseq \\<subseteq> AS_set\"\ndefinition realistic_executions :: \"('dom_t \\<Rightarrow> 'action_t execution) \\<Rightarrow> bool\"\nwhere \"realistic_executions execs \\<equiv> \\<forall>d. realistic_execution (execs d)\"\nabbreviation involved where \"involved \\<equiv> Kernel.involved kinvolved\"\nabbreviation step where \"step \\<equiv> Kernel.step kstep\"\nabbreviation purge where \"purge \\<equiv> Separation_Kernel.purge realistic_execution ifp\"\nabbreviation ipurge_l where \"ipurge_l \\<equiv> Separation_Kernel.ipurge_l kinvolved ifp\"\nabbreviation ipurge_r where \"ipurge_r \\<equiv> Separation_Kernel.ipurge_r realistic_execution kinvolved ifp\"\n\ndefinition NI_unrelated::bool\nwhere \"NI_unrelated\n  \\<equiv> \\<forall> execs a n . realistic_executions execs \\<longrightarrow>\n                      (let s_f = run n s0 execs in\n                         output_f s_f a = output_f (run n s0 (purge execs (current s_f))) a)\"\ndefinition NI_indirect_sources::bool\nwhere \"NI_indirect_sources\n  \\<equiv> \\<forall> execs a n. realistic_executions execs \\<longrightarrow>\n                    (let s_f = run n s0 execs in\n                      output_f (run n s0 (ipurge_l execs (current s_f))) a =\n                      output_f (run n s0 (ipurge_r execs (current s_f))) a)\"\ndefinition isecure::bool\nwhere \"isecure \\<equiv> NI_unrelated \\<and> NI_indirect_sources\"\n\n\nsubsubsection \\<open>Proofs\\<close>\ntext\\<open>\n  The final theorem is unwinding\\_implies\\_isecure\\_CISK.\n  This theorem shows that any interpretation of locale CISK is secure.\n\n  To prove this theorem, the refinement framework is used.\n  CISK is a refinement of ISK, as the only idfference is the control function.\n  In ISK, this function is a generic function called \\emph{control}, in CISK it is interpreted in function \\emph{CISK\\_control}.\n  It is proven that function \\emph{CISK\\_control} satisfies all the proof obligations concerning generic function \\emph{control}.\n  In other words, \\emph{CISK\\_control} is proven to be an interpretation of control.\n  Therefore, all theorems on run\\_total apply to the run function of CISK as well.\n\\<close>\n\nlemma next_action_consistent: \nshows \"\\<forall> s t execs . vpeq (current s) s t \\<and> (\\<forall> d \\<in>  involved (next_action s execs) . vpeq d s t) \\<and> current s = current t  \\<longrightarrow> next_action s execs = next_action t execs\"\nproof-\n{\n  fix s t execs\n  assume vpeq: \"vpeq (current s) s t\"\n  assume vpeq_involved: \"\\<forall> d \\<in>  involved (next_action s execs) . vpeq d s t\"\n  assume current_s_t: \"current s = current t\"\n  from aborting_consistent current_s_t vpeq\n   have \"aborting t (current s) = aborting s (current s)\" by auto\n  from current_s_t this waiting_consistent vpeq_involved\n    have \"next_action s execs = next_action t execs\"\n    unfolding Kernel.next_action_def \n    by(cases \"(s,(current s),execs (current s))\" rule: CISK_control.cases,auto)\n}\nthus ?thesis by auto\nqed\n\nlemma next_execs_consistent:\nshows \"\\<forall> s t execs . vpeq (current s) s t \\<and> (\\<forall> d \\<in> involved (next_action s execs) . vpeq d s t) \\<and> current s = current t \\<longrightarrow> fst (snd (CISK_control s (current s) (execs (current s)))) = fst (snd (CISK_control t (current s) (execs (current s))))\"\nproof-\n{\n  fix s t execs\n  assume vpeq: \"vpeq (current s) s t\"\n  assume vpeq_involved: \"\\<forall> d \\<in> involved (next_action s execs) . vpeq d s t\"\n  assume current_s_t: \"current s = current t\"\n  from aborting_consistent current_s_t vpeq\n     have 1: \"aborting t (current s) = aborting s (current s)\" by auto\n  from 1 vpeq current_s_t vpeq_involved waiting_consistent[THEN spec,THEN spec,THEN spec,THEN spec,where x3=s and x2=t and x1=\"current s\" and x=\"the (next_action s execs)\"]\n    have \"fst (snd (CISK_control s (current s) (execs (current s)))) = fst (snd (CISK_control t (current s) (execs (current s))))\"\n    unfolding Kernel.next_action_def Kernel.involved_def\n    by(cases \"(s,(current s),execs (current s))\" rule: CISK_control.cases,auto split: if_split_asm)\n}\nthus ?thesis by auto\nqed\n\nlemma next_state_consistent:\nshows \"\\<forall> s t u execs . vpeq (current s) s t \\<and> vpeq u s t \\<and> current s = current t \\<longrightarrow> vpeq u (next_state s execs) (next_state t execs)\"\nproof-\n{\n  fix s t u execs\n  assume vpeq_s_t: \"vpeq (current s) s t \\<and> vpeq u s t\"\n  assume current_s_t: \"current s = current t\"\n  from vpeq_s_t current_s_t\n    have \"vpeq u (next_state s execs) (next_state t execs)\"\n    unfolding Kernel.next_state_def\n    using aborting_consistent set_error_consistent\n    by(cases \"(s,(current s),execs (current s))\" rule: CISK_control.cases,auto)\n}\nthus ?thesis by auto\nqed\n\nlemma current_next_state:\nshows \"\\<forall> s execs . current (next_state s execs) = current s\" \nproof-\n{\n  fix s execs\n  have \"current (next_state s execs) = current s\"\n    unfolding Kernel.next_state_def\n    using current_set_error_code\n    by(cases \"(s,(current s),execs (current s))\" rule: CISK_control.cases,auto)\n}\nthus ?thesis by auto\nqed\n\nlemma locally_respects_next_state:\nshows \"\\<forall> s u execs. \\<not>ifp (current s) u \\<longrightarrow> vpeq u s (next_state s execs)\"\nproof-\n{\n  fix s u execs\n  assume \"\\<not>ifp (current s) u\"\n  hence \"vpeq u s (next_state s execs)\"\n    unfolding Kernel.next_state_def\n    using vpeq_reflexive set_error_locally_respects\n    by(cases \"(s,(current s),execs (current s))\" rule: CISK_control.cases,auto)\n}\nthus ?thesis by auto\nqed\n\nlemma CISK_control_spec:\nshows \"\\<forall>s d aseqs.\n       case CISK_control s d aseqs of\n       (a, aseqs', s') \\<Rightarrow>\n         thread_empty aseqs \\<and> (a, aseqs') = (None, []) \\<or>\n         aseqs \\<noteq> [] \\<and> hd aseqs \\<noteq> [] \\<and> \\<not> aborting s' d (the a) \\<and> \\<not> waiting s' d (the a) \\<and> (a, aseqs') = (Some (hd (hd aseqs)), tl (hd aseqs) # tl aseqs) \\<or>\n         aseqs \\<noteq> [] \\<and> hd aseqs \\<noteq> [] \\<and> waiting s' d (the a) \\<and> (a, aseqs', s') = (Some (hd (hd aseqs)), aseqs, s) \\<or> (a, aseqs') = (None, tl aseqs)\"\nproof-\n{\n  fix s d aseqs\n  have \"case CISK_control s d aseqs of\n       (a, aseqs', s') \\<Rightarrow>\n         thread_empty aseqs \\<and> (a, aseqs') = (None, []) \\<or>\n         aseqs \\<noteq> [] \\<and> hd aseqs \\<noteq> [] \\<and> \\<not> aborting s' d (the a) \\<and> \\<not> waiting s' d (the a) \\<and> (a, aseqs') = (Some (hd (hd aseqs)), tl (hd aseqs) # tl aseqs) \\<or>\n         aseqs \\<noteq> [] \\<and> hd aseqs \\<noteq> [] \\<and> waiting s' d (the a) \\<and> (a, aseqs', s') = (Some (hd (hd aseqs)), aseqs, s) \\<or> (a, aseqs') = (None, tl aseqs)\"\n  by(cases \"(s,d,aseqs)\" rule: CISK_control.cases,auto)\n}\nthus ?thesis by auto\nqed\n\nlemma next_action_after_cswitch:\nshows \"\\<forall> s n d aseqs . fst (CISK_control (cswitch n s) d aseqs) = fst (CISK_control s d aseqs)\"\nproof-\n{\n  fix s n d aseqs\n  have \"fst (CISK_control (cswitch n s) d aseqs) = fst (CISK_control s d aseqs)\"\n  using aborting_switch_independent waiting_switch_independent\n  by(cases \"(s,d,aseqs)\" rule: CISK_control.cases,auto)\n}\nthus ?thesis by auto\nqed\n\n\nlemma next_action_after_next_state:\nshows \"\\<forall> s execs d . current s \\<noteq> d \\<longrightarrow> fst (CISK_control (next_state s execs) d (execs d)) = None \\<or> fst (CISK_control (next_state s execs) d (execs d)) = fst (CISK_control s d (execs d))\"\nproof-\n{\n  fix s execs d aseqs\n  assume 1: \"current s \\<noteq> d\"\n  have \"fst (CISK_control (next_state s execs) d aseqs) = None \\<or> fst (CISK_control (next_state s execs) d aseqs) = fst (CISK_control s d aseqs)\"\n    proof(cases \"(s,d,aseqs)\" rule: CISK_control.cases,simp,simp,simp)\n    case (4 sa da a as execs')\n      thus ?thesis\n          unfolding Kernel.next_state_def\n          using aborting_error_update waiting_error_update 1\n          by(cases \"(sa,current sa,execs (current sa))\" rule: CISK_control.cases,auto split: if_split_asm)\n    qed\n}\nthus ?thesis by auto\nqed\n\nlemma next_action_after_step:\nshows \"\\<forall> s a d aseqs . current s \\<noteq> d \\<longrightarrow> fst (CISK_control (step s a) d aseqs) = fst (CISK_control s d aseqs)\"\nproof-\n{\n  fix s a d aseqs\n  assume 1: \"current s \\<noteq> d\"\n  from this aborting_after_step \n    have  \"fst (CISK_control (step s a) d aseqs) = fst (CISK_control s d aseqs)\"\n    unfolding Kernel.step_def \n    by(cases \"(s,d,aseqs)\" rule: CISK_control.cases,simp,simp,simp,cases a,auto)\n}\nthus ?thesis by auto\nqed\n\nlemma next_state_precondition:\nshows \"\\<forall>s d a execs. AS_precondition s d a \\<longrightarrow> AS_precondition (next_state s execs) d a\"\nproof-\n{\n  fix s a d execs\n  assume \"AS_precondition s d a\"\n  hence \"AS_precondition (next_state s execs) d a\"\n    unfolding Kernel.next_state_def\n    using precondition_after_set_error_code\n    by(cases \"(s,(current s),execs (current s))\" rule: CISK_control.cases,auto)\n}\nthus ?thesis by auto\nqed\n\nlemma next_state_invariant:\nshows \"\\<forall>s execs. invariant s \\<longrightarrow> invariant (next_state s execs)\"\nproof-\n{\n  fix s execs\n  assume \"invariant s\"\n  hence \"invariant (next_state s execs)\"\n    unfolding Kernel.next_state_def\n    using invariant_after_set_error_code\n    by(cases \"(s,(current s),execs (current s))\" rule: CISK_control.cases,auto)\n}\nthus ?thesis by auto\nqed\n\nlemma next_action_from_execs:\nshows \"\\<forall> s execs . next_action s execs \\<rightharpoonup> (\\<lambda> a . a \\<in> actions_in_execution (execs (current s)))\"\nproof-\n{\n  fix s execs\n  {\n    fix a\n    assume 1: \"next_action s execs = Some a\"\n    from 1 have \"a \\<in> actions_in_execution (execs (current s))\"\n      unfolding Kernel.next_action_def actions_in_execution_def\n      by (cases \"(s,(current s),execs (current s))\" rule: CISK_control.cases,auto split: if_split_asm)\n  }\n  hence \"next_action s execs \\<rightharpoonup> (\\<lambda> a . a \\<in> actions_in_execution (execs (current s)))\"\n    unfolding B_def\n    by (cases \"next_action s execs\",auto)\n}\nthus ?thesis unfolding B_def by (auto)\nqed\n\nlemma next_execs_subset:\nshows \"\\<forall>s execs u . actions_in_execution (next_execs s execs u) \\<subseteq> actions_in_execution (execs u)\"\nproof-\n{\n  fix s execs u\n  have \"actions_in_execution (next_execs s execs u) \\<subseteq> actions_in_execution (execs u)\"\n    unfolding Kernel.next_execs_def actions_in_execution_def\n    by (cases \"(s,(current s),execs (current s))\" rule: CISK_control.cases,auto split: if_split_asm)\n}\nthus ?thesis by auto\nqed\n\n\ntheorem unwinding_implies_isecure_CISK:\nshows isecure\nproof-\n  interpret int: Interruptible_Separation_Kernel kstep output_f s0 current cswitch interrupt kprecondition realistic_execution CISK_control kinvolved ifp vpeq AS_set invariant AS_precondition aborting waiting\n    proof (unfold_locales)\n      show \"\\<forall>a b c u. vpeq u a b \\<and> vpeq u b c \\<longrightarrow> vpeq u a c\"\n        using vpeq_transitive by blast\n      show \"\\<forall>a b u. vpeq u a b \\<longrightarrow> vpeq u b a\"\n        using vpeq_symmetric by blast\n      show \"\\<forall>a u. vpeq u a a\"\n        using vpeq_reflexive by blast\n      show \"\\<forall>u. ifp u u\"\n        using ifp_reflexive by blast\n      show \"\\<forall> s t u a. vpeq u s t \\<and> vpeq (current s) s t \\<and> kprecondition s a \\<and> kprecondition t a \\<and> current s = current t  \\<longrightarrow> vpeq u (kstep s a) (kstep t a)\"\n        using weakly_step_consistent by blast\n      show \"\\<forall> a s u. \\<not>ifp (current s) u  \\<and> kprecondition s a \\<longrightarrow> vpeq u s (kstep s a)\"\n        using locally_respects by blast\n      show \"\\<forall> a s t. vpeq (current s) s t \\<and> current s = current t \\<longrightarrow> (output_f s a) = (output_f t a)\"\n        using output_consistent by blast        \n      show \"\\<forall> s a . current (kstep s a) = current s\"\n        using step_atomicity by blast        \n      show \"\\<forall> n s t . current s = current t \\<longrightarrow> current (cswitch n s) = current (cswitch n t)\"\n        using cswitch_independent_of_state by blast                                                    \n      show \"\\<forall> u s t n . vpeq u s t \\<longrightarrow> vpeq u (cswitch n s) (cswitch n t)\"\n        using cswitch_consistency by blast\n      show \"\\<forall>s t execs. vpeq (current s) s t \\<and> (\\<forall> d \\<in> involved (next_action s execs) . vpeq d s t) \\<and> current s = current t \\<longrightarrow> next_action s execs = next_action t execs\"\n        using next_action_consistent by blast\n      show \"\\<forall>s t execs.\n        vpeq (current s) s t \\<and> (\\<forall> d \\<in> involved (next_action s execs) . vpeq d s t) \\<and> current s = current t \\<longrightarrow>\n        fst (snd (CISK_control s (current s) (execs (current s)))) = fst (snd (CISK_control t (current s) (execs (current s))))\"\n        using next_execs_consistent by blast\n      show \" \\<forall>s t u execs. vpeq (current s) s t \\<and> vpeq u s t \\<and> current s = current t \\<longrightarrow> vpeq u (next_state s execs) (next_state t execs)\"\n        using next_state_consistent by auto\n      show \" \\<forall>s execs. current (next_state s execs) = current s\"\n        using current_next_state by auto\n      show \"\\<forall>s u execs. \\<not> ifp (current s) u \\<longrightarrow> vpeq u s (next_state s execs)\"\n        using locally_respects_next_state by auto\n      show \"[] \\<in> AS_set\"\n        using empty_in_AS_set by blast\n      show \"\\<forall> s n . invariant s \\<longrightarrow> invariant (cswitch n s)\"\n        using invariant_after_cswitch by blast\n      show \"\\<forall> s d n a. AS_precondition s d a \\<longrightarrow> AS_precondition (cswitch n s) d a\"\n        using precondition_after_cswitch by blast\n      show \"invariant s0\"\n        using invariant_s0 by blast\n      show \"\\<forall> s d aseq . invariant s \\<and> aseq \\<in> AS_set \\<and> aseq \\<noteq> [] \\<longrightarrow> AS_precondition s d (hd aseq)\"\n        using AS_prec_first_action by blast\n      show \"\\<forall>s a a'. (\\<exists>aseq\\<in>AS_set. is_sub_seq a a' aseq) \\<and> invariant s \\<and> AS_precondition s (current s) a \\<and> \\<not> aborting s (current s) a \\<and> \\<not> waiting s (current s) a \\<longrightarrow>\n             AS_precondition (kstep s a) (current s) a'\"\n        using AS_prec_after_step by blast       \n      show \"\\<forall> s d a a' . current s \\<noteq> d \\<and> AS_precondition s d a \\<longrightarrow> AS_precondition (kstep s a') d a\"\n        using AS_prec_dom_independent by blast  \n      show \"\\<forall> s a . invariant s \\<longrightarrow> invariant (kstep s a)\"\n        using spec_of_invariant by blast\n      show \"\\<And>s a. kprecondition s a \\<equiv> kprecondition s a\"\n        by auto         \n      show \"\\<And>aseq. realistic_execution aseq \\<equiv> set aseq \\<subseteq> AS_set\"\n        unfolding realistic_execution_def\n        by auto\n      show \"\\<forall>s a. \\<forall> d \\<in> involved a. kprecondition s (the a) \\<longrightarrow> ifp d (current s)\"\n        using involved_ifp unfolding Kernel.involved_def by (auto split: option.splits)\n      show \"\\<forall>s execs. next_action s execs \\<rightharpoonup> (\\<lambda>a. a \\<in> actions_in_execution (execs (current s)))\"\n        using next_action_from_execs by blast \n      show \"\\<forall>s execs u. actions_in_execution (next_execs s execs u) \\<subseteq> actions_in_execution (execs u)\"\n        using next_execs_subset by blast        \n      show \"\\<forall>s d aseqs.\n       case CISK_control s d aseqs of\n       (a, aseqs', s') \\<Rightarrow>\n         thread_empty aseqs \\<and> (a, aseqs') = (None, []) \\<or>\n         aseqs \\<noteq> [] \\<and> hd aseqs \\<noteq> [] \\<and> \\<not> aborting s' d (the a) \\<and> \\<not> waiting s' d (the a) \\<and> (a, aseqs') = (Some (hd (hd aseqs)), tl (hd aseqs) # tl aseqs) \\<or>\n         aseqs \\<noteq> [] \\<and> hd aseqs \\<noteq> [] \\<and> waiting s' d (the a) \\<and> (a, aseqs', s') = (Some (hd (hd aseqs)), aseqs, s) \\<or> (a, aseqs') = (None, tl aseqs)\"\n        using CISK_control_spec by blast\n      show \"\\<forall>s n d aseqs. fst (CISK_control (cswitch n s) d aseqs) = fst (CISK_control s d aseqs)\"\n        using next_action_after_cswitch by auto\n      show \"\\<forall>s execs d.\n       current s \\<noteq> d \\<longrightarrow>\n       fst (CISK_control (next_state s execs) d (execs d)) = None \\<or> fst (CISK_control (next_state s execs) d (execs d)) = fst (CISK_control s d (execs d))\"\n        using next_action_after_next_state by auto\n      show \"\\<forall>s a d aseqs. current s \\<noteq> d \\<longrightarrow> fst (CISK_control (step s a) d aseqs) = fst (CISK_control s d aseqs)\"\n        using next_action_after_step by auto\n      show \"\\<forall>s d a execs. AS_precondition s d a \\<longrightarrow> AS_precondition (next_state s execs) d a\"\n        using next_state_precondition by auto\n      show \"\\<forall>s execs. invariant s \\<longrightarrow> invariant (next_state s execs)\"\n        using next_state_invariant by auto\n      show \"\\<forall>s a. waiting s (current s) a \\<longrightarrow> kstep s a = s\"\n        using spec_of_waiting by blast\n  qed\n  \n  note interpreted = int.Interruptible_Separation_Kernel_axioms\n  note run_total_induct = Interruptible_Separation_Kernel.run_total.induct[of kstep output_f s0 current cswitch kprecondition realistic_execution\n                                                                             CISK_control kinvolved ifp vpeq AS_set invariant AS_precondition aborting waiting _ interrupt]\n  have run_equals_run_total:\n     \"\\<And> n s execs . run n s execs \\<equiv> Interruptible_Separation_Kernel.run_total kstep current cswitch interrupt CISK_control n s execs\"\n     proof-\n        fix n s execs\n        show \"run n s execs \\<equiv> Interruptible_Separation_Kernel.run_total kstep current cswitch interrupt CISK_control n s execs\"\n          using interpreted int.step_def\n          by(induct n s execs rule: run_total_induct,auto split: option.splits)\n     qed\n  from interpreted\n    have 0: \"Interruptible_Separation_Kernel.isecure_total kstep output_f s0 current cswitch interrupt realistic_execution CISK_control kinvolved ifp\"\n    by (metis int.unwinding_implies_isecure_total)\n  from 0 run_equals_run_total\n    have 1: \"NI_unrelated\"\n    by (metis realistic_executions_def int.isecure_total_def int.realistic_executions_def int.NI_unrelated_total_def NI_unrelated_def)\n  from 0 run_equals_run_total\n    have 2: \"NI_indirect_sources\"\n    by (metis realistic_executions_def int.NI_indirect_sources_total_def int.isecure_total_def int.realistic_executions_def NI_indirect_sources_def)\n  from 1 2 show ?thesis unfolding isecure_def by auto\nqed\n\nend\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/CISC-Kernel/trace/Rushby-with-Control/CISK.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6757645879592642, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.2932693057451644}}
{"text": "section \"Packed Traces\"\ntheory packed_traces\n  imports commutativity\nbegin\n\n\ntext \"In this section we show that traces can be packed.\nIntuitively a transaction is packed, if there are no steps from other invocations between a \n@{term ABeginAtomic} and @{term AEndAtomic} action.\n\nThe following definition defines that such a step exists at an index @{term k}.\n\"\n\ndefinition indexInOtherTransaction :: \"('proc, 'op, 'any) trace \\<Rightarrow> txId \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"indexInOtherTransaction tr tx k \\<equiv> \n  \\<exists>i s ntxns. \n      k<length tr \n    \\<and> i<k \n    \\<and> tr!i = (s, ABeginAtomic tx ntxns)  \n    \\<and> get_invoc (tr!k) \\<noteq> s\n    \\<and> \\<not>(\\<exists>j. i < j \\<and> j < k \\<and> tr!j = (s, AEndAtomic))\"\n\ntext \"With this we can define that a trace is packed, if no such step exists:\"\n\ndefinition transactionIsPacked :: \"('proc, 'op, 'any) trace \\<Rightarrow> txId \\<Rightarrow> bool\" where\n  \"transactionIsPacked tr tx \\<equiv> \n  \\<forall>k. \\<not>indexInOtherTransaction tr tx k\"  \n\n\n\n\n\n\\<comment> \\<open>this is an alternative definition, which might be easier to work with in some cases\\<close>\ndefinition transactionIsPackedAlt :: \"('proc, 'op, 'any) trace \\<Rightarrow> txId \\<Rightarrow> bool\" where\n  \"transactionIsPackedAlt tr tx \\<equiv> \n  if \\<exists>i s ntxns. i < length tr \\<and> tr!i = (s, ABeginAtomic tx ntxns) then\n    \\<exists>i s end ntxns. \n         i < length tr \n        \\<and> tr!i = (s, ABeginAtomic tx ntxns)\n        \\<and> end > i  \n        \\<and> (end < length tr \\<and> tr!end = (s, AEndAtomic) \\<or> end = length tr)  \n        \\<and> (\\<forall>j. i\\<le>j \\<and> j< end \\<longrightarrow> get_invoc (tr!j) = s) \n  else\n    True\n  \"  \n\nlemma transactionIsPackedAlt_case_tx_exists:\n  assumes \"(s, ABeginAtomic tx ntxns) \\<in> set tr\"\n  shows \"transactionIsPackedAlt tr tx \\<equiv> \n    \\<exists>i s end ntxns. \n         i < length tr \n        \\<and> tr!i = (s, ABeginAtomic tx ntxns)\n        \\<and> end > i  \n        \\<and> (end < length tr \\<and> tr!end = (s, AEndAtomic) \\<or> end = length tr)  \n        \\<and> (\\<forall>j. i\\<le>j \\<and> j< end \\<longrightarrow> get_invoc (tr!j) = s) \n  \"  \n  by (subst transactionIsPackedAlt_def,\n      subst if_P,\n      insert assms,\n      meson in_set_conv_nth, simp)\n\n\n\nlemma transactionIsPackedAlt_eq:\n  assumes uniqueTxs: \"\\<And>i j s s' tnxns tnxns'. \\<lbrakk>i<length tr; j<length tr; tr!i = (s, ABeginAtomic tx tnxns); tr!j = (s', ABeginAtomic tx tnxns')\\<rbrakk> \\<Longrightarrow> i = j\"\n  shows \"transactionIsPackedAlt tr tx = transactionIsPacked tr tx\"\nproof (auto simp add: transactionIsPackedAlt_def )\n  fix i s ntxns ia sa ntxns'\n  assume a0: \"i < length tr\"\n    and a1: \"tr ! i = (s, ABeginAtomic tx ntxns)\"\n    and a2: \"ia < length tr\"\n    and a3: \"tr ! ia = (sa, ABeginAtomic tx ntxns')\"\n    and a4: \"\\<forall>j. ia \\<le> j \\<and> j < length tr \\<longrightarrow> get_invoc (tr ! j) = sa\"\n\n  have [simp]: \"ia = i\"\n    using a2 a0 a3 a1 by (rule uniqueTxs)\n\n\n\n  then have [simp]: \"sa = s\"\n    using a1 a3 by auto  \n  then have a4': \"\\<And>j. i \\<le> j \\<Longrightarrow> j < length tr \\<Longrightarrow> get_invoc (tr ! j) = s\"  \n    using a4 by auto\n\n  show \"transactionIsPacked tr tx\"\n    by (auto simp add: transactionIsPacked_def indexInOtherTransaction_def,\n        smt \\<open>ia = i\\<close> \\<open>sa = s\\<close> a2 a3 a4' le_eq_less_or_eq le_less_trans prod.inject uniqueTxs)\nnext\n  fix i s ntxns\n  assume a0: \"i < length tr\"\n    and a1: \"tr ! i = (s, ABeginAtomic tx ntxns)\"\n    and a2: \"transactionIsPacked tr tx\"\n\n  from a2\n  have a2': \"get_invoc (tr ! k) = s \\<or> (\\<exists>j<k. i < j \\<and> tr ! j = (s, AEndAtomic))\" \n    if \"k<length tr\" \"i<k\"\n    for k\n    using a1 that by (auto simp add: transactionIsPacked_def indexInOtherTransaction_def)\n\n  show \"\\<exists>i<length tr. \\<exists>s. (\\<exists>ntxns. tr ! i = (s, ABeginAtomic tx ntxns)) \\<and> (\\<exists>end>i. (end < length tr \\<and> tr ! end = (s, AEndAtomic) \\<or> end = length tr) \\<and> (\\<forall>j. i \\<le> j \\<and> j < end \\<longrightarrow> get_invoc (tr ! j) = s))\"  \n  proof (rule exI[where x=i], (auto simp add: a0))\n    show \"\\<exists>s. (\\<exists>ntxns. tr ! i = (s, ABeginAtomic tx ntxns)) \\<and> (\\<exists>end>i. (end < length tr \\<and> tr ! end = (s, AEndAtomic) \\<or> end = length tr) \\<and> (\\<forall>j. i \\<le> j \\<and> j < end \\<longrightarrow> get_invoc (tr ! j) = s))\"\n    proof (rule exI[where x=s], safe)\n      show \"\\<exists>ntxns. tr ! i = (s, ABeginAtomic tx ntxns)\"\n        by (simp add: a1) \n      define endPos where \"endPos = (if \\<exists>j. i<j \\<and> j<length tr \\<and> tr!j = (s, AEndAtomic) then LEAST j. i<j \\<and> j<length tr \\<and> tr!j = (s, AEndAtomic) else length tr)\"\n      show \"\\<exists>end>i. (end < length tr \\<and> tr ! end = (s, AEndAtomic) \\<or> end = length tr) \\<and> (\\<forall>j. i \\<le> j \\<and> j < end \\<longrightarrow> get_invoc (tr ! j) = s) \"\n      proof (rule exI[where x=\"endPos\"], (auto simp add: endPos_def))\n        show \"\\<And>j. \\<lbrakk>i < j; j < length tr; tr ! j = (s, AEndAtomic); (LEAST j. i < j \\<and> j < length tr \\<and> tr ! j = (s, AEndAtomic)) \\<noteq> length tr\\<rbrakk> \\<Longrightarrow> (LEAST j. i < j \\<and> j < length tr \\<and> tr ! j = (s, AEndAtomic)) < length tr\"\n          by (smt less_trans neqE not_less_Least)\n        show \"\\<And>j. \\<lbrakk>i < j; j < length tr; tr ! j = (s, AEndAtomic); (LEAST j. i < j \\<and> j < length tr \\<and> tr ! j = (s, AEndAtomic)) \\<noteq> length tr\\<rbrakk> \\<Longrightarrow> tr ! (LEAST j. i < j \\<and> j < length tr \\<and> tr ! j = (s, AEndAtomic)) = (s, AEndAtomic)\"\n          by (smt LeastI)\n        show \"\\<And>j ja. \\<lbrakk>i < j; j < length tr; tr ! j = (s, AEndAtomic); i \\<le> ja; ja < (LEAST j. i < j \\<and> j < length tr \\<and> tr ! j = (s, AEndAtomic))\\<rbrakk> \\<Longrightarrow> get_invoc (tr ! ja) = s\"\n          by (smt a1 a2' dual_order.strict_trans fst_conv neqE not_le not_less_Least)\n        show \"\\<And>j. \\<lbrakk>\\<forall>j<length tr. i < j \\<longrightarrow> tr ! j \\<noteq> (s, AEndAtomic); i \\<le> j; j < length tr\\<rbrakk> \\<Longrightarrow> get_invoc (tr ! j) = s\"\n          by (metis a1 a2' dual_order.strict_trans fst_conv le_eq_less_or_eq)\n        show \"\\<And>j. \\<lbrakk>i < j; j < length tr; tr ! j = (s, AEndAtomic)\\<rbrakk> \\<Longrightarrow> i < (LEAST j. i < j \\<and> j < length tr \\<and> tr ! j = (s, AEndAtomic))\"\n          by (metis (mono_tags, lifting) LeastI_ex)\n        show \"\\<forall>j<length tr. i < j \\<longrightarrow> tr ! j \\<noteq> (s, AEndAtomic) \\<Longrightarrow> i < length tr\"\n          using a0 by blast  \n      qed\n    qed\n  qed  \nnext\n  show \"\\<forall>i<length tr. \\<forall>s ntxns. tr ! i \\<noteq> (s, ABeginAtomic tx ntxns) \\<Longrightarrow> transactionIsPacked tr tx\"\n    by (auto simp add: transactionIsPacked_def indexInOtherTransaction_def)\nnext\n  fix i s ntxns ia sa ntxns' ende\n  assume a0: \"i < length tr\"\n    and a1: \"tr ! i = (s, ABeginAtomic tx ntxns)\"\n    and a3: \"tr ! ia = (sa, ABeginAtomic tx ntxns')\"\n    and a7: \"ia < ende\"\n    and a4: \"\\<forall>j. ia \\<le> j \\<and> j < ende \\<longrightarrow> get_invoc (tr ! j) = sa\"\n    and a5: \"ende < length tr\"\n    and a6: \"tr ! ende = (sa, AEndAtomic)\"\n\n  have a2: \"ia < length tr\"\n    using a5 a7 less_trans by blast\n\n\n  with uniqueTxs have [simp]: \"ia = i\"\n    using a0 a1 a3 by blast\n\n  then have [simp]: \"sa = s\"\n    using a1 a3 by auto     \n\n  have a4': \"get_invoc (tr ! j) = s\" if \"i \\<le> j\" and \"j < ende\" for j\n    by (auto simp add: that a4)  \n\n\n  show \"transactionIsPacked tr tx\"\n  proof (auto simp add: transactionIsPacked_def indexInOtherTransaction_def)\n    fix k i' s' ntxns\n    assume b0: \"k < length tr\"\n      and b1: \"i' < k\"\n      and b2: \"tr ! i' = (s', ABeginAtomic tx ntxns)\"\n      and b3: \"\\<forall>j>i'. j < k \\<longrightarrow> tr ! j \\<noteq> (s', AEndAtomic)\"\n      and b4: \"get_invoc (tr ! k) \\<noteq> s'\"\n\n    have \" i' < length tr\"\n      using b0 b1 order.strict_trans by blast \n\n\n    then have [simp]: \"i' = i\"\n      using uniqueTxs b2 a1 a0 by blast \n\n    then have [simp]: \"s' = s\"\n      using a1 b2 by auto\n\n    have b3': \"\\<forall>j>i. j < k \\<longrightarrow> tr ! j \\<noteq> (s, AEndAtomic)\"\n      using b3 by simp      \n    have \"get_invoc (tr ! k) = s\"\n    proof (cases \"k < ende\")\n      case True\n      show ?thesis\n      proof (rule a4')\n        show \"i \\<le> k\"\n          using \\<open>i' = i\\<close> b1 dual_order.strict_implies_order by blast \n        show \"k < ende\" using True .\n      qed\n    next case False\n      then have \"k \\<ge> ende\" by simp\n      show ?thesis\n      proof (cases \"k = ende\")\n        case True\n        then show ?thesis\n          by (simp add: a6) \n      next\n        case False\n        then have \"k > ende\"\n          by (simp add: \\<open>ende \\<le> k\\<close> dual_order.strict_iff_order) \n        from b3' have \"ende>i \\<and> ende < k \\<longrightarrow> tr ! ende \\<noteq> (s, AEndAtomic)\"\n          by blast\n        with \\<open>k > ende\\<close> have \"tr ! ende \\<noteq> (s, AEndAtomic)\"\n          using \\<open>ia = i\\<close> a7 by blast\n\n        then show ?thesis\n          by (simp add: a6) \n      qed\n    qed \n    with b4 show False  by simp\n  qed\nqed\n\nlemma transactionIsPackedAlt_eq2:\n  assumes steps: \"initialState p ~~ tr \\<leadsto>* S\"\n  shows \"transactionIsPackedAlt tr tx = transactionIsPacked tr tx\"\n  by (auto simp add: transactionIdsUnique[OF steps] transactionIsPackedAlt_eq)\n\n\n\n\n\n\nlemma transactionIsPacked_show:\n  assumes steps: \"initialState p ~~ tr \\<leadsto>* S\"\n    and beginAtomic1: \"beginAtomic < endAtomic\"\n    and beginAtomic2: \"tr!beginAtomic = (s, ABeginAtomic tx ntxns)\"\n    and endAtomic1: \"endAtomic < length tr\"    \n    and endAtomic2: \"tr!endAtomic = (s, AEndAtomic)\"\n    and a1: \"\\<forall>i. beginAtomic \\<le> i \\<and> i \\<le> endAtomic \\<longrightarrow> get_invoc (tr ! i) = s\"\n  shows \"transactionIsPacked tr tx\"\nproof (auto simp add: transactionIsPacked_def indexInOtherTransaction_def)\n  fix k i s' ntxns\n  assume b0: \"k < length tr\"\n    and b1: \"i < k\"\n    and b2: \"tr ! i = (s', ABeginAtomic tx ntxns)\"\n    and b3: \"\\<forall>j>i. j < k \\<longrightarrow> tr ! j \\<noteq> (s', AEndAtomic)\"\n    and b4: \"get_invoc (tr ! k) \\<noteq> s'\"\n\n  from b2\n  have \"i = beginAtomic\"\n    using b0 b1 beginAtomic1 beginAtomic2 endAtomic1 transactionIdsUnique[OF steps] by auto\n  then have \"s' = s\"\n    using b2 beginAtomic2 by auto\n\n  from b3\n  have \"k \\<le> endAtomic\"\n    using \\<open>i = beginAtomic\\<close> \\<open>s' = s\\<close> beginAtomic1 endAtomic2 leI by blast\n\n  with b4 show False\n    using \\<open>i = beginAtomic\\<close> \\<open>k \\<le> endAtomic\\<close> a1 b1 b2 by auto\nqed    \n\n\n\n\\<comment> \\<open>the set of transactions occurring in the trace\\<close>    \ndefinition traceTransactions :: \"('proc, 'op, 'any) trace \\<Rightarrow> txId set\" where\n  \"traceTransactions tr \\<equiv> {tx | s tx txns. (s, ABeginAtomic tx txns) \\<in> set tr}\"\n\ntext \\<open>between begin and end of a transaction there are no actions from other sessions\\<close>\ndefinition transactionsArePacked :: \"('proc, 'op, 'any) trace \\<Rightarrow> bool\" where\n  \"transactionsArePacked tr \\<equiv>\n  \\<forall>i k s t txns. \n      i<k \n    \\<and> k<length tr \n    \\<and> tr!i = (s, ABeginAtomic t txns)  \n    \\<and> get_invoc (tr!k) \\<noteq> s\n    \\<longrightarrow>  (\\<exists>j. i < j \\<and> j < k \\<and> tr!j = (s, AEndAtomic))\"\n\ntext \\<open>\nFor termination proofs, we want to measure how far a trace is from being packed.\nFor this we take the sum over all actions in the trace and count in how many transactions\nit appears.\n\\<close>\n\n\n\\<comment> \\<open>checks if sessions s is in a transaction at position i in trace tr\\<close>\ndefinition inTransaction :: \"('proc, 'op, 'any) trace \\<Rightarrow> nat \\<Rightarrow> invocId \\<Rightarrow> bool\"  where \n  \"inTransaction tr i s \\<equiv>\n  \\<exists>j. j\\<le>i \\<and> i<length tr \\<and> (\\<exists>t txns. tr!j = (s, ABeginAtomic t txns))\n     \\<and> (\\<forall>k. j<k \\<and> k < length tr \\<and> k\\<le>i \\<longrightarrow> tr!k \\<noteq> (s, AEndAtomic))\n\"\n\n\\<comment> \\<open>returns the set of all transactions, which are in a transaction at point i in the trace\\<close>\ndefinition sessionsInTransaction :: \"('proc, 'op, 'any) trace \\<Rightarrow> nat \\<Rightarrow> invocId set\"  where \n  \"sessionsInTransaction tr i \\<equiv> {s. inTransaction tr i s}\"\n\n\n\n\n\n\nlemma sessionsInTransaction_h1: \" sessionsInTransaction [(s\\<^sub>1, ABeginAtomic t\\<^sub>1 txns), (s\\<^sub>1, AEndAtomic)] 3 = {}\" \n  by (auto simp add: sessionsInTransaction_def  inTransaction_def nth_Cons' split: if_splits)\n\n\nlemma sessionsInTransaction_h2: \" sessionsInTransaction [(s1, ABeginAtomic t\\<^sub>1 txns)] 0= {s1}\" \n  by (auto simp add: sessionsInTransaction_def inTransaction_def nth_Cons' split: if_splits)\n\nlemma sessionsInTransaction_h3: \" sessionsInTransaction [(s\\<^sub>1, ABeginAtomic t\\<^sub>1 txns), (s\\<^sub>1, AEndAtomic)] 1 = {}\" \n  by (auto simp add: sessionsInTransaction_def inTransaction_def nth_Cons' split: if_splits )\n\n\n\nlemma sessionsInTransaction_append:\n  \"i<length xs \\<Longrightarrow> sessionsInTransaction (xs@ys) i = sessionsInTransaction xs i\"\n  by (auto simp add: nth_append sessionsInTransaction_def inTransaction_def)\n\n\n\nlemma not_packed_example:\n  assumes notPacked: \"\\<not>transactionsArePacked tr\"\n  shows \"\\<exists>i k s t ts a s'. \n      tr ! k = (s', a)\n    \\<and> i<k \n    \\<and> k<length tr \n    \\<and> tr!i = (s, ABeginAtomic t ts)  \n    \\<and> s' \\<noteq> s\n    \\<and>  (\\<forall>j. i < j \\<and> j < k \\<longrightarrow> tr!j \\<noteq> (s, AEndAtomic))\"\n  using assms by (auto simp add: transactionsArePacked_def, metis prod.collapse)\n\n\n\n\n\nlemma show_traceCorrect_same:\n  assumes sameTraceContent: \"set tr = set tr'\"\n  shows \"traceCorrect tr' = traceCorrect tr\"\n  using assms by (auto simp add: traceCorrect_def)\n\n\n\ndefinition allowed_context_switch where \n  \"allowed_context_switch action \\<equiv> \n            (\\<exists>txId txns. action = ABeginAtomic txId txns) \n          \\<or> (\\<exists>p. action = AInvoc p)\"\n\nlemma allowed_context_switch_cases[consumes 1, elim, case_names invoc beginAtomic]:\n  assumes \"allowed_context_switch action\"\n    and \"\\<And>p. action = AInvoc p \\<Longrightarrow> P\"\n    and \"\\<And>txId txns. action = ABeginAtomic txId txns \\<Longrightarrow> P\"\n  shows P\n  using allowed_context_switch_def assms by blast\n\n\n\nlemma allowed_context_switch_simps:\n  shows \"\\<not>allowed_context_switch (ALocal ok)\" \n    and \"\\<not>allowed_context_switch (ANewId uid)\"\n    and \"allowed_context_switch (ABeginAtomic t ats)\"\n    and \"\\<not>allowed_context_switch AEndAtomic\" \n    and \"\\<not>allowed_context_switch (ADbOp c x ar)\" \n    and \"allowed_context_switch (AInvoc p)\"\n    and \"\\<not>allowed_context_switch (AReturn ir)\" \n    and \"\\<not>allowed_context_switch ACrash\" \n    and \"\\<not>allowed_context_switch (AInvcheck invr)\" by (auto simp add: allowed_context_switch_def)\n\n\n\n\nlemma canSwap_when_allowed:\n  assumes no_ctxt_switch: \"\\<not>allowed_context_switch b\"\n    and no_invcheck_a: \"\\<not>is_AInvcheck a\"\n    and no_invcheck_b: \"\\<not>is_AInvcheck b\"  \n    and no_fail_a: \"a \\<noteq> ACrash\"\n    and no_fail_b: \"b \\<noteq> ACrash\"    \n  shows \"canSwap t a b\"\n  by (metis allowed_context_switch_def canSwap_cases no_ctxt_switch no_fail_a no_fail_b no_invcheck_a no_invcheck_b)\n\n\n\n\ndefinition packed_trace :: \"('proc, 'op, 'any) trace \\<Rightarrow> bool\" where\n  \"packed_trace tr \\<equiv>\n  \\<forall>i.\n      0<i\n    \\<longrightarrow> i<length tr\n    \\<longrightarrow> get_invoc (tr!(i-1)) \\<noteq> get_invoc (tr!i)\n    \\<longrightarrow> (allowed_context_switch (get_action (tr!i)))\" \n\n\ntext \\<open>\\DefineSnippet{packed_trace_def}{\n  @{thm [display] packed_trace_def[unfolded imp_conjL[symmetric]]}\n}%EndSnippet\\<close>\n\n\ntext \\<open>\\DefineSnippet{allowed_context_switch_def}{\n  @{thm [display] allowed_context_switch_def}\n}%EndSnippet\\<close>\n\nlemmas use_packed_trace = iffD1[OF packed_trace_def[THEN meta_eq_to_obj_eq], rule_format]\n\n\n\nlemma prefixes_are_packed:\n  assumes \"packed_trace tr'\" \n    and \"isPrefix tr tr'\"\n  shows \"packed_trace tr\"\n  using \\<open>packed_trace tr'\\<close> by (auto simp add: packed_trace_def,\n      metis (no_types, lifting) Suc_leI assms(2) diff_less_Suc isPrefix_len isPrefix_same less_le_trans)\n\n\n\nlemma context_switches_in_packed: \n  assumes packed: \"packed_trace tr\"\n    and split_tr: \"tr = tr1@[(s,a),(s',a')]@tr2\"\n    and differentSession: \"s \\<noteq> s'\"\n  shows \"allowed_context_switch a'\"\nproof -\n  have \"a' = get_action(tr!(1+length tr1))\"\n    using split_tr by (auto simp add: nth_append)\n\n  moreover\n  have \"allowed_context_switch (get_action(tr!(1+length tr1)))\"\n    using packed proof (rule use_packed_trace)\n    show \"0 < 1 + length tr1\" by simp\n    show \"1 + length tr1 < length tr\" using split_tr by auto\n    show \"get_invoc (tr ! (1 + length tr1 - 1)) \\<noteq> get_invoc (tr ! (1 + length tr1))\" using split_tr \\<open>s \\<noteq> s'\\<close> by (auto simp add: nth_append)\n  qed\n  ultimately\n  show ?thesis by simp\nqed  \n\n\n\ndefinition packed_trace_i :: \"('proc, 'op, 'any) trace \\<Rightarrow> invocId \\<Rightarrow> bool\" where\n  \"packed_trace_i tr i \\<equiv>\n  \\<forall>k.\n      0<k\n    \\<longrightarrow> k<length tr\n    \\<longrightarrow> get_invoc (tr!k) = i\n    \\<longrightarrow> get_invoc (tr!(k-1)) \\<noteq> i\n    \\<longrightarrow> (allowed_context_switch (get_action (tr!k)))\" \n\ntext_raw \\<open>\\DefineSnippet{pack_trace_for_one_session}{\\<close>\nlemma pack_trace_for_one_session:\n  assumes steps: \"initialState program ~~ tr1 \\<leadsto>* C\"\n    and noFail: \"\\<And>s. (s, ACrash) \\<notin> set tr1\" (is \"\\<And>s. _ \\<notin> set ?tr\")\n    and noInvcheck: \"\\<And>s a. (s, a)\\<in>set tr1 \\<Longrightarrow> \\<not>is_AInvcheck a \"\n  shows \"\\<exists>tr'. packed_trace_i tr' s\n        \\<and> (initialState program ~~ tr' \\<leadsto>* C)\n        \\<and> (\\<forall>s. packed_trace_i tr1 s \\<longrightarrow> packed_trace_i tr' s)\n        \\<and> (set tr' = set tr1)\"\ntext_raw \\<open>}%EndSnippet\\<close>\n  text \\<open>By induction over the minimal index that is not packed.\\<close>\nproof -\n\n  have \"\\<exists>tr'. \n      (\\<forall>i<length tr1. \\<not>(0 < i  \n                      \\<and>  get_invoc (tr'!(i-1)) \\<noteq> s \n                      \\<and> get_invoc (tr'!i) = s \n                      \\<and> \\<not>(allowed_context_switch (get_action(tr'!i))) )  )\n        \\<and> (initialState program ~~ tr' \\<leadsto>* C)\n        \\<and> (length tr' = length tr1)\n        \\<and> (\\<forall>s. packed_trace_i tr1 s \\<longrightarrow> packed_trace_i tr' s)\n        \\<and> (set tr' = set tr1)\" (is \"\\<exists>tr'. ?P tr'\")\n  proof (rule fix_smallest_induct, auto simp add: assms disj_imp rewrite_and_implies, rename_tac tr i)\n\n    show \"\\<exists>tr'. \n      (\\<forall>j\\<le>i. 0 < j \n          \\<longrightarrow> get_invoc (tr' ! (j - Suc 0)) \\<noteq> get_invoc (tr ! i) \n          \\<longrightarrow> get_invoc (tr' ! j) = get_invoc (tr ! i) \n          \\<longrightarrow> allowed_context_switch (get_action (tr' ! j))) \n      \\<and> initialState program ~~ tr' \\<leadsto>* C \n      \\<and> length tr' = length tr1 \n      \\<and> (\\<forall>s. packed_trace_i tr1 s \\<longrightarrow> packed_trace_i tr' s) \n      \\<and> set tr' = set tr1\"\n      if c0: \"\\<And>j. j < i \\<Longrightarrow> 0 < j \\<longrightarrow> get_invoc (tr ! (j - Suc 0)) \\<noteq> get_invoc (tr ! i) \\<longrightarrow> get_invoc (tr ! j) = get_invoc (tr ! i) \\<longrightarrow> allowed_context_switch (get_action (tr ! j))\"\n        and c1: \"i < length tr1\"\n        and c2: \"initialState program ~~ tr \\<leadsto>* C\"\n        and i1[simp]: \"0 < i\"\n        and c4: \"length tr = length tr1\"\n        and c5: \"get_invoc (tr ! (i - Suc 0)) \\<noteq> get_invoc (tr ! i)\"\n        and c6: \"\\<forall>s. packed_trace_i tr1 s \\<longrightarrow> packed_trace_i tr s\"\n        and same_tr: \"set tr = set tr1\"\n        and i5: \"\\<not> allowed_context_switch (get_action (tr ! i))\"\n        and c8: \"s = get_invoc (tr ! i)\"\n      for  tr i\n    proof -\n\n      have i2: \"i<length tr\"\n        by (simp add: c1 c4)\n\n\n      have i4: \"get_invoc (tr!i) = s\"\n        by (simp add: c8)\n\n\n      text \\<open>There must be a previous action on the same invocId (at least the invocId should be there, since i is no invocId).\\<close>\n      obtain prev\n        where prev1: \"get_invoc(tr!prev) = s\"\n          and prev2: \"prev < i\"\n          and prev3: \"\\<And>j. \\<lbrakk>prev < j; j < i\\<rbrakk> \\<Longrightarrow> get_invoc(tr!j) \\<noteq> s\"\n      proof (atomize_elim)\n        from \\<open>initialState program ~~ tr \\<leadsto>* C\\<close> \\<open>i<length tr\\<close> \\<open>get_invoc (tr!i) = s\\<close>\n        have \"\\<exists>j<i. get_invoc (tr ! j) = s \\<and> (\\<exists>p. get_action (tr ! j) = AInvoc p)\"\n        proof (rule exists_invoc)\n          show \"\\<And>p. get_action (tr ! i) \\<noteq> AInvoc p\"\n            using allowed_context_switch_def[where action=\"get_action (tr ! i)\"] i5 by blast\n          show \"\\<not> is_AInvcheck (get_action (tr ! i))\"\n            by (metis i2 noInvcheck nth_mem prod.collapse same_tr)\n        qed\n        then have \"\\<exists>j<i. get_invoc (tr ! j) = s\"\n          by auto\n        then have \"\\<exists>j. (j<i \\<and> get_invoc (tr ! j) = s) \\<and> (\\<forall>j'. j'<i \\<and> get_invoc (tr ! j') = s \\<longrightarrow> j'\\<le>j)\"\n        proof (rule exists_greatest')\n          show \"\\<exists>bound. \\<forall>j. j < i \\<and> get_invoc (tr ! j) = s \\<longrightarrow> j \\<le> bound\"\n            using less_or_eq_imp_le by blast\n        qed\n        from this obtain j where \"(j<i \\<and> get_invoc (tr ! j) = s) \\<and> (\\<forall>j'. j'<i \\<and> get_invoc (tr ! j') = s \\<longrightarrow> j'\\<le>j)\"\n          by blast\n        then have \"get_invoc (tr ! j) = s \\<and> j < i \\<and> (\\<forall>j'>j. j' < i \\<longrightarrow> get_invoc (tr ! j') \\<noteq> s)\"\n          by auto\n\n        then show \"\\<exists>prev. get_invoc (tr ! prev) = s \\<and> prev < i \\<and> (\\<forall>j>prev. j < i \\<longrightarrow> get_invoc (tr ! j) \\<noteq> s)\"  ..\n      qed\n\n      have [simp]: \"prev < length tr\"\n        using i2 order.strict_trans prev2 by blast\n      have [simp]: \"min (length tr) prev = prev\"\n        using i2 prev2 by linarith  \n      have [simp]: \"min (length tr) i = i\"\n        using i2  by linarith    \n\n      text \\<open>Then we can split the trace, so that we have (one action from s) -- (many other actions) -- (action i form s)\\<close>\n      have tr_split: \"tr = take prev tr @ [tr!prev] @ drop (Suc prev) (take i tr) @ [tr!i] @ drop (Suc i) tr\"\n      proof (rule nth_equalityI)\n        show \"length tr = length (take prev tr @ [tr ! prev] @ drop (Suc prev) (take i tr) @ [tr ! i] @ drop (Suc i) tr)\"\n          using i2 prev2 by auto\n        show \"tr ! ia = (take prev tr @ [tr ! prev] @ drop (Suc prev) (take i tr) @ [tr ! i] @ drop (Suc i) tr) ! ia\" if \"ia<length tr\"for ia\n          using that by (auto simp add: nth_append nth_Cons'  Suc_leI less_diff_conv prev2)\n\n      qed    \n\n\n      text \\<open>Because of the swap lemma we can change this to (one action from s) -- (action i form s) -- (many other actions)\\<close>\n      define tr' where \"tr' = take prev tr @ [tr!prev, tr!i] @ drop (Suc prev) (take i tr)  @ drop (Suc i) tr\"\n\n      have tr'sameLength: \"length tr' = length tr\"\n        using i2 prev2  by (auto simp add: tr'_def)\n\n\n      have tr'_sameSet: \"set tr' = set tr\" \n        by (subst tr_split, subst  tr'_def, auto)\n\n\n      have tr'1: \"tr'!x = tr!x\" if \"x \\<le> prev\" for x\n        using that by (auto simp add: tr'_def nth_append)\n      moreover have tr'2: \"tr'!x = tr!i\" if \"x=Suc prev\" for x\n        using that by (auto simp add: tr'_def nth_append)\n      moreover have tr'3: \"tr'!x = tr!(x-1)\" if \"x>Suc prev\"  and \"x<i\" for x\n        using that by (auto simp add: tr'_def nth_append nth_Cons',\n            metis Suc_diff_Suc diff_Suc_less dual_order.strict_trans less_2_cases not_less_eq numeral_2_eq_2)\n      moreover have tr'4: \"tr'!x = tr!(x-1)\" if  \"x = i\" for x\n        using that prev2 antisym  prev1 c5 c8  by (auto simp add: tr'_def nth_append nth_Cons' Suc_diff_Suc numeral_2_eq_2, fastforce)\n      moreover have tr'5: \"tr'!x = tr!x\" if \"x > i\" and \"x < length tr\" for x\n        using that prev2 by (auto simp add: tr'_def nth_append nth_Cons')\n      ultimately have tr'i_def: \"tr'!x = (if x\\<le>prev then tr!x else if x=Suc prev then tr!i else if x\\<le>i then tr!(x-1) else tr!x)\" if \"x<length tr\" for x\n        by (metis antisym_conv2 not_le not_less_eq_eq that)  \n\n\n      have \"initialState program ~~ (take prev tr @ [tr!prev]) @ [tr!i] @ drop (Suc prev) (take i tr)  @ drop (Suc i) tr \\<leadsto>* C\"\n      proof (rule swapMany_middle')\n        show \"initialState program ~~ (take prev tr @ [tr ! prev]) @ drop (Suc prev) (take i tr) @ [tr ! i] @ drop (Suc i) tr \\<leadsto>* C\"\n          using tr_split c2 by auto \n\n        show \"\\<And>x. x \\<in> set (drop (Suc prev) (take i tr)) \\<Longrightarrow> get_invoc x \\<noteq> get_invoc (tr ! i)\"\n          using prev3 by (auto simp add: in_set_conv_nth,\n              metis add.commute add_Suc_right fst_conv i4 less_add_Suc1 less_diff_conv) \n\n        from i5\n        show \"canSwap t (get_action x) (get_action (tr ! i))\" if \"x \\<in> set (drop (Suc prev) (take i tr))\" for x t\n        proof (rule canSwap_when_allowed)\n          from that obtain k \n            where k1: \"x = tr!k\" \n              and k2: \"k<i\" \n              and k3: \"k>prev\"\n            by (auto simp add: in_set_conv_nth)\n\n          then have k4: \"x\\<in>set tr\"\n            using dual_order.strict_trans i2 nth_mem by blast\n\n\n          show \"\\<not> is_AInvcheck (get_action x)\"\n            by (metis k4 noInvcheck prod.collapse same_tr)\n          show \"\\<not> is_AInvcheck (get_action (tr ! i))\"\n            by (metis i2 noInvcheck nth_mem prod.collapse same_tr)\n          show \"get_action x \\<noteq> ACrash\"\n            by (metis k4 noFail prod.collapse same_tr)\n          show \"get_action (tr ! i) \\<noteq> ACrash\"\n            by (metis c1 c4 noFail nth_mem same_tr surjective_pairing)\n        qed  \n\n        show \"state_wellFormed (initialState program)\"\n          by (simp add: state_wellFormed_init)\n\n        from noFail\n        show \"\\<And>i. (i, ACrash) \\<notin> set (take prev tr @ [tr ! prev])\"\n          by (metis Un_iff same_tr set_append tr_split)\n        from noFail\n        show \"\\<And>ia. (ia, ACrash) \\<notin> set (drop (Suc prev) (take i tr))\"\n          using in_set_dropD in_set_takeD same_tr by fastforce\n      qed    \n\n\n      then have \"initialState program ~~ tr' \\<leadsto>* C\"\n        by (simp add: tr'_def)\n\n      have tr'packed: \"packed_trace_i tr' s\" if \"packed_trace_i tr s\" for s\n        using that Suc_leI prev2 \n        by (auto simp add: packed_trace_i_def tr'i_def tr'sameLength i4 prev1,\n            metis Suc_pred c8 diff_le_self le_less_Suc_eq le_zero_eq not_le_imp_less,\n            metis Suc_pred c5 i2 i5 le_less_Suc_eq not_le_imp_less not_less0 not_less_iff_gr_or_eq)\n\n      show \"\\<exists>tr'. (\\<forall>j\\<le>i. 0 < j \\<longrightarrow>\n                  get_invoc (tr' ! (j - Suc 0)) \\<noteq> get_invoc (tr ! i) \\<longrightarrow>\n                  get_invoc (tr' ! j) = get_invoc (tr ! i) \\<longrightarrow> allowed_context_switch (get_action (tr' ! j))) \\<and>\n          (initialState program ~~ tr' \\<leadsto>* C) \\<and>\n          length tr' = length tr1 \\<and> (\\<forall>s. packed_trace_i tr1 s \\<longrightarrow> packed_trace_i tr' s) \\<and> set tr' = set tr1\"\n      proof (rule exI[where x=tr'], intro conjI impI allI)\n\n        show \"initialState program ~~ tr' \\<leadsto>* C\"\n          by (simp add: \\<open>initialState program ~~ tr' \\<leadsto>* C\\<close>)\n        show \"length tr' = length tr1\"\n          using c4 tr'sameLength by auto\n\n        show \"\\<And>s. packed_trace_i tr1 s \\<Longrightarrow> packed_trace_i tr' s\"\n          using c6 tr'packed by blast\n\n        show \"allowed_context_switch (get_action (tr' ! j))\"\n          if d0: \"j \\<le> i\"\n            and d1: \"0 < j\"\n            and d2: \"get_invoc (tr' ! (j - Suc 0)) \\<noteq> get_invoc (tr ! i)\"\n            and d3: \"get_invoc (tr' ! j) = get_invoc (tr ! i)\"\n          for  j\n        proof (cases \"j = i\")\n          case True\n          then show ?thesis\n            using c5 d3 tr'4  by (auto simp add: tr'_def nth_append nth_Cons' split: if_splits)\n        next\n          case False\n          hence \"j < i\"\n            using antisym_conv2 d0 by blast\n          hence \"allowed_context_switch (get_action (tr ! j))\"\n            by (smt Suc_pred c0 c1 c4 c8 d0 d1 d2 d3 diff_Suc_1 leD less_trans not_le_imp_less not_less_eq prev1 prev3 tr'i_def)\n\n          thus \"allowed_context_switch (get_action (tr' ! j))\"\n            using \\<open>j < i\\<close> c1 c4 c8 d2 d3 less_trans prev1 prev3 tr'i_def by auto\n        qed\n\n        show \" set tr' = set tr1\"\n          by (simp add: same_tr tr'_sameSet)\n      qed\n    qed\n  qed\n\n  thus ?thesis\n    by (metis packed_trace_i_def)\n\nqed\n\n\nlemma packed_trace_iff_all_sessions_packed:\n  \"packed_trace tr \\<longleftrightarrow> (\\<forall>i. packed_trace_i tr i)\"\n  by (auto simp add: packed_trace_def packed_trace_i_def)\n\ntext \\<open>\\DefineSnippet{packed_trace_i_def}{\n  @{thm [display] packed_trace_i_def[unfolded imp_conjL[symmetric]]}\n}%EndSnippet\\<close>\n\ntext \\<open>\\DefineSnippet{packed_trace_iff_all_sessions_packed}{\n  @{thm [display] packed_trace_iff_all_sessions_packed}\n}%EndSnippet\\<close>\n\n\ntext \\<open>Now we can just repeat fixing invocId by invocId, until all sessions are packed.\\<close>\nlemma pack_trace:\n  assumes steps: \"initialState program ~~ tr \\<leadsto>* C\"\n    and noFail: \"\\<And>s. (s, ACrash) \\<notin> set tr\"\n    and noInvcheck: \"\\<And>s a. (s, a)\\<in>set tr \\<Longrightarrow> \\<not>is_AInvcheck a \"\n  shows \"\\<exists>tr'. packed_trace tr'\n        \\<and> (initialState program ~~ tr' \\<leadsto>* C)\n        \\<and> (set tr' = set tr)\"\nproof -\n  have \"{s. \\<not>packed_trace_i tr s } \\<subseteq> set (map get_invoc tr)\"\n    by (auto simp add: packed_trace_i_def)\n\n  then have \"finite {s. \\<not>packed_trace_i tr s }\"\n    using infinite_super by blast\n\n  from this and assms\n  show ?thesis\n  proof (induct \"{s. \\<not>packed_trace_i tr s }\" arbitrary: tr rule: finite_psubset_induct)\n    case psubset\n\n    show ?case \n    proof (cases \"{s. \\<not>packed_trace_i tr s } = {}\")\n      case True\n      then have \"packed_trace tr\"\n        by (auto simp add: packed_trace_iff_all_sessions_packed)\n      then show ?thesis\n        using psubset.prems by blast \n    next\n      case False\n      from this obtain s where \"\\<not> packed_trace_i tr s\"\n        by blast\n\n\n      from \\<open>initialState program ~~ tr \\<leadsto>* C\\<close> \\<open>\\<And>s. (s, ACrash) \\<notin> set tr\\<close> \\<open>\\<And>s a. (s, a) \\<in> set tr \\<Longrightarrow> \\<not> is_AInvcheck a\\<close>\n      have \"\\<exists>tr'. packed_trace_i tr' s \n          \\<and> (initialState program ~~ tr' \\<leadsto>* C) \n          \\<and> (\\<forall>s. packed_trace_i tr s \\<longrightarrow> packed_trace_i tr' s) \n          \\<and> (set tr' = set tr)\"  \n        by (rule pack_trace_for_one_session; force)\n\n      from this\n      obtain tr' \n        where tr'1: \"packed_trace_i tr' s\"\n          and tr'2: \"initialState program ~~ tr' \\<leadsto>* C\"\n          and tr'3: \"\\<forall>s. packed_trace_i tr s \\<longrightarrow> packed_trace_i tr' s\"\n          and tr'4: \"set tr' = set tr\"\n        by blast\n\n      from tr'1 tr'3 \\<open>\\<not> packed_trace_i tr s\\<close>\n      have subset: \"{s. \\<not>packed_trace_i tr' s } \\<subset> {s. \\<not>packed_trace_i tr s }\"\n        by auto\n\n      from subset tr'2\n      have \" \\<exists>tr''. packed_trace tr'' \\<and> (initialState program ~~ tr'' \\<leadsto>* C) \\<and> set tr'' = set tr'\"\n      proof (rule psubset.hyps(2))\n        show \"\\<And>s. (s, ACrash) \\<notin> set tr'\"\n          by (simp add: psubset.prems(2) tr'4)\n        show \"\\<And>s a. (s, a) \\<in> set tr' \\<Longrightarrow> \\<not> is_AInvcheck a\"\n          using psubset.prems(3) tr'4 by blast\n      qed\n\n      thus ?thesis\n        by (simp add: tr'4)\n    qed\n  qed\nqed\n\nlemma remove_invchecks:\n  assumes \"(S ~~ tr \\<leadsto>* S') \"\n  shows \"(S ~~ filter (\\<lambda>a. \\<not>is_AInvcheck (get_action a)) tr \\<leadsto>* S')\"\n  using assms proof (induct rule: steps_induct)\n  case initial\n  then show ?case \n    by (simp add: steps_refl)\nnext\n  case (step S' tr a S'')\n  then show ?case \n    by( auto simp add: is_AInvcheck_def step.simps steps_step steps_empty)\nqed\n\n\n\ntext_raw \\<open>\\DefineSnippet{pack_incorrect_trace}{\\<close>\nlemma pack_incorrect_trace:\n  assumes steps: \"initialState program ~~ tr \\<leadsto>* C\"\n    and noFail: \"\\<And>s. (s, ACrash) \\<notin> set tr\"\n    and notCorrect: \"\\<not>traceCorrect tr\"\n  shows \"\\<exists>tr' C'. packed_trace tr' \n        \\<and> (initialState program ~~ tr' \\<leadsto>* C')\n        \\<and> (\\<forall>s. (s, ACrash) \\<notin> set tr')\n        \\<and> \\<not>traceCorrect tr'\"\ntext_raw \\<open>}%EndSnippet\\<close>\nproof -\n  text \\<open>As the trace is not correct, there must be a failing invariant:\\<close> \n\n  show ?thesis\n  proof (cases \"\\<exists>failPos1 < length tr. \\<exists>s. tr ! failPos1 = (s, AInvcheck False)\")\n    case True\n\n    from this\n    obtain failPos1 \n      where failPos1_props: \"failPos1 < length tr \\<and> (\\<exists>s. tr ! failPos1 = (s, AInvcheck False))\"\n      by blast\n\n    text \\<open>Now take the minimal failing position.\\<close>  \n    then have \"\\<exists>failPos1. (failPos1 < length tr \\<and> (\\<exists>s. tr ! failPos1 = (s, AInvcheck False)))\n           \\<and> (\\<forall>i. (i < length tr \\<and> (\\<exists>s. tr ! i = (s, AInvcheck False))) \\<longrightarrow> i \\<ge> failPos1)\"\n      by (rule ex_has_least_nat)\n    from this\n    obtain failPos failPos_s \n      where failPos_len: \"failPos < length tr\" \n        and failPos_fail: \"tr ! failPos = (failPos_s, AInvcheck False)\"\n        and failPos_min: \"\\<And> i. \\<lbrakk>i < length tr; \\<exists>s txns. tr ! i = (s, AInvcheck False)\\<rbrakk> \\<Longrightarrow> i\\<ge>failPos\"\n      by auto\n\n\n\n    text \\<open>Only the part leading to the invariant violation is relevant ...\\<close>  \n\n    define tr' where \"tr' = take failPos tr\"\n\n    from steps\n    obtain C' where tr'_steps: \"initialState program ~~ tr' \\<leadsto>* C'\"\n      by (metis append_take_drop_id steps_append tr'_def)\n\n    from steps\n    have \"initialState program ~~ (tr'@[tr!failPos]@drop (Suc failPos) tr) \\<leadsto>* C\"\n      by (metis \\<open>failPos < length tr\\<close> append.assoc append_take_drop_id take_Suc_conv_app_nth tr'_def)\n    then have \"\\<exists>C''. C' ~~ tr ! failPos  \\<leadsto>  C''\"\n      using  tr'_steps by (auto simp add: steps_append2 steps_appendFront)\n\n    then have C'_fails: \"\\<And>s. C' ~~ (s, AInvcheck False) \\<leadsto> C'\"  \n      by (auto simp add: failPos_fail step_simps)\n\n\n    text \\<open>Now remove all other invariant checks\\<close>\n    define tr'' where \"tr'' = filter (\\<lambda>a. \\<not>is_AInvcheck (get_action a)) tr'\"\n\n    from tr'_steps\n    have tr''_steps:  \"initialState program ~~ tr'' \\<leadsto>* C'\"\n      using remove_invchecks tr''_def by blast\n\n\n    have no_crash'': \"\\<And>s. (s, ACrash) \\<notin> set tr''\"\n      using noFail by (auto simp add: tr'_def tr''_def dest: in_set_takeD)\n    have no_invcheck'': \"\\<And>s a. (s, a) \\<in> set tr'' \\<Longrightarrow> \\<not> is_AInvcheck a\"\n      by (auto simp add: tr''_def)\n\n    from tr''_steps no_crash'' no_invcheck''\n    have \"\\<exists>tr'''. packed_trace tr''' \\<and> (initialState program ~~ tr''' \\<leadsto>* C') \\<and> (set tr''' = set tr'')\"\n      by (rule pack_trace)\n\n    from this\n    obtain tr'''\n      where tr'''1: \"packed_trace tr'''\"\n        and tr'''2: \"initialState program ~~ tr''' \\<leadsto>* C'\"\n        and tr'''3: \"set tr''' = set tr''\"\n      by blast\n\n    define tr4 where \"tr4 = tr''' @ [(get_invoc (last tr'''), AInvcheck False)]\"\n\n    from \\<open>packed_trace tr'''\\<close>\n    have \"packed_trace tr4\"\n      by (auto simp add: packed_trace_def tr4_def nth_append,\n          metis One_nat_def gr_implies_not_zero last_conv_nth length_0_conv less_SucE)\n\n\n    moreover have \"initialState program ~~ tr4 \\<leadsto>* C'\"\n      using C'_fails steps_append2 steps_single tr'''2 tr4_def by blast\n    moreover have \"\\<forall>s. (s, ACrash) \\<notin> set tr4\"\n      by (simp add: no_crash'' tr'''3 tr4_def)\n    moreover have \"\\<not> traceCorrect tr4\"\n      by (simp add: actionCorrect_def tr4_def traceCorrect_def)\n\n    ultimately show ?thesis by blast\n  next \n    case False\n    hence \"(i, AInvcheck False) \\<notin> set tr\" for i\n      by (meson in_set_conv_nth)\n    hence assertionError: \"\\<exists>i. (i, ALocal False) \\<in> set tr\"\n      using notCorrect by (auto simp add: traceCorrect_def actionCorrect_def)\n\n\n\n    text \\<open>Remove all invariant checks\\<close>\n    define tr' where \"tr' = filter (\\<lambda>a. \\<not>is_AInvcheck (get_action a)) tr\"\n\n    from steps\n    have tr'_steps:  \"initialState program ~~ tr' \\<leadsto>* C\"\n      using remove_invchecks tr'_def by blast\n\n\n    have noFail': \"\\<And>s. (s, ACrash) \\<notin> set tr'\"\n      by (simp add: noFail tr'_def)\n\n\n    have \"\\<exists>tr''. packed_trace tr'' \n    \\<and> (initialState program ~~ tr'' \\<leadsto>* C) \n    \\<and> (set tr'' = set tr')\"\n    proof (rule pack_trace[OF tr'_steps noFail'])\n      show \"\\<And>s a. (s, a) \\<in> set tr' \\<Longrightarrow> \\<not> is_AInvcheck a\"\n        by (simp add: tr'_def)\n    qed\n\n    from this obtain tr''\n      where \"packed_trace tr'' \"\n        and \"initialState program ~~ tr'' \\<leadsto>* C\"\n        and \"set tr'' = set tr'\"\n      by blast\n\n    show ?thesis\n    proof (intro exI[where x=tr''] exI[where x=C] conjI)\n      show \" packed_trace tr''\"\n        by (simp add: \\<open>packed_trace tr''\\<close>)\n\n      show \" initialState program ~~ tr'' \\<leadsto>* C\"\n        by (simp add: \\<open>initialState program ~~ tr'' \\<leadsto>* C\\<close>)\n\n      show \" \\<forall>s. (s, ACrash) \\<notin> set tr''\"\n        by (simp add: \\<open>set tr'' = set tr'\\<close> noFail')\n\n      from assertionError\n      show \" \\<not> traceCorrect tr''\"\n        using  `set tr'' = set tr'` is_AInvcheck_def\n        by (auto simp add: tr'_def traceCorrect_def actionCorrect_def)\n    qed    \n  qed\nqed\n\n\n\n\n\nend\n", "meta": {"author": "peterzeller", "repo": "repliss-isabelle", "sha": "f43744678cc9c5a4684e8bd0e9c83510bae1d9a4", "save_path": "github-repos/isabelle/peterzeller-repliss-isabelle", "path": "github-repos/isabelle/peterzeller-repliss-isabelle/repliss-isabelle-f43744678cc9c5a4684e8bd0e9c83510bae1d9a4/packed_traces.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5078118642792046, "lm_q2_score": 0.5774953651858118, "lm_q1q2_score": 0.29325899800760713}}
{"text": "theory Safety_Certification_Pure\n  imports\n    Safety_Certification\n    \\<comment> \\<open>We generalize the material from this theory to federation subsumption:\\<close>\n    Certification.Unreachability_Certification2 \\<comment> \\<open>XXX: These should be merged.\\<close>\nbegin\n\nlocale Reachability_Impl_pure_base =\n  Reachability_Impl_base where less_eq = less_eq\n  for less_eq :: \"'a \\<Rightarrow> 'a set \\<Rightarrow> bool\" (infix \"\\<preceq>\" 50) +\n  fixes get_succs and K and A and L and Li and lei\n    and Li_split :: \"'ki list list\"\n  assumes K_right_unique: \"single_valued K\"\n  assumes K_left_unique:  \"single_valued (K\\<inverse>)\"\n  assumes Li_L: \"(Li, L) \\<in> \\<langle>K\\<rangle>list_set_rel\"\n  assumes lei_less_eq: \"(lei, less_eq) \\<in> A \\<rightarrow> \\<langle>A\\<rangle>list_set_rel \\<rightarrow> bool_rel\"\n  assumes get_succs_succs[param]:\n    \"(get_succs, succs) \\<in> K \\<rightarrow> \\<langle>A\\<rangle>list_set_rel \\<rightarrow> \\<langle>K \\<times>\\<^sub>r \\<langle>A\\<rangle>list_set_rel\\<rangle>list_rel\"\n  assumes full_split: \"set Li = (\\<Union>xs \\<in> set Li_split. set xs)\"\nbegin\n\nlemma lei_refine[refine_mono]:\n  \\<open>RETURN (lei a b) \\<le> RETURN (a' \\<preceq> b')\\<close> if \\<open>(a, a') \\<in> A\\<close> \\<open>(b, b') \\<in> \\<langle>A\\<rangle>list_set_rel\\<close>\n  using that using lei_less_eq by simp (metis pair_in_Id_conv tagged_fun_relD_both)\n\ndefinition list_all_split :: \"_ \\<Rightarrow> 'ki list \\<Rightarrow> bool\" where [simp]:\n  \"list_all_split = list_all\"\n\ndefinition monadic_list_all_split :: \"_ \\<Rightarrow> 'ki list \\<Rightarrow> bool nres\" where [simp]:\n  \"monadic_list_all_split = monadic_list_all\"\n\nlemmas pure_unfolds =\n  monadic_list_all_RETURN[where 'a = 'ki, folded monadic_list_all_split_def list_all_split_def]\n  monadic_list_ex_RETURN monadic_list_all_RETURN monadic_list_ex_RETURN\n  nres_monad1 option.case_distrib[where h = RETURN, symmetric]\n  if_distrib[where f = RETURN, symmetric] prod.case_distrib[where h = RETURN, symmetric]\n\nlemma list_all_split:\n  \"list_all_split Q Li = list_all id (Parallel.map (list_all Q) Li_split)\"\n  unfolding list_all_split_def list_all_split[OF full_split, symmetric] Parallel.map_def ..\n\nend\n\n\nlocale Reachability_Impl_pure_invariant =\n  Certification_Impl_invariant where M = M +\n  Reachability_Impl_pure_base where Li_split = Li_split\n  for M :: \"'k \\<Rightarrow> 'a set\" and Li_split :: \"'ki list list\"\n\nlocale Reachability_Impl_pure_base2 =\n  Reachability_Impl_pure_base where less_eq = less_eq and Li_split = Li_split\n  for less_eq :: \"'a \\<Rightarrow> 'a set \\<Rightarrow> bool\" (infix \"\\<preceq>\" 50) and Li_split :: \"'ki list list\" +\n  fixes Pi and Fi\n  assumes Pi_P'[refine,param]: \"(Pi, P') \\<in> K \\<times>\\<^sub>r A \\<rightarrow> bool_rel\"\n  assumes Fi_F[refine]: \"(Fi, F) \\<in> K \\<times>\\<^sub>r A \\<rightarrow> bool_rel\"\n\nlocale Reachability_Impl_pure =\n  Certification_Impl_common where M = M +\n  Reachability_Impl_pure_base2 +\n  Reachability_Impl_correct where M = \"\\<lambda>x. case M x of None \\<Rightarrow> {} | Some S \\<Rightarrow> S\"\n  for M :: \"'k \\<Rightarrow> 'a set option\" +\n  fixes Mi l\\<^sub>0i s\\<^sub>0i\n  assumes Mi_M[param]: \"(Mi, M) \\<in> K \\<rightarrow> \\<langle>\\<langle>A\\<rangle>list_set_rel\\<rangle>option_rel\"\n  assumes l\\<^sub>0i_l\\<^sub>0[refine,param]: \"(l\\<^sub>0i, l\\<^sub>0) \\<in> K\"\n      and s\\<^sub>0i_s\\<^sub>0[refine,param,refine_mono]: \"(s\\<^sub>0i, s\\<^sub>0) \\<in> A\"\n  fixes nonempty :: \"'a \\<Rightarrow> bool\"\n  assumes empty_not_subsumed [simp]:\n    \"nonempty x \\<Longrightarrow> x \\<preceq> {} \\<longleftrightarrow> False\"\n  assumes succs_nonempty:\n    \"(l', S') \\<in> set (succs l S) \\<Longrightarrow> x \\<in> S' \\<Longrightarrow> nonempty x\"\n  assumes M_l\\<^sub>0_not_None: \"s\\<^sub>0 \\<preceq> {} \\<Longrightarrow> M l\\<^sub>0 \\<noteq> None\"\nbegin\n\nparagraph \\<open>Refinement\\<close>\n\ndefinition \"check_invariant1 L' \\<equiv>\ndo {\n  monadic_list_all_split (\\<lambda>l.\n    case Mi l of\n      None \\<Rightarrow> RETURN True\n    | Some as \\<Rightarrow> do {\n        let succs = get_succs l as;\n        monadic_list_all (\\<lambda>(l', xs).\n        do {\n          if xs = [] then RETURN True\n          else do {\n            case Mi l' of\n              None \\<Rightarrow> RETURN False\n            | Some ys \\<Rightarrow> monadic_list_all (\\<lambda>x.\n              RETURN (lei x ys)\n            ) xs\n          }\n        }\n        ) succs\n      }\n  ) L'\n}\n\"\n\nlemma Mi_M_None_iff[simp]:\n  \"M l = None \\<longleftrightarrow> Mi li = None\" if \"(li, l) \\<in> K\"\nproof -\n  from that have \"(Mi li, M l) \\<in> \\<langle>\\<langle>A\\<rangle>list_set_rel\\<rangle>option_rel\"\n    by parametricity\n  then show ?thesis\n    by auto\nqed\n\ndefinition A' where \"A' = {(c, a). (c, a) \\<in> A \\<and> nonempty a}\"\n\nlemma A'_le_A [relator_props]:\n  \"A' \\<le> A\"\n  unfolding A'_def by auto\n\nlemma get_succs_succs'[param]:\n  \"(get_succs, succs) \\<in> K \\<rightarrow> \\<langle>A\\<rangle>list_set_rel \\<rightarrow> \\<langle>K \\<times>\\<^sub>r \\<langle>A'\\<rangle>list_set_rel\\<rangle>list_rel\"\n  using succs_nonempty get_succs_succs unfolding A'_def\n  by (auto dest!: fun_relD)\n     (auto elim!: list.rel_mono_strong intro!: relcomp.relcompI\n       simp: refine_rel_defs list_set_rel_def)\n\nlemma empty_not_subsumed' [simp]:\n  \"(cs, as) \\<in> \\<langle>A'\\<rangle>list_rel \\<Longrightarrow> x \\<in> set as \\<Longrightarrow> x \\<preceq> {} \\<longleftrightarrow> False\"\n  unfolding A'_def by (auto elim: list_rel_setE2)\n\nlemma check_invariant1_refine[refine]:\n  \"check_invariant1 L1 \\<le> check_invariant L'\" if \"(L1, L') \\<in> \\<langle>K\\<rangle>list_rel\" \"L = dom M\"\n  unfolding check_invariant1_def check_invariant_def Let_def monadic_list_all_split_def\n  apply (refine_rcg monadic_list_all_mono' refine_IdI that)\n  apply (clarsimp split: option.splits simp: succs_empty; safe)\n   apply (simp flip: Mi_M_None_iff; fail)\n  apply (refine_rcg monadic_list_all_mono')\n   apply parametricity\n  subgoal\n    using Mi_M by (auto dest!: fun_relD1)\n  apply (clarsimp split: option.splits; safe)\n  apply (\n    elim list_set_relE specify_right;\n    auto simp: monadic_list_all_False intro!: res_right simp flip: Mi_M_None_iff; fail)\n  apply (\n    elim list_set_relE specify_right;\n    auto simp: monadic_list_all_RETURN list_all_iff intro!: res_right simp flip: Mi_M_None_iff;\n    fail)+\n  subgoal premises prems for _ _ _ _ li _ l _ S xsi\n  proof -\n    have rel_mono: \"\\<langle>A'\\<rangle>list_rel \\<le> \\<langle>A\\<rangle>list_rel\"\n      by (intro relator_props)\n    have *: \\<open>li \\<in> set Li \\<longleftrightarrow> l \\<in> L\\<close> if \\<open>(li, l) \\<in> K\\<close>\n      using that using Li_L K_left_unique K_right_unique\n      by (auto dest: single_valuedD elim: list_rel_setE1 list_rel_setE2 elim!: list_set_relE)\n    have [simp]: \"l \\<in> L\"\n      using prems(6) that(2) by blast\n    from prems have \"(Mi li, M l) \\<in> \\<langle>\\<langle>A\\<rangle>list_set_rel\\<rangle>option_rel\"\n      by parametricity\n    with prems have \"(xsi, S) \\<in> \\<langle>A\\<rangle>list_set_rel\"\n      by auto\n    with prems show ?thesis\n      apply (elim list_set_relE, elim specify_right)\n      apply (clarsimp, safe)\n       apply (auto; fail)\n      supply [refine_mono] = monadic_list_all_mono' monadic_list_ex_mono'\n      apply refine_mono\n      using rel_mono by fast\n  qed\n  done\n\ndefinition check_prop1 where\n  \"check_prop1 L' M' = do {\n  l \\<leftarrow> RETURN L';\n  monadic_list_all (\\<lambda>l. do {\n    let S = op_map_lookup l M';\n    case S of None \\<Rightarrow> RETURN True | Some S \\<Rightarrow> do {\n      xs \\<leftarrow> RETURN S;\n      r \\<leftarrow> monadic_list_all (\\<lambda>s.\n        RETURN (Pi (l, s))\n      ) xs;\n      RETURN r\n    }\n    }\n  ) l\n  }\"\n\nlemma check_prop1_refine:\n  \"(check_prop1, check_prop') \\<in> \\<langle>K\\<rangle>list_set_rel \\<rightarrow> (K \\<rightarrow> \\<langle>\\<langle>A\\<rangle>list_set_rel\\<rangle>option_rel) \\<rightarrow> \\<langle>Id\\<rangle>nres_rel\"\n  supply [refine] =\n    list_of_set_impl[THEN fun_relD, THEN nres_relD] monadic_list_all_mono' case_option_mono'\n  supply [refine_mono] =\n    monadic_list_all_mono' list_of_set_impl[THEN fun_relD, THEN nres_relD]\n  unfolding check_prop1_def check_prop'_def list_of_set_def[symmetric] Let_def op_map_lookup_def\n  apply refine_rcg\n   apply assumption\n  apply (refine_rcg refine_IdI, assumption)\n   apply parametricity\n  apply (rule bind_mono)\n   apply refine_mono+\n  using Pi_P'\n  apply (auto simp add: prod_rel_def dest!: fun_relD)\n  done\n\nlemma [refine]:\n  \"(Mi l\\<^sub>0i \\<noteq> None, l\\<^sub>0 \\<in> L) \\<in> bool_rel\" if \"L = dom M\"\n  using that by (auto simp: Mi_M_None_iff[symmetric, OF l\\<^sub>0i_l\\<^sub>0])\n\nlemma [refine]:\n  \"(Pi (l\\<^sub>0i, s\\<^sub>0i), P' (l\\<^sub>0, s\\<^sub>0)) \\<in> bool_rel\"\n  by parametricity\n\ndefinition\n  \"check_all_pre1 \\<equiv> do {\n  b1 \\<leftarrow> RETURN (Mi l\\<^sub>0i \\<noteq> None);\n  b2 \\<leftarrow> RETURN (Pi (l\\<^sub>0i, s\\<^sub>0i));\n  case Mi l\\<^sub>0i of\n    None \\<Rightarrow> RETURN False\n  | Some xs \\<Rightarrow> do {\n    b3 \\<leftarrow> RETURN (lei s\\<^sub>0i xs);\n    b4 \\<leftarrow> check_prop1 Li Mi;\n    RETURN (b1 \\<and> b2 \\<and> b3 \\<and> b4)\n  }\n  }\"\n\ndefinition check_all_pre0 where\n  \"check_all_pre0 = do {\n  b1 \\<leftarrow> RETURN (l\\<^sub>0 \\<in> L);\n  b2 \\<leftarrow> RETURN (P' (l\\<^sub>0, s\\<^sub>0));\n  case M l\\<^sub>0 of\n    None \\<Rightarrow> RETURN False\n  | Some xs \\<Rightarrow> do {\n    b3 \\<leftarrow> RETURN (less_eq s\\<^sub>0 xs);\n    b4 \\<leftarrow> check_prop P';\n    RETURN (b1 \\<and> b2 \\<and> b3 \\<and> b4)\n  }\n  }\"\n\nlemma check_all_pre0_correct:\n  \"check_all_pre0 \\<le> SPEC (\\<lambda>r. r \\<longrightarrow> check_all_pre_spec l\\<^sub>0 s\\<^sub>0)\"\n  unfolding check_all_pre0_def check_all_pre_spec_def\n  by (refine_vcg check_prop_correct; auto simp: list_ex_iff)\n\nlemma check_all_pre0_1_refine:\n  \"(check_all_pre1, check_all_pre0) \\<in> \\<langle>bool_rel\\<rangle>nres_rel\" if \"L = dom M\"\nunfolding check_all_pre1_def check_all_pre0_def\n    apply (refine_rcg that; simp)\n    supply [refine_mono] =\n      monadic_list_ex_mono' monadic_list_ex_RETURN_mono specify_right HOL.refl\n      check_prop1_refine[THEN fun_relD, THEN fun_relD, THEN nres_relD, THEN refine_IdD,\n        of Li L Mi M, unfolded check_prop_alt_def]\n      Li_L Mi_M\n    supply [param] = lei_less_eq\n   apply parametricity\n  apply parametricity\n  apply (rule order.trans)\n  apply (rule refine_mono)\n   apply refine_mono\n  apply refine_mono\napply refine_rcg+\n  by simp\n\nlemma check_all_pre1_correct:\n  \"check_all_pre1 \\<le> SPEC (\\<lambda>r. r \\<longrightarrow> check_all_pre_spec l\\<^sub>0 s\\<^sub>0)\" if \"L = dom M\"\nproof -\n  note check_all_pre0_1_refine[THEN nres_relD]\n  also note check_all_pre0_correct\n  finally show ?thesis using that .\nqed\n\nlemma (in -) nres_cases'[case_names FAIL RES]:\n  obtains \"M=FAIL\" | X where \"X = {}\" \"M=RES X\" | X where \"X \\<noteq> {}\" \"M=RES X\"\n  by (cases M) auto\n\ntext \\<open>This is just a refinement-oriented alternative to derive @{thm check_all_pre1_correct}.\\<close>\nlemma check_prop_nofail:\n  \"nofail (check_prop P')\"\n  unfolding check_prop_def\n  by (auto 4 5 intro: monadic_list_all_nofailI no_fail_RES_bindI split: option.split_asm)\n\nlemma check_all_pre0_refine:\n  \"(check_all_pre0, check_all_pre l\\<^sub>0 s\\<^sub>0) \\<in> \\<langle>bool_rel\\<rangle>nres_rel\" if \"L = dom M\"\n  apply (cases \"M l\\<^sub>0\")\n   apply (cases \"P' (l\\<^sub>0, s\\<^sub>0)\")\n  unfolding check_all_pre0_def check_all_pre_def\n  subgoal\n    apply (refine_rcg, simp)\n    apply (cases \"s\\<^sub>0 \\<preceq> {}\"; simp add: M_l\\<^sub>0_not_None)\n    apply (cases \"check_prop P'\" rule: nres_cases'; simp)\n    using check_prop_gt_SUCCEED by order\n  subgoal\n    apply (cases \"check_prop P'\" rule: nres_cases'; simp)\n    subgoal\n      using check_prop_nofail by refine_rcg\n    subgoal for X\n      using check_prop_gt_SUCCEED by order\n    by refine_rcg\n  by refine_rcg auto\n\nlemma check_all_pre1_refine:\n  \"(check_all_pre1, check_all_pre l\\<^sub>0 s\\<^sub>0) \\<in> \\<langle>bool_rel\\<rangle>nres_rel\" if \"L = dom M\"\nproof -\n  note check_all_pre0_1_refine [THEN nres_relD]\n  also note check_all_pre0_refine [THEN nres_relD]\n  finally show ?thesis\n    using that by refine_vcg\nqed\n\ndefinition\n  \"check_all1 \\<equiv> do {\n  b \\<leftarrow> check_all_pre1;\n  if b\n  then do {\n    r \\<leftarrow> check_invariant1 Li;\n    PRINT_CHECK STR ''State set invariant check'' r;\n    RETURN r\n  }\n  else RETURN False\n  }\n\"\n\nlemma check_all1_correct[refine]:\n  \"check_all1 \\<le> SPEC (\\<lambda>r. r \\<longrightarrow> check_all_pre_spec l\\<^sub>0 s\\<^sub>0 \\<and> check_invariant_spec L)\" if \"L = dom M\"\nproof -\n  note [refine] = check_all_pre1_correct [OF that]\n  obtain L' where \"(Li, L') \\<in> \\<langle>K\\<rangle>list_rel\" \"set L' = L\"\n    using Li_L by (elim list_set_relE)\n  note check_invariant1_refine\n  also note check_invariant_correct\n  also have [refine]: \"check_invariant1 Li \\<le> SPEC (\\<lambda>r. r \\<longrightarrow> check_invariant_spec L)\"\n    if \"check_all_pre_spec l\\<^sub>0 s\\<^sub>0\"\n    apply (subst (2) \\<open>_ = L\\<close>[symmetric])\n    apply (rule calculation)\n    using Li_L \\<open>(Li, L') \\<in> _\\<close> that unfolding check_all_pre_spec_def\n    by (auto simp: \\<open>_ = L\\<close> \\<open>L = _\\<close> dest: P'_P)\n  show ?thesis\n    unfolding check_all1_def PRINT_CHECK_def comp_def by (refine_vcg; simp)\nqed\n\ndefinition\n  \"check_final1 L' = do {\n  monadic_list_all (\\<lambda>l. do {\n    case op_map_lookup l Mi of None \\<Rightarrow> RETURN True | Some xs \\<Rightarrow> do {\n      monadic_list_all (\\<lambda>s.\n        RETURN (\\<not> PR_CONST Fi (l, s))\n      ) xs\n    }\n    }\n  ) L'\n  }\"\n\nlemma check_final1_refine:\n  \"check_final1 Li \\<le> check_final' L M\"\n    using Li_L apply (elim list_set_relE)\n  unfolding check_final1_def check_final'_def\n  apply (erule specify_right)\n  supply [refine_mono] = monadic_list_all_mono'\n  apply refine_mono\n  apply (clarsimp split: option.splits)\n  apply (refine_rcg monadic_list_all_mono')\n   apply (simp flip: Mi_M_None_iff; fail)\n  subgoal premises prems for _ li l xsi S\n  proof -\n    from \\<open>(li, l) \\<in> K\\<close> have \"(Mi li, M l) \\<in> \\<langle>\\<langle>A\\<rangle>list_set_rel\\<rangle>option_rel\"\n      by parametricity\n    with prems have \"(xsi, S) \\<in> \\<langle>A\\<rangle>list_set_rel\"\n      by auto\n    then obtain xs where \"(xsi, xs) \\<in> \\<langle>A\\<rangle>list_rel\" \"set xs = S\"\n      by (elim list_set_relE)\n    then show ?thesis\n      using Fi_F \\<open>(li, l) \\<in> K\\<close>\n      by (refine_rcg monadic_list_all_mono' specify_right) (auto dest!: fun_relD)\n  qed\n  done\n\ndefinition\n  \"certify_unreachable1 = do {\n    b1 \\<leftarrow> check_all1;\n    b2 \\<leftarrow> check_final1 Li;\n    RETURN (b1 \\<and> b2)\n  }\"\n\nlemma certify_unreachable1_correct:\n  \"certify_unreachable1 \\<le> SPEC (\\<lambda>r. r \\<longrightarrow> check_all_spec \\<and> check_final_spec)\" if \"L = dom M\"\nproof -\n  note check_final1_refine[unfolded check_final_alt_def]\n  also note check_final_correct\n  finally have [refine]: \"check_final1 Li \\<le> SPEC (\\<lambda>r. r = check_final_spec)\" .\n  show ?thesis\n    unfolding certify_unreachable1_def check_all_spec_def by (refine_vcg that; fast)\nqed\n\nparagraph \\<open>Synthesizing a pure program via rewriting\\<close>\n\nlemma check_final1_alt_def:\n  \"check_final1 L' = RETURN (list_all_split\n    (\\<lambda>l. case op_map_lookup l Mi of None \\<Rightarrow> True | Some xs \\<Rightarrow> list_all (\\<lambda>s. \\<not> Fi (l, s)) xs) L')\"\n  unfolding check_final1_def\n  unfolding monadic_list_all_RETURN[symmetric] list_all_split_def\n  by (fo_rule arg_cong2, intro ext)\n     (auto split: option.splits simp: monadic_list_all_RETURN[symmetric])\n\nconcrete_definition check_final_impl\n  uses check_final1_alt_def is \"_ = RETURN ?f\"\n\nschematic_goal check_prop1_alt_def:\n  \"check_prop1 L' M' \\<equiv> RETURN ?f\"\n  unfolding check_prop1_def pure_unfolds Let_def .\n\nconcrete_definition check_prop_impl uses check_prop1_alt_def is \"_ \\<equiv> RETURN ?f\"\n\nschematic_goal check_all_pre1_alt_def:\n  \"check_all_pre1 \\<equiv> RETURN ?f\"\n  unfolding check_all_pre1_def check_prop_impl.refine pure_unfolds .\n\nconcrete_definition check_all_pre_impl uses check_all_pre1_alt_def is \"_ \\<equiv> RETURN ?f\" \n\nschematic_goal check_invariant1_alt_def:\n  \"check_invariant1 Li \\<equiv> RETURN ?f\"\n  unfolding check_invariant1_def Let_def pure_unfolds .\n\nconcrete_definition check_invariant_impl uses check_invariant1_alt_def is \"_ \\<equiv> RETURN ?f\"\n\nschematic_goal certify_unreachable1_alt_def:\n  \"certify_unreachable1 \\<equiv> RETURN ?f\"\n  unfolding\n    certify_unreachable1_def check_all1_def check_final_impl.refine check_all_pre_impl.refine\n    check_invariant_impl.refine\n    pure_unfolds PRINT_CHECK_def comp_def short_circuit_conv .\n\nconcrete_definition certify_unreachable_impl_pure1\n  uses certify_unreachable1_alt_def is \"_ \\<equiv> RETURN ?f\"\n\ntext \\<open>This is where we add parallel execution:\\<close>\n\nschematic_goal certify_unreachable_impl_pure1_alt_def:\n  \"certify_unreachable_impl_pure1 \\<equiv> ?f\"\n  unfolding certify_unreachable_impl_pure1_def\n  apply (abstract_let check_invariant_impl check_invariant)\n  apply (abstract_let \"check_final_impl Li\" check_final)\n  apply (abstract_let check_all_pre_impl check_all_pre_impl)\n  apply (time_it \"STR ''Time for state set preconditions check''\" check_all_pre_impl)\n  apply (time_it \"STR ''Time for state space invariant check''\"   check_invariant_impl)\n  apply (time_it \"STR ''Time to check final state predicate''\"    \"check_final_impl Li\")\n  unfolding\n    check_invariant_impl_def check_all_pre_impl_def\n    check_prop_impl_def check_final_impl_def\n    list_all_split\n  apply (subst list_all_default_split[where xs = Li, folded Parallel.map_def])\n  .\n\nconcrete_definition (in -) certify_unreachable_impl_pure\n  uses Reachability_Impl_pure.certify_unreachable_impl_pure1_alt_def is \"_ \\<equiv> ?f\"\n\nsublocale correct: Reachability_Impl_correct where\n  M = \"\\<lambda>x. case M x of None \\<Rightarrow> {} | Some S \\<Rightarrow> abs_s ` S\"\n  apply standard\n  oops\n\nend (* Reachability_Impl_pure *)\n\nlocale Reachability_Impl_pure_correct =\n  Reachability_Impl_pure where M = M +\n  Reachability_Impl_correct where M = \"\\<lambda>x. case M x of None \\<Rightarrow> {} | Some S \\<Rightarrow> S\" for M\nbegin\n\ntheorem certify_unreachable_impl_pure_correct:\n  \"certify_unreachable_impl_pure get_succs Li lei Li_split Pi Fi Mi l\\<^sub>0i s\\<^sub>0i\n  \\<longrightarrow> (\\<nexists>s'. E\\<^sup>*\\<^sup>* (l\\<^sub>0, s\\<^sub>0) s' \\<and> F s')\"\n  if \"L = dom M\"\n  using certify_unreachable1_correct that\n  unfolding\n    certify_unreachable_impl_pure1.refine\n    certify_unreachable_impl_pure.refine[OF Reachability_Impl_pure_axioms]\n  using certify_unreachableI by simp\n\nend (* Reachability_Impl_pure correct *)\n\nlocale Reachability_Impl_imp_base =\n  Reachability_Impl_base +\n  Certification_Impl_imp_base\n\nlocale Reachability_Impl_imp_to_pure_base = Reachability_Impl_imp_base\n  where K = K and A = A\n  for K :: \"'k \\<Rightarrow> ('ki :: {hashable,heap}) \\<Rightarrow> assn\" and A :: \"'s \\<Rightarrow> ('si :: heap) \\<Rightarrow> assn\"\n  +\n  fixes to_state :: \"'s1 \\<Rightarrow> 'si Heap\" and from_state :: \"'si \\<Rightarrow> 's1 Heap\"\n    and to_loc :: \"'k1 \\<Rightarrow> 'ki\" and from_loc :: \"'ki \\<Rightarrow> 'k1\"\n  fixes lei\n  fixes K_rel and A_rel\n  fixes L_list :: \"'ki list\" and Li :: \"'k1 list\" and L :: \"'k set\" and L' :: \"'k list\"\n  fixes Li_split :: \"'k1 list list\"\n  assumes Li: \"(L_list, L') \\<in> \\<langle>the_pure K\\<rangle>list_rel\" \"(Li, L') \\<in> \\<langle>K_rel\\<rangle>list_rel\" \"set L' = L\"\n  assumes to_state_ht: \"(s1, s) \\<in> A_rel \\<Longrightarrow> <emp> to_state s1 <\\<lambda>si. A s si>\"\n  assumes from_state_ht: \"<A s si> from_state si <\\<lambda>s'. \\<up>((s', s) \\<in> A_rel)>\\<^sub>t\"\n  assumes from_loc: \"(li, l) \\<in> the_pure K \\<Longrightarrow> (from_loc li, l) \\<in> K_rel\"\n  assumes to_loc: \"(l1, l) \\<in> K_rel \\<Longrightarrow> (to_loc l1, l) \\<in> the_pure K\"\n  assumes K_rel: \"single_valued K_rel\" \"single_valued (K_rel\\<inverse>)\"\n  \\<^cancel>\\<open>assumes lei_less_eq: \"(lei, (\\<preceq>)) \\<in> A_rel \\<rightarrow> A_rel \\<rightarrow> bool_rel\"\\<close>\n  assumes lei_less_eq: \"(lei, (\\<preceq>)) \\<in> A_rel \\<rightarrow> \\<langle>A_rel\\<rangle>list_set_rel \\<rightarrow> bool_rel\"\n  assumes full_split: \"set Li = (\\<Union>xs \\<in> set Li_split. set xs)\"\nbegin\n\ndefinition\n  \"get_succs l xs \\<equiv>\n    do {\n      let li = to_loc l;\n      xsi \\<leftarrow> Heap_Monad.fold_map to_state xs;\n      r \\<leftarrow> succsi li xsi;\n      Heap_Monad.fold_map\n        (\\<lambda>(li, xsi). do {xs \\<leftarrow> Heap_Monad.fold_map from_state xsi; return (from_loc li, xs)}) r\n    }\"\n\nlemma get_succs:\n  \"(run_heap oo get_succs, succs)\n  \\<in> K_rel \\<rightarrow> \\<langle>A_rel\\<rangle>list_set_rel \\<rightarrow> \\<langle>K_rel \\<times>\\<^sub>r \\<langle>A_rel\\<rangle>list_set_rel\\<rangle>list_rel\"\nproof (refine_rcg, clarsimp, rule hoare_triple_run_heapD)\n  fix l :: \\<open>'k\\<close> and l1 :: \\<open>'k1\\<close> and xs :: \\<open>'s1 list\\<close> and S :: \\<open>'s set\\<close>\n  assume \\<open>(l1, l) \\<in> K_rel\\<close> \\<open>(xs, S) \\<in> \\<langle>A_rel\\<rangle>list_set_rel\\<close>\n  then obtain ys where ys: \"(xs, ys) \\<in> \\<langle>A_rel\\<rangle>list_rel\" \"set ys = S\"\n    by (elim list_set_relE)\n  have 1: \"K = pure (the_pure K)\"\n    using pure_K by auto\n  let ?li = \"to_loc l1\"\n  show \"<emp> get_succs l1 xs <\\<lambda>r. \\<up>((r, succs l S) \\<in> \\<langle>K_rel \\<times>\\<^sub>r \\<langle>A_rel\\<rangle>list_set_rel\\<rangle>list_rel)>\\<^sub>t\"\n    unfolding get_succs_def\n    apply sep_auto\n      (* fold_map to_state *)\n     apply (rule Hoare_Triple.cons_pre_rule[rotated])\n      apply (rule fold_map_ht3[where A = true and R = \"pure A_rel\" and Q = A and xs = ys])\n    apply (sep_auto heap: to_state_ht simp: pure_def; fail)\n     apply (unfold list_assn_pure_conv, sep_auto simp: pure_def ys; fail)\n    apply sep_auto\n      (* succsi *)\n     apply (rule Hoare_Triple.cons_pre_rule[rotated], rule frame_rule[where R = true])\n      apply (rule succsi[to_hnr, unfolded hn_refine_def hn_ctxt_def, simplified, of S _ l ?li])\n    subgoal\n      using ys \\<open>(l1, l) \\<in> K_rel\\<close> unfolding lso_assn_def hr_comp_def br_def \\<open>set ys = _\\<close>[symmetric]\n      by (subst 1) (sep_auto simp: pure_def to_loc)\n        (* nested fold_map *)\n    apply (sep_auto simp: invalid_assn_def)\n    apply (rule cons_rule[rotated 2])\n      apply (rule frame_rule)\n      apply (rule fold_map_ht1[where\n          A = true and R = \"(K \\<times>\\<^sub>a lso_assn A)\" and xs = \"succs l S\" and\n          Q = \"\\<lambda>x xi. (xi, x) \\<in> K_rel \\<times>\\<^sub>r \\<langle>A_rel\\<rangle>list_set_rel\"\n          ])\n    subgoal\n      unfolding lso_assn_def\n      apply (subst 1, subst pure_def)\n      apply (sep_auto simp: prod_assn_def hr_comp_def br_def split: prod.splits)\n        (* inner fold_map *)\n       apply (rule Hoare_Triple.cons_pre_rule[rotated])\n        apply (rule fold_map_ht1[where A = true and R = A and Q = \"\\<lambda>l l1. (l1, l) \\<in> A_rel\"])\n        apply (rule cons_rule[rotated 2], rule frame_rule, rule from_state_ht)\n         apply frame_inference\n        apply (sep_auto; fail)\n       apply solve_entails\n        (* return *)\n      using list_all2_swap by (sep_auto simp: list.rel_eq list_set_rel_def from_loc list_rel_def)\n     apply solve_entails\n    using list_all2_swap by (sep_auto simp: list_rel_def)\nqed\n\ndefinition\n  \"to_pair \\<equiv> \\<lambda>(l, s). do {s \\<leftarrow> to_state s; return (to_loc l, s)}\"\n\nlemma to_pair_ht:\n  \"<emp> to_pair a1 <\\<lambda>ai. (K \\<times>\\<^sub>a A) a ai>\" if \"(a1, a) \\<in> K_rel \\<times>\\<^sub>r A_rel\"\n  using that unfolding to_pair_def\n  by (cases a, cases a1, subst pure_the_pure[symmetric, OF pure_K])\n     (sep_auto heap: to_state_ht simp: pure_def to_loc prod_assn_def split: prod.splits)\n\nsublocale pure:\n  Reachability_Impl_pure_base2\n  where\n    get_succs = \"run_heap oo get_succs\" and\n    K = K_rel and\n    A = A_rel and\n    lei = lei and\n    Pi = \"\\<lambda>a. run_heap (do {a \\<leftarrow> to_pair a; Pi a})\" and\n    Fi = \"\\<lambda>a. run_heap (do {a \\<leftarrow> to_pair a; Fi a})\" \\<^cancel>\\<open>and\n    l\\<^sub>0i = \"from_loc (run_heap l\\<^sub>0i)\" and\n    s\\<^sub>0i = \"run_heap (do {s \\<leftarrow> s\\<^sub>0i; from_state s})\"\\<close>\n  apply standard\n  subgoal\n    by (rule K_rel)\n  subgoal\n    by (rule K_rel)\n  subgoal\n    using Li unfolding list_set_rel_def by auto\n  subgoal\n    by (rule lei_less_eq)\n  subgoal\n    using get_succs .\n  subgoal\n    by (rule full_split)\n  subgoal\n    apply standard\n    apply (rule hoare_triple_run_heapD)\n    apply (sep_auto heap: to_pair_ht simp del: prod_rel_simp prod_assn_pair_conv)\n    apply (rule Hoare_Triple.cons_rule[rotated 2])\n      apply (rule Pi_P'[to_hnr, unfolded hn_refine_def hn_ctxt_def, simplified], rule ent_refl)\n    apply (sep_auto simp: pure_def)\n    done\n  subgoal\n    apply standard\n    apply (rule hoare_triple_run_heapD)\n    apply (sep_auto heap: to_pair_ht simp del: prod_rel_simp prod_assn_pair_conv)\n    apply (rule Hoare_Triple.cons_rule[rotated 2])\n      apply (rule Fi_F[to_hnr, unfolded hn_refine_def hn_ctxt_def, simplified], rule ent_refl)\n    apply (sep_auto simp: pure_def)\n    done\n  done\n\nend\n\nlocale Reachability_Impl_imp_to_pure = Reachability_Impl where\n  l\\<^sub>0 = l\\<^sub>0 and s\\<^sub>0 = s\\<^sub>0 and M = M and K = K and A = A\n  + Reachability_Impl_imp_to_pure_base\n  where K_rel = K_rel and A_rel = A_rel and K = K and A = A\n  for l\\<^sub>0 :: 'k and s\\<^sub>0 :: 'a\n  and K :: \"'k \\<Rightarrow> ('ki :: {hashable,heap}) \\<Rightarrow> assn\" and A :: \"'a \\<Rightarrow> ('ai :: heap) \\<Rightarrow> assn\"\n  and M and K_rel :: \"('k1 \\<times> 'k) set\" and A_rel :: \"('a1 \\<times> 'a) set\" +\n  fixes Mi :: \"'k1 \\<Rightarrow> 'a1 list option\"\n  assumes Mi_M: \"(Mi, M) \\<in> K_rel \\<rightarrow> \\<langle>\\<langle>A_rel\\<rangle>list_set_rel\\<rangle>option_rel\"\n  fixes nonempty :: \"'a \\<Rightarrow> bool\"\n  assumes empty_not_subsumed [simp]:\n    \"nonempty x \\<Longrightarrow> x \\<preceq> {} \\<longleftrightarrow> False\"\n  assumes succs_nonempty:\n    \"(l', S') \\<in> set (succs l S) \\<Longrightarrow> x \\<in> S' \\<Longrightarrow> nonempty x\"\n  assumes M_l\\<^sub>0_not_None: \"s\\<^sub>0 \\<preceq> {} \\<Longrightarrow> M l\\<^sub>0 \\<noteq> None\"\nbegin\n\nsublocale pure:\n  Reachability_Impl_pure\n  where           \n    M = M and\n    Mi = Mi and\n    get_succs = \"run_heap oo get_succs\" and\n    K = K_rel and\n    A = A_rel and\n    lei = lei and\n    Pi = \"\\<lambda>a. run_heap (do {a \\<leftarrow> to_pair a; Pi a})\" and\n    Fi = \"\\<lambda>a. run_heap (do {a \\<leftarrow> to_pair a; Fi a})\" and\n    l\\<^sub>0i = \"from_loc (run_heap l\\<^sub>0i)\" and\n    s\\<^sub>0i = \"run_heap (do {s \\<leftarrow> s\\<^sub>0i; from_state s})\"\n  apply standard\n    apply (rule Mi_M)\n  subgoal\n    apply (rule from_loc)\n    apply (rule hoare_triple_run_heapD)\n    using l\\<^sub>0i_l\\<^sub>0[to_hnr, unfolded hn_refine_def hn_ctxt_def, simplified]\n    apply (subst (asm) pure_the_pure[symmetric, OF pure_K])\n    apply (sep_auto simp: pure_def elim!: cons_post_rule)\n    done\n  subgoal\n    using s\\<^sub>0i_s\\<^sub>0[to_hnr, unfolded hn_refine_def hn_ctxt_def, simplified]\n    by - (rule hoare_triple_run_heapD, sep_auto heap: from_state_ht)\n  apply (rule empty_not_subsumed succs_nonempty M_l\\<^sub>0_not_None; assumption; fail)+\n  done\n\nend\n\nlocale Reachability_Impl_imp_to_pure_correct =\n  Reachability_Impl_imp_to_pure where M = M\n  + Reachability_Impl_correct where M = \"\\<lambda>x. case M x of None \\<Rightarrow> {} | Some S \\<Rightarrow> S\"\n  for M\nbegin\n\nsublocale pure:\n  Reachability_Impl_pure_correct\n  where           \n    M = M and\n    Mi = Mi and\n    get_succs = \"run_heap oo get_succs\" and\n    K = K_rel and\n    A = A_rel and\n    lei = lei and\n    Pi = \"\\<lambda>a. run_heap (do {a \\<leftarrow> to_pair a; Pi a})\" and\n    Fi = \"\\<lambda>a. run_heap (do {a \\<leftarrow> to_pair a; Fi a})\" and\n    l\\<^sub>0i = \"from_loc (run_heap l\\<^sub>0i)\" and\n    s\\<^sub>0i = \"run_heap (do {s \\<leftarrow> s\\<^sub>0i; from_state s})\"\n  by standard\n\nend\n\nend", "meta": {"author": "wimmers", "repo": "munta-games", "sha": "12da82b74f595c33278aeac82b58cbfbfd2fd6a3", "save_path": "github-repos/isabelle/wimmers-munta-games", "path": "github-repos/isabelle/wimmers-munta-games/munta-games-12da82b74f595c33278aeac82b58cbfbfd2fd6a3/Safety_Certification_Pure.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5774953651858118, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.2932589980076071}}
{"text": "theory Hoare_Indexed\n  imports\n \"../Syntax/Gensyn\" \"../Syntax/Gensyn_Descend\" \"../Mergeable/Mergeable\"\n  \"../Mergeable/Mergeable_Instances\"\n \"../Semantics/Semantics\" \"../Semantics/Semantics_Facts\"\nbegin\n\n(*\n * An alternate version of Hoare logic that includes explicit step-counts.\n * This ends up being useful for proving statements about control constructs that may\n * diverge (e.g. loops).\n *)\n\n(* Captures being safe for a certain number of steps *)\ndefinition safe_for :: \"('syn, 'mstate) semc \\<Rightarrow> ('syn, 'mstate) control \\<Rightarrow> nat \\<Rightarrow> bool\" where\n\"safe_for gs full n =\n  ((\\<exists> n0 full' . n0 \\<le> n \\<and> sem_exec_c_p gs full n0 full' \\<and> cont full' = Inl []) \\<or>\n   (\\<forall> n0 . n0 \\<le> n \\<longrightarrow> (\\<exists> full' h t . sem_exec_c_p gs full n0 full' \\<and> cont full' = Inl (h#t))))\"\n\nlemma safe_forI_halt :\n  assumes \"n0 \\<le> n\"\n  assumes \"sem_exec_c_p gs full n0 full'\"\n  assumes \"cont full' = Inl []\"\n  shows \"safe_for gs full n\"\n  using assms unfolding safe_for_def by blast\n\nlemma safe_forI_spin :\n  assumes \"\\<And> n0 . n0 \\<le> n \\<Longrightarrow> (\\<exists> full' h t . sem_exec_c_p gs full n0 full' \\<and> cont full' = Inl (h#t))\"\n  shows \"safe_for gs full n\" using assms unfolding safe_for_def by blast\n\nlemma exec_c_p_prefix :\n  assumes H : \"sem_exec_c_p gs st1 n st2\"\n  assumes \"cont st2 = Inl z\"\n  assumes \"n' < n\"\n  shows \"(\\<exists> st2' h' t' . sem_exec_c_p gs st1 n' st2' \\<and> cont st2' = Inl (h'#t'))\"\n  using assms\nproof(induction arbitrary: z n' rule: sem_exec_c_p.induct)\n  case (Excp_0 m)\n\n  then show ?case using Excp_0 by blast\nnext\n  case (Excp_Suc m1 m2 n m3)\n  then show ?case \n  proof(cases n')\n    case 0\n\n    have Exec0 : \"sem_exec_c_p gs m1 n' m1\"\n      using sem_exec_c_p.intros(1)[of gs m1] unfolding 0 by auto\n\n    obtain h t where Cont1 : \"cont m1 = Inl (h#t)\"\n      using Excp_Suc.hyps(1)\n      unfolding sem_step_p_eq sem_step_def\n      by(auto split: sum.splits list.splits)\n\n    show ?thesis using Exec0 Cont1 by blast\n  next\n    case (Suc n'')\n\n    then have Lt : \"n'' < n\"\n      using Excp_Suc.prems by auto\n\n    obtain st2' h' t' where\n      Exec2 : \"sem_exec_c_p gs m2 n'' st2'\" and Cont2 :\"cont st2' = Inl (h'#t')\"\n      using Excp_Suc.IH[OF Excp_Suc.prems(1) Lt]\n      by blast\n\n    have ExecSuc : \"sem_exec_c_p gs m1 (Suc n'') st2'\"\n      using sem_exec_c_p.intros(2)[OF Excp_Suc.hyps(1) Exec2] by auto\n\n    show ?thesis using ExecSuc Cont2 unfolding Suc by blast\n  qed\nqed\n\n\nlemma safe_for_weaken :\n  assumes H : \"safe_for gs full n\"\n  assumes Leq : \"n' \\<le> n\"\n  shows \"safe_for gs full n'\"\nproof-\n\n  consider \n    (1) n0 full' where \"n0 \\<le> n\" \"sem_exec_c_p gs full n0 full'\" \"cont full' = Inl []\" |\n    (2) \"\\<And> n0 . n0 \\<le>n \\<Longrightarrow> \\<exists>full' h t. sem_exec_c_p gs full n0 full' \\<and> cont full' = Inl (h # t)\"\n    using H unfolding safe_for_def\n    by blast\n\n  then show \"safe_for gs full n'\"\n  proof cases\n    case 1\n    then show ?thesis\n    proof(cases \"n0 \\<le> n'\")\n      case True\n\n      show ?thesis using safe_forI_halt[OF True 1(2) 1(3)] by auto\n    next\n      case False\n\n      hence False' : \"n' < n0\" by simp\n\n      obtain mid h t where\n        Exec_Mid : \"sem_exec_c_p gs full n' mid\" and\n        Cont_Mid : \"cont mid = Inl (h#t)\"\n        using exec_c_p_prefix[OF 1(2) 1(3) False'] by blast\n\n      have Safe_for_prem : \"(\\<And>nx. nx \\<le> n' \\<Longrightarrow> \\<exists>fullx hx tx. sem_exec_c_p gs full nx fullx \\<and> cont fullx = Inl (hx # tx))\"\n      proof-\n        fix nx\n\n        assume Nx : \"nx \\<le> n'\"\n        hence Nx' : \"nx < n0\" using False' by auto\n\n      obtain mid h t where\n        Exec_Mid : \"sem_exec_c_p gs full nx mid\" and\n        Cont_Mid : \"cont mid = Inl (h#t)\"\n        using exec_c_p_prefix[OF 1(2) 1(3) Nx'] by blast\n\n      then show \"\\<exists>fullx hx tx. sem_exec_c_p gs full nx fullx \\<and> cont fullx = Inl (hx # tx)\"\n        by blast\n    qed\n\n    show ?thesis using safe_forI_spin[OF Safe_for_prem] by blast\n  qed\n  next\n    case 2\n\n    have Safe_for_prem : \"(\\<And>nx. nx \\<le> n' \\<Longrightarrow> \\<exists>fullx hx tx. sem_exec_c_p gs full nx fullx \\<and> cont fullx = Inl (hx # tx))\"\n    proof-\n      fix nx\n      assume Nx : \"nx \\<le> n'\"\n\n      have Leq' : \"nx \\<le> n\" using Nx Leq by simp\n\n      show \"\\<exists>fullx hx tx. sem_exec_c_p gs full nx fullx \\<and> cont fullx = Inl (hx # tx)\"\n        using 2[OF Leq'] by blast\n    qed\n\n    then show ?thesis using safe_forI_spin[OF Safe_for_prem] by blast\n  qed\nqed\n\nlemma safe_for_extend :\n  assumes H : \"safe_for gs st2 n2\"\n  assumes Hexec : \"sem_exec_c_p gs st1 n1 st2\"\n  shows \"safe_for gs st1 (n1 + n2)\" using Hexec H\nproof(induction arbitrary: n2 rule: sem_exec_c_p.induct)\n  case (Excp_0 m)\n  then show ?case by simp\nnext\n  case (Excp_Suc m1 m2 n m3)\n\n  have Safe2 : \"safe_for gs m2 (n + n2)\"\n    using Excp_Suc.IH[OF Excp_Suc.prems(1)] by simp\n\n  consider \n    (1) n0 full' where \"n0 \\<le> n + n2\" \"sem_exec_c_p gs m2 n0 full'\" \"cont full' = Inl []\" |\n    (2) \"\\<And> n0 . n0 \\<le>n + n2 \\<Longrightarrow> \\<exists>full' h t. sem_exec_c_p gs m2 n0 full' \\<and> cont full' = Inl (h # t)\"\n    using Safe2 unfolding safe_for_def\n    by blast\n\n  then show ?case\n  proof cases\n    case 1\n\n    have Exec : \"sem_exec_c_p gs m1 (Suc n0) full'\"\n      using sem_exec_c_p.intros(2)[OF Excp_Suc.hyps(1) 1(2)] by simp\n\n    have Leq : \"Suc n0 \\<le> Suc n + n2 \" using 1(1) by simp\n\n    show ?thesis using safe_forI_halt[OF Leq Exec 1(3)] by simp\n  next\n    case 2\n\n    have Safe_for_prem :\n      \"(\\<And>n0. n0 \\<le> (Suc n + n2) \\<Longrightarrow> \\<exists>full' h t. sem_exec_c_p gs m1 n0 full' \\<and> cont full' = Inl (h # t))\"\n    proof-\n      fix n0\n      assume N0 : \"n0 \\<le> Suc n + n2\"\n\n      show \"\\<exists>full' h t. sem_exec_c_p gs m1 n0 full' \\<and> cont full' = Inl (h # t)\"\n      proof(cases n0)\n        case 0\n\n        have Exec0 : \"sem_exec_c_p gs m1 n0 m1\"\n          using sem_exec_c_p.intros(1)[of gs m1] unfolding 0 by simp\n\n        obtain h t where Cont0 : \"cont m1 = Inl (h # t)\"\n          using Excp_Suc.hyps(1) unfolding sem_step_p_eq sem_step_def\n          by(auto split: sum.splits list.splits)\n\n        show ?thesis using Exec0 Cont0 by blast\n      next\n        case (Suc n0')\n\n        have Leq' : \"n0' \\<le> n + n2\" using Suc N0 by simp\n\n        obtain m2' h t where M2_exec : \"sem_exec_c_p gs m2 n0' m2'\" and M2_cont : \"cont m2' = Inl (h # t)\"\n          using 2[OF Leq'] by blast\n\n        have Exec_Suc : \"sem_exec_c_p gs m1 n0 m2'\"\n          using sem_exec_c_p.intros(2)[OF Excp_Suc.hyps(1) M2_exec] \n          unfolding Suc by simp\n\n        show ?thesis using Exec_Suc M2_cont by blast\n      qed\n    qed\n\n    show ?thesis using safe_forI_spin[OF Safe_for_prem, of \"Suc n + n2\"] by simp\n  qed\nqed\n\n(* Indexed version of guarded (capturing the idea that starting in a state satisfying P\n * means we are safe for a certain number of steps)\n *)\ndefinition guarded :: \"('syn, 'mstate :: Okay) semc \\<Rightarrow> ('mstate \\<Rightarrow> bool) \\<Rightarrow> nat \\<Rightarrow> 'syn gensyn list \\<Rightarrow> bool\"\n(\"|#_#| {#_, _#} _\" [210, 212, 214, 216])\n where\n\"guarded gs P n c =\n  (\\<forall> m . m \\<in> ok_S \\<longrightarrow> P (payload m) \\<longrightarrow> cont m = Inl c \\<longrightarrow> safe_for gs m n)\"\n\nlemma guardediI [intro] :\n  assumes H : \"\\<And> m . m \\<in> ok_S \\<Longrightarrow> P (payload m) \\<Longrightarrow> cont m = Inl c \\<Longrightarrow> safe_for gs m n\"\n  shows \"guarded gs P n c\" using H\n  unfolding guarded_def\n  by auto\n\nlemma guardediD :\n  assumes H : \"guarded gs P n c\"\n  assumes Hok : \"m \\<in> ok_S\"\n  assumes HP : \"P (payload m)\"\n  assumes Hcont : \"cont m = Inl c\"\n  shows \"safe_for gs m n\" using assms\n  unfolding guarded_def by blast\n\n(* Our indexed Hoare triple. The basic idea here is that we limit the number of steps we are\n * required to be safe for, both on the \"input\" (|gs| {Q, nq} (c')) \n * and the \"output\" (|gs| {P, np} (c @ c')) *)\ndefinition HT :: \"('syn, 'mstate :: Okay) semc \\<Rightarrow> ('mstate \\<Rightarrow> bool) \\<Rightarrow> nat \\<Rightarrow> 'syn gensyn list \\<Rightarrow> ('mstate \\<Rightarrow> bool) \\<Rightarrow> nat \\<Rightarrow> bool\" \n  (\"|#_#| {#-_, _-#} _ {#-_, _-#}\" [220, 222, 224, 226, 228, 230])\n  where\n\"HT gs P np c Q nq =\n  (\\<forall> c' . |#gs#| {#Q, nq#} (c') \\<longrightarrow> |#gs#| {#P, np#} (c @ c'))\"\n\nlemma HTiI [intro] :\n  assumes H : \"\\<And> c' . |#gs#| {#Q, nq#} (c') \\<Longrightarrow> |#gs#| {#P, np#} (c @ c')\"\n  shows \"HT gs P np c Q nq\" using H unfolding HT_def\n  by auto\n\nlemma HTiE [elim]:\n  assumes H : \"HT gs P np c Q nq\"\n  assumes H' : \"|#gs#| {#Q, nq#} c'\"\n  shows \"|#gs#| {#P, np#} (c@c')\" using assms\n  unfolding HT_def\n  by auto\n\nlemma HConseq :\n  assumes H : \"|#gs#| {#- P', np' -#} c {#-Q', nq'-#}\"\n  assumes HP1 : \"\\<And> st . P st \\<Longrightarrow> P' st\"\n  assumes HP2 : \"np \\<le> np'\"\n  assumes HQ1 : \"\\<And> st . Q' st \\<Longrightarrow> Q st\"\n  assumes HQ2 : \"nq' \\<le> nq\"\n  shows \"|#gs#| {#-P, np-#} c {#-Q, nq-#}\"\nproof(rule HTiI)\n  fix c'\n  assume Exec : \"|#gs#| {#Q, nq#} c'\"\n\n  have Exec' : \"|#gs#| {#Q', nq'#} c'\"\n  proof\n    fix m :: \"('a, 'b) control\"\n    assume Ok : \"m \\<in> ok_S\"\n    assume Q' : \"Q' (payload m)\"\n    assume C : \"cont m = Inl c'\"\n\n    have Q : \"Q (payload m)\" using HQ1[OF Q'] by simp\n\n    have Conc' : \"safe_for gs m nq\"\n      using guardediD[OF Exec Ok Q C] by auto\n\n    show \"safe_for gs m nq'\"\n      using safe_for_weaken[OF Conc' HQ2] by auto\n  qed\n\n  then have Exec'' :\"|#gs#| {#P', np'#} (c@c')\"\n    using HTiE[OF H Exec'] by auto\n\n  show \"|#gs#| {#P, np#} (c @ c')\"\n  proof\n    fix m :: \"('a, 'b) control\"\n    assume Ok : \"m \\<in> ok_S\"\n    assume P: \"P (payload m)\"\n    assume C : \"cont m = Inl (c @ c')\"\n\n    have P' : \"P' (payload m)\" using HP1[OF P] by simp\n\n    have Conc' : \"safe_for gs m np'\"\n      using guardediD[OF Exec'' Ok P' C] by auto\n\n    show \"safe_for gs m np\"\n      using safe_for_weaken[OF Conc' HP2] by auto\n  qed\nqed\n\nlemma HCat :\n  assumes H : \"|#gs#| {#- P1, np1 -#} c1 {#- P2, np2 -#}\"\n  assumes H' : \"|#gs#| {#- P2, np2 -#} c2 {#- P3, np3 -#}\"\n  shows \"|#gs#| {#- P1, np1 -#} (c1 @ c2) {#- P3, np3 -#}\"\nproof(rule HTiI)\n  fix c'\n  assume HP3 : \"|#gs#| {#P3, np3#} c'\"\n\n  have P2_cont : \"|#gs#| {#P2, np2#} (c2 @ c')\"\n    using HTiE[OF H' HP3]\n    by auto\n\n  show \"|#gs#| {#P1, np1#} ((c1 @ c2) @ c')\"\n    using HTiE[OF H P2_cont]\n    unfolding append_assoc\n    by auto\nqed\n\n(* Wrapping the indexed Hoare triples to make them work like non-indexed ones.\n * The idea here is that we only care about how long the \"output\" (program combined with\n * the arbitrary tail quantified within the Hoare triple definition) is safe for. So, in order\n * for this to work like a normal Hoare triple, for any desired safe execution length npre,\n * we must be able to find a suffix execution\n * (safe for some npost number of steps) such that the concatenation is safe for npre. *)\ndefinition HT' :: \"('syn, 'mstate :: Okay) semc \\<Rightarrow> ('mstate \\<Rightarrow> bool) \\<Rightarrow> 'syn gensyn list \\<Rightarrow> ('mstate \\<Rightarrow> bool)\\<Rightarrow> bool\" \n  (\"|_| {~_~} _ {~_~}\" [250, 252, 254, 256])  \n  where\n\"HT' gs P c Q =\n  ((\\<forall> npost . \\<exists> npre . |#gs#| {#- P, (npre + npost) -#} c {#- Q, npost -#}))\"\n\nlemma HT'I :\n  assumes H : \"(\\<And> npost. \\<exists> npre . |#gs#| {#- P, (npre + npost) -#} c {#- Q, npost -#})\"\n  shows \"HT' gs P c Q\" using assms unfolding HT'_def by blast\n\nlemma HT'D :\n  assumes H : \"HT' gs P c Q\"\n  shows \"(\\<And> npost . \\<exists> npre . |#gs#| {#- P, (npre + npost) -#} c {#- Q, npost -#})\"\n  using H unfolding HT'_def by simp\n\n(* Consequence and Cat for our wrapped Hoare triple. \n * Rules using the \"wrapped\" indexed Hoare logic HT' will have names starting with Hx.\n *)\n\nlemma HT'Conseq :\n  assumes H : \"|gs| {~ P'~} c {~Q'~}\"\n  assumes HP1 : \"\\<And> st . P st \\<Longrightarrow> P' st\"\n  assumes HQ1 : \"\\<And> st . Q' st \\<Longrightarrow> Q st\"\n  shows \"|gs| {~P~} c {~Q~}\"\nproof(rule HT'I)\n  fix npre\n\n  obtain npre'\n    where Npre' : \"|#gs#| {#-P', (npre' + npre) -#} c {#-Q', npre-#}\"\n    using HT'D[OF H, of npre]\n    by blast\n\n  have \"|#gs#| {#-P, (0 + npre) -#} c {#-Q, npre-#}\"\n    using HConseq[OF Npre', of P npre Q npre] HP1 HQ1\n    by(auto)\n\n  then show \"\\<exists>npre''. |#gs#| {#-P, (npre'' + npre)-#} c {#-Q, npre-#}\"\n    by blast\nqed\n\nlemma HT'Cat :\n  assumes H : \"|gs| {~ P1 ~} c1 {~ P2 ~}\"\n  assumes H' : \"|gs| {~ P2 ~} c2 {~ P3 ~}\"\n  shows \"|gs| {~ P1 ~} (c1 @ c2) {~ P3 ~}\"\nproof(rule HT'I)\n  fix npre\n\n  obtain n1\n    where N1 : \"|#gs#| {#-P1, (n1 + npre)-#} c1 {#-P2, npre-#}\"\n    using HT'D[OF H]\n    by blast\n\n  obtain n2\n    where N2 : \"|#gs#| {#-P2, (n2 + npre)-#} c2 {#-P3, npre-#}\"\n    using HT'D[OF H']\n    by blast\n\n  have N2' : \"|#gs#| {#-P2, (npre)-#} c2 {#-P3, npre-#}\"\n    using HConseq[OF N2, of P2 npre P3 npre] by auto\n\n\n  show \"\\<exists>n3. |#gs#| {#-P1, (n3 + npre)-#} (c1 @ c2) {#-P3, npre-#}\"\n    using HCat[OF N1 N2'] by blast\nqed\n\nlemma HT'Cons :\n  assumes H : \"|gs| {~P1~} [c] {~P2~}\"\n  assumes H' : \"|gs| {~P2~} cs {~P3~}\"\n  shows \"|gs| {~P1~} (c#cs) {~P3~}\"\n  using HT'Cat[OF H H']\n  by auto\n\nlemma HT'D0 :\n  assumes H : \"HT' gs P c Q\"\n  shows \"(\\<And> npost . |#gs#| {#- P, (npost) -#} c {#- Q, npost -#})\"\nproof-\n  fix npost\n\n  obtain npre where Npre : \"|#gs#| {#- P, (npre + npost) -#} c {#- Q, npost -#}\"\n    using HT'D[OF H] by blast\n\n  show \"|#gs#| {#-P, npost-#} c {#-Q, npost-#}\"\n    using HConseq[OF Npre, of P npost Q npost] by auto\nqed\n\nlemma HT'Nil :\n  shows \"|gs| {~P1~} [] {~P1~}\"\nproof(rule HT'I)\n  fix npost\n\n  have \"|#gs#| {#-P1, (npost)-#} [] {#-P1, npost-#}\"\n  proof\n    fix c'\n    assume \"|#gs#| {#P1, npost#} c'\"\n    then show \"|#gs#| {#P1, npost#} ([] @ c')\"\n      by auto\n  qed\n\n  then have \"|#gs#| {#-P1, (0 + npost)-#} [] {#-P1, npost-#}\"\n    by simp\n\n  then show \"\\<exists>npre. |#gs#| {#-P1, (npre + npost)-#} [] {#-P1, npost-#}\"\n    by blast\nqed\n\nend", "meta": {"author": "mmalvarez", "repo": "Gazelle", "sha": "0a80144107b3ec7487725bd88d658843beb6cb82", "save_path": "github-repos/isabelle/mmalvarez-Gazelle", "path": "github-repos/isabelle/mmalvarez-Gazelle/Gazelle-0a80144107b3ec7487725bd88d658843beb6cb82/Hoare/Hoare_Indexed.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6150878555160665, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.29313835555535167}}
{"text": "(*****************************************************************************\n * Featherweight-OCL --- A Formal Semantics for UML-OCL Version OCL 2.5\n *                       for the OMG Standard.\n *                       http://www.brucker.ch/projects/hol-testgen/\n *\n * UML_State.thy --- State Operations and Objects.\n * This file is part of HOL-TestGen.\n *\n * Copyright (c) 2012-2015 Université Paris-Saclay, Univ. Paris-Sud, France\n *               2013-2015 IRT SystemX, France\n *\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are\n * met:\n *\n *     * Redistributions of source code must retain the above copyright\n *       notice, this list of conditions and the following disclaimer.\n *\n *     * Redistributions in binary form must reproduce the above\n *       copyright notice, this list of conditions and the following\n *       disclaimer in the documentation and/or other materials provided\n *       with the distribution.\n *\n *     * Neither the name of the copyright holders nor the names of its\n *       contributors may be used to endorse or promote products derived\n *       from this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n ******************************************************************************)\n\nchapter\\<open>Formalization III:  UML/OCL constructs: State Operations and Objects\\<close>\n\ntheory  UML_State\nimports UML_Library\nbegin\n\nno_notation None (\"\\<bottom>\")\nsection\\<open>Introduction: States over Typed Object Universes\\<close>\n\ntext\\<open>\\label{sec:universe}\n  In the following, we will refine the concepts of a user-defined\n  data-model (implied by a class-diagram) as well as the notion of\n  $\\state{}$ used in the previous section to much more detail.\n  Surprisingly, even without a concrete notion of an objects and a\n  universe of object representation, the generic infrastructure of\n  state-related operations is fairly rich.\n\\<close>\n\n\n\nsubsection\\<open>Fundamental Properties on Objects: Core Referential Equality\\<close>\nsubsubsection\\<open>Definition\\<close>\n\ntext\\<open>Generic referential equality - to be used for instantiations\n with concrete object types ...\\<close>\ndefinition  StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t :: \"('\\<AA>,'a::{object,null})val \\<Rightarrow> ('\\<AA>,'a)val \\<Rightarrow> ('\\<AA>)Boolean\"\nwhere      \"StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t x y\n            \\<equiv> \\<lambda> \\<tau>. if (\\<upsilon> x) \\<tau> = true \\<tau> \\<and> (\\<upsilon> y) \\<tau> = true \\<tau>\n                    then if x \\<tau> = null \\<or> y \\<tau> = null\n                         then \\<lfloor>\\<lfloor>x \\<tau> = null \\<and> y \\<tau> = null\\<rfloor>\\<rfloor>\n                         else \\<lfloor>\\<lfloor>(oid_of (x \\<tau>)) = (oid_of (y \\<tau>)) \\<rfloor>\\<rfloor>\n                    else invalid \\<tau>\"\n\nsubsubsection\\<open>Strictness and context passing\\<close>\n\nlemma StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t_strict1[simp,code_unfold] :\n\"(StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t x invalid) = invalid\"\nby(rule ext, simp add: StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t_def true_def false_def)\n\nlemma StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t_strict2[simp,code_unfold] :\n\"(StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t invalid x) = invalid\"\nby(rule ext, simp add: StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t_def true_def false_def)\n\n\nlemma cp_StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t:\n\"(StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t x y \\<tau>) = (StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t (\\<lambda>_. x \\<tau>) (\\<lambda>_. y \\<tau>)) \\<tau>\"\nby(auto simp: StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t_def cp_valid[symmetric])\n\ntext_raw\\<open>\\isatagafp\\<close>\nlemmas cp0_StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t= cp_StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t[THEN allI[THEN allI[THEN allI[THEN cpI2]],\n             of \"StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t\"]]\n\nlemmas cp_intro''[intro!,simp,code_unfold] =\n       cp_intro''\n       cp_StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t[THEN allI[THEN allI[THEN allI[THEN cpI2]],\n             of \"StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t\"]]\n\ntext_raw\\<open>\\endisatagafp\\<close>\n\nsubsection\\<open>Logic and Algebraic Layer on Object\\<close>\nsubsubsection\\<open>Validity and Definedness Properties\\<close>\n\ntext\\<open>We derive the usual laws on definedness for (generic) object equality:\\<close>\n\n\n\n\nlemma StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t_def_homo :\n\"\\<delta>(StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t x (y::('\\<AA>,'a::{null,object})val)) = ((\\<upsilon> x) and (\\<upsilon> y))\"\noops (* sorry *)\n\nsubsubsection\\<open>Symmetry\\<close>\n\nlemma StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t_sym :\nassumes x_val : \"\\<tau> \\<Turnstile> \\<upsilon> x\"\nshows \"\\<tau> \\<Turnstile> StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t x x\"\nby(simp add: StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t_def true_def OclValid_def\n             x_val[simplified OclValid_def])\n\n\nsubsubsection\\<open>Behavior vs StrongEq\\<close>\n\ntext\\<open>It remains to clarify the role of the state invariant\n$\\inv_\\sigma(\\sigma)$ mentioned above that states the condition that\nthere is a ``one-to-one'' correspondence between object\nrepresentations and $\\oid$'s: $\\forall \\mathit{oid} \\in \\dom\\ap\n\\sigma\\spot oid = \\HolOclOidOf\\ap \\drop{\\sigma(\\mathit{oid})}$.  This\ncondition is also mentioned in~\\cite[Annex A]{omg:ocl:2012} and goes\nback to \\citet{richters:precise:2002}; however, we state this\ncondition as an invariant on states rather than a global axiom. It\ncan, therefore, not be taken for granted that an $\\oid$ makes sense\nboth in pre- and post-states of OCL expressions.\n\\<close>\n\ntext\\<open>We capture this invariant in the predicate WFF :\\<close>\n\ndefinition WFF :: \"('\\<AA>::object)st \\<Rightarrow> bool\"\nwhere \"WFF \\<tau> = ((\\<forall> x \\<in> ran(heap(fst \\<tau>)). \\<lceil>heap(fst \\<tau>) (oid_of x)\\<rceil> = x) \\<and>\n                (\\<forall> x \\<in> ran(heap(snd \\<tau>)). \\<lceil>heap(snd \\<tau>) (oid_of x)\\<rceil> = x))\"\n\ntext\\<open>It turns out that WFF is a key-concept for linking strict referential equality to\nlogical equality: in well-formed states (i.e. those states where the self (oid-of) field contains\nthe pointer to which the object is associated to in the state), referential equality coincides\nwith logical equality.\\<close>\n\n\ntext\\<open>We turn now to the generic definition of referential equality on objects:\nEquality on objects in a state is reduced to equality on the\nreferences to these objects. As in HOL-OCL~\\cite{brucker.ea:hol-ocl:2008,brucker.ea:hol-ocl-book:2006},\nwe will store the reference of an object inside the object in a (ghost) field.\nBy establishing certain invariants (``consistent state''), it can\nbe assured that there is a ``one-to-one-correspondence'' of objects\nto their references---and therefore the definition below\nbehaves as we expect.\\<close>\ntext\\<open>Generic Referential Equality enjoys the usual properties:\n(quasi) reflexivity, symmetry, transitivity, substitutivity for\ndefined values. For type-technical reasons, for each concrete\nobject type, the equality \\<open>\\<doteq>\\<close> is defined by generic referential\nequality.\\<close>\n\ntheorem StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t_vs_StrongEq:\nassumes WFF: \"WFF \\<tau>\"\nand valid_x: \"\\<tau> \\<Turnstile>(\\<upsilon> x)\"\nand valid_y: \"\\<tau> \\<Turnstile>(\\<upsilon> y)\"\nand x_present_pre: \"x \\<tau> \\<in> ran (heap(fst \\<tau>))\"\nand y_present_pre: \"y \\<tau> \\<in> ran (heap(fst \\<tau>))\"\nand x_present_post:\"x \\<tau> \\<in> ran (heap(snd \\<tau>))\"\nand y_present_post:\"y \\<tau> \\<in> ran (heap(snd \\<tau>))\"\n (* x and y must be object representations that exist in either the pre or post state *)\nshows \"(\\<tau> \\<Turnstile> (StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t x y)) = (\\<tau> \\<Turnstile> (x \\<triangleq> y))\"\napply(insert WFF valid_x valid_y x_present_pre y_present_pre x_present_post y_present_post)\napply(auto simp: StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t_def OclValid_def WFF_def StrongEq_def true_def Ball_def)\napply(erule_tac x=\"x \\<tau>\" in allE', simp_all)\ndone\n\ntheorem StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t_vs_StrongEq':\nassumes WFF: \"WFF \\<tau>\"\nand valid_x: \"\\<tau> \\<Turnstile>(\\<upsilon> (x :: ('\\<AA>::object,'\\<alpha>::{null,object})val))\"\nand valid_y: \"\\<tau> \\<Turnstile>(\\<upsilon> y)\"\nand oid_preserve: \"\\<And>x. x \\<in> ran (heap(fst \\<tau>)) \\<or> x \\<in> ran (heap(snd \\<tau>)) \\<Longrightarrow>\n                        H x \\<noteq> \\<bottom> \\<Longrightarrow> oid_of (H x) = oid_of x\"\nand xy_together: \"x \\<tau> \\<in> H ` ran (heap(fst \\<tau>)) \\<and> y \\<tau> \\<in> H ` ran (heap(fst \\<tau>)) \\<or>\n                  x \\<tau> \\<in> H ` ran (heap(snd \\<tau>)) \\<and> y \\<tau> \\<in> H ` ran (heap(snd \\<tau>))\"\n (* x and y must be object representations that exist in either the pre or post state *)\nshows \"(\\<tau> \\<Turnstile> (StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t x y)) = (\\<tau> \\<Turnstile> (x \\<triangleq> y))\"\n apply(insert WFF valid_x valid_y xy_together)\n apply(simp add: WFF_def)\n apply(auto simp: StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t_def OclValid_def WFF_def StrongEq_def true_def Ball_def)\nby (metis foundation18' oid_preserve valid_x valid_y)+\n\ntext\\<open>So, if two object descriptions live in the same state (both pre or post), the referential\nequality on objects implies in a WFF state the logical equality.\\<close>\n\nsection\\<open>Operations on Object\\<close>\nsubsection\\<open>Initial States (for testing and code generation)\\<close>\n\ndefinition \\<tau>\\<^sub>0 :: \"('\\<AA>)st\"\nwhere     \"\\<tau>\\<^sub>0 \\<equiv> (\\<lparr>heap=Map.empty, assocs = Map.empty\\<rparr>,\n                 \\<lparr>heap=Map.empty, assocs = Map.empty\\<rparr>)\"\n\nsubsection\\<open>OclAllInstances\\<close>\n\ntext\\<open>To denote OCL types occurring in OCL expressions syntactically---as, for example,\nas ``argument'' of \\inlineocl{oclAllInstances()}---we use the inverses of the injection functions into the object\nuniverses; we show that this is a sufficient ``characterization.''\\<close>\n\ndefinition OclAllInstances_generic :: \"(('\\<AA>::object) st \\<Rightarrow> '\\<AA> state) \\<Rightarrow> ('\\<AA>::object \\<rightharpoonup> '\\<alpha>) \\<Rightarrow>\n                                       ('\\<AA>, '\\<alpha> option option) Set\"\nwhere \"OclAllInstances_generic fst_snd H =\n                    (\\<lambda>\\<tau>. Abs_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e \\<lfloor>\\<lfloor> Some ` ((H ` ran (heap (fst_snd \\<tau>))) - { None }) \\<rfloor>\\<rfloor>)\"\n\nlemma OclAllInstances_generic_defined: \"\\<tau> \\<Turnstile> \\<delta> (OclAllInstances_generic pre_post H)\"\n apply(simp add: defined_def OclValid_def OclAllInstances_generic_def false_def true_def\n                 bot_fun_def bot_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e_def null_fun_def null_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e_def)\n apply(rule conjI)\n apply(rule notI, subst (asm) Abs_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e_inject, simp,\n       (rule disjI2)+,\n       metis bot_option_def option.distinct(1),\n       (simp add: bot_option_def null_option_def)+)+\ndone\n\nlemma OclAllInstances_generic_init_empty:\n assumes [simp]: \"\\<And>x. pre_post (x, x) = x\"\n shows \"\\<tau>\\<^sub>0 \\<Turnstile> OclAllInstances_generic pre_post H \\<triangleq> Set{}\"\nby(simp add: StrongEq_def OclAllInstances_generic_def OclValid_def \\<tau>\\<^sub>0_def mtSet_def)\n\n\n\n\nlemma represented_generic_objects_defined:\nassumes A: \"\\<tau> \\<Turnstile> ((OclAllInstances_generic pre_post (H::('\\<AA>::object \\<rightharpoonup> '\\<alpha>))) ->includes\\<^sub>S\\<^sub>e\\<^sub>t(x))\"\nshows      \"\\<tau> \\<Turnstile> \\<delta> (OclAllInstances_generic pre_post H) \\<and> \\<tau> \\<Turnstile> \\<delta> x\"\nby (metis OclAllInstances_generic_defined\n          A[THEN represented_generic_objects_nonnull] OclIncludes.defined_args_valid\n          A foundation16' foundation18 foundation24 foundation6)\n\n\ntext\\<open>One way to establish the actual presence of an object representation in a state is:\\<close>\n\ndefinition \"is_represented_in_state fst_snd x H \\<tau> = (x \\<tau> \\<in> (Some o H) ` ran (heap (fst_snd \\<tau>)))\"\n\nlemma represented_generic_objects_in_state:\nassumes A: \"\\<tau> \\<Turnstile> (OclAllInstances_generic pre_post H)->includes\\<^sub>S\\<^sub>e\\<^sub>t(x)\"\nshows      \"is_represented_in_state pre_post x H \\<tau>\"\nproof -\n   have B: \"(\\<delta> (OclAllInstances_generic pre_post H)) \\<tau> = true \\<tau>\"\n           by(simp add: OclValid_def[symmetric] OclAllInstances_generic_defined)\n   have C: \"(\\<upsilon> x) \\<tau> = true \\<tau>\"\n           by (metis OclValid_def UML_Set.OclIncludes_def assms bot_option_def option.distinct(1) true_def)\n   have F: \"Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (Abs_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e \\<lfloor>\\<lfloor>Some ` (H ` ran (heap (pre_post \\<tau>)) - {None})\\<rfloor>\\<rfloor>) =\n            \\<lfloor>\\<lfloor>Some ` (H ` ran (heap (pre_post \\<tau>)) - {None})\\<rfloor>\\<rfloor>\"\n           by(subst Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e.Abs_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e_inverse,simp_all add: bot_option_def)\n   show ?thesis\n    apply(insert A)\n    apply(simp add: is_represented_in_state_def OclIncludes_def OclValid_def ran_def B C image_def true_def)\n    apply(simp add: OclAllInstances_generic_def)\n    apply(simp add: F)\n    apply(simp add: ran_def)\n   by(fastforce)\nqed\n\n\nlemma state_update_vs_allInstances_generic_empty:\nassumes [simp]: \"\\<And>a. pre_post (mk a) = a\"\nshows   \"(mk \\<lparr>heap=Map.empty, assocs=A\\<rparr>) \\<Turnstile> OclAllInstances_generic pre_post Type \\<doteq> Set{}\"\nproof -\n have state_update_vs_allInstances_empty:\n  \"(OclAllInstances_generic pre_post Type) (mk \\<lparr>heap=Map.empty, assocs=A\\<rparr>) =\n   Set{} (mk \\<lparr>heap=Map.empty, assocs=A\\<rparr>)\"\n by(simp add: OclAllInstances_generic_def mtSet_def)\n show ?thesis\n  apply(simp only: OclValid_def, subst StrictRefEq\\<^sub>S\\<^sub>e\\<^sub>t.cp0,\n        simp only: state_update_vs_allInstances_empty StrictRefEq\\<^sub>S\\<^sub>e\\<^sub>t.refl_ext)\n  apply(simp add: OclIf_def valid_def mtSet_def defined_def\n                  bot_fun_def null_fun_def null_option_def bot_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e_def)\n by(subst Abs_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e_inject, (simp add: bot_option_def true_def)+)\nqed\n\ntext\\<open>Here comes a couple of operational rules that allow to infer the value\nof \\inlineisar+oclAllInstances+ from the context $\\tau$. These rules are a special-case\nin the sense that they are the only rules that relate statements with \\emph{different}\n$\\tau$'s. For that reason, new concepts like ``constant contexts P'' are necessary\n(for which we do not elaborate an own theory for reasons of space limitations;\n in examples, we will prove resulting constraints straight forward by hand).\\<close>\n\n\nlemma state_update_vs_allInstances_generic_including':\nassumes [simp]: \"\\<And>a. pre_post (mk a) = a\"\nassumes \"\\<And>x. \\<sigma>' oid = Some x \\<Longrightarrow> x = Object\"\n    and \"Type Object \\<noteq> None\"\n  shows \"(OclAllInstances_generic pre_post Type)\n         (mk \\<lparr>heap=\\<sigma>'(oid\\<mapsto>Object), assocs=A\\<rparr>)\n         =\n         ((OclAllInstances_generic pre_post Type)->including\\<^sub>S\\<^sub>e\\<^sub>t(\\<lambda> _. \\<lfloor>\\<lfloor> drop (Type Object) \\<rfloor>\\<rfloor>))\n         (mk \\<lparr>heap=\\<sigma>',assocs=A\\<rparr>)\"\nproof -\n have drop_none : \"\\<And>x. x \\<noteq> None \\<Longrightarrow> \\<lfloor>\\<lceil>x\\<rceil>\\<rfloor> = x\"\n by(case_tac x, simp+)\n\n have insert_diff : \"\\<And>x S. insert \\<lfloor>x\\<rfloor> (S - {None}) = (insert \\<lfloor>x\\<rfloor> S) - {None}\"\n by (metis insert_Diff_if option.distinct(1) singletonE)\n\n show ?thesis\n  apply(simp add: UML_Set.OclIncluding_def OclAllInstances_generic_defined[simplified OclValid_def],\n        simp add: OclAllInstances_generic_def)\n  apply(subst Abs_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e_inverse, simp add: bot_option_def, simp add: comp_def,\n        subst image_insert[symmetric],\n        subst drop_none, simp add: assms)\n  apply(case_tac \"Type Object\", simp add: assms, simp only:,\n        subst insert_diff, drule sym, simp)\n  apply(subgoal_tac \"ran (\\<sigma>'(oid \\<mapsto> Object)) = insert Object (ran \\<sigma>')\", simp)\n  apply(case_tac \"\\<not> (\\<exists>x. \\<sigma>' oid = Some x)\")\n   apply(rule ran_map_upd, simp)\n  apply(simp, erule exE, frule assms, simp)\n  apply(subgoal_tac \"Object \\<in> ran \\<sigma>'\") prefer 2\n   apply(rule ranI, simp)\n by(subst insert_absorb, simp, metis fun_upd_apply)\n\nqed\n\n\nlemma state_update_vs_allInstances_generic_including:\nassumes [simp]: \"\\<And>a. pre_post (mk a) = a\"\nassumes \"\\<And>x. \\<sigma>' oid = Some x \\<Longrightarrow> x = Object\"\n    and \"Type Object \\<noteq> None\"\nshows   \"(OclAllInstances_generic pre_post Type)\n         (mk \\<lparr>heap=\\<sigma>'(oid\\<mapsto>Object), assocs=A\\<rparr>)\n         =\n         ((\\<lambda>_. (OclAllInstances_generic pre_post Type)\n                 (mk \\<lparr>heap=\\<sigma>', assocs=A\\<rparr>))->including\\<^sub>S\\<^sub>e\\<^sub>t(\\<lambda> _. \\<lfloor>\\<lfloor> drop (Type Object) \\<rfloor>\\<rfloor>))\n         (mk \\<lparr>heap=\\<sigma>'(oid\\<mapsto>Object), assocs=A\\<rparr>)\"\n apply(subst state_update_vs_allInstances_generic_including', (simp add: assms)+,\n       subst UML_Set.OclIncluding.cp0,\n       simp add: UML_Set.OclIncluding_def)\n apply(subst (1 3) cp_defined[symmetric],\n       simp add: OclAllInstances_generic_defined[simplified OclValid_def])\n\n apply(simp add: defined_def OclValid_def OclAllInstances_generic_def invalid_def\n                 bot_fun_def null_fun_def bot_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e_def null_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e_def)\n apply(subst (1 3) Abs_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e_inject)\nby(simp add: bot_option_def null_option_def)+\n\n\n\nlemma state_update_vs_allInstances_generic_noincluding':\nassumes [simp]: \"\\<And>a. pre_post (mk a) = a\"\nassumes \"\\<And>x. \\<sigma>' oid = Some x \\<Longrightarrow> x = Object\"\n    and \"Type Object = None\"\n  shows \"(OclAllInstances_generic pre_post Type)\n         (mk \\<lparr>heap=\\<sigma>'(oid\\<mapsto>Object), assocs=A\\<rparr>)\n         =\n         (OclAllInstances_generic pre_post Type)\n         (mk \\<lparr>heap=\\<sigma>', assocs=A\\<rparr>)\"\nproof -\n have drop_none : \"\\<And>x. x \\<noteq> None \\<Longrightarrow> \\<lfloor>\\<lceil>x\\<rceil>\\<rfloor> = x\"\n by(case_tac x, simp+)\n\n have insert_diff : \"\\<And>x S. insert \\<lfloor>x\\<rfloor> (S - {None}) = (insert \\<lfloor>x\\<rfloor> S) - {None}\"\n by (metis insert_Diff_if option.distinct(1) singletonE)\n\n show ?thesis\n  apply(simp add: OclIncluding_def OclAllInstances_generic_defined[simplified OclValid_def]\n                  OclAllInstances_generic_def)\n  apply(subgoal_tac \"ran (\\<sigma>'(oid \\<mapsto> Object)) = insert Object (ran \\<sigma>')\", simp add: assms)\n  apply(case_tac \"\\<not> (\\<exists>x. \\<sigma>' oid = Some x)\")\n   apply(rule ran_map_upd, simp)\n  apply(simp, erule exE, frule assms, simp)\n  apply(subgoal_tac \"Object \\<in> ran \\<sigma>'\") prefer 2\n   apply(rule ranI, simp)\n  apply(subst insert_absorb, simp)\n by (metis fun_upd_apply)\nqed\n\ntheorem state_update_vs_allInstances_generic_ntc:\nassumes [simp]: \"\\<And>a. pre_post (mk a) = a\"\nassumes oid_def:   \"oid\\<notin>dom \\<sigma>'\"\nand  non_type_conform: \"Type Object = None \"\nand  cp_ctxt:      \"cp P\"\nand  const_ctxt:   \"\\<And>X. const X \\<Longrightarrow> const (P X)\"\nshows \"(mk \\<lparr>heap=\\<sigma>'(oid\\<mapsto>Object),assocs=A\\<rparr> \\<Turnstile> P (OclAllInstances_generic pre_post Type)) =\n       (mk \\<lparr>heap=\\<sigma>', assocs=A\\<rparr>            \\<Turnstile> P (OclAllInstances_generic pre_post Type))\"\n      (is \"(?\\<tau> \\<Turnstile> P ?\\<phi>) = (?\\<tau>' \\<Turnstile> P ?\\<phi>)\")\nproof -\n have P_cp  : \"\\<And>x \\<tau>. P x \\<tau> = P (\\<lambda>_. x \\<tau>) \\<tau>\"\n             by (metis (full_types) cp_ctxt cp_def)\n have A     : \"const (P (\\<lambda>_. ?\\<phi> ?\\<tau>))\"\n             by(simp add: const_ctxt const_ss)\n have       \"(?\\<tau> \\<Turnstile> P ?\\<phi>) = (?\\<tau> \\<Turnstile> \\<lambda>_. P ?\\<phi> ?\\<tau>)\"\n             by(subst foundation23, rule refl)\n also have  \"... = (?\\<tau> \\<Turnstile> \\<lambda>_. P (\\<lambda>_. ?\\<phi> ?\\<tau>)  ?\\<tau>)\"\n             by(subst P_cp, rule refl)\n also have  \"... = (?\\<tau>' \\<Turnstile> \\<lambda>_. P (\\<lambda>_. ?\\<phi> ?\\<tau>)  ?\\<tau>')\"\n             apply(simp add: OclValid_def)\n             by(subst A[simplified const_def], subst const_true[simplified const_def], simp)\n finally have X: \"(?\\<tau> \\<Turnstile> P ?\\<phi>) = (?\\<tau>' \\<Turnstile> \\<lambda>_. P (\\<lambda>_. ?\\<phi> ?\\<tau>)  ?\\<tau>')\"\n             by simp\n show ?thesis\n apply(subst X) apply(subst foundation23[symmetric])\n apply(rule StrongEq_L_subst3[OF cp_ctxt])\n apply(simp add: OclValid_def StrongEq_def true_def)\n apply(rule state_update_vs_allInstances_generic_noincluding')\n by(insert oid_def, auto simp: non_type_conform)\nqed\n\ntheorem state_update_vs_allInstances_generic_tc:\nassumes [simp]: \"\\<And>a. pre_post (mk a) = a\"\nassumes oid_def:   \"oid\\<notin>dom \\<sigma>'\"\nand  type_conform: \"Type Object \\<noteq> None \"\nand  cp_ctxt:      \"cp P\"\nand  const_ctxt:   \"\\<And>X. const X \\<Longrightarrow> const (P X)\"\nshows \"(mk \\<lparr>heap=\\<sigma>'(oid\\<mapsto>Object),assocs=A\\<rparr> \\<Turnstile> P (OclAllInstances_generic pre_post Type)) =\n       (mk \\<lparr>heap=\\<sigma>', assocs=A\\<rparr>            \\<Turnstile> P ((OclAllInstances_generic pre_post Type)\n                                                                ->including\\<^sub>S\\<^sub>e\\<^sub>t(\\<lambda> _. \\<lfloor>(Type Object)\\<rfloor>)))\"\n       (is \"(?\\<tau> \\<Turnstile> P ?\\<phi>) = (?\\<tau>' \\<Turnstile> P ?\\<phi>')\")\nproof -\n have P_cp  : \"\\<And>x \\<tau>. P x \\<tau> = P (\\<lambda>_. x \\<tau>) \\<tau>\"\n             by (metis (full_types) cp_ctxt cp_def)\n have A     : \"const (P (\\<lambda>_. ?\\<phi> ?\\<tau>))\"\n             by(simp add: const_ctxt const_ss)\n have       \"(?\\<tau> \\<Turnstile> P ?\\<phi>) = (?\\<tau> \\<Turnstile> \\<lambda>_. P ?\\<phi> ?\\<tau>)\"\n             by(subst foundation23, rule refl)\n also have  \"... = (?\\<tau> \\<Turnstile> \\<lambda>_. P (\\<lambda>_. ?\\<phi> ?\\<tau>)  ?\\<tau>)\"\n             by(subst P_cp, rule refl)\n also have  \"... = (?\\<tau>' \\<Turnstile> \\<lambda>_. P (\\<lambda>_. ?\\<phi> ?\\<tau>)  ?\\<tau>')\"\n             apply(simp add: OclValid_def)\n             by(subst A[simplified const_def], subst const_true[simplified const_def], simp)\n finally have X: \"(?\\<tau> \\<Turnstile> P ?\\<phi>) = (?\\<tau>' \\<Turnstile> \\<lambda>_. P (\\<lambda>_. ?\\<phi> ?\\<tau>)  ?\\<tau>')\"\n             by simp\n let         ?allInstances = \"OclAllInstances_generic pre_post Type\"\n have        \"?allInstances ?\\<tau> = \\<lambda>_. ?allInstances ?\\<tau>'->including\\<^sub>S\\<^sub>e\\<^sub>t(\\<lambda>_.\\<lfloor>\\<lfloor>\\<lceil>Type Object\\<rceil>\\<rfloor>\\<rfloor>) ?\\<tau>\"\n             apply(rule state_update_vs_allInstances_generic_including)\n             by(insert oid_def, auto simp: type_conform)\n also have   \"... = ((\\<lambda>_. ?allInstances ?\\<tau>')->including\\<^sub>S\\<^sub>e\\<^sub>t(\\<lambda>_. (\\<lambda>_.\\<lfloor>\\<lfloor>\\<lceil>Type Object\\<rceil>\\<rfloor>\\<rfloor>) ?\\<tau>') ?\\<tau>')\"\n             by(subst const_OclIncluding[simplified const_def], simp+)\n also have   \"... = (?allInstances->including\\<^sub>S\\<^sub>e\\<^sub>t(\\<lambda> _. \\<lfloor>Type Object\\<rfloor>) ?\\<tau>')\"\n             apply(subst UML_Set.OclIncluding.cp0[symmetric])\n             by(insert type_conform, auto)\n finally have Y : \"?allInstances ?\\<tau> = (?allInstances->including\\<^sub>S\\<^sub>e\\<^sub>t(\\<lambda> _. \\<lfloor>Type Object\\<rfloor>) ?\\<tau>')\"\n             by auto\n show ?thesis\n      apply(subst X) apply(subst foundation23[symmetric])\n      apply(rule StrongEq_L_subst3[OF cp_ctxt])\n      apply(simp add: OclValid_def StrongEq_def Y true_def)\n done\nqed\n\ndeclare OclAllInstances_generic_def [simp]\n\nsubsubsection\\<open>OclAllInstances (@post)\\<close>\n\ndefinition OclAllInstances_at_post :: \"('\\<AA> :: object \\<rightharpoonup> '\\<alpha>) \\<Rightarrow> ('\\<AA>, '\\<alpha> option option) Set\"\n                           (\"_ .allInstances'(')\")\nwhere  \"OclAllInstances_at_post =  OclAllInstances_generic snd\"\n\nlemma OclAllInstances_at_post_defined: \"\\<tau> \\<Turnstile> \\<delta> (H .allInstances())\"\nunfolding OclAllInstances_at_post_def\nby(rule OclAllInstances_generic_defined)\n\nlemma \"\\<tau>\\<^sub>0 \\<Turnstile> H .allInstances() \\<triangleq> Set{}\"\nunfolding OclAllInstances_at_post_def\nby(rule OclAllInstances_generic_init_empty, simp)\n\n\nlemma represented_at_post_objects_nonnull:\nassumes A: \"\\<tau> \\<Turnstile> (((H::('\\<AA>::object \\<rightharpoonup> '\\<alpha>)).allInstances()) ->includes\\<^sub>S\\<^sub>e\\<^sub>t(x))\"\nshows      \"\\<tau> \\<Turnstile> not(x \\<triangleq> null)\"\nby(rule represented_generic_objects_nonnull[OF A[simplified OclAllInstances_at_post_def]])\n\n\nlemma represented_at_post_objects_defined:\nassumes A: \"\\<tau> \\<Turnstile> (((H::('\\<AA>::object \\<rightharpoonup> '\\<alpha>)).allInstances()) ->includes\\<^sub>S\\<^sub>e\\<^sub>t(x))\"\nshows      \"\\<tau> \\<Turnstile> \\<delta> (H .allInstances()) \\<and> \\<tau> \\<Turnstile> \\<delta> x\"\nunfolding OclAllInstances_at_post_def\nby(rule represented_generic_objects_defined[OF A[simplified OclAllInstances_at_post_def]])\n\n\ntext\\<open>One way to establish the actual presence of an object representation in a state is:\\<close>\n\nlemma\nassumes A: \"\\<tau> \\<Turnstile> H .allInstances()->includes\\<^sub>S\\<^sub>e\\<^sub>t(x)\"\nshows      \"is_represented_in_state snd x H \\<tau>\"\nby(rule represented_generic_objects_in_state[OF A[simplified OclAllInstances_at_post_def]])\n\nlemma state_update_vs_allInstances_at_post_empty:\nshows   \"(\\<sigma>, \\<lparr>heap=Map.empty, assocs=A\\<rparr>) \\<Turnstile> Type .allInstances() \\<doteq> Set{}\"\nunfolding OclAllInstances_at_post_def\nby(rule state_update_vs_allInstances_generic_empty[OF snd_conv])\n\ntext\\<open>Here comes a couple of operational rules that allow to infer the value\nof \\inlineisar+oclAllInstances+ from the context $\\tau$. These rules are a special-case\nin the sense that they are the only rules that relate statements with \\emph{different}\n$\\tau$'s. For that reason, new concepts like ``constant contexts P'' are necessary\n(for which we do not elaborate an own theory for reasons of space limitations;\n in examples, we will prove resulting constraints straight forward by hand).\\<close>\n\n\nlemma state_update_vs_allInstances_at_post_including':\nassumes \"\\<And>x. \\<sigma>' oid = Some x \\<Longrightarrow> x = Object\"\n    and \"Type Object \\<noteq> None\"\n  shows \"(Type .allInstances())\n         (\\<sigma>, \\<lparr>heap=\\<sigma>'(oid\\<mapsto>Object), assocs=A\\<rparr>)\n         =\n         ((Type .allInstances())->including\\<^sub>S\\<^sub>e\\<^sub>t(\\<lambda> _. \\<lfloor>\\<lfloor> drop (Type Object) \\<rfloor>\\<rfloor>))\n         (\\<sigma>, \\<lparr>heap=\\<sigma>',assocs=A\\<rparr>)\"\nunfolding OclAllInstances_at_post_def\nby(rule state_update_vs_allInstances_generic_including'[OF snd_conv], insert assms)\n\n\nlemma state_update_vs_allInstances_at_post_including:\nassumes \"\\<And>x. \\<sigma>' oid = Some x \\<Longrightarrow> x = Object\"\n    and \"Type Object \\<noteq> None\"\nshows   \"(Type .allInstances())\n         (\\<sigma>, \\<lparr>heap=\\<sigma>'(oid\\<mapsto>Object), assocs=A\\<rparr>)\n         =\n         ((\\<lambda>_. (Type .allInstances())\n                 (\\<sigma>, \\<lparr>heap=\\<sigma>', assocs=A\\<rparr>))->including\\<^sub>S\\<^sub>e\\<^sub>t(\\<lambda> _. \\<lfloor>\\<lfloor> drop (Type Object) \\<rfloor>\\<rfloor>))\n         (\\<sigma>, \\<lparr>heap=\\<sigma>'(oid\\<mapsto>Object), assocs=A\\<rparr>)\"\nunfolding OclAllInstances_at_post_def\nby(rule state_update_vs_allInstances_generic_including[OF snd_conv], insert assms)\n\n\n\nlemma state_update_vs_allInstances_at_post_noincluding':\nassumes \"\\<And>x. \\<sigma>' oid = Some x \\<Longrightarrow> x = Object\"\n    and \"Type Object = None\"\n  shows \"(Type .allInstances())\n         (\\<sigma>, \\<lparr>heap=\\<sigma>'(oid\\<mapsto>Object), assocs=A\\<rparr>)\n         =\n         (Type .allInstances())\n         (\\<sigma>, \\<lparr>heap=\\<sigma>', assocs=A\\<rparr>)\"\nunfolding OclAllInstances_at_post_def\nby(rule state_update_vs_allInstances_generic_noincluding'[OF snd_conv], insert assms)\n\ntheorem state_update_vs_allInstances_at_post_ntc:\nassumes oid_def:   \"oid\\<notin>dom \\<sigma>'\"\nand  non_type_conform: \"Type Object = None \"\nand  cp_ctxt:      \"cp P\"\nand  const_ctxt:   \"\\<And>X. const X \\<Longrightarrow> const (P X)\"\nshows   \"((\\<sigma>, \\<lparr>heap=\\<sigma>'(oid\\<mapsto>Object),assocs=A\\<rparr>) \\<Turnstile> (P(Type .allInstances()))) =\n         ((\\<sigma>, \\<lparr>heap=\\<sigma>', assocs=A\\<rparr>)            \\<Turnstile> (P(Type .allInstances())))\"\nunfolding OclAllInstances_at_post_def\nby(rule state_update_vs_allInstances_generic_ntc[OF snd_conv], insert assms)\n\ntheorem state_update_vs_allInstances_at_post_tc:\nassumes oid_def:   \"oid\\<notin>dom \\<sigma>'\"\nand  type_conform: \"Type Object \\<noteq> None \"\nand  cp_ctxt:      \"cp P\"\nand  const_ctxt:   \"\\<And>X. const X \\<Longrightarrow> const (P X)\"\nshows   \"((\\<sigma>, \\<lparr>heap=\\<sigma>'(oid\\<mapsto>Object),assocs=A\\<rparr>) \\<Turnstile> (P(Type .allInstances()))) =\n         ((\\<sigma>, \\<lparr>heap=\\<sigma>', assocs=A\\<rparr>)            \\<Turnstile> (P((Type .allInstances())\n                                                               ->including\\<^sub>S\\<^sub>e\\<^sub>t(\\<lambda> _. \\<lfloor>(Type Object)\\<rfloor>))))\"\nunfolding OclAllInstances_at_post_def\nby(rule state_update_vs_allInstances_generic_tc[OF snd_conv], insert assms)\n\nsubsubsection\\<open>OclAllInstances (@pre)\\<close>\n\ndefinition OclAllInstances_at_pre :: \"('\\<AA> :: object \\<rightharpoonup> '\\<alpha>) \\<Rightarrow> ('\\<AA>, '\\<alpha> option option) Set\"\n                           (\"_ .allInstances@pre'(')\")\nwhere  \"OclAllInstances_at_pre = OclAllInstances_generic fst\"\n\nlemma OclAllInstances_at_pre_defined: \"\\<tau> \\<Turnstile> \\<delta> (H .allInstances@pre())\"\nunfolding OclAllInstances_at_pre_def\nby(rule OclAllInstances_generic_defined)\n\nlemma \"\\<tau>\\<^sub>0 \\<Turnstile> H .allInstances@pre() \\<triangleq> Set{}\"\nunfolding OclAllInstances_at_pre_def\nby(rule OclAllInstances_generic_init_empty, simp)\n\n\nlemma represented_at_pre_objects_nonnull:\nassumes A: \"\\<tau> \\<Turnstile> (((H::('\\<AA>::object \\<rightharpoonup> '\\<alpha>)).allInstances@pre()) ->includes\\<^sub>S\\<^sub>e\\<^sub>t(x))\"\nshows      \"\\<tau> \\<Turnstile> not(x \\<triangleq> null)\"\nby(rule represented_generic_objects_nonnull[OF A[simplified OclAllInstances_at_pre_def]])\n\nlemma represented_at_pre_objects_defined:\nassumes A: \"\\<tau> \\<Turnstile> (((H::('\\<AA>::object \\<rightharpoonup> '\\<alpha>)).allInstances@pre()) ->includes\\<^sub>S\\<^sub>e\\<^sub>t(x))\"\nshows      \"\\<tau> \\<Turnstile> \\<delta> (H .allInstances@pre()) \\<and> \\<tau> \\<Turnstile> \\<delta> x\"\nunfolding OclAllInstances_at_pre_def\nby(rule represented_generic_objects_defined[OF A[simplified OclAllInstances_at_pre_def]])\n\n\ntext\\<open>One way to establish the actual presence of an object representation in a state is:\\<close>\n\nlemma\nassumes A: \"\\<tau> \\<Turnstile> H .allInstances@pre()->includes\\<^sub>S\\<^sub>e\\<^sub>t(x)\"\nshows      \"is_represented_in_state fst x H \\<tau>\"\nby(rule represented_generic_objects_in_state[OF A[simplified OclAllInstances_at_pre_def]])\n\n\nlemma state_update_vs_allInstances_at_pre_empty:\nshows   \"(\\<lparr>heap=Map.empty, assocs=A\\<rparr>, \\<sigma>) \\<Turnstile> Type .allInstances@pre() \\<doteq> Set{}\"\nunfolding OclAllInstances_at_pre_def\nby(rule state_update_vs_allInstances_generic_empty[OF fst_conv])\n\ntext\\<open>Here comes a couple of operational rules that allow to infer the value\nof \\inlineisar+oclAllInstances@pre+ from the context $\\tau$. These rules are a special-case\nin the sense that they are the only rules that relate statements with \\emph{different}\n$\\tau$'s. For that reason, new concepts like ``constant contexts P'' are necessary\n(for which we do not elaborate an own theory for reasons of space limitations;\n in examples, we will prove resulting constraints straight forward by hand).\\<close>\n\n\nlemma state_update_vs_allInstances_at_pre_including':\nassumes \"\\<And>x. \\<sigma>' oid = Some x \\<Longrightarrow> x = Object\"\n    and \"Type Object \\<noteq> None\"\n  shows \"(Type .allInstances@pre())\n         (\\<lparr>heap=\\<sigma>'(oid\\<mapsto>Object), assocs=A\\<rparr>, \\<sigma>)\n         =\n         ((Type .allInstances@pre())->including\\<^sub>S\\<^sub>e\\<^sub>t(\\<lambda> _. \\<lfloor>\\<lfloor> drop (Type Object) \\<rfloor>\\<rfloor>))\n         (\\<lparr>heap=\\<sigma>',assocs=A\\<rparr>, \\<sigma>)\"\nunfolding OclAllInstances_at_pre_def\nby(rule state_update_vs_allInstances_generic_including'[OF fst_conv], insert assms)\n\n\nlemma state_update_vs_allInstances_at_pre_including:\nassumes \"\\<And>x. \\<sigma>' oid = Some x \\<Longrightarrow> x = Object\"\n    and \"Type Object \\<noteq> None\"\nshows   \"(Type .allInstances@pre())\n         (\\<lparr>heap=\\<sigma>'(oid\\<mapsto>Object), assocs=A\\<rparr>, \\<sigma>)\n         =\n         ((\\<lambda>_. (Type .allInstances@pre())\n                 (\\<lparr>heap=\\<sigma>', assocs=A\\<rparr>, \\<sigma>))->including\\<^sub>S\\<^sub>e\\<^sub>t(\\<lambda> _. \\<lfloor>\\<lfloor> drop (Type Object) \\<rfloor>\\<rfloor>))\n         (\\<lparr>heap=\\<sigma>'(oid\\<mapsto>Object), assocs=A\\<rparr>, \\<sigma>)\"\nunfolding OclAllInstances_at_pre_def\nby(rule state_update_vs_allInstances_generic_including[OF fst_conv], insert assms)\n\n\n\nlemma state_update_vs_allInstances_at_pre_noincluding':\nassumes \"\\<And>x. \\<sigma>' oid = Some x \\<Longrightarrow> x = Object\"\n    and \"Type Object = None\"\n  shows \"(Type .allInstances@pre())\n         (\\<lparr>heap=\\<sigma>'(oid\\<mapsto>Object), assocs=A\\<rparr>, \\<sigma>)\n         =\n         (Type .allInstances@pre())\n         (\\<lparr>heap=\\<sigma>', assocs=A\\<rparr>, \\<sigma>)\"\nunfolding OclAllInstances_at_pre_def\nby(rule state_update_vs_allInstances_generic_noincluding'[OF fst_conv], insert assms)\n\ntheorem state_update_vs_allInstances_at_pre_ntc:\nassumes oid_def:   \"oid\\<notin>dom \\<sigma>'\"\nand  non_type_conform: \"Type Object = None \"\nand  cp_ctxt:      \"cp P\"\nand  const_ctxt:   \"\\<And>X. const X \\<Longrightarrow> const (P X)\"\nshows   \"((\\<lparr>heap=\\<sigma>'(oid\\<mapsto>Object),assocs=A\\<rparr>, \\<sigma>) \\<Turnstile> (P(Type .allInstances@pre()))) =\n         ((\\<lparr>heap=\\<sigma>', assocs=A\\<rparr>, \\<sigma>)            \\<Turnstile> (P(Type .allInstances@pre())))\"\nunfolding OclAllInstances_at_pre_def\nby(rule state_update_vs_allInstances_generic_ntc[OF fst_conv], insert assms)\n\ntheorem state_update_vs_allInstances_at_pre_tc:\nassumes oid_def:   \"oid\\<notin>dom \\<sigma>'\"\nand  type_conform: \"Type Object \\<noteq> None \"\nand  cp_ctxt:      \"cp P\"\nand  const_ctxt:   \"\\<And>X. const X \\<Longrightarrow> const (P X)\"\nshows   \"((\\<lparr>heap=\\<sigma>'(oid\\<mapsto>Object),assocs=A\\<rparr>, \\<sigma>) \\<Turnstile> (P(Type .allInstances@pre()))) =\n         ((\\<lparr>heap=\\<sigma>', assocs=A\\<rparr>, \\<sigma>)            \\<Turnstile> (P((Type .allInstances@pre())\n                                                               ->including\\<^sub>S\\<^sub>e\\<^sub>t(\\<lambda> _. \\<lfloor>(Type Object)\\<rfloor>))))\"\nunfolding OclAllInstances_at_pre_def\nby(rule state_update_vs_allInstances_generic_tc[OF fst_conv], insert assms)\n\nsubsubsection\\<open>@post or @pre\\<close>\n\ntheorem StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t_vs_StrongEq'':\nassumes WFF: \"WFF \\<tau>\"\nand valid_x: \"\\<tau> \\<Turnstile>(\\<upsilon> (x :: ('\\<AA>::object,'\\<alpha>::object option option)val))\"\nand valid_y: \"\\<tau> \\<Turnstile>(\\<upsilon> y)\"\nand oid_preserve: \"\\<And>x. x \\<in> ran (heap(fst \\<tau>)) \\<or> x \\<in> ran (heap(snd \\<tau>)) \\<Longrightarrow>\n                        oid_of (H x) = oid_of x\"\nand xy_together: \"\\<tau> \\<Turnstile> ((H .allInstances()->includes\\<^sub>S\\<^sub>e\\<^sub>t(x) and H .allInstances()->includes\\<^sub>S\\<^sub>e\\<^sub>t(y)) or\n                       (H .allInstances@pre()->includes\\<^sub>S\\<^sub>e\\<^sub>t(x) and H .allInstances@pre()->includes\\<^sub>S\\<^sub>e\\<^sub>t(y)))\"\n (* x and y must be object representations that exist in either the pre or post state *)\nshows \"(\\<tau> \\<Turnstile> (StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t x y)) = (\\<tau> \\<Turnstile> (x \\<triangleq> y))\"\nproof -\n   have at_post_def : \"\\<And>x. \\<tau> \\<Turnstile> \\<upsilon> x \\<Longrightarrow> \\<tau> \\<Turnstile> \\<delta> (H .allInstances()->includes\\<^sub>S\\<^sub>e\\<^sub>t(x))\"\n    apply(simp add: OclIncludes_def OclValid_def\n                    OclAllInstances_at_post_defined[simplified OclValid_def])\n   by(subst cp_defined, simp)\n   have at_pre_def : \"\\<And>x. \\<tau> \\<Turnstile> \\<upsilon> x \\<Longrightarrow> \\<tau> \\<Turnstile> \\<delta> (H .allInstances@pre()->includes\\<^sub>S\\<^sub>e\\<^sub>t(x))\"\n    apply(simp add: OclIncludes_def OclValid_def\n                    OclAllInstances_at_pre_defined[simplified OclValid_def])\n   by(subst cp_defined, simp)\n   have F: \"Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (Abs_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e \\<lfloor>\\<lfloor>Some ` (H ` ran (heap (fst \\<tau>)) - {None})\\<rfloor>\\<rfloor>) =\n            \\<lfloor>\\<lfloor>Some ` (H ` ran (heap (fst \\<tau>)) - {None})\\<rfloor>\\<rfloor>\"\n           by(subst Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e.Abs_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e_inverse,simp_all add: bot_option_def)\n   have F': \"Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (Abs_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e \\<lfloor>\\<lfloor>Some ` (H ` ran (heap (snd \\<tau>)) - {None})\\<rfloor>\\<rfloor>) =\n            \\<lfloor>\\<lfloor>Some ` (H ` ran (heap (snd \\<tau>)) - {None})\\<rfloor>\\<rfloor>\"\n           by(subst Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e.Abs_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e_inverse,simp_all add: bot_option_def)\n show ?thesis\n  apply(rule StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t_vs_StrongEq'[OF WFF valid_x valid_y, where H = \"Some o H\"])\n  apply(subst oid_preserve[symmetric], simp, simp add: oid_of_option_def)\n  apply(insert xy_together,\n        subst (asm) foundation11,\n        metis at_post_def defined_and_I valid_x valid_y,\n        metis at_pre_def defined_and_I valid_x valid_y)\n  apply(erule disjE)\n by(drule foundation5,\n    simp add: OclAllInstances_at_pre_def OclAllInstances_at_post_def\n              OclValid_def OclIncludes_def true_def F F'\n              valid_x[simplified OclValid_def] valid_y[simplified OclValid_def] bot_option_def\n         split: if_split_asm,\n    simp add: comp_def image_def, fastforce)+\nqed\n\nsubsection\\<open>OclIsNew, OclIsDeleted, OclIsMaintained, OclIsAbsent\\<close>\n\ndefinition OclIsNew:: \"('\\<AA>, '\\<alpha>::{null,object})val \\<Rightarrow> ('\\<AA>)Boolean\"   (\"(_).oclIsNew'(')\")\nwhere \"X .oclIsNew() \\<equiv> (\\<lambda>\\<tau> . if (\\<delta> X) \\<tau> = true \\<tau>\n                              then \\<lfloor>\\<lfloor>oid_of (X \\<tau>) \\<notin> dom(heap(fst \\<tau>)) \\<and>\n                                     oid_of (X \\<tau>) \\<in> dom(heap(snd \\<tau>))\\<rfloor>\\<rfloor>\n                              else invalid \\<tau>)\"\n\ntext\\<open>The following predicates --- which are not part of the OCL standard descriptions ---\ncomplete the goal of \\inlineisar+oclIsNew+ by describing where an object belongs.\n\\<close>\n\ndefinition OclIsDeleted:: \"('\\<AA>, '\\<alpha>::{null,object})val \\<Rightarrow> ('\\<AA>)Boolean\"   (\"(_).oclIsDeleted'(')\")\nwhere \"X .oclIsDeleted() \\<equiv> (\\<lambda>\\<tau> . if (\\<delta> X) \\<tau> = true \\<tau>\n                              then \\<lfloor>\\<lfloor>oid_of (X \\<tau>) \\<in> dom(heap(fst \\<tau>)) \\<and>\n                                     oid_of (X \\<tau>) \\<notin> dom(heap(snd \\<tau>))\\<rfloor>\\<rfloor>\n                              else invalid \\<tau>)\"\n\ndefinition OclIsMaintained:: \"('\\<AA>, '\\<alpha>::{null,object})val \\<Rightarrow> ('\\<AA>)Boolean\"(\"(_).oclIsMaintained'(')\")\nwhere \"X .oclIsMaintained() \\<equiv> (\\<lambda>\\<tau> . if (\\<delta> X) \\<tau> = true \\<tau>\n                              then \\<lfloor>\\<lfloor>oid_of (X \\<tau>) \\<in> dom(heap(fst \\<tau>)) \\<and>\n                                     oid_of (X \\<tau>) \\<in> dom(heap(snd \\<tau>))\\<rfloor>\\<rfloor>\n                              else invalid \\<tau>)\"\n\ndefinition OclIsAbsent:: \"('\\<AA>, '\\<alpha>::{null,object})val \\<Rightarrow> ('\\<AA>)Boolean\"   (\"(_).oclIsAbsent'(')\")\nwhere \"X .oclIsAbsent() \\<equiv> (\\<lambda>\\<tau> . if (\\<delta> X) \\<tau> = true \\<tau>\n                              then \\<lfloor>\\<lfloor>oid_of (X \\<tau>) \\<notin> dom(heap(fst \\<tau>)) \\<and>\n                                     oid_of (X \\<tau>) \\<notin> dom(heap(snd \\<tau>))\\<rfloor>\\<rfloor>\n                              else invalid \\<tau>)\"\n\nlemma state_split : \"\\<tau> \\<Turnstile> \\<delta> X \\<Longrightarrow>\n                     \\<tau> \\<Turnstile> (X .oclIsNew()) \\<or> \\<tau> \\<Turnstile> (X .oclIsDeleted()) \\<or>\n                     \\<tau> \\<Turnstile> (X .oclIsMaintained()) \\<or> \\<tau> \\<Turnstile> (X .oclIsAbsent())\"\nby(simp add: OclIsDeleted_def OclIsNew_def OclIsMaintained_def OclIsAbsent_def\n             OclValid_def true_def, blast)\n\nlemma notNew_vs_others : \"\\<tau> \\<Turnstile> \\<delta> X \\<Longrightarrow>\n                         (\\<not> \\<tau> \\<Turnstile> (X .oclIsNew())) = (\\<tau> \\<Turnstile> (X .oclIsDeleted()) \\<or>\n                          \\<tau> \\<Turnstile> (X .oclIsMaintained()) \\<or> \\<tau> \\<Turnstile> (X .oclIsAbsent()))\"\nby(simp add: OclIsDeleted_def OclIsNew_def OclIsMaintained_def OclIsAbsent_def\n                OclNot_def OclValid_def true_def, blast)\n\nsubsection\\<open>OclIsModifiedOnly\\<close>\nsubsubsection\\<open>Definition\\<close>\n\ntext\\<open>The following predicate---which is not part of the OCL\nstandard---provides a simple, but powerful means to describe framing\nconditions. For any formal approach, be it animation of OCL contracts,\ntest-case generation or die-hard theorem proving, the specification of\nthe part of a system transition that \\emph{does not change} is of\nprimordial importance. The following operator establishes the equality\nbetween old and new objects in the state (provided that they exist in\nboth states), with the exception of those objects.\\<close>\n\ndefinition OclIsModifiedOnly ::\"('\\<AA>::object,'\\<alpha>::{null,object})Set \\<Rightarrow> '\\<AA> Boolean\"\n                        (\"_->oclIsModifiedOnly'(')\")\nwhere \"X->oclIsModifiedOnly() \\<equiv> (\\<lambda>(\\<sigma>,\\<sigma>').\n                           let X' = (oid_of ` \\<lceil>\\<lceil>Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e(X(\\<sigma>,\\<sigma>'))\\<rceil>\\<rceil>);\n                               S = ((dom (heap \\<sigma>) \\<inter> dom (heap \\<sigma>')) - X')\n                           in if (\\<delta> X) (\\<sigma>,\\<sigma>') = true (\\<sigma>,\\<sigma>') \\<and> (\\<forall>x\\<in>\\<lceil>\\<lceil>Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e(X(\\<sigma>,\\<sigma>'))\\<rceil>\\<rceil>. x \\<noteq> null)\n                              then \\<lfloor>\\<lfloor>\\<forall> x \\<in> S. (heap \\<sigma>) x = (heap \\<sigma>') x\\<rfloor>\\<rfloor>\n                              else invalid (\\<sigma>,\\<sigma>'))\"\n\nsubsubsection\\<open>Execution with Invalid or Null or Null Element as Argument\\<close>\n\nlemma \"invalid->oclIsModifiedOnly() = invalid\"\nby(simp add: OclIsModifiedOnly_def)\n\nlemma \"null->oclIsModifiedOnly() = invalid\"\nby(simp add: OclIsModifiedOnly_def)\n\nlemma\n assumes X_null : \"\\<tau> \\<Turnstile> X->includes\\<^sub>S\\<^sub>e\\<^sub>t(null)\"\n shows \"\\<tau> \\<Turnstile> X->oclIsModifiedOnly() \\<triangleq> invalid\"\n apply(insert X_null,\n       simp add : OclIncludes_def OclIsModifiedOnly_def StrongEq_def OclValid_def true_def)\n apply(case_tac \\<tau>, simp)\n apply(simp split: if_split_asm)\nby(simp add: null_fun_def, blast)\n\nsubsubsection\\<open>Context Passing\\<close>\n\nlemma cp_OclIsModifiedOnly : \"X->oclIsModifiedOnly() \\<tau> = (\\<lambda>_. X \\<tau>)->oclIsModifiedOnly() \\<tau>\"\nby(simp only: OclIsModifiedOnly_def, case_tac \\<tau>, simp only:, subst cp_defined, simp)\n\nsubsection\\<open>OclSelf\\<close>\n\ntext\\<open>The following predicate---which is not part of the OCL\nstandard---explicitly retrieves in the pre or post state the original OCL expression\ngiven as argument.\\<close>\n\ndefinition [simp]: \"OclSelf x H fst_snd = (\\<lambda>\\<tau> . if (\\<delta> x) \\<tau> = true \\<tau>\n                        then if oid_of (x \\<tau>) \\<in> dom(heap(fst \\<tau>)) \\<and> oid_of (x \\<tau>) \\<in> dom(heap (snd \\<tau>))\n                             then  H \\<lceil>(heap(fst_snd \\<tau>))(oid_of (x \\<tau>))\\<rceil>\n                             else invalid \\<tau>\n                        else invalid \\<tau>)\"\n\ndefinition OclSelf_at_pre :: \"('\\<AA>::object,'\\<alpha>::{null,object})val \\<Rightarrow>\n                      ('\\<AA> \\<Rightarrow> '\\<alpha>) \\<Rightarrow>\n                      ('\\<AA>::object,'\\<alpha>::{null,object})val\" (\"(_)@pre(_)\")\nwhere \"x @pre H = OclSelf x H fst\"\n\ndefinition OclSelf_at_post :: \"('\\<AA>::object,'\\<alpha>::{null,object})val \\<Rightarrow>\n                      ('\\<AA> \\<Rightarrow> '\\<alpha>) \\<Rightarrow>\n                      ('\\<AA>::object,'\\<alpha>::{null,object})val\" (\"(_)@post(_)\")\nwhere \"x @post H = OclSelf x H snd\"\n\nsubsection\\<open>Framing Theorem\\<close>\n\nlemma all_oid_diff:\n assumes def_x : \"\\<tau> \\<Turnstile> \\<delta> x\"\n assumes def_X : \"\\<tau> \\<Turnstile> \\<delta> X\"\n assumes def_X' : \"\\<And>x. x \\<in> \\<lceil>\\<lceil>Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (X \\<tau>)\\<rceil>\\<rceil> \\<Longrightarrow> x \\<noteq> null\"\n\n defines \"P \\<equiv> (\\<lambda>a. not (StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t x a))\"\n shows \"(\\<tau> \\<Turnstile> X->forAll\\<^sub>S\\<^sub>e\\<^sub>t(a| P a)) = (oid_of (x \\<tau>) \\<notin> oid_of ` \\<lceil>\\<lceil>Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (X \\<tau>)\\<rceil>\\<rceil>)\"\nproof -\n have P_null_bot: \"\\<And>b. b = null \\<or> b = \\<bottom> \\<Longrightarrow>\n                        \\<not> (\\<exists>x\\<in>\\<lceil>\\<lceil>Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (X \\<tau>)\\<rceil>\\<rceil>. P (\\<lambda>(_:: 'a state \\<times> 'a state). x) \\<tau> = b \\<tau>)\"\n  apply(erule disjE)\n   apply(simp, rule ballI,\n         simp add: P_def StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t_def, rename_tac x',\n         subst cp_OclNot, simp,\n         subgoal_tac \"x \\<tau> \\<noteq> null \\<and> x' \\<noteq> null\", simp,\n         simp add: OclNot_def null_fun_def null_option_def bot_option_def bot_fun_def invalid_def,\n         ( metis def_X' def_x foundation16[THEN iffD1]\n         | (metis bot_fun_def OclValid_def Set_inv_lemma def_X def_x defined_def valid_def,\n            metis def_X' def_x foundation16[THEN iffD1])))+\n done\n\n\n have not_inj : \"\\<And>x y. ((not x) \\<tau> = (not y) \\<tau>) = (x \\<tau> = y \\<tau>)\"\n by (metis foundation21 foundation22)\n\n have P_false : \"\\<exists>x\\<in>\\<lceil>\\<lceil>Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (X \\<tau>)\\<rceil>\\<rceil>. P (\\<lambda>_. x) \\<tau> = false \\<tau> \\<Longrightarrow>\n                 oid_of (x \\<tau>) \\<in> oid_of ` \\<lceil>\\<lceil>Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (X \\<tau>)\\<rceil>\\<rceil>\"\n  apply(erule bexE, rename_tac x')\n  apply(simp add: P_def)\n  apply(simp only: OclNot3[symmetric], simp only: not_inj)\n  apply(simp add: StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t_def split: if_split_asm)\n    apply(subgoal_tac \"x \\<tau> \\<noteq> null \\<and> x' \\<noteq> null\", simp)\n    apply (metis (mono_tags) drop.simps def_x foundation16[THEN iffD1] true_def)\n by(simp add: invalid_def bot_option_def true_def)+\n\n have P_true : \"\\<forall>x\\<in>\\<lceil>\\<lceil>Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (X \\<tau>)\\<rceil>\\<rceil>. P (\\<lambda>_. x) \\<tau> = true \\<tau> \\<Longrightarrow>\n                oid_of (x \\<tau>) \\<notin> oid_of ` \\<lceil>\\<lceil>Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (X \\<tau>)\\<rceil>\\<rceil>\"\n  apply(subgoal_tac \"\\<forall>x'\\<in>\\<lceil>\\<lceil>Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (X \\<tau>)\\<rceil>\\<rceil>. oid_of x' \\<noteq> oid_of (x \\<tau>)\")\n   apply (metis imageE)\n  apply(rule ballI, drule_tac x = \"x'\" in ballE) prefer 3 apply assumption\n   apply(simp add: P_def)\n   apply(simp only: OclNot4[symmetric], simp only: not_inj)\n   apply(simp add: StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t_def false_def split: if_split_asm)\n    apply(subgoal_tac \"x \\<tau> \\<noteq> null \\<and> x' \\<noteq> null\", simp)\n    apply (metis def_X' def_x  foundation16[THEN iffD1])\n by(simp add: invalid_def bot_option_def false_def)+\n\n have bool_split : \"\\<forall>x\\<in>\\<lceil>\\<lceil>Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (X \\<tau>)\\<rceil>\\<rceil>. P (\\<lambda>_. x) \\<tau> \\<noteq> null \\<tau> \\<Longrightarrow>\n                    \\<forall>x\\<in>\\<lceil>\\<lceil>Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (X \\<tau>)\\<rceil>\\<rceil>. P (\\<lambda>_. x) \\<tau> \\<noteq> \\<bottom> \\<tau> \\<Longrightarrow>\n                    \\<forall>x\\<in>\\<lceil>\\<lceil>Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (X \\<tau>)\\<rceil>\\<rceil>. P (\\<lambda>_. x) \\<tau> \\<noteq> false \\<tau> \\<Longrightarrow>\n                    \\<forall>x\\<in>\\<lceil>\\<lceil>Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (X \\<tau>)\\<rceil>\\<rceil>. P (\\<lambda>_. x) \\<tau> = true \\<tau>\"\n  apply(rule ballI)\n  apply(drule_tac x = x in ballE) prefer 3 apply assumption\n   apply(drule_tac x = x in ballE) prefer 3 apply assumption\n    apply(drule_tac x = x in ballE) prefer 3 apply assumption\n     apply (metis (full_types) bot_fun_def OclNot4 OclValid_def foundation16\n                               foundation9 not_inj null_fun_def)\n by(fast+)\n\n show ?thesis\n  apply(subst OclForall_rep_set_true[OF def_X], simp add: OclValid_def)\n  apply(rule iffI, simp add: P_true)\n by (metis P_false P_null_bot bool_split)\nqed\n\ntheorem framing:\n      assumes modifiesclause:\"\\<tau> \\<Turnstile> (X->excluding\\<^sub>S\\<^sub>e\\<^sub>t(x))->oclIsModifiedOnly()\"\n      and oid_is_typerepr : \"\\<tau> \\<Turnstile> X->forAll\\<^sub>S\\<^sub>e\\<^sub>t(a| not (StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t x a))\"\n      shows \"\\<tau> \\<Turnstile> (x @pre P  \\<triangleq>  (x @post P))\"\n apply(case_tac \"\\<tau> \\<Turnstile> \\<delta> x\")\n proof - show \"\\<tau> \\<Turnstile> \\<delta> x \\<Longrightarrow> ?thesis\" proof - assume def_x : \"\\<tau> \\<Turnstile> \\<delta> x\" show ?thesis proof -\n\n have def_X : \"\\<tau> \\<Turnstile> \\<delta> X\"\n  apply(insert oid_is_typerepr, simp add: UML_Set.OclForall_def OclValid_def split: if_split_asm)\n by(simp add: bot_option_def true_def)\n\n have def_X' : \"\\<And>x. x \\<in> \\<lceil>\\<lceil>Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (X \\<tau>)\\<rceil>\\<rceil> \\<Longrightarrow> x \\<noteq> null\"\n  apply(insert modifiesclause, simp add: OclIsModifiedOnly_def OclValid_def split: if_split_asm)\n  apply(case_tac \\<tau>, simp split: if_split_asm)\n   apply(simp add: UML_Set.OclExcluding_def split: if_split_asm)\n    apply(subst (asm) (2) Abs_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e_inverse)\n     apply(simp, (rule disjI2)+)\n     apply (metis (hide_lams, mono_tags) Diff_iff Set_inv_lemma def_X)\n    apply(simp)\n    apply(erule ballE[where P = \"\\<lambda>x. x \\<noteq> null\"]) apply(assumption)\n    apply(simp)\n    apply (metis (hide_lams, no_types) def_x  foundation16[THEN iffD1])\n   apply (metis (hide_lams, no_types) OclValid_def def_X def_x foundation20\n                                      OclExcluding_valid_args_valid OclExcluding_valid_args_valid'')\n by(simp add: invalid_def bot_option_def)\n\n have oid_is_typerepr : \"oid_of (x \\<tau>) \\<notin> oid_of ` \\<lceil>\\<lceil>Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (X \\<tau>)\\<rceil>\\<rceil>\"\n by(rule all_oid_diff[THEN iffD1, OF def_x def_X def_X' oid_is_typerepr])\n\n show ?thesis\n  apply(simp add: StrongEq_def OclValid_def true_def OclSelf_at_pre_def OclSelf_at_post_def\n                  def_x[simplified OclValid_def])\n  apply(rule conjI, rule impI)\n   apply(rule_tac f = \"\\<lambda>x. P \\<lceil>x\\<rceil>\" in arg_cong)\n   apply(insert modifiesclause[simplified OclIsModifiedOnly_def OclValid_def])\n   apply(case_tac \\<tau>, rename_tac \\<sigma> \\<sigma>', simp split: if_split_asm)\n    apply(subst (asm) (2) UML_Set.OclExcluding_def)\n    apply(drule foundation5[simplified OclValid_def true_def], simp)\n    apply(subst (asm) Abs_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e_inverse, simp)\n     apply(rule disjI2)+\n     apply (metis (hide_lams, no_types) DiffD1 OclValid_def Set_inv_lemma def_x\n                                        foundation16 foundation18')\n    apply(simp)\n    apply(erule_tac x = \"oid_of (x (\\<sigma>, \\<sigma>'))\" in ballE) apply simp+\n    apply (metis (hide_lams, no_types)\n                 DiffD1 image_iff image_insert insert_Diff_single insert_absorb oid_is_typerepr)\n   apply(simp add: invalid_def bot_option_def)+\n by blast\n qed qed\nqed(simp add: OclSelf_at_post_def OclSelf_at_pre_def OclValid_def StrongEq_def true_def)+\n\n\ntext\\<open>As corollary, the framing property can be expressed with only the strong equality\nas comparison operator.\\<close>\n\ntheorem framing':\n  assumes wff : \"WFF \\<tau>\"\n  assumes modifiesclause:\"\\<tau> \\<Turnstile> (X->excluding\\<^sub>S\\<^sub>e\\<^sub>t(x))->oclIsModifiedOnly()\"\n  and oid_is_typerepr : \"\\<tau> \\<Turnstile> X->forAll\\<^sub>S\\<^sub>e\\<^sub>t(a| not (x \\<triangleq> a))\"\n  and oid_preserve: \"\\<And>x. x \\<in> ran (heap(fst \\<tau>)) \\<or> x \\<in> ran (heap(snd \\<tau>)) \\<Longrightarrow>\n                          oid_of (H x) = oid_of x\"\n  and xy_together:\n  \"\\<tau> \\<Turnstile> X->forAll\\<^sub>S\\<^sub>e\\<^sub>t(y | (H .allInstances()->includes\\<^sub>S\\<^sub>e\\<^sub>t(x) and H .allInstances()->includes\\<^sub>S\\<^sub>e\\<^sub>t(y)) or\n                     (H .allInstances@pre()->includes\\<^sub>S\\<^sub>e\\<^sub>t(x) and H .allInstances@pre()->includes\\<^sub>S\\<^sub>e\\<^sub>t(y)))\"\n  shows \"\\<tau> \\<Turnstile> (x @pre P  \\<triangleq>  (x @post P))\"\nproof -\n have def_X : \"\\<tau> \\<Turnstile> \\<delta> X\"\n  apply(insert oid_is_typerepr, simp add: UML_Set.OclForall_def OclValid_def split: if_split_asm)\n by(simp add: bot_option_def true_def)\n show ?thesis\n  apply(case_tac \"\\<tau> \\<Turnstile> \\<delta> x\", drule foundation20)\n   apply(rule framing[OF modifiesclause])\n   apply(rule OclForall_cong'[OF _ oid_is_typerepr xy_together], rename_tac y)\n   apply(cut_tac Set_inv_lemma'[OF def_X]) prefer 2 apply assumption\n   apply(rule OclNot_contrapos_nn, simp add: StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t_def)\n     apply(simp add: OclValid_def, subst cp_defined, simp,\n           assumption)\n   apply(rule StrictRefEq\\<^sub>O\\<^sub>b\\<^sub>j\\<^sub>e\\<^sub>c\\<^sub>t_vs_StrongEq''[THEN iffD1, OF wff _ _ oid_preserve], assumption+)\n by(simp add: OclSelf_at_post_def OclSelf_at_pre_def OclValid_def StrongEq_def true_def)+\nqed\n\nsubsection\\<open>Miscellaneous\\<close>\n\nlemma pre_post_new: \"\\<tau> \\<Turnstile> (x .oclIsNew()) \\<Longrightarrow> \\<not> (\\<tau> \\<Turnstile> \\<upsilon>(x @pre H1)) \\<and> \\<not> (\\<tau> \\<Turnstile> \\<upsilon>(x @post H2))\"\nby(simp add: OclIsNew_def OclSelf_at_pre_def OclSelf_at_post_def\n             OclValid_def StrongEq_def true_def false_def\n             bot_option_def invalid_def bot_fun_def valid_def\n      split: if_split_asm)\n\nlemma pre_post_old: \"\\<tau> \\<Turnstile> (x .oclIsDeleted()) \\<Longrightarrow> \\<not> (\\<tau> \\<Turnstile> \\<upsilon>(x @pre H1)) \\<and> \\<not> (\\<tau> \\<Turnstile> \\<upsilon>(x @post H2))\"\nby(simp add: OclIsDeleted_def OclSelf_at_pre_def OclSelf_at_post_def\n             OclValid_def StrongEq_def true_def false_def\n             bot_option_def invalid_def bot_fun_def valid_def\n      split: if_split_asm)\n\nlemma pre_post_absent: \"\\<tau> \\<Turnstile> (x .oclIsAbsent()) \\<Longrightarrow> \\<not> (\\<tau> \\<Turnstile> \\<upsilon>(x @pre H1)) \\<and> \\<not> (\\<tau> \\<Turnstile> \\<upsilon>(x @post H2))\"\nby(simp add: OclIsAbsent_def OclSelf_at_pre_def OclSelf_at_post_def\n             OclValid_def StrongEq_def true_def false_def\n             bot_option_def invalid_def bot_fun_def valid_def\n      split: if_split_asm)\n\nlemma pre_post_maintained: \"(\\<tau> \\<Turnstile> \\<upsilon>(x @pre H1) \\<or> \\<tau> \\<Turnstile> \\<upsilon>(x @post H2)) \\<Longrightarrow> \\<tau> \\<Turnstile> (x .oclIsMaintained())\"\nby(simp add: OclIsMaintained_def OclSelf_at_pre_def OclSelf_at_post_def\n             OclValid_def StrongEq_def true_def false_def\n             bot_option_def invalid_def bot_fun_def valid_def\n      split: if_split_asm)\n\nlemma pre_post_maintained':\n\"\\<tau> \\<Turnstile> (x .oclIsMaintained()) \\<Longrightarrow> (\\<tau> \\<Turnstile> \\<upsilon>(x @pre (Some o H1)) \\<and> \\<tau> \\<Turnstile> \\<upsilon>(x @post (Some o H2)))\"\nby(simp add: OclIsMaintained_def OclSelf_at_pre_def OclSelf_at_post_def\n             OclValid_def StrongEq_def true_def false_def\n             bot_option_def invalid_def bot_fun_def valid_def\n      split: if_split_asm)\n\nlemma framing_same_state: \"(\\<sigma>, \\<sigma>) \\<Turnstile> (x @pre H  \\<triangleq>  (x @post H))\"\nby(simp add: OclSelf_at_pre_def OclSelf_at_post_def OclValid_def StrongEq_def)\n\nsection\\<open>Accessors on Object\\<close>\nsubsection\\<open>Definition\\<close>\n\ndefinition \"select_object mt incl smash deref l = smash (foldl incl mt (map deref l))\n \\<comment> \\<open>smash returns null with \\<open>mt\\<close> in input (in this case, object contains null pointer)\\<close>\"\n\ntext\\<open>The continuation \\<open>f\\<close> is usually instantiated with a smashing\nfunction which is either the identity @{term id} or, for \\inlineocl{0..1} cardinalities\nof associations, the @{term OclANY}-selector which also handles the\n@{term null}-cases appropriately. A standard use-case for this combinator\nis for example:\\<close>\nterm \"(select_object mtSet UML_Set.OclIncluding UML_Set.OclANY f  l oid )::('\\<AA>, 'a::null)val\"\n\ndefinition \"select_object\\<^sub>S\\<^sub>e\\<^sub>t = select_object mtSet UML_Set.OclIncluding id\"\ndefinition \"select_object_any0\\<^sub>S\\<^sub>e\\<^sub>t f s_set = UML_Set.OclANY (select_object\\<^sub>S\\<^sub>e\\<^sub>t f s_set)\"\ndefinition \"select_object_any\\<^sub>S\\<^sub>e\\<^sub>t f s_set = \n (let s = select_object\\<^sub>S\\<^sub>e\\<^sub>t f s_set in\n  if s->size\\<^sub>S\\<^sub>e\\<^sub>t() \\<triangleq> \\<one> then\n    s->any\\<^sub>S\\<^sub>e\\<^sub>t()\n  else\n    \\<bottom>\n  endif)\"\ndefinition \"select_object\\<^sub>S\\<^sub>e\\<^sub>q = select_object mtSequence UML_Sequence.OclIncluding id\"\ndefinition \"select_object_any\\<^sub>S\\<^sub>e\\<^sub>q f s_set = UML_Sequence.OclANY (select_object\\<^sub>S\\<^sub>e\\<^sub>q f s_set)\"\ndefinition \"select_object\\<^sub>P\\<^sub>a\\<^sub>i\\<^sub>r f1 f2 = (\\<lambda>(a,b). OclPair (f1 a) (f2 b))\"\n\nsubsection\\<open>Validity and Definedness Properties\\<close>\n\nlemma select_fold_exec\\<^sub>S\\<^sub>e\\<^sub>q:\n assumes \"list_all (\\<lambda>f. (\\<tau> \\<Turnstile> \\<upsilon> f)) l\"\n shows \"\\<lceil>\\<lceil>Rep_Sequence\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (foldl UML_Sequence.OclIncluding Sequence{} l \\<tau>)\\<rceil>\\<rceil> = List.map (\\<lambda>f. f \\<tau>) l\"\nproof -\n have def_fold: \"\\<And>l. list_all (\\<lambda>f. \\<tau> \\<Turnstile> \\<upsilon> f) l \\<Longrightarrow>\n            \\<tau> \\<Turnstile> (\\<delta> foldl UML_Sequence.OclIncluding Sequence{} l)\"\n  apply(rule rev_induct[where P = \"\\<lambda>l. list_all (\\<lambda>f. (\\<tau> \\<Turnstile> \\<upsilon> f)) l \\<longrightarrow> \\<tau> \\<Turnstile> (\\<delta> foldl UML_Sequence.OclIncluding Sequence{} l)\", THEN mp], simp)\n by(simp add: foundation10')\n show ?thesis\n  apply(rule rev_induct[where P = \"\\<lambda>l. list_all (\\<lambda>f. (\\<tau> \\<Turnstile> \\<upsilon> f)) l \\<longrightarrow> \\<lceil>\\<lceil>Rep_Sequence\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (foldl UML_Sequence.OclIncluding Sequence{} l \\<tau>)\\<rceil>\\<rceil> = List.map (\\<lambda>f. f \\<tau>) l\", THEN mp], simp)\n    apply(simp add: mtSequence_def)\n    apply(subst Abs_Sequence\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e_inverse, (simp | intro impI)+)\n   apply(simp add: UML_Sequence.OclIncluding_def, intro conjI impI)\n    apply(subst Abs_Sequence\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e_inverse, simp, (rule disjI2)+)\n     apply(simp add: list_all_iff foundation18', simp)\n   apply(subst (asm) def_fold[simplified (no_asm) OclValid_def], simp, simp add: OclValid_def)\n by (rule assms)\nqed\n\nlemma select_fold_exec\\<^sub>S\\<^sub>e\\<^sub>t:\n assumes \"list_all (\\<lambda>f. (\\<tau> \\<Turnstile> \\<upsilon> f)) l\"\n shows \"\\<lceil>\\<lceil>Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (foldl UML_Set.OclIncluding Set{} l \\<tau>)\\<rceil>\\<rceil> = set (List.map (\\<lambda>f. f \\<tau>) l)\"\nproof -\n have def_fold: \"\\<And>l. list_all (\\<lambda>f. \\<tau> \\<Turnstile> \\<upsilon> f) l \\<Longrightarrow>\n            \\<tau> \\<Turnstile> (\\<delta> foldl UML_Set.OclIncluding Set{} l)\"\n  apply(rule rev_induct[where P = \"\\<lambda>l. list_all (\\<lambda>f. (\\<tau> \\<Turnstile> \\<upsilon> f)) l \\<longrightarrow> \\<tau> \\<Turnstile> (\\<delta> foldl UML_Set.OclIncluding Set{} l)\", THEN mp], simp)\n by(simp add: foundation10')\n show ?thesis\n  apply(rule rev_induct[where P = \"\\<lambda>l. list_all (\\<lambda>f. (\\<tau> \\<Turnstile> \\<upsilon> f)) l \\<longrightarrow> \\<lceil>\\<lceil>Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (foldl UML_Set.OclIncluding Set{} l \\<tau>)\\<rceil>\\<rceil> = set (List.map (\\<lambda>f. f \\<tau>) l)\", THEN mp], simp)\n    apply(simp add: mtSet_def)\n    apply(subst Abs_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e_inverse, (simp | intro impI)+)\n   apply(simp add: UML_Set.OclIncluding_def, intro conjI impI)\n    apply(subst Abs_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e_inverse, simp, (rule disjI2)+)\n     apply(simp add: list_all_iff foundation18', simp)\n   apply(subst (asm) def_fold[simplified (no_asm) OclValid_def], simp, simp add: OclValid_def)\n by (rule assms)\nqed\n\n\n\nlemma fold_val_elem\\<^sub>S\\<^sub>e\\<^sub>t:\n assumes \"\\<tau> \\<Turnstile> \\<upsilon> (foldl UML_Set.OclIncluding Set{} (List.map (f p) s_set))\"\n shows \"list_all (\\<lambda>x. (\\<tau> \\<Turnstile> \\<upsilon> (f p x))) s_set\"\n apply(rule rev_induct[where P = \"\\<lambda>s_set. \\<tau> \\<Turnstile> \\<upsilon> foldl UML_Set.OclIncluding Set{} (List.map (f p) s_set) \\<longrightarrow> list_all (\\<lambda>x. \\<tau> \\<Turnstile> \\<upsilon> f p x) s_set\", THEN mp])\n   apply(simp, auto)\n    apply (metis (hide_lams, mono_tags) foundation10' foundation20)+\nby(simp add: assms)\n\nlemma select_object_any_defined\\<^sub>S\\<^sub>e\\<^sub>q:\n assumes def_sel: \"\\<tau> \\<Turnstile> \\<delta> (select_object_any\\<^sub>S\\<^sub>e\\<^sub>q f s_set)\"\n shows \"s_set \\<noteq> []\"\n apply(insert def_sel, case_tac s_set)\n  apply(simp add: select_object_any\\<^sub>S\\<^sub>e\\<^sub>q_def UML_Sequence.OclANY_def select_object\\<^sub>S\\<^sub>e\\<^sub>q_def select_object_def\n                  defined_def OclValid_def\n                  false_def true_def bot_fun_def bot_option_def\n             split: if_split_asm)\n  apply(simp add: mtSequence_def, subst (asm) Abs_Sequence\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e_inverse, simp, simp)\nby(simp)\n\nlemma (*select_object_any_defined\\<^sub>S\\<^sub>e\\<^sub>t:*)\n assumes def_sel: \"\\<tau> \\<Turnstile> \\<delta> (select_object_any0\\<^sub>S\\<^sub>e\\<^sub>t f s_set)\"\n shows \"s_set \\<noteq> []\"\n apply(insert def_sel, case_tac s_set)\n  apply(simp add: select_object_any0\\<^sub>S\\<^sub>e\\<^sub>t_def UML_Sequence.OclANY_def select_object\\<^sub>S\\<^sub>e\\<^sub>t_def select_object_def\n                  defined_def OclValid_def\n                  false_def true_def bot_fun_def bot_option_def\n             split: if_split_asm)\nby(simp)\n\nlemma select_object_any_defined\\<^sub>S\\<^sub>e\\<^sub>t:\n assumes def_sel: \"\\<tau> \\<Turnstile> \\<delta> (select_object_any\\<^sub>S\\<^sub>e\\<^sub>t f s_set)\"\n shows \"s_set \\<noteq> []\"\n apply(insert def_sel, case_tac s_set)\n  apply(simp add: select_object_any\\<^sub>S\\<^sub>e\\<^sub>t_def UML_Sequence.OclANY_def select_object\\<^sub>S\\<^sub>e\\<^sub>t_def select_object_def\n                  defined_def OclValid_def\n                  false_def true_def bot_fun_def bot_option_def\n                  OclInt0_def OclInt1_def StrongEq_def OclIf_def null_fun_def null_option_def\n             split: if_split_asm)\nby(simp)\n\nlemma select_object_any_exec0\\<^sub>S\\<^sub>e\\<^sub>q:\n assumes def_sel: \"\\<tau> \\<Turnstile> \\<delta> (select_object_any\\<^sub>S\\<^sub>e\\<^sub>q f s_set)\"\n shows \"\\<tau> \\<Turnstile> (select_object_any\\<^sub>S\\<^sub>e\\<^sub>q f s_set \\<triangleq> f (hd s_set))\"\n  apply(insert def_sel[simplified foundation16],\n        simp add: select_object_any\\<^sub>S\\<^sub>e\\<^sub>q_def foundation22 UML_Sequence.OclANY_def split: if_split_asm)\n  apply(case_tac \"\\<lceil>\\<lceil>Rep_Sequence\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (select_object\\<^sub>S\\<^sub>e\\<^sub>q f s_set \\<tau>)\\<rceil>\\<rceil>\", simp add: bot_option_def, simp)\n  apply(simp add: select_object\\<^sub>S\\<^sub>e\\<^sub>q_def select_object_def)\n  apply(subst (asm) select_fold_exec\\<^sub>S\\<^sub>e\\<^sub>q)\n   apply(rule fold_val_elem\\<^sub>S\\<^sub>e\\<^sub>q, simp add: foundation18' invalid_def)\n  apply(simp)\nby(drule arg_cong[where f = hd], subst (asm) hd_map, simp add: select_object_any_defined\\<^sub>S\\<^sub>e\\<^sub>q[OF def_sel], simp)\n\nlemma select_object_any_exec\\<^sub>S\\<^sub>e\\<^sub>q:\n assumes def_sel: \"\\<tau> \\<Turnstile> \\<delta> (select_object_any\\<^sub>S\\<^sub>e\\<^sub>q f s_set)\"\n shows \"\\<exists>e. List.member s_set e \\<and> (\\<tau> \\<Turnstile> (select_object_any\\<^sub>S\\<^sub>e\\<^sub>q f s_set \\<triangleq> f e))\"\n apply(insert select_object_any_exec0\\<^sub>S\\<^sub>e\\<^sub>q[OF def_sel])\n apply(rule exI[where x = \"hd s_set\"], simp)\n apply(case_tac s_set, simp add: select_object_any_defined\\<^sub>S\\<^sub>e\\<^sub>q[OF def_sel])\nby (metis list.sel member_rec(1))\n\nlemma (*select_object_any_exec\\<^sub>S\\<^sub>e\\<^sub>t:*)\n assumes def_sel: \"\\<tau> \\<Turnstile> \\<delta> (select_object_any0\\<^sub>S\\<^sub>e\\<^sub>t f s_set)\"\n shows \"\\<exists> e. List.member s_set e \\<and> (\\<tau> \\<Turnstile> (select_object_any0\\<^sub>S\\<^sub>e\\<^sub>t f s_set \\<triangleq> f e))\"\nproof -\n have list_all_map: \"\\<And>P f l. list_all P (List.map f l) = list_all (P o f) l\"\n by(induct_tac l, simp_all)\n\n fix z\n show ?thesis\n  when \"\\<lceil>\\<lceil>Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (select_object\\<^sub>S\\<^sub>e\\<^sub>t f s_set \\<tau>)\\<rceil>\\<rceil> = z\"\n  apply(insert that def_sel[simplified foundation16],\n        simp add: select_object_any0\\<^sub>S\\<^sub>e\\<^sub>t_def foundation22 UML_Set.OclANY_def null_fun_def split: if_split_asm)\n\n  apply(simp add: select_object\\<^sub>S\\<^sub>e\\<^sub>t_def select_object_def)\n  apply(subst (asm) select_fold_exec\\<^sub>S\\<^sub>e\\<^sub>t)\n   apply(rule fold_val_elem\\<^sub>S\\<^sub>e\\<^sub>t, simp add: OclValid_def)\n  apply(simp add: comp_def)\n\n  apply(case_tac s_set, simp, simp add: false_def true_def, simp)\n\n  proof - fix a l\n  show \"insert (f a \\<tau>) ((\\<lambda>x. f x \\<tau>) ` set l) = z \\<Longrightarrow>\n        \\<exists>e. List.member (a # l) e \\<and> (SOME y. y \\<in> z) = f e \\<tau>\"\n   apply(rule list.induct[where P = \"\\<lambda>l. \\<forall>z a. insert (f a \\<tau>) ((\\<lambda>x. f x \\<tau>) ` set l) = z \\<longrightarrow>\n        (\\<exists>e. List.member (a # l) e \\<and> ((SOME y. y \\<in> z) = f e \\<tau>))\", THEN spec, THEN spec, THEN mp], intro allI impI)\n     proof - fix x xa show \"insert (f xa \\<tau>) ((\\<lambda>x. f x \\<tau>) ` set []) = x \\<Longrightarrow> \\<exists>e. List.member [xa] e \\<and> (SOME y. y \\<in> x) = f e \\<tau>\"\n      apply(rule exI[where x = xa], simp add: List.member_def)\n      apply(subst some_equality[where a = \"f xa \\<tau>\"])\n        apply (metis (mono_tags) insertI1)\n       apply (metis (mono_tags) empty_iff insert_iff)\n     by(simp)\n    apply_end(intro allI impI, simp)\n    fix x list xa xb\n    show \" \\<forall>x. \\<exists>e. List.member (x # list) e \\<and> (SOME y. y = f x \\<tau> \\<or> y \\<in> (\\<lambda>x. f x \\<tau>) ` set list) = f e \\<tau> \\<Longrightarrow>\n       insert (f xb \\<tau>) (insert (f x \\<tau>) ((\\<lambda>x. f x \\<tau>) ` set list)) = xa \\<Longrightarrow>\n       \\<exists>e. List.member (xb # x # list) e \\<and> (SOME y. y \\<in> xa) = f e \\<tau>\"\n     apply(case_tac \"x = xb\", simp)\n      apply(erule allE[where x = xb])\n      apply(erule exE)\n      proof - fix e show \"insert (f xb \\<tau>) ((\\<lambda>x. f x \\<tau>) ` set list) = xa \\<Longrightarrow>\n         x = xb \\<Longrightarrow>\n         List.member (xb # list) e \\<and> (SOME y. y = f xb \\<tau> \\<or> y \\<in> (\\<lambda>x. f x \\<tau>) ` set list) = f e \\<tau> \\<Longrightarrow>\n         \\<exists>e. List.member (xb # xb # list) e \\<and> (SOME y. y \\<in> xa) = f e \\<tau>\"\n      apply(rule exI[where x = e], auto)\n      by (metis member_rec(1))\n     apply_end(case_tac \"List.member list x\")\n      apply_end(erule allE[where x = xb])\n      apply_end(erule exE)\n      fix e\n      let ?P = \"\\<lambda>y. y = f xb \\<tau> \\<or> y \\<in> (\\<lambda>x. f x \\<tau>) ` set list\"\n      show \"insert (f xb \\<tau>) (insert (f x \\<tau>) ((\\<lambda>x. f x \\<tau>) ` set list)) = xa \\<Longrightarrow>\n         x \\<noteq> xb \\<Longrightarrow>\n         List.member list x \\<Longrightarrow>\n         List.member (xb # list) e \\<and> (SOME y. y = f xb \\<tau> \\<or> y \\<in> (\\<lambda>x. f x \\<tau>) ` set list) = f e \\<tau> \\<Longrightarrow>\n         \\<exists>e. List.member (xb # x # list) e \\<and> (SOME y. y \\<in> xa) = f e \\<tau>\"\n       apply(rule exI[where x = e], auto)\n        apply (metis member_rec(1))\n\n       apply(subgoal_tac \"?P (f e \\<tau>)\")\n        prefer 2\n        apply(case_tac \"xb = e\", simp)\n        apply (metis (mono_tags) image_eqI in_set_member member_rec(1)) \n\n       apply(rule someI2[where a = \"f e \\<tau>\"])\n        apply(erule disjE, simp)+\n        apply(rule disjI2)+ apply(simp)\noops\n\nlemma select_object_any_exec\\<^sub>S\\<^sub>e\\<^sub>t:\n assumes def_sel: \"\\<tau> \\<Turnstile> \\<delta> (select_object_any\\<^sub>S\\<^sub>e\\<^sub>t f s_set)\"\n shows \"\\<exists> e. List.member s_set e \\<and> (\\<tau> \\<Turnstile> (select_object_any\\<^sub>S\\<^sub>e\\<^sub>t f s_set \\<triangleq> f e))\"\nproof -\n have card_singl: \"\\<And>A a. finite A \\<Longrightarrow> card (insert a A) = 1 \\<Longrightarrow> A \\<subseteq> {a}\"\n by (auto, metis Suc_inject card_Suc_eq card_eq_0_iff insert_absorb insert_not_empty singleton_iff)\n\n have list_same: \"\\<And>f s_set z' x. f ` set s_set = {z'} \\<Longrightarrow> List.member s_set x \\<Longrightarrow> f x = z'\"\n by (metis (full_types) empty_iff imageI in_set_member insert_iff)\n\n fix z\n show ?thesis\n  when \"\\<lceil>\\<lceil>Rep_Set\\<^sub>b\\<^sub>a\\<^sub>s\\<^sub>e (select_object\\<^sub>S\\<^sub>e\\<^sub>t f s_set \\<tau>)\\<rceil>\\<rceil> = z\"\n  apply(insert that def_sel[simplified foundation16],\n        simp add: select_object_any\\<^sub>S\\<^sub>e\\<^sub>t_def foundation22\n                  Let_def null_fun_def bot_fun_def OclIf_def\n             split: if_split_asm)\n  apply(simp add: StrongEq_def OclInt1_def true_def UML_Set.OclSize_def\n                  bot_option_def UML_Set.OclANY_def null_fun_def\n                  split: if_split_asm)\n  apply(subgoal_tac \"\\<exists>z'. z = {z'}\")\n   prefer 2\n   apply(rule finite.cases[where a = z], simp, simp, simp)\n   apply(rule card_singl, simp, simp)\n  apply(erule exE, clarsimp)\n\n  apply(simp add: select_object\\<^sub>S\\<^sub>e\\<^sub>t_def select_object_def)\n  apply(subst (asm) select_fold_exec\\<^sub>S\\<^sub>e\\<^sub>t)\n   apply(rule fold_val_elem\\<^sub>S\\<^sub>e\\<^sub>t, simp add: OclValid_def true_def)\n  apply(simp add: comp_def)\n\n  apply(case_tac s_set, simp)\n  proof - fix z' a list show \"(\\<lambda>x. f x \\<tau>) ` set s_set = {z'} \\<Longrightarrow> s_set = a # list \\<Longrightarrow> \\<exists>e. List.member s_set e \\<and> z' = f e \\<tau>\"\n    apply(drule list_same[where x1 = a])\n     apply (metis member_rec(1))\n   by (metis (hide_lams, mono_tags) ListMem_iff elem in_set_member)\n  qed\nqed blast+\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Featherweight_OCL/UML_State.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6150878414043816, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.29313834883000983}}
{"text": "(*\n    Author:     Gerwin Klein\n    Copyright   1999 Technische Universitaet Muenchen\n*)\n\nsection \\<open>Correctness of the LBV\\<close>\n\ntheory LBVCorrect\nimports LBVSpec Typing_Framework\nbegin\n\nlocale lbvs = lbv +\n  fixes s\\<^sub>0  :: 'a\n  fixes c   :: \"'a list\"\n  fixes ins :: \"'b list\"\n  fixes \\<tau>s  :: \"'a list\"\n  defines phi_def:\n  \"\\<tau>s \\<equiv> map (\\<lambda>pc. if c!pc = \\<bottom> then wtl (take pc ins) c 0 s\\<^sub>0 else c!pc) \n       [0..<size ins]\"\n\n  assumes bounded: \"bounded step (size ins)\"\n  assumes cert: \"cert_ok c (size ins) \\<top> \\<bottom> A\"\n  assumes pres: \"pres_type step (size ins) A\"\n\nlemma (in lbvs) phi_None [intro?]:\n  \"\\<lbrakk> pc < size ins; c!pc = \\<bottom> \\<rbrakk> \\<Longrightarrow> \\<tau>s!pc = wtl (take pc ins) c 0 s\\<^sub>0\"\n(*<*) by (simp add: phi_def) (*>*)\n\nlemma (in lbvs) phi_Some [intro?]:\n  \"\\<lbrakk> pc < size ins; c!pc \\<noteq> \\<bottom> \\<rbrakk> \\<Longrightarrow> \\<tau>s!pc = c!pc\"\n(*<*) by (simp add: phi_def) (*>*)\n\nlemma (in lbvs) phi_len [simp]: \"size \\<tau>s = size ins\"\n(*<*) by (simp add: phi_def) (*>*)\n\nlemma (in lbvs) wtl_suc_pc:\n  assumes all: \"wtl ins c 0 s\\<^sub>0 \\<noteq> \\<top>\" \n  assumes pc:  \"pc+1 < size ins\"\n  shows \"wtl (take (pc+1) ins) c 0 s\\<^sub>0 \\<sqsubseteq>\\<^sub>r \\<tau>s!(pc+1)\"\n(*<*)\nproof -\n  from all pc\n  have \"wtc c (pc+1) (wtl (take (pc+1) ins) c 0 s\\<^sub>0) \\<noteq> T\" by (rule wtl_all)\n  with pc show ?thesis by (simp add: phi_def wtc split: if_split_asm)\nqed\n(*>*)\n\nlemma (in lbvs) wtl_stable:\n  assumes wtl: \"wtl ins c 0 s\\<^sub>0 \\<noteq> \\<top>\" \n  assumes s\\<^sub>0:  \"s\\<^sub>0 \\<in> A\" and  pc:  \"pc < size ins\" \n  shows \"stable r step \\<tau>s pc\"\n(*<*)\nproof (unfold stable_def, clarify)\n  fix pc' s' assume step: \"(pc',s') \\<in> set (step pc (\\<tau>s ! pc))\" \n                      (is \"(pc',s') \\<in> set (?step pc)\")\n  \n  from bounded pc step have pc': \"pc' < size ins\" by (rule boundedD)\n\n  have tkpc: \"wtl (take pc ins) c 0 s\\<^sub>0 \\<noteq> \\<top>\" (is \"?s\\<^sub>1 \\<noteq> _\") using wtl by (rule wtl_take)\n  have s\\<^sub>2: \"wtl (take (pc+1) ins) c 0 s\\<^sub>0 \\<noteq> \\<top>\" (is \"?s\\<^sub>2 \\<noteq> _\") using wtl by (rule wtl_take)\n  \n  from wtl pc have wt_s\\<^sub>1: \"wtc c pc ?s\\<^sub>1 \\<noteq> \\<top>\" by (rule wtl_all)\n\n  have c_Some: \"\\<forall>pc t. pc < size ins \\<longrightarrow> c!pc \\<noteq> \\<bottom> \\<longrightarrow> \\<tau>s!pc = c!pc\" \n    by (simp add: phi_def)\n  have c_None: \"c!pc = \\<bottom> \\<Longrightarrow> \\<tau>s!pc = ?s\\<^sub>1\" using pc ..\n\n  from wt_s\\<^sub>1 pc c_None c_Some\n  have inst: \"wtc c pc ?s\\<^sub>1  = wti c pc (\\<tau>s!pc)\"\n    by (simp add: wtc split: if_split_asm)\n\n  have \"?s\\<^sub>1 \\<in> A\" using pres cert s\\<^sub>0 wtl pc by (rule wtl_pres)\n  with pc c_Some cert c_None\n  have \"\\<tau>s!pc \\<in> A\" by (cases \"c!pc = \\<bottom>\") (auto dest: cert_okD1)\n  with pc pres\n  have step_in_A: \"snd`set (?step pc) \\<subseteq> A\" by (auto dest: pres_typeD2)\n\n  show \"s' \\<sqsubseteq>\\<^sub>r \\<tau>s!pc'\" \n  proof (cases \"pc' = pc+1\")\n    case True\n    with pc' cert\n    have cert_in_A: \"c!(pc+1) \\<in> A\" by (auto dest: cert_okD1)\n    from True pc' have pc1: \"pc+1 < size ins\" by simp\n    with tkpc have \"?s\\<^sub>2 = wtc c pc ?s\\<^sub>1\" by - (rule wtl_Suc)\n    with inst \n    have merge: \"?s\\<^sub>2 = merge c pc (?step pc) (c!(pc+1))\" by (simp add: wti)\n    also from s\\<^sub>2 merge have \"\\<dots> \\<noteq> \\<top>\" (is \"?merge \\<noteq> _\") by simp\n    with cert_in_A step_in_A\n    have \"?merge = (map snd [(p',t') \\<leftarrow> ?step pc. p'=pc+1] \\<Squnion>\\<^bsub>f\\<^esub> c!(pc+1))\"\n      by (rule merge_not_top_s) \n    finally have \"s' \\<sqsubseteq>\\<^sub>r ?s\\<^sub>2\" using step_in_A cert_in_A True step \n      by (auto intro: pp_ub1')\n    also from wtl pc1 have \"?s\\<^sub>2 \\<sqsubseteq>\\<^sub>r \\<tau>s!(pc+1)\" by (rule wtl_suc_pc)\n    also note True [symmetric]\n    finally show ?thesis by simp    \n  next\n    case False\n    from wt_s\\<^sub>1 inst \n    have \"merge c pc (?step pc) (c!(pc+1)) \\<noteq> \\<top>\" by (simp add: wti)\n    with step_in_A have \"\\<forall>(pc', s')\\<in>set (?step pc). pc'\\<noteq>pc+1 \\<longrightarrow> s' \\<sqsubseteq>\\<^sub>r c!pc'\"\n      by - (rule merge_not_top)\n    with step False  have ok: \"s' \\<sqsubseteq>\\<^sub>r c!pc'\" by blast\n    moreover from ok have \"c!pc' = \\<bottom> \\<Longrightarrow> s' = \\<bottom>\" by simp\n    moreover from c_Some pc'  have \"c!pc' \\<noteq> \\<bottom> \\<Longrightarrow> \\<tau>s!pc' = c!pc'\" by auto\n    ultimately show ?thesis by (cases \"c!pc' = \\<bottom>\") auto \n  qed\nqed\n(*>*)\n  \nlemma (in lbvs) phi_not_top:\n  assumes wtl: \"wtl ins c 0 s\\<^sub>0 \\<noteq> \\<top>\" and pc:  \"pc < size ins\"\n  shows \"\\<tau>s!pc \\<noteq> \\<top>\"\n(*<*)\nproof (cases \"c!pc = \\<bottom>\")\n  case False with pc\n  have \"\\<tau>s!pc = c!pc\" ..\n  also from cert pc have \"\\<dots> \\<noteq> \\<top>\" by (rule cert_okD4)\n  finally show ?thesis .\nnext\n  case True with pc\n  have \"\\<tau>s!pc = wtl (take pc ins) c 0 s\\<^sub>0\" ..\n  also from wtl have \"\\<dots> \\<noteq> \\<top>\" by (rule wtl_take)\n  finally show ?thesis .\nqed\n(*>*)\n\nlemma (in lbvs) phi_in_A:\n  assumes wtl: \"wtl ins c 0 s\\<^sub>0 \\<noteq> \\<top>\" and s\\<^sub>0: \"s\\<^sub>0 \\<in> A\"\n  shows \"\\<tau>s \\<in> list (size ins) A\"\n(*<*)\nproof -\n  { fix x assume \"x \\<in> set \\<tau>s\"\n    then obtain xs ys where \"\\<tau>s = xs @ x # ys\" \n      by (auto simp add: in_set_conv_decomp)\n    then obtain pc where pc: \"pc < size \\<tau>s\" and x: \"\\<tau>s!pc = x\"\n      by (simp add: that [of \"size xs\"] nth_append)\n    \n    from pres cert wtl s\\<^sub>0 pc \n    have \"wtl (take pc ins) c 0 s\\<^sub>0 \\<in> A\" by (auto intro!: wtl_pres)\n    moreover\n    from pc have \"pc < size ins\" by simp\n    with cert have \"c!pc \\<in> A\" ..\n    ultimately\n    have \"\\<tau>s!pc \\<in> A\" using pc by (simp add: phi_def)\n    hence \"x \\<in> A\" using x by simp\n  } \n  hence \"set \\<tau>s \\<subseteq> A\" ..\n  thus ?thesis by (unfold list_def) simp\nqed\n(*>*)\n\nlemma (in lbvs) phi0:\n  assumes wtl: \"wtl ins c 0 s\\<^sub>0 \\<noteq> \\<top>\" and 0: \"0 < size ins\"\n  shows \"s\\<^sub>0 \\<sqsubseteq>\\<^sub>r \\<tau>s!0\"\n(*<*)\nproof (cases \"c!0 = \\<bottom>\")\n  case True\n  with 0 have \"\\<tau>s!0 = wtl (take 0 ins) c 0 s\\<^sub>0\" ..\n  moreover have \"wtl (take 0 ins) c 0 s\\<^sub>0 = s\\<^sub>0\" by simp\n  ultimately have \"\\<tau>s!0 = s\\<^sub>0\" by simp\n  thus ?thesis by simp\nnext\n  case False\n  with 0 have \"\\<tau>s!0 = c!0\" ..\n  moreover \n  have \"wtl (take 1 ins) c 0 s\\<^sub>0 \\<noteq> \\<top>\" using wtl by (rule wtl_take)\n  with 0 False \n  have \"s\\<^sub>0 \\<sqsubseteq>\\<^sub>r c!0\" by (auto simp add: neq_Nil_conv wtc split: if_split_asm)\n  ultimately\n  show ?thesis by simp\nqed\n(*>*)\n\n\n\n\n\ntheorem (in lbvs) wtl_sound_strong:\n  assumes wtl: \"wtl ins c 0 s\\<^sub>0 \\<noteq> \\<top>\" \n  assumes s\\<^sub>0: \"s\\<^sub>0 \\<in> A\" and ins: \"0 < size ins\"\n  shows \"\\<exists>\\<tau>s \\<in> list (size ins) A. wt_step r \\<top> step \\<tau>s \\<and> s\\<^sub>0 \\<sqsubseteq>\\<^sub>r \\<tau>s!0\"\n(*<*)\nproof -\n  have \"\\<tau>s \\<in> list (size ins) A\" using wtl s\\<^sub>0 by (rule phi_in_A)\n  moreover\n  have \"wt_step r \\<top> step \\<tau>s\"\n  proof (unfold wt_step_def, intro strip conjI)\n    fix pc assume \"pc < size \\<tau>s\"\n    then obtain pc: \"pc < size ins\" by simp\n    with wtl show \"\\<tau>s!pc \\<noteq> \\<top>\" by (rule phi_not_top)\n    from wtl s\\<^sub>0 and pc show \"stable r step \\<tau>s pc\" by (rule wtl_stable)\n  qed\n  moreover from wtl ins have \"s\\<^sub>0 \\<sqsubseteq>\\<^sub>r \\<tau>s!0\" by (rule phi0)\n  ultimately show ?thesis by fast\nqed\n(*>*)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/JinjaThreads/DFA/LBVCorrect.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6001883735630721, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.29306201686046157}}
{"text": "theory IDentity imports\n  CryptHOL.CryptHOL\n  Game_Based_Crypto.Game_Based_Crypto\nbegin\n\nsledgehammer_params[timeout = 1000]\n\ntype_synonym ('share1', 'share2', 'share3') share_user_record = \"'share1' \\<times> 'share2' \\<times> 'share3'\"\n\ntype_synonym ('attrs', 'sens_atrrs', 'result') query = \"('attrs' set \\<times> 'sens_atrrs' set) \\<Rightarrow> 'result'\"\n\ntype_synonym ('attrs', 'sens_atrrs') user_attrs = \"('attrs' set \\<times> 'sens_atrrs' set)\" \n\ntype_synonym ('user', 'state_attr_hid', 'enc_attrs') attr_hiding_adversary\n  = \"(('user' \\<times> 'user') \\<times> 'state_attr_hid') spmf \\<times> ('state_attr_hid' \\<Rightarrow> 'enc_attrs' \\<Rightarrow> bool spmf)\"\n\ntype_synonym ('user', 'state_attr_hid', 'share1', 'share2', 'share3') attr_hiding_adversary'\n  = \"(('user' \\<times> 'user') \\<times> 'state_attr_hid') spmf \\<times> ('state_attr_hid' \\<Rightarrow> ('share1', 'share2', 'share3') share_user_record \\<Rightarrow> bool spmf)\"\n\ntype_synonym ('token', 'state',  'auth_token') hiding_adversary = \"(('token' \\<times> 'token') \\<times> 'state') spmf \\<times> ('state' \\<Rightarrow> 'auth_token' \\<Rightarrow> bool spmf)\"\n\ntype_synonym 'token' soundness_adversary = \"'token' \\<Rightarrow> 'token' spmf\"\n\nlocale identity_system =\n  fixes reg_enc_sens_attrs :: \"'sens_atrrs set \\<Rightarrow> 'enc_attrs spmf\" \\<comment> \\<open>The user encrypts their attributes before sending them to the government.\\<close> \n    and reg_govt_shares :: \"'attrs set \\<Rightarrow> 'enc_attrs \\<Rightarrow> (('share1, 'share2, 'share3) share_user_record \\<times> 'state_govt) spmf\"\n    and reg_govt_token :: \"'state_govt \\<Rightarrow> ('share1, 'share2, 'share3) share_user_record \\<Rightarrow> 'token spmf\"\n    \\<comment> \\<open>The government first produces the shares of the user record and then a token to be sent back to the user.\\<close>\n    and auth :: \"'token \\<Rightarrow> ('attrs, 'sens_atrrs, 'result) query \\<Rightarrow> 'auth_token spmf\" \n    \\<comment> \\<open>Authentication is run between a user and a service provider. \n    The user inputs their token, the service provider their desired query and an authorised token is returned. This is sent to the government.\\<close>\n    and ver :: \"'auth_token \\<Rightarrow> 'result spmf\"\n    \\<comment> \\<open>The government uses the authorised token to determine the response to the query.\\<close>\n    and valid_user :: \"'user \\<Rightarrow> bool\"\n    and valid_attrs :: \"('attrs set \\<times> 'sens_atrrs set) \\<Rightarrow> bool\" \n    and valid_token :: \"'token \\<Rightarrow> bool\"\n    and valid_query :: \"('attrs, 'sens_atrrs, 'result) query \\<Rightarrow> bool\"\n    and user_set :: \"'user set\"\n    and attrs_set :: \"('attrs set \\<times> 'sens_atrrs set) set\"\n    and users_attr_creation :: \"'user \\<Rightarrow> ('attrs set \\<times> 'sens_atrrs set)\"\n  assumes users_are_valid: \"user \\<in> user_set \\<longrightarrow> valid_user user\"\n    and atrrs_are_valid: \"attrs \\<in> attrs_set \\<longrightarrow> valid_attrs attrs\"\n    and user_set_not_empty: \"user_set \\<noteq> {}\"\n    and attrs_set_not_empty: \"attrs_set \\<noteq> {}\"\n    and bij_betw_users_attrs: \"bij_betw users_attr_creation user_set attrs_set\"\n    and lossless_reg_govt_token: \"lossless_spmf (reg_govt_token \\<sigma> S)\"\nbegin\n\nlemma all_users_valid: \"\\<forall> user. user \\<in> user_set \\<longrightarrow> valid_user user\"   \n  using users_are_valid by simp\n\nlemma all_attrs_valid: \"\\<forall> attrs. attrs \\<in> attrs_set \\<longrightarrow> valid_attrs attrs\"   \n  using atrrs_are_valid by simp\n\ntext\\<open>We define the registration phase using the fixes parameters for the user and government.\\<close>\n\ndefinition reg :: \"'user \\<Rightarrow> ('token \\<times> ('share1, 'share2, 'share3) share_user_record) spmf\" \n  where \"reg user = do {\n   let (attrs, sens_attrs) = users_attr_creation user;\n   enc_attrs \\<leftarrow> reg_enc_sens_attrs sens_attrs;\n   (S, \\<sigma>) \\<leftarrow> reg_govt_shares attrs enc_attrs;\n   token \\<leftarrow> reg_govt_token \\<sigma> S;\n   return_spmf (token, S)}\"\n\nsubsection\\<open>Functional Properties\\<close>\n\nlemma obtain_user_from_attrs:\n  fixes attrs\n  assumes \"attrs \\<in> attrs_set\"\n  obtains user where \"user \\<in> user_set\" and \"users_attr_creation user = attrs\"\n  using bij_betw_users_attrs[unfolded bij_betw_def] assms\n  by auto \n\nlemma obtain_attrs_from_user:\n  fixes user\n  assumes \"user \\<in> user_set\"\n  obtains attrs where \"attrs \\<in> attrs_set\" \"users_attr_creation user = attrs\"\n  using bij_betw_users_attrs[unfolded bij_betw_def] assms by blast\n\ntext\\<open>We require that that no two users, with different attributes, will yield the same tokens upon registration. This must be a property of the registration phase the attributes.\\<close>\n\ndefinition \"unique_users = (\\<forall> user1 user2. user1 \\<in> user_set \\<longrightarrow> user2 \\<in> user_set \\<longrightarrow> user1 \\<noteq> user2 \\<longrightarrow> reg user1 \\<noteq> reg user2)\"\n\ntext \\<open>The correctness property ensures if the IDentity system is carried out honestly the correct query result is returned.\\<close>\n\ndefinition correct_game :: \"'user \\<Rightarrow> ('attrs, 'sens_atrrs, 'result) query \\<Rightarrow> bool spmf\"\n  where \"correct_game user query = do {\n        let attrs = users_attr_creation user;\n        (token, enc_user_record) \\<leftarrow> reg user;\n        auth_token \\<leftarrow> auth token query;\n        b \\<leftarrow> ver auth_token;\n        return_spmf (b = query attrs)}\"  \n\ndefinition \"correct \\<longleftrightarrow> (\\<forall> user query. valid_user user \\<longrightarrow> valid_query query \\<longrightarrow> spmf (correct_game user query) True = 1)\"\n\n(*the output given to the adversary should be from after the registration phase, in particular the \nsecond output from the reg phase as this is what the government sees.*)\n\nprimrec sens_attrs_hiding_game :: \"('user, 'state_attr_hid, 'enc_attrs) attr_hiding_adversary \\<Rightarrow> bool spmf\"\n  where \n    \"sens_attrs_hiding_game (\\<A>1, \\<A>2) = TRY do {\n      ((user0, user1), \\<sigma>) \\<leftarrow> \\<A>1;\n      _ :: unit \\<leftarrow> assert_spmf (valid_user user0 \\<and> valid_user user1);\n      b \\<leftarrow> coin_spmf;\n      let (attrsb, sens_attrsb) = users_attr_creation (if b then user0 else user1);\n      enc_attrs_b \\<leftarrow> reg_enc_sens_attrs sens_attrsb;\n      b' \\<leftarrow> \\<A>2 \\<sigma> enc_attrs_b;\n      return_spmf (b' = b)} ELSE coin_spmf\"\n\nprimrec sens_attrs_hiding_game' :: \"('user, 'state_attr_hid, 'share1, 'share2, 'share3) attr_hiding_adversary' \\<Rightarrow> bool spmf\"\n  where \n    \"sens_attrs_hiding_game' (\\<A>1, \\<A>2) = TRY do {\n      ((user0, user1), \\<sigma>) \\<leftarrow> \\<A>1;\n      _ :: unit \\<leftarrow> assert_spmf (valid_user user0 \\<and> valid_user user1);\n      b :: bool \\<leftarrow> coin_spmf;\n      (token, S) \\<leftarrow> reg (if b then user0 else user1);\n      b' \\<leftarrow> \\<A>2 \\<sigma> S;\n      return_spmf (b' = b)} ELSE coin_spmf\"\n\ndefinition \"sens_attrs_hiding_advantage \\<A> = \\<bar>spmf (sens_attrs_hiding_game \\<A>) True - 1/2\\<bar>\"\n\ndefinition \"sens_attrs_hiding_advantage' \\<A> = \\<bar>spmf (sens_attrs_hiding_game' \\<A>) True - 1/2\\<bar>\"\n\ndefinition \"perfect_sens_attrs_hiding \\<A> \\<longleftrightarrow> sens_attrs_hiding_advantage \\<A> = 0\"\n\ndefinition \"perfect_sens_attrs_hiding' \\<A> \\<longleftrightarrow> sens_attrs_hiding_advantage' \\<A> = 0\"\n\ndefinition \"no_sens_attr \\<longleftrightarrow> (\\<forall> user. snd (users_attr_creation user) = {})\"\n\nlemma \n  assumes \"no_sens_attr\"\n  shows \"perfect_sens_attrs_hiding \\<A>\"\n  including monad_normalisation\nproof-\n  note [simp] = Let_def split_def \n  have \"\\<bar>spmf (sens_attrs_hiding_game \\<A>) True - 1/2\\<bar> = 0\"\n  proof-\n    obtain \\<A>1 and \\<A>2 where \\<A> [simp]: \"\\<A> = (\\<A>1, \\<A>2)\" by(cases \\<A>)\n    have \"sens_attrs_hiding_game (\\<A>1, \\<A>2) = TRY do {\n      ((user0, user1), \\<sigma>) \\<leftarrow> \\<A>1;\n      _ :: unit \\<leftarrow> assert_spmf (valid_user user0 \\<and> valid_user user1);\n      b \\<leftarrow> coin_spmf;\n      let (attrsb, sens_attrsb) = users_attr_creation (if b then user0 else user1);\n      enc_attrs_b \\<leftarrow> reg_enc_sens_attrs sens_attrsb;\n      b' \\<leftarrow> \\<A>2 \\<sigma> enc_attrs_b;\n      return_spmf (b' = b)} ELSE coin_spmf\"\n      by(simp add: sens_attrs_hiding_game_def)\n    also have \"... = TRY do {\n      ((user0, user1), \\<sigma>) \\<leftarrow> \\<A>1;\n      _ :: unit \\<leftarrow> assert_spmf (valid_user user0 \\<and> valid_user user1);\n      b :: bool \\<leftarrow> coin_spmf;\n      enc_attrs_b \\<leftarrow> reg_enc_sens_attrs {};\n      b' :: bool \\<leftarrow> \\<A>2 \\<sigma> enc_attrs_b;\n      return_spmf (b' = b)} ELSE coin_spmf\"\n      using assms[unfolded no_sens_attr_def] \n      by simp\n    also have \"... = TRY do {\n      ((user0, user1), \\<sigma>) \\<leftarrow> \\<A>1;\n      _ :: unit \\<leftarrow> assert_spmf (valid_user user0 \\<and> valid_user user1);\n      enc_attrs_b \\<leftarrow> reg_enc_sens_attrs {};\n      b' :: bool \\<leftarrow> \\<A>2 \\<sigma> enc_attrs_b;\n      map_spmf((=) b') coin_spmf} ELSE coin_spmf\"\n      by(simp add: map_spmf_conv_bind_spmf)\n    also have \"... = coin_spmf\" \n      by(auto simp add: bind_spmf_const map_eq_const_coin_spmf try_bind_spmf_lossless2' scale_bind_spmf weight_spmf_le_1 scale_scale_spmf)\n    ultimately show ?thesis  \n      by(simp add: spmf_of_set)\n  qed\n  thus ?thesis \n    by(simp add: perfect_sens_attrs_hiding_def sens_attrs_hiding_advantage_def)\nqed\n\ndefinition token_hiding_game :: \"('attrs, 'sens_atrrs, 'result) query \\<Rightarrow> ('token, 'state,  'auth_token) hiding_adversary \\<Rightarrow> bool spmf\"\n  where \n    \"token_hiding_game query \\<A> = do {\n      let (\\<A>1, \\<A>2) = \\<A>;\n      ((token0, token1), \\<sigma>) \\<leftarrow> \\<A>1;\n      _ :: unit \\<leftarrow> assert_spmf (valid_token token0 \\<and> valid_token token1);\n      b \\<leftarrow> coin_spmf;\n      auth_token \\<leftarrow> auth (if b then token1 else token0) query;\n      b' \\<leftarrow> \\<A>2 \\<sigma> auth_token;  \n      return_spmf (b = b')}\"\n\ndefinition \"token_hiding_advantage query \\<A> = (\\<bar>spmf (token_hiding_game query \\<A>) True - 1/2\\<bar>)\"\n\ndefinition \"perfect_hiding \\<A> \\<longleftrightarrow> (\\<forall> query. valid_query query \\<longrightarrow> token_hiding_advantage query \\<A> = 0)\" \n\ndefinition user_binding_game :: \"'user \\<Rightarrow> ('attrs, 'sens_atrrs, 'result) query \\<Rightarrow> 'token soundness_adversary \\<Rightarrow> bool spmf\"\n  where \n    \"user_binding_game user query \\<A> = do {\n      (token1, enc_user_record) \\<leftarrow> reg user;\n      token2 \\<leftarrow> \\<A> token1;\n      _ :: unit \\<leftarrow> assert_spmf (valid_token token2);\n      auth_token1 \\<leftarrow> auth token1 query;\n      auth_token2 \\<leftarrow> auth token2 query;\n      b :: 'result \\<leftarrow> ver auth_token1;\n      b' \\<leftarrow> ver auth_token2;\n      return_spmf (b \\<noteq> b')}\"\n\ndefinition \"user_binding_advantage user query \\<A> = \\<bar>spmf (user_binding_game user query \\<A>) True\\<bar>\"\n\ndefinition \"perfect_soundness \\<A> \\<longleftrightarrow> (\\<forall> user query. valid_user user \\<longrightarrow> valid_query query \\<longrightarrow> user_binding_advantage user query \\<A> = 0)\"\n\nend\n\nlocale identity_ind_cpa_base = enc: ind_cpa key_gen encrypt decrypt valid_plains \n  for key_gen :: \"('pk \\<times> 'sk) spmf\"\n    and encrypt :: \"'pk \\<Rightarrow> 'sens_atrrs set \\<Rightarrow> 'enc_attrs spmf\"\n    and decrypt :: \"'sk \\<Rightarrow> 'enc_attrs \\<Rightarrow> 'sens_atrrs set option\"\n    and valid_plains :: \"'sens_atrrs set \\<Rightarrow> 'sens_atrrs set \\<Rightarrow> bool\"\nbegin\n\ndefinition reg_enc_sens_attrs :: \"'sens_atrrs set \\<Rightarrow> 'enc_attrs spmf\"\n  where \n    \"reg_enc_sens_attrs sens_attrs = do {\n      (pk,sk) \\<leftarrow> key_gen;\n      encrypt pk sens_attrs}\"   \n\nend \n\nlocale id_ind_cpa = identity_ind_cpa_base + \n  id_sys: identity_system reg_enc_sens_attrs reg_govt_shares reg_govt_token auth ver valid_user valid_attrs valid_token valid_query user_set attrs_set users_attr_creation\n  for reg_govt_shares reg_govt_token auth ver valid_user valid_attrs valid_token valid_query user_set attrs_set users_attr_creation\n    + \n  assumes valid_user_valid_plains: \"\\<forall> u0 u1. valid_user u0 \\<and> valid_user u1  \\<longleftrightarrow> valid_plains (snd (users_attr_creation u0)) (snd (users_attr_creation u1))\"\nbegin\n\n\ndefinition sens_hiding_adversary1 :: \"(('m \\<times> 'm) \\<times> 'n) spmf \\<Rightarrow> 'a \\<Rightarrow> (('c set \\<times> 'c set) \\<times> 'n) spmf\"\n  where \"sens_hiding_adversary1 \\<A>1 pk = do {\n    ((u0,u1), \\<sigma>) \\<leftarrow> \\<A>1;\n    _ :: unit \\<leftarrow> assert_spmf (valid_user u0 \\<and> valid_user u1);\n    let sens_set0 = snd (users_attr_creation u0);\n    let sens_set1 = snd (users_attr_creation u1);\n    return_spmf ((sens_set0, sens_set1), \\<sigma>)}\"\n\ndefinition sens_hiding_adversary2 :: \"('n \\<Rightarrow> 'd \\<Rightarrow> bool spmf) \\<Rightarrow> 'd \\<Rightarrow> 'n \\<Rightarrow> bool spmf\"\n  where \"sens_hiding_adversary2 \\<A>2 enc \\<sigma> = \\<A>2 \\<sigma> enc\"\n\nfun sens_hiding_adversary:: \"(('m \\<times> 'm) \\<times> 'n) spmf \\<times> ('n \\<Rightarrow> 'd \\<Rightarrow> bool spmf) \\<Rightarrow> ('a \\<Rightarrow> (('c set \\<times> 'c set) \\<times> 'n) spmf) \\<times> ('d \\<Rightarrow> 'n \\<Rightarrow> bool spmf)\"\n  where \"sens_hiding_adversary (\\<A>1, \\<A>2) = (sens_hiding_adversary1 \\<A>1, sens_hiding_adversary2 \\<A>2)\"\n\nlemma if_cases_sens_hiding_attrs:\n  shows \"(if b then fst (fst ((snd (users_attr_creation (fst (fst y))), snd (users_attr_creation (snd (fst y)))), snd y))\n             else snd (fst ((snd (users_attr_creation (fst (fst y))), snd (users_attr_creation (snd (fst y)))), snd y))) =\n                 snd (users_attr_creation (if b then fst (fst y) else snd (fst y)))\"\n  by(cases b; auto)\ndeclare[[show_types]]\nterm \"enc.advantage\"\nterm \"id_sys.sens_attrs_hiding_advantage\"\nlemma sens_attrs_hiding_reduce_to_ind_cpa:\n  shows \"id_sys.sens_attrs_hiding_advantage \\<A> = enc.advantage (sens_hiding_adversary \\<A>)\"\n  unfolding id_sys.reg_def id_sys.sens_attrs_hiding_advantage_def enc.advantage_def enc.ind_cpa_def id_sys.sens_attrs_hiding_game_def reg_enc_sens_attrs_def\n  including monad_normalisation\nproof-\n  note [simp] = split_def Let_def\n  obtain \\<A>1 and \\<A>2 where \\<A> [simp]: \"\\<A> = (\\<A>1, \\<A>2)\" by(cases \\<A>)\n  have \"id_sys.sens_attrs_hiding_advantage (\\<A>1, \\<A>2) = enc.advantage (sens_hiding_adversary1 \\<A>1, sens_hiding_adversary2 \\<A>2)\"\n  proof-\n    have \"TRY coin_spmf \\<bind>\n           (\\<lambda>b. key_gen \\<bind>\n                 (\\<lambda>y. \\<A>1 \\<bind>\n                       (\\<lambda>p. encrypt (fst y) (snd (users_attr_creation (if b then fst (fst p) else snd (fst p)))) \\<bind>\n                             (\\<lambda>enc_attrs_b.\n                                 \\<A>2 (snd p) enc_attrs_b \\<bind> (\\<lambda>b'. assert_spmf (valid_user (fst (fst p)) \\<and> valid_user (snd (fst p))) \n                                     \\<bind> (\\<lambda>_ :: unit. return_spmf (b' = b))))))) ELSE coin_spmf = \n          TRY coin_spmf \\<bind>\n                     (\\<lambda>b. key_gen \\<bind>\n                           (\\<lambda>p. \\<A>1 \\<bind>\n                                 (\\<lambda>y. encrypt (fst p) (snd (users_attr_creation (if b then fst (fst y) else snd (fst y)))) \\<bind>\n                                       (\\<lambda>cipher.\n                                           \\<A>2 (snd y) cipher \\<bind>\n                                           (\\<lambda>b'. assert_spmf (valid_user (fst (fst y)) \\<and> valid_user (snd (fst y))) \\<bind>\n                                                  (\\<lambda>ya :: unit. assert_spmf (valid_plains (snd (users_attr_creation (fst (fst y)))) (snd (users_attr_creation (snd (fst y))))) \\<bind>\n                                                         (\\<lambda>_ :: unit. return_spmf (b = b')))))))) ELSE coin_spmf\"\n      apply(intro try_spmf_cong bind_spmf_cong[OF refl]; clarsimp?)+ using valid_user_valid_plains by force\n    thus ?thesis\n      unfolding id_sys.sens_attrs_hiding_advantage_def enc.advantage_def id_sys.sens_attrs_hiding_game_def \n        enc.ind_cpa_def reg_enc_sens_attrs_def sens_hiding_adversary1_def sens_hiding_adversary2_def\n      by(auto simp add: if_cases_sens_hiding_attrs) \n  qed\n  then show ?thesis by auto\nqed\n\ncorollary perfect_sens_attrs_hiding:\n  \"id_sys.perfect_sens_attrs_hiding \\<A>\" if \"enc.advantage (sens_hiding_adversary \\<A>) = 0\"\n  unfolding id_sys.perfect_sens_attrs_hiding_def\n  by (simp add: sens_attrs_hiding_reduce_to_ind_cpa that)\n\nend\n\n(*To consider token hiding we need to define the token value that is returned to the user in the registration phase as being an encrypted value*)\n\nend", "meta": {"author": "Davetbutler", "repo": "Privacy-ID", "sha": "a9d67b9ef02dea9ae51e5c6de8630666c4d0a148", "save_path": "github-repos/isabelle/Davetbutler-Privacy-ID", "path": "github-repos/isabelle/Davetbutler-Privacy-ID/Privacy-ID-a9d67b9ef02dea9ae51e5c6de8630666c4d0a148/ID_system_formalisation/IDentity.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.600188359260205, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.2930620098766091}}
{"text": "section {*FUNCTION\\_\\_DPDA\\_EA\\_OPT\\_\\_DPDA\\_ENFORCE\\_ACCESSIBLE\\_OPT*}\ntheory\n  FUNCTION__DPDA_EA_OPT__DPDA_ENFORCE_ACCESSIBLE_OPT\n\nimports\n  PRJ_12_08_04__ENTRY\n\nbegin\n\nlemma F_DPDA_EA_OPT__preserves_DPDA: \"\n  valid_dpda G\n  \\<Longrightarrow> valid_dpda (F_DPDA_EA_OPT G)\"\n  apply(simp add: F_DPDA_EA_OPT_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac G=\"G\" and E=\"(F_DPDA_DRE G (Suc 0))\" in F_EPDA_RE__SOUND2)\n   apply(simp add: F_EPDA_RE__SpecInput2_def)\n   apply(subgoal_tac \"X\" for X)\n    prefer 2\n    apply(rule_tac G=\"G\" and k=\"Suc 0\" in F_DPDA_DRE__SOUND)\n     apply(simp add: F_DPDA_DRE__SpecInput_def)\n    apply(simp add: F_DPDA_DRE__SpecOutput_def)\n   apply(simp add: F_DPDA_DRE__SpecOutput_def)\n   apply (metis epdaS_required_edges__vs__epdaH_required_edges valid_dpda_def valid_pda_def)\n  apply(simp add: F_EPDA_RE__SpecOutput2_def)\n  done\n\nlemma F_DPDA_EA_OPT__preserves_lang: \"\n  valid_dpda G\n  \\<Longrightarrow> epdaS.marked_language G = epdaS.marked_language (F_DPDA_EA_OPT G)\"\n  apply(simp add: F_DPDA_EA_OPT_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac G=\"G\" and E=\"(F_DPDA_DRE G (Suc 0))\" in F_EPDA_RE__SOUND2)\n   apply(simp add: F_EPDA_RE__SpecInput2_def)\n   apply(subgoal_tac \"X\" for X)\n    prefer 2\n    apply(rule_tac G=\"G\" and k=\"Suc 0\" in F_DPDA_DRE__SOUND)\n     apply(simp add: F_DPDA_DRE__SpecInput_def)\n    apply(simp add: F_DPDA_DRE__SpecOutput_def)\n   apply(simp add: F_DPDA_DRE__SpecOutput_def)\n   apply (metis epdaS_required_edges__vs__epdaH_required_edges valid_dpda_def valid_pda_def)\n  apply(simp add: F_EPDA_RE__SpecOutput2_def)\n  done\n\nlemma F_DPDA_EA_OPT__preserves_unmarked_language: \"\n  valid_dpda G\n  \\<Longrightarrow> epdaH.Nonblockingness_branching G\n  \\<Longrightarrow> epdaS.unmarked_language G = epdaS.unmarked_language (F_DPDA_EA_OPT G)\"\n  apply(simp add: F_DPDA_EA_OPT_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac G=\"G\" and E=\"(F_DPDA_DRE G (Suc 0))\" in F_EPDA_RE__SOUND2)\n   apply(simp add: F_EPDA_RE__SpecInput2_def)\n   apply(subgoal_tac \"X\" for X)\n    prefer 2\n    apply(rule_tac G=\"G\" and k=\"Suc 0\" in F_DPDA_DRE__SOUND)\n     apply(simp add: F_DPDA_DRE__SpecInput_def)\n    apply(simp add: F_DPDA_DRE__SpecOutput_def)\n   apply(simp add: F_DPDA_DRE__SpecOutput_def)\n   apply (metis epdaS_required_edges__vs__epdaH_required_edges valid_dpda_def valid_pda_def)\n  apply(simp add: F_EPDA_RE__SpecOutput2_def)\n  apply(force)\n  done\n\nlemma F_DPDA_EA_OPT__enforces_accessible: \"\n  valid_dpda G\n  \\<Longrightarrow> epdaS.accessible (F_DPDA_EA_OPT G)\"\n  apply(simp add: F_DPDA_EA_OPT_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac G=\"G\" and E=\"(F_DPDA_DRE G (Suc 0))\" in F_EPDA_RE__SOUND2)\n   apply(simp add: F_EPDA_RE__SpecInput2_def)\n   apply(subgoal_tac \"X\" for X)\n    prefer 2\n    apply(rule_tac G=\"G\" and k=\"Suc 0\" in F_DPDA_DRE__SOUND)\n     apply(simp add: F_DPDA_DRE__SpecInput_def)\n    apply(simp add: F_DPDA_DRE__SpecOutput_def)\n   apply(simp add: F_DPDA_DRE__SpecOutput_def)\n   apply (metis epdaS_required_edges__vs__epdaH_required_edges valid_dpda_def valid_pda_def)\n  apply(simp add: F_EPDA_RE__SpecOutput2_def)\n  done\n\nlemma F_DPDA_EA_OPT__preserves_epdaH_no_livelocks_from_marking_states: \"\n  valid_dpda G\n  \\<Longrightarrow> epdaH_no_livelocks_from_marking_states G\n  \\<Longrightarrow> epdaH_no_livelocks_from_marking_states (F_DPDA_EA_OPT G)\"\n  apply(simp add: epdaH_no_livelocks_from_marking_states_def F_DPDA_EA_OPT_def)\n  apply(clarsimp)\n  apply(rename_tac d n e c)(*strict*)\n  apply(erule_tac\n      x=\"d\"\n      in allE)\n  apply(erule_tac\n      x=\"n\"\n      in allE)\n  apply(clarsimp)\n  apply(erule impE)\n   apply(rename_tac d n e c)(*strict*)\n   prefer 2\n   apply(simp add: F_EPDA_R_def F_EPDA_RE_def F_DPDA_DAE_def Let_def)\n  apply(rename_tac d n e c)(*strict*)\n  apply(rule epdaH.derivation_initialI)\n   apply(rename_tac d n e c)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac d n e c ca)(*strict*)\n   apply(simp add: get_configuration_def epdaH_initial_configurations_def epdaH.derivation_initial_def)\n   apply(rule conjI)\n    apply(rename_tac d n e c ca)(*strict*)\n    apply(simp add: F_ALT_EPDA_RE_def F_DPDA_DAE_def Let_def F_EPDA_R_def F_EPDA_RE_def)\n   apply(rename_tac d n e c ca)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d n e c ca)(*strict*)\n    apply(simp add: F_ALT_EPDA_RE_def F_DPDA_DAE_def Let_def F_EPDA_R_def F_EPDA_RE_def)\n   apply(rename_tac d n e c ca)(*strict*)\n   apply(simp add: F_ALT_EPDA_RE_def F_DPDA_DAE_def Let_def epdaH_configurations_def valid_dpda_def valid_pda_def valid_epda_def)\n   apply(clarsimp)\n   apply(simp add: F_ALT_EPDA_RE_def F_DPDA_DAE_def Let_def F_EPDA_R_def F_EPDA_RE_def)\n  apply(rename_tac d n e c)(*strict*)\n  apply(simp add: epdaH.derivation_initial_def)\n  apply(clarsimp)\n  apply(thin_tac \"d n = Some (pair (Some e) c)\")\n  apply(thin_tac \"case d 0 of None \\<Rightarrow> False\n       | Some (pair e c) \\<Rightarrow>\n           c \\<in> epdaH_initial_configurations (F_EPDA_RE G (F_DPDA_DRE G (Suc 0))) \\<and> e = None\")\n  apply(rename_tac d n e c)(*strict*)\n  apply(thin_tac \"edge_src e \\<in> epda_marking (F_EPDA_RE G (F_DPDA_DRE G (Suc 0)))\")\n  apply(thin_tac \"edge_event e = None\")\n  apply(simp (no_asm) add: epdaH.derivation_def)\n  apply(rename_tac d)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i)(*strict*)\n  apply(case_tac i)\n   apply(rename_tac d i)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d)(*strict*)\n   apply(simp add: epdaH.derivation_def)\n   apply(erule_tac\n      x=\"0\"\n      in allE)\n   apply(clarsimp)\n  apply(rename_tac d i nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d nat)(*strict*)\n  apply(case_tac \"d (Suc nat)\")\n   apply(rename_tac d nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d nat a)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d nat a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      n=\"nat\"\n      and m=\"Suc nat\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac d nat a)(*strict*)\n     apply(force)\n    apply(rename_tac d nat a)(*strict*)\n    apply(force)\n   apply(rename_tac d nat a)(*strict*)\n   apply(force)\n  apply(rename_tac d nat a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d nat e1 e2 c1 c2)(*strict*)\n  apply(simp add: epdaH_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac d nat e1 e2 c1 c2 w)(*strict*)\n  apply(simp add: F_ALT_EPDA_RE_def F_DPDA_DAE_def Let_def F_EPDA_R_def F_EPDA_RE_def)\n  done\n\ndefinition F_DPDA_EA_OPT__SpecInput :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_EA_OPT__SpecInput G \\<equiv>\n  valid_dpda G\n  \\<and> nonblockingness_language (epdaS.unmarked_language G) (epdaS.marked_language G)\n  \\<and> epdaH_no_livelocks_from_marking_states G\"\n\ndefinition F_DPDA_EA_OPT__SpecOutput :: \"\n  ('p, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stackx) epda\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_EA_OPT__SpecOutput Gi Go \\<equiv>\n  valid_dpda Go\n  \\<and> epdaS.marked_language Gi = epdaS.marked_language Go\n  \\<and> epdaS.unmarked_language Gi = epdaS.unmarked_language Go\n  \\<and> nonblockingness_language (epdaS.unmarked_language Go) (epdaS.marked_language Go)\n  \\<and> epdaS.accessible Go\n  \\<and> epdaH_no_livelocks_from_marking_states Go\"\n\ntheorem F_DPDA_EA_OPT__SOUND: \"\n  F_DPDA_EA_OPT__SpecInput G\n  \\<Longrightarrow> F_DPDA_EA_OPT__SpecOutput G (F_DPDA_EA_OPT G)\"\n  apply(simp add: F_DPDA_EA_OPT__SpecInput_def F_DPDA_EA_OPT__SpecOutput_def)\n  apply(rule conjI)\n   apply (metis F_DPDA_EA_OPT__preserves_DPDA)\n  apply(rule context_conjI)\n   apply(rule F_DPDA_EA_OPT__preserves_lang)\n   apply(force)\n  apply(rule context_conjI)\n   apply(subgoal_tac \"epdaS.unmarked_language G = epdaS.unmarked_language (F_DPDA_EA_OPT G)\")\n    apply(force)\n   apply(rule F_DPDA_EA_OPT__preserves_unmarked_language)\n    apply(force)\n   apply (metis epdaH_operational_Nonblockingness_from_language_Nonblockingness epda_inter_semantic_relationship valid_dpda_def valid_pda_def)\n  apply(rule context_conjI)\n   apply(subgoal_tac \"epdaS.unmarked_language G = epdaS.unmarked_language (F_DPDA_EA_OPT G)\")\n    apply(force)\n   apply(rule F_DPDA_EA_OPT__preserves_unmarked_language)\n    apply(force)\n   apply (metis epdaH_operational_Nonblockingness_from_language_Nonblockingness epda_inter_semantic_relationship valid_dpda_def valid_pda_def)\n  apply(rule conjI)\n   apply(rule F_DPDA_EA_OPT__enforces_accessible)\n   apply(force)\n  apply(rule F_DPDA_EA_OPT__preserves_epdaH_no_livelocks_from_marking_states)\n   apply(force)\n  apply(force)\n  done\n\nlemma F_DPDA_EA_OPT__constructs_epda_sub: \"\n  valid_epda G\n  \\<Longrightarrow> epda_sub (F_DPDA_EA_OPT G) G\"\n  apply(simp add: epda_sub_def F_EPDA_R_def F_DPDA_EA_OPT_def F_EPDA_RE_def Let_def)\n  apply(simp add: valid_epda_def)\n  apply(clarsimp)\n  done\n\ntheorem F_DPDA_EA_OPT__preserves_not_livelock: \"\n  valid_epda G\n  \\<Longrightarrow> \\<not> epdaH_livelock G\n  \\<Longrightarrow> \\<not> epdaH_livelock (F_DPDA_EA_OPT G)\"\n  apply(rule epda_sub_preserves_not_livelock)\n     apply(simp add: F_DPDA_EA_OPT_def F_EPDA_RE_def)\n     apply(rule F_EPDA_R_preserves_valid_epda)\n       apply(force)\n      prefer 2\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(rule F_DPDA_EA_OPT__constructs_epda_sub)\n   apply(force)\n  apply(force)\n  done\n\nhide_fact F_DPDA_EA_OPT__preserves_DPDA\nhide_fact F_DPDA_EA_OPT__preserves_lang\nhide_fact F_DPDA_EA_OPT__preserves_unmarked_language\nhide_fact F_DPDA_EA_OPT__enforces_accessible\nhide_fact F_DPDA_EA_OPT__preserves_epdaH_no_livelocks_from_marking_states\n\nend\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_12_08_04/FUNCTION__DPDA_EA_OPT__DPDA_ENFORCE_ACCESSIBLE_OPT.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.600188359260205, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.2930620098766091}}
{"text": "(*\n(C) Copyright Andreas Viktor Hess, DTU, 2020\n(C) Copyright Sebastian A. Mödersheim, DTU, 2020\n(C) Copyright Achim D. Brucker, University of Exeter, 2020\n(C) Copyright Anders Schlichtkrull, DTU, 2020\n\nAll Rights Reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\n- Redistributions of source code must retain the above copyright\n  notice, this list of conditions and the following disclaimer.\n\n- Redistributions in binary form must reproduce the above copyright\n  notice, this list of conditions and the following disclaimer in the\n  documentation and/or other materials provided with the distribution.\n\n- Neither the name of the copyright holder nor the names of its\n  contributors may be used to endorse or promote products\n  derived from this software without specific prior written\n  permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\nLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\nA PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\nOWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\nLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\nTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n*)\n\n(*  Title:      Term_Implication.thy\n    Author:     Andreas Viktor Hess, DTU\n    Author:     Sebastian A. Mödersheim, DTU\n    Author:     Achim D. Brucker, University of Exeter\n    Author:     Anders Schlichtkrull, DTU\n*)\n\nsection\\<open>Term Implication\\<close>\ntheory Term_Implication\n  imports Stateful_Protocol_Model Term_Variants\nbegin\n\nsubsection \\<open>Single Term Implications\\<close>\ndefinition timpl_apply_term (\"\\<langle>_ --\\<guillemotright> _\\<rangle>\\<langle>_\\<rangle>\") where\n  \"\\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>t\\<rangle> \\<equiv> term_variants ((\\<lambda>_. [])(Abs a := [Abs b])) t\"\n\ndefinition timpl_apply_terms (\"\\<langle>_ --\\<guillemotright> _\\<rangle>\\<langle>_\\<rangle>\\<^sub>s\\<^sub>e\\<^sub>t\") where\n  \"\\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>M\\<rangle>\\<^sub>s\\<^sub>e\\<^sub>t \\<equiv> \\<Union>((set o timpl_apply_term a b) ` M)\"\n\nlemma timpl_apply_Fun:\n  assumes \"\\<And>i. i < length T \\<Longrightarrow> S ! i \\<in> set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>T ! i\\<rangle>\"\n    and \"length T = length S\"\n  shows \"Fun f S \\<in> set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>Fun f T\\<rangle>\"\nusing assms term_variants_Fun term_variants_pred_iff_in_term_variants\nby (metis timpl_apply_term_def)\n\nlemma timpl_apply_Abs:\n  assumes \"\\<And>i. i < length T \\<Longrightarrow> S ! i \\<in> set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>T ! i\\<rangle>\"\n    and \"length T = length S\"\n  shows \"Fun (Abs b) S \\<in> set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>Fun (Abs a) T\\<rangle>\"\nusing assms(1) term_variants_P[OF assms(2), of \"(\\<lambda>_. [])(Abs a := [Abs b])\" \"Abs b\" \"Abs a\"]\nunfolding timpl_apply_term_def term_variants_pred_iff_in_term_variants[symmetric]\nby fastforce\n\nlemma timpl_apply_refl: \"t \\<in> set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>t\\<rangle>\"\nunfolding timpl_apply_term_def\nby (metis term_variants_pred_refl term_variants_pred_iff_in_term_variants)\n\nlemma timpl_apply_const: \"Fun (Abs b) [] \\<in> set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>Fun (Abs a) []\\<rangle>\"\nusing term_variants_pred_iff_in_term_variants term_variants_pred_const\nunfolding timpl_apply_term_def by auto\n\nlemma timpl_apply_const':\n  \"c = a \\<Longrightarrow> set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>Fun (Abs c) []\\<rangle> = {Fun (Abs b) [], Fun (Abs c) []}\"\n  \"c \\<noteq> a \\<Longrightarrow> set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>Fun (Abs c) []\\<rangle> = {Fun (Abs c) []}\"\nusing term_variants_pred_const_cases[of \"(\\<lambda>_. [])(Abs a := [Abs b])\" \"Abs c\"]\n      term_variants_pred_iff_in_term_variants[of \"(\\<lambda>_. [])(Abs a := [Abs b])\"]\nunfolding timpl_apply_term_def by auto\n\nlemma timpl_apply_term_subst:\n  \"s \\<in> set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>t\\<rangle> \\<Longrightarrow> s \\<cdot> \\<delta> \\<in> set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>t \\<cdot> \\<delta>\\<rangle>\"\nby (metis term_variants_pred_iff_in_term_variants term_variants_pred_subst timpl_apply_term_def)\n\nlemma timpl_apply_inv:\n  assumes \"Fun h S \\<in> set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>Fun f T\\<rangle>\"\n  shows \"length T = length S\"\n    and \"\\<And>i. i < length T \\<Longrightarrow> S ! i \\<in> set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>T ! i\\<rangle>\"\n    and \"f \\<noteq> h \\<Longrightarrow> f = Abs a \\<and> h = Abs b\"\nusing assms term_variants_pred_iff_in_term_variants[of \"(\\<lambda>_. [])(Abs a := [Abs b])\"]\nunfolding timpl_apply_term_def\nby (metis (full_types) term_variants_pred_inv(1),\n    metis (full_types) term_variants_pred_inv(2),\n    fastforce dest: term_variants_pred_inv(3))\n\nlemma timpl_apply_inv':\n  assumes \"s \\<in> set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>Fun f T\\<rangle>\"\n  shows \"\\<exists>g S. s = Fun g S\"\nproof -\n  have *: \"term_variants_pred ((\\<lambda>_. [])(Abs a := [Abs b])) (Fun f T) s\"\n    using assms term_variants_pred_iff_in_term_variants[of \"(\\<lambda>_. [])(Abs a := [Abs b])\"]\n    unfolding timpl_apply_term_def by force\n  show ?thesis using term_variants_pred.cases[OF *, of ?thesis] by fastforce\nqed\n\nlemma timpl_apply_term_Var_iff:\n  \"Var x \\<in> set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>t\\<rangle> \\<longleftrightarrow> t = Var x\"\nusing term_variants_pred_inv_Var term_variants_pred_iff_in_term_variants\nunfolding timpl_apply_term_def by metis\n\n\n\nsubsection \\<open>Term Implication Closure\\<close>\ninductive_set timpl_closure for t TI where\n  FP: \"t \\<in> timpl_closure t TI\"\n| TI: \"\\<lbrakk>u \\<in> timpl_closure t TI; (a,b) \\<in> TI; term_variants_pred ((\\<lambda>_. [])(Abs a := [Abs b])) u s\\<rbrakk>\n       \\<Longrightarrow> s \\<in> timpl_closure t TI\"\n\ndefinition \"timpl_closure_set M TI \\<equiv> (\\<Union>t \\<in> M. timpl_closure t TI)\"\n\ninductive_set timpl_closure'_step for TI where\n  \"\\<lbrakk>(a,b) \\<in> TI; term_variants_pred ((\\<lambda>_. [])(Abs a := [Abs b])) t s\\<rbrakk>\n    \\<Longrightarrow> (t,s) \\<in> timpl_closure'_step TI\"\n\ndefinition \"timpl_closure' TI \\<equiv> (timpl_closure'_step TI)\\<^sup>*\"\n\ndefinition comp_timpl_closure where\n  \"comp_timpl_closure FP TI \\<equiv>\n    let f = \\<lambda>X. FP \\<union> (\\<Union>x \\<in> X. \\<Union>(a,b) \\<in> TI. set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>x\\<rangle>)\n    in while (\\<lambda>X. f X \\<noteq> X) f {}\"\n\ndefinition comp_timpl_closure_list where\n  \"comp_timpl_closure_list FP TI \\<equiv>\n    let f = \\<lambda>X. remdups (concat (map (\\<lambda>x. concat (map (\\<lambda>(a,b). \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>x\\<rangle>) TI)) X))\n    in while (\\<lambda>X. set (f X) \\<noteq> set X) f FP\"\n\nlemma timpl_closure_setI:\n  \"t \\<in> M \\<Longrightarrow> t \\<in> timpl_closure_set M TI\"\nunfolding timpl_closure_set_def by (auto intro: timpl_closure.FP)\n\nlemma timpl_closure_set_empty_timpls:\n  \"timpl_closure t {} = {t}\" (is \"?A = ?B\")\nproof (intro subset_antisym subsetI)\n  fix s show \"s \\<in> ?A \\<Longrightarrow> s \\<in> ?B\"\n    by (induct s rule: timpl_closure.induct) auto\nqed (simp add: timpl_closure.FP)\n\nlemmas timpl_closure_set_is_timpl_closure_union = meta_eq_to_obj_eq[OF timpl_closure_set_def]\n\nlemma term_variants_pred_eq_case_Abs:\n  fixes a b\n  defines \"P \\<equiv> (\\<lambda>_. [])(Abs a := [Abs b])\"\n  assumes \"term_variants_pred P t s\" \"\\<forall>f \\<in> funs_term s. \\<not>is_Abs f\"\n  shows \"t = s\"\nusing assms(2,3) P_def\nproof (induction P t s rule: term_variants_pred.induct)\n  case (term_variants_Fun T S f)\n  have \"\\<not>is_Abs h\" when i: \"i < length S\" and h: \"h \\<in> funs_term (S ! i)\" for i h\n    using i h term_variants_Fun.hyps(4) by auto\n  hence \"T ! i = S ! i\" when i: \"i < length T\" for i using i term_variants_Fun.hyps(1,3) by auto\n  hence \"T = S\" using term_variants_Fun.hyps(1) nth_equalityI[of T S] by fast\n  thus ?case using term_variants_Fun.hyps(1) by blast\nqed (simp_all add: term_variants_pred_refl)\n\nlemma timpl_closure'_step_inv:\n  assumes \"(t,s) \\<in> timpl_closure'_step TI\"\n  obtains a b where \"(a,b) \\<in> TI\" \"term_variants_pred ((\\<lambda>_. [])(Abs a := [Abs b])) t s\"\nusing assms by (auto elim: timpl_closure'_step.cases)\n\nlemma timpl_closure_mono:\n  assumes \"TI \\<subseteq> TI'\"\n  shows \"timpl_closure t TI \\<subseteq> timpl_closure t TI'\"\nproof\n  fix s show \"s \\<in> timpl_closure t TI \\<Longrightarrow> s \\<in> timpl_closure t TI'\"\n    apply (induct rule: timpl_closure.induct)\n    using assms by (auto intro: timpl_closure.intros)\nqed\n\nlemma timpl_closure_set_mono:\n  assumes \"M \\<subseteq> M'\" \"TI \\<subseteq> TI'\"\n  shows \"timpl_closure_set M TI \\<subseteq> timpl_closure_set M' TI'\"\nusing assms(1) timpl_closure_mono[OF assms(2)] unfolding timpl_closure_set_def by fast\n\nlemma timpl_closure_idem:\n  \"timpl_closure_set (timpl_closure t TI) TI = timpl_closure t TI\" (is \"?A = ?B\")\nproof\n  have \"s \\<in> timpl_closure t TI\"\n    when \"s \\<in> timpl_closure u TI\" \"u \\<in> timpl_closure t TI\"\n    for s u\n    using that\n    by (induction rule: timpl_closure.induct)\n       (auto intro: timpl_closure.intros)\n  thus \"?A \\<subseteq> ?B\" unfolding timpl_closure_set_def by blast\n\n  show \"?B \\<subseteq> ?A\"\n    unfolding timpl_closure_set_def\n    by (blast intro: timpl_closure.FP)\nqed\n\nlemma timpl_closure_set_idem:\n  \"timpl_closure_set (timpl_closure_set M TI) TI = timpl_closure_set M TI\"\nusing timpl_closure_idem[of _ TI]unfolding timpl_closure_set_def by auto\n\nlemma timpl_closure_set_mono_timpl_closure_set:\n  assumes N: \"N \\<subseteq> timpl_closure_set M TI\"\n  shows \"timpl_closure_set N TI \\<subseteq> timpl_closure_set M TI\"\nusing timpl_closure_set_mono[OF N, of TI TI] timpl_closure_set_idem[of M TI]\nby simp\n\nlemma timpl_closure_is_timpl_closure':\n  \"s \\<in> timpl_closure t TI \\<longleftrightarrow> (t,s) \\<in> timpl_closure' TI\"\nproof\n  show \"s \\<in> timpl_closure t TI \\<Longrightarrow> (t,s) \\<in> timpl_closure' TI\"\n    unfolding timpl_closure'_def\n    by (induct rule: timpl_closure.induct)\n       (auto intro: rtrancl_into_rtrancl timpl_closure'_step.intros)\n\n  show \"(t,s) \\<in> timpl_closure' TI \\<Longrightarrow> s \\<in> timpl_closure t TI\"\n    unfolding timpl_closure'_def\n    by (induct rule: rtrancl_induct)\n       (auto dest: timpl_closure'_step_inv\n             intro: timpl_closure.FP timpl_closure.TI)\nqed\n\nlemma timpl_closure'_mono:\n  assumes \"TI \\<subseteq> TI'\"\n  shows \"timpl_closure' TI \\<subseteq> timpl_closure' TI'\"\nusing timpl_closure_mono[OF assms]\n      timpl_closure_is_timpl_closure'[of _ _ TI]\n      timpl_closure_is_timpl_closure'[of _ _ TI']\nby fast\n\nlemma timpl_closureton_is_timpl_closure:\n  \"timpl_closure_set {t} TI = timpl_closure t TI\"\nby (simp add: timpl_closure_set_is_timpl_closure_union)\n\nlemma timpl_closure'_timpls_trancl_subset:\n  \"timpl_closure' (c\\<^sup>+) \\<subseteq> timpl_closure' c\"\nunfolding timpl_closure'_def\nproof\n  fix s t::\"(('a,'b,'c) prot_fun,'d) term\"\n  show \"(s,t) \\<in> (timpl_closure'_step (c\\<^sup>+))\\<^sup>* \\<Longrightarrow> (s,t) \\<in> (timpl_closure'_step c)\\<^sup>*\"\n  proof (induction rule: rtrancl_induct)\n    case (step u t)\n    obtain a b where ab:\n        \"(a,b) \\<in> c\\<^sup>+\" \"term_variants_pred ((\\<lambda>_. [])(Abs a := [Abs b])) u t\"\n      using step.hyps(2) timpl_closure'_step_inv by blast\n    hence \"(u,t) \\<in> (timpl_closure'_step c)\\<^sup>*\"\n    proof (induction arbitrary: t rule: trancl_induct)\n      case (step d e)\n      obtain s where s:\n          \"term_variants_pred ((\\<lambda>_. [])(Abs a := [Abs d])) u s\"\n          \"term_variants_pred ((\\<lambda>_. [])(Abs d := [Abs e])) s t\"\n        using term_variants_pred_dense'[OF step.prems, of \"Abs d\"] by blast\n\n      have \"(u,s) \\<in> (timpl_closure'_step c)\\<^sup>*\"\n           \"(s,t) \\<in> timpl_closure'_step c\"\n        using step.hyps(2) s(2) step.IH[OF s(1)]\n        by (auto intro: timpl_closure'_step.intros)\n      thus ?case by simp\n    qed (auto intro: timpl_closure'_step.intros)\n    thus ?case using step.IH by simp\n  qed simp\nqed\n\nlemma timpl_closure'_timpls_trancl_subset':\n  \"timpl_closure' {(a,b) \\<in> c\\<^sup>+. a \\<noteq> b} \\<subseteq> timpl_closure' c\"\nusing timpl_closure'_timpls_trancl_subset\n      timpl_closure'_mono[of \"{(a,b) \\<in> c\\<^sup>+. a \\<noteq> b}\" \"c\\<^sup>+\"]\nby fast\n\nlemma timpl_closure_set_timpls_trancl_subset:\n  \"timpl_closure_set M (c\\<^sup>+) \\<subseteq> timpl_closure_set M c\"\nusing timpl_closure'_timpls_trancl_subset[of c]\n      timpl_closure_is_timpl_closure'[of _ _ c]\n      timpl_closure_is_timpl_closure'[of _ _ \"c\\<^sup>+\"]\n      timpl_closure_set_is_timpl_closure_union[of M c]\n      timpl_closure_set_is_timpl_closure_union[of M \"c\\<^sup>+\"]\nby fastforce\n\nlemma timpl_closure_set_timpls_trancl_subset':\n  \"timpl_closure_set M {(a,b) \\<in> c\\<^sup>+. a \\<noteq> b} \\<subseteq> timpl_closure_set M c\"\nusing timpl_closure'_timpls_trancl_subset'[of c]\n      timpl_closure_is_timpl_closure'[of _ _ c]\n      timpl_closure_is_timpl_closure'[of _ _ \"{(a,b) \\<in> c\\<^sup>+. a \\<noteq> b}\"]\n      timpl_closure_set_is_timpl_closure_union[of M c]\n      timpl_closure_set_is_timpl_closure_union[of M \"{(a,b) \\<in> c\\<^sup>+. a \\<noteq> b}\"]\nby fastforce\n\nlemma timpl_closure'_timpls_trancl_supset':\n  \"timpl_closure' c \\<subseteq> timpl_closure' {(a,b) \\<in> c\\<^sup>+. a \\<noteq> b}\"\nunfolding timpl_closure'_def\nproof\n  let ?cl = \"{(a,b) \\<in> c\\<^sup>+. a \\<noteq> b}\"\n\n  fix s t::\"(('e,'f,'c) prot_fun,'g) term\"\n  show \"(s,t) \\<in> (timpl_closure'_step c)\\<^sup>* \\<Longrightarrow> (s,t) \\<in> (timpl_closure'_step ?cl)\\<^sup>*\"\n  proof (induction rule: rtrancl_induct)\n    case (step u t)\n    obtain a b where ab:\n        \"(a,b) \\<in> c\" \"term_variants_pred ((\\<lambda>_. [])(Abs a := [Abs b])) u t\"\n      using step.hyps(2) timpl_closure'_step_inv by blast\n    hence \"(a,b) \\<in> c\\<^sup>+\" by simp\n    hence \"(u,t) \\<in> (timpl_closure'_step ?cl)\\<^sup>*\" using ab(2)\n    proof (induction arbitrary: t rule: trancl_induct)\n      case (base d) show ?case\n      proof (cases \"a = d\")\n        case True thus ?thesis\n          using base term_variants_pred_refl_inv[of _ u t]\n          by force\n      next\n        case False thus ?thesis\n          using base timpl_closure'_step.intros[of a d ?cl]\n          by fast\n      qed\n    next\n      case (step d e)\n      obtain s where s:\n          \"term_variants_pred ((\\<lambda>_. [])(Abs a := [Abs d])) u s\"\n          \"term_variants_pred ((\\<lambda>_. [])(Abs d := [Abs e])) s t\"\n        using term_variants_pred_dense'[OF step.prems, of \"Abs d\"] by blast\n\n      show ?case\n      proof (cases \"d = e\")\n        case True\n        thus ?thesis\n          using step.prems step.IH[of t]\n          by blast\n      next\n        case False\n        hence \"(u,s) \\<in> (timpl_closure'_step ?cl)\\<^sup>*\"\n              \"(s,t) \\<in> timpl_closure'_step ?cl\"\n          using step.hyps(2) s(2) step.IH[OF s(1)]\n          by (auto intro: timpl_closure'_step.intros)\n        thus ?thesis by simp\n      qed\n    qed\n    thus ?case using step.IH by simp\n  qed simp\nqed\n\nlemma timpl_closure'_timpls_trancl_supset:\n  \"timpl_closure' c \\<subseteq> timpl_closure' (c\\<^sup>+)\"\nusing timpl_closure'_timpls_trancl_supset'[of c]\n      timpl_closure'_mono[of \"{(a,b) \\<in> c\\<^sup>+. a \\<noteq> b}\" \"c\\<^sup>+\"]\nby fast\n\nlemma timpl_closure'_timpls_trancl_eq:\n  \"timpl_closure' (c\\<^sup>+) = timpl_closure' c\"\nusing timpl_closure'_timpls_trancl_subset timpl_closure'_timpls_trancl_supset\nby blast\n\nlemma timpl_closure'_timpls_trancl_eq':\n  \"timpl_closure' {(a,b) \\<in> c\\<^sup>+. a \\<noteq> b} = timpl_closure' c\"\nusing timpl_closure'_timpls_trancl_subset' timpl_closure'_timpls_trancl_supset'\nby blast\n\nlemma timpl_closure'_timpls_rtrancl_subset:\n  \"timpl_closure' (c\\<^sup>*) \\<subseteq> timpl_closure' c\"\nunfolding timpl_closure'_def\nproof\n  fix s t::\"(('a,'b,'c) prot_fun,'d) term\"\n  show \"(s,t) \\<in> (timpl_closure'_step (c\\<^sup>*))\\<^sup>* \\<Longrightarrow> (s,t) \\<in> (timpl_closure'_step c)\\<^sup>*\"\n  proof (induction rule: rtrancl_induct)\n    case (step u t)\n    obtain a b where ab:\n        \"(a,b) \\<in> c\\<^sup>*\" \"term_variants_pred ((\\<lambda>_. [])(Abs a := [Abs b])) u t\"\n      using step.hyps(2) timpl_closure'_step_inv by blast\n    hence \"(u,t) \\<in> (timpl_closure'_step c)\\<^sup>*\"\n    proof (induction arbitrary: t rule: rtrancl_induct)\n      case base\n      hence \"u = t\" using term_variants_pred_refl_inv by fastforce\n      thus ?case by simp\n    next\n      case (step d e)\n      obtain s where s:\n          \"term_variants_pred ((\\<lambda>_. [])(Abs a := [Abs d])) u s\"\n          \"term_variants_pred ((\\<lambda>_. [])(Abs d := [Abs e])) s t\"\n        using term_variants_pred_dense'[OF step.prems, of \"Abs d\"] by blast\n\n      have \"(u,s) \\<in> (timpl_closure'_step c)\\<^sup>*\"\n           \"(s,t) \\<in> timpl_closure'_step c\"\n        using step.hyps(2) s(2) step.IH[OF s(1)]\n        by (auto intro: timpl_closure'_step.intros)\n      thus ?case by simp\n    qed\n    thus ?case using step.IH by simp\n  qed simp\nqed\n\nlemma timpl_closure'_timpls_rtrancl_supset:\n  \"timpl_closure' c \\<subseteq> timpl_closure' (c\\<^sup>*)\"\nunfolding timpl_closure'_def\nproof\n  fix s t::\"(('e,'f,'c) prot_fun,'g) term\"\n  show \"(s,t) \\<in> (timpl_closure'_step c)\\<^sup>* \\<Longrightarrow> (s,t) \\<in> (timpl_closure'_step (c\\<^sup>*))\\<^sup>*\"\n  proof (induction rule: rtrancl_induct)\n    case (step u t)\n    obtain a b where ab:\n        \"(a,b) \\<in> c\" \"term_variants_pred ((\\<lambda>_. [])(Abs a := [Abs b])) u t\"\n      using step.hyps(2) timpl_closure'_step_inv by blast\n    hence \"(a,b) \\<in> c\\<^sup>*\" by simp\n    hence \"(u,t) \\<in> (timpl_closure'_step (c\\<^sup>*))\\<^sup>*\" using ab(2)\n    proof (induction arbitrary: t rule: rtrancl_induct)\n      case (base t) thus ?case using term_variants_pred_refl_inv[of _ u t] by fastforce\n    next\n      case (step d e)\n      obtain s where s:\n          \"term_variants_pred ((\\<lambda>_. [])(Abs a := [Abs d])) u s\"\n          \"term_variants_pred ((\\<lambda>_. [])(Abs d := [Abs e])) s t\"\n        using term_variants_pred_dense'[OF step.prems, of \"Abs d\"] by blast\n\n      show ?case\n      proof (cases \"d = e\")\n        case True\n        thus ?thesis\n          using step.prems step.IH[of t]\n          by blast\n      next\n        case False\n        hence \"(u,s) \\<in> (timpl_closure'_step (c\\<^sup>*))\\<^sup>*\"\n              \"(s,t) \\<in> timpl_closure'_step (c\\<^sup>*)\"\n          using step.hyps(2) s(2) step.IH[OF s(1)]\n          by (auto intro: timpl_closure'_step.intros)\n        thus ?thesis by simp\n      qed\n    qed\n    thus ?case using step.IH by simp\n  qed simp\nqed\n\nlemma timpl_closure'_timpls_rtrancl_eq:\n  \"timpl_closure' (c\\<^sup>*) = timpl_closure' c\"\nusing timpl_closure'_timpls_rtrancl_subset timpl_closure'_timpls_rtrancl_supset\nby blast\n\nlemma timpl_closure_timpls_trancl_eq:\n  \"timpl_closure t (c\\<^sup>+) = timpl_closure t c\"\nusing timpl_closure'_timpls_trancl_eq[of c]\n      timpl_closure_is_timpl_closure'[of _ _ c]\n      timpl_closure_is_timpl_closure'[of _ _ \"c\\<^sup>+\"]\nby fastforce\n\n\n\nlemma timpl_closure_set_timpls_trancl_eq':\n  \"timpl_closure_set M {(a,b) \\<in> c\\<^sup>+. a \\<noteq> b} = timpl_closure_set M c\"\nusing timpl_closure'_timpls_trancl_eq'[of c]\n      timpl_closure_is_timpl_closure'[of _ _ c]\n      timpl_closure_is_timpl_closure'[of _ _ \"{(a,b) \\<in> c\\<^sup>+. a \\<noteq> b}\"]\n      timpl_closure_set_is_timpl_closure_union[of M c]\n      timpl_closure_set_is_timpl_closure_union[of M \"{(a,b) \\<in> c\\<^sup>+. a \\<noteq> b}\"]\nby fastforce\n\nlemma timpl_closure_Var_in_iff:\n  \"Var x \\<in> timpl_closure t TI \\<longleftrightarrow> t = Var x\" (is \"?A \\<longleftrightarrow> ?B\")\nproof\n  have \"s \\<in> timpl_closure t TI \\<Longrightarrow> s = Var x \\<Longrightarrow> s = t\" for s\n    apply (induction rule: timpl_closure.induct)\n    by (simp, metis term_variants_pred_inv_Var(2))\n  thus \"?A \\<Longrightarrow> ?B\" by blast\nqed (blast intro: timpl_closure.FP)\n\nlemma timpl_closure_set_Var_in_iff:\n  \"Var x \\<in> timpl_closure_set M TI \\<longleftrightarrow> Var x \\<in> M\"\nunfolding timpl_closure_set_def by (simp add: timpl_closure_Var_in_iff[of x _ TI]) \n\nlemma timpl_closure_Var_inv:\n  assumes \"t \\<in> timpl_closure (Var x) TI\"\n  shows \"t = Var x\"\nusing assms\nproof (induction rule: timpl_closure.induct)\n  case (TI u a b s) thus ?case using term_variants_pred_inv_Var by fast\nqed simp\n\nlemma timpls_Un_mono: \"mono (\\<lambda>X. FP \\<union> (\\<Union>x \\<in> X. \\<Union>(a,b) \\<in> TI. set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>x\\<rangle>))\"\nby (auto intro!: monoI)\n\nlemma timpl_closure_set_lfp:\n  fixes M TI\n  defines \"f \\<equiv> \\<lambda>X. M \\<union> (\\<Union>x \\<in> X. \\<Union>(a,b) \\<in> TI. set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>x\\<rangle>)\"\n  shows \"lfp f = timpl_closure_set M TI\"\nproof\n  note 0 = timpls_Un_mono[of M TI, unfolded f_def[symmetric]]\n\n  let ?N = \"timpl_closure_set M TI\"\n\n  show \"lfp f \\<subseteq> ?N\"\n  proof (induction rule: lfp_induct)\n    case 2 thus ?case\n    proof\n      fix t assume \"t \\<in> f (lfp f \\<inter> ?N)\"\n      hence \"t \\<in> M \\<or> t \\<in> (\\<Union>x \\<in> ?N. \\<Union>(a,b) \\<in> TI. set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>x\\<rangle>)\" (is \"?A \\<or> ?B\")\n        unfolding f_def by blast\n      thus \"t \\<in> ?N\"\n      proof\n        assume ?B\n        then obtain s a b where s: \"s \\<in> ?N\" \"(a,b) \\<in> TI\" \"t \\<in> set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>s\\<rangle>\" by moura\n        thus ?thesis \n          using term_variants_pred_iff_in_term_variants[of \"(\\<lambda>_. [])(Abs a := [Abs b])\" s]\n          unfolding timpl_closure_set_def timpl_apply_term_def\n          by (auto intro: timpl_closure.intros)\n      qed (auto simp add: timpl_closure_set_def intro: timpl_closure.intros)\n    qed\n  qed (rule 0)\n\n  have \"t \\<in> lfp f\" when t: \"t \\<in> timpl_closure s TI\" and s: \"s \\<in> M\" for t s\n    using t\n  proof (induction t rule: timpl_closure.induct)\n    case (TI u a b v) thus ?case \n      using term_variants_pred_iff_in_term_variants[of \"(\\<lambda>_. [])(Abs a := [Abs b])\"]\n            lfp_fixpoint[OF 0]\n      unfolding timpl_apply_term_def f_def by fastforce\n  qed (use s lfp_fixpoint[OF 0] f_def in blast)\n  thus \"?N \\<subseteq> lfp f\" unfolding timpl_closure_set_def by blast\nqed\n\nlemma timpl_closure_set_supset:\n  assumes \"\\<forall>t \\<in> FP. t \\<in> closure\"\n  and \"\\<forall>t \\<in> closure. \\<forall>(a,b) \\<in> TI. \\<forall>s \\<in> set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>t\\<rangle>. s \\<in> closure\"\n  shows \"timpl_closure_set FP TI \\<subseteq> closure\"\nproof -\n  have \"t \\<in> closure\" when t: \"t \\<in> timpl_closure s TI\" and s: \"s \\<in> FP\" for t s\n    using t\n  proof (induction rule: timpl_closure.induct)\n    case FP thus ?case using s assms(1) by blast\n  next\n    case (TI u a b s') thus ?case\n      using assms(2) term_variants_pred_iff_in_term_variants[of \"(\\<lambda>_. [])(Abs a := [Abs b])\"]\n      unfolding timpl_apply_term_def by fastforce\n  qed\n  thus ?thesis unfolding timpl_closure_set_def by blast\nqed\n\nlemma timpl_closure_set_supset':\n  assumes \"\\<forall>t \\<in> FP. \\<forall>(a,b) \\<in> TI. \\<forall>s \\<in> set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>t\\<rangle>. s \\<in> FP\"\n  shows \"timpl_closure_set FP TI \\<subseteq> FP\"\nusing timpl_closure_set_supset[OF _ assms] by blast\n\nlemma timpl_closure'_param:\n  assumes \"(t,s) \\<in> timpl_closure' c\"\n    and fg: \"f = g \\<or> (\\<exists>a b. (a,b) \\<in> c \\<and> f = Abs a \\<and> g = Abs b)\"\n  shows \"(Fun f (S@t#T), Fun g (S@s#T)) \\<in> timpl_closure' c\"\nusing assms(1) unfolding timpl_closure'_def\nproof (induction rule: rtrancl_induct)\n  case base thus ?case\n  proof (cases \"f = g\")\n    case False\n    then obtain a b where ab: \"(a,b) \\<in> c\" \"f = Abs a\" \"g = Abs b\"\n      using fg by moura\n    show ?thesis\n      using term_variants_pred_param[OF term_variants_pred_refl[of \"(\\<lambda>_. [])(Abs a := [Abs b])\" t]]\n            timpl_closure'_step.intros[OF ab(1)] ab(2,3)\n      by fastforce\n  qed simp\nnext\n  case (step u s)\n  obtain a b where ab: \"(a,b) \\<in> c\" \"term_variants_pred ((\\<lambda>_. [])(Abs a := [Abs b])) u s\"\n    using timpl_closure'_step_inv[OF step.hyps(2)] by blast\n  have \"(Fun g (S@u#T), Fun g (S@s#T)) \\<in> timpl_closure'_step c\"\n      using ab(1) term_variants_pred_param[OF ab(2), of g g S T]\n      by (auto simp add: timpl_closure'_def intro: timpl_closure'_step.intros)\n  thus ?case using rtrancl_into_rtrancl[OF step.IH] fg by blast\nqed\n\nlemma timpl_closure'_param':\n  assumes \"(t,s) \\<in> timpl_closure' c\"\n  shows \"(Fun f (S@t#T), Fun f (S@s#T)) \\<in> timpl_closure' c\"\nusing timpl_closure'_param[OF assms] by simp\n\nlemma timpl_closure_FunI:\n  assumes IH: \"\\<And>i. i < length T \\<Longrightarrow> (T ! i, S ! i) \\<in> timpl_closure' c\"\n    and len: \"length T = length S\"\n    and fg: \"f = g \\<or> (\\<exists>a b. (a,b) \\<in> c\\<^sup>+ \\<and> f = Abs a \\<and> g = Abs b)\"\n  shows \"(Fun f T, Fun g S) \\<in> timpl_closure' c\"\nproof -\n  have aux: \"(Fun f T, Fun g (take n S@drop n T)) \\<in> timpl_closure' c\"\n    when \"n \\<le> length T\" for n\n    using that\n  proof (induction n)\n    case 0\n    have \"(T ! n, T ! n) \\<in> timpl_closure' c\" when n: \"n < length T\" for n\n      using n unfolding timpl_closure'_def by simp\n    hence \"(Fun f T, Fun g T) \\<in> timpl_closure' c\"\n    proof (cases \"f = g\")\n      case False\n      then obtain a b where ab: \"(a, b) \\<in> c\\<^sup>+\" \"f = Abs a\" \"g = Abs b\"\n        using fg by moura\n      show ?thesis\n        using timpl_closure'_step.intros[OF ab(1), of \"Fun f T\" \"Fun g T\"] ab(2,3)\n              term_variants_P[OF _ term_variants_pred_refl[of \"(\\<lambda>_. [])(Abs a := [Abs b])\"],\n                              of T g f]\n              timpl_closure'_timpls_trancl_eq\n        unfolding timpl_closure'_def\n        by (metis fun_upd_same list.set_intros(1) r_into_rtrancl)\n    qed (simp add: timpl_closure'_def)\n    thus ?case by simp\n  next\n    case (Suc n)\n    hence IH': \"(Fun f T, Fun g (take n S@drop n T)) \\<in> timpl_closure' c\"\n      and n: \"n < length T\" \"n < length S\"\n      by (simp_all add: len)\n\n    obtain T1 T2 where T: \"T = T1@T ! n#T2\" \"length T1 = n\"\n      using length_prefix_ex'[OF n(1)] by auto\n\n    obtain S1 S2 where S: \"S = S1@S ! n#S2\" \"length S1 = n\"\n      using length_prefix_ex'[OF n(2)] by auto\n\n    have \"take n S@drop n T = S1@T ! n#T2\" \"take (Suc n) S@drop (Suc n) T = S1@S ! n#T2\"\n      using n T S append_eq_conv_conj\n      by (metis, metis (no_types, opaque_lifting) Cons_nth_drop_Suc append.assoc append_Cons\n                                             append_Nil take_Suc_conv_app_nth) \n    moreover have \"(T ! n, S ! n) \\<in> timpl_closure' c\" using IH Suc.prems by simp\n    ultimately show ?case\n      using timpl_closure'_param IH'(1)\n      by (metis (no_types, lifting) timpl_closure'_def rtrancl_trans)\n  qed\n\n  show ?thesis using aux[of \"length T\"] len by simp\nqed\n\nlemma timpl_closure_FunI':\n  assumes IH: \"\\<And>i. i < length T \\<Longrightarrow> (T ! i, S ! i) \\<in> timpl_closure' c\"\n    and len: \"length T = length S\"\n  shows \"(Fun f T, Fun f S) \\<in> timpl_closure' c\"\nusing timpl_closure_FunI[OF IH len] by simp\n\nlemma timpl_closure_FunI2:\n  fixes f g::\"('a, 'b, 'c) prot_fun\"\n  assumes IH: \"\\<And>i. i < length T \\<Longrightarrow> \\<exists>u. (T!i, u) \\<in> timpl_closure' c \\<and> (S!i, u) \\<in> timpl_closure' c\"\n    and len: \"length T = length S\"\n    and fg: \"f = g \\<or> (\\<exists>a b d. (a, d) \\<in> c\\<^sup>+ \\<and> (b, d) \\<in> c\\<^sup>+ \\<and> f = Abs a \\<and> g = Abs b)\"\n  shows \"\\<exists>h U. (Fun f T, Fun h U) \\<in> timpl_closure' c \\<and> (Fun g S, Fun h U) \\<in> timpl_closure' c\"\nproof -\n  let ?P = \"\\<lambda>i u. (T ! i, u) \\<in> timpl_closure' c \\<and> (S ! i, u) \\<in> timpl_closure' c\"\n\n  define U where \"U \\<equiv> map (\\<lambda>i. SOME u. ?P i u) [0..<length T]\"\n\n  have U1: \"length U = length T\"\n    unfolding U_def by auto\n\n  have U2: \"(T ! i, U ! i) \\<in> timpl_closure' c \\<and> (S ! i, U ! i) \\<in> timpl_closure' c\"\n    when i: \"i < length U\" for i\n    using i someI_ex[of \"?P i\"] IH[of i] U1 len\n    unfolding U_def by simp\n\n  show ?thesis\n  proof (cases \"f = g\")\n    case False\n    then obtain a b d where abd: \"(a, d) \\<in> c\\<^sup>+\" \"(b, d) \\<in> c\\<^sup>+\" \"f = Abs a\" \"g = Abs b\"\n      using fg by moura\n\n    define h::\"('a, 'b, 'c) prot_fun\" where \"h = Abs d\"\n\n    have \"f = h \\<or> (\\<exists>a b. (a, b) \\<in> c\\<^sup>+ \\<and> f = Abs a \\<and> h = Abs b)\"\n         \"g = h \\<or> (\\<exists>a b. (a, b) \\<in> c\\<^sup>+ \\<and> g = Abs a \\<and> h = Abs b)\"\n      using abd unfolding h_def by blast+\n    thus ?thesis by (metis timpl_closure_FunI len U1 U2)\n  qed (metis timpl_closure_FunI' len U1 U2)\nqed\n\nlemma timpl_closure_FunI3:\n  fixes f g::\"('a, 'b, 'c) prot_fun\"\n  assumes IH: \"\\<And>i. i < length T \\<Longrightarrow> \\<exists>u. (T!i, u) \\<in> timpl_closure' c \\<and> (S!i, u) \\<in> timpl_closure' c\"\n    and len: \"length T = length S\"\n    and fg: \"f = g \\<or> (\\<exists>a b d. (a, d) \\<in> c \\<and> (b, d) \\<in> c \\<and> f = Abs a \\<and> g = Abs b)\"\n  shows \"\\<exists>h U. (Fun f T, Fun h U) \\<in> timpl_closure' c \\<and> (Fun g S, Fun h U) \\<in> timpl_closure' c\"\nusing timpl_closure_FunI2[OF IH len] fg unfolding timpl_closure'_timpls_trancl_eq by blast\n\n\n\nlemma (in stateful_protocol_model) timpl_closure_subst:\n  assumes t: \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"\\<forall>x \\<in> fv t. \\<exists>a. \\<Gamma>\\<^sub>v x = TAtom (Atom a)\"\n    and \\<delta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\"\n  shows \"timpl_closure (t \\<cdot> \\<delta>) T = timpl_closure t T \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>\"\nproof\n  have \"s \\<in> timpl_closure t T \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>\"\n    when \"s \\<in> timpl_closure (t \\<cdot> \\<delta>) T\" for s\n    using that\n  proof (induction s rule: timpl_closure.induct)\n    case FP thus ?case using timpl_closure.FP[of t T] by simp\n  next\n    case (TI u a b s)\n    then obtain u' where u': \"u' \\<in> timpl_closure t T\" \"u = u' \\<cdot> \\<delta>\" by moura\n    \n    have u'_fv: \"\\<forall>x \\<in> fv u'. \\<exists>a. \\<Gamma>\\<^sub>v x = TAtom (Atom a)\"\n      using timpl_closure_fv_eq[OF u'(1)] t(2) by simp\n    hence u_fv: \"\\<forall>x \\<in> fv u. \\<exists>a. \\<Gamma>\\<^sub>v x = TAtom (Atom a)\"\n      using u'(2) wt_subst_trm''[OF \\<delta>(1)] wt_subst_const_fv_type_eq[OF _ \\<delta>(1,2), of u']\n      by fastforce\n\n    have \"\\<forall>x \\<in> fv u' \\<union> fv s. (\\<exists>y. \\<delta> x = Var y) \\<or> (\\<exists>f. \\<delta> x = Fun f [] \\<and> Abs a \\<noteq> f)\"\n    proof (intro ballI)\n      fix x assume x: \"x \\<in> fv u' \\<union> fv s\"\n      then obtain c where c: \"\\<Gamma>\\<^sub>v x = TAtom (Atom c)\"\n        using u'_fv u_fv term_variants_pred_fv_eq[OF TI.hyps(3)]\n        by blast\n\n      show \"(\\<exists>y. \\<delta> x = Var y) \\<or> (\\<exists>f. \\<delta> x = Fun f [] \\<and> Abs a \\<noteq> f)\"\n      proof (cases \"\\<delta> x\")\n        case (Fun f T)\n        hence **: \"\\<Gamma> (Fun f T) = TAtom (Atom c)\" and \"wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f T)\"\n          using c wt_subst_trm''[OF \\<delta>(1), of \"Var x\"] \\<delta>(2)\n          by fastforce+\n        hence \"\\<delta> x = Fun f []\" using Fun const_type_inv_wf by metis\n        thus ?thesis using ** by force\n      qed metis\n    qed\n    hence *: \"\\<forall>x \\<in> fv u' \\<union> fv s.\n                (\\<exists>y. \\<delta> x = Var y) \\<or> (\\<exists>f. \\<delta> x = Fun f [] \\<and> ((\\<lambda>_. [])(Abs a := [Abs b])) f = [])\"\n      by fastforce\n\n    obtain s' where s': \"term_variants_pred ((\\<lambda>_. [])(Abs a := [Abs b])) u' s'\" \"s = s' \\<cdot> \\<delta>\"\n      using term_variants_pred_subst'[OF _ *] u'(2) TI.hyps(3)\n      by blast\n\n    show ?case using timpl_closure.TI[OF u'(1) TI.hyps(2) s'(1)] s'(2) by blast\n  qed\n  thus \"timpl_closure (t \\<cdot> \\<delta>) T \\<subseteq> timpl_closure t T \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>\" by fast\n\n  have \"s \\<in> timpl_closure (t \\<cdot> \\<delta>) T\"\n    when s: \"s \\<in> timpl_closure t T \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>\" for s\n  proof -\n    obtain s' where s': \"s' \\<in> timpl_closure t T\" \"s = s' \\<cdot> \\<delta>\" using s by moura\n    have \"s' \\<cdot> \\<delta> \\<in> timpl_closure (t \\<cdot> \\<delta>) T\" using s'(1)\n    proof (induction s' rule: timpl_closure.induct)\n      case FP thus ?case using timpl_closure.FP[of \"t \\<cdot> \\<delta>\" T] by simp\n    next\n      case (TI u' a b s') show ?case\n        using timpl_closure.TI[OF TI.IH TI.hyps(2)]\n              term_variants_pred_subst[OF TI.hyps(3)]\n        by blast\n    qed\n    thus ?thesis using s'(2) by metis\n  qed\n  thus \"timpl_closure t T \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta> \\<subseteq> timpl_closure (t \\<cdot> \\<delta>) T\" by fast\nqed\n\nlemma (in stateful_protocol_model) timpl_closure_subst_subset:\n  assumes t: \"t \\<in> M\"\n    and M: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s M\" \"\\<forall>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t M. \\<exists>a. \\<Gamma>\\<^sub>v x = TAtom (Atom a)\"\n    and \\<delta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\" \"ground (subst_range \\<delta>)\" \"subst_domain \\<delta> \\<subseteq> fv\\<^sub>s\\<^sub>e\\<^sub>t M\"\n    and M_supset: \"timpl_closure t T \\<subseteq> M\"\n  shows \"timpl_closure (t \\<cdot> \\<delta>) T \\<subseteq> M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>\"\nproof -\n  have t': \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"\\<forall>x \\<in> fv t. \\<exists>a. \\<Gamma>\\<^sub>v x = TAtom (Atom a)\" using t M by auto\n  show ?thesis using timpl_closure_subst[OF t' \\<delta>(1,2), of T] M_supset by blast\nqed\n\nlemma (in stateful_protocol_model) timpl_closure_set_subst_subset:\n  assumes M: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s M\" \"\\<forall>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t M. \\<exists>a. \\<Gamma>\\<^sub>v x = TAtom (Atom a)\"\n    and \\<delta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\" \"ground (subst_range \\<delta>)\" \"subst_domain \\<delta> \\<subseteq> fv\\<^sub>s\\<^sub>e\\<^sub>t M\"\n    and M_supset: \"timpl_closure_set M T \\<subseteq> M\"\n  shows \"timpl_closure_set (M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>) T \\<subseteq> M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>\"\nusing timpl_closure_subst_subset[OF _ M \\<delta>, of _ T] M_supset\n      timpl_closure_set_is_timpl_closure_union[of \"M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>\" T]\n      timpl_closure_set_is_timpl_closure_union[of M T]\nby auto\n\nlemma timpl_closure_set_Union:\n  \"timpl_closure_set (\\<Union>Ms) T = (\\<Union>M \\<in> Ms. timpl_closure_set M T)\"\nusing timpl_closure_set_is_timpl_closure_union[of \"\\<Union>Ms\" T]\n      timpl_closure_set_is_timpl_closure_union[of _ T]\nby force\n\nlemma timpl_closure_set_Union_subst_set:\n  assumes \"s \\<in> timpl_closure_set (\\<Union>{M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta> | \\<delta>. P \\<delta>}) T\"\n  shows \"\\<exists>\\<delta>. P \\<delta> \\<and> s \\<in> timpl_closure_set (M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>) T\"\nusing assms timpl_closure_set_is_timpl_closure_union[of \"(\\<Union>{M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta> | \\<delta>. P \\<delta>})\" T]\n      timpl_closure_set_is_timpl_closure_union[of _ T]\nby blast\n\nlemma timpl_closure_set_Union_subst_singleton:\n  assumes \"s \\<in> timpl_closure_set {t \\<cdot> \\<delta> | \\<delta>. P \\<delta>} T\"\n  shows \"\\<exists>\\<delta>. P \\<delta> \\<and> s \\<in> timpl_closure_set {t \\<cdot> \\<delta>} T\"\nusing assms timpl_closure_set_is_timpl_closure_union[of \"{t \\<cdot> \\<delta> |\\<delta>. P \\<delta>}\" T]\n      timpl_closureton_is_timpl_closure[of _ T]\nby fast\n\n\n\nlemma timpl_closure'_inv':\n  assumes \"(s, t) \\<in> timpl_closure' TI\"\n  shows \"(\\<exists>x. s = Var x \\<and> t = Var x) \\<or>\n         (\\<exists>f g S T. s = Fun f S \\<and> t = Fun g T \\<and> length S = length T \\<and>\n                    (\\<forall>i < length T. (S ! i, T ! i) \\<in> timpl_closure' TI) \\<and>\n                    (f \\<noteq> g \\<longrightarrow> is_Abs f \\<and> is_Abs g \\<and> (the_Abs f, the_Abs g) \\<in> TI\\<^sup>+))\"\n    (is \"?A s t \\<or> ?B s t (timpl_closure' TI)\")\nusing assms unfolding timpl_closure'_def\nproof (induction rule: rtrancl_induct)\n  case base thus ?case by (cases s) auto\nnext\n  case (step t u)\n  obtain a b where ab: \"(a, b) \\<in> TI\" \"term_variants_pred ((\\<lambda>_. [])(Abs a := [Abs b])) t u\"\n    using timpl_closure'_step_inv[OF step.hyps(2)] by blast\n  show ?case using step.IH\n  proof\n    assume \"?A s t\"\n    thus ?case using step.hyps(2) term_variants_pred_inv_Var ab by fastforce\n  next\n    assume \"?B s t ((timpl_closure'_step TI)\\<^sup>*)\"\n    then obtain f g S T where st:\n        \"s = Fun f S\" \"t = Fun g T\" \"length S = length T\"\n        \"\\<And>i. i < length T \\<Longrightarrow> (S ! i, T ! i) \\<in> (timpl_closure'_step TI)\\<^sup>*\"\n        \"f \\<noteq> g \\<Longrightarrow> is_Abs f \\<and> is_Abs g \\<and> (the_Abs f, the_Abs g) \\<in> TI\\<^sup>+\"\n      by moura\n    obtain h U where u:\n        \"u = Fun h U\" \"length T = length U\"\n        \"\\<And>i. i < length T \\<Longrightarrow> term_variants_pred ((\\<lambda>_. [])(Abs a := [Abs b])) (T ! i) (U ! i)\"\n        \"g \\<noteq> h \\<Longrightarrow> is_Abs g \\<and> is_Abs h \\<and> (the_Abs g, the_Abs h) \\<in> TI\\<^sup>+\"\n      using ab(2) st(2) r_into_trancl[OF ab(1)]\n            term_variants_pred_inv'(1,2,3,4)[of \"(\\<lambda>_. [])(Abs a := [Abs b])\" g T u]\n            term_variants_pred_inv'(5)[of \"(\\<lambda>_. [])(Abs a := [Abs b])\" g T u \"Abs a\" \"Abs b\"]\n      unfolding is_Abs_def the_Abs_def by force\n\n    have \"(S ! i, U ! i) \\<in> (timpl_closure'_step TI)\\<^sup>*\" when i: \"i < length U\" for i\n      using u(2) i rtrancl.rtrancl_into_rtrancl[OF\n              st(4)[of i] timpl_closure'_step.intros[OF ab(1) u(3)[of i]]]\n      by argo\n    moreover have \"length S = length U\" using st u by argo\n    moreover have \"is_Abs f \\<and> is_Abs h \\<and> (the_Abs f, the_Abs h) \\<in> TI\\<^sup>+\" when fh: \"f \\<noteq> h\"\n      using fh st u by fastforce\n    ultimately show ?case using st(1) u(1) by blast\n  qed\nqed\n\nlemma timpl_closure'_inv'':\n  assumes \"(Fun f S, Fun g T) \\<in> timpl_closure' TI\"\n  shows \"length S = length T\"\n    and \"\\<And>i. i < length T \\<Longrightarrow> (S ! i, T ! i) \\<in> timpl_closure' TI\"\n    and \"f \\<noteq> g \\<Longrightarrow> is_Abs f \\<and> is_Abs g \\<and> (the_Abs f, the_Abs g) \\<in> TI\\<^sup>+\"\nusing assms timpl_closure'_inv' by auto\n\nlemma timpl_closure_Fun_inv:\n  assumes \"s \\<in> timpl_closure (Fun f T) TI\"\n  shows \"\\<exists>g S. s = Fun g S\"\nusing assms timpl_closure_is_timpl_closure' timpl_closure'_inv\nby fastforce\n\nlemma timpl_closure_Fun_inv':\n  assumes \"Fun g S \\<in> timpl_closure (Fun f T) TI\"\n  shows \"length S = length T\"\n    and \"\\<And>i. i < length S \\<Longrightarrow> S ! i \\<in> timpl_closure (T ! i) TI\"\n    and \"f \\<noteq> g \\<Longrightarrow> is_Abs f \\<and> is_Abs g \\<and> (the_Abs f, the_Abs g) \\<in> TI\\<^sup>+\"\nusing assms timpl_closure_is_timpl_closure'\nby (metis timpl_closure'_inv''(1), metis timpl_closure'_inv''(2), metis timpl_closure'_inv''(3))\n\nlemma timpl_closure_Fun_not_Var[simp]:\n  \"Fun f T \\<notin> timpl_closure (Var x) TI\"\nusing timpl_closure_Var_inv by fast\n\nlemma timpl_closure_Var_not_Fun[simp]:\n  \"Var x \\<notin> timpl_closure (Fun f T) TI\"\nusing timpl_closure_Fun_inv by fast\n\nlemma (in stateful_protocol_model) timpl_closure_wf_trms:\n  assumes m: \"wf\\<^sub>t\\<^sub>r\\<^sub>m m\"\n  shows \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (timpl_closure m TI)\"\nproof\n  fix t assume \"t \\<in> timpl_closure m TI\"\n  thus \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\n  proof (induction t rule: timpl_closure.induct)\n    case TI thus ?case using term_variants_pred_wf_trms by force\n  qed (rule m)\nqed\n\nlemma (in stateful_protocol_model) timpl_closure_set_wf_trms:\n  assumes M: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s M\"\n  shows \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (timpl_closure_set M TI)\"\nproof\n  fix t assume \"t \\<in> timpl_closure_set M TI\"\n  then obtain m where \"t \\<in> timpl_closure m TI\" \"m \\<in> M\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m m\"\n    using M timpl_closure_set_is_timpl_closure_union by blast\n  thus \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" using timpl_closure_wf_trms by blast\nqed\n\n\n\n  show ?case\n    using term_variants_pred_inv'(1,2,4)[OF *] U\n    by force\nqed simp\n\nlemma timpl_closure_Fu_inv':\n  assumes \"Fun (Fu f) T \\<in> timpl_closure t TI\"\n  shows \"\\<exists>S. length S = length T \\<and> t = Fun (Fu f) S\"\nusing assms\nproof (induction \"Fun (Fu f) T\" arbitrary: T rule: timpl_closure.induct)\n  case (TI u a b)\n  obtain g U where U:\n      \"u = Fun g U\" \"length U = length T\"\n      \"Fu f \\<noteq> g \\<Longrightarrow> Abs a = g \\<and> Fu f = Abs b\"\n    using term_variants_pred_inv''[OF TI.hyps(4)] by fastforce\n\n  have g: \"g = Fu f\" using U(3) by blast\n  \n  show ?case using TI.hyps(2)[OF U(1)[unfolded g]] U(2) by auto\nqed simp\n\nlemma timpl_closure_no_Abs_eq:\n  assumes \"t \\<in> timpl_closure s TI\"\n    and \"\\<forall>f \\<in> funs_term t. \\<not>is_Abs f\"\n  shows \"t = s\"\nusing assms\nproof (induction t rule: timpl_closure.induct)\n  case (TI t a b s) thus ?case\n    using term_variants_pred_eq_case_Abs[of a b t s]\n    unfolding timpl_apply_term_def term_variants_pred_iff_in_term_variants[symmetric]\n    by metis\nqed simp\n\nlemma timpl_closure_set_no_Abs_in_set:\n  assumes \"t \\<in> timpl_closure_set FP TI\"\n    and \"\\<forall>f \\<in> funs_term t. \\<not>is_Abs f\"\n  shows \"t \\<in> FP\"\nusing assms timpl_closure_no_Abs_eq unfolding timpl_closure_set_def by blast\n\nlemma timpl_closure_funs_term_subset:\n  \"\\<Union>(funs_term ` (timpl_closure t TI)) \\<subseteq> funs_term t \\<union> Abs ` snd ` TI\"\n  (is \"?A \\<subseteq> ?B \\<union> ?C\")\nproof\n  fix f assume \"f \\<in> ?A\"\n  then obtain s where \"s \\<in> timpl_closure t TI\" \"f \\<in> funs_term s\" by moura\n  thus \"f \\<in> ?B \\<union> ?C\"\n  proof (induction s rule: timpl_closure.induct)\n    case (TI u a b s)\n    have \"Abs b \\<in> Abs ` snd ` TI\" using TI.hyps(2) by force\n    thus ?case using term_variants_pred_funs_term[OF TI.hyps(3) TI.prems] TI.IH by force\n  qed blast\nqed\n\nlemma timpl_closure_set_funs_term_subset:\n  \"\\<Union>(funs_term ` (timpl_closure_set FP TI)) \\<subseteq> \\<Union>(funs_term ` FP) \\<union> Abs ` snd ` TI\"\nusing timpl_closure_funs_term_subset[of _ TI]\n      timpl_closure_set_is_timpl_closure_union[of FP TI]\nby auto\n\nlemma funs_term_OCC_TI_subset:\n  defines \"absc \\<equiv> \\<lambda>a. Fun (Abs a) []\"\n  assumes OCC1: \"\\<forall>t \\<in> FP. \\<forall>f \\<in> funs_term t. is_Abs f \\<longrightarrow> f \\<in> Abs ` OCC\"\n    and OCC2: \"snd ` TI \\<subseteq> OCC\"\n  shows \"\\<forall>t \\<in> timpl_closure_set FP TI. \\<forall>f \\<in> funs_term t. is_Abs f \\<longrightarrow> f \\<in> Abs ` OCC\" (is ?A)\n    and \"\\<forall>t \\<in> absc ` OCC. \\<forall>(a,b) \\<in> TI. \\<forall>s \\<in> set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>t\\<rangle>. s \\<in> absc ` OCC\" (is ?B)\nproof -\n  let ?F = \"\\<Union>(funs_term ` FP)\"\n  let ?G = \"Abs ` snd ` TI\"\n\n  show ?A\n  proof (intro ballI impI)\n    fix t f assume t: \"t \\<in> timpl_closure_set FP TI\" and f: \"f \\<in> funs_term t\" \"is_Abs f\"\n    hence \"f \\<in> ?F \\<or> f \\<in> ?G\" using timpl_closure_set_funs_term_subset[of FP TI] by auto\n    thus \"f \\<in> Abs ` OCC\"\n    proof\n      assume \"f \\<in> ?F\" thus ?thesis using OCC1 f(2) by fast\n    next\n      assume \"f \\<in> ?G\" thus ?thesis using OCC2 by auto\n    qed\n  qed\n\n  { fix s t a b\n    assume t: \"t \\<in> absc ` OCC\"\n      and ab: \"(a, b) \\<in> TI\"\n      and s: \"s \\<in> set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>t\\<rangle>\"\n    obtain c where c: \"t = absc c\" \"c \\<in> OCC\" using t by moura\n    hence \"s = absc b \\<or> s = absc c\"\n      using ab s timpl_apply_const'[of c a b] unfolding absc_def by auto\n    moreover have \"b \\<in> OCC\" using ab OCC2 by auto\n    ultimately have \"s \\<in> absc ` OCC\" using c(2) by blast\n  } thus ?B by blast\nqed\n\nlemma (in stateful_protocol_model) intruder_synth_timpl_closure_set:\n  fixes M::\"('fun,'atom,'sets) prot_terms\" and t::\"('fun,'atom,'sets) prot_term\"\n  assumes \"M \\<turnstile>\\<^sub>c t\"\n    and \"s \\<in> timpl_closure t TI\"\n  shows \"timpl_closure_set M TI \\<turnstile>\\<^sub>c s\"\nusing assms\nproof (induction t arbitrary: s rule: intruder_synth_induct)\n  case (AxiomC t)\n  hence \"s \\<in> timpl_closure_set M TI\"\n    using timpl_closure_set_is_timpl_closure_union[of M TI]\n    by blast\n  thus ?case by simp\nnext\n  case (ComposeC T f)\n  obtain g S where s: \"s = Fun g S\"\n    using timpl_closure_Fun_inv[OF ComposeC.prems] by moura\n  hence s':\n      \"f = g\" \"length S = length T\"\n      \"\\<And>i. i < length S \\<Longrightarrow> S ! i \\<in> timpl_closure (T ! i) TI\"\n    using timpl_closure_Fun_inv'[of g S f T TI] ComposeC.prems ComposeC.hyps(2)\n    unfolding is_Abs_def by fastforce+\n  \n  have \"timpl_closure_set M TI \\<turnstile>\\<^sub>c u\" when u: \"u \\<in> set S\" for u\n    using ComposeC.IH u s'(2,3) in_set_conv_nth[of _ T] in_set_conv_nth[of u S] by auto\n  thus ?case\n    using s s'(1,2) ComposeC.hyps(1,2) intruder_synth.ComposeC[of S g \"timpl_closure_set M TI\"]\n    by argo\nqed\n\nlemma (in stateful_protocol_model) intruder_synth_timpl_closure':\n  fixes M::\"('fun,'atom,'sets) prot_terms\" and t::\"('fun,'atom,'sets) prot_term\"\n  assumes \"timpl_closure_set M TI \\<turnstile>\\<^sub>c t\"\n    and \"s \\<in> timpl_closure t TI\"\n  shows \"timpl_closure_set M TI \\<turnstile>\\<^sub>c s\"\nby (metis intruder_synth_timpl_closure_set[OF assms] timpl_closure_set_idem)\n\n\n\n\nsubsection \\<open>Composition-only Intruder Deduction Modulo Term Implication Closure of the Intruder Knowledge\\<close>\ncontext stateful_protocol_model\nbegin\n\nfun in_trancl where\n  \"in_trancl TI a b = (\n    if (a,b) \\<in> set TI then True\n    else list_ex (\\<lambda>(c,d). c = a \\<and> in_trancl (removeAll (c,d) TI) d b) TI)\"\n\ndefinition in_rtrancl where\n  \"in_rtrancl TI a b \\<equiv> a = b \\<or> in_trancl TI a b\"\n\ndeclare in_trancl.simps[simp del]\n\nfun timpls_transformable_to where\n  \"timpls_transformable_to TI (Var x) (Var y) = (x = y)\"\n| \"timpls_transformable_to TI (Fun f T) (Fun g S) = (\n    (f = g \\<or> (is_Abs f \\<and> is_Abs g \\<and> (the_Abs f, the_Abs g) \\<in> set TI)) \\<and>\n    list_all2 (timpls_transformable_to TI) T S)\"\n| \"timpls_transformable_to _ _ _ = False\"\n\nfun timpls_transformable_to' where\n  \"timpls_transformable_to' TI (Var x) (Var y) = (x = y)\"\n| \"timpls_transformable_to' TI (Fun f T) (Fun g S) = (\n    (f = g \\<or> (is_Abs f \\<and> is_Abs g \\<and> in_trancl TI (the_Abs f) (the_Abs g))) \\<and>\n    list_all2 (timpls_transformable_to' TI) T S)\"\n| \"timpls_transformable_to' _ _ _ = False\"\n\nfun equal_mod_timpls where\n  \"equal_mod_timpls TI (Var x) (Var y) = (x = y)\"\n| \"equal_mod_timpls TI (Fun f T) (Fun g S) = (\n    (f = g \\<or> (is_Abs f \\<and> is_Abs g \\<and>\n                ((the_Abs f, the_Abs g) \\<in> set TI \\<or>\n                 (the_Abs g, the_Abs f) \\<in> set TI \\<or>\n                 (\\<exists>ti \\<in> set TI. (the_Abs f, snd ti) \\<in> set TI \\<and> (the_Abs g, snd ti) \\<in> set TI)))) \\<and>\n    list_all2 (equal_mod_timpls TI) T S)\"\n| \"equal_mod_timpls _ _ _ = False\"\n\nfun intruder_synth_mod_timpls where\n  \"intruder_synth_mod_timpls M TI (Var x) = List.member M (Var x)\"\n| \"intruder_synth_mod_timpls M TI (Fun f T) = (\n    (list_ex (\\<lambda>t. timpls_transformable_to TI t (Fun f T)) M) \\<or>\n    (public f \\<and> length T = arity f \\<and> list_all (intruder_synth_mod_timpls M TI) T))\"\n\nfun intruder_synth_mod_timpls' where\n  \"intruder_synth_mod_timpls' M TI (Var x) = List.member M (Var x)\"\n| \"intruder_synth_mod_timpls' M TI (Fun f T) = (\n    (list_ex (\\<lambda>t. timpls_transformable_to' TI t (Fun f T)) M) \\<or>\n    (public f \\<and> length T = arity f \\<and> list_all (intruder_synth_mod_timpls' M TI) T))\"\n\nfun intruder_synth_mod_eq_timpls where\n  \"intruder_synth_mod_eq_timpls M TI (Var x) = (Var x \\<in> M)\"\n| \"intruder_synth_mod_eq_timpls M TI (Fun f T) = (\n    (\\<exists>t \\<in> M. equal_mod_timpls TI t (Fun f T)) \\<or>\n    (public f \\<and> length T = arity f \\<and> list_all (intruder_synth_mod_eq_timpls M TI) T))\"\n\ndefinition analyzed_closed_mod_timpls where\n  \"analyzed_closed_mod_timpls M TI \\<equiv>\n    let f = list_all (intruder_synth_mod_timpls M TI);\n        g = \\<lambda>t. if f (fst (Ana t)) then f (snd (Ana t))\n                else \\<forall>s \\<in> comp_timpl_closure {t} (set TI). case Ana s of (K,R) \\<Rightarrow> f K \\<longrightarrow> f R\n    in list_all g M\"\n\ndefinition analyzed_closed_mod_timpls' where\n  \"analyzed_closed_mod_timpls' M TI \\<equiv>\n    let f = list_all (intruder_synth_mod_timpls' M TI);\n        g = \\<lambda>t. if f (fst (Ana t)) then f (snd (Ana t))\n                else \\<forall>s \\<in> comp_timpl_closure {t} (set TI). case Ana s of (K,R) \\<Rightarrow> f K \\<longrightarrow> f R\n    in list_all g M\"\n(* Alternative definition (allows for computing the closures beforehand which may be useful) *)\ndefinition analyzed_closed_mod_timpls_alt where\n  \"analyzed_closed_mod_timpls_alt M TI timpl_cl_witness \\<equiv>\n    let f = \\<lambda>R. \\<forall>r \\<in> set R. intruder_synth_mod_timpls M TI r;\n        N = {t \\<in> set M. f (fst (Ana t))};\n        N' = set M - N\n    in (\\<forall>t \\<in> N. f (snd (Ana t))) \\<and>\n       (N' \\<noteq> {} \\<longrightarrow> (N' \\<union> (\\<Union>x\\<in>timpl_cl_witness. \\<Union>(a,b)\\<in>set TI. set \\<langle>a --\\<guillemotright> b\\<rangle>\\<langle>x\\<rangle>) \\<subseteq> timpl_cl_witness)) \\<and>\n       (\\<forall>s \\<in> timpl_cl_witness. case Ana s of (K,R) \\<Rightarrow> f K \\<longrightarrow> f R)\"\n\nlemma in_trancl_closure_iff_in_trancl_fun:\n  \"(a,b) \\<in> (set TI)\\<^sup>+ \\<longleftrightarrow> in_trancl TI a b\" (is \"?A TI a b \\<longleftrightarrow> ?B TI a b\")\nproof\n  show \"?A TI a b \\<Longrightarrow> ?B TI a b\"\n  proof (induction rule: trancl_induct)\n    case (step c d)\n    show ?case using step.IH step.hyps(2)\n    proof (induction TI a c rule: in_trancl.induct)\n      case (1 TI a b) thus ?case using in_trancl.simps\n        by (smt Bex_set case_prodE case_prodI member_remove prod.sel(2) remove_code(1))\n    qed\n  qed (metis in_trancl.simps)\n\n  show \"?B TI a b \\<Longrightarrow> ?A TI a b\"\n  proof (induction TI a b rule: in_trancl.induct)\n    case (1 TI a b)\n    let ?P = \"\\<lambda>TI a b c d. in_trancl (List.removeAll (c,d) TI) d b\"\n    have *: \"\\<exists>(c,d) \\<in> set TI. c = a \\<and> ?P TI a b c d\" when \"(a,b) \\<notin> set TI\"\n      using that \"1.prems\" list_ex_iff[of _ TI] in_trancl.simps[of TI a b]\n      by auto\n    show ?case\n    proof (cases \"(a,b) \\<in> set TI\")\n      case False\n      hence \"\\<exists>(c,d) \\<in> set TI. c = a \\<and> ?P TI a b c d\" using * by blast\n      then obtain d where d: \"(a,d) \\<in> set TI\" \"?P TI a b a d\" by blast\n      have \"(d,b) \\<in> (set (removeAll (a,d) TI))\\<^sup>+\" using \"1.IH\"[OF False d(1)] d(2) by blast\n      moreover have \"set (removeAll (a,d) TI) \\<subseteq> set TI\" by simp\n      ultimately have \"(d,b) \\<in> (set TI)\\<^sup>+\" using trancl_mono by blast\n      thus ?thesis using d(1) by fastforce\n    qed simp\n  qed\nqed\n\nlemma in_rtrancl_closure_iff_in_rtrancl_fun:\n  \"(a,b) \\<in> (set TI)\\<^sup>* \\<longleftrightarrow> in_rtrancl TI a b\"\nby (metis rtrancl_eq_or_trancl in_trancl_closure_iff_in_trancl_fun in_rtrancl_def)\n\nlemma in_trancl_mono:\n  assumes \"set TI \\<subseteq> set TI'\"\n    and \"in_trancl TI a b\"\n  shows \"in_trancl TI' a b\"\nby (metis assms in_trancl_closure_iff_in_trancl_fun trancl_mono)\n\nlemma equal_mod_timpls_refl:\n  \"equal_mod_timpls TI t t\"\nproof (induction t)\n  case (Fun f T) thus ?case\n    using list_all2_conv_all_nth[of \"equal_mod_timpls TI\" T T] by force\nqed simp\n\nlemma equal_mod_timpls_inv_Var:\n  \"equal_mod_timpls TI (Var x) t \\<Longrightarrow> t = Var x\" (is \"?A \\<Longrightarrow> ?C\")\n  \"equal_mod_timpls TI t (Var x) \\<Longrightarrow> t = Var x\" (is \"?B \\<Longrightarrow> ?C\")\nproof -\n  show \"?A \\<Longrightarrow> ?C\" by (cases t) auto\n  show \"?B \\<Longrightarrow> ?C\" by (cases t) auto\nqed\n\nlemma equal_mod_timpls_inv:\n  assumes \"equal_mod_timpls TI (Fun f T) (Fun g S)\"\n  shows \"length T = length S\"\n    and \"\\<And>i. i < length T \\<Longrightarrow> equal_mod_timpls TI (T ! i) (S ! i)\"\n    and \"f \\<noteq> g \\<Longrightarrow> (is_Abs f \\<and> is_Abs g \\<and> (\n                      (the_Abs f, the_Abs g) \\<in> set TI \\<or> (the_Abs g, the_Abs f) \\<in> set TI \\<or>\n                      (\\<exists>ti \\<in> set TI. (the_Abs f, snd ti) \\<in> set TI \\<and>\n                                     (the_Abs g, snd ti) \\<in> set TI)))\"\nusing assms list_all2_conv_all_nth[of \"equal_mod_timpls TI\" T S]\nby (auto elim: equal_mod_timpls.cases)\n\nlemma equal_mod_timpls_inv':\n  assumes \"equal_mod_timpls TI (Fun f T) t\"\n  shows \"is_Fun t\"\n    and \"length T = length (args t)\"\n    and \"\\<And>i. i < length T \\<Longrightarrow> equal_mod_timpls TI (T ! i) (args t ! i)\"\n    and \"f \\<noteq> the_Fun t \\<Longrightarrow> (is_Abs f \\<and> is_Abs (the_Fun t) \\<and> (\n                      (the_Abs f, the_Abs (the_Fun t)) \\<in> set TI \\<or>\n                      (the_Abs (the_Fun t), the_Abs f) \\<in> set TI \\<or>\n                      (\\<exists>ti \\<in> set TI. (the_Abs f, snd ti) \\<in> set TI \\<and>\n                                     (the_Abs (the_Fun t), snd ti) \\<in> set TI)))\"\n    and \"\\<not>is_Abs f \\<Longrightarrow> f = the_Fun t\"\nusing assms list_all2_conv_all_nth[of \"equal_mod_timpls TI\" T]\nby (cases t; auto)+\n\nlemma equal_mod_timpls_if_term_variants:\n  fixes s t::\"(('a, 'b, 'c) prot_fun, 'd) term\" and a b::\"'c set\"\n  defines \"P \\<equiv> (\\<lambda>_. [])(Abs a := [Abs b])\"\n  assumes st: \"term_variants_pred P s t\"\n    and ab: \"(a,b) \\<in> set TI\"\n  shows \"equal_mod_timpls TI s t\"\nusing st P_def\nproof (induction rule: term_variants_pred.induct)\n  case (term_variants_P T S f) thus ?case\n    using ab list_all2_conv_all_nth[of \"equal_mod_timpls TI\" T S]\n          in_trancl_closure_iff_in_trancl_fun[of _ _ TI]\n    by auto\nnext\n  case (term_variants_Fun T S f) thus ?case\n    using ab list_all2_conv_all_nth[of \"equal_mod_timpls TI\" T S]\n          in_trancl_closure_iff_in_trancl_fun[of _ _ TI]\n    by auto\nqed simp\n\nlemma equal_mod_timpls_mono:\n  assumes \"set TI \\<subseteq> set TI'\"\n    and \"equal_mod_timpls TI s t\"\n  shows \"equal_mod_timpls TI' s t\"\n  using assms\nproof (induction TI s t rule: equal_mod_timpls.induct)\n  case (2 TI f T g S)\n  have *: \"f = g \\<or> (is_Abs f \\<and> is_Abs g \\<and> ((the_Abs f, the_Abs g) \\<in> set TI \\<or>\n                 (the_Abs g, the_Abs f) \\<in> set TI \\<or>\n                 (\\<exists>ti \\<in> set TI. (the_Abs f, snd ti) \\<in> set TI \\<and>\n                                (the_Abs g, snd ti) \\<in> set TI)))\"\n          \"list_all2 (equal_mod_timpls TI) T S\"\n    using \"2.prems\" by simp_all\n\n  show ?case\n    using \"2.IH\" \"2.prems\"(1) list.rel_mono_strong[OF *(2)] *(1) in_trancl_mono[of TI TI']\n    by (metis (no_types, lifting) equal_mod_timpls.simps(2) set_rev_mp)\nqed auto\n\nlemma equal_mod_timpls_refl_minus_eq:\n  \"equal_mod_timpls TI s t \\<longleftrightarrow> equal_mod_timpls (filter (\\<lambda>(a,b). a \\<noteq> b) TI) s t\"\n  (is \"?A \\<longleftrightarrow> ?B\")\nproof\n  show ?A when ?B using that equal_mod_timpls_mono[of \"filter (\\<lambda>(a,b). a \\<noteq> b) TI\" TI] by auto\n\n  show ?B when ?A using that\n  proof (induction TI s t rule: equal_mod_timpls.induct)\n    case (2 TI f T g S)\n    define TI' where \"TI' \\<equiv> filter (\\<lambda>(a,b). a \\<noteq> b) TI\"\n\n    let ?P = \"\\<lambda>X Y. f = g \\<or> (is_Abs f \\<and> is_Abs g \\<and> ((the_Abs f, the_Abs g) \\<in> set X \\<or>\n                 (the_Abs g, the_Abs f) \\<in> set X \\<or> (\\<exists>ti \\<in> set Y.\n                 (the_Abs f, snd ti) \\<in> set X \\<and> (the_Abs g, snd ti) \\<in> set X)))\"\n\n    have *: \"?P TI TI\" \"list_all2 (equal_mod_timpls TI) T S\"\n      using \"2.prems\" by simp_all\n\n    have \"?P TI' TI\"\n      using *(1) unfolding TI'_def is_Abs_def by auto\n    hence \"?P TI' TI'\"\n      by (metis (no_types, lifting) snd_conv)\n    moreover have \"list_all2 (equal_mod_timpls TI') T S\"\n      using *(2) \"2.IH\" list.rel_mono_strong unfolding TI'_def by blast\n    ultimately show ?case unfolding TI'_def by force\n  qed auto\nqed\n\nlemma timpls_transformable_to_refl:\n  \"timpls_transformable_to TI t t\" (is ?A)\n  \"timpls_transformable_to' TI t t\" (is ?B)\nby (induct t) (auto simp add: list_all2_conv_all_nth)\n\nlemma timpls_transformable_to_inv_Var:\n  \"timpls_transformable_to TI (Var x) t \\<Longrightarrow> t = Var x\" (is \"?A \\<Longrightarrow> ?C\")\n  \"timpls_transformable_to TI t (Var x) \\<Longrightarrow> t = Var x\" (is \"?B \\<Longrightarrow> ?C\")\n  \"timpls_transformable_to' TI (Var x) t \\<Longrightarrow> t = Var x\" (is \"?A' \\<Longrightarrow> ?C\")\n  \"timpls_transformable_to' TI t (Var x) \\<Longrightarrow> t = Var x\" (is \"?B' \\<Longrightarrow> ?C\")\nby (cases t; auto)+\n\nlemma timpls_transformable_to_inv:\n  assumes \"timpls_transformable_to TI (Fun f T) (Fun g S)\"\n  shows \"length T = length S\"\n    and \"\\<And>i. i < length T \\<Longrightarrow> timpls_transformable_to TI (T ! i) (S ! i)\"\n    and \"f \\<noteq> g \\<Longrightarrow> (is_Abs f \\<and> is_Abs g \\<and> (the_Abs f, the_Abs g) \\<in> set TI)\"\nusing assms list_all2_conv_all_nth[of \"timpls_transformable_to TI\" T S] by auto\n\nlemma timpls_transformable_to'_inv:\n  assumes \"timpls_transformable_to' TI (Fun f T) (Fun g S)\"\n  shows \"length T = length S\"\n    and \"\\<And>i. i < length T \\<Longrightarrow> timpls_transformable_to' TI (T ! i) (S ! i)\"\n    and \"f \\<noteq> g \\<Longrightarrow> (is_Abs f \\<and> is_Abs g \\<and> in_trancl TI (the_Abs f) (the_Abs g))\"\nusing assms list_all2_conv_all_nth[of \"timpls_transformable_to' TI\" T S] by auto\n\nlemma timpls_transformable_to_inv':\n  assumes \"timpls_transformable_to TI (Fun f T) t\"\n  shows \"is_Fun t\"\n    and \"length T = length (args t)\"\n    and \"\\<And>i. i < length T \\<Longrightarrow> timpls_transformable_to TI (T ! i) (args t ! i)\"\n    and \"f \\<noteq> the_Fun t \\<Longrightarrow> (\n          is_Abs f \\<and> is_Abs (the_Fun t) \\<and> (the_Abs f, the_Abs (the_Fun t)) \\<in> set TI)\"\n    and \"\\<not>is_Abs f \\<Longrightarrow> f = the_Fun t\"\nusing assms list_all2_conv_all_nth[of \"timpls_transformable_to TI\" T]\nby (cases t; auto)+\n\nlemma timpls_transformable_to'_inv':\n  assumes \"timpls_transformable_to' TI (Fun f T) t\"\n  shows \"is_Fun t\"\n    and \"length T = length (args t)\"\n    and \"\\<And>i. i < length T \\<Longrightarrow> timpls_transformable_to' TI (T ! i) (args t ! i)\"\n    and \"f \\<noteq> the_Fun t \\<Longrightarrow> (\n          is_Abs f \\<and> is_Abs (the_Fun t) \\<and> in_trancl TI (the_Abs f) (the_Abs (the_Fun t)))\"\n    and \"\\<not>is_Abs f \\<Longrightarrow> f = the_Fun t\"\nusing assms list_all2_conv_all_nth[of \"timpls_transformable_to' TI\" T]\nby (cases t; auto)+\n\nlemma timpls_transformable_to_size_eq:\n  fixes s t::\"(('b, 'c, 'a) prot_fun, 'd) term\"\n  shows \"timpls_transformable_to TI s t \\<Longrightarrow> size s = size t\" (is \"?A \\<Longrightarrow> ?C\")\n    and \"timpls_transformable_to' TI s t \\<Longrightarrow> size s = size t\" (is \"?B \\<Longrightarrow> ?C\")\nproof -\n  have *: \"size_list size T = size_list size S\"\n    when \"length T = length S\" \"\\<And>i. i < length T \\<Longrightarrow> size (T ! i) = size (S ! i)\"\n    for S T::\"(('b, 'c, 'a) prot_fun, 'd) term list\"\n    using that\n  proof (induction T arbitrary: S)\n    case (Cons x T')\n    then obtain y S' where y: \"S = y#S'\" by (cases S) auto\n    hence \"size_list size T' = size_list size S'\" \"size x = size y\"\n      using Cons.prems Cons.IH[of S'] by force+\n    thus ?case using y by simp\n  qed simp\n\n  show ?C when ?A using that\n  proof (induction rule: timpls_transformable_to.induct)\n    case (2 TI f T g S)\n    hence \"length T = length S\" \"\\<And>i. i < length T \\<Longrightarrow> size (T ! i) = size (S ! i)\"\n      using timpls_transformable_to_inv(1,2)[of TI f T g S] by auto\n    thus ?case using *[of S T] by simp\n  qed simp_all\n\n  show ?C when ?B using that\n  proof (induction rule: timpls_transformable_to.induct)\n    case (2 TI f T g S)\n    hence \"length T = length S\" \"\\<And>i. i < length T \\<Longrightarrow> size (T ! i) = size (S ! i)\"\n      using timpls_transformable_to'_inv(1,2)[of TI f T g S] by auto\n    thus ?case using *[of S T] by simp\n  qed simp_all\nqed\n\nlemma timpls_transformable_to_if_term_variants:\n  fixes s t::\"(('a, 'b, 'c) prot_fun, 'd) term\" and a b::\"'c set\"\n  defines \"P \\<equiv> (\\<lambda>_. [])(Abs a := [Abs b])\"\n  assumes st: \"term_variants_pred P s t\"\n    and ab: \"(a,b) \\<in> set TI\"\n  shows \"timpls_transformable_to TI s t\"\nusing st P_def\nproof (induction rule: term_variants_pred.induct)\n  case (term_variants_P T S f) thus ?case\n    using ab list_all2_conv_all_nth[of \"timpls_transformable_to TI\" T S]\n    by auto\nnext\n  case (term_variants_Fun T S f) thus ?case\n    using ab list_all2_conv_all_nth[of \"timpls_transformable_to TI\" T S]\n    by auto\nqed simp\n\nlemma timpls_transformable_to'_if_term_variants:\n  fixes s t::\"(('a, 'b, 'c) prot_fun, 'd) term\" and a b::\"'c set\"\n  defines \"P \\<equiv> (\\<lambda>_. [])(Abs a := [Abs b])\"\n  assumes st: \"term_variants_pred P s t\"\n    and ab: \"(a,b) \\<in> (set TI)\\<^sup>+\"\n  shows \"timpls_transformable_to' TI s t\"\nusing st P_def\nproof (induction rule: term_variants_pred.induct)\n  case (term_variants_P T S f) thus ?case\n    using ab list_all2_conv_all_nth[of \"timpls_transformable_to' TI\" T S]\n          in_trancl_closure_iff_in_trancl_fun[of _ _ TI]\n    by auto\nnext\n  case (term_variants_Fun T S f) thus ?case\n    using ab list_all2_conv_all_nth[of \"timpls_transformable_to' TI\" T S]\n          in_trancl_closure_iff_in_trancl_fun[of _ _ TI]\n    by auto\nqed simp\n\nlemma timpls_transformable_to_trans:\n  assumes TI_trancl: \"\\<forall>(a,b) \\<in> (set TI)\\<^sup>+. a \\<noteq> b \\<longrightarrow> (a,b) \\<in> set TI\"\n    and st: \"timpls_transformable_to TI s t\"\n    and tu: \"timpls_transformable_to TI t u\"\n  shows \"timpls_transformable_to TI s u\"\nusing st tu\nproof (induction s arbitrary: t u)\n  case (Var x) thus ?case using tu timpls_transformable_to_inv_Var(1) by fast\nnext\n  case (Fun f T)\n  obtain g S where t:\n      \"t = Fun g S\" \"length T = length S\"\n      \"\\<And>i. i < length T \\<Longrightarrow> timpls_transformable_to TI (T ! i) (S ! i)\"\n      \"f \\<noteq> g \\<Longrightarrow> is_Abs f \\<and> is_Abs g \\<and> (the_Abs f, the_Abs g) \\<in> set TI\"\n    using timpls_transformable_to_inv'[OF Fun.prems(1)] TI_trancl by moura\n\n  obtain h U where u:\n      \"u = Fun h U\" \"length S = length U\"\n      \"\\<And>i. i < length S \\<Longrightarrow> timpls_transformable_to TI (S ! i) (U ! i)\"\n      \"g \\<noteq> h \\<Longrightarrow> is_Abs g \\<and> is_Abs h \\<and> (the_Abs g, the_Abs h) \\<in> set TI\"\n    using timpls_transformable_to_inv'[OF Fun.prems(2)[unfolded t(1)]] TI_trancl by moura\n\n  have \"list_all2 (timpls_transformable_to TI) T U\"\n    using t(1,2,3) u(1,2,3) Fun.IH\n          list_all2_conv_all_nth[of \"timpls_transformable_to TI\" T S]\n          list_all2_conv_all_nth[of \"timpls_transformable_to TI\" S U]\n          list_all2_conv_all_nth[of \"timpls_transformable_to TI\" T U]\n    by force\n  moreover have \"(the_Abs f, the_Abs h) \\<in> set TI\"\n    when \"(the_Abs f, the_Abs g) \\<in> set TI\" \"(the_Abs g, the_Abs h) \\<in> set TI\"\n         \"f \\<noteq> h\" \"is_Abs f\" \"is_Abs h\"\n    using that(3,4,5) TI_trancl trancl_into_trancl[OF r_into_trancl[OF that(1)] that(2)]\n    unfolding is_Abs_def the_Abs_def\n    by force\n  hence \"is_Abs f \\<and> is_Abs h \\<and> (the_Abs f, the_Abs h) \\<in> set TI\"\n    when \"f \\<noteq> h\"\n    using that TI_trancl t(4) u(4) by fast\n  ultimately show ?case using t(1) u(1) by force\nqed\n\nlemma timpls_transformable_to'_trans:\n  assumes st: \"timpls_transformable_to' TI s t\"\n    and tu: \"timpls_transformable_to' TI t u\"\n  shows \"timpls_transformable_to' TI s u\"\nusing st tu\nproof (induction s arbitrary: t u)\n  case (Var x) thus ?case using tu timpls_transformable_to_inv_Var(3) by fast\nnext\n  case (Fun f T)\n  note 0 = in_trancl_closure_iff_in_trancl_fun[of _ _ TI]\n\n  obtain g S where t:\n      \"t = Fun g S\" \"length T = length S\"\n      \"\\<And>i. i < length T \\<Longrightarrow> timpls_transformable_to' TI (T ! i) (S ! i)\"\n      \"f \\<noteq> g \\<Longrightarrow> is_Abs f \\<and> is_Abs g \\<and> (the_Abs f, the_Abs g) \\<in> (set TI)\\<^sup>+\"\n    using timpls_transformable_to'_inv'[OF Fun.prems(1)] 0 by moura\n\n  obtain h U where u:\n      \"u = Fun h U\" \"length S = length U\"\n      \"\\<And>i. i < length S \\<Longrightarrow> timpls_transformable_to' TI (S ! i) (U ! i)\"\n      \"g \\<noteq> h \\<Longrightarrow> is_Abs g \\<and> is_Abs h \\<and> (the_Abs g, the_Abs h) \\<in> (set TI)\\<^sup>+\"\n    using timpls_transformable_to'_inv'[OF Fun.prems(2)[unfolded t(1)]] 0 by moura\n\n  have \"list_all2 (timpls_transformable_to' TI) T U\"\n    using t(1,2,3) u(1,2,3) Fun.IH\n          list_all2_conv_all_nth[of \"timpls_transformable_to' TI\" T S]\n          list_all2_conv_all_nth[of \"timpls_transformable_to' TI\" S U]\n          list_all2_conv_all_nth[of \"timpls_transformable_to' TI\" T U]\n    by force\n  moreover have \"(the_Abs f, the_Abs h) \\<in> (set TI)\\<^sup>+\"\n    when \"(the_Abs f, the_Abs g) \\<in> (set TI)\\<^sup>+\" \"(the_Abs g, the_Abs h) \\<in> (set TI)\\<^sup>+\"\n    using that by simp\n  hence \"is_Abs f \\<and> is_Abs h \\<and> (the_Abs f, the_Abs h) \\<in> (set TI)\\<^sup>+\"\n    when \"f \\<noteq> h\"\n    by (metis that t(4) u(4))\n  ultimately show ?case using t(1) u(1) 0 by force\nqed\n\nlemma timpls_transformable_to_mono:\n  assumes \"set TI \\<subseteq> set TI'\"\n    and \"timpls_transformable_to TI s t\"\n  shows \"timpls_transformable_to TI' s t\"\n  using assms\nproof (induction TI s t rule: timpls_transformable_to.induct)\n  case (2 TI f T g S)\n  have *: \"f = g \\<or> (is_Abs f \\<and> is_Abs g \\<and> (the_Abs f, the_Abs g) \\<in> set TI)\"\n          \"list_all2 (timpls_transformable_to TI) T S\"\n    using \"2.prems\" by simp_all\n\n  show ?case\n    using \"2.IH\" \"2.prems\"(1) list.rel_mono_strong[OF *(2)] *(1) in_trancl_mono[of TI TI']\n    by (metis (no_types, lifting) timpls_transformable_to.simps(2) set_rev_mp)\nqed auto\n\nlemma timpls_transformable_to'_mono:\n  assumes \"set TI \\<subseteq> set TI'\"\n    and \"timpls_transformable_to' TI s t\"\n  shows \"timpls_transformable_to' TI' s t\"\n  using assms\nproof (induction TI s t rule: timpls_transformable_to'.induct)\n  case (2 TI f T g S)\n  have *: \"f = g \\<or> (is_Abs f \\<and> is_Abs g \\<and> in_trancl TI (the_Abs f) (the_Abs g))\"\n          \"list_all2 (timpls_transformable_to' TI) T S\"\n    using \"2.prems\" by simp_all\n\n  show ?case\n    using \"2.IH\" \"2.prems\"(1) list.rel_mono_strong[OF *(2)] *(1) in_trancl_mono[of TI TI']\n    by (metis (no_types, lifting) timpls_transformable_to'.simps(2))\nqed auto\n\nlemma timpls_transformable_to_refl_minus_eq:\n  \"timpls_transformable_to TI s t \\<longleftrightarrow> timpls_transformable_to (filter (\\<lambda>(a,b). a \\<noteq> b) TI) s t\"\n  (is \"?A \\<longleftrightarrow> ?B\")\nproof\n  let ?TI' = \"\\<lambda>TI. filter (\\<lambda>(a,b). a \\<noteq> b) TI\"\n\n  show ?A when ?B using that timpls_transformable_to_mono[of \"?TI' TI\" TI] by auto\n\n  show ?B when ?A using that\n  proof (induction TI s t rule: timpls_transformable_to.induct)\n    case (2 TI f T g S)\n    have *: \"f = g \\<or> (is_Abs f \\<and> is_Abs g \\<and> (the_Abs f, the_Abs g) \\<in> set TI)\"\n            \"list_all2 (timpls_transformable_to TI) T S\"\n      using \"2.prems\" by simp_all\n\n    have \"f = g \\<or> (is_Abs f \\<and> is_Abs g \\<and> (the_Abs f, the_Abs g) \\<in> set (?TI' TI))\"\n      using *(1) unfolding is_Abs_def by auto\n    moreover have \"list_all2 (timpls_transformable_to (?TI' TI)) T S\"\n      using *(2) \"2.IH\" list.rel_mono_strong by blast\n    ultimately show ?case by force\n  qed auto\nqed\n\nlemma timpls_transformable_to_iff_in_timpl_closure:\n  assumes \"set TI' = {(a,b) \\<in> (set TI)\\<^sup>+. a \\<noteq> b}\"\n  shows \"timpls_transformable_to TI' s t \\<longleftrightarrow> t \\<in> timpl_closure s (set TI)\" (is \"?A s t \\<longleftrightarrow> ?B s t\")\nproof\n  show \"?A s t \\<Longrightarrow> ?B s t\" using assms\n  proof (induction s t rule: timpls_transformable_to.induct)\n    case (2 TI f T g S)\n    note prems = \"2.prems\"\n    note IH = \"2.IH\"\n\n    have 1: \"length T = length S\" \"\\<forall>i<length T. timpls_transformable_to TI' (T ! i) (S ! i)\"\n      using prems(1) list_all2_conv_all_nth[of \"timpls_transformable_to TI'\" T S] by simp_all\n\n    note 2 = timpl_closure_is_timpl_closure'\n    note 3 = in_set_conv_nth[of _ T] in_set_conv_nth[of _ S]\n\n    have 4: \"timpl_closure' (set TI') = timpl_closure' (set TI)\"\n      using timpl_closure'_timpls_trancl_eq'[of \"set TI\"] prems(2) by simp\n\n    have IH': \"(T ! i, S ! i) \\<in> timpl_closure' (set TI')\" when i: \"i < length S\" for i\n    proof -\n      have \"timpls_transformable_to TI' (T ! i) (S ! i)\" using i 1 by presburger \n      hence \"S ! i \\<in> timpl_closure (T ! i) (set TI)\"\n        using IH[of \"T ! i\" \"S ! i\"] i 1(1) prems(2) by force\n      thus ?thesis using 2[of \"S ! i\" \"T ! i\" \"set TI\"] 4 by blast\n    qed\n\n    have 5: \"f = g \\<or> (\\<exists>a b. (a, b) \\<in> (set TI')\\<^sup>+ \\<and> f = Abs a \\<and> g = Abs b)\"\n      using prems(1) the_Abs_def[of f] the_Abs_def[of g] is_Abs_def[of f] is_Abs_def[of g] \n      by fastforce\n\n    show ?case using 2 4 timpl_closure_FunI[OF IH' 1(1) 5] 1(1) by auto\n  qed (simp_all add: timpl_closure.FP)\n\n  show \"?B s t \\<Longrightarrow> ?A s t\"\n  proof (induction t rule: timpl_closure.induct)\n    case (TI u a b v) show ?case\n    proof (cases \"a = b\")\n      case True thus ?thesis using TI.hyps(3) TI.IH term_variants_pred_refl_inv by fastforce\n    next\n      case False\n      hence 1: \"timpls_transformable_to TI' u v\"\n        using TI.hyps(2) assms timpls_transformable_to_if_term_variants[OF TI.hyps(3), of TI']\n        by blast\n      have 2: \"(c,d) \\<in> set TI'\" when cd: \"(c,d) \\<in> (set TI')\\<^sup>+\" \"c \\<noteq> d\" for c d\n      proof -\n        let ?cl = \"\\<lambda>X. {(a,b) \\<in> X\\<^sup>+. a \\<noteq> b}\"\n        have \"?cl (set TI') = ?cl (?cl (set TI))\" using assms by presburger\n        hence \"set TI' = ?cl (set TI')\" using assms trancl_minus_refl_idem[of \"set TI\"] by argo\n        thus ?thesis using cd by blast\n      qed\n      show ?thesis using timpls_transformable_to_trans[OF _ TI.IH 1] 2 by blast\n    qed\n  qed (use timpls_transformable_to_refl in fast)\nqed\n\nlemma timpls_transformable_to'_iff_in_timpl_closure:\n  \"timpls_transformable_to' TI s t \\<longleftrightarrow> t \\<in> timpl_closure s (set TI)\" (is \"?A s t \\<longleftrightarrow> ?B s t\")\nproof\n  show \"?A s t \\<Longrightarrow> ?B s t\"\n  proof (induction s t rule: timpls_transformable_to'.induct)\n    case (2 TI f T g S)\n    note prems = \"2.prems\"\n    note IH = \"2.IH\"\n\n    have 1: \"length T = length S\" \"\\<forall>i<length T. timpls_transformable_to' TI (T ! i) (S ! i)\"\n      using prems list_all2_conv_all_nth[of \"timpls_transformable_to' TI\" T S] by simp_all\n\n    note 2 = timpl_closure_is_timpl_closure'\n    note 3 = in_set_conv_nth[of _ T] in_set_conv_nth[of _ S]\n\n    have IH': \"(T ! i, S ! i) \\<in> timpl_closure' (set TI)\" when i: \"i < length S\" for i\n    proof -\n      have \"timpls_transformable_to' TI (T ! i) (S ! i)\" using i 1 by presburger \n      hence \"S ! i \\<in> timpl_closure (T ! i) (set TI)\" using IH[of \"T ! i\" \"S ! i\"] i 1(1) by force\n      thus ?thesis using 2[of \"S ! i\" \"T ! i\" \"set TI\"] by blast\n    qed\n\n    have 4: \"f = g \\<or> (\\<exists>a b. (a, b) \\<in> (set TI)\\<^sup>+ \\<and> f = Abs a \\<and> g = Abs b)\"\n      using prems the_Abs_def[of f] the_Abs_def[of g] is_Abs_def[of f] is_Abs_def[of g]\n            in_trancl_closure_iff_in_trancl_fun[of _ _ TI]\n      by auto\n\n    show ?case using 2 timpl_closure_FunI[OF IH' 1(1) 4] 1(1) by auto\n  qed (simp_all add: timpl_closure.FP)\n\n  show \"?B s t \\<Longrightarrow> ?A s t\"\n  proof (induction t rule: timpl_closure.induct)\n    case (TI u a b v) thus ?case\n      using timpls_transformable_to'_trans\n            timpls_transformable_to'_if_term_variants\n      by blast\n  qed (use timpls_transformable_to_refl(2) in fast)\nqed\n\nlemma equal_mod_timpls_iff_ex_in_timpl_closure:\n  assumes \"set TI' = {(a,b) \\<in> TI\\<^sup>+. a \\<noteq> b}\"\n  shows \"equal_mod_timpls TI' s t \\<longleftrightarrow> (\\<exists>u. u \\<in> timpl_closure s TI \\<and> u \\<in> timpl_closure t TI)\"\n    (is \"?A s t \\<longleftrightarrow> ?B s t\")\nproof\n  show \"?A s t \\<Longrightarrow> ?B s t\" using assms\n  proof (induction s t rule: equal_mod_timpls.induct)\n    case (2 TI' f T g S)\n    note prems = \"2.prems\"\n    note IH = \"2.IH\"\n\n    have 1: \"length T = length S\" \"\\<forall>i<length T. equal_mod_timpls (TI') (T ! i) (S ! i)\"\n      using prems list_all2_conv_all_nth[of \"equal_mod_timpls TI'\" T S] by simp_all\n\n    note 2 = timpl_closure_is_timpl_closure'\n    note 3 = in_set_conv_nth[of _ T] in_set_conv_nth[of _ S]\n\n    have 4: \"timpl_closure' (set TI') = timpl_closure' TI\"\n      using timpl_closure'_timpls_trancl_eq'[of TI] prems\n      by simp\n\n    have IH: \"\\<exists>u. (T ! i, u) \\<in> timpl_closure' TI \\<and> (S ! i, u) \\<in> timpl_closure' TI\"\n      when i: \"i < length S\" for i\n    proof -\n      have \"equal_mod_timpls TI' (T ! i) (S ! i)\" using i 1 by presburger \n      hence \"\\<exists>u. u \\<in> timpl_closure (T ! i) TI \\<and> u \\<in> timpl_closure (S ! i) TI\"\n        using IH[of \"T ! i\" \"S ! i\"] i 1(1) prems by force\n      thus ?thesis using 4 unfolding 2 by blast\n    qed\n\n    let ?P = \"\\<lambda>G. f = g \\<or> (\\<exists>a b. (a, b) \\<in> G \\<and> f = Abs a \\<and> g = Abs b) \\<or>\n                   (\\<exists>a b. (a, b) \\<in> G \\<and> f = Abs b \\<and> g = Abs a) \\<or>\n                   (\\<exists>a b c. (a, c) \\<in> G \\<and> (b, c) \\<in> G \\<and> f = Abs a \\<and> g = Abs b)\"\n\n    have \"?P (set TI')\"\n      using prems the_Abs_def[of f] the_Abs_def[of g] is_Abs_def[of f] is_Abs_def[of g]\n      by fastforce\n    hence \"?P (TI\\<^sup>+)\" unfolding prems by blast\n    hence \"?P (rtrancl TI)\" by (metis (no_types, lifting) trancl_into_rtrancl)\n    hence 5: \"f = g \\<or> (\\<exists>a b c. (a, c) \\<in> TI\\<^sup>* \\<and> (b, c) \\<in> TI\\<^sup>* \\<and> f = Abs a \\<and> g = Abs b)\" by blast\n\n    show ?case\n      using timpl_closure_FunI3[OF _ 1(1) 5]  IH 1(1)\n      unfolding timpl_closure'_timpls_rtrancl_eq 2\n      by auto\n  qed (use timpl_closure.FP in auto)\n\n  show \"?A s t\" when B: \"?B s t\"\n  proof -\n    obtain u where u: \"u \\<in> timpl_closure s TI\" \"u \\<in> timpl_closure t TI\"\n      using B by moura\n    thus ?thesis using assms\n    proof (induction u arbitrary: s t rule: term.induct)\n      case (Var x s t) thus ?case\n        using timpl_closure_Var_in_iff[of x s TI]\n              timpl_closure_Var_in_iff[of x t TI]\n              equal_mod_timpls.simps(1)[of TI' x x]\n        by blast\n    next\n      case (Fun f U s t)\n      obtain g S where s:\n          \"s = Fun g S\" \"length U = length S\"\n          \"\\<And>i. i < length U \\<Longrightarrow> U ! i \\<in> timpl_closure (S ! i) TI\"\n          \"g \\<noteq> f \\<Longrightarrow> is_Abs g \\<and> is_Abs f \\<and> (the_Abs g, the_Abs f) \\<in> TI\\<^sup>+\"\n        using Fun.prems(1) timpl_closure_Fun_inv'[of f U _ _ TI]\n        by (cases s) auto\n\n      obtain h T where t:\n          \"t = Fun h T\" \"length U = length T\"\n          \"\\<And>i. i < length U \\<Longrightarrow> U ! i \\<in> timpl_closure (T ! i) TI\"\n          \"h \\<noteq> f \\<Longrightarrow> is_Abs h \\<and> is_Abs f \\<and> (the_Abs h, the_Abs f) \\<in> TI\\<^sup>+\"\n        using Fun.prems(2) timpl_closure_Fun_inv'[of f U _ _ TI]\n        by (cases t) auto\n\n      have g: \"(the_Abs g, the_Abs f) \\<in> set TI'\" \"is_Abs f\" \"is_Abs g\" when neq_f: \"g \\<noteq> f\"\n      proof -\n        obtain ga fa where a: \"g = Abs ga\" \"f = Abs fa\"\n          using s(4)[OF neq_f] unfolding is_Abs_def by presburger\n        hence \"the_Abs g \\<noteq> the_Abs f\" using neq_f by simp\n        thus \"(the_Abs g, the_Abs f) \\<in> set TI'\" \"is_Abs f\" \"is_Abs g\"\n          using s(4)[OF neq_f] Fun.prems by blast+\n      qed\n\n      have h: \"(the_Abs h, the_Abs f) \\<in> set TI'\" \"is_Abs f\" \"is_Abs h\" when neq_f: \"h \\<noteq> f\"\n      proof -\n        obtain ha fa where a: \"h = Abs ha\" \"f = Abs fa\"\n          using t(4)[OF neq_f] unfolding is_Abs_def by presburger\n        hence \"the_Abs h \\<noteq> the_Abs f\" using neq_f by simp\n        thus \"(the_Abs h, the_Abs f) \\<in> set TI'\" \"is_Abs f\" \"is_Abs h\"\n          using t(4)[OF neq_f] Fun.prems by blast+\n      qed\n\n      have \"equal_mod_timpls TI' (S ! i) (T ! i)\"\n        when i: \"i < length U\" for i\n        using i Fun.IH s(1,2,3) t(1,2,3) nth_mem[OF i] Fun.prems by meson\n      hence \"list_all2 (equal_mod_timpls TI') S T\"\n        using list_all2_conv_all_nth[of \"equal_mod_timpls TI'\" S T] s(2) t(2) by presburger\n      thus ?case using s(1) t(1) g h by fastforce\n    qed\n  qed\nqed\n\n(* lemma equal_mod_timpls_iff_ex_in_timpl_closure':\n  \"equal_mod_timpls (TI\\<^sup>+) s t \\<longleftrightarrow> (\\<exists>u. u \\<in> timpl_closure s TI \\<and> u \\<in> timpl_closure t TI)\"\nusing equal_mod_timpls_iff_ex_in_timpl_closure equal_mod_timpls_refl_minus_eq\nby blast *)\n\ncontext\nbegin\nprivate inductive timpls_transformable_to_pred where\n  Var: \"timpls_transformable_to_pred A (Var x) (Var x)\"\n| Fun: \"\\<lbrakk>\\<not>is_Abs f; length T = length S;\n         \\<And>i. i < length T \\<Longrightarrow> timpls_transformable_to_pred A (T ! i) (S ! i)\\<rbrakk>\n        \\<Longrightarrow> timpls_transformable_to_pred A (Fun f T) (Fun f S)\"\n| Abs: \"b \\<in> A \\<Longrightarrow> timpls_transformable_to_pred A (Fun (Abs a) []) (Fun (Abs b) [])\"\n\nprivate lemma timpls_transformable_to_pred_inv_Var:\n  assumes \"timpls_transformable_to_pred A (Var x) t\"\n  shows \"t = Var x\"\nusing assms by (auto elim: timpls_transformable_to_pred.cases)\n\nprivate lemma timpls_transformable_to_pred_inv:\n  assumes \"timpls_transformable_to_pred A (Fun f T) t\"\n  shows \"is_Fun t\"\n    and \"length T = length (args t)\"\n    and \"\\<And>i. i < length T \\<Longrightarrow> timpls_transformable_to_pred A (T ! i) (args t ! i)\"\n    and \"\\<not>is_Abs f \\<Longrightarrow> f = the_Fun t\"\n    and \"is_Abs f \\<Longrightarrow> (is_Abs (the_Fun t) \\<and> the_Abs (the_Fun t) \\<in> A)\"\nusing assms by (auto elim!: timpls_transformable_to_pred.cases[of A])\n\nprivate lemma timpls_transformable_to_pred_finite_aux1:\n  assumes f: \"\\<not>is_Abs f\"\n  shows \"{s. timpls_transformable_to_pred A (Fun f T) s} \\<subseteq>\n          (\\<lambda>S. Fun f S) ` {S. length T = length S \\<and>\n                              (\\<forall>s \\<in> set S. \\<exists>t \\<in> set T. timpls_transformable_to_pred A t s)}\"\n    (is \"?B \\<subseteq> ?C\")\nproof\n  fix s assume s: \"s \\<in> ?B\"\n  hence *: \"timpls_transformable_to_pred A (Fun f T) s\" by blast\n\n  obtain S where S:\n      \"s = Fun f S\" \"length T = length S\" \"\\<And>i. i < length T \\<Longrightarrow> timpls_transformable_to_pred A (T ! i) (S ! i)\"\n    using f timpls_transformable_to_pred_inv[OF *] unfolding the_Abs_def is_Abs_def by auto\n\n  have \"\\<forall>s\\<in>set S. \\<exists>t\\<in>set T. timpls_transformable_to_pred A t s\" using S(2,3) in_set_conv_nth by metis\n  thus \"s \\<in> ?C\" using S(1,2) by blast\nqed\n\nprivate lemma timpls_transformable_to_pred_finite_aux2:\n  \"{s. timpls_transformable_to_pred A (Fun (Abs a) []) s} \\<subseteq> (\\<lambda>b. Fun (Abs b) []) ` A\" (is \"?B \\<subseteq> ?C\")\nproof\n  fix s assume s: \"s \\<in> ?B\"\n  hence *: \"timpls_transformable_to_pred A (Fun (Abs a) []) s\" by blast\n\n  obtain b where b: \"s = Fun (Abs b) []\" \"b \\<in> A\"\n    using timpls_transformable_to_pred_inv[OF *] unfolding the_Abs_def is_Abs_def by auto\n  thus \"s \\<in> ?C\" by blast\nqed\n\nprivate lemma timpls_transformable_to_pred_finite:\n  fixes t::\"(('fun,'atom,'sets) prot_fun, 'a) term\"\n  assumes A: \"finite A\"\n    and t: \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\n  shows \"finite {s. timpls_transformable_to_pred A t s}\"\nusing t\nproof (induction t)\n  case (Var x)\n  have \"{s::(('fun,'atom,'sets) prot_fun, 'a) term. timpls_transformable_to_pred A (Var x) s} = {Var x}\"\n    by (auto intro: timpls_transformable_to_pred.Var elim: timpls_transformable_to_pred_inv_Var)\n  thus ?case by simp\nnext\n  case (Fun f T)\n  have IH: \"finite {s. timpls_transformable_to_pred A t s}\" when t: \"t \\<in> set T\" for t\n    using Fun.IH[OF t] wf_trm_param[OF Fun.prems t] by blast\n\n  show ?case\n  proof (cases \"is_Abs f\")\n    case True\n    then obtain a where a: \"f = Abs a\" unfolding is_Abs_def by presburger\n    hence \"T = []\" using wf_trm_arity[OF Fun.prems] by simp_all\n    hence \"{a. timpls_transformable_to_pred A (Fun f T) a} \\<subseteq> (\\<lambda>b. Fun (Abs b) []) ` A\"\n      using timpls_transformable_to_pred_finite_aux2[of A a] a by auto\n    thus ?thesis using A finite_subset by fast\n  next\n    case False thus ?thesis\n      using IH finite_lists_length_eq' timpls_transformable_to_pred_finite_aux1[of f A T] finite_subset\n      by blast\n  qed\nqed\n\nprivate lemma timpls_transformable_to_pred_if_timpls_transformable_to:\n  assumes s: \"timpls_transformable_to TI t s\"\n    and t: \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"\\<forall>f \\<in> funs_term t. is_Abs f \\<longrightarrow> the_Abs f \\<in> A\"\n  shows \"timpls_transformable_to_pred (A \\<union> fst ` (set TI)\\<^sup>+ \\<union> snd ` (set TI)\\<^sup>+) t s\"\nusing s t\nproof (induction rule: timpls_transformable_to.induct)\n  case (2 TI f T g S)\n  let ?A = \"A \\<union> fst ` (set TI)\\<^sup>+ \\<union> snd ` (set TI)\\<^sup>+\"\n\n  note prems = \"2.prems\"\n  note IH = \"2.IH\"\n\n  note 0 = timpls_transformable_to_inv[OF prems(1)]\n\n  have 1: \"T = []\" \"S = []\" when f: \"f = Abs a\" for a\n    using f wf_trm_arity[OF prems(2)] 0(1) by simp_all\n\n  have \"\\<forall>f \\<in> funs_term t. is_Abs f \\<longrightarrow> the_Abs f \\<in> A\" when t: \"t \\<in> set T\" for t\n    using t prems(3) funs_term_subterms_eq(1)[of \"Fun f T\"] by blast\n  hence 2: \"timpls_transformable_to_pred ?A (T ! i) (S ! i)\"\n    when i: \"i < length T\" for i\n    using i IH 0(1,2) wf_trm_param[OF prems(2)]\n    by (metis (no_types) in_set_conv_nth)\n\n  have 3: \"the_Abs f \\<in> ?A\" when f: \"is_Abs f\" using prems(3) f by force\n\n  show ?case\n  proof (cases \"f = g\")\n    case True\n    note fg = True\n    show ?thesis\n    proof (cases \"is_Abs f\")\n      case True\n      then obtain a where a: \"f = Abs a\" unfolding is_Abs_def by moura\n      thus ?thesis using fg 1[OF a] timpls_transformable_to_pred.Abs[of a ?A a] 3 by simp\n    qed (use fg timpls_transformable_to_pred.Fun[OF _ 0(1) 2, of f] in blast)\n  next\n    case False\n    then obtain a b where ab: \"f = Abs a\" \"g = Abs b\" \"(a, b) \\<in> (set TI)\\<^sup>+\"\n      using 0(3) in_trancl_closure_iff_in_trancl_fun[of _ _ TI]\n      unfolding is_Abs_def the_Abs_def by fastforce\n    hence \"a \\<in> ?A\" \"b \\<in> ?A\" by force+\n    thus ?thesis using timpls_transformable_to_pred.Abs ab(1,2) 1[OF ab(1)] by metis\n  qed\nqed (simp_all add: timpls_transformable_to_pred.Var)\n\nprivate lemma timpls_transformable_to_pred_if_timpls_transformable_to':\n  assumes s: \"timpls_transformable_to' TI t s\"\n    and t: \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"\\<forall>f \\<in> funs_term t. is_Abs f \\<longrightarrow> the_Abs f \\<in> A\"\n  shows \"timpls_transformable_to_pred (A \\<union> fst ` (set TI)\\<^sup>+ \\<union> snd ` (set TI)\\<^sup>+) t s\"\nusing s t\nproof (induction rule: timpls_transformable_to.induct)\n  case (2 TI f T g S)\n  let ?A = \"A \\<union> fst ` (set TI)\\<^sup>+ \\<union> snd ` (set TI)\\<^sup>+\"\n\n  note prems = \"2.prems\"\n  note IH = \"2.IH\"\n\n  note 0 = timpls_transformable_to'_inv[OF prems(1)]\n\n  have 1: \"T = []\" \"S = []\" when f: \"f = Abs a\" for a\n    using f wf_trm_arity[OF prems(2)] 0(1) by simp_all\n\n  have \"\\<forall>f \\<in> funs_term t. is_Abs f \\<longrightarrow> the_Abs f \\<in> A\" when t: \"t \\<in> set T\" for t\n    using t prems(3) funs_term_subterms_eq(1)[of \"Fun f T\"] by blast\n  hence 2: \"timpls_transformable_to_pred ?A (T ! i) (S ! i)\"\n    when i: \"i < length T\" for i\n    using i IH 0(1,2) wf_trm_param[OF prems(2)]\n    by (metis (no_types) in_set_conv_nth)\n\n  have 3: \"the_Abs f \\<in> ?A\" when f: \"is_Abs f\" using prems(3) f by force\n\n  show ?case\n  proof (cases \"f = g\")\n    case True\n    note fg = True\n    show ?thesis\n    proof (cases \"is_Abs f\")\n      case True\n      then obtain a where a: \"f = Abs a\" unfolding is_Abs_def by moura\n      thus ?thesis using fg 1[OF a] timpls_transformable_to_pred.Abs[of a ?A a] 3 by simp\n    qed (use fg timpls_transformable_to_pred.Fun[OF _ 0(1) 2, of f] in blast)\n  next\n    case False\n    then obtain a b where ab: \"f = Abs a\" \"g = Abs b\" \"(a, b) \\<in> (set TI)\\<^sup>+\"\n      using 0(3) in_trancl_closure_iff_in_trancl_fun[of _ _ TI]\n      unfolding is_Abs_def the_Abs_def by fastforce\n    hence \"a \\<in> ?A\" \"b \\<in> ?A\" by force+\n    thus ?thesis using timpls_transformable_to_pred.Abs ab(1,2) 1[OF ab(1)] by metis\n  qed\nqed (simp_all add: timpls_transformable_to_pred.Var)\n\nprivate lemma timpls_transformable_to_pred_if_equal_mod_timpls:\n  assumes s: \"equal_mod_timpls TI t s\"\n    and t: \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"\\<forall>f \\<in> funs_term t. is_Abs f \\<longrightarrow> the_Abs f \\<in> A\"\n  shows \"timpls_transformable_to_pred (A \\<union> fst ` (set TI)\\<^sup>+ \\<union> snd ` (set TI)\\<^sup>+) t s\"\nusing s t\nproof (induction rule: equal_mod_timpls.induct)\n  case (2 TI f T g S)\n  let ?A = \"A \\<union> fst ` (set TI)\\<^sup>+ \\<union> snd ` (set TI)\\<^sup>+\"\n\n  note prems = \"2.prems\"\n  note IH = \"2.IH\"\n\n  note 0 = equal_mod_timpls_inv[OF prems(1)]\n\n  have 1: \"T = []\" \"S = []\" when f: \"f = Abs a\" for a\n    using f wf_trm_arity[OF prems(2)] 0(1) by simp_all\n\n  have \"\\<forall>f \\<in> funs_term t. is_Abs f \\<longrightarrow> the_Abs f \\<in> A\" when t: \"t \\<in> set T\" for t\n    using t prems(3) funs_term_subterms_eq(1)[of \"Fun f T\"] by blast\n  hence 2: \"timpls_transformable_to_pred ?A (T ! i) (S ! i)\"\n    when i: \"i < length T\" for i\n    using i IH 0(1,2) wf_trm_param[OF prems(2)]\n    by (metis (no_types) in_set_conv_nth)\n\n  have 3: \"the_Abs f \\<in> ?A\" when f: \"is_Abs f\" using prems(3) f by force\n\n  show ?case\n  proof (cases \"f = g\")\n    case True\n    note fg = True\n    show ?thesis\n    proof (cases \"is_Abs f\")\n      case True\n      then obtain a where a: \"f = Abs a\" unfolding is_Abs_def by moura\n      thus ?thesis using fg 1[OF a] timpls_transformable_to_pred.Abs[of a ?A a] 3 by simp\n    qed (use fg timpls_transformable_to_pred.Fun[OF _ 0(1) 2, of f] in blast)\n  next\n    case False\n    then obtain a b where ab: \"f = Abs a\" \"g = Abs b\"\n        \"(a, b) \\<in> (set TI)\\<^sup>+ \\<or> (b, a) \\<in> (set TI)\\<^sup>+ \\<or>\n         (\\<exists>ti \\<in> set TI. (a, snd ti) \\<in> (set TI)\\<^sup>+ \\<and> (b, snd ti) \\<in> (set TI)\\<^sup>+)\"\n      using 0(3) in_trancl_closure_iff_in_trancl_fun[of _ _ TI]\n      unfolding is_Abs_def the_Abs_def by fastforce\n    hence \"a \\<in> ?A\" \"b \\<in> ?A\" by force+\n    thus ?thesis using timpls_transformable_to_pred.Abs ab(1,2) 1[OF ab(1)] by metis\n  qed\nqed (simp_all add: timpls_transformable_to_pred.Var)\n\nlemma timpls_transformable_to_finite:\n  assumes t: \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\n  shows \"finite {s. timpls_transformable_to TI t s}\" (is ?P)\n    and \"finite {s. timpls_transformable_to' TI t s}\" (is ?Q)\nproof -\n  let ?A = \"the_Abs ` {f \\<in> funs_term t. is_Abs f} \\<union> fst ` (set TI)\\<^sup>+ \\<union> snd ` (set TI)\\<^sup>+\"\n\n  have 0: \"finite ?A\" by auto\n\n  have 1: \"{s. timpls_transformable_to TI t s} \\<subseteq> {s. timpls_transformable_to_pred ?A t s}\"\n    using timpls_transformable_to_pred_if_timpls_transformable_to[OF _ t] by auto\n\n  have 2: \"{s. timpls_transformable_to' TI t s} \\<subseteq> {s. timpls_transformable_to_pred ?A t s}\"\n    using timpls_transformable_to_pred_if_timpls_transformable_to'[OF _ t] by auto\n\n  show ?P using timpls_transformable_to_pred_finite[OF 0 t] finite_subset[OF 1] by blast\n  show ?Q using timpls_transformable_to_pred_finite[OF 0 t] finite_subset[OF 2] by blast\nqed\n\nlemma equal_mod_timpls_finite:\n  assumes t: \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\n  shows \"finite {s. equal_mod_timpls TI t s}\"\nproof -\n  let ?A = \"the_Abs ` {f \\<in> funs_term t. is_Abs f} \\<union> fst ` (set TI)\\<^sup>+ \\<union> snd ` (set TI)\\<^sup>+\"\n\n  have 0: \"finite ?A\" by auto\n\n  have 1: \"{s. equal_mod_timpls TI t s} \\<subseteq> {s. timpls_transformable_to_pred ?A t s}\"\n    using timpls_transformable_to_pred_if_equal_mod_timpls[OF _ t] by auto\n\n  show ?thesis using timpls_transformable_to_pred_finite[OF 0 t] finite_subset[OF 1] by blast\nqed\n\nend\n\nlemma intruder_synth_mod_timpls_is_synth_timpl_closure_set:\n  fixes t::\"(('fun, 'atom, 'sets) prot_fun, 'a) term\" and TI TI'\n  assumes \"set TI' = {(a,b) \\<in> (set TI)\\<^sup>+. a \\<noteq> b}\"\n  shows \"intruder_synth_mod_timpls M TI' t \\<longleftrightarrow> timpl_closure_set (set M) (set TI) \\<turnstile>\\<^sub>c t\"\n      (is \"?C t \\<longleftrightarrow> ?D t\")\nproof -\n  have *: \"(\\<exists>m \\<in> M. timpls_transformable_to TI' m t) \\<longleftrightarrow> t \\<in> timpl_closure_set M (set TI)\"\n    when \"set TI' = {(a,b) \\<in> (set TI)\\<^sup>+. a \\<noteq> b}\"\n    for M TI TI' and t::\"(('fun, 'atom, 'sets) prot_fun, 'a) term\"\n    using timpls_transformable_to_iff_in_timpl_closure[OF that]\n          timpl_closure_set_is_timpl_closure_union[of M \"set TI\"]\n          timpl_closure_set_timpls_trancl_eq[of M \"set TI\"]\n          timpl_closure_set_timpls_trancl_eq'[of M \"set TI\"]\n    by auto\n\n  show \"?C t \\<longleftrightarrow> ?D t\"\n  proof\n    show \"?C t \\<Longrightarrow> ?D t\" using assms\n    proof (induction t arbitrary: M TI TI' rule: intruder_synth_mod_timpls.induct)\n      case (1 M TI' x)\n      hence \"Var x \\<in> timpl_closure_set (set M) (set TI)\"\n        using timpl_closure.FP member_def unfolding timpl_closure_set_def by force\n      thus ?case by simp\n    next\n      case (2 M TI f T)\n      show ?case\n      proof (cases \"\\<exists>m \\<in> set M. timpls_transformable_to TI' m (Fun f T)\")\n        case True thus ?thesis\n          using \"2.prems\" *[of TI' TI \"set M\" \"Fun f T\"]\n                intruder_synth.AxiomC[of \"Fun f T\" \"timpl_closure_set (set M) (set TI)\"]\n          by blast\n      next\n        case False\n        hence \"\\<not>(list_ex (\\<lambda>t. timpls_transformable_to TI' t (Fun f T)) M)\"\n          unfolding list_ex_iff by blast\n        hence \"public f\" \"length T = arity f\" \"list_all (intruder_synth_mod_timpls M TI') T\"\n          using \"2.prems\"(1) by force+\n        thus ?thesis using \"2.IH\"[OF _ _ \"2.prems\"(2)] unfolding list_all_iff by force\n      qed\n    qed\n  \n    show \"?D t \\<Longrightarrow> ?C t\"\n    proof (induction t rule: intruder_synth_induct)\n      case (AxiomC t) thus ?case\n        using timpl_closure_set_Var_in_iff[of _ \"set M\" \"set TI\"] *[OF assms, of \"set M\" t]\n        by (cases t rule: term.exhaust) (force simp add: member_def list_ex_iff)+\n    next\n      case (ComposeC T f) thus ?case\n        using list_all_iff[of \"intruder_synth_mod_timpls M TI'\" T]\n              intruder_synth_mod_timpls.simps(2)[of M TI' f T]\n        by blast\n    qed\n  qed\nqed\n\nlemma intruder_synth_mod_timpls'_is_synth_timpl_closure_set:\n  fixes t::\"(('fun, 'atom, 'sets) prot_fun, 'a) term\" and TI\n  shows \"intruder_synth_mod_timpls' M TI t \\<longleftrightarrow> timpl_closure_set (set M) (set TI) \\<turnstile>\\<^sub>c t\"\n      (is \"?A t \\<longleftrightarrow> ?B t\")\nproof -\n  have *: \"(\\<exists>m \\<in> M. timpls_transformable_to' TI m t) \\<longleftrightarrow> t \\<in> timpl_closure_set M (set TI)\"\n    for M TI and t::\"(('fun, 'atom, 'sets) prot_fun, 'a) term\"\n    using timpls_transformable_to'_iff_in_timpl_closure[of TI _ t]\n          timpl_closure_set_is_timpl_closure_union[of M \"set TI\"]\n    by blast+\n\n  show \"?A t \\<longleftrightarrow> ?B t\"\n  proof\n    show \"?A t \\<Longrightarrow> ?B t\"\n    proof (induction t arbitrary: M TI rule: intruder_synth_mod_timpls'.induct)\n      case (1 M TI x)\n      hence \"Var x \\<in> timpl_closure_set (set M) (set TI)\"\n        using timpl_closure.FP List.member_def[of M] unfolding timpl_closure_set_def by auto\n      thus ?case by simp\n    next\n      case (2 M TI f T)\n      show ?case\n      proof (cases \"\\<exists>m \\<in> set M. timpls_transformable_to' TI m (Fun f T)\")\n        case True thus ?thesis\n          using \"2.prems\" *[of \"set M\" TI \"Fun f T\"]\n                intruder_synth.AxiomC[of \"Fun f T\" \"timpl_closure_set (set M) (set TI)\"]\n          by blast\n      next\n        case False\n        hence \"public f\" \"length T = arity f\" \"list_all (intruder_synth_mod_timpls' M TI) T\"\n          using \"2.prems\" list_ex_iff[of _ M] by force+\n        thus ?thesis\n          using \"2.IH\"[of _ M TI] list_all_iff[of \"intruder_synth_mod_timpls' M TI\" T]\n          by force\n      qed\n    qed\n  \n    show \"?B t \\<Longrightarrow> ?A t\"\n    proof (induction t rule: intruder_synth_induct)\n      case (AxiomC t) thus ?case\n        using AxiomC timpl_closure_set_Var_in_iff[of _ \"set M\" \"set TI\"] *[of \"set M\" TI t]\n              list_ex_iff[of _ M] List.member_def[of M]\n        by (cases t rule: term.exhaust) force+\n    next\n      case (ComposeC T f) thus ?case\n        using list_all_iff[of \"intruder_synth_mod_timpls' M TI\" T]\n              intruder_synth_mod_timpls'.simps(2)[of M TI f T]\n        by blast\n    qed\n  qed\nqed\n\nlemma intruder_synth_mod_eq_timpls_is_synth_timpl_closure_set:\n  fixes t::\"(('fun, 'atom, 'sets) prot_fun, 'a) term\" and TI\n  defines \"cl \\<equiv> \\<lambda>TI. {(a,b) \\<in> TI\\<^sup>+. a \\<noteq> b}\"\n  shows (* \"set TI' = (set TI)\\<^sup>+ \\<Longrightarrow>\n         intruder_synth_mod_eq_timpls M TI' t \\<longleftrightarrow>\n         (\\<exists>s \\<in> timpl_closure t (set TI). timpl_closure_set M (set TI) \\<turnstile>\\<^sub>c s)\"\n      (is \"?P TI TI' \\<Longrightarrow> ?A t \\<longleftrightarrow> ?B t\")\n    and *) \"set TI' = {(a,b) \\<in> (set TI)\\<^sup>+. a \\<noteq> b} \\<Longrightarrow>\n         intruder_synth_mod_eq_timpls M TI' t \\<longleftrightarrow>\n         (\\<exists>s \\<in> timpl_closure t (set TI). timpl_closure_set M (set TI) \\<turnstile>\\<^sub>c s)\"\n      (is \"?Q TI TI' \\<Longrightarrow> ?C t \\<longleftrightarrow> ?D t\")\nproof -\n  (* have *: \"(\\<exists>m \\<in> M. equal_mod_timpls TI' m t) \\<longleftrightarrow>\n           (\\<exists>s \\<in> timpl_closure t (set TI). s \\<in> timpl_closure_set M (set TI))\"\n    when P: \"?P TI TI'\"\n    for M TI TI' and t::\"(('fun, 'atom, 'sets) prot_fun, 'a) term\"\n    using equal_mod_timpls_iff_ex_in_timpl_closure'[OF P]\n          timpl_closure_set_is_timpl_closure_union[of M \"set TI\"]\n          timpl_closure_set_timpls_trancl_eq[of M \"set TI\"]\n    by blast *)\n\n  have **: \"(\\<exists>m \\<in> M. equal_mod_timpls TI' m t) \\<longleftrightarrow>\n            (\\<exists>s \\<in> timpl_closure t (set TI). s \\<in> timpl_closure_set M (set TI))\"\n    when Q: \"?Q TI TI'\"\n    for M TI TI' and t::\"(('fun, 'atom, 'sets) prot_fun, 'a) term\"\n    using equal_mod_timpls_iff_ex_in_timpl_closure[OF Q]\n          timpl_closure_set_is_timpl_closure_union[of M \"set TI\"]\n          timpl_closure_set_timpls_trancl_eq'[of M \"set TI\"]\n    by fastforce\n\n(*   show \"?A t \\<longleftrightarrow> ?B t\" when P: \"?P TI TI'\"\n  proof\n    show \"?A t \\<Longrightarrow> ?B t\"\n    proof (induction t arbitrary: M TI rule: intruder_synth_mod_eq_timpls.induct)\n      case (1 M TI x)\n      hence \"Var x \\<in> timpl_closure_set M TI\" \"Var x \\<in> timpl_closure (Var x) TI\"\n        using timpl_closure.FP unfolding timpl_closure_set_def by auto\n      thus ?case by force\n    next\n      case (2 M TI f T)\n      show ?case\n      proof (cases \"\\<exists>m \\<in> M. equal_mod_timpls (TI\\<^sup>+) m (Fun f T)\")\n        case True thus ?thesis\n          using \"2.prems\" *[of M TI \"Fun f T\"] intruder_synth.AxiomC[of _ \"timpl_closure_set M TI\"]\n          by blast\n      next\n        case False\n        hence f: \"public f\" \"length T = arity f\" \"list_all (intruder_synth_mod_eq_timpls M (TI\\<^sup>+)) T\"\n          using \"2.prems\" by force+\n  \n        let ?sy = \"intruder_synth (timpl_closure_set M TI)\"\n\n        have IH: \"\\<exists>u \\<in> timpl_closure (T ! i) TI. ?sy u\"\n          when i: \"i < length T\" for i\n          using \"2.IH\"[of _ M TI] f(3) nth_mem[OF i]\n          unfolding list_all_iff by blast\n  \n        define S where \"S \\<equiv> map (\\<lambda>u. SOME v. v \\<in> timpl_closure u TI \\<and> ?sy v) T\"\n  \n        have S1: \"length T = length S\"\n          unfolding S_def by simp\n  \n        have S2: \"S ! i \\<in> timpl_closure (T ! i) TI\"\n                 \"timpl_closure_set M TI \\<turnstile>\\<^sub>c S ! i\"\n          when i: \"i < length S\" for i\n          using i IH someI_ex[of \"\\<lambda>v. v \\<in> timpl_closure (T ! i) TI \\<and> ?sy v\"]\n          unfolding S_def by auto\n  \n        have \"Fun f S \\<in> timpl_closure (Fun f T) TI\"\n          using timpl_closure_FunI[of T S TI f f] S1 S2(1)\n          unfolding timpl_closure_is_timpl_closure' by presburger\n        thus ?thesis\n          by (metis intruder_synth.ComposeC[of S f] f(1,2) S1 S2(2) in_set_conv_nth[of _ S])\n      qed\n    qed\n  \n    show \"?A t\" when B: \"?B t\"\n    proof -\n      obtain s where \"timpl_closure_set M TI \\<turnstile>\\<^sub>c s\" \"s \\<in> timpl_closure t TI\"\n        using B by moura\n      thus ?thesis\n      proof (induction s arbitrary: t rule: intruder_synth_induct)\n        case (AxiomC s t)\n        note 1 = timpl_closure_set_Var_in_iff[of _ M TI] timpl_closure_Var_inv[of s _ TI]\n        note 2 = *[of M TI]\n        show ?case\n        proof (cases t)\n          case Var thus ?thesis using 1 AxiomC by auto\n        next\n          case Fun thus ?thesis using 2 AxiomC by auto\n        qed\n      next\n        case (ComposeC T f t)\n        obtain g S where gS:\n            \"t = Fun g S\" \"length S = length T\"\n            \"\\<forall>i < length T. T ! i \\<in> timpl_closure (S ! i) TI\"\n            \"g \\<noteq> f \\<Longrightarrow> is_Abs g \\<and> is_Abs f \\<and> (the_Abs g, the_Abs f) \\<in> TI\\<^sup>+\"\n          using ComposeC.prems(1) timpl_closure'_inv'[of t \"Fun f T\" TI]\n                timpl_closure_is_timpl_closure'[of _ _ TI]\n          by fastforce\n  \n        have IH: \"intruder_synth_mod_eq_timpls M (TI\\<^sup>+) u\" when u: \"u \\<in> set S\" for u\n          by (metis u gS(2,3) ComposeC.IH in_set_conv_nth)\n  \n        note 0 = list_all_iff[of \"intruder_synth_mod_eq_timpls M (TI\\<^sup>+)\" S]\n                 intruder_synth_mod_eq_timpls.simps(2)[of M \"TI\\<^sup>+\" g S]\n  \n        have \"f = g\" using ComposeC.hyps gS(4) unfolding is_Abs_def by fastforce\n        thus ?case by (metis ComposeC.hyps(1,2) gS(1,2) IH 0)\n      qed\n    qed\n  qed *)\n\n  show \"?C t \\<longleftrightarrow> ?D t\" when Q: \"?Q TI TI'\"\n  proof\n    show \"?C t \\<Longrightarrow> ?D t\" using Q\n    proof (induction t arbitrary: M TI rule: intruder_synth_mod_eq_timpls.induct)\n      case (1 M TI' x M TI)\n      hence \"Var x \\<in> timpl_closure_set M (set TI)\" \"Var x \\<in> timpl_closure (Var x) (set TI)\"\n        using timpl_closure.FP unfolding timpl_closure_set_def by auto\n      thus ?case by force\n    next\n      case (2 M TI' f T M TI)\n      show ?case\n      proof (cases \"\\<exists>m \\<in> M. equal_mod_timpls TI' m (Fun f T)\")\n        case True thus ?thesis\n          using **[OF \"2.prems\"(2), of M \"Fun f T\"]\n                intruder_synth.AxiomC[of _ \"timpl_closure_set M (set TI)\"]\n          by blast\n      next\n        case False\n        hence f: \"public f\" \"length T = arity f\" \"list_all (intruder_synth_mod_eq_timpls M TI') T\"\n          using \"2.prems\" by force+\n  \n        let ?sy = \"intruder_synth (timpl_closure_set M (set TI))\"\n\n        have IH: \"\\<exists>u \\<in> timpl_closure (T ! i) (set TI). ?sy u\"\n          when i: \"i < length T\" for i\n          using \"2.IH\"[of _ M TI] f(3) nth_mem[OF i] \"2.prems\"(2)\n          unfolding list_all_iff by blast\n  \n        define S where \"S \\<equiv> map (\\<lambda>u. SOME v. v \\<in> timpl_closure u (set TI) \\<and> ?sy v) T\"\n  \n        have S1: \"length T = length S\"\n          unfolding S_def by simp\n  \n        have S2: \"S ! i \\<in> timpl_closure (T ! i) (set TI)\"\n                  \"timpl_closure_set M (set TI) \\<turnstile>\\<^sub>c S ! i\"\n          when i: \"i < length S\" for i\n          using i IH someI_ex[of \"\\<lambda>v. v \\<in> timpl_closure (T ! i) (set TI) \\<and> ?sy v\"]\n          unfolding S_def by auto\n  \n        have \"Fun f S \\<in> timpl_closure (Fun f T) (set TI)\"\n          using timpl_closure_FunI[of T S \"set TI\" f f] S1 S2(1)\n          unfolding timpl_closure_is_timpl_closure' by presburger\n        thus ?thesis\n          by (metis intruder_synth.ComposeC[of S f] f(1,2) S1 S2(2) in_set_conv_nth[of _ S])\n      qed\n    qed\n  \n    show \"?C t\" when D: \"?D t\"\n    proof -\n      obtain s where \"timpl_closure_set M (set TI) \\<turnstile>\\<^sub>c s\" \"s \\<in> timpl_closure t (set TI)\"\n        using D by moura\n      thus ?thesis\n      proof (induction s arbitrary: t rule: intruder_synth_induct)\n        case (AxiomC s t)\n        note 1 = timpl_closure_set_Var_in_iff[of _ M \"set TI\"] timpl_closure_Var_inv[of s _ \"set TI\"]\n        note 2 = **[OF Q, of M]\n        show ?case\n        proof (cases t)\n          case Var thus ?thesis using 1 AxiomC by auto\n        next\n          case Fun thus ?thesis using 2 AxiomC by auto\n        qed\n      next\n        case (ComposeC T f t)\n        obtain g S where gS:\n            \"t = Fun g S\" \"length S = length T\"\n            \"\\<forall>i < length T. T ! i \\<in> timpl_closure (S ! i) (set TI)\"\n            \"g \\<noteq> f \\<Longrightarrow> is_Abs g \\<and> is_Abs f \\<and> (the_Abs g, the_Abs f) \\<in> (set TI)\\<^sup>+\"\n          using ComposeC.prems(1) timpl_closure'_inv'[of t \"Fun f T\" \"set TI\"]\n                timpl_closure_is_timpl_closure'[of _ _ \"set TI\"]\n          by fastforce\n  \n        have IH: \"intruder_synth_mod_eq_timpls M TI' u\" when u: \"u \\<in> set S\" for u\n          by (metis u gS(2,3) ComposeC.IH in_set_conv_nth)\n  \n        note 0 = list_all_iff[of \"intruder_synth_mod_eq_timpls M TI'\" S]\n                 intruder_synth_mod_eq_timpls.simps(2)[of M TI' g S]\n  \n        have \"f = g\" using ComposeC.hyps gS(4) unfolding is_Abs_def by fastforce\n        thus ?case by (metis ComposeC.hyps(1,2) gS(1,2) IH 0)\n      qed\n    qed\n  qed\nqed\n\nlemma timpl_closure_finite:\n  assumes t: \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\n  shows \"finite (timpl_closure t (set TI))\"\nusing timpls_transformable_to'_iff_in_timpl_closure[of TI t]\n      timpls_transformable_to_finite[OF t, of TI]\nby auto\n\nlemma timpl_closure_set_finite:\n  fixes TI::\"('sets set \\<times> 'sets set) list\"\n  assumes M_finite: \"finite M\"\n    and M_wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s M\"\n  shows \"finite (timpl_closure_set M (set TI))\"\nusing timpl_closure_set_is_timpl_closure_union[of M \"set TI\"]\n      timpl_closure_finite[of _ TI] M_finite M_wf finite\nby auto\n\nlemma comp_timpl_closure_is_timpl_closure_set:\n  fixes M and TI::\"('sets set \\<times> 'sets set) list\"\n  assumes M_finite: \"finite M\"\n    and M_wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s M\"\n  shows \"comp_timpl_closure M (set TI) = timpl_closure_set M (set TI)\"\nusing lfp_while''[OF timpls_Un_mono[of M \"set TI\"]]\n      timpl_closure_set_finite[OF M_finite M_wf]\n      timpl_closure_set_lfp[of M \"set TI\"]\nunfolding comp_timpl_closure_def Let_def by presburger\n\ncontext\nbegin\n\nprivate lemma analyzed_closed_mod_timpls_is_analyzed_closed_timpl_closure_set_aux1:\n  fixes M::\"('fun,'atom,'sets) prot_terms\"\n  assumes f: \"arity\\<^sub>f f = length T\" \"arity\\<^sub>f f > 0\" \"Ana\\<^sub>f f = (K, R)\"\n    and i: \"i < length R\"\n    and M: \"timpl_closure_set M TI \\<turnstile>\\<^sub>c T ! (R ! i)\"\n    and m: \"Fun (Fu f) T \\<in> M\"\n    and t: \"Fun (Fu f) S \\<in> timpl_closure (Fun (Fu f) T) TI\"\n  shows \"timpl_closure_set M TI \\<turnstile>\\<^sub>c S ! (R ! i)\"\nproof -\n  have \"R ! i < length T\" using i Ana\\<^sub>f_assm2_alt[OF f(3)] f(1) by simp\n  thus ?thesis\n    using timpl_closure_Fun_inv'(1,2)[OF t] intruder_synth_timpl_closure'[OF M]\n    by presburger\nqed\n\nprivate lemma analyzed_closed_mod_timpls_is_analyzed_closed_timpl_closure_set_aux2:\n  fixes M::\"('fun,'atom,'sets) prot_terms\"\n  assumes M: \"\\<forall>s \\<in> set (snd (Ana m)). timpl_closure_set M TI \\<turnstile>\\<^sub>c s\"\n    and m: \"m \\<in> M\"\n    and t: \"t \\<in> timpl_closure m TI\"\n    and s: \"s \\<in> set (snd (Ana t))\"\n  shows \"timpl_closure_set M TI \\<turnstile>\\<^sub>c s\"\nproof -\n  obtain f S K N where fS: \"t = Fun (Fu f) S\" \"arity\\<^sub>f f = length S\" \"0 < arity\\<^sub>f f\"\n      and Ana_f: \"Ana\\<^sub>f f = (K, N)\"\n      and Ana_t: \"Ana t = (K \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t (!) S, map ((!) S) N)\"\n    using Ana_nonempty_inv[of t] s by fastforce\n  then obtain T where T: \"m = Fun (Fu f) T\" \"length T = length S\"\n    using t timpl_closure_Fu_inv'[of f S m TI]\n    by moura\n  hence Ana_m: \"Ana m = (K \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t (!) T, map ((!) T) N)\"\n    using fS(2,3) Ana_f by auto\n\n  obtain i where i: \"i < length N\" \"s = S ! (N ! i)\"\n    using s[unfolded fS(1)] Ana_t[unfolded fS(1)] T(2)\n          in_set_conv_nth[of s \"map (\\<lambda>i. S ! i) N\"]\n    by auto\n  hence \"timpl_closure_set M TI \\<turnstile>\\<^sub>c T ! (N ! i)\"\n    using M[unfolded T(1)] Ana_m[unfolded T(1)] T(2)\n    by simp\n  thus ?thesis\n    using analyzed_closed_mod_timpls_is_analyzed_closed_timpl_closure_set_aux1[\n            OF fS(2)[unfolded T(2)[symmetric]] fS(3) Ana_f\n               i(1) _ m[unfolded T(1)] t[unfolded fS(1) T(1)]]\n          i(2)\n    by argo\nqed\n\nlemma analyzed_closed_mod_timpls_is_analyzed_timpl_closure_set:\n  fixes M::\"('fun,'atom,'sets) prot_term list\"\n  assumes TI': \"set TI' = {(a,b) \\<in> (set TI)\\<^sup>+. a \\<noteq> b}\"\n    and M_wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (set M)\"\n  shows \"analyzed_closed_mod_timpls M TI' \\<longleftrightarrow> analyzed (timpl_closure_set (set M) (set TI))\"\n    (is \"?A \\<longleftrightarrow> ?B\")\nproof\n  let ?C = \"\\<forall>t \\<in> timpl_closure_set (set M) (set TI).\n              analyzed_in t (timpl_closure_set (set M) (set TI))\"\n\n  let ?P = \"\\<lambda>T. \\<forall>t \\<in> set T. timpl_closure_set (set M) (set TI) \\<turnstile>\\<^sub>c t\"\n  let ?Q = \"\\<lambda>t. \\<forall>s \\<in> comp_timpl_closure {t} (set TI'). case Ana s of (K, R) \\<Rightarrow> ?P K \\<longrightarrow> ?P R\"\n  \n  note defs = analyzed_closed_mod_timpls_def analyzed_in_code\n  note 0 = intruder_synth_mod_timpls_is_synth_timpl_closure_set[OF TI', of M]\n  note 1 = timpl_closure_set_is_timpl_closure_union[of _ \"set TI\"]\n\n  have 2: \"comp_timpl_closure {t} (set TI') = timpl_closure_set {t} (set TI)\"\n    when t: \"t \\<in> set M\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" for t\n    using t timpl_closure_set_timpls_trancl_eq'[of \"{t}\" \"set TI\"]\n          comp_timpl_closure_is_timpl_closure_set[of \"{t}\" TI']\n    unfolding TI'[symmetric]\n    by blast\n  hence 3: \"comp_timpl_closure {t} (set TI') \\<subseteq> timpl_closure_set (set M) (set TI)\"\n    when t: \"t \\<in> set M\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" for t\n    using t timpl_closure_set_mono[of \"{t}\" \"set M\"]\n    by fast\n\n  have ?A when C: ?C\n    unfolding analyzed_closed_mod_timpls_def\n              intruder_synth_mod_timpls_is_synth_timpl_closure_set[OF TI']\n              list_all_iff Let_def\n  proof (intro ballI)\n    fix t assume t: \"t \\<in> set M\"\n    show \"if ?P (fst (Ana t)) then ?P (snd (Ana t)) else ?Q t\" (is ?R)\n    proof (cases \"?P (fst (Ana t))\")\n      case True\n      hence \"?P (snd (Ana t))\"\n        using C timpl_closure_setI[OF t, of \"set TI\"] prod.exhaust_sel\n        unfolding analyzed_in_def by blast\n      thus ?thesis using True by simp\n    next\n      case False\n      have \"?Q t\" using 3[OF t] C M_wf t unfolding analyzed_in_def by auto\n      thus ?thesis using False by argo\n    qed\n  qed\n  thus ?A when B: ?B using B analyzed_is_all_analyzed_in by metis\n\n  have ?C when A: ?A unfolding analyzed_in_def Let_def\n  proof (intro ballI allI impI; elim conjE)\n    fix t K T s\n    assume t: \"t \\<in> timpl_closure_set (set M) (set TI)\"\n      and s: \"s \\<in> set T\"\n      and Ana_t: \"Ana t = (K, T)\"\n      and K: \"\\<forall>k \\<in> set K. timpl_closure_set (set M) (set TI) \\<turnstile>\\<^sub>c k\"\n\n    obtain m where m: \"m \\<in> set M\" \"t \\<in> timpl_closure m (set TI)\"\n      using timpl_closure_set_is_timpl_closure_union t by moura\n\n    show \"timpl_closure_set (set M) (set TI) \\<turnstile>\\<^sub>c s\"\n    proof (cases \"\\<forall>k \\<in> set (fst (Ana m)). timpl_closure_set (set M) (set TI) \\<turnstile>\\<^sub>c k\")\n      case True\n      hence *: \"\\<forall>r \\<in> set (snd (Ana m)). timpl_closure_set (set M) (set TI) \\<turnstile>\\<^sub>c r\"\n        using m(1) A\n        unfolding analyzed_closed_mod_timpls_def\n                  intruder_synth_mod_timpls_is_synth_timpl_closure_set[OF TI']\n                  list_all_iff\n        by simp\n\n      show ?thesis\n        using K s Ana_t A\n              analyzed_closed_mod_timpls_is_analyzed_closed_timpl_closure_set_aux2[OF * m]\n        by simp\n    next\n      case False\n      hence \"?Q m\"\n        using m(1) A\n        unfolding analyzed_closed_mod_timpls_def\n                  intruder_synth_mod_timpls_is_synth_timpl_closure_set[OF TI']\n                  list_all_iff Let_def\n        by auto \n      moreover have \"comp_timpl_closure {m} (set TI') = timpl_closure m (set TI)\"\n        using 2[OF m(1)] timpl_closureton_is_timpl_closure M_wf m(1)\n        by blast\n      ultimately show ?thesis\n        using m(2) K s Ana_t\n        unfolding Let_def by auto\n    qed\n  qed\n  thus ?B when A: ?A using A analyzed_is_all_analyzed_in by metis\nqed\n\nlemma analyzed_closed_mod_timpls'_is_analyzed_timpl_closure_set:\n  fixes M::\"('fun,'atom,'sets) prot_term list\"\n  assumes M_wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (set M)\"\n  shows \"analyzed_closed_mod_timpls' M TI \\<longleftrightarrow> analyzed (timpl_closure_set (set M) (set TI))\"\n    (is \"?A \\<longleftrightarrow> ?B\")\nproof\n  let ?C = \"\\<forall>t \\<in> timpl_closure_set (set M) (set TI). analyzed_in t (timpl_closure_set (set M) (set TI))\"\n\n  let ?P = \"\\<lambda>T. \\<forall>t \\<in> set T. timpl_closure_set (set M) (set TI) \\<turnstile>\\<^sub>c t\"\n  let ?Q = \"\\<lambda>t. \\<forall>s \\<in> comp_timpl_closure {t} (set TI). case Ana s of (K, R) \\<Rightarrow> ?P K \\<longrightarrow> ?P R\"\n  \n  note defs = analyzed_closed_mod_timpls'_def analyzed_in_code\n  note 0 = intruder_synth_mod_timpls'_is_synth_timpl_closure_set[of M TI]\n  note 1 = timpl_closure_set_is_timpl_closure_union[of _ \"set TI\"]\n\n  have 2: \"comp_timpl_closure {t} (set TI) = timpl_closure_set {t} (set TI)\"\n    when t: \"t \\<in> set M\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" for t\n    using t timpl_closure_set_timpls_trancl_eq[of \"{t}\" \"set TI\"]\n          comp_timpl_closure_is_timpl_closure_set[of \"{t}\"]\n    by blast\n  hence 3: \"comp_timpl_closure {t} (set TI) \\<subseteq> timpl_closure_set (set M) (set TI)\"\n    when t: \"t \\<in> set M\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" for t\n    using t timpl_closure_set_mono[of \"{t}\" \"set M\"]\n    by fast\n\n  have ?A when C: ?C\n    unfolding analyzed_closed_mod_timpls'_def\n              intruder_synth_mod_timpls'_is_synth_timpl_closure_set\n              list_all_iff Let_def\n  proof (intro ballI)\n    fix t assume t: \"t \\<in> set M\"\n    show \"if ?P (fst (Ana t)) then ?P (snd (Ana t)) else ?Q t\" (is ?R)\n    proof (cases \"?P (fst (Ana t))\")\n      case True\n      hence \"?P (snd (Ana t))\"\n        using C timpl_closure_setI[OF t, of \"set TI\"] prod.exhaust_sel\n        unfolding analyzed_in_def by blast\n      thus ?thesis using True by simp\n    next\n      case False\n      have \"?Q t\" using 3[OF t] C M_wf t unfolding analyzed_in_def by auto\n      thus ?thesis using False by argo\n    qed\n  qed\n  thus ?A when B: ?B using B analyzed_is_all_analyzed_in by metis\n\n  have ?C when A: ?A unfolding analyzed_in_def Let_def\n  proof (intro ballI allI impI; elim conjE)\n    fix t K T s\n    assume t: \"t \\<in> timpl_closure_set (set M) (set TI)\"\n      and s: \"s \\<in> set T\"\n      and Ana_t: \"Ana t = (K, T)\"\n      and K: \"\\<forall>k \\<in> set K. timpl_closure_set (set M) (set TI) \\<turnstile>\\<^sub>c k\"\n\n    obtain m where m: \"m \\<in> set M\" \"t \\<in> timpl_closure m (set TI)\"\n      using timpl_closure_set_is_timpl_closure_union t by moura\n\n    show \"timpl_closure_set (set M) (set TI) \\<turnstile>\\<^sub>c s\"\n    proof (cases \"\\<forall>k \\<in> set (fst (Ana m)). timpl_closure_set (set M) (set TI) \\<turnstile>\\<^sub>c k\")\n      case True\n      hence *: \"\\<forall>r \\<in> set (snd (Ana m)). timpl_closure_set (set M) (set TI) \\<turnstile>\\<^sub>c r\"\n        using m(1) A\n        unfolding analyzed_closed_mod_timpls'_def\n                  intruder_synth_mod_timpls'_is_synth_timpl_closure_set\n                  list_all_iff\n        by simp\n\n      show ?thesis\n        using K s Ana_t A\n              analyzed_closed_mod_timpls_is_analyzed_closed_timpl_closure_set_aux2[OF * m]\n        by simp\n    next\n      case False\n      hence \"?Q m\"\n        using m(1) A\n        unfolding analyzed_closed_mod_timpls'_def\n                  intruder_synth_mod_timpls'_is_synth_timpl_closure_set\n                  list_all_iff Let_def\n        by auto \n      moreover have \"comp_timpl_closure {m} (set TI) = timpl_closure m (set TI)\"\n        using 2[OF m(1)] timpl_closureton_is_timpl_closure M_wf m(1)\n        by blast\n      ultimately show ?thesis\n        using m(2) K s Ana_t\n        unfolding Let_def by auto\n    qed\n  qed\n  thus ?B when A: ?A using A analyzed_is_all_analyzed_in by metis\nqed\n\nend\n\nend\n\nend\n", "meta": {"author": "logicalhacking", "repo": "Automated_Stateful_Protocol_Verification", "sha": "e24b8241b56d24240e1227caff737d4af82e12ec", "save_path": "github-repos/isabelle/logicalhacking-Automated_Stateful_Protocol_Verification", "path": "github-repos/isabelle/logicalhacking-Automated_Stateful_Protocol_Verification/Automated_Stateful_Protocol_Verification-e24b8241b56d24240e1227caff737d4af82e12ec/Automated_Stateful_Protocol_Verification/Term_Implication.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5039061705290806, "lm_q2_score": 0.5813030906443133, "lm_q1q2_score": 0.2929222143232949}}
{"text": "(*  Title:      HOL/Imperative_HOL/Ref.thy\n    Author:     John Matthews, Galois Connections; Alexander Krauss, Lukas Bulwahn & Florian Haftmann, TU Muenchen\n*)\n\nsection \\<open>Monadic references\\<close>\n\ntheory Ref\nimports Array\nbegin\n\ntext \\<open>\n  Imperative reference operations; modeled after their ML counterparts.\n  See \\<^url>\\<open>http://caml.inria.fr/pub/docs/manual-caml-light/node14.15.html\\<close>\n  and \\<^url>\\<open>http://www.smlnj.org/doc/Conversion/top-level-comparison.html\\<close>.\n\\<close>\n\nsubsection \\<open>Primitives\\<close>\n\ndefinition present :: \"heap \\<Rightarrow> 'a::heap ref \\<Rightarrow> bool\" where\n  \"present h r \\<longleftrightarrow> addr_of_ref r < lim h\"\n\ndefinition get :: \"heap \\<Rightarrow> 'a::heap ref \\<Rightarrow> 'a\" where\n  \"get h = from_nat \\<circ> refs h TYPEREP('a) \\<circ> addr_of_ref\"\n\ndefinition set :: \"'a::heap ref \\<Rightarrow> 'a \\<Rightarrow> heap \\<Rightarrow> heap\" where\n  \"set r x = refs_update\n    (\\<lambda>h. h(TYPEREP('a) := ((h (TYPEREP('a))) (addr_of_ref r := to_nat x))))\"\n\ndefinition alloc :: \"'a \\<Rightarrow> heap \\<Rightarrow> 'a::heap ref \\<times> heap\" where\n  \"alloc x h = (let\n     l = lim h;\n     r = Ref l\n   in (r, set r x (h\\<lparr>lim := l + 1\\<rparr>)))\"\n\ndefinition noteq :: \"'a::heap ref \\<Rightarrow> 'b::heap ref \\<Rightarrow> bool\" (infix \"=!=\" 70) where\n  \"r =!= s \\<longleftrightarrow> TYPEREP('a) \\<noteq> TYPEREP('b) \\<or> addr_of_ref r \\<noteq> addr_of_ref s\"\n\n\nsubsection \\<open>Monad operations\\<close>\n\ndefinition ref :: \"'a::heap \\<Rightarrow> 'a ref Heap\" where\n  [code del]: \"ref v = Heap_Monad.heap (alloc v)\"\n\ndefinition lookup :: \"'a::heap ref \\<Rightarrow> 'a Heap\" (\"!_\" 61) where\n  [code del]: \"lookup r = Heap_Monad.tap (\\<lambda>h. get h r)\"\n\ndefinition update :: \"'a ref \\<Rightarrow> 'a::heap \\<Rightarrow> unit Heap\" (\"_ := _\" 62) where\n  [code del]: \"update r v = Heap_Monad.heap (\\<lambda>h. ((), set r v h))\"\n\ndefinition change :: \"('a::heap \\<Rightarrow> 'a) \\<Rightarrow> 'a ref \\<Rightarrow> 'a Heap\" where\n  \"change f r = do {\n     x \\<leftarrow> ! r;\n     let y = f x;\n     r := y;\n     return y\n   }\"\n\n\nsubsection \\<open>Properties\\<close>\n\ntext \\<open>Primitives\\<close>\n\nlemma noteq_sym: \"r =!= s \\<Longrightarrow> s =!= r\"\n  and unequal [simp]: \"r \\<noteq> r' \\<longleftrightarrow> r =!= r'\" \\<comment> \"same types!\"\n  by (auto simp add: noteq_def)\n\nlemma noteq_irrefl: \"r =!= r \\<Longrightarrow> False\"\n  by (auto simp add: noteq_def)\n\nlemma present_alloc_neq: \"present h r \\<Longrightarrow> r =!= fst (alloc v h)\"\n  by (simp add: present_def alloc_def noteq_def Let_def)\n\nlemma next_fresh [simp]:\n  assumes \"(r, h') = alloc x h\"\n  shows \"\\<not> present h r\"\n  using assms by (cases h) (auto simp add: alloc_def present_def Let_def)\n\nlemma next_present [simp]:\n  assumes \"(r, h') = alloc x h\"\n  shows \"present h' r\"\n  using assms by (cases h) (auto simp add: alloc_def set_def present_def Let_def)\n\nlemma get_set_eq [simp]:\n  \"get (set r x h) r = x\"\n  by (simp add: get_def set_def)\n\nlemma get_set_neq [simp]:\n  \"r =!= s \\<Longrightarrow> get (set s x h) r = get h r\"\n  by (simp add: noteq_def get_def set_def)\n\nlemma set_same [simp]:\n  \"set r x (set r y h) = set r x h\"\n  by (simp add: set_def)\n\nlemma not_present_alloc [simp]:\n  \"\\<not> present h (fst (alloc v h))\"\n  by (simp add: present_def alloc_def Let_def)\n\nlemma set_set_swap:\n  \"r =!= r' \\<Longrightarrow> set r x (set r' x' h) = set r' x' (set r x h)\"\n  by (simp add: noteq_def set_def fun_eq_iff)\n\nlemma alloc_set:\n  \"fst (alloc x (set r x' h)) = fst (alloc x h)\"\n  by (simp add: alloc_def set_def Let_def)\n\nlemma get_alloc [simp]:\n  \"get (snd (alloc x h)) (fst (alloc x' h)) = x\"\n  by (simp add: alloc_def Let_def)\n\nlemma set_alloc [simp]:\n  \"set (fst (alloc v h)) v' (snd (alloc v h)) = snd (alloc v' h)\"\n  by (simp add: alloc_def Let_def)\n\nlemma get_alloc_neq: \"r =!= fst (alloc v h) \\<Longrightarrow> \n  get (snd (alloc v h)) r  = get h r\"\n  by (simp add: get_def set_def alloc_def Let_def noteq_def)\n\nlemma lim_set [simp]:\n  \"lim (set r v h) = lim h\"\n  by (simp add: set_def)\n\nlemma present_alloc [simp]: \n  \"present h r \\<Longrightarrow> present (snd (alloc v h)) r\"\n  by (simp add: present_def alloc_def Let_def)\n\nlemma present_set [simp]:\n  \"present (set r v h) = present h\"\n  by (simp add: present_def fun_eq_iff)\n\nlemma noteq_I:\n  \"present h r \\<Longrightarrow> \\<not> present h r' \\<Longrightarrow> r =!= r'\"\n  by (auto simp add: noteq_def present_def)\n\n\ntext \\<open>Monad operations\\<close>\n\nlemma execute_ref [execute_simps]:\n  \"execute (ref v) h = Some (alloc v h)\"\n  by (simp add: ref_def execute_simps)\n\nlemma success_refI [success_intros]:\n  \"success (ref v) h\"\n  by (auto intro: success_intros simp add: ref_def)\n\nlemma effect_refI [effect_intros]:\n  assumes \"(r, h') = alloc v h\"\n  shows \"effect (ref v) h h' r\"\n  by (rule effectI) (insert assms, simp add: execute_simps)\n\nlemma effect_refE [effect_elims]:\n  assumes \"effect (ref v) h h' r\"\n  obtains \"get h' r = v\" and \"present h' r\" and \"\\<not> present h r\"\n  using assms by (rule effectE) (simp add: execute_simps)\n\nlemma execute_lookup [execute_simps]:\n  \"Heap_Monad.execute (lookup r) h = Some (get h r, h)\"\n  by (simp add: lookup_def execute_simps)\n\nlemma success_lookupI [success_intros]:\n  \"success (lookup r) h\"\n  by (auto intro: success_intros  simp add: lookup_def)\n\nlemma effect_lookupI [effect_intros]:\n  assumes \"h' = h\" \"x = get h r\"\n  shows \"effect (!r) h h' x\"\n  by (rule effectI) (insert assms, simp add: execute_simps)\n\nlemma effect_lookupE [effect_elims]:\n  assumes \"effect (!r) h h' x\"\n  obtains \"h' = h\" \"x = get h r\"\n  using assms by (rule effectE) (simp add: execute_simps)\n\nlemma execute_update [execute_simps]:\n  \"Heap_Monad.execute (update r v) h = Some ((), set r v h)\"\n  by (simp add: update_def execute_simps)\n\nlemma success_updateI [success_intros]:\n  \"success (update r v) h\"\n  by (auto intro: success_intros  simp add: update_def)\n\nlemma effect_updateI [effect_intros]:\n  assumes \"h' = set r v h\"\n  shows \"effect (r := v) h h' x\"\n  by (rule effectI) (insert assms, simp add: execute_simps)\n\nlemma effect_updateE [effect_elims]:\n  assumes \"effect (r' := v) h h' r\"\n  obtains \"h' = set r' v h\"\n  using assms by (rule effectE) (simp add: execute_simps)\n\nlemma execute_change [execute_simps]:\n  \"Heap_Monad.execute (change f r) h = Some (f (get h r), set r (f (get h r)) h)\"\n  by (simp add: change_def bind_def Let_def execute_simps)\n\nlemma success_changeI [success_intros]:\n  \"success (change f r) h\"\n  by (auto intro!: success_intros effect_intros simp add: change_def)\n\nlemma effect_changeI [effect_intros]: \n  assumes \"h' = set r (f (get h r)) h\" \"x = f (get h r)\"\n  shows \"effect (change f r) h h' x\"\n  by (rule effectI) (insert assms, simp add: execute_simps)  \n\nlemma effect_changeE [effect_elims]:\n  assumes \"effect (change f r') h h' r\"\n  obtains \"h' = set r' (f (get h r')) h\" \"r = f (get h r')\"\n  using assms by (rule effectE) (simp add: execute_simps)\n\nlemma lookup_chain:\n  \"(!r \\<then> f) = f\"\n  by (rule Heap_eqI) (auto simp add: lookup_def execute_simps intro: execute_bind)\n\nlemma update_change [code]:\n  \"r := e = change (\\<lambda>_. e) r \\<then> return ()\"\n  by (rule Heap_eqI) (simp add: change_def lookup_chain)\n\n\ntext \\<open>Non-interaction between imperative arrays and imperative references\\<close>\n\nlemma array_get_set [simp]:\n  \"Array.get (set r v h) = Array.get h\"\n  by (simp add: Array.get_def set_def fun_eq_iff)\n\nlemma get_update [simp]:\n  \"get (Array.update a i v h) r = get h r\"\n  by (simp add: get_def Array.update_def Array.set_def)\n\nlemma alloc_update:\n  \"fst (alloc v (Array.update a i v' h)) = fst (alloc v h)\"\n  by (simp add: Array.update_def Array.get_def Array.set_def alloc_def Let_def)\n\nlemma update_set_swap:\n  \"Array.update a i v (set r v' h) = set r v' (Array.update a i v h)\"\n  by (simp add: Array.update_def Array.get_def Array.set_def set_def)\n\nlemma length_alloc [simp]: \n  \"Array.length (snd (alloc v h)) a = Array.length h a\"\n  by (simp add: Array.length_def Array.get_def alloc_def set_def Let_def)\n\nlemma array_get_alloc [simp]: \n  \"Array.get (snd (alloc v h)) = Array.get h\"\n  by (simp add: Array.get_def alloc_def set_def Let_def fun_eq_iff)\n\nlemma present_update [simp]: \n  \"present (Array.update a i v h) = present h\"\n  by (simp add: Array.update_def Array.set_def fun_eq_iff present_def)\n\nlemma array_present_set [simp]:\n  \"Array.present (set r v h) = Array.present h\"\n  by (simp add: Array.present_def set_def fun_eq_iff)\n\nlemma array_present_alloc [simp]:\n  \"Array.present h a \\<Longrightarrow> Array.present (snd (alloc v h)) a\"\n  by (simp add: Array.present_def alloc_def Let_def)\n\nlemma set_array_set_swap:\n  \"Array.set a xs (set r x' h) = set r x' (Array.set a xs h)\"\n  by (simp add: Array.set_def set_def)\n\nhide_const (open) present get set alloc noteq lookup update change\n\n\nsubsection \\<open>Code generator setup\\<close>\n\ntext \\<open>Intermediate operation avoids invariance problem in \\<open>Scala\\<close> (similar to value restriction)\\<close>\n\ndefinition ref' where\n  [code del]: \"ref' = ref\"\n\n\n\n\ntext \\<open>SML / Eval\\<close>\n\ncode_printing type_constructor ref \\<rightharpoonup> (SML) \"_/ ref\"\ncode_printing type_constructor ref \\<rightharpoonup> (Eval) \"_/ Unsynchronized.ref\"\ncode_printing constant Ref \\<rightharpoonup> (SML) \"raise/ (Fail/ \\\"bare Ref\\\")\"\ncode_printing constant ref' \\<rightharpoonup> (SML) \"(fn/ ()/ =>/ ref/ _)\"\ncode_printing constant ref' \\<rightharpoonup> (Eval) \"(fn/ ()/ =>/ Unsynchronized.ref/ _)\"\ncode_printing constant Ref.lookup \\<rightharpoonup> (SML) \"(fn/ ()/ =>/ !/ _)\"\ncode_printing constant Ref.update \\<rightharpoonup> (SML) \"(fn/ ()/ =>/ _/ :=/ _)\"\ncode_printing constant \"HOL.equal :: 'a ref \\<Rightarrow> 'a ref \\<Rightarrow> bool\" \\<rightharpoonup> (SML) infixl 6 \"=\"\n\ncode_reserved Eval Unsynchronized\n\n\ntext \\<open>OCaml\\<close>\n\ncode_printing type_constructor ref \\<rightharpoonup> (OCaml) \"_/ ref\"\ncode_printing constant Ref \\<rightharpoonup> (OCaml) \"failwith/ \\\"bare Ref\\\"\"\ncode_printing constant ref' \\<rightharpoonup> (OCaml) \"(fun/ ()/ ->/ ref/ _)\"\ncode_printing constant Ref.lookup \\<rightharpoonup> (OCaml) \"(fun/ ()/ ->/ !/ _)\"\ncode_printing constant Ref.update \\<rightharpoonup> (OCaml) \"(fun/ ()/ ->/ _/ :=/ _)\"\ncode_printing constant \"HOL.equal :: 'a ref \\<Rightarrow> 'a ref \\<Rightarrow> bool\" \\<rightharpoonup> (OCaml) infixl 4 \"=\"\n\ncode_reserved OCaml ref\n\n\ntext \\<open>Haskell\\<close>\n\ncode_printing type_constructor ref \\<rightharpoonup> (Haskell) \"Heap.STRef/ Heap.RealWorld/ _\"\ncode_printing constant Ref \\<rightharpoonup> (Haskell) \"error/ \\\"bare Ref\\\"\"\ncode_printing constant ref' \\<rightharpoonup> (Haskell) \"Heap.newSTRef\"\ncode_printing constant Ref.lookup \\<rightharpoonup> (Haskell) \"Heap.readSTRef\"\ncode_printing constant Ref.update \\<rightharpoonup> (Haskell) \"Heap.writeSTRef\"\ncode_printing constant \"HOL.equal :: 'a ref \\<Rightarrow> 'a ref \\<Rightarrow> bool\" \\<rightharpoonup> (Haskell) infix 4 \"==\"\ncode_printing class_instance ref :: HOL.equal \\<rightharpoonup> (Haskell) -\n\n\ntext \\<open>Scala\\<close>\n\ncode_printing type_constructor ref \\<rightharpoonup> (Scala) \"!Ref[_]\"\ncode_printing constant Ref \\<rightharpoonup> (Scala) \"!sys.error(\\\"bare Ref\\\")\"\ncode_printing constant ref' \\<rightharpoonup> (Scala) \"('_: Unit)/ =>/ Ref((_))\"\ncode_printing constant Ref.lookup \\<rightharpoonup> (Scala) \"('_: Unit)/ =>/ Ref.lookup((_))\"\ncode_printing constant Ref.update \\<rightharpoonup> (Scala) \"('_: Unit)/ =>/ Ref.update((_), (_))\"\ncode_printing constant \"HOL.equal :: 'a ref \\<Rightarrow> 'a ref \\<Rightarrow> bool\" \\<rightharpoonup> (Scala) infixl 5 \"==\"\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/HOL/Imperative_HOL/Ref.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5813030906443133, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.29292221432329485}}
{"text": "theory Linked_List_Insert imports\n \"/home/dacosta/development/rockwellcollins/l4v/tools/autocorres/AutoCorres\"\n \"/home/dacosta/development/rockwellcollins/l4v/tools/autocorres/DataStructures\"\nbegin\n\ntext{* \n\nAuthor: Dan DaCosta\nDescription: Work towards a correctness proof of an order preserving linked list insert. Insertion\nrelies on the function, find_insertion, to find the correct placement for the new node. Currently,\nthere is a proof that find_insertion finds the insertion point according to the following \nstatements:\n\n  - find_insertion does not alter the heap\n\n  - if find_insertion returns a non-null node n, then all ancestors of n and n have values less than\n  or equal to the value find_insertion was called with.\n\n  - if find_insertion returns a non-null node n and n's direct descendant is not null than n's \n  direct descendant has a value greater than the value of what find_insertion was called with.\n\n  - if find_insertion returns null then either the list find_insertion was called with is null or\n  the first element of the list is greater than the value find_insertion was called with.\n\nTODO:\n \n - Requires significant cleanup.\n\n - A proof that insert uses find_insertion to insert a new element into a linked list preserving\n ascending order must be given.\n\n*}\n\ninstall_C_file linked_list.c\nautocorres [ heap_abs_syntax, ts_rules = nondet] linked_list.c\ncontext linked_list begin\n\ninterpretation DataStructures.linked_list next_C NULL\ndone\n\ntext{*\n\nBoth of these lemma seem like poor candidates for simplification rules; they both have the \npotential for looping.\n\n*}\n\ndeclare list_split [simp del]\ndeclare path_split [simp del]\n\ndefinition lkup :: \"lifted_globals \\<Rightarrow> ll_C ptr \\<Rightarrow> ll_C option\" where \n\"lkup s a \\<equiv> (if is_valid_ll_C s a then Some (s[a]) else None)\"\n\ntext{*\n\nA useful lemma when using DataStructures.thy. It connects the lkup function to the structure \nnotations generated by AutoCorres.\n\n*}\n\nlemma lkup_conv[simp]: \"lkup s i = Some j \\<Longrightarrow> is_valid_ll_C s i \\<and> s[i] = j \\<and> next_C j = s[i]\\<rightarrow>next \\<and> val_C j = s[i]\\<rightarrow>val\"\nby \n  (metis \n    linked_list.get_ll_next_def\n    linked_list.get_ll_val_def\n    linked_list.lkup_def \n    option.distinct(1) \n    option.sel)\n\nlemma list_null_free: \"list (lkup s') xs i \\<Longrightarrow> NULL \\<notin> set xs\"\n apply (induction xs arbitrary: i) by auto\n\nlemma list_member_not_null:\"\\<lbrakk>list (lkup s') xs i; j \\<in> set xs\\<rbrakk> \\<Longrightarrow> j \\<noteq> NULL\"\n apply (rule ccontr)\n apply (simp add: list_null_free)\n done\n\nlemma list_non_empty_recursive: \"list (lkup s) (x # xs) i \\<Longrightarrow> list (lkup s) xs s[i]\\<rightarrow>next\" by auto\n\nlemma list_non_empty_member: \n\"\\<lbrakk>list (lkup s) (x # xs) i; j \\<in> set (x # xs)\\<rbrakk> \n  \\<Longrightarrow> j = x \\<or> (list (lkup s) xs s[i]\\<rightarrow>next \\<and> j \\<in> set xs)\" by auto\n\n(* Take a bit longer. *)\nlemma list_next:\"\\<lbrakk>list (lkup s) xs i; j \\<in> set xs; s[j]\\<rightarrow>next \\<noteq> NULL\\<rbrakk> \\<Longrightarrow> s[j]\\<rightarrow>next \\<in> set xs\"\n apply (induction xs arbitrary: i j) using list_mem by auto \n\nlemma list_all_valid:\"\\<lbrakk>list (lkup s) xs i; j \\<in> set xs\\<rbrakk> \\<Longrightarrow> is_valid_ll_C s j\"\n apply (induction xs arbitrary: i j) by auto\n\nlemma the_list_next_is_smaller:\"\\<lbrakk>list (lkup s) xs i; j \\<in> set xs\\<rbrakk>\n       \\<Longrightarrow> length (the_list (lkup s) s[j]\\<rightarrow>next) < length (the_list (lkup s) j)\"\n apply (induction xs arbitrary: i j)\n apply auto\n by (simp add: is_list_non_NULL linked_list.list_is_list the_list_non_NULL)\n\n(* Awkward. Can this be generalized into something more intuitive? *)\nlemma the_list_absurd:\n  \"\\<lbrakk>is_valid_ll_C s x; x \\<noteq> NULL; s[x]\\<rightarrow>next = NULL; the_list (lkup s) x = []\\<rbrakk> \\<Longrightarrow> False\"\nby \n  (metis \n    is_list_non_NULL\n    linked_list.get_ll_next_def\n    linked_list.is_list_empty\n    linked_list.lkup_def\n    the_list_empty')\n\nlemma path_null_list_imp: \"list s xs i \\<Longrightarrow> path s i xs NULL\"\n using path_null_list by auto\n\nlemma list_singleton: \"\\<lbrakk>list (lkup s) xs i; i \\<noteq> NULL; s[i]\\<rightarrow>next = NULL\\<rbrakk> \\<Longrightarrow> xs = [i]\"\n by (cases xs, auto) \n\nlemma list_non_empty: \n\"list (lkup s) (x # xs) i \n  \\<Longrightarrow> i \\<noteq> NULL \\<and> x = i \\<and> is_valid_ll_C s i \\<and> list (lkup s) xs s[i]\\<rightarrow>next\"\n by auto\n\nlemma list_member_has_sublist:\"\\<lbrakk>list (lkup s) xs i; j \\<in> set xs\\<rbrakk> \\<Longrightarrow> \\<exists> xs1 xs2. xs = xs1 @ xs2 \\<and> list (lkup s) xs2 j\"\n apply (induction xs arbitrary: i)\n apply auto\n using list_non_NULL apply auto[1]\n by (metis append_Cons)\n\nlemma list_is_two_paths:\"\\<lbrakk>list (lkup s) xs i; j \\<in> set xs \\<rbrakk> \\<Longrightarrow>  \\<exists> xs1 xs2. xs = xs1 @ xs2 \\<and> path (lkup s) i xs1 j \\<and> path (lkup s) j xs2 NULL\"\nproof(induction xs arbitrary: i j)\n  case Nil\n  thus ?case by auto\nnext\n  case (Cons x xs)\n  have \"s[i]\\<rightarrow>next = NULL \\<or> s[i]\\<rightarrow>next \\<noteq> NULL\" by auto\n  thus ?case\n  proof\n    assume \"s[i]\\<rightarrow>next = NULL\"\n    thus ?case using Cons by (metis append_Nil empty_iff linked_list.list_singleton linked_list.path.simps(1) linked_list.path_null_list list.set(1) local.list.simps(2) set_ConsD)\n  next\n    assume a1:\"s[i]\\<rightarrow>next \\<noteq> NULL\"\n    have \"x = j \\<or> x \\<noteq> j\" by auto\n    thus ?case\n    proof\n      assume a2:\"x = j\"\n      thus ?case using a1 a2 Cons by (metis (no_types, hide_lams) append_Nil linked_list.list.simps(2) linked_list.path.simps(1) linked_list.path_null_list)\n    next\n      assume a2:\"x \\<noteq> j\"\n      then have h1:\"list (lkup s) xs s[i]\\<rightarrow>next\" using Cons by auto\n      then have h2:\"j \\<in> set xs\" using a2 Cons by auto\n      then obtain xs1 xs2 where \"xs = xs1 @ xs2 \\<and> path (lkup s) s[i]\\<rightarrow>next xs1 j \\<and> path (lkup s) j xs2 NULL\" using Cons(1)[OF h1 h2] by auto\n      then have \"i # xs = i # xs1 @ xs2 \\<and> path (lkup s) i (i # xs1) j \\<and> path (lkup s) j xs2 NULL\" using Cons by (metis linked_list.get_ll_next_def linked_list.list_non_empty linked_list.lkup_def path.simps(2))\n      thus ?case by (metis Cons(2) append_Cons linked_list.list.simps(2))\n    qed\n  qed\nqed\n \nlemma list_hd_non_member_tail:\"\\<lbrakk>list (lkup s) xs i; xs \\<noteq> []\\<rbrakk> \\<Longrightarrow> xs = [] \\<or> hd xs \\<notin> set (tl xs)\"\napply (induction xs arbitrary: i)\napply auto\nby \n  (metis \n    linked_list.get_ll_next_def \n    linked_list.list_all_valid \n    linked_list.list_head_not_in_list \n    linked_list.lkup_def)\n\nlemma path_non_empty_non_null_start:\"\\<lbrakk>path (lkup s) i xs j; xs \\<noteq> []\\<rbrakk> \\<Longrightarrow> i \\<noteq> NULL\" by auto\n\nlemma path_extend:\n\"\\<lbrakk>path (lkup s) i xs a; a \\<noteq> NULL; is_valid_ll_C s a\\<rbrakk> \\<Longrightarrow> path (lkup s) i (xs@[a]) s[a]\\<rightarrow>next\"\nproof(induction xs arbitrary:i)\n  case Nil\n  thus ?case by (metis append_Nil linked_list.get_ll_next_def path.simps lkup_def)\nnext\n  case (Cons x xs)\n  then have \"i \\<noteq> NULL \\<and> is_valid_ll_C s a \\<and> i = x \\<and> path (lkup s) s[i]\\<rightarrow>next xs a\" \n    using lkup_def\n    by (metis linked_list.get_ll_next_def option.distinct(1) option.sel path.simps(2))\n  then have h1:\"i = x\" and h2:\"path (lkup s) s[i]\\<rightarrow>next xs a\" and h3:\"i \\<noteq> NULL\" and h4:\"is_valid_ll_C s a\" by auto\n  then have \"path (lkup s) s[i]\\<rightarrow>next (xs @ [a]) s[a]\\<rightarrow>next\" using Cons(1)[OF h2 Cons(3) Cons(4)] by auto\n  thus ?case \n    using h3 h4 h1 Cons.prems(1) append_Cons linked_list.get_ll_next_def \n    by (metis lkup_def option.simps(3) path.simps(2))\nqed\n\nlemma path_equal_endpoints:\"path (lkup s) j [] j\" by (meson linked_list.path.simps(1))\n \nlemma list_path_no_cycles:\"\\<lbrakk>list (lkup s) xs i; j \\<in> set xs; path (lkup s) j ys j\\<rbrakk> \\<Longrightarrow> ys = []\"\nproof (induction xs arbitrary: i)\n  case Nil\n  thus ?case by auto\nnext\n  case (Cons x xs)\n  have \"j = i \\<or> j \\<noteq> i\" using Cons by auto\n  thus ?case\n  proof\n    assume \"j = i\"\n    thus ?case using Cons by (meson append_self_conv2 list_split list_unique)\n  next\n    assume a:\"j \\<noteq> i\"\n    then have \"x = i \\<and> list (lkup s) xs (s[i]\\<rightarrow>next)\" using Cons list_non_empty by blast\n    then have h1:\"x = i\" and h2:\"list (lkup s) xs (s[i]\\<rightarrow>next)\" by auto\n    thus ?case using Cons Cons(1)[OF h2 _ Cons(4)] a by auto\n  qed\nqed\n\nlemma paths_preserve_list:\n\"\\<lbrakk>list (lkup s) xs i; j \\<in> set xs; path (lkup s) i xs1 j; path (lkup s) j xs2 NULL\\<rbrakk> \n  \\<Longrightarrow> xs = xs1 @ xs2\"\nproof (induction xs arbitrary: i)\n  case Nil\n  thus ?case by auto\nnext\n  case (Cons x xs)\n  have \"j = i \\<or> j \\<noteq> i\" using Cons by auto\n  thus ?case\n  proof\n    assume \"j = i\"\n    thus ?case using Cons list_path_no_cycles \n      by (metis append_self_conv2 list_unique path_null_list)\n  next\n    assume a:\"j \\<noteq> i\"\n    then have \"x = i \\<and> list (lkup s) xs (s[i]\\<rightarrow>next)\" using list_non_empty Cons by blast\n    then have h1:\"x = i\" and h2:\"list (lkup s) xs (s[i]\\<rightarrow>next)\" by auto\n    thus ?case \n      using Cons(1)[OF h2 _ _ Cons(5)] Cons a by (meson list_split list_unique path_null_list) \n  qed\nqed\n\nlemma path_shorten:\"\\<lbrakk>path (lkup s) i xs NULL; i \\<noteq> NULL\\<rbrakk> \\<Longrightarrow> path (lkup s) s[i]\\<rightarrow>next (tl xs) NULL\"\nproof -\n  assume a1:\"path (lkup s) i xs NULL\"\n  and a2:\"i \\<noteq> NULL\"\n  have \"s[i]\\<rightarrow>next = NULL \\<or> s[i]\\<rightarrow>next \\<noteq> NULL\" by simp\n  thus ?thesis\n  proof \n    assume \"s[i]\\<rightarrow>next = NULL\"\n    thus ?thesis \n      using a1 a2 linked_list.path.simps(1) linked_list.path_null_list \n            linked_list.list_singleton list.sel(3) \n      by fastforce\n  next\n    assume \"s[i]\\<rightarrow>next \\<noteq> NULL\"\n    thus ?thesis by (metis a1 a2 linked_list.path_null_list list.sel(3) list_non_empty path_next)\n  qed\nqed\n\nlemma find_insertion_1_loop_step:\nassumes a1:\"list (lkup s) xs i\"\nand a2:\"path (lkup s) i xs1 a\"\nand a3:\"\\<forall>x\\<in>set xs1. sint s[x]\\<rightarrow>val \\<le> v\"\nand a4:\"path (lkup s) a xs2 NULL\"\nand a5:\"a \\<noteq> NULL\"\nand a6:\"sint s[a]\\<rightarrow>val \\<le> v\"\nand a7:\"a \\<in> set xs\"\nshows \"\\<exists>xs1. path (lkup s) i xs1 s[a]\\<rightarrow>next \n       \\<and> (\\<exists>xs2. path (lkup s) s[a]\\<rightarrow>next xs2 NULL) \n       \\<and> (\\<forall>x\\<in>set xs1. sint s[x]\\<rightarrow>val \\<le> v)\"\nproof - \n  have h1:\"path (lkup s) i (xs1 @ [a]) s[a]\\<rightarrow>next\" using path_extend[OF a2 a5 list_all_valid[OF a1 a7]] by simp\n  then have h2:\"path (lkup s) s[a]\\<rightarrow>next (tl xs2) NULL\" using path_shorten[OF a4 a5] by simp\n  then have h3:\"\\<forall>x\\<in>set (xs1@[a]). sint s[x]\\<rightarrow>val \\<le> v\" using a3 a6 by simp\n  thus ?thesis using h1 h2 h3 by metis\nqed\n\ntext{*\n\nCorrectness of find_insertion when the input list is not null and the head of the list is less \nthan or equal to value supplied.\n\n*}\n\nlemma find_insertion_1:\n\"\\<lbrace> \\<lambda> (s::lifted_globals). \n  s' = s\n  \\<and> i \\<noteq> NULL\n  \\<and> sint s'[i]\\<rightarrow>val \\<le> v\n  \\<and> list (lkup s) xs i \\<rbrace>\n  find_insertion' v i\n\\<lbrace> \\<lambda> r s.\n  s' = s\n  \\<and> r \\<in> set xs\n  \\<and> (s[r]\\<rightarrow>next = NULL \\<or> (s[r]\\<rightarrow>next \\<noteq> NULL \\<and>  v < sint s[s[r]\\<rightarrow>next]\\<rightarrow>val))\n  \\<and> (\\<exists> xs1 xs2.\n       path (lkup s) i xs1 s[r]\\<rightarrow>next \n       \\<and> path (lkup s) s[r]\\<rightarrow>next xs2 NULL\n       \\<and> (\\<forall> x \\<in> set xs1. sint s[x]\\<rightarrow>val \\<le> v))\n\\<rbrace>!\"\n apply (rule validNF_assume_pre)\n apply (unfold find_insertion'_def)\n apply (subst whileLoop_add_inv [where \n  I = \" \\<lambda> (it,last,cond) s. \n       s = s'\n       \\<and> (cond \\<noteq> 0 \\<longrightarrow> it \\<noteq> NULL \\<and> sint s[it]\\<rightarrow>val \\<le> v \\<and> it \\<in> set xs)\n       \\<and> (cond = 0 \\<longrightarrow> last \\<noteq> NULL \\<and> (it = NULL \\<or> v < sint s[it]\\<rightarrow>val))\n       \\<and> (last \\<noteq> NULL \\<longrightarrow> s[last]\\<rightarrow>next = it \\<and> last \\<in> set xs)\n       \\<and> (\\<exists> xs1 xs2. path (lkup s) i xs1 it \\<and> path (lkup s) it xs2 NULL \\<and> (\\<forall> x \\<in> set xs1. sint s[x]\\<rightarrow>val \\<le> v))\n\" \n  and M = \"\\<lambda>((it,r,_),s). length (the_list (lkup s) it)\"])\n apply wp\n    apply (clarsimp,auto intro: list_all_valid list_next list_mem the_list_next_is_smaller path_null_list_imp the_list_absurd find_insertion_1_loop_step)[1]\n   apply (clarsimp, auto)\n  apply wp\n apply (auto intro: list_mem list_all_valid) \n apply (metis empty_iff linked_list.path.simps(1) linked_list.path_null_list list.set(1))\ndone\n\ntext{*\n\nCorrectness of find_insertion when the input list is null.\n\n*}\n\nlemma find_insertion_2:\n\"\\<lbrace> \\<lambda> (s::lifted_globals). \n  s' = s\n  \\<and> i = NULL\n  \\<and> list (lkup s) xs i \\<rbrace>\n  find_insertion' v i\n\\<lbrace> \\<lambda> r s.\n  s' = s\n  \\<and> r = NULL\n\\<rbrace>!\"\n apply (unfold find_insertion'_def)\n apply (subst whileLoop_unroll)\n apply wp\n    apply (rule validNF_false_pre)\n   apply (rule validNF_false_pre)\n  apply wp\n apply auto\ndone\n\ntext{*\n\nCorrectness of find_insertion when the input list is not null and the head of the list is greater\nthan the value supplied to find_insertion.\n\n*}\n\nlemma find_insertion_3:\n\"\\<lbrace> \\<lambda> (s::lifted_globals). \n  s' = s\n  \\<and> i \\<noteq> NULL\n  \\<and> v < sint s'[i]\\<rightarrow>val\n  \\<and> list (lkup s) xs i \\<rbrace>\n  find_insertion' v i\n\\<lbrace> \\<lambda> r s.\n  s' = s\n  \\<and> r = NULL\n  \\<and> v < sint s'[i]\\<rightarrow>val\n\\<rbrace>!\"\n apply (unfold find_insertion'_def)\n apply (subst whileLoop_unroll)\n apply wp\n    apply (rule validNF_false_pre)\n   apply (rule validNF_false_pre)\n  apply wp\n apply (auto intro: list_all_valid list_mem) \ndone\n\nlemma find_insertion_pre_part:\n\"\\<And>s. s' = s \\<and> list (lkup s) xs i\n \\<Longrightarrow> ((s' = s \\<and> i \\<noteq> NULL \\<and> sint s'[i]\\<rightarrow>val \\<le> v \\<and> list (lkup s) xs i)\n     \\<or> (s' = s \\<and> i = NULL \\<and> list (lkup s) xs i)\n     \\<or> (s' = s \\<and> i \\<noteq> NULL \\<and> v < sint s'[i]\\<rightarrow>val \\<and> list (lkup s) xs i))\"\nby auto\n\nlemma find_insertion:\n\"\n\\<lbrace> \\<lambda> (s::lifted_globals). \n  s' = s\n  \\<and> list (lkup s) xs i \\<rbrace>\n  find_insertion' v i\n\\<lbrace> \\<lambda> r s.\n  (s' = s \\<and> r \\<in> set xs \\<and>\n                     (s[r]\\<rightarrow>next = NULL \\<or> s[r]\\<rightarrow>next \\<noteq> NULL \\<and> v < sint s[s[r]\\<rightarrow>next]\\<rightarrow>val) \\<and>\n                     (\\<exists>xs1 xs2. path (lkup s) i xs1 s[r]\\<rightarrow>next \\<and> path (lkup s) s[r]\\<rightarrow>next xs2 NULL \\<and> (\\<forall>x\\<in>set xs1. sint s[x]\\<rightarrow>val \\<le> v)) \\<or>\n            s' = s \\<and> r = NULL) \\<or>\n           s' = s \\<and> r = NULL \\<and> v < sint s'[i]\\<rightarrow>val\n\\<rbrace>!\"\nusing validNF_weaken_pre[OF \n        validNF_vcg_disj_lift[OF \n          validNF_vcg_disj_lift[OF find_insertion_1 find_insertion_2]  \n          find_insertion_3, \n          of s' i v xs s' xs s' xs],\n        of \"\\<lambda> s . s' = s \\<and> list (lkup s) xs i\"] find_insertion_pre_part by simp\n\n\nlemma else_branch:\"\\<not> C \\<Longrightarrow> Q \\<Longrightarrow> if C then P else Q\"\n by auto\n\nlemma next_update_preserve_validity:\"is_valid_ll_C s i = is_valid_ll_C s[j\\<rightarrow>next := x] i\"\n  by auto\n\nlemma next_update_preserve_untouched_state:\"x \\<noteq> y \\<Longrightarrow> lkup s x = lkup s[y\\<rightarrow>next := v] x\"\n apply(unfold lkup_def) by (simp add: linked_list.update_ll_next_def)\n\nlemma next_update_preserve_path:\"\\<lbrakk>i \\<notin> set xs; path (lkup s) j xs k\\<rbrakk> \\<Longrightarrow> path (lkup s[i\\<rightarrow>next := l]) j xs k\"\n  apply(induction xs arbitrary: j)\n  apply auto\n  using linked_list.next_update_preserve_untouched_state by auto\n\nlemma non_member_next_update_preserves_list:\"\\<lbrakk>list (lkup s) xs i; n \\<notin> set xs\\<rbrakk> \\<Longrightarrow> list (lkup s[n\\<rightarrow>next := j]) xs i\"\nproof (induction xs arbitrary: i) \n  case Nil\n  thus ?case by auto\nnext\n  case (Cons x xs)\n  then have h1:\"list (lkup s) xs s[i]\\<rightarrow>next\" and h2:\"x = i\" by auto \n  have h3:\"n \\<notin> set xs\" using Cons by auto\n  have h4:\"i \\<noteq> n\" using Cons h2 by auto\n  have h5:\"is_valid_ll_C s[n\\<rightarrow>next := j] i\" using next_update_preserve_validity Cons by auto\n  have h6:\"i \\<noteq> NULL\" using Cons by auto\n  obtain di where h7:\"lkup s i = Some di\" using Cons by auto\n  have h8:\"lkup s[n\\<rightarrow>next := j] i = Some di\" using next_update_preserve_untouched_state[OF h4,of s x] h7 using h4 linked_list.next_update_preserve_untouched_state by presburger\n  have h9:\"s[n\\<rightarrow>next := j][i]\\<rightarrow>next = next_C di\" using h8 by auto\n  have h10:\"s[i]\\<rightarrow>next = s[n\\<rightarrow>next := j][i]\\<rightarrow>next\" using h4 by simp\n  have h11:\"list (lkup s[n\\<rightarrow>next := j]) xs s[n\\<rightarrow>next := j][i]\\<rightarrow>next\" using Cons(1)[OF h1 h3] h10 by auto\n  thus ?case using h2 h6 h8 h11 h9 by auto\nqed\n\nlemma path_one_step:\"\\<lbrakk>path (lkup s) i xs j; i\\<noteq> NULL; xs \\<noteq> []\\<rbrakk> \\<Longrightarrow> path (lkup s) s[i]\\<rightarrow>next (tl xs) j\"\n apply(induction xs arbitrary: i) by auto\n(*\nlemma path_cannot_cycle:\"\\<lbrakk>list (lkup s) xs i; j \\<in> set xs; path (lkup s) i ys s[j]\\<rightarrow>next\\<rbrakk> \\<Longrightarrow> ys \\<noteq> []\"\nsorry\n*)\n\nlemma lkup_valid_eval:\"is_valid_ll_C s i \\<Longrightarrow> lkup s i = Some s[i]\"\n  using lkup_def by metis\n\nlemma list_last_element:\"\\<lbrakk>list (lkup s) xs i; n \\<notin> set xs;  r \\<in> set xs; s[r]\\<rightarrow>next = NULL\\<rbrakk> \\<Longrightarrow> last xs = r\"\n  apply(induction xs arbitrary: i) by auto\n\nlemma hd_last_not_equal_if_distinct:\"\\<lbrakk>distinct xs; length xs > 1\\<rbrakk> \\<Longrightarrow> hd xs \\<noteq> last xs\"\n  apply(induction xs) by auto\n\nlemma insert_front:\n\"\\<lbrakk>n \\<noteq> NULL; is_valid_ll_C s n; list (lkup s) xs i; n \\<notin> set xs\\<rbrakk> \n   \\<Longrightarrow> list (lkup s[n\\<rightarrow>next := i]) (n # xs) n\"\nproof -\n  assume a1:\"n \\<noteq> NULL\"\n  assume a2:\"is_valid_ll_C s n\"\n  assume a3:\"list (lkup s) xs i\"\n  assume a4:\"n \\<notin> set xs\"\n  have h1:\"is_valid_ll_C s[n\\<rightarrow>next := i] n\" using next_update_preserve_validity a2 by auto\n  have h2:\"list (lkup s[n\\<rightarrow>next := i]) xs i\" using non_member_next_update_preserves_list[OF a3 a4, of i] by auto\n  obtain dn where h3:\"lkup s[n\\<rightarrow>next := i] n = Some dn\" by (metis h1 lkup_def)\n  have h4:\"next_C dn = i\" using lkup_conv[OF h3] by simp\n  thus ?thesis using a1 h3 h2 h4 by auto\nqed\n\nlemma insert_back:\n\"\\<lbrakk>n \\<noteq> NULL; is_valid_ll_C s n; list (lkup s) xs i; n \\<notin> set xs;  last xs = r; xs \\<noteq> []\\<rbrakk> \n   \\<Longrightarrow> list (lkup s[n\\<rightarrow>next := NULL][r\\<rightarrow>next := n]) (xs@[n]) i  \\<and> insert n (set xs) = set (xs@[n])\"\nproof (induction xs arbitrary: i)\n  case Nil\n  thus ?case by auto\nnext\n  case (Cons x xs)\n  have h2:\"list (lkup s) xs s[i]\\<rightarrow>next\" and h3:\"x = i\" and h4:\"i \\<noteq> NULL\" using Cons by auto\n  have h5:\"(last xs = r \\<and> xs \\<noteq> []) \\<or> xs = []\" using Cons by auto\n  thus ?case\n  proof\n    assume a:\"last xs = r \\<and> xs \\<noteq> []\"\n    have \"length (x # xs) > 1\" using a Cons by auto\n    then have \"r \\<noteq> i\" by (metis Cons.prems(3) Cons.prems(5) h3 list.sel(1) hd_last_not_equal_if_distinct list_distinct)\n    then have h6:\"lkup s i = lkup s[n\\<rightarrow>next := NULL][r\\<rightarrow>next := n] i\" by (metis List.list.simps(15) h3 insert_iff Cons next_update_preserve_untouched_state )\n    have \"is_valid_ll_C s[n\\<rightarrow>next := NULL][r\\<rightarrow>next := n] i\" using Cons next_update_preserve_validity linked_list.list_non_empty by presburger\n    thus ?case using Cons h2 h3 h4 a h6 by auto\n  next \n    assume \"xs = []\"\n    then have \"list (lkup s[n\\<rightarrow>next := NULL][r\\<rightarrow>next := n]) ((x # xs) @ [n]) i\" using Cons \n    by (metis (no_types, hide_lams) append.simps(1) append.simps(2) empty_iff insert_front last_in_set linked_list.heap_abs_simps(36) linked_list.list_empty list.set(1) list_non_empty set_ConsD) \n    thus ?case using Cons by auto\n  qed\nqed\n\nlemma insert_middle:\" \\<lbrakk>n \\<noteq> NULL; is_valid_ll_C s n; list (lkup s) xs i; n \\<notin> set xs; r \\<in> set xs; path (lkup s) i xs1 s[r]\\<rightarrow>next; path (lkup s) s[r]\\<rightarrow>next xs2 NULL\\<rbrakk>\n       \\<Longrightarrow> list (lkup s[n\\<rightarrow>next := s[r]\\<rightarrow>next][r\\<rightarrow>next := n]) (xs1@[n]@xs2) i \\<and> insert n (set xs) = set (xs1@[n]@xs2)\"\nproof (induction xs arbitrary: i xs1)\n  case Nil\n  thus ?case by auto\nnext \n  case (Cons x xs)\n  then have h1:\"x = i\" by auto\n  then have \"r = x \\<or> r \\<in> set xs\" using Cons by auto\n  thus ?case\n  proof\n    assume a:\"r = x\"\n    then have h2:\"r = i\" using h1 by auto\n    then have h3:\"r \\<notin> set xs2\" using a Cons list_distinct by (metis linked_list.get_ll_next_def linked_list.list_head_not_in_list linked_list.path_null_list list_non_empty lkup_def)\n    then have \"xs1 @ xs = i # xs\"\n      by (metis (no_types) Cons h2 h1 linked_list.list_non_empty_recursive linked_list.list_split linked_list.list_unique)\n    then have h4:\"xs1 = [r]\" using h2 by auto\n    then have \"path (lkup s) i [r] s[r]\\<rightarrow>next\" using Cons by auto\n    then have h5:\"path (lkup s[n\\<rightarrow>next := s[r]\\<rightarrow>next]) i [r] s[n\\<rightarrow>next := s[r]\\<rightarrow>next][i]\\<rightarrow>next\" using Cons by (metis h2 fun_upd_apply linked_list.heap_abs_simps(16) linked_list.next_update_preserve_path singleton_set)\n    then have h6:\"n \\<notin> set xs2\" using Cons by (metis List.list.simps(15) h2 insert_iff linked_list.list_non_empty_recursive linked_list.list_the_list path_null_list)\n    then have h7:\"path (lkup s[n\\<rightarrow>next := s[r]\\<rightarrow>next]) s[n\\<rightarrow>next := s[r]\\<rightarrow>next][r]\\<rightarrow>next xs2 NULL\" using next_update_preserve_path[OF h6 Cons(8)] Cons by auto\n    then have h8:\"path (lkup s[n\\<rightarrow>next := s[r]\\<rightarrow>next][r\\<rightarrow>next := n]) n (n#xs2) NULL\" using Cons by (metis h3 h6 linked_list.insert_front linked_list.non_member_next_update_preserves_list linked_list.path_null_list set_ConsD)\n    then have h9:\"x = i\" using a h2 by auto\n    then have h10:\"i \\<noteq> NULL\" using Cons by auto\n    have h11:\"lkup s[n\\<rightarrow>next := s[r]\\<rightarrow>next] r \\<noteq> None \\<or> [] = xs1\" using h5 by auto\n    then have h12:\"list (lkup s[n\\<rightarrow>next := s[r]\\<rightarrow>next][r\\<rightarrow>next := n]) (xs1@[n]@xs2) i\" using h11 h10 h9 h4 h7 h2 h4 \n    by (metis Cons.prems(1) Cons.prems(2) Cons.prems(4) Cons.prems(7) List.list.simps(15) append_Cons append_Nil h3 h6 insert_iff linked_list.insert_front linked_list.lkup_def linked_list.path_null_list)\n    thus ?thesis using Cons by (metis (mono_tags, hide_lams) List.list.simps(15) a append_Cons append_Nil h4 h9 insert_commute linked_list.list_non_empty_recursive linked_list.list_the_list path_null_list)\n  next\n    assume a:\"r \\<in> set xs\"\n    then have h1:\"list (lkup s) xs s[i]\\<rightarrow>next\" using Cons by auto\n    then have h2:\"path (lkup s) s[i]\\<rightarrow>next (tl xs1) s[r]\\<rightarrow>next\" using path_one_step[OF Cons(7)] \n       Cons.prems(3) Cons.prems(5) Cons.prems(6) linked_list.list_non_empty by (metis Linked_List_Insert.linked_list.list_next a distinct.simps(2) linked_list.list_distinct linked_list.path.simps(1))\n    then have h3:\"n \\<notin> set xs\" using Cons by auto\n    then have h4:\"list (lkup s[n\\<rightarrow>next := s[r]\\<rightarrow>next][r\\<rightarrow>next := n]) (tl xs1 @ [n] @ xs2) s[i]\\<rightarrow>next\" and h45:\"insert n (set xs) = set (tl xs1 @ [n] @ xs2)\"\n    using Cons(1)[OF Cons(2) Cons(3) h1 h3 a h2 Cons(8)] by auto\n    then have h5:\"list (lkup s[n\\<rightarrow>next := s[r]\\<rightarrow>next][r\\<rightarrow>next := n]) (tl xs1 @ [n] @ xs2) s[n\\<rightarrow>next := s[r]\\<rightarrow>next][r\\<rightarrow>next := n][i]\\<rightarrow>next\" \n    by (metis a append.simps(1) distinct.simps(2) fun_upd_apply in_set_conv_decomp linked_list.heap_abs_simps(16) linked_list.list_distinct local.Cons(4) local.Cons(5) local.list.simps(2))\n    then have h6:\"i = x\" using Cons by (meson linked_list.list.simps(2))\n    then have h7:\"x \\<noteq> NULL\" using Cons using linked_list.list_non_empty by blast\n    then obtain a where  h8:\"lkup s[n\\<rightarrow>next := s[r]\\<rightarrow>next][r\\<rightarrow>next := n] i = Some a\" by (meson Cons.prems(3) linked_list.heap_abs_simps(36) linked_list.list_non_empty linked_list.lkup_def)\n    then obtain h9:\"list (lkup s[n\\<rightarrow>next := s[r]\\<rightarrow>next][r\\<rightarrow>next := n]) (tl xs1 @ [n] @ xs2) (next_C a)\"\n    by (metis Cons.prems(3) Cons.prems(4) a append_Nil distinct.simps(2) h4 in_set_conv_decomp linked_list.get_ll_next_def linked_list.list_distinct linked_list.list_non_empty linked_list.lkup_def linked_list.next_update_preserve_untouched_state option.sel)\n    then have h11:\"list (lkup s[n\\<rightarrow>next := s[r]\\<rightarrow>next][r\\<rightarrow>next := n]) ((x # tl xs1) @ [n] @ xs2) i\" using h6 h7 h8 h9 by auto\n    then have h12:\"xs1 = x # tl xs1\" using path_one_step[OF Cons(7)] h7 h6\n    by (metis Cons.prems(1) Cons.prems(6) append_Cons append_Nil h1 h3 h4 linked_list.list.simps(2) linked_list.path.simps(2) list.sel(2) list.sel(3) list_mem neq_Nil_conv)  \n    then have h13:\"list (lkup s[n\\<rightarrow>next := s[r]\\<rightarrow>next][r\\<rightarrow>next := n]) (xs1 @ [n] @ xs2) i\" using h11 h12 by auto\n    thus ?thesis using h13 h45 by (metis List.list.simps(15) append_Cons h12 insert_commute)\n  qed\nqed\n\nlemma gets_maintains_state:\n\"\n\\<lbrace>\\<lambda>s. s' = s \n  \\<and> n \\<noteq> NULL \n  \\<and> is_valid_ll_C s n \\<and> s[n]\\<rightarrow>next = NULL \n  \\<and> list (lkup s) xs' i \n  \\<and> n \\<notin> set xs' \\<rbrace> \nguard (\\<lambda> s.  is_valid_ll_C s n)\n\\<lbrace>\\<lambda> _ s. s' = s\\<rbrace>!\"\n by (simp add: guard_def validNF_alt_def validNF_state_assert state_assert_def validNF_weaken_pre)\n\nlemma \"\\<lbrace> \\<lambda> (s::lifted_globals). \n  s' = s\n  \\<and> n \\<noteq> NULL\n  \\<and> is_valid_ll_C s n\n  \\<and> s[n]\\<rightarrow>next = NULL\n  \\<and> list (lkup s) xs' i \n  \\<and> n \\<notin> set xs'\\<rbrace>\n  insert' n i\n\\<lbrace> \\<lambda> r s. (\\<exists> xs . list (lkup s) xs r \\<and> set (n # xs') = set xs)\\<rbrace>!\"\n apply (rule validNF_assume_pre)\n apply (unfold insert'_def)\n apply wp\n   apply (rule validNF_chain[OF find_insertion,of \"\\<lambda> s. s' = s\" s' xs'],simp)\n   apply safe\n      apply (rule else_branch)\n       apply (simp add: list_member_not_null)\n      apply (auto intro: list_all_valid)[1]\n      using insert_back apply (metis linked_list.list_last_element list.distinct(1) list.set_cases)\n     apply (rule else_branch)\n      apply (simp add: list_member_not_null) \n     apply (auto intro: list_all_valid, metis insert_middle)[1]\n    apply (auto intro: list_all_valid insert_front)[1]\n   apply (auto intro: list_all_valid insert_front)[1]\n  apply (rule validNF_gets)\n apply (rule gets_maintains_state)\ndone\n\nend", "meta": {"author": "smaccm", "repo": "autocorres-experiments", "sha": "9d27f34ae62e50eb43fb1bceab866c2c5500e3bc", "save_path": "github-repos/isabelle/smaccm-autocorres-experiments", "path": "github-repos/isabelle/smaccm-autocorres-experiments/autocorres-experiments-9d27f34ae62e50eb43fb1bceab866c2c5500e3bc/linked_list/Linked_List_Insert.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5813030906443133, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.29292221432329485}}
{"text": "theory Global\n  imports \"HOL-Library.Library\" Result Env List_util Option_Extra Map_Extra AList_Extra\nbegin\n\nsledgehammer_params [timeout = 30]\nsledgehammer_params [provers = \"cvc4 e spass vampire z3 zipperposition\"]\n\ndeclare K_record_comp[simp]\n\nlemma if_then_Some_else_None_eq[simp]:\n  \"(if a then Some b else None) = Some c \\<longleftrightarrow> a \\<and> b = c\"\n  \"(if a then Some b else None) = None \\<longleftrightarrow> \\<not> a\"\n  by (cases a) simp_all\n\nlemma if_then_else_distributive: \"(if a then f b else f c) = f (if a then b else c)\"\n  by simp\n\n\nsection \\<open>Rest\\<close>\n\nlemma map_ofD:\n  fixes xs k opt\n  assumes \"map_of xs k = opt\"\n  shows \"opt = None \\<or> (\\<exists>n < length xs. opt = Some (snd (xs ! n)))\"\n  using assms\n  by (metis in_set_conv_nth map_of_SomeD not_Some_eq snd_conv)\n\nlemma list_all2_assoc_map_rel_get:\n  assumes \"list_all2 (=) (map fst xs) (map fst ys)\" and \"list_all2 R (map snd xs) (map snd ys)\"\n  shows \"rel_option R (map_of xs k) (map_of ys k)\"\n  using assms[unfolded list.rel_map]\nproof (induction xs ys rule: list.rel_induct)\n  case Nil\n  thus ?case by simp\nnext\n  case (Cons x xs y ys)\n  thus ?case by (cases \"k = fst x\") auto\nqed\n\nsubsection \\<open>Function definition\\<close>\n\ndatatype ('label, 'instr) fundef =\n  Fundef (body: \"('label \\<times> 'instr list) list\") (arity: nat) (return: nat) (fundef_locals: nat)\n\nlemma rel_fundef_arities: \"rel_fundef r1 r2 gd1 gd2 \\<Longrightarrow> arity gd1 = arity gd2\"\n  by (simp add: fundef.rel_sel)\n\nlemma rel_fundef_return: \"rel_fundef R1 R2 gd1 gd2 \\<Longrightarrow> return gd1 = return gd2\"\n  by (simp add: fundef.rel_sel)\n\nlemma rel_fundef_locals: \"rel_fundef R1 R2 gd1 gd2 \\<Longrightarrow> fundef_locals gd1 = fundef_locals gd2\"\n  by (simp add: fundef.rel_sel)\n\nlemma rel_fundef_body_length[simp]:\n  \"rel_fundef r1 r2 fd1 fd2 \\<Longrightarrow> length (body fd1) = length (body fd2)\"\n  by (auto intro: list_all2_lengthD simp add: fundef.rel_sel)\n\ndefinition funtype where\n  \"funtype fd \\<equiv> (arity fd, return fd)\"\n\nlemma rel_fundef_funtype[simp]: \"rel_fundef R1 R2 fd1 fd2 \\<Longrightarrow> funtype fd1 = funtype fd2\"\n  by (simp add: fundef.rel_sel funtype_def)\n\nlemma rel_fundef_rel_fst_hd_bodies:\n  assumes \"rel_fundef R1 R2 fd1 fd2\" and \"body fd1 \\<noteq> [] \\<or> body fd2 \\<noteq> []\"\n  shows \"R1 (fst (hd (body fd1))) (fst (hd (body fd2)))\"\n  using assms\n  unfolding fundef.rel_sel\n  by (auto intro: list_all2_rel_prod_fst_hd[THEN conjunct1])\n\nlemma map_option_comp_conv:\n  assumes\n    \"\\<And>x. rel_option R (f x) (g x)\"\n    \"\\<And>fd1 fd2. fd1 \\<in> ran f \\<Longrightarrow> fd2 \\<in> ran g \\<Longrightarrow> R fd1 fd2 \\<Longrightarrow> h fd1 = i fd2\"\n  shows \"map_option h \\<circ> f = map_option i \\<circ> g\"\nproof (intro ext)\n  fix x\n  show \"(map_option h \\<circ> f) x = (map_option i \\<circ> g) x\"\n    using assms(1)[of x]\n    by (cases rule: option.rel_cases) (auto intro: ranI assms(2))\nqed\n\nlemma map_option_arity_comp_conv:\n  assumes \"(\\<And>x. rel_option (rel_fundef R S) (f x) (g x))\"\n  shows \"map_option arity \\<circ> f = map_option arity \\<circ> g\"\nproof (rule map_option_comp_conv)\n  fix x show \"rel_option (rel_fundef R S) (f x) (g x)\"\n    by (rule assms(1))\nnext\n  fix fd1 fd2\n  show \"rel_fundef R S fd1 fd2 \\<Longrightarrow> arity fd1 = arity fd2 \"\n    by (rule rel_fundef_arities)\nqed\n\ndefinition wf_fundef where\n  \"wf_fundef fd \\<longleftrightarrow> body fd \\<noteq> []\"\n\nlemma wf_fundef_non_empty_bodyD[dest,intro]: \"wf_fundef fd \\<Longrightarrow> body fd \\<noteq> []\"\n  by (simp add: wf_fundef_def)\n\ndefinition wf_fundefs where\n  \"wf_fundefs F \\<longleftrightarrow> (\\<forall>f fd. F f = Some fd \\<longrightarrow> wf_fundef fd)\"\n\nlemma wf_fundefsI:\n  assumes \"\\<And>f fd. F f = Some fd \\<Longrightarrow> wf_fundef fd\"\n  shows \"wf_fundefs F\"\n  using assms by (simp add: wf_fundefs_def)\n\nlemma wf_fundefsI':\n  assumes \"\\<And>f. pred_option wf_fundef (F f)\"\n  shows \"wf_fundefs F\"\n  using assms unfolding wf_fundefs_def\n  by (metis option.pred_inject(2))\n\nlemma wf_fundefs_imp_wf_fundef:\n  assumes \"wf_fundefs F\" and \"F f = Some fd\"\n  shows \"wf_fundef fd\"\n  using assms by (simp add: wf_fundefs_def)\n\nhide_fact wf_fundefs_def\n\nsubsection \\<open>Program\\<close>\n\ndatatype ('fenv, 'henv, 'fun) prog =\n  Prog (prog_fundefs: 'fenv) (heap: 'henv) (main_fun: 'fun)\n\ndefinition wf_prog where                \n  \"wf_prog Get p \\<longleftrightarrow> wf_fundefs (Get (prog_fundefs p))\"\n\nsubsection \\<open>Stack frame\\<close>\n\ndatatype ('fun, 'label, 'operand) frame =\n  Frame 'fun 'label (prog_counter: nat) (regs: \"'operand list\") (operand_stack: \"'operand list\")\n\ndefinition instr_at where\n  \"instr_at fd label pc =\n    (case map_of (body fd) label of\n      Some instrs \\<Rightarrow>\n        if pc < length instrs then\n          Some (instrs ! pc)\n        else\n          None\n    | None \\<Rightarrow> None)\"\n\nlemma instr_atD:\n  assumes \"instr_at fd l pc = Some instr\"\n  shows \"\\<exists>instrs. map_of (body fd) l = Some instrs \\<and> pc < length instrs \\<and> instrs ! pc = instr\"\n  using assms\n  by (cases \"map_of (body fd) l\") (auto simp: instr_at_def)\n\nlemma rel_fundef_imp_rel_option_instr_at:\n  assumes \"rel_fundef (=) R fd1 fd2\"\n  shows \"rel_option R (instr_at fd1 l pc) (instr_at fd2 l pc)\"\n  using assms\nproof (cases rule: fundef.rel_cases)\n  case (Fundef bblocks1 _ _ bblocks2 )\n  then show ?thesis\n    by (auto simp: instr_at_def list_all2_lengthD\n        intro: list_all2_nthD2 elim!: option.rel_cases dest!: rel_option_map_of[of _ _ _ l])\nqed\n\ndefinition next_instr where\n  \"next_instr F f label pc \\<equiv> do {\n    fd \\<leftarrow> F f;\n    instr_at fd label pc\n  }\"\n\nlemma next_instr_eq_Some_conv:\n  \"next_instr F f l pc = Some instr \\<longleftrightarrow> (\\<exists>fd. F f = Some fd \\<and> instr_at fd l pc = Some instr)\"\n  by (simp add: next_instr_def bind_eq_Some_conv)\n\nlemma next_instrD:\n  assumes \"next_instr F f l pc = Some instr\"\n  shows \"\\<exists>fd. F f = Some fd \\<and> instr_at fd l pc = Some instr\"\n  using assms unfolding next_instr_def\n  by (cases \"F f\"; simp)\n\nlemma next_instr_pc_lt_length_instrsI:\n  assumes\n    \"next_instr F f l pc = Some instr\" and\n    \"F f = Some fd\" and\n    \"map_of (body fd) l = Some instrs\"\n  shows \"pc < length instrs\"\n  using assms\n  by (auto dest!: next_instrD instr_atD)\n\nlemma next_instr_get_map_ofD:\n  assumes\n    \"next_instr F f l pc = Some instr\" and\n    \"F f = Some fd\" and\n    \"map_of (body fd) l = Some instrs\"\n  shows \"pc < length instrs\" and \"instrs ! pc = instr\"\n  using assms\n  by (auto dest!: next_instrD instr_atD)\n\nlemma next_instr_length_instrs:\n  assumes\n    \"F f = Some fd\" and\n    \"map_of (body fd) label = Some instrs\"\n  shows \"next_instr F f label (length instrs) = None\"\n  by (simp add: assms next_instr_def instr_at_def)\n\nlemma next_instr_take_Suc_conv:\n  assumes \"next_instr F f l pc = Some instr\" and\n    \"F f = Some fd\" and\n    \"map_of (body fd) l = Some instrs\"\n  shows \"take (Suc pc) instrs = take pc instrs @ [instr]\"\n  using assms\n  by (auto simp: take_Suc_conv_app_nth dest!: next_instrD instr_atD)\n\n\nsubsection \\<open>Dynamic state\\<close>\n\ndatatype ('fenv, 'henv, 'frame) state =\n  State (state_fundefs: 'fenv) (heap: 'henv) (callstack: \"'frame list\")\n\ndefinition state_ok where\n  \"state_ok Get s \\<longleftrightarrow> wf_fundefs (Get (state_fundefs s))\"\n\ninductive final for F_get Return where\n  finalI: \"next_instr (F_get F) f l pc = Some Return \\<Longrightarrow>\n    final F_get Return (State F H [Frame f l pc R \\<Sigma>])\"\n\ndefinition allocate_frame where\n  \"allocate_frame f fd args uninitialized \\<equiv>\n    Frame f (fst (hd (body fd))) 0 (args @ replicate (fundef_locals fd) uninitialized) []\"\n\ninductive load for F_get Uninitialized where\n  \"F_get F main = Some fd \\<Longrightarrow> arity fd = 0 \\<Longrightarrow> body fd \\<noteq> [] \\<Longrightarrow>\n  load F_get Uninitialized (Prog F H main) (State F H [allocate_frame main fd [] Uninitialized])\"\n\nlemma length_neq_imp_not_list_all2:\n  assumes \"length xs \\<noteq> length ys\"\n  shows \"\\<not> list_all2 R xs ys\"\nproof (rule notI)\n  assume \"list_all2 R xs ys\"\n  hence \"length xs = length ys\"\n    by (rule list_all2_lengthD)\n  thus False\n    using assms by contradiction\nqed\n\nlemma list_all2_rel_prod_conv:\n  \"list_all2 (rel_prod R S) xs ys \\<longleftrightarrow>\n    list_all2 R (map fst xs) (map fst ys) \\<and> list_all2 S (map snd xs) (map snd ys)\"\nproof (cases \"length xs = length ys\")\n  case True\n  then show ?thesis\n    by (induction xs ys rule: list_induct2) (auto simp: rel_prod_sel)\nnext\n  case False\n  hence neq_length_maps:\n      \"length (map fst xs) \\<noteq> length (map fst ys)\"\n      \"length (map snd xs) \\<noteq> length (map snd ys)\"\n    by simp_all\n  show ?thesis\n    using length_neq_imp_not_list_all2[OF False]\n    using neq_length_maps[THEN length_neq_imp_not_list_all2]\n    by simp\nqed\n\ndefinition rewrite_fundef_body ::\n  \"('label, 'instr) fundef \\<Rightarrow> 'label \\<Rightarrow> nat \\<Rightarrow> 'instr \\<Rightarrow> ('label, 'instr) fundef\" where\n  \"rewrite_fundef_body fd l n instr =\n    (case fd of Fundef bblocks ar ret locals \\<Rightarrow>\n      Fundef (AList.map_entry l (\\<lambda>instrs. instrs[n := instr]) bblocks) ar ret locals)\"\n\nlemma rewrite_fundef_body_cases[case_names invalid_label valid_label]:\n  assumes\n    \"\\<And>bs ar ret locals. fd = Fundef bs ar ret locals \\<Longrightarrow> map_of bs l = None \\<Longrightarrow> P\"\n    \"\\<And>bs ar ret locals instrs. fd = Fundef bs ar ret locals \\<Longrightarrow> map_of bs l = Some instrs \\<Longrightarrow> P\"\n  shows \"P\"\n  using assms\n  by (cases fd; cases \"map_of (body fd) l\") auto\n\nlemma arity_rewrite_fundef_body[simp]: \"arity (rewrite_fundef_body fd l pc instr) = arity fd\"\n  by (cases fd; simp add: rewrite_fundef_body_def option.case_eq_if)\n\nlemma return_rewrite_fundef_body[simp]: \"return (rewrite_fundef_body fd l pc instr) = return fd\"\n  by (cases fd) (simp add: rewrite_fundef_body_def option.case_eq_if)\n\nlemma funtype_rewrite_fundef_body[simp]: \"funtype (rewrite_fundef_body fd l pc instr') = funtype fd\"\n  by (simp add: funtype_def)\n\nlemma length_body_rewrite_fundef_body[simp]:\n  \"length (body (rewrite_fundef_body fd l pc instr)) = length (body fd)\"\n  by (cases fd) (simp add: rewrite_fundef_body_def)\n\nlemma prod_in_set_fst_image_conv: \"(x, y) \\<in> set xys \\<Longrightarrow> x \\<in> fst ` set xys\"\n  by (metis fstI image_eqI)\n\nlemma map_of_body_rewrite_fundef_body_conv_neq[simp]:\n  assumes \"l \\<noteq> l'\"\n  shows \"map_of (body (rewrite_fundef_body fd l pc instr)) l' = map_of (body fd) l'\"\n  using assms\n  by (cases fd) (simp add: rewrite_fundef_body_def map_of_map_entry)\n\nlemma map_of_body_rewrite_fundef_body_conv_eq[simp]:\n  \"map_of (body (rewrite_fundef_body fd l pc instr)) l =\n   map_option (\\<lambda>xs. xs[pc := instr]) (map_of (body fd) l)\"\n  by (cases fd) (simp add: rewrite_fundef_body_def map_of_map_entry map_option_case)\n\nlemma instr_at_rewrite_fundef_body_conv:\n  \"instr_at (rewrite_fundef_body fd l' pc' instr') l pc =\n    map_option (\\<lambda>instr. if l = l' \\<and> pc = pc' then instr' else instr) (instr_at fd l pc)\"\nproof (cases fd)\n  case (Fundef bblocks ar ret locals)\n  then show ?thesis\n  proof (cases \"instr_at fd l pc\")\n    case None\n    then show ?thesis\n      by (cases \"map_of bblocks l\")\n        (auto simp add: Fundef rewrite_fundef_body_def instr_at_def map_of_map_entry)\n  next\n    case (Some instrs)\n    then show ?thesis\n      by (cases \"map_of bblocks l\")\n        (auto simp add: Fundef rewrite_fundef_body_def instr_at_def map_of_map_entry)\n  qed\nqed\n\nlemma fundef_locals_rewrite_fundef_body[simp]:\n  \"fundef_locals (rewrite_fundef_body fd l pc instr) = fundef_locals fd\"\n  by (cases fd; simp add: rewrite_fundef_body_def option.case_eq_if)\n\nlemma rel_fundef_rewrite_body1:\n  assumes\n    rel_fd1_fd2: \"rel_fundef (=) R fd1 fd2\" and\n    instr_at_l_pc: \"instr_at fd1 l pc = Some instr\" and\n    R_iff: \"\\<And>x. R instr x \\<longleftrightarrow> R instr' x\"\n  shows \"rel_fundef (=) R (rewrite_fundef_body fd1 l pc instr') fd2\"\n  using assms(1)\nproof (cases rule: fundef.rel_cases)\n  case (Fundef xs ar' ret' locals' ys ar ret locals)\n  show ?thesis\n    using Fundef(3,3,1,2,4-) instr_at_l_pc\n  proof (induction xs ys arbitrary: fd1 fd2 rule: list.rel_induct)\n    case Nil\n    then show ?case by (simp add: rewrite_fundef_body_def)\n  next\n    case (Cons x xs y ys)\n    then show ?case\n      apply (simp add: rewrite_fundef_body_def)\n      apply safe\n      using assms(3)\n       apply (smt (verit, ccfv_SIG) fun_upd_apply fundef.sel(1) instr_atD list_all2_lengthD\n          list_all2_nthD2 list_all2_update1_cong map_of.simps(2) option.simps(1) prod.sel(1,2)\n          rel_prod_sel)\n      by (simp add: instr_at_def)\n  qed\nqed\n\nlemma rel_fundef_rewrite_body:\n  assumes rel_fd1_fd2: \"rel_fundef (=) R fd1 fd2\" and R_i1_i2: \"R i1 i2\"\n  shows \"rel_fundef (=) R (rewrite_fundef_body fd1 l pc i1) (rewrite_fundef_body fd2 l pc i2)\"\n  using assms(1)\nproof (cases rule: fundef.rel_cases)\n  case (Fundef bblocks1 ar1 ret1 locals1 bblocks2 ar2 ret2 locals2)\n  then show ?thesis\n    using R_i1_i2\n    by (auto simp: rewrite_fundef_body_def\n      intro!: list_all2_update_cong\n      intro!: list_all2_rel_prod_map_entry\n      dest: rel_option_map_of[of _ _ _ l])\nqed\n\nlemma rewrite_fundef_body_triv:\n  \"instr_at fd l pc = Some instr \\<Longrightarrow> rewrite_fundef_body fd l pc instr = fd\"\n  by (cases fd)\n    (auto simp add: rewrite_fundef_body_def map_entry_map_of_Some_conv update_triv dest: instr_atD)\n\nlemma rel_fundef_rewrite_body2:\n  assumes\n    rel_fd1_fd2: \"rel_fundef (=) R fd1 fd2\" and\n    instr_at_l_pc: \"instr_at fd2 l pc = Some instr\" and\n    R_iff: \"\\<And>x. R x instr \\<longleftrightarrow> R x instr'\"\n  shows \"rel_fundef (=) R fd1 (rewrite_fundef_body fd2 l pc instr')\"\n  using assms(1)\nproof (cases rule: fundef.rel_cases)\n  case (Fundef xs ar' ret' locals' ys ar ret locals)\n  moreover obtain instrs2 where\n    \"map_of (body fd2) l = Some instrs2\" and \"pc < length instrs2\" and \"instrs2 ! pc = instr\"\n    using instr_atD[OF instr_at_l_pc] by auto\n  moreover then obtain instrs1 instr1 where\n    \"map_of (body fd1) l = Some instrs1\" and \"pc < length instrs1\" and \"instrs1 ! pc = instr1\"\n    using rel_fundef_imp_rel_option_instr_at[OF rel_fd1_fd2, of l pc]\n    apply (auto simp add: instr_at_def option_rel_Some2)\n    by (metis instr_atD instr_at_def)\n  moreover have \"list_all2 R instrs1 instrs2\"\n    using Fundef \\<open>map_of (body fd2) l = Some instrs2\\<close> \\<open>map_of (body fd1) l = Some instrs1\\<close>\n    by (auto dest: rel_option_map_of[of _ _ _ l])\n  moreover hence \"R (instrs1 ! pc) (instrs2 ! pc)\"\n    using \\<open>pc < length instrs1\\<close>\n    by (auto intro: list_all2_nthD)\n  ultimately show ?thesis\n    by (auto simp: rewrite_fundef_body_def R_iff\n          intro!: list_all2_rel_prod_map_entry2\n          intro: list_all2_update2_cong)\nqed\n\nlemma rel_fundef_rewrite_body2':\n  assumes\n    rel_fd1_fd2: \"rel_fundef (=) R fd1 fd2\" and\n    instr_at1: \"instr_at fd1 l pc = Some instr1\" and\n    R_instr1_instr2: \"R instr1 instr2'\"\n  shows \"rel_fundef (=) R fd1 (rewrite_fundef_body fd2 l pc instr2')\"\n  using assms(1)\nproof (cases rule: fundef.rel_cases)\n  case (Fundef bblocks1 ar1 ret1 locals1 bblocks2 ar2 ret2 locals2)\n  moreover obtain instrs1 where\n    \"map_of bblocks1 l = Some instrs1\" and \"pc < length instrs1\" and \"instrs1 ! pc = instr1\"\n    using Fundef instr_at1[THEN instr_atD] by auto\n\n  moreover then obtain instrs2 instr2 where\n    \"map_of (body fd2) l = Some instrs2\" and \"pc < length instrs2\" and \"instrs2 ! pc = instr2\"\n    using Fundef rel_fd1_fd2\n    apply (auto simp: option_rel_Some1 dest!: rel_option_map_of[where l = l])\n    by (metis list_all2_lengthD)\n  ultimately show ?thesis\n    using R_instr1_instr2\n    by (auto simp: rewrite_fundef_body_def\n          intro!: list_all2_update2_cong list_all2_rel_prod_map_entry2\n          dest: rel_option_map_of[of _ _ _ l])\nqed\n\nthm rel_fundef_rewrite_body\n\nlemma if_eq_const_conv: \"(if x then y else z) = w \\<longleftrightarrow> x \\<and> y = w \\<or> \\<not> x \\<and> z = w\"\n  by simp\n\nlemma const_eq_if_conv: \"w = (if x then y else z) \\<longleftrightarrow> x \\<and> w = y \\<or> \\<not> x \\<and> w = z\"\n  by auto\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Interpreter_Optimizations/Global.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.5813030906443133, "lm_q1q2_score": 0.29292221432329485}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      HoarePartial.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection \\<open>Properties of Total Correctness Hoare Logic\\<close>\n\ntheory HoareTotalProps imports SmallStep HoareTotalDef HoarePartialProps begin\n\nsubsection \\<open>Soundness\\<close>\n\nlemma hoaret_sound: \n assumes hoare: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nusing hoare\nproof (induct)\n  case (Skip \\<Theta> F P A)\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Skip P,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Skip,Normal s\\<rangle> \\<Rightarrow> t\" \"s \\<in> P\"\n    thus \"t \\<in> Normal ` P \\<union> Abrupt ` A\"\n      by cases auto\n  next\n    fix s show \"\\<Gamma>\\<turnstile>Skip \\<down> Normal s\"\n      by (rule terminates.intros)\n  qed\nnext\n  case (Basic \\<Theta> F f P A)\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. f s \\<in> P} (Basic f) P,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Basic f,Normal s\\<rangle> \\<Rightarrow> t\" \"s \\<in> {s. f s \\<in> P}\"\n    thus \"t \\<in> Normal ` P \\<union> Abrupt ` A\"\n      by cases auto\n  next\n    fix s show \"\\<Gamma>\\<turnstile>Basic f \\<down> Normal s\"\n      by (rule terminates.intros)\n  qed\nnext\n  case (Spec \\<Theta> F r Q A)\n  show \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. (\\<forall>t. (s, t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s, t) \\<in> r)} Spec r Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Spec r ,Normal s\\<rangle> \\<Rightarrow> t\" \n           \"s \\<in> {s. (\\<forall>t. (s, t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s, t) \\<in> r)}\"\n    thus \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by cases auto\n  next\n    fix s show \"\\<Gamma>\\<turnstile>Spec r \\<down> Normal s\"\n      by (rule terminates.intros)\n  qed\nnext\n  case (Seq \\<Theta> F P c1 R A c2 Q)\n  have valid_c1: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c1 R,A\" by fact\n  have valid_c2: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c2 Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Seq c1 c2 Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal s\\<rangle> \\<Rightarrow> t\" \n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    from exec P obtain r where\n      exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> r\" and exec_c2:  \"\\<Gamma>\\<turnstile>\\<langle>c2,r\\<rangle> \\<Rightarrow> t\"\n      by cases auto\n    with t_notin_F have \"r \\<notin> Fault ` F\"\n      by (auto dest: Fault_end)\n    from valid_c1 ctxt exec_c1 P this\n    have r: \"r \\<in> Normal ` R \\<union> Abrupt ` A\"\n      by (rule cvalidt_postD)\n    show \"t\\<in>Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases r)\n      case (Normal r')\n      with exec_c2 r\n      show \"t\\<in>Normal ` Q \\<union> Abrupt ` A\"\n        apply -\n        apply (rule cvalidt_postD [OF valid_c2 ctxt _ _ t_notin_F])\n        apply auto\n        done\n    next\n      case (Abrupt r')\n      with exec_c2 have \"t=Abrupt r'\"\n        by (auto elim: exec_elim_cases)\n      with Abrupt r show ?thesis\n        by auto\n    next\n      case Fault with r show ?thesis by blast\n    next\n      case Stuck with r show ?thesis by blast\n    qed\n  next\n    fix s \n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s\\<in>P\"\n    show \"\\<Gamma>\\<turnstile>Seq c1 c2 \\<down> Normal s\"\n    proof -\n      from valid_c1 ctxt P\n      have \"\\<Gamma>\\<turnstile>c1\\<down> Normal s\"\n        by (rule cvalidt_termD)\n      moreover\n      {\n        fix r assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> r\"\n        have \"\\<Gamma>\\<turnstile>c2 \\<down> r\"\n        proof (cases r)\n          case (Normal r')\n          with cvalidt_postD [OF valid_c1 ctxt exec_c1 P]\n          have r: \"r\\<in>Normal ` R\"\n            by auto\n          with cvalidt_termD [OF valid_c2 ctxt] exec_c1\n          show \"\\<Gamma>\\<turnstile>c2 \\<down> r\"\n            by auto\n        qed auto        \n      }\n      ultimately show ?thesis\n        by (iprover intro: terminates.intros)\n    qed\n  qed\nnext\n  case (Cond \\<Theta> F P b c1 Q A c2)\n  have valid_c1: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> b) c1 Q,A\" by fact\n  have valid_c2: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> - b) c2 Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Cond b c1 c2 Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow> t\"\n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases \"s\\<in>b\")\n      case True\n      with exec have \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> t\"\n        by cases auto\n      with P True \n      show ?thesis\n        by - (rule cvalidt_postD [OF valid_c1 ctxt _ _ t_notin_F],auto)\n    next\n      case False\n      with exec P have \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal s\\<rangle> \\<Rightarrow> t\"\n        by cases auto\n      with P False \n      show ?thesis\n        by - (rule cvalidt_postD [OF valid_c2 ctxt _ _ t_notin_F],auto)\n    qed\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s \\<in> P\"\n    thus \"\\<Gamma>\\<turnstile>Cond b c1 c2 \\<down> Normal s\"\n      using cvalidt_termD [OF valid_c1 ctxt] cvalidt_termD [OF valid_c2 ctxt]\n      by (cases \"s \\<in> b\") (auto intro: terminates.intros)\n  qed\nnext\n  case (While r \\<Theta> F P b c A)\n  assume wf: \"wf r\"\n  have valid_c: \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P \\<inter> b) c ({t. (t, \\<sigma>) \\<in> r} \\<inter> P),A\"\n    using While.hyps by iprover\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (While b c) (P \\<inter> - b),A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume wprems: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow> t\" \"s \\<in> P\" \"t \\<notin> Fault ` F\"\n    from wf\n    have \"\\<And>t. \\<lbrakk>\\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow> t; s \\<in> P; t \\<notin> Fault ` F\\<rbrakk> \n                 \\<Longrightarrow> t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\"\n    proof (induct)\n      fix s t\n      assume hyp: \n        \"\\<And>s' t. \\<lbrakk>(s',s)\\<in>r; \\<Gamma>\\<turnstile>\\<langle>While b c,Normal s'\\<rangle> \\<Rightarrow> t; s' \\<in> P; t \\<notin> Fault ` F\\<rbrakk>\n                 \\<Longrightarrow> t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\"\n      assume exec: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow> t\"\n      assume P: \"s \\<in> P\"\n      assume t_notin_F: \"t \\<notin> Fault ` F\"\n      from exec\n      show \"t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\"\n      proof (cases)\n        fix s'\n        assume b: \"s\\<in>b\"\n        assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> s'\" \n        assume exec_w: \"\\<Gamma>\\<turnstile>\\<langle>While b c,s'\\<rangle> \\<Rightarrow> t\"\n        from exec_w t_notin_F have \"s' \\<notin> Fault ` F\"\n          by (auto dest: Fault_end)\n        from exec_c P b valid_c ctxt this\n        have s': \"s' \\<in> Normal ` ({s'. (s', s) \\<in> r} \\<inter> P) \\<union> Abrupt ` A\"\n          by (auto simp add: cvalidt_def validt_def valid_def)\n        show ?thesis\n        proof (cases s')\n          case Normal \n          with exec_w s' t_notin_F\n          show ?thesis\n            by - (rule hyp,auto)\n        next\n          case Abrupt\n          with exec_w have \"t=s'\"\n            by (auto dest: Abrupt_end)\n          with Abrupt s' show ?thesis\n            by blast\n        next\n          case Fault\n          with exec_w have \"t=s'\"\n            by (auto dest: Fault_end)\n          with Fault s' show ?thesis\n            by blast\n        next\n          case Stuck\n          with exec_w have \"t=s'\"\n            by (auto dest: Stuck_end)\n          with Stuck s' show ?thesis\n            by blast\n        qed\n      next\n        assume \"s\\<notin>b\" \"t=Normal s\" with P show ?thesis by simp\n      qed\n    qed\n    with wprems show \"t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\" by blast\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume \"s \\<in> P\"\n    with wf \n    show \"\\<Gamma>\\<turnstile>While b c \\<down> Normal s\"\n    proof (induct)\n      fix s\n      assume hyp: \"\\<And>s'. \\<lbrakk>(s',s)\\<in>r; s' \\<in> P\\<rbrakk> \n                         \\<Longrightarrow> \\<Gamma>\\<turnstile>While b c \\<down> Normal s'\"\n      assume P: \"s \\<in> P\"\n      show \"\\<Gamma>\\<turnstile>While b c \\<down> Normal s\"\n      proof (cases \"s \\<in> b\")\n        case False with P show ?thesis\n          by (blast intro: terminates.intros)\n      next\n        case True\n        with valid_c P ctxt\n        have \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n          by (simp add: cvalidt_def validt_def)\n        moreover\n        {\n          fix s'\n          assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> s'\"\n          have \"\\<Gamma>\\<turnstile>While b c \\<down> s'\"\n          proof (cases s')\n            case (Normal s'')\n            with exec_c P True valid_c ctxt\n            have s': \"s' \\<in> Normal ` ({s'. (s', s) \\<in> r} \\<inter> P)\"\n              by (fastforce simp add: cvalidt_def validt_def valid_def)\n            then show ?thesis\n              by (blast intro: hyp)\n          qed auto\n        }\n        ultimately\n        show ?thesis\n          by (blast intro: terminates.intros)\n      qed\n    qed\n  qed\nnext\n  case (Guard \\<Theta> F g P c Q A  f)\n  have valid_c: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) Guard f g c Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow> t\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    assume P:\"s \\<in> (g \\<inter> P)\"\n    from exec P have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by cases auto\n    from valid_c ctxt this P t_notin_F\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by (rule cvalidt_postD)\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P:\"s \\<in> (g \\<inter> P)\"\n    thus \"\\<Gamma>\\<turnstile>Guard f g c  \\<down> Normal s\"\n      by (auto intro: terminates.intros cvalidt_termD [OF valid_c ctxt])\n  qed\nnext\n  case (Guarantee f F \\<Theta> g P c Q A)\n  have valid_c: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\" by fact\n  have f_F: \"f \\<in> F\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Guard f g c Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow> t\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    assume P:\"s \\<in> P\"\n    from exec f_F t_notin_F have g: \"s \\<in> g\"\n      by cases auto\n    with P have P': \"s \\<in> g \\<inter> P\"\n      by blast\n    from exec g have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by cases auto\n    from valid_c ctxt this P' t_notin_F\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by (rule cvalidt_postD)\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P:\"s \\<in> P\"\n    thus \"\\<Gamma>\\<turnstile>Guard f g c  \\<down> Normal s\"\n      by (auto intro: terminates.intros cvalidt_termD [OF valid_c ctxt])\n  qed\nnext\n  case (CallRec P p Q A Specs r Specs_wf \\<Theta>  F)\n  have p: \"(P,p,Q,A) \\<in> Specs\"  by fact\n  have wf: \"wf r\" by fact\n  have Specs_wf: \n    \"Specs_wf = (\\<lambda>p \\<tau>. (\\<lambda>(P,q,Q,A). (P \\<inter> {s. ((s, q),\\<tau>,p) \\<in> r},q,Q,A)) ` Specs)\" by fact\n  from CallRec.hyps\n  have valid_body: \n    \"\\<forall>(P, p, Q, A)\\<in>Specs. p \\<in> dom \\<Gamma> \\<and>\n        (\\<forall>\\<tau>. \\<Gamma>,\\<Theta> \\<union> Specs_wf p \\<tau>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) the (\\<Gamma> p) Q,A)\" by auto\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  proof -\n    {\n      fix \\<tau>p \n      assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n      from wf\n      have \"\\<And>\\<tau> p P Q A.  \\<lbrakk>\\<tau>p = (\\<tau>,p); (P,p,Q,A) \\<in> Specs\\<rbrakk> \\<Longrightarrow> \n                  \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> (p))) Q,A\"    \n      proof (induct \\<tau>p rule: wf_induct [rule_format, consumes 1, case_names WF])\n        case (WF \\<tau>p \\<tau> p P Q A)\n        have \\<tau>p: \"\\<tau>p = (\\<tau>, p)\" by fact\n        have p: \"(P, p, Q, A) \\<in> Specs\" by fact\n        {\n          fix q P' Q' A'\n          assume q: \"(P',q,Q',A') \\<in> Specs\"\n          have \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' \\<inter> {s. ((s,q), \\<tau>,p) \\<in> r}) (Call q) Q',A'\"\n          proof (rule validtI)\n            fix s t\n            assume exec_q: \n              \"\\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow> t\"\n            assume Pre: \"s \\<in> P' \\<inter> {s. ((s,q), \\<tau>,p) \\<in> r}\"\n            assume t_notin_F: \"t \\<notin> Fault ` F\"\n            from Pre q \\<tau>p\n            have valid_bdy: \n              \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s} \\<inter> P') the (\\<Gamma> q) Q',A'\"\n              by - (rule WF.hyps, auto)\n            from Pre q\n            have Pre': \"s \\<in> {s} \\<inter> P'\"\n              by auto\n            from exec_q show \"t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n            proof (cases)\n              fix bdy \n              assume bdy: \"\\<Gamma> q = Some bdy\"\n              assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal s\\<rangle> \\<Rightarrow> t\"\n              from valid_bdy [simplified bdy option.sel]  t_notin_F exec_bdy Pre'\n              have \"t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n                by (auto simp add: validt_def valid_def)\n              with Pre q \n              show ?thesis\n                by auto\n            next\n              assume \"\\<Gamma> q = None\"\n              with q valid_body have False by auto\n              thus ?thesis ..\n            qed\n          next\n            fix s\n            assume Pre: \"s \\<in> P' \\<inter> {s. ((s,q), \\<tau>,p) \\<in> r}\"\n            from Pre q \\<tau>p\n            have valid_bdy: \n              \"\\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s} \\<inter> P') (the (\\<Gamma> q)) Q',A'\"\n              by - (rule WF.hyps, auto)\n            from Pre q\n            have Pre': \"s \\<in> {s} \\<inter> P'\"\n              by auto\n            from valid_bdy ctxt Pre'\n            have \"\\<Gamma>\\<turnstile>the (\\<Gamma> q) \\<down> Normal s\"\n              by (auto simp add: validt_def)\n            with valid_body q \n            show \"\\<Gamma>\\<turnstile>Call q\\<down> Normal s\"\n              by (fastforce intro: terminates.Call)\n          qed\n        }\n        hence \"\\<forall>(P, p, Q, A)\\<in>Specs_wf p \\<tau>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Call p Q,A\"\n          by (auto simp add: cvalidt_def Specs_wf)\n        with ctxt have \"\\<forall>(P, p, Q, A)\\<in>\\<Theta> \\<union> Specs_wf p \\<tau>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Call p Q,A\"\n          by auto\n        with p valid_body \n        show \"\\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> p)) Q,A\"\n          by (simp add: cvalidt_def) blast\n      qed\n    }\n    note lem = this\n    have valid_body': \n      \"\\<And>\\<tau>. \\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A \\<Longrightarrow> \n      \\<forall>(P,p,Q,A)\\<in>Specs. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> p)) Q,A\"\n      by (auto intro: lem)\n    show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    proof (rule cvalidtI)\n      fix s t\n      assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n      assume exec_call: \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow> t\"\n      assume P: \"s \\<in> P\"\n      assume t_notin_F: \"t \\<notin> Fault ` F\"\n      from exec_call show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      proof (cases)\n        fix bdy \n        assume bdy: \"\\<Gamma> p = Some bdy\"\n        assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal s\\<rangle> \\<Rightarrow> t\"\n        from exec_body bdy p P t_notin_F \n          valid_body' [of \"s\", OF ctxt] \n          ctxt\n        have \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n          apply (simp only: cvalidt_def validt_def valid_def) \n          apply (drule (1) bspec)\n          apply auto\n          done\n        with p P \n        show ?thesis\n          by simp\n      next\n        assume \"\\<Gamma> p = None\"\n        with p valid_body have False by auto\n        thus ?thesis by simp\n      qed\n    next\n      fix s\n      assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n      assume P: \"s \\<in> P\"\n      show \"\\<Gamma>\\<turnstile>Call p \\<down> Normal s\"\n      proof -\n        from ctxt P p valid_body' [of \"s\",OF ctxt]\n        have \"\\<Gamma>\\<turnstile>(the (\\<Gamma> p)) \\<down> Normal s\"\n          by (auto simp add: cvalidt_def validt_def)\n        with valid_body p show ?thesis\n          by (fastforce intro: terminates.Call)\n      qed\n    qed\n  qed\nnext\n  case (DynCom P \\<Theta> F c Q A)\n  hence valid_c: \"\\<forall>s\\<in>P. \\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (c s) Q,A\" by simp\n  show \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P DynCom c Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal s\\<rangle> \\<Rightarrow> t\" \n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    from exec show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases)\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c s,Normal s\\<rangle> \\<Rightarrow> t\"      \n      from cvalidt_postD [OF valid_c [rule_format, OF P] ctxt this P t_notin_F]\n      show ?thesis .\n    qed\n  next\n    fix s \n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s \\<in> P\"\n    show \"\\<Gamma>\\<turnstile>DynCom c \\<down> Normal s\"\n    proof -\n      from cvalidt_termD [OF valid_c [rule_format, OF P] ctxt P]\n      have \"\\<Gamma>\\<turnstile>c s \\<down> Normal s\" .\n      thus ?thesis\n        by (rule terminates.intros)\n    qed\n  qed\nnext\n  case (Throw \\<Theta> F A Q)\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> A Throw Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Throw,Normal s\\<rangle> \\<Rightarrow> t\" \"s \\<in> A\"\n    then show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by cases simp\n  next\n    fix s\n    show \"\\<Gamma>\\<turnstile>Throw \\<down> Normal s\"\n      by (rule terminates.intros)\n  qed\nnext\n  case (Catch \\<Theta> F P c\\<^sub>1 Q R c\\<^sub>2 A)\n  have valid_c1: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,R\" by fact\n  have valid_c2: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Catch c\\<^sub>1 c\\<^sub>2 Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow> t\" \n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    from exec show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases)\n      fix s'\n      assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Abrupt s'\" \n      assume exec_c2: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s'\\<rangle> \\<Rightarrow> t\"\n      from cvalidt_postD [OF valid_c1 ctxt exec_c1 P]\n      have \"Abrupt s' \\<in> Abrupt ` R\"\n        by auto\n      with cvalidt_postD [OF valid_c2 ctxt] exec_c2 t_notin_F\n      show ?thesis\n        by fastforce\n    next\n      assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t\" \n      assume notAbr: \"\\<not> isAbr t\"\n      from cvalidt_postD [OF valid_c1 ctxt exec_c1 P] t_notin_F\n      have \"t \\<in> Normal ` Q \\<union> Abrupt ` R\" .\n      with notAbr\n      show ?thesis\n        by auto\n    qed\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s \\<in> P\"\n    show \"\\<Gamma>\\<turnstile>Catch c\\<^sub>1 c\\<^sub>2 \\<down> Normal s\"  \n    proof -\n      from valid_c1 ctxt P\n      have \"\\<Gamma>\\<turnstile>c\\<^sub>1\\<down> Normal s\"\n        by (rule cvalidt_termD)\n      moreover\n      {\n        fix r assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Abrupt r\"\n        from cvalidt_postD [OF valid_c1 ctxt exec_c1 P]\n        have r: \"Abrupt r\\<in>Normal ` Q \\<union> Abrupt ` R\"\n          by auto\n        hence \"Abrupt r\\<in>Abrupt ` R\" by fast\n        with cvalidt_termD [OF valid_c2 ctxt] exec_c1\n        have \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal r\"\n          by fast\n      }\n      ultimately show ?thesis\n        by (iprover intro: terminates.intros)\n    qed\n  qed\nnext\n  case (Conseq P \\<Theta> F c Q A)\n  hence adapt: \n    \"\\<forall>s \\<in> P. (\\<exists>P' Q' A'. (\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A') \\<and> s \\<in> P'\\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A)\" by blast\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof -\n      from adapt [rule_format, OF P]\n      obtain P' and Q' and A' where \n        valid_P'_Q': \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A'\"\n        and weaken: \"s \\<in> P'\" \"Q' \\<subseteq>  Q\" \"A'\\<subseteq> A\"\n        by blast\n      from exec valid_P'_Q' ctxt t_notin_F\n      have P'_Q': \"Normal s \\<in> Normal ` P' \\<longrightarrow> \n        t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n        by (unfold cvalidt_def validt_def valid_def) blast\n      hence \"s \\<in> P' \\<longrightarrow> t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n        by blast\n      with weaken \n      show ?thesis\n        by blast\n    qed\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s \\<in> P\"\n    show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    proof -\n      from P adapt\n      obtain P' and Q' and  A' where \n        \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A'\"\n        \"s \\<in> P'\"\n        by blast\n      with ctxt\n      show ?thesis\n        by (simp add: cvalidt_def validt_def)\n    qed\n  qed\nnext\n  case (Asm P p Q A \\<Theta> F)\n  assume \"(P, p, Q, A) \\<in> \\<Theta>\"\n  then show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (auto simp add: cvalidt_def )\nnext\n  case ExFalso thus ?case by iprover\nqed\n\nlemma hoaret_sound':\n\"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (drule hoaret_sound)\n  apply (simp add: cvalidt_def)\n  done\n\ntheorem total_to_partial: \n assumes total: \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" shows \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from total have \"\\<Gamma>,{}\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (rule hoaret_sound)\n  hence \"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (simp add: cvalidt_def validt_def cvalid_def)\n  thus ?thesis\n    by (rule hoare_complete)\nqed\n\nsubsection \\<open>Completeness\\<close>\n\nlemma MGT_valid:\n\"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \\<Gamma>\\<turnstile>c\\<down>Normal s} c \n    {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t}, {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\nproof (rule validtI) \n  fix s t\n  assume \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n         \"s \\<in> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \\<Gamma>\\<turnstile>c\\<down>Normal s}\"\n         \"t \\<notin> Fault ` F\"\n  thus \"t \\<in> Normal ` {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t} \\<union> \n            Abrupt ` {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    apply (cases t) \n    apply (auto simp add: final_notin_def)\n    done\nnext\n  fix s\n  assume \"s \\<in> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \\<Gamma>\\<turnstile>c\\<down>Normal s}\"\n  thus \"\\<Gamma>\\<turnstile>c\\<down>Normal s\"\n    by blast\nqed\n\ntext \\<open>The consequence rule where the existential @{term Z} is instantiated\nto @{term s}. Usefull in proof of \\<open>MGT_lemma\\<close>.\\<close>\nlemma ConseqMGT: \n  assumes modif: \"\\<forall>Z::'a. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z::'a assn) c (Q' Z),(A' Z)\"\n  assumes impl: \"\\<And>s. s \\<in> P \\<Longrightarrow> s \\<in> P' s \\<and> (\\<forall>t. t \\<in> Q' s \\<longrightarrow> t \\<in> Q) \\<and> \n                                            (\\<forall>t. t \\<in> A' s \\<longrightarrow> t \\<in> A)\"\n  shows \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nusing impl \nby - (rule conseq [OF modif],blast)\n\nlemma MGT_implies_complete:\n  assumes MGT: \"\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                                 \\<Gamma>\\<turnstile>c\\<down>Normal s}\n                              c \n                            {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                            {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  assumes valid: \"\\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" \n  shows \"\\<Gamma>,{} \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  using MGT\n  apply (rule ConseqMGT) \n  apply (insert valid)\n  apply (auto simp add: validt_def valid_def intro!: final_notinI)\n  done\n\nlemma conseq_extract_state_indep_prop: \n  assumes state_indep_prop:\"\\<forall>s \\<in> P. R\" \n  assumes to_show: \"R \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule Conseq)\n  apply (clarify)\n  apply (rule_tac x=\"P\" in exI)\n  apply (rule_tac x=\"Q\" in exI)\n  apply (rule_tac x=\"A\" in exI)\n  using state_indep_prop to_show\n  by blast\n\nlemma MGT_lemma:\n  assumes MGT_Calls: \n    \"\\<forall>p \\<in> dom \\<Gamma>. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> \n       {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n           \\<Gamma>\\<turnstile>(Call p)\\<down>Normal s}\n             (Call p)\n       {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n       {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  shows \"\\<And>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                          \\<Gamma>\\<turnstile>c\\<down>Normal s} \n               c \n             {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\nproof (induct c)\n  case Skip\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Skip,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                   \\<Gamma>\\<turnstile>Skip \\<down> Normal s} \n               Skip\n            {t. \\<Gamma>\\<turnstile>\\<langle>Skip,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>Skip,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoaret.Skip [THEN conseqPre])\n       (auto elim: exec_elim_cases simp add: final_notin_def \n             intro: exec.intros terminates.intros)\nnext\n  case (Basic f)\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Basic f,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                 \\<Gamma>\\<turnstile>Basic f \\<down> Normal s} \n                Basic f\n              {t. \\<Gamma>\\<turnstile>\\<langle>Basic f,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Basic f,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoaret.Basic [THEN conseqPre]) \n       (auto elim: exec_elim_cases simp add: final_notin_def \n             intro: exec.intros terminates.intros)\nnext\n  case (Spec r)\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Spec r,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Spec r \\<down> Normal s} \n                Spec r\n              {t. \\<Gamma>\\<turnstile>\\<langle>Spec r,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Spec r,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    apply (rule hoaret.Spec [THEN conseqPre])\n    apply (clarsimp simp add: final_notin_def)\n    apply (case_tac \"\\<exists>t. (Z,t) \\<in> r\")\n    apply (auto elim: exec_elim_cases simp add: final_notin_def intro: exec.intros)\n    done\nnext\n  case (Seq c1 c2) \n  have hyp_c1: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                                \\<Gamma>\\<turnstile>c1\\<down>Normal s}\n                            c1 \n                           {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                           {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" \n    using Seq.hyps by iprover\n  have hyp_c2: \"\\<forall> Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                                 \\<Gamma>\\<turnstile>c2\\<down>Normal s}\n                              c2 \n                            {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                            {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" \n    using Seq.hyps by iprover\n  from hyp_c1 \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                \\<Gamma>\\<turnstile>Seq c1 c2\\<down>Normal s} c1 \n    {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t \\<and> \\<Gamma>\\<turnstile>\\<langle>c2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n        \\<Gamma>\\<turnstile>c2\\<down>Normal t},\n    {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT)\n       (auto dest: Seq_NoFaultStuckD1 [simplified] Seq_NoFaultStuckD2 [simplified]\n             elim: terminates_Normal_elim_cases \n             intro: exec.intros)\n  thus \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                 \\<Gamma>\\<turnstile>Seq c1 c2\\<down>Normal s} \n                Seq c1 c2\n              {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  proof (rule hoaret.Seq )\n    show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t \\<and>\n                    \\<Gamma>\\<turnstile>\\<langle>c2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \\<Gamma>\\<turnstile>c2 \\<down> Normal t}\n                 c2 \n                {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    proof (rule ConseqMGT [OF hyp_c2],safe)\n      fix r t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal r\" \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal r\\<rangle> \\<Rightarrow> Normal t\"\n      then show \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n        by (rule exec.intros)\n    next\n      fix r t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal r\" \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal r\\<rangle> \\<Rightarrow> Abrupt t\"\n      then show \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n        by (rule exec.intros)\n    qed\n  qed\nnext\n  case (Cond b c1 c2) \n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                         \\<Gamma>\\<turnstile>c1\\<down>Normal s} \n                     c1 \n                   {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                   {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" \n    using Cond.hyps by iprover  \n  hence \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                     \\<Gamma>\\<turnstile>(Cond b c1 c2)\\<down>Normal s}\\<inter>b) \n                c1 \n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"  \n    by (rule ConseqMGT)\n       (fastforce simp add: final_notin_def intro: exec.CondTrue \n                 elim: terminates_Normal_elim_cases)\n  moreover\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                               \\<Gamma>\\<turnstile>c2\\<down>Normal s} \n                      c2 \n                    {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                    {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"  \n    using Cond.hyps by iprover  \n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>(Cond b c1 c2)\\<down>Normal s}\\<inter>-b) \n                c2 \n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" \n    by (rule ConseqMGT)\n       (fastforce simp add: final_notin_def intro: exec.CondFalse \n                 elim: terminates_Normal_elim_cases)\n  ultimately\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n               \\<Gamma>\\<turnstile>(Cond b c1 c2)\\<down>Normal s} \n               (Cond b c1 c2)\n              {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoaret.Cond)       \nnext\n  case (While b c)\n  let ?unroll = \"({(s,t). s\\<in>b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t})\\<^sup>*\"\n  let ?P' = \"\\<lambda>Z. {t. (Z,t)\\<in>?unroll \\<and> \n                    (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                         \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                             (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)) \\<and>\n                    \\<Gamma>\\<turnstile>(While b c)\\<down>Normal t}\"\n  let ?A = \"\\<lambda>Z. {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  let ?r = \"{(t,s). \\<Gamma>\\<turnstile>(While b c)\\<down>Normal s \\<and> s\\<in>b \\<and> \n                    \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t}\"\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>  \n                  \\<Gamma>\\<turnstile>(While b c)\\<down>Normal s} \n              (While b c)\n              {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  proof (rule ConseqMGT [where ?P'=\"\\<lambda> Z. ?P' Z\" \n                         and ?Q'=\"\\<lambda> Z. ?P' Z \\<inter> - b\"])\n    have wf_r: \"wf ?r\" by (rule wf_terminates_while)\n    show \"\\<forall> Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (?P' Z) (While b c) (?P' Z \\<inter> - b),(?A Z)\"\n    proof (rule allI, rule hoaret.While [OF wf_r])\n      fix Z\n      from While \n      have hyp_c: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                                  \\<Gamma>\\<turnstile>c\\<down>Normal s}\n                                c\n                              {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                              {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" by iprover\n      show \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> ?P' Z  \\<inter> b) c \n                       ({t. (t, \\<sigma>) \\<in> ?r} \\<inter> ?P' Z),(?A Z)\"\n      proof (rule allI, rule ConseqMGT [OF hyp_c])\n        fix \\<sigma> s\n        assume  \"s\\<in> {\\<sigma>} \\<inter>  \n                   {t. (Z, t) \\<in> ?unroll \\<and> \n                      (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                           \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                               (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                                    \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)) \\<and>\n                      \\<Gamma>\\<turnstile>(While b c)\\<down>Normal t}\n                   \\<inter> b\"\n        then obtain \n          s_eq_\\<sigma>: \"s=\\<sigma>\" and\n          Z_s_unroll: \"(Z,s) \\<in> ?unroll\" and\n          noabort:\"\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                        \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                            (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)\" and\n          while_term:  \"\\<Gamma>\\<turnstile>(While b c)\\<down>Normal s\" and\n          s_in_b: \"s\\<in>b\" \n          by blast\n        show \"s \\<in> {t. t = s \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                       \\<Gamma>\\<turnstile>c\\<down>Normal t} \\<and>\n        (\\<forall>t. t \\<in> {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t} \\<longrightarrow>\n             t \\<in> {t. (t,\\<sigma>) \\<in> ?r} \\<inter>  \n                 {t. (Z, t) \\<in> ?unroll \\<and> \n                     (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow>  e\\<in>b \n                           \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                              (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)) \\<and> \n                      \\<Gamma>\\<turnstile>(While b c)\\<down>Normal t})  \\<and> \n         (\\<forall>t. t \\<in> {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Abrupt t} \\<longrightarrow>\n             t \\<in> {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})\"\n          (is \"?C1 \\<and> ?C2 \\<and> ?C3\")\n        proof (intro conjI)\n          from Z_s_unroll noabort s_in_b while_term show ?C1 \n            by (blast elim: terminates_Normal_elim_cases)\n        next\n          {\n            fix t \n            assume s_t: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t\"\n            with s_eq_\\<sigma> while_term s_in_b have \"(t,\\<sigma>) \\<in> ?r\"\n              by blast\n            moreover\n            from Z_s_unroll s_t s_in_b \n            have \"(Z, t) \\<in> ?unroll\"\n              by (blast intro: rtrancl_into_rtrancl)\n            moreover from while_term s_t s_in_b \n            have \"\\<Gamma>\\<turnstile>(While b c)\\<down>Normal t\"\n              by (blast elim: terminates_Normal_elim_cases)\n            moreover note noabort\n            ultimately \n            have \"(t,\\<sigma>) \\<in> ?r \\<and> (Z, t) \\<in> ?unroll \\<and> \n                  (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                        \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                            (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)) \\<and>\n                  \\<Gamma>\\<turnstile>(While b c)\\<down>Normal t\"\n              by iprover\n          }\n          then show ?C2 by blast\n        next\n          {\n            fix t\n            assume s_t:  \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Abrupt t\" \n            from Z_s_unroll noabort s_t s_in_b\n            have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n              by blast\n          } thus ?C3 by simp\n        qed\n      qed\n    qed\n  next\n    fix s\n    assume P: \"s \\<in> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                       \\<Gamma>\\<turnstile>While b c \\<down> Normal s}\"\n    hence WhileNoFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n      by auto\n    show \"s \\<in> ?P' s \\<and> \n     (\\<forall>t. t\\<in>(?P' s \\<inter> - b)\\<longrightarrow>\n          t\\<in>{t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t})\\<and>\n     (\\<forall>t. t\\<in>?A s \\<longrightarrow> t\\<in>?A Z)\"\n    proof (intro conjI)\n      {\n        fix e\n        assume \"(Z,e) \\<in> ?unroll\" \"e \\<in> b\"\n        from this WhileNoFault\n        have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n               (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)\" (is \"?Prop Z e\")\n        proof (induct rule: converse_rtrancl_induct [consumes 1])\n          assume e_in_b: \"e \\<in> b\"\n          assume WhileNoFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n          with e_in_b WhileNoFault\n          have cNoFault: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n            by (auto simp add: final_notin_def intro: exec.intros)\n          moreover\n          {\n            fix u assume \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow> Abrupt u\"\n            with e_in_b have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal e\\<rangle> \\<Rightarrow> Abrupt u\"\n              by (blast intro: exec.intros)\n          }\n          ultimately\n          show \"?Prop e e\"\n            by iprover\n        next\n          fix Z r\n          assume e_in_b: \"e\\<in>b\" \n          assume WhileNoFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n          assume hyp: \"\\<lbrakk>e\\<in>b;\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\\<rbrakk>\n                       \\<Longrightarrow> ?Prop r e\"\n          assume Z_r:\n            \"(Z, r) \\<in> {(Z, r). Z \\<in> b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal r}\"\n          with WhileNoFault\n          have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n            by (auto simp add: final_notin_def intro: exec.intros)\n          from hyp [OF e_in_b this] obtain\n            cNoFault: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\" and\n            Abrupt_r: \"\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow> Abrupt u \\<longrightarrow> \n                            \\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow> Abrupt u\"\n            by simp\n          \n           {\n            fix u assume \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow> Abrupt u\"\n            with Abrupt_r have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow> Abrupt u\" by simp\n            moreover from  Z_r obtain\n              \"Z \\<in> b\"  \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal r\"\n              by simp\n            ultimately have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u\"\n              by (blast intro: exec.intros)\n          }\n          with cNoFault show \"?Prop Z e\"\n            by iprover\n        qed\n      }\n      with P show \"s \\<in> ?P' s\"\n        by blast\n    next\n      {\n        fix t\n        assume \"termination\": \"t \\<notin> b\"\n        assume \"(Z, t) \\<in> ?unroll\"\n        hence \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n        proof (induct rule: converse_rtrancl_induct [consumes 1])\n          from \"termination\" \n          show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal t\\<rangle> \\<Rightarrow> Normal t\"\n            by (blast intro: exec.WhileFalse)\n        next\n          fix Z r\n          assume first_body: \n                 \"(Z, r) \\<in> {(s, t). s \\<in> b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t}\"\n          assume \"(r, t) \\<in> ?unroll\"\n          assume rest_loop: \"\\<Gamma>\\<turnstile>\\<langle>While b c, Normal r\\<rangle> \\<Rightarrow> Normal t\"\n          show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n          proof -\n            from first_body obtain\n              \"Z \\<in> b\" \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal r\"\n              by fast\n            moreover\n            from rest_loop have\n              \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow> Normal t\"\n              by fast\n            ultimately show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n              by (rule exec.WhileTrue)\n          qed\n        qed\n      }\n      with P\n      show \"(\\<forall>t. t\\<in>(?P' s \\<inter> - b)\n            \\<longrightarrow>t\\<in>{t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t})\"\n        by blast\n    next\n      from P show \"\\<forall>t. t\\<in>?A s \\<longrightarrow> t\\<in>?A Z\"\n        by simp\n    qed\n  qed\nnext\n  case (Call p)\n  from noStuck_Call\n  have \"\\<forall>s \\<in> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                         \\<Gamma>\\<turnstile>Call p\\<down> Normal s}.\n          p \\<in> dom \\<Gamma>\"\n    by (fastforce simp add: final_notin_def)\n  then show ?case\n  proof (rule conseq_extract_state_indep_prop)\n    assume p_defined: \"p \\<in> dom \\<Gamma>\"\n    with MGT_Calls show\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s=Z \\<and> \n                 \\<Gamma>\\<turnstile>\\<langle>Call p ,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\\<and>\n                 \\<Gamma>\\<turnstile>Call  p\\<down>Normal s}\n                (Call p)\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      by (auto)\n  qed\nnext\n  case (DynCom c)\n  have hyp: \n    \"\\<And>s'. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c s',Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                       \\<Gamma>\\<turnstile>c s'\\<down>Normal s} c s'\n      {t. \\<Gamma>\\<turnstile>\\<langle>c s',Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c s',Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using DynCom by simp\n  have hyp':\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n            \\<Gamma>\\<turnstile>DynCom c\\<down>Normal s} \n         (c Z)\n        {t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT [OF hyp]) \n       (fastforce simp add: final_notin_def intro: exec.intros \n          elim: terminates_Normal_elim_cases)\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                 \\<Gamma>\\<turnstile>DynCom c\\<down>Normal s}\n                DynCom c\n             {t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    apply (rule hoaret.DynCom)\n    apply (clarsimp)\n    apply (rule hyp' [simplified])\n    done\nnext\n  case (Guard f g c)\n  have hyp_c: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                              \\<Gamma>\\<turnstile>c\\<down>Normal s} \n                     c \n                   {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                   {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Guard by iprover\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Guard f g c\\<down> Normal s} \n                Guard f g c \n              {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  proof (cases \"f \\<in> F\")\n    case True\n    from hyp_c\n    have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>(g \\<inter> {s. s=Z \\<and> \n                     \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck}\\<union> Fault ` (-F))\\<and>\n                     \\<Gamma>\\<turnstile>Guard f g c\\<down> Normal s})\n                   c\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      apply (rule ConseqMGT)\n      apply (insert True)\n      apply  (auto simp add: final_notin_def intro: exec.intros \n                   elim: terminates_Normal_elim_cases)\n      done\n    from True this\n    show ?thesis\n      by (rule conseqPre [OF Guarantee]) auto\n  next\n    case False\n    from hyp_c\n    have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>(g \\<inter> {s. s \\<in> g \\<and> s=Z \\<and> \n                     \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck}\\<union> Fault ` (-F))\\<and>\n                     \\<Gamma>\\<turnstile>Guard f g c\\<down> Normal s} )\n                   c\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      apply (rule ConseqMGT)\n      apply clarify\n      apply (frule Guard_noFaultStuckD [OF _ False])\n      apply  (auto simp add: final_notin_def intro: exec.intros \n                   elim: terminates_Normal_elim_cases)\n      done\n    then show ?thesis\n      apply (rule conseqPre [OF hoaret.Guard])\n      apply clarify\n      apply (frule Guard_noFaultStuckD [OF _ False])\n      apply auto\n      done\n  qed\nnext\n  case Throw\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Throw,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Throw \\<down> Normal s}\n              Throw\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule conseqPre [OF hoaret.Throw]) \n       (blast intro: exec.intros terminates.intros)\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                        \\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s} \n                    c\\<^sub>1\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                   \\<Gamma>\\<turnstile>Catch c\\<^sub>1 c\\<^sub>2 \\<down> Normal s} \n                c\\<^sub>1\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t \\<and> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal t \\<and>\n                   \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\"\n    by (rule ConseqMGT)\n       (fastforce intro: exec.intros terminates.intros \n                 elim: terminates_Normal_elim_cases\n                 simp add: final_notin_def)\n  moreover\n  have \n    \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                     \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s} c\\<^sub>2\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow>Abrupt s \\<and> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s \\<and> \n                   \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} \n               c\\<^sub>2\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      by (rule ConseqMGT)\n         (fastforce intro: exec.intros terminates.intros \n                   simp add: noFault_def')\n  ultimately\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                   \\<Gamma>\\<turnstile>Catch c\\<^sub>1 c\\<^sub>2 \\<down> Normal s} \n                Catch c\\<^sub>1 c\\<^sub>2\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoaret.Catch )\nqed\n\n\n\n\n      assume \"Z \\<in> g\"\n      from this have \"\\<Gamma>\\<turnstile>(Guard f g c,Normal Z) \\<rightarrow> (c,Normal Z)\"\n        by (rule step.Guard)\n      from step_redexes [OF this c'] obtain c'' where\n        step: \"\\<Gamma>\\<turnstile> (c', Normal Z) \\<rightarrow> (c'', Normal Z)\"  and c'': \"c \\<in> redexes c''\"\n        by blast\n      note steps also note step \n      finally show \"\\<exists>c'. \\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z) \\<and> c \\<in> redexes c'\"\n        using c'' by blast\n    next\n      fix t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\" \n        \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n      thus \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n        using False\n        by (cases \"Z\\<in> g\") (auto simp add: final_notin_def intro: exec.intros )\n    next\n      fix t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\" \n             \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n      thus \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n        using False\n        by (cases \"Z\\<in> g\") (auto simp add: final_notin_def intro: exec.intros )\n    qed\n    then show ?thesis\n      apply (rule conseqPre [OF hoaret.Guard])\n      apply clarify\n      apply (frule Guard_noFaultStuckD [OF _ False])\n      apply auto\n      done\n  qed\nnext\n  case Throw\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Throw,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                  \\<Gamma>\\<turnstile>Call p\\<down>Normal \\<sigma> \\<and>\n                (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and> Throw \\<in> redexes c')}\n              Throw\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule conseqPre [OF hoaret.Throw]) \n       (blast intro: exec.intros terminates.intros)\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have hyp_c1:\n   \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s= Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call p \\<down> Normal \\<sigma> \\<and>\n                (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and> \n                      c\\<^sub>1 \\<in> redexes c')}\n               c\\<^sub>1 \n              {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  have hyp_c2:\n   \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s= Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                     \\<Gamma>\\<turnstile>Call p\\<down> Normal \\<sigma> \\<and>\n                (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and> c\\<^sub>2 \\<in> redexes c')}\n               c\\<^sub>2\n              {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  have\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n               \\<Gamma>\\<turnstile>Call p\\<down> Normal \\<sigma> \\<and>\n            (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>)\\<rightarrow>\\<^sup>+(c',Normal s) \\<and>\n                   Catch c\\<^sub>1 c\\<^sub>2 \\<in> redexes c')}\n            c\\<^sub>1\n           {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n           {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t \\<and> \n               \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault`(-F)) \\<and> \\<Gamma>\\<turnstile>Call p \\<down> Normal \\<sigma> \\<and>\n               (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal t) \\<and> c\\<^sub>2 \\<in> redexes c')}\"\n  proof (rule ConseqMGT [OF hyp_c1],clarify,safe) \n    assume \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n    thus \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n      by (fastforce simp add: final_notin_def intro: exec.intros)\n  next\n    fix c'\n    assume steps: \"\\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z)\" \n    assume c': \"Catch c\\<^sub>1 c\\<^sub>2 \\<in> redexes c'\"\n    from steps redexes_subset [OF this]\n    show \"\\<exists>c'. \\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z) \\<and> c\\<^sub>1 \\<in> redexes c'\"\n      by (auto iff:  root_in_redexes)\n  next\n    fix t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n    thus \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n      by (auto intro: exec.intros)\n  next\n    fix t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\" \n      \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n    thus \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n      by (auto simp add: final_notin_def intro: exec.intros)\n  next\n    fix c' t\n    assume steps_c': \"\\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z)\" \n    assume red: \"Catch c\\<^sub>1 c\\<^sub>2 \\<in> redexes c'\"\n    assume exec_c\\<^sub>1: \"\\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n    show \"\\<exists>c'. \\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal t) \\<and> c\\<^sub>2 \\<in> redexes c'\"\n    proof -\n      note steps_c'\n      also\n      from exec_impl_steps_Normal_Abrupt [OF exec_c\\<^sub>1]\n      have \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal Z) \\<rightarrow>\\<^sup>* (Throw, Normal t)\".\n      from steps_redexes_Catch [OF this red] \n      obtain c'' where\n        steps_c'': \"\\<Gamma>\\<turnstile> (c', Normal Z) \\<rightarrow>\\<^sup>* (c'', Normal t)\" and\n        Catch: \"Catch Throw c\\<^sub>2 \\<in> redexes c''\"\n        by blast\n      note steps_c''\n      also \n      have step_Catch: \"\\<Gamma>\\<turnstile> (Catch Throw c\\<^sub>2,Normal t) \\<rightarrow> (c\\<^sub>2,Normal t)\"\n        by (rule step.CatchThrow)\n      from step_redexes [OF step_Catch Catch]\n      obtain c''' where\n        step_c''': \"\\<Gamma>\\<turnstile> (c'', Normal t) \\<rightarrow> (c''', Normal t)\" and\n        c2: \"c\\<^sub>2 \\<in> redexes c'''\"\n        by blast\n      note step_c'''\n      finally show ?thesis\n        using c2\n        by blast\n    qed\n  qed\n  moreover\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t \\<and> \n                  \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                  \\<Gamma>\\<turnstile>Call p \\<down> Normal \\<sigma> \\<and>\n                  (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal t) \\<and> c\\<^sub>2 \\<in> redexes c')} \n               c\\<^sub>2\n              {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT [OF hyp_c2]) (fastforce intro: exec.intros)\n  ultimately show ?case\n    by (rule hoaret.Catch)\nqed\n\n\ntext \\<open>To prove a procedure implementation correct it suffices to assume\n       only the procedure specifications of procedures that actually\n       occur during evaluation of the body.  \n\\<close>\n\nlemma Call_lemma:\n assumes A: \n \"\\<forall>q \\<in> dom \\<Gamma>. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> \n                 {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call q\\<down>Normal s \\<and> ((s,q),(\\<sigma>,p)) \\<in> termi_call_steps \\<Gamma>}\n                 (Call q)\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n assumes pdef: \"p \\<in> dom \\<Gamma>\"\n shows \"\\<And>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>  \n              ({\\<sigma>} \\<inter> {s. s=Z \\<and>\\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>  \n                                 \\<Gamma>\\<turnstile>the (\\<Gamma> p)\\<down>Normal s}) \n                 the (\\<Gamma> p) \n              {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (rule conseqPre)\napply (rule Call_lemma' [OF A])\nusing pdef\napply (fastforce intro: terminates.intros tranclp.r_into_trancl [of \"(step \\<Gamma>)\", OF step.Call] root_in_redexes)\ndone\n\nlemma Call_lemma_switch_Call_body:\n assumes \n call: \"\\<forall>q \\<in> dom \\<Gamma>. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> \n                 {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call q\\<down>Normal s \\<and> ((s,q),(\\<sigma>,p)) \\<in> termi_call_steps \\<Gamma>}\n                 (Call q)\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n assumes p_defined: \"p \\<in> dom \\<Gamma>\"\n shows \"\\<And>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>  \n              ({\\<sigma>} \\<inter> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>  \n                                 \\<Gamma>\\<turnstile>Call p\\<down>Normal s}) \n                 the (\\<Gamma> p) \n              {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (simp only: exec_Call_body' [OF p_defined] noFaultStuck_Call_body' [OF p_defined] terminates_Normal_Call_body [OF p_defined])\napply (rule conseqPre)\napply (rule Call_lemma')\napply (rule call)\nusing p_defined\napply (fastforce intro: terminates.intros tranclp.r_into_trancl [of \"(step \\<Gamma>)\", OF step.Call] \nroot_in_redexes)\ndone\n\nlemma MGT_Call:\n\"\\<forall>p \\<in> dom \\<Gamma>. \\<forall>Z. \n  \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n             \\<Gamma>\\<turnstile>(Call p)\\<down>Normal s}\n           (Call p)\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (intro ballI allI)\napply (rule CallRec' [where Procs=\"dom \\<Gamma>\" and\n    P=\"\\<lambda>p Z. {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call p\\<down>Normal s}\" and\n    Q=\"\\<lambda>p Z. {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t}\" and\n    A=\"\\<lambda>p Z. {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" and\n    r=\"termi_call_steps \\<Gamma>\"\n    ]) \napply    simp\napply   simp\napply  (rule wf_termi_call_steps)\napply (intro ballI allI)\napply simp\napply (rule Call_lemma_switch_Call_body [rule_format, simplified])\napply  (rule hoaret.Asm)\napply  fastforce\napply assumption\ndone\n\n\nlemma CollInt_iff: \"{s. P s} \\<inter> {s. Q s} = {s. P s \\<and> Q s}\"\n  by auto\n\nlemma image_Un_conv: \"f ` (\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. {x p Z}) =  (\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. {f (x p Z)})\"\n  by (auto iff: not_None_eq)\n\n\ntext \\<open>Another proof of \\<open>MGT_Call\\<close>, maybe a little more readable\\<close>\nlemma \n\"\\<forall>p \\<in> dom \\<Gamma>. \\<forall>Z. \n  \\<Gamma>,{} \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n             \\<Gamma>\\<turnstile>(Call p)\\<down>Normal s}\n           (Call p)\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\nproof -\n  {\n    fix p Z \\<sigma>\n    assume defined: \"p \\<in> dom \\<Gamma>\"\n    define Specs where \"Specs = (\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. \n            {({s. s=Z \\<and> \n              \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n              \\<Gamma>\\<turnstile>Call p\\<down>Normal s},\n             p,\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})})\"\n    define Specs_wf where \"Specs_wf p \\<sigma> = (\\<lambda>(P,q,Q,A). \n                       (P \\<inter> {s. ((s,q),\\<sigma>,p) \\<in> termi_call_steps \\<Gamma>}, q, Q, A)) ` Specs\" for p \\<sigma>\n    have \"\\<Gamma>,Specs_wf p \\<sigma>\n            \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>({\\<sigma>} \\<inter>\n                 {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                  \\<Gamma>\\<turnstile>the (\\<Gamma> p)\\<down>Normal s}) \n                (the (\\<Gamma> p))\n               {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      apply (rule Call_lemma [rule_format, OF _ defined])\n      apply (rule hoaret.Asm)\n      apply (clarsimp simp add: Specs_wf_def Specs_def image_Un_conv)\n      apply (rule_tac x=q in bexI)\n      apply (rule_tac x=Z in exI)\n      apply (clarsimp simp add: CollInt_iff)\n      apply auto\n      done\n    hence \"\\<Gamma>,Specs_wf p \\<sigma>\n            \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>({\\<sigma>} \\<inter>\n                 {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                  \\<Gamma>\\<turnstile>Call p\\<down>Normal s}) \n                (the (\\<Gamma> p))\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      by (simp only: exec_Call_body' [OF defined] \n                   noFaultStuck_Call_body' [OF defined] \n                  terminates_Normal_Call_body [OF defined])\n  } note bdy=this\n  show ?thesis\n    apply (intro ballI allI)\n    apply (rule hoaret.CallRec [where Specs=\"(\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. \n            {({s. s=Z \\<and> \n              \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n              \\<Gamma>\\<turnstile>Call p\\<down>Normal s},\n             p,\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})})\", \n             OF _ wf_termi_call_steps [of \\<Gamma>] refl])\n    apply fastforce\n    apply clarify\n    apply (rule conjI)\n    apply  fastforce\n    apply (rule allI)\n    apply (simp (no_asm_use) only : Un_empty_left)\n    apply (rule bdy)\n    apply auto\n    done\nqed\n\n\ntheorem hoaret_complete: \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (iprover intro: MGT_implies_complete MGT_lemma [OF MGT_Call])\n\nlemma hoaret_complete': \n  assumes cvalid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (cases \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\")\n  case True\n  hence \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (rule hoaret_complete)\n  thus \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (rule hoaret_augment_context) simp\nnext\n  case False\n  with cvalid\n  show ?thesis\n    by (rule ExFalso)\nqed\n\nsubsection \\<open>And Now: Some Useful Rules\\<close>\n\nsubsubsection \\<open>Modify Return\\<close>\n\nlemma ProcModifyReturn_sound:\n  assumes valid_call: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P call init p return' c Q,A\"\n  assumes valid_modif: \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call p) (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \n  assumes res_modif:\n  \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\n  assumes ret_modifAbr: \n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\n  shows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>call init p return c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from exec\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: exec_call_Normal_elim)\n    fix bdy t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\" \n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> \\<Rightarrow> t\" \n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>(Call p ),Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with res_modif have \"Normal (return' s t') = Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy \n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_call)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\" \n    assume t: \"t = Abrupt (return s t')\"\n    also from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>(Call p),Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_callAbrupt)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy f\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Fault f\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callFault)\n    from cvalidt_postD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Stuck\"  \n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callStuck)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    assume \"\\<Gamma> p = None\" \"t=Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callUndefined)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults)\n  assume P: \"s \\<in> P\"\n  from valid_call ctxt P\n  have call: \"\\<Gamma>\\<turnstile>call init p return' c\\<down> Normal s\"\n    by (rule cvalidt_termD)\n  show \"\\<Gamma>\\<turnstile>call init p return c \\<down> Normal s\"\n  proof (cases \"p \\<in> dom \\<Gamma>\")\n    case True\n    with call obtain bdy where \n      bdy: \"\\<Gamma> p = Some bdy\" and termi_bdy: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\" and \n      termi_c: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>c s t \\<down> Normal (return' s t)\"\n      by cases auto \n    {\n      fix t\n      assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n      hence \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n      proof -\n        from exec_bdy bdy\n        have \"\\<Gamma>\\<turnstile>\\<langle>(Call p ),Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n          by (auto simp add: intro: exec.intros)\n        from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P \n          res_modif\n        have \"return' s t = return s t\"\n          by auto\n        with termi_c exec_bdy show ?thesis by auto\n      qed\n    }\n    with bdy termi_bdy\n    show ?thesis\n      by (iprover intro: terminates_call)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates_callUndefined)\n  qed\nqed\n\nlemma ProcModifyReturn:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes res_modif:\n  \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes ret_modifAbr: \n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:    \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call p) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule hoaret_complete') \napply (rule ProcModifyReturn_sound [where Modif=Modif and ModifAbr=ModifAbr, \n        OF _ _ res_modif ret_modifAbr])\napply (rule hoaret_sound [OF spec])\nusing modifies_spec\napply (blast intro: hoare_sound)\ndone\n\nlemma ProcModifyReturnSameFaults_sound:\n  assumes valid_call: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P call init p return' c Q,A\"\n  assumes valid_modif: \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call p (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \n  assumes res_modif:\n  \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\n  assumes ret_modifAbr: \n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\n  shows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>call init p return c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from exec\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: exec_call_Normal_elim)\n    fix bdy t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\" \n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> \\<Rightarrow> t\" \n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>(Call p) ,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with res_modif have \"Normal (return' s t') = Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy \n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_call)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\" \n    assume t: \"t = Abrupt (return s t')\"\n    also \n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call p ,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_callAbrupt)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy f\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Fault f\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callFault)\n    from cvalidt_postD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Stuck\"  \n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callStuck)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    assume \"\\<Gamma> p = None\" \"t=Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callUndefined)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  assume P: \"s \\<in> P\"\n  from valid_call ctxt P\n  have call: \"\\<Gamma>\\<turnstile>call init p return' c\\<down> Normal s\"\n    by (rule cvalidt_termD)\n  show \"\\<Gamma>\\<turnstile>call init p return c \\<down> Normal s\"\n  proof (cases \"p \\<in> dom \\<Gamma>\")\n    case True\n    with call obtain bdy where \n      bdy: \"\\<Gamma> p = Some bdy\" and termi_bdy: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\" and \n      termi_c: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>c s t \\<down> Normal (return' s t)\"\n      by cases auto \n    {\n      fix t\n      assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n      hence \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n      proof -\n        from exec_bdy bdy\n        have \"\\<Gamma>\\<turnstile>\\<langle>(Call p ),Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n          by (auto simp add: intro: exec.intros)\n        from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P \n          res_modif\n        have \"return' s t = return s t\"\n          by auto\n        with termi_c exec_bdy show ?thesis by auto\n      qed\n    }\n    with bdy termi_bdy\n    show ?thesis\n      by (iprover intro: terminates_call)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates_callUndefined)\n  qed\nqed\n\nlemma ProcModifyReturnSameFaults:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes res_modif:\n  \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes ret_modifAbr: \n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:    \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} (Call p) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule hoaret_complete') \napply (rule ProcModifyReturnSameFaults_sound [where Modif=Modif and ModifAbr=ModifAbr,\n          OF _ _ res_modif ret_modifAbr])\napply (rule hoaret_sound [OF spec])\nusing modifies_spec\napply (blast intro: hoare_sound)\ndone\n\n\nsubsubsection \\<open>DynCall\\<close>\n\n\nlemma dynProcModifyReturn_sound:\nassumes valid_call: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes valid_modif: \n    \"\\<forall>s\\<in>P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call (p s)) (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\nshows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  assume P: \"s \\<in> P\"\n  with valid_modif \n  have valid_modif': \n    \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call (p s)) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n    by blast\n  from exec\n  have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return c,Normal s\\<rangle> \\<Rightarrow> t\"\n    by (cases rule: exec_dynCall_Normal_elim)\n  then show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: exec_call_Normal_elim)\n    fix bdy t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\" \n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> \\<Rightarrow> t\" \n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s),Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: exec.Call)\n    from cvalidD [OF valid_modif' [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with ret_modif have \"Normal (return' s t') = \n      Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_call)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\" \n    assume t: \"t = Abrupt (return s t')\"\n    also from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s) ,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif' [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_callAbrupt)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy f\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Fault f\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callFault)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by blast\n  next\n    fix bdy\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Stuck\"  \n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callStuck)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    fix bdy\n    assume \"\\<Gamma> (p s) = None\" \"t=Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callUndefined)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults)\n  assume P: \"s \\<in> P\"\n  from valid_call ctxt P\n  have \"\\<Gamma>\\<turnstile>dynCall init p return' c\\<down> Normal s\"\n    by (rule cvalidt_termD)\n  hence call: \"\\<Gamma>\\<turnstile>call init (p s) return' c\\<down> Normal s\"\n    by cases\n  have \"\\<Gamma>\\<turnstile>call init (p s) return c \\<down> Normal s\"\n  proof (cases \"p s \\<in> dom \\<Gamma>\")\n    case True\n    with call obtain bdy where \n      bdy: \"\\<Gamma> (p s) = Some bdy\" and termi_bdy: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\" and \n      termi_c: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>c s t \\<down> Normal (return' s t)\"\n      by cases auto \n    {\n      fix t\n      assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n      hence \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n      proof -\n        from exec_bdy bdy\n        have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s),Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n          by (auto simp add: intro: exec.intros)\n        from cvalidD [OF valid_modif [rule_format, of s \"init s\"] ctxt' this] P \n          ret_modif\n        have \"return' s t = return s t\"\n          by auto\n        with termi_c exec_bdy show ?thesis by auto\n      qed\n    }\n    with bdy termi_bdy\n    show ?thesis\n      by (iprover intro: terminates_call)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates_callUndefined)\n  qed\n  thus \"\\<Gamma>\\<turnstile>dynCall init p return c \\<down> Normal s\"\n    by (iprover intro: terminates_dynCall)\nqed\n\nlemma dynProcModifyReturn:\nassumes dyn_call: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s) \n           \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s) \n                             \\<longrightarrow> return' s t = return s t\"\nassumes modif: \n    \"\\<forall>s \\<in> P. \\<forall>\\<sigma>.  \n       \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \nshows \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\napply (rule hoaret_complete')\napply (rule dynProcModifyReturn_sound \n        [where Modif=Modif and ModifAbr=ModifAbr,\n            OF hoaret_sound [OF dyn_call] _ ret_modif ret_modifAbr])\napply (intro ballI allI)\napply (rule hoare_sound [OF modif [rule_format]])\napply assumption\ndone\n\nlemma dynProcModifyReturnSameFaults_sound:\nassumes valid_call: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes valid_modif: \n    \"\\<forall>s\\<in>P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\nshows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  assume P: \"s \\<in> P\"\n  with valid_modif \n  have valid_modif': \n    \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} (Call (p s)) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n    by blast\n  from exec\n  have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return c,Normal s\\<rangle> \\<Rightarrow> t\"\n    by (cases rule: exec_dynCall_Normal_elim)\n  then show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: exec_call_Normal_elim)\n    fix bdy t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\" \n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> \\<Rightarrow> t\" \n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s),Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif' [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with ret_modif have \"Normal (return' s t') = \n      Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_call)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\" \n    assume t: \"t = Abrupt (return s t')\"\n    also from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s)  ,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif' [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_callAbrupt)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy f\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Fault f\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callFault)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Stuck\"  \n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callStuck)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    fix bdy\n    assume \"\\<Gamma> (p s) = None\" \"t=Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callUndefined)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  assume P: \"s \\<in> P\"\n  from valid_call ctxt P\n  have \"\\<Gamma>\\<turnstile>dynCall init p return' c\\<down> Normal s\"\n    by (rule cvalidt_termD)\n  hence call: \"\\<Gamma>\\<turnstile>call init (p s) return' c\\<down> Normal s\"\n    by cases\n  have \"\\<Gamma>\\<turnstile>call init (p s) return c \\<down> Normal s\"\n  proof (cases \"p s \\<in> dom \\<Gamma>\")\n    case True\n    with call obtain bdy where \n      bdy: \"\\<Gamma> (p s) = Some bdy\" and termi_bdy: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\" and \n      termi_c: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>c s t \\<down> Normal (return' s t)\"\n      by cases auto \n    {\n      fix t\n      assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n      hence \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n      proof -\n        from exec_bdy bdy\n        have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s),Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n          by (auto simp add: intro: exec.intros)\n        from cvalidD [OF valid_modif [rule_format, of s \"init s\"] ctxt' this] P \n          ret_modif\n        have \"return' s t = return s t\"\n          by auto\n        with termi_c exec_bdy show ?thesis by auto\n      qed\n    }\n    with bdy termi_bdy\n    show ?thesis\n      by (iprover intro: terminates_call)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates_callUndefined)\n  qed\n  thus \"\\<Gamma>\\<turnstile>dynCall init p return c \\<down> Normal s\"\n    by (iprover intro: terminates_dynCall)\nqed\n\nlemma dynProcModifyReturnSameFaults:\nassumes dyn_call: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\nassumes modif: \n    \"\\<forall>s \\<in> P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \nshows \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\napply (rule hoaret_complete')\napply (rule dynProcModifyReturnSameFaults_sound \n        [where Modif=Modif and ModifAbr=ModifAbr,\n          OF hoaret_sound [OF dyn_call] _ ret_modif ret_modifAbr])\napply (intro ballI allI)\napply (rule hoare_sound [OF modif [rule_format]])\napply assumption\ndone\n\nsubsubsection \\<open>Conjunction of Postcondition\\<close>\n\nlemma PostConjI_sound:\n  assumes valid_Q: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes valid_R: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c R,B\"\n  shows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from valid_Q ctxt exec P t_notin_F have \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    by (rule cvalidt_postD)\n  moreover\n  from valid_R ctxt exec P t_notin_F have \"t \\<in> Normal ` R \\<union> Abrupt ` B\"\n    by (rule cvalidt_postD)\n  ultimately show \"t \\<in> Normal ` (Q \\<inter> R) \\<union> Abrupt ` (A \\<inter> B)\"\n    by blast\nnext \n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  from valid_Q ctxt P\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule cvalidt_termD)\nqed\n\nlemma PostConjI:\n  assumes deriv_Q: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" \n  assumes deriv_R: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c R,B\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\napply (rule hoaret_complete')\napply (rule PostConjI_sound)\napply (rule hoaret_sound [OF deriv_Q])\napply (rule hoaret_sound [OF deriv_R])\ndone\n\n\nlemma Merge_PostConj_sound: \n  assumes validF: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes validG: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/G\\<^esub> P' c R,X\"\n  assumes F_G: \"F \\<subseteq> G\"\n  assumes P_P': \"P \\<subseteq> P'\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> X)\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  with F_G have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/G\\<^esub> P (Call p) Q,A\" \n    by (auto intro: validt_augment_Faults)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\" \n  with P_P' have P': \"s \\<in> P'\"\n    by auto\n  assume t_noFault: \"t \\<notin> Fault ` F\"\n  show \"t \\<in> Normal ` (Q \\<inter> R) \\<union> Abrupt ` (A \\<inter> X)\"\n  proof -\n    from cvalidt_postD [OF validF [rule_format] ctxt exec P t_noFault]\n    have t: \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\n    then have \"t \\<notin> Fault ` G\"\n      by auto\n    from cvalidt_postD [OF validG [rule_format] ctxt' exec P' this]\n    have \"t \\<in> Normal ` R \\<union> Abrupt ` X\" .\n    with t show ?thesis by auto\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  from validF ctxt P\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule cvalidt_termD)\nqed\n\n\n\nlemma Merge_PostConj: \n  assumes validF: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes validG: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/G\\<^esub> P' c R,X\"\n  assumes F_G: \"F \\<subseteq> G\"\n  assumes P_P': \"P \\<subseteq> P'\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> X)\"\napply (rule hoaret_complete')\napply (rule Merge_PostConj_sound [OF _ _ F_G P_P'])\nusing validF apply (blast intro:hoaret_sound)\nusing validG apply (blast intro:hoaret_sound)\ndone\n\n\nsubsubsection \\<open>Guards and Guarantees\\<close>\n\nlemma SplitGuards_sound:\n  assumes valid_c1: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,A\"\n  assumes valid_c2: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>2 UNIV,UNIV\"\n  assumes c: \"(c\\<^sub>1 \\<inter>\\<^sub>g c\\<^sub>2) = Some c\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def) \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases t)\n    case Normal\n    with inter_guards_exec_noFault [OF c exec]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t\" by simp\n    from valid_c1 ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    case Abrupt\n    with inter_guards_exec_noFault [OF c exec]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t\" by simp\n    from valid_c1 ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    case (Fault f)\n    assume t: \"t=Fault f\"\n    with exec inter_guards_exec_Fault [OF c]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Fault f \\<or> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow> Fault f\"\n      by auto\n    then show ?thesis\n    proof (cases rule: disjE [consumes 1])\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Fault f\"\n      from cvalidt_postD [OF valid_c1 ctxt this P] t t_notin_F\n      show ?thesis\n        by blast\n    next\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow> Fault f\"\n      from cvalidD [OF valid_c2 ctxt' this P] t t_notin_F\n      show ?thesis\n        by blast\n    qed\n  next\n    case Stuck\n    with inter_guards_exec_noFault [OF c exec]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t\" by simp\n    from valid_c1 ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n  proof -\n    from valid_c1 ctxt P\n    have \"\\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s\"\n      by (rule cvalidt_termD)\n    with c show ?thesis\n      by (rule inter_guards_terminates)\n  qed\nqed\n\nlemma SplitGuards: \n  assumes c: \"(c\\<^sub>1 \\<inter>\\<^sub>g c\\<^sub>2) = Some c\" \n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,A\" \n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>2 UNIV,UNIV\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule SplitGuards_sound [OF _ _ c])\napply (rule hoaret_sound [OF deriv_c1])\napply (rule hoare_sound [OF deriv_c2])\ndone\n\nlemma CombineStrip_sound:\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes valid_strip: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/{}\\<^esub> P (strip_guards (-F) c) UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n    by (auto simp add: validt_def)\n  from ctxt have ctxt'': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\" \n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases t)\n    case (Normal t')\n    from cvalidt_postD [OF valid ctxt'' exec P] Normal \n    show ?thesis\n      by auto\n  next\n    case (Abrupt t')\n    from cvalidt_postD [OF valid ctxt'' exec P] Abrupt \n    show ?thesis\n      by auto\n  next\n    case (Fault f)\n    show ?thesis\n    proof (cases \"f \\<in> F\")\n      case True\n      hence \"f \\<notin> -F\" by simp\n      with exec Fault\n      have \"\\<Gamma>\\<turnstile>\\<langle>strip_guards (-F) c,Normal s\\<rangle> \\<Rightarrow> Fault f\" \n        by (auto intro: exec_to_exec_strip_guards_Fault)\n      from cvalidD [OF valid_strip ctxt' this P] Fault\n      have False\n        by auto\n      thus ?thesis ..\n    next\n      case False\n      with cvalidt_postD [OF valid ctxt'' exec P] Fault\n      show ?thesis\n        by auto\n    qed\n  next\n    case Stuck\n    from cvalidt_postD [OF valid ctxt'' exec P] Stuck\n    show ?thesis\n      by auto\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  assume P: \"s \\<in> P\"\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n  proof -\n    from valid ctxt' P\n    show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n      by (rule cvalidt_termD)\n  qed\nqed\n\nlemma CombineStrip:\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes deriv_strip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P (strip_guards (-F) c) UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule CombineStrip_sound)\napply  (iprover intro: hoaret_sound [OF deriv])\napply (iprover intro: hoare_sound [OF deriv_strip])\ndone\n\nlemma GuardsFlip_sound:\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes validFlip: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/-F\\<^esub> P c UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  from ctxt have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  from ctxt have ctxtFlip: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^bsub>/-F\\<^esub> P (Call p) Q,A\" \n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\" \n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases t)\n    case (Normal t')\n    from cvalidt_postD [OF valid ctxt' exec P] Normal \n    show ?thesis\n      by auto\n  next\n    case (Abrupt t')\n    from cvalidt_postD [OF valid ctxt' exec P] Abrupt \n    show ?thesis\n      by auto\n  next\n    case (Fault f)\n    show ?thesis\n    proof (cases \"f \\<in> F\")\n      case True\n      hence \"f \\<notin> -F\" by simp\n      with cvalidD [OF validFlip ctxtFlip exec P] Fault\n      have False\n        by auto\n      thus ?thesis ..\n    next\n      case False\n      with cvalidt_postD [OF valid ctxt' exec P] Fault\n      show ?thesis\n        by auto\n    qed\n  next\n    case Stuck\n    from cvalidt_postD [OF valid ctxt' exec P] Stuck\n    show ?thesis\n      by auto\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  assume P: \"s \\<in> P\"\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n  proof -\n    from valid ctxt' P\n    show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n      by (rule cvalidt_termD)\n  qed\nqed\n\n\nlemma GuardsFlip: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes derivFlip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/-F\\<^esub> P c UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule GuardsFlip_sound)\napply  (iprover intro: hoaret_sound [OF deriv])\napply (iprover intro: hoare_sound [OF derivFlip])\ndone\n\nlemma MarkGuardsI_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c,Normal s\\<rangle> \\<Rightarrow> t\" \n  from exec_mark_guards_to_exec [OF exec] obtain t' where\n    exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t'\" and\n    t'_noFault: \"\\<not> isFault t' \\<longrightarrow> t' = t\"\n    by blast\n  assume P: \"s \\<in> P\" \n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof -\n    from cvalidt_postD [OF valid [rule_format] ctxt exec_c P]\n    have \"t' \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by blast\n    with t'_noFault\n    show ?thesis\n      by auto\n  qed\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>mark_guards f c \\<down> Normal s\"\n    by (rule terminates_to_terminates_mark_guards)\nqed\n\nlemma MarkGuardsI: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\"\napply (rule hoaret_complete')\napply (rule MarkGuardsI_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\n\nlemma MarkGuardsD_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\" \n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\" \n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases \"isFault t\")\n    case True\n    with exec_to_exec_mark_guards_Fault exec\n    obtain f' where \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c,Normal s\\<rangle> \\<Rightarrow> Fault f'\"\n      by (fastforce elim: isFaultE)\n    from cvalidt_postD [OF valid [rule_format] ctxt this P]\n    have False\n      by auto\n    thus ?thesis ..\n  next\n    case False\n    from exec_to_exec_mark_guards [OF exec False]\n    obtain f' where \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by auto\n    from cvalidt_postD [OF valid [rule_format] ctxt this P]\n    show ?thesis\n      by auto\n  qed\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>mark_guards f c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule terminates_mark_guards_to_terminates)\nqed\n\nlemma MarkGuardsD: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule MarkGuardsD_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nlemma MergeGuardsI_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P merge_guards c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume exec_merge: \"\\<Gamma>\\<turnstile>\\<langle>merge_guards c,Normal s\\<rangle> \\<Rightarrow> t\"\n  from exec_merge_guards_to_exec [OF exec_merge] \n  have exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" .\n  assume P: \"s \\<in> P\" \n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec P t_notin_F]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>merge_guards c \\<down> Normal s\"\n    by (rule terminates_to_terminates_merge_guards)\nqed\n\nlemma MergeGuardsI: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P merge_guards c Q,A\"\napply (rule hoaret_complete')\napply (rule MergeGuardsI_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nlemma MergeGuardsD_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P merge_guards c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  from exec_to_exec_merge_guards [OF exec] \n  have exec_merge: \"\\<Gamma>\\<turnstile>\\<langle>merge_guards c,Normal s\\<rangle> \\<Rightarrow> t\".\n  assume P: \"s \\<in> P\" \n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec_merge P t_notin_F]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>merge_guards c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule terminates_merge_guards_to_terminates)\nqed\n\n\n\n\nlemma SubsetGuards_sound: \n  assumes c_c': \"c \\<subseteq>\\<^sub>g c'\"\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c' Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  from exec_to_exec_subseteq_guards [OF c_c' exec] obtain t' where\n    exec_c': \"\\<Gamma>\\<turnstile>\\<langle>c',Normal s\\<rangle> \\<Rightarrow> t'\" and\n    t'_noFault: \"\\<not> isFault t' \\<longrightarrow> t' = t\"\n    by blast\n  assume P: \"s \\<in> P\" \n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec_c' P] t'_noFault t_noFault\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    by auto\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have termi_c': \"\\<Gamma>\\<turnstile>c' \\<down> Normal s\".\n  from cvalidt_postD [OF valid ctxt _ P]\n  have noFault_c': \"\\<Gamma>\\<turnstile>\\<langle>c',Normal s\\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\"\n    by (auto simp add: final_notin_def)\n  from termi_c' c_c' noFault_c'\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule terminates_fewer_guards)\nqed\n\nlemma SubsetGuards: \n  assumes c_c': \"c \\<subseteq>\\<^sub>g c'\"\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c' Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule SubsetGuards_sound [OF c_c'])\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nlemma NormalizeD_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  hence exec_norm: \"\\<Gamma>\\<turnstile>\\<langle>normalize c,Normal s\\<rangle> \\<Rightarrow> t\" \n    by (rule exec_to_exec_normalize)\n  assume P: \"s \\<in> P\" \n  assume noFault: \"t \\<notin> Fault ` F\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec_norm P noFault]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>normalize c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule terminates_normalize_to_terminates)\nqed\n\nlemma NormalizeD: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule NormalizeD_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nlemma NormalizeI_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume \"\\<Gamma>\\<turnstile>\\<langle>normalize c,Normal s\\<rangle> \\<Rightarrow> t\" \n  hence exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n    by (rule exec_normalize_to_exec)\n  assume P: \"s \\<in> P\" \n  assume noFault: \"t \\<notin> Fault ` F\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec P noFault]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile> c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>normalize c \\<down> Normal s\"\n    by (rule terminates_to_terminates_normalize)\nqed\n\nlemma NormalizeI: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\napply (rule hoaret_complete')\napply (rule NormalizeI_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nsubsubsection \\<open>Restricting the Procedure Environment\\<close>\n\nlemma validt_restrict_to_validt:\nassumes validt_c: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nshows \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from validt_c\n  have valid_c: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\" by (simp add: validt_def)\n  hence \"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\" by (rule valid_restrict_to_valid)\n  moreover\n  {\n    fix s\n    assume P: \"s \\<in> P\"\n    have \"\\<Gamma>\\<turnstile>c\\<down>Normal s\"\n    proof -\n      from P validt_c have \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>c\\<down>Normal s\"\n        by (auto simp add: validt_def)\n      moreover\n      from P valid_c\n      have \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>{Stuck}\"\n        by (auto simp add: valid_def  final_notin_def)\n      ultimately show ?thesis\n        by (rule terminates_restrict_to_terminates)\n    qed\n   }\n   ultimately show ?thesis\n     by (auto simp add: validt_def)\nqed\n\n\nlemma augment_procs:\nassumes deriv_c: \"\\<Gamma>|\\<^bsub>M\\<^esub>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nshows \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule hoaret_complete)\n  apply (rule validt_restrict_to_validt)\n  apply (insert hoaret_sound [OF deriv_c])\n  by (simp add: cvalidt_def)\n\nsubsubsection \\<open>Miscellaneous\\<close>\n\nlemma augment_Faults:\nassumes deriv_c: \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nassumes F: \"F \\<subseteq> F'\"\nshows \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F'\\<^esub> P c Q,A\"\n  apply (rule hoaret_complete)\n  apply (rule validt_augment_Faults [OF _ F])\n  apply (insert hoaret_sound [OF deriv_c])\n  by (simp add: cvalidt_def)\n\nlemma TerminationPartial_sound:\n  assumes \"termination\": \"\\<forall>s \\<in> P. \\<Gamma>\\<turnstile>c\\<down>Normal s\"\n  assumes partial_corr: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nusing \"termination\" partial_corr \nby (auto simp add: cvalidt_def validt_def cvalid_def)\n\nlemma TerminationPartial:\n  assumes partial_deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes \"termination\": \"\\<forall>s \\<in> P. \\<Gamma>\\<turnstile>c\\<down>Normal s\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule hoaret_complete')\n  apply (rule TerminationPartial_sound [OF \"termination\"])\n  apply (rule hoare_sound [OF partial_deriv])\n  done\n\nlemma TerminationPartialStrip:\n  assumes partial_deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes \"termination\": \"\\<forall>s \\<in> P. strip F' \\<Gamma>\\<turnstile>strip_guards F' c\\<down>Normal s\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from \"termination\" have \"\\<forall>s \\<in> P. \\<Gamma>\\<turnstile>c\\<down>Normal s\"\n    by (auto intro: terminates_strip_guards_to_terminates \n      terminates_strip_to_terminates)\n  with partial_deriv\n  show ?thesis\n    by (rule TerminationPartial)\nqed\n\nlemma SplitTotalPartial:\n  assumes termi: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q',A'\"\n  assumes part: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from hoaret_sound [OF termi] hoare_sound [OF part]\n  have \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (fastforce simp add: cvalidt_def validt_def cvalid_def valid_def)\n  thus ?thesis\n    by (rule hoaret_complete')\nqed\n   \nlemma SplitTotalPartial':\n  assumes termi: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/UNIV\\<^esub> P c Q',A'\"\n  assumes part: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from hoaret_sound [OF termi] hoare_sound [OF part]\n  have \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (fastforce simp add: cvalidt_def validt_def cvalid_def valid_def)\n  thus ?thesis\n    by (rule hoaret_complete')\nqed\n \nend\n", "meta": {"author": "LVPGroup", "repo": "TimSort", "sha": "16437b6b6e2df9f6d32b2a32be7d0d650d83f980", "save_path": "github-repos/isabelle/LVPGroup-TimSort", "path": "github-repos/isabelle/LVPGroup-TimSort/TimSort-16437b6b6e2df9f6d32b2a32be7d0d650d83f980/Simpl/HoareTotalProps.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5813030761371503, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.2929222070130459}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2005         |\n            |                  March 2007               |\n            |                                           |\n            |        CSP-Prover on Isabelle2016         |\n            |                    May 2016  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2017         |\n            |                  April 2018  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory CSP_T_law_fix\nimports CSP_T_law_fp\nbegin\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite UnionT and InterT.                 *)\n(*                  Union (B ` A) = (UN x:A. B x)                      *)\n(*                  Inter (B ` A) = (INT x:A. B x)                     *)\n\n(*\ndeclare Union_image_eq [simp del]\ndeclare Inter_image_eq [simp del]\n*)\n(* no simp rules in Isabelle 2017 \ndeclare Sup_image_eq [simp del]\ndeclare Inf_image_eq [simp del]\n*)\n\ndefinition\n FIXn :: \"nat => ('p => ('p,'a) proc) => ('p => ('p,'a) proc)\"\n                                                      (\"FIX[_] _\" [0,1000] 55)\n  where\n  FIXn_def :  \"FIX[n] Pf == ((Pf <<< )^^n) (%q. DIV)\"\n  \ndefinition\n  FIX  :: \"(('p) => ('p,'a) proc) => ('p => ('p,'a) proc)\"\n                                                      (\"FIX _\" [1000] 55)\n  where\n  FIX_def : \"FIX Pf == (%p. (!nat n .. ((FIX[n] Pf) p)))\"\n\n(* ----- test ----- *\nconsts\n FIXnrec :: \"nat => ('p => ('p,'a) proc) => ('p => ('p,'a) proc)\"\n                                                      (\"FIXrec[_] _\" [0,1000] 55)\nprimrec\n     \"FIXrec[0] Pf = (%p. DIV)\"\n \"FIXrec[Suc n] Pf = (%p. (Pf p)<<(FIXrec[n] Pf))\"\n\nlemma FIXn_FIXnrec: \"FIX[n] Pf = FIXrec[n] Pf\"\napply (induct_tac n)\napply (simp_all add: FIXn_def)\ndone\n\n * ----- test ----- *)\n\n(*-----------*\n |   noPN    |\n *-----------*)\n\nlemma noPNfun_FIXn: \"noPNfun (%p. (FIX[n] Pf)(p))\"\napply (simp add: FIXn_def)\napply (induct_tac n)\napply (simp add: noPNfun_def)\napply (simp (no_asm) add: noPNfun_def)\napply (intro allI)\napply (simp add: Subst_procfun_prod_def)\napply (simp add: noPN_Subst_Pf)\ndone\n\nlemma noPN_FIXn: \"noPN ((FIX[n] Pf)p)\"\napply (insert noPNfun_FIXn[of _ Pf])\napply (simp add: noPNfun_def)\ndone\n\nlemma noPN_FIX: \"noPN ((FIX Pf) p)\"\napply (simp add: FIX_def)\napply (simp add: noPN_FIXn)\ndone\n\n(*-----------*\n |    Bot    |\n *-----------*)\n\nlemma traces_prod_Bot: \"(%p. traces DIV M) = Bot\"\napply (simp add: prod_Bot_def)\napply (simp add: fun_eq_iff)\napply (simp add: traces_iff)\napply (simp add: bottom_domT_def)\ndone\n\nlemma semT_prod_Bot: \"(%p. [[DIV]]T) = Bot\"\nby (simp add: semT_def semTf_def traces_prod_Bot)\n\n(*-----------*\n |   FIX P   |\n *-----------*)\n\nlemma traces_subst_Bot: \"traces (P<<(%q. DIV)) M = (traces P) Bot\"\napply (induct_tac P)\napply (simp_all add: traces_iff)\napply (simp add: prod_Bot_def)\napply (simp add: bottom_domT_def)\ndone\n\nlemma traces_iteration_semTfun_Bot:\n  \"ALL p. traces (((Pf <<<) ^^ n) (%q. DIV) p) M = ([[Pf]]Tfun ^^ n) Bot p\"\napply (simp add: semTfun_def)\napply (simp add: semTf_def)\napply (induct_tac n)\n\n(* base *)\napply (simp_all add: traces_iff)\napply (simp add: prod_Bot_def)\napply (simp add: bottom_domT_def)\n\n(* step *)\napply (simp add: Subst_procfun_prod_def)\napply (simp add: traces_subst)\ndone\n\nlemma traces_FIX:\n    \"traces ((FIX Pf) p) M\n     = UnionT {u. EX n. u = ([[Pf]]Tfun ^^ n) Bot p}\"\napply (simp add: FIX_def FIXn_def)\napply (subgoal_tac \"{u. EX n. u = ([[Pf]]Tfun ^^ n) Bot p} ~= {}\")\napply (rule order_antisym)\n\n (* <= *)\n apply (rule)\n apply (simp add: in_traces)\n apply (erule disjE, simp)\n apply (elim conjE exE)\n apply (rule_tac x=\"traces (((Pf <<<) ^^ n) (%q. DIV) p) M\" in exI)\n apply (simp)\n apply (rule_tac x=\"n\" in exI)\n apply (simp add: traces_iteration_semTfun_Bot)\n\n (* => *)\n apply (rule)\n apply (simp add: in_traces)\n apply (rule disjI2)\n apply (elim conjE exE)\n apply (simp)\n apply (rule_tac x=\"na\" in exI)\n apply (simp add: traces_iteration_semTfun_Bot)\n\nby (auto)\n\n(*** [[ ]]T ***)\n\nlemma semT_FIX:\n    \"[[(FIX Pf) p]]T\n     = UnionT {u. EX n. u = ([[Pf]]Tfun ^^ n) Bot p}\"\napply (simp add: semT_def semTf_def)\napply (simp add: traces_FIX)\ndone\n\n(*** FIX is LUB ***)\n\nlemma semT_FIX_isLUB:\n   \"(%p. [[(FIX Pf) p]]T) isLUB {x. EX n. x = ([[Pf]]Tfun ^^ n) Bot}\"\napply (simp add: prod_LUB_decompo)\napply (intro allI)\napply (simp add: proj_fun_def)\napply (simp add: image_def)\napply (simp add: semT_FIX)\napply (subgoal_tac \n     \"{y. EX x. (EX n. x = ([[Pf]]Tfun ^^ n) Bot) & y = x i} =\n      {u. EX n. u = ([[Pf]]Tfun ^^ n) Bot i}\")\napply (simp)\napply (rule UnionT_isLUB)\napply (auto)\ndone\n\nlemma semT_FIX_LUB:\n   \"(%p. [[(FIX Pf) p]]T) = LUB {x. EX n. x = ([[Pf]]Tfun ^^ n) Bot}\"\napply (rule sym)\napply (rule isLUB_LUB)\napply (simp add: semT_FIX_isLUB)\ndone\n\nlemma semT_FIX_LFP:\n   \"(%p. [[(FIX Pf) p]]T) = LFP [[Pf]]Tfun\"\napply (simp add: semT_FIX_LUB)\napply (simp add: Tarski_thm_LFP_LUB continuous_semTfun)\ndone\n\nlemma semT_FIX_LFP_p:\n   \"[[(FIX Pf) p]]T = LFP [[Pf]]Tfun p\"\napply (insert semT_FIX_LFP[of Pf])\napply (simp add: fun_eq_iff)\ndone\n\nlemma semT_FIX_isLFP:\n   \"(%p. [[(FIX Pf) p]]T) isLFP [[Pf]]Tfun\"\napply (simp add: semT_FIX_LFP)\napply (simp add: LFP_is Tarski_thm_EX continuous_semTfun)\ndone\n\nlemma semT_FIX_LFP_fixed_point:\n   \"[[Pf]]Tfun (%p. [[(FIX Pf) p]]T) = (%p. [[(FIX Pf) p]]T)\"\napply (insert semT_FIX_isLFP[of Pf])\napply (simp add: isLFP_def)\ndone\n\nlemma semT_FIX_LFP_least:\n   \"ALL Tf. [[Pf]]Tfun Tf = Tf --> (%p. [[(FIX Pf) p]]T) <= Tf\"\napply (insert semT_FIX_isLFP[of Pf])\napply (simp add: isLFP_def)\ndone\n\n(*=======================================================*\n |                                                       |\n |                        CPO                            |\n |                                                       |\n *=======================================================*)\n\nlemma cspT_FIX_cpo:\n  \"[| FPmode = CPOmode |\n      FPmode = MIXmode ;\n      Pf = PNfun |]\n  ==> $p =T (FIX Pf)(p)\"\napply (simp add: eqT_def)\napply (fold semT_def)\napply (simp add: semT_FIX_LFP_p)\napply (simp add: semT_LFP_cpo)\ndone\n\nlemma cspT_FIX_cms:\n  \"[| FPmode = CMSmode ;\n      Pf = PNfun ;\n      guardedfun (Pf) |]\n  ==> $p =T (FIX Pf)(p)\"\napply (simp add: eqT_def)\napply (fold semT_def)\napply (simp add: semT_FIX_LFP_p)\napply (simp add: semT_guarded_LFP_UFP)\napply (simp add: semT_UFP_cms)\ndone\n\nlemma cspT_FIX:\n  \"[| FPmode = CPOmode | \n      FPmode = CMSmode & guardedfun (Pf) |\n      FPmode = MIXmode ;\n      Pf = PNfun |]\n  ==> $p =T (FIX Pf)(p)\"\napply (erule disjE)\napply (simp add: cspT_FIX_cpo)\napply (erule disjE)\napply (simp add: cspT_FIX_cms)\napply (simp add: cspT_FIX_cpo)\ndone\n\n(*==============================================================*\n |                                                              |\n | replace process names by infinite repcicated internal choice |\n |                         rmPN   (FIX)                         |\n |                                                              |\n *==============================================================*)\n\nprimrec \n   rmPN :: \"('p,'a) proc => ('p,'a) proc\"\nwhere\n  \"rmPN(STOP)        = STOP\"\n |\"rmPN(SKIP)        = SKIP\"\n |\"rmPN(DIV)         = DIV\"\n |\"rmPN(a -> P)      = a -> (rmPN P)\"\n |\"rmPN(? :A -> Pf)  = ? a:A -> (rmPN (Pf a))\"\n |\"rmPN(P [+] Q)     = (rmPN P) [+] (rmPN Q)\"\n |\"rmPN(P |~| Q)     = (rmPN P) |~| (rmPN Q)\"\n |\"rmPN(!! :C .. Pf) = !! c:C .. rmPN (Pf c)\"\n |\"rmPN(IF b THEN P ELSE Q) = (IF b THEN rmPN(P) ELSE rmPN(Q))\"\n |\"rmPN(P |[X]| Q)   = (rmPN P) |[X]| (rmPN Q)\"\n |\"rmPN(P -- X)      = (rmPN P) -- X\"\n |\"rmPN(P [[r]])     = (rmPN P) [[r]]\"\n |\"rmPN(P ;; Q)      = (rmPN P) ;; (rmPN Q)\"\n |\"rmPN(P |. n)      = (rmPN P) |. n\"\n |\"rmPN($p)          = (FIX PNfun)(p)\"\n\nlemma noPN_rmPN: \"noPN (rmPN P)\"\napply (induct_tac P)\napply (simp_all)\napply (simp add: noPN_FIX)\ndone\n\nlemma cspT_rmPN_eqT:\n  \"FPmode = CPOmode | \n   FPmode = CMSmode & guardedfun (PNfun::('p=>('p,'a) proc)) |\n   FPmode = MIXmode \n   ==> (P::('p,'a) proc) =T rmPN(P)\"\napply (induct_tac P)\napply (simp_all add: cspT_decompo)\napply (rule cspT_FIX)\napply (simp_all)\ndone\n\n(*-------------------------------------------------------*\n |                                                       |\n |         FIX expansion (CSP-Prover intro rule)         |\n |                                                       |\n *-------------------------------------------------------*)\n\nlemma traces_FIXn_plus_sub_lm:\n \"ALL n m p. traces ((FIX[n] Pf) p) M <= traces ((FIX[n+m] Pf) p) M\"\napply (rule)\napply (induct_tac n)\napply (simp add: FIXn_def Subst_procfun_prod_def)\napply (intro allI)\napply (rule)\napply (simp add: in_traces)\n\napply (rule allI)\napply (simp add: FIXn_def Subst_procfun_prod_def)\napply (drule_tac x=\"m\" in spec)\napply (simp add: traces_subst)\napply (rule allI)\napply (fold order_prod_def)\napply (simp add: mono_traces[simplified mono_def])\ndone\n\nlemma traces_FIXn_plus_sub: \n   \"traces ((FIX[n] Pf) p) M <= traces ((FIX[n+m] Pf) p) M\"\nby (simp add: traces_FIXn_plus_sub_lm)\n\nlemma semT_FIXn_plus_sub:\n \"[[(FIX[n] Pf) p]]Tf M <= [[(FIX[n+m] Pf) p]]Tf M\"\napply (simp add: semTf_def)\napply (simp add: traces_FIXn_plus_sub)\ndone\n\nlemma in_traces_FIXn_plus_sub: \n  \"t :t traces ((FIX[n] Pf) p) M ==> t :t traces ((FIX[n+m] Pf) p) M\"\napply (insert traces_FIXn_plus_sub[of n Pf p M m])\nby (auto)\n\n(*-----------------------------------------------------*\n |  sometimes FIX[n + f n] is useful more than FIX[n]  |\n *-----------------------------------------------------*)\n\nlemma cspT_FIX_plus_eq: \n     \"ALL f p. (FIX Pf) p =T[M,M] (!nat n .. ((FIX[n + f n] Pf) p))\"\napply (simp add: FIX_def)\napply (simp add: eqT_def)\napply (intro allI)\napply (simp add: semTf_def)\napply (rule order_antisym)\n\n apply (rule)\n apply (simp add: in_traces)\n apply (rule disjI2)\n apply (elim conjE exE disjE, simp)\n apply (rule_tac x=\"n\" in exI)\n apply (simp add: in_traces_FIXn_plus_sub)\n\n apply (rule)\n apply (simp add: in_traces)\n apply (elim conjE exE disjE)\n apply (simp)\n apply (rule disjI2)\n apply (rule_tac x=\"n + f n\" in exI)\n apply (simp)\ndone\n\n(****************** to add them again ******************)\n(*\ndeclare Union_image_eq [simp]\ndeclare Inter_image_eq [simp]\n*)\n(* 2017\ndeclare Sup_image_eq [simp]\ndeclare Inf_image_eq [simp]\n*)\n\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/CSP_T/CSP_T_law_fix.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6406358548398979, "lm_q2_score": 0.45713671682749485, "lm_q1q2_score": 0.2928581713634865}}
{"text": "(*******************************************************************************\n\n  Project: Refining Authenticated Key Agreement with Strong Adversaries\n\n  Module:  IK.thy (Isabelle/HOL 2016-1)\n  ID:      $Id: IK.thy 132882 2016-12-23 09:03:55Z csprenge $\n  Author:  Joseph Lallemand, INRIA Nancy <joseph.lallemand@loria.fr>\n           Christoph Sprenger, ETH Zurich <sprenger@inf.ethz.ch>\n  \n  State with intruder knowledge and corresponding Dolev-Yao derivation event.\n  - This is used a building block for Secrecy model. \n  - The attacker event is also used by level-3 models.\n\n  Copyright (c) 2015-2016 Joseph Lallemand and Christoph Sprenger\n  Licence: LGPL\n\n*******************************************************************************)\n\nsection \\<open>Environment: Dolev-Yao Intruder\\<close>\n\ntheory IK\nimports Message_derivation \nbegin\n\ntext \\<open>Basic state contains intruder knowledge. The secrecy model and concrete Level 1 \nstates will be record extensions of this state.\\<close>\n\nrecord ik_state =\n  ik :: \"msg set\"\n\n\ntext \\<open>Dolev-Yao intruder event adds a derived message.\\<close>\n\ndefinition\n  ik_dy :: \"msg \\<Rightarrow> ('a ik_state_scheme * 'a ik_state_scheme) set\"\nwhere\n  \"ik_dy m \\<equiv> {(s, s').\n    \\<comment> \\<open>guard\\<close>\n    m \\<in> synth (analz (ik s)) \\<and>\n\n    \\<comment> \\<open>action\\<close>\n    s' = s \\<lparr>ik := ik s \\<union> {m}\\<rparr>\n  }\"\n\ndefinition\n  ik_trans :: \"('a ik_state_scheme * 'a ik_state_scheme) set\"\nwhere\n  \"ik_trans \\<equiv> (\\<Union> m.  ik_dy m)\"\n\nlemmas ik_trans_defs = ik_trans_def ik_dy_def\n\n\nlemma ik_trans_ik_increasing: \"(s, s') \\<in> ik_trans \\<Longrightarrow> ik s \\<subseteq> ik s'\"\nby (auto simp add: ik_trans_defs)\n\n\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Key_Agreement_Strong_Adversaries/IK.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7122321964553657, "lm_q2_score": 0.41111086923216805, "lm_q1q2_score": 0.29280639737990166}}
{"text": "theory flash90Bra  imports flash90Rev\n \n  begin\nlemma onInv90:\n\n   assumes  a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" and \n\n     b1:\"r \\<in> rules N\" and b2:\"invf=inv90  iInv1  iInv2 \"\n   shows  \"invHoldForRule' s invf r (invariants   N)\" \n   proof - \nhave c1:\"ex1P N (% iRule1 .  r=NI_Local_GetX_PutX1 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_GetX  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Replace  iRule1 )\\<or>ex0P N (  r=NI_ShWb N )\\<or>ex0P N (  r=PI_Local_GetX_GetX2 )\\<or>ex0P N (  r=NI_Local_PutXAcksDone )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX7 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Nak2  iRule1 )\\<or>ex0P N (  r=NI_ReplaceHomeShrVld )\\<or>ex1P N (% iRule1 .  r=NI_Remote_Put  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX5 N  iRule1 )\\<or>ex0P N (  r=NI_Wb )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Get  iRule1 )\\<or>ex0P N (  r=PI_Local_Replace )\\<or>ex1P N (% iRule1 .  r=NI_ReplaceShrVld  iRule1 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Local_GetX_PutX8 N  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=NI_InvAck_2 N  iRule1 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Remote_Get_Nak2  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=PI_Remote_Replace  iRule1 )\\<or>ex0P N (  r=NI_Nak_Home )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Put2  iRule1 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_InvAck_1  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX11 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX6 N  iRule1 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Remote_Get_Put2  iRule1  iRule2 )\\<or>ex0P N (  r=PI_Local_Get_Put )\\<or>ex0P N (  r=PI_Local_GetX_PutX1 N )\\<or>ex1P N (% iRule1 .  r=NI_InvAck_1_Home  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Remote_Get_Nak1  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Nak1  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_Nak2  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX10_home N  iRule1 )\\<or>ex1P N (% iRule1 .  r=PI_Remote_Get  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_Nak3  iRule1 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Local_GetX_PutX10 N  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX2 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Remote_Get_Put1  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Remote_PutX  iRule1 )\\<or>ex1P N (% iRule1 .  r=Store  iRule1 )\\<or>ex0P N (  r=NI_FAck )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX3 N  iRule1 )\\<or>ex0P N (  r=PI_Local_GetX_PutX3 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Remote_GetX_PutX  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX8_home N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Put1 N  iRule1 )\\<or>ex0P N (  r=PI_Local_GetX_GetX1 )\\<or>ex0P N (  r=StoreHome )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Remote_GetX_Nak  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=NI_Inv  iRule1 )\\<or>ex1P N (% iRule1 .  r=PI_Remote_PutX  iRule1 )\\<or>ex0P N (  r=PI_Local_GetX_PutX4 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX4 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Nak  iRule1 )\\<or>ex0P N (  r=PI_Local_GetX_PutX2 N )\\<or>ex0P N (  r=NI_Local_Put )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_Nak1  iRule1 )\\<or>ex0P N (  r=NI_Nak_Clear )\\<or>ex0P N (  r=PI_Local_PutX )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Nak3  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Remote_GetX_Nak_Home  iRule1 )\\<or>ex0P N (  r=PI_Local_Get_Get )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX9 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=PI_Remote_GetX  iRule1 )\\<or>ex0P N (  r=NI_ReplaceHome )\\<or>ex1P N (% iRule1 .  r=NI_Remote_GetX_PutX_Home  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Put3  iRule1 )\" \n\n        apply(cut_tac  b1)\n        apply auto\n        done      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX1 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX1 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX1VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_GetX  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_GetX  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_GetX  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_GetXVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Replace  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Replace  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Replace  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_ReplaceVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_ShWb N )\n\"\n         \n         from c1 have c2:\" r= NI_ShWb N \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_ShWb N ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_ShWbVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_GetX2 )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_GetX2 \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Local_GetX_GetX2 ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_GetX_GetX2VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= NI_Local_PutXAcksDone )\n\"\n         \n         from c1 have c2:\" r= NI_Local_PutXAcksDone \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_PutXAcksDone ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_Local_PutXAcksDoneVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX7 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX7 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX7VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Nak2  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Nak2  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_Get_Nak2  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_Nak2VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_ReplaceHomeShrVld )\n\"\n         \n         from c1 have c2:\" r= NI_ReplaceHomeShrVld \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_ReplaceHomeShrVld ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_ReplaceHomeShrVldVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_Put  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_Put  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Remote_Put  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_PutVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX5 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX5 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX5VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_Wb )\n\"\n         \n         from c1 have c2:\" r= NI_Wb \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Wb ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_WbVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Get  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Get  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_Get_Get  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_GetVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_Replace )\n\"\n         \n         from c1 have c2:\" r= PI_Local_Replace \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Local_Replace ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_ReplaceVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_ReplaceShrVld  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_ReplaceShrVld  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_ReplaceShrVld  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_ReplaceShrVldVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Local_GetX_PutX8 N  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Local_GetX_PutX8 N  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX8VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_InvAck_2 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_InvAck_2 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_InvAck_2 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_InvAck_2VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Remote_Get_Nak2  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Remote_Get_Nak2  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_Get_Nak2VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= PI_Remote_Replace  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= PI_Remote_Replace  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Remote_Replace  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis PI_Remote_ReplaceVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_Nak_Home )\n\"\n         \n         from c1 have c2:\" r= NI_Nak_Home \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Nak_Home ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_Nak_HomeVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Put2  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Put2  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_Get_Put2  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_Put2VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_InvAck_1  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_InvAck_1  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_InvAck_1VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX11 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX11 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX11VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX6 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX6 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX6VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Remote_Get_Put2  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Remote_Get_Put2  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_Get_Put2VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_Get_Put )\n\"\n         \n         from c1 have c2:\" r= PI_Local_Get_Put \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Local_Get_Put ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_Get_PutVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_PutX1 N )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_PutX1 N \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Local_GetX_PutX1 N ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_GetX_PutX1VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_InvAck_1_Home  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_InvAck_1_Home  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_InvAck_1_Home  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_InvAck_1_HomeVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_Get_Nak1  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_Get_Nak1  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_Get_Nak1VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Nak1  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Nak1  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_Get_Nak1  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_Nak1VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_Nak2  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_Nak2  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_Nak2VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX10_home N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX10_home N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX10_homeVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= PI_Remote_Get  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= PI_Remote_Get  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Remote_Get  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis PI_Remote_GetVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_Nak3  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_Nak3  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_Nak3VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Local_GetX_PutX10 N  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Local_GetX_PutX10 N  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX10VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX2 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX2 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX2VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_Get_Put1  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_Get_Put1  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Remote_Get_Put1  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_Get_Put1VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_PutX  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_PutX  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Remote_PutX  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_PutXVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= Store  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= Store  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (Store  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis StoreVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_FAck )\n\"\n         \n         from c1 have c2:\" r= NI_FAck \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_FAck ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_FAckVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX3 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX3 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX3VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_PutX3 )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_PutX3 \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Local_GetX_PutX3 ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_GetX_PutX3VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Remote_GetX_PutX  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Remote_GetX_PutX  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_GetX_PutXVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX8_home N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX8_home N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX8_homeVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Put1 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Put1 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_Put1VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_GetX1 )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_GetX1 \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Local_GetX_GetX1 ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_GetX_GetX1VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= StoreHome )\n\"\n         \n         from c1 have c2:\" r= StoreHome \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (StoreHome ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis StoreHomeVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Remote_GetX_Nak  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Remote_GetX_Nak  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_GetX_NakVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Inv  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Inv  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Inv  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_InvVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= PI_Remote_PutX  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= PI_Remote_PutX  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Remote_PutX  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis PI_Remote_PutXVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_PutX4 )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_PutX4 \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Local_GetX_PutX4 ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_GetX_PutX4VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX4 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX4 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX4VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Nak  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Nak  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Nak  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_NakVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_PutX2 N )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_PutX2 N \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Local_GetX_PutX2 N ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_GetX_PutX2VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= NI_Local_Put )\n\"\n         \n         from c1 have c2:\" r= NI_Local_Put \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_Put ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_Local_PutVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_Nak1  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_Nak1  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_Nak1VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_Nak_Clear )\n\"\n         \n         from c1 have c2:\" r= NI_Nak_Clear \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Nak_Clear ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_Nak_ClearVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_PutX )\n\"\n         \n         from c1 have c2:\" r= PI_Local_PutX \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Local_PutX ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_PutXVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Nak3  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Nak3  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_Get_Nak3  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_Nak3VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_GetX_Nak_Home  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_GetX_Nak_Home  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_GetX_Nak_HomeVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_Get_Get )\n\"\n         \n         from c1 have c2:\" r= PI_Local_Get_Get \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Local_Get_Get ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_Get_GetVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX9 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX9 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX9VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= PI_Remote_GetX  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= PI_Remote_GetX  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Remote_GetX  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis PI_Remote_GetXVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_ReplaceHome )\n\"\n         \n         from c1 have c2:\" r= NI_ReplaceHome \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_ReplaceHome ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_ReplaceHomeVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_GetX_PutX_Home  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_GetX_PutX_Home  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_GetX_PutX_HomeVsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Put3  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Put3  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_Get_Put3  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_Put3VsInv90 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }ultimately show \"invHoldForRule' s invf r (invariants N) \"\n          by blast \n     qed\nend", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash90Bra.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297746074044134, "lm_q2_score": 0.4649015713733885, "lm_q1q2_score": 0.2927832045933706}}
{"text": "section {*FUNCTION\\_CFG\\_ENFORCE\\_ACCESSIBILITY\\_cfgLM*}\ntheory\n  FUNCTION_CFG_ENFORCE_ACCESSIBILITY_cfgLM\n\nimports\n  FUNCTION_CFG_ENFORCE_ACCESSIBILITY_cfgLM_EXTRA\n\nbegin\n\ndefinition F_CFG_EASTD_ALT :: \"\n  ('nonterminal, 'event) cfg\n  \\<Rightarrow> ('nonterminal, 'event) cfg\"\n  where\n    \"F_CFG_EASTD_ALT G \\<equiv>\n  let\n    N = F_CFG_APLM__fp G (cfg_nonterminals G) {cfg_initial G}\n  in\n    \\<lparr>cfg_nonterminals = N,\n    cfg_events = cfg_events G,\n    cfg_initial = cfg_initial G,\n    cfg_productions = {p \\<in> cfg_productions G. prod_lhs p \\<in> N}\\<rparr>\"\n\ndefinition F_CFG_EASTD__SpecInput :: \"\n  ('nonterminal, 'event) cfg\n  \\<Rightarrow> bool\"\n  where\n    \"F_CFG_EASTD__SpecInput G \\<equiv>\n  valid_cfg G\n  \\<and> cfg_nonterminals G = cfgSTD_Nonblockingness_nonterminals G\"\n\ndefinition F_CFG_EASTD__SpecOutput :: \"\n  ('nonterminal, 'event) cfg\n  \\<Rightarrow> ('nonterminal, 'event) cfg\n  \\<Rightarrow> bool\"\n  where\n    \"F_CFG_EASTD__SpecOutput Gi Go \\<equiv>\n  valid_cfg Go\n  \\<and> cfg_sub Go Gi\n  \\<and> cfgLM.marked_language Go = cfgLM.marked_language Gi\n  \\<and> cfgLM.initial_marking_derivations Go = cfgLM.initial_marking_derivations Gi\n  \\<and> cfg_nonterminals Go = cfgLM_accessible_nonterminals Gi \\<inter> cfgSTD_Nonblockingness_nonterminals Gi\n  \\<and> cfg_nonterminals Go = cfgLM_accessible_nonterminals Go \\<inter> cfgSTD_Nonblockingness_nonterminals Go\n  \\<and> cfg_nonterminals Go = cfgLM_language_relevant_nonterminals Go\n  \\<and> cfg_productions Go = cfgLM_language_relevant_productions Go\n  \\<and> cfgLM.marked_language Go \\<noteq> {}\"\n\nlemma F_CFG_EASTD_ALT_preserves_valid_cfg: \"\n  valid_cfg G\n  \\<Longrightarrow> cfg_nonterminals G = cfgSTD_Nonblockingness_nonterminals G\n  \\<Longrightarrow> valid_cfg (F_CFG_EASTD_ALT G)\"\n  apply(simp add: F_CFG_EASTD_ALT_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule F_CFG_APLMSoundL)\n   apply(force)\n  apply(simp (no_asm) add: Let_def valid_cfg_def)\n  apply(rule conjI)\n   apply(simp add: Let_def valid_cfg_def)\n  apply(rule conjI)\n   apply(rule_tac\n      B=\"cfgLM_accessible_nonterminals G\"\n      in finite_subset)\n    apply(simp (no_asm_simp))\n   apply(rule_tac\n      B=\"cfg_nonterminals G\"\n      in finite_subset)\n    apply(simp (no_asm) add: cfgLM_accessible_nonterminals_def)\n    apply(force)\n   apply(simp add: Let_def valid_cfg_def)\n  apply(rule conjI)\n   apply(rule_tac\n      A=\"cfgLM_accessible_nonterminals G\"\n      in set_mp)\n    apply(simp (no_asm_simp))\n   apply(simp (no_asm) add: cfgLM_accessible_nonterminals_def)\n   apply(rule conjI)\n    apply(simp add: valid_cfg_def)\n   apply(rule_tac\n      x=\"der1 \\<lparr>cfg_conf=[teA (cfg_initial G)]\\<rparr>\"\n      in exI)\n   apply(rule conjI)\n    apply(rule cfgLM.derivation_initialI)\n     apply(rule cfgLM.der1_is_derivation)\n    apply(clarsimp)\n    apply(rename_tac c)(*strict*)\n    apply(simp add: get_configuration_def der1_def)\n    apply(clarsimp)\n    apply(simp add: valid_cfg_def cfg_initial_configurations_def cfg_configurations_def)\n   apply(rule_tac\n      x=\"0\"\n      in exI)\n   apply(simp add: get_configuration_def der1_def)\n   apply(rule_tac\n      x=\"[]\"\n      in exI)\n   apply(rule_tac\n      x=\"[]\"\n      in exI)\n   apply(force)\n  apply(rule conjI)\n   apply(simp add: Let_def valid_cfg_def)\n  apply(rule_tac\n      t=\"F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}\"\n      and s=\"cfgLM_accessible_nonterminals G\"\n      in ssubst)\n   apply(force)\n  apply(thin_tac \"cfgLM_accessible_nonterminals G = F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}\")\n  apply(clarsimp)\n  apply(rename_tac e)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac e)(*strict*)\n   prefer 2\n   apply(simp add: valid_cfg_def)\n  apply(rename_tac e)(*strict*)\n  apply(rule one_step_preserves_cfgLM_accessible_nonterminals)\n     apply(rename_tac e)(*strict*)\n     apply(force)+\n  done\n\nlemma F_CFG_EASTD_ALT_is_cfg_sub: \"\n  valid_cfg G\n  \\<Longrightarrow> cfg_nonterminals G = cfgSTD_Nonblockingness_nonterminals G\n  \\<Longrightarrow> cfg_sub (F_CFG_EASTD_ALT G) G\"\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule F_CFG_EASTD_ALT_preserves_valid_cfg)\n    apply(force)\n   apply(force)\n  apply(simp add: F_CFG_EASTD_ALT_def Let_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule F_CFG_APLMSoundL)\n   apply(force)\n  apply(simp add: cfg_sub_def)\n  apply(rule conjI)\n   apply(rule_tac\n      t=\"F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}\"\n      and s=\"cfgLM_accessible_nonterminals G\"\n      in ssubst)\n    apply(force)\n   apply(rule_tac\n      t=\"cfgSTD_Nonblockingness_nonterminals G\"\n      and s=\"cfg_nonterminals G\"\n      in ssubst)\n    apply(force)\n   apply(simp (no_asm) add: cfgLM_accessible_nonterminals_def)\n   apply(force)\n  apply(force)\n  done\n\nlemma F_CFG_EASTD_ALT_preserves_language: \"\n  valid_cfg G\n  \\<Longrightarrow> cfg_nonterminals G = cfgSTD_Nonblockingness_nonterminals G\n  \\<Longrightarrow> cfgLM.marked_language G = cfgLM.marked_language (F_CFG_EASTD_ALT G)\"\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule F_CFG_EASTD_ALT_is_cfg_sub)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule F_CFG_EASTD_ALT_preserves_valid_cfg)\n    apply(force)\n   apply(force)\n  apply(simp add: F_CFG_EASTD_ALT_def Let_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule F_CFG_APLMSoundL)\n   apply(force)\n  apply(rule antisym)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   apply(simp add: cfgLM.marked_language_def)\n   apply(clarsimp)\n   apply(rename_tac x d)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac x d)(*strict*)\n    prefer 2\n    apply(rule cfg_sub_preserves_cfgLM_derivation_initial)\n      apply(rename_tac x d)(*strict*)\n      apply(force)\n     apply(rename_tac x d)(*strict*)\n     apply(force)\n    apply(rename_tac x d)(*strict*)\n    apply(force)\n   apply(rename_tac x d)(*strict*)\n   apply(rule_tac\n      x=\"d\"\n      in exI)\n   apply(clarsimp)\n   apply(rule conjI)\n    apply(rename_tac x d)(*strict*)\n    apply(simp add: cfg_marked_effect_def)\n   apply(rename_tac x d)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac x d)(*strict*)\n    apply(simp add: cfgLM.derivation_initial_def)\n   apply(rename_tac x d)(*strict*)\n   apply(simp add: cfg_marked_effect_def)\n   apply(clarsimp)\n   apply(rename_tac x d e c i)(*strict*)\n   apply(simp add: cfg_marking_condition_def)\n   apply(clarsimp)\n   apply(rename_tac x d e c i ia ea ca)(*strict*)\n   apply(simp add: cfg_marking_configuration_def)\n   apply(clarsimp)\n   apply(rule_tac\n      x=\"i\"\n      in exI)\n   apply(clarsimp)\n   apply(rule cfgLM.belongs_configurations)\n    apply(rename_tac x d e c i ia ea ca)(*strict*)\n    apply(rule cfgLM.derivation_initial_belongs)\n     apply(rename_tac x d e c i ia ea ca)(*strict*)\n     apply(force)\n    apply(rename_tac x d e c i ia ea ca)(*strict*)\n    apply(force)\n   apply(rename_tac x d e c i ia ea ca)(*strict*)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: cfgLM.marked_language_def)\n  apply(clarsimp)\n  apply(rename_tac x d)(*strict*)\n  apply(rule_tac\n      x=\"d\"\n      in exI)\n  apply(rule context_conjI)\n   apply(rename_tac x d)(*strict*)\n   prefer 2\n   apply(rule conjI)\n    apply(rename_tac x d)(*strict*)\n    apply(simp add: cfg_marked_effect_def)\n   apply(rename_tac x d)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac x d)(*strict*)\n    apply(simp add: cfgLM.derivation_initial_def)\n   apply(rename_tac x d)(*strict*)\n   apply(simp add: cfg_marking_condition_def)\n   apply(clarsimp)\n   apply(rename_tac x d i e c)(*strict*)\n   apply(rule_tac\n      x=\"i\"\n      in exI)\n   apply(clarsimp)\n   apply(simp add: cfg_marking_configuration_def cfg_configurations_def)\n   apply(clarsimp)\n  apply(rename_tac x d)(*strict*)\n  apply(rule cfg_sub_preserves_derivation_initial_contra)\n      apply(rename_tac x d)(*strict*)\n      apply(force)\n     apply(rename_tac x d)(*strict*)\n     apply(force)\n    apply(rename_tac x d)(*strict*)\n    apply(force)\n   apply(rename_tac x d)(*strict*)\n   apply(force)\n  apply(rename_tac x d)(*strict*)\n  apply(rule allI)+\n  apply(rename_tac x d i e c)(*strict*)\n  apply(rule impI)\n  apply(rule cfg_sub_preserves_derivation_initial_contra2)\n       apply(rename_tac x d i e c)(*strict*)\n       apply(force)\n      apply(rename_tac x d i e c)(*strict*)\n      apply(force)\n     apply(rename_tac x d i e c)(*strict*)\n     apply(force)\n    apply(rename_tac x d i e c)(*strict*)\n    apply(force)\n   apply(rename_tac x d i e c)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac x d i e c)(*strict*)\n  apply(rule_tac\n      t=\"F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}\"\n      and s=\"cfgLM_accessible_nonterminals G\"\n      in ssubst)\n   apply(rename_tac x d i e c)(*strict*)\n   apply(force)\n  apply(rename_tac x d i e c)(*strict*)\n  apply(thin_tac \"cfgLM_accessible_nonterminals G = F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}\")\n  apply(clarsimp)\n  apply(rename_tac x d i e c ea ca c')(*strict*)\n  apply(simp add: cfgLM_step_relation_def cfg_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac x d i e c ea c' l r)(*strict*)\n  apply(simp add: setAConcat)\n  apply(simp add: setBConcat)\n  apply(case_tac c')\n  apply(rename_tac x d i e c ea c' l r cfg_confa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d i e c ea l r)(*strict*)\n  apply(simp add: setAConcat)\n  apply(simp add: setBConcat)\n  apply(rule conjI)\n   apply(rename_tac x d i e c ea l r)(*strict*)\n   prefer 2\n   apply(simp add: cfg_sub_def valid_cfg_def)\n  apply(rename_tac x d i e c ea l r)(*strict*)\n  apply(rule one_step_preserves_cfgLM_accessible_nonterminals)\n     apply(rename_tac x d i e c ea l r)(*strict*)\n     apply(force)\n    apply(rename_tac x d i e c ea l r)(*strict*)\n    apply(force)\n   apply(rename_tac x d i e c ea l r)(*strict*)\n   apply(force)\n  apply(rename_tac x d i e c ea l r)(*strict*)\n  apply(force)\n  done\n\nlemma F_CFG_EASTD_ALT_idemp_cfgLM_accessible_nonterminals: \"\n  valid_cfg G\n  \\<Longrightarrow> cfg_nonterminals G = cfgSTD_Nonblockingness_nonterminals G\n  \\<Longrightarrow> cfgLM_accessible_nonterminals (F_CFG_EASTD_ALT G) = cfgLM_accessible_nonterminals G\"\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule F_CFG_EASTD_ALT_is_cfg_sub)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule F_CFG_EASTD_ALT_preserves_valid_cfg)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule F_CFG_APLMSoundL)\n   apply(force)\n  apply(rule antisym)\n   apply(simp add: F_CFG_EASTD_ALT_def Let_def)\n   apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   apply(rule_tac\n      t=\"F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}\"\n      and s=\"cfgLM_accessible_nonterminals G\"\n      in ssubst)\n    apply(rename_tac x)(*strict*)\n    apply(force)\n   apply(rename_tac x)(*strict*)\n   apply(simp add: cfgLM_accessible_nonterminals_def)\n  apply(simp add: F_CFG_EASTD_ALT_def Let_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(subgoal_tac \"x \\<in> cfgLM_accessible_nonterminals G\")\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(rule_tac\n      s=\"F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}\"\n      and t=\"cfgLM_accessible_nonterminals G\"\n      in ssubst)\n    apply(rename_tac x)(*strict*)\n    apply(force)\n   apply(rename_tac x)(*strict*)\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(thin_tac \"x \\<in> F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}\")\n  apply(rule_tac\n      t=\"F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}\"\n      and s=\"cfgLM_accessible_nonterminals G\"\n      in ssubst)\n   apply(rename_tac x)(*strict*)\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(simp (no_asm_use) add: cfgLM_accessible_nonterminals_def)\n  apply(clarsimp)\n  apply(rename_tac x d n c w1 w2)(*strict*)\n  apply(rule_tac\n      x=\"d\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac x d n c w1 w2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      x=\"n\"\n      in exI)\n   apply(clarsimp)\n   apply(force)\n  apply(rename_tac x d n c w1 w2)(*strict*)\n  apply(rule_tac\n      t=\"\\<lparr>cfg_nonterminals = F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}, cfg_events = cfg_events G, cfg_initial = cfg_initial G, cfg_productions = {p \\<in> cfg_productions G. prod_lhs p \\<in> cfgSTD_Nonblockingness_nonterminals G \\<and> (\\<exists>d. cfgLM.derivation_initial G d \\<and> (\\<exists>n c. get_configuration (d n) = Some c \\<and> (\\<exists>w1 w2. cfg_conf c = liftB w1 @ teA (prod_lhs p) # w2)))}\\<rparr>\"\n      and s=\"\\<lparr>cfg_nonterminals = F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}, cfg_events = cfg_events G, cfg_initial = cfg_initial G, cfg_productions = {p \\<in> cfg_productions G. prod_lhs p \\<in> F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}}\\<rparr>\"\n      in ssubst)\n   apply(rename_tac x d n c w1 w2)(*strict*)\n   apply(simp add: cfgLM_accessible_nonterminals_def)\n   apply(rule_tac\n      t=\"F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}\"\n      and s=\"{A \\<in> cfgSTD_Nonblockingness_nonterminals G. \\<exists>d. cfgLM.derivation_initial G d \\<and> (\\<exists>n c. get_configuration (d n) = Some c \\<and> (\\<exists>w1 w2. cfg_conf c = liftB w1 @ teA A # w2))}\"\n      in ssubst)\n    apply(rename_tac x d n c w1 w2)(*strict*)\n    apply(force)\n   apply(rename_tac x d n c w1 w2)(*strict*)\n   apply(simp (no_asm))\n  apply(rename_tac x d n c w1 w2)(*strict*)\n  apply(rule cfg_sub_preserves_derivation_initial_contra)\n      apply(rename_tac x d n c w1 w2)(*strict*)\n      apply(force)\n     apply(rename_tac x d n c w1 w2)(*strict*)\n     apply(force)\n    apply(rename_tac x d n c w1 w2)(*strict*)\n    apply(force)\n   apply(rename_tac x d n c w1 w2)(*strict*)\n   apply(force)\n  apply(rename_tac x d n c w1 w2)(*strict*)\n  apply(rule allI)+\n  apply(rename_tac x d n c w1 w2 i e ca)(*strict*)\n  apply(rule impI)\n  apply(rule cfg_sub_preserves_derivation_initial_contra2)\n       apply(rename_tac x d n c w1 w2 i e ca)(*strict*)\n       apply(force)\n      apply(rename_tac x d n c w1 w2 i e ca)(*strict*)\n      apply(force)\n     apply(rename_tac x d n c w1 w2 i e ca)(*strict*)\n     apply(force)\n    apply(rename_tac x d n c w1 w2 i e ca)(*strict*)\n    apply(force)\n   apply(rename_tac x d n c w1 w2 i e ca)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac x d n c w1 w2 i e ca)(*strict*)\n  apply(rule_tac\n      t=\"F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}\"\n      and s=\"{A \\<in> cfgSTD_Nonblockingness_nonterminals G. \\<exists>d. cfgLM.derivation_initial G d \\<and> (\\<exists>n c. get_configuration (d n) = Some c \\<and> (\\<exists>w1 w2. cfg_conf c = liftB w1 @ teA A # w2))}\"\n      in ssubst)\n   apply(rename_tac x d n c w1 w2 i e ca)(*strict*)\n   apply(force)\n  apply(rename_tac x d n c w1 w2 i e ca)(*strict*)\n  apply(thin_tac \"{A \\<in> cfgSTD_Nonblockingness_nonterminals G. \\<exists>d. cfgLM.derivation_initial G d \\<and> (\\<exists>n c. get_configuration (d n) = Some c \\<and> (\\<exists>w1 w2. cfg_conf c = liftB w1 @ teA A # w2))} = F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}\")\n  apply(rename_tac x d n c w1 w2 i e ca)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d n c w1 w2 i e ca ea cb c')(*strict*)\n  apply(simp add: cfgLM_step_relation_def cfg_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac x d n c w1 w2 i e ca ea c' l r)(*strict*)\n  apply(simp add: setAConcat)\n  apply(simp add: setBConcat)\n  apply(case_tac c')\n  apply(rename_tac x d n c w1 w2 i e ca ea c' l r cfg_confa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d n c w1 w2 i e ca ea l r da na cb w1a w2a)(*strict*)\n  apply(simp add: setAConcat)\n  apply(simp add: setBConcat)\n  apply(rule conjI)\n   apply(rename_tac x d n c w1 w2 i e ca ea l r da na cb w1a w2a)(*strict*)\n   prefer 2\n   apply(simp add: cfg_sub_def valid_cfg_def)\n  apply(rename_tac x d n c w1 w2 i e ca ea l r da na cb w1a w2a)(*strict*)\n  apply(rule_tac\n      t=\"{A \\<in> cfgSTD_Nonblockingness_nonterminals G. \\<exists>d. cfgLM.derivation_initial G d \\<and> (\\<exists>n c. get_configuration (d n) = Some c \\<and> (\\<exists>w1 w2. cfg_conf c = liftB w1 @ teA A # w2))}\"\n      and s=\"cfgLM_accessible_nonterminals G\"\n      in ssubst)\n   apply(rename_tac x d n c w1 w2 i e ca ea l r da na cb w1a w2a)(*strict*)\n   apply(simp (no_asm_use) add: cfgLM_accessible_nonterminals_def)\n   apply(force)\n  apply(rename_tac x d n c w1 w2 i e ca ea l r da na cb w1a w2a)(*strict*)\n  apply(rule one_step_preserves_cfgLM_accessible_nonterminals)\n     apply(rename_tac x d n c w1 w2 i e ca ea l r da na cb w1a w2a)(*strict*)\n     apply(force)\n    apply(rename_tac x d n c w1 w2 i e ca ea l r da na cb w1a w2a)(*strict*)\n    apply(force)\n   apply(rename_tac x d n c w1 w2 i e ca ea l r da na cb w1a w2a)(*strict*)\n   apply(force)\n  apply(rename_tac x d n c w1 w2 i e ca ea l r da na cb w1a w2a)(*strict*)\n  apply(simp (no_asm_use) add: cfgLM_accessible_nonterminals_def)\n  apply(force)\n  done\n\nlemma F_CFG_EASTD_ALT_preserves_Eliminability: \"\n  valid_cfg G\n  \\<Longrightarrow> cfg_nonterminals G = cfgSTD_Nonblockingness_nonterminals G\n  \\<Longrightarrow> cfg_nonterminals (F_CFG_EASTD_ALT G) = cfgLM_accessible_nonterminals (F_CFG_EASTD_ALT G) \\<inter> cfgSTD_Nonblockingness_nonterminals (F_CFG_EASTD_ALT G)\"\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule F_CFG_EASTD_ALT_idemp_cfgLM_accessible_nonterminals)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule F_CFG_EASTD_ALT_is_cfg_sub)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule F_CFG_EASTD_ALT_preserves_valid_cfg)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule F_CFG_APLMSoundL)\n   apply(force)\n  apply(rule inter_eq_intro)\n    apply(simp add: F_CFG_EASTD_ALT_def Let_def)\n   prefer 2\n   apply(simp add: F_CFG_EASTD_ALT_def Let_def)\n  apply(simp add: F_CFG_EASTD_ALT_def Let_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(subgoal_tac \"x \\<in> {A \\<in> cfg_nonterminals G. \\<exists>d n c. cfgLM.derivation_initial G d \\<and> get_configuration (d n) = Some c \\<and> (\\<exists>w1 w2. cfg_conf c = liftB w1 @ teA A # w2)}\")\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(unfold cfgLM_accessible_nonterminals_def)[1]\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(thin_tac \"x \\<in> F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}\")\n  apply(clarsimp)\n  apply(rename_tac x d n c w1 w2)(*strict*)\n  apply(subgoal_tac \"x \\<in> {A \\<in> cfg_nonterminals G. \\<exists>d w'. cfgSTD.derivation_from_to G d {pair None \\<lparr>cfg_conf = [teA A]\\<rparr>} ({y. (\\<exists>x. y = pair x \\<lparr>cfg_conf = w'\\<rparr>)}) \\<and> setA w' = {}}\")\n   apply(rename_tac x d n c w1 w2)(*strict*)\n   prefer 2\n   apply(simp (no_asm_use) only: cfgSTD_Nonblockingness_nonterminals_def)\n  apply(rename_tac x d n c w1 w2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d n c w1 w2 da w')(*strict*)\n  apply(subgoal_tac \"\\<exists>d n e. cfgSTD.derivation G d \\<and> d 0 = Some (pair None \\<lparr>cfg_conf = [teA x]\\<rparr>) \\<and> d n = Some (pair e \\<lparr>cfg_conf = w'\\<rparr>)\")\n   apply(rename_tac x d n c w1 w2 da w')(*strict*)\n   prefer 2\n   apply(rule_tac\n      x=\"da\"\n      in exI)\n   apply(simp add: cfgSTD.derivation_to_def cfgSTD.derivation_from_def cfgSTD.derivation_from_to_def )\n   apply(clarsimp)\n   apply(rename_tac x d n c w1 w2 da w' na xa)(*strict*)\n   apply(case_tac \"da 0\")\n    apply(rename_tac x d n c w1 w2 da w' na xa)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac x d n c w1 w2 da w' na xa a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x d n c w1 w2 da w' na xa)(*strict*)\n   apply(rule_tac\n      x=\"na\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac x d n c w1 w2 da w')(*strict*)\n  apply(thin_tac \"cfgSTD.derivation_from_to G da {pair None \\<lparr>cfg_conf = [teA x]\\<rparr>} ({y. (\\<exists>x. y = pair x \\<lparr>cfg_conf = w'\\<rparr>)})\")\n  apply(rename_tac x d n c w1 w2 da w')(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d n c w1 w2 w' da na e)(*strict*)\n  apply(case_tac \"d n\")\n   apply(rename_tac x d n c w1 w2 w' da na e)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac x d n c w1 w2 w' da na e a)(*strict*)\n  apply(clarsimp)\n  apply(simp add: get_configuration_def)\n  apply(case_tac a)\n  apply(rename_tac x d n c w1 w2 w' da na e a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d n c w1 w2 w' da na e option)(*strict*)\n  apply(case_tac c)\n  apply(rename_tac x d n c w1 w2 w' da na e option cfg_confa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d n w1 w2 w' da na e option)(*strict*)\n  apply(subgoal_tac \"x \\<in> {A \\<in> cfg_nonterminals \\<lparr>cfg_nonterminals = F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}, cfg_events = cfg_events G, cfg_initial = cfg_initial G, cfg_productions = {p \\<in> cfg_productions G. prod_lhs p \\<in> F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}}\\<rparr>. \\<exists>d w'. cfgSTD.derivation_from_to \\<lparr>cfg_nonterminals = F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}, cfg_events = cfg_events G, cfg_initial = cfg_initial G, cfg_productions = {p \\<in> cfg_productions G. prod_lhs p \\<in> F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}}\\<rparr> d {pair None \\<lparr>cfg_conf = [teA A]\\<rparr>} ({ y. (\\<exists>x. y = pair x \\<lparr>cfg_conf = w'\\<rparr>)}) \\<and> setA w' = {}}\")\n   apply(rename_tac x d n w1 w2 w' da na e option)(*strict*)\n   apply(simp add: cfgSTD_Nonblockingness_nonterminals_def)\n  apply(rename_tac x d n w1 w2 w' da na e option)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"cfgSTD.derivation \\<lparr>cfg_nonterminals = F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}, cfg_events = cfg_events G, cfg_initial = cfg_initial G, cfg_productions = {p \\<in> cfg_productions G. prod_lhs p \\<in> F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}}\\<rparr> da \")\n   apply(rename_tac x d n w1 w2 w' da na e option)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac x d n w1 w2 w' da na e option)(*strict*)\n    prefer 2\n    apply(rule_tac\n      x=\"da\"\n      in exI)\n    apply(rule_tac\n      x=\"w'\"\n      in exI)\n    apply(simp add: cfgSTD.derivation_to_def cfgSTD.derivation_from_def cfgSTD.derivation_from_to_def )\n    apply(rule_tac\n      x=\"na\"\n      in exI)\n    apply(clarsimp)\n    apply(case_tac \"da (Suc na)\")\n     apply(rename_tac x d n w1 w2 w' da na e option)(*strict*)\n     apply(force)\n    apply(rename_tac x d n w1 w2 w' da na e option a)(*strict*)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac x d n w1 w2 w' da na e option a)(*strict*)\n     prefer 2\n     apply(rule_tac\n      G=\"G\"\n      and d=\"da\"\n      and n=\"na\"\n      and m=\"Suc na\"\n      in cfgSTD.step_detail_before_some_position)\n       apply(rename_tac x d n w1 w2 w' da na e option a)(*strict*)\n       apply(force)\n      apply(rename_tac x d n w1 w2 w' da na e option a)(*strict*)\n      apply(force)\n     apply(rename_tac x d n w1 w2 w' da na e option a)(*strict*)\n     apply(force)\n    apply(rename_tac x d n w1 w2 w' da na e option a)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac x d n w1 w2 w' da na e option e2 c2)(*strict*)\n    apply(simp add: cfgSTD_step_relation_def)\n    apply(clarsimp)\n    apply(rename_tac x d n w1 w2 da na e option e2 c2 l r)(*strict*)\n    apply(simp add: setAConcat)\n   apply(rename_tac x d n w1 w2 w' da na e option)(*strict*)\n   apply(rule_tac\n      t=\"F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}\"\n      and s=\"cfgLM_accessible_nonterminals G\"\n      in ssubst)\n    apply(rename_tac x d n w1 w2 w' da na e option)(*strict*)\n    apply(force)\n   apply(rename_tac x d n w1 w2 w' da na e option)(*strict*)\n   apply(simp (no_asm) only: cfgLM_accessible_nonterminals_def)\n   apply(simp (no_asm))\n   apply(rule conjI)\n    apply(rename_tac x d n w1 w2 w' da na e option)(*strict*)\n    prefer 2\n    apply(rule_tac\n      x=\"d\"\n      in exI)\n    apply(clarsimp)\n    apply(rule_tac\n      x=\"n\"\n      in exI)\n    apply(clarsimp)\n    apply(simp add: get_configuration_def)\n    apply(force)\n   apply(rename_tac x d n w1 w2 w' da na e option)(*strict*)\n   apply(simp add: cfgSTD_Nonblockingness_nonterminals_def)\n  apply(rename_tac x d n w1 w2 w' da na e option)(*strict*)\n  apply(rule cfg_sub_preserves_cfg_derivation_contra)\n      apply(rename_tac x d n w1 w2 w' da na e option)(*strict*)\n      apply(force)\n     apply(rename_tac x d n w1 w2 w' da na e option)(*strict*)\n     apply(force)\n    apply(rename_tac x d n w1 w2 w' da na e option)(*strict*)\n    apply(force)\n   apply(rename_tac x d n w1 w2 w' da na e option)(*strict*)\n   apply(force)\n  apply(rename_tac x d n w1 w2 w' da na e option)(*strict*)\n  apply(rule allI)+\n  apply(rename_tac x d n w1 w2 w' da na e option i ea c)(*strict*)\n  apply(rule impI)\n  apply(rule cfg_sub_preserves_cfg_derivation_contra2)\n         apply(rename_tac x d n w1 w2 w' da na e option i ea c)(*strict*)\n         apply(force)\n        apply(rename_tac x d n w1 w2 w' da na e option i ea c)(*strict*)\n        apply(force)\n       apply(rename_tac x d n w1 w2 w' da na e option i ea c)(*strict*)\n       apply(force)\n      apply(rename_tac x d n w1 w2 w' da na e option i ea c)(*strict*)\n      apply(force)\n     apply(rename_tac x d n w1 w2 w' da na e option i ea c)(*strict*)\n     apply(force)\n    apply(rename_tac x d n w1 w2 w' da na e option i ea c)(*strict*)\n    prefer 3\n    apply(force)\n   apply(rename_tac x d n w1 w2 w' da na e option i ea c)(*strict*)\n   apply(simp add: cfg_configurations_def)\n   apply(rule_tac\n      t=\"F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}\"\n      and s=\"cfgLM_accessible_nonterminals G\"\n      in ssubst)\n    apply(rename_tac x d n w1 w2 w' da na e option i ea c)(*strict*)\n    apply(force)\n   apply(rename_tac x d n w1 w2 w' da na e option i ea c)(*strict*)\n   apply(simp (no_asm) only: cfgLM_accessible_nonterminals_def)\n   apply(simp (no_asm))\n   apply(rule conjI)\n    apply(rename_tac x d n w1 w2 w' da na e option i ea c)(*strict*)\n    apply(force)\n   apply(rename_tac x d n w1 w2 w' da na e option i ea c)(*strict*)\n   apply(rule_tac\n      x=\"d\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac x d n w1 w2 w' da na e option i ea c)(*strict*)\n    apply(force)\n   apply(rename_tac x d n w1 w2 w' da na e option i ea c)(*strict*)\n   apply(rule_tac\n      x=\"n\"\n      in exI)\n   apply(simp add: get_configuration_def)\n   apply(force)\n  apply(rename_tac x d n w1 w2 w' da na e option i ea c)(*strict*)\n  apply(simp add: cfgSTD_step_relation_def cfg_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac x d n w1 w2 w' da na e option i ea c eb c' l r)(*strict*)\n  apply(simp add: setAConcat)\n  apply(simp add: setBConcat)\n  apply(case_tac c')\n  apply(rename_tac x d n w1 w2 w' da na e option i ea c eb c' l r cfg_confa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d n w1 w2 w' da na e option i ea c eb l r)(*strict*)\n  apply(simp add: setAConcat)\n  apply(simp add: setBConcat)\n  apply(rule conjI)\n   apply(rename_tac x d n w1 w2 w' da na e option i ea c eb l r)(*strict*)\n   prefer 2\n   apply(simp add: cfg_sub_def valid_cfg_def)\n  apply(rename_tac x d n w1 w2 w' da na e option i ea c eb l r)(*strict*)\n  apply(rule_tac\n      t=\"F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G}\"\n      and s=\"cfgLM_accessible_nonterminals G\"\n      in ssubst)\n   apply(rename_tac x d n w1 w2 w' da na e option i ea c eb l r)(*strict*)\n   apply(force)\n  apply(rename_tac x d n w1 w2 w' da na e option i ea c eb l r)(*strict*)\n  apply(rule one_step_preserves_cfgLM_accessible_nonterminals)\n     apply(rename_tac x d n w1 w2 w' da na e option i ea c eb l r)(*strict*)\n     apply(force)\n    apply(rename_tac x d n w1 w2 w' da na e option i ea c eb l r)(*strict*)\n    apply(force)\n   apply(rename_tac x d n w1 w2 w' da na e option i ea c eb l r)(*strict*)\n   apply(force)\n  apply(rename_tac x d n w1 w2 w' da na e option i ea c eb l r)(*strict*)\n  apply(force)\n  done\n\nlemma F_CFG_EASTD_ALT_makes_precise_accessible_and_Nonblockingness: \"\n  valid_cfg G\n  \\<Longrightarrow> cfg_nonterminals G = cfgSTD_Nonblockingness_nonterminals G\n  \\<Longrightarrow> cfg_nonterminals (F_CFG_EASTD_ALT G) = cfgLM_accessible_nonterminals G \\<inter> cfgSTD_Nonblockingness_nonterminals G\"\n  apply(simp add: F_CFG_EASTD_ALT_def Let_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule F_CFG_APLMSoundL)\n   apply(force)\n  apply(clarsimp)\n  apply(subgoal_tac \"F_CFG_APLM__fp G (cfgSTD_Nonblockingness_nonterminals G) {cfg_initial G} \\<subseteq> cfg_nonterminals G\")\n   apply(blast)\n  apply(rule_tac B=\"cfgLM_accessible_nonterminals G\" in subset_trans)\n   apply(rule F_CFG_APLM_F_CFG_APLM__fp_invariant_03_unfold)\n   apply(simp add: F_CFG_APLM__fp_valid_input_def)\n   apply(simp add: valid_cfg_def)\n  apply(simp add: cfgLM_accessible_nonterminals_def)\n  apply(force)\n  done\n\nlemma cfg_with_cfgLM_Nonblockingness_nonterminals_has_nonempty_cfgLM_marked_language: \"\n  valid_cfg G\n  \\<Longrightarrow> cfg_nonterminals G \\<subseteq> cfgLM_Nonblockingness_nonterminals G\n  \\<Longrightarrow> cfgLM.marked_language G \\<noteq> {}\"\n  apply(simp add: cfgLM.marked_language_def)\n  apply(subgoal_tac \"cfg_initial G \\<in> cfgLM_Nonblockingness_nonterminals G\")\n   prefer 2\n   apply(simp add: valid_cfg_def)\n   apply(force)\n  apply(thin_tac \"cfg_nonterminals G \\<subseteq> cfgLM_Nonblockingness_nonterminals G\")\n  apply(simp add: cfgLM_Nonblockingness_nonterminals_def)\n  apply(clarsimp)\n  apply(rule_tac x=\"filterB w'\" in exI)\n  apply(rule_tac x=\"d\" in exI)\n  apply(clarsimp)\n  apply(simp add: cfg_marked_effect_def)\n  apply(rule conjI)\n   apply(rule_tac x=\"e\" in exI)\n   apply(rule_tac x=\"\\<lparr>cfg_conf = w'\\<rparr>\" in exI)\n   apply(clarsimp)\n   apply(rule conjI)\n    apply(force)\n   apply (metis liftBDeConv2)\n  apply(rule conjI)\n   apply(simp add: cfgLM.derivation_initial_def cfg_initial_configurations_def cfg_configurations_def cfg_marking_condition_def cfg_marking_configuration_def)\n  apply(simp add: cfg_marking_condition_def cfg_marking_configuration_def)\n  apply(rule_tac x=\"n\" in exI)\n  apply(clarsimp)\n  apply(rule_tac d=\"d\" in cfgLM.belongs_configurations)\n   apply(rule cfgLM.derivation_belongs)\n      apply(force)\n     apply(force)\n    apply(simp add: cfgLM.derivation_initial_def cfg_initial_configurations_def cfg_configurations_def cfg_marking_condition_def cfg_marking_configuration_def)\n   apply(force)\n  apply(force)\n  done\n\nlemma F_CFG_EASTD_ALT_preserves_cfgLM_initial_marking_derivations: \"\n  valid_cfg Gi\n  \\<Longrightarrow> valid_cfg Go\n  \\<Longrightarrow> cfg_sub Go Gi\n  \\<Longrightarrow> cfg_nonterminals Gi = cfgSTD_Nonblockingness_nonterminals Gi\n  \\<Longrightarrow> Go = F_CFG_EASTD_ALT Gi\n  \\<Longrightarrow> cfgLM.initial_marking_derivations Gi \\<subseteq> cfgLM.initial_marking_derivations Go\"\n  apply(simp add: cfgLM.initial_marking_derivations_def)\n  apply(clarsimp)\n  apply(rename_tac d)\n  apply(rule conjI)\n   prefer 2\n   apply(simp add: cfg_marking_condition_def)\n   apply(simp add: cfg_marking_configuration_def cfg_configurations_def cfg_sub_def)\n   apply(clarsimp)\n   apply(rule_tac x=\"i\" in exI)\n   apply(clarsimp)\n   apply(simp add: F_CFG_EASTD_ALT_def Let_def)\n   apply(force)\n  apply(simp add: cfg_marking_condition_def cfg_marking_configuration_def)\n  apply(clarsimp)\n  apply(case_tac c)\n  apply(clarsimp)\n  apply(rename_tac w)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule F_CFG_EASTD_ALT_preserves_valid_cfg)\n    apply(force)\n   apply(force)\n  apply(simp add: F_CFG_EASTD_ALT_def Let_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule F_CFG_APLMSoundL)\n   apply(force)\n  apply(rule cfg_sub_preserves_derivation_initial_contra)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(rule allI)+\n  apply(rule impI)\n  apply(rule cfg_sub_preserves_derivation_initial_contra2)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   prefer 2\n   apply(force)\n  apply(rule_tac\n      t=\"F_CFG_APLM__fp Gi (cfgSTD_Nonblockingness_nonterminals Gi) {cfg_initial Gi}\"\n      and s=\"cfgLM_accessible_nonterminals Gi\"\n      in ssubst)\n   apply(force)\n  apply(thin_tac \"cfgLM_accessible_nonterminals Gi = F_CFG_APLM__fp Gi (cfgSTD_Nonblockingness_nonterminals Gi) {cfg_initial Gi}\")\n  apply(clarsimp)\n  apply(simp add: cfgLM_step_relation_def cfg_configurations_def)\n  apply(clarsimp)\n  apply(simp add: setAConcat)\n  apply(simp add: setBConcat)\n  apply(case_tac c')\n  apply(clarsimp)\n  apply(simp add: setAConcat)\n  apply(simp add: setBConcat)\n  apply(rule conjI)\n   prefer 2\n   apply(simp add: cfg_sub_def valid_cfg_def)\n  apply(rule one_step_preserves_cfgLM_accessible_nonterminals)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(force)\n  done\n\nlemma F_CFG_EASTD_ALT_makes_equal_cfgLM_initial_marking_derivations: \"\n  valid_cfg Gi\n  \\<Longrightarrow> valid_cfg Go\n  \\<Longrightarrow> cfg_sub Go Gi\n  \\<Longrightarrow> cfg_nonterminals Gi = cfgSTD_Nonblockingness_nonterminals Gi\n  \\<Longrightarrow> Go = F_CFG_EASTD_ALT Gi\n  \\<Longrightarrow> cfgLM.initial_marking_derivations Go = cfgLM.initial_marking_derivations Gi\"\n  apply(rule antisym)\n   apply(rule cfg_sub_preserves_cfgLM_initial_marking_derivations)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(rule F_CFG_EASTD_ALT_preserves_cfgLM_initial_marking_derivations)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(force)\n  done\n\nlemma F_CFG_EASTD_ALT_enforces_cfgLM_language_relevant_productions: \"\n  valid_cfg Gi\n  \\<Longrightarrow> valid_cfg Go\n  \\<Longrightarrow> cfg_sub Go Gi\n  \\<Longrightarrow> cfg_nonterminals Gi = cfgSTD_Nonblockingness_nonterminals Gi\n  \\<Longrightarrow> Go = F_CFG_EASTD_ALT Gi\n  \\<Longrightarrow> cfg_productions Go = cfgLM_language_relevant_productions Go\"\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac\n      G=\"Gi\"\n      in F_CFG_EASTD_ALT_preserves_Eliminability)\n    apply(simp add: F_CFG_EASTD__SpecInput_def F_CFG_EASTD__SpecOutput_def)\n   apply(simp add: F_CFG_EASTD__SpecInput_def F_CFG_EASTD__SpecOutput_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac G=\"Gi\" in F_CFG_EASTD_ALT_makes_precise_accessible_and_Nonblockingness)\n    apply(simp add: F_CFG_EASTD__SpecInput_def)\n   apply(simp add: F_CFG_EASTD__SpecInput_def)\n  apply(subgoal_tac \"\ncfgLM_accessible_nonterminals (F_CFG_EASTD_ALT Gi) \\<inter> cfgSTD_Nonblockingness_nonterminals (F_CFG_EASTD_ALT Gi) = cfgLM_language_relevant_nonterminals (F_CFG_EASTD_ALT Gi)\")\n   prefer 2\n   apply(rule cfgLM_language_relevant_nonterminals_vs_cfgLM_accessible_nonterminals_and_cfgSTD_Nonblockingness_nonterminals_in_cfgSTD_Nonblockingness_nonterminals_grammar)\n      prefer 2\n      apply(force)\n     prefer 2\n     apply(force)\n    apply(force)\n   apply(rule antisym)\n    apply(force)\n   apply(simp (no_asm) add: cfgSTD_Nonblockingness_nonterminals_def)\n   apply(force)\n  apply(rule antisym)\n   prefer 2\n   apply(simp add: cfgLM_language_relevant_productions_def)\n   apply(clarsimp)\n   apply(subgoal_tac \"x \\<in> cfg_step_labels (F_CFG_EASTD_ALT Gi)\")\n    prefer 2\n    apply(rule cfgLM.belongs_step_labels)\n     apply(rule cfgLM.derivation_initial_belongs)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(simp add: cfg_step_labels_def)\n  apply(rule_tac t=\"cfg_productions Go\" and s=\"{p \\<in> cfg_productions Gi.\n     prod_lhs p\n     \\<in> F_CFG_APLM__fp Gi (cfgSTD_Nonblockingness_nonterminals Gi) {cfg_initial Gi}}\" in ssubst)\n   apply(simp add: F_CFG_EASTD_ALT_def Let_def)\n  apply(rule_tac\n      t=\"F_CFG_APLM__fp X (cfgSTD_Nonblockingness_nonterminals X) {cfg_initial X}\"\n      and s=\"cfgLM_accessible_nonterminals X\" for X\n      in ssubst)\n   apply(subgoal_tac \"X\" for X)\n    prefer 2\n    apply(rule F_CFG_APLMSoundL)\n    apply(force)\n   apply(force)\n  apply(simp add: cfgLM_language_relevant_productions_def)\n  apply(clarsimp)\n  apply(case_tac x)\n  apply(clarsimp)\n  apply(rename_tac A w)\n  apply(subgoal_tac \"A \\<in> cfgSTD_Nonblockingness_nonterminals Gi \\<and>\n           (\\<exists>d. cfgLM.derivation_initial\n                 Gi d \\<and>\n                (\\<exists>n c. get_configuration (d n) = Some c \\<and>\n                       (\\<exists>w1 w2. cfg_conf c = liftB w1 @ teA A # w2)))\")\n   prefer 2\n   apply(simp add: cfgLM_accessible_nonterminals_def)\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac Go=\"F_CFG_EASTD_ALT Gi\" and Gi=\"Gi\" in F_CFG_EASTD_ALT_makes_equal_cfgLM_initial_marking_derivations)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(case_tac \"d n\")\n   apply(simp add: get_configuration_def)\n  apply(simp add: get_configuration_def)\n  apply(case_tac c)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(clarsimp)\n  apply(rename_tac e)\n  apply(subgoal_tac \"\\<lparr>cfg_conf = liftB w1 @ teA A # w2\\<rparr> \\<in> SSX\" for SSX)\n   prefer 2\n   apply(rule_tac d=\"d\" in cfgLM.belongs_configurations)\n    apply(rule cfgLM.derivation_initial_belongs)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"prod_lhs \\<lparr>prod_lhs = A, prod_rhs = w\\<rparr> \\<in> cfgSTD_Nonblockingness_nonterminals Gi \\<and>\n           setA (prod_rhs \\<lparr>prod_lhs = A, prod_rhs = w\\<rparr>) \\<subseteq> cfgSTD_Nonblockingness_nonterminals Gi \\<and>\n           setB (prod_rhs \\<lparr>prod_lhs = A, prod_rhs = w\\<rparr>) \\<subseteq> cfg_events Gi\")\n   prefer 2\n   apply(simp add: valid_cfg_def)\n   apply(force)\n  apply(subgoal_tac \"setA (liftB w1 @ w @ w2) \\<subseteq> cfg_nonterminals Gi\")\n   prefer 2\n   apply(simp add:  cfg_configurations_def setA_liftB setAConcat)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac w=\"liftB w1 @ w @ w2\" and G=\"Gi\" in construct_elimininating_derivation_prime)\n     apply(force)\n    apply(rule antisym)\n     prefer 2\n     apply(simp add: cfgSTD_Nonblockingness_nonterminals_def)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<lparr>cfg_conf = liftB v\\<rparr> \\<in> SSX\" for SSX)\n   prefer 2\n   apply(rule_tac d=\"da\" in cfgLM.belongs_configurations)\n    apply(rule cfgLM.derivation_belongs)\n       apply(force)\n      apply(force)\n     apply(simp add: cfg_configurations_def)\n     apply(simp add: setBConcat)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"derivation_append d (derivation_append (der2 \\<lparr>cfg_conf = liftB w1 @ [teA A] @ w2\\<rparr> \\<lparr>prod_lhs = A, prod_rhs = w\\<rparr>  \\<lparr>cfg_conf = liftB w1 @ w @ w2\\<rparr>) da (Suc 0)) n \\<in> cfgLM.initial_marking_derivations  (F_CFG_EASTD_ALT Gi)\")\n   prefer 2\n   apply(rule_tac A=\"cfgLM.initial_marking_derivations  (Gi)\" in set_mp)\n    apply(force)\n   apply(thin_tac \"cfgLM.initial_marking_derivations A = VB\" for A VB)\n   apply(simp add: cfgLM.initial_marking_derivations_def cfg_marking_condition_def)\n   apply(rule context_conjI)\n    apply(rule cfgLM.derivation_append_preserves_derivation_initial)\n      apply(force)\n     apply(force)\n    apply(rule cfgLM.derivation_append_preserves_derivation)\n      apply(simp add: cfgLM.derivation_initial_def)\n     apply(rule cfgLM.derivation_append_preserves_derivation)\n       apply(rule cfgLM.der2_is_derivation)\n       apply(simp add: cfgLM_step_relation_def)\n       apply(rule_tac x=\"liftB w1\" in exI)\n       apply(clarsimp)\n       apply(simp add: setA_liftB)\n      apply(force)\n     apply(simp add: der2_def)\n    apply(clarsimp)\n    apply(simp add: derivation_append_def der2_def)\n   apply(rule_tac x=\"n+Suc 0+na\" in exI)\n   apply(simp add: setA_liftB)\n   apply(simp add: derivation_append_def der2_def cfg_marking_configuration_def cfg_configurations_def)\n   apply(simp add: setA_liftB)\n   apply(clarsimp)\n   apply(rule_tac t=\"liftB w1 @ w @ w2\" and s=\"liftB v\" in ssubst)\n    apply(force)\n   apply(simp (no_asm) add: setA_liftB)\n  apply(thin_tac \"       ATS_Language0.initial_marking_derivations cfg_initial_configurations\n        cfgLM_step_relation cfg_marking_condition (F_CFG_EASTD_ALT Gi) =\n       ATS_Language0.initial_marking_derivations cfg_initial_configurations\n        cfgLM_step_relation cfg_marking_condition Gi \")\n  apply(simp add: cfgLM.initial_marking_derivations_def)\n  apply(rule_tac x=\"derivation_append d\n          (derivation_append\n            (der2 \\<lparr>cfg_conf = liftB w1 @ teA A # w2\\<rparr> \\<lparr>prod_lhs = A, prod_rhs = w\\<rparr>\n              \\<lparr>cfg_conf = liftB w1 @ w @ w2\\<rparr>)\n            da (Suc 0))\n          n\" in exI)\n  apply(clarsimp)\n  apply(rule_tac x=\"Suc n\" in exI)\n  apply(simp add: derivation_append_def der2_def)\n  done\n\ntheorem SOUND_FUN_CFGLMACX: \"\n  F_CFG_EASTD__SpecInput G\n  \\<Longrightarrow> F_CFG_EASTD__SpecOutput G (F_CFG_EASTD_ALT G)\"\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule F_CFG_EASTD_ALT_preserves_valid_cfg)\n    apply(simp add: F_CFG_EASTD__SpecInput_def F_CFG_EASTD__SpecOutput_def)\n    apply(force)\n   apply(simp add: F_CFG_EASTD__SpecInput_def F_CFG_EASTD__SpecOutput_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac\n      G=\"G\"\n      in F_CFG_EASTD_ALT_is_cfg_sub)\n    apply(simp add: F_CFG_EASTD__SpecInput_def F_CFG_EASTD__SpecOutput_def)\n   apply(simp add: F_CFG_EASTD__SpecInput_def F_CFG_EASTD__SpecOutput_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac\n      G=\"G\"\n      in F_CFG_APLMSoundL)\n   apply(simp add: F_CFG_EASTD__SpecInput_def F_CFG_EASTD__SpecOutput_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac\n      G=\"G\"\n      in F_CFG_EASTD_ALT_preserves_language)\n    apply(simp add: F_CFG_EASTD__SpecInput_def F_CFG_EASTD__SpecOutput_def)\n   apply(simp add: F_CFG_EASTD__SpecInput_def F_CFG_EASTD__SpecOutput_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac\n      G=\"G\"\n      in F_CFG_EASTD_ALT_preserves_Eliminability)\n    apply(simp add: F_CFG_EASTD__SpecInput_def F_CFG_EASTD__SpecOutput_def)\n   apply(simp add: F_CFG_EASTD__SpecInput_def F_CFG_EASTD__SpecOutput_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac G=\"G\" in F_CFG_EASTD_ALT_makes_precise_accessible_and_Nonblockingness)\n    apply(simp add: F_CFG_EASTD__SpecInput_def)\n   apply(simp add: F_CFG_EASTD__SpecInput_def)\n  apply(subgoal_tac \"\ncfgLM_accessible_nonterminals (F_CFG_EASTD_ALT G) \\<inter> cfgSTD_Nonblockingness_nonterminals (F_CFG_EASTD_ALT G) = cfgLM_language_relevant_nonterminals (F_CFG_EASTD_ALT G)\")\n   prefer 2\n   apply(rule cfgLM_language_relevant_nonterminals_vs_cfgLM_accessible_nonterminals_and_cfgSTD_Nonblockingness_nonterminals_in_cfgSTD_Nonblockingness_nonterminals_grammar)\n      prefer 2\n      apply(force)\n     prefer 2\n     apply(force)\n    apply(simp add: F_CFG_EASTD_ALT_def F_CFG_EASTD__SpecInput_def F_CFG_EASTD__SpecOutput_def)\n   apply(rule antisym)\n    apply(force)\n   apply(simp add: cfgSTD_Nonblockingness_nonterminals_def)\n   apply(force)\n  apply(subgoal_tac \"cfgLM.initial_marking_derivations (F_CFG_EASTD_ALT G) = cfgLM.initial_marking_derivations G\")\n   prefer 2\n   apply(rule F_CFG_EASTD_ALT_makes_equal_cfgLM_initial_marking_derivations)\n       apply(simp add: F_CFG_EASTD_ALT_def F_CFG_EASTD__SpecInput_def F_CFG_EASTD__SpecOutput_def)\n      apply(force)\n     apply(simp add: F_CFG_EASTD_ALT_def F_CFG_EASTD__SpecInput_def F_CFG_EASTD__SpecOutput_def)\n    apply(simp add: F_CFG_EASTD_ALT_def F_CFG_EASTD__SpecInput_def F_CFG_EASTD__SpecOutput_def)\n   apply(simp add: F_CFG_EASTD_ALT_def F_CFG_EASTD__SpecInput_def F_CFG_EASTD__SpecOutput_def)\n  apply(subgoal_tac \"cfgLM.marked_language (F_CFG_EASTD_ALT G) \\<noteq> {}\")\n   prefer 2\n   apply(rule cfg_with_cfgLM_Nonblockingness_nonterminals_has_nonempty_cfgLM_marked_language)\n    apply(force)\n   apply(rule_tac t=\"cfgLM_Nonblockingness_nonterminals (F_CFG_EASTD_ALT G)\" and s=\"cfgSTD_Nonblockingness_nonterminals (F_CFG_EASTD_ALT G)\" in ssubst)\n    prefer 2\n    apply(force)\n   apply (metis cfgLM_Nonblockingness_nonterminals_vs_cfgSTD_Nonblockingness_nonterminals)\n  apply(subgoal_tac \"cfg_productions (F_CFG_EASTD_ALT G) = cfgLM_language_relevant_productions (F_CFG_EASTD_ALT G)\")\n   prefer 2\n   apply(rule F_CFG_EASTD_ALT_enforces_cfgLM_language_relevant_productions)\n       prefer 2\n       apply(force)\n      prefer 2\n      apply(force)\n     apply(simp add: F_CFG_EASTD__SpecInput_def)\n    apply(simp add: F_CFG_EASTD__SpecInput_def)\n   apply(force)\n  apply(simp add: F_CFG_EASTD_ALT_def F_CFG_EASTD__SpecInput_def F_CFG_EASTD__SpecOutput_def)\n  done\n\nend\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_12_04_06_04/FUNCTION_CFG_ENFORCE_ACCESSIBILITY_cfgLM.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6513548646660543, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.2927140786037151}}
{"text": "(*<*)\ntheory Monitor\n  imports Abstract_Monitor\n    Optimized_Join\n    \"HOL-Library.While_Combinator\"\n    \"HOL-Library.Mapping\"\n    \"Deriving.Derive\"\n    \"Generic_Join.Generic_Join_Correctness\"\nbegin\n(*>*)\n\nsection \\<open>Generic monitoring algorithm\\<close>\n\ntext \\<open>The algorithm defined here abstracts over the implementation of the temporal operators.\\<close>\n\nsubsection \\<open>Monitorable formulas\\<close>\n\ndefinition \"mmonitorable \\<phi> \\<longleftrightarrow> safe_formula \\<phi> \\<and> Formula.future_bounded \\<phi>\"\ndefinition \"mmonitorable_regex b g r \\<longleftrightarrow> safe_regex b g r \\<and> Regex.pred_regex Formula.future_bounded r\"\n\ndefinition is_simple_eq :: \"Formula.trm \\<Rightarrow> Formula.trm \\<Rightarrow> bool\" where\n  \"is_simple_eq t1 t2 = (Formula.is_Const t1 \\<and> (Formula.is_Const t2 \\<or> Formula.is_Var t2) \\<or>\n    Formula.is_Var t1 \\<and> Formula.is_Const t2)\"\n\nfun mmonitorable_exec :: \"Formula.formula \\<Rightarrow> bool\" where\n  \"mmonitorable_exec (Formula.Eq t1 t2) = is_simple_eq t1 t2\"\n| \"mmonitorable_exec (Formula.Neg (Formula.Eq (Formula.Var x) (Formula.Var y))) = (x = y)\"\n| \"mmonitorable_exec (Formula.Pred e ts) = list_all (\\<lambda>t. Formula.is_Var t \\<or> Formula.is_Const t) ts\"\n| \"mmonitorable_exec (Formula.Let p b \\<phi> \\<psi>) = ({0..<Formula.nfv \\<phi>} \\<subseteq> Formula.fv \\<phi> \\<and> b \\<le> Formula.nfv \\<phi> \\<and> mmonitorable_exec \\<phi> \\<and> mmonitorable_exec \\<psi>)\"\n| \"mmonitorable_exec (Formula.Neg \\<phi>) = (fv \\<phi> = {} \\<and> mmonitorable_exec \\<phi>)\"\n| \"mmonitorable_exec (Formula.Or \\<phi> \\<psi>) = (fv \\<phi> = fv \\<psi> \\<and> mmonitorable_exec \\<phi> \\<and> mmonitorable_exec \\<psi>)\"\n| \"mmonitorable_exec (Formula.And \\<phi> \\<psi>) = (mmonitorable_exec \\<phi> \\<and>\n    (safe_assignment (fv \\<phi>) \\<psi> \\<or> mmonitorable_exec \\<psi> \\<or>\n      fv \\<psi> \\<subseteq> fv \\<phi> \\<and> (is_constraint \\<psi> \\<or> (case \\<psi> of Formula.Neg \\<psi>' \\<Rightarrow> mmonitorable_exec \\<psi>' | _ \\<Rightarrow> False))))\"\n| \"mmonitorable_exec (Formula.Ands l) = (let (pos, neg) = partition mmonitorable_exec l in\n    pos \\<noteq> [] \\<and> list_all mmonitorable_exec (map remove_neg neg) \\<and>\n    \\<Union>(set (map fv neg)) \\<subseteq> \\<Union>(set (map fv pos)))\"\n| \"mmonitorable_exec (Formula.Exists \\<phi>) = (mmonitorable_exec \\<phi>)\"\n| \"mmonitorable_exec (Formula.Agg y \\<omega> b f \\<phi>) = (mmonitorable_exec \\<phi> \\<and>\n    y + b \\<notin> Formula.fv \\<phi> \\<and> {0..<b} \\<subseteq> Formula.fv \\<phi> \\<and> Formula.fv_trm f \\<subseteq> Formula.fv \\<phi>)\"\n| \"mmonitorable_exec (Formula.Prev I \\<phi>) = (mmonitorable_exec \\<phi>)\"\n| \"mmonitorable_exec (Formula.Next I \\<phi>) = (mmonitorable_exec \\<phi>)\"\n| \"mmonitorable_exec (Formula.Since \\<phi> I \\<psi>) = (Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi> \\<and>\n    (mmonitorable_exec \\<phi> \\<or> (case \\<phi> of Formula.Neg \\<phi>' \\<Rightarrow> mmonitorable_exec \\<phi>' | _ \\<Rightarrow> False)) \\<and> mmonitorable_exec \\<psi>)\"\n| \"mmonitorable_exec (Formula.Until \\<phi> I \\<psi>) = (Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi> \\<and> right I \\<noteq> \\<infinity> \\<and>\n    (mmonitorable_exec \\<phi> \\<or> (case \\<phi> of Formula.Neg \\<phi>' \\<Rightarrow> mmonitorable_exec \\<phi>' | _ \\<Rightarrow> False)) \\<and> mmonitorable_exec \\<psi>)\"\n| \"mmonitorable_exec (Formula.MatchP I r) = Regex.safe_regex Formula.fv (\\<lambda>g \\<phi>. mmonitorable_exec \\<phi> \\<or> (g = Lax \\<and> (case \\<phi> of Formula.Neg \\<phi>' \\<Rightarrow> mmonitorable_exec \\<phi>' | _ \\<Rightarrow> False))) Past Strict r\"\n| \"mmonitorable_exec (Formula.MatchF I r) = (Regex.safe_regex Formula.fv (\\<lambda>g \\<phi>. mmonitorable_exec \\<phi> \\<or> (g = Lax \\<and> (case \\<phi> of Formula.Neg \\<phi>' \\<Rightarrow> mmonitorable_exec \\<phi>' | _ \\<Rightarrow> False))) Futu Strict r \\<and> right I \\<noteq> \\<infinity>)\"\n| \"mmonitorable_exec _ = False\"\n\nlemma cases_Neg_iff:\n  \"(case \\<phi> of formula.Neg \\<psi> \\<Rightarrow> P \\<psi> | _ \\<Rightarrow> False) \\<longleftrightarrow> (\\<exists>\\<psi>. \\<phi> = formula.Neg \\<psi> \\<and> P \\<psi>)\"\n  by (cases \\<phi>) auto\n\nlemma safe_formula_mmonitorable_exec: \"safe_formula \\<phi> \\<Longrightarrow> Formula.future_bounded \\<phi> \\<Longrightarrow> mmonitorable_exec \\<phi>\"\nproof (induct \\<phi> rule: safe_formula.induct)\n  case (8 \\<phi> \\<psi>)\n  then show ?case\n    unfolding safe_formula.simps future_bounded.simps mmonitorable_exec.simps\n    by (auto simp: cases_Neg_iff)\nnext\n  case (9 \\<phi> \\<psi>)\n  then show ?case\n    unfolding safe_formula.simps future_bounded.simps mmonitorable_exec.simps\n    by (auto simp: cases_Neg_iff)\nnext\n  case (10 l)\n  from \"10.prems\"(2) have bounded: \"Formula.future_bounded \\<phi>\" if \"\\<phi> \\<in> set l\" for \\<phi>\n    using that by (auto simp: list.pred_set)\n  obtain poss negs where posnegs: \"(poss, negs) = partition safe_formula l\" by simp\n  obtain posm negm where posnegm: \"(posm, negm) = partition mmonitorable_exec l\" by simp\n  have \"set poss \\<subseteq> set posm\"\n  proof (rule subsetI)\n    fix x assume \"x \\<in> set poss\"\n    then have \"x \\<in> set l\" \"safe_formula x\" using posnegs by simp_all\n    then have \"mmonitorable_exec x\" using \"10.hyps\"(1) bounded by blast\n    then show \"x \\<in> set posm\" using \\<open>x \\<in> set poss\\<close> posnegm posnegs by simp\n  qed\n  then have \"set negm \\<subseteq> set negs\" using posnegm posnegs by auto\n  obtain \"poss \\<noteq> []\" \"list_all safe_formula (map remove_neg negs)\"\n    \"(\\<Union>x\\<in>set negs. fv x) \\<subseteq> (\\<Union>x\\<in>set poss. fv x)\"\n    using \"10.prems\"(1) posnegs by simp\n  then have \"posm \\<noteq> []\" using \\<open>set poss \\<subseteq> set posm\\<close> by auto\n  moreover have \"list_all mmonitorable_exec (map remove_neg negm)\"\n  proof -\n    let ?l = \"map remove_neg negm\"\n    have \"\\<And>x. x \\<in> set ?l \\<Longrightarrow> mmonitorable_exec x\"\n    proof -\n      fix x assume \"x \\<in> set ?l\"\n      then obtain y where \"y \\<in> set negm\" \"x = remove_neg y\" by auto\n      then have \"y \\<in> set negs\" using \\<open>set negm \\<subseteq> set negs\\<close> by blast\n      then have \"safe_formula x\"\n        unfolding \\<open>x = remove_neg y\\<close> using \\<open>list_all safe_formula (map remove_neg negs)\\<close>\n        by (simp add: list_all_def)\n      show \"mmonitorable_exec x\"\n      proof (cases \"\\<exists>z. y = Formula.Neg z\")\n        case True\n        then obtain z where \"y = Formula.Neg z\" by blast\n        then show ?thesis\n          using \"10.hyps\"(2)[OF posnegs refl] \\<open>x = remove_neg y\\<close> \\<open>y \\<in> set negs\\<close> posnegs bounded\n            \\<open>safe_formula x\\<close> by fastforce\n      next\n        case False\n        then have \"remove_neg y = y\" by (cases y) simp_all\n        then have \"y = x\" unfolding \\<open>x = remove_neg y\\<close> by simp\n        show ?thesis\n          using \"10.hyps\"(1) \\<open>y \\<in> set negs\\<close> posnegs \\<open>safe_formula x\\<close> unfolding \\<open>y = x\\<close>\n          by auto\n      qed\n    qed\n    then show ?thesis by (simp add: list_all_iff)\n  qed\n  moreover have \"(\\<Union>x\\<in>set negm. fv x) \\<subseteq> (\\<Union>x\\<in>set posm. fv x)\"\n    using \\<open>\\<Union> (fv ` set negs) \\<subseteq> \\<Union> (fv ` set poss)\\<close> \\<open>set poss \\<subseteq> set posm\\<close> \\<open>set negm \\<subseteq> set negs\\<close>\n    by fastforce\n  ultimately show ?case using posnegm by simp\nnext\n  case (15 \\<phi> I \\<psi>)\n  then show ?case\n    unfolding safe_formula.simps future_bounded.simps mmonitorable_exec.simps\n    by (auto simp: cases_Neg_iff)\nnext\n  case (16 \\<phi> I \\<psi>)\n  then show ?case\n    unfolding safe_formula.simps future_bounded.simps mmonitorable_exec.simps\n    by (auto simp: cases_Neg_iff)\nnext\n  case (17 I r)\n  then show ?case\n    by (auto elim!: safe_regex_mono[rotated] simp: cases_Neg_iff regex.pred_set)\nnext\n  case (18 I r)\n  then show ?case\n    by (auto elim!: safe_regex_mono[rotated] simp: cases_Neg_iff regex.pred_set)\nqed (auto simp add: is_simple_eq_def list.pred_set)\n\nlemma safe_assignment_future_bounded: \"safe_assignment X \\<phi> \\<Longrightarrow> Formula.future_bounded \\<phi>\"\n  unfolding safe_assignment_def by (auto split: formula.splits)\n\nlemma is_constraint_future_bounded: \"is_constraint \\<phi> \\<Longrightarrow> Formula.future_bounded \\<phi>\"\n  by (induction rule: is_constraint.induct) simp_all\n\nlemma mmonitorable_exec_mmonitorable: \"mmonitorable_exec \\<phi> \\<Longrightarrow> mmonitorable \\<phi>\"\nproof (induct \\<phi> rule: mmonitorable_exec.induct)\n  case (7 \\<phi> \\<psi>)\n  then show ?case\n    unfolding mmonitorable_def mmonitorable_exec.simps safe_formula.simps\n    by (auto simp: cases_Neg_iff intro: safe_assignment_future_bounded is_constraint_future_bounded)\nnext\n  case (8 l)\n  obtain poss negs where posnegs: \"(poss, negs) = partition safe_formula l\" by simp\n  obtain posm negm where posnegm: \"(posm, negm) = partition mmonitorable_exec l\" by simp\n  have pos_monitorable: \"list_all mmonitorable_exec posm\" using posnegm by (simp add: list_all_iff)\n  have neg_monitorable: \"list_all mmonitorable_exec (map remove_neg negm)\"\n    using \"8.prems\" posnegm by (simp add: list_all_iff)\n  have \"set posm \\<subseteq> set poss\"\n    using \"8.hyps\"(1) posnegs posnegm unfolding mmonitorable_def by auto\n  then have \"set negs \\<subseteq> set negm\"\n    using posnegs posnegm by auto\n\n  have \"poss \\<noteq> []\" using \"8.prems\" posnegm \\<open>set posm \\<subseteq> set poss\\<close> by auto\n  moreover have \"list_all safe_formula (map remove_neg negs)\"\n    using neg_monitorable \"8.hyps\"(2)[OF posnegm refl] \\<open>set negs \\<subseteq> set negm\\<close>\n    unfolding mmonitorable_def by (auto simp: list_all_iff)\n  moreover have \"\\<Union> (fv ` set negm) \\<subseteq> \\<Union> (fv ` set posm)\"\n    using \"8.prems\" posnegm by simp\n  then have \"\\<Union> (fv ` set negs) \\<subseteq> \\<Union> (fv ` set poss)\"\n    using \\<open>set posm \\<subseteq> set poss\\<close> \\<open>set negs \\<subseteq> set negm\\<close> by fastforce\n  ultimately have \"safe_formula (Formula.Ands l)\" using posnegs by simp\n  moreover have \"Formula.future_bounded (Formula.Ands l)\"\n  proof -\n    have \"list_all Formula.future_bounded posm\"\n      using pos_monitorable \"8.hyps\"(1) posnegm unfolding mmonitorable_def\n      by (auto elim!: list.pred_mono_strong)\n    moreover have fnegm: \"list_all Formula.future_bounded (map remove_neg negm)\"\n      using neg_monitorable \"8.hyps\"(2) posnegm unfolding mmonitorable_def\n      by (auto elim!: list.pred_mono_strong)\n    then have \"list_all Formula.future_bounded negm\"\n    proof -\n      have \"\\<And>x. x \\<in> set negm \\<Longrightarrow> Formula.future_bounded x\"\n      proof -\n        fix x assume \"x \\<in> set negm\"\n        have \"Formula.future_bounded (remove_neg x)\" using fnegm \\<open>x \\<in> set negm\\<close> by (simp add: list_all_iff)\n        then show \"Formula.future_bounded x\" by (cases x) auto\n      qed\n      then show ?thesis by (simp add: list_all_iff)\n    qed\n    ultimately have \"list_all Formula.future_bounded l\" using posnegm by (auto simp: list_all_iff)\n    then show ?thesis by (auto simp: list_all_iff)\n  qed\n  ultimately show ?case unfolding mmonitorable_def ..\nnext\n  case (13 \\<phi> I \\<psi>)\n  then show ?case\n    unfolding mmonitorable_def mmonitorable_exec.simps safe_formula.simps\n    by (fastforce simp: cases_Neg_iff)\nnext\n  case (14 \\<phi> I \\<psi>)\n  then show ?case\n    unfolding mmonitorable_def mmonitorable_exec.simps safe_formula.simps\n    by (fastforce simp: one_enat_def cases_Neg_iff)\nnext\n  case (15 I r)\n  then show ?case\n    by (auto elim!: safe_regex_mono[rotated] dest: safe_regex_safe[rotated]\n        simp: mmonitorable_regex_def mmonitorable_def cases_Neg_iff regex.pred_set)\nnext\n  case (16 I r)\n  then show ?case\n    by (auto 0 3 elim!: safe_regex_mono[rotated] dest: safe_regex_safe[rotated]\n        simp: mmonitorable_regex_def mmonitorable_def cases_Neg_iff regex.pred_set)\nqed (auto simp add: mmonitorable_def mmonitorable_regex_def is_simple_eq_def one_enat_def list.pred_set)\n\nlemma monitorable_formula_code[code]: \"mmonitorable \\<phi> = mmonitorable_exec \\<phi>\"\n  using mmonitorable_exec_mmonitorable safe_formula_mmonitorable_exec mmonitorable_def\n  by blast\n\nsubsection \\<open>Handling regular expressions\\<close>\n\ndatatype mregex =\n  MSkip nat\n  | MTestPos nat\n  | MTestNeg nat\n  | MPlus mregex mregex\n  | MTimes mregex mregex\n  | MStar mregex\n\nprimrec ok where\n  \"ok _ (MSkip n) = True\"\n| \"ok m (MTestPos n) = (n < m)\"\n| \"ok m (MTestNeg n) = (n < m)\"\n| \"ok m (MPlus r s) = (ok m r \\<and> ok m s)\"\n| \"ok m (MTimes r s) = (ok m r \\<and> ok m s)\"\n| \"ok m (MStar r) = ok m r\"\n\nprimrec from_mregex where\n  \"from_mregex (MSkip n) _ = Regex.Skip n\"\n| \"from_mregex (MTestPos n) \\<phi>s = Regex.Test (\\<phi>s ! n)\"\n| \"from_mregex (MTestNeg n) \\<phi>s = (if safe_formula (Formula.Neg (\\<phi>s ! n))\n    then Regex.Test (Formula.Neg (Formula.Neg (Formula.Neg (\\<phi>s ! n))))\n    else Regex.Test (Formula.Neg (\\<phi>s ! n)))\"\n| \"from_mregex (MPlus r s) \\<phi>s = Regex.Plus (from_mregex r \\<phi>s) (from_mregex s \\<phi>s)\"\n| \"from_mregex (MTimes r s) \\<phi>s = Regex.Times (from_mregex r \\<phi>s) (from_mregex s \\<phi>s)\"\n| \"from_mregex (MStar r) \\<phi>s = Regex.Star (from_mregex r \\<phi>s)\"\n\nprimrec to_mregex_exec where\n  \"to_mregex_exec (Regex.Skip n) xs = (MSkip n, xs)\"\n| \"to_mregex_exec (Regex.Test \\<phi>) xs = (if safe_formula \\<phi> then (MTestPos (length xs), xs @ [\\<phi>])\n     else case \\<phi> of Formula.Neg \\<phi>' \\<Rightarrow> (MTestNeg (length xs), xs @ [\\<phi>']) | _ \\<Rightarrow> (MSkip 0, xs))\"\n| \"to_mregex_exec (Regex.Plus r s) xs =\n     (let (mr, ys) = to_mregex_exec r xs; (ms, zs) = to_mregex_exec s ys\n     in (MPlus mr ms, zs))\"\n| \"to_mregex_exec (Regex.Times r s) xs =\n     (let (mr, ys) = to_mregex_exec r xs; (ms, zs) = to_mregex_exec s ys\n     in (MTimes mr ms, zs))\"\n| \"to_mregex_exec (Regex.Star r) xs =\n     (let (mr, ys) = to_mregex_exec r xs in (MStar mr, ys))\"\n\nprimrec shift where\n  \"shift (MSkip n) k = MSkip n\"\n| \"shift (MTestPos i) k = MTestPos (i + k)\"\n| \"shift (MTestNeg i) k = MTestNeg (i + k)\"\n| \"shift (MPlus r s) k = MPlus (shift r k) (shift s k)\"\n| \"shift (MTimes r s) k = MTimes (shift r k) (shift s k)\"\n| \"shift (MStar r) k = MStar (shift r k)\"\n\nprimrec to_mregex where\n  \"to_mregex (Regex.Skip n) = (MSkip n, [])\"\n| \"to_mregex (Regex.Test \\<phi>) = (if safe_formula \\<phi> then (MTestPos 0, [\\<phi>])\n     else case \\<phi> of Formula.Neg \\<phi>' \\<Rightarrow> (MTestNeg 0, [\\<phi>']) | _ \\<Rightarrow> (MSkip 0, []))\"\n| \"to_mregex (Regex.Plus r s) =\n     (let (mr, ys) = to_mregex r; (ms, zs) = to_mregex s\n     in (MPlus mr (shift ms (length ys)), ys @ zs))\"\n| \"to_mregex (Regex.Times r s) =\n     (let (mr, ys) = to_mregex r; (ms, zs) = to_mregex s\n     in (MTimes mr (shift ms (length ys)), ys @ zs))\"\n| \"to_mregex (Regex.Star r) =\n     (let (mr, ys) = to_mregex r in (MStar mr, ys))\"\n\nlemma shift_0: \"shift r 0 = r\"\n  by (induct r) auto\n\nlemma shift_shift: \"shift (shift r k) j = shift r (k + j)\"\n  by (induct r) auto\n\nlemma to_mregex_to_mregex_exec:\n  \"case to_mregex r of (mr, \\<phi>s) \\<Rightarrow> to_mregex_exec r xs = (shift mr (length xs), xs @ \\<phi>s)\"\n  by (induct r arbitrary: xs)\n    (auto simp: shift_shift ac_simps split: formula.splits prod.splits)\n\nlemma to_mregex_to_mregex_exec_Nil[code]: \"to_mregex r = to_mregex_exec r []\"\n  using to_mregex_to_mregex_exec[where xs=\"[]\" and r = r] by (auto simp: shift_0)\n\nlemma ok_mono: \"ok m mr \\<Longrightarrow> m \\<le> n \\<Longrightarrow> ok n mr\"\n  by (induct mr) auto\n\nlemma from_mregex_cong: \"ok m mr \\<Longrightarrow> (\\<forall>i < m. xs ! i = ys ! i) \\<Longrightarrow> from_mregex mr xs = from_mregex mr ys\"\n  by (induct mr) auto\n\nlemma not_Neg_cases:\n  \"(\\<forall>\\<psi>. \\<phi> \\<noteq> Formula.Neg \\<psi>) \\<Longrightarrow> (case \\<phi> of formula.Neg \\<psi> \\<Rightarrow> f \\<psi> | _ \\<Rightarrow> x) = x\"\n  by (cases \\<phi>) auto\n\nlemma to_mregex_exec_ok:\n  \"to_mregex_exec r xs = (mr, ys) \\<Longrightarrow> \\<exists>zs. ys = xs @ zs \\<and> set zs = atms r \\<and> ok (length ys) mr\"\nproof (induct r arbitrary: xs mr ys)\n  case (Skip x)\n  then show ?case by (auto split: if_splits prod.splits simp: atms_def elim: ok_mono)\nnext\n  case (Test x)\n  show ?case proof (cases \"\\<exists>x'. x = Formula.Neg x'\")\n    case True\n    with Test show ?thesis by (auto split: if_splits prod.splits simp: atms_def elim: ok_mono)\n  next\n    case False\n    with Test show ?thesis by (auto split: if_splits prod.splits simp: atms_def not_Neg_cases elim: ok_mono)\n  qed\nnext\n  case (Plus r1 r2)\n  then show ?case by (fastforce split: if_splits prod.splits formula.splits simp: atms_def elim: ok_mono)\nnext\n  case (Times r1 r2)\n  then show ?case by (fastforce split: if_splits prod.splits formula.splits simp: atms_def elim: ok_mono)\nnext\n  case (Star r)\n  then show ?case by (auto split: if_splits prod.splits simp: atms_def elim: ok_mono)\nqed\n\nlemma ok_shift: \"ok (i + m) (Monitor.shift r i) \\<longleftrightarrow> ok m r\"\n  by (induct r) auto\n\nlemma to_mregex_ok: \"to_mregex r = (mr, ys) \\<Longrightarrow> set ys = atms r \\<and> ok (length ys) mr\"\nproof (induct r arbitrary: mr ys)\n  case (Skip x)\n  then show ?case by (auto simp: atms_def elim: ok_mono split: if_splits prod.splits)\nnext\n  case (Test x)\n  show ?case proof (cases \"\\<exists>x'. x = Formula.Neg x'\")\n    case True\n    with Test show ?thesis by (auto split: if_splits prod.splits simp: atms_def elim: ok_mono)\n  next\n    case False\n    with Test show ?thesis by (auto split: if_splits prod.splits simp: atms_def not_Neg_cases elim: ok_mono)\n  qed\nnext\n  case (Plus r1 r2)\n  then show ?case by (fastforce simp: ok_shift atms_def elim: ok_mono split: if_splits prod.splits)\nnext\n  case (Times r1 r2)\n  then show ?case by (fastforce simp: ok_shift atms_def elim: ok_mono split: if_splits prod.splits)\nnext\n  case (Star r)\n  then show ?case by (auto simp: atms_def elim: ok_mono split: if_splits prod.splits)\nqed\n\nlemma from_mregex_shift: \"from_mregex (shift r (length xs)) (xs @ ys) = from_mregex r ys\"\n  by (induct r) (auto simp: nth_append)\n\nlemma from_mregex_to_mregex: \"safe_regex m g r \\<Longrightarrow> case_prod from_mregex (to_mregex r) = r\"\n  by (induct r rule: safe_regex.induct)\n    (auto dest: to_mregex_ok intro!: from_mregex_cong simp: nth_append from_mregex_shift cases_Neg_iff\n      split: prod.splits modality.splits)\n\nlemma from_mregex_eq: \"safe_regex m g r \\<Longrightarrow> to_mregex r = (mr, \\<phi>s) \\<Longrightarrow> from_mregex mr \\<phi>s = r\"\n  using from_mregex_to_mregex[of m g r] by auto\n\nlemma from_mregex_to_mregex_exec: \"safe_regex m g r \\<Longrightarrow> case_prod from_mregex (to_mregex_exec r xs) = r\"\nproof (induct r arbitrary: xs rule: safe_regex_induct)\n  case (Plus b g r s)\n  from Plus(3) Plus(1)[of xs] Plus(2)[of \"snd (to_mregex_exec r xs)\"] show ?case\n    by (auto split: prod.splits simp: nth_append dest: to_mregex_exec_ok\n        intro!: from_mregex_cong[where m = \"length (snd (to_mregex_exec r xs))\"])\nnext\n  case (TimesF g r s)\n  from TimesF(3) TimesF(2)[of xs] TimesF(1)[of \"snd (to_mregex_exec r xs)\"] show ?case\n    by (auto split: prod.splits simp: nth_append dest: to_mregex_exec_ok\n        intro!: from_mregex_cong[where m = \"length (snd (to_mregex_exec r xs))\"])\nnext\n  case (TimesP g r s)\n  from TimesP(3) TimesP(1)[of xs] TimesP(2)[of \"snd (to_mregex_exec r xs)\"] show ?case\n    by (auto split: prod.splits simp: nth_append dest: to_mregex_exec_ok\n        intro!: from_mregex_cong[where m = \"length (snd (to_mregex_exec r xs))\"])\nnext\n  case (Star b g r)\n  from Star(2) Star(1)[of xs] show ?case\n    by (auto split: prod.splits)\nqed (auto split: prod.splits simp: cases_Neg_iff)\n\n\nderive linorder mregex\n\nsubsubsection \\<open>LPD\\<close>\n\ndefinition saturate where\n  \"saturate f = while (\\<lambda>S. f S \\<noteq> S) f\"\n\nlemma saturate_code[code]:\n  \"saturate f S = (let S' = f S in if S' = S then S else saturate f S')\"\n  unfolding saturate_def Let_def\n  by (subst while_unfold) auto\n\ndefinition \"MTimesL r S = MTimes r ` S\"\ndefinition \"MTimesR R s = (\\<lambda>r. MTimes r s) ` R\"\n\nprimrec LPD where\n  \"LPD (MSkip n) = (case n of 0 \\<Rightarrow> {} | Suc m \\<Rightarrow> {MSkip m})\"\n| \"LPD (MTestPos \\<phi>) = {}\"\n| \"LPD (MTestNeg \\<phi>) = {}\"\n| \"LPD (MPlus r s) = (LPD r \\<union> LPD s)\"\n| \"LPD (MTimes r s) = MTimesR (LPD r) s \\<union> LPD s\"\n| \"LPD (MStar r) = MTimesR (LPD r) (MStar r)\"\n\nprimrec LPDi where\n  \"LPDi 0 r = {r}\"\n| \"LPDi (Suc i) r = (\\<Union>s \\<in> LPD r. LPDi i s)\"\n\nlemma LPDi_Suc_alt: \"LPDi (Suc i) r = (\\<Union>s \\<in> LPDi i r. LPD s)\"\n  by (induct i arbitrary: r) fastforce+\n\ndefinition \"LPDs r = (\\<Union>i. LPDi i r)\"\n\nlemma LPDs_refl: \"r \\<in> LPDs r\"\n  by (auto simp: LPDs_def intro: exI[of _ 0])\nlemma LPDs_trans: \"r \\<in> LPD s \\<Longrightarrow> s \\<in> LPDs t \\<Longrightarrow> r \\<in> LPDs t\"\n  by (force simp: LPDs_def LPDi_Suc_alt simp del: LPDi.simps intro: exI[of _ \"Suc _\"])\n\nlemma LPDi_Test:\n  \"LPDi i (MSkip 0) \\<subseteq> {MSkip 0}\"\n  \"LPDi i (MTestPos \\<phi>) \\<subseteq> {MTestPos \\<phi>}\"\n  \"LPDi i (MTestNeg \\<phi>) \\<subseteq> {MTestNeg \\<phi>}\"\n  by (induct i) auto\n\nlemma LPDs_Test:\n  \"LPDs (MSkip 0) \\<subseteq> {MSkip 0}\"\n  \"LPDs (MTestPos \\<phi>) \\<subseteq> {MTestPos \\<phi>}\"\n  \"LPDs (MTestNeg \\<phi>) \\<subseteq> {MTestNeg \\<phi>}\"\n  unfolding LPDs_def using LPDi_Test by blast+\n\nlemma LPDi_MSkip: \"LPDi i (MSkip n) \\<subseteq> MSkip ` {i. i \\<le> n}\"\n  by (induct i arbitrary: n) (auto dest: set_mp[OF LPDi_Test(1)] simp: le_Suc_eq split: nat.splits)\n\nlemma LPDs_MSkip: \"LPDs (MSkip n) \\<subseteq> MSkip ` {i. i \\<le> n}\"\n  unfolding LPDs_def using LPDi_MSkip by auto\n\nlemma LPDi_Plus: \"LPDi i (MPlus r s) \\<subseteq> {MPlus r s} \\<union> LPDi i r \\<union> LPDi i s\"\n  by (induct i arbitrary: r s) auto\n\nlemma LPDs_Plus: \"LPDs (MPlus r s) \\<subseteq> {MPlus r s} \\<union> LPDs r \\<union> LPDs s\"\n  unfolding LPDs_def using LPDi_Plus[of _ r s] by auto\n\nlemma LPDi_Times:\n  \"LPDi i (MTimes r s) \\<subseteq> {MTimes r s} \\<union> MTimesR (\\<Union>j \\<le> i. LPDi j r) s \\<union> (\\<Union>j \\<le> i. LPDi j s)\"\nproof (induct i arbitrary: r s)\n  case (Suc i)\n  show ?case\n    by (fastforce simp: MTimesR_def dest: bspec[of _ _ \"Suc _\"] dest!: set_mp[OF Suc])\nqed simp\n\nlemma LPDs_Times: \"LPDs (MTimes r s) \\<subseteq> {MTimes r s} \\<union> MTimesR (LPDs r) s \\<union> LPDs s\"\n  unfolding LPDs_def using LPDi_Times[of _ r s] by (force simp: MTimesR_def)\n\nlemma LPDi_Star: \"j \\<le> i \\<Longrightarrow> LPDi j (MStar r) \\<subseteq> {MStar r} \\<union> MTimesR (\\<Union>j \\<le> i. LPDi j r) (MStar r)\"\nproof (induct i arbitrary: j r)\n  case (Suc i)\n  from Suc(2) show ?case\n    by (auto 0 5 simp: MTimesR_def image_iff le_Suc_eq\n        dest: bspec[of _ _ \"Suc 0\"] bspec[of _ _ \"Suc _\"] set_mp[OF Suc(1)] dest!: set_mp[OF LPDi_Times])\nqed simp\n\nlemma LPDs_Star: \"LPDs (MStar r) \\<subseteq> {MStar r} \\<union> MTimesR (LPDs r) (MStar r)\"\n  unfolding LPDs_def using LPDi_Star[OF order_refl, of _ r] by (force simp: MTimesR_def)\n\nlemma finite_LPDs: \"finite (LPDs r)\"\nproof (induct r)\n  case (MSkip n)\n  then show ?case by (intro finite_subset[OF LPDs_MSkip]) simp\nnext\n  case (MTestPos \\<phi>)\n  then show ?case by (intro finite_subset[OF LPDs_Test(2)]) simp\nnext\n  case (MTestNeg \\<phi>)\n  then show ?case by (intro finite_subset[OF LPDs_Test(3)]) simp\nnext\n  case (MPlus r s)\n  then show ?case by (intro finite_subset[OF LPDs_Plus]) simp\nnext\n  case (MTimes r s)\n  then show ?case by (intro finite_subset[OF LPDs_Times]) (simp add: MTimesR_def)\nnext\n  case (MStar r)\n  then show ?case by (intro finite_subset[OF LPDs_Star]) (simp add: MTimesR_def)\nqed\n\ncontext begin\n\nprivate abbreviation (input) \"addLPD r \\<equiv> \\<lambda>S. insert r S \\<union> Set.bind (insert r S) LPD\"\n\nprivate lemma mono_addLPD: \"mono (addLPD r)\"\n  unfolding mono_def Set.bind_def by auto\n\nprivate lemma LPDs_aux1: \"lfp (addLPD r) \\<subseteq> LPDs r\"\n  by (rule lfp_induct[OF mono_addLPD], auto intro: LPDs_refl LPDs_trans simp: Set.bind_def)\n\nprivate lemma LPDs_aux2: \"LPDi i r \\<subseteq> lfp (addLPD r)\"\nproof (induct i)\n  case 0\n  then show ?case\n    by (subst lfp_unfold[OF mono_addLPD]) auto\nnext\n  case (Suc i)\n  then show ?case\n    by (subst lfp_unfold[OF mono_addLPD]) (auto simp: LPDi_Suc_alt simp del: LPDi.simps)\nqed\n\nlemma LPDs_alt: \"LPDs r = lfp (addLPD r)\"\n  using LPDs_aux1 LPDs_aux2 by (force simp: LPDs_def)\n\nlemma LPDs_code[code]:\n  \"LPDs r = saturate (addLPD r) {}\"\n  unfolding LPDs_alt saturate_def\n  by (rule lfp_while[OF mono_addLPD _ finite_LPDs, of r]) (auto simp: LPDs_refl LPDs_trans Set.bind_def)\n\nend\n\nsubsubsection \\<open>RPD\\<close>\n\nprimrec RPD where\n  \"RPD (MSkip n) = (case n of 0 \\<Rightarrow> {} | Suc m \\<Rightarrow> {MSkip m})\"\n| \"RPD (MTestPos \\<phi>) = {}\"\n| \"RPD (MTestNeg \\<phi>) = {}\"\n| \"RPD (MPlus r s) = (RPD r \\<union> RPD s)\"\n| \"RPD (MTimes r s) = MTimesL r (RPD s) \\<union> RPD r\"\n| \"RPD (MStar r) = MTimesL (MStar r) (RPD r)\"\n\nprimrec RPDi where\n  \"RPDi 0 r = {r}\"\n| \"RPDi (Suc i) r = (\\<Union>s \\<in> RPD r. RPDi i s)\"\n\nlemma RPDi_Suc_alt: \"RPDi (Suc i) r = (\\<Union>s \\<in> RPDi i r. RPD s)\"\n  by (induct i arbitrary: r) fastforce+\n\ndefinition \"RPDs r = (\\<Union>i. RPDi i r)\"\n\nlemma RPDs_refl: \"r \\<in> RPDs r\"\n  by (auto simp: RPDs_def intro: exI[of _ 0])\nlemma RPDs_trans: \"r \\<in> RPD s \\<Longrightarrow> s \\<in> RPDs t \\<Longrightarrow> r \\<in> RPDs t\"\n  by (force simp: RPDs_def RPDi_Suc_alt simp del: RPDi.simps intro: exI[of _ \"Suc _\"])\n\nlemma RPDi_Test:\n  \"RPDi i (MSkip 0) \\<subseteq> {MSkip 0}\"\n  \"RPDi i (MTestPos \\<phi>) \\<subseteq> {MTestPos \\<phi>}\"\n  \"RPDi i (MTestNeg \\<phi>) \\<subseteq> {MTestNeg \\<phi>}\"\n  by (induct i) auto\n\nlemma RPDs_Test:\n  \"RPDs (MSkip 0) \\<subseteq> {MSkip 0}\"\n  \"RPDs (MTestPos \\<phi>) \\<subseteq> {MTestPos \\<phi>}\"\n  \"RPDs (MTestNeg \\<phi>) \\<subseteq> {MTestNeg \\<phi>}\"\n  unfolding RPDs_def using RPDi_Test by blast+\n\nlemma RPDi_MSkip: \"RPDi i (MSkip n) \\<subseteq> MSkip ` {i. i \\<le> n}\"\n  by (induct i arbitrary: n) (auto dest: set_mp[OF RPDi_Test(1)] simp: le_Suc_eq split: nat.splits)\n\nlemma RPDs_MSkip: \"RPDs (MSkip n) \\<subseteq> MSkip ` {i. i \\<le> n}\"\n  unfolding RPDs_def using RPDi_MSkip by auto\n\nlemma RPDi_Plus: \"RPDi i (MPlus r s) \\<subseteq> {MPlus r s} \\<union> RPDi i r \\<union> RPDi i s\"\n  by (induct i arbitrary: r s) auto\n\nlemma RPDi_Suc_RPD_Plus:\n  \"RPDi (Suc i) r \\<subseteq> RPDs (MPlus r s)\"\n  \"RPDi (Suc i) s \\<subseteq> RPDs (MPlus r s)\"\n  unfolding RPDs_def by (force intro!: exI[of _ \"Suc i\"])+\n\nlemma RPDs_Plus: \"RPDs (MPlus r s) \\<subseteq> {MPlus r s} \\<union> RPDs r \\<union> RPDs s\"\n  unfolding RPDs_def using RPDi_Plus[of _ r s] by auto\n\nlemma RPDi_Times:\n  \"RPDi i (MTimes r s) \\<subseteq> {MTimes r s} \\<union> MTimesL r (\\<Union>j \\<le> i. RPDi j s) \\<union> (\\<Union>j \\<le> i. RPDi j r)\"\nproof (induct i arbitrary: r s)\n  case (Suc i)\n  show ?case\n    by (fastforce simp: MTimesL_def dest: bspec[of _ _ \"Suc _\"] dest!: set_mp[OF Suc])\nqed simp\n\nlemma RPDs_Times: \"RPDs (MTimes r s) \\<subseteq> {MTimes r s} \\<union> MTimesL r (RPDs s) \\<union> RPDs r\"\n  unfolding RPDs_def using RPDi_Times[of _ r s] by (force simp: MTimesL_def)\n\nlemma RPDi_Star: \"j \\<le> i \\<Longrightarrow> RPDi j (MStar r) \\<subseteq> {MStar r} \\<union> MTimesL (MStar r) (\\<Union>j \\<le> i. RPDi j r)\"\nproof (induct i arbitrary: j r)\n  case (Suc i)\n  from Suc(2) show ?case\n    by (auto 0 5 simp: MTimesL_def image_iff le_Suc_eq\n        dest: bspec[of _ _ \"Suc 0\"] bspec[of _ _ \"Suc _\"] set_mp[OF Suc(1)] dest!: set_mp[OF RPDi_Times])\nqed simp\n\nlemma RPDs_Star: \"RPDs (MStar r) \\<subseteq> {MStar r} \\<union> MTimesL (MStar r) (RPDs r)\"\n  unfolding RPDs_def using RPDi_Star[OF order_refl, of _ r] by (force simp: MTimesL_def)\n\nlemma finite_RPDs: \"finite (RPDs r)\"\nproof (induct r)\n  case MSkip\n  then show ?case by (intro finite_subset[OF RPDs_MSkip]) simp\nnext\n  case (MTestPos \\<phi>)\n  then show ?case by (intro finite_subset[OF RPDs_Test(2)]) simp\nnext\n  case (MTestNeg \\<phi>)\n  then show ?case by (intro finite_subset[OF RPDs_Test(3)]) simp\nnext\n  case (MPlus r s)\n  then show ?case by (intro finite_subset[OF RPDs_Plus]) simp\nnext\n  case (MTimes r s)\n  then show ?case by (intro finite_subset[OF RPDs_Times]) (simp add: MTimesL_def)\nnext\n  case (MStar r)\n  then show ?case by (intro finite_subset[OF RPDs_Star]) (simp add: MTimesL_def)\nqed\n\ncontext begin\n\nprivate abbreviation (input) \"addRPD r \\<equiv> \\<lambda>S. insert r S \\<union> Set.bind (insert r S) RPD\"\n\nprivate lemma mono_addRPD: \"mono (addRPD r)\"\n  unfolding mono_def Set.bind_def by auto\n\nprivate lemma RPDs_aux1: \"lfp (addRPD r) \\<subseteq> RPDs r\"\n  by (rule lfp_induct[OF mono_addRPD], auto intro: RPDs_refl RPDs_trans simp: Set.bind_def)\n\nprivate lemma RPDs_aux2: \"RPDi i r \\<subseteq> lfp (addRPD r)\"\nproof (induct i)\n  case 0\n  then show ?case\n    by (subst lfp_unfold[OF mono_addRPD]) auto\nnext\n  case (Suc i)\n  then show ?case\n    by (subst lfp_unfold[OF mono_addRPD]) (auto simp: RPDi_Suc_alt simp del: RPDi.simps)\nqed\n\nlemma RPDs_alt: \"RPDs r = lfp (addRPD r)\"\n  using RPDs_aux1 RPDs_aux2 by (force simp: RPDs_def)\n\nlemma RPDs_code[code]:\n  \"RPDs r = saturate (addRPD r) {}\"\n  unfolding RPDs_alt saturate_def\n  by (rule lfp_while[OF mono_addRPD _ finite_RPDs, of r]) (auto simp: RPDs_refl RPDs_trans Set.bind_def)\n\nend\n\nsubsection \\<open>The executable monitor\\<close>\n\ntype_synonym ts = nat\n\ntype_synonym 'a mbuf2 = \"'a table list \\<times> 'a table list\"\ntype_synonym 'a mbufn = \"'a table list list\"\ntype_synonym 'a msaux = \"(ts \\<times> 'a table) list\"\ntype_synonym 'a muaux = \"(ts \\<times> 'a table \\<times> 'a table) list\"\ntype_synonym 'a mr\\<delta>aux = \"(ts \\<times> (mregex, 'a table) mapping) list\"\ntype_synonym 'a ml\\<delta>aux = \"(ts \\<times> 'a table list \\<times> 'a table) list\"\n\ndatatype mconstraint = MEq | MLess | MLessEq\n\nrecord args =\n  args_ivl :: \\<I>\n  args_n :: nat\n  args_L :: \"nat set\"\n  args_R :: \"nat set\"\n  args_pos :: bool\n\ndatatype (dead 'msaux, dead 'muaux) mformula =\n  MRel \"event_data table\"\n  | MPred Formula.name \"Formula.trm list\"\n  | MLet Formula.name nat nat \"('msaux, 'muaux) mformula\" \"('msaux, 'muaux) mformula\"\n  | MAnd \"nat set\" \"('msaux, 'muaux) mformula\" bool \"nat set\" \"('msaux, 'muaux) mformula\" \"event_data mbuf2\"\n  | MAndAssign \"('msaux, 'muaux) mformula\" \"nat \\<times> Formula.trm\"\n  | MAndRel \"('msaux, 'muaux) mformula\" \"Formula.trm \\<times> bool \\<times> mconstraint \\<times> Formula.trm\"\n  | MAnds \"nat set list\" \"nat set list\" \"('msaux, 'muaux) mformula list\" \"event_data mbufn\"\n  | MOr \"('msaux, 'muaux) mformula\" \"('msaux, 'muaux) mformula\" \"event_data mbuf2\"\n  | MNeg \"('msaux, 'muaux) mformula\"\n  | MExists \"('msaux, 'muaux) mformula\"\n  | MAgg bool nat Formula.agg_op nat \"Formula.trm\" \"('msaux, 'muaux) mformula\"\n  | MPrev \\<I> \"('msaux, 'muaux) mformula\" bool \"event_data table list\" \"ts list\"\n  | MNext \\<I> \"('msaux, 'muaux) mformula\" bool \"ts list\"\n  | MSince args \"('msaux, 'muaux) mformula\" \"('msaux, 'muaux) mformula\" \"event_data mbuf2\" \"ts list\" \"'msaux\"\n  | MUntil args \"('msaux, 'muaux) mformula\" \"('msaux, 'muaux) mformula\" \"event_data mbuf2\" \"ts list\" \"'muaux\"\n  | MMatchP \\<I> \"mregex\" \"mregex list\" \"('msaux, 'muaux) mformula list\" \"event_data mbufn\" \"ts list\" \"event_data mr\\<delta>aux\"\n  | MMatchF \\<I> \"mregex\" \"mregex list\" \"('msaux, 'muaux) mformula list\" \"event_data mbufn\" \"ts list\" \"event_data ml\\<delta>aux\"\n\nrecord ('msaux, 'muaux) mstate =\n  mstate_i :: nat\n  mstate_m :: \"('msaux, 'muaux) mformula\"\n  mstate_n :: nat\n\nfun eq_rel :: \"nat \\<Rightarrow> Formula.trm \\<Rightarrow> Formula.trm \\<Rightarrow> event_data table\" where\n  \"eq_rel n (Formula.Const x) (Formula.Const y) = (if x = y then unit_table n else empty_table)\"\n| \"eq_rel n (Formula.Var x) (Formula.Const y) = singleton_table n x y\"\n| \"eq_rel n (Formula.Const x) (Formula.Var y) = singleton_table n y x\"\n| \"eq_rel n _ _ = undefined\"\n\nlemma regex_atms_size: \"x \\<in> regex.atms r \\<Longrightarrow> size x < regex.size_regex size r\"\n  by (induct r) auto\n\nlemma atms_size:\n  assumes \"x \\<in> atms r\"\n  shows \"size x < Regex.size_regex size r\"\nproof -\n  { fix y assume \"y \\<in> regex.atms r\" \"case y of formula.Neg z \\<Rightarrow> x = z | _ \\<Rightarrow> False\"\n    then have \"size x < Regex.size_regex size r\"\n      by (cases y rule: formula.exhaust) (auto dest: regex_atms_size)\n  }\n  with assms show ?thesis\n    unfolding atms_def\n    by (auto split: formula.splits dest: regex_atms_size)\nqed\n\ndefinition init_args :: \"\\<I> \\<Rightarrow> nat \\<Rightarrow> nat set \\<Rightarrow> nat set \\<Rightarrow> bool \\<Rightarrow> args\" where\n  \"init_args I n L R pos = \\<lparr>args_ivl = I, args_n = n, args_L = L, args_R = R, args_pos = pos\\<rparr>\"\n\nlocale msaux =\n  fixes valid_msaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'msaux \\<Rightarrow> event_data msaux \\<Rightarrow> bool\"\n    and init_msaux :: \"args \\<Rightarrow> 'msaux\"\n    and add_new_ts_msaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'msaux \\<Rightarrow> 'msaux\"\n    and join_msaux :: \"args \\<Rightarrow> event_data table \\<Rightarrow> 'msaux \\<Rightarrow> 'msaux\"\n    and add_new_table_msaux :: \"args \\<Rightarrow> event_data table \\<Rightarrow> 'msaux \\<Rightarrow> 'msaux\"\n    and result_msaux :: \"args \\<Rightarrow> 'msaux \\<Rightarrow> event_data table\"\n  assumes valid_init_msaux: \"L \\<subseteq> R \\<Longrightarrow>\n    valid_msaux (init_args I n L R pos) 0 (init_msaux (init_args I n L R pos)) []\"\n  assumes valid_add_new_ts_msaux: \"valid_msaux args cur aux auxlist \\<Longrightarrow> nt \\<ge> cur \\<Longrightarrow>\n    valid_msaux args nt (add_new_ts_msaux args nt aux)\n    (filter (\\<lambda>(t, rel). enat (nt - t) \\<le> right (args_ivl args)) auxlist)\"\n  assumes valid_join_msaux: \"valid_msaux args cur aux auxlist \\<Longrightarrow>\n    table (args_n args) (args_L args) rel1 \\<Longrightarrow>\n    valid_msaux args cur (join_msaux args rel1 aux)\n    (map (\\<lambda>(t, rel). (t, join rel (args_pos args) rel1)) auxlist)\"\n  assumes valid_add_new_table_msaux: \"valid_msaux args cur aux auxlist \\<Longrightarrow>\n    table (args_n args) (args_R args) rel2 \\<Longrightarrow>\n    valid_msaux args cur (add_new_table_msaux args rel2 aux)\n    (case auxlist of\n      [] => [(cur, rel2)]\n    | ((t, y) # ts) \\<Rightarrow> if t = cur then (t, y \\<union> rel2) # ts else (cur, rel2) # auxlist)\"\n    and valid_result_msaux: \"valid_msaux args cur aux auxlist \\<Longrightarrow> result_msaux args aux =\n    foldr (\\<union>) [rel. (t, rel) \\<leftarrow> auxlist, left (args_ivl args) \\<le> cur - t] {}\"\n\nfun check_before :: \"\\<I> \\<Rightarrow> ts \\<Rightarrow> (ts \\<times> 'a \\<times> 'b) \\<Rightarrow> bool\" where\n  \"check_before I dt (t, a, b) \\<longleftrightarrow> enat t + right I < enat dt\"\n\nfun proj_thd :: \"('a \\<times> 'b \\<times> 'c) \\<Rightarrow> 'c\" where\n  \"proj_thd (t, a1, a2) = a2\"\n\ndefinition update_until :: \"args \\<Rightarrow> event_data table \\<Rightarrow> event_data table \\<Rightarrow> ts \\<Rightarrow> event_data muaux \\<Rightarrow> event_data muaux\" where\n  \"update_until args rel1 rel2 nt aux =\n    (map (\\<lambda>x. case x of (t, a1, a2) \\<Rightarrow> (t, if (args_pos args) then join a1 True rel1 else a1 \\<union> rel1,\n      if mem (nt - t) (args_ivl args) then a2 \\<union> join rel2 (args_pos args) a1 else a2)) aux) @\n    [(nt, rel1, if left (args_ivl args) = 0 then rel2 else empty_table)]\"\n\nlemma map_proj_thd_update_until: \"map proj_thd (takeWhile (check_before (args_ivl args) nt) auxlist) =\n  map proj_thd (takeWhile (check_before (args_ivl args) nt) (update_until args rel1 rel2 nt auxlist))\"\nproof (induction auxlist)\n  case Nil\n  then show ?case by (simp add: update_until_def)\nnext\n  case (Cons a auxlist)\n  then show ?case\n    by (cases \"right (args_ivl args)\") (auto simp add: update_until_def split: if_splits prod.splits)\nqed\n\nfun eval_until :: \"\\<I> \\<Rightarrow> ts \\<Rightarrow> event_data muaux \\<Rightarrow> event_data table list \\<times> event_data muaux\" where\n  \"eval_until I nt [] = ([], [])\"\n| \"eval_until I nt ((t, a1, a2) # aux) = (if t + right I < nt then\n    (let (xs, aux) = eval_until I nt aux in (a2 # xs, aux)) else ([], (t, a1, a2) # aux))\"\n\nlemma eval_until_length:\n  \"eval_until I nt auxlist = (res, auxlist') \\<Longrightarrow> length auxlist = length res + length auxlist'\"\n  by (induction I nt auxlist arbitrary: res auxlist' rule: eval_until.induct)\n    (auto split: if_splits prod.splits)\n\nlemma eval_until_res: \"eval_until I nt auxlist = (res, auxlist') \\<Longrightarrow>\n  res = map proj_thd (takeWhile (check_before I nt) auxlist)\"\n  by (induction I nt auxlist arbitrary: res auxlist' rule: eval_until.induct)\n    (auto split: prod.splits)\n\nlemma eval_until_auxlist': \"eval_until I nt auxlist = (res, auxlist') \\<Longrightarrow>\n  auxlist' = drop (length res) auxlist\"\n  by (induction I nt auxlist arbitrary: res auxlist' rule: eval_until.induct)\n    (auto split: if_splits prod.splits)\n\nlocale muaux =\n  fixes valid_muaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'muaux \\<Rightarrow> event_data muaux \\<Rightarrow> bool\"\n    and init_muaux :: \"args \\<Rightarrow> 'muaux\"\n    and add_new_muaux :: \"args \\<Rightarrow> event_data table \\<Rightarrow> event_data table \\<Rightarrow> ts \\<Rightarrow> 'muaux \\<Rightarrow> 'muaux\"\n    and length_muaux :: \"args \\<Rightarrow> 'muaux \\<Rightarrow> nat\"\n    and eval_muaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'muaux \\<Rightarrow> event_data table list \\<times> 'muaux\"\n  assumes valid_init_muaux: \"L \\<subseteq> R \\<Longrightarrow>\n    valid_muaux (init_args I n L R pos) 0 (init_muaux (init_args I n L R pos)) []\"\n  assumes valid_add_new_muaux: \"valid_muaux args cur aux auxlist \\<Longrightarrow>\n    table (args_n args) (args_L args) rel1 \\<Longrightarrow>\n    table (args_n args) (args_R args) rel2 \\<Longrightarrow>\n    nt \\<ge> cur \\<Longrightarrow>\n    valid_muaux args nt (add_new_muaux args rel1 rel2 nt aux)\n    (update_until args rel1 rel2 nt auxlist)\"\n  assumes valid_length_muaux: \"valid_muaux args cur aux auxlist \\<Longrightarrow> length_muaux args aux = length auxlist\"\n  assumes valid_eval_muaux: \"valid_muaux args cur aux auxlist \\<Longrightarrow> nt \\<ge> cur \\<Longrightarrow>\n    eval_muaux args nt aux = (res, aux') \\<Longrightarrow> eval_until (args_ivl args) nt auxlist = (res', auxlist') \\<Longrightarrow>\n    res = res' \\<and> valid_muaux args cur aux' auxlist'\"\n\nlocale maux = msaux valid_msaux init_msaux add_new_ts_msaux join_msaux add_new_table_msaux result_msaux +\n  muaux valid_muaux init_muaux add_new_muaux length_muaux eval_muaux\n  for valid_msaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'msaux \\<Rightarrow> event_data msaux \\<Rightarrow> bool\"\n    and init_msaux :: \"args \\<Rightarrow> 'msaux\"\n    and add_new_ts_msaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'msaux \\<Rightarrow> 'msaux\"\n    and join_msaux :: \"args \\<Rightarrow> event_data table \\<Rightarrow> 'msaux \\<Rightarrow> 'msaux\"\n    and add_new_table_msaux :: \"args \\<Rightarrow> event_data table \\<Rightarrow> 'msaux \\<Rightarrow> 'msaux\"\n    and result_msaux :: \"args \\<Rightarrow> 'msaux \\<Rightarrow> event_data table\"\n    and valid_muaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'muaux \\<Rightarrow> event_data muaux \\<Rightarrow> bool\"\n    and init_muaux :: \"args \\<Rightarrow> 'muaux\"\n    and add_new_muaux :: \"args \\<Rightarrow> event_data table \\<Rightarrow> event_data table \\<Rightarrow> ts \\<Rightarrow> 'muaux \\<Rightarrow> 'muaux\"\n    and length_muaux :: \"args \\<Rightarrow> 'muaux \\<Rightarrow> nat\"\n    and eval_muaux :: \"args \\<Rightarrow> nat \\<Rightarrow> 'muaux \\<Rightarrow> event_data table list \\<times> 'muaux\"\n\nfun split_assignment :: \"nat set \\<Rightarrow> Formula.formula \\<Rightarrow> nat \\<times> Formula.trm\" where\n  \"split_assignment X (Formula.Eq t1 t2) = (case (t1, t2) of\n      (Formula.Var x, Formula.Var y) \\<Rightarrow> if x \\<in> X then (y, t1) else (x, t2)\n    | (Formula.Var x, _) \\<Rightarrow> (x, t2)\n    | (_, Formula.Var y) \\<Rightarrow> (y, t1))\"\n| \"split_assignment _ _ = undefined\"\n\nfun split_constraint :: \"Formula.formula \\<Rightarrow> Formula.trm \\<times> bool \\<times> mconstraint \\<times> Formula.trm\" where\n  \"split_constraint (Formula.Eq t1 t2) = (t1, True, MEq, t2)\"\n| \"split_constraint (Formula.Less t1 t2) = (t1, True, MLess, t2)\"\n| \"split_constraint (Formula.LessEq t1 t2) = (t1, True, MLessEq, t2)\"\n| \"split_constraint (Formula.Neg (Formula.Eq t1 t2)) = (t1, False, MEq, t2)\"\n| \"split_constraint (Formula.Neg (Formula.Less t1 t2)) = (t1, False, MLess, t2)\"\n| \"split_constraint (Formula.Neg (Formula.LessEq t1 t2)) = (t1, False, MLessEq, t2)\"\n| \"split_constraint _ = undefined\"\n\nfunction (in maux) (sequential) minit0 :: \"nat \\<Rightarrow> Formula.formula \\<Rightarrow> ('msaux, 'muaux) mformula\" where\n  \"minit0 n (Formula.Neg \\<phi>) = (if fv \\<phi> = {} then MNeg (minit0 n \\<phi>) else MRel empty_table)\"\n| \"minit0 n (Formula.Eq t1 t2) = MRel (eq_rel n t1 t2)\"\n| \"minit0 n (Formula.Pred e ts) = MPred e ts\"\n| \"minit0 n (Formula.Let p b \\<phi> \\<psi>) = MLet p (Formula.nfv \\<phi>) b (minit0 (Formula.nfv \\<phi>) \\<phi>) (minit0 n \\<psi>)\"\n| \"minit0 n (Formula.Or \\<phi> \\<psi>) = MOr (minit0 n \\<phi>) (minit0 n \\<psi>) ([], [])\"\n| \"minit0 n (Formula.And \\<phi> \\<psi>) = (if safe_assignment (fv \\<phi>) \\<psi> then\n      MAndAssign (minit0 n \\<phi>) (split_assignment (fv \\<phi>) \\<psi>)\n    else if safe_formula \\<psi> then\n      MAnd (fv \\<phi>) (minit0 n \\<phi>) True (fv \\<psi>) (minit0 n \\<psi>) ([], [])\n    else if is_constraint \\<psi> then\n      MAndRel (minit0 n \\<phi>) (split_constraint \\<psi>)\n    else (case \\<psi> of Formula.Neg \\<psi> \\<Rightarrow>\n      MAnd (fv \\<phi>) (minit0 n \\<phi>) False (fv \\<psi>) (minit0 n \\<psi>) ([], [])))\"\n| \"minit0 n (Formula.Ands l) = (let (pos, neg) = partition safe_formula l in\n    let mpos = map (minit0 n) pos in\n    let mneg = map (minit0 n) (map remove_neg neg) in\n    let vpos = map fv pos in\n    let vneg = map fv neg in\n    MAnds vpos vneg (mpos @ mneg) (replicate (length l) []))\"\n| \"minit0 n (Formula.Exists \\<phi>) = MExists (minit0 (Suc n) \\<phi>)\"\n| \"minit0 n (Formula.Agg y \\<omega> b f \\<phi>) = MAgg (fv \\<phi> \\<subseteq> {0..<b}) y \\<omega> b f (minit0 (b + n) \\<phi>)\"\n| \"minit0 n (Formula.Prev I \\<phi>) = MPrev I (minit0 n \\<phi>) True [] []\"\n| \"minit0 n (Formula.Next I \\<phi>) = MNext I (minit0 n \\<phi>) True []\"\n| \"minit0 n (Formula.Since \\<phi> I \\<psi>) = (if safe_formula \\<phi>\n    then MSince (init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) True) (minit0 n \\<phi>) (minit0 n \\<psi>) ([], []) [] (init_msaux (init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) True))\n    else (case \\<phi> of\n      Formula.Neg \\<phi> \\<Rightarrow> MSince (init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) False) (minit0 n \\<phi>) (minit0 n \\<psi>) ([], []) [] (init_msaux (init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) False))\n    | _ \\<Rightarrow> undefined))\"\n| \"minit0 n (Formula.Until \\<phi> I \\<psi>) = (if safe_formula \\<phi>\n    then MUntil (init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) True) (minit0 n \\<phi>) (minit0 n \\<psi>) ([], []) [] (init_muaux (init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) True))\n    else (case \\<phi> of\n      Formula.Neg \\<phi> \\<Rightarrow> MUntil (init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) False) (minit0 n \\<phi>) (minit0 n \\<psi>) ([], []) [] (init_muaux (init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) False))\n    | _ \\<Rightarrow> undefined))\"\n| \"minit0 n (Formula.MatchP I r) =\n    (let (mr, \\<phi>s) = to_mregex r\n    in MMatchP I mr (sorted_list_of_set (RPDs mr)) (map (minit0 n) \\<phi>s) (replicate (length \\<phi>s) []) [] [])\"\n| \"minit0 n (Formula.MatchF I r) =\n    (let (mr, \\<phi>s) = to_mregex r\n    in MMatchF I mr (sorted_list_of_set (LPDs mr)) (map (minit0 n) \\<phi>s) (replicate (length \\<phi>s) []) [] [])\"\n| \"minit0 n _ = undefined\"\n  by pat_completeness auto\ntermination (in maux)\n  by (relation \"measure (\\<lambda>(_, \\<phi>). size \\<phi>)\")\n    (auto simp: less_Suc_eq_le size_list_estimation' size_remove_neg\n      dest!: to_mregex_ok[OF sym] atms_size)\n\ndefinition (in maux) minit :: \"Formula.formula \\<Rightarrow> ('msaux, 'muaux) mstate\" where\n  \"minit \\<phi> = (let n = Formula.nfv \\<phi> in \\<lparr>mstate_i = 0, mstate_m = minit0 n \\<phi>, mstate_n = n\\<rparr>)\"\n\nfun mprev_next :: \"\\<I> \\<Rightarrow> event_data table list \\<Rightarrow> ts list \\<Rightarrow> event_data table list \\<times> event_data table list \\<times> ts list\" where\n  \"mprev_next I [] ts = ([], [], ts)\"\n| \"mprev_next I xs [] = ([], xs, [])\"\n| \"mprev_next I xs [t] = ([], xs, [t])\"\n| \"mprev_next I (x # xs) (t # t' # ts) = (let (ys, zs) = mprev_next I xs (t' # ts)\n    in ((if mem (t' - t) I then x else empty_table) # ys, zs))\"\n\nfun mbuf2_add :: \"event_data table list \\<Rightarrow> event_data table list \\<Rightarrow> event_data mbuf2 \\<Rightarrow> event_data mbuf2\" where\n  \"mbuf2_add xs' ys' (xs, ys) = (xs @ xs', ys @ ys')\"\n\nfun mbuf2_take :: \"(event_data table \\<Rightarrow> event_data table \\<Rightarrow> 'b) \\<Rightarrow> event_data mbuf2 \\<Rightarrow> 'b list \\<times> event_data mbuf2\" where\n  \"mbuf2_take f (x # xs, y # ys) = (let (zs, buf) = mbuf2_take f (xs, ys) in (f x y # zs, buf))\"\n| \"mbuf2_take f (xs, ys) = ([], (xs, ys))\"\n\nfun mbuf2t_take :: \"(event_data table \\<Rightarrow> event_data table \\<Rightarrow> ts \\<Rightarrow> 'b \\<Rightarrow> 'b) \\<Rightarrow> 'b \\<Rightarrow>\n    event_data mbuf2 \\<Rightarrow> ts list \\<Rightarrow> 'b \\<times> event_data mbuf2 \\<times> ts list\" where\n  \"mbuf2t_take f z (x # xs, y # ys) (t # ts) = mbuf2t_take f (f x y t z) (xs, ys) ts\"\n| \"mbuf2t_take f z (xs, ys) ts = (z, (xs, ys), ts)\"\n\nlemma size_list_length_diff1: \"xs \\<noteq> [] \\<Longrightarrow> [] \\<notin> set xs \\<Longrightarrow>\n  size_list (\\<lambda>xs. length xs - Suc 0) xs < size_list length xs\"\nproof (induct xs)\n  case (Cons x xs)\n  then show ?case\n    by (cases xs) auto\nqed simp\n\nfun mbufn_add :: \"event_data table list list \\<Rightarrow> event_data mbufn \\<Rightarrow> event_data mbufn\" where\n  \"mbufn_add xs' xs = List.map2 (@) xs xs'\"\n\nfunction mbufn_take :: \"(event_data table list \\<Rightarrow> 'b \\<Rightarrow> 'b) \\<Rightarrow> 'b \\<Rightarrow> event_data mbufn \\<Rightarrow> 'b \\<times> event_data mbufn\" where\n  \"mbufn_take f z buf = (if buf = [] \\<or> [] \\<in> set buf then (z, buf)\n    else mbufn_take f (f (map hd buf) z) (map tl buf))\"\n  by pat_completeness auto\ntermination by (relation \"measure (\\<lambda>(_, _, buf). size_list length buf)\")\n    (auto simp: comp_def Suc_le_eq size_list_length_diff1)\n\nfun mbufnt_take :: \"(event_data table list \\<Rightarrow> ts \\<Rightarrow> 'b \\<Rightarrow> 'b) \\<Rightarrow>\n    'b \\<Rightarrow> event_data mbufn \\<Rightarrow> ts list \\<Rightarrow> 'b \\<times> event_data mbufn \\<times> ts list\" where\n  \"mbufnt_take f z buf ts =\n    (if [] \\<in> set buf \\<or> ts = [] then (z, buf, ts)\n    else mbufnt_take f (f (map hd buf) (hd ts) z) (map tl buf) (tl ts))\"\n\nfun match :: \"Formula.trm list \\<Rightarrow> event_data list \\<Rightarrow> (nat \\<rightharpoonup> event_data) option\" where\n  \"match [] [] = Some Map.empty\"\n| \"match (Formula.Const x # ts) (y # ys) = (if x = y then match ts ys else None)\"\n| \"match (Formula.Var x # ts) (y # ys) = (case match ts ys of\n      None \\<Rightarrow> None\n    | Some f \\<Rightarrow> (case f x of\n        None \\<Rightarrow> Some (f(x \\<mapsto> y))\n      | Some z \\<Rightarrow> if y = z then Some f else None))\"\n| \"match _ _ = None\"\n\nfun meval_trm :: \"Formula.trm \\<Rightarrow> event_data tuple \\<Rightarrow> event_data\" where\n  \"meval_trm (Formula.Var x) v = the (v ! x)\"\n| \"meval_trm (Formula.Const x) v = x\"\n| \"meval_trm (Formula.Plus x y) v = meval_trm x v + meval_trm y v\"\n| \"meval_trm (Formula.Minus x y) v = meval_trm x v - meval_trm y v\"\n| \"meval_trm (Formula.UMinus x) v = - meval_trm x v\"\n| \"meval_trm (Formula.Mult x y) v = meval_trm x v * meval_trm y v\"\n| \"meval_trm (Formula.Div x y) v = meval_trm x v div meval_trm y v\"\n| \"meval_trm (Formula.Mod x y) v = meval_trm x v mod meval_trm y v\"\n| \"meval_trm (Formula.F2i x) v = EInt (integer_of_event_data (meval_trm x v))\"\n| \"meval_trm (Formula.I2f x) v = EFloat (double_of_event_data (meval_trm x v))\"\n\ndefinition eval_agg :: \"nat \\<Rightarrow> bool \\<Rightarrow> nat \\<Rightarrow> Formula.agg_op \\<Rightarrow> nat \\<Rightarrow> Formula.trm \\<Rightarrow>\n  event_data table \\<Rightarrow> event_data table\" where\n  \"eval_agg n g0 y \\<omega> b f rel = (if g0 \\<and> rel = empty_table\n    then singleton_table n y (eval_agg_op \\<omega> {})\n    else (\\<lambda>k.\n      let group = Set.filter (\\<lambda>x. drop b x = k) rel;\n        M = (\\<lambda>y. (y, ecard (Set.filter (\\<lambda>x. meval_trm f x = y) group))) ` meval_trm f ` group\n      in k[y:=Some (eval_agg_op \\<omega> M)]) ` (drop b) ` rel)\"\n\ndefinition (in maux) update_since :: \"args \\<Rightarrow> event_data table \\<Rightarrow> event_data table \\<Rightarrow> ts \\<Rightarrow>\n  'msaux \\<Rightarrow> event_data table \\<times> 'msaux\" where\n  \"update_since args rel1 rel2 nt aux =\n    (let aux0 = join_msaux args rel1 (add_new_ts_msaux args nt aux);\n         aux' = add_new_table_msaux args rel2 aux0\n    in (result_msaux args aux', aux'))\"\n\ndefinition \"lookup = Mapping.lookup_default empty_table\"\n\nfun \\<epsilon>_lax where\n  \"\\<epsilon>_lax guard \\<phi>s (MSkip n) = (if n = 0 then guard else empty_table)\"\n| \"\\<epsilon>_lax guard \\<phi>s (MTestPos i) = join guard True (\\<phi>s ! i)\"\n| \"\\<epsilon>_lax guard \\<phi>s (MTestNeg i) = join guard False (\\<phi>s ! i)\"\n| \"\\<epsilon>_lax guard \\<phi>s (MPlus r s) = \\<epsilon>_lax guard \\<phi>s r \\<union> \\<epsilon>_lax guard \\<phi>s s\"\n| \"\\<epsilon>_lax guard \\<phi>s (MTimes r s) = join (\\<epsilon>_lax guard \\<phi>s r) True (\\<epsilon>_lax guard \\<phi>s s)\"\n| \"\\<epsilon>_lax guard \\<phi>s (MStar r) = guard\"\n\nfun r\\<epsilon>_strict where\n  \"r\\<epsilon>_strict n \\<phi>s (MSkip m) = (if m = 0 then unit_table n else empty_table)\"\n| \"r\\<epsilon>_strict n \\<phi>s (MTestPos i) = \\<phi>s ! i\"\n| \"r\\<epsilon>_strict n \\<phi>s (MTestNeg i) = (if \\<phi>s ! i = empty_table then unit_table n else empty_table)\"\n| \"r\\<epsilon>_strict n \\<phi>s (MPlus r s) = r\\<epsilon>_strict n \\<phi>s r \\<union> r\\<epsilon>_strict n \\<phi>s s\"\n| \"r\\<epsilon>_strict n \\<phi>s (MTimes r s) = \\<epsilon>_lax (r\\<epsilon>_strict n \\<phi>s r) \\<phi>s s\"\n| \"r\\<epsilon>_strict n \\<phi>s (MStar r) = unit_table n\"\n\nfun l\\<epsilon>_strict where\n  \"l\\<epsilon>_strict n \\<phi>s (MSkip m) = (if m = 0 then unit_table n else empty_table)\"\n| \"l\\<epsilon>_strict n \\<phi>s (MTestPos i) = \\<phi>s ! i\"\n| \"l\\<epsilon>_strict n \\<phi>s (MTestNeg i) = (if \\<phi>s ! i = empty_table then unit_table n else empty_table)\"\n| \"l\\<epsilon>_strict n \\<phi>s (MPlus r s) = l\\<epsilon>_strict n \\<phi>s r \\<union> l\\<epsilon>_strict n \\<phi>s s\"\n| \"l\\<epsilon>_strict n \\<phi>s (MTimes r s) = \\<epsilon>_lax (l\\<epsilon>_strict n \\<phi>s s) \\<phi>s r\"\n| \"l\\<epsilon>_strict n \\<phi>s (MStar r) = unit_table n\"\n\nfun r\\<delta> :: \"(mregex \\<Rightarrow> mregex) \\<Rightarrow> (mregex, 'a table) mapping \\<Rightarrow> 'a table list \\<Rightarrow> mregex \\<Rightarrow> 'a table\"  where\n  \"r\\<delta> \\<kappa> X \\<phi>s (MSkip n) = (case n of 0 \\<Rightarrow> empty_table | Suc m \\<Rightarrow> lookup X (\\<kappa> (MSkip m)))\"\n| \"r\\<delta> \\<kappa> X \\<phi>s (MTestPos i) = empty_table\"\n| \"r\\<delta> \\<kappa> X \\<phi>s (MTestNeg i) = empty_table\"\n| \"r\\<delta> \\<kappa> X \\<phi>s (MPlus r s) = r\\<delta> \\<kappa> X \\<phi>s r \\<union> r\\<delta> \\<kappa> X \\<phi>s s\"\n| \"r\\<delta> \\<kappa> X \\<phi>s (MTimes r s) = r\\<delta> (\\<lambda>t. \\<kappa> (MTimes r t)) X \\<phi>s s \\<union> \\<epsilon>_lax (r\\<delta> \\<kappa> X \\<phi>s r) \\<phi>s s\"\n| \"r\\<delta> \\<kappa> X \\<phi>s (MStar r) = r\\<delta> (\\<lambda>t. \\<kappa> (MTimes (MStar r) t)) X \\<phi>s r\"\n\nfun l\\<delta> :: \"(mregex \\<Rightarrow> mregex) \\<Rightarrow> (mregex, 'a table) mapping \\<Rightarrow> 'a table list \\<Rightarrow> mregex \\<Rightarrow> 'a table\" where\n  \"l\\<delta> \\<kappa> X \\<phi>s (MSkip n) = (case n of 0 \\<Rightarrow> empty_table | Suc m \\<Rightarrow> lookup X (\\<kappa> (MSkip m)))\"\n| \"l\\<delta> \\<kappa> X \\<phi>s (MTestPos i) = empty_table\"\n| \"l\\<delta> \\<kappa> X \\<phi>s (MTestNeg i) = empty_table\"\n| \"l\\<delta> \\<kappa> X \\<phi>s (MPlus r s) = l\\<delta> \\<kappa> X \\<phi>s r \\<union> l\\<delta> \\<kappa> X \\<phi>s s\"\n| \"l\\<delta> \\<kappa> X \\<phi>s (MTimes r s) = l\\<delta> (\\<lambda>t. \\<kappa> (MTimes t s)) X \\<phi>s r \\<union> \\<epsilon>_lax (l\\<delta> \\<kappa> X \\<phi>s s) \\<phi>s r\"\n| \"l\\<delta> \\<kappa> X \\<phi>s (MStar r) = l\\<delta> (\\<lambda>t. \\<kappa> (MTimes t (MStar r))) X \\<phi>s r\"\n\nlift_definition mrtabulate :: \"mregex list \\<Rightarrow> (mregex \\<Rightarrow> 'b table) \\<Rightarrow> (mregex, 'b table) mapping\"\n  is \"\\<lambda>ks f. (map_of (List.map_filter (\\<lambda>k. let fk = f k in if fk = empty_table then None else Some (k, fk)) ks))\" .\n\nlemma lookup_tabulate:\n  \"distinct xs \\<Longrightarrow> lookup (mrtabulate xs f) x = (if x \\<in> set xs then f x else empty_table)\"\n  unfolding lookup_default_def lookup_def\n  by transfer (auto simp: Let_def map_filter_def map_of_eq_None_iff o_def image_image dest!: map_of_SomeD\n      split: if_splits option.splits)\n\ndefinition update_matchP :: \"nat \\<Rightarrow> \\<I> \\<Rightarrow> mregex \\<Rightarrow> mregex list \\<Rightarrow> event_data table list \\<Rightarrow> ts \\<Rightarrow>\n  event_data mr\\<delta>aux \\<Rightarrow> event_data table \\<times> event_data mr\\<delta>aux\" where\n  \"update_matchP n I mr mrs rels nt aux =\n    (let aux = (case [(t, mrtabulate mrs (\\<lambda>mr.\n        r\\<delta> id rel rels mr \\<union> (if t = nt then r\\<epsilon>_strict n rels mr else {}))).\n      (t, rel) \\<leftarrow> aux, enat (nt - t) \\<le> right I]\n      of [] \\<Rightarrow> [(nt, mrtabulate mrs (r\\<epsilon>_strict n rels))]\n      | x # aux' \\<Rightarrow> (if fst x = nt then x # aux'\n                     else (nt, mrtabulate mrs (r\\<epsilon>_strict n rels)) # x # aux'))\n    in (foldr (\\<union>) [lookup rel mr. (t, rel) \\<leftarrow> aux, left I \\<le> nt - t] {}, aux))\"\n\ndefinition update_matchF_base where\n  \"update_matchF_base n I mr mrs rels nt =\n     (let X = mrtabulate mrs (l\\<epsilon>_strict n rels)\n     in ([(nt, rels, if left I = 0 then lookup X mr else empty_table)], X))\"\n\ndefinition update_matchF_step where\n  \"update_matchF_step I mr mrs nt = (\\<lambda>(t, rels', rel) (aux', X).\n     (let Y = mrtabulate mrs (l\\<delta> id X rels')\n     in ((t, rels', if mem (nt - t) I then rel \\<union> lookup Y mr else rel) # aux', Y)))\"\n\ndefinition update_matchF :: \"nat \\<Rightarrow> \\<I> \\<Rightarrow> mregex \\<Rightarrow> mregex list \\<Rightarrow> event_data table list \\<Rightarrow> ts \\<Rightarrow> event_data ml\\<delta>aux \\<Rightarrow> event_data ml\\<delta>aux\" where\n  \"update_matchF n I mr mrs rels nt aux =\n     fst (foldr (update_matchF_step I mr mrs nt) aux (update_matchF_base n I mr mrs rels nt))\"\n\nfun eval_matchF :: \"\\<I> \\<Rightarrow> mregex \\<Rightarrow> ts \\<Rightarrow> event_data ml\\<delta>aux \\<Rightarrow> event_data table list \\<times> event_data ml\\<delta>aux\" where\n  \"eval_matchF I mr nt [] = ([], [])\"\n| \"eval_matchF I mr nt ((t, rels, rel) # aux) = (if t + right I < nt then\n    (let (xs, aux) = eval_matchF I mr nt aux in (rel # xs, aux)) else ([], (t, rels, rel) # aux))\"\n\nprimrec map_split where\n  \"map_split f [] = ([], [])\"\n| \"map_split f (x # xs) =\n    (let (y, z) = f x; (ys, zs) = map_split f xs\n    in (y # ys, z # zs))\"\n\nfun eval_assignment :: \"nat \\<times> Formula.trm \\<Rightarrow> event_data tuple \\<Rightarrow> event_data tuple\" where\n  \"eval_assignment (x, t) y = (y[x:=Some (meval_trm t y)])\"\n\nfun eval_constraint0 :: \"mconstraint \\<Rightarrow> event_data \\<Rightarrow> event_data \\<Rightarrow> bool\" where\n  \"eval_constraint0 MEq x y = (x = y)\"\n| \"eval_constraint0 MLess x y = (x < y)\"\n| \"eval_constraint0 MLessEq x y = (x \\<le> y)\"\n\nfun eval_constraint :: \"Formula.trm \\<times> bool \\<times> mconstraint \\<times> Formula.trm \\<Rightarrow> event_data tuple \\<Rightarrow> bool\" where\n  \"eval_constraint (t1, p, c, t2) x = (eval_constraint0 c (meval_trm t1 x) (meval_trm t2 x) = p)\"\n\nprimrec (in maux) meval :: \"nat \\<Rightarrow> ts \\<Rightarrow> Formula.database \\<Rightarrow> ('msaux, 'muaux) mformula \\<Rightarrow>\n    event_data table list \\<times> ('msaux, 'muaux) mformula\" where\n  \"meval n t db (MRel rel) = ([rel], MRel rel)\"\n| \"meval n t db (MPred e ts) = (map (\\<lambda>X. (\\<lambda>f. Table.tabulate f 0 n) ` Option.these\n    (match ts ` X)) (case Mapping.lookup db e of None \\<Rightarrow> [{}] | Some xs \\<Rightarrow> xs), MPred e ts)\"\n| \"meval n t db (MLet p m b \\<phi> \\<psi>) =\n    (let (xs, \\<phi>) = meval m t db \\<phi>; (ys, \\<psi>) = meval n t (Mapping.update p (map (image (drop b o map the)) xs) db) \\<psi>\n    in (ys, MLet p m b \\<phi> \\<psi>))\"\n| \"meval n t db (MAnd A_\\<phi> \\<phi> pos A_\\<psi> \\<psi> buf) =\n    (let (xs, \\<phi>) = meval n t db \\<phi>; (ys, \\<psi>) = meval n t db \\<psi>;\n      (zs, buf) = mbuf2_take (\\<lambda>r1 r2. bin_join n A_\\<phi> r1 pos A_\\<psi> r2) (mbuf2_add xs ys buf)\n    in (zs, MAnd A_\\<phi> \\<phi> pos A_\\<psi> \\<psi> buf))\"\n| \"meval n t db (MAndAssign \\<phi> conf) =\n    (let (xs, \\<phi>) = meval n t db \\<phi> in (map (\\<lambda>r. eval_assignment conf ` r) xs, MAndAssign \\<phi> conf))\"\n| \"meval n t db (MAndRel \\<phi> conf) =\n    (let (xs, \\<phi>) = meval n t db \\<phi> in (map (Set.filter (eval_constraint conf)) xs, MAndRel \\<phi> conf))\"\n| \"meval n t db (MAnds A_pos A_neg L buf) =\n    (let R = map (meval n t db) L in\n    let buf = mbufn_add (map fst R) buf in\n    let (zs, buf) = mbufn_take (\\<lambda>xs zs. zs @ [mmulti_join n A_pos A_neg xs]) [] buf in\n    (zs, MAnds A_pos A_neg (map snd R) buf))\"\n| \"meval n t db (MOr \\<phi> \\<psi> buf) =\n    (let (xs, \\<phi>) = meval n t db \\<phi>; (ys, \\<psi>) = meval n t db \\<psi>;\n      (zs, buf) = mbuf2_take (\\<lambda>r1 r2. r1 \\<union> r2) (mbuf2_add xs ys buf)\n    in (zs, MOr \\<phi> \\<psi> buf))\"\n| \"meval n t db (MNeg \\<phi>) =\n    (let (xs, \\<phi>) = meval n t db \\<phi> in (map (\\<lambda>r. (if r = empty_table then unit_table n else empty_table)) xs, MNeg \\<phi>))\"\n| \"meval n t db (MExists \\<phi>) =\n    (let (xs, \\<phi>) = meval (Suc n) t db \\<phi> in (map (\\<lambda>r. tl ` r) xs, MExists \\<phi>))\"\n| \"meval n t db (MAgg g0 y \\<omega> b f \\<phi>) =\n    (let (xs, \\<phi>) = meval (b + n) t db \\<phi> in (map (eval_agg n g0 y \\<omega> b f) xs, MAgg g0 y \\<omega> b f \\<phi>))\"\n| \"meval n t db (MPrev I \\<phi> first buf nts) =\n    (let (xs, \\<phi>) = meval n t db \\<phi>;\n      (zs, buf, nts) = mprev_next I (buf @ xs) (nts @ [t])\n    in (if first then empty_table # zs else zs, MPrev I \\<phi> False buf nts))\"\n| \"meval n t db (MNext I \\<phi> first nts) =\n    (let (xs, \\<phi>) = meval n t db \\<phi>;\n      (xs, first) = (case (xs, first) of (_ # xs, True) \\<Rightarrow> (xs, False) | a \\<Rightarrow> a);\n      (zs, _, nts) = mprev_next I xs (nts @ [t])\n    in (zs, MNext I \\<phi> first nts))\"\n| \"meval n t db (MSince args \\<phi> \\<psi> buf nts aux) =\n    (let (xs, \\<phi>) = meval n t db \\<phi>; (ys, \\<psi>) = meval n t db \\<psi>;\n      ((zs, aux), buf, nts) = mbuf2t_take (\\<lambda>r1 r2 t (zs, aux).\n        let (z, aux) = update_since args r1 r2 t aux\n        in (zs @ [z], aux)) ([], aux) (mbuf2_add xs ys buf) (nts @ [t])\n    in (zs, MSince args \\<phi> \\<psi> buf nts aux))\"\n| \"meval n t db (MUntil args \\<phi> \\<psi> buf nts aux) =\n    (let (xs, \\<phi>) = meval n t db \\<phi>; (ys, \\<psi>) = meval n t db \\<psi>;\n      (aux, buf, nts) = mbuf2t_take (add_new_muaux args) aux (mbuf2_add xs ys buf) (nts @ [t]);\n      (zs, aux) = eval_muaux args (case nts of [] \\<Rightarrow> t | nt # _ \\<Rightarrow> nt) aux\n    in (zs, MUntil args \\<phi> \\<psi> buf nts aux))\"\n| \"meval n t db (MMatchP I mr mrs \\<phi>s buf nts aux) =\n    (let (xss, \\<phi>s) = map_split id (map (meval n t db) \\<phi>s);\n      ((zs, aux), buf, nts) = mbufnt_take (\\<lambda>rels t (zs, aux).\n        let (z, aux) = update_matchP n I mr mrs rels t aux\n        in (zs @ [z], aux)) ([], aux) (mbufn_add xss buf) (nts @ [t])\n    in (zs, MMatchP I mr mrs \\<phi>s buf nts aux))\"\n| \"meval n t db (MMatchF I mr mrs \\<phi>s buf nts aux) =\n    (let (xss, \\<phi>s) = map_split id (map (meval n t db) \\<phi>s);\n      (aux, buf, nts) = mbufnt_take (update_matchF n I mr mrs) aux (mbufn_add xss buf) (nts @ [t]);\n      (zs, aux) = eval_matchF I mr (case nts of [] \\<Rightarrow> t | nt # _ \\<Rightarrow> nt) aux\n    in (zs, MMatchF I mr mrs \\<phi>s buf nts aux))\"\n\ndefinition (in maux) mstep :: \"Formula.database \\<times> ts \\<Rightarrow> ('msaux, 'muaux) mstate \\<Rightarrow> (nat \\<times> event_data table) list \\<times> ('msaux, 'muaux) mstate\" where\n  \"mstep tdb st =\n     (let (xs, m) = meval (mstate_n st) (snd tdb) (fst tdb) (mstate_m st)\n     in (List.enumerate (mstate_i st) xs,\n      \\<lparr>mstate_i = mstate_i st + length xs, mstate_m = m, mstate_n = mstate_n st\\<rparr>))\"\n\nsubsection \\<open>Verdict delay\\<close>\n\ncontext fixes \\<sigma> :: Formula.trace begin\n\nfun progress :: \"(Formula.name \\<rightharpoonup> nat) \\<Rightarrow> Formula.formula \\<Rightarrow> nat \\<Rightarrow> nat\" where\n  \"progress P (Formula.Pred e ts) j = (case P e of None \\<Rightarrow> j | Some k \\<Rightarrow> k)\"\n| \"progress P (Formula.Let p b \\<phi> \\<psi>) j = progress (P(p \\<mapsto> progress P \\<phi> j)) \\<psi> j\"\n| \"progress P (Formula.Eq t1 t2) j = j\"\n| \"progress P (Formula.Less t1 t2) j = j\"\n| \"progress P (Formula.LessEq t1 t2) j = j\"\n| \"progress P (Formula.Neg \\<phi>) j = progress P \\<phi> j\"\n| \"progress P (Formula.Or \\<phi> \\<psi>) j = min (progress P \\<phi> j) (progress P \\<psi> j)\"\n| \"progress P (Formula.And \\<phi> \\<psi>) j = min (progress P \\<phi> j) (progress P \\<psi> j)\"\n| \"progress P (Formula.Ands l) j = (if l = [] then j else Min (set (map (\\<lambda>\\<phi>. progress P \\<phi> j) l)))\"\n| \"progress P (Formula.Exists \\<phi>) j = progress P \\<phi> j\"\n| \"progress P (Formula.Agg y \\<omega> b f \\<phi>) j = progress P \\<phi> j\"\n| \"progress P (Formula.Prev I \\<phi>) j = (if j = 0 then 0 else min (Suc (progress P \\<phi> j)) j)\"\n| \"progress P (Formula.Next I \\<phi>) j = progress P \\<phi> j - 1\"\n| \"progress P (Formula.Since \\<phi> I \\<psi>) j = min (progress P \\<phi> j) (progress P \\<psi> j)\"\n| \"progress P (Formula.Until \\<phi> I \\<psi>) j =\n    Inf {i. \\<forall>k. k < j \\<and> k \\<le> min (progress P \\<phi> j) (progress P \\<psi> j) \\<longrightarrow> \\<tau> \\<sigma> i + right I \\<ge> \\<tau> \\<sigma> k}\"\n| \"progress P (Formula.MatchP I r) j = min_regex_default (progress P) r j\"\n| \"progress P (Formula.MatchF I r) j =\n    Inf {i. \\<forall>k. k < j \\<and> k \\<le> min_regex_default (progress P) r j \\<longrightarrow> \\<tau> \\<sigma> i + right I \\<ge> \\<tau> \\<sigma> k}\"\n\ndefinition \"progress_regex P = min_regex_default (progress P)\"\n\ndeclare progress.simps[simp del]\nlemmas progress_simps[simp] = progress.simps[folded progress_regex_def[THEN fun_cong, THEN fun_cong]]\n\nend\n\ndefinition \"pred_mapping Q = pred_fun (\\<lambda>_. True) (pred_option Q)\"\ndefinition \"rel_mapping Q = rel_fun (=) (rel_option Q)\"\n\nlemma pred_mapping_alt: \"pred_mapping Q P = (\\<forall>p \\<in> dom P. Q (the (P p)))\"\n  unfolding pred_mapping_def pred_fun_def option.pred_set dom_def\n  by (force split: option.splits)\n\nlemma rel_mapping_alt: \"rel_mapping Q P P' = (dom P = dom P' \\<and> (\\<forall>p \\<in> dom P. Q (the (P p)) (the (P' p))))\"\n  unfolding rel_mapping_def rel_fun_def rel_option_iff dom_def\n  by (force split: option.splits)\n\nlemma rel_mapping_map_upd[simp]: \"Q x y \\<Longrightarrow> rel_mapping Q P P' \\<Longrightarrow> rel_mapping Q (P(p \\<mapsto> x)) (P'(p \\<mapsto> y))\"\n  by (auto simp: rel_mapping_alt)\n\nlemma pred_mapping_map_upd[simp]: \"Q x \\<Longrightarrow> pred_mapping Q P \\<Longrightarrow> pred_mapping Q (P(p \\<mapsto> x))\"\n  by (auto simp: pred_mapping_alt)\n\nlemma pred_mapping_empty[simp]: \"pred_mapping Q Map.empty\"\n  by (auto simp: pred_mapping_alt)\n\nlemma pred_mapping_mono: \"pred_mapping Q P \\<Longrightarrow> Q \\<le> R \\<Longrightarrow> pred_mapping R P\"\n  by (auto simp: pred_mapping_alt)\n\nlemma pred_mapping_mono_strong: \"pred_mapping Q P \\<Longrightarrow>\n  (\\<And>p. p \\<in> dom P \\<Longrightarrow> Q (the (P p)) \\<Longrightarrow> R (the (P p))) \\<Longrightarrow> pred_mapping R P\"\n  by (auto simp: pred_mapping_alt)\n\nlemma progress_mono_gen: \"j \\<le> j' \\<Longrightarrow> rel_mapping (\\<le>) P P' \\<Longrightarrow> progress \\<sigma> P \\<phi> j \\<le> progress \\<sigma> P' \\<phi> j'\"\nproof (induction \\<phi> arbitrary: P P')\n  case (Pred e ts)\n  then show ?case\n    by (force simp: rel_mapping_alt dom_def split: option.splits)\nnext\n  case (Ands l)\n  then show ?case\n    by (auto simp: image_iff intro!: Min.coboundedI[THEN order_trans])\nnext\n  case (Until \\<phi> I \\<psi>)\n  from Until(1,2)[of P P'] Until.prems show ?case\n    by (cases \"right I\")\n      (auto dest: trans_le_add1[OF \\<tau>_mono] intro!: cInf_superset_mono)\nnext\n  case (MatchF I r)\n  from MatchF(1)[of _ P P'] MatchF.prems show ?case\n    by (cases \"right I\"; cases \"regex.atms r = {}\")\n      (auto 0 3 simp: Min_le_iff progress_regex_def dest: trans_le_add1[OF \\<tau>_mono]\n        intro!: cInf_superset_mono elim!: less_le_trans order_trans)\nqed (force simp: Min_le_iff progress_regex_def split: option.splits)+\n\nlemma rel_mapping_reflp: \"reflp Q \\<Longrightarrow> rel_mapping Q P P\"\n  by (auto simp: rel_mapping_alt reflp_def)\n\nlemmas progress_mono = progress_mono_gen[OF _ rel_mapping_reflp[unfolded reflp_def], simplified]\n\nlemma progress_le_gen: \"pred_mapping (\\<lambda>x. x \\<le> j) P \\<Longrightarrow> progress \\<sigma> P \\<phi> j \\<le> j\"\nproof (induction \\<phi> arbitrary: P)\n  case (Pred e ts)\n  then show ?case\n    by (auto simp: pred_mapping_alt dom_def split: option.splits)\nnext\n  case (Ands l)\n  then show ?case\n    by (auto simp: image_iff intro!: Min.coboundedI[where a=\"progress \\<sigma> P (hd l) j\", THEN order_trans])\nnext\n  case (Until \\<phi> I \\<psi>)\n  then show ?case\n    by (cases \"right I\")\n      (auto intro: trans_le_add1[OF \\<tau>_mono] intro!: cInf_lower)\nnext\n  case (MatchF I r)\n  then show ?case\n    by (cases \"right I\")\n      (auto intro: trans_le_add1[OF \\<tau>_mono] intro!: cInf_lower)\nqed (force simp: Min_le_iff progress_regex_def split: option.splits)+\n\nlemma progress_le: \"progress \\<sigma> Map.empty \\<phi> j \\<le> j\"\n  using progress_le_gen[of _ Map.empty] by auto\n\nlemma progress_0_gen[simp]:\n  \"pred_mapping (\\<lambda>x. x = 0) P \\<Longrightarrow> progress \\<sigma> P \\<phi> 0 = 0\"\n  using progress_le_gen[of 0 P] by auto\n\nlemma progress_0[simp]:\n  \"progress \\<sigma> Map.empty \\<phi> 0 = 0\"\n  by (auto simp: pred_mapping_alt)\n\ndefinition max_mapping :: \"('b \\<Rightarrow> 'a option) \\<Rightarrow> ('b \\<Rightarrow> 'a option) \\<Rightarrow> 'b \\<Rightarrow> ('a :: linorder) option\" where\n  \"max_mapping P P' x = (case (P x, P' x) of\n    (None, None) \\<Rightarrow> None\n  | (Some x, None) \\<Rightarrow> None\n  | (None, Some x) \\<Rightarrow> None\n  | (Some x, Some y) \\<Rightarrow> Some (max x y))\"\n\ndefinition Max_mapping :: \"('b \\<Rightarrow> 'a option) set \\<Rightarrow> 'b \\<Rightarrow> ('a :: linorder) option\" where\n  \"Max_mapping Ps x = (if (\\<forall>P \\<in> Ps. P x \\<noteq> None) then Some (Max ((\\<lambda>P. the (P x)) ` Ps)) else None)\"\n\nlemma dom_max_mapping[simp]: \"dom (max_mapping P1 P2) = dom P1 \\<inter> dom P2\"\n  unfolding max_mapping_def by (auto split: option.splits)\n\nlemma dom_Max_mapping[simp]: \"dom (Max_mapping X) = (\\<Inter>P \\<in> X. dom P)\"\n  unfolding Max_mapping_def by (auto split: if_splits)\n\nlemma Max_mapping_coboundedI:\n  assumes \"finite X\" \"\\<forall>Q \\<in> X. dom Q = dom P\" \"P \\<in> X\"\n  shows \"rel_mapping (\\<le>) P (Max_mapping X)\"\n  unfolding rel_mapping_alt\nproof (intro conjI ballI)\n  from assms(3) have \"X \\<noteq> {}\" by auto\n  then show \"dom P = dom (Max_mapping X)\" using assms(2) by auto\nnext\n  fix p\n  assume \"p \\<in> dom P\"\n  with assms show \"the (P p) \\<le> the (Max_mapping X p)\"\n    by (force simp add: Max_mapping_def intro!: Max.coboundedI imageI)\nqed\n\nlemma rel_mapping_trans: \"P OO Q \\<le> R \\<Longrightarrow>\n  rel_mapping P P1 P2 \\<Longrightarrow> rel_mapping Q P2 P3 \\<Longrightarrow> rel_mapping R P1 P3\"\n  by (force simp: rel_mapping_alt dom_def set_eq_iff)\n\nabbreviation range_mapping :: \"nat \\<Rightarrow> nat \\<Rightarrow> ('b \\<Rightarrow> nat option) \\<Rightarrow> bool\" where\n  \"range_mapping i j P \\<equiv> pred_mapping (\\<lambda>x. i \\<le> x \\<and> x \\<le> j) P\"\n\nlemma range_mapping_relax:\n  \"range_mapping i j P \\<Longrightarrow> i' \\<le> i \\<Longrightarrow> j' \\<ge> j \\<Longrightarrow> range_mapping i' j' P\"\n  by (auto simp: pred_mapping_alt dom_def set_eq_iff max_mapping_def split: option.splits)\n\nlemma range_mapping_max_mapping[simp]:\n  \"range_mapping i j1 P1 \\<Longrightarrow> range_mapping i j2 P2 \\<Longrightarrow> range_mapping i (max j1 j2) (max_mapping P1 P2)\"\n  by (auto simp: pred_mapping_alt dom_def set_eq_iff max_mapping_def split: option.splits)\n\nlemma range_mapping_Max_mapping[simp]:\n  \"finite X \\<Longrightarrow> X \\<noteq> {} \\<Longrightarrow> \\<forall>x\\<in>X. range_mapping i (j x) (P x) \\<Longrightarrow> range_mapping i (Max (j ` X)) (Max_mapping (P ` X))\"\n  by (force simp: pred_mapping_alt Max_mapping_def dom_def image_iff\n      intro!: Max_ge_iff[THEN iffD2] split: if_splits)\n\nlemma pred_mapping_le:\n  \"pred_mapping ((\\<le>) i) P1 \\<Longrightarrow> rel_mapping (\\<le>) P1 P2 \\<Longrightarrow> pred_mapping ((\\<le>) (i :: nat)) P2\"\n  by (force simp: rel_mapping_alt pred_mapping_alt dom_def set_eq_iff)\n\nlemma pred_mapping_le':\n  \"pred_mapping ((\\<le>) j) P1 \\<Longrightarrow> i \\<le> j \\<Longrightarrow> rel_mapping (\\<le>) P1 P2 \\<Longrightarrow> pred_mapping ((\\<le>) (i :: nat)) P2\"\n  by (force simp: rel_mapping_alt pred_mapping_alt dom_def set_eq_iff)\n\nlemma max_mapping_cobounded1: \"dom P1 \\<subseteq> dom P2 \\<Longrightarrow> rel_mapping (\\<le>) P1 (max_mapping P1 P2)\"\n  unfolding max_mapping_def rel_mapping_alt by (auto simp: dom_def split: option.splits)\n\nlemma max_mapping_cobounded2: \"dom P2 \\<subseteq> dom P1 \\<Longrightarrow> rel_mapping (\\<le>) P2 (max_mapping P1 P2)\"\n  unfolding max_mapping_def rel_mapping_alt by (auto simp: dom_def split: option.splits)\n\nlemma max_mapping_fun_upd2[simp]:\n  \"max_mapping P1 (P2(p := y))(p \\<mapsto> x) = (max_mapping P1 P2)(p \\<mapsto> x)\"\n  by (auto simp: max_mapping_def)\n\nlemma rel_mapping_max_mapping_fun_upd: \"dom P2 \\<subseteq> dom P1 \\<Longrightarrow> p \\<in> dom P2 \\<Longrightarrow> the (P2 p) \\<le> y \\<Longrightarrow>\n  rel_mapping (\\<le>) P2 (max_mapping P1 P2(p \\<mapsto> y))\"\n  by (auto simp: rel_mapping_alt max_mapping_def split: option.splits)\n\nlemma progress_ge_gen: \"Formula.future_bounded \\<phi> \\<Longrightarrow>\n   \\<exists>P j. dom P = S \\<and> range_mapping i j P \\<and> i \\<le> progress \\<sigma> P \\<phi> j\"\nproof (induction \\<phi> arbitrary: i S)\n  case (Pred e ts)\n  then show ?case\n    by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some i else None\"])\n      (auto split: option.splits if_splits simp: rel_mapping_alt pred_mapping_alt dom_def)\nnext\n  case (Let p b \\<phi> \\<psi>)\n  from Let.prems obtain P2 j2 where P2: \"dom P2 = insert p S\" \"range_mapping i j2 P2\"\n    \"i \\<le> progress \\<sigma> P2 \\<psi> j2\"\n    by (atomize_elim, intro Let(2)) (force simp: pred_mapping_alt rel_mapping_alt dom_def)+\n  from Let.prems obtain P1 j1 where P1: \"dom P1 = S\" \"range_mapping (the (P2 p)) j1 P1\"\n    \"the (P2 p) \\<le> progress \\<sigma> P1 \\<phi> j1\"\n    by (atomize_elim, intro Let(1)) auto\n  let ?P12 = \"max_mapping P1 P2\"\n  from P1 P2 have le1: \"progress \\<sigma> P1 \\<phi> j1 \\<le> progress \\<sigma> (?P12(p := P1 p)) \\<phi> (max j1 j2)\"\n    by (intro progress_mono_gen) (auto simp: rel_mapping_alt max_mapping_def)\n  from P1 P2 have le2: \"progress \\<sigma> P2 \\<psi> j2 \\<le> progress \\<sigma> (?P12(p \\<mapsto> progress \\<sigma> P1 \\<phi> j1)) \\<psi> (max j1 j2)\"\n    by (intro progress_mono_gen) (auto simp: rel_mapping_alt max_mapping_def)\n  show ?case\n    unfolding progress.simps\n  proof (intro exI[of _ \"?P12(p := P1 p)\"] exI[of _ \"max j1 j2\"] conjI)\n    show \"dom (?P12(p := P1 p)) = S\"\n      using P1 P2 by (auto simp: dom_def max_mapping_def)\n  next\n    show \"range_mapping i (max j1 j2) (?P12(p := P1 p))\"\n      using P1 P2 by (force simp add: pred_mapping_alt dom_def max_mapping_def split: option.splits)\n  next\n    have \"i \\<le> progress \\<sigma> P2 \\<psi> j2\" by fact\n    also have \"... \\<le> progress \\<sigma> (?P12(p \\<mapsto> progress \\<sigma> P1 \\<phi> j1)) \\<psi> (max j1 j2)\"\n      using le2 by blast\n    also have \"... \\<le> progress \\<sigma> (?P12(p := P1 p)(p\\<mapsto>progress \\<sigma> (?P12(p := P1 p)) \\<phi> (max j1 j2))) \\<psi> (max j1 j2)\"\n      by (auto intro!: progress_mono_gen simp: le1 rel_mapping_alt)\n    finally show \"i \\<le> ...\" .\n  qed\nnext\n  case (Eq _ _)\n  then show ?case\n    by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some i else None\"]) (auto split: if_splits simp: pred_mapping_alt)\nnext\n  case (Less _ _)\n  then show ?case\n    by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some i else None\"]) (auto split: if_splits simp: pred_mapping_alt)\nnext\n  case (LessEq _ _)\n  then show ?case\n    by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some i else None\"]) (auto split: if_splits simp: pred_mapping_alt)\nnext\n  case (Or \\<phi>1 \\<phi>2)\n  from Or(3) obtain P1 j1 where P1: \"dom P1 = S\" \"range_mapping i j1 P1\"  \"i \\<le> progress \\<sigma> P1 \\<phi>1 j1\"\n    using Or(1)[of S i] by auto\n  moreover\n  from Or(3) obtain P2 j2 where P2: \"dom P2 = S\" \"range_mapping i j2 P2\" \"i \\<le> progress \\<sigma> P2 \\<phi>2 j2\"\n    using Or(2)[of S i] by auto\n  ultimately have \"i \\<le> progress \\<sigma> (max_mapping P1 P2) (Formula.Or \\<phi>1 \\<phi>2) (max j1 j2)\"\n    by (auto 0 3 elim!: order.trans[OF _ progress_mono_gen] intro: max_mapping_cobounded1 max_mapping_cobounded2)\n  with P1 P2 show ?case by (intro exI[of _ \"max_mapping P1 P2\"] exI[of _ \"max j1 j2\"]) auto\nnext\n  case (And \\<phi>1 \\<phi>2)\n  from And(3) obtain P1 j1 where P1: \"dom P1 = S\" \"range_mapping i j1 P1\"  \"i \\<le> progress \\<sigma> P1 \\<phi>1 j1\"\n    using And(1)[of S i] by auto\n  moreover\n  from And(3) obtain P2 j2 where P2: \"dom P2 = S\" \"range_mapping i j2 P2\" \"i \\<le> progress \\<sigma> P2 \\<phi>2 j2\"\n    using And(2)[of S i] by auto\n  ultimately have \"i \\<le> progress \\<sigma> (max_mapping P1 P2) (Formula.And \\<phi>1 \\<phi>2) (max j1 j2)\"\n    by (auto 0 3 elim!: order.trans[OF _ progress_mono_gen] intro: max_mapping_cobounded1 max_mapping_cobounded2)\n  with P1 P2 show ?case by (intro exI[of _ \"max_mapping P1 P2\"] exI[of _ \"max j1 j2\"]) auto\nnext\n  case (Ands l)\n  show ?case proof (cases \"l = []\")\n    case True\n    then show ?thesis\n      by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some i else None\"])\n        (auto split: if_splits simp: pred_mapping_alt)\n  next\n    case False\n    then obtain \\<phi> where \"\\<phi> \\<in> set l\" by (cases l) auto\n    from Ands.prems have \"\\<forall>\\<phi>\\<in>set l. Formula.future_bounded \\<phi>\"\n      by (simp add: list.pred_set)\n    { fix \\<phi>\n      assume \"\\<phi> \\<in> set l\"\n      with Ands.prems obtain P j where \"dom P = S\" \"range_mapping i j P\" \"i \\<le> progress \\<sigma> P \\<phi> j\"\n        by (atomize_elim, intro Ands(1)[of \\<phi> S i]) (auto simp: list.pred_set)\n      then have \"\\<exists>Pj. dom (fst Pj) = S \\<and> range_mapping i (snd Pj) (fst Pj) \\<and> i \\<le> progress \\<sigma> (fst Pj) \\<phi> (snd Pj)\"\n        (is \"\\<exists>Pj. ?P Pj\")\n        by (intro exI[of _ \"(P, j)\"]) auto\n    }\n    then have \"\\<forall>\\<phi>\\<in>set l. \\<exists>Pj. dom (fst Pj) = S \\<and> range_mapping i (snd Pj) (fst Pj) \\<and> i \\<le> progress \\<sigma> (fst Pj) \\<phi> (snd Pj)\"\n      (is \"\\<forall>\\<phi>\\<in>set l. \\<exists>Pj. ?P Pj \\<phi>\")\n      by blast\n    with Ands(1) Ands.prems False have \"\\<exists>Pjf. \\<forall>\\<phi>\\<in>set l. ?P (Pjf \\<phi>) \\<phi>\"\n      by (auto simp: Ball_def intro: choice)\n    then obtain Pjf where Pjf: \"\\<forall>\\<phi>\\<in>set l. ?P (Pjf \\<phi>) \\<phi>\" ..\n    define Pf where \"Pf = fst o Pjf\"\n    define jf where \"jf = snd o Pjf\"\n    have *: \"dom (Pf \\<phi>) = S\" \"range_mapping i (jf \\<phi>) (Pf \\<phi>)\" \"i \\<le> progress \\<sigma> (Pf \\<phi>) \\<phi> (jf \\<phi>)\"\n      if \"\\<phi> \\<in> set l\" for \\<phi>\n      using Pjf[THEN bspec, OF that] unfolding Pf_def jf_def by auto\n    with False show ?thesis\n      unfolding progress.simps eq_False[THEN iffD2, OF False] if_False\n      by ((subst Min_ge_iff; simp add: False),\n          intro exI[where x=\"MAX \\<phi>\\<in>set l. jf \\<phi>\"] exI[where x=\"Max_mapping (Pf ` set l)\"]\n          conjI ballI order.trans[OF *(3) progress_mono_gen] Max_mapping_coboundedI)\n        (auto simp: False *[OF \\<open>\\<phi> \\<in> set l\\<close>] \\<open>\\<phi> \\<in> set l\\<close>)\n  qed\nnext\n  case (Exists \\<phi>)\n  then show ?case by simp\nnext\n  case (Prev I \\<phi>)\n  then obtain P j where \"dom P = S\" \"range_mapping i j P\" \"i \\<le> progress \\<sigma> P \\<phi> j\"\n    by (atomize_elim, intro Prev(1)) (auto simp: pred_mapping_alt dom_def)\n  with Prev(2) have\n    \"dom P = S \\<and> range_mapping i (max i j) P \\<and> i \\<le> progress \\<sigma> P (formula.Prev I \\<phi>) (max i j)\"\n    by (auto simp: le_Suc_eq max_def pred_mapping_alt split: if_splits\n        elim: order.trans[OF _ progress_mono])\n  then show ?case by blast\nnext\n  case (Next I \\<phi>)\n  then obtain P j where \"dom P = S\" \"range_mapping (Suc i) j P\" \"Suc i \\<le> progress \\<sigma> P \\<phi> j\"\n    by (atomize_elim, intro Next(1)) (auto simp: pred_mapping_alt dom_def)\n  then show ?case\n    by (intro exI[of _ P] exI[of _ j]) (auto 0 3 simp: pred_mapping_alt dom_def)\nnext\n  case (Since \\<phi>1 I \\<phi>2)\n  from Since(3) obtain P1 j1 where P1: \"dom P1 = S\" \"range_mapping i j1 P1\"  \"i \\<le> progress \\<sigma> P1 \\<phi>1 j1\"\n    using Since(1)[of S i] by auto\n  moreover\n  from Since(3) obtain P2 j2 where P2: \"dom P2 = S\" \"range_mapping i j2 P2\" \"i \\<le> progress \\<sigma> P2 \\<phi>2 j2\"\n    using Since(2)[of S i] by auto\n  ultimately have \"i \\<le> progress \\<sigma> (max_mapping P1 P2) (Formula.Since \\<phi>1 I \\<phi>2) (max j1 j2)\"\n    by (auto elim!: order.trans[OF _ progress_mono_gen] simp: max_mapping_cobounded1 max_mapping_cobounded2)\n  with P1 P2 show ?case by (intro exI[of _ \"max_mapping P1 P2\"] exI[of _ \"max j1 j2\"])\n      (auto elim!: pred_mapping_le intro: max_mapping_cobounded1)\nnext\n  case (Until \\<phi>1 I \\<phi>2)\n  from Until.prems obtain b where [simp]: \"right I = enat b\"\n    by (cases \"right I\") (auto)\n  obtain i' where \"i < i'\" and \"\\<tau> \\<sigma> i + b + 1 \\<le> \\<tau> \\<sigma> i'\"\n    using ex_le_\\<tau>[where x=\"\\<tau> \\<sigma> i + b + 1\"] by (auto simp add: less_eq_Suc_le)\n  then have 1: \"\\<tau> \\<sigma> i + b < \\<tau> \\<sigma> i'\" by simp\n  from Until.prems obtain P1 j1 where P1: \"dom P1 = S\" \"range_mapping (Suc i') j1 P1\" \"Suc i' \\<le> progress \\<sigma> P1 \\<phi>1 j1\"\n    by (atomize_elim, intro Until(1)) (auto simp: pred_mapping_alt dom_def)\n  from Until.prems obtain P2 j2 where P2: \"dom P2 = S\" \"range_mapping (Suc i') j2 P2\" \"Suc i' \\<le> progress \\<sigma> P2 \\<phi>2 j2\"\n    by (atomize_elim, intro Until(2)) (auto simp: pred_mapping_alt dom_def)\n  let ?P12 = \"max_mapping P1 P2\"\n  have \"i \\<le> progress \\<sigma> ?P12 (Formula.Until \\<phi>1 I \\<phi>2) (max j1 j2)\"\n    unfolding progress.simps\n  proof (intro cInf_greatest, goal_cases nonempty greatest)\n    case nonempty\n    then show ?case\n      by (auto simp: trans_le_add1[OF \\<tau>_mono] intro!: exI[of _ \"max j1 j2\"])\n  next\n    case (greatest x)\n    from P1(2,3) have \"i' < j1\"\n      by (auto simp: less_eq_Suc_le intro!: progress_le_gen elim!: order.trans pred_mapping_mono_strong)\n    then have \"i' < max j1 j2\" by simp\n    have \"progress \\<sigma> P1 \\<phi>1 j1 \\<le> progress \\<sigma> ?P12 \\<phi>1 (max j1 j2)\"\n      using P1(1) P2(1) by (auto intro!: progress_mono_gen max_mapping_cobounded1)\n    moreover have \"progress \\<sigma> P2 \\<phi>2 j2 \\<le> progress \\<sigma> ?P12 \\<phi>2 (max j1 j2)\"\n      using P1(1) P2(1) by (auto intro!: progress_mono_gen max_mapping_cobounded2)\n    ultimately have \"i' \\<le> min (progress \\<sigma> ?P12 \\<phi>1 (max j1 j2)) (progress \\<sigma> ?P12 \\<phi>2 (max j1 j2))\"\n      using P1(3) P2(3) by simp\n    with greatest \\<open>i' < max j1 j2\\<close> have \"\\<tau> \\<sigma> i' \\<le> \\<tau> \\<sigma> x + b\"\n      by simp\n    with 1 have \"\\<tau> \\<sigma> i < \\<tau> \\<sigma> x\" by simp\n    then show ?case by (auto dest!: less_\\<tau>D)\n  qed\n  with P1 P2 \\<open>i < i'\\<close> show ?case\n    by (intro exI[of _ \"max_mapping P1 P2\"] exI[of _ \"max j1 j2\"]) (auto simp: range_mapping_relax)\nnext\n  case (MatchP I r)\n  then show ?case\n  proof (cases \"regex.atms r = {}\")\n    case True\n    with MatchP.prems show ?thesis\n      unfolding progress.simps\n      by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some i else None\"] exI[of _ i])\n        (auto split: if_splits simp: pred_mapping_alt regex.pred_set)\n  next\n    case False\n    define pick where \"pick = (\\<lambda>\\<phi>. SOME Pj. dom (fst Pj) = S \\<and> range_mapping i (snd Pj) (fst Pj) \\<and>\n       i \\<le> progress \\<sigma> (fst Pj) \\<phi> (snd Pj))\"\n    let ?pickP = \"fst o pick\" let ?pickj = \"snd o pick\"\n    from MatchP have pick: \"\\<phi> \\<in> regex.atms r \\<Longrightarrow> dom (?pickP \\<phi>) = S \\<and>\n      range_mapping i (?pickj \\<phi>) (?pickP \\<phi>) \\<and> i \\<le> progress \\<sigma> (?pickP \\<phi>) \\<phi> (?pickj \\<phi>)\" for \\<phi>\n      unfolding pick_def o_def future_bounded.simps regex.pred_set\n      by (intro someI_ex[where P = \"\\<lambda>Pj. dom (fst Pj) = S \\<and> range_mapping i (snd Pj) (fst Pj) \\<and>\n         i \\<le> progress \\<sigma> (fst Pj) \\<phi> (snd Pj)\"]) auto\n    with False show ?thesis\n      unfolding progress.simps\n      by (intro exI[of _ \"Max_mapping (?pickP ` regex.atms r)\"] exI[of _ \"Max (?pickj ` regex.atms r)\"])\n        (auto simp: Max_mapping_coboundedI\n          order_trans[OF pick[THEN conjunct2, THEN conjunct2] progress_mono_gen])\n  qed\nnext\n  case (MatchF I r)\n  from MatchF.prems obtain b where [simp]: \"right I = enat b\"\n    by auto\n  obtain i' where i': \"i < i'\" \"\\<tau> \\<sigma> i + b + 1 \\<le> \\<tau> \\<sigma> i'\"\n    using ex_le_\\<tau>[where x=\"\\<tau> \\<sigma> i + b + 1\"] by (auto simp add: less_eq_Suc_le)\n  then have 1: \"\\<tau> \\<sigma> i + b < \\<tau> \\<sigma> i'\" by simp\n  have ix: \"i \\<le> x\" if \"\\<tau> \\<sigma> i' \\<le> b + \\<tau> \\<sigma> x\" \"b + \\<tau> \\<sigma> i < \\<tau> \\<sigma> i'\" for x\n    using less_\\<tau>D[of \\<sigma> i] that less_le_trans by fastforce\n  show ?case\n  proof (cases \"regex.atms r = {}\")\n    case True\n    with MatchF.prems i' ix show ?thesis\n      unfolding progress.simps\n      by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some (Suc i') else None\"] exI[of _ \"Suc i'\"])\n        (auto split: if_splits simp: pred_mapping_alt regex.pred_set add.commute less_Suc_eq\n          intro!: cInf_greatest dest!: spec[of _ i'] less_imp_le[THEN \\<tau>_mono, of _ i' \\<sigma>])\n  next\n    case False\n    then obtain \\<phi> where \\<phi>: \"\\<phi> \\<in> regex.atms r\" by auto\n    define pick where \"pick = (\\<lambda>\\<phi>. SOME Pj. dom (fst Pj) = S \\<and> range_mapping (Suc i') (snd Pj) (fst Pj) \\<and>\n      Suc i' \\<le> progress \\<sigma> (fst Pj) \\<phi> (snd Pj))\"\n    define pickP where \"pickP = fst o pick\" define pickj where \"pickj = snd o pick\"\n    from MatchF have pick: \"\\<phi> \\<in> regex.atms r \\<Longrightarrow> dom (pickP \\<phi>) = S \\<and>\n    range_mapping (Suc i') (pickj \\<phi>) (pickP \\<phi>) \\<and> Suc i' \\<le> progress \\<sigma> (pickP \\<phi>) \\<phi> (pickj \\<phi>)\" for \\<phi>\n      unfolding pick_def o_def future_bounded.simps regex.pred_set pickj_def pickP_def\n      by (intro someI_ex[where P = \"\\<lambda>Pj. dom (fst Pj) = S \\<and> range_mapping (Suc i') (snd Pj) (fst Pj) \\<and>\n       Suc i' \\<le> progress \\<sigma> (fst Pj) \\<phi> (snd Pj)\"]) auto\n    let ?P = \"Max_mapping (pickP ` regex.atms r)\" let ?j = \"Max (pickj ` regex.atms r)\"\n    from pick[OF \\<phi>] False \\<phi> have \"Suc i' \\<le> ?j\"\n      by (intro order_trans[OF pick[THEN conjunct2, THEN conjunct2], OF \\<phi>] order_trans[OF progress_le_gen])\n        (auto simp: Max_ge_iff dest: range_mapping_relax[of _ _ _ 0, OF _ _ order_refl, simplified])\n    moreover\n    note i' 1 ix\n    moreover\n    from MatchF.prems have \"Regex.pred_regex Formula.future_bounded r\"\n      by auto\n    ultimately show ?thesis using \\<tau>_mono[of _ ?j \\<sigma>] less_\\<tau>D[of \\<sigma> i] pick False\n      by (intro exI[of _ \"?j\"]  exI[of _ \"?P\"])\n        (auto 0 3 intro!: cInf_greatest\n          order_trans[OF le_SucI[OF order_refl] order_trans[OF pick[THEN conjunct2, THEN conjunct2] progress_mono_gen]]\n          range_mapping_Max_mapping[OF _ _ ballI[OF range_mapping_relax[of \"Suc i'\" _ _ i, OF _ _ order_refl]]]\n          simp: ac_simps Suc_le_eq trans_le_add2 Max_mapping_coboundedI progress_regex_def\n          dest: spec[of _ \"i'\"] spec[of _ ?j])\n  qed\nqed (auto split: option.splits)\n\nlemma progress_ge: \"Formula.future_bounded \\<phi> \\<Longrightarrow> \\<exists>j. i \\<le> progress \\<sigma> Map.empty \\<phi> j\"\n  using progress_ge_gen[of \\<phi> \"{}\" i \\<sigma>]\n  by auto\n\n\n\nlemma progress_time_conv:\n  assumes \"\\<forall>i<j. \\<tau> \\<sigma> i = \\<tau> \\<sigma>' i\"\n  shows \"progress \\<sigma> P \\<phi> j = progress \\<sigma>' P \\<phi> j\"\n  using assms proof (induction \\<phi> arbitrary: P)\n  case (Until \\<phi>1 I \\<phi>2)\n  have *: \"i \\<le> j - 1 \\<longleftrightarrow> i < j\" if \"j \\<noteq> 0\" for i\n    using that by auto\n  with Until show ?case\n  proof (cases \"right I\")\n    case (enat b)\n    then show ?thesis\n    proof (cases \"j\")\n      case (Suc n)\n      with enat * Until show ?thesis\n        using \\<tau>_mono[THEN trans_le_add1]\n        by (auto 8 0\n            intro!: box_equals[OF arg_cong[where f=Inf]\n              cInf_restrict_nat[symmetric, where x=n] cInf_restrict_nat[symmetric, where x=n]])\n    qed simp\n  qed simp\nnext\n  case (MatchF I r)\n  have *: \"i \\<le> j - 1 \\<longleftrightarrow> i < j\" if \"j \\<noteq> 0\" for i\n    using that by auto\n  with MatchF show ?case using \\<tau>_mono[THEN trans_le_add1]\n    by (cases \"right I\"; cases j)\n      ((auto 6 0 simp: progress_le_gen progress_regex_def intro!: box_equals[OF arg_cong[where f=Inf]\n            cInf_restrict_nat[symmetric, where x=\"j-1\"] cInf_restrict_nat[symmetric, where x=\"j-1\"]]) [])+\nqed (auto simp: progress_regex_def)\n\nlemma Inf_UNIV_nat: \"(Inf UNIV :: nat) = 0\"\n  by (simp add: cInf_eq_minimum)\n\nlemma progress_prefix_conv:\n  assumes \"prefix_of \\<pi> \\<sigma>\" and \"prefix_of \\<pi> \\<sigma>'\"\n  shows \"progress \\<sigma> P \\<phi> (plen \\<pi>) = progress \\<sigma>' P \\<phi> (plen \\<pi>)\"\n  using assms by (auto intro: progress_time_conv \\<tau>_prefix_conv)\n\nlemma bounded_rtranclp_mono:\n  fixes n :: \"'x :: linorder\"\n  assumes \"\\<And>i j. R i j \\<Longrightarrow> j < n \\<Longrightarrow> S i j\" \"\\<And>i j. R i j \\<Longrightarrow> i \\<le> j\"\n  shows \"rtranclp R i j \\<Longrightarrow> j < n \\<Longrightarrow> rtranclp S i j\"\nproof (induct rule: rtranclp_induct)\n  case (step y z)\n  then show ?case\n    using assms(1,2)[of y z]\n    by (auto elim!: rtrancl_into_rtrancl[to_pred, rotated])\nqed auto\n\nlemma sat_prefix_conv_gen:\n  assumes \"prefix_of \\<pi> \\<sigma>\" and \"prefix_of \\<pi> \\<sigma>'\"\n  shows \"i < progress \\<sigma> P \\<phi> (plen \\<pi>) \\<Longrightarrow> dom V = dom V' \\<Longrightarrow> dom P = dom V \\<Longrightarrow>\n    pred_mapping (\\<lambda>x. x \\<le> plen \\<pi>) P \\<Longrightarrow>\n    (\\<And>p i \\<phi>. p \\<in> dom V \\<Longrightarrow> i < the (P p) \\<Longrightarrow> the (V p) i = the (V' p) i) \\<Longrightarrow>\n    Formula.sat \\<sigma> V v i \\<phi> \\<longleftrightarrow> Formula.sat \\<sigma>' V' v i \\<phi>\"\nproof (induction \\<phi> arbitrary: P V V' v i)\n  case (Pred e ts)\n  from Pred.prems(1,4) have \"i < plen \\<pi>\"\n    by (blast intro!: order.strict_trans2 progress_le_gen)\n  show ?case proof (cases \"V e\")\n    case None\n    then have \"V' e = None\" using \\<open>dom V = dom V'\\<close> by auto\n    with None \\<Gamma>_prefix_conv[OF assms(1,2) \\<open>i < plen \\<pi>\\<close>] show ?thesis by simp\n  next\n    case (Some a)\n    obtain a' where \"V' e = Some a'\" using Some \\<open>dom V = dom V'\\<close> by auto\n    then have \"i < the (P e)\"\n      using Pred.prems(1-3) by (auto split: option.splits)\n    then have \"the (V e) i = the (V' e) i\"\n      using Some by (intro Pred.prems(5)) (simp_all add: domI)\n    with Some \\<open>V' e = Some a'\\<close> show ?thesis by simp\n  qed\nnext\n  case (Let p b \\<phi> \\<psi>)\n  let ?V = \"\\<lambda>V \\<sigma>. (V(p \\<mapsto>\n      \\<lambda>i. {v. length v = Formula.nfv \\<phi> - b \\<and>\n              (\\<exists>zs. length zs = b \\<and>\n                    Formula.sat \\<sigma> V (zs @ v) i \\<phi>)}))\"\n  show ?case unfolding sat.simps proof (rule Let.IH(2))\n    from Let.prems show \"i < progress \\<sigma> (P(p \\<mapsto> progress \\<sigma> P \\<phi> (plen \\<pi>))) \\<psi> (plen \\<pi>)\"\n      by simp\n    from Let.prems show \"dom (?V V \\<sigma>) = dom (?V V' \\<sigma>')\"\n      by simp\n    from Let.prems show \"dom (P(p \\<mapsto> progress \\<sigma> P \\<phi> (plen \\<pi>))) = dom (?V V \\<sigma>)\"\n      by simp\n    from Let.prems show \"pred_mapping (\\<lambda>x. x \\<le> plen \\<pi>) (P(p \\<mapsto> progress \\<sigma> P \\<phi> (plen \\<pi>)))\"\n      by (auto intro!: pred_mapping_map_upd elim!: progress_le_gen)\n  next\n    fix p' i \\<phi>'\n    assume 1: \"p' \\<in> dom (?V V \\<sigma>)\" and 2: \"i < the ((P(p \\<mapsto> progress \\<sigma> P \\<phi> (plen \\<pi>))) p')\"\n    show \"the (?V V \\<sigma> p') i = the (?V V' \\<sigma>' p') i\" proof (cases \"p' = p\")\n      case True\n      with Let 2 show ?thesis by auto\n    next\n      case False\n      with 1 2 show ?thesis by (auto intro!: Let.prems(5))\n    qed\n  qed\nnext\n  case (Eq t1 t2)\n  show ?case by simp\nnext\n  case (Neg \\<phi>)\n  then show ?case by simp\nnext\n  case (Or \\<phi>1 \\<phi>2)\n  then show ?case by auto\nnext\n  case (Ands l)\n  from Ands.prems have \"\\<forall>\\<phi>\\<in>set l. i < progress \\<sigma> P \\<phi> (plen \\<pi>)\"\n    by (cases l) simp_all\n  with Ands show ?case unfolding sat_Ands by blast\nnext\n  case (Exists \\<phi>)\n  then show ?case by simp\nnext\n  case (Prev I \\<phi>)\n  with \\<tau>_prefix_conv[OF assms(1,2)] show ?case\n    by (cases i) (auto split: if_splits)\nnext\n  case (Next I \\<phi>)\n  then have \"Suc i < plen \\<pi>\"\n    by (auto intro: order.strict_trans2[OF _ progress_le_gen[of _ P \\<sigma> \\<phi>]])\n  with Next.prems \\<tau>_prefix_conv[OF assms(1,2)] show ?case\n    unfolding sat.simps\n    by (intro conj_cong Next) auto\nnext\n  case (Since \\<phi>1 I \\<phi>2)\n  then have \"i < plen \\<pi>\"\n    by (auto elim!: order.strict_trans2[OF _ progress_le_gen])\n  with Since.prems \\<tau>_prefix_conv[OF assms(1,2)] show ?case\n    unfolding sat.simps\n    by (intro conj_cong ex_cong ball_cong Since) auto\nnext\n  case (Until \\<phi>1 I \\<phi>2)\n  from Until.prems obtain b where right[simp]: \"right I = enat b\"\n    by (cases \"right I\") (auto simp add: Inf_UNIV_nat)\n  from Until.prems obtain j where \"\\<tau> \\<sigma> i + b + 1 \\<le> \\<tau> \\<sigma> j\"\n    \"j \\<le> progress \\<sigma> P \\<phi>1 (plen \\<pi>)\" \"j \\<le> progress \\<sigma> P \\<phi>2 (plen \\<pi>)\"\n    by atomize_elim (auto 0 4 simp add: less_eq_Suc_le not_le intro: Suc_leI dest: spec[of _ \"i\"]\n        dest!: le_cInf_iff[THEN iffD1, rotated -1])\n  then have 1: \"k < progress \\<sigma> P \\<phi>1 (plen \\<pi>)\" and 2: \"k < progress \\<sigma> P \\<phi>2 (plen \\<pi>)\"\n    if \"\\<tau> \\<sigma> k \\<le> \\<tau> \\<sigma> i + b\" for k\n    using that by (fastforce elim!: order.strict_trans2[rotated] intro: less_\\<tau>D[of \\<sigma>])+\n  have 3: \"k < plen \\<pi>\" if \"\\<tau> \\<sigma> k \\<le> \\<tau> \\<sigma> i + b\" for k\n    using 1[OF that] Until(6) by (auto simp only: less_eq_Suc_le order.trans[OF _ progress_le_gen])\n\n  from Until.prems have \"i < progress \\<sigma>' P (Formula.Until \\<phi>1 I \\<phi>2) (plen \\<pi>)\"\n    unfolding progress_prefix_conv[OF assms(1,2)] by blast\n  then obtain j where \"\\<tau> \\<sigma>' i + b + 1 \\<le> \\<tau> \\<sigma>' j\"\n    \"j \\<le> progress \\<sigma>' P \\<phi>1 (plen \\<pi>)\" \"j \\<le> progress \\<sigma>' P \\<phi>2 (plen \\<pi>)\"\n    by atomize_elim (auto 0 4 simp add: less_eq_Suc_le not_le intro: Suc_leI dest: spec[of _ \"i\"]\n        dest!: le_cInf_iff[THEN iffD1, rotated -1])\n  then have 11: \"k < progress \\<sigma> P \\<phi>1 (plen \\<pi>)\" and 21: \"k < progress \\<sigma> P \\<phi>2 (plen \\<pi>)\"\n    if \"\\<tau> \\<sigma>' k \\<le> \\<tau> \\<sigma>' i + b\" for k\n    unfolding progress_prefix_conv[OF assms(1,2)]\n    using that by (fastforce elim!: order.strict_trans2[rotated] intro: less_\\<tau>D[of \\<sigma>'])+\n  have 31: \"k < plen \\<pi>\" if \"\\<tau> \\<sigma>' k \\<le> \\<tau> \\<sigma>' i + b\" for k\n    using 11[OF that] Until(6) by (auto simp only: less_eq_Suc_le order.trans[OF _ progress_le_gen])\n  show ?case unfolding sat.simps\n  proof ((intro ex_cong iffI; elim conjE), goal_cases LR RL)\n    case (LR j)\n    with Until(1)[OF 1] Until(2)[OF 2] \\<tau>_prefix_conv[OF assms(1,2) 3] Until.prems show ?case\n      by (auto 0 4 simp: le_diff_conv add.commute dest: less_imp_le order.trans[OF \\<tau>_mono, rotated])\n  next\n    case (RL j)\n    with Until(1)[OF 11] Until(2)[OF 21] \\<tau>_prefix_conv[OF assms(1,2) 31] Until.prems show ?case\n      by (auto 0 4 simp: le_diff_conv add.commute dest: less_imp_le order.trans[OF \\<tau>_mono, rotated])\n  qed\nnext\n  case (MatchP I r)\n  then have \"i < plen \\<pi>\"\n    by (force simp: pred_mapping_alt elim!: order.strict_trans2[OF _ progress_le_gen])\n  with MatchP.prems \\<tau>_prefix_conv[OF assms(1,2)] show ?case\n    unfolding sat.simps\n    by (intro ex_cong conj_cong match_cong_strong MatchP) (auto simp: progress_regex_def split: if_splits)\nnext\n  case (MatchF I r)\n  from MatchF.prems obtain b where right[simp]: \"right I = enat b\"\n    by (cases \"right I\") (auto simp add: Inf_UNIV_nat)\n  show ?case\n  proof (cases \"regex.atms r = {}\")\n    case True\n    from MatchF.prems(1) obtain j where \"\\<tau> \\<sigma> i + b + 1 \\<le> \\<tau> \\<sigma> j\" \"j \\<le> plen \\<pi>\"\n      by atomize_elim (auto 0 4 simp add: less_eq_Suc_le not_le dest!: le_cInf_iff[THEN iffD1, rotated -1])\n    then have 1: \"k < plen \\<pi>\" if \"\\<tau> \\<sigma> k \\<le> \\<tau> \\<sigma> i + b\" for k\n      by (meson \\<tau>_mono discrete not_le order.strict_trans2 that)\n    from MatchF.prems have \"i < progress \\<sigma>' P (Formula.MatchF I r) (plen \\<pi>)\"\n      unfolding progress_prefix_conv[OF assms(1,2)] by blast\n    then obtain j where \"\\<tau> \\<sigma>' i + b + 1 \\<le> \\<tau> \\<sigma>' j\" \"j \\<le> plen \\<pi>\"\n      by atomize_elim (auto 0 4 simp add: less_eq_Suc_le not_le dest!: le_cInf_iff[THEN iffD1, rotated -1])\n    then have 2: \"k < plen \\<pi>\" if \"\\<tau> \\<sigma>' k \\<le> \\<tau> \\<sigma>' i + b\" for k\n      by (meson \\<tau>_mono discrete not_le order.strict_trans2 that)\n    from MatchF.prems(1,4) True show ?thesis\n      unfolding sat.simps conj_commute[of \"left I \\<le> _\" \"_ \\<le> _\"]\n    proof (intro ex_cong conj_cong match_cong_strong, goal_cases left right sat)\n      case (left j)\n      then show ?case\n        by (intro iffI)\n          ((subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 1, symmetric]; auto elim: order.trans[OF \\<tau>_mono, rotated]),\n            (subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 2]; auto elim: order.trans[OF \\<tau>_mono, rotated]))\n    next\n      case (right j)\n      then show ?case\n        by (intro iffI)\n          ((subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 2, symmetric]; auto elim: order.trans[OF \\<tau>_mono, rotated]),\n            (subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 2]; auto elim: order.trans[OF \\<tau>_mono, rotated]))\n    qed auto\n  next\n    case False\n    from MatchF.prems(1) False obtain j where \"\\<tau> \\<sigma> i + b + 1 \\<le> \\<tau> \\<sigma> j\" \"(\\<forall>x\\<in>regex.atms r. j \\<le> progress \\<sigma> P x (plen \\<pi>))\"\n      by atomize_elim (auto 0 6 simp add: less_eq_Suc_le not_le progress_regex_def\n        dest!: le_cInf_iff[THEN iffD1, rotated -1])\n    then have 1: \"\\<phi> \\<in> regex.atms r \\<Longrightarrow> k < progress \\<sigma> P \\<phi> (plen \\<pi>)\" if \"\\<tau> \\<sigma> k \\<le> \\<tau> \\<sigma> i + b\" for k \\<phi>\n      using that\n      by (fastforce elim!: order.strict_trans2[rotated] intro: less_\\<tau>D[of \\<sigma>])\n    then have 2: \"k < plen \\<pi>\" if \"\\<tau> \\<sigma> k \\<le> \\<tau> \\<sigma> i + b\" \"regex.atms r \\<noteq> {}\" for k\n      using that\n      by (fastforce intro: order.strict_trans2[OF _ progress_le_gen[OF MatchF(5), of \\<sigma>], of k])\n\n    from MatchF.prems have \"i < progress \\<sigma>' P (Formula.MatchF I r) (plen \\<pi>)\"\n      unfolding progress_prefix_conv[OF assms(1,2)] by blast\n    with False obtain j where \"\\<tau> \\<sigma>' i + b + 1 \\<le> \\<tau> \\<sigma>' j\" \"(\\<forall>x\\<in>regex.atms r. j \\<le> progress \\<sigma>' P x (plen \\<pi>))\"\n      by atomize_elim (auto 0 6 simp add: less_eq_Suc_le not_le progress_regex_def\n        dest!: le_cInf_iff[THEN iffD1, rotated -1])\n    then have 11:  \"\\<phi> \\<in> regex.atms r \\<Longrightarrow> k < progress \\<sigma> P \\<phi> (plen \\<pi>)\" if \"\\<tau> \\<sigma>' k \\<le> \\<tau> \\<sigma>' i + b\" for k \\<phi>\n      using that using progress_prefix_conv[OF assms(1,2)]\n      by (auto 0 3 elim!: order.strict_trans2[rotated] intro: less_\\<tau>D[of \\<sigma>'])\n    have 21: \"k < plen \\<pi>\" if \"\\<tau> \\<sigma>' k \\<le> \\<tau> \\<sigma>' i + b\" for k\n      using 11[OF that(1)] False by (fastforce intro: order.strict_trans2[OF _ progress_le_gen[OF MatchF(5), of \\<sigma>], of k])\n    show ?thesis unfolding sat.simps conj_commute[of \"left I \\<le> _\" \"_ \\<le> _\"]\n    proof ((intro ex_cong conj_cong match_cong_strong MatchF(1)[OF _ _ MatchF(3-6)]; assumption?), goal_cases right left progress)\n      case (right j)\n      with False show ?case\n        by (intro iffI)\n          ((subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 2, symmetric]; auto elim: order.trans[OF \\<tau>_mono, rotated]),\n            (subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 21]; auto elim: order.trans[OF \\<tau>_mono, rotated]))\n    next\n      case (left j)\n      with False show ?case unfolding right enat_ord_code le_diff_conv add.commute[of b]\n        by (intro iffI)\n          ((subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 21, symmetric]; auto elim: order.trans[OF \\<tau>_mono, rotated]),\n            (subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 21]; auto elim: order.trans[OF \\<tau>_mono, rotated]))\n    next\n      case (progress j k z)\n      with False show ?case unfolding right enat_ord_code le_diff_conv add.commute[of b]\n        by (elim 1[rotated])\n          (subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 21]; auto elim!: order.trans[OF \\<tau>_mono, rotated])\n    qed\n  qed\nqed auto\n\nlemma sat_prefix_conv:\n  assumes \"prefix_of \\<pi> \\<sigma>\" and \"prefix_of \\<pi> \\<sigma>'\"\n  shows \"i < progress \\<sigma> Map.empty \\<phi> (plen \\<pi>) \\<Longrightarrow>\n    Formula.sat \\<sigma> Map.empty v i \\<phi> \\<longleftrightarrow> Formula.sat \\<sigma>' Map.empty v i \\<phi>\"\n  by (erule sat_prefix_conv_gen[OF assms]) auto\n\nlemma progress_remove_neg[simp]: \"progress \\<sigma> P (remove_neg \\<phi>) j = progress \\<sigma> P \\<phi> j\"\n  by (cases \\<phi>) simp_all\n\nlemma safe_progress_get_and: \"safe_formula \\<phi> \\<Longrightarrow>\n  Min ((\\<lambda>\\<phi>. progress \\<sigma> P \\<phi> j) ` set (get_and_list \\<phi>)) = progress \\<sigma> P \\<phi> j\"\n  by (induction \\<phi> rule: get_and_list.induct) auto\n\nlemma progress_convert_multiway: \"safe_formula \\<phi> \\<Longrightarrow> progress \\<sigma> P (convert_multiway \\<phi>) j = progress \\<sigma> P \\<phi> j\"\nproof (induction \\<phi> arbitrary: P rule: safe_formula_induct)\n  case (And_safe \\<phi> \\<psi>)\n  let ?c = \"convert_multiway (Formula.And \\<phi> \\<psi>)\"\n  let ?c\\<phi> = \"convert_multiway \\<phi>\"\n  let ?c\\<psi> = \"convert_multiway \\<psi>\"\n  have c_eq: \"?c = Formula.Ands (get_and_list ?c\\<phi> @ get_and_list ?c\\<psi>)\"\n    using And_safe by simp\n  from \\<open>safe_formula \\<phi>\\<close> have \"safe_formula ?c\\<phi>\" by (rule safe_convert_multiway)\n  moreover from \\<open>safe_formula \\<psi>\\<close> have \"safe_formula ?c\\<psi>\" by (rule safe_convert_multiway)\n  ultimately show ?case\n    unfolding c_eq\n    using And_safe.IH\n    by (auto simp: get_and_nonempty Min.union safe_progress_get_and)\nnext\n  case (And_Not \\<phi> \\<psi>)\n  let ?c = \"convert_multiway (Formula.And \\<phi> (Formula.Neg \\<psi>))\"\n  let ?c\\<phi> = \"convert_multiway \\<phi>\"\n  let ?c\\<psi> = \"convert_multiway \\<psi>\"\n  have c_eq: \"?c = Formula.Ands (Formula.Neg ?c\\<psi> # get_and_list ?c\\<phi>)\"\n    using And_Not by simp\n  from \\<open>safe_formula \\<phi>\\<close> have \"safe_formula ?c\\<phi>\" by (rule safe_convert_multiway)\n  moreover from \\<open>safe_formula \\<psi>\\<close> have \"safe_formula ?c\\<psi>\" by (rule safe_convert_multiway)\n  ultimately show ?case\n    unfolding c_eq\n    using And_Not.IH\n    by (auto simp: get_and_nonempty Min.union safe_progress_get_and)\nnext\n  case (MatchP I r)\n  from MatchP show ?case\n    unfolding progress.simps regex.map convert_multiway.simps regex.set_map image_image\n    by (intro if_cong arg_cong[of _ _ Min] image_cong)\n      (auto 0 4 simp: atms_def elim!: disjE_Not2 dest: safe_regex_safe_formula)\nnext\n  case (MatchF I r)\n  from MatchF show ?case\n    unfolding progress.simps regex.map convert_multiway.simps regex.set_map image_image\n    by (intro if_cong arg_cong[of _ _ Min] arg_cong[of _ _ Inf] arg_cong[of _ _ \"(\\<le>) _\"]\n      image_cong Collect_cong all_cong1 imp_cong conj_cong image_cong)\n      (auto 0 4 simp: atms_def elim!: disjE_Not2 dest: safe_regex_safe_formula)\nqed auto\n\n\ninterpretation verimon: monitor_timed_progress Formula.future_bounded \"\\<lambda>\\<sigma>. progress \\<sigma> Map.empty\"\n  by (unfold_locales, (fact progress_mono progress_le progress_time_conv sat_prefix_conv |\n        simp add: mmonitorable_def progress_ge)+)\n\nabbreviation \"mverdicts \\<equiv> verimon.verdicts\"\n\n\nsubsection \\<open>Correctness\\<close>\n\nsubsubsection \\<open>Invariants\\<close>\n\ndefinition wf_mbuf2 :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> (nat \\<Rightarrow> event_data table \\<Rightarrow> bool) \\<Rightarrow> (nat \\<Rightarrow> event_data table \\<Rightarrow> bool) \\<Rightarrow>\n    event_data mbuf2 \\<Rightarrow> bool\" where\n  \"wf_mbuf2 i ja jb P Q buf \\<longleftrightarrow> i \\<le> ja \\<and> i \\<le> jb \\<and> (case buf of (xs, ys) \\<Rightarrow>\n    list_all2 P [i..<ja] xs \\<and> list_all2 Q [i..<jb] ys)\"\n\ninductive list_all3 :: \"('a \\<Rightarrow> 'b \\<Rightarrow> 'c \\<Rightarrow> bool) \\<Rightarrow> 'a list \\<Rightarrow> 'b list \\<Rightarrow> 'c list \\<Rightarrow> bool\" for P :: \"('a \\<Rightarrow> 'b \\<Rightarrow> 'c \\<Rightarrow> bool)\" where\n  \"list_all3 P [] [] []\"\n| \"P a1 a2 a3 \\<Longrightarrow> list_all3 P q1 q2 q3 \\<Longrightarrow> list_all3 P (a1 # q1) (a2 # q2) (a3 # q3)\"\n\nlemma list_all3_list_all2D: \"list_all3 P xs ys zs \\<Longrightarrow>\n  (length xs = length ys \\<and> list_all2 (case_prod P) (zip xs ys) zs)\"\n  by (induct xs ys zs rule: list_all3.induct) auto\n\nlemma list_all2_list_all3I: \"length xs = length ys \\<Longrightarrow> list_all2 (case_prod P) (zip xs ys) zs \\<Longrightarrow>\n  list_all3 P xs ys zs\"\n  by (induct xs ys arbitrary: zs rule: list_induct2)\n    (auto simp: list_all2_Cons1 intro: list_all3.intros)\n\nlemma list_all3_list_all2_eq: \"list_all3 P xs ys zs \\<longleftrightarrow>\n  (length xs = length ys \\<and> list_all2 (case_prod P) (zip xs ys) zs)\"\n  using list_all2_list_all3I list_all3_list_all2D by blast\n\nlemma list_all3_mapD: \"list_all3 P (map f xs) (map g ys) (map h zs) \\<Longrightarrow>\n  list_all3 (\\<lambda>x y z. P (f x) (g y) (h z)) xs ys zs\"\n  by (induct \"map f xs\" \"map g ys\" \"map h zs\" arbitrary: xs ys zs rule: list_all3.induct)\n    (auto intro: list_all3.intros)\n\nlemma list_all3_mapI: \"list_all3 (\\<lambda>x y z. P (f x) (g y) (h z)) xs ys zs \\<Longrightarrow>\n  list_all3 P (map f xs) (map g ys) (map h zs)\"\n  by (induct xs ys zs rule: list_all3.induct)\n    (auto intro: list_all3.intros)\n\nlemma list_all3_map_iff: \"list_all3 P (map f xs) (map g ys) (map h zs) \\<longleftrightarrow>\n  list_all3 (\\<lambda>x y z. P (f x) (g y) (h z)) xs ys zs\"\n  using list_all3_mapD list_all3_mapI by blast\n\nlemmas list_all3_map =\n  list_all3_map_iff[where g=id and h=id, unfolded list.map_id id_apply]\n  list_all3_map_iff[where f=id and h=id, unfolded list.map_id id_apply]\n  list_all3_map_iff[where f=id and g=id, unfolded list.map_id id_apply]\n\nlemma list_all3_conv_all_nth:\n  \"list_all3 P xs ys zs =\n  (length xs = length ys \\<and> length ys = length zs \\<and> (\\<forall>i < length xs. P (xs!i) (ys!i) (zs!i)))\"\n  by (auto simp add: list_all3_list_all2_eq list_all2_conv_all_nth)\n\nlemma list_all3_refl [intro?]:\n  \"(\\<And>x. x \\<in> set xs \\<Longrightarrow> P x x x) \\<Longrightarrow> list_all3 P xs xs xs\"\n  by (simp add: list_all3_conv_all_nth)\n\ndefinition wf_mbufn :: \"nat \\<Rightarrow> nat list \\<Rightarrow> (nat \\<Rightarrow> event_data table \\<Rightarrow> bool) list \\<Rightarrow> event_data mbufn \\<Rightarrow> bool\" where\n  \"wf_mbufn i js Ps buf \\<longleftrightarrow> list_all3 (\\<lambda>P j xs. i \\<le> j \\<and> list_all2 P [i..<j] xs) Ps js buf\"\n\ndefinition wf_mbuf2' :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> event_data list set \\<Rightarrow>\n  Formula.formula \\<Rightarrow> Formula.formula \\<Rightarrow> event_data mbuf2 \\<Rightarrow> bool\" where\n  \"wf_mbuf2' \\<sigma> P V j n R \\<phi> \\<psi> buf \\<longleftrightarrow> wf_mbuf2 (min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j))\n    (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)\n    (\\<lambda>i. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>))\n    (\\<lambda>i. qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>)) buf\"\n\ndefinition wf_mbufn' :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> event_data list set \\<Rightarrow>\n  Formula.formula Regex.regex \\<Rightarrow> event_data mbufn \\<Rightarrow> bool\" where\n  \"wf_mbufn' \\<sigma>  P V j n R r buf \\<longleftrightarrow> (case to_mregex r of (mr, \\<phi>s) \\<Rightarrow>\n    wf_mbufn (progress_regex \\<sigma> P r j) (map (\\<lambda>\\<phi>. progress \\<sigma> P \\<phi> j) \\<phi>s)\n    (map (\\<lambda>\\<phi> i. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>)) \\<phi>s)\n    buf)\"\n\nlemma wf_mbuf2'_UNIV_alt: \"wf_mbuf2' \\<sigma> P V j n UNIV \\<phi> \\<psi> buf \\<longleftrightarrow> (case buf of (xs, ys) \\<Rightarrow>\n  list_all2 (\\<lambda>i. wf_table n (Formula.fv \\<phi>) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>))\n    [min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j) ..< (progress \\<sigma> P \\<phi> j)] xs \\<and>\n  list_all2 (\\<lambda>i. wf_table n (Formula.fv \\<psi>) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>))\n    [min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j) ..< (progress \\<sigma> P \\<psi> j)] ys)\"\n  unfolding wf_mbuf2'_def wf_mbuf2_def\n  by (simp add: mem_restr_UNIV[THEN eqTrueI, abs_def] split: prod.split)\n\ndefinition wf_ts :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> Formula.formula \\<Rightarrow> Formula.formula \\<Rightarrow> ts list \\<Rightarrow> bool\" where\n  \"wf_ts \\<sigma> P j \\<phi> \\<psi> ts \\<longleftrightarrow> list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)..<j] ts\"\n\ndefinition wf_ts_regex :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> Formula.formula Regex.regex \\<Rightarrow> ts list \\<Rightarrow> bool\" where\n  \"wf_ts_regex \\<sigma> P j r ts \\<longleftrightarrow> list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [progress_regex \\<sigma> P r j..<j] ts\"\n\nabbreviation \"Sincep pos \\<phi> I \\<psi> \\<equiv> Formula.Since (if pos then \\<phi> else Formula.Neg \\<phi>) I \\<psi>\"\n\ndefinition (in msaux) wf_since_aux :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> event_data list set \\<Rightarrow> args \\<Rightarrow>\n  Formula.formula \\<Rightarrow> Formula.formula \\<Rightarrow> 'msaux \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"wf_since_aux \\<sigma> V R args \\<phi> \\<psi> aux ne \\<longleftrightarrow> Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi> \\<and> (\\<exists>cur auxlist. valid_msaux args cur aux auxlist \\<and>\n    cur = (if ne = 0 then 0 else \\<tau> \\<sigma> (ne - 1)) \\<and>\n    sorted_wrt (\\<lambda>x y. fst x > fst y) auxlist \\<and>\n    (\\<forall>t X. (t, X) \\<in> set auxlist \\<longrightarrow> ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne - 1) \\<and> \\<tau> \\<sigma> (ne - 1) - t \\<le> right (args_ivl args) \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      qtable (args_n args) (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne-1) (Sincep (args_pos args) \\<phi> (point (\\<tau> \\<sigma> (ne - 1) - t)) \\<psi>)) X) \\<and>\n    (\\<forall>t. ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne - 1) \\<and> \\<tau> \\<sigma> (ne - 1) - t \\<le> right (args_ivl args) \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<longrightarrow>\n      (\\<exists>X. (t, X) \\<in> set auxlist)))\"\n\ndefinition wf_matchP_aux :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> event_data list set \\<Rightarrow>\n    \\<I> \\<Rightarrow> Formula.formula Regex.regex \\<Rightarrow> event_data mr\\<delta>aux \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"wf_matchP_aux \\<sigma> V n R I r aux ne \\<longleftrightarrow> sorted_wrt (\\<lambda>x y. fst x > fst y) aux \\<and>\n    (\\<forall>t X. (t, X) \\<in> set aux \\<longrightarrow> ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne-1) \\<and> \\<tau> \\<sigma> (ne-1) - t \\<le> right I \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      (case to_mregex r of (mr, \\<phi>s) \\<Rightarrow>\n      (\\<forall>ms \\<in> RPDs mr. qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne-1)\n         (Formula.MatchP (point (\\<tau> \\<sigma> (ne-1) - t)) (from_mregex ms \\<phi>s)))\n         (lookup X ms)))) \\<and>\n    (\\<forall>t. ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne-1) \\<and> \\<tau> \\<sigma> (ne-1) - t \\<le> right I \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<longrightarrow>\n      (\\<exists>X. (t, X) \\<in> set aux))\"\n\nlemma qtable_mem_restr_UNIV: \"qtable n A(mem_restr UNIV) Q X = wf_table n A Q X\"\n  unfolding qtable_def by auto\n\nlemma (in msaux) wf_since_aux_UNIV_alt:\n  \"wf_since_aux \\<sigma> V UNIV args \\<phi> \\<psi> aux ne \\<longleftrightarrow> Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi> \\<and> (\\<exists>cur auxlist. valid_msaux args cur aux auxlist \\<and>\n    cur = (if ne = 0 then 0 else \\<tau> \\<sigma> (ne - 1)) \\<and>\n    sorted_wrt (\\<lambda>x y. fst x > fst y) auxlist \\<and>\n    (\\<forall>t X. (t, X) \\<in> set auxlist \\<longrightarrow> ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne - 1) \\<and> \\<tau> \\<sigma> (ne - 1) - t \\<le> right (args_ivl args) \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      wf_table (args_n args) (Formula.fv \\<psi>)\n          (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne - 1) (Sincep (args_pos args) \\<phi> (point (\\<tau> \\<sigma> (ne - 1) - t)) \\<psi>)) X) \\<and>\n    (\\<forall>t. ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne - 1) \\<and> \\<tau> \\<sigma> (ne - 1) - t \\<le> right (args_ivl args) \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<longrightarrow>\n      (\\<exists>X. (t, X) \\<in> set auxlist)))\"\n  unfolding wf_since_aux_def qtable_mem_restr_UNIV ..\n\ndefinition wf_until_auxlist :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> event_data list set \\<Rightarrow> bool \\<Rightarrow>\n    Formula.formula \\<Rightarrow> \\<I> \\<Rightarrow> Formula.formula \\<Rightarrow> event_data muaux \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> auxlist ne \\<longleftrightarrow>\n    list_all2 (\\<lambda>x i. case x of (t, r1, r2) \\<Rightarrow> t = \\<tau> \\<sigma> i \\<and>\n      qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. if pos then (\\<forall>k\\<in>{i..<ne+length auxlist}. Formula.sat \\<sigma> V (map the v) k \\<phi>)\n          else (\\<exists>k\\<in>{i..<ne+length auxlist}. Formula.sat \\<sigma> V (map the v) k \\<phi>)) r1 \\<and>\n      qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. (\\<exists>j. i \\<le> j \\<and> j < ne + length auxlist \\<and> mem (\\<tau> \\<sigma> j - \\<tau> \\<sigma> i) I \\<and>\n          Formula.sat \\<sigma> V (map the v) j \\<psi> \\<and>\n          (\\<forall>k\\<in>{i..<j}. if pos then Formula.sat \\<sigma> V (map the v) k \\<phi> else \\<not> Formula.sat \\<sigma> V (map the v) k \\<phi>))) r2)\n      auxlist [ne..<ne+length auxlist]\"\n\ndefinition (in muaux) wf_until_aux :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> event_data list set \\<Rightarrow> args \\<Rightarrow>\n  Formula.formula \\<Rightarrow> Formula.formula \\<Rightarrow> 'muaux \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"wf_until_aux \\<sigma> V R args \\<phi> \\<psi> aux ne \\<longleftrightarrow> Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi> \\<and>\n    (\\<exists>cur auxlist. valid_muaux args cur aux auxlist \\<and>\n      cur = (if ne + length auxlist = 0 then 0 else \\<tau> \\<sigma> (ne + length auxlist - 1)) \\<and>\n      wf_until_auxlist \\<sigma> V (args_n args) R (args_pos args) \\<phi> (args_ivl args) \\<psi> auxlist ne)\"\n\nlemma (in muaux) wf_until_aux_UNIV_alt:\n  \"wf_until_aux \\<sigma> V UNIV args \\<phi> \\<psi> aux ne \\<longleftrightarrow> Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi> \\<and>\n    (\\<exists>cur auxlist. valid_muaux args cur aux auxlist \\<and>\n      cur = (if ne + length auxlist = 0 then 0 else \\<tau> \\<sigma> (ne + length auxlist - 1)) \\<and>\n      list_all2 (\\<lambda>x i. case x of (t, r1, r2) \\<Rightarrow> t = \\<tau> \\<sigma> i \\<and>\n      wf_table (args_n args) (Formula.fv \\<phi>) (\\<lambda>v. if (args_pos args)\n          then (\\<forall>k\\<in>{i..<ne+length auxlist}. Formula.sat \\<sigma> V (map the v) k \\<phi>)\n          else (\\<exists>k\\<in>{i..<ne+length auxlist}. Formula.sat \\<sigma> V (map the v) k \\<phi>)) r1 \\<and>\n      wf_table (args_n args) (Formula.fv \\<psi>) (\\<lambda>v. \\<exists>j. i \\<le> j \\<and> j < ne + length auxlist \\<and> mem (\\<tau> \\<sigma> j - \\<tau> \\<sigma> i) (args_ivl args) \\<and>\n          Formula.sat \\<sigma> V (map the v) j \\<psi> \\<and>\n          (\\<forall>k\\<in>{i..<j}. if (args_pos args) then Formula.sat \\<sigma> V (map the v) k \\<phi> else \\<not> Formula.sat \\<sigma> V (map the v) k \\<phi>)) r2)\n      auxlist [ne..<ne+length auxlist])\"\n  unfolding wf_until_aux_def wf_until_auxlist_def qtable_mem_restr_UNIV ..\n\ndefinition wf_matchF_aux :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> event_data list set \\<Rightarrow>\n    \\<I> \\<Rightarrow> Formula.formula Regex.regex \\<Rightarrow> event_data ml\\<delta>aux \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"wf_matchF_aux \\<sigma> V n R I r aux ne k \\<longleftrightarrow> (case to_mregex r of (mr, \\<phi>s) \\<Rightarrow>\n      list_all2 (\\<lambda>x i. case x of (t, rels, rel) \\<Rightarrow> t = \\<tau> \\<sigma> i \\<and>\n        list_all2 (\\<lambda>\\<phi>. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v.\n          Formula.sat \\<sigma> V (map the v) i \\<phi>)) \\<phi>s rels \\<and>\n        qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v. (\\<exists>j. i \\<le> j \\<and> j < ne + length aux + k \\<and> mem (\\<tau> \\<sigma> j - \\<tau> \\<sigma> i) I \\<and>\n          Regex.match (Formula.sat \\<sigma> V (map the v)) r i j)) rel)\n    aux [ne..<ne+length aux])\"\n\ndefinition wf_matchF_invar where\n  \"wf_matchF_invar \\<sigma> V n R I r st i =\n     (case st of (aux, Y) \\<Rightarrow> aux \\<noteq> [] \\<and> wf_matchF_aux \\<sigma> V n R I r aux i 0 \\<and>\n     (case to_mregex r of (mr, \\<phi>s) \\<Rightarrow> \\<forall>ms \\<in> LPDs mr.\n       qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v.\n         Regex.match (Formula.sat \\<sigma> V (map the v)) (from_mregex ms \\<phi>s) i (i + length aux - 1)) (lookup Y ms)))\"\n\ndefinition lift_envs' :: \"nat \\<Rightarrow> event_data list set \\<Rightarrow> event_data list set\" where\n  \"lift_envs' b R = (\\<lambda>(xs,ys). xs @ ys) ` ({xs. length xs = b} \\<times> R)\"\n\nfun formula_of_constraint :: \"Formula.trm \\<times> bool \\<times> mconstraint \\<times> Formula.trm \\<Rightarrow> Formula.formula\" where\n  \"formula_of_constraint (t1, True, MEq, t2) = Formula.Eq t1 t2\"\n| \"formula_of_constraint (t1, True, MLess, t2) = Formula.Less t1 t2\"\n| \"formula_of_constraint (t1, True, MLessEq, t2) = Formula.LessEq t1 t2\"\n| \"formula_of_constraint (t1, False, MEq, t2) = Formula.Neg (Formula.Eq t1 t2)\"\n| \"formula_of_constraint (t1, False, MLess, t2) = Formula.Neg (Formula.Less t1 t2)\"\n| \"formula_of_constraint (t1, False, MLessEq, t2) = Formula.Neg (Formula.LessEq t1 t2)\"\n\ninductive (in maux) wf_mformula :: \"Formula.trace \\<Rightarrow> nat \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow>\n  nat \\<Rightarrow> event_data list set \\<Rightarrow> ('msaux, 'muaux) mformula \\<Rightarrow> Formula.formula \\<Rightarrow> bool\"\n  for \\<sigma> j where\n    Eq: \"is_simple_eq t1 t2 \\<Longrightarrow>\n    \\<forall>x\\<in>Formula.fv_trm t1. x < n \\<Longrightarrow> \\<forall>x\\<in>Formula.fv_trm t2. x < n \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MRel (eq_rel n t1 t2)) (Formula.Eq t1 t2)\"\n  | neq_Var: \"x < n \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MRel empty_table) (Formula.Neg (Formula.Eq (Formula.Var x) (Formula.Var x)))\"\n  | Pred: \"\\<forall>x\\<in>Formula.fv (Formula.Pred e ts). x < n \\<Longrightarrow>\n    \\<forall>t\\<in>set ts. Formula.is_Var t \\<or> Formula.is_Const t \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MPred e ts) (Formula.Pred e ts)\"\n  | Let: \"wf_mformula \\<sigma> j P V m UNIV \\<phi> \\<phi>' \\<Longrightarrow>\n    wf_mformula \\<sigma> j (P(p \\<mapsto> progress \\<sigma> P \\<phi>' j))\n      (V(p \\<mapsto> \\<lambda>i. {v. length v = m - b \\<and> (\\<exists>zs. length zs = b \\<and> Formula.sat \\<sigma> V (zs @ v) i \\<phi>')})) n R \\<psi> \\<psi>' \\<Longrightarrow>\n    {0..<m} \\<subseteq> Formula.fv \\<phi>' \\<Longrightarrow> b \\<le> m \\<Longrightarrow> m = Formula.nfv \\<phi>' \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MLet p m b \\<phi> \\<psi>) (Formula.Let p b \\<phi>' \\<psi>')\"\n  | And: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow> wf_mformula \\<sigma> j P V n R \\<psi> \\<psi>' \\<Longrightarrow>\n    if pos then \\<chi> = Formula.And \\<phi>' \\<psi>'\n      else \\<chi> = Formula.And \\<phi>' (Formula.Neg \\<psi>') \\<and> Formula.fv \\<psi>' \\<subseteq> Formula.fv \\<phi>' \\<Longrightarrow>\n    wf_mbuf2' \\<sigma> P V j n R \\<phi>' \\<psi>' buf \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MAnd (fv \\<phi>') \\<phi> pos (fv \\<psi>') \\<psi> buf) \\<chi>\"\n  | AndAssign: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow>\n    x < n \\<Longrightarrow> x \\<notin> Formula.fv \\<phi>' \\<Longrightarrow> Formula.fv_trm t \\<subseteq> Formula.fv \\<phi>' \\<Longrightarrow> (x, t) = conf \\<Longrightarrow>\n    \\<psi>' = Formula.Eq (Formula.Var x) t \\<or> \\<psi>' = Formula.Eq t (Formula.Var x) \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MAndAssign \\<phi> conf) (Formula.And \\<phi>' \\<psi>')\"\n  | AndRel: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow>\n    \\<psi>' = formula_of_constraint conf \\<Longrightarrow>\n    (let (t1, _, _, t2) = conf in Formula.fv_trm t1 \\<union> Formula.fv_trm t2 \\<subseteq> Formula.fv \\<phi>') \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MAndRel \\<phi> conf) (Formula.And \\<phi>' \\<psi>')\"\n  | Ands: \"list_all2 (\\<lambda>\\<phi> \\<phi>'. wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>') l (l_pos @ map remove_neg l_neg) \\<Longrightarrow>\n    wf_mbufn (progress \\<sigma> P (Formula.Ands l') j) (map (\\<lambda>\\<psi>. progress \\<sigma> P \\<psi> j) (l_pos @ map remove_neg l_neg)) (map (\\<lambda>\\<psi> i.\n      qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>)) (l_pos @ map remove_neg l_neg)) buf \\<Longrightarrow>\n    (l_pos, l_neg) = partition safe_formula l' \\<Longrightarrow>\n    l_pos \\<noteq> [] \\<Longrightarrow>\n    list_all safe_formula (map remove_neg l_neg) \\<Longrightarrow>\n    A_pos = map fv l_pos \\<Longrightarrow>\n    A_neg = map fv l_neg \\<Longrightarrow>\n    \\<Union>(set A_neg) \\<subseteq> \\<Union>(set A_pos) \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MAnds A_pos A_neg l buf) (Formula.Ands l')\"\n  | Or: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow> wf_mformula \\<sigma> j P V n R \\<psi> \\<psi>' \\<Longrightarrow>\n    Formula.fv \\<phi>' = Formula.fv \\<psi>' \\<Longrightarrow>\n    wf_mbuf2' \\<sigma> P V j n R \\<phi>' \\<psi>' buf \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MOr \\<phi> \\<psi> buf) (Formula.Or \\<phi>' \\<psi>')\"\n  | Neg: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow> Formula.fv \\<phi>' = {} \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MNeg \\<phi>) (Formula.Neg \\<phi>')\"\n  | Exists: \"wf_mformula \\<sigma> j P V (Suc n) (lift_envs R) \\<phi> \\<phi>' \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MExists \\<phi>) (Formula.Exists \\<phi>')\"\n  | Agg: \"wf_mformula \\<sigma> j P V (b + n) (lift_envs' b R) \\<phi> \\<phi>' \\<Longrightarrow>\n    y < n \\<Longrightarrow>\n    y + b \\<notin> Formula.fv \\<phi>' \\<Longrightarrow>\n    {0..<b} \\<subseteq> Formula.fv \\<phi>' \\<Longrightarrow>\n    Formula.fv_trm f \\<subseteq> Formula.fv \\<phi>' \\<Longrightarrow>\n    g0 = (Formula.fv \\<phi>' \\<subseteq> {0..<b}) \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MAgg g0 y \\<omega> b f \\<phi>) (Formula.Agg y \\<omega> b f \\<phi>')\"\n  | Prev: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow>\n    first \\<longleftrightarrow> j = 0 \\<Longrightarrow>\n    list_all2 (\\<lambda>i. qtable n (Formula.fv \\<phi>') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>'))\n      [min (progress \\<sigma> P \\<phi>' j) (j-1)..<progress \\<sigma> P \\<phi>' j] buf \\<Longrightarrow>\n    list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [min (progress \\<sigma> P \\<phi>' j) (j-1)..<j] nts \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MPrev I \\<phi> first buf nts) (Formula.Prev I \\<phi>')\"\n  | Next: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow>\n    first \\<longleftrightarrow> progress \\<sigma> P \\<phi>' j = 0 \\<Longrightarrow>\n    list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [progress \\<sigma> P \\<phi>' j - 1..<j] nts \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MNext I \\<phi> first nts) (Formula.Next I \\<phi>')\"\n  | Since: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow> wf_mformula \\<sigma> j P V n R \\<psi> \\<psi>' \\<Longrightarrow>\n    if args_pos args then \\<phi>'' = \\<phi>' else \\<phi>'' = Formula.Neg \\<phi>' \\<Longrightarrow>\n    safe_formula \\<phi>'' = args_pos args \\<Longrightarrow>\n    args_ivl args = I \\<Longrightarrow>\n    args_n args = n \\<Longrightarrow>\n    args_L args = Formula.fv \\<phi>' \\<Longrightarrow>\n    args_R args = Formula.fv \\<psi>' \\<Longrightarrow>\n    Formula.fv \\<phi>' \\<subseteq> Formula.fv \\<psi>' \\<Longrightarrow>\n    wf_mbuf2' \\<sigma> P V j n R \\<phi>' \\<psi>' buf \\<Longrightarrow>\n    wf_ts \\<sigma> P j \\<phi>' \\<psi>' nts \\<Longrightarrow>\n    wf_since_aux \\<sigma> V R args \\<phi>' \\<psi>' aux (progress \\<sigma> P (Formula.Since \\<phi>'' I \\<psi>') j) \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MSince args \\<phi> \\<psi> buf nts aux) (Formula.Since \\<phi>'' I \\<psi>')\"\n  | Until: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow> wf_mformula \\<sigma> j P V n R \\<psi> \\<psi>' \\<Longrightarrow>\n    if args_pos args then \\<phi>'' = \\<phi>' else \\<phi>'' = Formula.Neg \\<phi>' \\<Longrightarrow>\n    safe_formula \\<phi>'' = args_pos args \\<Longrightarrow>\n    args_ivl args = I \\<Longrightarrow>\n    args_n args = n \\<Longrightarrow>\n    args_L args = Formula.fv \\<phi>' \\<Longrightarrow>\n    args_R args = Formula.fv \\<psi>' \\<Longrightarrow>\n    Formula.fv \\<phi>' \\<subseteq> Formula.fv \\<psi>' \\<Longrightarrow>\n    wf_mbuf2' \\<sigma> P V j n R \\<phi>' \\<psi>' buf \\<Longrightarrow>\n    wf_ts \\<sigma> P j \\<phi>' \\<psi>' nts \\<Longrightarrow>\n    wf_until_aux \\<sigma> V R args \\<phi>' \\<psi>' aux (progress \\<sigma> P (Formula.Until \\<phi>'' I \\<psi>') j) \\<Longrightarrow>\n    progress \\<sigma> P (Formula.Until \\<phi>'' I \\<psi>') j + length_muaux args aux = min (progress \\<sigma> P \\<phi>' j) (progress \\<sigma> P \\<psi>' j) \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MUntil args \\<phi> \\<psi> buf nts aux) (Formula.Until \\<phi>'' I \\<psi>')\"\n  | MatchP: \"(case to_mregex r of (mr', \\<phi>s') \\<Rightarrow>\n      list_all2 (wf_mformula \\<sigma> j P V n R) \\<phi>s \\<phi>s' \\<and> mr = mr') \\<Longrightarrow>\n    mrs = sorted_list_of_set (RPDs mr) \\<Longrightarrow>\n    safe_regex Past Strict r \\<Longrightarrow>\n    wf_mbufn' \\<sigma> P V j n R r buf \\<Longrightarrow>\n    wf_ts_regex \\<sigma> P j r nts \\<Longrightarrow>\n    wf_matchP_aux \\<sigma> V n R I r aux (progress \\<sigma> P (Formula.MatchP I r) j) \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MMatchP I mr mrs \\<phi>s buf nts aux) (Formula.MatchP I r)\"\n  | MatchF: \"(case to_mregex r of (mr', \\<phi>s') \\<Rightarrow>\n      list_all2 (wf_mformula \\<sigma> j P V n R) \\<phi>s \\<phi>s' \\<and> mr = mr') \\<Longrightarrow>\n    mrs = sorted_list_of_set (LPDs mr) \\<Longrightarrow>\n    safe_regex Futu Strict r \\<Longrightarrow>\n    wf_mbufn' \\<sigma> P V j n R r buf \\<Longrightarrow>\n    wf_ts_regex \\<sigma> P j r nts \\<Longrightarrow>\n    wf_matchF_aux \\<sigma> V n R I r aux (progress \\<sigma> P (Formula.MatchF I r) j) 0 \\<Longrightarrow>\n    progress \\<sigma> P (Formula.MatchF I r) j + length aux = progress_regex \\<sigma> P r j \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MMatchF I mr mrs \\<phi>s buf nts aux) (Formula.MatchF I r)\"\n\ndefinition (in maux) wf_mstate :: \"Formula.formula \\<Rightarrow> Formula.prefix \\<Rightarrow> event_data list set \\<Rightarrow> ('msaux, 'muaux) mstate \\<Rightarrow> bool\" where\n  \"wf_mstate \\<phi> \\<pi> R st \\<longleftrightarrow> mstate_n st = Formula.nfv \\<phi> \\<and> (\\<forall>\\<sigma>. prefix_of \\<pi> \\<sigma> \\<longrightarrow>\n    mstate_i st = progress \\<sigma> Map.empty \\<phi> (plen \\<pi>) \\<and>\n    wf_mformula \\<sigma> (plen \\<pi>) Map.empty Map.empty (mstate_n st) R (mstate_m st) \\<phi>)\"\n\n\nsubsubsection \\<open>Initialisation\\<close>\n\n\nlemma wf_mbuf2'_0: \"pred_mapping (\\<lambda>x. x = 0) P \\<Longrightarrow> wf_mbuf2' \\<sigma> P V 0 n R \\<phi> \\<psi> ([], [])\"\n  unfolding wf_mbuf2'_def wf_mbuf2_def by simp\n\nlemma wf_mbufn'_0: \"to_mregex r = (mr, \\<phi>s) \\<Longrightarrow> pred_mapping (\\<lambda>x. x = 0) P \\<Longrightarrow> wf_mbufn' \\<sigma> P V 0 n R r (replicate (length \\<phi>s) [])\"\n  unfolding wf_mbufn'_def wf_mbufn_def map_replicate_const[symmetric]\n  by (auto simp: list_all3_map intro: list_all3_refl simp: Min_eq_iff progress_regex_def)\n\nlemma wf_ts_0: \"wf_ts \\<sigma> P 0 \\<phi> \\<psi> []\"\n  unfolding wf_ts_def by simp\n\nlemma wf_ts_regex_0: \"wf_ts_regex \\<sigma> P 0 r []\"\n  unfolding wf_ts_regex_def by simp\n\nlemma (in msaux) wf_since_aux_Nil: \"Formula.fv \\<phi>' \\<subseteq> Formula.fv \\<psi>' \\<Longrightarrow>\n  wf_since_aux \\<sigma> V R (init_args I n (Formula.fv \\<phi>') (Formula.fv \\<psi>') b) \\<phi>' \\<psi>' (init_msaux (init_args I n (Formula.fv \\<phi>') (Formula.fv \\<psi>') b)) 0\"\n  unfolding wf_since_aux_def by (auto intro!: valid_init_msaux)\n\nlemma (in muaux) wf_until_aux_Nil: \"Formula.fv \\<phi>' \\<subseteq> Formula.fv \\<psi>' \\<Longrightarrow>\n  wf_until_aux \\<sigma> V R (init_args I n (Formula.fv \\<phi>') (Formula.fv \\<psi>') b) \\<phi>' \\<psi>' (init_muaux (init_args I n (Formula.fv \\<phi>') (Formula.fv \\<psi>') b)) 0\"\n  unfolding wf_until_aux_def wf_until_auxlist_def by (auto intro: valid_init_muaux)\n\nlemma wf_matchP_aux_Nil: \"wf_matchP_aux \\<sigma> V n R I r [] 0\"\n  unfolding wf_matchP_aux_def by simp\n\nlemma wf_matchF_aux_Nil: \"wf_matchF_aux \\<sigma> V n R I r [] 0 k\"\n  unfolding wf_matchF_aux_def by simp\n\nlemma fv_regex_alt: \"safe_regex m g r \\<Longrightarrow> Formula.fv_regex r = (\\<Union>\\<phi> \\<in> atms r. Formula.fv \\<phi>)\"\n  unfolding fv_regex_alt atms_def\n  by (auto 0 3 dest: safe_regex_safe_formula)\n\nlemmas to_mregex_atms =\n  to_mregex_ok[THEN conjunct1, THEN equalityD1, THEN set_mp, rotated]\n\nlemma (in maux) wf_minit0: \"safe_formula \\<phi> \\<Longrightarrow> \\<forall>x\\<in>Formula.fv \\<phi>. x < n \\<Longrightarrow>\n  pred_mapping (\\<lambda>x. x = 0) P \\<Longrightarrow>\n  wf_mformula \\<sigma> 0 P V n R (minit0 n \\<phi>) \\<phi>\"\nproof (induction arbitrary: n R P V rule: safe_formula_induct)\n  case (Eq_Const c d)\n  then show ?case\n    by (auto simp add: is_simple_eq_def simp del: eq_rel.simps intro!: wf_mformula.Eq)\nnext\n  case (Eq_Var1 c x)\n  then show ?case\n    by (auto simp add: is_simple_eq_def simp del: eq_rel.simps intro!: wf_mformula.Eq)\nnext\n  case (Eq_Var2 c x)\n  then show ?case\n    by (auto simp add: is_simple_eq_def simp del: eq_rel.simps intro!: wf_mformula.Eq)\nnext\n  case (neq_Var x y)\n  then show ?case by (auto intro!: wf_mformula.neq_Var)\nnext\n  case (Pred e ts)\n  then show ?case by (auto intro!: wf_mformula.Pred)\nnext\n  case (Let p b \\<phi> \\<psi>)\n  with fvi_less_nfv show ?case\n    by (auto simp: pred_mapping_alt dom_def intro!: wf_mformula.Let Let(4,5))\nnext\n  case (And_assign \\<phi> \\<psi>)\n  then have 1: \"\\<forall>x\\<in>fv \\<psi>. x < n\" by simp\n  from 1 \\<open>safe_assignment (fv \\<phi>) \\<psi>\\<close>\n  obtain x t where\n    \"x < n\" \"x \\<notin> fv \\<phi>\" \"fv_trm t \\<subseteq> fv \\<phi>\"\n    \"\\<psi> = Formula.Eq (Formula.Var x) t \\<or> \\<psi> = Formula.Eq t (Formula.Var x)\"\n    unfolding safe_assignment_def by (force split: formula.splits trm.splits)\n  with And_assign show ?case\n    by (auto intro!: wf_mformula.AndAssign split: trm.splits)\nnext\n  case (And_safe \\<phi> \\<psi>)\n  then show ?case by (auto intro!: wf_mformula.And wf_mbuf2'_0)\nnext\n  case (And_constraint \\<phi> \\<psi>)\n  from \\<open>fv \\<psi> \\<subseteq> fv \\<phi>\\<close> \\<open>is_constraint \\<psi>\\<close>\n  obtain t1 p c t2 where\n    \"(t1, p, c, t2) = split_constraint \\<psi>\"\n    \"formula_of_constraint (split_constraint \\<psi>) = \\<psi>\"\n    \"fv_trm t1 \\<union> fv_trm t2 \\<subseteq> fv \\<phi>\"\n    by (induction rule: is_constraint.induct) auto\n  with And_constraint show ?case\n    by (auto 0 3 intro!: wf_mformula.AndRel)\nnext\n  case (And_Not \\<phi> \\<psi>)\n  then show ?case by (auto intro!: wf_mformula.And wf_mbuf2'_0)\nnext\n  case (Ands l pos neg)\n  note posneg = \"Ands.hyps\"(1)\n  let ?wf_minit = \"\\<lambda>x. wf_mformula \\<sigma> 0 P V n R (minit0 n x)\"\n  let ?pos = \"filter safe_formula l\"\n  let ?neg = \"filter (Not \\<circ> safe_formula) l\"\n  have \"list_all2 ?wf_minit ?pos pos\"\n    using Ands.IH(1) Ands.prems posneg by (auto simp: list_all_iff intro!: list.rel_refl_strong)\n  moreover have \"list_all2 ?wf_minit (map remove_neg ?neg) (map remove_neg neg)\"\n    using Ands.IH(2) Ands.prems posneg by (auto simp: list.rel_map list_all_iff intro!: list.rel_refl_strong)\n  moreover have \"list_all3 (\\<lambda>_ _ _. True) (?pos @ map remove_neg ?neg) (?pos @ map remove_neg ?neg) l\"\n    by (auto simp: list_all3_conv_all_nth comp_def sum_length_filter_compl)\n  moreover have \"l \\<noteq> [] \\<Longrightarrow> (MIN \\<phi>\\<in>set l. (0 :: nat)) = 0\"\n    by (cases l) (auto simp: Min_eq_iff)\n  ultimately show ?case using Ands.hyps Ands.prems(2)\n    by (auto simp: wf_mbufn_def list_all3_map list.rel_map map_replicate_const[symmetric] subset_eq\n        map_map[symmetric] map_append[symmetric] simp del: map_map map_append\n        intro!: wf_mformula.Ands list_all2_appendI)\nnext\n  case (Neg \\<phi>)\n  then show ?case by (auto intro!: wf_mformula.Neg)\nnext\n  case (Or \\<phi> \\<psi>)\n  then show ?case by (auto intro!: wf_mformula.Or wf_mbuf2'_0)\nnext\n  case (Exists \\<phi>)\n  then show ?case by (auto simp: fvi_Suc_bound intro!: wf_mformula.Exists)\nnext\n  case (Agg y \\<omega> b f \\<phi>)\n  then show ?case by (auto intro!: wf_mformula.Agg Agg.IH fvi_plus_bound)\nnext\n  case (Prev I \\<phi>)\n  thm wf_mformula.Prev[where P=P]\n  then show ?case by (auto intro!: wf_mformula.Prev)\nnext\n  case (Next I \\<phi>)\n  then show ?case by (auto intro!: wf_mformula.Next)\nnext\n  case (Since \\<phi> I \\<psi>)\n  then show ?case\n    using wf_since_aux_Nil\n    by (auto simp add: init_args_def intro!: wf_mformula.Since wf_mbuf2'_0 wf_ts_0)\nnext\n  case (Not_Since \\<phi> I \\<psi>)\n  then show ?case\n    using wf_since_aux_Nil\n    by (auto simp add: init_args_def intro!: wf_mformula.Since wf_mbuf2'_0 wf_ts_0)\nnext\n  case (Until \\<phi> I \\<psi>)\n  then show ?case\n    using valid_length_muaux[OF valid_init_muaux[OF Until(1)]] wf_until_aux_Nil\n    by (auto simp add: init_args_def simp del: progress_simps intro!: wf_mformula.Until wf_mbuf2'_0 wf_ts_0)\nnext\n  case (Not_Until \\<phi> I \\<psi>)\n  then show ?case\n    using valid_length_muaux[OF valid_init_muaux[OF Not_Until(1)]] wf_until_aux_Nil\n    by (auto simp add: init_args_def simp del: progress_simps intro!: wf_mformula.Until wf_mbuf2'_0 wf_ts_0)\nnext\n  case (MatchP I r)\n  then show ?case\n    by (auto simp: list.rel_map fv_regex_alt simp del: progress_simps split: prod.split\n        intro!: wf_mformula.MatchP list.rel_refl_strong wf_mbufn'_0 wf_ts_regex_0 wf_matchP_aux_Nil\n        dest!: to_mregex_atms)\nnext\n  case (MatchF I r)\n  then show ?case\n    by (auto simp: list.rel_map fv_regex_alt progress_le Min_eq_iff progress_regex_def\n        simp del: progress_simps split: prod.split\n        intro!: wf_mformula.MatchF list.rel_refl_strong wf_mbufn'_0 wf_ts_regex_0 wf_matchF_aux_Nil\n        dest!: to_mregex_atms)\nqed\n\nlemma (in maux) wf_mstate_minit: \"safe_formula \\<phi> \\<Longrightarrow> wf_mstate \\<phi> pnil R (minit \\<phi>)\"\n  unfolding wf_mstate_def minit_def Let_def\n  by (auto intro!: wf_minit0 fvi_less_nfv)\n\n\nsubsubsection \\<open>Evaluation\\<close>\n\nlemma match_wf_tuple: \"Some f = match ts xs \\<Longrightarrow>\n  wf_tuple n (\\<Union>t\\<in>set ts. Formula.fv_trm t) (Table.tabulate f 0 n)\"\n  by (induction ts xs arbitrary: f rule: match.induct)\n    (fastforce simp: wf_tuple_def split: if_splits option.splits)+\n\nlemma match_fvi_trm_None: \"Some f = match ts xs \\<Longrightarrow> \\<forall>t\\<in>set ts. x \\<notin> Formula.fv_trm t \\<Longrightarrow> f x = None\"\n  by (induction ts xs arbitrary: f rule: match.induct) (auto split: if_splits option.splits)\n\nlemma match_fvi_trm_Some: \"Some f = match ts xs \\<Longrightarrow> t \\<in> set ts \\<Longrightarrow> x \\<in> Formula.fv_trm t \\<Longrightarrow> f x \\<noteq> None\"\n  by (induction ts xs arbitrary: f rule: match.induct) (auto split: if_splits option.splits)\n\nlemma match_eval_trm: \"\\<forall>t\\<in>set ts. \\<forall>i\\<in>Formula.fv_trm t. i < n \\<Longrightarrow> Some f = match ts xs \\<Longrightarrow>\n    map (Formula.eval_trm (Table.tabulate (\\<lambda>i. the (f i)) 0 n)) ts = xs\"\nproof (induction ts xs arbitrary: f rule: match.induct)\n  case (3 x ts y ys)\n  from 3(1)[symmetric] 3(2,3) show ?case\n    by (auto 0 3 dest: match_fvi_trm_Some sym split: option.splits if_splits intro!: eval_trm_fv_cong)\nqed (auto split: if_splits)\n\nlemma wf_tuple_tabulate_Some: \"wf_tuple n A (Table.tabulate f 0 n) \\<Longrightarrow> x \\<in> A \\<Longrightarrow> x < n \\<Longrightarrow> \\<exists>y. f x = Some y\"\n  unfolding wf_tuple_def by auto\n\nlemma ex_match: \"wf_tuple n (\\<Union>t\\<in>set ts. Formula.fv_trm t) v \\<Longrightarrow>\n  \\<forall>t\\<in>set ts. (\\<forall>x\\<in>Formula.fv_trm t. x < n) \\<and> (Formula.is_Var t \\<or> Formula.is_Const t) \\<Longrightarrow>\n  \\<exists>f. match ts (map (Formula.eval_trm (map the v)) ts) = Some f \\<and> v = Table.tabulate f 0 n\"\nproof (induction ts \"map (Formula.eval_trm (map the v)) ts\" arbitrary: v rule: match.induct)\n  case (3 x ts y ys)\n  then show ?case\n  proof (cases \"x \\<in> (\\<Union>t\\<in>set ts. Formula.fv_trm t)\")\n    case True\n    with 3 show ?thesis\n      by (auto simp: insert_absorb dest!: wf_tuple_tabulate_Some meta_spec[of _ v])\n  next\n    case False\n    with 3(3,4) have\n      *: \"map (Formula.eval_trm (map the v)) ts = map (Formula.eval_trm (map the (v[x := None]))) ts\"\n      by (auto simp: wf_tuple_def nth_list_update intro!: eval_trm_fv_cong)\n    from False 3(2-4) obtain f where\n      \"match ts (map (Formula.eval_trm (map the v)) ts) = Some f\" \"v[x := None] = Table.tabulate f 0 n\"\n      unfolding *\n      by (atomize_elim, intro 3(1)[of \"v[x := None]\"])\n        (auto simp: wf_tuple_def nth_list_update intro!: eval_trm_fv_cong)\n    moreover from False this have \"f x = None\" \"length v = n\"\n      by (auto dest: match_fvi_trm_None[OF sym] arg_cong[of _ _ length])\n    ultimately show ?thesis using 3(3)\n      by (auto simp: list_eq_iff_nth_eq wf_tuple_def)\n  qed\nqed (auto simp: wf_tuple_def intro: nth_equalityI)\n\nlemma eq_rel_eval_trm: \"v \\<in> eq_rel n t1 t2 \\<Longrightarrow> is_simple_eq t1 t2 \\<Longrightarrow>\n  \\<forall>x\\<in>Formula.fv_trm t1 \\<union> Formula.fv_trm t2. x < n \\<Longrightarrow>\n  Formula.eval_trm (map the v) t1 = Formula.eval_trm (map the v) t2\"\n  by (cases t1; cases t2) (simp_all add: is_simple_eq_def singleton_table_def split: if_splits)\n\nlemma in_eq_rel: \"wf_tuple n (Formula.fv_trm t1 \\<union> Formula.fv_trm t2) v \\<Longrightarrow>\n  is_simple_eq t1 t2 \\<Longrightarrow>\n  Formula.eval_trm (map the v) t1 = Formula.eval_trm (map the v) t2 \\<Longrightarrow>\n  v \\<in> eq_rel n t1 t2\"\n  by (cases t1; cases t2)\n    (auto simp: is_simple_eq_def singleton_table_def wf_tuple_def unit_table_def\n      intro!: nth_equalityI split: if_splits)\n\nlemma table_eq_rel: \"is_simple_eq t1 t2 \\<Longrightarrow>\n  table n (Formula.fv_trm t1 \\<union> Formula.fv_trm t2) (eq_rel n t1 t2)\"\n  by (cases t1; cases t2; simp add: is_simple_eq_def)\n\nlemma wf_tuple_Suc_fviD: \"wf_tuple (Suc n) (Formula.fvi b \\<phi>) v \\<Longrightarrow> wf_tuple n (Formula.fvi (Suc b) \\<phi>) (tl v)\"\n  unfolding wf_tuple_def by (simp add: fvi_Suc nth_tl)\n\nlemma table_fvi_tl: \"table (Suc n) (Formula.fvi b \\<phi>) X \\<Longrightarrow> table n (Formula.fvi (Suc b) \\<phi>) (tl ` X)\"\n  unfolding table_def by (auto intro: wf_tuple_Suc_fviD)\n\nlemma wf_tuple_Suc_fvi_SomeI: \"0 \\<in> Formula.fvi b \\<phi> \\<Longrightarrow> wf_tuple n (Formula.fvi (Suc b) \\<phi>) v \\<Longrightarrow>\n  wf_tuple (Suc n) (Formula.fvi b \\<phi>) (Some x # v)\"\n  unfolding wf_tuple_def\n  by (auto simp: fvi_Suc less_Suc_eq_0_disj)\n\nlemma wf_tuple_Suc_fvi_NoneI: \"0 \\<notin> Formula.fvi b \\<phi> \\<Longrightarrow> wf_tuple n (Formula.fvi (Suc b) \\<phi>) v \\<Longrightarrow>\n  wf_tuple (Suc n) (Formula.fvi b \\<phi>) (None # v)\"\n  unfolding wf_tuple_def\n  by (auto simp: fvi_Suc less_Suc_eq_0_disj)\n\nlemma qtable_project_fv: \"qtable (Suc n) (fv \\<phi>) (mem_restr (lift_envs R)) P X \\<Longrightarrow>\n    qtable n (Formula.fvi (Suc 0) \\<phi>) (mem_restr R)\n      (\\<lambda>v. \\<exists>x. P ((if 0 \\<in> fv \\<phi> then Some x else None) # v)) (tl ` X)\"\n  using neq0_conv by (fastforce simp: image_iff Bex_def fvi_Suc elim!: qtable_cong dest!: qtable_project)\n\nlemma mem_restr_lift_envs'_append[simp]:\n  \"length xs = b \\<Longrightarrow> mem_restr (lift_envs' b R) (xs @ ys) = mem_restr R ys\"\n  unfolding mem_restr_def lift_envs'_def\n  by (auto simp: list_all2_append list.rel_map intro!: exI[where x=\"map the xs\"] list.rel_refl)\n\nlemma nth_list_update_alt: \"xs[i := x] ! j = (if i < length xs \\<and> i = j then x else xs ! j)\"\n  by auto\n\nlemma wf_tuple_upd_None: \"wf_tuple n A xs \\<Longrightarrow> A - {i} = B \\<Longrightarrow> wf_tuple n B (xs[i:=None])\"\n  unfolding wf_tuple_def\n  by (auto simp: nth_list_update_alt)\n\nlemma mem_restr_upd_None: \"mem_restr R xs \\<Longrightarrow> mem_restr R (xs[i:=None])\"\n  unfolding mem_restr_def\n  by (auto simp: list_all2_conv_all_nth nth_list_update_alt)\n\nlemma mem_restr_dropI: \"mem_restr (lift_envs' b R) xs \\<Longrightarrow> mem_restr R (drop b xs)\"\n  unfolding mem_restr_def lift_envs'_def\n  by (auto simp: append_eq_conv_conj list_all2_append2)\n\nlemma mem_restr_dropD:\n  assumes \"b \\<le> length xs\" and \"mem_restr R (drop b xs)\"\n  shows \"mem_restr (lift_envs' b R) xs\"\nproof -\n  let ?R = \"\\<lambda>a b. a \\<noteq> None \\<longrightarrow> a = Some b\"\n  from assms(2) obtain v where \"v \\<in> R\" and \"list_all2 ?R (drop b xs) v\"\n    unfolding mem_restr_def ..\n  show ?thesis unfolding mem_restr_def proof\n    have \"list_all2 ?R (take b xs) (map the (take b xs))\"\n      by (auto simp: list.rel_map intro!: list.rel_refl)\n    moreover note \\<open>list_all2 ?R (drop b xs) v\\<close>\n    ultimately have \"list_all2 ?R (take b xs @ drop b xs) (map the (take b xs) @ v)\"\n      by (rule list_all2_appendI)\n    then show \"list_all2 ?R xs (map the (take b xs) @ v)\" by simp\n    show \"map the (take b xs) @ v \\<in> lift_envs' b R\"\n      unfolding lift_envs'_def using assms(1) \\<open>v \\<in> R\\<close> by auto\n  qed\nqed\n\nlemma wf_tuple_append: \"wf_tuple a {x \\<in> A. x < a} xs \\<Longrightarrow>\n  wf_tuple b {x - a | x. x \\<in> A \\<and> x \\<ge> a} ys \\<Longrightarrow>\n  wf_tuple (a + b) A (xs @ ys)\"\n  unfolding wf_tuple_def by (auto simp: nth_append eq_diff_iff)\n\nlemma wf_tuple_map_Some: \"length xs = n \\<Longrightarrow> {0..<n} \\<subseteq> A \\<Longrightarrow> wf_tuple n A (map Some xs)\"\n  unfolding wf_tuple_def by auto\n\nlemma wf_tuple_drop: \"wf_tuple (b + n) A xs \\<Longrightarrow> {x - b | x. x \\<in> A \\<and> x \\<ge> b} = B \\<Longrightarrow>\n  wf_tuple n B (drop b xs)\"\n  unfolding wf_tuple_def by force\n\nlemma ecard_image: \"inj_on f A \\<Longrightarrow> ecard (f ` A) = ecard A\"\n  unfolding ecard_def by (auto simp: card_image dest: finite_imageD)\n\nlemma meval_trm_eval_trm: \"wf_tuple n A x \\<Longrightarrow> fv_trm t \\<subseteq> A \\<Longrightarrow> \\<forall>i\\<in>A. i < n \\<Longrightarrow>\n    meval_trm t x = Formula.eval_trm (map the x) t\"\n  unfolding wf_tuple_def\n  by (induction t) simp_all\n\nlemma list_update_id: \"xs ! i = z \\<Longrightarrow> xs[i:=z] = xs\"\n  by (induction xs arbitrary: i) (auto split: nat.split)\n\nlemma qtable_wf_tupleD: \"qtable n A P Q X \\<Longrightarrow> \\<forall>x\\<in>X. wf_tuple n A x\"\n  unfolding qtable_def table_def by blast\n\nlemma qtable_eval_agg:\n  assumes inner: \"qtable (b + n) (Formula.fv \\<phi>) (mem_restr (lift_envs' b R))\n      (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>) rel\"\n    and n: \"\\<forall>x\\<in>Formula.fv (Formula.Agg y \\<omega> b f \\<phi>). x < n\"\n    and fresh: \"y + b \\<notin> Formula.fv \\<phi>\"\n    and b_fv: \"{0..<b} \\<subseteq> Formula.fv \\<phi>\"\n    and f_fv: \"Formula.fv_trm f \\<subseteq> Formula.fv \\<phi>\"\n    and g0: \"g0 = (Formula.fv \\<phi> \\<subseteq> {0..<b})\"\n  shows \"qtable n (Formula.fv (Formula.Agg y \\<omega> b f \\<phi>)) (mem_restr R)\n      (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (Formula.Agg y \\<omega> b f \\<phi>)) (eval_agg n g0 y \\<omega> b f rel)\"\n    (is \"qtable _ ?fv _ ?Q ?rel'\")\nproof -\n  define M where \"M = (\\<lambda>v. {(x, ecard Zs) | x Zs.\n      Zs = {zs. length zs = b \\<and> Formula.sat \\<sigma> V (zs @ v) i \\<phi> \\<and> Formula.eval_trm (zs @ v) f = x} \\<and>\n      Zs \\<noteq> {}})\"\n  have f_fvi: \"Formula.fvi_trm b f \\<subseteq> Formula.fvi b \\<phi>\"\n    using f_fv by (auto simp: fvi_trm_iff_fv_trm[where b=b] fvi_iff_fv[where b=b])\n  show ?thesis proof (cases \"g0 \\<and> rel = empty_table\")\n    case True\n    then have [simp]: \"Formula.fvi b \\<phi> = {}\"\n      by (auto simp: g0 fvi_iff_fv(1)[where b=b])\n    then have [simp]: \"Formula.fvi_trm b f = {}\"\n      using f_fvi by auto\n    show ?thesis proof (rule qtableI)\n      show \"table n ?fv ?rel'\" by (simp add: eval_agg_def True)\n    next\n      fix v\n      assume \"wf_tuple n ?fv v\" \"mem_restr R v\"\n      have \"\\<not> Formula.sat \\<sigma> V (zs @ map the v) i \\<phi>\" if [simp]: \"length zs = b\" for zs\n      proof -\n        let ?zs = \"map2 (\\<lambda>z i. if i \\<in> Formula.fv \\<phi> then Some z else None) zs [0..<b]\"\n        have \"wf_tuple b {x \\<in> fv \\<phi>. x < b} ?zs\"\n          by (simp add: wf_tuple_def)\n        then have \"wf_tuple (b + n) (Formula.fv \\<phi>) (?zs @ v[y:=None])\"\n          using \\<open>wf_tuple n ?fv v\\<close> True\n          by (auto simp: g0 intro!: wf_tuple_append wf_tuple_upd_None)\n        then have \"\\<not> Formula.sat \\<sigma> V (map the (?zs @ v[y:=None])) i \\<phi>\"\n          using True \\<open>mem_restr R v\\<close>\n          by (auto simp del: map_append dest!: in_qtableI[OF inner, rotated -1]\n              intro!: mem_restr_upd_None)\n        also have \"Formula.sat \\<sigma> V (map the (?zs @ v[y:=None])) i \\<phi> \\<longleftrightarrow> Formula.sat \\<sigma> V (zs @ map the v) i \\<phi>\"\n          using True by (auto simp: g0 nth_append intro!: sat_fv_cong)\n        finally show ?thesis .\n      qed\n      then have M_empty: \"M (map the v) = {}\"\n        unfolding M_def by blast\n      show \"Formula.sat \\<sigma> V (map the v) i (Formula.Agg y \\<omega> b f \\<phi>)\"\n        if \"v \\<in> eval_agg n g0 y \\<omega> b f rel\"\n        using M_empty True that n\n        by (simp add: M_def eval_agg_def g0 singleton_table_def)\n      have \"v \\<in> singleton_table n y (the (v ! y))\" \"length v = n\"\n        using \\<open>wf_tuple n ?fv v\\<close> unfolding wf_tuple_def singleton_table_def\n        by (auto simp add: tabulate_alt map_nth\n            intro!: trans[OF map_cong[where g=\"(!) v\", simplified nth_map, OF refl], symmetric])\n      then show \"v \\<in> eval_agg n g0 y \\<omega> b f rel\"\n        if \"Formula.sat \\<sigma> V (map the v) i (Formula.Agg y \\<omega> b f \\<phi>)\"\n        using M_empty True that n\n        by (simp add: M_def eval_agg_def g0)\n    qed\n  next\n    case non_default_case: False\n    have union_fv: \"{0..<b} \\<union> (\\<lambda>x. x + b) ` Formula.fvi b \\<phi> = fv \\<phi>\"\n      using b_fv\n      by (auto simp: fvi_iff_fv(1)[where b=b] intro!: image_eqI[where b=x and x=\"x - b\" for x])\n    have b_n: \"\\<forall>x\\<in>fv \\<phi>. x < b + n\"\n    proof\n      fix x assume \"x \\<in> fv \\<phi>\"\n      show \"x < b + n\" proof (cases \"x \\<ge> b\")\n        case True\n        with \\<open>x \\<in> fv \\<phi>\\<close> have \"x - b \\<in> ?fv\"\n          by (simp add: fvi_iff_fv(1)[where b=b])\n        then show ?thesis using n f_fvi by (auto simp: Un_absorb2)\n      qed simp\n    qed\n\n    define M' where \"M' = (\\<lambda>k. let group = Set.filter (\\<lambda>x. drop b x = k) rel;\n        images = meval_trm f ` group\n      in (\\<lambda>y. (y, ecard (Set.filter (\\<lambda>x. meval_trm f x = y) group))) ` images)\"\n    have M'_M: \"M' (drop b x) = M (map the (drop b x))\" if \"x \\<in> rel\" \"mem_restr (lift_envs' b R) x\" for x\n    proof -\n      from that have wf_x: \"wf_tuple (b + n) (fv \\<phi>) x\"\n        by (auto elim!: in_qtableE[OF inner])\n      then have wf_zs_x: \"wf_tuple (b + n) (fv \\<phi>) (map Some zs @ drop b x)\"\n        if \"length zs = b\" for zs\n        using that b_fv\n        by (auto intro!: wf_tuple_append wf_tuple_map_Some wf_tuple_drop)\n      have 1: \"(length zs = b \\<and> Formula.sat \\<sigma> V (zs @ map the (drop b x)) i \\<phi> \\<and>\n          Formula.eval_trm (zs @ map the (drop b x)) f = y) \\<longleftrightarrow>\n        (\\<exists>a. a \\<in> rel \\<and> take b a = map Some zs \\<and> drop b a = drop b x \\<and> meval_trm f a = y)\"\n        (is \"?A \\<longleftrightarrow> (\\<exists>a. ?B a)\") for y zs\n      proof (intro iffI conjI)\n        assume ?A\n        then have \"?B (map Some zs @ drop (length zs) x)\"\n          using in_qtableI[OF inner wf_zs_x] \\<open>mem_restr (lift_envs' b R) x\\<close>\n            meval_trm_eval_trm[OF wf_zs_x f_fv b_n]\n          by (auto intro!: mem_restr_dropI)\n        then show \"\\<exists>a. ?B a\" ..\n      next\n        assume \"\\<exists>a. ?B a\"\n        then obtain a where \"?B a\" ..\n        then have \"a \\<in> rel\" and a_eq: \"a = map Some zs @ drop b x\"\n          using append_take_drop_id[of b a] by auto\n        then have \"length a = b + n\"\n          using inner unfolding qtable_def table_def\n          by (blast intro!: wf_tuple_length)\n        then show \"length zs = b\"\n          using wf_tuple_length[OF wf_x] unfolding a_eq by simp\n        then have \"mem_restr (lift_envs' b R) a\"\n          using \\<open>mem_restr _ x\\<close> unfolding a_eq by (auto intro!: mem_restr_dropI)\n        then show \"Formula.sat \\<sigma> V (zs @ map the (drop b x)) i \\<phi>\"\n          using in_qtableE[OF inner \\<open>a \\<in> rel\\<close>]\n          by (auto simp: a_eq sat_fv_cong[THEN iffD1, rotated -1])\n        from \\<open>?B a\\<close> show \"Formula.eval_trm (zs @ map the (drop b x)) f = y\"\n          using meval_trm_eval_trm[OF wf_zs_x f_fv b_n, OF \\<open>length zs = b\\<close>]\n          unfolding a_eq by simp\n      qed\n      have 2: \"map Some (map the (take b a)) = take b a\" if \"a \\<in> rel\" for a\n        using that b_fv inner[THEN qtable_wf_tupleD]\n        unfolding table_def wf_tuple_def\n        by (auto simp: list_eq_iff_nth_eq)\n      have 3: \"ecard {zs. \\<exists>a. a \\<in> rel \\<and> take b a = map Some zs \\<and> drop b a = drop b x \\<and> P a} =\n        ecard {a. a \\<in> rel \\<and> drop b a = drop b x \\<and> P a}\" (is \"ecard ?A = ecard ?B\") for P\n      proof -\n        have \"ecard ?A = ecard ((\\<lambda>zs. map Some zs @ drop b x) ` ?A)\"\n          by (auto intro!: ecard_image[symmetric] inj_onI)\n        also have \"(\\<lambda>zs. map Some zs @ drop b x) ` ?A = ?B\"\n          by (subst (1 2) eq_commute) (auto simp: image_iff, metis \"2\" append_take_drop_id)\n        finally show ?thesis .\n      qed\n      show ?thesis\n        unfolding M_def M'_def\n        by (auto simp: non_default_case Let_def image_def Set.filter_def 1 3, metis \"2\")\n    qed\n    have drop_lift: \"mem_restr (lift_envs' b R) x\" if \"x \\<in> rel\" \"mem_restr R ((drop b x)[y:=z])\" for x z\n    proof -\n      have \"(drop b x)[y:=None] = (drop b x)[y:=drop b x ! y]\" proof -\n        from \\<open>x \\<in> rel\\<close> have \"drop b x ! y = None\"\n          using fresh n inner[THEN qtable_wf_tupleD]\n          by (simp add: add.commute wf_tuple_def)\n        then show ?thesis by simp\n      qed\n      then have \"(drop b x)[y:=None] = drop b x\" by simp\n      moreover from \\<open>x \\<in> rel\\<close> have \"length x = b + n\"\n        using inner[THEN qtable_wf_tupleD]\n        by (simp add: wf_tuple_def)\n      moreover from that(2) have \"mem_restr R ((drop b x)[y:=z, y:=None])\"\n        by (rule mem_restr_upd_None)\n      ultimately show ?thesis\n        by (auto intro!: mem_restr_dropD)\n    qed\n\n    {\n      fix v\n      assume \"mem_restr R v\"\n      have \"v \\<in> (\\<lambda>k. k[y:=Some (eval_agg_op \\<omega> (M' k))]) ` drop b ` rel \\<longleftrightarrow>\n          v \\<in> (\\<lambda>k. k[y:=Some (eval_agg_op \\<omega> (M (map the k)))]) ` drop b ` rel\"\n        (is \"v \\<in> ?A \\<longleftrightarrow> v \\<in> ?B\")\n      proof\n        assume \"v \\<in> ?A\"\n        then obtain v' where *: \"v' \\<in> rel\" \"v = (drop b v')[y:=Some (eval_agg_op \\<omega> (M' (drop b v')))]\"\n          by auto\n        then have \"M' (drop b v') = M (map the (drop b v'))\"\n          using \\<open>mem_restr R v\\<close> by (auto intro!: M'_M drop_lift)\n        with * show \"v \\<in> ?B\" by simp\n      next\n        assume \"v \\<in> ?B\"\n        then obtain v' where *: \"v' \\<in> rel\" \"v = (drop b v')[y:=Some (eval_agg_op \\<omega> (M (map the (drop b v'))))]\"\n          by auto\n        then have \"M (map the (drop b v')) = M' (drop b v')\"\n          using \\<open>mem_restr R v\\<close> by (auto intro!: M'_M[symmetric] drop_lift)\n        with * show \"v \\<in> ?A\" by simp\n      qed\n      then have \"v \\<in> eval_agg n g0 y \\<omega> b f rel \\<longleftrightarrow> v \\<in> (\\<lambda>k. k[y:=Some (eval_agg_op \\<omega> (M (map the k)))]) ` drop b ` rel\"\n        by (simp add: non_default_case eval_agg_def M'_def Let_def)\n    }\n    note alt = this\n\n    show ?thesis proof (rule qtableI)\n      show \"table n ?fv ?rel'\"\n        using inner[THEN qtable_wf_tupleD] n f_fvi\n        by (auto simp: eval_agg_def non_default_case table_def wf_tuple_def Let_def nth_list_update\n            fvi_iff_fv[where b=b] add.commute)\n    next\n      fix v\n      assume \"wf_tuple n ?fv v\" \"mem_restr R v\"\n      then have length_v: \"length v = n\" by (simp add: wf_tuple_def)\n\n      show \"Formula.sat \\<sigma> V (map the v) i (Formula.Agg y \\<omega> b f \\<phi>)\"\n        if \"v \\<in> eval_agg n g0 y \\<omega> b f rel\"\n      proof -\n        from that obtain v' where \"v' \\<in> rel\"\n          \"v = (drop b v')[y:=Some (eval_agg_op \\<omega> (M (map the (drop b v'))))]\"\n          using alt[OF \\<open>mem_restr R v\\<close>] by blast\n        then have length_v': \"length v' = b + n\"\n          using inner[THEN qtable_wf_tupleD]\n          by (simp add: wf_tuple_def)\n        have \"Formula.sat \\<sigma> V (map the v') i \\<phi>\"\n          using \\<open>v' \\<in> rel\\<close> \\<open>mem_restr R v\\<close>\n          by (auto simp: \\<open>v = _\\<close> elim!: in_qtableE[OF inner] intro!: drop_lift \\<open>v' \\<in> rel\\<close>)\n        then have \"Formula.sat \\<sigma> V (map the (take b v') @ map the v) i \\<phi>\"\n        proof (rule sat_fv_cong[THEN iffD1, rotated], intro ballI)\n          fix x\n          assume \"x \\<in> fv \\<phi>\"\n          then have \"x \\<noteq> y + b\" using fresh by blast\n          moreover have \"x < length v'\"\n            using \\<open>x \\<in> fv \\<phi>\\<close> b_n by (simp add: length_v')\n          ultimately show \"map the v' ! x = (map the (take b v') @ map the v) ! x\"\n            by (auto simp: \\<open>v = _\\<close> nth_append)\n        qed\n        then have 1: \"M (map the v) \\<noteq> {}\" by (force simp: M_def length_v')\n\n        have \"y < length (drop b v')\" using n by (simp add: length_v')\n        moreover have \"Formula.sat \\<sigma> V (zs @ map the v) i \\<phi> \\<longleftrightarrow>\n          Formula.sat \\<sigma> V (zs @ map the (drop b v')) i \\<phi>\" if \"length zs = b\" for zs\n        proof (intro sat_fv_cong ballI)\n          fix x\n          assume \"x \\<in> fv \\<phi>\"\n          then have \"x \\<noteq> y + b\" using fresh by blast\n          moreover have \"x < length v'\"\n            using \\<open>x \\<in> fv \\<phi>\\<close> b_n by (simp add: length_v')\n          ultimately show \"(zs @ map the v) ! x = (zs @ map the (drop b v')) ! x\"\n            by (auto simp: \\<open>v = _\\<close> that nth_append)\n        qed\n        moreover have \"Formula.eval_trm (zs @ map the v) f =\n          Formula.eval_trm (zs @ map the (drop b v')) f\" if \"length zs = b\" for zs\n        proof (intro eval_trm_fv_cong ballI)\n          fix x\n          assume \"x \\<in> fv_trm f\"\n          then have \"x \\<noteq> y + b\" using f_fv fresh by blast\n          moreover have \"x < length v'\"\n            using \\<open>x \\<in> fv_trm f\\<close> f_fv b_n by (auto simp: length_v')\n          ultimately show \"(zs @ map the v) ! x = (zs @ map the (drop b v')) ! x\"\n            by (auto simp: \\<open>v = _\\<close> that nth_append)\n        qed\n        ultimately have \"map the v ! y = eval_agg_op \\<omega> (M (map the v))\"\n          by (simp add: M_def \\<open>v = _\\<close> conj_commute cong: conj_cong)\n        with 1 show ?thesis by (auto simp: M_def)\n      qed\n\n      show \"v \\<in> eval_agg n g0 y \\<omega> b f rel\"\n        if sat_Agg: \"Formula.sat \\<sigma> V (map the v) i (Formula.Agg y \\<omega> b f \\<phi>)\"\n      proof -\n        obtain zs where \"length zs = b\" and \"map Some zs @ v[y:=None] \\<in> rel\"\n        proof (cases \"fv \\<phi> \\<subseteq> {0..<b}\")\n          case True\n          with non_default_case have \"rel \\<noteq> empty_table\" by (simp add: g0)\n          then obtain x where \"x \\<in> rel\" by auto\n          have \"(\\<forall>i < n. (v[y:=None]) ! i = None)\"\n            using True \\<open>wf_tuple n ?fv v\\<close> f_fv\n            by (fastforce simp: wf_tuple_def fvi_iff_fv[where b=b] fvi_trm_iff_fv_trm[where b=b])\n          moreover have x: \"(\\<forall>i < n. drop b x ! i = None) \\<and> length x = b + n\"\n            using True \\<open>x \\<in> rel\\<close> inner[THEN qtable_wf_tupleD] f_fv\n            by (auto simp: wf_tuple_def)\n          ultimately have \"v[y:=None] = drop b x\"\n            unfolding list_eq_iff_nth_eq by (auto simp: length_v)\n          with \\<open>x \\<in> rel\\<close> have \"take b x @ v[y:=None] \\<in> rel\" by simp\n          moreover have \"map (Some \\<circ> the) (take b x) = take b x\"\n            using True \\<open>x \\<in> rel\\<close> inner[THEN qtable_wf_tupleD] b_fv\n            by (subst map_cong[where g=id, OF refl]) (auto simp: wf_tuple_def in_set_conv_nth)\n          ultimately have \"map Some (map the (take b x)) @ v[y:=None] \\<in> rel\" by simp\n          then show thesis using x[THEN conjunct2] by (fastforce intro!: that[rotated])\n        next\n          case False\n          with sat_Agg obtain zs where \"length zs = b\" and \"Formula.sat \\<sigma> V (zs @ map the v) i \\<phi>\"\n            by auto\n          then have \"Formula.sat \\<sigma> V (zs @ map the (v[y:=None])) i \\<phi>\"\n            using fresh\n            by (auto simp: map_update not_less nth_append elim!: sat_fv_cong[THEN iffD1, rotated]\n                intro!: nth_list_update_neq[symmetric])\n          then have \"map Some zs @ v[y:=None] \\<in> rel\"\n            using b_fv f_fv fresh\n            by (auto intro!: in_qtableI[OF inner] wf_tuple_append wf_tuple_map_Some\n                wf_tuple_upd_None \\<open>wf_tuple n ?fv v\\<close> mem_restr_upd_None \\<open>mem_restr R v\\<close>\n                simp: \\<open>length zs = b\\<close> set_eq_iff fvi_iff_fv[where b=b] fvi_trm_iff_fv_trm[where b=b])\n              force+\n          with that \\<open>length zs = b\\<close> show thesis by blast\n        qed\n        then have 1: \"v[y:=None] \\<in> drop b ` rel\" by (intro image_eqI) auto\n\n        have y_length: \"y < length v\" using n by (simp add: length_v)\n        moreover have \"Formula.sat \\<sigma> V (zs @ map the (v[y:=None])) i \\<phi> \\<longleftrightarrow>\n          Formula.sat \\<sigma> V (zs @ map the v) i \\<phi>\" if \"length zs = b\" for zs\n        proof (intro sat_fv_cong ballI)\n          fix x\n          assume \"x \\<in> fv \\<phi>\"\n          then have \"x \\<noteq> y + b\" using fresh by blast\n          moreover have \"x < b + length v\"\n            using \\<open>x \\<in> fv \\<phi>\\<close> b_n by (simp add: length_v)\n          ultimately show \"(zs @ map the (v[y:=None])) ! x = (zs @ map the v) ! x\"\n            by (auto simp: that nth_append)\n        qed\n        moreover have \"Formula.eval_trm (zs @ map the (v[y:=None])) f =\n          Formula.eval_trm (zs @ map the v) f\" if \"length zs = b\" for zs\n        proof (intro eval_trm_fv_cong ballI)\n          fix x\n          assume \"x \\<in> fv_trm f\"\n          then have \"x \\<noteq> y + b\" using f_fv fresh by blast\n          moreover have \"x < b + length v\"\n            using \\<open>x \\<in> fv_trm f\\<close> f_fv b_n by (auto simp: length_v)\n          ultimately show \"(zs @ map the (v[y:=None])) ! x = (zs @ map the v) ! x\"\n            by (auto simp: that nth_append)\n        qed\n        ultimately have \"map the v ! y = eval_agg_op \\<omega> (M (map the (v[y:=None])))\"\n          using sat_Agg by (simp add: M_def cong: conj_cong) (simp cong: rev_conj_cong)\n        then have 2: \"v ! y = Some (eval_agg_op \\<omega> (M (map the (v[y:=None]))))\"\n          using \\<open>wf_tuple n ?fv v\\<close> y_length by (auto simp add: wf_tuple_def)\n        show ?thesis\n          unfolding alt[OF \\<open>mem_restr R v\\<close>]\n          by (rule image_eqI[where x=\"v[y:=None]\"]) (use 1 2 in \\<open>auto simp: y_length list_update_id\\<close>)\n      qed\n    qed\n  qed\nqed\n\nlemma mprev: \"mprev_next I xs ts = (ys, xs', ts') \\<Longrightarrow>\n  list_all2 P [i..<j'] xs \\<Longrightarrow> list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [i..<j] ts \\<Longrightarrow> i \\<le> j' \\<Longrightarrow> i < j \\<Longrightarrow>\n  list_all2 (\\<lambda>i X. if mem (\\<tau> \\<sigma> (Suc i) - \\<tau> \\<sigma> i) I then P i X else X = empty_table)\n    [i..<min j' (j-1)] ys \\<and>\n  list_all2 P [min j' (j-1)..<j'] xs' \\<and>\n  list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [min j' (j-1)..<j] ts'\"\nproof (induction I xs ts arbitrary: i ys xs' ts' rule: mprev_next.induct)\n  case (1 I ts)\n  then have \"min j' (j-1) = i\" by auto\n  with 1 show ?case by auto\nnext\n  case (3 I v v' t)\n  then have \"min j' (j-1) = i\" by (auto simp: list_all2_Cons2 upt_eq_Cons_conv)\n  with 3 show ?case by auto\nnext\n  case (4 I x xs t t' ts)\n  from 4(1)[of \"tl ys\" xs' ts' \"Suc i\"] 4(2-6) show ?case\n    by (auto simp add: list_all2_Cons2 upt_eq_Cons_conv Suc_less_eq2\n        elim!: list.rel_mono_strong split: prod.splits if_splits)\nqed simp\n\nlemma mnext: \"mprev_next I xs ts = (ys, xs', ts') \\<Longrightarrow>\n  list_all2 P [Suc i..<j'] xs \\<Longrightarrow> list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [i..<j] ts \\<Longrightarrow> Suc i \\<le> j' \\<Longrightarrow> i < j \\<Longrightarrow>\n  list_all2 (\\<lambda>i X. if mem (\\<tau> \\<sigma> (Suc i) - \\<tau> \\<sigma> i) I then P (Suc i) X else X = empty_table)\n    [i..<min (j'-1) (j-1)] ys \\<and>\n  list_all2 P [Suc (min (j'-1) (j-1))..<j'] xs' \\<and>\n  list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [min (j'-1) (j-1)..<j] ts'\"\nproof (induction I xs ts arbitrary: i ys xs' ts' rule: mprev_next.induct)\n  case (1 I ts)\n  then have \"min (j' - 1) (j-1) = i\" by auto\n  with 1 show ?case by auto\nnext\n  case (3 I v v' t)\n  then have \"min (j' - 1) (j-1) = i\" by (auto simp: list_all2_Cons2 upt_eq_Cons_conv)\n  with 3 show ?case by auto\nnext\n  case (4 I x xs t t' ts)\n  from 4(1)[of \"tl ys\" xs' ts' \"Suc i\"] 4(2-6) show ?case\n    by (auto simp add: list_all2_Cons2 upt_eq_Cons_conv Suc_less_eq2\n        elim!: list.rel_mono_strong split: prod.splits if_splits) (* slow 10 sec *)\nqed simp\n\nlemma in_foldr_UnI: \"x \\<in> A \\<Longrightarrow> A \\<in> set xs \\<Longrightarrow> x \\<in> foldr (\\<union>) xs {}\"\n  by (induction xs) auto\n\nlemma in_foldr_UnE: \"x \\<in> foldr (\\<union>) xs {} \\<Longrightarrow> (\\<And>A. A \\<in> set xs \\<Longrightarrow> x \\<in> A \\<Longrightarrow> P) \\<Longrightarrow> P\"\n  by (induction xs) auto\n\nlemma sat_the_restrict: \"fv \\<phi> \\<subseteq> A \\<Longrightarrow> Formula.sat \\<sigma> V (map the (restrict A v)) i \\<phi> = Formula.sat \\<sigma> V (map the v) i \\<phi>\"\n  by (rule sat_fv_cong) (auto intro!: map_the_restrict)\n\nlemma eps_the_restrict: \"fv_regex r \\<subseteq> A \\<Longrightarrow> Regex.eps (Formula.sat \\<sigma> V (map the (restrict A v))) i r = Regex.eps (Formula.sat \\<sigma> V (map the v)) i r\"\n  by (rule eps_fv_cong) (auto intro!: map_the_restrict)\n\nlemma sorted_wrt_filter[simp]: \"sorted_wrt R xs \\<Longrightarrow> sorted_wrt R (filter P xs)\"\n  by (induct xs) auto\n\nlemma concat_map_filter[simp]:\n  \"concat (map f (filter P xs)) = concat (map (\\<lambda>x. if P x then f x else []) xs)\"\n  by (induct xs) auto\n\nlemma map_filter_alt:\n  \"map f (filter P xs) = concat (map (\\<lambda>x. if P x then [f x] else []) xs)\"\n  by (induct xs) auto\n\nlemma (in maux) update_since:\n  assumes pre: \"wf_since_aux \\<sigma> V R args \\<phi> \\<psi> aux ne\"\n    and qtable1: \"qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne \\<phi>) rel1\"\n    and qtable2: \"qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne \\<psi>) rel2\"\n    and result_eq: \"(rel, aux') = update_since args rel1 rel2 (\\<tau> \\<sigma> ne) aux\"\n    and fvi_subset: \"Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi>\"\n    and args_ivl: \"args_ivl args = I\"\n    and args_n: \"args_n args = n\"\n    and args_L: \"args_L args = Formula.fv \\<phi>\"\n    and args_R: \"args_R args = Formula.fv \\<psi>\"\n    and args_pos: \"args_pos args = pos\"\n  shows \"wf_since_aux \\<sigma> V R args \\<phi> \\<psi> aux' (Suc ne)\"\n    and \"qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne (Sincep pos \\<phi> I \\<psi>)) rel\"\nproof -\n  let ?wf_tuple = \"\\<lambda>v. wf_tuple n (Formula.fv \\<psi>) v\"\n  note sat.simps[simp del]\n  from pre[unfolded wf_since_aux_def] obtain cur auxlist where aux: \"valid_msaux args cur aux auxlist\"\n    \"sorted_wrt (\\<lambda>x y. fst y < fst x) auxlist\"\n    \"\\<And>t X. (t, X) \\<in> set auxlist \\<Longrightarrow> ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne - 1) \\<and> \\<tau> \\<sigma> (ne - 1) - t \\<le> right I \\<and>\n      (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      qtable n (fv \\<psi>) (mem_restr R)\n        (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne - 1) (Sincep pos \\<phi> (point (\\<tau> \\<sigma> (ne - 1) - t)) \\<psi>)) X\"\n    \"\\<And>t. ne \\<noteq> 0 \\<Longrightarrow> t \\<le> \\<tau> \\<sigma> (ne - 1) \\<Longrightarrow> \\<tau> \\<sigma> (ne - 1) - t \\<le> right I \\<Longrightarrow> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<Longrightarrow>\n      (\\<exists>X. (t, X) \\<in> set auxlist)\"\n    and cur_def:\n    \"cur = (if ne = 0 then 0 else \\<tau> \\<sigma> (ne - 1))\"\n    unfolding args_ivl args_n args_pos by blast\n  from pre[unfolded wf_since_aux_def] have fv_sub: \"Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi>\" by simp\n\n  define aux0 where \"aux0 = join_msaux args rel1 (add_new_ts_msaux args (\\<tau> \\<sigma> ne) aux)\"\n  define auxlist0 where \"auxlist0 = [(t, join rel pos rel1). (t, rel) \\<leftarrow> auxlist, \\<tau> \\<sigma> ne - t \\<le> right I]\"\n  have tabL: \"table (args_n args) (args_L args) rel1\"\n    using qtable1[unfolded qtable_def] unfolding args_n[symmetric] args_L[symmetric] by simp\n  have cur_le: \"cur \\<le> \\<tau> \\<sigma> ne\"\n    unfolding cur_def by auto\n  have valid0: \"valid_msaux args (\\<tau> \\<sigma> ne) aux0 auxlist0\" unfolding aux0_def auxlist0_def\n    using valid_join_msaux[OF valid_add_new_ts_msaux[OF aux(1)], OF cur_le tabL]\n    by (auto simp: args_ivl args_pos cur_def map_filter_alt split_beta cong: map_cong)\n  from aux(2) have sorted_auxlist0: \"sorted_wrt (\\<lambda>x y. fst x > fst y) auxlist0\"\n    unfolding auxlist0_def\n    by (induction auxlist) (auto simp add: sorted_wrt_append)\n  have in_auxlist0_1: \"(t, X) \\<in> set auxlist0 \\<Longrightarrow> ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne-1) \\<and> \\<tau> \\<sigma> ne - t \\<le> right I \\<and>\n      (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. (Formula.sat \\<sigma> V (map the v) (ne-1) (Sincep pos \\<phi> (point (\\<tau> \\<sigma> (ne-1) - t)) \\<psi>) \\<and>\n        (if pos then Formula.sat \\<sigma> V (map the v) ne \\<phi> else \\<not> Formula.sat \\<sigma> V (map the v) ne \\<phi>))) X\" for t X\n    unfolding auxlist0_def using fvi_subset\n    by (auto 0 1 elim!: qtable_join[OF _ qtable1] simp: sat_the_restrict dest!: aux(3))\n  then have in_auxlist0_le_\\<tau>: \"(t, X) \\<in> set auxlist0 \\<Longrightarrow> t \\<le> \\<tau> \\<sigma> ne\" for t X\n    by (meson \\<tau>_mono diff_le_self le_trans)\n  have in_auxlist0_2: \"ne \\<noteq> 0 \\<Longrightarrow> t \\<le> \\<tau> \\<sigma> (ne-1) \\<Longrightarrow> \\<tau> \\<sigma> ne - t \\<le> right I \\<Longrightarrow> \\<exists>i. \\<tau> \\<sigma> i = t \\<Longrightarrow>\n    \\<exists>X. (t, X) \\<in> set auxlist0\" for t\n  proof -\n    fix t\n    assume \"ne \\<noteq> 0\" \"t \\<le> \\<tau> \\<sigma> (ne-1)\" \"\\<tau> \\<sigma> ne - t \\<le> right I\" \"\\<exists>i. \\<tau> \\<sigma> i = t\"\n    then obtain X where \"(t, X) \\<in> set auxlist\"\n      by (atomize_elim, intro aux(4))\n        (auto simp: gr0_conv_Suc elim!: order_trans[rotated] intro!: diff_le_mono \\<tau>_mono)\n    with \\<open>\\<tau> \\<sigma> ne - t \\<le> right I\\<close> have \"(t, join X pos rel1) \\<in> set auxlist0\"\n      unfolding auxlist0_def by (auto elim!: bexI[rotated] intro!: exI[of _ X])\n    then show \"\\<exists>X. (t, X) \\<in> set auxlist0\"\n      by blast\n  qed\n  have auxlist0_Nil: \"auxlist0 = [] \\<Longrightarrow> ne = 0 \\<or> ne \\<noteq> 0 \\<and> (\\<forall>t. t \\<le> \\<tau> \\<sigma> (ne-1) \\<and> \\<tau> \\<sigma> ne - t \\<le> right I \\<longrightarrow>\n        (\\<nexists>i. \\<tau> \\<sigma> i = t))\"\n    using in_auxlist0_2 by (auto)\n\n  have aux'_eq: \"aux' = add_new_table_msaux args rel2 aux0\"\n    using result_eq unfolding aux0_def update_since_def Let_def by simp\n  define auxlist' where\n    auxlist'_eq: \"auxlist' = (case auxlist0 of\n      [] \\<Rightarrow> [(\\<tau> \\<sigma> ne, rel2)]\n    | x # auxlist' \\<Rightarrow> (if fst x = \\<tau> \\<sigma> ne then (fst x, snd x \\<union> rel2) # auxlist' else (\\<tau> \\<sigma> ne, rel2) # x # auxlist'))\"\n  have tabR: \"table (args_n args) (args_R args) rel2\"\n    using qtable2[unfolded qtable_def] unfolding args_n[symmetric] args_R[symmetric] by simp\n  have valid': \"valid_msaux args (\\<tau> \\<sigma> ne) aux' auxlist'\"\n    unfolding aux'_eq auxlist'_eq using valid_add_new_table_msaux[OF valid0 tabR]\n    by (auto simp: not_le split: list.splits option.splits if_splits)\n  have sorted_auxlist': \"sorted_wrt (\\<lambda>x y. fst x > fst y) auxlist'\"\n    unfolding auxlist'_eq\n    using sorted_auxlist0 in_auxlist0_le_\\<tau> by (cases auxlist0) fastforce+\n  have in_auxlist'_1: \"t \\<le> \\<tau> \\<sigma> ne \\<and> \\<tau> \\<sigma> ne - t \\<le> right I \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne (Sincep pos \\<phi> (point (\\<tau> \\<sigma> ne - t)) \\<psi>)) X\"\n    if auxlist': \"(t, X) \\<in> set auxlist'\" for t X\n  proof (cases auxlist0)\n    case Nil\n    with auxlist' show ?thesis\n      unfolding auxlist'_eq using qtable2 auxlist0_Nil\n      by (auto simp: zero_enat_def[symmetric] sat_Since_rec[where i=ne]\n          dest: spec[of _ \"\\<tau> \\<sigma> (ne-1)\"] elim!: qtable_cong[OF _ refl])\n  next\n    case (Cons a as)\n    show ?thesis\n    proof (cases \"t = \\<tau> \\<sigma> ne\")\n      case t: True\n      show ?thesis\n      proof (cases \"fst a = \\<tau> \\<sigma> ne\")\n        case True\n        with auxlist' Cons t have \"X = snd a \\<union> rel2\"\n          unfolding auxlist'_eq using sorted_auxlist0 by (auto split: if_splits)\n        moreover from in_auxlist0_1[of \"fst a\" \"snd a\"] Cons have \"ne \\<noteq> 0\"\n          \"fst a \\<le> \\<tau> \\<sigma> (ne - 1)\" \"\\<tau> \\<sigma> ne - fst a \\<le> right I\" \"\\<exists>i. \\<tau> \\<sigma> i = fst a\"\n          \"qtable n (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne - 1)\n            (Sincep pos \\<phi> (point (\\<tau> \\<sigma> (ne - 1) - fst a)) \\<psi>) \\<and> (if pos then Formula.sat \\<sigma> V (map the v) ne \\<phi>\n              else \\<not> Formula.sat \\<sigma> V (map the v) ne \\<phi>)) (snd a)\"\n          by (auto simp: True[symmetric] zero_enat_def[symmetric])\n        ultimately show ?thesis using qtable2 t True\n          by (auto simp: sat_Since_rec[where i=ne] sat.simps(6) elim!: qtable_union)\n      next\n        case False\n        with auxlist' Cons t have \"X = rel2\"\n          unfolding auxlist'_eq using sorted_auxlist0 in_auxlist0_le_\\<tau>[of \"fst a\" \"snd a\"] by (auto split: if_splits)\n        with auxlist' Cons t False show ?thesis\n          unfolding auxlist'_eq using qtable2 in_auxlist0_2[of \"\\<tau> \\<sigma> (ne-1)\"] in_auxlist0_le_\\<tau>[of \"fst a\" \"snd a\"] sorted_auxlist0\n          by (auto simp: sat_Since_rec[where i=ne] sat.simps(3) zero_enat_def[symmetric] enat_0_iff not_le\n              elim!: qtable_cong[OF _ refl] dest!: le_\\<tau>_less meta_mp)\n      qed\n    next\n      case False\n      with auxlist' Cons have \"(t, X) \\<in> set auxlist0\"\n        unfolding auxlist'_eq by (auto split: if_splits)\n      then have \"ne \\<noteq> 0\" \"t \\<le> \\<tau> \\<sigma> (ne - 1)\" \"\\<tau> \\<sigma> ne - t \\<le> right I\" \"\\<exists>i. \\<tau> \\<sigma> i = t\"\n        \"qtable n (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne - 1) (Sincep pos \\<phi> (point (\\<tau> \\<sigma> (ne - 1) - t)) \\<psi>) \\<and>\n           (if pos then Formula.sat \\<sigma> V (map the v) ne \\<phi> else \\<not> Formula.sat \\<sigma> V (map the v) ne \\<phi>)) X\"\n        using in_auxlist0_1 by blast+\n      with False auxlist' Cons show ?thesis\n        unfolding auxlist'_eq using qtable2\n        by (fastforce simp: sat_Since_rec[where i=ne] sat.simps(6)\n            diff_diff_right[where i=\"\\<tau> \\<sigma> ne\" and j=\"\\<tau> \\<sigma> _ + \\<tau> \\<sigma> ne\" and k=\"\\<tau> \\<sigma> (ne - 1)\",\n              OF trans_le_add2, simplified] elim!: qtable_cong[OF _ refl] order_trans dest: le_\\<tau>_less)\n    qed\n  qed\n\n  have in_auxlist'_2: \"\\<exists>X. (t, X) \\<in> set auxlist'\" if \"t \\<le> \\<tau> \\<sigma> ne\" \"\\<tau> \\<sigma> ne - t \\<le> right I\" \"\\<exists>i. \\<tau> \\<sigma> i = t\" for t\n  proof (cases \"t = \\<tau> \\<sigma> ne\")\n    case True\n    then show ?thesis\n    proof (cases auxlist0)\n      case Nil\n      with True show ?thesis unfolding auxlist'_eq by (simp add: zero_enat_def[symmetric])\n    next\n      case (Cons a as)\n      with True show ?thesis unfolding auxlist'_eq\n        by (cases \"fst a = \\<tau> \\<sigma> ne\") (auto simp: zero_enat_def[symmetric])\n    qed\n  next\n    case False\n    with that have \"ne \\<noteq> 0\"\n      using le_\\<tau>_less neq0_conv by blast\n    moreover from False that have  \"t \\<le> \\<tau> \\<sigma> (ne-1)\"\n      by (metis One_nat_def Suc_leI Suc_pred \\<tau>_mono diff_is_0_eq' order.antisym neq0_conv not_le)\n    ultimately obtain X where \"(t, X) \\<in> set auxlist0\" using \\<open>\\<tau> \\<sigma> ne - t \\<le> right I\\<close> \\<open>\\<exists>i. \\<tau> \\<sigma> i = t\\<close>\n      using \\<tau>_mono[of \"ne - 1\" \"ne\" \\<sigma>] by (atomize_elim, cases \"right I\") (auto intro!: in_auxlist0_2 simp del: \\<tau>_mono)\n    then show ?thesis unfolding auxlist'_eq using False \\<open>\\<tau> \\<sigma> ne - t \\<le> right I\\<close>\n      by (auto intro: exI[of _ X] split: list.split)\n  qed\n\n  show \"wf_since_aux \\<sigma> V R args \\<phi> \\<psi> aux' (Suc ne)\"\n    unfolding wf_since_aux_def args_ivl args_n args_pos\n    by (auto simp add: fv_sub dest: in_auxlist'_1 intro: sorted_auxlist' in_auxlist'_2\n        intro!: exI[of _ auxlist'] valid')\n\n  have \"rel = result_msaux args aux'\"\n    using result_eq by (auto simp add: update_since_def Let_def)\n  with valid' have rel_eq: \"rel = foldr (\\<union>) [rel. (t, rel) \\<leftarrow> auxlist', left I \\<le> \\<tau> \\<sigma> ne - t] {}\"\n    by (auto simp add: args_ivl valid_result_msaux\n        intro!: arg_cong[where f = \"\\<lambda>x. foldr (\\<union>) (concat x) {}\"] split: option.splits)\n  have rel_alt: \"rel = (\\<Union>(t, rel) \\<in> set auxlist'. if left I \\<le> \\<tau> \\<sigma> ne - t then rel else empty_table)\"\n    unfolding rel_eq\n    by (auto elim!: in_foldr_UnE bexI[rotated] intro!: in_foldr_UnI)\n  show \"qtable n (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne (Sincep pos \\<phi> I \\<psi>)) rel\"\n    unfolding rel_alt\n  proof (rule qtable_Union[where Qi=\"\\<lambda>(t, X) v.\n    left I \\<le> \\<tau> \\<sigma> ne - t \\<and> Formula.sat \\<sigma> V (map the v) ne (Sincep pos \\<phi> (point (\\<tau> \\<sigma> ne - t)) \\<psi>)\"],\n        goal_cases finite qtable equiv)\n    case (equiv v)\n    show ?case\n    proof (rule iffI, erule sat_Since_point, goal_cases left right)\n      case (left j)\n      then show ?case using in_auxlist'_2[of \"\\<tau> \\<sigma> j\", OF _ _ exI, OF _ _ refl] by auto\n    next\n      case right\n      then show ?case by (auto elim!: sat_Since_pointD dest: in_auxlist'_1)\n    qed\n  qed (auto dest!: in_auxlist'_1 intro!: qtable_empty)\nqed\n\nlemma fv_regex_from_mregex:\n  \"ok (length \\<phi>s) mr \\<Longrightarrow> fv_regex (from_mregex mr \\<phi>s) \\<subseteq> (\\<Union>\\<phi> \\<in> set \\<phi>s. fv \\<phi>)\"\n  by (induct mr) (auto simp: Bex_def in_set_conv_nth)+\n\nlemma qtable_\\<epsilon>_lax:\n  assumes \"ok (length \\<phi>s) mr\"\n    and \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>) rel) \\<phi>s rels\"\n    and \"fv_regex (from_mregex mr \\<phi>s) \\<subseteq> A\" and \"qtable n A (mem_restr R) Q guard\"\n  shows \"qtable n A (mem_restr R)\n   (\\<lambda>v. Regex.eps (Formula.sat \\<sigma> V (map the v)) i (from_mregex mr \\<phi>s) \\<and> Q v) (\\<epsilon>_lax guard rels mr)\"\n  using assms\nproof (induct mr)\n  case (MPlus mr1 mr2)\n  from MPlus(3-6) show ?case\n    by (auto intro!: qtable_union[OF MPlus(1,2)])\nnext\n  case (MTimes mr1 mr2)\n  then have \"fv_regex (from_mregex mr1 \\<phi>s) \\<subseteq> A\" \"fv_regex (from_mregex mr2 \\<phi>s) \\<subseteq> A\"\n    using fv_regex_from_mregex[of \\<phi>s mr1] fv_regex_from_mregex[of \\<phi>s mr2] by (auto simp: subset_eq)\n  with MTimes(3-6) show ?case\n    by (auto simp: eps_the_restrict restrict_idle intro!: qtable_join[OF MTimes(1,2)])\nqed (auto split: prod.splits if_splits simp: qtable_empty_iff list_all2_conv_all_nth\n    in_set_conv_nth restrict_idle sat_the_restrict\n    intro: in_qtableI qtableI elim!: qtable_join[where A=A and C=A])\n\nlemma nullary_qtable_cases: \"qtable n {} P Q X \\<Longrightarrow> (X = empty_table \\<or> X = unit_table n)\"\n  by (simp add: qtable_def table_empty)\n\nlemma qtable_empty_unit_table:\n  \"qtable n {} R P empty_table \\<Longrightarrow> qtable n {} R (\\<lambda>v. \\<not> P v) (unit_table n)\"\n  by (auto intro: qtable_unit_table simp add: qtable_empty_iff)\n\nlemma qtable_unit_empty_table:\n  \"qtable n {} R P (unit_table n) \\<Longrightarrow> qtable n {} R (\\<lambda>v. \\<not> P v) empty_table\"\n  by (auto intro!: qtable_empty elim: in_qtableE simp add: wf_tuple_empty unit_table_def)\n\nlemma qtable_nonempty_empty_table:\n  \"qtable n {} R P X \\<Longrightarrow> x \\<in> X \\<Longrightarrow> qtable n {} R (\\<lambda>v. \\<not> P v) empty_table\"\n  by (frule nullary_qtable_cases) (auto dest: qtable_unit_empty_table)\n\n\nlemma qtable_r\\<epsilon>_strict:\n  assumes \"safe_regex Past Strict (from_mregex mr \\<phi>s)\" \"ok (length \\<phi>s) mr\" \"A = fv_regex (from_mregex mr \\<phi>s)\"\n    and \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>) rel) \\<phi>s rels\"\n  shows \"qtable n A (mem_restr R) (\\<lambda>v. Regex.eps (Formula.sat \\<sigma> V (map the v)) i (from_mregex mr \\<phi>s)) (r\\<epsilon>_strict n rels mr)\"\n  using assms\nproof (hypsubst, induct Past Strict \"from_mregex mr \\<phi>s\" arbitrary: mr rule: safe_regex_induct)\n  case (Skip n)\n  then show ?case\n    by (cases mr) (auto simp: qtable_empty_iff qtable_unit_table split: if_splits)\nnext\n  case (Test \\<phi>)\n  then show ?case\n    by (cases mr) (auto simp: list_all2_conv_all_nth qtable_empty_unit_table\n        dest!: qtable_nonempty_empty_table split: if_splits)\nnext\n  case (Plus r s)\n  then show ?case\n    by (cases mr) (fastforce intro: qtable_union split: if_splits)+\nnext\n  case (TimesP r s)\n  then show ?case\n    by (cases mr) (auto intro: qtable_cong[OF qtable_\\<epsilon>_lax] split: if_splits)+\nnext\n  case (Star r)\n  then show ?case\n    by (cases mr) (auto simp: qtable_unit_table split: if_splits)\nqed\n\nlemma qtable_l\\<epsilon>_strict:\n  assumes \"safe_regex Futu Strict (from_mregex mr \\<phi>s)\" \"ok (length \\<phi>s) mr\" \"A = fv_regex (from_mregex mr \\<phi>s)\"\n    and \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>) rel) \\<phi>s rels\"\n  shows \"qtable n A (mem_restr R) (\\<lambda>v. Regex.eps (Formula.sat \\<sigma> V (map the v)) i (from_mregex mr \\<phi>s)) (l\\<epsilon>_strict n rels mr)\"\n  using assms\nproof (hypsubst, induct Futu Strict \"from_mregex mr \\<phi>s\" arbitrary: mr rule: safe_regex_induct)\n  case (Skip n)\n  then show ?case\n    by (cases mr) (auto simp: qtable_empty_iff qtable_unit_table split: if_splits)\nnext\n  case (Test \\<phi>)\n  then show ?case\n    by (cases mr) (auto simp: list_all2_conv_all_nth qtable_empty_unit_table\n        dest!: qtable_nonempty_empty_table split: if_splits)\nnext\n  case (Plus r s)\n  then show ?case\n    by (cases mr) (fastforce intro: qtable_union split: if_splits)+\nnext\n  case (TimesF r s)\n  then show ?case\n    by (cases mr) (auto intro: qtable_cong[OF qtable_\\<epsilon>_lax] split: if_splits)+\nnext\n  case (Star r)\n  then show ?case\n    by (cases mr) (auto simp: qtable_unit_table split: if_splits)\nqed\n\nlemma rtranclp_False: \"(\\<lambda>i j. False)\\<^sup>*\\<^sup>* = (=)\"\nproof -\n  have \"(\\<lambda>i j. False)\\<^sup>*\\<^sup>* i j \\<Longrightarrow> i = j\" for i j :: 'a\n    by (induct i j rule: rtranclp.induct) auto\n  then show ?thesis\n    by (auto intro: exI[of _ 0])\nqed\n\ninductive ok_rctxt for \\<phi>s where\n  \"ok_rctxt \\<phi>s id id\"\n| \"ok_rctxt \\<phi>s \\<kappa> \\<kappa>' \\<Longrightarrow> ok_rctxt \\<phi>s (\\<lambda>t. \\<kappa> (MTimes mr t)) (\\<lambda>t. \\<kappa>' (Regex.Times (from_mregex mr \\<phi>s) t))\"\n\nlemma ok_rctxt_swap: \"ok_rctxt \\<phi>s \\<kappa> \\<kappa>' \\<Longrightarrow> from_mregex (\\<kappa> mr) \\<phi>s = \\<kappa>' (from_mregex mr \\<phi>s)\"\n  by (induct \\<kappa> \\<kappa>' arbitrary: mr rule: ok_rctxt.induct) auto\n\nlemma ok_rctxt_cong: \"ok_rctxt \\<phi>s \\<kappa> \\<kappa>' \\<Longrightarrow> Regex.match (Formula.sat \\<sigma> V v) r = Regex.match (Formula.sat \\<sigma> V v) s \\<Longrightarrow>\n  Regex.match (Formula.sat \\<sigma> V v) (\\<kappa>' r) i j = Regex.match (Formula.sat \\<sigma> V v) (\\<kappa>' s) i j\"\n  by (induct \\<kappa> \\<kappa>' arbitrary: r s rule: ok_rctxt.induct) simp_all\n\nlemma qtable_r\\<delta>\\<kappa>:\n  assumes \"ok (length \\<phi>s) mr\" \"fv_regex (from_mregex mr \\<phi>s) \\<subseteq> A\"\n    and \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) j \\<phi>) rel) \\<phi>s rels\"\n    and \"ok_rctxt \\<phi>s \\<kappa> \\<kappa>'\"\n    and \"\\<forall>ms \\<in> \\<kappa> ` RPD mr. qtable n A (mem_restr R) (\\<lambda>v. Q (map the v) (from_mregex ms \\<phi>s)) (lookup rel ms)\"\n  shows \"qtable n A (mem_restr R)\n  (\\<lambda>v. \\<exists>s \\<in> Regex.rpd\\<kappa> \\<kappa>' (Formula.sat \\<sigma> V (map the v)) j (from_mregex mr \\<phi>s). Q (map the v) s)\n  (r\\<delta> \\<kappa> rel rels mr)\"\n  using assms\nproof (induct mr arbitrary: \\<kappa> \\<kappa>')\n  case MSkip\n  then show ?case\n    by (auto simp: rtranclp_False ok_rctxt_swap qtable_empty_iff\n        elim!: qtable_cong[OF _ _ ok_rctxt_cong[of _ \\<kappa> \\<kappa>']] split: nat.splits)\nnext\n  case (MPlus mr1 mr2)\n  from MPlus(3-7) show ?case\n    by (auto intro!: qtable_union[OF MPlus(1,2)])\nnext\n  case (MTimes mr1 mr2)\n  from MTimes(3-7) show ?case\n    by (auto intro!: qtable_union[OF MTimes(2) qtable_\\<epsilon>_lax[OF _ _ _ MTimes(1)]]\n        elim!: ok_rctxt.intros(2) simp: MTimesL_def Ball_def)\nnext\n  case (MStar mr)\n  from MStar(2-6) show ?case\n    by (auto intro!: qtable_cong[OF MStar(1)] intro: ok_rctxt.intros simp: MTimesL_def Ball_def)\nqed (auto simp: qtable_empty_iff)\n\nlemmas qtable_r\\<delta> = qtable_r\\<delta>\\<kappa>[OF _ _ _ ok_rctxt.intros(1), unfolded rpd\\<kappa>_rpd image_id id_apply]\n\ninductive ok_lctxt for \\<phi>s where\n  \"ok_lctxt \\<phi>s id id\"\n| \"ok_lctxt \\<phi>s \\<kappa> \\<kappa>' \\<Longrightarrow> ok_lctxt \\<phi>s (\\<lambda>t. \\<kappa> (MTimes t mr)) (\\<lambda>t. \\<kappa>' (Regex.Times t (from_mregex mr \\<phi>s)))\"\n\nlemma ok_lctxt_swap: \"ok_lctxt \\<phi>s \\<kappa> \\<kappa>' \\<Longrightarrow> from_mregex (\\<kappa> mr) \\<phi>s = \\<kappa>' (from_mregex mr \\<phi>s)\"\n  by (induct \\<kappa> \\<kappa>' arbitrary: mr rule: ok_lctxt.induct) auto\n\nlemma ok_lctxt_cong: \"ok_lctxt \\<phi>s \\<kappa> \\<kappa>' \\<Longrightarrow> Regex.match (Formula.sat \\<sigma> V v) r = Regex.match (Formula.sat \\<sigma> V v) s \\<Longrightarrow>\n  Regex.match (Formula.sat \\<sigma> V v) (\\<kappa>' r) i j = Regex.match (Formula.sat \\<sigma> V v) (\\<kappa>' s) i j\"\n  by (induct \\<kappa> \\<kappa>' arbitrary: r s rule: ok_lctxt.induct) simp_all\n\nlemma qtable_l\\<delta>\\<kappa>:\n  assumes \"ok (length \\<phi>s) mr\" \"fv_regex (from_mregex mr \\<phi>s) \\<subseteq> A\"\n    and \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) j \\<phi>) rel) \\<phi>s rels\"\n    and \"ok_lctxt \\<phi>s \\<kappa> \\<kappa>'\"\n    and \"\\<forall>ms \\<in> \\<kappa> ` LPD mr. qtable n A (mem_restr R) (\\<lambda>v. Q (map the v) (from_mregex ms \\<phi>s)) (lookup rel ms)\"\n  shows \"qtable n A (mem_restr R)\n  (\\<lambda>v. \\<exists>s \\<in> Regex.lpd\\<kappa> \\<kappa>' (Formula.sat \\<sigma> V (map the v)) j (from_mregex mr \\<phi>s). Q (map the v) s)\n  (l\\<delta> \\<kappa> rel rels mr)\"\n  using assms\nproof (induct mr arbitrary: \\<kappa> \\<kappa>')\n  case MSkip\n  then show ?case\n    by (auto simp: rtranclp_False ok_lctxt_swap qtable_empty_iff\n        elim!: qtable_cong[OF _ _ ok_rctxt_cong[of _ \\<kappa> \\<kappa>']] split: nat.splits)\nnext\n  case (MPlus mr1 mr2)\n  from MPlus(3-7) show ?case\n    by (auto intro!: qtable_union[OF MPlus(1,2)])\nnext\n  case (MTimes mr1 mr2)\n  from MTimes(3-7) show ?case\n    by (auto intro!: qtable_union[OF MTimes(1) qtable_\\<epsilon>_lax[OF _ _ _ MTimes(2)]]\n        elim!: ok_lctxt.intros(2) simp: MTimesR_def Ball_def)\nnext\n  case (MStar mr)\n  from MStar(2-6) show ?case\n    by (auto intro!: qtable_cong[OF MStar(1)] intro: ok_lctxt.intros simp: MTimesR_def Ball_def)\nqed (auto simp: qtable_empty_iff)\n\nlemmas qtable_l\\<delta> = qtable_l\\<delta>\\<kappa>[OF _ _ _ ok_lctxt.intros(1), unfolded lpd\\<kappa>_lpd image_id id_apply]\n\nlemma RPD_fv_regex_le:\n  \"ms \\<in> RPD mr \\<Longrightarrow> fv_regex (from_mregex ms \\<phi>s) \\<subseteq> fv_regex (from_mregex mr \\<phi>s)\"\n  by (induct mr arbitrary: ms) (auto simp: MTimesL_def split: nat.splits)+\n\nlemma RPD_safe: \"safe_regex Past g (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> RPD mr \\<Longrightarrow> safe_regex Past g (from_mregex ms \\<phi>s)\"\nproof (induct Past g \"from_mregex mr \\<phi>s\" arbitrary: mr ms rule: safe_regex_induct)\n  case Skip\n  then show ?case\n    by (cases mr) (auto split: nat.splits)\nnext\n  case (Test g \\<phi>)\n  then show ?case\n    by (cases mr) auto\nnext\n  case (Plus g r s mrs)\n  then show ?case\n  proof (cases mrs)\n    case (MPlus mr ms)\n    with Plus(3-5) show ?thesis\n      by (auto dest!: Plus(1,2))\n  qed auto\nnext\n  case (TimesP g r s mrs)\n  then show ?case\n  proof (cases mrs)\n    case (MTimes mr ms)\n    with TimesP(3-5) show ?thesis\n      by (cases g) (auto 0 4 simp: MTimesL_def dest: RPD_fv_regex_le TimesP(1,2))\n  qed auto\nnext\n  case (Star g r)\n  then show ?case\n  proof (cases mr)\n    case (MStar x6)\n    with Star(2-4) show ?thesis\n      by (cases g) (auto 0 4 simp: MTimesL_def dest: RPD_fv_regex_le\n          elim!: safe_cosafe[rotated] dest!: Star(1))\n  qed auto\nqed\n\nlemma RPDi_safe: \"safe_regex Past g (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> RPDi n mr ==> safe_regex Past g (from_mregex ms \\<phi>s)\"\n  by (induct n arbitrary: ms mr) (auto dest: RPD_safe)\n\nlemma RPDs_safe: \"safe_regex Past g (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> RPDs mr ==> safe_regex Past g (from_mregex ms \\<phi>s)\"\n  unfolding RPDs_def by (auto dest: RPDi_safe)\n\nlemma RPD_safe_fv_regex: \"safe_regex Past Strict (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> RPD mr \\<Longrightarrow> fv_regex (from_mregex ms \\<phi>s) = fv_regex (from_mregex mr \\<phi>s)\"\nproof (induct Past Strict \"from_mregex mr \\<phi>s\" arbitrary: mr rule: safe_regex_induct)\n  case (Skip n)\n  then show ?case\n    by (cases mr) (auto split: nat.splits)\nnext\n  case (Test \\<phi>)\n  then show ?case\n    by (cases mr) auto\nnext\n  case (Plus r s)\n  then show ?case\n    by (cases mr) auto\nnext\n  case (TimesP r s)\n  then show ?case\n    by (cases mr) (auto 0 3 simp: MTimesL_def dest: RPD_fv_regex_le split: modality.splits)\nnext\n  case (Star r)\n  then show ?case\n    by (cases mr) (auto 0 3 simp: MTimesL_def dest: RPD_fv_regex_le)\nqed\n\nlemma RPDi_safe_fv_regex: \"safe_regex Past Strict (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> RPDi n mr ==> fv_regex (from_mregex ms \\<phi>s) = fv_regex (from_mregex mr \\<phi>s)\"\n  by (induct n arbitrary: ms mr) (auto 5 0 dest: RPD_safe_fv_regex RPD_safe)\n\nlemma RPDs_safe_fv_regex: \"safe_regex Past Strict (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> RPDs mr ==> fv_regex (from_mregex ms \\<phi>s) = fv_regex (from_mregex mr \\<phi>s)\"\n  unfolding RPDs_def by (auto dest: RPDi_safe_fv_regex)\n\nlemma RPD_ok: \"ok m mr \\<Longrightarrow> ms \\<in> RPD mr \\<Longrightarrow> ok m ms\"\nproof (induct mr arbitrary: ms)\n  case (MPlus mr1 mr2)\n  from MPlus(3,4) show ?case\n    by (auto elim: MPlus(1,2))\nnext\n  case (MTimes mr1 mr2)\n  from MTimes(3,4) show ?case\n    by (auto elim: MTimes(1,2) simp: MTimesL_def)\nnext\n  case (MStar mr)\n  from MStar(2,3) show ?case\n    by (auto elim: MStar(1) simp: MTimesL_def)\nqed (auto split: nat.splits)\n\nlemma RPDi_ok: \"ok m mr \\<Longrightarrow> ms \\<in> RPDi n mr \\<Longrightarrow> ok m ms\"\n  by (induct n arbitrary: ms mr) (auto intro: RPD_ok)\n\nlemma RPDs_ok: \"ok m mr \\<Longrightarrow> ms \\<in> RPDs mr \\<Longrightarrow> ok m ms\"\n  unfolding RPDs_def by (auto intro: RPDi_ok)\n\nlemma LPD_fv_regex_le:\n  \"ms \\<in> LPD mr \\<Longrightarrow> fv_regex (from_mregex ms \\<phi>s) \\<subseteq> fv_regex (from_mregex mr \\<phi>s)\"\n  by (induct mr arbitrary: ms) (auto simp: MTimesR_def split: nat.splits)+\n\nlemma LPD_safe: \"safe_regex Futu g (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> LPD mr ==> safe_regex Futu g (from_mregex ms \\<phi>s)\"\nproof (induct Futu g \"from_mregex mr \\<phi>s\" arbitrary: mr ms rule: safe_regex_induct)\n  case Skip\n  then show ?case\n    by (cases mr) (auto split: nat.splits)\nnext\n  case (Test g \\<phi>)\n  then show ?case\n    by (cases mr) auto\nnext\n  case (Plus g r s mrs)\n  then show ?case\n  proof (cases mrs)\n    case (MPlus mr ms)\n    with Plus(3-5) show ?thesis\n      by (auto dest!: Plus(1,2))\n  qed auto\nnext\n  case (TimesF g r s mrs)\n  then show ?case\n  proof (cases mrs)\n    case (MTimes mr ms)\n    with TimesF(3-5) show ?thesis\n      by (cases g) (auto 0 4 simp: MTimesR_def dest: LPD_fv_regex_le split: modality.splits dest: TimesF(1,2))\n  qed auto\nnext\n  case (Star g r)\n  then show ?case\n  proof (cases mr)\n    case (MStar x6)\n    with Star(2-4) show ?thesis\n      by (cases g) (auto 0 4 simp: MTimesR_def dest: LPD_fv_regex_le\n          elim!: safe_cosafe[rotated] dest!: Star(1))\n  qed auto\nqed\n\nlemma LPDi_safe: \"safe_regex Futu g (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> LPDi n mr ==> safe_regex Futu g (from_mregex ms \\<phi>s)\"\n  by (induct n arbitrary: ms mr) (auto dest: LPD_safe)\n\nlemma LPDs_safe: \"safe_regex Futu g (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> LPDs mr ==> safe_regex Futu g (from_mregex ms \\<phi>s)\"\n  unfolding LPDs_def by (auto dest: LPDi_safe)\n\nlemma LPD_safe_fv_regex: \"safe_regex Futu Strict (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> LPD mr ==> fv_regex (from_mregex ms \\<phi>s) = fv_regex (from_mregex mr \\<phi>s)\"\nproof (induct Futu Strict \"from_mregex mr \\<phi>s\" arbitrary: mr rule: safe_regex_induct)\n  case Skip\n  then show ?case\n    by (cases mr) (auto split: nat.splits)\nnext\n  case (Test \\<phi>)\n  then show ?case\n    by (cases mr) auto\nnext\n  case (Plus r s)\n  then show ?case\n    by (cases mr) auto\nnext\n  case (TimesF r s)\n  then show ?case\n    by (cases mr) (auto 0 3 simp: MTimesR_def dest: LPD_fv_regex_le split: modality.splits)\nnext\n  case (Star r)\n  then show ?case\n    by (cases mr) (auto 0 3 simp: MTimesR_def dest: LPD_fv_regex_le)\nqed\n\nlemma LPDi_safe_fv_regex: \"safe_regex Futu Strict (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> LPDi n mr ==> fv_regex (from_mregex ms \\<phi>s) = fv_regex (from_mregex mr \\<phi>s)\"\n  by (induct n arbitrary: ms mr) (auto 5 0 dest: LPD_safe_fv_regex LPD_safe)\n\nlemma LPDs_safe_fv_regex: \"safe_regex Futu Strict (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> LPDs mr ==> fv_regex (from_mregex ms \\<phi>s) = fv_regex (from_mregex mr \\<phi>s)\"\n  unfolding LPDs_def by (auto dest: LPDi_safe_fv_regex)\n\nlemma LPD_ok: \"ok m mr \\<Longrightarrow> ms \\<in> LPD mr \\<Longrightarrow> ok m ms\"\nproof (induct mr arbitrary: ms)\n  case (MPlus mr1 mr2)\n  from MPlus(3,4) show ?case\n    by (auto elim: MPlus(1,2))\nnext\n  case (MTimes mr1 mr2)\n  from MTimes(3,4) show ?case\n    by (auto elim: MTimes(1,2) simp: MTimesR_def)\nnext\n  case (MStar mr)\n  from MStar(2,3) show ?case\n    by (auto elim: MStar(1) simp: MTimesR_def)\nqed (auto split: nat.splits)\n\nlemma LPDi_ok: \"ok m mr \\<Longrightarrow> ms \\<in> LPDi n mr \\<Longrightarrow> ok m ms\"\n  by (induct n arbitrary: ms mr) (auto intro: LPD_ok)\n\nlemma LPDs_ok: \"ok m mr \\<Longrightarrow> ms \\<in> LPDs mr \\<Longrightarrow> ok m ms\"\n  unfolding LPDs_def by (auto intro: LPDi_ok)\n\nlemma update_matchP:\n  assumes pre: \"wf_matchP_aux \\<sigma> V n R I r aux ne\"\n    and safe: \"safe_regex Past Strict r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (RPDs mr)\"\n    and qtables: \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne \\<phi>) rel) \\<phi>s rels\"\n    and result_eq: \"(rel, aux') = update_matchP n I mr mrs rels (\\<tau> \\<sigma> ne) aux\"\n  shows \"wf_matchP_aux \\<sigma> V n R I r aux' (Suc ne)\"\n    and \"qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne (Formula.MatchP I r)) rel\"\nproof -\n  let ?wf_tuple = \"\\<lambda>v. wf_tuple n (Formula.fv_regex r) v\"\n  let ?update = \"\\<lambda>rel t. mrtabulate mrs (\\<lambda>mr.\n    r\\<delta> id rel rels mr \\<union> (if t = \\<tau> \\<sigma> ne then r\\<epsilon>_strict n rels mr else {}))\"\n  note sat.simps[simp del]\n\n  define aux0 where \"aux0 = [(t, ?update rel t). (t, rel) \\<leftarrow> aux, enat (\\<tau> \\<sigma> ne - t) \\<le> right I]\"\n  have sorted_aux0: \"sorted_wrt (\\<lambda>x y. fst x > fst y) aux0\"\n    using pre[unfolded wf_matchP_aux_def, THEN conjunct1]\n    unfolding aux0_def\n    by (induction aux) (auto simp add: sorted_wrt_append)\n  { fix ms\n    assume \"ms \\<in> RPDs mr\"\n    then have \"fv_regex (from_mregex ms \\<phi>s) = fv_regex r\"\n      \"safe_regex Past Strict (from_mregex ms \\<phi>s)\" \"ok (length \\<phi>s) ms\" \"RPD ms \\<subseteq> RPDs mr\"\n      using safe RPDs_safe RPDs_safe_fv_regex mr from_mregex_to_mregex RPDs_ok to_mregex_ok RPDs_trans\n      by fastforce+\n  } note * = this\n  have **: \"\\<tau> \\<sigma> ne - (\\<tau> \\<sigma> i + \\<tau> \\<sigma> ne - \\<tau> \\<sigma> (ne - Suc 0)) = \\<tau> \\<sigma> (ne - Suc 0) - \\<tau> \\<sigma> i\" for i\n    by (metis (no_types, lifting) Nat.diff_diff_right \\<tau>_mono add.commute add_diff_cancel_left diff_le_self le_add2 order_trans)\n  have ***: \"\\<tau> \\<sigma> i = \\<tau> \\<sigma> ne\"\n    if  \"\\<tau> \\<sigma> ne \\<le> \\<tau> \\<sigma> i\" \"\\<tau> \\<sigma> i \\<le> \\<tau> \\<sigma> (ne - Suc 0)\" \"ne > 0\" for i\n    by (metis (no_types, lifting) Suc_pred \\<tau>_mono diff_le_self le_\\<tau>_less le_antisym not_less_eq that)\n  then have in_aux0_1: \"(t, X) \\<in> set aux0 \\<Longrightarrow> ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> ne \\<and> \\<tau> \\<sigma> ne - t \\<le> right I \\<and>\n      (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      (\\<forall>ms\\<in>RPDs mr. qtable n (fv_regex r) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne\n         (Formula.MatchP (point (\\<tau> \\<sigma> ne - t)) (from_mregex ms \\<phi>s))) (lookup X ms))\" for t X\n    unfolding aux0_def using safe mr mrs\n    by (auto simp: lookup_tabulate map_of_map_restrict restrict_map_def finite_RPDs * ** RPDs_trans diff_le_mono2\n        intro!: sat_MatchP_rec[of \\<sigma> _ _ ne, THEN iffD2]\n        qtable_union[OF qtable_r\\<delta>[OF _ _ qtables] qtable_r\\<epsilon>_strict[OF _ _ _ qtables],\n          of ms \"fv_regex r\" \"\\<lambda>v r. Formula.sat \\<sigma> V v (ne - Suc 0) (Formula.MatchP (point 0) r)\" _ ms for ms]\n        qtable_cong[OF qtable_r\\<delta>[OF _ _ qtables],\n          of ms \"fv_regex r\" \"\\<lambda>v r. Formula.sat \\<sigma> V v (ne - Suc 0) (Formula.MatchP (point (\\<tau> \\<sigma> (ne - Suc 0) - \\<tau> \\<sigma> i)) r)\"\n          _ _  \"(\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne (Formula.MatchP (point (\\<tau> \\<sigma> ne - \\<tau> \\<sigma> i))  (from_mregex ms \\<phi>s)))\" for ms i]\n        dest!: assms(1)[unfolded wf_matchP_aux_def, THEN conjunct2, THEN conjunct1, rule_format]\n        sat_MatchP_rec[\"of\" \\<sigma> _ _ ne, THEN iffD1]\n        elim!: bspec order.trans[OF _ \\<tau>_mono] bexI[rotated] split: option.splits if_splits) (* slow 7 sec *)\n  then have in_aux0_le_\\<tau>: \"(t, X) \\<in> set aux0 \\<Longrightarrow> t \\<le> \\<tau> \\<sigma> ne\" for t X\n    by (meson \\<tau>_mono diff_le_self le_trans)\n  have in_aux0_2: \"ne \\<noteq> 0 \\<Longrightarrow> t \\<le> \\<tau> \\<sigma> (ne-1) \\<Longrightarrow> \\<tau> \\<sigma> ne - t \\<le> right I \\<Longrightarrow> \\<exists>i. \\<tau> \\<sigma> i = t \\<Longrightarrow>\n    \\<exists>X. (t, X) \\<in> set aux0\" for t\n  proof -\n    fix t\n    assume \"ne \\<noteq> 0\" \"t \\<le> \\<tau> \\<sigma> (ne-1)\" \"\\<tau> \\<sigma> ne - t \\<le> right I\" \"\\<exists>i. \\<tau> \\<sigma> i = t\"\n    then obtain X where \"(t, X) \\<in> set aux\"\n      by (atomize_elim, intro assms(1)[unfolded wf_matchP_aux_def, THEN conjunct2, THEN conjunct2, rule_format])\n        (auto simp: gr0_conv_Suc elim!: order_trans[rotated] intro!: diff_le_mono \\<tau>_mono)\n    with \\<open>\\<tau> \\<sigma> ne - t \\<le> right I\\<close> have \"(t, ?update X t) \\<in> set aux0\"\n      unfolding aux0_def by (auto simp: id_def elim!: bexI[rotated] intro!: exI[of _ X])\n    then show \"\\<exists>X. (t, X) \\<in> set aux0\"\n      by blast\n  qed\n  have aux0_Nil: \"aux0 = [] \\<Longrightarrow> ne = 0 \\<or> ne \\<noteq> 0 \\<and> (\\<forall>t. t \\<le> \\<tau> \\<sigma> (ne-1) \\<and> \\<tau> \\<sigma> ne - t \\<le> right I \\<longrightarrow>\n        (\\<nexists>i. \\<tau> \\<sigma> i = t))\"\n    using in_aux0_2 by (cases \"ne = 0\") (auto)\n\n  have aux'_eq: \"aux' = (case aux0 of\n      [] \\<Rightarrow> [(\\<tau> \\<sigma> ne, mrtabulate mrs (r\\<epsilon>_strict n rels))]\n    | x # aux' \\<Rightarrow> (if fst x = \\<tau> \\<sigma> ne then x # aux'\n       else (\\<tau> \\<sigma> ne, mrtabulate mrs (r\\<epsilon>_strict n rels)) # x # aux'))\"\n    using result_eq unfolding aux0_def update_matchP_def Let_def by simp\n  have sorted_aux': \"sorted_wrt (\\<lambda>x y. fst x > fst y) aux'\"\n    unfolding aux'_eq\n    using sorted_aux0 in_aux0_le_\\<tau> by (cases aux0) (fastforce)+\n\n  have in_aux'_1: \"t \\<le> \\<tau> \\<sigma> ne \\<and> \\<tau> \\<sigma> ne - t \\<le> right I \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n     (\\<forall>ms\\<in>RPDs mr. qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v.\n        Formula.sat \\<sigma> V (map the v) ne (Formula.MatchP (point (\\<tau> \\<sigma> ne - t)) (from_mregex ms \\<phi>s))) (lookup X ms))\"\n    if aux': \"(t, X) \\<in> set aux'\" for t X\n  proof (cases aux0)\n    case Nil\n    with aux' show ?thesis\n      unfolding aux'_eq using safe mrs qtables aux0_Nil *\n      by (auto simp: zero_enat_def[symmetric] sat_MatchP_rec[where i=ne]\n          lookup_tabulate finite_RPDs split: option.splits\n          intro!: qtable_cong[OF qtable_r\\<epsilon>_strict]\n          dest: spec[of _ \"\\<tau> \\<sigma> (ne-1)\"])\n  next\n    case (Cons a as)\n    show ?thesis\n    proof (cases \"t = \\<tau> \\<sigma> ne\")\n      case t: True\n      show ?thesis\n      proof (cases \"fst a = \\<tau> \\<sigma> ne\")\n        case True\n        with aux' Cons t have \"X = snd a\"\n          unfolding aux'_eq using sorted_aux0 by auto\n        moreover from in_aux0_1[of \"fst a\" \"snd a\"] Cons have \"ne \\<noteq> 0\"\n          \"fst a \\<le> \\<tau> \\<sigma> ne\" \"\\<tau> \\<sigma> ne - fst a \\<le> right I\" \"\\<exists>i. \\<tau> \\<sigma> i = fst a\"\n          \"\\<forall>ms \\<in> RPDs mr. qtable n (fv_regex r) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne\n            (Formula.MatchP (point (\\<tau> \\<sigma> ne - fst a)) (from_mregex ms \\<phi>s))) (lookup (snd a) ms)\"\n          by auto\n        ultimately show ?thesis using t True\n          by auto\n      next\n        case False\n        with aux' Cons t have \"X = mrtabulate mrs (r\\<epsilon>_strict n rels)\"\n          unfolding aux'_eq using sorted_aux0 in_aux0_le_\\<tau>[of \"fst a\" \"snd a\"] by auto\n        with aux' Cons t False show ?thesis\n          unfolding aux'_eq using safe mrs qtables * in_aux0_2[of \"\\<tau> \\<sigma> (ne-1)\"] in_aux0_le_\\<tau>[of \"fst a\" \"snd a\"] sorted_aux0\n          by (auto simp: sat_MatchP_rec[where i=ne] zero_enat_def[symmetric] enat_0_iff not_le\n              lookup_tabulate finite_RPDs split: option.splits\n              intro!: qtable_cong[OF qtable_r\\<epsilon>_strict] dest!: le_\\<tau>_less meta_mp)\n      qed\n    next\n      case False\n      with aux' Cons have \"(t, X) \\<in> set aux0\"\n        unfolding aux'_eq by (auto split: if_splits)\n      then have \"ne \\<noteq> 0\" \"t \\<le> \\<tau> \\<sigma> ne\" \"\\<tau> \\<sigma> ne - t \\<le> right I\" \"\\<exists>i. \\<tau> \\<sigma> i = t\"\n        \"\\<forall>ms \\<in> RPDs mr. qtable n (fv_regex r) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne\n          (Formula.MatchP (point (\\<tau> \\<sigma> ne - t)) (from_mregex ms \\<phi>s))) (lookup X ms)\"\n        using in_aux0_1 by blast+\n      with False aux' Cons show ?thesis\n        unfolding aux'_eq by auto\n    qed\n  qed\n\n  have in_aux'_2: \"\\<exists>X. (t, X) \\<in> set aux'\" if \"t \\<le> \\<tau> \\<sigma> ne\" \"\\<tau> \\<sigma> ne - t \\<le> right I\" \"\\<exists>i. \\<tau> \\<sigma> i = t\" for t\n  proof (cases \"t = \\<tau> \\<sigma> ne\")\n    case True\n    then show ?thesis\n    proof (cases aux0)\n      case Nil\n      with True show ?thesis unfolding aux'_eq by simp\n    next\n      case (Cons a as)\n      with True show ?thesis unfolding aux'_eq using eq_fst_iff[of t a]\n        by (cases \"fst a = \\<tau> \\<sigma> ne\") auto\n    qed\n  next\n    case False\n    with that have \"ne \\<noteq> 0\"\n      using le_\\<tau>_less neq0_conv by blast\n    moreover from False that have  \"t \\<le> \\<tau> \\<sigma> (ne-1)\"\n      by (metis One_nat_def Suc_leI Suc_pred \\<tau>_mono diff_is_0_eq' order.antisym neq0_conv not_le)\n    ultimately obtain X where \"(t, X) \\<in> set aux0\" using \\<open>\\<tau> \\<sigma> ne - t \\<le> right I\\<close> \\<open>\\<exists>i. \\<tau> \\<sigma> i = t\\<close>\n      by atomize_elim (auto intro!: in_aux0_2)\n    then show ?thesis unfolding aux'_eq using False\n      by (auto intro: exI[of _ X] split: list.split)\n  qed\n\n  show \"wf_matchP_aux \\<sigma> V n R I r aux' (Suc ne)\"\n    unfolding wf_matchP_aux_def using mr\n    by (auto dest: in_aux'_1 intro: sorted_aux' in_aux'_2)\n\n  have rel_eq: \"rel = foldr (\\<union>) [lookup rel mr. (t, rel) \\<leftarrow> aux', left I \\<le> \\<tau> \\<sigma> ne - t] {}\"\n    unfolding aux'_eq aux0_def\n    using result_eq by (simp add: update_matchP_def Let_def)\n  have rel_alt: \"rel = (\\<Union>(t, rel) \\<in> set aux'. if left I \\<le> \\<tau> \\<sigma> ne - t then lookup rel mr else empty_table)\"\n    unfolding rel_eq\n    by (auto elim!: in_foldr_UnE bexI[rotated] intro!: in_foldr_UnI)\n  show \"qtable n (fv_regex r) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne (Formula.MatchP I r)) rel\"\n    unfolding rel_alt\n  proof (rule qtable_Union[where Qi=\"\\<lambda>(t, X) v.\n    left I \\<le> \\<tau> \\<sigma> ne - t \\<and> Formula.sat \\<sigma> V (map the v) ne (Formula.MatchP (point (\\<tau> \\<sigma> ne - t)) r)\"],\n        goal_cases finite qtable equiv)\n    case (equiv v)\n    show ?case\n    proof (rule iffI, erule sat_MatchP_point, goal_cases left right)\n      case (left j)\n      then show ?case using in_aux'_2[of \"\\<tau> \\<sigma> j\", OF _ _ exI, OF _ _ refl] by auto\n    next\n      case right\n      then show ?case by (auto elim!: sat_MatchP_pointD dest: in_aux'_1)\n    qed\n  qed (auto dest!: in_aux'_1 intro!: qtable_empty dest!: bspec[OF _ RPDs_refl]\n      simp: from_mregex_eq[OF safe mr])\nqed\n\nlemma length_update_until: \"length (update_until args rel1 rel2 nt aux) = Suc (length aux)\"\n  unfolding update_until_def by simp\n\nlemma wf_update_until_auxlist:\n  assumes pre: \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> auxlist ne\"\n    and qtable1: \"qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne + length auxlist) \\<phi>) rel1\"\n    and qtable2: \"qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne + length auxlist) \\<psi>) rel2\"\n    and fvi_subset: \"Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi>\"\n    and args_ivl: \"args_ivl args = I\"\n    and args_n: \"args_n args = n\"\n    and args_pos: \"args_pos args = pos\"\n  shows \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> (update_until args rel1 rel2 (\\<tau> \\<sigma> (ne + length auxlist)) auxlist) ne\"\n  unfolding wf_until_auxlist_def length_update_until\n  unfolding update_until_def list.rel_map add_Suc_right upt.simps eqTrueI[OF le_add1] if_True\nproof (rule list_all2_appendI, unfold list.rel_map, goal_cases old new)\n  case old\n  show ?case\n  proof (rule list.rel_mono_strong[OF assms(1)[unfolded wf_until_auxlist_def]]; safe, goal_cases mono1 mono2)\n    case (mono1 i X Y v)\n    then show ?case\n      by (fastforce simp: args_ivl args_n args_pos sat_the_restrict less_Suc_eq\n          elim!: qtable_join[OF _ qtable1] qtable_union[OF _ qtable1])\n  next\n    case (mono2 i X Y v)\n    then show ?case using fvi_subset\n      by (auto 0 3 simp: args_ivl args_n args_pos sat_the_restrict less_Suc_eq split: if_splits\n          elim!: qtable_union[OF _ qtable_join_fixed[OF qtable2]]\n          elim: qtable_cong[OF _ refl] intro: exI[of _ \"ne + length auxlist\"]) (* slow 8 sec*)\n  qed\nnext\n  case new\n  then show ?case\n    by (auto intro!: qtable_empty qtable1 qtable2[THEN qtable_cong] exI[of _ \"ne + length auxlist\"]\n        simp: args_ivl args_n args_pos less_Suc_eq zero_enat_def[symmetric])\nqed\n\nlemma (in muaux) wf_update_until:\n  assumes pre: \"wf_until_aux \\<sigma> V R args \\<phi> \\<psi> aux ne\"\n    and qtable1: \"qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne + length_muaux args aux) \\<phi>) rel1\"\n    and qtable2: \"qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne + length_muaux args aux) \\<psi>) rel2\"\n    and fvi_subset: \"Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi>\"\n    and args_ivl: \"args_ivl args = I\"\n    and args_n: \"args_n args = n\"\n    and args_L: \"args_L args = Formula.fv \\<phi>\"\n    and args_R: \"args_R args = Formula.fv \\<psi>\"\n    and args_pos: \"args_pos args = pos\"\n  shows \"wf_until_aux \\<sigma> V R args \\<phi> \\<psi> (add_new_muaux args rel1 rel2 (\\<tau> \\<sigma> (ne + length_muaux args aux)) aux) ne \\<and>\n      length_muaux args (add_new_muaux args rel1 rel2 (\\<tau> \\<sigma> (ne + length_muaux args aux)) aux) = Suc (length_muaux args aux)\"\nproof -\n  from pre obtain cur auxlist where valid_aux: \"valid_muaux args cur aux auxlist\" and\n    cur: \"cur = (if ne + length auxlist = 0 then 0 else \\<tau> \\<sigma> (ne + length auxlist - 1))\" and\n    pre_list: \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> auxlist ne\"\n    unfolding wf_until_aux_def args_ivl args_n args_pos by auto\n  have length_aux: \"length_muaux args aux = length auxlist\"\n    using valid_length_muaux[OF valid_aux] .\n  define nt where \"nt \\<equiv> \\<tau> \\<sigma> (ne + length_muaux args aux)\"\n  have nt_mono: \"cur \\<le> nt\"\n    unfolding cur nt_def length_aux by simp\n  define auxlist' where \"auxlist' \\<equiv> update_until args rel1 rel2 (\\<tau> \\<sigma> (ne + length auxlist)) auxlist\"\n  have length_auxlist': \"length auxlist' = Suc (length auxlist)\"\n    unfolding auxlist'_def by (auto simp add: length_update_until)\n  have tab1: \"table (args_n args) (args_L args) rel1\"\n    using qtable1 unfolding args_n[symmetric] args_L[symmetric] by (auto simp add: qtable_def)\n  have tab2: \"table (args_n args) (args_R args) rel2\"\n    using qtable2 unfolding args_n[symmetric] args_R[symmetric] by (auto simp add: qtable_def)\n  have fv_sub: \"fv \\<phi> \\<subseteq> fv \\<psi>\"\n    using pre unfolding wf_until_aux_def by auto\n  moreover have valid_add_new_auxlist: \"valid_muaux args nt (add_new_muaux args rel1 rel2 nt aux) auxlist'\"\n    using valid_add_new_muaux[OF valid_aux tab1 tab2 nt_mono]\n    unfolding auxlist'_def nt_def length_aux .\n  moreover have \"length_muaux args (add_new_muaux args rel1 rel2 nt aux) = Suc (length_muaux args aux)\"\n    using valid_length_muaux[OF valid_add_new_auxlist] unfolding length_auxlist' length_aux[symmetric] .\n  moreover have \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> auxlist' ne\"\n    using wf_update_until_auxlist[OF pre_list qtable1[unfolded length_aux] qtable2[unfolded length_aux] fv_sub args_ivl args_n args_pos]\n    unfolding auxlist'_def .\n  moreover have \"\\<tau> \\<sigma> (ne + length auxlist) = (if ne + length auxlist' = 0 then 0 else \\<tau> \\<sigma> (ne + length auxlist' - 1))\"\n    unfolding cur length_auxlist' by auto\n  ultimately show ?thesis\n    unfolding wf_until_aux_def nt_def length_aux args_ivl args_n args_pos by fast\nqed\n\nlemma length_update_matchF_base:\n  \"length (fst (update_matchF_base I mr mrs nt entry st)) = Suc 0\"\n  by (auto simp: Let_def update_matchF_base_def)\n\nlemma length_update_matchF_step:\n  \"length (fst (update_matchF_step I mr mrs nt entry st)) = Suc (length (fst st))\"\n  by (auto simp: Let_def update_matchF_step_def split: prod.splits)\n\nlemma length_foldr_update_matchF_step:\n  \"length (fst (foldr (update_matchF_step I mr mrs nt) aux base)) = length aux + length (fst base)\"\n  by (induct aux arbitrary: base) (auto simp: Let_def length_update_matchF_step)\n\nlemma length_update_matchF: \"length (update_matchF n I mr mrs rels nt aux) = Suc (length aux)\"\n  unfolding update_matchF_def update_matchF_base_def length_foldr_update_matchF_step\n  by (auto simp: Let_def)\n\nlemma wf_update_matchF_base_invar:\n  assumes safe: \"safe_regex Futu Strict r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (LPDs mr)\"\n    and qtables: \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) j \\<phi>) rel) \\<phi>s rels\"\n  shows \"wf_matchF_invar \\<sigma> V n R I r (update_matchF_base n I mr mrs rels (\\<tau> \\<sigma> j)) j\"\nproof -\n  have from_mregex: \"from_mregex mr \\<phi>s = r\"\n    using safe mr using from_mregex_eq by blast\n  { fix ms\n    assume \"ms \\<in> LPDs mr\"\n    then have \"fv_regex (from_mregex ms \\<phi>s) = fv_regex r\"\n      \"safe_regex Futu Strict (from_mregex ms \\<phi>s)\" \"ok (length \\<phi>s) ms\" \"LPD ms \\<subseteq> LPDs mr\"\n      using safe LPDs_safe LPDs_safe_fv_regex mr from_mregex_to_mregex LPDs_ok to_mregex_ok LPDs_trans\n      by fastforce+\n  } note * = this\n  show ?thesis\n    unfolding wf_matchF_invar_def wf_matchF_aux_def update_matchF_base_def mr prod.case Let_def mrs\n    using safe\n    by (auto simp: * from_mregex qtables qtable_empty_iff zero_enat_def[symmetric]\n        lookup_tabulate finite_LPDs eps_match less_Suc_eq LPDs_refl\n        intro!: qtable_cong[OF qtable_l\\<epsilon>_strict[where \\<phi>s=\\<phi>s]] intro: qtables exI[of _ j]\n        split: option.splits)\nqed\n\nlemma Un_empty_table[simp]: \"rel \\<union> empty_table = rel\" \"empty_table \\<union> rel = rel\"\n  unfolding empty_table_def by auto\n\nlemma wf_matchF_invar_step:\n  assumes wf: \"wf_matchF_invar \\<sigma> V n R I r st (Suc i)\"\n    and safe: \"safe_regex Futu Strict r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (LPDs mr)\"\n    and qtables: \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>) rel) \\<phi>s rels\"\n    and rel: \"qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v. (\\<exists>j. i \\<le> j \\<and> j < i + length (fst st) \\<and> mem (\\<tau> \\<sigma> j - \\<tau> \\<sigma> i) I \\<and>\n          Regex.match (Formula.sat \\<sigma> V (map the v)) r i j)) rel\"\n    and entry: \"entry = (\\<tau> \\<sigma> i, rels, rel)\"\n    and nt: \"nt = \\<tau> \\<sigma> (i + length (fst st))\"\n  shows \"wf_matchF_invar \\<sigma> V n R I r (update_matchF_step I mr mrs nt entry st) i\"\nproof -\n  have from_mregex: \"from_mregex mr \\<phi>s = r\"\n    using safe mr using from_mregex_eq by blast\n  { fix ms\n    assume \"ms \\<in> LPDs mr\"\n    then have \"fv_regex (from_mregex ms \\<phi>s) = fv_regex r\"\n      \"safe_regex Futu Strict (from_mregex ms \\<phi>s)\" \"ok (length \\<phi>s) ms\" \"LPD ms \\<subseteq> LPDs mr\"\n      using safe LPDs_safe LPDs_safe_fv_regex mr from_mregex_to_mregex LPDs_ok to_mregex_ok LPDs_trans\n      by fastforce+\n  } note * = this\n  { fix aux X ms\n    assume \"st = (aux, X)\" \"ms \\<in> LPDs mr\"\n    with wf mr have \"qtable n (fv_regex r) (mem_restr R)\n      (\\<lambda>v. Regex.match (Formula.sat \\<sigma> V (map the v)) (from_mregex ms \\<phi>s) i (i + length aux))\n      (l\\<delta> (\\<lambda>x. x) X rels ms)\"\n      by (intro qtable_cong[OF qtable_l\\<delta>[where \\<phi>s=\\<phi>s and A=\"fv_regex r\" and\n              Q=\"\\<lambda>v r. Regex.match (Formula.sat \\<sigma> V v) r (Suc i) (i + length aux)\", OF _ _ qtables]])\n        (auto simp: wf_matchF_invar_def * LPDs_trans lpd_match[of i] elim!: bspec)\n  } note l\\<delta> = this\n  have \"lookup (mrtabulate mrs f) ms = f ms\" if \"ms \\<in> LPDs mr\" for ms and f :: \"mregex \\<Rightarrow> 'a table\"\n    using that mrs  by (fastforce simp: lookup_tabulate finite_LPDs split: option.splits)+\n  then show ?thesis\n    using wf mr mrs entry nt LPDs_trans\n    by (auto 0 3 simp: Let_def wf_matchF_invar_def update_matchF_step_def wf_matchF_aux_def mr * LPDs_refl\n        list_all2_Cons1 append_eq_Cons_conv upt_eq_Cons_conv Suc_le_eq qtables\n        lookup_tabulate finite_LPDs id_def l\\<delta> from_mregex less_Suc_eq\n        intro!: qtable_union[OF rel l\\<delta>] qtable_cong[OF rel]\n        intro: exI[of _ \"i + length _\"]\n        split: if_splits prod.splits)\nqed\n\nlemma wf_update_matchF_invar:\n  assumes pre: \"wf_matchF_aux \\<sigma> V n R I r aux ne (length (fst st) - 1)\"\n    and wf: \"wf_matchF_invar \\<sigma> V n R I r st (ne + length aux)\"\n    and safe: \"safe_regex Futu Strict r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (LPDs mr)\"\n    and j: \"j = ne + length aux + length (fst st) - 1\"\n  shows \"wf_matchF_invar \\<sigma> V n R I r (foldr (update_matchF_step I mr mrs (\\<tau> \\<sigma> j)) aux st) ne\"\n  using pre wf unfolding j\nproof (induct aux arbitrary: ne)\n  case (Cons entry aux)\n  from Cons(1)[of \"Suc ne\"] Cons(2,3) show ?case\n    unfolding foldr.simps o_apply\n    by (intro wf_matchF_invar_step[where rels = \"fst (snd entry)\" and rel = \"snd (snd entry)\"])\n      (auto simp: safe mr mrs wf_matchF_aux_def wf_matchF_invar_def list_all2_Cons1 append_eq_Cons_conv\n        Suc_le_eq upt_eq_Cons_conv length_foldr_update_matchF_step add.assoc split: if_splits)\nqed simp\n\n\nlemma wf_update_matchF:\n  assumes pre: \"wf_matchF_aux \\<sigma> V n R I r aux ne 0\"\n    and safe: \"safe_regex Futu Strict r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (LPDs mr)\"\n    and nt: \"nt = \\<tau> \\<sigma> (ne + length aux)\"\n    and qtables: \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne + length aux) \\<phi>) rel) \\<phi>s rels\"\n  shows \"wf_matchF_aux \\<sigma> V n R I r (update_matchF n I mr mrs rels nt aux) ne 0\"\n  unfolding update_matchF_def using wf_update_matchF_base_invar[OF safe mr mrs qtables, of I]\n  unfolding nt\n  by (intro wf_update_matchF_invar[OF _ _ safe mr mrs, unfolded wf_matchF_invar_def split_beta, THEN conjunct2, THEN conjunct1])\n    (auto simp: length_update_matchF_base wf_matchF_invar_def update_matchF_base_def Let_def pre)\n\nlemma wf_until_aux_Cons: \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> (a # aux) ne \\<Longrightarrow>\n  wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> aux (Suc ne)\"\n  unfolding wf_until_auxlist_def\n  by (simp add: upt_conv_Cons del: upt_Suc cong: if_cong)\n\nlemma wf_matchF_aux_Cons: \"wf_matchF_aux \\<sigma> V n R I r (entry # aux) ne i \\<Longrightarrow>\n  wf_matchF_aux \\<sigma> V n R I r aux (Suc ne) i\"\n  unfolding wf_matchF_aux_def\n  by (simp add: upt_conv_Cons del: upt_Suc cong: if_cong split: prod.splits)\n\nlemma wf_until_aux_Cons1: \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> ((t, a1, a2) # aux) ne \\<Longrightarrow> t = \\<tau> \\<sigma> ne\"\n  unfolding wf_until_auxlist_def\n  by (simp add: upt_conv_Cons del: upt_Suc)\n\nlemma wf_matchF_aux_Cons1: \"wf_matchF_aux \\<sigma> V n R I r ((t, rels, rel) # aux) ne i \\<Longrightarrow> t = \\<tau> \\<sigma> ne\"\n  unfolding wf_matchF_aux_def\n  by (simp add: upt_conv_Cons del: upt_Suc split: prod.splits)\n\nlemma wf_until_aux_Cons3: \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> ((t, a1, a2) # aux) ne \\<Longrightarrow>\n  qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. (\\<exists>j. ne \\<le> j \\<and> j < Suc (ne + length aux) \\<and> mem (\\<tau> \\<sigma> j - \\<tau> \\<sigma> ne) I \\<and>\n    Formula.sat \\<sigma> V (map the v) j \\<psi> \\<and> (\\<forall>k\\<in>{ne..<j}. if pos then Formula.sat \\<sigma> V (map the v) k \\<phi> else \\<not> Formula.sat \\<sigma> V (map the v) k \\<phi>))) a2\"\n  unfolding wf_until_auxlist_def\n  by (simp add: upt_conv_Cons del: upt_Suc)\n\nlemma wf_matchF_aux_Cons3: \"wf_matchF_aux \\<sigma> V n R I r ((t, rels, rel) # aux) ne i \\<Longrightarrow>\n  qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v. (\\<exists>j. ne \\<le> j \\<and> j < Suc (ne + length aux + i) \\<and> mem (\\<tau> \\<sigma> j - \\<tau> \\<sigma> ne) I \\<and>\n    Regex.match (Formula.sat \\<sigma> V (map the v)) r ne j)) rel\"\n  unfolding wf_matchF_aux_def\n  by (simp add: upt_conv_Cons del: upt_Suc split: prod.splits)\n\nlemma upt_append: \"a \\<le> b \\<Longrightarrow> b \\<le> c \\<Longrightarrow> [a..<b] @ [b..<c] = [a..<c]\"\n  by (metis le_Suc_ex upt_add_eq_append)\n\nlemma wf_mbuf2_add:\n  assumes \"wf_mbuf2 i ja jb P Q buf\"\n    and \"list_all2 P [ja..<ja'] xs\"\n    and \"list_all2 Q [jb..<jb'] ys\"\n    and \"ja \\<le> ja'\" \"jb \\<le> jb'\"\n  shows \"wf_mbuf2 i ja' jb' P Q (mbuf2_add xs ys buf)\"\n  using assms unfolding wf_mbuf2_def\n  by (auto 0 3 simp: list_all2_append2 upt_append dest: list_all2_lengthD\n      intro: exI[where x=\"[i..<ja]\"] exI[where x=\"[ja..<ja']\"]\n      exI[where x=\"[i..<jb]\"] exI[where x=\"[jb..<jb']\"] split: prod.splits)\n\nlemma wf_mbufn_add:\n  assumes \"wf_mbufn i js Ps buf\"\n    and \"list_all3 list_all2 Ps (List.map2 (\\<lambda>j j'. [j..<j']) js js') xss\"\n    and \"list_all2 (\\<le>) js js'\"\n  shows \"wf_mbufn i js' Ps (mbufn_add xss buf)\"\n  unfolding wf_mbufn_def list_all3_conv_all_nth\nproof safe\n  show \"length Ps = length js'\" \"length js' = length (mbufn_add xss buf)\"\n    using assms unfolding wf_mbufn_def list_all3_conv_all_nth list_all2_conv_all_nth by auto\nnext\n  fix k assume k: \"k < length Ps\"\n  then show \"i \\<le> js' ! k\"\n    using assms unfolding wf_mbufn_def list_all3_conv_all_nth list_all2_conv_all_nth\n    by (auto 0 4 dest: spec[of _ i])\n  from k have \" [i..<js' ! k] =  [i..<js ! k] @ [js ! k ..<js' ! k]\" and\n    \"length [i..<js ! k] = length (buf ! k)\"\n    using assms(1,3) unfolding wf_mbufn_def list_all3_conv_all_nth list_all2_conv_all_nth\n    by (auto simp: upt_append)\n  with k show \"list_all2 (Ps ! k) [i..<js' ! k] (mbufn_add xss buf ! k)\"\n    using assms[unfolded wf_mbufn_def list_all3_conv_all_nth]\n    by (auto simp add: list_all2_append)\nqed\n\nlemma mbuf2_take_eqD:\n  assumes \"mbuf2_take f buf = (xs, buf')\"\n    and \"wf_mbuf2 i ja jb P Q buf\"\n  shows \"wf_mbuf2 (min ja jb) ja jb P Q buf'\"\n    and \"list_all2 (\\<lambda>i z. \\<exists>x y. P i x \\<and> Q i y \\<and> z = f x y) [i..<min ja jb] xs\"\n  using assms unfolding wf_mbuf2_def\n  by (induction f buf arbitrary: i xs buf' rule: mbuf2_take.induct)\n    (fastforce simp add: list_all2_Cons2 upt_eq_Cons_conv min_absorb1 min_absorb2 split: prod.splits)+\n\nlemma list_all3_Nil[simp]:\n  \"list_all3 P xs ys [] \\<longleftrightarrow> xs = [] \\<and> ys = []\"\n  \"list_all3 P xs [] zs \\<longleftrightarrow> xs = [] \\<and> zs = []\"\n  \"list_all3 P [] ys zs \\<longleftrightarrow> ys = [] \\<and> zs = []\"\n  unfolding list_all3_conv_all_nth by auto\n\nlemma list_all3_Cons:\n  \"list_all3 P xs ys (z # zs) \\<longleftrightarrow> (\\<exists>x xs' y ys'. xs = x # xs' \\<and> ys = y # ys' \\<and> P x y z \\<and> list_all3 P xs' ys' zs)\"\n  \"list_all3 P xs (y # ys) zs \\<longleftrightarrow> (\\<exists>x xs' z zs'. xs = x # xs' \\<and> zs = z # zs' \\<and> P x y z \\<and> list_all3 P xs' ys zs')\"\n  \"list_all3 P (x # xs) ys zs \\<longleftrightarrow> (\\<exists>y ys' z zs'. ys = y # ys' \\<and> zs = z # zs' \\<and> P x y z \\<and> list_all3 P xs ys' zs')\"\n  unfolding list_all3_conv_all_nth\n  by (auto simp: length_Suc_conv Suc_length_conv nth_Cons split: nat.splits)\n\nlemma list_all3_mono_strong: \"list_all3 P xs ys zs \\<Longrightarrow>\n  (\\<And>x y z. x \\<in> set xs \\<Longrightarrow> y \\<in> set ys \\<Longrightarrow> z \\<in> set zs \\<Longrightarrow> P x y z \\<Longrightarrow> Q x y z) \\<Longrightarrow>\n  list_all3 Q xs ys zs\"\n  by (induct xs ys zs rule: list_all3.induct) (auto intro: list_all3.intros)\n\ndefinition Mini where\n  \"Mini i js = (if js = [] then i else Min (set js))\"\n\nlemma wf_mbufn_in_set_Mini:\n  assumes \"wf_mbufn i js Ps buf\"\n  shows \"[] \\<in> set buf \\<Longrightarrow> Mini i js = i\"\n  unfolding in_set_conv_nth\nproof (elim exE conjE)\n  fix k\n  have \"i \\<le> j\" if \"j \\<in> set js\" for j\n    using that assms unfolding wf_mbufn_def list_all3_conv_all_nth in_set_conv_nth by auto\n  moreover assume \"k < length buf\" \"buf ! k = []\"\n  ultimately show ?thesis using assms\n    unfolding Mini_def wf_mbufn_def list_all3_conv_all_nth\n    by (auto 0 4 dest!: spec[of _ k] intro: Min_eqI simp: in_set_conv_nth)\nqed\n\nlemma wf_mbufn_notin_set:\n  assumes \"wf_mbufn i js Ps buf\"\n  shows \"[] \\<notin> set buf \\<Longrightarrow> j \\<in> set js \\<Longrightarrow> i < j\"\n  using assms unfolding wf_mbufn_def list_all3_conv_all_nth\n  by (cases \"i \\<in> set js\") (auto intro: le_neq_implies_less simp: in_set_conv_nth)\n\nlemma wf_mbufn_map_tl:\n  \"wf_mbufn i js Ps buf \\<Longrightarrow> [] \\<notin> set buf \\<Longrightarrow> wf_mbufn (Suc i) js Ps (map tl buf)\"\n  by (auto simp: wf_mbufn_def list_all3_map Suc_le_eq\n      dest: rel_funD[OF tl_transfer]  elim!: list_all3_mono_strong le_neq_implies_less)\n\nlemma list_all3_list_all2I: \"list_all3 (\\<lambda>x y z. Q x z) xs ys zs \\<Longrightarrow> list_all2 Q xs zs\"\n  by (induct xs ys zs rule: list_all3.induct) auto\n\nlemma mbuf2t_take_eqD:\n  assumes \"mbuf2t_take f z buf nts = (z', buf', nts')\"\n    and \"wf_mbuf2 i ja jb P Q buf\"\n    and \"list_all2 R [i..<j] nts\"\n    and \"ja \\<le> j\" \"jb \\<le> j\"\n  shows \"wf_mbuf2 (min ja jb) ja jb P Q buf'\"\n    and \"list_all2 R [min ja jb..<j] nts'\"\n  using assms unfolding wf_mbuf2_def\n  by (induction f z buf nts arbitrary: i z' buf' nts' rule: mbuf2t_take.induct)\n    (auto simp add: list_all2_Cons2 upt_eq_Cons_conv less_eq_Suc_le min_absorb1 min_absorb2\n      split: prod.split)\n\nlemma wf_mbufn_take:\n  assumes \"mbufn_take f z buf = (z', buf')\"\n    and \"wf_mbufn i js Ps buf\"\n  shows \"wf_mbufn (Mini i js) js Ps buf'\"\n  using assms unfolding wf_mbufn_def\nproof (induction f z buf arbitrary: i z' buf' rule: mbufn_take.induct)\n  case rec: (1 f z buf)\n  show ?case proof (cases \"buf = []\")\n    case True\n    with rec.prems show ?thesis by simp\n  next\n    case nonempty: False\n    show ?thesis proof (cases \"[] \\<in> set buf\")\n      case True\n      from rec.prems(2) have \"\\<forall>j\\<in>set js. i \\<le> j\"\n        by (auto simp: in_set_conv_nth list_all3_conv_all_nth)\n      moreover from True rec.prems(2) have \"i \\<in> set js\"\n        by (fastforce simp: in_set_conv_nth list_all3_conv_all_nth list_all2_iff)\n      ultimately have \"Mini i js = i\"\n        unfolding Mini_def\n        by (auto intro!: antisym[OF Min.coboundedI Min.boundedI])\n      with rec.prems nonempty True show ?thesis by simp\n    next\n      case False\n      from nonempty rec.prems(2) have \"Mini i js = Mini (Suc i) js\"\n        unfolding Mini_def by auto\n      show ?thesis\n        unfolding \\<open>Mini i js = Mini (Suc i) js\\<close>\n      proof (rule rec.IH)\n        show \"\\<not> (buf = [] \\<or> [] \\<in> set buf)\" using nonempty False by simp\n        show \"list_all3 (\\<lambda>P j xs. Suc i \\<le> j \\<and> list_all2 P [Suc i..<j] xs) Ps js (map tl buf)\"\n          using False rec.prems(2)\n          by (auto simp: list_all3_map elim!: list_all3_mono_strong dest: list.rel_sel[THEN iffD1])\n        show \"mbufn_take f (f (map hd buf) z) (map tl buf) = (z', buf')\"\n          using nonempty False rec.prems(1) by simp\n      qed\n    qed\n  qed\nqed\n\nlemma mbufnt_take_eqD:\n  assumes \"mbufnt_take f z buf nts = (z', buf', nts')\"\n    and \"wf_mbufn i js Ps buf\"\n    and \"list_all2 R [i..<j] nts\"\n    and \"\\<And>k. k \\<in> set js \\<Longrightarrow> k \\<le> j\"\n    and \"k = Mini (i + length nts) js\"\n  shows \"wf_mbufn k js Ps buf'\"\n    and \"list_all2 R [k..<j] nts'\"\n  using assms(1-4) unfolding assms(5)\nproof (induction f z buf nts arbitrary: i z' buf' nts' rule: mbufnt_take.induct)\n  case IH: (1 f z buf nts)\n  note mbufnt_take.simps[simp del]\n  case 1\n  then have *: \"list_all2 R [Suc i..<j] (tl nts)\"\n    by (auto simp: list.rel_sel[of R \"[i..<j]\" nts, simplified])\n  from 1 show ?case\n    using wf_mbufn_in_set_Mini[OF 1(2)]\n    by (subst (asm) mbufnt_take.simps)\n      (force simp: Mini_def wf_mbufn_def split: if_splits prod.splits elim!: list_all3_mono_strong\n        dest!: IH(1)[rotated, OF _ wf_mbufn_map_tl[OF 1(2)] *])\n  case 2\n  then have *: \"list_all2 R [Suc i..<j] (tl nts)\"\n    by (auto simp: list.rel_sel[of R \"[i..<j]\" nts, simplified])\n  have [simp]: \"Suc (i + (length nts - Suc 0)) = i + length nts\" if \"nts \\<noteq> []\"\n    using that by (fastforce simp flip: length_greater_0_conv)\n  with 2 show ?case\n    using wf_mbufn_in_set_Mini[OF 2(2)] wf_mbufn_notin_set[OF 2(2)]\n    by (subst (asm) mbufnt_take.simps) (force simp: Mini_def wf_mbufn_def\n        dest!: IH(2)[rotated, OF _ wf_mbufn_map_tl[OF 2(2)] *]\n        split: if_splits prod.splits)\nqed\n\nlemma mbuf2t_take_induct[consumes 5, case_names base step]:\n  assumes \"mbuf2t_take f z buf nts = (z', buf', nts')\"\n    and \"wf_mbuf2 i ja jb P Q buf\"\n    and \"list_all2 R [i..<j] nts\"\n    and \"ja \\<le> j\" \"jb \\<le> j\"\n    and \"U i z\"\n    and \"\\<And>k x y t z. i \\<le> k \\<Longrightarrow> Suc k \\<le> ja \\<Longrightarrow> Suc k \\<le> jb \\<Longrightarrow>\n      P k x \\<Longrightarrow> Q k y \\<Longrightarrow> R k t \\<Longrightarrow> U k z \\<Longrightarrow> U (Suc k) (f x y t z)\"\n  shows \"U (min ja jb) z'\"\n  using assms unfolding wf_mbuf2_def\n  by (induction f z buf nts arbitrary: i z' buf' nts' rule: mbuf2t_take.induct)\n    (auto simp add: list_all2_Cons2 upt_eq_Cons_conv less_eq_Suc_le min_absorb1 min_absorb2\n      elim!: arg_cong2[of _ _ _ _ U, OF _ refl, THEN iffD1, rotated] split: prod.split)\n\nlemma list_all2_hdD:\n  assumes \"list_all2 P [i..<j] xs\" \"xs \\<noteq> []\"\n  shows \"P i (hd xs)\" \"i < j\"\n  using assms unfolding list_all2_conv_all_nth\n  by (auto simp: hd_conv_nth intro: zero_less_diff[THEN iffD1] dest!: spec[of _ 0])\n\nlemma mbufn_take_induct[consumes 3, case_names base step]:\n  assumes \"mbufn_take f z buf = (z', buf')\"\n    and \"wf_mbufn i js Ps buf\"\n    and \"U i z\"\n    and \"\\<And>k xs z. i \\<le> k \\<Longrightarrow> Suc k \\<le> Mini i js \\<Longrightarrow>\n      list_all2 (\\<lambda>P x. P k x) Ps xs \\<Longrightarrow> U k z \\<Longrightarrow> U (Suc k) (f xs z)\"\n  shows \"U (Mini i js) z'\"\n  using assms unfolding wf_mbufn_def\nproof (induction f z buf arbitrary: i z' buf' rule: mbufn_take.induct)\n  case rec: (1 f z buf)\n  show ?case proof (cases \"buf = []\")\n    case True\n    with rec.prems show ?thesis unfolding Mini_def by simp\n  next\n    case nonempty: False\n    show ?thesis proof (cases \"[] \\<in> set buf\")\n      case True\n      from rec.prems(2) have \"\\<forall>j\\<in>set js. i \\<le> j\"\n        by (auto simp: in_set_conv_nth list_all3_conv_all_nth)\n      moreover from True rec.prems(2) have \"i \\<in> set js\"\n        by (fastforce simp: in_set_conv_nth list_all3_conv_all_nth list_all2_iff)\n      ultimately have \"Mini i js = i\"\n        unfolding Mini_def\n        by (auto intro!: antisym[OF Min.coboundedI Min.boundedI])\n      with rec.prems nonempty True show ?thesis by simp\n    next\n      case False\n      with nonempty rec.prems(2) have more: \"Suc i \\<le> Mini i js\"\n        using diff_is_0_eq not_le unfolding Mini_def\n        by (fastforce simp: in_set_conv_nth list_all3_conv_all_nth list_all2_iff)\n      then have \"Mini i js = Mini (Suc i) js\" unfolding Mini_def by auto\n      show ?thesis\n        unfolding \\<open>Mini i js = Mini (Suc i) js\\<close>\n      proof (rule rec.IH)\n        show \"\\<not> (buf = [] \\<or> [] \\<in> set buf)\" using nonempty False by simp\n        show \"mbufn_take f (f (map hd buf) z) (map tl buf) = (z', buf')\"\n          using nonempty False rec.prems by simp\n        show \"list_all3 (\\<lambda>P j xs. Suc i \\<le> j \\<and> list_all2 P [Suc i..<j] xs) Ps js (map tl buf)\"\n          using False rec.prems\n          by (auto simp: list_all3_map elim!: list_all3_mono_strong dest: list.rel_sel[THEN iffD1])\n        show \"U (Suc i) (f (map hd buf) z)\"\n          using more False rec.prems\n          by (auto 0 4 simp: list_all3_map intro!: rec.prems(4) list_all3_list_all2I\n              elim!: list_all3_mono_strong dest: list.rel_sel[THEN iffD1])\n        show \"\\<And>k xs z. Suc i \\<le> k \\<Longrightarrow> Suc k \\<le> Mini (Suc i) js \\<Longrightarrow>\n          list_all2 (\\<lambda>P. P k) Ps xs \\<Longrightarrow> U k z \\<Longrightarrow> U (Suc k) (f xs z)\"\n          by (rule rec.prems(4)) (auto simp: Mini_def)\n      qed\n    qed\n  qed\nqed\n\nlemma mbufnt_take_induct[consumes 5, case_names base step]:\n  assumes \"mbufnt_take f z buf nts = (z', buf', nts')\"\n    and \"wf_mbufn i js Ps buf\"\n    and \"list_all2 R [i..<j] nts\"\n    and \"\\<And>k. k \\<in> set js \\<Longrightarrow> k \\<le> j\"\n    and \"U i z\"\n    and \"\\<And>k xs t z. i \\<le> k \\<Longrightarrow> Suc k \\<le> Mini j js \\<Longrightarrow>\n      list_all2 (\\<lambda>P x. P k x) Ps xs \\<Longrightarrow> R k t \\<Longrightarrow> U k z \\<Longrightarrow> U (Suc k) (f xs t z)\"\n  shows \"U (Mini (i + length nts) js) z'\"\n  using assms\nproof (induction f z buf nts arbitrary: i z' buf' nts' rule: mbufnt_take.induct)\n  case (1 f z buf nts)\n  then have *: \"list_all2 R [Suc i..<j] (tl nts)\"\n    by (auto simp: list.rel_sel[of R \"[i..<j]\" nts, simplified])\n  note mbufnt_take.simps[simp del]\n  from 1(2-6) have \"i = Min (set js)\" if \"js \\<noteq> []\" \"nts = []\"\n    using that unfolding wf_mbufn_def using wf_mbufn_in_set_Mini[OF 1(3)]\n    by (fastforce simp: Mini_def list_all3_Cons neq_Nil_conv)\n  with 1(2-7) list_all2_hdD[OF 1(4)] show ?case\n    unfolding wf_mbufn_def using wf_mbufn_in_set_Mini[OF 1(3)] wf_mbufn_notin_set[OF 1(3)]\n    by (subst (asm) mbufnt_take.simps)\n      (auto simp add: Mini_def list.rel_map Suc_le_eq\n        elim!: arg_cong2[of _ _ _ _ U, OF _ refl, THEN iffD1, rotated]\n        list_all3_mono_strong[THEN list_all3_list_all2I[of _ _ js]] list_all2_hdD\n        dest!: 1(1)[rotated, OF _ wf_mbufn_map_tl[OF 1(3)] * _ 1(7)] split: prod.split if_splits)\nqed\n\nlemma mbuf2_take_add':\n  assumes eq: \"mbuf2_take f (mbuf2_add xs ys buf) = (zs, buf')\"\n    and pre: \"wf_mbuf2' \\<sigma> P V j n R \\<phi> \\<psi> buf\"\n    and rm: \"rel_mapping (\\<le>) P P'\"\n    and xs: \"list_all2 (\\<lambda>i. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>))\n      [progress \\<sigma> P \\<phi> j..<progress \\<sigma> P' \\<phi> j'] xs\"\n    and ys: \"list_all2 (\\<lambda>i. qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>))\n      [progress \\<sigma> P \\<psi> j..<progress \\<sigma> P' \\<psi> j'] ys\"\n    and \"j \\<le> j'\"\n  shows \"wf_mbuf2' \\<sigma> P' V j' n R \\<phi> \\<psi> buf'\"\n    and \"list_all2 (\\<lambda>i Z. \\<exists>X Y.\n      qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>) X \\<and>\n      qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>) Y \\<and>\n      Z = f X Y)\n      [min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)..<min (progress \\<sigma> P' \\<phi> j') (progress \\<sigma> P' \\<psi> j')] zs\"\n  using pre rm unfolding wf_mbuf2'_def\n  by (force intro!: mbuf2_take_eqD[OF eq] wf_mbuf2_add[OF _ xs ys] progress_mono_gen[OF \\<open>j \\<le> j'\\<close> rm])+\n\nlemma mbuf2t_take_add':\n  assumes eq: \"mbuf2t_take f z (mbuf2_add xs ys buf) nts = (z', buf', nts')\"\n    and bounded: \"pred_mapping (\\<lambda>x. x \\<le> j) P\" \"pred_mapping (\\<lambda>x. x \\<le> j') P'\"\n    and rm: \"rel_mapping (\\<le>) P P'\"\n    and pre_buf: \"wf_mbuf2' \\<sigma> P V j n R \\<phi> \\<psi> buf\"\n    and pre_nts: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)..<j'] nts\"\n    and xs: \"list_all2 (\\<lambda>i. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>))\n      [progress \\<sigma> P \\<phi> j..<progress \\<sigma> P' \\<phi> j'] xs\"\n    and ys: \"list_all2 (\\<lambda>i. qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>))\n      [progress \\<sigma> P \\<psi> j..<progress \\<sigma> P' \\<psi> j'] ys\"\n    and \"j \\<le> j'\"\n  shows \"wf_mbuf2' \\<sigma> P' V j' n R \\<phi> \\<psi> buf'\"\n    and \"wf_ts \\<sigma> P' j' \\<phi> \\<psi> nts'\"\n  using pre_buf pre_nts bounded rm unfolding wf_mbuf2'_def wf_ts_def\n  by (auto intro!: mbuf2t_take_eqD[OF eq] wf_mbuf2_add[OF _ xs ys] progress_mono_gen[OF \\<open>j \\<le> j'\\<close> rm]\n      progress_le_gen)\n\nlemma ok_0_atms: \"ok 0 mr \\<Longrightarrow> regex.atms (from_mregex mr []) = {}\"\n  by (induct mr) auto\n\nlemma ok_0_progress: \"ok 0 mr \\<Longrightarrow> progress_regex \\<sigma> P (from_mregex mr []) j = j\"\n  by (drule ok_0_atms) (auto simp: progress_regex_def)\n\nlemma atms_empty_atms: \"safe_regex m g r \\<Longrightarrow> atms r = {} \\<longleftrightarrow> regex.atms r = {}\"\n  by (induct r rule: safe_regex_induct) (auto split: if_splits simp: cases_Neg_iff)\n\nlemma atms_empty_progress: \"safe_regex m g r \\<Longrightarrow> atms r = {} \\<Longrightarrow> progress_regex \\<sigma> P r j = j\"\n  by (drule atms_empty_atms) (auto simp: progress_regex_def)\n\nlemma to_mregex_empty_progress: \"safe_regex m g r \\<Longrightarrow> to_mregex r = (mr, []) \\<Longrightarrow>\n  progress_regex \\<sigma> P r j = j\"\n  using from_mregex_eq ok_0_progress to_mregex_ok atms_empty_atms by fastforce\n\nlemma progress_regex_le: \"pred_mapping (\\<lambda>x. x \\<le> j) P \\<Longrightarrow> progress_regex \\<sigma> P r j \\<le> j\"\n  by (auto intro!: progress_le_gen simp: Min_le_iff progress_regex_def)\n\nlemma Neg_acyclic: \"formula.Neg x = x \\<Longrightarrow> P\"\n  by (induct x) auto\n\nlemma case_Neg_in_iff: \"x \\<in> (case y of formula.Neg \\<phi>' \\<Rightarrow> {\\<phi>'} | _ \\<Rightarrow> {}) \\<longleftrightarrow> y = formula.Neg x\"\n  by (cases y) auto\n\nlemma atms_nonempty_progress:\n  \"safe_regex m g r \\<Longrightarrow> atms r \\<noteq> {} \\<Longrightarrow> (\\<lambda>\\<phi>. progress \\<sigma> P \\<phi> j) ` atms r = (\\<lambda>\\<phi>. progress \\<sigma> P \\<phi> j) ` regex.atms r\"\n  by (frule atms_empty_atms; simp)\n    (auto 0 3 simp: atms_def image_iff case_Neg_in_iff elim!: disjE_Not2 dest: safe_regex_safe_formula)\n\nlemma to_mregex_nonempty_progress: \"safe_regex m g r \\<Longrightarrow> to_mregex r = (mr, \\<phi>s) \\<Longrightarrow> \\<phi>s \\<noteq> [] \\<Longrightarrow>\n  progress_regex \\<sigma> P r j = (MIN \\<phi>\\<in>set \\<phi>s. progress \\<sigma> P \\<phi> j)\"\n  using atms_nonempty_progress to_mregex_ok unfolding progress_regex_def by fastforce\n\nlemma to_mregex_progress: \"safe_regex m g r \\<Longrightarrow> to_mregex r = (mr, \\<phi>s) \\<Longrightarrow>\n  progress_regex \\<sigma> P r j = (if \\<phi>s = [] then j else (MIN \\<phi>\\<in>set \\<phi>s. progress \\<sigma> P \\<phi> j))\"\n  using to_mregex_nonempty_progress to_mregex_empty_progress unfolding progress_regex_def by auto\n\nlemma mbufnt_take_add':\n  assumes eq: \"mbufnt_take f z (mbufn_add xss buf) nts = (z', buf', nts')\"\n    and bounded: \"pred_mapping (\\<lambda>x. x \\<le> j) P\" \"pred_mapping (\\<lambda>x. x \\<le> j') P'\"\n    and rm: \"rel_mapping (\\<le>) P P'\"\n    and safe: \"safe_regex m g r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and pre_buf: \"wf_mbufn' \\<sigma> P V j n R r buf\"\n    and pre_nts: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [progress_regex \\<sigma> P r j..<j'] nts\"\n    and xss: \"list_all3 list_all2\n     (map (\\<lambda>\\<phi> i. qtable n (fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>)) \\<phi>s)\n     (map2 upt (map (\\<lambda>\\<phi>. progress \\<sigma> P \\<phi> j) \\<phi>s) (map (\\<lambda>\\<phi>. progress \\<sigma> P' \\<phi> j') \\<phi>s)) xss\"\n    and \"j \\<le> j'\"\n  shows \"wf_mbufn' \\<sigma> P' V j' n R r buf'\"\n    and \"wf_ts_regex \\<sigma> P' j' r nts'\"\n  using pre_buf pre_nts bounded rm mr safe xss \\<open>j \\<le> j'\\<close>  unfolding wf_mbufn'_def wf_ts_regex_def\n  using atms_empty_progress[of m g r] to_mregex_ok[OF mr]\n  by (auto 0 3 simp: list.rel_map to_mregex_empty_progress to_mregex_nonempty_progress Mini_def\n      intro: progress_mono_gen[OF \\<open>j \\<le> j'\\<close> rm] list.rel_refl_strong progress_le_gen\n      dest: list_all2_lengthD elim!: mbufnt_take_eqD[OF eq wf_mbufn_add])\n\nlemma mbuf2t_take_add_induct'[consumes 6, case_names base step]:\n  assumes eq: \"mbuf2t_take f z (mbuf2_add xs ys buf) nts = (z', buf', nts')\"\n    and bounded: \"pred_mapping (\\<lambda>x. x \\<le> j) P\" \"pred_mapping (\\<lambda>x. x \\<le> j') P'\"\n    and rm: \"rel_mapping (\\<le>) P P'\"\n    and pre_buf: \"wf_mbuf2' \\<sigma> P V j n R \\<phi> \\<psi> buf\"\n    and pre_nts: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)..<j'] nts\"\n    and xs: \"list_all2 (\\<lambda>i. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>))\n      [progress \\<sigma> P \\<phi> j..<progress \\<sigma> P' \\<phi> j'] xs\"\n    and ys: \"list_all2 (\\<lambda>i. qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>))\n      [progress \\<sigma> P \\<psi> j..<progress \\<sigma> P' \\<psi> j'] ys\"\n    and \"j \\<le> j'\"\n    and base: \"U (min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)) z\"\n    and step: \"\\<And>k X Y z. min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j) \\<le> k \\<Longrightarrow>\n      Suc k \\<le> progress \\<sigma> P' \\<phi> j' \\<Longrightarrow> Suc k \\<le> progress \\<sigma> P' \\<psi> j' \\<Longrightarrow>\n      qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) k \\<phi>) X \\<Longrightarrow>\n      qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) k \\<psi>) Y \\<Longrightarrow>\n      U k z \\<Longrightarrow> U (Suc k) (f X Y (\\<tau> \\<sigma> k) z)\"\n  shows \"U (min (progress \\<sigma> P' \\<phi> j') (progress \\<sigma> P' \\<psi> j')) z'\"\n  using pre_buf pre_nts bounded rm unfolding wf_mbuf2'_def\n  by (blast intro!: mbuf2t_take_induct[OF eq] wf_mbuf2_add[OF _ xs ys] progress_mono_gen[OF \\<open>j \\<le> j'\\<close> rm]\n      progress_le_gen base step)\n\nlemma mbufnt_take_add_induct'[consumes 6, case_names base step]:\n  assumes eq: \"mbufnt_take f z (mbufn_add xss buf) nts = (z', buf', nts')\"\n    and bounded: \"pred_mapping (\\<lambda>x. x \\<le> j) P\" \"pred_mapping (\\<lambda>x. x \\<le> j') P'\"\n    and rm: \"rel_mapping (\\<le>) P P'\"\n    and safe: \"safe_regex m g r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and pre_buf: \"wf_mbufn' \\<sigma> P V j n R r buf\"\n    and pre_nts: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [progress_regex \\<sigma> P r j..<j'] nts\"\n    and xss: \"list_all3 list_all2\n     (map (\\<lambda>\\<phi> i. qtable n (fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>)) \\<phi>s)\n     (map2 upt (map (\\<lambda>\\<phi>. progress \\<sigma> P \\<phi> j) \\<phi>s) (map (\\<lambda>\\<phi>. progress \\<sigma> P' \\<phi> j') \\<phi>s)) xss\"\n    and \"j \\<le> j'\"\n    and base: \"U (progress_regex \\<sigma> P r j) z\"\n    and step: \"\\<And>k Xs z. progress_regex \\<sigma> P r j \\<le> k \\<Longrightarrow> Suc k \\<le> progress_regex \\<sigma> P' r j' \\<Longrightarrow>\n      list_all2 (\\<lambda>\\<phi>. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) k \\<phi>)) \\<phi>s Xs \\<Longrightarrow>\n      U k z \\<Longrightarrow> U (Suc k) (f Xs (\\<tau> \\<sigma> k) z)\"\n  shows \"U (progress_regex \\<sigma> P' r j') z'\"\n  using pre_buf pre_nts bounded rm \\<open>j \\<le> j'\\<close> to_mregex_progress[OF safe mr, of \\<sigma> P' j'] to_mregex_empty_progress[OF safe, of mr \\<sigma> P j] base\n  unfolding wf_mbufn'_def mr prod.case\n  by (fastforce dest!: mbufnt_take_induct[OF eq wf_mbufn_add[OF _ xss] pre_nts, of U]\n      simp: list.rel_map le_imp_diff_is_add ac_simps Mini_def\n      intro: progress_mono_gen[OF \\<open>j \\<le> j'\\<close> rm] list.rel_refl_strong progress_le_gen\n      intro!: base step  dest: list_all2_lengthD split: if_splits)\n\nlemma progress_Until_le: \"progress \\<sigma> P (Formula.Until \\<phi> I \\<psi>) j \\<le> min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)\"\n  by (cases \"right I\") (auto simp: trans_le_add1 intro!: cInf_lower)\n\nlemma progress_MatchF_le: \"progress \\<sigma> P (Formula.MatchF I r) j \\<le> progress_regex \\<sigma> P r j\"\n  by (cases \"right I\") (auto simp: trans_le_add1 progress_regex_def intro!: cInf_lower)\n\nlemma list_all2_upt_Cons: \"P a x \\<Longrightarrow> list_all2 P [Suc a..<b] xs \\<Longrightarrow> Suc a \\<le> b \\<Longrightarrow>\n  list_all2 P [a..<b] (x # xs)\"\n  by (simp add: list_all2_Cons2 upt_eq_Cons_conv)\n\nlemma list_all2_upt_append: \"list_all2 P [a..<b] xs \\<Longrightarrow> list_all2 P [b..<c] ys \\<Longrightarrow>\n  a \\<le> b \\<Longrightarrow> b \\<le> c \\<Longrightarrow> list_all2 P [a..<c] (xs @ ys)\"\n  by (induction xs arbitrary: a) (auto simp add: list_all2_Cons2 upt_eq_Cons_conv)\n\nlemma list_all3_list_all2_conv: \"list_all3 R xs xs ys = list_all2 (\\<lambda>x. R x x) xs ys\"\n  by (auto simp: list_all3_conv_all_nth list_all2_conv_all_nth)\n\nlemma map_split_map: \"map_split f (map g xs) = map_split (f o g) xs\"\n  by (induct xs) auto\n\nlemma map_split_alt: \"map_split f xs = (map (fst o f) xs, map (snd o f) xs)\"\n  by (induct xs) (auto split: prod.splits)\n\nlemma fv_formula_of_constraint: \"fv (formula_of_constraint (t1, p, c, t2)) = fv_trm t1 \\<union> fv_trm t2\"\n  by (induction \"(t1, p, c, t2)\" rule: formula_of_constraint.induct) simp_all\n\nlemma (in maux) wf_mformula_wf_set: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow> wf_set n (Formula.fv \\<phi>')\"\n  unfolding wf_set_def\nproof (induction rule: wf_mformula.induct)\n  case (AndRel P V n R \\<phi> \\<phi>' \\<psi>' conf)\n  then show ?case by (auto simp: fv_formula_of_constraint dest!: subsetD)\nnext\n  case (Ands P V n R l l_pos l_neg l' buf A_pos A_neg)\n  from Ands.IH have \"\\<forall>\\<phi>'\\<in>set (l_pos @ map remove_neg l_neg). \\<forall>x\\<in>fv \\<phi>'. x < n\"\n    by (simp add: list_all2_conv_all_nth all_set_conv_all_nth[of \"_ @ _\"] del: set_append)\n  then have \"\\<forall>\\<phi>'\\<in>set (l_pos @ l_neg). \\<forall>x\\<in>fv \\<phi>'. x < n\"\n    by (auto dest: bspec[where x=\"remove_neg _\"])\n  then show ?case using Ands.hyps(2) by auto\nnext\n  case (Agg P V b n R \\<phi> \\<phi>' y f g0 \\<omega>)\n  then have \"Formula.fvi_trm b f \\<subseteq> Formula.fvi b \\<phi>'\"\n    by (auto simp: fvi_trm_iff_fv_trm[where b=b] fvi_iff_fv[where b=b])\n  with Agg show ?case by (auto 0 3 simp: Un_absorb2 fvi_iff_fv[where b=b])\nnext\n  case (MatchP r P V n R \\<phi>s mr mrs buf nts I aux)\n  then obtain \\<phi>s' where conv: \"to_mregex r = (mr, \\<phi>s')\" by blast\n  with MatchP have \"\\<forall>\\<phi>'\\<in>set \\<phi>s'. \\<forall>x\\<in>fv \\<phi>'. x < n\"\n    by (simp add: list_all2_conv_all_nth all_set_conv_all_nth[of \\<phi>s'])\n  with conv show ?case\n    by (simp add: to_mregex_ok[THEN conjunct1] fv_regex_alt[OF \\<open>safe_regex _ _ r\\<close>])\nnext\n  case (MatchF r  P V n R \\<phi>s mr mrs buf nts I aux)\n  then obtain \\<phi>s' where conv: \"to_mregex r = (mr, \\<phi>s')\" by blast\n  with MatchF have \"\\<forall>\\<phi>'\\<in>set \\<phi>s'. \\<forall>x\\<in>fv \\<phi>'. x < n\"\n    by (simp add: list_all2_conv_all_nth all_set_conv_all_nth[of \\<phi>s'])\n  with conv show ?case\n    by (simp add: to_mregex_ok[THEN conjunct1] fv_regex_alt[OF \\<open>safe_regex _ _ r\\<close>])\nqed (auto simp: fvi_Suc split: if_splits)\n\nlemma qtable_mmulti_join:\n  assumes pos: \"list_all3 (\\<lambda>A Qi X. qtable n A P Qi X \\<and> wf_set n A) A_pos Q_pos L_pos\"\n    and neg: \"list_all3 (\\<lambda>A Qi X. qtable n A P Qi X \\<and> wf_set n A) A_neg Q_neg L_neg\"\n    and C_eq: \"C = \\<Union>(set A_pos)\" and L_eq: \"L = L_pos @ L_neg\"\n    and \"A_pos \\<noteq> []\" and fv_subset: \"\\<Union>(set A_neg) \\<subseteq> \\<Union>(set A_pos)\"\n    and restrict_pos: \"\\<And>x. wf_tuple n C x \\<Longrightarrow> P x \\<Longrightarrow> list_all (\\<lambda>A. P (restrict A x)) A_pos\"\n    and restrict_neg: \"\\<And>x. wf_tuple n C x \\<Longrightarrow> P x \\<Longrightarrow> list_all (\\<lambda>A. P (restrict A x)) A_neg\"\n    and Qs: \"\\<And>x. wf_tuple n C x \\<Longrightarrow> P x \\<Longrightarrow> Q x \\<longleftrightarrow>\n      list_all2 (\\<lambda>A Qi. Qi (restrict A x)) A_pos Q_pos \\<and>\n      list_all2 (\\<lambda>A Qi. \\<not> Qi (restrict A x)) A_neg Q_neg\"\n  shows \"qtable n C P Q (mmulti_join n A_pos A_neg L)\"\nproof (rule qtableI)\n  from pos have 1: \"list_all2 (\\<lambda>A X. table n A X \\<and> wf_set n A) A_pos L_pos\"\n    by (simp add: list_all3_conv_all_nth list_all2_conv_all_nth qtable_def)\n  moreover from neg have \"list_all2 (\\<lambda>A X. table n A X \\<and> wf_set n A) A_neg L_neg\"\n    by (simp add: list_all3_conv_all_nth list_all2_conv_all_nth qtable_def)\n  ultimately have L: \"list_all2 (\\<lambda>A X. table n A X \\<and> wf_set n A) (A_pos @ A_neg) (L_pos @ L_neg)\"\n    by (rule list_all2_appendI)\n  note in_join_iff = mmulti_join_correct[OF \\<open>A_pos \\<noteq> []\\<close> L]\n  from 1 have take_eq: \"take (length A_pos) (L_pos @ L_neg) = L_pos\"\n    by (auto dest!: list_all2_lengthD)\n  from 1 have drop_eq: \"drop (length A_pos) (L_pos @ L_neg) = L_neg\"\n    by (auto dest!: list_all2_lengthD)\n\n  note mmulti_join.simps[simp del]\n  show \"table n C (mmulti_join n A_pos A_neg L)\"\n    unfolding C_eq L_eq table_def by (simp add: in_join_iff)\n  show \"Q x\" if \"x \\<in> mmulti_join n A_pos A_neg L\" \"wf_tuple n C x\" \"P x\" for x\n    using that(2,3)\n  proof (rule Qs[THEN iffD2, OF _ _ conjI])\n    have pos': \"list_all2 (\\<lambda>A. (\\<in>) (restrict A x)) A_pos L_pos\"\n      and neg': \"list_all2 (\\<lambda>A. (\\<notin>) (restrict A x)) A_neg L_neg\"\n      using that(1) unfolding L_eq in_join_iff take_eq drop_eq by simp_all\n    show \"list_all2 (\\<lambda>A Qi. Qi (restrict A x)) A_pos Q_pos\"\n      using pos pos' restrict_pos that(2,3)\n      by (simp add: list_all3_conv_all_nth list_all2_conv_all_nth list_all_length qtable_def)\n    have fv_subset': \"\\<And>i. i < length A_neg \\<Longrightarrow> A_neg ! i \\<subseteq> C\"\n      using fv_subset unfolding C_eq by (auto simp: Sup_le_iff)\n    show \"list_all2 (\\<lambda>A Qi. \\<not> Qi (restrict A x)) A_neg Q_neg\"\n      using neg neg' restrict_neg that(2,3)\n      by (auto simp: list_all3_conv_all_nth list_all2_conv_all_nth list_all_length qtable_def\n          wf_tuple_restrict_simple[OF _ fv_subset'])\n  qed\n  show \"x \\<in> mmulti_join n A_pos A_neg L\" if \"wf_tuple n C x\" \"P x\" \"Q x\" for x\n    unfolding L_eq in_join_iff take_eq drop_eq\n  proof (intro conjI)\n    from that have pos': \"list_all2 (\\<lambda>A Qi. Qi (restrict A x)) A_pos Q_pos\"\n      and neg': \"list_all2 (\\<lambda>A Qi. \\<not> Qi (restrict A x)) A_neg Q_neg\"\n      using Qs[THEN iffD1] by auto\n    show \"wf_tuple n (\\<Union>A\\<in>set A_pos. A) x\"\n      using \\<open>wf_tuple n C x\\<close> unfolding C_eq by simp\n    show \"list_all2 (\\<lambda>A. (\\<in>) (restrict A x)) A_pos L_pos\"\n      using pos pos' restrict_pos that(1,2)\n      by (simp add: list_all3_conv_all_nth list_all2_conv_all_nth list_all_length qtable_def\n          C_eq wf_tuple_restrict_simple[OF _ Sup_upper])\n    show \"list_all2 (\\<lambda>A. (\\<notin>) (restrict A x)) A_neg L_neg\"\n      using neg neg' restrict_neg that(1,2)\n      by (auto simp: list_all3_conv_all_nth list_all2_conv_all_nth list_all_length qtable_def)\n  qed\nqed\n\nlemma nth_filter: \"i < length (filter P xs) \\<Longrightarrow>\n  (\\<And>i'. i' < length xs \\<Longrightarrow> P (xs ! i') \\<Longrightarrow> Q (xs ! i')) \\<Longrightarrow> Q (filter P xs ! i)\"\n  by (metis (lifting) in_set_conv_nth set_filter mem_Collect_eq)\n\nlemma nth_partition: \"i < length xs \\<Longrightarrow>\n  (\\<And>i'. i' < length (filter P xs) \\<Longrightarrow> Q (filter P xs ! i')) \\<Longrightarrow>\n  (\\<And>i'. i' < length (filter (Not \\<circ> P) xs) \\<Longrightarrow> Q (filter (Not \\<circ> P) xs ! i')) \\<Longrightarrow> Q (xs ! i)\"\n  by (metis (no_types, lifting) in_set_conv_nth set_filter mem_Collect_eq comp_apply)\n\nlemma qtable_bin_join:\n  assumes \"qtable n A P Q1 X\" \"qtable n B P Q2 Y\" \"\\<not> b \\<Longrightarrow> B \\<subseteq> A\" \"C = A \\<union> B\"\n    \"\\<And>x. wf_tuple n C x \\<Longrightarrow> P x \\<Longrightarrow> P (restrict A x) \\<and> P (restrict B x)\"\n    \"\\<And>x. b \\<Longrightarrow> wf_tuple n C x \\<Longrightarrow> P x \\<Longrightarrow> Q x \\<longleftrightarrow> Q1 (restrict A x) \\<and> Q2 (restrict B x)\"\n    \"\\<And>x. \\<not> b \\<Longrightarrow> wf_tuple n C x \\<Longrightarrow> P x \\<Longrightarrow> Q x \\<longleftrightarrow> Q1 (restrict A x) \\<and> \\<not> Q2 (restrict B x)\"\n  shows \"qtable n C P Q (bin_join n A X b B Y)\"\n  using qtable_join[OF assms] bin_join_table[of n A X B Y b] assms(1,2)\n  by (auto simp add: qtable_def)\n\nlemma restrict_update: \"y \\<notin> A \\<Longrightarrow> y < length x \\<Longrightarrow> restrict A (x[y:=z]) = restrict A x\"\n  unfolding restrict_def by (auto simp add: nth_list_update)\n\nlemma qtable_assign:\n  assumes \"qtable n A P Q X\"\n    \"y < n\" \"insert y A = A'\" \"y \\<notin> A\"\n    \"\\<And>x'. wf_tuple n A' x' \\<Longrightarrow> P x' \\<Longrightarrow> P (restrict A x')\"\n    \"\\<And>x. wf_tuple n A x \\<Longrightarrow> P x \\<Longrightarrow> Q x \\<Longrightarrow> Q' (x[y:=Some (f x)])\"\n    \"\\<And>x'. wf_tuple n A' x' \\<Longrightarrow> P x' \\<Longrightarrow> Q' x' \\<Longrightarrow> Q (restrict A x') \\<and> x' ! y = Some (f (restrict A x'))\"\n  shows \"qtable n A' P Q' ((\\<lambda>x. x[y:=Some (f x)]) ` X)\" (is \"qtable _ _ _ _ ?Y\")\nproof (rule qtableI)\n  from assms(1) have \"table n A X\" unfolding qtable_def by simp\n  then show \"table n A' ?Y\"\n    unfolding table_def wf_tuple_def using assms(2,3)\n    by (auto simp: nth_list_update)\nnext\n  fix x'\n  assume \"x' \\<in> ?Y\" \"wf_tuple n A' x'\" \"P x'\"\n  then obtain x where \"x \\<in> X\" and x'_eq: \"x' = x[y:=Some (f x)]\" by blast\n  then have \"wf_tuple n A x\"\n    using assms(1) unfolding qtable_def table_def by blast\n  then have \"y < length x\" using assms(2) by (simp add: wf_tuple_def)\n  with \\<open>wf_tuple n A x\\<close> have \"restrict A x' = x\"\n    unfolding x'_eq by (simp add: restrict_update[OF assms(4)] restrict_idle)\n  with \\<open>wf_tuple n A' x'\\<close> \\<open>P x'\\<close> have \"P x\"\n    using assms(5) by blast\n  with \\<open>wf_tuple n A x\\<close> \\<open>x \\<in> X\\<close> have \"Q x\"\n    using assms(1) by (elim in_qtableE)\n  with \\<open>wf_tuple n A x\\<close> \\<open>P x\\<close> show \"Q' x'\"\n    unfolding x'_eq by (rule assms(6))\nnext\n  fix x'\n  assume \"wf_tuple n A' x'\" \"P x'\" \"Q' x'\"\n  then have \"wf_tuple n A (restrict A x')\"\n    using assms(3) by (auto intro!: wf_tuple_restrict_simple)\n  moreover have \"P (restrict A x')\"\n    using \\<open>wf_tuple n A' x'\\<close> \\<open>P x'\\<close> by (rule assms(5))\n  moreover have \"Q (restrict A x')\" and y: \"x' ! y = Some (f (restrict A x'))\"\n    using \\<open>wf_tuple n A' x'\\<close> \\<open>P x'\\<close> \\<open>Q' x'\\<close> by (auto dest!: assms(7))\n  ultimately have \"restrict A x' \\<in> X\" by (intro in_qtableI[OF assms(1)])\n  moreover have \"x' = (restrict A x')[y:=Some (f (restrict A x'))]\"\n    using y assms(2,3) \\<open>wf_tuple n A (restrict A x')\\<close> \\<open>wf_tuple n A' x'\\<close>\n    by (auto simp: list_eq_iff_nth_eq wf_tuple_def nth_list_update nth_restrict)\n  ultimately show \"x' \\<in> ?Y\" by simp\nqed\n\nlemma sat_the_update: \"y \\<notin> fv \\<phi> \\<Longrightarrow> Formula.sat \\<sigma> V (map the (x[y:=z])) i \\<phi> = Formula.sat \\<sigma> V (map the x) i \\<phi>\"\n  by (rule sat_fv_cong) (metis map_update nth_list_update_neq)\n\nlemma progress_constraint: \"progress \\<sigma> P (formula_of_constraint c) j = j\"\n  by (induction rule: formula_of_constraint.induct) simp_all\n\nlemma qtable_filter:\n  assumes \"qtable n A P Q X\"\n    \"\\<And>x. wf_tuple n A x \\<Longrightarrow> P x \\<Longrightarrow> Q x \\<and> R x \\<longleftrightarrow> Q' x\"\n  shows \"qtable n A P Q' (Set.filter R X)\" (is \"qtable _ _ _ _ ?Y\")\nproof (rule qtableI)\n  from assms(1) have \"table n A X\"\n    unfolding qtable_def by simp\n  then show \"table n A ?Y\"\n    unfolding table_def wf_tuple_def by simp\nnext\n  fix x\n  assume \"x \\<in> ?Y\" \"wf_tuple n A x\" \"P x\"\n  with assms show \"Q' x\" by (auto elim!: in_qtableE)\nnext\n  fix x\n  assume \"wf_tuple n A x\" \"P x\" \"Q' x\"\n  with assms show \"x \\<in> Set.filter R X\" by (auto intro!: in_qtableI)\nqed\n\nlemma eval_constraint_sat_eq: \"wf_tuple n A x \\<Longrightarrow> fv_trm t1 \\<subseteq> A \\<Longrightarrow> fv_trm t2 \\<subseteq> A \\<Longrightarrow>\n  \\<forall>i\\<in>A. i < n \\<Longrightarrow> eval_constraint (t1, p, c, t2) x =\n    Formula.sat \\<sigma> V (map the x) i (formula_of_constraint (t1, p, c, t2))\"\n  by (induction \"(t1, p, c, t2)\" rule: formula_of_constraint.induct)\n    (simp_all add: meval_trm_eval_trm)\n\ndeclare progress_le_gen[simp]\n\ndefinition \"wf_envs \\<sigma> j P P' V db =\n  (dom V = dom P \\<and>\n   Mapping.keys db = dom P \\<union> {p. p \\<in> fst ` \\<Gamma> \\<sigma> j} \\<and>\n   rel_mapping (\\<le>) P P' \\<and>\n   pred_mapping (\\<lambda>i. i \\<le> j) P \\<and>\n   pred_mapping (\\<lambda>i. i \\<le> Suc j) P' \\<and>\n   (\\<forall>p \\<in> Mapping.keys db - dom P. the (Mapping.lookup db p) = [{ts. (p, ts) \\<in> \\<Gamma> \\<sigma> j}]) \\<and>\n   (\\<forall>p \\<in> dom P. list_all2 (\\<lambda>i X. X = the (V p) i) [the (P p)..<the (P' p)] (the (Mapping.lookup db p))))\"\n\n\nlift_definition mk_db :: \"(Formula.name \\<times> event_data list) set \\<Rightarrow> Formula.database\" is\n  \"\\<lambda>X p. (if p \\<in> fst ` X then Some [{ts. (p, ts) \\<in> X}] else None)\" .\n\nlemma wf_envs_mk_db: \"wf_envs \\<sigma> j Map.empty Map.empty Map.empty (mk_db (\\<Gamma> \\<sigma> j))\"\n  unfolding wf_envs_def mk_db_def\n  by transfer (force split: if_splits simp: image_iff rel_mapping_alt)\n\nlemma wf_envs_update:\n  assumes wf_envs: \"wf_envs \\<sigma> j P P' V db\"\n    and m_eq: \"m = Formula.nfv \\<phi>\"\n    and in_fv: \"{0 ..< m} \\<subseteq> fv \\<phi>\"\n    and b_le_m: \"b \\<le> m\"\n    and xs: \"list_all2 (\\<lambda>i. qtable m (Formula.fv \\<phi>) (mem_restr UNIV) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>))\n      [progress \\<sigma> P \\<phi> j..<progress \\<sigma> P' \\<phi> (Suc j)] xs\"\n  shows \"wf_envs \\<sigma> j (P(p \\<mapsto> progress \\<sigma> P \\<phi> j)) (P'(p \\<mapsto> progress \\<sigma> P' \\<phi> (Suc j)))\n    (V(p \\<mapsto> \\<lambda>i. {v. length v = m - b \\<and> (\\<exists>zs. length zs = b \\<and> Formula.sat \\<sigma> V (zs @ v) i \\<phi>)}))\n    (Mapping.update p (map (image (drop b o map the)) xs) db)\"\n  unfolding wf_envs_def\nproof (intro conjI ballI, goal_cases)\n  case 3\n  from assms show ?case\n    by (auto simp: wf_envs_def pred_mapping_alt progress_le progress_mono_gen\n        intro!: rel_mapping_map_upd)\nnext\n  case (6 p')\n  with assms show ?case by (cases \"p' \\<in> dom P\") (auto simp: wf_envs_def lookup_update')\nnext\n  case (7 p')\n  from xs have \"list_all2 (\\<lambda>x y. (\\<lambda>x. drop b (map the x)) ` y =\n          {v. length v = m - b \\<and> (\\<exists>zs. length zs = b \\<and> Formula.sat \\<sigma> V (zs @ v) x \\<phi>)})\n      [progress \\<sigma> P \\<phi> j..<progress \\<sigma> P' \\<phi> (Suc j)] xs\"\n  proof (rule list.rel_mono_strong, safe)\n    fix i X\n    assume qtable: \"qtable m (fv \\<phi>) (mem_restr UNIV) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>) X\"\n    {\n      fix v\n      assume \"v \\<in> X\"\n      then show \"length (drop b (map the v)) = m - b\" and\n        \"\\<exists>zs. length zs = b \\<and> Formula.sat \\<sigma> V (zs @ drop b (map the v)) i \\<phi>\"\n        using qtable b_le_m\n        by (auto simp: wf_tuple_def elim!: in_qtableE intro!: exI[of _ \"take b (map the v)\"])\n    }\n    {\n      fix zs v\n      assume \"length v = m - length zs\" and \"Formula.sat \\<sigma> V (zs @ v) i \\<phi>\" and \"b = length zs\"\n      then show \"v \\<in> (\\<lambda>x. drop (length zs) (map the x)) ` X\"\n        using in_fv b_le_m\n        by (auto 0 3 simp: wf_tuple_def nth_append\n            intro!: image_eqI[where x=\"map Some (zs @ v)\"] in_qtableI[OF qtable])\n    }\n  qed\n  moreover have \"list_all2 (\\<lambda>i X. X = the (V p') i) [the (P p')..<the (P' p')] (the (Mapping.lookup db p'))\"\n    if \"p \\<noteq> p'\"\n  proof -\n    from that 7 have \"p' \\<in> dom P\" by simp\n    with wf_envs show ?thesis by (simp add: wf_envs_def)\n  qed\n  ultimately show ?case\n    by (simp add: list.rel_map image_iff lookup_update')\nqed (use assms in \\<open>auto simp: wf_envs_def\\<close>)\n\nlemma wf_envs_P_simps[simp]:\n   \"wf_envs \\<sigma> j P P' V db \\<Longrightarrow> pred_mapping (\\<lambda>i. i \\<le> j) P\"\n   \"wf_envs \\<sigma> j P P' V db \\<Longrightarrow> pred_mapping (\\<lambda>i. i \\<le> Suc j) P'\"\n   \"wf_envs \\<sigma> j P P' V db \\<Longrightarrow> rel_mapping (\\<le>) P P'\"\n  unfolding wf_envs_def by auto\n\nlemma wf_envs_progress_le[simp]:\n   \"wf_envs \\<sigma> j P P' V db \\<Longrightarrow> progress \\<sigma> P \\<phi> j \\<le> j\"\n   \"wf_envs \\<sigma> j P P' V db \\<Longrightarrow> progress \\<sigma> P' \\<phi> (Suc j) \\<le> Suc j\"\n  unfolding wf_envs_def by auto\n\nlemma wf_envs_progress_regex_le[simp]:\n   \"wf_envs \\<sigma> j P P' V db \\<Longrightarrow> progress_regex \\<sigma> P r j \\<le> j\"\n   \"wf_envs \\<sigma> j P P' V db \\<Longrightarrow> progress_regex \\<sigma> P' r (Suc j) \\<le> Suc j\"\n  unfolding wf_envs_def by (auto simp: progress_regex_le)\n\nlemma wf_envs_progress_mono[simp]:\n   \"wf_envs \\<sigma> j P P' V db \\<Longrightarrow> a \\<le> b \\<Longrightarrow> progress \\<sigma> P \\<phi> a \\<le> progress \\<sigma> P' \\<phi> b\"\n  unfolding wf_envs_def\n  by (auto simp: progress_mono_gen)\n\nlemma qtable_wf_tuple_cong: \"qtable n A P Q X \\<Longrightarrow> A = B \\<Longrightarrow> (\\<And>v. wf_tuple n A v \\<Longrightarrow> P v \\<Longrightarrow> Q v = Q' v) \\<Longrightarrow> qtable n B P Q' X\"\n  unfolding qtable_def table_def by blast\n\nlemma (in maux) meval:\n  assumes \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>'\" \"wf_envs \\<sigma> j P P' V db\"\n  shows \"case meval n (\\<tau> \\<sigma> j) db \\<phi> of (xs, \\<phi>\\<^sub>n) \\<Rightarrow> wf_mformula \\<sigma> (Suc j) P' V n R \\<phi>\\<^sub>n \\<phi>' \\<and>\n    list_all2 (\\<lambda>i. qtable n (Formula.fv \\<phi>') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>'))\n    [progress \\<sigma> P \\<phi>' j..<progress \\<sigma> P' \\<phi>' (Suc j)] xs\"\n  using assms\nproof (induction \\<phi> arbitrary: db P P' V n R \\<phi>')\n  case (MRel rel)\n  then show ?case\n    by (cases rule: wf_mformula.cases)\n      (auto simp add: ball_Un intro: wf_mformula.intros table_eq_rel eq_rel_eval_trm\n        in_eq_rel qtable_empty qtable_unit_table intro!: qtableI)\nnext\n  case (MPred e ts)\n  then show ?case\n  proof (cases \"e \\<in> dom P\")\n    case True\n    with MPred(2) have \"e \\<in> Mapping.keys db\" \"e \\<in> dom P'\" \"e \\<in> dom V\"\n      \"list_all2 (\\<lambda>i X. X = the (V e) i) [the (P e)..<the (P' e)]\n         (the (Mapping.lookup db e))\" unfolding wf_envs_def rel_mapping_alt by blast+\n    with MPred(1) True show ?thesis\n      by (cases rule: wf_mformula.cases)\n        (fastforce intro!: wf_mformula.Pred qtableI bexI[where P=\"\\<lambda>x. _ = tabulate x 0 n\", OF refl]\n        elim!: list.rel_mono_strong bexI[rotated] dest: ex_match\n        simp: list.rel_map table_def match_wf_tuple in_these_eq match_eval_trm image_iff\n          list.map_comp keys_dom_lookup)\n  next\n    note MPred(1)\n    moreover\n    case False\n    moreover\n    from False MPred(2) have \"e \\<notin> dom P'\" \"e \\<notin> dom V\"\n      unfolding wf_envs_def rel_mapping_alt by auto\n    moreover\n    from False MPred(2) have *: \"e \\<in> fst ` \\<Gamma> \\<sigma> j \\<longleftrightarrow> e \\<in> Mapping.keys db\"\n      unfolding wf_envs_def by auto\n    from False MPred(2) have\n      \"e \\<in> Mapping.keys db \\<Longrightarrow> Mapping.lookup db e = Some [{ts. (e, ts) \\<in> \\<Gamma> \\<sigma> j}]\"\n      unfolding wf_envs_def keys_dom_lookup by (metis Diff_iff domD option.sel)\n    with * have \"(case Mapping.lookup db e of None \\<Rightarrow> [{}] | Some xs \\<Rightarrow> xs) = [{ts. (e, ts) \\<in> \\<Gamma> \\<sigma> j}]\"\n      by (cases \"e \\<in> fst ` \\<Gamma> \\<sigma> j\") (auto simp: image_iff keys_dom_lookup split: option.splits)\n    ultimately show ?thesis\n      by (cases rule: wf_mformula.cases)\n        (fastforce intro!: wf_mformula.Pred qtableI bexI[where P=\"\\<lambda>x. _ = tabulate x 0 n\", OF refl]\n        elim!: list.rel_mono_strong bexI[rotated] dest: ex_match\n        simp: list.rel_map table_def match_wf_tuple in_these_eq match_eval_trm image_iff list.map_comp)\n  qed\nnext\n  case (MLet p m b \\<phi>1 \\<phi>2)\n  from MLet.prems(1) obtain \\<phi>1' \\<phi>2' where Let: \"\\<phi>' = Formula.Let p b \\<phi>1' \\<phi>2'\" and\n    1: \"wf_mformula \\<sigma> j P V m UNIV \\<phi>1 \\<phi>1'\" and\n    fv: \"m = Formula.nfv \\<phi>1'\" \"{0..<m} \\<subseteq> fv \\<phi>1'\" \"b \\<le> m\" and\n    2: \"wf_mformula \\<sigma> j (P(p \\<mapsto> progress \\<sigma> P \\<phi>1' j))\n      (V(p \\<mapsto> \\<lambda>i. {v. length v = m - b \\<and> (\\<exists>zs. length zs = b \\<and> Formula.sat \\<sigma> V (zs @ v) i \\<phi>1')}))\n      n R \\<phi>2 \\<phi>2'\"\n    by (cases rule: wf_mformula.cases) auto\n  obtain xs \\<phi>1_new where e1: \"meval m (\\<tau> \\<sigma> j) db \\<phi>1 = (xs, \\<phi>1_new)\" and\n      wf1: \"wf_mformula \\<sigma> (Suc j) P' V m UNIV \\<phi>1_new \\<phi>1'\" and\n      res1: \"list_all2 (\\<lambda>i. qtable m (fv \\<phi>1') (mem_restr UNIV) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>1'))\n       [progress \\<sigma> P \\<phi>1' j..<progress \\<sigma> P' \\<phi>1' (Suc j)] xs\"\n    using MLet(1)[OF 1(1) MLet.prems(2)] by (auto simp: eqTrueI[OF mem_restr_UNIV, abs_def])\n  from MLet(2)[OF 2 wf_envs_update[OF MLet.prems(2) fv res1]] wf1 e1 fv\n  show ?case unfolding Let\n    by (auto simp: fun_upd_def intro!: wf_mformula.Let)\nnext\n  case (MAnd A_\\<phi> \\<phi> pos A_\\<psi> \\<psi> buf)\n  from MAnd.prems show ?case\n    by (cases rule: wf_mformula.cases)\n      (auto simp: sat_the_restrict simp del: bin_join.simps\n        dest!: MAnd.IH split: if_splits prod.splits intro!: wf_mformula.And qtable_bin_join\n        elim: mbuf2_take_add'(1) list.rel_mono_strong[OF mbuf2_take_add'(2)])\nnext\n  case (MAndAssign \\<phi> conf)\n  from MAndAssign.prems obtain \\<phi>'' x t \\<psi>'' where\n    wf_envs: \"wf_envs \\<sigma> j P P' V db\" and\n    \\<phi>'_eq: \"\\<phi>' = formula.And \\<phi>'' \\<psi>''\" and\n    wf_\\<phi>: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>''\" and\n    \"x < n\" and\n    \"x \\<notin> fv \\<phi>''\" and\n    fv_t_subset: \"fv_trm t \\<subseteq> fv \\<phi>''\" and\n    conf: \"(x, t) = conf\" and\n    \\<psi>''_eqs: \"\\<psi>'' = formula.Eq (trm.Var x) t \\<or> \\<psi>'' = formula.Eq t (trm.Var x)\"\n    by (cases rule: wf_mformula.cases)\n  from wf_\\<phi> wf_envs obtain xs \\<phi>\\<^sub>n where\n    meval_eq: \"meval n (\\<tau> \\<sigma> j) db \\<phi> = (xs, \\<phi>\\<^sub>n)\" and\n    wf_\\<phi>\\<^sub>n: \"wf_mformula \\<sigma> (Suc j) P' V n R \\<phi>\\<^sub>n \\<phi>''\" and\n    xs: \"list_all2 (\\<lambda>i. qtable n (fv \\<phi>'') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>''))\n        [progress \\<sigma> P \\<phi>'' j..<progress \\<sigma> P' \\<phi>'' (Suc j)] xs\"\n    by (auto dest!: MAndAssign.IH)\n  have progress_eqs:\n      \"progress \\<sigma> P \\<phi>' j = progress \\<sigma> P \\<phi>'' j\"\n      \"progress \\<sigma> P' \\<phi>' (Suc j) = progress \\<sigma> P' \\<phi>'' (Suc j)\"\n    using \\<psi>''_eqs wf_envs_progress_le[OF wf_envs] by (auto simp: \\<phi>'_eq)\n\n  show ?case proof (simp add: meval_eq, intro conjI)\n    show \"wf_mformula \\<sigma> (Suc j) P' V n R (MAndAssign \\<phi>\\<^sub>n conf) \\<phi>'\"\n      unfolding \\<phi>'_eq\n      by (rule wf_mformula.AndAssign) fact+\n  next\n    show \"list_all2 (\\<lambda>i. qtable n (fv \\<phi>') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>'))\n        [progress \\<sigma> P \\<phi>' j..<progress \\<sigma> P' \\<phi>' (Suc j)] (map ((`) (eval_assignment conf)) xs)\"\n      unfolding list.rel_map progress_eqs conf[symmetric] eval_assignment.simps\n      using xs\n    proof (rule list.rel_mono_strong)\n      fix i X\n      assume qtable: \"qtable n (fv \\<phi>'') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>'') X\"\n      then show \"qtable n (fv \\<phi>') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>')\n          ((\\<lambda>y. y[x := Some (meval_trm t y)]) ` X)\"\n      proof (rule qtable_assign)\n        show \"x < n\" by fact\n        show \"insert x (fv \\<phi>'') = fv \\<phi>'\"\n          using \\<psi>''_eqs fv_t_subset by (auto simp: \\<phi>'_eq)\n        show \"x \\<notin> fv \\<phi>''\" by fact\n      next\n        fix v\n        assume wf_v: \"wf_tuple n (fv \\<phi>') v\" and \"mem_restr R v\"\n        then show \"mem_restr R (restrict (fv \\<phi>'') v)\" by simp\n\n        assume sat: \"Formula.sat \\<sigma> V (map the v) i \\<phi>'\"\n        then have A: \"Formula.sat \\<sigma> V (map the (restrict (fv \\<phi>'') v)) i \\<phi>''\" (is ?A)\n          by (simp add: \\<phi>'_eq sat_the_restrict)\n        have \"map the v ! x = Formula.eval_trm (map the v) t\"\n          using sat \\<psi>''_eqs by (auto simp: \\<phi>'_eq)\n        also have \"... = Formula.eval_trm (map the (restrict (fv \\<phi>'') v)) t\"\n          using fv_t_subset by (auto simp: map_the_restrict intro!: eval_trm_fv_cong)\n        finally have \"map the v ! x = meval_trm t (restrict (fv \\<phi>'') v)\"\n          using meval_trm_eval_trm[of n \"fv \\<phi>''\" \"restrict (fv \\<phi>'') v\" t]\n            fv_t_subset wf_v wf_mformula_wf_set[unfolded wf_set_def, OF wf_\\<phi>]\n          by (fastforce simp: \\<phi>'_eq intro!: wf_tuple_restrict)\n        then have B: \"v ! x = Some (meval_trm t (restrict (fv \\<phi>'') v))\" (is ?B)\n          using \\<psi>''_eqs wf_v \\<open>x < n\\<close> by (auto simp: wf_tuple_def \\<phi>'_eq)\n        from A B show \"?A \\<and> ?B\" ..\n      next\n        fix v\n        assume wf_v: \"wf_tuple n (fv \\<phi>'') v\" and \"mem_restr R v\"\n          and sat: \"Formula.sat \\<sigma> V (map the v) i \\<phi>''\"\n        let ?v = \"v[x := Some (meval_trm t v)]\"\n        from sat have A: \"Formula.sat \\<sigma> V (map the ?v) i \\<phi>''\"\n          using \\<open>x \\<notin> fv \\<phi>''\\<close> by (simp add: sat_the_update)\n        have \"y \\<in> fv_trm t \\<Longrightarrow> x \\<noteq> y\" for y\n          using fv_t_subset \\<open>x \\<notin> fv \\<phi>''\\<close> by auto\n        then have B: \"Formula.sat \\<sigma> V (map the ?v) i \\<psi>''\"\n          using \\<psi>''_eqs meval_trm_eval_trm[of n \"fv \\<phi>''\" v t] \\<open>x < n\\<close>\n            fv_t_subset wf_v wf_mformula_wf_set[unfolded wf_set_def, OF wf_\\<phi>]\n          by (auto simp: wf_tuple_def map_update intro!: eval_trm_fv_cong)\n        from A B show \"Formula.sat \\<sigma> V (map the ?v) i \\<phi>'\"\n          by (simp add: \\<phi>'_eq)\n      qed\n    qed\n  qed\nnext\n  case (MAndRel \\<phi> conf)\n  from MAndRel.prems show ?case\n    by (cases rule: wf_mformula.cases)\n      (auto simp: progress_constraint progress_le list.rel_map fv_formula_of_constraint\n        Un_absorb2 wf_mformula_wf_set[unfolded wf_set_def] split: prod.splits\n        dest!: MAndRel.IH[where db=db and P=P and P'=P'] eval_constraint_sat_eq[THEN iffD2]\n        intro!: wf_mformula.AndRel\n        elim!: list.rel_mono_strong qtable_filter eval_constraint_sat_eq[THEN iffD1])\nnext\n  case (MAnds A_pos A_neg l buf)\n  note mbufn_take.simps[simp del] mbufn_add.simps[simp del] mmulti_join.simps[simp del]\n\n  from MAnds.prems obtain pos neg l' where\n    wf_l: \"list_all2 (wf_mformula \\<sigma> j P V n R) l (pos @ map remove_neg neg)\" and\n    wf_buf: \"wf_mbufn (progress \\<sigma> P (formula.Ands l') j) (map (\\<lambda>\\<psi>. progress \\<sigma> P \\<psi> j) (pos @ map remove_neg neg))\n      (map (\\<lambda>\\<psi> i. qtable n (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>)) (pos @ map remove_neg neg)) buf\" and\n    posneg: \"(pos, neg) = partition safe_formula l'\" and\n    \"pos \\<noteq> []\" and\n    safe_neg: \"list_all safe_formula (map remove_neg neg)\" and\n    A_eq: \"A_pos = map fv pos\" \"A_neg = map fv neg\" and\n    fv_subset: \"\\<Union> (set A_neg) \\<subseteq> \\<Union> (set A_pos)\" and\n    \"\\<phi>' = Formula.Ands l'\"\n    by (cases rule: wf_mformula.cases) simp\n  have progress_eq: \"progress \\<sigma> P' (formula.Ands l') (Suc j) =\n      Mini (progress \\<sigma> P (formula.Ands l') j) (map (\\<lambda>\\<psi>. progress \\<sigma> P' \\<psi> (Suc j)) (pos @ map remove_neg neg))\"\n    using \\<open>pos \\<noteq> []\\<close> posneg\n    by (auto simp: Mini_def image_Un[symmetric] Collect_disj_eq[symmetric] intro!: arg_cong[where f=Min])\n\n  have join_ok: \"qtable n (\\<Union> (fv ` set l')) (mem_restr R)\n        (\\<lambda>v. list_all (Formula.sat \\<sigma> V (map the v) k) l')\n        (mmulti_join n A_pos A_neg L)\"\n    if args_ok: \"list_all2 (\\<lambda>x. qtable n (fv x) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) k x))\n        (pos @ map remove_neg neg) L\"\n    for k L\n  proof (rule qtable_mmulti_join)\n    let ?ok = \"\\<lambda>A Qi X. qtable n A (mem_restr R) Qi X \\<and> wf_set n A\"\n    let ?L_pos = \"take (length A_pos) L\"\n    let ?L_neg = \"drop (length A_pos) L\"\n    have 1: \"length pos \\<le> length L\"\n      using args_ok by (auto dest!: list_all2_lengthD)\n    show \"list_all3 ?ok A_pos (map (\\<lambda>\\<psi> v. Formula.sat \\<sigma> V (map the v) k \\<psi>) pos) ?L_pos\"\n      using args_ok wf_l unfolding A_eq\n      by (auto simp add: list_all3_conv_all_nth list_all2_conv_all_nth nth_append\n          split: if_splits intro!: wf_mformula_wf_set[of \\<sigma> j P V n R]\n          dest: order.strict_trans2[OF _ 1])\n    from args_ok have prems_neg: \"list_all2 (\\<lambda>\\<psi>. qtable n (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) k (remove_neg \\<psi>))) neg ?L_neg\"\n      by (auto simp: A_eq list_all2_append1 list.rel_map)\n    show \"list_all3 ?ok A_neg (map (\\<lambda>\\<psi> v. Formula.sat \\<sigma> V (map the v) k (remove_neg \\<psi>)) neg) ?L_neg\"\n      using prems_neg wf_l unfolding A_eq\n      by (auto simp add: list_all3_conv_all_nth list_all2_conv_all_nth list_all_length nth_append less_diff_conv\n          split: if_splits intro!: wf_mformula_wf_set[of \\<sigma> j P V n R _ \"remove_neg _\", simplified])\n    show \"\\<Union>(fv ` set l') = \\<Union>(set A_pos)\"\n      using fv_subset posneg unfolding A_eq by auto\n    show \"L = take (length A_pos) L @ drop (length A_pos) L\" by simp\n    show \"A_pos \\<noteq> []\" using \\<open>pos \\<noteq> []\\<close> A_eq by simp\n\n    fix x :: \"event_data tuple\"\n    assume \"wf_tuple n (\\<Union> (fv ` set l')) x\" and \"mem_restr R x\"\n    then show \"list_all (\\<lambda>A. mem_restr R (restrict A x)) A_pos\"\n      and \"list_all (\\<lambda>A. mem_restr R (restrict A x)) A_neg\"\n      by (simp_all add: list.pred_set)\n\n    have \"list_all Formula.is_Neg neg\"\n      using posneg safe_neg\n      by (auto 0 3 simp add: list.pred_map elim!: list.pred_mono_strong\n          intro: formula.exhaust[of \\<psi> \"Formula.is_Neg \\<psi>\" for \\<psi>])\n    then have \"list_all (\\<lambda>\\<psi>. Formula.sat \\<sigma> V (map the v) i (remove_neg \\<psi>) \\<longleftrightarrow>\n      \\<not> Formula.sat \\<sigma> V (map the v) i \\<psi>) neg\" for v i\n      by (fastforce simp: Formula.is_Neg_def elim!: list.pred_mono_strong)\n    then show \"list_all (Formula.sat \\<sigma> V (map the x) k) l' =\n       (list_all2 (\\<lambda>A Qi. Qi (restrict A x)) A_pos\n         (map (\\<lambda>\\<psi> v. Formula.sat \\<sigma> V (map the v) k \\<psi>) pos) \\<and>\n        list_all2 (\\<lambda>A Qi. \\<not> Qi (restrict A x)) A_neg\n         (map (\\<lambda>\\<psi> v. Formula.sat \\<sigma> V (map the v) k\n                       (remove_neg \\<psi>))\n           neg))\"\n      using posneg\n      by (auto simp add: A_eq list_all2_conv_all_nth list_all_length sat_the_restrict\n          elim: nth_filter nth_partition[where P=safe_formula and Q=\"Formula.sat _ _ _ _\"])\n  qed fact\n\n  from MAnds.prems(2) show ?case\n    unfolding \\<open>\\<phi>' = Formula.Ands l'\\<close>\n    by (auto 0 3 simp add: list.rel_map progress_eq map2_map_map list_all3_map\n        list_all3_list_all2_conv list.pred_map\n        simp del: set_append map_append progress_simps split: prod.splits\n        intro!: wf_mformula.Ands[OF _ _ posneg \\<open>pos \\<noteq> []\\<close> safe_neg A_eq fv_subset]\n        list.rel_mono_strong[OF wf_l] wf_mbufn_add[OF wf_buf]\n        list.rel_flip[THEN iffD1, OF list.rel_mono_strong, OF wf_l]\n        list.rel_refl join_ok[unfolded list.pred_set]\n        dest!: MAnds.IH[OF _ _ MAnds.prems(2), rotated]\n        elim!: wf_mbufn_take list_all2_appendI\n        elim: mbufn_take_induct[OF _ wf_mbufn_add[OF wf_buf]])\nnext\n  case (MOr \\<phi> \\<psi> buf)\n  from MOr.prems show ?case\n    by (cases rule: wf_mformula.cases)\n      (auto dest!: MOr.IH split: if_splits prod.splits intro!: wf_mformula.Or qtable_union\n        elim: mbuf2_take_add'(1) list.rel_mono_strong[OF mbuf2_take_add'(2)])\nnext\n  case (MNeg \\<phi>)\n  have *: \"qtable n {} (mem_restr R) (\\<lambda>v. P v) X \\<Longrightarrow>\n    \\<not> qtable n {} (mem_restr R) (\\<lambda>v. \\<not> P v) empty_table \\<Longrightarrow> x \\<in> X \\<Longrightarrow> False\" for P x X\n    using nullary_qtable_cases qtable_unit_empty_table by fastforce\n  from MNeg.prems show ?case\n    by (cases rule: wf_mformula.cases)\n      (auto 0 4 intro!: wf_mformula.Neg dest!: MNeg.IH\n        simp add: list.rel_map\n        dest: nullary_qtable_cases qtable_unit_empty_table intro!: qtable_empty_unit_table\n        elim!: list.rel_mono_strong elim: *)\nnext\n  case (MExists \\<phi>)\n  from MExists.prems show ?case\n    by (cases rule: wf_mformula.cases)\n      (force simp: list.rel_map fvi_Suc sat_fv_cong nth_Cons'\n        intro!: wf_mformula.Exists dest!: MExists.IH qtable_project_fv\n        elim!: list.rel_mono_strong table_fvi_tl qtable_cong sat_fv_cong[THEN iffD1, rotated -1]\n        split: if_splits)+\nnext\n  case (MAgg g0 y \\<omega> b f \\<phi>)\n  from MAgg.prems show ?case\n    using wf_mformula_wf_set[OF MAgg.prems(1), unfolded wf_set_def]\n    by (cases rule: wf_mformula.cases)\n      (auto 0 3 simp add: list.rel_map simp del: sat.simps fvi.simps split: prod.split\n        intro!: wf_mformula.Agg qtable_eval_agg dest!: MAgg.IH elim!: list.rel_mono_strong)\nnext\n  case (MPrev I \\<phi> first buf nts)\n  from MPrev.prems show ?case\n  proof (cases rule: wf_mformula.cases)\n    case (Prev \\<psi>)\n    let ?xs = \"fst (meval n (\\<tau> \\<sigma> j) db \\<phi>)\"\n    let ?\\<phi> = \"snd (meval n (\\<tau> \\<sigma> j) db \\<phi>)\"\n    let ?ls = \"fst (mprev_next I (buf @ ?xs) (nts @ [\\<tau> \\<sigma> j]))\"\n    let ?rs = \"fst (snd (mprev_next I (buf @ ?xs) (nts @ [\\<tau> \\<sigma> j])))\"\n    let ?ts = \"snd (snd (mprev_next I (buf @ ?xs) (nts @ [\\<tau> \\<sigma> j])))\"\n    let ?P = \"\\<lambda>i X. qtable n (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>) X\"\n    let ?min = \"min (progress \\<sigma> P' \\<psi> (Suc j)) (Suc j - 1)\"\n    from Prev MPrev.IH[OF _ MPrev.prems(2), of n R \\<psi>] have IH: \"wf_mformula \\<sigma> (Suc j) P' V n R ?\\<phi> \\<psi>\" and\n      \"list_all2 ?P [progress \\<sigma> P \\<psi> j..<progress \\<sigma> P' \\<psi> (Suc j)] ?xs\" by auto\n    with Prev(4,5) MPrev.prems(2) have \"list_all2 (\\<lambda>i X. if mem (\\<tau> \\<sigma> (Suc i) - \\<tau> \\<sigma> i) I then ?P i X else X = empty_table)\n        [min (progress \\<sigma> P \\<psi> j) (j - 1)..<?min] ?ls \\<and>\n       list_all2 ?P [?min..<progress \\<sigma> P' \\<psi> (Suc j)] ?rs \\<and>\n       list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [?min..<Suc j] ?ts\"\n      by (intro mprev) (auto intro!: list_all2_upt_append list_all2_appendI order.trans[OF min.cobounded1])\n    moreover have \"min (Suc (progress \\<sigma> P \\<psi> j)) j = Suc (min (progress \\<sigma> P \\<psi> j) (j-1))\" if \"j > 0\"\n      using that by auto\n    ultimately show ?thesis using Prev(1,3) MPrev.prems(2) IH\n      by (auto simp: map_Suc_upt[symmetric] upt_Suc[of 0] list.rel_map qtable_empty_iff\n          simp del: upt_Suc elim!: wf_mformula.Prev list.rel_mono_strong\n          split: prod.split if_split_asm)\n  qed\nnext\n  case (MNext I \\<phi> first nts)\n  from MNext.prems show ?case\n  proof (cases rule: wf_mformula.cases)\n    case (Next \\<psi>)\n\n    have min[simp]:\n      \"min (progress \\<sigma> P \\<psi> j - Suc 0) (j - Suc 0) = progress \\<sigma> P \\<psi> j - Suc 0\"\n      \"min (progress \\<sigma> P' \\<psi> (Suc j) - Suc 0) j = progress \\<sigma> P' \\<psi> (Suc j) - Suc 0\"\n      using wf_envs_progress_le[OF MNext.prems(2), of \\<psi>] by auto\n\n    let ?xs = \"fst (meval n (\\<tau> \\<sigma> j) db \\<phi>)\"\n    let ?ys = \"case (?xs, first) of (_ # xs, True) \\<Rightarrow> xs | _ \\<Rightarrow> ?xs\"\n    let ?\\<phi> = \"snd (meval n (\\<tau> \\<sigma> j) db \\<phi>)\"\n    let ?ls = \"fst (mprev_next I ?ys (nts @ [\\<tau> \\<sigma> j]))\"\n    let ?rs = \"fst (snd (mprev_next I ?ys (nts @ [\\<tau> \\<sigma> j])))\"\n    let ?ts = \"snd (snd (mprev_next I ?ys (nts @ [\\<tau> \\<sigma> j])))\"\n    let ?P = \"\\<lambda>i X. qtable n (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>) X\"\n    let ?min = \"min (progress \\<sigma> P' \\<psi> (Suc j) - 1) (Suc j - 1)\"\n    from Next MNext.IH[OF _ MNext.prems(2), of n R \\<psi>] have IH: \"wf_mformula \\<sigma> (Suc j) P' V  n R ?\\<phi> \\<psi>\"\n      \"list_all2 ?P [progress \\<sigma> P \\<psi> j..<progress \\<sigma> P' \\<psi> (Suc j)] ?xs\" by auto\n    with Next have \"list_all2 (\\<lambda>i X. if mem (\\<tau> \\<sigma> (Suc i) - \\<tau> \\<sigma> i) I then ?P (Suc i) X else X = empty_table)\n        [progress \\<sigma> P \\<psi> j - 1..<?min] ?ls \\<and>\n       list_all2 ?P [Suc ?min..<progress \\<sigma> P' \\<psi> (Suc j)] ?rs \\<and>\n       list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [?min..<Suc j] ?ts\" if \"progress \\<sigma> P \\<psi> j < progress \\<sigma> P' \\<psi> (Suc j)\"\n      using that wf_envs_progress_le[OF MNext.prems(2), of \\<psi>]\n      by (intro mnext) (auto simp: list_all2_Cons2 upt_eq_Cons_conv\n          intro!: list_all2_upt_append list_all2_appendI split: list.splits)\n    then show ?thesis using wf_envs_progress_le[OF MNext.prems(2), of \\<psi>]\n      wf_envs_progress_mono[OF MNext.prems(2), of j \"Suc j\" \\<psi>, simplified] Next IH\n      by (cases \"progress \\<sigma> P' \\<psi> (Suc j) > progress \\<sigma> P \\<psi> j\")\n        (auto 0 3 simp: qtable_empty_iff le_Suc_eq le_diff_conv\n          elim!: wf_mformula.Next list.rel_mono_strong list_all2_appendI\n          split: prod.split list.splits if_split_asm)  (* slow 5 sec*)\n  qed\nnext\n  case (MSince args \\<phi> \\<psi> buf nts aux)\n  note sat.simps[simp del]\n  from MSince.prems obtain \\<phi>'' \\<phi>''' \\<psi>'' I where Since_eq: \"\\<phi>' = Formula.Since \\<phi>''' I \\<psi>''\"\n    and pos: \"if args_pos args then \\<phi>''' = \\<phi>'' else \\<phi>''' = Formula.Neg \\<phi>''\"\n    and pos_eq: \"safe_formula \\<phi>''' = args_pos args\"\n    and \\<phi>: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>''\"\n    and \\<psi>: \"wf_mformula \\<sigma> j P V n R \\<psi> \\<psi>''\"\n    and fvi_subset: \"Formula.fv \\<phi>'' \\<subseteq> Formula.fv \\<psi>''\"\n    and buf: \"wf_mbuf2' \\<sigma> P V j n R \\<phi>'' \\<psi>'' buf\"\n    and nts: \"wf_ts \\<sigma> P j \\<phi>'' \\<psi>'' nts\"\n    and aux: \"wf_since_aux \\<sigma> V R args \\<phi>'' \\<psi>'' aux (progress \\<sigma> P (Formula.Since \\<phi>''' I \\<psi>'') j)\"\n    and args_ivl: \"args_ivl args = I\"\n    and args_n: \"args_n args = n\"\n    and args_L: \"args_L args = Formula.fv \\<phi>''\"\n    and args_R: \"args_R args = Formula.fv \\<psi>''\"\n    by (cases rule: wf_mformula.cases) (auto)\n  have \\<phi>''': \"Formula.fv \\<phi>''' = Formula.fv \\<phi>''\" \"progress \\<sigma> P \\<phi>''' j = progress \\<sigma> P \\<phi>'' j\"\n    \"progress \\<sigma> P' \\<phi>''' j = progress \\<sigma> P' \\<phi>'' j\" for j\n    using pos by (simp_all split: if_splits)\n  from MSince.prems(2) have nts_snoc: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i)\n    [min (progress \\<sigma> P \\<phi>'' j) (progress \\<sigma> P \\<psi>'' j)..<Suc j] (nts @ [\\<tau> \\<sigma> j])\"\n    using nts unfolding wf_ts_def\n    by (auto simp add: wf_envs_progress_le[THEN min.coboundedI1] intro: list_all2_appendI)\n  have update: \"wf_since_aux \\<sigma> V R args \\<phi>'' \\<psi>'' (snd (zs, aux')) (progress \\<sigma> P' (Formula.Since \\<phi>''' I \\<psi>'') (Suc j)) \\<and>\n    list_all2 (\\<lambda>i. qtable n (Formula.fv \\<phi>''' \\<union> Formula.fv \\<psi>'') (mem_restr R)\n      (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (Formula.Since \\<phi>''' I \\<psi>'')))\n      [progress \\<sigma> P (Formula.Since \\<phi>''' I \\<psi>'') j..<progress \\<sigma> P' (Formula.Since \\<phi>''' I \\<psi>'') (Suc j)] (fst (zs, aux'))\"\n    if eval_\\<phi>: \"fst (meval n (\\<tau> \\<sigma> j) db \\<phi>) = xs\"\n      and eval_\\<psi>: \"fst (meval n (\\<tau> \\<sigma> j) db \\<psi>) = ys\"\n      and eq: \"mbuf2t_take (\\<lambda>r1 r2 t (zs, aux).\n        case update_since args r1 r2 t aux of (z, x) \\<Rightarrow> (zs @ [z], x))\n        ([], aux) (mbuf2_add xs ys buf) (nts @ [\\<tau> \\<sigma> j]) = ((zs, aux'), buf', nts')\"\n    for xs ys zs aux' buf' nts'\n    unfolding progress_simps \\<phi>'''\n  proof (rule mbuf2t_take_add_induct'[where j=j and j'=\"Suc j\" and z'=\"(zs, aux')\",\n      OF eq wf_envs_P_simps[OF MSince.prems(2)] buf nts_snoc],\n      goal_cases xs ys _ base step)\n    case xs\n    then show ?case\n      using MSince.IH(1)[OF \\<phi> MSince.prems(2)] eval_\\<phi> by auto\n  next\n    case ys\n    then show ?case\n      using MSince.IH(2)[OF \\<psi> MSince.prems(2)] eval_\\<psi> by auto\n  next\n    case base\n    then show ?case\n      using aux by (simp add: \\<phi>''')\n  next\n    case (step k X Y z)\n    then show ?case\n      using fvi_subset pos\n      by (auto 0 3 simp: args_ivl args_n args_L args_R Un_absorb1\n          elim!: update_since(1) list_all2_appendI dest!: update_since(2)\n          split: prod.split if_splits)\n  qed simp\n  with MSince.IH(1)[OF \\<phi> MSince.prems(2)] MSince.IH(2)[OF \\<psi> MSince.prems(2)] show ?case\n    by (auto 0 3 simp: Since_eq split: prod.split\n        intro: wf_mformula.Since[OF _ _ pos pos_eq args_ivl args_n args_L args_R fvi_subset]\n        elim: mbuf2t_take_add'(1)[OF _ wf_envs_P_simps[OF MSince.prems(2)] buf nts_snoc]\n              mbuf2t_take_add'(2)[OF _ wf_envs_P_simps[OF MSince.prems(2)] buf nts_snoc])\nnext\n  case (MUntil args \\<phi> \\<psi> buf nts aux)\n  note sat.simps[simp del] progress_simps[simp del]\n  from MUntil.prems obtain \\<phi>'' \\<phi>''' \\<psi>'' I where Until_eq: \"\\<phi>' = Formula.Until \\<phi>''' I \\<psi>''\"\n    and pos: \"if args_pos args then \\<phi>''' = \\<phi>'' else \\<phi>''' = Formula.Neg \\<phi>''\"\n    and pos_eq: \"safe_formula \\<phi>''' = args_pos args\"\n    and \\<phi>: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>''\"\n    and \\<psi>: \"wf_mformula \\<sigma> j P V n R \\<psi> \\<psi>''\"\n    and fvi_subset: \"Formula.fv \\<phi>'' \\<subseteq> Formula.fv \\<psi>''\"\n    and buf: \"wf_mbuf2' \\<sigma> P V j n R \\<phi>'' \\<psi>'' buf\"\n    and nts: \"wf_ts \\<sigma> P j \\<phi>'' \\<psi>'' nts\"\n    and aux: \"wf_until_aux \\<sigma> V R args \\<phi>'' \\<psi>'' aux (progress \\<sigma> P (Formula.Until \\<phi>''' I \\<psi>'') j)\"\n    and args_ivl: \"args_ivl args = I\"\n    and args_n: \"args_n args = n\"\n    and args_L: \"args_L args = Formula.fv \\<phi>''\"\n    and args_R: \"args_R args = Formula.fv \\<psi>''\"\n    and length_aux: \"progress \\<sigma> P (Formula.Until \\<phi>''' I \\<psi>'') j + length_muaux args aux =\n      min (progress \\<sigma> P \\<phi>'' j) (progress \\<sigma> P \\<psi>'' j)\"\n    by (cases rule: wf_mformula.cases) (auto)\n  define pos where args_pos: \"pos = args_pos args\"\n  have \\<phi>''': \"progress \\<sigma> P \\<phi>''' j = progress \\<sigma> P \\<phi>'' j\"  \"progress \\<sigma> P' \\<phi>''' j = progress \\<sigma> P' \\<phi>'' j\" for j\n    using pos by (simp_all add: progress.simps split: if_splits)\n  from MUntil.prems(2) have nts_snoc: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i)\n    [min (progress \\<sigma> P \\<phi>'' j) (progress \\<sigma> P \\<psi>'' j)..<Suc j] (nts @ [\\<tau> \\<sigma> j])\"\n    using nts unfolding wf_ts_def\n    by (auto simp add: wf_envs_progress_le[THEN min.coboundedI1] intro: list_all2_appendI)\n  {\n    fix xs ys zs aux' aux'' buf' nts'\n    assume eval_\\<phi>: \"fst (meval n (\\<tau> \\<sigma> j) db \\<phi>) = xs\"\n      and eval_\\<psi>: \"fst (meval n (\\<tau> \\<sigma> j) db \\<psi>) = ys\"\n      and eq1: \"mbuf2t_take (add_new_muaux args) aux (mbuf2_add xs ys buf) (nts @ [\\<tau> \\<sigma> j]) =\n        (aux', buf', nts')\"\n      and eq2: \"eval_muaux args (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # _ \\<Rightarrow> nt) aux' = (zs, aux'')\"\n    define ne where \"ne \\<equiv> progress \\<sigma> P (Formula.Until \\<phi>''' I \\<psi>'') j\"\n    have update1: \"wf_until_aux \\<sigma> V R args \\<phi>'' \\<psi>'' aux' (progress \\<sigma> P (Formula.Until \\<phi>''' I \\<psi>'') j) \\<and>\n      ne + length_muaux args aux' = min (progress \\<sigma> P' \\<phi>''' (Suc j)) (progress \\<sigma> P' \\<psi>'' (Suc j))\"\n      using MUntil.IH(1)[OF \\<phi> MUntil.prems(2)] eval_\\<phi> MUntil.IH(2)[OF \\<psi> MUntil.prems(2)]\n        eval_\\<psi> nts_snoc nts_snoc length_aux aux fvi_subset\n      unfolding \\<phi>'''\n      by (elim mbuf2t_take_add_induct'[where j'=\"Suc j\", OF eq1 wf_envs_P_simps[OF MUntil.prems(2)] buf])\n        (auto simp: args_n args_L args_R ne_def wf_update_until)\n    then obtain cur auxlist' where valid_aux': \"valid_muaux args cur aux' auxlist'\" and\n      cur: \"cur = (if ne + length auxlist' = 0 then 0 else \\<tau> \\<sigma> (ne + length auxlist' - 1))\" and\n      wf_auxlist': \"wf_until_auxlist \\<sigma> V n R pos \\<phi>'' I \\<psi>'' auxlist' (progress \\<sigma> P (Formula.Until \\<phi>''' I \\<psi>'') j)\"\n      unfolding wf_until_aux_def ne_def args_ivl args_n args_pos by auto\n    have length_aux': \"length_muaux args aux' = length auxlist'\"\n      using valid_length_muaux[OF valid_aux'] .\n    have nts': \"wf_ts \\<sigma> P' (Suc j) \\<phi>'' \\<psi>'' nts'\"\n      using MUntil.IH(1)[OF \\<phi> MUntil.prems(2)] eval_\\<phi> MUntil.IH(2)[OF \\<psi> MUntil.prems(2)]\n        MUntil.prems(2) eval_\\<psi> nts_snoc\n      unfolding wf_ts_def\n      by (intro mbuf2t_take_eqD(2)[OF eq1]) (auto intro: wf_mbuf2_add buf[unfolded wf_mbuf2'_def])\n    define zs'' where \"zs'' = fst (eval_until I (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt) auxlist')\"\n    define auxlist'' where \"auxlist'' = snd (eval_until I (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt) auxlist')\"\n    have current_w_le: \"cur \\<le> (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt)\"\n    proof (cases nts')\n      case Nil\n      have p_le: \"min (progress \\<sigma> P' \\<phi>''' (Suc j)) (progress \\<sigma> P' \\<psi>'' (Suc j)) - 1 \\<le> j\"\n        using wf_envs_progress_le[OF MUntil.prems(2)]\n        by (auto simp: min_def le_diff_conv)\n      then show ?thesis\n        unfolding cur conjunct2[OF update1, unfolded length_aux']\n        using Nil by auto\n    next\n      case (Cons nt x)\n      have progress_\\<phi>''': \"progress \\<sigma> P' \\<phi>'' (Suc j) = progress \\<sigma> P' \\<phi>''' (Suc j)\"\n        using pos by (auto simp add: progress.simps split: if_splits)\n      have \"nt = \\<tau> \\<sigma> (min (progress \\<sigma> P' \\<phi>'' (Suc j)) (progress \\<sigma> P' \\<psi>'' (Suc j)))\"\n        using nts'[unfolded wf_ts_def Cons]\n        unfolding list_all2_Cons2 upt_eq_Cons_conv by auto\n      then show ?thesis\n        unfolding cur conjunct2[OF update1, unfolded length_aux'] Cons progress_\\<phi>'''\n        by (auto split: if_splits list.splits intro!: \\<tau>_mono)\n    qed\n    have valid_aux'': \"valid_muaux args cur aux'' auxlist''\"\n      using valid_eval_muaux[OF valid_aux' current_w_le eq2, of zs'' auxlist'']\n      by (auto simp add: args_ivl zs''_def auxlist''_def)\n    have length_aux'': \"length_muaux args aux'' = length auxlist''\"\n      using valid_length_muaux[OF valid_aux''] .\n    have eq2': \"eval_until I (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # _ \\<Rightarrow> nt) auxlist' = (zs, auxlist'')\"\n      using valid_eval_muaux[OF valid_aux' current_w_le eq2, of zs'' auxlist'']\n      by (auto simp add: args_ivl zs''_def auxlist''_def)\n    have length_aux'_aux'': \"length_muaux args aux' = length zs + length_muaux args aux''\"\n      using eval_until_length[OF eq2'] unfolding length_aux' length_aux'' .\n    have \"i \\<le> progress \\<sigma> P' (Formula.Until \\<phi>''' I \\<psi>'') (Suc j) \\<Longrightarrow>\n      wf_until_auxlist \\<sigma> V n R pos \\<phi>'' I \\<psi>'' auxlist' i \\<Longrightarrow>\n      i + length auxlist' = min (progress \\<sigma> P' \\<phi>''' (Suc j)) (progress \\<sigma> P' \\<psi>'' (Suc j)) \\<Longrightarrow>\n      wf_until_auxlist \\<sigma> V n R pos \\<phi>'' I \\<psi>'' auxlist'' (progress \\<sigma> P' (Formula.Until \\<phi>''' I \\<psi>'') (Suc j)) \\<and>\n        i + length zs = progress \\<sigma> P' (Formula.Until \\<phi>''' I \\<psi>'') (Suc j) \\<and>\n        i + length zs + length auxlist'' = min (progress \\<sigma> P' \\<phi>''' (Suc j)) (progress \\<sigma> P' \\<psi>'' (Suc j)) \\<and>\n        list_all2 (\\<lambda>i. qtable n (Formula.fv \\<psi>'') (mem_restr R)\n          (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (Formula.Until (if pos then \\<phi>'' else Formula.Neg \\<phi>'') I \\<psi>'')))\n          [i..<i + length zs] zs\" for i\n      using eq2'\n    proof (induction auxlist' arbitrary: zs auxlist'' i)\n      case Nil\n      then show ?case\n        by (auto dest!: antisym[OF progress_Until_le])\n    next\n      case (Cons a aux')\n      obtain t a1 a2 where \"a = (t, a1, a2)\" by (cases a)\n      from Cons.prems(2) have aux': \"wf_until_auxlist \\<sigma> V n R pos \\<phi>'' I \\<psi>'' aux' (Suc i)\"\n        by (rule wf_until_aux_Cons)\n      from Cons.prems(2) have 1: \"t = \\<tau> \\<sigma> i\"\n        unfolding \\<open>a = (t, a1, a2)\\<close> by (rule wf_until_aux_Cons1)\n      from Cons.prems(2) have 3: \"qtable n (Formula.fv \\<psi>'') (mem_restr R) (\\<lambda>v.\n        (\\<exists>j\\<ge>i. j < Suc (i + length aux') \\<and> mem (\\<tau> \\<sigma> j - \\<tau> \\<sigma> i) I \\<and> Formula.sat \\<sigma> V (map the v) j \\<psi>'' \\<and>\n        (\\<forall>k\\<in>{i..<j}. if pos then Formula.sat \\<sigma> V (map the v) k \\<phi>'' else \\<not> Formula.sat \\<sigma> V (map the v) k \\<phi>''))) a2\"\n        unfolding \\<open>a = (t, a1, a2)\\<close> by (rule wf_until_aux_Cons3)\n      from Cons.prems(3) have Suc_i_aux': \"Suc i + length aux' =\n          min (progress \\<sigma> P' \\<phi>''' (Suc j)) (progress \\<sigma> P' \\<psi>'' (Suc j))\"\n        by simp\n      have \"i \\<ge> progress \\<sigma> P' (Formula.Until \\<phi>''' I \\<psi>'') (Suc j)\"\n        if \"enat (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt) \\<le> enat t + right I\"\n        using that nts' unfolding wf_ts_def progress.simps\n        by (auto simp add: 1 list_all2_Cons2 upt_eq_Cons_conv \\<phi>'''\n            intro!: cInf_lower \\<tau>_mono elim!: order.trans[rotated] simp del: upt_Suc split: if_splits list.splits)\n      moreover\n      have \"Suc i \\<le> progress \\<sigma> P' (Formula.Until \\<phi>''' I \\<psi>'') (Suc j)\"\n        if \"enat t + right I < enat (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt)\"\n      proof -\n        from that obtain m where m: \"right I = enat m\" by (cases \"right I\") auto\n        have \\<tau>_min:  \"\\<tau> \\<sigma> (min j k) = min (\\<tau> \\<sigma> j) (\\<tau> \\<sigma> k)\" for k\n          by (simp add: min_of_mono monoI)\n        have le_progress_iff[simp]: \"(Suc j) \\<le> progress \\<sigma> P' \\<phi> (Suc j) \\<longleftrightarrow> progress \\<sigma> P' \\<phi> (Suc j) = (Suc j)\" for \\<phi>\n          using wf_envs_progress_le[OF MUntil.prems(2), of \\<phi>] by auto\n        have min_Suc[simp]: \"min j (Suc j) = j\" by auto\n        let ?X = \"{i. \\<forall>k. k < Suc j \\<and> k \\<le>min (progress \\<sigma> P' \\<phi>''' (Suc j)) (progress \\<sigma> P' \\<psi>'' (Suc j)) \\<longrightarrow> enat (\\<tau> \\<sigma> k) \\<le> enat (\\<tau> \\<sigma> i) + right I}\"\n        let ?min = \"min j (min (progress \\<sigma> P' \\<phi>'' (Suc j)) (progress \\<sigma> P' \\<psi>'' (Suc j)))\"\n        have \"\\<tau> \\<sigma> ?min \\<le> \\<tau> \\<sigma> j\"\n          by (rule \\<tau>_mono) auto\n        from m have \"?X \\<noteq> {}\"\n          by (auto dest!: \\<tau>_mono[of _ \"progress \\<sigma> P' \\<phi>'' (Suc j)\" \\<sigma>]\n              simp: not_le not_less \\<phi>''' intro!: exI[of _ \"progress \\<sigma> P' \\<phi>'' (Suc j)\"])\n        from m show ?thesis\n          using that nts' unfolding wf_ts_def progress.simps\n          by (intro cInf_greatest[OF \\<open>?X \\<noteq> {}\\<close>])\n            (auto simp: 1 \\<phi>''' not_le not_less list_all2_Cons2 upt_eq_Cons_conv less_Suc_eq\n              simp del: upt_Suc split: list.splits if_splits\n              dest!: spec[of _ \"?min\"] less_le_trans[of \"\\<tau> \\<sigma> i + m\" \"\\<tau> \\<sigma> _\" \"\\<tau> \\<sigma> _ + m\"] less_\\<tau>D)\n      qed\n      moreover have *: \"k < progress \\<sigma> P' \\<psi> (Suc j)\" if\n        \"enat (\\<tau> \\<sigma> i) + right I < enat (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt)\"\n        \"enat (\\<tau> \\<sigma> k - \\<tau> \\<sigma> i) \\<le> right I\" \"\\<psi> = \\<psi>'' \\<or> \\<psi> = \\<phi>''\" for k \\<psi>\n      proof -\n        from that(1,2) obtain m where \"right I = enat m\"\n          \"\\<tau> \\<sigma> i + m < (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt)\" \"\\<tau> \\<sigma> k - \\<tau> \\<sigma> i \\<le> m\"\n          by (cases \"right I\") auto\n        with that(3) nts' progress_le[of \\<sigma> \\<psi>'' \"Suc j\"] progress_le[of \\<sigma> \\<phi>'' \"Suc j\"]\n        show ?thesis\n          unfolding wf_ts_def le_diff_conv\n          by (auto simp: not_le list_all2_Cons2 upt_eq_Cons_conv less_Suc_eq add.commute\n              simp del: upt_Suc split: list.splits if_splits dest!: le_less_trans[of \"\\<tau> \\<sigma> k\"] less_\\<tau>D)\n      qed\n      ultimately show ?case using Cons.prems Suc_i_aux'[simplified]\n        unfolding \\<open>a = (t, a1, a2)\\<close>\n        by (auto simp: \\<phi>''' 1 sat.simps upt_conv_Cons dest!:  Cons.IH[OF _ aux' Suc_i_aux']\n            simp del: upt_Suc split: if_splits prod.splits intro!: iff_exI qtable_cong[OF 3 refl])\n    qed\n    thm this\n    note wf_aux'' = this[OF wf_envs_progress_mono[OF MUntil.prems(2) le_SucI[OF order_refl]]\n      wf_auxlist' conjunct2[OF update1, unfolded ne_def length_aux']]\n    have \"progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j + length auxlist' =\n      progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (Suc j) + length auxlist''\"\n      using wf_aux'' valid_aux'' length_aux'_aux''\n      by (auto simp add: ne_def length_aux' length_aux'')\n    then have \"cur =\n      (if progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (Suc j) + length auxlist'' = 0 then 0\n      else \\<tau> \\<sigma> (progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (Suc j) + length auxlist'' - 1))\"\n      unfolding cur ne_def by auto\n    then have \"wf_until_aux \\<sigma> V R args \\<phi>'' \\<psi>'' aux'' (progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (Suc j)) \\<and>\n      progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j + length zs = progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (Suc j) \\<and>\n      progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j + length zs + length_muaux args aux'' = min (progress \\<sigma> P' \\<phi>''' (Suc j)) (progress \\<sigma> P' \\<psi>'' (Suc j)) \\<and>\n      list_all2 (\\<lambda>i. qtable n (fv \\<psi>'') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (formula.Until (if pos then \\<phi>'' else formula.Neg \\<phi>'') I \\<psi>'')))\n      [progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j..<progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j + length zs] zs\"\n      using wf_aux'' valid_aux'' fvi_subset\n      unfolding wf_until_aux_def length_aux'' args_ivl args_n args_pos by (auto simp only: length_aux'')\n  }\n  note update = this\n  from MUntil.IH(1)[OF \\<phi> MUntil.prems(2)] MUntil.IH(2)[OF \\<psi> MUntil.prems(2)] pos pos_eq fvi_subset show ?case\n    by (auto 0 4 simp: args_ivl args_n args_pos Until_eq \\<phi>''' progress.simps(6) split: prod.split if_splits\n        dest!: update[OF refl refl, rotated]\n        intro!: wf_mformula.Until[OF _ _ _ _ args_ivl args_n args_L args_R fvi_subset]\n        elim!: list.rel_mono_strong qtable_cong\n        elim: mbuf2t_take_add'(1)[OF _ wf_envs_P_simps[OF MUntil.prems(2)] buf nts_snoc]\n              mbuf2t_take_add'(2)[OF _ wf_envs_P_simps[OF MUntil.prems(2)] buf nts_snoc])\nnext\n  case (MMatchP I mr mrs \\<phi>s buf nts aux)\n  note sat.simps[simp del] mbufnt_take.simps[simp del] mbufn_add.simps[simp del]\n  from MMatchP.prems obtain r \\<psi>s where eq: \"\\<phi>' = Formula.MatchP I r\"\n    and safe: \"safe_regex Past Strict r\"\n    and mr: \"to_mregex r = (mr, \\<psi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (RPDs mr)\"\n    and \\<psi>s: \"list_all2 (wf_mformula \\<sigma> j P V n R) \\<phi>s \\<psi>s\"\n    and buf: \"wf_mbufn' \\<sigma> P V j n R r buf\"\n    and nts: \"wf_ts_regex \\<sigma> P j r nts\"\n    and aux: \"wf_matchP_aux \\<sigma> V n R I r aux (progress \\<sigma> P (Formula.MatchP I r) j)\"\n    by (cases rule: wf_mformula.cases) (auto)\n  have nts_snoc: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [progress_regex \\<sigma> P r j..<Suc j] (nts @ [\\<tau> \\<sigma> j])\"\n    using nts unfolding wf_ts_regex_def\n    by (auto simp add: wf_envs_progress_regex_le[OF MMatchP.prems(2)] intro: list_all2_appendI)\n  have update: \"wf_matchP_aux \\<sigma> V n R I r (snd (zs, aux')) (progress \\<sigma> P' (Formula.MatchP I r) (Suc j)) \\<and>\n    list_all2 (\\<lambda>i. qtable n (Formula.fv_regex r) (mem_restr R)\n      (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (Formula.MatchP I r)))\n      [progress \\<sigma> P (Formula.MatchP I r) j..<progress \\<sigma> P' (Formula.MatchP I r) (Suc j)] (fst (zs, aux'))\"\n    if eval: \"map (fst o meval n (\\<tau> \\<sigma> j) db) \\<phi>s = xss\"\n      and eq: \"mbufnt_take (\\<lambda>rels t (zs, aux).\n        case update_matchP n I mr mrs rels t aux of (z, x) \\<Rightarrow> (zs @ [z], x))\n        ([], aux) (mbufn_add xss buf) (nts @ [\\<tau> \\<sigma> j]) = ((zs, aux'), buf', nts')\"\n    for xss zs aux' buf' nts'\n    unfolding progress_simps\n  proof (rule mbufnt_take_add_induct'[where j'=\"Suc j\" and z'=\"(zs, aux')\", OF eq wf_envs_P_simps[OF MMatchP.prems(2)] safe mr buf nts_snoc],\n      goal_cases xss _ base step)\n    case xss\n    then show ?case\n      using eval \\<psi>s\n      by (auto simp: list_all3_map map2_map_map list_all3_list_all2_conv list.rel_map\n          list.rel_flip[symmetric, of _ \\<psi>s \\<phi>s] dest!: MMatchP.IH(1)[OF _ _ MMatchP.prems(2)]\n          elim!: list.rel_mono_strong split: prod.splits)\n  next\n    case base\n    then show ?case\n      using aux by auto\n  next\n    case (step k Xs z)\n    then show ?case\n      by (auto simp: Un_absorb1 mrs safe mr elim!: update_matchP(1) list_all2_appendI\n          dest!: update_matchP(2) split: prod.split)\n  qed simp\n  then show ?case using \\<psi>s\n    by (auto simp: eq mr mrs safe map_split_alt list.rel_flip[symmetric, of _ \\<psi>s \\<phi>s]\n        list_all3_map map2_map_map list_all3_list_all2_conv list.rel_map intro!: wf_mformula.intros\n        elim!: list.rel_mono_strong mbufnt_take_add'(1)[OF _ wf_envs_P_simps[OF MMatchP.prems(2)] safe mr buf nts_snoc]\n        mbufnt_take_add'(2)[OF _ wf_envs_P_simps[OF MMatchP.prems(2)] safe mr buf nts_snoc]\n        dest!: MMatchP.IH[OF _ _ MMatchP.prems(2)] split: prod.splits)\nnext\n  case (MMatchF I mr mrs \\<phi>s buf nts aux)\n  note sat.simps[simp del] mbufnt_take.simps[simp del] mbufn_add.simps[simp del] progress_simps[simp del]\n  from MMatchF.prems obtain r \\<psi>s where eq: \"\\<phi>' = Formula.MatchF I r\"\n    and safe: \"safe_regex Futu Strict r\"\n    and mr: \"to_mregex r = (mr, \\<psi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (LPDs mr)\"\n    and \\<psi>s: \"list_all2 (wf_mformula \\<sigma> j P V n R) \\<phi>s \\<psi>s\"\n    and buf: \"wf_mbufn' \\<sigma> P V j n R r buf\"\n    and nts: \"wf_ts_regex \\<sigma> P j r nts\"\n    and aux: \"wf_matchF_aux \\<sigma> V n R I r aux (progress \\<sigma> P (Formula.MatchF I r) j) 0\"\n    and length_aux: \"progress \\<sigma> P (Formula.MatchF I r) j + length aux = progress_regex \\<sigma> P r j\"\n    by (cases rule: wf_mformula.cases) (auto)\n  have nts_snoc: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i)\n    [progress_regex \\<sigma> P r j..<Suc j] (nts @ [\\<tau> \\<sigma> j])\"\n    using nts unfolding wf_ts_regex_def\n    by (auto simp add: wf_envs_progress_regex_le[OF MMatchF.prems(2)] intro: list_all2_appendI)\n  {\n    fix xss zs aux' aux'' buf' nts'\n    assume eval: \"map (fst o meval n (\\<tau> \\<sigma> j) db) \\<phi>s = xss\"\n      and eq1: \"mbufnt_take (update_matchF n I mr mrs) aux (mbufn_add xss buf) (nts @ [\\<tau> \\<sigma> j]) =\n        (aux', buf', nts')\"\n      and eq2: \"eval_matchF I mr (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # _ \\<Rightarrow> nt) aux' = (zs, aux'')\"\n    have update1: \"wf_matchF_aux \\<sigma> V n R I r aux' (progress \\<sigma> P (Formula.MatchF I r) j) 0 \\<and>\n      progress \\<sigma> P (Formula.MatchF I r) j + length aux' = progress_regex \\<sigma> P' r (Suc j)\"\n      using eval nts_snoc nts_snoc length_aux aux \\<psi>s\n      by (elim mbufnt_take_add_induct'[where j'=\"Suc j\", OF eq1 wf_envs_P_simps[OF MMatchF.prems(2)] safe mr buf])\n        (auto simp: length_update_matchF\n          list_all3_map map2_map_map list_all3_list_all2_conv list.rel_map list.rel_flip[symmetric, of _ \\<psi>s \\<phi>s]\n          dest!: MMatchF.IH[OF _ _ MMatchF.prems(2)]\n          elim: wf_update_matchF[OF _ safe mr mrs] elim!: list.rel_mono_strong)\n    from MMatchF.prems(2) have nts': \"wf_ts_regex \\<sigma> P' (Suc j) r nts'\"\n      using eval eval nts_snoc \\<psi>s\n      unfolding wf_ts_regex_def\n      by (intro mbufnt_take_eqD(2)[OF eq1 wf_mbufn_add[where js'=\"map (\\<lambda>\\<phi>. progress \\<sigma> P' \\<phi> (Suc j)) \\<psi>s\",\n              OF buf[unfolded wf_mbufn'_def mr prod.case]]])\n        (auto simp: to_mregex_progress[OF safe mr] Mini_def\n          list_all3_map map2_map_map list_all3_list_all2_conv list.rel_map list.rel_flip[symmetric, of _ \\<psi>s \\<phi>s]\n          list_all2_Cons1 elim!: list.rel_mono_strong intro!: list.rel_refl_strong\n          dest!: MMatchF.IH[OF _ _ MMatchF.prems(2)])\n    have \"i \\<le> progress \\<sigma> P' (Formula.MatchF I r) (Suc j) \\<Longrightarrow>\n      wf_matchF_aux \\<sigma> V n R I r aux' i 0 \\<Longrightarrow>\n      i + length aux' = progress_regex \\<sigma> P' r (Suc j) \\<Longrightarrow>\n      wf_matchF_aux \\<sigma> V n R I r aux'' (progress \\<sigma> P' (Formula.MatchF I r) (Suc j)) 0 \\<and>\n        i + length zs = progress \\<sigma> P' (Formula.MatchF I r) (Suc j) \\<and>\n        i + length zs + length aux'' = progress_regex \\<sigma> P' r (Suc j) \\<and>\n        list_all2 (\\<lambda>i. qtable n (Formula.fv_regex r) (mem_restr R)\n          (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (Formula.MatchF I r)))\n          [i..<i + length zs] zs\" for i\n      using eq2\n    proof (induction aux' arbitrary: zs aux'' i)\n      case Nil\n      then show ?case by (auto dest!: antisym[OF progress_MatchF_le])\n    next\n      case (Cons a aux')\n      obtain t rels rel where \"a = (t, rels, rel)\" by (cases a)\n      from Cons.prems(2) have aux': \"wf_matchF_aux \\<sigma> V n R I r aux' (Suc i) 0\"\n        by (rule wf_matchF_aux_Cons)\n      from Cons.prems(2) have 1: \"t = \\<tau> \\<sigma> i\"\n        unfolding \\<open>a = (t, rels, rel)\\<close> by (rule wf_matchF_aux_Cons1)\n      from Cons.prems(2) have 3: \"qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v.\n        (\\<exists>j\\<ge>i. j < Suc (i + length aux') \\<and> mem (\\<tau> \\<sigma> j - \\<tau> \\<sigma> i) I \\<and> Regex.match (Formula.sat \\<sigma> V (map the v)) r i j)) rel\"\n        unfolding \\<open>a = (t, rels, rel)\\<close> using wf_matchF_aux_Cons3 by force\n      from Cons.prems(3) have Suc_i_aux': \"Suc i + length aux' = progress_regex \\<sigma> P' r (Suc j)\"\n        by simp\n      have \"i \\<ge> progress \\<sigma> P' (Formula.MatchF I r) (Suc j)\"\n        if \"enat (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt) \\<le> enat t + right I\"\n        using that nts' unfolding wf_ts_regex_def progress_simps\n        by (auto simp add: 1 list_all2_Cons2 upt_eq_Cons_conv\n            intro!: cInf_lower \\<tau>_mono elim!: order.trans[rotated] simp del: upt_Suc split: if_splits list.splits)\n      moreover\n      have \"Suc i \\<le> progress \\<sigma> P' (Formula.MatchF I r) (Suc j)\"\n        if \"enat t + right I < enat (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt)\"\n      proof -\n        from that obtain m where m: \"right I = enat m\" by (cases \"right I\") auto\n        have \\<tau>_min:  \"\\<tau> \\<sigma> (min j k) = min (\\<tau> \\<sigma> j) (\\<tau> \\<sigma> k)\" for k\n          by (simp add: min_of_mono monoI)\n        have le_progress_iff[simp]: \"Suc j \\<le> progress \\<sigma> P' \\<phi> (Suc j) \\<longleftrightarrow> progress \\<sigma> P' \\<phi> (Suc j) = (Suc j)\" for \\<phi>\n          using wf_envs_progress_le[OF MMatchF.prems(2), of \\<phi>] by auto\n        have min_Suc[simp]: \"min j (Suc j) = j\" by auto\n        let ?X = \"{i. \\<forall>k. k < Suc j \\<and> k \\<le> progress_regex \\<sigma> P' r (Suc j) \\<longrightarrow> enat (\\<tau> \\<sigma> k) \\<le> enat (\\<tau> \\<sigma> i) + right I}\"\n        let ?min = \"min j (progress_regex \\<sigma> P' r (Suc j))\"\n        have \"\\<tau> \\<sigma> ?min \\<le> \\<tau> \\<sigma> j\"\n          by (rule \\<tau>_mono) auto\n        from m have \"?X \\<noteq> {}\"\n          by (auto dest!: less_\\<tau>D add_lessD1 simp: not_le not_less)\n        from m show ?thesis\n          using that nts' wf_envs_progress_regex_le[OF MMatchF.prems(2), of r]\n          unfolding wf_ts_regex_def progress_simps\n          by (intro cInf_greatest[OF \\<open>?X \\<noteq> {}\\<close>])\n            (auto simp: 1 not_le not_less list_all2_Cons2 upt_eq_Cons_conv less_Suc_eq\n              simp del: upt_Suc split: list.splits if_splits\n              dest!: spec[of _ \"?min\"] less_le_trans[of \"\\<tau> \\<sigma> i + m\" \"\\<tau> \\<sigma> _\" \"\\<tau> \\<sigma> _ + m\"] less_\\<tau>D)\n      qed\n      moreover have *: \"k < progress_regex \\<sigma> P' r (Suc j)\" if\n        \"enat (\\<tau> \\<sigma> i) + right I < enat (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt)\"\n        \"enat (\\<tau> \\<sigma> k - \\<tau> \\<sigma> i) \\<le> right I\" for k\n      proof -\n        from that(1,2) obtain m where \"right I = enat m\"\n          \"\\<tau> \\<sigma> i + m < (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt)\" \"\\<tau> \\<sigma> k - \\<tau> \\<sigma> i \\<le> m\"\n          by (cases \"right I\") auto\n        with nts' wf_envs_progress_regex_le[OF MMatchF.prems(2), of r]\n        show ?thesis\n          unfolding wf_ts_regex_def le_diff_conv\n          by (auto simp: not_le list_all2_Cons2 upt_eq_Cons_conv less_Suc_eq add.commute\n              simp del: upt_Suc split: list.splits if_splits dest!: le_less_trans[of \"\\<tau> \\<sigma> k\"] less_\\<tau>D)\n      qed\n      ultimately show ?case using Cons.prems Suc_i_aux'[simplified]\n        unfolding \\<open>a = (t, rels, rel)\\<close>\n        by (auto simp: 1 sat.simps upt_conv_Cons dest!:  Cons.IH[OF _ aux' Suc_i_aux']\n            simp del: upt_Suc split: if_splits prod.splits intro!: iff_exI qtable_cong[OF 3 refl])\n\n    qed\n    note this[OF progress_mono_gen[OF le_SucI, OF order.refl] conjunct1[OF update1] conjunct2[OF update1]]\n  }\n  note update = this[OF refl, rotated]\n  with MMatchF.prems(2) show ?case using \\<psi>s\n    by (auto simp: eq mr mrs safe map_split_alt list.rel_flip[symmetric, of _ \\<psi>s \\<phi>s]\n        list_all3_map map2_map_map list_all3_list_all2_conv list.rel_map intro!: wf_mformula.intros\n        elim!: list.rel_mono_strong mbufnt_take_add'(1)[OF _ wf_envs_P_simps[OF MMatchF.prems(2)] safe mr buf nts_snoc]\n        mbufnt_take_add'(2)[OF _ wf_envs_P_simps[OF MMatchF.prems(2)] safe mr buf nts_snoc]\n        dest!: MMatchF.IH[OF _ _ MMatchF.prems(2)] update split: prod.splits)\nqed\n\n\nsubsubsection \\<open>Monitor step\\<close>\n\nlemma (in maux) wf_mstate_mstep: \"wf_mstate \\<phi> \\<pi> R st \\<Longrightarrow> last_ts \\<pi> \\<le> snd tdb \\<Longrightarrow>\n  wf_mstate \\<phi> (psnoc \\<pi> tdb) R (snd (mstep (map_prod mk_db id tdb) st))\"\n  unfolding wf_mstate_def mstep_def Let_def\n  by (fastforce simp add: progress_mono le_imp_diff_is_add split: prod.splits\n      elim!: prefix_of_psnocE dest: meval[OF _ wf_envs_mk_db] list_all2_lengthD)\n\ndefinition \"flatten_verdicts Vs = (\\<Union> (set (map (\\<lambda>(i, X). (\\<lambda>v. (i, v)) ` X) Vs)))\"\n\nlemma flatten_verdicts_append[simp]:\n  \"flatten_verdicts (Vs @ Us) = flatten_verdicts Vs \\<union> flatten_verdicts Us\"\n  by (induct Vs) (auto simp: flatten_verdicts_def)\n\nlemma (in maux) mstep_output_iff:\n  assumes \"wf_mstate \\<phi> \\<pi> R st\" \"last_ts \\<pi> \\<le> snd tdb\" \"prefix_of (psnoc \\<pi> tdb) \\<sigma>\" \"mem_restr R v\"\n  shows \"(i, v) \\<in> flatten_verdicts (fst (mstep (map_prod mk_db id tdb) st)) \\<longleftrightarrow>\n    progress \\<sigma> Map.empty \\<phi> (plen \\<pi>) \\<le> i \\<and> i < progress \\<sigma> Map.empty \\<phi> (Suc (plen \\<pi>)) \\<and>\n    wf_tuple (Formula.nfv \\<phi>) (Formula.fv \\<phi>) v \\<and> Formula.sat \\<sigma> Map.empty (map the v) i \\<phi>\"\nproof -\n  from prefix_of_psnocE[OF assms(3,2)] have \"prefix_of \\<pi> \\<sigma>\"\n    \"\\<Gamma> \\<sigma> (plen \\<pi>) = fst tdb\" \"\\<tau> \\<sigma> (plen \\<pi>) = snd tdb\" by auto\n  moreover from assms(1) \\<open>prefix_of \\<pi> \\<sigma>\\<close> have \"mstate_n st = Formula.nfv \\<phi>\"\n    \"mstate_i st = progress \\<sigma> Map.empty \\<phi> (plen \\<pi>)\" \"wf_mformula \\<sigma> (plen \\<pi>) Map.empty Map.empty (mstate_n st) R (mstate_m st) \\<phi>\"\n    unfolding wf_mstate_def by blast+\n  moreover from meval[OF \\<open>wf_mformula \\<sigma> (plen \\<pi>) Map.empty Map.empty (mstate_n st) R (mstate_m st) \\<phi>\\<close> wf_envs_mk_db] obtain Vs st' where\n    \"meval (mstate_n st) (\\<tau> \\<sigma> (plen \\<pi>)) (mk_db (\\<Gamma> \\<sigma> (plen \\<pi>))) (mstate_m st) = (Vs, st')\"\n    \"wf_mformula \\<sigma> (Suc (plen \\<pi>))  Map.empty Map.empty (mstate_n st) R st' \\<phi>\"\n    \"list_all2 (\\<lambda>i. qtable (mstate_n st) (fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> Map.empty (map the v) i \\<phi>))\n      [progress \\<sigma> Map.empty \\<phi> (plen \\<pi>)..<progress \\<sigma> Map.empty \\<phi> (Suc (plen \\<pi>))] Vs\" by blast\n  moreover from this assms(4) have \"qtable (mstate_n st) (fv \\<phi>) (mem_restr R)\n    (\\<lambda>v. Formula.sat \\<sigma> Map.empty (map the v) i \\<phi>) (Vs ! (i - progress \\<sigma> Map.empty \\<phi> (plen \\<pi>)))\"\n    if \"progress \\<sigma> Map.empty \\<phi> (plen \\<pi>) \\<le> i\" \"i < progress \\<sigma> Map.empty \\<phi> (Suc (plen \\<pi>))\"\n    using that by (auto simp: list_all2_conv_all_nth\n        dest!: spec[of _ \"(i - progress \\<sigma> Map.empty \\<phi> (plen \\<pi>))\"])\n  ultimately show ?thesis\n    using assms(4) unfolding mstep_def Let_def flatten_verdicts_def\n    by (auto simp: in_set_enumerate_eq list_all2_conv_all_nth progress_mono le_imp_diff_is_add\n        elim!: in_qtableE in_qtableI intro!: bexI[of _ \"(i, Vs ! (i - progress \\<sigma> Map.empty \\<phi> (plen \\<pi>)))\"])\nqed\n\n\nsubsubsection \\<open>Monitor function\\<close>\n\ncontext maux\nbegin\n\ndefinition minit_safe where\n  \"minit_safe \\<phi> = (if mmonitorable_exec \\<phi> then minit \\<phi> else undefined)\"\n\nlemma minit_safe_minit: \"mmonitorable \\<phi> \\<Longrightarrow> minit_safe \\<phi> = minit \\<phi>\"\n  unfolding minit_safe_def monitorable_formula_code by simp\n\nlemma mstep_mverdicts:\n  assumes wf: \"wf_mstate \\<phi> \\<pi> R st\"\n    and le[simp]: \"last_ts \\<pi> \\<le> snd tdb\"\n    and restrict: \"mem_restr R v\"\n  shows \"(i, v) \\<in> flatten_verdicts (fst (mstep (map_prod mk_db id tdb) st)) \\<longleftrightarrow>\n    (i, v) \\<in> mverdicts \\<phi> (psnoc \\<pi> tdb) - mverdicts \\<phi> \\<pi>\"\nproof -\n  obtain \\<sigma> where p2: \"prefix_of (psnoc \\<pi> tdb) \\<sigma>\"\n    using ex_prefix_of by blast\n  with le have p1: \"prefix_of \\<pi> \\<sigma>\" by (blast elim!: prefix_of_psnocE)\n  show ?thesis\n    unfolding verimon.verdicts_def\n    by (auto 0 3 simp: p2 progress_prefix_conv[OF _ p1] sat_prefix_conv[OF _ p1] not_less\n        dest:  mstep_output_iff[OF wf le p2 restrict, THEN iffD1] spec[of _ \\<sigma>]\n        mstep_output_iff[OF wf le _ restrict, THEN iffD1] verimon.progress_sat_cong[OF p1]\n        intro: mstep_output_iff[OF wf le p2 restrict, THEN iffD2] p1)\nqed\n\nprimrec msteps0 where\n  \"msteps0 [] st = ([], st)\"\n| \"msteps0 (tdb # \\<pi>) st =\n    (let (V', st') = mstep (map_prod mk_db id tdb) st; (V'', st'') = msteps0 \\<pi> st' in (V' @ V'', st''))\"\n\nprimrec msteps0_stateless where\n  \"msteps0_stateless [] st = []\"\n| \"msteps0_stateless (tdb # \\<pi>) st = (let (V', st') = mstep (map_prod mk_db id tdb) st in V' @ msteps0_stateless \\<pi> st')\"\n\nlemma msteps0_msteps0_stateless: \"fst (msteps0 w st) = msteps0_stateless w st\"\n  by (induct w arbitrary: st) (auto simp: split_beta)\n\nlift_definition msteps :: \"Formula.prefix \\<Rightarrow> ('msaux, 'muaux) mstate \\<Rightarrow> (nat \\<times> event_data table) list \\<times> ('msaux, 'muaux) mstate\"\n  is msteps0 .\n\nlift_definition msteps_stateless :: \"Formula.prefix \\<Rightarrow> ('msaux, 'muaux) mstate \\<Rightarrow> (nat \\<times> event_data table) list\"\n  is msteps0_stateless .\n\nlemma msteps_msteps_stateless: \"fst (msteps w st) = msteps_stateless w st\"\n  by transfer (rule msteps0_msteps0_stateless)\n\nlemma msteps0_snoc: \"msteps0 (\\<pi> @ [tdb]) st =\n   (let (V', st') = msteps0 \\<pi> st; (V'', st'') = mstep (map_prod mk_db id tdb) st' in (V' @ V'', st''))\"\n  by (induct \\<pi> arbitrary: st) (auto split: prod.splits)\n\nlemma msteps_psnoc: \"last_ts \\<pi> \\<le> snd tdb \\<Longrightarrow> msteps (psnoc \\<pi> tdb) st =\n   (let (V', st') = msteps \\<pi> st; (V'', st'') = mstep (map_prod mk_db id tdb) st' in (V' @ V'', st''))\"\n  by transfer' (auto simp: msteps0_snoc split: list.splits prod.splits if_splits)\n\ndefinition monitor where\n  \"monitor \\<phi> \\<pi> = msteps_stateless \\<pi> (minit_safe \\<phi>)\"\n\nlemma Suc_length_conv_snoc: \"(Suc n = length xs) = (\\<exists>y ys. xs = ys @ [y] \\<and> length ys = n)\"\n  by (cases xs rule: rev_cases) auto\n\nlemma wf_mstate_msteps: \"wf_mstate \\<phi> \\<pi> R st \\<Longrightarrow> mem_restr R v \\<Longrightarrow> \\<pi> \\<le> \\<pi>' \\<Longrightarrow>\n  X = msteps (pdrop (plen \\<pi>) \\<pi>') st \\<Longrightarrow> wf_mstate \\<phi> \\<pi>' R (snd X) \\<and>\n  ((i, v) \\<in> flatten_verdicts (fst X)) = ((i, v) \\<in> mverdicts \\<phi> \\<pi>' - mverdicts \\<phi> \\<pi>)\"\nproof (induct \"plen \\<pi>' - plen \\<pi>\" arbitrary: X st \\<pi> \\<pi>')\n  case 0\n  from 0(1,4,5) have \"\\<pi> = \\<pi>'\"  \"X = ([], st)\"\n    by (transfer; auto)+\n  with 0(2) show ?case unfolding flatten_verdicts_def by simp\nnext\n  case (Suc x)\n  from Suc(2,5) obtain \\<pi>'' tdb where \"x = plen \\<pi>'' - plen \\<pi>\"  \"\\<pi> \\<le> \\<pi>''\"\n    \"\\<pi>' = psnoc \\<pi>'' tdb\" \"pdrop (plen \\<pi>) (psnoc \\<pi>'' tdb) = psnoc (pdrop (plen \\<pi>) \\<pi>'') tdb\"\n    \"last_ts (pdrop (plen \\<pi>) \\<pi>'') \\<le> snd tdb\" \"last_ts \\<pi>'' \\<le> snd tdb\"\n    \"\\<pi>'' \\<le> psnoc \\<pi>'' tdb\"\n  proof (atomize_elim, transfer, elim exE, goal_cases prefix)\n    case (prefix _ _ \\<pi>' _ \\<pi>_tdb)\n    then show ?case\n    proof (cases \\<pi>_tdb rule: rev_cases)\n      case (snoc \\<pi> tdb)\n      with prefix show ?thesis\n        by (intro bexI[of _ \"\\<pi>' @ \\<pi>\"] exI[of _ tdb])\n          (force simp: sorted_append append_eq_Cons_conv split: list.splits if_splits)+\n    qed simp\n  qed\n  with Suc(1)[OF this(1) Suc.prems(1,2) this(2) refl] Suc.prems show ?case\n    unfolding msteps_msteps_stateless[symmetric]\n    by (auto simp: msteps_psnoc split_beta mstep_mverdicts\n        dest: verimon.verdicts_mono[THEN set_mp, rotated] intro!: wf_mstate_mstep)\nqed\n\nlemma wf_mstate_msteps_stateless:\n  assumes \"wf_mstate \\<phi> \\<pi> R st\" \"mem_restr R v\" \"\\<pi> \\<le> \\<pi>'\"\n  shows \"(i, v) \\<in> flatten_verdicts (msteps_stateless (pdrop (plen \\<pi>) \\<pi>') st) \\<longleftrightarrow> (i, v) \\<in> mverdicts \\<phi> \\<pi>' - mverdicts \\<phi> \\<pi>\"\n  using wf_mstate_msteps[OF assms refl] unfolding msteps_msteps_stateless by simp\n\nlemma wf_mstate_msteps_stateless_UNIV: \"wf_mstate \\<phi> \\<pi> UNIV st \\<Longrightarrow> \\<pi> \\<le> \\<pi>' \\<Longrightarrow>\n  flatten_verdicts (msteps_stateless (pdrop (plen \\<pi>) \\<pi>') st) = mverdicts \\<phi> \\<pi>' - mverdicts \\<phi> \\<pi>\"\n  by (auto dest: wf_mstate_msteps_stateless[OF _ mem_restr_UNIV])\n\nlemma mverdicts_Nil: \"mverdicts \\<phi> pnil = {}\"\n  unfolding verimon.verdicts_def\n  by (auto intro: ex_prefix_of)\n\nlemma wf_mstate_minit_safe: \"mmonitorable \\<phi> \\<Longrightarrow> wf_mstate \\<phi> pnil R (minit_safe \\<phi>)\"\n  using wf_mstate_minit minit_safe_minit mmonitorable_def by metis\n\nlemma monitor_mverdicts: \"mmonitorable \\<phi> \\<Longrightarrow> flatten_verdicts (monitor \\<phi> \\<pi>) = mverdicts \\<phi> \\<pi>\"\n  unfolding monitor_def\n  by (subst wf_mstate_msteps_stateless_UNIV[OF wf_mstate_minit_safe, simplified])\n    (auto simp: mmonitorable_def mverdicts_Nil)\n\nsubsection \\<open>Collected correctness results\\<close>\n\ntext \\<open>We summarize the main results proved above.\n\\begin{enumerate}\n\\item The term @{term mverdicts} describes semantically the monitor's expected behaviour:\n\\begin{itemize}\n\\item @{thm[source] verimon.mono_monitor}: @{thm verimon.mono_monitor[no_vars]}\n\\item @{thm[source] verimon.sound_monitor}: @{thm verimon.sound_monitor[no_vars]}\n\\item @{thm[source] verimon.complete_monitor}: @{thm verimon.complete_monitor[no_vars]}\n\\item @{thm[source] verimon.monitor_slice}: @{thm verimon.monitor_slice[no_vars]}\n\\end{itemize}\n\\item The executable monitor's online interface @{term minit_safe} and @{term mstep}\n  preserves the invariant @{term wf_mstate} and produces the the verdicts according\n  to @{term mverdicts}:\n\\begin{itemize}\n\\item @{thm[source] wf_mstate_minit_safe}: @{thm wf_mstate_minit_safe[no_vars]}\n\\item @{thm[source] wf_mstate_mstep}: @{thm wf_mstate_mstep[no_vars]}\n\\item @{thm[source] mstep_mverdicts}: @{thm mstep_mverdicts[no_vars]}\n\\end{itemize}\n\\item The executable monitor's offline interface @{term monitor} implements @{term mverdicts}:\n\\begin{itemize}\n\\item @{thm[source] monitor_mverdicts}: @{thm monitor_mverdicts[no_vars]}\n\\end{itemize}\n\\end{enumerate}\n\\<close>\n\nend \\<comment> \\<open>context @{locale maux}\\<close>\n\n(*<*)\nend\n(*>*)\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/MFODL_Monitor_Optimized/Monitor.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6513548511303336, "lm_q2_score": 0.4493926344647597, "lm_q1q2_score": 0.292714072520862}}
{"text": "theory LiarsStreet  (*Christoph Benzmüller, 2020*)\n  imports Main  \n\n(*\nabbrevs   \n Nilda=\"\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a\" and Nilda=\"\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a\" and And=\"( \\<^bold>a\\<^bold>n\\<^bold>d )\" and Or=\"( \\<^bold>o\\<^bold>r )\" and Not=\"(\\<^bold>n\\<^bold>o\\<^bold>t )\" and If_then=\"(\\<^bold>I\\<^bold>f \\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>n )\"\n and LiarsStreet=\"\\<^bold>L\\<^bold>i\\<^bold>a\\<^bold>r\\<^bold>s\\<^bold>S\\<^bold>t\\<^bold>r\\<^bold>e\\<^bold>e\\<^bold>t\" and TruthtellersRoad=\"\\<^bold>T\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h\\<^bold>t\\<^bold>e\\<^bold>l\\<^bold>l\\<^bold>e\\<^bold>r\\<^bold>s\\<^bold>R\\<^bold>o\\<^bold>a\\<^bold>d\" and Lies=\"\\<^bold>(l\\<^bold>i\\<^bold>e\\<^bold>s )\"\n and Says_the_truth=\"(\\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s\\<^bold>-\\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>-\\<^bold>t\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h )\" and Lives_not_in=\"( \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>n\\<^bold>o\\<^bold>t\\<^bold>-\\<^bold>i\\<^bold>n )\" \n and Neither_nor_live_in=\"( \\<^bold>n\\<^bold>e\\<^bold>i\\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>r  \\<^bold>n\\<^bold>o\\<^bold>r  \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>-\\<^bold>i\\<^bold>n )\" and Both_live_in=\"( \\<^bold>\\<^bold>b\\<^bold>o\\<^bold>t\\<^bold>h  \\<^bold>a\\<^bold>n\\<^bold>d  \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>-\\<^bold>i\\<^bold>n )\" \n*)\n\nbegin          \n(*unimportant*) nitpick_params [user_axioms,format=2,show_all]\n(*unimportant*) declare [[show_abbrevs=false]]\n\n(***********************************************************************************\n ******************  Some Basic Types of our Ontology ******************************\n ***********************************************************************************)\n(* There are some kids, could be many more *)\ndatatype Entity = Nilda (\"\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a\") | Carla  (\"\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a\")\nprint_theorems\n\nlemma \"\\<not>(\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a = \\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a)\" sledgehammer by simp\n\n(* There are some roads, could be many more *)\ndatatype Street = LiarsStreet (\"\\<^bold>L\\<^bold>i\\<^bold>a\\<^bold>r\\<^bold>s\\<^bold>S\\<^bold>t\\<^bold>r\\<^bold>e\\<^bold>e\\<^bold>t\") | TruthtellersRoad (\"\\<^bold>T\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h\\<^bold>t\\<^bold>e\\<^bold>l\\<^bold>l\\<^bold>e\\<^bold>r\\<^bold>s\\<^bold>R\\<^bold>o\\<^bold>a\\<^bold>d\") \n\n(***********************************************************************************\n ******************  Controlled Natural Language Library ***************************\n ******************  Logic and Modalities ******************************************\n ***********************************************************************************)\n\ndefinition And (\"_ \\<^bold>a\\<^bold>n\\<^bold>d _\") where \"X \\<^bold>a\\<^bold>n\\<^bold>d Y \\<equiv> X \\<and> Y\"\nabbreviation Or (\"_ \\<^bold>o\\<^bold>r _\") where \"X \\<^bold>o\\<^bold>r Y \\<equiv> X \\<or> Y\"\ndefinition Not (\"\\<^bold>n\\<^bold>o\\<^bold>t _\") where \"\\<^bold>n\\<^bold>o\\<^bold>t X \\<equiv> \\<not>X\"\ndefinition If_then (\"\\<^bold>I\\<^bold>f _ \\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>n _\") where \"\\<^bold>I\\<^bold>f X \\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>n Y \\<equiv> X \\<longrightarrow> Y\"\n\n\n(* \"Says\" \"Knows\" \"Belief\" \"Obligation\", etc. as uninterpreted truth-functions\n   --- which, of course, will lead to known paradoxes *)\nconsts  Says::\"Entity\\<Rightarrow>bool\\<Rightarrow>bool\"  (\"_ \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s _\") \nconsts  Knows::\"Entity\\<Rightarrow>bool\\<Rightarrow>bool\"  (\"_ \\<^bold>k\\<^bold>n\\<^bold>o\\<^bold>w\\<^bold>s _\")  \nconsts  Believes::\"Entity\\<Rightarrow>bool\\<Rightarrow>bool\"  (\"_ \\<^bold>b\\<^bold>e\\<^bold>l\\<^bold>i\\<^bold>e\\<^bold>v\\<^bold>e\\<^bold>s _\")    \nconsts  Obligation::\"Entity\\<Rightarrow>bool\\<Rightarrow>bool\"  (\"_ \\<^bold>m\\<^bold>u\\<^bold>s\\<^bold>t\\<^bold>-\\<^bold>d\\<^bold>o _\") \n\n(* We can introduce some further derived modal NL phrases *)\ndefinition Lies (\"\\<^bold>l\\<^bold>i\\<^bold>e\\<^bold>s _\") where \"\\<^bold>l\\<^bold>i\\<^bold>e\\<^bold>s X \\<equiv> \\<forall>Y. \\<^bold>I\\<^bold>f (X \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s Y) \\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>n \\<^bold>n\\<^bold>o\\<^bold>t Y\"\ndefinition Says_the_truth (\"\\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s\\<^bold>-\\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>-\\<^bold>t\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h _\") \n  where \"\\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s\\<^bold>-\\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>-\\<^bold>t\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h X \\<equiv> \\<forall>Y. \\<^bold>I\\<^bold>f (X \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s Y) \\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>n Y\" \n\n(* We add the above defintions to our \"bag\" called \"Defs\" — Unimportant *)\nnamed_theorems Defs\ndeclare Lies_def [Defs] Says_the_truth_def [Defs] \n\n\n(***********************************************************************************\n ****************** Controlled Natural Language Library ****************************\n ****************** Domain specific concepts ***************************************\n ***********************************************************************************)\n\n(* Uninterpreted predicate: Lives_in *)\nconsts Lives_in::\"Entity\\<Rightarrow>Street\\<Rightarrow>bool\" (\"_ \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n _\") \n\n(* Further derived NL phrases that concern \"Lives_in\" *)\ndefinition Lives_not_in (\"_ \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>n\\<^bold>o\\<^bold>t\\<^bold>-\\<^bold>i\\<^bold>n _\")\n  where \"X \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>n\\<^bold>o\\<^bold>t\\<^bold>-\\<^bold>i\\<^bold>n G \\<equiv> \\<^bold>n\\<^bold>o\\<^bold>t (X \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n G)\"\ndefinition Neither_nor_live_in (\"\\<^bold>n\\<^bold>e\\<^bold>i\\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>r _ \\<^bold>n\\<^bold>o\\<^bold>r _ \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>-\\<^bold>i\\<^bold>n _\") \n  where \"\\<^bold>n\\<^bold>e\\<^bold>i\\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>r X \\<^bold>n\\<^bold>o\\<^bold>r Y \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>-\\<^bold>i\\<^bold>n G \\<equiv> (\\<^bold>n\\<^bold>o\\<^bold>t (X \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n G)) \\<^bold>a\\<^bold>n\\<^bold>d (\\<^bold>n\\<^bold>o\\<^bold>t (Y \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n G))\"\ndefinition Both_live_in (\"\\<^bold>b\\<^bold>o\\<^bold>t\\<^bold>h _ \\<^bold>a\\<^bold>n\\<^bold>d _ \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>-\\<^bold>i\\<^bold>n _\") \n  where \"\\<^bold>b\\<^bold>o\\<^bold>t\\<^bold>h X \\<^bold>a\\<^bold>n\\<^bold>d Y \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>-\\<^bold>i\\<^bold>n G \\<equiv> (X \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n G) \\<^bold>a\\<^bold>n\\<^bold>d (Y \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n G)\"\n\n(* We add the above defintions to our \"bag\" called \"Defs\" — Unimportant *)\ndeclare Lives_not_in_def [Defs] Neither_nor_live_in_def [Defs] Both_live_in_def [Defs] \n\n\n(***********************************************************************************\n ****************** Example Queries ************************************************\n ***********************************************************************************)\n\naxiomatization where\nA1:  \"\\<forall>X. \\<^bold>I\\<^bold>f (X \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>L\\<^bold>i\\<^bold>a\\<^bold>r\\<^bold>s\\<^bold>S\\<^bold>t\\<^bold>r\\<^bold>e\\<^bold>e\\<^bold>t) \\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>n (\\<^bold>l\\<^bold>i\\<^bold>e\\<^bold>s X)\"  and\nA2:  \"\\<forall>X. \\<^bold>I\\<^bold>f (X \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>T\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h\\<^bold>t\\<^bold>e\\<^bold>l\\<^bold>l\\<^bold>e\\<^bold>r\\<^bold>s\\<^bold>R\\<^bold>o\\<^bold>a\\<^bold>d) \\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>n (\\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s\\<^bold>-\\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>-\\<^bold>t\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h X)\" \n\n\nlemma Question1:\n  assumes\n   \"\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s (\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>T\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h\\<^bold>t\\<^bold>e\\<^bold>l\\<^bold>l\\<^bold>e\\<^bold>r\\<^bold>s\\<^bold>R\\<^bold>o\\<^bold>a\\<^bold>d)\" \n   \"\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s (\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>T\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h\\<^bold>t\\<^bold>e\\<^bold>l\\<^bold>l\\<^bold>e\\<^bold>r\\<^bold>s\\<^bold>R\\<^bold>o\\<^bold>a\\<^bold>d)\"\n  shows\n   \"((\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n S1) \\<^bold>a\\<^bold>n\\<^bold>d (\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n S2))\"         \n  nitpick[satisfy] oops  \n\n\n\nlemma Question1b:\n  assumes\n   \"\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s (\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>T\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h\\<^bold>t\\<^bold>e\\<^bold>l\\<^bold>l\\<^bold>e\\<^bold>r\\<^bold>s\\<^bold>R\\<^bold>o\\<^bold>a\\<^bold>d)\" \n   \"\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s (\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>T\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h\\<^bold>t\\<^bold>e\\<^bold>l\\<^bold>l\\<^bold>e\\<^bold>r\\<^bold>s\\<^bold>R\\<^bold>o\\<^bold>a\\<^bold>d)\"\n  shows\n   \"((\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>L\\<^bold>i\\<^bold>a\\<^bold>r\\<^bold>s\\<^bold>S\\<^bold>t\\<^bold>r\\<^bold>e\\<^bold>e\\<^bold>t) \\<^bold>a\\<^bold>n\\<^bold>d (\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n S2))\"         \n  nitpick[satisfy] oops \n\nlemma Question2:\n  assumes\n   \"\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s (\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>L\\<^bold>i\\<^bold>a\\<^bold>r\\<^bold>s\\<^bold>S\\<^bold>t\\<^bold>r\\<^bold>e\\<^bold>e\\<^bold>t)\"  \n   \"\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s (\\<^bold>n\\<^bold>e\\<^bold>i\\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>r \\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>n\\<^bold>o\\<^bold>r \\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>L\\<^bold>i\\<^bold>a\\<^bold>r\\<^bold>s\\<^bold>S\\<^bold>t\\<^bold>r\\<^bold>e\\<^bold>e\\<^bold>t)\"\n  shows\n   \"((\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n S1) \\<^bold>a\\<^bold>n\\<^bold>d (\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n S2))\"         \n  nitpick[satisfy] oops\n\nlemma Question3:\n  assumes\n   \"\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s (\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>L\\<^bold>i\\<^bold>a\\<^bold>r\\<^bold>s\\<^bold>S\\<^bold>t\\<^bold>r\\<^bold>e\\<^bold>e\\<^bold>t)\" \n   \"\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s (\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>L\\<^bold>i\\<^bold>a\\<^bold>r\\<^bold>s\\<^bold>S\\<^bold>t\\<^bold>r\\<^bold>e\\<^bold>e\\<^bold>t)\" \n shows\n   \"((\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n S1) \\<^bold>a\\<^bold>n\\<^bold>d (\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n S2))\"    \n  nitpick[satisfy] oops\n\n(*** Do we run into Paradoxes with the modelling of modalities? ***)\n\nconsts It_holds_that_One_plus_One_Equals_Two::bool\n       It_holds_that_Fermats_last_Theorem_is_True::bool\n\n\n\nlemma Question8:\n  assumes\n   \"It_holds_that_One_plus_One_Equals_Two\" \n   \"It_holds_that_Fermats_last_Theorem_is_True\" \n   \"\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s It_holds_that_One_plus_One_Equals_Two\"\n  shows\n   \"\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s It_holds_that_Fermats_last_Theorem_is_True\"  \n  using assms(1) assms(2) assms(3) by auto\n\n\nlemma Question9:\n  assumes\n   \"It_holds_that_One_plus_One_Equals_Two\" \n   \"It_holds_that_Fermats_last_Theorem_is_True\" \n   \"\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>k\\<^bold>n\\<^bold>o\\<^bold>w\\<^bold>s It_holds_that_One_plus_One_Equals_Two\"\n  shows\n   \"\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>k\\<^bold>n\\<^bold>o\\<^bold>w\\<^bold>s It_holds_that_Fermats_last_Theorem_is_True\"  \n  sledgehammer [verbose](assms)\n  nitpick oops\n\nend", "meta": {"author": "cbenzmueller", "repo": "LogiKEy", "sha": "5c16bdeb68bf8131e24ba9c8d774d4af663cb2cf", "save_path": "github-repos/isabelle/cbenzmueller-LogiKEy", "path": "github-repos/isabelle/cbenzmueller-LogiKEy/LogiKEy-5c16bdeb68bf8131e24ba9c8d774d4af663cb2cf/CoursesAndTutorials/2022-Bamberg/LiarsStreet.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.2925942007574071}}
{"text": "header {* Compositional Reasoning *}\n\n(*<*)\ntheory Compositional_Reasoning\nimports BD_Security\nbegin\n(*>*)\n\n\ncontext BD_Security begin\n\n\nsubsection{* Preliminaries *}\n\ndefinition \"disjAll \\<Delta>s s vl s1 vl1 \\<equiv> (\\<exists>\\<Delta> \\<in> \\<Delta>s. \\<Delta> s vl s1 vl1)\"\n\nlemma disjAll_simps[simp]:\n  \"disjAll {} \\<equiv> \\<lambda>_ _ _ _. False\"\n  \"disjAll (insert \\<Delta> \\<Delta>s) \\<equiv> \\<lambda>s vl s1 vl1. \\<Delta> s vl s1 vl1 \\<or> disjAll \\<Delta>s s vl s1 vl1\"\n  unfolding disjAll_def[abs_def] by auto\n\n\nlemma iaction_mono:\nassumes 1: \"iaction \\<Delta> s vl s1 vl1\" and 2: \"\\<And> s vl s1 vl1. \\<Delta> s vl s1 vl1 \\<Longrightarrow> \\<Delta>' s vl s1 vl1\"\nshows \"iaction \\<Delta>' s vl s1 vl1\"\nproof-\n  obtain a1 ou1 s1' vl1'\n  where \"step s1 a1 = (ou1, s1')\" and \"\\<phi> (Trans s1 a1 ou1 s1')\"\n  and \"consume (Trans s1 a1 ou1 s1') vl1 vl1'\" and \"\\<not> \\<gamma> (Trans s1 a1 ou1 s1')\"\n  and \"\\<Delta> s vl s1' vl1'\" using 1 unfolding iaction_def by auto\n  thus ?thesis unfolding iaction_def using 2 apply -\n  by (rule exI[of _ a1], rule exI[of _ ou1], rule exI[of _ s1'], rule exI[of _ vl1']) auto\nqed\n\nlemma match_mono:\nassumes 1: \"match \\<Delta> s s1 vl1 a ou s' vl'\" and 2: \"\\<And> s vl s1 vl1. \\<Delta> s vl s1 vl1 \\<Longrightarrow> \\<Delta>' s vl s1 vl1\"\nshows \"match \\<Delta>' s s1 vl1 a ou s' vl'\"\nproof-\n  obtain a1 ou1 s1' vl1'\n  where \"\\<Delta> s' vl' s1' vl1'\"\n  and \"step s1 a1 = (ou1, s1')\"\n  and \"consume (Trans s1 a1 ou1 s1') vl1 vl1'\"\n  and \"\\<gamma> (Trans s a ou s') = \\<gamma> (Trans s1 a1 ou1 s1')\"\n  and \"(\\<gamma> (Trans s a ou s') \\<longrightarrow> g (Trans s a ou s') = g (Trans s1 a1 ou1 s1'))\"\n  using 1 unfolding match_def by auto\n  thus ?thesis unfolding match_def using 2 apply -\n  by (rule exI[of _ a1], rule exI[of _ ou1], rule exI[of _ s1'], rule exI[of _ vl1']) auto\nqed\n\nlemma ignore_mono:\nassumes 1: \"ignore \\<Delta> s s1 vl1 a ou s' vl'\" and 2: \"\\<And> s vl s1 vl1. \\<Delta> s vl s1 vl1 \\<Longrightarrow> \\<Delta>' s vl s1 vl1\"\nshows \"ignore \\<Delta>' s s1 vl1 a ou s' vl'\"\nusing assms unfolding ignore_def by auto\n\nlemma reaction_mono:\nassumes 1: \"reaction \\<Delta> s vl s1 vl1\" and 2: \"\\<And> s vl s1 vl1. \\<Delta> s vl s1 vl1 \\<Longrightarrow> \\<Delta>' s vl s1 vl1\"\nshows \"reaction \\<Delta>' s vl s1 vl1\"\nproof\n  fix a ou s' vl'\n  assume \"step s a = (ou, s')\" and \"\\<not> T (Trans s a ou s')\" and \"consume (Trans s a ou s') vl vl'\"\n  hence \"match \\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore \\<Delta> s s1 vl1 a ou s' vl'\" (is \"?m \\<or> ?i\")\n  using 1 unfolding reaction_def by auto\n  thus \"match \\<Delta>' s s1 vl1 a ou s' vl' \\<or> ignore \\<Delta>' s s1 vl1 a ou s' vl'\" (is \"?m' \\<or> ?i'\")\n  proof\n    assume ?m from match_mono[OF this 2] show ?thesis by simp\n  next\n    assume ?i from ignore_mono[OF this 2] show ?thesis by simp\n  qed\nqed\n\n\nsubsection{* Decomposition into an arbitrary network of components *}\n\n(* Unwind not to itself, but to a disjunction of other relations: *)\ndefinition unwind_to where\n\"unwind_to \\<Delta> \\<Delta>s \\<equiv>\n \\<forall> s vl s1 vl1.\n   reachNT s \\<and> reach s1 \\<and> \\<Delta> s vl s1 vl1\n   \\<longrightarrow>\n   vl \\<noteq> [] \\<and> exit s (hd vl)\n   \\<or>\n   iaction (disjAll \\<Delta>s) s vl s1 vl1\n   \\<or>\n   (vl \\<noteq> [] \\<or> vl1 = []) \\<and> reaction (disjAll \\<Delta>s) s vl s1 vl1\"\n\nlemma unwind_toI[intro?]:\nassumes\n\"\\<And> s vl s1 vl1.\n   \\<lbrakk>reachNT s; reach s1; \\<Delta> s vl s1 vl1\\<rbrakk>\n   \\<Longrightarrow>\n   vl \\<noteq> [] \\<and> exit s (hd vl)\n   \\<or>\n   iaction (disjAll \\<Delta>s) s vl s1 vl1\n   \\<or>\n   (vl \\<noteq> [] \\<or> vl1 = []) \\<and> reaction (disjAll \\<Delta>s) s vl s1 vl1\"\nshows \"unwind_to \\<Delta> \\<Delta>s\"\nusing assms unfolding unwind_to_def by auto\n\n(* Decomposition: *)\nlemma unwind_dec:\nassumes ne: \"\\<And> \\<Delta>. \\<Delta> \\<in> \\<Delta>s \\<Longrightarrow> next \\<Delta> \\<subseteq> \\<Delta>s \\<and> unwind_to \\<Delta> (next \\<Delta>)\"\nshows \"unwind (disjAll \\<Delta>s)\" (is \"unwind ?\\<Delta>\")\nproof\n  fix s s1 :: 'state and vl vl1 :: \"'value list\"\n  assume r: \"reachNT s\" \"reach s1\" and \\<Delta>: \"?\\<Delta> s vl s1 vl1\"\n  then obtain \\<Delta> where \\<Delta>: \"\\<Delta> \\<in> \\<Delta>s\" and 2: \"\\<Delta> s vl s1 vl1\" unfolding disjAll_def by auto\n  let ?\\<Delta>s' = \"next \\<Delta>\"  let ?\\<Delta>' = \"disjAll ?\\<Delta>s'\"\n  have \"(vl \\<noteq> [] \\<and> exit s (hd vl)) \\<or>\n        iaction ?\\<Delta>' s vl s1 vl1 \\<or>\n        ((vl \\<noteq> [] \\<or> vl1 = []) \\<and> reaction ?\\<Delta>' s vl s1 vl1)\"\n  using 2 \\<Delta> ne r unfolding unwind_to_def by auto\n  moreover have \"\\<And> s vl s1 vl1. ?\\<Delta>' s vl s1 vl1 \\<Longrightarrow> ?\\<Delta> s vl s1 vl1\"\n  using ne[OF \\<Delta>] unfolding disjAll_def by auto\n  ultimately show\n       \"(vl \\<noteq> [] \\<and> exit s (hd vl)) \\<or>\n        iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl \\<noteq> [] \\<or> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\"\n  using iaction_mono[of ?\\<Delta>' _ _ _ _ ?\\<Delta>] reaction_mono[of ?\\<Delta>' _ _ _ _ ?\\<Delta>] by blast\nqed\n\nlemma init_dec:\nassumes \\<Delta>0: \"\\<Delta>0 \\<in> \\<Delta>s\"\nand i: \"\\<And> vl vl1. B vl vl1 \\<Longrightarrow> \\<Delta>0 istate vl istate vl1\"\nshows \"\\<forall> vl vl1. B vl vl1 \\<longrightarrow> disjAll \\<Delta>s istate vl istate vl1\"\nusing assms unfolding disjAll_def by auto\n\ntheorem unwind_dec_secure:\nassumes \\<Delta>0: \"\\<Delta>0 \\<in> \\<Delta>s\"\nand i: \"\\<And> vl vl1. B vl vl1 \\<Longrightarrow> \\<Delta>0 istate vl istate vl1\"\nand ne: \"\\<And> \\<Delta>. \\<Delta> \\<in> \\<Delta>s \\<Longrightarrow> next \\<Delta> \\<subseteq> \\<Delta>s \\<and> unwind_to \\<Delta> (next \\<Delta>)\"\nshows secure\nusing init_dec[OF \\<Delta>0 i] unwind_dec[OF ne] unwind_secure by metis\n\n\nsubsection{* A customization for linear modular reasoning *}\n\n(* The customization assumes that each component unwinds only into itself,\nits successor or an exit component.  *)\n\ndefinition unwind_cont where\n\"unwind_cont \\<Delta> \\<Delta>s \\<equiv>\n \\<forall> s vl s1 vl1.\n   reachNT s \\<and> reach s1 \\<and> \\<Delta> s vl s1 vl1\n   \\<longrightarrow>\n   iaction (disjAll \\<Delta>s) s vl s1 vl1\n   \\<or>\n   ((vl \\<noteq> [] \\<or> vl1 = []) \\<and> reaction (disjAll \\<Delta>s) s vl s1 vl1)\"\n\nlemma unwind_contI[intro?]:\nassumes\n\"\\<And> s vl s1 vl1.\n   \\<lbrakk>reachNT s; reach s1; \\<Delta> s vl s1 vl1\\<rbrakk>\n   \\<Longrightarrow>\n   iaction (disjAll \\<Delta>s) s vl s1 vl1\n   \\<or>\n   ((vl \\<noteq> [] \\<or> vl1 = []) \\<and> reaction (disjAll \\<Delta>s) s vl s1 vl1)\"\nshows \"unwind_cont \\<Delta> \\<Delta>s\"\nusing assms unfolding unwind_cont_def by auto\n\ndefinition unwind_exit where\n\"unwind_exit \\<Delta>e \\<equiv>\n \\<forall> s vl s1 vl1.\n   reachNT s \\<and> reach s1 \\<and> \\<Delta>e s vl s1 vl1\n   \\<longrightarrow>\n   vl \\<noteq> [] \\<and> exit s (hd vl)\"\n\nlemma unwind_exitI[intro?]:\nassumes\n\"\\<And> s vl s1 vl1.\n   \\<lbrakk>reachNT s; reach s1; \\<Delta>e s vl s1 vl1\\<rbrakk>\n   \\<Longrightarrow>\n   vl \\<noteq> [] \\<and> exit s (hd vl)\"\nshows \"unwind_exit \\<Delta>e\"\nusing assms unfolding unwind_exit_def by auto\n\nfun allConsec :: \"'a list \\<Rightarrow> ('a * 'a) set\" where\n  \"allConsec [] = {}\"\n| \"allConsec [a] = {}\"\n| \"allConsec (a # b # as) = insert (a,b) (allConsec (b#as))\"\n\n\nlemma set_allConsec:\nassumes \"\\<Delta> \\<in> set \\<Delta>s'\" and \"\\<Delta>s = \\<Delta>s' ## \\<Delta>1\"\nshows \"\\<exists> \\<Delta>2. (\\<Delta>,\\<Delta>2) \\<in> allConsec \\<Delta>s\"\nusing assms proof (induction \\<Delta>s' arbitrary: \\<Delta>s)\n  case Nil thus ?case by auto\nnext\n  case (Cons \\<Delta>3 \\<Delta>s' \\<Delta>s)\n  show ?case proof(cases \"\\<Delta> = \\<Delta>3\")\n    case True\n    show ?thesis proof(cases \\<Delta>s')\n      case Nil\n      show ?thesis unfolding `\\<Delta>s = (\\<Delta>3 # \\<Delta>s') ## \\<Delta>1` Nil True by (rule exI[of _ \\<Delta>1]) simp\n    next\n      case (Cons \\<Delta>4 \\<Delta>s'')\n      show ?thesis unfolding `\\<Delta>s = (\\<Delta>3 # \\<Delta>s') ## \\<Delta>1` Cons True by (rule exI[of _ \\<Delta>4]) simp\n    qed\n  next\n    case False hence \"\\<Delta> \\<in> set \\<Delta>s'\" using Cons by auto\n    then obtain \\<Delta>2 where \"(\\<Delta>, \\<Delta>2) \\<in> allConsec (\\<Delta>s' ## \\<Delta>1)\" using Cons by auto\n    thus ?thesis unfolding `\\<Delta>s = (\\<Delta>3 # \\<Delta>s') ## \\<Delta>1` by (intro exI[of _ \\<Delta>2]) (cases \\<Delta>s', auto)\n  qed\nqed\n\nlemma allConsec_set:\nassumes \"(\\<Delta>1,\\<Delta>2) \\<in> allConsec \\<Delta>s\"\nshows \"\\<Delta>1 \\<in> set \\<Delta>s \\<and> \\<Delta>2 \\<in> set \\<Delta>s\"\nusing assms by (induct \\<Delta>s rule: allConsec.induct) auto\n\n(* Liniar decomposition: *)\ntheorem unwind_decomp_secure:\nassumes n: \"\\<Delta>s \\<noteq> []\"\nand i: \"\\<And> vl vl1. B vl vl1 \\<Longrightarrow> hd \\<Delta>s istate vl istate vl1\"\nand c: \"\\<And> \\<Delta>1 \\<Delta>2. (\\<Delta>1,\\<Delta>2) \\<in> allConsec \\<Delta>s \\<Longrightarrow> unwind_cont \\<Delta>1 {\\<Delta>1, \\<Delta>2, \\<Delta>e}\"\nand l: \"unwind_cont (last \\<Delta>s) {last \\<Delta>s, \\<Delta>e}\"\nand e: \"unwind_exit \\<Delta>e\"\nshows secure\nproof-\n  let ?\\<Delta>0 = \"hd \\<Delta>s\"  let ?\\<Delta>s = \"insert \\<Delta>e (set \\<Delta>s)\"\n  def \"next\" \\<equiv>\n  \"\\<lambda> \\<Delta>1.\n     if \\<Delta>1 = \\<Delta>e then {}\n     else if \\<Delta>1 = last \\<Delta>s then {\\<Delta>1,\\<Delta>e}\n     else {\\<Delta>1,SOME \\<Delta>2. (\\<Delta>1,\\<Delta>2) \\<in> allConsec \\<Delta>s,\\<Delta>e}\"\n  show ?thesis\n  proof(rule unwind_dec_secure)\n    show \"?\\<Delta>0 \\<in> ?\\<Delta>s\" using n by auto\n  next\n    fix vl vl1 assume \"B vl vl1\"\n    thus \"?\\<Delta>0 istate vl istate vl1\" by fact\n  next\n    fix \\<Delta>\n    assume 1: \"\\<Delta> \\<in> ?\\<Delta>s\" show \"next \\<Delta> \\<subseteq> ?\\<Delta>s \\<and> unwind_to \\<Delta> (next \\<Delta>)\"\n    proof-\n      {assume \"\\<Delta> = \\<Delta>e\"\n       hence ?thesis using e unfolding next_def unwind_exit_def unwind_to_def by auto\n      }\n      moreover\n      {assume \"\\<Delta> = last \\<Delta>s\" and \"\\<Delta> \\<noteq> \\<Delta>e\"\n       hence ?thesis using n l unfolding next_def unwind_cont_def unwind_to_def by simp\n      }\n      moreover\n      {assume 1: \"\\<Delta> \\<in> set \\<Delta>s\" and 2: \"\\<Delta> \\<noteq> last \\<Delta>s\" \"\\<Delta> \\<noteq> \\<Delta>e\"\n       then obtain \\<Delta>' \\<Delta>s' where \\<Delta>s: \"\\<Delta>s = \\<Delta>s' ## \\<Delta>'\" and \\<Delta>: \"\\<Delta> \\<in> set \\<Delta>s'\"\n       by (metis (no_types) append_Cons append_assoc in_set_conv_decomp last_snoc rev_exhaust)\n       have \"\\<exists> \\<Delta>2. (\\<Delta>, \\<Delta>2) \\<in> allConsec \\<Delta>s\" using set_allConsec[OF \\<Delta> \\<Delta>s] .\n       hence \"(\\<Delta>, SOME \\<Delta>2. (\\<Delta>, \\<Delta>2) \\<in> allConsec \\<Delta>s) \\<in> allConsec \\<Delta>s\" by (metis (lifting) someI_ex)\n       hence ?thesis using 1 2 c unfolding next_def unwind_cont_def unwind_to_def\n       by simp (metis (no_types) allConsec_set)\n      }\n      ultimately show ?thesis using 1 by blast\n    qed\n  qed\nqed\n\nsubsection{* Instances *}\n\ncorollary unwind_decomp3_secure:\nassumes\ni: \"\\<And> vl vl1. B vl vl1 \\<Longrightarrow> \\<Delta>1 istate vl istate vl1\"\nand c1: \"unwind_cont \\<Delta>1 {\\<Delta>1, \\<Delta>2, \\<Delta>e}\"\nand c2: \"unwind_cont \\<Delta>2 {\\<Delta>2, \\<Delta>3, \\<Delta>e}\"\nand l: \"unwind_cont \\<Delta>3 {\\<Delta>3, \\<Delta>e}\"\nand e: \"unwind_exit \\<Delta>e\"\nshows secure\napply(rule unwind_decomp_secure[of \"[\\<Delta>1, \\<Delta>2, \\<Delta>3]\" \\<Delta>e])\nusing assms by auto\n\ncorollary unwind_decomp4_secure:\nassumes\ni: \"\\<And> vl vl1. B vl vl1 \\<Longrightarrow> \\<Delta>1 istate vl istate vl1\"\nand c1: \"unwind_cont \\<Delta>1 {\\<Delta>1, \\<Delta>2, \\<Delta>e}\"\nand c2: \"unwind_cont \\<Delta>2 {\\<Delta>2, \\<Delta>3, \\<Delta>e}\"\nand c3: \"unwind_cont \\<Delta>3 {\\<Delta>3, \\<Delta>4, \\<Delta>e}\"\nand l: \"unwind_cont \\<Delta>4 {\\<Delta>4, \\<Delta>e}\"\nand e: \"unwind_exit \\<Delta>e\"\nshows secure\napply(rule unwind_decomp_secure[of \"[\\<Delta>1, \\<Delta>2, \\<Delta>3, \\<Delta>4]\" \\<Delta>e])\nusing assms by auto\n\ncorollary unwind_decomp5_secure:\nassumes\ni: \"\\<And> vl vl1. B vl vl1 \\<Longrightarrow> \\<Delta>1 istate vl istate vl1\"\nand c1: \"unwind_cont \\<Delta>1 {\\<Delta>1, \\<Delta>2, \\<Delta>e}\"\nand c2: \"unwind_cont \\<Delta>2 {\\<Delta>2, \\<Delta>3, \\<Delta>e}\"\nand c3: \"unwind_cont \\<Delta>3 {\\<Delta>3, \\<Delta>4, \\<Delta>e}\"\nand c4: \"unwind_cont \\<Delta>4 {\\<Delta>4, \\<Delta>5, \\<Delta>e}\"\nand l: \"unwind_cont \\<Delta>5 {\\<Delta>5, \\<Delta>e}\"\nand e: \"unwind_exit \\<Delta>e\"\nshows secure\napply(rule unwind_decomp_secure[of \"[\\<Delta>1, \\<Delta>2, \\<Delta>3, \\<Delta>4, \\<Delta>5]\" \\<Delta>e])\nusing assms by auto\n\n\n\n\n(*<*)\n\nend (* context BD_Security *)\n\n\nend\n\n(*>*)", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Bounded_Deducibility_Security/Compositional_Reasoning.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.29255872599718435}}
{"text": "\nsection \"Auxiliary algebraic laws for abrupt designs\"\ntheory algebraic_laws_fault_aux\nimports \"../../../theories/Fault/utp_fault_designs\"\n \nbegin\nnamed_theorems uflt_simpl and uflt_cond and uflt_comp and uflt_lens\nsubsection {*THM setup*}\ndeclare design_condr[urel_cond] \n\n\nsubsection {*abrupt alphabet behavior*}\n\nlemma assigns_flt_alpha:\n  \"(fault :== (\\<not> &fault)) = (\\<lceil>II\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<and>  $fault\\<acute> =\\<^sub>u (\\<not>$fault) \\<and> $ok =\\<^sub>u $ok\\<acute>)\"\n  \"(ok :== (\\<not> &ok)) = (\\<lceil>II\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<and>  $fault\\<acute> =\\<^sub>u $fault \\<and> $ok =\\<^sub>u (\\<not>$ok\\<acute>))\"\n  by rel_auto+\n\nlemma vwb_of_fault[simp]: \n  \"vwb_lens ok\" \"vwb_lens fault\"\n  by simp_all\n\nlemma unrest_pre_out\\<alpha>_flt[unrest]: \"out\\<alpha> \\<sharp> \\<lceil>b\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\\<^sub><\"\n  by (transfer, auto simp add: out\\<alpha>_def lens_prod_def)\n \nlemma unrest_post_in\\<alpha>_flt[unrest]: \"in\\<alpha> \\<sharp> \\<lceil>b\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\\<^sub>>\"\n  by (transfer, auto simp add: in\\<alpha>_def lens_prod_def)\n\nlemma unrest_ok_fault_rel_uexpr_lift_cpf[unrest]:\n  \"$ok \\<sharp> \\<lceil>P\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\" \"$ok\\<acute> \\<sharp> \\<lceil>P\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\"\n  \"$fault \\<sharp> \\<lceil>P\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\" \"$fault\\<acute> \\<sharp> \\<lceil>P\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\"\n  by (pred_auto)+\n\nlemma unrest_ok_fault_rel_usubst_lift_cpf[unrest]:\n  \"$ok\\<acute> \\<sharp> \\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>F\\<^sub>L\\<^sub>T\" \"$ok \\<sharp> \\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>F\\<^sub>L\\<^sub>T\"\n  \"$fault\\<acute> \\<sharp> \\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>F\\<^sub>L\\<^sub>T\" \"$fault \\<sharp> \\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>F\\<^sub>L\\<^sub>T\"               \n  by rel_auto+\n\nlemma unrest_in_out_rel_ok_fault_res_flt [unrest]:\n  \"$ok \\<sharp> (P \\<restriction>\\<^sub>\\<alpha> ok)\" \"$ok\\<acute> \\<sharp> (P \\<restriction>\\<^sub>\\<alpha> ok)\"  \n  \"$fault \\<sharp> (P \\<restriction>\\<^sub>\\<alpha> fault)\" \"$fault\\<acute> \\<sharp> (P \\<restriction>\\<^sub>\\<alpha> fault)\"\n  by (simp_all add: rel_var_res_def unrest)\n\nlemma uflt_alphabet_unrest[unrest]:(*FIXEME:These laws should be generated automatically by alphabet backend since all the fields of alphabet are independant*)\n  \"$ok\\<acute> \\<sharp> $fault\\<acute>\" \"$ok \\<sharp> $fault\"\n  \"$ok\\<acute> \\<sharp> $x\" \"$ok \\<sharp> $fault\\<acute>\"\n  \"$fault\\<acute> \\<sharp> $ok\\<acute>\" \"$fault \\<sharp> $ok \"\n  \"$fault \\<sharp> $ok\\<acute>\" \"$fault\\<acute> \\<sharp> $x\"\n  by pred_simp+\n\nlemma cpf_ord [usubst]:\n  \"$ok \\<prec>\\<^sub>v $ok\\<acute>\" \"$abrupt \\<prec>\\<^sub>v $abrupt\\<acute>\" \"$ok \\<prec>\\<^sub>v $abrupt\\<acute>\" \n  \"$ok \\<prec>\\<^sub>v $abrupt\" \"$ok\\<acute> \\<prec>\\<^sub>v $abrupt\\<acute>\" \"$ok\\<acute> \\<prec>\\<^sub>v $abrupt\" \n  by (simp_all add: var_name_ord_def)\n\nlemma rel_usubst_lift_cpf_in_out_fault_ok[usubst]:\n  \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>F\\<^sub>L\\<^sub>T \\<dagger> $fault = $fault\" \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>F\\<^sub>L\\<^sub>T \\<dagger> (\\<not>$fault) = (\\<not>$fault)\"\n  \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>F\\<^sub>L\\<^sub>T \\<dagger> ($ok) = ($ok)\" \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>F\\<^sub>L\\<^sub>T \\<dagger> (\\<not>$ok) = (\\<not>$ok)\" \n  \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>F\\<^sub>L\\<^sub>T \\<dagger> ($fault\\<acute>) = (($fault\\<acute>))\" \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>F\\<^sub>L\\<^sub>T \\<dagger> (\\<not>$fault\\<acute>) = (\\<not>$fault\\<acute>)\"\n  \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>F\\<^sub>L\\<^sub>T \\<dagger> ($ok\\<acute>) = ($ok\\<acute>)\"  \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>F\\<^sub>L\\<^sub>T \\<dagger> (\\<not>$ok\\<acute>) = (\\<not>$ok\\<acute>)\" \n  by (simp_all add: usubst unrest)\n\nlemma abrupt_ok_simpl[uflt_comp]:\n  \"($fault ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T P) = $fault\" \"(\\<not>$ok ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T P) = (\\<not>$ok)\" \n  \"($fault ;; (P \\<turnstile> Q)) = $fault\" \"(\\<not>$ok ;; (P \\<turnstile> Q)) = (\\<not>$ok)\"\n  \"(\\<not>$fault ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T P) = (\\<not>$fault)\" \"(\\<not>$ok ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T P) = (\\<not>$ok)\" \n  \"(\\<not>$fault ;; (P \\<turnstile> Q)) = (\\<not>$fault)\" \"(\\<not>$ok ;; (P \\<turnstile> Q)) = (\\<not>$ok)\"\n  \"($fault\\<acute> ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T P) = $fault\\<acute>\" \n  \"(\\<not>$fault\\<acute> ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T P) = (\\<not>$fault\\<acute>)\" \n  by rel_auto+\n\nlemma simpl_flt_in_ok:\n  \"Simpl\\<^sub>F\\<^sub>L\\<^sub>T ($ok) = ((\\<not>$fault \\<and> ($ok \\<Rightarrow>$ok\\<acute>)) \\<or> (II))\" \n  by rel_auto\n\nlemma  simpl_flt_our_ok:\n  \"Simpl\\<^sub>F\\<^sub>L\\<^sub>T ($ok\\<acute>) = ((\\<not>$fault \\<and> ($ok \\<Rightarrow>$ok\\<acute>)) \\<or> (II))\" \n  by rel_auto\n\nlemma simpl_flt_in_abrupt:\n  \"Simpl\\<^sub>F\\<^sub>L\\<^sub>T ($fault) = ((\\<not>$fault \\<and> ($ok \\<Rightarrow>($ok\\<acute> \\<and> $fault))) \\<or> ($fault \\<and> II))\" \n  by rel_auto\n\nlemma simpl_flt_alt_def:\n  \"Simpl\\<^sub>F\\<^sub>L\\<^sub>T (P) = ((\\<not>$fault \\<and> ($ok \\<Rightarrow>($ok\\<acute> \\<and> P))) \\<or> ($fault \\<and> II))\" \n  by rel_auto\n\nsubsection {*Healthiness condition behavior*}\n\nlemma rel_usubst_cpf_c3_flt[usubst]: \n  assumes \"$ok \\<sharp> \\<sigma>\" \"$ok\\<acute> \\<sharp> \\<sigma> \"\n  shows \"\\<sigma> \\<dagger> C3_flt(P) = (\\<sigma> \\<dagger> P \\<triangleleft> \\<sigma> \\<dagger> (\\<not>$fault) \\<triangleright> (\\<sigma> \\<dagger> II))\"\n  using assms unfolding C3_flt_def  \n  by (simp add: usubst) \n\nlemma Simpl_flt_idem[simp]: \"Simpl\\<^sub>F\\<^sub>L\\<^sub>T(Simpl\\<^sub>F\\<^sub>L\\<^sub>T(P)) = Simpl\\<^sub>F\\<^sub>L\\<^sub>T(P)\"\n  by (rel_auto)\n\nlemma simpl_flt_Idempotent: \"Idempotent Simpl\\<^sub>F\\<^sub>L\\<^sub>T\"\n  by (simp add: Idempotent_def)\n\nlemma Simpl_flt_mono: \"P \\<sqsubseteq> Q \\<Longrightarrow> Simpl\\<^sub>F\\<^sub>L\\<^sub>T(P) \\<sqsubseteq> Simpl\\<^sub>F\\<^sub>L\\<^sub>T(Q)\"\n  by (rel_auto)\n\nlemma simpl_flt_Monotonic: \"Monotonic Simpl\\<^sub>F\\<^sub>L\\<^sub>T\"\n  by (simp add: Monotonic_def Simpl_flt_mono)\n\nlemma simpl_flt_def: \n  \"Simpl\\<^sub>F\\<^sub>L\\<^sub>T(P) = ((\\<lceil>true\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<turnstile> P) \\<triangleleft> \\<not>$fault \\<triangleright>  II)\"\n  unfolding C3_flt_def ..\n\nlemma simpl_flt_condr[uflt_simpl]: \n  \"Simpl\\<^sub>F\\<^sub>L\\<^sub>T(P \\<triangleleft> b \\<triangleright> Q) = (Simpl\\<^sub>F\\<^sub>L\\<^sub>T(P) \\<triangleleft> b \\<triangleright> Simpl\\<^sub>F\\<^sub>L\\<^sub>T(Q))\"\n  unfolding simpl_flt_def \n  by (simp add: urel_cond)\n\nlemma simpl_abr_skip_abr[uflt_simpl]: \n  \"Simpl\\<^sub>F\\<^sub>L\\<^sub>T(SKIP\\<^sub>F\\<^sub>L\\<^sub>T) = (SKIP\\<^sub>F\\<^sub>L\\<^sub>T)\"\n  by (simp add: urel_cond urel_defs) \n       \nlemma simpl_flt_assign_flt[uflt_simpl]: \n  \"Simpl\\<^sub>F\\<^sub>L\\<^sub>T(\\<langle>\\<sigma>\\<rangle>\\<^sub>F\\<^sub>L\\<^sub>T) = (\\<langle>\\<sigma>\\<rangle>\\<^sub>F\\<^sub>L\\<^sub>T)\"\n  by (simp add: urel_cond urel_defs)\n\nlemma simpl_flt_form: \n  \"Simpl\\<^sub>F\\<^sub>L\\<^sub>T(P) = (((\\<not>$fault) \\<and> (\\<lceil>true\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<turnstile> (P)))  \\<or> ($fault \\<and> II))\"\n  by rel_auto \n\nlemma abrupt_simpl_flt[uflt_simpl]:\n  \"($fault \\<and> Simpl\\<^sub>F\\<^sub>L\\<^sub>T(P)) = ($fault \\<and>II)\"\n   by rel_auto\n\nlemma nabrupt_simpl_flt[uflt_simpl]:\n  \"(\\<not>$fault \\<and> Simpl\\<^sub>F\\<^sub>L\\<^sub>T(P)) = (\\<not>$fault \\<and> (\\<lceil>true\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<turnstile> (P)))\"\n  by (rel_auto)\n\ndefinition design_flt_sup :: \"('\\<alpha>,'\\<beta>) rel_cpf set \\<Rightarrow> ('\\<alpha>,'\\<beta>) rel_cpf\" (\"\\<Sqinter>\\<^sub>F\\<^sub>L\\<^sub>T_\" [900] 900) where\n\"\\<Sqinter>\\<^sub>F\\<^sub>L\\<^sub>T A = (if (A = {}) then \\<top>\\<^sub>F\\<^sub>L\\<^sub>T else \\<Sqinter> A)\"\n\nlemma simpl_flt_Continuous: \"Continuous Simpl\\<^sub>F\\<^sub>L\\<^sub>T\"\n  unfolding Continuous_def SUP_def apply rel_simp\n  unfolding  SUP_def \n  apply transfer apply auto \ndone\n\nlemma simpl_flt_R3_conj: \n  \"Simpl\\<^sub>F\\<^sub>L\\<^sub>T(P \\<and> Q) = (Simpl\\<^sub>F\\<^sub>L\\<^sub>T(P) \\<and> Simpl\\<^sub>F\\<^sub>L\\<^sub>T(Q))\"\n  by (rel_auto)\n\nlemma simpl_flt_disj: \n  \"Simpl\\<^sub>F\\<^sub>L\\<^sub>T(P \\<or> Q) = (Simpl\\<^sub>F\\<^sub>L\\<^sub>T(P) \\<or> Simpl\\<^sub>F\\<^sub>L\\<^sub>T(Q))\"\n  by (rel_auto)\n\nlemma Simpl_flt_USUP:\n  assumes \"A \\<noteq> {}\"\n  shows \"Simpl\\<^sub>F\\<^sub>L\\<^sub>T(\\<Sqinter> i \\<in> A \\<bullet> P(i)) = (\\<Sqinter> i \\<in> A \\<bullet> Simpl\\<^sub>F\\<^sub>L\\<^sub>T(P(i)))\"\n  using assms by (rel_auto)\n\nlemma design_flt_sup_non_empty [simp]:  \n  \"A \\<noteq> {} \\<Longrightarrow> \\<Sqinter>\\<^sub>F\\<^sub>L\\<^sub>T A = \\<Sqinter> A\"\n  by (simp add: design_flt_sup_def)\n\nsubsection {*Signature behavior*}\n\nlemma design_top_flt:\n  \"(P \\<turnstile> Q) \\<sqsubseteq> \\<top>\\<^sub>F\\<^sub>L\\<^sub>T\"\n  by (rel_auto)\n\nlemma design_flt_sup_empty [simp]: \n  \"\\<Sqinter>\\<^sub>F\\<^sub>L\\<^sub>T {} = \\<top>\\<^sub>F\\<^sub>L\\<^sub>T\"\n  by (simp add: design_flt_sup_def)\n\n\nabbreviation design_inf :: \"('\\<alpha>, '\\<beta>) rel_des set \\<Rightarrow> ('\\<alpha>, '\\<beta>) rel_des\" (\"\\<Squnion>\\<^sub>F\\<^sub>L\\<^sub>T_\" [900] 900) where\n\"\\<Squnion>\\<^sub>F\\<^sub>L\\<^sub>T A \\<equiv> \\<Squnion> A\"\n\nlemma design_bottom_flt:\n  \"\\<bottom>\\<^sub>F\\<^sub>L\\<^sub>T \\<sqsubseteq> (P \\<turnstile> Q)\"\n  by simp\n\nlemma Simpl_flt_UINF:\n  assumes \"A \\<noteq> {}\"\n  shows \"Simpl\\<^sub>F\\<^sub>L\\<^sub>T(\\<Squnion> i \\<in> A \\<bullet> P(i)) = (\\<Squnion> i \\<in> A \\<bullet> Simpl\\<^sub>F\\<^sub>L\\<^sub>T(P(i)))\"\n  using assms by (rel_auto)\n\nlemma skip_cpf_def:\n  \"II = (\\<lceil>II\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<and> $fault =\\<^sub>u $fault\\<acute> \\<and> $ok =\\<^sub>u $ok\\<acute>)\" \n  by rel_auto\n\nlemma skip_lift_flt_def:\n  \"\\<lceil>II\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T = ($\\<Sigma>\\<^sub>F\\<^sub>L\\<^sub>T\\<acute> =\\<^sub>u $\\<Sigma>\\<^sub>F\\<^sub>L\\<^sub>T)\"\n  by rel_auto\n\nlemma seqr_fault_true [usubst]: \n  \"(P ;; Q) \\<^sub>f\\<^sub>t = (P \\<^sub>f\\<^sub>t ;; Q)\"\n  by (rel_auto)\n\nlemma seqr_fault_false [usubst]: \n  \"(P ;; Q) \\<^sub>f\\<^sub>f = (P \\<^sub>f\\<^sub>f ;; Q)\"\n  by (rel_auto)\n\nlemma rel_usubst_lift_cpf_uexpr_lift_cpf[usubst]:\n  \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>F\\<^sub>L\\<^sub>T \\<dagger> \\<lceil>P\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T = \\<lceil>\\<sigma> \\<dagger> P\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\" \n  by rel_auto\n\nlemma usubst_lift_cpf_assigns_lift_cpf [usubst]:\n  \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>s\\<^sub>F\\<^sub>L\\<^sub>T \\<dagger> \\<lceil>\\<langle>\\<rho>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T = \\<lceil>\\<langle>\\<rho> \\<circ> \\<sigma>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\" \n  by (simp add: usubst)\n\nlemma usubst_lift_cpf_pre_uexpr_lift_cpf[usubst]:\n  \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>s\\<^sub>F\\<^sub>L\\<^sub>T \\<dagger> \\<lceil>b\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\\<^sub>< = \\<lceil>\\<sigma> \\<dagger> b\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\\<^sub><\" \n  by (simp add: usubst)\n\nlemma rel_usubst_lift_cpf_design[usubst]: \n  \"(\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>F\\<^sub>L\\<^sub>T \\<dagger> (Q \\<turnstile> P)) = (\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>F\\<^sub>L\\<^sub>T \\<dagger> Q) \\<turnstile> (\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>F\\<^sub>L\\<^sub>T \\<dagger> P)\"\n  by (simp add: usubst unrest)\n\nlemma usubst_cpf_true[usubst]: \n  \"\\<sigma> \\<dagger> \\<lceil>true\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T = \\<lceil>true\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\" \n  by rel_auto\n\nlemma usubst_cpf_false[usubst]: \n  \"\\<sigma> \\<dagger> \\<lceil>false\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T = \\<lceil>false\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\" \n  by rel_auto\n\nlemma rel_usubst_cpf_skip_cpf[usubst]: \n  \"(\\<sigma> \\<dagger> II) = ((\\<sigma> \\<dagger> \\<lceil>II\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T) \\<and> \\<sigma> \\<dagger> $fault =\\<^sub>u \\<sigma> \\<dagger> $fault\\<acute> \\<and> \\<sigma> \\<dagger> $ok =\\<^sub>u \\<sigma> \\<dagger> $ok\\<acute>)\" \n  by (simp add: usubst unrest skip_cpf_def)\n\nlemma usubst_lift_cpf_skip_lift_cpf[usubst]: \n  \"(\\<lceil>\\<sigma>\\<rceil>\\<^sub>s\\<^sub>F\\<^sub>L\\<^sub>T \\<dagger> \\<lceil>II\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T) = \\<lceil>\\<langle>\\<sigma>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\" \n  unfolding skip_r_def\n  by (simp add: usubst_lift_cpf_assigns_lift_cpf)\n\nlemma usubst_cpf_skip_cpf [usubst]:\n  assumes \"$ok \\<sharp> \\<sigma>\" \"$ok\\<acute> \\<sharp> \\<sigma> \"\n  shows \n  \"(\\<sigma> \\<dagger> SKIP\\<^sub>F\\<^sub>L\\<^sub>T) = (\\<lceil>true\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<turnstile> (\\<sigma> \\<dagger> (\\<not>$fault\\<acute> \\<and> \\<lceil>II\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T)) \\<triangleleft> \\<sigma> \\<dagger> (\\<not>$fault) \\<triangleright> (\\<sigma> \\<dagger> (II)))\"\n  using assms unfolding skip_flt_def\n  by (simp add: usubst)  \n\nlemma usubst_cpf_assigns_cpf [usubst]:\n  assumes \"$ok \\<sharp> \\<sigma>\" \"$ok\\<acute> \\<sharp> \\<sigma> \"\n  shows \n  \"\\<sigma> \\<dagger> \\<langle>\\<rho>\\<rangle>\\<^sub>F\\<^sub>L\\<^sub>T = (\\<lceil>true\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<turnstile> (\\<sigma> \\<dagger> ((\\<not>$fault\\<acute>) \\<and> \\<lceil>\\<langle>\\<rho>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T)) \\<triangleleft> \\<sigma> \\<dagger> (\\<not>$fault) \\<triangleright>  (\\<sigma> \\<dagger> (II)))\"  \n  using assms unfolding assigns_flt_def\n  by (simp add: usubst)\n\nlemma c3_flt_comp_left_distr:\n  \"(C3_flt (P) ;; R) = ((P;;R) \\<triangleleft> \\<not>$fault \\<triangleright> (II ;; R))\"\n  apply pred_simp\n  apply rel_simp\n  apply fastforce\ndone\n\nlemma c3_flt_comp_semir:\n  \"(C3_flt(P) ;; C3_flt(R)) = C3_flt (P ;; C3_flt(R))\"\n  by rel_auto\n\nlemma c3_flt_comp_simpl[uflt_comp]:\n  \"(C3_flt(P) ;; C3_flt(R)) = ((P ;; C3_flt(R)) \\<triangleleft> \\<not>$fault \\<triangleright> (II))\"\n  by rel_auto\n\nlemma simpl_flt_comp_semir:\n  \"(Simpl\\<^sub>F\\<^sub>L\\<^sub>T(P) ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T(R)) = Simpl\\<^sub>F\\<^sub>L\\<^sub>T ((\\<lceil>true\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<turnstile> P) ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T(R))\"\n  by rel_auto\n\ntheorem design_top_flt_left_zero[uflt_comp]: \n  \"(\\<top>\\<^sub>F\\<^sub>L\\<^sub>T ;; (P \\<turnstile> Q)) = \\<top>\\<^sub>F\\<^sub>L\\<^sub>T\"\n  by (rel_auto)\n\ntheorem Simpl_flt_top_flt_left_zero[uflt_comp]: \n  \"(\\<top>\\<^sub>F\\<^sub>L\\<^sub>T ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T (P)) = \\<top>\\<^sub>F\\<^sub>L\\<^sub>T\"\n  by (rel_auto)\n\nlemma assigns_lift_cpf_comp_rel_cpf[uflt_comp]:\n  assumes \"$ok \\<sharp> P\" \"$fault \\<sharp> P\"\n  shows  \"(\\<lceil>\\<langle>\\<sigma>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T ;; P) = (\\<lceil>\\<sigma>\\<rceil>\\<^sub>s\\<^sub>F\\<^sub>L\\<^sub>T \\<dagger> P)\"\n  apply (insert assms)\n  apply pred_simp \n  apply rel_blast \ndone\n\nlemma lift_des_skip_dr_unit_flt [uflt_comp]:\n  \"(\\<lceil>P\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T ;; \\<lceil>II\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T) = \\<lceil>P\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\"\n  \"(\\<lceil>II\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T ;; \\<lceil>P\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T) = \\<lceil>P\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\"\n  by (rel_auto)+\n\nlemma skip_cpf_left_comp_simpl[uflt_comp]:\n  \"(SKIP\\<^sub>F\\<^sub>L\\<^sub>T ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T(R)) = (Simpl\\<^sub>F\\<^sub>L\\<^sub>T(R))\"\n  by rel_auto\n\nlemma skip_cpf_right_comp_simpl[uflt_comp]:\n  \"(Simpl\\<^sub>F\\<^sub>L\\<^sub>T(R) ;; SKIP\\<^sub>F\\<^sub>L\\<^sub>T) = (Simpl\\<^sub>F\\<^sub>L\\<^sub>T(R))\"\n  by rel_auto\n\nlemma assign_flt_alt_def: \n  \"\\<langle>\\<sigma>\\<rangle>\\<^sub>F\\<^sub>L\\<^sub>T = Simpl\\<^sub>F\\<^sub>L\\<^sub>T (\\<not>$fault\\<acute> \\<and> \\<lceil>\\<lceil>\\<sigma>\\<rceil>\\<^sub>s \\<dagger> II\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T)\"\n  by rel_auto\n\nlemma assign_flt_left_comp_c3[uflt_comp]:\n  \"\\<langle>a\\<rangle>\\<^sub>F\\<^sub>L\\<^sub>T ;; C3_flt (P \\<turnstile> Q) = C3_flt (\\<lceil>a\\<rceil>\\<^sub>s\\<^sub>F\\<^sub>L\\<^sub>T \\<dagger> (P \\<turnstile>  Q))\"\n  by rel_auto\n\nlemma assigns_flt_comp[uflt_comp]: \n  \"(\\<langle>f\\<rangle>\\<^sub>F\\<^sub>L\\<^sub>T ;; \\<langle>g\\<rangle>\\<^sub>F\\<^sub>L\\<^sub>T) = \\<langle>g \\<circ> f\\<rangle>\\<^sub>F\\<^sub>L\\<^sub>T\"\n  by rel_auto\n\nlemma usubst_cpf_des_cond_flt [usubst]:\n  \"\\<lbrakk>$ok \\<sharp> \\<sigma>; $ok\\<acute> \\<sharp> \\<sigma> \\<rbrakk> \\<Longrightarrow> \n    \\<sigma> \\<dagger> (R \\<turnstile> bif b then P else Q eif) = \n    (\\<sigma> \\<dagger> R \\<turnstile>  (\\<sigma> \\<dagger> P \\<triangleleft> \\<sigma> \\<dagger> \\<lceil>b\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T\\<^sub>< \\<triangleright> \\<sigma> \\<dagger> Q))\"\n  by (simp add: usubst)\n\nlemma comp_cond_flt_left_distr[uflt_comp]:\n  \"((bif b then Simpl\\<^sub>F\\<^sub>L\\<^sub>T P else Simpl\\<^sub>F\\<^sub>L\\<^sub>T Q eif) ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T R) = \n    (bif b then (Simpl\\<^sub>F\\<^sub>L\\<^sub>T P ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T R) else (Simpl\\<^sub>F\\<^sub>L\\<^sub>T Q ;; Simpl\\<^sub>F\\<^sub>L\\<^sub>T R) eif)\"\n  apply pred_simp \n  apply rel_simp\ndone\n\nlemma if_mono:\n  \"\\<lbrakk> P\\<^sub>1 \\<sqsubseteq> P\\<^sub>2; Q\\<^sub>1 \\<sqsubseteq> Q\\<^sub>2 \\<rbrakk> \\<Longrightarrow> (bif b then P\\<^sub>1 else Q\\<^sub>1 eif) \\<sqsubseteq> (bif b then P\\<^sub>2 else Q\\<^sub>2 eif)\"\n  by rel_auto\n\nlemma design_post_seqr_rcond_left_not_ivar[urel_cond]:\n  \"S \\<turnstile> (\\<lceil>true\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<turnstile> (\\<lceil>R\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<and> $x\\<acute>) ;; P \\<triangleleft> \\<not> $x \\<triangleright> Q) = \n   S \\<turnstile> (\\<lceil>true\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<turnstile> (\\<lceil>R\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<and> $x\\<acute>);; Q)\"\n  apply pred_simp\n  apply fastforce \ndone\n\nlemma  design_post_seqr_rcond_left_ivar [urel_cond]:\n  \"S \\<turnstile> (\\<lceil>true\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<turnstile> (\\<lceil>R\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<and>  $x\\<acute>) ;; P \\<triangleleft> $x \\<triangleright> Q) = \n   S \\<turnstile> (\\<lceil>true\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<turnstile> (\\<lceil>R\\<rceil>\\<^sub>F\\<^sub>L\\<^sub>T \\<and>  $x\\<acute>);; P)\"\n  apply pred_simp\n  apply fastforce \ndone\n\nsubsection {*While abrupt usubst*}\n\nsubsection {*block abrupt usubst*}\n\nsubsection {*Catch abrupt usubst*}\n\nend", "meta": {"author": "git-vt", "repo": "orca", "sha": "92bda0f9cfe5cc680b9c405fc38f07a960087a36", "save_path": "github-repos/isabelle/git-vt-orca", "path": "github-repos/isabelle/git-vt-orca/orca-92bda0f9cfe5cc680b9c405fc38f07a960087a36/Archive/Programming-Languages-Semantics/WP11-C-semantics/src/IMP-Lenses/hoare/AlgebraicLaws/Fault/algebraic_laws_fault_aux.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5851011542032312, "lm_q2_score": 0.5, "lm_q1q2_score": 0.2925505771016156}}
{"text": "theory iPropShallow                                                      \nimports DerivedConstructions \"../SpanningTree/SpanningTreeCameras\" Namespace\n  ProofSearchPredicates \"../HeapLang/PrimitiveLaws\" View ProphMap\nbegin\n\n(*\n  The functorial definition of iprop is as follows (unused arguments omitted):\n\n  gmapF := ((loc\\<rightharpoonup>((loc option\\<times>loc option) ex))\\<times>frac) option auth\n  markingF := loc set auth\n  b invF := (name\\<rightharpoonup>b later ag) auth\n  heapF := (loc\\<rightharpoonup>(dfrac\\<times>val ag)) auth\n  (b,_) resF := gmapF \\<times> markingF \\<times> b invF \\<times> heapF\n  iprop := (iprop,iprop) resF upred\n*)\n\ntype_synonym 'a pre_inv = \"(name, 'a later) map_view \\<times> name dset \\<times> name dfset\"\n\nML \\<open>\n  local\n  type camera_data = {\n    camera: typ,\n    name: string,\n    getter: term option,\n    constructor: term option\n  }\n\n  type cameras_data = {\n    number: int,\n    cameras: camera_data list,\n    cmraPT: typ option\n  }\n\n  (* Names *)\n  val resFN = Binding.name \"resF\"\n  val invN = Binding.name \"inv\"\n  val resN = Binding.name \"res\"\n  val ipropN = Binding.name \"iprop\"\n  val getter_prefix = \"get_\"\n  val constructor_prefix = \"constr_\"\n  val gnameN = \"name\"\n  val mapN = \"map_res\"\n\n  (* Types *)\n  val pre_ipropT = \\<^typ>\\<open>pre_iprop\\<close>\n  val gnameT = \\<^typ>\\<open>gname\\<close>\n  fun mk_opt T = Type (\\<^type_name>\\<open>option\\<close>, [T])\n  fun mk_res_mapT res = gnameT --> mk_opt res (* This might need to be (gname,res) fmap *)\n  val invT = \\<^typ>\\<open>'a pre_inv\\<close>\n  val heapT = \\<^typ>\\<open>heap_lang_heap\\<close>\n  val cinvT = \\<^typ>\\<open>frac option\\<close>\n  val aT = \\<^typ>\\<open>'a\\<close>\n  val base_cameraT = HOLogic.mk_prodT (mk_res_mapT cinvT, \n    HOLogic.mk_prodT (mk_res_mapT invT, mk_res_mapT heapT))\n  \n  fun mk_pred cmraT = typ_subst_atomic [(aT,cmraT)] \\<^typ>\\<open>'a upred_f\\<close>\n  fun subst_aT fp cmraT = typ_subst_atomic [(aT,fp)] cmraT\n  fun add_cameraT cmraT cmrasT = HOLogic.mk_prodT (cmraT,cmrasT)\n  fun fixed_cmras preT = [\n    {camera = cinvT, name = \"cinv\", getter = NONE, constructor = NONE},\n    {camera = subst_aT preT invT, name = \"inv\", getter = NONE, constructor = NONE},\n    {camera = heapT, name = \"heap\", getter = NONE, constructor = NONE}\n   ]\n  val mk_cmraT = curry (Library.foldr (uncurry add_cameraT))\n  val mk_maps = map mk_res_mapT\n\n  (* Setup to generate getters for single cameras from the camera product *)\n  val gname_param = Free (gnameN, gnameT)\n  fun mk_def trm lthy = let val prop_trm = HOLogic.mk_Trueprop trm\n    in Specification.definition NONE [] [] ((Binding.empty,[]), prop_trm) lthy |> snd end\n\n  fun mk_defs (cmras_data:cameras_data) lthy =\n    let fun mk_getter name cmraT = \n          Free (getter_prefix ^ name, [gnameT, the (#cmraPT cmras_data)]--->mk_opt cmraT)$gname_param\n        fun mk_own name cmraT = \n          Free (constructor_prefix ^ name, [gnameT,cmraT]--->(the (#cmraPT cmras_data)))$gname_param$\n          Free (Binding.name_of resN, cmraT)\n    in\n      Library.foldl (fn (lthy, cmra_data:camera_data) => \n        (mk_def (curry HOLogic.mk_eq (mk_getter (#name cmra_data) (#camera cmra_data))\n          (the (#getter cmra_data))) \n       #> mk_def (curry HOLogic.mk_eq (mk_own (#name cmra_data) (#camera cmra_data))\n          (the (#constructor cmra_data))))\n       lthy)\n      (lthy, #cameras cmras_data)\n    end\n\n  val dummy_fst = Const (\\<^const_name>\\<open>fst\\<close>, dummyT)\n  val dummy_snd = Const (\\<^const_name>\\<open>snd\\<close>, dummyT)\n  val dummy_comp = Const (\\<^const_name>\\<open>comp\\<close>, dummyT)\n  val dummy_I = Const (\\<^const_name>\\<open>id\\<close>, dummyT)\n  val dummy_eps = Const (\\<^const_name>\\<open>\\<epsilon>\\<close>, dummyT)\n  val dummy_cmra_object = Free (Binding.name_of resN, dummyT)\n  val map_param = Bound 0\n  val lookup_name = Abs (mapN, dummyT, map_param$gname_param)\n  fun mk_some trm = Const (\\<^const_name>\\<open>Some\\<close>, dummyT-->mk_opt dummyT)$trm\n  fun mk_singleton_map res = \n    Const (\\<^const_name>\\<open>fun_upd\\<close>, [mk_res_mapT dummyT,gnameT,dummyT]--->mk_res_mapT dummyT)\n    $Const (\"Map.empty\", mk_res_mapT dummyT)\n    $gname_param$(mk_some res)\n  fun mk_comp_lookup getter = Const (\\<^const_name>\\<open>comp\\<close>, dummyT)$lookup_name$getter\n\n  fun mk_getter levels is_heap = \n    let val base = if is_heap then dummy_I else dummy_fst\n      fun add_level 0 = base\n        | add_level n = dummy_comp$(add_level (n-1))$dummy_snd\n    in mk_comp_lookup (add_level levels) end\n\n  fun mk_getters ({ number, cameras, cmraPT}: cameras_data) = let\n    fun mk_getters_levels _ _ [] = []\n      | mk_getters_levels levels n ((cmra: camera_data)::cameras) = \n        {camera = #camera cmra, name = #name cmra,\n          getter= if n=levels then SOME (mk_getter n true) else SOME (mk_getter n false),\n          constructor = #constructor cmra\n        }::(mk_getters_levels levels (n+1) cameras)\n    in { number = number, cameras = mk_getters_levels (number-1) 0 cameras, cmraPT = cmraPT }\n    end\n\n  fun mk_own levels is_heap =\n    let val base = if is_heap then mk_singleton_map dummy_cmra_object \n      else curry HOLogic.mk_prod (mk_singleton_map dummy_cmra_object) dummy_eps\n      fun add_level 0 = base\n        | add_level n = curry HOLogic.mk_prod dummy_eps (add_level (n-1))\n    in add_level levels end\n\n    fun mk_owns ({ number, cameras, cmraPT}: cameras_data) = let\n    fun mk_owns_levels _ _ [] = []\n      | mk_owns_levels levels n ((cmra: camera_data)::cameras) = \n        {camera = #camera cmra, name = #name cmra,\n          getter = #getter cmra,\n          constructor = if n=levels then SOME (mk_own n true) else SOME (mk_own n false)\n        }::(mk_owns_levels levels (n+1) cameras)\n    in { number = number, cameras = mk_owns_levels (number-1) 0 cameras, cmraPT = cmraPT }\n    end\n\n  (* Setup functions *)\n  fun def_resF cmraT = (#2 o Typedecl.abbrev_global (resFN,[\"'a\", \"'b\"],NoSyn) cmraT)\n  fun def_inv preT = (#2 o Typedecl.abbrev_global (invN,[],NoSyn) (subst_aT preT invT))\n  fun def_res cmraT = (#2 o Typedecl.abbrev_global (resN,[],NoSyn) cmraT)\n  fun def_iprop cmraT = (#2 o Typedecl.abbrev_global (ipropN,[],NoSyn) (mk_pred cmraT))\n\n  fun wrap_quick_and_dirtys_mode f thy =\n    let val qad = Config.get_global thy quick_and_dirty in\n      thy |> Config.put_global quick_and_dirty true |> f |> Config.put_global quick_and_dirty qad \n    end\n\n  in\n\n  fun mk_iprop cmras thy = \n    let \n      val cmras_raw = map (fn (cmra,name)=>{camera=cmra, name=name, getter=NONE, constructor=NONE}) cmras\n      val cmra_data = {number = length cmras+3, cameras = cmras_raw@fixed_cmras pre_ipropT, cmraPT = NONE}\n      val cmra_data = mk_getters cmra_data\n      val cmra_data = mk_owns cmra_data\n      val cmraT = subst_aT pre_ipropT base_cameraT |> mk_cmraT (mk_maps (map fst cmras))\n      val cmra_data = {number = #number cmra_data, cameras = #cameras cmra_data, cmraPT = SOME cmraT}\n    in thy |> \n      wrap_quick_and_dirtys_mode (fn thy => thy\n        |> def_resF cmraT |> def_inv pre_ipropT |> def_res cmraT |> def_iprop cmraT\n        |> Named_Target.theory_map (mk_defs cmra_data)\n      )\n    end\nend;\n\\<close>\n\ntype_synonym lockG = \"unit ex\"\n\nsetup \\<open>mk_iprop [(\\<^typ>\\<open>graphUR auth\\<close>, \"graph\"), (\\<^typ>\\<open>markingUR auth\\<close>, \"markings\"), \n  (\\<^typ>\\<open>heap_lang_proph_map\\<close>, \"proph\"), (\\<^typ>\\<open>lockG\\<close>, \"lock\")]\\<close>\n  \ntext \\<open>Again some experiments wrt the iprop fixed-point\\<close>\ndefinition inv_map :: \"('a::cofe \\<Rightarrow> 'b::cofe) \\<Rightarrow> ('a pre_inv \\<Rightarrow> 'b pre_inv)\" where \n  \"inv_map (f::'a\\<Rightarrow>'b) = map_prod (map_map_view (map_later f)) id\"\n\nlift_definition marking_map :: \"('a::cofe -n> 'b::cofe) \\<Rightarrow> (markingUR auth -n> markingUR auth)\" is\n  \"\\<lambda>_. id\" by (rule discrete_ne)\n\nlemma \"contractive marking_map\"\n  unfolding contr_contr_alt contractive_alt_def\n  apply transfer by (simp add: ofe_refl)\n\nlift_definition later_map :: \"('a::cofe -n> 'b::cofe) \\<Rightarrow> ('a later -n> 'b later)\" is\n  \"\\<lambda>(f::'a\\<Rightarrow>'b) (l::'a later). map_later f l\"\n  unfolding non_expansive_def\n  by (auto simp: n_equiv_later_def later.map_sel)\n\nlemma contr_later: \"contractive later_map\"\n  unfolding contr_contr_alt contractive_alt_def\n  apply transfer by (auto simp: later.map_sel n_equiv_later_def split: nat.split)\n\nlemma \"contr_ne f \\<Longrightarrow> contr_ne (later_map f)\"\napply transfer\nunfolding contr_contr_alt contractive_alt_def non_expansive_def\napply (auto simp: later.map_sel n_equiv_later_def split: nat.splits)\nby (metis Suc_pred)\n\nlift_definition ag_map :: \"('a::cofe -n> 'b::cofe) \\<Rightarrow> ('a ag -n> 'b ag)\" is\n  \"\\<lambda>(f::'a\\<Rightarrow>'b) (a::'a ag). map_ag f a\"\n  unfolding non_expansive_def\n  apply (auto simp: n_equiv_ag_def)\n  apply (smt (verit, best) image_iff map_ag.rep_eq)\n  by (smt (verit, best) ag.set_map image_iff)\n\nlemma \"contr_ne f \\<Longrightarrow> contr_ne (ag_map f)\"\napply transfer\nunfolding contr_contr_alt contractive_alt_def non_expansive_def\napply (auto simp: non_expansive_def n_equiv_ag_def image_iff map_ag.rep_eq ag.set_map split: nat.splits)\nusing Rep_ag apply fastforce\nusing Rep_ag apply fastforce\nby metis+\n\nlift_definition ag_map_contr :: \"('a::cofe -n> 'b::cofe) -c> ('a later -n> 'b later)\" is\n  \"later_map\" by (rule contr_later)\n  \nlocale T_iso = \nfixes to_iso :: \"'a::ofe \\<Rightarrow> 'b::ofe\" and from_iso :: \"'b \\<Rightarrow> 'a\"\nassumes isomorph1: \"ofe_eq (to_iso (from_iso x)) x\" and isomorph2: \"ofe_eq (from_iso (to_iso y)) y\"\n  and to_ne: \"non_expansive to_iso\" and from_ne: \"non_expansive from_iso\"\n  \nlemma \nassumes iso: \"T_iso to from\"\nshows \"n_equiv n x y \\<longleftrightarrow> n_equiv n (to x) (to y)\"\nproof \nassume \"n_equiv n x y\"\nfrom non_expansiveE[OF T_iso.to_ne[OF iso], OF this] show \"n_equiv n (to x) (to y)\" by simp\nnext\nassume \"n_equiv n (to x) (to y)\"\nfrom non_expansiveE[OF T_iso.from_ne[OF iso], OF this] have \"n_equiv n (from (to x)) (from (to y))\" \n  by simp\nwith T_iso.isomorph2[OF iso] show \"n_equiv n x y\"\nby (meson ofe_eq_equiv ofe_trans_eqL)\nqed\n  \nlemma \"\\<exists>(to_iso::markingUR auth\\<Rightarrow>markingUR auth) from_iso. T_iso to_iso from_iso\"\nproof -\nhave \"T_iso (id::markingUR auth \\<Rightarrow> markingUR auth) id\"\n  by (auto simp: T_iso_def ofe_refl non_expansive_def ofe_limit)\nthen show ?thesis by auto\nqed\n\nconsts isos :: \"('a::ofe pre_inv \\<Rightarrow> 'a) \\<times>('a \\<Rightarrow> 'a pre_inv)\"\nspecification (isos)\n  is_iso: \"T_iso (fst isos) (snd isos)\"\n  sorry\n\ntext \\<open>inG instance examples\\<close>\ninterpretation idInG: inG \"\\<lambda>\\<gamma> (m::gname \\<rightharpoonup> 'a::ucamera). m \\<gamma>\" \"\\<lambda>\\<gamma> x. [\\<gamma>\\<mapsto>x]\"\napply (auto simp: inG_def prod_n_valid_def \\<epsilon>_n_valid op_prod_def \\<epsilon>_left_id)\napply (auto simp: pcore_prod_def pcore_fun_def \\<epsilon>_fun_def \\<epsilon>_option_def pcore_option_def comp_def \n  split: option.splits)\nusing singleton_map_only_n_equiv by metis\n\ninterpretation invInG: inG get_inv constr_inv\n  apply (auto simp: inG_def get_inv_def constr_inv_def dest!: singleton_map_only_n_equiv)\n  apply (auto simp: d_equiv n_equiv_fun_def n_equiv_option_def prod_n_valid_def \\<epsilon>_n_valid op_prod_def \\<epsilon>_left_id)\n  by (auto simp: pcore_prod_def pcore_fun_def \\<epsilon>_fun_def \\<epsilon>_option_def pcore_option_def comp_def \n    constr_inv_def split: option.splits)\n\nglobal_interpretation lockInG: inG get_lock constr_lock\napply (auto simp: get_lock_def constr_lock_def d_equiv inG_def prod_n_valid_def \\<epsilon>_n_valid op_prod_def\n  \\<epsilon>_left_id intro: map_upd_eqD1)\nby (auto simp: pcore_prod_def pcore_fun_def \\<epsilon>_fun_def \\<epsilon>_option_def pcore_option_def comp_def\n  constr_lock_def singleton_map_n_incl split: option.splits)\n\nglobal_interpretation prophInG: inG get_proph constr_proph\napply (auto simp: get_proph_def constr_proph_def d_equiv inG_def prod_n_valid_def \\<epsilon>_n_valid op_prod_def\n  \\<epsilon>_left_id intro: map_upd_eqD1)\nby (auto simp: pcore_prod_def pcore_fun_def \\<epsilon>_fun_def \\<epsilon>_option_def pcore_option_def comp_def\n  constr_proph_def singleton_map_n_incl split: option.splits)\n\ncontext begin\nprivate lemma testlemma: \"inG (getter::gname\\<Rightarrow>'a::ucamera\\<Rightarrow>lockG option) put\n  \\<Longrightarrow> 1=2\" sorry\n  \nthm testlemma[OF lockInG.inG_axioms]\nend\nend", "meta": {"author": "firefighterduck", "repo": "isariris", "sha": "d02268e1e11cf681cae70b366b52843cbd90cc49", "save_path": "github-repos/isabelle/firefighterduck-isariris", "path": "github-repos/isabelle/firefighterduck-isariris/isariris-d02268e1e11cf681cae70b366b52843cbd90cc49/IrisCore/iPropShallow.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318337259584, "lm_q2_score": 0.4843800842769844, "lm_q1q2_score": 0.29253255251773347}}
{"text": "(*  Title:      HOL/Auth/Yahalom2.thy\n    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory\n    Copyright   1996  University of Cambridge\n*)\n\nsection{*The Yahalom Protocol, Variant 2*}\n\ntheory Yahalom2 imports Public begin\n\ntext{*\nThis version trades encryption of NB for additional explicitness in YM3.\nAlso in YM3, care is taken to make the two certificates distinct.\n\nFrom page 259 of\n  Burrows, Abadi and Needham (1989).  A Logic of Authentication.\n  Proc. Royal Soc. 426\n\nThis theory has the prototypical example of a secrecy relation, KeyCryptNonce.\n*}\n\ninductive_set yahalom :: \"event list set\"\n  where\n         (*Initial trace is empty*)\n   Nil:  \"[] \\<in> yahalom\"\n\n         (*The spy MAY say anything he CAN say.  We do not expect him to\n           invent new nonces here, but he can also use NS1.  Common to\n           all similar protocols.*)\n | Fake: \"[| evsf \\<in> yahalom;  X \\<in> synth (analz (knows Spy evsf)) |]\n          ==> Says Spy B X  # evsf \\<in> yahalom\"\n\n         (*A message that has been sent can be received by the\n           intended recipient.*)\n | Reception: \"[| evsr \\<in> yahalom;  Says A B X \\<in> set evsr |]\n               ==> Gets B X # evsr \\<in> yahalom\"\n\n         (*Alice initiates a protocol run*)\n | YM1:  \"[| evs1 \\<in> yahalom;  Nonce NA \\<notin> used evs1 |]\n          ==> Says A B {|Agent A, Nonce NA|} # evs1 \\<in> yahalom\"\n\n         (*Bob's response to Alice's message.*)\n | YM2:  \"[| evs2 \\<in> yahalom;  Nonce NB \\<notin> used evs2;\n             Gets B {|Agent A, Nonce NA|} \\<in> set evs2 |]\n          ==> Says B Server\n                  {|Agent B, Nonce NB, Crypt (shrK B) {|Agent A, Nonce NA|}|}\n                # evs2 \\<in> yahalom\"\n\n         (*The Server receives Bob's message.  He responds by sending a\n           new session key to Alice, with a certificate for forwarding to Bob.\n           Both agents are quoted in the 2nd certificate to prevent attacks!*)\n | YM3:  \"[| evs3 \\<in> yahalom;  Key KAB \\<notin> used evs3;\n             Gets Server {|Agent B, Nonce NB,\n                           Crypt (shrK B) {|Agent A, Nonce NA|}|}\n               \\<in> set evs3 |]\n          ==> Says Server A\n               {|Nonce NB,\n                 Crypt (shrK A) {|Agent B, Key KAB, Nonce NA|},\n                 Crypt (shrK B) {|Agent A, Agent B, Key KAB, Nonce NB|}|}\n                 # evs3 \\<in> yahalom\"\n\n         (*Alice receives the Server's (?) message, checks her Nonce, and\n           uses the new session key to send Bob his Nonce.*)\n | YM4:  \"[| evs4 \\<in> yahalom;\n             Gets A {|Nonce NB, Crypt (shrK A) {|Agent B, Key K, Nonce NA|},\n                      X|}  \\<in> set evs4;\n             Says A B {|Agent A, Nonce NA|} \\<in> set evs4 |]\n          ==> Says A B {|X, Crypt K (Nonce NB)|} # evs4 \\<in> yahalom\"\n\n         (*This message models possible leaks of session keys.  The nonces\n           identify the protocol run.  Quoting Server here ensures they are\n           correct. *)\n | Oops: \"[| evso \\<in> yahalom;\n             Says Server A {|Nonce NB,\n                             Crypt (shrK A) {|Agent B, Key K, Nonce NA|},\n                             X|}  \\<in> set evso |]\n          ==> Notes Spy {|Nonce NA, Nonce NB, Key K|} # evso \\<in> yahalom\"\n\n\ndeclare Says_imp_knows_Spy [THEN analz.Inj, dest]\ndeclare parts.Body  [dest]\ndeclare Fake_parts_insert_in_Un  [dest]\ndeclare analz_into_parts [dest]\n\ntext{*A \"possibility property\": there are traces that reach the end*}\nlemma \"Key K \\<notin> used []\n       ==> \\<exists>X NB. \\<exists>evs \\<in> yahalom.\n             Says A B {|X, Crypt K (Nonce NB)|} \\<in> set evs\"\napply (intro exI bexI)\napply (rule_tac [2] yahalom.Nil\n                    [THEN yahalom.YM1, THEN yahalom.Reception,\n                     THEN yahalom.YM2, THEN yahalom.Reception,\n                     THEN yahalom.YM3, THEN yahalom.Reception,\n                     THEN yahalom.YM4])\napply (possibility, simp add: used_Cons)\ndone\n\nlemma Gets_imp_Says:\n     \"[| Gets B X \\<in> set evs; evs \\<in> yahalom |] ==> \\<exists>A. Says A B X \\<in> set evs\"\nby (erule rev_mp, erule yahalom.induct, auto)\n\ntext{*Must be proved separately for each protocol*}\nlemma Gets_imp_knows_Spy:\n     \"[| Gets B X \\<in> set evs; evs \\<in> yahalom |]  ==> X \\<in> knows Spy evs\"\nby (blast dest!: Gets_imp_Says Says_imp_knows_Spy)\n\ndeclare Gets_imp_knows_Spy [THEN analz.Inj, dest]\n\n\nsubsection{*Inductive Proofs*}\n\ntext{*Result for reasoning about the encrypted portion of messages.\nLets us treat YM4 using a similar argument as for the Fake case.*}\nlemma YM4_analz_knows_Spy:\n     \"[| Gets A {|NB, Crypt (shrK A) Y, X|} \\<in> set evs;  evs \\<in> yahalom |]\n      ==> X \\<in> analz (knows Spy evs)\"\nby blast\n\nlemmas YM4_parts_knows_Spy =\n       YM4_analz_knows_Spy [THEN analz_into_parts]\n\n\n(** Theorems of the form X \\<notin> parts (knows Spy evs) imply that NOBODY\n    sends messages containing X! **)\n\ntext{*Spy never sees a good agent's shared key!*}\nlemma Spy_see_shrK [simp]:\n     \"evs \\<in> yahalom ==> (Key (shrK A) \\<in> parts (knows Spy evs)) = (A \\<in> bad)\"\nby (erule yahalom.induct, force,\n    drule_tac [6] YM4_parts_knows_Spy, simp_all, blast+)\n\nlemma Spy_analz_shrK [simp]:\n     \"evs \\<in> yahalom ==> (Key (shrK A) \\<in> analz (knows Spy evs)) = (A \\<in> bad)\"\nby auto\n\nlemma Spy_see_shrK_D [dest!]:\n     \"[|Key (shrK A) \\<in> parts (knows Spy evs);  evs \\<in> yahalom|] ==> A \\<in> bad\"\nby (blast dest: Spy_see_shrK)\n\ntext{*Nobody can have used non-existent keys!  \n    Needed to apply @{text analz_insert_Key}*}\nlemma new_keys_not_used [simp]:\n    \"[|Key K \\<notin> used evs; K \\<in> symKeys; evs \\<in> yahalom|]\n     ==> K \\<notin> keysFor (parts (spies evs))\"\napply (erule rev_mp)\napply (erule yahalom.induct, force,\n       frule_tac [6] YM4_parts_knows_Spy, simp_all)\ntxt{*Fake*}\napply (force dest!: keysFor_parts_insert)\ntxt{*YM3*}\napply blast\ntxt{*YM4*}\napply auto\napply (blast dest!: Gets_imp_knows_Spy [THEN parts.Inj])\ndone\n\n\ntext{*Describes the form of K when the Server sends this message.  Useful for\n  Oops as well as main secrecy property.*}\nlemma Says_Server_message_form:\n     \"[| Says Server A {|nb', Crypt (shrK A) {|Agent B, Key K, na|}, X|}\n          \\<in> set evs;  evs \\<in> yahalom |]\n      ==> K \\<notin> range shrK\"\nby (erule rev_mp, erule yahalom.induct, simp_all)\n\n\n(****\n The following is to prove theorems of the form\n\n          Key K \\<in> analz (insert (Key KAB) (knows Spy evs)) ==>\n          Key K \\<in> analz (knows Spy evs)\n\n A more general formula must be proved inductively.\n****)\n\n(** Session keys are not used to encrypt other session keys **)\n\nlemma analz_image_freshK [rule_format]:\n \"evs \\<in> yahalom ==>\n   \\<forall>K KK. KK <= - (range shrK) -->\n          (Key K \\<in> analz (Key`KK Un (knows Spy evs))) =\n          (K \\<in> KK | Key K \\<in> analz (knows Spy evs))\"\napply (erule yahalom.induct)\napply (frule_tac [8] Says_Server_message_form)\napply (drule_tac [7] YM4_analz_knows_Spy, analz_freshK, spy_analz, blast)\ndone\n\nlemma analz_insert_freshK:\n     \"[| evs \\<in> yahalom;  KAB \\<notin> range shrK |] ==>\n      (Key K \\<in> analz (insert (Key KAB) (knows Spy evs))) =\n      (K = KAB | Key K \\<in> analz (knows Spy evs))\"\nby (simp only: analz_image_freshK analz_image_freshK_simps)\n\n\ntext{*The Key K uniquely identifies the Server's  message*}\nlemma unique_session_keys:\n     \"[| Says Server A\n          {|nb, Crypt (shrK A) {|Agent B, Key K, na|}, X|} \\<in> set evs;\n        Says Server A'\n          {|nb', Crypt (shrK A') {|Agent B', Key K, na'|}, X'|} \\<in> set evs;\n        evs \\<in> yahalom |]\n     ==> A=A' & B=B' & na=na' & nb=nb'\"\napply (erule rev_mp, erule rev_mp)\napply (erule yahalom.induct, simp_all)\ntxt{*YM3, by freshness*}\napply blast\ndone\n\n\nsubsection{*Crucial Secrecy Property: Spy Does Not See Key @{term KAB}*}\n\nlemma secrecy_lemma:\n     \"[| A \\<notin> bad;  B \\<notin> bad;  evs \\<in> yahalom |]\n      ==> Says Server A\n            {|nb, Crypt (shrK A) {|Agent B, Key K, na|},\n                  Crypt (shrK B) {|Agent A, Agent B, Key K, nb|}|}\n           \\<in> set evs -->\n          Notes Spy {|na, nb, Key K|} \\<notin> set evs -->\n          Key K \\<notin> analz (knows Spy evs)\"\napply (erule yahalom.induct, force, frule_tac [7] Says_Server_message_form,\n       drule_tac [6] YM4_analz_knows_Spy)\napply (simp_all add: pushes analz_insert_eq analz_insert_freshK, spy_analz)\napply (blast dest: unique_session_keys)+  (*YM3, Oops*)\ndone\n\n\ntext{*Final version*}\nlemma Spy_not_see_encrypted_key:\n     \"[| Says Server A\n            {|nb, Crypt (shrK A) {|Agent B, Key K, na|},\n                  Crypt (shrK B) {|Agent A, Agent B, Key K, nb|}|}\n         \\<in> set evs;\n         Notes Spy {|na, nb, Key K|} \\<notin> set evs;\n         A \\<notin> bad;  B \\<notin> bad;  evs \\<in> yahalom |]\n      ==> Key K \\<notin> analz (knows Spy evs)\"\nby (blast dest: secrecy_lemma Says_Server_message_form)\n\n\n\ntext{*This form is an immediate consequence of the previous result.  It is\nsimilar to the assertions established by other methods.  It is equivalent\nto the previous result in that the Spy already has @{term analz} and\n@{term synth} at his disposal.  However, the conclusion\n@{term \"Key K \\<notin> knows Spy evs\"} appears not to be inductive: all the cases\nother than Fake are trivial, while Fake requires\n@{term \"Key K \\<notin> analz (knows Spy evs)\"}. *}\nlemma Spy_not_know_encrypted_key:\n     \"[| Says Server A\n            {|nb, Crypt (shrK A) {|Agent B, Key K, na|},\n                  Crypt (shrK B) {|Agent A, Agent B, Key K, nb|}|}\n         \\<in> set evs;\n         Notes Spy {|na, nb, Key K|} \\<notin> set evs;\n         A \\<notin> bad;  B \\<notin> bad;  evs \\<in> yahalom |]\n      ==> Key K \\<notin> knows Spy evs\"\nby (blast dest: Spy_not_see_encrypted_key)\n\n\nsubsection{*Security Guarantee for A upon receiving YM3*}\n\ntext{*If the encrypted message appears then it originated with the Server.\n  May now apply @{text Spy_not_see_encrypted_key}, subject to its conditions.*}\nlemma A_trusts_YM3:\n     \"[| Crypt (shrK A) {|Agent B, Key K, na|} \\<in> parts (knows Spy evs);\n         A \\<notin> bad;  evs \\<in> yahalom |]\n      ==> \\<exists>nb. Says Server A\n                    {|nb, Crypt (shrK A) {|Agent B, Key K, na|},\n                          Crypt (shrK B) {|Agent A, Agent B, Key K, nb|}|}\n                  \\<in> set evs\"\napply (erule rev_mp)\napply (erule yahalom.induct, force,\n       frule_tac [6] YM4_parts_knows_Spy, simp_all)\ntxt{*Fake, YM3*}\napply blast+\ndone\n\ntext{*The obvious combination of @{text A_trusts_YM3} with \n@{text Spy_not_see_encrypted_key}*}\ntheorem A_gets_good_key:\n     \"[| Crypt (shrK A) {|Agent B, Key K, na|} \\<in> parts (knows Spy evs);\n         \\<forall>nb. Notes Spy {|na, nb, Key K|} \\<notin> set evs;\n         A \\<notin> bad;  B \\<notin> bad;  evs \\<in> yahalom |]\n      ==> Key K \\<notin> analz (knows Spy evs)\"\nby (blast dest!: A_trusts_YM3 Spy_not_see_encrypted_key)\n\n\nsubsection{*Security Guarantee for B upon receiving YM4*}\n\ntext{*B knows, by the first part of A's message, that the Server distributed\n  the key for A and B, and has associated it with NB.*}\nlemma B_trusts_YM4_shrK:\n     \"[| Crypt (shrK B) {|Agent A, Agent B, Key K, Nonce NB|}\n           \\<in> parts (knows Spy evs);\n         B \\<notin> bad;  evs \\<in> yahalom |]\n  ==> \\<exists>NA. Says Server A\n             {|Nonce NB,\n               Crypt (shrK A) {|Agent B, Key K, Nonce NA|},\n               Crypt (shrK B) {|Agent A, Agent B, Key K, Nonce NB|}|}\n             \\<in> set evs\"\napply (erule rev_mp)\napply (erule yahalom.induct, force,\n       frule_tac [6] YM4_parts_knows_Spy, simp_all)\ntxt{*Fake, YM3*}\napply blast+\ndone\n\n\ntext{*With this protocol variant, we don't need the 2nd part of YM4 at all:\n  Nonce NB is available in the first part.*}\n\ntext{*What can B deduce from receipt of YM4?  Stronger and simpler than Yahalom\n  because we do not have to show that NB is secret. *}\nlemma B_trusts_YM4:\n     \"[| Gets B {|Crypt (shrK B) {|Agent A, Agent B, Key K, Nonce NB|},  X|}\n           \\<in> set evs;\n         A \\<notin> bad;  B \\<notin> bad;  evs \\<in> yahalom |]\n  ==> \\<exists>NA. Says Server A\n             {|Nonce NB,\n               Crypt (shrK A) {|Agent B, Key K, Nonce NA|},\n               Crypt (shrK B) {|Agent A, Agent B, Key K, Nonce NB|}|}\n            \\<in> set evs\"\nby (blast dest!: B_trusts_YM4_shrK)\n\n\ntext{*The obvious combination of @{text B_trusts_YM4} with \n@{text Spy_not_see_encrypted_key}*}\ntheorem B_gets_good_key:\n     \"[| Gets B {|Crypt (shrK B) {|Agent A, Agent B, Key K, Nonce NB|}, X|}\n           \\<in> set evs;\n         \\<forall>na. Notes Spy {|na, Nonce NB, Key K|} \\<notin> set evs;\n         A \\<notin> bad;  B \\<notin> bad;  evs \\<in> yahalom |]\n      ==> Key K \\<notin> analz (knows Spy evs)\"\nby (blast dest!: B_trusts_YM4 Spy_not_see_encrypted_key)\n\n\nsubsection{*Authenticating B to A*}\n\ntext{*The encryption in message YM2 tells us it cannot be faked.*}\nlemma B_Said_YM2:\n     \"[| Crypt (shrK B) {|Agent A, Nonce NA|} \\<in> parts (knows Spy evs);\n         B \\<notin> bad;  evs \\<in> yahalom |]\n      ==> \\<exists>NB. Says B Server {|Agent B, Nonce NB,\n                               Crypt (shrK B) {|Agent A, Nonce NA|}|}\n                      \\<in> set evs\"\napply (erule rev_mp)\napply (erule yahalom.induct, force,\n       frule_tac [6] YM4_parts_knows_Spy, simp_all)\ntxt{*Fake, YM2*}\napply blast+\ndone\n\n\ntext{*If the server sends YM3 then B sent YM2, perhaps with a different NB*}\nlemma YM3_auth_B_to_A_lemma:\n     \"[| Says Server A {|nb, Crypt (shrK A) {|Agent B, Key K, Nonce NA|}, X|}\n           \\<in> set evs;\n         B \\<notin> bad;  evs \\<in> yahalom |]\n      ==> \\<exists>nb'. Says B Server {|Agent B, nb',\n                                   Crypt (shrK B) {|Agent A, Nonce NA|}|}\n                       \\<in> set evs\"\napply (erule rev_mp)\napply (erule yahalom.induct, simp_all)\ntxt{*Fake, YM2, YM3*}\napply (blast dest!: B_Said_YM2)+\ndone\n\ntext{*If A receives YM3 then B has used nonce NA (and therefore is alive)*}\ntheorem YM3_auth_B_to_A:\n     \"[| Gets A {|nb, Crypt (shrK A) {|Agent B, Key K, Nonce NA|}, X|}\n           \\<in> set evs;\n         A \\<notin> bad;  B \\<notin> bad;  evs \\<in> yahalom |]\n ==> \\<exists>nb'. Says B Server\n                  {|Agent B, nb', Crypt (shrK B) {|Agent A, Nonce NA|}|}\n               \\<in> set evs\"\nby (blast dest!: A_trusts_YM3 YM3_auth_B_to_A_lemma)\n\n\nsubsection{*Authenticating A to B*}\n\ntext{*using the certificate @{term \"Crypt K (Nonce NB)\"}*}\n\ntext{*Assuming the session key is secure, if both certificates are present then\n  A has said NB.  We can't be sure about the rest of A's message, but only\n  NB matters for freshness.  Note that @{term \"Key K \\<notin> analz (knows Spy evs)\"}\n  must be the FIRST antecedent of the induction formula.*}\n\ntext{*This lemma allows a use of @{text unique_session_keys} in the next proof,\n  which otherwise is extremely slow.*}\nlemma secure_unique_session_keys:\n     \"[| Crypt (shrK A) {|Agent B, Key K, na|} \\<in> analz (spies evs);\n         Crypt (shrK A') {|Agent B', Key K, na'|} \\<in> analz (spies evs);\n         Key K \\<notin> analz (knows Spy evs);  evs \\<in> yahalom |]\n     ==> A=A' & B=B'\"\nby (blast dest!: A_trusts_YM3 dest: unique_session_keys Crypt_Spy_analz_bad)\n\n\nlemma Auth_A_to_B_lemma [rule_format]:\n     \"evs \\<in> yahalom\n      ==> Key K \\<notin> analz (knows Spy evs) -->\n          K \\<in> symKeys -->\n          Crypt K (Nonce NB) \\<in> parts (knows Spy evs) -->\n          Crypt (shrK B) {|Agent A, Agent B, Key K, Nonce NB|}\n            \\<in> parts (knows Spy evs) -->\n          B \\<notin> bad -->\n          (\\<exists>X. Says A B {|X, Crypt K (Nonce NB)|} \\<in> set evs)\"\napply (erule yahalom.induct, force,\n       frule_tac [6] YM4_parts_knows_Spy)\napply (analz_mono_contra, simp_all)\ntxt{*Fake*}\napply blast\ntxt{*YM3: by @{text new_keys_not_used}, the message\n   @{term \"Crypt K (Nonce NB)\"} could not exist*}\napply (force dest!: Crypt_imp_keysFor)\ntxt{*YM4: was   @{term \"Crypt K (Nonce NB)\"} the very last message?  If so, \n    apply unicity of session keys; if not, use the induction hypothesis*}\napply (blast dest!: B_trusts_YM4_shrK dest: secure_unique_session_keys)\ndone\n\n\ntext{*If B receives YM4 then A has used nonce NB (and therefore is alive).\n  Moreover, A associates K with NB (thus is talking about the same run).\n  Other premises guarantee secrecy of K.*}\ntheorem YM4_imp_A_Said_YM3 [rule_format]:\n     \"[| Gets B {|Crypt (shrK B) {|Agent A, Agent B, Key K, Nonce NB|},\n                  Crypt K (Nonce NB)|} \\<in> set evs;\n         (\\<forall>NA. Notes Spy {|Nonce NA, Nonce NB, Key K|} \\<notin> set evs);\n         K \\<in> symKeys;  A \\<notin> bad;  B \\<notin> bad;  evs \\<in> yahalom |]\n      ==> \\<exists>X. Says A B {|X, Crypt K (Nonce NB)|} \\<in> set evs\"\nby (blast intro: Auth_A_to_B_lemma\n          dest: Spy_not_see_encrypted_key B_trusts_YM4_shrK)\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/Auth/Yahalom2.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.603931819468636, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.29253254561177044}}
{"text": "(*\n * Copyright (C) 2014, National ICT Australia Limited. All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are\n * met:\n *\n *  * Redistributions of source code must retain the above copyright\n *    notice, this list of conditions and the following disclaimer.\n *\n *  * Redistributions in binary form must reproduce the above copyright\n *    notice, this list of conditions and the following disclaimer in the\n *    documentation and/or other materials provided with the distribution.\n *\n *  * The name of National ICT Australia Limited nor the names of its\n *    contributors may be used to endorse or promote products derived from\n *    this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS\n * IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\n * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A\n * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n *)\n\nheader \"Machine Word Setup\"\n\ntheory WordSetup\nimports WordEnum DistinctProp\n\nbegin\n\ntext {* This theory defines the standard platform-specific word size\nand alignment. *}\n\ndefinition\n  word_bits :: nat where\n  \"word_bits \\<equiv> len_of TYPE(32)\"\n\ndefinition\n  word_size :: \"'a :: numeral\" where\n  \"word_size \\<equiv> 4\"\n\nlemma word_bits_conv:\n  \"word_bits = 32\" unfolding word_bits_def by simp\n\nlemma word_bits_word_size_conv:\n  \"word_bits = word_size * 8\"\n  unfolding word_bits_def word_size_def by simp\n\ndefinition\n  is_aligned :: \"'a :: len word \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"is_aligned ptr n \\<equiv> 2^n dvd unat ptr\"\n\ndefinition\n  ptr_add :: \"word32 \\<Rightarrow> nat \\<Rightarrow> word32\" where\n  \"ptr_add ptr n \\<equiv> ptr + of_nat n\"\n\ndefinition\n  complement :: \"('a :: len) word \\<Rightarrow> 'a word\"  where\n \"complement x \\<equiv> x xor -1\"\n\ndefinition\n  alignUp :: \"'a::len word \\<Rightarrow> nat \\<Rightarrow> 'a word\" where\n \"alignUp x n \\<equiv> x + 2 ^ n - 1 && complement (2 ^ n - 1)\"\n\nend\n", "meta": {"author": "jcaesar", "repo": "fixed-topos-header-space-analysis", "sha": "2da808ab41e5924d616ad1af15e8f50cb986c803", "save_path": "github-repos/isabelle/jcaesar-fixed-topos-header-space-analysis", "path": "github-repos/isabelle/jcaesar-fixed-topos-header-space-analysis/fixed-topos-header-space-analysis-2da808ab41e5924d616ad1af15e8f50cb986c803/thy/autocorres-0.98/lib/WordSetup.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318194686359, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.2925325456117704}}
{"text": "section \\<open>Helper theory for using the main passification global block theorem\\<close>\n\ntheory PassificationEndToEnd\nimports  Semantics Util Passification VCExprHelper\nbegin\n\nsubsection \\<open>Picking an initial set of target states\\<close>\n\ntext \\<open>The global block theorem for the entry block in the passification phase states the following:\nGiven an initial source state s (in the non-passified program) and given a non-empty set of initial target\nstates U (in the passive program) that are related to s (w.r.t. the initial variable relation), then\nit holds for any source execution from s, there is at least target execution from some state in U\nthat simulates this source execution (there are some more properties on U that we do not mention here,\nsee \\<^const>\\<open>passive_lemma_assms_2\\<close>).\n\nFrom the VC phase we know that no target execution can fail if the VC holds. In our proof generation, \nwe use this result together with the global entry block theorem in the passification phase to get that:\nIf the VC holds, then there cannot be any failing source execution in the non-passified program).\n\nTo obtain this result, we must instantiate U such that every state in U is a feasible initial\ntarget state and satisfies all other properties. This subsection provides the definitions and lemmas\nto do so.\\<close>\n\nfun initial_set :: \"'a absval_ty_fun \\<Rightarrow> passive_rel \\<Rightarrow> var_context \\<Rightarrow> var_context \\<Rightarrow> rtype_env \\<Rightarrow> 'a nstate \\<Rightarrow> ('a nstate) set\"\n  where \"initial_set A R \\<Lambda> \\<Lambda>' \\<Omega> ns = \n              {u. state_typ_wf A \\<Omega> (local_state u) (snd \\<Lambda>') \\<and> state_typ_wf A \\<Omega> (global_state u) (fst \\<Lambda>') \\<and>\n              (\\<forall>x y. R x = Some (Inl y) \\<longrightarrow> lookup_var \\<Lambda> ns x = lookup_var \\<Lambda>' u y) \\<and> (\\<forall> x y. map_of (fst \\<Lambda>) x = Some y \\<longrightarrow> (global_state u) x = (global_state ns) x) \\<and>\n              binder_state u = Map.empty}\"\n\ntext \\<open>We instantiate U with \\<^const>\\<open>initial_set\\<close>\\<close>\n\ntext \\<open>Next we construct a state that is in the selected U to show that U is non-empty under certain assumptions (\nthat we can prove when validating the passification phase) and that U satisfies the necessary properties.\\<close>\n\nfun initial_state_local :: \"'a absval_ty_fun \\<Rightarrow> rtype_env \\<Rightarrow> passive_rel \\<Rightarrow> var_context \\<Rightarrow> var_context \\<Rightarrow> 'a nstate \\<Rightarrow> 'a named_state\"\n  where \"initial_state_local A \\<Omega> R \\<Lambda> \\<Lambda>' ns x = \n         (case (map_of (snd \\<Lambda>') x) of Some tw =>\n           (if (\\<exists>z. R z = Some (Inl x)) then \n              lookup_var \\<Lambda> ns (SOME z. R z = Some (Inl x)) \n            else \n              Some (val_of_type A (instantiate \\<Omega> (fst tw)))\n           )\n          | None \\<Rightarrow> None)\"\n\nfun initial_state_global :: \"'a absval_ty_fun \\<Rightarrow> rtype_env \\<Rightarrow> passive_rel \\<Rightarrow> var_context \\<Rightarrow> var_context \\<Rightarrow> 'a nstate \\<Rightarrow> 'a named_state\"\n  where \"initial_state_global A \\<Omega> R \\<Lambda> \\<Lambda>' ns x = \n           (case (map_of (fst \\<Lambda>') x) of Some tw =>\n           (if (\\<exists>z. R z = Some (Inl x)) then \n              lookup_var \\<Lambda> ns (SOME z. R z = Some (Inl x)) \n            else \n              ( Some (val_of_type A (instantiate \\<Omega> (fst tw))))             \n           )\n          | None \\<Rightarrow> None)\"\n\ndefinition rel_range\n  where \"rel_range R = {y. \\<exists>x. R x = Some (Inl y)}\"\n\ndefinition inj_on_defined \n  where \"inj_on_defined R = (\\<forall> x y z. R x = R y \\<and> R x = Some (Inl z) \\<longrightarrow> x = y)\"\n\nlemma initial_state_lookup: \n  assumes InjAssm:\"inj_on_defined R\" and \"R x = Some (Inl y)\" and \"map_of (snd \\<Lambda>') y = Some vd\"\n  shows \"initial_state_local A \\<Omega> R \\<Lambda> \\<Lambda>' ns y = lookup_var \\<Lambda> ns x\" (is \"?u y = lookup_var \\<Lambda> ns x\")\nproof -\n  from \\<open>R x = Some (Inl y)\\<close> \\<open>map_of (snd \\<Lambda>') y = Some vd\\<close> have \"?u y = (lookup_var \\<Lambda> ns (SOME z. R z = Some (Inl y)))\" by auto\n  thus \"?u y = lookup_var \\<Lambda> ns x\" using InjAssm\n    unfolding inj_on_defined_def\n    by (metis (full_types, lifting) assms(2) tfl_some)       \nqed\n\nlemma initial_state_global_lookup: \n  assumes InjAssm: \"inj_on_defined R\" and \"R x = Some (Inl y)\" and \"map_of (fst \\<Lambda>') y = Some vd\"\n  shows \"initial_state_global A \\<Omega> R \\<Lambda> \\<Lambda>' ns y = lookup_var \\<Lambda> ns x\" (is \"?u y = lookup_var \\<Lambda> ns x\")\nproof -\n  from \\<open>R x = Some (Inl y)\\<close> \\<open>map_of (fst \\<Lambda>') y = Some vd\\<close> have \"?u y = (lookup_var \\<Lambda> ns (SOME z. R z = Some (Inl y)))\" \n    by auto\n  thus \"?u y = lookup_var \\<Lambda> ns x\" using InjAssm\n    unfolding inj_on_defined_def\n    by (metis (full_types, lifting) assms(2) tfl_some)    \nqed\n\ntext \\<open>The following lemma shows the set we pick for U is non-empty under certain assumptions.\\<close>\nlemma init_state_elem_init_set:\n  assumes \n          NonEmptyTypes:\"\\<And> t. closed t \\<Longrightarrow> \\<exists>v. type_of_val A v = t\" and\n          Closed:\"\\<And>y \\<tau>. \\<not>(\\<exists> x. R x = Some (Inl y)) \\<Longrightarrow> lookup_var_ty \\<Lambda>' y = Some \\<tau> \\<Longrightarrow> closed (instantiate \\<Omega> \\<tau>)\" and          \n          RelTy:\"\\<And>x y. R x = Some (Inl y) \\<Longrightarrow> lookup_var_ty \\<Lambda> x = lookup_var_ty \\<Lambda>' y\" and\n          RelWt:\"rel_well_typed A \\<Lambda> \\<Omega> R ns\" and\n          InjAssm:\"inj_on_defined R\" and\n          GlobalsSame: \"fst \\<Lambda> = fst \\<Lambda>'\" and\n          WellTyp: \"(state_typ_wf A \\<Omega> (global_state ns) (fst \\<Lambda>))\" and\n       (* since the initial state's global state is the same as for n_s (otherwise the axiom assumption cannot be satisfied)\n          the lemma requires that that R maps globals to globals (otherwise it cannot be shown that ns and u respect R)*)\n          RelGlobalsSame: \"\\<forall>x y. R x = Some (Inl y) \\<longrightarrow> map_of (fst \\<Lambda>') y \\<noteq> None \\<longrightarrow> x = y\" and \n       (* no shadowing *)\n          ConstsDisj:\"set (map fst (fst \\<Lambda>)) \\<inter> set (map fst (snd \\<Lambda>)) = {}\" and\n          ConstsDisj2:\"set (map fst (fst \\<Lambda>')) \\<inter> set (map fst (snd \\<Lambda>')) = {}\"\n        shows \"\\<lparr>old_global_state = Map.empty, \n               global_state = global_state ns, \n               local_state = (initial_state_local A \\<Omega> R \\<Lambda> \\<Lambda>' ns), \n               binder_state = Map.empty \\<rparr> \\<in> initial_set A R \\<Lambda> \\<Lambda>' \\<Omega> ns\" (is \"?u \\<in> ?U\")\nproof (simp only: initial_set.simps, rule, intro conjI)\n  show \"state_typ_wf A \\<Omega> (local_state ?u) (snd \\<Lambda>')\"\n    unfolding state_typ_wf_def\n  proof ((rule allI)+, rule impI)\n    fix y \\<tau>\n    assume localy:\"lookup_vdecls_ty (snd \\<Lambda>') y = Some \\<tau>\"\n    hence LookupTyY:\"lookup_var_ty \\<Lambda>' y = Some \\<tau>\"\n      by (simp add: lookup_vdecls_ty_local_3)           \n    show \"map_option (type_of_val A) (local_state ?u y) = Some (instantiate \\<Omega> \\<tau>)\"\n    proof (cases \"\\<exists>x. R x = Some (Inl y)\")\n      case True\n      from this obtain x where \"R x = Some (Inl y)\" by auto\n      hence LookupUY:\"local_state ?u y = lookup_var \\<Lambda> ns x\"\n        by (metis InjAssm LookupTyY initial_state_lookup localy lookup_var_decl_local_2 lookup_var_ty_decl_Some lookup_vdecls_ty_def map_option_is_None nstate.select_convs(3) option.discI)\n      from RelTy RelWt obtain v where\n              \"lookup_var \\<Lambda> ns x = Some v\" and \"type_of_val A v = instantiate \\<Omega> \\<tau>\"\n        unfolding rel_well_typed_def using LookupTyY \\<open>R x = Some (Inl y)\\<close>\n        by fastforce \n      thus ?thesis using LookupUY by auto\n    next\n      case False\n      hence \"local_state ?u y = Some (val_of_type A (instantiate \\<Omega> \\<tau>))\"\n        using localy lookup_vdecls_ty_map_of\n        by fastforce        \n      thus ?thesis using  False LookupTyY Closed val_of_type_correct NonEmptyTypes\n        by blast      \n    qed\n  qed\nnext\n  show \"state_typ_wf A \\<Omega> (global_state ?u) (fst \\<Lambda>')\" using WellTyp GlobalsSame by simp\nnext\n  show \"\\<forall> x y. R x = Some (Inl y) \\<longrightarrow> lookup_var \\<Lambda> ns x = lookup_var \\<Lambda>' ?u y\"\n  proof (rule+)\n    fix x y\n    assume \"R x = Some (Inl y)\"\n    hence SameTy:\"lookup_var_ty \\<Lambda> x = lookup_var_ty \\<Lambda>' y\" using RelTy by simp\n    moreover from \\<open>R x = Some (Inl y)\\<close> RelWt obtain \\<tau> where LookupX:\"lookup_var_ty \\<Lambda> x = Some \\<tau>\"\n      by (meson rel_well_typed_def)\n    hence \"lookup_var_ty \\<Lambda>' y = Some \\<tau>\" using RelTy[OF \\<open>R x = Some (Inl y)\\<close>] by simp    \n    show \"lookup_var \\<Lambda> ns x = lookup_var \\<Lambda>' ?u y\"\n    proof (cases \"map_of (snd \\<Lambda>') y = None\")\n      case True\n      hence global_y:\"lookup_vdecls_ty (fst \\<Lambda>') y = Some \\<tau>\" using \\<open>lookup_var_ty \\<Lambda>' y = Some \\<tau>\\<close> \n        using lookup_vdecls_ty_global_5 by simp\n      from True have \"lookup_var \\<Lambda>' ?u y = global_state ?u y\"\n        by (simp add: lookup_var_def)\n      hence lookup_global_u:\"lookup_var \\<Lambda>' ?u y = global_state ns y\" by simp\n      moreover from global_y have \"map_of (snd \\<Lambda>) y = None\" using ConstsDisj \n        by (metis GlobalsSame disjoint_iff list.set_map lookup_vdecls_ty_map_of map_of_eq_None_iff option.discI)        \n      ultimately have \"lookup_var \\<Lambda> ns y = (global_state ns) y\" by (simp add: lookup_var_def)\n      with lookup_global_u have \"lookup_var \\<Lambda> ns y = lookup_var \\<Lambda>' ?u y\" by simp\n      moreover from \\<open>lookup_vdecls_ty (fst \\<Lambda>') y = Some \\<tau>\\<close> \\<open>R x = Some (Inl y)\\<close> RelGlobalsSame have \"x = y\"\n        using lookup_vdecls_ty_map_of by fastforce\n      ultimately show ?thesis by simp\n    next\n      case False\n      hence \"lookup_var \\<Lambda>' ?u y = local_state ?u y\"\n        by (metis lookup_var_local option.exhaust_sel prod.collapse)      \n      hence \"\\<dots> = (lookup_var \\<Lambda> ns (SOME z. R z = Some (Inl y)))\" using \\<open>R x = Some (Inl y)\\<close> False by auto      \n      then show ?thesis using InjAssm \\<open>R x = Some (Inl y)\\<close> initial_state_lookup\n        by (metis False \\<open>lookup_var \\<Lambda>' ?u y = local_state ?u y\\<close> nstate.select_convs(3) option.collapse)\n    qed\n  qed\nnext\n  show \"\\<forall>x y. map_of (fst \\<Lambda>) x = Some y \\<longrightarrow> (global_state ?u) x = (global_state ns) x\" by simp\nnext\n  show \"binder_state ?u = Map.empty\"\n    by simp\nqed\n\nlemma init_set_non_empty:\n  assumes NonEmptyTypes:\"\\<And> t. closed t \\<Longrightarrow> \\<exists>v. type_of_val A v = t\" and\n          Closed:\"\\<And>y \\<tau>. \\<not>(\\<exists> x. R x = Some (Inl y)) \\<Longrightarrow> lookup_var_ty \\<Lambda>' y = Some \\<tau> \\<Longrightarrow> closed (instantiate \\<Omega> \\<tau>)\" and          \n          RelTy:\"\\<And>x y. R x = Some (Inl y) \\<Longrightarrow> lookup_var_ty \\<Lambda> x = lookup_var_ty \\<Lambda>' y\" and\n          RelWt:\"rel_well_typed A \\<Lambda> \\<Omega> R ns\" and\n          InjAssm:\"inj_on_defined R\" and\n          GlobalsSame: \"fst \\<Lambda> = fst \\<Lambda>'\" and\n          WellTyp: \"(state_typ_wf A \\<Omega> (global_state ns) (fst \\<Lambda>))\" and\n          RelGlobalsSame: \"\\<forall>x y. R x = Some (Inl y) \\<longrightarrow> map_of (fst \\<Lambda>') y \\<noteq> None \\<longrightarrow> x = y\" and \n          ConstsDisj:\"set (map fst (fst \\<Lambda>)) \\<inter> set (map fst (snd \\<Lambda>)) = {}\" and\n          ConstsDisj2:\"set (map fst (fst \\<Lambda>')) \\<inter> set (map fst (snd \\<Lambda>')) = {}\"\n  shows \"initial_set A R \\<Lambda> \\<Lambda>' \\<Omega> ns \\<noteq> {}\"\n  using assms init_state_elem_init_set by blast\n\ntext \\<open>Next, we show that U has the remaining desired properties.\\<close>\n\nlemma init_state_dependent:\"dependent A \\<Lambda>' \\<Omega> (initial_set A R \\<Lambda> \\<Lambda>' \\<Omega> ns) ((rel_range R) \\<union> set (map fst (fst \\<Lambda>)))\" \n         (is \"dependent A \\<Lambda>' \\<Omega> ?U ((rel_range R) \\<union> set (map fst (fst \\<Lambda>))) \")\n  unfolding dependent_def closed_set_ty_def\n  proof (rule ballI, rule allI, rule allI, rule impI, rule conjI[OF _ impI[OF allI[OF impI]]])\n    fix u \\<tau> d\n    assume \"u \\<in> ?U\"\n    hence S1:\"state_typ_wf A \\<Omega> (local_state u) (snd \\<Lambda>')\" and S2:\"state_typ_wf A \\<Omega> (global_state u) (fst \\<Lambda>')\" by auto\n    assume LookupTy:\"lookup_var_ty \\<Lambda>' d = Some \\<tau>\"\n    thus \"lookup_var_ty_match A \\<Lambda>' \\<Omega> u d \\<tau>\"\n      using state_typ_wf_lookup[OF S1 S2 LookupTy] \n      by (simp add: lookup_var_ty_match_def)\n  next\n    fix u \\<tau> d v\n    assume \"u \\<in> ?U\"\n    hence S1:\"state_typ_wf A \\<Omega> (local_state u) (snd \\<Lambda>')\" and\n          S2:\"state_typ_wf A \\<Omega> (global_state u) (fst \\<Lambda>')\" and\n          Rel1: \"(\\<forall>x y. R x = Some (Inl y) \\<longrightarrow> lookup_var \\<Lambda> ns x = lookup_var \\<Lambda>' u y)\" and\n          Binder1: \"binder_state u = Map.empty\" by auto\n    assume LookupTy:\"lookup_var_ty \\<Lambda>' d = Some \\<tau>\"\n    assume dNotElem:\"d \\<notin> rel_range R \\<union> set (map fst (fst \\<Lambda>))\"\n    assume TypV:\"type_of_val A v = instantiate \\<Omega> \\<tau>\"\n    have S1Upd:\"state_typ_wf A \\<Omega> (local_state (update_var \\<Lambda>' u d v)) (snd \\<Lambda>')\"\n      unfolding state_typ_wf_def\n    proof (rule allI, rule allI, rule impI)\n      fix x \\<tau>'\n      assume MapOfX:\"lookup_vdecls_ty (snd \\<Lambda>') x = Some \\<tau>'\"\n      show \"map_option (type_of_val A) (local_state (update_var \\<Lambda>' u d v) x) = Some (instantiate \\<Omega> \\<tau>')\"\n      proof (cases \"d = x\")\n        case True\n        then show ?thesis \n        by (metis (mono_tags, lifting) LookupTy MapOfX TypV lookup_var_local lookup_vdecls_ty_local_3 lookup_vdecls_ty_map_of option.simps(9) prod.collapse update_var_same)\n      next\n        case False\n        from S1 MapOfX have \"map_option (type_of_val A) (local_state u x) = Some (instantiate \\<Omega> \\<tau>')\"\n          using state_typ_wf_def by blast        \n        with False show ?thesis using local_state_update_other\n          by metis\n      qed\n    qed\n    have S2Upd:\"state_typ_wf A \\<Omega> (global_state (update_var \\<Lambda>' u d v)) (fst \\<Lambda>')\"\n      unfolding state_typ_wf_def\n    proof (rule allI, rule allI, rule impI)\n      fix x \\<tau>'\n      assume MapOfX:\"lookup_vdecls_ty (fst \\<Lambda>') x = Some \\<tau>'\"\n      from S2 MapOfX have GlobalUX:\"map_option (type_of_val A) (global_state u x) = Some (instantiate \\<Omega> \\<tau>')\" using state_typ_wf_def by blast\n      show  \"map_option (type_of_val A) (global_state (update_var \\<Lambda>' u d v) x) = Some (instantiate \\<Omega> \\<tau>')\"\n      proof (cases \"map_of (snd \\<Lambda>') d = None\")\n        case True \n        hence Aux1:\"global_state (update_var \\<Lambda>' u d v) = (global_state u)(d \\<mapsto> v)\"  by (simp add: global_update)\n        show ?thesis\n          proof (cases \"d = x\")\n            case True\n            moreover with MapOfX LookupTy \\<open>map_of (snd \\<Lambda>') d = None\\<close> have \"\\<tau> = \\<tau>'\"\n              using lookup_vdecls_ty_global_4 lookup_vdecls_ty_map_of lookup_var_decl_global              \n              by auto\n            ultimately show ?thesis\n              apply (subst Aux1)\n              using TypV MapOfX\n              by simp\n          next\n            case False\n            thus ?thesis using global_state_update_other GlobalUX\n              by metis               \n          qed\n      next\n        case False\n        hence Aux2: \"global_state (update_var \\<Lambda>' u d v) = global_state u\" using global_state_update_local by blast\n        thus ?thesis using GlobalUX by simp             \n        qed\n    qed\n    have Rel1Upd: \"\\<forall>x y. R x = Some (Inl y) \\<longrightarrow> lookup_var \\<Lambda> ns x = lookup_var \\<Lambda>' (update_var \\<Lambda>' u d v) y\"\n    proof (rule allI, rule allI, rule impI)\n      fix x y\n      assume \"R x = Some (Inl y)\"\n      show \"lookup_var \\<Lambda> ns x = lookup_var \\<Lambda>' (update_var \\<Lambda>' u d v) y\"\n        apply (cases \"d = y\")\n        using \\<open>R x = Some (Inl y)\\<close> dNotElem\n         apply (simp add: rel_range_def)\n        using Rel1 \\<open>R x = Some (Inl y)\\<close> \n        apply simp\n        done\n    qed \n    have GlobalConstraint: \"\\<forall>x y. map_of (fst \\<Lambda>) x = Some y \\<longrightarrow> global_state (update_var \\<Lambda>' u d v) x = global_state ns x\"\n    proof (rule+)\n      fix x y\n      assume \"map_of (fst \\<Lambda>) x = Some y\"\n      hence \"d \\<noteq> x\" using dNotElem\n        by (metis UnCI domI dom_map_of_2)\n      thus \"global_state (update_var \\<Lambda>' u d v) x = global_state ns x\" using \\<open>u \\<in> ?U\\<close>\n        by (simp add: \\<open>map_of (fst \\<Lambda>) x = Some y\\<close> global_state_update_other)\n    qed\n    show \"update_var \\<Lambda>' u d v \\<in> ?U\" \n      apply (simp only: initial_set.simps)\n      apply (rule Set.CollectI)\n      apply (intro conjI)\n         apply (rule S1Upd)\n      apply (rule S2Upd)\n        apply (rule Rel1Upd)\n      apply (rule GlobalConstraint)\n      using update_var_binder_same Binder1 \n      by metis\n  qed\n\nlemma state_typ_wf_some:\n  assumes \"map_of vs x \\<noteq> None\" and\n          \"state_typ_wf A \\<Omega> ns vs\" \n        shows \"ns x \\<noteq> None\"\n  using assms map_of_lookup_vdecls_ty\n  unfolding state_typ_wf_def\n  by blast\n\nlemma nstate_old_rel_helper:\n  assumes \"state_typ_wf A [] (global_state ns) (fst \\<Lambda>1)\" and\n          \"global_state ns = old_global_state ns\" and\n          \"set (map fst (fst \\<Lambda>1)) \\<inter> set (map fst (snd \\<Lambda>1)) = {}\"\n          \"u \\<in> initial_set  A R \\<Lambda>1 \\<Lambda>2 [] ns\" and\n          \"\\<And>x y. R_old x = Some y \\<longrightarrow> map_of (fst \\<Lambda>1) x \\<noteq> None\" and\n          \"\\<And>x y. R_old x = Some y \\<longrightarrow> R x = Some y\"\n        shows \"nstate_old_rel \\<Lambda>1 \\<Lambda>2 R_old ns u\"\n  unfolding nstate_old_rel_def\nproof (rule allI, rule allI, rule impI)  \n  fix x y\n  assume \"R_old x = Some (Inl y)\"\n  hence GlobalX:\"map_of (fst \\<Lambda>1) x \\<noteq> None\"\n    using assms(5) by simp\n  hence NotLocalX:\"map_of (snd \\<Lambda>1) x = None\"\n    using assms(3)\n    by (metis disjoint_iff_not_equal list.set_map map_of_eq_None_iff)\n\n  from \\<open>R_old x = Some (Inl y)\\<close> have \"R x = Some (Inl y)\" using assms(6) by simp  \n  hence LookupSame:\"lookup_var \\<Lambda>1 ns x = lookup_var \\<Lambda>2 u y\" using assms(4)\n    by simp\n\n  from \\<open>map_of (fst \\<Lambda>1) x \\<noteq> None\\<close>\n  obtain v where \"global_state ns x = Some v\"\n    using assms(1) GlobalX state_typ_wf_some\n    by fastforce\n  moreover from this have \"lookup_var \\<Lambda>1 ns x = Some v\"\n    using GlobalX NotLocalX\n    by (metis lookup_var_global prod.collapse)\n  ultimately have Rel:\"(\\<exists>v. old_global_state ns x = Some v \\<and> lookup_var \\<Lambda>2 u y = Some v)\"\n    using assms(2)    \n    by (simp add: LookupSame)\n  \n  show \"(map_of (fst \\<Lambda>1) x \\<noteq> None \\<and> map_of (snd \\<Lambda>1) x = None) \\<and> (\\<exists>v. old_global_state ns x = Some v \\<and> lookup_var \\<Lambda>2 u y = Some v)\"\n    using GlobalX NotLocalX Rel \n    by simp\nqed\n\nlemma nstate_old_rel_states_helper:\n  assumes \"state_typ_wf A [] (global_state ns) (fst \\<Lambda>1)\" and\n          \"global_state ns = old_global_state ns\" and\n          \"set (map fst (fst \\<Lambda>1)) \\<inter> set (map fst (snd \\<Lambda>1)) = {}\"\n          \"\\<And>x y. R_old x = Some y \\<longrightarrow> map_of (fst \\<Lambda>1) x \\<noteq> None\" and\n          \"\\<And>x y. R_old x = Some y \\<longrightarrow> R x = Some y\"\n        shows \"nstate_old_rel_states \\<Lambda>1 \\<Lambda>2 R_old ns (initial_set  A R \\<Lambda>1 \\<Lambda>2 [] ns)\"\n  unfolding nstate_old_rel_states_def\n  using assms nstate_old_rel_helper\n  by blast\n\nsubsection \\<open>Some more helper definitions and lemmas for the final part of the passification validation\\<close>\n\nlemma const_rel:\n  assumes Rel:\"nstate_rel ((consts@globals),locals) (consts@globals2, locals2) R ns u\" and\n          R_consts:\"list_all (\\<lambda>vd. R (fst vd) = Some (Inl (fst vd))) consts\" and\n          ConstsDisj:\"set (map fst consts) \\<inter> set (map fst locals) = {}\" and\n          ConstsDisj2:\"set (map fst consts) \\<inter> set (map fst locals2) = {}\"\n  shows \"state_restriction (global_state ns) consts = state_restriction (global_state u) consts\"  \nproof (rule HOL.ext)\n  fix x\n  show \"state_restriction (global_state ns) consts x = state_restriction (global_state u) consts x\"\n  proof (cases \"map_of consts x \\<noteq> None\")\n    case True\n    from this obtain \\<tau> where \"map_of consts x = Some \\<tau>\" by auto\n    moreover have \"map_of locals x = None\" and \"map_of locals2 x = None\" using ConstsDisj ConstsDisj2\n      by (metis True disjoint_iff_not_equal domIff dom_map_of_2)+\n    ultimately have LookupNs:\"lookup_var ((consts@globals),locals) ns x = global_state ns x\" and\n                    LookupU:\"lookup_var ((consts@globals2),locals2) u x = global_state u x\"\n      by (auto simp add: lookup_var_global)\n    from \\<open>map_of consts x = Some \\<tau>\\<close> have \"(x,\\<tau>) \\<in> set (consts)\"\n      by (simp add: map_of_SomeD) \n    with R_consts have \"R x = Some (Inl x)\"\n      by (metis (mono_tags, lifting) fst_conv in_set_conv_decomp_last list.pred_inject(2) list_all_append) \n    with Rel have \"lookup_var ((consts@globals),locals) ns x = lookup_var ((consts@globals2),locals2) u x\"\n      by (simp add: nstate_rel_def)\n    with LookupNs LookupU show ?thesis using \\<open>map_of consts x \\<noteq> None\\<close> \n      by (simp add: state_restriction_def)\n  next\n    case False\n    then show ?thesis \n      by (simp add: state_restriction_def)      \n  qed\nqed\n\nlemma rel_well_typed_state_typ_wf: \n  assumes S1:\"state_typ_wf A \\<Omega> (local_state ns) (snd \\<Lambda>)\" and\n          S2:\"state_typ_wf A \\<Omega> (global_state ns) (fst \\<Lambda>)\" and\n          RelWtVar:\"\\<And>x y. R x = Some (Inl y) \\<Longrightarrow> \\<exists>\\<tau>. lookup_var_ty \\<Lambda> x = Some \\<tau>\" and\n          RelWtConst:\"\\<And>x y. R x = Some (Inr y) \\<Longrightarrow> lookup_var \\<Lambda> ns x = Some (LitV y) \\<and> (\\<exists>\\<tau>. lookup_var_ty \\<Lambda> x = Some \\<tau>)\"\n        shows \"rel_well_typed A \\<Lambda> \\<Omega> R ns\"\n  unfolding rel_well_typed_def rel_const_correct_def\n  apply (rule conjI, rule allI, rule allI, rule impI)\n  using state_typ_wf_lookup[OF S1 S2] RelWtVar\n   apply blast\n  using RelWtConst\n  using \\<open>\\<And>x \\<tau>. lookup_var_ty \\<Lambda> x = Some \\<tau> \\<Longrightarrow> \\<exists>v. lookup_var \\<Lambda> ns x = Some v \\<and> type_of_val A v = instantiate \\<Omega> \\<tau>\\<close> by force\n\nlemma convert_fun_to_list:\nassumes A0:\"R_fun = map_of R_list\" and\n        A1:\"list_all (\\<lambda>t. P (fst t) (snd t)) R_list\"\n      shows  \"R_fun x = Some y \\<longrightarrow> P x y\"    \nproof (rule+)  \n  assume \"R_fun x = Some y\"\n  hence \"(x,y) \\<in> set (R_list)\"\n    using A0\n    by (simp add: map_of_SomeD)\n  moreover from A1 have \"\\<forall>t \\<in> set (R_list). (\\<lambda>t. P (fst t) (snd t)) t\"\n    by (simp only: List.list_all_iff)\n  ultimately show \"P x y\" by auto\nqed\n\nfun custom_cmp :: \"(nat + lit) \\<Rightarrow> (nat + lit) \\<Rightarrow> bool\"\n  where \n    \"custom_cmp (Inl n) (Inl m) = (n < m)\"\n  | \"custom_cmp _ _ = False\"\n\nlemma custom_cmp_diff: \"custom_cmp a b \\<Longrightarrow> a \\<noteq> b\"\n  by (cases a, cases b) auto  \n\nfun strictly_ordered :: \"(nat + lit) list \\<Rightarrow> bool\"\n  where \n    \"strictly_ordered [] = True\"\n  | \"strictly_ordered [x] = True\"\n  | \"strictly_ordered (x#y#zs) = (custom_cmp x y \\<and> strictly_ordered (y#zs))\"\n\nlemma strictly_ordered_smaller: \"strictly_ordered ((Inl a)#xs) \\<Longrightarrow> (\\<forall> y \\<in> (set xs). \\<exists>a'. y= Inl a' \\<and> a < a')\"\nproof (induction arbitrary:a rule: strictly_ordered.induct)\n  case 1\n  then show ?case by simp\nnext\n  case (2 x)\n  then show ?case apply simp \n    using custom_cmp.elims(2) by blast\nnext\n  case (3 x y zs)\n  show ?case\n  proof (rule ballI)\n    fix r\n    assume RElem:\"r \\<in> set (x # y # zs)\"\n    show \"\\<exists>a'. r = Inl a' \\<and> a < a'\"\n    proof (cases \"r = x\")\n    case True\n      then show ?thesis using 3 \n        by (metis custom_cmp.elims(2) custom_cmp.simps(1) strictly_ordered.simps(3))\n    next\n      case False\n      hence \"r \\<in> set (y # zs)\" using RElem by simp\n      then show ?thesis using 3 \n        by (metis custom_cmp.elims(2) custom_cmp.simps(1) dual_order.strict_trans strictly_ordered.simps(3))\n    qed\n  qed\nqed\n\nlemma strictly_ordered_distinct: \"strictly_ordered xs \\<Longrightarrow> distinct xs\"\nproof (induction rule: strictly_ordered.induct)\ncase 1\nthen show ?case by simp\nnext\n  case (2 x)\n  then show ?case by simp\nnext\n  case (3 x y zs)\n  then show ?case apply simp\n    by (metis (full_types) custom_cmp.elims(2) custom_cmp.simps(1) strictly_ordered_smaller sup.strict_boundedE sup.strict_order_iff)\nqed\n\nlemma distinct_helper:\n  assumes A1:\"(x, fx) \\<in> set xs\" and \n          A2:\"(y, fy) \\<in> set xs\" and\n          \"x \\<noteq> y\"\n          \"distinct (map snd xs)\"\n        shows \"fx \\<noteq> fy\"  \nproof -\n  thm distinct_conv_nth\n  from A1 obtain i where \"i < length xs\" and  \"xs ! i = (x, fx)\"\n    by (meson in_set_conv_nth)\n  moreover from A2 obtain j where \"j < length xs\" and \"xs ! j = (y, fy)\"\n    by (meson in_set_conv_nth)\n  ultimately show ?thesis using \\<open>x \\<noteq> y\\<close> \\<open>distinct (map snd xs)\\<close> distinct_conv_nth\n    by (metis eq_snd_iff length_map nth_map prod.inject)\nqed\n\nlemma injective_fun_to_list:\n  assumes R_fun_def: \"R_fun = map_of R_list\" and\n          Distinct:\"distinct (map snd R_list)\"\n  shows \"inj_on_defined R_fun\"\n  unfolding inj_on_defined_def distinct_helper  \nproof ((rule allI)+, rule impI, erule conjE)\n  fix x y z\n  let ?map_of_x = \"map_of R_list x\"\n  let ?map_of_y = \"map_of R_list y\"\n  assume \"R_fun x = R_fun y\" and \"R_fun x = Some (Inl z)\"\n  hence \"(x, Inl z) \\<in> set R_list\"\n    using R_fun_def \\<open>R_fun x = Some (Inl z)\\<close> map_of_SomeD by force\n  moreover have \"(y, Inl z) \\<in> set R_list\" \n    using R_fun_def \\<open>R_fun x = Some (Inl z)\\<close> \\<open>R_fun x = R_fun y\\<close> map_of_SomeD by fastforce\n  ultimately show \"x = y\"\n  using distinct_helper Distinct by fastforce\nqed\n\nlemma injective_fun_to_list_2:\n  assumes \"R_fun = map_of R_list\" and\n          \"strictly_ordered (map snd R_list)\"\n  shows \"inj_on_defined R_fun\"\n  using assms injective_fun_to_list strictly_ordered_distinct by blast\n\nfun max_rel :: \"(nat + lit) list \\<Rightarrow> nat\"\n  where \n    \"max_rel [] = 0\"\n  | \"max_rel ((Inl n) # xs) = (max n (max_rel xs))\" \n  | \"max_rel ((Inr l) # xs) = (max_rel xs)\"\n\n\nlemma max_rel_aux:\n  assumes \"max_rel xs = w_max\" and \"(Inl n) \\<in> set xs\" \n  shows \"n \\<le> w_max\"\n  using assms\n  apply (induction arbitrary: n w_max rule: max_rel.induct)\n    apply simp\n   apply fastforce\n  apply simp\n  done\n\nfun max_rel_tail :: \"nat \\<Rightarrow> (nat + lit) list \\<Rightarrow> nat\"\n  where \n    \"max_rel_tail k [] = k\"\n  | \"max_rel_tail k ((Inl n) # xs) = (max_rel_tail (max n k) xs)\" \n  | \"max_rel_tail k ((Inr l) # xs) = (max_rel_tail k xs)\"\n\nlemma max_rel_tail_equiv_aux: \"max_rel_tail k xs = max k (max_rel xs)\"\n  by (induction arbitrary: k rule: max_rel.induct) auto\n\nlemma max_tail_equiv: \"max_rel_tail 0 xs = max_rel xs\"\n  by (simp add: max_rel_tail_equiv_aux)\n\nlemma rel_range_fun_to_list:\n  assumes R_fun_def:\"R_fun = map_of R_list\" and\n          \"max_rel_tail 0 (map snd R_list) = w_max\"\n  shows \"\\<forall>x. x \\<in> rel_range R_fun \\<longrightarrow> x \\<le> w_max\"\n  unfolding rel_range_def\nproof (rule, rule)\n  fix x\n  assume \"x \\<in> {y. \\<exists>x. R_fun x = Some (Inl y)}\"\n  from this obtain z where \"R_fun z = Some (Inl x)\" by auto\n  hence \"map_of R_list z = Some (Inl x)\" using R_fun_def by simp\n  hence \"(z,Inl x) \\<in> set (R_list)\"\n    by (simp add: map_of_SomeD)\n  thus \"x \\<le> w_max\" using max_tail_equiv max_rel_aux\n    by (metis assms(2) set_zip_rightD zip_map_fst_snd)\nqed\n\nlemma axiom_assm_aux:\n  assumes \"axiom_assm A \\<Gamma> consts ns1 axioms\" and\n          \"\\<And> x y. map_of consts x = Some y \\<Longrightarrow> (global_state ns1) x = (global_state ns2) x\"\n        shows \"axiom_assm A \\<Gamma> consts ns2 axioms\"\n  using assms\n  unfolding nstate_global_restriction_def state_restriction_def\nproof -\n  have Aux:\" (\\<lambda>x. if map_of consts x \\<noteq> None then global_state ns2 x else None) =  (\\<lambda>x. if map_of consts x \\<noteq> None then global_state ns1 x else None)\"\n    using assms(2) by fastforce\n  show \"axioms_sat A (consts, []) \\<Gamma> (global_to_nstate (\\<lambda>x. if map_of consts x \\<noteq> None then global_state ns2 x else None)) axioms\"\n    apply (subst Aux)\n    using assms(1)\n    unfolding nstate_global_restriction_def state_restriction_def\n    apply assumption\n    done\nqed\n\nlemma helper_init_disj:\n  assumes Max1:\"\\<forall>x. x \\<in> xs \\<longrightarrow> x \\<le> n\" and \"\\<forall>y. y \\<in> ys \\<longrightarrow> y \\<le> m\" and \"n < w_max\" and \"m < w_max\"\n  shows \"{w. (w :: nat) \\<ge> w_max} \\<inter> (xs \\<union> ys) = {}\"\n  using assms\n  by auto\n \nfun is_prefix :: \"'b list \\<Rightarrow> 'b list \\<Rightarrow> bool\"\n  where \n    \"is_prefix [] ys = True\"\n  | \"is_prefix (x#xs) (y#ys) = ((x = y) \\<and> is_prefix xs ys)\"\n  | \"is_prefix  _ _ = False\"\n\nlemma is_prefix_empty: \"is_prefix ys [] \\<Longrightarrow> ys = []\"\n  by (cases ys) auto\n\nlemma is_prefix_append: \"is_prefix xs ys \\<Longrightarrow> \\<exists>zs. ys = xs@zs\"\n  by (induction rule: is_prefix.induct) (auto simp: is_prefix_empty)\n\nlemma prefix_map_of:\n  assumes \"\\<exists>zs. ys = xs@zs\" and\n          \"R1 = map_of ys\" and\n          \"R2 = map_of xs\"\n  shows \"\\<forall>x y. R2 x = Some y \\<longrightarrow> R1 x = Some y\"\n  using assms\n  by auto\n\nend", "meta": {"author": "gauravpartha", "repo": "foundational_boogie", "sha": "4667c538759128ad88588ff2c1ae821d7a78b16b", "save_path": "github-repos/isabelle/gauravpartha-foundational_boogie", "path": "github-repos/isabelle/gauravpartha-foundational_boogie/foundational_boogie-4667c538759128ad88588ff2c1ae821d7a78b16b/BoogieLang/PassificationEndToEnd.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.603931819468636, "lm_q2_score": 0.4843800842769843, "lm_q1q2_score": 0.2925325456117704}}
{"text": "section\\<open>Temporal Properties\\<close>\ntext\\<open>This theory presents some examples of temporal properties over the simple drinks machine.\\<close>\n\ntheory Drinks_Machine_LTL\nimports \"Drinks_Machine\" \"EFSM.EFSM_LTL\"\nbegin\n\ndeclare One_nat_def [simp del]\n\nlemma P_ltl_step_0:\n  assumes invalid: \"P (None, [], <>)\"\n  assumes select: \"l = STR ''select'' \\<longrightarrow> P (Some 1, [], <1 $:= Some (hd i), 2 $:= Some (Num 0)>)\"\n  shows \"P (ltl_step drinks (Some 0) <> (l, i))\"\nproof-\n  have length_i: \"\\<exists>d. (l, i) = (STR ''select'', [d]) \\<Longrightarrow> length i = 1\"\n    by (induct i, auto)\n  have length_i_2: \"\\<forall>d. i \\<noteq> [d] \\<Longrightarrow> length i \\<noteq> 1\"\n    by (induct i, auto)\n  show ?thesis\n    apply (case_tac \"\\<exists>d. (l, i) = (STR ''select'', [d])\")\n     apply (simp add: possible_steps_0 length_i select_def apply_updates_def)\n    using select apply auto[1]\n    by (simp add: possible_steps_0_invalid length_i_2 invalid)\nqed\n\nlemma P_ltl_step_1:\n  assumes invalid: \"P (None, [], r)\"\n  assumes coin: \"l = STR ''coin'' \\<longrightarrow> P (Some 1, [value_plus (r $ 2) (Some (hd i))], r(2 $:= value_plus (r $ 2) (Some (i ! 0))))\"\n  assumes vend_fail: \"value_gt (Some (Num 100)) (r $ 2) = trilean.true \\<longrightarrow> P (Some 1, [],r)\"\n  assumes vend: \"\\<not>? value_gt (Some (Num 100)) (r $ 2) = trilean.true \\<longrightarrow> P (Some 2, [r$1], r)\"\n  shows \"P (ltl_step drinks (Some 1) r (l, i))\"\nproof-\n  have length_i: \"\\<And>s. \\<exists>d. (l, i) = (s, [d]) \\<Longrightarrow> length i = 1\"\n    by (induct i, auto)\n  have length_i_2: \"\\<forall>d. i \\<noteq> [d] \\<Longrightarrow> length i \\<noteq> 1\"\n    by (induct i, auto)\n  show ?thesis\n    apply (case_tac \"\\<exists>d. (l, i) = (STR ''coin'', [d])\")\n     apply (simp add: possible_steps_1_coin length_i coin_def apply_outputs_def apply_updates_def)\n    using coin apply auto[1]\n    apply (case_tac \"(l, i) = (STR ''vend'', [])\")\n     apply (case_tac \"\\<exists>n. r $ 2 = Some (Num n)\")\n      apply clarsimp\n      apply (case_tac \"n \\<ge> 100\")\n       apply (simp add: drinks_vend_sufficient vend_def apply_updates_def apply_outputs_def)\n       apply (metis finfun_upd_triv possible_steps_2_vend vend vend_ge_100)\n      apply (simp add: drinks_vend_insufficient vend_fail_def apply_updates_def apply_outputs_def)\n      apply (metis MaybeBoolInt.simps(1) finfun_upd_triv not_less value_gt_def vend_fail)\n     apply (simp add: drinks_vend_invalid invalid)\n    by (simp add: drinks_no_possible_steps_1 length_i_2 invalid)\nqed\n\nlemma LTL_r2_not_always_gt_100: \"not (alw (check_exp (Gt (V (Rg 2)) (L (Num 100))))) (watch drinks i)\"\n  using value_gt_def by auto\n\nlemma drinks_step_2_none: \"ltl_step drinks (Some 2) r e = (None, [], r)\"\n  by (simp add: drinks_end ltl_step_none_2)\n\nlemma one_before_two_2:\n  \"alw (\\<lambda>x. statename (shd (stl x)) = Some 2 \\<longrightarrow> statename (shd x) = Some 1) (make_full_observation drinks (Some 2) r [r $ 1] x2a)\"\nproof(coinduction)\n  case alw\n  then show ?case\n    apply (simp add: drinks_step_2_none)\n    by (metis (mono_tags, lifting) alw_mono nxt.simps once_none_nxt_always_none option.distinct(1))\nqed\n\nlemma one_before_two_aux:\n  assumes \"\\<exists> p r i. j = nxt (make_full_observation drinks (Some 1) r p) i\"\n  shows \"alw (\\<lambda>x. nxt (state_eq (Some 2)) x \\<longrightarrow> state_eq (Some 1) x) j\"\n  using assms apply(coinduct)\n  apply simp\n  apply clarify\n  apply standard\n   apply simp\n  apply simp\n  apply (case_tac \"shd (stl i)\")\n  apply (simp del: ltl_step.simps)\n  apply (rule P_ltl_step_1)\n     apply (rule disjI2)\n     apply (rule alw_mono[of \"nxt (state_eq None)\"])\n      apply (simp add: once_none_nxt_always_none)\n     apply simp\n    apply auto[1]\n   apply auto[1]\n  apply simp\n  by (simp add: one_before_two_2)\n\nlemma LTL_nxt_2_means_vend:\n  \"alw (nxt (state_eq (Some 2)) impl (state_eq (Some 1))) (watch drinks i)\"\nproof(coinduction)\n  case alw\n  then show ?case\n    apply (case_tac \"shd i\")\n    apply (simp del: ltl_step.simps)\n    apply (rule P_ltl_step_0)\n     apply simp\n     apply (rule disjI2)\n     apply (rule alw_mono[of \"nxt (state_eq None)\"])\n      apply (simp add: once_none_nxt_always_none)\n    using one_before_two_aux by auto\nqed\n\nlemma costsMoney_aux:\n  assumes \"\\<exists>p r i. j = (nxt (make_full_observation drinks (Some 1) r p) i)\"\n  shows \"alw (\\<lambda>xs. nxt (state_eq (Some 2)) xs \\<longrightarrow> check_exp (Ge (V (Rg 2)) (L (Num 100))) xs) j\"\n  using assms apply coinduct\n  apply clarsimp\n  apply (case_tac \"shd (stl i)\")\n  apply (simp del: ltl_step.simps)\n  apply (rule P_ltl_step_1)\n     apply simp\n     apply (rule disjI2)\n     apply (rule alw_mono[of \"nxt (state_eq None)\"])\n      apply (simp add: once_none_nxt_always_none)\n     apply simp\n    apply auto[1]\n   apply auto[1]\n  apply simp\n  apply standard\n  apply (rule disjI2)\n  apply (rule alw_mono[of \"nxt (state_eq None)\"])\n   apply (metis (no_types, lifting) drinks_step_2_none fst_conv make_full_observation.sel(2) nxt.simps nxt_alw once_none_always_none_aux)\n  by simp\n\n(* costsMoney: THEOREM drinks |- G(X(cfstate=State_2) => gval(value_ge(r_2, Some(NUM(100))))); *)\nlemma LTL_costsMoney:\n  \"(alw (nxt (state_eq (Some 2)) impl (check_exp (Ge (V (Rg 2)) (L (Num 100)))))) (watch drinks i)\"\nproof(coinduction)\n  case alw\n  then show ?case\n    apply (cases \"shd i\")\n    subgoal for l ip\n      apply (case_tac \"l = STR ''select'' \\<and> length ip = 1\")\n       defer\n       apply (simp add: possible_steps_0_invalid)\n       apply (rule disjI2)\n       apply (rule alw_mono[of \"nxt (state_eq None)\"])\n        apply (simp add: once_none_nxt_always_none)\n       apply (simp add: )\n      apply (simp add: possible_steps_0 select_def)\n      apply (rule disjI2)\n      apply (simp only: nxt.simps[symmetric])\n      using costsMoney_aux by auto\n    done\nqed\n\nlemma LTL_costsMoney_aux:\n  \"(alw (not (check_exp (Ge (V (Rg 2)) (L (Num 100)))) impl (not (nxt (state_eq (Some 2)))))) (watch drinks i)\"\n  by (metis (no_types, lifting) LTL_costsMoney alw_mono)\n\nlemma implode_select: \"String.implode ''select'' = STR ''select''\"\n  by (metis Literal.rep_eq String.implode_explode_eq zero_literal.rep_eq)\n\nlemma implode_coin: \"String.implode ''coin'' = STR ''coin''\"\n  by (metis Literal.rep_eq String.implode_explode_eq zero_literal.rep_eq)\n\nlemma implode_vend: \"String.implode ''vend'' = STR ''vend''\"\n  by (metis Literal.rep_eq String.implode_explode_eq zero_literal.rep_eq)\n\nlemmas implode_labels = implode_select implode_coin implode_vend\n\nlemma LTL_neverReachS2:\"(((((action_eq (''select'', [Str ''coke''])))\n                    aand\n                    (nxt ((action_eq (''coin'', [Num 100])))))\n                    aand\n                    (nxt (nxt((label_eq ''vend'' aand (input_eq []))))))\n                    impl\n                    (nxt (nxt (nxt (state_eq (Some 2))))))\n                    (watch drinks i)\"\n  apply (simp add: implode_labels)\n  apply (cases i)\n  apply clarify\n  apply simp\n  apply (simp add: possible_steps_0 select_def)\n  apply (case_tac \"shd x2\", clarify)\n  apply (simp add: possible_steps_1_coin coin_def value_plus_def finfun_update_twist apply_updates_def)\n  apply (case_tac \"shd (stl x2)\", clarify)\n  by (simp add: drinks_vend_sufficient )\n\nlemma ltl_step_not_select:\n  \"\\<nexists>i. e = (STR ''select'', [i]) \\<Longrightarrow>\n   ltl_step drinks (Some 0) r e = (None, [], r)\"\n  apply (cases e, clarify)\n  apply (rule ltl_step_none)\n  apply (simp add: possible_steps_empty drinks_def can_take_transition_def can_take_def select_def)\n  by (cases e, case_tac b, auto)\n\nlemma ltl_step_select:\n  \"ltl_step drinks (Some 0) <> (STR ''select'', [i]) = (Some 1, [], <1 $:= Some i, 2 $:= Some (Num 0)>)\"\n  apply (rule  ltl_step_some[of _ _ _ _ _ _ select])\n    apply (simp add: possible_steps_0)\n   apply (simp add: select_def)\n  by (simp add: select_def finfun_update_twist apply_updates_def)\n\nlemma ltl_step_not_coin_or_vend:\n  \"\\<nexists>i. e = (STR ''coin'', [i]) \\<Longrightarrow>\n    e \\<noteq> (STR ''vend'', []) \\<Longrightarrow>\n    ltl_step drinks (Some 1) r e = (None, [], r)\"\n  apply (cases e)\n  apply (simp del: ltl_step.simps)\n  apply (rule ltl_step_none)\n  apply (simp add: possible_steps_empty drinks_def can_take_transition_def can_take_def transitions)\n  by (case_tac e, case_tac b, auto)\n\nlemma ltl_step_coin:\n  \"\\<exists>p r'. ltl_step drinks (Some 1) r (STR ''coin'', [i]) = (Some 1, p, r')\"\n  by (simp add: possible_steps_1_coin)\n\nlemma alw_tl:\n  \"alw \\<phi> (make_full_observation e (Some 0) <> [] xs) \\<Longrightarrow>\n    alw \\<phi>\n     (make_full_observation e (fst (ltl_step e (Some 0) <> (shd xs))) (snd (snd (ltl_step e (Some 0) <> (shd xs))))\n       (fst (snd (ltl_step e (Some 0) <> (shd xs)))) (stl xs))\"\n  by auto\n\nlemma stop_at_none:\n  \"alw (\\<lambda>xs. output (shd (stl xs)) = [Some (EFSM.Str drink)] \\<longrightarrow> check_exp (Ge (V (Rg 2)) (L (Num 100))) xs)\n            (make_full_observation drinks None r p t)\"\n  apply (rule alw_mono[of \"nxt (output_eq [])\"])\n   apply (simp add: no_output_none_nxt)\n  by simp\n\nlemma drink_costs_money_aux:\n  assumes \"\\<exists>p r t. j = make_full_observation drinks (Some 1) r p t\"\n  shows \"alw (\\<lambda>xs. output (shd (stl xs)) = [Some (EFSM.Str drink)] \\<longrightarrow> check_exp (Ge (V (Rg 2)) (L (Num 100))) xs) j\"\n  using assms apply coinduct\n  apply clarsimp\n  apply (case_tac \"shd t\")\n  apply (simp del: ltl_step.simps)\n  apply (rule P_ltl_step_1)\n     apply simp\n     apply (rule disjI2)\n     apply (rule alw_mono[of \"nxt (output_eq [])\"])\n      apply (simp add: no_output_none_nxt)\n     apply simp\n    apply (simp add: Str_def value_plus_never_string)\n    apply auto[1]\n   apply auto[1]\n  apply simp\n  apply standard\n  apply (rule disjI2)\n  apply (rule alw_mono[of \"nxt (output_eq [])\"])\n   apply (simp add: drinks_step_2_none no_output_none_if_empty nxt_alw)\n  by simp\n\nlemma LTL_drinks_cost_money:\n  \"alw (nxt (output_eq [Some (Str drink)]) impl (check_exp (Ge (V (Rg 2)) (L (Num 100))))) (watch drinks t)\"\nproof(coinduction)\n  case alw\n  then show ?case\n    apply (case_tac \"shd t\")\n    apply (simp del: ltl_step.simps)\n    apply (rule P_ltl_step_0)\n     apply simp\n     apply (rule disjI2)\n     apply (rule alw_mono[of \"nxt (output_eq [])\"])\n      apply (simp add: no_output_none_nxt)\n     apply simp\n    apply simp\n    using drink_costs_money_aux\n    apply simp\n    by blast\nqed\n\nlemma steps_1_invalid:\n      \"\\<nexists>i. (a, b) = (STR ''coin'', [i]) \\<Longrightarrow>\n       \\<nexists>i. (a, b) = (STR ''vend'', []) \\<Longrightarrow>\n       possible_steps drinks 1 r a b = {||}\"\n  apply (simp add: possible_steps_empty drinks_def transitions can_take_transition_def can_take_def)\n  by (induct b, auto)\n\nlemma output_vend_aux:\n  assumes \"\\<exists>p r t. j = make_full_observation drinks (Some 1) r p t\"\n  shows \"alw (\\<lambda>xs. label_eq ''vend'' xs \\<and> output (shd (stl xs)) = [Some d] \\<longrightarrow> check_exp (Ge (V (Rg 2)) (L (Num 100))) xs) j\"\n  using assms apply coinduct\n  apply clarsimp\n  apply (case_tac \"shd t\")\n  apply (simp add: implode_vend del: ltl_step.simps)\n  apply (rule P_ltl_step_1)\n     apply simp\n     apply (rule disjI2)\n     apply (rule alw_mono[of \"nxt (output_eq [])\"])\n      apply (simp add: no_output_none_nxt)\n     apply simp\n    apply auto[1]\n   apply auto[1]\n  apply simp\n  apply standard\n  apply (rule disjI2)\n  apply (rule alw_mono[of \"nxt (output_eq [])\"])\n   apply (simp add: drinks_step_2_none no_output_none_if_empty nxt_alw)\n  by simp\n\ntext_raw\\<open>\\snip{outputVend}{1}{2}{%\\<close>\nlemma LTL_output_vend:\n  \"alw (((label_eq ''vend'') aand (nxt (output_eq [Some d]))) impl\n         (check_exp (Ge (V (Rg 2)) (L (Num 100))))) (watch drinks t)\"\ntext_raw\\<open>}%endsnip\\<close>\nproof(coinduction)\n  case alw\n  then show ?case\n    apply (simp add: implode_vend)\n    apply (case_tac \"shd t\")\n    apply (simp del: ltl_step.simps)\n    apply (rule P_ltl_step_0)\n     apply simp\n    apply (rule disjI2)\n     apply (rule alw_mono[of \"nxt (output_eq [])\"])\n      apply (simp add: no_output_none_nxt)\n     apply simp\n    apply simp\n    subgoal for a b\n      using output_vend_aux[of \"(make_full_observation drinks (Some 1)\n              <1 $:= Some (hd b), 2 $:= Some (Num 0)> [] (stl t))\" d]\n      using implode_vend by auto\n    done\nqed\n\ntext_raw\\<open>\\snip{outputVendUnfolded}{1}{2}{%\\<close>\nlemma LTL_output_vend_unfolded:\n  \"alw (\\<lambda>xs. (label (shd xs) = STR ''vend'' \\<and>\n             nxt (\\<lambda>s. output (shd s) = [Some d]) xs) \\<longrightarrow>\n              \\<not>? value_gt (Some (Num 100)) (datastate (shd xs) $ 2) = trilean.true)\n     (watch drinks t)\"\ntext_raw\\<open>}%endsnip\\<close>\n  apply (insert LTL_output_vend[of d t])\n  by (simp add: implode_vend)\n\nend\n", "meta": {"author": "jmafoster1", "repo": "efsm-isabelle", "sha": "fde322562b98c9b4618c112e36a6ac5b9a056610", "save_path": "github-repos/isabelle/jmafoster1-efsm-isabelle", "path": "github-repos/isabelle/jmafoster1-efsm-isabelle/efsm-isabelle-fde322562b98c9b4618c112e36a6ac5b9a056610/examples/Drinks_Machine_LTL.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5312093733737563, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.2924877936209498}}
{"text": "(* CPS conversion *)\ntheory CPS1_Plotkin\nimports Lt\nbegin\n\nnominal_function\n  CPS :: \"lt \\<Rightarrow> lt\" (\"_*\" [250] 250)\nwhere\n  \"atom k \\<sharp> x \\<Longrightarrow> (x~)* = (Lam k ((k~) $$ (x~)))\"\n| \"atom k \\<sharp> (x, M) \\<Longrightarrow> (Lam x M)* = Lam k (k~ $$ Lam x (M*))\"\n| \"atom k \\<sharp> (M, N) \\<Longrightarrow> atom m \\<sharp> (N, k) \\<Longrightarrow> atom n \\<sharp> (k, m) \\<Longrightarrow>\n    (M $$ N)* = Lam k (M* $$ Lam m (N* $$ Lam n (m~ $$ n~ $$ k~)))\"\nunfolding eqvt_def CPS_graph_aux_def\napply (simp)\nusing [[simproc del: alpha_lst]]\napply (simp_all add: fresh_Pair_elim)\napply (rule_tac y=\"x\" in lt.exhaust)\napply (auto)[3]\napply (rule_tac x=\"name\" and ?'a=\"name\" in obtain_fresh)\nusing [[simproc del: alpha_lst]]\napply (simp_all add: fresh_at_base)[3]\napply (rule_tac x=\"(lt1, lt2)\" and ?'a=\"name\" in obtain_fresh)\napply (rule_tac x=\"(lt2, a)\" and ?'a=\"name\" in obtain_fresh)\napply (rule_tac x=\"(a, aa)\" and ?'a=\"name\" in obtain_fresh)\napply (simp add: fresh_Pair_elim fresh_at_base)\napply (rule_tac x=\"(name, lt)\" and ?'a=\"name\" in obtain_fresh)\napply (simp add: fresh_Pair_elim fresh_at_base)[2]\napply (simp add: Abs1_eq_iff lt.fresh fresh_at_base)\n--\"-\"\napply(rule_tac s=\"[[atom ka]]lst. ka~ $$ Lam x (CPS_sumC M)\" in trans)\napply (case_tac \"k = ka\")\napply simp\nthm Abs1_eq_iff\napply(subst Abs1_eq_iff)\napply(rule disjI2)\napply(rule conjI)\napply(simp)\napply(rule conjI)\napply (simp only: lt.perm_simps(1) lt.perm_simps(2) flip_def[symmetric] lt.eq_iff)\napply (subst  flip_at_base_simps(2))\napply(simp)\napply (intro conjI refl)\napply (rule flip_fresh_fresh[symmetric])\napply (simp_all add: lt.fresh)\napply (metis fresh_eqvt_at lt.fsupp)\napply (case_tac \"ka = x\")\napply simp_all[2]\napply (metis Abs_fresh_iff(3) atom_eq_iff finite_set fresh_Cons fresh_Nil fresh_atom fresh_eqvt_at fresh_finite_atom_set fresh_set lt.fsupp)\napply (metis Abs_fresh_iff(3) atom_eq_iff finite_set fresh_Cons fresh_Nil fresh_atom fresh_eqvt_at fresh_finite_atom_set fresh_set lt.fsupp)\n--\"-\"\napply (simp add: Abs1_eq(3))\napply (erule Abs_lst1_fcb2)\napply (simp_all add: Abs_fresh_iff fresh_Nil fresh_star_def eqvt_at_def)[4]\n--\"-\"\napply (rename_tac k' M N m' n')\napply (subgoal_tac \"atom k \\<sharp> CPS_sumC M \\<and> atom k' \\<sharp> CPS_sumC M \\<and> atom k \\<sharp> CPS_sumC N \\<and> atom k' \\<sharp> CPS_sumC N \\<and>\n                    atom m \\<sharp> CPS_sumC N \\<and> atom m' \\<sharp> CPS_sumC N\")\nprefer 2\napply (intro conjI)\napply (erule fresh_eqvt_at, simp add: finite_supp, assumption)+\napply clarify\napply (case_tac \"k = k'\", case_tac [!] \"m' = k\",case_tac [!]\"m = k'\",case_tac[!] \"m = m'\")\napply (simp_all add: Abs1_eq_iff lt.fresh flip_def[symmetric] fresh_at_base flip_fresh_fresh permute_eq_iff)\nby (metis flip_at_base_simps(3) flip_at_simps(2) flip_commute permute_flip_at)+\n\nnominal_termination (eqvt) by lexicographic_order\n\nlemmas [simp] = fresh_Pair_elim CPS.simps(2,3)[simplified fresh_Pair_elim]\n\n\n\nlemma [simp]: \"x \\<sharp> M* = x \\<sharp> M\"\n  unfolding fresh_def by simp\n\nnominal_function\n  convert:: \"lt => lt\" (\"_+\" [250] 250)\nwhere\n  \"(Var x)+ = Var x\"\n| \"(Lam x M)+ = Lam x (M*)\"\n| \"(M $$ N)+ = M $$ N\"\n  unfolding convert_graph_aux_def eqvt_def\n  apply (simp)\n  apply(rule TrueI)\n  apply (erule lt.exhaust)\n  using [[simproc del: alpha_lst]]\n  apply (simp_all)\n  apply (simp add: Abs1_eq_iff CPS.eqvt)\n  by blast\n\nnominal_termination (eqvt)\n  by (relation \"measure size\") (simp_all)\n\nlemma convert_supp[simp]:\n  shows \"supp (M+) = supp M\"\n  by (induct M rule: lt.induct, simp_all add: lt.supp)\n\nlemma convert_fresh[simp]:\n  shows \"x \\<sharp> (M+) = x \\<sharp> M\"\n  unfolding fresh_def by simp\n\nlemma [simp]:\n  shows \"isValue (p \\<bullet> (M::lt)) = isValue M\"\n  by (nominal_induct M rule: lt.strong_induct) auto\n\nnominal_function\n  Kapply :: \"lt \\<Rightarrow> lt \\<Rightarrow> lt\"       (infixl \";\" 100)\nwhere\n  \"Kapply (Lam x M) K = K $$ (Lam x M)+\"\n| \"Kapply (Var x) K = K $$ Var x\"\n| \"isValue M \\<Longrightarrow> isValue N \\<Longrightarrow> Kapply (M $$ N) K = M+ $$ N+ $$ K\"\n| \"isValue M \\<Longrightarrow> \\<not>isValue N \\<Longrightarrow> atom n \\<sharp> M \\<Longrightarrow> atom n \\<sharp> K \\<Longrightarrow>\n    Kapply (M $$ N) K = N; (Lam n (M+ $$ Var n $$ K))\"\n| \"\\<not>isValue M \\<Longrightarrow> atom m \\<sharp> N \\<Longrightarrow> atom m \\<sharp> K \\<Longrightarrow> atom n \\<sharp> m \\<Longrightarrow> atom n \\<sharp> K \\<Longrightarrow>\n    Kapply (M $$ N) K = M; (Lam m (N*  $$ (Lam n (Var m $$ Var n $$ K))))\"\n  unfolding Kapply_graph_aux_def eqvt_def\n  apply (simp)\nusing [[simproc del: alpha_lst]]\napply (simp_all)\napply (case_tac x)\napply (rule_tac y=\"a\" in lt.exhaust)\napply (auto)\napply (case_tac \"isValue lt1\")\napply (case_tac \"isValue lt2\")\napply (auto)[1]\napply (rule_tac x=\"(lt1, ba)\" and ?'a=\"name\" in obtain_fresh)\napply (simp add: fresh_Pair_elim fresh_at_base)\napply (rule_tac x=\"(lt2, ba)\" and ?'a=\"name\" in obtain_fresh)\napply (rule_tac x=\"(a, ba)\" and ?'a=\"name\" in obtain_fresh)\napply (simp add: fresh_Pair_elim fresh_at_base)\napply (auto simp add: Abs1_eq_iff eqvts)[1]\napply (rename_tac M N u K)\napply (subgoal_tac \"Lam n (M+ $$ n~ $$ K) =  Lam u (M+ $$ u~ $$ K)\")\napply (simp only:)\napply (auto simp add: Abs1_eq_iff flip_fresh_fresh fresh_at_base)[1]\napply (subgoal_tac \"Lam m (Na* $$ Lam n (m~ $$ n~ $$ Ka)) = Lam ma (Na* $$ Lam na (ma~ $$ na~ $$ Ka))\")\napply (simp only:)\napply (simp add: Abs1_eq_iff flip_fresh_fresh fresh_at_base)\napply (case_tac \"m = ma\")\napply simp_all\napply (case_tac \"m = na\")\napply(simp_all add: flip_fresh_fresh)\ndone\n\nnominal_termination (eqvt)\n  by (relation \"measure (\\<lambda>(t, _). size t)\") (simp_all)\n\nsection{* lemma related to Kapply *}\n\nlemma [simp]: \"isValue V \\<Longrightarrow> V; K = K $$ (V+)\"\n  by (nominal_induct V rule: lt.strong_induct) auto\n\nsection{* lemma related to CPS conversion *}\n\nlemma value_CPS:\n  assumes \"isValue V\"\n  and \"atom a \\<sharp> V\"\n  shows \"V* = Lam a (a~ $$ V+)\"\n  using assms\nproof (nominal_induct V avoiding: a rule: lt.strong_induct, simp_all add: lt.fresh)\n  fix name :: name and lt aa\n  assume a: \"atom name \\<sharp> aa\" \"\\<And>b. \\<lbrakk>isValue lt; atom b \\<sharp> lt\\<rbrakk> \\<Longrightarrow> lt* = Lam b (b~ $$ lt+)\"\n    \"atom aa \\<sharp> lt \\<or> aa = name\"\n  obtain ab :: name where b: \"atom ab \\<sharp> (name, lt, a)\" using obtain_fresh by blast\n  show \"Lam name lt* = Lam aa (aa~ $$ Lam name (lt*))\" using a b\n    by (simp add: Abs1_eq_iff fresh_at_base lt.fresh)\nqed\n\nsection{* first lemma CPS subst *}\n\nlemma CPS_subst_fv:\n  assumes *:\"isValue V\"\n  shows \"((M[x ::= V])* = (M*)[x ::= V+])\"\nusing * proof (nominal_induct M avoiding: V x rule: lt.strong_induct)\n  case (Var name)\n  assume *: \"isValue V\"\n  obtain a :: name where a: \"atom a \\<sharp> (x, name, V)\" using obtain_fresh by blast\n  show \"((name~)[x ::= V])* = (name~)*[x ::= V+]\" using a\n    by (simp add: fresh_at_base * value_CPS)\nnext\n  case (Lam name lt V x)\n  assume *: \"atom name \\<sharp> V\" \"atom name \\<sharp> x\" \"\\<And>b ba. isValue b \\<Longrightarrow> (lt[ba ::= b])* = lt*[ba ::= b+]\"\n    \"isValue V\"\n  obtain a :: name where a: \"atom a \\<sharp> (name, lt, lt[x ::= V], x, V)\" using obtain_fresh by blast\n  show \"(Lam name lt[x ::= V])* = Lam name lt*[x ::= V+]\" using * a\n    by (simp add: fresh_at_base)\nnext\n  case (App lt1 lt2 V x)\n  assume *: \"\\<And>b ba. isValue b \\<Longrightarrow> (lt1[ba ::= b])* = lt1*[ba ::= b+]\" \"\\<And>b ba. isValue b \\<Longrightarrow> (lt2[ba ::= b])* = lt2*[ba ::= b+]\"\n    \"isValue V\"\n  obtain a :: name where a: \"atom a \\<sharp> (lt1[x ::= V], lt1, lt2[x ::= V], lt2, V, x)\" using obtain_fresh by blast\n  obtain b :: name where b: \"atom b \\<sharp> (lt2[x ::= V], lt2, a, V, x)\" using obtain_fresh by blast\n  obtain c :: name where c: \"atom c \\<sharp> (a, b, V, x)\" using obtain_fresh by blast\n  show \"((lt1 $$ lt2)[x ::= V])* = (lt1 $$ lt2)*[x ::= V+]\" using * a b c\n    by (simp add: fresh_at_base)\nqed\n\nlemma [simp]: \"isValue V \\<Longrightarrow> isValue (V+)\"\n  by (nominal_induct V rule: lt.strong_induct, auto)\n\nlemma CPS_eval_Kapply:\n  assumes a: \"isValue K\"\n  shows \"(M* $$ K) \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* (M ; K)\"\n  using a\nproof (nominal_induct M avoiding: K rule: lt.strong_induct, simp_all)\n  case (Var name K)\n  assume *: \"isValue K\"\n  obtain a :: name where a: \"atom a \\<sharp> (name, K)\" using obtain_fresh by blast\n  show \"(name~)* $$ K \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* K $$ name~\" using * a\n    by simp (rule evbeta', simp_all add: fresh_at_base)\nnext\n  fix name :: name and lt K\n  assume *: \"atom name \\<sharp> K\" \"\\<And>b. isValue b \\<Longrightarrow> lt* $$ b \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* lt ; b\" \"isValue K\"\n  obtain a :: name where a: \"atom a \\<sharp> (name, K, lt)\" using obtain_fresh by blast\n  then have b: \"atom name \\<sharp> a\" using fresh_PairD(1) fresh_at_base atom_eq_iff by metis\n  show \"Lam name lt* $$ K \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* K $$ Lam name (lt*)\" using * a b\n    by simp (rule evbeta', simp_all)\nnext\n  fix lt1 lt2 K\n  assume *: \"\\<And>b. isValue b \\<Longrightarrow>  lt1* $$ b \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* lt1 ; b\" \"\\<And>b. isValue b \\<Longrightarrow>  lt2* $$ b \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* lt2 ; b\" \"isValue K\"\n  obtain a :: name where a: \"atom a \\<sharp> (lt1, lt2, K)\" using obtain_fresh by blast\n  obtain b :: name where b: \"atom b \\<sharp> (lt1, lt2, K, a)\" using obtain_fresh by blast\n  obtain c :: name where c: \"atom c \\<sharp> (lt1, lt2, K, a, b)\" using obtain_fresh by blast\n  have d: \"atom a \\<sharp> lt1\" \"atom a \\<sharp> lt2\" \"atom a \\<sharp> K\" \"atom b \\<sharp> lt1\" \"atom b \\<sharp> lt2\" \"atom b \\<sharp> K\" \"atom b \\<sharp> a\"\n    \"atom c \\<sharp> lt1\" \"atom c \\<sharp> lt2\" \"atom c \\<sharp> K\" \"atom c \\<sharp> a\" \"atom c \\<sharp> b\" using fresh_Pair a b c by simp_all\n  have \"(lt1 $$ lt2)* $$ K \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* lt1* $$ Lam b (lt2* $$ Lam c (b~ $$ c~ $$ K))\" using * d\n    by (simp add: fresh_at_base) (rule evbeta', simp_all add: fresh_at_base)\n  also have \"... \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* lt1 $$ lt2 ; K\" proof (cases \"isValue lt1\")\n    assume e: \"isValue lt1\"\n    have \"lt1* $$ Lam b (lt2* $$ Lam c (b~ $$ c~ $$ K)) \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* Lam b (lt2* $$ Lam c (b~ $$ c~ $$ K)) $$ lt1+\"\n      using * d e by simp\n    also have \"... \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* lt2* $$ Lam c (lt1+ $$ c~ $$ K)\"\n      by (rule evbeta')(simp_all add: * d e)\n    also have \"... \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* lt1 $$ lt2 ; K\" proof (cases \"isValue lt2\")\n      assume f: \"isValue lt2\"\n      have \"lt2* $$ Lam c (lt1+ $$ c~ $$ K) \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* Lam c (lt1+ $$ c~ $$ K) $$ lt2+\" using * d e f by simp\n      also have \"... \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* lt1+ $$ lt2+ $$ K\"\n        by (rule evbeta', simp_all add: d e f)\n      finally show ?thesis using * d e f by simp\n    next\n      assume f: \"\\<not> isValue lt2\"\n      have \"lt2* $$ Lam c (lt1+ $$ c~ $$ K) \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* lt2 ; Lam c (lt1+ $$ c~ $$ K)\" using * d e f by simp\n      also have \"... \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* lt2 ; Lam a (lt1+ $$ a~ $$ K)\" using Kapply.simps(4) d e evs1 f by metis\n      finally show ?thesis using * d e f by simp\n    qed\n    finally show ?thesis .\n  qed (metis Kapply.simps(5) isValue.simps(2) * d)\n  finally show \"(lt1 $$ lt2)* $$ K \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* lt1 $$ lt2 ; K\" .\nqed\n\nlemma Kapply_eval:\n  assumes a: \"M \\<longrightarrow>\\<^isub>\\<beta> N\" \"isValue K\"\n  shows \"(M; K) \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>*  (N; K)\"\n  using assms\nproof (induct arbitrary: K rule: eval.induct)\n  case (evbeta x V M)\n  fix K\n  assume a: \"isValue K\" \"isValue V\" \"atom x \\<sharp> V\"\n  have \"Lam x (M*) $$ V+ $$ K \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* (((M*)[x ::= V+]) $$ K)\"\n    by (rule evs2,rule ev2,rule Lt.evbeta) (simp_all add: fresh_def a[simplified fresh_def] evs1)\n  also have \"... = ((M[x ::= V])* $$ K)\" by (simp add: CPS_subst_fv a)\n  also have \"... \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* ((M[x ::= V]) ; K)\" by (rule CPS_eval_Kapply, simp_all add: a)\n  finally show \"(Lam x M $$ V ; K) \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>*  ((M[x ::= V]) ; K)\" using a by simp\nnext\n  case (ev1 V M N)\n  fix V M N K\n  assume a: \"isValue V\" \"M \\<longrightarrow>\\<^isub>\\<beta> N\" \"\\<And>K. isValue K \\<Longrightarrow> M ; K \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* N ; K\" \"isValue K\"\n  obtain a :: name where b: \"atom a \\<sharp> (V, K, M, N)\" using obtain_fresh by blast\n  show \"V $$ M ; K \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* V $$ N ; K\" proof (cases \"isValue N\")\n    assume \"\\<not> isValue N\"\n    then show \"V $$ M ; K \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* V $$ N ; K\" using a b by simp\n  next\n    assume n: \"isValue N\"\n    have c: \"M; Lam a (V+ $$ a~ $$ K) \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* Lam a (V+ $$ a~ $$ K) $$ N+\" using a b by (simp add: n)\n    also have d: \"... \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* V+ $$ N+ $$ K\" by (rule evbeta') (simp_all add: a b n)\n    finally show \"V $$ M ; K \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* V $$ N ; K\" using a b by (simp add: n)\n  qed\nnext\n  case (ev2 M M' N)\n  assume *: \"M \\<longrightarrow>\\<^isub>\\<beta> M'\" \"\\<And>K. isValue K \\<Longrightarrow>  M ; K \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* M' ; K\" \"isValue K\"\n  obtain a :: name where a: \"atom a \\<sharp> (K, M, N, M')\" using obtain_fresh by blast\n  obtain b :: name where b: \"atom b \\<sharp> (a, K, M, N, M', N+)\" using obtain_fresh by blast\n  have d: \"atom a \\<sharp> K\" \"atom a \\<sharp> M\" \"atom a \\<sharp> N\" \"atom a \\<sharp> M'\" \"atom b \\<sharp> a\" \"atom b \\<sharp> K\"\n    \"atom b \\<sharp> M\" \"atom b \\<sharp> N\" \"atom b \\<sharp> M'\" using a b fresh_Pair by simp_all\n  have \"M $$ N ; K  \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* M' ; Lam a (N* $$ Lam b (a~ $$ b~ $$ K))\" using * d by simp\n  also have \"... \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* M' $$ N ; K\" proof (cases \"isValue M'\")\n    assume \"\\<not> isValue M'\"\n    then show ?thesis using * d by (simp_all add: evs1)\n  next\n    assume e: \"isValue M'\"\n    then have \"M' ; Lam a (N* $$ Lam b (a~ $$ b~ $$ K)) = Lam a (N* $$ Lam b (a~ $$ b~ $$ K)) $$ M'+\" by simp\n    also have \"... \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* (N* $$ Lam b (a~ $$ b~ $$ K))[a ::= M'+]\"\n      by (rule evbeta') (simp_all add: fresh_at_base e d)\n    also have \"... = N* $$ Lam b (M'+ $$ b~ $$ K)\" using * d by (simp add: fresh_at_base)\n    also have \"... \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* M' $$ N ; K\" proof (cases \"isValue N\")\n      assume f: \"isValue N\"\n      have \"N* $$ Lam b (M'+ $$ b~ $$ K) \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* Lam b (M'+ $$ b~ $$ K) $$ N+\"\n        by (rule eval_trans, rule CPS_eval_Kapply) (simp_all add: d e f * evs1)\n      also have \"... \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* M' $$ N ; K\" by (rule evbeta') (simp_all add: d e f evs1)\n      finally show ?thesis .\n    next\n      assume \"\\<not> isValue N\"\n      then show ?thesis using d e\n        by (metis CPS_eval_Kapply Kapply.simps(4) isValue.simps(2))\n    qed\n    finally show ?thesis .\n  qed\n  finally show ?case .\nqed\n\nlemma Kapply_eval_rtrancl:\n  assumes H: \"M \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>*  N\" and \"isValue K\"\n  shows \"(M;K) \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* (N;K)\"\n  using H\n  by (induct) (metis Kapply_eval assms(2) eval_trans evs1)+\n\nlemma\n  assumes \"isValue V\" \"M \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* V\"\n  shows \"M* $$ (Lam x (x~)) \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* V+\"\nproof-\n  obtain y::name where *: \"atom y \\<sharp> V\" using obtain_fresh by blast\n  have e: \"Lam x (x~) = Lam y (y~)\"\n    by (simp add: Abs1_eq_iff lt.fresh fresh_at_base)\n  have \"M* $$ Lam x (x~) \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* M ; Lam x (x~)\"\n    by(rule CPS_eval_Kapply,simp_all add: assms)\n  also have \"... \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* (V ; Lam x (x~))\" by (rule Kapply_eval_rtrancl, simp_all add: assms)\n  also have \"... = V ; Lam y (y~)\" using e by (simp only:)\n  also have \"... \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* (V+)\" by (simp add: assms, rule evbeta') (simp_all add: assms *)\n  finally show \"M* $$ (Lam x (x~)) \\<longrightarrow>\\<^isub>\\<beta>\\<^sup>* (V+)\" .\nqed\n\nend\n\n\n\n", "meta": {"author": "goodlyrottenapple", "repo": "Nominal2-Isabelle", "sha": "214274ed6db74c19b8694fc5c8dd9cafa13b056a", "save_path": "github-repos/isabelle/goodlyrottenapple-Nominal2-Isabelle", "path": "github-repos/isabelle/goodlyrottenapple-Nominal2-Isabelle/Nominal2-Isabelle-214274ed6db74c19b8694fc5c8dd9cafa13b056a/Nominal/Ex/CPS/CPS1_Plotkin.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5506073655352403, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.29248779362094973}}
{"text": "section \\<open>Set Interface\\<close>\ntheory IICF_Set\nimports \"../../Sepref\"\nbegin\n\nsubsection \\<open>Operations\\<close>\n\ncontext \n  notes [simp] = IS_LEFT_UNIQUE_def (* Argh, the set parametricity lemmas use single_valued (K\\<inverse>) here. *)\nbegin\n\ncontext\n  fixes t ::  \"unit \\<Rightarrow> nat\"\nbegin\n  definition \"mop_set_empty = SPECT [ {} \\<mapsto> enat (t ()) ]\"\n\n  lemma mop_set_empty: \"tt \\<le> lst (SPECT [ {} \\<mapsto> (t ()) ]) Q \\<Longrightarrow> tt\n           \\<le> lst (mop_set_empty) Q\" unfolding mop_set_empty_def by simp\n\n  sepref_register \"mop_set_empty\" \nend\n\n\ncontext\n  fixes t ::  \"'c set \\<Rightarrow> nat\"\nbegin\n  definition \"mop_set_isempty S = SPECT [ S={} \\<mapsto> t S ]\"\n\n  lemma  mop_set_isempty: \"tt \\<le> lst (SPECT [ S={} \\<mapsto> t S ])  Q\n        \\<Longrightarrow> tt \\<le> lst (mop_set_isempty S) Q\" unfolding mop_set_isempty_def by simp\n \n  sepref_register \"mop_set_isempty\" \nend\n\n\ncontext\n  fixes t ::  \"'c set \\<Rightarrow> nat\"\nbegin\n  definition \"mop_set_pick S = do { ASSERT (S\\<noteq>{}); SPECT (emb (\\<lambda>x. x\\<in>S) (t S)) }\"\n\n  lemma  mop_set_pick: \"tt \\<le> lst (SPECT (emb (\\<lambda>x. x\\<in>S) (t S)))  Q\n        \\<Longrightarrow> S \\<noteq> {} \\<Longrightarrow> tt \\<le> lst (mop_set_pick S) Q\" unfolding mop_set_pick_def by simp\n\n  lemma progress_mop_set_pick[progress_rules]: \"t S > 0 \\<Longrightarrow> progress (mop_set_pick S)\"\n    unfolding mop_set_pick_def by (auto intro!: progress_rules simp add:   zero_enat_def) \n\n  sepref_register \"mop_set_pick\" \nend\n\ncontext\n  fixes t ::  \"'c set \\<Rightarrow> nat\"\nbegin\n  definition \"mop_set_pick_extract S = do { ASSERT (S\\<noteq>{}); SPECT (emb (\\<lambda>(x,C). x\\<in>S \\<and> C=S-{x}) (t S)) }\"\n\n  lemma  mop_set_pick_extract: \"tt \\<le> lst (SPECT (emb (\\<lambda>(x,C). x\\<in>S \\<and> C=S-{x}) (t S))) Q\n        \\<Longrightarrow> S \\<noteq> {} \\<Longrightarrow> tt \\<le> lst (mop_set_pick_extract S) Q\" unfolding mop_set_pick_extract_def by simp\n\n  thm progress_rules\n\n  lemma progress_mop_set_pick_extract[progress_rules]: \"t S > 0 \\<Longrightarrow> progress (mop_set_pick_extract S)\"\n    unfolding mop_set_pick_extract_def by (auto intro!: progress_rules simp add:   zero_enat_def) \n\n  sepref_register \"mop_set_pick_extract\" \nend\n \n\n\ncontext\n  fixes t:: \"('c * 'c set) \\<Rightarrow> nat\" \nbegin\n  definition \"mop_set_member x S = SPECT [ x \\<in> S \\<mapsto> enat (t (x,S)) ]\"\n  sepref_register \"mop_set_member\" \n  print_theorems \nend\n\n \n\ncontext\n  fixes t ::  \"('c set * 'c) \\<Rightarrow> nat\"\nbegin\n  definition \"mop_set_del S x = SPECT [ S - {x} \\<mapsto> t (S,x)]\"\n\n  lemma  mop_set_del: \"tt \\<le> lst (SPECT [ S - {x} \\<mapsto> t (S,x)])  Q\n        \\<Longrightarrow> tt \\<le> lst (mop_set_del S x) Q\" unfolding mop_set_del_def by simp\n\n\n  lemma progress_mop_set_del[progress_rules]: \"t (S,x) > 0 \\<Longrightarrow> progress (mop_set_del S x)\"\n      unfolding mop_set_del_def  by (auto intro: progress_rules simp add:   zero_enat_def) \n\n  sepref_register \"mop_set_del\" \nend\n\n\ncontext \n  fixes t :: \"('c*'c set) \\<Rightarrow> nat\"\nbegin\n\n  definition \"mop_set_insert x S = SPECT [insert x S \\<mapsto> t (x,S)]\"\n\n  lemma mop_set_insert: \"tt \\<le> lst (SPECT [ (insert x S) \\<mapsto> t (x,S)]) Q \\<Longrightarrow>\n         tt \\<le> lst (mop_set_insert x S) Q\" unfolding mop_set_insert_def by simp\n\n  sepref_register \"mop_set_insert\" \nend\n\nend\nend\n\n", "meta": {"author": "maxhaslbeck", "repo": "Sepreftime", "sha": "c1c987b45ec886d289ba215768182ac87b82f20d", "save_path": "github-repos/isabelle/maxhaslbeck-Sepreftime", "path": "github-repos/isabelle/maxhaslbeck-Sepreftime/Sepreftime-c1c987b45ec886d289ba215768182ac87b82f20d/Refine_Imperative_HOL/IICF/Intf/IICF_Set.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6187804337438501, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.2924872866867424}}
{"text": "theory Proof_5_8\n  imports Proofs_5\nbegin\n\nabbreviation s where \"s s0 userAtTop_value userAtBottom_value directionSwitch_value alarmButton_value stuck_value \\<equiv>\n (toEnv\n       (setPstate (setVarAny s0 userAtTop_value userAtBottom_value directionSwitch_value alarmButton_value stuck_value) ERROR\n         Ctrl'emergency))\"\n\ntheorem proof_5_8: \"VC8 inv5 env s0 userAtTop_value userAtBottom_value directionSwitch_value alarmButton_value stuck_value\"\n  apply(simp only: VC8_def inv5_def R5_def extraInv_def)\n  apply(rule impI)\n  apply(rule conjI)\n   apply(rule conjI)\n    apply simp\n   apply((rule allI)+)\n   apply(rule impI)\n   apply((drule conjE)+)\n                      prefer 31\n                      apply assumption\n                      prefer 30\n                      apply assumption\n                      prefer 29\n                      apply assumption\n                      prefer 28\n                      apply assumption\n                      prefer 27\n                      apply assumption\n                      prefer 26\n                      apply assumption\n                      prefer 25\n                      apply assumption\n                      prefer 24\n                      apply assumption\n                      prefer 23\n                      apply assumption\n                      prefer 22\n                      apply assumption\n                      prefer 21\n                      apply assumption\n                      prefer 20\n                      apply assumption\n                     prefer 19\n                     apply assumption\n                    prefer 18\n                    apply assumption\n                   prefer 17\n                   apply assumption\n                  prefer 16\n                  apply assumption\n                 prefer 15\n                 apply assumption\n                prefer 14\n                apply assumption\n               prefer 13\n               apply assumption\n              prefer 12\n              apply assumption\n             prefer 11\n             apply assumption\n            prefer 10\n            apply assumption\n           prefer 9\n           apply assumption\n          prefer 8\n          apply assumption\n         prefer 7\n         apply assumption\n        prefer 6\n        apply assumption\n       prefer 5\n       apply assumption\n      prefer 4\n      apply assumption\n     prefer 3\n     apply assumption\n    prefer 2\n    apply assumption\n  subgoal premises prems for s1 s2\n    apply(rule disjE[OF le_imp_less_or_eq[OF prems(13)]])\n    apply(rule cut_rl[of \" \\<exists>s4. toEnvP s4 \\<and>\n         substate s2 s4 \\<and>\n         substate s4  s0 \\<and>\n         toEnvNum s2 s4 \\<le> ERROR \\<and>\n         getVarBool s4 up' = DOWN' \\<and>\n         getVarBool s4 down' = DOWN' \\<and>\n         (\\<forall>s3. toEnvP s3 \\<and> substate s2 s3 \\<and> substate s3 s4 \\<and> s3 \\<noteq> s4 \\<longrightarrow> getVarBool s3 up' = UP' \\<or> getVarBool s3 down' = UP')\"])\n      apply(drule exE)\n       prefer 2\n       apply assumption\n    subgoal for s4\n      apply(rule exI[of _ s4])\n      by simp\n    using prems(2) prems(4) prems(6) prems(8) prems(9) prems(11) prems(15) prems(16) apply -[1]\n     apply(drule allE[of _ s1])\n      prefer 2\n      apply assumption\n     apply(drule allE[of _ s2])\n      prefer 2\n      apply assumption\n     apply(simp split: if_splits)\n    apply(rule cut_rl[of \"\\<forall> s5. toEnvP s5 \\<and> substate s2 s5 \\<and> substate s5\n (s s0 userAtTop_value userAtBottom_value directionSwitch_value alarmButton_value stuck_value) \\<longrightarrow>\n pred5 s1 s2\n (s s0 userAtTop_value userAtBottom_value directionSwitch_value alarmButton_value stuck_value) s5\"])\n     apply(drule allE[of _ s2])\n      prefer 2\n      apply assumption\n     apply(drule impE)\n       prefer 3\n       apply assumption\n    using prems(4,8) substate_refl apply fast\n     apply(simp only: pred5_def)\n     apply(drule impE)\n       prefer 3\n       apply assumption\n    using prems(2)  prems(4) prems(6) prems(8) prems(9) prems(15) prems(16) substate_refl substate_trans substate_antisym\n      apply blast\n     apply fast\n      apply(rule allI)\n    subgoal premises toEnvNums2s for s5\n      apply(induction rule: state_down_ind)\n      using prems(8) apply simp\n       apply(simp only: pred5_def)\n       apply(rule impI)\n       apply((drule conjE)+)\n                  prefer 12\n                  apply assumption\n                 prefer 11\n                 apply assumption\n                prefer 10\n                apply assumption\n               prefer 9\n               apply assumption\n              prefer 8\n              apply assumption\n             prefer 7\n             apply assumption\n            prefer 6\n            apply assumption\n           prefer 5\n           apply assumption\n          prefer 4\n          apply assumption\n         prefer 3\n         apply assumption\n        prefer 2\n        apply assumption\n\n       apply(rule cut_rl[of\n \"\\<exists>s4. toEnvP s4 \\<and> substate s4 s0 \\<and> toEnvNum s4 s0 \\<le> ERROR \\<and> getVarBool s4 up' = DOWN' \\<and> getVarBool s4 down' = DOWN'\"])\n        apply(drule exE)\n         prefer 2\n         apply assumption\n      subgoal for s4\n        apply(rule disjE[of \"toEnvNum s4 s0 < 1\" \"toEnvNum s4 s0 = 1\"])\n          apply(rule le_imp_less_or_eq)\n          apply fast\n        apply (metis getPstate.simps(9) less_one prems(10) prems(30) prems(5) substate_toEnvNum_id)\n        apply(rule cut_rl[of \"s4 = s1\"])\n         apply simp\n        apply (simp split: if_splits)\n        using toEnvNum3 substate_toEnvNum_id gtimeE_inj\n        by (metis prems(10) shift_toEnvNum) \n       apply(rule goUp_not_moving[of s2 _ s0])\n       apply(rule conjI)\n        apply assumption\n       apply(rule conjI)\n      using prems(10) apply fast\n       apply(rule conjI)\n        apply (simp split: if_splits)\n       apply(rule conjI)\n      using substate_refl apply fast\n       apply(rule conjI)\n        apply(simp split: if_splits)\n       apply(rule conjI)\n        apply assumption\n       apply(rule conjI)\n      using prems(5) apply simp\n      using prems apply fast\n\n      subgoal for s5\n        apply(simp only: pred5_def)\n        apply(rule impI)\n        apply(cases \"getVarBool (predEnv s5) up' = False  \\<and> getVarBool (predEnv s5) down' = False\")\n       apply(rule exI[of _ \"predEnv s5\"])\n       apply(rule conjI)\n        apply(rule toEnvP_substate_pred_imp_toEnvP_pred[of s2])\n        apply blast\n       apply(rule conjI)\n      using substate_refl apply simp\n       apply(rule conjI)\n      using predEnv_substate substate_trans apply blast\n       apply(rule conjI)\n      using toEnvNum3[of s2 \"predEnv s5\"\n \"(s s0 userAtTop_value userAtBottom_value directionSwitch_value alarmButton_value stuck_value) \"]\n        apply force\n       apply(rule conjI)\n        apply fast\n       apply(rule conjI)\n        apply fast\n      using substate_antisym apply fast\n      apply(drule impE)\n        apply(((rule conjI),blast)+)\n      using substate_eq_or_predEnv apply blast\n      prefer 2\n       apply assumption\n      apply(drule exE)\n       prefer 2\n       apply assumption\n      subgoal for s4\n        apply(rule exI[of _ s4])\n       apply(rule conjI)\n         apply blast\n        apply(rule conjI)\n        using predEnv_substate substate_trans apply blast\n        apply(((rule conjI),blast)+)\n        apply((drule conjE)+)\n                           prefer 20\n                           apply assumption\n                          prefer 19\n                          apply assumption\n                         prefer 18\n                         apply assumption\n                        prefer 17\n                        apply assumption\n                       prefer 16\n                       apply assumption\n                      prefer 15\n                      apply assumption\n                     prefer 14\n                     apply assumption\n                    prefer 13\n                    apply assumption\n                   prefer 12\n                   apply assumption\n                  prefer 11\n                  apply assumption\n                 prefer 10\n                 apply assumption\n                prefer 9\n                apply assumption\n               prefer 8\n               apply assumption\n              prefer 7\n              apply assumption\n             prefer 6\n             apply assumption\n            prefer 5\n            apply assumption\n           prefer 4\n           apply assumption\n          prefer 3\n          apply assumption\n         prefer 2\n         apply assumption\n        using predEnv_substate_imp_eq_or_substate by blast\n      done\n    done\n  done\n           \n\n        \n", "meta": {"author": "ivchernenko", "repo": "post_vcgenerator", "sha": "fadfff131086870a027d6bd1c78b8d5a3baf183b", "save_path": "github-repos/isabelle/ivchernenko-post_vcgenerator", "path": "github-repos/isabelle/ivchernenko-post_vcgenerator/post_vcgenerator-fadfff131086870a027d6bd1c78b8d5a3baf183b/case-studies/escalator/Proof_5_8.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.61878043374385, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.29248728668674234}}
{"text": "theory flash imports flashMainLemma\nbegin\n\nlemma main:\n  assumes   a1:\"s \\<in> reachableSet {andList (allIniSpecs   N)} (rules N)\"  and a2:\"0<N\"\n\n  shows \"\\<forall>invf. invf \\<in>(invariants N)\\<longrightarrow>formEval invf s\"\nproof(rule newconsistentLemma)\n  show \"newconsistent (invariants N) {andList (allIniSpecs   N)}(rules N)\"\n  proof(cut_tac a1, unfold newconsistent_def,rule conjI)\n    show \" \\<forall>invf ini s. invf \\<in>(invariants N)\\<longrightarrow> ini \\<in>{andList (allIniSpecs   N)}\\<longrightarrow> formEval ini s\\<longrightarrow> formEval invf s\"\n    proof((rule allI)+,(rule impI)+)\n      fix invf ini s \n      assume b1:\"invf \\<in>(invariants N) \" and b2:\"ini \\<in> {andList (allIniSpecs   N)} \" and b3:\"formEval ini s\"\n                \n      have b4:\"formEval (andList (allIniSpecs   N)) s\"\n         by(cut_tac b2 b3,simp)\n\n      show \"formEval invf s\"\n      proof -     \n        \n        have c1:\" ex2P N (% iInv1  iInv2 .  invf= inv1  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv2  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv3  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv4  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv5  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv6  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv7  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv8  iInv1  iInv2 )  \\<or> ex1P N (% iInv1 .  invf= inv9  iInv1 )  \\<or> ex1P N (% iInv1 .  invf= inv10  iInv1 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv11  iInv1  iInv2 )  \\<or> ex0P N  (  invf= inv12 )  \\<or> ex1P N (% iInv1 .  invf= inv13  iInv1 )  \\<or> ex1P N (% iInv1 .  invf= inv14  iInv1 )  \\<or> ex3P N (% iInv1  iInv2  iInv3 .  invf= inv15  iInv1  iInv2  iInv3 )  \\<or> ex3P N (% iInv1  iInv2  iInv3 .  invf= inv16  iInv1  iInv2  iInv3 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv17  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv18  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv19  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv20  iInv1  iInv2 )  \\<or> ex1P N (% iInv1 .  invf= inv21  iInv1 )  \\<or> ex3P N (% iInv1  iInv2  iInv3 .  invf= inv22  iInv1  iInv2  iInv3 )  \\<or> ex3P N (% iInv1  iInv2  iInv3 .  invf= inv23  iInv1  iInv2  iInv3 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv24  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv25  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv26  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv27  iInv1  iInv2 )  \\<or> ex1P N (% iInv1 .  invf= inv28  iInv1 )  \\<or> ex1P N (% iInv1 .  invf= inv29  iInv1 )  \\<or> ex1P N (% iInv1 .  invf= inv30  iInv1 )  \\<or> ex1P N (% iInv1 .  invf= inv31  iInv1 )  \\<or> ex1P N (% iInv1 .  invf= inv32  iInv1 )  \\<or> ex1P N (% iInv1 .  invf= inv33  iInv1 )  \\<or> ex1P N (% iInv1 .  invf= inv34  iInv1 )  \\<or> ex1P N (% iInv1 .  invf= inv35  iInv1 )  \\<or> ex1P N (% iInv1 .  invf= inv36  iInv1 )  \\<or> ex0P N  (  invf= inv37 )  \\<or> ex0P N  (  invf= inv38 )  \\<or> ex0P N  (  invf= inv39 )  \\<or> ex1P N (% iInv1 .  invf= inv40  iInv1 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv41  iInv1  iInv2 )  \\<or> ex3P N (% iInv1  iInv2  iInv3 .  invf= inv42  iInv1  iInv2  iInv3 )  \\<or> ex0P N  (  invf= inv43 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv44  iInv1  iInv2 )  \\<or> ex0P N  (  invf= inv45 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv46  iInv1  iInv2 )  \\<or> ex0P N  (  invf= inv47 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv48  iInv1  iInv2 )  \\<or> ex3P N (% iInv1  iInv2  iInv3 .  invf= inv49  iInv1  iInv2  iInv3 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv50  iInv1  iInv2 )  \\<or> ex3P N (% iInv1  iInv2  iInv3 .  invf= inv51  iInv1  iInv2  iInv3 )  \\<or> ex3P N (% iInv1  iInv2  iInv3 .  invf= inv52  iInv1  iInv2  iInv3 )  \\<or> ex0P N  (  invf= inv53 )  \\<or> ex3P N (% iInv1  iInv2  iInv3 .  invf= inv54  iInv1  iInv2  iInv3 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv55  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv56  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv57  iInv1  iInv2 )  \\<or> ex3P N (% iInv1  iInv2  iInv3 .  invf= inv58  iInv1  iInv2  iInv3 )  \\<or> ex3P N (% iInv1  iInv2  iInv3 .  invf= inv59  iInv1  iInv2  iInv3 )  \\<or> ex1P N (% iInv1 .  invf= inv60  iInv1 )  \\<or> ex1P N (% iInv1 .  invf= inv61  iInv1 )  \\<or> ex1P N (% iInv1 .  invf= inv62  iInv1 )  \\<or> ex1P N (% iInv1 .  invf= inv63  iInv1 )  \\<or> ex1P N (% iInv1 .  invf= inv64  iInv1 )  \\<or> ex1P N (% iInv1 .  invf= inv65  iInv1 )  \\<or> ex0P N  (  invf= inv66 )  \\<or> ex0P N  (  invf= inv67 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv68  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv69  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv70  iInv1  iInv2 )  \\<or> ex0P N  (  invf= inv71 )  \\<or> ex0P N  (  invf= inv72 )  \\<or> ex0P N  (  invf= inv73 )  \\<or> ex0P N  (  invf= inv74 )  \\<or> ex0P N  (  invf= inv75 )  \\<or> ex0P N  (  invf= inv76 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv77  iInv1  iInv2 )  \\<or> ex0P N  (  invf= inv78 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv79  iInv1  iInv2 )  \\<or> ex0P N  (  invf= inv80 )  \\<or> ex0P N  (  invf= inv81 )  \\<or> ex1P N (% iInv1 .  invf= inv82  iInv1 )  \\<or> ex0P N  (  invf= inv83 )  \\<or> ex0P N  (  invf= inv84 )  \\<or> ex0P N  (  invf= inv85 )  \\<or> ex0P N  (  invf= inv86 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv87  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv88  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv89  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv90  iInv1  iInv2 )  \\<or> ex0P N  (  invf= inv91 )  \\<or> ex0P N  (  invf= inv92 )  \\<or> ex0P N  (  invf= inv93 )  \\<or> ex0P N  (  invf= inv94 )  \\<or> ex0P N  (  invf= inv95 )  \\<or> ex0P N  (  invf= inv96 )  \\<or> ex0P N  (  invf= inv97 )  \\<or> ex0P N  (  invf= inv98 )  \\<or> ex0P N  (  invf= inv99 )  \\<or> ex0P N  (  invf= inv100 )  \\<or> ex1P N (% iInv1 .  invf= inv101  iInv1 )  \\<or> ex0P N  (  invf= inv102 )  \\<or> ex0P N  (  invf= inv103 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv104  iInv1  iInv2 )  \\<or> ex2P N (% iInv1  iInv2 .  invf= inv105  iInv1  iInv2 )  \\<or> ex0P N  (  invf= inv106 )  \\<or> ex0P N  (  invf= inv107 )  \\<or> ex0P N  (  invf= inv108 )  \\<or> ex0P N  (  invf= inv109 )  \\<or> ex0P N  (  invf= inv110 )  \\<or> ex0P N  (  invf= inv111 )  \\<or> ex0P N  (  invf= inv112 )  \\<or> ex0P N  (  invf= inv113 )   \"\n          by (cut_tac b1, simp )       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv1  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv1.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv2  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv2.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv3  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv3.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv4  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv4.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv5  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv5.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv6  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv6.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv7  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv7.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv8  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv8.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv9  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv9.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv10  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv10.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv11  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv11.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv12 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv12.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv13  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv13.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv14  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv14.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex3P N (% iInv1  iInv2  iInv3 .  invf= inv15  iInv1  iInv2  iInv3 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv15.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex3P N (% iInv1  iInv2  iInv3 .  invf= inv16  iInv1  iInv2  iInv3 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv16.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv17  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv17.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv18  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv18.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv19  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv19.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv20  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv20.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv21  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv21.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex3P N (% iInv1  iInv2  iInv3 .  invf= inv22  iInv1  iInv2  iInv3 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv22.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex3P N (% iInv1  iInv2  iInv3 .  invf= inv23  iInv1  iInv2  iInv3 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv23.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv24  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv24.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv25  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv25.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv26  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv26.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv27  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv27.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv28  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv28.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv29  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv29.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv30  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv30.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv31  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv31.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv32  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv32.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv33  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv33.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv34  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv34.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv35  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv35.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv36  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv36.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv37 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv37.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv38 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv38.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv39 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv39.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv40  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv40.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv41  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv41.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex3P N (% iInv1  iInv2  iInv3 .  invf= inv42  iInv1  iInv2  iInv3 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv42.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv43 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv43.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv44  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv44.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv45 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv45.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv46  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv46.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv47 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv47.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv48  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv48.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex3P N (% iInv1  iInv2  iInv3 .  invf= inv49  iInv1  iInv2  iInv3 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv49.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv50  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv50.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex3P N (% iInv1  iInv2  iInv3 .  invf= inv51  iInv1  iInv2  iInv3 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv51.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex3P N (% iInv1  iInv2  iInv3 .  invf= inv52  iInv1  iInv2  iInv3 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv52.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv53 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv53.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex3P N (% iInv1  iInv2  iInv3 .  invf= inv54  iInv1  iInv2  iInv3 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv54.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv55  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv55.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv56  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv56.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv57  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv57.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex3P N (% iInv1  iInv2  iInv3 .  invf= inv58  iInv1  iInv2  iInv3 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv58.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex3P N (% iInv1  iInv2  iInv3 .  invf= inv59  iInv1  iInv2  iInv3 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv59.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv60  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv60.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv61  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv61.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv62  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv62.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv63  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv63.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv64  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv64.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv65  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv65.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv66 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv66.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv67 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv67.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv68  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv68.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv69  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv69.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv70  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv70.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv71 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv71.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv72 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv72.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv73 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv73.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv74 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv74.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv75 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv75.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv76 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv76.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv77  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv77.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv78 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv78.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv79  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv79.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv80 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv80.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv81 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv81.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv82  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv82.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv83 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv83.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv84 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv84.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv85 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv85.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv86 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv86.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv87  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv87.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv88  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv88.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv89  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv89.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv90  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv90.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv91 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv91.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv92 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv92.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv93 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv93.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv94 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv94.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv95 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv95.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv96 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv96.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv97 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv97.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv98 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv98.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv99 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv99.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv100 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv100.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex1P N (% iInv1 .  invf= inv101  iInv1 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv101.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv102 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv102.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv103 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv103.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv104  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv104.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex2P N (% iInv1  iInv2 .  invf= inv105  iInv1  iInv2 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv105.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv106 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv106.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv107 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv107.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv108 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv108.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv109 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv109.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv110 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv110.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv111 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv111.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv112 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv112.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n       moreover\n        {assume d1: \" ex0P N  (  invf= inv113 )  \"\n\n          have \"formEval invf s\"\n\n            by(metis b4 d1 iniImply_inv113.iniImplyInv)\n           (* apply(cut_tac d1,assumption)\n           by (cut_tac  b4,simp)*)\n        }\n\n      ultimately show \"formEval invf s\"\n      by blast\n      qed\n    qed\nnext\n   show  \"\\<forall>invf r s. invf \\<in> invariants N\\<longrightarrow> r \\<in>rules N\\<longrightarrow> invHoldForRule' s invf r (invariants N) \"\n   \n\n   proof((rule allI)+,(rule impI)+)\n      fix invf r s\n      assume b1:\"invf \\<in> invariants N\" and b2:\"r \\<in> rules N\"\n      show \"invHoldForRule' s invf r (invariants N) \"\n          by (metis mainLemma b1 b2) \n     qed\nqed\nnext\n  show \"s \\<in> reachableSet {andList (allIniSpecs   N)}  (rules N)\"\nby (metis a1)\n \n \nqed\nend  \n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6859494421679929, "lm_q2_score": 0.4263215925474903, "lm_q1q2_score": 0.2924350585921213}}
{"text": "section \\<open>Operation Identification Phase\\<close>\ntheory Sepref_Id_Op\nimports \n  Main \n  Automatic_Refinement.Refine_Lib\n  Automatic_Refinement.Autoref_Tagging\n  Refine_Imperative_HOL.Named_Theorems_Rev\nbegin\n\ntext \\<open>\n  The operation identification phase is adapted from the Autoref tool.\n  The basic idea is to have a type system, which works on so called \n  interface types (also called conceptual types). Each conceptual type\n  denotes an abstract data type, e.g., set, map, priority queue.\n  \n  Each abstract operation, which must be a constant applied to its arguments,\n  is assigned a conceptual type. Additionally, there is a set of \n  {\\emph pattern rewrite rules},\n  which are applied to subterms before type inference takes place, and \n  which may be backtracked over. \n  This way, encodings of abstract operations in Isabelle/HOL, like \n  @{term [source] \"\\<lambda>_. None\"} for the empty map, \n  or @{term [source] \"fun_upd m k (Some v)\"} for map update, can be rewritten\n  to abstract operations, and get properly typed.\n\\<close>\n\nsubsection \"Proper Protection of Term\"\ntext \\<open> The following constants are meant to encode abstraction and \n  application as proper HOL-constants, and thus avoid strange effects with\n  HOL's higher-order unification heuristics and automatic \n  beta and eta-contraction.\n\n  The first step of operation identification is to protect the term\n  by replacing all function applications and abstractions be \n  the constants defined below.\n\\<close>\n\ndefinition [simp]: \"PROTECT2 x (y::prop) \\<equiv> x\"\nconsts DUMMY :: \"prop\"\n\nabbreviation PROTECT2_syn (\"'(#_#')\") where \"PROTECT2_syn t \\<equiv> PROTECT2 t DUMMY\"\n\nabbreviation (input)ABS2 :: \"('a\\<Rightarrow>'b)\\<Rightarrow>'a\\<Rightarrow>'b\" (binder \"\\<lambda>\\<^sub>2\" 10)\n  where \"ABS2 f \\<equiv> (\\<lambda>x. PROTECT2 (f x) DUMMY)\"\n\nlemma beta: \"(\\<lambda>\\<^sub>2x. f x)$x \\<equiv> f x\" by simp\n\ntext \\<open>\n  Another version of @{const \"APP\"}. Treated like @{const APP} by our tool.\n  Required to avoid infinite pattern rewriting in some cases, e.g., map-lookup.\n\\<close>\n\ndefinition APP' (infixl \"$''\" 900) where [simp, autoref_tag_defs]: \"f$'a \\<equiv> f a\"\n\ntext \\<open>\n  Sometimes, whole terms should be protected from being processed by our tool.\n  For example, our tool should not look into numerals. For this reason,\n  the \\<open>PR_CONST\\<close> tag indicates terms that our tool shall handle as\n  atomic constants, an never look into them.\n\n  The special form \\<open>UNPROTECT\\<close> can be used inside pattern rewrite rules.\n  It has the effect to revert the protection from its argument, and then wrap\n  it into a \\<open>PR_CONST\\<close>.\n\\<close>\ndefinition [simp, autoref_tag_defs]: \"PR_CONST x \\<equiv> x\" \\<comment> \\<open>Tag to protect constant\\<close>\ndefinition [simp, autoref_tag_defs]: \"UNPROTECT x \\<equiv> x\" \\<comment> \\<open>Gets \n  converted to @{term PR_CONST}, after unprotecting its content\\<close>\n\n\nsubsection \\<open>Operation Identification\\<close>\n\ntext \\<open> Indicator predicate for conceptual typing of a constant \\<close>\ndefinition intf_type :: \"'a \\<Rightarrow> 'b itself \\<Rightarrow> bool\" (infix \"::\\<^sub>i\" 10) where\n  [simp]: \"c::\\<^sub>iI \\<equiv> True\"\n\nlemma itypeI: \"c::\\<^sub>iI\" by simp\nlemma itypeI': \"intf_type c TYPE('T)\" by (rule itypeI)\n\nlemma itype_self: \"(c::'a) ::\\<^sub>i TYPE('a)\" by simp\n\ndefinition CTYPE_ANNOT :: \"'b \\<Rightarrow> 'a itself \\<Rightarrow> 'b\" (infix \":::\\<^sub>i\" 10) where\n  [simp]: \"c:::\\<^sub>iI \\<equiv> c\"\n\ntext \\<open> Wrapper predicate for an conceptual type inference \\<close>\ndefinition ID :: \"'a \\<Rightarrow> 'a \\<Rightarrow> 'c itself \\<Rightarrow> bool\" \n  where [simp]: \"ID t t' T \\<equiv> t=t'\"\n\nsubsubsection \\<open>Conceptual Typing Rules\\<close>\n\nlemma ID_unfold_vars: \"ID x y T \\<Longrightarrow> x\\<equiv>y\" by simp\nlemma ID_PR_CONST_trigger: \"ID (PR_CONST x) y T \\<Longrightarrow> ID (PR_CONST x) y T\" .\n\nlemma pat_rule:\n  \"\\<lbrakk> p\\<equiv>p'; ID p' t' T \\<rbrakk> \\<Longrightarrow> ID p t' T\" by simp\n\nlemma app_rule:\n  \"\\<lbrakk> ID f f' TYPE('a\\<Rightarrow>'b); ID x x' TYPE('a)\\<rbrakk> \\<Longrightarrow> ID (f$x) (f'$x') TYPE('b)\"\n  by simp\n\nlemma app'_rule:\n  \"\\<lbrakk> ID f f' TYPE('a\\<Rightarrow>'b); ID x x' TYPE('a)\\<rbrakk> \\<Longrightarrow> ID (f$'x) (f'$x') TYPE('b)\"\n  by simp\n\nlemma abs_rule:\n  \"\\<lbrakk> \\<And>x x'. ID x x' TYPE('a) \\<Longrightarrow> ID (t x) (t' x x') TYPE('b) \\<rbrakk> \\<Longrightarrow>\n    ID (\\<lambda>\\<^sub>2x. t x) (\\<lambda>\\<^sub>2x'. t' x' x') TYPE('a\\<Rightarrow>'b)\"\n  by simp\n\nlemma id_rule: \"c::\\<^sub>iI \\<Longrightarrow> ID c c I\" by simp\n\nlemma annot_rule: \"ID t t' I \\<Longrightarrow> ID (t:::\\<^sub>iI) t' I\"\n  by simp\n\nlemma fallback_rule:\n  \"ID (c::'a) c TYPE('c)\"\n  by simp\n\nlemma unprotect_rl1: \"ID (PR_CONST x) t T \\<Longrightarrow> ID (UNPROTECT x) t T\"\n  by simp\n\nsubsection \\<open> ML-Level code \\<close>\nML \\<open>\ninfix 0 THEN_ELSE_COMB'\n\nsignature ID_OP_TACTICAL = sig\n  val SOLVE_FWD: tactic' -> tactic'\n  val DF_SOLVE_FWD: bool -> tactic' -> tactic'\nend\n\nstructure Id_Op_Tactical :ID_OP_TACTICAL = struct\n\n  fun SOLVE_FWD tac i st = SOLVED' (\n    tac \n    THEN_ALL_NEW_FWD (SOLVE_FWD tac)) i st\n\n\n  (* Search for solution with DFS-strategy. If dbg-flag is given,\n    return sequence of stuck states if no solution is found.\n  *)\n  fun DF_SOLVE_FWD dbg tac = let\n    val stuck_list_ref = Unsynchronized.ref []\n\n    fun stuck_tac _ st = if dbg then (\n      stuck_list_ref := st :: !stuck_list_ref;\n      Seq.empty\n    ) else Seq.empty\n\n    fun rec_tac i st = (\n        (tac THEN_ALL_NEW_FWD (SOLVED' rec_tac))\n        ORELSE' stuck_tac\n      ) i st\n\n    fun fail_tac _ _ = if dbg then\n      Seq.of_list (rev (!stuck_list_ref))\n    else Seq.empty\n  in\n    rec_tac ORELSE' fail_tac    \n  end\n\nend\n\\<close>\n\n\nnamed_theorems_rev id_rules \"Operation identification rules\"\nnamed_theorems_rev pat_rules \"Operation pattern rules\"\nnamed_theorems_rev def_pat_rules \"Definite operation pattern rules (not backtracked over)\"\n\n\n\nML \\<open>\n\n  structure Id_Op = struct\n\n    fun id_a_conv cnv ct = case Thm.term_of ct of\n      @{mpat \"ID _ _ _\"} => Conv.fun_conv (Conv.fun_conv (Conv.arg_conv cnv)) ct\n    | _ => raise CTERM(\"id_a_conv\",[ct])\n\n    fun \n      protect env (@{mpat \"?t:::\\<^sub>i?I\"}) = let\n        val t = protect env t\n      in \n        @{mk_term env: \"?t:::\\<^sub>i?I\"}\n      end\n    | protect _ (t as @{mpat \"PR_CONST _\"}) = t\n    | protect env (t1$t2) = let\n        val t1 = protect env t1\n        val t2 = protect env t2\n      in\n        @{mk_term env: \"?t1.0 $ ?t2.0\"}\n      end\n    | protect env (Abs (x,T,t)) = let\n        val t = protect (T::env) t\n      in\n        @{mk_term env: \"\\<lambda>v_x::?'v_T. PROTECT2 ?t DUMMY\"}\n      end\n    | protect _ t = t\n\n    fun protect_conv ctxt = Refine_Util.f_tac_conv ctxt\n      (protect []) \n      (simp_tac \n        (put_simpset HOL_basic_ss ctxt addsimps @{thms PROTECT2_def APP_def}) 1)\n\n    fun unprotect_conv ctxt\n      = Simplifier.rewrite (put_simpset HOL_basic_ss ctxt \n        addsimps @{thms PROTECT2_def APP_def})\n\n    fun do_unprotect_tac ctxt =\n      resolve_tac ctxt @{thms unprotect_rl1} THEN'\n      CONVERSION (Refine_Util.HOL_concl_conv (fn ctxt => id_a_conv (unprotect_conv ctxt)) ctxt)\n\n    val cfg_id_debug = \n      Attrib.setup_config_bool @{binding id_debug} (K false)\n\n    val cfg_id_trace_fallback = \n      Attrib.setup_config_bool @{binding id_trace_fallback} (K false)\n\n    fun dest_id_rl thm = case Thm.concl_of thm of\n      @{mpat (typs) \"Trueprop (?c::\\<^sub>iTYPE(?'v_T))\"} => (c,T)\n    | _ => raise THM(\"dest_id_rl\",~1,[thm])\n\n    \n    val add_id_rule = snd oo Thm.proof_attributes [Named_Theorems_Rev.add @{named_theorems_rev id_rules}]\n\n    datatype id_tac_mode = Init | Step | Normal | Solve\n\n    fun id_tac ss ctxt = let\n      open Id_Op_Tactical\n      val certT = Thm.ctyp_of ctxt\n      val cert = Thm.cterm_of ctxt\n\n      val thy = Proof_Context.theory_of ctxt\n\n      val id_rules = Named_Theorems_Rev.get ctxt @{named_theorems_rev id_rules}\n      val pat_rules = Named_Theorems_Rev.get ctxt @{named_theorems_rev pat_rules}\n      val def_pat_rules = Named_Theorems_Rev.get ctxt @{named_theorems_rev def_pat_rules}\n\n      val rl_net = Tactic.build_net (\n        (pat_rules |> map (fn thm => thm RS @{thm pat_rule})) \n        @ @{thms annot_rule app_rule app'_rule abs_rule} \n        @ (id_rules |> map (fn thm => thm RS @{thm id_rule}))\n      )\n\n      val def_rl_net = Tactic.build_net (\n        (def_pat_rules |> map (fn thm => thm RS @{thm pat_rule}))\n      )  \n\n      val id_pr_const_rename_tac = \n          resolve_tac ctxt @{thms ID_PR_CONST_trigger} THEN'\n          Subgoal.FOCUS (fn { context=ctxt, prems, ... } => \n            let\n              fun is_ID @{mpat \"Trueprop (ID _ _ _)\"} = true | is_ID _ = false\n              val prems = filter (Thm.prop_of #> is_ID) prems\n              val eqs = map (fn thm => thm RS @{thm ID_unfold_vars}) prems\n              val conv = Conv.rewrs_conv eqs\n              val conv = fn ctxt => (Conv.top_sweep_conv (K conv) ctxt)\n              val conv = fn ctxt => Conv.fun2_conv (Conv.arg_conv (conv ctxt))\n              val conv = Refine_Util.HOL_concl_conv conv ctxt\n            in CONVERSION conv 1 end \n          ) ctxt THEN'\n          resolve_tac ctxt @{thms id_rule} THEN'\n          resolve_tac ctxt id_rules \n\n      val ityping = id_rules \n        |> map dest_id_rl\n        |> filter (is_Const o #1)\n        |> map (apfst (#1 o dest_Const))\n        |> Symtab.make_list\n\n      val has_type = Symtab.defined ityping\n\n      fun mk_fallback name cT =\n        case try (Sign.the_const_constraint thy) name of\n          SOME T => try (Thm.instantiate' \n                          [SOME (certT cT), SOME (certT T)] [SOME (cert (Const (name,cT)))])\n                        @{thm fallback_rule} \n        | NONE => NONE\n\n      fun trace_fallback thm = \n        Config.get ctxt cfg_id_trace_fallback       \n        andalso let \n          open Pretty\n          val p = block [str \"ID_OP: Applying fallback rule: \", Thm.pretty_thm ctxt thm]\n        in \n          string_of p |> tracing; \n          false\n        end  \n\n      val fallback_tac = CONVERSION Thm.eta_conversion THEN' IF_EXGOAL (fn i => fn st =>\n        case Logic.concl_of_goal (Thm.prop_of st) i of\n          @{mpat \"Trueprop (ID (mpaq_STRUCT (mpaq_Const ?name ?cT)) _ _)\"} => (\n            if not (has_type name) then \n              case mk_fallback name cT of\n                SOME thm => (trace_fallback thm; resolve_tac ctxt [thm] i st)\n              | NONE => Seq.empty  \n            else Seq.empty\n          )\n        | _ => Seq.empty)\n\n      val init_tac = CONVERSION (\n        Refine_Util.HOL_concl_conv (fn ctxt => (id_a_conv (protect_conv ctxt))) \n          ctxt\n      )\n\n      val step_tac = (FIRST' [\n        assume_tac ctxt, \n        eresolve_tac ctxt @{thms id_rule},\n        resolve_from_net_tac ctxt def_rl_net, \n        resolve_from_net_tac ctxt rl_net, \n        id_pr_const_rename_tac,\n        do_unprotect_tac ctxt, \n        fallback_tac])\n\n      val solve_tac = DF_SOLVE_FWD (Config.get ctxt cfg_id_debug) step_tac  \n\n    in\n      case ss of\n        Init => init_tac \n      | Step => step_tac \n      | Normal => init_tac THEN' solve_tac\n      | Solve => solve_tac\n\n    end\n\n  end\n\n\\<close>\n\nsubsection \\<open>Default Setup\\<close>\n\nsubsubsection \\<open>Numerals\\<close> \nlemma pat_numeral[def_pat_rules]: \"numeral$x \\<equiv> UNPROTECT (numeral$x)\" by simp\n\nlemma id_nat_const[id_rules]: \"(PR_CONST (a::nat)) ::\\<^sub>i TYPE(nat)\" by simp\nlemma id_int_const[id_rules]: \"(PR_CONST (a::int)) ::\\<^sub>i TYPE(int)\" by simp\n\n(*subsection \\<open>Example\\<close>\nschematic_lemma \n  \"ID (\\<lambda>a b. (b(1::int\\<mapsto>2::nat) |`(-{3})) a, Map.empty, \\<lambda>a. case a of None \\<Rightarrow> Some a | Some _ \\<Rightarrow> None) (?c) (?T::?'d itself)\"\n  (*\"TERM (?c,?T)\"*)\n  using [[id_debug]]\n  apply (tactic {* Id_Op.id_tac Id_Op.Normal @{context} 1  *})  \n  done\n*)\n\nend\n\n", "meta": {"author": "maxhaslbeck", "repo": "Sepreftime", "sha": "c1c987b45ec886d289ba215768182ac87b82f20d", "save_path": "github-repos/isabelle/maxhaslbeck-Sepreftime", "path": "github-repos/isabelle/maxhaslbeck-Sepreftime/Sepreftime-c1c987b45ec886d289ba215768182ac87b82f20d/Refine_Imperative_HOL/Sepref_Id_Op.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.2923814378995846}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |               November 2004               |\n            |                   July 2005  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |                October 2005  (modified)   |\n            |                  April 2006  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2009         |\n            |                   June 2009  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2016         |\n            |                    May 2016  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory Trace_par\nimports Prefix\nbegin\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite (notick | t = <>)                  *)\n(*                                                                     *)\n(*                  disj_not1: (~ P | Q) = (P --> Q)                   *)\n\ndeclare disj_not1 [simp del]\n\n(*****************************************************************\n\n         1. s |[X]|list t  : lists  --> list set\n         2. s |[X]|tr t   : traces --> trace set\n         3. \n         4. \n\n *****************************************************************)\n\n(* Isabelle 2005\nconsts\n  parx :: \"'a set => ('a trace * 'a trace * 'a trace) set\"\n\ninductive \"parx X\"\nintros\nparx_nil_nil: \n  \"(<>, <>, <>) : parx X\"\n\nparx_Tick_Tick: \n  \"(<Tick>, <Tick>, <Tick>) : parx X\"\n\nparx_Ev_nil: \n  \"[| (u, s, <>) : parx X ; a ~: X |]\n   ==> (<Ev a> ^^^ u, <Ev a> ^^^ s, <>) : parx X\"\n\nparx_nil_Ev: \n  \"[| (u, <>, t) : parx X ; a ~: X |]\n   ==> (<Ev a> ^^^ u, <>, <Ev a> ^^^ t) : parx X\"\n\nparx_Ev_sync: \n  \"[| (u, s, t) : parx X ; a : X |]\n   ==> (<Ev a> ^^^ u, <Ev a> ^^^ s, <Ev a> ^^^ t) : parx X\"\n\nparx_Ev_left: \n  \"[| (u, s, t) : parx X ; a ~: X |]\n   ==> (<Ev a> ^^^ u, <Ev a> ^^^ s, t) : parx X\"\n\nparx_Ev_right: \n  \"[| (u, s, t) : parx X ; a ~: X |]\n   ==> (<Ev a> ^^^ u, s, <Ev a> ^^^ t) : parx X\"\n*)\n\n\ninductive_set\n  parx :: \"'a set => ('a trace * 'a trace * 'a trace) set\"\n  for X :: \"'a set\"\n\nwhere\nparx_nil_nil: \n  \"(<>, <>, <>) : parx X\" |\n\nparx_Tick_Tick: \n  \"(<Tick>, <Tick>, <Tick>) : parx X\" |\n\nparx_Ev_nil: \n  \"[| (u, s, <>) : parx X ; a ~: X |]\n   ==> (<Ev a> ^^^ u, <Ev a> ^^^ s, <>) : parx X\" |\n\nparx_nil_Ev: \n  \"[| (u, <>, t) : parx X ; a ~: X |]\n   ==> (<Ev a> ^^^ u, <>, <Ev a> ^^^ t) : parx X\" |\n\nparx_Ev_sync: \n  \"[| (u, s, t) : parx X ; a : X |]\n   ==> (<Ev a> ^^^ u, <Ev a> ^^^ s, <Ev a> ^^^ t) : parx X\" |\n\nparx_Ev_left: \n  \"[| (u, s, t) : parx X ; a ~: X |]\n   ==> (<Ev a> ^^^ u, <Ev a> ^^^ s, t) : parx X\" |\n\nparx_Ev_right: \n  \"[| (u, s, t) : parx X ; a ~: X |]\n   ==> (<Ev a> ^^^ u, s, <Ev a> ^^^ t) : parx X\"\n\ndefinition\n  par_tr :: \"'a trace => 'a set => 'a trace => 'a trace set\"\n                                        (\"(_ |[_]|tr _)\" [76,0,77] 76)\n where\n  par_tr_def : \"s |[X]|tr t == {u. (u, s, t) : parx X}\"\n\nlemma par_tr_defE: \"[| u : s |[X]|tr t ; (u, s, t) : parx X ==> R |] ==> R\"\nby (simp add: par_tr_def)\n\n(*************************************************************\n                 par_tr intros and elims\n *************************************************************)\n\n(*-------------------*\n |      intros       |\n *-------------------*)\n\nlemma par_tr_nil_nil: \n  \"<> : <> |[X]|tr <>\"\napply (simp add: par_tr_def)\nby (simp add: parx.intros)\n\nlemma par_tr_Tick_Tick: \n  \"<Tick> : <Tick> |[X]|tr <Tick>\"\napply (simp add: par_tr_def)\nby (simp add: parx.intros)\n\nlemma par_tr_Ev_nil: \n  \"[| u : s |[X]|tr <> ; a ~: X |]\n   ==> <Ev a> ^^^ u : (<Ev a> ^^^ s) |[X]|tr <>\"\napply (simp add: par_tr_def)\nby (simp add: parx.intros)\n\nlemma par_tr_nil_Ev: \n  \"[| u : <> |[X]|tr t ; a ~: X |]\n   ==> <Ev a> ^^^ u : <> |[X]|tr (<Ev a> ^^^ t)\"\napply (simp add: par_tr_def)\nby (simp add: parx.intros)\n\nlemma par_tr_Ev_sync: \n  \"[| u : s |[X]|tr t ; a : X |]\n   ==> <Ev a> ^^^ u : (<Ev a> ^^^ s) |[X]|tr (<Ev a> ^^^ t)\"\napply (simp add: par_tr_def)\nby (simp add: parx.intros)\n\nlemma par_tr_Ev_left: \n  \"[| u : s |[X]|tr t ; a ~: X |]\n   ==> <Ev a> ^^^ u : (<Ev a> ^^^ s) |[X]|tr t\"\napply (simp add: par_tr_def)\nby (simp add: parx.intros)\n\nlemma par_tr_Ev_right: \n  \"[| u : s |[X]|tr t ; a ~: X |]\n   ==> <Ev a> ^^^ u : s |[X]|tr (<Ev a> ^^^ t)\"\napply (simp add: par_tr_def)\nby (simp add: parx.intros)\n\n(*** intro rule ***)\n\nlemmas par_tr_intros =\n       par_tr_nil_nil\n       par_tr_Tick_Tick\n       par_tr_Ev_nil\n       par_tr_nil_Ev\n       par_tr_Ev_sync\n       par_tr_Ev_left\n       par_tr_Ev_right\n\n(*-------------------*\n |       elims       |\n *-------------------*)\n\nlemma par_tr_elims_lm:\n \"[| u : s |[X]|tr t ;\n     (u = <> & s = <> & t = <>) --> P ;\n     (u = <Tick> & s = <Tick> & t = <Tick>) --> P ;\n     ALL a s' u'.\n        (u = <Ev a> ^^^ u' & s = <Ev a> ^^^ s' & t = <> &\n           u' : s' |[X]|tr <> & a ~: X)\n        --> P;\n     ALL a t' u'.\n        (u = <Ev a> ^^^ u' & s = <> & t = <Ev a> ^^^ t' & \n           u' : <> |[X]|tr t' & a ~: X)\n        --> P;\n     ALL a s' t' u'.\n        (u = <Ev a> ^^^ u' & s = <Ev a> ^^^ s' & t = <Ev a> ^^^ t' &\n           u' : s' |[X]|tr t' & a : X)\n        --> P;\n     ALL a s' u'.\n        (u = <Ev a> ^^^ u' & s = <Ev a> ^^^ s' &\n           u' : s' |[X]|tr t & a ~: X)\n        --> P;\n     ALL a t' u'.\n        (u = <Ev a> ^^^ u' & t = <Ev a> ^^^ t' & \n           u' : s |[X]|tr t' & a ~: X)\n        --> P |]\n  ==> P\"\napply (simp add: par_tr_def)\napply (erule parx.cases)      (* .elims --> .cases *)\napply (simp_all)\ndone\n\n(*** elim rule ***)\n\nlemma par_tr_elims:\n \"[| u : s |[X]|tr t ;\n     [| u = <>; s = <>; t = <> |] ==> P ;\n     [| u = <Tick>; s = <Tick>; t = <Tick> |] ==> P ;\n     !!a s' u'.\n        [| u = <Ev a> ^^^ u'; s = <Ev a> ^^^ s'; t = <> ; \n           u' : s' |[X]|tr <>; a ~: X |]\n        ==> P;\n     !!a t' u'.\n        [| u = <Ev a> ^^^ u' ; s = <> ; t = <Ev a> ^^^ t' ; \n           u' : <> |[X]|tr t'; a ~: X |]\n        ==> P;\n     !!a s' t' u'.\n        [| u = <Ev a> ^^^ u' ; s = <Ev a> ^^^ s' ; t = <Ev a> ^^^ t' ;\n           u' : s' |[X]|tr t'; a : X |]\n        ==> P;\n     !!a s' u'.\n        [| u = <Ev a> ^^^ u' ; s = <Ev a> ^^^ s' ; \n           u' : s' |[X]|tr t; a ~: X |]\n        ==> P;\n     !!a t' u'.\n        [| u = <Ev a> ^^^ u' ; t = <Ev a> ^^^ t' ; \n           u' : s |[X]|tr t'; a ~: X |]\n        ==> P |]\n  ==> P\"\napply (rule par_tr_elims_lm[of u s X t])\napply (simp_all)\n(* for Isabelle 2013\napply (fast)\napply (fast)\napply (fast)    (* this takes 1 min *)\napply (fast)    (* this takes 1 min *)\napply (fast)    (* this takes 1 min *)\n*)\ndone\n\n(*************************************************************\n                 par_tr decomposition\n *************************************************************)\n\n(*-------------------*\n |     par nil       |\n *-------------------*)\n\n(*** par_tr ***)\n\nlemma par_tr_nil_only_if:\n  \"<> : s |[X]|tr t ==> s = <> & t = <>\"\napply (erule par_tr_elims)\nby (simp_all)\n\n(*** iff ***)\n\nlemma par_tr_nil1[simp]:\n  \"(<> : s |[X]|tr t) = (s = <> & t = <>)\"\napply (rule iffI)\napply (simp add: par_tr_nil_only_if)\nby (simp add: par_tr_intros)\n\nlemma par_tr_nil2[simp]:\n  \"(u : <> |[X]|tr <>) = (u = <>)\"\napply (rule iffI)\napply (erule par_tr_elims)\nby (simp_all)\n\n(*-------------------*\n |     par Tick      |\n *-------------------*)\n\n(*** only if ***)\n\nlemma par_tr_Tick_only_if:\n  \"<Tick> : s |[X]|tr t ==> s = <Tick> & t = <Tick>\"\napply (erule par_tr_elims)\nby (simp_all)\n\n(*** iff ***)\n\nlemma par_tr_Tick1[simp]:\n  \"<Tick> : s |[X]|tr t = (s = <Tick> & t = <Tick>)\"\napply (rule iffI)\napply (simp add: par_tr_Tick_only_if)\nby (simp add: par_tr_intros)\n\nlemma par_tr_Tick2[simp]:\n  \"(u : <Tick> |[X]|tr <Tick>) = (u = <Tick>)\"\napply (rule iffI)\napply (erule par_tr_elims)\nby (simp_all)\n\n(*-----------------*\n |     par Ev      |\n *-----------------*)\n\n(*** only if ***)\n\nlemma par_tr_Ev_only_if:\n \"<Ev a> : s |[X]|tr t\n   ==> ((a  : X & s = <Ev a> & t = <Ev a>) |\n        (a ~: X & s = <Ev a> & t = <>) |\n        (a ~: X & s = <>     & t = <Ev a> ))\"\napply (erule par_tr_elims)\nby (simp_all)\n\n(*** if ***)\n\nlemma par_tr_Ev_if:\n \"((a  : X & s = <Ev a> & t = <Ev a>) |\n   (a ~: X & s = <Ev a> & t = <>) |\n   (a ~: X & s = <>     & t = <Ev a> ))\n   ==> <Ev a> : s |[X]|tr t\"\napply (erule disjE)\napply (insert par_tr_Ev_sync[of \"<>\" \"<>\" X \"<>\" a], simp)\napply (erule disjE)\napply (insert par_tr_Ev_left[of \"<>\" \"<>\" X \"<>\" a], simp)\napply (insert par_tr_Ev_right[of \"<>\" \"<>\" X \"<>\" a], simp)\ndone\n\nlemma par_tr_Ev:\n \"<Ev a> : s |[X]|tr t\n   = ((a  : X & s = <Ev a> & t = <Ev a>) |\n      (a ~: X & s = <Ev a> & t = <>) |\n      (a ~: X & s = <>     & t = <Ev a> ))\"\napply (rule iffI)\napply (simp add: par_tr_Ev_only_if)\napply (simp add: par_tr_Ev_if)\ndone\n\n(*--------------------------------------------*\n |                 par one                    |\n *--------------------------------------------*)\n\nlemma par_tr_one:\n \"<e> : s |[X]|tr t\n   = ((e = Tick & s = <Tick> & t = <Tick>) |\n     (EX a. e = Ev a &\n       ((a  : X & s = <Ev a> & t = <Ev a>) |\n        (a ~: X & s = <Ev a> & t = <>) |\n        (a ~: X & s = <>     & t = <Ev a> ))))\"\napply (insert event_Tick_or_Ev)\napply (drule_tac x=\"e\" in spec)\napply (erule disjE)\napply (simp)\n\napply (erule exE)\napply (simp add: par_tr_Ev)\ndone\n\n(*--------------------------------------------*\n |                par head                    |\n *--------------------------------------------*)\n\n(*** only if ***)\n\nlemma par_tr_head_only_if:\n \"<Ev a> ^^^ u : s |[X]|tr t\n   ==> (a  : X & (EX s' t'. u : s' |[X]|tr t'\n               & s = <Ev a> ^^^ s' & t = <Ev a> ^^^ t')) |\n       (a ~: X & (EX s'.    u : s' |[X]|tr t & s = <Ev a> ^^^ s')) |\n       (a ~: X & (EX t'.    u : s |[X]|tr t' & t = <Ev a> ^^^ t'))\"\napply (erule par_tr_elims)\nby (simp_all)\n\n(*** if ***)\n\nlemma par_tr_head_if:\n \"(a  : X & (EX s' t'. u : s' |[X]|tr t'\n               & s = <Ev a> ^^^ s' & t = <Ev a> ^^^ t')) |\n       (a ~: X & (EX s'.    u : s' |[X]|tr t & s = <Ev a> ^^^ s')) |\n       (a ~: X & (EX t'.    u : s |[X]|tr t' & t = <Ev a> ^^^ t'))\n  ==> <Ev a> ^^^ u : s |[X]|tr t\"\n\n (*** sync ***)\n apply (erule disjE)\n apply (elim conjE exE)\n apply (simp add: par_tr_intros)\n\n (*** left ***)\n apply (erule disjE)\n apply (elim conjE exE)\n apply (simp add: par_tr_intros)\n\n (*** right ***)\n apply (elim conjE exE)\n apply (simp add: par_tr_intros)\ndone\n\n(*** iff ***)\n\nlemma par_tr_head:\n \"<Ev a> ^^^ u : s |[X]|tr t\n   = ((a  : X & (EX s' t'. u : s' |[X]|tr t'\n              & s = <Ev a> ^^^ s' & t = <Ev a> ^^^ t')) |\n      (a ~: X & (EX s'.    u : s' |[X]|tr t & s = <Ev a> ^^^ s')) |\n      (a ~: X & (EX t'.    u : s |[X]|tr t' & t = <Ev a> ^^^ t')))\"\napply (rule iffI)\napply (simp add: par_tr_head_only_if)\napply (simp add: par_tr_head_if)\ndone\n\n(* erule *)\n\nlemma par_tr_head_ifE:\n \"[| <Ev a> ^^^ u : s |[X]|tr t ;\n     [| (a  : X & (EX s' t'. u : s' |[X]|tr t'\n                & s = <Ev a> ^^^ s' & t = <Ev a> ^^^ t')) |\n        (a ~: X & (EX s'.    u : s' |[X]|tr t & s = <Ev a> ^^^ s')) |\n        (a ~: X & (EX t'.    u : s |[X]|tr t' & t = <Ev a> ^^^ t')) |] ==> R\n  |] ==> R\"\nby (simp add: par_tr_head)\n\n(* head Ev Ev *)\n\nlemma par_tr_head_Ev_Ev:\n   \"(u : (<Ev a> ^^^ s) |[X]|tr (<Ev b> ^^^ t))\n    = (EX c v. u = <Ev c> ^^^ v &\n               (c : X & v : s |[X]|tr t & a = c & b = c |\n                c ~: X & v : s |[X]|tr (<Ev b> ^^^ t) & a = c |\n                c ~: X & v : (<Ev a> ^^^ s) |[X]|tr t & b = c))\"\napply (rule iffI)\n\n (* => *)\n apply (insert trace_nil_or_Tick_or_Ev)\n apply (drule_tac x=\"u\" in spec)\n apply (elim disjE conjE exE)\n apply (simp_all)\n apply (simp add: par_tr_head)\n\n (* => *)\n apply (elim conjE exE)\n apply (simp add: par_tr_head)\ndone\n\n(* step *)\n\nlemma par_tr_step:\n   \"(u : s |[X]|tr t)\n    = ((u = <> & s = <> & t = <>) |\n       (u = <Tick> & s = <Tick> & t = <Tick>) |\n       (EX a v. u = <Ev a> ^^^ v & \n        ((a  : X & (EX s' t'. v : s' |[X]|tr t'\n              & s = <Ev a> ^^^ s' & t = <Ev a> ^^^ t')) |\n         (a ~: X & (EX s'.    v : s' |[X]|tr t & s = <Ev a> ^^^ s')) |\n         (a ~: X & (EX t'.    v : s |[X]|tr t' & t = <Ev a> ^^^ t')))))\"\napply (insert trace_nil_or_Tick_or_Ev)\napply (drule_tac x=\"u\" in spec)\napply (elim disjE)\napply (simp_all)\napply (elim exE)\napply (simp add: par_tr_head)\ndone\n\nlemma par_tr_stepI:\n   \"((u = <> & s = <> & t = <>) |\n       (u = <Tick> & s = <Tick> & t = <Tick>) |\n       (EX a v. u = <Ev a> ^^^ v & \n        ((a  : X & (EX s' t'. v : s' |[X]|tr t'\n              & s = <Ev a> ^^^ s' & t = <Ev a> ^^^ t')) |\n         (a ~: X & (EX s'.    v : s' |[X]|tr t & s = <Ev a> ^^^ s')) |\n         (a ~: X & (EX t'.    v : s |[X]|tr t' & t = <Ev a> ^^^ t')))))\n     ==> (u : s |[X]|tr t)\"\nby (simp add: par_tr_step[THEN sym])\n\nlemma par_tr_stepE:\n   \"[| u : s |[X]|tr t ;\n      ((u = <> & s = <> & t = <>) |\n       (u = <Tick> & s = <Tick> & t = <Tick>) |\n       (EX a v. u = <Ev a> ^^^ v & \n        ((a  : X & (EX s' t'. v : s' |[X]|tr t'\n              & s = <Ev a> ^^^ s' & t = <Ev a> ^^^ t')) |\n         (a ~: X & (EX s'.    v : s' |[X]|tr t & s = <Ev a> ^^^ s')) |\n         (a ~: X & (EX t'.    v : s |[X]|tr t' & t = <Ev a> ^^^ t')))))\n     ==> R |] ==> R\"\nby (simp add: par_tr_step[THEN sym])\n\n(*--------------------------------------------*\n |                par last                    |\n *--------------------------------------------*)\n\n(*** only if ***)\n\nlemma par_tr_last_only_if_lm:\n \"ALL X u s t e.\n    (u ^^^ <e> : s |[X]|tr t & noTick u)\n   --> (((e  : Ev ` X | e = Tick) &\n            (EX s' t'. u : s' |[X]|tr t' & s = s' ^^^ <e> & t = t' ^^^ <e>\n                       & noTick s' & noTick t')) |\n        (e ~: Ev ` X & e ~= Tick & \n            (EX s'.    u : s' |[X]|tr t & s = s' ^^^ <e> & noTick s' & noTick t)) |\n        (e ~: Ev ` X & e ~= Tick & \n            (EX t'.    u : s |[X]|tr t' & t = t' ^^^ <e> & noTick s & noTick t')))\" \napply (rule allI)\napply (rule allI)\napply (induct_tac u rule: induct_trace)\n\n(* base *)\n (* <> *)\n apply (intro allI impI)\n apply (simp add: par_tr_one)\n apply (erule disjE, simp)\n apply (erule exE, force)\n\n (* <Tick> *)\n apply (simp)\n\n (* <Ev a> ^^^ ua *)\n apply (intro allI impI)\n apply (elim conjE)\n apply (simp add: appt_assoc)\n apply (simp add: par_tr_head)\n apply (elim disjE conjE exE)\n\n  (* head sync *)\n  apply (drule_tac x=\"s'\" in spec)\n  apply (drule_tac x=\"t'\" in spec)\n  apply (drule_tac x=\"e\" in spec)\n  apply (simp)\n\n   (* last sync *)\n   apply (erule disjE, simp)\n   apply (elim conjE exE)\n   apply (rule disjI1)\n   apply (rule_tac x=\"<Ev a> ^^^ s'a\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t'a\" in exI)\n   apply (simp add: appt_assoc)\n\n   (* last left *)\n   apply (erule disjE, simp)\n   apply (elim conjE exE)\n   apply (rule disjI1)\n   apply (rule_tac x=\"<Ev a> ^^^ s'a\" in exI, simp)\n   apply (simp add: appt_assoc)\n\n   (* last right *)\n   apply (simp)\n   apply (elim conjE exE)\n   apply (rule disjI2)\n   apply (rule_tac x=\"<Ev a> ^^^ t'a\" in exI, simp)\n   apply (simp add: appt_assoc)\n\n  (* head left *)\n  apply (drule_tac x=\"s'\" in spec)\n  apply (drule_tac x=\"t\" in spec)\n  apply (drule_tac x=\"e\" in spec)\n  apply (simp)\n\n   (* last sync *)\n   apply (erule disjE, simp)\n   apply (elim conjE exE)\n   apply (rule disjI1)\n   apply (rule_tac x=\"<Ev a> ^^^ s'a\" in exI)\n   apply (rule_tac x=\"t'\" in exI)\n   apply (simp add: appt_assoc)\n\n   (* last left *)\n   apply (erule disjE, simp)\n   apply (elim conjE exE)\n   apply (rule disjI1)\n   apply (rule_tac x=\"<Ev a> ^^^ s'a\" in exI, simp)\n   apply (simp add: appt_assoc)\n\n   (* last right *)\n   apply (simp)\n   apply (elim conjE exE)\n   apply (rule disjI2)\n   apply (rule_tac x=\"t'\" in exI, simp)\n\n  (* head right *)\n  apply (drule_tac x=\"sa\" in spec)\n  apply (drule_tac x=\"t'\" in spec)\n  apply (drule_tac x=\"e\" in spec)\n  apply (simp)\n\n   (* last sync *)\n   apply (erule disjE, simp)\n   apply (elim conjE exE)\n   apply (rule disjI1)\n   apply (rule_tac x=\"s'\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t'a\" in exI)\n   apply (simp add: appt_assoc)\n\n   (* last left *)\n   apply (erule disjE, simp)\n   apply (elim conjE exE)\n   apply (rule disjI1)\n   apply (rule_tac x=\"s'\" in exI, simp)\n\n   (* last right *)\n   apply (simp)\n   apply (elim conjE exE)\n   apply (rule disjI2)\n   apply (rule_tac x=\"<Ev a> ^^^ t'a\" in exI)\n   apply (simp add: appt_assoc)\ndone\n\n(*** rule ***)\n\nlemma par_tr_last_only_if:\n \"[| u ^^^ <e> : s |[X]|tr t ; noTick u |]\n   ==> (((e  : Ev ` X | e = Tick) &\n            (EX s' t'. u : s' |[X]|tr t' & s = s' ^^^ <e> & t = t' ^^^ <e>\n                       & noTick s' & noTick t')) |\n        (e ~: Ev ` X & e ~= Tick & \n            (EX s'.    u : s' |[X]|tr t & s = s' ^^^ <e> & noTick s' & noTick t)) |\n        (e ~: Ev ` X & e ~= Tick & \n            (EX t'.    u : s |[X]|tr t' & t = t' ^^^ <e> & noTick s & noTick t')))\" \nby (simp add: par_tr_last_only_if_lm)\n\n(*** if ***)\n\nlemma par_tr_last_if_lm:\n \"ALL X u s t e. (noTick u &\n   (((e  : Ev ` X | e = Tick) &\n            (EX s' t'. u : s' |[X]|tr t' & s = s' ^^^ <e> & t = t' ^^^ <e>\n                       & noTick s' & noTick t')) |\n        (e ~: Ev ` X & e ~= Tick & \n            (EX s'.    u : s' |[X]|tr t & s = s' ^^^ <e> & noTick s' & noTick t)) |\n        (e ~: Ev ` X & e ~= Tick & \n            (EX t'.    u : s |[X]|tr t' & t = t' ^^^ <e>  & noTick s & noTick t'))))\n   --> u ^^^ <e> : s |[X]|tr t\"\napply (rule allI)\napply (rule allI)\napply (induct_tac u rule: induct_trace)\n\n(* base *)\n (* <> *)\n apply (intro allI impI)\n apply (simp add: par_tr_one)\n apply (elim conjE disjE)\n apply (force)\n apply (simp)\n apply (simp add: not_Tick_to_Ev, fast)\n apply (simp add: not_Tick_to_Ev, fast)\n\n (* <Tick> *)\n apply (simp)\n\n (* s ^^^ <e> *)\n apply (intro allI impI)\n apply (simp add: par_tr_head)\n apply (simp add: appt_assoc)\n apply (elim conjE)\n apply (elim disjE)\n\n  (* last sync *)\n  apply (elim conjE exE)\n\n   (* sync *)\n   apply (rotate_tac 3)\n   apply (erule disjE)\n   apply (elim conjE exE)\n   apply (simp add: appt_assoc)\n   apply (simp add: par_tr_head)\n   apply (drule_tac x=\"s'a ^^^ <e>\" in spec)\n   apply (drule_tac x=\"t'a ^^^ <e>\" in spec)\n   apply (drule_tac x=\"e\" in spec)\n   apply (simp)\n   apply (fast)\n\n   (* left *)\n   apply (rotate_tac -1)\n   apply (erule disjE)\n   apply (elim conjE exE)\n   apply (simp add: appt_assoc)\n   apply (simp add: par_tr_head)\n   apply (drule_tac x=\"s'a ^^^ <e>\" in spec)\n   apply (drule_tac x=\"t' ^^^ <e>\" in spec)\n   apply (drule_tac x=\"e\" in spec)\n   apply (simp)\n   apply (fast)\n\n   (* right *)\n   apply (elim conjE exE)\n   apply (simp add: appt_assoc)\n   apply (simp add: par_tr_head)\n   apply (drule_tac x=\"s' ^^^ <e>\" in spec)\n   apply (drule_tac x=\"t'a ^^^ <e>\" in spec)\n   apply (drule_tac x=\"e\" in spec)\n   apply (simp)\n   apply (fast)\n\n  (* last left *)\n  apply (elim conjE exE)\n\n   (* sync *)\n   apply (rotate_tac 4)\n   apply (erule disjE)\n   apply (elim conjE exE)\n   apply (simp add: appt_assoc)\n   apply (simp add: par_tr_head)\n   apply (drule_tac x=\"s'a ^^^ <e>\" in spec)\n   apply (drule_tac x=\"t'\" in spec)\n   apply (drule_tac x=\"e\" in spec)\n   apply (simp)\n   apply (fast)\n\n   (* left *)\n   apply (rotate_tac -1)\n   apply (erule disjE)\n   apply (elim conjE exE)\n   apply (simp add: appt_assoc)\n   apply (simp add: par_tr_head)\n   apply (drule_tac x=\"s'a ^^^ <e>\" in spec)\n   apply (drule_tac x=\"t\" in spec)\n   apply (drule_tac x=\"e\" in spec)\n   apply (simp)\n   apply (fast)\n\n   (* right *)\n   apply (elim conjE exE)\n   apply (simp add: appt_assoc)\n   apply (simp add: par_tr_head)\n   apply (drule_tac x=\"s' ^^^ <e>\" in spec)\n   apply (drule_tac x=\"t'\" in spec)\n   apply (drule_tac x=\"e\" in spec)\n   apply (simp)\n   apply (fast)\n\n  (* last right *)\n  apply (elim conjE exE)\n\n   (* sync *)\n   apply (rotate_tac 4)\n   apply (erule disjE)\n   apply (elim conjE exE)\n   apply (simp add: appt_assoc)\n   apply (simp add: par_tr_head)\n   apply (drule_tac x=\"s'\" in spec)\n   apply (drule_tac x=\"t'a ^^^ <e>\" in spec)\n   apply (drule_tac x=\"e\" in spec)\n   apply (simp)\n   apply (fast)\n\n   (* left *)\n   apply (rotate_tac -1)\n   apply (erule disjE)\n   apply (elim conjE exE)\n   apply (simp add: appt_assoc)\n   apply (simp add: par_tr_head)\n   apply (drule_tac x=\"s'\" in spec)\n   apply (drule_tac x=\"t' ^^^ <e>\" in spec)\n   apply (drule_tac x=\"e\" in spec)\n   apply (simp)\n   apply (fast)\n\n   (* right *)\n   apply (elim conjE exE)\n   apply (simp add: appt_assoc)\n   apply (simp add: par_tr_head)\n   apply (drule_tac x=\"sa\" in spec)\n   apply (drule_tac x=\"t'a ^^^ <e>\" in spec)\n   apply (drule_tac x=\"e\" in spec)\n   apply (simp)\n   apply (fast)\ndone\n\n(*** rule ***)\n\nlemma par_tr_last_if:\n \"[| noTick u;\n    ((e  : Ev ` X | e = Tick) &\n          (EX s' t'. u : s' |[X]|tr t' & s = s' ^^^ <e> & t = t' ^^^ <e>\n                      & noTick s' & noTick t')) |\n     (e ~: Ev ` X & e ~= Tick & \n          (EX s'.    u : s' |[X]|tr t & s = s' ^^^ <e> & noTick s' & noTick t)) |\n     (e ~: Ev ` X & e ~= Tick & \n          (EX t'.    u : s |[X]|tr t' & t = t' ^^^ <e> & noTick s & noTick t')) |]\n   ==> u ^^^ <e> : s |[X]|tr t\"\napply (insert par_tr_last_if_lm)\napply (drule_tac x=\"X\" in spec)\napply (drule_tac x=\"u\" in spec)\napply (drule_tac x=\"s\" in spec)\napply (drule_tac x=\"t\" in spec)\napply (drule_tac x=\"e\" in spec)\nby (simp)\n\n(*** iff ***)\n\nlemma par_tr_last:\n \"noTick u ==>\n   u ^^^ <e> : s |[X]|tr t \n   = (((e  : Ev ` X | e = Tick) &\n            (EX s' t'. u : s' |[X]|tr t' & s = s' ^^^ <e> & t = t' ^^^ <e>\n                       & noTick s' & noTick t')) |\n      (e ~: Ev ` X & e ~= Tick & \n            (EX s'.    u : s' |[X]|tr t & s = s' ^^^ <e> & noTick s' & noTick t)) |\n      (e ~: Ev ` X & e ~= Tick & \n            (EX t'.    u : s |[X]|tr t' & t = t' ^^^ <e> & noTick s & noTick t')))\" \napply (rule iffI)\napply (simp add: par_tr_last_only_if)\napply (simp add: par_tr_last_if)\ndone\n\n(*************************************************************\n                     symmetricity  \n *************************************************************)\n\nlemma par_tr_sym_only_if_lm:\n  \"ALL u s t. u : (s |[X]|tr t) --> u : (t |[X]|tr s)\"\napply (rule allI)\napply (induct_tac u rule: induct_trace)\napply (simp_all)\n\napply (intro allI impI)\napply (erule par_tr_elims)\n\n (* <> *)\n apply (simp)\n\n (* <Tick> *)\n apply (simp)\n\n (* Ev_nil *)\n apply (drule_tac x=\"s'\" in spec)\n apply (drule_tac x=\"<>\" in spec)\n apply (simp add: par_tr_intros)\n\n (* nil_Ev *)\n apply (drule_tac x=\"<>\" in spec)\n apply (drule_tac x=\"t'\" in spec)\n apply (simp add: par_tr_intros)\n\n (* sync *)\n apply (drule_tac x=\"s'\" in spec)\n apply (drule_tac x=\"t'\" in spec)\n apply (simp add: par_tr_intros)\n\n (* left *)\n apply (drule_tac x=\"s'\" in spec)\n apply (drule_tac x=\"t\" in spec)\n apply (simp add: par_tr_intros)\n\n (* right *)\n apply (drule_tac x=\"sa\" in spec)\n apply (drule_tac x=\"t'\" in spec)\n apply (simp add: par_tr_intros)\ndone\n\nlemma par_tr_sym_only_if:\n  \"u : (s |[X]|tr t) ==> u : (t |[X]|tr s)\"\napply (insert par_tr_sym_only_if_lm[of X])\napply (drule_tac x=\"u\" in spec)\napply (drule_tac x=\"s\" in spec)\napply (drule_tac x=\"t\" in spec)\napply (simp)\ndone\n\nlemma par_tr_sym: \"s |[X]|tr t = t |[X]|tr s\"\napply (auto)\napply (rule par_tr_sym_only_if, simp_all)\napply (rule par_tr_sym_only_if, simp_all)\ndone\n\n(*************************************************************\n                     prefix_closed\n *************************************************************)\n\nlemma par_tr_prefix_lm:\n \"ALL X v u s t. prefix v u & u : s |[X]|tr t\n     --> (EX s' t'. v : s' |[X]|tr t' & \n                    prefix s' s & prefix t' t)\"\napply (rule allI)\napply (rule allI)\napply (induct_tac v rule: induct_trace)\napply (simp_all add: disj_not1)\napply (simp add: prefix_Tick)\n\napply (intro allI impI)\napply (elim conjE exE)\napply (simp add: par_tr_head)\n\n (* sync *)\n apply (erule disjE)\n apply (elim conjE exE)\n apply (drule_tac x=\"u'\" in spec)\n apply (drule_tac x=\"s'\" in spec)\n apply (drule_tac x=\"t'\" in spec)\n apply (force)\n\n (* left *)\n apply (erule disjE)\n apply (elim conjE exE)\n apply (drule_tac x=\"u'\" in spec)\n apply (drule_tac x=\"s'\" in spec)\n apply (drule_tac x=\"t\" in spec)\n apply (force)\n\n (* right *)\n apply (elim conjE exE)\n apply (drule_tac x=\"u'\" in spec)\n apply (drule_tac x=\"sa\" in spec)\n apply (drule_tac x=\"t'\" in spec)\n apply (force)\ndone\n\n(*** rule ***)\n\nlemma par_tr_prefix:\n \"[| prefix v u ; u : s |[X]|tr t |]\n  ==> (EX s' t'. v : s' |[X]|tr t' & prefix s' s & prefix t' t)\"\napply (insert par_tr_prefix_lm)\napply (drule_tac x=\"X\" in spec)\napply (drule_tac x=\"v\" in spec)\napply (drule_tac x=\"u\" in spec)\napply (drule_tac x=\"s\" in spec)\napply (drule_tac x=\"t\" in spec)\nby (simp)\n\nlemma par_tr_prefixE:\n \"[| prefix v u ; u : s |[X]|tr t ;\n     !! s' t'. [| v : s' |[X]|tr t' ; prefix s' s ; prefix t' t |] ==> R\n  |] ==> R\"\napply (insert par_tr_prefix[of v u s X t])\nby (auto)\n\n(*************************************************************\n                  parallel lemmas etc.\n *************************************************************)\n\n(*******************************\n          par_tr lenght \n *******************************)\n\nlemma par_tr_lengtht_lm:\n \"ALL X u s t. u : s |[X]|tr t\n         --> lengtht s <= lengtht u & lengtht t <= lengtht u\"\napply (rule allI)\napply (rule allI)\napply (induct_tac u rule: induct_trace)\napply (simp_all)\n\napply (intro allI impI)\napply (simp add: par_tr_head)\n\n (* sync *)\n apply (erule disjE)\n apply (elim conjE exE)\n apply (drule_tac x=\"s'\" in spec)\n apply (drule_tac x=\"t'\" in spec)\n apply (simp)\n\n (* left *)\n apply (erule disjE)\n apply (elim conjE exE)\n apply (drule_tac x=\"s'\" in spec)\n apply (drule_tac x=\"t\" in spec)\n apply (force)\n\n (* right *)\n apply (elim conjE exE)\n apply (drule_tac x=\"sa\" in spec)\n apply (drule_tac x=\"t'\" in spec)\n apply (force)\ndone\n\n(*** rule ***)\n\nlemma par_tr_lengtht:\n \"u : s |[X]|tr t ==> lengtht s <= lengtht u & lengtht t <= lengtht u\"\nby (simp add: par_tr_lengtht_lm)\n\n(*** ruleE ***)\n\nlemma par_tr_lengthtE:\n \"[| u : s |[X]|tr t ; \n     [| lengtht s <= lengtht u ; lengtht t <= lengtht u|] ==> R |] ==> R\"\nby (simp add: par_tr_lengtht)\n\n(**************************************************\n                    para\n **************************************************)\n\nlemma par_tr_nil_Ev_rev:\n  \"u : <> |[X]|tr (<Ev a> ^^^ t)\n   ==> a ~: X & (EX v. u = <Ev a> ^^^ v & v : <> |[X]|tr t)\"\napply (erule par_tr_elims)\nby (simp_all add: par_tr_intros)\n\nlemma par_tr_Tick_Ev_rev:\n  \"u : <Tick> |[X]|tr (<Ev a> ^^^ t)\n   ==> a ~: X & (EX v. u = <Ev a> ^^^ v & v : <Tick> |[X]|tr t)\"\napply (erule par_tr_elims)\nby (simp_all add: par_tr_intros)\n\n(**************************************************\n                    noTick\n **************************************************)\n\n(*-----------------*\n |   par noTick    |\n *-----------------*)\n\n(*** only if ***)\n\nlemma par_tr_noTick_only_if_lm:\n \"ALL s t. ( u : s |[X]|tr t & noTick s & noTick t ) --> noTick u\"\napply (induct_tac u rule: induct_trace)\napply (simp)\napply (intro allI)\napply (case_tac \"s ~= <Tick>\", simp)\napply (case_tac \"t ~= <Tick>\", simp)\napply (simp)\n\napply (intro allI impI)\napply (elim conjE)\napply (simp add: par_tr_head)\napply (elim disjE conjE exE)\napply (auto)\ndone\n\nlemma par_tr_noTick_only_if:\n \"[| u : s |[X]|tr t ; noTick s ; noTick t |] ==> noTick u\"\napply (insert par_tr_noTick_only_if_lm[of u X])\napply (drule_tac x=\"s\" in spec)\napply (drule_tac x=\"t\" in spec)\nby (simp)\n\n(*** if ***)\n\nlemma par_tr_noTick_if_lm:\n \"ALL s t. ( u : s |[X]|tr t & noTick u ) --> ( noTick s & noTick t )\"\napply (induct_tac u rule: induct_trace)\napply (simp)\napply (simp)\n\napply (intro allI impI)\napply (elim conjE)\napply (erule par_tr_head_ifE)\napply (elim conjE exE disjE)\n\napply (drule_tac x=\"s'\" in spec)\napply (drule_tac x=\"t'\" in spec)\napply (simp)\n\napply (drule_tac x=\"s'\" in spec)\napply (drule_tac x=\"t\" in spec)\napply (simp)\n\napply (drule_tac x=\"sa\" in spec)\napply (drule_tac x=\"t'\" in spec)\napply (simp)\ndone\n\nlemma par_tr_noTick_if:\n \"[| u : s |[X]|tr t ; noTick u |] ==> ( noTick s & noTick t )\"\napply (insert par_tr_noTick_if_lm[of u X])\napply (drule_tac x=\"s\" in spec)\napply (drule_tac x=\"t\" in spec)\nby (simp)\n\n(*** iff ***)\n\nlemma par_tr_noTick:\n \"u : s |[X]|tr t ==> (noTick s & noTick t) = noTick u\"\napply (rule iffI)\napply (simp add: par_tr_noTick_only_if)\napply (simp add: par_tr_noTick_if)\ndone\n\nlemmas par_tr_noTick_compo = par_tr_noTick_only_if\nlemmas par_tr_noTick_decompo = par_tr_noTick_if\n\n(****** used in Alpha_parallel ******)\n\n(*** nil-Tick ***)\n\nlemma par_tr_nil_Tick[simp]:\n  \"(u : <> |[X]|tr <Tick>) = False\"\napply (induct_tac u rule: induct_trace)\nby (simp_all add: par_tr_head)\n\nlemma par_tr_Tick_nil[simp]:\n  \"(u : <Tick> |[X]|tr <>) = False\"\napply (induct_tac u rule: induct_trace)\nby (simp_all add: par_tr_head)\n\n(*** nil-Ev ***)\n\nlemma par_tr_nil_Ev_iff:\n  \"u : <> |[X]|tr (<Ev a> ^^^ t)\n   = (a ~: X & (EX v. u = <Ev a> ^^^ v & v : <> |[X]|tr t))\"\napply (rule iffI)\napply (rule par_tr_nil_Ev_rev)\napply (simp)\n\napply (elim conjE exE, simp)\napply (simp add: par_tr_nil_Ev)\ndone\n\n(*** Tcik-Ev ***)\n\nlemma par_tr_Tick_Ev_iff:\n  \"u : <Tick> |[X]|tr (<Ev a> ^^^ t)\n   = (a ~: X & (EX v. u = <Ev a> ^^^ v & v : <Tick> |[X]|tr t))\"\napply (rule iffI)\napply (rule par_tr_Tick_Ev_rev)\napply (simp)\n\napply (elim conjE exE, simp)\napply (simp add: par_tr_Ev_right)\ndone\n\n(****** nil ******)\n\nlemma par_tr_nil_left_only_if_imp:\n \"ALL u. (u : <> |[X]|tr s)\n   --> (u = s & Tick ~: sett u & sett u Int Ev ` X = {})\"\napply (induct_tac s rule: induct_trace)\napply (simp_all)\n\napply (intro allI impI)\napply (simp add: par_tr_nil_Ev_iff)\napply (elim conjE exE)\napply (drule_tac x=\"v\" in spec)\napply (auto)\ndone\n\nlemma par_tr_nil_left_only_if:\n \"(u : <> |[X]|tr s) \n   ==> u = s & Tick ~: sett u & sett u Int Ev ` X = {}\"\napply (insert par_tr_nil_left_only_if_imp[of X s])\napply (drule_tac x=\"u\" in spec)\napply (auto)\ndone\n\nlemma par_tr_nil_left_if_imp:\n \"(Tick ~: sett u & sett u Int Ev ` X = {})\n  --> (u : <> |[X]|tr u)\"\napply (induct_tac u rule: induct_trace)\nby (auto simp add: par_tr_head)\n\nlemma par_tr_nil_left_if:\n \"[| Tick ~: sett u ; sett u Int Ev ` X = {} |]\n  ==> (u : <> |[X]|tr u)\"\nby (simp add: par_tr_nil_left_if_imp)\n\n(*** nil left ***)\n\nlemma par_tr_nil_left:\n \"(u : <> |[X]|tr s) = (u = s & Tick ~: sett u & sett u Int Ev ` X = {})\"\napply (rule iffI)\napply (simp add: par_tr_nil_left_only_if)\napply (auto simp add: par_tr_nil_left_if)\ndone\n\n(*** nil right ***)\n\nlemma par_tr_nil_right:\n \"(u : s |[X]|tr <>) = (u = s & Tick ~: sett u & sett u Int Ev ` X = {})\"\napply (simp add: par_tr_sym)\napply (simp add: par_tr_nil_left)\ndone\n\nlemmas par_tr_nil = par_tr_nil_left par_tr_nil_right\n\n(****** Tick ******)\n\nlemma par_tr_Tick_left_only_if_imp:\n \"ALL u. u : <Tick> |[X]|tr s \n   --> (u = s & Tick : sett u & sett u Int Ev ` X = {})\"\napply (induct_tac s rule: induct_trace)\napply (simp_all)\napply (simp add: image_def)\n\napply (intro allI impI)\napply (simp add: par_tr_Tick_Ev_iff)\napply (elim conjE exE)\napply (drule_tac x=\"v\" in spec)\napply (auto)\ndone\n\nlemma par_tr_Tick_left_only_if:\n \"(u : <Tick> |[X]|tr s) \n   ==> u = s & Tick : sett u & sett u Int Ev ` X = {}\"\napply (insert par_tr_Tick_left_only_if_imp[of X s])\napply (drule_tac x=\"u\" in spec)\napply (auto)\ndone\n\nlemma par_tr_Tick_left_if_imp:\n \"(Tick : sett u & sett u Int Ev ` X = {})\n  --> (u : <Tick> |[X]|tr u)\"\napply (induct_tac u rule: induct_trace)\nby (auto simp add: par_tr_head)\n\nlemma par_tr_Tick_left_if:\n \"[| Tick : sett u ; sett u Int Ev ` X = {} |]\n  ==> (u : <Tick> |[X]|tr u)\"\nby (simp add: par_tr_Tick_left_if_imp)\n\n(*** Tick left ***)\n\nlemma par_tr_Tick_left:\n \"(u : <Tick> |[X]|tr s) \n= (u = s & Tick : sett u & sett u Int Ev ` X = {})\"\napply (rule iffI)\napply (simp add: par_tr_Tick_left_only_if)\napply (auto simp add: par_tr_Tick_left_if)\ndone\n\n(*** Tick right ***)\n\nlemma par_tr_Tick_right:\n \"(u : s |[X]|tr <Tick>) \n= (u = s & Tick : sett u & sett u Int Ev ` X = {})\"\napply (simp add: par_tr_sym[of _ _ \"<Tick>\"])\napply (simp add: par_tr_Tick_left)\ndone\n\nlemmas par_tr_Tick = par_tr_Tick_left par_tr_Tick_right\n\n(*** par sett ***)\n\nlemma par_tr_sett: \"ALL s t. u : s |[X]|tr t --> sett u <= sett s Un sett t\"\napply (induct_tac u rule: induct_trace)\napply (simp_all)\napply (intro allI impI)\napply (simp add: par_tr_head)\napply (erule disjE)\n\n(* sync *)\n apply (elim conjE exE)\n apply (drule_tac x=\"s'\" in spec)\n apply (drule_tac x=\"t'\" in spec)\n apply (force)\n\n(* left *)\n apply (erule disjE)\n apply (elim conjE exE)\n apply (drule_tac x=\"s'\" in spec)\n apply (drule_tac x=\"t\" in spec)\n apply (force)\n\n(* right *)\n apply (elim conjE exE)\n apply (drule_tac x=\"sa\" in spec)\n apply (drule_tac x=\"t'\" in spec)\n apply (force)\ndone\n\n(* =================================================== *\n |             addition for CSP-Prover 5               |\n * =================================================== *)\n\n\nlemma interleave_appt_left_lm:\n  \"ALL u s t. \n   (u : s |[{}]|tr t & (noTick v))\n     --> v ^^^ u : (v ^^^ s) |[{}]|tr t\"\napply (induct_tac v rule: induct_trace)\napply (simp_all)\napply (intro allI impI)\napply (simp)\napply (drule_tac x=\"u\" in spec)\napply (drule_tac x=\"sa\" in spec)\napply (drule_tac x=\"t\" in spec)\napply (erule conjE)\napply (simp add: appt_assoc)\napply (simp add: par_tr_head)\ndone\n\nlemma interleave_appt_left_step:\n  \"[| u : s |[{}]|tr t ; noTick v |] ==> v ^^^ u : (v ^^^ s) |[{}]|tr t\"\nby (simp add: interleave_appt_left_lm)\n\nlemma interleave_appt_right_step:\n  \"[| u : t |[{}]|tr s ; noTick v |] ==> v ^^^ u : t |[{}]|tr (v ^^^ s)\"\napply (simp add: par_tr_sym)\napply (insert interleave_appt_left_step[of u s t v])\napply (simp add: par_tr_sym)\ndone\n\nlemma interleave_appt_left_nil:\n  \"[| u : <> |[{}]|tr t ; noTick v |] ==> v ^^^ u : v |[{}]|tr t\"\napply (insert interleave_appt_left_step[of u <> t v])\nby (simp)\n\nlemma interleave_appt_right_nil:\n  \"[| u : t |[{}]|tr <> ; noTick v |] ==> v ^^^ u : t |[{}]|tr v\"\napply (insert interleave_appt_right_step[of u t <> v])\nby (simp)\n\nlemma interleave_appt_left_nil_nil:\n  \"noTick t ==> t : t |[{}]|tr <>\"\napply (insert interleave_appt_left_step[of <> <> <> t])\nby (simp)\n\nlemma interleave_appt_right_nil_nil:\n  \"noTick t ==> t : <> |[{}]|tr t\"\napply (insert interleave_appt_right_step[of <> <> <> t])\nby (simp)\n\nlemmas interleave_appt_left =\n       interleave_appt_left_step\n       interleave_appt_left_nil\n       interleave_appt_left_nil_nil\n\nlemmas interleave_appt_right =\n       interleave_appt_right_step\n       interleave_appt_right_nil\n       interleave_appt_right_nil_nil\n\n(*  par decompo *)\n\nlemma par_tr_app_right[rule_format]:\n  \"ALL u v s t.\n   (noTick u & sett u Int (Ev ` X) = {} & v : (s |[X]|tr t))\n     --> u ^^^ v : (s |[X]|tr (u ^^^ t))\"\napply (rule)\napply (induct_tac u rule: induct_trace)\napply (simp_all)\napply (intro allI impI)\napply (elim exE conjE)\napply (drule_tac x=\"v\" in spec)\napply (drule_tac x=\"sa\" in spec)\napply (drule_tac x=\"t\" in spec)\napply (simp)\napply (simp add: appt_assoc)\napply (simp add: par_tr_head)\napply (auto)\ndone\n\n(****************** to add it again ******************)\n\ndeclare disj_not1   [simp] \n\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/CSP/Trace_par.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.2923814378995846}}
{"text": "(* \n   Title: Psi-calculi   \n   Author/Maintainer: Jesper Bengtson (jebe@itu.dk), 2012\n*)\ntheory Bisim_Pres\n  imports Bisimulation Sim_Pres\nbegin\n\ncontext env begin\n\nlemma bisimInputPres:\n  fixes \\<Psi>    :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   xvec :: \"name list\"\n  and   N    :: 'a\n\n  assumes \"\\<And>Tvec. length xvec = length Tvec \\<Longrightarrow> \\<Psi> \\<rhd> P[xvec::=Tvec] \\<sim> Q[xvec::=Tvec]\"\n\n  shows \"\\<Psi> \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.P \\<sim> M\\<lparr>\\<lambda>*xvec N\\<rparr>.Q\"\nproof -\n  let ?X = \"{(\\<Psi>, M\\<lparr>\\<lambda>*xvec N\\<rparr>.P, M\\<lparr>\\<lambda>*xvec N\\<rparr>.Q) | \\<Psi> M xvec N P Q. \\<forall>Tvec. length xvec = length Tvec \\<longrightarrow> \\<Psi> \\<rhd> P[xvec::=Tvec] \\<sim> Q[xvec::=Tvec]}\"\n\n  from assms have \"(\\<Psi>, M\\<lparr>\\<lambda>*xvec N\\<rparr>.P, M\\<lparr>\\<lambda>*xvec N\\<rparr>.Q) \\<in> ?X\" by blast\n  thus ?thesis\n  proof(coinduct rule: bisimCoinduct)\n    case(cStatEq \\<Psi> P Q)\n    thus ?case by auto\n  next\n    case(cSim \\<Psi> P Q)\n    thus ?case by(blast intro: inputPres)\n  next\n    case(cExt \\<Psi> P Q \\<Psi>')\n    thus ?case by(blast dest: bisimE)\n  next\n    case(cSym \\<Psi> P Q)\n    thus ?case by(blast dest: bisimE)\n  qed\nqed\n  \nlemma bisimOutputPres:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   M :: 'a\n  and   N :: 'a\n\n  assumes \"\\<Psi> \\<rhd> P \\<sim> Q\"\n\n  shows \"\\<Psi> \\<rhd> M\\<langle>N\\<rangle>.P \\<sim> M\\<langle>N\\<rangle>.Q\"\nproof -\n  let ?X = \"{(\\<Psi>, M\\<langle>N\\<rangle>.P, M\\<langle>N\\<rangle>.Q) | \\<Psi> M N P Q. \\<Psi> \\<rhd> P \\<sim> Q}\"\n  from \\<open>\\<Psi> \\<rhd> P \\<sim> Q\\<close> have \"(\\<Psi>, M\\<langle>N\\<rangle>.P, M\\<langle>N\\<rangle>.Q) \\<in> ?X\" by auto\n  thus ?thesis\n    by(coinduct rule: bisimCoinduct, auto) (blast intro: outputPres dest: bisimE)+\nqed\n\nlemma bisimCasePres:\n  fixes \\<Psi>   :: 'b\n  and   CsP :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n  and   CsQ :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n\n  assumes \"\\<And>\\<phi> P. (\\<phi>, P) mem CsP \\<Longrightarrow> \\<exists>Q. (\\<phi>, Q) mem CsQ \\<and> guarded Q \\<and> \\<Psi> \\<rhd> P \\<sim> Q\"\n  and     \"\\<And>\\<phi> Q. (\\<phi>, Q) mem CsQ \\<Longrightarrow> \\<exists>P. (\\<phi>, P) mem CsP \\<and> guarded P \\<and> \\<Psi> \\<rhd> P \\<sim> Q\"\n\n  shows \"\\<Psi> \\<rhd> Cases CsP \\<sim> Cases CsQ\"\nproof -\n  let ?X = \"{(\\<Psi>, Cases CsP, Cases CsQ) | \\<Psi> CsP CsQ. (\\<forall>\\<phi> P. (\\<phi>, P) mem CsP \\<longrightarrow> (\\<exists>Q. (\\<phi>, Q) mem CsQ \\<and> guarded Q \\<and> \\<Psi> \\<rhd> P \\<sim> Q)) \\<and>\n                                                     (\\<forall>\\<phi> Q. (\\<phi>, Q) mem CsQ \\<longrightarrow> (\\<exists>P. (\\<phi>, P) mem CsP \\<and> guarded P \\<and> \\<Psi> \\<rhd> P \\<sim> Q))}\"\n  from assms have \"(\\<Psi>, Cases CsP, Cases CsQ) \\<in> ?X\" by auto\n  thus ?thesis\n  proof(coinduct rule: bisimCoinduct)\n    case(cStatEq \\<Psi> P Q)\n    thus ?case by auto\n  next\n    case(cSim \\<Psi> CasesP CasesQ)\n    then obtain CsP CsQ where C1: \"\\<And>\\<phi> Q. (\\<phi>, Q) mem CsQ \\<Longrightarrow> \\<exists>P. (\\<phi>, P) mem CsP \\<and> guarded P \\<and> \\<Psi> \\<rhd> P \\<sim> Q\"\n                          and A: \"CasesP = Cases CsP\" and B: \"CasesQ = Cases CsQ\"\n      by auto\n    note C1\n    moreover have \"\\<And>\\<Psi> P Q. \\<Psi> \\<rhd> P \\<sim> Q \\<Longrightarrow> \\<Psi> \\<rhd> P \\<leadsto>[bisim] Q\" by(rule bisimE)\n    moreover have \"bisim \\<subseteq> ?X \\<union> bisim\" by blast\n    ultimately have \"\\<Psi> \\<rhd> Cases CsP \\<leadsto>[(?X \\<union> bisim)] Cases CsQ\"\n      by(rule casePres)\n    thus ?case using A B by blast\n  next\n    case(cExt \\<Psi> P Q)\n    thus ?case by(blast dest: bisimE)\n  next\n    case(cSym \\<Psi> P Q)\n    thus ?case by(blast dest: bisimE)\n  qed\nqed\n\nlemma bisimResPres:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   x :: name\n  \n  assumes \"\\<Psi> \\<rhd> P \\<sim> Q\"\n  and     \"x \\<sharp> \\<Psi>\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<sim> \\<lparr>\\<nu>x\\<rparr>Q\"\nproof -\n  let ?X = \"{(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>P, \\<lparr>\\<nu>x\\<rparr>Q) | \\<Psi> x P Q. \\<Psi> \\<rhd> P \\<sim> Q \\<and> x \\<sharp> \\<Psi>}\"\n  \n  from assms have \"(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>P, \\<lparr>\\<nu>x\\<rparr>Q) \\<in> ?X\" by auto\n  thus ?thesis\n  proof(coinduct rule: bisimCoinduct)\n    case(cStatEq \\<Psi> xP xQ)\n    from \\<open>(\\<Psi>, xP, xQ) \\<in> ?X\\<close> obtain x P Q where \"\\<Psi> \\<rhd> P \\<sim> Q\" and \"x \\<sharp> \\<Psi>\" and \"xP = \\<lparr>\\<nu>x\\<rparr>P\" and \"xQ = \\<lparr>\\<nu>x\\<rparr>Q\"\n      by auto\n    moreover from \\<open>\\<Psi> \\<rhd> P \\<sim> Q\\<close> have PeqQ: \"insertAssertion(extractFrame P) \\<Psi> \\<simeq>\\<^sub>F insertAssertion(extractFrame Q) \\<Psi>\"\n      by(rule bisimE)\n    ultimately show ?case by(auto intro: frameResPres)\n  next\n    case(cSim \\<Psi> xP xQ)\n    from \\<open>(\\<Psi>, xP, xQ) \\<in> ?X\\<close> obtain x P Q where \"\\<Psi> \\<rhd> P \\<sim> Q\" and \"x \\<sharp> \\<Psi>\" and \"xP = \\<lparr>\\<nu>x\\<rparr>P\" and \"xQ = \\<lparr>\\<nu>x\\<rparr>Q\"\n      by auto\n    from \\<open>\\<Psi> \\<rhd> P \\<sim> Q\\<close> have \"\\<Psi> \\<rhd> P \\<leadsto>[bisim] Q\" by(rule bisimE)\n    moreover have \"eqvt ?X\"\n      by(force simp add: eqvt_def bisimClosed pt_fresh_bij[OF pt_name_inst, OF at_name_inst])\n    hence \"eqvt(?X \\<union> bisim)\" by auto\n    moreover note \\<open>x \\<sharp> \\<Psi>\\<close>\n    moreover have \"bisim \\<subseteq> ?X \\<union> bisim\" by auto\n    moreover have \"\\<And>\\<Psi> P Q x. \\<lbrakk>(\\<Psi>, P, Q) \\<in> bisim; x \\<sharp> \\<Psi>\\<rbrakk> \\<Longrightarrow> (\\<Psi>, \\<lparr>\\<nu>x\\<rparr>P, \\<lparr>\\<nu>x\\<rparr>Q) \\<in> ?X \\<union> bisim\"\n      by auto\n    ultimately have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<leadsto>[(?X \\<union> bisim)] \\<lparr>\\<nu>x\\<rparr>Q\"\n      by(rule resPres)\n    with \\<open>xP = \\<lparr>\\<nu>x\\<rparr>P\\<close> \\<open>xQ = \\<lparr>\\<nu>x\\<rparr>Q\\<close> show ?case\n      by simp\n  next\n    case(cExt \\<Psi> xP xQ \\<Psi>')\n    from \\<open>(\\<Psi>, xP, xQ) \\<in> ?X\\<close> obtain x P Q where \"\\<Psi> \\<rhd> P \\<sim> Q\" and \"x \\<sharp> \\<Psi>\" and \"xP = \\<lparr>\\<nu>x\\<rparr>P\" and \"xQ = \\<lparr>\\<nu>x\\<rparr>Q\"\n      by auto\n    obtain y::name where \"y \\<sharp> P\" and \"y \\<sharp> Q\" and \"y \\<sharp> \\<Psi>\" and \"y \\<sharp> \\<Psi>'\"\n     by(generate_fresh \"name\", auto simp add: fresh_prod)\n   from \\<open>\\<Psi> \\<rhd> P \\<sim> Q\\<close> have \"\\<Psi> \\<otimes> ([(x, y)] \\<bullet> \\<Psi>') \\<rhd> P \\<sim> Q\"\n     by(rule bisimE)\n   hence \"([(x, y)] \\<bullet> (\\<Psi> \\<otimes> ([(x, y)] \\<bullet> \\<Psi>'))) \\<rhd> ([(x, y)] \\<bullet> P) \\<sim> ([(x, y)] \\<bullet> Q)\"\n     by(rule bisimClosed)\n   with \\<open>x \\<sharp> \\<Psi>\\<close> \\<open>y \\<sharp> \\<Psi>\\<close> have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> ([(x, y)] \\<bullet> P) \\<sim> ([(x, y)] \\<bullet> Q)\"\n     by(simp add: eqvts)\n   with \\<open>y \\<sharp> \\<Psi>\\<close> \\<open>y \\<sharp> \\<Psi>'\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>', \\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> P), \\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> Q)) \\<in> ?X\"\n     by auto\n   moreover from \\<open>y \\<sharp> P\\<close> \\<open>y \\<sharp> Q\\<close> have \"\\<lparr>\\<nu>x\\<rparr>P = \\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> P)\" and \"\\<lparr>\\<nu>x\\<rparr>Q = \\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> Q)\"\n     by(simp add: alphaRes)+\n   ultimately show ?case using \\<open>xP = \\<lparr>\\<nu>x\\<rparr>P\\<close> \\<open>xQ = \\<lparr>\\<nu>x\\<rparr>Q\\<close> by simp\n next\n    case(cSym \\<Psi> P Q)\n    thus ?case\n      by(blast dest: bisimE)\n  qed\nqed\n\nlemma bisimResChainPres:\n  fixes \\<Psi>   :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   xvec :: \"name list\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<sim> Q\"\n  and     \"xvec \\<sharp>* \\<Psi>\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>P \\<sim> \\<lparr>\\<nu>*xvec\\<rparr>Q\"\nusing assms\nby(induct xvec) (auto intro: bisimResPres)\n\nlemma bisimParPresAux:\n  fixes \\<Psi>  :: 'b\n  and   \\<Psi>\\<^sub>R :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   Q  :: \"('a, 'b, 'c) psi\"\n  and   R  :: \"('a, 'b, 'c) psi\"\n  and   A\\<^sub>R :: \"name list\"\n  \n  assumes \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q\"\n  and     FrR: \"extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\"\n  and     \"A\\<^sub>R \\<sharp>* \\<Psi>\"\n  and     \"A\\<^sub>R \\<sharp>* P\"\n  and     \"A\\<^sub>R \\<sharp>* Q\"\n\n  shows \"\\<Psi> \\<rhd> P \\<parallel> R \\<sim> Q \\<parallel> R\"\nproof -\n  let ?X = \"{(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> R), \\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> R)) | xvec \\<Psi> P Q R. xvec \\<sharp>* \\<Psi> \\<and> (\\<forall>A\\<^sub>R \\<Psi>\\<^sub>R. (extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle> \\<and> A\\<^sub>R \\<sharp>* \\<Psi> \\<and> A\\<^sub>R \\<sharp>* P \\<and> A\\<^sub>R \\<sharp>* Q) \\<longrightarrow>\n                                                                                          \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q)}\"\n  {\n    fix xvec :: \"name list\"\n    and \\<Psi>    :: 'b \n    and P    :: \"('a, 'b, 'c) psi\"\n    and Q    :: \"('a, 'b, 'c) psi\"\n    and R    :: \"('a, 'b, 'c) psi\"\n\n    assume \"xvec \\<sharp>* \\<Psi>\"\n    and    \"\\<And>A\\<^sub>R \\<Psi>\\<^sub>R. \\<lbrakk>extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>; A\\<^sub>R \\<sharp>* \\<Psi>; A\\<^sub>R \\<sharp>* P; A\\<^sub>R \\<sharp>* Q\\<rbrakk> \\<Longrightarrow> \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q\"\n\n    hence \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> R), \\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> R)) \\<in> ?X\"\n      apply auto\n      by blast\n  }\n\n  note XI = this\n  {\n    fix xvec :: \"name list\"\n    and \\<Psi>    :: 'b \n    and P    :: \"('a, 'b, 'c) psi\"\n    and Q    :: \"('a, 'b, 'c) psi\"\n    and R    :: \"('a, 'b, 'c) psi\"\n    and C    :: \"'d::fs_name\"\n\n    assume \"xvec \\<sharp>* \\<Psi>\"\n    and    A: \"\\<And>A\\<^sub>R \\<Psi>\\<^sub>R. \\<lbrakk>extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>; A\\<^sub>R \\<sharp>* \\<Psi>; A\\<^sub>R \\<sharp>* P; A\\<^sub>R \\<sharp>* Q; A\\<^sub>R \\<sharp>* C\\<rbrakk> \\<Longrightarrow> \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q\"\n\n    from \\<open>xvec \\<sharp>* \\<Psi>\\<close> have \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> R), \\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> R)) \\<in> ?X\"\n    proof(rule XI)\n      fix A\\<^sub>R \\<Psi>\\<^sub>R\n      assume FrR: \"extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\"\n      obtain p::\"name prm\" where \"(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>\" and \"(p \\<bullet> A\\<^sub>R) \\<sharp>* P\" and \"(p \\<bullet> A\\<^sub>R) \\<sharp>* Q\" and \"(p \\<bullet> A\\<^sub>R) \\<sharp>* R\" and \"(p \\<bullet> A\\<^sub>R) \\<sharp>* C\"\n                             and \"(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>\\<^sub>R\" and S: \"(set p) \\<subseteq> (set A\\<^sub>R) \\<times> (set(p \\<bullet> A\\<^sub>R))\" and \"distinctPerm p\"\n        by(rule_tac c=\"(\\<Psi>, P, Q, R, \\<Psi>\\<^sub>R, C)\" in name_list_avoiding) auto\n      from FrR \\<open>(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>\\<^sub>R\\<close> S have \"extractFrame R = \\<langle>(p \\<bullet> A\\<^sub>R), p \\<bullet> \\<Psi>\\<^sub>R\\<rangle>\" by(simp add: frameChainAlpha')\n\n      moreover assume \"A\\<^sub>R \\<sharp>* \\<Psi>\"\n      hence \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> \\<Psi>)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n      with \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>\\<close> S have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>\" by simp\n      moreover assume \"A\\<^sub>R \\<sharp>* P\"\n      hence \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> P)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n      with \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>(p \\<bullet> A\\<^sub>R) \\<sharp>* P\\<close> S have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* P\" by simp\n      moreover assume \"A\\<^sub>R \\<sharp>* Q\"\n      hence \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> Q)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n      with \\<open>A\\<^sub>R \\<sharp>* Q\\<close> \\<open>(p \\<bullet> A\\<^sub>R) \\<sharp>* Q\\<close> S have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* Q\" by simp\n      ultimately have \"\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R) \\<rhd> P \\<sim> Q\" using \\<open>(p \\<bullet> A\\<^sub>R) \\<sharp>* C\\<close> A by blast\n      hence \"(p \\<bullet> (\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R))) \\<rhd> (p \\<bullet> P) \\<sim> (p \\<bullet> Q)\" by(rule bisimClosed)\n      with \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>(p \\<bullet> A\\<^sub>R) \\<sharp>* P\\<close> \\<open>A\\<^sub>R \\<sharp>* Q\\<close> \\<open>(p \\<bullet> A\\<^sub>R) \\<sharp>* Q\\<close> S \\<open>distinctPerm p\\<close>\n      show \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q\" by(simp add: eqvts)\n    qed\n  }\n  note XI' = this\n\n  have \"eqvt ?X\"\n    apply(auto simp add: eqvt_def)\n    apply(rule_tac x=\"p \\<bullet> xvec\" in exI)\n    apply(rule_tac x=\"p \\<bullet> P\" in exI)\n    apply(rule_tac x=\"p \\<bullet> Q\" in exI)\n    apply(rule_tac x=\"p \\<bullet> R\" in exI)\n    apply(simp add: eqvts)\n    apply(simp add: fresh_star_bij)\n    apply(clarify)\n    apply(erule_tac x=\"(rev p) \\<bullet> A\\<^sub>R\" in allE)\n    apply(erule_tac x=\"(rev p) \\<bullet> \\<Psi>\\<^sub>R\" in allE)\n    apply(drule mp)\n    apply(rule conjI)\n    apply(rule_tac pi=p in pt_bij4[OF pt_name_inst, OF at_name_inst])\n    apply(simp add: eqvts)\n    defer\n    apply(drule_tac p=p in bisimClosed)\n    apply(simp add: eqvts)\n    apply(subst pt_fresh_star_bij[OF pt_name_inst,OF at_name_inst, of p, THEN sym])\n    apply simp\n    apply(subst pt_fresh_star_bij[OF pt_name_inst,OF at_name_inst, of p, THEN sym])\n    apply simp\n    apply(subst pt_fresh_star_bij[OF pt_name_inst,OF at_name_inst, of p, THEN sym])\n    by simp\n\n  moreover have Res: \"\\<And>\\<Psi> P Q x. \\<lbrakk>(\\<Psi>, P, Q) \\<in> ?X \\<union> bisim; x \\<sharp> \\<Psi>\\<rbrakk> \\<Longrightarrow> (\\<Psi>, \\<lparr>\\<nu>x\\<rparr>P, \\<lparr>\\<nu>x\\<rparr>Q) \\<in> ?X \\<union> bisim\"\n  proof -\n    fix \\<Psi> P Q x\n    assume \"(\\<Psi>, P, Q) \\<in> ?X \\<union> bisim\" and \"(x::name) \\<sharp> \\<Psi>\"\n    show \"(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>P, \\<lparr>\\<nu>x\\<rparr>Q) \\<in> ?X \\<union> bisim\"\n    proof(case_tac \"(\\<Psi>, P, Q) \\<in> ?X\")\n      assume \"(\\<Psi>, P, Q) \\<in> ?X\"\n      with \\<open>x \\<sharp> \\<Psi>\\<close> have \"(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>P, \\<lparr>\\<nu>x\\<rparr>Q) \\<in> ?X\"\n        apply auto\n        by(rule_tac x=\"x#xvec\" in exI) auto\n      thus ?thesis by simp\n    next\n      assume \"\\<not>(\\<Psi>, P, Q) \\<in> ?X\"\n      with \\<open>(\\<Psi>, P, Q) \\<in> ?X \\<union> bisim\\<close> have \"\\<Psi> \\<rhd> P \\<sim> Q\"\n        by blast\n      hence \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<sim> \\<lparr>\\<nu>x\\<rparr>Q\" using \\<open>x \\<sharp> \\<Psi>\\<close>\n        by(rule bisimResPres)\n      thus ?thesis\n        by simp\n    qed\n  qed\n\n  have \"(\\<Psi>, P \\<parallel> R, Q \\<parallel> R) \\<in> ?X\" \n  proof -\n    {\n      fix A\\<^sub>R' :: \"name list\"\n      and \\<Psi>\\<^sub>R' :: 'b\n\n      assume FrR': \"extractFrame R = \\<langle>A\\<^sub>R', \\<Psi>\\<^sub>R'\\<rangle>\"\n      and    \"A\\<^sub>R' \\<sharp>* \\<Psi>\"\n      and    \"A\\<^sub>R' \\<sharp>* P\"\n      and    \"A\\<^sub>R' \\<sharp>* Q\"\n\n      obtain p where \"(p \\<bullet> A\\<^sub>R') \\<sharp>* A\\<^sub>R\" and \"(p \\<bullet> A\\<^sub>R') \\<sharp>* \\<Psi>\\<^sub>R'\" and \"(p \\<bullet> A\\<^sub>R') \\<sharp>* \\<Psi>\" and \"(p \\<bullet> A\\<^sub>R') \\<sharp>* P\" and \"(p \\<bullet> A\\<^sub>R') \\<sharp>* Q\"\n                 and Sp: \"(set p) \\<subseteq> (set A\\<^sub>R') \\<times> (set(p \\<bullet> A\\<^sub>R'))\" and \"distinctPerm p\"\n        by(rule_tac c=\"(A\\<^sub>R, \\<Psi>, \\<Psi>\\<^sub>R', P, Q)\" in name_list_avoiding) auto\n            \n      from FrR' \\<open>(p \\<bullet> A\\<^sub>R') \\<sharp>*  \\<Psi>\\<^sub>R'\\<close> Sp have \"extractFrame R = \\<langle>(p \\<bullet> A\\<^sub>R'), p \\<bullet> \\<Psi>\\<^sub>R'\\<rangle>\"\n        by(simp add: frameChainAlpha eqvts)\n      with FrR \\<open>(p \\<bullet> A\\<^sub>R') \\<sharp>* A\\<^sub>R\\<close> obtain q::\"name prm\" \n        where Sq: \"set q \\<subseteq> set(p \\<bullet> A\\<^sub>R') \\<times> set A\\<^sub>R\" and \"distinctPerm q\" and \"\\<Psi>\\<^sub>R = q \\<bullet> p \\<bullet> \\<Psi>\\<^sub>R'\"\n        by(force elim: frameChainEq)\n\n      from \\<open>\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q\\<close> \\<open>\\<Psi>\\<^sub>R = q \\<bullet> p \\<bullet> \\<Psi>\\<^sub>R'\\<close> have \"\\<Psi> \\<otimes> (q \\<bullet> p \\<bullet> \\<Psi>\\<^sub>R') \\<rhd> P \\<sim> Q\" by simp\n      hence \"(q \\<bullet> (\\<Psi> \\<otimes> (q \\<bullet> p \\<bullet> \\<Psi>\\<^sub>R'))) \\<rhd> (q \\<bullet> P) \\<sim> (q \\<bullet> Q)\" by(rule bisimClosed)\n      with Sq \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>(p \\<bullet> A\\<^sub>R') \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>(p \\<bullet> A\\<^sub>R') \\<sharp>* P\\<close> \\<open>A\\<^sub>R \\<sharp>* Q\\<close> \\<open>(p \\<bullet> A\\<^sub>R') \\<sharp>* Q\\<close> \\<open>distinctPerm q\\<close>\n      have \"\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R') \\<rhd> P \\<sim> Q\" by(simp add: eqvts)\n      hence \"(p \\<bullet> (\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R'))) \\<rhd> (p \\<bullet> P) \\<sim> (p \\<bullet> Q)\" by(rule bisimClosed)\n      with Sp \\<open>A\\<^sub>R' \\<sharp>* \\<Psi>\\<close> \\<open>(p \\<bullet> A\\<^sub>R') \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R' \\<sharp>* P\\<close> \\<open>(p \\<bullet> A\\<^sub>R') \\<sharp>* P\\<close> \\<open>A\\<^sub>R' \\<sharp>* Q\\<close> \\<open>(p \\<bullet> A\\<^sub>R') \\<sharp>* Q\\<close> \\<open>distinctPerm p\\<close>\n      have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R' \\<rhd> P \\<sim> Q\" by(simp add: eqvts)\n    }\n    thus ?thesis\n      apply auto\n      apply(rule_tac x=\"[]\" in exI)\n      by auto blast\n  qed\n  thus ?thesis\n  proof(coinduct rule: bisimCoinduct)\n    case(cStatEq \\<Psi> PR QR)\n    from \\<open>(\\<Psi>, PR, QR) \\<in> ?X\\<close>\n    obtain xvec P Q R A\\<^sub>R \\<Psi>\\<^sub>R where PFrR: \"PR = \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> R)\" and QFrR: \"QR = \\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> R)\"\n                              and \"xvec \\<sharp>* \\<Psi>\" and FrR: \"extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" and PSimQ: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q\"\n                              and \"A\\<^sub>R \\<sharp>* xvec\" and \"A\\<^sub>R \\<sharp>* \\<Psi>\" and \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* Q\" and \"A\\<^sub>R \\<sharp>* R\"\n      apply auto\n      apply(subgoal_tac \"\\<exists>A\\<^sub>R \\<Psi>\\<^sub>R. extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle> \\<and> A\\<^sub>R \\<sharp>* (xvec, \\<Psi>, P, Q, R)\")\n      apply auto\n      apply(rule_tac F=\"extractFrame R\" and C=\"(xvec, \\<Psi>, P, Q, R)\" in freshFrame)\n      by auto\n\n    obtain A\\<^sub>P \\<Psi>\\<^sub>P where FrP: \"extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\" and \"A\\<^sub>P \\<sharp>* A\\<^sub>R\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R\"\n      by(rule_tac C=\"(\\<Psi>, A\\<^sub>R, \\<Psi>\\<^sub>R)\" in freshFrame) auto\n    obtain A\\<^sub>Q \\<Psi>\\<^sub>Q where FrQ: \"extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\" and \"A\\<^sub>Q \\<sharp>* A\\<^sub>R\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R\"\n      by(rule_tac C=\"(\\<Psi>, A\\<^sub>R, \\<Psi>\\<^sub>R)\" in freshFrame) auto\n    from \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>A\\<^sub>R \\<sharp>* Q\\<close> \\<open>A\\<^sub>P \\<sharp>* A\\<^sub>R\\<close> \\<open>A\\<^sub>Q \\<sharp>* A\\<^sub>R\\<close> FrP FrQ have \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P\" and  \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q\"\n      by(force dest: extractFrameFreshChain)+\n    \n    have \"\\<langle>(A\\<^sub>P@A\\<^sub>R), \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<simeq>\\<^sub>F \\<langle>(A\\<^sub>Q@A\\<^sub>R), \\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n    proof -\n      have \"\\<langle>A\\<^sub>P, \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P\\<rangle>\"\n        by(metis frameResChainPres frameNilStatEq Associativity Commutativity AssertionStatEqTrans Composition)\n      moreover from PSimQ have \"insertAssertion(extractFrame P) (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<simeq>\\<^sub>F insertAssertion(extractFrame Q) (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R)\"\n        by(rule bisimE)\n      with FrP FrQ freshCompChain \\<open>A\\<^sub>P \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R\\<close> \\<open>A\\<^sub>Q \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R\\<close> have \"\\<langle>A\\<^sub>P, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle>\"\n        by auto\n      moreover have \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>Q, \\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n        by(metis frameResChainPres frameNilStatEq Associativity Commutativity AssertionStatEqTrans Composition)\n      ultimately have \"\\<langle>A\\<^sub>P, \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>Q, \\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n        by(blast intro: FrameStatEqTrans)\n      hence \"\\<langle>(A\\<^sub>R@A\\<^sub>P), \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<simeq>\\<^sub>F \\<langle>(A\\<^sub>R@A\\<^sub>Q), \\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n        by(drule_tac frameResChainPres) (simp add: frameChainAppend)\n      thus ?thesis\n        apply(simp add: frameChainAppend)\n        by(metis frameResChainComm FrameStatEqTrans)\n    qed\n    moreover from \\<open>A\\<^sub>P \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> have \"(A\\<^sub>P@A\\<^sub>R) \\<sharp>* \\<Psi>\" by simp\n    moreover from \\<open>A\\<^sub>Q \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> have \"(A\\<^sub>Q@A\\<^sub>R) \\<sharp>* \\<Psi>\" by simp\n    ultimately have PFrRQR: \"insertAssertion(extractFrame(P \\<parallel> R)) \\<Psi> \\<simeq>\\<^sub>F insertAssertion(extractFrame(Q \\<parallel> R)) \\<Psi>\"\n      using FrP FrQ FrR \\<open>A\\<^sub>P \\<sharp>* A\\<^sub>R\\<close> \\<open>A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R\\<close> \\<open>A\\<^sub>Q \\<sharp>* A\\<^sub>R\\<close> \\<open>A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R\\<close> \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P\\<close> \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q\\<close>\n      by simp\n      \n    from \\<open>xvec \\<sharp>* \\<Psi>\\<close> have \"insertAssertion (extractFrame(\\<lparr>\\<nu>*xvec\\<rparr>P \\<parallel> R)) \\<Psi> \\<simeq>\\<^sub>F \\<lparr>\\<nu>*xvec\\<rparr>(insertAssertion (extractFrame(P \\<parallel> R)) \\<Psi>)\"\n      by(rule insertAssertionExtractFrameFresh)\n    moreover from PFrRQR have \"\\<lparr>\\<nu>*xvec\\<rparr>(insertAssertion (extractFrame(P \\<parallel> R)) \\<Psi>) \\<simeq>\\<^sub>F \\<lparr>\\<nu>*xvec\\<rparr>(insertAssertion (extractFrame(Q \\<parallel> R)) \\<Psi>)\"\n      by(induct xvec) (auto intro: frameResPres)\n    moreover from \\<open>xvec \\<sharp>* \\<Psi>\\<close> have \"\\<lparr>\\<nu>*xvec\\<rparr>(insertAssertion (extractFrame(Q \\<parallel> R)) \\<Psi>) \\<simeq>\\<^sub>F insertAssertion (extractFrame(\\<lparr>\\<nu>*xvec\\<rparr>Q \\<parallel> R)) \\<Psi>\"\n      by(rule FrameStatEqSym[OF insertAssertionExtractFrameFresh])\n    ultimately show ?case using PFrR QFrR\n      by(blast intro: FrameStatEqTrans)\n  next\n    case(cSim \\<Psi> PR QR)\n    {\n      fix \\<Psi> P Q R xvec\n      assume \"\\<And>A\\<^sub>R \\<Psi>\\<^sub>R. \\<lbrakk>extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>; A\\<^sub>R \\<sharp>* \\<Psi>; A\\<^sub>R \\<sharp>* P; A\\<^sub>R \\<sharp>* Q\\<rbrakk> \\<Longrightarrow> \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q\"\n      moreover have \"eqvt bisim\" by simp\n      moreover from \\<open>eqvt ?X\\<close> have \"eqvt(?X \\<union> bisim)\" by auto\n      moreover from bisimE(1) have \"\\<And>\\<Psi> P Q. \\<Psi> \\<rhd> P \\<sim> Q \\<Longrightarrow> insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P) \\<Psi>\" by(simp add: FrameStatEq_def)\n      moreover note bisimE(2) bisimE(3)\n      moreover \n      {\n        fix \\<Psi> P Q A\\<^sub>R \\<Psi>\\<^sub>R R\n        assume PSimQ: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q\"\n           and FrR: \"extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\"\n           and \"A\\<^sub>R \\<sharp>* \\<Psi>\"\n           and \"A\\<^sub>R \\<sharp>* P\"\n           and \"A\\<^sub>R \\<sharp>* Q\"\n        hence \"(\\<Psi>, P \\<parallel> R, Q \\<parallel> R) \\<in> ?X\"\n        proof -\n          have \"P \\<parallel> R = \\<lparr>\\<nu>*[]\\<rparr>(P \\<parallel> R)\" by simp\n          moreover have \"Q \\<parallel> R = \\<lparr>\\<nu>*[]\\<rparr>(Q \\<parallel> R)\" by simp\n          moreover have \"([]::name list) \\<sharp>* \\<Psi>\" by simp\n          moreover \n          {\n            fix A\\<^sub>R' \\<Psi>\\<^sub>R'\n\n            assume FrR': \"extractFrame R = \\<langle>A\\<^sub>R', \\<Psi>\\<^sub>R'\\<rangle>\"\n               and \"A\\<^sub>R' \\<sharp>* \\<Psi>\"\n               and \"A\\<^sub>R' \\<sharp>* P\"\n               and \"A\\<^sub>R' \\<sharp>* Q\"\n            obtain p where \"(p \\<bullet> A\\<^sub>R') \\<sharp>* A\\<^sub>R\"\n                       and \"(p \\<bullet> A\\<^sub>R') \\<sharp>* \\<Psi>\\<^sub>R'\"\n                       and \"(p \\<bullet> A\\<^sub>R') \\<sharp>* \\<Psi>\"\n                       and \"(p \\<bullet> A\\<^sub>R') \\<sharp>* P\"\n                       and \"(p \\<bullet> A\\<^sub>R') \\<sharp>* Q\"\n                       and S: \"(set p) \\<subseteq> (set A\\<^sub>R') \\<times> (set(p \\<bullet> A\\<^sub>R'))\" and \"distinctPerm p\"\n              by(rule_tac c=\"(A\\<^sub>R, \\<Psi>, \\<Psi>\\<^sub>R', P, Q)\" in name_list_avoiding) auto\n\n\n            from \\<open>(p \\<bullet> A\\<^sub>R') \\<sharp>* \\<Psi>\\<^sub>R'\\<close> S have \"\\<langle>A\\<^sub>R', \\<Psi>\\<^sub>R'\\<rangle> = \\<langle>p \\<bullet> A\\<^sub>R', p \\<bullet> \\<Psi>\\<^sub>R'\\<rangle>\"\n              by(simp add: frameChainAlpha)\n\n            with FrR' have FrR'': \"extractFrame R = \\<langle>p \\<bullet> A\\<^sub>R', p \\<bullet> \\<Psi>\\<^sub>R'\\<rangle>\" by simp\n            with FrR \\<open>(p \\<bullet> A\\<^sub>R') \\<sharp>* A\\<^sub>R\\<close>\n            obtain q where \"p \\<bullet> \\<Psi>\\<^sub>R' = (q::name prm) \\<bullet> \\<Psi>\\<^sub>R\" and S': \"set q \\<subseteq> (set A\\<^sub>R) \\<times> set(p \\<bullet> A\\<^sub>R')\" and \"distinctPerm q\"\n              apply auto\n              apply(drule_tac sym) apply simp\n              by(drule_tac frameChainEq) auto\n            from PSimQ have \"(q \\<bullet> (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R)) \\<rhd> (q \\<bullet> P) \\<sim> (q \\<bullet> Q)\"\n              by(rule bisimClosed)\n            with \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>A\\<^sub>R \\<sharp>* Q\\<close> \\<open>(p \\<bullet> A\\<^sub>R') \\<sharp>* \\<Psi>\\<close> \\<open>(p \\<bullet> A\\<^sub>R') \\<sharp>* P\\<close> \\<open>(p \\<bullet> A\\<^sub>R') \\<sharp>* Q\\<close> S'\n            have \"\\<Psi> \\<otimes> (q \\<bullet> \\<Psi>\\<^sub>R) \\<rhd> P \\<sim> Q\" by(simp add: eqvts)\n            hence \"(p \\<bullet> (\\<Psi> \\<otimes> (q \\<bullet> \\<Psi>\\<^sub>R))) \\<rhd> (p \\<bullet> P) \\<sim> (p \\<bullet> Q)\" by(rule bisimClosed)\n            with \\<open>A\\<^sub>R' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R' \\<sharp>* P\\<close> \\<open>A\\<^sub>R' \\<sharp>* Q\\<close> \\<open>(p \\<bullet> A\\<^sub>R') \\<sharp>* \\<Psi>\\<close> \\<open>(p \\<bullet> A\\<^sub>R') \\<sharp>* P\\<close> \\<open>(p \\<bullet> A\\<^sub>R') \\<sharp>* Q\\<close> S \\<open>distinctPerm p\\<close> \\<open>(p \\<bullet> \\<Psi>\\<^sub>R') = q \\<bullet> \\<Psi>\\<^sub>R\\<close> \n            have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R' \\<rhd> P \\<sim> Q\"\n              by(drule_tac sym) (simp add: eqvts)\n          }\n          ultimately show ?thesis\n            by blast\n        qed\n        hence \"(\\<Psi>, P \\<parallel> R, Q \\<parallel> R) \\<in> ?X \\<union> bisim\"\n          by simp\n      }\n      moreover have \"\\<And>\\<Psi> P Q xvec. \\<lbrakk>(\\<Psi>, P, Q) \\<in> ?X \\<union> bisim; (xvec::name list) \\<sharp>* \\<Psi>\\<rbrakk> \\<Longrightarrow> (\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>P, \\<lparr>\\<nu>*xvec\\<rparr>Q) \\<in> ?X \\<union> bisim\"\n      proof -\n        fix \\<Psi> P Q xvec\n        assume \"(\\<Psi>, P, Q) \\<in> ?X \\<union> bisim\"\n        assume \"(xvec::name list) \\<sharp>* \\<Psi>\"\n        thus \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>P, \\<lparr>\\<nu>*xvec\\<rparr>Q) \\<in> ?X \\<union> bisim\"\n        proof(induct xvec)\n          case Nil\n          thus ?case using \\<open>(\\<Psi>, P, Q) \\<in> ?X \\<union> bisim\\<close> by simp\n        next\n          case(Cons x xvec)\n          thus ?case by(simp only: resChain.simps) (rule_tac Res, auto)\n        qed\n      qed\n      ultimately have \"\\<Psi> \\<rhd> P \\<parallel> R \\<leadsto>[(?X \\<union> bisim)] Q \\<parallel> R\" using statEqBisim\n        by(rule parPres)\n      moreover assume \"(xvec::name list) \\<sharp>* \\<Psi>\"\n      moreover from \\<open>eqvt ?X\\<close> have \"eqvt(?X \\<union> bisim)\" by auto\n      ultimately have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> R) \\<leadsto>[(?X \\<union> bisim)] \\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> R)\" using Res\n        by(rule_tac resChainPres)\n    }\n    with \\<open>(\\<Psi>, PR, QR) \\<in> ?X\\<close> show ?case by blast\n  next\n    case(cExt \\<Psi> PR QR \\<Psi>')\n\n    from \\<open>(\\<Psi>, PR, QR) \\<in> ?X\\<close>\n    obtain xvec P Q R A\\<^sub>R \\<Psi>\\<^sub>R where PFrR: \"PR = \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> R)\" and QFrR: \"QR = \\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> R)\"\n                               and \"xvec \\<sharp>* \\<Psi>\" and A: \"\\<forall>A\\<^sub>R \\<Psi>\\<^sub>R. (extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle> \\<and> A\\<^sub>R \\<sharp>* \\<Psi> \\<and> A\\<^sub>R \\<sharp>* P \\<and> A\\<^sub>R \\<sharp>* Q) \\<longrightarrow> \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q\"\n      by auto\n    \n    obtain p where \"(p \\<bullet> xvec) \\<sharp>* \\<Psi>\"\n               and \"(p \\<bullet> xvec) \\<sharp>* P\"\n               and \"(p \\<bullet> xvec) \\<sharp>* Q\"\n               and \"(p \\<bullet> xvec) \\<sharp>* R\"\n               and \"(p \\<bullet> xvec) \\<sharp>* \\<Psi>'\"\n               and S: \"(set p) \\<subseteq> (set xvec) \\<times> (set(p \\<bullet> xvec))\" and \"distinctPerm p\"\n      by(rule_tac c=\"(\\<Psi>, P, Q, R, \\<Psi>')\" in name_list_avoiding) auto\n\n    from \\<open>(p \\<bullet> xvec) \\<sharp>* P\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* R\\<close> S have \"\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> R) = \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>(p \\<bullet> (P \\<parallel> R))\"\n      by(subst resChainAlpha) auto\n    hence PRAlpha: \"\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> R) = \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> P) \\<parallel> (p \\<bullet> R))\"\n      by(simp add: eqvts)\n\n    from \\<open>(p \\<bullet> xvec) \\<sharp>* Q\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* R\\<close> S have \"\\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> R) = \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>(p \\<bullet> (Q \\<parallel> R))\"\n      by(subst resChainAlpha) auto\n    hence QRAlpha: \"\\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> R) = \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> Q) \\<parallel> (p \\<bullet> R))\"\n      by(simp add: eqvts)\n\n    from \\<open>(p \\<bullet> xvec) \\<sharp>* \\<Psi>\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* \\<Psi>'\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>', \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> P) \\<parallel> (p \\<bullet> R)), \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> Q) \\<parallel> (p \\<bullet> R))) \\<in> ?X\"\n    proof(rule_tac C2=\"(\\<Psi>, (p \\<bullet> P), (p \\<bullet> Q), R, \\<Psi>', xvec, p \\<bullet> xvec)\" in XI', auto)\n      fix A\\<^sub>R \\<Psi>\\<^sub>R\n      assume FrR: \"extractFrame (p \\<bullet> R) = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" and \"A\\<^sub>R \\<sharp>* \\<Psi>\" and \"A\\<^sub>R \\<sharp>* \\<Psi>'\" and \"A\\<^sub>R \\<sharp>* (p \\<bullet> P)\" and \"A\\<^sub>R \\<sharp>* (p \\<bullet> Q)\"\n      from FrR have \"(p \\<bullet> (extractFrame (p \\<bullet> R))) = (p \\<bullet> \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>)\" by simp\n      with \\<open>distinctPerm p\\<close> have \"extractFrame R = \\<langle>p \\<bullet> A\\<^sub>R, p \\<bullet> \\<Psi>\\<^sub>R\\<rangle>\" by(simp add: eqvts)\n      moreover from \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> \\<Psi>)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n      with \\<open>xvec \\<sharp>* \\<Psi>\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* \\<Psi>\\<close> S have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>\" by simp\n      moreover from \\<open>A\\<^sub>R \\<sharp>* (p \\<bullet> P)\\<close> have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> p \\<bullet> P)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n      with \\<open>distinctPerm p\\<close> have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* P\" by simp\n      moreover from \\<open>A\\<^sub>R \\<sharp>* (p \\<bullet> Q)\\<close> have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> p \\<bullet> Q)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n      with \\<open>distinctPerm p\\<close> have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* Q\" by simp\n      ultimately have \"\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R) \\<rhd> P \\<sim> Q\" using A by blast\n      hence \"(\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> (p \\<bullet> \\<Psi>') \\<rhd> P \\<sim> Q\" by(rule bisimE)\n      moreover have \"(\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> (p \\<bullet> \\<Psi>') \\<simeq> (\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>')) \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)\"\n        by(metis Associativity Commutativity Composition AssertionStatEqTrans AssertionStatEqSym)\n      ultimately have \"(\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>')) \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R) \\<rhd> P \\<sim> Q\" \n        by(rule statEqBisim)\n      hence \"(p \\<bullet> ((\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>')) \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R))) \\<rhd> (p \\<bullet> P) \\<sim> (p \\<bullet> Q)\"\n        by(rule bisimClosed)\n      with \\<open>distinctPerm p\\<close> \\<open>xvec \\<sharp>* \\<Psi>\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* \\<Psi>\\<close> S show \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>R \\<rhd> (p \\<bullet> P) \\<sim> (p \\<bullet> Q)\"\n        by(simp add: eqvts)\n    qed\n    with PFrR QFrR PRAlpha QRAlpha show ?case by simp\n  next\n    case(cSym \\<Psi> PR QR)\n    thus ?case by(blast dest: bisimE)\n  qed\nqed\n\nlemma bisimParPres:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   R :: \"('a, 'b, 'c) psi\"\n  \n  assumes \"\\<Psi> \\<rhd> P \\<sim> Q\"\n\n  shows \"\\<Psi> \\<rhd> P \\<parallel> R \\<sim> Q \\<parallel> R\"\nproof -\n  obtain A\\<^sub>R \\<Psi>\\<^sub>R where \"extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" and \"A\\<^sub>R \\<sharp>* \\<Psi>\" and \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* Q\"\n    by(rule_tac C=\"(\\<Psi>, P, Q)\" in freshFrame) auto\n  moreover from \\<open>\\<Psi> \\<rhd> P \\<sim> Q\\<close> have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q\" by(rule bisimE)\n  ultimately show ?thesis by(rule_tac bisimParPresAux)\nqed\n\nend\n\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Psi_Calculi/Bisim_Pres.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.2923814378995846}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory DistinctPropLemmaBucket\nimports\n  Lib\n  MoreDivides\n  Aligned\n  HOLLemmaBucket\n  DistinctProp\n  \"~~/src/HOL/Library/Sublist\"\n  \"~~/src/HOL/Library/Prefix_Order\"\n\nbegin\n\n\nlemma n_less_equal_power_2 [simp]:\n  \"n < 2 ^ n\"\n  by (induct_tac n, simp_all)\n\nlemma drop_Suc_nth:\n  \"n < length xs \\<Longrightarrow> drop n xs = xs!n # drop (Suc n) xs\"\n  apply (induct xs arbitrary: n)\n   apply simp\n  apply simp\n  apply (case_tac \"n = length xs\")\n   apply simp\n   apply (case_tac xs, simp)\n   apply (simp add: nth_append)\n  apply (case_tac n, simp)\n  apply simp\n  done\n\nlemma minus_Suc_0_lt:\n  \"a \\<noteq> 0 \\<Longrightarrow> a - Suc 0 < a\"\n  by simp\n\nlemma map_length_cong:\n  \"\\<lbrakk> length xs = length ys; \\<And>x y. (x, y) \\<in> set (zip xs ys) \\<Longrightarrow> f x = g y \\<rbrakk>\n     \\<Longrightarrow> map f xs = map g ys\"\n  apply atomize\n  apply (erule rev_mp, erule list_induct2)\n   apply auto\n  done\n\n(* FIXME: duplicate *)\nlemma zip_take_triv2:\n  \"n \\<ge> length as \\<Longrightarrow> zip as (take n bs) = zip as bs\"\n  apply (induct as arbitrary: n bs)\n   apply simp\n  apply simp\n  apply (case_tac n, simp_all)\n  apply (case_tac bs, simp_all)\n  done\n\nlemma zip_is_empty:\n  \"(zip xs ys = []) = (xs = [] \\<or> ys = [])\"\n  apply (case_tac xs, simp_all)\n  apply (case_tac ys, simp_all)\n  done\n\nlemma fst_last_zip_upt:\n  \"zip [0 ..< m] xs \\<noteq> [] \\<Longrightarrow>\n   fst (last (zip [0 ..< m] xs))\n    = (if length xs < m then length xs - 1 else m - 1)\"\n  apply (subst last_conv_nth, assumption)\n  apply (simp only: One_nat_def)\n  apply (subst nth_zip)\n    apply (rule order_less_le_trans[OF minus_Suc_0_lt])\n     apply (simp add: zip_is_empty)\n    apply simp\n   apply (rule order_less_le_trans[OF minus_Suc_0_lt])\n    apply (simp add: zip_is_empty)\n   apply simp\n  apply (simp add: min_def zip_is_empty)\n  done\n\nlemma not_prefixI:\n  fixes xs :: \"'a list\"\n  shows \"\\<lbrakk> xs \\<noteq> ys; length xs = length ys\\<rbrakk> \\<Longrightarrow> \\<not> xs \\<le> ys\"\n  apply (erule contrapos_nn)\n  apply (erule prefixE)\n  apply simp\n  done\n\n\nlemma less_1_helper:\n  \"n \\<le> m \\<Longrightarrow> (n - 1 :: int) < m\"\n  by arith\n\nlemma power_sub_int:\n  \"\\<lbrakk> m \\<le> n; 0 < b \\<rbrakk> \\<Longrightarrow> b ^ n div b ^ m = (b ^ (n - m) :: int)\"\n  apply (subgoal_tac \"\\<exists>n'. n = m + n'\")\n   apply (clarsimp simp: power_add)\n  apply (rule exI[where x=\"n - m\"])\n  apply simp\n  done\n\nlemma split_state_strg:\n  \"(\\<exists>x. f s = x \\<and> P x s) \\<longrightarrow> P (f s) s\" by clarsimp\n\nlemma theD:\n  \"\\<lbrakk>the (f x) = y;  x \\<in> dom f \\<rbrakk> \\<Longrightarrow> f x = Some y\"\n  by (auto simp add: dom_def)\n\nlemma bspec_split:\n  \"\\<lbrakk> \\<forall>(a, b) \\<in> S. P a b; (a, b) \\<in> S \\<rbrakk> \\<Longrightarrow> P a b\"\n  by fastforce\n\nlemma set_zip_same:\n  \"set (zip xs xs) = Id \\<inter> (set xs \\<times> set xs)\"\n  apply (induct xs, simp_all)\n  apply safe\n  done\n\nlemma univ_eq_obvious:\n  \"\\<not> (\\<forall>x. y \\<noteq> x)\"\n  by simp\n\nlemma ball_ran_updI:\n  \"(\\<forall>x \\<in> ran m. P x) \\<Longrightarrow> P v \\<Longrightarrow> (\\<forall>x \\<in> ran (m (y \\<mapsto> v)). P x)\"\n  by (auto simp add: ran_def)\n\nlemma not_psubset_eq:\n  \"\\<lbrakk> \\<not> A \\<subset> B; A \\<subseteq> B \\<rbrakk> \\<Longrightarrow> A = B\"\n  by blast\n\nprimrec\n  opt_rel :: \"('a \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow> 'a option \\<Rightarrow> 'b option \\<Rightarrow> bool\"\nwhere\n  \"opt_rel f  None    y = (y = None)\"\n| \"opt_rel f (Some x) y = (\\<exists>y'. y = Some y' \\<and> f x y')\"\n\nlemma opt_rel_None_rhs[simp]:\n  \"opt_rel f x None = (x = None)\"\n  by (cases x, simp_all)\n\nlemma opt_rel_Some_rhs[simp]:\n  \"opt_rel f x (Some y) = (\\<exists>x'. x = Some x' \\<and> f x' y)\"\n  by (cases x, simp_all)\n\nlemma in_image_op_plus:\n  \"(x + y \\<in> op + x ` S) = ((y :: 'a :: ring) \\<in> S)\"\n  by (simp add: image_def)\n\nlemma insert_subtract_new:\n  \"x \\<notin> S \\<Longrightarrow> (insert x S - S) = {x}\"\n  by auto\n\nlemma replicate_eq:\n  \"(replicate n x = replicate m y) = (n = m \\<and> (n \\<noteq> 0 \\<longrightarrow> x = y))\"\n  apply (induct n arbitrary: m)\n   apply simp\n   apply (case_tac m, simp_all)[1]\n  apply (case_tac m, simp_all)\n  apply auto\n  done\n\nlemma bspec_upd_None:\n  \"\\<lbrakk> \\<forall>c\\<in>ran (f (x := None)). P c; f y = Some c; y \\<noteq> x \\<rbrakk>\n     \\<Longrightarrow> P c\"\n  apply (erule bspec)\n  apply (simp add: fun_upd_def)\n  apply (rule ranI)\n  apply (subst if_not_P, assumption)\n  apply assumption\n  done\n\nlemma distinct_prefix:\n  \"\\<lbrakk> distinct xs; ys \\<le> xs \\<rbrakk> \\<Longrightarrow> distinct ys\"\n  apply (clarsimp simp: less_eq_list_def)\n  apply (induct xs arbitrary: ys)\n   apply simp\n  apply (case_tac ys)\n   apply simp\n  apply clarsimp\n  apply (drule set_mono_prefixeq)\n  apply fastforce\n  done\n\nprimrec\n  distinct_sets :: \"'a set list \\<Rightarrow> bool\"\nwhere\n  \"distinct_sets [] = True\"\n| \"distinct_sets (x#xs) = (x \\<inter> \\<Union>set xs = {} \\<and> distinct_sets xs)\"\n\nlemma distinct_sets_prop:\n  \"distinct_sets xs = distinct_prop (\\<lambda>x y. x \\<inter> y = {}) xs\"\n  by (induct xs) auto\n\nlemma distinct_take_strg:\n  \"distinct xs \\<longrightarrow> distinct (take n xs)\"\n  by simp\n\nlemma map_fst_zip_prefix:\n  \"map fst (zip xs ys) \\<le> xs\"\n  apply (induct xs arbitrary: ys)\n   apply simp\n  apply (case_tac ys)\n   apply simp\n  apply simp\n  done\n\n\nlemma distinct_prop_prefixE:\n  \"\\<lbrakk> distinct_prop P ys; prefixeq xs ys \\<rbrakk> \\<Longrightarrow> distinct_prop P xs\"\n  apply (induct xs arbitrary: ys)\n   apply simp\n  apply (case_tac ys)\n   apply simp\n  apply clarsimp\n  apply (drule set_mono_prefixeq)\n  apply (drule(1) subsetD)\n  apply clarsimp\n  done\n\nlemma inj_Pair:\n  \"inj_on (Pair x) S\"\n  by (rule inj_onI, simp)\n\nlemma inj_on_split:\n  \"inj_on f S \\<Longrightarrow> inj_on (\\<lambda>x. (z, f x)) S\"\n  by (auto simp: inj_on_def)\n\nlemma less_Suc_unat_less_bound:\n  \"n < Suc (unat (x :: ('a :: len) word)) \\<Longrightarrow> n < 2 ^ len_of TYPE('a)\"\n  apply (erule order_less_le_trans)\n  apply (rule Suc_leI)\n  apply simp\n  done\n\nlemma map_snd_zip_prefix:\n  \"map snd (zip xs ys) \\<le> ys\"\n  apply (induct xs arbitrary: ys)\n   apply simp\n  apply (case_tac ys)\n   apply simp\n  apply simp\n  done\n\n\n\n(****************************************\n * Take, drop, zip, list_all etc rules. *\n ****************************************)\n\nlemma nth_upt_0 [simp]:\n  \"i < length xs \\<Longrightarrow> [0..<length xs] ! i = i\"\n  by simp\n\nlemma take_insert_nth:\n  \"i < length xs\\<Longrightarrow>\n  insert (xs ! i) (set (take i xs)) = set (take (Suc i) xs)\"\n  by (subst take_Suc_conv_app_nth, assumption, fastforce)\n\nlemma zip_take_drop:\n  \"\\<lbrakk>n < length xs; length ys = length xs\\<rbrakk> \\<Longrightarrow>\n    zip xs (take n ys @ a # drop (Suc n) ys) =\n    zip (take n xs) (take n ys) @ (xs ! n, a) #  zip (drop (Suc n) xs) (drop (Suc n) ys)\"\n  by (subst id_take_nth_drop, assumption, simp)\n\nlemma take_nth_distinct:\n  \"\\<lbrakk>distinct xs; n < length xs; xs ! n \\<in> set (take n xs)\\<rbrakk> \\<Longrightarrow> False\"\n  by (fastforce simp: distinct_conv_nth in_set_conv_nth)\n\nlemma take_drop_append:\n  \"drop a xs = take b (drop a xs) @ drop (a + b) xs\"\n  by (metis append_take_drop_id drop_drop add.commute)\n\nlemma drop_take_drop:\n  \"drop a (take (b + a) xs) @ drop (b + a) xs = drop a xs\"\n  by (metis add.commute take_drop take_drop_append)\n\nlemma map_fst_zip':\n  \"length xs \\<le> length ys \\<Longrightarrow> map fst (zip xs ys) = xs\"\n  by (metis length_map length_zip map_fst_zip_prefix min_absorb1 not_prefixI)\n\nlemma zip_take_length:\n  \"zip xs (take (length xs) ys) = zip xs ys\"\n  by (metis order_refl zip_take_triv2)\n\nlemma zip_singleton:\n  \"ys \\<noteq> [] \\<Longrightarrow> zip [a] ys = [(a, ys ! 0)]\"\n   by (case_tac ys, simp_all)\n\nlemma zip_append_singleton:\n  \"\\<lbrakk>i = length xs; length xs < length ys\\<rbrakk>\n  \\<Longrightarrow> zip (xs @ [a]) ys = (zip xs ys) @ [(a,ys ! i)]\"\n  apply (induct xs)\n   apply (case_tac ys, simp_all)\n  apply (case_tac ys, simp_all)\n  apply (clarsimp simp: zip_append1 zip_take_length zip_singleton)\n  done\n\nlemma ran_map_of_zip:\n  \"\\<lbrakk>length xs = length ys; distinct xs\\<rbrakk> \\<Longrightarrow> ran (map_of (zip xs ys)) = set ys\"\n  by (induct rule: list_induct2, simp_all)\n\nlemma map_of_zip_range:\n  \"\\<lbrakk>length xs = length ys; distinct xs\\<rbrakk>\n  \\<Longrightarrow> (\\<lambda>x. (the (map_of (zip xs ys) x))) ` set xs = set ys\"\n  apply (clarsimp simp: image_def)\n  apply (subst ran_map_of_zip [symmetric, where xs=xs and ys=ys], simp+)\n  apply (clarsimp simp: ran_def)\n  apply (rule)\n   apply clarsimp\n   apply (frule_tac x=xa in map_of_zip_is_Some, clarsimp)\n   apply fast\n  apply (clarsimp simp: set_zip)\n  by (metis domI dom_map_of_zip nth_mem ranE ran_map_of_zip option.sel)\n\nlemma map_zip_fst:\n  \"length xs = length ys \\<Longrightarrow> map (\\<lambda>(x, y). f x) (zip xs ys) = map f xs\"\n  apply (induct xs arbitrary: ys)\n   apply simp\n  apply (case_tac ys, clarsimp+)\n  done\n\nlemma map_zip_fst':\n  \"length xs \\<le> length ys \\<Longrightarrow> map (\\<lambda>(x, y). f x) (zip xs ys) = map f xs\"\n  by (metis length_map map_fst_zip' map_zip_fst zip_map_fst_snd)\n\nlemma map_zip_snd:\n  \"length xs = length ys \\<Longrightarrow> map (\\<lambda>(x, y). f y) (zip xs ys) = map f ys\"\n  apply (induct ys arbitrary: xs)\n   apply simp\n  apply (case_tac xs, clarsimp+)\n  done\n\nlemma map_zip_snd':\n  \"length ys \\<le> length xs \\<Longrightarrow> map (\\<lambda>(x, y). f y) (zip xs ys) = map f ys\"\n  apply (induct ys arbitrary: xs)\n   apply simp\n  apply (case_tac xs, clarsimp+)\n  done\n\nlemma map_of_zip_tuple_in:\n  \"\\<lbrakk>(x, y) \\<in> set (zip xs ys); distinct xs\\<rbrakk> \\<Longrightarrow> map_of (zip xs ys) x = Some y\"\n  apply (induct xs arbitrary: ys, simp_all)\n  apply (case_tac ys, clarsimp+)\n  apply (rule conjI)\n   apply (metis in_set_zipE)\n  apply clarsimp\n  done\n\nlemma in_set_zip1:\n  \"(x, y) \\<in> set (zip xs ys) \\<Longrightarrow> x \\<in> set xs\"\n  by (metis in_set_zipE)\n\nlemma in_set_zip2:\n  \"(x, y) \\<in> set (zip xs ys) \\<Longrightarrow> y \\<in> set ys\"\n  by (metis in_set_zipE)\n\nlemma map_zip_snd_take:\n  \"map (\\<lambda>(x, y). f y) (zip xs ys) = map f (take (length xs) ys)\"\n  apply (subst map_zip_snd' [symmetric, where xs=xs and ys=\"take (length xs) ys\"])\n   apply simp\n  apply (subst zip_take_length [symmetric], simp)\n  done\n\nlemma map_of_zip_is_index:\n  \"\\<lbrakk>length xs = length ys; x \\<in> set xs\\<rbrakk>\n  \\<Longrightarrow> \\<exists>i. (map_of (zip xs ys)) x = Some (ys ! i)\"\n  apply (induct rule: list_induct2, simp_all)\n  apply (rule conjI)\n   apply clarsimp\n   apply (metis nth_Cons_0)\n  apply clarsimp\n  apply (metis nth_Cons_Suc)\n  done\n\nlemma map_of_zip_take_update:\n  \"\\<lbrakk>i < length xs; length xs \\<le> length ys; distinct xs\\<rbrakk>\n  \\<Longrightarrow> map_of (zip (take i xs) ys)(xs ! i \\<mapsto> (ys ! i)) =\n      map_of (zip (take (Suc i) xs) ys)\"\n  apply (rule ext)\n  apply (case_tac \"x=xs ! i\", simp_all)\n   apply clarsimp\n   apply (rule map_of_is_SomeI[symmetric])\n    apply (simp add: map_fst_zip')\n   apply (simp add: set_zip)\n   apply (rule_tac x=i in exI)\n   apply clarsimp\n  apply (clarsimp simp: take_Suc_conv_app_nth zip_append_singleton map_add_def\n                 split: option.splits)\n  done\n\n(* A weaker version of map_of_zip_is_Some (from HOL). *)\nlemma map_of_zip_is_Some':\n  \"length xs \\<le> length ys \\<Longrightarrow> (x \\<in> set xs) = (\\<exists>y. map_of (zip xs ys) x = Some y)\"\n  apply (subst zip_take_length[symmetric])\n  apply (rule map_of_zip_is_Some)\n  by (metis length_take min_absorb2)\n\nlemma map_of_zip_inj:\n  \"\\<lbrakk>distinct xs; distinct ys; length xs = length ys\\<rbrakk>\n    \\<Longrightarrow> inj_on (\\<lambda>x. (the (map_of (zip xs ys) x))) (set xs)\"\n  apply (clarsimp simp: inj_on_def)\n  apply (subst (asm) map_of_zip_is_Some, assumption)+\n  apply clarsimp\n  apply (clarsimp simp: set_zip)\n  by (metis nth_eq_iff_index_eq)\n\nlemma map_of_zip_inj':\n  \"\\<lbrakk>distinct xs; distinct ys; length xs \\<le> length ys\\<rbrakk>\n    \\<Longrightarrow> inj_on (\\<lambda>x. (the (map_of (zip xs ys) x))) (set xs)\"\n  apply (subst zip_take_length[symmetric])\n  apply (erule map_of_zip_inj, simp)\n  by (metis length_take min_absorb2)\n\nlemma list_all_nth:\n  \"\\<lbrakk>list_all P xs; i < length xs\\<rbrakk> \\<Longrightarrow> P (xs ! i)\"\n  by (metis list_all_length)\n\nlemma list_all_update:\n  \"\\<lbrakk>list_all P xs; i < length xs; \\<And>x. P x \\<Longrightarrow> P (f x)\\<rbrakk>\n  \\<Longrightarrow> list_all P (xs [i := f (xs ! i)])\"\n  by (metis length_list_update list_all_length nth_list_update)\n\nlemma list_allI:\n  \"\\<lbrakk>list_all P xs; \\<And>x. P x \\<Longrightarrow> P' x\\<rbrakk> \\<Longrightarrow> list_all P' xs\"\n  by (metis list_all_length)\n\nlemma list_all_imp_filter:\n  \"list_all (\\<lambda>x. f x \\<longrightarrow> g x) xs\n  = list_all (\\<lambda>x. g x) [x\\<leftarrow>xs . f x]\"\n  by (fastforce simp: Ball_set_list_all[symmetric])\n\nlemma list_all_imp_filter2:\n  \"list_all (\\<lambda>x. f x \\<longrightarrow> g x) xs\n  = list_all (\\<lambda>x. \\<not>f x) [x\\<leftarrow>xs . (\\<lambda>x. \\<not>g x) x]\"\n  by (fastforce simp: Ball_set_list_all[symmetric])\n\nlemma list_all_imp_chain:\n  \"\\<lbrakk>list_all (\\<lambda>x. f x \\<longrightarrow> g x) xs; list_all (\\<lambda>x. f' x \\<longrightarrow> f x) xs\\<rbrakk>\n  \\<Longrightarrow>\n   list_all (\\<lambda>x. f' x \\<longrightarrow> g x) xs\"\n  by (clarsimp simp: Ball_set_list_all [symmetric])\n\n(***********************\n * distinct_sets rules *\n ***********************)\n\nlemma distinct_sets_union_sub:\n  \"\\<lbrakk>x \\<in> A; distinct_sets [A,B]\\<rbrakk> \\<Longrightarrow> A \\<union> B - {x} = A - {x} \\<union> B\"\n  by (auto simp: distinct_sets_def)\n\nlemma distinct_sets_append:\n  \"distinct_sets (xs @ ys) \\<Longrightarrow> distinct_sets xs \\<and> distinct_sets ys\"\n  apply (subst distinct_sets_prop)+\n  apply (subst (asm) distinct_sets_prop)\n  apply (subst (asm) distinct_prop_append)\n  apply clarsimp\n  done\n\nlemma distinct_sets_append1:\n  \"distinct_sets (xs @ ys) \\<Longrightarrow> distinct_sets xs\"\n  by (drule distinct_sets_append, simp)\n\n\nlemma distinct_sets_append2:\n  \"distinct_sets (xs @ ys) \\<Longrightarrow> distinct_sets ys\"\n  by (drule distinct_sets_append, simp)\n\nlemma distinct_sets_append_Cons:\n  \"distinct_sets (xs @ a # ys) \\<Longrightarrow> distinct_sets (xs @ ys)\"\n  apply (subst distinct_sets_prop)+\n  apply (subst (asm) distinct_sets_prop)\n  apply (subst distinct_prop_append)\n  apply (subst (asm) distinct_prop_append)\n  apply clarsimp\n  done\n\nlemma distinct_sets_append_Cons_disjoint:\n  \"distinct_sets (xs @ a # ys) \\<Longrightarrow>  a \\<inter> \\<Union>set xs = {} \"\n  apply (subst (asm) distinct_sets_prop)\n  apply (subst (asm) distinct_prop_append)\n  apply (subst Int_commute)\n  apply (subst Union_disjoint)\n  apply clarsimp\n  done\n\nlemma distinct_prop_take:\n  \"\\<lbrakk>distinct_prop P xs; i < length xs\\<rbrakk>\n \\<Longrightarrow> distinct_prop P (take i xs)\"\n  by (metis take_is_prefixeq distinct_prop_prefixE)\n\nlemma distinct_sets_take:\n  \"\\<lbrakk>distinct_sets xs; i < length xs\\<rbrakk>\n \\<Longrightarrow> distinct_sets (take i xs)\"\n  by (simp add: distinct_sets_prop distinct_prop_take)\n\nlemma distinct_prop_take_Suc:\n  \"\\<lbrakk>distinct_prop P xs; i < length xs\\<rbrakk>\n \\<Longrightarrow> distinct_prop P (take (Suc i) xs)\"\n  by (metis distinct_prop_take not_less take_all)\n\nlemma distinct_sets_take_Suc:\n  \"\\<lbrakk>distinct_sets xs; i < length xs\\<rbrakk>\n \\<Longrightarrow> distinct_sets (take (Suc i) xs)\"\n  by (simp add: distinct_sets_prop distinct_prop_take_Suc)\n\nlemma distinct_prop_rev:\n  \"distinct_prop P (rev xs) = distinct_prop (\\<lambda>y x. P x y) xs\"\n  apply (induct xs)\n   apply clarsimp\n  apply clarsimp\n  apply rule\n   apply (subst (asm) distinct_prop_append, simp)\n  apply (subst distinct_prop_append, simp)\n  done\n\nlemma distinct_sets_rev [simp]:\n  \"distinct_sets (rev xs) = distinct_sets xs\"\n  apply (unfold distinct_sets_prop)\n  apply (subst distinct_prop_rev)\n  apply (subst Int_commute)\n  apply clarsimp\n  done\n\nlemma distinct_sets_drop:\n  \"\\<lbrakk>distinct_sets xs; i < length xs\\<rbrakk>\n \\<Longrightarrow> distinct_sets (drop i xs)\"\n  apply (case_tac \"i=0\", simp)\n  apply (subst distinct_sets_rev [symmetric])\n  apply (subst rev_drop)\n  apply (subst distinct_sets_take, simp_all)\n  done\n\nlemma distinct_sets_drop_Suc:\n  \"\\<lbrakk>distinct_sets xs; i < length xs\\<rbrakk>\n \\<Longrightarrow> distinct_sets (drop (Suc i) xs)\"\n  apply (subst distinct_sets_rev [symmetric])\n  apply (subst rev_drop)\n  apply (subst distinct_sets_take, simp_all)\n  done\n\nlemma distinct_sets_take_nth:\n  \"\\<lbrakk>distinct_sets xs; i < length xs; x \\<in> set (take i xs)\\<rbrakk> \\<Longrightarrow> x \\<inter> xs ! i = {}\"\n  apply (drule (1) distinct_sets_take_Suc)\n  apply (subst (asm) take_Suc_conv_app_nth, assumption)\n  apply (unfold distinct_sets_prop)\n  apply (subst (asm) distinct_prop_append)\n  apply clarsimp\n  done\n\nlemma distinct_sets_drop_nth:\n  \"\\<lbrakk>distinct_sets xs; i < length xs; x \\<in> set (drop (Suc i) xs)\\<rbrakk> \\<Longrightarrow> x \\<inter> xs ! i = {}\"\n  apply (drule (1) distinct_sets_drop)\n  apply (subst (asm) drop_Suc_nth, assumption)\n  apply fastforce\n  done\n\nlemma distinct_sets_append_distinct:\n  \"\\<lbrakk>x \\<in> set xs; y \\<in> set ys; distinct_sets (xs @ ys)\\<rbrakk>\n  \\<Longrightarrow> x \\<inter> y = {}\"\n  apply (unfold distinct_sets_prop)\n  apply (clarsimp simp: distinct_prop_append)\n  done\n\nlemma distinct_sets_update:\n \"\\<lbrakk>a \\<subseteq> xs ! i; distinct_sets xs; i < length xs\\<rbrakk>\n  \\<Longrightarrow> distinct_sets (xs[i := a])\"\n  apply (subst distinct_sets_prop)\n  apply (subst (asm) distinct_sets_prop)\n  apply (subst upd_conv_take_nth_drop)\n   apply simp\n  apply (subst distinct_prop_append)\n  apply (intro conjI)\n    apply (erule (1) distinct_prop_take)\n   apply (rule conjI|clarsimp)+\n    apply (fold distinct_sets_prop)\n    apply (drule (1) distinct_sets_drop)\n    apply (subst (asm) drop_Suc_nth, assumption)\n    apply clarsimp\n    apply blast\n   apply (drule (1) distinct_sets_drop)\n   apply (subst (asm) drop_Suc_nth, assumption)\n   apply clarsimp\n  apply clarsimp\n  apply rule\n   apply (drule (2) distinct_sets_take_nth)\n   apply blast\n  apply clarsimp\n  apply (thin_tac \"P \\<subseteq> Q\" for P Q)\n  apply (subst (asm) id_take_nth_drop, assumption)\n  apply (drule distinct_sets_append_Cons)\n  apply (erule (2) distinct_sets_append_distinct)\n  done\n\n\nlemma distinct_sets_map_update:\n  \"\\<lbrakk>distinct_sets (map f xs); i < length xs; f a \\<subseteq> f(xs ! i)\\<rbrakk>\n  \\<Longrightarrow> distinct_sets (map f (xs[i := a]))\"\n  by (metis distinct_sets_update length_map map_update nth_map)\n\nlemma Union_list_update:\n  \"\\<lbrakk>i < length xs; distinct_sets (map f xs)\\<rbrakk>\n  \\<Longrightarrow>\n   (\\<Union>x\\<in>set (xs [i := a]). f x)\n = (\\<Union>x\\<in>set xs. f x) - f (xs ! i) \\<union> f a\"\n  apply (induct xs arbitrary: i)\n   apply clarsimp\n  apply clarsimp\n  apply (case_tac i)\n  apply clarsimp\n   apply fastforce\n  apply fastforce\n  done\n\nlemma if_fold:\"(if P then Q else if P then R else S) = (if P then Q else S)\"\n  by presburger\n\nlemma fold_and_false[simp]:\"\\<not>(fold (op \\<and>) xs False)\"\n  apply clarsimp\n  apply (induct xs)\n   apply simp\n  apply simp\n  done\n\nlemma fold_and_true:\"fold (op \\<and>) xs True \\<Longrightarrow> \\<forall>i < length xs. xs ! i\"\n  apply clarsimp\n  apply (induct xs)\n   apply simp\n  apply (case_tac \"i = 0\"; simp)\n   apply (case_tac a; simp)\n  apply (case_tac a; simp)\n  done\n\nlemma fold_or_true[simp]:\"fold (op \\<or>) xs True\"\n  by (induct xs, simp+)\n\nlemma fold_or_false:\"\\<not>(fold (op \\<or>) xs False) \\<Longrightarrow> \\<forall>i < length xs. \\<not>(xs ! i)\"\n  apply (induct xs, simp+)\n  apply (case_tac a, simp+)\n  apply (rule allI, case_tac \"i = 0\", simp+)\n  done\n\nlemma fst_enumerate:\"i < length xs \\<Longrightarrow> fst (enumerate n xs ! i) = i + n\"\n  by (metis add.commute fst_conv nth_enumerate_eq)\n\nlemma snd_enumerate:\"i < length xs \\<Longrightarrow> snd (enumerate n xs ! i) = xs ! i\"\n  by (metis nth_enumerate_eq snd_conv)\n\nlemma pair_unpack:\"((a, b) = x) = (a = fst x \\<and> b = snd x)\"\n  by fastforce\n\nlemma enumerate_member:\"i < length xs \\<Longrightarrow> (n + i, xs ! i) \\<in> set (enumerate n xs)\"\n  apply (subgoal_tac \"(n + i, xs ! i) = enumerate n xs ! i\")\n   apply clarsimp\n  apply (subst pair_unpack)\n  apply (rule conjI)\n   apply (simp add:fst_enumerate)\n  apply (simp add:snd_enumerate)\n  done\n\nend\n", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/lib/DistinctPropLemmaBucket.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5273165085228825, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.29238142966199177}}
{"text": "(*  Title:      HOL/Auth/Guard/Guard_Shared.thy\n    Author:     Frederic Blanqui, University of Cambridge Computer Laboratory\n    Copyright   2002  University of Cambridge\n*)\n\nsection\\<open>lemmas on guarded messages for protocols with symmetric keys\\<close>\n\ntheory Guard_Shared imports Guard GuardK \"../Shared\" begin\n\nsubsection\\<open>Extensions to Theory \\<open>Shared\\<close>\\<close>\n\ndeclare initState.simps [simp del]\n\nsubsubsection\\<open>a little abbreviation\\<close>\n\nabbreviation\n  Ciph :: \"agent => msg => msg\" where\n  \"Ciph A X == Crypt (shrK A) X\"\n\nsubsubsection\\<open>agent associated to a key\\<close>\n\ndefinition agt :: \"key => agent\" where\n\"agt K == @A. K = shrK A\"\n\nlemma agt_shrK [simp]: \"agt (shrK A) = A\"\nby (simp add: agt_def)\n\nsubsubsection\\<open>basic facts about @{term initState}\\<close>\n\nlemma no_Crypt_in_parts_init [simp]: \"Crypt K X ~:parts (initState A)\"\nby (cases A, auto simp: initState.simps)\n\nlemma no_Crypt_in_analz_init [simp]: \"Crypt K X ~:analz (initState A)\"\nby auto\n\nlemma no_shrK_in_analz_init [simp]: \"A ~:bad\n==> Key (shrK A) ~:analz (initState Spy)\"\nby (auto simp: initState.simps)\n\nlemma shrK_notin_initState_Friend [simp]: \"A ~= Friend C\n==> Key (shrK A) ~: parts (initState (Friend C))\"\nby (auto simp: initState.simps)\n\nlemma keyset_init [iff]: \"keyset (initState A)\"\nby (cases A, auto simp: keyset_def initState.simps)\n\nsubsubsection\\<open>sets of symmetric keys\\<close>\n\ndefinition shrK_set :: \"key set => bool\" where\n\"shrK_set Ks == ALL K. K:Ks --> (EX A. K = shrK A)\"\n\nlemma in_shrK_set: \"[| shrK_set Ks; K:Ks |] ==> EX A. K = shrK A\"\nby (simp add: shrK_set_def)\n\nlemma shrK_set1 [iff]: \"shrK_set {shrK A}\"\nby (simp add: shrK_set_def)\n\nlemma shrK_set2 [iff]: \"shrK_set {shrK A, shrK B}\"\nby (simp add: shrK_set_def)\n\nsubsubsection\\<open>sets of good keys\\<close>\n\ndefinition good :: \"key set => bool\" where\n\"good Ks == ALL K. K:Ks --> agt K ~:bad\"\n\nlemma in_good: \"[| good Ks; K:Ks |] ==> agt K ~:bad\"\nby (simp add: good_def)\n\nlemma good1 [simp]: \"A ~:bad ==> good {shrK A}\"\nby (simp add: good_def)\n\nlemma good2 [simp]: \"[| A ~:bad; B ~:bad |] ==> good {shrK A, shrK B}\"\nby (simp add: good_def)\n\n\nsubsection\\<open>Proofs About Guarded Messages\\<close>\n\nsubsubsection\\<open>small hack\\<close>\n\nlemma shrK_is_invKey_shrK: \"shrK A = invKey (shrK A)\"\nby simp\n\nlemmas shrK_is_invKey_shrK_substI = shrK_is_invKey_shrK [THEN ssubst]\n\nlemmas invKey_invKey_substI = invKey [THEN ssubst]\n\nlemma \"Nonce n:parts {X} ==> Crypt (shrK A) X:guard n {shrK A}\"\napply (rule shrK_is_invKey_shrK_substI, rule invKey_invKey_substI)\nby (rule Guard_Nonce, simp+)\n\nsubsubsection\\<open>guardedness results on nonces\\<close>\n\nlemma guard_ciph [simp]: \"shrK A:Ks ==> Ciph A X:guard n Ks\"\nby (rule Guard_Nonce, simp)\n\nlemma guardK_ciph [simp]: \"shrK A:Ks ==> Ciph A X:guardK n Ks\"\nby (rule Guard_Key, simp)\n\nlemma Guard_init [iff]: \"Guard n Ks (initState B)\"\nby (induct B, auto simp: Guard_def initState.simps)\n\nlemma Guard_knows_max': \"Guard n Ks (knows_max' C evs)\n==> Guard n Ks (knows_max C evs)\"\nby (simp add: knows_max_def)\n\nlemma Nonce_not_used_Guard_spies [dest]: \"Nonce n ~:used evs\n==> Guard n Ks (spies evs)\"\nby (auto simp: Guard_def dest: not_used_not_known parts_sub)\n\nlemma Nonce_not_used_Guard [dest]: \"[| evs:p; Nonce n ~:used evs;\nGets_correct p; one_step p |] ==> Guard n Ks (knows (Friend C) evs)\"\nby (auto simp: Guard_def dest: known_used parts_trans)\n\nlemma Nonce_not_used_Guard_max [dest]: \"[| evs:p; Nonce n ~:used evs;\nGets_correct p; one_step p |] ==> Guard n Ks (knows_max (Friend C) evs)\"\nby (auto simp: Guard_def dest: known_max_used parts_trans)\n\nlemma Nonce_not_used_Guard_max' [dest]: \"[| evs:p; Nonce n ~:used evs;\nGets_correct p; one_step p |] ==> Guard n Ks (knows_max' (Friend C) evs)\"\napply (rule_tac H=\"knows_max (Friend C) evs\" in Guard_mono)\nby (auto simp: knows_max_def)\n\nsubsubsection\\<open>guardedness results on keys\\<close>\n\nlemma GuardK_init [simp]: \"n ~:range shrK ==> GuardK n Ks (initState B)\"\nby (induct B, auto simp: GuardK_def initState.simps)\n\nlemma GuardK_knows_max': \"[| GuardK n A (knows_max' C evs); n ~:range shrK |]\n==> GuardK n A (knows_max C evs)\"\nby (simp add: knows_max_def)\n\nlemma Key_not_used_GuardK_spies [dest]: \"Key n ~:used evs\n==> GuardK n A (spies evs)\"\nby (auto simp: GuardK_def dest: not_used_not_known parts_sub)\n\nlemma Key_not_used_GuardK [dest]: \"[| evs:p; Key n ~:used evs;\nGets_correct p; one_step p |] ==> GuardK n A (knows (Friend C) evs)\"\nby (auto simp: GuardK_def dest: known_used parts_trans)\n\nlemma Key_not_used_GuardK_max [dest]: \"[| evs:p; Key n ~:used evs;\nGets_correct p; one_step p |] ==> GuardK n A (knows_max (Friend C) evs)\"\nby (auto simp: GuardK_def dest: known_max_used parts_trans)\n\nlemma Key_not_used_GuardK_max' [dest]: \"[| evs:p; Key n ~:used evs;\nGets_correct p; one_step p |] ==> GuardK n A (knows_max' (Friend C) evs)\"\napply (rule_tac H=\"knows_max (Friend C) evs\" in GuardK_mono)\nby (auto simp: knows_max_def)\n\nsubsubsection\\<open>regular protocols\\<close>\n\ndefinition regular :: \"event list set => bool\" where\n\"regular p == ALL evs A. evs:p --> (Key (shrK A):parts (spies evs)) = (A:bad)\"\n\nlemma shrK_parts_iff_bad [simp]: \"[| evs:p; regular p |] ==>\n(Key (shrK A):parts (spies evs)) = (A:bad)\"\nby (auto simp: regular_def)\n\nlemma shrK_analz_iff_bad [simp]: \"[| evs:p; regular p |] ==>\n(Key (shrK A):analz (spies evs)) = (A:bad)\"\nby auto\n\nlemma Guard_Nonce_analz: \"[| Guard n Ks (spies evs); evs:p;\nshrK_set Ks; good Ks; regular p |] ==> Nonce n ~:analz (spies evs)\"\napply (clarify, simp only: knows_decomp)\napply (drule Guard_invKey_keyset, simp+, safe)\napply (drule in_good, simp)\napply (drule in_shrK_set, simp+, clarify)\napply (frule_tac A=A in shrK_analz_iff_bad)\nby (simp add: knows_decomp)+\n\nlemma GuardK_Key_analz:\n  assumes \"GuardK n Ks (spies evs)\" \"evs \\<in> p\" \"shrK_set Ks\"\n    \"good Ks\" \"regular p\" \"n \\<notin> range shrK\"\n  shows \"Key n \\<notin> analz (spies evs)\"\nproof (rule ccontr)\n  assume \"\\<not> Key n \\<notin> analz (knows Spy evs)\"\n  then have *: \"Key n \\<in> analz (spies' evs \\<union> initState Spy)\"\n    by (simp add: knows_decomp)\n  from \\<open>GuardK n Ks (spies evs)\\<close>\n  have \"GuardK n Ks (spies' evs \\<union> initState Spy)\"\n    by (simp add: knows_decomp)  \n  then have \"GuardK n Ks (spies' evs)\"\n    and \"finite (spies' evs)\" \"keyset (initState Spy)\"\n    by simp_all\n  moreover have \"Key n \\<notin> initState Spy\"\n    using \\<open>n \\<notin> range shrK\\<close> by (simp add: image_iff initState_Spy)\n  ultimately obtain K\n    where \"K \\<in> Ks\" and **: \"Key K \\<in> analz (spies' evs \\<union> initState Spy)\"\n    using * by (auto dest: GuardK_invKey_keyset)\n  from \\<open>K \\<in> Ks\\<close> and \\<open>good Ks\\<close> have \"agt K \\<notin> bad\"\n    by (auto dest: in_good)\n  from \\<open>K \\<in> Ks\\<close> \\<open>shrK_set Ks\\<close> obtain A\n    where \"K = shrK A\"\n    by (auto dest: in_shrK_set)\n  then have \"agt K \\<in> bad\"\n    using ** \\<open>evs \\<in> p\\<close> \\<open>regular p\\<close> shrK_analz_iff_bad [of evs p \"agt K\"]\n    by (simp add: knows_decomp)\n  with \\<open>agt K \\<notin> bad\\<close> show False by simp\nqed\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/HOL/Auth/Guard/Guard_Shared.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.29214426401641486}}
{"text": "(*  Title:      JinjaThreads/MM/JMM_Type.thy\n    Author:     Andreas Lochbihler\n*)\n\nsection \\<open>JMM heap implementation 1\\<close>\n\ntheory JMM_Type\nimports \n  \"../Common/ExternalCallWF\"\n  \"../Common/ConformThreaded\"\n  JMM_Heap\nbegin\n\nsubsection \\<open>Definitions\\<close>\n\ntext \\<open>\n  The JMM heap only stores type information.\n\\<close>\n\ntype_synonym 'addr JMM_heap = \"'addr \\<rightharpoonup> htype\"\n\ntranslations (type) \"'addr JMM_heap\" <= (type) \"'addr \\<Rightarrow> htype option\"\n\nabbreviation jmm_empty :: \"'addr JMM_heap\" where \"jmm_empty == Map.empty\"\n\ndefinition jmm_allocate :: \"'addr JMM_heap \\<Rightarrow> htype \\<Rightarrow> ('addr JMM_heap \\<times> 'addr) set\"\nwhere \"jmm_allocate h hT = (\\<lambda>a. (h(a \\<mapsto> hT), a)) ` {a. h a = None}\"\n\ndefinition jmm_typeof_addr :: \"'addr JMM_heap \\<Rightarrow> 'addr \\<rightharpoonup> htype\"\nwhere \"jmm_typeof_addr h = h\"\n\ndefinition jmm_heap_read :: \"'addr JMM_heap \\<Rightarrow> 'addr \\<Rightarrow> addr_loc \\<Rightarrow> 'addr val \\<Rightarrow> bool\"\nwhere \"jmm_heap_read h a ad v = True\"\n\ncontext\n  notes [[inductive_internals]]\nbegin\n\ninductive jmm_heap_write :: \"'addr JMM_heap \\<Rightarrow> 'addr \\<Rightarrow> addr_loc \\<Rightarrow> 'addr val \\<Rightarrow> 'addr JMM_heap \\<Rightarrow> bool\"\nwhere \"jmm_heap_write h a ad v h\"\n\nend\n\ndefinition jmm_hconf :: \"'m prog \\<Rightarrow> 'addr JMM_heap \\<Rightarrow> bool\" (\"_ \\<turnstile>jmm _ \\<surd>\" [51,51] 50)\nwhere \"P \\<turnstile>jmm h \\<surd> \\<longleftrightarrow> ty_of_htype ` ran h \\<subseteq> {T. is_type P T}\"\n\ndefinition jmm_allocated :: \"'addr JMM_heap \\<Rightarrow> 'addr set\"\nwhere \"jmm_allocated h = dom (jmm_typeof_addr h)\"\n\ndefinition jmm_spurious_wakeups :: bool\nwhere \"jmm_spurious_wakeups = True\"\n\nlemmas jmm_heap_ops_defs =\n  jmm_allocate_def jmm_typeof_addr_def \n  jmm_heap_read_def jmm_heap_write_def\n  jmm_allocated_def jmm_spurious_wakeups_def\n\ntype_synonym 'addr thread_id = \"'addr\"\n\nabbreviation (input) addr2thread_id :: \"'addr \\<Rightarrow> 'addr thread_id\"\nwhere \"addr2thread_id \\<equiv> \\<lambda>x. x\"\n\nabbreviation (input) thread_id2addr :: \"'addr thread_id \\<Rightarrow> 'addr\"\nwhere \"thread_id2addr \\<equiv> \\<lambda>x. x\"\n\ninterpretation jmm: heap_base\n  addr2thread_id thread_id2addr\n  jmm_spurious_wakeups\n  jmm_empty jmm_allocate jmm_typeof_addr jmm_heap_read jmm_heap_write \n.\n\nnotation jmm.hext  (\"_ \\<unlhd>jmm _\" [51,51] 50)\nnotation jmm.conf (\"_,_ \\<turnstile>jmm _ :\\<le> _\"  [51,51,51,51] 50)\nnotation jmm.addr_loc_type (\"_,_ \\<turnstile>jmm _@_ : _\" [50, 50, 50, 50, 50] 51)\nnotation jmm.confs (\"_,_ \\<turnstile>jmm _ [:\\<le>] _\"  [51,51,51,51] 50)\nnotation jmm.tconf (\"_,_ \\<turnstile>jmm _ \\<surd>t\" [51,51,51] 50)\n\ntext \\<open>Now a variation of the JMM with a different read operation that permits to read only type-conformant values\\<close>\n\ninterpretation jmm': heap_base\n  addr2thread_id thread_id2addr\n  jmm_spurious_wakeups\n  jmm_empty jmm_allocate jmm_typeof_addr \"jmm.heap_read_typed P\" jmm_heap_write\n  for P .\n\nnotation jmm'.hext (\"_ \\<unlhd>jmm'' _\" [51,51] 50)\nnotation jmm'.conf (\"_,_ \\<turnstile>jmm'' _ :\\<le> _\"  [51,51,51,51] 50)\nnotation jmm'.addr_loc_type (\"_,_ \\<turnstile>jmm'' _@_ : _\" [50, 50, 50, 50, 50] 51)\nnotation jmm'.confs (\"_,_ \\<turnstile>jmm'' _ [:\\<le>] _\"  [51,51,51,51] 50)\nnotation jmm'.tconf (\"_,_ \\<turnstile>jmm'' _ \\<surd>t\" [51,51,51] 50)\n\nsubsection \\<open>Heap locale interpretations\\<close>\n\nsubsection \\<open>Locale \\<open>heap\\<close>\\<close>\n\nlemma jmm_heap: \"heap addr2thread_id thread_id2addr jmm_allocate jmm_typeof_addr jmm_heap_write P\"\nproof\n  fix h' a h hT\n  assume \"(h', a) \\<in> jmm_allocate h hT\"\n  thus \"jmm_typeof_addr h' a = \\<lfloor>hT\\<rfloor>\"\n    by(auto simp add: jmm_heap_ops_defs)\nnext\n  fix h' :: \"('addr :: addr) JMM_heap\" and h hT a\n  assume \"(h', a) \\<in> jmm_allocate h hT\"\n  thus \"h \\<unlhd>jmm h'\"\n    by(fastforce simp add: jmm_heap_ops_defs intro: jmm.hextI)\nnext\n  fix h a al v and h' :: \"('addr :: addr) JMM_heap\"\n  assume \"jmm_heap_write h a al v h'\"\n  thus \"h \\<unlhd>jmm h'\" by cases auto\nqed simp\n\ninterpretation jmm: heap\n  addr2thread_id thread_id2addr\n  jmm_spurious_wakeups\n  jmm_empty jmm_allocate jmm_typeof_addr jmm_heap_read jmm_heap_write\n  P\n  for P\nby(rule jmm_heap)\n\ndeclare jmm.typeof_addr_thread_id2_addr_addr2thread_id [simp del]\n\nlemmas jmm'_heap = jmm_heap\n\ninterpretation jmm': heap\n  addr2thread_id thread_id2addr\n  jmm_spurious_wakeups\n  jmm_empty jmm_allocate jmm_typeof_addr \"jmm.heap_read_typed P\" jmm_heap_write\n  P\n  for P\nby(rule jmm'_heap)\n\ndeclare jmm'.typeof_addr_thread_id2_addr_addr2thread_id [simp del]\n\nsubsection \\<open>Locale \\<open>heap_conf\\<close>\\<close>\n\ninterpretation jmm: heap_conf_base\n  addr2thread_id thread_id2addr\n  jmm_spurious_wakeups\n  jmm_empty jmm_allocate jmm_typeof_addr jmm_heap_read jmm_heap_write \"jmm_hconf P\"\n  P\n  for P .\n\nabbreviation (input) jmm'_hconf :: \"'m prog \\<Rightarrow> 'addr JMM_heap \\<Rightarrow> bool\" (\"_ \\<turnstile>jmm'' _ \\<surd>\" [51,51] 50)\nwhere \"jmm'_hconf == jmm_hconf\"\n\ninterpretation jmm': heap_conf_base\n  addr2thread_id thread_id2addr\n  jmm_spurious_wakeups\n  jmm_empty jmm_allocate jmm_typeof_addr \"jmm.heap_read_typed P\" jmm_heap_write \"jmm'_hconf P\"\n  P\n  for P .\n\nabbreviation jmm_heap_read_typeable :: \"('addr :: addr) itself \\<Rightarrow> 'm prog \\<Rightarrow> bool\"\nwhere \"jmm_heap_read_typeable tytok P \\<equiv> jmm.heap_read_typeable (jmm_hconf P :: 'addr JMM_heap \\<Rightarrow> bool) P\"\n\nabbreviation jmm'_heap_read_typeable :: \"('addr :: addr) itself \\<Rightarrow> 'm prog \\<Rightarrow> bool\"\nwhere \"jmm'_heap_read_typeable tytok P \\<equiv> jmm'.heap_read_typeable TYPE('m) P (jmm_hconf P :: 'addr JMM_heap \\<Rightarrow> bool) P\"\n\nlemma jmm_heap_read_typeable: \"jmm_heap_read_typeable tytok P\"\nby(rule jmm.heap_read_typeableI)(simp add: jmm_heap_read_def)\n\nlemma jmm'_heap_read_typeable: \"jmm'_heap_read_typeable tytok P\"\nby(rule jmm'.heap_read_typeableI)(auto simp add: jmm.heap_read_typed_def jmm_heap_read_def dest: jmm'.addr_loc_type_fun)\n\nlemma jmm_heap_conf:\n  \"heap_conf addr2thread_id thread_id2addr jmm_empty jmm_allocate jmm_typeof_addr jmm_heap_write (jmm_hconf P) P\"\nproof\n  show \"P \\<turnstile>jmm jmm_empty \\<surd>\"\n    by(simp add: jmm_hconf_def)\nnext\n  fix h a hT\n  assume \"jmm_typeof_addr h a = \\<lfloor>hT\\<rfloor>\" \"P \\<turnstile>jmm h \\<surd>\"\n  thus \"is_htype P hT\" by(auto simp add: jmm_hconf_def jmm_heap_ops_defs intro: ranI)\nnext\n  fix h' h hT a\n  assume \"(h', a) \\<in> jmm_allocate h hT\" \"P \\<turnstile>jmm h \\<surd>\" \"is_htype P hT\"\n  thus \"P \\<turnstile>jmm h' \\<surd>\"\n    by(fastforce simp add: jmm_hconf_def jmm_heap_ops_defs ran_def split: if_split_asm)\nnext\n  fix h a al v h' T\n  assume \"jmm_heap_write h a al v h'\" \"P \\<turnstile>jmm h \\<surd>\"\n    and \"jmm.addr_loc_type P h a al T\" and \"P,h \\<turnstile>jmm v :\\<le> T\"\n  thus \"P \\<turnstile>jmm h' \\<surd>\" by(cases) simp\nqed\n\ninterpretation jmm: heap_conf\n  addr2thread_id thread_id2addr\n  jmm_spurious_wakeups\n  jmm_empty jmm_allocate jmm_typeof_addr jmm_heap_read jmm_heap_write \"jmm_hconf P\"\n  P\n  for P\nby(rule jmm_heap_conf)\n\nlemmas jmm'_heap_conf = jmm_heap_conf\n\ninterpretation jmm': heap_conf\n  addr2thread_id thread_id2addr\n  jmm_spurious_wakeups\n  jmm_empty jmm_allocate jmm_typeof_addr \"jmm.heap_read_typed P\" jmm_heap_write \"jmm'_hconf P\"\n  P\n  for P\nby(rule jmm'_heap_conf)\n\nsubsection \\<open>Locale \\<open>heap_progress\\<close>\\<close>\n\nlemma jmm_heap_progress:\n  \"heap_progress addr2thread_id thread_id2addr jmm_empty jmm_allocate jmm_typeof_addr jmm_heap_read jmm_heap_write (jmm_hconf P) P\"\nproof\n  fix h a al T\n  assume \"P \\<turnstile>jmm h \\<surd>\"\n    and al: \"jmm.addr_loc_type P h a al T\"\n  show \"\\<exists>v. jmm_heap_read h a al v \\<and> P,h \\<turnstile>jmm v :\\<le> T\"\n    using jmm.defval_conf[of P h T] unfolding jmm_heap_ops_defs by blast\nnext\n  fix h a al T v\n  assume \"jmm.addr_loc_type P h a al T\"\n  show \"\\<exists>h'. jmm_heap_write h a al v h'\"\n    by(auto intro: jmm_heap_write.intros)\nqed\n\ninterpretation jmm: heap_progress\n  addr2thread_id thread_id2addr\n  jmm_spurious_wakeups\n  jmm_empty jmm_allocate jmm_typeof_addr jmm_heap_read jmm_heap_write \"jmm_hconf P\"\n  P\n  for P\nby(rule jmm_heap_progress)\n\nlemma jmm'_heap_progress:\n  \"heap_progress addr2thread_id thread_id2addr jmm_empty jmm_allocate jmm_typeof_addr (jmm.heap_read_typed P) jmm_heap_write (jmm'_hconf P) P\"\nproof\n  fix h a al T\n  assume \"P \\<turnstile>jmm' h \\<surd>\"\n    and al: \"jmm'.addr_loc_type P h a al T\"\n  thus \"\\<exists>v. jmm.heap_read_typed P h a al v \\<and> P,h \\<turnstile>jmm' v :\\<le> T\"\n    unfolding jmm.heap_read_typed_def jmm_heap_read_def\n    by(auto dest: jmm'.addr_loc_type_fun intro: jmm'.defval_conf)\nnext\n  fix h a al T v\n  assume \"jmm'.addr_loc_type P h a al T\"\n    and \"P,h \\<turnstile>jmm' v :\\<le> T\"\n  thus \"\\<exists>h'. jmm_heap_write h a al v h'\"\n    by(auto intro: jmm_heap_write.intros)\nqed\n\ninterpretation jmm': heap_progress\n  addr2thread_id thread_id2addr\n  jmm_spurious_wakeups\n  jmm_empty jmm_allocate jmm_typeof_addr \"jmm.heap_read_typed P\" jmm_heap_write \"jmm'_hconf P\"\n  P\n  for P\nby(rule jmm'_heap_progress)\n\nsubsection \\<open>Locale \\<open>heap_conf_read\\<close>\\<close>\n\nlemma jmm'_heap_conf_read:\n  \"heap_conf_read addr2thread_id thread_id2addr jmm_empty jmm_allocate jmm_typeof_addr (jmm.heap_read_typed P) jmm_heap_write (jmm'_hconf P) P\"\nby(rule jmm.heap_conf_read_heap_read_typed)\n\ninterpretation jmm': heap_conf_read\n  addr2thread_id thread_id2addr\n  jmm_spurious_wakeups\n  jmm_empty jmm_allocate jmm_typeof_addr \"jmm.heap_read_typed P\" jmm_heap_write \"jmm'_hconf P\"\n  P\n  for P\nby(rule jmm'_heap_conf_read)\n\ninterpretation jmm': heap_typesafe\n  addr2thread_id thread_id2addr\n  jmm_spurious_wakeups\n  jmm_empty jmm_allocate jmm_typeof_addr \"jmm.heap_read_typed P\" jmm_heap_write \"jmm'_hconf P\"\n  P\n  for P\n..\n\nsubsection \\<open>Locale \\<open>allocated_heap\\<close>\\<close>\n\nlemma jmm_allocated_heap: \n  \"allocated_heap addr2thread_id thread_id2addr jmm_empty jmm_allocate jmm_typeof_addr jmm_heap_write jmm_allocated P\"\nproof\n  show \"jmm_allocated jmm_empty = {}\" by(auto simp add: jmm_heap_ops_defs)\nnext\n  fix h' a h hT\n  assume \"(h', a) \\<in> jmm_allocate h hT\"\n  thus \"jmm_allocated h' = insert a (jmm_allocated h) \\<and> a \\<notin> jmm_allocated h\"\n    by(auto simp add: jmm_heap_ops_defs split: if_split_asm)\nnext\n  fix h a al v h'\n  assume \"jmm_heap_write h a al v h'\"\n  thus \"jmm_allocated h' = jmm_allocated h\" by cases simp\nqed\n\ninterpretation jmm: allocated_heap\n  addr2thread_id thread_id2addr\n  jmm_spurious_wakeups\n  jmm_empty jmm_allocate jmm_typeof_addr jmm_heap_read jmm_heap_write\n  jmm_allocated\n  P\n  for P\nby(rule jmm_allocated_heap)\n\nlemmas jmm'_allocated_heap = jmm_allocated_heap\n\ninterpretation jmm': allocated_heap\n  addr2thread_id thread_id2addr\n  jmm_spurious_wakeups\n  jmm_empty jmm_allocate jmm_typeof_addr \"jmm.heap_read_typed P\" jmm_heap_write\n  jmm_allocated\n  P\n  for P\nby(rule jmm'_allocated_heap)\n\nsubsection \\<open>Syntax translations\\<close>\n\nnotation jmm'.external_WT' (\"_,_ \\<turnstile>jmm'' (_\\<bullet>_'(_')) : _\" [50,0,0,0,50] 60)\n\nabbreviation jmm'_red_external :: \n  \"'m prog \\<Rightarrow> 'addr thread_id \\<Rightarrow> 'addr JMM_heap \\<Rightarrow> 'addr \\<Rightarrow> mname \\<Rightarrow> 'addr val list\n  \\<Rightarrow> ('addr :: addr, 'addr thread_id, 'addr JMM_heap) external_thread_action \n  \\<Rightarrow> 'addr extCallRet \\<Rightarrow> 'addr JMM_heap \\<Rightarrow> bool\"\nwhere \"jmm'_red_external P \\<equiv> jmm'.red_external (TYPE('m)) P P\"\n\nabbreviation jmm'_red_external_syntax :: \n  \"'m prog \\<Rightarrow> 'addr thread_id \\<Rightarrow> 'addr \\<Rightarrow> mname \\<Rightarrow> 'addr val list \\<Rightarrow> 'addr JMM_heap\n  \\<Rightarrow> ('addr :: addr, 'addr thread_id, 'addr JMM_heap) external_thread_action \n  \\<Rightarrow> 'addr extCallRet \\<Rightarrow> 'addr JMM_heap \\<Rightarrow> bool\"\n  (\"_,_ \\<turnstile>jmm'' (\\<langle>(_\\<bullet>_'(_')),/_\\<rangle>) -_\\<rightarrow>ext (\\<langle>(_),/(_)\\<rangle>)\" [50, 0, 0, 0, 0, 0, 0, 0, 0] 51)\nwhere\n  \"P,t \\<turnstile>jmm' \\<langle>a\\<bullet>M(vs), h\\<rangle> -ta\\<rightarrow>ext \\<langle>va, h'\\<rangle> \\<equiv> jmm'_red_external P t h a M vs ta va h'\"\n\nabbreviation jmm'_red_external_aggr :: \n  \"'m prog \\<Rightarrow> 'addr thread_id \\<Rightarrow> 'addr \\<Rightarrow> mname \\<Rightarrow> 'addr val list \\<Rightarrow> 'addr JMM_heap \n    \\<Rightarrow> (('addr :: addr, 'addr thread_id, 'addr JMM_heap) external_thread_action \\<times> 'addr extCallRet \\<times> 'addr JMM_heap) set\"\nwhere \"jmm'_red_external_aggr P \\<equiv> jmm'.red_external_aggr TYPE('m) P P\"\n\nabbreviation jmm'_heap_copy_loc :: \n  \"'m prog \\<Rightarrow> 'addr \\<Rightarrow> 'addr \\<Rightarrow> addr_loc \\<Rightarrow> 'addr JMM_heap\n  \\<Rightarrow> ('addr :: addr, 'addr thread_id) obs_event list \\<Rightarrow> 'addr JMM_heap \\<Rightarrow> bool\"\nwhere \"jmm'_heap_copy_loc \\<equiv> jmm'.heap_copy_loc TYPE('m)\"\n\nabbreviation jmm'_heap_copies :: \n  \"'m prog \\<Rightarrow> 'addr \\<Rightarrow> 'addr \\<Rightarrow> addr_loc list \\<Rightarrow> 'addr JMM_heap\n  \\<Rightarrow> ('addr :: addr, 'addr thread_id) obs_event list \\<Rightarrow> 'addr JMM_heap \\<Rightarrow> bool\"\nwhere \"jmm'_heap_copies \\<equiv> jmm'.heap_copies TYPE('m)\"\n\nabbreviation jmm'_heap_clone ::\n  \"'m prog \\<Rightarrow> 'addr JMM_heap \\<Rightarrow> 'addr \\<Rightarrow> 'addr JMM_heap\n  \\<Rightarrow> (('addr :: addr, 'addr thread_id) obs_event list \\<times> 'addr) option \\<Rightarrow> bool\"\nwhere \"jmm'_heap_clone P \\<equiv> jmm'.heap_clone TYPE('m) P P\"\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/JinjaThreads/MM/JMM_Type.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.29214426401641486}}
{"text": "theory Failures_TickTock_SeqComp\n\nimports\n  Failures_TickTock\nbegin\n\nlemma ttproc2F_SeqCompTT_failures_subseteq_SeqCompF:\n  assumes TTwf_P: \"TTwf P\" and TT0_P: \"TT0 P\" and TT1_P: \"TT1 P\"\n      and TTwf_Q: \"TTwf Q\" and TT0_Q: \"TT0 Q\" and TT1_Q: \"TT1 Q\"\n  shows \"fst (ttproc2F (P ;\\<^sub>C Q)) \\<subseteq>  fst ((ttproc2F P) ;\\<^sub>F (ttproc2F Q))\" \n  using assms unfolding ttproc2F_def SeqCompTT_def SeqCompF_def\nproof (auto)\n  fix a b s t\n  assume assm1:\"\\<forall>s t. a = s @ t \\<longrightarrow> (\\<forall>y. s @ [tick] = tt2T y \\<longrightarrow> y \\<notin> P) \\<or> (\\<forall>y. Some (t, b) = tt2F y \\<longrightarrow> y \\<notin> Q)\"\n    and  assm2:\"Some (a, b) = tt2F (s @ t)\" \n    and  assm3:\"s @ [[Tick]\\<^sub>E] \\<in> P\" \n    and  assm4:\"t \\<in> Q\"\n\n  have \"a = tt2T (s@t)\"\n    using Some_tt2F_imp_tt2T' assm2 by blast\n\n  have \"\\<exists>y. tt2F (s @ t) = tt2F y \\<and> y \\<lesssim>\\<^sub>C s\"\n    using assm1 assm2 assm3 assm4\n  proof (induct t arbitrary:s a b rule:rev_induct)\n    case Nil\n    then show ?case\n      apply (rule_tac x=\"s\" in exI, auto)\n      using tt_prefix_subset_refl by blast\n  next\n    case (snoc x t)\n    then show ?case\n      proof (cases x)\n        case (ObsEvent x1)\n        then have \"tt2F (s @ t @ [x]) = None\"\n          using snoc\n          by (metis Some_tt2F_concat_refusal append_is_Nil_conv last_appendR last_snoc ttobs.distinct(1))\n        then show ?thesis using snoc by auto\n      next\n        case (Ref x2)\n        then have \"[Tick]\\<^sub>E \\<notin> set s\" \"[Tock]\\<^sub>E \\<notin> set s\" \"\\<not>(\\<exists>R. [R]\\<^sub>R \\<in> set s)\"\n          using TTwf_P TTwf_concat_prefix_set_no_Tick snoc.prems(3) apply blast\n          using Some_tt2F_no_Tock snoc.prems(2) apply fastforce\n          using snoc Some_tt2F_no_prev_refusals Ref \n          by (metis (no_types) Some_tt2F_no_prev_refusals UnCI append.assoc set_append)\n        then have \"a = (tt2T s) @ (tt2T t)\"\n          by (smt Some_tt2F_concat_refusal append.assoc append_same_eq last_snoc snoc.prems(2) tt2T_concat_dist)\n\n        then have pp:\"(\\<forall>y. (tt2T s) @ [tick] = tt2T y \\<longrightarrow> y \\<notin> P) \\<or> (\\<forall>y. Some ((tt2T t), b) = tt2F y \\<longrightarrow> y \\<notin> Q)\"\n          using snoc by blast\n\n        have \"(tt2T s) @ [tick] = tt2T (s@[[Tick]\\<^sub>E])\"\n          by (simp add: \\<open>[Tick]\\<^sub>E \\<notin> set s\\<close> \\<open>[Tock]\\<^sub>E \\<notin> set s\\<close> \\<open>\\<nexists>R. [R]\\<^sub>R \\<in> set s\\<close> tt2T_concat_dist)\n\n        then have \"s @ [[Tick]\\<^sub>E] \\<notin> P \\<or> t @ [x] \\<notin> Q\"\n          using pp\n          by (smt Nil_is_append_conv Some_tt2F_concat_refusal Some_tt2F_no_Tock TTwf_Q TTwf_def UnCI last_appendR last_snoc set_append snoc.prems(2) snoc.prems(4) ttWF_tt2F_last_refusal_concat)\n          \n        then show ?thesis using snoc by auto\n      qed\n  qed\n  then show \"\\<exists>y. tt2F (s @ t) = tt2F y \\<and> y \\<in> P\"\n    by (meson TT1_P TT1_def assm3 tt_prefix_concat tt_prefix_imp_prefix_subset)\nqed\n\nlemma ttproc2F_SeqCompF_failures_subseteq_SeqCompTT:\n  assumes TTwf_P: \"TTwf P\" and TT0_P: \"TT0 P\" and TT1_P: \"TT1 P\"\n      and TTwf_Q: \"TTwf Q\" and TT0_Q: \"TT0 Q\" and TT1_Q: \"TT1 Q\"\n  shows \"fst ((ttproc2F P) ;\\<^sub>F (ttproc2F Q)) \\<subseteq> fst (ttproc2F (P ;\\<^sub>C Q))\" \n  using assms unfolding ttproc2F_def SeqCompTT_def SeqCompF_def\nproof (auto)\n  fix a b y\n  assume assm2:\"Some (a, b) = tt2F y\"\n   and   assm3:\"y \\<in> P\"\n  show \"\\<exists>ya. tt2F y = tt2F ya \\<and> (ya \\<in> P \\<and> (\\<forall>s. ya \\<noteq> s @ [[Tick]\\<^sub>E]) \\<or> (\\<exists>s. s @ [[Tick]\\<^sub>E] \\<in> P \\<and> (\\<exists>t. t \\<in> Q \\<and> ya = s @ t)))\"\n    using assm2 assm3 Some_tt2F_no_Tick by fastforce\nnext\n  fix b s t y ya\n  assume assm1:\"s @ [tick] = tt2T y\"\n  and    assm2:\"y \\<in> P\"\n  and    assm3:\"Some (t, b) = tt2F ya\"\n  and    assm4:\"ya \\<in> Q\"\n\n  obtain z where z:\"y = z@[[Tick]\\<^sub>E]\"\n    using assm1 assm2 tt2T_tick_exists_Cons by blast\n  \n  show \"\\<exists>y. Some (s @ t, b) = tt2F y \\<and> \n            (y \\<in> P \\<and> (\\<forall>s. y \\<noteq> s @ [[Tick]\\<^sub>E]) \\<or> (\\<exists>s. s @ [[Tick]\\<^sub>E] \\<in> P \\<and> (\\<exists>t. t \\<in> Q \\<and> y = s @ t)))\"\n    using assm1 assm2 assm3 assm4\n    apply (rule_tac x=\"z@ya\" in exI, auto simp add:z)\n    using Some_concat_extend Some_tt2F_imp_tt2T' Some_concat_extend' tt2T_tick_butlast by fastforce\nqed\n\nlemma ttproc2F_SeqCompTT_traces_subseteq_SeqCompF:\n  assumes TTwf_P: \"TTwf P\" and TT0_P: \"TT0 P\" and TT1_P: \"TT1 P\" \n      and TTwf_Q: \"TTwf Q\" and TT0_Q: \"TT0 Q\" and TT1_Q: \"TT1 Q\"\n  shows \"snd (ttproc2F (P ;\\<^sub>C Q)) \\<subseteq> snd ((ttproc2F P) ;\\<^sub>F (ttproc2F Q))\" \n  using assms unfolding ttproc2F_def SeqCompTT_def SeqCompF_def\nproof (auto)\n  fix y\n  assume assm1:\"\\<forall>s t. tt2T y = s @ t \\<longrightarrow> (\\<forall>y. s @ [tick] = tt2T y \\<longrightarrow> y \\<notin> P) \\<or> (\\<forall>y. t = tt2T y \\<longrightarrow> y \\<notin> Q)\"\n    and  assm2:\"y \\<in> P\"\n    and  assm3:\"\\<forall>s. y \\<noteq> s @ [[Tick]\\<^sub>E]\"\n    and  assm4:\"tick \\<in> set (tt2T y)\"\n  have ttWF_y:\"ttWF y\"\n    using TTwf_P TTwf_def assm2 by blast\n  have Tick_set:\"[Tick]\\<^sub>E \\<in> set y\"\n    using assm4 Tick_set_tt2T_in by blast\n\n  show \"False\"\n    using assm1 assm2 assm3 assm4\n  proof (cases \"y = []\")\n    case True\n    then show ?thesis using assm1 assm2 assm3 assm4 by auto\n  next\n    case False\n    then obtain xs where xs:\"y = xs@[[Tick]\\<^sub>E]\"\n      using False ttWF_y Tick_set Tick_set_ends_in_Tick by blast\n    then show ?thesis using assm3 by auto\n  qed\nnext\n  fix s t\n  assume assm1:\"\\<forall>sa ta. tt2T (s @ t) = sa @ ta \\<longrightarrow> (\\<forall>y. sa @ [tick] = tt2T y \\<longrightarrow> y \\<notin> P) \\<or> (\\<forall>y. ta = tt2T y \\<longrightarrow> y \\<notin> Q)\"\n    and  assm2:\"s @ [[Tick]\\<^sub>E] \\<in> P\"\n    and  assm3:\"t \\<in> Q\"\n    and  assm4:\"tick \\<in> set (tt2T (s @ t))\"\n  have \"[Tick]\\<^sub>E \\<notin> set s\"\n    using TTwf_P TTwf_concat_prefix_set_no_Tick assm2 by blast\n  then show \"False\"\n    using assm1 assm2 assm3 Tock_in_trace_Tick_no_Tick Tock_in_trace_Refusal_no_Tick\n    by (metis TTwf_P TTwf_def assm4 tt2T.simps(1) tt2T_concat_dist)\nnext\n  fix s t\n  assume assm1:\"\\<forall>sa ta. tt2T (s @ t) = sa @ ta \\<longrightarrow> (\\<forall>y. sa @ [tick] = tt2T y \\<longrightarrow> y \\<notin> P) \\<or> (\\<forall>y. ta = tt2T y \\<longrightarrow> y \\<notin> Q)\"\n    and  assm2:\"s @ [[Tick]\\<^sub>E] \\<in> P\"\n    and  assm3:\"t \\<in> Q\"\n  have \"[Tick]\\<^sub>E \\<notin> set s\"\n    using TTwf_P TTwf_concat_prefix_set_no_Tick assm2 by blast\n\n  text \\<open> It's basically by case analysis on whether Tock or Refs exist in s. \\<close>\n\n  show \"\\<exists>y. tt2T (s @ t) = tt2T y \\<and> y \\<in> P\"\n    using assm1 assm2 assm3\n    by (metis Ref_in_concat_lhs Tock_in_concat_lhs \\<open>[Tick]\\<^sub>E \\<notin> set s\\<close> tt2T.simps(1) tt2T_concat_dist)\nqed\n\nlemma\n  assumes \"tick \\<notin> set (tt2T y)\" \"ttWF y\" \"[Tock]\\<^sub>E \\<notin> set y\"\n  shows \"[Tick]\\<^sub>E \\<notin> set y\"\n  using assms apply (induct y rule:tt2T.induct, auto)\n  apply (smt hd_in_set list.distinct(1) list.inject list.sel(1) list.set_cases ttWF.elims(2) ttobs.distinct(1))\n  using ttWF.elims(2) by auto\n\nlemma ttproc2F_SeqCompF_traces_subseteq_SeqCompTT:\n  assumes TTwf_P: \"TTwf P\" and TT0_P: \"TT0 P\" and TT1_P: \"TT1 P\" \n      and TTwf_Q: \"TTwf Q\" and TT0_Q: \"TT0 Q\" and TT1_Q: \"TT1 Q\" \n  shows \"snd ((ttproc2F P) ;\\<^sub>F (ttproc2F Q)) \\<subseteq> snd (ttproc2F (P ;\\<^sub>C Q))\" \n  unfolding ttproc2F_def SeqCompTT_def SeqCompF_def\nproof (auto)\n  fix y x \n  assume assm1:\"tick \\<notin> set (tt2T y)\"\n  and    assm2:\"y \\<in> P\"\n  have \"\\<exists>ya. tt2T y = tt2T ya \\<and> (ya \\<lesssim>\\<^sub>C y \\<and> (\\<forall>s. ya \\<noteq> s @ [[Tick]\\<^sub>E]) \\<or> ya @ [[Tick]\\<^sub>E] \\<lesssim>\\<^sub>C y)\"\n    using assm1\n    apply (induct y rule:tt2T.induct, auto)\n       apply (metis (no_types, hide_lams) Cons_eq_append_conv tt2T.simps(2) tt_prefix_subset.simps(3) ttevent.distinct(3))\n      apply (metis (no_types, hide_lams) Cons_eq_append_conv tt2T.simps(2) tt_prefix_subset.simps(3) ttevent.distinct(3))\n  by (rule_tac x=\"[]\" in exI, auto)+\n  then show \"\\<exists>ya. tt2T y = tt2T ya \\<and> (ya \\<in> P \\<and> (\\<forall>s. ya \\<noteq> s @ [[Tick]\\<^sub>E]) \\<or> (\\<exists>s. s @ [[Tick]\\<^sub>E] \\<in> P \\<and> (\\<exists>t. t \\<in> Q \\<and> ya = s @ t)))\"\n    by (metis TT0_Q TT0_TT1_empty TT1_P TT1_Q TT1_def append.right_neutral assm2)\nnext\n  fix s y ya\n  assume assm1:\"s @ [tick] = tt2T y\"\n  and    assm2:\"y \\<in> P\"\n  and    assm3:\"ya \\<in> Q\"\n  then show \"\\<exists>y. s @ tt2T ya = tt2T y \\<and> (y \\<in> P \\<and> (\\<forall>s. y \\<noteq> s @ [[Tick]\\<^sub>E]) \\<or> (\\<exists>s. s @ [[Tick]\\<^sub>E] \\<in> P \\<and> (\\<exists>t. t \\<in> Q \\<and> y = s @ t)))\"\n    using assm1 assm2 assm3 apply (rule_tac x=\"butlast y@ya\" in exI, auto)\n    apply (smt Nil_is_append_conv TTwf_P TTwf_def Tick_set_ends_in_Tick Tick_set_tt2T_in append_butlast_last_id last_in_set last_snoc not_Cons_self2 tt2T_concat_Tick_no_Ref_set tt2T_concat_Tick_no_Tick_set tt2T_concat_Tick_no_Tock_set tt2T_concat_dist tt2T_tick_butlast)\n    using tt2T_tick_exists_Cons by force+\nqed\n\nlemma ttproc2F_SeqCompTT_eq_SeqCompF:\n  assumes TTwf_P: \"TTwf P\" and TT0_P: \"TT0 P\" and TT1_P: \"TT1 P\" \n      and TTwf_Q: \"TTwf Q\" and TT0_Q: \"TT0 Q\" and TT1_Q: \"TT1 Q\"\n  shows \"(ttproc2F (P ;\\<^sub>C Q)) = ((ttproc2F P) ;\\<^sub>F (ttproc2F Q))\" \n  using assms\n  by (simp add: refines_asym refines_def ttproc2F_SeqCompF_failures_subseteq_SeqCompTT ttproc2F_SeqCompF_traces_subseteq_SeqCompTT ttproc2F_SeqCompTT_failures_subseteq_SeqCompF ttproc2F_SeqCompTT_traces_subseteq_SeqCompF)\n\nend", "meta": {"author": "UoY-RoboStar", "repo": "tick-tock-CSP", "sha": "7186d2e7f70116589850112a7353bc521372c913", "save_path": "github-repos/isabelle/UoY-RoboStar-tick-tock-CSP", "path": "github-repos/isabelle/UoY-RoboStar-tick-tock-CSP/tick-tock-CSP-7186d2e7f70116589850112a7353bc521372c913/Failures/Failures_TickTock_SeqComp.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.29214426401641486}}
{"text": "section\"Example: Lorenz attractor\"\ntheory Lorenz_Approximation\nimports\n  \"HOL-ODE-Numerics.ODE_Numerics\"\n  Result_File_Coarse\nbegin\ntext \\<open>\\label{sec:lorenz}\\<close>\n\ntext \\<open>TODO: move to isabelle? \\<close>\nlifting_update blinfun.lifting\nlifting_forget blinfun.lifting\n\n\nlemma eventually_uniformly_on:\n  \"(\\<forall>\\<^sub>F x in uniformly_on T l. P x) = (\\<exists>e>0. \\<forall>f. (\\<forall>x\\<in>T. dist (f x) (l x) < e) \\<longrightarrow> P f)\"\n  unfolding uniformly_on_def\n  apply (subst eventually_INF)\n  apply safe\n  subgoal for E\n    apply (cases \"E = {}\")\n    subgoal by (auto intro!: exI[where x=1])\n    subgoal\n      apply (auto simp: INF_principal_finite eventually_principal elim!: )\n    proof goal_cases\n      case (1 x)\n      from 1 have \"0 < Min E\"\n        apply (subst Min_gr_iff)\n          apply force apply force apply force done\n      have *: \"(\\<Inter>e\\<in>E. {f. \\<forall>t\\<in>T. dist (f t) (l t) < e}) = {f. \\<forall>t\\<in>T. dist (f t) (l t) < Min E}\"\n        using 1 apply (auto simp: )\n         apply (subst Min_gr_iff)\n           apply force apply force apply force\n        apply (drule bspec, assumption)\n        apply (rule less_le_trans, assumption)\n        apply auto\n        done\n      from 1 have \"\\<forall>f. (\\<forall>x\\<in>T. dist (f x) (l x) < Min E) \\<longrightarrow> P f\" unfolding * by simp\n      then show ?case\n        using 1(4)[rule_format, OF \\<open>0 < Min E\\<close>] by auto\n    qed\n    done\n  subgoal for e\n    apply (rule exI[where x=\"{e}\"])\n    by (auto simp: eventually_principal)\n  done\n\n\nlemma op_cast_image_impl[autoref_rules]:\n  \"(\\<lambda>x. x, op_cast_image::'a::executable_euclidean_space set \\<Rightarrow>\n                          'b::executable_euclidean_space set)\n    \\<in> aform.appr_rel \\<rightarrow> aform.appr_rel\"\n  if \"DIM('a) = DIM('b)\"\n  using that\n  apply (auto simp: aform.appr_rel_def intro!: relcompI)\n  unfolding lv_rel_def set_rel_br\n  by (force simp: intro!: brI dest!: brD)\n\nlemma cast_bl_blinfun_of_list[simp]:\n  \"cast_bl (blinfun_of_list xs::'a \\<Rightarrow>\\<^sub>L 'a) =\n    (blinfun_of_list xs::'b\\<Rightarrow>\\<^sub>L'b)\"\n  if \"DIM('a::executable_euclidean_space) = DIM('b::executable_euclidean_space)\"\n  using that\n  apply (auto simp: cast_bl_rep intro!: blinfun_eqI)\n  by (auto simp: blinfun_of_list_def blinfun_of_matrix_apply\n      linear_sum linear.scaleR sum_Basis_sum_nth_Basis_list\n      linear_cast)\n\nlemma cast_idem[simp]: \"cast x = x\"\n  by (auto simp: cast_def)\n\nlemma cast_bl_idem[simp]: \"cast_bl x = x\"\n  by (auto simp: cast_bl_rep intro!: blinfun_eqI)\n\nlemma op_cast_eucl1_image_impl[autoref_rules]:\n  \"(\\<lambda>x. x, op_cast_eucl1_image::'a::executable_euclidean_space c1_info set \\<Rightarrow>\n                          'b::executable_euclidean_space c1_info set)\n    \\<in> aform.appr1_rel \\<rightarrow> aform.appr1_rel\"\n  if \"DIM_precond TYPE('a) D\"\n    \"DIM_precond TYPE('b) D\"\n  using that\nproof (auto, goal_cases)\n  case (1 a b a')\n  then show ?case\n    apply (auto simp: aform.appr1_rel_br set_rel_br br_def)\n    subgoal for w x y z\n      apply (auto simp: aform.c1_info_of_appr_def cast_eucl1_def aform.c1_info_invar_def\n          split: option.splits)\n       apply (rule image_eqI)\n        apply (rule cast_eucl_of_list, force, force simp: Joints_imp_length_eq, force)\n      subgoal for s t\n        apply (rule image_eqI[where x=\"t\"])\n         supply [simp del] = eucl_of_list_take_DIM\n        apply (auto simp: flow1_of_list_def)\n        apply (subst cast_eucl_of_list)\n        subgoal by simp\n        subgoal\n          by (auto dest!: Joints_imp_length_eq\n              simp: power2_eq_square flow1_of_list_def[abs_def])\n        subgoal by simp\n        done\n      done\n    subgoal for w x\n      apply (rule image_eqI[where x=\"cast_eucl1 (w, x)\"])\n       apply (auto simp: aform.c1_info_of_appr_def cast_eucl1_def\n          aform.c1_info_invar_def\n          split: option.splits)\n       apply (rule image_eqI)\n        apply (rule cast_eucl_of_list, force, force simp: Joints_imp_length_eq, force)\n      subgoal for s t\n        apply (rule image_eqI[where x=\"t\"])\n         supply [simp del] = eucl_of_list_take_DIM\n        apply (auto simp: flow1_of_list_def)\n        apply (subst cast_eucl_of_list)\n        subgoal by simp\n        subgoal\n          by (auto dest!: Joints_imp_length_eq\n              simp: power2_eq_square flow1_of_list_def[abs_def])\n        subgoal by simp\n        done\n      done\n    done\nqed\n\nlemma less_3_iff: \"i < (3::nat) \\<longleftrightarrow> i = 0 \\<or> i = 1 \\<or> i = 2\"\n  by arith\n\ndefinition mat3_of_vec::\"R3 \\<Rightarrow> real^3^3\" where\n  \"mat3_of_vec x = (let xs = list_of_eucl x in eucl_of_list [xs!0,0,0,  xs!1,0,0,  xs!2,0,0])\"\n\nlemma ll3: \"{..<3} = {0,1,2::nat}\"\n  by (auto simp: less_3_iff)\n\nlemma mat3_of_vec: \"cast (mat3_of_vec x *v eucl_of_list [1, 0, 0]) = x\"\n  by (auto simp: mat3_of_vec_def eucl_of_list_matrix_vector_mult_eq_sum_nth_Basis_list\n      linear_sum linear_cast linear.scaleR ll3 linear_add Basis_list_R3 inner_prod_def\n      prod_eq_iff)\n\nprimrec bisect_form where\n  \"bisect_form p f xs l u 0 = (l, u)\"\n| \"bisect_form p f xs l u (Suc n) =\n    (let m = (l + u)/2 in\n    if approx_form_aform p (f m) xs\n    then bisect_form p f xs l m n\n    else bisect_form p f xs m u n)\"\n\ntext \\<open>This should prove that the expansion estimates are sufficient.\\<close>\n\nlemma expansion_main: \"expansion_main (coarse_results) = Some True\"\n  by eval\n\ncontext includes floatarith_notation begin\n\ndefinition \"matrix_of_degrees2\\<^sub>e =\n  (let\n    e = Var 2;\n    ur = Rad_of (Var 0);\n    vr = Rad_of (Var 1);\n    x1 = Cos ur;\n    x2 = Cos vr;\n    y1 = Sin ur;\n    y2 = Sin vr\n   in\n    [x1 + (e * (x2 - x1)), 0, 0,\n    y1 + (e * (y2 - y1)), 0, 0,\n    0, 0, 0])\"\n\ndefinition \"matrix_of_degrees2 u v =\n  approx_floatariths 30 matrix_of_degrees2\\<^sub>e (aforms_of_ivls [u, v, 0] [u, v, 1])\"\n\ntext \\<open>following \\<open>vector_field.h\\<close> / \\<open>vector_field.cc\\<close>\\<close>\n\nabbreviation \"S \\<equiv> 10::real\"\nabbreviation \"B \\<equiv> 8/3::real\"\nabbreviation \"TEMP \\<equiv> sqrt((S + 1) * (S + 1) + 4 * S * (28 - 1))\"\nabbreviation \"K1 \\<equiv> S / TEMP\"\nabbreviation \"K2 \\<equiv> (S - 1 + TEMP) / (2 * S)\"\nabbreviation \"K3 \\<equiv> (S - 1 - TEMP) / (2 * S)\"\nabbreviation \"E1 \\<equiv> (- (S + 1) + TEMP) / 2\"\nabbreviation \"E2 \\<equiv> (- (S + 1) - TEMP) / 2\"\nabbreviation \"E3 \\<equiv> - B\"\nabbreviation \"C1 \\<equiv> \\<lambda>X. X ! 0 + X ! 1\"\nabbreviation \"C2 \\<equiv> \\<lambda>X. K1 * C1 X * X ! 2\"\n\nschematic_goal\n  lorenz_fas:\n  \"[E1 * X!0 - C2 X,\n    E2 * X!1 + C2 X,\n    E3 * X!2 + C1 X * (K2 * X!0 + K3 * X!1)] =\n  interpret_floatariths ?fas X\"\n  by (reify_floatariths)\nconcrete_definition lorenz_fas uses lorenz_fas\nend\n\ninterpretation lorenz: ode_interpretation true_form UNIV lorenz_fas \"\\<lambda>(X0, X1, X2).\n (E1 * X0 -        K1 * (X0 + X1) * X2,\n  E2 * X1 +        K1 * (X0 + X1) * X2,\n  E3 * X2 + (X0 + X1) * (K2 * X0 + K3 * X1))::real*real*real\"\n  \"d::3\" for d\n  by standard\n    (auto simp: lorenz_fas_def less_Suc_eq_0_disj nth_Basis_list_prod Basis_list_real_def\n      mk_ode_ops_def eucl_of_list_prod power2_eq_square inverse_eq_divide intro!: isFDERIV_I)\n\nvalue [code] \"length (slp_of_fas lorenz_fas)\"\n\ndefinition \"mig_aform p x = mig_componentwise (Inf_aform' p x) (Sup_aform' p x)\"\n\ncontext includes floatarith_notation begin\n\ndefinition \"mig_aforms p x = real_of_float ((lower o the) ((approx p (Norm (map (Num o float_of o (mig_aform p)) x))) []))\"\n\ndefinition\n  \"column_of_c1_info x N j = (map (\\<lambda>i. the (snd x) ! i) (map (\\<lambda>i. i * N + j) [0..<N]))\"\n\ndefinition \"rotate_x_fa a =\n  [1, 0, 0,\n  0, Cos a, - Sin a,\n  0, Sin a, Cos a]\"\n\ndefinition \"rotate_y_fa a =\n  [Cos a, 0, Sin a,\n  0, 1, 0,\n  - Sin a, 0, Cos a]\"\n\ndefinition \"rotate_z_fa a =\n  [Cos a, - Sin a, 0,\n  Sin a, Cos a, 0,\n  0, 0, 1]\"\n\ndefinition \"rotate_zx_slp a b xs =\n  slp_of_fas (mvmult_fa 3 3 (mmult_fa 3 3 3 (rotate_x_fa (Rad_of (R\\<^sub>e b))) (rotate_z_fa (Rad_of (R\\<^sub>e a)))) xs)\"\n\ndefinition \"perspective_projection_aforms xs =\n  the (approx_slp_outer 30 3 (rotate_zx_slp (-30) (-60) (map Var [0..<3])) xs)\"\n\ndefinition \"print_lorenz_aform print_fun cx cy cz ci\n    cd1 cd2\n  = (\\<lambda>a b.\n        let (s1, n) = ((-6), False);\n            _ = print_fun (String.implode (''# gen(''@ show a@''): ''@ shows_aforms_hr (b) '''' @ ''\\<newline>''));\n            _ = print_fun (String.implode (''# box(''@ show a@''): ''@ shows_box_of_aforms_hr (b) '''' @ ''\\<newline>''));\n            ((x0, y0, z0), (x1, y1, z1)) = case (map (Inf_aform' 30) (take 3 b), map (Sup_aform' 30) (take 3 b)) of\n              ([x0, y0, z0], [x1, y1, z1]) \\<Rightarrow> ((x0, y0, z0), (x1, y1, z1));\n            _ = print_fun (String.implode (shows_segments_of_aform 0 1 b ((shows cx o shows_space o shows z0 o shows_space o shows z1)'''') ''\\<newline>''));\n            _ = print_fun (String.implode (shows_segments_of_aform 0 2 b ((shows cy o shows_space o shows y0 o shows_space o shows y1)'''') ''\\<newline>''));\n            _ = print_fun (String.implode (shows_segments_of_aform 1 2 b ((shows cz o shows_space o shows x0 o shows_space o shows x1)'''') ''\\<newline>''));\n            PS = perspective_projection_aforms b;\n            _ = print_fun (String.implode (shows_segments_of_aform 0 1 PS\n                  ((shows ci o shows_space o shows (fst (PS ! 2)) o shows_space o shows (fst (b ! 2))) '''') ''\\<newline>''))\n        in if \\<not> a \\<and> length b > 10 then\n          print_fun (String.implode (shows_aforms_vareq 3 [(0, 1), (0, 2), (1, 2)] [0..<3]\n              cd1\n              cd2\n          (FloatR 1 s1 * (if n then\n              real_divl 30 1 (max (mig_aforms 30 (map (\\<lambda>i. b ! i) [3,6,9]))\n                         (mig_aforms 30 (map (\\<lambda>i. b ! i) [4,7,10])))\n            else 1)) \\<comment> \\<open>always length \\<open>2^s!\\<close>\\<close>\n          ''# no C1 info'' b ''''))\n        else ())\"\n\ndefinition \"print_lorenz_aform_std print_fun =\n  print_lorenz_aform print_fun ''0x000001'' ''0x000002'' ''0x000012'' ''0x000003''\n    [''0xa66f00'', ''0x06266f'', ''0xc60000'']\n    [''0xffaa00'', ''0x1240ab'', ''0xc60000'']\"\n\ndefinition \"lorenz_optns print_funo =\n  (let\n    pf = the_default (\\<lambda>_ _. ()) (map_option print_lorenz_aform_std print_funo);\n    tf = the_default (\\<lambda>_ _. ()) (map_option (\\<lambda>print_fun a b.\n          let\n            _ = print_fun (String.implode (''# '' @ a @ ''\\<newline>''))\n          in case b of Some b \\<Rightarrow>\n            (print_fun (String.implode (''# '' @ shows_box_of_aforms_hr (b) '''' @ ''\\<newline>'')))\n            | None \\<Rightarrow> ()) print_funo)\n  in\n    \\<lparr>\n    precision = 30,\n    adaptive_atol = FloatR 1 (-30),\n    adaptive_rtol = FloatR 1 (-30),\n    method_id = 2,\n    start_stepsize  = FloatR 1 (- 8),\n    iterations = 40,\n    halve_stepsizes = 10,\n    widening_mod = 40,\n    rk2_param = FloatR 1 0,\n    default_reduce = correct_girard 30 50 25,\n    printing_fun = pf,\n    tracing_fun = tf\n  \\<rparr>)\"\n\ndefinition lorenz_optns'\n  where \"lorenz_optns' pf m N rk2p a = lorenz_optns pf \\<lparr>\n      default_reduce := correct_girard 30 m N,\n      rk2_param := rk2p,\n      adaptive_atol := a,\n      adaptive_rtol := a\n    \\<rparr>\"\n\ndefinition mirror_irects\n  where \"mirror_irects =\n    map (\\<lambda>irect. case irect of [i, j, k] \\<Rightarrow> [if j < 0 then - i else i , abs j, k] | irect \\<Rightarrow> irect)\"\n\ndefinition \"print_irects irects =\n  (let _ = map (\\<lambda>is.\n    let _ = map (\\<lambda>j.\n      let _ = print (String.implode (show j)) in print (STR '' '')) is in print (STR ''\\<newline>'')) irects\n  in ())\"\n\nabbreviation \"aforms_of_ivl \\<equiv> \\<lambda>x. aforms_of_ivls (fst x) (snd x)\"\n\ndefinition \"conefield_propagation\\<^sub>e =\n  ([Deg_of (Arctan (Var (6) / Var (3))),\n   Deg_of (Arctan (Var (7) / Var (4))),\n   Min (Norm [Var(3), Var (6), Var (9)]) (Norm [Var(4), Var (7), Var (10)])])\"\n\ndefinition \"conefield_propagation DX = approx_floatariths 30 conefield_propagation\\<^sub>e DX\"\n\ndefinition \"conefield_propagation_slp = slp_of_fas conefield_propagation\\<^sub>e\"\n\n\ndefinition op_with_unit_matrix :: \"'a::real_normed_vector \\<Rightarrow> 'a \\<times> 'a \\<Rightarrow>\\<^sub>L 'a\" where\n  \"op_with_unit_matrix X = (X, 1\\<^sub>L)\"\n\ncontext includes blinfun.lifting begin\nlemma matrix_vector_mult_blinfun_works[simp]: \"matrix e *v g = e g\" for e::\"(real^'n) \\<Rightarrow>\\<^sub>L (real^'m)\"\n  by transfer (simp add: bounded_linear_def matrix_works)\nend\n\nlemma length_conefield_propagation\\<^sub>e[simp]: \"length conefield_propagation\\<^sub>e = 3\"\n  by (simp add: conefield_propagation\\<^sub>e_def)\n\nlemma interpret_floatariths_conefield_propagation:\n  \"interpret_floatariths conefield_propagation\\<^sub>e\n    (list_of_eucl (vec1_of_flow1 (xDX::(real^3) \\<times> ((real^3)\\<Rightarrow>\\<^sub>L(real^3)))))\n   =\n  (let\n    DX = snd xDX;\n    DXu = DX (eucl_of_list [1, 0, 0]);\n    DXv = DX (eucl_of_list [0, 1, 0])\n  in\n  [deg_of (arctan (vec_nth DXu 1 / vec_nth DXu 0)),\n   deg_of (arctan (vec_nth DXv 1 / vec_nth DXv 0)),\n   min (norm DXu) (norm DXv)]\n  )\"\n  apply (auto simp: conefield_propagation\\<^sub>e_def Let_def interpret_mvmult_nth[where 'n=3 and 'm=3]\n      inverse_eq_divide vec1_of_flow1_def nth_append)\n    apply (auto simp: matrix_inner_Basis_list )\n    apply (auto simp: interpret_floatarith_norm[where 'a=\"real ^ 3\"]\n      einterpret_mvmult_fa[where 'n=3 and 'm=3] matrix_inner_Basis_list nth_append)\n  by (auto simp: matrix_def axis_eq_eucl_of_list eucl_of_list_012)\n\ndefinition \"conefield_bounds_form l u =\n  (fold Conj [\n    Less (-90) (N\\<^sub>r l),\n    LessEqual (N\\<^sub>r l) (N\\<^sub>r u),\n    LessEqual (Var 9) (0),\n    LessEqual 0 (Var 9),\n    Less (N\\<^sub>r u) (90),\n    Less 0 (Var 3),\n    AtLeastAtMost (Var 6) (Tan (Rad_of (N\\<^sub>r l)) * Var 3) (Tan (Rad_of (N\\<^sub>r u)) * Var 3)] true_form)\"\n\ndefinition \"contract_angles X i = (snd (bisect_form 30 (\\<lambda>x. conefield_bounds_form x (89)) X 89 (-89) i),\n                                   snd (bisect_form 30 (conefield_bounds_form (-89)) X (-89) 89 i))\"\n\ndefinition \"approx_conefield_bounds (DX::(R3 \\<times> (R3 \\<Rightarrow>\\<^sub>L R3)) set) l u =\n  do {\n    let DX = (cast_eucl1 ` DX::3 eucl1 set);\n    DXo \\<leftarrow> aform.vec1rep DX;\n    DX \\<leftarrow> (case DXo of None \\<Rightarrow> do {\n        let _ = aform.print_msg (''# approx_conefield_bounds failed DXo...'');\n        SUCCEED\n      }\n    | Some DX \\<Rightarrow> RETURN DX);\n    let _ = aform.trace_set (''# approx_conefield_bounds DX: '') (Some DX);\n    approx_form_spec (conefield_bounds_form l u) (list_of_eucl ` DX)\n  }\"\n\nlemma [autoref_rules]:\n  includes autoref_syntax\n  shows \"(conefield_bounds_form, conefield_bounds_form) \\<in> Id \\<rightarrow> Id \\<rightarrow> Id \"\n  by auto\n\nlemma [autoref_rules_raw]:\n  \"DIM_precond TYPE((real, 3) vec \\<times> ((real, 3) vec, 3) vec) 12\"\n  \"DIM_precond TYPE(R3) 3\"\n  \"DIM_precond TYPE((real, 3) vec) 3\"\n  by auto\n\nschematic_goal approx_conefield_bounds_impl:\n  includes autoref_syntax\n  fixes optns::\"real aform numeric_options\"\n  assumes [autoref_rules]: \"(DXi, DX) \\<in> aform.appr1_rel\"\n  assumes [autoref_rules]: \"(li, l) \\<in> Id\"\n  assumes [autoref_rules]: \"(ui, u) \\<in> Id\"\n  notes [autoref_rules] =\n      aform.print_msg_impl[where optns = optns]\n      aform.ivl_rep_of_set_autoref[where optns = optns]\n      aform.transfer_operations(12)[where optns = optns]\n      aform.approx_euclarithform[where optns=optns]\n      aform.trace_set_impl[of optns]\n  shows \"(nres_of ?r, approx_conefield_bounds $ DX $ l $ u) \\<in> \\<langle>bool_rel\\<rangle>nres_rel\"\n  unfolding autoref_tag_defs\n  unfolding approx_conefield_bounds_def\n  including art\n  by autoref_monadic\nconcrete_definition approx_conefield_bounds_impl for optns li ui DXi uses\n  approx_conefield_bounds_impl\nlemmas [autoref_rules] = approx_conefield_bounds_impl.refine\n\ncontext includes autoref_syntax begin\nlemma [autoref_rules]:\n  \"(real_of_ereal, real_of_ereal) \\<in> ereal_rel \\<rightarrow> rnv_rel\"\n  \"(\\<infinity>, \\<infinity>) \\<in> ereal_rel\"\n  by auto\nend\n\nlemma interpret_form_true_form[simp]: \"interpret_form true_form \\<equiv> \\<lambda>_. True\"\n  by (force simp: true_form_def intro!: eq_reflection)\n\nlemma interpret_form_conefield_bounds_form_list:\n  \"interpret_form (conefield_bounds_form L U)\n    [x, y, z, ux, vx, wx,\n              uy, vy, wy,\n              uz, vz, wz]\n   \\<longleftrightarrow>\n    (0 < ux \\<and> -90 < L \\<and> L \\<le> U \\<and> U < 90 \\<and> uz = 0 \\<and>\n    uy \\<le> tan (rad_of U) * ux \\<and>\n    tan (rad_of L) * ux  \\<le> uy)\"\n  if \"U \\<in> float\" \"L \\<in> float\" \"e \\<in> float\" \"em \\<in> float\"\n  using that\n  by (auto simp: conefield_bounds_form_def L2_set_def)\n\nlemma list_of_eucl_eucl1_3:\n  includes vec_syntax\n  shows \"(list_of_eucl (vec1_of_flow1 (xDX::(real^3) \\<times> ((real^3)\\<Rightarrow>\\<^sub>L(real^3))))) =\n  (let\n    (x, DX) = xDX;\n    DXu = DX (eucl_of_list [1, 0, 0]);\n    DXv = DX (eucl_of_list [0, 1, 0]);\n    DXw = DX (eucl_of_list [0, 0, 1])\n  in [x $ 0, x $ 1, x $ 2, vec_nth DXu 0, vec_nth DXv 0, vec_nth DXw 0,\n                           vec_nth DXu 1, vec_nth DXv 1, vec_nth DXw 1,\n                           vec_nth DXu 2, vec_nth DXv 2, vec_nth DXw 2])\"\n  apply (auto simp: matrix_inner_Basis_list Let_def vec1_of_flow1_def\n      concat_map_map_index less_Suc_eq_0_disj\n      list_of_eucl_matrix eval_nat_numeral aform.inner_Basis_eq_vec_nth\n      intro!: nth_equalityI\n      split: prod.splits)\n  by (auto simp: matrix_def axis_eq_eucl_of_list eucl_of_list_012)\n\nlemma interpret_form_conefield_bounds_form:\n  \"interpret_form (conefield_bounds_form L U)\n    (list_of_eucl (vec1_of_flow1 (xDX::(real^3) \\<times> ((real^3)\\<Rightarrow>\\<^sub>L(real^3)))))\n   =\n  (let\n    DX = snd xDX;\n    DXu = DX (eucl_of_list [1, 0, 0]);\n    DXv = DX (eucl_of_list [0, 1, 0]);\n    uz = vec_nth DXu 2;\n    uy = vec_nth DXu 1;\n    ux = vec_nth DXu 0;\n    vy = vec_nth DXv 1;\n    vx = vec_nth DXv 0\n  in\n    ux > 0 \\<and> -90 < L \\<and> L \\<le> U \\<and> U < 90 \\<and> uz = 0 \\<and>\n    (uy / ux) \\<in> {tan (rad_of L) .. tan (rad_of U)}\n  )\"\n  if \"L \\<in> float\" \"U \\<in> float\"\n  using that\n  unfolding list_of_eucl_eucl1_3 Let_def\n  by (auto  split: prod.splits simp: interpret_form_conefield_bounds_form_list divide_simps)\n\nlemma approx_conefield_bounds_cast:\n  \"approx_conefield_bounds DX L U \\<le> SPEC (\\<lambda>b. b \\<longrightarrow>\n    (\\<forall>(x, dx) \\<in> cast_eucl1 ` DX::3 eucl1 set.\n      let\n        u' = dx (eucl_of_list [1, 0, 0])\n      in\n        vec_nth u' 1 / vec_nth u' 0 \\<in> {tan (rad_of L) .. tan (rad_of U)}\n        \\<and> vec_nth u' 2 = 0 \\<and> vec_nth u' 0 > 0 \\<and> -90 < L \\<and> L \\<le> U \\<and> U < 90)\n  )\"\n  if \"L \\<in> float\" \"U \\<in> float\"\n  unfolding approx_conefield_bounds_def\n  apply refine_vcg\n   apply (auto simp: env_len_def )\n  subgoal for a b c\n    apply (drule bspec, assumption)\n    unfolding interpret_form_conefield_bounds_form[OF that]\n    by (auto simp: Let_def divide_simps)\n  done\n\n\nlemma approx_conefield_bounds[le, refine_vcg]:\n  \"approx_conefield_bounds DX l u \\<le> SPEC (\\<lambda>b. b \\<longrightarrow>\n    (\\<forall>(x, dx) \\<in> DX::R3 c1_info set.\n      let\n        (u'1, u'2, u'3) = dx ((1, 0, 0))\n      in u'2 / u'1 \\<in> {tan (rad_of l) .. tan (rad_of u)} \\<and> u'3 = 0 \\<and> u'1 > 0 \\<and> -90 < l \\<and> l \\<le> u \\<and> u < 90)\n  )\"\n  if \"l \\<in> float\" \"u \\<in> float\"\n  apply (rule approx_conefield_bounds_cast[le, OF that])\n  apply (auto dest!: bspec simp: Let_def split: prod.splits)\n  by (auto simp: cast_eucl1_def cast_def)\n\nschematic_goal MU\\<^sub>e: \"-E2 / E1 = interpret_floatarith ?fas []\"\n  by (reify_floatariths)\nconcrete_definition MU\\<^sub>e uses MU\\<^sub>e\nschematic_goal NU\\<^sub>e: \"-E3 / E1 = interpret_floatarith ?fas []\"\n  by (reify_floatariths)\nconcrete_definition NU\\<^sub>e uses NU\\<^sub>e\n\ndefinition \"approx_ivls p fas xs = do {\n  let xs = ivls_of_aforms p xs;\n  res \\<leftarrow> those (map (\\<lambda>f. approx p f xs) fas);\n  Some (map (real_of_float o lower) res, map (real_of_float o upper) res)\n}\"\ndefinition\n  \"deform p t exit XDX = (case XDX of (lu, (X, DX)) \\<Rightarrow>\n    let\n      d = ldec 0.1;\n      d = if exit then (1 - real_of_float (lb_sqrt 30 (1 - 2 * float_of (d)))) else d;\n      sd = real_of_float ((float_of (d*d)));\n      C0Deform = aforms_of_ivls [-sd,-sd,-sd] [sd, sd, sd];\n      result = msum_aforms' X C0Deform\n    in (lu,\n      case DX of None \\<Rightarrow> (result, None)\n      | Some DX \\<Rightarrow> let\n        C1_norm = 2 * d;\n        C1_norm = if exit then real_divr 30 C1_norm (1 - C1_norm) else C1_norm;\n        l = -C1_norm;\n        u = C1_norm;\n        D_M = aforms_of_ivls [1 + l,0,0, 0,1 + l,0, 0,0,1 + l] [1 + u,0,0, 0,1 + u,0, 0,0,1 + u];\n        (ri, ru) = the (approx_ivls p\n          (mmult_fa 3 3 3 (map Var [0..<9]) (map Var [9..<18])) (D_M @ DX));\n        Dresult = aforms_of_ivls ri ru;\n        resultDresult = product_aforms result Dresult\n      in (take 3 resultDresult, Some (drop 3 resultDresult))))\"\n\ndefinition \"ivls_of_aforms' p r = (map (Inf_aform' p) r, map (Sup_aform' p) r)\"\n\ndefinition \"compute_half_exit p t XDX = (case XDX of ((l, u::ereal), (X, DX)) \\<Rightarrow>\n   let\n    \\<comment> \\<open>ASSERTING that \\<open>Y\\<close> straddles zero\\<close>\n    (x0, y0, _) = case map (Inf_aform' p) X of [x,y,z] \\<Rightarrow> (x, y, z);\n    (x1, y1, _) = case map (Sup_aform' p) X of [x,y,z] \\<Rightarrow> (x, y, z);\n    splitting = x0 = 0 \\<or> x1 = 0;\n    sign_x = if (x0 + x1) / 2 > 0 then 1 else -1;\n    mag_x = max (abs x0) (abs x1);\n    sign_x\\<^sub>e = N\\<^sub>r sign_x;\n    exit_rad\\<^sub>e = N\\<^sub>r (ldec 0.1);\n    X\\<^sub>e = Var (0);\n    Y\\<^sub>e = Var (1);\n    Z\\<^sub>e = Var (2);\n    max_x_over_r\\<^sub>e = N\\<^sub>r mag_x / exit_rad\\<^sub>e;\n    abs_x_over_r\\<^sub>e = (Abs X\\<^sub>e) / exit_rad\\<^sub>e;\n    result = (if splitting\n      then let result = (the (approx_floatariths p [sign_x\\<^sub>e * exit_rad\\<^sub>e,\n          Y\\<^sub>e * Powr (max_x_over_r\\<^sub>e) MU\\<^sub>e,\n          Z\\<^sub>e * Powr (max_x_over_r\\<^sub>e) NU\\<^sub>e] X));\n      (ir, sr) = ivls_of_aforms' p result\n      in aforms_of_ivls (ir[1:=min 0 (ir!1), 2:=min 0 (ir!2)])\n                              (sr[1:=max 0 (sr!1), 2:=max 0 (sr!2)])\n      else the (approx_floatariths p [sign_x\\<^sub>e * exit_rad\\<^sub>e,\n          Y\\<^sub>e * Powr (abs_x_over_r\\<^sub>e) MU\\<^sub>e,\n          Z\\<^sub>e * Powr (abs_x_over_r\\<^sub>e) NU\\<^sub>e] X));\n    _ = ()\n    in ((l::ereal, \\<infinity>::ereal), (case DX of None \\<Rightarrow> (result, None)\n    | Some DX \\<Rightarrow>\n      let\n        ux\\<^sub>e = Var (3);\n        uy\\<^sub>e = Var (6);\n        P21\\<^sub>e = if splitting\n          then (MU\\<^sub>e / exit_rad\\<^sub>e) * Y\\<^sub>e * sign_x\\<^sub>e * Powr (max_x_over_r\\<^sub>e) (MU\\<^sub>e - 1) \\<comment> \\<open>No need for \\<open>Hull(0)\\<close> because \\<open>y\\<close> straddles zero\\<close>\n          else (MU\\<^sub>e / exit_rad\\<^sub>e) * Y\\<^sub>e * sign_x\\<^sub>e * Powr (abs_x_over_r\\<^sub>e) (MU\\<^sub>e - 1);\n        P22\\<^sub>e = if splitting\n          then Powr (max_x_over_r\\<^sub>e) MU\\<^sub>e\n          else Powr (abs_x_over_r\\<^sub>e) MU\\<^sub>e;\n        P31\\<^sub>e = if splitting\n          then sign_x\\<^sub>e * (NU\\<^sub>e / exit_rad\\<^sub>e) * Z\\<^sub>e * Powr (max_x_over_r\\<^sub>e) (NU\\<^sub>e - 1) \\<comment> \\<open>No need for \\<open>Hull(\\<infinity>)\\<close> because scaling afterwards\\<close>\n          else sign_x\\<^sub>e * (NU\\<^sub>e / exit_rad\\<^sub>e) * Z\\<^sub>e * Powr (abs_x_over_r\\<^sub>e) (NU\\<^sub>e - 1);\n        ry = (P21\\<^sub>e * ux\\<^sub>e) + (P22\\<^sub>e * uy\\<^sub>e);\n        rz = P31\\<^sub>e * ux\\<^sub>e;\n        (iDr, sDr) = the (approx_ivls p ([0, 0, 0,\n             ry,   0, 0,\n             rz,   0, 0]) (X @ DX));\n        Dresult = aforms_of_ivls (iDr[3:=min 0 (iDr!3)])\n                              (sDr[3:=max 0 (sDr!3)]);\n        resultDresult = product_aforms result Dresult\n      in (take 3 resultDresult, Some (drop 3 resultDresult))\n    )))\"\n\nfun list3 where \"list3 [a,b,c] = (a, b, c)\"\n\ndefinition\n  \"split_x n x0 y0 z0 x1 y1 z1 =\n    (let\n      elem = (\\<lambda>(x0, x1). aforms_of_ivls [x0, y0, z0] [x1, y1, z1]);\n      coord = (\\<lambda>x0 n i. i * x0 * FloatR 1 (-int n));\n      us = map (coord x0 n) (rev [0..<(2^n)]) @ map (coord x1 n) [Suc 0..<Suc (2^n)];\n      ls = map (coord x0 n) (rev [Suc 0..<Suc (2^n)]) @ map (coord x1 n) [0..<(2^n)]\n    in map elem (zip ls us))\"\n\ndefinition \"compute_cube_exit p t XDX =\n  (let\n    ((l, u), (X', DX')) = deform p t False XDX;\n    ((x0, y0, z0), (x1, y1, z1)) = pairself list3 (ivls_of_aforms' p X');\n    X's = [aforms_of_ivls [x0, y0, z0] [0, y1, z1], aforms_of_ivls [0, y0, z0] [x1, y1, z1]];\n    XDX's = map (\\<lambda>X'. ((l, u), (X', DX'))) X's;\n    Xes = map (compute_half_exit p t) XDX's;\n    Xlumpies = map (deform p t True) Xes\n  in\n    Xlumpies)\"\n\n\ndefinition \"cube_enteri = (map ldec [-0.1, -0.00015, 0.1,   0.8,0,0,       0.0005,0,0,   0,0,0],\n                             map udec [ 0.1,  0.00015,   0.1,   1.7,0,0,      0.002,0,0,   0,0,0])\"\ndefinition \"cube_enter = set_of_ivl (pairself eucl_of_list cube_enteri)\"\n\nvalue [code] \"println ((show) (map (ivls_of_aforms' 100 o list_of_appr1e_aform)\n  (compute_cube_exit 30 (FloatR 1 (-10)) ((ereal 1, ereal 1),\n    (aforms_of_ivls (take 3 (fst cube_enteri))\n                    (take 3 (snd cube_enteri)),\n      Some (aforms_of_ivls (drop 3 (fst cube_enteri))\n                       (drop 3 (snd cube_enteri))))))))\"\n\ndefinition \"cube_exiti =\n  [(aforms_of_ivls (map ldec [-0.12,  -0.024, -0.012])\n                   (map udec [-0.088,  0.024,  0.13]),\n     Some (aforms_of_ivls (map ldec [0,0,0,  -0.56,0,0,  -0.6,0,0])\n                          (map udec [0,0,0,   0.56,0,0,  -0.08,0,0]))),\n  (aforms_of_ivls (map ldec [ 0.088,  -0.024, -0.012])\n                  (map udec [ 0.12,   0.024,  0.13]),\n     Some (aforms_of_ivls (map ldec [0,0,0,  -0.53,0,0,   0.08,0,0])\n                          (map udec [0,0,0,   0.56,0,0,   0.6,0,0])))]\"\ndefinition \"cube_exitv = aform.c1_info_of_apprs cube_exiti\"\n\nlemma cube_enteri[autoref_rules]: \"(cube_enteri, cube_enter::'a set) \\<in> lvivl_rel\"\n  if \"DIM_precond TYPE('a::executable_euclidean_space) 12\"\n  using that\n  by (auto simp: cube_enteri_def cube_enter_def set_of_ivl_def\n      intro!: brI lv_relivl_relI)\n\nlemma cube_exiti[autoref_rules]: \"(cube_exiti, cube_exitv::'n eucl1 set) \\<in> clw_rel aform.appr1_rel\"\n  if \"DIM_precond TYPE('n::enum rvec) 3\"\n  unfolding cube_exitv_def cube_exiti_def\n  apply (rule aform.clw_rel_appr1_relI)\n  using that\n  by (auto simp: aform.c1_info_invar_def power2_eq_square)\n\ndefinition \"lorenz_interrupt (optns::real aform numeric_options) b (eX::3 eucl1 set) =\n  do {\n    ((el, eu), X) \\<leftarrow> scaleR2_rep eX;\n    let fX = fst ` X;\n    fentry \\<leftarrow> op_image_fst_ivl (cube_enter::3 vec1 set);\n    interrupt \\<leftarrow> aform.op_subset (fX:::aform.appr_rel) fentry;\n    (ol, ou) \\<leftarrow> ivl_rep fentry;\n    aform.CHECKs (ST ''asdf'') (0 < el \\<and> ol \\<le> ou);\n    let _ = (if b then aform.trace_set (ST ''Potential Interrupt: '') (Some fX) else ());\n    let _ = (if b then aform.trace_set (ST ''With: '') (Some ({ol .. ou::3 rvec}:::aform.appr_rel)) else ());\n    if \\<not>b \\<or> \\<not>interrupt then RETURN (op_empty_coll, mk_coll eX)\n    else do {\n      vX \\<leftarrow> aform.vec1rep X;\n      let _ = (if b then aform.trace_set1e (ST ''Actual Interrupt: '') (Some eX) else ());\n      let l = (eucl_of_list [-1/2/2,-1/2/2,-1/2/2]::3 rvec);\n      let u = eucl_of_list [1/2/2, 1/2/2, 1/2/2];\n      ASSERT (l \\<le> u);\n      let CX = mk_coll ({l .. u}:::aform.appr_rel);\n      (C0::3 eucl1 set) \\<leftarrow> scaleRe_ivl_coll_spec el eu (fst ` cube_exitv \\<times> UNIV);\n      (C1::3 eucl1 set) \\<leftarrow> scaleRe_ivl_coll_spec el eu (cube_exitv);\n      case vX of None \\<Rightarrow> RETURN (CX, C0)\n      | Some vX \\<Rightarrow> do {\n        b \\<leftarrow> aform.op_subset vX cube_enter;\n        aform.CHECKs (ST ''FAILED: TANGENT VECTORs are not contained'') b;\n        RETURN (CX, C1)\n      }\n    }\n  }\"\nlemma [autoref_rules]:\n  includes autoref_syntax\n  shows\n    \"(real_of_int, real_of_int) \\<in> int_rel \\<rightarrow> rnv_rel\"\n    \"(ldec, ldec) \\<in> Id \\<rightarrow> rnv_rel\"\n    \"(udec, udec) \\<in> Id \\<rightarrow> rnv_rel\"\n  by auto\n\nschematic_goal lorenz_interrupti:\n  includes autoref_syntax\n  assumes[autoref_rules]: \"(bi, b) \\<in> bool_rel\" \"(Xi, X::3 eucl1 set) \\<in> aform.appr1e_rel\"\n    \"(optnsi, optns) \\<in> Id\"\n  shows\n    \"(nres_of ?r, lorenz_interrupt optns b X) \\<in> \\<langle>clw_rel aform.appr_rel \\<times>\\<^sub>r clw_rel aform.appr1e_rel\\<rangle>nres_rel\"\n  unfolding lorenz_interrupt_def\n  including art\n  by autoref_monadic\nconcrete_definition lorenz_interrupti for optnsi1 bi Xi uses\n  lorenz_interrupti[where optnsi = \"optnsi\"\n       and optnsa = \"\\<lambda>_ _ _ _ _ _ _ _. optnsi\"\n         and optnsb = \"\\<lambda>_ _ _ _ _ _ _ _ _. optnsi\"\n       and optnsc = \"\\<lambda>_ _ _ _ _ _ _ _ _ _ _. optnsi\"\n       and optnsd = \"\\<lambda>_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. optnsi\"\n       and optnse = \"\\<lambda>_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. optnsi\"\n       and optnsf = \"\\<lambda>_ _ _ _ _ _ _ _ _. optnsi\"\n         and optns = \"\\<lambda>_ _ _ _ _. optnsi\"\n       for optnsi]\nlemma lorenz_interrupti_refine[autoref_rules]:\n  includes autoref_syntax\n  shows\n  \"(\\<lambda>optnsi bi Xi. (lorenz_interrupti optnsi bi Xi),\n    lorenz_interrupt)\n    \\<in> num_optns_rel \\<rightarrow> bool_rel \\<rightarrow> aform.appr1e_rel \\<rightarrow> \\<langle>clw_rel aform.appr_rel \\<times>\\<^sub>r clw_rel aform.appr1e_rel\\<rangle>dres_nres_rel\"\n  using lorenz_interrupti.refine\n  by (auto simp: nres_rel_def dres_nres_rel_def)\n\ndefinition \"(large_cube::R3 set) = {-1/4 .. 1/4} \\<times> {-1/4 .. 1/4} \\<times> {-1/4 .. 1/4}\"\n\ndefinition \"cube_entry = (cast_eucl1 ` (flow1_of_vec1 ` cube_enter::3 eucl1 set)::R3 c1_info set)\"\ndefinition \"cube_exit = (cast_eucl1 ` (cube_exitv::3 eucl1 set)::R3 c1_info set)\"\n\ntext \\<open>protect locale parameters\\<close>\nlemma flow0_cong[cong]: \"auto_ll_on_open.flow0 ode X = auto_ll_on_open.flow0 ode X\"\n  by (auto simp:)\nlemma existence_ivl0_cong[cong]:\n  \"auto_ll_on_open.existence_ivl0 ode X = auto_ll_on_open.existence_ivl0 ode X\"\n  by (auto simp:)\nlemma Dflow_cong[cong]: \"c1_on_open_euclidean.Dflow ode ode_d X = c1_on_open_euclidean.Dflow ode ode_d X\"\n  by (auto simp:)\nlemma flowsto_cong[cong]:\n  \"c1_on_open_euclidean.flowsto ode ode_d D = c1_on_open_euclidean.flowsto ode ode_d D\"\n  by (auto simp:)\nlemma poincare_mapsto_cong[cong]:\n  \"c1_on_open_euclidean.poincare_mapsto ode X = c1_on_open_euclidean.poincare_mapsto ode X\"\n  by (auto simp:)\nlemma returns_to_cong[cong]:\n  \"auto_ll_on_open.returns_to ode X = auto_ll_on_open.returns_to ode X\"\n  by (auto simp:)\nlemma return_time_cong[cong]:\n  \"auto_ll_on_open.return_time ode X = auto_ll_on_open.return_time ode X\"\n  by (auto simp: )\nlemma poincare_map_cong[cong]:\n  \"auto_ll_on_open.poincare_map ode X = auto_ll_on_open.poincare_map ode X\"\n  by (auto simp: )\n\nlemma eq_nth_iff_index:\n  \"distinct xs \\<Longrightarrow> n < length xs \\<Longrightarrow> i = xs ! n  \\<longleftrightarrow> index xs i = n\"\n  using index_nth_id by fastforce\n\nlemma cast_in_BasisI: \"(cast i::'a) \\<in> Basis\"\n  if \"(i::'c) \\<in> Basis\"\"DIM('c::executable_euclidean_space) = DIM('a::executable_euclidean_space)\"\n  using that\n  by (auto simp: cast_def eucl_of_list_nth inner_Basis if_distrib if_distribR\n      eq_nth_iff_index\n      cong: if_cong)\n\nlemma cast_le_iff: \"(cast (x::'a)::'c) \\<le> y \\<longleftrightarrow> x \\<le> cast y\"\n  if \"DIM('c::executable_euclidean_space) = DIM('a::executable_euclidean_space)\"\n  apply (auto simp: eucl_le[where 'a='a] eucl_le[where 'a='c]\n      dest!: bspec intro!: )\n     apply (rule cast_in_BasisI, assumption)\n     apply (auto simp: that)\n    apply (metis cast_eqI2 cast_inner that)\n     apply (rule cast_in_BasisI, assumption)\n     apply (auto simp: that)\n  apply (metis cast_eqI2 cast_inner that)\n  done\n\nlemma cast_le_cast_iff: \"(cast (x::'a)::'c) \\<le> cast y \\<longleftrightarrow> x \\<le> y\"\n  if \"DIM('c::executable_euclidean_space) = DIM('a::executable_euclidean_space)\"\n  apply (auto simp: eucl_le[where 'a='a] eucl_le[where 'a='c]\n      dest!: bspec intro!: )\n     apply (rule cast_in_BasisI, assumption)\n     apply (auto simp: that)\n     apply (rule cast_in_BasisI, assumption)\n     apply (auto simp: that)\n  by (metis cast_eqI2 cast_inner that)\n\nlemma cast_image_Icc[simp]: \"cast ` {a .. b::'c} = {cast a .. cast b::'a}\"\n  if \"DIM('c::executable_euclidean_space) = DIM('a::executable_euclidean_space)\"\n  using that\n  apply (auto simp:  cast_le_iff dest!:)\n  subgoal for x\n    apply (rule image_eqI[where x=\"cast x\"])\n    by (auto simp: cast_le_iff)\n  done\n\nlemma cast_eucl1_image_scaleR2:\n  \"cast_eucl1 ` scaleR2 l u X = scaleR2 l u (cast_eucl1 ` (X::'b c1_info set)::'a c1_info set)\"\n  if \"DIM('a::executable_euclidean_space) = DIM('b::executable_euclidean_space)\"\n  using that\n  apply (auto simp: scaleR2_def image_def vimage_def cast_eucl1_def\n      linear.scaleR linear_cast_bl)\n   apply force+\n  apply (rule exI conjI)+\n    apply assumption\n  apply (rule exI conjI)+\n    apply assumption\n   apply (rule bexI) prefer 2 apply assumption\n   apply force\n  by (auto simp: linear.scaleR linear_cast_bl)\n\nlemma scaleR2_diff_prod2: \"scaleR2 d e (X) - Y \\<times> UNIV = scaleR2 d e (X - Y \\<times> UNIV)\"\n  by (force simp: scaleR2_def vimage_def image_def)\n\nend\n\nlemma (in c1_on_open_euclidean) flowsto_scaleR2I:\n  \"flowsto (scaleR2 d e X0) T (CX \\<times> UNIV) (scaleR2 d e Y)\"\n  if \"flowsto (X0) T (CX \\<times> UNIV) (Y)\"\n  using that\n  apply (auto simp: flowsto_def scaleR2_def)\n  apply (drule bspec, assumption)\n  apply auto\n  apply (rule bexI) prefer 2 apply assumption\n  apply auto\n  subgoal for x a b h\n    by (auto intro!: image_eqI[where x=\"(x, (flow0 a h, Dflow a h o\\<^sub>L b))\"] blinfun_eqI\n        simp: blinfun.bilinear_simps)\n  done\n\ndefinition \"aforms_of_resultrect x0 x1 y0 y1 = aforms_of_ivl (ivl_of_resultrect x0 x1 y0 y1)\"\n\ndefinition \"flatten_varveq x = fst x @ the_default [] (snd x)\"\n\n(*\nLessEqual (N\\<^sub>r e) (N\\<^sub>r em *\\<^sub>e floatarith.Min (norm\\<^sub>e [(3)\\<^sub>e, (6)\\<^sub>e, (9)\\<^sub>e])\n  (norm\\<^sub>e [(4)\\<^sub>e, (7)\\<^sub>e, (10)\\<^sub>e]))\n*)\n\nderive \"show\" ereal\n\ndefinition \\<Sigma>::\"(real*real*real) set\" where\n  \"\\<Sigma> = {(-6, -6, 27) .. (6, 6, 27)}\"\ndefinition \\<Sigma>\\<^sub>l\\<^sub>e::\"(real*real*real) set\" where\n  \"\\<Sigma>\\<^sub>l\\<^sub>e = {(x, y, z). z \\<le> 27}\"\n\ndefinition \"results = symmetrize coarse_results\"\ndefinition \"results_at x = {res \\<in> set results.  x \\<in> source_of_res res}\"\n\ntext \\<open>a part of the stable manifold (up to the (backward) first intersection with \\<open>\\<Sigma>\\<close>)\\<close>\ndefinition \\<Gamma>::\"(real*real*real) set\" where\n  \"\\<Gamma> = {x.\n    {0..} \\<subseteq> lorenz.existence_ivl0 x \\<and>\n    (\\<forall>t>0. lorenz.flow0 x t \\<notin> \\<Sigma>) \\<and>\n    (lorenz.flow0 x \\<longlongrightarrow> 0) at_top}\"\n\ndefinition \"\\<Gamma>\\<^sub>i intr = (if intr then \\<Gamma> else {})\"\ndefinition \"\\<Gamma>\\<^sub>i\\<^sub>v intr = cast ` (\\<Gamma>\\<^sub>i intr)\"\n\ndefinition \"sourcei_of_res res = source_of_res res - (\\<Gamma>\\<^sub>i (invoke_nf res))\"\ndefinition \"resultsi_at x = {res \\<in> set results.  x \\<in> sourcei_of_res res}\"\n\ndefinition \"N = \\<Union>(source_of_res ` (set results))\"\ndefinition \"\\<CC> x = \\<Union>(conefield_of_res ` (results_at x))\"\ndefinition \"R = lorenz.poincare_map \\<Sigma>\"\ndefinition \"DR x = frechet_derivative (lorenz.poincare_map \\<Sigma>) (at x within \\<Sigma>\\<^sub>l\\<^sub>e)\"\ndefinition \"\\<E> x = Min (expansion ` results_at x)\"\ndefinition \"\\<E>\\<^sub>p x = Min (preexpansion ` results_at x)\"\n\nabbreviation returns_to (infixl \"returns'_to\" 50) where\n  \"(x returns_to P) \\<equiv> lorenz.returns_to P x\"\n\nlemma closed_\\<Sigma>[intro, simp]: \"closed \\<Sigma>\"\n  by (auto simp: \\<Sigma>_def)\n\nlemma \\<Gamma>_stable: \"lorenz.stable_on (- \\<Sigma>) \\<Gamma>\"\n  unfolding lorenz.stable_on_def\nproof (intro allI impI)\n  fix t x0\n  assume outside: \"\\<forall>s\\<in>{0<..t}. lorenz.flow0 x0 s \\<in> - \\<Sigma>\"\n  assume assms: \"lorenz.flow0 x0 t \\<in> \\<Gamma>\" \"t \\<in> lorenz.existence_ivl0 x0\" \"0 < t\"\n  from assms have *: \"{0..} \\<subseteq> lorenz.existence_ivl0 (lorenz.flow0 x0 t)\"\n    \"(lorenz.flow0 (lorenz.flow0 x0 t) \\<longlongrightarrow> 0) at_top\"\n    by (auto simp: \\<Gamma>_def)\n  have nonneg_exivl: \"s \\<in> lorenz.existence_ivl0 x0\" if \"s \\<ge> 0\" for s\n  proof (cases \"s \\<le> t\")\n    case True\n    then show ?thesis\n      using \\<open>0 \\<le> s\\<close> assms(2) lorenz.ivl_subset_existence_ivl[of t x0] by auto\n  next\n    case False\n    define u where \"u = s - t\"\n    with False have \"u > 0\" \"s = t + u\" by auto\n    note this(2)\n    also have \"t + u \\<in> lorenz.existence_ivl0 x0\"\n      apply (rule lorenz.existence_ivl_trans)\n       apply fact\n      using * \\<open>u > 0\\<close> by auto\n    finally show ?thesis .\n  qed\n  show \"x0 \\<in> \\<Gamma>\"\n    unfolding \\<Gamma>_def\n  proof (safe intro!: nonneg_exivl)\n    have \"\\<forall>\\<^sub>F s in at_top. (s::real) \\<ge> 0\"\n      using eventually_ge_at_top by blast\n    then have \"\\<forall>\\<^sub>F s in at_top. lorenz.flow0 (lorenz.flow0 x0 t) s = lorenz.flow0 x0 (s + t)\"\n    proof eventually_elim\n      case (elim s)\n      then have \"s \\<in> lorenz.existence_ivl0 x0\"\n        using nonneg_exivl[OF \\<open>0 \\<le> s\\<close>] by simp\n      then have \"lorenz.flow0 (lorenz.flow0 x0 t) s = lorenz.flow0 x0 (t + s)\"\n        apply (subst lorenz.flow_trans)\n        using assms * elim by auto\n      then show ?case by (simp add: ac_simps)\n    qed\n    then have \"((\\<lambda>s. (lorenz.flow0 x0 (s + t))) \\<longlongrightarrow> 0) at_top\"\n      by (blast intro: * Lim_transform_eventually)\n    then show \"(lorenz.flow0 x0 \\<longlongrightarrow> 0) at_top\"\n      unfolding aform.tendsto_at_top_translate_iff .\n  next\n    fix s::real assume s: \"0 < s\" \"lorenz.flow0 x0 s \\<in> \\<Sigma>\"\n    show False\n    proof (cases \"s \\<le> t\")\n      case True\n      then show ?thesis\n        using outside s\n        by (auto simp: \\<Gamma>_def)\n    next\n      case False\n      then obtain u where u: \"u = s - t\" \"u > 0\"\n        by auto\n      then have \"lorenz.flow0 x0 (s) = lorenz.flow0 x0 (t + u)\" by (simp add: algebra_simps)\n      also have \"\\<dots> = lorenz.flow0 (lorenz.flow0 x0 t) u\"\n        apply (subst lorenz.flow_trans)\n        subgoal by fact\n        subgoal unfolding u\n          apply (rule lorenz.diff_existence_ivl_trans) apply fact+\n          apply (rule nonneg_exivl) using \\<open>0 < s\\<close> by simp\n        subgoal by simp\n        done\n      also from assms(1) \\<open>u > 0\\<close> have \"\\<dots> \\<notin> \\<Sigma>\"\n        by (auto simp: \\<Gamma>_def)\n      finally show ?thesis using s\n        by auto\n    qed\n  qed\nqed\n\nlemma (in auto_ll_on_open) stable_on_empty[intro, simp]: \"stable_on asdf {}\"\n  by (auto simp: stable_on_def)\n\nlemma \\<Gamma>\\<^sub>i_stable: \"lorenz.stable_on (- \\<Sigma>) (\\<Gamma>\\<^sub>i b)\"\n  using \\<Gamma>_stable\n  unfolding \\<Gamma>\\<^sub>i_def\n  apply (cases b)\n  subgoal by auto\n  subgoal using lorenz.stable_on_empty\n    by (auto simp: \\<Gamma>\\<^sub>i_def)\n  done\n\ndefinition \"\\<Gamma>\\<^sub>v = (cast ` \\<Gamma>)\"\n\ndefinition \"NF = lorenz.flowsto (cube_entry - \\<Gamma> \\<times> UNIV) {0..} (large_cube \\<times> UNIV) cube_exit\"\n\nlemma NF0: \"lorenz.flowsto ((fst ` cube_entry - \\<Gamma>) \\<times> UNIV) {0..} (large_cube \\<times> UNIV)\n  (fst ` cube_exit \\<times> UNIV)\"\n  if NF\n  using that\n  unfolding NF_def lorenz.flowsto_def\n  apply (auto simp: NF_def)\n  apply (drule bspec, force)\n  by auto\n\nlemma [autoref_rules]: includes autoref_syntax shows \"(\\<lambda>_. (), \\<Gamma>\\<^sub>i\\<^sub>v) \\<in> bool_rel \\<rightarrow> ghost_rel\"\n  by (auto simp: ghost_rel_def)\n\nlemma lorenz_interrupt[le, refine_vcg]:\n  \"lorenz_interrupt optns b X \\<le> SPEC (\\<lambda>(CX, R).\n    lorenz.flowsto ((cast_eucl1 ` X::R3 c1_info set) - (\\<Gamma>\\<^sub>i b \\<times> UNIV)) {0..} (cast ` CX \\<times> UNIV) (cast_eucl1 ` R))\"\n  if NF\n  unfolding lorenz_interrupt_def\n  apply refine_vcg\n  subgoal\n    by (rule lorenz.flowsto_self) auto\n  subgoal\n    by (auto simp: eucl_le[where 'a=\"3 rvec\"] eucl_of_list_inner Basis_list_vec_def Basis_list_real_def)\n  subgoal for a b c d e f g h i j k l m n p\n    apply (auto)\n    apply (simp add: cast_eucl1_image_scaleR2 scaleR2_diff_prod2)\n    apply (erule make_neg_goal)\n    apply (rule lorenz.flowsto_scaleR2I)\n    using NF0[OF that]\n    apply (rule lorenz.flowsto_subset)\n    subgoal for q\n      apply (auto simp: scaleR2_def cast_eucl1_def)\n      apply (auto simp: linear_cast_bl linear.scaleR cube_entry_def cast_eucl1_def image_image)\n      subgoal premises prems for r s t u v\n      proof -\n        from prems have \"fst ` c \\<subseteq> fst ` (cube_enter::3 vec1 set)\"\n          by auto\n        with \\<open>(u, v) \\<in> c\\<close> obtain w where \"((u, w)::3 vec1) \\<in> cube_enter\"\n          by auto\n        from _ this have \"cast u \\<in> (\\<lambda>x. cast (fst (x::3 vec1))) ` cube_enter\"\n          by (rule image_eqI)  auto\n        then show ?thesis using prems\n          by blast\n      qed\n      subgoal by (auto simp: \\<Gamma>\\<^sub>i_def)\n      done\n    subgoal by simp\n    subgoal premises _\n      by (auto simp: eucl_le[where 'a=\"3 rvec\"] eucl_of_list_inner Basis_list_vec_def Basis_list_real_def\n          eucl_of_list_def\n          large_cube_def)\n    subgoal premises prems for x\n      apply (auto simp:)\n      subgoal for A B C D E\n        apply (rule image_eqI[where x=\"cast_eucl1 (((B, C, D), A))\"])\n         apply (auto simp: cast_eucl1_def)\n        subgoal premises prems\n          using prems(1)\n          apply (auto simp: cube_exit_def aform.c1_info_of_apprs_def cube_exiti_def\n              cast_eucl1_def aform.c1_info_of_appr_def)\n          done\n        done\n      done\n    done\n  subgoal for a b c d e f g h i j k l m n p\n    apply (auto)\n    apply (erule make_neg_goal, thin_tac \"\\<not> _\")\n    apply (simp add: cast_eucl1_image_scaleR2 scaleR2_diff_prod2)\n    apply (rule lorenz.flowsto_scaleR2I)\n    using that[unfolded NF_def]\n    apply (rule lorenz.flowsto_subset)\n    subgoal for q\n      apply (auto simp: scaleR2_def cast_eucl1_def )\n      apply (auto simp: linear_cast_bl linear.scaleR cube_entry_def cast_eucl1_def image_image)\n      subgoal premises prems for r s t u v\n      proof -\n        from prems have \\<open>vec1_of_flow1 (u, v) \\<in> cube_enter\\<close>\n          by auto\n        from _ this have \"(cast u, cast_bl v) \\<in> (\\<lambda>x. (cast (fst (x::3 vec1)), cast_bl (snd (flow1_of_vec1 x)))) ` cube_enter\"\n          by (rule image_eqI) (auto simp: )\n        then show ?thesis\n          using prems by blast\n      qed\n      subgoal by (auto simp: \\<Gamma>\\<^sub>i_def)\n      done\n    subgoal by simp\n    subgoal premises _\n      by (auto simp: eucl_le[where 'a=\"3 rvec\"] eucl_of_list_inner Basis_list_vec_def Basis_list_real_def\n          eucl_of_list_def\n          large_cube_def)\n    subgoal by (simp add: cube_exit_def)\n    done\n  done\n\n\ndefinition \"lorenz_S X = (case X of (x, y, z) \\<Rightarrow> (-x, -y, z))\"\n\nlemma lorenz_symI: \"((\\<lambda>t. lorenz_S (f t)) has_vderiv_on lf') T\"\n  if \"(f has_vderiv_on f') T\" \"\\<And>t. t \\<in> T \\<Longrightarrow> lf' t = lorenz_S (f' t)\"\n  using that\n  by (auto simp: has_vderiv_on_def lorenz_S_def  split_beta' has_vector_derivative_def\n      intro!: derivative_eq_intros)\n\nlemma lorenz_S:\n  \"t \\<in> lorenz.existence_ivl0 (lorenz_S X)\" (is ?th1)\n  \"lorenz.flow0 (lorenz_S X) t = lorenz_S (lorenz.flow0 X t)\" (is ?th2)\n  if \"t \\<in> lorenz.existence_ivl0 X\"\nproof -\n  have 1: \"((\\<lambda>t. lorenz_S (lorenz.flow0 X t)) solves_ode\n     (\\<lambda>_ (X0, X1, X2).\n         (E1 * X0 - K1 * (X0 + X1) * X2,\n          E2 * X1 + K1 * (X0 + X1) * X2,\n          E3 * X2 + (X0 + X1) * (K2 * X0 + K3 * X1))))\n     {0--t} UNIV\"\n    apply (rule solves_odeI)\n     apply (rule lorenz_symI)\n      apply (rule lorenz.flow_has_vderiv_on_compose)\n          apply simp\n         apply simp\n        apply (rule derivative_intros)\n        apply (rule refl)\n    using that\n       apply (rule lorenz.in_existence_between_zeroI)\n       apply assumption\n      apply (rule refl)\n    unfolding lorenz_S_def\n     apply (split prod.splits)+\n     apply (simp add: field_simps)\n    apply simp\n    done\n  have \"lorenz.flow0 X 0 = X\"\n    unfolding lorenz.flow_initial_time_if\n    by simp\n  then have 2:\n    \"lorenz_S (lorenz.flow0 X 0) = lorenz_S X\"\n    \"is_interval {0--t}\"\n    \"0 \\<in> {0--t}\"\n    \"{0--t} \\<subseteq> UNIV\"\n    by auto\n  from lorenz.maximal_existence_flow[OF 1 2]\n  show ?th1 ?th2 by fast+\nqed\n\nlemma \\<Sigma>\\<^sub>l\\<^sub>e_impl[autoref_rules]: \"(Sctn [0, 0, 1] 27, \\<Sigma>\\<^sub>l\\<^sub>e) \\<in> \\<langle>lv_rel\\<rangle>below_rel\"\n  apply (auto simp: below_rel_def \\<Sigma>\\<^sub>l\\<^sub>e_def below_halfspace_def sctn_rel_def\n      intro!: relcompI[where b=\"Sctn (0, 0, 1) 27\"] brI lv_relI)\n  subgoal\n    unfolding lv_rel_def\n    by (auto intro!: brI)\n  unfolding le_halfspace_def\n  by (auto intro!: brI)\n\nlemma [autoref_rules]: \"((), \\<Gamma>\\<^sub>v) \\<in> ghost_rel\"\n  by (auto intro!: ghost_relI)\n\nno_notation vec_nth (infixl \"$\" 90) and vec_lambda (binder \"\\<chi>\" 10)\n\nabbreviation \"guards_rel \\<equiv> \\<langle>clw_rel (\\<langle>\\<langle>lv_rel\\<rangle>ivl_rel, \\<langle>lv_rel\\<rangle>plane_rel\\<rangle>inter_rel) \\<times>\\<^sub>r aform.reach_optns_rel\\<rangle>list_rel\"\n\n\ndefinition \"aform_poincare_onto_from optns = aform.poincare_onto_from\"\n\nlemma aform_poincare_onto_from[autoref_rules]:\n  includes autoref_syntax\n  shows\n\"DIM_precond TYPE('b rvec) E \\<Longrightarrow>\n    (XSi, XS::'b::enum eucl1 set) \\<in> clw_rel aform.appr1e_rel \\<Longrightarrow>\n    (sctni, sctn) \\<in> \\<langle>lv_rel\\<rangle>sctn_rel \\<Longrightarrow>\n    (ivli, ivl) \\<in> \\<langle>lv_rel\\<rangle>ivl_rel \\<Longrightarrow>\n    (Si, Sa) \\<in> \\<langle>lv_rel\\<rangle>halfspaces_rel \\<Longrightarrow>\n    (guardsi, guards) \\<in> guards_rel \\<Longrightarrow>\n    (symstartd, symstart) \\<in> aform.appr1e_rel \\<rightarrow> \\<langle>clw_rel aform.appr_rel \\<times>\\<^sub>r clw_rel aform.appr1e_rel\\<rangle>dres_nres_rel \\<Longrightarrow>\n    ((), trap) \\<in> ghost_rel \\<Longrightarrow>\n    (roi, roptn) \\<in> aform.reach_optns_rel \\<Longrightarrow>\n    (odoi, odo) \\<in> ode_ops_rel \\<Longrightarrow>\n    (optnsi, optns) \\<in> num_optns_rel \\<Longrightarrow>\n    (nres_of\n      (solve_poincare_map_aform optnsi E odoi symstartd Si guardsi ivli\n        sctni roi XSi),\n     aform_poincare_onto_from $ optns $ odo $ symstart $ trap $ Sa $ guards $\n     ivl $\n     sctn $\n     roptn $\n     XS)\n    \\<in> \\<langle>clw_rel aform.appr1e_rel\\<rangle>nres_rel\"\n  unfolding autoref_tag_defs aform_poincare_onto_from_def\n  using aform.poincare_onto_from_impl.refine[OF _ aform_ncc aform_ncc,\n      where 'a='b, of E odoi odo XSi XS Si Sa guardsi guards ivli ivl sctni sctn roi roptn\n        \"(\\<lambda>x. nres_of (symstartd x))\" symstart symstartd trap optnsi,\n        unfolded autoref_tag_defs, OF _ _ _ _ _ _ _ _ _ order_refl]\n  by (auto simp: dest!: aform.dres_nres_rel_nres_relD)\n\ndefinition \"lorenz_odo_impl = init_ode_ops True True lorenz.odo\"\ninterpretation autoref_op_pat_def lorenz.odo .\nlemma lorenz_odo_impl[autoref_rules]: \"(lorenz_odo_impl, lorenz.odo) \\<in> ode_ops_rel\"\n  by (auto simp: ode_ops_rel_def lorenz_odo_impl_def)\n\ndefinition lorenz_poincare where\n \"lorenz_poincare optns interrupt guards roptn XS0 =\n    aform_poincare_onto_from optns lorenz.odo\n      (lorenz_interrupt optns interrupt)\n      (\\<Gamma>\\<^sub>i\\<^sub>v interrupt:::ghost_rel)\n      ((below_halfspaces {Sctn (eucl_of_list [0, 0, 1]) 27}::(real^3) set):::\\<langle>lv_rel\\<rangle>halfspaces_rel)\n      guards\n      (op_atLeastAtMost_ivl (eucl_of_list [-6, -6, 27]:::lv_rel) (eucl_of_list [6, 6, 27]:::lv_rel):::lvivl_rel::(real^3) set)\n       (Sctn (eucl_of_list [0, 0, -1]) (- 27)::(real^3) sctn)\n      roptn\n      XS0\"\n\nlemma [autoref_rules_raw]:\n  includes autoref_syntax\n  shows \"((),\n     (OP \\<Gamma>\\<^sub>i\\<^sub>v ::: bool_rel \\<rightarrow> ghost_rel) $\n     (OP intr ::: bool_rel))\n    \\<in> ghost_rel\" by (auto simp: ghost_rel_def)\n\nschematic_goal lorenz_poincare_impl[autoref_rules]:\n  includes autoref_syntax\n  assumes [autoref_rules]: \"(XSi, XS) \\<in> clw_rel aform.appr1e_rel\"\n    \"(intri, intr) \\<in> bool_rel\"\n    \"(guardsi, guards) \\<in> guards_rel\"\n    \"(roi, roptn) \\<in> aform.reach_optns_rel\"\n    \"(optnsi, optns) \\<in> num_optns_rel\"\n  shows \"(nres_of ?r, lorenz_poincare $ optns $ intr $ guards $ roptn $ XS) \\<in>\n    \\<langle>clw_rel aform.appr1e_rel\\<rangle>nres_rel\"\n  unfolding autoref_tag_defs\n  unfolding lorenz_poincare_def\n  including art\n  supply [autoref_rules_raw] = ghost_relI\n  by autoref_monadic\n\nlemma cast_image_eqI: \"cast ` X = Y\"\n  if \"DIM('a) = DIM('b)\"\n    \"(X::'a::executable_euclidean_space set) = cast ` (Y::'b::executable_euclidean_space set)\"\n  using that\n  by (auto simp: image_image)\n\nlemma transfer_\\<Gamma>[transfer_rule]: \"(rel_set lorenz.rel_ve) \\<Gamma>\\<^sub>v \\<Gamma>\"\n  unfolding \\<Gamma>\\<^sub>v_def\n  by (auto simp: lorenz.rel_ve_cast' intro!: rel_setI)\n\nlemma transfer_\\<Sigma>\\<^sub>l\\<^sub>e[transfer_rule]: \"(rel_set lorenz.rel_ve) (cast ` \\<Sigma>\\<^sub>l\\<^sub>e) \\<Sigma>\\<^sub>l\\<^sub>e\"\n  by (auto simp: lorenz.rel_ve_cast' intro!: rel_setI)\n\nlemma transfer_\\<Gamma>\\<^sub>i[transfer_rule]: \"(rel_fun (=) (rel_set lorenz.rel_ve)) \\<Gamma>\\<^sub>i\\<^sub>v \\<Gamma>\\<^sub>i\"\n  unfolding \\<Gamma>\\<^sub>i\\<^sub>v_def\n  by (auto simp: lorenz.rel_ve_cast' intro!: rel_setI)\n\nlemma transfer_\\<Sigma>[transfer_rule]: \"(rel_set lorenz.rel_ve) (cast ` \\<Sigma>) \\<Sigma>\"\n  by (auto simp: lorenz.rel_ve_cast' intro!: rel_setI)\n\nlemma len_fas: \"length lorenz_fas = 3\"\n  by (auto simp: lorenz_fas_def)\n\nlemma lorenz_poincare[le, refine_vcg]:\n  \"lorenz_poincare optns intr guards roptn XS \\<le> SPEC (\\<lambda>R.\n    aform.poincare_mapsto lorenz.odo (cast ` \\<Sigma>) (XS - (\\<Gamma>\\<^sub>i\\<^sub>v intr \\<times> UNIV)) (cast ` \\<Sigma>\\<^sub>l\\<^sub>e)\n   UNIV R)\"\n  if [refine_vcg]: NF\n  unfolding lorenz_poincare_def aform_poincare_onto_from_def\n  apply (refine_vcg)\n  subgoal  by (simp add: aform.wd_def aform.ode_e_def len_fas)\n  subgoal for a b c d\n    apply (auto simp: lorenz.flowsto_eq[symmetric])\n  proof goal_cases\n    case 1\n    from 1(2)[unfolded lorenz.flowsto_eq[symmetric]]\n    show ?case\n      by transfer (simp add: lorenz.avflowsto_eq)\n  qed\n  subgoal\n    unfolding aform.stable_on_def unfolding autoref_tag_defs\n  proof (intro allI impI, goal_cases)\n    case (1 t x0)\n    from 1 have t: \"t \\<in> lorenz.v.existence_ivl0 x0\"\n      using lorenz.vex_ivl_eq by simp\n    from 1 have f: \"lorenz.v.flow0 x0 t \\<in> \\<Gamma>\\<^sub>i\\<^sub>v intr\"\n      using lorenz.vflow_eq[OF t] by simp\n    from 1 have \"lorenz.v.flow0 x0 s \\<in> - cast ` \\<Sigma>\"\n      if \"s\\<in>{0<..t}\" for s\n    proof -\n      from that t have s: \"s \\<in> lorenz.v.existence_ivl0 x0\"\n        by (auto dest!: lorenz.a.v.closed_segment_subset_existence_ivl\n            simp: closed_segment_eq_real_ivl)\n      have \"lorenz.v.flow0 x0 s\n        \\<in> aform.Csafe lorenz.odo -\n           op_atLeastAtMost_ivl (eucl_of_list [- 6, - 6, 27]) (eucl_of_list [6, 6, 27]) \\<inter>\n           plane_of (Sctn (eucl_of_list [0, 0, - 1]) (- 27))\"\n        using 1(4)[rule_format, OF that]\n        unfolding lorenz.vflow_eq[OF s] \n        by auto\n      also have \"\\<dots> \\<subseteq> - cast ` \\<Sigma>\"\n        by (auto simp: eucl_le[where 'a=\"real^3\"] eucl_of_list_inner axis_eq_axis\n               cast_def Basis_list_real_def Basis_list_vec3 \\<Sigma>_def plane_of_def\n               eucl_of_list_inner_eq inner_lv_rel_def)\n      finally show \"lorenz.v.flow0 x0 s \\<in> - cast ` \\<Sigma>\" .\n    qed\n    show \"x0 \\<in> \\<Gamma>\\<^sub>i\\<^sub>v intr\"\n      by (rule \\<Gamma>\\<^sub>i_stable[Transfer.untransferred, unfolded lorenz.v.stable_on_def, rule_format])\n        fact+\n  qed\n  subgoal for R\n  proof (clarsimp, goal_cases)\n    case 1\n    note 1(2)\n    also have \"({eucl_of_list [- 6, - 6, 27]..eucl_of_list [6, 6, 27]::3 rvec} \\<inter>\n      plane_of (Sctn (eucl_of_list [0, 0, - 1]) (- 27))) = cast ` \\<Sigma>\"\n      apply auto\n      apply (auto simp: \\<Sigma>_def  o_def plane_of_def \n          eucl_of_list_def Basis_list_R3 Basis_list_vec3)\n      subgoal\n        by (auto simp: cast_def eucl_of_list_def Basis_list_R3 Basis_list_vec3)\n      subgoal\n        by (auto simp: cast_def eucl_of_list_def Basis_list_R3 Basis_list_vec3)\n      subgoal\n        apply (auto simp: cast_le_iff[symmetric])\n        by (auto simp: cast_def eucl_of_list_def Basis_list_R3 Basis_list_vec3 less_eq_prod_def\n            list_of_eucl_def inner_simps inner_axis_axis)\n      subgoal\n        apply (auto simp: cast_le_iff)\n        by (auto simp: cast_def eucl_of_list_def Basis_list_R3 Basis_list_vec3 less_eq_prod_def\n            list_of_eucl_def inner_simps inner_axis_axis)\n      subgoal\n        by (auto simp: cast_def eucl_of_list_def Basis_list_R3 Basis_list_vec3 less_eq_prod_def\n            list_of_eucl_def inner_simps inner_axis_axis)\n      done\n    also have \"(below_halfspaces {Sctn (eucl_of_list [0, 0, 1]::3 rvec) 27}) = (cast ` \\<Sigma>\\<^sub>l\\<^sub>e)\"\n      apply (auto simp: \\<Sigma>\\<^sub>l\\<^sub>e_def below_halfspaces_def below_halfspace_def le_halfspace_def\n                    eucl_of_list_def Basis_list_R3 Basis_list_vec3)\n       apply (rule image_eqI)\n        apply (rule cast_cast[symmetric])\n      by (auto simp:  cast_def list_of_eucl_def o_def plane_of_def inner_simps inner_axis_axis\n          eucl_of_list_def Basis_list_R3 Basis_list_vec3)\n    finally\n    show ?case\n      by (rule aform.poincare_mapsto_subset) (force simp: lorenz.vX_def intro: cast_cast[symmetric])+\n  qed\n  done\n\ncontext includes floatarith_notation begin\n\ndefinition \"mat1\\<^sub>e =\n  [Var 0, Var 1, Var 2,   Var 3, 0, 0,\n                          Var 4, 0, 0,\n                          Var 5, 0, 0]\"\n\ndefinition mat1_nres::\"3 rvec set \\<Rightarrow> 3 rvec set \\<Rightarrow> 3 eucl1 set nres\"\n  where\n\"mat1_nres X v = do {\n  Xv \\<leftarrow> aform.approx_slp_appr mat1\\<^sub>e (slp_of_fas mat1\\<^sub>e) (concat ` listset [list_of_eucl ` X, list_of_eucl ` v]);\n  RETURN (flow1_of_vec1 ` Xv)\n}\"\nlemma [simp]: \"(x, x') \\<in> aform.appr_rel \\<Longrightarrow> aform.ncc x'\"\n  using aform_ncc[where 'a='a]\n  by (auto simp: aform.ncc_precond_def)\nlemma mat1e_autoref[autoref_rules]: \"(mat1\\<^sub>e, mat1\\<^sub>e) \\<in> \\<langle>Id\\<rangle>list_rel\"\n  by auto\nschematic_goal mat1_impl:\n  includes autoref_syntax\n  assumes [autoref_rules]: \"(Xi, X) \\<in> aform.appr_rel\" \"(vi, v) \\<in> aform.appr_rel\"\n  shows \"(nres_of ?r, mat1_nres $ X $ v) \\<in> \\<langle>aform.appr1_rel\\<rangle>nres_rel\"\n  unfolding mat1_nres_def\n  including art\n  by autoref_monadic\nconcrete_definition mat1_impl for Xi vi uses mat1_impl\nlemmas [autoref_rules] = mat1_impl.refine\n\nlemma mat_nres[le, refine_vcg]:\n  \"mat1_nres X v \\<le> SPEC (\\<lambda>M. X \\<times> v \\<subseteq> (\\<lambda>x. (fst x, blinfun_apply (snd x) (eucl_of_list [1, 0, 0]))) ` M)\"\n  unfolding mat1_nres_def\n  apply refine_vcg\n  apply (auto simp: dest!: bspec)\n  apply (auto simp: mat1\\<^sub>e_def image_image )\n  subgoal for x a b\n    apply (rule image_eqI[where x=\"eucl_of_list\n     [(list_of_eucl a @ list_of_eucl b) ! 0, (list_of_eucl a @ list_of_eucl b) ! Suc 0,\n      (list_of_eucl a @ list_of_eucl b) ! 2, (list_of_eucl a @ list_of_eucl b) ! 3, 0, 0,\n      (list_of_eucl a @ list_of_eucl b) ! 4, 0, 0, (list_of_eucl a @ list_of_eucl b) ! 5, 0, 0]\"])\n     apply (auto simp: eucl_of_list_prod eucl_of_list_inner nth_append Basis_list_vec3\n        intro!: euclidean_eqI[where 'a=\"3 rvec\"])\n    unfolding Basis_list[symmetric] Basis_list_vec3\n    by (auto simp: flow1_of_vec1_def blinfun_of_vmatrix.rep_eq Basis_list_vec3 inner_simps\n        matrix_vector_mult_eq_list_of_eucl_nth ll3 inner_axis_axis)\n  done\n\ndefinition [simp]: \"op_image_cast_eucl1e = (`) cast_eucl1\"\ndefinition [simp]: \"op_image_cast_eucl1e_coll = (`) cast_eucl1\"\n\nlemma prod_relI'': \"\\<lbrakk>(fst ab, a')\\<in>R1; (snd ab, b')\\<in>R2\\<rbrakk> \\<Longrightarrow> (ab,(a', b'))\\<in>\\<langle>R1,R2\\<rangle>prod_rel\"\n  by  (auto simp: prod_rel_def)\n\nlemma strange_aux_lemma:\n  \"(b, b') \\<in> A \\<Longrightarrow> (b, snd (a'a, b')) \\<in> A\"\n  by auto\n\nlemma [autoref_rules]:\n  includes autoref_syntax\n  assumes\n    \"DIM_precond TYPE('a::executable_euclidean_space) D\"\n    \"DIM_precond TYPE('b::executable_euclidean_space) D\"\n  shows\n    \"(\\<lambda>x. x, (op_image_cast_eucl1e::('a::executable_euclidean_space c1_info set \\<Rightarrow> 'b::executable_euclidean_space c1_info set))) \\<in> aform.appr1e_rel \\<rightarrow> aform.appr1e_rel\"\n    (is ?th1)\n    and \"(\\<lambda>x. x, op_image_cast_eucl1e_coll::'a::executable_euclidean_space c1_info set \\<Rightarrow> 'b::executable_euclidean_space c1_info set) \\<in> clw_rel aform.appr1e_rel \\<rightarrow> clw_rel aform.appr1e_rel\"\n    (is ?th2)\nproof -\n  show 1: ?th1\n    unfolding scaleR2_rel_def\n    apply (rule subsetD)\n     apply (rule fun_rel_comp_dist)\n    apply (rule relcompI)\n     apply (rule fun_relI)\n     apply (erule prod_relE)\n     apply simp\n     apply (rule prod_relI)\n      apply simp\n      apply (rule fst_conv[symmetric])\n     apply (rule op_cast_eucl1_image_impl[OF assms, param_fo])\n     apply (rule strange_aux_lemma)\n     apply (auto simp: br_def scaleR2_def image_def vimage_def\n        cast_eucl1_def)\n    subgoal for a b c d e f g\n      apply (rule exI[where x=e] conjI)+\n       apply assumption\n      apply (rule exI conjI)+\n       apply assumption\n      apply (rule exI conjI)+\n       apply (rule bexI) prefer 2 apply assumption\n       apply (rule conjI) apply force\n       apply (rule refl)\n      using assms\n      by (auto simp: blinfun.bilinear_simps linear_cast linear.scaleR\n          intro!: blinfun_eqI)\n    subgoal for a b c d e f g\n      apply (rule exI[where x=e] exI conjI)+\n        apply assumption\n       apply (rule exI conjI)+\n        apply assumption\n       apply (rule bexI) prefer 2 apply assumption\n       apply force\n      using assms\n      by (auto simp: blinfun.bilinear_simps linear_cast linear.scaleR\n          intro!: blinfun_eqI)\n    done\n  have id_map: \"(\\<lambda>x. x) = (map (\\<lambda>x. x))\" by simp\n  show ?th2\n    apply (subst id_map)\n    apply (rule lift_clw_rel_map)\n       apply (rule relator_props)+\n    subgoal using 1 by auto\n    subgoal by auto\n    done\nqed\n\ndefinition \"lorenz_poincare_tangents optns interrupt guards roptn c1 (X0::R3 set) (tangents::R3 set) =\n  do {\n    X0tanmat \\<leftarrow> (if c1 then\n      do {\n        R \\<leftarrow> mat1_nres (cast ` X0) (cast ` tangents);\n        RETURN (R::3 eucl1 set)\n      } else RETURN (cast ` X0 \\<times> UNIV));\n    XDX0 \\<leftarrow> scaleRe_ivl_spec 1 1 (X0tanmat);\n    let _ = aform.trace_set1e ''START'' (Some XDX0);\n    let _ = aform.print_set1e False (XDX0);\n    P \\<leftarrow> lorenz_poincare optns interrupt guards roptn ((mk_coll XDX0:::clw_rel aform.appr1e_rel));\n    RETURN (op_image_cast_eucl1e_coll P::R3 c1_info set)\n  }\"\nlemma [autoref_rules_raw]: \"DIM(real \\<times> real \\<times> real) = DIM((real, 3) vec)\"\n  by auto\n\nschematic_goal lorenz_poincare_tangents_impl:\n  includes autoref_syntax\n  assumes [autoref_rules]:\n    \"(optnsi, optns) \\<in> Id\"\n    \"(intrri, intr) \\<in> bool_rel\"\n    \"(guardsi, guards) \\<in> guards_rel\"\n    \"(roi, roptn) \\<in> aform.reach_optns_rel\"\n    \"(c1i, c1) \\<in> bool_rel\"\n    \"(X0i, X0) \\<in> aform.appr_rel\"\n    \"(tangentsi, tangents) \\<in> aform.appr_rel\"\n  shows\n  \"(nres_of ?r, lorenz_poincare_tangents $ optns $ intr $ guards $ roptn $ c1 $ (X0::R3 set) $ tangents) \\<in>\n    \\<langle>clw_rel aform.appr1e_rel\\<rangle>nres_rel\"\n  unfolding lorenz_poincare_tangents_def\n  including art\n  by (autoref_monadic)\n\nconcrete_definition lorenz_poincare_tangents_impl uses\n  lorenz_poincare_tangents_impl[where\n     optnsa = \"\\<lambda>_ _ _ _ _ _ _ _. optns\"\n    and optnsb = \"\\<lambda>_ _ _ _ _ _ _ _ _. optns\"\n    and optnsi = \"optns\"\n    and optnsc = \"optns\"\n    and optns = \"\\<lambda>_ _ _ _ _ _ _. optns\"\n  for optns optnsc]\nlemma lorenz_poincare_tangents_impl_refine[autoref_rules]:\n  includes autoref_syntax\n  shows\n  \"(\\<lambda>optnsi intrri guardsi roi c1i X0i tangentsi. nres_of\n    (lorenz_poincare_tangents_impl optnsi intrri guardsi roi c1i X0i tangentsi),\n   lorenz_poincare_tangents)\n  \\<in> num_optns_rel \\<rightarrow> bool_rel \\<rightarrow> guards_rel \\<rightarrow> aform.reach_optns_rel \\<rightarrow> bool_rel \\<rightarrow> aform.appr_rel \\<rightarrow>\n    aform.appr_rel \\<rightarrow>\n    \\<langle>clw_rel aform.appr1e_rel\\<rangle>nres_rel\"\n  using lorenz_poincare_tangents_impl.refine by force\n\nlemma transfer_UNIV_rel_blinfun[transfer_rule]:\n  \"(rel_set (rel_blinfun lorenz.rel_ve lorenz.rel_ve)) UNIV UNIV\"\n  apply (auto intro!: rel_setI simp: rel_blinfun_def)\n  subgoal for x\n    apply (rule exI[where x=\"cast_bl x\"])\n    by (auto intro!: rel_funI simp: lorenz.rel_ve_cast)\n  subgoal for x\n    apply (rule exI[where x=\"cast_bl x\"])\n    by (auto intro!: rel_funI simp: lorenz.rel_ve_cast)\n  done\n\nlemma lorenz_vX[simp]: \"lorenz.vX = (UNIV::3 rvec set)\"\n  by (force simp: lorenz.vX_def intro!: cast_cast[symmetric])\n\nlemma closed_cast_\\<Sigma>[intro, simp]: \"closed (cast ` \\<Sigma>::3 rvec set)\"\n  by (auto simp: \\<Sigma>_def )\nlemma blinfun_apply_transfer[transfer_rule]:\n  \"(rel_fun (rel_blinfun lorenz.rel_ve lorenz.rel_ve)\n       (rel_fun (rel_prod (=) (rel_prod (=) (=))) lorenz.rel_ve))\n     (blinfun_apply o cast_bl) blinfun_apply\"\n  by (auto intro!: rel_funI simp: rel_blinfun_def lorenz.rel_ve_cast\n      dest!: rel_funD)\n\nlemma lorenz_poincare_tangents[le, refine_vcg]:\n  \"lorenz_poincare_tangents optns intr guards roptn c1 (X0::R3 set) tangents \\<le>\n    SPEC (\\<lambda>x.\n      (if c1 then \\<exists>tans. X0 \\<times> tangents \\<subseteq> (\\<lambda>(x, y). (x, blinfun_apply y (1, 0, 0))) ` tans \\<and> lorenz.poincare_mapsto \\<Sigma> (tans - \\<Gamma>\\<^sub>i intr \\<times> UNIV) (\\<Sigma>\\<^sub>l\\<^sub>e) UNIV x\n       else lorenz.poincare_mapsto \\<Sigma> ((X0 - \\<Gamma>\\<^sub>i intr) \\<times> UNIV) (\\<Sigma>\\<^sub>l\\<^sub>e) UNIV x))\"\n  if [refine_vcg]: NF\n  unfolding lorenz_poincare_tangents_def\n  apply refine_vcg\n   apply auto\n   apply (subst lorenz.poincare_mapsto_eq[symmetric])\n    apply simp\nproof goal_cases\n  case (2 R)\n  then show ?case\n    apply transfer\n    apply (subst lorenz.vpoincare_mapsto_eq[symmetric])\n     apply (auto simp: )\n    apply (rule aform.poincare_mapsto_subset, assumption)\n    by (force simp: scaleR2_def )+\nnext\n  case (1 tans R)\n  show ?case\n    apply (rule exI[where x=\"cast_eucl1 ` tans\"])\n    apply (rule conjI)\n    subgoal including lifting_syntax\n      using 1(2)\n      by transfer (force simp: cast_def o_def)\n    subgoal\n      using 1(3) apply transfer\n      apply (subst lorenz.avpoincare_mapsto_eq[symmetric])\n      by (auto simp: )\n    done\nqed\n\ndefinition of_mat1_image::\"R3 c1_info set \\<Rightarrow> R3 set nres\"\n  where [refine_vcg_def]: \"of_mat1_image X = SPEC (\\<lambda>R. R = (\\<lambda>x. blinfun_apply (snd x) (1, 0, 0)) ` X)\"\n\nlemma of_mat1_image_impl[autoref_rules]:\n  \"(\\<lambda>x. (case x of (_, Some xs) \\<Rightarrow> RETURN [xs ! 0, xs ! 3, xs ! 6]\n          | (_, None) \\<Rightarrow> SUCCEED), of_mat1_image) \\<in> aform.appr1_rel \\<rightarrow> \\<langle>aform.appr_rel\\<rangle>nres_rel\"\n  apply (auto simp: of_mat1_image_def RETURN_RES_refine_iff nres_rel_def\n      aform.appr1_rel_internal aform.appr_rel_def\n      intro!: relcompI\n      split: option.splits)\n  unfolding aforms_rel_def\n   apply (rule brI)\n    apply (auto simp: )\n  unfolding lv_rel_def set_rel_br\n  apply (rule brI)\n   prefer 2 apply (force simp: Joints_imp_length_eq)\n  apply (auto elim!: mem_Joints_appendE simp: flow1_of_list_def Joints_imp_length_eq)\n  subgoal for a b c d e f g h i j\n    apply (rule image_eqI[where x=\"[j ! 0, j ! 3, j! 6]\"])\n     apply (auto simp: blinfun_of_list_def blinfun_of_matrix_apply\n        Basis_prod_def Basis_list_R3 Basis_list_vec3 eval_nat_numeral zero_prod_def)\n    apply (rule map_nth_Joints'[of _ _ \"[0, Suc (Suc (Suc 0)), Suc (Suc (Suc (Suc (Suc (Suc 0)))))]\",\n          simplified])\n    apply auto\n    done\n  subgoal for a b c d e f\n    unfolding image_image\n    apply (auto simp: Joints_def valuate_def)\n    subgoal for g\n      apply (rule image_eqI)\n      prefer 2\n      apply (rule image_eqI[where x=g])\n      apply (rule refl)\n      apply (auto simp: )\n      apply (auto simp: blinfun_of_list_def blinfun_of_matrix_apply flow1_of_list_def\n          Basis_prod_def Basis_list_R3 Basis_list_vec3 eval_nat_numeral zero_prod_def)\n      done\n    done\n  done\n\ndefinition [refine_vcg_def]: \"floatdegs res = SPEC (\\<lambda>_::unit. min_deg res \\<in> float \\<and> max_deg res \\<in> float)\"\ndefinition [simp]: \"isinfloat x \\<longleftrightarrow> x \\<in> float\"\n\n\nlemma floatdegs_impl[autoref_rules]:\n  includes autoref_syntax\n  shows\n  \"(\\<lambda>res. (if isinfloat (min_deg res) \\<and> isinfloat (max_deg res) then RETURN () else SUCCEED), floatdegs)\n    \\<in> Id \\<rightarrow> \\<langle>unit_rel\\<rangle>nres_rel\"\n  by (auto simp: nres_rel_def floatdegs_def)\n\ndefinition \"check_c1_entry optns em P (res0::result) (res::result) = do {\n    uv_ret \\<leftarrow> of_mat1_image P;\n    nuv \\<leftarrow> aform.mig_set 3 uv_ret;\n    floatdegs res0;\n    floatdegs res;\n    let e' = em * ereal nuv;\n    b1 \\<leftarrow> approx_conefield_bounds P (min_deg res) (max_deg res);\n    let b2 = e' \\<ge> preexpansion res;\n    let b3 = e' \\<ge> expansion res0;\n    let _ = aform.print_msg ((shows ''# check_c1_entry: '' o shows_list [b1, b2, b3] o shows_space o\n      shows_list [e', preexpansion res, expansion res0]) '''');\n    RETURN (em \\<ge> 0 \\<and> b1 \\<and> b2 \\<and> b3)\n  }\"\n\nlemma [autoref_itype]:\n  \"shows_prec ::\\<^sub>i i_nat \\<rightarrow>\\<^sub>i A \\<rightarrow>\\<^sub>i i_string \\<rightarrow>\\<^sub>i i_string\"\n  by auto\n\nlemma [autoref_rules]:\n  includes autoref_syntax\n  shows\n    \"PREFER_id A \\<Longrightarrow> (shows_list, shows_list) \\<in> \\<langle>A\\<rangle>list_rel \\<rightarrow> string_rel \\<rightarrow> string_rel\"\n    \"(shows_prec, shows_prec) \\<in> nat_rel \\<rightarrow> string_rel \\<rightarrow> string_rel \\<rightarrow> string_rel\"\n    \"(shows_prec, shows_prec) \\<in> nat_rel \\<rightarrow> ereal_rel \\<rightarrow> string_rel \\<rightarrow> string_rel\"\n    \"(shows_prec, shows_prec::_\\<Rightarrow>result \\<Rightarrow>_) \\<in> nat_rel \\<rightarrow> Id \\<rightarrow> string_rel \\<rightarrow> string_rel\"\n    \"(shows_space, shows_space) \\<in> string_rel \\<rightarrow> string_rel\"\n  by (auto simp: string_rel_def)\nlemma [autoref_rules]:\n  includes autoref_syntax\n  shows\n    \"(expansion, expansion) \\<in> Id \\<rightarrow> rnv_rel\"\n    \"(preexpansion, preexpansion) \\<in> Id \\<rightarrow> rnv_rel\"\n    \"(min_deg, min_deg) \\<in> Id \\<rightarrow> rnv_rel\"\n    \"(max_deg, max_deg) \\<in> Id \\<rightarrow> rnv_rel\"\n  by auto\ninterpretation autoref_op_pat_def aform.mig_set .\nlemma [autoref_rules_raw]: \"DIM_precond TYPE(real \\<times> real \\<times> real) (OP 3 ::: nat_rel)\"\n  by simp\nschematic_goal check_c1_entry_impl:\n  includes autoref_syntax\n  assumes [autoref_rules]:\n    \"(optnsi, optns) \\<in> Id\"\n    \"(res0i, res0) \\<in> Id\"\n    \"(resi, res) \\<in> Id\"\n    \"(emi, em) \\<in> ereal_rel\"\n    \"(Pei, P) \\<in> aform.appr1_rel\"\n  shows\n    \"(nres_of ?r, check_c1_entry optns em P res0 res) \\<in> \\<langle>bool_rel\\<rangle>nres_rel\"\n  unfolding check_c1_entry_def\n  including art\n  by autoref_monadic\n\nconcrete_definition check_c1_entry_impl uses check_c1_entry_impl[\n    where optns = \"\\<lambda>_ . optnsi\"\n    and optnsi=\"optnsi\"\n    and optnsc=optns\n    and optnsa=\"\\<lambda>_ _ _ _ _. optnsi\"\n    and optnsb=\"\\<lambda>_ _ _ _  _ _ _ _ . optnsi\"\n    and optns=\"\\<lambda>_. optnsi\"\n    for optns optnsi]\nlemmas check_c1_entry_impl_refine[autoref_rules] = check_c1_entry_impl.refine[autoref_higher_order_rule]\n\ndefinition \"c1_entry_correct (em::ereal) (P::R3 c1_info set) res0 res = (\\<forall>(_, d)\\<in>P. case (d (1, 0, 0)) of (dx, dy, dz) \\<Rightarrow>\n      dz = 0 \\<and> dx > 0 \\<and> -90 < min_deg res \\<and> min_deg res \\<le> max_deg res \\<and> max_deg res < 90 \\<and>\n      ereal (preexpansion res) \\<le> em * (norm (dx, dy, dz)) \\<and>\n      ereal (expansion res0) \\<le> em * (norm (dx, dy, dz)) \\<and>\n      dy / dx \\<in> {tan (rad_of (min_deg res)) .. tan (rad_of (max_deg res))})\"\n\nlemma check_c1_entry[le, refine_vcg]:\n  \"check_c1_entry optns em P res0 res \\<le> SPEC (\\<lambda>b. b \\<longrightarrow> c1_entry_correct em P res0 res)\"\n  unfolding check_c1_entry_def c1_entry_correct_def\n  apply refine_vcg\n  apply (auto dest!: bspec simp:)\n    apply (rule order_trans, assumption, rule ereal_mult_left_mono, force, force)\n  apply (rule order_trans, assumption, rule ereal_mult_left_mono, force, force)\n  done\n\n\nsubsection \\<open>options for the lorenz system\\<close>\n\ndefinition aform_numeric_optns::\"_ \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow>\n    real aform numeric_options\" where\n  \"aform_numeric_optns = numeric_options.fields\"\n\nfun zbucket::\"real \\<Rightarrow>  real \\<times> real \\<Rightarrow> real \\<times> real \\<Rightarrow> real \\<times> real \\<Rightarrow> ((real list \\<times> real list) \\<times> real list sctn) list\"\n  where \"zbucket d (x0,x1) (y0, y1) (z0, z1) =\n    [zsec' (x0 - d, x0 + d) (y0 - d, y1 + d) z0, \\<comment> \\<open>bottom\\<close>\n     xsec' x0 (y0 - d, y1 + d) (z0 - d, z1),     \\<comment> \\<open>left\\<close>\n     xsec x1 (y0 - d, y1 + d) (z0 - d, z1),      \\<comment> \\<open>right\\<close>\n     ysec' (x0 - d, x1 + d) y0 (z0 - d, z1),     \\<comment> \\<open>backno\\<close>\n     ysec (x0 - d, x1 + d) y1  (z0 - d, z1)]     \\<comment> \\<open>front\\<close>\"\n\nsubsubsection \\<open>Hybridizations\\<close>\n\ndefinition \"reduce_weak_params c1 = (if c1 then (12::nat, 0::nat) else (3, 0))\"\ndefinition \"reduce_hard_params c1 = (if c1 then (0::nat, 100::nat) else (0, 100))\"\ndefinition \"ro_split_weak   c1 w     = (case reduce_weak_params c1 of (m, n) \\<Rightarrow> ro (w + 1) m n w w (-5))\"\ndefinition \"ro_split_weak'  c1 w     = (case reduce_weak_params c1 of (m, n) \\<Rightarrow> ro w m n w w (-5))\"\ndefinition \"ro_split_weak'' c1 w     = (case reduce_weak_params c1 of (m, n) \\<Rightarrow> ro (w + 2) m n w w (-5))\"\ndefinition \"ro_split_weak4' c1 w     = (case reduce_weak_params c1 of (m, n) \\<Rightarrow> ro (w + 4) m n w w (-5))\"\ndefinition \"ro_split_weak2  c1 w w2  = (case reduce_weak_params c1 of (m, n) \\<Rightarrow> ro (w + 1) m n w w2 (-5))\"\ndefinition \"ro_split_weak2' c1 w w2  = (case reduce_weak_params c1 of (m, n) \\<Rightarrow> ro (w) m n w w2 (-5))\"\ndefinition \"ro_split_hard   c1 w0 w1 = (case reduce_hard_params c1 of (m, n) \\<Rightarrow> ro (w0 + 1) m n w0 w1 (-5))\"\ndefinition \"ro_split_hard'' c1 w0 w1 = (case reduce_hard_params c1 of (m, n) \\<Rightarrow> ro (w0 + 2) m n w0 w1 (-5))\"\ndefinition \"ro_split_not    c1 w     = (case reduce_weak_params c1 of (m, n) \\<Rightarrow> ro       0 m n w w (-5))\"\ndefinition \"ro_split_not2   c1 w w2  = (case reduce_weak_params c1 of (m, n) \\<Rightarrow> ro       0 m n w w2 (-5))\"\n\ndefinition \"xsecs x y z = [xsec' (-x) (-y, y) (0, z), xsec x (-y, y) (0, z)]\"\n\ntype_synonym run_options = \"(nat \\<times> nat) \\<times> int \\<times>\n  (((real list \\<times> real list) \\<times> real list sctn) list \\<times> real aform reach_options) list \\<times> real aform reach_options\"\n\nabbreviation \"p1 \\<equiv> ldec 0.1\"\n\ndefinition mode_middle::\"_ \\<Rightarrow> run_options\" where \"mode_middle c1 = (reduce_weak_params c1, -14,\n  [([zsec' (-2, 2) (-1, 1) 10], ro_split_weak' c1 (-3)),\n  (xsecs (5 * p1)  10    10 @\n   xsecs p1      10  (6) @\n   [zsec' (-p1, p1) (-p1, p1) p1],\n      ro_split_hard c1 (-5) (-2)),\n  (xsecs (3/2/2) 10 (10), ro_split_not2 c1 0 (-2)), \\<comment> \\<open>To collect after interrupt\\<close>\n    ([zsec (-30, -6) (-10, 10) 30, zsec (6, 30) (-10, 10) 30], ro_split_not2 c1 (-1) (-3))\n  ], ro_split_weak4' c1 (-5))\"\n\ndefinition mode_inner3::\"bool\\<Rightarrow>bool\\<Rightarrow>run_options\" where \"mode_inner3 c1 very_inner =\n   (reduce_weak_params c1, -15,\n    (if very_inner then [([zsec' (-2, 2) (-1, 1) 10], ro_split_weak' c1 (-2))] else [])@\n    [(xsecs (3/2) 15 27@xsecs 1 (10) (11/2), ro_split_weak2 c1 (-2) (-1)),\n     ([ zsec (-30, -6) (-10, 10) 30, zsec (6, 30) (-10, 10) 30], ro_split_not2 c1 (-1) (-3))\n    ],\n     if very_inner then ro_split_weak4' c1 (-5) else ro_split_weak'' c1 (-5))\"\n\ndefinition mode_inner2::\"bool \\<Rightarrow> real \\<Rightarrow> run_options\" where \"mode_inner2 c1 x =\n  (reduce_weak_params c1, -14,\n    [(xsecs x 10 27, ro_split_weak2' c1 (-2) (-1)),\n     ([zsec ( -30, -6) (-10, 10) 30, zsec (6, 30) (-10, 10) 30], ro_split_not2 c1 (-3) (-3))],\n  ro_split_not c1 (-6))\"\n\ndefinition \"ro_outer c1 w = (case reduce_weak_params c1 of (m, n) \\<Rightarrow> ro w m n (-6) (-6) (-5))\"\ndefinition mode_outer::\"bool\\<Rightarrow>_\\<Rightarrow>_\\<Rightarrow>run_options\" where\n  \"mode_outer c1 w i = (reduce_weak_params c1, (-i),\n    [([zsec (-30, -6) (-10, 10) 27, zsec (6, 30) (-10, 10) 27], ro_split_not2 c1 (-3) (-4))], ro_outer c1 w)\"\n\ndefinition lookup_mode::\"bool \\<Rightarrow> result \\<Rightarrow> _\" where\n\"lookup_mode c1 i =\n  (if     gridx0 i \\<le> - 1024 then mode_outer  c1 (-3) 16\n  else if gridx0 i \\<le> - 120  then mode_outer  c1 (-3) 14\n  else if gridx0 i \\<le> 107    then mode_inner2 c1 (4)\n  else if gridx0 i \\<le> 169    then mode_inner3 c1 False\n  else if gridx0 i \\<le> 196    then mode_inner3 c1 True\n  else if gridx0 i \\<le> 201    then mode_middle c1\n  else if gridx0 i \\<le> 235    then mode_inner3 c1 True\n  else if gridx0 i \\<le> 290    then mode_inner3 c1 False\n  else if gridx0 i \\<le> 450    then mode_inner2 c1 4\n  else                           mode_outer  c1 (-3) 14)\"\n\ndefinition mode_ro_spec::\"bool \\<Rightarrow> result \\<Rightarrow> ((nat \\<times> nat) \\<times>\n          int \\<times> ((real, 3) vec set \\<times> unit) list \\<times>\n          unit) nres\"\nwhere [refine_vcg_def]: \"mode_ro_spec c1 res = SPEC (\\<lambda>_. True)\"\n\nlemma reach_options_rel_br: \"reach_options_rel TYPE('ty) = br (\\<lambda>_. ()) (\\<lambda>_. True)\"\n  by (auto simp: reach_options_rel_def br_def)\n\nlemma mode_ro_spec_impl[autoref_rules]:\n  includes autoref_syntax\n  shows \"(\\<lambda>b x. RETURN (lookup_mode b x), mode_ro_spec) \\<in> bool_rel \\<rightarrow> Id \\<rightarrow>\n    \\<langle>(nat_rel \\<times>\\<^sub>r nat_rel) \\<times>\\<^sub>r int_rel \\<times>\\<^sub>r guards_rel \\<times>\\<^sub>r aform.reach_optns_rel\\<rangle>nres_rel\"\n  supply [simp del] = prod_rel_id_simp\n  apply (rule fun_relI)\n  apply (rule fun_relI)\n  apply (rule nres_relI)\n  unfolding mode_ro_spec_def\n  apply (rule RETURN_SPEC_refine)\n  apply (auto simp: mode_ro_spec_def nres_rel_def RETURN_RES_refine_iff)\n  apply (rule exI)+\n  apply (rule prod_relI'' IdI)+\n  unfolding lv_rel_def ivl_rel_def br_rel_prod br_chain plane_rel_br inter_rel_br\n    clw_rel_br br_list_rel Id_br prod_eq_iff reach_options_rel_br\n   apply (rule brI refl)+\n   defer apply (rule brI) apply (rule refl) apply auto\n  apply (auto simp: lookup_mode_def mode_outer_def mode_inner2_def mode_inner3_def xsecs_def\n      mode_middle_def)\n  done\n\nlemma [autoref_rules]: includes autoref_syntax shows\n  \"(ivl_of_res, ivl_of_res) \\<in> Id \\<rightarrow> \\<langle>rnv_rel\\<rangle>list_rel \\<times>\\<^sub>r \\<langle>rnv_rel\\<rangle>list_rel\"\n  by auto\n\n\nlemma [autoref_rules]: includes autoref_syntax shows\n  \"(Polygon.pairself, Polygon.pairself) \\<in> (A \\<rightarrow> C) \\<rightarrow> (A \\<times>\\<^sub>r A) \\<rightarrow> (C \\<times>\\<^sub>r C)\"\n  by (auto dest: fun_relD)\n\nlemma set_of_ivl_impl[autoref_rules]: includes autoref_syntax shows\n  \"(\\<lambda>x. x, set_of_ivl) \\<in> (A \\<times>\\<^sub>r A) \\<rightarrow> \\<langle>A\\<rangle>ivl_rel\"\n  by (auto simp: ivl_rel_def br_def)\nlemma eucl_of_list_pad: includes autoref_syntax shows\n  \"DIM_precond TYPE('a::executable_euclidean_space) D \\<Longrightarrow>\n    (\\<lambda>xs. take D xs @ replicate (D - length xs) 0, eucl_of_list::_\\<Rightarrow>'a) \\<in> rl_rel \\<rightarrow> lv_rel\"\n  unfolding lv_rel_def\n  by (auto simp: intro!: brI)\nconcrete_definition eucl_of_list_pad uses eucl_of_list_pad\nlemmas [autoref_rules] = eucl_of_list_pad.refine\n\nlemma source_of_res_impl[autoref_rules]: includes autoref_syntax shows\n  \"(ivl_of_res, source_of_res) \\<in> Id \\<rightarrow> \\<langle>lv_rel\\<rangle>ivl_rel\"\n  unfolding source_of_res_def\n  apply (auto simp: ivl_rel_def intro!: relcompI brI)\n  subgoal for a\n    apply (auto simp: ivl_of_res_def ivl_of_resultrect_def\n        intro!: lv_relI)\n    unfolding lv_rel_def\n     apply (auto intro!: brI)\n    done\n  done\n\ndefinition tangent_seg_of_res :: \"real aform numeric_options \\<Rightarrow> result \\<Rightarrow> R3 set nres\" where\n\"tangent_seg_of_res optns res0 = do {\n  let fas = map (OP (nth matrix_of_degrees2\\<^sub>e)) [0, 3, 6];\n  let u = min_deg res0;\n  let v = max_deg res0;\n  aform.approx_slp_appr fas (slp_of_fas fas) (lv_ivl [u, v, 0] [u, v, 1])\n}\"\nlemmas [refine_vcg_def] = tangent_seg_of_res_spec_def\nlemma tangent_seg_of_res[le, refine_vcg]:\n  \"tangent_seg_of_res optns res \\<le> tangent_seg_of_res_spec res\"\n  unfolding tangent_seg_of_res_def tangent_seg_of_res_spec_def\n  apply refine_vcg\n  apply (auto simp: matrix_of_degrees2\\<^sub>e_def Let_def in_segment)\n  subgoal for x a b c u\n    by (drule bspec[where x=\"[min_deg res, max_deg res, u]\"])\n       (auto simp: tangent_of_deg_def lv_ivl_def algebra_simps intro!:)\n  done\nlemma [autoref_rules]: includes autoref_syntax shows\n  \"(nth matrix_of_degrees2\\<^sub>e, nth matrix_of_degrees2\\<^sub>e) \\<in> nat_rel \\<rightarrow> Id\"\n  by auto\nschematic_goal tangent_seg_of_res_impl:\n  includes autoref_syntax\n  assumes [autoref_rules]: \"(resi, res) \\<in> Id\"\n    \"(optnsi, optns) \\<in> num_optns_rel\"\n  shows\n  \"(nres_of ?r, tangent_seg_of_res optns res) \\<in> \\<langle>aform.appr_rel\\<rangle>nres_rel\"\n  unfolding tangent_seg_of_res_def\n  including art\n  by autoref_monadic\nconcrete_definition tangent_seg_of_res_impl uses tangent_seg_of_res_impl\nlemmas [autoref_rules] = tangent_seg_of_res_impl.refine[where\n    optnsi = optnsi and optnsa=optns and optns=\"\\<lambda>_ _ _. optnsi\" for optns optnsi, autoref_higher_order_rule]\n\nlemma return_of_res_impl:\n includes autoref_syntax shows\n  \"(\\<lambda>results res. (get_results (inf_retx res) (inf_rety res) (sup_retx res) (sup_rety res) results),\n    return_of_res) \\<in> \\<langle>Id\\<rangle>list_rel \\<rightarrow> Id \\<rightarrow> \\<langle>Id\\<rangle>list_wset_rel\"\n  by (auto simp: return_of_res_def list_wset_rel_def intro!: brI)\nconcrete_definition return_of_res_impl uses return_of_res_impl\nlemmas [autoref_rules] = return_of_res_impl.refine\n\nlemma lorenz_optns'_impl[autoref_rules]: includes autoref_syntax shows\n  \"(lorenz_optns', lorenz_optns') \\<in>\n    \\<langle>Id \\<rightarrow> unit_rel\\<rangle>option_rel \\<rightarrow> nat_rel \\<rightarrow> nat_rel \\<rightarrow> rnv_rel \\<rightarrow> rnv_rel \\<rightarrow> num_optns_rel\"\n  by auto\nlemma [autoref_rules]:\n  includes autoref_syntax shows\n    \"(results, results) \\<in> \\<langle>Id\\<rangle>list_rel\"\n    \"(invoke_nf, invoke_nf) \\<in> Id \\<rightarrow> bool_rel\"\n  by auto\n\ndefinition \"check_line_nres print_fun m0 n0 c1 res0 = do {\n    let X0 = source_of_res res0;\n    (X0l, X0u) \\<leftarrow> ivl_rep X0;\n    ((m::nat, n::nat), a::int, modes, ro) \\<leftarrow> mode_ro_spec c1 res0;\n    let interrupt = invoke_nf res0;\n    let optns = lorenz_optns' print_fun (the_default m m0) (the_default n n0) 1 (FloatR 1 a);\n    tangents \\<leftarrow> tangent_seg_of_res optns res0;\n    aform.CHECKs (ST ''check_line_nres le'') (X0l \\<le> X0u);\n    sp \\<leftarrow> aform.subset_spec_plane X0 (Sctn (eucl_of_list [0, 0, 1]) 27);\n    aform.CHECKs (ST ''check_line_nres le'') sp;\n    ASSERT (X0l \\<le> X0u);\n    Pe \\<leftarrow> lorenz_poincare_tangents optns interrupt modes ro c1 ({X0l .. X0u}) tangents;\n    PeS \\<leftarrow> sets_of_coll Pe;\n    let RETs = (return_of_res results res0);\n    let RET = \\<Union>((mk_coll ` (source_of_res ` RETs:::\\<langle>lvivl_rel\\<rangle>list_wset_rel):::\\<langle>clw_rel lvivl_rel\\<rangle>list_wset_rel));\n    every \\<leftarrow> WEAK_ALL\\<^bsup>\\<lambda>Pe. \\<exists>P em eM Rivls. em > 0 \\<and> Pe = scaleR2 em eM P \\<and> fst ` P \\<subseteq> \\<Union>Rivls \\<and> (\\<forall>Rivl \\<in> Rivls. (\\<exists>res\\<in>RETs. Rivl \\<subseteq> source_of_res res \\<and> (c1 \\<longrightarrow> c1_entry_correct em P res0 res)))\\<^esup>\n    PeS (\\<lambda>Pe. do {\n      let _ = aform.trace_set1e (ST ''# Return Element: '') (Some Pe);\n      ((em, eM), P) \\<leftarrow> scaleR2_rep Pe;\n      aform.CHECKs (ST ''check_line_nres pos'') (0 < em);\n      let R = (fst ` P:::aform.appr_rel);\n      (Ri, Rs) \\<leftarrow> op_ivl_rep_of_set R;\n      let Rivl = (op_atLeastAtMost_ivl Ri Rs);\n      Rivls \\<leftarrow> aform.split_along_ivls2 3 (mk_coll Rivl) RET;\n      Rivlss \\<leftarrow> sets_of_coll Rivls;\n      WEAK_ALL\\<^bsup>\\<lambda>Rivl. \\<exists>res\\<in>RETs. Rivl \\<subseteq> source_of_res res \\<and> (c1 \\<longrightarrow> c1_entry_correct em P res0 res)\\<^esup> Rivlss\n      (\\<lambda>Rivl. do {\n        b \\<leftarrow>\n          WEAK_EX\\<^bsup>\\<lambda>res. Rivl \\<subseteq> source_of_res res \\<and> (c1 \\<longrightarrow> c1_entry_correct em P res0 res)\\<^esup> RETs\n          (\\<lambda>res. do {\n            let src = (source_of_res res:::lvivl_rel);\n            let subs = Rivl \\<subseteq> src;\n            cones \\<leftarrow> if \\<not>(c1 \\<and> subs) then RETURN True else check_c1_entry optns em P res0 res;\n            RETURN (subs \\<and> cones)\n          });\n        let _ = aform.print_msg ((shows (ST ''# return of '') o shows res0 o\n          shows (if b then ST '' OK'' else ST '' FAILED''))'''');\n        RETURN b\n      })\n    });\n    RETURN (every, Pe, RET)\n  }\"\n\n\ndefinition \"aform_subset_spec_plane optns = aform.subset_spec_plane\"\n\nlemma aform_subset_spec_plane_impl[autoref_rules]:  includes autoref_syntax shows\n  \"DIM_precond TYPE('a::executable_euclidean_space) D \\<Longrightarrow>\n  (Xi, X::'a set) \\<in> \\<langle>lv_rel\\<rangle>ivl_rel \\<Longrightarrow>\n  (sctni, sctn) \\<in> \\<langle>lv_rel\\<rangle>sctn_rel \\<Longrightarrow>\n  (optnsi, optns) \\<in> num_optns_rel \\<Longrightarrow>\n  (nres_of (subset_spec_plane_impl_aform optnsi D Xi sctni),\n   aform_subset_spec_plane $ optns $ X $ sctn)\n  \\<in> \\<langle>bool_rel\\<rangle>nres_rel\"\n  using aform.subset_spec_plane_impl.refine[where 'a='a, of D Xi X sctni sctn optnsi]\n  by (force simp: aform_subset_spec_plane_def)\n\nschematic_goal check_line_impl:\n  includes autoref_syntax\n  assumes [autoref_rules]: \"(pfi, pf) \\<in> \\<langle>Id \\<rightarrow> unit_rel\\<rangle>option_rel\"\n    \"(c1i, c1) \\<in> bool_rel\" \"(res0i, res0) \\<in> Id\"\n    \"(m0i, m0) \\<in> \\<langle>nat_rel\\<rangle>option_rel\" \"(n0i, n0) \\<in> \\<langle>nat_rel\\<rangle>option_rel\"\n  shows\n  \"(nres_of ?r, check_line_nres $ pf $ m0 $ n0 $ c1 $ res0) \\<in>\n    \\<langle>bool_rel \\<times>\\<^sub>r clw_rel aform.appr1e_rel \\<times>\\<^sub>r clw_rel lvivl_rel\\<rangle>nres_rel\"\n  unfolding check_line_nres_def\n  including art\n  by autoref_monadic\n\nconcrete_definition check_line_impl uses check_line_impl[where\n     optns = \"\\<lambda>_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ . lorenz_optns pfi\"\n    and optnsa = \"\\<lambda>_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. lorenz_optns pfi\"\n    and optnsb = \"\\<lambda>_ _ _ _ _ _ _ _ _ _  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. lorenz_optns pfi\"\n    and optnsc = \"\\<lambda>_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. lorenz_optns pfi\"\n    and optnsd = \"\\<lambda>_ _ _ _ _ _ _ _ _ _  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. lorenz_optns pfi\"\n    and optnse = \"\\<lambda>_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. lorenz_optns pfi\"\n    and optnsf = \"\\<lambda> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _. lorenz_optns pfi\"\n    and pfi = pfi\n    for pfi]\nlemmas [autoref_rules] = check_line_impl.refine\n\n\nlemma check_line_nres:\n  \"check_line_nres pf m0 n0 c1 res0 \\<le> SPEC (\\<lambda>(every, Pe, RET). \\<exists>P. Pe = \\<Union>P \\<and>\n    (if c1\n    then \\<exists>tans. source_of_res res0 \\<times> {tangent_of_deg (min_deg res0)--tangent_of_deg (max_deg res0)} \\<subseteq> (\\<lambda>(x, y). (x, blinfun_apply y (1, 0,  0))) ` tans \\<and>\n                lorenz.poincare_mapsto \\<Sigma> (tans - \\<Gamma>\\<^sub>i (invoke_nf res0) \\<times> UNIV) \\<Sigma>\\<^sub>l\\<^sub>e UNIV (Pe)\n    else lorenz.poincare_mapsto \\<Sigma> ((sourcei_of_res res0) \\<times> UNIV) \\<Sigma>\\<^sub>l\\<^sub>e UNIV (\\<Union>P)) \\<and>\n    source_of_res res0 \\<subseteq> plane_of (Sctn (0, 0, 1) 27) \\<and>\n    (every \\<longrightarrow>\n    (\\<forall>x\\<in>P. \\<exists>P em. em > 0 \\<and> (\\<exists>eM. x = scaleR2 em eM P) \\<and>\n                   (\\<exists>Rivls. fst ` P \\<subseteq> \\<Union>Rivls \\<and>\n                            (\\<forall>Rivl\\<in>Rivls.\n                                \\<exists>res\\<in>return_of_res results res0.\n                                   Rivl \\<subseteq> source_of_res res \\<and> (c1 \\<longrightarrow> c1_entry_correct em P res0 res))))))\"\n  if [refine_vcg]: NF\n  unfolding check_line_nres_def sourcei_of_res_def\n  apply (refine_vcg, clarsimp_all)\n  using [[goals_limit=1]]\n  subgoal for a0 a b c d e f g h i j k l m n p q r s t\n    apply (rule exI[where x=i])\n    apply (rule exI[where x=j])\n    apply (rule conjI)\n     apply force\n    apply (rule conjI)\n    apply (rule exI[where x=k])\n     apply force\n    apply (rule exI[where x=s])\n    apply (rule conjI) defer apply force\n    apply blast\n    done\n  subgoal for x0 y0 z0 x1 y1 z1 tangents s R every\n    apply (rule exI[where x=R])\n    apply auto\n    subgoal for tans\n      apply (rule exI[where x=tans])\n      by auto\n    subgoal for tans\n      apply (rule exI[where x=tans])\n      by auto\n    done\n  done\n\ndefinition \"print_sets_color (print_fun::String.literal \\<Rightarrow> unit) (c::string) (X::'a::executable_euclidean_space set) = ()\"\n\ndefinition \"print_lorenz_color print_fun cx cy cz ci cd1 cd2 P = ()\"\n\ndefinition \"print_aforms print_fun c aforms =\n  fold (\\<lambda>a _.  print_fun (String.implode (shows_segments_of_aform 0 1 a c ''\\<newline>''))) aforms ()\"\n\nlemma print_sets_color_impl[autoref_rules]: includes autoref_syntax shows\n  \"(\\<lambda>print_fun c X. print_aforms print_fun c X, print_sets_color) \\<in>\n    (Id \\<rightarrow> unit_rel) \\<rightarrow> string_rel \\<rightarrow> clw_rel aform.appr_rel \\<rightarrow> unit_rel\"\n  by auto\n\nlemma print_lorenz_color_impl[autoref_rules]: includes autoref_syntax shows\n  \"(\\<lambda>print_fun cx cy cz ci cd1 cd2 P.\n    fold (\\<lambda>(_, x) b.\n        print_lorenz_aform print_fun\n          cx cy cz ci cd1 cd2\n          False\n          (fst x @ the_default [] (snd x))\n        ) P (), print_lorenz_color) \\<in>\n    (Id \\<rightarrow> unit_rel) \\<rightarrow> string_rel \\<rightarrow> string_rel \\<rightarrow> string_rel \\<rightarrow> string_rel \\<rightarrow>\n    \\<langle>\\<langle>string_rel\\<rangle>list_rel, \\<langle>\\<langle>string_rel\\<rangle>list_rel, (\\<langle>clw_rel aform.appr1e_rel, unit_rel\\<rangle>fun_rel)\\<rangle>fun_rel\\<rangle>fun_rel\"\n  by auto\n\ndefinition check_line_core where\n \"check_line_core print_funo m0 n0 c1 i =\n  do {\n      let print_fun = the_default (\\<lambda>_. ()) print_funo;\n      CHECK (\\<lambda>_. print_fun (STR ''Hey, out of bounds!'')) (i < length results);\n      let res = ((results:::\\<langle>Id\\<rangle>list_rel) ! (i:::nat_rel));\n      (r, P, B) \\<leftarrow> check_line_nres print_funo m0 n0 c1 res;\n      let _ = print_sets_color print_fun (ST ''0x007f00'') (aform.sets_of_ivls B);\n      (_, Pu) \\<leftarrow> scaleR2_rep_coll P;\n      let _ = print_sets_color print_fun (ST ''0x7f0000'')\n          (aform.op_image_fst_coll (Pu:::clw_rel aform.appr1_rel):::clw_rel aform.appr_rel);\n      let _ = print_lorenz_color print_fun\n          (ST ''0x7f0000'') (ST ''0x7f0001'') (ST ''0x7f0002'') (ST ''0x7f0003'')\n          [(ST ''0xc60000''), (ST ''0xc60000''), (ST ''0xc60000'')]\n          [(ST ''0xf60000''), (ST ''0xf60000''), (ST ''0xf60000'')]\n          P;\n      let _ = (if r\n        then print_fun\n          (String.implode ((show (ST ''# VERIFIED '') @ show i @ show (ST ''\\<newline>''))))\n        else print_fun (String.implode ((show (ST ''# Failed to verify '') @ show i @ show (ST ''\\<newline>'')) )));\n      RETURN r\n    }\"\nlemma [autoref_rules]: includes autoref_syntax shows\n  \"(shows_prec, shows_prec) \\<in> nat_rel \\<rightarrow> nat_rel \\<rightarrow> string_rel \\<rightarrow> string_rel\"\n  \"(shows_prec, shows_prec) \\<in> nat_rel \\<rightarrow> string_rel \\<rightarrow> string_rel \\<rightarrow> string_rel\"\n  \"(String.implode, String.implode) \\<in> string_rel \\<rightarrow> Id\"\n  by (auto simp: string_rel_def)\nschematic_goal check_line_core_impl:\n  includes autoref_syntax\n  assumes [autoref_rules]: \"(pfi, pf) \\<in> \\<langle>Id \\<rightarrow> unit_rel\\<rangle>option_rel\"\n    \"(c1i, c1) \\<in> bool_rel\" \"(ii, i) \\<in> nat_rel\"\n    \"(m0i, m0) \\<in> \\<langle>nat_rel\\<rangle>option_rel\" \"(n0i, n0) \\<in> \\<langle>nat_rel\\<rangle>option_rel\"\n  shows \"(nres_of ?f, check_line_core $ pf $ m0 $ n0 $ c1 $ i) \\<in> \\<langle>bool_rel\\<rangle>nres_rel\"\n  unfolding check_line_core_def\n  including art\n  by autoref_monadic\nconcrete_definition check_line_core_impl for pfi m0i n0i c1i ii uses check_line_core_impl\nlemmas [autoref_rules] = check_line_core_impl.refine\n\ndefinition \"c1i_of_res res = sourcei_of_res res \\<times> conefield_of_res res\"\n\ndefinition \"correct_res res =\n  ((\\<forall>(x, dx) \\<in> c1i_of_res res.\n    x \\<in> plane_of (Sctn (0, 0, 1) 27) \\<and>\n    dx \\<in> plane_of (Sctn (0, 0, 1) 0) \\<and>\n    ((lorenz.returns_to \\<Sigma> x \\<and>\n      lorenz.return_time \\<Sigma> differentiable at x within \\<Sigma>\\<^sub>l\\<^sub>e \\<and>\n      (\\<exists>D. (lorenz.poincare_map \\<Sigma> has_derivative D) (at x within \\<Sigma>\\<^sub>l\\<^sub>e) \\<and>\n           norm (D dx) \\<ge> expansion res * norm dx \\<and>\n           (\\<exists>res2 \\<in> return_of_res results res.\n              (lorenz.poincare_map \\<Sigma> x, D dx) \\<in> c1_of_res res2 \\<and>\n              norm (D dx) \\<ge> preexpansion res2 * norm dx))))))\"\n\nlemma check_line_nres_c0_correct:\n  \"check_line_nres pf m0 n0 c1 res \\<le> SPEC (\\<lambda>(every, Pe, RET). every \\<longrightarrow>\n    (\\<forall>x \\<in> sourcei_of_res res. lorenz.poincare_map \\<Sigma> x \\<in> \\<Union>(source_of_res ` return_of_res results res)))\"\n  if NF\n  apply (rule check_line_nres[OF \\<open>NF\\<close>, le])\n  apply (auto simp: c1i_of_res_def lorenz.poincare_mapsto_def)\n  subgoal\n    apply (drule bspec, force)\n    apply (auto dest!: spec[where x=\"1\\<^sub>L\"])\n    apply (drule bspec, force)\n    apply (force simp: scaleR2_def image_def vimage_def)\n    done\n  subgoal premises prems for a b c d e tans\n  proof -\n    obtain t where\n      \"((c, d, e), t) \\<in> tans  - \\<Gamma>\\<^sub>i (invoke_nf res) \\<times> UNIV\"\n      \"((c, d, e), tangent_of_deg (min_deg res)) = (\\<lambda>(x, y). (x, blinfun_apply y (1, 0, 0))) ((c, d, e), t)\"\n      using prems\n      by (auto simp: sourcei_of_res_def)\n    with prems(6)[rule_format, of \"((c, d, e), t)\"] prems(3)\n    obtain D x where \"tangent_of_deg (min_deg res) = blinfun_apply t (1, 0, 0)\"\n      \"(c, d, e) returns_to \\<Sigma>\"\n      \"fst ` (tans - \\<Gamma>\\<^sub>i (invoke_nf res) \\<times> UNIV) \\<subseteq> \\<Sigma>\\<^sub>l\\<^sub>e\"\n      \"lorenz.return_time \\<Sigma> differentiable at (c, d, e) within \\<Sigma>\\<^sub>l\\<^sub>e\"\n      \"(lorenz.poincare_map \\<Sigma> has_derivative blinfun_apply D) (at (c, d, e) within \\<Sigma>\\<^sub>l\\<^sub>e)\"\n      \"x \\<in> b\" \"(lorenz.poincare_map \\<Sigma> (c, d, e), D o\\<^sub>L t) \\<in> x\"\n      by auto\n    with prems\n    show ?thesis\n      subgoal\n        apply (auto dest!: bspec[OF _ \\<open>x \\<in> b\\<close>])\n        apply (auto simp: scaleR2_def image_def vimage_def)\n        apply (auto simp: subset_iff)\n        by fastforce \\<comment>\\<open>slow\\<close>\n      done\n  qed\n  subgoal for a b c d e f\n    apply (drule bspec[where A=\"sourcei_of_res res\"]) apply force\n    apply (auto dest!: spec[where x=\"1\\<^sub>L\"])\n    apply (drule bspec, force)\n    apply auto\n    apply (auto simp: scaleR2_def image_def vimage_def)\n    apply (auto simp: subset_iff)\n    by fastforce\\<comment> \\<open>slow\\<close>\n  done\n\nlemma cone_conefield[intro, simp]: \"cone (conefield a b)\"\n  unfolding conefield_alt_def\n  by (rule cone_cone_hull)\n\nlemma in_segment_norm_bound: \"c \\<in> {a -- b} \\<Longrightarrow> norm c \\<le> max (norm a) (norm b)\"\n  apply (auto simp: in_segment max_def intro!: norm_triangle_le)\n   apply (auto simp: algebra_simps intro: add_mono mult_left_mono\n      mult_right_mono)\n  using affine_ineq by blast\n\nlemma norm_tangent_of_deg[simp]: \"norm (tangent_of_deg d) = 1\"\n  by (auto simp: tangent_of_deg_def norm_prod_def)\n\nlemma check_line_nres_c1_correct:\n  \"check_line_nres pf m0 n0 True res \\<le> SPEC (\\<lambda>(correct, Pe, RET). correct \\<longrightarrow> correct_res res)\"\n  if NF\nproof (rule check_line_nres[OF \\<open>NF\\<close>, le], clarsimp, goal_cases)\n  case P: (1 a P tans)\n  let ?tans = \"{tangent_of_deg (min_deg res)--tangent_of_deg (max_deg res)}\"\n  have tans_plane: \"?tans \\<subseteq> UNIV \\<times> UNIV \\<times> {0}\"\n    by (auto simp: in_segment tangent_of_deg_def)\n  from P have *: \"x \\<in> plane_of (Sctn (0, 0, 1) 27)\" if \"x \\<in> sourcei_of_res res\" for x\n    using that\n    by (auto simp: that sourcei_of_res_def)\n  from tans_plane P have **: \"dx \\<in> plane_of (Sctn (0, 0, 1) 0)\"\n    if \"x \\<in> sourcei_of_res res\" \"dx \\<in> conefield_of_res res\" for x dx\n  proof -\n    from tans_plane that obtain c dx' dy' where\n      c: \"dx = c *\\<^sub>R (dx', dy', 0)\" \"(dx', dy', 0) \\<in> ?tans\" \"c \\<ge> 0\"\n      unfolding conefield_of_res_def conefield_alt_def cone_hull_expl\n      by auto\n    then show ?thesis by (auto simp: plane_of_def)\n  qed\n  show ?case\n    unfolding correct_res_def\n  proof (intro ballI conjI, clarsimp_all simp add:\n      * ** c1i_of_res_def c1_of_res_def sourcei_of_res_def, goal_cases)\n    case source: (1 x y z dx dy dz)\n    from tans_plane source obtain c dx' dy' where\n      c: \"(dx, dy, dz) = c *\\<^sub>R (dx', dy', 0)\" \"(dx', dy', 0) \\<in> ?tans\" \"c \\<ge> 0\"\n      unfolding conefield_of_res_def conefield_alt_def cone_hull_expl\n      by auto\n    from c source P\n    obtain t where tans: \"((x, y, z), t) \\<in> tans\" \"blinfun_apply t (1, 0, 0) = (dx', dy', 0)\"\n      by auto \n    from P(3) tans(1) source(3) obtain Re D where Re:\n      \"(x, y, z) returns_to \\<Sigma>\" \"fst ` (tans - \\<Gamma>\\<^sub>i (invoke_nf res) \\<times> UNIV) \\<subseteq> \\<Sigma>\\<^sub>l\\<^sub>e\"\n      \"lorenz.return_time \\<Sigma> differentiable at (x, y, z) within \\<Sigma>\\<^sub>l\\<^sub>e\"\n      \"(lorenz.poincare_map \\<Sigma> has_derivative blinfun_apply D) (at (x, y, z) within \\<Sigma>\\<^sub>l\\<^sub>e)\"\n      \"Re \\<in> P\" \"(lorenz.poincare_map \\<Sigma> (x, y, z), D o\\<^sub>L t) \\<in> Re\"\n      by (auto simp: lorenz.poincare_mapsto_def dest!: bspec)\n    from P(5)[rule_format, OF \\<open>Re \\<in> P\\<close>]\n    obtain R em eM Rivls\n      where R: \"Re = scaleR2 em eM R\"\n        \"em > 0\"\n        \"fst ` R \\<subseteq> \\<Union>Rivls\"\n        \"\\<And>Rivl. Rivl\\<in>Rivls \\<Longrightarrow>\n          \\<exists>resa\\<in>return_of_res results res. Rivl \\<subseteq> source_of_res resa \\<and> c1_entry_correct em R res resa\"\n      by auto\n    have \"lorenz.poincare_map \\<Sigma> (x, y, z) \\<in> fst ` R\"\n      and s2: \"(lorenz.poincare_map \\<Sigma> (x, y, z), D o\\<^sub>L t) \\<in> scaleR2 em eM R\"\n      using Re R by (auto simp: scaleR2_def)\n    then obtain Rivl res' where Rivl:\n      \"lorenz.poincare_map \\<Sigma> (x, y, z) \\<in> Rivl\" \"Rivl \\<in> Rivls\"\n      \"res' \\<in> return_of_res results res\" \"Rivl \\<subseteq> source_of_res res'\"\n      and c1: \"c1_entry_correct em R res res'\"\n      using R\n      by force\n    from s2 obtain ed Dt where Dt:\n      \"em \\<le> ereal ed\" \"ereal ed \\<le> eM\" \"D o\\<^sub>L t = ed *\\<^sub>R Dt\"\n      \"(lorenz.poincare_map \\<Sigma> (x, y, z), Dt) \\<in> R\"\n      by (force simp: scaleR2_def)\n    then have Dt_simp[simp]: \"Dt = inverse ed *\\<^sub>R (D o\\<^sub>L t)\"\n      using \\<open>0 < em\\<close>\n      by (cases em) (auto simp: intro!:  simp: blinfun.bilinear_simps inverse_eq_divide)\n    from c1[unfolded c1_entry_correct_def, rule_format, OF Dt(4)]\n    obtain dxr dyr where dxrdyr: \"blinfun_apply D (dx', dy', 0) /\\<^sub>R ed = (dxr, dyr, 0)\"\n      \"ereal (preexpansion res') \\<le> em * ereal (norm (dxr, dyr, 0::real))\"\n      \"ereal (expansion res) \\<le> em * ereal (norm (dxr, dyr, 0::real))\"\n      \"-90 < min_deg res'\" \"min_deg res' \\<le> max_deg res'\"\n      \"tan (rad_of (min_deg res')) \\<le> (dyr / dxr)\"\n      \"(dyr / dxr) \\<le> tan (rad_of (max_deg res'))\"\n      \"max_deg res' < 90\"\n      \"0 < dxr\"\n      by (auto simp: blinfun.bilinear_simps tans)\n\n    then obtain emr where emr: \"em = ereal emr\" \"0 < emr\" \"emr \\<le> ed\"\n      \"(preexpansion res') \\<le> emr * (norm (dxr, dyr, 0::real))\"\n      \"(expansion res) \\<le> emr * (norm (dxr, dyr, 0::real))\"\n      using \\<open>0 < em\\<close> Dt\n      by (cases em) (auto simp: simp: blinfun.bilinear_simps divide_simps prod_eq_iff)\n    from dxrdyr have Ddx'dy': \"D (dx', dy', 0) = ed *\\<^sub>R (dxr, dyr, 0)\"\n      using \\<open>0 < em\\<close> Dt\n      by (cases em) (auto simp: simp: blinfun.bilinear_simps divide_simps prod_eq_iff)\n\n    note \\<open>(x, y, z) returns_to \\<Sigma>\\<close>\n    moreover note \\<open>lorenz.return_time \\<Sigma> differentiable at (x, y, z) within \\<Sigma>\\<^sub>l\\<^sub>e\\<close>\n    moreover note \\<open>(lorenz.poincare_map \\<Sigma> has_derivative D) (at (x, y, z) within \\<Sigma>\\<^sub>l\\<^sub>e)\\<close>\n    moreover note \\<open>res' \\<in> return_of_res results res\\<close>\n    moreover have \"lorenz.poincare_map \\<Sigma> (x, y, z) \\<in> source_of_res res'\"\n      using Rivl by force\n    moreover\n    have \\<open>0 \\<le> ed\\<close> using Dt \\<open>0 < em\\<close> by (cases em) auto\n    have \\<open>D (dx, dy, dz) \\<in> conefield_of_res res'\\<close>\n      unfolding c blinfun.bilinear_simps conefield_of_res_def Ddx'dy'\n      apply (intro mem_cone, simp_all add: \\<open>0 \\<le> ed\\<close> \\<open>0 \\<le> c\\<close> tangent_of_deg_def)\n      apply (rule conefield_prod3I)\n      unfolding fun_cong[OF tan_def, symmetric]\n      subgoal by fact\n      subgoal using dxrdyr\n        apply (intro cos_gt_zero_pi)\n        unfolding rad_of_lt_iff rad_of_gt_iff\n        by (auto simp: deg_of_def)\n      subgoal using dxrdyr\n        apply (intro cos_gt_zero_pi)\n        unfolding rad_of_lt_iff rad_of_gt_iff\n        by (auto simp: deg_of_def)\n      subgoal by fact\n      subgoal by fact\n      done\n    moreover\n    have norms_le: \"emr * norm (dx', dy', 0::real) * (\\<bar>c\\<bar> * norm (dxr, dyr, 0::real)) \\<le> \\<bar>ed\\<bar> * (\\<bar>c\\<bar> * norm (dxr, dyr, 0::real))\"\n    proof -\n      from c(2)[THEN in_segment_norm_bound] have \"norm (dx', dy', 0::real) \\<le> 1\"\n        by auto\n      also have \"\\<dots> \\<le> ed / emr\"\n        using dxrdyr emr\n        unfolding Ddx'dy'\n        by auto\n      finally show ?thesis\n        using emr\n        by (intro mult_right_mono) (auto simp: divide_simps ac_simps)\n    qed\n    then have \"expansion res * norm (dx, dy, dz) \\<le> norm (D (dx, dy, dz))\"\n      unfolding c blinfun.bilinear_simps conefield_of_res_def Ddx'dy' norm_scaleR\n      apply -\n      apply (rule order_trans)\n       apply (rule mult_right_mono)\n        apply (rule emr)\n      by (auto simp: ac_simps)\n    moreover have \"preexpansion res' * norm (dx, dy, dz) \\<le> norm (D (dx, dy, dz))\"\n      using norms_le\n      unfolding c blinfun.bilinear_simps conefield_of_res_def Ddx'dy' norm_scaleR\n      apply -\n      apply (rule order_trans)\n       apply (rule mult_right_mono)\n        apply (rule emr)\n      by (auto simp: ac_simps)\n    ultimately\n    show ?case\n      by blast\n  qed\nqed\n\nlemma conefield_ne_empyt[simp]: \"conefield a b \\<noteq> {}\"\n  by (auto simp: conefield_def conesegment_def cone_hull_empty_iff[symmetric])\n\nlemma in_return_of_resD: \"res' \\<in> return_of_res results res \\<Longrightarrow> res' \\<in> set results\"\n  by (auto simp: return_of_res_def get_results_def)\nlemma finite_results_at[intro, simp]: \"finite (results_at x)\"\n  by (auto simp: results_at_def)\n\n\nlemma lorenz_bounds_lemma:\n  \"x returns_to \\<Sigma>\"\n  \"R x \\<in> N\"\n  \"(R has_derivative DR x) (at x within \\<Sigma>\\<^sub>l\\<^sub>e)\"\n  \"\\<And>c. c \\<in> \\<CC> x \\<Longrightarrow> DR x c \\<in> \\<CC> (R x)\"\n  \"\\<And>c. c \\<in> \\<CC> x \\<Longrightarrow> norm (DR x c) \\<ge> \\<E> x      * norm c\"\n  \"\\<And>c. c \\<in> \\<CC> x \\<Longrightarrow> norm (DR x c) \\<ge> \\<E>\\<^sub>p (R x) * norm c\"\n  if \"x \\<in> N - \\<Gamma>\" NF \"\\<And>res. res \\<in> set results \\<Longrightarrow> correct_res res\"\nproof -\n  from \\<open>x \\<in> N - \\<Gamma>\\<close> obtain res where res: \"res \\<in> set results\" \"x \\<in> sourcei_of_res res\"\n    by (auto simp: N_def sourcei_of_res_def \\<Gamma>\\<^sub>i_def)\n  then have ne: \"c1i_of_res res \\<noteq> {}\"\n    by (auto simp: c1i_of_res_def conefield_of_res_def)\n  from res this obtain dx where dx: \"(x, dx) \\<in> c1i_of_res res\"\n    by (auto simp: c1i_of_res_def)\n  from that(3)[OF \\<open>res \\<in> set _\\<close>] have \"correct_res res\" by simp\n  from this[unfolded correct_res_def, rule_format, OF dx] res\n  obtain res' D where res': \"x returns_to \\<Sigma>\"\n    \"lorenz.return_time \\<Sigma> differentiable at x within \\<Sigma>\\<^sub>l\\<^sub>e\"\n    \"(lorenz.poincare_map \\<Sigma> has_derivative D) (at x within \\<Sigma>\\<^sub>l\\<^sub>e)\"\n    \"expansion res * norm dx \\<le> norm (D dx)\"\n    \"res' \\<in> return_of_res results res\"\n    \"(lorenz.poincare_map \\<Sigma> x, D dx) \\<in> c1_of_res res'\"\n    \"preexpansion res' * norm dx \\<le> norm (D dx)\"\n    by auto\n  show \"x returns_to \\<Sigma>\" by fact\n  show \"R x \\<in> N\" using res'\n    by (auto simp: R_def N_def N_def c1i_of_res_def c1_of_res_def in_return_of_resD\n        sourcei_of_res_def)\n  show \"(R has_derivative DR x) (at x within \\<Sigma>\\<^sub>l\\<^sub>e)\"\n    apply (auto simp: R_def DR_def N_def c1_of_res_def in_return_of_resD)\n    apply (subst frechet_derivative_works[symmetric])\n    apply (rule differentiableI)\n    by fact\nnext\n  fix dx assume \"dx \\<in> \\<CC> x\"\n  then obtain res where res: \"res \\<in> set results\" and dx: \"(x, dx) \\<in> c1_of_res res\"\n    by (auto simp: \\<CC>_def results_at_def c1_of_res_def )\n  then have dx: \"(x, dx) \\<in> c1i_of_res res\"\n    using \\<open>x \\<in> N - _\\<close>\n    by (auto simp: c1i_of_res_def sourcei_of_res_def c1_of_res_def \\<Gamma>\\<^sub>i_def)\n  from res dx have ne: \"c1i_of_res res \\<noteq> {}\"\n    by (auto simp: c1_of_res_def conefield_of_res_def)\n  from that(3)[OF \\<open>res \\<in> set _\\<close>] have \"correct_res res\" by simp\n  from that this[unfolded correct_res_def, rule_format, OF dx] res\n  obtain res' D where res': \"x returns_to \\<Sigma>\" \"x \\<in> plane_of (Sctn (0, 0, 1) 27)\"\n    \"lorenz.return_time \\<Sigma> differentiable at x within \\<Sigma>\\<^sub>l\\<^sub>e\"\n    \"(lorenz.poincare_map \\<Sigma> has_derivative D) (at x within \\<Sigma>\\<^sub>l\\<^sub>e)\"\n    \"expansion res * norm dx \\<le> norm (D dx)\"\n    \"res' \\<in> return_of_res results res\"\n    \"(lorenz.poincare_map \\<Sigma> x, D dx) \\<in> c1_of_res res'\"\n    \"preexpansion res' * norm dx \\<le> norm (D dx)\"\n    by auto\n  have DRD: \"DR x = D\"\n    unfolding DR_def\n    apply (rule frechet_derivative_unique_within)\n      apply (subst frechet_derivative_works[symmetric])\n      apply (rule differentiableI)\n      apply fact\n     apply fact using \\<open>x \\<in> plane_of _\\<close>\n    apply safe\n    subgoal for _ _ _ e\n      by (auto simp: \\<Sigma>\\<^sub>l\\<^sub>e_def Basis_prod_def prod_eq_iff plane_of_def prod_eq_iff\n          inner_prod_def intro!: exI[where x=\"-e/2\"])\n    done\n  have [intro, simp]: \"res' \\<in> results_at (lorenz.poincare_map \\<Sigma> x)\"\n    using res'\n    by (auto simp: c1_of_res_def results_at_def in_return_of_resD R_def\n        intro!: exI[where x=res'])\n  have [intro, simp]: \"res \\<in> results_at x\"\n    using res dx\n    by (auto simp: c1i_of_res_def results_at_def sourcei_of_res_def)\n  show \"DR x dx \\<in> \\<CC> (R x)\"\n    unfolding DRD \\<CC>_def\n    using res'\n    by (auto simp: c1_of_res_def R_def)\n  have \"\\<E> x * norm dx \\<le> expansion res * norm dx\"\n    by (rule mult_right_mono) (auto simp: \\<E>_def)\n  also have \"\\<dots> \\<le> norm (DR x dx)\" unfolding DRD by fact\n  finally show \"\\<E> x * norm dx \\<le> norm (DR x dx)\" .\n\n  have \"\\<E>\\<^sub>p (R x) * norm dx \\<le> preexpansion res' * norm dx\"\n    by (rule mult_right_mono) (auto simp: \\<E>\\<^sub>p_def R_def)\n  also have \"\\<dots> \\<le> norm (DR x dx)\" unfolding DRD by fact\n  finally show \"\\<E>\\<^sub>p (R x) * norm dx \\<le> norm (DR x dx)\" .\nqed\n\n\nlemma check_line_core_correct:\n  \"check_line_core pf m0 n0 True i \\<le> SPEC (\\<lambda>correct. correct \\<longrightarrow> correct_res (results ! i))\"\n  if [refine_vcg]: NF\n  unfolding check_line_core_def\n  supply [refine_vcg] = check_line_nres_c1_correct[le]\n  by refine_vcg\n\n\ntext \\<open>The symmetric reduction\\<close>\n\nlemma source_of_res_mirror: \"(x, y, z) \\<in> source_of_res (mirror_result res) \\<longleftrightarrow>\n    (-x, -y, z) \\<in> source_of_res res\"\n  by (cases res)\n     (auto simp: source_of_res_def ivl_of_res_def ivl_of_resultrect_def set_of_ivl_def)\n\nlemma conefield_of_res_mirror[simp]: \"(x, y, z) \\<in> conefield_of_res (mirror_result res) \\<longleftrightarrow>\n    (x, y, z) \\<in> conefield_of_res res\"\n  by (cases res) (auto simp: conefield_of_res_def ivl_of_res_def)\n\nlemma c1_of_res_mirror: \"((x, y, z), dx, dy, dz) \\<in> c1_of_res (mirror_result res) \\<longleftrightarrow>\n  ((-x, -y, z), dx, dy, dz) \\<in> c1_of_res res\"\n  by (auto simp: c1_of_res_def source_of_res_mirror)\n\nlemmas [simp] = lorenz_S(2)\nlemma lorenz_S_idem[simp]: \"lorenz_S (lorenz_S x) = (x::R3)\"\n  by (auto simp: lorenz_S_def split_beta')\nlemma lorenz_S_exivl[simp]:\n  \"lorenz.existence_ivl0 (lorenz_S X) = lorenz.existence_ivl0 X\"\n  using lorenz_S(1)[of _ X]\n  using lorenz_S(1)[of _ \"lorenz_S X\"]\n  by auto\nlemma lorenz_S_zero[simp]: \"lorenz_S x = 0 \\<longleftrightarrow> (x::R3) = 0\"\n  by (auto simp: lorenz_S_def split_beta' prod_eq_iff)\nlemma lorenz_S_returns_toI[simp]:\n  \"x returns_to (lorenz_S ` P) \\<Longrightarrow> lorenz_S x returns_to P\"\n  apply (auto simp: lorenz.returns_to_def)\n  subgoal premises prems for t\n  proof -\n    have \" \\<forall>\\<^sub>F s in at_right 0. s < t\"\n      using tendsto_ident_at \\<open>0 < t\\<close>\n      by (rule order_tendstoD)\n    then have \" \\<forall>\\<^sub>F s in at_right 0. s \\<in> lorenz.existence_ivl0 x\"\n      unfolding eventually_at_filter\n      apply eventually_elim\n      using \\<open>0 < t\\<close> lorenz.closed_segment_subset_existence_ivl[OF prems(3)]\n      by (auto simp: closed_segment_eq_real_ivl subset_iff)\n    then show ?thesis using prems(1)\n      by eventually_elim force\n  qed\n  done\n\nlemma lorenz_S_returns_to[simp]:\n  \"lorenz_S x returns_to P \\<longleftrightarrow> x returns_to (lorenz_S ` P)\"\n  using lorenz_S_returns_toI[of P x] lorenz_S_returns_toI[of \"lorenz_S ` P\" \"lorenz_S x\"]\n  by (auto simp: image_image)\nlemma lorenz_S_image_Sigma[simp]: \"lorenz_S ` \\<Sigma> = \\<Sigma>\"\n  apply (auto simp: \\<Sigma>_def lorenz_S_def)\n  apply (rule image_eqI)\n   apply (rule lorenz_S_idem[symmetric])\n  apply (auto simp: \\<Sigma>_def lorenz_S_def)\n  done\n\nlemma linear_lorenz_S: \"linear lorenz_S\"\n  by unfold_locales (auto simp: lorenz_S_def)\nlemma inj_lorenz_S: \"inj_on (lorenz_S::R3 \\<Rightarrow> _) G\"\n  by (rule inj_onI) (auto simp: lorenz_S_def prod_eq_iff)\n\nlemma lorenz_S_return_time:\n  \"lorenz.return_time P (lorenz_S x) = lorenz.return_time (lorenz_S ` P) x\"\n  if \"x returns_to (lorenz_S ` P)\" \"closed P\"\nproof -\n  from lorenz.returns_toE[OF that(1)] obtain t0 t1\n    where f: \"0 < t0\" \"t0 \\<le> t1\" \" t1 \\<in> lorenz.existence_ivl0 x\"\n      \"lorenz.flow0 x t1 \\<in> lorenz_S ` P\"\n      \"\\<And>t. 0 < t \\<Longrightarrow> t < t0 \\<Longrightarrow> lorenz.flow0 x t \\<notin> lorenz_S ` P\"\n    by auto\n  have [simp]: \"lorenz.return_time (lorenz_S ` P) x \\<in> lorenz.existence_ivl0 x\"\n    by (auto intro!: that closed_injective_linear_image linear_lorenz_S\n        lorenz.return_time_exivl\n        inj_lorenz_S)\n  have c': \"closed (lorenz_S ` P)\"\n    by (auto intro!: that closed_injective_linear_image linear_lorenz_S\n        lorenz.return_time_exivl lorenz.return_time_pos\n        inj_lorenz_S)\n  show ?thesis\n    using f(1-4)\n    using lorenz.return_time_returns[OF that(1) c']\n    apply (intro lorenz.return_time_eqI)\n       apply (auto intro!: that closed_injective_linear_image linear_lorenz_S\n        lorenz.return_time_exivl lorenz.return_time_pos c'\n        inj_lorenz_S)\n    subgoal premises prems for a b c d e f g\n    proof -\n      have [simp]: \"a \\<in> lorenz.existence_ivl0 x\"\n        using _ that(1)\n        apply (rule lorenz.less_return_time_imp_exivl)\n        using prems that(2) c'\n        by auto\n      have \"lorenz.return_time (lorenz_S ` P) x \\<le> a\"\n        apply (rule lorenz.return_time_le)\n        using prems\n           apply (auto intro!: that closed_injective_linear_image linear_lorenz_S\n            lorenz.return_time_exivl lorenz.return_time_pos c'\n            inj_lorenz_S)\n        apply (rule image_eqI)\n         apply (rule lorenz_S_idem[symmetric])\n        by auto\n      then show ?thesis using prems\n        by simp\n    qed\n    done\nqed\n\nlemma lorenz_S_poincare_map:\n  \"lorenz.poincare_map P (lorenz_S x) = lorenz_S (lorenz.poincare_map (lorenz_S ` P) x)\"\n  if \"x returns_to (lorenz_S ` P)\" \"closed P\"\n  using that\n  unfolding lorenz.poincare_map_def\n  apply (auto simp: lorenz_S_return_time)\n  apply (subst lorenz_S)\n   by (auto intro!: lorenz.return_time_exivl that\n      closed_injective_linear_image linear_lorenz_S inj_lorenz_S)\n\nlemma [continuous_intros]: \"isCont (lorenz_S::_\\<Rightarrow>R3) x\"\n  \"continuous_on (G::R3 set) lorenz_S\"\n  by (auto simp:lorenz_S_def[abs_def] split_beta' continuous_intros)\n\nlemma filtermap_lorenz_S_le: \"filtermap lorenz_S (at x within lorenz_S ` P) \\<le>(at (lorenz_S x::R3) within P)\"\\<comment> \\<open>TODO: generalize!\\<close>\n  unfolding at_within_def\n  apply (auto simp: intro!: antisym filtermap_inf[le] filtermap_inf[ge])\n    apply (rule inf.coboundedI1)\n    apply (subst filtermap_nhds_open_map)\n    apply (auto simp: intro!: invariance_of_domain inj_lorenz_S continuous_intros)\n   apply (rule inf.coboundedI2)\n   apply (auto simp: image_image )\n  apply (auto simp: lorenz_S_def split_beta')[]\n  done\n\nlemma filtermap_lorenz_S_eq: \"filtermap lorenz_S (at (x::R3) within lorenz_S ` P) = (at (lorenz_S x::R3) within P)\"\n  apply (rule antisym)\n  using filtermap_lorenz_S_le[of \"x\" P]\n   apply simp\n  subgoal\n  proof -\n    have \"filtermap lorenz_S (at (lorenz_S x) within P) \\<le>\n    filtermap lorenz_S (filtermap lorenz_S  (at x within lorenz_S ` P))\"\n      using filtermap_lorenz_S_le[of \"lorenz_S x\" \"lorenz_S ` P\"]\n      by (auto simp: image_image filtermap_filtermap)\n    then show ?thesis\n      apply (subst (asm) filtermap_mono_strong)\n      by (auto simp: inj_lorenz_S)\n  qed\n  done\n\nlemma norm_lorenz_S[simp]: \"norm (lorenz_S x) = norm x\"\n  by (auto simp: lorenz_S_def norm_prod_def split_beta')\n\nlemma bl_lorenz_S: \"bounded_linear (lorenz_S)\"\n  by unfold_locales (auto simp: lorenz_S_def norm_prod_def intro!: exI[where x=1])\n\nlemma filtermap_lorenz_S_eq_bot[simp]:\n  \"filtermap (lorenz_S::R3\\<Rightarrow>_) F = bot \\<longleftrightarrow> F = bot\"\n  apply (auto simp: )\n  apply (subst (asm) filtermap_bot[symmetric])\n  apply (subst (asm) filtermap_eq_strong)\n  by (auto simp: inj_lorenz_S)\n\nlemma netlimit_filtermap[simp]:\n  \"at x within X \\<noteq> bot \\<Longrightarrow> netlimit (filtermap lorenz_S (at x within X)) = lorenz_S (x::R3)\"\n  apply (rule tendsto_Lim)\n  unfolding filterlim_filtermap\n   apply simp\n  by (auto intro!: tendsto_eq_intros simp: split_beta' lorenz_S_def[abs_def])\n\nlemma lorenz_S_halfspace [simp]: \"lorenz_S ` \\<Sigma>\\<^sub>l\\<^sub>e = \\<Sigma>\\<^sub>l\\<^sub>e\"\n  apply (auto simp: \\<Sigma>\\<^sub>l\\<^sub>e_def lorenz_S_def[abs_def])\n  apply (rule image_eqI)\n   apply auto\n   apply (rule sym)\n   apply (rule minus_minus)\n  apply (rule minus_minus[symmetric])\n  done\n\nlemma closure_Sigma_le_eq: \"closure \\<Sigma>\\<^sub>l\\<^sub>e = \\<Sigma>\\<^sub>l\\<^sub>e\"\nproof (rule closure_closed)\n  have \"\\<Sigma>\\<^sub>l\\<^sub>e = {x. x \\<bullet> (0, 0, 1) \\<le> 27}\"\n    by (auto simp: \\<Sigma>\\<^sub>l\\<^sub>e_def )\n  also have \"closed \\<dots>\"\n    by (rule closed_halfspace_component_le)\n  finally show \"closed \\<Sigma>\\<^sub>l\\<^sub>e\" .\nqed\n\nlemma closure_Sigma_le[simp]: \"closure (\\<Sigma>\\<^sub>l\\<^sub>e - {x}) = \\<Sigma>\\<^sub>l\\<^sub>e\"\nproof (cases \"x \\<in> \\<Sigma>\\<^sub>l\\<^sub>e\")\n  case that: True\n  have \"closure \\<Sigma>\\<^sub>l\\<^sub>e \\<subseteq> closure (insert x (\\<Sigma>\\<^sub>l\\<^sub>e - {x}))\" by (rule closure_mono) auto\n  also have \"\\<dots> = insert x (closure (\\<Sigma>\\<^sub>l\\<^sub>e - {x}))\"\n    apply (subst closure_insert) by simp\n  also\n  have \"x \\<in> closure (\\<Sigma>\\<^sub>l\\<^sub>e - {x})\"\n    apply (rule closed_sequentially[where f=\"\\<lambda>n. x - (0, 0, inverse (Suc n))\"])\n      apply (rule closed_closure)\n    subgoal\n      apply (auto simp: ) apply (rule subsetD) apply (rule closure_subset)\n      using that\n      apply (auto simp: \\<Sigma>\\<^sub>l\\<^sub>e_def prod_eq_iff)\n      apply (rule order_trans)\n       apply (rule diff_right_mono)\n       apply (assumption)\n      apply simp\n      done\n    subgoal\n      apply (rule tendsto_eq_intros)\n        apply (rule tendsto_intros)\n        apply (rule tendsto_intros)\n        apply (rule tendsto_intros)\n        apply (rule tendsto_intros)\n        apply (rule tendsto_intros)\n      apply (rule LIMSEQ_inverse_real_of_nat)\n      by (auto simp: prod_eq_iff)\n    done\n  then have \"insert x (closure (\\<Sigma>\\<^sub>l\\<^sub>e - {x})) \\<subseteq> closure (\\<Sigma>\\<^sub>l\\<^sub>e - {x})\"\n    by auto\n  finally have \"closure \\<Sigma>\\<^sub>l\\<^sub>e \\<subseteq> closure (\\<Sigma>\\<^sub>l\\<^sub>e - {x})\" .\n  moreover\n  have \"closure (\\<Sigma>\\<^sub>l\\<^sub>e - {x}) \\<subseteq> closure (\\<Sigma>\\<^sub>l\\<^sub>e)\"\n    by (rule closure_mono) auto\n  ultimately have \"closure (\\<Sigma>\\<^sub>l\\<^sub>e - {x}) = closure (\\<Sigma>\\<^sub>l\\<^sub>e)\"\n    by simp\n  also have \"\\<dots> = \\<Sigma>\\<^sub>l\\<^sub>e\"\n    by (rule closure_Sigma_le_eq)\n  finally show ?thesis .\nnext\n  case False\n  then show ?thesis\n    apply simp\n    apply (rule closure_Sigma_le_eq)\n    done\nqed\n\nlemma lorenz_S_return_time_has_derivative:\n  assumes \"(lorenz.return_time \\<Sigma> has_derivative D) (at x within \\<Sigma>\\<^sub>l\\<^sub>e)\"\n        and \"lorenz.returns_to \\<Sigma> x\" and \"x \\<in> \\<Sigma>\\<^sub>l\\<^sub>e\"\n  shows \"(lorenz.return_time \\<Sigma> has_derivative D o lorenz_S) (at (lorenz_S x) within \\<Sigma>\\<^sub>l\\<^sub>e)\"\nproof -\n  have [simp]: \"\\<not>trivial_limit (at x within \\<Sigma>\\<^sub>l\\<^sub>e)\"\n    unfolding at_within_eq_bot_iff\n    using assms\n    by simp\n  interpret bounded_linear \"lorenz_S::R3\\<Rightarrow>_\" by (rule bl_lorenz_S)\n  have \"\\<forall>\\<^sub>F x in at x within \\<Sigma>\\<^sub>l\\<^sub>e. (x::R3) returns_to \\<Sigma>\"\n    by (blast intro: lorenz.eventually_returns_to_continuousI has_derivative_continuous assms)\n  then have \"\\<forall>\\<^sub>F y in at x within \\<Sigma>\\<^sub>l\\<^sub>e.\n               inverse (norm (y - x)) * (lorenz.return_time \\<Sigma> y - lorenz.return_time \\<Sigma> x - D (y - x))\n             = inverse (norm (lorenz_S y - lorenz_S x)) *\n               (lorenz.return_time \\<Sigma> (lorenz_S y) - lorenz.return_time \\<Sigma> (lorenz_S x) - D (y - x))\"\n      by eventually_elim (auto simp: lorenz_S_return_time assms diff[symmetric])\n  then show ?thesis\n    using assms\n    apply (subst filtermap_lorenz_S_eq[symmetric])\n    apply (auto simp: has_derivative_def filterlim_filtermap)\n    unfolding o_def\n     apply (rule bounded_linear_compose, assumption, rule bl_lorenz_S)\n    unfolding diff lorenz_S_idem\n     apply (auto simp: Lim_ident_at)\n    apply (blast intro: Lim_transform_eventually)\n    done\nqed\n\nlemma lorenz_S_return_time_differentiable:\n  \"lorenz.return_time \\<Sigma> differentiable at (lorenz_S x) within \\<Sigma>\\<^sub>l\\<^sub>e\"\n  if \"lorenz.return_time \\<Sigma> differentiable at x within \\<Sigma>\\<^sub>l\\<^sub>e\"\n    \"lorenz.returns_to \\<Sigma> x\" \"x \\<in> \\<Sigma>\\<^sub>l\\<^sub>e\"\nproof -\n  from that obtain D where \"(lorenz.return_time \\<Sigma> has_derivative D) (at x within \\<Sigma>\\<^sub>l\\<^sub>e)\"\n    by (auto simp: differentiable_def)\n  then have \"(lorenz.return_time \\<Sigma> has_derivative D o lorenz_S) (at (lorenz_S x) within \\<Sigma>\\<^sub>l\\<^sub>e)\"\n    by (rule lorenz_S_return_time_has_derivative) fact+\n  then show ?thesis\n    by (auto simp: differentiable_def)\nqed\n\nlemma lorenz_S_has_derivative:\n  \"(lorenz_S has_derivative lorenz_S) (at (x::R3) within X)\"\n  by (auto simp: lorenz_S_def[abs_def] split_beta' intro!: derivative_eq_intros)\n\nlemma lorenz_S_poincare_map_has_derivative:\n  assumes \"(lorenz.poincare_map \\<Sigma> has_derivative D) (at x within \\<Sigma>\\<^sub>l\\<^sub>e)\"\n    \"(lorenz.return_time \\<Sigma> has_derivative Dr) (at x within \\<Sigma>\\<^sub>l\\<^sub>e)\"\n    \"lorenz.returns_to \\<Sigma> x\" \"x \\<in> \\<Sigma>\\<^sub>l\\<^sub>e\"\n  shows \"(lorenz.poincare_map \\<Sigma> has_derivative lorenz_S o D o lorenz_S) (at (lorenz_S x) within \\<Sigma>\\<^sub>l\\<^sub>e)\"\nproof -\n  have [simp]: \"\\<not>trivial_limit (at x within \\<Sigma>\\<^sub>l\\<^sub>e)\"\n    unfolding at_within_eq_bot_iff\n    using assms\n    by simp\n  interpret bounded_linear \"lorenz_S::R3\\<Rightarrow>_\" by (rule bl_lorenz_S)\n  have \"\\<forall>\\<^sub>F x in at x within \\<Sigma>\\<^sub>l\\<^sub>e. (x::R3) returns_to \\<Sigma>\"\n    by (blast intro: lorenz.eventually_returns_to_continuousI has_derivative_continuous assms)\n  then have \"\\<forall>\\<^sub>F y in at x within \\<Sigma>\\<^sub>l\\<^sub>e.\n                 (lorenz_S (lorenz.poincare_map \\<Sigma> y) - lorenz_S (lorenz.poincare_map \\<Sigma> x) - lorenz_S (D (y - x))) /\\<^sub>R\n                 norm (y - x) \n               = (lorenz.poincare_map \\<Sigma> (lorenz_S y) - lorenz.poincare_map \\<Sigma> (lorenz_S x) - lorenz_S (D (y - x))) /\\<^sub>R\n                 norm (lorenz_S y - lorenz_S x)\"\n    by eventually_elim (auto simp: lorenz_S_return_time lorenz_S_poincare_map assms diff[symmetric])\n  then show ?thesis\n    using has_derivative_compose[OF assms(1) lorenz_S_has_derivative] assms\n    apply (subst filtermap_lorenz_S_eq[symmetric])\n    apply (auto simp: has_derivative_def filterlim_filtermap)\n    unfolding o_def\n     apply (rule bounded_linear_compose, rule bl_lorenz_S)\n     apply (rule bounded_linear_compose, assumption, rule bl_lorenz_S)\n    unfolding diff lorenz_S_idem\n     apply (auto simp: Lim_ident_at)\n    apply (blast intro: Lim_transform_eventually)\n    done\nqed\n\nlemma [simp]: \"expansion (mirror_result res) = expansion res\"\n  by (cases res) auto\n\nlemma lorenz_S_on_plane: \"lorenz_S (dx, dy, 0::real) = - (dx, dy, 0)\"\n  by (auto simp: lorenz_S_def )\n\nlemma mirror_result_idem[simp]: \"mirror_result (mirror_result x) = x\"\n  by (cases x) (auto simp: mirror_result_def)\n\nlemma mirror_in_set: \"x \\<in> set results \\<Longrightarrow> mirror_result x \\<in> set results\"\n  by (auto simp: results_def symmetrize_def)\n\nlemma mirror_result_in:\n  \"mirror_result res2 \\<in> return_of_res results (mirror_result res)\"\n  if \"res2 \\<in> return_of_res results res\"\nproof -\n  from that have \"res2 \\<in> set results\" by (rule in_return_of_resD)\n  from mirror_in_set[OF this] have \"mirror_result res2 \\<in> set results\" .\n  then show ?thesis\n    apply (cases res2; cases res)\n    using that\n    by (auto simp: return_of_res_def get_results_def)\nqed\n\nlemma in_source_of_res_mirrorI:\n  \"(x::R3) \\<in> source_of_res (mirror_result (r))\" if \"lorenz_S x \\<in> source_of_res r\"\n  using that\n  apply (cases r; cases x)\n  by (auto simp: source_of_res_def set_of_ivl_def ivl_of_res_def lorenz_S_def\n      less_eq_prod_def ivl_of_resultrect_def)\n\nlemma conefield_of_res_mirror_simp[simp]: \"conefield_of_res (mirror_result res2) = conefield_of_res res2\"\n  by (cases res2) (auto simp: conefield_of_res_def)\n\nlemma lorenz_minus_planeI: \"lorenz_S (- x) = x\" if \"snd (snd (x::R3)) = 0\"\n  using that\n  by (auto simp: lorenz_S_def split_beta' prod_eq_iff)\n\nlemma preexpansion_mirror_result[simp]: \"preexpansion (mirror_result res2) = preexpansion res2\"\n  by (cases res2) (auto simp: )\n\nlemma lorenz_S_tendsto_0I: \"(lorenz.flow0 (lorenz_S x) \\<longlongrightarrow> 0) at_top\"\n  if \"{0..} \\<subseteq> lorenz.existence_ivl0 x\" \"(lorenz.flow0 x \\<longlongrightarrow> 0) at_top\"\nproof (rule Lim_transform_eventually)\n  have \"\\<forall>\\<^sub>F s in at_top. (s::real) \\<ge> 0\"\n    using eventually_ge_at_top by blast\n  then show \"\\<forall>\\<^sub>F s in at_top. lorenz_S (lorenz.flow0 x s) = lorenz.flow0 (lorenz_S x) s\"\n    by eventually_elim (use that in auto)\n  show \"((\\<lambda>s. lorenz_S (lorenz.flow0 x s)) \\<longlongrightarrow> 0) at_top\"\n    unfolding Zfun_def[symmetric] by (rule bounded_linear.tendsto_zero[OF bl_lorenz_S that(2)])\nqed\n\nlemma lorenz_S_tendsto_0_iff:\n  \"(lorenz.flow0 (lorenz_S x) \\<longlongrightarrow> 0) at_top \\<longleftrightarrow> (lorenz.flow0 x \\<longlongrightarrow> 0) at_top\"\n  if \"{0..} \\<subseteq> lorenz.existence_ivl0 x\"\n  using lorenz_S_tendsto_0I[of x, OF that] lorenz_S_tendsto_0I[of \"lorenz_S x\"] that\n  by auto\n\nlemma lorenz_S_eq_iff[simp]: \"lorenz_S y = lorenz_S x \\<longleftrightarrow> y = x\" for x y::\"real*real*real\"\n  by (auto simp: lorenz_S_def split: prod.splits)\n\nlemma lorenz_S_\\<Gamma>: \"lorenz_S x \\<in> \\<Gamma> \\<longleftrightarrow> x \\<in> \\<Gamma>\"\n  apply (auto simp: \\<Gamma>_def lorenz_S_tendsto_0_iff )\n  subgoal for t\n    apply (auto simp: dest!: spec[where x=t])\n    apply (subst (asm) lorenz_S) apply auto\n    apply (subst (asm) (2) lorenz_S_image_Sigma[symmetric])\n    by (simp del: lorenz_S_image_Sigma)\n  subgoal for t\n    apply (auto simp: dest!: spec[where x=t])\n    apply (subst (asm) lorenz_S) apply auto\n    apply (subst (asm) lorenz_S_image_Sigma[symmetric])\n    apply (auto simp del: lorenz_S_image_Sigma)\n    done\n  done\n\nlemma sourcei_of_res_mirror: \"(x, y, z) \\<in> sourcei_of_res (mirror_result res) \\<longleftrightarrow>\n    (-x, -y, z) \\<in> sourcei_of_res res\"\n  using lorenz_S_\\<Gamma>[of \"(x, y, z)\"]\n  by (cases res)\n     (auto simp: source_of_res_def sourcei_of_res_def ivl_of_res_def ivl_of_resultrect_def\n       set_of_ivl_def \\<Gamma>\\<^sub>i_def lorenz_S_def)\n\nlemma c1i_of_res_mirror: \"((x, y, z), dx, dy, dz) \\<in> c1i_of_res (mirror_result res) \\<longleftrightarrow>\n  ((-x, -y, z), dx, dy, dz) \\<in> c1i_of_res res\"\n  by (auto simp: c1i_of_res_def sourcei_of_res_mirror)\n\nlemma correct_res_mirror_result:\n  \"correct_res (mirror_result res)\" if \"correct_res res\"\n  unfolding correct_res_def\nproof (clarsimp simp add: c1i_of_res_mirror, goal_cases)\n  case (1 x y z dx dy dz)\n  then have 1: \"(lorenz_S (x, y, z), dx, dy, dz) \\<in> c1i_of_res res\"\n    by (auto simp: lorenz_S_def)\n  from that[unfolded correct_res_def, rule_format, OF 1, simplified]\n  have \"(lorenz_S (x, y, z)) \\<in> plane_of (Sctn (0, 0, 1) 27)\"\n    \"(dx, dy, dz) \\<in> plane_of (Sctn (0, 0, 1) 0)\"\n    by auto\n  then have plane: \"(x, y, z) \\<in> plane_of (Sctn (0, 0, 1) 27)\"\n    \"(dx, dy, dz) \\<in> plane_of (Sctn (0, 0, 1) 0)\"\n    by (auto simp: plane_of_def lorenz_S_def)\n  then show ?case\n  proof (clarsimp, goal_cases)\n    case mem: 1\n    with that[unfolded correct_res_def, rule_format, OF 1, simplified]\n    obtain D res2 where D:\n      \"lorenz_S (x, y, z) returns_to \\<Sigma>\"\n      \"lorenz.return_time \\<Sigma> differentiable at (lorenz_S (x, y, z)) within \\<Sigma>\\<^sub>l\\<^sub>e\"\n      \"(lorenz.poincare_map \\<Sigma> has_derivative D) (at (lorenz_S (x, y, z)) within \\<Sigma>\\<^sub>l\\<^sub>e)\"\n      \"expansion res * norm (dx, dy, dz) \\<le> norm (D (dx, dy, dz))\"\n      \"res2 \\<in> return_of_res results res\"\n      \"(lorenz.poincare_map \\<Sigma> (lorenz_S (x, y, z)), D (dx, dy, dz)) \\<in> c1_of_res res2\"\n      \"preexpansion res2 * norm (dx, dy, dz) \\<le> norm (D (dx, dy, dz))\"\n      by auto\n    from plane have S_le: \"lorenz_S (x, y, z) \\<in> \\<Sigma>\\<^sub>l\\<^sub>e\"\n      by (auto simp: \\<Sigma>\\<^sub>l\\<^sub>e_def plane_of_def lorenz_S_def)\n    interpret linear D by (rule has_derivative_linear; fact)\n\n    have ret: \"(x, y, z) returns_to \\<Sigma>\" using D(1) lorenz_S_returns_to by simp\n    moreover have \"lorenz.return_time \\<Sigma> differentiable at (x, y, z) within \\<Sigma>\\<^sub>l\\<^sub>e\"\n      using lorenz_S_return_time_differentiable[OF D(2) D(1) S_le] by auto\n    moreover from D obtain Dr where Dr: \"(lorenz.return_time \\<Sigma> has_derivative Dr) (at (lorenz_S (x, y, z)) within \\<Sigma>\\<^sub>l\\<^sub>e)\"\n      by (auto simp: differentiable_def)\n    let ?D = \"lorenz_S \\<circ> D \\<circ> lorenz_S\"\n    have \"(lorenz.poincare_map \\<Sigma> has_derivative ?D) (at (x, y, z) within \\<Sigma>\\<^sub>l\\<^sub>e)\"\n      using lorenz_S_poincare_map_has_derivative[OF D(3) Dr D(1) S_le]\n      by auto\n    moreover\n    from plane have [simp]: \"dz = 0\" by (auto simp: plane_of_def)\n    have \"expansion (mirror_result res) * norm (dx, dy, dz) \\<le> norm (?D (dx, dy, dz))\"\n      using D(4) apply (auto simp: )\n      unfolding lorenz_S_on_plane neg\n      by simp\n    moreover have \\<open>mirror_result res2 \\<in> return_of_res results (mirror_result res)\\<close>\n      using D(5) by (rule mirror_result_in)\n    moreover have \"(lorenz.poincare_map \\<Sigma> (x, y, z), ?D (dx, dy, dz)) \\<in> c1_of_res (mirror_result res2)\"\n      using D(6) apply (subst (asm) lorenz_S_poincare_map)\n        apply auto apply fact\n      apply (auto simp: c1_of_res_def in_source_of_res_mirrorI)\n      unfolding lorenz_S_on_plane neg\n      apply (subst lorenz_minus_planeI)\n       apply (auto simp: conefield_of_res_def conefield_alt_def cone_hull_expl\n          in_segment tangent_of_deg_def)\n      done\n    moreover have \"preexpansion (mirror_result res2) * norm (dx, dy, dz) \\<le> norm (?D (dx, dy, dz))\"\n      using D(7) apply (auto simp: )\n      unfolding lorenz_S_on_plane neg\n      by simp\n    ultimately show ?case\n      by (force intro!: exI[where x = ?D] bexI[where x=\"mirror_result res2\"])\n  qed\nqed\n\nlemma reduce_lorenz_symmetry: \"Ball (set results) correct_res\"\n  if \"Ball (set coarse_results) correct_res\"\n  using that\n  by (auto simp: results_def symmetrize_def intro!: correct_res_mirror_result)\n\nend\n\nsubsection \\<open>Code Generation\\<close>\n\ndefinition [code_abbrev]: \"my_divide_integer (i::integer) (j::integer) = i div j\"\ncode_printing constant my_divide_integer \\<rightharpoonup> (SML) \"IntInf.div/ (_,/ _)\"\n\nsubsection \\<open>Tuning code equations\\<close>\n\ndefinition mult_twopow_int::\"int \\<Rightarrow> int \\<Rightarrow> int\" where \"mult_twopow_int x n = x * (power_int 2 n)\"\ndefinition div_twopow_int :: \"int \\<Rightarrow> int \\<Rightarrow> int\" where \"div_twopow_int x n = x div (power_int 2 n)\"\n\ncontext includes integer.lifting begin\n\nlift_definition mult_twopow_integer :: \"integer \\<Rightarrow> integer \\<Rightarrow> integer\" is mult_twopow_int .\nlift_definition div_twopow_integer :: \"integer \\<Rightarrow> integer \\<Rightarrow> integer\" is div_twopow_int .\n\nend\n\nlemma compute_float_round_down[code]:\n  \"float_round_down prec (Float m e) =\n    (let d = bitlen \\<bar>m\\<bar> - int prec - 1 in\n      if 0 < d then Float (div_twopow_int m d) (e + d)\n      else Float m e)\"\n  including float.lifting\n  using Float.compute_float_down[of \"Suc prec - bitlen \\<bar>m\\<bar> - e\" m e, symmetric]\n  by transfer\n     (auto simp add: field_simps abs_mult log_mult bitlen_alt_def truncate_down_def\n      div_twopow_int_def power_int_def\n      cong del: if_weak_cong)\n\nlemma compute_float_plus_down[code]:\n  fixes p::nat and m1 e1 m2 e2::int\n  shows \"float_plus_down p (Float m1 e1) (Float m2 e2) =\n    (if m1 = 0 then float_round_down p (Float m2 e2)\n    else if m2 = 0 then float_round_down p (Float m1 e1)\n    else\n      (if e1 \\<ge> e2 then\n        (let k1 = Suc p - nat (bitlen \\<bar>m1\\<bar>) in\n          if bitlen \\<bar>m2\\<bar> > e1 - e2 - k1 - 2\n          then float_round_down p ((Float m1 e1) + (Float m2 e2))\n          else float_round_down p (Float (mult_twopow_int m1 (int k1 + 2) + sgn m2) (e1 - int k1 - 2)))\n    else float_plus_down p (Float m2 e2) (Float m1 e1)))\"\n  using Float.compute_float_plus_down[of p m1 e1 m2 e2]\n  by (auto simp: mult_twopow_int_def Let_def power_int_def nat_add_distrib)\n\nsubsection \\<open>Codegen\\<close>\n\ndefinition \"is_dRETURN_True x = (case x of dRETURN b \\<Rightarrow> b | _ \\<Rightarrow> False)\"\ndefinition \"file_output_option s f =\n  (case s of None \\<Rightarrow> f None\n  | Some s \\<Rightarrow> file_output (String.implode s) (\\<lambda>pf. f (Some pf)))\"\n\ndefinition \"check_line_lookup_out s m0 n0 c1 i =\n  is_dRETURN_True (file_output_option s (\\<lambda>pf. check_line_core_impl pf m0 n0 c1 i))\"\n\nfun alternating where \"alternating [] xs = xs\"\n  | \"alternating xs [] = xs\"\n  | \"alternating (x#xs) (y#ys) = x#y#alternating xs ys\"\n\ndefinition \"ordered_lines = alternating (rev [0..<222]) ([222..<400])\"\n  \\<comment> \\<open>the hard ones ``first'', potentially useless due to nondeterministic \\<open>Parallel.map\\<close>\\<close>\n\ndefinition \"parallel_check filenameo m n c1 ns =\n  Parallel.forall (\\<lambda>i.\n    let\n      _ = print (String.implode (''# Starting '' @ show i @ ''\\<newline>''));\n      b =\n      check_line_lookup_out (map_option (\\<lambda>f. f @ show i) filenameo)\n        (Some m) (Some n) c1 i;\n      _ = if b\n        then print (String.implode (''# Success: '' @ show i @ ''\\<newline>''))\n        else print (String.implode (''# Failed:  '' @ show i @ ''\\<newline>''))\n    in b\n    ) ns\"\n\nML \\<open>val check_line = @{computation_check\n  terms:\n    Trueprop\n    parallel_check\n    ordered_lines\n    check_line_core_impl\n    check_line_lookup_out\n\n    (* bool *)\n    True False\n\n    (* num *)\n    Num.One Num.Bit0 Num.Bit1\n\n    (* nat *)\n    Suc \"0::nat\" \"1::nat\" \"numeral::num\\<Rightarrow>nat\"\n\n    (* int / integer*)\n    \"numeral::num\\<Rightarrow>int\"\n    \"numeral::num\\<Rightarrow>integer\"\n    \"uminus::_\\<Rightarrow>int\"\n    \"uminus::_\\<Rightarrow>integer\"\n    int_of_integer integer_of_int\n    \"0::int\"\n    \"1::int\"\n\n    (* Pairs *)\n    \"Pair::_ \\<Rightarrow> _\\<Rightarrow> (real list \\<times> real list)\"\n    \"Pair::_\\<Rightarrow>_\\<Rightarrow>(real list \\<times> real list) \\<times> real list sctn\"\n    \"Pair::_\\<Rightarrow>_\\<Rightarrow>((real list \\<times> real list) \\<times> real list sctn) list \\<times> real aform reach_options\"\n\n    (* Option *)\n    \"None::nat option\"\n    \"Some::_\\<Rightarrow>nat option\"\n    \"None::string option\"\n    \"Some::_\\<Rightarrow>string option\"\n\n    (* Lists *)\n    \"Nil::real list\"\n    \"Cons::_\\<Rightarrow>_\\<Rightarrow>real list\"\n    \"Nil::nat list\"\n    \"Cons::_\\<Rightarrow>_\\<Rightarrow>nat list\"\n    \"Nil::real aform list\"\n    \"Cons::_\\<Rightarrow>_\\<Rightarrow>real aform list\"\n    \"Nil::((real list \\<times> real list) \\<times> real list sctn) list\"\n    \"Cons::_\\<Rightarrow>_\\<Rightarrow>((real list \\<times> real list) \\<times> real list sctn) list\"\n    \"Nil::(((real list \\<times> real list) \\<times> real list sctn) list \\<times> real aform reach_options)list\"\n    \"Cons::_\\<Rightarrow>_\\<Rightarrow>(((real list \\<times> real list) \\<times> real list sctn) list \\<times> real aform  reach_options)list\"\n\n    (* String *)\n    String.Char\n    String.implode \"Cons::char \\<Rightarrow> char list \\<Rightarrow> char list\" \"Nil::char list\"\n\n    (* float *)\n    Float float_of_int float_of_nat\n\n    (* real *)\n    \"numeral::num\\<Rightarrow>real\" \"real_of_float\" \"(/)::real\\<Rightarrow>real\\<Rightarrow>real\" \"uminus::real\\<Rightarrow>_\"\n    real_divl real_divr\n    real_of_int\n\n    (* section *)\n    \"Sctn::_\\<Rightarrow>_\\<Rightarrow>real list sctn\"\n\n    (* aform *)\n    \"aforms_of_ivls::_\\<Rightarrow>_\\<Rightarrow>real aform list\"\n\n    (* input *)\n    coarse_results\n\n    (* modes *)\n    xsec xsec' ysec ysec' zsec zsec' zbucket\n    lookup_mode\n    ro\n    ro_outer\n    mode_outer\n\n    (* unit *)\n    \"()\"\n\n  }\\<close>\n\n\nlemma is_dRETURN_True_iff[simp]: \"is_dRETURN_True x \\<longleftrightarrow> (x = dRETURN True)\"\n  by (auto simp: is_dRETURN_True_def split: dres.splits)\n\nlemma check_line_core_impl_True:\n  \"check_line_core_impl pfo m n True i = dRETURN True \\<Longrightarrow> NF \\<Longrightarrow> correct_res (results ! i)\"\n  apply (cases \"check_line_core_impl pfo m n True i\")\n  using check_line_core_correct[of pfo m n i]\n    check_line_core_impl.refine[of pfo pfo True True i i m m n n]\n    apply (auto simp: nres_rel_def)\n  apply (drule order_trans[where y=\"check_line_core pfo m n True i\"])\n   apply assumption\n  by auto\n\nlemma check_line_lookup_out: \"correct_res (results ! i)\"\n  if \"\\<exists>s m n. check_line_lookup_out s m n True i\" NF\n  using that\n  by (auto simp: check_line_lookup_out_def file_output_iff check_line_core_impl_True\n      file_output_option_def split: dres.splits option.splits)\n\ndefinition \"check_lines c1 ns = list_all (\\<lambda>i. \\<exists>s m n. check_line_lookup_out s m n c1 i) ns\"\n\nlemma check_linesI:\n  \"check_lines c1 ns\"\n  if \"parallel_check s m n c1 ns\"\n  using that\n  by (auto simp: parallel_check_def check_lines_def list_all_iff)\n\nsubsection \\<open>Automate generation of lemmas\\<close>\n\nlemma length_coarse_results[simp]: \"length coarse_results = 400\"\n  by (simp add: coarse_results_def)\n\nlemma correct_res_coarse_resultsI:\n  \"correct_res (results ! i) \\<Longrightarrow> i < 400 \\<Longrightarrow> correct_res (coarse_results ! i)\"\n  by (auto simp: results_def symmetrize_def nth_append)\n\nlemma Ball_coarseI: \"Ball (set coarse_results) correct_res\"\n  if NF \"check_lines True xs\" \"set xs = {..<400}\"\n  using that\n  by (force simp: check_lines_def list_all_iff in_set_conv_nth\n      intro!: correct_res_coarse_resultsI check_line_lookup_out)\n\nML \\<open>map_option (using_master_directory_term @{context}) (SOME \"a\")\\<close>\nML \\<open>\nfun mk_optionT ty = Type (@{type_name \"option\"}, [ty])\nfun mk_None ty = Const (@{const_name \"None\"}, mk_optionT ty)\nfun mk_Some ty x = Const (@{const_name \"Some\"}, ty --> mk_optionT ty) $ x\nfun mk_option ty _ NONE = mk_None ty\n  | mk_option ty f (SOME x) = mk_Some ty (f x)\nfun check_lines_tac' s m n ctxt =\n  resolve_tac ctxt\n    [Thm.instantiate ([],\n      [(\"s\", @{typ \"string option\"}, mk_option @{typ string} (using_master_directory_term ctxt) s),\n       (\"m\", @{typ nat}, HOLogic.mk_nat m),\n       (\"n\", @{typ nat}, HOLogic.mk_nat n)]\n        |> map (fn (s, ty, t) => (((s, 0), ty), Thm.cterm_of ctxt t)))\n      @{thm check_linesI}]\n  THEN' CONVERSION (check_line ctxt)\n  THEN' resolve_tac ctxt @{thms TrueI}\n\\<close>\n\nmethod_setup parallel_check = \\<open>\n  Scan.lift (Parse.maybe Parse.string) -- Scan.lift Parse.nat -- Scan.lift Parse.nat\n  >> (fn ((s, m), n) => fn ctxt => SIMPLE_METHOD' (check_lines_tac' s m n ctxt))\n\\<close>\n\nlemma lorenz_bounds_lemma_asym:\n  \"\\<forall>x \\<in> N - \\<Gamma>. x returns_to \\<Sigma>\"\n  \"R ` (N - \\<Gamma>) \\<subseteq> N\"\n  \"\\<forall>x \\<in> N - \\<Gamma>. (R has_derivative DR x) (at x within \\<Sigma>\\<^sub>l\\<^sub>e)\"\n  \"\\<forall>x \\<in> N - \\<Gamma>. DR x ` \\<CC> x \\<subseteq> \\<CC> (R x)\"\n  \"\\<forall>x \\<in> N - \\<Gamma>. \\<forall>c \\<in> \\<CC> x. norm (DR x c) \\<ge> \\<E> x      * norm c\"\n  \"\\<forall>x \\<in> N - \\<Gamma>. \\<forall>c \\<in> \\<CC> x. norm (DR x c) \\<ge> \\<E>\\<^sub>p (R x) * norm c\"\n  if NF \"Ball (set results) correct_res\"\n  using that\n  by (auto intro!: lorenz_bounds_lemma)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Ordinary_Differential_Equations/Ex/Lorenz/Lorenz_Approximation.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5621765008857982, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.29206267891059184}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntext \\<open>A simple proof method for rewriting Simpl programs under a predicate which\n      is preserved by semantic equivalence.\\<close>\n\ntheory Simpl_Rewrite\nimports\n  \"Simpl-VCG.Vcg\"\n  \"Lib.Eisbach_Methods\"\n  \"Lib.Apply_Debug\"\nbegin\n\ntext \\<open>Definitions and lemmas for reasoning about equivalence of Simpl programs.\\<close>\n\nnamed_theorems C_simp\nnamed_theorems C_simp_pre\nnamed_theorems C_simp_simps\nnamed_theorems C_simp_throws\n\nlocale simpl_rewrite_base =\n  fixes \\<Gamma> :: \"'p \\<Rightarrow> ('s,'p,'f) com option\"\nbegin\n\ntext \\<open>Semantic equivalence of two Simpl programs.\n\n      Since we quantify over all possible states, this is somewhat stronger than some other\n      notions of semantic equivalence. In particular, @{text ceqv} takes particular begin and\n      end states as arguments, and is only defined for @{term Normal} begin and end states.\\<close>\n\ndefinition\n  \"com_eq t c c' \\<equiv> t \\<longrightarrow> (\\<forall>s s'. \\<Gamma> \\<turnstile> \\<langle>c,s\\<rangle> \\<Rightarrow> s' \\<longleftrightarrow> \\<Gamma> \\<turnstile> \\<langle>c',s\\<rangle> \\<Rightarrow> s')\"\n\ntext \\<open>@{text com_eq} assertions may be guarded. Guards enable simple conditional rewriting.\\<close>\n\nlemma com_eq_weaken_guard:\n  \"com_eq t c c' \\<Longrightarrow> (t' \\<Longrightarrow> t) \\<Longrightarrow> com_eq t' c c'\"\n  by (simp add: com_eq_def)\n\nlemma com_eq_guard_False:\n  \"com_eq False c c'\"\n  by (simp add: com_eq_def)\n\ntext \\<open>Most @{text com_eq} simplification rules will be unguarded, however.\\<close>\n\nabbreviation\n  \"com_equiv \\<equiv> com_eq True\"\n\nnotation com_equiv (infix \"\\<sim>\" 10)\n\ntext \\<open>@{term \"com_eq\"} is an equivalence relation.\\<close>\n\nlemma com_eq_refl:\n  \"c \\<sim> c\"\n  by (auto simp: com_eq_def)\n\nlemma com_eq_sym:\n  \"c \\<sim> c' \\<Longrightarrow> c' \\<sim> c\"\n  by (auto simp: com_eq_def)\n\nlemma com_eq_trans:\n  \"\\<lbrakk> c \\<sim> c'; c' \\<sim> c'' \\<rbrakk> \\<Longrightarrow> c \\<sim> c''\"\n  by (auto simp add: com_eq_def)\n\ntext \\<open>Structural decomposition of Simpl programs under @{term \"com_eq\"}.\\<close>\n\nlemma com_eq_Seq:\n  \"\\<lbrakk> c1 \\<sim> c1'; c2 \\<sim> c2' \\<rbrakk> \\<Longrightarrow> c1;;c2 \\<sim> c1';;c2'\"\n  unfolding com_eq_def by (auto intro: exec.Seq elim!: exec_elim_cases)\n\nlemma com_eq_Cond:\n  \"\\<lbrakk> c1 \\<sim> c1'; c2 \\<sim> c2' \\<rbrakk> \\<Longrightarrow> Cond b c1 c2 \\<sim> Cond b c1' c2'\"\n  unfolding com_eq_def by (auto intro: exec.CondTrue exec.CondFalse elim!: exec_elim_cases)\n\nlemma com_eq_While':\n  assumes eq: \"c \\<sim> c'\"\n  assumes W: \"\\<Gamma> \\<turnstile> \\<langle>While b c,s\\<rangle> \\<Rightarrow> s'\"\n  shows \"\\<Gamma> \\<turnstile> \\<langle>While b c',s\\<rangle> \\<Rightarrow> s'\"\n  using W\n  proof (induct \"While b c\" s s')\n    case WhileTrue\n    with eq show ?case unfolding com_eq_def by (auto elim: exec.WhileTrue)\n  next\n    case WhileFalse\n    then show ?case by (rule exec.WhileFalse)\n  qed auto\n\nlemma com_eq_While:\n  \"c \\<sim> c' \\<Longrightarrow> While b c \\<sim> While b c'\"\n  by (subst com_eq_def) (auto intro: com_eq_While' com_eq_While' [OF com_eq_sym])\n\nlemma com_eq_whileAnno:\n  \"c \\<sim> c' \\<Longrightarrow> whileAnno b I V c \\<sim> whileAnno b I V c'\"\n  by (clarsimp simp: whileAnno_def elim!: com_eq_While)\n\nlemma com_eq_Guard:\n  \"c \\<sim> c' \\<Longrightarrow> Guard f b c \\<sim> Guard f b c'\"\n  by (auto simp: com_eq_def intro: exec.Guard exec.GuardFault elim!: exec_elim_cases)\n\nlemma com_eq_Catch:\n  \"\\<lbrakk> c \\<sim> c'; h \\<sim> h' \\<rbrakk> \\<Longrightarrow> Catch c h \\<sim> Catch c' h'\"\n  by (auto simp: com_eq_def intro: exec.CatchMiss exec.CatchMatch elim!: exec_elim_cases)\n\nlemmas com_eq_intros =\n  com_eq_Seq com_eq_Cond com_eq_While com_eq_whileAnno com_eq_Guard com_eq_Catch\n\ntext \\<open>Simpl @{term Seq} is associative under @{term com_eq}.\\<close>\n\nlemma com_eq_Seq_assoc_l:\n  \"c1;;(c2;;c3) \\<sim> (c1;;c2);;c3\"\n  by (clarsimp simp: com_eq_def exec_assoc)\n\nlemma com_eq_Seq_assoc_r:\n  \"(c1;;c2);;c3 \\<sim> c1;;(c2;;c3)\"\n  by (clarsimp simp: com_eq_def exec_assoc)\n\ntext \\<open>Under @{term com_eq}, some Simpl elements are right-distributive w.r.t. @{term Seq}.\\<close>\n\nlemma com_eq_Cond_distrib_r:\n  \"Cond b (c1;;c) (c2;;c) \\<sim> Cond b c1 c2 ;; c\"\n  by (auto simp: com_eq_def\n          intro: exec.Seq exec.CondTrue exec.CondFalse\n          elim!: exec_elim_cases)\n\nlemma com_eq_Guard_distrib_r:\n  \"Guard f b (c1;;c2) \\<sim> Guard f b c1 ;; c2\"\n  by (auto simp: com_eq_def\n          intro: exec.Seq exec.Guard exec.GuardFault\n          elim!: exec_elim_cases)\n\ntext \\<open>Simplification rules should be of the form @{term \"com_eq t c c'\"}.\n\n      Simplifications added to the @{thm C_simp_pre} set will be performed before\n      sub-programs have been simplified. Those added to the @{thm C_simp} set\n      will be performed after sub-programs have been simplified.\n\n      Conditional simplification rules will only apply if the guard @{term t} can be\n      immediately solved by @{method simp}.\\<close>\n\nlemma com_eq_Skip_Seq [C_simp]:\n  \"Skip;;c \\<sim> c\"\n  apply (clarsimp simp: com_eq_def)\n  apply (rule iffI)\n   apply (fastforce elim!: exec_elim_cases)\n  apply (case_tac s; (simp, (erule exec_elim_cases; simp)?))\n  apply (rule exec.Seq, rule exec.Skip, simp)\n  done\n\nlemma com_eq_Seq_Skip [C_simp]:\n  \"c;;Skip \\<sim> c\"\n  apply (clarsimp simp: com_eq_def)\n  apply (rule iffI)\n   apply (fastforce elim!: exec_elim_cases)\n  apply (case_tac s; (simp, (erule exec_elim_cases; simp)?))\n  apply (rule exec.Seq, simp)\n  apply (case_tac s'; (simp, (erule exec_elim_cases; simp)?))\n  apply (rule exec.Skip)\n  done\n\nlemma com_eq_Cond_empty [C_simp_pre]:\n  \"com_eq (b = {}) (Cond b c1 c2) c2\"\n  by (clarsimp simp: com_eq_def, case_tac s, auto intro: exec.CondFalse elim!: exec_elim_cases)\n\nlemma com_eq_Cond_UNIV [C_simp_pre]:\n  \"com_eq (b = UNIV) (Cond b c1 c2) c1\"\n  by (clarsimp simp: com_eq_def, case_tac s, auto intro: exec.CondTrue  elim!: exec_elim_cases)\n\nlemma exec_Cond_cases:\n  \"\\<lbrakk>s \\<in> b \\<Longrightarrow> \\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t; s \\<notin> b \\<Longrightarrow> \\<Gamma>\\<turnstile> \\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow> t\\<rbrakk> \\<Longrightarrow>\n  \\<Gamma>\\<turnstile> \\<langle>Cond b c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow> t\"\n  by (cases \"s \\<in> b\") (auto intro: exec.CondTrue exec.CondFalse)\n\nlemma com_eq_Cond_both [C_simp]:\n  \"Cond b c c \\<sim> c\"\n  by (clarsimp simp: com_eq_def, case_tac s, auto intro: exec_Cond_cases elim!: exec_elim_cases)\n\nlemma com_eq_While_empty [C_simp_pre]:\n  \"com_eq (b = {}) (While b c) Skip\"\n  by (auto simp: com_eq_def intro: exec.WhileFalse exec.Skip elim!: exec_elim_cases)\n\nlemma com_eq_whileAnno_empty [C_simp_pre]:\n  \"com_eq (b = {}) (whileAnno b I V c) Skip\"\n  by (simp add: com_eq_While_empty whileAnno_def)\n\nlemma com_eq_Guard_UNIV [C_simp_pre]:\n  \"com_eq (b = UNIV) (Guard f b c) c\"\n  by (clarsimp simp: com_eq_def, case_tac s, auto intro: exec.Guard elim!: exec_elim_cases)\n\nlemma com_eq_Guard_empty [C_simp_pre]:\n  \"com_eq (c \\<noteq> Skip \\<and> b = {}) (Guard f b c) (Guard f {} Skip)\"\n  by (clarsimp simp: com_eq_def, case_tac s, auto intro: exec.GuardFault elim!: exec_elim_cases)\n\nlemma com_eq_Catch_Skip [C_simp]:\n  \"Catch Skip c \\<sim> Skip\"\n  by (auto simp: com_eq_def intro: exec.CatchMiss exec.Skip elim!: exec_elim_cases)\n\nlemma com_eq_Catch_Throw [C_simp]:\n  \"Catch Throw c \\<sim> c\"\n  by (clarsimp simp: com_eq_def, case_tac s)\n     (auto intro: exec.CatchMatch exec.Throw elim!: exec_elim_cases)\n\ntext \\<open>An assertion expressing that a Simpl program never finishes normally.\\<close>\n\ndefinition\n  \"never_continues t c \\<equiv> t \\<longrightarrow> (\\<forall>s s'. \\<not> \\<Gamma> \\<turnstile> \\<langle>c, Normal s\\<rangle> \\<Rightarrow> Normal s')\"\n\ntext \\<open>Commands sequenced after a command that @{term never_continues} may be ignored.\\<close>\n\nlemma never_continues_def2:\n  \"never_continues t c \\<equiv> t \\<longrightarrow> (\\<forall>r. (c;;r) \\<sim> c)\"\n  unfolding atomize_eq never_continues_def com_eq_def\n  apply (rule iffI; erule (1) imp_forward; clarsimp)\n   apply (rule iffI)\n    apply (erule exec_elim_cases; clarsimp)\n    apply (match premises in \"\\<Gamma> \\<turnstile> \\<langle>c, Normal _\\<rangle> \\<Rightarrow> s'\" for s' \\<Rightarrow> \\<open>cases s'\\<close>;\n           clarsimp elim!: exec_elim_cases)\n   apply (match premises in \"\\<Gamma> \\<turnstile> \\<langle>c, s\\<rangle> \\<Rightarrow> s'\" for s s' \\<Rightarrow> \\<open>cases s; cases s'\\<close>;\n          clarsimp elim!: exec_elim_cases exec.Seq)\n  by (fastforce dest!: spec[of _ Throw] elim!: exec_elim_cases)\n\ntext \\<open>Rules for rewriting the arguments of @{term never_continues}.\\<close>\n\nlemma never_continues_weaken_guard:\n  \"never_continues t c \\<Longrightarrow> (t' \\<Longrightarrow> t) \\<Longrightarrow> never_continues t' c\"\n  by (simp add: never_continues_def)\n\nlemma never_continues_rewrite_com_eq:\n  \"c \\<sim> c' \\<Longrightarrow> never_continues t c \\<Longrightarrow> never_continues t c'\"\n  apply (simp add: never_continues_def2)\n  apply (elim imp_forward all_forward, assumption)\n  apply (rule com_eq_trans, rule com_eq_Seq, erule com_eq_sym, rule com_eq_refl)\n  by (erule com_eq_trans[rotated])\n\ntext \\<open>Rules of the form @{term \"never_continues True c\"} may be added to @{text C_simp_throws}.\\<close>\n\nlemma never_continues_Throw [C_simp_throws]:\n  \"never_continues True Throw\"\n  by (auto simp: never_continues_def elim: exec_elim_cases)\n\nlemma While_UNIV_helper:\n  \"\\<Gamma> \\<turnstile> \\<langle>c',s\\<rangle> \\<Rightarrow> s'' \\<Longrightarrow> c' = While UNIV c \\<Longrightarrow> s'' = Normal s' \\<Longrightarrow> False\"\n  by (induct rule: exec.induct) auto\n\nlemma never_continues_While_UNIV [C_simp_throws]:\n  \"never_continues True (While UNIV c)\"\n  by (auto simp: never_continues_def elim: While_UNIV_helper)\n\nlemma never_continues_While_True [C_simp_throws]:\n  \"never_continues True (WHILE True DO c OD)\"\n  by (simp add: whileAnno_def never_continues_While_UNIV)\n\nlemma never_continues_Guard_False [C_simp_throws]:\n  \"never_continues True (Guard f {} c)\"\n  by (auto simp: never_continues_def elim: exec_elim_cases)\n\ntext \\<open>Structural decomposition of Simpl programs under @{term never_continues}.\\<close>\n\nlemma never_continues_Seq1:\n  \"never_continues t c1 \\<Longrightarrow> never_continues t (c1;;c2)\"\n  apply (clarsimp simp: never_continues_def2)\n  apply (frule spec[of _ c2], erule com_eq_trans[rotated, OF com_eq_sym])\n  apply (rule com_eq_trans[OF com_eq_Seq_assoc_r])\n  by simp\n\nlemma never_continues_Seq2:\n  \"never_continues t c2 \\<Longrightarrow> never_continues t (c1;;c2)\"\n  apply (clarsimp simp: never_continues_def2)\n  apply (rule com_eq_trans[OF com_eq_Seq_assoc_r])\n  apply (rule com_eq_Seq[OF com_eq_refl])\n  by simp\n\nlemmas never_continues_Seqs =\n  never_continues_Seq1 never_continues_Seq2\n\nlemma never_continues_Cond:\n  \"never_continues t1 c1 \\<Longrightarrow> never_continues t2 c2 \\<Longrightarrow> never_continues (t1 \\<and> t2) (Cond b c1 c2)\"\n  by (auto simp: never_continues_def elim: exec_elim_cases)\n\nlemma never_continues_Guard:\n  \"never_continues t c \\<Longrightarrow> never_continues t (Guard f b c)\"\n  by (auto simp: never_continues_def elim: exec_elim_cases)\n\nlemma never_continues_Catch:\n  \"never_continues tc c \\<Longrightarrow> never_continues th h \\<Longrightarrow> never_continues (tc \\<and> th) (Catch c h)\"\n  by (auto simp: never_continues_def elim: exec_elim_cases)\n\ntext \\<open>If all else fails...\\<close>\n\nlemma never_continues_False:\n  \"never_continues False c\"\n  by (simp add: never_continues_def)\n\nend\n\ntext \\<open>One layer of context around a Simpl program.\n\n      For example, if the current focus is the first branch of a @{term Cond},\n      then the context consists of a constructor @{text CondTC} which indicates\n      this is the context, and carries everything but but the focused branch,\n      i.e. the condition and the second branch.\n\n      The @{text CondFC} and @{text HandlerC} cases each carry an extra bit of\n      information, which indicates whether the left-hand branch @{text never_continues}.\n      The assumption here is that we always traverse Simpl programs left-to-right.\n      @{text Seq2C} does not require an extra bit, because we never enter the second\n      command of a @{term Seq} if the first command @{text never_continues}.\\<close>\n\ndatatype ('s,'p,'f) com_ctxt\n  = Seq1C \"('s,'p,'f) com\" \\<comment> \\<open>first command of a @{term Seq}\\<close>\n  | Seq2C \"('s,'p,'f) com\" \\<comment> \\<open>second command of a @{term Seq}\\<close>\n  | CondTC \"'s bexp\" \"('s,'p,'f) com\" \\<comment> \\<open>first branch of a @{term Cond}\\<close>\n  | CondFC \"'s bexp\" \"('s,'p,'f) com\" bool \\<comment> \\<open>second branch of a @{term Cond}\\<close>\n  | WhileC \"'s bexp\" \\<comment> \\<open>body of a @{term While}\\<close>\n  | WhileAnnoC \"'s bexp\" \"'s assn\" \"('s \\<times> 's) assn\" \\<comment> \\<open>body of a @{term whileAnno}\\<close>\n  | GuardC \"'f\" \"'s bexp\" \\<comment> \\<open>body of a @{term Guard}\\<close>\n  | TryC \"('s,'p,'f) com\" \\<comment> \\<open>body of a @{term Catch}\\<close>\n  | HandlerC \"('s,'p,'f) com\" bool \\<comment> \\<open>handler of a @{term Catch}\\<close>\n\ntext \\<open>Rewrite Simpl programs under a predicate @{term P} which is preserved by @{term com_eq}.\\<close>\n\nlocale simpl_rewrite = simpl_rewrite_base \\<Gamma>\n  for \\<Gamma> :: \"'p \\<Rightarrow> ('s,'p,'f) com option\" +\n  fixes P :: \"('s,'p,'f) com \\<Rightarrow> bool\"\n  assumes inv: \"\\<And>c c'. c \\<sim> c' \\<Longrightarrow> P c' \\<Longrightarrow> P c\"\nbegin\n\ntext \\<open>Calculate @{term P} for a Simpl program consisting of a sub-program in a nest of contexts.\\<close>\n\nfun\n  ctxt_P :: \"('s,'p,'f) com \\<Rightarrow> ('s,'p,'f) com_ctxt list \\<Rightarrow> bool\"\nwhere\n    \"ctxt_P c [] = P c\"\n  | \"ctxt_P c (Seq1C c' # cs) = ctxt_P (Seq c c') cs\"\n  | \"ctxt_P c (Seq2C c' # cs) = ctxt_P (Seq c' c) cs\"\n  | \"ctxt_P c (CondTC b c' # cs) = ctxt_P (Cond b c c') cs\"\n  | \"ctxt_P c (CondFC b c' t # cs) = (never_continues t c' \\<longrightarrow> ctxt_P (Cond b c' c) cs)\"\n  | \"ctxt_P c (WhileC b # cs) = ctxt_P (While b c) cs\"\n  | \"ctxt_P c (WhileAnnoC b I V # cs) = ctxt_P (whileAnno b I V c) cs\"\n  | \"ctxt_P c (GuardC f b # cs) = ctxt_P (Guard f b c) cs\"\n  | \"ctxt_P c (TryC c' # cs) = ctxt_P (Catch c c') cs\"\n  | \"ctxt_P c (HandlerC c' t # cs) = (never_continues t c' \\<longrightarrow> ctxt_P (Catch c' c) cs)\"\n\ntext \\<open>For the current focus, we add a flag @{term t} of type @{typ \"bool option\"}.\n      @{term t} is None until we have finished rewriting sub-programs.\n      It is @{term \"Some t\"} when rewriting has finished for the current focus, and\n      the result satisfies @{term \"never_continues t\"}.\\<close>\n\ndefinition\n  \"nc_opt t \\<equiv> never_continues (case_option False id t)\"\n\ndefinition\n  \"focus c t cs \\<equiv> nc_opt t c \\<longrightarrow> ctxt_P c cs\"\n\nlemmas focus_defs = focus_def nc_opt_def\n\nlemma nc_opt_None:\n  \"nc_opt None t\"\n  by (simp add: nc_opt_def never_continues_False)\n\ntext \\<open>Rules for beginning and ending the rewriting process.\\<close>\n\nlemma enter_focus:\n  \"focus c None [] \\<Longrightarrow> P c\"\n  by (simp add: focus_defs never_continues_False)\n\nlemma exit_focus:\n  \"P c \\<Longrightarrow> focus c t []\"\n  by (simp add: focus_defs)\n\ntext \\<open>Rules for rewriting at the current focus.\\<close>\n\nlemma nc_opt_rewrite_com_eq:\n  \"c \\<sim> c' \\<Longrightarrow> nc_opt t c \\<Longrightarrow> nc_opt t c'\"\n  by (simp add: nc_opt_def never_continues_rewrite_com_eq)\n\nlemma ctxt_P_rewrite_com_eq:\n  \"c \\<sim> c' \\<Longrightarrow> ctxt_P c' cs \\<Longrightarrow> ctxt_P c cs\"\n  proof (induct cs arbitrary: c c')\n    case Nil thus ?case by (simp add: inv)\n  next\n    case (Cons c'' cs) show ?case using Cons.prems(2)\n      by (cases c''; clarsimp elim!: Cons.hyps[rotated];\n          intro com_eq_intros com_eq_refl Cons.prems(1))\n  qed\n\nlemma rewrite_focus:\n  \"com_eq p c c' \\<Longrightarrow> p \\<Longrightarrow> focus c' t cs \\<Longrightarrow> focus c t cs\"\n  by (simp add: focus_def nc_opt_rewrite_com_eq ctxt_P_rewrite_com_eq)\n\ntext \\<open>Rules to set the @{term never_continues} flag for the current focus.\\<close>\n\nlemma focus_set_never_continues:\n  \"never_continues t c \\<Longrightarrow> focus c (Some t) cs \\<Longrightarrow> focus c None cs\"\n  by (simp add: focus_defs)\n\nlemma focus_update_never_continues:\n  \"never_continues t c \\<Longrightarrow> focus c (Some (t \\<or> t')) cs \\<Longrightarrow> focus c (Some t') cs\"\n  by (cases t; cases t'; simp add: focus_defs)\n\nlemmas focus_never_continues =\n  focus_update_never_continues[where t'=True, simplified]\n  focus_update_never_continues[where t'=False, simplified]\n  focus_set_never_continues\n\ntext \\<open>Rules for moving the focus down the left spine.\\<close>\n\nlemma focus_left:\n  \"focus c None (Seq1C c' # cs) \\<Longrightarrow> focus (Seq c c') None cs\"\n  \"focus c None (CondTC b c' # cs) \\<Longrightarrow> focus (Cond b c c') None cs\"\n  \"focus c None (WhileC b # cs) \\<Longrightarrow> focus (While b c) None cs\"\n  \"focus c None (WhileAnnoC b I V # cs) \\<Longrightarrow> focus (whileAnno b I V c) None cs\"\n  \"focus c None (GuardC f b # cs) \\<Longrightarrow> focus (Guard f b c) None cs\"\n  \"focus c None (TryC c' # cs) \\<Longrightarrow> focus (Catch c c') None cs\"\n  by (auto simp: focus_def nc_opt_None)\n\ntext \\<open>Rules for moving the focus to the right sibling.\\<close>\n\nlemma focus_right:\n  \"focus c' None (Seq2C c # cs) \\<Longrightarrow> focus c (Some False) (Seq1C c' # cs)\"\n  \"focus c' None (CondFC b c t # cs) \\<Longrightarrow> focus c (Some t) (CondTC b c' # cs)\"\n  \"focus c' None (HandlerC c t # cs) \\<Longrightarrow> focus c (Some t) (TryC c' # cs)\"\n  by (auto simp: focus_defs never_continues_False)\n\ntext \\<open>Rules for moving the focus up to the parent.\\<close>\n\nlemma ctxt_P_Seq1:\n  \"never_continues True c \\<Longrightarrow> ctxt_P c cs \\<Longrightarrow> ctxt_P (Seq c c') cs\"\n  by (auto simp: never_continues_def2 elim: ctxt_P_rewrite_com_eq)\n\nlemma unfocus_simple:\n  \"focus c (Some True) cs \\<Longrightarrow> focus c (Some True) (Seq1C c' # cs)\"\n  \"focus (Seq c' c) (Some t) cs \\<Longrightarrow> focus c (Some t) (Seq2C c' # cs)\"\n  \"focus (While b c) (Some False) cs \\<Longrightarrow> focus c (Some t) (WhileC b # cs)\"\n  \"focus (whileAnno b I V c) (Some False) cs \\<Longrightarrow> focus c (Some t) (WhileAnnoC b I V # cs)\"\n  \"focus (Guard f b c) (Some t) cs \\<Longrightarrow> focus c (Some t) (GuardC f b # cs)\"\n  by (auto simp: focus_defs never_continues_False ctxt_P_Seq1 never_continues_Seq2 never_continues_Guard)\n\nlemma unfocus_complex:\n  \"focus (Cond b c' c) (Some (t' \\<and> t)) cs \\<Longrightarrow> focus c (Some t) (CondFC b c' t' # cs)\"\n  \"focus (Catch c' c) (Some (t' \\<and> t)) cs \\<Longrightarrow> focus c (Some t) (HandlerC c' t' # cs)\"\n  by (auto simp: focus_defs never_continues_False never_continues_Cond never_continues_Catch)\n\nlemmas unfocus =\n  unfocus_complex[where t=True and t'=True, simplified]\n  unfocus_complex[where t=False, simplified]\n  unfocus_complex[where t'=False, simplified]\n  unfocus_simple\n\ntext \\<open>Methods to automate rewriting.\\<close>\n\nmethod do_rewrite uses ruleset declares C_simp_simps =\n  (rule rewrite_focus, rule ruleset,\n   #break \"simpl_rewrite_rewrite\", (simp add: C_simp_simps; fail))+\n\nmethod rewrite_pre declares C_simp_pre C_simp_simps =\n  (do_rewrite ruleset: C_simp_pre)\n\nmethod rewrite_post declares C_simp C_simp_simps =\n  (do_rewrite ruleset: C_simp)\n\nmethod never_continues declares C_simp_throws =\n  (rule focus_never_continues, rule C_simp_throws never_continues_False)\n\nmethod children methods do_focus declares C_simp C_simp_pre C_simp_simps C_simp_throws =\n  (rule focus_left, do_focus, (rule focus_right, do_focus)?, rule unfocus)?\n\nmethod do_focus declares C_simp C_simp_pre C_simp_simps C_simp_throws =\n  (#break \"simpl_rewrite_step\", rewrite_pre?, children \\<open>do_focus\\<close>,\n   #break \"simpl_rewrite_step\", rewrite_post?, never_continues)\n\nmethod simpl_rewrite declares C_simp C_simp_pre C_simp_simps C_simp_throws =\n  changed \\<open>rule enter_focus, do_focus, rule exit_focus\\<close>\n\ntext \\<open>Tests\\<close>\n\nlemma\n  assumes c3: \"c3 \\<sim> c\"\n  assumes c: \"(c;;c) \\<sim> c\"\n  shows \"P (c;; Guard f UNIV (IF X THEN c ELSE c FI);; Cond {} Skip (Skip;;c2);; Skip;;\n            (IF False THEN Skip ELSE SKIP;; TRY THROW CATCH c3 END FI;; SKIP))\"\n  apply simpl_rewrite\n  apply (match conclusion in \"P (c;;c;;c2;;c3)\" \\<Rightarrow> \\<open>-\\<close>)\n  apply (simpl_rewrite C_simp: c3)\n  apply (match conclusion in \"P (c;;c;;c2;;c)\" \\<Rightarrow> \\<open>-\\<close>)\n  apply (simpl_rewrite C_simp: c)\n  apply (match conclusion in \"P (c;;c2;;c)\" \\<Rightarrow> \\<open>-\\<close>)\n  apply (fails \\<open>simpl_rewrite\\<close>)\n  oops\n\ntext \\<open>Test for @{text WHILE} (@{term whileAnno}) case.\\<close>\n\nlemma\n  \"P (WHILE b DO Guard f g c;; IF False THEN c2 FI OD;; SKIP)\"\n  apply simpl_rewrite\n  apply (match conclusion in \"P (WHILE b DO Guard f g c OD)\" \\<Rightarrow> \\<open>-\\<close>)\n  oops\n\ntext \\<open>Test that simplification works down all branches of the term.\\<close>\n\nlemma\n  \"P (IF b THEN\n        (SKIP ;; c) ;; (SKIP ;; IF True THEN SKIP ELSE c FI)\n      ELSE\n        (SKIP ;; SKIP) ;; (Guard f UNIV c ;; SKIP)\n      FI)\"\n  apply simpl_rewrite\n  apply (match conclusion in \"P c\" \\<Rightarrow> \\<open>-\\<close>)\n  oops\n\ntext \\<open>Test that complex simplification rules work.\\<close>\n\nlemma com_eq_Cond_redundant:\n  \"(IF b THEN c1 ELSE IF b THEN c2 ELSE c3 FI FI) \\<sim> (IF b THEN c1 ELSE c3 FI)\"\n  unfolding com_eq_def\n  by (auto intro: exec.CondTrue exec.CondFalse elim!: exec_elim_cases)\n\nlemma\n  \"P (SKIP ;;\n      IF b THEN\n        (SKIP ;; c1) ;; (SKIP ;; SKIP)\n      ELSE\n        IF b THEN\n          IF b1 THEN c2 ELSE c2 FI\n        ELSE\n          WHILE False DO c4 OD ;; (c3 ;; SKIP)\n        FI\n      FI)\"\n  apply (simpl_rewrite C_simp: com_eq_Cond_redundant)\n  apply (match conclusion in \"P (IF b THEN c1 ELSE c3 FI)\" \\<Rightarrow> \\<open>-\\<close>)\n  oops\n\ntext \\<open>Test False guard avoids looping.\\<close>\n\nlemma\n  \"P (SKIP ;; Guard f {} (IF b THEN c ELSE c FI) ;; SKIP)\"\n  apply simpl_rewrite\n  apply (match conclusion in \"P (Guard f {} SKIP)\" \\<Rightarrow> \\<open>-\\<close>)\n  oops\n\ntext \\<open>Test that everything after a deeply nested Throw is discarded.\\<close>\n\nlemma\n  \"P (c0;; (c1;; (c2;; (c3;; (c4;; Throw;; c5);; c6);; c7);; c8);; c9)\"\n  apply simpl_rewrite\n  apply (match conclusion in \"P (c0;; (c1;; (c2;; (c3;; (c4;; Throw)))))\" \\<Rightarrow> \\<open>-\\<close>)\n  oops\n\ntext \\<open>Test that rewriting can simplify conditions, also using assumptions in the context.\\<close>\n\nlemma\n  assumes \"\\<And>s. A s \\<Longrightarrow> C s\"\n  shows \"\\<forall>s. Q s = (A s \\<longrightarrow> B s \\<longrightarrow> C s) \\<Longrightarrow> P (Cond {s. \\<not> Q s} c1 c2)\"\n  apply (simpl_rewrite C_simp_simps: assms)\n  apply (match premises in \"\\<forall>s. Q s = (A s \\<longrightarrow> B s \\<longrightarrow> C s)\" \\<Rightarrow> \\<open>match conclusion in \"P c2\" \\<Rightarrow> \\<open>-\\<close>\\<close>)\n  oops\n\nend\n\nend\n", "meta": {"author": "NICTA", "repo": "l4v", "sha": "3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b", "save_path": "github-repos/isabelle/NICTA-l4v", "path": "github-repos/isabelle/NICTA-l4v/l4v-3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b/lib/clib/Simpl_Rewrite.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.519521321952093, "lm_q2_score": 0.5621765008857981, "lm_q1q2_score": 0.2920626789105918}}
{"text": "header {* \\isaheader{Relations between control dependences} *}\n\ntheory ControlDependenceRelations \n  imports WeakOrderDependence StandardControlDependence \nbegin\n\ncontext StrongPostdomination begin\n\nlemma standard_control_implies_weak_order: \n  assumes \"n controls\\<^sub>s n'\" shows \"n \\<longrightarrow>\\<^bsub>wod\\<^esub> n',(_Exit_)\"\nproof -\n  from `n controls\\<^sub>s n'` obtain as a a' as' where \"as = a#as'\"\n    and \"n' \\<notin> set(sourcenodes as)\" and \"n -as\\<rightarrow>* n'\"\n    and \"n' postdominates (targetnode a)\"\n    and \"valid_edge a'\" and \"sourcenode a' = n\"\n    and \"\\<not> n' postdominates (targetnode a')\" \n    by(auto simp:standard_control_dependence_def)\n  from `n -as\\<rightarrow>* n'` `as = a#as'` have \"sourcenode a = n\" by(auto elim:path.cases)\n  from `n -as\\<rightarrow>* n'` `as = a#as'` `n' \\<notin> set(sourcenodes as)` have \"n \\<noteq> n'\"\n    by(induct rule:path.induct,auto simp:sourcenodes_def)\n  from `n -as\\<rightarrow>* n'` `as = a#as'` have \"valid_edge a\"\n    by(auto elim:path.cases)\n  from `n controls\\<^sub>s n'` have \"n' \\<noteq> (_Exit_)\"\n    by(fastforce dest:Exit_not_standard_control_dependent)\n  from `n -as\\<rightarrow>* n'` have \"(_Exit_) \\<notin> set (sourcenodes as)\" by fastforce\n  from `n -as\\<rightarrow>* n'` have \"valid_node n\" and \"valid_node n'\"\n    by(auto dest:path_valid_node)\n  with `\\<not> n' postdominates (targetnode a')` `valid_edge a'`\n  obtain asx where \"targetnode a' -asx\\<rightarrow>* (_Exit_)\" and \"n' \\<notin> set(sourcenodes asx)\"\n    by(auto simp:postdominate_def)\n  with `valid_edge a'` `sourcenode a' = n` have \"n -a'#asx\\<rightarrow>* (_Exit_)\"\n    by(fastforce intro:Cons_path)\n  with `n \\<noteq> n'` `sourcenode a' = n` `n' \\<notin> set(sourcenodes asx)`\n  have \"n' \\<notin> set(sourcenodes (a'#asx))\" by(simp add:sourcenodes_def)\n  from `n' postdominates (targetnode a)` \n  obtain asx' where \"targetnode a -asx'\\<rightarrow>* n'\" by(erule postdominate_implies_path)\n  from `n' postdominates (targetnode a)`\n  have \"\\<forall>as'. targetnode a -as'\\<rightarrow>* (_Exit_) \\<longrightarrow> n' \\<in> set(sourcenodes as')\"\n    by(auto simp:postdominate_def)\n  with `n' \\<noteq> (_Exit_)` `n -as\\<rightarrow>* n'` `(_Exit_) \\<notin> set (sourcenodes as)`\n    `n -a'#asx\\<rightarrow>* (_Exit_)` `n' \\<notin> set(sourcenodes (a'#asx))`\n    `valid_edge a` `sourcenode a = n` `targetnode a -asx'\\<rightarrow>* n'`\n  show ?thesis by(auto simp:wod_def)\nqed\n\nend\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Slicing/StaticIntra/ControlDependenceRelations.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6334102636778401, "lm_q2_score": 0.46101677931231594, "lm_q1q2_score": 0.29201275974412266}}
{"text": "(*\n * Copyright 2023, Proofcraft Pty Ltd\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: GPL-2.0-only\n *)\n\ntheory Example_Valid_State\nimports\n  \"ArchNoninterference\"\n  \"Lib.Distinct_Cmd\"\n  \"AInvs.KernelInit_AI\"\nbegin\n\nsection \\<open>Example\\<close>\n\n(* This example is a classic 'one way information flow'\n   example, where information is allowed to flow from Low to High,\n   but not the reverse. We consider a typical scenario where\n   shared memory and an notification for notifications are used to\n   implement a ring-buffer. We consider the NTFN to be in the domain of High,\n   and the shared memory to be in the domain of Low. *)\n\n(* basic machine-level declarations that need to happen outside the locale *)\n\nconsts s0_context :: user_context\n\n(* define the irqs to come regularly every 10 *)\n\naxiomatization where\n  irq_oracle_def: \"RISCV64.irq_oracle \\<equiv> \\<lambda>pos. if pos mod 10 = 0 then 10 else 0\"\n\ncontext begin interpretation Arch . (*FIXME: arch_split*)\n\nsubsection \\<open>We show that the authority graph does not let information flow from High to Low\\<close>\n\ndatatype auth_graph_label = High | Low | IRQ0\n\nabbreviation partition_label where\n  \"partition_label x \\<equiv> OrdinaryLabel x\"\n\ndefinition Sys1AuthGraph :: \"(auth_graph_label subject_label) auth_graph\" where\n  \"Sys1AuthGraph \\<equiv>\n     {(partition_label High, Read, partition_label Low),\n      (partition_label Low, Notify, partition_label High),\n      (partition_label Low, Reset, partition_label High),\n      (SilcLabel, Read, partition_label Low),\n      (SilcLabel, Notify, partition_label High),\n      (SilcLabel, Reset, partition_label High)}\n   \\<union> {(x, a, y). x = y}\"\n\nlemma subjectReads_Low:\n  \"subjectReads Sys1AuthGraph (partition_label Low) = {partition_label Low}\"\n  apply (rule equalityI)\n   apply (rule subsetI)\n   apply (erule subjectReads.induct, (fastforce simp: Sys1AuthGraph_def)+)\n  done\n\nlemma Low_in_subjectReads_High:\n  \"partition_label Low \\<in> subjectReads Sys1AuthGraph (partition_label High)\"\n  by (simp add: Sys1AuthGraph_def reads_read)\n\nlemma subjectReads_High:\n  \"subjectReads Sys1AuthGraph (partition_label High) = {partition_label High, partition_label Low}\"\n  apply (rule equalityI)\n   apply (rule subsetI)\n   apply (erule subjectReads.induct, (fastforce simp: Sys1AuthGraph_def)+)\n  apply (auto intro: Low_in_subjectReads_High)\n  done\n\nlemma subjectReads_IRQ0:\n  \"subjectReads Sys1AuthGraph (partition_label IRQ0) = {partition_label IRQ0}\"\n  apply (rule equalityI)\n   apply (rule subsetI)\n   apply (erule subjectReads.induct, (fastforce simp: Sys1AuthGraph_def)+)\n  done\n\nlemma High_in_subjectAffects_Low:\n  \"partition_label High \\<in> subjectAffects Sys1AuthGraph (partition_label Low)\"\n  apply (rule affects_ep)\n   apply (simp add: Sys1AuthGraph_def)\n   apply (rule disjI1, simp+)\n  done\n\nlemma subjectAffects_Low:\n  \"subjectAffects Sys1AuthGraph (partition_label Low) = {partition_label Low, partition_label High}\"\n  apply (rule equalityI)\n   apply (rule subsetI)\n   apply (erule subjectAffects.induct, (fastforce simp: Sys1AuthGraph_def)+)\n  apply (auto intro: affects_lrefl High_in_subjectAffects_Low)\n  done\n\nlemma subjectAffects_High:\n  \"subjectAffects Sys1AuthGraph (partition_label High) = {partition_label High}\"\n  apply (rule equalityI)\n   apply (rule subsetI)\n   apply (erule subjectAffects.induct, (fastforce simp: Sys1AuthGraph_def)+)\n  apply (auto intro: affects_lrefl)\n  done\n\nlemma subjectAffects_IRQ0:\n \"subjectAffects Sys1AuthGraph (partition_label IRQ0) = {partition_label IRQ0}\"\n  apply (rule equalityI)\n   apply (rule subsetI)\n   apply (erule subjectAffects.induct, (fastforce simp: Sys1AuthGraph_def)+)\n  apply (auto intro: affects_lrefl)\n  done\n\nlemmas subjectReads = subjectReads_High subjectReads_Low subjectReads_IRQ0\n\nlemma partsSubjectAffects_Low:\n  \"partsSubjectAffects Sys1AuthGraph Low = {Partition Low, Partition High}\"\n  by (auto simp: partsSubjectAffects_def image_def label_can_affect_partition_def\n                 subjectReads subjectAffects_Low | case_tac xa, rename_tac xa)+\n\nlemma partsSubjectAffects_High:\n  \"partsSubjectAffects Sys1AuthGraph High = {Partition High}\"\n  by (auto simp: partsSubjectAffects_def image_def label_can_affect_partition_def\n                 subjectReads subjectAffects_High | rename_tac xa, case_tac xa)+\n\nlemma partsSubjectAffects_IRQ0:\n  \"partsSubjectAffects Sys1AuthGraph IRQ0 = {Partition IRQ0}\"\n  by (auto simp: partsSubjectAffects_def image_def label_can_affect_partition_def\n                 subjectReads subjectAffects_IRQ0 | rename_tac xa, case_tac xa)+\n\nlemmas partsSubjectAffects =\n   partsSubjectAffects_High partsSubjectAffects_Low partsSubjectAffects_IRQ0\n\ndefinition example_policy where\n  \"example_policy \\<equiv>\n     {(PSched, d) | d. True} \\<union> {(d,e). d = e} \\<union> {(Partition Low, Partition High)}\"\n\nlemma \"policyFlows Sys1AuthGraph = example_policy\"\n  apply (rule equalityI)\n   apply (rule subsetI)\n   apply (clarsimp simp: example_policy_def)\n   apply (erule policyFlows.cases)\n    apply (case_tac l, auto simp: partsSubjectAffects)[1]\n   apply assumption\n  apply (rule subsetI)\n  apply (clarsimp simp: example_policy_def)\n  apply (elim disjE)\n    apply (fastforce simp: partsSubjectAffects intro: policy_affects)\n   apply (fastforce intro: policy_scheduler)\n  apply (fastforce intro: policyFlows_refl refl_onD)\n  done\n\n\nsubsection \\<open>We show there exists a valid initial state associated to the\n              above authority graph\\<close>\n\ntext \\<open>\n\nThis example (modified from ../access-control/ExampleSystem) is a system Sys1 made\nof 2 main components Low and High, connected through an notification NTFN.\nBoth Low and High contains:\n\n  . one TCB\n  . one vspace made up of one top-level page table\n  - one asid pool with a single entry for the corresponding vspace\n  . each top-level pt contains a single page table, with access to a shared page in memory\n     Low can read/write to this page, High can only read\n  . one cspace made up of one cnode\n  . each cspace contains 4 caps:\n         one to the tcb\n         one to the cnode itself\n         one to the top level page table\n         one to the asid pool\n         one to the shared page\n         one to the second level page table\n         one to the ntfn\n\nLow can send to the ntfn while High can receive from it.\n\nAttempt to ASCII art:\n\n          --------    ----                    ----   --------\n          |       |   |  |                    |  |   |      |\n          V       |   |  V    S         R     |  V   |      V\nLow_tcb(3079)-->Low_cnode(6)--->ntfn(9)<---High_cnode(7)<--High_tcb(3080)\n  |              |                               |          |\n  V              |                               |          V\nLow_pd(3063)<---------Low_pool      High_pool------------> High_pd(3065)\n  |                                                         |\n  V               R/W                           R           V\nLow_pt(3072)---------------->shared_page<-----------------High_pt(3077)\n\n\n(the references are derived from the dump of the SAC system)\n\n\nThe aim is to be able to prove\n\n  valid_initial_state s0_internal Sys1PAS timer_irq utf\n\nwhere Sys1PAS is the label graph defining the AC policy for Sys1 using\nthe authority graph defined above and s0 is the state of Sys1 described above.\n\n\\<close>\n\nsubsubsection \\<open>Defining the State\\<close>\n\ndefinition \"ntfn_ptr \\<equiv> pptr_base + 0x20\"\n\ndefinition \"Low_tcb_ptr \\<equiv> pptr_base + 0x400\"\ndefinition \"High_tcb_ptr = pptr_base + 0x800\"\ndefinition \"idle_tcb_ptr = pptr_base + 0x1000\"\n\ndefinition \"Low_pt_ptr = pptr_base + 0x4000\"\ndefinition \"High_pt_ptr = pptr_base + 0x5000\"\n\ndefinition \"Low_pd_ptr = pptr_base + 0x7000\"\ndefinition \"High_pd_ptr = pptr_base + 0x8000\"\n\ndefinition \"Low_pool_ptr = pptr_base + 0x9000\"\ndefinition \"High_pool_ptr = pptr_base + 0xA000\"\n\ndefinition \"Low_cnode_ptr = pptr_base + 0x10000\"\ndefinition \"High_cnode_ptr = pptr_base + 0x18000\"\ndefinition \"Silc_cnode_ptr = pptr_base + 0x20000\"\ndefinition \"irq_cnode_ptr = pptr_base + 0x28000\"\n\ndefinition \"shared_page_ptr_virt = pptr_base + 0x200000\"\ndefinition \"shared_page_ptr_phys = addrFromPPtr shared_page_ptr_virt\"\n\ndefinition \"timer_irq \\<equiv> 10\" (* not sure exactly how this fits in *)\n\ndefinition \"Low_mcp \\<equiv> 5 :: priority\"\ndefinition \"Low_prio \\<equiv> 5 :: priority\"\ndefinition \"High_mcp \\<equiv> 5 :: priority\"\ndefinition \"High_prio \\<equiv> 5 :: priority\"\ndefinition \"Low_time_slice \\<equiv> 0 :: nat\"\ndefinition \"High_time_slice \\<equiv> 5 :: nat\"\ndefinition \"Low_domain \\<equiv> 0 :: domain\"\ndefinition \"High_domain \\<equiv> 1 :: domain\"\n\nlemmas s0_ptr_defs =\n  Low_pool_ptr_def High_pool_ptr_def Low_cnode_ptr_def High_cnode_ptr_def Silc_cnode_ptr_def\n  ntfn_ptr_def irq_cnode_ptr_def Low_pd_ptr_def High_pd_ptr_def Low_pt_ptr_def High_pt_ptr_def\n  Low_tcb_ptr_def High_tcb_ptr_def idle_tcb_ptr_def timer_irq_def Low_prio_def High_prio_def\n  Low_time_slice_def Low_domain_def High_domain_def init_irq_node_ptr_def riscv_global_pt_ptr_def\n  pptr_base_def pptrBase_def canonical_bit_def shared_page_ptr_virt_def\n\n(* Distinctness proof of kernel pointers. *)\n\ndistinct ptrs_distinct[simp]:\n  Low_tcb_ptr High_tcb_ptr idle_tcb_ptr ntfn_ptr\n  Low_pt_ptr High_pt_ptr shared_page_ptr_virt Low_pd_ptr High_pd_ptr\n  Low_cnode_ptr High_cnode_ptr Low_pool_ptr High_pool_ptr\n  Silc_cnode_ptr irq_cnode_ptr riscv_global_pt_ptr\n  by (auto simp: s0_ptr_defs)\n\n\ntext \\<open>We need to define the asids of each pd and pt to ensure that\nthe object is included in the right ASID-label\\<close>\n\ndefinition Low_asid :: asid where\n  \"Low_asid \\<equiv> 1 << asid_low_bits\"\n\ndefinition High_asid :: asid where\n  \"High_asid \\<equiv> 2 << asid_low_bits\"\n\ndefinition Silc_asid :: asid where\n  \"Silc_asid \\<equiv> 3 << asid_low_bits\"\n\ndistinct asid_high_bits_distinct[simp]:\n  \"asid_high_bits_of Low_asid\"\n  \"asid_high_bits_of High_asid\"\n  \"asid_high_bits_of Silc_asid\"\n  by (auto simp: asid_high_bits_of_def asid_low_bits_def Low_asid_def High_asid_def Silc_asid_def)\n\ndistinct asids_distinct[simp]:\n  High_asid Low_asid Silc_asid\n  by (auto simp: Low_asid_def High_asid_def Silc_asid_def asid_low_bits_def)\n\n\ntext \\<open>converting a nat to a bool list of size 10 - for the cnodes\\<close>\n\ndefinition nat_to_bl :: \"nat \\<Rightarrow> nat \\<Rightarrow> bool list option\" where\n  \"nat_to_bl bits n \\<equiv>\n    if n \\<ge> 2^bits then None\n    else Some $ bin_to_bl bits (of_nat n)\"\n\nlemma nat_to_bl_id [simp]: \"nat_to_bl (size (x :: (('a::len) word))) (unat x) = Some (to_bl x)\"\n  by (clarsimp simp: nat_to_bl_def to_bl_def le_def word_size)\n\ndefinition the_nat_to_bl :: \"nat \\<Rightarrow> nat \\<Rightarrow> bool list\" where\n  \"the_nat_to_bl sz n \\<equiv> the (nat_to_bl sz (n mod 2^sz))\"\n\nabbreviation (input) the_nat_to_bl_10  :: \"nat \\<Rightarrow> bool list\" where\n  \"the_nat_to_bl_10 n \\<equiv> the_nat_to_bl 10 n\"\n\nlemma len_the_nat_to_bl[simp]:\n  \"length (the_nat_to_bl x y) = x\"\n  apply (clarsimp simp: the_nat_to_bl_def nat_to_bl_def)\n  apply safe\n   apply (metis le_def mod_less_divisor nat_zero_less_power_iff zero_less_numeral)\n  apply (clarsimp simp: len_bin_to_bl_aux not_le)\n  done\n\nlemma tcb_cnode_index_nat_to_bl [simp]:\n  \"the_nat_to_bl_10 n \\<noteq> tcb_cnode_index n\"\n  by (clarsimp simp: tcb_cnode_index_def intro!: length_neq)\n\nlemma mod_less_self [simp]:\n  \"a \\<le> b mod a \\<longleftrightarrow> ((a :: nat) = 0)\"\n  by (metis mod_less_divisor nat_neq_iff not_less not_less0)\n\nlemma split_div_mod:\n  \"a = (b::nat) \\<longleftrightarrow> (a div k = b div k \\<and> a mod k = b mod k)\"\n  by (metis mult_div_mod_eq)\n\nlemma nat_to_bl_eq:\n  assumes \"a < 2 ^ n \\<or> b < 2 ^ n\"\n  shows \"nat_to_bl n a = nat_to_bl n b \\<longleftrightarrow> a = b\"\n  using assms\n  apply -\n  apply (erule disjE_R)\n   apply (clarsimp simp: nat_to_bl_def)\n  apply (case_tac \"a \\<ge> 2 ^ n\")\n   apply (clarsimp simp: nat_to_bl_def)\n  apply (clarsimp simp: not_le)\n  apply (induct n arbitrary: a b)\n   apply (clarsimp simp: nat_to_bl_def)\n  apply atomize\n  apply (clarsimp simp: nat_to_bl_def)\n  apply (erule_tac x=\"a div 2\" in allE)\n  apply (erule_tac x=\"b div 2\" in allE)\n  apply (erule impE)\n   apply (metis power_commutes td_gal_lt zero_less_numeral)\n  apply (clarsimp simp: bin_last_def zdiv_int)\n  apply (rule iffI [rotated], clarsimp)\n  apply (subst (asm) (1 2 3 4) bin_to_bl_aux_alt)\n  apply (clarsimp simp: mod_eq_dvd_iff)\n  apply (subst split_div_mod [where k=2])\n  apply clarsimp\n  apply presburger\n  done\n\nlemma nat_to_bl_mod_n_eq[simp]:\n  \"nat_to_bl n a = nat_to_bl n b \\<longleftrightarrow> ((a = b \\<and> a < 2 ^ n) \\<or> (a \\<ge> 2 ^ n \\<and> b \\<ge> 2 ^ n))\"\n  apply (rule iffI)\n   apply (clarsimp simp: not_le)\n   apply (subst (asm) nat_to_bl_eq, simp)\n   apply clarsimp\n  apply (erule disjE)\n   apply clarsimp\n  apply (clarsimp simp: nat_to_bl_def)\n  done\n\nlemma the_the_eq:\n  \"\\<lbrakk> x \\<noteq> None; y \\<noteq> None \\<rbrakk> \\<Longrightarrow> (the x = the y) = (x = y)\"\n  by auto\n\nlemma the_nat_to_bl_eq [simp]:\n  \"(the_nat_to_bl n a = the_nat_to_bl m b) \\<longleftrightarrow> (n = m \\<and> (a mod 2 ^ n = b mod 2 ^ n))\"\n  apply (case_tac \"n = m\")\n   apply (clarsimp simp: the_nat_to_bl_def)\n   apply (subst the_the_eq)\n     apply (clarsimp simp: nat_to_bl_def)\n    apply (clarsimp simp: nat_to_bl_def)\n   apply simp\n  apply simp\n  apply (metis len_the_nat_to_bl)\n  done\n\nlemma empty_cnode_eq_Some[simp]:\n  \"(empty_cnode n x = Some y) = (length x = n \\<and> y = NullCap)\"\n  by (clarsimp simp: empty_cnode_def, metis)\n\nlemma empty_cnode_eq_None[simp]:\n  \"(empty_cnode n x = None) = (length x \\<noteq> n)\"\n  by (clarsimp simp: empty_cnode_def)\n\n\ntext \\<open>Low's CSpace\\<close>\n\ndefinition Low_caps :: cnode_contents where\n  \"Low_caps \\<equiv>\n   (empty_cnode 10)\n     ((the_nat_to_bl_10 1)\n        \\<mapsto> ThreadCap Low_tcb_ptr,\n      (the_nat_to_bl_10 2)\n        \\<mapsto> CNodeCap Low_cnode_ptr 10 (the_nat_to_bl_10 2),\n      (the_nat_to_bl_10 3)\n        \\<mapsto> ArchObjectCap (PageTableCap Low_pd_ptr (Some (Low_asid,0))),\n      (the_nat_to_bl_10 4)\n        \\<mapsto> ArchObjectCap (ASIDPoolCap Low_pool_ptr Low_asid),\n      (the_nat_to_bl_10 5)\n        \\<mapsto> ArchObjectCap (FrameCap shared_page_ptr_virt vm_read_write RISCVLargePage False (Some (Low_asid,0))),\n      (the_nat_to_bl_10 6)\n        \\<mapsto> ArchObjectCap (PageTableCap Low_pt_ptr (Some (Low_asid,0))),\n      (the_nat_to_bl_10 318)\n        \\<mapsto> NotificationCap ntfn_ptr 0 {AllowSend})\"\n\ndefinition Low_cnode :: kernel_object where\n  \"Low_cnode \\<equiv> CNode 10 Low_caps\"\n\nlemma ran_empty_cnode[simp]:\n  \"ran (empty_cnode C) = {NullCap}\"\n  by (auto simp: empty_cnode_def ran_def Ex_list_of_length intro: set_eqI)\n\nlemma empty_cnode_app[simp]:\n  \"length x = n \\<Longrightarrow> empty_cnode n x = Some NullCap\"\n  by (auto simp: empty_cnode_def)\n\nlemma in_ran_If[simp]:\n  \"(x \\<in> ran (\\<lambda>n. if P n then A n else B n)) \\<longleftrightarrow>\n   (\\<exists>n. P n \\<and> A n = Some x) \\<or> (\\<exists>n. \\<not> P n \\<and> B n = Some x)\"\n  by (auto simp: ran_def)\n\nlemma Low_caps_ran:\n  \"ran Low_caps =\n     {ThreadCap Low_tcb_ptr,\n      CNodeCap Low_cnode_ptr 10 (the_nat_to_bl_10 2),\n      ArchObjectCap (PageTableCap Low_pd_ptr (Some (Low_asid,0))),\n      ArchObjectCap (PageTableCap Low_pt_ptr (Some (Low_asid,0))),\n      ArchObjectCap (ASIDPoolCap Low_pool_ptr Low_asid),\n      ArchObjectCap (FrameCap shared_page_ptr_virt vm_read_write RISCVLargePage False (Some (Low_asid,0))),\n      NotificationCap ntfn_ptr 0 {AllowSend},\n      NullCap}\"\n  apply (rule equalityI)\n   apply (clarsimp simp: Low_caps_def fun_upd_def empty_cnode_def split: if_split_asm)\n  apply (clarsimp simp: Low_caps_def fun_upd_def empty_cnode_def split: if_split_asm cong: conj_cong)\n  apply (rule exI[where x=\"the_nat_to_bl_10 0\"])\n  apply simp\n  done\n\n\ntext \\<open>High's Cspace\\<close>\n\ndefinition High_caps :: cnode_contents where\n  \"High_caps \\<equiv>\n     (empty_cnode 10)\n       ((the_nat_to_bl_10 1)\n          \\<mapsto> ThreadCap High_tcb_ptr,\n        (the_nat_to_bl_10 2)\n          \\<mapsto> CNodeCap High_cnode_ptr 10 (the_nat_to_bl_10 2),\n        (the_nat_to_bl_10 3)\n          \\<mapsto> ArchObjectCap (PageTableCap High_pd_ptr (Some (High_asid,0))),\n        (the_nat_to_bl_10 4)\n          \\<mapsto> ArchObjectCap (ASIDPoolCap High_pool_ptr High_asid),\n        (the_nat_to_bl_10 5)\n          \\<mapsto> ArchObjectCap (FrameCap shared_page_ptr_virt vm_read_only RISCVLargePage False (Some (High_asid,0))),\n        (the_nat_to_bl_10 6)\n          \\<mapsto> ArchObjectCap (PageTableCap High_pt_ptr (Some (High_asid,0))),\n        (the_nat_to_bl_10 318)\n          \\<mapsto> NotificationCap ntfn_ptr 0 {AllowRecv}) \"\n\ndefinition High_cnode :: kernel_object where\n  \"High_cnode \\<equiv> CNode 10 High_caps\"\n\nlemma High_caps_ran:\n  \"ran High_caps =\n     {ThreadCap High_tcb_ptr,\n      CNodeCap High_cnode_ptr 10 (the_nat_to_bl_10 2),\n      ArchObjectCap (PageTableCap High_pd_ptr (Some (High_asid,0))),\n      ArchObjectCap (PageTableCap High_pt_ptr (Some (High_asid,0))),\n      ArchObjectCap (ASIDPoolCap High_pool_ptr High_asid),\n      ArchObjectCap (FrameCap shared_page_ptr_virt vm_read_only RISCVLargePage False (Some (High_asid,0))),\n      NotificationCap ntfn_ptr 0 {AllowRecv},\n      NullCap}\"\n  apply (rule equalityI)\n   apply (clarsimp simp: High_caps_def ran_def empty_cnode_def split: if_split_asm)\n  apply (clarsimp simp: High_caps_def ran_def empty_cnode_def split: if_split_asm cong: conj_cong)\n  apply (rule exI [where x=\"the_nat_to_bl_10 0\"])\n  apply simp\n  done\n\n\ntext \\<open>We need a copy of boundary crossing caps owned by SilcLabel\\<close>\n\ndefinition Silc_caps :: cnode_contents where\n  \"Silc_caps \\<equiv>\n     (empty_cnode 10)\n       ((the_nat_to_bl_10 2)\n          \\<mapsto> CNodeCap Silc_cnode_ptr 10 (the_nat_to_bl_10 2),\n        (the_nat_to_bl_10 5)\n          \\<mapsto> ArchObjectCap (FrameCap shared_page_ptr_virt vm_read_only RISCVLargePage False (Some (Silc_asid,0))),\n        (the_nat_to_bl_10 318)\n          \\<mapsto> NotificationCap ntfn_ptr 0 {AllowSend} )\"\n\ndefinition Silc_cnode :: kernel_object where\n  \"Silc_cnode \\<equiv> CNode 10 Silc_caps\"\n\nlemma Silc_caps_ran:\n  \"ran Silc_caps =\n     {CNodeCap Silc_cnode_ptr 10 (the_nat_to_bl_10 2),\n      ArchObjectCap (FrameCap shared_page_ptr_virt vm_read_only RISCVLargePage False (Some (Silc_asid,0))),\n      NotificationCap ntfn_ptr 0 {AllowSend},\n      NullCap}\"\n  apply (rule equalityI)\n   apply (clarsimp simp: Silc_caps_def ran_def empty_cnode_def)\n  apply (clarsimp simp: ran_def Silc_caps_def empty_cnode_def cong: conj_cong)\n  apply (rule_tac x=\"the_nat_to_bl_10 0\" in exI)\n  apply simp\n  done\n\n\ntext \\<open>notification between Low and High\\<close>\n\ndefinition ntfn :: kernel_object where\n  \"ntfn \\<equiv> Notification \\<lparr>ntfn_obj = WaitingNtfn [High_tcb_ptr], ntfn_bound_tcb=None\\<rparr>\"\n\n\ntext \\<open>global page table is mapped into the top-level page tables of each vspace\\<close>\n\nabbreviation init_global_pt' where\n  \"init_global_pt' \\<equiv> (\\<lambda>idx. if idx \\<in> kernel_mapping_slots then global_pte idx else InvalidPTE)\"\n\n\ntext \\<open>Low's VSpace (PageDirectory)\\<close>\n\nabbreviation ppn_from_addr :: \"paddr \\<Rightarrow> pte_ppn\" where\n  \"ppn_from_addr addr \\<equiv> ucast (addr >> pt_bits)\"\n\nabbreviation Low_pt' :: pt where\n  \"Low_pt' \\<equiv>\n     (\\<lambda>_. InvalidPTE)\n       (0 := PagePTE (ppn_from_addr shared_page_ptr_phys) {} vm_read_write)\"\n\ndefinition Low_pt :: kernel_object where\n  \"Low_pt \\<equiv> ArchObj (PageTable Low_pt')\"\n\nabbreviation Low_pd' :: pt where\n  \"Low_pd' \\<equiv>\n     init_global_pt'\n       (0 := PageTablePTE (ppn_from_addr (addrFromPPtr Low_pt_ptr)) {})\"\n\ndefinition Low_pd :: kernel_object where\n  \"Low_pd \\<equiv> ArchObj (PageTable Low_pd')\"\n\n\ntext \\<open>High's VSpace (PageDirectory)\\<close>\n\nabbreviation High_pt' :: pt where\n  \"High_pt' \\<equiv>\n     (\\<lambda>_. InvalidPTE)\n       (0 := PagePTE (ppn_from_addr shared_page_ptr_phys) {} vm_read_only)\"\n\ndefinition High_pt :: kernel_object where\n  \"High_pt \\<equiv> ArchObj (PageTable High_pt')\"\n\nabbreviation High_pd' :: pt where\n  \"High_pd' \\<equiv>\n     init_global_pt'\n       (0 := PageTablePTE (ppn_from_addr (addrFromPPtr High_pt_ptr)) {})\"\n\ndefinition High_pd :: kernel_object where\n  \"High_pd \\<equiv> ArchObj (PageTable High_pd')\"\n\n\ntext \\<open>Low's tcb\\<close>\n\ndefinition Low_tcb :: kernel_object where\n  \"Low_tcb \\<equiv> TCB \\<lparr>tcb_ctable = CNodeCap Low_cnode_ptr 10 (the_nat_to_bl_10 2),\n                  tcb_vtable = ArchObjectCap (PageTableCap Low_pd_ptr (Some (Low_asid,0))),\n                  tcb_reply = ReplyCap Low_tcb_ptr True {AllowGrant, AllowWrite},\n                  tcb_caller = NullCap,\n                  tcb_ipcframe = NullCap,\n                  tcb_state = Running,\n                  tcb_fault_handler = replicate word_bits False,\n                  tcb_ipc_buffer = 0,\n                  tcb_fault = None,\n                  tcb_bound_notification = None,\n                  tcb_mcpriority = Low_mcp,\n                  tcb_arch = \\<lparr>tcb_context = undefined\\<rparr>\\<rparr>\"\n\ndefinition Low_etcb :: etcb where\n  \"Low_etcb \\<equiv> \\<lparr>tcb_priority   = Low_prio,\n               tcb_time_slice = Low_time_slice,\n               tcb_domain     = Low_domain\\<rparr>\"\n\n\ntext \\<open>High's tcb\\<close>\n\ndefinition High_tcb :: kernel_object where\n  \"High_tcb \\<equiv> TCB \\<lparr>tcb_ctable = CNodeCap High_cnode_ptr 10 (the_nat_to_bl_10 2) ,\n                   tcb_vtable = ArchObjectCap (PageTableCap High_pd_ptr (Some (High_asid,0))),\n                   tcb_reply = ReplyCap High_tcb_ptr True {AllowGrant, AllowWrite},\n                   tcb_caller = NullCap,\n                   tcb_ipcframe = NullCap,\n                   tcb_state = BlockedOnNotification ntfn_ptr,\n                   tcb_fault_handler = replicate word_bits False,\n                   tcb_ipc_buffer = 0,\n                   tcb_fault = None,\n                   tcb_bound_notification = None,\n                   tcb_mcpriority = High_mcp,\n                   tcb_arch = \\<lparr>tcb_context = undefined\\<rparr>\\<rparr>\"\n\ndefinition High_etcb :: etcb where\n  \"High_etcb \\<equiv> \\<lparr>tcb_priority   = High_prio,\n                tcb_time_slice = High_time_slice,\n                tcb_domain     = High_domain\\<rparr>\"\n\n\ntext \\<open>idle's tcb\\<close>\n\ndefinition idle_tcb :: kernel_object where\n  \"idle_tcb \\<equiv> TCB \\<lparr>tcb_ctable = NullCap,\n                   tcb_vtable = NullCap,\n                   tcb_reply = NullCap,\n                   tcb_caller = NullCap,\n                   tcb_ipcframe = NullCap,\n                   tcb_state = IdleThreadState,\n                   tcb_fault_handler = replicate word_bits False,\n                   tcb_ipc_buffer = 0,\n                   tcb_fault = None,\n                   tcb_bound_notification = None,\n                   tcb_mcpriority = default_priority,\n                   tcb_arch = \\<lparr>tcb_context = empty_context\\<rparr>\\<rparr>\"\n\ndefinition\n  \"irq_cnode \\<equiv> CNode 0 (Map.empty([] \\<mapsto> cap.NullCap))\"\n\nabbreviation\n  \"Low_pool' \\<equiv> \\<lambda>idx. if idx = asid_low_bits_of Low_asid then Some Low_pd_ptr else None\"\n\ndefinition\n  \"Low_pool \\<equiv> ArchObj (ASIDPool Low_pool')\"\n\nabbreviation\n  \"High_pool' \\<equiv> \\<lambda>idx. if idx = asid_low_bits_of High_asid then Some High_pd_ptr else None\"\n\ndefinition\n  \"High_pool \\<equiv> ArchObj (ASIDPool High_pool')\"\n\ndefinition\n  \"shared_page \\<equiv> ArchObj (DataPage False RISCVLargePage)\"\n\ndefinition kh0 :: kheap where\n  \"kh0 \\<equiv> (\\<lambda>x. if \\<exists>irq :: irq. init_irq_node_ptr + (ucast irq << 5) = x\n               then Some (CNode 0 (empty_cnode 0))\n               else None)\n         (Low_cnode_ptr  \\<mapsto> Low_cnode,\n          High_cnode_ptr \\<mapsto> High_cnode,\n          Low_pool_ptr   \\<mapsto> Low_pool,\n          High_pool_ptr  \\<mapsto> High_pool,\n          Silc_cnode_ptr \\<mapsto> Silc_cnode,\n          ntfn_ptr       \\<mapsto> ntfn,\n          irq_cnode_ptr  \\<mapsto> irq_cnode,\n          Low_pd_ptr     \\<mapsto> Low_pd,\n          High_pd_ptr    \\<mapsto> High_pd,\n          Low_pt_ptr     \\<mapsto> Low_pt,\n          High_pt_ptr    \\<mapsto> High_pt,\n          Low_tcb_ptr    \\<mapsto> Low_tcb,\n          High_tcb_ptr   \\<mapsto> High_tcb,\n          idle_tcb_ptr   \\<mapsto> idle_tcb,\n          shared_page_ptr_virt \\<mapsto> shared_page,\n          riscv_global_pt_ptr \\<mapsto> init_global_pt)\"\n\nlemma irq_node_offs_min:\n  \"init_irq_node_ptr \\<le> init_irq_node_ptr + (ucast (irq :: irq) << 5)\"\n  apply (rule_tac sz=59 in machine_word_plus_mono_right_split)\n   apply (simp add: unat_word_ariths mask_def shiftl_t2n s0_ptr_defs)\n   apply (cut_tac x=irq and 'a=64 in ucast_less)\n    apply simp\n   apply (simp add: word_less_nat_alt)\n  apply (simp add: word_bits_def)\n  done\n\nlemma irq_node_offs_max:\n  \"init_irq_node_ptr + (ucast (irq:: irq) << 5) < init_irq_node_ptr + 0x7E1\"\n  apply (simp add: s0_ptr_defs shiftl_t2n)\n  apply (cut_tac x=irq and 'a=64 in ucast_less)\n   apply simp\n  apply (simp add: word_less_nat_alt unat_word_ariths)\n  done\n\ndefinition irq_node_offs_range where\n  \"irq_node_offs_range \\<equiv> {x. init_irq_node_ptr \\<le> x \\<and> x < init_irq_node_ptr + 0x7E1}\n                       \\<inter> {x. is_aligned x 5}\"\n\nlemma irq_node_offs_in_range:\n  \"init_irq_node_ptr + (ucast (irq:: irq) << 5) \\<in> irq_node_offs_range\"\n  apply (clarsimp simp: irq_node_offs_min irq_node_offs_max irq_node_offs_range_def)\n  apply (rule is_aligned_add[OF _ is_aligned_shift])\n  apply (simp add: is_aligned_def s0_ptr_defs)\n  done\n\nlemma irq_node_offs_range_correct:\n  \"x \\<in> irq_node_offs_range\n   \\<Longrightarrow> \\<exists>irq. x = init_irq_node_ptr + (ucast (irq:: irq) << 5)\"\n  apply (clarsimp simp: irq_node_offs_min irq_node_offs_max irq_node_offs_range_def s0_ptr_defs)\n  apply (rule_tac x=\"ucast ((x - 0xFFFFFFC000003000) >> 5)\" in exI)\n  apply (clarsimp simp: ucast_ucast_mask)\n  apply (subst aligned_shiftr_mask_shiftl)\n   apply (rule aligned_sub_aligned)\n     apply assumption\n    apply (simp add: is_aligned_def)\n   apply simp\n  apply simp\n  apply (rule_tac n=11 in mask_eqI)\n   apply (subst mask_add_aligned)\n    apply (simp add: is_aligned_def)\n   apply (simp add: mask_twice)\n   apply (simp add: diff_conv_add_uminus del: add_uminus_conv_diff)\n   apply (subst add.commute[symmetric])\n   apply (subst mask_add_aligned)\n    apply (simp add: is_aligned_def)\n   apply simp\n  apply (simp add: diff_conv_add_uminus del: add_uminus_conv_diff)\n  apply (subst add_mask_lower_bits)\n    apply (simp add: is_aligned_def)\n   apply clarsimp\n  apply (cut_tac x=x and y=\"0xFFFFFFC0000037E0\" and n=14 in neg_mask_mono_le)\n   apply (force dest: word_less_sub_1)\n  apply (drule_tac n=11 in aligned_le_sharp)\n   apply (simp add: is_aligned_def)\n  apply (simp add: mask_def is_aligned_mask)\n  apply word_bitwise\n  apply fastforce\n  done\n\nlemma irq_node_offs_range_distinct[simp]:\n  \"Low_cnode_ptr \\<notin> irq_node_offs_range\"\n  \"High_cnode_ptr \\<notin> irq_node_offs_range\"\n  \"Low_pool_ptr \\<notin> irq_node_offs_range\"\n  \"High_pool_ptr \\<notin> irq_node_offs_range\"\n  \"Silc_cnode_ptr \\<notin> irq_node_offs_range\"\n  \"ntfn_ptr \\<notin> irq_node_offs_range\"\n  \"irq_cnode_ptr \\<notin> irq_node_offs_range\"\n  \"Low_pd_ptr \\<notin> irq_node_offs_range\"\n  \"High_pd_ptr \\<notin> irq_node_offs_range\"\n  \"Low_pt_ptr \\<notin> irq_node_offs_range\"\n  \"High_pt_ptr \\<notin> irq_node_offs_range\"\n  \"Low_tcb_ptr \\<notin> irq_node_offs_range\"\n  \"High_tcb_ptr \\<notin> irq_node_offs_range\"\n  \"idle_tcb_ptr \\<notin> irq_node_offs_range\"\n  \"riscv_global_pt_ptr \\<notin> irq_node_offs_range\"\n  \"shared_page_ptr_virt \\<notin> irq_node_offs_range\"\n  by(simp add:irq_node_offs_range_def s0_ptr_defs)+\n\nlemma irq_node_offs_distinct[simp]:\n  \"init_irq_node_ptr + (ucast (irq:: irq) << 5) \\<noteq> Low_cnode_ptr\"\n  \"init_irq_node_ptr + (ucast (irq:: irq) << 5) \\<noteq> High_cnode_ptr\"\n  \"init_irq_node_ptr + (ucast (irq:: irq) << 5) \\<noteq> Low_pool_ptr\"\n  \"init_irq_node_ptr + (ucast (irq:: irq) << 5) \\<noteq> High_pool_ptr\"\n  \"init_irq_node_ptr + (ucast (irq:: irq) << 5) \\<noteq> Silc_cnode_ptr\"\n  \"init_irq_node_ptr + (ucast (irq:: irq) << 5) \\<noteq> ntfn_ptr\"\n  \"init_irq_node_ptr + (ucast (irq:: irq) << 5) \\<noteq> irq_cnode_ptr\"\n  \"init_irq_node_ptr + (ucast (irq:: irq) << 5) \\<noteq> Low_pd_ptr\"\n  \"init_irq_node_ptr + (ucast (irq:: irq) << 5) \\<noteq> High_pd_ptr\"\n  \"init_irq_node_ptr + (ucast (irq:: irq) << 5) \\<noteq> Low_pt_ptr\"\n  \"init_irq_node_ptr + (ucast (irq:: irq) << 5) \\<noteq> High_pt_ptr\"\n  \"init_irq_node_ptr + (ucast (irq:: irq) << 5) \\<noteq> Low_tcb_ptr\"\n  \"init_irq_node_ptr + (ucast (irq:: irq) << 5) \\<noteq> High_tcb_ptr\"\n  \"init_irq_node_ptr + (ucast (irq:: irq) << 5) \\<noteq> idle_tcb_ptr\"\n  \"init_irq_node_ptr + (ucast (irq:: irq) << 5) \\<noteq> riscv_global_pt_ptr\"\n  \"init_irq_node_ptr + (ucast (irq:: irq) << 5) \\<noteq> shared_page_ptr_virt\"\n  by (simp add:not_inD[symmetric, OF _ irq_node_offs_in_range])+\n\nlemma kh0_dom:\n  \"dom kh0 = {shared_page_ptr_virt, riscv_global_pt_ptr, idle_tcb_ptr, High_tcb_ptr, Low_tcb_ptr,\n              High_pt_ptr, Low_pt_ptr, High_pd_ptr, Low_pd_ptr, irq_cnode_ptr, ntfn_ptr,\n              Silc_cnode_ptr, High_pool_ptr, Low_pool_ptr, High_cnode_ptr, Low_cnode_ptr}\n           \\<union> irq_node_offs_range\"\n  apply (rule equalityI)\n   apply (simp add: kh0_def dom_def)\n   apply (clarsimp simp: irq_node_offs_in_range)\n  apply (clarsimp simp: dom_def)\n  apply (rule conjI, clarsimp simp: kh0_def)+\n  apply (force simp: kh0_def dest: irq_node_offs_range_correct)\n  done\n\nlemmas kh0_SomeD' = set_mp[OF equalityD1[OF kh0_dom[simplified dom_def]], OF CollectI, simplified, OF exI]\n\nlemma kh0_SomeD:\n  \"kh0 x = Some y \\<Longrightarrow>\n        x = shared_page_ptr_virt \\<and> y = shared_page \\<or>\n        x = riscv_global_pt_ptr \\<and> y = init_global_pt \\<or>\n        x = idle_tcb_ptr \\<and> y = idle_tcb \\<or>\n        x = High_tcb_ptr \\<and> y = High_tcb \\<or>\n        x = Low_tcb_ptr \\<and> y = Low_tcb \\<or>\n        x = High_pt_ptr \\<and> y = High_pt \\<or>\n        x = Low_pt_ptr \\<and> y = Low_pt \\<or>\n        x = High_pd_ptr \\<and> y = High_pd \\<or>\n        x = Low_pd_ptr \\<and> y = Low_pd \\<or>\n        x = irq_cnode_ptr \\<and> y = irq_cnode \\<or>\n        x = ntfn_ptr \\<and> y = ntfn \\<or>\n        x = Silc_cnode_ptr \\<and> y = Silc_cnode \\<or>\n        x = High_pool_ptr \\<and> y = High_pool \\<or>\n        x = Low_pool_ptr \\<and> y = Low_pool \\<or>\n        x = High_cnode_ptr \\<and> y = High_cnode \\<or>\n        x = Low_cnode_ptr \\<and> y = Low_cnode \\<or>\n        x \\<in> irq_node_offs_range \\<and> y = CNode 0 (empty_cnode 0)\"\n  apply (frule kh0_SomeD')\n  apply (erule disjE, simp add: kh0_def | force simp: kh0_def split: if_split_asm)+\n  done\n\nlemmas kh0_obj_def =\n  Low_cnode_def High_cnode_def Silc_cnode_def Low_pool_def High_pool_def Low_pd_def High_pd_def\n  Low_pt_def High_pt_def  Low_tcb_def High_tcb_def idle_tcb_def irq_cnode_def ntfn_def\n  init_global_pt_def global_pte_def vm_kernel_only_def shared_page_def\n\n\ndefinition exst0 :: \"det_ext\" where\n  \"exst0 \\<equiv> \\<lparr>work_units_completed_internal = undefined,\n            scheduler_action_internal = resume_cur_thread,\n            ekheap_internal = [Low_tcb_ptr  \\<mapsto> Low_etcb,\n                               High_tcb_ptr \\<mapsto> High_etcb,\n                               idle_tcb_ptr \\<mapsto> default_etcb],\n            domain_list_internal = [(0, 10), (1, 10)],\n            domain_index_internal = 0,\n            cur_domain_internal = 0,\n            domain_time_internal = 5,\n            ready_queues_internal = (const (const [])),\n            cdt_list_internal = const []\\<rparr>\"\n\nlemmas ekh0_obj_def =\n  Low_etcb_def High_etcb_def default_etcb_def\n\ndefinition machine_state0 :: \"machine_state\" where\n  \"machine_state0 \\<equiv> \\<lparr>irq_masks = (\\<lambda>irq. if irq = timer_irq then False else True),\n                     irq_state = 0,\n                     underlying_memory = const 0,\n                     device_state = Map.empty,\n                     machine_state_rest = undefined\\<rparr>\"\n\ndefinition arch_state0 :: \"arch_state\" where\n  \"arch_state0 \\<equiv> \\<lparr>\n     riscv_asid_table = [asid_high_bits_of Low_asid \\<mapsto> Low_pool_ptr,\n                         asid_high_bits_of High_asid \\<mapsto> High_pool_ptr],\n     riscv_global_pts = (\\<lambda>level. if level = max_pt_level then {riscv_global_pt_ptr} else {}),\n     riscv_kernel_vspace = init_vspace_uses\n   \\<rparr>\"\n\ndefinition s0_internal :: \"det_ext state\" where\n  \"s0_internal \\<equiv> \\<lparr>\n     kheap = kh0,\n     cdt = Map.empty,\n     is_original_cap = (\\<lambda>_. False) ((Low_tcb_ptr, tcb_cnode_index 2) := True,\n                                    (High_tcb_ptr, tcb_cnode_index 2) := True),\n     cur_thread = Low_tcb_ptr,\n     idle_thread = idle_tcb_ptr,\n     machine_state = machine_state0,\n     interrupt_irq_node = (\\<lambda>irq. init_irq_node_ptr + (ucast irq << 5)),\n     interrupt_states = (\\<lambda>_. irq_state.IRQInactive) (timer_irq := irq_state.IRQTimer),\n     arch_state = arch_state0,\n     exst = exst0\n   \\<rparr>\"\n\nlemma kh_s0_def:\n  \"(kheap s0_internal x = Some y) = (\n        x = shared_page_ptr_virt \\<and> y = shared_page \\<or>\n        x = riscv_global_pt_ptr \\<and> y = init_global_pt \\<or>\n        x = idle_tcb_ptr \\<and> y = idle_tcb \\<or>\n        x = High_tcb_ptr \\<and> y = High_tcb \\<or>\n        x = Low_tcb_ptr \\<and> y = Low_tcb \\<or>\n        x = High_pt_ptr \\<and> y = High_pt \\<or>\n        x = Low_pt_ptr \\<and> y = Low_pt \\<or>\n        x = High_pd_ptr \\<and> y = High_pd \\<or>\n        x = Low_pd_ptr \\<and> y = Low_pd \\<or>\n        x = irq_cnode_ptr \\<and> y = irq_cnode \\<or>\n        x = ntfn_ptr \\<and> y = ntfn \\<or>\n        x = Silc_cnode_ptr \\<and> y = Silc_cnode \\<or>\n        x = High_pool_ptr \\<and> y = High_pool \\<or>\n        x = Low_pool_ptr \\<and> y = Low_pool \\<or>\n        x = High_cnode_ptr \\<and> y = High_cnode \\<or>\n        x = Low_cnode_ptr \\<and> y = Low_cnode \\<or>\n        x \\<in> irq_node_offs_range \\<and> y = CNode 0 (empty_cnode 0))\"\n  apply (clarsimp simp: s0_internal_def kh0_def)\n  apply (auto simp: irq_node_offs_in_range dest: irq_node_offs_range_correct)\n  done\n\n\nsubsubsection \\<open>Defining the policy graph\\<close>\n\ndefinition Sys1AgentMap :: \"(auth_graph_label subject_label) agent_map\" where\n  \"Sys1AgentMap \\<equiv>\n   \\<comment> \\<open>set the range of the shared_page to Low, default everything else to IRQ0\\<close>\n   (\\<lambda>p. if p \\<in> ptr_range shared_page_ptr_virt (pageBitsForSize RISCVLargePage)\n        then partition_label Low\n        else partition_label IRQ0)\n   (Low_cnode_ptr := partition_label Low,\n    High_cnode_ptr := partition_label High,\n    Low_pool_ptr := partition_label Low,\n    High_pool_ptr := partition_label High,\n    ntfn_ptr := partition_label High,\n    irq_cnode_ptr := partition_label IRQ0,\n    Silc_cnode_ptr := SilcLabel,\n    Low_pd_ptr := partition_label Low,\n    High_pd_ptr := partition_label High,\n    Low_pt_ptr := partition_label Low,\n    High_pt_ptr := partition_label High,\n    Low_tcb_ptr := partition_label Low,\n    High_tcb_ptr := partition_label High,\n    idle_tcb_ptr := partition_label Low)\"\n\nlemma Sys1AgentMap_simps:\n  \"Sys1AgentMap Low_cnode_ptr = partition_label Low\"\n  \"Sys1AgentMap High_cnode_ptr = partition_label High\"\n  \"Sys1AgentMap Low_pool_ptr = partition_label Low\"\n  \"Sys1AgentMap High_pool_ptr = partition_label High\"\n  \"Sys1AgentMap ntfn_ptr = partition_label High\"\n  \"Sys1AgentMap irq_cnode_ptr = partition_label IRQ0\"\n  \"Sys1AgentMap Silc_cnode_ptr = SilcLabel\"\n  \"Sys1AgentMap Low_pd_ptr = partition_label Low\"\n  \"Sys1AgentMap High_pd_ptr = partition_label High\"\n  \"Sys1AgentMap Low_pt_ptr = partition_label Low\"\n  \"Sys1AgentMap High_pt_ptr = partition_label High\"\n  \"Sys1AgentMap Low_tcb_ptr = partition_label Low\"\n  \"Sys1AgentMap High_tcb_ptr = partition_label High\"\n  \"Sys1AgentMap idle_tcb_ptr = partition_label Low\"\n  \"\\<And>p. p \\<in> ptr_range shared_page_ptr_virt (pageBitsForSize RISCVLargePage)\n         \\<Longrightarrow> Sys1AgentMap p = partition_label Low\"\n  unfolding Sys1AgentMap_def\n  apply simp_all\n  by (auto simp: s0_ptr_defs ptr_range_def)\n\ndefinition Sys1ASIDMap :: \"(auth_graph_label subject_label) agent_asid_map\" where\n  \"Sys1ASIDMap \\<equiv>\n     (\\<lambda>x. if asid_high_bits_of x = asid_high_bits_of Low_asid\n          then partition_label Low\n          else if asid_high_bits_of x = asid_high_bits_of High_asid\n          then partition_label High\n          else if asid_high_bits_of x = asid_high_bits_of Silc_asid\n          then SilcLabel\n          else undefined)\"\n\n(* We include 2 domains, Low is associated to domain 0, High to domain 1,\n   we default the rest of the possible domains to High *)\n\ndefinition Sys1PAS :: \"(auth_graph_label subject_label) PAS\" where\n  \"Sys1PAS \\<equiv>\n     \\<lparr>pasObjectAbs = Sys1AgentMap,\n      pasASIDAbs = Sys1ASIDMap,\n      pasIRQAbs = (\\<lambda>_. partition_label IRQ0),\n      pasPolicy = Sys1AuthGraph,\n      pasSubject = partition_label Low,\n      pasMayActivate = True,\n      pasMayEditReadyQueues = True, pasMaySendIrqs = False,\n      pasDomainAbs = ((\\<lambda>_. {partition_label High})(0 := {partition_label Low}))\\<rparr>\"\n\n\nsubsubsection \\<open>Proof of pas_refined for Sys1\\<close>\n\nlemma High_caps_well_formed: \"well_formed_cnode_n 10 High_caps\"\n  by (auto simp: High_caps_def well_formed_cnode_n_def  split: if_split_asm)\n\nlemma Low_caps_well_formed: \"well_formed_cnode_n 10 Low_caps\"\n  by (auto simp: Low_caps_def well_formed_cnode_n_def  split: if_split_asm)\n\nlemma Silc_caps_well_formed: \"well_formed_cnode_n 10 Silc_caps\"\n  by (auto simp: Silc_caps_def well_formed_cnode_n_def  split: if_split_asm)\n\nlemma s0_caps_of_state :\n  \"caps_of_state s0_internal p = Some cap \\<Longrightarrow>\n     cap = NullCap \\<or>\n     (p,cap) \\<in>\n       { ((Low_cnode_ptr,(the_nat_to_bl_10 1)), ThreadCap Low_tcb_ptr),\n         ((Low_cnode_ptr,(the_nat_to_bl_10 2)), CNodeCap Low_cnode_ptr 10 (the_nat_to_bl_10 2)),\n         ((Low_cnode_ptr,(the_nat_to_bl_10 3)), ArchObjectCap (PageTableCap Low_pd_ptr (Some (Low_asid,0)))),\n         ((Low_cnode_ptr,(the_nat_to_bl_10 6)), ArchObjectCap (PageTableCap Low_pt_ptr (Some (Low_asid,0)))),\n         ((Low_cnode_ptr,(the_nat_to_bl_10 4)), ArchObjectCap (ASIDPoolCap Low_pool_ptr Low_asid)),\n         ((Low_cnode_ptr,(the_nat_to_bl_10 5)), ArchObjectCap (FrameCap shared_page_ptr_virt vm_read_write RISCVLargePage False (Some (Low_asid, 0)))),\n         ((Low_cnode_ptr,(the_nat_to_bl_10 318)), NotificationCap ntfn_ptr 0 {AllowSend}),\n         ((High_cnode_ptr,(the_nat_to_bl_10 1)), ThreadCap High_tcb_ptr),\n         ((High_cnode_ptr,(the_nat_to_bl_10 2)), CNodeCap High_cnode_ptr 10 (the_nat_to_bl_10 2)),\n         ((High_cnode_ptr,(the_nat_to_bl_10 3)), ArchObjectCap (PageTableCap High_pd_ptr (Some (High_asid,0)))),\n         ((High_cnode_ptr,(the_nat_to_bl_10 6)), ArchObjectCap (PageTableCap High_pt_ptr (Some (High_asid,0)))),\n         ((High_cnode_ptr,(the_nat_to_bl_10 4)), ArchObjectCap (ASIDPoolCap High_pool_ptr High_asid)),\n         ((High_cnode_ptr,(the_nat_to_bl_10 5)), ArchObjectCap (FrameCap shared_page_ptr_virt vm_read_only RISCVLargePage False (Some (High_asid, 0)))),\n         ((High_cnode_ptr,(the_nat_to_bl_10 318)), NotificationCap  ntfn_ptr 0 {AllowRecv}) ,\n         ((Silc_cnode_ptr,(the_nat_to_bl_10 2)), CNodeCap Silc_cnode_ptr 10 (the_nat_to_bl_10 2)),\n         ((Silc_cnode_ptr,(the_nat_to_bl_10 5)), ArchObjectCap (FrameCap shared_page_ptr_virt vm_read_only RISCVLargePage False (Some (Silc_asid, 0)))),\n         ((Silc_cnode_ptr,(the_nat_to_bl_10 318)), NotificationCap ntfn_ptr 0 {AllowSend}),\n         ((Low_tcb_ptr,(tcb_cnode_index 0)), CNodeCap Low_cnode_ptr 10 (the_nat_to_bl_10 2)),\n         ((Low_tcb_ptr,(tcb_cnode_index 1)), ArchObjectCap (PageTableCap Low_pd_ptr (Some (Low_asid,0)))),\n         ((Low_tcb_ptr,(tcb_cnode_index 2)), ReplyCap Low_tcb_ptr True {AllowGrant, AllowWrite}),\n         ((Low_tcb_ptr,(tcb_cnode_index 3)), NullCap),\n         ((Low_tcb_ptr,(tcb_cnode_index 4)), NullCap),\n         ((High_tcb_ptr,(tcb_cnode_index 0)), CNodeCap High_cnode_ptr 10 (the_nat_to_bl_10 2)),\n         ((High_tcb_ptr,(tcb_cnode_index 1)), ArchObjectCap (PageTableCap High_pd_ptr (Some (High_asid,0)))),\n         ((High_tcb_ptr,(tcb_cnode_index 2)), ReplyCap High_tcb_ptr True {AllowGrant, AllowWrite}),\n         ((High_tcb_ptr,(tcb_cnode_index 3)), NullCap),\n         ((High_tcb_ptr,(tcb_cnode_index 4)), NullCap)} \"\n  supply if_cong[cong]\n  apply (insert High_caps_well_formed)\n  apply (insert Low_caps_well_formed)\n  apply (insert Silc_caps_well_formed)\n  apply (simp add: caps_of_state_cte_wp_at cte_wp_at_cases s0_internal_def kh0_def kh0_obj_def)\n  apply (case_tac p, clarsimp)\n  apply (clarsimp split: if_splits)\n       apply (clarsimp simp: cte_wp_at_cases tcb_cap_cases_def split: if_split_asm)+\n    apply (clarsimp simp: Silc_caps_def split: if_splits)\n   apply (clarsimp simp: High_caps_def split: if_splits)\n  apply (clarsimp simp: Low_caps_def split: if_splits)\n  done\n\nlemma tcb_states_of_state_s0:\n  \"tcb_states_of_state s0_internal = [High_tcb_ptr \\<mapsto> thread_state.BlockedOnNotification ntfn_ptr,\n                                      Low_tcb_ptr \\<mapsto> thread_state.Running,\n                                      idle_tcb_ptr \\<mapsto> thread_state.IdleThreadState ]\"\n  unfolding s0_internal_def tcb_states_of_state_def\n  by (auto simp: get_tcb_def kh0_def kh0_obj_def)\n\nlemma thread_bounds_of_state_s0:\n  \"thread_bound_ntfns s0_internal = Map.empty\"\n  unfolding s0_internal_def thread_bound_ntfns_def\n  by (auto simp: get_tcb_def kh0_def kh0_obj_def)\n\nlemma Sys1_wellformed':\n  \"policy_wellformed (pasPolicy Sys1PAS) False irqs x\"\n  by (clarsimp simp: Sys1PAS_def Sys1AgentMap_simps Sys1AuthGraph_def policy_wellformed_def)\n\ncorollary Sys1_wellformed:\n  \"x \\<in> range (pasObjectAbs Sys1PAS) \\<union> \\<Union>(range (pasDomainAbs Sys1PAS)) - {SilcLabel}\n   \\<Longrightarrow> policy_wellformed (pasPolicy Sys1PAS) False irqs x\"\n  by (rule Sys1_wellformed')\n\nlemma Sys1_pas_wellformed:\n  \"pas_wellformed Sys1PAS\"\n  by (clarsimp simp: Sys1PAS_def Sys1AgentMap_simps Sys1AuthGraph_def policy_wellformed_def)\n\nlemma domains_of_state_s0[simp]:\n  \"domains_of_state s0_internal = {(High_tcb_ptr, High_domain),\n                                   (Low_tcb_ptr, Low_domain),\n                                   (idle_tcb_ptr, default_domain)}\"\n  apply (rule equalityI)\n   apply (rule subsetI)\n   apply clarsimp\n   apply (erule domains_of_state_aux.cases)\n   apply (clarsimp simp: s0_internal_def exst0_def ekh0_obj_def split: if_split_asm)\n  apply (force simp: s0_internal_def exst0_def ekh0_obj_def intro: domains_of_state_aux.domtcbs)+\n  done\n\nlemma pool_for_asid_s0:\n  \"pool_for_asid asid s0_internal = (if asid_high_bits_of asid = asid_high_bits_of High_asid\n                                     then Some High_pool_ptr\n                                     else if asid_high_bits_of asid = asid_high_bits_of Low_asid\n                                     then Some Low_pool_ptr\n                                     else None)\"\n  by (clarsimp simp: pool_for_asid_def s0_internal_def arch_state0_def)\n\nlemma asid_pools_of_s0:\n  \"asid_pools_of s0_internal = [Low_pool_ptr \\<mapsto> Low_pool', High_pool_ptr \\<mapsto> High_pool']\"\n  by (auto simp: asid_pools_of_ko_at obj_at_def s0_internal_def opt_map_def kh0_def kh0_obj_def\n          split: option.splits)\n\nlemma pts_of_s0:\n  \"pts_of s0_internal = [Low_pd_ptr \\<mapsto> Low_pd',\n                         High_pd_ptr \\<mapsto> High_pd',\n                         Low_pt_ptr \\<mapsto> Low_pt',\n                         High_pt_ptr \\<mapsto> High_pt',\n                         riscv_global_pt_ptr \\<mapsto> init_global_pt']\"\n  by (auto simp: opt_map_def s0_internal_def kh0_def kh0_obj_def\n          split: option.splits if_splits)+\n\n\nlemma ptes_of_s0_PageTablePTE:\n  \"\\<lbrakk> ptes_of s0_internal ptr = Some pte; is_PageTablePTE pte \\<rbrakk>\n     \\<Longrightarrow> table_base ptr = Low_pd_ptr \\<and> pte = PageTablePTE (ppn_from_addr (addrFromPPtr Low_pt_ptr)) {}\n       \\<or> table_base ptr = High_pd_ptr \\<and> pte = PageTablePTE (ppn_from_addr (addrFromPPtr High_pt_ptr)) {}\"\n  by (auto simp: ptes_of_def pts_of_s0 obind_def kh0_obj_def split: option.splits if_splits)\n\nlemma Low_pt_is_aligned[simp]:\n  \"is_aligned Low_pt_ptr pt_bits\"\n  by (clarsimp simp: s0_ptr_defs pt_bits_def table_size_def ptTranslationBits_def pte_bits_def word_size_bits_def is_aligned_def)\n\nlemma High_pt_is_aligned[simp]:\n  \"is_aligned High_pt_ptr pt_bits\"\n  by (clarsimp simp: s0_ptr_defs pt_bits_def table_size_def ptTranslationBits_def pte_bits_def word_size_bits_def is_aligned_def)\n\nlemma Low_pd_is_aligned[simp]:\n  \"is_aligned Low_pd_ptr pt_bits\"\n  by (clarsimp simp: s0_ptr_defs pt_bits_def table_size_def ptTranslationBits_def pte_bits_def word_size_bits_def is_aligned_def)\n\nlemma High_pd_is_aligned[simp]:\n  \"is_aligned High_pd_ptr pt_bits\"\n  by (clarsimp simp: s0_ptr_defs pt_bits_def table_size_def ptTranslationBits_def pte_bits_def word_size_bits_def is_aligned_def)\n\nlemma shared_page_ptr_is_aligned[simp]:\n  \"is_aligned shared_page_ptr_virt pt_bits\"\n  by (clarsimp simp: s0_ptr_defs pt_bits_def table_size_def ptTranslationBits_def pte_bits_def word_size_bits_def is_aligned_def)\n\nlemma vs_lookup_s0_SomeD:\n  \"vs_lookup_table lvl asid vref s0_internal = Some (lvl', p)\n   \\<Longrightarrow> (asid_high_bits_of asid = asid_high_bits_of High_asid \\<and> lvl' = asid_pool_level \\<and> p = High_pool_ptr\n      \\<or> asid_high_bits_of asid = asid_high_bits_of Low_asid \\<and> lvl' = asid_pool_level \\<and> p = Low_pool_ptr\n      \\<or> asid = High_asid \\<and> lvl' = max_pt_level \\<and> p = High_pd_ptr\n      \\<or> asid = Low_asid \\<and> lvl' = max_pt_level \\<and> p = Low_pd_ptr\n      \\<or> asid = High_asid \\<and> lvl' = max_pt_level - 1 \\<and> p = High_pt_ptr\n      \\<or> asid = Low_asid \\<and> lvl' = max_pt_level - 1 \\<and> p = Low_pt_ptr)\"\n  apply (clarsimp simp: vs_lookup_table_def obind_def split: option.splits if_splits)\n   apply (clarsimp simp: pool_for_asid_s0 split: if_splits)\n  apply (case_tac \"lvl = max_pt_level\")\n   apply (clarsimp simp: asid_pools_of_s0 pool_for_asid_s0 asid_high_low vspace_for_pool_def\n                  split: if_splits)\n  apply (case_tac \"lvl = max_pt_level - 1\")\n   apply (clarsimp simp: pt_walk.simps split: if_splits)\n    apply (drule (1) ptes_of_s0_PageTablePTE)\n    apply (auto simp: pptr_from_pte_def ptrFromPAddr_addr_from_ppn' ptes_of_def asid_high_low\n                      kh0_obj_def pts_of_s0 pool_for_asid_s0 asid_pools_of_s0 vspace_for_pool_def\n               split: if_splits)[2]\n  apply (clarsimp simp: pt_walk.simps)\n  apply (clarsimp split: if_splits)\n   apply (drule (1) ptes_of_s0_PageTablePTE)\n   apply (erule disjE; clarsimp)\n  by (clarsimp simp: pptr_from_pte_def ptrFromPAddr_addr_from_ppn' kh0_obj_def\n                     pt_walk.simps ptes_of_def pts_of_s0 asid_high_low\n                     pool_for_asid_s0 asid_pools_of_s0 vspace_for_pool_def\n              split: if_splits)+\n\nlemma pt_bits_left_max_minus_1_pageBitsForSize:\n  \"pt_bits_left (max_pt_level - 1) = pageBitsForSize RISCVLargePage\"\n  apply (clarsimp simp: pt_bits_left_def max_pt_level_def2)\n  done\n\nlemma Sys1_pas_refined:\n  \"pas_refined Sys1PAS s0_internal\"\n  apply (clarsimp simp: pas_refined_def)\n  apply (intro conjI)\n       apply (simp add: Sys1_pas_wellformed)\n      apply (clarsimp simp: irq_map_wellformed_aux_def s0_internal_def Sys1AgentMap_def Sys1PAS_def)\n      apply (clarsimp simp: s0_ptr_defs ptr_range_def)\n      apply word_bitwise\n     apply (clarsimp simp: tcb_domain_map_wellformed_aux_def minBound_word High_domain_def Low_domain_def\n                           Sys1PAS_def Sys1AgentMap_def default_domain_def)\n    apply (clarsimp simp: auth_graph_map_def Sys1PAS_def state_objs_to_policy_def state_bits_to_policy_def)\n    apply (erule state_bits_to_policyp.cases; clarsimp)\n          apply (drule s0_caps_of_state, clarsimp)\n          apply (simp add: Sys1AuthGraph_def)\n          apply (elim disjE; clarsimp simp: Sys1AgentMap_simps cap_auth_conferred_def ptr_range_def\n                                            arch_cap_auth_conferred_def vspace_cap_rights_to_auth_def\n                                            vm_read_write_def vm_read_only_def cap_rights_to_auth_def)\n         apply (drule s0_caps_of_state, clarsimp)\n         apply (elim disjE, simp_all)[1]\n        apply (clarsimp simp: state_refs_of_def thread_st_auth_def tcb_states_of_state_s0\n                              Sys1AuthGraph_def Sys1AgentMap_simps split: if_splits)\n       apply (clarsimp simp: state_refs_of_def thread_st_auth_def thread_bounds_of_state_s0)\n      apply (simp add: s0_internal_def) (* this is OK because cdt is empty..*)\n     apply (simp add: s0_internal_def) (* this is OK because cdt is empty..*)\n    apply (clarsimp simp: state_vrefs_def)\n    apply (drule vs_lookup_s0_SomeD)\n    apply (elim disjE; clarsimp)\n         apply ((clarsimp simp: s0_internal_def kh0_obj_def opt_map_def vs_refs_aux_def\n                                vm_read_only_def vspace_cap_rights_to_auth_def pte_ref2_def\n                                Sys1AuthGraph_def Sys1AgentMap_simps graph_of_def ptrFromPAddr_addr_from_ppn'\n                                shared_page_ptr_phys_def pt_bits_left_max_minus_1_pageBitsForSize\n                         dest!: kh0_SomeD split: option.splits if_splits)+)[6]\n   apply (rule subsetI, clarsimp)\n   apply (erule state_asids_to_policy_aux.cases)\n     apply (drule s0_caps_of_state, clarsimp)\n     apply (fastforce simp: Sys1AuthGraph_def Sys1PAS_def Sys1ASIDMap_def Sys1AgentMap_def\n                            Low_asid_def High_asid_def Silc_asid_def\n                            asid_low_bits_def asid_high_bits_of_def)\n    apply (clarsimp simp: state_vrefs_def)\n    apply (drule vs_lookup_s0_SomeD)\n    apply (clarsimp simp: vs_refs_aux_def s0_internal_def arch_state0_def kh0_def kh0_obj_def\n                          Sys1PAS_def Sys1ASIDMap_def Sys1AgentMap_simps Sys1AuthGraph_def\n                          opt_map_def graph_of_def split: if_splits)\n   apply (clarsimp simp: Sys1PAS_def Sys1ASIDMap_def Sys1AgentMap_simps Sys1AuthGraph_def\n                         s0_internal_def arch_state0_def split: if_splits)\n  apply (fastforce elim: state_irqs_to_policy_aux.cases dest: s0_caps_of_state)\n  done\n\nlemma Sys1_pas_cur_domain:\n  \"pas_cur_domain Sys1PAS s0_internal\"\n  by (simp add: s0_internal_def exst0_def Sys1PAS_def)\n\nlemma Sys1_current_subject_idemp:\n  \"Sys1PAS\\<lparr>pasSubject := the_elem (pasDomainAbs Sys1PAS (cur_domain s0_internal))\\<rparr> = Sys1PAS\"\n  by (simp add: Sys1PAS_def s0_internal_def exst0_def)\n\nlemma pasMaySendIrqs_Sys1PAS[simp]:\n  \"pasMaySendIrqs Sys1PAS = False\"\n  by(auto simp: Sys1PAS_def)\n\nlemma Sys1_pas_domains_distinct:\n  \"pas_domains_distinct Sys1PAS\"\n  by (clarsimp simp: Sys1PAS_def pas_domains_distinct_def)\n\nlemma Sys1_pas_wellformed_noninterference:\n  \"pas_wellformed_noninterference Sys1PAS\"\n  apply (simp add: pas_wellformed_noninterference_def)\n  apply (intro conjI ballI allI)\n    apply (blast intro: Sys1_wellformed)\n   apply (clarsimp simp: Sys1PAS_def policy_wellformed_def Sys1AuthGraph_def)\n  apply (rule Sys1_pas_domains_distinct)\n  done\n\nlemma Sys1AgentMap_shared_page_ptr:\n  \"Sys1AgentMap shared_page_ptr_virt = partition_label Low\"\n  by (clarsimp simp: Sys1AgentMap_def s0_ptr_defs ptr_range_def bit_simps)\n\nlemma silc_inv_s0:\n  \"silc_inv Sys1PAS s0_internal s0_internal\"\n  apply (clarsimp simp: silc_inv_def)\n  apply (rule conjI, simp add: Sys1PAS_def)\n  apply (rule conjI)\n   apply (clarsimp simp: Sys1PAS_def Sys1AgentMap_def s0_internal_def kh0_def obj_at_def kh0_obj_def\n                         is_cap_table_def Silc_caps_well_formed split: if_split_asm)\n  apply (rule conjI)\n   apply (clarsimp simp: Sys1PAS_def Sys1AuthGraph_def)\n  apply (rule conjI)\n   apply clarsimp\n   apply (rule_tac x=Silc_cnode_ptr in exI)\n   apply (rule conjI)\n    apply (subgoal_tac \"(Silc_cnode_ptr,the_nat_to_bl_10 318) \\<in> slots_holding_overlapping_caps cap s0_internal\n                      \\<or> (Silc_cnode_ptr, the_nat_to_bl_10 5) \\<in> slots_holding_overlapping_caps cap s0_internal\")\n     apply fastforce\n    apply clarsimp\n    apply (clarsimp simp: slots_holding_overlapping_caps_def2)\n    apply (case_tac \"cap = NullCap\")\n     apply clarsimp\n     apply (simp add: cte_wp_at_cases s0_internal_def kh0_def kh0_obj_def)\n     apply (case_tac a, clarsimp)\n     apply (clarsimp split: if_splits)\n            apply ((clarsimp simp: intra_label_cap_def cte_wp_at_cases tcb_cap_cases_def\n                                   cap_points_to_label_def split: if_split_asm)+)[8]\n    apply (clarsimp simp: intra_label_cap_def cap_points_to_label_def)\n    apply (drule cte_wp_at_caps_of_state' s0_caps_of_state)+\n    apply ((erule disjE |\n          clarsimp simp: Sys1PAS_def Sys1AgentMap_simps\n              the_nat_to_bl_def nat_to_bl_def ctes_wp_at_def cte_wp_at_cases\n              s0_internal_def kh0_def kh0_obj_def Silc_caps_well_formed obj_refs_def\n         | simp add: Silc_caps_def)+)[1]\n  apply (clarsimp simp: Sys1PAS_def Sys1AgentMap_def)\n  apply (intro conjI)\n  apply (clarsimp simp: all_children_def s0_internal_def silc_dom_equiv_def equiv_for_refl)\n  apply (clarsimp simp: all_children_def s0_internal_def silc_dom_equiv_def equiv_for_refl)\n  apply (clarsimp simp: Invariants_AI.cte_wp_at_caps_of_state )\n  by (auto simp:is_transferable.simps dest:s0_caps_of_state)\n\n\nlemma only_timer_irq_s0:\n  \"only_timer_irq timer_irq s0_internal\"\n  apply (clarsimp simp: only_timer_irq_def s0_internal_def irq_is_recurring_def is_irq_at_def\n                        irq_at_def Let_def irq_oracle_def machine_state0_def timer_irq_def)\n  apply presburger\n  done\n\nlemma domain_sep_inv_s0:\n  \"domain_sep_inv False s0_internal s0_internal\"\n  apply (clarsimp simp: domain_sep_inv_def)\n  apply (force dest: cte_wp_at_caps_of_state' s0_caps_of_state\n         | rule conjI allI | clarsimp simp: s0_internal_def)+\n  done\n\nlemma only_timer_irq_inv_s0:\n  \"only_timer_irq_inv timer_irq s0_internal s0_internal\"\n  by (simp add: only_timer_irq_inv_def only_timer_irq_s0 domain_sep_inv_s0)\n\nlemma Sys1_guarded_pas_domain:\n  \"guarded_pas_domain Sys1PAS s0_internal\"\n  by (clarsimp simp: guarded_pas_domain_def Sys1PAS_def s0_internal_def exst0_def Sys1AgentMap_simps)\n\nlemma s0_valid_domain_list:\n  \"valid_domain_list s0_internal\"\n  by (clarsimp simp: valid_domain_list_2_def s0_internal_def exst0_def)\n\ndefinition\n  \"s0 \\<equiv> ((if ct_idle s0_internal then idle_context s0_internal else s0_context,s0_internal),KernelExit)\"\n\n\nsubsubsection \\<open>einvs\\<close>\n\nlemma well_formed_cnode_n_s0_caps[simp]:\n  \"well_formed_cnode_n 10 High_caps\"\n  \"well_formed_cnode_n 10 Low_caps\"\n  \"well_formed_cnode_n 10 Silc_caps\"\n  \"\\<not> well_formed_cnode_n 10 [[] \\<mapsto> NullCap]\"\n  apply (simp add: High_caps_well_formed Low_caps_well_formed Silc_caps_well_formed)+\n  apply (fastforce simp: well_formed_cnode_n_def dest: eqset_imp_iff[where x=\"[]\"])\n  done\n\nlemma valid_caps_s0[simp]:\n  \"s0_internal \\<turnstile> ThreadCap Low_tcb_ptr\"\n  \"s0_internal \\<turnstile> ThreadCap High_tcb_ptr\"\n  \"s0_internal \\<turnstile> CNodeCap Low_cnode_ptr 10 (the_nat_to_bl_10 2)\"\n  \"s0_internal \\<turnstile> CNodeCap High_cnode_ptr 10 (the_nat_to_bl_10 2)\"\n  \"s0_internal \\<turnstile> CNodeCap Silc_cnode_ptr 10 (the_nat_to_bl_10 2)\"\n  \"s0_internal \\<turnstile> ArchObjectCap (ASIDPoolCap Low_pool_ptr Low_asid)\"\n  \"s0_internal \\<turnstile> ArchObjectCap (ASIDPoolCap High_pool_ptr High_asid)\"\n  \"s0_internal \\<turnstile> ArchObjectCap (PageTableCap Low_pd_ptr (Some (Low_asid,0)))\"\n  \"s0_internal \\<turnstile> ArchObjectCap (PageTableCap High_pd_ptr (Some (High_asid,0)))\"\n  \"s0_internal \\<turnstile> ArchObjectCap (PageTableCap Low_pt_ptr (Some (Low_asid,0)))\"\n  \"s0_internal \\<turnstile> ArchObjectCap (PageTableCap High_pt_ptr (Some (High_asid,0)))\"\n  \"s0_internal \\<turnstile> ArchObjectCap (FrameCap shared_page_ptr_virt vm_read_write RISCVLargePage False (Some (Low_asid,0)))\"\n  \"s0_internal \\<turnstile> ArchObjectCap (FrameCap shared_page_ptr_virt vm_read_only RISCVLargePage False (Some (High_asid,0)))\"\n  \"s0_internal \\<turnstile> ArchObjectCap (FrameCap shared_page_ptr_virt vm_read_only RISCVLargePage False (Some (Silc_asid,0)))\"\n  \"s0_internal \\<turnstile> NotificationCap ntfn_ptr 0 {AllowWrite}\"\n  \"s0_internal \\<turnstile> NotificationCap ntfn_ptr 0 {AllowRead}\"\n  \"s0_internal \\<turnstile> ReplyCap Low_tcb_ptr True {AllowGrant,AllowWrite}\"\n  \"s0_internal \\<turnstile> ReplyCap High_tcb_ptr True {AllowGrant,AllowWrite}\"\n  by (auto simp: s0_internal_def s0_ptr_defs kh0_def kh0_obj_def bit_simps word_bits_def\n                 valid_cap_def cap_aligned_def is_aligned_def obj_at_def cte_level_bits_def\n                 is_ntfn_def is_tcb_def is_cap_table_def a_type_def the_nat_to_bl_def nat_to_bl_def\n                 Low_asid_def High_asid_def Silc_asid_def asid_low_bits_def asid_bits_def\n                 wellformed_mapdata_def valid_vm_rights_def vmsz_aligned_def)\n\nlemma valid_obj_s0[simp]:\n  \"valid_obj Low_cnode_ptr       Low_cnode      s0_internal\"\n  \"valid_obj High_cnode_ptr      High_cnode     s0_internal\"\n  \"valid_obj High_pool_ptr       High_pool      s0_internal\"\n  \"valid_obj Low_pool_ptr        Low_pool       s0_internal\"\n  \"valid_obj Silc_cnode_ptr      Silc_cnode     s0_internal\"\n  \"valid_obj ntfn_ptr            ntfn           s0_internal\"\n  \"valid_obj irq_cnode_ptr       irq_cnode      s0_internal\"\n  \"valid_obj Low_pd_ptr          Low_pd         s0_internal\"\n  \"valid_obj High_pd_ptr         High_pd        s0_internal\"\n  \"valid_obj Low_pt_ptr          Low_pt         s0_internal\"\n  \"valid_obj High_pt_ptr         High_pt        s0_internal\"\n  \"valid_obj Low_tcb_ptr         Low_tcb        s0_internal\"\n  \"valid_obj High_tcb_ptr        High_tcb       s0_internal\"\n  \"valid_obj idle_tcb_ptr        idle_tcb       s0_internal\"\n  \"valid_obj riscv_global_pt_ptr init_global_pt s0_internal\"\n  \"valid_obj shared_page_ptr_virt shared_page s0_internal\"\n                 apply (simp_all add: valid_obj_def kh0_obj_def)\n              apply (simp add: valid_cs_def Low_caps_ran High_caps_ran Silc_caps_ran\n                               valid_cs_size_def word_bits_def cte_level_bits_def)+\n           apply (simp add: valid_ntfn_def obj_at_def s0_internal_def kh0_def High_tcb_def is_tcb_def)\n          apply (simp add: valid_cs_def valid_cs_size_def word_bits_def\n                           cte_level_bits_def well_formed_cnode_n_def)\n         apply (clarsimp simp: valid_tcb_def tcb_cap_cases_def valid_tcb_state_def valid_arch_tcb_def\n                               is_valid_vtable_root_def is_master_reply_cap_def is_ntfn_def obj_at_def\n                               wellformed_pte_def valid_vm_rights_def vm_kernel_only_def\n                | fastforce simp: s0_internal_def kh0_def kh0_obj_def)+\n  done\n\nlemma valid_objs_s0:\n  \"valid_objs s0_internal\"\n  apply (clarsimp simp: valid_objs_def)\n  apply (subst (asm) s0_internal_def, clarsimp)\n  apply (drule kh0_SomeD)\n  apply (elim disjE; clarsimp)\n  apply (fastforce simp: valid_obj_def valid_cs_def valid_cs_size_def\n                         cte_level_bits_def word_bits_def well_formed_cnode_n_def)\n  done\n\nlemma pspace_aligned_s0:\n  \"pspace_aligned s0_internal\"\n  apply (clarsimp simp: pspace_aligned_def s0_internal_def)\n  apply (drule kh0_SomeD)\n  apply (auto simp: cte_level_bits_def irq_node_offs_range_def\n                    is_aligned_def s0_ptr_defs kh0_obj_def bit_simps)\n  done\n\nlemma pspace_distinct_s0:\n  \"pspace_distinct s0_internal\"\n  apply (clarsimp simp: pspace_distinct_def s0_internal_def)\n  apply (drule kh0_SomeD)+\n  apply (case_tac \"x \\<in> irq_node_offs_range \\<and> y \\<in> irq_node_offs_range\")\n   apply clarsimp\n   apply (drule irq_node_offs_range_correct)+\n   apply clarsimp\n   apply (clarsimp simp: s0_ptr_defs cte_level_bits_def)\n   apply word_bitwise\n   apply auto[1]\n  apply (elim disjE)\n  (* slow *)\n  by (simp | clarsimp simp: kh0_obj_def cte_level_bits_def s0_ptr_defs pte_bits_def bit_simps\n           | fastforce\n           | clarsimp simp: irq_node_offs_range_def s0_ptr_defs,\n             drule_tac x=\"0x1F\" in word_plus_strict_mono_right, simp, simp add: add.commute,\n             drule(1) notE[rotated, OF less_trans, OF _ _ leD, rotated 2]\n           | drule(1) notE[rotated, OF le_less_trans, OF _ _ leD, rotated 2], simp, assumption)+\n\nlemma valid_pspace_s0[simp]:\n  \"valid_pspace s0_internal\"\n  apply (simp add: valid_pspace_def pspace_distinct_s0 pspace_aligned_s0 valid_objs_s0)\n  apply (rule conjI)\n   apply (clarsimp simp: if_live_then_nonz_cap_def)\n   apply (subst (asm) s0_internal_def)\n   apply (clarsimp simp: ex_nonz_cap_to_def live_def hyp_live_def obj_at_def kh0_def kh0_obj_def\n                  split: if_splits)\n     apply (rule_tac x=\"High_cnode_ptr\" in exI)\n     apply (rule_tac x=\"the_nat_to_bl_10 1\" in exI)\n     apply (force simp: s0_internal_def kh0_def kh0_obj_def High_caps_def\n                        cte_wp_at_cases well_formed_cnode_n_def)\n    apply (rule_tac x=\"Low_cnode_ptr\" in exI)\n    apply (rule_tac x=\"the_nat_to_bl_10 1\" in exI)\n    apply (force simp: s0_internal_def kh0_def kh0_obj_def Low_caps_def\n                       cte_wp_at_cases well_formed_cnode_n_def)\n   apply (rule_tac x=\"High_cnode_ptr\" in exI)\n   apply (rule_tac x=\"the_nat_to_bl_10 318\" in exI)\n   apply (force simp: s0_internal_def kh0_def kh0_obj_def High_caps_def\n                      cte_wp_at_cases well_formed_cnode_n_def)\n  apply (intro conjI)\n    apply (force dest: s0_caps_of_state simp: cte_wp_at_caps_of_state zombies_final_def is_zombie_def)\n   apply (clarsimp simp: sym_refs_def state_refs_of_def state_hyp_refs_of_def\n                         refs_of_def s0_internal_def kh0_def kh0_obj_def)\n  apply (clarsimp simp: sym_refs_def state_hyp_refs_of_def s0_internal_def kh0_def)\n  done\n\nlemma descendants_s0[simp]:\n  \"descendants_of (a, b) (cdt s0_internal) = {}\"\n  apply (rule set_eqI)\n  apply clarsimp\n  apply (drule descendants_of_NoneD[rotated])\n   apply (simp add: s0_internal_def)+\n  done\n\nlemma valid_mdb_s0[simp]:\n  \"valid_mdb s0_internal\"\n  apply (simp add: valid_mdb_def reply_mdb_def)\n  apply (intro conjI)\n            apply (clarsimp simp: mdb_cte_at_def s0_internal_def)\n           apply (force dest: s0_caps_of_state simp: untyped_mdb_def)\n          apply (clarsimp simp: descendants_inc_def)\n         apply (clarsimp simp: no_mloop_def s0_internal_def cdt_parent_defs)\n        apply (clarsimp simp: untyped_inc_def)\n        apply (drule s0_caps_of_state)+\n        apply ((simp | erule disjE)+)[1]\n       apply (force dest: s0_caps_of_state simp: ut_revocable_def)\n      apply (force dest: s0_caps_of_state simp: irq_revocable_def)\n     apply (clarsimp simp: reply_master_revocable_def)\n     apply (drule s0_caps_of_state)\n     apply ((simp add: is_master_reply_cap_def s0_internal_def s0_ptr_defs | erule disjE)+)[1]\n    apply (force dest: s0_caps_of_state simp: reply_caps_mdb_def)\n   apply (clarsimp simp: reply_masters_mdb_def)\n   apply (simp add: s0_internal_def)\n  apply (clarsimp simp: valid_arch_mdb_def)\n  done\n\nlemma valid_ioc_s0[simp]:\n  \"valid_ioc s0_internal\"\n  by (clarsimp simp: cte_wp_at_cases valid_ioc_def s0_internal_def kh0_def kh0_obj_def)\n\nlemma valid_idle_s0[simp]:\n  \"valid_idle s0_internal\"\n  by (clarsimp simp: valid_idle_def valid_arch_idle_def  pred_tcb_at_def obj_at_def\n                     idle_thread_ptr_def idle_tcb_def kh0_def s0_ptr_defs s0_internal_def)\n\nlemma only_idle_s0[simp]:\n  \"only_idle s0_internal\"\n  apply (clarsimp simp: only_idle_def st_tcb_at_tcb_states_of_state_eq\n                        identity_eq[symmetric] tcb_states_of_state_s0)\n  apply (simp add: s0_ptr_defs s0_internal_def)\n  done\n\nlemma if_unsafe_then_cap_s0[simp]:\n  \"if_unsafe_then_cap s0_internal\"\n  apply (clarsimp simp: if_unsafe_then_cap_def ex_cte_cap_wp_to_def)\n  apply (drule s0_caps_of_state)\n  apply (case_tac \"a=Low_cnode_ptr\")\n   apply (rule_tac x=Low_tcb_ptr in exI, rule_tac x=\"tcb_cnode_index 0\" in exI)\n   apply (fastforce simp: cte_wp_at_cases s0_internal_def kh0_def kh0_obj_def)\n  apply (case_tac \"a=High_cnode_ptr\")\n   apply (rule_tac x=High_tcb_ptr in exI, rule_tac x=\"tcb_cnode_index 0\" in exI)\n   apply (fastforce simp: cte_wp_at_cases s0_internal_def kh0_def kh0_obj_def)\n  apply (case_tac \"a=Low_tcb_ptr\")\n   apply (rule_tac x=Low_cnode_ptr in exI, rule_tac x=\"the_nat_to_bl_10 1\" in exI)\n   apply (fastforce simp: s0_internal_def kh0_def kh0_obj_def Low_caps_def\n                          cte_wp_at_cases well_formed_cnode_n_def)\n  apply (case_tac \"a=High_tcb_ptr\")\n   apply (rule_tac x=High_cnode_ptr in exI, rule_tac x=\"the_nat_to_bl_10 1\" in exI)\n   apply (fastforce simp: s0_internal_def kh0_def kh0_obj_def High_caps_def\n                          cte_wp_at_cases well_formed_cnode_n_def)\n  apply (rule_tac x=Silc_cnode_ptr in exI, rule_tac x=\"the_nat_to_bl_10 2\" in exI)\n  apply (fastforce simp: s0_internal_def kh0_def kh0_obj_def Silc_caps_def\n                         cte_wp_at_cases well_formed_cnode_n_def)\n  done\n\nlemma valid_reply_caps_s0[simp]:\n  \"valid_reply_caps s0_internal\"\n  apply (clarsimp simp: valid_reply_caps_def)\n  apply (rule conjI)\n   apply (force dest: s0_caps_of_state\n                simp: cte_wp_at_caps_of_state has_reply_cap_def is_reply_cap_to_def)\n  apply (clarsimp simp: unique_reply_caps_def)\n  apply (drule s0_caps_of_state)+\n  apply (erule disjE | simp add: is_reply_cap_def)+\n  done\n\nlemma valid_reply_masters_s0[simp]:\n  \"valid_reply_masters s0_internal\"\n  apply (clarsimp simp: valid_reply_masters_def)\n  apply (force dest: s0_caps_of_state simp: cte_wp_at_caps_of_state is_master_reply_cap_to_def)\n  done\n\nlemma valid_global_refs_s0[simp]:\n  \"valid_global_refs s0_internal\"\n  apply (clarsimp simp: valid_global_refs_def valid_refs_def cte_wp_at_caps_of_state)\n  apply (drule s0_caps_of_state)\n  apply (clarsimp simp: global_refs_def s0_internal_def arch_state0_def)\n  apply (erule disjE | simp add: cap_range_def\n                     | clarsimp simp: irq_node_offs_distinct[symmetric]\n                     | simp only: s0_ptr_defs, force)+\n  done\n\nlemma valid_arch_state_s0[simp]:\n  \"valid_arch_state s0_internal\"\n  apply (clarsimp simp: valid_arch_state_def s0_internal_def arch_state0_def)\n  apply (intro conjI)\n    apply (auto simp: valid_asid_table_def kh0_def kh0_obj_def opt_map_def split: option.splits)[1]\n   apply (fastforce simp: valid_global_arch_objs_def obj_at_def kh0_def a_type_def\n                         init_global_pt_def max_pt_level_not_asid_pool_level[symmetric])\n  apply (clarsimp simp: valid_global_tables_def pt_walk.simps obind_def)\n  apply (fastforce dest: pt_walk_max_level\n                   simp: obind_def opt_map_def asid_pool_level_eq geq_max_pt_level pte_of_def kh0_def\n                         kh0_obj_def pte_rights_of_def\n                  split: if_splits)\n  done\n\nlemma valid_irq_node_s0[simp]:\n  \"valid_irq_node s0_internal\"\n  apply (clarsimp simp: valid_irq_node_def)\n  apply (rule conjI)\n   apply (simp add: s0_internal_def)\n   apply (rule injI)\n   apply simp\n   apply (rule ccontr)\n   apply (rule_tac bnd=\"0x40\" and 'a=64 in shift_distinct_helper[rotated 3])\n        apply assumption\n       apply simp\n      apply simp\n     apply (rule ucast_less[where 'b=6, simplified])\n     apply simp\n    apply (rule ucast_less[where 'b=6, simplified])\n    apply simp\n   apply (rule notI)\n   apply (drule ucast_up_inj)\n    apply simp\n   apply simp\n  apply (clarsimp simp: obj_at_def s0_internal_def)\n  apply (force simp: kh0_def is_cap_table_def well_formed_cnode_n_def dom_empty_cnode)\n  done\n\nlemma valid_irq_handlers_s0[simp]:\n  \"valid_irq_handlers s0_internal\"\n  apply (clarsimp simp: valid_irq_handlers_def ran_def)\n  apply (force dest: s0_caps_of_state)\n  done\n\nlemma valid_irq_state_s0[simp]:\n  \"valid_irq_states s0_internal\"\n  by (clarsimp simp: valid_irq_states_def valid_irq_masks_def s0_internal_def machine_state0_def)\n\nlemma valid_machine_state_s0[simp]:\n  \"valid_machine_state s0_internal\"\n  by (clarsimp simp: valid_machine_state_def s0_internal_def const_def\n                     machine_state0_def in_user_frame_def obj_at_def)\n\nlemma valid_arch_objs_s0[simp]:\n  \"valid_vspace_objs s0_internal\"\n  apply (clarsimp simp: valid_vspace_objs_def obj_at_def)\n  apply (drule vs_lookup_s0_SomeD)\n  apply (auto simp: aobjs_of_Some kh_s0_def kh0_obj_def data_at_def obj_at_def\n                    ptrFromPAddr_addr_from_ppn' vmpage_size_of_level_def max_pt_level_def2\n                    shared_page_ptr_phys_def)\n  done\n\nlemma valid_vs_lookup_s0_internal:\n  \"valid_vs_lookup s0_internal\"\n  supply pt_simps = pt_slot_offset_def pt_bits_left_def pt_index_def max_pt_level_def2\n  supply user_region_simps = user_region_def canonical_user_def\n  supply caps_of_state_simps = caps_of_state_def get_cap_def gets_def get_def get_object_def\n                               assert_def assert_opt_def fail_def return_def bind_def\n  apply (clarsimp simp: valid_vs_lookup_def vs_lookup_target_def vs_lookup_slot_def split: if_splits)\n   \\<comment> \\<open>asid pool level\\<close>\n   apply (drule vs_lookup_level)\n   apply (clarsimp simp: pool_for_asid_vs_lookup pool_for_asid_s0 asid_pools_of_s0\n                         vspace_for_pool_def user_region_def vref_for_level_asid_pool\n                  dest!: asid_high_low split: if_splits)\n    \\<comment> \\<open>High asid\\<close>\n    apply (rule conjI, clarsimp simp: High_asid_def asid_low_bits_def)\n    apply (rule_tac x=High_cnode_ptr in exI)\n    apply (rule_tac x=\"(the_nat_to_bl_10 3)\" in exI)\n    apply (fastforce simp: High_cnode_def High_caps_def caps_of_state_def get_cap_def get_object_def\n                           gets_def get_def assert_def assert_opt_def fail_def return_def bind_def\n                           s0_internal_def kh0_def well_formed_cnode_n_def)\n   \\<comment> \\<open>Low asid\\<close>\n   apply (rule conjI, clarsimp simp: Low_asid_def asid_low_bits_def)\n   apply (rule_tac x=Low_cnode_ptr in exI)\n   apply (rule_tac x=\"(the_nat_to_bl_10 3)\" in exI)\n   apply (fastforce simp: Low_cnode_def Low_caps_def caps_of_state_def get_cap_def get_object_def\n                          gets_def get_def assert_def assert_opt_def fail_def return_def bind_def\n                          s0_internal_def kh0_def well_formed_cnode_n_def)\n  \\<comment> \\<open>below asid pool level\\<close>\n  apply (clarsimp simp: vs_lookup_table_def split: if_splits)\n  apply (clarsimp simp: pt_walk.simps)\n  apply (case_tac \"bot_level < max_pt_level\"; clarsimp)\n\n   prefer 2\n   \\<comment> \\<open>bot level = max pt level\\<close>\n\n   apply (clarsimp simp: pool_for_asid_s0 vspace_for_pool_def asid_pools_of_s0\n                  dest!: asid_high_low split: if_splits)\n    \\<comment> \\<open>High asid\\<close>\n    apply (rule conjI, clarsimp simp: High_asid_def asid_low_bits_def)\n    apply (rule_tac x=High_cnode_ptr in exI)\n    apply (rule_tac x=\"(the_nat_to_bl_10 6)\" in exI)\n    apply (rule_tac x=\"ArchObjectCap (PageTableCap High_pt_ptr (Some (High_asid,0)))\" in exI)\n    apply (subst (asm) s0_internal_def)\n    apply (clarsimp simp: in_omonad ptes_of_def High_pd_def ptrFromPAddr_addr_from_ppn'\n                   dest!: kh0_SomeD split: if_splits)\n     apply (intro conjI)\n      apply (fastforce simp: High_cnode_def High_caps_def caps_of_state_simps\n                             s0_internal_def kh0_def well_formed_cnode_n_def)\n     apply (clarsimp simp: vref_for_level_def mask_def pt_simps user_region_simps bit_simps s0_ptr_defs)\n     apply (word_bitwise, fastforce)\n    apply (clarsimp simp: kh0_obj_def mask_def pt_simps user_region_simps bit_simps s0_ptr_defs)\n    apply (rule FalseE, word_bitwise, fastforce simp: elf_index_value)\n   \\<comment> \\<open>Low asid\\<close>\n   apply (rule conjI, clarsimp simp: Low_asid_def asid_low_bits_def)\n   apply (rule_tac x=Low_cnode_ptr in exI)\n   apply (rule_tac x=\"(the_nat_to_bl_10 6)\" in exI)\n   apply (rule_tac x=\"ArchObjectCap (PageTableCap Low_pt_ptr (Some (Low_asid,0)))\" in exI)\n   apply (subst (asm) s0_internal_def)\n   apply (clarsimp simp: in_omonad ptes_of_def Low_pd_def ptrFromPAddr_addr_from_ppn'\n                  dest!: kh0_SomeD split: if_splits)\n    apply (intro conjI)\n     apply (fastforce simp: Low_cnode_def Low_caps_def caps_of_state_simps\n                            s0_internal_def kh0_def well_formed_cnode_n_def)\n    apply (clarsimp simp: vref_for_level_def mask_def pt_simps user_region_simps bit_simps s0_ptr_defs)\n    apply (word_bitwise, fastforce)\n   apply (clarsimp simp: kh0_obj_def mask_def pt_simps user_region_simps bit_simps s0_ptr_defs)\n   apply (rule FalseE, word_bitwise, fastforce simp: elf_index_value)\n  \\<comment> \\<open>bot level < max pt level\\<close>\n  apply (clarsimp simp: pool_for_asid_s0 vspace_for_pool_def asid_pools_of_s0\n                 dest!: asid_high_low split: if_splits)\n     \\<comment> \\<open>High asid\\<close>\n     apply (subst (asm) ptes_of_def)\n     apply (clarsimp simp: pts_of_s0)\n     apply (clarsimp simp: in_omonad kh0_obj_def pptr_from_pte_def ptrFromPAddr_addr_from_ppn'\n                    split: if_splits)\n     apply (rule conjI, clarsimp simp: High_asid_def asid_low_bits_def)\n     apply (prop_tac \"pt_walk (max_pt_level - 1) bot_level High_pt_ptr vref (ptes_of s0_internal) =\n                      Some (max_pt_level - 1, High_pt_ptr)\")\n      apply (clarsimp simp: pt_walk.simps)\n      apply (clarsimp simp: ptes_of_def pts_of_s0 in_omonad split: if_splits)\n     apply (clarsimp simp: ptes_of_def pts_of_s0 shared_page_ptr_phys_def ptrFromPAddr_addr_from_ppn'\n                    split: if_splits)\n     apply (rule_tac x=High_cnode_ptr in exI)\n     apply (rule_tac x=\"the_nat_to_bl_10 5\" in exI)\n     apply (rule exI, intro conjI)\n       apply (fastforce simp: High_cnode_def High_caps_def caps_of_state_simps\n                              s0_internal_def kh0_def well_formed_cnode_n_def)\n      apply clarsimp\n     apply (clarsimp simp: vref_for_level_def mask_def pt_simps user_region_simps bit_simps s0_ptr_defs)\n     apply (word_bitwise, fastforce)\n    \\<comment> \\<open>Low asid\\<close>\n    prefer 2\n    apply (subst (asm) ptes_of_def)\n    apply (clarsimp simp: pts_of_s0)\n    apply (clarsimp simp: in_omonad kh0_obj_def pptr_from_pte_def ptrFromPAddr_addr_from_ppn'\n                   split: if_splits)\n    apply (rule conjI, clarsimp simp: Low_asid_def asid_low_bits_def)\n    apply (prop_tac \"pt_walk (max_pt_level - 1) bot_level Low_pt_ptr vref (ptes_of s0_internal) =\n                     Some (max_pt_level - 1, Low_pt_ptr)\")\n     apply (clarsimp simp: pt_walk.simps)\n     apply (clarsimp simp: ptes_of_def pts_of_s0 in_omonad split: if_splits)\n    apply (clarsimp simp: ptes_of_def pts_of_s0 shared_page_ptr_phys_def ptrFromPAddr_addr_from_ppn'\n                   split: if_splits)\n    apply (rule_tac x=Low_cnode_ptr in exI)\n    apply (rule_tac x=\"the_nat_to_bl_10 5\" in exI)\n    apply (rule exI, intro conjI)\n      apply (fastforce simp: Low_cnode_def Low_caps_def caps_of_state_simps\n                             s0_internal_def kh0_def well_formed_cnode_n_def)\n     apply clarsimp\n    apply (clarsimp simp: vref_for_level_def mask_def pt_simps user_region_simps bit_simps s0_ptr_defs)\n    apply (word_bitwise, fastforce)\n   \\<comment> \\<open>No lookups to other ptes\\<close>\n   apply (clarsimp simp: in_omonad ptes_of_def pts_of_s0  split: if_splits)\n   apply (clarsimp simp: kh0_obj_def mask_def pt_simps user_region_simps bit_simps s0_ptr_defs)\n   apply (rule FalseE, word_bitwise, fastforce simp: elf_index_value)\n  apply (clarsimp simp: in_omonad ptes_of_def pts_of_s0  split: if_splits)\n  apply (clarsimp simp: kh0_obj_def mask_def pt_simps user_region_simps bit_simps s0_ptr_defs)\n  apply (rule FalseE, word_bitwise, fastforce simp: elf_index_value)\n  done\n\nlemma valid_arch_caps_s0[simp]:\n  \"valid_arch_caps s0_internal\"\n  supply if_split[split del]\n  supply caps_of_state_simps = caps_of_state_def get_cap_def gets_def get_def get_object_def\n                               assert_def assert_opt_def fail_def return_def bind_def\n  apply (clarsimp simp: valid_arch_caps_def)\n  apply (intro conjI)\n      apply (simp add: valid_vs_lookup_s0_internal)\n     apply (clarsimp simp: valid_asid_pool_caps_def s0_internal_def arch_state0_def)\n     apply (clarsimp split: if_splits)\n      apply (rule_tac x=\"High_cnode_ptr\" in exI)\n      apply (rule_tac x=\"the_nat_to_bl_10 4\" in exI)\n      apply (force simp: caps_of_state_simps well_formed_cnode_n_def s0_internal_def kh0_obj_def\n                         kh0_def High_caps_def High_asid_def asid_high_bits_of_def asid_low_bits_def\n                  split: if_splits)\n     apply (rule_tac x=\"Low_cnode_ptr\" in exI)\n     apply (rule_tac x=\"the_nat_to_bl_10 4\" in exI)\n     apply (force simp: caps_of_state_simps well_formed_cnode_n_def s0_internal_def kh0_obj_def\n                        kh0_def Low_caps_def Low_asid_def asid_high_bits_of_def asid_low_bits_def\n                 split: if_splits)\n    apply (clarsimp simp: valid_table_caps_def)\n    apply (fastforce simp: caps_of_state_simps pts_of_s0 s0_internal_def kh0_obj_def\n                           tcb_cnode_map_def Silc_caps_def High_caps_def Low_caps_def\n                    dest!: kh0_SomeD split: if_splits kernel_object.splits option.splits)\n   apply (clarsimp simp: unique_table_caps_def)\n   apply (clarsimp simp: caps_of_state_simps split: if_splits kernel_object.splits option.splits)\n      apply (subst (asm) s0_internal_def)\n      apply (clarsimp simp: kh0_def kh0_obj_def Silc_caps_def High_caps_def Low_caps_def\n                     split: if_splits)\n     apply (subst (asm) s0_internal_def)\n     apply (clarsimp simp: kh0_def kh0_obj_def Silc_caps_def High_caps_def Low_caps_def\n                    split: if_splits)\n    apply (clarsimp simp: s0_internal_def kh0_def kh0_obj_def split: if_splits;\n           clarsimp simp: tcb_cnode_map_def split: if_splits)\n   apply (clarsimp simp: s0_internal_def kh0_def kh0_obj_def split: if_splits;\n          clarsimp simp: tcb_cnode_map_def split: if_splits)\n  apply (clarsimp simp: unique_table_refs_def)\n  apply (drule s0_caps_of_state)+\n  apply clarsimp\n  apply (elim disjE; clarsimp)\n  done\n\nlemma valid_global_objs_s0[simp]:\n  \"valid_global_objs s0_internal\"\n  by (clarsimp simp: valid_global_objs_def s0_internal_def arch_state0_def)\n\nlemma valid_kernel_mappings_s0[simp]:\n  \"valid_kernel_mappings s0_internal\"\n  by (clarsimp simp: valid_kernel_mappings_def s0_internal_def ran_def\n              split: kernel_object.splits arch_kernel_obj.splits)\n\nlemma equal_kernel_mappings_s0[simp]:\n  \"equal_kernel_mappings s0_internal\"\n  supply misc = vref_for_level_def pt_bits_left_def asid_pool_level_size\n                pageBits_def ptTranslationBits_def mask_def max_pt_level_def2\n  apply (clarsimp simp: equal_kernel_mappings_def obj_at_def vspace_for_asid_def\n                        vspace_for_pool_def pool_for_asid_s0 asid_pools_of_s0)\n   apply (clarsimp simp: obind_def pts_of_s0)\n   apply (clarsimp simp: has_kernel_mappings_def split: if_splits)\n   apply (rule conjI; clarsimp)\n    apply (clarsimp simp: kernel_mapping_slots_def s0_ptr_defs misc)\n   apply (fastforce simp: pts_of_s0 s0_internal_def arch_state0_def\n                          kh0_obj_def opt_map_def riscv_global_pt_def\n                   dest!: kh0_SomeD split: if_splits option.splits)\n  apply (clarsimp simp: pts_of_s0)\n  apply (clarsimp simp: s0_internal_def riscv_global_pt_def arch_state0_def kh0_obj_def\n                        kernel_mapping_slots_def s0_ptr_defs misc elf_index_value)+\n  done\n\nlemma valid_asid_map_s0[simp]:\n  \"valid_asid_map s0_internal\"\n  by (clarsimp simp: valid_asid_map_def s0_internal_def arch_state0_def)\n\nlemma valid_global_pd_mappings_s0_helper:\n  \"\\<lbrakk> pptr_base \\<le> vref; vref < pptr_base + (1 << kernel_window_bits) \\<rbrakk>\n     \\<Longrightarrow> \\<exists>a b. pt_lookup_target 0 riscv_global_pt_ptr vref (ptes_of s0_internal) = Some (a, b) \\<and>\n               is_aligned b (pt_bits_left a) \\<and>\n               addrFromPPtr b + (vref && mask (pt_bits_left a)) = addrFromPPtr vref\"\n  supply misc = vref_for_level_def pt_bits_left_def asid_pool_level_size\n                pageBits_def ptTranslationBits_def mask_def max_pt_level_def2\n  apply (clarsimp simp: pt_lookup_target_def obind_def split: option.splits)\n  apply (prop_tac \"pt_lookup_slot_from_level max_pt_level 0 riscv_global_pt_ptr vref (ptes_of s0_internal) =\n                   Some (max_pt_level, pt_slot_offset max_pt_level riscv_global_pt_ptr vref)\")\n   apply (clarsimp simp: pt_lookup_slot_from_level_def pt_walk.simps)\n   apply (fastforce simp: ptes_of_def in_omonad s0_internal_def kh0_def init_global_pt_def\n                          global_pte_def is_aligned_pt_slot_offset_pte)\n  apply (clarsimp simp: pt_lookup_slot_from_level_def pt_walk.simps)\n  apply (rule conjI; clarsimp dest!: pt_walk_max_level simp: max_pt_level_def2 split: if_splits)\n  apply (rule conjI; clarsimp)\n   apply (clarsimp simp: ptes_of_def pts_of_s0 global_pte_def kernel_window_bits_def\n                         table_index_offset_pt_bits_left is_aligned_pt_slot_offset_pte\n                  split: if_splits)\n    apply (clarsimp simp: misc s0_ptr_defs)\n    apply (word_bitwise, fastforce)\n   apply (clarsimp simp: misc s0_ptr_defs kernel_mapping_slots_def)\n   apply (word_bitwise, fastforce)\n  apply (clarsimp simp: ptes_of_def pts_of_s0 is_aligned_pt_slot_offset_pte global_pte_def\n                 split: if_splits)\n   apply (clarsimp simp: addr_from_ppn_def ptrFromPAddr_def addrFromPPtr_def bit_simps\n                         mask_def s0_ptr_defs pt_bits_left_def max_pt_level_def2\n                         pptrBaseOffset_def paddrBase_def is_aligned_def kernel_window_bits_def)\n   apply (word_bitwise, fastforce)\n  apply (clarsimp simp: addr_from_ppn_def ptrFromPAddr_def addrFromPPtr_def bit_simps is_aligned_def\n                        s0_ptr_defs pt_bits_left_def max_pt_level_def2 kernel_mapping_slots_def\n                        mask_def pt_slot_offset_def pt_index_def pptrBaseOffset_def paddrBase_def\n                        toplevel_bits_value elf_index_value kernel_window_bits_def)\n  apply (word_bitwise, fastforce)\n  done\n\nlemma ptes_of_elf_window:\n  \"\\<lbrakk>kernel_elf_base \\<le> vref; vref < kernel_elf_base + 2 ^ pageBits\\<rbrakk>\n   \\<Longrightarrow> ptes_of s0_internal (pt_slot_offset max_pt_level riscv_global_pt_ptr vref)\n       = Some (global_pte elf_index)\"\n  unfolding ptes_of_def pts_of_s0\n  apply (clarsimp simp: obind_def elf_window_4k is_aligned_pt_slot_offset_pte)\n  done\n\nlemma valid_global_pd_mappings_s0_helper':\n  \"\\<lbrakk> kernel_elf_base \\<le> vref; vref < kernel_elf_base + (1 << pageBits) \\<rbrakk>\n     \\<Longrightarrow> \\<exists>a b. pt_lookup_target 0 riscv_global_pt_ptr vref (ptes_of s0_internal) = Some (a, b) \\<and>\n               is_aligned b (pt_bits_left a) \\<and>\n               addrFromPPtr b + (vref && mask (pt_bits_left a)) = addrFromKPPtr vref\"\n  supply misc = vref_for_level_def pt_bits_left_def asid_pool_level_size\n                pageBits_def ptTranslationBits_def mask_def max_pt_level_def2\n  apply (clarsimp simp: pt_lookup_target_def obind_def split: option.splits)\n  apply (prop_tac \"pt_lookup_slot_from_level max_pt_level 0 riscv_global_pt_ptr vref (ptes_of s0_internal) =\n                   Some (max_pt_level, pt_slot_offset max_pt_level riscv_global_pt_ptr vref)\")\n   apply (clarsimp simp: pt_lookup_slot_from_level_def pt_walk.simps)\n   apply (fastforce simp: ptes_of_def in_omonad s0_internal_def kh0_def init_global_pt_def\n                          global_pte_def is_aligned_pt_slot_offset_pte)\n  apply (rule conjI; clarsimp)\n  apply (rule conjI; clarsimp)\n   apply (clarsimp simp: pt_lookup_slot_from_level_def pt_walk.simps)\n  apply (rule conjI; clarsimp)\n   apply (clarsimp simp: ptes_of_elf_window global_pte_def split: if_splits)\n  apply (clarsimp simp: ptes_of_elf_window global_pte_def elf_index_value)\n  apply (clarsimp simp: is_aligned_ptrFromPAddr_kernelELFPAddrBase kernelELFPAddrBase_addrFromKPPtr)\n  done\n\nlemma valid_global_pd_mappings_s0[simp]:\n  \"valid_global_vspace_mappings s0_internal\"\n  unfolding valid_global_vspace_mappings_def Let_def\n  apply (intro conjI)\n    apply (simp add: s0_internal_def arch_state0_def riscv_global_pt_def)\n   apply (fastforce simp: s0_internal_def arch_state0_def in_omonad kernel_window_def\n                          init_vspace_uses_def translate_address_def riscv_global_pt_def\n                   dest!: valid_global_pd_mappings_s0_helper split: if_splits)\n  apply (fastforce simp: translate_address_def in_omonad s0_internal_def arch_state0_def\n                         riscv_global_pt_def kernel_elf_window_def init_vspace_uses_def\n                  dest!: valid_global_pd_mappings_s0_helper' split: if_splits)\n  done\n\nlemma pspace_in_kernel_window_s0[simp]:\n  \"pspace_in_kernel_window s0_internal\"\n  apply (clarsimp simp: pspace_in_kernel_window_def kernel_window_def\n                        init_vspace_uses_def s0_internal_def arch_state0_def)\n  apply (subgoal_tac \"x \\<in> {pptr_base..<pptr_base + (1 << kernel_window_bits)}\"; clarsimp)\n  apply (drule kh0_SomeD)\n  by (clarsimp simp: s0_ptr_defs kh0_obj_def cte_level_bits_def table_size pageBits_def\n                     ptTranslationBits_def kernel_window_bits_def\n              dest!: irq_node_offs_range_correct\n      | erule disjE dual_order.strict_trans2[rotated] dual_order.trans\n      | rule conjI | word_bitwise)+\n\nlemma cap_refs_in_kernel_window_s0[simp]:\n  \"cap_refs_in_kernel_window s0_internal\"\n  apply (clarsimp simp: cap_refs_in_kernel_window_def valid_refs_def not_kernel_window_def\n                        cap_range_def Invariants_AI.cte_wp_at_caps_of_state)\n  apply (subgoal_tac \"- kernel_window s0_internal \\<inter> obj_refs cap = {}\")\n   apply (fastforce dest: s0_caps_of_state)\n  apply (rule Int_emptyI, clarsimp)\n  apply (erule swap, clarsimp)\n  apply (drule s0_caps_of_state)\n  apply (clarsimp simp: kernel_window_def init_vspace_uses_def s0_internal_def arch_state0_def)\n  apply (subgoal_tac \"x \\<in> {pptr_base..<pptr_base + (1 << kernel_window_bits)}\"; clarsimp)\n  by (clarsimp simp: s0_ptr_defs kh0_obj_def table_size pageBits_def ptTranslationBits_def\n                     kernel_window_bits_def\n              dest!: irq_node_offs_range_correct\n      | erule disjE dual_order.strict_trans2[rotated] dual_order.trans\n      | rule conjI | word_bitwise)+\n\nlemma cur_tcb_s0[simp]:\n  \"cur_tcb s0_internal\"\n  by (simp add: cur_tcb_def s0_ptr_defs s0_internal_def kh0_def kh0_obj_def obj_at_def is_tcb_def)\n\nlemma valid_list_s0[simp]:\n  \"valid_list s0_internal\"\n  by (simp add: valid_list_2_def s0_internal_def exst0_def const_def)\n\nlemma valid_sched_s0[simp]:\n  \"valid_sched s0_internal\"\n  apply (simp add: valid_sched_def s0_internal_def exst0_def)\n  apply (intro conjI)\n        apply (clarsimp simp: valid_etcbs_def is_etcb_at'_def kh0_def kh0_obj_def\n                              st_tcb_at_kh_def obj_at_kh_def obj_at_def)\n       apply (clarsimp simp: const_def)\n      apply (clarsimp simp: const_def)\n     apply (clarsimp simp: valid_sched_action_def is_activatable_def st_tcb_at_kh_def\n                           obj_at_kh_def obj_at_def kh0_def kh0_obj_def s0_ptr_defs)\n    apply (clarsimp simp: ct_in_cur_domain_def in_cur_domain_def etcb_at'_def ekh0_obj_def\n                          s0_ptr_defs)\n   apply (clarsimp simp: const_def valid_blocked_def st_tcb_at_kh_def obj_at_kh_def obj_at_def\n                         kh0_def kh0_obj_def split: if_split_asm)\n  apply (clarsimp simp: valid_idle_etcb_def etcb_at'_def ekh0_obj_def s0_ptr_defs idle_thread_ptr_def)\n  done\n\nlemma respects_device_trivial:\n  \"pspace_respects_device_region s0_internal\"\n  \"cap_refs_respects_device_region s0_internal\"\n   apply (clarsimp simp: s0_internal_def pspace_respects_device_region_def machine_state0_def kh0_def\n                         kh0_obj_def device_mem_def in_device_frame_def obj_at_kh_def obj_at_def\n                  split: if_splits)\n   apply fastforce\n  apply (clarsimp simp: cap_refs_respects_device_region_def Invariants_AI.cte_wp_at_caps_of_state\n                        cap_range_respects_device_region_def machine_state0_def)\n  apply (intro conjI impI)\n   apply (drule s0_caps_of_state)\n   apply fastforce\n  apply (clarsimp simp: s0_internal_def machine_state0_def)\n  done\n\nlemma einvs_s0:\n  \"einvs s0_internal\"\n  by (simp add: valid_state_def invs_def respects_device_trivial)\n\n\nsubsubsection \\<open>Haskell state\\<close>\n\ntext \\<open>One invariant we need on s0 is that there exists\n        an associated Haskell state satisfying the invariants.\n        This does not yet exist.\\<close>\n\nlemma Sys1_valid_initial_state_noenabled:\n  assumes extras_s0: \"step_restrict s0\"\n  assumes utf_det: \"\\<forall>pl pr pxn tc ms s. det_inv InUserMode tc s \\<and> einvs s \\<and>\n                                        context_matches_state pl pr pxn ms s \\<and> ct_running s\n                   \\<longrightarrow> (\\<exists>x. utf (cur_thread s) pl pr pxn (tc, ms) = {x})\"\n  assumes utf_non_empty: \"\\<forall>t pl pr pxn tc ms. utf t pl pr pxn (tc, ms) \\<noteq> {}\"\n  assumes utf_non_interrupt: \"\\<forall>t pl pr pxn tc ms e f g. (e,f,g) \\<in> utf t pl pr pxn (tc, ms)\n                                                         \\<longrightarrow> e \\<noteq> Some Interrupt\"\n  assumes det_inv_invariant: \"invariant_over_ADT_if det_inv utf\"\n  assumes det_inv_s0: \"det_inv KernelExit (cur_context s0_internal) s0_internal\"\n  shows \"valid_initial_state_noenabled det_inv utf s0_internal Sys1PAS timer_irq s0_context\"\n  apply (unfold_locales, simp_all only: pasMaySendIrqs_Sys1PAS)\n                      apply (insert det_inv_invariant)[9]\n                      apply (erule(2) invariant_over_ADT_if.det_inv_abs_state)\n                     apply ((erule invariant_over_ADT_if.det_inv_abs_state\n                                   invariant_over_ADT_if.check_active_irq_if_Idle_det_inv\n                                   invariant_over_ADT_if.check_active_irq_if_User_det_inv\n                                   invariant_over_ADT_if.do_user_op_if_det_inv\n                                   invariant_over_ADT_if.handle_preemption_if_det_inv\n                                   invariant_over_ADT_if.kernel_entry_if_Interrupt_det_inv\n                                   invariant_over_ADT_if.kernel_entry_if_det_inv\n                                   invariant_over_ADT_if.kernel_exit_if_det_inv\n                                   invariant_over_ADT_if.schedule_if_det_inv)+)[8]\n            apply (rule Sys1_pas_cur_domain)\n           apply (rule Sys1_pas_wellformed_noninterference)\n          apply (simp only: einvs_s0)\n          apply (simp add: Sys1_current_subject_idemp)\n          apply (simp add: only_timer_irq_inv_s0 silc_inv_s0 Sys1_pas_cur_domain\n                           domain_sep_inv_s0 Sys1_pas_refined Sys1_guarded_pas_domain\n                           idle_equiv_refl)\n          apply (clarsimp simp: valid_domain_list_2_def s0_internal_def exst0_def)\n         apply (simp add: det_inv_s0)\n        apply (simp add: s0_internal_def exst0_def)\n       apply (simp add: ct_in_state_def st_tcb_at_tcb_states_of_state_eq\n                        identity_eq[symmetric] tcb_states_of_state_s0)\n       apply (simp add: s0_ptr_defs s0_internal_def)\n      apply (simp add: s0_internal_def exst0_def)\n     apply (rule utf_det)\n    apply (rule utf_non_empty)\n   apply (rule utf_non_interrupt)\n  apply (simp add: extras_s0[simplified s0_def])\n  done\n\ntext \\<open>the extra assumptions in valid_initial_state of being enabled,\n        and a serial system, follow from ADT_IF_Refine\\<close>\n\nend\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/proof/infoflow/RISCV64/Example_Valid_State.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6442251064863697, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.29200266230392086}}
{"text": "(*\n   Copyright 2017 Sidney Amani\n   Copyright 2017 Maksym Bortin\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n*)\ntheory EvmFacts\n  imports \"Hoare\"\nbegin\n\ndeclare memory_as_set_def [simp del]\ndeclare storage_as_set_def [simp del]\ndeclare balance_as_set_def [simp del]\ndeclare log_as_set_def [simp del]\n\n\nlemmas gas_simps = Gverylow_def Glow_def Gmid_def Gbase_def Gzero_def Glogtopic_def \n    Gsha3word_def Gsha3_def Gextcode_def Gcopy_def Gblockhash_def Gexpbyte_def Gexp_def\n    Gbalance_def Gsload_def Gsreset_def Gsset_def Gjumpdest_def Ghigh_def\n    Glogdata_def  Glog_def Gcreate_def Ccall_def \n    Cgascap_def Cextra_def Gnewaccount_def Cxfer_def Cnew_def\n    Gcall_def Gcallvalue_def \n\ntermination log256floor by lexicographic_order\n\nlemma log256floor_ge_0:\n  \"0 \\<le> log256floor s\"\n  apply (induct s rule: log256floor.induct)\n  subgoal for x\n    by (case_tac \"\\<not> x \\<le> 255\")\n       (clarsimp)+\n  done\ndeclare  log256floor.simps[simp del ]\n\nlemma Cextra_gt_0:\n  \"0 < Cextra  a b c\"\n  by (simp add:  gas_simps)\n\nlemma L_compare : \"x \\<ge> 0 \\<Longrightarrow> L x \\<ge> 0\"\nby (simp add:L_def)\n\nlemma Cgascap_gt_0:\n  \"f \\<ge> 0 \\<Longrightarrow> 0 \\<le> Cgascap a b c d e f + f\"\napply (auto simp add:  gas_simps L_def min_def)\ndone\n\nlemma Ccall_gt_0:\n  \"memu \\<ge> 0 \\<Longrightarrow>  0 < Ccall s0 s1 s2 recipient_empty\n            remaining_gas blocknumber memu + memu\"\n\n  unfolding Ccall_def\napply (auto)\n  apply (simp add: Cextra_gt_0 add.commute add_nonneg_pos)\n  apply (metis Cextra_gt_0 Cgascap_gt_0 add.commute add.left_commute add_strict_increasing)\n  by (simp add: Cextra_gt_0 add.commute add_nonneg_pos)\n\nlemma Ccall_ge_0:\n  \"memu \\<ge> 0 \\<Longrightarrow>  0 \\<le> Ccall s0 s1 s2 recipient_empty\n            remaining_gas blocknumber memu + memu\"\nusing Ccall_gt_0\n  by (simp add: dual_order.order_iff_strict)\n\n\nlemma Csuicide_gt_0:\n  \"at_least_eip150 net \\<Longrightarrow> 0 < Csuicide recipient_empty net\"\n  unfolding Csuicide_def\n  by (auto split: if_splits\n           simp add: gas_simps Gsuicide_def)\n\nlemma thirdComponentOfC_gt_0:\n  \"i \\<noteq> Misc STOP \\<Longrightarrow> i \\<noteq> Misc RETURN \\<Longrightarrow> (\\<forall>v. i \\<noteq> Unknown v) \\<Longrightarrow>\n   i = Misc SUICIDE \\<longrightarrow> at_least_eip150 net \\<Longrightarrow>\n   i = Misc DELEGATECALL \\<longrightarrow> \\<not> (before_homestead net)  \\<Longrightarrow>\n   memu \\<ge> 0 \\<Longrightarrow>\n  0 < thirdComponentOfC i s0 s1 s2 s3 recipient_empty orig_val\n      new_val remaining_gas net memu + memu\"\n  unfolding thirdComponentOfC_def\n  apply (case_tac i ; simp add: gas_simps )\n            apply fastforce\n           apply (case_tac x2; simp add: gas_simps)\n          apply (case_tac x3; simp add: gas_simps )\n         apply (case_tac x4 ; simp add: gas_simps)\n         using log256floor_ge_0[where s=\"uint s1\"]\n                 apply (simp add: )\n              apply (clarsimp; simp add: word_less_def word_neq_0_conv)\n                apply (case_tac x5; simp add: gas_simps)\n              apply (case_tac x7; simp add: gas_simps)\n                apply (case_tac \"s2 = 0\" ; auto simp: word_less_def word_neq_0_conv)\n                apply (case_tac \"s2 = 0\" ; auto simp: word_less_def word_neq_0_conv)\n              apply (case_tac \"s3 = 0\" ; auto simp: word_less_def word_neq_0_conv)\n            apply (case_tac x8; simp add: gas_simps Csstore_def)\n            apply (case_tac x9; simp add: gas_simps Csstore_def)\n           apply (case_tac x10; simp add: gas_simps Csstore_def)\n          apply ( case_tac x12; case_tac \"s1 = 0\"; \n             simp add: gas_simps word_less_def word_neq_0_conv)\n         apply (clarsimp split: misc_inst.splits)\n         apply (rule conjI, clarsimp simp add: gas_simps L_def)\n         apply (rule conjI)\n          apply (auto simp add: Ccall_gt_0 at_least_eip150.simps)+\n         apply (smt Csuicide_gt_0)\n         apply (smt Csuicide_gt_0)\ndone\n\nlemma thirdComponentOfC_ge_0:\n  \"memu \\<ge> 0 \\<Longrightarrow>\n  0 \\<le> thirdComponentOfC i s0 s1 s2 s3 recipient_empty orig_val\n      new_val remaining_gas net memu + memu\"\n  unfolding thirdComponentOfC_def\n  apply (case_tac i ; simp add: gas_simps )\n           apply (case_tac x2; simp add: gas_simps)\n          apply (case_tac x3; simp add: gas_simps )\n         apply (case_tac x4 ; simp add: gas_simps)\n         using log256floor_ge_0[where s=\"uint s1\"]\n                 apply (simp add: )\n              apply (clarsimp; simp add: word_less_def word_neq_0_conv)\n                apply (case_tac x5; simp add: gas_simps)\n              apply (case_tac x7; simp add: gas_simps)\n                apply (case_tac \"s2 = 0\" ; auto simp: word_less_def word_neq_0_conv)\n                apply (case_tac \"s2 = 0\" ; auto simp: word_less_def word_neq_0_conv)\n              apply (case_tac \"s3 = 0\" ; auto simp: word_less_def word_neq_0_conv)\n            apply (case_tac x8; simp add: gas_simps Csstore_def)\n            apply (case_tac x9; simp add: gas_simps Csstore_def)\n           apply (case_tac x10; simp add: gas_simps Csstore_def)\n          apply ( case_tac x12; case_tac \"s1 = 0\"; \n             simp add: gas_simps word_less_def word_neq_0_conv)\n         apply (clarsimp split: misc_inst.splits)\n         apply (rule conjI, clarsimp simp add: gas_simps L_def)\n         apply (rule conjI)\n          apply (auto simp add: Ccall_ge_0 Gcreate_def Gzero_def\n                Csuicide_def Gsuicide_def Gnewaccount_def)+\ndone\n\n\n\nlemma Cmem_lift:\n  \"0 \\<le> x \\<Longrightarrow> x \\<le> y \\<Longrightarrow> Cmem x \\<le> Cmem y\"\n  apply (simp add: Cmem_def Gmemory_def)\n  apply (case_tac \"x = y\")\n   apply clarsimp\n  apply (drule (1) order_class.le_neq_trans)\n  apply simp\n  apply (rule add_mono, simp)\n  apply (rule zdiv_mono1[rotated], simp)\n  apply (rule mult_mono ; simp)\n  done\n\n(*\nlemma thirdComponentOfC_gt_0_massaged :\n  \"i \\<noteq> Misc STOP \\<Longrightarrow> i \\<noteq> Misc RETURN \\<Longrightarrow> (\\<forall>v. i \\<noteq> Unknown v) \\<Longrightarrow>\n   i = Misc SUICIDE \\<longrightarrow> at_least_eip150 net \\<Longrightarrow>\n   i = Misc DELEGATECALL \\<longrightarrow> \\<not> before_homestead net \\<Longrightarrow>\n   x \\<ge> y \\<Longrightarrow>\n  0 < x - y + thirdComponentOfC i s0 s1 s2 s3 recipient_empty orig_val\n      new_val remaining_gas net (x-y)\"\n  by (metis add.commute diff_ge_0_iff_ge thirdComponentOfC_gt_0)\n*)\n\nlemma vctx_memory_usage_never_decreases:\n  \"orig \\<le> new_memory_consumption inst orig s0 s1 s2 s3 s4 s5 s6\"\n  by (case_tac inst)\n     (rename_tac x, case_tac x; auto simp add: new_memory_consumption.simps M_def)+\n\nlemma obvious_principle :\n\"0 < (t::int) + (m1-m2) \\<Longrightarrow>\n m1 \\<ge> m2 \\<Longrightarrow>\n m2 \\<ge> 0 \\<Longrightarrow>\n 0 < m1 - m2 + t\"\nby auto\n\nlemma Cmem_zero : \"Cmem 0 = 0\"\nby (auto simp:Cmem_def)\n\nlemma meter_gas_gt_0:\n  \" inst \\<noteq> Misc STOP \\<Longrightarrow>\n    inst \\<noteq> Misc RETURN \\<Longrightarrow>\n   inst = Misc SUICIDE \\<longrightarrow> at_least_eip150 net \\<Longrightarrow>\n   inst = Misc DELEGATECALL \\<longrightarrow> \\<not>before_homestead net  \\<Longrightarrow>\n    inst \\<notin> range Unknown \\<Longrightarrow>\n   0 \\<le> vctx_memory_usage var \\<Longrightarrow>\n   0 < meter_gas inst var const net\"\n  apply (simp add: C_def meter_gas_def)\napply (rule obvious_principle)\napply (rule thirdComponentOfC_gt_0)\napply simp\napply simp\napply force\napply simp\napply simp\nusing Cmem_lift vctx_memory_usage_never_decreases\napply force\nusing Cmem_lift vctx_memory_usage_never_decreases\napply force\nusing Cmem_lift Cmem_zero\napply force\ndone\n\nlemma obvious_principle2 :\n\"0 \\<le> (t::int) + (m1-m2) \\<Longrightarrow>\n m1 \\<ge> m2 \\<Longrightarrow>\n m2 \\<ge> 0 \\<Longrightarrow>\n 0 \\<le> m1 - m2 + t\"\nby auto\n\nlemma meter_gas_ge_0:\n  \"0 \\<le> vctx_memory_usage var \\<Longrightarrow>\n   0 \\<le> meter_gas inst var const net\"\n  apply (simp add: C_def meter_gas_def)\napply (rule obvious_principle2)\napply (rule thirdComponentOfC_ge_0)\nusing Cmem_lift vctx_memory_usage_never_decreases\napply force\nusing Cmem_lift vctx_memory_usage_never_decreases\napply force\nusing Cmem_lift Cmem_zero\napply force\ndone\n\ndefinition all :: \"state_element set_pred\" where\n\"all s = True\"\n\ndefinition ex :: \"('a \\<Rightarrow> 'b set_pred) \\<Rightarrow> 'b set_pred\" where\n\"ex f s = (\\<exists>x. f x s)\"\n\ndefinition gas_smaller :: \"int \\<Rightarrow> state_element set_pred\" where\n\"gas_smaller x s = (\\<exists>y. y < x \\<and> gas_pred y s)\"\n\ndefinition some_gas :: \"state_element set_pred\" where\n\"some_gas s = (\\<exists>y. gas_pred y s)\"\n\ndefinition sep_add :: \"'a set_pred \\<Rightarrow> 'a set_pred \\<Rightarrow> 'a set_pred\"\n  where\n    \"sep_add p q == (\\<lambda> s. p s \\<or> q s)\"\n\nnotation sep_add (infixr \"\\<or>*\" 59)\n\nlemma sep_add_assoc [simp]: \"((a \\<or>* b) \\<or>* c) = (a \\<or>* b \\<or>* c)\"\n  by (simp add: sep_add_def)\n\nlemma sep_add_commute [simp]: \"(a \\<or>* b)= (b \\<or>* a)\"\n by (simp add: sep_add_def) blast\n\ndefinition never :: \"'a set_pred\" where\n\"never == (\\<lambda>s. False)\"\n\nlemma sep_add_never [simp] : \"r \\<or>* never = r\"\nby (simp add: never_def sep_add_def)\n\n(*\nlemma sep_add_distr [simp] : \"a ** (b \\<or>* c) == (a**b) \\<or>* (a**c)\"\napply (simp add: sep_add_def sep_conj_def sep_distinct_def)\napply blast\n*)\n\ndefinition action ::\n   \"(contract_action \\<Rightarrow> bool) \\<Rightarrow> state_element set_pred\" where\n\"action p s = (\\<exists>x. {ContractActionElm x} = s \\<and> p x)\"\n\ndefinition failing :: \"state_element set_pred\" where\n\"failing = action (\\<lambda>y. \\<exists>x. ContractFail x = y)\"\n\ndefinition returning :: \"state_element set_pred\" where\n\"returning = action (\\<lambda>y. \\<exists>x. ContractReturn x = y)\"\n\ndefinition destructing :: \"state_element set_pred\" where\n\"destructing = action (\\<lambda>y. \\<exists>x. ContractSuicide x = y)\"\n\ndefinition calling :: \"state_element set_pred\" where\n\"calling = action (\\<lambda>y. \\<exists>x. ContractCall x = y)\"\n\ndefinition creating :: \"state_element set_pred\" where\n\"creating = action (\\<lambda>y. \\<exists>x. ContractCreate x = y)\"\n\ndefinition delegating :: \"state_element set_pred\" where\n\"delegating = action (\\<lambda>y. \\<exists>x. ContractDelegateCall x = y)\"\n\nlemmas rw = instruction_sem_def instruction_failure_result_def\n  subtract_gas.simps stack_2_1_op_def stack_1_1_op_def\n  stack_3_1_op_def stack_0_1_op_def  general_dup_def\n  mload_def mstore_def mstore8_def calldatacopy_def\n  codecopy_def stack_0_0_op_def jump_def jumpi_def\n  extcodecopy_def sstore_def pc_def pop_def swap_def log_def\n  stop_def create_def call_def delegatecall_def ret_def\n  suicide_def callcode_def strict_if_def blocked_jump_def\nblockedInstructionContinue_def\n\nlemma inst_no_reasons :\n\"instruction_sem v c aa net \\<noteq>\n       InstructionToEnvironment\n        (ContractFail []) a b\"\napply (cases aa)\napply (simp add:rw)\napply (rename_tac inst; case_tac inst;auto simp:rw split:list.split)\napply (rename_tac inst; case_tac inst;auto simp:rw split:list.split)\napply (rename_tac inst; case_tac inst;auto simp:rw sha3_def\n   split:list.split if_split)\napply(case_tac \"\\<not> cctx_hash_filter c ( cut_memory x21 x21a\n                (vctx_memory v))\"; auto simp:rw)\napply (rename_tac inst; case_tac inst;auto simp:rw split:list.split)\napply (rename_tac inst; case_tac inst;\n  auto simp:rw split:list.split option.split)\napply (rename_tac inst; case_tac inst;auto simp:rw split:list.split)\napply (rename_tac inst; case_tac inst;auto simp:rw split:list.split)\ndefer\napply (rename_tac inst; case_tac inst;auto simp:rw split:list.split)\napply (rename_tac inst; case_tac inst;auto simp:rw\n   split:list.split option.split)\napply (rename_tac inst; case_tac inst;auto simp:rw split:list.split)\napply (rename_tac inst; case_tac inst;auto simp:rw split:list.split)\napply (rename_tac inst; case_tac inst;auto simp:rw\n   split:list.split option.split)\napply (case_tac \"vctx_next_instruction (v\n               \\<lparr>vctx_stack := x22,\n                  vctx_pc := uint x21\\<rparr>)\n                  c\"; auto simp:rw)\nsubgoal for x y aaa\napply (case_tac aaa; auto simp:rw)\napply (case_tac x9; auto simp:rw)\ndone\napply (case_tac \"vctx_next_instruction (v\n               \\<lparr>vctx_stack := x22,\n                  vctx_pc := uint x21\\<rparr>)\n                  c\"; auto simp:rw)\nsubgoal for x y z aaa\napply (case_tac aaa; auto simp:rw)\napply (case_tac x9; auto simp:rw)\ndone\ndone\n\nlemma no_reasons_next :\n   \"failed_for_reasons {}\n   (next_state stopper c net (InstructionContinue v)) = False\"\nby (auto simp:failed_for_reasons_def)\n\nlemma program_environment :\n\"program_sem stopper c n net (InstructionToEnvironment a b d) =\n (InstructionToEnvironment a b d)\"\nby (induction n, auto simp:program_sem.simps next_state_def)\n\n\nlemma no_reasons [simp] :\n   \"failed_for_reasons {}\n   (program_sem stopper c n net (InstructionContinue v)) = False\"\napply (induction n arbitrary:v)\napply (auto simp add:program_sem.simps failed_for_reasons_def\n  no_reasons_next)\ndone\n\n(*\nlemmas context_rw = contexts_as_set_def constant_ctx_as_set_def variable_ctx_as_set_def\n      program_as_set_def stack_as_set_def memory_as_set_def storage_as_set_def\n      balance_as_set_def log_as_set_def data_sent_as_set_def ext_program_as_set_def\n      account_balance_as_set_def\n*)\n\n(*\nlemma not_cont_insert :\n \"x (s-{ContinuingElm False}) \\<Longrightarrow>\n  (x ** not_continuing) (insert (ContinuingElm False) s)\"\napply(auto simp add:rw sep_conj_def  not_continuing_def all_def\n         failing_def some_gas_def code_def gas_pred_def context_rw)\ndone\nlemma context_cont :\n  \"contexts_as_set x1 co_ctx -\n      {ContinuingElm a, ContractActionElm b} =\n   contexts_as_set x1 co_ctx\"\napply(auto simp add:rw sep_def  not_continuing_def all_def\n         failing_def some_gas_def code_def gas_pred_def context_rw)\ndone\n\nlemma context_cont1 :\n  \"contexts_as_set x1 co_ctx - {ContinuingElm a} =\n   contexts_as_set x1 co_ctx\"\napply(auto simp add:rw sep_def  not_continuing_def all_def\n         failing_def some_gas_def code_def gas_pred_def context_rw)\ndone\n\nlemma failing_insert :\n \"x (s-{ContractActionElm (ContractFail b)}) \\<Longrightarrow>\n  (x ** failing) (insert (ContractActionElm (ContractFail b)) s)\"\napply(auto simp add:rw sep_def  not_continuing_def all_def\n         action_def failing_def some_gas_def code_def gas_pred_def context_rw)\ndone\n\nlemma some_gas_in_context :\n\"(rest ** gas_pred g) s \\<Longrightarrow>\n(rest ** some_gas ) s\"\napply(auto simp add:rw sep_def  not_continuing_def all_def\n         failing_def some_gas_def code_def gas_pred_def context_rw)\ndone\n\n*)\n\nlemma meter_gas_check :\n  \"\\<not> meter_gas a x1 co_ctx net \\<le> vctx_gas x1 \\<Longrightarrow>\n   check_resources x1 co_ctx (vctx_stack x1) a net \\<Longrightarrow>\n   False\"\nby (simp add:check_resources_def)\n\nlemmas instruction_sem_simps =\n  rw sha3_def vctx_update_storage_def\n  vctx_pop_stack_def vctx_advance_pc_def\nvctx_memory_usage_never_decreases\n\nlemma env_meter_gas :\n\"instruction_sem v1 c inst net =\n InstructionToEnvironment act v2 x33 \\<Longrightarrow>\n vctx_gas v2 = vctx_gas v1 - meter_gas inst v1 c net\"\napply (simp only: instruction_sem_def)\n  apply (case_tac inst; clarsimp)\napply (case_tac x1 ; \n          clarsimp simp: rw\n           split:list.splits)\n         apply (case_tac x2 ; clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (case_tac x3 ; clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (case_tac x4 ; clarsimp simp: instruction_sem_simps split:list.splits)\napply(case_tac \"\\<not> cctx_hash_filter c ( cut_memory x21 x21a (vctx_memory v1))\")\n         apply (clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (case_tac x5 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n         apply (case_tac x6 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n         apply (case_tac x7 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n      apply (case_tac x8 ; clarsimp simp: instruction_sem_simps Let_def split:list.splits option.splits pc_inst.splits )\n      apply (case_tac x9; clarsimp simp: instruction_sem_simps Let_def split: list.splits  pc_inst.splits option.splits)\n       apply (case_tac \"x2\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x21a = 0\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x2\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x21a = 0\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x2a\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n     apply (case_tac \"x10\"; clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits list.splits)\n     apply (clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits)\n     apply (case_tac \"x12\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n     apply (case_tac \"x13\"; clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits list.splits if_splits)\ndone\n\nlemma continue_meter_gas :\n\"instruction_sem v1 c inst net =\n InstructionContinue v2 \\<Longrightarrow>\n vctx_gas v2 = vctx_gas v1 - meter_gas inst v1 c net\"\napply (simp only: instruction_sem_def)\n  apply (case_tac inst; clarsimp)\napply (case_tac x1 ; \n          clarsimp simp: rw\n           split:list.splits)\n         apply (case_tac x2 ; clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (case_tac x3 ; clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (case_tac x4 ; clarsimp simp: instruction_sem_simps split:list.splits)\napply(case_tac \"\\<not> cctx_hash_filter c ( cut_memory x21 x21a (vctx_memory v1))\")\n         apply (clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (case_tac x5 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n         apply (case_tac x6 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n         apply (case_tac x7 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n      apply (case_tac x8 ; clarsimp simp: instruction_sem_simps Let_def split:list.splits option.splits pc_inst.splits )\n      apply (case_tac x9; clarsimp simp: instruction_sem_simps Let_def split: list.splits  pc_inst.splits option.splits)\n       apply (case_tac \"x2\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x21a = 0\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x2\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x21a = 0\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x2a\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n     apply (case_tac \"x10\"; clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits list.splits)\n     apply (clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits)\n     apply (case_tac \"x12\"; clarsimp simp: Let_def instruction_sem_simps  split: pc_inst.splits option.splits)\n     apply (case_tac \"x13\"; clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits list.splits if_splits)\ndone\n\nlemma memu_good :\n\"instruction_sem v1 c inst net = InstructionContinue v2 \\<Longrightarrow>\n vctx_memory_usage v2 \\<ge> vctx_memory_usage v1\"\napply (simp only: instruction_sem_def)\n  apply (case_tac inst; clarsimp)\napply (case_tac x1 ; \n          clarsimp simp: rw\n           split:list.splits)\n         apply (case_tac x2 ; clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (case_tac x3 ; clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (case_tac x4 ; clarsimp simp: instruction_sem_simps split:list.splits)\napply(case_tac \"\\<not> cctx_hash_filter c ( cut_memory x21 x21a (vctx_memory v1))\")\n         apply (clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (case_tac x5 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n         apply (case_tac x6 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n         apply (case_tac x7 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n      apply (case_tac x8 ; clarsimp simp: instruction_sem_simps Let_def split:list.splits option.splits pc_inst.splits )\n      apply (case_tac x9; clarsimp simp: instruction_sem_simps Let_def split: list.splits  pc_inst.splits option.splits)\n       apply (case_tac \"x2\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x21a = 0\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x2\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x21a = 0\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x2a\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n     apply (case_tac \"x10\"; clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits list.splits)\n     apply (clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits)\n     apply (case_tac \"x12\"; clarsimp simp: Let_def instruction_sem_simps  split: pc_inst.splits option.splits)\n     apply (case_tac \"x13\"; clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits list.splits if_splits)\ndone\n\nlemma memu_good_env :\n\"instruction_sem v1 c inst net = InstructionToEnvironment act v2 zz \\<Longrightarrow>\n vctx_memory_usage v2 \\<ge> vctx_memory_usage v1\"\napply (simp only: instruction_sem_def)\n  apply (case_tac inst; clarsimp)\napply (case_tac x1 ; \n          clarsimp simp: instruction_sem_simps\n           split:list.splits)\napply (case_tac x2 ; clarsimp simp: instruction_sem_simps split:list.splits)\napply (case_tac x3 ; clarsimp simp: instruction_sem_simps split:list.splits)\napply (case_tac x4 ; clarsimp simp: instruction_sem_simps split:list.splits)\napply(case_tac \"\\<not> cctx_hash_filter c ( cut_memory x21 x21a (vctx_memory v1))\")\n         apply (clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (case_tac x5 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n         apply (case_tac x6 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n         apply (case_tac x7 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n      apply (case_tac x8 ; clarsimp simp: instruction_sem_simps Let_def split:list.splits option.splits pc_inst.splits )\n      apply (case_tac x9; clarsimp simp: instruction_sem_simps Let_def split: list.splits  pc_inst.splits option.splits)\n       apply (case_tac \"x2\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x21a = 0\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x2\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x21a = 0\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x2a\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n     apply (case_tac \"x10\"; clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits list.splits)\n     apply (clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits)\n     apply (case_tac \"x12\"; clarsimp simp: Let_def instruction_sem_simps  split: pc_inst.splits option.splits)\n     apply (case_tac \"x13\"; clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits list.splits if_splits)\ndone\n\n\nlemma call_instruction :\n\"instruction_sem v c inst net =\n InstructionToEnvironment (ContractCall args) x32 x33 \\<Longrightarrow>\n inst = Misc CALL \\<or> inst = Misc CALLCODE\"\napply (simp only: instruction_sem_def)\n  apply (case_tac inst; clarsimp)\napply (case_tac x1 ; \n          clarsimp simp: rw\n           split:list.splits)\n         apply (case_tac x2 ; clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (case_tac x3 ; clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (case_tac x4 ; clarsimp simp: instruction_sem_simps split:list.splits)\napply(case_tac \"\\<not> cctx_hash_filter c ( cut_memory x21 x21a (vctx_memory v))\")\n         apply (clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (case_tac x5 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n         apply (case_tac x6 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n         apply (case_tac x7 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n      apply (case_tac x8 ; clarsimp simp: instruction_sem_simps Let_def split:list.splits option.splits pc_inst.splits )\n      apply (case_tac x9; clarsimp simp: instruction_sem_simps Let_def split: list.splits  pc_inst.splits option.splits)\n       apply (case_tac \"x2\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x21a = 0\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x2\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x21a = 0\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x2a\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n     apply (case_tac \"x10\"; clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits list.splits)\n     apply (clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits)\n     apply (case_tac \"x12\"; clarsimp simp: Let_def instruction_sem_simps  split: pc_inst.splits option.splits)\n     apply (case_tac \"x13\"; clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits list.splits if_splits)\ndone\n\nlemma create_instruction :\n\"instruction_sem v c inst net =\n InstructionToEnvironment (ContractCreate args) x32 x33 \\<Longrightarrow>\n inst = Misc CREATE\"\napply (simp only: instruction_sem_def)\n  apply (case_tac inst; clarsimp)\napply (case_tac x1 ; \n          clarsimp simp: rw\n           split:list.splits)\n         apply (case_tac x2 ; clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (case_tac x3 ; clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (case_tac x4 ; clarsimp simp: instruction_sem_simps split:list.splits)\napply(case_tac \"\\<not> cctx_hash_filter c ( cut_memory x21 x21a (vctx_memory v))\")\n         apply (clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (case_tac x5 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n         apply (case_tac x6 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n         apply (case_tac x7 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n      apply (case_tac x8 ; clarsimp simp: instruction_sem_simps Let_def split:list.splits option.splits pc_inst.splits )\n      apply (case_tac x9; clarsimp simp: instruction_sem_simps Let_def split: list.splits  pc_inst.splits option.splits)\n       apply (case_tac \"x2\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x21a = 0\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x2\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x21a = 0\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x2a\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n     apply (case_tac \"x10\"; clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits list.splits)\n     apply (clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits)\n     apply (case_tac \"x12\"; clarsimp simp: Let_def instruction_sem_simps  split: pc_inst.splits option.splits)\n     apply (case_tac \"x13\"; clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits list.splits if_splits)\ndone\n\n\nlemma continue_instruction :\n \"instruction_sem v c inst net = InstructionContinue v2 \\<Longrightarrow>\n  inst \\<noteq> Misc STOP \\<and> inst \\<noteq> Misc RETURN \\<and>\n  inst \\<noteq> Misc SUICIDE \\<and> inst \\<noteq> Misc DELEGATECALL \\<and>\n  inst \\<notin> range Unknown\"\napply (simp only: instruction_sem_def)\n  apply (case_tac inst; clarsimp)\napply (case_tac x1 ; clarsimp simp: rw split:list.splits)\napply (case_tac \"x13\"; clarsimp simp: instruction_sem_simps\n    split: pc_inst.splits option.splits list.splits if_splits)\ndone\n\nlemma delegatecall_instruction :\n\"instruction_sem v c inst net =\n InstructionToEnvironment (ContractDelegateCall args) x32 x33 \\<Longrightarrow>\n inst = Misc DELEGATECALL \\<and> \\<not> before_homestead net\"\napply (simp only: instruction_sem_def)\n  apply (case_tac inst; clarsimp)\napply (case_tac x1 ; \n          clarsimp simp: rw\n           split:list.splits)\n         apply (case_tac x2 ; clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (case_tac x3 ; clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (case_tac x4 ; clarsimp simp: instruction_sem_simps split:list.splits)\napply(case_tac \"\\<not> cctx_hash_filter c ( cut_memory x21 x21a (vctx_memory v))\")\n         apply (clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (clarsimp simp: instruction_sem_simps split:list.splits)\n         apply (case_tac x5 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n         apply (case_tac x6 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n         apply (case_tac x7 ; clarsimp simp: instruction_sem_simps split:list.splits option.splits)\n      apply (case_tac x8 ; clarsimp simp: instruction_sem_simps Let_def split:list.splits option.splits pc_inst.splits )\n      apply (case_tac x9; clarsimp simp: instruction_sem_simps Let_def split: list.splits  pc_inst.splits option.splits)\n       apply (case_tac \"x2\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x21a = 0\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x2\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x21a = 0\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n       apply (case_tac \"x2a\"; clarsimp simp: instruction_sem_simps Let_def split: pc_inst.splits option.splits)\n     apply (case_tac \"x10\"; clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits list.splits)\n     apply (clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits)\n     apply (case_tac \"x12\"; clarsimp simp: Let_def instruction_sem_simps  split: pc_inst.splits option.splits)\n     apply (case_tac \"x13\"; clarsimp simp: instruction_sem_simps  split: pc_inst.splits option.splits list.splits if_splits)\ndone\n\nlemma delegatecall_decr_gas :\n   assumes a:\"instruction_sem v1 co_ctx a net =\n       InstructionToEnvironment (ContractDelegateCall x1a)\n        v2 x33\"\n   and good:\"vctx_memory_usage v1 \\<ge> 0\"\n  shows  \"vctx_gas v1 > vctx_gas v2\"\nproof -\n  have inst: \"a = Misc DELEGATECALL \\<and>\n \\<not> before_homestead net\"\n   using delegatecall_instruction and a by force\n  then have \"meter_gas a v1 co_ctx net > 0\"\n   using good and meter_gas_gt_0 by blast\n  then show ?thesis using env_meter_gas and a by force\nqed\n\nlemma create_decr_gas :\n   assumes a:\"instruction_sem v1 co_ctx a net =\n       InstructionToEnvironment (ContractCreate x1a)\n        v2 x33\"\n   and good:\"vctx_memory_usage v1 \\<ge> 0\"\n  shows  \"vctx_gas v1 > vctx_gas v2\"\nproof -\n  have inst: \"a = Misc CREATE\"\n   using create_instruction and a by force\n  then have \"meter_gas a v1 co_ctx net > 0\"\n   using good and meter_gas_gt_0 by blast\n  then show ?thesis using env_meter_gas and a by force\nqed\n\nlemma call_decr_gas :\n   assumes a:\"instruction_sem v1 co_ctx a net =\n       InstructionToEnvironment (ContractCall x1a)\n        v2 x33\"\n   and good:\"vctx_memory_usage v1 \\<ge> 0\"\n  shows  \"vctx_gas v1 > vctx_gas v2\"\nproof -\n  have inst: \"a = Misc CALL \\<or> a = Misc CALLCODE\"\n   using call_instruction and a by force\n  then have \"meter_gas a v1 co_ctx net > 0\"\n   using good and meter_gas_gt_0 by blast\n  then show ?thesis using env_meter_gas and a by force\nqed\n\nlemma continue_decr_gas :\n   assumes a:\"instruction_sem v1 co_ctx a net = InstructionContinue v2\"\n   and good:\"vctx_memory_usage v1 \\<ge> 0\"\n  shows  \"vctx_gas v1 > vctx_gas v2\"\nproof -\n  have \"meter_gas a v1 co_ctx net > 0\"\n   using a and good and meter_gas_gt_0 and continue_instruction\n   by auto\n  then show ?thesis using continue_meter_gas and a by force\nqed\n\ndefinition all_stack :: \"state_element set_pred\" where\n\"all_stack s = (\\<exists>t. s = stack_as_set t)\"\n\ndefinition all_but_gas :: \"state_element set_pred\" where\n\"all_but_gas s = (\\<exists>c v.\n   s = contexts_as_set v c - {GasElm (vctx_gas v)})\"\n\nlemma maximality_stack_aux :\n   \"stack_as_set s1 \\<subseteq> stack_as_set s2 \\<Longrightarrow>\n    i < length s1 \\<Longrightarrow>\n    rev s1!i = rev s2!i\"\napply(auto simp add:context_rw)\napply blast\ndone\n\nlemma maximality_stack_length :\n   \"stack_as_set s1 \\<subseteq> stack_as_set s2 \\<Longrightarrow>\n    length s1 = length s2\"\nby (auto simp add:context_rw)\n\nlemma list_eq :\n   \"length l1 = length l2 \\<Longrightarrow>\n    (\\<forall>i. i < length l1 \\<longrightarrow> l1!i = l2!i) \\<Longrightarrow>\n    rev l1 = rev l2\"\napply (rule List.nth_equalityI)\napply auto\n  by (simp add: Suc_diff_Suc rev_nth)\n\n\nlemma maximality_stack_aux2 :\n \"stack_as_set s1 \\<subseteq> stack_as_set s2 \\<Longrightarrow>\n  rev s1 = rev s2\"\napply (rule list_eq)\nusing maximality_stack_length\napply force\napply auto\nsubgoal for i\nusing maximality_stack_aux [of s1 s2 \"length s2 - i -1\"]\n  and maximality_stack_length [of s1 s2]\nproof -\n  assume a1: \"i < length s1\"\n  assume a2: \"stack_as_set s1 \\<subseteq> stack_as_set s2\"\n  have f3: \"\\<not> stack_as_set s1 \\<subseteq> stack_as_set s2 \\<or> length s1 = length s2\"\n    by (metis \\<open>stack_as_set s1 \\<subseteq> stack_as_set s2 \\<Longrightarrow> length s1 = length s2\\<close>)\n  have f4: \"length s2 - i - 1 = length s2 - Suc i\"\n    using diff_Suc_eq_diff_pred diff_commute by presburger\n  have \"0 < length s2\"\n    using f3 a2 a1 by linarith\n  then have \"rev s1 ! (length s2 - i - 1) = rev s2 ! (length s2 - i - 1)\"\n    using f4 f3 a2 \\<open>\\<lbrakk>stack_as_set s1 \\<subseteq> stack_as_set s2; length s2 - i - 1 < length s1\\<rbrakk> \\<Longrightarrow> rev s1 ! (length s2 - i - 1) = rev s2 ! (length s2 - i - 1)\\<close> diff_Suc_less by presburger\n  then show ?thesis\n    using f4 f3 a2 a1 by (metis (no_types) nth_rev_alt)\nqed\ndone\n\nlemma maximality_stack :\n \"stack_as_set s1 \\<subseteq> stack_as_set s2 \\<Longrightarrow>\n  s1 = s2\"\nusing maximality_stack_aux2\n  by auto\n\nlemma stack_height_at_context :\n \"StackHeightElm x \\<in> contexts_as_set v2 c2 \\<Longrightarrow>\n  StackHeightElm x \\<in> stack_as_set (vctx_stack v2)\"\napply(simp add:context_rw)\ndone\n\nlemma stack_elem_at_context :\n \"StackElm (x,y) \\<in> contexts_as_set v2 c2 \\<Longrightarrow>\n  StackElm (x,y) \\<in> stack_as_set (vctx_stack v2)\"\napply(simp add:context_rw)\ndone\n\nlemma stack_at_context :\n \"stack_as_set s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  stack_as_set s1 \\<subseteq> stack_as_set (vctx_stack v2)\"\napply auto\napply (case_tac x)\napply auto\nusing stack_height_at_context\napply force\nusing stack_elem_at_context\napply force\napply(auto simp add:context_rw)\ndone\n\nlemma stack_from_context :\n \"stack_as_set s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  vctx_stack v2 = s1\"\nusing stack_at_context [of s1 v2 c2]\n  and maximality_stack [of s1 \"vctx_stack v2\"]\nby force\n\nlemma maximality_data_aux :\n   \"data_sent_as_set s1 \\<subseteq> data_sent_as_set s2 \\<Longrightarrow>\n    i < length s1 \\<Longrightarrow>\n    s1!i = s2!i\"\napply(auto simp add:context_rw)\napply blast\ndone\n\nlemma maximality_data_length :\n   \"data_sent_as_set s1 \\<subseteq> data_sent_as_set s2 \\<Longrightarrow>\n    length s1 = length s2\"\nby (auto simp add:context_rw)\n\nlemma maximality_data_sent :\n \"data_sent_as_set s1 \\<subseteq> data_sent_as_set s2 \\<Longrightarrow>\n  s1 = s2\"\napply (rule List.nth_equalityI)\nusing maximality_data_length\napply force\napply auto\nsubgoal for i\nusing maximality_data_aux [of s1 s2 i]\napply simp\ndone\ndone\n\nlemma data_size_at_context :\n \"SentDataLengthElm x \\<in> contexts_as_set v2 c2 \\<Longrightarrow>\n  SentDataLengthElm x \\<in> data_sent_as_set (vctx_data_sent v2)\"\napply(simp add:context_rw)\ndone\n\nlemma data_elem_at_context :\n \"SentDataElm (x,y) \\<in> contexts_as_set v2 c2 \\<Longrightarrow>\n  SentDataElm (x,y) \\<in> data_sent_as_set (vctx_data_sent v2)\"\napply(simp add:context_rw)\ndone\n\nlemma data_at_context :\n \"data_sent_as_set s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  data_sent_as_set s1 \\<subseteq> data_sent_as_set (vctx_data_sent v2)\"\napply (auto)\napply (case_tac x)\napply (auto simp:data_size_at_context data_elem_at_context)\napply(auto simp add:context_rw)\ndone\n\nlemma data_from_context :\n \"data_sent_as_set s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  vctx_data_sent v2 = s1\"\nusing data_at_context [of s1 v2 c2]\n  and maximality_data_sent [of s1 \"vctx_data_sent v2\"]\nby force\n\n(* reconstruct memory *)\n\nlemma maximality_memory :\n \"memory_as_set m1 \\<subseteq> memory_as_set m2 \\<Longrightarrow>\n  m1 = m2\"\napply(auto simp add:context_rw)\ndone\n\nlemma memory_at_context :\n \"memory_as_set s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  memory_as_set s1 \\<subseteq> memory_as_set (vctx_memory v2)\"\napply(auto simp add:context_rw)\ndone\n\nlemma memory_from_context :\n \"memory_as_set s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  vctx_memory v2 = s1\"\nusing memory_at_context [of s1 v2 c2]\n  and maximality_memory [of s1 \"vctx_memory v2\"]\nby force\n\n(* reconstruct storage *)\n\nlemma maximality_storage :\n \"storage_as_set m1 \\<subseteq> storage_as_set m2 \\<Longrightarrow>\n  m1 = m2\"\napply(auto simp add:context_rw)\ndone\n\nlemma storage_at_context :\n \"storage_as_set s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  storage_as_set s1 \\<subseteq> storage_as_set (vctx_storage v2)\"\napply(auto simp add:context_rw)\ndone\n\nlemma storage_from_context :\n \"storage_as_set s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  vctx_storage v2 = s1\"\nusing storage_at_context [of s1 v2 c2]\n  and maximality_storage [of s1 \"vctx_storage v2\"]\nby force\n\n(* balance *)\n\nlemma maximality_balance :\n \"balance_as_set m1 \\<subseteq> balance_as_set m2 \\<Longrightarrow>\n  m1 = m2\"\napply(auto simp add:context_rw)\ndone\n\nlemma balance_at_context :\n \"balance_as_set s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  balance_as_set s1 \\<subseteq> balance_as_set (vctx_balance v2)\"\napply(auto simp add:context_rw)\ndone\n\nlemma balance_from_context :\n \"balance_as_set s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  vctx_balance v2 = s1\"\n  by (metis balance_at_context maximality_balance)\n\n(* block info *)\n\nlemma maximality_block :\n \"blockhash_as_elm m1 \\<subseteq> blockhash_as_elm m2 \\<Longrightarrow>\n  m1 = m2\"\napply(auto simp add:context_rw)\ndone\n\nlemma block_at_context :\n \"blockhash_as_elm s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  blockhash_as_elm s1 \\<subseteq>\n    blockhash_as_elm (block_blockhash (vctx_block v2))\"\napply(auto simp add:context_rw)\ndone\n\nlemma block_from_context :\n \"blockhash_as_elm s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  block_blockhash (vctx_block v2) = s1\"\nusing block_at_context [of s1 v2 c2]\n and maximality_block [of s1 \" block_blockhash (vctx_block v2)\"]\nby force\n\n(* program *)\n\ndefinition program_inst :: \"program \\<Rightarrow> int \\<Rightarrow> inst\" where\n\"program_inst p i =\n   (case program_content p i of None \\<Rightarrow> Misc STOP | Some i \\<Rightarrow> i)\"\n\ndefinition program_as_set2 :: \"program \\<Rightarrow> state_element set\" where\n\"program_as_set2 p =\n { CodeElm (pos, i) | pos i. program_inst p pos = i  }\"\n\nlemma maximality_program_aux :\n \"program_as_set2 m1 \\<subseteq> program_as_set2 m2 \\<Longrightarrow>\n  program_inst m1 = program_inst m2\"\napply(auto simp add:context_rw program_as_set2_def)\ndone\n\nlemma program_as_set_eq : \"program_as_set p = program_as_set2 p\"\napply (auto simp:program_as_set_def\n  program_as_set2_def program_inst_def split:option.split)\ndone\n\nlemma maximality_program :\n \"program_as_set m1 \\<subseteq> program_as_set m2 \\<Longrightarrow>\n  program_inst m1 = program_inst m2\"\nby (auto simp:program_as_set_eq maximality_program_aux)\n\nlemma program_at_context :\n \"program_as_set s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  program_as_set s1 \\<subseteq> program_as_set (cctx_program c2)\"\napply(auto simp add:context_rw)\napply blast\napply force\ndone\n\nlemma program_from_context :\n \"program_as_set s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  program_inst (cctx_program c2) = program_inst s1\"\n  by (metis program_at_context maximality_program)\n\nlemma program_inst_same :\n   \"program_inst p1 = program_inst p2 \\<Longrightarrow>\n    program_as_set p1 = program_as_set p2\"\napply (auto simp:program_as_set_def\n  program_as_set2_def program_inst_def split:option.split)\n  apply (metis option.case_eq_if option.expand option.sel option.simps(3) program_inst_def)\n  apply (metis option.case_eq_if option.sel option.simps(3) program_inst_def)\n  apply (metis option.case_eq_if  option.sel option.simps(3) program_inst_def)\n  apply (metis option.case_eq_if option.expand option.sel option.simps(3) program_inst_def)\n  apply (metis option.case_eq_if  option.sel option.simps(3) program_inst_def)\n  apply (metis option.case_eq_if  option.sel option.simps(3) program_inst_def)\ndone\n\n(* reconstruct logs *)\n\nlemma maximality_log_aux :\n   \"log_as_set s1 \\<subseteq> log_as_set s2 \\<Longrightarrow>\n    i < length s1 \\<Longrightarrow>\n    rev s1!i = rev s2!i\"\napply(auto simp add:context_rw)\napply blast\ndone\n\nlemma maximality_log_length :\n   \"log_as_set s1 \\<subseteq> log_as_set s2 \\<Longrightarrow>\n    length s1 = length s2\"\nby (auto simp add:context_rw)\n\nlemma maximality_log :\n \"log_as_set s1 \\<subseteq> log_as_set s2 \\<Longrightarrow>\n  s1 = s2\"\nusing maximality_log_aux [of s1 s2]\n  and maximality_log_length [of s1 s2]\n  and list_eq [of s1 s2]\n  by (metis length_rev nth_equalityI rev_is_rev_conv)\n\nlemma log_length_at_context :\n \"LogNumElm x \\<in> contexts_as_set v2 c2 \\<Longrightarrow>\n  LogNumElm x \\<in> log_as_set (vctx_logs v2)\"\napply(simp add:context_rw)\ndone\n\nlemma log_elem_at_context :\n \"LogElm (x,y) \\<in> contexts_as_set v2 c2 \\<Longrightarrow>\n  LogElm (x,y) \\<in> log_as_set (vctx_logs v2)\"\napply(simp add:context_rw)\ndone\n\nlemma log_at_context_aux :\n \"log_as_set s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  x \\<in> log_as_set s1 \\<Longrightarrow>\n  x \\<in> log_as_set (vctx_logs v2)\"\napply (case_tac x)\napply (auto simp:log_length_at_context log_elem_at_context)\napply(auto simp add:context_rw)\ndone\n\nlemma log_at_context :\n \"log_as_set s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  log_as_set s1 \\<subseteq> log_as_set (vctx_logs v2)\"\nusing log_at_context_aux\napply (auto)\ndone\n\nlemma log_from_context :\n \"log_as_set s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  vctx_logs v2 = s1\"\nusing log_at_context [of s1 v2 c2]\n  and maximality_log [of s1 \"vctx_logs v2\"]\nby force\n\n(* external programs *)\n\nlemma maximal_ext_length :\n   \"ext_program_as_set s1 \\<subseteq> ext_program_as_set s2 \\<Longrightarrow>\n    program_length (s1 addr) = program_length (s2 addr)\"\napply(auto simp add:context_rw)\ndone\n\nlemma maximal_ext_content :\n   \"ext_program_as_set s1 \\<subseteq> ext_program_as_set s2 \\<Longrightarrow>\n    program_as_natural_map (s1 addr) =\n    program_as_natural_map (s2 addr)\"\napply(auto simp add:context_rw)\napply blast\ndone\n\nlemma ext_at_context :\n \"ext_program_as_set s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  ext_program_as_set s1 \\<subseteq> ext_program_as_set (vctx_ext_program v2)\"\napply(auto simp add:context_rw)\napply blast\ndone\n\nlemma ext_length_from_context :\n \"ext_program_as_set s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  program_length (vctx_ext_program v2 addr) = program_length (s1 addr)\"\nusing ext_at_context [of s1 v2 c2]\n  and maximal_ext_length [of s1 \"vctx_ext_program v2\"]\nby force\n\nlemma ext_content_from_context :\n \"ext_program_as_set s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  program_as_natural_map (vctx_ext_program v2 addr) =\n  program_as_natural_map (s1 addr)\"\nusing ext_at_context [of s1 v2 c2]\n  and maximal_ext_content [of s1 \"vctx_ext_program v2\"]\nby force\n\nlemma ext_program_same :\n   \"(\\<forall>addr. program_length (p1 addr) = program_length (p2 addr)) \\<Longrightarrow>\n    (\\<forall>addr. program_as_natural_map (p1 addr) =\n            program_as_natural_map (p2 addr)) \\<Longrightarrow>\n    ext_program_as_set p1 = ext_program_as_set p2\"\napply(simp add:ext_program_as_set_def)\ndone\n\n(* account existence *)\n\nlemma maximality_existence :\n \"account_existence_as_set m1 \\<subseteq> account_existence_as_set m2 \\<Longrightarrow>\n  m1 = m2\"\napply(auto simp add:context_rw)\ndone\n\nlemma existence_at_context :\n \"account_existence_as_set s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  account_existence_as_set s1 \\<subseteq> account_existence_as_set (vctx_account_existence v2)\"\napply(auto simp add:context_rw)\ndone\n\nlemma existence_from_context :\n \"account_existence_as_set s1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n  vctx_account_existence v2 = s1\"\n by (metis existence_at_context maximality_existence)\n\n\n(* lemmas for all obvious subsets *)\n\nlemma stack_subset :\n  \"stack_as_set (vctx_stack v1) \\<subseteq> contexts_as_set v1 c1\"\nby(auto simp add:context_rw)\n\nlemma memory_subset :\n  \"memory_as_set (vctx_memory v1) \\<subseteq> contexts_as_set v1 c1\"\nby(auto simp add:context_rw)\n\nlemma storage_subset :\n  \"storage_as_set (vctx_storage v1) \\<subseteq> contexts_as_set v1 c1\"\nby(auto simp add:context_rw)\n\nlemma balance_subset :\n  \"balance_as_set (vctx_balance v1) \\<subseteq> contexts_as_set v1 c1\"\nby (auto simp add:context_rw)\n\nlemma existence_subset :\n  \"account_existence_as_set (vctx_account_existence v1) \\<subseteq> contexts_as_set v1 c1\"\nby (auto simp add:context_rw)\n\nlemma data_sent_subset :\n  \"data_sent_as_set (vctx_data_sent v1) \\<subseteq> contexts_as_set v1 c1\"\nby (auto simp add:context_rw)\n\nlemma ext_program_subset :\n  \"ext_program_as_set (vctx_ext_program v1) \\<subseteq> contexts_as_set v1 c1\"\nby (auto simp add:context_rw)\n\nlemma log_subset :\n  \"log_as_set (vctx_logs v1) \\<subseteq> contexts_as_set v1 c1\"\nby (auto simp add:context_rw)\n\nlemma block_subset :\n  \"blockhash_as_elm (block_blockhash (vctx_block v1)) \\<subseteq> contexts_as_set v1 c1\"\nby (auto simp add:context_rw)\n\n\nlemma program_subset :\n  \"program_as_set (cctx_program c1) \\<subseteq> contexts_as_set v1 c1\"\nby (auto simp add:context_rw)\n\nlemma get_condition1 :\n   \"contexts_as_set v1 c1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n    vctx_memory_usage v1 =\n    vctx_memory_usage v2 \\<and>\n    vctx_caller v1 = vctx_caller v2 \\<and>\n    vctx_value_sent v1 =\n    vctx_value_sent v2 \\<and>\n    vctx_origin v1 = vctx_origin v2 \\<and>\n    vctx_gas v1 = vctx_gas v2 \\<and>\n    vctx_pc v1 = vctx_pc v2 \\<and>\n    block_coinbase (vctx_block v1) =\n    block_coinbase (vctx_block v2) \\<and>\n    block_timestamp (vctx_block v1) =\n    block_timestamp (vctx_block v2) \\<and>\n    block_difficulty (vctx_block v1) =\n    block_difficulty (vctx_block v2) \\<and>\n    block_gaslimit (vctx_block v1) =\n    block_gaslimit (vctx_block v2) \\<and>\n    block_number (vctx_block v1) =\n    block_number (vctx_block v2) \\<and>\n    cctx_this c1 = cctx_this c2\"\napply(simp add:context_rw)\ndone\n\nlemma eq_class :\n    \"vctx_memory_usage v1 = vctx_memory_usage v2 \\<Longrightarrow>\n    vctx_caller v1 = vctx_caller v2 \\<Longrightarrow>\n    vctx_value_sent v1 = vctx_value_sent v2 \\<Longrightarrow>\n    vctx_gasprice v1 = vctx_gasprice v2 \\<Longrightarrow>\n    vctx_origin v1 = vctx_origin v2 \\<Longrightarrow>\n    vctx_gas v1 = vctx_gas v2 \\<Longrightarrow>\n    vctx_pc v1 = vctx_pc v2 \\<Longrightarrow>\n    vctx_data_sent v1 = vctx_data_sent v2 \\<Longrightarrow>\n    block_coinbase (vctx_block v1) =\n    block_coinbase (vctx_block v2) \\<Longrightarrow>\n    block_blockhash (vctx_block v1) =\n    block_blockhash (vctx_block v2) \\<Longrightarrow>\n    block_timestamp (vctx_block v1) =\n    block_timestamp (vctx_block v2) \\<Longrightarrow>\n    block_difficulty (vctx_block v1) =\n    block_difficulty (vctx_block v2) \\<Longrightarrow>\n    block_gaslimit (vctx_block v1) =\n    block_gaslimit (vctx_block v2) \\<Longrightarrow>\n    block_number (vctx_block v1) = block_number (vctx_block v2) \\<Longrightarrow>\n    vctx_logs v1 = vctx_logs v2 \\<Longrightarrow>\n    vctx_stack v1 = vctx_stack v2 \\<Longrightarrow>\n    vctx_memory v1 = vctx_memory v2 \\<Longrightarrow>\n    vctx_storage v1 = vctx_storage v2 \\<Longrightarrow>\n    vctx_balance v1 = vctx_balance v2 \\<Longrightarrow>\n    vctx_account_existence v1 = vctx_account_existence v2 \\<Longrightarrow>\n    program_inst (cctx_program c1) = program_inst (cctx_program c2) \\<Longrightarrow>\n    cctx_this c1 = cctx_this c2 \\<Longrightarrow>\n    (\\<forall>addr. program_length (vctx_ext_program v1 addr) =\n            program_length (vctx_ext_program v2 addr)) \\<Longrightarrow>\n    (\\<forall>addr. program_as_natural_map (vctx_ext_program v1 addr) =\n            program_as_natural_map (vctx_ext_program v2 addr)) \\<Longrightarrow>\n    contexts_as_set v1 c1 = contexts_as_set v2 c2\"\napply(simp add:contexts_as_set_def constant_ctx_as_set_def\n  variable_ctx_as_set_def)\napply auto\nusing program_inst_same apply blast\nusing ext_program_same apply blast\nusing program_inst_same apply blast\nusing ext_program_same apply blast\ndone\n\nlemma maximality :\n   \"contexts_as_set v1 c1 \\<subseteq> contexts_as_set v2 c2 \\<Longrightarrow>\n    contexts_as_set v1 c1 = contexts_as_set v2 c2\"\napply (rule eq_class)\napply(simp add:context_rw)\napply(simp add:context_rw)\napply(simp add:context_rw)\napply(simp add:context_rw)\napply(simp add:context_rw)\napply(simp add:context_rw)\napply(simp add:context_rw)\n  apply (metis data_from_context data_sent_subset order.trans)\napply(simp add:context_rw)\nusing block_from_context and block_subset\napply force\napply(simp add:context_rw)\napply(simp add:context_rw)\napply(simp add:context_rw)\napply(simp add:context_rw)\nusing log_from_context and log_subset\napply force\nusing stack_from_context and stack_subset\napply force\nusing memory_from_context and memory_subset\napply force\nusing storage_from_context and storage_subset\napply force\nusing balance_from_context and balance_subset apply force\nusing existence_from_context and existence_subset apply force\nusing program_from_context and program_subset apply force\napply(simp add:context_rw)\nusing ext_length_from_context and ext_program_subset apply force\nusing ext_content_from_context and ext_program_subset apply force\ndone\n\n(* Looping *)\n(*\ndefinition zero :: \"'a set_pred\" where\n\"zero = (\\<lambda>x. False)\"\n\nlemma zero_add : \"zero ## a = a\"\napply (simp add:zero_def sep_add_def)\ndone\n\nlemma zero_mul : \"zero ** a = zero\"\napply (simp add:zero_def sep_def)\ndone\n\nlemma zero_triple : \"triple net {} zero {} p\"\napply (auto simp add:zero_mul triple_def zero_def sep_def)\ndone\n\nlemma loop_triple :\n  \"(\\<forall>x. \\<exists>y. y < x \\<and> triple net {} (p x) {} (p y ## q)) \\<Longrightarrow>\n    p (0::nat) = zero \\<Longrightarrow>\n    triple net {} (p x) {} q\"\napply auto\ndone\n\nlemma triple_three :\n  \"triple net {} p2 {} (q ## p1) \\<Longrightarrow>\n   triple net {} p1 {} (q ## p0) \\<Longrightarrow>\n   triple net {} p2 {} (q ## p0)\"\napply (auto simp:triple_def failed_for_reasons_def)\napply(drule_tac x = co_ctx in spec)\napply(drule_tac x = co_ctx in spec)\napply auto\napply(drule_tac x = presult in spec)\napply(drule_tac x = rest in spec)\napply auto\napply(drule_tac x = stopper in spec)\napply auto\napply (auto simp:sep_add_def)\napply(drule_tac x = \"program_sem stopper co_ctx k net presult\" in spec)\napply(drule_tac x = rest in spec)\napply auto\napply(drule_tac x = stopper in spec)\napply auto\ndone\n\nlemma loop_triple2 :\n  \"(\\<forall>x. triple net {} (p x) {} (p (x-1) ## q)) \\<Longrightarrow>\n    triple net {} (p x) {} (p (0::nat) ## q)\"\napply (induction x)\napply auto\n  apply (metis diff_0_eq_0)\napply(drule_tac x = \"Suc x\" in spec)\napply auto\napply (rule triple_three)\napply auto\ndone\n\nlemma loop_triple_int :\n  \"(\\<forall>x. triple net {} (p x) {} (p (x-1) ## q)) \\<Longrightarrow>\n    \\<exists>y. y < (0::int) \\<and> triple net {} (p x) {} (p y ## q)\"\napply (induction x)\nsubgoal for n\napply (induction n)\n  apply force\napply auto\napply(drule_tac x = \"int (Suc n)\" in spec)\napply auto\nusing triple_three\n  by blast\n  by force\n\ndefinition stable :: \"network \\<Rightarrow> state_element set_pred \\<Rightarrow> bool\" where\n\"stable net pre ==\n    \\<forall> co_ctx presult rest stopper. no_assertion co_ctx \\<longrightarrow>\n       (pre ** rest) (instruction_result_as_set co_ctx presult) \\<longrightarrow>\n       (\\<forall> k.\n         (pre ** rest) (instruction_result_as_set co_ctx (program_sem stopper co_ctx k net presult)))\"\n\n\nlemma triple_stable :\n   \"triple net {} p {} (q##r) \\<Longrightarrow>\n    triple net {} (p##r) {} (q##r)\"\n  using triple_tauto triple_three by fastforce\n\nlemma triple_stable2 :\n   \"triple net {} p {} (q##s) \\<Longrightarrow>\n    triple net {} s {} r \\<Longrightarrow>\n    triple net {} (p##r) {} (q##r)\"\n  by (metis sep_add_def triple_stable triple_three weaken_post)\n\nlemma loop_triple_int2 :\n  \"(\\<forall>x. triple net {} (p x) {} (p (x-1) ## q x)) \\<Longrightarrow>\n   (\\<forall>x. triple net {} (q x) {} (q (x+1))) \\<Longrightarrow>\n   \\<exists>y. y < (0::int) \\<and> triple net {} (p x) {} (p y ## q x)\"\napply (induction x)\nsubgoal for n\napply (induction n)\n  apply (smt semiring_1_class.of_nat_simps(1))\napply auto\napply(drule_tac x = \"int (Suc n)\" in spec)\napply(drule_tac x = \"int n\" in spec)\napply auto\nsubgoal for n y\napply (rule exI[of _ y])\napply auto\n  by (smt sep_add_assoc sep_add_commute sep_add_never triple_stable2 triple_three)\ndone\n  by (smt negative_zle)\n\nlemma loop_triple_int3 :\n  \"(\\<forall>x. triple net {} (p x) {} (p (x-1) ## q x)) \\<Longrightarrow>\n   (\\<forall>x. triple net {} (q x) {} (q (x+1))) \\<Longrightarrow>\n   \\<exists>y. y < (0::int) \\<and> y \\<le> x \\<and> triple net {} (p x) {} (p y ## q x)\"\napply (induction x)\nsubgoal for n\napply (induction n)\n  apply (smt semiring_1_class.of_nat_simps(1))\napply auto\napply(drule_tac x = \"int (Suc n)\" in spec)\napply(drule_tac x = \"int n\" in spec)\napply auto\nsubgoal for n y\napply (rule exI[of _ y])\napply auto\n  by (smt sep_add_assoc sep_add_commute sep_add_never triple_stable2 triple_three)\ndone\n  by (smt negative_zle)\n\n\n\n\ndefinition ex_pred :: \"('b \\<Rightarrow> 'a set_pred) \\<Rightarrow> 'a set_pred\" where\n\"ex_pred pred = (\\<lambda>s. \\<exists>y. pred y s)\"\n\ndefinition s_triple :: \"network \\<Rightarrow> state_element set_pred \\<Rightarrow> state_element set_pred \\<Rightarrow> bool\" where\n\"s_triple net pre post ==\n    \\<forall> co_ctx presult rest stopper. no_assertion co_ctx \\<longrightarrow>\n       (pre ** rest) (instruction_result_as_set co_ctx presult) \\<longrightarrow>\n       (\\<exists> k.\n         (post ** rest) (instruction_result_as_set co_ctx (program_sem stopper co_ctx k net presult)))\"\n\n\nlemma s_triple_eq : \"s_triple net p q = triple net {} p {} q\"\napply (auto simp add: triple_def s_triple_def failed_for_reasons_def)\ndone\n\ndefinition failures :: \"failure_reason set \\<Rightarrow> state_element set_pred\" where\n\"failures fails = (\\<lambda>s.\n   \\<exists>lst. set lst \\<subseteq> fails \\<and> set lst \\<noteq> {} \\<and>\n   s = {ContinuingElm False,\n    ContractActionElm (ContractFail lst)})\"\n\nlemma s_triple_eq2 :\n   \"s_triple net (p**code c) (q**code c) = triple net {} p c q\"\napply (auto simp add: triple_def s_triple_def failed_for_reasons_def)\ndone\n\nlemma no_annotation_failure :\n \"no_assertion co_ctx \\<Longrightarrow>\n  presult \\<noteq> InstructionAnnotationFailure \\<Longrightarrow>\n  program_sem stopper co_ctx k net presult \\<noteq> InstructionAnnotationFailure\"\napply(cases presult)\napply (simp add:program_sem.simps failed_for_reasons_def\n  program_annotation no_reasons_next)\nsubgoal for v1\napply (induction k arbitrary:v1 presult)\napply (auto simp add:program_sem.simps failed_for_reasons_def\n  program_annotation no_reasons_next)\napply (case_tac \"next_state stopper co_ctx net\n             (InstructionContinue v1)\")\napply auto\ndefer\n  apply (simp add: program_environment)\napply(simp add:next_state_def)\napply(case_tac \"vctx_next_instruction v1 co_ctx\"; auto)\napply(case_tac \"check_resources v1 co_ctx (vctx_stack v1) a net\"; auto)\nusing no_annotation_inst by force\n  apply (auto simp add: program_environment)\ndone\n\nlemma code_elm_preserved :\n\"no_assertion co_ctx \\<Longrightarrow>\n CodeElm (pos, i) \\<in> instruction_result_as_set co_ctx presult \\<Longrightarrow>\n CodeElm (pos, i) \\<in> instruction_result_as_set co_ctx\n (program_sem stopper co_ctx k net presult)\"\napply (cases presult; auto)\napply(case_tac \"program_sem stopper co_ctx k net\n             (InstructionContinue x1)\")\napply (auto simp add:context_rw instruction_result_as_set_def)\nusing no_annotation_failure apply force\nusing no_annotation_failure apply force\napply(case_tac \"program_sem stopper co_ctx k net\n             presult\")\napply (auto simp add:context_rw instruction_result_as_set_def)\nusing no_annotation_failure apply force\napply(case_tac \"program_sem stopper co_ctx k net\n             presult\")\napply (auto simp add:context_rw instruction_result_as_set_def)\nusing no_annotation_failure apply force\ndone\n\nlemma continue_elm_false :\n\"ContinuingElm False \\<notin>\n       instruction_result_as_set co_ctx\n        (InstructionContinue x1)\"\napply(auto simp:context_rw instruction_result_as_set_def)\ndone\n\nlemma get_action_elm :\n\"ContractActionElm act \\<in>\n       instruction_result_as_set co_ctx\n        (InstructionToEnvironment act2 v2 zz) \\<Longrightarrow>\n act = act2\"\napply(auto simp:context_rw instruction_result_as_set_def)\ndone\n\nlemma s_triple_imp :\n   \"s_triple net (p**code c) (q**code c ##failures f) \\<Longrightarrow>\n    triple net f p c q\"\napply (auto simp add: triple_def s_triple_def sep_add_def)\napply (drule_tac x = co_ctx in spec)\napply clarsimp\napply (drule_tac x = presult and y = rest in spec2)\napply clarsimp\napply (drule_tac x = stopper in spec)\napply clarsimp\nsubgoal for co_ctx presult rest stopper k\napply (rule_tac exI[of _ k])\napply auto\nusing code_elm_preserved apply fastforce\n\napply (auto simp add:sep_def failures_def\n  failed_for_reasons_def)\nsubgoal for u ua v va\napply (rule exI [of _ \"(va -\n          {CodeElm (pos, i) |pos i. (pos, i) \\<in> c})\"])\napply auto\nproof -\n  assume a1: \"rest ua\"\n  assume a2: \"ua \\<union> va = instruction_result_as_set co_ctx (program_sem stopper co_ctx k net presult)\"\n  assume a3: \"ua \\<inter> va = {}\"\n  assume \"{CodeElm (pos, i) |pos i. (pos, i) \\<in> c} \\<subseteq> va\"\n  then have f4: \"ua \\<inter> {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} = {}\"\n    using a3 by blast\n  have \"\\<forall>S. (va - S) \\<inter> ua = {} \\<or> {} - ua \\<inter> S \\<noteq> {}\"\n    using a3 by blast\n  then have \"(va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c}) \\<inter> ua = {} \\<and> ua \\<union> va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} = ua \\<union> (va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c})\"\n    using f4 by (simp add: Diff_triv Un_Diff)\n  then show \"\\<exists>S. rest S \\<and> va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} \\<union> S = instruction_result_as_set co_ctx (program_sem stopper co_ctx k net presult) - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} \\<and> (va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c}) \\<inter> S = {}\"\n    using a2 a1 by auto\nqed\napply (cases \"program_sem stopper co_ctx k net presult\")\napply simp\nsubgoal for u ua v lst x1\nusing continue_elm_false[of co_ctx x1]\napply auto\ndone\napply simp\nsubgoal for u ua v lst act vctx x33\napply (cases act; simp)\nusing get_action_elm\n [of \"ContractFail lst\" co_ctx act vctx x33]\n  apply (metis contract_action.distinct(5) insertI1 insert_commute)\nusing get_action_elm\n [of \"ContractFail lst\" co_ctx act vctx x33]\n  apply (metis contract_action.distinct insertI1 insert_commute)\nusing get_action_elm\n [of \"ContractFail lst\" co_ctx act vctx x33]\n  apply (metis contract_action.distinct insertI1 insert_commute)\ndefer\nusing get_action_elm\n [of \"ContractFail lst\" co_ctx act vctx x33]\n  apply (metis contract_action.distinct insertI1 insert_commute)\nusing get_action_elm\n [of \"ContractFail lst\" co_ctx act vctx x33]\n  apply (metis contract_action.distinct insertI1 insert_commute)\n  by (metis \\<open>ContractActionElm (ContractFail lst) \\<in> instruction_result_as_set co_ctx (InstructionToEnvironment act vctx x33) \\<Longrightarrow> ContractFail lst = act\\<close> contract_action.inject(4) insertI1 insert_commute)\n\napply (cases \"program_sem stopper co_ctx k net presult\")\napply simp\n\nsubgoal for u ua v va x1\napply (rule exI [of _ \"(va -\n          {CodeElm (pos, i) |pos i. (pos, i) \\<in> c})\"])\napply auto\nproof -\n  assume a1: \"rest ua\"\n  assume a2: \"ua \\<union> va = instruction_result_as_set co_ctx (InstructionContinue x1)\"\n  assume a3: \"ua \\<inter> va = {}\"\n  assume a4: \"{CodeElm (pos, i) |pos i. (pos, i) \\<in> c} \\<subseteq> va\"\n  have f5: \"\\<forall>S. {} - ua \\<inter> S = ua \\<inter> (va - S)\"\n    using a3 by auto\n  have \"ua \\<union> va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} = ua \\<union> (va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c})\"\n    using a4 a3 by auto\n  then have \"(va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c}) \\<inter> ua = {} \\<and> ua \\<union> va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} = va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} \\<union> ua\"\n    using f5 by (simp add: inf_sup_aci(1) inf_sup_aci(5))\n  then show \"\\<exists>S. rest S \\<and> va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} \\<union> S = instruction_result_as_set co_ctx (InstructionContinue x1) - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} \\<and> (va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c}) \\<inter> S = {}\"\n    using a2 a1 by auto\nqed\napply simp\nsubgoal for u ua v va\napply (rule exI [of _ \"(va -\n          {CodeElm (pos, i) |pos i. (pos, i) \\<in> c})\"])\napply auto\ndone\nsubgoal for u ua v va act vctx x33\napply (rule exI [of _ \"(va -\n          {CodeElm (pos, i) |pos i. (pos, i) \\<in> c})\"])\nproof -\n  assume a1: \"rest ua\"\n  assume a2: \"ua \\<inter> va = {}\"\n  assume a3: \"{CodeElm (pos, i) |pos i. (pos, i) \\<in> c} \\<subseteq> va\"\n  assume a4: \"q (va - {CodeElm (pos, i) |pos i. (pos, i) \\<in> c})\"\n  assume \"program_sem stopper co_ctx k net presult = InstructionToEnvironment act vctx x33\"\n  assume a5: \"ua \\<union> va = instruction_result_as_set co_ctx (program_sem stopper co_ctx k net presult)\"\n  have \"ua \\<inter> {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} = {}\"\n    using a3 a2 by blast\n  then have \"va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} \\<union> ua = ua \\<union> va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} \\<and> (va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c}) \\<inter> ua = {}\"\n    using a2 by (simp add: Diff_Int_distrib Diff_triv Un_Diff inf_sup_aci(1) inf_sup_aci(5))\n  then show \"q (va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c}) \\<and> (\\<exists>S. rest S \\<and> va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} \\<union> S = instruction_result_as_set co_ctx (program_sem stopper co_ctx k net presult) - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} \\<and> (va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c}) \\<inter> S = {})\"\n    using a5 a4 a1 by auto\nqed\ndone\ndone\n\ndefinition failures2 :: \"failure_reason set \\<Rightarrow> state_element set_pred\" where\n\"failures2 fails = (\\<lambda>s.\n   \\<exists>lst. set lst \\<subseteq> fails \\<and> set lst \\<noteq> {} \\<and>\n   ContinuingElm False \\<in> s \\<and>\n   ContractActionElm (ContractFail lst) \\<in> s)\"\n\nlemma s_triple_imp2 :\n   \"s_triple net (p**code c) (q**code c ##failures2 f) \\<Longrightarrow> triple net f p c q\"\napply (auto simp add: triple_def s_triple_def sep_add_def)\napply (drule_tac x = co_ctx in spec)\napply clarsimp\napply (drule_tac x = presult and y = rest in spec2)\napply clarsimp\napply (drule_tac x = stopper in spec)\napply clarsimp\nsubgoal for co_ctx presult rest stopper k\napply (rule_tac exI[of _ k])\napply auto\nusing code_elm_preserved apply fastforce\n\napply (auto simp add:sep_def failures2_def\n  failed_for_reasons_def)\nsubgoal for u ua v va\napply (rule exI [of _ \"(va -\n          {CodeElm (pos, i) |pos i. (pos, i) \\<in> c})\"])\napply auto\nproof -\n  assume a1: \"rest ua\"\n  assume a2: \"ua \\<union> va = instruction_result_as_set co_ctx (program_sem stopper co_ctx k net presult)\"\n  assume a3: \"ua \\<inter> va = {}\"\n  assume \"{CodeElm (pos, i) |pos i. (pos, i) \\<in> c} \\<subseteq> va\"\n  then have f4: \"ua \\<inter> {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} = {}\"\n    using a3 by blast\n  have \"\\<forall>S. (va - S) \\<inter> ua = {} \\<or> {} - ua \\<inter> S \\<noteq> {}\"\n    using a3 by blast\n  then have \"(va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c}) \\<inter> ua = {} \\<and> ua \\<union> va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} = ua \\<union> (va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c})\"\n    using f4 by (simp add: Diff_triv Un_Diff)\n  then show \"\\<exists>S. rest S \\<and> va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} \\<union> S = instruction_result_as_set co_ctx (program_sem stopper co_ctx k net presult) - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} \\<and> (va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c}) \\<inter> S = {}\"\n    using a2 a1 by auto\nqed\napply (cases \"program_sem stopper co_ctx k net presult\")\napply simp\nsubgoal for u ua v va lst x1\nusing continue_elm_false[of co_ctx x1]\napply auto\ndone\napply auto\napply (cases \"program_sem stopper co_ctx k net presult\")\napply auto\nsubgoal for u ua v va lst x31 x32 x33\napply (rule exI [of _ \"(va -\n          {CodeElm (pos, i) |pos i. (pos, i) \\<in> c})\"])\napply auto\n  apply (metis Un_upper2 get_action_elm subset_iff)\n  by (metis Un_upper2 get_action_elm subset_iff)\nsubgoal for u ua v va\napply (rule exI [of _ \"(va -\n          {CodeElm (pos, i) |pos i. (pos, i) \\<in> c})\"])\napply auto\nproof -\n  assume a1: \"rest ua\"\n  assume a2: \"ua \\<union> va = instruction_result_as_set co_ctx (program_sem stopper co_ctx k net presult)\"\n  assume a3: \"ua \\<inter> va = {}\"\n  assume \"{CodeElm (pos, i) |pos i. (pos, i) \\<in> c} \\<subseteq> va\"\n  then have \"ua \\<inter> {} = ua \\<inter> {CodeElm (i, ia) |i ia. (i, ia) \\<in> c}\"\n  using a3 by auto\n  then have \"ua \\<union> va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} = va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} \\<union> ua\"\n    by auto\n  then show \"\\<exists>S. rest S \\<and> va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} \\<union> S = instruction_result_as_set co_ctx (program_sem stopper co_ctx k net presult) - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c} \\<and> (va - {CodeElm (i, ia) |i ia. (i, ia) \\<in> c}) \\<inter> S = {}\"\n    using a3 a2 a1 by auto\n  qed\ndone\ndone\n\nlemma s_triple_imp2 :\n   \"triple net f p c q \\<Longrightarrow> s_triple net (p**code c) (q**code c ##failures2 f)\"\napply (auto simp add: triple_def s_triple_def sep_add_def)\napply (drule_tac x = co_ctx in spec)\napply clarsimp\napply (drule_tac x = presult and y = rest in spec2)\napply clarsimp\napply (drule_tac x = stopper in spec)\napply clarsimp\nsubgoal for co_ctx presult rest stopper k\napply (rule_tac exI[of _ k])\napply auto\n\napply (auto simp add:sep_def failures_def\n  failed_for_reasons_def)[1]\nsubgoal for u ua v va\napply (rule exI [of _ va])\napply clarsimp\napply (rule exI [of _\n \"ua \\<union> {CodeElm (pos, i) |pos i. (pos, i) \\<in> c}\"])\napply auto\n  by (metis (no_types, lifting) Diff_cancel Int_Diff Un_Diff inf_commute inf_sup_absorb inf_sup_aci(1) sup_bot.right_neutral)\n\napply (cases \"program_sem stopper co_ctx k net presult\")\napply (simp add:failed_for_reasons_def)\napply (simp add:failed_for_reasons_def)\napply (simp add:failed_for_reasons_def)\napply clarsimp\noops\n*)\n\nend\n", "meta": {"author": "pirapira", "repo": "eth-isabelle", "sha": "d0bb02b3e64a2046a7c9670545d21f10bccd7b27", "save_path": "github-repos/isabelle/pirapira-eth-isabelle", "path": "github-repos/isabelle/pirapira-eth-isabelle/eth-isabelle-d0bb02b3e64a2046a7c9670545d21f10bccd7b27/Hoare/EvmFacts.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6442251064863697, "lm_q2_score": 0.4532618480153861, "lm_q1q2_score": 0.2920026623039208}}
{"text": "section \\<open>State Separators\\<close>\n\ntext \\<open>This theory defined state separators.\n      A state separator @{text \"S\"} of some pair of states @{text \"q1\"}, @{text \"q2\"} of some FSM @{text \"M\"} \n      is an acyclic single-input FSM based on the product machine @{text \"P\"} of @{text \"M\"} with initial state\n      @{text \"q1\"} and @{text \"M\"} with initial state @{text \"q2\"} such that every maximal length\n      sequence in the language of @{text \"S\"} is either in the language of @{text \"q1\"} or the\n      language of @{text \"q2\"}, but not both.\n      That is, @{text \"C\"} represents a strategy of distinguishing @{text \"q1\"} and @{text \"q2\"} in \n      every complete submachine of @{text \"P\"}.\n      In testing, separators are used to distinguish states reached in the SUT to establish a lower\n      bound on the number of distinct states in the SUT.\\<close>\n\n\ntheory State_Separator\nimports Product_FSM Backwards_Reachability_Analysis \"HOL-Library.Product_Lexorder\"\nbegin\n\nsubsection \\<open>Canonical Separators\\<close>\n\nsubsubsection \\<open>Construction\\<close>\n\nlift_definition canonical_separator' :: \"('a,'b,'c) fsm \\<Rightarrow> (('a \\<times> 'a),'b,'c) fsm \\<Rightarrow> 'a \\<Rightarrow> 'a \\<Rightarrow> (('a \\<times> 'a) + 'a,'b,'c) fsm\" is FSM_Impl.canonical_separator'\nproof -\n  fix A :: \"('a,'b,'c) fsm_impl\"\n  fix B :: \"('a \\<times> 'a,'b,'c) fsm_impl\"\n  fix q1 :: 'a\n  fix q2 :: 'a\n  assume \"well_formed_fsm A\" and \"well_formed_fsm B\"\n\n  then have p1a: \"fsm_impl.initial A \\<in> fsm_impl.nodes A\"\n        and p2a: \"finite (fsm_impl.nodes A)\"\n        and p3a: \"finite (fsm_impl.inputs A)\"\n        and p4a: \"finite (fsm_impl.outputs A)\"\n        and p5a: \"finite (fsm_impl.transitions A)\"\n        and p6a: \"(\\<forall>t\\<in>fsm_impl.transitions A.\n            t_source t \\<in> fsm_impl.nodes A \\<and>\n            t_input t \\<in> fsm_impl.inputs A \\<and> t_target t \\<in> fsm_impl.nodes A \\<and>\n                                             t_output t \\<in> fsm_impl.outputs A)\"\n        and p1b: \"fsm_impl.initial B \\<in> fsm_impl.nodes B\"\n        and p2b: \"finite (fsm_impl.nodes B)\"\n        and p3b: \"finite (fsm_impl.inputs B)\"\n        and p4b: \"finite (fsm_impl.outputs B)\"\n        and p5b: \"finite (fsm_impl.transitions B)\"\n        and p6b: \"(\\<forall>t\\<in>fsm_impl.transitions B.\n            t_source t \\<in> fsm_impl.nodes B \\<and>\n            t_input t \\<in> fsm_impl.inputs B \\<and> t_target t \\<in> fsm_impl.nodes B \\<and>\n                                             t_output t \\<in> fsm_impl.outputs B)\"\n    by simp+\n\n  let ?P = \"FSM_Impl.canonical_separator' A B q1 q2\"\n\n  show \"well_formed_fsm ?P\" proof (cases \"fsm_impl.initial B = (q1,q2)\")\n    case False\n    then show ?thesis by auto\n  next\n    case True\n\n    let ?f = \"(\\<lambda>qx . (case (set_as_map (image (\\<lambda>(q,x,y,q') . ((q,x),y)) (fsm_impl.transitions A))) qx of Some yqs \\<Rightarrow> yqs | None \\<Rightarrow> {}))\"\n  \n    have \"\\<And> qx . (\\<lambda>qx . (case (set_as_map (image (\\<lambda>(q,x,y,q') . ((q,x),y)) (fsm_impl.transitions A))) qx of Some yqs \\<Rightarrow> yqs | None \\<Rightarrow> {})) qx = (\\<lambda> qx . {z. (qx, z) \\<in> (\\<lambda>(q, x, y, q'). ((q, x), y)) ` fsm_impl.transitions A}) qx\"\n    proof -\n      fix qx\n      show \"\\<And> qx . (\\<lambda>qx . (case (set_as_map (image (\\<lambda>(q,x,y,q') . ((q,x),y)) (fsm_impl.transitions A))) qx of Some yqs \\<Rightarrow> yqs | None \\<Rightarrow> {})) qx = (\\<lambda> qx . {z. (qx, z) \\<in> (\\<lambda>(q, x, y, q'). ((q, x), y)) ` fsm_impl.transitions A}) qx\"\n        unfolding set_as_map_def by (cases \"\\<exists>z. (qx, z) \\<in> (\\<lambda>(q, x, y, q'). ((q, x), y)) ` fsm_impl.transitions A\"; auto)\n    qed\n    moreover have \"\\<And> qx . (\\<lambda> qx . {z. (qx, z) \\<in> (\\<lambda>(q, x, y, q'). ((q, x), y)) ` fsm_impl.transitions A}) qx = (\\<lambda> qx . {y | y . \\<exists> q' . (fst qx, snd qx, y, q') \\<in> fsm_impl.transitions A}) qx\"\n    proof -\n      fix qx \n      show \"(\\<lambda> qx . {z. (qx, z) \\<in> (\\<lambda>(q, x, y, q'). ((q, x), y)) ` fsm_impl.transitions A}) qx = (\\<lambda> qx . {y | y . \\<exists> q' . (fst qx, snd qx, y, q') \\<in> fsm_impl.transitions A}) qx\"\n        by force\n    qed\n    ultimately have *:\" ?f = (\\<lambda> qx . {y | y . \\<exists> q' . (fst qx, snd qx, y, q') \\<in> fsm_impl.transitions A})\" \n      by blast\n      \n    let ?shifted_transitions' = \"shifted_transitions (fsm_impl.transitions B)\"\n    let ?distinguishing_transitions_lr = \"distinguishing_transitions ?f q1 q2 (fsm_impl.nodes B) (fsm_impl.inputs B)\"\n    let ?ts = \"?shifted_transitions' \\<union> ?distinguishing_transitions_lr\"\n  \n    have \"FSM_Impl.nodes ?P = (image Inl (FSM_Impl.nodes B)) \\<union> {Inr q1, Inr q2}\"\n    and  \"FSM_Impl.transitions ?P = ?ts\"\n      unfolding FSM_Impl.canonical_separator'.simps Let_def True by simp+\n\n    have p2: \"finite (fsm_impl.nodes ?P)\"\n      unfolding \\<open>FSM_Impl.nodes ?P = (image Inl (FSM_Impl.nodes B)) \\<union> {Inr q1, Inr q2}\\<close> using p2b by blast\n  \n    have \"fsm_impl.initial ?P = Inl (q1,q2)\" by auto\n    then have p1: \"fsm_impl.initial ?P \\<in> fsm_impl.nodes ?P\" \n      using p1a p1b unfolding canonical_separator'.simps True by auto\n    have p3: \"finite (fsm_impl.inputs ?P)\"\n      using p3a p3b by auto\n    have p4: \"finite (fsm_impl.outputs ?P)\"\n      using p4a p4b by auto\n\n    have \"finite (fsm_impl.nodes B \\<times> fsm_impl.inputs B)\"\n      using p2b p3b by blast\n    moreover have **: \"\\<And> x q1 . finite ({y |y. \\<exists>q'. (fst (q1, x), snd (q1, x), y, q') \\<in> fsm_impl.transitions A})\"\n    proof - \n      fix x q1\n      have \"{y |y. \\<exists>q'. (fst (q1, x), snd (q1, x), y, q') \\<in> fsm_impl.transitions A} = {t_output t | t . t \\<in> fsm_impl.transitions A \\<and> t_source t = q1 \\<and> t_input t = x}\"\n        by auto\n      then have \"{y |y. \\<exists>q'. (fst (q1, x), snd (q1, x), y, q') \\<in> fsm_impl.transitions A} \\<subseteq> image t_output (fsm_impl.transitions A)\"\n        unfolding fst_conv snd_conv by blast\n      moreover have \"finite (image t_output (fsm_impl.transitions A))\"\n        using p5a by auto\n      ultimately show \"finite ({y |y. \\<exists>q'. (fst (q1, x), snd (q1, x), y, q') \\<in> fsm_impl.transitions A})\"\n        by (simp add: finite_subset)\n    qed\n    ultimately have \"finite ?distinguishing_transitions_lr\"\n      unfolding * distinguishing_transitions_def by force\n    moreover have \"finite ?shifted_transitions'\"\n      unfolding shifted_transitions_def using p5b by auto\n    ultimately have \"finite ?ts\" by blast\n    then have p5: \"finite (fsm_impl.transitions ?P)\"\n      by simp\n     \n    have \"fsm_impl.inputs ?P = fsm_impl.inputs A \\<union> fsm_impl.inputs B\"\n      using True by auto\n    have \"fsm_impl.outputs ?P = fsm_impl.outputs A \\<union> fsm_impl.outputs B\"\n      using True by auto\n  \n    have \"\\<And> t . t \\<in> ?shifted_transitions' \\<Longrightarrow> t_source t \\<in> fsm_impl.nodes ?P \\<and> t_target t \\<in> fsm_impl.nodes ?P\"\n      unfolding \\<open>FSM_Impl.nodes ?P = (image Inl (FSM_Impl.nodes B)) \\<union> {Inr q1, Inr q2}\\<close> shifted_transitions_def \n      using p6b by force\n    moreover have \"\\<And> t . t \\<in> ?distinguishing_transitions_lr \\<Longrightarrow> t_source t \\<in> fsm_impl.nodes ?P \\<and> t_target t \\<in> fsm_impl.nodes ?P\"\n      unfolding \\<open>FSM_Impl.nodes ?P = (image Inl (FSM_Impl.nodes B)) \\<union> {Inr q1, Inr q2}\\<close> distinguishing_transitions_def * by force\n    ultimately have \"\\<And> t . t \\<in> ?ts \\<Longrightarrow> t_source t \\<in> fsm_impl.nodes ?P \\<and> t_target t \\<in> fsm_impl.nodes ?P\"\n      by blast\n    moreover have \"\\<And> t . t \\<in> ?shifted_transitions' \\<Longrightarrow> t_input t \\<in> fsm_impl.inputs ?P \\<and> t_output t \\<in> fsm_impl.outputs ?P\"\n    proof -\n      have \"\\<And> t . t \\<in> ?shifted_transitions' \\<Longrightarrow> t_input t \\<in> fsm_impl.inputs B \\<and> t_output t \\<in> fsm_impl.outputs B\"\n        unfolding shifted_transitions_def using p6b by auto\n      then show \"\\<And> t . t \\<in> ?shifted_transitions' \\<Longrightarrow> t_input t \\<in> fsm_impl.inputs ?P \\<and> t_output t \\<in> fsm_impl.outputs ?P\"\n        unfolding \\<open>fsm_impl.inputs ?P = fsm_impl.inputs A \\<union> fsm_impl.inputs B\\<close>\n                  \\<open>fsm_impl.outputs ?P = fsm_impl.outputs A \\<union> fsm_impl.outputs B\\<close> by blast\n    qed\n    moreover have \"\\<And> t . t \\<in> ?distinguishing_transitions_lr \\<Longrightarrow> t_input t \\<in> fsm_impl.inputs ?P \\<and> t_output t \\<in> fsm_impl.outputs ?P\"\n      unfolding * distinguishing_transitions_def using p6a p6b True by auto\n    ultimately have p6: \"(\\<forall>t\\<in>fsm_impl.transitions ?P.\n              t_source t \\<in> fsm_impl.nodes ?P \\<and>\n              t_input t \\<in> fsm_impl.inputs ?P \\<and> t_target t \\<in> fsm_impl.nodes ?P \\<and>\n                                               t_output t \\<in> fsm_impl.outputs ?P)\"\n      unfolding \\<open>FSM_Impl.transitions ?P = ?ts\\<close> by blast\n  \n    show \"well_formed_fsm ?P\"\n      using p1 p2 p3 p4 p5 p6 by linarith\n  qed\nqed \n\n\nlemma canonical_separator'_simps :\n  assumes \"initial P = (q1,q2)\"\n  shows \"initial (canonical_separator' M P q1 q2) = Inl (q1,q2)\"\n        \"nodes (canonical_separator' M P q1 q2) = (image Inl (nodes P)) \\<union> {Inr q1, Inr q2}\"\n        \"inputs (canonical_separator' M P q1 q2) = inputs M \\<union> inputs P\"\n        \"outputs (canonical_separator' M P q1 q2) = outputs M \\<union> outputs P\"\n        \"transitions (canonical_separator' M P q1 q2) \n          = shifted_transitions (transitions P) \n              \\<union> distinguishing_transitions (h_out M) q1 q2 (nodes P) (inputs P)\"\n  using assms unfolding h_out_code by (transfer; auto)+\n\n\n\nfun canonical_separator :: \"('a,'b,'c) fsm \\<Rightarrow> 'a \\<Rightarrow> 'a \\<Rightarrow> (('a \\<times> 'a) + 'a,'b,'c) fsm\"  where\n  \"canonical_separator M q1 q2 = (canonical_separator' M ((product (from_FSM M q1) (from_FSM M q2))) q1 q2)\"\n\n\nlemma canonical_separator_simps :\n  assumes \"q1 \\<in> nodes M\" and \"q2 \\<in> nodes M\"\n  shows \"initial (canonical_separator M q1 q2) = Inl (q1,q2)\"\n        \"nodes (canonical_separator M q1 q2) \n            = (image Inl (nodes (product (from_FSM M q1) (from_FSM M q2)))) \\<union> {Inr q1, Inr q2}\"\n        \"inputs (canonical_separator M q1 q2) = inputs M\"\n        \"outputs (canonical_separator M q1 q2) = outputs M\"\n        \"transitions (canonical_separator M q1 q2) \n            = shifted_transitions (transitions ((product (from_FSM M q1) (from_FSM M q2)))) \n                  \\<union> distinguishing_transitions (h_out M) q1 q2 (nodes ((product (from_FSM M q1) (from_FSM M q2)))) (inputs ((product (from_FSM M q1) (from_FSM M q2))))\"\nproof -\n  have *: \"initial ((product (from_FSM M q1) (from_FSM M q2))) = (q1,q2)\"\n    unfolding restrict_to_reachable_nodes_simps product_simps using assms by auto\n  have ***: \"inputs ((product (from_FSM M q1) (from_FSM M q2))) = inputs M\"\n    unfolding restrict_to_reachable_nodes_simps product_simps using assms by auto\n  have ****: \"outputs ((product (from_FSM M q1) (from_FSM M q2))) = outputs M\"\n    unfolding restrict_to_reachable_nodes_simps product_simps using assms by auto\n  \n  show \"initial (canonical_separator M q1 q2) = Inl (q1,q2)\"\n        \"nodes (canonical_separator M q1 q2) = (image Inl (nodes (product (from_FSM M q1) (from_FSM M q2)))) \\<union> {Inr q1, Inr q2}\"\n        \"inputs (canonical_separator M q1 q2) = inputs M\"\n        \"outputs (canonical_separator M q1 q2) = outputs M\"\n        \"transitions (canonical_separator M q1 q2) = shifted_transitions (transitions ((product (from_FSM M q1) (from_FSM M q2)))) \\<union> distinguishing_transitions (h_out M) q1 q2 (nodes ((product (from_FSM M q1) (from_FSM M q2)))) (inputs ((product (from_FSM M q1) (from_FSM M q2))))\"\n    unfolding canonical_separator.simps canonical_separator'_simps[OF *, of M] *** **** by blast+\nqed\n\n\nlemma distinguishing_transitions_alt_def :\n  \"distinguishing_transitions (h_out M) q1 q2 PS (inputs M) = \n    {(Inl (q1',q2'),x,y,Inr q1) | q1' q2' x y . (q1',q2') \\<in> PS \\<and> (\\<exists> q' . (q1',x,y,q') \\<in> transitions M) \\<and> \\<not>(\\<exists> q' . (q2',x,y,q') \\<in> transitions M)}\n    \\<union> {(Inl (q1',q2'),x,y,Inr q2) | q1' q2' x y . (q1',q2') \\<in> PS \\<and> \\<not>(\\<exists> q' . (q1',x,y,q') \\<in> transitions M) \\<and> (\\<exists> q' . (q2',x,y,q') \\<in> transitions M)}\"\n   (is \"?dts = ?dl \\<union> ?dr\")\nproof -\n  have \"\\<And> t . t \\<in> ?dts \\<Longrightarrow> t \\<in> ?dl \\<or> t \\<in> ?dr\" \n    unfolding distinguishing_transitions_def h_out.simps by fastforce\n  moreover have \"\\<And> t . t \\<in> ?dl \\<or> t \\<in> ?dr \\<Longrightarrow> t \\<in> ?dts\"  \n  proof -\n    fix t assume \"t \\<in> ?dl \\<or> t \\<in> ?dr\"\n    then obtain q1' q2' where \"t_source t = Inl (q1',q2')\" and \"(q1',q2') \\<in> PS\"\n      by auto\n    \n    consider (a) \"t \\<in> ?dl\" |\n             (b) \"t \\<in> ?dr\" \n      using \\<open>t \\<in> ?dl \\<or> t \\<in> ?dr\\<close> by blast\n    then show \"t \\<in> ?dts\" proof cases\n      case a\n      then have \"t_target t = Inr q1\" and \"(\\<exists> q' . (q1',t_input t,t_output t,q') \\<in> transitions M)\" \n            and \"\\<not>(\\<exists> q' . (q2',t_input t,t_output t,q') \\<in> transitions M)\"\n        using \\<open>t_source t = Inl (q1',q2')\\<close> by force+\n      then have \"t_output t \\<in> h_out M (q1',t_input t) - h_out M (q2',t_input t)\"\n        unfolding h_out.simps by blast\n      then have \"t \\<in> (\\<lambda>y. (Inl (q1', q2'), t_input t, y, Inr q1)) ` (h_out M (q1', t_input t) - h_out M (q2', t_input t))\"\n        using \\<open>t_source t = Inl (q1',q2')\\<close> \\<open>t_target t = Inr q1\\<close>\n        by (metis (mono_tags, lifting) imageI surjective_pairing) \n      moreover have \"((q1',q2'),t_input t) \\<in> PS \\<times> inputs M\"\n        using fsm_transition_input \\<open>(\\<exists> q' . (q1',t_input t,t_output t,q') \\<in> transitions M)\\<close> \n              \\<open>(q1',q2') \\<in> PS\\<close> \n        by auto \n      ultimately show ?thesis \n        unfolding distinguishing_transitions_def by fastforce\n    next\n      case b\n      then have \"t_target t = Inr q2\" and \"\\<not>(\\<exists> q' . (q1',t_input t,t_output t,q') \\<in> transitions M)\" \n            and \"(\\<exists> q' . (q2',t_input t,t_output t,q') \\<in> transitions M)\"\n        using \\<open>t_source t = Inl (q1',q2')\\<close> by force+\n      then have \"t_output t \\<in> h_out M (q2',t_input t) - h_out M (q1',t_input t)\"\n        unfolding h_out.simps by blast\n      then have \"t \\<in> (\\<lambda>y. (Inl (q1', q2'), t_input t, y, Inr q2)) ` (h_out M (q2', t_input t) - h_out M (q1', t_input t))\"\n        using \\<open>t_source t = Inl (q1',q2')\\<close> \\<open>t_target t = Inr q2\\<close>\n        by (metis (mono_tags, lifting) imageI surjective_pairing) \n      moreover have \"((q1',q2'),t_input t) \\<in> PS \\<times> inputs M\"\n        using fsm_transition_input \\<open>(\\<exists> q' . (q2',t_input t,t_output t,q') \\<in> transitions M)\\<close> \\<open>(q1',q2') \\<in> PS\\<close> \n        by auto \n      ultimately show ?thesis \n        unfolding distinguishing_transitions_def by fastforce\n    qed\n  qed\n  ultimately show ?thesis by blast\nqed\n\n\nlemma distinguishing_transitions_alt_alt_def :\n  \"distinguishing_transitions (h_out M) q1 q2 PS (inputs M) = \n    { t . \\<exists> q1' q2' . t_source t = Inl (q1',q2') \\<and> (q1',q2') \\<in> PS \\<and> t_target t = Inr q1 \\<and> (\\<exists> t'  \\<in> transitions M . t_source t' = q1' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t) \\<and> \\<not>(\\<exists> t'  \\<in> transitions M . t_source t' = q2' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)}\n  \\<union> { t . \\<exists> q1' q2' . t_source t = Inl (q1',q2') \\<and> (q1',q2') \\<in> PS \\<and> t_target t = Inr q2 \\<and> \\<not>(\\<exists> t'  \\<in> transitions M . t_source t' = q1' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t) \\<and> (\\<exists> t'  \\<in> transitions M . t_source t' = q2' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)}\"\n  \nproof -\n  have \"{(Inl (q1',q2'),x,y,Inr q1) | q1' q2' x y . (q1',q2') \\<in> PS \\<and> (\\<exists> q' . (q1',x,y,q') \\<in> transitions M) \\<and> \\<not>(\\<exists> q' . (q2',x,y,q') \\<in> transitions M)}\n        = { t . \\<exists> q1' q2' . t_source t = Inl (q1',q2') \\<and> (q1',q2') \\<in> PS \\<and> t_target t = Inr q1 \\<and> (\\<exists> t'  \\<in> transitions M . t_source t' = q1' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t) \\<and> \\<not>(\\<exists> t'  \\<in> transitions M . t_source t' = q2' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)}\"\n    by force\n  moreover have \"{(Inl (q1',q2'),x,y,Inr q2) | q1' q2' x y . (q1',q2') \\<in> PS \\<and> \\<not>(\\<exists> q' . (q1',x,y,q') \\<in> transitions M) \\<and> (\\<exists> q' . (q2',x,y,q') \\<in> transitions M)}\n        = { t . \\<exists> q1' q2' . t_source t = Inl (q1',q2') \\<and> (q1',q2') \\<in> PS \\<and> t_target t = Inr q2 \\<and> \\<not>(\\<exists> t'  \\<in> transitions M . t_source t' = q1' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t) \\<and> (\\<exists> t'  \\<in> transitions M . t_source t' = q2' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)}\"\n    by force\n  ultimately show ?thesis  \n    unfolding distinguishing_transitions_alt_def by force\nqed\n   \n\nlemma shifted_transitions_alt_def :\n  \"shifted_transitions ts = {(Inl (q1',q2'), x, y, (Inl (q1'',q2''))) | q1' q2' x y q1'' q2'' . ((q1',q2'), x, y, (q1'',q2'')) \\<in> ts}\"   \n  unfolding shifted_transitions_def by force\n\n\nlemma canonical_separator_transitions_helper :\n  assumes \"q1 \\<in> nodes M\" and \"q2 \\<in> nodes M\"\n  shows \"transitions (canonical_separator M q1 q2) = \n          (shifted_transitions  (transitions (product (from_FSM M q1) (from_FSM M q2))))\n          \\<union> {(Inl (q1',q2'),x,y,Inr q1) | q1' q2' x y . (q1',q2') \\<in> nodes (product (from_FSM M q1) (from_FSM M q2)) \\<and> (\\<exists> q' . (q1',x,y,q') \\<in> transitions M) \\<and> \\<not>(\\<exists> q' . (q2',x,y,q') \\<in> transitions M)}\n          \\<union> {(Inl (q1',q2'),x,y,Inr q2) | q1' q2' x y . (q1',q2') \\<in> nodes (product (from_FSM M q1) (from_FSM M q2)) \\<and> \\<not>(\\<exists> q' . (q1',x,y,q') \\<in> transitions M) \\<and> (\\<exists> q' . (q2',x,y,q') \\<in> transitions M)}\"\n  unfolding canonical_separator_simps[OF assms]\n            restrict_to_reachable_nodes_simps\n            product_simps from_FSM_simps[OF assms(1)] from_FSM_simps[OF assms(2)]\n            sup.idem\n            distinguishing_transitions_alt_def \n  by blast\n\n\ndefinition distinguishing_transitions_left :: \"('a, 'b, 'c) fsm \\<Rightarrow> 'a \\<Rightarrow> 'a \\<Rightarrow> (('a \\<times> 'a + 'a) \\<times> 'b \\<times> 'c \\<times> ('a \\<times> 'a + 'a)) set\" where\n  \"distinguishing_transitions_left M q1 q2  \\<equiv> {(Inl (q1',q2'),x,y,Inr q1) | q1' q2' x y . (q1',q2') \\<in> nodes (product (from_FSM M q1) (from_FSM M q2)) \\<and> (\\<exists> q' . (q1',x,y,q') \\<in> transitions M) \\<and> \\<not>(\\<exists> q' . (q2',x,y,q') \\<in> transitions M)}\"\ndefinition distinguishing_transitions_right :: \"('a, 'b, 'c) fsm \\<Rightarrow> 'a \\<Rightarrow> 'a \\<Rightarrow> (('a \\<times> 'a + 'a) \\<times> 'b \\<times> 'c \\<times> ('a \\<times> 'a + 'a)) set\" where\n  \"distinguishing_transitions_right M q1 q2 \\<equiv> {(Inl (q1',q2'),x,y,Inr q2) | q1' q2' x y . (q1',q2') \\<in> nodes (product (from_FSM M q1) (from_FSM M q2)) \\<and> \\<not>(\\<exists> q' . (q1',x,y,q') \\<in> transitions M) \\<and> (\\<exists> q' . (q2',x,y,q') \\<in> transitions M)}\"\n\ndefinition distinguishing_transitions_left_alt :: \"('a, 'b, 'c) fsm \\<Rightarrow> 'a \\<Rightarrow> 'a \\<Rightarrow> (('a \\<times> 'a + 'a) \\<times> 'b \\<times> 'c \\<times> ('a \\<times> 'a + 'a)) set\" where\n  \"distinguishing_transitions_left_alt M q1 q2  \\<equiv> { t . \\<exists> q1' q2' . t_source t = Inl (q1',q2') \\<and> (q1',q2') \\<in> nodes (product (from_FSM M q1) (from_FSM M q2)) \\<and> t_target t = Inr q1 \\<and> (\\<exists> t'  \\<in> transitions M . t_source t' = q1' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t) \\<and> \\<not>(\\<exists> t'  \\<in> transitions M . t_source t' = q2' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)}\"\ndefinition distinguishing_transitions_right_alt :: \"('a, 'b, 'c) fsm \\<Rightarrow> 'a \\<Rightarrow> 'a \\<Rightarrow> (('a \\<times> 'a + 'a) \\<times> 'b \\<times> 'c \\<times> ('a \\<times> 'a + 'a)) set\" where\n  \"distinguishing_transitions_right_alt M q1 q2 \\<equiv> { t . \\<exists> q1' q2' . t_source t = Inl (q1',q2') \\<and> (q1',q2') \\<in> nodes (product (from_FSM M q1) (from_FSM M q2)) \\<and> t_target t = Inr q2 \\<and> \\<not>(\\<exists> t'  \\<in> transitions M . t_source t' = q1' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t) \\<and> (\\<exists> t'  \\<in> transitions M . t_source t' = q2' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)}\"\n\n\ndefinition shifted_transitions_for :: \"('a, 'b, 'c) fsm \\<Rightarrow> 'a \\<Rightarrow> 'a \\<Rightarrow> (('a \\<times> 'a + 'a) \\<times> 'b \\<times> 'c \\<times> ('a \\<times> 'a + 'a)) set\" where\n\"shifted_transitions_for M q1 q2 \\<equiv> {(Inl (t_source t),t_input t, t_output t, Inl (t_target t)) | t . t \\<in> transitions (product (from_FSM M q1) (from_FSM M q2))}\"\n\n\nlemma shifted_transitions_for_alt_def :\n  \"shifted_transitions_for M q1 q2 = {(Inl (q1',q2'), x, y, (Inl (q1'',q2''))) | q1' q2' x y q1'' q2'' . ((q1',q2'), x, y, (q1'',q2'')) \\<in> transitions (product (from_FSM M q1) (from_FSM M q2))}\"\n  unfolding shifted_transitions_for_def by auto\n\n\nlemma distinguishing_transitions_left_alt_alt_def :\n  \"distinguishing_transitions_left M q1 q2 = distinguishing_transitions_left_alt M q1 q2\" \nproof -\n  have \"\\<And> t . t \\<in> distinguishing_transitions_left M q1 q2 \\<Longrightarrow> t \\<in> distinguishing_transitions_left_alt M q1 q2\" \n  proof -\n    fix t assume \"t \\<in> distinguishing_transitions_left M q1 q2\"\n    then obtain q1' q2' x y where \"t = (Inl (q1', q2'), x, y, Inr q1)\"\n                                  \"(q1', q2') \\<in> nodes (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2))\"\n                                  \"(\\<exists>q'. (q1', x, y, q') \\<in> FSM.transitions M)\" \n                                  \"(\\<nexists>q'. (q2', x, y, q') \\<in> FSM.transitions M)\"\n      unfolding distinguishing_transitions_left_def by blast\n\n    have \"t_source t = Inl (q1', q2')\"\n      using \\<open>t = (Inl (q1', q2'), x, y, Inr q1)\\<close> by auto\n    moreover note \\<open>(q1', q2') \\<in> nodes (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2))\\<close>\n    moreover have \"t_target t = Inr q1\"\n      using \\<open>t = (Inl (q1', q2'), x, y, Inr q1)\\<close> by auto\n    moreover have \"(\\<exists>t'\\<in>FSM.transitions M. t_source t' = q1' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)\" \n      using \\<open>(\\<exists>q'. (q1', x, y, q') \\<in> FSM.transitions M)\\<close> unfolding \\<open>t = (Inl (q1', q2'), x, y, Inr q1)\\<close> by force\n    moreover have \"\\<not>(\\<exists>t'\\<in>FSM.transitions M. t_source t' = q2' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)\" \n      using \\<open>(\\<nexists>q'. (q2', x, y, q') \\<in> FSM.transitions M)\\<close> unfolding \\<open>t = (Inl (q1', q2'), x, y, Inr q1)\\<close> by force\n    ultimately show \"t \\<in> distinguishing_transitions_left_alt M q1 q2\"\n      unfolding distinguishing_transitions_left_alt_def by simp\n  qed\n  moreover have \"\\<And> t . t \\<in> distinguishing_transitions_left_alt M q1 q2 \\<Longrightarrow> t \\<in> distinguishing_transitions_left M q1 q2\"\n    unfolding distinguishing_transitions_left_alt_def distinguishing_transitions_left_def \n    by fastforce\n  ultimately show ?thesis by blast \nqed\n\n\nlemma distinguishing_transitions_right_alt_alt_def :\n  \"distinguishing_transitions_right M q1 q2 = distinguishing_transitions_right_alt M q1 q2\" \nproof -\n  have \"\\<And> t . t \\<in> distinguishing_transitions_right M q1 q2 \\<Longrightarrow> t \\<in> distinguishing_transitions_right_alt M q1 q2\" \n  proof -\n    fix t assume \"t \\<in> distinguishing_transitions_right M q1 q2\"\n    then obtain q1' q2' x y where \"t = (Inl (q1', q2'), x, y, Inr q2)\"\n                                  \"(q1', q2') \\<in> nodes (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2))\"\n                                  \"(\\<nexists>q'. (q1', x, y, q') \\<in> FSM.transitions M)\" \n                                  \"(\\<exists>q'. (q2', x, y, q') \\<in> FSM.transitions M)\"\n      unfolding distinguishing_transitions_right_def by blast\n\n    have \"t_source t = Inl (q1', q2')\"\n      using \\<open>t = (Inl (q1', q2'), x, y, Inr q2)\\<close> by auto\n    moreover note \\<open>(q1', q2') \\<in> nodes (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2))\\<close>\n    moreover have \"t_target t = Inr q2\"\n      using \\<open>t = (Inl (q1', q2'), x, y, Inr q2)\\<close> by auto\n    moreover have \"\\<not>(\\<exists>t'\\<in>FSM.transitions M. t_source t' = q1' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)\" \n      using \\<open>(\\<nexists>q'. (q1', x, y, q') \\<in> FSM.transitions M)\\<close> unfolding \\<open>t = (Inl (q1', q2'), x, y, Inr q2)\\<close> by force\n    moreover have \"(\\<exists>t'\\<in>FSM.transitions M. t_source t' = q2' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)\" \n      using \\<open>(\\<exists>q'. (q2', x, y, q') \\<in> FSM.transitions M)\\<close> unfolding \\<open>t = (Inl (q1', q2'), x, y, Inr q2)\\<close> by force\n    ultimately show \"t \\<in> distinguishing_transitions_right_alt M q1 q2\"\n      unfolding distinguishing_transitions_right_def distinguishing_transitions_right_alt_def by simp\n  qed\n  moreover have \"\\<And> t . t \\<in> distinguishing_transitions_right_alt M q1 q2 \\<Longrightarrow> t \\<in> distinguishing_transitions_right M q1 q2\"\n    unfolding distinguishing_transitions_right_def distinguishing_transitions_right_alt_def by fastforce\n  ultimately show ?thesis\n    by blast\nqed\n\n    \nlemma canonical_separator_transitions_def :\n  assumes \"q1 \\<in> nodes M\" and \"q2 \\<in> nodes M\"\n  shows \"transitions (canonical_separator M q1 q2) = \n        {(Inl (q1',q2'), x, y, (Inl (q1'',q2''))) | q1' q2' x y q1'' q2'' . ((q1',q2'), x, y, (q1'',q2'')) \\<in> transitions (product (from_FSM M q1) (from_FSM M q2))}\n        \\<union> (distinguishing_transitions_left M q1 q2)       \n        \\<union> (distinguishing_transitions_right M q1 q2)\"\n  unfolding canonical_separator_transitions_helper[OF assms]\n            shifted_transitions_alt_def \n            distinguishing_transitions_left_def\n            distinguishing_transitions_right_def by simp \n\nlemma canonical_separator_transitions_alt_def :\n  assumes \"q1 \\<in> nodes M\" and \"q2 \\<in> nodes M\"\n  shows \"transitions (canonical_separator M q1 q2) = \n        (shifted_transitions_for M q1 q2)\n        \\<union> (distinguishing_transitions_left_alt M q1 q2)\n        \\<union> (distinguishing_transitions_right_alt M q1 q2)\"\nproof -\n  have *: \"(shift_Inl `\n            {t \\<in> FSM.transitions (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2)).\n             t_source t \\<in> reachable_nodes (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2))})\n          = {(Inl (t_source t), t_input t, t_output t, Inl (t_target t)) |t.\n             t \\<in> FSM.transitions (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2)) \\<and>\n             t_source t \\<in> reachable_nodes (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2))}\" \n    by blast\n  \n  show ?thesis\n  unfolding canonical_separator_simps[OF assms]\n            shifted_transitions_def\n            restrict_to_reachable_nodes_simps\n            product_simps from_FSM_simps[OF assms(1)] from_FSM_simps[OF assms(2)]\n            sup.idem\n  \n            distinguishing_transitions_alt_alt_def\n            shifted_transitions_for_def \n            * \n            \n            distinguishing_transitions_left_alt_def\n            distinguishing_transitions_right_alt_def\n  by blast\nqed\n\n\n\n\nsubsubsection \\<open>State Separators as Submachines of Canonical Separators\\<close>\n\ndefinition is_state_separator_from_canonical_separator :: \"(('a \\<times> 'a) + 'a, 'b, 'c) fsm \\<Rightarrow> 'a \\<Rightarrow> 'a \\<Rightarrow> (('a \\<times> 'a) + 'a, 'b, 'c) fsm \\<Rightarrow> bool\" where\n  \"is_state_separator_from_canonical_separator CSep q1 q2 S = (\n    is_submachine S CSep \n    \\<and> single_input S\n    \\<and> acyclic S\n    \\<and> deadlock_state S (Inr q1)\n    \\<and> deadlock_state S (Inr q2)\n    \\<and> ((Inr q1) \\<in> reachable_nodes S)\n    \\<and> ((Inr q2) \\<in> reachable_nodes S)\n    \\<and> (\\<forall> q \\<in> reachable_nodes S . (q \\<noteq> Inr q1 \\<and> q \\<noteq> Inr q2) \\<longrightarrow> (isl q \\<and> \\<not> deadlock_state S q))\n    \\<and> (\\<forall> q \\<in> reachable_nodes S . \\<forall> x \\<in> (inputs CSep) . (\\<exists> t \\<in> transitions S . t_source t = q \\<and> t_input t = x) \\<longrightarrow> (\\<forall> t' \\<in> transitions CSep . t_source t' = q \\<and> t_input t' = x \\<longrightarrow> t' \\<in> transitions S))\n)\"\n\n\nsubsubsection \\<open>Canonical Separator Properties\\<close>\n\nlemma is_state_separator_from_canonical_separator_simps :\n  assumes \"is_state_separator_from_canonical_separator CSep q1 q2 S\"\n  shows \"is_submachine S CSep\" \n  and   \"single_input S\"\n  and   \"acyclic S\"\n  and   \"deadlock_state S (Inr q1)\"\n  and   \"deadlock_state S (Inr q2)\"\n  and   \"((Inr q1) \\<in> reachable_nodes S)\"\n  and   \"((Inr q2) \\<in> reachable_nodes S)\"\n  and   \"\\<And> q . q \\<in> reachable_nodes S \\<Longrightarrow> q \\<noteq> Inr q1 \\<Longrightarrow> q \\<noteq> Inr q2 \\<Longrightarrow> (isl q \\<and> \\<not> deadlock_state S q)\"\n  and   \"\\<And> q x t . q \\<in> reachable_nodes S \\<Longrightarrow> x \\<in> (inputs CSep) \\<Longrightarrow> (\\<exists> t \\<in> transitions S . t_source t = q \\<and> t_input t = x) \\<Longrightarrow> t \\<in> transitions CSep \\<Longrightarrow> t_source t = q \\<Longrightarrow> t_input t = x \\<Longrightarrow> t \\<in> transitions S\"\n  using assms unfolding is_state_separator_from_canonical_separator_def by blast+\n\n\nlemma is_state_separator_from_canonical_separator_initial :\n  assumes \"is_state_separator_from_canonical_separator (canonical_separator M q1 q2) q1 q2 A\"\n      and \"q1 \\<in> nodes M\"\n      and \"q2 \\<in> nodes M\"\n  shows \"initial A = Inl (q1,q2)\"\n  using is_state_separator_from_canonical_separator_simps(1)[OF assms(1)] \n  using canonical_separator_simps(1)[OF assms(2,3)] by auto\n\n\nlemma path_shift_Inl :\n  assumes \"(image shift_Inl (transitions M)) \\<subseteq> (transitions C)\"\n      and \"\\<And> t . t \\<in> (transitions C) \\<Longrightarrow> isl (t_target t) \\<Longrightarrow> \\<exists> t' \\<in> transitions M . t = (Inl (t_source t'), t_input t', t_output t', Inl (t_target t'))\"\n      and \"initial C = Inl (initial M)\"\n      and \"(inputs C) = (inputs M)\"\n      and \"(outputs C) = (outputs M)\"\n    shows \"path M (initial M) p = path C (initial C) (map shift_Inl p)\"\nproof (induction p rule: rev_induct)\n  case Nil\n  then show ?case by auto\nnext\n  case (snoc t p)\n\n  have \"path M (initial M) (p@[t]) \\<Longrightarrow> path C (initial C) (map shift_Inl (p@[t]))\"\n  proof -\n    assume \"path M (initial M) (p@[t])\"\n    then have \"path M (initial M) p\" by auto\n    then have \"path C (initial C) (map shift_Inl p)\" using snoc.IH\n      by auto \n\n    have \"t_source t = target (initial M) p\"\n      using \\<open>path M (initial M) (p@[t])\\<close> by auto\n    then have \"t_source (shift_Inl t) = target (Inl (initial M)) (map shift_Inl p)\"\n      by (cases p rule: rev_cases; auto)\n    then have \"t_source (shift_Inl t) = target (initial C) (map shift_Inl p)\"\n      using assms(3) by auto\n    moreover have \"target (initial C) (map shift_Inl p) \\<in> nodes C\"\n      using path_target_is_node[OF \\<open>path C (initial C) (map shift_Inl p)\\<close>] by assumption\n    ultimately have \"t_source (shift_Inl t) \\<in> nodes C\"\n      by auto\n    moreover have \"t \\<in> transitions M\"\n      using \\<open>path M (initial M) (p@[t])\\<close> by auto\n    ultimately have \"(shift_Inl t) \\<in> transitions C\"\n      using assms by auto\n\n    show \"path C (initial C) (map shift_Inl (p@[t]))\"\n      using path_append [OF \\<open>path C (initial C) (map shift_Inl p)\\<close>, of \"[shift_Inl t]\"]\n      using \\<open>(shift_Inl t) \\<in> transitions C\\<close> \\<open>t_source (shift_Inl t) = target (initial C) (map shift_Inl p)\\<close>\n      using single_transition_path by force \n  qed\n\n  moreover have \"path C (initial C) (map shift_Inl (p@[t])) \\<Longrightarrow> path M (initial M) (p@[t])\" \n  proof -\n    assume \"path C (initial C) (map shift_Inl (p@[t]))\"\n    then have \"path C (initial C) (map shift_Inl p)\" by auto\n    then have \"path M (initial M) p\" using snoc.IH\n      by blast \n\n    have \"t_source (shift_Inl t) = target (initial C) (map shift_Inl p)\"\n      using \\<open>path C (initial C) (map shift_Inl (p@[t]))\\<close> by auto\n    then have \"t_source (shift_Inl t) = target (Inl (initial M)) (map shift_Inl p)\"\n      using assms(3) by (cases p rule: rev_cases; auto)\n    then have \"t_source t = target (initial M) p\"\n      by (cases p rule: rev_cases; auto)\n    moreover have \"target (initial M) p \\<in> nodes M\"\n      using path_target_is_node[OF \\<open>path M (initial M) p\\<close>] by assumption\n    ultimately have \"t_source t \\<in> nodes M\"\n      by auto\n    moreover have \"shift_Inl t \\<in> transitions C\"\n      using \\<open>path C (initial C) (map shift_Inl (p@[t]))\\<close> by auto\n    moreover have \"isl (t_target (shift_Inl t))\"\n      by auto\n    ultimately have \"t \\<in> transitions M\" using assms by fastforce\n\n    show \"path M (initial M) (p@[t])\"\n      using path_append [OF \\<open>path M (initial M) p\\<close>, of \"[t]\"]\n            single_transition_path[OF \\<open>t \\<in> transitions M\\<close>]\n            \\<open>t_source t = target (initial M) p\\<close> by auto\n  qed\n\n  ultimately show ?case\n    by linarith \nqed\n\n\nlemma canonical_separator_product_transitions_subset : \n  assumes \"q1 \\<in> nodes M\" and \"q2 \\<in> nodes M\"\n  shows \"image shift_Inl (transitions (product (from_FSM M q1) (from_FSM M q2))) \\<subseteq> (transitions (canonical_separator M q1 q2))\"\n  unfolding canonical_separator_simps[OF assms] shifted_transitions_def restrict_to_reachable_nodes_simps \n  by blast\n\n\nlemma canonical_separator_transition_targets :\n  assumes \"t \\<in> (transitions (canonical_separator M q1 q2))\" \n  and \"q1 \\<in> nodes M\" \n  and \"q2 \\<in> nodes M\"\nshows \"isl (t_target t) \\<Longrightarrow> t \\<in> {(Inl (t_source t),t_input t, t_output t, Inl (t_target t)) | t . t \\<in> transitions (product (from_FSM M q1) (from_FSM M q2))}\" \nand   \"t_target t = Inr q1 \\<Longrightarrow> q1 \\<noteq> q2 \\<Longrightarrow> t \\<in> (distinguishing_transitions_left_alt M q1 q2)\"\nand   \"t_target t = Inr q2 \\<Longrightarrow> q1 \\<noteq> q2 \\<Longrightarrow> t \\<in> (distinguishing_transitions_right_alt M q1 q2)\"\nand   \"isl (t_target t) \\<or> t_target t = Inr q1 \\<or> t_target t = Inr q2\"\nunfolding shifted_transitions_for_def\n          distinguishing_transitions_left_alt_def\n          distinguishing_transitions_right_alt_def\nproof -\n  let ?shftd = \"{(Inl (t_source t),t_input t, t_output t, Inl (t_target t)) | t . t \\<in> transitions (product (from_FSM M q1) (from_FSM M q2))}\"\n  let ?dl    = \"{ t . \\<exists> q1' q2' . t_source t = Inl (q1',q2') \\<and> (q1',q2') \\<in> nodes (product (from_FSM M q1) (from_FSM M q2)) \\<and> t_target t = Inr q1 \\<and> (\\<exists> t'  \\<in> transitions M . t_source t' = q1' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t) \\<and> \\<not>(\\<exists> t'  \\<in> transitions M . t_source t' = q2' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)}\"\n  let ?dr    = \"{ t . \\<exists> q1' q2' . t_source t = Inl (q1',q2') \\<and> (q1',q2') \\<in> nodes (product (from_FSM M q1) (from_FSM M q2)) \\<and> t_target t = Inr q2 \\<and> \\<not>(\\<exists> t'  \\<in> transitions M . t_source t' = q1' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t) \\<and> (\\<exists> t'  \\<in> transitions M . t_source t' = q2' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)}\"\n\n  have \"t \\<in> ?shftd \\<union> ?dl \\<union> ?dr\"\n    using assms(1) \n    unfolding canonical_separator_transitions_alt_def[OF assms(2,3)]\n              shifted_transitions_for_def\n              distinguishing_transitions_left_alt_def\n              distinguishing_transitions_right_alt_def\n    by force\n\n  moreover have p1: \"\\<And> t' . t' \\<in> ?shftd \\<Longrightarrow> isl (t_target t')\" \n  and  p2: \"\\<And> t' . t' \\<in> ?dl \\<Longrightarrow> t_target t' = Inr q1\" \n  and  p3: \"\\<And> t' . t' \\<in> ?dr \\<Longrightarrow> t_target t' = Inr q2\" \n    by auto\n  ultimately show \"isl (t_target t) \\<or> t_target t = Inr q1 \\<or> t_target t = Inr q2\" \n    by fast\n\n  show \"isl (t_target t) \\<Longrightarrow> t \\<in> ?shftd\" \n  proof -\n    assume \"isl (t_target t)\"\n    then have \"t_target t \\<noteq> Inr q1\" and \"t_target t \\<noteq> Inr q2\" by auto\n    then have \"t \\<notin> ?dl\" and \"t \\<notin> ?dr\" by force+\n    then show ?thesis using \\<open>t \\<in> ?shftd \\<union> ?dl \\<union> ?dr\\<close> by fastforce\n  qed\n\n  show \"t_target t = Inr q1 \\<Longrightarrow> q1 \\<noteq> q2 \\<Longrightarrow> t \\<in> ?dl\" \n  proof -\n    assume \"t_target t = Inr q1\" and \"q1 \\<noteq> q2\"\n    then have \"\\<not> isl (t_target t)\" and \"t_target t \\<noteq> Inr q2\" by auto\n    then have \"t \\<notin> ?shftd\" and \"t \\<notin> ?dr\" by force+\n    then show ?thesis using \\<open>t \\<in> ?shftd \\<union> ?dl \\<union> ?dr\\<close> by fastforce\n  qed\n\n  show \"t_target t = Inr q2 \\<Longrightarrow> q1 \\<noteq> q2 \\<Longrightarrow> t \\<in> ?dr\" \n  proof -\n    assume \"t_target t = Inr q2\" and \"q1 \\<noteq> q2\"\n    then have \"\\<not> isl (t_target t)\" and \"t_target t \\<noteq> Inr q1\"  by auto\n    then have \"t \\<notin> ?shftd\" and \"t \\<notin> ?dl\" by force+\n    then show ?thesis using \\<open>t \\<in> ?shftd \\<union> ?dl \\<union> ?dr\\<close> by fastforce\n  qed\nqed\n\n\nlemma canonical_separator_path_shift :\n  assumes \"q1 \\<in> nodes M\" and \"q2 \\<in> nodes M\"\n  shows \"path (product (from_FSM M q1) (from_FSM M q2)) (initial (product (from_FSM M q1) (from_FSM M q2))) p \n    = path (canonical_separator M q1 q2) (initial (canonical_separator M q1 q2)) (map shift_Inl p)\"\nproof -\n  let ?C = \"(canonical_separator M q1 q2)\"\n  let ?P = \"(product (from_FSM M q1) (from_FSM M q2))\"\n  let ?PR = \"(product (from_FSM M q1) (from_FSM M q2))\"\n  \n  have \"(inputs ?C) = (inputs ?P)\" \n  and  \"(outputs ?C) = (outputs ?P)\"\n    unfolding canonical_separator_simps(3,4)[OF assms] using assms by auto\n\n  have p1: \"shift_Inl `\n    FSM.transitions\n     ((Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2)))\n    \\<subseteq> FSM.transitions (canonical_separator M q1 q2)\"\n    using canonical_separator_product_transitions_subset[OF assms]\n    unfolding restrict_to_reachable_nodes_simps by assumption\n\n  have p2: \"(\\<And>t. t \\<in> FSM.transitions (canonical_separator M q1 q2) \\<Longrightarrow>\n          isl (t_target t) \\<Longrightarrow>\n          \\<exists>t'\\<in>FSM.transitions\n                ((Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2))).\n             t = shift_Inl t')\"\n    using canonical_separator_transition_targets(1)[OF _ assms] unfolding restrict_to_reachable_nodes_simps by fastforce\n\n  have \"path ?PR (initial ?PR) p = path ?C (initial ?C) (map shift_Inl p)\"\n    using path_shift_Inl[of ?PR ?C, OF p1 p2]  \n    unfolding restrict_to_reachable_nodes_simps canonical_separator_simps(1,2,3,4)[OF assms] using assms by auto\n  moreover have \"path ?P (initial ?P) p = path ?PR (initial ?PR) p\"\n    unfolding restrict_to_reachable_nodes_simps\n              restrict_to_reachable_nodes_path[OF reachable_nodes_initial] \n    by simp  \n  ultimately show ?thesis \n    by simp\nqed\n\n\nlemma canonical_separator_t_source_isl :\n  assumes \"t \\<in> (transitions (canonical_separator M q1 q2))\"\n  and \"q1 \\<in> nodes M\" and \"q2 \\<in> nodes M\"\n  shows \"isl (t_source t)\"\n  using assms(1) \n  unfolding canonical_separator_transitions_alt_def[OF assms(2,3)] \n            shifted_transitions_for_def\n            distinguishing_transitions_left_alt_def\n            distinguishing_transitions_right_alt_def\n  by force\n\n\nlemma canonical_separator_path_from_shift :\n  assumes \"path (canonical_separator M q1 q2) (initial (canonical_separator M q1 q2)) p\"\n      and \"isl (target (initial (canonical_separator M q1 q2)) p)\"\n      and \"q1 \\<in> nodes M\" and \"q2 \\<in> nodes M\"\n    shows \"\\<exists> p' . path (product (from_FSM M q1) (from_FSM M q2)) (initial (product (from_FSM M q1) (from_FSM M q2))) p' \n                  \\<and> p = (map shift_Inl p')\"\nusing assms(1,2) proof (induction p rule: rev_induct)\n  case Nil\n  show ?case using canonical_separator_path_shift[OF assms(3,4), of \"[]\"] by fast\nnext\n  case (snoc t p)\n  then have \"isl (t_target t)\" by auto\n\n  let ?C = \"(canonical_separator M q1 q2)\"\n  let ?P = \"(product (from_FSM M q1) (from_FSM M q2))\"\n\n  have \"t \\<in> transitions ?C\" and \"t_source t = target (initial ?C) p\" \n    using snoc.prems by auto\n  then have \"isl (t_source t)\"\n    using canonical_separator_t_source_isl[of t M q1 q2, OF _ assms(3,4)] by blast  \n  then have \"isl (target (initial (canonical_separator M q1 q2)) p)\"\n    using \\<open>t_source t = target (initial ?C) p\\<close> by auto\n\n  have \"path ?C (initial ?C) p\" using snoc.prems by auto\n  then obtain p' where \"path ?P (initial ?P) p'\"\n                   and \"p = map (\\<lambda>t. (Inl (t_source t), t_input t, t_output t, Inl (t_target t))) p'\"\n    using snoc.IH[OF _ \\<open>isl (target (initial (canonical_separator M q1 q2)) p)\\<close>] by blast\n  then have \"target (initial ?C) p = Inl (target (initial ?P) p')\"\n  proof (cases p rule: rev_cases)\n    case Nil\n    then show ?thesis \n      unfolding target.simps visited_nodes.simps using \\<open>p = map (\\<lambda>t. (Inl (t_source t), t_input t, t_output t, Inl (t_target t))) p'\\<close> canonical_separator_simps(1)[OF assms(3,4)]\n      by (simp add: assms(3) assms(4)) \n  next\n    case (snoc ys y)\n    then show ?thesis \n      unfolding target.simps visited_nodes.simps using \\<open>p = map (\\<lambda>t. (Inl (t_source t), t_input t, t_output t, Inl (t_target t))) p'\\<close> by (cases p' rule: rev_cases; auto)\n  qed\n  \n  obtain t' where \"t' \\<in> transitions ?P\" \n              and \"t = (Inl (t_source t'), t_input t', t_output t', Inl (t_target t'))\"\n    using canonical_separator_transition_targets(1)[OF \\<open>t \\<in> transitions ?C\\<close> assms(3,4) \\<open>isl (t_target t)\\<close>]\n    by blast \n  \n  have \"path ?P (initial ?P) (p'@[t'])\"\n    by (metis \\<open>path (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2)) (FSM.initial (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2))) p'\\<close> \n          \\<open>t = shift_Inl t'\\<close> \\<open>t' \\<in> FSM.transitions (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2))\\<close> \n          \\<open>t_source t = target (FSM.initial (canonical_separator M q1 q2)) p\\<close> \n          \\<open>target (FSM.initial (canonical_separator M q1 q2)) p = Inl (target (FSM.initial (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2))) p')\\<close> \n          fst_conv path_append_transition sum.inject(1))\n  moreover have \"p@[t] = map shift_Inl (p'@[t'])\"\n    using \\<open>p = map (\\<lambda>t. (Inl (t_source t), t_input t, t_output t, Inl (t_target t))) p'\\<close> \n          \\<open>t = (Inl (t_source t'), t_input t', t_output t', Inl (t_target t'))\\<close> \n    by auto\n  ultimately show ?case \n    by meson\nqed\n    \n\nlemma shifted_transitions_targets :\n  assumes \"t \\<in> (shifted_transitions ts)\"\n  shows \"isl (t_target t)\"\n  using assms unfolding shifted_transitions_def by force\n\n\nlemma distinguishing_transitions_left_sources_targets :\n  assumes \"t \\<in> (distinguishing_transitions_left_alt M q1 q2)\"\n      and \"q2 \\<in> nodes M\"  \n    obtains q1' q2' t' where \"t_source t = Inl (q1',q2')\" \n                            \"q1' \\<in> nodes M\" \n                            \"q2' \\<in> nodes M\" \n                            \"t' \\<in> transitions M\" \n                            \"t_source t' = q1'\" \n                            \"t_input t' = t_input t\" \n                            \"t_output t' = t_output t\" \n                            \"\\<not> (\\<exists>t''\\<in> transitions M. t_source t'' = q2' \\<and> t_input t'' = t_input t \\<and> t_output t'' = t_output t)\" \n                            \"t_target t = Inr q1\"\n  using assms(1) assms(2) fsm_transition_source path_target_is_node \n  unfolding distinguishing_transitions_left_alt_def\n  by fastforce\n\n\nlemma distinguishing_transitions_right_sources_targets :\n  assumes \"t \\<in> (distinguishing_transitions_right_alt M q1 q2)\"\n      and \"q1 \\<in> nodes M\"  \n    obtains q1' q2' t' where \"t_source t = Inl (q1',q2')\" \n                            \"q1' \\<in> nodes M\" \n                            \"q2' \\<in> nodes M\" \n                            \"t' \\<in> transitions M\" \n                            \"t_source t' = q2'\" \n                            \"t_input t' = t_input t\" \n                            \"t_output t' = t_output t\" \n                            \"\\<not> (\\<exists>t''\\<in> transitions M. t_source t'' = q1' \\<and> t_input t'' = t_input t \\<and> t_output t'' = t_output t)\" \n                            \"t_target t = Inr q2\"\n  using assms(1) assms(2) fsm_transition_source path_target_is_node \n  unfolding distinguishing_transitions_right_alt_def\n  by fastforce\n\n\nlemma product_from_transition_split :\n  assumes \"t \\<in> transitions (product (from_FSM M q1) (from_FSM M q2))\"\n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\nshows   \"(\\<exists>t'\\<in> transitions M. t_source t' = fst (t_source t) \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)\"\nand     \"(\\<exists>t'\\<in> transitions M. t_source t' = snd (t_source t) \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)\"\n  using product_transition_split_ob[OF assms(1)]\n  unfolding product_transitions_alt_def from_FSM_simps[OF assms(2)] from_FSM_simps[OF assms(3)] by blast+\n\n\nlemma shifted_transitions_underlying_transition :\n  assumes \"tS \\<in> shifted_transitions_for M q1 q2\"\n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\n  obtains t where \"tS = (Inl (t_source t), t_input t, t_output t, Inl (t_target t))\"\n            and   \"t \\<in> (transitions ((product (from_FSM M q1) (from_FSM M q2))))\"\n            and   \"(\\<exists>t'\\<in>(transitions M).\n                            t_source t' = fst (t_source t) \\<and>\n                            t_input t' = t_input t \\<and> t_output t' = t_output t)\"\n            and   \"(\\<exists>t'\\<in>(transitions M).\n                            t_source t' = snd (t_source t) \\<and>\n                            t_input t' = t_input t \\<and> t_output t' = t_output t)\"\nproof -\n  obtain t where \"tS = (Inl (t_source t), t_input t, t_output t, Inl (t_target t))\"\n           and   *: \"t \\<in> (transitions ((product (from_FSM M q1) (from_FSM M q2))))\"\n    using assms unfolding shifted_transitions_for_def shifted_transitions_def restrict_to_reachable_nodes_simps by blast\n  moreover have \"(\\<exists>t'\\<in>(transitions M).\n                            t_source t' = fst (t_source t) \\<and>\n                            t_input t' = t_input t \\<and> t_output t' = t_output t)\"\n    using product_from_transition_split(1)[OF _ assms(2,3)]\n          *\n    unfolding restrict_to_reachable_nodes_simps by blast\n  moreover have \"(\\<exists>t'\\<in>(transitions M).\n                            t_source t' = snd (t_source t) \\<and>\n                            t_input t' = t_input t \\<and> t_output t' = t_output t)\"\n    using product_from_transition_split(2)[OF _ assms(2,3)]\n          *\n    unfolding restrict_to_reachable_nodes_simps by blast\n  ultimately show ?thesis\n    using that by blast \nqed\n     \n\nlemma shifted_transitions_observable_against_distinguishing_transitions_left :\n  assumes \"t1 \\<in> (shifted_transitions_for M q1 q2)\"\n  and     \"t2 \\<in> (distinguishing_transitions_left M q1 q2)\"\n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\nshows \"\\<not> (t_source t1 = t_source t2 \\<and> t_input t1 = t_input t2 \\<and> t_output t1 = t_output t2)\"\n  using assms(1,2)\n  unfolding product_transitions_def from_FSM_simps[OF assms(3)] from_FSM_simps[OF assms(4)]\n            shifted_transitions_for_def distinguishing_transitions_left_def\n  by force\n\nlemma shifted_transitions_observable_against_distinguishing_transitions_right :\n  assumes \"t1 \\<in> (shifted_transitions_for M q1 q2)\"\n  and     \"t2 \\<in> (distinguishing_transitions_right M q1 q2)\"\n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\nshows \"\\<not> (t_source t1 = t_source t2 \\<and> t_input t1 = t_input t2 \\<and> t_output t1 = t_output t2)\"\n  using assms\n  unfolding product_transitions_def from_FSM_simps[OF assms(3)] from_FSM_simps[OF assms(4)] \n            shifted_transitions_for_def distinguishing_transitions_right_def\n  by force\n\n\nlemma distinguishing_transitions_left_observable_against_distinguishing_transitions_right :\n  assumes \"t1 \\<in> (distinguishing_transitions_left M q1 q2)\"\n  and     \"t2 \\<in> (distinguishing_transitions_right M q1 q2)\"\nshows \"\\<not> (t_source t1 = t_source t2 \\<and> t_input t1 = t_input t2 \\<and> t_output t1 = t_output t2)\"\n  using assms \n  unfolding distinguishing_transitions_left_def distinguishing_transitions_right_def by force\n\n\nlemma distinguishing_transitions_left_observable_against_distinguishing_transitions_left :\n  assumes \"t1 \\<in> (distinguishing_transitions_left M q1 q2)\"\n  and     \"t2 \\<in> (distinguishing_transitions_left M q1 q2)\"\n  and     \"t_source t1 = t_source t2 \\<and> t_input t1 = t_input t2 \\<and> t_output t1 = t_output t2\"\nshows \"t1 = t2\"\n  using assms unfolding distinguishing_transitions_left_def by force\n\n\nlemma distinguishing_transitions_right_observable_against_distinguishing_transitions_right :\n  assumes \"t1 \\<in> (distinguishing_transitions_right M q1 q2)\"\n  and     \"t2 \\<in> (distinguishing_transitions_right M q1 q2)\"\n  and     \"t_source t1 = t_source t2 \\<and> t_input t1 = t_input t2 \\<and> t_output t1 = t_output t2\"\nshows \"t1 = t2\"\n  using assms unfolding distinguishing_transitions_right_def by force\n\n\nlemma shifted_transitions_observable_against_shifted_transitions :\n  assumes \"t1 \\<in> (shifted_transitions_for M q1 q2)\"\n  and     \"t2 \\<in> (shifted_transitions_for M q1 q2)\"\n  and     \"observable M\"\n  and     \"t_source t1 = t_source t2 \\<and> t_input t1 = t_input t2 \\<and> t_output t1 = t_output t2\"\nshows \"t1 = t2\" \nproof -\n  obtain t1' where d1: \"t1 = (Inl (t_source t1'), t_input t1', t_output t1', Inl (t_target t1'))\"\n             and   h1: \"t1' \\<in> (transitions (product (from_FSM M q1) (from_FSM M q2)))\"\n    using assms(1) unfolding shifted_transitions_for_def by auto\n\n  obtain t2' where d2: \"t2 = (Inl (t_source t2'), t_input t2', t_output t2', Inl (t_target t2'))\"\n             and   h2: \"t2' \\<in> (transitions (product (from_FSM M q1) (from_FSM M q2)))\"\n    using assms(2) unfolding shifted_transitions_for_def by auto\n\n  have \"observable (product (from_FSM M q1) (from_FSM M q2))\"\n    using from_FSM_observable[OF assms(3)] \n          product_observable \n    by metis\n  \n  then have \"t1' = t2'\"\n    using d1 d2 h1 h2 \\<open>t_source t1 = t_source t2 \\<and> t_input t1 = t_input t2 \\<and> t_output t1 = t_output t2\\<close>\n    by (metis fst_conv observable.elims(2) prod.expand snd_conv sum.inject(1)) \n  then show ?thesis using d1 d2 by auto\nqed\n  \n\nlemma canonical_separator_observable :\n  assumes \"observable M\"\n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\nshows \"observable (canonical_separator M q1 q2)\" (is \"observable ?CSep\")\nproof -\n\n  have  \"\\<And> t1 t2 . t1 \\<in> (transitions ?CSep) \\<Longrightarrow> \n                             t2 \\<in> (transitions ?CSep) \\<Longrightarrow> \n                    t_source t1 = t_source t2 \\<and> t_input t1 = t_input t2 \\<and> t_output t1 = t_output t2 \\<Longrightarrow> t_target t1 = t_target t2\" \n  proof -\n    fix t1 t2 assume \"t1 \\<in> (transitions ?CSep)\" \n              and    \"t2 \\<in> (transitions ?CSep)\"\n              and    *: \"t_source t1 = t_source t2 \\<and> t_input t1 = t_input t2 \\<and> t_output t1 = t_output t2\"\n    \n    moreover have \"transitions ?CSep = shifted_transitions_for M q1 q2 \\<union>\n                                       distinguishing_transitions_left M q1 q2 \\<union>\n                                       distinguishing_transitions_right M q1 q2\"\n      using canonical_separator_transitions_alt_def[OF assms(2,3)] \n      unfolding distinguishing_transitions_left_alt_alt_def distinguishing_transitions_right_alt_alt_def by assumption\n\n    ultimately consider \"t1 \\<in> shifted_transitions_for M q1 q2 \\<and> t2 \\<in> shifted_transitions_for M q1 q2\"\n                      | \"t1 \\<in> shifted_transitions_for M q1 q2 \\<and> t2 \\<in> distinguishing_transitions_left M q1 q2\"\n                      | \"t1 \\<in> shifted_transitions_for M q1 q2 \\<and> t2 \\<in> distinguishing_transitions_right M q1 q2\"\n                      | \"t1 \\<in> distinguishing_transitions_left M q1 q2 \\<and> t2 \\<in> shifted_transitions_for M q1 q2\"\n                      | \"t1 \\<in> distinguishing_transitions_left M q1 q2 \\<and> t2 \\<in> distinguishing_transitions_left M q1 q2\"\n                      | \"t1 \\<in> distinguishing_transitions_left M q1 q2 \\<and> t2 \\<in> distinguishing_transitions_right M q1 q2\"\n                      | \"t1 \\<in> distinguishing_transitions_right M q1 q2 \\<and> t2 \\<in> shifted_transitions_for M q1 q2\"\n                      | \"t1 \\<in> distinguishing_transitions_right M q1 q2 \\<and> t2 \\<in> distinguishing_transitions_left M q1 q2\"\n                      | \"t1 \\<in> distinguishing_transitions_right M q1 q2 \\<and> t2 \\<in> distinguishing_transitions_right M q1 q2\"\n      by force\n    then show \"t_target t1 = t_target t2\" proof cases\n      case 1\n      then show ?thesis using shifted_transitions_observable_against_shifted_transitions[of t1 M q1 q2 t2, OF _ _ assms(1) *] by fastforce\n    next\n      case 2\n      then show ?thesis using shifted_transitions_observable_against_distinguishing_transitions_left[OF _ _ assms(2,3), of t1 t2] * by fastforce\n    next\n      case 3\n      then show ?thesis using shifted_transitions_observable_against_distinguishing_transitions_right[OF _ _ assms(2,3), of t1 t2] * by fastforce\n    next\n      case 4\n      then show ?thesis using shifted_transitions_observable_against_distinguishing_transitions_left[OF _ _ assms(2,3), of t2 t1] * by fastforce\n    next\n      case 5\n      then show ?thesis using * unfolding distinguishing_transitions_left_def by fastforce\n    next\n      case 6\n      then show ?thesis using * unfolding distinguishing_transitions_left_def distinguishing_transitions_right_def by fastforce\n    next\n      case 7\n      then show ?thesis using shifted_transitions_observable_against_distinguishing_transitions_right[OF _ _ assms(2,3), of t2 t1] * by fastforce\n    next\n      case 8\n      then show ?thesis using * unfolding distinguishing_transitions_left_def distinguishing_transitions_right_def by fastforce\n    next\n      case 9\n      then show ?thesis using * unfolding distinguishing_transitions_right_def by fastforce\n    qed \n  qed\n  then show ?thesis unfolding observable.simps by blast\nqed\n\n\nlemma canonical_separator_targets_ineq :\n  assumes \"t \\<in> transitions (canonical_separator M q1 q2)\" \n      and \"q1 \\<in> nodes M\" and \"q2 \\<in> nodes M\" and \"q1 \\<noteq> q2\"\n  shows \"isl (t_target t) \\<Longrightarrow> t \\<in> (shifted_transitions_for M q1 q2)\"\n    and \"t_target t = Inr q1 \\<Longrightarrow> t \\<in> (distinguishing_transitions_left M q1 q2)\"\n    and \"t_target t = Inr q2 \\<Longrightarrow> t \\<in> (distinguishing_transitions_right M q1 q2)\"\nproof -\n  show \"isl (t_target t) \\<Longrightarrow> t \\<in> (shifted_transitions_for M q1 q2)\"\n    by (metis (no_types, lifting) assms(1) assms(2) assms(3) canonical_separator_transition_targets(1) shifted_transitions_for_def)\n  show \"t_target t = Inr q1 \\<Longrightarrow> t \\<in> (distinguishing_transitions_left M q1 q2)\"\n    by (metis assms(1) assms(2) assms(3) assms(4) canonical_separator_transition_targets(2) distinguishing_transitions_left_alt_alt_def)\n  show \"t_target t = Inr q2 \\<Longrightarrow> t \\<in> (distinguishing_transitions_right M q1 q2)\"\n    by (metis assms(1) assms(2) assms(3) assms(4) canonical_separator_transition_targets(3) distinguishing_transitions_right_alt_alt_def)\nqed\n\n\nlemma canonical_separator_targets_observable :\n  assumes \"t \\<in> transitions (canonical_separator M q1 q2)\" \n      and \"q1 \\<in> nodes M\" and \"q2 \\<in> nodes M\" and \"q1 \\<noteq> q2\"\n  shows \"isl (t_target t) \\<Longrightarrow> t \\<in> (shifted_transitions_for M q1 q2)\"\n    and \"t_target t = Inr q1 \\<Longrightarrow> t \\<in> (distinguishing_transitions_left M q1 q2)\"\n    and \"t_target t = Inr q2 \\<Longrightarrow> t \\<in> (distinguishing_transitions_right M q1 q2)\"\nproof -\n  show \"isl (t_target t) \\<Longrightarrow> t \\<in> (shifted_transitions_for M q1 q2)\"\n    by (metis assms canonical_separator_targets_ineq(1))\n  show \"t_target t = Inr q1 \\<Longrightarrow> t \\<in> (distinguishing_transitions_left M q1 q2)\"\n    by (metis assms canonical_separator_targets_ineq(2))\n  show \"t_target t = Inr q2 \\<Longrightarrow> t \\<in> (distinguishing_transitions_right M q1 q2)\"\n    by (metis assms canonical_separator_targets_ineq(3))\nqed\n\n\nlemma canonical_separator_maximal_path_distinguishes_left :\n  assumes \"is_state_separator_from_canonical_separator (canonical_separator M q1 q2) q1 q2 S\" (is \"is_state_separator_from_canonical_separator ?C q1 q2 S\")\n      and \"path S (initial S) p\"\n      and \"target (initial S) p = Inr q1\"  \n      and \"observable M\"\n      and \"q1 \\<in> nodes M\" and \"q2 \\<in> nodes M\" and \"q1 \\<noteq> q2\"\nshows \"p_io p \\<in> LS M q1 - LS M q2\"\nproof (cases p rule: rev_cases)\n  case Nil\n  then have \"initial S = Inr q1\" using assms(3) by auto\n  then have \"initial ?C = Inr q1\"\n    using assms(1) assms(5) assms(6) is_state_separator_from_canonical_separator_initial by fastforce\n  then show ?thesis using canonical_separator_simps(1) Inr_Inl_False\n    using assms(5) assms(6) by fastforce \nnext\n  case (snoc p' t) \n  then have \"path S (initial S) (p'@[t])\"\n    using assms(2) by auto\n  then have \"t \\<in> transitions S\" and \"t_source t = target (initial S) p'\" by auto\n\n\n  have \"path ?C (initial ?C) (p'@[t])\"\n    using \\<open>path S (initial S) (p'@[t])\\<close> assms(1) is_state_separator_from_canonical_separator_def[of ?C q1 q2 S] by (meson submachine_path_initial)\n  then have \"path ?C (initial ?C) (p')\" and \"t \\<in> transitions ?C\"\n    by auto\n\n  have \"isl (target (initial S) p')\"\n  proof (rule ccontr)\n    assume \"\\<not> isl (target (initial S) p')\"\n    moreover have \"target (initial S) p' \\<in> nodes S\"\n      using \\<open>path S (initial S) (p'@[t])\\<close> by auto\n    ultimately have \"target (initial S) p' = Inr q1 \\<or> target (initial S) p' = Inr q2\"\n      using \\<open>t \\<in> FSM.transitions (canonical_separator M q1 q2)\\<close> \\<open>t_source t = target (FSM.initial S) p'\\<close> assms(5) assms(6) canonical_separator_t_source_isl by fastforce            \n    moreover have \"deadlock_state S (Inr q1)\" and \"deadlock_state S (Inr q2)\"\n      using assms(1) is_state_separator_from_canonical_separator_def[of ?C q1 q2 S] by presburger+\n    ultimately show \"False\" \n      using \\<open>t \\<in> transitions S\\<close> \\<open>t_source t = target (initial S) p'\\<close> unfolding deadlock_state.simps\n      by metis \n  qed\n  then obtain q1' q2' where \"target (initial S) p' = Inl (q1',q2')\" using isl_def prod.collapse by metis\n  then have \"isl (target (initial ?C) p')\"\n     using assms(1) is_state_separator_from_canonical_separator_def[of ?C q1 q2 S]\n     by (metis (no_types, lifting) Nil_is_append_conv assms(2) isl_def list.distinct(1) list.sel(1) path.cases snoc submachine_path_initial) \n\n\n  obtain pC where \"path (product (from_FSM M q1) (from_FSM M q2)) (initial (product (from_FSM M q1) (from_FSM M q2))) pC\"\n              and \"p' = map shift_Inl pC\"\n    by (metis (mono_tags, lifting) \\<open>isl (target (FSM.initial (canonical_separator M q1 q2)) p')\\<close> \n          \\<open>path (canonical_separator M q1 q2) (FSM.initial (canonical_separator M q1 q2)) p'\\<close> \n          assms(5) assms(6) canonical_separator_path_from_shift)\n  then have \"path (product (from_FSM M q1) (from_FSM M q2)) (q1,q2) pC\"\n    by (simp add: assms(5) assms(6))\n  then have \"path (from_FSM M q1) q1 (left_path pC)\" and \"path (from_FSM M q2) q2 (right_path pC)\"\n    using product_path[of \"from_FSM M q1\" \"from_FSM M q2\" q1 q2 pC] by presburger+\n\n  have \"path M q1 (left_path pC)\"\n    using from_FSM_path[OF assms(5) \\<open>path (from_FSM M q1) q1 (left_path pC)\\<close>] by assumption\n  have \"path M q2 (right_path pC)\"\n    using from_FSM_path[OF assms(6) \\<open>path (from_FSM M q2) q2 (right_path pC)\\<close>] by assumption\n  \n  have \"t_target t = Inr q1\"\n    using \\<open>path S (initial S) (p'@[t])\\<close> snoc assms(3) by auto\n  then have \"t \\<in> (distinguishing_transitions_left M q1 q2)\"\n    using canonical_separator_targets_ineq(2)[OF \\<open>t \\<in> transitions ?C\\<close> assms(5,6,7)] by auto\n  then have \"t \\<in> (distinguishing_transitions_left_alt M q1 q2)\"\n    using distinguishing_transitions_left_alt_alt_def by force\n\n  have \"t_source t = Inl (q1',q2')\"\n    using \\<open>target (initial S) p' = Inl (q1',q2')\\<close> \\<open>t_source t = target (initial S) p'\\<close> by auto\n\n  then obtain t' where \"q1' \\<in> nodes M\"\n                        and \"q2' \\<in> nodes M\"\n                        and \"t' \\<in> transitions M\"\n                        and \"t_source t' = q1'\"\n                        and \"t_input t' = t_input t\"\n                        and \"t_output t' = t_output t\"\n                        and \"\\<not> (\\<exists>t''\\<in> transitions M. t_source t'' = q2' \\<and> t_input t'' = t_input t \\<and> t_output t'' = t_output t)\"\n    using \\<open>t \\<in> (distinguishing_transitions_left_alt M q1 q2)\\<close> assms(5,6) fsm_transition_source path_target_is_node \n    unfolding distinguishing_transitions_left_alt_def reachable_nodes_def by fastforce\n\n\n  have \"initial S = Inl (q1,q2)\"\n    by (meson assms(1) assms(5) assms(6) is_state_separator_from_canonical_separator_initial)\n  have \"length p' = length pC\"\n    using \\<open>p' = map shift_Inl pC\\<close> by auto\n  then have \"target (initial S) p' = Inl (target (q1,q2) pC)\"\n    using \\<open>p' = map shift_Inl pC\\<close> \\<open>initial S = Inl (q1,q2)\\<close> by (induction p' pC rule: list_induct2; auto)\n  then have \"target (q1,q2) pC = (q1',q2')\"\n     using \\<open>target (initial S) p' = Inl (q1',q2')\\<close> by auto \n  then have \"target q2 (right_path pC) = q2'\"\n    using product_target_split(2) by fastforce\n  then have \"\\<not> (\\<exists>t'\\<in> transitions M. t_source t' = target q2 (right_path pC) \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)\"\n    using \\<open>\\<not> (\\<exists>t'\\<in> transitions M. t_source t' = q2' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)\\<close> by blast\n\n  have \"target q1 (left_path pC) = q1'\"\n    using \\<open>target (q1,q2) pC = (q1',q2')\\<close> product_target_split(1) by fastforce\n  then have \"path M q1 ((left_path pC)@[t'])\"\n    using \\<open>path M q1 (left_path pC)\\<close> \\<open>t' \\<in> transitions M\\<close> \\<open>t_source t' = q1'\\<close>\n    by (simp add: path_append_transition)\n  then have \"p_io ((left_path pC)@[t']) \\<in> LS M q1\" \n    unfolding LS.simps by force \n  moreover have \"p_io p' = p_io (left_path pC)\"\n    using \\<open>p' = map shift_Inl pC\\<close> by auto\n  ultimately have \"p_io (p'@[t]) \\<in> LS M q1\"\n    using \\<open>t_input t' = t_input t\\<close> \\<open>t_output t' = t_output t\\<close> by auto\n    \n  have \"p_io (right_path pC) @  [(t_input t, t_output t)] \\<notin> LS M q2\"\n    using observable_path_language_step[OF assms(4) \\<open>path M q2 (right_path pC)\\<close> \\<open>\\<not> (\\<exists>t'\\<in> transitions M. t_source t' = target q2 (right_path pC) \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)\\<close>] by assumption\n  moreover have \"p_io p' = p_io (right_path pC)\"\n    using \\<open>p' = map shift_Inl pC\\<close> by auto\n  ultimately have \"p_io (p'@[t]) \\<notin> LS M q2\"\n    by auto\n\n  show ?thesis \n    using \\<open>p_io (p'@[t]) \\<in> LS M q1\\<close> \\<open>p_io (p'@[t]) \\<notin> LS M q2\\<close> snoc by blast\nqed\n\n\nlemma canonical_separator_maximal_path_distinguishes_right :\n  assumes \"is_state_separator_from_canonical_separator (canonical_separator M q1 q2) q1 q2 S\" \n          (is \"is_state_separator_from_canonical_separator ?C q1 q2 S\")\n      and \"path S (initial S) p\"\n      and \"target (initial S) p = Inr q2\"  \n      and \"observable M\"\n      and \"q1 \\<in> nodes M\" and \"q2 \\<in> nodes M\" and \"q1 \\<noteq> q2\"\nshows \"p_io p \\<in> LS M q2 - LS M q1\"\nproof (cases p rule: rev_cases)\n  case Nil\n  then have \"initial S = Inr q2\" using assms(3) by auto\n  then have \"initial ?C = Inr q2\"\n    using assms(1) assms(5) assms(6) is_state_separator_from_canonical_separator_initial by fastforce\n  then show ?thesis using canonical_separator_simps(1) Inr_Inl_False\n    using assms(5) assms(6) by fastforce  \nnext\n  case (snoc p' t) \n  then have \"path S (initial S) (p'@[t])\"\n    using assms(2) by auto\n  then have \"t \\<in> transitions S\" and \"t_source t = target (initial S) p'\" \n    by auto\n\n  have \"path ?C (initial ?C) (p'@[t])\"\n    using \\<open>path S (initial S) (p'@[t])\\<close> assms(1) is_state_separator_from_canonical_separator_def[of ?C q1 q2 S] \n    by (meson submachine_path_initial)\n  then have \"path ?C (initial ?C) (p')\" and \"t \\<in> transitions ?C\"\n    by auto\n\n  have \"isl (target (initial S) p')\"\n  proof (rule ccontr)\n    assume \"\\<not> isl (target (initial S) p')\"\n    moreover have \"target (initial S) p' \\<in> nodes S\"\n      using \\<open>path S (initial S) (p'@[t])\\<close> by auto\n    ultimately have \"target (initial S) p' = Inr q1 \\<or> target (initial S) p' = Inr q2\"\n      \n      using assms(1) unfolding is_state_separator_from_canonical_separator_def\n      by (metis \\<open>t \\<in> FSM.transitions (canonical_separator M q1 q2)\\<close> \\<open>t_source t = target (FSM.initial S) p'\\<close> \n            assms(5) assms(6) canonical_separator_t_source_isl)   \n    moreover have \"deadlock_state S (Inr q1)\" and \"deadlock_state S (Inr q2)\"\n      using assms(1) is_state_separator_from_canonical_separator_def[of ?C q1 q2 S] by presburger+\n    ultimately show \"False\" \n      using \\<open>t \\<in> transitions S\\<close> \\<open>t_source t = target (initial S) p'\\<close> unfolding deadlock_state.simps\n      by metis \n  qed\n  then obtain q1' q2' where \"target (initial S) p' = Inl (q1',q2')\" \n    using isl_def prod.collapse by metis\n  then have \"isl (target (initial ?C) p')\"\n     using assms(1) is_state_separator_from_canonical_separator_def[of ?C q1 q2 S]\n     by (metis (no_types, lifting) Nil_is_append_conv assms(2) isl_def list.distinct(1) list.sel(1) \n         path.cases snoc submachine_path_initial) \n\n  obtain pC where \"path (product (from_FSM M q1) (from_FSM M q2)) (initial (product (from_FSM M q1) (from_FSM M q2))) pC\"\n              and \"p' = map shift_Inl pC\"\n    using canonical_separator_path_from_shift[OF \\<open>path ?C (initial ?C) (p')\\<close> \\<open>isl (target (initial ?C) p')\\<close>]\n    using assms(5) assms(6) by blast \n  then have \"path (product (from_FSM M q1) (from_FSM M q2)) (q1,q2) pC\"\n    by (simp add: assms(5) assms(6))\n\n  then have \"path (from_FSM M q1) q1 (left_path pC)\" and \"path (from_FSM M q2) q2 (right_path pC)\"\n    using product_path[of \"from_FSM M q1\" \"from_FSM M q2\" q1 q2 pC] by presburger+\n\n  have \"path M q1 (left_path pC)\"\n    using from_FSM_path[OF assms(5) \\<open>path (from_FSM M q1) q1 (left_path pC)\\<close>] by assumption\n  have \"path M q2 (right_path pC)\"\n    using from_FSM_path[OF assms(6) \\<open>path (from_FSM M q2) q2 (right_path pC)\\<close>] by assumption\n  \n  have \"t_target t = Inr q2\"\n    using \\<open>path S (initial S) (p'@[t])\\<close> snoc assms(3) by auto\n  then have \"t \\<in> (distinguishing_transitions_right M q1 q2)\"\n    using canonical_separator_targets_ineq(3)[OF \\<open>t \\<in> transitions ?C\\<close> assms(5,6,7)] by auto\n  then have \"t \\<in> (distinguishing_transitions_right_alt M q1 q2)\"\n    unfolding distinguishing_transitions_right_alt_alt_def by assumption\n\n  have \"t_source t = Inl (q1',q2')\"\n    using \\<open>target (initial S) p' = Inl (q1',q2')\\<close> \\<open>t_source t = target (initial S) p'\\<close> by auto\n\n  then obtain t' where \"q1' \\<in> nodes M\"\n                        and \"q2' \\<in> nodes M\"\n                        and \"t' \\<in> transitions M\"\n                        and \"t_source t' = q2'\"                        \n                        and \"t_input t' = t_input t\"\n                        and \"t_output t' = t_output t\"\n                        and \"\\<not> (\\<exists>t''\\<in> transitions M. t_source t'' = q1' \\<and> t_input t'' = t_input t \\<and> t_output t'' = t_output t)\"\n    using \\<open>t \\<in> (distinguishing_transitions_right_alt M q1 q2)\\<close> assms(5,6) fsm_transition_source path_target_is_node \n    unfolding distinguishing_transitions_right_alt_def reachable_nodes_def by fastforce\n\n  \n  have \"initial S = Inl (q1,q2)\"\n    by (meson assms(1) assms(5) assms(6) is_state_separator_from_canonical_separator_initial)\n  have \"length p' = length pC\"\n    using \\<open>p' = map shift_Inl pC\\<close> by auto\n  then have \"target (initial S) p' = Inl (target (q1,q2) pC)\"\n    using \\<open>p' = map shift_Inl pC\\<close> \\<open>initial S = Inl (q1,q2)\\<close> by (induction p' pC rule: list_induct2; auto)\n  then have \"target (q1,q2) pC = (q1',q2')\"\n     using \\<open>target (initial S) p' = Inl (q1',q2')\\<close> by auto \n  then have \"target q1 (left_path pC) = q1'\"\n    using product_target_split(1) by fastforce\n  then have \"\\<not> (\\<exists>t'\\<in> transitions M. t_source t' = target q1 (left_path pC) \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)\"\n    using \\<open>\\<not> (\\<exists>t'\\<in> transitions M. t_source t' = q1' \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)\\<close> by blast\n\n  have \"target q2 (right_path pC) = q2'\"\n    using \\<open>target (q1,q2) pC = (q1',q2')\\<close> product_target_split(2) by fastforce\n  then have \"path M q2 ((right_path pC)@[t'])\"\n    using \\<open>path M q2 (right_path pC)\\<close> \\<open>t' \\<in> transitions M\\<close> \\<open>t_source t' = q2'\\<close>\n    by (simp add: path_append_transition)\n  then have \"p_io ((right_path pC)@[t']) \\<in> LS M q2\" \n    unfolding LS.simps by force \n  moreover have \"p_io p' = p_io (right_path pC)\"\n    using \\<open>p' = map shift_Inl pC\\<close> by auto\n  ultimately have \"p_io (p'@[t]) \\<in> LS M q2\"\n    using \\<open>t_input t' = t_input t\\<close> \\<open>t_output t' = t_output t\\<close> by auto\n    \n\n  have \"p_io (left_path pC) @  [(t_input t, t_output t)] \\<notin> LS M q1\"\n    using observable_path_language_step[OF assms(4) \\<open>path M q1 (left_path pC)\\<close> \\<open>\\<not> (\\<exists>t'\\<in> transitions M. t_source t' = target q1 (left_path pC) \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)\\<close>] by assumption\n  moreover have \"p_io p' = p_io (left_path pC)\"\n    using \\<open>p' = map shift_Inl pC\\<close> by auto\n  ultimately have \"p_io (p'@[t]) \\<notin> LS M q1\"\n    by auto\n  \n  show ?thesis \n    using \\<open>p_io (p'@[t]) \\<in> LS M q2\\<close> \\<open>p_io (p'@[t]) \\<notin> LS M q1\\<close> snoc \n    by blast   \nqed\n\n\nlemma state_separator_from_canonical_separator_observable :\n  assumes \"is_state_separator_from_canonical_separator (canonical_separator M q1 q2) q1 q2 A\"\n  and     \"observable M\"\n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\nshows \"observable A\"\n  using submachine_observable[OF _ canonical_separator_observable[OF assms(2,3,4)]]\n  using assms(1) unfolding is_state_separator_from_canonical_separator_def \n  by metis\n\n\nlemma canonical_separator_initial :\n  assumes \"q1 \\<in> nodes M\" and \"q2 \\<in> nodes M\"\n  shows \"initial (canonical_separator M q1 q2) = Inl (q1,q2)\" \n    unfolding canonical_separator_simps[OF assms] by simp\n\n\nlemma canonical_separator_nodes :\n  assumes \"Inl (s1,s2) \\<in> nodes (canonical_separator M q1 q2)\"\n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\nshows \"(s1,s2) \\<in> nodes (product (from_FSM M q1) (from_FSM M q2))\"\n  using assms(1) reachable_node_is_node\n  unfolding canonical_separator_simps[OF assms(2,3)] by fastforce\n\n\nlemma canonical_separator_transition :\n  assumes \"t \\<in> transitions (canonical_separator M q1 q2)\" (is \"t \\<in> transitions ?C\")\n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\n  and     \"t_source t = Inl (s1,s2)\"\n  and     \"observable M\"\n  and     \"q1 \\<noteq> q2\"\nshows \"\\<And> s1' s2' . t_target t = Inl (s1',s2') \\<Longrightarrow> (s1, t_input t, t_output t, s1') \\<in> transitions M \\<and> (s2, t_input t, t_output t, s2') \\<in> transitions M \"\nand   \"t_target t = Inr q1 \\<Longrightarrow> (\\<exists> t'\\<in> transitions M . t_source t' = s1 \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t) \n                                \\<and> (\\<not>(\\<exists> t'\\<in> transitions M . t_source t' = s2 \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t))\"\nand   \"t_target t = Inr q2 \\<Longrightarrow> (\\<exists> t'\\<in> transitions M . t_source t' = s2 \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t) \n                                \\<and> (\\<not>(\\<exists> t'\\<in> transitions M . t_source t' = s1 \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t))\"\nand   \"(\\<exists> s1' s2' . t_target t = Inl (s1',s2')) \\<or> t_target t = Inr q1 \\<or> t_target t = Inr q2\"\nproof -\n  show \"\\<And> s1' s2' . t_target t = Inl (s1',s2') \\<Longrightarrow> (s1, t_input t, t_output t, s1') \\<in> transitions M \\<and> (s2, t_input t, t_output t, s2') \\<in> transitions M\"\n    using canonical_separator_transition_targets(1)[OF assms(1,2,3)] assms(4)\n    unfolding shifted_transitions_for_def[symmetric] \n    unfolding shifted_transitions_for_alt_def \n    unfolding product_transitions_def from_FSM_simps[OF assms(2)] from_FSM_simps[OF assms(3)] by fastforce\n\n  show \"t_target t = Inr q1 \\<Longrightarrow> (\\<exists> t'\\<in> transitions M . t_source t' = s1 \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t) \n                                \\<and> (\\<not>(\\<exists> t'\\<in> transitions M . t_source t' = s2 \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t))\"\n    using canonical_separator_targets_observable(2)[OF assms(1,2,3,6)] assms(4)\n    unfolding distinguishing_transitions_left_def by fastforce\n\n  show \"t_target t = Inr q2 \\<Longrightarrow> (\\<exists> t'\\<in> transitions M . t_source t' = s2 \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t) \n                                \\<and> (\\<not>(\\<exists> t'\\<in> transitions M . t_source t' = s1 \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t))\"\n    using canonical_separator_targets_observable(3)[OF assms(1,2,3,6)] assms(4)\n    unfolding distinguishing_transitions_right_def by fastforce\n\n  show \"(\\<exists> s1' s2' . t_target t = Inl (s1',s2')) \\<or> t_target t = Inr q1 \\<or> t_target t = Inr q2\"\n    using canonical_separator_transition_targets(4)[OF assms(1,2,3)]\n    by (simp add: isl_def) \nqed\n\n\nlemma canonical_separator_transition_source :\n  assumes \"t \\<in> transitions (canonical_separator M q1 q2)\" (is \"t \\<in> transitions ?C\")\n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\nobtains q1' q2' where \"t_source t = Inl (q1',q2')\"\n                      \"(q1',q2') \\<in> nodes (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2))\"\nproof -\n  consider \"t \\<in> shifted_transitions_for M q1 q2\" | \"t \\<in> distinguishing_transitions_left_alt M q1 q2\" |\n       \"t \\<in> distinguishing_transitions_right_alt M q1 q2\"\n    using assms(1)\n    unfolding canonical_separator_transitions_alt_def[OF assms(2,3)] by blast\n  then show ?thesis proof cases\n    case 1\n    then show ?thesis unfolding shifted_transitions_for_def using that\n      using fsm_transition_source by fastforce\n  next\n    case 2\n    then show ?thesis unfolding distinguishing_transitions_left_alt_def using that by fastforce\n  next\n    case 3\n    then show ?thesis unfolding distinguishing_transitions_right_alt_def using that by fastforce\n  qed \nqed\n\n\nlemma canonical_separator_transition_ex :\n  assumes \"t \\<in> transitions (canonical_separator M q1 q2)\" (is \"t \\<in> transitions ?C\")\n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\n  and     \"t_source t = Inl (s1,s2)\"\nshows \"(\\<exists> t1 \\<in> transitions M . t_source t1 = s1 \\<and> t_input t1 = t_input t \\<and> t_output t1 = t_output t) \\<or>\n       (\\<exists> t2 \\<in> transitions M . t_source t2 = s2 \\<and> t_input t2 = t_input t \\<and> t_output t2 = t_output t)\"\nproof -\n  consider \"t \\<in> shifted_transitions_for M q1 q2\" | \"t \\<in> distinguishing_transitions_left_alt M q1 q2\" |\n       \"t \\<in> distinguishing_transitions_right_alt M q1 q2\"\n    using assms(1)\n    unfolding canonical_separator_transitions_alt_def[OF assms(2,3)] by blast\n  then show ?thesis proof cases\n    case 1\n    then show ?thesis unfolding shifted_transitions_for_def \n      using product_from_transition_split[OF _ assms(2,3)]\n      using assms(4) by force\n  next\n    case 2\n    then show ?thesis unfolding distinguishing_transitions_left_alt_def\n      using assms(4) by auto \n      \n  next\n    case 3\n    then show ?thesis unfolding distinguishing_transitions_right_alt_def \n      using assms(4) by auto \n  qed \nqed\n\n\nlemma canonical_separator_path_split_target_isl :\n  assumes \"path (canonical_separator M q1 q2) (initial (canonical_separator M q1 q2)) (p@[t])\"\n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\n  shows \"isl (target (initial (canonical_separator M q1 q2)) p)\"\nproof -\n  let ?C = \"(canonical_separator M q1 q2)\"\n  have \"t \\<in> transitions ?C\"\n    using assms by auto\n  moreover have \"\\<not> deadlock_state ?C (t_source t)\"\n    using assms unfolding deadlock_state.simps by blast\n  ultimately show ?thesis \n    using canonical_separator_t_source_isl assms\n    by fastforce\nqed\n\n\nlemma canonical_separator_path_initial :\n  assumes \"path (canonical_separator M q1 q2) (initial (canonical_separator M q1 q2)) p\" (is \"path ?C (initial ?C) p\")\n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\n  and     \"observable M\"\n  and     \"q1 \\<noteq> q2\"\nshows \"\\<And> s1' s2' . target (initial (canonical_separator M q1 q2)) p = Inl (s1',s2') \\<Longrightarrow> (\\<exists> p1 p2 . path M q1 p1 \\<and> path M q2 p2 \\<and> p_io p1 = p_io p2 \\<and> p_io p1 = p_io p \\<and> target q1 p1 = s1' \\<and> target q2 p2 = s2')\"\nand   \"target (initial (canonical_separator M q1 q2)) p = Inr q1 \\<Longrightarrow> (\\<exists> p1 p2 t . path M q1 (p1@[t]) \\<and> path M q2 p2 \\<and> p_io (p1@[t]) = p_io p \\<and> p_io p2 = butlast (p_io p)) \\<and> (\\<not>(\\<exists> p2 . path M q2 p2 \\<and> p_io p2 = p_io p))\"\nand   \"target (initial (canonical_separator M q1 q2)) p = Inr q2 \\<Longrightarrow> (\\<exists> p1 p2 t . path M q1 p1 \\<and> path M q2 (p2@[t]) \\<and> p_io p1 = butlast (p_io p) \\<and> p_io (p2@[t]) = p_io p) \\<and> (\\<not>(\\<exists> p1 . path M q1 p1 \\<and> p_io p1 = p_io p))\"\nand   \"(\\<exists> s1' s2' . target (initial (canonical_separator M q1 q2)) p = Inl (s1',s2')) \\<or> target (initial (canonical_separator M q1 q2)) p = Inr q1 \\<or> target (initial (canonical_separator M q1 q2)) p = Inr q2\"\nproof -\n\n  let ?P1 = \"\\<forall> s1' s2' . target (initial (canonical_separator M q1 q2)) p = Inl (s1',s2') \\<longrightarrow> (\\<exists> p1 p2 . path M q1 p1 \\<and> path M q2 p2 \\<and> p_io p1 = p_io p2 \\<and> p_io p1 = p_io p \\<and> target q1 p1 = s1' \\<and> target q2 p2 = s2')\"\n  let ?P2 = \"target (initial (canonical_separator M q1 q2)) p = Inr q1 \\<longrightarrow> (\\<exists> p1 p2 t . path M q1 (p1@[t]) \\<and> path M q2 p2 \\<and> p_io (p1@[t]) = p_io p \\<and> p_io p2 = butlast (p_io p)) \\<and> (\\<not>(\\<exists> p2 . path M q2 p2 \\<and> p_io p2 = p_io p))\"\n  let ?P3 = \"target (initial (canonical_separator M q1 q2)) p = Inr q2 \\<longrightarrow> (\\<exists> p1 p2 t . path M q1 p1 \\<and> path M q2 (p2@[t]) \\<and> p_io p1 = butlast (p_io p) \\<and> p_io (p2@[t]) = p_io p) \\<and> (\\<not>(\\<exists> p1 . path M q1 p1 \\<and> p_io p1 = p_io p))\"\n\n  have \"?P1 \\<and> ?P2 \\<and> ?P3\"\n  using assms(1) proof (induction p rule: rev_induct) \n    case Nil \n    then have \"target (FSM.initial (canonical_separator M q1 q2)) [] = Inl (q1, q2)\"\n      unfolding canonical_separator_simps[OF assms(2,3)] by auto\n    then show ?case using assms(2,3,4) by fastforce\n  next\n    case (snoc t p)\n    \n    have \"path ?C (initial ?C) p\" and \"t \\<in> transitions ?C\" and \"t_source t = target (initial ?C) p\"\n      using snoc.prems(1) by auto\n\n    let ?P1' = \"(\\<forall>s1' s2'. target (initial (canonical_separator M q1 q2)) (p @ [t]) = Inl (s1', s2') \\<longrightarrow> (\\<exists>p1 p2. path M q1 p1 \\<and> path M q2 p2 \\<and> p_io p1 = p_io p2 \\<and> p_io p1 = p_io (p @ [t]) \\<and> target q1 p1 = s1' \\<and> target q2 p2 = s2'))\"\n    let ?P2' = \"(target (initial (canonical_separator M q1 q2)) (p @ [t]) = Inr q1 \\<longrightarrow> (\\<exists>p1 p2 ta. path M q1 (p1 @ [ta]) \\<and> path M q2 p2 \\<and> p_io (p1 @ [ta]) = p_io (p @ [t]) \\<and> p_io p2 = butlast (p_io (p @ [t]))) \\<and> (\\<nexists>p2. path M q2 p2 \\<and> p_io p2 = p_io (p @ [t])))\"\n    let ?P3' = \"(target (initial (canonical_separator M q1 q2)) (p @ [t]) = Inr q2 \\<longrightarrow> (\\<exists>p1 p2 ta. path M q1 p1 \\<and> path M q2 (p2 @ [ta]) \\<and> p_io p1 = butlast (p_io (p @ [t])) \\<and> p_io (p2 @ [ta]) = p_io (p @ [t])) \\<and> (\\<nexists>p1. path M q1 p1 \\<and> p_io p1 = p_io (p @ [t])))\"\n\n    let ?P = \"(product (from_FSM M q1) (from_FSM M q2))\"\n    \n    obtain p' where \"path ?P (initial ?P) p'\"\n              and   *:\"p = map (\\<lambda>t. (Inl (t_source t), t_input t, t_output t, Inl (t_target t))) p'\"\n      using canonical_separator_path_from_shift[OF \\<open>path ?C (initial ?C) p\\<close> canonical_separator_path_split_target_isl[OF snoc.prems assms(2,3)] assms(2,3)]\n      by blast\n      \n  \n    let ?pL = \"(map (\\<lambda>t. (fst (t_source t), t_input t, t_output t, fst (t_target t))) p')\"\n    let ?pR = \"(map (\\<lambda>t. (snd (t_source t), t_input t, t_output t, snd (t_target t))) p')\"\n  \n    have \"path ?P (q1,q2) p'\"\n      using \\<open>path ?P (initial ?P) p'\\<close> assms(2,3) unfolding product_simps(1) from_FSM_simps(1) by simp  \n    then have pL: \"path (from_FSM M q1) q1 ?pL\"\n         and  pR: \"path (from_FSM M q2) q2 ?pR\"\n      using product_path[of \"from_FSM M q1\" \"from_FSM M q2\" q1 q2 p'] by simp+\n\n    have \"p_io ?pL = p_io p\" and \"p_io ?pR = p_io p\"\n      using * by auto\n\n    have pf1: \"path (from_FSM M q1) (initial (from_FSM M q1)) ?pL\"\n      using pL assms(2) unfolding from_FSM_simps(1) by auto\n    have pf2: \"path (from_FSM M q2) (initial (from_FSM M q2)) ?pR\"\n      using pR assms(3) unfolding from_FSM_simps(1) by auto\n    have pio: \"p_io ?pL = p_io ?pR\"\n      by auto\n    \n    have \"p_io (zip_path ?pL ?pR) = p_io ?pL\"\n      by (induction p'; auto)\n\n    have zip1: \"path ?P (initial ?P) (zip_path ?pL ?pR)\"\n    and  \"target (initial ?P) (zip_path ?pL ?pR) = (target q1 ?pL, target q2 ?pR)\"\n      using product_path_from_paths[OF pf1 pf2 pio] assms(2,3)\n      unfolding from_FSM_simps(1) by simp+\n      \n    have \"p_io (zip_path ?pL ?pR) = p_io p\"\n      using \\<open>p_io ?pL = p_io p\\<close> \\<open>p_io (zip_path ?pL ?pR) = p_io ?pL\\<close> by auto \n    have \"observable ?P\"\n      using product_observable[OF from_FSM_observable[OF assms(4)] from_FSM_observable[OF assms(4)]] by assumption\n    \n    have \"p_io p' = p_io p\"\n      using * by auto\n    \n    obtain s1 s2 where \"t_source t = Inl (s1,s2)\"\n      using canonical_separator_path_split_target_isl[OF snoc.prems(1) assms(2,3)] \n      by (metis \\<open>t_source t = target (initial (canonical_separator M q1 q2)) p\\<close> isl_def old.prod.exhaust)\n  \n    have \"map t_target p = map (Inl o t_target) p'\"\n      using * by auto\n    have \"target (initial ?C) p = Inl (target (q1,q2) p')\"\n      unfolding target.simps visited_nodes.simps canonical_separator_simps[OF assms(2,3)] \n      unfolding \\<open>map t_target p = map (Inl o t_target) p'\\<close>\n      by (simp add: last_map)\n    then have \"target (q1,q2) p'= (s1,s2)\"\n      using \\<open>t_source t = target (initial ?C) p\\<close> \\<open>t_source t = Inl (s1,s2)\\<close>\n      by auto \n      \n    have \"target q1 ?pL = s1\" and \"target q2 ?pR = s2\"  \n      using product_target_split[OF \\<open>target (q1,q2) p'= (s1,s2)\\<close>] by auto\n\n    consider (a) \"(\\<exists>s1' s2'. t_target t = Inl (s1', s2'))\" |\n             (b) \"t_target t = Inr q1\" |\n             (c) \"t_target t = Inr q2\"\n      using canonical_separator_transition(4)[OF \\<open>t \\<in> transitions ?C\\<close> \\<open>q1 \\<in> nodes M\\<close> \\<open>q2 \\<in> nodes M\\<close> \\<open>t_source t = Inl (s1,s2)\\<close> \\<open>observable M\\<close> \\<open>q1 \\<noteq> q2\\<close>]\n      by blast\n    then show \"?P1' \\<and> ?P2' \\<and> ?P3'\" proof cases\n      case a\n      then obtain s1' s2' where \"t_target t = Inl (s1',s2')\"\n        by blast\n\n      let ?t1 = \"(s1, t_input t, t_output t, s1')\"\n      let ?t2 = \"(s2, t_input t, t_output t, s2')\"\n\n      have \"?t1 \\<in> transitions M\" \n      and  \"?t2 \\<in> transitions M\"\n        using canonical_separator_transition(1)[OF \\<open>t \\<in> transitions ?C\\<close> \\<open>q1 \\<in> nodes M\\<close> \\<open>q2 \\<in> nodes M\\<close> \\<open>t_source t = Inl (s1,s2)\\<close> \\<open>observable M\\<close>  \\<open>q1 \\<noteq> q2\\<close> \\<open>t_target t = Inl (s1',s2')\\<close>] \n        by auto\n\n      have \"target (initial (canonical_separator M q1 q2)) (p @ [t]) = Inl (s1', s2')\"\n        using \\<open>t_target t = Inl (s1',s2')\\<close> by auto\n\n      have \"path M q1 (?pL@[?t1])\"\n        using path_append_transition[OF from_FSM_path[OF \\<open>q1 \\<in> nodes M\\<close> pL] \\<open>?t1 \\<in> transitions M\\<close>] \\<open>target q1 ?pL = s1\\<close> by auto\n      moreover have \"path M q2 (?pR@[?t2])\"\n        using path_append_transition[OF from_FSM_path[OF \\<open>q2 \\<in> nodes M\\<close> pR] \\<open>?t2 \\<in> transitions M\\<close>] \\<open>target q2 ?pR = s2\\<close> by auto\n      moreover have \"p_io (?pL@[?t1]) = p_io (?pR@[?t2])\"\n        by auto\n      moreover have \"p_io (?pL@[?t1]) = p_io (p@[t])\"\n        using \\<open>p_io ?pL = p_io p\\<close> by auto\n      moreover have \"target q1 (?pL@[?t1]) = s1'\" and \"target q2 (?pR@[?t2]) = s2'\"\n        by auto \n      ultimately have \"path M q1 (?pL@[?t1]) \\<and> path M q2 (?pR@[?t2]) \\<and> p_io (?pL@[?t1]) = p_io (?pR@[?t2]) \\<and> p_io (?pL@[?t1]) = p_io (p@[t]) \\<and> target q1 (?pL@[?t1]) = s1' \\<and> target q2 (?pR@[?t2]) = s2'\"\n        by presburger\n      then have \"(\\<exists>p1 p2. path M q1 p1 \\<and> path M q2 p2 \\<and> p_io p1 = p_io p2 \\<and> p_io p1 = p_io (p @ [t]) \\<and> target q1 p1 = s1' \\<and> target q2 p2 = s2')\"\n        by meson\n      then have ?P1'\n        using \\<open>target (initial (canonical_separator M q1 q2)) (p @ [t]) = Inl (s1', s2')\\<close> by auto\n      then show ?thesis using \\<open>target (initial (canonical_separator M q1 q2)) (p @ [t]) = Inl (s1', s2')\\<close> \n        by auto\n    next\n      case b\n      then have \"target (initial (canonical_separator M q1 q2)) (p @ [t]) = Inr q1\"\n        by auto\n\n      have \"(\\<exists>t'\\<in>(transitions M). t_source t' = s1 \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)\"\n      and  \"\\<not> (\\<exists>t'\\<in>(transitions M). t_source t' = s2 \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)\"\n        using canonical_separator_transition(2)[OF \\<open>t \\<in> transitions ?C\\<close> \\<open>q1 \\<in> nodes M\\<close> \\<open>q2 \\<in> nodes M\\<close> \\<open>t_source t = Inl (s1,s2)\\<close> \\<open>observable M\\<close>  \\<open>q1 \\<noteq> q2\\<close> b] by blast+\n\n      then obtain t' where \"t' \\<in> transitions M\" and \"t_source t' = s1\" and \"t_input t' = t_input t\" and \"t_output t' = t_output t\"\n        by blast\n\n      have \"path M q1 (?pL@[t'])\"\n        using path_append_transition[OF from_FSM_path[OF \\<open>q1 \\<in> nodes M\\<close> pL] \\<open>t' \\<in> transitions M\\<close>] \\<open>target q1 ?pL = s1\\<close> \\<open>t_source t' = s1\\<close> by auto\n      moreover have \"p_io (?pL@[t']) = p_io (p@[t])\"\n        using \\<open>p_io ?pL = p_io p\\<close> \\<open>t_input t' = t_input t\\<close> \\<open>t_output t' = t_output t\\<close> by auto\n      moreover have \"p_io ?pR = butlast (p_io (p @ [t]))\"\n        using \\<open>p_io ?pR = p_io p\\<close> by auto\n      ultimately have \"path M q1 (?pL@[t']) \\<and> path M q2 ?pR \\<and> p_io (?pL@[t']) = p_io (p @ [t]) \\<and> p_io ?pR = butlast (p_io (p @ [t]))\"\n        using from_FSM_path[OF \\<open>q2 \\<in> nodes M\\<close> pR] by linarith\n      then have \"(\\<exists>p1 p2 ta. path M q1 (p1 @ [ta]) \\<and> path M q2 p2 \\<and> p_io (p1 @ [ta]) = p_io (p @ [t]) \\<and> p_io p2 = butlast (p_io (p @ [t])))\"\n        by meson\n            \n      moreover have \"(\\<nexists>p2. path M q2 p2 \\<and> p_io p2 = p_io (p @ [t]))\"\n      proof \n        assume \"\\<exists>p2. path M q2 p2 \\<and> p_io p2 = p_io (p @ [t])\"\n        then obtain p'' where \"path M q2 p'' \\<and> p_io p'' = p_io (p @ [t])\"\n          by blast\n        then have \"p'' \\<noteq> []\" by auto\n        then obtain p2 t2 where \"p'' = p2@[t2]\"\n          using rev_exhaust by blast\n        then have \"path M q2 (p2@[t2])\" and \"p_io (p2@[t2]) = p_io (p @ [t])\"\n          using \\<open>path M q2 p'' \\<and> p_io p'' = p_io (p @ [t])\\<close> by auto\n        then have \"path M q2 p2\" by auto\n\n\n        then have pf2': \"path (from_FSM M q2) (initial (from_FSM M q2)) p2\"\n          using from_FSM_path_initial[OF \\<open>q2 \\<in> nodes M\\<close>, of p2] by simp\n        have pio': \"p_io ?pL = p_io p2\"\n          using \\<open>p_io (?pL@[t']) = p_io (p@[t])\\<close> \\<open>p_io (p2@[t2]) = p_io (p @ [t])\\<close> by auto\n\n        have zip2: \"path ?P (initial ?P) (zip_path ?pL p2)\"\n        and  \"target (initial ?P) (zip_path ?pL p2) = (target q1 ?pL, target q2 p2)\"\n          using product_path_from_paths[OF pf1 pf2' pio'] assms(2,3)\n          unfolding from_FSM_simps(1) by simp+\n\n        have \"length p' = length p2\"\n          using \\<open>p_io (p2@[t2]) = p_io (p @ [t])\\<close> \n          by (metis (no_types, lifting) length_map pio') \n        then have \"p_io (zip_path ?pL p2) = p_io p'\"\n          by (induction p' p2 rule: list_induct2; auto)\n        then have \"p_io (zip_path ?pL p2) = p_io p\"\n          using * by auto\n        then have \"p_io (zip_path ?pL ?pR) = p_io (zip_path ?pL p2)\" \n          using \\<open>p_io (zip_path ?pL ?pR) = p_io p\\<close> by simp\n\n        have \"p_io ?pR = p_io p2\"\n          using \\<open>p_io ?pL = p_io p2\\<close> pio by auto \n\n\n        have l1: \"length ?pL = length ?pR\" by auto\n        have l2: \"length ?pR = length ?pL\" by auto \n        have l3: \"length ?pL = length p2\" using \\<open>length p' = length p2\\<close> by auto\n        \n        have \"p2 = ?pR\"\n          using zip_path_eq_right[OF l1 l2 l3 \\<open>p_io ?pR = p_io p2\\<close> observable_path_unique[OF \\<open>observable ?P\\<close> zip1 zip2 \\<open>p_io (zip_path ?pL ?pR) = p_io (zip_path ?pL p2)\\<close>]] by simp\n        then have \"target q2 p2 = s2\"\n          using \\<open>target q2 ?pR = s2\\<close> by auto\n        then have \"t2 \\<in> transitions M\" and \"t_source t2 = s2\"\n          using \\<open>path M q2 (p2@[t2])\\<close> by auto\n        moreover have \"t_input t2 = t_input t \\<and> t_output t2 = t_output t\"\n          using \\<open>p_io (p2@[t2]) = p_io (p @ [t])\\<close> by auto\n        ultimately show \"False\"\n          using \\<open>\\<not> (\\<exists>t'\\<in>(transitions M). t_source t' = s2 \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)\\<close> by blast\n      qed\n\n      ultimately have ?P2' \n        by blast\n      moreover have ?P3' \n        using  \\<open>q1 \\<noteq> q2\\<close> \\<open>t_target t = Inr q1\\<close> by auto\n      moreover have ?P1'\n       using \\<open>target (initial (canonical_separator M q1 q2)) (p @ [t]) = Inr q1\\<close> by auto\n     ultimately show ?thesis\n       by blast\n    next\n      case c\n      then have \"target (initial (canonical_separator M q1 q2)) (p @ [t]) = Inr q2\"\n        by auto\n\n      have \"(\\<exists>t'\\<in>(transitions M). t_source t' = s2 \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)\"\n      and  \"\\<not> (\\<exists>t'\\<in>(transitions M). t_source t' = s1 \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)\"\n        using canonical_separator_transition(3)[OF \\<open>t \\<in> transitions ?C\\<close> \\<open>q1 \\<in> nodes M\\<close> \\<open>q2 \\<in> nodes M\\<close> \\<open>t_source t = Inl (s1,s2)\\<close> \\<open>observable M\\<close>  \\<open>q1 \\<noteq> q2\\<close> c] by blast+\n\n      then obtain t' where \"t' \\<in> transitions M\" and \"t_source t' = s2\" and \"t_input t' = t_input t\" and \"t_output t' = t_output t\"\n        by blast\n\n      have \"path M q2 (?pR@[t'])\"\n        using path_append_transition[OF from_FSM_path[OF \\<open>q2 \\<in> nodes M\\<close> pR] \\<open>t' \\<in> transitions M\\<close>] \\<open>target q2 ?pR = s2\\<close> \\<open>t_source t' = s2\\<close> by auto\n      moreover have \"p_io (?pR@[t']) = p_io (p@[t])\"\n        using \\<open>p_io ?pR = p_io p\\<close> \\<open>t_input t' = t_input t\\<close> \\<open>t_output t' = t_output t\\<close> by auto\n      moreover have \"p_io ?pL = butlast (p_io (p @ [t]))\"\n        using \\<open>p_io ?pL = p_io p\\<close> by auto\n      ultimately have \"path M q2 (?pR@[t']) \\<and> path M q1 ?pL \\<and> p_io (?pR@[t']) = p_io (p @ [t]) \\<and> p_io ?pL = butlast (p_io (p @ [t]))\"\n        using from_FSM_path[OF \\<open>q1 \\<in> nodes M\\<close> pL] by linarith\n      then have \"(\\<exists>p1 p2 ta. path M q1 p1 \\<and> path M q2 (p2 @ [ta]) \\<and> p_io p1 = butlast (p_io (p @ [t])) \\<and> p_io (p2 @ [ta]) = p_io (p @ [t]))\"\n        by meson\n            \n      moreover have \"(\\<nexists>p1. path M q1 p1 \\<and> p_io p1 = p_io (p @ [t]))\"\n      proof \n        assume \"\\<exists>p1. path M q1 p1 \\<and> p_io p1 = p_io (p @ [t])\"\n        then obtain p'' where \"path M q1 p'' \\<and> p_io p'' = p_io (p @ [t])\"\n          by blast\n        then have \"p'' \\<noteq> []\" by auto\n        then obtain p1 t1 where \"p'' = p1@[t1]\"\n          using rev_exhaust by blast\n        then have \"path M q1 (p1@[t1])\" and \"p_io (p1@[t1]) = p_io (p @ [t])\"\n          using \\<open>path M q1 p'' \\<and> p_io p'' = p_io (p @ [t])\\<close> by auto\n        then have \"path M q1 p1\" \n          by auto\n        then have pf1': \"path (from_FSM M q1) (initial (from_FSM M q1)) p1\"\n          using from_FSM_path_initial[OF \\<open>q1 \\<in> nodes M\\<close>, of p1] by simp\n        have pio': \"p_io p1 = p_io ?pR\"\n          using \\<open>p_io (?pR@[t']) = p_io (p@[t])\\<close> \\<open>p_io (p1@[t1]) = p_io (p @ [t])\\<close> by auto\n\n        have zip2: \"path ?P (initial ?P) (zip_path p1 ?pR)\"\n          using product_path_from_paths[OF pf1' pf2 pio']\n          unfolding from_FSM_simps(1) by simp\n\n        have \"length p' = length p1\"\n          using \\<open>p_io (p1@[t1]) = p_io (p @ [t])\\<close> \n          by (metis (no_types, lifting) length_map pio') \n        then have \"p_io (zip_path p1 ?pR) = p_io p'\"\n          using \\<open>p_io p1 = p_io ?pR\\<close> by (induction p' p1 rule: list_induct2; auto)\n        then have \"p_io (zip_path p1 ?pR) = p_io p\"\n          using * by auto\n        then have \"p_io (zip_path ?pL ?pR) = p_io (zip_path p1 ?pR)\" \n          using \\<open>p_io (zip_path ?pL ?pR) = p_io p\\<close> by simp\n        \n        have l1: \"length ?pL = length ?pR\" by auto\n        have l2: \"length ?pR = length p1\" using \\<open>length p' = length p1\\<close> by auto\n        have l3: \"length p1 = length ?pR\" using l2 by auto\n        \n        have \"?pL = p1\"\n          using zip_path_eq_left[OF l1 l2 l3 observable_path_unique[OF \\<open>observable ?P\\<close> zip1 zip2 \\<open>p_io (zip_path ?pL ?pR) = p_io (zip_path p1 ?pR)\\<close>]] by simp\n        then have \"target q1 p1 = s1\"\n          using \\<open>target q1 ?pL = s1\\<close> by auto\n        then have \"t1 \\<in> transitions M\" and \"t_source t1 = s1\"\n          using \\<open>path M q1 (p1@[t1])\\<close> by auto\n        moreover have \"t_input t1 = t_input t \\<and> t_output t1 = t_output t\"\n          using \\<open>p_io (p1@[t1]) = p_io (p @ [t])\\<close> by auto\n        ultimately show \"False\"\n          using \\<open>\\<not> (\\<exists>t'\\<in>(transitions M). t_source t' = s1 \\<and> t_input t' = t_input t \\<and> t_output t' = t_output t)\\<close> by blast\n      qed\n\n      ultimately have ?P3' \n        by blast\n      moreover have ?P2' \n        using \\<open>q1 \\<noteq> q2\\<close> \\<open>t_target t = Inr q2\\<close> by auto\n      moreover have ?P1'\n        using \\<open>target (initial (canonical_separator M q1 q2)) (p @ [t]) = Inr q2\\<close> by auto\n      ultimately show ?thesis\n        by blast\n    qed \n  qed\n\n  then show  \"\\<And> s1' s2' . target (initial (canonical_separator M q1 q2)) p = Inl (s1',s2') \\<Longrightarrow> (\\<exists> p1 p2 . path M q1 p1 \\<and> path M q2 p2 \\<and> p_io p1 = p_io p2 \\<and> p_io p1 = p_io p \\<and> target q1 p1 = s1' \\<and> target q2 p2 = s2')\"\n       and   \"target (initial (canonical_separator M q1 q2)) p = Inr q1 \\<Longrightarrow> (\\<exists> p1 p2 t . path M q1 (p1@[t]) \\<and> path M q2 p2 \\<and> p_io (p1@[t]) = p_io p \\<and> p_io p2 = butlast (p_io p)) \\<and> (\\<not>(\\<exists> p2 . path M q2 p2 \\<and> p_io p2 = p_io p))\"\n       and   \"target (initial (canonical_separator M q1 q2)) p = Inr q2 \\<Longrightarrow> (\\<exists> p1 p2 t . path M q1 p1 \\<and> path M q2 (p2@[t]) \\<and> p_io p1 = butlast (p_io p) \\<and> p_io (p2@[t]) = p_io p) \\<and> (\\<not>(\\<exists> p1 . path M q1 p1 \\<and> p_io p1 = p_io p))\"\n    by blast+\n\n  \n  show   \"(\\<exists> s1' s2' . target (initial (canonical_separator M q1 q2)) p = Inl (s1',s2')) \\<or> target (initial (canonical_separator M q1 q2)) p = Inr q1 \\<or> target (initial (canonical_separator M q1 q2)) p = Inr q2\"\n  proof (cases p rule: rev_cases)\n    case Nil\n    then show ?thesis unfolding canonical_separator_simps(1)[OF assms(2,3)] by auto\n  next\n    case (snoc p' t)\n    then have \"t \\<in> transitions ?C\" and \"target (initial (canonical_separator M q1 q2)) p = t_target t\"\n      using assms(1) by auto\n    then have \"t \\<in> (transitions ?C)\"\n      by auto\n    obtain s1 s2 where \"t_source t = Inl (s1,s2)\"\n      using canonical_separator_t_source_isl[OF \\<open>t \\<in> (transitions ?C)\\<close> assms(2,3)]\n      by (metis sum.collapse(1) surjective_pairing)\n    show ?thesis\n      using canonical_separator_transition(4)[OF \\<open>t \\<in> transitions ?C\\<close> assms(2,3) \\<open>t_source t = Inl (s1,s2)\\<close> assms(4) \\<open>q1 \\<noteq> q2\\<close>] \n            \\<open>target (initial (canonical_separator M q1 q2)) p = t_target t\\<close>\n      by simp \n  qed \nqed\n\n\n(* does not assume observability of M (in contrast to the much stronger canonical_separator_path_initial) *)\nlemma canonical_separator_path_initial_ex :\n  assumes \"path (canonical_separator M q1 q2) (initial (canonical_separator M q1 q2)) p\" (is \"path ?C (initial ?C) p\")\n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\nshows \"(\\<exists> p1 . path M q1 p1 \\<and> p_io p1 = p_io p) \\<or> (\\<exists> p2 . path M q2 p2 \\<and> p_io p2 = p_io p)\"\nand   \"(\\<exists> p1 p2 . path M q1 p1 \\<and> path M q2 p2 \\<and> p_io p1 = butlast (p_io p) \\<and> p_io p2 = butlast (p_io p))\"\nproof -\n  have \"((\\<exists> p1 . path M q1 p1 \\<and> p_io p1 = p_io p) \\<or> (\\<exists> p2 . path M q2 p2 \\<and> p_io p2 = p_io p))\n         \\<and> (\\<exists> p1 p2 . path M q1 p1 \\<and> path M q2 p2 \\<and> p_io p1 = butlast (p_io p) \\<and> p_io p2 = butlast (p_io p))\"\n  using assms proof (induction p rule: rev_induct) \n    case Nil\n    then show ?case by auto\n  next\n    case (snoc t p)\n    then have \"path ?C (initial ?C) p\" and \"t \\<in> transitions ?C\" and \"t_source t = target (initial ?C) p\"\n      by auto\n  \n    let ?P = \"(product (from_FSM M q1) (from_FSM M q2))\"\n    \n    obtain p' where \"path ?P (initial ?P) p'\"\n              and   *:\"p = map (\\<lambda>t. (Inl (t_source t), t_input t, t_output t, Inl (t_target t))) p'\"\n      using canonical_separator_path_from_shift[OF \\<open>path ?C (initial ?C) p\\<close> canonical_separator_path_split_target_isl[OF snoc.prems(1) assms(2,3)] assms(2,3)]\n      by blast\n  \n    let ?pL = \"(map (\\<lambda>t. (fst (t_source t), t_input t, t_output t, fst (t_target t))) p')\"\n    let ?pR = \"(map (\\<lambda>t. (snd (t_source t), t_input t, t_output t, snd (t_target t))) p')\"\n  \n    have \"path ?P (q1,q2) p'\"\n      using \\<open>path ?P (initial ?P) p'\\<close> assms(2,3) by simp\n  \n    then have pL: \"path (from_FSM M q1) q1 ?pL\"\n         and  pR: \"path (from_FSM M q2) q2 ?pR\"\n      using product_path[of \"from_FSM M q1\" \"from_FSM M q2\" q1 q2 p'] by auto\n\n    have \"p_io ?pL = butlast (p_io (p@[t]))\" and \"p_io ?pR = butlast (p_io (p@[t]))\"\n      using * by auto\n    then have \"path M q1 ?pL \\<and> path M q2 ?pR \\<and> p_io ?pL = butlast (p_io (p@[t])) \\<and> p_io ?pR = butlast (p_io (p@[t]))\"\n      using from_FSM_path[OF \\<open>q1 \\<in> nodes M\\<close> pL] from_FSM_path[OF \\<open>q2 \\<in> nodes M\\<close> pR] by auto\n    then have \"(\\<exists>p1 p2. path M q1 p1 \\<and> path M q2 p2 \\<and> p_io p1 = butlast (p_io (p @ [t])) \\<and> p_io p2 = butlast (p_io (p @ [t])))\"\n      by blast\n    \n    obtain s1 s2 where \"t_source t = Inl (s1,s2)\"\n      using canonical_separator_path_split_target_isl[OF snoc.prems(1) assms(2,3)] \n      by (metis \\<open>t_source t = target (initial (canonical_separator M q1 q2)) p\\<close> isl_def old.prod.exhaust)\n  \n    have \"map t_target p = map (Inl o t_target) p'\"\n      using * by auto\n    then have \"target (initial ?C) p = Inl (target (q1,q2) p')\"\n      unfolding target.simps visited_nodes.simps canonical_separator_simps(1)[OF assms(2,3)] \n      by (simp add: last_map) \n    then have \"target (q1,q2) p'= (s1,s2)\"\n      using \\<open>t_source t = target (initial ?C) p\\<close> \\<open>t_source t = Inl (s1,s2)\\<close>\n      by auto \n      \n    have \"target q1 ?pL = s1\" and \"target q2 ?pR = s2\"  \n      using product_target_split[OF \\<open>target (q1,q2) p'= (s1,s2)\\<close>] by auto\n  \n    consider (a) \"(\\<exists>t1\\<in>(transitions M). t_source t1 = s1 \\<and> t_input t1 = t_input t \\<and> t_output t1 = t_output t)\" |\n             (b) \"(\\<exists>t2\\<in>(transitions M). t_source t2 = s2 \\<and> t_input t2 = t_input t \\<and> t_output t2 = t_output t)\"\n      using canonical_separator_transition_ex[OF \\<open>t \\<in> transitions ?C\\<close> \\<open>q1 \\<in> nodes M\\<close> \\<open>q2 \\<in> nodes M\\<close> \\<open>t_source t = Inl (s1,s2)\\<close>] by blast\n    then show ?case proof cases\n      case a\n      then obtain t1 where \"t1 \\<in> transitions M\" and \"t_source t1 = s1\" and \"t_input t1 = t_input t\" and \"t_output t1 = t_output t\" \n        by blast\n  \n      have \"t_source t1 = target q1 ?pL\"\n        using \\<open>target q1 ?pL = s1\\<close> \\<open>t_source t1 = s1\\<close> by auto\n      then have \"path M q1 (?pL@[t1])\"\n        using pL \\<open>t1 \\<in> transitions M\\<close>\n        by (meson from_FSM_path path_append_transition snoc.prems(2))\n      moreover have \"p_io (?pL@[t1]) = p_io (p@[t])\"\n        using * \\<open>t_input t1 = t_input t\\<close> \\<open>t_output t1 = t_output t\\<close> by auto\n      ultimately show ?thesis\n        using \\<open>(\\<exists>p1 p2. path M q1 p1 \\<and> path M q2 p2 \\<and> p_io p1 = butlast (p_io (p @ [t])) \\<and> p_io p2 = butlast (p_io (p @ [t])))\\<close>\n        by meson\n    next\n      case b\n      then obtain t2 where \"t2 \\<in> transitions M\" and \"t_source t2 = s2\" and \"t_input t2 = t_input t\" and \"t_output t2 = t_output t\" \n        by blast\n  \n      have \"t_source t2 = target q2 ?pR\"\n        using \\<open>target q2 ?pR = s2\\<close> \\<open>t_source t2 = s2\\<close> by auto\n      then have \"path M q2 (?pR@[t2])\"\n        using pR \\<open>t2 \\<in> transitions M\\<close>\n        by (meson from_FSM_path path_append_transition snoc.prems(3))\n      moreover have \"p_io (?pR@[t2]) = p_io (p@[t])\"\n        using * \\<open>t_input t2 = t_input t\\<close> \\<open>t_output t2 = t_output t\\<close> by auto\n      ultimately show ?thesis\n        using \\<open>(\\<exists>p1 p2. path M q1 p1 \\<and> path M q2 p2 \\<and> p_io p1 = butlast (p_io (p @ [t])) \\<and> p_io p2 = butlast (p_io (p @ [t])))\\<close>\n        by meson\n    qed\n  qed\n  then show \"(\\<exists> p1 . path M q1 p1 \\<and> p_io p1 = p_io p) \\<or> (\\<exists> p2 . path M q2 p2 \\<and> p_io p2 = p_io p)\"\n       and  \"(\\<exists> p1 p2 . path M q1 p1 \\<and> path M q2 p2 \\<and> p_io p1 = butlast (p_io p) \\<and> p_io p2 = butlast (p_io p))\"\n    by blast+\nqed\n\n\nlemma canonical_separator_language :\n  assumes \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\nshows \"L (canonical_separator M q1 q2) \\<subseteq> L (from_FSM M q1) \\<union> L (from_FSM M q2)\" (is \"L ?C \\<subseteq> L ?M1 \\<union> L ?M2\")\nproof \n  fix io assume \"io \\<in> L (canonical_separator M q1 q2)\"\n  then obtain p where *: \"path (canonical_separator M q1 q2) (initial (canonical_separator M q1 q2)) p\" and **: \"p_io p = io\"\n    by auto\n  \n  show \"io \\<in> L (from_FSM M q1) \\<union> L (from_FSM M q2)\"\n    using canonical_separator_path_initial_ex[OF * assms] unfolding ** \n    using from_FSM_path_initial[OF assms(1)] from_FSM_path_initial[OF assms(2)]  \n    unfolding LS.simps by blast\nqed\n\n\nlemma canonical_separator_language_prefix :\n  assumes \"io@[xy] \\<in> L (canonical_separator M q1 q2)\"\n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\n  and     \"observable M\"\n  and     \"q1 \\<noteq> q2\"\nshows \"io \\<in> LS M q1\"\nand   \"io \\<in> LS M q2\"\nproof -\n  let ?C = \"(canonical_separator M q1 q2)\"\n  obtain p where \"path ?C (initial ?C) p\" and \"p_io p = io@[xy]\"\n    using assms(1) by auto\n\n  consider (a) \"(\\<exists>s1' s2'. target (initial (canonical_separator M q1 q2)) p = Inl (s1', s2'))\" |\n           (b) \"target (initial (canonical_separator M q1 q2)) p = Inr q1\" | \n           (c) \"target (initial (canonical_separator M q1 q2)) p = Inr q2\"\n    using canonical_separator_path_initial(4)[OF \\<open>path ?C (initial ?C) p\\<close> assms(2,3,4,5)] by blast\n  then have \"io \\<in> LS M q1 \\<and> io \\<in> LS M q2\"\n  proof cases\n    case a\n    then obtain s1 s2 where *: \"target (initial (canonical_separator M q1 q2)) p = Inl (s1, s2)\"\n      by blast\n    show ?thesis using canonical_separator_path_initial(1)[OF \\<open>path ?C (initial ?C) p\\<close> assms(2,3,4,5) *] language_prefix\n      by (metis (mono_tags, lifting) LS.simps \\<open>p_io p = io @ [xy]\\<close> mem_Collect_eq )\n  next\n    case b\n    show ?thesis using canonical_separator_path_initial(2)[OF \\<open>path ?C (initial ?C) p\\<close> assms(2,3,4,5) b]\n      using \\<open>p_io p = io @ [xy]\\<close> by fastforce      \n  next\n    case c\n    show ?thesis using canonical_separator_path_initial(3)[OF \\<open>path ?C (initial ?C) p\\<close> assms(2,3,4,5) c]\n      using \\<open>p_io p = io @ [xy]\\<close> by fastforce\n  qed\n  then show \"io \\<in> LS M q1\" and   \"io \\<in> LS M q2\"\n    by auto\nqed\n\n\nlemma canonical_separator_distinguishing_transitions_left_containment :\n  assumes \"t \\<in> (distinguishing_transitions_left M q1 q2)\"\n      and \"q1 \\<in> nodes M\" and \"q2 \\<in> nodes M\"\n    shows \"t \\<in> transitions (canonical_separator M q1 q2)\" \n  using assms(1) unfolding canonical_separator_transitions_def[OF assms(2,3)] by blast\n\n\nlemma canonical_separator_distinguishing_transitions_right_containment :\n  assumes \"t \\<in> (distinguishing_transitions_right M q1 q2)\"\n      and \"q1 \\<in> nodes M\" and \"q2 \\<in> nodes M\"\n  shows \"t \\<in> transitions (canonical_separator M q1 q2)\" (is \"t \\<in> transitions ?C\")\n   using assms(1) unfolding canonical_separator_transitions_def[OF assms(2,3)] by blast\n\n\nlemma distinguishing_transitions_left_alt_intro :\n  assumes \"(s1,s2) \\<in> nodes (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2))\"\n  and \"(\\<exists>t \\<in> transitions M. t_source t = s1 \\<and> t_input t = x \\<and> t_output t = y)\" \n  and \"\\<not>(\\<exists>t \\<in> transitions M. t_source t = s2 \\<and> t_input t = x \\<and> t_output t = y)\" \nshows \"(Inl (s1,s2), x, y, Inr q1) \\<in> distinguishing_transitions_left_alt M q1 q2\"\n  using assms unfolding distinguishing_transitions_left_alt_def\n  by auto \n\n\nlemma distinguishing_transitions_left_right_intro :\n  assumes \"(s1,s2) \\<in> nodes (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2))\"\n  and \"\\<not>(\\<exists>t \\<in> transitions M. t_source t = s1 \\<and> t_input t = x \\<and> t_output t = y)\" \n  and \"(\\<exists>t \\<in> transitions M. t_source t = s2 \\<and> t_input t = x \\<and> t_output t = y)\" \nshows \"(Inl (s1,s2), x, y, Inr q2) \\<in> distinguishing_transitions_right_alt M q1 q2\"\n  using assms unfolding distinguishing_transitions_right_alt_def\n  by auto \n\n\nlemma canonical_separator_io_from_prefix_left :\n  assumes \"io @ [io1] \\<in> LS M q1\"\n  and     \"io \\<in> LS M q2\"\n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\n  and     \"observable M\"\n  and     \"q1 \\<noteq> q2\"\nshows \"io @ [io1] \\<in> L (canonical_separator M q1 q2)\"\nproof -\n  let ?C = \"canonical_separator M q1 q2\"\n\n  obtain p1 where \"path M q1 p1\" and \"p_io p1 = io @ [io1]\"\n    using \\<open>io @ [io1] \\<in> LS M q1\\<close> by auto\n  then have \"p1 \\<noteq> []\"\n    by auto\n  then obtain pL tL where \"p1 = pL @ [tL]\"\n    using rev_exhaust by blast\n  then have \"path M q1 (pL@[tL])\" and \"path M q1 pL\" and \"p_io pL = io\" and \"tL \\<in> transitions M\" \n        and \"t_input tL = fst io1\" and \"t_output tL = snd io1\" and \"p_io (pL@[tL]) = io @ [io1]\"\n    using \\<open>path M q1 p1\\<close> \\<open>p_io p1 = io @ [io1]\\<close> by auto\n  then have pLf: \"path (from_FSM M q1) (initial (from_FSM M q1)) pL\" \n        and pLf': \"path (from_FSM M q1) (initial (from_FSM M q1)) (pL@[tL])\"\n    using from_FSM_path_initial[OF \\<open>q1 \\<in> nodes M\\<close>] by auto\n\n  obtain pR where \"path M q2 pR\" and \"p_io pR = io\"\n    using \\<open>io \\<in> LS M q2\\<close> by auto\n  then have pRf: \"path (from_FSM M q2) (initial (from_FSM M q2)) pR\"\n    using from_FSM_path_initial[OF \\<open>q2 \\<in> nodes M\\<close>] by auto\n\n  have \"p_io pL = p_io pR\"\n    using \\<open>p_io pL = io\\<close> \\<open>p_io pR = io\\<close> by auto\n\n  let ?pLR = \"zip_path pL pR\"\n  let ?pCLR = \"map shift_Inl ?pLR\"\n  let ?P = \"product (from_FSM M q1) (from_FSM M q2)\"\n\n  have \"path ?P (initial ?P) ?pLR\"\n  and  \"target (initial ?P) ?pLR = (target q1 pL, target q2 pR)\"\n    using product_path_from_paths[OF pLf pRf \\<open>p_io pL = p_io pR\\<close>]\n    unfolding from_FSM_simps[OF assms(3)] from_FSM_simps[OF assms(4)] by linarith+\n\n  have \"path ?C (initial ?C) ?pCLR\"\n    using canonical_separator_path_shift[OF assms(3,4)] \\<open>path ?P (initial ?P) ?pLR\\<close> \n    by simp \n\n  have \"isl (target (initial ?C) ?pCLR)\" \n    unfolding canonical_separator_simps(1)[OF assms(3,4)] by (cases ?pLR rule: rev_cases; auto)\n  then obtain s1 s2 where \"target (initial ?C) ?pCLR = Inl (s1,s2)\"\n    by (metis (no_types, lifting) \\<open>path (canonical_separator M q1 q2) (initial (canonical_separator M q1 q2)) (map (\\<lambda>t. (Inl (t_source t), t_input t, t_output t, Inl (t_target t))) (map (\\<lambda>t. ((t_source (fst t), t_source (snd t)), t_input (fst t), t_output (fst t), t_target (fst t), t_target (snd t))) (zip pL pR)))\\<close> \n          assms(3) assms(4) assms(5) assms(6) canonical_separator_path_initial(4) sum.discI(2))\n  then have \"Inl (s1,s2) \\<in> nodes ?C\"\n    using path_target_is_node[OF \\<open>path ?C (initial ?C) ?pCLR\\<close>] by simp\n  then have \"(s1,s2) \\<in> nodes ?P\"\n    using canonical_separator_nodes[OF _ assms(3,4)] by force\n\n  have \"target (initial ?P) ?pLR = (s1,s2)\"\n    using \\<open>target (initial ?C) ?pCLR = Inl (s1,s2)\\<close> assms(3,4) \n    unfolding canonical_separator_simps(1)[OF assms(3,4)] product_simps(1) from_FSM_simps target.simps visited_nodes.simps \n    by (cases ?pLR rule: rev_cases; auto)\n  then have \"target q1 pL = s1\" and \"target q2 pR = s2\"\n    using \\<open>target (initial ?P) ?pLR = (target q1 pL, target q2 pR)\\<close> by auto\n  then have \"t_source tL = s1\"\n    using \\<open>path M q1 (pL@[tL])\\<close> by auto\n\n  show ?thesis proof (cases \"\\<exists> tR \\<in> (transitions M) . t_source tR = target q2 pR \\<and> t_input tR = t_input tL \\<and> t_output tR = t_output tL\")\n    case True\n    then obtain tR where \"tR \\<in> (transitions M)\" and \"t_source tR = target q2 pR\" and \"t_input tR = t_input tL\" and \"t_output tR = t_output tL\"\n      by blast\n    \n    have \"t_source tR \\<in> nodes M\"\n      unfolding \\<open>t_source tR = target q2 pR\\<close> \\<open>target q2 pR = s2\\<close> \n      using \\<open>(s1,s2) \\<in> nodes ?P\\<close> product_simps(2) from_FSM_simps(2) assms(3,4) by simp\n\n    then have \"tR \\<in> transitions M\"\n      using \\<open>tR \\<in> (transitions M)\\<close> \\<open>t_input tR = t_input tL\\<close> \\<open>t_output tR = t_output tL\\<close> \\<open>tL \\<in> transitions M\\<close> by auto\n\n    then have \"path M q2 (pR@[tR])\" \n      using \\<open>path M q2 pR\\<close> \\<open>t_source tR = target q2 pR\\<close> path_append_transition by metis\n    then have pRf': \"path (from_FSM M q2) (initial (from_FSM M q2)) (pR@[tR])\"\n      using from_FSM_path_initial[OF \\<open>q2 \\<in> nodes M\\<close>] by auto\n    \n    let ?PP = \"(zip_path (pL@[tL]) (pR@[tR]))\"\n    let ?PC = \"map shift_Inl ?PP\"\n\n    have \"length pL = length pR\"\n      using \\<open>p_io pL = p_io pR\\<close> map_eq_imp_length_eq by blast\n    moreover have \"p_io (pL@[tL]) = p_io (pR@[tR])\"\n      using \\<open>p_io pR = io\\<close> \\<open>t_input tL = fst io1\\<close> \\<open>t_output tL = snd io1\\<close> \\<open>t_input tR = t_input tL\\<close> \\<open>t_output tR = t_output tL\\<close> \\<open>p_io (pL@[tL]) = io@[io1]\\<close> by auto\n    ultimately have \"p_io ?PP = p_io (pL@[tL])\"\n      by (induction pL pR rule: list_induct2; auto)\n\n    have \"p_io ?PC = p_io ?PP\"\n      by auto\n           \n    have \"path ?P (initial ?P) ?PP\"\n      using product_path_from_paths(1)[OF pLf' pRf' \\<open>p_io (pL@[tL]) = p_io (pR@[tR])\\<close>] by assumption\n    then have \"path ?C (initial ?C) ?PC\"\n      using canonical_separator_path_shift[OF assms(3,4)] by simp    \n    moreover have \"p_io ?PC = io@[io1]\"\n      using \\<open>p_io (pL@[tL]) = io@[io1]\\<close>  \\<open>p_io ?PP = p_io (pL@[tL])\\<close>  \\<open>p_io ?PC = p_io ?PP\\<close> by simp\n    ultimately have \"\\<exists> p . path ?C (initial ?C) p \\<and> p_io p = io@[io1]\"\n      by blast\n    then show ?thesis unfolding LS.simps by force\n  next\n    case False\n\n    let ?t = \"(Inl (s1,s2), t_input tL, t_output tL, Inr q1)\"\n\n    have \"(s1,s2) \\<in> reachable_nodes (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2))\"\n      by (metis (no_types, lifting) \\<open>path (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2)) (FSM.initial (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2))) (zip_path pL pR)\\<close> \\<open>target (FSM.initial (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2))) (zip_path pL pR) = (s1, s2)\\<close> reachable_nodes_intro)\n    moreover have \"(\\<exists>tR\\<in>FSM.transitions M.\n           t_source tR = target q1 pL \\<and> t_input tR = t_input tL \\<and> t_output tR = t_output tL)\"\n      using \\<open>tL \\<in> transitions M\\<close> \\<open>path M q1 (pL@[tL])\\<close>\n      by auto     \n    ultimately have \"?t \\<in> (distinguishing_transitions_left_alt M q1 q2)\"\n      using distinguishing_transitions_left_alt_intro[OF _ _ False ]  \\<open>q1 \\<noteq> q2\\<close>\n      unfolding \\<open>target q1 pL = s1\\<close> \\<open>target q2 pR = s2\\<close>\n      using \\<open>(s1, s2) \\<in> FSM.nodes (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2))\\<close> by blast\n    then have \"?t \\<in> transitions ?C\" \n      using canonical_separator_distinguishing_transitions_left_containment[OF _ assms(3,4)] unfolding distinguishing_transitions_left_alt_alt_def by blast \n    then have \"path ?C (initial ?C) (?pCLR@[?t])\"\n      using \\<open>path ?C (initial ?C) ?pCLR\\<close> \\<open>target (initial ?C) ?pCLR = Inl (s1,s2)\\<close> \n      by (simp add: path_append_transition)\n\n    have \"length pL = length pR\"\n      using \\<open>p_io pL = p_io pR\\<close> \n      using map_eq_imp_length_eq by blast\n    then have \"p_io ?pCLR = p_io pL\" \n      by (induction pL pR rule: list_induct2; auto)\n    then have \"p_io (?pCLR@[?t]) = io @ [io1]\"\n      using \\<open>p_io pL = io\\<close> \\<open>t_input tL = fst io1\\<close> \\<open>t_output tL = snd io1\\<close>\n      by auto\n    then have \"\\<exists> p . path ?C (initial ?C) p \\<and> p_io p = io@[io1]\"\n      using \\<open>path ?C (initial ?C) (?pCLR@[?t])\\<close> by meson\n    then show ?thesis \n      unfolding LS.simps by force\n  qed\nqed\n\n\n\n\n\nlemma canonical_separator_path_targets_language :\n  assumes \"path (canonical_separator M q1 q2) (initial (canonical_separator M q1 q2)) p\"\n  and     \"observable M\" \n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\n  and     \"q1 \\<noteq> q2\"\nshows \"isl (target (initial (canonical_separator M q1 q2)) p) \\<Longrightarrow> p_io p \\<in> LS M q1 \\<inter> LS M q2\"\nand   \"(target (initial (canonical_separator M q1 q2)) p) = Inr q1 \\<Longrightarrow> p_io p \\<in> LS M q1 - LS M q2 \\<and> p_io (butlast p) \\<in> LS M q1 \\<inter> LS M q2\"\nand   \"(target (initial (canonical_separator M q1 q2)) p) = Inr q2 \\<Longrightarrow> p_io p \\<in> LS M q2 - LS M q1 \\<and> p_io (butlast p) \\<in> LS M q1 \\<inter> LS M q2\"\nand   \"p_io p \\<in> LS M q1 \\<inter> LS M q2 \\<Longrightarrow> isl (target (initial (canonical_separator M q1 q2)) p)\"\nand   \"p_io p \\<in> LS M q1 - LS M q2 \\<Longrightarrow> target (initial (canonical_separator M q1 q2)) p = Inr q1\"\nand   \"p_io p \\<in> LS M q2 - LS M q1 \\<Longrightarrow> target (initial (canonical_separator M q1 q2)) p = Inr q2\"\nproof -\n  let ?C = \"canonical_separator M q1 q2\"\n  let ?tgt = \"target (initial ?C) p\"\n\n  show \"isl ?tgt \\<Longrightarrow> p_io p \\<in> LS M q1 \\<inter> LS M q2\"\n  proof -\n    assume \"isl ?tgt\"\n    then obtain s1 s2 where \"?tgt = Inl (s1,s2)\"\n      by (metis isl_def old.prod.exhaust)\n    then obtain p1 p2 where \"path M q1 p1\" and \"path M q2 p2\" and \"p_io p1 = p_io p\" and \"p_io p2 = p_io p\" \n      using canonical_separator_path_initial(1)[OF assms(1) \\<open>q1 \\<in> nodes M\\<close> \\<open>q2 \\<in> nodes M\\<close> \\<open>observable M\\<close>  \\<open>q1 \\<noteq> q2\\<close> \\<open>?tgt = Inl (s1,s2)\\<close> ] by force\n    then show \"p_io p \\<in> LS M q1 \\<inter> LS M q2\"\n      unfolding LS.simps by force\n  qed\n  moreover show \"?tgt = Inr q1 \\<Longrightarrow> p_io p \\<in> LS M q1 - LS M q2 \\<and> p_io (butlast p) \\<in> LS M q1 \\<inter> LS M q2\"\n  proof -\n    assume \"?tgt = Inr q1\"\n    obtain p1 p2 t where \"path M q1 (p1 @ [t])\" and \"path M q2 p2\" and \"p_io (p1 @ [t]) = p_io p\" \n                     and \"p_io p2 = butlast (p_io p)\" and \"(\\<nexists>p2. path M q2 p2 \\<and> p_io p2 = p_io p)\" \n      using canonical_separator_path_initial(2)[OF assms(1) \\<open>q1 \\<in> nodes M\\<close> \\<open>q2 \\<in> nodes M\\<close> \n            \\<open>observable M\\<close>  \\<open>q1 \\<noteq> q2\\<close> \\<open>?tgt = Inr q1\\<close>] \n      by meson\n\n    have \"path M q1 p1\"\n      using \\<open>path M q1 (p1@[t])\\<close> by auto\n    have \"p_io p1 = butlast (p_io p)\"\n      using \\<open>p_io (p1 @ [t]) = p_io p\\<close> \n      by (metis (no_types, lifting) butlast_snoc map_butlast)\n\n    have \"p_io p \\<in> LS M q1\" \n      using \\<open>path M q1 (p1@[t])\\<close> \\<open>p_io (p1 @ [t]) = p_io p\\<close> unfolding LS.simps by force\n    moreover have \"p_io p \\<notin> LS M q2\"\n      using \\<open>(\\<nexists>p2. path M q2 p2 \\<and> p_io p2 = p_io p)\\<close> unfolding LS.simps by force\n    moreover have \"butlast (p_io p) \\<in> LS M q1\"\n      using \\<open>path M q1 p1\\<close> \\<open>p_io p1 = butlast (p_io p)\\<close> unfolding LS.simps by force\n    moreover have \"butlast (p_io p) \\<in> LS M q2\"\n      using \\<open>path M q2 p2\\<close> \\<open>p_io p2 = butlast (p_io p)\\<close> unfolding LS.simps by force\n    ultimately show \"p_io p \\<in> LS M q1 - LS M q2 \\<and> p_io (butlast p) \\<in> LS M q1 \\<inter> LS M q2\"\n      by (simp add: map_butlast)\n  qed \n  moreover show \"?tgt = Inr q2 \\<Longrightarrow> p_io p \\<in> LS M q2 - LS M q1 \\<and> p_io (butlast p) \\<in> LS M q1 \\<inter> LS M q2\"\n  proof -\n    assume \"?tgt = Inr q2\"\n    obtain p1 p2 t where \"path M q2 (p2 @ [t])\" and \"path M q1 p1\" and \"p_io (p2 @ [t]) = p_io p\" \n                     and \"p_io p1 = butlast (p_io p)\" and \"(\\<nexists>p2. path M q1 p2 \\<and> p_io p2 = p_io p)\" \n      using canonical_separator_path_initial(3)[OF assms(1) \\<open>q1 \\<in> nodes M\\<close> \\<open>q2 \\<in> nodes M\\<close> \n            \\<open>observable M\\<close> \\<open>q1 \\<noteq> q2\\<close> \\<open>?tgt = Inr q2\\<close>] \n      by meson\n\n    have \"path M q2 p2\"\n      using \\<open>path M q2 (p2@[t])\\<close> by auto\n    have \"p_io p2 = butlast (p_io p)\"\n      using \\<open>p_io (p2 @ [t]) = p_io p\\<close> \n      by (metis (no_types, lifting) butlast_snoc map_butlast)\n\n    have \"p_io p \\<in> LS M q2\" \n      using \\<open>path M q2 (p2@[t])\\<close> \\<open>p_io (p2 @ [t]) = p_io p\\<close> unfolding LS.simps by force\n    moreover have \"p_io p \\<notin> LS M q1\"\n      using \\<open>(\\<nexists>p2. path M q1 p2 \\<and> p_io p2 = p_io p)\\<close> unfolding LS.simps by force\n    moreover have \"butlast (p_io p) \\<in> LS M q1\"\n      using \\<open>path M q1 p1\\<close> \\<open>p_io p1 = butlast (p_io p)\\<close> unfolding LS.simps by force\n    moreover have \"butlast (p_io p) \\<in> LS M q2\"\n      using \\<open>path M q2 p2\\<close> \\<open>p_io p2 = butlast (p_io p)\\<close> unfolding LS.simps by force\n    ultimately show \"p_io p \\<in> LS M q2 - LS M q1 \\<and> p_io (butlast p) \\<in> LS M q1 \\<inter> LS M q2\"\n      by (simp add: map_butlast)\n  qed \n  moreover have \"isl ?tgt \\<or> ?tgt = Inr q1 \\<or> ?tgt = Inr q2\"\n    using canonical_separator_path_initial(4)[OF assms(1) \\<open>q1 \\<in> nodes M\\<close> \\<open>q2 \\<in> nodes M\\<close> \\<open>observable M\\<close>  \\<open>q1 \\<noteq> q2\\<close>] by force\n  ultimately show \"p_io p \\<in> LS M q1 \\<inter> LS M q2 \\<Longrightarrow> isl (target (initial (canonical_separator M q1 q2)) p)\"\n             and  \"p_io p \\<in> LS M q1 - LS M q2 \\<Longrightarrow> target (initial (canonical_separator M q1 q2)) p = Inr q1\"\n             and  \"p_io p \\<in> LS M q2 - LS M q1 \\<Longrightarrow> target (initial (canonical_separator M q1 q2)) p = Inr q2\"\n    by blast+\nqed\n  \n\nlemma canonical_separator_language_target :\n  assumes \"io \\<in> L (canonical_separator M q1 q2)\"\n  and     \"observable M\" \n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\n  and     \"q1 \\<noteq> q2\"\nshows \"io \\<in> LS M q1 - LS M q2 \\<Longrightarrow> io_targets (canonical_separator M q1 q2) io (initial (canonical_separator M q1 q2)) = {Inr q1}\"\nand   \"io \\<in> LS M q2 - LS M q1 \\<Longrightarrow> io_targets (canonical_separator M q1 q2) io (initial (canonical_separator M q1 q2)) = {Inr q2}\"\nproof -\n  let ?C = \"canonical_separator M q1 q2\"\n  obtain p where \"path ?C (initial ?C) p\" and \"p_io p = io\"\n    using assms(1) by force\n\n  show \"io \\<in> LS M q1 - LS M q2 \\<Longrightarrow> io_targets (canonical_separator M q1 q2) io (initial (canonical_separator M q1 q2)) = {Inr q1}\"\n  proof -\n    assume \"io \\<in> LS M q1 - LS M q2\"\n    then have \"p_io p \\<in> LS M q1 - LS M q2\"\n      using \\<open>p_io p = io\\<close> by auto\n    have \"Inr q1 \\<in> io_targets ?C io (initial ?C)\"\n      using canonical_separator_path_targets_language(5)[OF \\<open>path ?C (initial ?C) p\\<close> assms(2,3,4,5) \\<open>p_io p \\<in> LS M q1 - LS M q2\\<close>]\n      using \\<open>path ?C (initial ?C) p\\<close> unfolding io_targets.simps \n      by (metis (mono_tags, lifting) \\<open>p_io p = io\\<close> mem_Collect_eq)\n    then show ?thesis\n      by (metis (mono_tags, lifting) assms(1) assms(2) assms(3) assms(4) canonical_separator_observable observable_io_targets singletonD)\n  qed\n\n  show \"io \\<in> LS M q2 - LS M q1 \\<Longrightarrow> io_targets (canonical_separator M q1 q2) io (initial (canonical_separator M q1 q2)) = {Inr q2}\"\n  proof -\n    assume \"io \\<in> LS M q2 - LS M q1\"\n    then have \"p_io p \\<in> LS M q2 - LS M q1\"\n      using \\<open>p_io p = io\\<close> by auto\n    have \"Inr q2 \\<in> io_targets ?C io (initial ?C)\"\n      using canonical_separator_path_targets_language(6)[OF \\<open>path ?C (initial ?C) p\\<close> assms(2,3,4,5) \\<open>p_io p \\<in> LS M q2 - LS M q1\\<close>]\n      using \\<open>path ?C (initial ?C) p\\<close> unfolding io_targets.simps \n      by (metis (mono_tags, lifting) \\<open>p_io p = io\\<close> mem_Collect_eq)\n    then show ?thesis\n      by (metis (mono_tags, lifting) assms(1) assms(2) assms(3) assms(4) canonical_separator_observable observable_io_targets singletonD)\n  qed\nqed\n\n\nlemma canonical_separator_language_intersection :\n  assumes \"io \\<in> LS M q1\"\n  and     \"io \\<in> LS M q2\"\n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\nshows \"io \\<in> L (canonical_separator M q1 q2)\" (is \"io \\<in> L ?C\")\nproof -\n  let ?P = \"product (from_FSM M q1) (from_FSM M q2)\"\n\n  have \"io \\<in> L ?P\"\n    using \\<open>io \\<in> LS M q1\\<close> \\<open>io \\<in> LS M q2\\<close> product_language[of \"from_FSM M q1\" \"from_FSM M q2\"] \n    unfolding from_FSM_language[OF \\<open>q1 \\<in> nodes M\\<close>] from_FSM_language[OF \\<open>q2 \\<in> nodes M\\<close>]\n    by blast\n  then obtain p where \"path ?P (initial ?P) p\" and \"p_io p = io\"\n    by auto\n  then have *: \"path ?C (initial ?C) (map shift_Inl p)\"\n    using canonical_separator_path_shift[OF assms(3,4)] by auto\n  have **: \"p_io (map shift_Inl p) = io\"\n    using \\<open>p_io p = io\\<close> by (induction p; auto)\n  show \"io \\<in> L ?C\" \n    using language_state_containment[OF * **] by assumption\nqed\n\n\nlemma canonical_separator_deadlock :\n  assumes \"q1 \\<in> nodes M\"\n      and \"q2 \\<in> nodes M\"\n    shows \"deadlock_state (canonical_separator M q1 q2) (Inr q1)\"\n      and \"deadlock_state (canonical_separator M q1 q2) (Inr q2)\"\n  unfolding deadlock_state.simps \n  by (metis assms(1) assms(2) canonical_separator_t_source_isl sum.disc(2))+\n\n\nlemma canonical_separator_isl_deadlock :\n  assumes \"Inl (q1',q2') \\<in> nodes (canonical_separator M q1 q2)\"\n      and \"x \\<in> inputs M\"\n      and \"completely_specified M\"\n      and \"\\<not>(\\<exists> t \\<in> transitions (canonical_separator M q1 q2) . t_source t = Inl (q1',q2') \\<and> t_input t = x \\<and> isl (t_target t))\"\n      and \"q1 \\<in> nodes M\"\n      and \"q2 \\<in> nodes M\"\nobtains y1 y2 where \"(Inl (q1',q2'),x,y1,Inr q1) \\<in> transitions (canonical_separator M q1 q2)\"\n                    \"(Inl (q1',q2'),x,y2,Inr q2) \\<in> transitions (canonical_separator M q1 q2)\"\nproof -\n  let ?C = \"(canonical_separator M q1 q2)\"\n  let ?P = \"(product (from_FSM M q1) (from_FSM M q2))\"\n\n  have \"(q1',q2') \\<in> nodes ?P\"\n    using assms(1) unfolding canonical_separator_simps[OF assms(5,6)] by fastforce\n  then have \"(q1',q2') \\<in> nodes ?P\"\n    using reachable_node_is_node by force\n  then have \"q1' \\<in> nodes M\" and \"q2' \\<in> nodes M\"\n    using assms(5,6) by auto\n  then obtain y1 y2 where \"y1 \\<in> h_out M (q1',x)\" and \"y2 \\<in> h_out M (q2',x)\"\n    by (metis (no_types, lifting) assms(2,3) h_out.simps completely_specified_alt_def mem_Collect_eq) \n  moreover have \"h_out M (q1',x) \\<inter> h_out M (q2',x) = {}\"\n  proof (rule ccontr)\n    assume \"h_out M (q1', x) \\<inter> h_out M (q2', x) \\<noteq> {}\"\n    then obtain y where \"y \\<in> h_out M (q1', x) \\<inter> h_out M (q2', x)\" by blast\n    then obtain q1'' q2'' where \"((q1',q2'),x,y,(q1'',q2'')) \\<in> transitions ?P\"\n      unfolding product_transitions_def h_out.simps using assms(5,6) by auto\n    then have \"(Inl (q1',q2'),x,y,Inl (q1'',q2'')) \\<in> transitions ?C\"\n      using \\<open>(q1',q2') \\<in> nodes ?P\\<close> unfolding canonical_separator_transitions_def[OF assms(5,6)] h_out.simps by blast\n    then show \"False\"\n      using assms(4) by auto\n  qed\n  ultimately have \"y1 \\<in> h_out M (q1',x) - h_out M (q2',x)\"\n             and  \"y2 \\<in> h_out M (q2',x) - h_out M (q1',x)\"\n    by blast+\n\n  let ?t1 = \"(Inl (q1',q2'),x,y1,Inr q1)\"\n  let ?t2 = \"(Inl (q1',q2'),x,y2,Inr q2)\"\n\n  have \"?t1 \\<in> distinguishing_transitions_left M q1 q2\"\n    using \\<open>(q1',q2') \\<in> nodes ?P\\<close> \\<open>y1 \\<in> h_out M (q1',x) - h_out M (q2',x)\\<close>\n    unfolding distinguishing_transitions_left_def by auto\n  then have \"?t1 \\<in> transitions (canonical_separator M q1 q2)\"\n    unfolding canonical_separator_transitions_def[OF assms(5,6)] by blast\n\n  have \"?t2 \\<in> distinguishing_transitions_right M q1 q2\"\n    using \\<open>(q1',q2') \\<in> nodes ?P\\<close> \\<open>y2 \\<in> h_out M (q2',x) - h_out M (q1',x)\\<close>\n    unfolding distinguishing_transitions_right_def by auto\n  then have \"?t2 \\<in> transitions (canonical_separator M q1 q2)\"\n    unfolding canonical_separator_transitions_def[OF assms(5,6)] by blast\n\n  show ?thesis \n    using that \\<open>?t1 \\<in> transitions (canonical_separator M q1 q2)\\<close> \\<open>?t2 \\<in> transitions (canonical_separator M q1 q2)\\<close> by blast\nqed\n\n\nlemma canonical_separator_deadlocks :\n  assumes \"q1 \\<in> nodes M\" and \"q2 \\<in> nodes M\"\nshows \"deadlock_state (canonical_separator M q1 q2) (Inr q1)\"\nand   \"deadlock_state (canonical_separator M q1 q2) (Inr q2)\"\n  using canonical_separator_t_source_isl[OF _ assms]\n  unfolding deadlock_state.simps by force+\n\n\nlemma state_separator_from_canonical_separator_language_target :\n  assumes \"is_state_separator_from_canonical_separator (canonical_separator M q1 q2) q1 q2 A\"\n  and     \"io \\<in> L A\"\n  and     \"observable M\" \n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\n  and     \"q1 \\<noteq> q2\"\nshows \"io \\<in> LS M q1 - LS M q2 \\<Longrightarrow> io_targets A io (initial A) = {Inr q1}\"\nand   \"io \\<in> LS M q2 - LS M q1 \\<Longrightarrow> io_targets A io (initial A) = {Inr q2}\"\nand   \"io \\<in> LS M q1 \\<inter> LS M q2 \\<Longrightarrow> io_targets A io (initial A) \\<inter> {Inr q1, Inr q2} = {}\"\nproof -\n  have \"observable A\"\n    using state_separator_from_canonical_separator_observable[OF assms(1,3,4,5)] by assumption\n\n  let ?C = \"canonical_separator M q1 q2\"\n\n  obtain p where \"path A (initial A) p\" and \"p_io p = io\"\n    using assms(2) by force\n  then have \"path ?C (initial ?C) p\"\n    using submachine_path_initial[OF is_state_separator_from_canonical_separator_simps(1)[OF assms(1)]] by auto\n  then have \"io \\<in> L ?C\"\n    using \\<open>p_io p = io\\<close> by auto\n\n  show \"io \\<in> LS M q1 - LS M q2 \\<Longrightarrow> io_targets A io (initial A) = {Inr q1}\"\n  proof -\n    assume \"io \\<in> LS M q1 - LS M q2\"\n\n    have \"target (initial A) p = Inr q1\"\n      using submachine_path_initial[OF is_state_separator_from_canonical_separator_simps(1)[OF assms(1)] \\<open>path A (initial A) p\\<close>] \n            canonical_separator_language_target(1)[OF \\<open>io \\<in> L ?C\\<close> assms(3,4,5,6) \\<open>io \\<in> LS M q1 - LS M q2\\<close>] \n            \\<open>p_io p = io\\<close>\n      unfolding io_targets.simps is_state_separator_from_canonical_separator_initial[OF assms(1,4,5)] \n                canonical_separator_simps product_simps from_FSM_simps[OF assms(4)] from_FSM_simps[OF assms(5)]\n      using assms(4) assms(5) canonical_separator_initial by fastforce\n    then have \"Inr q1 \\<in> io_targets A io (initial A)\"\n      using \\<open>path A (initial A) p\\<close> \\<open>p_io p = io\\<close> unfolding io_targets.simps\n      by (metis (mono_tags, lifting) mem_Collect_eq)  \n    then show \"io_targets A io (initial A) = {Inr q1}\"\n      using observable_io_targets[OF \\<open>observable A\\<close> \\<open>io \\<in> L A\\<close>]\n      by (metis singletonD)   \n  qed\n\n  show \"io \\<in> LS M q2 - LS M q1 \\<Longrightarrow> io_targets A io (initial A) = {Inr q2}\"\n  proof -\n    assume \"io \\<in> LS M q2 - LS M q1\"\n\n    have \"target (initial A) p = Inr q2\"\n      using submachine_path_initial[OF is_state_separator_from_canonical_separator_simps(1)[OF assms(1)] \\<open>path A (initial A) p\\<close>] \n            canonical_separator_language_target(2)[OF \\<open>io \\<in> L ?C\\<close> assms(3,4,5,6) \\<open>io \\<in> LS M q2 - LS M q1\\<close>] \n            \\<open>p_io p = io\\<close>\n      unfolding io_targets.simps is_state_separator_from_canonical_separator_initial[OF assms(1,4,5)] \n                canonical_separator_simps product_simps from_FSM_simps[OF assms(4)] from_FSM_simps[OF assms(5)]\n      using assms(4) assms(5) canonical_separator_initial by fastforce\n    then have \"Inr q2 \\<in> io_targets A io (initial A)\"\n      using \\<open>path A (initial A) p\\<close> \\<open>p_io p = io\\<close> unfolding io_targets.simps\n      by (metis (mono_tags, lifting) mem_Collect_eq)  \n    then show \"io_targets A io (initial A) = {Inr q2}\"\n      using observable_io_targets[OF \\<open>observable A\\<close> \\<open>io \\<in> L A\\<close>]\n      by (metis singletonD)   \n  qed\n\n  show \"io \\<in> LS M q1 \\<inter> LS M q2 \\<Longrightarrow> io_targets A io (initial A) \\<inter> {Inr q1, Inr q2} = {}\"\n  proof -\n    let ?P = \"product (from_FSM M q1) (from_FSM M q2)\"\n\n    assume \"io \\<in> LS M q1 \\<inter> LS M q2\"\n\n    have\"\\<And> q . q \\<in> io_targets A io (initial A) \\<Longrightarrow> q \\<notin> {Inr q1, Inr q2}\"\n    proof -\n      fix q assume \"q \\<in> io_targets A io (initial A)\"\n      then obtain p where \"q = target (initial A) p\" and \"path A (initial A) p\" and \"p_io p = io\"\n        by auto\n      then have \"path ?C (initial ?C) p\"\n        using submachine_path_initial[OF is_state_separator_from_canonical_separator_simps(1)[OF assms(1)]] by auto\n      then have \"isl (target (initial ?C) p)\"\n        using canonical_separator_path_targets_language(4)[OF _ \\<open>observable M\\<close> \\<open>q1 \\<in> nodes M\\<close> \\<open>q2 \\<in> nodes M\\<close>  \\<open>q1 \\<noteq> q2\\<close>]\n        using \\<open>p_io p = io\\<close> \\<open>io \\<in> LS M q1 \\<inter> LS M q2\\<close> by auto\n      then show \"q \\<notin> {Inr q1, Inr q2}\"\n        using \\<open>q = target (initial A) p\\<close> \n        unfolding is_state_separator_from_canonical_separator_initial[OF assms(1,4,5)]\n        unfolding canonical_separator_simps product_simps from_FSM_simps by auto\n    qed\n\n    then show \"io_targets A io (initial A) \\<inter> {Inr q1, Inr q2} = {}\"\n      by blast\n  qed\nqed\n\n\nlemma state_separator_language_intersections_nonempty :\n  assumes \"is_state_separator_from_canonical_separator (canonical_separator M q1 q2) q1 q2 A\"\n  and     \"observable M\"\n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\n  and     \"q1 \\<noteq> q2\"\nshows \"\\<exists> io . io \\<in> (L A \\<inter> LS M q1) - LS M q2\" and \"\\<exists> io . io \\<in> (L A \\<inter> LS M q2) - LS M q1\"\nproof -\n  have \"Inr q1 \\<in> reachable_nodes A\"\n    using is_state_separator_from_canonical_separator_simps(6)[OF assms(1)] by assumption\n  then obtain p where \"path A (initial A) p\" and \"target (initial A) p = Inr q1\"\n    unfolding reachable_nodes_def by auto \n  then have \"p_io p \\<in> LS M q1 - LS M q2\"\n    using canonical_separator_maximal_path_distinguishes_left[OF assms(1) _ _ assms(2,3,4,5)] by blast\n  moreover have \"p_io p \\<in> L A\"\n    using \\<open>path A (initial A) p\\<close> by auto\n  ultimately show \"\\<exists> io . io \\<in> (L A \\<inter> LS M q1) - LS M q2\" by blast\n\n  have \"Inr q2 \\<in> reachable_nodes A\"\n    using is_state_separator_from_canonical_separator_simps(7)[OF assms(1)] by assumption\n  then obtain p' where \"path A (initial A) p'\" and \"target (initial A) p' = Inr q2\"\n    unfolding reachable_nodes_def by auto \n  then have \"p_io p' \\<in> LS M q2 - LS M q1\"\n    using canonical_separator_maximal_path_distinguishes_right[OF assms(1) _ _ assms(2,3,4,5)] by blast\n  moreover have \"p_io p' \\<in> L A\"\n    using \\<open>path A (initial A) p'\\<close> by auto\n  ultimately show \"\\<exists> io . io \\<in> (L A \\<inter> LS M q2) - LS M q1\" by blast\nqed\n\n\nlemma state_separator_language_inclusion :\n  assumes \"is_state_separator_from_canonical_separator (canonical_separator M q1 q2) q1 q2 A\"\n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\nshows \"L A \\<subseteq> LS M q1 \\<union> LS M q2\"\n  using canonical_separator_language[OF assms(2,3)]\n  using submachine_language[OF is_state_separator_from_canonical_separator_simps(1)[OF assms(1)]] \n  unfolding from_FSM_language[OF assms(2)] from_FSM_language[OF assms(3)] by blast\n\n\nlemma state_separator_from_canonical_separator_targets_left_inclusion :\n  assumes \"observable T\" \n  and     \"observable M\"\n  and     \"t1 \\<in> nodes T\"\n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\n  and     \"is_state_separator_from_canonical_separator (canonical_separator M q1 q2) q1 q2 A\"\n  and     \"(inputs T) = (inputs M)\"\n  and     \"path A (initial A) p\"\n  and     \"p_io p \\<in> LS M q1\"\n  and     \"q1 \\<noteq> q2\"\nshows \"target (initial A) p \\<noteq> Inr q2\"\nand   \"target (initial A) p = Inr q1 \\<or> isl (target (initial A) p)\"\nproof -\n  let ?C = \"canonical_separator M q1 q2\"\n  have c_path: \"\\<And> p . path A (initial A) p \\<Longrightarrow> path ?C (initial ?C) p\"\n    using is_state_separator_from_canonical_separator_simps(1)[OF assms(6)] submachine_path_initial by metis\n  have \"path ?C (initial ?C) p\"\n    using assms(8) c_path by auto\n\n  show \"target (initial A) p \\<noteq> Inr q2\"\n  proof \n    assume \"target (initial A) p = Inr q2\"\n    then have \"target (initial ?C) p = Inr q2\"\n      using is_state_separator_from_canonical_separator_simps(1)[OF assms(6)] by auto\n\n    have \"(\\<nexists>p1. path M q1 p1 \\<and> p_io p1 = p_io p)\"\n      using canonical_separator_path_initial(3)[OF \\<open>path ?C (initial ?C) p\\<close> assms(4,5,2,10) \\<open>target (initial ?C) p = Inr q2\\<close>] by blast\n    then have \"p_io p \\<notin> LS M q1\"\n      unfolding LS.simps by force\n    then show \"False\"\n      using \\<open>p_io p \\<in> LS M q1\\<close> by blast\n  qed\n  then have \"target (initial ?C) p \\<noteq> Inr q2\"\n    using is_state_separator_from_canonical_separator_simps(1)[OF assms(6)] unfolding is_submachine.simps by simp\n  then have \"target (initial ?C) p = Inr q1 \\<or> isl (target (initial ?C) p)\"\n  proof (cases p rule: rev_cases)\n    case Nil\n    then show ?thesis unfolding canonical_separator_simps[OF assms(4,5)] by simp\n  next\n    case (snoc ys y)\n    then show ?thesis\n      by (metis \\<open>path (canonical_separator M q1 q2) (FSM.initial (canonical_separator M q1 q2)) p\\<close> \\<open>target (FSM.initial (canonical_separator M q1 q2)) p \\<noteq> Inr q2\\<close> assms(10) assms(2) assms(4) assms(5) canonical_separator_path_initial(4) isl_def)        \n  qed\n  then show \"target (initial A) p = Inr q1 \\<or> isl (target (initial A) p)\"\n    using is_state_separator_from_canonical_separator_simps(1)[OF assms(6)] unfolding is_submachine.simps by simp\nqed\n\n\nlemma state_separator_from_canonical_separator_targets_right_inclusion :\n  assumes \"observable T\" \n  and     \"observable M\"\n  and     \"t1 \\<in> nodes T\"\n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\n  and     \"is_state_separator_from_canonical_separator (canonical_separator M q1 q2) q1 q2 A\"\n  and     \"(inputs T) = (inputs M)\"\n  and     \"path A (initial A) p\"\n  and     \"p_io p \\<in> LS M q2\"\n  and     \"q1 \\<noteq> q2\"\nshows \"target (initial A) p \\<noteq> Inr q1\"\nand   \"target (initial A) p = Inr q2 \\<or> isl (target (initial A) p)\"\nproof -\n  let ?C = \"canonical_separator M q1 q2\"\n  have c_path: \"\\<And> p . path A (initial A) p \\<Longrightarrow> path ?C (initial ?C) p\"\n    using is_state_separator_from_canonical_separator_simps(1)[OF assms(6)] submachine_path_initial by metis\n  have \"path ?C (initial ?C) p\"\n    using assms(8) c_path by auto\n\n  show \"target (initial A) p \\<noteq> Inr q1\"\n  proof \n    assume \"target (initial A) p = Inr q1\"\n    then have \"target (initial ?C) p = Inr q1\"\n      using is_state_separator_from_canonical_separator_simps(1)[OF assms(6)] by auto\n\n    have \"(\\<nexists>p1. path M q2 p1 \\<and> p_io p1 = p_io p)\"\n      using canonical_separator_path_initial(2)[OF \\<open>path ?C (initial ?C) p\\<close> assms(4,5,2,10) \\<open>target (initial ?C) p = Inr q1\\<close> ] by blast\n    then have \"p_io p \\<notin> LS M q2\"\n      unfolding LS.simps by force\n    then show \"False\"\n      using \\<open>p_io p \\<in> LS M q2\\<close> by blast\n  qed\n\n  then have \"target (initial ?C) p \\<noteq> Inr q1\"\n    using is_state_separator_from_canonical_separator_simps(1)[OF assms(6)] unfolding is_submachine.simps by simp\n  then have \"target (initial ?C) p = Inr q2 \\<or> isl (target (initial ?C) p)\"\n  proof (cases p rule: rev_cases)\n    case Nil\n    then show ?thesis unfolding canonical_separator_simps[OF assms(4,5)] by simp\n  next\n    case (snoc ys y)\n    then show ?thesis\n      by (metis \\<open>path (canonical_separator M q1 q2) (FSM.initial (canonical_separator M q1 q2)) p\\<close> \\<open>target (FSM.initial (canonical_separator M q1 q2)) p \\<noteq> Inr q1\\<close> assms(10) assms(2) assms(4) assms(5) canonical_separator_path_initial(4) isl_def)\n  qed\n  then show \"target (initial A) p = Inr q2 \\<or> isl (target (initial A) p)\"\n    using is_state_separator_from_canonical_separator_simps(1)[OF assms(6)] unfolding is_submachine.simps by simp\nqed\n\n\n\n\nsubsection \\<open>Calculating State Separators\\<close>\n\nsubsubsection \\<open>Sufficient Condition to Induce a State Separator\\<close>\n\ndefinition state_separator_from_input_choices :: \"('a,'b,'c) fsm \\<Rightarrow> (('a \\<times> 'a) + 'a,'b,'c) fsm \\<Rightarrow> 'a \\<Rightarrow> 'a \\<Rightarrow> ((('a \\<times> 'a) + 'a) \\<times> 'b) list \\<Rightarrow> (('a \\<times> 'a) + 'a, 'b, 'c) fsm\" where\n  \"state_separator_from_input_choices M CSep q1 q2 cs = \n    (let css  = set cs;\n         cssQ = (set (map fst cs)) \\<union> {Inr q1, Inr q2};\n         S0   = filter_nodes CSep (\\<lambda> q . q \\<in> cssQ);\n         S1   = filter_transitions S0 (\\<lambda> t . (t_source t, t_input t) \\<in> css)          \n    in S1)\"\n\n\n\n\nlemma state_separator_from_input_choices_simps :      \n  assumes \"q1 \\<in> nodes M\" \n      and \"q2 \\<in> nodes M\"\n      and \"\\<And> qq x . (qq,x) \\<in> set cs \\<Longrightarrow> qq \\<in> nodes (canonical_separator M q1 q2) \\<and> x \\<in> inputs M\"\n      and \"Inl (q1,q2) \\<in> set (map fst cs)\"\n      and \"\\<And> qq . qq \\<in> set (map fst cs) \\<Longrightarrow> \\<exists> q1' q2' . qq = Inl (q1',q2')\"\nshows\n  \"initial (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs) = Inl (q1,q2)\"\n  \"nodes (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs) = (set (map fst cs)) \\<union> {Inr q1, Inr q2}\"\n  \"inputs (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs) = inputs M\"\n  \"outputs (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs) = outputs M\"\n  \"transitions (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs) = \n    {t \\<in> (transitions (canonical_separator M q1 q2)) . \\<exists> q1' q2' x . (Inl (q1',q2'),x) \\<in> set cs \\<and> t_source t = Inl (q1',q2') \\<and> t_input t = x \\<and> t_target t \\<in> (set (map fst cs)) \\<union> {Inr q1, Inr q2}}\"\nproof -\n  let ?SS = \"(state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs)\"\n  let ?S0 = \"filter_nodes (canonical_separator M q1 q2) (\\<lambda> q . q \\<in> (set (map fst cs)) \\<union> {Inr q1, Inr q2})\"\n\n  have \"(\\<lambda> q . q \\<in> (set (map fst cs)) \\<union> {Inr q1, Inr q2}) (initial (canonical_separator M q1 q2))\"\n    unfolding canonical_separator_simps[OF assms(1,2)]\n    using assms(4) by simp\n\n  have \"nodes ?S0 = (set (map fst cs)) \\<union> {Inr q1, Inr q2}\"\n  proof -\n    have \"\\<And> qq . qq \\<in> nodes ?S0 \\<Longrightarrow> qq \\<in> (set (map fst cs)) \\<union> {Inr q1, Inr q2}\"\n      unfolding filter_nodes_simps[of \"(\\<lambda> q . q \\<in> (set (map fst cs)) \\<union> {Inr q1, Inr q2})\", \n                                   OF \\<open>(\\<lambda> q . q \\<in> (set (map fst cs)) \\<union> {Inr q1, Inr q2}) (initial (canonical_separator M q1 q2))\\<close> ]\n      by fastforce\n    moreover have \"\\<And> qq . qq \\<in> (set (map fst cs)) \\<union> {Inr q1, Inr q2} \\<Longrightarrow> qq \\<in> nodes ?S0\"\n    proof -\n      fix qq assume \"qq \\<in> set (map fst cs) \\<union> {Inr q1, Inr q2}\"\n      then consider (a) \"qq \\<in> set (map fst cs)\" | (b) \"qq \\<in> {Inr q1, Inr q2}\"\n        by blast\n      then show \"qq \\<in> nodes ?S0\" proof cases\n        case a\n        then obtain q1' q2' where \"qq = Inl (q1',q2')\"\n          using assms(5) by (metis old.prod.exhaust) \n        then show ?thesis \n          using a assms(3)[of qq]  \n          unfolding filter_nodes_simps[of \"(\\<lambda> q . q \\<in> (set (map fst cs)) \\<union> {Inr q1, Inr q2})\", OF \\<open>(\\<lambda> q . q \\<in> (set (map fst cs)) \\<union> {Inr q1, Inr q2}) (initial (canonical_separator M q1 q2))\\<close> ]\n                canonical_separator_simps[OF assms(1,2)] by force\n      next\n        case b\n        then show ?thesis using assms(3)  \n          unfolding filter_nodes_simps[of \"(\\<lambda> q . q \\<in> (set (map fst cs)) \\<union> {Inr q1, Inr q2})\", OF \\<open>(\\<lambda> q . q \\<in> (set (map fst cs)) \\<union> {Inr q1, Inr q2}) (initial (canonical_separator M q1 q2))\\<close> ]\n                canonical_separator_simps[OF assms(1,2)] by force\n      qed \n    qed\n      \n    ultimately show ?thesis by blast\n  qed\n    \n\n  show \"initial (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs) = Inl (q1,q2)\"\n       \"nodes (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs) = (set (map fst cs)) \\<union> {Inr q1, Inr q2}\"\n       \"inputs (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs) = inputs M\"\n       \"outputs (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs) = outputs M\"\n    unfolding canonical_separator_simps[OF assms(1,2)] \n              filter_transitions_simps \n              state_separator_from_input_choices_def \n              Let_def \n              filter_nodes_simps(1,3,4,5)[of \"(\\<lambda> q . q \\<in> (set (map fst cs)) \\<union> {Inr q1, Inr q2})\", OF \\<open>(\\<lambda> q . q \\<in> (set (map fst cs)) \\<union> {Inr q1, Inr q2}) (initial (canonical_separator M q1 q2))\\<close> ] \n              \\<open>nodes ?S0 = (set (map fst cs)) \\<union> {Inr q1, Inr q2}\\<close> \n    by simp+\n\n  have alt_def_shared: \"{t \\<in> {t \\<in> FSM.transitions (canonical_separator M q1 q2). t_source t \\<in> set (map fst cs) \\<union> {Inr q1, Inr q2} \\<and> t_target t \\<in> set (map fst cs) \\<union> {Inr q1, Inr q2}}. (t_source t, t_input t) \\<in> set cs}\n                        = {t \\<in> FSM.transitions (canonical_separator M q1 q2). \\<exists> q1' q2' x . (Inl (q1', q2'), x)\\<in>set cs \\<and> t_source t = Inl (q1', q2') \\<and> t_input t = x \\<and> t_target t \\<in> set (map fst cs) \\<union> {Inr q1, Inr q2}}\" \n      (is \"?ts1 = ?ts2\")\n  proof -\n    have \"\\<And> t . t \\<in> ?ts1 \\<Longrightarrow> t \\<in> ?ts2\"\n    proof -\n      fix t assume \"t \\<in> ?ts1\"\n      then have \"t \\<in> FSM.transitions (canonical_separator M q1 q2)\" and \"t_source t \\<in> set (map fst cs) \\<union> {Inr q1, Inr q2}\" and \"t_target t \\<in> set (map fst cs) \\<union> {Inr q1, Inr q2}\" and \"(t_source t, t_input t) \\<in> set cs\"\n        by blast+\n      \n      have \"t_source t \\<in> set (map fst cs)\"\n        using \\<open>t \\<in> FSM.transitions (canonical_separator M q1 q2)\\<close> \\<open>t_source t \\<in> set (map fst cs) \\<union> {Inr q1, Inr q2}\\<close>\n        using canonical_separator_deadlocks[OF assms(1,2)]\n        by fastforce\n      then obtain q1' q2' where \"t_source t = Inl (q1',q2')\"\n        using assms(5) by (metis old.prod.exhaust) \n      then have \"\\<exists>q1' q2' x. (Inl (q1', q2'), x) \\<in> set cs \\<and> t_source t = Inl (q1', q2') \\<and> t_input t = x\"\n        using \\<open>(t_source t, t_input t) \\<in> set cs\\<close> by auto\n        \n      then show \"t \\<in> ?ts2\"\n        using \\<open>t \\<in> FSM.transitions (canonical_separator M q1 q2)\\<close> \\<open>t_target t \\<in> set (map fst cs) \\<union> {Inr q1, Inr q2}\\<close>\n        by simp\n    qed\n    moreover have \"\\<And> t . t \\<in> ?ts2 \\<Longrightarrow> t \\<in> ?ts1\"\n      by force\n    ultimately show ?thesis by blast\n  qed\n\n  show \"transitions (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs) = \n    {t \\<in> (transitions (canonical_separator M q1 q2)) . \\<exists> q1' q2' x . (Inl (q1',q2'),x) \\<in> set cs \\<and> t_source t = Inl (q1',q2') \\<and> t_input t = x \\<and> t_target t \\<in> (set (map fst cs)) \\<union> {Inr q1, Inr q2}}\"\n    unfolding canonical_separator_simps(1,2,3,4)[OF assms(1,2)] \n    unfolding state_separator_from_input_choices_def Let_def\n    unfolding filter_transitions_simps\n    unfolding filter_nodes_simps[of \"(\\<lambda> q . q \\<in> (set (map fst cs)) \\<union> {Inr q1, Inr q2})\", OF \\<open>(\\<lambda> q . q \\<in> (set (map fst cs)) \\<union> {Inr q1, Inr q2}) (initial (canonical_separator M q1 q2))\\<close> ]\n    unfolding alt_def_shared by blast\nqed\n\n\nlemma state_separator_from_input_choices_submachine :\n  assumes \"q1 \\<in> nodes M\" \n      and \"q2 \\<in> nodes M\"\n      and \"\\<And> qq x . (qq,x) \\<in> set cs \\<Longrightarrow> qq \\<in> nodes (canonical_separator M q1 q2) \\<and> x \\<in> inputs M\"\n      and \"Inl (q1,q2) \\<in> set (map fst cs)\"\n      and \"\\<And> qq . qq \\<in> set (map fst cs) \\<Longrightarrow> \\<exists> q1' q2' . qq = Inl (q1',q2')\"\n    shows \"is_submachine (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs) (canonical_separator M q1 q2)\"\nproof -\n  have \"(\\<lambda> q . q \\<in> (set (map fst cs)) \\<union> {Inr q1, Inr q2}) (initial (canonical_separator M q1 q2))\"\n    unfolding canonical_separator_simps[OF assms(1,2)]\n    using assms(4) by simp\n\n  show ?thesis\n    unfolding state_separator_from_input_choices_def Let_def\n    using submachine_transitive[OF filter_nodes_submachine[of \"(\\<lambda> q . q \\<in> (set (map fst cs)) \\<union> {Inr q1, Inr q2})\", OF \\<open>(\\<lambda> q . q \\<in> (set (map fst cs)) \\<union> {Inr q1, Inr q2}) (initial (canonical_separator M q1 q2))\\<close>]\n                                   filter_transitions_submachine[of \"filter_nodes (canonical_separator M q1 q2) (\\<lambda>q. q \\<in> set (map fst cs) \\<union> {Inr q1, Inr q2})\" \"(\\<lambda>t. (t_source t, t_input t) \\<in> set cs)\"]]\n    by assumption\nqed\n\n\nlemma state_separator_from_input_choices_single_input :\n  assumes \"distinct (map fst cs)\"\n      and \"q1 \\<in> nodes M\" \n      and \"q2 \\<in> nodes M\"\n      and \"\\<And> qq x . (qq,x) \\<in> set cs \\<Longrightarrow> qq \\<in> nodes (canonical_separator M q1 q2) \\<and> x \\<in> inputs M\"\n      and \"Inl (q1,q2) \\<in> set (map fst cs)\"\n      and \"\\<And> qq . qq \\<in> set (map fst cs) \\<Longrightarrow> \\<exists> q1' q2' . qq = Inl (q1',q2')\"\n    shows \"single_input (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs)\"\nproof -\n  have \"\\<And> t1 t2 . t1 \\<in> FSM.transitions (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs) \\<Longrightarrow>\n          t2 \\<in> FSM.transitions (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs) \\<Longrightarrow>\n             t_source t1 = t_source t2 \\<Longrightarrow> t_input t1 = t_input t2\"\n  proof -\n    fix t1 t2\n    assume \"t1 \\<in> FSM.transitions (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs)\"\n       and \"t2 \\<in> FSM.transitions (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs)\"\n       and \"t_source t1 = t_source t2\"\n\n    obtain q1' q2' where \"(Inl (q1',q2'),t_input t1) \\<in> set cs\"\n                     and \"t_source t1 = Inl (q1',q2')\"\n      using \\<open>t1 \\<in> FSM.transitions (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs)\\<close>\n      using state_separator_from_input_choices_simps(5)[OF assms(2,3,4,5,6)] by fastforce\n\n    obtain q1'' q2'' where \"(Inl (q1'',q2''),t_input t2) \\<in> set cs\"\n                     and \"t_source t2 = Inl (q1'',q2'')\"\n      using \\<open>t2 \\<in> FSM.transitions (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs)\\<close>\n      using state_separator_from_input_choices_simps(5)[OF assms(2,3,4,5,6)] by fastforce\n\n    have \"(Inl (q1',q2'),t_input t2) \\<in> set cs\"\n      using \\<open>(Inl (q1'',q2''),t_input t2) \\<in> set cs\\<close> \\<open>t_source t1 = Inl (q1',q2')\\<close> \\<open>t_source t2 = Inl (q1'',q2'')\\<close> \\<open>t_source t1 = t_source t2\\<close> \n      by simp\n    then show \"t_input t1 = t_input t2\"\n      using \\<open>(Inl (q1',q2'),t_input t1) \\<in> set cs\\<close> \\<open>distinct (map fst cs)\\<close>\n      by (meson eq_key_imp_eq_value) \n  qed\n  then show ?thesis\n    by fastforce\nqed\n\n\nlemma state_separator_from_input_choices_transition_list : \n  assumes \"q1 \\<in> nodes M\" \n      and \"q2 \\<in> nodes M\"\n      and \"\\<And> qq x . (qq,x) \\<in> set cs \\<Longrightarrow> qq \\<in> nodes (canonical_separator M q1 q2) \\<and> x \\<in> inputs M\"\n      and \"Inl (q1,q2) \\<in> set (map fst cs)\"\n      and \"\\<And> qq . qq \\<in> set (map fst cs) \\<Longrightarrow> \\<exists> q1' q2' . qq = Inl (q1',q2')\"\n      and \"t \\<in> transitions (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs)\"\n    shows \"(t_source t, t_input t) \\<in> set cs\"\nusing state_separator_from_input_choices_simps(5)[OF assms(1,2,3,4,5)] assms(6) by auto\n\n\nlemma state_separator_from_input_choices_transition_target :\n  assumes \"t \\<in> transitions (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs)\"\n      and \"q1 \\<in> nodes M\" \n      and \"q2 \\<in> nodes M\"\n      and \"\\<And> qq x . (qq,x) \\<in> set cs \\<Longrightarrow> qq \\<in> nodes (canonical_separator M q1 q2) \\<and> x \\<in> inputs M\"\n      and \"Inl (q1,q2) \\<in> set (map fst cs)\"\n      and \"\\<And> qq . qq \\<in> set (map fst cs) \\<Longrightarrow> \\<exists> q1' q2' . qq = Inl (q1',q2')\"\n    shows \"t \\<in> transitions (canonical_separator M q1 q2) \\<or> t_target t \\<in> {Inr q1, Inr q2}\"\n  using state_separator_from_input_choices_simps(5)[OF assms(2-6)] assms(1) by fastforce\n\n\nlemma state_separator_from_input_choices_acyclic_paths' :\n  assumes \"distinct (map fst cs)\"\n      and \"q1 \\<in> nodes M\" \n      and \"q2 \\<in> nodes M\"\n      and \"\\<And> qq x . (qq,x) \\<in> set cs \\<Longrightarrow> qq \\<in> nodes (canonical_separator M q1 q2) \\<and> x \\<in> inputs M\"\n      and \"Inl (q1,q2) \\<in> set (map fst cs)\"\n      and \"\\<And> qq . qq \\<in> set (map fst cs) \\<Longrightarrow> \\<exists> q1' q2' . qq = Inl (q1',q2')\"\n      and \"\\<And> i t . i < length cs \n                    \\<Longrightarrow> t \\<in> transitions (canonical_separator M q1 q2) \n                    \\<Longrightarrow> t_source t = (fst (cs ! i))\n                    \\<Longrightarrow> t_input  t = snd (cs ! i)\n                    \\<Longrightarrow> t_target t \\<in> ((set (map fst (take i cs))) \\<union> {Inr q1, Inr q2})\"\n      and \"path (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs) q' p\"\n      and \"target q' p = q'\"\n      and \"p \\<noteq> []\"\nshows \"False\"\nproof -\n\n  let ?S = \"(state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs)\"\n\n  from \\<open>p \\<noteq> []\\<close> obtain p' t' where \"p = t'#p'\"\n    using list.exhaust by blast\n  then have \"path ?S q' (p@[t'])\" \n    using assms(8,9) by fastforce\n\n  define f :: \"(('a \\<times> 'a + 'a) \\<times> 'b \\<times> 'c \\<times> ('a \\<times> 'a + 'a)) \\<Rightarrow> nat\"\n    where f_def: \"f = (\\<lambda> t . the (find_index (\\<lambda> qx . (fst qx) = t_source t \\<and> snd qx = t_input t) cs))\"\n  \n  have f_prop: \"\\<And> t . t \\<in> set (p@[t']) \\<Longrightarrow> (f t < length cs) \n                                      \\<and> (\\<lambda>(q, x). (q, x)) (cs ! (f t)) = (t_source t,t_input t)\n                                      \\<and> (\\<forall> j < f t . (fst (cs ! j)) \\<noteq> t_source t)\"\n  proof -\n    fix t assume \"t \\<in> set (p@[t'])\"\n    then have \"t \\<in> set p\" using \\<open>p = t'#p'\\<close> by auto\n    then have \"t \\<in> transitions ?S\" \n      using assms(8)\n      by (meson path_transitions subsetD) \n    then have \"(t_source t, t_input t) \\<in> set cs\"\n      using state_separator_from_input_choices_transition_list[OF assms(2,3,4,5,6)]\n      by blast \n    then have \"\\<exists> qx \\<in> set cs . (\\<lambda> qx . (fst qx) = t_source t \\<and> snd qx = t_input t) qx\"\n      by force\n    then have \"find_index (\\<lambda> qx . (fst qx) = t_source t \\<and> snd qx = t_input t) cs \\<noteq> None\"\n      by (simp add: find_index_exhaustive) \n    then obtain i where *: \"find_index (\\<lambda> qx . (fst qx) = t_source t \\<and> snd qx = t_input t) cs = Some i\"\n      by auto\n\n    have **: \"\\<And> j . j < i \\<Longrightarrow> (fst (cs ! j)) = t_source t \\<Longrightarrow> cs ! i = cs ! j\"\n      using assms(1)\n      using nth_eq_iff_index_eq  find_index_index[OF *]\n      by (metis (mono_tags, lifting) Suc_lessD length_map less_trans_Suc nth_map)\n\n    have \"f t < length cs\"\n      unfolding f_def using find_index_index(1)[OF *] unfolding * by simp\n    moreover have \"(\\<lambda>(q, x). (q, x)) (cs ! (f t)) = (t_source t, t_input t)\"\n      unfolding f_def using find_index_index(2)[OF *]\n      by (metis \"*\" case_prod_Pair_iden option.sel prod.collapse)\n    moreover have \"\\<forall> j < f t . (fst (cs ! j)) \\<noteq> t_source t\"\n      unfolding f_def using find_index_index(3)[OF *] unfolding *  \n      using assms(1) **\n      by (metis (no_types, lifting) \"*\" \\<open>\\<exists>qx\\<in>set cs. fst qx = t_source t \\<and> snd qx = t_input t\\<close> eq_key_imp_eq_value find_index_index(1) nth_mem option.sel prod.collapse)\n    \n    ultimately show \"(f t < length cs)\n                      \\<and> (\\<lambda>(q, x). (q, x)) (cs ! (f t)) = (t_source t,t_input t)\n                      \\<and> (\\<forall> j < f t . (fst (cs ! j)) \\<noteq> t_source t)\" by simp\n  qed\n\n  have *: \"\\<And> i . Suc i < length (p@[t']) \\<Longrightarrow> f ((p@[t']) ! i) > f ((p@[t']) ! (Suc i))\"\n  proof -\n    fix i assume \"Suc i < length (p@[t'])\"\n    then have \"(p@[t']) ! i \\<in> set (p@[t'])\" and \"(p@[t']) ! (Suc i) \\<in> set (p@[t'])\"\n      using Suc_lessD nth_mem by blast+\n    then have \"(p@[t']) ! i \\<in> transitions ?S\" and \"(p@[t']) ! Suc i \\<in> transitions ?S\" \n      using \\<open>path ?S q' (p@[t'])\\<close>\n      by (meson path_transitions subsetD)+\n    then have \"(p @ [t']) ! i \\<in> FSM.transitions (canonical_separator M q1 q2) \\<or> t_target ((p @ [t']) ! i) \\<in> {Inr q1, Inr q2}\" \n      using state_separator_from_input_choices_transition_target[OF _ assms(2-6)] by blast\n    \n    have \"f ((p@[t']) ! i) < length cs\"\n    and  \"(\\<lambda>(q, x). (q, x)) (cs ! (f ((p@[t']) ! i))) = (t_source ((p@[t']) ! i), t_input ((p@[t']) ! i))\"\n    and  \"(\\<forall>j<f ((p@[t']) ! i). (fst (cs ! j)) \\<noteq> t_source ((p@[t']) ! i))\"\n      using f_prop[OF \\<open>(p@[t']) ! i \\<in> set (p@[t'])\\<close>] by auto\n\n    have \"f ((p@[t']) ! Suc i) < length cs\"\n    and  \"(\\<lambda>(q, x). (q, x)) (cs ! (f ((p@[t']) ! Suc i))) = (t_source ((p@[t']) ! Suc i), t_input ((p@[t']) ! Suc i))\"\n    and  \"(\\<forall>j<f ((p@[t']) ! Suc i). (fst (cs ! j)) \\<noteq> t_source ((p@[t']) ! Suc i))\"\n      using f_prop[OF \\<open>(p@[t']) ! Suc i \\<in> set (p@[t'])\\<close>] by auto\n\n    have \"t_source ((p @ [t']) ! i) = (fst (cs ! f ((p @ [t']) ! i)))\" and \"t_input ((p @ [t']) ! i) = snd (cs ! f ((p @ [t']) ! i))\"\n       using f_prop[OF \\<open>(p@[t']) ! i \\<in> set (p@[t'])\\<close>]\n       by (simp add: prod.case_eq_if)+ \n\n    have \"t_target ((p@[t']) ! i) = t_source ((p@[t']) ! Suc i)\"\n      using \\<open>Suc i < length (p@[t'])\\<close> \\<open>path ?S q' (p@[t'])\\<close>\n      by (simp add: path_source_target_index) \n    then have \"t_target ((p@[t']) ! i) \\<notin> {Inr q1, Inr q2}\"\n      using state_separator_from_input_choices_transition_list[OF assms(2,3,4,5,6) \\<open>(p@[t']) ! Suc i \\<in> transitions ?S\\<close>] assms(6) by force\n    then have \"t_target ((p @ [t']) ! i) \\<in> set (map fst (take (f ((p @ [t']) ! i)) cs))\"\n      using assms(7)[OF \\<open>f ((p@[t']) ! i) < length cs\\<close> _ \\<open>t_source ((p @ [t']) ! i) = (fst (cs ! f ((p @ [t']) ! i)))\\<close> \\<open>t_input ((p @ [t']) ! i) = snd (cs ! f ((p @ [t']) ! i))\\<close>] \n      using \\<open>(p @ [t']) ! i \\<in> FSM.transitions (canonical_separator M q1 q2) \\<or> t_target ((p @ [t']) ! i) \\<in> {Inr q1, Inr q2}\\<close> by blast\n    then have \"(\\<exists>qx'\\<in>set (take (f ((p@[t']) ! i)) cs). (fst qx') = t_target ((p@[t']) ! i))\" \n      by force \n    then obtain j where \"(fst (cs ! j)) = t_source ((p@[t']) ! Suc i)\" and \"j < f ((p@[t']) ! i)\" \n      unfolding \\<open>t_target ((p@[t']) ! i) = t_source ((p@[t']) ! Suc i)\\<close>\n      by (metis (no_types, lifting) \\<open>f ((p@[t']) ! i) < length cs\\<close> in_set_conv_nth leD length_take min_def_raw nth_take)     \n    then show \"f ((p@[t']) ! i) > f ((p@[t']) ! (Suc i))\"\n      using \\<open>(\\<forall>j<f ((p@[t']) ! Suc i). (fst (cs ! j)) \\<noteq> t_source ((p@[t']) ! Suc i))\\<close>\n      using leI le_less_trans by blast \n  qed\n\n  have \"\\<And> i j . j < i \\<Longrightarrow> i < length (p@[t']) \\<Longrightarrow> f ((p@[t']) ! j) > f ((p@[t']) ! i)\"\n    using list_index_fun_gt[of \"p@[t']\" f] * by blast\n  then have \"f t' < f t'\"\n    unfolding \\<open>p = t'#p'\\<close> by fastforce \n  then show \"False\"\n    by auto\nqed\n\n\nlemma state_separator_from_input_choices_acyclic_paths :\n  assumes \"distinct (map fst cs)\"\n      and \"q1 \\<in> nodes M\" \n      and \"q2 \\<in> nodes M\"\n      and \"\\<And> qq x . (qq,x) \\<in> set cs \\<Longrightarrow> qq \\<in> nodes (canonical_separator M q1 q2) \\<and> x \\<in> inputs M\"\n      and \"Inl (q1,q2) \\<in> set (map fst cs)\"\n      and \"\\<And> qq . qq \\<in> set (map fst cs) \\<Longrightarrow> \\<exists> q1' q2' . qq = Inl (q1',q2')\"\n      and \"\\<And> i t . i < length cs \n                    \\<Longrightarrow> t \\<in> transitions (canonical_separator M q1 q2) \n                    \\<Longrightarrow> t_source t = (fst (cs ! i))\n                    \\<Longrightarrow> t_input  t = snd (cs ! i)\n                    \\<Longrightarrow> t_target t \\<in> ((set (map fst (take i cs))) \\<union> {Inr q1, Inr q2})\"\n      and \"path (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs) q' p\"\nshows \"distinct (visited_nodes q' p)\"\nproof (rule ccontr)\n  assume \"\\<not> distinct (visited_nodes q' p)\"\n  \n  obtain i j where p1:\"take j (drop i p) \\<noteq> []\"\n               and p2:\"target (target q' (take i p)) (take j (drop i p)) = (target q' (take i p))\"\n               and p3:\"path (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs) (target q' (take i p)) (take j (drop i p))\"\n    using cycle_from_cyclic_path[OF assms(8) \\<open>\\<not> distinct (visited_nodes q' p)\\<close>] by blast\n  \n  show \"False\"\n    using state_separator_from_input_choices_acyclic_paths'[OF assms(1-7) p3 p2 p1] by blast\nqed\n\n\nlemma state_separator_from_input_choices_acyclic :\n  assumes \"distinct (map fst cs)\"\n      and \"q1 \\<in> nodes M\" \n      and \"q2 \\<in> nodes M\"\n      and \"\\<And> qq x . (qq,x) \\<in> set cs \\<Longrightarrow> qq \\<in> nodes (canonical_separator M q1 q2) \\<and> x \\<in> inputs M\"\n      and \"Inl (q1,q2) \\<in> set (map fst cs)\"\n      and \"\\<And> qq . qq \\<in> set (map fst cs) \\<Longrightarrow> \\<exists> q1' q2' . qq = Inl (q1',q2')\"\n      and \"\\<And> i t . i < length cs \n                    \\<Longrightarrow> t \\<in> transitions (canonical_separator M q1 q2)\n                    \\<Longrightarrow> t_source t = (fst (cs ! i))\n                    \\<Longrightarrow> t_input  t = snd (cs ! i)\n                    \\<Longrightarrow> t_target t \\<in> ((set (map fst (take i cs))) \\<union> {Inr q1, Inr q2})\"\n    shows \"acyclic (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs)\"\n  unfolding acyclic.simps using state_separator_from_input_choices_acyclic_paths[OF assms] by blast\n\n\nlemma state_separator_from_input_choices_target :\n  assumes \"\\<And> i t . i < length cs\n                    \\<Longrightarrow> t \\<in> transitions (canonical_separator M q1 q2) \n                    \\<Longrightarrow> t_source t = (fst (cs ! i))\n                    \\<Longrightarrow> t_input  t = snd (cs ! i)\n                    \\<Longrightarrow> t_target t \\<in> ((set (map fst (take i cs))) \\<union> {Inr q1, Inr q2})\"\n      and \"t \\<in> FSM.transitions (canonical_separator M q1 q2)\"\n      and \"\\<exists> q1' q2' x . (Inl (q1', q2'), x)\\<in>set cs \\<and> t_source t = Inl (q1', q2') \\<and> t_input t = x\" \n    shows \"t_target t \\<in> set (map fst cs) \\<union> {Inr q1, Inr q2}\" \nproof -\n  from assms(3) obtain q1' q2' x where \"(Inl (q1', q2'), x)\\<in>set cs\" and \"t_source t = Inl (q1', q2')\" and \"t_input t = x\"\n    by auto\n  then obtain i where \"i < length cs\" and \"t_source t = (fst (cs ! i))\" and \"t_input  t = snd (cs ! i)\"\n    by (metis fst_conv in_set_conv_nth snd_conv)\n  then have \"t_target t \\<in> set (map fst (take i cs)) \\<union> {Inr q1, Inr q2}\" using assms(1)[OF _ assms(2)] by blast\n  then consider \"t_target t \\<in> set (map fst (take i cs))\" | \"t_target t \\<in> {Inr q1, Inr q2}\" by blast\n  then show ?thesis proof cases\n    case 1 \n    then have \"t_target t \\<in> set (map fst cs)\" \n      by (metis in_set_takeD take_map)\n    then show ?thesis by blast\n  next\n    case 2\n    then show ?thesis by auto\n  qed \nqed\n\n\nlemma state_separator_from_input_choices_transitions_alt_def :\n  assumes \"q1 \\<in> nodes M\" \n      and \"q2 \\<in> nodes M\"\n      and \"\\<And> qq x . (qq,x) \\<in> set cs \\<Longrightarrow> qq \\<in> nodes (canonical_separator M q1 q2) \\<and> x \\<in> inputs M\"\n      and \"Inl (q1,q2) \\<in> set (map fst cs)\"\n      and \"\\<And> qq . qq \\<in> set (map fst cs) \\<Longrightarrow> \\<exists> q1' q2' . qq = Inl (q1',q2')\"\n      and \"\\<And> i t . i < length cs\n                    \\<Longrightarrow> t \\<in> transitions (canonical_separator M q1 q2) \n                    \\<Longrightarrow> t_source t = (fst (cs ! i))\n                    \\<Longrightarrow> t_input  t = snd (cs ! i)\n                    \\<Longrightarrow> t_target t \\<in> ((set (map fst (take i cs))) \\<union> {Inr q1, Inr q2})\"\n  shows \"transitions (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs) = \n    {t \\<in> (transitions (canonical_separator M q1 q2)) . \\<exists> q1' q2' x . (Inl (q1',q2'),x) \\<in> set cs \\<and> t_source t = Inl (q1',q2') \\<and> t_input t = x}\"\nproof -\n  have \"FSM.transitions (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs) =\n    {t \\<in> FSM.transitions (canonical_separator M q1 q2).\n     \\<exists> q1' q2' x . (Inl (q1', q2'), x)\\<in>set cs \\<and>\n        t_source t = Inl (q1', q2') \\<and>\n        t_input t = x \\<and> t_target t \\<in> set (map fst cs) \\<union> {Inr q1, Inr q2}}\"\n    using state_separator_from_input_choices_simps(5)[OF assms(1,2,3,4,5)] by blast\n\n  moreover have \"\\<And> t . t \\<in> FSM.transitions (canonical_separator M q1 q2) \\<Longrightarrow>  \\<exists> q1' q2' x . (Inl (q1', q2'), x)\\<in>set cs \\<and> t_source t = Inl (q1', q2') \\<and> t_input t = x \\<Longrightarrow> t_target t \\<in> set (map fst cs) \\<union> {Inr q1, Inr q2}\"\n    using state_separator_from_input_choices_target[OF assms(6)] by blast\n\n  ultimately show ?thesis \n    by fast\nqed\n\n\nlemma state_separator_from_input_choices_deadlock :\n  assumes \"distinct (map fst cs)\"\n      and \"q1 \\<in> nodes M\" \n      and \"q2 \\<in> nodes M\"\n      and \"\\<And> qq x . (qq,x) \\<in> set cs \\<Longrightarrow> qq \\<in> nodes (canonical_separator M q1 q2) \\<and> x \\<in> inputs M\"\n      and \"Inl (q1,q2) \\<in> set (map fst cs)\"\n      and \"\\<And> qq . qq \\<in> set (map fst cs) \\<Longrightarrow> \\<exists> q1' q2' . qq = Inl (q1',q2')\"\n      and \"\\<And> i t . i < length cs\n                    \\<Longrightarrow> t \\<in> transitions (canonical_separator M q1 q2) \n                    \\<Longrightarrow> t_source t = (fst (cs ! i))\n                    \\<Longrightarrow> t_input  t = snd (cs ! i)\n                    \\<Longrightarrow> t_target t \\<in> ((set (map fst (take i cs))) \\<union> {Inr q1, Inr q2})\"\n      \n    shows \"\\<And> qq . qq \\<in> nodes (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs) \\<Longrightarrow> deadlock_state (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs) qq \\<Longrightarrow> qq \\<in> {Inr q1, Inr q2} \\<or> (\\<exists> q1' q2' x . qq = Inl (q1',q2') \\<and> x \\<in> inputs M \\<and> (h_out M (q1',x) = {} \\<and> h_out M (q2',x) = {}))\"\nproof -\n  let ?C = \"(canonical_separator M q1 q2)\"\n  let ?S = \"(state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs)\"\n \n  fix qq assume \"qq \\<in> nodes ?S\" and \"deadlock_state ?S qq\"\n\n  then consider (a) \"qq \\<in> (set (map fst cs))\" | (b) \"qq \\<in> {Inr q1, Inr q2}\"\n    using state_separator_from_input_choices_simps(2)[OF assms(2,3,4,5,6)] by blast\n  then show \"qq \\<in> {Inr q1, Inr q2} \\<or> (\\<exists> q1' q2' x . qq = Inl (q1',q2') \\<and> x \\<in> inputs M \\<and> (h_out M (q1',x) = {} \\<and> h_out M (q2',x) = {}))\"\n  proof cases\n    case a\n    then obtain q1' q2' x where \"(Inl (q1',q2'),x) \\<in> set cs\" and  \"qq = Inl (q1',q2')\" using assms(6) by fastforce\n    then have \"Inl (q1',q2') \\<in> nodes (canonical_separator M q1 q2)\" and \"x \\<in> inputs M\" using assms(4) by blast+\n    then have \"(q1', q2') \\<in> nodes (product (from_FSM M q1) (from_FSM M q2))\"\n      using canonical_separator_simps(2)[OF assms(2,3)] by fastforce\n\n    have \"h_out M (q1',x) = {} \\<and> h_out M (q2',x) = {}\"\n    proof (rule ccontr)\n      assume \"\\<not> (h_out M (q1', x) = {} \\<and> h_out M (q2', x) = {})\"\n      then consider (a1) \"\\<exists> y \\<in> (h_out M (q1', x) \\<inter> h_out M (q2', x)) . True\" | \n                    (a2) \"\\<exists> y \\<in> (h_out M (q1', x) - h_out M (q2', x)) . True\" |\n                    (a3) \"\\<exists> y \\<in> (h_out M (q2', x) - h_out M (q1', x)) . True\"\n        by blast\n      then show \"False\" proof cases\n        case a1\n        then obtain y q1'' q2''  where \"(y,q1'') \\<in> h M (q1',x)\" and \"(y,q2'') \\<in> h M (q2',x)\" by auto\n        then have \"((q1',q2'),x,y,(q1'',q2'')) \\<in> transitions (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2))\"\n          unfolding product_transitions_def h.simps using assms(2,3) by auto\n        then have \"(Inl (q1',q2'),x,y,Inl (q1'',q2'')) \\<in> transitions ?C\"  \n          using \\<open>(q1', q2') \\<in> nodes (product (from_FSM M q1) (from_FSM M q2))\\<close>\n                canonical_separator_transitions_def[OF assms(2,3)]  by fast\n        \n        then have \"(Inl (q1',q2'),x,y,Inl (q1'',q2'')) \\<in> {t \\<in> FSM.transitions (canonical_separator M q1 q2).\n                                                             \\<exists>q1' q2' x . (Inl (q1', q2'), x)\\<in>set cs \\<and>\n                                                                t_source t = Inl (q1', q2') \\<and>\n                                                                t_input t = x \\<and> t_target t \\<in> set (map fst cs) \\<union> {Inr q1, Inr q2}}\"\n          using state_separator_from_input_choices_target[OF assms(7) \\<open>(Inl (q1',q2'),x,y,Inl (q1'',q2'')) \\<in> transitions ?C\\<close>]\n          using \\<open>(Inl (q1', q2'), x) \\<in> set cs\\<close> by force \n\n        then have \"(Inl (q1',q2'), x, y, Inl (q1'',q2'')) \\<in> transitions ?S\" \n          using state_separator_from_input_choices_simps(5)[OF assms(2,3,4,5,6)] by fastforce\n        then show \"False\" \n          using \\<open>deadlock_state ?S qq\\<close> unfolding \\<open>qq = Inl (q1',q2')\\<close> by auto\n      next\n        case a2\n        then obtain y where \"y \\<in> (h_out M (q1', x) - h_out M (q2', x))\" unfolding h_out.simps by blast\n        then have \"(\\<exists>q'. (q1', x, y, q') \\<in> FSM.transitions M) \\<and> (\\<nexists>q'. (q2', x, y, q') \\<in> FSM.transitions M)\" unfolding h_out.simps by blast\n        then have \"(Inl (q1',q2'), x, y, Inr q1) \\<in> distinguishing_transitions_left M q1 q2\"\n          unfolding distinguishing_transitions_left_def h.simps\n          using \\<open>(q1', q2') \\<in> nodes (product (from_FSM M q1) (from_FSM M q2))\\<close> by blast\n        then have \"(Inl (q1',q2'), x, y, Inr q1) \\<in> transitions ?C\"\n          unfolding canonical_separator_transitions_def[OF assms(2,3)] by blast\n        moreover have \"\\<exists>q1'' q2'' x' . (Inl (q1'', q2''), x')\\<in>set cs \\<and> t_source (Inl (q1',q2'), x, y, Inr q1) = Inl (q1'', q2'') \\<and> t_input (Inl (q1',q2'), x, y, Inr q1) = x'\"\n          using \\<open>(Inl (q1', q2'), x) \\<in> set cs\\<close> by auto\n        ultimately have \"(Inl (q1',q2'), x, y, Inr q1) \\<in> transitions ?S\" \n          using state_separator_from_input_choices_transitions_alt_def[OF assms(2,3,4,5,6,7)] by blast\n        then show \"False\" \n          using \\<open>deadlock_state ?S qq\\<close> unfolding \\<open>qq = Inl (q1',q2')\\<close> by auto\n      next\n        case a3\n        then obtain y where \"y \\<in> (h_out M (q2', x) - h_out M (q1', x))\" unfolding h_out.simps by blast\n        then have \"\\<not>(\\<exists>q'. (q1', x, y, q') \\<in> FSM.transitions M) \\<and> (\\<exists>q'. (q2', x, y, q') \\<in> FSM.transitions M)\" unfolding h_out.simps by blast\n        then have \"(Inl (q1',q2'), x, y, Inr q2) \\<in> distinguishing_transitions_right M q1 q2\"\n          unfolding distinguishing_transitions_right_def h.simps\n          using \\<open>(q1', q2') \\<in> nodes (product (from_FSM M q1) (from_FSM M q2))\\<close> by blast\n        then have \"(Inl (q1',q2'), x, y, Inr q2) \\<in> transitions ?C\"\n          unfolding canonical_separator_transitions_def[OF assms(2,3)] by blast\n        moreover have \"\\<exists>q1'' q2'' x' . (Inl (q1'', q2''), x')\\<in>set cs \\<and> t_source (Inl (q1',q2'), x, y, Inr q2) = Inl (q1'', q2'') \\<and> t_input (Inl (q1',q2'), x, y, Inr q2) = x'\"\n          using \\<open>(Inl (q1', q2'), x) \\<in> set cs\\<close> by auto\n        ultimately have \"(Inl (q1',q2'), x, y, Inr q2) \\<in> transitions ?S\" \n          using state_separator_from_input_choices_transitions_alt_def[OF assms(2,3,4,5,6,7)] by blast\n        then show \"False\" \n          using \\<open>deadlock_state ?S qq\\<close> unfolding \\<open>qq = Inl (q1',q2')\\<close> by auto\n      qed \n    qed\n    then show ?thesis \n      using \\<open>qq = Inl (q1', q2')\\<close> \\<open>x \\<in> FSM.inputs M\\<close> by blast\n  next\n    case b\n    then show ?thesis by simp\n  qed\nqed\n\n\nlemma state_separator_from_input_choices_retains_io :\n  assumes \"distinct (map fst cs)\"\n      and \"q1 \\<in> nodes M\" \n      and \"q2 \\<in> nodes M\"\n      and \"\\<And> qq x . (qq,x) \\<in> set cs \\<Longrightarrow> qq \\<in> nodes (canonical_separator M q1 q2) \\<and> x \\<in> inputs M\"\n      and \"Inl (q1,q2) \\<in> set (map fst cs)\"\n      and \"\\<And> qq . qq \\<in> set (map fst cs) \\<Longrightarrow> \\<exists> q1' q2' . qq = Inl (q1',q2')\"\n      and \"\\<And> i t . i < length cs\n                    \\<Longrightarrow> t \\<in> transitions (canonical_separator M q1 q2) \n                    \\<Longrightarrow> t_source t = (fst (cs ! i))\n                    \\<Longrightarrow> t_input  t = snd (cs ! i)\n                    \\<Longrightarrow> t_target t \\<in> ((set (map fst (take i cs))) \\<union> {Inr q1, Inr q2})\"\n    shows \"retains_outputs_for_states_and_inputs (canonical_separator M q1 q2) (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs)\"\n  unfolding retains_outputs_for_states_and_inputs_def\n  using state_separator_from_input_choices_transitions_alt_def[OF assms(2,3,4,5,6,7)] by fastforce\n\n\nlemma state_separator_from_input_choices_is_state_separator :\n  assumes \"distinct (map fst cs)\"\n      and \"q1 \\<in> nodes M\" \n      and \"q2 \\<in> nodes M\"\n      and \"\\<And> qq x . (qq,x) \\<in> set cs \\<Longrightarrow> qq \\<in> nodes (canonical_separator M q1 q2) \\<and> x \\<in> inputs M\"\n      and \"Inl (q1,q2) \\<in> set (map fst cs)\"\n      and \"\\<And> qq . qq \\<in> set (map fst cs) \\<Longrightarrow> \\<exists> q1' q2' . qq = Inl (q1',q2')\"\n      and \"\\<And> i t . i < length cs\n                    \\<Longrightarrow> t \\<in> transitions (canonical_separator M q1 q2) \n                    \\<Longrightarrow> t_source t = (fst (cs ! i))\n                    \\<Longrightarrow> t_input  t = snd (cs ! i)\n                    \\<Longrightarrow> t_target t \\<in> ((set (map fst (take i cs))) \\<union> {Inr q1, Inr q2})\"\n      and \"completely_specified M\"\n  shows \"is_state_separator_from_canonical_separator\n            (canonical_separator M q1 q2)\n            q1\n            q2\n            (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs)\"\nproof -\n  let ?C = \"(canonical_separator M q1 q2)\"\n  let ?S = \"(state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs)\"\n\n  have submachine_prop:   \"is_submachine ?S ?C\"\n    using state_separator_from_input_choices_submachine[OF assms(2,3,4,5,6)] by blast\n\n  have single_input_prop: \"single_input ?S\"\n    using state_separator_from_input_choices_single_input[OF assms(1,2,3,4,5,6)] by blast\n\n  have acyclic_prop :     \"acyclic ?S\"\n    using state_separator_from_input_choices_acyclic[OF assms(1,2,3,4,5,6,7)] by blast\n\n  have i3:                \"\\<And> qq . qq \\<in> nodes ?S \n                                  \\<Longrightarrow> deadlock_state ?S qq \n                                  \\<Longrightarrow> qq \\<in> {Inr q1, Inr q2} \n                                        \\<or> (\\<exists> q1' q2' x . qq = Inl (q1',q2') \n                                            \\<and> x \\<in> inputs M \n                                            \\<and> h_out M (q1',x) = {} \n                                            \\<and> h_out M (q2',x) = {})\"\n    using state_separator_from_input_choices_deadlock[OF assms(1,2,3,4,5,6,7)] by blast\n\n  have i4:                \"retains_outputs_for_states_and_inputs (canonical_separator M q1 q2) (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs)\"\n    using state_separator_from_input_choices_retains_io[OF assms(1,2,3,4,5,6,7)] by blast\n\n\n\n  have deadlock_prop_1: \"deadlock_state ?S (Inr q1)\"\n    using submachine_deadlock[OF \\<open>is_submachine ?S ?C\\<close> canonical_separator_deadlock(1)[OF assms(2,3)]] by assumption\n\n  have deadlock_prop_2: \"deadlock_state ?S (Inr q2)\"\n    using submachine_deadlock[OF \\<open>is_submachine ?S ?C\\<close> canonical_separator_deadlock(2)[OF assms(2,3)]] by assumption\n\n  have non_deadlock_prop': \"\\<And> qq . qq \\<in> nodes ?S \\<Longrightarrow> qq \\<noteq> Inr q1 \\<Longrightarrow> qq \\<noteq> Inr q2 \\<Longrightarrow> (isl qq \\<and> \\<not> deadlock_state ?S qq)\"\n  proof -\n    fix qq assume \"qq \\<in> nodes ?S\" and \"qq \\<noteq> Inr q1\" and \"qq \\<noteq> Inr q2\"\n    then have \"qq \\<in> set (map fst cs)\"\n      using state_separator_from_input_choices_simps(2)[OF assms(2,3,4,5,6)] by blast\n    then obtain q1' q2' x where \"qq = Inl (q1',q2')\" and \"(Inl (q1',q2'),x) \\<in> set cs\"\n      using assms(6) by fastforce\n    then have \"(Inl (q1',q2')) \\<in> nodes (canonical_separator M q1 q2)\" and \"x \\<in> inputs M\"\n      using assms(4) by blast+\n    then have \"(q1',q2') \\<in> nodes (product (from_FSM M q1) (from_FSM M q2))\"\n      using canonical_separator_simps(2)[OF assms(2,3)] by fastforce\n    then have \"(q1',q2') \\<in> nodes (product (from_FSM M q1) (from_FSM M q2))\"\n      using reachable_node_is_node by fastforce\n    then have \"q1' \\<in> nodes M\" and \"q2' \\<in> nodes M\"\n      using assms(2,3) by auto\n\n    obtain y q1'' where \"(y,q1'') \\<in> h M (q1',x)\"\n      using \\<open>completely_specified M\\<close> \\<open>q1' \\<in> nodes M\\<close> \\<open>x \\<in> inputs M\\<close>\n      unfolding completely_specified.simps h.simps by fastforce \n\n    consider (a) \"y \\<in> h_out M (q2',x)\" | (b) \"y \\<notin> h_out M (q2',x)\" by blast\n    then have \"\\<not> deadlock_state ?S (Inl (q1',q2'))\"\n    proof cases\n      case a \n      then obtain q2'' where \"(y,q2'') \\<in> h M (q2',x)\" by auto\n      then have \"((q1',q2'),x,y,(q1'',q2'')) \\<in> transitions (product (from_FSM M q1) (from_FSM M q2))\"\n        using assms(2,3) \\<open>(y,q1'') \\<in> h M (q1',x)\\<close>\n        unfolding h.simps product_transitions_def by fastforce\n      then have \"(Inl (q1',q2'),x,y,Inl (q1'',q2'')) \\<in> transitions ?C\"\n        using canonical_separator_transitions_def[OF assms(2,3)]\n        using \\<open>(q1',q2') \\<in> nodes (product (from_FSM M q1) (from_FSM M q2))\\<close> by fast\n      then have \"(Inl (q1',q2'),x,y,Inl (q1'',q2'')) \\<in> transitions ?S\"\n        using state_separator_from_input_choices_transitions_alt_def[OF assms(2,3,4,5,6,7)] \n              \\<open>(Inl (q1',q2'),x) \\<in> set cs\\<close> by fastforce\n      then show ?thesis \n        unfolding deadlock_state.simps by fastforce\n    next\n      case b\n      then have \"(Inl (q1',q2'),x,y,Inr q1) \\<in> distinguishing_transitions_left M q1 q2\"\n        using \\<open>(y,q1'') \\<in> h M (q1',x)\\<close> \\<open>(q1',q2') \\<in> nodes (product (from_FSM M q1) (from_FSM M q2))\\<close> \n        unfolding h.simps h_out.simps distinguishing_transitions_left_def \n        by blast        \n      then have \"(Inl (q1',q2'),x,y,Inr q1) \\<in> transitions ?C\"\n        unfolding canonical_separator_transitions_def[OF assms(2,3)] by blast\n      then have \"(Inl (q1',q2'),x,y,Inr q1) \\<in> transitions ?S\"\n        using state_separator_from_input_choices_transitions_alt_def[OF assms(2,3,4,5,6,7)] \n              \\<open>(Inl (q1',q2'),x) \\<in> set cs\\<close> by fastforce\n      then show ?thesis \n        unfolding deadlock_state.simps by fastforce\n    qed\n    then show \"(isl qq \\<and> \\<not> deadlock_state ?S qq)\"\n      unfolding \\<open>qq = Inl (q1',q2')\\<close> by simp\n  qed\n  then have non_deadlock_prop: \"(\\<forall> q \\<in> reachable_nodes ?S . (q \\<noteq> Inr q1 \\<and> q \\<noteq> Inr q2) \\<longrightarrow> (isl q \\<and> \\<not> deadlock_state ?S q))\"\n    using reachable_node_is_node by force\n    \n\n  (* Idea for reachable-deadlock proofs:\n      - get longest path from initial to some non-deadlock state\n      - that state can only target deadlock states\n      - by assm, both Inr q1 and Inr q2 must be reached from that state\n  *)\n  define ndlps where ndlps_def: \"ndlps = {p . path ?S (initial ?S) p \\<and> isl (target (initial ?S) p)}\"\n  \n\n  obtain qdl where \"qdl \\<in> reachable_nodes ?S\" and \"deadlock_state ?S qdl\"\n    using acyclic_deadlock_reachable[OF \\<open>acyclic ?S\\<close>] by blast\n  \n  have \"qdl = Inr q1 \\<or> qdl = Inr q2\"\n    using non_deadlock_prop'[OF reachable_node_is_node[OF \\<open>qdl \\<in> reachable_nodes ?S\\<close>]] \\<open>deadlock_state ?S qdl\\<close> by fastforce\n  then have \"Inr q1 \\<in> reachable_nodes ?S \\<or> Inr q2 \\<in> reachable_nodes ?S\"\n    using \\<open>qdl \\<in> reachable_nodes ?S\\<close> by blast\n\n  have \"isl (target (initial ?S) [])\"\n    using state_separator_from_input_choices_simps(1)[OF assms(2,3,4,5,6)] by auto\n  then have \"[] \\<in> ndlps\"\n    unfolding ndlps_def by auto\n  then have \"ndlps \\<noteq> {}\"\n    by blast\n  moreover have \"finite ndlps\"\n    using acyclic_finite_paths_from_reachable_node[OF \\<open>acyclic ?S\\<close>, of \"[]\"] unfolding ndlps_def by fastforce\n  ultimately have \"\\<exists> p \\<in> ndlps . \\<forall> p' \\<in> ndlps . length p' \\<le> length p\"\n    by (meson max_length_elem not_le_imp_less) \n  then obtain mndlp where \"path ?S (initial ?S) mndlp\"\n                      and \"isl (target (initial ?S) mndlp)\"\n                      and \"\\<And> p . path ?S (initial ?S) p \\<Longrightarrow> isl (target (initial ?S) p) \\<Longrightarrow> length p \\<le> length mndlp\"\n    unfolding ndlps_def by blast\n  then have \"(target (initial ?S) mndlp) \\<in> reachable_nodes ?S\"\n    unfolding reachable_nodes_def by auto\n  then have \"(target (initial ?S) mndlp) \\<in> nodes ?S\"\n    using reachable_node_is_node by auto\n  then have \"(target (initial ?S) mndlp) \\<in> (set (map fst cs))\"\n    using \\<open>isl (target (initial ?S) mndlp)\\<close> state_separator_from_input_choices_simps(2)[OF assms(2,3,4,5,6)] by force\n  then obtain q1' q2' x where \"(Inl (q1',q2'),x) \\<in> set cs\"\n                          and \"target (initial ?S) mndlp = Inl (q1',q2')\"\n    using assms(6) by fastforce\n  then obtain i where \"i < length cs\" and \"(cs ! i) = (Inl (q1',q2'),x)\"\n    by (metis in_set_conv_nth)\n\n  have \"Inl (q1', q2') \\<in> FSM.nodes (canonical_separator M q1 q2)\" and \"x \\<in> FSM.inputs M\"\n    using assms(4)[OF \\<open>(Inl (q1',q2'),x) \\<in> set cs\\<close>] by blast+\n  then have \"(q1',q2') \\<in> nodes (Product_FSM.product (FSM.from_FSM M q1) (FSM.from_FSM M q2))\"\n    using canonical_separator_simps(2)[OF assms(2,3)] by blast\n\n  have \"q1' \\<in> nodes M\" and \"q2' \\<in> nodes M\"\n    using canonical_separator_nodes[OF \\<open>Inl (q1', q2') \\<in> FSM.nodes (canonical_separator M q1 q2)\\<close> assms(2,3)]\n    unfolding product_simps using assms(2,3) by simp+\n\n  have \"\\<not>(\\<exists>t'\\<in>FSM.transitions (canonical_separator M q1 q2). t_source t' = target (initial ?S) mndlp \\<and> t_input t' = x \\<and> isl (t_target t'))\"\n  proof \n    assume \"\\<exists>t'\\<in>FSM.transitions (canonical_separator M q1 q2). t_source t' = target (initial ?S) mndlp \\<and> t_input t' = x \\<and> isl (t_target t')\"\n    then obtain t' where \"t'\\<in>FSM.transitions (canonical_separator M q1 q2)\"\n                     and \"t_source t' = target (initial ?S) mndlp\"\n                     and \"t_input t' = x\"\n                     and \"isl (t_target t')\" \n      by blast\n    then have \"\\<exists>q1' q2' x . (Inl (q1', q2'), x)\\<in>set cs \\<and> t_source t' = Inl (q1', q2') \\<and> t_input t' = x\"\n      using \\<open>(Inl (q1',q2'),x) \\<in> set cs\\<close> unfolding \\<open>target (initial ?S) mndlp = Inl (q1',q2')\\<close> by fast\n    then have \"t' \\<in> transitions ?S\"\n      using \\<open>t'\\<in>FSM.transitions (canonical_separator M q1 q2)\\<close> \\<open>(Inl (q1',q2'),x) \\<in> set cs\\<close>\n      using state_separator_from_input_choices_transitions_alt_def[OF assms(2,3,4,5,6,7)] by blast\n\n    then have \"path ?S (initial ?S) (mndlp @ [t'])\"\n      using \\<open>path ?S (initial ?S) mndlp\\<close> \\<open>t_source t' = target (initial ?S) mndlp\\<close> by (metis path_append_transition)\n    moreover have \"isl (target (initial ?S) (mndlp @[t']))\"\n      using \\<open>isl (t_target t')\\<close> by auto\n    ultimately show \"False\"\n      using \\<open>\\<And> p . path ?S (initial ?S) p \\<Longrightarrow> isl (target (initial ?S) p) \\<Longrightarrow> length p \\<le> length mndlp\\<close>[of \"mndlp@[t']\"] by auto\n  qed\n\n  then obtain y1 y2 where \"(Inl (q1',q2'),x,y1,Inr q1) \\<in> transitions (canonical_separator M q1 q2)\"\n                      and \"(Inl (q1',q2'),x,y2,Inr q2) \\<in> transitions (canonical_separator M q1 q2)\"\n    using canonical_separator_isl_deadlock[OF \\<open>Inl (q1', q2') \\<in> FSM.nodes (canonical_separator M q1 q2)\\<close> \\<open>x \\<in> FSM.inputs M\\<close> \\<open>completely_specified M\\<close> _ assms(2,3)]\n    unfolding \\<open>target (initial ?S) mndlp = Inl (q1',q2')\\<close> by blast\n\n\n  have \"(Inl (q1',q2'), x, y1, Inr q1) \\<in> transitions ?S\"\n    using \\<open>(Inl (q1',q2'),x) \\<in> set cs\\<close> state_separator_from_input_choices_transitions_alt_def[OF assms(2,3,4,5,6,7)] \\<open>(Inl (q1',q2'),x,y1,Inr q1) \\<in> transitions (canonical_separator M q1 q2)\\<close> by force\n\n  have \"(Inl (q1',q2'), x, y2, Inr q2) \\<in> transitions ?S\"\n    using \\<open>(Inl (q1',q2'),x) \\<in> set cs\\<close> state_separator_from_input_choices_transitions_alt_def[OF assms(2,3,4,5,6,7)] \\<open>(Inl (q1',q2'),x,y2,Inr q2) \\<in> transitions (canonical_separator M q1 q2)\\<close> by force\n\n  have \"path ?S (initial ?S) (mndlp@[(Inl (q1',q2'), x, y1, Inr q1)])\"\n    using \\<open>target (initial ?S) mndlp = Inl (q1',q2')\\<close> \n    using path_append_transition[OF \\<open>path ?S (initial ?S) mndlp\\<close> \\<open>(Inl (q1',q2'), x, y1, Inr q1) \\<in> transitions ?S\\<close>] by force\n  moreover have \"target (initial ?S) (mndlp@[(Inl (q1',q2'), x, y1, Inr q1)]) = Inr q1\"\n    by auto\n  ultimately have reachable_prop_1: \"Inr q1 \\<in> reachable_nodes ?S\"\n    using reachable_nodes_intro by metis\n\n   have \"path ?S (initial ?S) (mndlp@[(Inl (q1',q2'), x, y2, Inr q2)])\"\n    using \\<open>target (initial ?S) mndlp = Inl (q1',q2')\\<close> \n    using path_append_transition[OF \\<open>path ?S (initial ?S) mndlp\\<close> \\<open>(Inl (q1',q2'), x, y2, Inr q2) \\<in> transitions ?S\\<close>] by force\n  moreover have \"target (initial ?S) (mndlp@[(Inl (q1',q2'), x, y2, Inr q2)]) = Inr q2\"\n    by auto\n  ultimately have reachable_prop_2: \"Inr q2 \\<in> reachable_nodes ?S\"\n    using reachable_nodes_intro by metis\n\n\n  have retainment_prop : \"\\<And> q x t' . q \\<in> reachable_nodes ?S\n        \\<Longrightarrow> x \\<in> FSM.inputs ?C \n        \\<Longrightarrow> (\\<exists>t\\<in>FSM.transitions ?S. t_source t = q \\<and> t_input t = x) \n        \\<Longrightarrow> t' \\<in> FSM.transitions ?C\n        \\<Longrightarrow> t_source t' = q \n        \\<Longrightarrow> t_input t' = x \n        \\<Longrightarrow> t' \\<in> FSM.transitions ?S\"\n  proof -\n    fix q x t' assume \"q \\<in> reachable_nodes ?S\"\n                  and \"x \\<in> FSM.inputs ?C\"\n                  and \"(\\<exists>t\\<in>FSM.transitions ?S. t_source t = q \\<and> t_input t = x)\"\n                  and \"t' \\<in> FSM.transitions ?C\"\n                  and \"t_source t' = q\" \n                  and \"t_input t' = x\" \n\n    obtain t where \"t \\<in> FSM.transitions ?S\" and \"t_source t = q\" and \"t_input t = x\"\n      using \\<open>(\\<exists>t\\<in>FSM.transitions ?S. t_source t = q \\<and> t_input t = x)\\<close> by blast\n    then have \"t_source t = t_source t' \\<and> t_input t = t_input t'\"\n      using \\<open>t_source t' = q\\<close> \\<open>t_input t' = x\\<close> by auto\n\n    \n    show \"t' \\<in> FSM.transitions ?S\"\n      using i4 unfolding retains_outputs_for_states_and_inputs_def\n      using \\<open>t \\<in> FSM.transitions ?S\\<close> \\<open>t' \\<in> FSM.transitions ?C\\<close> \\<open>t_source t = t_source t' \\<and> t_input t = t_input t'\\<close> \n      by blast\n  qed\n    \n  show ?thesis unfolding is_state_separator_from_canonical_separator_def\n    using submachine_prop\n          single_input_prop\n          acyclic_prop\n          deadlock_prop_1\n          deadlock_prop_2\n          reachable_prop_1\n          reachable_prop_2\n          non_deadlock_prop\n          retainment_prop by blast \nqed\n    \n    \n\nsubsubsection \\<open>Calculating a State Separator by Backwards Reachability Analysis\\<close>\n\ntext \\<open>A state separator for states @{text \"q1\"} and @{text \"q2\"} can be calculated using backwards \n      reachability analysis starting from the two deadlock states of their canonical separator until\n      @{text \"Inl (q1.q2)\"} is reached or it is not possible to reach @{text \"(q1,q2)\"}.\\<close>\n\ndefinition s_states :: \"('a::linorder,'b::linorder,'c) fsm \\<Rightarrow> 'a \\<Rightarrow> 'a \\<Rightarrow> ((('a \\<times> 'a) + 'a) \\<times> 'b) list\" where\n  \"s_states M q1 q2 = (let C = canonical_separator M q1 q2\n   in select_inputs (h C) (initial C) (inputs_as_list C) (remove1 (Inl (q1,q2)) (remove1 (Inr q1) (remove1 (Inr q2) (nodes_as_list C)))) {Inr q1, Inr q2} [])\"\n\n\ndefinition state_separator_from_s_states :: \"('a::linorder,'b::linorder,'c) fsm \\<Rightarrow> 'a \\<Rightarrow> 'a \\<Rightarrow> (('a \\<times> 'a) + 'a, 'b, 'c) fsm option\" \n  where\n  \"state_separator_from_s_states M q1 q2 = \n    (let cs = s_states M q1 q2 \n      in (case length cs of\n            0 \\<Rightarrow> None |\n            _ \\<Rightarrow> if fst (last cs) = Inl (q1,q2)\n                  then Some (state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 cs)\n                  else None))\"\n\n\nlemma state_separator_from_s_states_code[code] :\n  \"state_separator_from_s_states M q1 q2 =\n    (let C = canonical_separator M q1 q2;\n         cs = select_inputs (h C) (initial C) (inputs_as_list C) (remove1 (Inl (q1,q2)) (remove1 (Inr q1) (remove1 (Inr q2) (nodes_as_list C)))) {Inr q1, Inr q2} []\n      in (case length cs of\n            0 \\<Rightarrow> None |\n            _ \\<Rightarrow> if fst (last cs) = Inl (q1,q2)\n                  then Some (state_separator_from_input_choices M C q1 q2 cs) \n                  else None))\"\n  unfolding s_states_def state_separator_from_s_states_def Let_def by simp\n\n\nlemma s_states_properties : \n  assumes \"q1 \\<in> nodes M\" and \"q2 \\<in> nodes M\" \n  shows \"distinct (map fst (s_states M q1 q2))\"\n    and \"\\<And> qq x . (qq,x) \\<in> set (s_states M q1 q2) \\<Longrightarrow> qq \\<in> nodes (canonical_separator M q1 q2) \\<and> x \\<in> inputs M\"\n    and \"\\<And> qq . qq \\<in> set (map fst (s_states M q1 q2)) \\<Longrightarrow> \\<exists> q1' q2' . qq = Inl (q1',q2')\"\n    and \"\\<And> i t . i < length (s_states M q1 q2)\n                  \\<Longrightarrow> t \\<in> transitions (canonical_separator M q1 q2) \n                  \\<Longrightarrow> t_source t = (fst ((s_states M q1 q2) ! i))\n                  \\<Longrightarrow> t_input  t = snd ((s_states M q1 q2) ! i)\n                  \\<Longrightarrow> t_target t \\<in> ((set (map fst (take i (s_states M q1 q2)))) \\<union> {Inr q1, Inr q2})\"\nproof -\n  let ?C = \"canonical_separator M q1 q2\"\n  let ?nS = \"{Inr q1, Inr q2}\"\n  let ?nL = \"(remove1 (Inl (q1,q2)) (remove1 (Inr q1) (remove1 (Inr q2) (nodes_as_list ?C))))\"\n  let ?iL = \"(inputs_as_list ?C)\"\n  let ?q0 = \"(initial ?C)\"\n  let ?f  = \"(h ?C)\"\n  let ?k  = \"(size (canonical_separator M q1 q2))\"\n\n  let ?cs = \"(s_states M q1 q2)\"\n  \n  (* parameter properties required by lemmata for select_inputs *)\n  have pp1: \"distinct (map fst [])\" by auto\n  have pp2: \"set (map fst []) \\<subseteq> ?nS\" by auto\n  have pp3: \"?nS = ?nS \\<union> set (map fst [])\" by auto\n  have pp4: \"?q0 \\<notin> ?nS\" unfolding canonical_separator_simps[OF assms] by auto\n  have pp5 :\"distinct ?nL\" using nodes_as_list_distinct by simp \n  have pp6: \"?q0 \\<notin> set ?nL\" unfolding canonical_separator_simps[OF assms] by auto\n  have pp7: \"set ?nL \\<inter> ?nS = {}\" by auto\n\n  (* index based properties *)\n\n  have \"\\<And> i . length [] \\<le> i\" by auto\n\n  have ip1: \"\\<And> i . i < length ?cs \\<Longrightarrow> fst (?cs ! i) \\<in> (insert ?q0 (set ?nL))\" \n  and  ip2: \"\\<And> i . i < length ?cs \\<Longrightarrow> fst (?cs ! i) \\<notin> ?nS0\"\n  and  ip3: \"\\<And> i . i < length ?cs \\<Longrightarrow> snd (?cs ! i) \\<in> set ?iL\"\n  and  ip4: \"\\<And> i . i < length ?cs \\<Longrightarrow> (\\<forall> qx' \\<in> set (take i ?cs) . fst (?cs ! i) \\<noteq> fst qx')\"\n    using select_inputs_index_properties[OF _ \\<open>\\<And> i . length [] \\<le> i\\<close> pp1 pp3 pp4 pp5 pp6 pp7]\n    unfolding s_states_def Let_def by blast+\n  have ip5: \"\\<And> i . i < length ?cs \\<Longrightarrow> (\\<exists> t \\<in> transitions ?C . t_source t = fst (?cs ! i) \\<and> t_input t = snd (?cs ! i))\"\n    using select_inputs_index_properties(5)[OF _ \\<open>\\<And> i . length [] \\<le> i\\<close> pp1 pp3 pp4 pp5 pp6 pp7]\n    unfolding s_states_def Let_def by blast\n  have ip6: \"\\<And> i t . i < length ?cs \\<Longrightarrow> t \\<in> transitions ?C \\<Longrightarrow> t_source t = fst (?cs ! i) \\<Longrightarrow> t_input t = snd (?cs ! i) \\<Longrightarrow> (t_target t \\<in> ?nS0 \\<or> (\\<exists> qx' \\<in> set (take i ?cs) . fst qx' = (t_target t)))\"\n    using select_inputs_index_properties(6)[OF _ \\<open>\\<And> i . length [] \\<le> i\\<close> pp1 pp3 pp4 pp5 pp6 pp7]\n    unfolding s_states_def Let_def by blast\n\n\n  show \"distinct (map fst ?cs)\" \n    using select_inputs_distinct[OF pp1 pp2 pp4 pp5 pp6 pp7]\n    unfolding s_states_def Let_def by blast\n\n  show \"\\<And> qq x . (qq,x) \\<in> set ?cs \\<Longrightarrow> qq \\<in> nodes (canonical_separator M q1 q2) \\<and> x \\<in> inputs M\"\n  proof -\n    fix qq x assume \"(qq,x) \\<in> set ?cs\"\n    then obtain i where \"i < length ?cs\" and \"?cs ! i = (qq,x)\"\n      by (meson in_set_conv_nth) \n    show \"qq \\<in> nodes (canonical_separator M q1 q2) \\<and> x \\<in> inputs M\"\n      using ip1[OF \\<open>i < length ?cs\\<close>] ip3[OF \\<open>i < length ?cs\\<close>] \n            nodes_as_list_set[of ?C] inputs_as_list_set[of ?C]\n      unfolding \\<open>?cs ! i = (qq,x)\\<close> fst_conv snd_conv canonical_separator_simps(3)[OF assms]\n      by auto \n  qed\n\n  show \"\\<And> qq . qq \\<in> set (map fst ?cs) \\<Longrightarrow> \\<exists> q1' q2' . qq = Inl (q1',q2')\"\n  proof -\n    fix qq assume \"qq \\<in> set (map fst ?cs)\"\n    then obtain i where \"i < length ?cs\" and \"fst (?cs ! i) = qq\"\n      by (metis (no_types, lifting) in_set_conv_nth length_map nth_map)\n    show \"\\<exists> q1' q2' . qq = Inl (q1',q2')\"\n      using ip1[OF \\<open>i < length ?cs\\<close>] nodes_as_list_set[of ?C]\n      unfolding \\<open>fst (?cs ! i) = qq\\<close> canonical_separator_simps[OF assms]\n      by auto \n  qed\n\n  show \"\\<And> i t . i < length ?cs\n                  \\<Longrightarrow> t \\<in> transitions (canonical_separator M q1 q2) \n                  \\<Longrightarrow> t_source t = (fst (?cs ! i))\n                  \\<Longrightarrow> t_input  t = snd (?cs ! i)\n                  \\<Longrightarrow> t_target t \\<in> ((set (map fst (take i ?cs))) \\<union> {Inr q1, Inr q2})\"\n  proof -\n    fix i t assume \"i < length ?cs\"\n               and \"t \\<in> transitions ?C\"\n               and \"t_source t = (fst (?cs ! i))\"\n               and \"t_input  t = snd (?cs ! i)\"\n\n    show \"t_target t \\<in> ((set (map fst (take i ?cs))) \\<union> {Inr q1, Inr q2})\"\n      using ip6[OF \\<open>i < length ?cs\\<close> \\<open>t \\<in> transitions ?C\\<close> \\<open>t_source t = (fst (?cs ! i))\\<close> \\<open>t_input  t = snd (?cs ! i)\\<close>] \n      by (metis Un_iff in_set_conv_nth length_map nth_map)\n  qed\nqed\n\n     \nlemma state_separator_from_s_states_soundness :\n  assumes \"state_separator_from_s_states M q1 q2 = Some A\"\n      and \"q1 \\<in> nodes M\" and \"q2 \\<in> nodes M\" and \"completely_specified M\"\n  shows \"is_state_separator_from_canonical_separator (canonical_separator M q1 q2) q1 q2 A\"\nproof -\n  let ?cs = \"s_states M q1 q2\"\n\n  have \"length (s_states M q1 q2) \\<noteq> 0 \\<and> fst (last (s_states M q1 q2)) = Inl (q1,q2)\"\n  and  \"A = state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 ?cs\"\n    using assms(1) unfolding state_separator_from_s_states_def Let_def\n    by (cases \"length (s_states M q1 q2)\"; cases \"fst (last (s_states M q1 q2)) = Inl (q1,q2)\"; auto)+\n  then have \"Inl (q1,q2) \\<in> set (map fst ?cs)\"\n    by (metis last_in_set length_0_conv map_set)\n     \n\n  show ?thesis \n    using state_separator_from_input_choices_is_state_separator[\n        OF _ assms(2,3) _ \\<open>Inl (q1,q2) \\<in> set (map fst ?cs)\\<close>,\n        OF s_states_properties[OF assms(2,3)] assms(4)] \n    unfolding \\<open>A = state_separator_from_input_choices M (canonical_separator M q1 q2) q1 q2 ?cs\\<close>[symmetric] by blast\nqed\n  \n\nlemma state_separator_from_s_states_exhaustiveness :\n  assumes \"\\<exists> S . is_state_separator_from_canonical_separator (canonical_separator M q1 q2) q1 q2 S\"\n      and \"q1 \\<in> nodes M\" and \"q2 \\<in> nodes M\" and \"completely_specified M\" and \"observable M\"\n  shows \"state_separator_from_s_states M q1 q2 \\<noteq> None\"\nproof -\n  let ?CSep = \"(canonical_separator M q1 q2)\"\n\n  obtain S where S_def: \"is_state_separator_from_canonical_separator (canonical_separator M q1 q2) q1 q2 S\"\n    using assms(1) by blast\n\n  then have \"is_submachine S ?CSep\" \n       and  \"single_input S\"\n       and  \"acyclic S\"\n        and  *:\"\\<And> q . q \\<in> reachable_nodes S \\<Longrightarrow> q \\<noteq> Inr q1 \\<Longrightarrow> q \\<noteq> Inr q2 \\<Longrightarrow> (isl q \\<and> \\<not> deadlock_state S q)\"\n       and  **:\"\\<And> q x t . q \\<in> reachable_nodes S \\<Longrightarrow> x \\<in> (inputs ?CSep) \\<Longrightarrow> (\\<exists> t \\<in> transitions S . t_source t = q \\<and> t_input t = x) \\<Longrightarrow> t \\<in> transitions ?CSep \\<Longrightarrow> t_source t = q \\<Longrightarrow> t_input t = x \\<Longrightarrow> t \\<in> transitions S\"\n    using assms unfolding is_state_separator_from_canonical_separator_def by blast+\n\n  have p1: \"(\\<And>q x. q \\<in> reachable_nodes S \\<Longrightarrow> h S (q, x) \\<noteq> {} \\<Longrightarrow> h S (q, x) = h ?CSep (q, x))\"\n  proof - \n    fix q x assume \"q \\<in> reachable_nodes S\" and \"h S (q, x) \\<noteq> {}\"\n\n    then have \"x \\<in> inputs ?CSep\"\n      using \\<open>is_submachine S ?CSep\\<close> fsm_transition_input by force\n    have \"(\\<exists> t \\<in> transitions S . t_source t = q \\<and> t_input t = x)\"\n      using \\<open>h S (q, x) \\<noteq> {}\\<close> by fastforce\n\n    have \"\\<And> y q'' . (y,q'') \\<in> h S (q,x) \\<Longrightarrow> (y,q'') \\<in> h ?CSep (q,x)\" \n      using \\<open>is_submachine S ?CSep\\<close> by force \n    moreover have \"\\<And> y q'' . (y,q'') \\<in> h ?CSep (q,x) \\<Longrightarrow> (y,q'') \\<in> h S (q,x)\" \n      using **[OF \\<open>q \\<in> reachable_nodes S\\<close> \\<open>x \\<in> inputs ?CSep\\<close> \\<open>(\\<exists> t \\<in> transitions S . t_source t = q \\<and> t_input t = x)\\<close>]\n      unfolding h.simps by force\n    ultimately show \"h S (q, x) = h ?CSep (q, x)\" \n      by force\n  qed \n\n  have p2: \"\\<And>q'. q' \\<in> reachable_nodes S \\<Longrightarrow> deadlock_state S q' \\<Longrightarrow> q' \\<in> {Inr q1, Inr q2} \\<union> set (map fst [])\"\n    using * by fast\n\n  have \"initial S = Inl (q1,q2)\"\n    using is_state_separator_from_canonical_separator_initial[OF S_def assms(2,3)] by assumption\n \n  have ***: \"(set (remove1 (Inl (q1, q2)) (remove1 (Inr q1) (remove1 (Inr q2) (nodes_as_list ?CSep)))) \\<union> {Inr q1, Inr q2} \\<union> set (map fst [])) = (nodes ?CSep - {Inl (q1,q2)})\"\n    using nodes_as_list_set[of ?CSep] nodes_as_list_distinct[of ?CSep] \n    unfolding \n              \\<open>initial S = Inl (q1,q2)\\<close> \n              canonical_separator_simps(2)[OF assms(2,3)]\n    by auto \n\n  have \"Inl (q1,q2) \\<in> reachable_nodes ?CSep\"\n    using reachable_nodes_initial[of S] unfolding \\<open>initial S = Inl (q1,q2)\\<close>\n    using  submachine_reachable_subset[OF \\<open>is_submachine S ?CSep\\<close>] by blast\n  then have p3: \"nodes ?CSep = insert (FSM.initial S) (set (remove1 (Inl (q1,q2)) (remove1 (Inr q1) (remove1 (Inr q2) (nodes_as_list ?CSep)))) \\<union> {Inr q1, Inr q2} \\<union> set (map fst []))\"\n    unfolding *** \\<open>initial S = Inl (q1,q2)\\<close>\n    using reachable_node_is_node by fastforce\n   \n  have p4: \"initial S \\<notin> (set (remove1 (Inl (q1,q2)) (remove1 (Inr q1) (remove1 (Inr q2) (nodes_as_list ?CSep)))) \\<union> {Inr q1, Inr q2} \\<union> set (map fst []))\"\n    using \\<open>FSM.initial S = Inl (q1, q2)\\<close> by auto \n\n  have \"fst (last (s_states M q1 q2)) = Inl (q1,q2)\" and \"length (s_states M q1 q2) > 0\"\n    using select_inputs_from_submachine[OF \\<open>single_input S\\<close> \\<open>acyclic S\\<close> \\<open>is_submachine S ?CSep\\<close> p1 p2 p3 p4]\n    unfolding s_states_def submachine_simps[OF \\<open>is_submachine S ?CSep\\<close>] Let_def canonical_separator_simps(1)[OF assms(2,3)]\n    by auto \n\n  obtain k where\"length (s_states M q1 q2) = Suc k\" \n    using \\<open>length (s_states M q1 q2) > 0\\<close> gr0_conv_Suc by blast \n  have \"(fst (last (s_states M q1 q2)) = Inl (q1,q2)) = True\"\n    using \\<open>fst (last (s_states M q1 q2)) = Inl (q1,q2)\\<close> by simp\n\n  show ?thesis                            \n    unfolding state_separator_from_s_states_def Let_def \\<open>length (s_states M q1 q2) = Suc k\\<close> \\<open>fst (last (s_states M q1 q2)) = Inl (q1,q2)\\<close>\n    by auto\nqed\n\n\n\nsubsection \\<open>Generalizing State Separators\\<close>\n\ntext \\<open>State separators can be defined without reverence to the canonical separator:\\<close>\n\ndefinition is_separator :: \"('a,'b,'c) fsm \\<Rightarrow> 'a \\<Rightarrow> 'a \\<Rightarrow> ('d,'b,'c) fsm \\<Rightarrow> 'd \\<Rightarrow> 'd \\<Rightarrow> bool\" where\n  \"is_separator M q1 q2 A t1 t2 = \n    (single_input A\n     \\<and> acyclic A\n     \\<and> observable A\n     \\<and> deadlock_state A t1 \n     \\<and> deadlock_state A t2\n     \\<and> t1 \\<in> reachable_nodes A\n     \\<and> t2 \\<in> reachable_nodes A\n     \\<and> (\\<forall> t \\<in> reachable_nodes A . (t \\<noteq> t1 \\<and> t \\<noteq> t2) \\<longrightarrow> \\<not> deadlock_state A t)\n     \\<and> (\\<forall> io \\<in> L A . (\\<forall> x yq yt . (io@[(x,yq)] \\<in> LS M q1 \\<and> io@[(x,yt)] \\<in> L A) \\<longrightarrow> (io@[(x,yq)] \\<in> L A))\n                   \\<and> (\\<forall> x yq2 yt . (io@[(x,yq2)] \\<in> LS M q2 \\<and> io@[(x,yt)] \\<in> L A) \\<longrightarrow> (io@[(x,yq2)] \\<in> L A)))\n     \\<and> (\\<forall> p . (path A (initial A) p \\<and> target (initial A) p = t1) \\<longrightarrow> p_io p \\<in> LS M q1 - LS M q2)\n     \\<and> (\\<forall> p . (path A (initial A) p \\<and> target (initial A) p = t2) \\<longrightarrow> p_io p \\<in> LS M q2 - LS M q1)\n     \\<and> (\\<forall> p . (path A (initial A) p \\<and> target (initial A) p \\<noteq> t1 \\<and> target (initial A) p \\<noteq> t2) \\<longrightarrow> p_io p \\<in> LS M q1 \\<inter> LS M q2)\n     \\<and> q1 \\<noteq> q2\n     \\<and> t1 \\<noteq> t2\n     \\<and> (inputs A) \\<subseteq> (inputs M))\"\n\n\nlemma is_separator_simps :\n  assumes \"is_separator M q1 q2 A t1 t2\"\nshows \"single_input A\"\n  and \"acyclic A\"\n  and \"observable A\"\n  and \"deadlock_state A t1\"\n  and \"deadlock_state A t2\"\n  and \"t1 \\<in> reachable_nodes A\"\n  and \"t2 \\<in> reachable_nodes A\"\n  and \"\\<And> t . t \\<in> reachable_nodes A \\<Longrightarrow> t \\<noteq> t1 \\<Longrightarrow> t \\<noteq> t2 \\<Longrightarrow> \\<not> deadlock_state A t\"\n  and \"\\<And> io x yq yt . io@[(x,yq)] \\<in> LS M q1 \\<Longrightarrow> io@[(x,yt)] \\<in> L A \\<Longrightarrow> (io@[(x,yq)] \\<in> L A)\"\n  and \"\\<And> io x yq yt . io@[(x,yq)] \\<in> LS M q2 \\<Longrightarrow> io@[(x,yt)] \\<in> L A \\<Longrightarrow> (io@[(x,yq)] \\<in> L A)\"\n  and \"\\<And> p . path A (initial A) p \\<Longrightarrow> target (initial A) p = t1 \\<Longrightarrow> p_io p \\<in> LS M q1 - LS M q2\"\n  and \"\\<And> p . path A (initial A) p \\<Longrightarrow> target (initial A) p = t2 \\<Longrightarrow> p_io p \\<in> LS M q2 - LS M q1\"\n  and \"\\<And> p . path A (initial A) p \\<Longrightarrow> target (initial A) p \\<noteq> t1 \\<Longrightarrow> target (initial A) p \\<noteq> t2 \\<Longrightarrow> p_io p \\<in> LS M q1 \\<inter> LS M q2\"\n  and \"q1 \\<noteq> q2\"\n  and \"t1 \\<noteq> t2\"\n  and \"(inputs A) \\<subseteq> (inputs M)\"\nproof -\n  have p01: \"single_input A\"\n  and  p02: \"acyclic A\"\n  and  p03: \"observable A\"\n  and  p04: \"deadlock_state A t1\" \n  and  p05: \"deadlock_state A t2\"\n  and  p06: \"t1 \\<in> reachable_nodes A\"\n  and  p07: \"t2 \\<in> reachable_nodes A\"\n  and  p08: \"(\\<forall> t \\<in> reachable_nodes A . (t \\<noteq> t1 \\<and> t \\<noteq> t2) \\<longrightarrow> \\<not> deadlock_state A t)\"\n  and  p09: \"(\\<forall> io \\<in> L A . (\\<forall> x yq yt . (io@[(x,yq)] \\<in> LS M q1 \\<and> io@[(x,yt)] \\<in> L A) \\<longrightarrow> (io@[(x,yq)] \\<in> L A))\n                         \\<and> (\\<forall> x yq2 yt . (io@[(x,yq2)] \\<in> LS M q2 \\<and> io@[(x,yt)] \\<in> L A) \\<longrightarrow> (io@[(x,yq2)] \\<in> L A)))\"\n  and  p10: \"(\\<forall> p . (path A (initial A) p \\<and> target (initial A) p = t1) \\<longrightarrow> p_io p \\<in> LS M q1 - LS M q2)\"\n  and  p11: \"(\\<forall> p . (path A (initial A) p \\<and> target (initial A) p = t2) \\<longrightarrow> p_io p \\<in> LS M q2 - LS M q1)\"\n  and  p12: \"(\\<forall> p . (path A (initial A) p \\<and> target (initial A) p \\<noteq> t1 \\<and> target (initial A) p \\<noteq> t2) \\<longrightarrow> p_io p \\<in> LS M q1 \\<inter> LS M q2)\"\n  and  p13: \"q1 \\<noteq> q2\"\n  and  p14: \"t1 \\<noteq> t2\"\n  and  p15: \"(inputs A) \\<subseteq> (inputs M)\"\n    using assms unfolding is_separator_def by presburger+\n\n  show \"single_input A\" using p01 by assumption\n  show \"acyclic A\" using p02 by assumption\n  show \"observable A\" using p03 by assumption\n  show \"deadlock_state A t1\" using p04 by assumption\n  show \"deadlock_state A t2\" using p05 by assumption\n  show \"t1 \\<in> reachable_nodes A\" using p06 by assumption\n  show \"t2 \\<in> reachable_nodes A\" using p07 by assumption\n  show \"\\<And> io x yq yt . io@[(x,yq)] \\<in> LS M q1 \\<Longrightarrow> io@[(x,yt)] \\<in> L A \\<Longrightarrow> (io@[(x,yq)] \\<in> L A)\" using p09 language_prefix[of _ _ A \"initial A\"] by blast\n  show \"\\<And> io x yq yt . io@[(x,yq)] \\<in> LS M q2 \\<Longrightarrow> io@[(x,yt)] \\<in> L A \\<Longrightarrow> (io@[(x,yq)] \\<in> L A)\" using p09 language_prefix[of _ _ A \"initial A\"] by blast\n  show \"\\<And> t . t \\<in> reachable_nodes A \\<Longrightarrow> t \\<noteq> t1 \\<Longrightarrow> t \\<noteq> t2 \\<Longrightarrow> \\<not> deadlock_state A t\" using p08 by blast\n  show \"\\<And> p . path A (initial A) p \\<Longrightarrow> target (initial A) p = t1 \\<Longrightarrow> p_io p \\<in> LS M q1 - LS M q2\" using p10 by blast\n  show \"\\<And> p . path A (initial A) p \\<Longrightarrow> target (initial A) p = t2 \\<Longrightarrow> p_io p \\<in> LS M q2 - LS M q1\" using p11 by blast\n  show \"\\<And> p . path A (initial A) p \\<Longrightarrow> target (initial A) p \\<noteq> t1 \\<Longrightarrow> target (initial A) p \\<noteq> t2 \\<Longrightarrow> p_io p \\<in> LS M q1 \\<inter> LS M q2\" using p12 by blast\n  show \"q1 \\<noteq> q2\" using p13 by assumption\n  show \"t1 \\<noteq> t2\" using p14 by assumption\n  show \"(inputs A) \\<subseteq> (inputs M)\" using p15 by assumption\nqed\n\n\nlemma separator_initial :\n  assumes \"is_separator M q1 q2 A t1 t2\"\nshows \"initial A \\<noteq> t1\"\nand   \"initial A \\<noteq> t2\"\nproof -\n  show \"initial A \\<noteq> t1\"\n  proof \n    assume \"initial A = t1\"\n    then have \"deadlock_state A (initial A)\"\n      using is_separator_simps(4)[OF assms] by auto\n    then have \"reachable_nodes A = {initial A}\" \n      using nodes_initial_deadlock by blast\n    then show \"False\"\n      using is_separator_simps(7,15)[OF assms] \\<open>initial A = t1\\<close> by auto\n  qed\n\n  show \"initial A \\<noteq> t2\"\n  proof \n    assume \"initial A = t2\"\n    then have \"deadlock_state A (initial A)\"\n      using is_separator_simps(5)[OF assms] by auto\n    then have \"reachable_nodes A = {initial A}\" \n      using nodes_initial_deadlock by blast\n    then show \"False\"\n      using is_separator_simps(6,15)[OF assms] \\<open>initial A = t2\\<close> by auto\n  qed\nqed\n\n\nlemma separator_path_targets :\n  assumes \"is_separator M q1 q2 A t1 t2\"\n  and     \"path A (initial A) p\"\nshows \"p_io p \\<in> LS M q1 - LS M q2 \\<Longrightarrow> target (initial A) p = t1\"\nand   \"p_io p \\<in> LS M q2 - LS M q1 \\<Longrightarrow> target (initial A) p = t2\"\nand   \"p_io p \\<in> LS M q1 \\<inter> LS M q2 \\<Longrightarrow> (target (initial A) p \\<noteq> t1 \\<and> target (initial A) p \\<noteq> t2)\"\nand   \"p_io p \\<in> LS M q1 \\<union> LS M q2\"\nproof -\n  have pt1: \"\\<And> p . path A (initial A) p \\<Longrightarrow> target (initial A) p = t1 \\<Longrightarrow> p_io p \\<in> LS M q1 - LS M q2\" \n  and  pt2: \"\\<And> p . path A (initial A) p \\<Longrightarrow> target (initial A) p = t2 \\<Longrightarrow> p_io p \\<in> LS M q2 - LS M q1\" \n  and  pt3: \"\\<And> p . path A (initial A) p \\<Longrightarrow> target (initial A) p \\<noteq> t1 \\<Longrightarrow> target (initial A) p \\<noteq> t2 \\<Longrightarrow> p_io p \\<in> LS M q1 \\<inter> LS M q2\" \n  and  \"t1 \\<noteq> t2\"\n  and  \"observable A\"\n    using is_separator_simps[OF assms(1)] by blast+\n\n  show \"p_io p \\<in> LS M q1 - LS M q2 \\<Longrightarrow> target (initial A) p = t1\"\n    using pt1[OF \\<open>path A (initial A) p\\<close>] pt2[OF \\<open>path A (initial A) p\\<close>] pt3[OF \\<open>path A (initial A) p\\<close>] \\<open>t1 \\<noteq> t2\\<close> by blast\n  show \"p_io p \\<in> LS M q2 - LS M q1 \\<Longrightarrow> target (initial A) p = t2\"\n    using pt1[OF \\<open>path A (initial A) p\\<close>] pt2[OF \\<open>path A (initial A) p\\<close>] pt3[OF \\<open>path A (initial A) p\\<close>] \\<open>t1 \\<noteq> t2\\<close> by blast\n  show \"p_io p \\<in> LS M q1 \\<inter> LS M q2 \\<Longrightarrow> (target (initial A) p \\<noteq> t1 \\<and> target (initial A) p \\<noteq> t2)\"\n    using pt1[OF \\<open>path A (initial A) p\\<close>] pt2[OF \\<open>path A (initial A) p\\<close>] pt3[OF \\<open>path A (initial A) p\\<close>] \\<open>t1 \\<noteq> t2\\<close> by blast\n  show \"p_io p \\<in> LS M q1 \\<union> LS M q2\"\n    using pt1[OF \\<open>path A (initial A) p\\<close>] pt2[OF \\<open>path A (initial A) p\\<close>] pt3[OF \\<open>path A (initial A) p\\<close>] \\<open>t1 \\<noteq> t2\\<close> by blast\nqed\n\n\nlemma separator_language :\n  assumes \"is_separator M q1 q2 A t1 t2\"\n  and     \"io \\<in> L A\"\nshows \"io \\<in> LS M q1 - LS M q2 \\<Longrightarrow> io_targets A io (initial A) = {t1}\"\nand   \"io \\<in> LS M q2 - LS M q1 \\<Longrightarrow> io_targets A io (initial A) = {t2}\"\nand   \"io \\<in> LS M q1 \\<inter> LS M q2 \\<Longrightarrow> io_targets A io (initial A) \\<inter> {t1,t2} = {}\"\nand   \"io \\<in> LS M q1 \\<union> LS M q2\"\nproof -\n\n  obtain p where \"path A (initial A) p\" and \"p_io p = io\"\n    using \\<open>io \\<in> L A\\<close>  by auto\n\n  have pt1: \"\\<And> p . path A (initial A) p \\<Longrightarrow> target (initial A) p = t1 \\<Longrightarrow> p_io p \\<in> LS M q1 - LS M q2\" \n  and  pt2: \"\\<And> p . path A (initial A) p \\<Longrightarrow> target (initial A) p = t2 \\<Longrightarrow> p_io p \\<in> LS M q2 - LS M q1\" \n  and  pt3: \"\\<And> p . path A (initial A) p \\<Longrightarrow> target (initial A) p \\<noteq> t1 \\<Longrightarrow> target (initial A) p \\<noteq> t2 \\<Longrightarrow> p_io p \\<in> LS M q1 \\<inter> LS M q2\" \n  and  \"t1 \\<noteq> t2\"\n  and  \"observable A\"\n    using is_separator_simps[OF assms(1)] by blast+\n\n\n  show \"io \\<in> LS M q1 - LS M q2 \\<Longrightarrow> io_targets A io (initial A) = {t1}\"\n  proof -\n    assume \"io \\<in> LS M q1 - LS M q2\"\n    \n    then have \"p_io p \\<in> LS M q1 - LS M q2\"\n      using \\<open>p_io p = io\\<close> by auto\n    then have \"target (initial A) p = t1\"\n      using pt1[OF \\<open>path A (initial A) p\\<close>] pt2[OF \\<open>path A (initial A) p\\<close>] pt3[OF \\<open>path A (initial A) p\\<close>] \\<open>t1 \\<noteq> t2\\<close>\n      by blast \n    then have \"t1 \\<in> io_targets A io (initial A)\"\n      using \\<open>path A (initial A) p\\<close> \\<open>p_io p = io\\<close> unfolding io_targets.simps by force\n    then show \"io_targets A io (initial A) = {t1}\"\n      using observable_io_targets[OF \\<open>observable A\\<close>]\n      by (metis \\<open>io \\<in> L A\\<close> singletonD) \n  qed\n\n  show \"io \\<in> LS M q2 - LS M q1 \\<Longrightarrow> io_targets A io (initial A) = {t2}\"\n  proof -\n    assume \"io \\<in> LS M q2 - LS M q1\"\n    \n    then have \"p_io p \\<in> LS M q2 - LS M q1\"\n      using \\<open>p_io p = io\\<close> by auto\n    then have \"target (initial A) p = t2\"\n      using pt1[OF \\<open>path A (initial A) p\\<close>] pt2[OF \\<open>path A (initial A) p\\<close>] pt3[OF \\<open>path A (initial A) p\\<close>] \\<open>t1 \\<noteq> t2\\<close>\n      by blast \n    then have \"t2 \\<in> io_targets A io (initial A)\"\n      using \\<open>path A (initial A) p\\<close> \\<open>p_io p = io\\<close> unfolding io_targets.simps by force\n    then show \"io_targets A io (initial A) = {t2}\"\n      using observable_io_targets[OF \\<open>observable A\\<close>]\n      by (metis \\<open>io \\<in> L A\\<close> singletonD) \n  qed\n\n  show \"io \\<in> LS M q1 \\<inter> LS M q2 \\<Longrightarrow> io_targets A io (initial A) \\<inter> {t1,t2} = {}\"\n  proof -\n    assume \"io \\<in> LS M q1 \\<inter> LS M q2\"\n    \n    then have \"p_io p \\<in> LS M q1 \\<inter> LS M q2\"\n      using \\<open>p_io p = io\\<close> by auto\n    then have \"target (initial A) p \\<noteq> t1\" and \"target (initial A) p \\<noteq> t2\"\n      using pt1[OF \\<open>path A (initial A) p\\<close>] pt2[OF \\<open>path A (initial A) p\\<close>] pt3[OF \\<open>path A (initial A) p\\<close>] \\<open>t1 \\<noteq> t2\\<close>\n      by blast+ \n    moreover have \"target (initial A) p \\<in> io_targets A io (initial A)\"\n      using \\<open>path A (initial A) p\\<close> \\<open>p_io p = io\\<close> unfolding io_targets.simps by force\n    ultimately show \"io_targets A io (initial A) \\<inter> {t1,t2} = {}\"\n      using observable_io_targets[OF \\<open>observable A\\<close> \\<open>io \\<in> L A\\<close>]\n      by (metis (no_types, hide_lams) inf_bot_left insert_disjoint(2) insert_iff singletonD) \n  qed\n\n  show \"io \\<in> LS M q1 \\<union> LS M q2\"\n    using separator_path_targets(4)[OF assms(1) \\<open>path A (initial A) p\\<close>] \\<open>p_io p = io\\<close> by auto\nqed\n\n\nlemma is_separator_sym :\n  \"is_separator M q1 q2 A t1 t2 \\<Longrightarrow> is_separator M q2 q1 A t2 t1\"\n  unfolding is_separator_def Int_commute[of \"LS M q2\" \"LS M q1\"] by meson \n\n\nlemma state_separator_from_canonical_separator_is_separator :\n  assumes \"is_state_separator_from_canonical_separator (canonical_separator M q1 q2) q1 q2 A\"\n  and     \"observable M\" \n  and     \"q1 \\<in> nodes M\"\n  and     \"q2 \\<in> nodes M\"\n  and     \"q1 \\<noteq> q2\"\nshows \"is_separator M q1 q2 A (Inr q1) (Inr q2)\"\nproof -\n  let ?C = \"canonical_separator M q1 q2\"\n  have \"observable ?C\"\n    using canonical_separator_observable[OF assms(2,3,4)] by assumption\n\n  have \"is_submachine A ?C\" \n  and   p1: \"single_input A\"\n  and   p2: \"acyclic A\"\n  and   p4: \"deadlock_state A (Inr q1)\"\n  and   p5: \"deadlock_state A (Inr q2)\"\n  and   p6: \"((Inr q1) \\<in> reachable_nodes A)\"\n  and   p7: \"((Inr q2) \\<in> reachable_nodes A)\"\n  and   \"\\<And> q . q \\<in> reachable_nodes A \\<Longrightarrow> q \\<noteq> Inr q1 \\<Longrightarrow> q \\<noteq> Inr q2 \\<Longrightarrow> (isl q \\<and> \\<not> deadlock_state A q)\"\n  and   compl: \"\\<And> q x t . q \\<in> reachable_nodes A \\<Longrightarrow> x \\<in> (inputs M) \\<Longrightarrow> (\\<exists> t \\<in> transitions A . t_source t = q \\<and> t_input t = x) \\<Longrightarrow> t \\<in> transitions ?C \\<Longrightarrow> t_source t = q \\<Longrightarrow> t_input t = x \\<Longrightarrow> t \\<in> transitions A\"\n    using is_state_separator_from_canonical_separator_simps[OF assms(1)]\n    unfolding canonical_separator_simps[OF assms(3,4)]\n    by blast+\n\n  have p3: \"observable A\" \n    using state_separator_from_canonical_separator_observable[OF assms(1-4)] by assumption\n\n  have p8: \"(\\<forall>t\\<in>reachable_nodes A. t \\<noteq> Inr q1 \\<and> t \\<noteq> Inr q2 \\<longrightarrow> \\<not> deadlock_state A t)\"\n    using \\<open>\\<And> q . q \\<in> reachable_nodes A \\<Longrightarrow> q \\<noteq> Inr q1 \\<Longrightarrow> q \\<noteq> Inr q2 \\<Longrightarrow> (isl q \\<and> \\<not> deadlock_state A q)\\<close> by simp\n\n  have \"\\<And> io . io \\<in> L A \\<Longrightarrow> \n        (io \\<in> LS M q1 - LS M q2 \\<longrightarrow> io_targets A io (initial A) = {Inr q1}) \\<and>\n        (io \\<in> LS M q2 - LS M q1 \\<longrightarrow> io_targets A io (initial A) = {Inr q2}) \\<and>\n        (io \\<in> LS M q1 \\<inter> LS M q2 \\<longrightarrow> io_targets A io (initial A) \\<inter> {Inr q1, Inr q2} = {}) \\<and>\n        (\\<forall>x yq yt. io @ [(x, yq)] \\<in> LS M q1 \\<and> io @ [(x, yt)] \\<in> LS A (initial A) \\<longrightarrow> io @ [(x, yq)] \\<in> LS A (initial A)) \\<and>\n        (\\<forall>x yq2 yt. io @ [(x, yq2)] \\<in> LS M q2 \\<and> io @ [(x, yt)] \\<in> LS A (initial A) \\<longrightarrow> io @ [(x, yq2)] \\<in> LS A (initial A))\"\n  proof -\n    fix io assume \"io \\<in> L A\"\n\n    have \"io \\<in> LS M q1 - LS M q2 \\<Longrightarrow> io_targets A io (initial A) = {Inr q1}\"\n      using state_separator_from_canonical_separator_language_target(1)[OF assms(1) \\<open>io \\<in> L A\\<close> assms(2,3,4,5)] by assumption\n    moreover have \"io \\<in> LS M q2 - LS M q1 \\<Longrightarrow> io_targets A io (initial A) = {Inr q2}\"\n      using state_separator_from_canonical_separator_language_target(2)[OF assms(1) \\<open>io \\<in> L A\\<close> assms(2,3,4,5)] by assumption\n    moreover have \"io \\<in> LS M q1 \\<inter> LS M q2 \\<Longrightarrow> io_targets A io (initial A) \\<inter> {Inr q1, Inr q2} = {}\"\n      using state_separator_from_canonical_separator_language_target(3)[OF assms(1) \\<open>io \\<in> L A\\<close> assms(2,3,4,5)] by assumption\n    moreover have \"\\<And> x yq yt. io @ [(x, yq)] \\<in> LS M q1 \\<Longrightarrow> io @ [(x, yt)] \\<in> L A \\<Longrightarrow> io @ [(x, yq)] \\<in> L A\"\n    proof -\n      fix x yq yt assume \"io @ [(x, yq)] \\<in> LS M q1\" and \"io @ [(x, yt)] \\<in> L A\"\n\n      obtain pA tA where \"path A (initial A) (pA@[tA])\" and \"p_io (pA@[tA]) = io @ [(x, yt)]\"\n        using language_initial_path_append_transition[OF \\<open>io @ [(x, yt)] \\<in> L A\\<close>] by blast\n      then have \"path A (initial A) pA\" and \"p_io pA = io\"\n        by auto\n      then have \"path ?C (initial ?C) pA\"\n        using submachine_path_initial[OF \\<open>is_submachine A ?C\\<close>] by auto\n\n      obtain p1 t1 where \"path M q1 (p1@[t1])\" and \"p_io (p1@[t1]) = io @ [(x, yq)]\"\n        using language_path_append_transition[OF \\<open>io @ [(x, yq)] \\<in> LS M q1\\<close>] by blast\n      then have \"path M q1 p1\" and \"p_io p1 = io\" and \"t1 \\<in> transitions M\" and \"t_input t1 = x\" and \"t_output t1 = yq\" and \"t_source t1 = target q1 p1\"\n        by auto\n\n      let ?q = \"target (initial A) pA\"\n      have \"?q \\<in> nodes A\"\n        using path_target_is_node \\<open>path A (initial A) (pA@[tA])\\<close> by auto\n      have \"?q \\<in> reachable_nodes A\"\n        using \\<open>path A (initial A) pA\\<close> reachable_nodes_intro by blast\n\n      have \"tA \\<in> transitions A\" and \"t_input tA = x\" and \"t_output tA = yt\" and \"t_source tA = target (initial A) pA\"\n        using \\<open>path A (initial A) (pA@[tA])\\<close> \\<open>p_io (pA@[tA]) = io @ [(x, yt)]\\<close> by auto\n      then have \"x \\<in> (inputs M)\"\n        using \\<open>is_submachine A ?C\\<close> \n        unfolding is_submachine.simps canonical_separator_simps[OF assms(3,4)] by auto\n      \n      have \"\\<exists>t\\<in>(transitions A). t_source t = target (initial A) pA \\<and> t_input t = x\"\n        using \\<open>tA \\<in> transitions A\\<close> \\<open>t_input tA = x\\<close> \\<open>t_source tA = target (initial A) pA\\<close> by blast\n\n      have \"io \\<in> LS M q2\"\n        using submachine_language[OF \\<open>is_submachine A ?C\\<close>] \\<open>io @ [(x, yt)] \\<in> L A\\<close> \n        using canonical_separator_language_prefix[OF _ assms(3,4,2,5), of io \"(x,yt)\"] by blast\n      then obtain p2 where \"path M q2 p2\" and \"p_io p2 = io\"\n        by auto\n      \n\n\n      show \"io @ [(x, yq)] \\<in> L A\" \n      proof (cases \"\\<exists> t2 \\<in> transitions M . t_source t2 = target q2 p2 \\<and> t_input t2 = x \\<and> t_output t2 = yq\")\n        case True\n        then obtain t2 where \"t2 \\<in> transitions M\" and \"t_source t2 = target q2 p2\" and \"t_input t2 = x\" and \"t_output t2 = yq\"\n          by blast\n        then have \"path M q2 (p2@[t2])\" and \"p_io (p2@[t2]) = io@[(x,yq)]\"\n          using path_append_transition[OF \\<open>path M q2 p2\\<close>] \\<open>p_io p2 = io\\<close> by auto\n        then have \"io @ [(x, yq)] \\<in> LS M q2\"\n          unfolding LS.simps by (metis (mono_tags, lifting) mem_Collect_eq) \n        then have \"io@[(x,yq)] \\<in> L ?C\"\n          using  canonical_separator_language_intersection[OF \\<open>io @ [(x, yq)] \\<in> LS M q1\\<close> _ assms(3,4)] by blast\n        \n        obtain pA' tA' where \"path ?C (initial ?C) (pA'@[tA'])\" and \"p_io (pA'@[tA']) = io@[(x,yq)]\"\n          using language_initial_path_append_transition[OF \\<open>io @ [(x, yq)] \\<in> L ?C\\<close>] by blast\n        then have \"path ?C (initial ?C) pA'\" and \"p_io pA' = io\" and \"tA' \\<in> transitions ?C\" and \"t_source tA' = target (initial ?C) pA'\" and \"t_input tA' = x\" and \"t_output tA' = yq\"\n          by auto\n\n        have \"pA = pA'\"\n          using observable_path_unique[OF \\<open>observable ?C\\<close> \\<open>path ?C (initial ?C) pA'\\<close> \\<open>path ?C (initial ?C) pA\\<close>]\n          using \\<open>p_io pA' = io\\<close> \\<open>p_io pA = io\\<close> by auto\n        then have \"t_source tA' = target (initial A) pA\"\n          using \\<open>t_source tA' = target (initial ?C) pA'\\<close>\n          using is_state_separator_from_canonical_separator_initial[OF assms(1,3,4)]\n          using canonical_separator_initial[OF assms(3,4)] by fastforce\n\n\n        have \"tA' \\<in> transitions A\"\n          using compl[OF \\<open>?q \\<in> reachable_nodes A\\<close> \\<open>x \\<in> (inputs M)\\<close> \\<open>\\<exists>t\\<in>(transitions A). t_source t = target (initial A) pA \\<and> t_input t = x\\<close> \\<open>tA' \\<in> transitions ?C\\<close> \\<open>t_source tA' = target (initial A) pA\\<close> \\<open>t_input tA' = x\\<close>] by assumption\n        then have \"path A (initial A) (pA@[tA'])\" \n          using \\<open>path A (initial A) pA\\<close> \\<open>t_source tA' = target (initial A) pA\\<close> using path_append_transition by metis\n        moreover have \"p_io (pA@[tA']) = io@[(x,yq)]\"\n          using \\<open>t_input tA' = x\\<close> \\<open>t_output tA' = yq\\<close> \\<open>p_io pA = io\\<close> by auto\n        \n        ultimately show ?thesis \n          using language_state_containment\n          by (metis (mono_tags, lifting)) \n          \n      next\n        case False\n\n        let ?P = \"product (from_FSM M q1) (from_FSM M q2)\"\n        let ?qq = \"(target q1 p1, target q2 p2)\"\n        let ?tA = \"(Inl (target q1 p1, target q2 p2), x, yq, Inr q1)\"\n\n        have \"path (from_FSM M q1) (initial (from_FSM M q1)) p1\" \n          using from_FSM_path_initial[OF \\<open>q1 \\<in> nodes M\\<close>] \\<open>path M q1 p1\\<close> by auto\n        have \"path (from_FSM M q2) (initial (from_FSM M q2)) p2\" \n          using from_FSM_path_initial[OF \\<open>q2 \\<in> nodes M\\<close>] \\<open>path M q2 p2\\<close> by auto\n        have \"p_io p1 = p_io p2\"\n          using \\<open>p_io p1 = io\\<close> \\<open>p_io p2 = io\\<close> by auto\n        \n        have \"?qq \\<in> nodes ?P\" \n          using reachable_nodes_intro[OF product_path_from_paths(1)[OF \\<open>path (from_FSM M q1) (initial (from_FSM M q1)) p1\\<close> \\<open>path (from_FSM M q2) (initial (from_FSM M q2)) p2\\<close> \\<open>p_io p1 = p_io p2\\<close>]]\n          unfolding product_path_from_paths(2)[OF \\<open>path (from_FSM M q1) (initial (from_FSM M q1)) p1\\<close> \\<open>path (from_FSM M q2) (initial (from_FSM M q2)) p2\\<close> \\<open>p_io p1 = p_io p2\\<close>] from_FSM_simps[OF assms(3)] from_FSM_simps[OF assms(4)] \n          using reachable_node_is_node\n          by metis\n        moreover have \"\\<exists>q'. (target q1 p1, x, yq, q') \\<in> FSM.transitions M\"\n          using \\<open>t1 \\<in> FSM.transitions M\\<close> \\<open>t_input t1 = x\\<close> \\<open>t_output t1 = yq\\<close> \\<open>t_source t1 = target q1 p1\\<close>\n          by (metis prod.collapse) \n        moreover have \"\\<not>(\\<exists>q'. (target q2 p2, x, yq, q') \\<in> FSM.transitions M)\"\n          using \\<open>t1 \\<in> FSM.transitions M\\<close> \\<open>t_input t1 = x\\<close> \\<open>t_output t1 = yq\\<close> \\<open>t_source t1 = target q1 p1\\<close> False\n          by fastforce\n        ultimately have \"?tA \\<in> (distinguishing_transitions_left M q1 q2)\"\n          unfolding distinguishing_transitions_left_def \n          by blast\n\n        then have \"(Inl (target q1 p1, target q2 p2), x, yq, Inr q1) \\<in> transitions ?C\"\n          using canonical_separator_distinguishing_transitions_left_containment[OF _ assms(3,4)] by metis\n\n        let ?pP = \"zip_path p1 p2\"\n        let ?pC = \"map shift_Inl ?pP\"\n        have \"path ?P (initial ?P) ?pP\" \n        and  \"target (initial ?P) ?pP = (target q1 p1, target q2 p2)\"\n          using  product_path_from_paths[OF \\<open>path (from_FSM M q1) (initial (from_FSM M q1)) p1\\<close>\n                                            \\<open>path (from_FSM M q2) (initial (from_FSM M q2)) p2\\<close>\n                                            \\<open>p_io p1 = p_io p2\\<close>]\n          using assms(3,4) by auto\n\n        have \"length p1 = length p2\"\n          using \\<open>p_io p1 = p_io p2\\<close> map_eq_imp_length_eq by blast \n        then have \"p_io ?pP = io\"\n          using \\<open>p_io p1 = io\\<close>  by (induction p1 p2 arbitrary: io rule: list_induct2; auto)\n        \n\n        have \"path ?C (initial ?C) ?pC\"\n          using canonical_separator_path_shift[OF assms(3,4)] \\<open>path ?P (initial ?P) ?pP\\<close> by simp\n\n        have \"target (initial ?C) ?pC = Inl (target q1 p1, target q2 p2)\"\n          using path_map_target[of Inl \"initial ?P\" Inl id id ?pP ]\n          using \\<open>target (initial ?P) ?pP = (target q1 p1, target q2 p2)\\<close>\n          unfolding canonical_separator_simps[OF assms(3,4)] product_simps from_FSM_simps[OF assms(3)] from_FSM_simps[OF assms(4)]\n          by fastforce\n        \n        have \"p_io ?pC = io\"\n          using \\<open>p_io ?pP = io\\<close> by auto\n        have \"p_io pA = p_io ?pC\"\n          unfolding \\<open>p_io ?pC = io\\<close>\n          using \\<open>p_io pA = io\\<close> by assumption\n  \n        then have \"?pC = pA\"\n          using observable_path_unique[OF \\<open>observable ?C\\<close> \\<open>path ?C (initial ?C) pA\\<close> \\<open>path ?C (initial ?C) ?pC\\<close>] by auto\n        then have \"t_source ?tA = target (initial A) pA\"\n          using \\<open>target (initial ?C) ?pC = Inl (target q1 p1, target q2 p2)\\<close>\n          unfolding is_state_separator_from_canonical_separator_initial[OF assms(1,3,4)]\n                    canonical_separator_simps[OF assms(3,4)] by force\n\n        have \"?tA \\<in> transitions A\"\n          using compl[OF \\<open>?q \\<in> reachable_nodes A\\<close> \\<open>x \\<in> (inputs M)\\<close> \\<open>\\<exists>t\\<in>(transitions A). t_source t = target (initial A) pA \\<and> t_input t = x\\<close> \\<open>?tA \\<in> transitions ?C\\<close> \\<open>t_source ?tA = target (initial A) pA\\<close> ]\n          unfolding snd_conv fst_conv by simp\n\n        have *: \"path A (initial A) (pA@[?tA])\"\n          using path_append_transition[OF \\<open>path A (initial A) pA\\<close> \\<open>?tA \\<in> transitions A\\<close>  \\<open>t_source ?tA = target (initial A) pA\\<close>] by assumption\n\n        have **: \"p_io (pA@[?tA]) = io@[(x,yq)]\"\n          using \\<open>p_io pA = io\\<close> by auto\n\n        show ?thesis \n          using language_state_containment[OF * **] by assumption\n      qed\n    qed\n\n    \n    moreover have \"\\<And> x yq yt. io @ [(x, yq)] \\<in> LS M q2 \\<Longrightarrow> io @ [(x, yt)] \\<in> L A \\<Longrightarrow> io @ [(x, yq)] \\<in> L A\"\n    proof -\n      fix x yq yt assume \"io @ [(x, yq)] \\<in> LS M q2\" and \"io @ [(x, yt)] \\<in> L A\"\n\n      obtain pA tA where \"path A (initial A) (pA@[tA])\" and \"p_io (pA@[tA]) = io @ [(x, yt)]\"\n        using language_initial_path_append_transition[OF \\<open>io @ [(x, yt)] \\<in> L A\\<close>] by blast\n      then have \"path A (initial A) pA\" and \"p_io pA = io\"\n        by auto\n      then have \"path ?C (initial ?C) pA\"\n        using submachine_path_initial[OF \\<open>is_submachine A ?C\\<close>] by auto\n\n      obtain p2 t2 where \"path M q2 (p2@[t2])\" and \"p_io (p2@[t2]) = io @ [(x, yq)]\"\n        using language_path_append_transition[OF \\<open>io @ [(x, yq)] \\<in> LS M q2\\<close>] by blast\n      then have \"path M q2 p2\" and \"p_io p2 = io\" and \"t2 \\<in> transitions M\" and \"t_input t2 = x\" and \"t_output t2 = yq\" and \"t_source t2 = target q2 p2\"\n        by auto\n\n      let ?q = \"target (initial A) pA\"\n      have \"?q \\<in> nodes A\"\n        using path_target_is_node \\<open>path A (initial A) (pA@[tA])\\<close> by auto\n\n      have \"tA \\<in> transitions A\" and \"t_input tA = x\" and \"t_output tA = yt\" and \"t_source tA = target (initial A) pA\"\n        using \\<open>path A (initial A) (pA@[tA])\\<close> \\<open>p_io (pA@[tA]) = io @ [(x, yt)]\\<close> by auto\n      then have \"x \\<in> (inputs M)\"\n        using \\<open>is_submachine A ?C\\<close> \n        unfolding is_submachine.simps canonical_separator_simps[OF assms(3,4)] by auto\n      \n      have \"\\<exists>t\\<in>(transitions A). t_source t = target (initial A) pA \\<and> t_input t = x\"\n        using \\<open>tA \\<in> transitions A\\<close> \\<open>t_input tA = x\\<close> \\<open>t_source tA = target (initial A) pA\\<close> by blast\n\n      have \"io \\<in> LS M q1\"\n        using submachine_language[OF \\<open>is_submachine A ?C\\<close>] \\<open>io @ [(x, yt)] \\<in> L A\\<close> \n        using canonical_separator_language_prefix[OF _ assms(3,4,2,5), of io \"(x,yt)\"] by blast\n      then obtain p1 where \"path M q1 p1\" and \"p_io p1 = io\"\n        by auto\n      \n\n\n      show \"io @ [(x, yq)] \\<in> L A\" \n      proof (cases \"\\<exists> t1 \\<in> transitions M . t_source t1 = target q1 p1 \\<and> t_input t1 = x \\<and> t_output t1 = yq\")\n        case True\n        then obtain t1 where \"t1 \\<in> transitions M\" and \"t_source t1 = target q1 p1\" and \"t_input t1 = x\" and \"t_output t1 = yq\"\n          by blast\n        then have \"path M q1 (p1@[t1])\" and \"p_io (p1@[t1]) = io@[(x,yq)]\"\n          using path_append_transition[OF \\<open>path M q1 p1\\<close>] \\<open>p_io p1 = io\\<close> by auto\n        then have \"io @ [(x, yq)] \\<in> LS M q1\"\n          unfolding LS.simps by (metis (mono_tags, lifting) mem_Collect_eq) \n        then have \"io@[(x,yq)] \\<in> L ?C\"\n          using  canonical_separator_language_intersection[OF _ \\<open>io @ [(x, yq)] \\<in> LS M q2\\<close> assms(3,4)] by blast\n        \n        obtain pA' tA' where \"path ?C (initial ?C) (pA'@[tA'])\" and \"p_io (pA'@[tA']) = io@[(x,yq)]\"\n          using language_initial_path_append_transition[OF \\<open>io @ [(x, yq)] \\<in> L ?C\\<close>] by blast\n        then have \"path ?C (initial ?C) pA'\" and \"p_io pA' = io\" and \"tA' \\<in> transitions ?C\" and \"t_source tA' = target (initial ?C) pA'\" and \"t_input tA' = x\" and \"t_output tA' = yq\"\n          by auto\n\n        have \"pA = pA'\"\n          using observable_path_unique[OF \\<open>observable ?C\\<close> \\<open>path ?C (initial ?C) pA'\\<close> \\<open>path ?C (initial ?C) pA\\<close>]\n          using \\<open>p_io pA' = io\\<close> \\<open>p_io pA = io\\<close> by auto\n        then have \"t_source tA' = target (initial A) pA\"\n          using \\<open>t_source tA' = target (initial ?C) pA'\\<close>\n          using is_state_separator_from_canonical_separator_initial[OF assms(1,3,4)] \n          unfolding canonical_separator_simps[OF assms(3,4)] by auto\n\n        have \"?q \\<in> reachable_nodes A\"\n          using \\<open>path A (initial A) pA\\<close> reachable_nodes_intro by blast\n\n        have \"tA' \\<in> transitions A\"\n          using compl[OF \\<open>?q \\<in> reachable_nodes A\\<close> \\<open>x \\<in> (inputs M)\\<close> \\<open>\\<exists>t\\<in>(transitions A). t_source t = target (initial A) pA \\<and> t_input t = x\\<close> \\<open>tA' \\<in> transitions ?C\\<close> \\<open>t_source tA' = target (initial A) pA\\<close> \\<open>t_input tA' = x\\<close>] by assumption\n        then have \"path A (initial A) (pA@[tA'])\" \n          using \\<open>path A (initial A) pA\\<close> \\<open>t_source tA' = target (initial A) pA\\<close> using path_append_transition by metis\n        moreover have \"p_io (pA@[tA']) = io@[(x,yq)]\"\n          using \\<open>t_input tA' = x\\<close> \\<open>t_output tA' = yq\\<close> \\<open>p_io pA = io\\<close> by auto\n        \n        ultimately show ?thesis \n          using language_state_containment\n          by (metis (mono_tags, lifting)) \n          \n      next\n        case False\n\n        let ?P = \"product (from_FSM M q1) (from_FSM M q2)\"\n        let ?qq = \"(target q1 p1, target q2 p2)\"\n        let ?tA = \"(Inl (target q1 p1, target q2 p2), x, yq, Inr q2)\"\n\n        have \"path (from_FSM M q1) (initial (from_FSM M q1)) p1\" \n          using from_FSM_path_initial[OF \\<open>q1 \\<in> nodes M\\<close>] \\<open>path M q1 p1\\<close> by auto\n        have \"path (from_FSM M q2) (initial (from_FSM M q2)) p2\" \n          using from_FSM_path_initial[OF \\<open>q2 \\<in> nodes M\\<close>] \\<open>path M q2 p2\\<close> by auto\n        have \"p_io p1 = p_io p2\"\n          using \\<open>p_io p1 = io\\<close> \\<open>p_io p2 = io\\<close> by auto\n\n        have \"?qq \\<in> nodes ?P\"\n          using reachable_nodes_intro[OF product_path_from_paths(1)[OF \\<open>path (from_FSM M q1) (initial (from_FSM M q1)) p1\\<close> \\<open>path (from_FSM M q2) (initial (from_FSM M q2)) p2\\<close> \\<open>p_io p1 = p_io p2\\<close>]]\n          unfolding product_path_from_paths(2)[OF \\<open>path (from_FSM M q1) (initial (from_FSM M q1)) p1\\<close> \\<open>path (from_FSM M q2) (initial (from_FSM M q2)) p2\\<close> \\<open>p_io p1 = p_io p2\\<close>] from_FSM_simps[OF assms(3)] from_FSM_simps[OF assms(4)] \n          using reachable_node_is_node by metis\n        moreover have \"\\<exists>q'. (target q2 p2, x, yq, q') \\<in> FSM.transitions M\"\n          using \\<open>t2 \\<in> FSM.transitions M\\<close> \\<open>t_input t2 = x\\<close> \\<open>t_output t2 = yq\\<close> \\<open>t_source t2 = target q2 p2\\<close>\n          by (metis prod.collapse) \n        moreover have \"\\<not>(\\<exists>q'. (target q1 p1, x, yq, q') \\<in> FSM.transitions M)\"\n          using \\<open>t2 \\<in> FSM.transitions M\\<close> \\<open>t_input t2 = x\\<close> \\<open>t_output t2 = yq\\<close> \\<open>t_source t2 = target q2 p2\\<close> False\n          by fastforce\n        ultimately have \"?tA \\<in> (distinguishing_transitions_right M q1 q2)\"\n          unfolding distinguishing_transitions_right_def \n          by blast\n\n        then have \"?tA \\<in> transitions ?C\"\n          using canonical_separator_distinguishing_transitions_right_containment[OF _ assms(3,4)] by metis\n\n        let ?pP = \"zip_path p1 p2\"\n        let ?pC = \"map shift_Inl ?pP\"\n        have \"path ?P (initial ?P) ?pP\" \n        and  \"target (initial ?P) ?pP = (target q1 p1, target q2 p2)\"\n          using  product_path_from_paths[OF \\<open>path (from_FSM M q1) (initial (from_FSM M q1)) p1\\<close>\n                                            \\<open>path (from_FSM M q2) (initial (from_FSM M q2)) p2\\<close>\n                                            \\<open>p_io p1 = p_io p2\\<close>]\n          using assms(3,4) by auto\n\n        have \"length p1 = length p2\"\n          using \\<open>p_io p1 = p_io p2\\<close> map_eq_imp_length_eq by blast \n        then have \"p_io ?pP = io\"\n          using \\<open>p_io p1 = io\\<close>  by (induction p1 p2 arbitrary: io rule: list_induct2; auto)\n        \n\n        have \"path ?C (initial ?C) ?pC\"\n          using canonical_separator_path_shift[OF assms(3,4)] \\<open>path ?P (initial ?P) ?pP\\<close> by simp\n\n        have \"target (initial ?C) ?pC = Inl (target q1 p1, target q2 p2)\"\n          using path_map_target[of Inl \"initial ?P\" Inl id id ?pP ]\n          using \\<open>target (initial ?P) ?pP = (target q1 p1, target q2 p2)\\<close>\n          unfolding canonical_separator_simps[OF assms(3,4)] product_simps from_FSM_simps[OF assms(3)] from_FSM_simps[OF assms(4)] by force\n        \n        have \"p_io ?pC = io\"\n          using \\<open>p_io ?pP = io\\<close> by auto\n        have \"p_io pA = p_io ?pC\"\n          unfolding \\<open>p_io ?pC = io\\<close>\n          using \\<open>p_io pA = io\\<close> by assumption\n  \n        then have \"?pC = pA\"\n          using observable_path_unique[OF \\<open>observable ?C\\<close> \\<open>path ?C (initial ?C) pA\\<close> \\<open>path ?C (initial ?C) ?pC\\<close>] by auto\n        then have \"t_source ?tA = target (initial A) pA\"\n          using \\<open>target (initial ?C) ?pC = Inl (target q1 p1, target q2 p2)\\<close>\n          unfolding is_state_separator_from_canonical_separator_initial[OF assms(1,3,4)]\n                    canonical_separator_simps[OF assms(3,4)] by force\n\n        have \"?q \\<in> reachable_nodes A\"\n          using \\<open>path A (initial A) pA\\<close> reachable_nodes_intro by blast\n        have \"?tA \\<in> transitions A\"\n          using compl[OF \\<open>?q \\<in> reachable_nodes A\\<close> \\<open>x \\<in> (inputs M)\\<close> \\<open>\\<exists>t\\<in>(transitions A). t_source t = target (initial A) pA \\<and> t_input t = x\\<close> \\<open>?tA \\<in> transitions ?C\\<close> \\<open>t_source ?tA = target (initial A) pA\\<close> ]\n          unfolding snd_conv fst_conv by simp\n\n        have *: \"path A (initial A) (pA@[?tA])\"\n          using path_append_transition[OF \\<open>path A (initial A) pA\\<close> \\<open>?tA \\<in> transitions A\\<close>  \\<open>t_source ?tA = target (initial A) pA\\<close>] by assumption\n\n        have **: \"p_io (pA@[?tA]) = io@[(x,yq)]\"\n          using \\<open>p_io pA = io\\<close> by auto\n\n        show ?thesis \n          using language_state_containment[OF * **] by assumption\n      qed\n    qed\n\n\n    ultimately show \"(io \\<in> LS M q1 - LS M q2 \\<longrightarrow> io_targets A io (initial A) = {Inr q1}) \\<and>\n        (io \\<in> LS M q2 - LS M q1 \\<longrightarrow> io_targets A io (initial A) = {Inr q2}) \\<and>\n        (io \\<in> LS M q1 \\<inter> LS M q2 \\<longrightarrow> io_targets A io (initial A) \\<inter> {Inr q1, Inr q2} = {}) \\<and>\n        (\\<forall>x yq yt. io @ [(x, yq)] \\<in> LS M q1 \\<and> io @ [(x, yt)] \\<in> LS A (initial A) \\<longrightarrow> io @ [(x, yq)] \\<in> LS A (initial A)) \\<and>\n        (\\<forall>x yq2 yt. io @ [(x, yq2)] \\<in> LS M q2 \\<and> io @ [(x, yt)] \\<in> LS A (initial A) \\<longrightarrow> io @ [(x, yq2)] \\<in> LS A (initial A))\" \n      by blast \n  qed\n\n  moreover have \"\\<And> p . path A (initial A) p \\<Longrightarrow> target (initial A) p = Inr q1 \\<Longrightarrow> p_io p \\<in> LS M q1 - LS M q2\"\n    using canonical_separator_maximal_path_distinguishes_left[OF assms(1) _ _ \\<open>observable M\\<close> \\<open>q1 \\<in> nodes M\\<close> \\<open>q2 \\<in> nodes M\\<close> \\<open>q1 \\<noteq> q2\\<close>] by blast\n  moreover have \"\\<And> p . path A (initial A) p \\<Longrightarrow> target (initial A) p = Inr q2 \\<Longrightarrow> p_io p \\<in> LS M q2 - LS M q1\"\n    using canonical_separator_maximal_path_distinguishes_right[OF assms(1) _ _ \\<open>observable M\\<close> \\<open>q1 \\<in> nodes M\\<close> \\<open>q2 \\<in> nodes M\\<close> \\<open>q1 \\<noteq> q2\\<close>] by blast\n  moreover have \"\\<And> p . path A (initial A) p \\<Longrightarrow> target (initial A) p \\<noteq> Inr q1 \\<Longrightarrow> target (initial A) p \\<noteq> Inr q2 \\<Longrightarrow> p_io p \\<in> LS M q1 \\<inter> LS M q2\"\n  proof -\n    fix p assume \"path A (initial A) p\" and \"target (initial A) p \\<noteq> Inr q1\" and \"target (initial A) p \\<noteq> Inr q2\"\n\n    have \"path ?C (initial ?C) p\"\n      using submachine_path_initial[OF is_state_separator_from_canonical_separator_simps(1)[OF assms(1)] \\<open>path A (initial A) p\\<close>] by assumption\n\n    have \"target (initial ?C) p \\<noteq> Inr q1\" and \"target (initial ?C) p \\<noteq> Inr q2\"\n      using \\<open>target (initial A) p \\<noteq> Inr q1\\<close> \\<open>target (initial A) p \\<noteq> Inr q2\\<close>\n      unfolding is_state_separator_from_canonical_separator_initial[OF assms(1,3,4)] canonical_separator_initial[OF assms(3,4)] by blast+\n\n    then have \"isl (target (initial ?C) p)\"\n      using canonical_separator_path_initial(4)[OF \\<open>path ?C (initial ?C) p\\<close> \\<open>q1 \\<in> nodes M\\<close> \\<open>q2 \\<in> nodes M\\<close> \\<open>observable M\\<close> \\<open>q1 \\<noteq> q2\\<close>]\n      by auto \n\n    then show \"p_io p \\<in> LS M q1 \\<inter> LS M q2\"\n      using \\<open>path ?C (initial ?C) p\\<close> canonical_separator_path_targets_language(1)[OF _ \\<open>observable M\\<close> \\<open>q1 \\<in> nodes M\\<close> \\<open>q2 \\<in> nodes M\\<close> \\<open>q1 \\<noteq> q2\\<close>] \n      by auto\n  qed\n\n  moreover have \"(inputs A) \\<subseteq> (inputs M)\"\n    using \\<open>is_submachine A ?C\\<close>\n    unfolding is_submachine.simps canonical_separator_simps[OF assms(3,4)] by auto\n\n  ultimately show ?thesis\n    unfolding is_separator_def\n    using p1 p2 p3 p4 p5 p6 p7 p8 \\<open>q1 \\<noteq> q2\\<close>\n    by (meson sum.simps(2))\nqed\n\n  \nlemma is_separator_separated_node_is_node :\n  assumes \"is_separator M q1 q2 A t1 t2\"\n  shows \"q1 \\<in> nodes M\" and \"q2 \\<in> nodes M\"\nproof -\n  have \"initial A \\<noteq> t1\"\n    using separator_initial[OF assms(1)] by blast\n\n  have \"t1 \\<in> reachable_nodes A\"\n  and  \"\\<And> p . path A (FSM.initial A) p \\<Longrightarrow> target (FSM.initial A) p = t1 \\<Longrightarrow> p_io p \\<in> LS M q1 - LS M q2\"\n  and  \"t2 \\<in> reachable_nodes A\"\n  and  \"\\<And> p . path A (FSM.initial A) p \\<Longrightarrow> target (FSM.initial A) p = t2 \\<Longrightarrow> p_io p \\<in> LS M q2 - LS M q1\"\n    using is_separator_simps[OF assms(1)] \n    by blast+\n\n  obtain p1 where \"path A (FSM.initial A) p1\" and \"target (FSM.initial A) p1 = t1\"\n    using \\<open>t1 \\<in> reachable_nodes A\\<close> unfolding reachable_nodes_def by auto\n  then have \"p_io p1 \\<in> LS M q1 - LS M q2\"\n    using \\<open>\\<And> p . path A (FSM.initial A) p \\<Longrightarrow> target (FSM.initial A) p = t1 \\<Longrightarrow> p_io p \\<in> LS M q1 - LS M q2\\<close> \n    by blast\n  then show \"q1 \\<in> nodes M\" unfolding LS.simps\n    using path_begin_node by fastforce \n\n  obtain p2 where \"path A (FSM.initial A) p2\" and \"target (FSM.initial A) p2 = t2\"\n    using \\<open>t2 \\<in> reachable_nodes A\\<close> unfolding reachable_nodes_def by auto\n  then have \"p_io p2 \\<in> LS M q2 - LS M q1\"\n    using \\<open>\\<And> p . path A (FSM.initial A) p \\<Longrightarrow> target (FSM.initial A) p = t2 \\<Longrightarrow> p_io p \\<in> LS M q2 - LS M q1\\<close> \n    by blast\n  then show \"q2 \\<in> nodes M\" unfolding LS.simps\n    using path_begin_node by fastforce \nqed\n\nend", "meta": {"author": "RobertSachtleben", "repo": "Refined-Adaptive-State-Counting", "sha": "3691de6f16cec5ec74282465495c12e6a40133aa", "save_path": "github-repos/isabelle/RobertSachtleben-Refined-Adaptive-State-Counting", "path": "github-repos/isabelle/RobertSachtleben-Refined-Adaptive-State-Counting/Refined-Adaptive-State-Counting-3691de6f16cec5ec74282465495c12e6a40133aa/Experiments/State_Separator.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5156199306096343, "lm_q2_score": 0.5660185351961015, "lm_q1q2_score": 0.29185043784158066}}
{"text": "(*   This file is a part of IsarMathLib - \n    a library of formalized mathematics for Isabelle/Isar.\n\n    Copyright (C) 2005-2020  Slawomir Kolodynski\n\n    This program is free software; Redistribution and use in source and binary forms, \n    with or without modification, are permitted provided that the following conditions are met:\n\n   1. Redistributions of source code must retain the above copyright notice, \n   this list of conditions and the following disclaimer.\n   2. Redistributions in binary form must reproduce the above copyright notice, \n   this list of conditions and the following disclaimer in the documentation and/or \n   other materials provided with the distribution.\n   3. The name of the author may not be used to endorse or promote products \n   derived from this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED \nWARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF \nMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \nIN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, \nPROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; \nOR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, \nWHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR \nOTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, \nEVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n*)\n\nsection \\<open>Even more on order relations\\<close>\n\ntheory Order_ZF_1a imports Order_ZF\n\nbegin\n\ntext\\<open>This theory is a continuation of \\<open>Order_ZF\\<close> and talks\n  about maximuma and minimum of a set, supremum and infimum\n  and strict (not reflexive) versions of order relations.\\<close>\n\nsubsection\\<open>Maximum and minimum of a set\\<close>\n\ntext\\<open>In this section we show that maximum and minimum are unique if they \n  exist. We also show that union of sets that have maxima (minima) has a \n  maximum (minimum). We also show that singletons have maximum and minimum.\n  All this allows to show (in \\<open>Finite_ZF\\<close>) that every finite set has \n  well-defined maximum and minimum.\\<close>\n\ntext\\<open>A somewhat technical fact that allows to reduce the number of premises in some\n  theorems: the assumption that a set has a maximum implies that it is not empty. \\<close>\n\nlemma set_max_not_empty: assumes \"HasAmaximum(r,A)\" shows \"A\\<noteq>0\"\n  using assms unfolding HasAmaximum_def by auto\n\ntext\\<open>If a set has a maximum implies that it is not empty. \\<close>\n\nlemma set_min_not_empty: assumes \"HasAminimum(r,A)\" shows \"A\\<noteq>0\"\n  using assms unfolding HasAminimum_def by auto\n\ntext\\<open>If a set has a supremum then it cannot be empty. We are probably using the fact that \n  $\\bigcap  \\emptyset = \\emptyset $, which makes me a bit anxious \n  as this I think is just a convention. \\<close>\n\nlemma set_sup_not_empty: assumes \"HasAsupremum(r,A)\" shows \"A\\<noteq>0\"\nproof -\n  from assms have \"HasAminimum(r,\\<Inter>a\\<in>A. r``{a})\" unfolding HasAsupremum_def\n    by simp \n  then have \"(\\<Inter>a\\<in>A. r``{a}) \\<noteq> 0\" using set_min_not_empty by simp\n  then obtain x where \"x \\<in> (\\<Inter>y\\<in>A. r``{y})\" by blast\n  thus ?thesis by auto\nqed\n\ntext\\<open>If a set has an infimum then it cannot be empty.  \\<close>\n\nlemma set_inf_not_empty: assumes \"HasAnInfimum(r,A)\" shows \"A\\<noteq>0\"\nproof -\n  from assms have \"HasAmaximum(r,\\<Inter>a\\<in>A. r-``{a})\" unfolding HasAnInfimum_def\n    by simp \n  then have \"(\\<Inter>a\\<in>A. r-``{a}) \\<noteq> 0\" using set_max_not_empty by simp\n  then obtain x where \"x \\<in> (\\<Inter>y\\<in>A. r-``{y})\" by blast\n  thus ?thesis by auto\nqed\n  \ntext\\<open>For antisymmetric relations maximum of a set is unique if it exists.\\<close>\n\nlemma Order_ZF_4_L1: assumes A1: \"antisym(r)\" and A2: \"HasAmaximum(r,A)\"\n  shows \"\\<exists>!M. M\\<in>A \\<and> (\\<forall>x\\<in>A. \\<langle> x,M\\<rangle> \\<in> r)\"\nproof\n  from A2 show \"\\<exists>M. M \\<in> A \\<and> (\\<forall>x\\<in>A. \\<langle>x, M\\<rangle> \\<in> r)\"\n    using HasAmaximum_def by auto\n  fix M1 M2 assume \n    A2: \"M1 \\<in> A \\<and> (\\<forall>x\\<in>A. \\<langle>x, M1\\<rangle> \\<in> r)\" \"M2 \\<in> A \\<and> (\\<forall>x\\<in>A. \\<langle>x, M2\\<rangle> \\<in> r)\"\n    then have \"\\<langle>M1,M2\\<rangle> \\<in> r\" \"\\<langle>M2,M1\\<rangle> \\<in> r\" by auto\n    with A1 show \"M1=M2\" by (rule Fol1_L4)\nqed\n\ntext\\<open>For antisymmetric relations minimum of a set is unique if it exists.\\<close>\n\nlemma Order_ZF_4_L2: assumes A1: \"antisym(r)\" and A2: \"HasAminimum(r,A)\"\n  shows \"\\<exists>!m. m\\<in>A \\<and> (\\<forall>x\\<in>A. \\<langle> m,x\\<rangle> \\<in> r)\"\nproof\n  from A2 show \"\\<exists>m. m \\<in> A \\<and> (\\<forall>x\\<in>A. \\<langle>m, x\\<rangle> \\<in> r)\"\n    using HasAminimum_def by auto\n  fix m1 m2 assume \n    A2: \"m1 \\<in> A \\<and> (\\<forall>x\\<in>A. \\<langle>m1, x\\<rangle> \\<in> r)\" \"m2 \\<in> A \\<and> (\\<forall>x\\<in>A. \\<langle>m2, x\\<rangle> \\<in> r)\"\n    then have \"\\<langle>m1,m2\\<rangle> \\<in> r\" \"\\<langle>m2,m1\\<rangle> \\<in> r\" by auto\n    with A1 show \"m1=m2\" by (rule Fol1_L4)\nqed\n\ntext\\<open>Maximum of a set has desired properties.\\<close>\n\nlemma Order_ZF_4_L3: assumes A1: \"antisym(r)\" and A2: \"HasAmaximum(r,A)\"\n  shows \"Maximum(r,A) \\<in> A\" \"\\<forall>x\\<in>A. \\<langle>x,Maximum(r,A)\\<rangle> \\<in> r\"\nproof - \n  let ?Max = \"THE M. M\\<in>A \\<and> (\\<forall>x\\<in>A. \\<langle> x,M\\<rangle> \\<in> r)\" \n  from A1 A2 have \"\\<exists>!M. M\\<in>A \\<and> (\\<forall>x\\<in>A. \\<langle> x,M\\<rangle> \\<in> r)\"\n    by (rule Order_ZF_4_L1)\n  then have \"?Max \\<in> A \\<and> (\\<forall>x\\<in>A. \\<langle> x,?Max\\<rangle> \\<in> r)\"\n    by (rule theI)\n  then show \"Maximum(r,A) \\<in> A\" \"\\<forall>x\\<in>A. \\<langle>x,Maximum(r,A)\\<rangle> \\<in> r\"\n    using Maximum_def by auto\nqed\n  \ntext\\<open>Minimum of a set has desired properties.\\<close>\n    \nlemma Order_ZF_4_L4: assumes A1: \"antisym(r)\" and A2: \"HasAminimum(r,A)\"\n  shows \"Minimum(r,A) \\<in> A\" \"\\<forall>x\\<in>A. \\<langle>Minimum(r,A),x\\<rangle> \\<in> r\"\nproof - \n  let ?Min = \"THE m. m\\<in>A \\<and> (\\<forall>x\\<in>A. \\<langle> m,x\\<rangle> \\<in> r)\" \n  from A1 A2 have \"\\<exists>!m. m\\<in>A \\<and> (\\<forall>x\\<in>A. \\<langle> m,x\\<rangle> \\<in> r)\"\n    by (rule Order_ZF_4_L2)\n  then have \"?Min \\<in> A \\<and> (\\<forall>x\\<in>A. \\<langle> ?Min,x\\<rangle> \\<in> r)\"\n    by (rule theI)\n  then show \"Minimum(r,A) \\<in> A\" \"\\<forall>x\\<in>A. \\<langle>Minimum(r,A),x\\<rangle> \\<in> r\"\n    using Minimum_def by auto\nqed\n\ntext\\<open>For total and transitive relations a union a of two sets that have \n  maxima has a maximum.\\<close>\n\nlemma Order_ZF_4_L5: \n  assumes A1: \"r {is total on} (A\\<union>B)\" and A2: \"trans(r)\"\n  and A3: \"HasAmaximum(r,A)\" \"HasAmaximum(r,B)\"\n  shows \"HasAmaximum(r,A\\<union>B)\"\nproof -\n  from A3 obtain M K where \n    D1: \"M\\<in>A \\<and> (\\<forall>x\\<in>A. \\<langle> x,M\\<rangle> \\<in> r)\" \"K\\<in>B \\<and> (\\<forall>x\\<in>B. \\<langle> x,K\\<rangle> \\<in> r)\" \n    using HasAmaximum_def by auto\n  let ?L = \"GreaterOf(r,M,K)\"\n  from D1 have T1: \"M \\<in> A\\<union>B\" \"K \\<in> A\\<union>B\" \n    \"\\<forall>x\\<in>A. \\<langle> x,M\\<rangle> \\<in> r\" \"\\<forall>x\\<in>B. \\<langle> x,K\\<rangle> \\<in> r\"\n    by auto\n  with A1 A2 have \"\\<forall>x\\<in>A\\<union>B.\\<langle> x,?L\\<rangle> \\<in> r\" by (rule Order_ZF_3_L2B)\n  moreover from T1 have \"?L \\<in> A\\<union>B\" using GreaterOf_def IsTotal_def \n    by simp\n  ultimately show \"HasAmaximum(r,A\\<union>B)\" using HasAmaximum_def by auto\nqed\n\ntext\\<open>For total and transitive relations A union a of two sets that have \n  minima has a minimum.\\<close>\n\nlemma Order_ZF_4_L6: \n  assumes A1: \"r {is total on} (A\\<union>B)\" and A2: \"trans(r)\"\n  and A3: \"HasAminimum(r,A)\" \"HasAminimum(r,B)\"\n  shows \"HasAminimum(r,A\\<union>B)\"\nproof -\n  from A3 obtain m k where \n    D1: \"m\\<in>A \\<and> (\\<forall>x\\<in>A. \\<langle> m,x\\<rangle> \\<in> r)\" \"k\\<in>B \\<and> (\\<forall>x\\<in>B. \\<langle> k,x\\<rangle> \\<in> r)\" \n    using HasAminimum_def by auto\n  let ?l = \"SmallerOf(r,m,k)\"\n  from D1 have T1: \"m \\<in> A\\<union>B\" \"k \\<in> A\\<union>B\" \n    \"\\<forall>x\\<in>A. \\<langle> m,x\\<rangle> \\<in> r\" \"\\<forall>x\\<in>B. \\<langle> k,x\\<rangle> \\<in> r\"\n    by auto\n  with A1 A2 have \"\\<forall>x\\<in>A\\<union>B.\\<langle> ?l,x\\<rangle> \\<in> r\" by (rule Order_ZF_3_L5B)\n  moreover from T1 have \"?l \\<in> A\\<union>B\" using SmallerOf_def IsTotal_def \n    by simp\n  ultimately show \"HasAminimum(r,A\\<union>B)\" using HasAminimum_def by auto\nqed\n\ntext\\<open>Set that has a maximum is bounded above.\\<close>\n\nlemma Order_ZF_4_L7:\n  assumes \"HasAmaximum(r,A)\"\n  shows \"IsBoundedAbove(A,r)\"\n  using assms HasAmaximum_def IsBoundedAbove_def by auto\n\ntext\\<open>Set that has a minimum is bounded below.\\<close>\n\nlemma Order_ZF_4_L8A:\n  assumes \"HasAminimum(r,A)\"\n  shows \"IsBoundedBelow(A,r)\"\n  using assms HasAminimum_def IsBoundedBelow_def by auto\n\ntext\\<open>For reflexive relations singletons have a minimum and maximum.\\<close>\n\nlemma Order_ZF_4_L8: assumes \"refl(X,r)\" and \"a\\<in>X\"\n  shows \"HasAmaximum(r,{a})\" \"HasAminimum(r,{a})\"\n  using assms refl_def HasAmaximum_def HasAminimum_def by auto\n\ntext\\<open>For total and transitive relations if we add an element to a set \n  that has a maximum, the set still has a maximum.\\<close>\n\nlemma Order_ZF_4_L9: \n  assumes A1: \"r {is total on} X\" and A2: \"trans(r)\"\n  and A3: \"A\\<subseteq>X\" and A4: \"a\\<in>X\" and A5: \"HasAmaximum(r,A)\"\n  shows \"HasAmaximum(r,A\\<union>{a})\"\nproof -\n  from A3 A4 have \"A\\<union>{a} \\<subseteq> X\" by auto\n  with A1 have \"r {is total on} (A\\<union>{a})\"\n    using Order_ZF_1_L4 by blast\n  moreover from A1 A2 A4 A5 have\n    \"trans(r)\" \"HasAmaximum(r,A)\" by auto\n  moreover from A1 A4 have \"HasAmaximum(r,{a})\"\n    using total_is_refl Order_ZF_4_L8 by blast\n  ultimately show \"HasAmaximum(r,A\\<union>{a})\" by (rule Order_ZF_4_L5)\nqed\n\ntext\\<open>For total and transitive relations if we add an element to a set \n  that has a minimum, the set still has a minimum.\\<close>\n\nlemma Order_ZF_4_L10: \n  assumes A1: \"r {is total on} X\" and A2: \"trans(r)\"\n  and A3: \"A\\<subseteq>X\" and A4: \"a\\<in>X\" and A5: \"HasAminimum(r,A)\"\n  shows \"HasAminimum(r,A\\<union>{a})\"\nproof -\n  from A3 A4 have \"A\\<union>{a} \\<subseteq> X\" by auto\n  with A1 have \"r {is total on} (A\\<union>{a})\"\n    using Order_ZF_1_L4 by blast\n  moreover from A1 A2 A4 A5 have\n    \"trans(r)\" \"HasAminimum(r,A)\" by auto\n  moreover from A1 A4 have \"HasAminimum(r,{a})\"\n    using total_is_refl Order_ZF_4_L8 by blast\n  ultimately show \"HasAminimum(r,A\\<union>{a})\" by (rule Order_ZF_4_L6)\nqed\n\ntext\\<open>If the order relation has a property that every nonempty bounded set \n  attains a minimum (for example integers are like that), \n  then every nonempty set bounded below attains a minimum.\\<close>\n\nlemma Order_ZF_4_L11: \n  assumes A1: \"r {is total on} X\" and \n  A2: \"trans(r)\" and \n  A3: \"r \\<subseteq> X\\<times>X\" and\n  A4: \"\\<forall>A. IsBounded(A,r) \\<and> A\\<noteq>0 \\<longrightarrow> HasAminimum(r,A)\" and \n  A5: \"B\\<noteq>0\" and A6: \"IsBoundedBelow(B,r)\"\n  shows \"HasAminimum(r,B)\"\nproof -\n  from A5 obtain b where T: \"b\\<in>B\" by auto\n  let ?L = \"{x\\<in>B. \\<langle>x,b\\<rangle> \\<in> r}\"\n  from A3 A6 T have T1: \"b\\<in>X\" using Order_ZF_3_L1B by blast\n  with A1 T have T2: \"b \\<in> ?L\"\n    using total_is_refl refl_def by simp\n  then have \"?L \\<noteq> 0\" by auto\n  moreover have \"IsBounded(?L,r)\"\n  proof -\n    have \"?L \\<subseteq> B\" by auto\n    with A6 have \"IsBoundedBelow(?L,r)\"\n      using Order_ZF_3_L12 by simp\n    moreover have \"IsBoundedAbove(?L,r)\"\n      by (rule Order_ZF_3_L15)\n    ultimately have \"IsBoundedAbove(?L,r) \\<and> IsBoundedBelow(?L,r)\"\n      by blast\n    then show \"IsBounded(?L,r)\" using IsBounded_def\n      by simp\n  qed\n  ultimately have \"IsBounded(?L,r) \\<and> ?L \\<noteq> 0\" by blast\n  with A4 have \"HasAminimum(r,?L)\" by simp\n  then obtain m where I: \"m\\<in>?L\" and II: \"\\<forall>x\\<in>?L. \\<langle> m,x\\<rangle> \\<in> r\" \n    using HasAminimum_def by auto\n  then have III: \"\\<langle>m,b\\<rangle> \\<in> r\" by simp\n  from I have \"m\\<in>B\" by simp\n  moreover have \"\\<forall>x\\<in>B. \\<langle>m,x\\<rangle> \\<in> r\"\n  proof\n    fix x assume A7: \"x\\<in>B\"\n    from A3 A6 have \"B\\<subseteq>X\" using Order_ZF_3_L1B by blast\n    with A1 A7 T1 have \"x \\<in>  ?L \\<union> {x\\<in>B. \\<langle>b,x\\<rangle> \\<in> r}\"\n      using Order_ZF_1_L5 by simp\n    then have \"x\\<in>?L \\<or> \\<langle>b,x\\<rangle> \\<in> r\" by auto\n    moreover\n    { assume \"x\\<in>?L\"\n      with II have \"\\<langle>m,x\\<rangle> \\<in> r\" by simp }\n    moreover\n    { assume \"\\<langle>b,x\\<rangle> \\<in> r\"\n      with A2 III have \"trans(r)\" and \"\\<langle>m,b\\<rangle> \\<in> r \\<and> \\<langle>b,x\\<rangle> \\<in> r\"\n\tby auto\n      then have  \"\\<langle>m,x\\<rangle> \\<in> r\" by (rule Fol1_L3) }\n    ultimately show \"\\<langle>m,x\\<rangle> \\<in> r\" by auto\n  qed\n  ultimately show \"HasAminimum(r,B)\" using HasAminimum_def\n    by auto\nqed\n\ntext\\<open>A dual to \\<open>Order_ZF_4_L11\\<close>: \n  If the order relation has a property that every nonempty bounded set \n  attains a maximum (for example integers are like that), \n  then every nonempty set bounded above attains a maximum.\\<close>\n\nlemma Order_ZF_4_L11A: \n  assumes A1: \"r {is total on} X\" and \n  A2: \"trans(r)\" and \n  A3: \"r \\<subseteq> X\\<times>X\" and\n  A4: \"\\<forall>A. IsBounded(A,r) \\<and> A\\<noteq>0 \\<longrightarrow> HasAmaximum(r,A)\" and \n  A5: \"B\\<noteq>0\" and A6: \"IsBoundedAbove(B,r)\"\n  shows \"HasAmaximum(r,B)\"\nproof -\n  from A5 obtain b where T: \"b\\<in>B\" by auto\n  let ?U = \"{x\\<in>B. \\<langle>b,x\\<rangle> \\<in> r}\"\n  from A3 A6 T have T1: \"b\\<in>X\" using Order_ZF_3_L1A by blast\n  with A1 T have T2: \"b \\<in> ?U\"\n    using total_is_refl refl_def by simp\n  then have \"?U \\<noteq> 0\" by auto\n  moreover have \"IsBounded(?U,r)\"\n  proof -\n    have \"?U \\<subseteq> B\" by auto\n    with A6 have \"IsBoundedAbove(?U,r)\"\n      using Order_ZF_3_L13 by blast\n    moreover have \"IsBoundedBelow(?U,r)\"\n      using IsBoundedBelow_def by auto\n    ultimately have \"IsBoundedAbove(?U,r) \\<and> IsBoundedBelow(?U,r)\"\n      by blast\n    then show \"IsBounded(?U,r)\" using IsBounded_def\n      by simp\n  qed\n  ultimately have \"IsBounded(?U,r) \\<and> ?U \\<noteq> 0\" by blast\n  with A4 have \"HasAmaximum(r,?U)\" by simp\n  then obtain m where I: \"m\\<in>?U\" and II: \"\\<forall>x\\<in>?U. \\<langle>x,m\\<rangle> \\<in> r\"\n    using HasAmaximum_def by auto\n  then have III: \"\\<langle>b,m\\<rangle> \\<in> r\" by simp\n  from I have \"m\\<in>B\" by simp\n  moreover have \"\\<forall>x\\<in>B. \\<langle>x,m\\<rangle> \\<in> r\"\n  proof\n    fix x assume A7: \"x\\<in>B\"\n    from A3 A6 have \"B\\<subseteq>X\" using Order_ZF_3_L1A by blast\n    with A1 A7 T1 have \"x \\<in> {x\\<in>B. \\<langle>x,b\\<rangle> \\<in> r} \\<union> ?U\"\n      using Order_ZF_1_L5 by simp\n    then have \"x\\<in>?U \\<or> \\<langle>x,b\\<rangle> \\<in> r\" by auto\n    moreover\n    { assume \"x\\<in>?U\"\n      with II have \"\\<langle>x,m\\<rangle> \\<in> r\" by simp }\n    moreover\n    { assume \"\\<langle>x,b\\<rangle> \\<in> r\"\n      with A2 III have \"trans(r)\" and \"\\<langle>x,b\\<rangle> \\<in> r \\<and> \\<langle>b,m\\<rangle> \\<in> r\"\n\tby auto\n      then have  \"\\<langle>x,m\\<rangle> \\<in> r\" by (rule Fol1_L3) }\n    ultimately show \"\\<langle>x,m\\<rangle> \\<in> r\" by auto\n  qed\n  ultimately show \"HasAmaximum(r,B)\" using HasAmaximum_def\n    by auto\nqed\n\ntext\\<open>If a set has a minimum and $L$ is less or equal than \n  all elements of the set, then $L$ is less or equal than the minimum.\\<close>\n\nlemma Order_ZF_4_L12: \n  assumes \"antisym(r)\" and \"HasAminimum(r,A)\" and \"\\<forall>a\\<in>A. \\<langle>L,a\\<rangle> \\<in> r\"\n  shows \"\\<langle>L,Minimum(r,A)\\<rangle> \\<in> r\"\n  using assms Order_ZF_4_L4 by simp\n\n\ntext\\<open>If a set has a maximum and all its elements are less or equal than \n  $M$, then the maximum of the set is less or equal than $M$.\\<close>\n\nlemma Order_ZF_4_L13: \n  assumes \"antisym(r)\" and \"HasAmaximum(r,A)\" and \"\\<forall>a\\<in>A. \\<langle>a,M\\<rangle> \\<in> r\"\n  shows \"\\<langle>Maximum(r,A),M\\<rangle> \\<in> r\"\n  using assms Order_ZF_4_L3 by simp\n\ntext\\<open>If an element belongs to a set and is greater or equal\n  than all elements of that set, then it is the maximum of that set.\\<close>\n\nlemma Order_ZF_4_L14: \n  assumes A1: \"antisym(r)\" and A2: \"M \\<in> A\" and \n  A3: \"\\<forall>a\\<in>A. \\<langle>a,M\\<rangle> \\<in> r\"\n  shows \"Maximum(r,A) = M\"\nproof -\n  from A2 A3 have I: \"HasAmaximum(r,A)\" using HasAmaximum_def\n    by auto\n  with A1 have \"\\<exists>!M. M\\<in>A \\<and> (\\<forall>x\\<in>A. \\<langle>x,M\\<rangle> \\<in> r)\"\n    using Order_ZF_4_L1 by simp\n  moreover from A2 A3 have \"M\\<in>A \\<and> (\\<forall>x\\<in>A. \\<langle>x,M\\<rangle> \\<in> r)\" by simp\n  moreover from A1 I have \n    \"Maximum(r,A) \\<in> A \\<and> (\\<forall>x\\<in>A. \\<langle>x,Maximum(r,A)\\<rangle> \\<in> r)\"\n    using Order_ZF_4_L3 by simp\n  ultimately show \"Maximum(r,A) = M\" by auto\nqed\n\ntext\\<open>If an element belongs to a set and is less or equal\n  than all elements of that set, then it is the minimum of that set.\\<close>\n\nlemma Order_ZF_4_L15: \n  assumes A1: \"antisym(r)\" and A2: \"m \\<in> A\" and \n  A3: \"\\<forall>a\\<in>A. \\<langle>m,a\\<rangle> \\<in> r\"\n  shows \"Minimum(r,A) = m\"\nproof -\n  from A2 A3 have I: \"HasAminimum(r,A)\" using HasAminimum_def\n    by auto\n  with A1 have \"\\<exists>!m. m\\<in>A \\<and> (\\<forall>x\\<in>A. \\<langle>m,x\\<rangle> \\<in> r)\"\n    using Order_ZF_4_L2 by simp\n  moreover from A2 A3 have \"m\\<in>A \\<and> (\\<forall>x\\<in>A. \\<langle>m,x\\<rangle> \\<in> r)\" by simp\n  moreover from A1 I have \n    \"Minimum(r,A) \\<in> A \\<and> (\\<forall>x\\<in>A. \\<langle>Minimum(r,A),x\\<rangle> \\<in> r)\"\n    using Order_ZF_4_L4 by simp\n  ultimately show \"Minimum(r,A) = m\" by auto\nqed\n\ntext\\<open>If a set does not have a maximum, then for any its element we can\n  find one that is (strictly) greater.\\<close>\n\nlemma Order_ZF_4_L16: \n  assumes A1: \"antisym(r)\" and A2: \"r {is total on} X\" and \n  A3: \"A\\<subseteq>X\" and\n  A4: \"\\<not>HasAmaximum(r,A)\" and \n  A5: \"x\\<in>A\"\n  shows \"\\<exists>y\\<in>A. \\<langle>x,y\\<rangle> \\<in> r \\<and> y\\<noteq>x\"\nproof -\n  { assume A6: \"\\<forall>y\\<in>A. \\<langle>x,y\\<rangle> \\<notin> r \\<or> y=x\"\n    have \"\\<forall>y\\<in>A. \\<langle>y,x\\<rangle> \\<in> r\"\n    proof\n      fix y assume A7: \"y\\<in>A\"\n      with A6 have \"\\<langle>x,y\\<rangle> \\<notin> r \\<or> y=x\" by simp\n      with A2 A3 A5 A7 show \"\\<langle>y,x\\<rangle> \\<in> r\"\n\tusing IsTotal_def Order_ZF_1_L1 by auto\n    qed\n    with A5 have \"\\<exists>x\\<in>A.\\<forall>y\\<in>A. \\<langle>y,x\\<rangle> \\<in> r\"\n      by auto\n    with A4 have False using HasAmaximum_def by simp\n  } then show \"\\<exists>y\\<in>A. \\<langle>x,y\\<rangle> \\<in> r \\<and> y\\<noteq>x\" by auto\nqed\n\n\nsubsection\\<open>Supremum and Infimum\\<close>\n\ntext\\<open>In this section we consider the notions of supremum and infimum a set.\\<close>\n\ntext\\<open>Elements of the set of upper bounds are indeed upper bounds.\n  Isabelle also thinks it is obvious.\\<close>\n\nlemma Order_ZF_5_L1: assumes \"u \\<in> (\\<Inter>a\\<in>A. r``{a})\" and \"a\\<in>A\"\n  shows \"\\<langle>a,u\\<rangle> \\<in> r\"\n  using assms by auto\n\ntext\\<open>Elements of the set of lower bounds are indeed lower bounds.\n  Isabelle also thinks it is obvious.\\<close>\n  \nlemma Order_ZF_5_L2: assumes \"l \\<in> (\\<Inter>a\\<in>A. r-``{a})\" and \"a\\<in>A\"\n  shows \"\\<langle>l,a\\<rangle> \\<in> r\"\n  using assms by auto\n\ntext\\<open>If the set of upper bounds has a minimum, then the supremum \n  is less or equal than any upper bound. We can probably do away with\n  the assumption that $A$ is not empty, (ab)using the fact that \n  intersection over an empty family is defined in Isabelle to be empty.\n  This lemma is obsolete and will be removed in the future. Use \\<open>sup_leq_up_bnd\\<close> instead.\\<close>\n\nlemma Order_ZF_5_L3: assumes A1: \"antisym(r)\" and A2: \"A\\<noteq>0\" and\n  A3: \"HasAminimum(r,\\<Inter>a\\<in>A. r``{a})\" and \n  A4: \"\\<forall>a\\<in>A. \\<langle>a,u\\<rangle> \\<in> r\"\n  shows \"\\<langle>Supremum(r,A),u\\<rangle> \\<in> r\"\nproof -\n  let ?U = \"\\<Inter>a\\<in>A. r``{a}\"\n  from A4 have \"\\<forall>a\\<in>A. u \\<in> r``{a}\" using image_singleton_iff\n    by simp\n  with A2 have \"u\\<in>?U\" by auto\n  with A1 A3 show \"\\<langle>Supremum(r,A),u\\<rangle> \\<in> r\"\n    using Order_ZF_4_L4 Supremum_def by simp\nqed\n\ntext\\<open>Supremum is less or equal than any upper bound. \\<close>\n\nlemma sup_leq_up_bnd: assumes \"antisym(r)\" \"HasAsupremum(r,A)\" \"\\<forall>a\\<in>A. \\<langle>a,u\\<rangle> \\<in> r\"\n  shows \"\\<langle>Supremum(r,A),u\\<rangle> \\<in> r\"\nproof -\n  let ?U = \"\\<Inter>a\\<in>A. r``{a}\"\n  from assms(3) have  \"\\<forall>a\\<in>A. u \\<in> r``{a}\" using image_singleton_iff by simp\n  with assms(2) have \"u\\<in>?U\" using set_sup_not_empty by auto\n  with assms(1,2) show \"\\<langle>Supremum(r,A),u\\<rangle> \\<in> r\" \n    unfolding HasAsupremum_def Supremum_def using Order_ZF_4_L4 by simp\nqed\n\ntext\\<open>Infimum is greater or equal than any lower bound. \n  This lemma is obsolete and will be removed. Use \\<open>inf_geq_lo_bnd\\<close> instead.\\<close>\n\nlemma Order_ZF_5_L4: assumes A1: \"antisym(r)\" and A2: \"A\\<noteq>0\" and\n  A3: \"HasAmaximum(r,\\<Inter>a\\<in>A. r-``{a})\" and \n  A4: \"\\<forall>a\\<in>A. \\<langle>l,a\\<rangle> \\<in> r\"\n  shows \"\\<langle>l,Infimum(r,A)\\<rangle> \\<in> r\"\nproof -\n  let ?L = \"\\<Inter>a\\<in>A. r-``{a}\"\n  from A4 have \"\\<forall>a\\<in>A. l \\<in> r-``{a}\" using vimage_singleton_iff\n    by simp\n  with A2 have \"l\\<in>?L\" by auto \n  with A1 A3 show \"\\<langle>l,Infimum(r,A)\\<rangle> \\<in> r\"\n    using Order_ZF_4_L3 Infimum_def by simp\nqed\n\ntext\\<open>Infimum is greater or equal than any upper bound. \\<close>\n\nlemma inf_geq_lo_bnd: assumes \"antisym(r)\" \"HasAnInfimum(r,A)\" \"\\<forall>a\\<in>A. \\<langle>u,a\\<rangle> \\<in> r\"\n  shows \"\\<langle>u,Infimum(r,A)\\<rangle> \\<in> r\"\nproof -\n  let ?U = \"\\<Inter>a\\<in>A. r-``{a}\"\n  from assms(3) have  \"\\<forall>a\\<in>A. u \\<in> r-``{a}\" using vimage_singleton_iff by simp\n  with assms(2) have \"u\\<in>?U\" using set_inf_not_empty by auto\n  with assms(1,2) show  \"\\<langle>u,Infimum(r,A)\\<rangle> \\<in> r\" \n    unfolding HasAnInfimum_def Infimum_def using Order_ZF_4_L3 by simp\nqed\n\ntext\\<open>If $z$ is an upper bound for $A$ and is less or equal than\n  any other upper bound, then $z$ is the supremum of $A$.\\<close>\n\nlemma Order_ZF_5_L5: assumes A1: \"antisym(r)\" and A2: \"A\\<noteq>0\" and\n  A3: \"\\<forall>x\\<in>A. \\<langle>x,z\\<rangle> \\<in> r\" and \n  A4: \"\\<forall>y. (\\<forall>x\\<in>A. \\<langle>x,y\\<rangle> \\<in> r) \\<longrightarrow> \\<langle>z,y\\<rangle> \\<in> r\"\n  shows \n  \"HasAminimum(r,\\<Inter>a\\<in>A. r``{a})\"\n  \"z = Supremum(r,A)\"\nproof -\n  let ?B = \"\\<Inter>a\\<in>A. r``{a}\"\n  from A2 A3 A4 have I: \"z \\<in> ?B\"   \"\\<forall>y\\<in>?B. \\<langle>z,y\\<rangle> \\<in> r\"\n    by auto\n  then show \"HasAminimum(r,\\<Inter>a\\<in>A. r``{a})\"\n    using HasAminimum_def by auto\n  from A1 I show \"z = Supremum(r,A)\"\n    using Order_ZF_4_L15 Supremum_def by simp\nqed\n\ntext\\<open>The dual theorem to \\<open>Order_ZF_5_L5\\<close>: if $z$ is an lower bound for $A$ and is \n  greater or equal than any other lower bound, then $z$ is the infimum of $A$.\\<close>\n\nlemma inf_glb: \n  assumes \"antisym(r)\" \"A\\<noteq>0\" \"\\<forall>x\\<in>A. \\<langle>z,x\\<rangle> \\<in> r\" \"\\<forall>y. (\\<forall>x\\<in>A. \\<langle>y,x\\<rangle> \\<in> r) \\<longrightarrow> \\<langle>y,z\\<rangle> \\<in> r\"\n  shows \n  \"HasAmaximum(r,\\<Inter>a\\<in>A. r-``{a})\"\n  \"z = Infimum(r,A)\"\nproof -\n  let ?B = \"\\<Inter>a\\<in>A. r-``{a}\"\n  from assms(2,3,4) have I: \"z \\<in> ?B\"   \"\\<forall>y\\<in>?B. \\<langle>y,z\\<rangle> \\<in> r\"\n    by auto\n  then show \"HasAmaximum(r,\\<Inter>a\\<in>A. r-``{a})\"\n    unfolding HasAmaximum_def by auto\n  from assms(1) I show \"z = Infimum(r,A)\"\n    using Order_ZF_4_L14 Infimum_def by simp\nqed\n\ntext\\<open> Supremum and infimum of a singleton is the element. \\<close>\n\nlemma sup_inf_singl: assumes \"antisym(r)\" \"refl(X,r)\" \"z\\<in>X\"\n  shows \n    \"HasAsupremum(r,{z})\" \"Supremum(r,{z}) = z\" and \n    \"HasAnInfimum(r,{z})\" \"Infimum(r,{z}) = z\"\nproof -\n  from assms show \"Supremum(r,{z}) = z\" and \"Infimum(r,{z}) = z\" \n    using inf_glb Order_ZF_5_L5 unfolding refl_def by auto\n  from assms show  \"HasAsupremum(r,{z})\" \n    using Order_ZF_5_L5 unfolding HasAsupremum_def refl_def by blast\n  from assms show \"HasAnInfimum(r,{z})\"\n    using inf_glb unfolding HasAnInfimum_def refl_def by blast\nqed\n  \ntext\\<open>If a set has a maximum, then the maximum is the supremum. This lemma is obsolete, use\n  \\<open>max_is_sup\\<close> instead.\\<close>\n\nlemma Order_ZF_5_L6: \n  assumes A1:  \"antisym(r)\" and A2: \"A\\<noteq>0\" and \n  A3: \"HasAmaximum(r,A)\"\n  shows \n  \"HasAminimum(r,\\<Inter>a\\<in>A. r``{a})\"\n  \"Maximum(r,A) = Supremum(r,A)\"\nproof -\n  let ?M = \"Maximum(r,A)\"\n  from A1 A3 have I: \"?M \\<in> A\" and II: \"\\<forall>x\\<in>A. \\<langle>x,?M\\<rangle> \\<in> r\"\n    using Order_ZF_4_L3 by auto\n  from I have III: \"\\<forall>y. (\\<forall>x\\<in>A. \\<langle>x,y\\<rangle> \\<in> r) \\<longrightarrow> \\<langle>?M,y\\<rangle> \\<in> r\"\n    by simp\n  with A1 A2 II show \"HasAminimum(r,\\<Inter>a\\<in>A. r``{a})\"\n    by (rule Order_ZF_5_L5)\n  from A1 A2 II III show \"?M = Supremum(r,A)\"\n    by (rule Order_ZF_5_L5)\nqed\n\ntext\\<open>Another version of \\<open>Order_ZF_5_L6\\<close> that: if a sat has a maximum then it has a supremum and \n  the maximum is the supremum. \\<close>\n\nlemma max_is_sup: assumes \"antisym(r)\" \"A\\<noteq>0\" \"HasAmaximum(r,A)\"\n  shows \"HasAsupremum(r,A)\" and \"Maximum(r,A) = Supremum(r,A)\"\nproof -\n  let ?M = \"Maximum(r,A)\"\n  from assms(1,3) have \"?M \\<in> A\" and I: \"\\<forall>x\\<in>A. \\<langle>x,?M\\<rangle> \\<in> r\" using Order_ZF_4_L3 \n    by auto\n  with assms(1,2) have \"HasAminimum(r,\\<Inter>a\\<in>A. r``{a})\" using Order_ZF_5_L5(1) \n    by blast\n  then show \"HasAsupremum(r,A)\" unfolding HasAsupremum_def by simp\n  from assms(1,2) \\<open>?M \\<in> A\\<close> I show \"?M = Supremum(r,A)\" using Order_ZF_5_L5(2) \n    by blast\nqed\n\ntext\\<open> Minimum is the infimum if it exists.\\<close>\n\nlemma min_is_inf: assumes \"antisym(r)\" \"A\\<noteq>0\" \"HasAminimum(r,A)\"\n  shows \"HasAnInfimum(r,A)\" and \"Minimum(r,A) = Infimum(r,A)\"\nproof -\n  let ?M = \"Minimum(r,A)\"\n  from assms(1,3) have \"?M\\<in>A\" and I: \"\\<forall>x\\<in>A. \\<langle>?M,x\\<rangle> \\<in> r\" using  Order_ZF_4_L4 \n    by auto\n  with assms(1,2) have \"HasAmaximum(r,\\<Inter>a\\<in>A. r-``{a})\" using inf_glb(1) by blast\n  then show \"HasAnInfimum(r,A)\" unfolding HasAnInfimum_def by simp\n  from assms(1,2) \\<open>?M \\<in> A\\<close> I show \"?M = Infimum(r,A)\" using inf_glb(2) by blast\nqed\n\ntext\\<open>For reflexive and total relations two-element set has a minimum and a maximum. \\<close>\n\nlemma min_max_two_el: assumes \"r {is total on} X\" \"x\\<in>X\" \"y\\<in>X\"\n  shows \"HasAminimum(r,{x,y})\" and \"HasAmaximum(r,{x,y})\"\n  using assms unfolding IsTotal_def HasAminimum_def HasAmaximum_def by auto\n\ntext\\<open>For antisymmetric, reflexive and total relations two-element set has a supremum and infimum. \\<close>\n\nlemma inf_sup_two_el:assumes \"antisym(r)\" \"r {is total on} X\" \"x\\<in>X\" \"y\\<in>X\"\n  shows \n    \"HasAnInfimum(r,{x,y})\"\n    \"Minimum(r,{x,y}) = Infimum(r,{x,y})\"\n    \"HasAsupremum(r,{x,y})\"\n    \"Maximum(r,{x,y}) = Supremum(r,{x,y})\"\n  using assms min_max_two_el max_is_sup min_is_inf by auto\n\ntext\\<open>A sufficient condition for the supremum to be in the space.\\<close>\n\nlemma sup_in_space: \n  assumes \"r \\<subseteq> X\\<times>X\" \"antisym(r)\" \"HasAminimum(r,\\<Inter>a\\<in>A. r``{a})\"\n  shows \"Supremum(r,A) \\<in> X\" and \"\\<forall>x\\<in>A. \\<langle>x,Supremum(r,A)\\<rangle> \\<in> r\"\nproof -\n  from assms(3) have \"A\\<noteq>0\" using set_sup_not_empty unfolding HasAsupremum_def by simp\n  then obtain a where \"a\\<in>A\" by auto\n  with assms(1,2,3) show \"Supremum(r,A) \\<in> X\" unfolding Supremum_def \n    using Order_ZF_4_L4 Order_ZF_5_L1 by blast\n  from assms(2,3) show \"\\<forall>x\\<in>A. \\<langle>x,Supremum(r,A)\\<rangle> \\<in> r\" unfolding Supremum_def\n    using Order_ZF_4_L4 by blast\nqed\n\ntext\\<open>A sufficient condition for the infimum to be in the space.\\<close>\n\nlemma inf_in_space: \n  assumes \"r \\<subseteq> X\\<times>X\" \"antisym(r)\" \"HasAmaximum(r,\\<Inter>a\\<in>A. r-``{a})\"\n  shows \"Infimum(r,A) \\<in> X\" and \"\\<forall>x\\<in>A. \\<langle>Infimum(r,A),x\\<rangle> \\<in> r\"\nproof -\n  from assms(3) have \"A\\<noteq>0\" using set_inf_not_empty unfolding HasAnInfimum_def by simp\n  then obtain a where \"a\\<in>A\" by auto\n  with assms(1,2,3) show \"Infimum(r,A) \\<in> X\" unfolding Infimum_def \n    using Order_ZF_4_L3 Order_ZF_5_L1 by blast\n  from assms(2,3) show \"\\<forall>x\\<in>A. \\<langle>Infimum(r,A),x\\<rangle> \\<in> r\" unfolding Infimum_def\n    using Order_ZF_4_L3 by blast\nqed\n\ntext\\<open>Properties of supremum of a set for complete relations.\\<close>\n\nlemma Order_ZF_5_L7: \n  assumes A1: \"r \\<subseteq> X\\<times>X\" and A2: \"antisym(r)\" and \n  A3: \"r {is complete}\" and\n  A4: \"A\\<noteq>0\" and A5: \"\\<exists>x\\<in>X. \\<forall>y\\<in>A. \\<langle>y,x\\<rangle> \\<in> r\"\n  shows \"Supremum(r,A) \\<in> X\" and \"\\<forall>x\\<in>A. \\<langle>x,Supremum(r,A)\\<rangle> \\<in> r\"\nproof -\n  from A3 A4 A5 have \"HasAminimum(r,\\<Inter>a\\<in>A. r``{a})\"\n    unfolding IsBoundedAbove_def IsComplete_def by blast\n  with A1 A2 show \"Supremum(r,A) \\<in> X\" and \"\\<forall>x\\<in>A. \\<langle>x,Supremum(r,A)\\<rangle> \\<in> r\"\n    using sup_in_space by auto\nqed \n\ntext\\<open> Infimum of the set of infima of a collection of sets is infimum of the union. \\<close>\n\nlemma inf_inf:\n  assumes \n    \"r \\<subseteq> X\\<times>X\" \"antisym(r)\" \"trans(r)\" \n    \"\\<forall>T\\<in>\\<T>. HasAnInfimum(r,T)\"\n    \"HasAnInfimum(r,{Infimum(r,T).T\\<in>\\<T>})\"\n  shows \n    \"HasAnInfimum(r,\\<Union>\\<T>)\" and \"Infimum(r,{Infimum(r,T).T\\<in>\\<T>}) = Infimum(r,\\<Union>\\<T>)\"\nproof -\n  let ?i = \"Infimum(r,{Infimum(r,T).T\\<in>\\<T>})\"\n  note assms(2)\n  moreover from assms(4,5) have \"\\<Union>\\<T> \\<noteq> 0\" using set_inf_not_empty by blast\n  moreover\n  have \"\\<forall>T\\<in>\\<T>.\\<forall>t\\<in>T. \\<langle>?i,t\\<rangle> \\<in> r\"\n  proof -\n    { fix T t assume \"T\\<in>\\<T>\" \"t\\<in>T\"\n      with assms(1,2,4) have \"\\<langle>Infimum(r,T),t\\<rangle> \\<in> r\"\n        unfolding HasAnInfimum_def using inf_in_space(2) by blast\n      moreover from assms(1,2,5) \\<open>T\\<in>\\<T>\\<close> have \"\\<langle>?i,Infimum(r,T)\\<rangle> \\<in> r\"\n        unfolding HasAnInfimum_def using inf_in_space(2) by blast\n      moreover note assms(3)\n      ultimately have \"\\<langle>?i,t\\<rangle> \\<in> r\" unfolding trans_def by blast\n    } thus ?thesis by simp\n  qed\n  hence I: \"\\<forall>t\\<in>\\<Union>\\<T>. \\<langle>?i,t\\<rangle> \\<in> r\" by auto\n  moreover have J: \"\\<forall>y. (\\<forall>x\\<in>\\<Union>\\<T>. \\<langle>y,x\\<rangle> \\<in> r) \\<longrightarrow> \\<langle>y,?i\\<rangle> \\<in> r\"\n  proof -\n    { fix y x assume A: \"\\<forall>x\\<in>\\<Union>\\<T>. \\<langle>y,x\\<rangle> \\<in> r\"\n      with assms(2,4) have \"\\<forall>a\\<in>{Infimum(r,T).T\\<in>\\<T>}. \\<langle>y,a\\<rangle> \\<in> r\" using inf_geq_lo_bnd\n        by simp\n      with assms(2,5) have \"\\<langle>y,?i\\<rangle> \\<in> r\" by (rule inf_geq_lo_bnd)\n    } thus ?thesis by simp\n  qed \n  ultimately have \"HasAmaximum(r,\\<Inter>a\\<in>\\<Union>\\<T>. r-``{a})\" by (rule inf_glb)\n  then show \"HasAnInfimum(r,\\<Union>\\<T>)\" unfolding HasAnInfimum_def by simp\n  from assms(2) \\<open>\\<Union>\\<T> \\<noteq> 0\\<close> I J show \"?i = Infimum(r,\\<Union>\\<T>)\" by (rule inf_glb)\nqed\n\ntext\\<open> Supremum of the set of suprema of a collection of sets is supremum of the union. \\<close>\n\nlemma sup_sup:\n  assumes \n    \"r \\<subseteq> X\\<times>X\" \"antisym(r)\" \"trans(r)\" \n    \"\\<forall>T\\<in>\\<T>. HasAsupremum(r,T)\"\n    \"HasAsupremum(r,{Supremum(r,T).T\\<in>\\<T>})\"\n  shows \n    \"HasAsupremum(r,\\<Union>\\<T>)\" and \"Supremum(r,{Supremum(r,T).T\\<in>\\<T>}) = Supremum(r,\\<Union>\\<T>)\"\nproof -\n  let ?s = \"Supremum(r,{Supremum(r,T).T\\<in>\\<T>})\"\n  note assms(2)\n  moreover from assms(4,5) have \"\\<Union>\\<T> \\<noteq> 0\" using set_sup_not_empty by blast\n  moreover\n  have \"\\<forall>T\\<in>\\<T>.\\<forall>t\\<in>T. \\<langle>t,?s\\<rangle> \\<in> r\"\n  proof -\n    { fix T t assume \"T\\<in>\\<T>\" \"t\\<in>T\"\n      with assms(1,2,4) have \"\\<langle>t,Supremum(r,T)\\<rangle> \\<in> r\"\n        unfolding HasAsupremum_def using sup_in_space(2) by blast\n      moreover from assms(1,2,5) \\<open>T\\<in>\\<T>\\<close> have \"\\<langle>Supremum(r,T),?s\\<rangle> \\<in> r\"\n        unfolding HasAsupremum_def using sup_in_space(2) by blast\n      moreover note assms(3)\n      ultimately have \"\\<langle>t,?s\\<rangle> \\<in> r\" unfolding trans_def by blast\n    } thus ?thesis by simp\n  qed\n  hence I: \"\\<forall>t\\<in>\\<Union>\\<T>. \\<langle>t,?s\\<rangle> \\<in> r\" by auto\n  moreover have J: \"\\<forall>y. (\\<forall>x\\<in>\\<Union>\\<T>. \\<langle>x,y\\<rangle> \\<in> r) \\<longrightarrow> \\<langle>?s,y\\<rangle> \\<in> r\"\n  proof -\n    { fix y x assume A: \"\\<forall>x\\<in>\\<Union>\\<T>. \\<langle>x,y\\<rangle> \\<in> r\"\n      with assms(2,4) have \"\\<forall>a\\<in>{Supremum(r,T).T\\<in>\\<T>}. \\<langle>a,y\\<rangle> \\<in> r\" using sup_leq_up_bnd\n        by simp\n      with assms(2,5) have \"\\<langle>?s,y\\<rangle> \\<in> r\" by (rule sup_leq_up_bnd)\n    } thus ?thesis by simp\n  qed \n  ultimately have \"HasAminimum(r,\\<Inter>a\\<in>\\<Union>\\<T>. r``{a})\" by (rule Order_ZF_5_L5)\n  then show \"HasAsupremum(r,\\<Union>\\<T>)\" unfolding HasAsupremum_def by simp\n  from assms(2) \\<open>\\<Union>\\<T> \\<noteq> 0\\<close> I J show \"?s = Supremum(r,\\<Union>\\<T>)\" by (rule Order_ZF_5_L5)\nqed\n\ntext\\<open>If the relation is a linear order then for any \n  element $y$ smaller than the supremum of a set we can\n  find one element of the set that is greater than $y$.\\<close>\n\nlemma Order_ZF_5_L8:\n  assumes A1: \"r \\<subseteq> X\\<times>X\"  and A2: \"IsLinOrder(X,r)\" and \n  A3: \"r {is complete}\" and\n  A4: \"A\\<subseteq>X\"  \"A\\<noteq>0\" and A5: \"\\<exists>x\\<in>X. \\<forall>y\\<in>A. \\<langle>y,x\\<rangle> \\<in> r\" and\n  A6: \"\\<langle>y,Supremum(r,A)\\<rangle> \\<in> r\"   \"y \\<noteq> Supremum(r,A)\"\n  shows \"\\<exists>z\\<in>A. \\<langle>y,z\\<rangle> \\<in> r \\<and> y \\<noteq> z\"\nproof -\n  from A2 have \n    I: \"antisym(r)\" and\n    II: \"trans(r)\" and\n    III: \"r {is total on} X\"\n    using IsLinOrder_def by auto\n  from A1 A6 have T1: \"y\\<in>X\" by auto\n  { assume A7: \"\\<forall>z \\<in> A. \\<langle>y,z\\<rangle> \\<notin> r \\<or> y=z\"\n    from A4 I have \"antisym(r)\" and \"A\\<noteq>0\" by auto\n    moreover have \"\\<forall>x\\<in>A. \\<langle>x,y\\<rangle> \\<in> r\"  \n    proof      \n      fix x assume A8: \"x\\<in>A\"\n      with A4 have T2: \"x\\<in>X\" by auto\n      from A7 A8 have \"\\<langle>y,x\\<rangle> \\<notin> r \\<or> y=x\" by simp\n      with III T1 T2 show \"\\<langle>x,y\\<rangle> \\<in> r\"\n\tusing IsTotal_def total_is_refl refl_def by auto\n    qed\n    moreover have \"\\<forall>u. (\\<forall>x\\<in>A. \\<langle>x,u\\<rangle> \\<in> r) \\<longrightarrow> \\<langle>y,u\\<rangle> \\<in> r\"\n    proof-\n      { fix u assume A9: \"\\<forall>x\\<in>A. \\<langle>x,u\\<rangle> \\<in> r\"\n\tfrom A4 A5 have \"IsBoundedAbove(A,r)\" and \"A\\<noteq>0\"\n\t  using IsBoundedAbove_def by auto\n\twith  A3 A4 A6 I A9  have \n\t  \"\\<langle>y,Supremum(r,A)\\<rangle> \\<in> r \\<and> \\<langle>Supremum(r,A),u\\<rangle> \\<in> r\"\n\t  using IsComplete_def Order_ZF_5_L3 by simp\n\twith II have \"\\<langle>y,u\\<rangle> \\<in> r\" by (rule Fol1_L3)\n      } then show \"\\<forall>u. (\\<forall>x\\<in>A. \\<langle>x,u\\<rangle> \\<in> r) \\<longrightarrow> \\<langle>y,u\\<rangle> \\<in> r\"\n\tby simp\n    qed\n    ultimately have \"y = Supremum(r,A)\"\n      by (rule Order_ZF_5_L5)\n    with A6 have False by simp\n  } then show \"\\<exists>z\\<in>A. \\<langle>y,z\\<rangle> \\<in> r \\<and> y \\<noteq> z\" by auto\nqed\n\nsubsection\\<open>Strict versions of order relations\\<close>\n\ntext\\<open>One of the problems with translating formalized mathematics from\n  Metamath to IsarMathLib is that Metamath uses strict orders (of the $<$ \n  type) while in IsarMathLib we mostly use nonstrict orders (of the \n  $\\leq$ type). \n  This doesn't really make any difference, but is annoying as we \n  have to prove many theorems twice. In this section we prove some theorems\n  to make it easier to translate the statements about strict orders to\n  statements about the corresponding non-strict order and vice versa.\\<close>\n\ntext\\<open>We define a strict version of a relation by removing the $y=x$ line \n  from the relation.\\<close>\n\ndefinition\n  \"StrictVersion(r) \\<equiv> r - {\\<langle>x,x\\<rangle>. x \\<in> domain(r)}\"\n\ntext\\<open>A reformulation of the definition of a strict version of an order.\n\\<close>\n\nlemma def_of_strict_ver: shows \n  \"\\<langle>x,y\\<rangle> \\<in> StrictVersion(r) \\<longleftrightarrow> \\<langle>x,y\\<rangle> \\<in> r \\<and> x\\<noteq>y\"\n  using StrictVersion_def domain_def by auto\n\ntext\\<open>The next lemma is about the strict version of an antisymmetric\n  relation.\\<close>\n\nlemma strict_of_antisym: \n  assumes A1: \"antisym(r)\" and A2: \"\\<langle>a,b\\<rangle> \\<in> StrictVersion(r)\"\n  shows \"\\<langle>b,a\\<rangle> \\<notin> StrictVersion(r)\"\nproof -\n  { assume A3: \"\\<langle>b,a\\<rangle> \\<in> StrictVersion(r)\"\n    with A2 have \"\\<langle>a,b\\<rangle> \\<in> r\"  and \"\\<langle>b,a\\<rangle> \\<in> r\"\n      using def_of_strict_ver by auto\n    with A1 have \"a=b\" by (rule Fol1_L4)\n    with A2 have False using def_of_strict_ver\n      by simp\n  } then show \"\\<langle>b,a\\<rangle> \\<notin> StrictVersion(r)\" by auto\nqed\n\ntext\\<open>The strict version of totality.\\<close>\n\nlemma strict_of_tot:\n  assumes \"r {is total on} X\" and \"a\\<in>X\"  \"b\\<in>X\"  \"a\\<noteq>b\"\n  shows \"\\<langle>a,b\\<rangle> \\<in> StrictVersion(r) \\<or> \\<langle>b,a\\<rangle> \\<in> StrictVersion(r)\"\n  using assms IsTotal_def def_of_strict_ver by auto\n\ntext\\<open>A trichotomy law for the strict version of a total \n  and antisymmetric\n  relation. It is kind of interesting that one does not need\n  the full linear order for this.\\<close>\n\nlemma strict_ans_tot_trich: \n  assumes A1: \"antisym(r)\" and A2: \"r {is total on} X\"\n  and A3: \"a\\<in>X\"  \"b\\<in>X\"\n  and A4: \"s = StrictVersion(r)\"\n  shows \"Exactly_1_of_3_holds(\\<langle>a,b\\<rangle> \\<in> s, a=b,\\<langle>b,a\\<rangle> \\<in> s)\"\nproof -\n  let ?p = \"\\<langle>a,b\\<rangle> \\<in> s\"\n  let ?q = \"a=b\"\n  let ?r = \"\\<langle>b,a\\<rangle> \\<in> s\"\n  from A2 A3 A4 have \"?p \\<or> ?q \\<or> ?r\"\n    using strict_of_tot by auto\n  moreover from A1 A4 have \"?p \\<longrightarrow> \\<not>?q \\<and> \\<not>?r\"\n    using def_of_strict_ver strict_of_antisym by simp\n  moreover from A4 have \"?q \\<longrightarrow> \\<not>?p \\<and> \\<not>?r\"\n    using def_of_strict_ver by simp\n  moreover from A1 A4 have \"?r \\<longrightarrow> \\<not>?p \\<and> \\<not>?q\"\n    using def_of_strict_ver strict_of_antisym by auto\n  ultimately show \"Exactly_1_of_3_holds(?p, ?q, ?r)\"\n    by (rule Fol1_L5)\nqed\n\ntext\\<open>A trichotomy law for linear order. This is a special\n  case of \\<open>strict_ans_tot_trich\\<close>.\\<close>\n\ncorollary strict_lin_trich: assumes A1: \"IsLinOrder(X,r)\" and\n  A2: \"a\\<in>X\"  \"b\\<in>X\" and \n  A3: \"s = StrictVersion(r)\"\n  shows \"Exactly_1_of_3_holds(\\<langle>a,b\\<rangle> \\<in> s, a=b,\\<langle>b,a\\<rangle> \\<in> s)\"\n  using assms IsLinOrder_def strict_ans_tot_trich by auto\n\ntext\\<open>For an antisymmetric relation if a pair is in relation then\n  the reversed pair is not in the strict version of the relation. \n\\<close>\n\nlemma geq_impl_not_less: \n  assumes A1: \"antisym(r)\" and A2: \"\\<langle>a,b\\<rangle> \\<in> r\"\n  shows \"\\<langle>b,a\\<rangle> \\<notin> StrictVersion(r)\"\nproof -\n  { assume A3: \"\\<langle>b,a\\<rangle> \\<in>  StrictVersion(r)\"\n    with A2 have \"\\<langle>a,b\\<rangle> \\<in> StrictVersion(r)\"\n      using def_of_strict_ver by auto\n    with A1 A3 have False using strict_of_antisym\n      by blast\n  } then show \"\\<langle>b,a\\<rangle> \\<notin> StrictVersion(r)\" by auto\nqed\n \ntext\\<open>If an antisymmetric relation is transitive, \n  then the strict version is also transitive, an explicit\n  version \\<open>strict_of_transB\\<close> below.\\<close>\n\nlemma strict_of_transA: \n  assumes A1: \"trans(r)\" and A2: \"antisym(r)\" and  \n  A3: \"s= StrictVersion(r)\" and  A4: \"\\<langle>a,b\\<rangle> \\<in> s\"  \"\\<langle>b,c\\<rangle> \\<in> s\"\n  shows \"\\<langle>a,c\\<rangle> \\<in> s\"\nproof -\n  from A3 A4 have I: \"\\<langle>a,b\\<rangle> \\<in> r \\<and> \\<langle>b,c\\<rangle> \\<in> r\"\n    using def_of_strict_ver by simp\n  with A1 have \"\\<langle>a,c\\<rangle> \\<in> r\" by (rule Fol1_L3)\n  moreover\n  { assume \"a=c\"\n    with I have \"\\<langle>a,b\\<rangle> \\<in> r\" and \"\\<langle>b,a\\<rangle> \\<in> r\" by auto\n    with A2 have \"a=b\" by (rule Fol1_L4)\n    with A3 A4 have False using def_of_strict_ver by simp\n  } then have \"a\\<noteq>c\" by auto\n  ultimately have  \"\\<langle>a,c\\<rangle> \\<in> StrictVersion(r)\"\n    using def_of_strict_ver by simp\n  with A3 show ?thesis by simp\nqed\n\ntext\\<open>If an antisymmetric relation is transitive, \n  then the strict version is also transitive.\\<close>\n\nlemma strict_of_transB: \n  assumes A1: \"trans(r)\" and A2: \"antisym(r)\"\n  shows \"trans(StrictVersion(r))\"\nproof -\n  let ?s = \"StrictVersion(r)\"\n  from A1 A2 have \n    \"\\<forall> x y z. \\<langle>x, y\\<rangle> \\<in> ?s \\<and> \\<langle>y, z\\<rangle> \\<in> ?s \\<longrightarrow> \\<langle>x, z\\<rangle> \\<in> ?s\"\n    using strict_of_transA by blast\n  then show \"trans(StrictVersion(r))\" by (rule Fol1_L2)\nqed\n\ntext\\<open>The next lemma provides a condition that is satisfied by\n  the strict version of a relation if the original relation \n  is a complete linear order.\\<close>\n\nlemma strict_of_compl: \n  assumes A1: \"r \\<subseteq> X\\<times>X\" and A2: \"IsLinOrder(X,r)\" and \n  A3: \"r {is complete}\" and \n  A4: \"A\\<subseteq>X\"  \"A\\<noteq>0\" and A5: \"s = StrictVersion(r)\" and \n  A6: \"\\<exists>u\\<in>X. \\<forall>y\\<in>A. \\<langle>y,u\\<rangle> \\<in> s\"\n  shows \n  \"\\<exists>x\\<in>X. ( \\<forall>y\\<in>A. \\<langle>x,y\\<rangle> \\<notin> s ) \\<and> (\\<forall>y\\<in>X. \\<langle>y,x\\<rangle> \\<in> s \\<longrightarrow> (\\<exists>z\\<in>A. \\<langle>y,z\\<rangle> \\<in> s))\"\nproof -\n  let ?x = \"Supremum(r,A)\"\n  from A2 have I: \"antisym(r)\" using IsLinOrder_def\n    by simp\n  moreover from A5 A6 have \"\\<exists>u\\<in>X. \\<forall>y\\<in>A. \\<langle>y,u\\<rangle> \\<in> r\"\n    using def_of_strict_ver by auto\n  moreover note A1 A3 A4 \n  ultimately have II: \"?x \\<in> X\"   \"\\<forall>y\\<in>A. \\<langle>y,?x\\<rangle> \\<in> r\"\n    using Order_ZF_5_L7 by auto\n  then have III: \"\\<exists>x\\<in>X. \\<forall>y\\<in>A. \\<langle>y,x\\<rangle> \\<in> r\" by auto\n  from A5 I II have \"?x \\<in> X\"   \"\\<forall>y\\<in>A. \\<langle>?x,y\\<rangle> \\<notin> s\"\n    using geq_impl_not_less by auto\n  moreover from A1 A2 A3 A4 A5 III have \n    \"\\<forall>y\\<in>X. \\<langle>y,?x\\<rangle> \\<in> s \\<longrightarrow> (\\<exists>z\\<in>A. \\<langle>y,z\\<rangle> \\<in> s)\"\n    using def_of_strict_ver Order_ZF_5_L8 by simp\n  ultimately show\n    \"\\<exists>x\\<in>X. ( \\<forall>y\\<in>A. \\<langle>x,y\\<rangle> \\<notin> s ) \\<and> (\\<forall>y\\<in>X. \\<langle>y,x\\<rangle> \\<in> s \\<longrightarrow> (\\<exists>z\\<in>A. \\<langle>y,z\\<rangle> \\<in> s))\"\n    by auto\nqed\n\ntext\\<open>Strict version of a relation on a set is a relation on that\n  set.\\<close>\n\nlemma strict_ver_rel: assumes A1: \"r \\<subseteq> A\\<times>A\"\n  shows \"StrictVersion(r) \\<subseteq> A\\<times>A\"\n  using assms StrictVersion_def by auto\n\nend\n", "meta": {"author": "SKolodynski", "repo": "IsarMathLib", "sha": "879c6b779ca00364879aa0232b0aa9f18bafa85a", "save_path": "github-repos/isabelle/SKolodynski-IsarMathLib", "path": "github-repos/isabelle/SKolodynski-IsarMathLib/IsarMathLib-879c6b779ca00364879aa0232b0aa9f18bafa85a/IsarMathLib/Order_ZF_1a.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5156199157230157, "lm_q2_score": 0.5660185351961015, "lm_q1q2_score": 0.2918504294154786}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |               December 2004               |\n            |                   June 2005  (modified)   |\n            |              September 2005  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |               November 2005  (modified)   |\n            |                  March 2007  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory CSP_F_law_ref\nimports CSP_F_law_basic CSP_T.CSP_T_law_ref\nbegin\n\n(*****************************************************************\n\n         1. rules for refinement\n\n *****************************************************************)\n\n(*-------------------------------------------------------*\n |            refinement and equality                    |\n *-------------------------------------------------------*)\n\nlemma cspF_ref_eq_iff: \"(P <=F[M,M] Q) = (P =F[M,M] Q |~| P)\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_ref_eq_iff)\napply (rule)\n\n(* <= *)\n apply (simp)\n apply (rule order_antisym)\n apply (simp add: subsetF_iff)\n apply (simp add: in_failures)\n apply (simp add: subsetF_iff)\n apply (simp add: in_failures)\n\n(* => *)\n apply (simp)\n apply (erule conjE)\n apply (erule order_antisymE)\n apply (rule)\n apply (rotate_tac 2)\n apply (erule subsetFE_ALL)\n apply (drule_tac x=\"s\" in spec)\n apply (drule_tac x=\"X\" in spec)\n apply (simp add: in_failures)\ndone\n\n(*-------------------------------------------------------*\n |              decompose Internal choice                |\n *-------------------------------------------------------*)\n\n(*** or <= ***)                                         (* unsafe *)\n\nlemma cspF_Int_choice_left1:\n  \"P1 <=F[M1,M2] Q ==> P1 |~| P2 <=F[M1,M2] Q\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Int_choice_left1)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Int_choice_left2:\n  \"P2 <=F[M1,M2] Q ==> P1 |~| P2 <=F[M1,M2] Q\"\napply (rule cspF_rw_left)\napply (rule cspF_commut)\nby (simp add: cspF_Int_choice_left1)\n\n(*** <= and ***)                                          (* safe *)\n\nlemma cspF_Int_choice_right:\n  \"[| P <=F[M1,M2] Q1 ; P <=F[M1,M2] Q2 |]\n      ==> P <=F[M1,M2] Q1 |~| Q2\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Int_choice_right)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\n(*-------------------------------------------------------*\n |        decompose Replicated internal choice           |\n *-------------------------------------------------------*)\n\n(*** EX <= ***)                                           (* unsafe *)\n\nlemma cspF_Rep_int_choice_nat_left:\n  \"(EX n. n:N & Pf n <=F[M1,M2] Q)\n      ==> !nat :N .. Pf <=F[M1,M2] Q\"\napply (simp add: cspF_cspT_semantics)\napply (rule conjI)\n\napply (rule cspT_Rep_int_choice_left)\napply (fast)\n\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_nat_left_x:\n  \"[| n:N ; Pf n <=F[M1,M2] Q |]\n  ==> !nat :N .. Pf <=F[M1,M2] Q\"\napply (rule cspF_Rep_int_choice_nat_left)\nby (fast)\n\nlemma cspF_Rep_int_choice_set_left:\n  \"(EX X. X:Xs & Pf X <=F[M1,M2] Q)\n      ==> !set :Xs .. Pf <=F[M1,M2] Q\"\napply (simp add: cspF_cspT_semantics)\napply (rule conjI)\n\napply (rule cspT_Rep_int_choice_left)\napply (fast)\n\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_set_left_x:\n  \"[| X:Xs ; Pf X <=F[M1,M2] Q |]\n  ==> !set :Xs .. Pf <=F[M1,M2] Q\"\napply (rule cspF_Rep_int_choice_set_left)\nby (fast)\n\nlemma cspF_Rep_int_choice_com_left:\n  \"(EX a. a:X & Pf a <=F[M1,M2] Q)\n      ==> ! :X .. Pf <=F[M1,M2] Q\"\napply (simp add: Rep_int_choice_com_def)\napply (rule cspF_Rep_int_choice_set_left)\napply (erule exE)\napply (rule_tac x=\"{a}\" in exI)\napply (auto)\ndone\n\nlemma cspF_Rep_int_choice_com_left_x:\n  \"[| a:X ; Pf a <=F[M1,M2] Q |]\n  ==> ! :X .. Pf <=F[M1,M2] Q\"\napply (rule cspF_Rep_int_choice_com_left)\nby (fast)\n\nlemma cspF_Rep_int_choice_f_left:\n  \"[| inj f ; (EX a. a:X & Pf a <=F[M1,M2] Q) |]\n      ==> !<f> :X .. Pf <=F[M1,M2] Q\"\napply (simp add: Rep_int_choice_f_def)\napply (rule cspF_Rep_int_choice_com_left)\napply (erule exE)\napply (rule_tac x=\"f a\" in exI)\napply (auto)\ndone\n\nlemma cspF_Rep_int_choice_f_left_x:\n  \"[| inj f ; a:X ; Pf a <=F[M1,M2] Q |]\n  ==> !<f> :X .. Pf <=F[M1,M2] Q\"\napply (rule cspF_Rep_int_choice_f_left)\napply (simp)\nby (fast)\n\nlemmas cspF_Rep_int_choice_left = cspF_Rep_int_choice_nat_left\n                                  cspF_Rep_int_choice_set_left\n                                  cspF_Rep_int_choice_com_left\n                                  cspF_Rep_int_choice_f_left\n\nlemmas cspF_Rep_int_choice_left_x = cspF_Rep_int_choice_nat_left_x\n                                  cspF_Rep_int_choice_set_left_x\n                                  cspF_Rep_int_choice_com_left_x\n                                  cspF_Rep_int_choice_f_left_x\n\n(*** <= ALL ***)                                         (* safe *)\n\nlemma cspF_Rep_int_choice_nat_right:\n  \"[| !!n. n:N ==> P <=F[M1,M2] Qf n |]\n               ==> P <=F[M1,M2] !nat :N .. Qf\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Rep_int_choice_right)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_set_right:\n  \"[| !!X. X:Xs ==> P <=F[M1,M2] Qf X |]\n               ==> P <=F[M1,M2] !set :Xs .. Qf\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Rep_int_choice_right)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_com_right:\n  \"[| !!a. a:X ==> P <=F[M1,M2] Qf a |]\n               ==> P <=F[M1,M2] ! :X .. Qf\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Rep_int_choice_right)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_f_right:\n  \"[| inj f ; !!a. a:X ==> P <=F[M1,M2] Qf a |]\n               ==> P <=F[M1,M2] !<f> :X .. Qf\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Rep_int_choice_right)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemmas cspF_Rep_int_choice_right \n     = cspF_Rep_int_choice_nat_right\n       cspF_Rep_int_choice_set_right\n       cspF_Rep_int_choice_com_right\n       cspF_Rep_int_choice_f_right\n\n(* 1,2,3,f E *)\n\nlemma cspF_Rep_int_choice_nat_rightE:\n  \"[| P <=F[M1,M2] !nat :N .. Qf ;\n      ALL n:N. P <=F[M1,M2] Qf n ==> R\n   |] ==> R\"\napply (simp add: cspF_cspT_semantics)\napply (elim conjE exE)\napply (erule cspT_Rep_int_choice_rightE)\n\napply (simp add: subsetF_iff)\napply (simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_set_rightE:\n  \"[| P <=F[M1,M2] !set :Xs .. Qf ;\n      ALL X:Xs. P <=F[M1,M2] Qf X ==> R\n   |] ==> R\"\napply (simp add: cspF_cspT_semantics)\napply (elim conjE exE)\napply (erule cspT_Rep_int_choice_rightE)\n\napply (simp add: subsetF_iff)\napply (simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_com_rightE:\n  \"[| P <=F[M1,M2] ! :X .. Qf ;\n      ALL a:X. P <=F[M1,M2] Qf a ==> R\n   |] ==> R\"\napply (simp add: cspF_cspT_semantics)\napply (elim conjE exE)\napply (erule cspT_Rep_int_choice_rightE)\n\napply (simp add: subsetF_iff)\napply (simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_f_rightE:\n  \"[| P <=F[M1,M2] !<f> :X .. Qf ; inj f ;\n      [| ALL a:X. P <=F[M1,M2] Qf a |] ==> R\n   |] ==> R\"\napply (simp add: cspF_cspT_semantics)\napply (elim conjE exE)\napply (erule cspT_Rep_int_choice_rightE)\napply (simp)\n\napply (simp add: subsetF_iff)\napply (simp add: in_failures)\napply (force)\ndone\n\nlemmas cspF_Rep_int_choice_rightE =\n       cspF_Rep_int_choice_nat_rightE\n       cspF_Rep_int_choice_set_rightE\n       cspF_Rep_int_choice_com_rightE\n       cspF_Rep_int_choice_f_rightE\n\n(*-------------------------------------------------------*\n |             decomposition with subset                 |\n *-------------------------------------------------------*)\n\nlemma cspF_Rep_int_choice_nat_subset:\n  \"[| N2 <= N1  ; !!n. n:N2 ==> Pf n <=F[M1,M2] Qf n |]\n                    ==> !nat :N1 .. Pf <=F[M1,M2] !nat :N2 .. Qf\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Rep_int_choice_subset)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_set_subset:\n  \"[| Ys <= Xs  ; !!X. X:Ys ==> Pf X <=F[M1,M2] Qf X |]\n                    ==> !set :Xs .. Pf <=F[M1,M2] !set :Ys .. Qf\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Rep_int_choice_subset)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_com_subset:\n  \"[| Y <= X  ; !!a. a:Y ==> Pf a <=F[M1,M2] Qf a |]\n                    ==> ! :X .. Pf <=F[M1,M2] ! :Y .. Qf\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Rep_int_choice_subset)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_f_subset:\n  \"[| inj f ; Y <= X  ; !!a. a:Y ==> Pf a <=F[M1,M2] Qf a |]\n                    ==> !<f> :X .. Pf <=F[M1,M2] !<f> :Y .. Qf\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Rep_int_choice_subset)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemmas cspF_Rep_int_choice_subset \n     = cspF_Rep_int_choice_nat_subset\n       cspF_Rep_int_choice_set_subset\n       cspF_Rep_int_choice_com_subset\n       cspF_Rep_int_choice_f_subset\n\n(*** ! x:X .. and ? -> ***)\n\nlemma cspF_Int_Ext_pre_choice_subset:\n  \"[| Y ~={} ; Y <= X ; !!a. a:Y ==> Pf a <=F[M1,M2] Qf a |]\n        ==> ! x:X .. (x -> Pf x) <=F[M1,M2]\n            ? :Y -> Qf\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Int_Ext_pre_choice_subset)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemmas cspF_decompo_subset = cspF_Rep_int_choice_subset\n                             cspF_Int_Ext_pre_choice_subset\n\n(*-------------------------------------------------------*\n |               decompose external choice               |\n *-------------------------------------------------------*)\n\nlemma cspF_Ext_choice_right:\n  \"[| P <=F[M1,M2] Q1 ;\n      P <=F[M1,M2] Q2 |]\n      ==> P <=F[M1,M2] Q1 [+] Q2\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Ext_choice_right)\napply (rule)\n\n apply (simp add: in_failures)\n apply (elim disjE conjE exE, simp)\n apply (force, force, force)\n apply (simp_all)\n\n apply (subgoal_tac \"(<>, X) :f failures(Q1) M2\")\n apply (force)\n apply (rule proc_F2_F4)\n apply (simp_all)\n apply (rule proc_F2_F4)\n apply (simp_all)\n apply (simp add: cspT_semantics)\n apply (auto)\ndone\n\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/CSP_F/CSP_F_law_ref.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6224593452091672, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.2918031064899669}}
{"text": "(*  Title:       AWN_SOS.thy\n    License:     BSD 2-Clause. See LICENSE.\n    Author:      Timothy Bourke\n*)\n\nsection \"Semantics of the Algebra of Wireless Networks\"\n\ntheory AWN_SOS\nimports TransitionSystems AWN\nbegin\n\nsubsection \"Table 1: Structural operational semantics for sequential process expressions \"\n\ninductive_set\n  seqp_sos\n  :: \"('s, 'm, 'p, 'l) seqp_env \\<Rightarrow> ('s \\<times> ('s, 'm, 'p, 'l) seqp, 'm seq_action) transition set\"\n  for \\<Gamma> :: \"('s, 'm, 'p, 'l) seqp_env\"\nwhere\n    broadcastT: \"((\\<xi>, {l}broadcast(s\\<^sub>m\\<^sub>s\\<^sub>g).p),          broadcast (s\\<^sub>m\\<^sub>s\\<^sub>g \\<xi>),         (\\<xi>, p)) \\<in> seqp_sos \\<Gamma>\"\n  | groupcastT: \"((\\<xi>, {l}groupcast(s\\<^sub>i\\<^sub>p\\<^sub>s, s\\<^sub>m\\<^sub>s\\<^sub>g).p),    groupcast (s\\<^sub>i\\<^sub>p\\<^sub>s \\<xi>) (s\\<^sub>m\\<^sub>s\\<^sub>g \\<xi>), (\\<xi>, p)) \\<in> seqp_sos \\<Gamma>\"\n  | unicastT:   \"((\\<xi>, {l}unicast(s\\<^sub>i\\<^sub>p, s\\<^sub>m\\<^sub>s\\<^sub>g).p \\<triangleright> q),   unicast (s\\<^sub>i\\<^sub>p \\<xi>) (s\\<^sub>m\\<^sub>s\\<^sub>g \\<xi>),    (\\<xi>, p)) \\<in> seqp_sos \\<Gamma>\"\n  | notunicastT:\"((\\<xi>, {l}unicast(s\\<^sub>i\\<^sub>p, s\\<^sub>m\\<^sub>s\\<^sub>g).p \\<triangleright> q),    \\<not>unicast (s\\<^sub>i\\<^sub>p \\<xi>),          (\\<xi>, q)) \\<in> seqp_sos \\<Gamma>\"\n  | sendT:      \"((\\<xi>, {l}send(s\\<^sub>m\\<^sub>s\\<^sub>g).p),               send (s\\<^sub>m\\<^sub>s\\<^sub>g \\<xi>),              (\\<xi>, p)) \\<in> seqp_sos \\<Gamma>\"\n  | deliverT:   \"((\\<xi>, {l}deliver(s\\<^sub>d\\<^sub>a\\<^sub>t\\<^sub>a).p),           deliver (s\\<^sub>d\\<^sub>a\\<^sub>t\\<^sub>a \\<xi>),          (\\<xi>, p)) \\<in> seqp_sos \\<Gamma>\"\n  | receiveT:   \"((\\<xi>, {l}receive(u\\<^sub>m\\<^sub>s\\<^sub>g).p),            receive msg,       (u\\<^sub>m\\<^sub>s\\<^sub>g msg \\<xi>, p)) \\<in> seqp_sos \\<Gamma>\"\n  | assignT:    \"((\\<xi>, {l}\\<lbrakk>u\\<rbrakk> p),                      \\<tau>,                        (u \\<xi>, p)) \\<in> seqp_sos \\<Gamma>\"\n\n  | callT:      \"\\<lbrakk> ((\\<xi>, \\<Gamma> pn), a, (\\<xi>', p')) \\<in> seqp_sos \\<Gamma> \\<rbrakk> \\<Longrightarrow>\n                 ((\\<xi>, call(pn)), a, (\\<xi>', p')) \\<in> seqp_sos \\<Gamma>\" (* TPB: quite different to Table 1 *)\n\n  | choiceT1:   \"((\\<xi>, p), a, (\\<xi>', p')) \\<in> seqp_sos \\<Gamma>  \\<Longrightarrow> ((\\<xi>, p \\<oplus> q), a, (\\<xi>', p')) \\<in> seqp_sos \\<Gamma>\"\n  | choiceT2:   \"((\\<xi>, q), a, (\\<xi>', q')) \\<in> seqp_sos \\<Gamma>  \\<Longrightarrow> ((\\<xi>, p \\<oplus> q), a, (\\<xi>', q')) \\<in> seqp_sos \\<Gamma>\"\n\n  | guardT:     \"\\<xi>' \\<in> g \\<xi> \\<Longrightarrow> ((\\<xi>, {l}\\<langle>g\\<rangle> p), \\<tau>, (\\<xi>', p)) \\<in> seqp_sos \\<Gamma>\"\n\ninductive_cases\n      seqp_callTE [elim]:      \"((\\<xi>, call(pn)), a, (\\<xi>', q)) \\<in> seqp_sos \\<Gamma>\"\n  and seqp_choiceTE [elim]:    \"((\\<xi>, p1 \\<oplus> p2), a, (\\<xi>', q)) \\<in> seqp_sos \\<Gamma>\"\n\nlemma seqp_broadcastTE [elim]:\n  \"\\<lbrakk>((\\<xi>, {l}broadcast(s\\<^sub>m\\<^sub>s\\<^sub>g). p), a, (\\<xi>', q)) \\<in> seqp_sos \\<Gamma>;\n    \\<lbrakk>a = broadcast (s\\<^sub>m\\<^sub>s\\<^sub>g \\<xi>); \\<xi>' = \\<xi>; q = p\\<rbrakk> \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  by (ind_cases \"((\\<xi>, {l}broadcast(s\\<^sub>m\\<^sub>s\\<^sub>g). p), a, (\\<xi>', q)) \\<in> seqp_sos \\<Gamma>\") simp\n\nlemma seqp_groupcastTE [elim]:\n  \"\\<lbrakk>((\\<xi>, {l}groupcast(s\\<^sub>i\\<^sub>p\\<^sub>s, s\\<^sub>m\\<^sub>s\\<^sub>g). p), a, (\\<xi>', q)) \\<in> seqp_sos \\<Gamma>;\n    \\<lbrakk>a = groupcast (s\\<^sub>i\\<^sub>p\\<^sub>s \\<xi>) (s\\<^sub>m\\<^sub>s\\<^sub>g \\<xi>); \\<xi>' = \\<xi>; q = p\\<rbrakk> \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  by (ind_cases \"((\\<xi>, {l}groupcast(s\\<^sub>i\\<^sub>p\\<^sub>s, s\\<^sub>m\\<^sub>s\\<^sub>g). p), a, (\\<xi>', q)) \\<in> seqp_sos \\<Gamma>\") simp\n\nlemma seqp_unicastTE [elim]:\n  \"\\<lbrakk>((\\<xi>, {l}unicast(s\\<^sub>i\\<^sub>p, s\\<^sub>m\\<^sub>s\\<^sub>g). p \\<triangleright> q), a, (\\<xi>', r)) \\<in> seqp_sos \\<Gamma>;\n    \\<lbrakk>a = unicast (s\\<^sub>i\\<^sub>p \\<xi>) (s\\<^sub>m\\<^sub>s\\<^sub>g \\<xi>); \\<xi>' = \\<xi>; r = p\\<rbrakk> \\<Longrightarrow> P;\n    \\<lbrakk>a = \\<not>unicast (s\\<^sub>i\\<^sub>p \\<xi>); \\<xi>' = \\<xi>; r = q\\<rbrakk> \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  by (ind_cases \"((\\<xi>, {l}unicast(s\\<^sub>i\\<^sub>p, s\\<^sub>m\\<^sub>s\\<^sub>g). p \\<triangleright> q), a, (\\<xi>', r)) \\<in> seqp_sos \\<Gamma>\") simp_all\n\nlemma seqp_sendTE [elim]:\n  \"\\<lbrakk>((\\<xi>, {l}send(s\\<^sub>m\\<^sub>s\\<^sub>g). p), a, (\\<xi>', q)) \\<in> seqp_sos \\<Gamma>;\n    \\<lbrakk>a = send (s\\<^sub>m\\<^sub>s\\<^sub>g \\<xi>); \\<xi>' = \\<xi>; q = p\\<rbrakk> \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  by (ind_cases \"((\\<xi>, {l}send(s\\<^sub>m\\<^sub>s\\<^sub>g). p), a, (\\<xi>', q)) \\<in> seqp_sos \\<Gamma>\") simp\n\nlemma seqp_deliverTE [elim]:\n  \"\\<lbrakk>((\\<xi>, {l}deliver(s\\<^sub>d\\<^sub>a\\<^sub>t\\<^sub>a). p), a, (\\<xi>', q)) \\<in> seqp_sos \\<Gamma>;\n    \\<lbrakk>a = deliver (s\\<^sub>d\\<^sub>a\\<^sub>t\\<^sub>a \\<xi>); \\<xi>' = \\<xi>; q = p\\<rbrakk> \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  by (ind_cases \"((\\<xi>, {l}deliver(s\\<^sub>d\\<^sub>a\\<^sub>t\\<^sub>a). p), a, (\\<xi>', q)) \\<in> seqp_sos \\<Gamma>\") simp\n\nlemma seqp_receiveTE [elim]:\n  \"\\<lbrakk>((\\<xi>, {l}receive(u\\<^sub>m\\<^sub>s\\<^sub>g). p), a, (\\<xi>', q)) \\<in> seqp_sos \\<Gamma>;\n    \\<And>msg. \\<lbrakk>a = receive msg; \\<xi>' = u\\<^sub>m\\<^sub>s\\<^sub>g msg \\<xi>; q = p\\<rbrakk> \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  by (ind_cases \"((\\<xi>, {l}receive(u\\<^sub>m\\<^sub>s\\<^sub>g). p), a, (\\<xi>', q)) \\<in> seqp_sos \\<Gamma>\") simp\n\nlemma seqp_assignTE [elim]:\n  \"\\<lbrakk>((\\<xi>, {l}\\<lbrakk>u\\<rbrakk> p), a, (\\<xi>', q)) \\<in> seqp_sos \\<Gamma>; \\<lbrakk>a = \\<tau>; \\<xi>' = u \\<xi>; q = p\\<rbrakk> \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  by (ind_cases \"((\\<xi>, {l}\\<lbrakk>u\\<rbrakk> p), a, (\\<xi>', q)) \\<in> seqp_sos \\<Gamma>\") simp\n\n\n\nlemmas seqpTEs =\n  seqp_broadcastTE\n  seqp_groupcastTE\n  seqp_unicastTE\n  seqp_sendTE\n  seqp_deliverTE\n  seqp_receiveTE\n  seqp_assignTE\n  seqp_callTE\n  seqp_choiceTE\n  seqp_guardTE\n\ndeclare seqp_sos.intros [intro]\n\nsubsection \"Table 2: Structural operational semantics for parallel process expressions \"\n\ninductive_set\n  parp_sos :: \"('s1, 'm seq_action) transition set\n                    \\<Rightarrow> ('s2, 'm seq_action) transition set\n                    \\<Rightarrow> ('s1 \\<times> 's2, 'm seq_action) transition set\"\n  for S :: \"('s1, 'm seq_action) transition set\"\n  and T :: \"('s2, 'm seq_action) transition set\"\nwhere\n    parleft:  \"\\<lbrakk> (s, a, s') \\<in> S; \\<And>m. a \\<noteq> receive m \\<rbrakk> \\<Longrightarrow> ((s, t), a, (s', t)) \\<in> parp_sos S T\"\n  | parright: \"\\<lbrakk> (t, a, t') \\<in> T; \\<And>m. a \\<noteq> send m \\<rbrakk> \\<Longrightarrow> ((s, t), a, (s, t')) \\<in> parp_sos S T\"\n  | parboth:  \"\\<lbrakk> (s, receive m, s') \\<in> S; (t, send m, t') \\<in> T \\<rbrakk>\n               \\<Longrightarrow>((s, t), \\<tau>, (s', t')) \\<in> parp_sos S T\"\n\nlemma par_broadcastTE [elim]:\n  \"\\<lbrakk>((s, t), broadcast m, (s', t')) \\<in> parp_sos S T;\n    \\<lbrakk>(s, broadcast m, s') \\<in> S; t' = t\\<rbrakk> \\<Longrightarrow> P;\n    \\<lbrakk>(t, broadcast m, t') \\<in> T; s' = s\\<rbrakk> \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  by (ind_cases \"((s, t), broadcast m, (s', t')) \\<in> parp_sos S T\") simp_all\n\nlemma par_groupcastTE [elim]:\n  \"\\<lbrakk>((s, t), groupcast ips m, (s', t')) \\<in> parp_sos S T;\n    \\<lbrakk>(s, groupcast ips m, s') \\<in> S; t' = t\\<rbrakk> \\<Longrightarrow> P;\n    \\<lbrakk>(t, groupcast ips m, t') \\<in> T; s' = s\\<rbrakk> \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  by (ind_cases \"((s, t), groupcast ips m, (s', t')) \\<in> parp_sos S T\") simp_all\n\nlemma par_unicastTE [elim]:\n  \"\\<lbrakk>((s, t), unicast i m, (s', t')) \\<in> parp_sos S T;\n    \\<lbrakk>(s, unicast i m, s') \\<in> S; t' = t\\<rbrakk> \\<Longrightarrow> P;\n    \\<lbrakk>(t, unicast i m, t') \\<in> T; s' = s\\<rbrakk> \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  by (ind_cases \"((s, t), unicast i m, (s', t')) \\<in> parp_sos S T\") simp_all\n\nlemma par_notunicastTE [elim]:\n  \"\\<lbrakk>((s, t), notunicast i, (s', t')) \\<in> parp_sos S T;\n    \\<lbrakk>(s, notunicast i, s') \\<in> S; t' = t\\<rbrakk> \\<Longrightarrow> P;\n    \\<lbrakk>(t, notunicast i, t') \\<in> T; s' = s\\<rbrakk> \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  by (ind_cases \"((s, t), notunicast i, (s', t')) \\<in> parp_sos S T\") simp_all\n\nlemma par_sendTE [elim]:\n  \"\\<lbrakk>((s, t), send m, (s', t')) \\<in> parp_sos S T;\n    \\<lbrakk>(s, send m, s') \\<in> S; t' = t\\<rbrakk> \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  by (ind_cases \"((s, t), send m, (s', t')) \\<in> parp_sos S T\") auto\n\nlemma par_deliverTE [elim]:\n  \"\\<lbrakk>((s, t), deliver d, (s', t')) \\<in> parp_sos S T;\n    \\<lbrakk>(s, deliver d, s') \\<in> S; t' = t\\<rbrakk> \\<Longrightarrow> P;\n    \\<lbrakk>(t, deliver d, t') \\<in> T; s' = s\\<rbrakk> \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  by (ind_cases \"((s, t), deliver d, (s', t')) \\<in> parp_sos S T\") simp_all\n\nlemma par_receiveTE [elim]:\n  \"\\<lbrakk>((s, t), receive m, (s', t')) \\<in> parp_sos S T;\n    \\<lbrakk>(t, receive m, t') \\<in> T; s' = s\\<rbrakk> \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  by (ind_cases \"((s, t), receive m, (s', t')) \\<in> parp_sos S T\") auto\n\ninductive_cases par_tauTE: \"((s, t), \\<tau>, (s', t')) \\<in> parp_sos S T\"\n\nlemmas parpTEs =\n  par_broadcastTE\n  par_groupcastTE\n  par_unicastTE\n  par_notunicastTE\n  par_sendTE\n  par_deliverTE\n  par_receiveTE\n\nlemma parp_sos_cases [elim]:\n  assumes \"((s, t), a, (s', t')) \\<in> parp_sos S T\"\n      and \"\\<lbrakk> (s, a, s') \\<in> S; \\<And>m. a \\<noteq> receive m; t' = t \\<rbrakk> \\<Longrightarrow> P\"\n      and \"\\<lbrakk> (t, a, t') \\<in> T; \\<And>m. a \\<noteq> send m; s' = s \\<rbrakk> \\<Longrightarrow> P\"\n      and \"\\<And>m. \\<lbrakk> (s, receive m, s') \\<in> S; (t, send m, t') \\<in> T \\<rbrakk> \\<Longrightarrow> P\"\n    shows \"P\"\n  using assms by cases auto\n\ndefinition\n  par_comp :: \"('s1, 'm seq_action) automaton\n              \\<Rightarrow> ('s2, 'm seq_action) automaton\n              \\<Rightarrow> ('s1 \\<times> 's2, 'm seq_action) automaton\"\n  (\"(_ \\<langle>\\<langle> _)\" [102, 103] 102)\nwhere\n  \"s \\<langle>\\<langle> t \\<equiv> \\<lparr> init = init s \\<times> init t, trans = parp_sos (trans s) (trans t) \\<rparr>\"\n\nlemma trans_par_comp [simp]:\n  \"trans (s \\<langle>\\<langle> t) = parp_sos (trans s) (trans t)\"\n  unfolding par_comp_def by simp\n\nlemma init_par_comp [simp]:\n  \"init (s \\<langle>\\<langle> t) = init s \\<times> init t\"\n  unfolding par_comp_def by simp\n\nsubsection \"Table 3: Structural operational semantics for node expressions \"\n\ninductive_set\n  node_sos :: \"('s, 'm seq_action) transition set \\<Rightarrow> ('s net_state, 'm node_action) transition set\"\n  for S :: \"('s, 'm seq_action) transition set\"\nwhere\n    node_bcast:\n    \"(s, broadcast m, s') \\<in> S \\<Longrightarrow> (NodeS i s R, R:*cast(m), NodeS i s' R) \\<in> node_sos S\"\n  | node_gcast:\n    \"(s, groupcast D m, s') \\<in> S \\<Longrightarrow> (NodeS i s R, (R\\<inter>D):*cast(m), NodeS i s' R) \\<in> node_sos S\"\n  | node_ucast:\n    \"\\<lbrakk> (s, unicast d m, s') \\<in> S; d\\<in>R \\<rbrakk> \\<Longrightarrow> (NodeS i s R, {d}:*cast(m), NodeS i s' R) \\<in> node_sos S\"\n  | node_notucast:\n    \"\\<lbrakk> (s, \\<not>unicast d, s') \\<in> S; d\\<notin>R \\<rbrakk> \\<Longrightarrow> (NodeS i s R, \\<tau>, NodeS i s' R) \\<in> node_sos S\"\n  | node_deliver:\n    \"(s, deliver d, s') \\<in> S \\<Longrightarrow> (NodeS i s R, i:deliver(d), NodeS i s' R) \\<in> node_sos S\"\n  | node_receive:\n    \"(s, receive m, s') \\<in> S \\<Longrightarrow> (NodeS i s R, {i}\\<not>{}:arrive(m), NodeS i s' R) \\<in> node_sos S\"\n  | node_tau:\n    \"(s, \\<tau>, s') \\<in> S         \\<Longrightarrow> (NodeS i s R, \\<tau>, NodeS i s' R) \\<in> node_sos S\"\n  | node_arrive:\n    \"(NodeS i s R, {}\\<not>{i}:arrive(m),  NodeS i s R) \\<in> node_sos S\"\n  | node_connect1:\n    \"(NodeS i s R, connect(i, i'),    NodeS i s (R \\<union> {i'})) \\<in> node_sos S\"\n  | node_connect2:\n    \"(NodeS i s R, connect(i', i),    NodeS i s (R \\<union> {i'})) \\<in> node_sos S\"\n  | node_disconnect1:\n    \"(NodeS i s R, disconnect(i, i'), NodeS i s (R - {i'})) \\<in> node_sos S\"\n  | node_disconnect2:\n    \"(NodeS i s R, disconnect(i', i), NodeS i s (R - {i'})) \\<in> node_sos S\"\n  | node_connect_other:\n    \"\\<lbrakk> i \\<noteq> i'; i \\<noteq> i'' \\<rbrakk> \\<Longrightarrow> (NodeS i s R, connect(i', i''), NodeS i s R) \\<in> node_sos S\"\n  | node_disconnect_other:\n    \"\\<lbrakk> i \\<noteq> i'; i \\<noteq> i'' \\<rbrakk> \\<Longrightarrow> (NodeS i s R, disconnect(i', i''), NodeS i s R) \\<in> node_sos S\"\n\ninductive_cases node_arriveTE:  \"(NodeS i s R, ii\\<not>ni:arrive(m), NodeS i s' R) \\<in> node_sos S\"\n            and node_arriveTE': \"(NodeS i s R, H\\<not>K:arrive(m), s') \\<in> node_sos S\"\n            and node_castTE:    \"(NodeS i s R, RM:*cast(m), NodeS i s' R') \\<in> node_sos S\"\n            and node_castTE':   \"(NodeS i s R, RM:*cast(m), s') \\<in> node_sos S\"\n            and node_deliverTE: \"(NodeS i s R, i:deliver(d), NodeS i s' R) \\<in> node_sos S\"\n            and node_deliverTE': \"(s, i:deliver(d), s') \\<in> node_sos S\"\n            and node_deliverTE'': \"(NodeS ii s R, i:deliver(d), s') \\<in> node_sos S\"\n            and node_tauTE:     \"(NodeS i s R, \\<tau>, NodeS i s' R) \\<in> node_sos S\"\n            and node_tauTE':    \"(NodeS i s R, \\<tau>, s') \\<in> node_sos S\"\n            and node_connectTE: \"(NodeS ii s R, connect(i, i'), NodeS ii s' R') \\<in> node_sos S\"\n            and node_connectTE': \"(NodeS ii s R, connect(i, i'), s') \\<in> node_sos S\"\n            and node_disconnectTE: \"(NodeS ii s R, disconnect(i, i'), NodeS ii s' R') \\<in> node_sos S\"\n            and node_disconnectTE': \"(NodeS ii s R, disconnect(i, i'), s') \\<in> node_sos S\"\n\nlemma node_sos_never_newpkt [simp]:\n  assumes \"(s, a, s') \\<in> node_sos S\"\n    shows \"a \\<noteq> i:newpkt(d, di)\"\n  using assms by cases auto\n\nlemma arrives_or_not:\n  assumes \"(NodeS i s R, ii\\<not>ni:arrive(m), NodeS i' s' R') \\<in> node_sos S\"\n    shows \"(ii = {i} \\<and> ni = {}) \\<or> (ii = {} \\<and> ni = {i})\"\n  using assms by rule simp_all\n\ndefinition\n  node_comp :: \"ip \\<Rightarrow> ('s, 'm seq_action) automaton \\<Rightarrow> ip set\n                   \\<Rightarrow> ('s net_state, 'm node_action) automaton\"\n    (\"(\\<langle>_ : (_) : _\\<rangle>)\" [0, 0, 0] 104)\nwhere\n  \"\\<langle>i : np : R\\<^sub>i\\<rangle> \\<equiv> \\<lparr> init = {NodeS i s R\\<^sub>i|s. s \\<in> init np}, trans = node_sos (trans np) \\<rparr>\"\n\nlemma trans_node_comp:\n  \"trans (\\<langle>i : np : R\\<^sub>i\\<rangle>) = node_sos (trans np)\"\n  unfolding node_comp_def by simp\n\nlemma init_node_comp:\n  \"init (\\<langle>i : np : R\\<^sub>i\\<rangle>) = {NodeS i s R\\<^sub>i|s. s \\<in> init np}\"\n  unfolding node_comp_def by simp\n\nlemmas node_comps = trans_node_comp init_node_comp\n\nlemma trans_par_node_comp [simp]:\n  \"trans (\\<langle>i : s \\<langle>\\<langle> t : R\\<rangle>) = node_sos (parp_sos (trans s) (trans t))\"\n  unfolding node_comp_def by simp\n\nlemma snd_par_node_comp [simp]:\n  \"init (\\<langle>i : s \\<langle>\\<langle> t : R\\<rangle>) = {NodeS i st R|st. st \\<in> init s \\<times> init t}\"\n  unfolding node_comp_def by simp\n\nlemma node_sos_dest_is_net_state:\n  assumes \"(s, a, s') \\<in> node_sos S\"\n    shows \"\\<exists>i' P' R'. s' = NodeS i' P' R'\"\n  using assms by induct auto\n\nlemma node_sos_dest:\n  assumes \"(NodeS i p R, a, s') \\<in> node_sos S\"\n    shows \"\\<exists>P' R'. s' = NodeS i P' R'\"\n  using assms assms [THEN node_sos_dest_is_net_state]\n  by - (erule node_sos.cases, auto)\n\nlemma node_sos_states [elim]:\n  assumes \"(ns, a, ns') \\<in> node_sos S\"\n  obtains i s R s' R' where \"ns  = NodeS i s  R\"\n                        and \"ns' = NodeS i s' R'\"\n  proof -\n    assume [intro!]: \"\\<And>i s R s' R'. ns = NodeS i s R \\<Longrightarrow> ns' = NodeS i s' R' \\<Longrightarrow> thesis\"\n    from assms(1) obtain i s R where \"ns = NodeS i s R\"\n      by (cases ns) auto\n    moreover with assms(1) obtain s' R' where \"ns' = NodeS i s' R'\"\n      by (metis node_sos_dest)\n    ultimately show thesis ..\n  qed\n\nlemma node_sos_cases [elim]:\n  \"(NodeS i p R, a, NodeS i p' R') \\<in> node_sos S \\<Longrightarrow>\n  (\\<And>m .       \\<lbrakk> a = R:*cast(m);          R' = R; (p, broadcast m, p') \\<in> S \\<rbrakk> \\<Longrightarrow> P) \\<Longrightarrow>\n  (\\<And>m D.      \\<lbrakk> a = (R \\<inter> D):*cast(m);    R' = R; (p, groupcast D m, p') \\<in> S \\<rbrakk> \\<Longrightarrow> P) \\<Longrightarrow>\n  (\\<And>d m.      \\<lbrakk> a = {d}:*cast(m);        R' = R; (p, unicast d m, p') \\<in> S; d \\<in> R \\<rbrakk> \\<Longrightarrow> P) \\<Longrightarrow>\n  (\\<And>d.        \\<lbrakk> a = \\<tau>;                   R' = R; (p, \\<not>unicast d, p') \\<in> S; d \\<notin> R \\<rbrakk> \\<Longrightarrow> P) \\<Longrightarrow>\n  (\\<And>d.        \\<lbrakk> a = i:deliver(d);        R' = R; (p, deliver d, p') \\<in> S \\<rbrakk> \\<Longrightarrow> P) \\<Longrightarrow>\n  (\\<And>m.        \\<lbrakk> a = {i}\\<not>{}:arrive(m);    R' = R; (p, receive m, p') \\<in> S \\<rbrakk> \\<Longrightarrow> P) \\<Longrightarrow>\n  (            \\<lbrakk> a = \\<tau>;                   R' = R; (p, \\<tau>, p') \\<in> S \\<rbrakk> \\<Longrightarrow> P) \\<Longrightarrow>\n  (\\<And>m.        \\<lbrakk> a = {}\\<not>{i}:arrive(m);    R' = R; p = p' \\<rbrakk> \\<Longrightarrow> P) \\<Longrightarrow>\n  (\\<And>i i'.     \\<lbrakk> a = connect(i, i');      R' = R \\<union> {i'}; p = p' \\<rbrakk> \\<Longrightarrow> P) \\<Longrightarrow>\n  (\\<And>i i'.     \\<lbrakk> a = connect(i', i);      R' = R \\<union> {i'}; p = p' \\<rbrakk> \\<Longrightarrow> P) \\<Longrightarrow>\n  (\\<And>i i'.     \\<lbrakk> a = disconnect(i, i');   R' = R - {i'}; p = p' \\<rbrakk> \\<Longrightarrow> P) \\<Longrightarrow>\n  (\\<And>i i'.     \\<lbrakk> a = disconnect(i', i);   R' = R - {i'}; p = p' \\<rbrakk> \\<Longrightarrow> P) \\<Longrightarrow>\n  (\\<And>i i' i''. \\<lbrakk> a = connect(i', i'');    R' = R; p = p'; i \\<noteq> i'; i \\<noteq> i'' \\<rbrakk> \\<Longrightarrow> P) \\<Longrightarrow>\n  (\\<And>i i' i''. \\<lbrakk> a = disconnect(i', i''); R' = R; p = p'; i \\<noteq> i'; i \\<noteq> i'' \\<rbrakk> \\<Longrightarrow> P) \\<Longrightarrow>\n  P\"\n  by (erule node_sos.cases) simp_all\n\nsubsection \"Table 4: Structural operational semantics for partial network expressions \"\n\ninductive_set\n  pnet_sos :: \"('s net_state, 'm node_action) transition set\n                    \\<Rightarrow> ('s net_state, 'm node_action) transition set\n                    \\<Rightarrow> ('s net_state, 'm node_action) transition set\"\n  for S :: \"('s net_state, 'm node_action) transition set\"\n  and T :: \"('s net_state, 'm node_action) transition set\"\nwhere\n    pnet_cast1: \"\\<lbrakk> (s, R:*cast(m), s') \\<in> S; (t, H\\<not>K:arrive(m), t') \\<in> T; H \\<subseteq> R; K \\<inter> R = {} \\<rbrakk>\n      \\<Longrightarrow> (SubnetS s t, R:*cast(m), SubnetS s' t') \\<in> pnet_sos S T\"\n\n  | pnet_cast2: \"\\<lbrakk> (s, H\\<not>K:arrive(m), s') \\<in> S; (t, R:*cast(m), t') \\<in> T;  H \\<subseteq> R; K \\<inter> R = {} \\<rbrakk>\n      \\<Longrightarrow> (SubnetS s t, R:*cast(m), SubnetS s' t') \\<in> pnet_sos S T\"\n\n  | pnet_arrive: \"\\<lbrakk> (s, H\\<not>K:arrive(m), s') \\<in> S; (t, H'\\<not>K':arrive(m), t') \\<in> T \\<rbrakk>\n      \\<Longrightarrow> (SubnetS s t,  (H \\<union> H')\\<not>(K \\<union> K'):arrive(m), SubnetS s' t') \\<in> pnet_sos S T\"\n\n  | pnet_deliver1: \"(s, i:deliver(d), s') \\<in> S\n      \\<Longrightarrow> (SubnetS s t, i:deliver(d), SubnetS s' t) \\<in> pnet_sos S T\"\n  | pnet_deliver2: \"\\<lbrakk> (t, i:deliver(d), t') \\<in> T \\<rbrakk>\n      \\<Longrightarrow> (SubnetS s t, i:deliver(d), SubnetS s t') \\<in> pnet_sos S T\"\n\n  | pnet_tau1: \"(s, \\<tau>, s') \\<in> S \\<Longrightarrow> (SubnetS s t, \\<tau>, SubnetS s' t) \\<in> pnet_sos S T\"\n  | pnet_tau2: \"(t, \\<tau>, t') \\<in> T \\<Longrightarrow> (SubnetS s t, \\<tau>, SubnetS s t') \\<in> pnet_sos S T\"\n\n  | pnet_connect: \"\\<lbrakk> (s, connect(i, i'), s') \\<in> S; (t, connect(i, i'), t') \\<in> T \\<rbrakk>\n      \\<Longrightarrow> (SubnetS s t, connect(i, i'), SubnetS s' t') \\<in> pnet_sos S T\"\n\n  | pnet_disconnect: \"\\<lbrakk> (s, disconnect(i, i'), s') \\<in> S; (t, disconnect(i, i'), t') \\<in> T \\<rbrakk>\n      \\<Longrightarrow> (SubnetS s t, disconnect(i, i'), SubnetS s' t') \\<in> pnet_sos S T\"\n\ninductive_cases partial_castTE [elim]:       \"(s, R:*cast(m), s') \\<in> pnet_sos S T\"\n            and partial_arriveTE [elim]:     \"(s, H\\<not>K:arrive(m), s') \\<in> pnet_sos S T\"\n            and partial_deliverTE [elim]:    \"(s, i:deliver(d), s') \\<in> pnet_sos S T\"\n            and partial_tauTE [elim]:        \"(s, \\<tau>, s') \\<in> pnet_sos S T\"\n            and partial_connectTE [elim]:    \"(s, connect(i, i'), s') \\<in> pnet_sos S T\"\n            and partial_disconnectTE [elim]: \"(s, disconnect(i, i'), s') \\<in> pnet_sos S T\"\n\nlemma pnet_sos_never_newpkt:\n  assumes \"(st, a, st') \\<in> pnet_sos S T\"\n      and \"\\<And>i d di a s s'. (s, a, s') \\<in> S \\<Longrightarrow> a \\<noteq> i:newpkt(d, di)\"\n      and \"\\<And>i d di a t t'. (t, a, t') \\<in> T \\<Longrightarrow> a \\<noteq> i:newpkt(d, di)\"\n    shows \"a \\<noteq> i:newpkt(d, di)\"\n  using assms(1) by cases (auto dest!: assms(2-3))\n\nfun pnet :: \"(ip \\<Rightarrow> ('s, 'm seq_action) automaton)\n              \\<Rightarrow> net_tree \\<Rightarrow> ('s net_state, 'm node_action) automaton\"\nwhere\n    \"pnet np (\\<langle>i; R\\<^sub>i\\<rangle>)  =  \\<langle>i : np i : R\\<^sub>i\\<rangle>\"\n  | \"pnet np (p\\<^sub>1 \\<parallel> p\\<^sub>2) = \\<lparr> init = {SubnetS s\\<^sub>1 s\\<^sub>2 |s\\<^sub>1 s\\<^sub>2. s\\<^sub>1 \\<in> init (pnet np p\\<^sub>1)\n                                                      \\<and> s\\<^sub>2 \\<in> init (pnet np p\\<^sub>2)},\n                           trans = pnet_sos (trans (pnet np p\\<^sub>1)) (trans (pnet np p\\<^sub>2)) \\<rparr>\"\n\nlemma pnet_node_init [elim, simp]:\n  assumes \"s \\<in> init (pnet np \\<langle>i; R\\<rangle>)\"\n    shows \"s \\<in> { NodeS i s R |s. s \\<in> init (np i)}\"\n  using assms by (simp add: node_comp_def)\n\nlemma pnet_node_init' [elim]:\n assumes \"s \\<in> init (pnet np \\<langle>i; R\\<rangle>)\"\n obtains ns where \"s = NodeS i ns R\"\n             and \"ns \\<in> init (np i)\"\n   using assms by (auto simp add: node_comp_def)\n\nlemma pnet_node_trans [elim, simp]:\n  assumes \"(s, a, s') \\<in> trans (pnet np \\<langle>i; R\\<rangle>)\"\n    shows \"(s, a, s') \\<in> node_sos (trans (np i))\"\n  using assms by (simp add: trans_node_comp)\n\nlemma pnet_never_newpkt':\n  assumes \"(s, a, s') \\<in> trans (pnet np n)\"\n    shows \"\\<forall>i d di. a \\<noteq> i:newpkt(d, di)\"\n  using assms proof (induction n arbitrary: s a s')\n    fix n1 n2 s a s'\n    assume IH1: \"\\<And>s a s'. (s, a, s') \\<in> trans (pnet np n1) \\<Longrightarrow> \\<forall>i d di. a \\<noteq> i:newpkt(d, di)\"\n       and IH2: \"\\<And>s a s'. (s, a, s') \\<in> trans (pnet np n2) \\<Longrightarrow> \\<forall>i d di. a \\<noteq> i:newpkt(d, di)\"\n       and \"(s, a, s') \\<in> trans (pnet np (n1 \\<parallel> n2))\"\n    show \"\\<forall>i d di. a \\<noteq> i:newpkt(d, di)\"\n    proof (intro allI)\n      fix i d di\n      from \\<open>(s, a, s') \\<in> trans (pnet np (n1 \\<parallel> n2))\\<close>\n        have \"(s, a, s') \\<in> pnet_sos (trans (pnet np n1)) (trans (pnet np n2))\"\n          by simp\n      thus \"a \\<noteq> i:newpkt(d, di)\"\n        by (rule pnet_sos_never_newpkt) (auto dest!: IH1 IH2)\n    qed\n  qed (simp add: node_comps)\n\nlemma pnet_never_newpkt:\n  assumes \"(s, a, s') \\<in> trans (pnet np n)\"\n    shows \"a \\<noteq> i:newpkt(d, di)\"\n  proof -\n    from assms have \"\\<forall>i d di. a \\<noteq> i:newpkt(d, di)\"\n      by (rule pnet_never_newpkt')\n    thus ?thesis by clarsimp\n  qed\n\nsubsection \"Table 5: Structural operational semantics for complete network expressions \"\n\ninductive_set\n  cnet_sos :: \"('s, ('m::msg) node_action) transition set\n                    \\<Rightarrow> ('s, 'm node_action) transition set\"\n  for S :: \"('s, 'm node_action) transition set\"\nwhere\n    cnet_connect: \"(s, connect(i, i'), s') \\<in> S  \\<Longrightarrow> (s, connect(i, i'), s') \\<in> cnet_sos S\"\n  | cnet_disconnect: \"(s, disconnect(i, i'), s') \\<in> S  \\<Longrightarrow> (s, disconnect(i, i'), s') \\<in> cnet_sos S\"\n  | cnet_cast: \"(s, R:*cast(m), s') \\<in> S  \\<Longrightarrow> (s, \\<tau>, s') \\<in> cnet_sos S\"\n  | cnet_tau: \"(s, \\<tau>, s') \\<in> S  \\<Longrightarrow> (s, \\<tau>, s') \\<in> cnet_sos S\"\n  | cnet_deliver: \"(s, i:deliver(d), s') \\<in> S  \\<Longrightarrow> (s, i:deliver(d), s') \\<in> cnet_sos S\"\n  | cnet_newpkt: \"(s, {i}\\<not>K:arrive(newpkt(d, di)), s') \\<in> S  \\<Longrightarrow> (s, i:newpkt(d, di), s') \\<in> cnet_sos S\"\n\ninductive_cases connect_completeTE: \"(s, connect(i, i'), s') \\<in> cnet_sos S\"\n            and disconnect_completeTE: \"(s, disconnect(i, i'), s') \\<in> cnet_sos S\"\n            and tau_completeTE: \"(s, \\<tau>, s') \\<in> cnet_sos S\"\n            and deliver_completeTE: \"(s, i:deliver(d), s') \\<in> cnet_sos S\"\n            and newpkt_completeTE: \"(s, i:newpkt(d, di), s') \\<in> cnet_sos S\"\n\nlemmas completeTEs = connect_completeTE\n                     disconnect_completeTE\n                     tau_completeTE\n                     deliver_completeTE\n                     newpkt_completeTE\n\nlemma complete_no_cast [simp]:\n  \"(s, R:*cast(m), s') \\<notin> cnet_sos T\"\n  proof\n    assume \"(s, R:*cast(m), s') \\<in> cnet_sos T\"\n    hence \"R:*cast(m) \\<noteq> R:*cast(m)\"\n     by (rule cnet_sos.cases) auto\n    thus False by simp\n  qed\n\nlemma complete_no_arrive [simp]:\n  \"(s, ii\\<not>ni:arrive(m), s') \\<notin> cnet_sos T\"\n  proof\n    assume \"(s, ii\\<not>ni:arrive(m), s') \\<in> cnet_sos T\"\n    hence \"ii\\<not>ni:arrive(m) \\<noteq> ii\\<not>ni:arrive(m)\"\n     by (rule cnet_sos.cases) auto\n    thus False by simp\n  qed\n\nabbreviation\n  closed :: \"('s net_state, ('m::msg) node_action) automaton \\<Rightarrow> ('s net_state, 'm node_action) automaton\"\nwhere\n  \"closed \\<equiv> (\\<lambda>A. A \\<lparr> trans := cnet_sos (trans A) \\<rparr>)\"\n\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/AWN/AWN_SOS.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926665999540698, "lm_q2_score": 0.4921881357207956, "lm_q1q2_score": 0.2917034689353762}}
{"text": "theory Proofs2\n  imports Requirements VCTheoryLemmas\nbegin\n\ndefinition inv2 where \"inv2 s \\<equiv> R2 s \\<and> extraInv s\"\n\ntheorem proof_2_1: \"VC1 inv2 s0\"\n  apply(unfold VC1_def inv2_def R2_def extraInv_def)\n  by auto\n\ntheorem proof_2_338: \"VC338 R2 env s0 PdOut_value paid_value opened_value\"\n  apply(unfold VC338_def inv2_def R2_def extraInv_def)\n  by auto\n\ntheorem proof_2_339: \"VC339 R2 env s0 PdOut_value paid_value opened_value\"\n  apply(unfold VC339_def inv2_def R2_def extraInv_def)\n  by auto\n\ntheorem proof_2_340: \"VC340 R2 env s0 PdOut_value paid_value opened_value\"\n  apply(unfold VC340_def inv2_def R2_def extraInv_def)\n  by auto\n\ntheorem proof_2_341: \"VC341 R2 env s0 PdOut_value paid_value opened_value\"\n  apply(unfold VC341_def inv2_def R2_def extraInv_def)\n  by auto\n\ntheorem proof_2_342: \"VC342 R2 env s0 PdOut_value paid_value opened_value\"\n  apply(unfold VC342_def inv2_def R2_def extraInv_def)\n  by auto\n\ntheorem proof_2_343: \"VC343 R2 env s0 PdOut_value paid_value opened_value\"\n  apply(unfold VC343_def inv2_def R2_def extraInv_def)\n  by auto\n\ntheorem proof_2_344: \"VC344 R2 env s0 PdOut_value paid_value opened_value\"\n  apply(unfold VC344_def inv2_def R2_def extraInv_def)\n  by auto\n\ntheorem proof_2_345: \"VC345 R2 env s0 PdOut_value paid_value opened_value\"\n  apply(unfold VC345_def inv2_def R2_def extraInv_def)\n  by auto\n\ntheorem proof_2_346: \"VC346 R2 env s0 PdOut_value paid_value opened_value\"\n  apply(unfold VC346_def inv2_def R2_def extraInv_def)\n  by auto\n\ntheorem proof_2_347: \"VC347 R2 env s0 PdOut_value paid_value opened_value\"\n  apply(unfold VC347_def inv2_def R2_def extraInv_def)\n  by auto\n\ntheorem proof_2_348: \"VC348 R2 env s0 PdOut_value paid_value opened_value\"\n  apply(unfold VC348_def inv2_def R2_def extraInv_def)\n  by auto\n\ntheorem proof_2_362: \"VC362 R2 env s0 PdOut_value paid_value opened_value\"\n  apply(unfold VC362_def inv2_def R2_def extraInv_def)\n  apply(rule impI)\n  apply(rule conjI)\n   apply simp\n  apply((rule allI)+)\n  apply(rule impI)\n  apply(simp split: if_splits)\n  using substate_toEnvNum_id apply blast\n  by auto\n\nend", "meta": {"author": "ivchernenko", "repo": "post_vcgenerator", "sha": "fadfff131086870a027d6bd1c78b8d5a3baf183b", "save_path": "github-repos/isabelle/ivchernenko-post_vcgenerator", "path": "github-repos/isabelle/ivchernenko-post_vcgenerator/post_vcgenerator-fadfff131086870a027d6bd1c78b8d5a3baf183b/case-studies/turnstile/Proofs2.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5926665999540698, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.29170346893537613}}
{"text": "(*  Title:      HOL/Extraction.thy\n    Author:     Stefan Berghofer, TU Muenchen\n*)\n\nsection {* Program extraction for HOL *}\n\ntheory Extraction\nimports Option\nbegin\n\nML_file \"Tools/rewrite_hol_proof.ML\"\n\nsubsection {* Setup *}\n\nsetup {*\n  Extraction.add_types\n      [(\"bool\", ([], NONE))] #>\n  Extraction.set_preprocessor (fn thy =>\n      Proofterm.rewrite_proof_notypes\n        ([], RewriteHOLProof.elim_cong :: ProofRewriteRules.rprocs true) o\n      Proofterm.rewrite_proof thy\n        (RewriteHOLProof.rews,\n         ProofRewriteRules.rprocs true @ [ProofRewriteRules.expand_of_class thy]) o\n      ProofRewriteRules.elim_vars (curry Const @{const_name default}))\n*}\n\nlemmas [extraction_expand] =\n  meta_spec atomize_eq atomize_all atomize_imp atomize_conj\n  allE rev_mp conjE Eq_TrueI Eq_FalseI eqTrueI eqTrueE eq_cong2\n  notE' impE' impE iffE imp_cong simp_thms eq_True eq_False\n  induct_forall_eq induct_implies_eq induct_equal_eq induct_conj_eq\n  induct_atomize induct_atomize' induct_rulify induct_rulify'\n  induct_rulify_fallback induct_trueI\n  True_implies_equals TrueE\n\nlemmas [extraction_expand_def] =\n  induct_forall_def induct_implies_def induct_equal_def induct_conj_def\n  induct_true_def induct_false_def\n\ndatatype (plugins only: code extraction) sumbool = Left | Right\n\nsubsection {* Type of extracted program *}\n\nextract_type\n  \"typeof (Trueprop P) \\<equiv> typeof P\"\n\n  \"typeof P \\<equiv> Type (TYPE(Null)) \\<Longrightarrow> typeof Q \\<equiv> Type (TYPE('Q)) \\<Longrightarrow>\n     typeof (P \\<longrightarrow> Q) \\<equiv> Type (TYPE('Q))\"\n\n  \"typeof Q \\<equiv> Type (TYPE(Null)) \\<Longrightarrow> typeof (P \\<longrightarrow> Q) \\<equiv> Type (TYPE(Null))\"\n\n  \"typeof P \\<equiv> Type (TYPE('P)) \\<Longrightarrow> typeof Q \\<equiv> Type (TYPE('Q)) \\<Longrightarrow>\n     typeof (P \\<longrightarrow> Q) \\<equiv> Type (TYPE('P \\<Rightarrow> 'Q))\"\n\n  \"(\\<lambda>x. typeof (P x)) \\<equiv> (\\<lambda>x. Type (TYPE(Null))) \\<Longrightarrow>\n     typeof (\\<forall>x. P x) \\<equiv> Type (TYPE(Null))\"\n\n  \"(\\<lambda>x. typeof (P x)) \\<equiv> (\\<lambda>x. Type (TYPE('P))) \\<Longrightarrow>\n     typeof (\\<forall>x::'a. P x) \\<equiv> Type (TYPE('a \\<Rightarrow> 'P))\"\n\n  \"(\\<lambda>x. typeof (P x)) \\<equiv> (\\<lambda>x. Type (TYPE(Null))) \\<Longrightarrow>\n     typeof (\\<exists>x::'a. P x) \\<equiv> Type (TYPE('a))\"\n\n  \"(\\<lambda>x. typeof (P x)) \\<equiv> (\\<lambda>x. Type (TYPE('P))) \\<Longrightarrow>\n     typeof (\\<exists>x::'a. P x) \\<equiv> Type (TYPE('a \\<times> 'P))\"\n\n  \"typeof P \\<equiv> Type (TYPE(Null)) \\<Longrightarrow> typeof Q \\<equiv> Type (TYPE(Null)) \\<Longrightarrow>\n     typeof (P \\<or> Q) \\<equiv> Type (TYPE(sumbool))\"\n\n  \"typeof P \\<equiv> Type (TYPE(Null)) \\<Longrightarrow> typeof Q \\<equiv> Type (TYPE('Q)) \\<Longrightarrow>\n     typeof (P \\<or> Q) \\<equiv> Type (TYPE('Q option))\"\n\n  \"typeof P \\<equiv> Type (TYPE('P)) \\<Longrightarrow> typeof Q \\<equiv> Type (TYPE(Null)) \\<Longrightarrow>\n     typeof (P \\<or> Q) \\<equiv> Type (TYPE('P option))\"\n\n  \"typeof P \\<equiv> Type (TYPE('P)) \\<Longrightarrow> typeof Q \\<equiv> Type (TYPE('Q)) \\<Longrightarrow>\n     typeof (P \\<or> Q) \\<equiv> Type (TYPE('P + 'Q))\"\n\n  \"typeof P \\<equiv> Type (TYPE(Null)) \\<Longrightarrow> typeof Q \\<equiv> Type (TYPE('Q)) \\<Longrightarrow>\n     typeof (P \\<and> Q) \\<equiv> Type (TYPE('Q))\"\n\n  \"typeof P \\<equiv> Type (TYPE('P)) \\<Longrightarrow> typeof Q \\<equiv> Type (TYPE(Null)) \\<Longrightarrow>\n     typeof (P \\<and> Q) \\<equiv> Type (TYPE('P))\"\n\n  \"typeof P \\<equiv> Type (TYPE('P)) \\<Longrightarrow> typeof Q \\<equiv> Type (TYPE('Q)) \\<Longrightarrow>\n     typeof (P \\<and> Q) \\<equiv> Type (TYPE('P \\<times> 'Q))\"\n\n  \"typeof (P = Q) \\<equiv> typeof ((P \\<longrightarrow> Q) \\<and> (Q \\<longrightarrow> P))\"\n\n  \"typeof (x \\<in> P) \\<equiv> typeof P\"\n\nsubsection {* Realizability *}\n\nrealizability\n  \"(realizes t (Trueprop P)) \\<equiv> (Trueprop (realizes t P))\"\n\n  \"(typeof P) \\<equiv> (Type (TYPE(Null))) \\<Longrightarrow>\n     (realizes t (P \\<longrightarrow> Q)) \\<equiv> (realizes Null P \\<longrightarrow> realizes t Q)\"\n\n  \"(typeof P) \\<equiv> (Type (TYPE('P))) \\<Longrightarrow>\n   (typeof Q) \\<equiv> (Type (TYPE(Null))) \\<Longrightarrow>\n     (realizes t (P \\<longrightarrow> Q)) \\<equiv> (\\<forall>x::'P. realizes x P \\<longrightarrow> realizes Null Q)\"\n\n  \"(realizes t (P \\<longrightarrow> Q)) \\<equiv> (\\<forall>x. realizes x P \\<longrightarrow> realizes (t x) Q)\"\n\n  \"(\\<lambda>x. typeof (P x)) \\<equiv> (\\<lambda>x. Type (TYPE(Null))) \\<Longrightarrow>\n     (realizes t (\\<forall>x. P x)) \\<equiv> (\\<forall>x. realizes Null (P x))\"\n\n  \"(realizes t (\\<forall>x. P x)) \\<equiv> (\\<forall>x. realizes (t x) (P x))\"\n\n  \"(\\<lambda>x. typeof (P x)) \\<equiv> (\\<lambda>x. Type (TYPE(Null))) \\<Longrightarrow>\n     (realizes t (\\<exists>x. P x)) \\<equiv> (realizes Null (P t))\"\n\n  \"(realizes t (\\<exists>x. P x)) \\<equiv> (realizes (snd t) (P (fst t)))\"\n\n  \"(typeof P) \\<equiv> (Type (TYPE(Null))) \\<Longrightarrow>\n   (typeof Q) \\<equiv> (Type (TYPE(Null))) \\<Longrightarrow>\n     (realizes t (P \\<or> Q)) \\<equiv>\n     (case t of Left \\<Rightarrow> realizes Null P | Right \\<Rightarrow> realizes Null Q)\"\n\n  \"(typeof P) \\<equiv> (Type (TYPE(Null))) \\<Longrightarrow>\n     (realizes t (P \\<or> Q)) \\<equiv>\n     (case t of None \\<Rightarrow> realizes Null P | Some q \\<Rightarrow> realizes q Q)\"\n\n  \"(typeof Q) \\<equiv> (Type (TYPE(Null))) \\<Longrightarrow>\n     (realizes t (P \\<or> Q)) \\<equiv>\n     (case t of None \\<Rightarrow> realizes Null Q | Some p \\<Rightarrow> realizes p P)\"\n\n  \"(realizes t (P \\<or> Q)) \\<equiv>\n   (case t of Inl p \\<Rightarrow> realizes p P | Inr q \\<Rightarrow> realizes q Q)\"\n\n  \"(typeof P) \\<equiv> (Type (TYPE(Null))) \\<Longrightarrow>\n     (realizes t (P \\<and> Q)) \\<equiv> (realizes Null P \\<and> realizes t Q)\"\n\n  \"(typeof Q) \\<equiv> (Type (TYPE(Null))) \\<Longrightarrow>\n     (realizes t (P \\<and> Q)) \\<equiv> (realizes t P \\<and> realizes Null Q)\"\n\n  \"(realizes t (P \\<and> Q)) \\<equiv> (realizes (fst t) P \\<and> realizes (snd t) Q)\"\n\n  \"typeof P \\<equiv> Type (TYPE(Null)) \\<Longrightarrow>\n     realizes t (\\<not> P) \\<equiv> \\<not> realizes Null P\"\n\n  \"typeof P \\<equiv> Type (TYPE('P)) \\<Longrightarrow>\n     realizes t (\\<not> P) \\<equiv> (\\<forall>x::'P. \\<not> realizes x P)\"\n\n  \"typeof (P::bool) \\<equiv> Type (TYPE(Null)) \\<Longrightarrow>\n   typeof Q \\<equiv> Type (TYPE(Null)) \\<Longrightarrow>\n     realizes t (P = Q) \\<equiv> realizes Null P = realizes Null Q\"\n\n  \"(realizes t (P = Q)) \\<equiv> (realizes t ((P \\<longrightarrow> Q) \\<and> (Q \\<longrightarrow> P)))\"\n\nsubsection {* Computational content of basic inference rules *}\n\ntheorem disjE_realizer:\n  assumes r: \"case x of Inl p \\<Rightarrow> P p | Inr q \\<Rightarrow> Q q\"\n  and r1: \"\\<And>p. P p \\<Longrightarrow> R (f p)\" and r2: \"\\<And>q. Q q \\<Longrightarrow> R (g q)\"\n  shows \"R (case x of Inl p \\<Rightarrow> f p | Inr q \\<Rightarrow> g q)\"\nproof (cases x)\n  case Inl\n  with r show ?thesis by simp (rule r1)\nnext\n  case Inr\n  with r show ?thesis by simp (rule r2)\nqed\n\ntheorem disjE_realizer2:\n  assumes r: \"case x of None \\<Rightarrow> P | Some q \\<Rightarrow> Q q\"\n  and r1: \"P \\<Longrightarrow> R f\" and r2: \"\\<And>q. Q q \\<Longrightarrow> R (g q)\"\n  shows \"R (case x of None \\<Rightarrow> f | Some q \\<Rightarrow> g q)\"\nproof (cases x)\n  case None\n  with r show ?thesis by simp (rule r1)\nnext\n  case Some\n  with r show ?thesis by simp (rule r2)\nqed\n\ntheorem disjE_realizer3:\n  assumes r: \"case x of Left \\<Rightarrow> P | Right \\<Rightarrow> Q\"\n  and r1: \"P \\<Longrightarrow> R f\" and r2: \"Q \\<Longrightarrow> R g\"\n  shows \"R (case x of Left \\<Rightarrow> f | Right \\<Rightarrow> g)\"\nproof (cases x)\n  case Left\n  with r show ?thesis by simp (rule r1)\nnext\n  case Right\n  with r show ?thesis by simp (rule r2)\nqed\n\ntheorem conjI_realizer:\n  \"P p \\<Longrightarrow> Q q \\<Longrightarrow> P (fst (p, q)) \\<and> Q (snd (p, q))\"\n  by simp\n\ntheorem exI_realizer:\n  \"P y x \\<Longrightarrow> P (snd (x, y)) (fst (x, y))\" by simp\n\ntheorem exE_realizer: \"P (snd p) (fst p) \\<Longrightarrow>\n  (\\<And>x y. P y x \\<Longrightarrow> Q (f x y)) \\<Longrightarrow> Q (let (x, y) = p in f x y)\"\n  by (cases p) (simp add: Let_def)\n\ntheorem exE_realizer': \"P (snd p) (fst p) \\<Longrightarrow>\n  (\\<And>x y. P y x \\<Longrightarrow> Q) \\<Longrightarrow> Q\" by (cases p) simp\n\nrealizers\n  impI (P, Q): \"\\<lambda>pq. pq\"\n    \"\\<^bold>\\<lambda>(c: _) (d: _) P Q pq (h: _). allI \\<cdot> _ \\<bullet> c \\<bullet> (\\<^bold>\\<lambda>x. impI \\<cdot> _ \\<cdot> _ \\<bullet> (h \\<cdot> x))\"\n\n  impI (P): \"Null\"\n    \"\\<^bold>\\<lambda>(c: _) P Q (h: _). allI \\<cdot> _ \\<bullet> c \\<bullet> (\\<^bold>\\<lambda>x. impI \\<cdot> _ \\<cdot> _ \\<bullet> (h \\<cdot> x))\"\n\n  impI (Q): \"\\<lambda>q. q\" \"\\<^bold>\\<lambda>(c: _) P Q q. impI \\<cdot> _ \\<cdot> _\"\n\n  impI: \"Null\" \"impI\"\n\n  mp (P, Q): \"\\<lambda>pq. pq\"\n    \"\\<^bold>\\<lambda>(c: _) (d: _) P Q pq (h: _) p. mp \\<cdot> _ \\<cdot> _ \\<bullet> (spec \\<cdot> _ \\<cdot> p \\<bullet> c \\<bullet> h)\"\n\n  mp (P): \"Null\"\n    \"\\<^bold>\\<lambda>(c: _) P Q (h: _) p. mp \\<cdot> _ \\<cdot> _ \\<bullet> (spec \\<cdot> _ \\<cdot> p \\<bullet> c \\<bullet> h)\"\n\n  mp (Q): \"\\<lambda>q. q\" \"\\<^bold>\\<lambda>(c: _) P Q q. mp \\<cdot> _ \\<cdot> _\"\n\n  mp: \"Null\" \"mp\"\n\n  allI (P): \"\\<lambda>p. p\" \"\\<^bold>\\<lambda>(c: _) P (d: _) p. allI \\<cdot> _ \\<bullet> d\"\n\n  allI: \"Null\" \"allI\"\n\n  spec (P): \"\\<lambda>x p. p x\" \"\\<^bold>\\<lambda>(c: _) P x (d: _) p. spec \\<cdot> _ \\<cdot> x \\<bullet> d\"\n\n  spec: \"Null\" \"spec\"\n\n  exI (P): \"\\<lambda>x p. (x, p)\" \"\\<^bold>\\<lambda>(c: _) P x (d: _) p. exI_realizer \\<cdot> P \\<cdot> p \\<cdot> x \\<bullet> c \\<bullet> d\"\n\n  exI: \"\\<lambda>x. x\" \"\\<^bold>\\<lambda>P x (c: _) (h: _). h\"\n\n  exE (P, Q): \"\\<lambda>p pq. let (x, y) = p in pq x y\"\n    \"\\<^bold>\\<lambda>(c: _) (d: _) P Q (e: _) p (h: _) pq. exE_realizer \\<cdot> P \\<cdot> p \\<cdot> Q \\<cdot> pq \\<bullet> c \\<bullet> e \\<bullet> d \\<bullet> h\"\n\n  exE (P): \"Null\"\n    \"\\<^bold>\\<lambda>(c: _) P Q (d: _) p. exE_realizer' \\<cdot> _ \\<cdot> _ \\<cdot> _ \\<bullet> c \\<bullet> d\"\n\n  exE (Q): \"\\<lambda>x pq. pq x\"\n    \"\\<^bold>\\<lambda>(c: _) P Q (d: _) x (h1: _) pq (h2: _). h2 \\<cdot> x \\<bullet> h1\"\n\n  exE: \"Null\"\n    \"\\<^bold>\\<lambda>P Q (c: _) x (h1: _) (h2: _). h2 \\<cdot> x \\<bullet> h1\"\n\n  conjI (P, Q): \"Pair\"\n    \"\\<^bold>\\<lambda>(c: _) (d: _) P Q p (h: _) q. conjI_realizer \\<cdot> P \\<cdot> p \\<cdot> Q \\<cdot> q \\<bullet> c \\<bullet> d \\<bullet> h\"\n\n  conjI (P): \"\\<lambda>p. p\"\n    \"\\<^bold>\\<lambda>(c: _) P Q p. conjI \\<cdot> _ \\<cdot> _\"\n\n  conjI (Q): \"\\<lambda>q. q\"\n    \"\\<^bold>\\<lambda>(c: _) P Q (h: _) q. conjI \\<cdot> _ \\<cdot> _ \\<bullet> h\"\n\n  conjI: \"Null\" \"conjI\"\n\n  conjunct1 (P, Q): \"fst\"\n    \"\\<^bold>\\<lambda>(c: _) (d: _) P Q pq. conjunct1 \\<cdot> _ \\<cdot> _\"\n\n  conjunct1 (P): \"\\<lambda>p. p\"\n    \"\\<^bold>\\<lambda>(c: _) P Q p. conjunct1 \\<cdot> _ \\<cdot> _\"\n\n  conjunct1 (Q): \"Null\"\n    \"\\<^bold>\\<lambda>(c: _) P Q q. conjunct1 \\<cdot> _ \\<cdot> _\"\n\n  conjunct1: \"Null\" \"conjunct1\"\n\n  conjunct2 (P, Q): \"snd\"\n    \"\\<^bold>\\<lambda>(c: _) (d: _) P Q pq. conjunct2 \\<cdot> _ \\<cdot> _\"\n\n  conjunct2 (P): \"Null\"\n    \"\\<^bold>\\<lambda>(c: _) P Q p. conjunct2 \\<cdot> _ \\<cdot> _\"\n\n  conjunct2 (Q): \"\\<lambda>p. p\"\n    \"\\<^bold>\\<lambda>(c: _) P Q p. conjunct2 \\<cdot> _ \\<cdot> _\"\n\n  conjunct2: \"Null\" \"conjunct2\"\n\n  disjI1 (P, Q): \"Inl\"\n    \"\\<^bold>\\<lambda>(c: _) (d: _) P Q p. iffD2 \\<cdot> _ \\<cdot> _ \\<bullet> (sum.case_1 \\<cdot> P \\<cdot> _ \\<cdot> p \\<bullet> arity_type_bool \\<bullet> c \\<bullet> d)\"\n\n  disjI1 (P): \"Some\"\n    \"\\<^bold>\\<lambda>(c: _) P Q p. iffD2 \\<cdot> _ \\<cdot> _ \\<bullet> (option.case_2 \\<cdot> _ \\<cdot> P \\<cdot> p \\<bullet> arity_type_bool \\<bullet> c)\"\n\n  disjI1 (Q): \"None\"\n    \"\\<^bold>\\<lambda>(c: _) P Q. iffD2 \\<cdot> _ \\<cdot> _ \\<bullet> (option.case_1 \\<cdot> _ \\<cdot> _ \\<bullet> arity_type_bool \\<bullet> c)\"\n\n  disjI1: \"Left\"\n    \"\\<^bold>\\<lambda>P Q. iffD2 \\<cdot> _ \\<cdot> _ \\<bullet> (sumbool.case_1 \\<cdot> _ \\<cdot> _ \\<bullet> arity_type_bool)\"\n\n  disjI2 (P, Q): \"Inr\"\n    \"\\<^bold>\\<lambda>(d: _) (c: _) Q P q. iffD2 \\<cdot> _ \\<cdot> _ \\<bullet> (sum.case_2 \\<cdot> _ \\<cdot> Q \\<cdot> q \\<bullet> arity_type_bool \\<bullet> c \\<bullet> d)\"\n\n  disjI2 (P): \"None\"\n    \"\\<^bold>\\<lambda>(c: _) Q P. iffD2 \\<cdot> _ \\<cdot> _ \\<bullet> (option.case_1 \\<cdot> _ \\<cdot> _ \\<bullet> arity_type_bool \\<bullet> c)\"\n\n  disjI2 (Q): \"Some\"\n    \"\\<^bold>\\<lambda>(c: _) Q P q. iffD2 \\<cdot> _ \\<cdot> _ \\<bullet> (option.case_2 \\<cdot> _ \\<cdot> Q \\<cdot> q \\<bullet> arity_type_bool \\<bullet> c)\"\n\n  disjI2: \"Right\"\n    \"\\<^bold>\\<lambda>Q P. iffD2 \\<cdot> _ \\<cdot> _ \\<bullet> (sumbool.case_2 \\<cdot> _ \\<cdot> _ \\<bullet> arity_type_bool)\"\n\n  disjE (P, Q, R): \"\\<lambda>pq pr qr.\n     (case pq of Inl p \\<Rightarrow> pr p | Inr q \\<Rightarrow> qr q)\"\n    \"\\<^bold>\\<lambda>(c: _) (d: _) (e: _) P Q R pq (h1: _) pr (h2: _) qr.\n       disjE_realizer \\<cdot> _ \\<cdot> _ \\<cdot> pq \\<cdot> R \\<cdot> pr \\<cdot> qr \\<bullet> c \\<bullet> d \\<bullet> e \\<bullet> h1 \\<bullet> h2\"\n\n  disjE (Q, R): \"\\<lambda>pq pr qr.\n     (case pq of None \\<Rightarrow> pr | Some q \\<Rightarrow> qr q)\"\n    \"\\<^bold>\\<lambda>(c: _) (d: _) P Q R pq (h1: _) pr (h2: _) qr.\n       disjE_realizer2 \\<cdot> _ \\<cdot> _ \\<cdot> pq \\<cdot> R \\<cdot> pr \\<cdot> qr \\<bullet> c \\<bullet> d \\<bullet> h1 \\<bullet> h2\"\n\n  disjE (P, R): \"\\<lambda>pq pr qr.\n     (case pq of None \\<Rightarrow> qr | Some p \\<Rightarrow> pr p)\"\n    \"\\<^bold>\\<lambda>(c: _) (d: _) P Q R pq (h1: _) pr (h2: _) qr (h3: _).\n       disjE_realizer2 \\<cdot> _ \\<cdot> _ \\<cdot> pq \\<cdot> R \\<cdot> qr \\<cdot> pr \\<bullet> c \\<bullet> d \\<bullet> h1 \\<bullet> h3 \\<bullet> h2\"\n\n  disjE (R): \"\\<lambda>pq pr qr.\n     (case pq of Left \\<Rightarrow> pr | Right \\<Rightarrow> qr)\"\n    \"\\<^bold>\\<lambda>(c: _) P Q R pq (h1: _) pr (h2: _) qr.\n       disjE_realizer3 \\<cdot> _ \\<cdot> _ \\<cdot> pq \\<cdot> R \\<cdot> pr \\<cdot> qr \\<bullet> c \\<bullet> h1 \\<bullet> h2\"\n\n  disjE (P, Q): \"Null\"\n    \"\\<^bold>\\<lambda>(c: _) (d: _) P Q R pq. disjE_realizer \\<cdot> _ \\<cdot> _ \\<cdot> pq \\<cdot> (\\<lambda>x. R) \\<cdot> _ \\<cdot> _ \\<bullet> c \\<bullet> d \\<bullet> arity_type_bool\"\n\n  disjE (Q): \"Null\"\n    \"\\<^bold>\\<lambda>(c: _) P Q R pq. disjE_realizer2 \\<cdot> _ \\<cdot> _ \\<cdot> pq \\<cdot> (\\<lambda>x. R) \\<cdot> _ \\<cdot> _ \\<bullet> c \\<bullet> arity_type_bool\"\n\n  disjE (P): \"Null\"\n    \"\\<^bold>\\<lambda>(c: _) P Q R pq (h1: _) (h2: _) (h3: _).\n       disjE_realizer2 \\<cdot> _ \\<cdot> _ \\<cdot> pq \\<cdot> (\\<lambda>x. R) \\<cdot> _ \\<cdot> _ \\<bullet> c \\<bullet> arity_type_bool \\<bullet> h1 \\<bullet> h3 \\<bullet> h2\"\n\n  disjE: \"Null\"\n    \"\\<^bold>\\<lambda>P Q R pq. disjE_realizer3 \\<cdot> _ \\<cdot> _ \\<cdot> pq \\<cdot> (\\<lambda>x. R) \\<cdot> _ \\<cdot> _ \\<bullet> arity_type_bool\"\n\n  FalseE (P): \"default\"\n    \"\\<^bold>\\<lambda>(c: _) P. FalseE \\<cdot> _\"\n\n  FalseE: \"Null\" \"FalseE\"\n\n  notI (P): \"Null\"\n    \"\\<^bold>\\<lambda>(c: _) P (h: _). allI \\<cdot> _ \\<bullet> c \\<bullet> (\\<^bold>\\<lambda>x. notI \\<cdot> _ \\<bullet> (h \\<cdot> x))\"\n\n  notI: \"Null\" \"notI\"\n\n  notE (P, R): \"\\<lambda>p. default\"\n    \"\\<^bold>\\<lambda>(c: _) (d: _) P R (h: _) p. notE \\<cdot> _ \\<cdot> _ \\<bullet> (spec \\<cdot> _ \\<cdot> p \\<bullet> c \\<bullet> h)\"\n\n  notE (P): \"Null\"\n    \"\\<^bold>\\<lambda>(c: _) P R (h: _) p. notE \\<cdot> _ \\<cdot> _ \\<bullet> (spec \\<cdot> _ \\<cdot> p \\<bullet> c \\<bullet> h)\"\n\n  notE (R): \"default\"\n    \"\\<^bold>\\<lambda>(c: _) P R. notE \\<cdot> _ \\<cdot> _\"\n\n  notE: \"Null\" \"notE\"\n\n  subst (P): \"\\<lambda>s t ps. ps\"\n    \"\\<^bold>\\<lambda>(c: _) s t P (d: _) (h: _) ps. subst \\<cdot> s \\<cdot> t \\<cdot> P ps \\<bullet> d \\<bullet> h\"\n\n  subst: \"Null\" \"subst\"\n\n  iffD1 (P, Q): \"fst\"\n    \"\\<^bold>\\<lambda>(d: _) (c: _) Q P pq (h: _) p.\n       mp \\<cdot> _ \\<cdot> _ \\<bullet> (spec \\<cdot> _ \\<cdot> p \\<bullet> d \\<bullet> (conjunct1 \\<cdot> _ \\<cdot> _ \\<bullet> h))\"\n\n  iffD1 (P): \"\\<lambda>p. p\"\n    \"\\<^bold>\\<lambda>(c: _) Q P p (h: _). mp \\<cdot> _ \\<cdot> _ \\<bullet> (conjunct1 \\<cdot> _ \\<cdot> _ \\<bullet> h)\"\n\n  iffD1 (Q): \"Null\"\n    \"\\<^bold>\\<lambda>(c: _) Q P q1 (h: _) q2.\n       mp \\<cdot> _ \\<cdot> _ \\<bullet> (spec \\<cdot> _ \\<cdot> q2 \\<bullet> c \\<bullet> (conjunct1 \\<cdot> _ \\<cdot> _ \\<bullet> h))\"\n\n  iffD1: \"Null\" \"iffD1\"\n\n  iffD2 (P, Q): \"snd\"\n    \"\\<^bold>\\<lambda>(c: _) (d: _) P Q pq (h: _) q.\n       mp \\<cdot> _ \\<cdot> _ \\<bullet> (spec \\<cdot> _ \\<cdot> q \\<bullet> d \\<bullet> (conjunct2 \\<cdot> _ \\<cdot> _ \\<bullet> h))\"\n\n  iffD2 (P): \"\\<lambda>p. p\"\n    \"\\<^bold>\\<lambda>(c: _) P Q p (h: _). mp \\<cdot> _ \\<cdot> _ \\<bullet> (conjunct2 \\<cdot> _ \\<cdot> _ \\<bullet> h)\"\n\n  iffD2 (Q): \"Null\"\n    \"\\<^bold>\\<lambda>(c: _) P Q q1 (h: _) q2.\n       mp \\<cdot> _ \\<cdot> _ \\<bullet> (spec \\<cdot> _ \\<cdot> q2 \\<bullet> c \\<bullet> (conjunct2 \\<cdot> _ \\<cdot> _ \\<bullet> h))\"\n\n  iffD2: \"Null\" \"iffD2\"\n\n  iffI (P, Q): \"Pair\"\n    \"\\<^bold>\\<lambda>(c: _) (d: _) P Q pq (h1 : _) qp (h2 : _). conjI_realizer \\<cdot>\n       (\\<lambda>pq. \\<forall>x. P x \\<longrightarrow> Q (pq x)) \\<cdot> pq \\<cdot>\n       (\\<lambda>qp. \\<forall>x. Q x \\<longrightarrow> P (qp x)) \\<cdot> qp \\<bullet>\n       (arity_type_fun \\<bullet> c \\<bullet> d) \\<bullet>\n       (arity_type_fun \\<bullet> d \\<bullet> c) \\<bullet>\n       (allI \\<cdot> _ \\<bullet> c \\<bullet> (\\<^bold>\\<lambda>x. impI \\<cdot> _ \\<cdot> _ \\<bullet> (h1 \\<cdot> x))) \\<bullet>\n       (allI \\<cdot> _ \\<bullet> d \\<bullet> (\\<^bold>\\<lambda>x. impI \\<cdot> _ \\<cdot> _ \\<bullet> (h2 \\<cdot> x)))\"\n\n  iffI (P): \"\\<lambda>p. p\"\n    \"\\<^bold>\\<lambda>(c: _) P Q (h1 : _) p (h2 : _). conjI \\<cdot> _ \\<cdot> _ \\<bullet>\n       (allI \\<cdot> _ \\<bullet> c \\<bullet> (\\<^bold>\\<lambda>x. impI \\<cdot> _ \\<cdot> _ \\<bullet> (h1 \\<cdot> x))) \\<bullet>\n       (impI \\<cdot> _ \\<cdot> _ \\<bullet> h2)\"\n\n  iffI (Q): \"\\<lambda>q. q\"\n    \"\\<^bold>\\<lambda>(c: _) P Q q (h1 : _) (h2 : _). conjI \\<cdot> _ \\<cdot> _ \\<bullet>\n       (impI \\<cdot> _ \\<cdot> _ \\<bullet> h1) \\<bullet>\n       (allI \\<cdot> _ \\<bullet> c \\<bullet> (\\<^bold>\\<lambda>x. impI \\<cdot> _ \\<cdot> _ \\<bullet> (h2 \\<cdot> x)))\"\n\n  iffI: \"Null\" \"iffI\"\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/Extraction.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5698526368038302, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.29160305648697193}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory ML_Goal_Test\nimports\n  ML_Goal\n  ML_Utils.ML_Utils\nbegin\nexperiment begin\n\n\\<comment>\\<open>\n  Basic usage.\n\\<close>\nML_goal test: \\<open>\n  [@{term \"(P \\<longrightarrow> Q) \\<and> P \\<longrightarrow> Q\"}]\n\\<close>\n  apply clarsimp\n  done\n\nthm test\n\n\\<comment>\\<open>\n  A goal that we definitely don't want to write out by hand.\n\n  In this case, we're going to show that if x is less than 10,\n  we \"only\" need to consider the cases when x = 0, or x = 1, or...\n\\<close>\nML_goal big_goal: \\<open>\n  let\n    val var_x = Free (\"x\", @{typ nat});\n    val var_P = Free (\"P\", @{typ bool});\n    val max = 10;\n\n    \\<comment>\\<open>\n      @{ML \"HOLogic.mk_nat\"} produces nested Suc's, which are pretty\n      ugly, so we use this instead.\n    \\<close>\n    val mk_nat = HOLogic.mk_number @{typ nat};\n\n    \\<comment>\\<open>\n      Turns (i: int) into @{term \"x = i \\<Longrightarrow> P\"}.\n    \\<close>\n    fun mk_case i =\n        let\n          val prem = HOLogic.mk_eq (var_x, mk_nat i) |> HOLogic.mk_Trueprop;\n          val conc = var_P |> HOLogic.mk_Trueprop;\n        in Logic.mk_implies (prem, conc) end\n\n    val x_cases =\n        ListExtras.range 0 max\n        |> map mk_case;\n\n    val assm =\n        HOLogic.mk_binrel @{const_name \"less\"}\n          (var_x,\n          (mk_nat max))\n        |> HOLogic.mk_Trueprop;\n\n    val goal =\n        Logic.list_implies (assm :: x_cases, var_P |> HOLogic.mk_Trueprop)\n\n  in [goal] end\n\\<close>\n  by force\n\n\\<comment>\\<open>\n  Names are optional.\n\\<close>\nML_goal \\<open>\n  [@{term \"True\"}]\n\\<close>\n  by (rule TrueI)\n\n\\<comment>\\<open>\n  Multiple goals are supported, and result in similar\n  \"list of fact\" lemmas\n\\<close>\nML_goal multiple_goals: \\<open>\n  [@{term \"(P \\<Longrightarrow> Q \\<Longrightarrow> P)\"}, @{term \"(P \\<Longrightarrow> Q \\<Longrightarrow> Q)\"}]\n\\<close>\n  by simp+\n\nthm multiple_goals[OF TrueI]\n\n\\<comment>\\<open>\n  Handles mixes of @{typ bool} and @{typ prop}.\n\\<close>\nML_goal \\<open>\n  [@{term \"PROP A \\<Longrightarrow> PROP A\"}, @{term \"B \\<longrightarrow> B\"}]\n\\<close>\n  by simp+\n\n\\<comment>\\<open>\n  Turns out a lemma name can refer to nothing as well!\n\\<close>\nML_goal nothing: \\<open>[]\\<close>\n  done\n\nthm nothing[OF TrueI]\n\n\\<comment>\\<open>\n  Attributes can be applied, just like normal lemmas.\n\\<close>\ndefinition magic where \"magic = (5 :: nat)\"\n\nML_goal declared_with_an_attribute[folded magic_def, simp]: \\<open>\n  [@{term \"(5 :: nat) = 2 + 3\"}]\n\\<close>\n  by simp\n\nlemma uses_our_new_magic_simp_rule:\n  \"magic = 1 + 4\"\n  by simp\n\nend\n\nend", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/lib/ML_Goal_Test.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6113819874558603, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.2913722142483306}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |                    May 2005               |\n            |                   June 2005  (modified)   |\n            |              September 2005  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |               November 2005  (modified)   |\n            |                  March 2007  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory CSP_F_law_rep_par\nimports CSP_F_law_alpha_par CSP_F_op_rep_par CSP_T_law_rep_par\nbegin\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite UnionT and InterT.                 *)\n(*                  Union (B ` A) = (UN x:A. B x)                      *)\n(*                  Inter (B ` A) = (INT x:A. B x)                     *)\n(*\ndeclare Union_image_eq [simp del]\ndeclare Inter_image_eq [simp del]\n*)\ndeclare Sup_image_eq [simp del]\ndeclare Inf_image_eq [simp del]\n\n(*****************************************************************\n\n         1. associativity of [||]:I\n         2. commutativity of [||]:I\n         3. \n         4. \n\n *****************************************************************)\n\n(*****************************************************\n   replace an index set with another equal index set\n *****************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspF_Rep_parallel_index_eq_lm1:\n   \"[| inj_on f I1 ; ALL i:I1. PXf2 (f i) = PXf1 i |] ==>\n    Union {(Yf i Int insert Tick (Ev ` snd (PXf1 i))) |i. i : I1} =\n    Union {(Yf (inv_on I1 f i) Int insert Tick (Ev ` snd (PXf2 i))) |i. i : f ` I1}\"\napply (rule) \n\n (* => *)\n apply (rule, simp)\n apply (elim conjE exE)\n apply (rule_tac x=\"(Yf i) Int insert Tick (Ev ` snd (PXf2 (f i)))\" in exI)\n apply (simp)\n apply (rule_tac x=\"f i\" in exI)\n apply (simp add: inv_f_f_on)\n\n (* <= *)\n apply (rule, simp)\n apply (simp add: image_iff)\n apply (elim conjE exE bexE)\n apply (rule_tac x=\n   \"(Yf xb) Int insert Tick (Ev ` snd (PXf1 xb))\" in exI)\n apply (simp)\n apply (simp add: inv_f_f_on)\n apply (rule_tac x=\"xb\" in exI)\n apply (simp)\ndone\n\nlemma cspF_Rep_parallel_index_eq_lm2:\n   \"ALL i:I1. PXf2 (f i) = PXf1 i ==>\n    Union {(Yf i Int insert Tick (Ev ` snd (PXf2 i))) |i. i : f ` I1} =\n    Union {(Yf (f i) Int insert Tick (Ev ` snd (PXf1 i))) |i. i : I1}\"\napply (rule) \n\n (* => *)\n apply (rule, simp)\n apply (simp add: image_iff)\n apply (elim conjE exE bexE)\n apply (simp)\n apply (rule_tac x=\"xa\" in exI)\n apply (simp)\n apply (rule_tac x=\"xb\" in exI)\n apply (simp)\n\n (* <= *)\n apply (rule, simp)\n apply (elim conjE exE)\n apply (rule_tac x=\"xa\" in exI)\n apply (simp)\n apply (rule_tac x=\"f i\" in exI)\n apply (simp)\ndone\n\n(* main *)\n\nlemma cspF_Rep_parallel_index_eq:\n   \"[| finite I1 ;\n       EX f. I2 = f ` I1 & inj_on f I1 &\n             (ALL i:I1. PXf2 (f i) = PXf1 i) |]\n     ==> [||]:I1 PXf1 =F[M,M] [||]:I2 PXf2\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Rep_parallel_index_eq)\napply (case_tac \"I1 = {}\", simp)\napply (rule order_antisym)\n\n (* <= *)\n apply (rule)\n apply (elim conjE exE)\n apply (simp add: in_failures_Rep_parallel)\n apply (subgoal_tac \"Union (snd ` PXf2 ` f ` I1) = Union (snd ` PXf1 ` I1)\")\n apply (simp)\n apply (elim conjE exE)\n apply (rule_tac x=\"(%i. Yf (inv_on I1 f i))\" in exI)\n apply (simp add: inv_f_f_on)\n apply (simp add: cspF_Rep_parallel_index_eq_lm1)\n apply (simp add: Union_index_fun)\n\n (* => *)\n apply (rule)\n apply (elim conjE exE)\n apply (simp add: in_failures_Rep_parallel)\n apply (subgoal_tac \"Union (snd ` PXf2 ` f ` I1) = Union (snd ` PXf1 ` I1)\")\n apply (simp)\n apply (elim conjE exE)\n apply (rule_tac x=\"(%i. Yf (f i))\" in exI)\n apply (simp)\n apply (simp add: cspF_Rep_parallel_index_eq_lm2)\n apply (simp add: Union_index_fun)\ndone\n\n(*********************************************************\n                [||]:I PXf ==> [||] PXs\n *********************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspF_Index_to_Inductive_parallel:\n  \"[| finite I ; Is isListOf I |] ==>\n   [||]:I PXf =F[M,M] [||] (map PXf Is)\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Index_to_Inductive_parallel)\napply (case_tac \"I = {}\", simp)\n\napply (case_tac \"map PXf Is = []\")\napply (simp)\napply (rule order_antisym)\n\n (* <= *)\n apply (rule)\n apply (simp add: in_failures_Rep_parallel)\n apply (simp add: in_failures_Inductive_parallel_nth)\n apply (simp add: isListOf_set_eq)\n apply (elim conjE exE)\n  apply (rule_tac x= \"map Yf Is\" in exI)\n  apply (simp)\n  apply (rule conjI)\n  apply (rule in_failures_Rep_parallel_lm2, simp)\n  apply (intro allI impI)\n  apply (drule_tac x=\"Is ! i\" in bspec)\n  apply (simp add: isListOf_nth_in_index)\n  apply (simp)\n\n (* => *)\n apply (rule)\n apply (simp add: in_failures_Rep_parallel)\n apply (simp add: in_failures_Inductive_parallel_nth)\n apply (simp add: isListOf_set_eq)\n apply (elim conjE exE)\n apply (rule_tac x= \"(%i. (Ys!(THE n. (Is!n) = i & n<length Is)))\" in exI)\n  apply (rule conjI)\n  apply (simp add: in_failures_Rep_parallel_lm1)\n  apply (rule ballI)\n\n  apply (erule isListOf_index_to_nthE)\n  apply (drule_tac x=\"i\" in bspec, simp)\n  apply (elim conjE exE, simp)\n\n  apply (drule_tac x=\"n\" in spec, simp)\n  apply (rotate_tac 4)\n  apply (drule sym)\n  apply (simp add: isListOf_THE_nth)\ndone\n\n(************************************\n |       [||]:I PXf and SKIP        |\n ************************************)\n\nlemma cspF_SKIP_Rep_parallel_right_lm1:\n  \"I ~= {} ==>\n   insert Tick (Union {(Yf i Int insert Tick (Ev ` snd (PXf i))) |i. i : I})\n   = Union {(insert Tick (Yf i Int Ev ` snd (PXf i))) |i. i : I}\"\nby (auto)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspF_SKIP_Rep_parallel_right:\n  \"finite I ==>\n   (([||]:I PXf) |[Union (snd `  PXf ` I), {}]| SKIP) =F[M,M]\n   ([||]:I PXf)\"\napply (case_tac \"I={}\")\napply (simp add: cspF_SKIP_Alpha_parallel)\n\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_SKIP_Rep_parallel_right)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_failures_Alpha_parallel)\n apply (simp add: in_failures_Rep_parallel)\n apply (elim conjE exE)\n\n  apply (case_tac \"Tick ~: Z\")\n  apply (simp)\n  apply (rule_tac x=\"Yf\" in exI)\n  apply (rule conjI)\n  apply (subgoal_tac \"Z Int {Tick} = {}\")\n  apply (simp (no_asm_simp))\n  apply (simp)\n\n  apply (intro ballI)\n  apply (drule_tac x=\"i\" in bspec, simp)\n  apply (subgoal_tac \" snd (PXf i) <= Union (snd ` PXf ` I)\")\n  apply (simp add: rest_tr_of_rest_tr_subset)\n  apply (force)\n\n  apply (simp add: in_failures)\n  apply (erule disjE)\n  apply (simp add: Evset_def)\n  apply (force)\n\n  apply (rule_tac x=\"(%i. insert Tick (Yf i))\" in exI)\n  apply (simp)\n  apply (subgoal_tac \"Z Int {Tick} = {Tick}\", simp)\n  apply (simp add: cspF_SKIP_Rep_parallel_right_lm1)\n\n  apply (intro ballI)\n  apply (drule_tac x=\"i\" in bspec, simp)\n  apply (subgoal_tac \" snd (PXf i) <= Union (snd ` PXf ` I)\")\n  apply (simp add: rest_tr_of_rest_tr_subset)\n\n  apply (simp add: rest_tr_Tick_sett)\n  apply (elim conjE exE)\n  apply (simp)\n  apply (rule proc_T2_T3)\n  apply (simp)\n  apply (simp)\n  apply (force)\n  apply (force)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_failures_Alpha_parallel)\n apply (rule_tac x=\"X\" in exI)\n apply (rule_tac x=\"{}\" in exI)\n apply (simp)\n\n apply (simp add: in_failures)\n apply (simp add: rest_tr_empty)\n apply (simp add: in_failures_Rep_parallel)\n apply (elim conjE exE)\n apply (rule_tac x=\"Yf\" in exI)\n apply (simp)\n apply (intro ballI)\n apply (drule_tac x=\"i\" in bspec, simp)\n\n apply (subgoal_tac \" snd (PXf i) <= Union (snd ` PXf ` I)\")\n apply (simp add: rest_tr_of_rest_tr_subset)\n apply (force)\ndone\n\n(************************************\n |        SKIP and [||]:I PXf       |\n ************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspF_SKIP_Rep_parallel_left:\n  \"finite I ==>\n   (SKIP |[{}, Union (snd ` PXf ` I)]| ([||]:I PXf)) =F[M,M]\n   ([||]:I PXf)\"\napply (subgoal_tac \n    \"(SKIP |[{}, Union (snd ` PXf ` I)]| ([||]:I PXf)) =F[M,M]\n     (([||]:I PXf) |[Union (snd ` PXf ` I), {}]| SKIP)\")\napply (rule cspF_trans)\napply (simp)\napply (simp add: cspF_SKIP_Rep_parallel_right)\napply (simp add: cspF_Alpha_parallel_commut)\ndone\n\n(*** left and right ***)\n\nlemmas cspF_SKIP_Rep_parallel = cspF_SKIP_Rep_parallel_left\n                                  cspF_SKIP_Rep_parallel_right\n\n(************************************\n |          associativity           |\n ************************************)\n\nlemma cspF_Rep_parallel_ass_lm1:\n   \"Union {(Yf i Int insert Tick (Ev ` snd (PXf i))) |i. i : I} Int\n           insert Tick (Ev ` Union (snd ` PXf ` I))\n    = Union {(Yf i Int insert Tick (Ev ` snd (PXf i))) |i. i : I}\"\nby (auto)\n\nlemma cspF_Rep_parallel_ass_lm2:\n   \"I1 Int I2 = {} ==>\n    Union {(Yf1 i Int insert Tick (Ev ` snd (PXf i))) |i. i : I1} Un\n    Union {(Yf2 i Int insert Tick (Ev ` snd (PXf i))) |i. i : I2} =\n    Union {(if i : I1 then Yf1 i else Yf2 i) Int insert Tick (Ev ` snd (PXf i)) |i.\n           i : I1 | i : I2}\"\napply (rule)\n\n apply (rule)\n apply (simp)\n apply (elim disjE conjE exE)\n\n  apply (rule_tac x=\"Yf1 i Int insert Tick (Ev ` snd (PXf i))\" in exI, simp)\n  apply (rule_tac x=\"i\" in exI, simp)\n  apply (rule_tac x=\"Yf2 i Int insert Tick (Ev ` snd (PXf i))\" in exI, simp)\n  apply (rule_tac x=\"i\" in exI, simp)\n  apply (force)\n\n apply (rule)\n apply (simp)\n apply (elim disjE conjE exE)\n\n  apply (rule disjI1)\n  apply (rule_tac x=\"Yf1 i Int insert Tick (Ev ` snd (PXf i))\" in exI, simp)\n  apply (rule_tac x=\"i\" in exI, simp)\n  apply (rule disjI2)\n  apply (case_tac \"i ~: I1\")\n  apply (rule_tac x=\"Yf2 i Int insert Tick (Ev ` snd (PXf i))\" in exI, simp)\n  apply (rule_tac x=\"i\" in exI, simp)\n  apply (force)\ndone\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspF_Rep_parallel_assoc:\n \"[| I1 Int I2 = {} ; finite I1 ; finite I2 |] ==>\n  [||]:(I1 Un I2) PXf =F[M,M]\n  [||]:I1 PXf |[Union (snd ` PXf ` I1), Union (snd ` PXf ` I2)]| [||]:I2 PXf\"\n\napply (case_tac \"I1 = {}\")\napply (case_tac \"I2 = {}\")\napply (rule cspF_sym)\napply (simp add: cspF_SKIP_Alpha_parallel)\napply (rule cspF_sym)\napply (simp add: cspF_SKIP_Rep_parallel)\n\napply (case_tac \"I2 = {}\")\napply (rule cspF_sym)\napply (simp add: cspF_SKIP_Rep_parallel)\n\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Rep_parallel_assoc)\napply (rule order_antisym)\n\n (* => *)\n apply (rule)\n apply (simp add: in_failures_Alpha_parallel)\n apply (simp add: in_failures_Rep_parallel)\n apply (elim conjE exE)\n\n apply (rule_tac x=\"Union {(Yf i Int insert Tick (Ev ` snd (PXf i))) |i. i : I1}\" in exI)\n apply (rule_tac x=\"Union {(Yf i Int insert Tick (Ev ` snd (PXf i))) |i. i : I2}\" in exI)\n apply (simp add: Union_snd_Un)\n apply (rule conjI)\n  apply (simp add: cspF_Rep_parallel_ass_lm1)\n  apply (blast)\n\n apply (rule conjI)\n\n  (* I1 *)\n  apply (rule_tac x=\"Yf\" in exI)\n  apply (simp add: cspF_Rep_parallel_ass_lm1)\n\n  apply (intro ballI)\n  apply (drule_tac x=\"i\" in bspec, simp)\n  apply (subgoal_tac \"snd (PXf i) <= Union (snd ` PXf ` I1)\")\n  apply (simp add: rest_tr_of_rest_tr_subset)\n  apply (force)\n\n  (* I2 *)\n  apply (rule_tac x=\"Yf\" in exI)\n  apply (simp add: cspF_Rep_parallel_ass_lm1)\n\n  apply (intro ballI)\n  apply (drule_tac x=\"i\" in bspec, simp)\n  apply (subgoal_tac \"snd (PXf i) <= Union (snd ` PXf ` I2)\")\n  apply (simp add: rest_tr_of_rest_tr_subset)\n  apply (force)\n\n (* <= *)\n apply (rule)\n apply (simp add: in_failures_Alpha_parallel)\n apply (simp add: in_failures_Rep_parallel)\n apply (elim exE conjE)\n apply (simp add: Union_snd_Un)\n apply (rename_tac s X Y Z Yf1 Yf2)\n\n apply (rule_tac x=\"(%i. if i:I1 then Yf1 i else Yf2 i)\" in exI)\n       (* the necessity of the condition \"I1 Int I2 = {}\" *)\n apply (simp add: cspF_Rep_parallel_ass_lm2)\n\n apply (intro ballI)\n apply (simp)\n apply (erule disjE)\n\n  apply (drule_tac x=\"i\" in bspec, simp, simp)\n  apply (subgoal_tac \"snd (PXf i) <= Union (snd ` PXf ` I1)\")\n  apply (simp add: rest_tr_of_rest_tr_subset)\n  apply (force)\n\n  apply (drule_tac x=\"i\" in bspec, simp)\n  apply (case_tac \"i ~: I1\")\n  apply (subgoal_tac \"snd (PXf i) <= Union (snd ` PXf ` I2)\")\n  apply (simp add: rest_tr_of_rest_tr_subset)\n  apply (force)\n  apply (blast)\ndone\n\n(************************************\n |             induct               |\n ************************************)\n\n(*------------------*\n |     csp law      |\n |   (derivable)    |\n *------------------*)\n\nlemma cspF_Rep_parallel_induct:\n \"[| finite I ; i ~: I |] ==>\n  [||]:(insert i I) PXf =F[M,M]\n  fst (PXf i) |[snd (PXf i), Union (snd ` PXf ` I)]| [||]:I PXf\"\napply (insert cspF_Rep_parallel_assoc[of \"{i}\" I PXf M])\napply (simp add: Rep_parallel_one)\napply (rule cspF_rw_left)\napply (simp)\n\napply (insert cspF_Alpha_parallel_assoc\n  [of \"fst (PXf i)\" \"snd (PXf i)\" \"{}\" \"SKIP\" \"Union (snd ` PXf ` I)\" \"[||]:I PXf\" M])\napply (rule cspF_trans)\napply (simp)\n\napply (rule cspF_decompo_Alpha_parallel)\napply (simp_all)\n\napply (simp add: cspF_SKIP_Rep_parallel)\ndone\n\n(****************** to add them again ******************)\n(*\ndeclare Union_image_eq [simp]\ndeclare Inter_image_eq [simp]\n*)\ndeclare Sup_image_eq [simp]\ndeclare Inf_image_eq [simp]\n\nend\n\n", "meta": {"author": "pefribeiro", "repo": "CSP-Prover", "sha": "8967cc482e5695fca4abb52d9dc2cf36b7b7a44e", "save_path": "github-repos/isabelle/pefribeiro-CSP-Prover", "path": "github-repos/isabelle/pefribeiro-CSP-Prover/CSP-Prover-8967cc482e5695fca4abb52d9dc2cf36b7b7a44e/CSP_F/CSP_F_law_rep_par.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.611381973294151, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.2913722074991481}}
{"text": "theory IICF_MS_Array_List\nimports \n  \"../Intf/IICF_List\" IICF_Array\nbegin\n  definition \"ms_irel M N \\<equiv> br (\\<lambda>(l,xs). take l xs) (\\<lambda>(l,xs). l\\<le>N \\<and> N = length xs \\<and> N<M)\"\n\n  \n  definition \"ms_empty N \\<equiv> RETURN (0::nat,replicate N init)\"\n  definition \"ms_is_empty \\<equiv> \\<lambda>(l,_). RETURN (l=0)\"\n  definition \"ms_length \\<equiv> \\<lambda>(l,_). RETURN l\"\n  definition \"ms_push_back \\<equiv> \\<lambda>(l,xs) x. doN {ASSERT (l < length xs); RETURN (l+1,xs[l:=x])}\"\n  definition \"ms_last \\<equiv> \\<lambda>(l,xs). doN {ASSERT (0<l \\<and> l\\<le>length xs); RETURN (xs!(l-1))}\"\n  definition \"ms_butlast \\<equiv> \\<lambda>(l,xs). doN {ASSERT (l>0); RETURN (l-1,xs)}\"\n  definition \"ms_get \\<equiv> \\<lambda>(l,xs) i. doN {ASSERT (i<length xs); RETURN (xs!i)}\"\n  definition \"ms_set \\<equiv> \\<lambda>(l,xs) i x. doN {ASSERT (i<length xs); RETURN (l,xs[i:=x])}\"\n\n  context begin\n  \n    private method ms_prove_refine = \n      (unfold ms_irel_def curry0_def;\n        intro nres_relI fun_relI frefI;\n        simp?;\n        refine_vcg?;\n        (auto simp: in_br_conv)\n      )\n  \n    lemma ms_empty_correct: \"N<M \\<Longrightarrow> (ms_empty N,mop_list_empty) \\<in> \\<langle>ms_irel M N\\<rangle>nres_rel\"\n      unfolding ms_empty_def by ms_prove_refine\n      \n    lemma ms_is_empty_correct: \"(ms_is_empty,mop_list_is_empty) \\<in> ms_irel M N \\<rightarrow> \\<langle>bool_rel\\<rangle>nres_rel\"  \n      unfolding ms_is_empty_def by ms_prove_refine\n\n    lemma ms_length_correct: \"(ms_length,mop_list_length) \\<in> ms_irel M N \\<rightarrow> \\<langle>nat_rel\\<rangle>nres_rel\"  \n      unfolding ms_length_def by ms_prove_refine\n    \n    lemma ms_push_back_correct: \"(uncurry ms_push_back,uncurry mop_list_append) \n      \\<in> [\\<lambda>(xs,x). length xs < N]\\<^sub>f (ms_irel M N \\<times>\\<^sub>r Id) \\<rightarrow> \\<langle>ms_irel M N\\<rangle>nres_rel\"  \n      unfolding ms_push_back_def \n      supply [simp] = take_update_last\n      by ms_prove_refine \n      \n    lemma ms_last_correct: \"(ms_last,mop_list_last)\\<in>ms_irel M N \\<rightarrow> \\<langle>Id\\<rangle>nres_rel\"  \n      unfolding ms_last_def supply [simp] = last_take_nth_conv by ms_prove_refine\n\n    lemma ms_butlast_correct: \"(ms_butlast,mop_list_butlast)\\<in>ms_irel M N \\<rightarrow> \\<langle>ms_irel M N\\<rangle>nres_rel\"  \n      unfolding ms_butlast_def supply [simp] = butlast_take by ms_prove_refine\n    \n    lemma ms_get_correct: \"(ms_get,mop_list_get)\\<in>ms_irel M N \\<rightarrow> nat_rel \\<rightarrow> \\<langle>Id\\<rangle>nres_rel\"  \n      unfolding ms_get_def by ms_prove_refine\n\n    lemma ms_set_correct: \"(ms_set,mop_list_set)\\<in>ms_irel M N \\<rightarrow> nat_rel \\<rightarrow> Id \\<rightarrow> \\<langle>ms_irel M N\\<rangle>nres_rel\"  \n      unfolding ms_set_def by ms_prove_refine\n    \n  end\n\n  type_synonym ('l,'a) marl = \"'l word \\<times> 'a ptr\"\n\n  lemma ms_irel_prenorm: \n    assumes \"((l,xs),xs')\\<in>ms_irel M N\"\n    shows \"length xs = N \\<and> l=length xs' \\<and> length xs'\\<le>N \\<and> N < M\"\n    using assms\n    unfolding ms_irel_def\n    by (auto simp: in_br_conv)\n  \n    \n  context\n    fixes M :: nat\n    defines \"M \\<equiv> max_snat (LENGTH ('l::len2))\"\n    notes [fcomp_prenorm_simps] = ms_irel_prenorm[where M=M]\n  begin\n    abbreviation \"marl2_assn \\<equiv> snat_assn' TYPE('l) \\<times>\\<^sub>a array_assn id_assn\"\n  \n    \n    sepref_definition marl_empty_impl [llvm_inline] is \"ms_empty\" :: \"(snat_assn' TYPE('l))\\<^sup>k \\<rightarrow>\\<^sub>a marl2_assn\"\n      unfolding ms_empty_def\n      supply [sepref_import_param] = IdI[of init]\n      apply (annot_snat_const \"TYPE('l)\")\n      apply (rewrite array_fold_custom_replicate)\n      by sepref\n\n      \n    definition [simp]: \"marl_empty_aux (N::nat) \\<equiv> op_list_empty\"  \n    \n    sepref_decl_op marl_empty: marl_empty_aux :: \"nat_rel \\<rightarrow> \\<langle>A\\<rangle>list_rel\" .\n    \n    lemma ms_empty_correct': \"(ms_empty,RETURN o op_marl_empty) \n      \\<in> [\\<lambda>N. N<M]\\<^sub>f\\<^sub>d nat_rel \\<rightarrow> (\\<lambda>N. \\<langle>ms_irel M N\\<rangle>nres_rel)\"\n      apply (rule frefI) using ms_empty_correct by auto\n\n    (*    \n    definition \"marl_assn' TYPE('l) N A \\<equiv> hr_comp (hr_comp marl2_assn (ms_irel (max_snat LENGTH('l)) N))\n                                     (\\<langle>the_pure A\\<rangle>list_rel)\" \n    *)\n    \n    definition \"marl_assn' TYPE('l) A N \\<equiv> hrr_comp nat_rel\n                                    (\\<lambda>N _. hr_comp marl2_assn (ms_irel M N))\n                                    (\\<lambda>_. \\<langle>the_pure A\\<rangle>list_rel) N ()\"\n                                         \n    lemmas [fcomp_norm_unfold] = marl_assn'_def[symmetric, abs_def]\n    \n    lemma marl_assn'_fold''[fcomp_norm_unfold]:\n      \"hrr_comp nat_rel (\\<lambda>x _. hr_comp (snat_assn \\<times>\\<^sub>a array_assn id_assn) (ms_irel M x)) (\\<lambda>x. \\<langle>the_pure A\\<rangle>list_rel)\n      = (\\<lambda>N _. marl_assn' TYPE('l) A N)\"\n      unfolding marl_assn'_def\n      by auto\n    \n    lemma marl_assn'_fold'[fcomp_norm_unfold]: \n      \"hr_comp (hr_comp (snat_assn \\<times>\\<^sub>a array_assn id_assn) (ms_irel M N)) (\\<langle>the_pure A\\<rangle>list_rel)\n        = marl_assn' TYPE('l) A N\"\n      unfolding marl_assn'_def\n      unfolding hrr_comp_def \n      apply (auto simp: fun_eq_iff sep_algebra_simps pred_lift_extract_simps)\n      unfolding non_dep2_def by metis+\n    \n    sepref_decl_impl marl_empty: marl_empty_impl.refine[FCOMP ms_empty_correct'] by simp \n  \n    sepref_definition marl_is_empty_impl [llvm_inline] is ms_is_empty :: \"marl2_assn\\<^sup>k \\<rightarrow>\\<^sub>a bool1_assn\"\n      unfolding ms_is_empty_def\n      apply (annot_snat_const \"TYPE('l)\")\n      apply sepref_dbg_keep\n      done\n      \n    sepref_decl_impl (ismop) marl_is_empty_impl.refine[FCOMP ms_is_empty_correct[of M]] .\n      \n    sepref_definition marl_length_impl [llvm_inline] is ms_length :: \"marl2_assn\\<^sup>k \\<rightarrow>\\<^sub>a snat_assn' TYPE('l)\"\n      unfolding ms_length_def\n      by sepref\n    sepref_decl_impl (ismop) marl_length_impl.refine[FCOMP ms_length_correct[of M]] .\n\n  \n    sepref_definition marl_push_back_impl [llvm_code] is \n      \"uncurry ms_push_back\" :: \"[\\<lambda>((l,a),_). length a < M ]\\<^sub>a marl2_assn\\<^sup>d*\\<^sub>aid_assn\\<^sup>k \\<rightarrow> marl2_assn\"\n      unfolding ms_push_back_def M_def\n      apply (annot_snat_const \"TYPE('l)\")\n      apply sepref_dbg_keep\n      done\n\n    sepref_decl_impl (ismop) marl_push_back_impl.refine[FCOMP ms_push_back_correct[where M=M]]  \n      by (parametricity add: IdI[of N])\n      \n      \n    sepref_definition marl_last_impl [llvm_code] is \n      \"ms_last\" :: \"marl2_assn\\<^sup>k \\<rightarrow>\\<^sub>a id_assn\"\n      unfolding ms_last_def M_def\n      apply (annot_snat_const \"TYPE('l)\")\n      apply sepref_dbg_keep\n      done\n    sepref_decl_impl (ismop) marl_last_impl.refine[FCOMP ms_last_correct[where M=M]] .\n      \n    sepref_definition marl_butlast_impl [llvm_code] is \n      \"ms_butlast\" :: \"marl2_assn\\<^sup>d \\<rightarrow>\\<^sub>a marl2_assn\"\n      unfolding ms_butlast_def M_def\n      apply (annot_snat_const \"TYPE('l)\")\n      apply sepref_dbg_keep\n      done\n    sepref_decl_impl (ismop) marl_butlast_impl.refine[FCOMP ms_butlast_correct[where M=M]] .\n      \n    \n    sepref_definition marl_get_impl [llvm_inline] is \n      \"uncurry ms_get\" :: \"marl2_assn\\<^sup>k *\\<^sub>a (snat_assn' TYPE('l))\\<^sup>k \\<rightarrow>\\<^sub>a id_assn\"\n      unfolding ms_get_def M_def\n      apply sepref_dbg_keep\n      done\n    sepref_decl_impl (ismop) marl_get_impl.refine[FCOMP ms_get_correct[where M=M]] .\n      \n    sepref_definition marl_set_impl [llvm_inline] is \n      \"uncurry2 ms_set\" :: \"marl2_assn\\<^sup>d *\\<^sub>a (snat_assn' TYPE('l))\\<^sup>k *\\<^sub>a id_assn\\<^sup>k \\<rightarrow>\\<^sub>a marl2_assn\"\n      unfolding ms_set_def M_def\n      apply sepref_dbg_keep\n      done\n    sepref_decl_impl (ismop) marl_set_impl.refine[FCOMP ms_set_correct[where M=M]] .\n  end\n          \n     \n  lemma fold_marl_empty:\n    \"[] = op_marl_empty N\"\n    \"RETURN [] = mop_marl_empty N\" \n    \"op_list_empty = op_marl_empty N\"\n    \"mop_list_empty = mop_marl_empty N\"\n    by auto\n\n\n  (* TODO: Move *)    \n    \n  schematic_goal [sepref_frame_free_rules]: \"MK_FREE (marl_assn' TYPE('l::len2) A N) ?f\"\n    unfolding marl_assn'_fold'[symmetric]\n    by sepref_dbg_side\n  \n  lemma marl_assn'_boundsD[sepref_bounds_dest]:\n     \"rdomp (marl_assn' TYPE('l::len2) A N) xs \\<Longrightarrow> length xs \\<le> N \\<and> N < max_snat LENGTH('l)\"  \n    unfolding marl_assn'_def\n    supply [sepref_bounds_dest] = ms_irel_prenorm\n    by sepref_bounds\n      \n  lemma bind_assoc_tagged: \"bind$(bind$m$f)$g = bind$m$(\\<lambda>\\<^sub>2x. bind$(f$x)$g)\" \n    unfolding autoref_tag_defs by simp \n      \n    \n    \nexperiment begin    \n\n  sepref_definition test is \"\\<lambda>N. (do {\n    let x = op_marl_empty N;\n    RETURN (x@[1::nat])\n  })\" :: \"[\\<lambda>N. N\\<ge>10]\\<^sub>a\\<^sub>d (snat_assn' TYPE(64))\\<^sup>k \\<rightarrow> (\\<lambda>N _. marl_assn' TYPE(64) (snat_assn' TYPE(64)) N)\"\n    apply (annot_snat_const \"TYPE(64)\")\n    by sepref\n    \n\nend\n\nend\n", "meta": {"author": "lammich", "repo": "isabelle_llvm", "sha": "6be37a9c3cae74a1134dbef2979e312abb5f7f42", "save_path": "github-repos/isabelle/lammich-isabelle_llvm", "path": "github-repos/isabelle/lammich-isabelle_llvm/isabelle_llvm-6be37a9c3cae74a1134dbef2979e312abb5f7f42/thys/sepref/IICF/Impl/IICF_MS_Array_List.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.665410558746814, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.2913323791780663}}
{"text": "theory \"Ids\"\n  imports Complex_Main\n   \"HOL-Library.Code_Target_Int\"\n   \"Syntax\"\nbegin\n\n(*Differential dynamic logic can be defined for any finite types, given a \n  few elements of those types (so that we can generate axioms). *)\n(*locale ids =\n  fixes vid1 :: ident\n  fixes vid2 :: ident\n  fixes vid3 :: ident\n  fixes is_vid1 :: \"ident \\<Rightarrow> bool\"\n  fixes fid1 :: ident\n  fixes fid2 :: ident\n  fixes fid3 :: ident\n  fixes pid1 :: ident\n  fixes pid2 :: ident\n  fixes pid3 :: ident\n  fixes pid4 :: ident\n  assumes vne12:\"vid1 \\<noteq> vid2\"\n  assumes vne23:\"vid2 \\<noteq> vid3\"\n  assumes vne13:\"vid1 \\<noteq> vid3\"\n  assumes fne12:\"fid1 \\<noteq> fid2\"\n  assumes fne23:\"fid2 \\<noteq> fid3\"\n  assumes fne13:\"fid1 \\<noteq> fid3\"\n  assumes pne12:\"pid1 \\<noteq> pid2\"\n  assumes pne23:\"pid2 \\<noteq> pid3\"\n  assumes pne13:\"pid1 \\<noteq> pid3\"\n  assumes pne14:\"pid1 \\<noteq> pid4\"\n  assumes pne24:\"pid2 \\<noteq> pid4\"\n  assumes pne34:\"pid3 \\<noteq> pid4\"\ncontext ids begin*)\n  lemma vne12:\"Ix \\<noteq> Iy\" apply (auto simp add: Ix_def Iy_def Iz_def Iw_def)using Ix.abs_eq Ix.rep_eq Iy.abs_eq Iy.rep_eq  Iz.abs_eq Iz.rep_eq Iw.abs_eq Iw.rep_eq by auto\n  lemma vne23:\"Iy \\<noteq> Iz\" apply (auto simp add: Ix_def Iy_def Iz_def Iw_def)using Ix.abs_eq Ix.rep_eq Iy.abs_eq Iy.rep_eq  Iz.abs_eq Iz.rep_eq Iw.abs_eq Iw.rep_eq by auto\n  lemma vne13:\"Ix \\<noteq> Iz\" apply (auto simp add: Ix_def Iy_def Iz_def Iw_def)using Ix.abs_eq Ix.rep_eq Iy.abs_eq Iy.rep_eq  Iz.abs_eq Iz.rep_eq Iw.abs_eq Iw.rep_eq by auto\n  lemma fne12:\"Ix \\<noteq> Iy\" apply (auto simp add: Ix_def Iy_def Iz_def Iw_def)using Ix.abs_eq Ix.rep_eq Iy.abs_eq Iy.rep_eq  Iz.abs_eq Iz.rep_eq Iw.abs_eq Iw.rep_eq by auto\n  lemma fne23:\"Iy \\<noteq> Iz\" apply (auto simp add: Ix_def Iy_def Iz_def Iw_def)using Ix.abs_eq Ix.rep_eq Iy.abs_eq Iy.rep_eq  Iz.abs_eq Iz.rep_eq Iw.abs_eq Iw.rep_eq by auto\n  lemma fne13:\"Ix \\<noteq> Iz\" apply (auto simp add: Ix_def Iy_def Iz_def Iw_def)using Ix.abs_eq Ix.rep_eq Iy.abs_eq Iy.rep_eq  Iz.abs_eq Iz.rep_eq Iw.abs_eq Iw.rep_eq by auto\n  lemma pne12:\"Ix \\<noteq> Iy\" apply (auto simp add: Ix_def Iy_def Iz_def Iw_def)using Ix.abs_eq Ix.rep_eq Iy.abs_eq Iy.rep_eq  Iz.abs_eq Iz.rep_eq Iw.abs_eq Iw.rep_eq by auto\n  lemma pne23:\"Iy \\<noteq> Iz\" apply (auto simp add: Ix_def Iy_def Iz_def Iw_def)using Ix.abs_eq Ix.rep_eq Iy.abs_eq Iy.rep_eq  Iz.abs_eq Iz.rep_eq Iw.abs_eq Iw.rep_eq by auto\n  lemma pne13:\"Ix \\<noteq> Iz\" apply (auto simp add: Ix_def Iy_def Iz_def Iw_def)using Ix.abs_eq Ix.rep_eq Iy.abs_eq Iy.rep_eq  Iz.abs_eq Iz.rep_eq Iw.abs_eq Iw.rep_eq by auto\n  lemma pne14:\"Ix \\<noteq> Iw\" apply (auto simp add: Ix_def Iy_def Iz_def Iw_def)using Ix.abs_eq Ix.rep_eq Iy.abs_eq Iy.rep_eq  Iz.abs_eq Iz.rep_eq Iw.abs_eq Iw.rep_eq by auto\n  lemma pne24:\"Iy \\<noteq> Iw\" apply (auto simp add: Ix_def Iy_def Iz_def Iw_def)using Ix.abs_eq Ix.rep_eq Iy.abs_eq Iy.rep_eq  Iz.abs_eq Iz.rep_eq Iw.abs_eq Iw.rep_eq by auto\n  lemma pne34:\"Iz \\<noteq> Iw\" apply (auto simp add: Ix_def Iy_def Iz_def Iw_def)using Ix.abs_eq Ix.rep_eq Iy.abs_eq Iy.rep_eq  Iz.abs_eq Iz.rep_eq Iw.abs_eq Iw.rep_eq by auto\n\n  lemma id_simps:\n    \"(Ix = Iy) = False\" \"(Iy = Iz) = False\" \"(Ix = Iz) = False\"\n    \"(Ix = Iy) = False\" \"(Iy = Iz) = False\" \"(Ix = Iz) = False\"\n    \"(Ix = Iy) = False\" \"(Iy = Iz) = False\" \"(Ix = Iz) = False\" \n    \"(Ix = Iw) = False\" \"(Iy = Iw) = False\" \"(Iz = Iw) = False\"\n    \"(Iy = Ix) = False\" \"(Iz = Iy) = False\" \"(Iz = Ix) = False\"\n    \"(Iy = Ix) = False\" \"(Iz = Iy) = False\" \"(Iz = Ix) = False\"\n    \"(Iy = Ix) = False\" \"(Iz = Iy) = False\" \"(Iz = Ix) = False\" \n    \"(Iw = Ix) = False\" \"(Iw = Iy) = False\" \"(Iw = Iz) = False\"\n    using vne12 vne23 vne13 fne12 fne23 fne13 pne12 pne23 pne13 pne14 pne24 pne34 by auto\n\n(* Function applied to one argument *)\ndefinition f1::\"ident \\<Rightarrow> ident \\<Rightarrow> trm\"\nwhere \"f1 f x = Function f (singleton (Var x))\"\n\n(* Function applied to zero arguments (simulates a constant symbol given meaning by the interpretation) *)\ndefinition f0::\"ident \\<Rightarrow> trm\"\nwhere \"f0 f = Function f empty\"\n\n(* Predicate applied to one argument *)\ndefinition p1::\"ident \\<Rightarrow> ident \\<Rightarrow> formula\"\nwhere \"p1 p x = Prop p (singleton (Var x))\"\n\n(* Predicational *)\ndefinition P::\"ident \\<Rightarrow> formula\"\nwhere \"P p = Predicational p\"\n\nend\n", "meta": {"author": "LS-Lab", "repo": "Isabelle-dL", "sha": "97770ed9ca8d6a633c59d11d799247f44cc62dc2", "save_path": "github-repos/isabelle/LS-Lab-Isabelle-dL", "path": "github-repos/isabelle/LS-Lab-Isabelle-dL/Isabelle-dL-97770ed9ca8d6a633c59d11d799247f44cc62dc2/Ids.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.29132070158518397}}
{"text": "section \\<open>Lemmas of Picore-SIMP\\<close>\n\ntheory picore_SIMP_lemma\nimports \"picore_SIMP_Syntax\" \"picore_SIMP\"\n\nbegin\n\nlemma id_belong[simp]: \"Id \\<subseteq>\\<lbrace>\\<ordfeminine>x= \\<ordmasculine>x\\<rbrace>\"\n  by (simp add: Collect_mono Id_fstsnd_eq)\n\nlemma allpre_eq_pre: \"(\\<forall>v\\<in>U. \\<turnstile>\\<^sub>I P sat\\<^sub>p [{v}, rely, guar, post]) \\<longleftrightarrow> \\<turnstile>\\<^sub>I P sat\\<^sub>p [U, rely, guar, post]\"\n  apply auto using Allprecond apply blast\n  using Conseq[of _ _ rely rely guar guar post post P] by auto\n\nlemma sat_pre_imp_allinpre: \" \\<turnstile>\\<^sub>I P sat\\<^sub>p [U, rely, guar, post] \\<Longrightarrow> v\\<in>U \\<Longrightarrow> \\<turnstile>\\<^sub>I P sat\\<^sub>p [{v}, rely, guar, post]\"\n  using Conseq[of _ _ rely rely guar guar post post P] by auto\n\nlemma stable_int_col2: \"stable \\<lbrace>s\\<rbrace> r \\<Longrightarrow> stable \\<lbrace>t\\<rbrace> r \\<Longrightarrow> stable \\<lbrace>s \\<and> t\\<rbrace> r\"\n  by auto\n\nlemma stable_int_col3: \"stable \\<lbrace>k\\<rbrace> r \\<Longrightarrow> stable \\<lbrace>s\\<rbrace> r \\<Longrightarrow> stable \\<lbrace>t\\<rbrace> r \\<Longrightarrow> stable \\<lbrace>k \\<and> s \\<and> t\\<rbrace> r\"\n  by auto\n\nlemma stable_int_col4: \"stable \\<lbrace>m\\<rbrace> r \\<Longrightarrow> stable \\<lbrace>k\\<rbrace> r \\<Longrightarrow> stable \\<lbrace>s\\<rbrace> r \n  \\<Longrightarrow> stable \\<lbrace>t\\<rbrace> r \\<Longrightarrow> stable \\<lbrace>m \\<and> k \\<and> s \\<and> t\\<rbrace> r\"\n  by auto\n\nlemma stable_int_col5: \"stable \\<lbrace>q\\<rbrace> r \\<Longrightarrow> stable \\<lbrace>m\\<rbrace> r \\<Longrightarrow>  stable \\<lbrace>k\\<rbrace> r \n  \\<Longrightarrow> stable \\<lbrace>s\\<rbrace> r \\<Longrightarrow> stable \\<lbrace>t\\<rbrace> r \\<Longrightarrow> stable \\<lbrace>q \\<and> m \\<and> k \\<and> s \\<and> t\\<rbrace> r\"\n  by auto\n\nlemma stable_un2: \"stable s r \\<Longrightarrow> stable t r \\<Longrightarrow> stable (s \\<union> t) r\"\n  by (simp add: stable_def)\n\nlemma stable_un_R: \"stable s r \\<Longrightarrow> stable s r' \\<Longrightarrow> stable s (r \\<union> r')\"\n  by (meson UnE stable_def)  \n\nlemma stable_un_S: \"\\<forall>t. stable s (P t) \\<Longrightarrow> stable s (\\<Union>t. P t)\" \napply(simp add:stable_def) by auto\n\nlemma stable_un_S2: \"\\<forall>t x. stable s (P t x) \\<Longrightarrow> stable s (\\<Union>t x. P t x)\" \napply(simp add:stable_def) by auto\n\nlemma pairv_IntI:\n\"y \\<in> \\<lbrace>\\<acute>(Pair V) \\<in> A\\<rbrace> \\<Longrightarrow> y \\<in> \\<lbrace>\\<acute>(Pair V) \\<in> B\\<rbrace> \\<Longrightarrow> y \\<in> \\<lbrace>\\<acute>(Pair V) \\<in> A \\<inter> B\\<rbrace>\"\nby auto\n\nlemma pairv_rId:\n\"y \\<in> \\<lbrace>\\<acute>(Pair V) \\<in> A\\<rbrace> \\<Longrightarrow> y \\<in> \\<lbrace>\\<acute>(Pair V) \\<in> A \\<union> Id\\<rbrace>\"\nby auto\n\nend", "meta": {"author": "SunHuan321", "repo": "uc-OS-verification", "sha": "760e159857c4015d6a9e3ccbe9f8247e4518862a", "save_path": "github-repos/isabelle/SunHuan321-uc-OS-verification", "path": "github-repos/isabelle/SunHuan321-uc-OS-verification/uc-OS-verification-760e159857c4015d6a9e3ccbe9f8247e4518862a/picore_SIMP_lemma.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.29132070158518397}}
{"text": "subsection {* Relational Hoare calculus *}\n\ntheory utp_hoare_helper\nimports utp_hoare_total \nbegin\nnamed_theorems utp_hoare_hp\n\nsubsection {*Try Catch Laws*}\n\ntext{*In this section we introduce the algebraic laws of programming related to the assignment\n      statement.*}\n\n\nlemma try_catch_unfold_hoare: (*because seq is assoc*)\n  \"\\<lbrace>p\\<rbrace>try  R ;; P catch  Q end\\<lbrace>q\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R = \n   \\<lbrace>p\\<rbrace>R ;; try  P catch Q end\\<lbrace>q\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R\"\n   apply pred_simp\n   apply rel_simp\n   apply auto\n   apply smt+\ndone\n\nlemma try_catch_abr_fold_hoare[utp_hoare_hp]: (*because seq is assoc*)\n  \"\\<lbrace>p\\<rbrace>R ;; try  P catch Q end \\<lbrace>q\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R = \n   \\<lbrace>p\\<rbrace>try  R ;; P catch  Q end \\<lbrace>q\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R\"\n   apply pred_simp\n   apply rel_simp\n   apply auto\n   apply smt+\ndone\n\nlemma try_catch_abr_throw_abr_hoare [utp_hoare_hp]:\n  \"\\<lbrace>p\\<rbrace> try THROW\\<^sub>A\\<^sub>B\\<^sub>R  catch Q end\\<lbrace>q\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R = \n   \\<lbrace>p\\<rbrace> Q \\<lbrace>q\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R\"\n   apply pred_simp\n   apply rel_simp\n   apply auto\n   apply smt+\ndone\n\nlemma try_catch_abr_skip_abr_hoare [utp_hoare_hp]:\n  \"\\<lbrace>p\\<rbrace>try  SKIP\\<^sub>A\\<^sub>B\\<^sub>R catch Q end\\<lbrace>q\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R = \n   \\<lbrace>p\\<rbrace>SKIP\\<^sub>A\\<^sub>B\\<^sub>R\\<lbrace>q\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R\"\n   apply pred_simp\n   apply rel_simp\n   apply auto\n   apply smt\ndone\n\nlemma try_catch_abr_assigns_abr_hoare [utp_hoare_hp]:\n  \"\\<lbrace>p\\<rbrace>try   \\<langle>\\<sigma>\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R catch Q end\\<lbrace>q\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R = \\<lbrace>p\\<rbrace> \\<langle>\\<sigma>\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R\\<lbrace>q\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R\"\n   apply pred_simp\n   apply rel_simp\n   apply auto\n   apply smt+\ndone\n\nsubsection {*Examples*}\n\nlemma\n  \"\\<lbrace>p\\<rbrace> try THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; SKIP\\<^sub>A\\<^sub>B\\<^sub>R catch Q end\\<lbrace>q\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R = \\<lbrace>p\\<rbrace>Q\\<lbrace>q\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R\"\n   by (simp only: utp_hoare_hp  uabr_comp)\n\nlemma \n  \"\\<lbrace>p\\<rbrace>THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; try \\<langle>\\<sigma>\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R catch Q end\\<lbrace>q\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R = \n   \\<lbrace>p\\<rbrace>Q \\<lbrace>q\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R\"\n  by (simp only: utp_hoare_hp  uabr_comp)\n\nlemma\n  \"\\<lbrace>p\\<rbrace>THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; try Simpl\\<^sub>A\\<^sub>B\\<^sub>R P catch Q end\\<lbrace>q\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R = \\<lbrace>p\\<rbrace>Q\\<lbrace>q\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R\"\n  by (simp only: utp_hoare_hp  uabr_comp)\n\nlemma \n  \"\\<lbrace>p\\<rbrace> try THROW\\<^sub>A\\<^sub>B\\<^sub>R;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R P catch Simpl\\<^sub>A\\<^sub>B\\<^sub>R Q end\\<lbrace>q\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R = \n   \\<lbrace>p\\<rbrace>Simpl\\<^sub>A\\<^sub>B\\<^sub>R Q \\<lbrace>q\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R\"\n   by (simp only: utp_hoare_hp  uabr_comp)\n\n\nend", "meta": {"author": "git-vt", "repo": "orca", "sha": "92bda0f9cfe5cc680b9c405fc38f07a960087a36", "save_path": "github-repos/isabelle/git-vt-orca", "path": "github-repos/isabelle/git-vt-orca/orca-92bda0f9cfe5cc680b9c405fc38f07a960087a36/Archive/Programming-Languages-Semantics/WP11-C-semantics/src/IMP-Lenses/hoare/HoareLogic/TotalCorrectness/Abrupt/utp_hoare_helper.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.29132070158518397}}
{"text": "(*<*)\n\n(* Author: Kyndylan Nienhuis *)\n\ntheory Examples\n\nimports \n  \"CHERI-instantiation.CheriInstantiation\"\n  \"TraceProperties\"\nbegin\n(*>*)\n\nsection \\<open>Reference monitor\\<close>\n\ndefinition CapabilityAligned :: \"('a::len) word set \\<Rightarrow> bool\" where\n  \"CapabilityAligned addresses \\<equiv>\n   \\<forall>a b. (a AND NOT mask 5 = b AND NOT mask 5) \\<longrightarrow>\n         a \\<in> addresses \\<longrightarrow>\n         b \\<in> addresses\"\n\nlemma CapabilityAlignedE:\n  fixes addresses :: \"('a::len) word set\"\n  assumes \"CapabilityAligned addresses\"\n      and \"a AND NOT mask 5 = b AND NOT mask 5\"\n      and \"a \\<in> addresses\"\n  shows \"b \\<in> addresses\"\nusing assms\nunfolding CapabilityAligned_def\nby blast\n\nlemma CapabilityAligned_CapAddressE:\n  fixes addresses :: \"40 word set\"\n  assumes \"CapabilityAligned addresses\"\n      and \"GetCapAddress a = GetCapAddress b\"\n      and \"a \\<in> addresses\"\n  shows \"b \\<in> addresses\"\nproof -\n  have \"a AND NOT mask 5 = b AND NOT mask 5\"\n    using `GetCapAddress a = GetCapAddress b`\n    unfolding GetCapAddress_def\n    using slice_eq_imp_and_not_mask_eq[where x=a and y=b and n=5 and 'b=35]\n    by auto\n  thus ?thesis\n    using assms CapabilityAlignedE\n    by metis\nqed\n\nlemma TranslationCapabilityAligned:\n  assumes \"CapabilityAligned segment\"\n  shows \"CapabilityAligned (getTranslateAddresses segment t s)\"\nunfolding CapabilityAligned_def\nproof clarify\n  fix a b :: PhysicalAddress\n  assume aligned: \"a AND NOT mask 5 = b AND NOT mask 5\"\n     and \"a \\<in> getTranslateAddresses segment t s\"\n  then obtain virtA where \"virtA \\<in> segment\" \n                      and a: \"getTranslateAddr (virtA, t) s = Some a\"\n    by auto\n  define virtB where \"virtB \\<equiv> (virtA AND NOT mask 12) OR ((ucast b) AND mask 12)\"\n  have virtB_upper: \"virtB AND NOT mask 12 = virtA AND NOT mask 12\"\n    unfolding virtB_def\n    by (simp add: word_ao_dist word_bool_alg.conj_assoc)\n  have virtB_lower: \"ucast virtB AND mask 12 = b AND mask 12\"\n    unfolding virtB_def\n    by (auto simp: word_ao_dist word_bool_alg.conj_assoc ucast_and ucast_or ucast_not)\n  have \"getTranslateAddr (virtA AND NOT mask 12, t) s = Some (a AND NOT mask 12)\"\n    using a\n    unfolding getTranslateAddr_and_not_mask\n    by simp\n  hence \"getTranslateAddr (virtB AND NOT mask 12, t) s = Some (b AND NOT mask 12)\"\n    using arg_cong[OF aligned, where f=\"\\<lambda>x. x AND NOT mask 12\"]\n    by (simp add: virtB_upper)\n  hence b: \"getTranslateAddr (virtB, t) s = Some b\"\n    unfolding getTranslateAddr_split[where vAddr=virtB]\n    by (auto simp: virtB_lower)\n  have \"virtA AND NOT mask 5 = virtB AND NOT mask 5\"\n    proof (intro word_eqI, simp add: word_size, intro impI)\n      fix n :: nat\n      assume \"n < 64\"\n      thus \"(virtA AND NOT mask 5) !! n = (virtB AND NOT mask 5) !! n\"\n        using word_eqD[OF aligned, where x=n]\n        using word_eqD[OF virtB_upper, where x=n]\n        using word_eqD[OF getTranslateAddr_ucast12[OF a], where x=n]\n        using word_eqD[OF getTranslateAddr_ucast12[OF b], where x=n]\n        by (cases \"n < 12\") (simp_all add: nth_ucast word_ops_nth_size word_size)\n     qed        \n  from CapabilityAlignedE[OF assms this]\n  have \"virtB \\<in> segment\"\n    using `virtA \\<in> segment` \n    by auto\n  thus \"b \\<in> getTranslateAddresses segment t s\"\n    using b\n    unfolding getTranslateAddresses_def\n    by auto\nqed\n\ndefinition AuthorityOfSegment where\n  \"AuthorityOfSegment segment types \\<equiv>\n   \\<lparr>SystemRegisterAccess = False,\n    ExecutableAddresses = segment,\n    LoadableAddresses = segment,\n    CapLoadableAddresses = segment,\n    StorableAddresses = segment,\n    CapStorableAddresses = segment,\n    LocalCapStorableAddresses = segment,\n    SealableTypes = types,\n    UnsealableTypes = types\\<rparr>\"\n\nlemma AuthorityOfSegment_simp [simp]:\n  shows \"SystemRegisterAccess (AuthorityOfSegment segment types) = False\"\n    and \"ExecutableAddresses (AuthorityOfSegment segment types) = segment\"\n    and \"LoadableAddresses (AuthorityOfSegment segment types) = segment\"\n    and \"CapLoadableAddresses (AuthorityOfSegment segment types) = segment\"\n    and \"StorableAddresses (AuthorityOfSegment segment types) = segment\"\n    and \"CapStorableAddresses (AuthorityOfSegment segment types) = segment\"\n    and \"LocalCapStorableAddresses (AuthorityOfSegment segment types) = segment\"\n    and \"SealableTypes (AuthorityOfSegment segment types) = types\"\n    and \"UnsealableTypes (AuthorityOfSegment segment types) = types\"\nunfolding AuthorityOfSegment_def\nby simp_all\n\ndefinition GrantedCaps where \n  \"GrantedCaps segment s \\<equiv>\n   {getCapReg r s |r. RegisterIsAlwaysAccessible r} \\<union>\n   {getMemCap (GetCapAddress a) s |a. a \\<in> getTranslateAddresses segment LOAD s}\"\n\nlemma ReadableCaps_AuthorityOfSegment:\n  shows \"ReadableCaps (AuthorityOfSegment segment types) s = \n         {cap. cap \\<in> GrantedCaps segment s \\<and> getTag cap}\"\nproof (intro equalityI; clarify, (intro conjI)?)\n  fix cap\n  assume \"cap \\<in> GrantedCaps segment s\"\n     and \"getTag cap\"\n  thus \"cap \\<in> ReadableCaps (AuthorityOfSegment segment types) s\"\n    unfolding GrantedCaps_def\n    proof (elim UnE; clarify)\n      fix r\n      assume \"RegisterIsAlwaysAccessible r\"\n         and \"getTag (getCapReg r s)\"\n      thus \"getCapReg r s \\<in> ReadableCaps (AuthorityOfSegment segment types) s\"\n        by (auto intro!: ReadableCapsI[where loc=\"LocReg r\"])\n    next\n      fix a\n      assume \"a \\<in> getTranslateAddresses segment LOAD s\"\n         and \"getTag (getMemCap (GetCapAddress a) s)\"\n      thus \"getMemCap (GetCapAddress a) s \\<in> ReadableCaps (AuthorityOfSegment segment types) s\"\n        by (auto intro!: ReadableCapsI[where loc=\"LocMem (GetCapAddress a)\"]\n                 simp: getTranslateCapAddresses_def)\n    qed\nnext\n  fix cap\n  assume readable: \"cap \\<in> ReadableCaps (AuthorityOfSegment segment types) s\"\n  thus \"getTag cap\" by auto\n  show \"cap \\<in> GrantedCaps segment s\"\n    using readable\n    unfolding ReadableCaps_def\n    proof clarify\n      fix loc\n      assume loc: \"loc \\<in> ReadableLocations (AuthorityOfSegment segment types) s\"\n         and tag: \"getTag (getCap loc s)\"\n      show \"getCap loc s \\<in> GrantedCaps segment s\"\n        proof (cases loc)\n          case (LocReg r)\n          hence \"RegisterIsAlwaysAccessible r\"\n            using loc\n            by auto\n          thus ?thesis\n            using loc tag LocReg\n            unfolding GrantedCaps_def\n            by auto\n        next\n          case (LocMem a)\n          then obtain a' where \"a = GetCapAddress a'\" \"a' \\<in> getTranslateAddresses segment LOAD s\"\n            using loc\n            by (auto simp: getTranslateCapAddresses_def)\n          thus ?thesis\n            using loc tag LocMem\n            unfolding GrantedCaps_def\n            by auto\n        qed\n    qed\nqed\n\ndefinition UsableCaps where \n  \"UsableCaps segment types s \\<equiv>\n   {cap\\<in>GrantedCaps segment s. \n    getTag cap \\<and>\n    (\\<not> getSealed cap \\<or> getType cap \\<in> types)}\"\n\ndefinition InvokableCaps where \n  \"InvokableCaps segment s \\<equiv>\n   {cap\\<in>GrantedCaps segment s. \n    getTag cap \\<and> Permit_CCall (getPerms cap)}\"\n\nlemma Authority_le_AuthorityOfSegment:\n  shows \"(GetAuthority cap \\<le> AuthorityOfSegment segment types) =\n         (\\<not> getTag cap \\<or>\n          ((Permit_Seal (getPerms cap) \\<or>\n            Permit_Unseal (getPerms cap)) \\<longrightarrow>\n           (\\<forall>t. ucast t \\<in> RegionOfCap cap \\<longrightarrow> t \\<in> types)) \\<and>\n          ((Permit_Execute (getPerms cap) \\<or>\n            Permit_Load (getPerms cap) \\<or>\n            Permit_Load_Capability (getPerms cap) \\<or>\n            Permit_Store (getPerms cap) \\<or>\n            Permit_Store_Capability (getPerms cap) \\<or>\n            Permit_Store_Local_Capability (getPerms cap)) \\<longrightarrow>\n           RegionOfCap cap \\<subseteq> segment) \\<and>\n          \\<not> Access_System_Registers (getPerms cap))\"\nunfolding less_eq_CompartmentAuthority_ext_def\nunfolding GetAuthority_accessors\nby auto\n\ndefinition NoSystemRegisterAccess where\n  \"NoSystemRegisterAccess segment types s \\<equiv>\n   \\<forall>cap. cap \\<in> UsableCaps segment types s \\<longrightarrow> \n    \\<not> Access_System_Registers (getPerms cap)\"\n\ndefinition ContainedCapBounds where\n  \"ContainedCapBounds segment types s \\<equiv>\n   \\<forall>cap. (cap \\<in> UsableCaps segment types s \\<and>\n          (Permit_Execute (getPerms cap) \\<or>\n           Permit_Load (getPerms cap) \\<or>\n           Permit_Load_Capability (getPerms cap) \\<or>\n           Permit_Store (getPerms cap) \\<or>\n           Permit_Store_Capability (getPerms cap) \\<or>\n           Permit_Store_Local_Capability (getPerms cap))) \\<longrightarrow>\n          RegionOfCap cap \\<subseteq> segment\"\n\ndefinition ContainedObjectTypes where \n  \"ContainedObjectTypes segment types s \\<equiv>\n   \\<forall>cap. (cap \\<in> UsableCaps segment types s \\<and>\n          (Permit_Seal (getPerms cap) \\<or>\n           Permit_Unseal (getPerms cap))) \\<longrightarrow>\n         (\\<forall>t. ucast t \\<in> RegionOfCap cap \\<longrightarrow> t \\<in> types)\"\n\ndefinition InvokableCapsSetup where \n  \"InvokableCapsSetup segment types exit s ==  \n   \\<forall>cap. cap \\<in> InvokableCaps segment s \\<longrightarrow> \n         getSealed cap \\<and> getType cap \\<notin> types \\<and> getBase cap + getOffset cap \\<in> exit\"\n\ndefinition CapabilitySetup where\n  \"CapabilitySetup segment types exit s \\<equiv>\n   NoSystemRegisterAccess segment types s \\<and>\n   ContainedCapBounds segment types s \\<and>\n   ContainedObjectTypes segment types s \\<and>\n   InvokableCapsSetup segment types exit s\"\n\ndefinition IsolationGuarantees where\n  \"IsolationGuarantees segment exit s s' \\<equiv>\n   (getBase (getPCC s') + getPC s' \\<in> exit) \\<and>\n   (\\<forall>a. a \\<notin> getTranslateAddresses segment STORE s \\<longrightarrow> \n        (getMemByte a s' = getMemByte a s \\<and>\n         getMemTag (GetCapAddress a) s' = getMemTag (GetCapAddress a) s)) \\<and>\n   (\\<forall>cd. (cd \\<noteq> 0 \\<and> cd \\<noteq> 1 \\<and> cd \\<noteq> 31) \\<longrightarrow> \n         getSCAPR cd s' = getSCAPR cd s)\"\n\nlemma CompartmentIsolation:\n  assumes abstraction: \"CanBeSimulated sem\"\n      and valid: \"getStateIsValid s\"\n      and aligned: \"CapabilityAligned segment\"\n      and ex: \"ExceptionPCs \\<subseteq> exit\"\n      and caps: \"CapabilitySetup segment types exit s\"\n      and trace: \"(step # trace, s') \\<in> Traces sem s\"\n      and intra: \"TracePreservesDomain trace\"\n      and inter: \"\\<not> PreservesDomain step\"\n  shows \"IsolationGuarantees segment exit s s'\"\nunfolding IsolationGuarantees_def\nproof (intro conjI allI impI)\n  have systemreg: \"\\<forall>cap. cap \\<in> UsableCaps segment types s \\<longrightarrow> \n                   \\<not> Access_System_Registers (getPerms cap)\"\n    using caps\n    unfolding CapabilitySetup_def NoSystemRegisterAccess_def\n    by simp\n  have segment: \"\\<forall>cap. (cap \\<in> UsableCaps segment types s \\<and>\n                 (Permit_Execute (getPerms cap) \\<or>\n                  Permit_Load (getPerms cap) \\<or>\n                  Permit_Load_Capability (getPerms cap) \\<or>\n                  Permit_Store (getPerms cap) \\<or>\n                  Permit_Store_Capability (getPerms cap) \\<or>\n                  Permit_Store_Local_Capability (getPerms cap))) \\<longrightarrow>\n                 RegionOfCap cap \\<subseteq> segment\"\n    using caps\n    unfolding CapabilitySetup_def ContainedCapBounds_def\n    by simp\n  have types: \"\\<forall>cap. (cap \\<in> UsableCaps segment types s \\<and>\n              (Permit_Seal (getPerms cap) \\<or>\n               Permit_Unseal (getPerms cap))) \\<longrightarrow>\n              (\\<forall>t. ucast t \\<in> RegionOfCap cap \\<longrightarrow> t \\<in> types)\"\n    using caps\n    unfolding CapabilitySetup_def ContainedObjectTypes_def\n    by simp\n  have invokable: \"\\<forall>cap. cap \\<in> InvokableCaps segment s \\<longrightarrow> \n                         getSealed cap \\<and> getType cap \\<notin> types \\<and> getBase cap + getOffset cap \\<in> exit\"\n    using caps\n    unfolding CapabilitySetup_def InvokableCapsSetup_def\n    by simp\n  define gPerm where \"gPerm = AuthorityOfSegment segment types\"\n  note [simp] = ReadableCaps_AuthorityOfSegment\n  have closed: \"PermIsClosed gPerm s\"\n    unfolding gPerm_def PermIsClosed_def ReadableCaps_AuthorityOfSegment\n    proof clarsimp\n      fix cap\n      assume \"cap \\<in> GrantedCaps segment s\"\n             \"getTag cap\"\n             \"getSealed cap \\<longrightarrow> getType cap \\<in> types\"\n      hence \"cap \\<in> UsableCaps segment types s\"\n        unfolding UsableCaps_def\n        by auto\n      thus \"GetAuthority cap \\<le> AuthorityOfSegment segment types\"\n        using systemreg[THEN spec[where x=cap]]\n        using segment[THEN spec[where x=cap]]\n        using types[THEN spec[where x=cap]]\n        unfolding Authority_le_AuthorityOfSegment\n        by simp\n     qed\n  note gPerm_def [simp]\n  note gperm = AvailableAuthorityInClosedPerm[OF closed]\n  have no_sys: \"\\<not> SystemRegisterAccess (AvailableAuthority s)\"\n    using SystemRegisterAccess_le[OF gperm]\n    by auto\n  obtain r where r\\<^sub>1: \"(trace, r) \\<in> Traces sem s\"\n             and r\\<^sub>2: \"(step, s') \\<in> sem r\"\n    using trace by auto\n  note r_valid = TraceInvarianceStateIsValid[OF abstraction valid r\\<^sub>1]\n  obtain crossing where [simp]: \"step = SwitchDomain crossing\"\n    using inter by (cases step) auto\n  show \"getMemByte a s' = getMemByte a s\"\n  if \"a \\<notin> getTranslateAddresses segment STORE s\" for a\n    proof -\n      have \"a \\<notin> StorablePhysAddresses gPerm s\"\n        using that\n        unfolding StorablePhysAddresses_def\n        by auto\n      hence \"a \\<notin> StorablePhysAddresses (AvailableAuthority s) s\"\n        using StorablePhysAddresses_le[OF gperm]\n        by auto\n      thus ?thesis\n        using MemoryInvariant[OF abstraction trace intra inter _ no_sys valid]\n        by metis\n    qed\n  show \"getMemTag (GetCapAddress a) s' = getMemTag (GetCapAddress a) s\" \n  if \"a \\<notin> getTranslateAddresses segment STORE s\" for a\n    proof -\n      have \"GetCapAddress a \\<notin> StorablePhysCapAddresses gPerm s\"\n        proof\n          assume \"GetCapAddress a \\<in> StorablePhysCapAddresses gPerm s\"\n          then obtain b where \"b \\<in> getTranslateAddresses segment STORE s\"\n                          and \"GetCapAddress b = GetCapAddress a\"\n            unfolding StorablePhysCapAddresses_def\n            unfolding getTranslateCapAddresses_def\n            by auto\n          hence \"a \\<in> getTranslateAddresses segment STORE s\"\n            using TranslationCapabilityAligned[OF aligned, where s=s and t=STORE]\n            using CapabilityAligned_CapAddressE[where a=b and b=a]\n            by auto\n          thus False\n            using that\n            by auto\n        qed\n      hence \"GetCapAddress a \\<notin> StorablePhysCapAddresses (AvailableAuthority s) s\"\n        using StorablePhysCapAddresses_le[OF gperm]\n        by auto\n      hence \"getMemCap (GetCapAddress a) s' = getMemCap (GetCapAddress a) s\"  \n        using MemCapInvariant[OF abstraction trace intra inter _ no_sys valid]\n        by metis\n      thus ?thesis\n        unfolding getMemTag_def\n        by auto\n    qed\n  show \"getSCAPR cd s' = getSCAPR cd s\" if \"cd \\<noteq> 0 \\<and> cd \\<noteq> 1 \\<and> cd \\<noteq> 31\" for cd\n    using SpecialCapRegisterInvariant[OF abstraction trace intra inter no_sys _ _ _ valid]\n    using that\n    by metis   \n  show \"getBase (getPCC s') + getPC s' \\<in> exit\"\n    proof (cases crossing)\n      case RaiseException\n      hence \"(SwitchDomain RaiseException, s') \\<in> sem r\"\n        using r\\<^sub>2 by auto\n      from CanBeSimulatedE_Exception[OF abstraction this _ r_valid]\n      have \"getBase (getPCC s') + getPC s' \\<in> ExceptionPCs\"\n        by auto\n      thus ?thesis\n        using ex\n        by auto\n    next\n      case (InvokeCapability cd cd')\n      hence \"(SwitchDomain (InvokeCapability cd cd'), s') \\<in> sem r\"\n        using r\\<^sub>2 by auto\n      note invoke = CanBeSimulatedE_InvokeCap[OF abstraction this _ r_valid, \n                                              where cd=cd and cd'=cd']\n      have \"getCAPR cd r \\<in> AvailableCaps r\"\n        using invoke by auto\n      hence available: \"getCAPR cd r \\<in> AvailableCaps s\"\n        using MonotonicityAvailableCaps[OF abstraction r\\<^sub>1 intra no_sys valid]\n        by auto\n      have \"InvokableCapsNotUnsealable gPerm s\"\n        using invokable\n        unfolding gPerm_def InvokableCapsNotUnsealable_def\n        unfolding InvokableCaps_def\n        by auto\n      from InvokableCapsNotUnsealable_le[OF gperm this]\n      have \"getCAPR cd r \\<in> ReadableCaps (AvailableAuthority s) s\"\n        using AvailableInvokableCapsAreReadable[OF available]\n        using invoke\n        by metis\n      hence \"getCAPR cd r \\<in> InvokableCaps segment s\"\n        using ReadableCaps_le[OF gperm] invoke\n        unfolding InvokableCaps_def\n        by auto\n      hence \"getBase (getCAPR cd r ) + getOffset (getCAPR cd r ) \\<in> exit\"\n        using invokable\n        by auto\n      hence \"getBase (getPCC s') + getPC s' \\<in> exit\"\n        using invoke\n        by auto\n      thus ?thesis\n        by simp\n    qed\nqed\n\n(*<*)\nend\n(*>*)\n", "meta": {"author": "CTSRD-CHERI", "repo": "l3-cheri-mips-proofs", "sha": "239c37ad1587caf261501478bbcd1293b9ecb7b7", "save_path": "github-repos/isabelle/CTSRD-CHERI-l3-cheri-mips-proofs", "path": "github-repos/isabelle/CTSRD-CHERI-l3-cheri-mips-proofs/l3-cheri-mips-proofs-239c37ad1587caf261501478bbcd1293b9ecb7b7/properties/Examples.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.689305616785446, "lm_q2_score": 0.4225046348141882, "lm_q1q2_score": 0.29123481789530364}}
{"text": "header {*\\subsection{Formulation of a subject-subject communication policy and an information flow \npolicy, and showing both can be derived from subject-object configuration data}*}\n\ntheory Step_policies\n  imports Step_configuration\nbegin\n\nsubsubsection {* Specification\\label{sect:policy_specification} *}\n\ntext {* In order to use CISK, we need an information flow policy @{term ifp}\n  relation. \n  We also express a static subject-subject @{term sp_spec_subj_obj} and subject-object @{term sp_spec_subj_subj} access control policy\n  for the implementation of the model. The following locale summarizes\n  all properties we need. *}\n\nlocale policy_axioms =\n  fixes sp_spec_subj_obj :: \"'a \\<Rightarrow> obj_id_t \\<Rightarrow> mode_t \\<Rightarrow> bool\"\n    and sp_spec_subj_subj :: \"'a \\<Rightarrow> 'a \\<Rightarrow> bool\"\n    and ifp :: \"'a \\<Rightarrow> 'a \\<Rightarrow> bool\"\n\n  assumes sp_spec_file_provider: \"\\<forall> p1 p2 f m1 m2 .\n     sp_spec_subj_obj p1 (FILEP f) m1 \\<and>\n     sp_spec_subj_obj p2 (FILEP f) m2 \\<longrightarrow> sp_spec_subj_subj p1 p2\"\n\n  and sp_spec_no_wronly_pages:\n    \"\\<forall> p x . sp_spec_subj_obj p (PAGE x) WRITE \\<longrightarrow> sp_spec_subj_obj p (PAGE x) READ\"\n\n  and ifp_reflexive:\n    \"\\<forall> p . ifp p p\"\n\n  and ifp_compatible_with_sp_spec:\n    \"\\<forall> a b . sp_spec_subj_subj a b \\<longrightarrow> ifp a b \\<and> ifp b a\"\n\n  and ifp_compatible_with_ipc:\n    \"\\<forall> a b c x . (sp_spec_subj_subj a b\n                  \\<and> sp_spec_subj_obj b (PAGE x) WRITE  \\<and> sp_spec_subj_obj c (PAGE x) READ)\n                 \\<longrightarrow> ifp a c\"\nbegin (* empty *) end\n\nsubsubsection {* Derivation *}\n\ntext {* The configuration data only consists of a subject-object policy. \nWe derive the subject-subject policy and the information flow policy from the configuration data and prove that properties we specified in Section~\\ref{sect:policy_specification} are satisfied. *}\n\nlocale abstract_policy_derivation =\n  fixes configuration_subj_obj :: \"'a \\<Rightarrow> obj_id_t \\<Rightarrow> mode_t \\<Rightarrow> bool\"\nbegin\n\n  definition \"sp_spec_subj_obj a x m \\<equiv>\n    configuration_subj_obj a x m \\<or> (\\<exists> y . x = PAGE y \\<and> m = READ \\<and> configuration_subj_obj a x WRITE)\"\n\n  definition \"sp_spec_subj_subj a b \\<equiv>\n    \\<exists> f m1 m2 . sp_spec_subj_obj a (FILEP f) m1 \\<and> sp_spec_subj_obj b (FILEP f) m2\"\n\n  definition \"ifp a b \\<equiv>\n     sp_spec_subj_subj a b\n   \\<or> sp_spec_subj_subj b a\n   \\<or> (\\<exists> c y . sp_spec_subj_subj a c\n            \\<and> sp_spec_subj_obj c (PAGE y) WRITE\n            \\<and> sp_spec_subj_obj b (PAGE y) READ)\n   \\<or> (a = b)\"\n\ntext {* Show that the policies specified in Section~\\ref{sect:policy_specification} can be derived from the configuration and their definitions. *}\n\n  lemma correct:\n    shows \"policy_axioms sp_spec_subj_obj sp_spec_subj_subj ifp\"\n  proof (unfold_locales)\n    show sp_spec_file_provider:\n      \"\\<forall> p1 p2 f m1 m2 .\n           sp_spec_subj_obj p1 (FILEP f) m1 \\<and>\n           sp_spec_subj_obj p2 (FILEP f) m2 \\<longrightarrow> sp_spec_subj_subj p1 p2\"\n      unfolding sp_spec_subj_subj_def by auto\n    show sp_spec_no_wronly_pages:\n      \"\\<forall> p x . sp_spec_subj_obj p (PAGE x) WRITE \\<longrightarrow> sp_spec_subj_obj p (PAGE x) READ\"\n      unfolding sp_spec_subj_obj_def by auto\n    show ifp_reflexive:\n      \"\\<forall> p . ifp p p\"\n      unfolding ifp_def by auto\n    show ifp_compatible_with_sp_spec:\n      \"\\<forall> a b . sp_spec_subj_subj a b \\<longrightarrow> ifp a b \\<and> ifp b a\"\n      unfolding ifp_def by auto\n    show ifp_compatible_with_ipc:\n      \"\\<forall> a b c x . (sp_spec_subj_subj a b\n                  \\<and> sp_spec_subj_obj b (PAGE x) WRITE  \\<and> sp_spec_subj_obj c (PAGE x) READ)\n                 \\<longrightarrow> ifp a c\"\n      unfolding ifp_def by auto\n  qed\nend\n\ntype_synonym sp_subj_subj_t = \"partition_id_t \\<Rightarrow> partition_id_t \\<Rightarrow> bool\"\ntype_synonym sp_subj_obj_t = \"partition_id_t \\<Rightarrow> obj_id_t \\<Rightarrow> mode_t \\<Rightarrow> bool\"\n\ninterpretation Policy: abstract_policy_derivation \"configured_subj_obj\".\ninterpretation Policy_properties: policy_axioms Policy.sp_spec_subj_obj Policy.sp_spec_subj_subj Policy.ifp\n  using Policy.correct by auto\n\nlemma example_how_to_use_properties_in_proofs:\n  shows \"\\<forall> p . Policy.ifp p p\"\n  using Policy_properties.ifp_reflexive by auto\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/CISC-Kernel/step/Step_policies.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6370307944803832, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.291210165906773}}
{"text": "theory flash11Bra  imports flash11Rev\n \n  begin\nlemma onInv11:\n\n   assumes  a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" and \n\n     b1:\"r \\<in> rules N\" and b2:\"invf=inv11  iInv1  iInv2 \"\n   shows  \"invHoldForRule' s invf r (invariants   N)\" \n   proof - \nhave c1:\"ex1P N (% iRule1 .  r=NI_Local_GetX_PutX1 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_GetX  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Replace  iRule1 )\\<or>ex0P N (  r=NI_ShWb N )\\<or>ex0P N (  r=PI_Local_GetX_GetX2 )\\<or>ex0P N (  r=NI_Local_PutXAcksDone )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX7 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Nak2  iRule1 )\\<or>ex0P N (  r=NI_ReplaceHomeShrVld )\\<or>ex1P N (% iRule1 .  r=NI_Remote_Put  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX5 N  iRule1 )\\<or>ex0P N (  r=NI_Wb )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Get  iRule1 )\\<or>ex0P N (  r=PI_Local_Replace )\\<or>ex1P N (% iRule1 .  r=NI_ReplaceShrVld  iRule1 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Local_GetX_PutX8 N  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=NI_InvAck_2 N  iRule1 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Remote_Get_Nak2  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=PI_Remote_Replace  iRule1 )\\<or>ex0P N (  r=NI_Nak_Home )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Put2  iRule1 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_InvAck_1  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX11 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX6 N  iRule1 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Remote_Get_Put2  iRule1  iRule2 )\\<or>ex0P N (  r=PI_Local_Get_Put )\\<or>ex0P N (  r=PI_Local_GetX_PutX1 N )\\<or>ex1P N (% iRule1 .  r=NI_InvAck_1_Home  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Remote_Get_Nak1  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Nak1  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_Nak2  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX10_home N  iRule1 )\\<or>ex1P N (% iRule1 .  r=PI_Remote_Get  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_Nak3  iRule1 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Local_GetX_PutX10 N  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX2 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Remote_Get_Put1  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Remote_PutX  iRule1 )\\<or>ex1P N (% iRule1 .  r=Store  iRule1 )\\<or>ex0P N (  r=NI_FAck )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX3 N  iRule1 )\\<or>ex0P N (  r=PI_Local_GetX_PutX3 )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Remote_GetX_PutX  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX8_home N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Put1 N  iRule1 )\\<or>ex0P N (  r=PI_Local_GetX_GetX1 )\\<or>ex0P N (  r=StoreHome )\\<or>ex2P N (% iRule1  iRule2 .  r=NI_Remote_GetX_Nak  iRule1  iRule2 )\\<or>ex1P N (% iRule1 .  r=NI_Inv  iRule1 )\\<or>ex1P N (% iRule1 .  r=PI_Remote_PutX  iRule1 )\\<or>ex0P N (  r=PI_Local_GetX_PutX4 )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX4 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Nak  iRule1 )\\<or>ex0P N (  r=PI_Local_GetX_PutX2 N )\\<or>ex0P N (  r=NI_Local_Put )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_Nak1  iRule1 )\\<or>ex0P N (  r=NI_Nak_Clear )\\<or>ex0P N (  r=PI_Local_PutX )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Nak3  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Remote_GetX_Nak_Home  iRule1 )\\<or>ex0P N (  r=PI_Local_Get_Get )\\<or>ex1P N (% iRule1 .  r=NI_Local_GetX_PutX9 N  iRule1 )\\<or>ex1P N (% iRule1 .  r=PI_Remote_GetX  iRule1 )\\<or>ex0P N (  r=NI_ReplaceHome )\\<or>ex1P N (% iRule1 .  r=NI_Remote_GetX_PutX_Home  iRule1 )\\<or>ex1P N (% iRule1 .  r=NI_Local_Get_Put3  iRule1 )\" \n\n        apply(cut_tac  b1)\n        apply auto\n        done      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX1 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX1 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX1VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_GetX  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_GetX  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_GetX  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_GetXVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Replace  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Replace  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Replace  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_ReplaceVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_ShWb N )\n\"\n         \n         from c1 have c2:\" r= NI_ShWb N \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_ShWb N ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_ShWbVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_GetX2 )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_GetX2 \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Local_GetX_GetX2 ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_GetX_GetX2VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= NI_Local_PutXAcksDone )\n\"\n         \n         from c1 have c2:\" r= NI_Local_PutXAcksDone \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_PutXAcksDone ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_Local_PutXAcksDoneVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX7 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX7 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX7VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Nak2  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Nak2  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_Get_Nak2  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_Nak2VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_ReplaceHomeShrVld )\n\"\n         \n         from c1 have c2:\" r= NI_ReplaceHomeShrVld \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_ReplaceHomeShrVld ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_ReplaceHomeShrVldVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_Put  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_Put  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Remote_Put  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_PutVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX5 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX5 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX5VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_Wb )\n\"\n         \n         from c1 have c2:\" r= NI_Wb \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Wb ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_WbVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Get  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Get  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_Get_Get  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_GetVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_Replace )\n\"\n         \n         from c1 have c2:\" r= PI_Local_Replace \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Local_Replace ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_ReplaceVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_ReplaceShrVld  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_ReplaceShrVld  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_ReplaceShrVld  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_ReplaceShrVldVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Local_GetX_PutX8 N  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Local_GetX_PutX8 N  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX8VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_InvAck_2 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_InvAck_2 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_InvAck_2 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_InvAck_2VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Remote_Get_Nak2  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Remote_Get_Nak2  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_Get_Nak2VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= PI_Remote_Replace  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= PI_Remote_Replace  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Remote_Replace  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis PI_Remote_ReplaceVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_Nak_Home )\n\"\n         \n         from c1 have c2:\" r= NI_Nak_Home \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Nak_Home ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_Nak_HomeVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Put2  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Put2  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_Get_Put2  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_Put2VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_InvAck_1  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_InvAck_1  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_InvAck_1VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX11 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX11 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX11VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX6 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX6 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX6VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Remote_Get_Put2  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Remote_Get_Put2  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_Get_Put2VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_Get_Put )\n\"\n         \n         from c1 have c2:\" r= PI_Local_Get_Put \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Local_Get_Put ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_Get_PutVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_PutX1 N )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_PutX1 N \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Local_GetX_PutX1 N ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_GetX_PutX1VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_InvAck_1_Home  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_InvAck_1_Home  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_InvAck_1_Home  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_InvAck_1_HomeVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_Get_Nak1  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_Get_Nak1  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_Get_Nak1VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Nak1  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Nak1  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_Get_Nak1  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_Nak1VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_Nak2  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_Nak2  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_Nak2VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX10_home N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX10_home N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX10_homeVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= PI_Remote_Get  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= PI_Remote_Get  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Remote_Get  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis PI_Remote_GetVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_Nak3  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_Nak3  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_Nak3VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Local_GetX_PutX10 N  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Local_GetX_PutX10 N  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX10VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX2 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX2 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX2VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_Get_Put1  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_Get_Put1  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Remote_Get_Put1  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_Get_Put1VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_PutX  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_PutX  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Remote_PutX  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_PutXVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= Store  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= Store  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (Store  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis StoreVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_FAck )\n\"\n         \n         from c1 have c2:\" r= NI_FAck \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_FAck ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_FAckVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX3 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX3 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX3VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_PutX3 )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_PutX3 \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Local_GetX_PutX3 ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_GetX_PutX3VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Remote_GetX_PutX  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Remote_GetX_PutX  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_GetX_PutXVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX8_home N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX8_home N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX8_homeVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Put1 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Put1 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_Put1VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_GetX1 )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_GetX1 \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Local_GetX_GetX1 ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_GetX_GetX1VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= StoreHome )\n\"\n         \n         from c1 have c2:\" r= StoreHome \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (StoreHome ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis StoreHomeVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex2P N (% iRule1  iRule2 .  r= NI_Remote_GetX_Nak  iRule1  iRule2 )\n\"\n         \n         from c1 obtain  iRule1  iRule2  where c2:\"  iRule1~=iRule2    \\<and>   iRule1 \\<le> N \\<and>   iRule2 \\<le> N \\<and>  r= NI_Remote_GetX_Nak  iRule1  iRule2 \" \n         by (auto simp add: ex2P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_GetX_NakVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Inv  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Inv  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Inv  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_InvVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= PI_Remote_PutX  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= PI_Remote_PutX  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Remote_PutX  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis PI_Remote_PutXVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_PutX4 )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_PutX4 \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Local_GetX_PutX4 ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_GetX_PutX4VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX4 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX4 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX4VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Nak  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Nak  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Nak  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_NakVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_GetX_PutX2 N )\n\"\n         \n         from c1 have c2:\" r= PI_Local_GetX_PutX2 N \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Local_GetX_PutX2 N ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_GetX_PutX2VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= NI_Local_Put )\n\"\n         \n         from c1 have c2:\" r= NI_Local_Put \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_Put ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_Local_PutVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_Nak1  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_Nak1  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_Nak1VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_Nak_Clear )\n\"\n         \n         from c1 have c2:\" r= NI_Nak_Clear \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Nak_Clear ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_Nak_ClearVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_PutX )\n\"\n         \n         from c1 have c2:\" r= PI_Local_PutX \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Local_PutX ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_PutXVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Nak3  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Nak3  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_Get_Nak3  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_Nak3VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_GetX_Nak_Home  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_GetX_Nak_Home  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_GetX_Nak_HomeVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= PI_Local_Get_Get )\n\"\n         \n         from c1 have c2:\" r= PI_Local_Get_Get \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Local_Get_Get ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis PI_Local_Get_GetVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_GetX_PutX9 N  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_GetX_PutX9 N  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_GetX_PutX9VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= PI_Remote_GetX  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= PI_Remote_GetX  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Remote_GetX  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis PI_Remote_GetXVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex0P N (  r= NI_ReplaceHome )\n\"\n         \n         from c1 have c2:\" r= NI_ReplaceHome \" \n         by (auto simp add: ex0P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_ReplaceHome ) (invariants N) \"\n            apply(cut_tac   a1  a2  a3   b2 c2 )\n            by (metis NI_ReplaceHomeVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n\t}      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Remote_GetX_PutX_Home  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Remote_GetX_PutX_Home  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Remote_GetX_PutX_HomeVsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }      moreover\n        {assume c1: \"ex1P N (% iRule1 .  r= NI_Local_Get_Put3  iRule1 )\n\"\n         \n         from c1 obtain  iRule1  where c2:\"  iRule1 \\<le> N \\<and>  r= NI_Local_Get_Put3  iRule1 \" \n         by (auto simp add: ex1P_def)\n         \n         have \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_Get_Put3  iRule1 ) (invariants N) \"\n            apply(cut_tac  c2   a1  a2  a3 )\n            by (metis NI_Local_Get_Put3VsInv11 ) \n          then have \"invHoldForRule' s invf r (invariants N) \"\n            by(cut_tac c2 b2, metis) \n        }ultimately show \"invHoldForRule' s invf r (invariants N) \"\n          by blast \n     qed\nend", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash11Bra.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6370307944803831, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.29121016590677296}}
{"text": "section {*FUNCTION\\_\\_SDPDA\\_TO\\_LR1\\_STD*}\ntheory\n  FUNCTION__SDPDA_TO_LR1_STD\n\nimports\n  PRJ_12_04_06_07__ENTRY\n\nbegin\n\ndefinition F_SDPDA_TO_LR1_STD__SpecInput :: \"\n  ('nonterminal, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"F_SDPDA_TO_LR1_STD__SpecInput G \\<equiv>\n  valid_simple_dpda G\n  \\<and> \\<not> duplicate_marking G\"\n\ndefinition F_SDPDA_TO_LR1_STD__SpecOutput :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> ('nonterminal, 'event) cfg option\n  \\<Rightarrow> bool\"\n  where\n    \"F_SDPDA_TO_LR1_STD__SpecOutput Gi Go \\<equiv>\n  case Go of\n    None \\<Rightarrow> epdaS.marked_language Gi = {}\n    | Some Go \\<Rightarrow>\n      valid_cfg Go\n      \\<and> cfgLM.marked_language Go = epdaS.marked_language Gi\n      \\<and> cfg_LRk Go (Suc 0)\"\n\ntheorem F_SDPDA_TO_LR1_STD__SOUND: \"\n  F_SDPDA_TO_LR1_STD__SpecInput G\n  \\<Longrightarrow> F_SDPDA_TO_LR1_STD__SpecOutput G (F_SDPDA_TO_LR1_STD G)\"\n  apply(simp add: F_SDPDA_TO_LR1_STD__SpecInput_def F_SDPDA_TO_LR1_STD__SpecOutput_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac G=\"G\" in F_SDPDA_TO_CFG_STD__SOUND)\n   apply(simp add: F_SDPDA_TO_CFG_STD__SpecInput_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac G=\"F_SDPDA_TO_CFG_STD G\" in F_CFG_TRIM__SOUND)\n   apply(simp add: F_CFG_TRIM__SpecInput_def F_SDPDA_TO_CFG_STD__SpecOutput_def)\n  apply(case_tac \"F_SDPDA_TO_LR1_STD G\")\n   apply(clarsimp)\n   apply(simp add: F_SDPDA_TO_LR1_STD_def)\n   apply(simp add: F_CFG_TRIM__SpecOutput_def F_CFG_TRIM__SpecInput_def F_SDPDA_TO_CFG_STD__SpecOutput_def)\n   apply (metis CFG_lang_lm_lang_equal)\n  apply(clarsimp)\n  apply(simp add: F_SDPDA_TO_LR1_STD_def)\n  apply(simp add: F_CFG_TRIM__SpecOutput_def F_CFG_TRIM__SpecInput_def F_SDPDA_TO_CFG_STD__SpecOutput_def)\n  apply(rename_tac Go)\n  apply(rule conjI)\n   apply (metis CFG_lang_lm_lang_equal)\n  apply(rule F_SDPDA_TO_CFG_STD__enforces_cfg_LRk)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(force)\n  done\n\nend\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_12_04_06_07/FUNCTION__SDPDA_TO_LR1_STD.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6370307806984444, "lm_q2_score": 0.45713671682749485, "lm_q1q2_score": 0.2912101596065428}}
{"text": "theory Sequential_Composition_Ref\n  imports \"Basic_Modules/Component_Types/Electoral_Module_Ref\"\n        Verified_Voting_Rule_Construction.Sequential_Composition\n        Refine_Imperative_HOL.Sepref\nbegin\n\ndefinition seq_opt :: \"'a :: {default, heap, hashable} Electoral_Module \\<Rightarrow> \n  'a Electoral_Module\n  \\<Rightarrow> 'a set \\<Rightarrow> 'a Profile \\<Rightarrow> \n  'a Result nres\" \n  where \"seq_opt m n A p \\<equiv> do {\n  let (e, r, d) = m A p;\n  ASSERT (finite d);\n  let newA = d;\n  ASSERT(newA \\<subseteq> A);\n  ASSERT (finite_profile A p);\n  let newp = limit_profile newA p;\n  ASSERT (finite_profile newA newp);\n  let (ne, nr, nd) = n newA newp;\n   RETURN (e \\<union> ne, r \\<union> nr, nd) }\"\n\nlemma seq_opt_correct: \n  fixes m n :: \"'a :: {default, heap, hashable} Electoral_Module\"\n  assumes em_m: \"electoral_module m\" and\n  em_n: \"electoral_module n\"\nshows \"(uncurry (seq_opt m n), uncurry (RETURN oo (sequential_composition' m n))) \\<in>\n  [\\<lambda> (A, p). finite_profile A p]\\<^sub>f (\\<langle>Id\\<rangle>set_rel \\<times>\\<^sub>r \\<langle>\\<langle>Id \\<times>\\<^sub>r Id\\<rangle>set_rel\\<rangle>list_rel) \\<rightarrow> \n  \\<langle>\\<langle>Id\\<rangle>set_rel \\<times>\\<^sub>r \\<langle>Id\\<rangle>set_rel \\<times>\\<^sub>r \\<langle>Id\\<rangle>set_rel\\<rangle>nres_rel\"\n  unfolding comp_apply seq_opt_def\n  apply (intro frefI) apply clarsimp\n  using assms apply (refine_vcg)\n    apply auto\n  subgoal unfolding electoral_module_def\n    by (metis def_presv_fin_prof em_m snd_conv)\n  apply (metis defer_in_alts snd_conv subsetD) \n  by (metis def_presv_fin_prof limit_profile.elims snd_conv)\n\nlocale Seqcomp_Impl =\n  fixes m n :: \"'a :: {default, heap, hashable} Electoral_Module\"\n  fixes m_sep n_sep :: \"'a :: {default, heap, hashable} Electoral_Module_Sep\"\nassumes em_m: \"electoral_module m\" and\n  em_n: \"electoral_module n\"\n  assumes m_sep_correct: \"(uncurry m_sep, uncurry (RETURN oo m)) \\<in> elec_mod_seprel id_assn\"\n  assumes n_sep_correct: \"(uncurry n_sep, uncurry (RETURN oo n)) \\<in> elec_mod_seprel id_assn\"\nbegin\n\n  lemma this_loc: \"Seqcomp_Impl m n m_sep n_sep\" by unfold_locales\n\n  sepref_register m\n  sepref_register n\n\n  declare m_sep_correct[sepref_fr_rules]\n  declare n_sep_correct[sepref_fr_rules]\n\nschematic_goal seqcomp_sepimpl:\n  \"(uncurry ?f2, uncurry (seq_opt m n)) \\<in> elec_mod_seprel id_assn\"\n  unfolding seq_opt_def\n  by sepref\n\nconcrete_definition (in -) seqcomp_sep_uc uses Seqcomp_Impl.seqcomp_sepimpl\n  prepare_code_thms (in -) seqcomp_sep_uc_def\nlemmas  seqcomp_sep_ucp_refine = seqcomp_sep_uc.refine[OF this_loc]\n\nschematic_goal seqcomp_sepcurried:\n \"?curried = curry (seqcomp_sep_uc m_sep n_sep)\" by auto\n\nconcrete_definition (in -) seqcomp_sep uses Seqcomp_Impl.seqcomp_sepcurried\n\ntheorem seqcomp_sep_correct:\n  shows \"(uncurry (seqcomp_sep m_sep n_sep), uncurry (RETURN oo (PR_CONST (m \\<triangleright> n)))) \n\\<in> elec_mod_seprel id_assn\"\n    using seqcomp_sep_ucp_refine[FCOMP seq_opt_correct, OF em_m em_n]\n    unfolding seqcomp_alt_eq seqcomp_sep_def\n    by (simp)\n\nend\n\nabbreviation comp4 (infixl \"oooo\" 55) where \"f oooo g \\<equiv> \\<lambda>x. f ooo (g x)\"\n\n(*theorem seqcomp_sep_correct [sepref_fr_rules]:\n  shows \"(uncurry3 (seqcomp_sep), uncurry3 (RETURN oooo sequential_composition))\n   \\<in> [\\<lambda> (((m,n),a),b). electoral_module m \\<and>\n  electoral_module n \\<and> finite_profile a b]\\<^sub>a (elec_mod_assn_atom nat_assn)\\<^sup>k *\\<^sub>a \n    (elec_mod_assn_atom nat_assn)\\<^sup>k  \n    *\\<^sub>a (alts_set_impl_assn nat_assn)\\<^sup>k *\\<^sub>a (list_assn (ballot_assn nat_assn))\\<^sup>k \n        \\<rightarrow> (result_impl_assn nat_assn)\"\n  apply (intro hfrefI)\n  using Seqcomp_Impl.seqcomp_sep_correct\n  unfolding Seqcomp_Impl_def\n  unfolding hn_refine_def  hfref_def elec_mod_assn_atom_def hfref_def\n  apply (sep_auto simp del: sequential_composition.simps) done\n\nsepref_register \"sequential_composition\"\n\ndeclare seqcomp_sep_correct [sepref_fr_rules]\n\nsepref_decl_op seqi: \"(uncurry3 sequential_composition)\" :: \n  \"\\<langle>elec_mod_rel_orig R, \\<langle>elec_mod_rel_orig R, elec_mod_rel_orig R\\<rangle>fun_rel\\<rangle>fun_rel\" where \n  \"R = (Id)\" apply standard apply (rule nres_relI) unfolding elec_mod_rel_orig_def apply auto\n  done*)\n\n\nabbreviation sequence_opt\n     (infix \"\\<triangleright>sep\" 50) where\n  \"m \\<triangleright>sep n \\<equiv> seqcomp_sep m n\"\n\n\nend", "meta": {"author": "SpringVaS", "repo": "RefinementOfVotingRules", "sha": "a01e44b062fb43e172dff81cffbf941856c977d8", "save_path": "github-repos/isabelle/SpringVaS-RefinementOfVotingRules", "path": "github-repos/isabelle/SpringVaS-RefinementOfVotingRules/RefinementOfVotingRules-a01e44b062fb43e172dff81cffbf941856c977d8/theories/Compositional_Structures/Sequential_Composition_Ref.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982315512489, "lm_q2_score": 0.4493926344647597, "lm_q1q2_score": 0.2911157538784282}}
{"text": "(*  Title:      HOL/Auth/OtwayRees_AN.thy\n    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory\n    Copyright   1996  University of Cambridge\n*)\n\nsection\\<open>The Otway-Rees Protocol as Modified by Abadi and Needham\\<close>\n\ntheory OtwayRees_AN imports Public begin\n\ntext\\<open>\nThis simplified version has minimal encryption and explicit messages.\n\nNote that the formalization does not even assume that nonces are fresh.\nThis is because the protocol does not rely on uniqueness of nonces for\nsecurity, only for freshness, and the proof script does not prove freshness\nproperties.\n\nFrom page 11 of\n  Abadi and Needham (1996).  \n  Prudent Engineering Practice for Cryptographic Protocols.\n  IEEE Trans. SE 22 (1)\n\\<close>\n\ninductive_set otway :: \"event list set\"\n  where\n   Nil: \\<comment>\\<open>The empty trace\\<close>\n        \"[] \\<in> otway\"\n\n | Fake: \\<comment>\\<open>The Spy may say anything he can say.  The sender field is correct,\n            but agents don't use that information.\\<close>\n         \"[| evsf \\<in> otway;  X \\<in> synth (analz (knows Spy evsf)) |]\n          ==> Says Spy B X  # evsf \\<in> otway\"\n\n        \n | Reception: \\<comment>\\<open>A message that has been sent can be received by the\n                  intended recipient.\\<close>\n              \"[| evsr \\<in> otway;  Says A B X \\<in>set evsr |]\n               ==> Gets B X # evsr \\<in> otway\"\n\n | OR1:  \\<comment>\\<open>Alice initiates a protocol run\\<close>\n         \"evs1 \\<in> otway\n          ==> Says A B \\<lbrace>Agent A, Agent B, Nonce NA\\<rbrace> # evs1 \\<in> otway\"\n\n | OR2:  \\<comment>\\<open>Bob's response to Alice's message.\\<close>\n         \"[| evs2 \\<in> otway;\n             Gets B \\<lbrace>Agent A, Agent B, Nonce NA\\<rbrace> \\<in>set evs2 |]\n          ==> Says B Server \\<lbrace>Agent A, Agent B, Nonce NA, Nonce NB\\<rbrace>\n                 # evs2 \\<in> otway\"\n\n | OR3:  \\<comment>\\<open>The Server receives Bob's message.  Then he sends a new\n           session key to Bob with a packet for forwarding to Alice.\\<close>\n         \"[| evs3 \\<in> otway;  Key KAB \\<notin> used evs3;\n             Gets Server \\<lbrace>Agent A, Agent B, Nonce NA, Nonce NB\\<rbrace>\n               \\<in>set evs3 |]\n          ==> Says Server B\n               \\<lbrace>Crypt (shrK A) \\<lbrace>Nonce NA, Agent A, Agent B, Key KAB\\<rbrace>,\n                 Crypt (shrK B) \\<lbrace>Nonce NB, Agent A, Agent B, Key KAB\\<rbrace>\\<rbrace>\n              # evs3 \\<in> otway\"\n\n | OR4:  \\<comment>\\<open>Bob receives the Server's (?) message and compares the Nonces with\n             those in the message he previously sent the Server.\n             Need @{term \"B \\<noteq> Server\"} because we allow messages to self.\\<close>\n         \"[| evs4 \\<in> otway;  B \\<noteq> Server;\n             Says B Server \\<lbrace>Agent A, Agent B, Nonce NA, Nonce NB\\<rbrace> \\<in>set evs4;\n             Gets B \\<lbrace>X, Crypt(shrK B)\\<lbrace>Nonce NB,Agent A,Agent B,Key K\\<rbrace>\\<rbrace>\n               \\<in>set evs4 |]\n          ==> Says B A X # evs4 \\<in> otway\"\n\n | Oops: \\<comment>\\<open>This message models possible leaks of session keys.  The nonces\n             identify the protocol run.\\<close>\n         \"[| evso \\<in> otway;\n             Says Server B\n                      \\<lbrace>Crypt (shrK A) \\<lbrace>Nonce NA, Agent A, Agent B, Key K\\<rbrace>,\n                        Crypt (shrK B) \\<lbrace>Nonce NB, Agent A, Agent B, Key K\\<rbrace>\\<rbrace>\n               \\<in>set evso |]\n          ==> Notes Spy \\<lbrace>Nonce NA, Nonce NB, Key K\\<rbrace> # evso \\<in> otway\"\n\n\ndeclare Says_imp_knows_Spy [THEN analz.Inj, dest]\ndeclare parts.Body  [dest]\ndeclare analz_into_parts [dest]\ndeclare Fake_parts_insert_in_Un  [dest]\n\n\ntext\\<open>A \"possibility property\": there are traces that reach the end\\<close>\nlemma \"[| B \\<noteq> Server; Key K \\<notin> used [] |]\n      ==> \\<exists>evs \\<in> otway.\n           Says B A (Crypt (shrK A) \\<lbrace>Nonce NA, Agent A, Agent B, Key K\\<rbrace>)\n             \\<in> set evs\"\napply (intro exI bexI)\napply (rule_tac [2] otway.Nil\n                    [THEN otway.OR1, THEN otway.Reception,\n                     THEN otway.OR2, THEN otway.Reception,\n                     THEN otway.OR3, THEN otway.Reception, THEN otway.OR4])\napply (possibility, simp add: used_Cons) \ndone\n\nlemma Gets_imp_Says [dest!]:\n     \"[| Gets B X \\<in> set evs; evs \\<in> otway |] ==> \\<exists>A. Says A B X \\<in> set evs\"\nby (erule rev_mp, erule otway.induct, auto)\n\n\n\ntext\\<open>For reasoning about the encrypted portion of messages\\<close>\n\nlemma OR4_analz_knows_Spy:\n     \"[| Gets B \\<lbrace>X, Crypt(shrK B) X'\\<rbrace> \\<in> set evs;  evs \\<in> otway |]\n      ==> X \\<in> analz (knows Spy evs)\"\nby blast\n\n\ntext\\<open>Theorems of the form @{term \"X \\<notin> parts (spies evs)\"} imply that\nNOBODY sends messages containing X!\\<close>\n\ntext\\<open>Spy never sees a good agent's shared key!\\<close>\nlemma Spy_see_shrK [simp]:\n     \"evs \\<in> otway ==> (Key (shrK A) \\<in> parts (knows Spy evs)) = (A \\<in> bad)\"\nby (erule otway.induct, simp_all, blast+)\n\nlemma Spy_analz_shrK [simp]:\n     \"evs \\<in> otway ==> (Key (shrK A) \\<in> analz (knows Spy evs)) = (A \\<in> bad)\"\nby auto\n\nlemma Spy_see_shrK_D [dest!]:\n     \"[|Key (shrK A) \\<in> parts (knows Spy evs);  evs \\<in> otway|] ==> A \\<in> bad\"\nby (blast dest: Spy_see_shrK)\n\n\nsubsection\\<open>Proofs involving analz\\<close>\n\ntext\\<open>Describes the form of K and NA when the Server sends this message.\\<close>\nlemma Says_Server_message_form:\n     \"[| Says Server B\n            \\<lbrace>Crypt (shrK A) \\<lbrace>NA, Agent A, Agent B, Key K\\<rbrace>,\n              Crypt (shrK B) \\<lbrace>NB, Agent A, Agent B, Key K\\<rbrace>\\<rbrace>\n           \\<in> set evs;\n         evs \\<in> otway |]\n      ==> K \\<notin> range shrK & (\\<exists>i. NA = Nonce i) & (\\<exists>j. NB = Nonce j)\"\napply (erule rev_mp)\napply (erule otway.induct, auto)\ndone\n\n\n\n(****\n The following is to prove theorems of the form\n\n  Key K \\<in> analz (insert (Key KAB) (knows Spy evs)) ==>\n  Key K \\<in> analz (knows Spy evs)\n\n A more general formula must be proved inductively.\n****)\n\n\ntext\\<open>Session keys are not used to encrypt other session keys\\<close>\n\ntext\\<open>The equality makes the induction hypothesis easier to apply\\<close>\nlemma analz_image_freshK [rule_format]:\n \"evs \\<in> otway ==>\n   \\<forall>K KK. KK <= -(range shrK) -->\n          (Key K \\<in> analz (Key`KK Un (knows Spy evs))) =\n          (K \\<in> KK | Key K \\<in> analz (knows Spy evs))\"\napply (erule otway.induct) \napply (frule_tac [8] Says_Server_message_form)\napply (drule_tac [7] OR4_analz_knows_Spy, analz_freshK, spy_analz, auto) \ndone\n\nlemma analz_insert_freshK:\n  \"[| evs \\<in> otway;  KAB \\<notin> range shrK |] ==>\n      (Key K \\<in> analz (insert (Key KAB) (knows Spy evs))) =\n      (K = KAB | Key K \\<in> analz (knows Spy evs))\"\nby (simp only: analz_image_freshK analz_image_freshK_simps)\n\n\ntext\\<open>The Key K uniquely identifies the Server's message.\\<close>\nlemma unique_session_keys:\n     \"[| Says Server B\n          \\<lbrace>Crypt (shrK A) \\<lbrace>NA, Agent A, Agent B, K\\<rbrace>,\n            Crypt (shrK B) \\<lbrace>NB, Agent A, Agent B, K\\<rbrace>\\<rbrace>\n         \\<in> set evs;\n        Says Server B'\n          \\<lbrace>Crypt (shrK A') \\<lbrace>NA', Agent A', Agent B', K\\<rbrace>,\n            Crypt (shrK B') \\<lbrace>NB', Agent A', Agent B', K\\<rbrace>\\<rbrace>\n         \\<in> set evs;\n        evs \\<in> otway |]\n     ==> A=A' & B=B' & NA=NA' & NB=NB'\"\napply (erule rev_mp, erule rev_mp, erule otway.induct, simp_all)\napply blast+  \\<comment>\\<open>OR3 and OR4\\<close>\ndone\n\n\nsubsection\\<open>Authenticity properties relating to NA\\<close>\n\ntext\\<open>If the encrypted message appears then it originated with the Server!\\<close>\nlemma NA_Crypt_imp_Server_msg [rule_format]:\n    \"[| A \\<notin> bad;  A \\<noteq> B;  evs \\<in> otway |]\n     ==> Crypt (shrK A) \\<lbrace>NA, Agent A, Agent B, Key K\\<rbrace> \\<in> parts (knows Spy evs)\n       --> (\\<exists>NB. Says Server B\n                    \\<lbrace>Crypt (shrK A) \\<lbrace>NA, Agent A, Agent B, Key K\\<rbrace>,\n                      Crypt (shrK B) \\<lbrace>NB, Agent A, Agent B, Key K\\<rbrace>\\<rbrace>\n                    \\<in> set evs)\"\napply (erule otway.induct, force)\napply (simp_all add: ex_disj_distrib)\napply blast+  \\<comment>\\<open>Fake, OR3\\<close>\ndone\n\n\ntext\\<open>Corollary: if A receives B's OR4 message then it originated with the\n      Server. Freshness may be inferred from nonce NA.\\<close>\nlemma A_trusts_OR4:\n     \"[| Says B' A (Crypt (shrK A) \\<lbrace>NA, Agent A, Agent B, Key K\\<rbrace>) \\<in> set evs;\n         A \\<notin> bad;  A \\<noteq> B;  evs \\<in> otway |]\n      ==> \\<exists>NB. Says Server B\n                  \\<lbrace>Crypt (shrK A) \\<lbrace>NA, Agent A, Agent B, Key K\\<rbrace>,\n                    Crypt (shrK B) \\<lbrace>NB, Agent A, Agent B, Key K\\<rbrace>\\<rbrace>\n                 \\<in> set evs\"\nby (blast intro!: NA_Crypt_imp_Server_msg)\n\n\ntext\\<open>Crucial secrecy property: Spy does not see the keys sent in msg OR3\n    Does not in itself guarantee security: an attack could violate\n    the premises, e.g. by having @{term \"A=Spy\"}\\<close>\nlemma secrecy_lemma:\n     \"[| A \\<notin> bad;  B \\<notin> bad;  evs \\<in> otway |]\n      ==> Says Server B\n           \\<lbrace>Crypt (shrK A) \\<lbrace>NA, Agent A, Agent B, Key K\\<rbrace>,\n             Crypt (shrK B) \\<lbrace>NB, Agent A, Agent B, Key K\\<rbrace>\\<rbrace>\n          \\<in> set evs -->\n          Notes Spy \\<lbrace>NA, NB, Key K\\<rbrace> \\<notin> set evs -->\n          Key K \\<notin> analz (knows Spy evs)\"\napply (erule otway.induct, force)\napply (frule_tac [7] Says_Server_message_form)\napply (drule_tac [6] OR4_analz_knows_Spy)\napply (simp_all add: analz_insert_eq analz_insert_freshK pushes)\napply spy_analz  \\<comment>\\<open>Fake\\<close>\napply (blast dest: unique_session_keys)+  \\<comment>\\<open>OR3, OR4, Oops\\<close>\ndone\n\n\nlemma Spy_not_see_encrypted_key:\n     \"[| Says Server B\n            \\<lbrace>Crypt (shrK A) \\<lbrace>NA, Agent A, Agent B, Key K\\<rbrace>,\n              Crypt (shrK B) \\<lbrace>NB, Agent A, Agent B, Key K\\<rbrace>\\<rbrace>\n           \\<in> set evs;\n         Notes Spy \\<lbrace>NA, NB, Key K\\<rbrace> \\<notin> set evs;\n         A \\<notin> bad;  B \\<notin> bad;  evs \\<in> otway |]\n      ==> Key K \\<notin> analz (knows Spy evs)\"\n  by (metis secrecy_lemma)\n\n\ntext\\<open>A's guarantee.  The Oops premise quantifies over NB because A cannot know\n  what it is.\\<close>\nlemma A_gets_good_key:\n     \"[| Says B' A (Crypt (shrK A) \\<lbrace>NA, Agent A, Agent B, Key K\\<rbrace>) \\<in> set evs;\n         \\<forall>NB. Notes Spy \\<lbrace>NA, NB, Key K\\<rbrace> \\<notin> set evs;\n         A \\<notin> bad;  B \\<notin> bad;  A \\<noteq> B;  evs \\<in> otway |]\n      ==> Key K \\<notin> analz (knows Spy evs)\"\n  by (metis A_trusts_OR4 secrecy_lemma)\n\n\n\nsubsection\\<open>Authenticity properties relating to NB\\<close>\n\ntext\\<open>If the encrypted message appears then it originated with the Server!\\<close>\nlemma NB_Crypt_imp_Server_msg [rule_format]:\n \"[| B \\<notin> bad;  A \\<noteq> B;  evs \\<in> otway |]\n  ==> Crypt (shrK B) \\<lbrace>NB, Agent A, Agent B, Key K\\<rbrace> \\<in> parts (knows Spy evs)\n      --> (\\<exists>NA. Says Server B\n                   \\<lbrace>Crypt (shrK A) \\<lbrace>NA, Agent A, Agent B, Key K\\<rbrace>,\n                     Crypt (shrK B) \\<lbrace>NB, Agent A, Agent B, Key K\\<rbrace>\\<rbrace>\n                   \\<in> set evs)\"\napply (erule otway.induct, force, simp_all add: ex_disj_distrib)\napply blast+  \\<comment>\\<open>Fake, OR3\\<close>\ndone\n\n\n\ntext\\<open>Guarantee for B: if it gets a well-formed certificate then the Server\n  has sent the correct message in round 3.\\<close>\nlemma B_trusts_OR3:\n     \"[| Says S B \\<lbrace>X, Crypt (shrK B) \\<lbrace>NB, Agent A, Agent B, Key K\\<rbrace>\\<rbrace>\n           \\<in> set evs;\n         B \\<notin> bad;  A \\<noteq> B;  evs \\<in> otway |]\n      ==> \\<exists>NA. Says Server B\n                   \\<lbrace>Crypt (shrK A) \\<lbrace>NA, Agent A, Agent B, Key K\\<rbrace>,\n                     Crypt (shrK B) \\<lbrace>NB, Agent A, Agent B, Key K\\<rbrace>\\<rbrace>\n                   \\<in> set evs\"\nby (blast intro!: NB_Crypt_imp_Server_msg)\n\n\ntext\\<open>The obvious combination of \\<open>B_trusts_OR3\\<close> with \n      \\<open>Spy_not_see_encrypted_key\\<close>\\<close>\nlemma B_gets_good_key:\n     \"[| Gets B \\<lbrace>X, Crypt (shrK B) \\<lbrace>NB, Agent A, Agent B, Key K\\<rbrace>\\<rbrace>\n          \\<in> set evs;\n         \\<forall>NA. Notes Spy \\<lbrace>NA, NB, Key K\\<rbrace> \\<notin> set evs;\n         A \\<notin> bad;  B \\<notin> bad;  A \\<noteq> B;  evs \\<in> otway |]\n      ==> Key K \\<notin> analz (knows Spy evs)\"\nby (blast dest: B_trusts_OR3 Spy_not_see_encrypted_key)\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/HOL/Auth/OtwayRees_AN.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982315512488, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.2911157538784281}}
{"text": "theory Semantics_Ternary\nimports Matching_Ternary \"../Common/List_Misc\"\nbegin\n\nsection\\<open>Embedded Ternary-Matching Big Step Semantics\\<close>\n\nsubsection\\<open>Ternary Semantics (Big Step)\\<close>\n\ninductive approximating_bigstep :: \"('a, 'p) match_tac \\<Rightarrow> 'p \\<Rightarrow> 'a rule list \\<Rightarrow> state \\<Rightarrow> state \\<Rightarrow> bool\"\n  (\"_,_\\<turnstile> \\<langle>_, _\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> _\"  [60,60,20,98,98] 89)\n  for \\<gamma> and p where\nskip:  \"\\<gamma>,p\\<turnstile> \\<langle>[], t\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t\" |\naccept:  \"\\<lbrakk>matches \\<gamma> m Accept p\\<rbrakk> \\<Longrightarrow> \\<gamma>,p\\<turnstile> \\<langle>[Rule m Accept], Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Decision FinalAllow\" |\ndrop:  \"\\<lbrakk>matches \\<gamma> m Drop p\\<rbrakk> \\<Longrightarrow> \\<gamma>,p\\<turnstile> \\<langle>[Rule m Drop], Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Decision FinalDeny\" |\nreject:  \"\\<lbrakk>matches \\<gamma> m Reject p\\<rbrakk> \\<Longrightarrow>  \\<gamma>,p\\<turnstile> \\<langle>[Rule m Reject], Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Decision FinalDeny\" |\nlog:   \"\\<lbrakk>matches \\<gamma> m Log p\\<rbrakk> \\<Longrightarrow> \\<gamma>,p\\<turnstile> \\<langle>[Rule m Log], Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Undecided\" |\nempty:   \"\\<lbrakk>matches \\<gamma> m Empty p\\<rbrakk> \\<Longrightarrow> \\<gamma>,p\\<turnstile> \\<langle>[Rule m Empty], Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Undecided\" |\nnomatch:  \"\\<lbrakk>\\<not> matches \\<gamma> m a p\\<rbrakk> \\<Longrightarrow> \\<gamma>,p\\<turnstile> \\<langle>[Rule m a], Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Undecided\" | \ndecision:  \"\\<gamma>,p\\<turnstile> \\<langle>rs, Decision X\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Decision X\" |\nseq:  \"\\<lbrakk>\\<gamma>,p\\<turnstile> \\<langle>rs\\<^sub>1, Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t; \\<gamma>,p\\<turnstile> \\<langle>rs\\<^sub>2, t\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t'\\<rbrakk> \\<Longrightarrow> \\<gamma>,p\\<turnstile> \\<langle>rs\\<^sub>1@rs\\<^sub>2, Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t'\" \n\n\n\nthm approximating_bigstep.induct[of \\<gamma> p rs s t P]\n(*tuned induction rule*)\nlemma approximating_bigstep_induct[case_names Skip Allow Deny Log Nomatch Decision Seq, induct pred: approximating_bigstep] : \"\\<gamma>,p\\<turnstile> \\<langle>rs,s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t \\<Longrightarrow>\n(\\<And>t. P [] t t) \\<Longrightarrow>\n(\\<And>m a. matches \\<gamma> m a p \\<Longrightarrow> a = Accept \\<Longrightarrow> P [Rule m a] Undecided (Decision FinalAllow)) \\<Longrightarrow>\n(\\<And>m a. matches \\<gamma> m a p \\<Longrightarrow> a = Drop \\<or> a = Reject \\<Longrightarrow> P [Rule m a] Undecided (Decision FinalDeny)) \\<Longrightarrow>\n(\\<And>m a. matches \\<gamma> m a p \\<Longrightarrow> a = Log \\<or> a = Empty \\<Longrightarrow> P [Rule m a] Undecided Undecided) \\<Longrightarrow>\n(\\<And>m a. \\<not> matches \\<gamma> m a p \\<Longrightarrow> P [Rule m a] Undecided Undecided) \\<Longrightarrow>\n(\\<And>rs X. P rs (Decision X) (Decision X)) \\<Longrightarrow>\n(\\<And>rs rs\\<^sub>1 rs\\<^sub>2 t t'. rs = rs\\<^sub>1 @ rs\\<^sub>2 \\<Longrightarrow> \\<gamma>,p\\<turnstile> \\<langle>rs\\<^sub>1,Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t \\<Longrightarrow> P rs\\<^sub>1 Undecided t \\<Longrightarrow> \\<gamma>,p\\<turnstile> \\<langle>rs\\<^sub>2,t\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t' \\<Longrightarrow> P rs\\<^sub>2 t t' \\<Longrightarrow> P rs Undecided t')\n   \\<Longrightarrow> P rs s t\"\nby (induction rule: approximating_bigstep.induct) (simp_all)\n\n\nlemma skipD: \"\\<gamma>,p\\<turnstile> \\<langle>[], s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t \\<Longrightarrow> s = t\"\nby (induction \"[]::'a rule list\" s t rule: approximating_bigstep_induct) (simp_all)\n\nlemma decisionD: \"\\<gamma>,p\\<turnstile> \\<langle>rs, Decision X\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t \\<Longrightarrow> t = Decision X\"\nby (induction rs \"Decision X\" t rule: approximating_bigstep_induct) (simp_all)\n\nlemma acceptD: \"\\<gamma>,p\\<turnstile> \\<langle>[Rule m Accept], Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t \\<Longrightarrow> matches \\<gamma> m Accept p \\<Longrightarrow> t = Decision FinalAllow\"\nproof (induction \"[Rule m Accept]\" Undecided t rule: approximating_bigstep_induct)\n  case Seq thus ?case by (metis list_app_singletonE skipD)\nqed(simp_all)\n\n\n\nlemma rejectD: \"\\<gamma>,p\\<turnstile> \\<langle>[Rule m Reject], Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t \\<Longrightarrow> matches \\<gamma> m Reject p \\<Longrightarrow> t = Decision FinalDeny\"\napply (induction \"[Rule m Reject]\" Undecided t rule: approximating_bigstep_induct)\nby(auto dest: skipD elim!: rules_singleton_rev_E)\n\nlemma logD: \"\\<gamma>,p\\<turnstile> \\<langle>[Rule m Log], Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t \\<Longrightarrow> t = Undecided\"\napply (induction \"[Rule m Log]\" Undecided t rule: approximating_bigstep_induct)\nby(auto dest: skipD elim!: rules_singleton_rev_E)\n\nlemma emptyD: \"\\<gamma>,p\\<turnstile> \\<langle>[Rule m Empty], Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t \\<Longrightarrow> t = Undecided\"\napply (induction \"[Rule m Empty]\" Undecided t rule: approximating_bigstep_induct)\nby(auto dest: skipD elim!: rules_singleton_rev_E)\n\nlemma nomatchD: \"\\<gamma>,p\\<turnstile> \\<langle>[Rule m a], Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t \\<Longrightarrow> \\<not> matches \\<gamma> m a p \\<Longrightarrow> t = Undecided\"\napply (induction \"[Rule m a]\" Undecided t rule: approximating_bigstep_induct)\nby(auto dest: skipD elim!: rules_singleton_rev_E)\n\nlemmas approximating_bigstepD = skipD acceptD dropD rejectD logD emptyD nomatchD decisionD\n\nlemma approximating_bigstep_to_undecided: \"\\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Undecided \\<Longrightarrow> s = Undecided\"\n  by (metis decisionD state.exhaust)\n\nlemma approximating_bigstep_to_decision1: \"\\<gamma>,p\\<turnstile> \\<langle>rs, Decision Y\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Decision X \\<Longrightarrow> Y = X\"\n  by (metis decisionD state.inject)\n\nlemma nomatch_fst: \"\\<not> matches \\<gamma> m a p \\<Longrightarrow>  \\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t \\<Longrightarrow> \\<gamma>,p\\<turnstile> \\<langle>Rule m a # rs, s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t\"\n  apply(cases s)\n   apply(clarify)\n   apply(drule nomatch)\n   apply(drule(1) seq)\n   apply (simp; fail)\n  apply(clarify)\n  apply(drule decisionD)\n  apply(clarify)\n apply(simp add: decision)\ndone\n\nlemma seq':\n  assumes \"rs = rs\\<^sub>1 @ rs\\<^sub>2\" \"\\<gamma>,p\\<turnstile> \\<langle>rs\\<^sub>1,s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t\" \"\\<gamma>,p\\<turnstile> \\<langle>rs\\<^sub>2,t\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t'\"\n  shows \"\\<gamma>,p\\<turnstile> \\<langle>rs,s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t'\"\nusing assms by (cases s) (auto intro: seq decision dest: decisionD)\n\nlemma seq_split:\n  assumes \"\\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t\" \"rs = rs\\<^sub>1@rs\\<^sub>2\"\n  obtains t' where \"\\<gamma>,p\\<turnstile> \\<langle>rs\\<^sub>1,s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t'\" \"\\<gamma>,p\\<turnstile> \\<langle>rs\\<^sub>2,t'\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t\"\n  using assms\n  proof (induction rs s t arbitrary: rs\\<^sub>1 rs\\<^sub>2 thesis rule: approximating_bigstep_induct)\n    case Allow thus ?case by (auto dest: skipD elim!: rules_singleton_rev_E intro: approximating_bigstep.intros)\n  next\n    case Deny thus ?case by (auto dest: skipD elim!: rules_singleton_rev_E intro: approximating_bigstep.intros)\n  next\n    case Log thus ?case by (auto dest: skipD elim!: rules_singleton_rev_E intro: approximating_bigstep.intros)\n  next\n    case Nomatch thus ?case by (auto dest: skipD elim!: rules_singleton_rev_E intro: approximating_bigstep.intros)\n  next\n    case (Seq rs rsa rsb t t')\n    hence rs: \"rsa @ rsb = rs\\<^sub>1 @ rs\\<^sub>2\" by simp\n    note List.append_eq_append_conv_if[simp]\n    from rs show ?case\n      proof (cases rule: list_app_eq_cases)\n        case longer\n        with Seq have t1: \"\\<gamma>,p\\<turnstile> \\<langle>take (length rsa) rs\\<^sub>1, Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t\"\n          by simp\n        from Seq longer obtain t2\n          where t2a: \"\\<gamma>,p\\<turnstile> \\<langle>drop (length rsa) rs\\<^sub>1,t\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t2\"\n            and rs2_t2: \"\\<gamma>,p\\<turnstile> \\<langle>rs\\<^sub>2,t2\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t'\"\n          by blast\n        with t1 rs2_t2 have \"\\<gamma>,p\\<turnstile> \\<langle>take (length rsa) rs\\<^sub>1 @ drop (length rsa) rs\\<^sub>1,Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t2\"\n          by (blast intro: approximating_bigstep.seq)\n        with Seq rs2_t2 show ?thesis\n          by simp\n      next\n        case shorter\n        with rs have rsa': \"rsa = rs\\<^sub>1 @ take (length rsa - length rs\\<^sub>1) rs\\<^sub>2\"\n          by (metis append_eq_conv_conj length_drop)\n        from shorter rs have rsb': \"rsb = drop (length rsa - length rs\\<^sub>1) rs\\<^sub>2\"\n          by (metis append_eq_conv_conj length_drop)\n        from Seq rsa' obtain t1\n          where t1a: \"\\<gamma>,p\\<turnstile> \\<langle>rs\\<^sub>1,Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t1\"\n            and t1b: \"\\<gamma>,p\\<turnstile> \\<langle>take (length rsa - length rs\\<^sub>1) rs\\<^sub>2,t1\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t\"\n          by blast\n        from rsb' Seq.hyps have t2: \"\\<gamma>,p\\<turnstile> \\<langle>drop (length rsa - length rs\\<^sub>1) rs\\<^sub>2,t\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t'\"\n          by blast\n        with seq' t1b have \"\\<gamma>,p\\<turnstile> \\<langle>rs\\<^sub>2,t1\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t'\" by (metis append_take_drop_id)\n        with Seq t1a show ?thesis\n          by fast\n      qed\n  qed (auto intro: approximating_bigstep.intros)\n\n\nlemma seqE_fst:\n  assumes \"\\<gamma>,p\\<turnstile> \\<langle>r#rs, s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t\"\n  obtains t' where \"\\<gamma>,p\\<turnstile> \\<langle>[r],s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t'\" \"\\<gamma>,p\\<turnstile> \\<langle>rs,t'\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t\"\n  using assms seq_split by (metis append_Cons append_Nil)\n\nlemma seq_fst: assumes \"\\<gamma>,p\\<turnstile> \\<langle>[r], s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t\" and \"\\<gamma>,p\\<turnstile> \\<langle>rs, t\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t'\" shows \"\\<gamma>,p\\<turnstile> \\<langle>r # rs, s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t'\"\nproof(cases s)\n  case Undecided with assms seq show \"\\<gamma>,p\\<turnstile> \\<langle>r # rs, s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t'\" by fastforce\n  next\n  case Decision with assms show \"\\<gamma>,p\\<turnstile> \\<langle>r # rs, s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t'\"\n  by(auto simp: decision dest!: decisionD)\nqed\n\n\nsubsection\\<open>wf ruleset\\<close>\n  text\\<open>\n  A @{typ \"'a rule list\"} here is well-formed (for a packet) if\n    \\<^item> either the rules do not match\n    \\<^item> or the action is not @{const Call}, not @{const Return}, not @{const Unknown}\n\\<close>\n  definition wf_ruleset :: \"('a, 'p) match_tac \\<Rightarrow> 'p \\<Rightarrow> 'a rule list \\<Rightarrow> bool\" where\n    \"wf_ruleset \\<gamma> p rs \\<equiv> \\<forall>r \\<in> set rs. \n      (\\<not> matches \\<gamma> (get_match r) (get_action r) p) \\<or> \n      (\\<not>(\\<exists>chain. get_action r = Call chain) \\<and> get_action r \\<noteq> Return \\<and> \\<not>(\\<exists>chain. get_action r = Goto chain) \\<and> get_action r \\<noteq> Unknown)\"\n\n  lemma wf_ruleset_append: \"wf_ruleset \\<gamma> p (rs1@rs2) \\<longleftrightarrow> wf_ruleset \\<gamma> p rs1 \\<and> wf_ruleset \\<gamma> p rs2\"\n    by(auto simp add: wf_ruleset_def)\n  lemma wf_rulesetD: assumes \"wf_ruleset \\<gamma> p (r # rs)\" shows \"wf_ruleset \\<gamma> p [r]\" and \"wf_ruleset \\<gamma> p rs\"\n    using assms by(auto simp add: wf_ruleset_def)\n  lemma wf_ruleset_fst: \"wf_ruleset \\<gamma> p (Rule m a # rs) \\<longleftrightarrow> wf_ruleset \\<gamma> p [Rule m a] \\<and> wf_ruleset \\<gamma> p rs\"\n    by(auto simp add: wf_ruleset_def)\n  lemma wf_ruleset_stripfst: \"wf_ruleset \\<gamma> p (r # rs) \\<Longrightarrow> wf_ruleset \\<gamma> p (rs)\"\n    by(simp add: wf_ruleset_def)\n  lemma wf_ruleset_rest: \"wf_ruleset \\<gamma> p (Rule m a # rs) \\<Longrightarrow> wf_ruleset \\<gamma> p [Rule m a]\"\n    by(simp add: wf_ruleset_def)\n\nsubsection\\<open>Ternary Semantics (Function)\\<close>\n\nfun approximating_bigstep_fun :: \"('a, 'p) match_tac \\<Rightarrow> 'p \\<Rightarrow> 'a rule list \\<Rightarrow> state \\<Rightarrow> state\" where\n  \"approximating_bigstep_fun \\<gamma> p [] s = s\" |\n  \"approximating_bigstep_fun \\<gamma> p rs (Decision X) = (Decision X)\" |\n  \"approximating_bigstep_fun \\<gamma> p ((Rule m a)#rs) Undecided = (if \n      \\<not> matches \\<gamma> m a p\n    then\n      approximating_bigstep_fun \\<gamma> p rs Undecided\n    else\n      case a of Accept \\<Rightarrow> Decision FinalAllow\n              | Drop \\<Rightarrow> Decision FinalDeny\n              | Reject \\<Rightarrow> Decision FinalDeny\n              | Log \\<Rightarrow> approximating_bigstep_fun \\<gamma> p rs Undecided\n              | Empty \\<Rightarrow> approximating_bigstep_fun \\<gamma> p rs Undecided\n              (*unhalndled cases*)\n              )\"\n\n\n\n(*tuned induction rule*)\nlemma approximating_bigstep_fun_induct[case_names Empty Decision Nomatch Match] : \"\n(\\<And>\\<gamma> p s. P \\<gamma> p [] s) \\<Longrightarrow>\n(\\<And>\\<gamma> p r rs X. P \\<gamma> p (r # rs) (Decision X)) \\<Longrightarrow>\n(\\<And>\\<gamma> p m a rs.\n    \\<not> matches \\<gamma> m a p \\<Longrightarrow> P \\<gamma> p rs Undecided \\<Longrightarrow> P \\<gamma> p (Rule m a # rs) Undecided) \\<Longrightarrow>\n(\\<And>\\<gamma> p m a rs.\n    matches \\<gamma> m a p \\<Longrightarrow> (a = Log \\<Longrightarrow> P \\<gamma> p rs Undecided) \\<Longrightarrow> (a = Empty \\<Longrightarrow> P \\<gamma> p rs Undecided) \\<Longrightarrow> P \\<gamma> p (Rule m a # rs) Undecided) \\<Longrightarrow>\nP \\<gamma> p rs s\"\napply (rule approximating_bigstep_fun.induct[of P \\<gamma> p rs s])\n  apply (simp_all)\nby metis\n\nlemma Decision_approximating_bigstep_fun: \"approximating_bigstep_fun \\<gamma> p rs (Decision X) = Decision X\"\n  by(induction rs) (simp_all)\n\n  \nlemma approximating_bigstep_fun_induct_wf[case_names Empty Decision Nomatch MatchAccept MatchDrop MatchReject MatchLog MatchEmpty, consumes 1]:\n  \"wf_ruleset \\<gamma> p rs \\<Longrightarrow>\n(\\<And>\\<gamma> p s. P \\<gamma> p [] s) \\<Longrightarrow>\n(\\<And>\\<gamma> p r rs X. P \\<gamma> p (r # rs) (Decision X)) \\<Longrightarrow>\n(\\<And>\\<gamma> p m a rs.\n    \\<not> matches \\<gamma> m a p \\<Longrightarrow> P \\<gamma> p rs Undecided \\<Longrightarrow> P \\<gamma> p (Rule m a # rs) Undecided) \\<Longrightarrow>\n(\\<And>\\<gamma> p m a rs.\n    matches \\<gamma> m a p \\<Longrightarrow> a = Accept  \\<Longrightarrow> P \\<gamma> p (Rule m a # rs) Undecided) \\<Longrightarrow>\n(\\<And>\\<gamma> p m a rs.\n    matches \\<gamma> m a p \\<Longrightarrow> a = Drop \\<Longrightarrow> P \\<gamma> p (Rule m a # rs) Undecided) \\<Longrightarrow>\n(\\<And>\\<gamma> p m a rs.\n    matches \\<gamma> m a p \\<Longrightarrow> a = Reject \\<Longrightarrow> P \\<gamma> p (Rule m a # rs) Undecided) \\<Longrightarrow>\n(\\<And>\\<gamma> p m a rs.\n    matches \\<gamma> m a p \\<Longrightarrow> a = Log \\<Longrightarrow> P \\<gamma> p rs Undecided  \\<Longrightarrow> P \\<gamma> p (Rule m a # rs) Undecided) \\<Longrightarrow>\n(\\<And>\\<gamma> p m a rs.\n    matches \\<gamma> m a p \\<Longrightarrow> a = Empty \\<Longrightarrow> P \\<gamma> p rs Undecided \\<Longrightarrow> P \\<gamma> p (Rule m a # rs) Undecided) \\<Longrightarrow>\nP \\<gamma> p rs s\"\n  proof(induction \\<gamma> p rs s rule: approximating_bigstep_fun_induct)\n  case Empty thus ?case by blast\n  next\n  case Decision thus ?case by blast\n  next\n  case Nomatch thus ?case by(simp add: wf_ruleset_def)\n  next\n  case (Match \\<gamma> p m a) thus ?case\n    apply -\n    apply(frule wf_rulesetD(1), drule wf_rulesetD(2))\n    apply(simp)\n    apply(cases a)\n           apply(simp_all)\n      apply(auto simp add: wf_ruleset_def)\n    done\n  qed\n\nlemma just_show_all_approximating_bigstep_fun_equalities_with_start_Undecided[case_names Undecided]: \n      assumes \"s = Undecided \\<Longrightarrow> approximating_bigstep_fun \\<gamma> p rs1 s = approximating_bigstep_fun \\<gamma> p rs2 s\"\n      shows \"approximating_bigstep_fun \\<gamma> p rs1 s = approximating_bigstep_fun \\<gamma> p rs2 s\"\n  proof(cases s)\n  case Undecided thus ?thesis using assms by simp\n  next\n  case Decision thus ?thesis by (simp add: Decision_approximating_bigstep_fun)\n  qed\n\nsubsubsection\\<open>Append, Prepend, Postpend, Composition\\<close>\n  lemma approximating_bigstep_fun_seq_wf: \"\\<lbrakk> wf_ruleset \\<gamma> p rs\\<^sub>1\\<rbrakk> \\<Longrightarrow>\n      approximating_bigstep_fun \\<gamma> p (rs\\<^sub>1 @ rs\\<^sub>2) s = approximating_bigstep_fun \\<gamma> p rs\\<^sub>2 (approximating_bigstep_fun \\<gamma> p rs\\<^sub>1 s)\"\n   proof(induction \\<gamma> p rs\\<^sub>1 s rule: approximating_bigstep_fun_induct)\n   qed(simp_all add: wf_ruleset_def Decision_approximating_bigstep_fun split: action.split)\n\n  text\\<open>The state transitions from @{const Undecided} to @{const Undecided} if all intermediate states are @{const Undecided}\\<close>\n lemma approximating_bigstep_fun_seq_Undecided_wf: \"\\<lbrakk> wf_ruleset \\<gamma> p (rs1@rs2)\\<rbrakk> \\<Longrightarrow> \n      approximating_bigstep_fun \\<gamma> p (rs1@rs2) Undecided = Undecided \\<longleftrightarrow> \n  approximating_bigstep_fun \\<gamma> p rs1 Undecided = Undecided \\<and> approximating_bigstep_fun \\<gamma> p rs2 Undecided = Undecided\"\n    proof(induction \\<gamma> p rs1 Undecided rule: approximating_bigstep_fun_induct)\n    qed(simp_all add: wf_ruleset_def split: action.split)\n\n\n  lemma approximating_bigstep_fun_seq_Undecided_t_wf: \"\\<lbrakk> wf_ruleset \\<gamma> p (rs1@rs2)\\<rbrakk> \\<Longrightarrow> \n      approximating_bigstep_fun \\<gamma> p (rs1@rs2) Undecided = t \\<longleftrightarrow> \n  approximating_bigstep_fun \\<gamma> p rs1 Undecided = Undecided \\<and> approximating_bigstep_fun \\<gamma> p rs2 Undecided = t \\<or>\n  approximating_bigstep_fun \\<gamma> p rs1 Undecided = t \\<and> t \\<noteq> Undecided\"\n  proof(induction \\<gamma> p rs1 Undecided rule: approximating_bigstep_fun_induct)\n  case Empty thus ?case by(cases t) simp_all\n  next\n  case Nomatch thus ?case by(simp add: wf_ruleset_def)\n  next\n  case Match thus ?case by(auto simp add: wf_ruleset_def split: action.split)\n  qed\n \n\n  lemma approximating_bigstep_fun_wf_postpend: \"wf_ruleset \\<gamma> p rsA \\<Longrightarrow> wf_ruleset \\<gamma> p rsB \\<Longrightarrow> \n      approximating_bigstep_fun \\<gamma> p rsA s = approximating_bigstep_fun \\<gamma> p rsB s \\<Longrightarrow> \n      approximating_bigstep_fun \\<gamma> p (rsA@rsC) s = approximating_bigstep_fun \\<gamma> p (rsB@rsC) s\"\n  apply(induction \\<gamma> p rsA s rule: approximating_bigstep_fun_induct_wf)\n         apply(simp_all add: approximating_bigstep_fun_seq_wf)\n     apply (metis Decision_approximating_bigstep_fun)+\n  done\n\n\nlemma approximating_bigstep_fun_singleton_prepend:\n    assumes \"approximating_bigstep_fun \\<gamma> p rsB s = approximating_bigstep_fun \\<gamma> p rsC s\"\n    shows \"approximating_bigstep_fun \\<gamma> p (r#rsB) s = approximating_bigstep_fun \\<gamma> p (r#rsC) s\"\n  proof(cases s)\n  case Decision thus ?thesis by(simp add: Decision_approximating_bigstep_fun)\n  next\n  case Undecided\n  with assms show ?thesis by(cases r)(simp split: action.split)\n  qed\n\nsubsection\\<open>Equality with @{term \"\\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t\"} semantics\\<close>\n  lemma approximating_bigstep_wf: \"\\<gamma>,p\\<turnstile> \\<langle>rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Undecided \\<Longrightarrow> wf_ruleset \\<gamma> p rs\"\n  unfolding wf_ruleset_def\n  proof(induction rs Undecided Undecided rule: approximating_bigstep_induct)\n    case Skip thus ?case by simp\n    next\n    case Log thus ?case by auto\n    next\n    case Nomatch thus ?case by simp\n    next\n    case (Seq rs rs1 rs2 t)\n      from Seq approximating_bigstep_to_undecided have \"t = Undecided\" by fast\n      from this Seq show ?case by auto\n  qed\n  \n\n  text\\<open>only valid actions appear in this ruleset\\<close>\n  definition good_ruleset :: \"'a rule list \\<Rightarrow> bool\" where\n    \"good_ruleset rs \\<equiv> \\<forall>r \\<in> set rs. (\\<not>(\\<exists>chain. get_action r = Call chain) \\<and> get_action r \\<noteq> Return \\<and> \\<not>(\\<exists>chain. get_action r = Goto chain) \\<and> get_action r \\<noteq> Unknown)\"\n\n  \n\n  lemma good_ruleset_alt: \"good_ruleset rs = (\\<forall>r\\<in>set rs. get_action r = Accept \\<or> get_action r = Drop \\<or>\n                                                get_action r = Reject \\<or> get_action r = Log  \\<or> get_action r = Empty)\"\n      unfolding good_ruleset_def\n      apply(rule Set.ball_cong)\n       apply(simp_all)\n      apply(rename_tac r)\n      by(case_tac \"get_action r\")(simp_all)\n\n\n  lemma good_ruleset_append: \"good_ruleset (rs\\<^sub>1 @ rs\\<^sub>2) \\<longleftrightarrow> good_ruleset rs\\<^sub>1 \\<and> good_ruleset rs\\<^sub>2\"\n    by(simp add: good_ruleset_alt, blast)\n\n  lemma good_ruleset_fst: \"good_ruleset (r#rs) \\<Longrightarrow> good_ruleset [r]\"\n    by(simp add: good_ruleset_def)\n  lemma good_ruleset_tail: \"good_ruleset (r#rs) \\<Longrightarrow> good_ruleset rs\"\n    by(simp add: good_ruleset_def)\n\n  text\\<open>\n    @{term good_ruleset} is stricter than @{term wf_ruleset}. It can be easily checked with running code!\n\\<close>\n  lemma good_imp_wf_ruleset: \"good_ruleset rs \\<Longrightarrow> wf_ruleset \\<gamma> p rs\" by (metis good_ruleset_def wf_ruleset_def)\n\n  lemma simple_imp_good_ruleset: \"simple_ruleset rs \\<Longrightarrow> good_ruleset rs\"\n    by(simp add: simple_ruleset_def good_ruleset_def, fastforce)\n\n\nlemma approximating_bigstep_fun_seq_semantics: \"\\<lbrakk> \\<gamma>,p\\<turnstile> \\<langle>rs\\<^sub>1, s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t \\<rbrakk> \\<Longrightarrow> \n    approximating_bigstep_fun \\<gamma> p (rs\\<^sub>1 @ rs\\<^sub>2) s = approximating_bigstep_fun \\<gamma> p rs\\<^sub>2 t\"\n  proof(induction rs\\<^sub>1 s t arbitrary: rs\\<^sub>2 rule: approximating_bigstep.induct)\n  qed(simp_all add: Decision_approximating_bigstep_fun)\n\nlemma approximating_semantics_imp_fun: \"\\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t \\<Longrightarrow> approximating_bigstep_fun \\<gamma> p rs s = t\"\n  proof(induction rs s t rule: approximating_bigstep_induct)\n  qed(auto simp add: approximating_bigstep_fun_seq_semantics Decision_approximating_bigstep_fun)\n\nlemma approximating_fun_imp_semantics: assumes \"wf_ruleset \\<gamma> p rs\"\n      shows \"approximating_bigstep_fun \\<gamma> p rs s = t \\<Longrightarrow> \\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t\"\n  using assms proof(induction \\<gamma> p rs s rule: approximating_bigstep_fun_induct_wf)\n    case (Empty \\<gamma> p s)\n      thus \"\\<gamma>,p\\<turnstile> \\<langle>[], s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t\"  using skip by(simp)\n    next\n    case (Decision \\<gamma> p r rs X)\n      hence \"t = Decision X\" by simp\n      thus \"\\<gamma>,p\\<turnstile> \\<langle>r # rs, Decision X\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t\" using decision by fast\n    next\n    case (Nomatch \\<gamma> p m a rs)\n      thus \"\\<gamma>,p\\<turnstile> \\<langle>Rule m a # rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t\"\n        apply(rule_tac t=Undecided in seq_fst)\n         apply(simp add: nomatch)\n        apply(simp add: Nomatch.IH)\n        done\n    next\n    case (MatchAccept \\<gamma> p m a rs)\n      hence \"t = Decision FinalAllow\" by simp\n      thus ?case by (metis MatchAccept.hyps accept decision seq_fst)\n    next\n    case (MatchDrop \\<gamma> p m a rs)\n      hence \"t = Decision FinalDeny\" by simp\n      thus ?case by (metis MatchDrop.hyps drop decision seq_fst)\n    next\n    case (MatchReject \\<gamma> p m a rs)\n      hence \"t = Decision FinalDeny\" by simp\n      thus ?case by (metis MatchReject.hyps reject decision seq_fst)\n    next\n    case (MatchLog \\<gamma> p m a rs)\n      thus ?case\n        apply(simp)\n        apply(rule_tac t=Undecided in seq_fst)\n         apply(simp add: log)\n        apply(simp add: MatchLog.IH)\n        done\n    next\n    case (MatchEmpty \\<gamma> p m a rs)\n      thus ?case\n        apply(simp)\n        apply(rule_tac t=Undecided in seq_fst)\n         apply(simp add: empty)\n        apply(simp add: MatchEmpty.IH)\n        done\n    qed\n\n\ntext\\<open>Henceforth, we will use the @{term approximating_bigstep_fun} semantics, because they are easier.\nWe show that they are equal.\n\\<close>\ntheorem approximating_semantics_iff_fun: \"wf_ruleset \\<gamma> p rs \\<Longrightarrow>\n    \\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t \\<longleftrightarrow> approximating_bigstep_fun \\<gamma> p rs s = t\"\nby (metis approximating_fun_imp_semantics approximating_semantics_imp_fun)\n\ncorollary approximating_semantics_iff_fun_good_ruleset: \"good_ruleset rs \\<Longrightarrow>\n    \\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t \\<longleftrightarrow> approximating_bigstep_fun \\<gamma> p rs s = t\"\n  by (metis approximating_semantics_iff_fun good_imp_wf_ruleset)\n\nlemma approximating_bigstep_deterministic: \"\\<lbrakk> \\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t; \\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t' \\<rbrakk> \\<Longrightarrow> t = t'\"\n  proof(induction arbitrary: t' rule: approximating_bigstep_induct)\n  case Seq thus ?case\n    by (metis (hide_lams, mono_tags) append_Nil2 approximating_bigstep_fun.simps(1) approximating_bigstep_fun_seq_semantics)\n  qed(auto dest: approximating_bigstepD)\n\n\n\nlemma rm_LogEmpty_fun_semantics: \n  \"approximating_bigstep_fun \\<gamma> p (rm_LogEmpty rs) s = approximating_bigstep_fun \\<gamma> p rs s\"\n  proof(induction \\<gamma> p rs s rule: approximating_bigstep_fun_induct)\n    case Empty thus ?case by(simp)\n    next\n    case Decision thus ?case by(simp add: Decision_approximating_bigstep_fun)\n    next\n    case (Nomatch \\<gamma> p m a rs) thus ?case by(cases a,simp_all)\n    next\n    case (Match \\<gamma> p m a rs) thus ?case by(cases a,simp_all)\n  qed\n\n\n(*we probably don't need the following*)\nlemma \"\\<gamma>,p\\<turnstile> \\<langle>rm_LogEmpty rs, s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t \\<longleftrightarrow> \\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> t\"\napply(rule iffI)\n apply(induction rs arbitrary: s t)\n  apply(simp_all)\n apply(rename_tac r rs s t)\n apply(case_tac r)\n apply(simp)\n apply(rename_tac m a)\n apply(case_tac a)\n         apply(simp_all)\n         apply(auto intro: approximating_bigstep.intros )\n         apply(erule seqE_fst, simp add: seq_fst)\n        apply(erule seqE_fst, simp add: seq_fst)\n       apply (metis decision log nomatch_fst seq_fst state.exhaust)\n      apply(erule seqE_fst, simp add: seq_fst)\n     apply(erule seqE_fst, simp add: seq_fst)\n    apply(erule seqE_fst, simp add: seq_fst)\n   apply(erule seqE_fst, simp add: seq_fst)\n  apply (metis decision empty nomatch_fst seq_fst state.exhaust)\n apply(erule seqE_fst, simp add: seq_fst)\napply(induction rs s t rule: approximating_bigstep_induct)\n      apply(auto intro: approximating_bigstep.intros)\n apply(rename_tac m a)\n apply(case_tac a)\n         apply(auto intro: approximating_bigstep.intros)\napply(rename_tac rs\\<^sub>1 rs\\<^sub>2 t t')\napply(drule_tac rs\\<^sub>1=\"rm_LogEmpty rs\\<^sub>1\" and rs\\<^sub>2=\"rm_LogEmpty rs\\<^sub>2\" in seq)\n apply(simp_all)\nusing rm_LogEmpty_seq apply metis\ndone\n\n\nlemma rm_LogEmpty_simple_but_Reject: \n  \"good_ruleset rs \\<Longrightarrow> \\<forall>r \\<in> set (rm_LogEmpty rs). get_action r = Accept \\<or> get_action r = Reject \\<or> get_action r = Drop\"\n  proof(induction rs)\n  case Nil thus ?case by(simp add: good_ruleset_def)\n  next\n  case (Cons r rs) thus ?case\n    apply(clarify)\n    apply(cases r, rename_tac m a, simp)\n    by(case_tac a) (auto simp add: good_ruleset_def)\n  qed\n\n\n\nlemma rw_Reject_fun_semantics: \n  \"wf_unknown_match_tac \\<alpha> \\<Longrightarrow> \n  (approximating_bigstep_fun (\\<beta>, \\<alpha>) p (rw_Reject rs) s = approximating_bigstep_fun (\\<beta>, \\<alpha>) p rs s)\"\n  proof(induction rs)\n  case Nil thus ?case by simp\n  next\n  case (Cons r rs)\n    thus ?case\n      apply(case_tac r, rename_tac m a, simp)\n      apply(case_tac a)\n              apply(case_tac [!] s)\n                      apply(auto dest: wf_unknown_match_tacD_False1 wf_unknown_match_tacD_False2)\n      done\n    qed\n\nlemma rmLogEmpty_rwReject_good_to_simple: \"good_ruleset rs \\<Longrightarrow> simple_ruleset (rw_Reject (rm_LogEmpty rs))\"\n  apply(drule rm_LogEmpty_simple_but_Reject)\n  apply(simp add: simple_ruleset_def)\n  apply(induction rs)\n   apply(simp_all)\n  apply(rename_tac r rs)\n  apply(case_tac r)\n  apply(rename_tac m a)\n  apply(case_tac a)\n          apply(simp_all)\n  done\n\nsubsection\\<open>Matching\\<close>\nlemma optimize_matches_option_generic:\n  assumes \"\\<forall> r \\<in> set rs. P (get_match r) (get_action r)\"\n      and \"(\\<And>m m' a. P m a \\<Longrightarrow> f m = Some m' \\<Longrightarrow> matches \\<gamma> m' a p = matches \\<gamma> m a p)\"\n      and \"(\\<And>m a. P m a \\<Longrightarrow> f m = None \\<Longrightarrow> \\<not> matches \\<gamma> m a p)\"\n  shows \"approximating_bigstep_fun \\<gamma> p (optimize_matches_option f rs) s = approximating_bigstep_fun \\<gamma> p rs s\"\n    using assms proof(induction \\<gamma> p rs s rule: approximating_bigstep_fun_induct)\n      case Decision thus ?case by (simp add: Decision_approximating_bigstep_fun)\n    next\n      case (Nomatch \\<gamma> p m a rs) thus ?case\n        apply(simp)\n        apply(cases \"f m\")\n         apply(simp; fail)\n        apply(simp del: approximating_bigstep_fun.simps)\n        apply(rename_tac m')\n        apply(subgoal_tac \"\\<not> matches \\<gamma> m' a p\")\n         apply(simp; fail)\n        using assms by blast\n    next\n      case (Match \\<gamma> p m a rs) thus ?case\n        apply(cases \"f m\")\n         apply(simp; fail)\n        apply(simp del: approximating_bigstep_fun.simps)\n        apply(rename_tac m')\n        apply(subgoal_tac \"matches \\<gamma> m' a p\")\n         apply(simp split: action.split; fail)\n        using assms by blast\n    qed(simp)\n\n\nlemma optimize_matches_generic: \"\\<forall> r \\<in> set rs. P (get_match r) (get_action r) \\<Longrightarrow> \n      (\\<And>m a. P m a \\<Longrightarrow> matches \\<gamma> (f m) a p = matches \\<gamma> m a p) \\<Longrightarrow>\n      approximating_bigstep_fun \\<gamma> p (optimize_matches f rs) s = approximating_bigstep_fun \\<gamma> p rs s\"\n  unfolding optimize_matches_def\n  apply(rule optimize_matches_option_generic)\n    apply(simp; fail)\n   apply(simp split: if_split_asm)\n   apply blast\n  apply(simp split: if_split_asm)\n  using matcheq_matchNone_not_matches by fast\n\n\nlemma optimize_matches_matches_fst: \"matches \\<gamma> (f m) a p \\<Longrightarrow> optimize_matches f (Rule m a # rs) = (Rule (f m) a)# optimize_matches f rs\"\n  apply(simp add: optimize_matches_def)\n  by (meson matcheq_matchNone_not_matches)\n\n\nlemma optimize_matches: \"\\<forall>m a. matches \\<gamma> (f m) a p = matches \\<gamma> m a p \\<Longrightarrow> approximating_bigstep_fun \\<gamma> p (optimize_matches f rs) s = approximating_bigstep_fun \\<gamma> p rs s\"\n  using optimize_matches_generic[where P=\"\\<lambda>_ _. True\"] by metis\n\n\nlemma optimize_matches_opt_MatchAny_match_expr: \"approximating_bigstep_fun \\<gamma> p (optimize_matches opt_MatchAny_match_expr rs) s = approximating_bigstep_fun \\<gamma> p rs s\"\nusing optimize_matches opt_MatchAny_match_expr_correct by metis\n\n\nlemma optimize_matches_a: \"\\<forall>a m. matches \\<gamma> m a = matches \\<gamma> (f a m) a \\<Longrightarrow> approximating_bigstep_fun \\<gamma> p (optimize_matches_a f rs) s = approximating_bigstep_fun \\<gamma> p rs s\"\n  proof(induction \\<gamma> p rs s rule: approximating_bigstep_fun_induct)\n    case (Match \\<gamma> p m a rs) thus ?case by(case_tac a)(simp_all add: optimize_matches_a_def)\n  qed(simp_all add: optimize_matches_a_def)\n\n\nlemma optimize_matches_a_simplers:\n  assumes \"simple_ruleset rs\" and \"\\<forall>a m. a = Accept \\<or> a = Drop \\<longrightarrow> matches \\<gamma> (f a m) a = matches \\<gamma> m a\"\n  shows \"approximating_bigstep_fun \\<gamma> p (optimize_matches_a f rs) s = approximating_bigstep_fun \\<gamma> p rs s\"\nproof -\n  from assms(1) have \"wf_ruleset \\<gamma> p rs\" by(simp add: simple_imp_good_ruleset good_imp_wf_ruleset)\n  from \\<open>wf_ruleset \\<gamma> p rs\\<close> assms show \"approximating_bigstep_fun \\<gamma> p (optimize_matches_a f rs) s = approximating_bigstep_fun \\<gamma> p rs s\"\n    proof(induction \\<gamma> p rs s rule: approximating_bigstep_fun_induct_wf)\n    case Nomatch thus ?case\n     apply(simp add: optimize_matches_a_def simple_ruleset_def)\n     apply(safe)\n      apply(simp_all)\n    done\n    next\n    case MatchReject thus ?case by(simp add: optimize_matches_a_def simple_ruleset_def)\n    qed(simp_all add: optimize_matches_a_def simple_ruleset_tail)\nqed\n\n\n\nlemma not_matches_removeAll: \"\\<not> matches \\<gamma> m a p \\<Longrightarrow>\n  approximating_bigstep_fun \\<gamma> p (removeAll (Rule m a) rs) Undecided = approximating_bigstep_fun \\<gamma> p rs Undecided\"\n  apply(induction \\<gamma> p rs Undecided rule: approximating_bigstep_fun.induct)\n   apply(simp)\n  apply(simp split: action.split)\n  apply blast\n  done\n\n\nend\n", "meta": {"author": "diekmann", "repo": "Iptables_Semantics", "sha": "e0a2516bd885708fce875023b474ae341cbdee29", "save_path": "github-repos/isabelle/diekmann-Iptables_Semantics", "path": "github-repos/isabelle/diekmann-Iptables_Semantics/Iptables_Semantics-e0a2516bd885708fce875023b474ae341cbdee29/thy/Iptables_Semantics/Semantics_Ternary/Semantics_Ternary.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.29111574776707544}}
{"text": "theory Ex_CFG\nimports Monad2\nbegin\n  term fold\n\n\n\n  datatype err = STATIC_ERROR\n\n\n\n\n\n\n\n\n  type_synonym state = \"string \\<Rightarrow> int\"\n  type_synonym label = string\n  type_synonym proc_name = string\n  type_synonym val = \"int\"\n\n  datatype nt_instr = I_BASIC \"state \\<Rightarrow> state\" | I_CALL proc_name\n\n  datatype t_instr = TI_RETURN | TI_BR label | TI_CBR \"state\\<Rightarrow>bool\" label label\n\n  datatype bblock = BBLOCK (nt_instrs: \"nt_instr list\") (t_instr: \"t_instr\")\n\n\n  type_synonym proc_body = \"label \\<rightharpoonup> bblock\"\n  type_synonym prog = \"proc_name \\<rightharpoonup> proc_body\"\n\n\n  context\n    fixes \\<pi> :: prog\n  begin\n\n    context\n      fixes execute :: \"proc_body \\<times> label \\<Rightarrow> (unit,unit,state,err) M\"\n    begin\n\n      definition \"exec_nt_instr ins \\<equiv> case ins of\n        I_BASIC f \\<Rightarrow> doM { s\\<leftarrow>get; set (f s)}\n      | I_CALL p \\<Rightarrow> doM {\n          \\<beta> \\<leftarrow> lookup STATIC_ERROR \\<pi> p;\n          handle (doM {execute (\\<beta>,''__start''); fail STATIC_ERROR}) (\\<lambda>_. return ());\n          return ()\n        }\"\n\n      fun exec_t_instr where\n        \"exec_t_instr (TI_RETURN) = doM {\n          raise ()\n        }\"\n      | \"exec_t_instr (TI_BR l) = return l\"\n      | \"exec_t_instr (TI_CBR c l1 l2) = doM {\n          s\\<leftarrow>get;\n          if c s then return l1 else return l2\n      }\"\n\n      definition \"execute_body \\<equiv> \\<lambda>(\\<beta>,l). doM {\n        bb \\<leftarrow> lookup STATIC_ERROR \\<beta> l;\n        mfold' exec_nt_instr (nt_instrs bb);\n        l \\<leftarrow> exec_t_instr (t_instr bb);\n        execute (\\<beta>,l)\n      }\"\n    end\n\n    definition \"execute \\<equiv> REC execute_body\"\n\n    lemma mono_mfold[partial_function_mono]:\n      \"\\<lbrakk>\\<And>x s. M.mono_body (\\<lambda>f. F f x s)\\<rbrakk> \\<Longrightarrow> M.mono_body (\\<lambda>f. mfold (F f) xs s)\"\n      apply (induction xs arbitrary: s)\n      apply simp_all\n      apply pf_mono_prover\n      apply pf_mono_prover\n      apply simp_all\n      done\n\n    lemma mono_exec_ntinstr[partial_function_mono]: \"M.mono_body (\\<lambda>f. local.exec_nt_instr f ins)\"\n      by (cases ins; simp add: exec_nt_instr_def; pf_mono_prover)\n\n    lemma mono_execute_body[partial_function_mono]: \"\\<And>x. M.mono_body (\\<lambda>fa. local.execute_body fa x)\"\n      unfolding execute_body_def\n      by pf_mono_prover\n\n  end\n\n  lemmas\n        execute_unfold[code] = REC_unfold[OF execute_def, discharge_monos]\n    and execute_partial = lrmwpe_REC_partial[OF execute_def, discharge_monos, consumes 1, case_names nonterm step]\n    and execute_total = lrmwpe_REC_total[OF execute_def, discharge_monos, consumes 1, case_names wf step]\n    and execute_sim[sim_rules] = sim_REC[OF execute_def execute_def, discharge_monos]\n\n  term execute\n\n  thm sim_rules\n\n  lemma execute_sm_sim[sim_rules]:\n    assumes \"\\<pi> \\<subseteq>\\<^sub>m \\<pi>'\"\n    shows \"sim (execute \\<pi> \\<beta>l) (execute \\<pi>' \\<beta>l)\"\n    using assms\n    by (auto intro!: sim_rules split!: nt_instr.split simp: execute_body_def exec_nt_instr_def)\n\n\n  fun wf_nt_instr where\n    \"wf_nt_instr \\<pi> (I_BASIC f) \\<longleftrightarrow> True\"\n  | \"wf_nt_instr \\<pi> (I_CALL p) \\<longleftrightarrow> p\\<in>dom \\<pi>\"\n\n  fun wf_t_instr where\n    \"wf_t_instr \\<pi> \\<beta> (TI_RETURN) \\<longleftrightarrow> True\"\n  | \"wf_t_instr \\<pi> \\<beta> (TI_BR l) \\<longleftrightarrow> l\\<in>dom \\<beta>\"\n  | \"wf_t_instr \\<pi> \\<beta> (TI_CBR c l1 l2) \\<longleftrightarrow> l1\\<in>dom \\<beta> \\<and> l2\\<in>dom \\<beta>\"\n\n  fun wf_basic_block where\n    \"wf_basic_block \\<pi> \\<beta> (BBLOCK ntis ti) \\<longleftrightarrow> (\\<forall>nti\\<in>List.set ntis. wf_nt_instr \\<pi> nti) \\<and> wf_t_instr \\<pi> \\<beta> ti\"\n\n  definition \"wf_proc_body \\<pi> b \\<equiv> ''__start''\\<in>dom b \\<and> (\\<forall>bb\\<in>ran b. wf_basic_block \\<pi> b bb)\"\n\n  definition \"wf_prog \\<pi> \\<equiv> \\<forall>b\\<in>ran \\<pi>. wf_proc_body \\<pi> b\"\n\n  definition \"wf_pos \\<pi> \\<equiv> \\<lambda>(\\<beta>,l). \\<beta> \\<in> ran \\<pi> \\<and> l\\<in>dom \\<beta>\"\n\n\n\n\n  lemma\n    assumes \"run (execute \\<pi> \\<beta>l) s = r\"\n    assumes \"wf_pos \\<pi> \\<beta>l\"\n    assumes \"wf_prog \\<pi>\"\n    shows \"mwp r True bot top bot\"\n    using assms(1,2)\n  proof (induction rule: execute_partial)\n    case (nonterm x s)\n    then show ?case by simp\n  next\n    case (step f x s r)\n\n    note step.IH[OF refl, THEN mwp_cons, intro!]\n\n    obtain \\<beta> l where [simp]: \"x = (\\<beta>,l)\" by (cases x)\n    with \\<open>wf_pos \\<pi> x\\<close> obtain ntis ti where [simp]: \"\\<beta> l = Some (BBLOCK ntis ti)\" and \"\\<beta>\\<in>ran \\<pi>\"\n      apply (auto simp: wf_pos_def)\n      using bblock.exhaust by blast\n\n    have [THEN mwp_cons, intro!]:\n      \"mwp (run (exec_nt_instr \\<pi> f i) s) top bot bot top\" if \"wf_nt_instr \\<pi> i\" for i s\n      using that\n      apply (auto simp: run_simps exec_nt_instr_def split: nt_instr.splits option.split)\n      by (metis (mono_tags, lifting) assms(3) old.prod.case ranI wf_pos_def wf_proc_body_def wf_prog_def)\n\n\n    from \\<open>wf_prog \\<pi>\\<close> \\<open>\\<beta>\\<in>ran \\<pi>\\<close> have \"wf_basic_block \\<pi> \\<beta> (BBLOCK ntis ti)\"\n      unfolding wf_prog_def wf_proc_body_def apply (auto)\n      apply (meson \\<open>\\<beta> l = Some (BBLOCK ntis ti)\\<close> ranI wf_basic_block.simps)\n      apply (meson \\<open>\\<beta> l = Some (BBLOCK ntis ti)\\<close> ranI wf_basic_block.simps)\n      done\n    hence WF_NTI: \"(\\<forall>nti\\<in>List.set ntis. wf_nt_instr \\<pi> nti)\"\n      and WF_TI: \"wf_t_instr \\<pi> \\<beta> ti\" by simp_all\n\n    from WF_NTI have [THEN mwp_cons, intro!]:\n      \"mwp (run (mfold' (exec_nt_instr \\<pi> f) ntis) s) top bot bot top\"\n      apply (induction ntis arbitrary: s)\n      by (auto simp: run_simps)\n\n    from WF_TI have [THEN mwp_cons, intro!]: \"mwp (run (exec_t_instr ti) s) top bot top (\\<lambda>l _. l\\<in>dom \\<beta>)\" for s\n      apply (cases ti)\n      apply (auto simp: run_simps)\n      done\n\n    from step.hyps step.prems show ?case\n      by (auto simp: execute_body_def run_simps wf_pos_def split: prod.splits option.splits)\n\n  qed\n\n\nend\n\n\n", "meta": {"author": "lammich", "repo": "isabelle_llvm", "sha": "6be37a9c3cae74a1134dbef2979e312abb5f7f42", "save_path": "github-repos/isabelle/lammich-isabelle_llvm", "path": "github-repos/isabelle/lammich-isabelle_llvm/isabelle_llvm-6be37a9c3cae74a1134dbef2979e312abb5f7f42/thys-2018/others/simple/Ex_CFG.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.29111574776707544}}
{"text": "section \\<open>Random Permutation Cache\\<close>\n\ntheory CM_RpSpec\n  imports Main CM_SecurityModel\nbegin\n\nsubsection \\<open>Data type, Basic components\\<close>\n\n(*Basic data structures*)\ntype_synonym tagmask = nat\ntype_synonym setbits = nat\ntype_synonym setindex = nat\ntype_synonym wayindex = nat\n\ndatatype cachehit = Hit | Miss\n\ndatatype secure = H | L\n\ndatatype event = RP_READ\n\n(*Memory blocks*)\nrecord memory_request =\n  tag :: tagmask\n  index :: setbits\n  protect :: bool\n  thread :: secure\n\n(*Cache structure*)\nrecord cache_line =\n  ca_tag :: tagmask\n  ca_set :: setindex\n  ca_way :: wayindex\n  valid :: bool\n  lock :: bool\n  owned :: \"secure option\"\n\ntype_synonym cache = \"(cache_line set) list\"\n\ntype_synonym mapping = \"setbits \\<rightharpoonup> setindex\"\n\n(*State Machine*)\nrecord state =\n  sram :: cache\n  map_H :: mapping\n  map_L :: mapping\n\nsubsection \\<open>Random permutation cache model specifications\\<close>\n\ndefinition replace_policy :: \"cache_line set \\<Rightarrow> cache_line\"\n  where \"replace_policy cs \\<equiv> SOME l. l \\<in> cs\"\n\ndefinition probe_line :: \"cache_line set \\<Rightarrow> memory_request \\<Rightarrow> bool\"\n  where \"probe_line cs mr \\<equiv> \\<exists>b. b \\<in> cs \\<and> ca_tag b = tag mr \\<and> valid b \\<and> owned b = Some (thread mr)\"\n\ndefinition replace_line :: \"cache_line \\<Rightarrow> memory_request \\<Rightarrow> cache_line\"\n  where \"replace_line cl mr \\<equiv> cl\\<lparr>ca_tag := tag mr, valid := True, lock := protect mr, owned := Some (thread mr)\\<rparr>\"\n\ndefinition drop_line :: \"cache_line \\<Rightarrow> cache_line\"\n  where \"drop_line cl \\<equiv> cl\\<lparr>valid := False, lock := False, owned := None\\<rparr>\"\n\ndefinition fix_line :: \"cache_line set \\<Rightarrow> memory_request \\<Rightarrow> cache_line set\"\n  where \"fix_line cs mr \\<equiv> {t. \\<exists>r \\<in> cs. t = (if owned r = Some (thread mr) then r\\<lparr>valid := False, lock := False, owned := None\\<rparr> else r)}\"\n\ndefinition swap_map :: \"mapping \\<Rightarrow> setindex \\<Rightarrow> setindex \\<Rightarrow> mapping\"\n  where \"swap_map pt ra rb \\<equiv> let sa = {t. pt t = Some ra}; sb = {t. pt t = Some rb} in\n                             (\\<lambda>t. if t \\<in> sa then Some rb else if t \\<in> sb then Some ra else pt t)\"\n\ndefinition rp_read :: \"state \\<Rightarrow> memory_request \\<Rightarrow> state set\" where\n  \"rp_read s mr \\<equiv>\n      let map = (if thread mr = H then map_H s else map_L s);\n          redir_set = the (map (index mr));\n          redir_ca = (sram s) ! redir_set in\n      if probe_line redir_ca mr then {s}\n      else let r_line = replace_policy redir_ca;\n               policy_line = {t. \\<exists>l \\<in> {0..length (sram s) - 1}. t = replace_policy ((sram s) ! l)} in\n        if owned r_line = Some (thread mr) then\n          if lock r_line = protect mr then\n            let newset = insert (replace_line r_line mr) (redir_ca - {r_line}) in\n            {s\\<lparr>sram := list_update (sram s) redir_set newset\\<rparr>}\n          else {t. \\<exists>r'_line \\<in> policy_line. let newset = insert (drop_line r'_line) (((sram s) ! (ca_set r'_line)) - {r'_line}) in\n                   t = s\\<lparr>sram := list_update (sram s) (ca_set r'_line) newset\\<rparr>}\n        else\n          if thread mr = H then\n            {t. \\<exists>r'_line \\<in> policy_line.\n              if ca_set r'_line = redir_set then\n                let newset = insert (replace_line r'_line mr) (fix_line (((sram s) ! (ca_set r'_line)) - {r'_line}) mr) in\n                    t = s\\<lparr>sram := list_update (sram s) (ca_set r'_line) newset,\n                          map_H := swap_map (map_H s) redir_set (ca_set r'_line)\\<rparr>\n              else let newset = insert (replace_line r'_line mr) (fix_line (((sram s) ! (ca_set r'_line)) - {r'_line}) mr);\n                       new_redir_ca = fix_line redir_ca mr in\n                t = s\\<lparr>sram := list_update (list_update (sram s) (ca_set r'_line) newset) redir_set new_redir_ca,\n                      map_H := swap_map (map_H s) redir_set (ca_set r'_line)\\<rparr>}\n          else {t. \\<exists>r'_line \\<in> policy_line.\n                 if ca_set r'_line = redir_set then\n                   let newset = insert (replace_line r'_line mr) (fix_line (((sram s) ! (ca_set r'_line)) - {r'_line}) mr) in\n                       t = s\\<lparr>sram := list_update (sram s) (ca_set r'_line) newset,\n                             map_L := swap_map (map_L s) redir_set (ca_set r'_line)\\<rparr>\n                 else let newset = insert (replace_line r'_line mr) (fix_line (((sram s) ! (ca_set r'_line)) - {r'_line}) mr);\n                          new_redir_ca = fix_line redir_ca mr in\n                   t = s\\<lparr>sram := list_update (list_update (sram s) (ca_set r'_line) newset) redir_set new_redir_ca,\n                         map_L := swap_map (map_L s) redir_set (ca_set r'_line)\\<rparr>}\"\n\n\nsubsection \\<open>Instantiation\\<close>\n\nrecord cache_NE =\n  ca_N :: \"cache set\"\n  ca_E :: \"cache set\"\n\nconsts cache_comp :: cache_NE\n\ndefinition cache_comp_witness :: \"cache_NE\"\n  where \"cache_comp_witness \\<equiv> \\<lparr>ca_N = {[{(\\<lparr>ca_tag = 0, ca_set = 0, ca_way = 0, valid = True, lock = False, owned = Some L\\<rparr>)}]},\n                               ca_E = {[{(\\<lparr>ca_tag = 0, ca_set = 0, ca_way = 0, valid = True, lock = False, owned = Some L\\<rparr>)}]}\\<rparr>\"\n\nspecification (cache_comp)\n  caN_finite: \"finite (ca_N cache_comp)\"\n  caN_nonempty: \"(ca_N cache_comp) \\<noteq> {}\"\n\n  ca_length: \"\\<forall>c \\<in> (ca_N cache_comp). length c > 0\"\n  ca_length2: \"\\<forall>c1 c2. c1 \\<in> (ca_N cache_comp) \\<and> c2 \\<in> (ca_N cache_comp) \\<and> c1 \\<noteq> c2 \\<longrightarrow> length c1 = length c2\"\n  ca_finite: \"\\<forall>c \\<in> (ca_N cache_comp). finite (set c)\"\n  ca_set_nonempty: \"\\<forall>c \\<in> (ca_N cache_comp). (\\<forall>l < length c. c!l \\<noteq> {})\"\n  ca_set_finite: \"\\<forall>c \\<in> (ca_N cache_comp). (\\<forall>l < length c. finite (c!l))\"\n  ca_set_num: \"\\<forall>c \\<in> (ca_N cache_comp). (\\<forall>l < length c. \\<forall>e \\<in> (c!l). ca_set e = l)\"\n  ca_way_num: \"\\<forall>c \\<in> (ca_N cache_comp). (\\<forall>l1 l2. l1 < length c \\<and> l2 < length c \\<and> l1 \\<noteq> l2 \\<longrightarrow> card(c!l1) = card(c!l2))\"\n  ca_way_num2: \"\\<forall>c \\<in> (ca_N cache_comp). (\\<forall>l < length c. \\<forall>e1 e2. e1 \\<in> (c!l) \\<and> e2 \\<in> (c!l) \\<and> e1 \\<noteq> e2 \\<longrightarrow> ca_way e1 \\<noteq> ca_way e2)\"\n\n  caE_init: \"(ca_E cache_comp) \\<subseteq> (ca_N cache_comp)\"\n  caE_nonempty: \"(ca_E cache_comp) \\<noteq> {}\"\n  caE_occupy: \"\\<forall>c \\<in> (ca_E cache_comp). (\\<forall>l < length c. \\<forall>e \\<in> (c!l). owned e = Some L)\"\n  apply(intro exI[of _ cache_comp_witness])\n  unfolding cache_comp_witness_def by auto\n\nrecord mem_map =\n  map_conf :: \"mapping\"\n  mem_req :: \"(memory_request \\<times> real) set\"\n\nconsts mm_comp :: mem_map\n\ndefinition mm_comp_witness :: \"mem_map\"\n  where \"mm_comp_witness \\<equiv> \\<lparr>map_conf = (\\<lambda>t. if t = 0 then Some 0 else None),\n                            mem_req = {(\\<lparr>tag = 0, index = 0, protect = False, thread = H\\<rparr>, 1)}\\<rparr>\"\n\nspecification (mm_comp)\n  map_range: \"\\<forall>c \\<in> (ca_N cache_comp). (\\<forall>i. (map_conf mm_comp) i \\<noteq> None \\<longrightarrow> the ((map_conf mm_comp) i) < length c)\"\n  map_diff: \"\\<forall>i j. i \\<noteq> j \\<and> (map_conf mm_comp) i \\<noteq> None \\<and> (map_conf mm_comp) j \\<noteq> None \\<longrightarrow> the ((map_conf mm_comp) i) \\<noteq> the ((map_conf mm_comp) j)\"\n  mem_finite: \"finite (mem_req mm_comp)\"\n  mem_nonempty: \"card (mem_req mm_comp) > 0\"\n  mem_unique: \"\\<forall>i j. i \\<in> (mem_req mm_comp) \\<and> j \\<in> (mem_req mm_comp) \\<and> i \\<noteq> j \\<longrightarrow> index (fst i) \\<noteq> index (fst j)\"\n  mem_positive: \"\\<forall>i \\<in> (mem_req mm_comp). snd i > 0\"\n  mem_sum_one: \"folds (\\<lambda>t p. snd t + p) 0 (mem_req mm_comp) = 1\"\n  mem_occupy: \"\\<forall>i \\<in> (mem_req mm_comp). thread (fst i) = H\"\n  mem_mapping: \"\\<forall>i \\<in> (mem_req mm_comp). (map_conf mm_comp) (index (fst i)) \\<noteq> None\"\n  apply(intro exI[of _ \"mm_comp_witness\"])\n  unfolding mm_comp_witness_def apply auto\n  using ca_length by auto\n\n(*state N*)\nconsts state_N :: \"state set\"\n\ndefinition state_N_witness :: \"state set\"\n  where \"state_N_witness \\<equiv> {t. \\<exists>c \\<in> (ca_N cache_comp). t = \\<lparr>sram = c, map_H = (map_conf mm_comp), map_L = (map_conf mm_comp)\\<rparr>}\"\n\nspecification (state_N)\n  state_N_init: \"state_N = state_N_witness\"\n  by simp\n\nlemma stateN_finite: \"finite state_N\"\n  proof -\n    {\n      have \"\\<forall>c \\<in> (ca_N cache_comp). finite {t. \\<exists>c \\<in> (ca_N cache_comp). t = \\<lparr>sram = c, map_H = (map_conf mm_comp), map_L = (map_conf mm_comp)\\<rparr>}\"\n        using caN_finite by auto\n      then show ?thesis\n        using state_N_init state_N_witness_def by auto \n    }\n  qed\n\nlemma stateN_nonempty: \"state_N \\<noteq> {}\"\n  using state_N_init state_N_witness_def caN_nonempty\n  by blast\n\n(*state E*)\nconsts state_E :: \"state set\"\n\ndefinition state_E_witness :: \"state set\"\n  where \"state_E_witness \\<equiv> {t. \\<exists>c \\<in> (ca_E cache_comp). t = \\<lparr>sram = c, map_H = (map_conf mm_comp), map_L = (map_conf mm_comp)\\<rparr>}\"\n\nspecification (state_E)\n  state_E_init: \"state_E = state_E_witness\"\n  by simp\n\nlemma stateE_nonempty: \"state_E \\<noteq> {}\"\n  using state_E_init state_E_witness_def caE_nonempty\n  by blast\n\nlemma stateE_subset: \"state_E \\<subseteq> state_N\"\n  using state_N_init state_N_witness_def state_E_init state_E_witness_def\n  by (smt Collect_mono_iff caE_init subset_eq)\n  \nlemma cache_set_size:\n  \"\\<forall>s \\<in> state_N. card {0..length (sram s) - 1} = length (sram s)\"\n  proof -\n    {\n      fix s\n      assume \"s \\<in> state_N\"\n      have \"card {0..length (sram s) - 1} = length (sram s)\"\n      proof -\n        {\n          have \"sram s \\<in> ca_N cache_comp\"\n            using state_N_init unfolding state_N_witness_def\n            proof -\n              assume \"state_N = {t. \\<exists>c\\<in>ca_N cache_comp. t = \\<lparr>sram = c, map_H = map_conf mm_comp, map_L = map_conf mm_comp\\<rparr>}\"\n              then have \"state_N = {s. \\<exists>Cs. Cs \\<in> ca_N cache_comp \\<and> s = \\<lparr>sram = Cs, map_H = map_conf mm_comp, map_L = map_conf mm_comp\\<rparr>}\"\n                by meson\n              then have \"\\<exists>Cs. Cs \\<in> ca_N cache_comp \\<and> s = \\<lparr>sram = Cs, map_H = map_conf mm_comp, map_L = map_conf mm_comp\\<rparr>\"\n                using \\<open>s \\<in> state_N\\<close> by blast\n              then show ?thesis\n                by force\n            qed\n          then show ?thesis\n            using ca_length by simp\n        }\n      qed\n    }\n    then show ?thesis by auto\n  qed\n  \nlemma cache_set_size2:\n  assumes a_finite: \"finite (w::((nat \\<times> cachehit) \\<times> real) set)\"\n      and a_nonempty: \"w \\<noteq> {}\"\n      and a0: \"\\<forall>d \\<in> w. P d = (i::real)\"\n    shows \"folds (\\<lambda>s p. P s + p) 0 w = i * card w\"\n  proof -\n    show ?thesis using a_finite a_nonempty a0\n    proof(induct arbitrary: i rule: finite_ne_induct)\n      case (singleton x)\n      then have \"P x = i\"\n        by auto\n      moreover have \"folds (\\<lambda>s p. P s + p) 0 {x} = P x\"\n        by force\n      ultimately show ?case by auto\n    next\n      case (insert x F)\n      have p0: \"folds (\\<lambda>s p. P s + p) 0 (insert x F) = P x + folds (\\<lambda>s p. P s + p) 0 F\"\n        using plus_comp_fun_commute_P.fold_insert\n        by (simp add: insert.hyps(1) insert.hyps(3)) \n      have p1: \"folds (\\<lambda>s p. P s + p) 0 F = i * card F\"\n        using insert.hyps(4) insert.prems by blast\n      have p2: \"P x + folds (\\<lambda>s p. P s + p) 0 F = i * Suc (card F)\"\n        by (simp add: insert.prems p1 ring_class.ring_distribs(1))\n      then show ?case using p0\n        by (simp add: insert.hyps(1) insert.hyps(3)) \n    qed\n  qed\n\nlemma policy_line_length:\n  assumes a0: \"finite A\"\n      and a1: \"A \\<noteq> {}\"\n      and a2: \"\\<forall>a1 a2. a1 \\<in> A \\<and> a2 \\<in> A \\<and> a1 \\<noteq> a2 \\<longrightarrow> f a1 \\<noteq> f a2\"\n    shows \"card {t. \\<exists>a \\<in> A. t = f a} = card A\"\n  proof -\n    show ?thesis using a0 a1 a2\n    proof(induct rule: finite_ne_induct)\n      case (singleton x)\n      then show ?case by auto\n    next\n      case (insert x F)\n      have insert_length: \"card (insert x F) = card F + 1\"\n        by (simp add: insert.hyps(1) insert.hyps(3))\n      have \"{t. \\<exists>a \\<in> (insert x F). t = f a} = {t. \\<exists>a \\<in> {x}. t = f a} \\<union> {t. \\<exists>a \\<in> F. t = f a}\"\n        by auto\n      moreover have \"f x \\<notin> {t. \\<exists>a \\<in> F. t = f a}\"\n        using insert.hyps(3) insert.prems by blast\n      ultimately have \"card {t. \\<exists>a \\<in> (insert x F). t = f a} = card {t. \\<exists>a \\<in> F. t = f a} + 1\"\n        using insert.hyps(1) by auto\n      then show ?case\n        using insert_length by (simp add: insert.hyps(4) insert.prems) \n    qed\n  qed\n\n(*Observation*)\ndefinition rp_read_observe :: \"state \\<Rightarrow> memory_request \\<Rightarrow> ((setindex \\<times> cachehit) \\<times> real) set\" where\n  \"rp_read_observe s mr \\<equiv>\n      let maps = map_H s;\n          redir_set = the (maps (index mr));\n          redir_ca = (sram s) ! redir_set in\n      if probe_line redir_ca mr then {((redir_set, Hit), 1)}\n      else let r_line = replace_policy redir_ca;\n               policy_line = {t. \\<exists>l \\<in> {0..length (sram s) - 1}. t = replace_policy ((sram s) ! l)} in\n        if owned r_line = Some (thread mr) then\n          if lock r_line = protect mr then {((redir_set, Miss), 1)}\n          else {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/card policy_line)}\n        else\n          {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/card policy_line)}\"\n\nlemma mem_cache_miss:\n  \"\\<forall>i \\<in> mem_req mm_comp. \\<forall>s0 \\<in> state_E. rp_read_observe s0 (fst i) = {t. \\<exists>r \\<in> {0..length (sram s0) - 1}. t = ((r, Miss), 1/length (sram s0))}\"\n  proof -\n    {\n      fix i\n      assume t0: \"i \\<in> mem_req mm_comp\"\n      have \"\\<forall>s0 \\<in> state_E. rp_read_observe s0 (fst i) = {t. \\<exists>r \\<in> {0..length (sram s0) - 1}. t = ((r, Miss), 1/length (sram s0))}\"\n      proof -\n        {\n          fix s0\n          assume t00: \"s0 \\<in> state_E\"\n          have \"rp_read_observe s0 (fst i) = {t. \\<exists>r \\<in> {0..length (sram s0) - 1}. t = ((r, Miss), 1/length (sram s0))}\"\n          proof -\n            {\n              have iowned: \"thread (fst i) = H\"\n                by (simp add: mem_occupy t0)\n              let ?maps = \"map_H s0\"\n              let ?redir_set = \"the (?maps (index (fst i)))\"\n              have exi_redir: \"?redir_set < length (sram s0)\"\n                using state_E_init unfolding state_E_witness_def using mem_mapping\n                by (smt caE_init map_range mem_Collect_eq state.select_convs(1) state.select_convs(2) subsetD t0 t00)\n              let ?redir_ca = \"(sram s0) ! ?redir_set\"\n              have t000: \"sram s0 \\<in> ca_E cache_comp\"\n                using state_E_init unfolding state_E_witness_def\n                proof -\n                  assume \"state_E = {t. \\<exists>c\\<in>ca_E cache_comp. t = \\<lparr>sram = c, map_H = map_conf mm_comp, map_L = map_conf mm_comp\\<rparr>}\"\n                  then have \"state_E = {s. \\<exists>Cs. Cs \\<in> ca_E cache_comp \\<and> s = \\<lparr>sram = Cs, map_H = map_conf mm_comp, map_L = map_conf mm_comp\\<rparr>}\"\n                    by meson\n                  then have \"\\<exists>Cs. Cs \\<in> ca_E cache_comp \\<and> s0 = \\<lparr>sram = Cs, map_H = map_conf mm_comp, map_L = map_conf mm_comp\\<rparr>\"\n                    using t00 by blast\n                  then show ?thesis\n                    by fastforce\n                qed\n              then have setowned: \"\\<forall>l < length (sram s0). \\<forall>e \\<in> ((sram s0)!l). owned e = Some L\"\n                using caE_occupy by blast\n              then have \"\\<nexists>b. b \\<in> ?redir_ca \\<and> ca_tag b = tag (fst i) \\<and> valid b \\<and> owned b = Some (thread (fst i))\"\n                using iowned exi_redir by auto\n              then have c1: \"\\<not> probe_line ?redir_ca (fst i)\"\n                unfolding probe_line_def by blast\n              let ?r_line = \"replace_policy ?redir_ca\"\n              have \"?r_line \\<in> ?redir_ca\"\n                unfolding replace_policy_def\n                using caE_init ca_set_nonempty some_in_eq t000 exi_redir by blast\n              then have \"owned ?r_line = Some L\"\n                using setowned exi_redir by blast\n              then have c2: \"owned ?r_line \\<noteq> Some (thread (fst i))\"\n                using iowned by auto\n              let ?policy_line = \"{t. \\<exists>l \\<in> {0..length (sram s0) - 1}. t = replace_policy ((sram s0) ! l)}\"\n              have out: \"rp_read_observe s0 (fst i) = {t. \\<exists>r'_line \\<in> ?policy_line. t = ((ca_set r'_line, Miss), 1/card ?policy_line)}\"\n                unfolding rp_read_observe_def Let_def\n                using c1 c2 by (simp add: iowned)\n              have length_finite: \"finite {0..length (sram s0) - 1}\"\n                by blast\n              have length_nonempty: \"{0..length (sram s0) - 1} \\<noteq> {}\"\n                using atLeastatMost_empty_iff by blast\n              have caset_line: \"\\<forall>l \\<in> {0..length (sram s0) - 1}. ca_set (replace_policy ((sram s0) ! l)) = l\"\n                unfolding replace_policy_def\n                proof -\n                  { \n                    fix nn :: nat\n                    have \"sram s0 \\<in> ca_N cache_comp\"\n                      using caE_init t000 by blast\n                    then have \"nn \\<notin> {0..length (sram s0) - 1} \\<or> ca_set (SOME c. c \\<in> sram s0 ! nn) = nn\"\n                      by (metis (no_types) Suc_pred' atLeastAtMost_iff atLeastatMost_empty_iff2 ca_length ca_set_nonempty ca_set_num card_0_eq card_atLeastAtMost finite_atLeastAtMost neq0_conv some_in_eq zero_less_diff) \n                  }\n                  then show \"\\<forall>n\\<in>{0..length (sram s0) - 1}. ca_set (SOME c. c \\<in> sram s0 ! n) = n\"\n                    by blast\n                qed\n              then have line_diff: \"\\<forall>l1 l2. l1 \\<in> {0..length (sram s0) - 1} \\<and> l2 \\<in> {0..length (sram s0) - 1} \\<and> l1 \\<noteq> l2 \\<longrightarrow>\n                                    (replace_policy ((sram s0) ! l1)) \\<noteq> (replace_policy ((sram s0) ! l2))\"\n                proof -\n                  show ?thesis\n                    by (metis (no_types) caset_line)\n                qed\n              have policy_length: \"card ?policy_line = card {0..length (sram s0) - 1}\"\n                using length_finite length_nonempty line_diff\n                by (simp add: policy_line_length)\n              then have policy_length2: \"card ?policy_line = length (sram s0)\"\n                using cache_set_size t00 stateE_subset by auto\n              then have out1: \"{t. \\<exists>r'_line \\<in> ?policy_line. t = ((ca_set r'_line, Miss), 1/card ?policy_line)} =\n                               {t. \\<exists>r'_line \\<in> ?policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s0))}\"  \n                by auto\n              have s1: \"\\<forall>e \\<in> {t. \\<exists>r'_line \\<in> ?policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s0))}.\n                         e \\<in> {t. \\<exists>r \\<in> {0..length (sram s0) - 1}. t = ((r, Miss), 1/length (sram s0))}\"\n                proof -\n                  {\n                    fix e\n                    assume e0: \"e \\<in> {t. \\<exists>r'_line \\<in> ?policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s0))}\"\n                    have \"fst (fst e) \\<in> {0..length (sram s0) - 1}\"\n                      using e0 caset_line by auto\n                    then have \"\\<exists>d \\<in> {t. \\<exists>r \\<in> {0..length (sram s0) - 1}. t = ((r, Miss), 1/length (sram s0))}. d = e\"\n                      using e0 by auto\n                    then have \"e \\<in> {t. \\<exists>r \\<in> {0..length (sram s0) - 1}. t = ((r, Miss), 1/length (sram s0))}\"\n                      by auto\n                  }\n                  then show ?thesis by blast\n                qed\n              have s2: \"\\<forall>e \\<in> {t. \\<exists>r \\<in> {0..length (sram s0) - 1}. t = ((r, Miss), 1/length (sram s0))}.\n                         e \\<in> {t. \\<exists>r'_line \\<in> ?policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s0))}\"\n                proof -\n                  {\n                    fix e\n                    assume e1: \"e \\<in> {t. \\<exists>r \\<in> {0..length (sram s0) - 1}. t = ((r, Miss), 1/length (sram s0))}\"\n                    have \"fst (fst e) \\<in> {0..length (sram s0) - 1}\"\n                      using e1 by auto\n                    moreover have \"\\<forall>d \\<in> {t. \\<exists>r'_line \\<in> ?policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s0))}. fst (fst d) \\<in> {0..length (sram s0) - 1}\"\n                      using caset_line by auto\n                    ultimately have \"\\<exists>d \\<in> {t. \\<exists>r'_line \\<in> ?policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s0))}. d = e\"\n                      by (smt caset_line e1 mem_Collect_eq)\n                    then have \"e \\<in> {t. \\<exists>r'_line \\<in> ?policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s0))}\"\n                      by auto\n                  }\n                  then show ?thesis by blast\n                qed\n              have out_equal: \"{t. \\<exists>r'_line \\<in> ?policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s0))} =\n                               {t. \\<exists>r \\<in> {0..length (sram s0) - 1}. t = ((r, Miss), 1/length (sram s0))}\"\n                using s1 s2 by blast \n              show ?thesis\n                using out out_equal policy_length2 by presburger\n            }\n          qed\n        }\n        then show ?thesis by blast\n      qed\n    }\n    then show ?thesis by blast\n  qed\n\n(*pmf instantiate*)\ndefinition execution :: \"memory_request \\<Rightarrow> state \\<Rightarrow> event \\<Rightarrow> ((setindex \\<times> cachehit) \\<times> real) set\"\n  where \"execution mr s e \\<equiv> rp_read_observe s mr\"\n\nlemma read_finite:\n  \"\\<forall>e. \\<forall>mr \\<in> mem_req mm_comp. \\<forall>s \\<in> state_N. finite (execution (fst mr) s e)\"\n  unfolding execution_def rp_read_observe_def Let_def\n  by simp\n\nlemma read_nonempty_h1:\n  assumes t0: \"s \\<in> state_N\"\n      and t1: \"mr \\<in> mem_req mm_comp\"\n      and a0: \"maps = map_H s\"\n      and a1: \"redir_set = the (maps (index (fst mr)))\"\n      and a2: \"redir_ca = (sram s) ! redir_set\"\n      and a3: \"probe_line redir_ca (fst mr)\"\n    shows \"execution (fst mr) s e \\<noteq> {}\"\n  unfolding execution_def rp_read_observe_def Let_def\n  using t0 a0 a1 a2 a3 by auto\n\nlemma read_nonempty_h2:\n  assumes t0: \"s \\<in> state_N\"\n      and t1: \"mr \\<in> mem_req mm_comp\"\n      and a0: \"maps = map_H s\"\n      and a1: \"redir_set = the (maps (index (fst mr)))\"\n      and a2: \"redir_ca = (sram s) ! redir_set\"\n      and a3: \"\\<not> (probe_line redir_ca (fst mr))\"\n      and a4: \"r_line = replace_policy redir_ca\"\n      and a5: \"owned r_line = Some (thread (fst mr))\"\n      and a6: \"lock r_line = protect (fst mr)\"\n    shows \"execution (fst mr) s e \\<noteq> {}\"\n  unfolding execution_def rp_read_observe_def Let_def\n    using t0 a0 a1 a2 a3 a4 a5 a6 by auto\n\nlemma read_nonempty_h3:\n  assumes t0: \"s \\<in> state_N\"\n      and t1: \"mr \\<in> mem_req mm_comp\"\n      and a0: \"maps = map_H s\"\n      and a1: \"redir_set = the (maps (index (fst mr)))\"\n      and a2: \"redir_ca = (sram s) ! redir_set\"\n      and a3: \"\\<not> (probe_line redir_ca (fst mr))\"\n      and a4: \"r_line = replace_policy redir_ca\"\n      and a5: \"policy_line = {t. \\<exists>l \\<in> {0..length (sram s) - 1}. t = replace_policy ((sram s) ! l)}\"\n      and a6: \"owned r_line = Some (thread (fst mr))\"\n      and a7: \"lock r_line \\<noteq> protect (fst mr)\"\n    shows \"execution (fst mr) s e \\<noteq> {}\"\n  proof -\n    {\n      have exi_redir: \"redir_set < length (sram s)\"\n        using state_N_init unfolding state_N_witness_def using mem_mapping\n        by (smt a0 a1 map_range mem_Collect_eq state.select_convs(1) state.select_convs(2) t0 t1)\n      have out: \"execution (fst mr) s e = {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/card policy_line)}\"\n        unfolding execution_def rp_read_observe_def Let_def\n        using t0 t1 a0 a1 a2 a3 a4 a5 a6 a7 by auto\n      have length_finite: \"finite {0..length (sram s) - 1}\"\n        by blast\n      have length_nonempty: \"{0..length (sram s) - 1} \\<noteq> {}\"\n        using atLeastatMost_empty_iff by blast\n      have caset_line: \"\\<forall>l \\<in> {0..length (sram s) - 1}. ca_set (replace_policy ((sram s) ! l)) = l\"\n        unfolding replace_policy_def\n        proof -\n          { \n            fix nn :: nat\n            have \"sram s \\<in> ca_N cache_comp\"\n              by (smt mem_Collect_eq state.select_convs(1) state_N_init state_N_witness_def t0)\n            then have \"nn \\<notin> {0..length (sram s) - 1} \\<or> ca_set (SOME c. c \\<in> sram s ! nn) = nn\"\n              by (metis (no_types) Suc_pred' atLeastAtMost_iff atLeastatMost_empty_iff2 ca_length ca_set_nonempty ca_set_num card_0_eq card_atLeastAtMost finite_atLeastAtMost neq0_conv some_in_eq zero_less_diff) \n          }\n          then show \"\\<forall>n\\<in>{0..length (sram s) - 1}. ca_set (SOME c. c \\<in> sram s ! n) = n\"\n            by blast\n        qed\n      then have line_diff: \"\\<forall>l1 l2. l1 \\<in> {0..length (sram s) - 1} \\<and> l2 \\<in> {0..length (sram s) - 1} \\<and> l1 \\<noteq> l2 \\<longrightarrow>\n                            (replace_policy ((sram s) ! l1)) \\<noteq> (replace_policy ((sram s) ! l2))\"\n        proof -\n          show ?thesis\n            by (metis (no_types) caset_line)\n        qed\n      have policy_length: \"card policy_line = card {0..length (sram s) - 1}\"\n        using length_finite length_nonempty line_diff a5\n        by (simp add: policy_line_length)\n      then have policy_length2: \"card policy_line = length (sram s)\"\n        using cache_set_size t0 by auto\n      then have out1: \"{t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/card policy_line)} =\n                       {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}\"\n        by auto\n      have s1: \"\\<forall>e \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}.\n                 e \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n        proof -\n          {\n            fix e\n            assume e0: \"e \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}\"\n            have \"fst (fst e) \\<in> {0..length (sram s) - 1}\"\n              using e0 caset_line a5 by auto\n            then have \"\\<exists>d \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}. d = e\"\n              using e0 by auto\n            then have \"e \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n              by auto\n          }\n          then show ?thesis by blast\n        qed\n      have s2: \"\\<forall>e \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}.\n                 e \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}\"\n        proof -\n          {\n            fix e\n            assume e1: \"e \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n            have \"fst (fst e) \\<in> {0..length (sram s) - 1}\"\n              using e1 by auto\n            moreover have \"\\<forall>d \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}. fst (fst d) \\<in> {0..length (sram s) - 1}\"\n              using caset_line a5 by auto\n            ultimately have \"\\<exists>d \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}. d = e\"\n              by (smt caset_line e1 a5 mem_Collect_eq)\n            then have \"e \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}\"\n              by auto\n          }\n          then show ?thesis by blast\n        qed\n      have out_equal: \"{t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))} =\n                       {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n        using s1 s2 by blast\n      then have out2: \"execution (fst mr) s e = {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n        using out out1 by auto\n      have finite_out: \"finite {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n        by auto\n      have nonempty_out: \"{t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))} \\<noteq> {}\"\n        by auto\n      have value_out: \"\\<forall>d \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}. snd d = 1/length (sram s)\"\n        by auto\n      have \"folds (\\<lambda>t p. snd t + p) 0 {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))} =\n           1/length (sram s) * card {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n        using cache_set_size2[where ?w = \"{t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\" and\n                                    ?P = \"snd\" and\n                                    ?i = \"1/length (sram s)\"]\n              finite_out nonempty_out value_out by blast\n      moreover have \"card {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))} = length (sram s)\"\n      proof -\n        {\n          have \"\\<forall>l1 l2. l1 \\<in> {0..length (sram s) - 1} \\<and> l2 \\<in> {0..length (sram s) - 1} \\<and> l1 \\<noteq> l2 \\<longrightarrow>\n                ((l1, Miss), 1/length (sram s)) \\<noteq> ((l2, Miss), 1/length (sram s))\"\n            by auto\n          then have \"card {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1 / real (length (sram s)))} =\n                     card {0..length (sram s) - 1}\"\n            using length_finite length_nonempty\n            by (simp add: policy_line_length)\n          then show ?thesis\n            using cache_set_size t0 by auto\n        }\n      qed\n      ultimately show ?thesis\n        using of_nat_0 out2 by force \n    }\n  qed\n\nlemma read_nonempty_h4:\n  assumes t0: \"s \\<in> state_N\"\n      and t1: \"mr \\<in> mem_req mm_comp\"\n      and a0: \"maps = map_H s\"\n      and a1: \"redir_set = the (maps (index (fst mr)))\"\n      and a2: \"redir_ca = (sram s) ! redir_set\"\n      and a3: \"\\<not> (probe_line redir_ca (fst mr))\"\n      and a4: \"r_line = replace_policy redir_ca\"\n      and a5: \"policy_line = {t. \\<exists>l \\<in> {0..length (sram s) - 1}. t = replace_policy ((sram s) ! l)}\"\n      and a6: \"owned r_line \\<noteq> Some (thread (fst mr))\"\n    shows \"execution (fst mr) s e \\<noteq> {}\"\n  proof -\n    {\n      have exi_redir: \"redir_set < length (sram s)\"\n        using state_N_init unfolding state_N_witness_def using mem_mapping\n        by (smt a0 a1 map_range mem_Collect_eq state.select_convs(1) state.select_convs(2) t0 t1)\n      have out: \"execution (fst mr) s e = {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/card policy_line)}\"\n        unfolding execution_def rp_read_observe_def Let_def\n        using t0 t1 a0 a1 a2 a3 a4 a5 a6 by auto\n      have length_finite: \"finite {0..length (sram s) - 1}\"\n        by blast\n      have length_nonempty: \"{0..length (sram s) - 1} \\<noteq> {}\"\n        using atLeastatMost_empty_iff by blast\n      have caset_line: \"\\<forall>l \\<in> {0..length (sram s) - 1}. ca_set (replace_policy ((sram s) ! l)) = l\"\n        unfolding replace_policy_def\n        proof -\n          { \n            fix nn :: nat\n            have \"sram s \\<in> ca_N cache_comp\"\n              by (smt mem_Collect_eq state.select_convs(1) state_N_init state_N_witness_def t0)\n            then have \"nn \\<notin> {0..length (sram s) - 1} \\<or> ca_set (SOME c. c \\<in> sram s ! nn) = nn\"\n              by (metis (no_types) Suc_pred' atLeastAtMost_iff atLeastatMost_empty_iff2 ca_length ca_set_nonempty ca_set_num card_0_eq card_atLeastAtMost finite_atLeastAtMost neq0_conv some_in_eq zero_less_diff) \n          }\n          then show \"\\<forall>n\\<in>{0..length (sram s) - 1}. ca_set (SOME c. c \\<in> sram s ! n) = n\"\n            by blast\n        qed\n      then have line_diff: \"\\<forall>l1 l2. l1 \\<in> {0..length (sram s) - 1} \\<and> l2 \\<in> {0..length (sram s) - 1} \\<and> l1 \\<noteq> l2 \\<longrightarrow>\n                            (replace_policy ((sram s) ! l1)) \\<noteq> (replace_policy ((sram s) ! l2))\"\n        proof -\n          show ?thesis\n            by (metis (no_types) caset_line)\n        qed\n      have policy_length: \"card policy_line = card {0..length (sram s) - 1}\"\n        using length_finite length_nonempty line_diff a5\n        by (simp add: policy_line_length)\n      then have policy_length2: \"card policy_line = length (sram s)\"\n        using cache_set_size t0 by auto\n      then have out1: \"{t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/card policy_line)} =\n                       {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}\"\n        by auto\n      have s1: \"\\<forall>e \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}.\n                 e \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n        proof -\n          {\n            fix e\n            assume e0: \"e \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}\"\n            have \"fst (fst e) \\<in> {0..length (sram s) - 1}\"\n              using e0 caset_line a5 by auto\n            then have \"\\<exists>d \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}. d = e\"\n              using e0 by auto\n            then have \"e \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n              by auto\n          }\n          then show ?thesis by blast\n        qed\n      have s2: \"\\<forall>e \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}.\n                 e \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}\"\n        proof -\n          {\n            fix e\n            assume e1: \"e \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n            have \"fst (fst e) \\<in> {0..length (sram s) - 1}\"\n              using e1 by auto\n            moreover have \"\\<forall>d \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}. fst (fst d) \\<in> {0..length (sram s) - 1}\"\n              using caset_line a5 by auto\n            ultimately have \"\\<exists>d \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}. d = e\"\n              by (smt caset_line e1 a5 mem_Collect_eq)\n            then have \"e \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}\"\n              by auto\n          }\n          then show ?thesis by blast\n        qed\n      have out_equal: \"{t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))} =\n                       {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n        using s1 s2 by blast\n      then have out2: \"execution (fst mr) s e = {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n        using out out1 by auto\n      have finite_out: \"finite {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n        by auto\n      have nonempty_out: \"{t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))} \\<noteq> {}\"\n        by auto\n      have value_out: \"\\<forall>d \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}. snd d = 1/length (sram s)\"\n        by auto\n      have \"folds (\\<lambda>t p. snd t + p) 0 {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))} =\n           1/length (sram s) * card {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n        using cache_set_size2[where ?w = \"{t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\" and\n                                    ?P = \"snd\" and\n                                    ?i = \"1/length (sram s)\"]\n              finite_out nonempty_out value_out by blast\n      moreover have \"card {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))} = length (sram s)\"\n      proof -\n        {\n          have \"\\<forall>l1 l2. l1 \\<in> {0..length (sram s) - 1} \\<and> l2 \\<in> {0..length (sram s) - 1} \\<and> l1 \\<noteq> l2 \\<longrightarrow>\n                ((l1, Miss), 1/length (sram s)) \\<noteq> ((l2, Miss), 1/length (sram s))\"\n            by auto\n          then have \"card {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1 / real (length (sram s)))} =\n                     card {0..length (sram s) - 1}\"\n            using length_finite length_nonempty\n            by (simp add: policy_line_length)\n          then show ?thesis\n            using cache_set_size t0 by auto\n        }\n      qed\n      ultimately show ?thesis\n        using of_nat_0 out2 by force \n    }\n  qed\n\nlemma read_nonempty:\n  \"\\<forall>e. \\<forall>mr \\<in> mem_req mm_comp. \\<forall>s \\<in> state_N. execution (fst mr) s e \\<noteq> {}\"\n  proof -\n    {\n      fix e\n      have \"\\<forall>mr \\<in> mem_req mm_comp. \\<forall>s \\<in> state_N. execution (fst mr) s e \\<noteq> {}\"\n      proof -\n        {\n          fix mr\n          assume t0: \"mr \\<in> mem_req mm_comp\"\n          have \"\\<forall>s \\<in> state_N. execution (fst mr) s e \\<noteq> {}\"\n          proof -\n            {\n              fix s\n              assume t1: \"s \\<in> state_N\"\n              have \"execution (fst mr) s e \\<noteq> {}\"\n                using read_nonempty_h1 read_nonempty_h2 read_nonempty_h3 read_nonempty_h4 t0 t1\n                by meson \n            }\n            then show ?thesis by blast\n          qed\n        }\n        then show ?thesis by blast\n      qed\n    }\n    then show ?thesis by blast\n  qed\n\nlemma read_unique:\n  \"\\<forall>e. \\<forall>mr \\<in> mem_req mm_comp. \\<forall>s \\<in> state_N. \\<forall>m n. m \\<in> (execution (fst mr) s e) \\<and> n \\<in> (execution (fst mr) s e) \\<and> m \\<noteq> n \\<longrightarrow> fst m \\<noteq> fst n\"\n  unfolding execution_def rp_read_observe_def Let_def\n  by auto\n\nlemma read_positive:\n  \"\\<forall>e. \\<forall>mr \\<in> mem_req mm_comp. \\<forall>s \\<in> state_N. \\<forall>d \\<in> (execution (fst mr) s e). snd d \\<ge> 0\"\n  unfolding execution_def rp_read_observe_def Let_def\n  by (smt mem_Collect_eq of_nat_0_le_iff singletonD snd_conv zero_le_divide_1_iff)\n\nlemma read_sum_one_h1:\n  assumes t0: \"s \\<in> state_N\"\n      and t1: \"mr \\<in> mem_req mm_comp\"\n      and a0: \"maps = map_H s\"\n      and a1: \"redir_set = the (maps (index (fst mr)))\"\n      and a2: \"redir_ca = (sram s) ! redir_set\"\n      and a3: \"probe_line redir_ca (fst mr)\"\n    shows \"folds (\\<lambda>t p. snd t + p) 0 (execution (fst mr) s e) = 1\"\n  unfolding execution_def rp_read_observe_def Let_def\n  using t0 a0 a1 a2 a3 by auto\n\nlemma read_sum_one_h2:\n  assumes t0: \"s \\<in> state_N\"\n      and t1: \"mr \\<in> mem_req mm_comp\"\n      and a0: \"maps = map_H s\"\n      and a1: \"redir_set = the (maps (index (fst mr)))\"\n      and a2: \"redir_ca = (sram s) ! redir_set\"\n      and a3: \"\\<not> (probe_line redir_ca (fst mr))\"\n      and a4: \"r_line = replace_policy redir_ca\"\n      and a5: \"owned r_line = Some (thread (fst mr))\"\n      and a6: \"lock r_line = protect (fst mr)\"\n    shows \"folds (\\<lambda>t p. snd t + p) 0 (execution (fst mr) s e) = 1\"\n  unfolding execution_def rp_read_observe_def Let_def\n    using t0 a0 a1 a2 a3 a4 a5 a6 by auto\n\nlemma read_sum_one_h3:\n  assumes t0: \"s \\<in> state_N\"\n      and t1: \"mr \\<in> mem_req mm_comp\"\n      and a0: \"maps = map_H s\"\n      and a1: \"redir_set = the (maps (index (fst mr)))\"\n      and a2: \"redir_ca = (sram s) ! redir_set\"\n      and a3: \"\\<not> (probe_line redir_ca (fst mr))\"\n      and a4: \"r_line = replace_policy redir_ca\"\n      and a5: \"policy_line = {t. \\<exists>l \\<in> {0..length (sram s) - 1}. t = replace_policy ((sram s) ! l)}\"\n      and a6: \"owned r_line = Some (thread (fst mr))\"\n      and a7: \"lock r_line \\<noteq> protect (fst mr)\"\n    shows \"folds (\\<lambda>t p. snd t + p) 0 (execution (fst mr) s e) = 1\"\n  proof -\n    {\n      have exi_redir: \"redir_set < length (sram s)\"\n        using state_N_init unfolding state_N_witness_def using mem_mapping\n        by (smt a0 a1 map_range mem_Collect_eq state.select_convs(1) state.select_convs(2) t0 t1)\n      have out: \"execution (fst mr) s e = {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/card policy_line)}\"\n        unfolding execution_def rp_read_observe_def Let_def\n        using t0 t1 a0 a1 a2 a3 a4 a5 a6 a7 by auto\n      have length_finite: \"finite {0..length (sram s) - 1}\"\n        by blast\n      have length_nonempty: \"{0..length (sram s) - 1} \\<noteq> {}\"\n        using atLeastatMost_empty_iff by blast\n      have caset_line: \"\\<forall>l \\<in> {0..length (sram s) - 1}. ca_set (replace_policy ((sram s) ! l)) = l\"\n        unfolding replace_policy_def\n        proof -\n          { \n            fix nn :: nat\n            have \"sram s \\<in> ca_N cache_comp\"\n              by (smt mem_Collect_eq state.select_convs(1) state_N_init state_N_witness_def t0)\n            then have \"nn \\<notin> {0..length (sram s) - 1} \\<or> ca_set (SOME c. c \\<in> sram s ! nn) = nn\"\n              by (metis (no_types) Suc_pred' atLeastAtMost_iff atLeastatMost_empty_iff2 ca_length ca_set_nonempty ca_set_num card_0_eq card_atLeastAtMost finite_atLeastAtMost neq0_conv some_in_eq zero_less_diff) \n          }\n          then show \"\\<forall>n\\<in>{0..length (sram s) - 1}. ca_set (SOME c. c \\<in> sram s ! n) = n\"\n            by blast\n        qed\n      then have line_diff: \"\\<forall>l1 l2. l1 \\<in> {0..length (sram s) - 1} \\<and> l2 \\<in> {0..length (sram s) - 1} \\<and> l1 \\<noteq> l2 \\<longrightarrow>\n                            (replace_policy ((sram s) ! l1)) \\<noteq> (replace_policy ((sram s) ! l2))\"\n        proof -\n          show ?thesis\n            by (metis (no_types) caset_line)\n        qed\n      have policy_length: \"card policy_line = card {0..length (sram s) - 1}\"\n        using length_finite length_nonempty line_diff a5\n        by (simp add: policy_line_length)\n      then have policy_length2: \"card policy_line = length (sram s)\"\n        using cache_set_size t0 by auto\n      then have out1: \"{t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/card policy_line)} =\n                       {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}\"\n        by auto\n      have s1: \"\\<forall>e \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}.\n                 e \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n        proof -\n          {\n            fix e\n            assume e0: \"e \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}\"\n            have \"fst (fst e) \\<in> {0..length (sram s) - 1}\"\n              using e0 caset_line a5 by auto\n            then have \"\\<exists>d \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}. d = e\"\n              using e0 by auto\n            then have \"e \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n              by auto\n          }\n          then show ?thesis by blast\n        qed\n      have s2: \"\\<forall>e \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}.\n                 e \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}\"\n        proof -\n          {\n            fix e\n            assume e1: \"e \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n            have \"fst (fst e) \\<in> {0..length (sram s) - 1}\"\n              using e1 by auto\n            moreover have \"\\<forall>d \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}. fst (fst d) \\<in> {0..length (sram s) - 1}\"\n              using caset_line a5 by auto\n            ultimately have \"\\<exists>d \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}. d = e\"\n              by (smt caset_line e1 a5 mem_Collect_eq)\n            then have \"e \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}\"\n              by auto\n          }\n          then show ?thesis by blast\n        qed\n      have out_equal: \"{t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))} =\n                       {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n        using s1 s2 by blast\n      then have out2: \"execution (fst mr) s e = {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n        using out out1 by auto\n      have finite_out: \"finite {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n        by auto\n      have nonempty_out: \"{t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))} \\<noteq> {}\"\n        by auto\n      have value_out: \"\\<forall>d \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}. snd d = 1/length (sram s)\"\n        by auto\n      have \"folds (\\<lambda>t p. snd t + p) 0 {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))} =\n           1/length (sram s) * card {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n        using cache_set_size2[where ?w = \"{t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\" and\n                                    ?P = \"snd\" and\n                                    ?i = \"1/length (sram s)\"]\n              finite_out nonempty_out value_out by blast\n      moreover have \"card {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))} = length (sram s)\"\n      proof -\n        {\n          have \"\\<forall>l1 l2. l1 \\<in> {0..length (sram s) - 1} \\<and> l2 \\<in> {0..length (sram s) - 1} \\<and> l1 \\<noteq> l2 \\<longrightarrow>\n                ((l1, Miss), 1/length (sram s)) \\<noteq> ((l2, Miss), 1/length (sram s))\"\n            by auto\n          then have \"card {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1 / real (length (sram s)))} =\n                     card {0..length (sram s) - 1}\"\n            using length_finite length_nonempty\n            by (simp add: policy_line_length)\n          then show ?thesis\n            using cache_set_size t0 by auto\n        }\n      qed\n      ultimately show ?thesis\n        using of_nat_0 out2 by force \n    }\n  qed\n\nlemma read_sum_one_h4:\n  assumes t0: \"s \\<in> state_N\"\n      and t1: \"mr \\<in> mem_req mm_comp\"\n      and a0: \"maps = map_H s\"\n      and a1: \"redir_set = the (maps (index (fst mr)))\"\n      and a2: \"redir_ca = (sram s) ! redir_set\"\n      and a3: \"\\<not> (probe_line redir_ca (fst mr))\"\n      and a4: \"r_line = replace_policy redir_ca\"\n      and a5: \"policy_line = {t. \\<exists>l \\<in> {0..length (sram s) - 1}. t = replace_policy ((sram s) ! l)}\"\n      and a6: \"owned r_line \\<noteq> Some (thread (fst mr))\"\n    shows \"folds (\\<lambda>t p. snd t + p) 0 (execution (fst mr) s e) = 1\"\n  proof -\n    {\n      have exi_redir: \"redir_set < length (sram s)\"\n        using state_N_init unfolding state_N_witness_def using mem_mapping\n        by (smt a0 a1 map_range mem_Collect_eq state.select_convs(1) state.select_convs(2) t0 t1)\n      have out: \"execution (fst mr) s e = {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/card policy_line)}\"\n        unfolding execution_def rp_read_observe_def Let_def\n        using t0 t1 a0 a1 a2 a3 a4 a5 a6 by auto\n      have length_finite: \"finite {0..length (sram s) - 1}\"\n        by blast\n      have length_nonempty: \"{0..length (sram s) - 1} \\<noteq> {}\"\n        using atLeastatMost_empty_iff by blast\n      have caset_line: \"\\<forall>l \\<in> {0..length (sram s) - 1}. ca_set (replace_policy ((sram s) ! l)) = l\"\n        unfolding replace_policy_def\n        proof -\n          { \n            fix nn :: nat\n            have \"sram s \\<in> ca_N cache_comp\"\n              by (smt mem_Collect_eq state.select_convs(1) state_N_init state_N_witness_def t0)\n            then have \"nn \\<notin> {0..length (sram s) - 1} \\<or> ca_set (SOME c. c \\<in> sram s ! nn) = nn\"\n              by (metis (no_types) Suc_pred' atLeastAtMost_iff atLeastatMost_empty_iff2 ca_length ca_set_nonempty ca_set_num card_0_eq card_atLeastAtMost finite_atLeastAtMost neq0_conv some_in_eq zero_less_diff) \n          }\n          then show \"\\<forall>n\\<in>{0..length (sram s) - 1}. ca_set (SOME c. c \\<in> sram s ! n) = n\"\n            by blast\n        qed\n      then have line_diff: \"\\<forall>l1 l2. l1 \\<in> {0..length (sram s) - 1} \\<and> l2 \\<in> {0..length (sram s) - 1} \\<and> l1 \\<noteq> l2 \\<longrightarrow>\n                            (replace_policy ((sram s) ! l1)) \\<noteq> (replace_policy ((sram s) ! l2))\"\n        proof -\n          show ?thesis\n            by (metis (no_types) caset_line)\n        qed\n      have policy_length: \"card policy_line = card {0..length (sram s) - 1}\"\n        using length_finite length_nonempty line_diff a5\n        by (simp add: policy_line_length)\n      then have policy_length2: \"card policy_line = length (sram s)\"\n        using cache_set_size t0 by auto\n      then have out1: \"{t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/card policy_line)} =\n                       {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}\"\n        by auto\n      have s1: \"\\<forall>e \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}.\n                 e \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n        proof -\n          {\n            fix e\n            assume e0: \"e \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}\"\n            have \"fst (fst e) \\<in> {0..length (sram s) - 1}\"\n              using e0 caset_line a5 by auto\n            then have \"\\<exists>d \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}. d = e\"\n              using e0 by auto\n            then have \"e \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n              by auto\n          }\n          then show ?thesis by blast\n        qed\n      have s2: \"\\<forall>e \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}.\n                 e \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}\"\n        proof -\n          {\n            fix e\n            assume e1: \"e \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n            have \"fst (fst e) \\<in> {0..length (sram s) - 1}\"\n              using e1 by auto\n            moreover have \"\\<forall>d \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}. fst (fst d) \\<in> {0..length (sram s) - 1}\"\n              using caset_line a5 by auto\n            ultimately have \"\\<exists>d \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}. d = e\"\n              by (smt caset_line e1 a5 mem_Collect_eq)\n            then have \"e \\<in> {t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))}\"\n              by auto\n          }\n          then show ?thesis by blast\n        qed\n      have out_equal: \"{t. \\<exists>r'_line \\<in> policy_line. t = ((ca_set r'_line, Miss), 1/length (sram s))} =\n                       {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n        using s1 s2 by blast\n      then have out2: \"execution (fst mr) s e = {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n        using out out1 by auto\n      have finite_out: \"finite {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n        by auto\n      have nonempty_out: \"{t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))} \\<noteq> {}\"\n        by auto\n      have value_out: \"\\<forall>d \\<in> {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}. snd d = 1/length (sram s)\"\n        by auto\n      have \"folds (\\<lambda>t p. snd t + p) 0 {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))} =\n           1/length (sram s) * card {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n        using cache_set_size2[where ?w = \"{t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\" and\n                                    ?P = \"snd\" and\n                                    ?i = \"1/length (sram s)\"]\n              finite_out nonempty_out value_out by blast\n      moreover have \"card {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))} = length (sram s)\"\n      proof -\n        {\n          have \"\\<forall>l1 l2. l1 \\<in> {0..length (sram s) - 1} \\<and> l2 \\<in> {0..length (sram s) - 1} \\<and> l1 \\<noteq> l2 \\<longrightarrow>\n                ((l1, Miss), 1/length (sram s)) \\<noteq> ((l2, Miss), 1/length (sram s))\"\n            by auto\n          then have \"card {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1 / real (length (sram s)))} =\n                     card {0..length (sram s) - 1}\"\n            using length_finite length_nonempty\n            by (simp add: policy_line_length)\n          then show ?thesis\n            using cache_set_size t0 by auto\n        }\n      qed\n      ultimately show ?thesis\n        using of_nat_0 out2 by force \n    }\n  qed\n\nlemma read_sum_one:\n  \"\\<forall>e. \\<forall>mr \\<in> mem_req mm_comp. \\<forall>s \\<in> state_N. folds (\\<lambda>t p. snd t + p) 0 (execution (fst mr) s e) = 1\"\n  proof -\n    {\n      fix e\n      have \"\\<forall>mr \\<in> mem_req mm_comp. \\<forall>s \\<in> state_N. folds (\\<lambda>t p. snd t + p) 0 (execution (fst mr) s e) = 1\"\n      proof -\n        {\n          fix mr\n          assume t0: \"mr \\<in> mem_req mm_comp\"\n          have \"\\<forall>s \\<in> state_N. folds (\\<lambda>t p. snd t + p) 0 (execution (fst mr) s e) = 1\"\n          proof -\n            {\n              fix s\n              assume t1: \"s \\<in> state_N\"\n              have \"folds (\\<lambda>t p. snd t + p) 0 (execution (fst mr) s e) = 1\"\n                using read_sum_one_h1 read_sum_one_h2 read_sum_one_h3 read_sum_one_h4 t0 t1\n                by meson \n            }\n            then show ?thesis by blast\n          qed\n        }\n        then show ?thesis by blast\n      qed\n    }\n    then show ?thesis by blast\n  qed\n\ninterpretation CM state_N state_E \"mem_req mm_comp\" execution\n  apply standard\n  using mem_finite mem_nonempty mem_unique mem_positive mem_sum_one\n        read_finite read_nonempty read_unique read_positive read_sum_one\n        stateN_finite stateN_nonempty stateE_nonempty stateE_subset\n  by auto\n\n\nsubsection \\<open>Proofs of Correctness\\<close>\n\nlemma one_changed1:\n  assumes t0: \"s \\<in> state_N\"\n      and t1: \"mr \\<in> mem_req mm_comp\"\n      and a0: \"maps = map_H s\"\n      and a1: \"redir_set = the (maps (index (fst mr)))\"\n      and a2: \"redir_ca = (sram s) ! redir_set\"\n      and a3: \"\\<not> (probe_line redir_ca (fst mr))\"\n      and a4: \"r_line = replace_policy redir_ca\"\n      and a5: \"owned r_line = Some (thread (fst mr))\"\n      and a6: \"lock r_line = protect (fst mr)\"\n      and a7: \"r_line' = replace_line r_line (fst mr)\"\n      and a8: \"newset = insert r_line' (redir_ca - {r_line})\"\n    shows \"card ((sram (the_elem (rp_read s (fst mr))))!redir_set \\<inter> (sram s)!redir_set) =\n           card ((sram s)!redir_set) - 1\"\n  proof -\n    {\n      have exi_redir: \"redir_set < length (sram s)\"\n        using state_N_init unfolding state_N_witness_def using mem_mapping\n        by (smt a0 a1 map_range mem_Collect_eq state.select_convs(1) state.select_convs(2) t0 t1)\n      have t2: \"sram s \\<in> ca_N cache_comp\"\n        using state_N_init t0 unfolding state_N_witness_def\n        proof -\n          assume \"state_N = {t. \\<exists>c\\<in>ca_N cache_comp. t = \\<lparr>sram = c, map_H = map_conf mm_comp, map_L = map_conf mm_comp\\<rparr>}\"\n          then have \"state_N = {s. \\<exists>Cs. Cs \\<in> ca_N cache_comp \\<and> s = \\<lparr>sram = Cs, map_H = map_conf mm_comp, map_L = map_conf mm_comp\\<rparr>}\"\n            by meson\n          then have \"\\<exists>Cs. Cs \\<in> ca_N cache_comp \\<and> s = \\<lparr>sram = Cs, map_H = map_conf mm_comp, map_L = map_conf mm_comp\\<rparr>\"\n            using t0 by blast\n          then show ?thesis\n            by force\n        qed\n      have probe_fails: \"\\<nexists>b. b \\<in> redir_ca \\<and> ca_tag b = tag (fst mr) \\<and> valid b \\<and> owned b = Some (thread (fst mr))\"\n        using a3 unfolding probe_line_def by force\n      have t3: \"r_line \\<in> redir_ca\"\n        using a2 exi_redir a4 unfolding replace_policy_def\n        by (simp add: ca_set_nonempty some_in_eq t2) \n      then have tag_diff: \"\\<not> (ca_tag r_line = tag (fst mr) \\<and> valid r_line \\<and> owned r_line = Some (thread (fst mr)))\"\n        using probe_fails by auto\n      have tag_same: \"ca_tag r_line' = tag (fst mr) \\<and> valid r_line' \\<and> owned r_line' = Some (thread (fst mr))\"\n        using a7 unfolding replace_line_def by simp\n      have t4: \"r_line' \\<notin> redir_ca\"\n        using probe_fails tag_same by blast\n      then have \"newset \\<inter> redir_ca = redir_ca - {r_line}\"\n        using a8 by blast\n      then have re: \"card (newset \\<inter> redir_ca) = card redir_ca - 1\"\n        by (simp add: card_Diff_subset_Int t3)\n      have \"rp_read s (fst mr) = {s\\<lparr>sram := list_update (sram s) redir_set newset\\<rparr>}\"\n        unfolding rp_read_def Let_def\n        using a0 a1 a2 a3 a4 a5 a6 a7 a8 mem_occupy t1 by auto\n      then have \"the_elem (rp_read s (fst mr)) = s\\<lparr>sram := list_update (sram s) redir_set newset\\<rparr>\"\n        unfolding the_elem_def by auto\n      then have \"(sram (the_elem (rp_read s (fst mr))))!redir_set = newset\"\n        using exi_redir by simp\n      then show ?thesis\n        using re a2 by blast \n    }\n  qed\n\nlemma remain_same1:\n  assumes t0: \"s \\<in> state_N\"\n      and t1: \"mr \\<in> mem_req mm_comp\"\n      and a0: \"maps = map_H s\"\n      and a1: \"redir_set = the (maps (index (fst mr)))\"\n      and a2: \"redir_ca = (sram s) ! redir_set\"\n      and a3: \"\\<not> (probe_line redir_ca (fst mr))\"\n      and a4: \"r_line = replace_policy redir_ca\"\n      and a5: \"owned r_line = Some (thread (fst mr))\"\n      and a6: \"lock r_line = protect (fst mr)\"\n      and a7: \"newset = insert (replace_line r_line (fst mr)) (redir_ca - {r_line})\"\n    shows \"\\<forall>l \\<noteq> redir_set. (sram s)!l = (sram (the_elem (rp_read s (fst mr))))!l\"\n  proof -\n    {\n      fix l assume tl: \"l \\<noteq> redir_set\"\n      have \"(sram s)!l = (sram (the_elem (rp_read s (fst mr))))!l\"\n      proof -\n        {\n          have \"rp_read s (fst mr) = {s\\<lparr>sram := list_update (sram s) redir_set newset\\<rparr>}\"\n            unfolding rp_read_def Let_def\n            using a0 a1 a2 a3 a4 a5 a6 a7 mem_occupy t1 by auto \n          then show ?thesis using tl by auto\n        }\n      qed\n    }\n    then show ?thesis by blast\n  qed\n\nlemma one_changed_remain_same2:\n  assumes t0: \"s0 \\<in> state_N\"\n      and t1: \"\\<forall>l < length (sram s0). \\<forall>e \\<in> (sram s0)!l. valid e\"\n      and t2: \"mr \\<in> mem_req mm_comp\"\n      and a0: \"maps = map_H s0\"\n      and a1: \"redir_set = the (maps (index (fst mr)))\"\n      and a2: \"redir_ca = (sram s0) ! redir_set\"\n      and a3: \"\\<not> (probe_line redir_ca (fst mr))\"\n      and a4: \"r_line = replace_policy redir_ca\"\n      and a5: \"policy_line = {t. \\<exists>l \\<in> {0..length (sram s0) - 1}. t = replace_policy ((sram s0) ! l)}\"\n      and a6: \"owned r_line = Some (thread (fst mr))\"\n      and a7: \"lock r_line \\<noteq> protect (fst mr)\"\n    shows \"\\<forall>s' \\<in> rp_read s0 (fst mr). \\<exists>!l. (\\<forall>l' \\<noteq> l. (sram s0)!l' = (sram s')!l') \\<and> (card (((sram s') ! l) \\<inter> ((sram s0) ! l)) = card ((sram s0) ! l) - 1)\"\n  proof -\n    {\n      fix s' assume ts: \"s' \\<in> rp_read s0 (fst mr)\"\n      have \"\\<exists>!l. (\\<forall>l' \\<noteq> l. (sram s0)!l' = (sram s')!l') \\<and> (card (((sram s') ! l) \\<inter> ((sram s0) ! l)) = card ((sram s0) ! l) - 1)\"\n      proof -\n        {\n          have iowned: \"thread (fst mr) = H\"\n            by (simp add: mem_occupy t2)\n          have exi_redir: \"redir_set < length (sram s0)\"\n            using state_N_init unfolding state_N_witness_def using mem_mapping\n            by (smt a0 a1 map_range mem_Collect_eq state.select_convs(1) state.select_convs(2) t0 t2)\n          have t3: \"sram s0 \\<in> ca_N cache_comp\"\n            using state_N_init t0 unfolding state_N_witness_def\n            proof -\n              assume \"state_N = {t. \\<exists>c\\<in>ca_N cache_comp. t = \\<lparr>sram = c, map_H = map_conf mm_comp, map_L = map_conf mm_comp\\<rparr>}\"\n              then have \"state_N = {s. \\<exists>Cs. Cs \\<in> ca_N cache_comp \\<and> s = \\<lparr>sram = Cs, map_H = map_conf mm_comp, map_L = map_conf mm_comp\\<rparr>}\"\n                by meson\n              then have \"\\<exists>Cs. Cs \\<in> ca_N cache_comp \\<and> s0 = \\<lparr>sram = Cs, map_H = map_conf mm_comp, map_L = map_conf mm_comp\\<rparr>\"\n                using t0 by blast\n              then show ?thesis\n                by force\n            qed\n          have probe_fails: \"\\<nexists>b. b \\<in> redir_ca \\<and> ca_tag b = tag (fst mr) \\<and> valid b \\<and> owned b = Some (thread (fst mr))\"\n            using a3 unfolding probe_line_def by force\n          have t4: \"r_line \\<in> redir_ca\"\n            using a2 exi_redir a4 unfolding replace_policy_def\n            by (simp add: ca_set_nonempty some_in_eq t3) \n          then have tag_diff: \"\\<not> (ca_tag r_line = tag (fst mr) \\<and> valid r_line \\<and> owned r_line = Some (thread (fst mr)))\"\n            using probe_fails by auto\n          have out: \"rp_read s0 (fst mr) = {t. \\<exists>r'_line \\<in> policy_line. let newset = insert (drop_line r'_line) (((sram s0) ! (ca_set r'_line)) - {r'_line}) in\n                                               t = s0\\<lparr>sram := list_update (sram s0) (ca_set r'_line) newset\\<rparr>}\"\n            unfolding rp_read_def Let_def\n            using a0 a1 a2 a3 a4 a5 a6 a7 iowned by auto\n          then have \"\\<exists>r'_line \\<in> policy_line.\n                      s' = (let newset = insert (drop_line r'_line) (((sram s0) ! (ca_set r'_line)) - {r'_line}) in\n                            s0\\<lparr>sram := list_update (sram s0) (ca_set r'_line) newset\\<rparr>)\"\n            using ts by auto\n          then obtain r'_line where t5: \"r'_line \\<in> policy_line \\<and>\n                                         s' = (let newset = insert (drop_line r'_line) (((sram s0) ! (ca_set r'_line)) - {r'_line}) in\n                                               s0\\<lparr>sram := list_update (sram s0) (ca_set r'_line) newset\\<rparr>)\"\n            by auto\n          have r'_length: \"ca_set r'_line < length (sram s0)\"\n            using t5 by (smt Suc_pred' a5 atLeastAtMost_iff ca_length ca_set_nonempty ca_set_num less_Suc_eq_le mem_Collect_eq replace_policy_def some_in_eq t3)\n          have r'_belong: \"r'_line \\<in> (sram s0) ! (ca_set r'_line)\"\n            using t5 by (smt Suc_pred' a5 atLeastAtMost_iff ca_length ca_set_nonempty ca_set_num less_Suc_eq_le mem_Collect_eq replace_policy_def some_in_eq t3)\n          have tag_valid: \"valid r'_line\"\n            using t1 r'_belong r'_length by blast\n          let ?r'_line' = \"drop_line r'_line\"\n          have tag_drop: \"valid ?r'_line' = False \\<and> lock ?r'_line' = False \\<and> owned ?r'_line' = None\"\n            unfolding drop_line_def by simp\n          have t6: \"?r'_line' \\<notin> (sram s0) ! (ca_set r'_line)\"\n            using r'_length t1 tag_drop by blast\n          let ?newset = \"insert ?r'_line' (((sram s0) ! (ca_set r'_line)) - {r'_line})\"\n          have \"?newset \\<inter> ((sram s0) ! (ca_set r'_line)) = ((sram s0) ! (ca_set r'_line)) - {r'_line}\"\n            using t6 by auto\n          then have re: \"card (?newset \\<inter> ((sram s0) ! (ca_set r'_line))) = card ((sram s0) ! (ca_set r'_line)) - 1\"\n            by (simp add: card_Diff_subset_Int r'_belong)\n          have out1: \"s' = s0\\<lparr>sram := list_update (sram s0) (ca_set r'_line) ?newset\\<rparr>\"\n            using t5 by simp\n          then have \"sram s' = list_update (sram s0) (ca_set r'_line) ?newset\"\n            by auto\n          then have \"\\<exists>!l. l = ca_set r'_line \\<and> (\\<forall>l' \\<noteq> l. sram s0 ! l' = sram s' ! l') \\<and>\n                          card (((sram s') ! l) \\<inter> ((sram s0) ! l)) = card ((sram s0) ! l) - 1\"\n            using re nth_list_update_eq r'_length by auto \n          then show ?thesis\n            by (metis \\<open>sram s' = (sram s0) [ca_set r'_line := insert (drop_line r'_line) (sram s0 ! ca_set r'_line - {r'_line})]\\<close> insertI1 nth_list_update_eq r'_length t6) \n        }\n      qed\n    }\n    then show ?thesis by auto\n  qed\n\nlemma one_changed_remain_same3:\n  \"\\<forall>i \\<in> mem_req mm_comp. \\<forall>s0 \\<in> state_E. \\<forall>s' \\<in> rp_read s0 (fst i).\n    \\<exists>!l. (\\<forall>l' \\<noteq> l. (sram s0)!l' = (sram s')!l') \\<and> (card (((sram s') ! l) \\<inter> ((sram s0) ! l)) = card ((sram s0) ! l) - 1)\"\n  proof -\n    {\n      fix i assume t0: \"i \\<in> mem_req mm_comp\"\n      have \"\\<forall>s0 \\<in> state_E. \\<forall>s' \\<in> rp_read s0 (fst i).\n              \\<exists>!l. (\\<forall>l' \\<noteq> l. (sram s0)!l' = (sram s')!l') \\<and> (card (((sram s') ! l) \\<inter> ((sram s0) ! l)) = card ((sram s0) ! l) - 1)\"\n      proof -\n        {\n          fix s0 assume t1: \"s0 \\<in> state_E\"\n          have \"\\<forall>s' \\<in> rp_read s0 (fst i).\n                  \\<exists>!l. (\\<forall>l' \\<noteq> l. (sram s0)!l' = (sram s')!l') \\<and> (card (((sram s') ! l) \\<inter> ((sram s0) ! l)) = card ((sram s0) ! l) - 1)\"\n          proof -\n            {\n              fix s' assume t2: \"s' \\<in> rp_read s0 (fst i)\"\n              have \"\\<exists>!l. (\\<forall>l' \\<noteq> l. (sram s0)!l' = (sram s')!l') \\<and> (card (((sram s') ! l) \\<inter> ((sram s0) ! l)) = card ((sram s0) ! l) - 1)\"\n              proof -\n                {\n                  have iowned: \"thread (fst i) = H\"\n                    by (simp add: mem_occupy t0)\n                  then have \"(if thread (fst i) = H then map_H s0 else map_L s0) = map_H s0\"\n                    by auto\n                  let ?maps = \"map_H s0\"\n                  let ?redir_set = \"the (?maps (index (fst i)))\"\n                  have exi_redir: \"?redir_set < length (sram s0)\"\n                    using state_E_init unfolding state_E_witness_def using mem_mapping\n                    by (smt caE_init map_range mem_Collect_eq state.select_convs(1) state.select_convs(2) subsetD t0 t1)\n                  let ?redir_ca = \"(sram s0) ! ?redir_set\"\n                  have t3: \"sram s0 \\<in> ca_E cache_comp\"\n                    using state_E_init unfolding state_E_witness_def\n                    proof -\n                      assume \"state_E = {t. \\<exists>c\\<in>ca_E cache_comp. t = \\<lparr>sram = c, map_H = map_conf mm_comp, map_L = map_conf mm_comp\\<rparr>}\"\n                      then have \"state_E = {s. \\<exists>Cs. Cs \\<in> ca_E cache_comp \\<and> s = \\<lparr>sram = Cs, map_H = map_conf mm_comp, map_L = map_conf mm_comp\\<rparr>}\"\n                        by meson\n                      then have \"\\<exists>Cs. Cs \\<in> ca_E cache_comp \\<and> s0 = \\<lparr>sram = Cs, map_H = map_conf mm_comp, map_L = map_conf mm_comp\\<rparr>\"\n                        using t1 by blast\n                      then show ?thesis\n                        by fastforce\n                    qed\n                  then have setowned: \"\\<forall>l < length (sram s0). \\<forall>e \\<in> ((sram s0)!l). owned e = Some L\"\n                    using caE_occupy by blast\n                  then have \"\\<nexists>b. b \\<in> ?redir_ca \\<and> ca_tag b = tag (fst i) \\<and> valid b \\<and> owned b = Some (thread (fst i))\"\n                    using iowned exi_redir by auto\n                  then have c1: \"\\<not> probe_line ?redir_ca (fst i)\"\n                    unfolding probe_line_def by blast\n                  let ?r_line = \"replace_policy ?redir_ca\"\n                  have \"?r_line \\<in> ?redir_ca\"\n                    unfolding replace_policy_def\n                    using caE_init ca_set_nonempty some_in_eq t3 exi_redir by blast\n                  then have \"owned ?r_line = Some L\"\n                    using setowned exi_redir by blast\n                  then have c2: \"owned ?r_line \\<noteq> Some (thread (fst i))\"\n                    using iowned by auto\n                  let ?policy_line = \"{t. \\<exists>l \\<in> {0..length (sram s0) - 1}. t = replace_policy ((sram s0) ! l)}\"\n                  have out: \"rp_read s0 (fst i) = {t. \\<exists>r'_line \\<in> ?policy_line.\n                                                      if ca_set r'_line = ?redir_set then\n                                                        let newset = insert (replace_line r'_line (fst i)) (fix_line (((sram s0) ! (ca_set r'_line)) - {r'_line}) (fst i)) in\n                                                            t = s0\\<lparr>sram := list_update (sram s0) (ca_set r'_line) newset,\n                                                                   map_H := swap_map (map_H s0) ?redir_set (ca_set r'_line)\\<rparr>\n                                                      else let newset = insert (replace_line r'_line (fst i)) (fix_line (((sram s0) ! (ca_set r'_line)) - {r'_line}) (fst i));\n                                                               new_redir_ca = fix_line ?redir_ca (fst i) in\n                                                        t = s0\\<lparr>sram := list_update (list_update (sram s0) (ca_set r'_line) newset) ?redir_set new_redir_ca,\n                                                               map_H := swap_map (map_H s0) ?redir_set (ca_set r'_line)\\<rparr>}\"\n                    unfolding rp_read_def Let_def\n                    using c1 c2 by (simp add: iowned)\n                  then have \"\\<exists>r'_line \\<in> ?policy_line.\n                              s' = (if ca_set r'_line = ?redir_set then\n                                      let newset = insert (replace_line r'_line (fst i)) (fix_line (((sram s0) ! (ca_set r'_line)) - {r'_line}) (fst i)) in\n                                          s0\\<lparr>sram := list_update (sram s0) (ca_set r'_line) newset,\n                                             map_H := swap_map (map_H s0) ?redir_set (ca_set r'_line)\\<rparr>\n                                    else let newset = insert (replace_line r'_line (fst i)) (fix_line (((sram s0) ! (ca_set r'_line)) - {r'_line}) (fst i));\n                                             new_redir_ca = fix_line ?redir_ca (fst i) in\n                                      s0\\<lparr>sram := list_update (list_update (sram s0) (ca_set r'_line) newset) ?redir_set new_redir_ca,\n                                         map_H := swap_map (map_H s0) ?redir_set (ca_set r'_line)\\<rparr>)\"\n                    using t2 by auto \n                  then obtain r'_line where t4: \"r'_line \\<in> ?policy_line \\<and>\n                                                 s' = (if ca_set r'_line = ?redir_set then\n                                                         let newset = insert (replace_line r'_line (fst i)) (fix_line (((sram s0) ! (ca_set r'_line)) - {r'_line}) (fst i)) in\n                                                             s0\\<lparr>sram := list_update (sram s0) (ca_set r'_line) newset,\n                                                                map_H := swap_map (map_H s0) ?redir_set (ca_set r'_line)\\<rparr>\n                                                       else let newset = insert (replace_line r'_line (fst i)) (fix_line (((sram s0) ! (ca_set r'_line)) - {r'_line}) (fst i));\n                                                                new_redir_ca = fix_line ?redir_ca (fst i) in\n                                                         s0\\<lparr>sram := list_update (list_update (sram s0) (ca_set r'_line) newset) ?redir_set new_redir_ca,\n                                                            map_H := swap_map (map_H s0) ?redir_set (ca_set r'_line)\\<rparr>)\"\n                    by auto\n                  have r'_length: \"ca_set r'_line < length (sram s0)\"\n                    using t4\n                    proof -\n                      obtain nn :: \"cache_line \\<Rightarrow> nat\" where\n                        \"(r'_line \\<notin> {c. \\<exists>n. n \\<in> {0..length (sram s0) - 1} \\<and> c = replace_policy (sram s0 ! n)} \\<or> nn r'_line \\<in> {0..length (sram s0) - 1} \\<and> r'_line = (SOME c. c \\<in> sram s0 ! nn r'_line)) \\<and> (r'_line \\<in> {c. \\<exists>n. n \\<in> {0..length (sram s0) - 1} \\<and> c = replace_policy (sram s0 ! n)} \\<or> (\\<forall>n. n \\<notin> {0..length (sram s0) - 1} \\<or> r'_line \\<noteq> (SOME c. c \\<in> sram s0 ! n)))\"\n                        using replace_policy_def by moura\n                      then have f1: \"nn r'_line \\<in> {0..length (sram s0) - 1} \\<and> r'_line = (SOME c. c \\<in> sram s0 ! nn r'_line)\"\n                        using t4 by blast\n                      then have f2: \"nn r'_line \\<in> Collect ((\\<le>) 0) \\<and> length (sram s0) - 1 \\<in> Collect ((\\<le>) (nn r'_line))\"\n                        using atLeastAtMost_iff by blast\n                      have f3: \"sram s0 \\<in> ca_N cache_comp\"\n                        using caE_init t3 by blast\n                      then have f4: \"length (sram s0) = Suc (length (sram s0) - 1)\"\n                        by (meson Suc_pred' ca_length)\n                      have \"\\<forall>n na. (Suc na \\<in> Collect ((<) n)) = (na \\<in> Collect ((\\<le>) n))\"\n                        by (simp add: less_Suc_eq_le)\n                      then show ?thesis\n                        using f4 f3 f2 f1 by (metis ca_set_nonempty ca_set_num mem_Collect_eq some_in_eq)\n                    qed\n                  have r'_belong: \"r'_line \\<in> (sram s0) ! (ca_set r'_line)\"\n                    using t4\n                    proof -\n                      have f1: \"sram s0 \\<in> ca_N cache_comp\"\n                        using caE_init t3 by blast\n                      obtain nn :: \"cache_line \\<Rightarrow> nat\" where\n                        \"(r'_line \\<notin> {c. \\<exists>n. n \\<in> {0..length (sram s0) - 1} \\<and> c = replace_policy (sram s0 ! n)} \\<or> nn r'_line \\<in> {0..length (sram s0) - 1} \\<and> r'_line = (SOME c. c \\<in> sram s0 ! nn r'_line)) \\<and> (r'_line \\<in> {c. \\<exists>n. n \\<in> {0..length (sram s0) - 1} \\<and> c = replace_policy (sram s0 ! n)} \\<or> (\\<forall>n. n \\<notin> {0..length (sram s0) - 1} \\<or> r'_line \\<noteq> (SOME c. c \\<in> sram s0 ! n)))\"\n                        using replace_policy_def by moura\n                      then have f2: \"nn r'_line \\<in> {0..length (sram s0) - 1} \\<and> r'_line = (SOME c. c \\<in> sram s0 ! nn r'_line)\"\n                        using t4 by blast\n                      then have f3: \"length (sram s0) \\<in> Collect ((<) (nn r'_line))\"\n                        using f1 by (metis Suc_pred' atLeastAtMost_iff ca_length less_Suc_eq_le mem_Collect_eq)\n                      then have f4: \"(SOME c. c \\<in> sram s0 ! nn r'_line) \\<in> sram s0 ! nn r'_line\"\n                        using f1 by (simp add: ca_set_nonempty some_in_eq)\n                      then have \"nn r'_line = ca_set r'_line\"\n                        using f3 f2 f1 by (simp add: ca_set_num)\n                      then show ?thesis\n                      using f4 f2 by auto\n                    qed\n                  then have tag_diff: \"the (owned r'_line) \\<noteq> thread (fst i)\"\n                    using setowned r'_length iowned by auto \n                  {\n                    assume r0: \"ca_set r'_line = ?redir_set\"\n                    have fix_l: \"fix_line (((sram s0) ! (ca_set r'_line)) - {r'_line}) (fst i) = ((sram s0) ! (ca_set r'_line)) - {r'_line}\"\n                      unfolding fix_line_def using r'_length setowned iowned by auto\n                    let ?r'_line' = \"replace_line r'_line (fst i)\"\n                    have tag_same: \"ca_tag ?r'_line' = tag (fst i) \\<and> valid ?r'_line' \\<and> owned ?r'_line' = Some (thread (fst i))\"\n                      unfolding replace_line_def by simp\n                    have t5: \"?r'_line' \\<notin> (sram s0) ! (ca_set r'_line)\"\n                      using c1 probe_line_def r0 tag_same by auto\n                    let ?newset = \"insert ?r'_line' (((sram s0) ! (ca_set r'_line)) - {r'_line})\"\n                    have \"?newset \\<inter> ((sram s0) ! (ca_set r'_line)) = ((sram s0) ! (ca_set r'_line)) - {r'_line}\"\n                      using t5 by auto\n                    then have re: \"card (?newset \\<inter> ((sram s0) ! (ca_set r'_line))) = card ((sram s0) ! (ca_set r'_line)) - 1\"\n                      by (simp add: card_Diff_subset_Int r'_belong)\n                    have out1: \"s' = s0\\<lparr>sram := list_update (sram s0) (ca_set r'_line) ?newset,\n                                        map_H := swap_map (map_H s0) ?redir_set (ca_set r'_line)\\<rparr>\"\n                      using t4 fix_l r0 by auto\n                    then have \"sram s' = list_update (sram s0) (ca_set r'_line) ?newset\"\n                      by auto\n                    then have \"\\<exists>!l. l = ca_set r'_line \\<and> (\\<forall>l' \\<noteq> l. sram s0 ! l' = sram s' ! l') \\<and>\n                                    card (((sram s') ! l) \\<inter> ((sram s0) ! l)) = card ((sram s0) ! l) - 1\"\n                      using re nth_list_update_eq r'_length by auto \n                    then have ?thesis\n                      by (metis \\<open>sram s' = (sram s0) [ca_set r'_line := insert (replace_line r'_line (fst i)) (sram s0 ! ca_set r'_line - {r'_line})]\\<close> insertI1 nth_list_update_eq r'_length t5) \n                  }\n                  moreover\n                  {\n                    assume r1: \"ca_set r'_line \\<noteq> ?redir_set\"\n                    have fix_l: \"fix_line (((sram s0) ! (ca_set r'_line)) - {r'_line}) (fst i) = ((sram s0) ! (ca_set r'_line)) - {r'_line}\"\n                      unfolding fix_line_def using r'_length setowned iowned by auto\n                    let ?r'_line' = \"replace_line r'_line (fst i)\"\n                    have tag_same: \"ca_tag ?r'_line' = tag (fst i) \\<and> valid ?r'_line' \\<and> owned ?r'_line' = Some (thread (fst i))\"\n                      unfolding replace_line_def by simp\n                    have t5: \"?r'_line' \\<notin> (sram s0) ! (ca_set r'_line)\"\n                      using \\<open>owned (replace_policy (sram s0 ! the (map_H s0 (index (fst i))))) = Some L\\<close> c2 r'_length setowned tag_same by force\n                    let ?newset = \"insert ?r'_line' (((sram s0) ! (ca_set r'_line)) - {r'_line})\"\n  \n                    have \"?newset \\<inter> ((sram s0) ! (ca_set r'_line)) = ((sram s0) ! (ca_set r'_line)) - {r'_line}\"\n                      using t5 by auto\n                    then have re: \"card (?newset \\<inter> ((sram s0) ! (ca_set r'_line))) = card ((sram s0) ! (ca_set r'_line)) - 1\"\n                      by (simp add: card_Diff_subset_Int r'_belong)\n  \n                    have fix_ll: \"fix_line ?redir_ca (fst i) = ?redir_ca\"\n                      unfolding fix_line_def using setowned iowned exi_redir by auto\n                    let ?new_redir_ca = \"?redir_ca\"\n                    have out2: \"s' = s0\\<lparr>sram := list_update (list_update (sram s0) (ca_set r'_line) ?newset) ?redir_set ?new_redir_ca,\n                                        map_H := swap_map (map_H s0) ?redir_set (ca_set r'_line)\\<rparr>\"\n                      using t4\n                      by (simp add: \\<open>fix_line (sram s0 ! the (map_H s0 (index (fst i)))) (fst i) = sram s0 ! the (map_H s0 (index (fst i)))\\<close> fix_l r1) \n                    have \"list_update (list_update (sram s0) (ca_set r'_line) ?newset) ?redir_set ?new_redir_ca = list_update (sram s0) (ca_set r'_line) ?newset\"\n                      using fix_ll by (simp add: list_update_swap r1)\n                    then have \"sram s' = list_update (sram s0) (ca_set r'_line) ?newset\"\n                      using out2 by auto\n                    then have \"\\<exists>!l. l = ca_set r'_line \\<and> (\\<forall>l' \\<noteq> l. sram s0 ! l' = sram s' ! l') \\<and>\n                                    card (((sram s') ! l) \\<inter> ((sram s0) ! l)) = card ((sram s0) ! l) - 1\"\n                      using re nth_list_update_eq r'_length by auto \n                    have ?thesis\n                      by (metis \\<open>\\<exists>!l. l = ca_set r'_line \\<and> (\\<forall>l'. l' \\<noteq> l \\<longrightarrow> sram s0 ! l' = sram s' ! l') \\<and> card (sram s' ! l \\<inter> sram s0 ! l) = card (sram s0 ! l) - 1\\<close> \\<open>sram s' = (sram s0) [ca_set r'_line := insert (replace_line r'_line (fst i)) (sram s0 ! ca_set r'_line - {r'_line})]\\<close> insertI1 nth_list_update_eq r'_length t5)\n                  }\n                  ultimately have ?thesis\n                    by linarith \n                }\n                then show ?thesis by blast\n              qed\n            }\n            then show ?thesis by blast\n          qed\n        }\n        then show ?thesis by blast\n      qed\n    }\n    then show ?thesis by blast\n  qed\n\n\nsubsection \\<open>Proofs of Security Model\\<close>\n\nlemma read_not_zero:\n  \"\\<forall>e. \\<forall>mr \\<in> mem_req mm_comp. \\<forall>s \\<in> state_E. \\<forall>d \\<in> execution (fst mr) s e. snd d \\<noteq> 0\"\n  proof -\n    {\n      fix e\n      have \"\\<forall>mr \\<in> mem_req mm_comp. \\<forall>s \\<in> state_E. \\<forall>d \\<in> execution (fst mr) s e. snd d \\<noteq> 0\"\n      proof -\n        {\n          fix mr\n          assume t0: \"mr \\<in> mem_req mm_comp\"\n          have \"\\<forall>s \\<in> state_E. \\<forall>d \\<in> execution (fst mr) s e. snd d \\<noteq> 0\"\n          proof -\n            {\n              fix s\n              assume t1: \"s \\<in> state_E\"\n              have \"\\<forall>d \\<in> execution (fst mr) s e. snd d \\<noteq> 0\"\n              proof -\n                {\n                  have \"execution (fst mr) s e = {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n                    unfolding execution_def using mem_cache_miss t0 t1 by auto\n                  moreover have \"length (sram s) \\<noteq> 0\"\n                    using cache_set_size stateE_subset t1 by fastforce\n                  ultimately show ?thesis\n                    by simp \n                }\n              qed\n            }\n            then show ?thesis by blast\n          qed\n        }\n        then show ?thesis by blast\n      qed\n    }\n    then show ?thesis by blast\n  qed\n\nlemma read_uniform:\n  \"\\<forall>e. \\<forall>mr \\<in> mem_req mm_comp. \\<forall>s \\<in> state_E. \\<forall>d \\<in> execution (fst mr) s e.\n    snd d = folds (\\<lambda>t p. snd t + p) 0 {u. u \\<in> makeDist s e \\<and> snd (fst u) = fst d}\"\n  proof -\n    {\n      fix e\n      have \"\\<forall>mr \\<in> mem_req mm_comp. \\<forall>s \\<in> state_E. \\<forall>d \\<in> execution (fst mr) s e.\n             snd d = folds (\\<lambda>t p. snd t + p) 0 {u. u \\<in> makeDist s e \\<and> snd (fst u) = fst d}\"\n      proof -\n        {\n          fix mr assume t0: \"mr \\<in> mem_req mm_comp\"\n          have \"\\<forall>s \\<in> state_E. \\<forall>d \\<in> execution (fst mr) s e.\n                 snd d = folds (\\<lambda>t p. snd t + p) 0 {u. u \\<in> makeDist s e \\<and> snd (fst u) = fst d}\"\n          proof -\n            {\n              fix s assume t1: \"s \\<in> state_E\"\n              have \"\\<forall>d \\<in> execution (fst mr) s e.\n                     snd d = folds (\\<lambda>t p. snd t + p) 0 {u. u \\<in> makeDist s e \\<and> snd (fst u) = fst d}\"\n              proof -\n                {\n                  fix d assume \"d \\<in> execution (fst mr) s e\"\n                  have emr: \"execution (fst mr) s e = {t. \\<exists>r \\<in> {0..length (sram s) - 1}. t = ((r, Miss), 1/length (sram s))}\"\n                    unfolding execution_def using mem_cache_miss\n                    using t0 t1 by blast\n                  have pmf_m: \"\\<forall>m \\<in> mem_req mm_comp. \\<exists>!t \\<in> execution (fst m) s e. t = (fst d, snd d)\"\n                    using \\<open>d \\<in> execution (fst mr) s e\\<close> execution_def mem_cache_miss t0 t1 by auto\n                  then have makedist_m: \"\\<forall>m \\<in> mem_req mm_comp. ((fst m, fst d), snd m * snd d) \\<in> makeDist s e\"\n                    unfolding makeDist_def using emr by fastforce\n                  then have set_equal: \"{u. u \\<in> makeDist s e \\<and> snd (fst u) = fst d} =\n                                        {t. \\<exists>m \\<in> mem_req mm_comp. t = ((fst m, fst d), snd m * snd d)}\"\n                    by (smt Collect_cong Pair_inject execution_def makeDist_def mem_Collect_eq mem_cache_miss pmf_m surjective_pairing t1)\n                  have sum1: \"folds (\\<lambda>t p. snd t + p) 0 {t. \\<exists>m \\<in> mem_req mm_comp. t = ((fst m, fst d), snd m * snd d)} =\n                              folds (\\<lambda>t p. snd t * snd d + p) 0 (mem_req mm_comp)\" \n                    using folds_plus_times_input2[where ?w = \"mem_req mm_comp\" and ?d = \"d\"]\n                          mem_finite mem_nonempty mem_unique inputdist_nonempty by auto \n                  have sum2: \"folds (\\<lambda>t p. snd t * snd d + p) 0 (mem_req mm_comp) = snd d * (folds (\\<lambda>t p. snd t + p) 0 (mem_req mm_comp))\"\n                    using folds_plus_times_input[where ?w = \"mem_req mm_comp\" and ?i = \"snd d\"]\n                          mem_finite mem_nonempty mem_unique inputdist_nonempty by auto\n                  have \"snd d = folds (\\<lambda>t p. snd t + p) 0 {u. u \\<in> makeDist s e \\<and> snd (fst u) = fst d}\"\n                    using set_equal sum1 sum2 mem_sum_one by simp\n                }\n                then show ?thesis by auto\n              qed\n            }\n            then show ?thesis by auto\n          qed\n        }\n        then show ?thesis by blast\n      qed\n    }\n    then show ?thesis by blast\n  qed\n\nend\n", "meta": {"author": "johnakeke", "repo": "Microarchitecture-Side-Channel-Verification", "sha": "0b0bac7f86752ad40c601e2244a92a90af628aea", "save_path": "github-repos/isabelle/johnakeke-Microarchitecture-Side-Channel-Verification", "path": "github-repos/isabelle/johnakeke-Microarchitecture-Side-Channel-Verification/Microarchitecture-Side-Channel-Verification-0b0bac7f86752ad40c601e2244a92a90af628aea/CM_RpSpec.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.29111574776707544}}
{"text": "theory SM_Sticky\nimports \n  SM_Indep\n  DFS_Framework.Reachable_Nodes\n  DFS_Framework.Feedback_Arcs\n  Partial_Order_Reduction.Ample_Analysis\nbegin\n\n  lemma eq_conv_sym: \n    assumes \"(a=b) = c\"\n    shows \"(b=a) = c\"\n    using assms by auto\n\n  lemma neq_conv_sym: \n    assumes \"(a\\<noteq>b) = c\"\n    shows \"(b\\<noteq>a) = c\"\n    using assms by auto\n\n  lemmas [iff] = not_None_eq[THEN neq_conv_sym]\n\n  lemma none_notin_set_map_Some_conv: \"None \\<notin> set w \\<longleftrightarrow> (\\<exists>w'. w=map Some w')\"\n    apply rule\n      apply (induction w)\n      apply (auto simp: map_eq_Cons_conv[THEN eq_conv_sym]) [2]\n\n      apply auto []\n    done\n\n  context cprog begin \n    definition \"cfgc_V0 \\<equiv> comp.\\<gamma> ` cfg_V0 prog\"\n    definition \"cfgc_V0_list \\<equiv> map comp.\\<gamma> (cfg_V0_list prog)\"\n\n    lemma cfgc_V0_list_refine: \"(cfgc_V0_list, cfgc_V0) \\<in> \\<langle>Id\\<rangle>list_set_rel\"\n      unfolding cfgc_V0_def cfgc_V0_list_def list_set_rel_def br_def\n      using cfg_V0_list_invar cfg_V0_list_refine\n      apply (auto simp: distinct_map intro!: inj_onI)\n      using comp.\\<alpha>_\\<gamma>_inverse comp.rl_reachable\n      apply auto\n      by (meson Image_iff comp.\\<gamma>_inj inj_onD inj_on_subset rtrancl.rtrancl_refl)\n\n    definition \"cfgc_E \\<equiv> {(c,c'). \\<exists>a. cfgc c a c'}\"\n    definition \"cfgc_E_succ \\<equiv> remdups o map snd o comp.succ_impl\"\n\n    lemma cfgc_E_succ_refine: \"(cfgc_E_succ, cfgc_E) \\<in> \\<langle>nat_rel\\<rangle>slg_rel\"\n      unfolding cfgc_E_def cfgc_E_succ_def comp.astep_impl_def\n      unfolding slg_rel_def build_rel_def\n      apply (rule relcompI[where b=\"\\<lambda>c. snd`set (comp.succ_impl c)\"])\n      apply (auto simp: list_set_rel_def build_rel_def comp.succ_impl_invar)\n      done\n\n    definition \"cfgc_G \\<equiv> \\<lparr> g_V = UNIV, g_E = cfgc_E, g_V0 = cfgc_V0 \\<rparr>\"\n    definition \"cfgc_G_impl \\<equiv> \\<lparr> gi_V = \\<lambda> _. True, gi_E = cfgc_E_succ, gi_V0 = cfgc_V0_list \\<rparr>\"\n\n    lemma cfg_G_simps[simp]:\n      \"g_V cfgc_G = UNIV\"\n      \"g_E cfgc_G = cfgc_E\"\n      \"g_V0 cfgc_G = cfgc_V0\"\n      unfolding cfgc_G_def by auto\n\n    lemma cfgc_G_impl_refine: \"(cfgc_G_impl, cfgc_G) \\<in> \\<langle>unit_rel, nat_rel\\<rangle>g_impl_rel_ext\"\n      unfolding cfgc_G_def cfgc_G_impl_def\n      by (parametricity add: fun_set_UNIV_refine cfgc_V0_list_refine cfgc_E_succ_refine)\n\n    lemma cfgc_V0_invarc: \"c\\<in>cfgc_V0 \\<Longrightarrow> comp.invar c\"\n      unfolding cfgc_V0_def comp.invar_def\n      apply auto\n      apply (rule comp.\\<gamma>_invar)\n      apply (auto simp: approx_reachable_list_refine cfg_V0_def approx_reachable_prog0)\n      done\n\n    lemma cfgc_Estar_invarc: \"\\<lbrakk>comp.invar c; (c,c')\\<in>cfgc_E\\<^sup>*\\<rbrakk> \\<Longrightarrow> comp.invar c'\"\n      apply (rotate_tac)\n      apply (induction rule: rtrancl_induct)\n      apply (auto simp: cfgc_E_def comp.astep_impl_invarc)\n      done\n  \n  end\n\n  context visible_prog\n  begin\n\n    lemma pid_valid_preserve[simp]: \"pid_valid (ga_ex a gc) pid = pid_valid gc pid\"  \n      by (auto \n        simp: ga_ex_def ga_gex_def stutter_extend_ex_def\n        split: option.splits prod.splits\n      )\n\n    lemma pid_valid_preserve_fold[simp]: \"pid_valid (fold ga_ex w gc) pid = pid_valid gc pid\"  \n      by (induction w arbitrary: gc) auto\n\n    lemma pid_valid_ga_gen: \"(pid,cac)\\<in>ga_gen gc \\<Longrightarrow> pid_valid gc pid\"\n      by (auto simp: ga_gen_def)\n\n    lemma pid_valid_ga_en: \"Some (pid,cac)\\<in>ga_en gc \\<Longrightarrow> pid_valid gc pid\"\n      by (auto simp: some_ga_en_eq pid_valid_ga_gen)\n\n    sublocale sys_graph: fb_graph cfgc_G\n      apply unfold_locales\n      apply (simp_all add: cfgc_V0_def cfg_V0_def cfgc_E_def)\n      done\n\n    lemma finite_cfgE_reachable[simp, intro!]: \"finite (cfgc_E\\<^sup>* `` cfgc_V0)\"\n      apply (rule finite_ImageI)\n      using sys_graph.finite_V0\n      apply simp\n      apply (rule finite_subset[where B=\"Collect comp.invar\"])\n      apply (auto intro: cfgc_V0_invarc cfgc_Estar_invarc) []\n      apply (simp add: comp.invar_def[abs_def])      \n      done\n\n    definition \"vis_edges \\<equiv> {(c,c'). \\<exists>a. cfgc c a c' \\<and> write_globals a \\<inter> vis_vars \\<noteq> {}}\"\n\n    fun ga_is_pid :: \"global_action option \\<Rightarrow> pid \\<Rightarrow> bool\" where\n      \"ga_is_pid None _ \\<longleftrightarrow> True\"\n    | \"ga_is_pid (Some (pid',_)) pid \\<longleftrightarrow> pid'=pid\"\n\n\n    lemma \n      assumes \"(pid,c,a,c') \\<in> ga_gen gc\"\n      shows \n        ga_gen_cmd: \"cmd_of_pid gc pid = c\" and \n        ga_gen_cmd': \"cmd_of_pid (ga_gex (pid,c,a,c') gc) pid = c'\" and \n        ga_gen_edge: \"(c,c')\\<in>cfgc_E\"\n      using assms\n      apply -\n      apply (cases a)\n      apply (auto \n        simp: cfgc_E_def\n        simp: ga_gen_def la_en'_def\n        simp: ga_gex_def la_ex'_def\n        split: option.splits\n        ) [5]\n      apply (cases a)\n      apply (auto \n        simp: cfgc_E_def\n        simp: ga_gen_def la_en'_def\n        simp: ga_gex_def la_ex'_def\n        split: option.splits\n        ) [5]\n      apply (cases a)\n      apply (auto \n        simp: cfgc_E_def\n        simp: ga_gen_def la_en'_def\n        simp: ga_gex_def la_ex'_def\n        split: option.splits\n        ) [5]\n      done      \n\n    lemmas ga_gen_cmd_cfg = ga_gen_cmd ga_gen_cmd' ga_gen_edge\n\n    lemma ga_gex_other: \n      assumes \"pid'\\<noteq>pid\"\n      shows \"cmd_of_pid (ga_gex (pid',c,a,c') gc) pid = cmd_of_pid gc pid\"\n      using assms\n      apply (cases a)\n      apply (auto \n        simp: ga_gex_def la_ex'_def\n        split: option.splits\n        ) [5]\n      done\n\n    lemma proj_word_fin_to_cfg_E:\n      assumes \"jsys.path (map Some w) gc\"\n      assumes \"fold ga_gex w gc = gc'\"\n      shows \"(cmd_of_pid gc pid, cmd_of_pid gc' pid) \n        \\<in> (cfgc_E \\<inter> (\\<lambda>(_,c,_,c'). (c,c'))`set w)\\<^sup>*\" (is \"_\\<in>(?E w)\\<^sup>*\")\n      using assms\n    proof (induction w arbitrary: gc)\n      case (Cons ga w)\n      from Cons.prems have \n        EN: \"ga \\<in> ga_gen gc\" and\n        WF': \"jsys.path (map Some w) (ga_gex ga gc)\" and\n        EX': \"fold ga_gex w (ga_gex ga gc) = gc'\"\n        by (auto simp: some_ga_en_eq some_ga_ex_eq)\n      obtain pid' c a c' where [simp]: \"ga = (pid',c,a,c')\"\n        by (cases ga)\n\n      have \"(cmd_of_pid gc pid, cmd_of_pid (ga_gex ga gc) pid) \\<in> (?E (ga#w))\\<^sup>*\"\n      proof (cases \"pid'=pid\")  \n        case True\n        note True[simp]\n        from EN have \"(pid,c,a,c')\\<in>ga_gen gc\" by simp\n        from ga_gen_cmd_cfg[OF this] \n        have \"(cmd_of_pid gc pid, cmd_of_pid (ga_gex ga gc) pid) \\<in> ?E (ga#w)\" \n          by auto\n        thus ?thesis ..\n      next\n        case False\n        hence \"cmd_of_pid (ga_gex ga gc) pid = cmd_of_pid gc pid\"\n          by (simp add: ga_gex_other)\n        thus ?thesis by auto\n      qed\n      also from Cons.IH[OF WF' EX'] have \n        \"(cmd_of_pid (ga_gex ga gc) pid, cmd_of_pid gc' pid) \\<in> (?E (ga#w))\\<^sup>*\"\n        apply (rule set_rev_mp[OF _ rtrancl_mono])\n        by auto\n      finally show ?case .\n    qed simp\n\n    lemma words_fin_None_fmt:\n      assumes \"jsys.path w gc\"\n      obtains w' n where \"w=map Some w'@replicate n None\"\n      using assms\n    proof (induction arbitrary: thesis)\n      case nil thus ?case by simp\n    next\n      case (cons a gc w)\n      from cons.IH obtain w' n where [simp]: \"w=map Some w'@replicate n None\" .\n      show ?case proof (cases a)\n        case None\n        note None[simp] \n        from cons.hyps have [simp]: \"w'=[]\" \n          by (cases w') (auto simp: none_ga_en_eq some_ga_en_eq) \n        show ?thesis apply (rule cons.prems[of \"[]\" \"Suc n\"]) by simp\n      next\n        case (Some aa)\n        note Some[simp]\n        show ?thesis apply (rule cons.prems[of \"aa#w'\" n]) by simp\n      qed\n    qed\n\n    lemma proj_reachable_to_cfgE:\n      assumes R: \"gc\\<in>jsys.nodes\"\n      assumes PIDV: \"pid_valid gc pid\"\n      shows \"\\<exists>c0\\<in>cfgc_V0. (c0,cmd_of_pid gc pid)\\<in>cfgc_E\\<^sup>*\"\n    proof -\n      from R obtain w where \n        WF: \"jsys.path w pid_init_gc\"\n        and EX: \"fold ga_ex w (pid_init_gc) = gc\"\n        by rule auto\n      from words_fin_None_fmt[OF WF] obtain w' n where \n        [simp]: \"w = map Some w'@replicate n None\" .\n\n      from EX have \"fold ga_ex (map Some w') (pid_init_gc) = gc\" \n        by simp  \n      hence EX': \"fold ga_gex w' (pid_init_gc) = gc\"\n        by (simp add: fold_map some_ga_ex_eq)\n\n      from WF have WF': \"jsys.path (map Some w') pid_init_gc\" \n        by auto\n        \n      from proj_word_fin_to_cfg_E[OF WF' EX', of pid] have\n        G: \"(cmd_of_pid (pid_init_gc) pid,cmd_of_pid gc pid) \\<in> cfgc_E\\<^sup>*\"\n        by (rule set_rev_mp[OF _ rtrancl_mono]) auto\n        \n      show ?thesis proof (cases \"pid_valid (pid_init_gc) pid\")\n        case True \n        hence \"cmd_of_pid (pid_init_gc) pid \\<in> cfgc_V0\"\n          by (auto simp: cfgc_V0_def cfg_V0_def pid_init_gc_def init_pc_def)\n        with G show ?thesis ..\n      next\n        case False \n        hence \"\\<not>pid_valid gc pid\"\n          unfolding EX[symmetric] by simp \n        with PIDV have False by blast thus ?thesis ..\n      qed\n    qed\n\n    lemma proj_ne_word_fin_to_cfg_E:\n      assumes WF: \"jsys.path (map Some w) gc\"\n      assumes EX: \"fold ga_gex w gc = gc'\"\n      assumes [simp]: \"w=(pid,cac)#w'\" (is \"w=?ga#_\")\n      shows \"(cmd_of_pid gc pid, cmd_of_pid gc' pid) \n        \\<in> (cfgc_E \\<inter> (\\<lambda>(_,c,_,c'). (c,c'))`set w)\\<^sup>+\" (is \"_\\<in>?E\\<^sup>+\")\n    proof -\n      from WF EX have \n        EN: \"?ga \\<in> ga_gen gc\" and\n        WF': \"jsys.path (map Some w') (ga_gex ?ga gc)\" and\n        EX': \"fold ga_gex w' (ga_gex ?ga gc) = gc'\"\n        by (auto simp: some_ga_en_eq some_ga_ex_eq)\n\n      obtain c a c' where [simp]: \"cac = (c,a,c')\" by (cases cac)\n\n      from EN have \"(pid,c,a,c')\\<in>ga_gen gc\" by simp\n      from ga_gen_cmd_cfg[OF this] \n      have \"(cmd_of_pid gc pid, cmd_of_pid (ga_gex ?ga gc) pid) \\<in> ?E\" \n        by auto\n      also from proj_word_fin_to_cfg_E[OF WF' EX'] \n      have \"(cmd_of_pid (ga_gex ?ga gc) pid, cmd_of_pid gc' pid) \\<in> ?E\\<^sup>*\"\n        apply (rule set_rev_mp[OF _ rtrancl_mono])\n        by auto\n      finally (rtrancl_into_trancl2) show ?thesis .\n    qed\n\n  end\n\n  locale sticky_prog = visible_prog +\n    fixes sticky_E\n    assumes sticky_E_fas: \"is_fas cfgc_G sticky_E\"  \n    assumes sticky_E_vis: \"vis_edges \\<subseteq> sticky_E\"\n  begin\n\n    definition \"sticky_ga \\<equiv> Collect (\n      \\<lambda>None \\<Rightarrow> True \n    | Some (pid,c,a,c') \\<Rightarrow> (c,c')\\<in>sticky_E)\"\n\n    lemma sticky_ga_approx_visible: \"jsys.visible \\<subseteq> sticky_ga\"\n    proof -\n      have aux: \"\\<And>s s'. sm_props s \\<noteq> sm_props s' \\<Longrightarrow> s \\<noteq> s'\"\n        by auto\n\n      show ?thesis\n        apply (clarsimp simp: sticky_ga_def split: option.split)\n        apply (rule set_mp[OF sticky_E_vis])\n        apply (clarsimp \n          elim!: jsys.visibleE \n          simp: sticky_ga_def\n          split: option.split)\n        apply (clarsimp \n          split: prod.splits\n          simp: ga_en_def ga_gen_def ga_ex_def ga_gex_def\n          simp: pid_interp_gc_def interp_gs_def\n          simp: vis_edges_def)\n        apply (intro exI conjI, assumption) \n        apply (drule ex_mod_limit)\n        \n        apply (drule aux)\n        apply (fastforce simp: eq_on_def restrict_map_def)\n        done\n    qed  \n\n    lemma sticky_ga_breaks_cycles:\n      assumes \"gc\\<in>jsys.nodes\"\n      assumes \"w\\<in>jsys.cycles gc\"\n      assumes \"w\\<noteq>[]\"\n      shows \"set w \\<inter> sticky_ga \\<noteq> {}\"\n    proof (cases \"None \\<in> set w\")\n      case True\n      thus ?thesis\n        by (auto simp: sticky_ga_def)\n    next\n      case False\n      then obtain w' where [simp]: \"w=map Some w'\"\n        by (auto simp: none_notin_set_map_Some_conv)\n\n      have aux1: \"Some ` set w' \\<inter> sticky_ga \n        = Some ` (set w' \\<inter> {(pid,c,a,c'). (c,c')\\<in>sticky_E})\"\n        by (auto simp: sticky_ga_def)\n  \n\n      show ?thesis \n      proof (cases \"\\<exists>(pid,c,a,c')\\<in>set w'. (c,c')\\<in>sticky_E\")\n        case True thus ?thesis by (auto simp: aux1)\n      next  \n        case False \n        let ?E = \"(cfgc_E \\<inter> (\\<lambda>(_, c, _, c'). (c, c')) ` set w')\"\n\n        from False have NO_STICKY: \"?E \\<inter> sticky_E = {}\" by auto\n\n        from \\<open>w\\<noteq>[]\\<close> obtain pid cac w'' where W'_FMT[simp]: \"w'=(pid,cac)#w''\"\n          by (auto simp: neq_Nil_conv)\n\n        from \\<open>w\\<in>jsys.cycles gc\\<close> have PIDV: \"pid_valid gc pid\"\n          by (auto simp: pid_valid_ga_en)\n\n        have \"(cmd_of_pid gc pid, cmd_of_pid gc pid)\\<in> ?E\\<^sup>+\"\n          apply (rule proj_ne_word_fin_to_cfg_E[OF _ _ W'_FMT])\n          using \\<open>w\\<in>jsys.cycles gc\\<close>\n          by (auto simp: fold_map some_ga_ex_eq)\n        hence CYC: \"(cmd_of_pid gc pid, cmd_of_pid gc pid) \\<in> (cfgc_E-sticky_E)\\<^sup>+\"\n          apply (rule trancl_mono)\n          using NO_STICKY by blast\n\n        from proj_reachable_to_cfgE[OF \\<open>gc\\<in>jsys.nodes\\<close> PIDV] obtain\n          c0 where C0: \"c0\\<in>cfgc_V0\" and REACH: \"(c0,cmd_of_pid gc pid)\\<in>cfgc_E\\<^sup>*\" ..\n\n        from CYC C0 REACH sticky_E_fas[unfolded is_fas_def]\n          have False by force\n        thus ?thesis ..\n      qed\n    qed\n      \n    sublocale jsys: transition_system_sticky \n      ga_ex \"\\<lambda> a p. a \\<in> ga_en p\" \"\\<lambda> p. p = pid_init_gc\" pid_interp_gc sticky_ga\n      apply unfold_locales\n      using sticky_ga_breaks_cycles apply blast\n      using sticky_ga_approx_visible apply blast\n      done\n\n    sublocale jsys: transition_system_ample ga_ex \"\\<lambda> a p. a \\<in> ga_en p\" \"\\<lambda> p. p = pid_init_gc\"\n      pid_interp_gc sticky_ga ind\n      by unfold_locales\n\n  end\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/CAVA_LTL_Modelchecker/SM/Analysis/SM_Sticky.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982179521102, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.2911157477670754}}
{"text": "theory ExclLemma\n  imports RedSafeCV ProcCVars ProcDef\nbegin\n  \ndefinition can_access where\n  \"can_access e x = (x \\<in> ref_vars e)\"\n  \n  (*thm proper_exp_def*)\n  \nlemma well_typed_deref_ex: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; Loc x \\<notin> res_vars e; x \\<in> ref_vars e \\<rbrakk> \\<Longrightarrow> (\\<exists> z. (z, x) \\<in> own_pairs e)\"    \n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n        apply (auto)\n    (* var case *)\n         apply (case_tac xa)\n           apply (auto)\n    (* pair case. *)\n        apply (blast)\n       apply (blast)\n    (* if case. *)\n      apply (blast)\n     apply (blast)\n    apply (blast)\n    (* lam case. *)\n   apply (blast)\n    (* app case. *)\n  apply (blast)\n  done\n \nlemma well_typed_deref_ref_use: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; (x, y) \\<in> own_pairs e \\<rbrakk> \\<Longrightarrow> x \\<in> ref_vars e\"     \n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n        apply (auto)\n    (* var case *)\n      apply (case_tac xa)\n        apply (auto)\n    (* other cases. *)  \n     apply (blast)\n    apply (blast)\n   apply (blast)\n  apply (blast)\n  done\n    \nlemma well_typed_deref_npv_use: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; (x, y) \\<in> own_pairs e \\<rbrakk> \\<Longrightarrow> Loc x \\<in> non_prim_vars env e\"  \n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n        apply (auto)\n    (* var case *)\n          apply (case_tac xa)\n            apply (auto)\n          apply (simp add: non_prim_vars_def)\n          apply (simp add: non_prim_entry_def)\n    (* other cases. *)\n         apply (simp add: non_prim_vars_def)\n        apply (simp add: non_prim_vars_def)\n       apply (simp add: non_prim_vars_def)\n      apply (simp add: non_prim_vars_def)\n     apply (simp add: non_prim_vars_def)\n    apply (simp add: non_prim_vars_def)\n    (* lam case *)\n    apply (simp add: non_prim_entry_def)\n    apply (case_tac \"\\<exists> t. add_env env (Var x1a) t1 (Loc x) = Some t \\<and> req_type t \\<noteq> Prim\")\n     apply (simp add: add_env_def)\n    apply (auto)\n    (* app case *)\n   apply (simp add: non_prim_vars_def)\n  apply (simp add: non_prim_vars_def)\n  done\n    \nfun in_path where\n  \"in_path x [] = False\"\n| \"in_path x (y # t) = (x = y \\<or> in_path x t)\"  \n  \n  \n    (* if x \\<leadsto> z and y \\<leadsto> z, and x is in the path from y \\<leadsto> z, then y \\<leadsto> a \\<leadsto> x \\<leadsto> z *)\nlemma path_lookup_cross_ih: \"\\<lbrakk> path_lookup rs_map x l z; in_path x m; path_lookup rs_map y m z \\<rbrakk> \\<Longrightarrow>\n  (\\<exists> a m'. path_lookup rs_map y m' a \\<and> nres_lookup rs_map a (Loc x) \\<noteq> NoPerm \\<and> path_lookup rs_map x l z \\<and> (a = y \\<or> in_path a m))\"\n  apply (induct m arbitrary: y)  \n   apply (auto)\n    (* case where x = a (the top of the path) *)\n   apply (case_tac \"rs_map y\")\n    apply (auto)\n   apply (rule_tac x=\"y\" in exI)\n   apply (auto)\n    apply (rule_tac x=\"[]\" in exI)\n    apply (simp)\n   apply (simp add: nres_lookup_def)\n    (* inductive case *)\n  apply (case_tac \"rs_map y\")\n   apply (auto)\n  apply (case_tac \"\\<exists>b. (\\<exists>m'. path_lookup rs_map a m' b) \\<and> nres_lookup rs_map b (Loc x) \\<noteq> NoPerm \\<and> (b = a \\<or> in_path b m)\")\n   apply (erule_tac exE)\n   apply (auto)\n   apply (rule_tac x=\"a\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"[a]\" in exI)\n   apply (auto)\n  apply (rule_tac x=\"b\" in exI)\n  apply (auto)\n   apply (rule_tac x=\"a # m'\" in exI)\n  apply (auto)\n  done\n    \nlemma lookup_in_path: \"\\<lbrakk> in_path z l; path_lookup rs_map x l y \\<rbrakk> \\<Longrightarrow> (\\<exists> a. nres_lookup rs_map a (Loc z) \\<noteq> NoPerm)\"    \n  apply (induct l arbitrary: x)\n   apply (auto)\n   apply (case_tac \"rs_map x\")\n    apply (auto)\n   apply (simp add: nres_lookup_def)\n   apply (rule_tac x=\"x\" in exI)\n   apply (auto)\n  apply (case_tac \"rs_map x\")\n   apply (auto)\n  done\n  \nlemma end_in_path: \"\\<lbrakk> x \\<noteq> y; path_lookup rs_map x l y \\<rbrakk> \\<Longrightarrow> in_path y l\"    \n  apply (induct l arbitrary: x)\n   apply (auto)\n  apply (case_tac \"rs_map x\")\n   apply (auto)\n  apply (case_tac \"a = y\")\n   apply (auto)\n  done\n    \n    (* if x \\<leadsto> z and y \\<leadsto> z, then x \\<leadsto> a \\<leadsto> c \\<leadsto> z, and y \\<leadsto> b \\<leadsto> c \\<leadsto> z, a \\<noteq> b *)\nlemma path_lookup_cross: \"\\<lbrakk> x \\<noteq> y; \\<not> in_path x m; \\<not> in_path y l; path_lookup rs_map x l z; path_lookup rs_map y m z \\<rbrakk> \\<Longrightarrow>\n  (\\<exists> a b c l' m' lx. a \\<noteq> b \\<and> path_lookup rs_map x l' a \\<and> path_lookup rs_map y m' b \\<and>\n    nres_lookup rs_map a (Loc c) \\<noteq> NoPerm \\<and> nres_lookup rs_map b (Loc c) \\<noteq> NoPerm \\<and> path_lookup rs_map c lx z)\"\n    (* we induct over the l, attempting to apply the induction lemma, when x is in_path m *)\n  apply (induct l arbitrary: x)\n   apply (auto)\n    (* empty list case is impossible, since z must be in m *)\n   apply (cut_tac y=\"z\" and l=\"m\" in end_in_path)\n     apply (auto)\n  apply (case_tac \"rs_map x\")\n   apply (auto)\n    (* if a is in_path m, by lemma we can get y \\<leadsto> ? \\<leadsto> a \\<leadsto> z. we can select x \\<leadsto> x \\<leadsto> a \\<leadsto> z, y \\<leadsto> ? \\<leadsto> a \\<leadsto> z *)\n  apply (case_tac \"in_path a m\")\n   apply (case_tac \"\\<not> (\\<exists>aa m'. path_lookup rs_map y m' aa \\<and> nres_lookup rs_map aa (Loc a) \\<noteq> NoPerm \\<and> path_lookup rs_map a l z \\<and> (aa \\<noteq> x))\")\n    apply (cut_tac x=\"a\" and rs_map=\"rs_map\" and l=\"l\" and y=\"y\" and z=\"z\" and m=\"m\" in path_lookup_cross_ih)\n       apply (auto)\n   apply (rule_tac x=\"x\" in exI)\n   apply (rule_tac x=\"aaa\" in exI)\n   apply (auto)\n    apply (rule_tac x=\"[]\" in exI)\n    apply (auto)\n   apply (rule_tac x=\"a\" in exI)\n   apply (simp add: nres_lookup_def)\n   apply (case_tac \"rs_map aaa\")\n    apply (auto)\n    (* otherwise, we can induct. *)\n  apply (case_tac \"\\<exists>a' b. a' \\<noteq> b \\<and> (\\<exists>l'. path_lookup rs_map a l' a') \\<and>\n                          (\\<exists>m'. path_lookup rs_map y m' b) \\<and>\n                          (\\<exists>c. nres_lookup rs_map a' (Loc c) \\<noteq> NoPerm \\<and> nres_lookup rs_map b (Loc c) \\<noteq> NoPerm \\<and> (\\<exists>lx. path_lookup rs_map c lx z))\")\n   apply (erule_tac exE)\n   apply (auto)\n    (* - we take x \\<leadsto> a' \\<leadsto> c \\<leadsto> z, y \\<leadsto> b \\<leadsto> c \\<leadsto> z *)\n  apply (rule_tac x=\"a'\" in exI)\n  apply (rule_tac x=\"b\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"a # l'\" in exI)\n  apply (auto)\n  done\n    \ndefinition close_dom_use_env where\n  \"close_dom_use_env env rs_map e = (\\<lambda> x. if x \\<in> { Loc x | x. \\<exists> l z. Loc z \\<in> non_prim_vars env e \\<and> path_lookup rs_map z l x }\n    then OwnPerm else NoPerm)\"\n  \nlemma full_close_dom_use_env: \"\\<lbrakk> well_typed_system env rs_map p_map s p_set; p_set u = Some e \\<rbrakk> \\<Longrightarrow>\n  close_dom_use_env env rs_map e = full_dom_use_env env rs_map e\"\n    (* we want to prove these two definitions are equivalent in a well-typed system *)\n  apply (case_tac \"\\<forall> x. close_dom_use_env env rs_map e x = full_dom_use_env env rs_map e x\")\n   apply (auto)\n  apply (simp add: close_dom_use_env_def)\n  apply (simp add: full_dom_use_env_def)\n  apply (simp add: dom_use_env_def)\n    (* the only part where they would differ would be if x was in the set of non-prim vars, but not in the closure *)\n  apply (case_tac \"\\<exists>xa. x = Loc xa \\<and> (\\<exists>l z. Loc z \\<in> non_prim_vars env e \\<and> path_lookup rs_map z l xa)\")\n   apply (auto)\n  apply (case_tac \"x \\<in> non_prim_vars env e\")\n   apply (auto)\n    (* x cannot be a var since the env is contained in the state *)\n  apply (case_tac x)\n   apply (auto)\n   apply (simp add: well_typed_system_def)\n   apply (simp add: well_typed_state_def)\n   apply (simp add: sub_env_def)\n   apply (simp add: non_prim_vars_def)\n   apply (simp add: non_prim_entry_def)\n   apply (auto)\n    (* since x is a location, we need only demonstrate a path to it. it should lead to itself *)\n  apply (erule_tac x=\"[]\" in allE)\n  apply (erule_tac x=\"x2\" in allE)\n  apply (auto)\n  done\n    \nlemma wts_excl_dom_use_env: \"\\<lbrakk> well_typed_system env rs_map p_map s p_set; u \\<noteq> v; p_set u = Some e; p_set v = Some e';\n  p_map u = Some r_sa; p_map v = Some r_sb; well_typed env r_sa e UnitTy r_se r_xe; well_typed env r_sb e' UnitTy r_se' r_xe' \\<rbrakk> \\<Longrightarrow>\n  strong_disj_use_env (full_dom_use_env env rs_map e) (full_dom_use_env env rs_map e')\"\n    (* first, we use a weaker definition of dominator, to cancel out some edge cases *)\n  apply (rule_tac t=\"full_dom_use_env env rs_map e\" and s=\"close_dom_use_env env rs_map e\" in subst)\n   apply (simp add: full_close_dom_use_env)\n  apply (rule_tac t=\"full_dom_use_env env rs_map e'\" and s=\"close_dom_use_env env rs_map e'\" in subst)\n   apply (simp add: full_close_dom_use_env)\n    (* if they are not disjoint, there is some z \\<leadsto> xa, za \\<leadsto> x *)\n  apply (simp add: strong_disj_use_env_def)\n  apply (auto)\n  apply (simp add: close_dom_use_env_def)\n  apply (auto)\n  apply (case_tac \"\\<exists>l z. Loc z \\<in> non_prim_vars env e' \\<and> path_lookup rs_map z l xa\")\n   apply (auto)\n    (* we can establish r_sa z \\<noteq> None, and r_sb za \\<noteq> None *)\n  apply (case_tac \"r_sa (Loc z) = NoPerm\")\n   apply (cut_tac x=\"Loc z\" and ?r_s1.0=\"r_sa\" and e=\"e\" in well_typed_no_npv_use)\n     apply (auto)\n  apply (case_tac \"r_sb (Loc za) = NoPerm\")    \n   apply (cut_tac x=\"Loc za\" and ?r_s1.0=\"r_sb\" and e=\"e'\" in well_typed_no_npv_use)\n     apply (auto)\n    (* if z = za, we have a contradiction by map exclusion. *)\n  apply (case_tac \"z = za\")\n   apply (case_tac \"\\<not> disj_nres_map p_map\")\n    apply (simp add: well_typed_system_def)\n    apply (simp add: well_typed_proc_set_def)\n   apply (simp add: disj_nres_map_def)\n   apply (erule_tac x=\"u\" in allE)\n   apply (erule_tac x=\"v\" in allE)\n   apply (auto)\n   apply (simp add: strong_disj_use_env_def)\n   apply (erule_tac x=\"Loc za\" in allE)\n   apply (simp add: nres_lookup_def)\n    (* if za is in l, we have a contradiction by map separation. *)\n  apply (case_tac \"in_path za l\")\n   apply (simp add: well_typed_system_def)\n   apply (auto)\n   apply (erule_tac x=\"v\" in allE)\n   apply (auto)\n   apply (cut_tac rs_map=\"rs_map\" and z=\"za\" and l=\"l\" in lookup_in_path)\n     apply (auto)\n   apply (simp add: sep_nres_map_def)\n   apply (erule_tac x=\"a\" in allE)\n   apply (simp add: strong_disj_use_env_def)\n   apply (erule_tac x=\"Loc za\" in allE)\n   apply (auto)\n    (* similarly, we can show z is not in la *)\n  apply (case_tac \"in_path z la\")\n   apply (simp add: well_typed_system_def)\n   apply (auto)\n   apply (erule_tac x=\"u\" in allE)\n   apply (auto)\n   apply (cut_tac rs_map=\"rs_map\" and z=\"z\" and l=\"la\" in lookup_in_path)\n     apply (auto)\n   apply (simp add: sep_nres_map_def)\n   apply (erule_tac x=\"a\" in allE)\n   apply (simp add: strong_disj_use_env_def)\n   apply (erule_tac x=\"Loc z\" in allE)\n   apply (auto)\n    (* otherwise we should be able to find a, b, c where z \\<leadsto> a \\<leadsto> c \\<leadsto> xa and za \\<leadsto> b \\<leadsto> c \\<leadsto> xa*)\n  apply (cut_tac rs_map=\"rs_map\" and x=\"z\" and y=\"za\" and z=\"xa\" in path_lookup_cross)\n       apply (auto)\n    (* this is a contradiction by res map exclusion on the maps of a + b containing c *)\n  apply (case_tac \"\\<not> disj_nres_map rs_map\")\n   apply (simp add: well_typed_system_def)\n   apply (simp add: well_typed_state_def)\n   apply (simp add: valid_nres_map_def)\n  apply (simp add: disj_nres_map_def)\n  apply (erule_tac x=\"a\" in allE)\n  apply (erule_tac x=\"b\" in allE)\n  apply (auto)\n  apply (simp add: strong_disj_use_env_def)\n  apply (erule_tac x=\"Loc c\" in allE)\n  apply (auto)\n  done\n    \n    \nlemma well_typed_no_dom_use: \"\\<lbrakk> well_typed_state s env rs_map; p_set u = Some e; p_map u = Some r_s;\n  well_typed env r_s e UnitTy r_se r_xe; x \\<in> ref_vars e; proper_exp rs_map e \\<rbrakk> \\<Longrightarrow> full_dom_use_env env rs_map e (Loc x) \\<noteq> NoPerm\"\n    (* res_var case. in this case it is in the dominator since it is non-prim *)\n  apply (case_tac \"Loc x \\<in> res_vars e\")\n   apply (case_tac \"env (Loc x) = None\")\n    apply (cut_tac env=\"env\" and x=\"x\" and e=\"e\" in well_typed_rv_env_use)\n      apply (auto)\n   apply (case_tac \"Loc x \\<notin> non_prim_vars env e\")\n    apply (cut_tac s=\"s\" and env=\"env\" and rs_map=\"rs_map\" in wts_mem_val_env)\n     apply (simp)\n    apply (simp add: mem_val_env_def)\n    apply (erule_tac x=\"Loc x\" in allE)\n    apply (auto)\n    apply (simp add: non_prim_vars_def)\n    apply (simp add: non_prim_entry_def)\n    apply (case_tac y)\n          apply (auto)\n   apply (simp add: full_dom_use_env_def)\n   apply (simp add: dom_use_env_def)(*\n   apply (case_tac \"\\<exists> l z. z \\<in> non_prim_vars env e \\<and> path_lookup rs_map z l x\")\n    apply (auto)\n   apply (erule_tac x=\"[]\" in allE)\n   apply (erule_tac x=\"x\" in allE)\n   apply (auto)*)\n    (* otherwise, we presume that it has an owner with permissions in r_s. since e is proper, there is a lookup between them *)\n  apply (cut_tac x=\"x\" and e=\"e\" in well_typed_deref_ex)\n     apply (auto)\n  apply (simp add: proper_exp_def)\n  apply (erule_tac x=\"z\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (simp add: full_dom_use_env_def)\n  apply (simp add: dom_use_env_def)\n  apply (case_tac \"\\<exists> l z. Loc z \\<in> non_prim_vars env e \\<and> path_lookup rs_map z l x\")\n   apply (auto)\n  apply (erule_tac x=\"l\" in allE)\n  apply (erule_tac x=\"z\" in allE)\n  apply (auto)\n  apply (cut_tac x=\"z\" and y=\"x\" and e=\"e\" in well_typed_deref_npv_use)\n    apply (auto)\n  done\n    \nlemma excl_safe_lemma: \"\\<lbrakk> well_typed_system env rs_map p_map s p_set; p_set u = Some e; can_access e x;\n  p_set v = Some e'; u \\<noteq> v \\<rbrakk> \\<Longrightarrow> \\<not> can_access e' x\"\n    (* prelim: p_map u + v has an entry *)\n  apply (case_tac \"p_map u = None \\<or> p_map v = None\")\n   apply (simp add: well_typed_system_def)\n   apply (simp add: well_typed_proc_set_def)\n   apply (simp add: full_nres_map_def)\n   apply (auto)\n    apply (erule_tac x=\"u\" in allE)\n    apply (auto)\n   apply (erule_tac x=\"v\" in allE)\n   apply (auto)\n    (* prelim: e must be well-typed + proper *)\n  apply (case_tac \"\\<not> (\\<exists> r_s rx. well_typed env y e UnitTy r_s rx \\<and> proper_exp rs_map e)\")\n   apply (simp add: well_typed_system_def)\n   apply (simp add: well_typed_proc_set_def)\n   apply (auto)\n    apply (erule_tac x=\"u\" in allE)\n    apply (auto)\n   apply (erule_tac x=\"u\" in allE)\n   apply (auto)\n    (* prelim: e' is also well-typed + proper *)\n  apply (case_tac \"\\<not> (\\<exists> r_s rx. well_typed env ya e' UnitTy r_s rx \\<and> proper_exp rs_map e')\")\n   apply (simp add: well_typed_system_def)\n   apply (simp add: well_typed_proc_set_def)\n   apply (auto)\n    apply (erule_tac x=\"v\" in allE)\n    apply (auto)\n   apply (erule_tac x=\"v\" in allE)\n   apply (auto)\n    (* from here, we know that x is in the completion of y + ya *)\n  apply (cut_tac env=\"env\" and rs_map=\"rs_map\" and e=\"e\" and x=\"x\" and r_s=\"y\" and s=\"s\" in well_typed_no_dom_use)\n        apply (auto)\n    apply (simp add: well_typed_system_def)\n   apply (simp add: can_access_def)\n  apply (cut_tac env=\"env\" and rs_map=\"rs_map\" and e=\"e'\" and x=\"x\" and r_s=\"ya\" and s=\"s\" in well_typed_no_dom_use)\n        apply (auto)\n    apply (simp add: well_typed_system_def)\n   apply (simp add: can_access_def)\n    (* this is a contradiction by dominator exlcusion *)\n  apply (cut_tac env=\"env\" and rs_map=\"rs_map\" and e=\"e\" and e'=\"e'\" and u=\"u\" and v=\"v\" and p_map=\"p_map\" and s=\"s\" and\n      p_set=\"p_set\" in wts_excl_dom_use_env)\n          apply (auto)\n  apply (simp add: strong_disj_use_env_def)\n  apply (auto)\n  done\n    \nend", "meta": {"author": "anon-ef", "repo": "perm_lang_ef2", "sha": "0fcb6e4c175193cc7b94f297a8aaa605f502d711", "save_path": "github-repos/isabelle/anon-ef-perm_lang_ef2", "path": "github-repos/isabelle/anon-ef-perm_lang_ef2/perm_lang_ef2-0fcb6e4c175193cc7b94f297a8aaa605f502d711/perm_ref/ExclLemma.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6261241772283034, "lm_q2_score": 0.4649015713733885, "lm_q1q2_score": 0.29108611386830824}}
{"text": "theory Proof_5_5\n  imports Requirements VCTheoryLemmas\nbegin\n\nabbreviation s where \"s s0 requestButton_value \\<equiv> (toEnv (setVarAny s0 requestButton_value)) \"\n\nlemma VC5_R5_aux1: \"toEnvP s2 \\<and> toEnvP s0 \\<and> substate s2 s0 \\<and> toEnvNum s2 s3 < T1 \\<and> s3 = s s0 requestButton_value \\<Longrightarrow>\ntoEnvNum s2 s0 < T1\"\n  apply auto\n  apply(simp split: if_splits)\n  using substate_refl substate_asym[of s0 \"s s0 requestButton_value\"] by  auto\n\nlemma VC5_R5: \"   (toEnvP s0 \\<and>\n        (\\<forall>s1 s2 s3.\n            substate s1 s2 \\<and>\n            substate s2 s3 \\<and>\n            substate s3 s0 \\<and>\n            toEnvP s1 \\<and>\n            toEnvP s2 \\<and>\n            toEnvP s3 \\<and>\n            toEnvNum s1 s2 = Ctrl \\<and>\n            toEnvNum s2 s3 < T1 \\<and> getVarBool s1 minimalRed \\<noteq> NOT_PRESSED \\<and> getVarBool s2 minimalRed = NOT_PRESSED \\<longrightarrow>\n            getVarBool s3 minimalRed = NOT_PRESSED)) \\<and>\n       env (setVarAny s0 requestButton_value) requestButton_value \\<and>\n       getPstate (setVarAny s0 requestButton_value) Ctrl = minimalRed \\<and>\n       \\<not> getVarBool (setVarAny s0 requestButton_value) Ctrl \\<and>\n       \\<not> MINIMAL_RED_TIME_LIMIT \\<le> ltimeEnv (setVarAny s0 requestButton_value) Ctrl \\<Longrightarrow>\n       substate s1 s2 \\<and>\n       substate s2 s3 \\<and>\n       substate s3 (s s0 requestButton_value) \\<and>\n       toEnvP s1 \\<and>\n       toEnvP s2 \\<and>\n       toEnvP s3 \\<and>\n       toEnvNum s1 s2 = Ctrl \\<and>\n       toEnvNum s2 s3 < T1 \\<and> getVarBool s1 minimalRed \\<noteq> NOT_PRESSED \\<and> getVarBool s2 minimalRed = NOT_PRESSED \\<Longrightarrow>\n       getVarBool s3 minimalRed = NOT_PRESSED\"\n  apply(cases \"s3 = s s0 requestButton_value\")\n   apply(cases \"s2 = s s0 requestButton_value\")\n    apply blast\n   apply(rule cut_rl[of \"substate s2 s0\"])\n    apply(rule cut_rl[of \"getVarBool s0 trafficLight = RED\"])\n  apply (metis getVarBool.simps(2) getVarBool.simps(4) getVarBool.simps(6) getVarBool.simps(7) numeral_eq_iff one_eq_numeral_iff semiring_norm(85) semiring_norm(89))\n    apply(drule conjE)\n     prefer 2\n     apply assumption\napply(drule conjE)\n     prefer 2\n     apply assumption\napply(drule conjE)\n     prefer 2\n     apply assumption\napply(drule allE[of _ s1])\n     prefer 2\n  apply assumption\n   apply(drule allE[of _ s2])\n     prefer 2\n     apply assumption \napply(drule allE[of _ s0])\n     prefer 2\n     apply assumption\n    apply(rule cut_rl[of \"toEnvNum s2 s0 < T1\"])\n  using substate_refl apply fast\n    apply((rule VC5_R5_aux1);fast)\n  apply (metis substate.simps(2) substate.simps(4) substate.simps(6) substate.simps(7) toEnvP.simps(4) toEnvP.simps(6) toEnvP.simps(7))\n  apply(rule cut_rl [of \"substate s3 s0\"])\n   apply blast\n  by (metis substate.simps(2) substate.simps(4) substate.simps(6) substate.simps(7) toEnvP.simps(4) toEnvP.simps(6) toEnvP.simps(7))\n\n\ntheorem proof_5_5: \"VC5 R5 s0 requestButton_value\"\n  apply(simp only: VC5_def R5_def)\n  apply(rule impI)\n  apply(rule conjI)\n   apply simp\n  apply((rule allI);(rule allI);(rule allI))\n  apply(rule impI)\n  by ((rule VC5_R5);assumption)\n  ", "meta": {"author": "ivchernenko", "repo": "post_vcgenerator", "sha": "fadfff131086870a027d6bd1c78b8d5a3baf183b", "save_path": "github-repos/isabelle/ivchernenko-post_vcgenerator", "path": "github-repos/isabelle/ivchernenko-post_vcgenerator/post_vcgenerator-fadfff131086870a027d6bd1c78b8d5a3baf183b/case-studies/trafficLights/Proof_5_5.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.658417500561683, "lm_q2_score": 0.44167300566462553, "lm_q1q2_score": 0.2908052364552688}}
{"text": "theory SC_Depth_Limit\nimports SC_Sema SC_Depth\nbegin\n  \nlemma SC_completeness: \"\\<Turnstile> \\<Gamma> \\<Rightarrow> \\<Delta> \\<Longrightarrow> \\<Gamma> \\<Rightarrow> \\<Delta> \\<down> sequent_cost \\<Gamma> \\<Delta>\"\nproof(induction \"sequent_cost \\<Gamma> \\<Delta>\" arbitrary: \\<Gamma> \\<Delta>)\n  case 0 hence False by(simp add: sequent_cost_def) thus ?case by clarify\nnext\n  case (Suc n)\n  from Suc(3) show ?case\n    using SCc.cases[OF Suc.hyps(1)]\noops\ntext\\<open>Making this proof of completeness go through should be possible,\n  but finding the right way to split the cases could get verbose.\nThe variant with the search procedure is a lot more elegant.\\<close>\n  \n\nlemma sc_sim_depth:\n  assumes \"sc \\<Gamma> A \\<Delta> B = {}\"\n  shows \"image_mset Atom (mset A) + mset \\<Gamma> \\<Rightarrow> image_mset Atom (mset B) + mset \\<Delta> \\<down> sum_list (map size (\\<Gamma>@\\<Delta>)) + (if set A \\<inter> set B = {} then 0 else 1)\"\nproof -\n  have [simp]: \"image_mset Atom (mset A) \\<Rightarrow> image_mset Atom (mset B) \\<down> Suc 0\" (is ?k) if \"set A \\<inter> set B \\<noteq> {}\" for A B \n  proof -\n    from that obtain a where \"a \\<in> set A\" \"a \\<in> set B\" by blast\n    thus ?k by(force simp: in_image_mset intro: SCc.Ax[where k=a])\n  qed\n  note SCc.intros(3-)[intro]\n  have [elim!]: \"\\<Gamma> \\<Rightarrow> \\<Delta> \\<down> n \\<Longrightarrow> n \\<le> m \\<Longrightarrow> \\<Gamma> \\<Rightarrow> \\<Delta> \\<down> m\" for \\<Gamma> \\<Delta> n m using dec_induct by(fastforce elim!: deeper_suc) (* sledgehammer is flippin' using induction. *)\n  from assms show ?thesis\n    by(induction \\<Gamma> A \\<Delta> B rule: sc.induct)\n      (auto\n      simp add: list_sequent_cost_def add.assoc deeper_suc weakenR'\n      split: if_splits option.splits)\nqed\n\ncorollary sc_depth_complete:\n  assumes s: \"\\<Turnstile> \\<Gamma> \\<Rightarrow> \\<Delta>\"\n  shows \"\\<Gamma> \\<Rightarrow> \\<Delta> \\<down> sum_mset (image_mset size (\\<Gamma>+\\<Delta>))\"\nproof -\n  obtain \\<Gamma>' \\<Delta>' where p: \"\\<Gamma> = mset \\<Gamma>'\" \"\\<Delta> = mset \\<Delta>'\" by (metis ex_mset)\n  with s have sl: \"\\<Turnstile> mset \\<Gamma>' \\<Rightarrow> mset \\<Delta>'\" by simp\n  let ?d = \"sum_mset (image_mset size (\\<Gamma>+\\<Delta>))\"\n  have d: \"?d = sum_list (map size (\\<Gamma>'@\\<Delta>'))\"\n    unfolding p by (metis mset_append mset_map sum_mset_sum_list)\n  have \"mset \\<Gamma>' \\<Rightarrow> mset \\<Delta>' \\<down> ?d\"\n  proof cases\n    assume \"sc \\<Gamma>' [] \\<Delta>' [] = {}\"\n    from sc_sim_depth[OF this] show \"mset \\<Gamma>' \\<Rightarrow> mset \\<Delta>' \\<down> ?d\" unfolding d by auto\n  next\n    assume \"sc \\<Gamma>' [] \\<Delta>' [] \\<noteq> {}\"\n    with SC_counterexample have \"\\<not> \\<Turnstile> mset \\<Gamma>' \\<Rightarrow> mset \\<Delta>'\" by fastforce\n    moreover note s[unfolded p]\n    ultimately have False ..\n    thus \"mset \\<Gamma>' \\<Rightarrow> mset \\<Delta>' \\<down> ?d\" ..\n  qed\n  thus ?thesis unfolding p .\nqed\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Propositional_Proof_Systems/SC_Depth_Limit.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5813030906443133, "lm_q2_score": 0.5, "lm_q1q2_score": 0.29065154532215665}}
{"text": "(******************************************************************************)\n(* Project: The Isabelle/UTP Proof System                                     *)\n(* File: utp_circus_tutorial_ex.thy                                           *)\n(* Authors: Frank Zeyda and Simon Foster (University of York, UK)             *)\n(* Emails: frank.zeyda@york.ac.uk and simon.foster@york.ac.uk                 *)\n(******************************************************************************)\n\nsection {* {\\Circus} Tutorial *}\n\ntheory utp_circus_tutorial_ex\nimports \"../theories/utp_circus\" Transitive_Closure\nbegin recall_syntax\n\nsubsection {* Preliminaries *}\n\nno_translations\n  \"a \\<^bold>\\<rightarrow> P\" == \"CONST PrefixCSP \\<guillemotleft>a\\<guillemotright> P\"\n\ntranslations\n  \"a \\<^bold>\\<rightarrow> P\" == \"CONST PrefixCSP \\<guillemotleft>a()\\<guillemotright> P\"\n\ntext \\<open>Hints for the tutorial exercise.\\<close>\n\nconsts COMPLETE :: \"'a\" (\"\\<^bold>C\\<^bold>O\\<^bold>M\\<^bold>P\\<^bold>L\\<^bold>E\\<^bold>T\\<^bold>E\")\n\nparagraph \\<open>Additional proof support\\<close>\n\ndeclare list_concat_minus_list_concat [simp]\n\nlemma list_Cons_minus [simp]:\n\"(x # y) - (x # z) = y - z\"\n  by (simp add: minus_list_def)\n\nsubsection {* Time Types *}\n\ntext \\<open>Below we define synonyms for the types \\<open>TIME\\<close> and \\<open>PERIOD\\<close>.\\<close>\n\ntype_synonym TIME   = \"nat\"\ntype_synonym PERIOD = \"nat\"\n\nsubsection {* Channel Declarations *}\n\ndatatype timer_evt =\n  setT \"TIME\" |\n  updateSS \"PERIOD\" |\n  step \"TIME \\<times> PERIOD\" |\n  endc \"unit\"\n\nabbreviation timer_prefix ::\n  \"('a, timer_evt) chan \\<Rightarrow>\n   ('a, timer_evt + 'ext) chan\" where\n\"timer_prefix c \\<equiv> Inl o c\"\n\nnotation timer_prefix (\"tm:_\" [1000] 1000)\n\nabbreviation \"tm_events \\<equiv>\n  \\<epsilon>(tm:setT) \\<union> \\<epsilon>(tm:updateSS) \\<union> \\<epsilon>(tm:step) \\<union> \\<epsilon>(tm:endc)\"\n\nsubsection {* Process Definition *}\n\nalphabet timer_state =\n  currentTime :: \"TIME\"\n  stepSize :: \"PERIOD\"\n\ntype_synonym timer_action =\n  \"(timer_state, timer_evt) action\"\n\ndefinition [rdes]:\n\"process Timer(ct::TIME, hc::PERIOD, tN::TIME) \\<triangleq> begin\n  state(timer_state)\n  Step = (\n    (tm:setT?(t : \\<guillemotleft>t \\<le> tN\\<guillemotright>) \\<^bold>\\<rightarrow> currentTime :=\\<^sub>C \\<guillemotleft>t\\<guillemotright>) \\<box>\n    (tm:updateSS?(ss) \\<^bold>\\<rightarrow> stepSize :=\\<^sub>C \\<guillemotleft>ss\\<guillemotright>) \\<box>\n    \\<^bold>C\\<^bold>O\\<^bold>M\\<^bold>P\\<^bold>L\\<^bold>E\\<^bold>T\\<^bold>E) ;; Step\n  \\<bullet> \\<^bold>C\\<^bold>O\\<^bold>M\\<^bold>P\\<^bold>L\\<^bold>E\\<^bold>T\\<^bold>E\nend\"\n\ntext \\<open>The same process definition using deep variables.\\<close>\n\ndefinition [rdes]:\n\"process DvarTimer(ct::TIME, hc::PERIOD, tN::TIME) \\<triangleq> begin\n  state(vstore)\n  Step = (\n    (tm:setT?(t : \\<guillemotleft>t \\<le> tN\\<guillemotright>) \\<^bold>\\<rightarrow> <currentTime> :=\\<^sub>C \\<guillemotleft>t\\<guillemotright>) \\<box>\n    (tm:updateSS?(ss) \\<^bold>\\<rightarrow> <stepSize> :=\\<^sub>C \\<guillemotleft>ss\\<guillemotright>) \\<box>\n    (tm:step!(&<currentTime>)!(&<stepSize>) \\<^bold>\\<rightarrow>\n      <currentTime> :=\\<^sub>C min\\<^sub>u(&<currentTime> + &<stepSize>, \\<guillemotleft>tN\\<guillemotright>)) \\<box>\n    (&<currentTime> =\\<^sub>u \\<guillemotleft>tN\\<guillemotright>) &\\<^sub>u tm:endc \\<^bold>\\<rightarrow> Stop) ;; Step\n  \\<bullet> (<currentTime>, <stepSize>) :=\\<^sub>C (\\<guillemotleft>ct\\<guillemotright>, \\<guillemotleft>hc\\<guillemotright>) ;; Step\nend\"\n\ntext \\<open>Proof that the @{const Timer} process does not diverge.\\<close>\n\nlemma \"pre\\<^sub>R(Timer(ct, hc, tN)) = true\\<^sub>r\"\n-- \\<open>TODO: try to complete this prove using the @{method rdes_calc} tactic.\\<close>\noops\n\ntext \\<open>Proof about the initial refusal set of the @{const Timer} process.\\<close>\n\ntext \\<open>\n  Simplified encoding of the @{const Timer} process action. The simplification\n  does not consider hiding of the state in the process semantics and neither\n  uses the extensible event type. The @{const setT} communication is slightly\n  more restrictive, requiring \\<open>t < tN\\<close> rather than \\<open>t \\<le> tN\\<close>.\n\\<close>\n\ndefinition StepBody :: \"TIME \\<Rightarrow> timer_action\" where\n\"StepBody tN =\n  (setT?(t : \\<guillemotleft>t\\<guillemotright> <\\<^sub>u \\<guillemotleft>tN\\<guillemotright>) \\<^bold>\\<rightarrow> currentTime :=\\<^sub>C \\<guillemotleft>t\\<guillemotright>) \\<box>\n  (updateSS?(ss) \\<^bold>\\<rightarrow> stepSize :=\\<^sub>C \\<guillemotleft>ss\\<guillemotright>) \\<box>\n  (step!(&currentTime)!(&stepSize) \\<^bold>\\<rightarrow>\n    currentTime :=\\<^sub>C min\\<^sub>u(&currentTime + &stepSize, \\<guillemotleft>tN\\<guillemotright>)) \\<box>\n  (&currentTime =\\<^sub>u \\<guillemotleft>tN\\<guillemotright>) &\\<^sub>u endc \\<^bold>\\<rightarrow> Stop\"\n\nfun MainAction :: \"(TIME \\<times> PERIOD \\<times> TIME) \\<Rightarrow> timer_action\" where\n\"MainAction (ct, hc, tN) =\n  (currentTime, stepSize) :=\\<^sub>C (\\<guillemotleft>ct\\<guillemotright>, \\<guillemotleft>hc\\<guillemotright>) ;; (\\<mu>\\<^sub>C Step \\<bullet> StepBody(tN) ;; Step)\"\n\ntext \\<open>Additional lemma needed for the proof below.\\<close>\n\nlemma wpR_assign [wp]:\n  assumes \"P is NCSP\"\n  shows \"($tr\\<acute> =\\<^sub>u $tr \\<and> \\<lceil>\\<langle>\\<sigma>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>S) wp\\<^sub>R pre\\<^sub>R P = \\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>\\<sigma> \\<dagger> pre\\<^sub>R(P)\"\napply (simp add: wpR_def unrest rdes assms rea_not_not closure usubst)\ndone\n\ntext \\<open>Communications on @{const setT} are initially not refused.\\<close>\n\nlemma StepBody_muI:\n\"[true \\<turnstile> \\<^bold>\\<forall> t \\<bullet> \\<guillemotleft>t\\<guillemotright> <\\<^sub>u \\<guillemotleft>tN\\<guillemotright> \\<and> \\<guillemotleft>trace\\<guillemotright> =\\<^sub>u \\<langle>\\<rangle> \\<Rightarrow> (setT\\<cdot>\\<guillemotleft>t\\<guillemotright>)\\<^sub>u \\<notin>\\<^sub>u \\<guillemotleft>refs\\<guillemotright> | false]\\<^sub>C\n  \\<sqsubseteq> (\\<mu>\\<^sub>C X \\<bullet> StepBody tN ;; X)\"\napply (unfold StepBody_def)\napply (rule CRD_mu_basic_refine)\n-- \\<open>TODO: Can you finalise the rest of the proof?\\<close>\n-- {* Subgoal 1 *}\n-- {* Subgoal 2 *}\n-- {* Subgoal 3 *}\n-- {* Subgoal 4 *}\n-- {* Subgoal 5 *}\noops\n\ntext \\<open>@{const setT} is only enabled when \\<open>t < tN\\<close>.\\<close>\n\nlemma StepBody_muI2:\n\"[true \\<turnstile> \\<^bold>\\<forall> t \\<bullet> \\<guillemotleft>trace\\<guillemotright> =\\<^sub>u \\<langle>(setT\\<cdot>\\<guillemotleft>t\\<guillemotright>)\\<^sub>u\\<rangle> \\<Rightarrow> \\<guillemotleft>t\\<guillemotright> <\\<^sub>u \\<guillemotleft>tN\\<guillemotright> | false]\\<^sub>C\n  \\<sqsubseteq> (\\<mu>\\<^sub>C X \\<bullet> StepBody tN ;; X)\"\napply (unfold StepBody_def)\napply (rule CRD_mu_basic_refine)\n-- {* Subgoal 1 *}\napply (simp add: closure unrest alpha)\n-- {* Subgoal 2 *}\napply (simp add: closure unrest alpha)\n-- {* Subgoal 3 *}\napply (rdes_calc)\n-- {* Subgoal 4 *}\napply (rdes_calc)\napply (rel_simp)\n-- {* Subgoal 5 *}\napply (rdes_calc)\napply (rel_auto)\ndone\n\nlemma StepBody_muI3:\n\"[true \\<turnstile> \\<^bold>\\<forall> (ct, ss) \\<bullet> \\<guillemotleft>ct\\<guillemotright> <\\<^sub>u \\<guillemotleft>tN\\<guillemotright> \\<and>\n    \\<guillemotleft>trace\\<guillemotright> =\\<^sub>u \\<langle>(setT\\<cdot>\\<guillemotleft>ct\\<guillemotright>)\\<^sub>u, (updateSS\\<cdot>\\<guillemotleft>ss\\<guillemotright>)\\<^sub>u\\<rangle> \\<Rightarrow> (step\\<cdot>\\<guillemotleft>(ct, ss)\\<guillemotright>)\\<^sub>u \\<notin>\\<^sub>u \\<guillemotleft>refs\\<guillemotright>\n | false]\\<^sub>C\n \\<sqsubseteq> (\\<mu>\\<^sub>C X \\<bullet> StepBody tN ;; X)\"\napply (unfold StepBody_def)\napply (rule CRD_mu_basic_refine)\n-- {* Subgoal 1 *}\napply (simp add: closure unrest alpha)\n-- {* Subgoal 2 *}\napply (simp add: closure unrest alpha)\n-- {* Subgoal 3 *}\napply (rdes_calc)\n-- {* Subgoal 4 *}\napply (rdes_calc)\napply (rel_simp)\n-- {* Subgoal 5 *}\napply (rdes_calc)\napply (rel_simp)\napply (erule prefixE)\napply (auto)\noops\n\ntext \\<open>A simpler version of \\<open>Timer\\<close> with fewer communications and no recursion.\\<close>\n\ndefinition [rdes]:\n\"process SimpleTimer(ct::TIME, hc::PERIOD, tN::TIME) \\<triangleq> begin\n  state(timer_state)\n  Step = (\n    (step!(&currentTime)!(&stepSize) \\<^bold>\\<rightarrow>\n      currentTime :=\\<^sub>C min\\<^sub>u(&currentTime + &stepSize, \\<guillemotleft>tN\\<guillemotright>)) \\<box>\n    (&currentTime =\\<^sub>u \\<guillemotleft>tN\\<guillemotright>) &\\<^sub>u endc \\<^bold>\\<rightarrow> Stop)\n  \\<bullet> (currentTime, stepSize) :=\\<^sub>C (\\<guillemotleft>ct\\<guillemotright>, \\<guillemotleft>hc\\<guillemotright>) ;; Step\nend\"\n\nlemma\n\"SimpleTimer(ct, hc, tN) \\<sqsubseteq> step!(\\<guillemotleft>ct\\<guillemotright>)!(\\<guillemotleft>hc\\<guillemotright>) \\<^bold>\\<rightarrow> Skip\"\napply (unfold SimpleTimer_def)\napply (unfold circus_syntax)\napply (simp add: Let_def)\napply (rule_tac SRD_refine_intro)\n-- {* Subgoal 1 *}\napply (simp add: closure)\n-- {* Subgoal 2 *}\napply (simp add: closure)\n-- {* Subgoal 3 *}\napply (rdes_calc)\napply (rel_simp)\n-- {* Subgoal 4 *}\napply (rdes_calc)\napply (rel_simp)\napply (erule_tac Q = \"endc () \\<in> ref\\<^sub>v\" in contrapos_pp)\napply (simp) defer\n-- {* Subgoal 4 *}\napply (rdes_calc)\napply (rel_simp)\noops\n\nmethod rdes_refine_auto =\n  (rule_tac SRD_refine_intro;\n    (simp add: closure rdes unrest usubst; (rdes_calc, rel_auto?)))\n\nlemma\n\"ct < tN \\<Longrightarrow> SimpleTimer(ct, hc, tN) \\<sqsubseteq> step!(\\<guillemotleft>ct\\<guillemotright>)!(\\<guillemotleft>hc\\<guillemotright>) \\<^bold>\\<rightarrow> Skip\"\napply (unfold SimpleTimer_def)\napply (unfold circus_syntax)\napply (simp add: Let_def)\napply (rdes_refine_auto)\ndone\n\ntext \\<open>Simpler version of the Timer communicating only on channel @{const step}.\\<close>\n\ndefinition [rdes]: -- \\<open>@{const Timer} with only @{const step} recursion\\<close>\n\"process SimpleTimer2(ct::TIME, hc::PERIOD, tN::TIME) \\<triangleq> begin\n  state(timer_state)\n  Step = (step!(&currentTime)!(&stepSize) \\<^bold>\\<rightarrow>\n    currentTime :=\\<^sub>C min\\<^sub>u(&currentTime + &stepSize, \\<guillemotleft>tN\\<guillemotright>)) ;; Step\n  \\<bullet> (currentTime, stepSize) :=\\<^sub>C (\\<guillemotleft>ct\\<guillemotright>, \\<guillemotleft>hc\\<guillemotright>) ;; Step\nend\"\n\ntext \\<open>Let us try proving something about @{const step} events.\\<close>\n\nlemma \"`peri\\<^sub>R(SimpleTimer2(ct, hc, tN)) \\<and> $tr =\\<^sub>u $tr\\<acute> \\<Rightarrow> \\<guillemotleft>step(ct, hc)\\<guillemotright> \\<notin>\\<^sub>u $ref\\<acute>`\"\napply (rdes_calc)\napply (rel_simp)\napply (erule_tac Q = \"step (ct, hc) \\<in> ref\\<^sub>v\" in contrapos_pp; simp)\napply (subgoal_tac \"currentTime\\<^sub>v' = ct \\<and> stepSize\\<^sub>v' = hc\")\n-- {* Subgoal 1 *}\napply (clarsimp)\n-- {* Subgoal 2 *}\napply (thin_tac \"\\<not> step (currentTime\\<^sub>v', stepSize\\<^sub>v') \\<in> ref\\<^sub>v\")\napply (rename_tac n)\napply (case_tac \"n = 0\")\n-- {* Subgoal 2.1 *}\napply (clarsimp)\n-- {* Subgoal 2.2 *}\napply (clarify)\napply (erule contrapos_pp; simp)\n-- \\<open>@{command sledgehammer}\\<close>\n-- \\<open>We need additional lemmas here to make progress..!\\<close>\noops\n\nlemma nat_one_induct:\n\"0 < n \\<Longrightarrow> (P 1 \\<Longrightarrow> (\\<And>n. P n \\<Longrightarrow> P (Suc n)) \\<Longrightarrow> P n)\"\napply (induction n)\napply (simp_all)\napply (blast)\ndone\n\nlemma tr_in_relpow_grows:\n\"0 < n \\<Longrightarrow>\n  (\\<forall>ok1 ok2 wait1 wait2 (tr1::'\\<epsilon> list) (tr2::'\\<epsilon> list) (st1::'\\<sigma>) (st2::'\\<sigma>)\n    (ref1::'\\<epsilon> set) (ref2::'\\<epsilon> set).\n    (\\<lparr>ok\\<^sub>v = ok1, wait\\<^sub>v = wait1, tr\\<^sub>v = tr1, st\\<^sub>v = st1, ref\\<^sub>v = ref1\\<rparr>,\n     \\<lparr>ok\\<^sub>v = ok2, wait\\<^sub>v = wait2, tr\\<^sub>v = tr2, st\\<^sub>v = st2, ref\\<^sub>v = ref2\\<rparr>) \\<in> r \\<longrightarrow>\n    tr1 < tr2) \\<Longrightarrow>\n  (\\<forall>ok1 ok2 wait1 wait2 (tr1::'\\<epsilon> list) (tr2::'\\<epsilon> list) (st1::'\\<sigma>) (st2::'\\<sigma>)\n    (ref1::'\\<epsilon> set) (ref2::'\\<epsilon> set).\n    (\\<lparr>ok\\<^sub>v = ok1, wait\\<^sub>v = wait1, tr\\<^sub>v = tr1, st\\<^sub>v = st1, ref\\<^sub>v = ref1\\<rparr>,\n     \\<lparr>ok\\<^sub>v = ok2, wait\\<^sub>v = wait2, tr\\<^sub>v = tr2, st\\<^sub>v = st2, ref\\<^sub>v = ref2\\<rparr>) \\<in> (r ^^ n)\n  \\<longrightarrow> tr1 < tr2)\"\napply (erule nat_one_induct)\napply (simp_all)\napply (clarsimp)\napply (case_tac y)\napply (case_tac more)\napply (case_tac morea)\napply (case_tac moreb)\napply (clarsimp)\nusing dual_order.strict_trans by (blast)\n\nlemma empty_trace_neq_relpowI [rule_format]:\n\"0 < n \\<Longrightarrow>\n  (\\<forall>ok1 ok2 wait1 wait2 (tr1::'\\<epsilon> list) (tr2::'\\<epsilon> list) (st1::'\\<sigma>) (st2::'\\<sigma>)\n    (ref1::'\\<epsilon> set) (ref2::'\\<epsilon> set).\n    (\\<lparr>ok\\<^sub>v = ok1, wait\\<^sub>v = wait1, tr\\<^sub>v = tr1, st\\<^sub>v = st1, ref\\<^sub>v = ref1\\<rparr>,\n     \\<lparr>ok\\<^sub>v = ok2, wait\\<^sub>v = wait2, tr\\<^sub>v = tr2, st\\<^sub>v = st2, ref\\<^sub>v = ref2\\<rparr>) \\<in> r \\<longrightarrow>\n    tr1 < tr2) \\<Longrightarrow>\n  (\\<forall>ok1 ok2 wait1 wait2 tr st1 st2 ref1 ref2.\n    (\\<lparr>ok\\<^sub>v = ok1, wait\\<^sub>v = wait1, tr\\<^sub>v = tr, st\\<^sub>v = st1, ref\\<^sub>v = ref1\\<rparr>,\n     \\<lparr>ok\\<^sub>v = ok2, wait\\<^sub>v = wait2, tr\\<^sub>v = tr, st\\<^sub>v = st2, ref\\<^sub>v = ref2\\<rparr>) \\<notin> (r ^^ n))\"\napply (drule_tac tr_in_relpow_grows)\napply (assumption)\napply (clarsimp)\napply (subgoal_tac \"tr < tr\")\napply (clarsimp)\napply (blast)\ndone\n\ntext \\<open>Let us try again with those two lemmas above.\\<close>\n\nlemma \"`peri\\<^sub>R(SimpleTimer2(ct, hc, tN)) \\<and> $tr =\\<^sub>u $tr\\<acute> \\<Rightarrow> \\<guillemotleft>step(ct, hc)\\<guillemotright> \\<notin>\\<^sub>u $ref\\<acute>`\"\napply (rdes_calc)\napply (rel_simp)\napply (erule_tac Q = \"step (ct, hc) \\<in> ref\\<^sub>v\" in contrapos_pp; simp)\napply (subgoal_tac \"currentTime\\<^sub>v' = ct \\<and> stepSize\\<^sub>v' = hc\")\n-- {* Subgoal 1 *}\napply (clarsimp)\n-- {* Subgoal 2 *}\napply (thin_tac \"\\<not> step (currentTime\\<^sub>v', stepSize\\<^sub>v') \\<in> ref\\<^sub>v\")\napply (rename_tac n)\napply (case_tac \"n = 0\")\n-- {* Subgoal 2.1 *}\napply (clarsimp)\n-- {* Subgoal 2.2 *}\napply (clarify)\napply (erule contrapos_pp; simp)\napply (erule empty_trace_neq_relpowI)\napply (clarsimp)\napply (simp add: Prefix_Order.strict_prefixI')\ndone\nend", "meta": {"author": "isabelle-utp", "repo": "utp-main", "sha": "27bdf3aee6d4fc00c8fe4d53283d0101857e0d41", "save_path": "github-repos/isabelle/isabelle-utp-utp-main", "path": "github-repos/isabelle/isabelle-utp-utp-main/utp-main-27bdf3aee6d4fc00c8fe4d53283d0101857e0d41/tutorial/utp_circus_tutorial_ex.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.538983220687684, "lm_q1q2_score": 0.2905029121828687}}
{"text": "(*  Title:      HOL/Auth/Guard/Analz.thy\n    Author:     Frederic Blanqui, University of Cambridge Computer Laboratory\n    Copyright   2001  University of Cambridge\n*)\n\nsection\\<open>Decomposition of Analz into two parts\\<close>\n\ntheory Analz imports Extensions begin\n\ntext\\<open>decomposition of \\<^term>\\<open>analz\\<close> into two parts: \n      \\<^term>\\<open>pparts\\<close> (for pairs) and analz of \\<^term>\\<open>kparts\\<close>\\<close>\n\nsubsection\\<open>messages that do not contribute to analz\\<close>\n\ninductive_set\n  pparts :: \"msg set => msg set\"\n  for H :: \"msg set\"\nwhere\n  Inj [intro]: \"[| X \\<in> H; is_MPair X |] ==> X \\<in> pparts H\"\n| Fst [dest]: \"[| \\<lbrace>X,Y\\<rbrace> \\<in> pparts H; is_MPair X |] ==> X \\<in> pparts H\"\n| Snd [dest]: \"[| \\<lbrace>X,Y\\<rbrace> \\<in> pparts H; is_MPair Y |] ==> Y \\<in> pparts H\"\n\nsubsection\\<open>basic facts about \\<^term>\\<open>pparts\\<close>\\<close>\n\nlemma pparts_is_MPair [dest]: \"X \\<in> pparts H \\<Longrightarrow> is_MPair X\"\nby (erule pparts.induct, auto)\n\nlemma Crypt_notin_pparts [iff]: \"Crypt K X \\<notin> pparts H\"\nby auto\n\nlemma Key_notin_pparts [iff]: \"Key K \\<notin> pparts H\"\nby auto\n\nlemma Nonce_notin_pparts [iff]: \"Nonce n \\<notin> pparts H\"\nby auto\n\nlemma Number_notin_pparts [iff]: \"Number n \\<notin> pparts H\"\nby auto\n\nlemma Agent_notin_pparts [iff]: \"Agent A \\<notin> pparts H\"\nby auto\n\nlemma pparts_empty [iff]: \"pparts {} = {}\"\nby (auto, erule pparts.induct, auto)\n\nlemma pparts_insertI [intro]: \"X \\<in> pparts H \\<Longrightarrow> X \\<in> pparts (insert Y H)\"\nby (erule pparts.induct, auto)\n\nlemma pparts_sub: \"[| X \\<in> pparts G; G \\<subseteq> H |] ==> X \\<in> pparts H\"\nby (erule pparts.induct, auto)\n\nlemma pparts_insert2 [iff]: \"pparts (insert X (insert Y H))\n= pparts {X} Un pparts {Y} Un pparts H\"\nby (rule eq, (erule pparts.induct, auto)+)\n\nlemma pparts_insert_MPair [iff]: \"pparts (insert \\<lbrace>X,Y\\<rbrace> H)\n= insert \\<lbrace>X,Y\\<rbrace> (pparts ({X,Y} \\<union> H))\"\napply (rule eq, (erule pparts.induct, auto)+)\napply (rule_tac Y=Y in pparts.Fst, auto)\napply (erule pparts.induct, auto)\nby (rule_tac X=X in pparts.Snd, auto)\n\nlemma pparts_insert_Nonce [iff]: \"pparts (insert (Nonce n) H) = pparts H\"\nby (rule eq, erule pparts.induct, auto)\n\nlemma pparts_insert_Crypt [iff]: \"pparts (insert (Crypt K X) H) = pparts H\"\nby (rule eq, erule pparts.induct, auto)\n\nlemma pparts_insert_Key [iff]: \"pparts (insert (Key K) H) = pparts H\"\nby (rule eq, erule pparts.induct, auto)\n\nlemma pparts_insert_Agent [iff]: \"pparts (insert (Agent A) H) = pparts H\"\nby (rule eq, erule pparts.induct, auto)\n\nlemma pparts_insert_Number [iff]: \"pparts (insert (Number n) H) = pparts H\"\nby (rule eq, erule pparts.induct, auto)\n\nlemma pparts_insert_Hash [iff]: \"pparts (insert (Hash X) H) = pparts H\"\nby (rule eq, erule pparts.induct, auto)\n\nlemma pparts_insert: \"X \\<in> pparts (insert Y H) \\<Longrightarrow> X \\<in> pparts {Y} \\<union> pparts H\"\nby (erule pparts.induct, blast+)\n\nlemma insert_pparts: \"X \\<in> pparts {Y} \\<union> pparts H \\<Longrightarrow> X \\<in> pparts (insert Y H)\"\nby (safe, erule pparts.induct, auto)\n\nlemma pparts_Un [iff]: \"pparts (G \\<union> H) = pparts G \\<union> pparts H\"\nby (rule eq, erule pparts.induct, auto dest: pparts_sub)\n\nlemma pparts_pparts [iff]: \"pparts (pparts H) = pparts H\"\nby (rule eq, erule pparts.induct, auto)\n\nlemma pparts_insert_eq: \"pparts (insert X H) = pparts {X} Un pparts H\"\nby (rule_tac A=H in insert_Un, rule pparts_Un)\n\nlemmas pparts_insert_substI = pparts_insert_eq [THEN ssubst]\n\nlemma in_pparts: \"Y \\<in> pparts H \\<Longrightarrow> \\<exists>X. X \\<in> H \\<and> Y \\<in> pparts {X}\"\nby (erule pparts.induct, auto)\n\nsubsection\\<open>facts about \\<^term>\\<open>pparts\\<close> and \\<^term>\\<open>parts\\<close>\\<close>\n\nlemma pparts_no_Nonce [dest]: \"[| X \\<in> pparts {Y}; Nonce n \\<notin> parts {Y} |]\n==> Nonce n \\<notin> parts {X}\"\nby (erule pparts.induct, simp_all)\n\nsubsection\\<open>facts about \\<^term>\\<open>pparts\\<close> and \\<^term>\\<open>analz\\<close>\\<close>\n\nlemma pparts_analz: \"X \\<in> pparts H \\<Longrightarrow> X \\<in> analz H\"\nby (erule pparts.induct, auto)\n\nlemma pparts_analz_sub: \"[| X \\<in> pparts G; G \\<subseteq> H |] ==> X \\<in> analz H\"\nby (auto dest: pparts_sub pparts_analz)\n\nsubsection\\<open>messages that contribute to analz\\<close>\n\ninductive_set\n  kparts :: \"msg set => msg set\"\n  for H :: \"msg set\"\nwhere\n  Inj [intro]: \"[| X \\<in> H; not_MPair X |] ==> X \\<in> kparts H\"\n| Fst [intro]: \"[| \\<lbrace>X,Y\\<rbrace> \\<in> pparts H; not_MPair X |] ==> X \\<in> kparts H\"\n| Snd [intro]: \"[| \\<lbrace>X,Y\\<rbrace> \\<in> pparts H; not_MPair Y |] ==> Y \\<in> kparts H\"\n\nsubsection\\<open>basic facts about \\<^term>\\<open>kparts\\<close>\\<close>\n\nlemma kparts_not_MPair [dest]: \"X \\<in> kparts H \\<Longrightarrow> not_MPair X\"\nby (erule kparts.induct, auto)\n\nlemma kparts_empty [iff]: \"kparts {} = {}\"\nby (rule eq, erule kparts.induct, auto)\n\nlemma kparts_insertI [intro]: \"X \\<in> kparts H \\<Longrightarrow> X \\<in> kparts (insert Y H)\"\nby (erule kparts.induct, auto dest: pparts_insertI)\n\nlemma kparts_insert2 [iff]: \"kparts (insert X (insert Y H))\n= kparts {X} \\<union> kparts {Y} \\<union> kparts H\"\nby (rule eq, (erule kparts.induct, auto)+)\n\nlemma kparts_insert_MPair [iff]: \"kparts (insert \\<lbrace>X,Y\\<rbrace> H)\n= kparts ({X,Y} \\<union> H)\"\nby (rule eq, (erule kparts.induct, auto)+)\n\nlemma kparts_insert_Nonce [iff]: \"kparts (insert (Nonce n) H)\n= insert (Nonce n) (kparts H)\"\nby (rule eq, erule kparts.induct, auto)\n\nlemma kparts_insert_Crypt [iff]: \"kparts (insert (Crypt K X) H)\n= insert (Crypt K X) (kparts H)\"\nby (rule eq, erule kparts.induct, auto)\n\nlemma kparts_insert_Key [iff]: \"kparts (insert (Key K) H)\n= insert (Key K) (kparts H)\"\nby (rule eq, erule kparts.induct, auto)\n\nlemma kparts_insert_Agent [iff]: \"kparts (insert (Agent A) H)\n= insert (Agent A) (kparts H)\"\nby (rule eq, erule kparts.induct, auto)\n\nlemma kparts_insert_Number [iff]: \"kparts (insert (Number n) H)\n= insert (Number n) (kparts H)\"\nby (rule eq, erule kparts.induct, auto)\n\nlemma kparts_insert_Hash [iff]: \"kparts (insert (Hash X) H)\n= insert (Hash X) (kparts H)\"\nby (rule eq, erule kparts.induct, auto)\n\nlemma kparts_insert: \"X \\<in> kparts (insert X H) \\<Longrightarrow> X \\<in> kparts {X} \\<union> kparts H\"\nby (erule kparts.induct, (blast dest: pparts_insert)+)\n\nlemma kparts_insert_fst [rule_format,dest]: \"X \\<in> kparts (insert Z H) \\<Longrightarrow>\nX \\<notin> kparts H \\<longrightarrow> X \\<in> kparts {Z}\"\nby (erule kparts.induct, (blast dest: pparts_insert)+)\n\nlemma kparts_sub: \"[| X \\<in> kparts G; G \\<subseteq> H |] ==> X \\<in> kparts H\"\nby (erule kparts.induct, auto dest: pparts_sub)\n\nlemma kparts_Un [iff]: \"kparts (G \\<union> H) = kparts G \\<union> kparts H\"\nby (rule eq, erule kparts.induct, auto dest: kparts_sub)\n\nlemma pparts_kparts [iff]: \"pparts (kparts H) = {}\"\nby (rule eq, erule pparts.induct, auto)\n\nlemma kparts_kparts [iff]: \"kparts (kparts H) = kparts H\"\nby (rule eq, erule kparts.induct, auto)\n\nlemma kparts_insert_eq: \"kparts (insert X H) = kparts {X} \\<union> kparts H\"\nby (rule_tac A=H in insert_Un, rule kparts_Un)\n\nlemmas kparts_insert_substI = kparts_insert_eq [THEN ssubst]\n\nlemma in_kparts: \"Y \\<in> kparts H \\<Longrightarrow> \\<exists>X. X \\<in> H \\<and> Y \\<in> kparts {X}\"\nby (erule kparts.induct, auto dest: in_pparts)\n\nlemma kparts_has_no_pair [iff]: \"has_no_pair (kparts H)\"\nby auto\n\nsubsection\\<open>facts about \\<^term>\\<open>kparts\\<close> and \\<^term>\\<open>parts\\<close>\\<close>\n\nlemma kparts_no_Nonce [dest]: \"[| X \\<in> kparts {Y}; Nonce n \\<notin> parts {Y} |]\n==> Nonce n \\<notin> parts {X}\"\nby (erule kparts.induct, auto)\n\nlemma kparts_parts: \"X \\<in> kparts H \\<Longrightarrow> X \\<in> parts H\"\nby (erule kparts.induct, auto dest: pparts_analz)\n\nlemma parts_kparts: \"X \\<in> parts (kparts H) \\<Longrightarrow> X \\<in> parts H\"\nby (erule parts.induct, auto dest: kparts_parts\nintro: parts.Fst parts.Snd parts.Body)\n\nlemma Crypt_kparts_Nonce_parts [dest]: \"[| Crypt K Y \\<in> kparts {Z};\nNonce n \\<in> parts {Y} |] ==> Nonce n \\<in> parts {Z}\"\nby auto\n\nsubsection\\<open>facts about \\<^term>\\<open>kparts\\<close> and \\<^term>\\<open>analz\\<close>\\<close>\n\nlemma kparts_analz: \"X \\<in> kparts H \\<Longrightarrow> X \\<in> analz H\"\nby (erule kparts.induct, auto dest: pparts_analz)\n\nlemma kparts_analz_sub: \"[| X \\<in> kparts G; G \\<subseteq> H |] ==> X \\<in> analz H\"\nby (erule kparts.induct, auto dest: pparts_analz_sub)\n\nlemma analz_kparts [rule_format,dest]: \"X \\<in> analz H \\<Longrightarrow>\nY \\<in> kparts {X} \\<longrightarrow> Y \\<in> analz H\"\nby (erule analz.induct, auto dest: kparts_analz_sub)\n\nlemma analz_kparts_analz: \"X \\<in> analz (kparts H) \\<Longrightarrow> X \\<in> analz H\"\nby (erule analz.induct, auto dest: kparts_analz)\n\nlemma analz_kparts_insert: \"X \\<in> analz (kparts (insert Z H)) \\<Longrightarrow> X \\<in> analz (kparts {Z} \\<union> kparts H)\"\nby (rule analz_sub, auto)\n\nlemma Nonce_kparts_synth [rule_format]: \"Y \\<in> synth (analz G)\n\\<Longrightarrow> Nonce n \\<in> kparts {Y} \\<longrightarrow> Nonce n \\<in> analz G\"\nby (erule synth.induct, auto)\n\nlemma kparts_insert_synth: \"[| Y \\<in> parts (insert X G); X \\<in> synth (analz G);\nNonce n \\<in> kparts {Y}; Nonce n \\<notin> analz G |] ==> Y \\<in> parts G\"\napply (drule parts_insert_substD, clarify)\napply (drule in_sub, drule_tac X=Y in parts_sub, simp)\napply (auto dest: Nonce_kparts_synth)\ndone\n\nlemma Crypt_insert_synth:\n  \"[| Crypt K Y \\<in> parts (insert X G); X \\<in> synth (analz G); Nonce n \\<in> kparts {Y}; Nonce n \\<notin> analz G |] \n   ==> Crypt K Y \\<in> parts G\"\nby (metis Fake_parts_insert_in_Un Nonce_kparts_synth UnE analz_conj_parts synth_simps(5))\n\n\nsubsection\\<open>analz is pparts + analz of kparts\\<close>\n\nlemma analz_pparts_kparts: \"X \\<in> analz H \\<Longrightarrow> X \\<in> pparts H \\<or> X \\<in> analz (kparts H)\"\nby (erule analz.induct, auto) \n\nlemma analz_pparts_kparts_eq: \"analz H = pparts H Un analz (kparts H)\"\nby (rule eq, auto dest: analz_pparts_kparts pparts_analz analz_kparts_analz)\n\nlemmas analz_pparts_kparts_substI = analz_pparts_kparts_eq [THEN ssubst]\nlemmas analz_pparts_kparts_substD = analz_pparts_kparts_eq [THEN sym, THEN ssubst]\n\nend\n", "meta": {"author": "m-fleury", "repo": "isabelle-emacs", "sha": "756c662195e138a1941d22d4dd7ff759cbf6b6b9", "save_path": "github-repos/isabelle/m-fleury-isabelle-emacs", "path": "github-repos/isabelle/m-fleury-isabelle-emacs/isabelle-emacs-756c662195e138a1941d22d4dd7ff759cbf6b6b9/src/HOL/Auth/Guard/Analz.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.2904852897846908}}
{"text": "(*by Lammich*)\nsection \\<open>Imperative Interface\\<close>\ntheory VEBT_Intf_Imperative\n  imports \n  VEBT_Definitions\n  VEBT_Uniqueness\n  VEBT_Member \n  VEBT_Insert VEBT_InsertCorrectness \n  VEBT_MinMax \n  VEBT_Pred VEBT_Succ  \n  VEBT_Delete VEBT_DeleteCorrectness \n  VEBT_Bounds\n  VEBT_DeleteBounds\n  VEBT_Space\n  VEBT_Intf_Functional\n  VEBT_List_Assn\n  VEBT_BuildupMemImp \n  VEBT_SuccPredImperative\n  VEBT_DelImperative\nbegin\n\n  subsection \\<open>Code Export\\<close>\n\n  context begin \n    interpretation VEBT_internal .\n  \n    lemmas [code] = replicatei.simps vebt_memberi.simps highi_def lowi_def vebt_inserti.simps\n      minNulli.simps vebt_succi.simps vebt_predi.simps vebt_deletei.simps\n  \n      greater.simps \n      \n  end  \n    \n  \n  export_code \n    vebt_buildupi\n    vebt_memberi\n    vebt_inserti\n    vebt_maxti vebt_minti\n    vebt_predi vebt_succi \n    vebt_deletei\n  \n   checking SML_imp\n  \n  subsection \\<open>Interface\\<close> \n  \ndefinition vebt_assn::\"nat \\<Rightarrow> nat set \\<Rightarrow> VEBTi \\<Rightarrow> assn\" where\n\"vebt_assn n s ti \\<equiv> \\<exists>\\<^sub>A t. vebt_assn_raw t ti * \\<up>(s = set_vebt t \\<and> invar_vebt t n)\"\n  \n  \nsubsubsection \\<open>Buildup\\<close>\n\ncontext begin\n  interpretation VEBT_internal .\n  \n  interpretation vebt_inst for n .  \n\n\nlemma vebt_buildupi_rule_basic[sep_heap_rules]: \"n > 0 \\<Longrightarrow> <emp> vebt_buildupi n <\\<lambda> r. vebt_assn n {} r >\"\n  unfolding vebt_assn_def \n  apply(rule  post_exI_rule[where x = \"vebt_buildup n\"])\n  using builupicorr[of n] invar_vebt_buildup[of n] set_vebt_buildup[of n]\n  apply simp\n  done\n\nlemma vebt_buildupi_rule: \"<\\<up> (n > 0)> vebt_buildupi  n <\\<lambda> r. vebt_assn n {} r > T[10 * 2^n]\"  \n  unfolding vebt_assn_def htt_def\n  apply rule\n  apply(rule  post_exI_rule[where x = \"vebt_buildup n\"])\n  using vebt_buildupi_rule[of n] invar_vebt_buildup[of  n] set_vebt_buildup[of n] \n  unfolding htt_def \n   apply simp\n  using TBOUND_buildupi[of n] unfolding TBOUND_def\n  apply simp\n  done\n\nsubsubsection \\<open>Member\\<close>\nlemma vebt_memberi_rule: \"<vebt_assn n s ti> vebt_memberi ti x <\\<lambda> r. vebt_assn n s ti *  \\<up>(r = (x \\<in> s))>T[5 + 5 * (nat \\<lceil>lb n \\<rceil>)]\"\n  unfolding vebt_assn_def \n  apply(rule norm_pre_ex_rule_htt) \n  apply(clarsimp simp: norm_pre_pure_iff_htt)\n  apply(rule htt_cons_rule[OF htt_vebt_memberi_invar_vebt])\n     apply assumption\n    apply simp\n   apply (sep_auto simp: member_correct)\n  apply simp\n  done\n\n  \nsubsubsection \\<open>Insert\\<close>  \nlemma vebt_inserti_rule: \"x < 2^n \\<Longrightarrow> <vebt_assn n s ti> vebt_inserti ti x <\\<lambda> r. vebt_assn n (s \\<union> {x}) r >T[13 + 13 * (nat \\<lceil>lb n \\<rceil>)]\"\n  apply(sep_auto simp: norm_pre_pure_iff_htt)\n  unfolding vebt_assn_def\n  apply(rule norm_pre_ex_rule_htt) \n  apply(clarsimp simp: norm_pre_pure_iff_htt)\n  apply(rule htt_cons_rule[OF htt_vebt_inserti_invar_vebt])\n     apply assumption\n    apply simp\n   apply sep_auto\n      apply (auto simp add: insert_correct) \n     apply (simp add: valid_insert_both_member_options_add set_vebt_def)\n    apply (metis UnCI insert_correct)\n   apply (metis UnE insert_correct singletonD)\n  using valid_pres_insert by presburger\n\n\nsubsubsection \\<open>Maximum\\<close>  \nlemma vebt_maxti_rule: \"<vebt_assn n s ti> vebt_maxti ti <\\<lambda> r. vebt_assn n s ti *  \\<up>( r = Some y \\<longleftrightarrow> max_in_set s y)>T[1]\"\n  unfolding vebt_assn_def \n  apply(rule norm_pre_ex_rule_htt) \n  apply(clarsimp simp: norm_pre_pure_iff_htt)\n  apply(rule htt_cons_rule[OF vebt_maxti_hT])\n  apply(rule ent_refl)\n  apply (sep_auto simp: set_vebt_maxt)\n  by simp\n  \nsubsubsection \\<open>Minimum\\<close>  \nlemma vebt_minti_rule: \"<vebt_assn n s ti> vebt_minti ti <\\<lambda> r. vebt_assn n s ti *  \\<up>( r = Some y \\<longleftrightarrow> min_in_set s y)>T[1]\"\n  unfolding vebt_assn_def \n  apply(rule norm_pre_ex_rule_htt) \n  apply(clarsimp simp: norm_pre_pure_iff_htt)\n  apply(rule htt_cons_rule[OF vebt_minti_hT])\n  apply(rule ent_refl)\n  apply (sep_auto simp: set_vebt_mint)\n  by auto\n  \n  \nsubsubsection \\<open>Successor\\<close>  \nlemma vebt_succi_rule: \"<vebt_assn n s ti> vebt_succi ti x <\\<lambda> r. vebt_assn n s ti *  \\<up>( r = Some y \\<longleftrightarrow> is_succ_in_set s x y)>T[7 + 7 * (nat \\<lceil>lb n \\<rceil>)]\"\n  unfolding vebt_assn_def \n  apply(rule norm_pre_ex_rule_htt) \n  apply(clarsimp simp: norm_pre_pure_iff_htt)\n  apply(rule htt_cons_rule[OF htt_vebt_succi])\n  apply assumption\n  apply simp\n  apply (sep_auto simp: set_vebt_succ)\n  apply simp\n  done\n\nsubsubsection \\<open>Predecessor\\<close>  \nlemma vebt_predi_rule: \"<vebt_assn n s ti> vebt_predi ti x <\\<lambda> r. vebt_assn n s ti *  \\<up>( r = Some y \\<longleftrightarrow> is_pred_in_set s x y)>T[7 + 7 * (nat \\<lceil>lb n \\<rceil>)]\"\n  unfolding vebt_assn_def \n  apply(rule norm_pre_ex_rule_htt) \n  apply(clarsimp simp: norm_pre_pure_iff_htt)\n  apply(rule htt_cons_rule[OF htt_vebt_predi])\n  apply assumption\n  apply simp\n  apply (sep_auto simp: set_vebt_pred)\n  apply simp\n  done\n\nsubsubsection \\<open>Delete\\<close>  \nlemma vebt_deletei_rule: \"<vebt_assn n s ti > vebt_deletei ti x <\\<lambda> r. vebt_assn n (s - {x}) r >T[20 + 20 * (nat \\<lceil>lb n \\<rceil>)]\"\n  unfolding vebt_assn_def\n  apply(rule norm_pre_ex_rule_htt) \n  apply(clarsimp simp: norm_pre_pure_iff_htt)\n  apply(rule htt_cons_rule[OF htt_vebt_deletei])\n  apply assumption\n  apply simp\n  apply sep_auto\n   apply (auto simp add: set_vebt_delete invar_vebt_delete) \n  done\n\nsubsection \\<open>Setup of VCG\\<close>   \nlemmas vebt_heap_rules[THEN htt_htD,sep_heap_rules] = \n  vebt_buildupi_rule\n  vebt_memberi_rule\n  vebt_inserti_rule\n  vebt_maxti_rule\n  vebt_minti_rule\n  vebt_succi_rule\n  vebt_predi_rule\n  vebt_deletei_rule\n\nend\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Van_Emde_Boas_Trees/VEBT_Intf_Imperative.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.2904324311152722}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |               December 2004               |\n            |                   July 2005  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |                October 2005  (modified)   |\n            |                  April 2006  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2009-2       |\n            |                October 2010  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2016         |\n            |                    May 2016  (modified)   |\n            |                                           |\n\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory Domain_T_cms\nimports Domain_T CSP.RS\nbegin\n\n(*****************************************************************\n\n         1. \n         2. \n         3. \n         4. \n\n *****************************************************************)\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite UnionT and InterT.                 *)\n(*                  Union (B ` A) = (UN x:A. B x)                      *)\n(*                  Inter (B ` A) = (INT x:A. B x)                     *)\n\n(*\ndeclare Union_image_eq [simp del]\ndeclare Inter_image_eq [simp del]\n*)\n(* no simp rules in Isabelle 2017 \ndeclare Sup_image_eq [simp del]\ndeclare Inf_image_eq [simp del]\n*)\n\n(**********************************************************\n           Definitions (Restriction in domT)\n **********************************************************)\n\n(*\ninstance domT :: (type) ms0\nby (intro_classes)\n*)\n\ndefinition\n  restT      :: \"'a domT => nat => 'a trace set\" (\"_ restT _\" [84,900] 84)\n  where\n  restT_def  : \"T restT n == {s. s :t T & (lengtht s) <= n}\"\n\n(* (\"_ restT _\" [55,56] 55) in Isabelle 2005 *)\n\ndefinition\n  LimitT     :: \"'a domT infinite_seq => 'a trace set\"\n  where\n  LimitT_def : \"LimitT Ts == {s. s :t Ts (lengtht s)}\"\n  \ndefinition  \n  Limit_domT :: \"'a domT infinite_seq => 'a domT\"\n  where\n  Limit_domT_def    : \"Limit_domT Ts    == Abs_domT (LimitT Ts)\"\n\n(* isabelle 2009-2 *)\n\ninstantiation domT :: (type) rs0\nbegin\n\ndefinition\n  rest_domT_def : \"T .|. n == Abs_domT (T restT n)\"\n\n  instance ..\n\nend\n\n(* isabelle 2009-1\ndefs (overloaded)\n  rest_domT_def : \"T .|. n == Abs_domT (T restT n)\"\n*)\n\n\n\n(**********************************************************\n              Lemmas (Restriction in Dom_T)\n **********************************************************)\n\n(*** restT_def in domT ***)\n\nlemma restT_in[simp] : \"T restT n : domT\"\napply (simp add: restT_def)\napply (simp add: domT_def HC_T1_def)\napply (rule conjI)\napply (rule_tac x=\"<>\" in exI, simp)\n\napply (simp add: prefix_closed_def)\napply (intro allI impI)\napply (elim conjE exE)\n\napply (rule conjI)\napply (rule memT_prefix_closed, simp_all)\n\napply (subgoal_tac \"lengtht s <= lengtht t\", simp)\napply (rule length_of_prefix)\napply (simp)\ndone\n\n(*** restT in domT ***)\n\nlemmas restT_def_in = restT_in[simplified memT_def restT_def]\n\n(*********************************************************\n                     .|. on dom_T\n *********************************************************)\n\nlemma rest_domT_iff: \"T .|. n = {s. s :t T & lengtht s <= n}t\"\napply (simp add: rest_domT_def)\napply (simp add: restT_in[simplified restT_def] Abs_domT_inject)\napply (simp add: restT_def)\ndone\n\nlemma in_rest_domT: \"s :t T .|. n = (s :t T & lengtht s <= n)\"\napply (simp add: memT_def rest_domT_def)\napply (simp add: Abs_domT_inverse)\napply (simp add: memT_def restT_def)\ndone\n\nlemma rest_domT_eq_iff:\n   \"(T .|. n = S .|. m) =\n    (ALL s. (s :t T & lengtht s <= n) = (s :t S & lengtht s <= m))\"\napply (simp add: rest_domT_def Abs_domT_inject)\napply (simp add: restT_def)\nby (auto)\n\n(*********************************************************\n                     Dom_T --> RS\n *********************************************************)\n\n(*******************************\n        zero_eq_rs_domT\n *******************************)\n\n(*** restT 0 ***)\n\nlemma zero_domT: \"T restT 0 = {<>}\"\napply (simp add: restT_def)\napply (rule order_antisym)\n\napply (rule subsetI)\napply (simp)\napply (erule conjE)\napply (simp add: lengtht_zero)\nby (simp)\n\n(*** zero_eq_rs_domT ***)\n\nlemma zero_rs_domT: \"T .|. 0 = {<>}t\"\napply (simp add: rest_domT_def)\napply (simp add: Abs_domT_inject)\napply (simp add: zero_domT)\ndone\n\nlemma zero_eq_rs_domT: \"(T::'a domT) .|. 0 = S .|. 0\"\napply (simp add: zero_rs_domT)\ndone\n\n(*******************************\n         min_rs_domT\n *******************************)\n\nlemma min_rs_domT: \"((T::'a domT) .|. m) .|. n = T .|. (min m n)\"\napply (simp add: rest_domT_def)\napply (simp add: Abs_domT_inject)\n\napply (simp add: restT_def memT_def)\napply (simp add: restT_in[simplified memT_def restT_def]\n                 Abs_domT_inverse)\ndone\n\n(*******************************\n         diff_rs_domT\n *******************************)\n\n(*** contra = ***)\n\nlemma contra_diff_rs_domT: \n  \"(ALL n. (T::'a domT) .|. n = S .|. n) ==> T = S\"\napply (simp add: rest_domT_eq_iff)\napply (rule order_antisym)\nby (auto)\n\n(*** diff_rs_domT ***)\n\nlemma diff_rs_domT: \n  \"(T::'a domT) ~= S ==> (EX n. T .|. n ~= S .|. n)\"\napply (erule contrapos_pp)\napply (simp)\napply (rule contra_diff_rs_domT, simp)\ndone\n\n(***************************************************************\n                       domT ==> RS\n ***************************************************************)\n\ninstance domT :: (type) rs\napply (intro_classes)\napply (simp add: zero_eq_rs_domT)\napply (simp add: min_rs_domT)\napply (simp add: diff_rs_domT)\ndone\n\n(************************************************************\n                        domT ==> MS\n ************************************************************)\n\n\ninstantiation domT :: (type) ms0\nbegin\n\ndefinition\n  domT_distance_def:\n     \"distance (TT::('a domT * 'a domT)) = distance_rs TT\"\n  instance ..\nend\n\ninstance domT :: (type) ms\napply (intro_classes)\napply (simp_all add: domT_distance_def)\napply (simp add: diagonal_rs)\napply (simp add: symmetry_rs)\napply (simp add: triangle_inequality_rs)\ndone\n\n(************************************************************\n                 i.e.  domT ==> MS & RS \n ************************************************************)\n\ninstance domT :: (type) ms_rs\napply (intro_classes)\napply (simp add: domT_distance_def)\ndone\n\n(***********************************************************\n                      lemmas (Limit)\n ***********************************************************)\n\n(*** normal_seq lemma ***)\n\nlemma normal_seq_domT:\n  \"[| normal Ts ; lengtht s <= n |]\n   ==> (s :t Ts (lengtht s)) = (s :t Ts n)\"\napply (simp add: normal_def)\napply (drule_tac x=\"lengtht s\" in spec)\napply (drule_tac x=\"n\" in spec)\napply (simp add: min_is)\n\napply (simp add: to_distance_rs)\napply (simp add: distance_rs_le_1[THEN sym])\napply (simp add: rest_domT_eq_iff)\napply (drule_tac x=\"s\" in spec)\nby (simp)\n\nlemma normal_seq_domT_only_if:\n  \"[| normal Ts ; lengtht s <= n ; s :t Ts (lengtht s) |]\n   ==> s :t Ts n\"\nby (simp add: normal_seq_domT)\n\nlemma normal_seq_domT_if:\n  \"[| normal Ts ; lengtht s <= n ; s :t Ts n |]\n   ==>  s :t Ts (lengtht s)\"\nby (simp add: normal_seq_domT)\n\n(*** LimitT_def in domT ***)\n\nlemma LimitT_in[simp]:\n  \"normal (Ts::'a domT infinite_seq) ==> LimitT Ts : domT\"\napply (simp add: domT_def HC_T1_def)\napply (rule conjI)\n\napply (simp add: LimitT_def)\napply (rule_tac x=\"<>\" in exI)\napply (simp)\n\napply (simp add: prefix_closed_def LimitT_def)\napply (intro allI impI)\napply (elim conjE exE)\n\napply (subgoal_tac \"lengtht s <= lengtht t\")\napply (rule normal_seq_domT_if)\napply (simp_all)\napply (rule memT_prefix_closed, simp_all)\napply (rule length_of_prefix)\napply (simp)\ndone\n\n(*** :t Limit_domT ***)\n\nlemma Limit_domT_memT: \n  \"normal (Ts::'a domT infinite_seq)\n   ==> (s :t Limit_domT Ts) = (s :t Ts (lengtht s))\"\napply (simp add: memT_def)\napply (simp add: Limit_domT_def)\napply (simp add: Abs_domT_inverse)\napply (simp add: LimitT_def memT_def)\ndone\n\n(*** Limit_domT lemma ***)\n\nlemma Limit_domT_Limit_lm:\n  \"normal (Ts::'a domT infinite_seq)\n   ==> (ALL n. (Limit_domT Ts) .|. n = (Ts n) .|. n)\"\napply (intro allI)\napply (simp add: rest_domT_eq_iff)\napply (simp add: Limit_domT_memT)\nby (auto simp add: normal_seq_domT)\n\n(*** (normal) Ts converges to (Limit_domT Ts) ***)\n\nlemma Limit_domT_Limit:\n  \"normal (Ts::'a domT infinite_seq) ==> Ts convergeTo (Limit_domT Ts)\"\nby (simp add: to_distance_rs Limit_domT_Limit_lm rest_Limit)\n\n(*** (cauchy) Ts converges to (Limit_domT NF Ts) ***)\n\nlemma cauchy_Limit_domT_Limit:\n  \"cauchy (Ts::'a domT infinite_seq) ==> Ts convergeTo (Limit_domT (NF Ts))\"\napply (simp add: normal_form_seq_same_Limit)\napply (simp add: Limit_domT_Limit normal_form_seq_normal)\ndone\n\n(***************************************\n     Dom_T --> Complete Metric Space\n ***************************************)\n\nlemma domT_cms:\n  \"cauchy (Ts::'a domT infinite_seq) ==> (EX T. Ts convergeTo T)\"\napply (rule_tac x=\"Limit_domT (NF Ts)\" in exI)\nby (simp add: cauchy_Limit_domT_Limit)\n\n(************************************************************\n                   domT ==> CMS and RS\n ************************************************************)\n\ninstance domT :: (type) cms\napply (intro_classes)\nby (simp add: domT_cms)\n\ninstance domT :: (type) cms_rs\nby (intro_classes)\n\n(*** (normal) Limit Ts = Limit_domT Ts ***)\n\nlemma Limit_domT_Limit_eq:\n  \"normal (Ts::'a domT infinite_seq) ==> Limit Ts = Limit_domT Ts\"\napply (insert unique_convergence[of Ts \"Limit Ts\" \"Limit_domT Ts\"])\nby (simp add: Limit_domT_Limit Limit_is normal_cauchy)\n\n(*----------------------------------------------------------*\n |                                                          |\n |                       cms rs order                       |\n |                                                          |\n *----------------------------------------------------------*)\n\ninstance domT :: (type) ms_rs_order0\napply (intro_classes)\ndone\n\ninstance domT :: (type) ms_rs_order\napply (intro_classes)\napply (intro allI)\napply (rule iffI)\napply (simp add: rest_domT_def)\napply (simp add: subdomT_def)\napply (simp add: Abs_domT_inverse)\napply (fold subdomT_def)\napply (rule)\napply (drule_tac x=\"lengtht t\" in spec)\napply (simp add: restT_def)\napply (force)\n\napply (intro allI)\napply (simp add: rest_domT_def)\napply (simp add: subdomT_def)\napply (simp add: Abs_domT_inverse)\napply (fold subdomT_def)\napply (rule)\napply (simp add: restT_def)\napply (force)\ndone\n\ninstance domT :: (type) cms_rs_order\nby (intro_classes)\n\n(*----------------------------------------------------------*\n |                                                          |\n |  i.e. lemma \"continuous_rs (Ref_fun (S::'a domT))\"       |\n |       by (simp add: continuous_rs_Ref_fun)               |\n |                                                          |\n |  see RS.thy                                              |\n |                                                          |\n *----------------------------------------------------------*)\n\n(****************** to add them again ******************)\n(*\ndeclare Union_image_eq [simp]\ndeclare Inter_image_eq [simp]\n*)\n(*\ndeclare Sup_image_eq [simp]\ndeclare Inf_image_eq [simp]\n*)\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/CSP_T/Domain_T_cms.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.2904324311152722}}
{"text": "(* \n   Title: The pi-calculus   \n   Author/Maintainer: Jesper Bengtson (jebe.dk), 2012\n*)\ntheory Strong_Early_Bisim_Subst_SC\n  imports Strong_Early_Bisim Strong_Late_Bisim_Subst_SC Strong_Early_Late_Comp\nbegin\n\n(******** Structural Congruence **********)\n\n(******** The \\<nu>-operator *****************)\n\nlemma resComm:\n  fixes P :: pi\n  \n  shows \"<\\<nu>a><\\<nu>b>P \\<sim>\\<^sup>s\\<^sub>e <\\<nu>b><\\<nu>a>P\"\nproof -\n  have \"<\\<nu>a><\\<nu>b>P \\<sim>\\<^sup>s\\<^sub>l <\\<nu>b><\\<nu>a>P\"\n    by(rule Strong_Late_Bisim_Subst_SC.resComm)\n  thus ?thesis by(rule lateEarlyCong) \nqed\n\n(******** The Match *********)\n\nlemma matchId:\n  fixes a :: name\n  and   P :: pi\n\n  shows \"[a\\<frown>a]P \\<sim>\\<^sup>s\\<^sub>e P\"\nproof -\n  have \"[a\\<frown>a]P \\<sim>\\<^sup>s\\<^sub>l P\" by(rule Strong_Late_Bisim_Subst_SC.matchId)\n  thus ?thesis by(rule lateEarlyCong)\nqed\n\n(******** Mismatch *********)\n\n\n\n(******** The +-operator *********)\n\nlemma sumSym:\n  fixes P :: pi\n  and   Q :: pi\n  \n  shows \"P \\<oplus> Q \\<sim>\\<^sup>s\\<^sub>e Q \\<oplus> P\"\nproof -\n  have \"P \\<oplus> Q \\<sim>\\<^sup>s\\<^sub>l Q \\<oplus> P\" by(rule Strong_Late_Bisim_Subst_SC.sumSym)\n  thus ?thesis by(rule lateEarlyCong)\nqed\n\n\n\n\n\n(******** The |-operator *********)\n\nlemma parZero:\n  fixes P :: pi\n\n  shows \"P \\<parallel> \\<zero> \\<sim>\\<^sup>s\\<^sub>e P\"\nproof -\n  have \"P \\<parallel> \\<zero> \\<sim>\\<^sup>s\\<^sub>l P\" by(rule Strong_Late_Bisim_Subst_SC.parZero)\n  thus ?thesis by(rule lateEarlyCong)\nqed\n\nlemma parSym:\n  fixes P :: pi\n  and   Q :: pi\n\n  shows \"P \\<parallel> Q \\<sim>\\<^sup>s\\<^sub>e Q \\<parallel> P\"\nproof -\n  have \"P \\<parallel> Q \\<sim>\\<^sup>s\\<^sub>l Q \\<parallel> P\" by(rule Strong_Late_Bisim_Subst_SC.parSym)\n  thus ?thesis by(rule lateEarlyCong)\nqed\n\n\n\n  assumes \"x \\<sharp> P\"\n\n  shows \"<\\<nu>x>(P \\<parallel> Q) \\<sim>\\<^sup>s\\<^sub>e P \\<parallel> <\\<nu>x>Q\"\nproof -\n  from `x \\<sharp> P` have \"<\\<nu>x>(P \\<parallel> Q) \\<sim>\\<^sup>s\\<^sub>l P \\<parallel> <\\<nu>x>Q\" by(rule Strong_Late_Bisim_Subst_SC.scopeExtPar)\n  thus ?thesis by(rule lateEarlyCong)\nqed\n\nlemma scopeExtPar':\n  fixes P :: pi\n  and   Q :: pi\n  and   x :: name\n\n  assumes xFreshQ: \"x \\<sharp> Q\"\n\n  shows \"<\\<nu>x>(P \\<parallel> Q) \\<sim>\\<^sup>s\\<^sub>e (<\\<nu>x>P) \\<parallel> Q\"\nproof -\n  from `x \\<sharp> Q` have \"<\\<nu>x>(P \\<parallel> Q) \\<sim>\\<^sup>s\\<^sub>l (<\\<nu>x>P) \\<parallel> Q\" by(rule Strong_Late_Bisim_Subst_SC.scopeExtPar')\n  thus ?thesis by(rule lateEarlyCong)\nqed\n\n\n\n  shows \"(P \\<parallel> Q) \\<parallel> R \\<sim>\\<^sup>s\\<^sub>e P \\<parallel> (Q \\<parallel> R)\"\nproof -\n  have \"(P \\<parallel> Q) \\<parallel> R \\<sim>\\<^sup>s\\<^sub>l P \\<parallel> (Q \\<parallel> R)\" by(rule Strong_Late_Bisim_Subst_SC.parAssoc)\n  thus ?thesis by(rule lateEarlyCong)\nqed\n\nlemma freshRes:\n  fixes P :: pi\n  and   a :: name\n\n  assumes a \\<sharp> P\"\n\n  shows \"<\\<nu>a>P \\<sim>\\<^sup>s\\<^sub>e P\"\nproof -\n  from a \\<sharp> P` have \"<\\<nu>a>P \\<sim>\\<^sup>s\\<^sub>l P\" by(rule Strong_Late_Bisim_Subst_SC.freshRes)\n  thus ?thesis by(rule lateEarlyCong)\nqed\n\nlemma scopeExtSum:\n  fixes P :: pi\n  and   Q :: pi\n  and   x :: name\n  \n  assumes \"x \\<sharp> P\"\n\n  shows \"<\\<nu>x>(P \\<oplus> Q) \\<sim>\\<^sup>s\\<^sub>e P \\<oplus> <\\<nu>x>Q\"\nproof -\n  from `x \\<sharp> P` have \"<\\<nu>x>(P \\<oplus> Q) \\<sim>\\<^sup>s\\<^sub>l P \\<oplus> <\\<nu>x>Q\" by(rule Strong_Late_Bisim_Subst_SC.scopeExtSum)\n  thus ?thesis by(rule lateEarlyCong)\nqed\n\nlemma bangSC:\n  fixes P\n\n  shows \"!P \\<sim>\\<^sup>s\\<^sub>e P \\<parallel> !P\"\nproof -\n  have \"!P \\<sim>\\<^sup>s\\<^sub>l P \\<parallel> !P\" by(rule Strong_Late_Bisim_Subst_SC.bangSC)\n  thus ?thesis by(rule lateEarlyCong)\nqed\n\nend\n\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Pi_Calculus/Strong_Early_Bisim_Subst_SC.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.640635854839898, "lm_q2_score": 0.4532618480153861, "lm_q1q2_score": 0.2903757914696488}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory BinarySearch\nimports \"AutoCorres.AutoCorres\" \"../../DataStructures\"\nbegin\n\nexternal_file \"binary_search.c\"\ninstall_C_file \"binary_search.c\"\n\nautocorres [ts_rules = nondet, unsigned_word_abs=binary_search] \"binary_search.c\"\n\ncontext binary_search begin\n\nlemma uint_of_nat:\n    \"uint (of_nat x :: 'a::len word) = (int x) mod 2^ len_of TYPE('a)\"\n  apply (clarsimp simp only: uint_nat unat_of_nat)\n  apply (metis of_nat_numeral semiring_1_class.of_nat_power zmod_int)\n  done\n\nlemma ptr_add_uint_of_nat [simp]:\n    \"p +\\<^sub>p uint (of_nat x :: addr) = p +\\<^sub>p int x\"\n  apply (subst uint_of_nat)\n  apply (unfold CTypesDefs.ptr_add_def)\n  apply (metis (hide_lams, no_types) uint_of_nat of_int_of_nat_eq of_int_uint)\n  done\n\nlemmas [simp] = sint_ucast_eq_uint is_up is_down\n\n\nprimrec\n  array :: \"lifted_globals \\<Rightarrow> word32 ptr \\<Rightarrow> word32 list \\<Rightarrow> bool\"\nwhere\n    \"array s p [] = True\"\n  | \"array s p (x#xs) = ((heap_w32 s p = x) \\<and> (is_valid_w32 s p) \\<and> array s (p +\\<^sub>p 1) xs)\"\n\ndefinition\n  \"is_array s p n \\<equiv> \\<exists>l. array s p l \\<and> length l = n\"\n\ndefinition\n  \"the_array s p n \\<equiv> (THE l. length l = n \\<and> array s p l)\"\n\nlemma array_unique:\n    \"\\<lbrakk> array s p l; array s p l'; length l = length l' \\<rbrakk> \\<Longrightarrow> l = l'\"\n  apply (induct l arbitrary: l' p)\n   apply clarsimp\n  apply (case_tac l')\n   apply clarsimp\n   apply clarsimp\n  done\n\nlemma array_concat [simp]:\n  \"array s p (a @ b) = (array s p a \\<and> array s (p +\\<^sub>p int (length a)) b)\"\n  apply (induct a arbitrary: p)\n   apply clarsimp\n  apply clarsimp\n  apply atomize\n  apply (erule_tac x=\"p +\\<^sub>p 1\" in allE)\n  apply (clarsimp simp: CTypesDefs.ptr_add_def field_simps)\n  done\n\nlemma array_is_array: \"array s p a \\<Longrightarrow> is_array s p (length a)\"\n  apply (clarsimp simp: is_array_def)\n  apply force\n  done\n\nlemma array_the_array: \"\\<lbrakk> array s p a; length a = n \\<rbrakk> \\<Longrightarrow> the_array s p n = a\"\n  apply (simp add: the_array_def)\n  apply (metis (lifting, mono_tags) array_unique the_equality)\n  done\n\nlemma length_the_array [simp]: \"is_array s p n \\<Longrightarrow> length (the_array s p n) = n\"\n  apply (induct n arbitrary: n)\n   apply (clarsimp simp: is_array_def)\n   apply (metis array_the_array)\n  apply (clarsimp simp: is_array_def)\n  done\n\nlemma the_array_Suc:\n  \"\\<lbrakk> is_array s p n; n > 0 \\<rbrakk> \\<Longrightarrow> the_array s p n = (heap_w32 s p) # (the_array s (p +\\<^sub>p 1) (n - 1))\"\n  apply (clarsimp simp: is_array_def)\n  apply (case_tac l)\n   apply clarsimp\n  apply clarsimp\n  apply (metis One_nat_def Suc_eq_plus1 list.size(4) array.simps(2) array_the_array)\n  done\n\nlemma the_array_0 [simp]:\n  \"the_array s p 0 = []\"\n  by (metis list.size(3) array.simps(1) array_the_array)\n\nlemma is_array_0 [simp]:\n  \"is_array s p 0\"\n  apply (clarsimp simp: is_array_def)\n  done\n\nlemma is_array_Suc:\n  \"\\<lbrakk> is_array s p n; is_valid_w32 s (p +\\<^sub>p int n) \\<rbrakk> \\<Longrightarrow>\n      is_array s p (Suc n)\"\n  apply (clarsimp simp: is_array_def)\n  apply (rule_tac x=\"l @ [heap_w32 s (p +\\<^sub>p int (length l))]\" in exI)\n  apply clarsimp\n  done\n\nlemma array_expand: \"array s p n \\<Longrightarrow> array s (p +\\<^sub>p 1) (tl n)\"\n  apply (case_tac n)\n   apply clarsimp\n  apply clarsimp\n  done\n\nlemma array_Ex:\n  \"\\<lbrakk> array s p n; 0 \\<le> i; i < int (length n) \\<rbrakk> \\<Longrightarrow> is_valid_w32 s (p +\\<^sub>p i)\"\n  apply (induct n arbitrary: p i)\n   apply clarsimp\n  apply clarsimp\n  apply atomize\n  apply (erule_tac x=\"p +\\<^sub>p 1\" in allE)\n  apply (erule_tac x=\"i - 1\" in allE)\n  apply (clarsimp simp: CTypesDefs.ptr_add_def)\n  done\n\nlemma sorted_index_lt:\n  \"\\<lbrakk> sorted xs; unat (xs ! m) < v; n \\<le> m; m < length xs \\<rbrakk> \\<Longrightarrow>  unat (xs ! n) < v\"\n  by (meson le_less_trans sorted_nth_mono unat_arith_simps(1))\n\nlemma sorted_index_gt:\n    \"\\<lbrakk> sorted xs; v < unat (xs ! m); m \\<le> n; n < length xs \\<rbrakk> \\<Longrightarrow>  v < unat (xs ! n)\"\n  by (metis le_less_linear le_less_trans less_irrefl sorted_nth_mono word_less_nat_alt)\n\nlemma array_access_to_list_access:\n    \"\\<lbrakk> array s p data; n < length data \\<rbrakk> \\<Longrightarrow> (heap_w32 s (p +\\<^sub>p int n)) = data ! n\"\n  apply (induct data arbitrary: n p)\n   apply clarsimp\n  apply (case_tac \"n = 0\")\n   apply clarsimp\n  apply atomize\n  apply (erule_tac x=\"n - 1\" in allE)\n  apply (erule_tac x=\"p +\\<^sub>p 1\" in allE)\n  apply (erule impE)\n   apply clarsimp\n  apply (erule impE)\n   apply clarsimp\n   apply arith\n  apply (clarsimp simp: field_simps CTypesDefs.ptr_add_def)\n  done\n\nlemma binary_search_correct:\n  \"\\<lbrace> \\<lambda>s. array s arr data \\<and> length data < 1000000000 \\<and> n = length data \\<and> sorted data \\<rbrace>\n           binary_search' arr n v\n        \\<lbrace> \\<lambda>r s. r \\<noteq> 0 \\<longleftrightarrow> v \\<in> unat ` set data \\<rbrace>!\"\n  apply (rule validNF_assume_pre)\n  apply (unfold binary_search'_def)\n  apply (case_tac \"n = 0\")\n   apply (subst whileLoop_add_inv [where I=\"\\<lambda>(f, l, r) _. f = 0 \\<and> l = 0 \\<and> r = 0\" and M=\"\\<lambda>_. 0\"])\n   apply ((wp | clarsimp)+)[1]\n  apply (subst whileLoop_add_inv [where\n        I=\"\\<lambda>(found, l, r) s. array s arr data  \\<and> (r \\<le> n)\n                \\<and> (\\<forall>i. i < l \\<longrightarrow> i < n \\<longrightarrow> unat (data ! i) <  v)\n                \\<and> (\\<forall>i. i \\<ge> r \\<longrightarrow> i < n \\<longrightarrow> v < unat (data ! i))\n                \\<and> (found \\<noteq> 0 \\<longrightarrow> v \\<in> unat ` set data)\"\n          and  M=\"\\<lambda>((found, l, r), s). if found = 0 then 1 + (r - l) else 0\" ])\n  apply wp\n     apply (clarsimp split del: if_split cong: if_cong\n       simp: field_simps array_access_to_list_access array_Ex UINT_MAX_def)\n    apply (subgoal_tac \"aa \\<le> ((aa + b)  div 2) \\<and> ((aa + b) div 2) \\<le> b\")\n     apply (case_tac \"unat (data ! ((aa + b) div 2)) = v\")\n      apply (clarsimp simp: UINT_MAX_def INT_MAX_def)\n     apply (case_tac \"unat (data ! ((aa + b) div 2)) < v\")\n      apply (auto elim: sorted_index_lt simp: UINT_MAX_def INT_MAX_def cong: if_cong)[1]\n     apply (subgoal_tac \"unat (data ! ((aa + b) div 2)) > v\")\n      apply (clarsimp simp: UINT_MAX_def INT_MAX_def)\n      apply (fastforce elim: sorted_index_gt)\n     apply force\n    apply force\n   apply (clarsimp split del: if_split simp: field_simps cong: if_cong)\n   apply rule\n    apply clarsimp\n   apply clarsimp\n   apply (metis (no_types) in_set_conv_nth le_less_trans neq_iff not_less)\n  apply clarsimp\n  done\n\nend\n\nend\n", "meta": {"author": "NICTA", "repo": "l4v", "sha": "3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b", "save_path": "github-repos/isabelle/NICTA-l4v", "path": "github-repos/isabelle/NICTA-l4v/l4v-3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b/tools/autocorres/tests/examples/BinarySearch.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5506073655352404, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.29034436174122547}}
{"text": "theory Bool_Kernel_Isabelle\nimports Postkernel_Isabelle \"splice/Splice\"\nbegin\n\ndeclare [[ML_environment=\"HOL4\"]]\nML \\<open>Context_Var.bind_ref \"Bool_Kernel_Isabelle\"\\<close>\n\ndeclare [[ML_environment=\"HOL4\"]]\n\ntext \\<open> Theory bool and Kernel intertwined, because of strange HOL4-bootstrap (Suspend etc...)\\<close>\n\nsubsection \\<open>bool\\<close>\n\nML \\<open>Holmake build_heap (make_modules [\"boolpp\", \"TexTokenMap\"]) \"HOL/src/bool\"\\<close>\n\nML \\<open>Context_Var.start_temp()\\<close>\nML \\<open>\nstructure Bool1 = struct\n(* bool Script part 1 (building up \"suspended\" (why the hell?) kernel primitives)*)\nlocal\nopen HolKernel Parse\nopen Unicode TexTokenMap\nin\n\nval _ = new_theory \"bool\";\n\n(*---------------------------------------------------------------------------*\n *             BASIC DEFINITIONS                                             *\n *---------------------------------------------------------------------------*)\n\n(* parsing/printing support for theory min *)\nval _ = unicode_version {u = UChar.imp, tmnm = \"==>\"}\nval _ = TeX_notation {hol = \"==>\", TeX = (\"\\\\HOLTokenImp{}\", 1)}\nval _ = TeX_notation {hol = UChar.imp, TeX = (\"\\\\HOLTokenImp{}\", 1)}\n\nval _ = TeX_notation {hol = \"\\\\\", TeX = (\"\\\\HOLTokenLambda{}\", 1)}\nval _ = TeX_notation {hol = UChar.lambda, TeX = (\"\\\\HOLTokenLambda{}\", 1)}\n\nval _ = TeX_notation {hol = \"@\", TeX = (\"\\\\HOLTokenHilbert{}\", 1)}\n\n(* iff *)\nval _ = overload_on (\"<=>\", “(=) : bool -> bool -> bool”)\nval _ = set_fixity \"<=>\" (Infix(NONASSOC, 100))\nval _ = unicode_version {u = UChar.iff, tmnm = \"<=>\"}\nval _ = TeX_notation {hol = \"<=>\", TeX = (\"\\\\HOLTokenEquiv{}\",3)}\nval _ = TeX_notation {hol = UChar.iff, TeX = (\"\\\\HOLTokenEquiv{}\",3)}\n\n(* records *)\nval _ = TeX_notation {hol = \"<|\", TeX = (\"\\\\HOLTokenLeftrec{}\", 2)}\nval _ = TeX_notation {hol = \"|>\", TeX = (\"\\\\HOLTokenRightrec{}\", 2)}\n\n(* case expressions *)\nval _ = TeX_notation {hol = \"case\", TeX = (\"\\\\HOLKeyword{case}\", 4)}\nval _ = TeX_notation {hol = \"of\",   TeX = (\"\\\\HOLKeyword{of}\", 2)}\nval _ = TeX_notation {hol = \"=>\", TeX = (\"\\\\HOLTokenImp{}\", 1)}\n\n(* let expressions *)\nval _ = TeX_notation {hol = \"let\", TeX = (\"\\\\HOLKeyword{let}\", 3)}\nval _ = TeX_notation {hol = \"and\", TeX = (\"\\\\HOLKeyword{and}\", 2)}\nval _ = TeX_notation {hol = \"in\",  TeX = (\"\\\\HOLKeyword{in}\", 2)}\n\n(* if statements *)\nval _ = TeX_notation {hol = \"if\",   TeX = (\"\\\\HOLKeyword{if}\", 2)}\nval _ = TeX_notation {hol = \"then\", TeX = (\"\\\\HOLKeyword{then}\", 4)}\nval _ = TeX_notation {hol = \"else\", TeX = (\"\\\\HOLKeyword{else}\", 4)}\n\nval T_DEF =\n Definition.new_definition\n   (\"T_DEF\",           ``T = ((\\x:bool. x) = \\x:bool. x)``);\n\nval FORALL_DEF =\n Definition.new_definition\n   (\"FORALL_DEF\",     ``! = \\P:'a->bool. P = \\x. T``);\n\nval _ = set_fixity \"!\" Binder\nval _ = unicode_version {u = UChar.forall, tmnm = \"!\"};\nval _ = TeX_notation {hol = \"!\", TeX = (\"\\\\HOLTokenForall{}\",1)}\nval _ = TeX_notation {hol = UChar.forall, TeX = (\"\\\\HOLTokenForall{}\",1)}\n\nval EXISTS_DEF =\n Definition.new_definition\n   (\"EXISTS_DEF\",     ``? = \\P:'a->bool. P ($@ P)``);\n\nval _ = set_fixity \"?\" Binder\nval _ = unicode_version {u = UChar.exists, tmnm = \"?\"}\nval _ = TeX_notation {hol = \"?\", TeX = (\"\\\\HOLTokenExists{}\",1)}\nval _ = TeX_notation {hol = UChar.exists, TeX = (\"\\\\HOLTokenExists{}\",1)}\n\nval AND_DEF =\n Definition.new_definition\n   (\"AND_DEF\",        ``/\\ = \\t1 t2. !t. (t1 ==> t2 ==> t) ==> t``);\n\nval _ = set_fixity \"/\\\\\" (Infixr 400);\nval _ = unicode_version {u = UChar.conj, tmnm = \"/\\\\\"};\nval _ = TeX_notation {hol = \"/\\\\\", TeX = (\"\\\\HOLTokenConj{}\",1)}\nval _ = TeX_notation {hol = UChar.conj, TeX = (\"\\\\HOLTokenConj{}\",1)}\n\n\nval OR_DEF =\n Definition.new_definition\n   (\"OR_DEF\",         ``\\/ = \\t1 t2. !t. (t1 ==> t) ==> (t2 ==> t) ==> t``)\n\nval _ = set_fixity \"\\\\/\" (Infixr 300)\nval _ = unicode_version {u = UChar.disj, tmnm = \"\\\\/\"}\nval _ = TeX_notation {hol = \"\\\\/\", TeX = (\"\\\\HOLTokenDisj{}\",1)}\nval _ = TeX_notation {hol = UChar.disj, TeX = (\"\\\\HOLTokenDisj{}\",1)}\n\n\nval F_DEF =\n Definition.new_definition\n   (\"F_DEF\",          ``F = !t. t``);\n\nval NOT_DEF =\n Definition.new_definition\n   (\"NOT_DEF\",        ``~ = \\t. t ==> F``);\n\n(* now allows parsing of not equal *)\nval _ = overload_on (\"<>\", “\\x:'a y:'a. ~(x = y)”)\nval _ = set_fixity \"<>\" (Infix(NONASSOC, 450))\nval _ = TeX_notation {hol=\"<>\", TeX = (\"\\\\HOLTokenNotEqual{}\",1)}\n\nval _ = set_fixity UChar.neq (Infix(NONASSOC, 450))\nval _ = overload_on (UChar.neq, “\\x:'a y:'a. ~(x = y)”)\nval _ = TeX_notation {hol=UChar.neq, TeX = (\"\\\\HOLTokenNotEqual{}\",1)}\n\nval EXISTS_UNIQUE_DEF =\nDefinition.new_definition\n(\"EXISTS_UNIQUE_DEF\", ``?! = \\P:'a->bool.\n                                    $? P /\\ !x y. P x /\\ P y ==> (x=y)``);\n\nval _ = set_fixity \"?!\" Binder\n\nval _ = unicode_version { u = UChar.exists ^ \"!\", tmnm = \"?!\"}\nval _ = TeX_notation {hol = \"?!\", TeX = (\"\\\\HOLTokenUnique{}\",2)}\nval _ = TeX_notation {hol = UChar.exists ^ \"!\", TeX = (\"\\\\HOLTokenUnique{}\",2)}\n\nval LET_DEF =\n Definition.new_definition\n   (\"LET_DEF\",        ``LET = \\(f:'a->'b) x. f x``);\n\nval COND_DEF =\n Definition.new_definition\n   (\"COND_DEF\",       ``COND = \\t t1 t2.\n                                      @x:'a. ((t=T) ==> (x=t1)) /\\\n                                             ((t=F) ==> (x=t2))``);\nval _ = overload_on (\"case\", ``COND``)\n\nval ONE_ONE_DEF =\n Definition.new_definition\n   (\"ONE_ONE_DEF\",    ``ONE_ONE = \\f:'a->'b. !x1 x2.\n                                         (f x1 = f x2) ==> (x1 = x2)``);\n\nval ONTO_DEF =\n Definition.new_definition\n   (\"ONTO_DEF\",       ``ONTO = \\f:'a->'b. !y. ?x. y = f x``);\n\nval TYPE_DEFINITION =\n Definition.new_definition\n   (\"TYPE_DEFINITION\",\n                      ``TYPE_DEFINITION = \\P:'a->bool. \\rep:'b->'a.\n                              (!x' x''. (rep x' = rep x'') ==> (x' = x'')) /\\\n                              (!x. P x = (?x'. x = rep x'))``);\n\n\n(*---------------------------------------------------------------------------*\n *   Parsing directives for some of the basic operators.                     *\n *---------------------------------------------------------------------------*)\n\nlocal\nopen Portable\nin\nval _ = add_rule {term_name   = \"~\",\n                  fixity      = Prefix 900,\n                  pp_elements = [TOK \"~\"],\n                  paren_style = OnlyIfNecessary,\n                  block_style = (AroundEachPhrase, (CONSISTENT, 0))};\nval _ = unicode_version { u = UChar.neg, tmnm = \"~\"};\nval _ = TeX_notation {hol = \"~\", TeX = (\"\\\\HOLTokenNeg{}\",1)}\nval _ = TeX_notation {hol = UChar.neg, TeX = (\"\\\\HOLTokenNeg{}\",1)}\n\n(* prettyprinting information here for \"let\" and \"and\" is completely ignored;\n   the pretty-printer handles these specially.  These declarations are only\n   for the parser's benefit. *)\nval _ = add_rule {\n      pp_elements = [TOK \"let\",\n                     ListForm {\n                       separator = [TOK \";\"],\n                       cons = GrammarSpecials.letcons_special,\n                       nilstr = GrammarSpecials.letnil_special,\n                       block_info = (INCONSISTENT, 0)\n                     },\n                     TOK \"in\"],\n      term_name = GrammarSpecials.let_special,\n      paren_style = OnlyIfNecessary, fixity = Prefix 8,\n      block_style = (AroundEachPhrase, (CONSISTENT, 0))};\n\nval _ = add_rule {term_name = GrammarSpecials.and_special,\n                  fixity = Infixl 9,\n                  pp_elements = [TOK \"and\"],\n                  paren_style = OnlyIfNecessary,\n                  block_style = (AroundEachPhrase, (INCONSISTENT, 0))}\n\nval _ = add_rule{term_name   = \"COND\",\n                 fixity      = Prefix 70,\n                 pp_elements = [PPBlock([TOK \"if\", BreakSpace(1,2), TM,\n                                         BreakSpace(1,0),\n                                         TOK \"then\"], (CONSISTENT, 0)),\n                                BreakSpace(1,2), TM, BreakSpace(1,0),\n                                TOK \"else\", BreakSpace(1,2)],\n                 paren_style = OnlyIfNecessary,\n                 block_style = (AroundEachPhrase, (CONSISTENT, 0))};\nend\nend\nend\n\\<close>\n\n\nsubsection \\<open>Prove HOL4 axioms\\<close>\n\ndeclare [[ML_environment = \"Isabelle\"]]\n\nlemmas hol4_T_def = [[hol4_thm\\<open>Bool1.T_DEF\\<close>]]\n   and hol4_F_def = [[hol4_thm\\<open>Bool1.F_DEF\\<close>]]\n   and hol4_ex_def = [[hol4_thm\\<open>Bool1.EXISTS_DEF\\<close>]]\n   and hol4_all_def = [[hol4_thm\\<open>Bool1.FORALL_DEF\\<close>]]\n   and hol4_and_def = [[hol4_thm\\<open>Bool1.AND_DEF\\<close>]]\n   and hol4_or_def = [[hol4_thm\\<open>Bool1.OR_DEF\\<close>]]\n   and hol4_not_def = [[hol4_thm\\<open>Bool1.NOT_DEF\\<close>]]\n   and hol4_one_one_def = [[hol4_thm\\<open>Bool1.ONE_ONE_DEF\\<close>]]\n   and hol4_onto_def = [[hol4_thm\\<open>Bool1.ONTO_DEF\\<close>]]\n   and hol4_type_def = [[hol4_thm\\<open>Bool1.TYPE_DEFINITION\\<close>]]\n\nlemma bool_T_equiv: \"HOL4\\<open>T\\<close> \\<longleftrightarrow> True\"\n  apply(unfold hol4_T_def)\n  apply(unfold True_def)\n  ..\nlemma bool_all_equiv: \"HOL4\\<open>! x. P x\\<close> = (\\<forall> x. P x)\"\n  thm hol4_all_def\n  apply(unfold hol4_all_def)\n  apply(subst bool_T_equiv)\n  apply(unfold All_def)\n  ..\n\nlemma bool_ex_equiv: \"HOL4\\<open>? x. P x\\<close> = (\\<exists> x. P x)\"\n  apply(unfold hol4_ex_def)\n  apply(unfold Hilbert_Choice.some_eq_ex)\n  ..\n\nML \\<open>val bool_exE = @{thm exE[folded bool_ex_equiv]}\\<close>\nML \\<open>val bool_exI = @{thm exI[folded bool_ex_equiv]}\\<close>\nML \\<open>val bool_allI = @{thm allI[folded bool_all_equiv]}\\<close>\nML \\<open>val bool_allE = @{thm allE[folded bool_all_equiv]}\\<close>\n\nlemma bool_F_equiv: \"HOL4\\<open>F\\<close> \\<longleftrightarrow> False\"\n  apply(unfold hol4_F_def)\n  apply(subst bool_all_equiv)\n  apply(unfold False_def)\n  ..\n\nlemma bool_or_equiv: \"HOL4\\<open>x \\\\/ y\\<close> = (x \\<or> y)\"\n  apply(unfold hol4_or_def)\n  apply(subst bool_all_equiv)\n  apply(subst or_def)\n  ..\n\nlemma bool_and_equiv: \"HOL4\\<open>x /\\\\ y\\<close> = (x \\<and> y)\"\n  apply(unfold hol4_and_def)\n  apply(subst bool_all_equiv)\n  apply(subst and_def)\n  ..\n\nlemma bool_not_equiv: \"HOL4\\<open>~x\\<close> = (\\<not> x)\"\n  apply(unfold hol4_not_def)\n  apply(subst bool_F_equiv)\n  apply(subst not_def)\n  ..\n\nlemma bool_one_one_equiv: \"HOL4\\<open>ONE_ONE\\<close> f = inj f\"\n  apply(unfold hol4_one_one_def)\n  apply(unfold bool_all_equiv)\n  apply(subst inj_def)\n  ..\n\nlemma bool_onto_equiv: \"HOL4\\<open>ONTO\\<close> f = surj f\"\n  apply(unfold hol4_onto_def)\n  apply(subst bool_all_equiv)\n  apply(subst bool_ex_equiv)\n  apply(subst surj_def)\n  ..\n\nlemma hol4_rep_inject: \"type_definition r a A \\<Longrightarrow> r x = r x' \\<Longrightarrow> x = x'\"\n  by (simp add: type_definition.Rep_inject)\n\nlemma hol4_abs_inverse:\nassumes tydef:\"type_definition r a A\"\n    and P:\"P = (\\<lambda>x. x \\<in> A)\"\n  shows \"P x = (\\<exists> x'. x = r x')\"\nproof \n  fix x\n  assume \"P x\" \n  then have \"r (a x) = x\" by (meson P tydef type_definition.Abs_inverse)\n  then show \"\\<exists> x'. x = r x'\" by metis\nnext\n  assume \"\\<exists>x'. x = r x'\"\n  then show \"P x\" by (meson P tydef type_definition.Rep)\nqed  \n\nlemma type_definition_equiv:\n  assumes tydef:\"type_definition r a A\"\n  shows \"HOL4\\<open>TYPE_DEFINITION\\<close>  (\\<lambda>x. x \\<in> A) r\" \n  unfolding hol4_type_def bool_all_equiv bool_and_equiv bool_ex_equiv \n  using hol4_rep_inject[OF tydef] hol4_abs_inverse[OF tydef]\n  by blast\n\nlemma bool_cases_ax_transfer: \"HOL4\\<open>!t. (t = T) \\\\/ (t = F)\\<close>\"\n  apply(subst bool_all_equiv)\n  apply(subst bool_or_equiv)\n  apply(subst bool_T_equiv)\n  apply(subst bool_F_equiv)\n  by simp\n\nlemma eta_ax_transfer: \"HOL4\\<open>!t. (\\\\x. t x) = t\\<close>\"\n  apply(subst bool_all_equiv)\n  by simp\n\nlemma select_ax_transfer: \"HOL4\\<open>!P x. P x ==> P ($@ P)\\<close>\"\n  apply(unfold bool_all_equiv)\n  apply(unfold Hilbert_Choice.some_eq_ex)\n  by simp\n\nlemma suc_infinity: \"(inj Suc_Rep) \\<and> (\\<not> surj Suc_Rep)\"\n  using Suc_Rep_inject Suc_Rep_not_Zero_Rep\n  by (metis injI surjE)\n\nlemma infinity_ax_transfer: \"HOL4\\<open>?f:ind->ind. ONE_ONE f /\\\\ ~ONTO f\\<close>\"\n  apply(subst bool_one_one_equiv)\n  apply(subst bool_onto_equiv)\n  apply(subst bool_ex_equiv)\n  apply(subst bool_and_equiv)\n  apply(subst bool_not_equiv)\n  apply(rule exI)\n  apply(insert suc_infinity)\n  .\n\nlemma bool_ex_Ex: \"bool\\<E>036\\<E>063 \\<equiv> Ex\"\n  by (simp add: bool_ex_equiv[abs_def])\n\nML \\<open>\n\nstructure IsaHOLThmTransfer =\nstruct\nval T = Thm.unvarify_global @{theory} @{thm bool_T_equiv}\nval F = Thm.unvarify_global @{theory} @{thm bool_F_equiv}\nval all = Thm.unvarify_global @{theory} @{thm bool_all_equiv}\nval exists = Thm.unvarify_global @{theory} @{thm bool_ex_equiv}\n(* Needed for typedef proof *)\nval exists_schematic = @{thm bool_ex_equiv[symmetric]}\nval bool_ex_Ex = @{thm bool_ex_Ex}\nval type_definition_equiv = @{thm type_definition_equiv}\nval disj = Thm.unvarify_global @{theory} @{thm bool_or_equiv}\nval conj = Thm.unvarify_global @{theory} @{thm bool_and_equiv}\nval not = Thm.unvarify_global @{theory} @{thm bool_not_equiv}\nval one_one = Thm.unvarify_global @{theory} @{thm bool_one_one_equiv}\nval onto = Thm.unvarify_global @{theory} @{thm bool_onto_equiv}\nval cases_ax = Thm.unvarify_global @{theory} @{thm bool_cases_ax_transfer}\nval eta_ax = Thm.unvarify_global @{theory} @{thm eta_ax_transfer}\nval select_ax = Thm.unvarify_global @{theory} @{thm select_ax_transfer}\nval infinity_ax = Thm.unvarify_global @{theory} @{thm infinity_ax_transfer}\nend\n\\<close>\n\n\ndeclare [[ML_environment = \"Isabelle>HOL4\"]]\n\nML \\<open>\nstructure IsaHOLThmTransfer = IsaHOLThmTransfer\nval bool_exE = bool_exE\nval bool_exI = bool_exI\nval bool_allE = bool_allE\nval bool_allI = bool_allI\n\\<close>\n\ndeclare [[ML_environment = \"HOL4\"]]\n\nML \\<open>\nval _ = transfer_thms := \n  SOME {ex_equiv = IsaHOLThmTransfer.exists_schematic,\n        bool_ex_Ex = IsaHOLThmTransfer.bool_ex_Ex,\n        bool_exI = bool_exI, \n        typedef_equiv = IsaHOLThmTransfer.type_definition_equiv}\n\\<close>\n\n\nML \\<open>\nstructure Bool2 = struct\n(* bool Script part 2 continue building up kernel primitives using Isabelle/HOL axioms*)\nlocal\nopen HolKernel Parse\nopen Unicode TexTokenMap\nopen Bool1\nin\n\n(*---------------------------------------------------------------------------*\n *                   AXIOMS                                                  *\n *                                                                           *\n * Bruno Barras noticed that the axiom IMP_ANTISYM_AX from the original      *\n * HOL logic was provable.                                                   *\n *---------------------------------------------------------------------------*)\n\nval BOOL_CASES_AX = save_thm (\"BOOL_CASES_AX\", Thm\n    IsaHOLThmTransfer.cases_ax);\n\nval ETA_AX = save_thm (\"ETA_AX\", Thm\n    IsaHOLThmTransfer.eta_ax);\n\nval SELECT_AX = save_thm (\"SELECT_AX\", Thm\n    IsaHOLThmTransfer.select_ax);\n\nval INFINITY_AX = save_thm (\"INFINITY_AX\", Thm\n    IsaHOLThmTransfer.infinity_ax);\n\n\n(*---------------------------------------------------------------------------*\n * Miscellaneous utility definitions, of use in some packages.               *\n *---------------------------------------------------------------------------*)\n\nval arb = new_constant(\"ARB\",alpha);  (* Doesn't have to be defined at all. *)\n\nval literal_case_DEF =\n Definition.new_definition\n   (\"literal_case_DEF\",  ``literal_case = \\(f:'a->'b) x. f x``);\n\nval _ = overload_on (\"case\", ``bool$literal_case``);\n\nval IN_DEF =\n Definition.new_definition\n   (\"IN_DEF\",         ``IN = \\x (f:'a->bool). f x``);\n\nval _ = set_fixity \"IN\" (Infix(NONASSOC, 425))\nval _ = unicode_version {u = UChar.setelementof, tmnm = \"IN\"};\nval _ = TeX_notation {hol = \"IN\", TeX = (\"\\\\HOLTokenIn{}\",1)}\nval _ = TeX_notation {hol = UChar.setelementof, TeX = (\"\\\\HOLTokenIn{}\",1)}\n\nval RES_FORALL_DEF =\n Definition.new_definition\n   (\"RES_FORALL_DEF\", ``RES_FORALL = \\p m. !x : 'a. x IN p ==> m x``);\n\nval _ = associate_restriction (\"!\",  \"RES_FORALL\")\n\nval RES_EXISTS_DEF =\n Definition.new_definition\n   (\"RES_EXISTS_DEF\", ``RES_EXISTS = \\p m. ?x : 'a. x IN p /\\ m x``);\n\nval _ = associate_restriction (\"?\",  \"RES_EXISTS\")\n\nval RES_EXISTS_UNIQUE_DEF =\n Definition.new_definition\n   (\"RES_EXISTS_UNIQUE_DEF\",\n    ``RES_EXISTS_UNIQUE =\n          \\p m. (?(x : 'a) :: p. m x) /\\ !x y :: p. m x /\\ m y ==> (x = y)``);\n\nval _ = associate_restriction (\"?!\",  \"RES_EXISTS_UNIQUE\");\n\nval RES_SELECT_DEF =\n Definition.new_definition\n   (\"RES_SELECT_DEF\", ``RES_SELECT = \\p m. @x : 'a. x IN p /\\ m x``);\n\nval _ = associate_restriction (\"@\",  \"RES_SELECT\")\n\n(* Note: RES_ABSTRACT comes later, defined by new_specification *)\n\n(*---------------------------------------------------------------------------*)\n(* Experimental rewriting directives                                         *)\n(*---------------------------------------------------------------------------*)\n\nval BOUNDED_DEF =\n  Definition.new_definition\n    (\"BOUNDED_DEF\",\n     ``BOUNDED = \\(v:bool). T``);\n\n(*---------------------------------------------------------------------------*)\n(* Support for detecting datatypes in theory files                           *)\n(*---------------------------------------------------------------------------*)\n\nval DATATYPE_TAG_DEF =\n  Definition.new_definition\n    (\"DATATYPE_TAG_DEF\",\n     ``DATATYPE = \\x. T``);\n\n(*---------------------------------------------------------------------------*\n *                   THEOREMS                                                *\n *---------------------------------------------------------------------------*)\n\nlocal\nval op --> = Type.-->\ninfix ## |->\ninfixr ==>\ninfix ==\n\n\nval ERR = Feedback.mk_HOL_ERR \"boolScript\"\nin\nval F = ``F``\nval T = ``T``;\nval implication = prim_mk_const{Name=\"==>\", Thy=\"min\"}\nval select      = prim_mk_const{Name=\"@\",   Thy=\"min\"}\nval conjunction = prim_mk_const{Name=\"/\\\\\", Thy=\"bool\"}\nval disjunction = prim_mk_const{Name=\"\\\\/\", Thy=\"bool\"}\nval negation    = prim_mk_const{Name=\"~\",   Thy=\"bool\"}\nval universal   = prim_mk_const{Name=\"!\",   Thy=\"bool\"}\nval existential = prim_mk_const{Name=\"?\",   Thy=\"bool\"}\nval exists1     = prim_mk_const{Name=\"?!\",  Thy=\"bool\"}\nval in_tm       = prim_mk_const{Name=\"IN\",  Thy=\"bool\"};\n\n\nval dest_neg    = sdest_monop(\"~\",\"bool\")   (ERR\"dest_neg\" \"\");\nval dest_eq     = sdest_binop(\"=\",\"min\")    (ERR\"dest_eq\" \"\");\nval dest_disj   = sdest_binop(\"\\\\/\",\"bool\") (ERR\"dest_disj\" \"\");\nval dest_conj   = sdest_binop(\"/\\\\\",\"bool\") (ERR\"dest_conj\" \"\");\nval dest_forall = sdest_binder(\"!\",\"bool\")  (ERR\"dest_forall\" \"\");\nval dest_exists = sdest_binder(\"?\",\"bool\")  (ERR\"dest_exists\" \"\");\nfun strip_forall fm =\n   if can dest_forall fm\n   then let val (Bvar,Body) = dest_forall fm\n            val (bvs,core) = strip_forall Body\n        in ((Bvar::bvs), core)\n        end\n   else ([],fm);\nval lhs = fst o dest_eq;\nval rhs = snd o dest_eq;\n\nfun mk_eq (lhs,rhs) =\n let val ty = type_of lhs\n     val eq = mk_thy_const{Name=\"=\",Thy=\"min\",Ty=ty-->ty-->bool}\n in list_mk_comb(eq,[lhs,rhs])\n end;\nfun mk_imp(ant,conseq) = Term.prim_mk_imp ant conseq;\n\nfun mk_exists (absrec as (Bvar,_)) =\n  mk_comb(mk_thy_const{Name=\"?\",Thy=\"bool\", Ty= (type_of Bvar-->bool)-->bool},\n          mk_abs absrec)\n\nfun mk_exists1 (absrec as (Bvar,_)) =\n  mk_comb(mk_thy_const{Name=\"?!\",Thy=\"bool\", Ty= (type_of Bvar-->bool)-->bool},\n          mk_abs absrec)\n\n\n\nval F = mk_thy_const{Name=\"F\", Thy=\"bool\", Ty=bool};\n\nval mk_neg =\n  let val notc = mk_thy_const{Name=\"~\",Thy=\"bool\",Ty=bool --> bool}\n  in fn M => mk_comb(notc,M)\n  end;\n\nval mk_forall =\n let val forallc = prim_mk_const{Name=\"!\", Thy=\"bool\"}\n in fn (v, tm) =>\n      mk_comb(inst[alpha |-> type_of v] forallc, mk_abs(v,tm))\n end;\n\nval mk_conj =\n let val conjc = prim_mk_const{Name=\"/\\\\\", Thy=\"bool\"}\n in fn (M,N) => list_mk_comb(conjc,[M,N])\n end;\n\nval mk_disj =\n let val disjc = prim_mk_const{Name=\"\\\\/\", Thy=\"bool\"}\n in fn (M,N) => list_mk_comb(disjc,[M,N])\n end;\n\nval list_mk_forall = itlist (curry mk_forall)\nval list_mk_exists = itlist (curry mk_exists)\n\nlocal val DEST_IMP_ERR = thm_err \"dest_imp\" \"\"\nopen Term KernelTypes\nin\nfun dest_imp M =\n let val (Rator,conseq) = with_exn dest_comb M DEST_IMP_ERR\n in if is_comb Rator\n    then let val (Rator,ant) = dest_comb Rator\n         in if (Isabelle.Thm.term_of (dest_Ht Rator)) = (Isabelle.Thm.term_of (dest_Ht imp)) then (ant,conseq) else raise DEST_IMP_ERR\n         end\n    else case with_exn dest_thy_const Rator DEST_IMP_ERR\n          of {Name=\"~\", Thy=\"bool\",...} => (conseq, F)\n           | otherwise => raise DEST_IMP_ERR\n end\nend\n\nfun Av s = mk_var(s, alpha)\nfun Bv s = mk_var(s, bool)\nval tb = Bv \"t\"\nval t1b = Bv \"t1\"\nval t2b = Bv \"t2\"\nval Pb = Bv \"P\"\nval Qb = Bv \"Q\"\nval Pab = mk_var(\"P\", alpha --> bool)\nval Qab = mk_var(\"Q\", alpha --> bool)\n\nval fabt = mk_var(\"f\", alpha --> beta)\nval xa = Av \"x\"\nval ya = Av \"y\"\n\nval TRUTH = save_thm(\"TRUTH\", EQ_MP (SYM T_DEF) (REFL ``\\x:bool. x``));\n\nfun RIGHT_BETA th = TRANS th (BETA_CONV(snd(dest_eq(concl th))));\n\nfun UNFOLD_OR_CONV tm =\n  let val (disj1,disj2) = dest_disj tm in\n  RIGHT_BETA(AP_THM (RIGHT_BETA(AP_THM OR_DEF disj1)) disj2)\n  end;\n\nfun CUT_EQUAL P x y t thm =\n  let val e = mk_eq(y,t) in\n  DISCH e (SUBST [(x|->SYM (ASSUME e))] P thm)\n  end;\n\nfun EQT_ELIM th = EQ_MP (SYM th) TRUTH;\n\n(*\nfun SPEC t th =\n  let\n    val _ = (t, th)\n    val (F,body) = dest_comb(concl th)\n  in\n  if (not(#1(dest_const F) = #1(dest_const universal)))\n  then raise ERR  \"SPEC\" \"\"\n  else let val (x, _) = dest_abs body\n       and v1 = genvar(type_of F)\n       and v2 = genvar(type_of body)\n       val th1 = SUBST[v1 |-> INST_TYPE[{redex   = alpha,\n                                         residue = type_of x}] FORALL_DEF]\n                      (mk_comb (v1,body)) th\n       (* th1 = |- (\\P. P = (\\x. T))(\\x. t1 x) *)\n       val th2 = BETA_CONV(concl th1)\n       (* th2 = |- (\\P. P = (\\x. T))(\\x. t1 x) = ((\\x. t1 x) = (\\x. T)) *)\n       val th3 = EQ_MP th2 th1\n       (* th3 = |- (\\x. t1 x) = (\\x. T) *)\n       val th4 = SUBST [v2 |->th3]\n                  (mk_eq ((mk_comb (body,t)), (mk_comb (v2,t))))\n                  (REFL (mk_comb (body,t)))\n       (* th4 = |- (\\x. t1 x)t = (\\x. T)t *)\n       val (ls, rs) = dest_eq(concl th4)\n       val th5 = TRANS(TRANS(SYM(BETA_CONV ls))th4)(BETA_CONV rs)\n       (* th5 = |- t1 t = T *)\n       in\n       EQT_ELIM th5\n       end\n  end\n  handle Feedback.HOL_ERR _ => raise ERR \"SPEC\" \"\";\n*)\n\nlocal open Isabelle KernelTypes\nin\nfun SPEC (KernelTypes.Ht t) th =\n  let\n    val th = Thm' th\n    val P = Thm.cconcl_of th\n      |> Thm.dest_arg (* Trueprop *)\n      |> Thm.dest_arg (* forall *)\n    val tv = Thm.apply P t\n    val ctv = mk_cTrueprop tv\n    val P_argty = Thm.ctyp_of_cterm t\n    val tv_btv = Thm.beta_conversion false tv\n      |> Drule.arg_cong_rule cTrueprop\n    val btv = Thm.cconcl_of tv_btv |> Thm.dest_equals |> snd\n    val thm1 = Thm.instantiate ([(((\"'a\", 0), Isabelle.sort), P_argty)],\n      [(((\"x\",0),Thm.typ_of P_argty),t),\n      (((\"P\", 0), Isabelle.Term.-->(P_argty |> Thm.typ_of, bool)), P),\n      (((\"R\", 0), bool), btv |> Thm.dest_arg)]) bool_allE\n    val thm2 = Thm.implies_elim thm1 th\n    val h1 = Thm.assume ctv            (* tv |- tv*)\n    val h2 = h1 |> Thm.equal_elim tv_btv  (* tv |- btv *)\n    val h3 = h2 |> Thm.implies_intr ctv  (* |- tv ==> btv *)\n  in\n    Thm.implies_elim thm2 h3 |> Thm\n  end\n  handle _ => raise ERR \"SPEC\" \"\";\nend\n\n\nfun BOOL_CASE P x t pt pf =\n  let val th0 = SPEC t BOOL_CASES_AX\n      val th1 = EQ_MP (UNFOLD_OR_CONV (concl th0)) th0\n      val th2 = SPEC (subst[(x|->t)] P) th1 in\n  MP_imp (MP_imp (th2) (CUT_EQUAL P x t T pt)) (CUT_EQUAL P x t F pf)\n  end;\n\nfun FALSITY_CONV tm = DISCH F (SPEC tm (EQ_MP F_DEF (ASSUME F)))\n\nfun EQT_INTRO th =\n   let val t = concl th\n       val x = genvar bool\n   in\n   BOOL_CASE (mk_eq (x,T)) x t (REFL T)\n     (MP_imp (FALSITY_CONV (mk_eq (F,T))) (EQ_MP (ASSUME (mk_eq(t,F))) th))\n   end;\n\n(*\nfun GEN x th =\n  let\n     val _ = (\"GEN\", x, th)\n     val th1 = ABS x (EQT_INTRO th)\n     val abs = mk_abs (x,concl th)\n     and v1 = genvar (((type_of x) --> bool) --> bool)\n     and v2 = genvar bool \n     val th2 = SUBST [v1 |-> INST_TYPE[alpha|-> (type_of x)]FORALL_DEF]\n                     (mk_eq (mk_forall (x,concl th), mk_comb (v1,abs)))\n                     (REFL (mk_forall (x,concl th)))\n     val th3 = TRANS th2 (BETA_CONV(snd(dest_eq(concl th2))))\n     in\n     SUBST [v2 |-> SYM th3] v2 th1\n     end\n     handle Feedback.HOL_ERR _ => raise ERR \"GEN\" \"\"\n*)\n\nlocal open Isabelle KernelTypes in\nfun GEN (Ht x) th =\n  let val (vn, _) = Thm.term_of x |> Term.dest_Free\n      val P = Thm.lambda x (Thm.cconcl_of (Thm' th) |> Thm.dest_arg)\n      val tv = Thm.apply P x\n      val tyx = Thm.ctyp_of_cterm x\n      val all_inst = Thm.instantiate ([(((\"'a\",0),sort), tyx)],[(((\"P\",0),Isabelle.Term.-->(tyx |> Thm.typ_of, bool)), P)]) bool_allI\n\n      val btv_tv = Thm.beta_conversion false tv\n        |> Drule.arg_cong_rule cTrueprop |> Thm.symmetric\n      val btv = Thm.cconcl_of btv_tv |> Thm.dest_equals |> fst\n      val h1 = Thm.assume btv (* btv |- btv *)\n      val h2 = h1 |> Thm.equal_elim btv_tv (* btv |- tv *)\n      val h3 = h2 |> Thm.implies_intr (Thm.cprop_of (Thm' th)) (* |- btv ==> tv *)\n      val h4 = Thm.implies_elim h3 (Thm' th) (* |- tv *)\n      val h5 = h4 |> Thm.forall_intr_name (vn,x)\n      in Thm.implies_elim all_inst h5 |> Thm\n      handle _ => raise ERR \"GEN\" \"\"\n  end\nend\n\nval FALSITY = save_thm(\"FALSITY\", GEN tb (FALSITY_CONV tb))\n\nval op==> = mk_imp\nval op== = mk_eq\n\nval IMP_ANTISYM_AX = Theory.save_thm(\n  \"IMP_ANTISYM_AX\",\n  let fun dsch t1 t2 th = DISCH (t2 ==> t1) (DISCH (t1 ==> t2) th)\n      fun sch t1 t2 = (t1==>t2) ==> (t2==>t1) ==> (t1 == t2)\n      val abs = MP_imp (FALSITY_CONV (F == T)) (MP_imp (ASSUME (T ==> F)) TRUTH)\n      val tht = BOOL_CASE (sch T t2b) t2b t2b\n                          (dsch T T (REFL T)) (dsch F T (SYM abs))\n      val thf = BOOL_CASE (sch F t2b) t2b t2b\n                          (dsch T F abs) (dsch F F (REFL F))\n  in\n    GEN t1b (GEN t2b (BOOL_CASE (sch t1b t2b) t1b t1b tht thf))\n  end);\n\nval OR_ELIM_THM = Theory.save_thm(\"OR_ELIM_THM\",\n   let val th1 = ASSUME (mk_disj (t1b,t2b))\n       val th2 = UNFOLD_OR_CONV (concl th1)\n       val th3 = SPEC tb (EQ_MP th2 th1)\n       val th4 = MP_imp (MP_imp th3 (ASSUME (mk_imp (t1b,tb))))\n                    (ASSUME (mk_imp (t2b,tb)))\n       val th4 = DISCH (mk_imp (t1b,tb)) (DISCH (mk_imp (t2b,tb)) th4)\n   in\n     GEN tb (GEN t1b (GEN t2b (DISCH (mk_disj (t1b,t2b)) th4)))\n   end);\n\nfun DISJ_CASES th1 th2 th3 =\n  let val (t1,t2) = dest_disj(concl th1)\n      and t = concl th2\n      val th4 = SPEC t2 (SPEC t1 (SPEC t OR_ELIM_THM))\n  in\n  MP_imp (MP_imp (MP_imp th4 th1) (DISCH t1 th2)) (DISCH t2 th3)\n  end\n  handle Feedback.HOL_ERR _ => raise ERR \"DISJ_CASES\"  \"\";\n\n\n(*---------------------------------------------------------------------------\n *       |- !t1 t2. t1 ==> t2 ==> t1 /\\ t2\n *---------------------------------------------------------------------------*)\n\nval AND_INTRO_THM = Theory.save_thm(\n  \"AND_INTRO_THM\",\n   let val t12 = mk_imp (t1b, mk_imp (t2b, tb))\n       val th1 = GEN tb (DISCH t12 (MP_imp (MP_imp (ASSUME t12)\n                                           (ASSUME t1b))\n                                       (ASSUME t2b)))\n       val th2 = RIGHT_BETA(AP_THM (RIGHT_BETA(AP_THM AND_DEF t1b)) t2b)\n   in\n     GEN t1b (GEN t2b (DISCH t1b (DISCH t2b (EQ_MP (SYM th2) th1))))\n   end);\n\nfun CONJ th1 th2 = MP_imp (MP_imp (SPEC (concl th2)\n                             (SPEC (concl th1) AND_INTRO_THM))\n                          th1)\n                      th2\n\nfun ADD_ASSUM t th = MP_imp (DISCH t th) (ASSUME t);\n\n(*---------------------------------------------------------------------------\n * |- !t1 t2. t1 /\\ t2 ==> t1\n *---------------------------------------------------------------------------*)\n\nval AND1_THM = Theory.save_thm(\n  \"AND1_THM\",\n  let val t12 = mk_conj(t1b, t2b)\n      val th2 = RIGHT_BETA(AP_THM (RIGHT_BETA(AP_THM AND_DEF t1b)) t2b)\n      val th3 = SPEC t1b (EQ_MP th2 (ASSUME t12))\n      val th4 = DISCH t1b (DISCH t2b (ADD_ASSUM t2b (ASSUME t1b)))\n  in\n    GEN t1b (GEN t2b (DISCH t12 (MP_imp th3 th4)))\n  end);\n\nfun CONJUNCT1 th =\n  let val (t1,t2) = dest_conj(concl th)\n  in\n  MP_imp (SPEC t2 (SPEC t1 AND1_THM)) th\n  end\n  handle Feedback.HOL_ERR _ => raise ERR \"CONJUNCT1\" \"\";\n\n(*---------------------------------------------------------------------------\n *    |- !t1 t2. t1 /\\ t2 ==> t2\n *---------------------------------------------------------------------------*)\n\nval AND2_THM = Theory.save_thm(\"AND2_THM\",\n  let val t1 = ``t1:bool``\n      and t2 = ``t2:bool``\n      val th1 = ASSUME ``^t1 /\\ ^t2``\n      val th2 = RIGHT_BETA(AP_THM (RIGHT_BETA(AP_THM AND_DEF t1)) t2)\n      val th3 = SPEC t2 (EQ_MP th2 th1)\n      val th4 = DISCH t1 (DISCH t2 (ADD_ASSUM t1 (ASSUME t2)))\n  in\n  GEN t1 (GEN t2 (DISCH ``^t1 /\\ ^t2`` (MP_imp th3 th4)))\n  end);\n\nfun CONJUNCT2 th =\n  let val (t1,t2) = dest_conj(concl th)\n  in\n  MP_imp (SPEC t2 (SPEC t1 AND2_THM)) th\n  end\n  handle Feedback.HOL_ERR _ => raise ERR \"CONJUNCT2\" \"\";\n\n(*---------------------------------------------------------------------------\n *  |- !t1 t2. t1 ==> t1 \\/ t2\n *---------------------------------------------------------------------------*)\n\nval OR_INTRO_THM1 = Theory.save_thm(\"OR_INTRO_THM1\",\n  let val t = ``t:bool``\n      and t1 = ``t1:bool``\n      and t2 = ``t2:bool``\n      val th1 = ADD_ASSUM ``^t2 ==> ^t`` (MP_imp (ASSUME ``^t1 ==> ^t``)\n                                              (ASSUME t1))\n      val th2 = GEN t (DISCH ``^t1 ==> ^t`` (DISCH ``^t2 ==> ^t`` th1))\n      val th3 = RIGHT_BETA(AP_THM (RIGHT_BETA(AP_THM OR_DEF t1)) t2)\n  in\n    GEN t1 (GEN t2 (DISCH t1 (EQ_MP (SYM th3) th2)))\n  end);\n\n(*---------------------------------------------------------------------------\n * |- !t1 t2. t2 ==> t1 \\/ t2\n *---------------------------------------------------------------------------*)\n\nval OR_INTRO_THM2 = Theory.save_thm(\"OR_INTRO_THM2\",\n  let val t  = ``t:bool``\n      and t1 = ``t1:bool``\n      and t2 = ``t2:bool``\n      val th1 = ADD_ASSUM ``^t1 ==> ^t``\n                     (MP_imp (ASSUME ``^t2 ==> ^t``) (ASSUME t2))\n      val th2 = GEN t (DISCH ``^t1 ==> ^t`` (DISCH ``^t2 ==> ^t`` th1))\n      val th3 = RIGHT_BETA(AP_THM (RIGHT_BETA(AP_THM OR_DEF t1)) t2)\n  in\n    GEN t1 (GEN t2 (DISCH t2 (EQ_MP (SYM th3) th2)))\n  end);\n\nfun DISJ1 th t2 = MP_imp (SPEC t2 (SPEC (concl th) OR_INTRO_THM1)) th\n          handle Feedback.HOL_ERR _ => raise ERR \"DISJ1\" \"\";\n\nfun DISJ2 t1 th = MP_imp (SPEC (concl th) (SPEC t1 OR_INTRO_THM2)) th\n         handle Feedback.HOL_ERR _ => raise ERR \"DISJ2\" \"\";\n\nfun SELECT_INTRO th =\n   let\n      val (Rator, Rand) = dest_comb (concl th)\n      val SELECT_AX' = INST_TYPE [alpha |-> type_of Rand] SELECT_AX\n   in\n      MP_imp (SPEC Rand (SPEC Rator SELECT_AX')) th\n   end\n   handle Feedback.HOL_ERR _ => raise ERR \"SELECT_INTRO\" \"\"\n\n(*\nfun EXISTS (fm,tm) th =\n  let val (x,t) = dest_exists fm\n      val th1 = BETA_CONV (mk_comb (mk_abs (x,t), tm))\n      (* th1 = |- (\\x. t x)t' = t t' *)\n      val th2 = EQ_MP (SYM th1) th\n      (* th2 = |- (\\x. t x)t' *)\n      val th3 = SELECT_INTRO th2\n      (* th3 = |- (\\x. t x)(@x. t x) *)\n      val th4 = AP_THM(INST_TYPE[alpha|-> type_of x]EXISTS_DEF) (mk_abs (x,t))\n      (* th4 = |- (?x. t x) = (\\P. P($@ P))(\\x. t x) *)\n      val th5 = TRANS th4 (BETA_CONV(snd(dest_eq(concl th4))))\n      (* th5 = |- (?x. t x) = (\\x. t x)(@x. t x) *)\n  in\n  EQ_MP (SYM th5) th3\n  end\n  handle Feedback.HOL_ERR _ => raise ERR \"EXISTS\" \"\";\n*)\n\nlocal open Isabelle Isabelle.Term KernelTypes\nin\nfun EXISTS (Ht fm,Ht tm) th =\n  let val P = fm |> Thm.dest_arg (* Trueprop *)\n      val tv = Thm.apply P tm\n      val tyx = Thm.ctyp_of_cterm tm\n      val ex_inst = Thm.instantiate ([(((\"'a\",0),Isabelle.sort),tyx)],\n      [(((\"P\",0), (Thm.typ_of tyx) --> bool),P),(((\"x\",0), (Thm.typ_of tyx)), tm)]) bool_exI\n      val btv_tv = Thm.beta_conversion false tv\n        |> Drule.arg_cong_rule cTrueprop |> Thm.symmetric\n      val btv = Thm.cconcl_of btv_tv |> Thm.dest_equals |> fst\n      val h1 = Thm.assume btv (* btv |- btv *)\n      val h2 = h1 |> Thm.equal_elim btv_tv (* btv |- tv *)\n      val h3 = h2 |> Thm.implies_elim ex_inst (* btv |- thm *)\n      val h4 = h3 |> Thm.implies_intr (Thm.cprop_of th) (* |- btv ==> thm *)\n  in Thm.implies_elim h4  th\n  end\nend\n\nval F_IMP = Theory.save_thm(\"F_IMP\",\n   let val t = ``t:bool``\n       val th1 = RIGHT_BETA(AP_THM NOT_DEF t)\n   in\n   GEN t (DISCH ``~^t``\n                (EQ_MP th1 (ASSUME ``~^t``)))\n   end);\n\nfun NOT_ELIM th =\n   let val (_,t) = dest_comb(concl th)\n   in MP_imp (SPEC t F_IMP) th\n   end\n   handle Feedback.HOL_ERR _ => raise ERR \"NOT_ELIM\" \"\";\n\nval IMP_F = Theory.save_thm(\"IMP_F\",\n   let val t = ``t:bool``\n       val th1 = RIGHT_BETA (AP_THM NOT_DEF t)\n   in\n     GEN t (DISCH ``^t ==> F``\n                 (EQ_MP (SYM th1) (ASSUME ``^t ==> F``)))\n   end);\n\nfun SELECT_ELIM th1 (v, th2) =\n   let val _ = (th1, v, th2)\n      val (Rator, Rand) = dest_comb (concl th1)\n      val th3 = DISCH (mk_comb (Rator, v)) th2\n      val _ = (v, th3)\n      val _ = GEN v th3\n      (* th3 = |- P v ==> t *)\n   in\n      MP_imp (SPEC Rand (GEN v th3)) th1\n   end\n   handle Feedback.HOL_ERR _ => raise ERR \"SELECT_ELIM\" \"\"\n\n(*\nfun CHOOSE (v,th1) th2 =\n  let val (x,body) = dest_exists(concl th1)\n      and t'     = concl th2\n      and v1     = genvar bool\n      val th3 = AP_THM((INST_TYPE[alpha |-> type_of v]EXISTS_DEF)) (mk_abs (x,body))\n      (* th3 = |- (?x. t x) = (\\P. P($@ P))(\\x. t x) *)\n      val th4 = EQ_MP th3 th1\n      (* th4 = |- (\\P. P($@ P))(\\x. t x) *)\n      val th5 = EQ_MP (BETA_CONV(concl th4)) th4\n      (* th5 = |- (\\x. t x)(@x. t x) *)\n      val th6 = BETA_CONV (mk_comb (mk_abs (x,body), v))\n      (* th6 = |- (\\x. t x)v = t v *)\n      val Pa = snd(dest_eq(concl th6))\n      val dth = DISCH Pa th2\n      val th7 = (SUBST [v1 |-> (SYM th6)](mk_imp (v1,t')) dth)\n      val th8 = MP_imp th7 (ASSUME (fst (dest_eq(concl th6))))\n  in\n    SELECT_ELIM th5 (v,th8)\n  end\n  handle Feedback.HOL_ERR _ => raise ERR \"CHOOSE \" \"\";\n*)\nlocal\n  open Isabelle\nin\n(*\nfun CHOOSE (KernelTypes.Ht v, ex_thm) thm =\n  let\n    val (vn, _) = Thm.term_of v |> Term.dest_Free\n    val tv = Thm.cconcl_of ex_thm\n      |> Thm.dest_arg (* Trueprop *)\n      |> Thm.dest_arg (* exists *)\n      |> Thm.dest_abs (SOME vn)\n      |> snd\n      |> mk_cTrueprop\n  in\n    Thm.implies_elim\n      (Drule.RS (ex_thm, bool_exE)\n        |> Thm.instantiate ([],[(((\"Q\", 0), bool), Thm.cconcl_of thm |> Thm.dest_arg)]))\n      (Thm.implies_intr tv thm |> Thm.forall_intr v)\n  end\n*)\nfun CHOOSE (KernelTypes.Ht v, ex_thm) thm =\n  let\n    val (vn, _) = Thm.term_of v |> Term.dest_Free\n    val P = Thm.cconcl_of ex_thm\n      |> Thm.dest_arg (* Trueprop *)\n      |> Thm.dest_arg (* exists *)\n    val tv = Thm.apply P v\n    val ctv = mk_cTrueprop tv\n    val P_argty = P |> Thm.dest_abs (SOME vn) |> fst |> Thm.ctyp_of_cterm\n    val thm1 = Thm.instantiate ([(((\"'a\", 0), Isabelle.sort), P_argty)],\n      [(((\"P\", 0), Isabelle.Term.-->(P_argty |> Thm.typ_of, bool)), P),\n      (((\"Q\", 0), bool), Thm.cconcl_of thm |> Thm.dest_arg)]) bool_exE\n    val thm2 = Thm.implies_elim thm1 ex_thm\n    val tv_btv = Thm.beta_conversion false tv (* TODO: handle if this fails*)\n      |> Drule.arg_cong_rule cTrueprop\n    val btv = Thm.cconcl_of tv_btv |> Thm.dest_equals |> snd\n    val thm3 = Thm.implies_intr btv thm  (* |- btv ==> thm *)\n    val h1 = Thm.assume (ctv)            (* tv |- tv*)\n    val h2 = h1 |> Thm.equal_elim (tv_btv)  (* tv |- btv *)\n    val h3 = h2 |> Thm.implies_elim thm3  (* tv |- thm *)\n    val h4 = h3 |> Thm.implies_intr (ctv)  (* |- tv ==> thm *)\n    val thm4 = h4 |> Thm.forall_intr v\n  in\n    Thm.implies_elim thm2 thm4\n  end\nend\n\n(* MP has this weird special case... *)\nfun MP thm1 thm2 = MP_imp thm1 thm2\n  handle Isabelle.Thm.CTERM _ => MP (MP (SPEC (concl thm2) F_IMP) thm1) thm2\n\nfun IMP_ANTISYM_RULE th1 th2 =\n  let val (ant,conseq) = dest_imp(concl th1)\n  in\n     MP (MP (SPEC conseq (SPEC ant IMP_ANTISYM_AX)) th1) th2\n  end;\n\nval IMP_CLAUSE4 =\n   let val tImpF = mk_imp (T,F)\n       val th1 = DISCH tImpF (MP (ASSUME tImpF) TRUTH)\n       and th2 = SPEC tImpF FALSITY\n       and th3 = EQT_INTRO(DISCH F (ASSUME F))\n   in\n   CONJ(IMP_ANTISYM_RULE th1 th2) th3\n   end;\n\nfun CCONTR t th =\nlet val th1 = Beta(AP_THM NOT_DEF t)\n    and v   = genvar bool\n    val th2 = EQT_ELIM (ASSUME (mk_eq (t,T)))\n    val th3 = SUBST [v |-> th1] (mk_imp (v,F)) (DISCH (mk_neg t) th)\n    val th4 = SUBST[v |-> ASSUME(mk_eq (t,F))] (mk_imp (mk_imp (v,F), F)) th3\n    val th5 = MP th4 (EQT_ELIM (CONJUNCT2 IMP_CLAUSE4))\n    val th6 = EQ_MP (SYM(ASSUME (mk_eq (t,F)))) th5\nin                                                                    \nDISJ_CASES (SPEC t BOOL_CASES_AX) th2 th6\nend handle Feedback.HOL_ERR _ => raise ERR \"CCONTR\" \"\"\n\nfun NOT_INTRO th =\n  let val (t,_) = dest_imp(concl th)\n  in MP (SPEC t IMP_F) th\n  end\n  handle Feedback.HOL_ERR _ => raise ERR \"NOT_INTRO\" \"\";\n\nend\nend\nend\n\\<close>\n\nML \\<open>\nstructure Thm : sig\n  include Thm\n  val Thm: Isabelle.Thm.thm -> thm\n  val Thm': thm -> Isabelle.Thm.thm\nend =\n struct\nopen Lib Bool2 Map_Functions Thm\n\ntype depdisk = Thm.depdisk\ntype tag = Tag.tag\ntype hol_type = KernelTypes.hol_type\ntype term = KernelTypes.term\nval kernelid = Thm.kernelid\n\nval NOT_ELIM = NOT_ELIM\nval CHOOSE = ((I ** Thm') ==> Thm' ==> Thm) CHOOSE\nval EXISTS = (I ==> Thm' ==> Thm) EXISTS\nval Specialize = SPEC\nfun add_tag (x, thm) = add_tag (x, thm)\nval GENL = itlist GEN\nend\n\\<close>\n\nsubsection \\<open>now the rest of bool theory\\<close>\nML \\<open>structure HolKernel = struct open HolKernel open Thm end\\<close>\\<comment> \\<open>add the additional Thm stuff on bool\\<close>\n\nML \\<open>\nlocal\nopen Bool1 Bool2\n(*bool script part 3*)\nopen HolKernel Parse\nopen Unicode TexTokenMap\nopen Thm\n(* also implemented in Drule *)\nfun ETA_CONV t =\n  let val (var, cmb) = dest_abs t\n      val tysubst = [alpha |-> type_of var, beta |-> type_of cmb]\n      val th = SPEC (rator cmb) (INST_TYPE tysubst (ETA_AX))\n  in\n    TRANS (ALPHA t (lhs (concl th))) th\n  end;\n\nfun EXT th =\n   let val (Bvar,_) = dest_forall(concl th)\n       val th1 = SPEC Bvar th\n       val (t1x, t2x) = dest_eq(concl th1)\n       val x = rand t1x\n       val th2 = ABS x th1\n   in\n   TRANS (TRANS(SYM(ETA_CONV (mk_abs(x, t1x)))) th2)\n         (ETA_CONV (mk_abs(x,t2x)))\n   end;\n\nlocal\nfun DISCH_ALL_rec (t::ts) th = DISCH_ALL_rec ts (DISCH t th)\n  | DISCH_ALL_rec [] th = th\nin\nfun DISCH_ALL th = DISCH_ALL_rec (hyp th) th\nend\n\nfun PROVE_HYP ath bth = MP (DISCH (concl ath) bth) ath;\n\nfun CONV_RULE conv th = EQ_MP (conv(concl th)) th;\n\nfun RAND_CONV conv tm =\n   let val (Rator,Rand) = dest_comb tm\n   in AP_TERM Rator (conv Rand)\n   end;\n\nfun RATOR_CONV conv tm =\n   let val (Rator,Rand) = dest_comb tm in AP_THM (conv Rator) Rand end;\n\nfun ABS_CONV conv tm =\n   let val (Bvar,Body) = dest_abs tm in ABS Bvar (conv Body) end;\n\nfun QUANT_CONV conv = RAND_CONV(ABS_CONV conv);\n\nfun UNDISCH th = MP th (ASSUME(fst(dest_imp(concl th))));\n\ninfixr ==>\nval op==> = mk_imp\ninfix ==\nval op== = mk_eq\n\n(*---------------------------------------------------------------------------\n * |- !t. F ==> t\n *---------------------------------------------------------------------------*)\n\nfun CONTR tm th = MP (SPEC tm FALSITY) th\n\nfun DISJ_IMP dth =\n   let val (disj1,disj2) = dest_disj (concl dth)\n       val nota = mk_neg disj1\n   in\n     DISCH nota\n      (DISJ_CASES dth\n         (CONTR disj2 (MP (ASSUME nota) (ASSUME disj1)))\n         (ASSUME disj2))\n   end\n\nfun EQF_INTRO th = IMP_ANTISYM_RULE (NOT_ELIM th)\n        (DISCH ``F`` (CONTR (dest_neg (concl th)) (ASSUME ``F``)));\n\nfun SELECT_EQ x =\n let val ty = type_of x\n     val choose = mk_const(\"@\", (ty --> Type.bool) --> ty)\n in\n  fn th => AP_TERM choose (ABS x th)\n end\n\nval GENL = Thm.GENL;\n\nfun SPECL tm_list th = rev_itlist SPEC tm_list th\n\nfun GEN_ALL th =\n  itlist GEN (op_set_diff aconv (free_vars(concl th)) (free_varsl (hyp th))) th;\n\nlocal fun f v (vs,l) = let val v' = variant vs v in (v'::vs, v'::l) end\nin\nfun SPEC_ALL th =\n   let val (hvs,con) = (free_varsl ## I) (hyp th, concl th)\n       val fvs = free_vars con\n       and vars = fst(strip_forall con)\n   in\n     SPECL (snd(itlist f vars (hvs@fvs,[]))) th\n   end\nend;\n\nfun SUBST_CONV theta template tm =\n  let fun retheta {redex,residue} = (redex |-> genvar(type_of redex))\n      val theta0 = map retheta theta\n      val theta1 = map (op |-> o (#residue ## #residue)) (zip theta0 theta)\n  in\n   SUBST theta1 (mk_eq(tm,subst theta0 template)) (REFL tm)\n  end;\n\nlocal fun combine [] [] = []\n        | combine (v::rst1) (t::rst2) = (v |-> t) :: combine rst1 rst2\n        | combine _ _ = raise Fail \"SUBS\"\nin\nfun SUBS ths th =\n   let val ls = map (lhs o concl) ths\n       val vars = map (genvar o type_of) ls\n       val w = subst (combine ls vars) (concl th)\n   in\n     SUBST (combine vars ths) w th\n   end\nend;\n\nfun IMP_TRANS th1 th2 =\n   let val (ant,conseq) = dest_imp(concl th1)\n   in DISCH ant (MP th2 (MP th1 (ASSUME ant))) end;\n\nfun SPEC_VAR th =\n   let val (Bvar,_) = dest_forall (concl th)\n       val bv' = variant (free_varsl (hyp th)) Bvar\n   in (bv', SPEC bv' th)\n   end;\n\nfun MK_EXISTS bodyth =\n   let val (x, sth) = SPEC_VAR bodyth\n       val (a,b) = dest_eq (concl sth)\n       val (abimp,baimp) = EQ_IMP_RULE sth\n       fun HALF (p,q) pqimp =\n          let val xp = mk_exists(x,p)\n              and xq = mk_exists(x,q)\n          in DISCH xp\n              (CHOOSE (x, ASSUME xp) (EXISTS (xq,x) (MP pqimp (ASSUME p))))\n          end\n   in\n     IMP_ANTISYM_RULE (HALF (a,b) abimp) (HALF (b,a) baimp)\n   end;\n\nfun SELECT_RULE th =\n  let val (tm as (Bvar, Body)) = dest_exists(concl th)\n      val v = genvar(type_of Bvar)\n      val P = mk_abs tm\n      val SELECT_AX' = INST_TYPE[alpha |-> type_of Bvar] SELECT_AX\n      val th1 = SPEC v (SPEC P SELECT_AX')\n      val (ant,conseq) = dest_imp(concl th1)\n      val th2 = BETA_CONV ant\n      and th3 = BETA_CONV conseq\n      val th4 = EQ_MP th3 (MP th1 (EQ_MP(SYM th2) (ASSUME (rhs(concl th2)))))\n  in\n     CHOOSE (v,th) th4\n  end;\n\n\n(*---------------------------------------------------------------------------\n     ETA_THM = |- !M. (\\x. M x) = M\n ---------------------------------------------------------------------------*)\n\nval ETA_THM = save_thm(\"ETA_THM\", GEN_ALL(ETA_CONV ``\\x:'a. (M x:'b)``));\n\n(*---------------------------------------------------------------------------\n *  |- !t. t \\/ ~t\n *---------------------------------------------------------------------------*)\n\nval EXCLUDED_MIDDLE = save_thm(\n  \"EXCLUDED_MIDDLE\",\n  let val th1 = RIGHT_BETA(AP_THM NOT_DEF tb)\n      val th2 = DISJ1 (EQT_ELIM (ASSUME (tb == T))) (mk_neg tb)\n      and th3 = DISJ2 tb (EQ_MP (SYM th1)\n                                (DISCH tb (EQ_MP (ASSUME (tb == F))\n                                                         (ASSUME tb))))\n  in\n     GEN tb (DISJ_CASES (SPEC tb BOOL_CASES_AX) th2 th3)\n  end)\n\nfun IMP_ELIM th =\n  let val (ant,conseq) = dest_imp (concl th)\n       val not_t1 = mk_neg ant\n  in\n   DISJ_CASES (SPEC ant EXCLUDED_MIDDLE)\n              (DISJ2 not_t1 (MP th (ASSUME ant)))\n              (DISJ1 (ASSUME not_t1) conseq)\n  end;\n\n(*---------------------------------------------------------------------------*\n *  |- !f y. (\\x. f x) y = f y                                               *\n *---------------------------------------------------------------------------*)\n\nval BETA_THM = save_thm(\n  \"BETA_THM\",\n  GENL [fabt, ya] (BETA_CONV ``(\\x. (f:'a->'b) x) y``))\n\n(*---------------------------------------------------------------------------\n     LET_THM = |- !f x. LET f x = f x\n ---------------------------------------------------------------------------*)\n\nval LET_THM = save_thm(\n  \"LET_THM\",\n  GEN fabt (GEN xa\n    (RIGHT_BETA(AP_THM (RIGHT_BETA(AP_THM LET_DEF fabt)) xa))))\n\n(* |- $! f <=> !x. f x *)\nval FORALL_THM = save_thm(\n  \"FORALL_THM\",\n  SYM (AP_TERM ``$! :('a->bool)->bool``\n               (ETA_CONV ``\\x:'a. f x:bool``)))\n\n(* |- $? f <=> ?x. f x *)\nval EXISTS_THM = save_thm(\n  \"EXISTS_THM\",\n  SYM (AP_TERM ``$? :('a->bool)->bool``\n               (ETA_CONV ``\\x:'a. f x:bool``)));\n\n(*---------------------------------------------------------------------------*\n *  |- !t1:'a. !t2:'b. (\\x. t1) t2 = t1                                      *\n *---------------------------------------------------------------------------*)\n\nval ABS_SIMP = save_thm(\"ABS_SIMP\",\n   GENL [``t1:'a``, ``t2:'b``]\n        (BETA_CONV ``(\\x:'b. t1:'a) t2``));\n\n(*---------------------------------------------------------------------------\n *   |- !t. (!x.t)  =  t\n *---------------------------------------------------------------------------*)\n\nval FORALL_SIMP = save_thm(\n  \"FORALL_SIMP\",\n  GEN tb (IMP_ANTISYM_RULE\n           (DISCH ``!^xa. ^tb`` (SPEC xa (ASSUME ``!^xa.^tb``)))\n           (DISCH tb (GEN xa (ASSUME tb)))));\n\n(*---------------------------------------------------------------------------\n *   |- !t. (?x.t)  =  t\n *---------------------------------------------------------------------------*)\nval EXISTS_SIMP = save_thm(\n  \"EXISTS_SIMP\",\n  let val ext = mk_exists(xa,tb)\n  in\n  GEN tb (IMP_ANTISYM_RULE\n              (DISCH ext (CHOOSE(Av \"p\", ASSUME ext) (ASSUME tb)))\n              (DISCH tb (EXISTS(ext, Av \"r\") (ASSUME tb))))\n  end);\n\n(* CONJ, CONJUNCT1 and CONJUNCT2 should be built here.*)\n\nfun CONJ_PAIR thm = (CONJUNCT1 thm, CONJUNCT2 thm);\n\nfun CONJUNCTS th =\n  (CONJUNCTS (CONJUNCT1 th) @ CONJUNCTS (CONJUNCT2 th)) handle _ => [th];\n\nval LIST_CONJ = end_itlist CONJ\n\n(*---------------------------------------------------------------------------\n *   |- !t1 t2. (t1 /\\ t2) = (t2 /\\ t1)\n *---------------------------------------------------------------------------*)\n\nval CONJ_SYM = save_thm(\"CONJ_SYM\",\n  let val t1 = ``t1:bool``\n      and t2 = ``t2:bool``\n      val th1 = ASSUME ``^t1 /\\ ^t2``\n      and th2 = ASSUME ``^t2 /\\ ^t1``\n  in\n  GEN t1 (GEN t2 (IMP_ANTISYM_RULE\n                 (DISCH ``^t1 /\\ ^t2``\n                        (CONJ(CONJUNCT2 th1)(CONJUNCT1 th1)))\n                 (DISCH ``^t2 /\\ ^t1``\n                        (CONJ(CONJUNCT2 th2)(CONJUNCT1 th2)))))\n  end);\n\nval CONJ_COMM = save_thm(\"CONJ_COMM\", CONJ_SYM);\n\n(*---------------------------------------------------------------------------\n * |- !t1 t2 t3. t1 /\\ (t2 /\\ t3) = (t1 /\\ t2) /\\ t3\n *---------------------------------------------------------------------------*)\n\nval CONJ_ASSOC = save_thm(\"CONJ_ASSOC\",\n  let val t1 = ``t1:bool``\n      and t2 = ``t2:bool``\n      and t3 = ``t3:bool``\n      val th1 = ASSUME ``^t1 /\\ (^t2 /\\ ^t3)``\n      val th2 = ASSUME ``(^t1 /\\ ^t2) /\\ ^t3``\n      val th3 = DISCH ``^t1 /\\ (^t2 /\\ ^t3)``\n                   (CONJ (CONJ(CONJUNCT1 th1)\n                              (CONJUNCT1(CONJUNCT2 th1)))\n                         (CONJUNCT2(CONJUNCT2 th1)))\n      and th4 = DISCH ``(^t1 /\\ ^t2) /\\ ^t3``\n                   (CONJ (CONJUNCT1(CONJUNCT1 th2))\n                         (CONJ(CONJUNCT2(CONJUNCT1 th2))\n                              (CONJUNCT2 th2)))\n  in\n  GEN t1 (GEN t2 (GEN t3 (IMP_ANTISYM_RULE th3 th4)))\n  end);\n\n\n(*---------------------------------------------------------------------------\n * |- !t t1 t2. (t1 \\/ t2) ==> (t1 ==> t) ==> (t2 ==> t) ==> t\n *---------------------------------------------------------------------------*)\n\nval OR_ELIM_THM = save_thm(\"OR_ELIM_THM\",\n   let val t =  ``t:bool``\n       and t1 = ``t1:bool``\n       and t2 = ``t2:bool``\n       val th1 = ASSUME ``^t1 \\/ ^t2``\n       val th2 = UNFOLD_OR_CONV (concl th1)\n       val th3 = SPEC t (EQ_MP th2 th1)\n       val th4 = MP (MP th3 (ASSUME ``^t1 ==> ^t``))\n                    (ASSUME ``^t2 ==> ^t``)\n       val th4 = DISCH ``^t1 ==> ^t`` (DISCH ``^t2 ==> ^t`` th4)\n   in\n     GEN t (GEN t1 (GEN t2 (DISCH ``^t1 \\/ ^t2`` th4)))\n   end);\n\n(* DISJ1, DISJ2, DISJ_CASES should be built here. *)\n\nfun DISJ_CASES_UNION dth ath bth =\n    DISJ_CASES dth (DISJ1 ath (concl bth)) (DISJ2 (concl ath) bth);\n\n(*---------------------------------------------------------------------------\n * |- !t. (t ==> F) ==> ~t\n *---------------------------------------------------------------------------*)\n\nval IMP_F = save_thm(\"IMP_F\",\n   let val t = ``t:bool``\n       val th1 = RIGHT_BETA (AP_THM NOT_DEF t)\n   in\n     GEN t (DISCH ``^t ==> F``\n                 (EQ_MP (SYM th1) (ASSUME ``^t ==> F``)))\n   end);\n\n(*---------------------------------------------------------------------------\n * |- !t. ~t ==> (t ==> F)\n *---------------------------------------------------------------------------*)\n\nval F_IMP = save_thm(\"F_IMP\",\n   let val t = ``t:bool``\n       val th1 = RIGHT_BETA(AP_THM NOT_DEF t)\n   in\n   GEN t (DISCH ``~^t``\n                (EQ_MP th1 (ASSUME ``~^t``)))\n   end);\n\n(*---------------------------------------------------------------------------\n * |- !t. ~t ==> (t=F)\n *---------------------------------------------------------------------------*)\n\nval NOT_F = save_thm(\"NOT_F\",\n   let val t = ``t:bool``\n       val th1 = MP (SPEC t F_IMP) (ASSUME ``~ ^t``)\n       and th2 = SPEC t FALSITY\n       val th3 = IMP_ANTISYM_RULE th1 th2\n   in\n     GEN t (DISCH ``~^t`` th3)\n   end);\n\n(*---------------------------------------------------------------------------\n *  |- !t. ~(t /\\ ~t)\n *---------------------------------------------------------------------------*)\n\nval NOT_AND = save_thm(\"NOT_AND\",\n   let val th = ASSUME ``t /\\ ~t``\n   in NOT_INTRO(DISCH ``t /\\ ~t``\n      (MP (CONJUNCT2 th) (CONJUNCT1 th)))\n   end);\n\n(*---------------------------------------------------------------------------\n * |- !t. (T /\\ t) = t\n *---------------------------------------------------------------------------*)\n\nval AND_CLAUSE1 =\n   let val t = ``t:bool``\n       val th1 = DISCH ``T /\\ ^t`` (CONJUNCT2(ASSUME ``T /\\ ^t``))\n       and th2 = DISCH t (CONJ TRUTH (ASSUME t))\n   in\n   GEN t (IMP_ANTISYM_RULE th1 th2)\n   end;\n\n(*---------------------------------------------------------------------------\n *  |- !t. (t /\\ T) = t\n *---------------------------------------------------------------------------*)\n\nval AND_CLAUSE2 =\n   let val t = ``t:bool``\n       val th1 = DISCH ``^t /\\ T`` (CONJUNCT1(ASSUME ``^t /\\ T``))\n       and th2 = DISCH t (CONJ (ASSUME t) TRUTH)\n   in\n     GEN t (IMP_ANTISYM_RULE th1 th2)\n   end;\n\n(*---------------------------------------------------------------------------\n *   |- !t. (F /\\ t) = F\n *---------------------------------------------------------------------------*)\n\nval AND_CLAUSE3 =\n   let val t = ``t:bool``\n       val th1 = IMP_TRANS (SPEC t (SPEC ``F`` AND1_THM))\n                           (SPEC ``F`` FALSITY)\n       and th2 = SPEC ``F /\\ ^t`` FALSITY\n   in\n     GEN t (IMP_ANTISYM_RULE th1 th2)\n   end;\n\n(*---------------------------------------------------------------------------\n *   |- !t. (t /\\ F) = F\n *---------------------------------------------------------------------------*)\n\nval AND_CLAUSE4 =\n   let val t = ``t:bool``\n       val th1 = IMP_TRANS (SPEC ``F`` (SPEC t AND2_THM))\n                           (SPEC ``F`` FALSITY)\n       and th2 = SPEC ``^t /\\ F`` FALSITY\n   in\n     GEN t (IMP_ANTISYM_RULE th1 th2)\n   end;\n\n(*---------------------------------------------------------------------------\n *    |- !t. (t /\\ t) = t\n *---------------------------------------------------------------------------*)\n\nval AND_CLAUSE5 =\n   let val t = ``t:bool``\n       val th1 = DISCH ``^t /\\ ^t`` (CONJUNCT1(ASSUME ``^t /\\ ^t``))\n       and th2 = DISCH t (CONJ(ASSUME t)(ASSUME t))\n   in\n     GEN t (IMP_ANTISYM_RULE th1 th2)\n   end;\n\n(*---------------------------------------------------------------------------\n *  |- !t. (T /\\ t) = t /\\\n *         (t /\\ T) = t /\\\n *         (F /\\ t) = F /\\\n *         (t /\\ F) = F /\\\n *         (t /\\ t) = t\n *---------------------------------------------------------------------------*)\n\nval AND_CLAUSES = save_thm(\"AND_CLAUSES\",\n   let val t = ``t:bool``\n   in\n   GEN t (LIST_CONJ [SPEC t AND_CLAUSE1, SPEC t AND_CLAUSE2,\n                     SPEC t AND_CLAUSE3, SPEC t AND_CLAUSE4,\n                     SPEC t AND_CLAUSE5])\n   end);\n\n(*---------------------------------------------------------------------------\n *   |- !t. (T \\/ t) = T\n *---------------------------------------------------------------------------*)\n\nval OR_CLAUSE1 =\n   let val t = ``t:bool``\n       val th1 = DISCH ``T \\/ ^t`` TRUTH\n       and th2 = DISCH ``T`` (DISJ1 TRUTH t)\n   in\n   GEN t (IMP_ANTISYM_RULE th1 th2)\n   end;\n\n(*---------------------------------------------------------------------------\n *  |- !t. (t \\/ T) = T\n *---------------------------------------------------------------------------*)\n\nval OR_CLAUSE2 =\n   let val t = ``t:bool``\n       val th1 = DISCH ``^t \\/ T`` TRUTH\n       and th2 = DISCH ``T`` (DISJ2 t TRUTH)\n   in\n   GEN t (IMP_ANTISYM_RULE th1 th2)\n   end;\n\n(*---------------------------------------------------------------------------\n *    |- (F \\/ t) = t\n *---------------------------------------------------------------------------*)\n\nval OR_CLAUSE3 =\n   let val t = ``t:bool``\n       val th1 = DISCH ``F \\/ ^t`` (DISJ_CASES (ASSUME ``F \\/ ^t``)\n                                        (UNDISCH (SPEC t FALSITY))\n                                        (ASSUME t))\n       and th2 = SPEC t (SPEC ``F`` OR_INTRO_THM2)\n   in\n   GEN t (IMP_ANTISYM_RULE th1 th2)\n   end;\n\n(*---------------------------------------------------------------------------\n *    |- !t. (t \\/ F) = t\n *---------------------------------------------------------------------------*)\n\nval OR_CLAUSE4 =\n   let val t = ``t:bool``\n       val th1 = DISCH ``^t \\/ F`` (DISJ_CASES (ASSUME ``^t \\/ F``)\n                                             (ASSUME t)\n                                             (UNDISCH (SPEC t FALSITY)))\n       and th2 = SPEC ``F`` (SPEC t OR_INTRO_THM1)\n   in\n   GEN t (IMP_ANTISYM_RULE th1 th2)\n   end;\n\n(*---------------------------------------------------------------------------\n *   |- !t. (t \\/ t) = t\n *---------------------------------------------------------------------------*)\n\nval OR_CLAUSE5 =\n   let val t = ``t:bool``\n       val th1 = DISCH ``^t \\/ ^t``\n                  (DISJ_CASES(ASSUME ``^t \\/ ^t``) (ASSUME t) (ASSUME t))\n       and th2 = DISCH t (DISJ1(ASSUME t)t)\n   in\n   GEN t (IMP_ANTISYM_RULE th1 th2)\n   end;\n\n(*---------------------------------------------------------------------------\n * |- !t. (T \\/ t) = T /\\\n *        (t \\/ T) = T /\\\n *        (F \\/ t) = t /\\\n *        (t \\/ F) = t /\\\n *        (t \\/ t) = t\n *---------------------------------------------------------------------------*)\n\nval OR_CLAUSES = save_thm(\"OR_CLAUSES\",\n   let val t = ``t:bool``\n   in\n   GEN t (LIST_CONJ [SPEC t OR_CLAUSE1, SPEC t OR_CLAUSE2,\n                     SPEC t OR_CLAUSE3, SPEC t OR_CLAUSE4,\n                     SPEC t OR_CLAUSE5])\n   end);\n\n(*---------------------------------------------------------------------------\n *  |- !t. (T ==> t) = t\n *---------------------------------------------------------------------------*)\n\nval IMP_CLAUSE1 =\n   let val t = ``t:bool``\n       val th1 = DISCH ``T ==> ^t`` (MP (ASSUME ``T ==> ^t``) TRUTH)\n       and th2 = DISCH t (DISCH ``T`` (ADD_ASSUM ``T`` (ASSUME t)))\n   in\n   GEN t (IMP_ANTISYM_RULE th1 th2)\n   end;\n\n(*---------------------------------------------------------------------------\n *  |- !t. (F ==> t) = T\n *---------------------------------------------------------------------------*)\n\nval IMP_CLAUSE2 =\n   let val t = ``t:bool``\n   in GEN t (EQT_INTRO(SPEC t FALSITY))\n   end;\n\n(*---------------------------------------------------------------------------\n *  |- !t. (t ==> T) = T\n *---------------------------------------------------------------------------*)\n\nval IMP_CLAUSE3 =\n   let val t = ``t:bool``\n   in GEN t (EQT_INTRO(DISCH t (ADD_ASSUM t TRUTH)))\n   end;\n\n(*---------------------------------------------------------------------------\n *  |- ((T ==> F) = F) /\\ ((F ==> F) = T)\n *---------------------------------------------------------------------------*)\nval IMP_CLAUSE4 = IMP_CLAUSE4\n\n(*---------------------------------------------------------------------------\n *  |- !t. (t ==> F) = ~t\n *---------------------------------------------------------------------------*)\n\nval IMP_CLAUSE5 =\n    let val t = ``t:bool``\n        val th1 = SPEC t IMP_F\n        and th2 = SPEC t F_IMP\n    in\n    GEN t (IMP_ANTISYM_RULE th1 th2)\n    end;\n\n(*---------------------------------------------------------------------------\n *  |- !t. (T ==> t) = t /\\\n *         (t ==> T) = T /\\\n *         (F ==> t) = T /\\\n *         (t ==> t) = t /\\\n *         (t ==> F) = ~t\n *---------------------------------------------------------------------------*)\n\nval IMP_CLAUSES = save_thm(\"IMP_CLAUSES\",\n   let val t = ``t:bool``\n   in GEN t\n      (LIST_CONJ [SPEC t IMP_CLAUSE1, SPEC t IMP_CLAUSE3,\n                  SPEC t IMP_CLAUSE2, EQT_INTRO(DISCH t (ASSUME t)),\n                  SPEC t IMP_CLAUSE5])\n   end);\n\n(*----------------------------------------------------------------------------\n *    |- (~~t = t) /\\ (~T = F) /\\ (~F = T)\n *---------------------------------------------------------------------------*)\n\nval NOT_CLAUSES = save_thm(\"NOT_CLAUSES\",\n CONJ\n  (GEN ``t:bool``\n    (IMP_ANTISYM_RULE\n      (DISJ_IMP(IMP_ELIM(DISCH ``t:bool`` (ASSUME ``t:bool``))))\n      (DISCH ``t:bool``\n       (NOT_INTRO(DISCH ``~t`` (UNDISCH (NOT_ELIM(ASSUME ``~t``))))))))\n  (CONJ (IMP_ANTISYM_RULE\n          (DISCH ``~T``\n                 (MP (MP (SPEC ``T`` F_IMP) (ASSUME ``~T``)) TRUTH))\n          (SPEC ``~T`` FALSITY))\n        (IMP_ANTISYM_RULE (DISCH ``~F`` TRUTH)\n                          (DISCH ``T`` (MP (SPEC ``F`` IMP_F)\n                                               (SPEC ``F`` FALSITY))))));\n\n(*---------------------------------------------------------------------------\n *   |- !x. x=x\n *---------------------------------------------------------------------------*)\n\nval EQ_REFL = save_thm(\"EQ_REFL\", GEN ``x : 'a`` (REFL ``x : 'a``));\n\n(*---------------------------------------------------------------------------\n *   |- !x. (x=x) = T\n *---------------------------------------------------------------------------*)\n\nval REFL_CLAUSE = save_thm(\"REFL_CLAUSE\",\n  GEN ``x: 'a`` (EQT_INTRO(SPEC ``x:'a`` EQ_REFL)));\n\n(*---------------------------------------------------------------------------\n *   |- !x y. x=y  ==>  y=x\n *---------------------------------------------------------------------------*)\n\nval EQ_SYM = save_thm(\"EQ_SYM\",\n let val x = ``x:'a``\n     and y = ``y:'a``\n in\n   GEN x (GEN y (DISCH ``^x = ^y`` (SYM(ASSUME ``^x = ^y``))))\n end);\n\n(*---------------------------------------------------------------------------\n *    |- !x y. (x = y) = (y = x)\n *---------------------------------------------------------------------------*)\n\nval EQ_SYM_EQ = save_thm(\"EQ_SYM_EQ\",\n   GEN ``x:'a``\n    (GEN ``y:'a``\n      (IMP_ANTISYM_RULE (SPEC ``y:'a`` (SPEC ``x:'a`` EQ_SYM))\n                        (SPEC ``x:'a`` (SPEC ``y:'a`` EQ_SYM)))));\n\n(*---------------------------------------------------------------------------\n *    |- !f g. (!x. f x = g x)  ==>  f=g\n *---------------------------------------------------------------------------*)\n\nval EQ_EXT = save_thm(\"EQ_EXT\",\n   let val f = ``f:'a->'b``\n       and g = ``g: 'a -> 'b``\n   in\n   GEN f (GEN g (DISCH ``!x:'a. ^f (x:'a) = ^g (x:'a)``\n                       (EXT(ASSUME ``!x:'a. ^f (x:'a) = ^g (x:'a)``))))\n   end);\n\n(*---------------------------------------------------------------------------\n      FUN_EQ_THM  |- !f g. (f = g) = !x. f x = g x\n ---------------------------------------------------------------------------*)\n\nval FUN_EQ_THM = save_thm(\"FUN_EQ_THM\",\n   let\n    val f = ``f:'a->'b``\n    val g = ``g: 'a -> 'b``\n    val x = ``x: 'a``\n    val f_eq_g = mk_eq(f,g)\n    val fx_eq_gx = mk_eq(mk_comb(f,x),mk_comb(g,x))\n    val uq_f_eq_g = mk_forall (x, fx_eq_gx)\n    val th1 = GEN x (AP_THM (ASSUME f_eq_g) x)\n    val th2 = MP (SPEC_ALL EQ_EXT) (ASSUME uq_f_eq_g);\n  in\n    GEN f (GEN g\n        (IMP_ANTISYM_RULE (DISCH_ALL th1) (DISCH_ALL th2)))\n  end);\n\n(*---------------------------------------------------------------------------\n *    |- !x y z. x=y  /\\  y=z  ==>  x=z\n *---------------------------------------------------------------------------*)\n\nval EQ_TRANS = save_thm(\"EQ_TRANS\",\n   let val x = ``x:'a``\n       and y = ``y:'a``\n       and z = ``z:'a``\n       val xyyz  = ``(^x = ^y) /\\ (^y = ^z)``\n   in\n   GEN x\n    (GEN y\n     (GEN z\n      (DISCH xyyz\n       (TRANS (CONJUNCT1(ASSUME xyyz))\n              (CONJUNCT2(ASSUME xyyz))))))\n   end);\n\n(*---------------------------------------------------------------------------\n *     |- ~(T=F) /\\ ~(F=T)\n *---------------------------------------------------------------------------*)\n\nval BOOL_EQ_DISTINCT = save_thm(\"BOOL_EQ_DISTINCT\",\n   let val TF = ``T = F``\n       and FT = ``F = T``\n   in\n   CONJ\n    (NOT_INTRO(DISCH TF (EQ_MP (ASSUME TF) TRUTH)))\n    (NOT_INTRO(DISCH FT (EQ_MP (SYM(ASSUME FT)) TRUTH)))\n   end);\n\n(*---------------------------------------------------------------------------\n *     |- !t. (T = t) = t\n *---------------------------------------------------------------------------*)\n\nval EQ_CLAUSE1 =\n   let val t = ``t:bool``\n       val Tt = ``T = ^t``\n       val th1 = DISCH Tt (EQ_MP (ASSUME Tt) TRUTH)\n       and th2 = DISCH t (SYM(EQT_INTRO(ASSUME t)))\n   in\n   GEN t (IMP_ANTISYM_RULE th1 th2)\n   end;\n\n(*---------------------------------------------------------------------------\n *  |- !t. (t = T) = t\n *---------------------------------------------------------------------------*)\n\nval EQ_CLAUSE2 =\n   let val t = ``t:bool``\n       val tT = ``^t = T``\n       val th1 = DISCH tT (EQ_MP (SYM (ASSUME tT)) TRUTH)\n       and th2 = DISCH t (EQT_INTRO(ASSUME t))\n   in\n   GEN t (IMP_ANTISYM_RULE th1 th2)\n   end;\n\n(*---------------------------------------------------------------------------\n *    |- !t. (F = t) = ~t\n *---------------------------------------------------------------------------*)\n\nval EQ_CLAUSE3 =\n   let val t = ``t:bool``\n       val Ft = ``F = ^t``\n       val tF = ``^t = F``\n       val th1 = DISCH Ft (MP (SPEC t IMP_F)\n                              (DISCH t (EQ_MP(SYM(ASSUME Ft))\n                                             (ASSUME t))))\n       and th2 = IMP_TRANS (SPEC t NOT_F)\n                           (DISCH tF (SYM(ASSUME tF)))\n   in\n   GEN t (IMP_ANTISYM_RULE th1 th2)\n   end;\n\n(*---------------------------------------------------------------------------\n *  |- !t. (t = F) = ~t\n *---------------------------------------------------------------------------*)\n\nval EQ_CLAUSE4 =\n   let val t = ``t:bool``\n       val tF = ``^t = F``\n       val th1 = DISCH tF (MP (SPEC t IMP_F)\n                              (DISCH t (EQ_MP(ASSUME tF)\n                                             (ASSUME t))))\n       and th2 = SPEC t NOT_F\n   in\n   GEN t (IMP_ANTISYM_RULE th1 th2)\n   end;\n\n(*---------------------------------------------------------------------------\n *  |- !t.  (T = t)  =  t  /\\\n *          (t = T)  =  t  /\\\n *          (F = t)  =  ~t /\\\n *          (t = F)  =  ~t\n *---------------------------------------------------------------------------*)\n\nval EQ_CLAUSES = save_thm(\"EQ_CLAUSES\",\n   let val t = ``t:bool``\n   in\n   GEN t (LIST_CONJ [SPEC t EQ_CLAUSE1, SPEC t EQ_CLAUSE2,\n                     SPEC t EQ_CLAUSE3, SPEC t EQ_CLAUSE4])\n   end);\n\n(*---------------------------------------------------------------------------\n *    |- !t1 t2 :'a. COND T t1 t2 = t1\n *---------------------------------------------------------------------------*)\n\nval COND_CLAUSE1 =\n let val (x,t1,t2,v) = (``x:'a``, ``t1:'a``,\n                        ``t2:'a``, genvar Type.bool)\n     val th1 = RIGHT_BETA(AP_THM\n                 (RIGHT_BETA(AP_THM\n                    (RIGHT_BETA(AP_THM COND_DEF ``T``)) t1))t2)\n     val TT = EQT_INTRO(REFL ``T``)\n     val th2 = SUBST [v |-> SYM TT]\n                     ``(^v ==> (^x=^t1)) = (^x=^t1)``\n                     (CONJUNCT1 (SPEC ``^x=^t1`` IMP_CLAUSES))\n     and th3 = DISCH ``T=F``\n                     (MP (SPEC ``^x=^t2`` FALSITY)\n                         (UNDISCH(MP (SPEC ``T=F`` F_IMP)\n                                     (CONJUNCT1 BOOL_EQ_DISTINCT))))\n     val th4 = DISCH ``^x=^t1``\n                     (CONJ(EQ_MP(SYM th2)(ASSUME ``^x=^t1``))th3)\n     and th5 = DISCH ``((T=T) ==> (^x=^t1))/\\((T=F) ==> (^x=^t2))``\n                     (MP (CONJUNCT1(ASSUME ``((T=T) ==> (^x=^t1))/\\\n                                               ((T=F) ==> (^x=^t2))``))\n                         (REFL ``T``))\n     val th6 = IMP_ANTISYM_RULE th4 th5\n     val th7 = TRANS th1 (SYM(SELECT_EQ x th6))\n     val th8 = EQ_MP (SYM(BETA_CONV ``(\\ ^x.^x = ^t1) ^t1``)) (REFL t1)\n     val th9 = MP (SPEC t1 (SPEC ``\\ ^x.^x = ^t1`` SELECT_AX)) th8\n in\n   GEN t1 (GEN t2 (TRANS th7 (EQ_MP (BETA_CONV(concl th9)) th9)))\n end;\n\n(*---------------------------------------------------------------------------\n *    |- !tm1 tm2:'a. COND F tm1 tm2 = tm2\n *\n *   Note that there is a bound variable conflict if we use use t1\n *   and t2 as the variable names. That would be a good test of the\n *   substitution algorithm.\n *---------------------------------------------------------------------------*)\n\nval COND_CLAUSE2 =\n   let val (x,t1,t2,v) = (``x:'a``,  ``tm1:'a``, ``tm2:'a``,\n                          genvar Type.bool)\n       val th1 = RIGHT_BETA(AP_THM\n                   (RIGHT_BETA(AP_THM\n                     (RIGHT_BETA(AP_THM COND_DEF ``F``)) t1))t2)\n       val FF = EQT_INTRO(REFL ``F``)\n       val th2 = SUBST [v |-> SYM FF]\n                       ``(^v ==> (^x=^t2))=(^x=^t2)``\n                       (CONJUNCT1(SPEC ``^x=^t2`` IMP_CLAUSES))\n       and th3 = DISCH ``F=T`` (MP (SPEC ``^x=^t1`` FALSITY)\n                                 (UNDISCH (MP (SPEC ``F=T`` F_IMP)\n                                              (CONJUNCT2 BOOL_EQ_DISTINCT))))\n       val th4 = DISCH ``^x=^t2``\n                       (CONJ th3 (EQ_MP(SYM th2)(ASSUME ``^x=^t2``)))\n       and th5 = DISCH ``((F=T) ==> (^x=^t1)) /\\ ((F=F) ==> (^x=^t2))``\n                       (MP (CONJUNCT2(ASSUME ``((F=T) ==> (^x=^t1)) /\\\n                                                 ((F=F) ==> (^x=^t2))``))\n                           (REFL ``F``))\n       val th6 = IMP_ANTISYM_RULE th4 th5\n       val th7 = TRANS th1 (SYM(SELECT_EQ x th6))\n       val th8 = EQ_MP (SYM(BETA_CONV ``(\\ ^x.^x = ^t2) ^t2``))\n                       (REFL t2)\n       val th9 = MP (SPEC t2 (SPEC ``\\ ^x.^x = ^t2`` SELECT_AX)) th8\n   in\n     GEN t1 (GEN t2 (TRANS th7 (EQ_MP (BETA_CONV(concl th9)) th9)))\n   end;\n\n(*---------------------------------------------------------------------------\n *    |- !t1:'a.!t2:'a. ((T => t1 | t2) = t1) /\\ ((F => t1 | t2) = t2)\n *---------------------------------------------------------------------------*)\n\nval COND_CLAUSES = save_thm(\"COND_CLAUSES\",\n   let val (t1,t2) = (``t1:'a``, ``t2:'a``)\n   in\n   GEN t1 (GEN t2 (CONJ(SPEC t2(SPEC t1 COND_CLAUSE1))\n                       (SPEC t2(SPEC t1 COND_CLAUSE2))))\n   end);\n\n(*--------------------------------------------------------------------- *)\n(* |- b. !t. (b => t | t) = t                                           *)\n(*                                                         TFM 90.07.23 *)\n(*--------------------------------------------------------------------- *)\n\nval COND_ID = save_thm(\"COND_ID\",\n   let val b = ``b:bool``\n       and t = ``t:'a``\n       val def = INST_TYPE [beta |-> alpha] COND_DEF\n       val th1 = itlist (fn x => RIGHT_BETA o (C AP_THM x))\n                        [t,t,b] def\n       val p = genvar bool\n       val asm1 = ASSUME ``((^b=T)==>^p) /\\ ((^b=F)==>^p)``\n       val th2 = DISJ_CASES (SPEC b BOOL_CASES_AX)\n                            (UNDISCH (CONJUNCT1 asm1))\n                            (UNDISCH (CONJUNCT2 asm1))\n       val imp1 = DISCH (concl asm1) th2\n       val asm2 = ASSUME p\n       val imp2 = DISCH p (CONJ (DISCH ``^b=T``\n                                       (ADD_ASSUM ``^b=T`` asm2))\n                                (DISCH ``^b=F``\n                                       (ADD_ASSUM ``^b=F`` asm2)))\n       val lemma = SPEC ``x:'a = ^t``\n                        (GEN p (IMP_ANTISYM_RULE imp1 imp2))\n       val th3 = TRANS th1 (SELECT_EQ ``x:'a`` lemma)\n       val th4 = EQ_MP (SYM(BETA_CONV ``(\\x.x = ^t) ^t``))\n                       (REFL t)\n       val th5 = MP (SPEC t (SPEC ``\\x.x = ^t`` SELECT_AX)) th4\n       val lemma2 = EQ_MP (BETA_CONV(concl th5)) th5\n   in\n     GEN b (GEN t (TRANS th3 lemma2))\n   end);\n\n(*---------------------------------------------------------------------------\n      SELECT_THM = |- !P. P (@x. P x) = ?x. P x\n ---------------------------------------------------------------------------*)\n\nval SELECT_THM = save_thm(\"SELECT_THM\",\n  GEN ``P:'a->bool``\n   (SYM (RIGHT_BETA(RIGHT_BETA\n          (AP_THM EXISTS_DEF ``\\x:'a. P x:bool``)))));\n\n(* ---------------------------------------------------------------------*)\n(* SELECT_REFL = |- !x. (@y. y = x) = x                                 *)\n(* ---------------------------------------------------------------------*)\n\nval SELECT_REFL = save_thm(\"SELECT_REFL\",\n  let val th1 = SPEC ``x:'a`` (SPEC ``\\y:'a. y = x`` SELECT_AX)\n      val ths = map BETA_CONV [``(\\y:'a. y = x) x``,\n                               ``(\\y:'a. y = x)(@y. y = x)``]\n      val th2 = SUBST[``u:bool`` |-> el 1 ths, ``v:bool`` |-> el 2 ths]\n                     ``u ==> v`` th1\n  in\n  GEN ``x:'a`` (MP th2 (REFL ``x:'a``))\n  end);\n\nval SELECT_REFL_2 = save_thm(\"SELECT_REFL_2\",\n  let val x = mk_var(\"x\",   Type.alpha)\n      val y = mk_var(\"y\",   Type.alpha)\n      val th1 = REFL x\n      val th2 = EXISTS (mk_exists(y,mk_eq(x,y)),x) th1\n      val th3 = SPEC y (SPEC (mk_abs(y,mk_eq(x,y))) SELECT_AX)\n     val th4 = UNDISCH th3\n     val th5 = DISCH_ALL(SYM (EQ_MP (BETA_CONV (concl th4)) th4))\n     val th6 = UNDISCH(CONV_RULE (RATOR_CONV (RAND_CONV BETA_CONV)) th5)\n in\n   GEN x (CHOOSE(y,th2) th6)\n end);\n\n(*---------------------------------------------------------------------------*)\n(* SELECT_UNIQUE = |- !P x. (!y. P y = (y = x)) ==> ($@ P = x)               *)\n(*---------------------------------------------------------------------------*)\n\nval SELECT_UNIQUE = save_thm(\"SELECT_UNIQUE\",\n  let fun mksym tm = DISCH tm (SYM(ASSUME tm))\n      val th0 = IMP_ANTISYM_RULE (mksym ``y:'a = x``)\n                                 (mksym ``x:'a = y``)\n      val th1 = SPEC ``y:'a`` (ASSUME ``!y:'a. P y = (y = x)``)\n      val th2 = EXT(GEN ``y:'a`` (TRANS th1 th0))\n      val th3 = AP_TERM ``$@ :('a->bool)->'a`` th2\n      val th4 = TRANS (BETA_CONV ``(\\y:'a. y = x) y``) th0\n      val th5 = AP_TERM ``$@ :('a->bool)->'a`` (EXT(GEN ``y:'a`` th4))\n      val th6 = TRANS (TRANS th3 (SYM th5)) (SPEC ``x:'a`` SELECT_REFL)\n  in\n  GENL [``P:'a->bool``, ``x:'a``]\n       (DISCH ``!y:'a. P y = (y = x)`` th6)\n  end);\n\n(* ----------------------------------------------------------------------\n    SELECT_ELIM_THM = |- !P Q. (?x. P x) /\\ (!x. P x ==> Q x) ==> Q ($@ P)\n   ---------------------------------------------------------------------- *)\n\nval SELECT_ELIM_THM = let\n  val P = mk_var(\"P\", alpha --> bool)\n  val Q = mk_var(\"Q\", alpha --> bool)\n  val x = mk_var(\"x\", alpha)\n  val Px = mk_comb(P, x)\n  val Qx = mk_comb(Q, x)\n  val PimpQ = mk_imp(Px, Qx)\n  val allPimpQ = mk_forall (x, PimpQ)\n  val exPx = mk_exists (x, Px)\n  val selP = mk_comb(prim_mk_const{Thy = \"min\", Name = \"@\"}, P)\n  val asm_t = mk_conj(exPx, allPimpQ)\n  val asm = ASSUME asm_t\n  val (ex_th, forall_th) = CONJ_PAIR asm\n  val imp_th = SPEC selP forall_th\n  val Px_th = ASSUME Px\n  val PselP_th0 = UNDISCH (SPEC_ALL SELECT_AX)\n  val PselP_th = CHOOSE(x, ex_th) PselP_th0\nin\n  save_thm(\"SELECT_ELIM_THM\", GENL [P, Q] (DISCH_ALL (MP imp_th PselP_th)))\nend\n\n(* -------------------------------------------------------------------------*)\n(* NOT_FORALL_THM = |- !P. ~(!x. P x) = ?x. ~P x                            *)\n(* -------------------------------------------------------------------------*)\n\nval NOT_FORALL_THM = save_thm(\"NOT_FORALL_THM\",\n    let val f = ``P:'a->bool``\n        val x = ``x:'a``\n        val t = mk_comb(f,x)\n        val all = mk_forall (x, t)\n        and exists = mk_exists(x,mk_neg t)\n        val nott = ASSUME (mk_neg t)\n        val th1 = DISCH all (MP nott (SPEC x (ASSUME all)))\n        val imp1 = DISCH exists (CHOOSE (x, ASSUME exists) (NOT_INTRO th1))\n        val th2 = CCONTR t (MP (ASSUME(mk_neg exists)) (EXISTS(exists,x)nott))\n        val th3 = CCONTR exists (MP (ASSUME (mk_neg all)) (GEN x th2))\n        val imp2 = DISCH (mk_neg all) th3\n    in\n        GEN f (IMP_ANTISYM_RULE imp2 imp1)\n    end);\n\n(* ------------------------------------------------------------------------- *)\n(* NOT_EXISTS_THM = |- !P. ~(?x. P x) = (!x. ~P x)                          *)\n(* ------------------------------------------------------------------------- *)\n\nval NOT_EXISTS_THM = save_thm(\"NOT_EXISTS_THM\",\n    let val f = ``P:'a->bool``\n        val x = ``x:'a``\n        val t = mk_comb(f,x)\n        val tm = mk_neg(mk_exists(x,t))\n        val all = mk_forall (x, mk_neg t)\n        val asm1 = ASSUME t\n        val thm1 = MP (ASSUME tm) (EXISTS (rand tm, x) asm1)\n        val imp1 = DISCH tm (GEN x (NOT_INTRO (DISCH t thm1)))\n        val asm2 = ASSUME  all and asm3 = ASSUME (rand tm)\n        val thm2 = DISCH (rand tm) (CHOOSE (x,asm3) (MP (SPEC x asm2) asm1))\n        val imp2 = DISCH all (NOT_INTRO thm2)\n    in\n        GEN f (IMP_ANTISYM_RULE imp1 imp2)\n    end);\n\n(* ------------------------------------------------------------------------- *)\n(* FORALL_AND_THM |- !P Q. (!x. P x /\\ Q x) = ((!x. P x) /\\ (!x. Q x))       *)\n(* ------------------------------------------------------------------------- *)\n\nval FORALL_AND_THM = save_thm(\"FORALL_AND_THM\",\n    let val f = ``P:'a->bool``\n        val g = ``Q:'a->bool``\n        val x = ``x:'a``\n        val th1 = ASSUME ``!x:'a. (P x) /\\ (Q x)``\n        val imp1 = (uncurry CONJ) ((GEN x ## GEN x) (CONJ_PAIR (SPEC x th1)))\n        val th2 = ASSUME ``(!x:'a. P x) /\\ (!x:'a. Q x)``\n        val imp2 = GEN x (uncurry CONJ ((SPEC x ## SPEC x) (CONJ_PAIR th2)))\n    in\n        GENL [f,g] (IMP_ANTISYM_RULE (DISCH_ALL imp1) (DISCH_ALL imp2))\n    end);\n\n(* ------------------------------------------------------------------------- *)\n(* LEFT_AND_FORALL_THM = |- !P Q. (!x. P x) /\\ Q = (!x. P x /\\ Q)            *)\n(* ------------------------------------------------------------------------- *)\n\nval LEFT_AND_FORALL_THM = save_thm(\"LEFT_AND_FORALL_THM\",\n    let val x = ``x:'a``\n        val f = ``P:'a->bool``\n        val Q = ``Q:bool``\n        val th1 = ASSUME ``(!x:'a. P x) /\\ Q``\n        val imp1 = GEN x ((uncurry CONJ) ((SPEC x ## I) (CONJ_PAIR th1)))\n        val th2 = ASSUME ``!x:'a. P x /\\ Q``\n        val imp2 = (uncurry CONJ) ((GEN x ## I) (CONJ_PAIR (SPEC x th2)))\n    in\n        GENL [f,Q] (IMP_ANTISYM_RULE (DISCH_ALL imp1) (DISCH_ALL imp2))\n    end);\n\n(* ------------------------------------------------------------------------- *)\n(* RIGHT_AND_FORALL_THM = |- !P Q. P /\\ (!x. Q x) = (!x. P /\\ Q x)           *)\n(* ------------------------------------------------------------------------- *)\n\nval RIGHT_AND_FORALL_THM = save_thm(\"RIGHT_AND_FORALL_THM\",\n    let val x = ``x:'a``\n        val P = ``P:bool``\n        val g = ``Q:'a->bool``\n        val th1 = ASSUME ``P /\\ (!x:'a. Q x)``\n        val imp1 = GEN x ((uncurry CONJ) ((I ## SPEC x) (CONJ_PAIR th1)))\n        val th2 = ASSUME ``!x:'a. P /\\ Q x``\n        val imp2 = (uncurry CONJ) ((I ## GEN x) (CONJ_PAIR (SPEC x th2)))\n    in\n        GENL [P,g] (IMP_ANTISYM_RULE (DISCH_ALL imp1) (DISCH_ALL imp2))\n    end);\n\n(* ------------------------------------------------------------------------- *)\n(* EXISTS_OR_THM |- !P Q. (?x. P x \\/ Q x) = ((?x. P x) \\/ (?x. Q x))        *)\n(* ------------------------------------------------------------------------- *)\n\nval EXISTS_OR_THM = save_thm(\"EXISTS_OR_THM\",\n    let val f = ``P:'a->bool``\n        val g = ``Q:'a->bool``\n        val x = ``x:'a``\n        val P = mk_comb(f,x)\n        val Q = mk_comb(g,x)\n        val tm = mk_exists (x,mk_disj(P,Q))\n        val ep = mk_exists (x,P)\n        and eq = mk_exists(x,Q)\n        val Pth = EXISTS(ep,x)(ASSUME P)\n        and Qth = EXISTS(eq,x)(ASSUME Q)\n        val thm1 = DISJ_CASES_UNION (ASSUME(mk_disj(P,Q))) Pth Qth\n        val imp1 = DISCH tm (CHOOSE (x,ASSUME tm) thm1)\n        val t1 = DISJ1 (ASSUME P) Q and t2 = DISJ2 P (ASSUME Q)\n        val th1 = EXISTS(tm,x) t1 and th2 = EXISTS(tm,x) t2\n        val e1 = CHOOSE (x,ASSUME ep) th1 and e2 = CHOOSE (x,ASSUME eq) th2\n        val thm2 = DISJ_CASES (ASSUME(mk_disj(ep,eq))) e1 e2\n        val imp2 = DISCH (mk_disj(ep,eq)) thm2\n    in\n        GENL [f,g] (IMP_ANTISYM_RULE imp1 imp2)\n    end);\n\n(* ------------------------------------------------------------------------- *)\n(* LEFT_OR_EXISTS_THM = |- (?x. P x) \\/ Q = (?x. P x \\/ Q)                   *)\n(* ------------------------------------------------------------------------- *)\n\nval LEFT_OR_EXISTS_THM = save_thm(\"LEFT_OR_EXISTS_THM\",\n    let val x = ``x:'a``\n        val Q = ``Q:bool``\n        val f = ``P:'a->bool``\n        val P = mk_comb(f,x)\n        val ep = mk_exists(x,P)\n        val tm = mk_disj(ep,Q)\n        val otm = mk_exists(x,mk_disj(P,Q))\n        val t1 = DISJ1 (ASSUME P) Q\n        val t2 = DISJ2 P (ASSUME Q)\n        val th1 = EXISTS(otm,x) t1 and th2 = EXISTS(otm,x) t2\n        val thm1 = DISJ_CASES (ASSUME tm) (CHOOSE(x,ASSUME ep)th1) th2\n        val imp1 = DISCH tm thm1\n        val Pth = EXISTS(ep,x)(ASSUME P) and Qth = ASSUME Q\n        val thm2 = DISJ_CASES_UNION (ASSUME(mk_disj(P,Q))) Pth Qth\n        val imp2 = DISCH otm (CHOOSE (x,ASSUME otm) thm2)\n    in\n        GENL [f,Q] (IMP_ANTISYM_RULE imp1 imp2)\n    end);\n\n(* ------------------------------------------------------------------------- *)\n(* RIGHT_OR_EXISTS_THM = |- P \\/ (?x. Q x) = (?x. P \\/ Q x)                  *)\n(* ------------------------------------------------------------------------- *)\n\nval RIGHT_OR_EXISTS_THM = save_thm(\"RIGHT_OR_EXISTS_THM\",\n    let val x = ``x:'a``\n        val P = ``P:bool``\n        val g = ``Q:'a->bool``\n        val Q = mk_comb(g,x)\n        val eq = mk_exists(x,Q)\n        val tm = mk_disj(P,eq)\n        val otm = mk_exists(x,mk_disj(P,Q))\n        val t1 = DISJ1 (ASSUME P) Q and t2 = DISJ2 P (ASSUME Q)\n        val th1 = EXISTS(otm,x) t1 and th2 = EXISTS(otm,x) t2\n        val thm1 = DISJ_CASES (ASSUME tm) th1 (CHOOSE(x,ASSUME eq)th2)\n        val imp1 = DISCH tm thm1\n        val Qth = EXISTS(eq,x)(ASSUME Q) and Pth = ASSUME P\n        val thm2 = DISJ_CASES_UNION (ASSUME(mk_disj(P,Q))) Pth Qth\n        val imp2 = DISCH otm (CHOOSE (x,ASSUME otm)  thm2)\n    in\n        GENL [P,g] (IMP_ANTISYM_RULE imp1 imp2)\n    end);\n\n(* ------------------------------------------------------------------------- *)\n(* BOTH_EXISTS_AND_THM = |- !P Q. (?x. P /\\ Q) = (?x. P) /\\ (?x. Q)          *)\n(* ------------------------------------------------------------------------- *)\n\nval BOTH_EXISTS_AND_THM = save_thm(\"BOTH_EXISTS_AND_THM\",\n    let val x = ``x:'a``\n        val P = ``P:bool``\n        val Q = ``Q:bool``\n        val t = mk_conj(P,Q)\n        val exi = mk_exists(x,t)\n        val (t1,t2) = CONJ_PAIR (ASSUME t)\n        val t11 = EXISTS ((mk_exists(x,P)),x) t1\n        val t21 = EXISTS ((mk_exists(x,Q)),x) t2\n        val imp1 = DISCH_ALL (CHOOSE (x,\n                    ASSUME (mk_exists(x,mk_conj(P,Q))))\n                   (CONJ t11 t21))\n        val th21 = EXISTS (exi,x) (CONJ (ASSUME P) (ASSUME Q))\n        val th22 = CHOOSE(x,ASSUME(mk_exists(x,P))) th21\n        val th23 = CHOOSE(x,ASSUME(mk_exists(x,Q))) th22\n        val (u1,u2) =\n            CONJ_PAIR (ASSUME (mk_conj(mk_exists(x,P),mk_exists(x,Q))))\n        val th24 = PROVE_HYP u1 (PROVE_HYP u2 th23)\n        val imp2 = DISCH_ALL th24\n    in\n        GENL [P,Q] (IMP_ANTISYM_RULE imp1 imp2)\n    end);\n\n(* ------------------------------------------------------------------------- *)\n(* LEFT_EXISTS_AND_THM = |- !P Q. (?x. P x /\\ Q) = (?x. P x) /\\ Q            *)\n(* ------------------------------------------------------------------------- *)\n\nval LEFT_EXISTS_AND_THM = save_thm(\"LEFT_EXISTS_AND_THM\",\n    let val x = ``x:'a``\n        val f = ``P:'a->bool``\n        val P = mk_comb(f,x)\n        val Q = ``Q:bool``\n        val t = mk_conj(P,Q)\n        val exi = mk_exists(x,t)\n        val (t1,t2) = CONJ_PAIR (ASSUME t)\n        val t11 = EXISTS ((mk_exists(x,P)),x) t1\n        val imp1 =\n            DISCH_ALL\n                (CHOOSE\n                 (x, ASSUME (mk_exists(x,mk_conj(P,Q))))\n                    (CONJ t11 t2))\n        val th21 = EXISTS (exi,x) (CONJ (ASSUME P) (ASSUME Q))\n        val th22 = CHOOSE(x,ASSUME(mk_exists(x,P))) th21\n        val (u1,u2) = CONJ_PAIR(ASSUME(mk_conj(mk_exists(x,P), Q)))\n        val th23 = PROVE_HYP u1 (PROVE_HYP u2 th22)\n        val imp2 = DISCH_ALL th23\n    in\n        GENL [f,Q] (IMP_ANTISYM_RULE imp1 imp2)\n    end);\n\n(* ------------------------------------------------------------------------- *)\n(* RIGHT_EXISTS_AND_THM = |- !P Q. (?x. P /\\ Q x) = P /\\ (?x. Q x)           *)\n(* ------------------------------------------------------------------------- *)\n\nval RIGHT_EXISTS_AND_THM = save_thm(\"RIGHT_EXISTS_AND_THM\",\n    let val x = ``x:'a``\n        val P = ``P:bool``\n        val g = ``Q:'a->bool``\n        val Q = mk_comb(g,x)\n        val t = mk_conj(P,Q)\n        val exi = mk_exists(x,t)\n        val (t1,t2) = CONJ_PAIR (ASSUME t)\n        val t21 = EXISTS ((mk_exists(x,Q)),x) t2\n        val imp1 =\n            DISCH_ALL\n                (CHOOSE\n                 (x, ASSUME (mk_exists(x,mk_conj(P,Q)))) (CONJ t1 t21))\n        val th21 = EXISTS (exi,x) (CONJ (ASSUME P) (ASSUME Q))\n        val th22 = CHOOSE(x,ASSUME(mk_exists(x,Q))) th21\n        val (u1,u2) = CONJ_PAIR (ASSUME (mk_conj(P, mk_exists(x,Q))))\n        val th23 = PROVE_HYP u1 (PROVE_HYP u2 th22)\n        val imp2 = DISCH_ALL th23\n    in\n        GENL [P,g] (IMP_ANTISYM_RULE imp1 imp2)\n    end);\n\n(* ------------------------------------------------------------------------- *)\n(* BOTH_FORALL_OR_THM = |- !P Q. (!x. P \\/ Q) = (!x. P) \\/ (!x. Q)           *)\n(* ------------------------------------------------------------------------- *)\n\nval BOTH_FORALL_OR_THM = save_thm(\"BOTH_FORALL_OR_THM\",\n  let val x = ``x:'a``\n      val P = ``P:bool``\n      val Q = ``Q:bool``\n      val imp11 = DISCH_ALL (SPEC x (ASSUME (mk_forall (x, P))))\n      val imp12 = DISCH_ALL (GEN x (ASSUME P))\n      val fath = IMP_ANTISYM_RULE imp11 imp12\n      val th1 = REFL (mk_forall (x, mk_disj(P,Q)))\n      val th2 = CONV_RULE (RAND_CONV\n                 (K (INST [P |-> mk_disj(P,Q)] fath))) th1\n      val th3 = CONV_RULE(RAND_CONV(RATOR_CONV(RAND_CONV(K(SYM fath))))) th2\n      val th4 = CONV_RULE(RAND_CONV(RAND_CONV(K(SYM(INST[P|->Q] fath))))) th3\n  in\n    GENL [P,Q] th4\n  end);\n\n(* ------------------------------------------------------------------------- *)\n(* LEFT_FORALL_OR_THM = |- !P Q. (!x. P x \\/ Q) = (!x. P x) \\/ Q             *)\n(* ------------------------------------------------------------------------- *)\n\nval LEFT_FORALL_OR_THM = save_thm(\"LEFT_FORALL_OR_THM\",\n  let val x = ``x:'a``\n      val f = ``P:'a->bool``\n      val P = mk_comb(f,x)\n      val Q = ``Q:bool``\n      val tm = mk_forall (x, mk_disj(P,Q))\n      val thm1 = SPEC x (ASSUME tm)\n      val thm2 = CONTR P (MP (ASSUME (mk_neg Q)) (ASSUME Q))\n      val thm3 = DISJ1 (GEN x (DISJ_CASES thm1 (ASSUME P) thm2)) Q\n      val thm4 = DISJ2 (mk_forall (x, P)) (ASSUME Q)\n      val imp1 = DISCH tm (DISJ_CASES (SPEC Q EXCLUDED_MIDDLE) thm4 thm3)\n      val thm5 = SPEC x (ASSUME (mk_forall(x,P)))\n      val thm6 = ASSUME Q\n      val imp2 = DISCH_ALL (GEN x (DISJ_CASES_UNION\n                  (ASSUME(mk_disj(mk_forall(x,P), Q))) thm5 thm6))\n  in\n      GENL [Q,f] (IMP_ANTISYM_RULE imp1 imp2)\n  end);\n\n(* ------------------------------------------------------------------------- *)\n(* RIGHT_FORALL_OR_THM = |- !P Q. (!x. P \\/ Q x) = P \\/ (!x. Q x)            *)\n(* ------------------------------------------------------------------------- *)\n\nval RIGHT_FORALL_OR_THM = save_thm(\"RIGHT_FORALL_OR_THM\",\n    let val x = ``x:'a``\n        val P = ``P:bool``\n        val g = ``Q:'a->bool``\n        val Q = mk_comb(g,x)\n        val tm   = mk_forall(x,mk_disj(P,Q))\n        val thm1 = SPEC x (ASSUME tm)\n        val thm2 = CONTR Q (MP (ASSUME (mk_neg P)) (ASSUME P))\n        val thm3 = DISJ2 P (GEN x (DISJ_CASES thm1 thm2 (ASSUME Q)))\n        val thm4 = DISJ1 (ASSUME P) (mk_forall(x,Q))\n        val imp1 = DISCH tm (DISJ_CASES (SPEC P EXCLUDED_MIDDLE) thm4 thm3)\n        val thm5 = ASSUME P\n        val thm6 = SPEC x (ASSUME (mk_forall(x,Q)))\n        val imp2 = DISCH_ALL (GEN x (DISJ_CASES_UNION\n                   (ASSUME (mk_disj(P, mk_forall(x,Q))))\n                   thm5 thm6))\n    in\n            GENL [P,g] (IMP_ANTISYM_RULE imp1 imp2)\n    end);\n\n(* ------------------------------------------------------------------------- *)\n(* BOTH_FORALL_IMP_THM = |- (!x. P ==> Q) = ((?x.P) ==> (!x.Q))              *)\n(* ------------------------------------------------------------------------- *)\n\nval BOTH_FORALL_IMP_THM = save_thm(\"BOTH_FORALL_IMP_THM\",\n    let val x = ``x:'a``\n        val P = ``P:bool``\n        val Q = ``Q:bool``\n        val tm = mk_forall(x, mk_imp(P,Q))\n        val asm = mk_exists(x,P)\n        val th1 = GEN x (CHOOSE(x,ASSUME asm)(UNDISCH(SPEC x (ASSUME tm))))\n        val imp1 = DISCH tm (DISCH asm th1)\n        val cncl = rand(concl imp1)\n        val th2 = SPEC x (MP (ASSUME cncl) (EXISTS (asm,x) (ASSUME P)))\n        val imp2 = DISCH cncl (GEN x (DISCH P th2))\n    in\n        GENL [P,Q] (IMP_ANTISYM_RULE imp1 imp2)\n    end);\n\n(* ------------------------------------------------------------------------- *)\n(* LEFT_FORALL_IMP_THM = |- (!x. P[x]==>Q) = ((?x.P[x]) ==> Q)               *)\n(* ------------------------------------------------------------------------- *)\n\nval LEFT_FORALL_IMP_THM = save_thm(\"LEFT_FORALL_IMP_THM\",\n    let val x = ``x:'a``\n        val f = ``P:'a->bool``\n        val P = mk_comb(f,x)\n        val Q = ``Q:bool``\n        val tm = mk_forall(x, mk_imp(P,Q))\n        val asm = mk_exists(x,P)\n        val th1 = CHOOSE(x,ASSUME asm)(UNDISCH(SPEC x (ASSUME tm)))\n        val imp1 = DISCH tm (DISCH asm th1)\n        val cncl = rand(concl imp1)\n        val th2 = MP (ASSUME cncl) (EXISTS (asm,x) (ASSUME P))\n        val imp2 = DISCH cncl (GEN x (DISCH P th2))\n    in\n        GENL [f,Q] (IMP_ANTISYM_RULE imp1 imp2)\n    end);\n\n(* ------------------------------------------------------------------------- *)\n(* RIGHT_FORALL_IMP_THM = |- (!x. P==>Q[x]) = (P ==> (!x.Q[x]))              *)\n(* ------------------------------------------------------------------------- *)\n\nval RIGHT_FORALL_IMP_THM = save_thm(\"RIGHT_FORALL_IMP_THM\",\n    let val x = ``x:'a``\n        val P = ``P:bool``\n        val g = ``Q:'a->bool``\n        val Q = mk_comb(g,x)\n        val tm = mk_forall(x, mk_imp(P,Q))\n        val imp1 = DISCH P(GEN x(UNDISCH(SPEC x(ASSUME tm))))\n        val cncl = concl imp1\n        val imp2 = GEN x (DISCH P(SPEC x(UNDISCH (ASSUME cncl))))\n    in\n        GENL [P,g] (IMP_ANTISYM_RULE (DISCH tm imp1) (DISCH cncl imp2))\n    end);\n\n(* ------------------------------------------------------------------------- *)\n(* BOTH_EXISTS_IMP_THM = |- (?x. P ==> Q) = ((!x.P) ==> (?x.Q))              *)\n(* ------------------------------------------------------------------------- *)\n\nval BOTH_EXISTS_IMP_THM = save_thm(\"BOTH_EXISTS_IMP_THM\",\n    let val x = ``x:'a``\n        val P = ``P:bool``\n        val Q = ``Q:bool``\n        val tm = mk_exists(x,mk_imp(P,Q))\n        val eQ = mk_exists(x,Q)\n        val aP = mk_forall(x,P)\n        val thm1 = EXISTS(eQ,x)(UNDISCH(ASSUME(mk_imp(P,Q))))\n        val thm2 = DISCH aP (PROVE_HYP (SPEC x (ASSUME aP)) thm1)\n        val imp1 = DISCH tm (CHOOSE(x,ASSUME tm) thm2)\n        val thm2 = CHOOSE(x,UNDISCH (ASSUME (rand(concl imp1)))) (ASSUME Q)\n        val thm3 = DISCH P (PROVE_HYP (GEN x (ASSUME P)) thm2)\n        val imp2 = DISCH (rand(concl imp1)) (EXISTS(tm,x) thm3)\n    in\n        GENL [P,Q] (IMP_ANTISYM_RULE imp1 imp2)\n    end);\n\n(* ------------------------------------------------------------------------- *)\n(* LEFT_EXISTS_IMP_THM = |- (?x. P[x] ==> Q) = ((!x.P[x]) ==> Q)             *)\n(* ------------------------------------------------------------------------- *)\n\nval LEFT_EXISTS_IMP_THM = save_thm(\"LEFT_EXISTS_IMP_THM\",\n    let val x = ``x:'a``\n        val f = ``P:'a->bool``\n        val P = mk_comb(f,x)\n        val Q = ``Q:bool``\n        val tm = mk_exists(x, mk_imp(P,Q))\n        val allp = mk_forall(x,P)\n        val th1 = SPEC x (ASSUME allp)\n        val thm1 = MP (ASSUME(mk_imp(P,Q))) th1\n        val imp1 = DISCH tm (CHOOSE(x,ASSUME tm)(DISCH allp thm1))\n        val otm = rand(concl imp1)\n        val thm2 = EXISTS(tm,x)(DISCH P (UNDISCH(ASSUME otm)))\n        val nex =  mk_exists(x,mk_neg P)\n        val asm1 = EXISTS (nex, x) (ASSUME (mk_neg P))\n        val th2 = CCONTR P (MP (ASSUME (mk_neg nex)) asm1)\n        val th3 = CCONTR nex (MP (ASSUME (mk_neg allp)) (GEN x th2))\n        val thm4 = DISCH P (CONTR Q (UNDISCH (ASSUME (mk_neg P))))\n        val thm5 = CHOOSE(x,th3)(EXISTS(tm,x)thm4)\n        val thm6 = DISJ_CASES (SPEC allp EXCLUDED_MIDDLE) thm2 thm5\n        val imp2 = DISCH otm thm6\n    in\n        GENL [f, Q] (IMP_ANTISYM_RULE imp1 imp2)\n    end);\n\n(* ------------------------------------------------------------------------- *)\n(* RIGHT_EXISTS_IMP_THM = |- (?x. P ==> Q[x]) = (P ==> (?x.Q[x]))            *)\n(* ------------------------------------------------------------------------- *)\n\nval RIGHT_EXISTS_IMP_THM = save_thm(\"RIGHT_EXISTS_IMP_THM\",\n    let val x = ``x:'a``\n        val P = ``P:bool``\n        val g = ``Q:'a->bool``\n        val Q = mk_comb(g,x)\n        val tm = mk_exists(x,mk_imp(P,Q))\n        val thm1 = EXISTS (mk_exists(x,Q),x)\n                           (UNDISCH(ASSUME(mk_imp(P,Q))))\n        val imp1 = DISCH tm (CHOOSE(x,ASSUME tm) (DISCH P thm1))\n        val thm2 = UNDISCH (ASSUME (rand(concl imp1)))\n        val thm3 = CHOOSE (x,thm2) (EXISTS (tm,x) (DISCH P (ASSUME Q)))\n        val thm4 = EXISTS(tm,x)(DISCH P(CONTR Q(UNDISCH(ASSUME(mk_neg P)))))\n        val thm5 = DISJ_CASES (SPEC P EXCLUDED_MIDDLE) thm3 thm4\n        val imp2 = DISCH(rand(concl imp1)) thm5\n    in\n        GENL [P,g] (IMP_ANTISYM_RULE imp1 imp2)\n    end);\n\n(* --------------------------------------------------------------------- *)\n(* OR_IMP_THM = |- !A B. (A = B \\/ A) = (B ==> A)                        *)\n(* [TFM 90.06.28]                                                        *)\n(* --------------------------------------------------------------------- *)\n\nval OR_IMP_THM = save_thm(\"OR_IMP_THM\",\n let val t1 = ``A:bool`` and t2 = ``B:bool``\n     val asm1 = ASSUME ``^t1 = (^t2 \\/ ^t1)``\n     and asm2 = EQT_INTRO(ASSUME t2)\n     val th1 = SUBST [t2 |-> asm2] (concl asm1) asm1\n     val th2 = TRANS th1 (CONJUNCT1 (SPEC t1 OR_CLAUSES))\n     val imp1 = DISCH (concl asm1) (DISCH t2 (EQT_ELIM th2))\n     val asm3 = ASSUME ``^t2 ==> ^t1``\n     and asm4 = ASSUME ``^t2 \\/ ^t1``\n     val th3 = DISJ_CASES asm4 (MP asm3 (ASSUME t2)) (ASSUME t1)\n     val th4 = DISCH (concl asm4) th3\n     and th5 = DISCH t1 (DISJ2 t2 (ASSUME t1))\n     val imp2 = DISCH ``^t2 ==> ^t1`` (IMP_ANTISYM_RULE th5 th4)\n  in\n   GEN t1 (GEN t2 (IMP_ANTISYM_RULE imp1 imp2))\n  end);\n\n(* --------------------------------------------------------------------- *)\n(* NOT_IMP = |- !A B. ~(A ==> B) = A /\\ ~B                               *)\n(* [TFM 90.07.09]                                                        *)\n(* --------------------------------------------------------------------- *)\n\nval NOT_IMP = save_thm(\"NOT_IMP\",\nlet val t1 = ``A:bool`` and t2 = ``B:bool``\n    val asm1 = ASSUME ``~(^t1 ==> ^t2)``\n    val thm1 = SUBST [t1 |-> EQF_INTRO (ASSUME (mk_neg t1))] (concl asm1) asm1\n    val thm2 = CCONTR t1 (MP thm1 (DISCH``F``(CONTR t2 (ASSUME``F``))))\n    val thm3 = SUBST [t2 |-> EQT_INTRO (ASSUME t2)] (concl asm1) asm1\n    val thm4 = NOT_INTRO(DISCH t2 (MP thm3 (DISCH t1 (ADD_ASSUM t1 TRUTH))))\n    val imp1 = DISCH (concl asm1) (CONJ thm2 thm4)\n    val conj =  ASSUME ``^t1 /\\ ~^t2``\n    val (asm2,asm3) = (CONJUNCT1 conj, CONJUNCT2 conj)\n    val asm4 = ASSUME ``^t1 ==> ^t2``\n    val thm5 = MP (SUBST [t2 |-> EQF_INTRO asm3] (concl asm4) asm4) asm2\n    val imp2 = DISCH ``^t1 /\\ ~ ^t2``\n                     (NOT_INTRO(DISCH ``^t1 ==> ^t2`` thm5))\n in\n    GEN t1 (GEN t2 (IMP_ANTISYM_RULE imp1 imp2))\n end);\n\n(* --------------------------------------------------------------------- *)\n(* DISJ_ASSOC: |- !A B C. A \\/ B \\/ C = (A \\/ B) \\/ C                    *)\n(* --------------------------------------------------------------------- *)\n\nval DISJ_ASSOC = save_thm(\"DISJ_ASSOC\",\nlet val t1 = ``A:bool`` and t2 = ``B:bool`` and t3 = ``C:bool``\n    val at1 = DISJ1 (DISJ1 (ASSUME t1) t2) t3 and\n        at2 = DISJ1 (DISJ2 t1 (ASSUME t2)) t3 and\n        at3 = DISJ2 (mk_disj(t1,t2)) (ASSUME t3)\n    val thm = DISJ_CASES (ASSUME (mk_disj(t2,t3))) at2 at3\n    val thm1 = DISJ_CASES (ASSUME (mk_disj(t1,mk_disj(t2,t3)))) at1 thm\n    val at1 = DISJ1 (ASSUME t1) (mk_disj(t2,t3)) and\n        at2 = DISJ2 t1 (DISJ1 (ASSUME t2) t3) and\n        at3 = DISJ2 t1 (DISJ2 t2 (ASSUME t3))\n    val thm = DISJ_CASES (ASSUME (mk_disj(t1,t2))) at1 at2\n    val thm2 = DISJ_CASES (ASSUME (mk_disj(mk_disj(t1,t2),t3))) thm at3\n    val imp1 = DISCH (mk_disj(t1,mk_disj(t2,t3))) thm1 and\n        imp2 = DISCH (mk_disj(mk_disj(t1,t2),t3)) thm2\n in\n   GENL [t1,t2,t3] (IMP_ANTISYM_RULE imp1 imp2)\n end);\n\n(* --------------------------------------------------------------------- *)\n(* DISJ_SYM: |- !A B. A \\/ B = B \\/ A                                    *)\n(* --------------------------------------------------------------------- *)\n\nval DISJ_SYM = save_thm(\"DISJ_SYM\",\nlet val t1   = ``A:bool`` and t2 = ``B:bool``\n    val th1  = DISJ1 (ASSUME t1) t2 and th2 = DISJ2 t1 (ASSUME t2)\n    val thm1 = DISJ_CASES (ASSUME(mk_disj(t2,t1))) th2 th1\n    val th1  = DISJ1 (ASSUME t2) t1 and th2 = DISJ2 t2 (ASSUME t1)\n    val thm2 = DISJ_CASES (ASSUME(mk_disj(t1,t2))) th2 th1\n    val imp1 = DISCH (mk_disj(t2,t1)) thm1 and\n        imp2 = DISCH (mk_disj(t1,t2)) thm2\n in\n   GENL [t1,t2] (IMP_ANTISYM_RULE imp2 imp1)\n end);\n\nval DISJ_COMM = save_thm(\"DISJ_COMM\", DISJ_SYM);\n\n(* --------------------------------------------------------------------- *)\n(* DE_MORGAN_THM:                                                        *)\n(*  |- !A B. (~(t1 /\\ t2) = ~t1 \\/ ~t2) /\\ (~(t1 \\/ t2) = ~t1 /\\ ~t2)    *)\n(* --------------------------------------------------------------------- *)\n\nval DE_MORGAN_THM = save_thm(\"DE_MORGAN_THM\",\nlet val t1 = ``A:bool`` and t2 = ``B:bool``\n    val thm1 =\n      let val asm1 = ASSUME ``~(^t1 /\\ ^t2)``\n          val cnj = MP asm1 (CONJ (ASSUME t1) (ASSUME t2))\n          val imp1 =\n            let val case1 = DISJ2 ``~^t1`` (NOT_INTRO(DISCH t2 cnj))\n                val case2 = DISJ1 (ASSUME ``~ ^t1``) ``~ ^t2``\n            in DISJ_CASES (SPEC t1 EXCLUDED_MIDDLE) case1 case2\n            end\n          val th1 = MP (ASSUME ``~^t1``)\n                       (CONJUNCT1 (ASSUME ``^t1 /\\ ^t2``))\n          val th2 = MP (ASSUME ``~^t2``)\n                   (CONJUNCT2 (ASSUME ``^t1 /\\ ^t2``))\n          val imp2 =\n            let val fth = DISJ_CASES (ASSUME ``~^t1 \\/ ~^t2``) th1 th2\n            in DISCH ``~^t1 \\/ ~^t2``\n                     (NOT_INTRO(DISCH ``^t1 /\\ ^t2`` fth))\n            end\n      in\n        IMP_ANTISYM_RULE (DISCH ``~(^t1 /\\ ^t2)`` imp1) imp2\n      end\n    val thm2 =\n      let val asm1 = ASSUME ``~(^t1 \\/ ^t2)``\n          val imp1 =\n            let val th1 = NOT_INTRO (DISCH t1(MP asm1 (DISJ1 (ASSUME t1) t2)))\n                val th2 = NOT_INTRO (DISCH t2 (MP asm1 (DISJ2 t1 (ASSUME t2))))\n            in DISCH ``~(^t1 \\/ ^t2)`` (CONJ th1 th2)\n            end\n          val imp2 =\n            let val asm = ASSUME ``^t1 \\/ ^t2``\n                val a1 = CONJUNCT1(ASSUME ``~^t1 /\\ ~^t2``) and\n                    a2 = CONJUNCT2(ASSUME ``~^t1 /\\ ~^t2``)\n               val fth = DISJ_CASES asm (UNDISCH a1) (UNDISCH a2)\n            in DISCH ``~^t1 /\\ ~^t2``\n                    (NOT_INTRO(DISCH ``^t1 \\/ ^t2`` fth))\n            end\n      in IMP_ANTISYM_RULE imp1 imp2\n      end\n in GEN t1 (GEN t2 (CONJ thm1 thm2))\n end);\n\n(* -------------------------------------------------------------------------*)\n(* Distributive laws:                                                       *)\n(*                                                                          *)\n(* LEFT_AND_OVER_OR   |- !A B C. A /\\ (B \\/ C) = A /\\ B \\/ A /\\ C           *)\n(*                                                                          *)\n(* RIGHT_AND_OVER_OR  |- !A B C. (B \\/ C) /\\ A = B /\\ A \\/ C /\\ A           *)\n(*                                                                          *)\n(* LEFT_OR_OVER_AND   |- !A B C. A \\/ B /\\ C = (A \\/ B) /\\ (A \\/ C)         *)\n(*                                                                          *)\n(* RIGHT_OR_OVER_AND  |- !A B C. B /\\ C \\/ A = (B \\/ A) /\\ (C \\/ A)         *)\n(* -------------------------------------------------------------------------*)\n\nval LEFT_AND_OVER_OR = save_thm(\"LEFT_AND_OVER_OR\",\n    let val t1 = ``A:bool``\n        and t2 = ``B:bool``\n        and t3 = ``C:bool``\n        val (th1,th2) = CONJ_PAIR(ASSUME (mk_conj(t1,mk_disj(t2,t3))))\n        val th3 = CONJ th1 (ASSUME t2) and th4 = CONJ th1 (ASSUME t3)\n        val th5 = DISJ_CASES_UNION th2 th3 th4\n        val imp1 = DISCH (mk_conj(t1,mk_disj(t2,t3))) th5\n        val (th1,th2) = (I ## C DISJ1 t3) (CONJ_PAIR (ASSUME (mk_conj(t1,t2))))\n        val (th3,th4) = (I ## DISJ2 t2) (CONJ_PAIR (ASSUME (mk_conj(t1,t3))))\n        val th5 = CONJ th1 th2 and th6 = CONJ th3 th4\n        val th6 = DISJ_CASES (ASSUME (rand(concl imp1))) th5 th6\n        val imp2 = DISCH (rand(concl imp1)) th6\n    in\n      GEN t1 (GEN t2 (GEN t3 (IMP_ANTISYM_RULE imp1 imp2)))\n    end);\n\nval RIGHT_AND_OVER_OR = save_thm(\"RIGHT_AND_OVER_OR\",\n   let val t1 = ``A:bool``\n       and t2 = ``B:bool``\n       and t3 = ``C:bool``\n       val (th1,th2) = CONJ_PAIR(ASSUME (mk_conj(mk_disj(t2,t3),t1)))\n       val th3 = CONJ (ASSUME t2) th2 and th4 = CONJ (ASSUME t3) th2\n       val th5 = DISJ_CASES_UNION th1 th3 th4\n       val imp1 = DISCH (mk_conj(mk_disj(t2,t3),t1)) th5\n       val (th1,th2) = (C DISJ1 t3 ## I) (CONJ_PAIR (ASSUME (mk_conj(t2,t1))))\n       val (th3,th4) = (DISJ2 t2 ## I) (CONJ_PAIR (ASSUME (mk_conj(t3,t1))))\n       val th5 = CONJ th1 th2 and th6 = CONJ th3 th4\n       val th6 = DISJ_CASES (ASSUME (rand(concl imp1))) th5 th6\n       val imp2 = DISCH (rand(concl imp1)) th6\n   in\n     GEN t1 (GEN t2 (GEN t3 (IMP_ANTISYM_RULE imp1 imp2)))\n   end);\n\nval LEFT_OR_OVER_AND = save_thm(\"LEFT_OR_OVER_AND\",\n   let val t1 = ``A:bool``\n       and t2 = ``B:bool``\n       and t3 = ``C:bool``\n       val th1 = ASSUME (mk_disj(t1,mk_conj(t2,t3)))\n       val th2 = CONJ (DISJ1 (ASSUME t1) t2) (DISJ1 (ASSUME t1) t3)\n       val (th3,th4) = CONJ_PAIR (ASSUME(mk_conj(t2,t3)))\n       val th5 = CONJ (DISJ2 t1 th3) (DISJ2 t1 th4)\n       val imp1 = DISCH (concl th1) (DISJ_CASES th1 th2 th5)\n       val (th1,th2) = CONJ_PAIR (ASSUME (rand(concl imp1)))\n       val th3 = DISJ1 (ASSUME t1) (mk_conj(t2,t3))\n       val (th4,th5) = CONJ_PAIR (ASSUME (mk_conj(t2,t3)))\n       val th4 = DISJ2 t1 (CONJ (ASSUME t2) (ASSUME t3))\n       val th5 = DISJ_CASES th2 th3 (DISJ_CASES th1 th3 th4)\n       val imp2 = DISCH (rand(concl imp1)) th5\n   in\n     GEN t1 (GEN t2 (GEN t3 (IMP_ANTISYM_RULE imp1 imp2)))\n   end);\n\nval RIGHT_OR_OVER_AND = save_thm(\"RIGHT_OR_OVER_AND\",\n   let val t1 = ``A:bool``\n       and t2 = ``B:bool``\n       and t3 = ``C:bool``\n       val th1 = ASSUME (mk_disj(mk_conj(t2,t3),t1))\n       val th2 = CONJ (DISJ2 t2 (ASSUME t1)) (DISJ2 t3 (ASSUME t1))\n       val (th3,th4) = CONJ_PAIR (ASSUME(mk_conj(t2,t3)))\n       val th5 = CONJ (DISJ1 th3 t1) (DISJ1 th4 t1)\n       val imp1 = DISCH (concl th1) (DISJ_CASES th1 th5 th2)\n       val (th1,th2) = CONJ_PAIR (ASSUME (rand(concl imp1)))\n       val th3 = DISJ2 (mk_conj(t2,t3)) (ASSUME t1)\n       val (th4,th5) = CONJ_PAIR (ASSUME (mk_conj(t2,t3)))\n       val th4 = DISJ1 (CONJ (ASSUME t2) (ASSUME t3)) t1\n       val th5 = DISJ_CASES th2 (DISJ_CASES th1 th4 th3) th3\n       val imp2 = DISCH (rand(concl imp1)) th5\n   in\n     GEN t1 (GEN t2 (GEN t3 (IMP_ANTISYM_RULE imp1 imp2)))\n   end);\n\n(*---------------------------------------------------------------------------*\n * IMP_DISJ_THM = |- !A B. A ==> B = ~A \\/ B                                 *\n *---------------------------------------------------------------------------*)\n\nval IMP_DISJ_THM = save_thm(\"IMP_DISJ_THM\",\nlet val A = ``A:bool``\n    val B = ``B:bool``\n    val th1 = ASSUME ``A ==> B``\n    val th2 = ASSUME A\n    val th3 = MP th1 th2\n    val th4 = DISJ2 ``~A`` th3\n    val th5 = ASSUME ``~A``;\n    val th6 = ADD_ASSUM ``A ==> B`` th5\n    val th7 = DISJ1 th6 B\n    val th8 = SPEC A EXCLUDED_MIDDLE\n    val th9 = DISJ_CASES th8 th4 th7\n    val th10 = EQT_INTRO th2\n    val th11 = ASSUME ``~A \\/ B``\n    val th12 = SUBST [A |-> th10] (concl th11) th11\n    val th13 = CONJUNCT1 (CONJUNCT2 NOT_CLAUSES)\n    val th14 = SUBST [A |-> th13] (subst [``~T`` |-> A] (concl th12)) th12\n    val th15 = CONJUNCT1 (CONJUNCT2(CONJUNCT2 (SPEC B OR_CLAUSES)))\n    val th16 = SUBST [A |-> th15] A th14\n    val th17 = DISCH A th16\n    val th18 = DISCH (concl th11) th17\n in\n   GENL [A,B] (IMP_ANTISYM_RULE (DISCH (hd(hyp th9)) th9) th18)\n end);\n\n(*----------------------------------------------------------------------*)\n(* DISJ_IMP_THM = |- !P Q R. P \\/ Q ==> R = (P ==> R) /\\ (Q ==> R)      *)\n(*                                                         MN 99.05.06  *)\n(*----------------------------------------------------------------------*)\n\nval DISJ_IMP_THM = let\n  val P = ``P:bool``\n  val Q = ``Q:bool``\n  val R = ``R:bool``\n  val lhs = ``P \\/ Q ==> R``\n  val rhs = ``(P ==> R) /\\ (Q ==> R)``\n  val ass_lhs = ASSUME lhs\n  val ass_P = ASSUME P\n  val ass_Q = ASSUME Q\n  val p_imp_r = DISCH P (MP ass_lhs (DISJ1 ass_P Q))\n  val q_imp_r = DISCH Q (MP ass_lhs (DISJ2 P ass_Q))\n  val lr_imp = DISCH lhs (CONJ p_imp_r q_imp_r)\n  (* half way there! *)\n  val ass_rhs = ASSUME rhs\n  val porq = ``P \\/ Q``\n  val ass_porq = ASSUME porq\n  val my_and1 = SPECL [``P ==> R``, ``Q ==> R``] AND1_THM\n  val p_imp_r = MP my_and1 ass_rhs\n  val r_from_p = MP p_imp_r ass_P\n  val my_and2 = SPECL [``P ==> R``, ``Q ==> R``] AND2_THM\n  val q_imp_r = MP my_and2 ass_rhs\n  val r_from_q = MP q_imp_r ass_Q\n  val rl_imp = DISCH rhs (DISCH porq (DISJ_CASES ass_porq r_from_p r_from_q))\nin\n  save_thm(\"DISJ_IMP_THM\", GENL [P,Q,R] (IMP_ANTISYM_RULE lr_imp rl_imp))\nend\n\n(* ----------------------------------------------------------------------\n    IMP_CONJ_THM = |- !P Q R. P ==> Q /\\ R = (P ==> Q) /\\ (P ==> R)\n                                                          MN 2002.10.06\n   ---------------------------------------------------------------------- *)\n\nval IMP_CONJ_THM = let\n  val P = mk_var(\"P\", bool)\n  val Q = mk_var(\"Q\", bool)\n  val R = mk_var(\"R\", bool)\n  val QandR = mk_conj(Q,R)\n  val PimpQandR = mk_imp(P, QandR)\n  val PiQaR_th = ASSUME PimpQandR\n  val P_th = ASSUME P\n  val QaR_th = MP PiQaR_th P_th\n  val (Q_th, R_th) = CONJ_PAIR QaR_th\n  val PQ_th = DISCH P Q_th\n  val PR_th = DISCH P R_th\n  val L2R = DISCH PimpQandR (CONJ PQ_th PR_th)\n  val PiQ = mk_imp(P, Q)\n  val PiR = mk_imp(P, R)\n  val PiQaPiR = mk_conj(PiQ, PiR)\n  val PiQaPiR_th = ASSUME PiQaPiR\n  val (PiQ_th, PiR_th) = CONJ_PAIR PiQaPiR_th\n  val Q_th = MP PiQ_th P_th\n  val R_th = MP PiR_th P_th\n  val QaR_th = CONJ Q_th R_th\n  val R2L = DISCH PiQaPiR (DISCH P QaR_th)\nin\n  save_thm(\"IMP_CONJ_THM\", GENL [P,Q,R] (IMP_ANTISYM_RULE L2R R2L))\nend\n\n(* ---------------------------------------------------------------------*)\n(* IMP_F_EQ_F                                                           *)\n(*                                                                      *)\n(* |- !t. t ==> F = (t = F)                                             *)\n(*                                                         RJB 92.09.26 *)\n(* ---------------------------------------------------------------------*)\n\nlocal fun nthCONJUNCT n cth =\n        let val th = funpow (n-1) CONJUNCT2 cth\n        in if (can dest_conj (concl th))\n           then CONJUNCT1 th else th\n        end\nin\nval IMP_F_EQ_F = save_thm(\"IMP_F_EQ_F\",\n   GEN ``t:bool``\n     (TRANS (nthCONJUNCT 5 (SPEC_ALL IMP_CLAUSES))\n            (SYM (nthCONJUNCT 4 (SPEC_ALL EQ_CLAUSES)))))\nend;\n\n(* ---------------------------------------------------------------------*)\n(* AND_IMP_INTRO                                                        *)\n(*                                                                      *)\n(* |- !t1 t2 t3. t1 ==> t2 ==> t3 = t1 /\\ t2 ==> t3                     *)\n(*                                                         RJB 92.09.26 *)\n(* ---------------------------------------------------------------------*)\n\nval AND_IMP_INTRO = save_thm(\"AND_IMP_INTRO\",\nlet val t1 = ``t1:bool``\n    and t2 = ``t2:bool``\n    and t3 = ``t3:bool``\n    and imp = ``$==>``\n    val [IMP1,IMP2,IMP3,_,IMP4] = map GEN_ALL(CONJUNCTS (SPEC_ALL IMP_CLAUSES))\n    and [AND1,AND2,AND3,AND4,_] = map GEN_ALL(CONJUNCTS (SPEC_ALL AND_CLAUSES))\n    val thTl = SPEC ``t2 ==> t3`` IMP1\n    and thFl = SPEC ``t2 ==> t3`` IMP3\n    val thTr = AP_THM (AP_TERM imp (SPEC t2 AND1)) t3\n    and thFr = TRANS (AP_THM (AP_TERM imp (SPEC t2 AND3)) t3)(SPEC t3 IMP3)\n    val thT1 = TRANS thTl (SYM thTr)\n    and thF1 = TRANS thFl (SYM thFr)\n    val tm   = ``t1 ==> t2 ==> t3 <=> t1 /\\ t2 ==> t3``\n    val thT2 = SUBST_CONV [t1 |-> ASSUME ``t1 = T``] tm tm\n    and thF2 = SUBST_CONV [t1 |-> ASSUME ``t1 = F``] tm tm\n    val thT3 = EQ_MP (SYM thT2) thT1\n    and thF3 = EQ_MP (SYM thF2) thF1\n in\n   GENL [t1,t2,t3] (DISJ_CASES (SPEC t1 BOOL_CASES_AX) thT3 thF3)\n end);\n\n(* ---------------------------------------------------------------------*)\n(* EQ_IMP_THM                                                           *)\n(*                                                                      *)\n(* |- !t1 t2. (t1 = t2) = (t1 ==> t2) /\\ (t2 ==> t1)                    *)\n(*                                                                      *)\n(*                                                         RJB 92.09.26 *)\n(* ---------------------------------------------------------------------*)\n\nval EQ_IMP_THM = save_thm(\"EQ_IMP_THM\",\nlet val t1 = ``t1:bool``\n    and t2 = ``t2:bool``\n    val conj = ``$/\\``\n    val [IMP1,IMP2,IMP3,_,IMP4] = map GEN_ALL(CONJUNCTS (SPEC_ALL IMP_CLAUSES))\n    and [AND1,AND2,AND3,AND4,_] = map GEN_ALL(CONJUNCTS (SPEC_ALL AND_CLAUSES))\n    and [EQ1,EQ2,EQ3,EQ4] = map GEN_ALL (CONJUNCTS (SPEC_ALL EQ_CLAUSES))\n    val thTl = SPEC t2 EQ1\n    and thFl = SPEC t2 EQ3\n    val thTr = TRANS (MK_COMB (AP_TERM conj (SPEC t2 IMP1), SPEC t2 IMP2))\n                     (SPEC t2 AND2)\n    and thFr = TRANS (MK_COMB (AP_TERM conj (SPEC t2 IMP3), SPEC t2 IMP4))\n                     (SPEC (mk_neg t2) AND1)\n    val thT1 = TRANS thTl (SYM thTr)\n    and thF1 = TRANS thFl (SYM thFr)\n    val tm = ``(t1 = t2) <=> (t1 ==> t2) /\\ (t2 ==> t1)``\n    val thT2 = SUBST_CONV [t1 |-> ASSUME ``t1 = T``] tm tm\n    and thF2 = SUBST_CONV [t1 |-> ASSUME ``t1 = F``] tm tm\n    val thT3 = EQ_MP (SYM thT2) thT1\n    and thF3 = EQ_MP (SYM thF2) thF1\n in\n   GENL [t1,t2] (DISJ_CASES (SPEC t1 BOOL_CASES_AX) thT3 thF3)\n end);\n\n(* ---------------------------------------------------------------------*)\n(* EQ_EXPAND = |- !t1 t2. (t1 = t2) = ((t1 /\\ t2) \\/ (~t1 /\\ ~t2))      *)\n(*                                                         RJB 92.09.26 *)\n(* ---------------------------------------------------------------------*)\n\nval EQ_EXPAND = save_thm(\"EQ_EXPAND\",\nlet val t1 = ``t1:bool`` and t2 = ``t2:bool``\n    val conj = ``$/\\``   and disj = ``$\\/``\n    val [NOT1,NOT2] = tl (CONJUNCTS NOT_CLAUSES)\n    and [EQ1,EQ2,EQ3,EQ4] = map GEN_ALL (CONJUNCTS (SPEC_ALL EQ_CLAUSES))\n    and [OR1,OR2,OR3,OR4,_] = map GEN_ALL (CONJUNCTS (SPEC_ALL OR_CLAUSES))\n    and [AND1,AND2,AND3,AND4,_] = map GEN_ALL (CONJUNCTS(SPEC_ALL AND_CLAUSES))\n    val thTl = SPEC t2 EQ1\n    and thFl = SPEC t2 EQ3\n    val thTr = TRANS (MK_COMB (AP_TERM disj (SPEC t2 AND1),\n                               TRANS (AP_THM (AP_TERM conj NOT1) (mk_neg t2))\n                                     (SPEC (mk_neg t2) AND3)))\n                     (SPEC t2 OR4)\n    and thFr = TRANS (MK_COMB (AP_TERM disj (SPEC t2 AND3),\n                               TRANS (AP_THM (AP_TERM conj NOT2) (mk_neg t2))\n                                     (SPEC (mk_neg t2) AND1)))\n                     (SPEC (mk_neg t2) OR3)\n    val thT1 = TRANS thTl (SYM thTr)\n    and thF1 = TRANS thFl (SYM thFr)\n    val tm = ``(t1 = t2) <=> ((t1 /\\ t2) \\/ (~t1 /\\ ~t2))``\n    val thT2 = SUBST_CONV [t1 |-> ASSUME ``t1 = T``] tm tm\n    and thF2 = SUBST_CONV [t1 |-> ASSUME ``t1 = F``] tm tm\n    val thT3 = EQ_MP (SYM thT2) thT1\n    and thF3 = EQ_MP (SYM thF2) thF1\n in\n   GENL [t1,t2] (DISJ_CASES (SPEC t1 BOOL_CASES_AX) thT3 thF3)\n end);\n\n(* ---------------------------------------------------------------------*)\n(* COND_RATOR |- !b (f:'a->'b) g x. (b => f | g) x = (b => f x | g x)   *)\n(*                                                                      *)\n(*                                                         RJB 92.09.26 *)\n(* ---------------------------------------------------------------------*)\n\nval COND_RATOR = save_thm(\"COND_RATOR\",\nlet val f = ``f: 'a -> 'b``\n    val g = ``g: 'a -> 'b``\n    val x = ``x:'a``\n    and b = ``b:bool``\n    val fx = ``^f ^x`` and gx = ``^g ^x``\n    val t1 = ``t1:'a``\n    val t2 = ``t2:'a``\n    val theta1 = [``:'a`` |-> ``:'a -> 'b``]\n    val theta2 = [``:'a`` |-> ``:'b``]\n    val (COND_T,COND_F) = (GENL[t1,t2]##GENL[t1,t2])\n                          (CONJ_PAIR(SPEC_ALL COND_CLAUSES))\n    val thTl = AP_THM (SPECL [f,g] (INST_TYPE theta1 COND_T)) x\n    and thFl = AP_THM (SPECL [f,g] (INST_TYPE theta1 COND_F)) x\n    val thTr = SPECL [fx,gx] (INST_TYPE theta2 COND_T)\n    and thFr = SPECL [fx,gx] (INST_TYPE theta2 COND_F)\n    val thT1 = TRANS thTl (SYM thTr)\n    and thF1 = TRANS thFl (SYM thFr)\n    val tm = ``(if b then (f:'a->'b ) else g) x = (if b then f x else g x)``\n    val thT2 = SUBST_CONV [b |-> ASSUME ``b = T``] tm tm\n    and thF2 = SUBST_CONV [b |-> ASSUME ``b = F``] tm tm\n    val thT3 = EQ_MP (SYM thT2) thT1\n    and thF3 = EQ_MP (SYM thF2) thF1\n in\n    GENL [b,f,g,x] (DISJ_CASES (SPEC b BOOL_CASES_AX) thT3 thF3)\n end);\n\n(* ---------------------------------------------------------------------*)\n(* COND_RAND                                                            *)\n(*                                                                      *)\n(* |- !(f:'a->'b) b x y. f (b => x | y) = (b => f x | f y)              *)\n(*                                                                      *)\n(*                                                         RJB 92.09.26 *)\n(* ---------------------------------------------------------------------*)\n\nval COND_RAND = save_thm(\"COND_RAND\",\nlet val f = ``f: 'a -> 'b``\n    val x = ``x:'a``\n    val y = ``y:'a``\n    and b = ``b:bool``\n    val fx = ``^f ^x`` and fy = ``^f ^y``\n    val t1 = ``t1:'a``\n    val t2 = ``t2:'a``\n    val theta = [Type.alpha |-> Type.beta]\n    val (COND_T,COND_F) = (GENL[t1,t2]##GENL[t1,t2])\n                          (CONJ_PAIR (SPEC_ALL COND_CLAUSES))\n    val thTl = AP_TERM f (SPECL [x,y] COND_T)\n    and thFl = AP_TERM f (SPECL [x,y] COND_F)\n    val thTr = SPECL [fx,fy] (INST_TYPE theta COND_T)\n    and thFr = SPECL [fx,fy] (INST_TYPE theta COND_F)\n    val thT1 = TRANS thTl (SYM thTr)\n    and thF1 = TRANS thFl (SYM thFr)\n    val tm = ``(f:'a->'b ) (if b then x else y) = (if b then f x else f y)``\n    val thT2 = SUBST_CONV [b |-> ASSUME ``b = T``] tm tm\n    and thF2 = SUBST_CONV [b |-> ASSUME ``b = F``] tm tm\n    val thT3 = EQ_MP (SYM thT2) thT1\n    and thF3 = EQ_MP (SYM thF2) thF1\n in\n   GENL [f,b,x,y] (DISJ_CASES (SPEC b BOOL_CASES_AX) thT3 thF3)\n end);\n\n(* ---------------------------------------------------------------------*)\n(* COND_ABS                                                             *)\n(*                                                                      *)\n(* |- !b (f:'a->'b) g. (\\x. (b => f(x) | g(x))) = (b => f | g)          *)\n(*                                                                      *)\n(*                                                         RJB 92.09.26 *)\n(* ---------------------------------------------------------------------*)\n\nval COND_ABS = save_thm(\"COND_ABS\",\nlet val b = ``b:bool``\n    val f = ``f:'a->'b``\n    val g = ``g:'a->'b``\n    val x = ``x:'a``\n in\n   GENL [b,f,g]\n      (TRANS (ABS x (SYM (SPECL [b,f,g,x] COND_RATOR)))\n             (ETA_CONV ``\\ ^x. (if ^b then ^f else ^g) ^x``))\n end);\n\n(* ---------------------------------------------------------------------*)\n(* COND_EXPAND                                                          *)\n(*                                                                      *)\n(* |- !b t1 t2. (b => t1 | t2) = ((~b \\/ t1) /\\ (b \\/ t2))              *)\n(*                                                                      *)\n(*                                                         RJB 92.09.26 *)\n(* ---------------------------------------------------------------------*)\n\nval COND_EXPAND = save_thm(\"COND_EXPAND\",\nlet val b    = ``b:bool``\n    val t1   = ``t1:bool``\n    val t2   = ``t2:bool``\n    val conj = ``$/\\``\n    val disj = ``$\\/``\n    val theta = [``:'a`` |-> Type.bool]\n    val (COND_T,COND_F) =\n      let val t1 = ``t1:'a``  and  t2 = ``t2:'a``\n      in (GENL[t1,t2]##GENL[t1,t2]) (CONJ_PAIR(SPEC_ALL COND_CLAUSES))\n      end\n    and [NOT1,NOT2] = tl (CONJUNCTS NOT_CLAUSES)\n    and [OR1,OR2,OR3,OR4,_] = map GEN_ALL (CONJUNCTS (SPEC_ALL OR_CLAUSES))\n    and [AND1,AND2,AND3,AND4,_] = map GEN_ALL (CONJUNCTS(SPEC_ALL AND_CLAUSES))\n    val thTl = SPECL [t1,t2] (INST_TYPE theta COND_T)\n    and thFl = SPECL [t1,t2] (INST_TYPE theta COND_F)\n    val thTr =\n      let val th1 = TRANS (AP_THM (AP_TERM disj NOT1) t1) (SPEC t1 OR3)\n          and th2 = SPEC t2 OR1\n      in\n         TRANS (MK_COMB (AP_TERM conj th1,th2)) (SPEC t1 AND2)\n      end\n    and thFr =\n      let val th1 = TRANS (AP_THM (AP_TERM disj NOT2) t1) (SPEC t1 OR1)\n          and th2 = SPEC t2 OR3\n      in\n        TRANS (MK_COMB (AP_TERM conj th1,th2)) (SPEC t2 AND1)\n      end\n    val thT1 = TRANS thTl (SYM thTr)\n    and thF1 = TRANS thFl (SYM thFr)\n    val tm = ``(if b then t1 else t2) = ((~b \\/ t1) /\\ (b \\/ t2))``\n    val thT2 = SUBST_CONV [b |-> ASSUME ``b = T``] tm tm\n    and thF2 = SUBST_CONV [b |-> ASSUME ``b = F``] tm tm\n    val thT3 = EQ_MP (SYM thT2) thT1\n    and thF3 = EQ_MP (SYM thF2) thF1\n in\n   GENL [b, t1, t2] (DISJ_CASES (SPEC b BOOL_CASES_AX) thT3 thF3)\n end);\n\n(* ---------------------------------------------------------------------*)\n(* COND_EXPAND_IMP                                                      *)\n(*                                                                      *)\n(* |- !b t1 t2. (b => t1 | t2) = ((b ==> t1) /\\ (~b ==> t2))            *)\n(*                                                                      *)\n(*                                                          TT 09.03.18 *)\n(* ---------------------------------------------------------------------*)\n\nval COND_EXPAND_IMP = save_thm(\"COND_EXPAND_IMP\",\nlet val b    = ``b:bool``\n    val t1   = ``t1:bool``\n    val t2   = ``t2:bool``\n    val nb   = mk_neg b;\n    val nnb  = mk_neg nb;\n    val imp_th1  = SPECL [b, t1] IMP_DISJ_THM;\n    val imp_th2a = SPECL [nb, t2] IMP_DISJ_THM\n    val imp_th2b = SUBST_CONV [nnb |-> (SPEC b (CONJUNCT1 NOT_CLAUSES))]\n                     (mk_disj (nnb, t2)) (mk_disj (nnb, t2))\n    val imp_th2  = TRANS imp_th2a imp_th2b\n    val new_rhs = ``(b ==> t1) /\\ (~b ==> t2)``;\n    val subst = [mk_imp(b,t1) |-> imp_th1,\n                 mk_imp(nb,t2) |-> imp_th2]\n    val th1 = SUBST_CONV subst new_rhs new_rhs\n    val th2 = TRANS (SPECL [b,t1,t2] COND_EXPAND) (SYM th1)\nin\n    GENL [b,t1,t2] th2\nend);\n\n(* ---------------------------------------------------------------------*)\n(* COND_EXPAND_OR                                                       *)\n(*                                                                      *)\n(* |- !b t1 t2. (b => t1 | t2) = ((b /\\ t1) \\/ (~b /\\ t2))              *)\n(*                                                                      *)\n(*                                                          TT 09.03.18 *)\n(* ---------------------------------------------------------------------*)\n\nval COND_EXPAND_OR = save_thm(\"COND_EXPAND_OR\",\nlet val b    = ``b:bool``\n    val t1   = ``t1:bool``\n    val t2   = ``t2:bool``\n    val conj = ``$/\\``\n    val disj = ``$\\/``\n    val theta = [``:'a`` |-> Type.bool]\n    val (COND_T,COND_F) =\n      let val t1 = ``t1:'a``  and  t2 = ``t2:'a``\n      in (GENL[t1,t2]##GENL[t1,t2]) (CONJ_PAIR(SPEC_ALL COND_CLAUSES))\n      end\n    and [NOT1,NOT2] = tl (CONJUNCTS NOT_CLAUSES)\n    and [OR1,OR2,OR3,OR4,_] = map GEN_ALL (CONJUNCTS (SPEC_ALL OR_CLAUSES))\n    and [AND1,AND2,AND3,AND4,_] = map GEN_ALL (CONJUNCTS(SPEC_ALL AND_CLAUSES))\n    val thTl = SPECL [t1,t2] (INST_TYPE theta COND_T)\n    and thFl = SPECL [t1,t2] (INST_TYPE theta COND_F)\n    val thTr =\n      let val th2 = TRANS (AP_THM (AP_TERM conj NOT1) t2) (SPEC t2 AND3)\n          and th1 = SPEC t1 AND1\n      in\n         TRANS (MK_COMB (AP_TERM disj th1,th2)) (SPEC t1 OR4)\n      end\n    and thFr =\n      let val th2 = TRANS (AP_THM (AP_TERM conj NOT2) t2) (SPEC t2 AND1)\n          and th1 = SPEC t1 AND3\n      in\n        TRANS (MK_COMB (AP_TERM disj th1,th2)) (SPEC t2 OR3)\n      end\n    val thT1 = TRANS thTl (SYM thTr)\n    and thF1 = TRANS thFl (SYM thFr)\n    val tm = ``(if b then t1 else t2) = ((b /\\ t1) \\/ (~b /\\ t2))``\n    val thT2 = SUBST_CONV [b |-> ASSUME ``b = T``] tm tm\n    and thF2 = SUBST_CONV [b |-> ASSUME ``b = F``] tm tm\n    val thT3 = EQ_MP (SYM thT2) thT1\n    and thF3 = EQ_MP (SYM thF2) thF1\n in\n   GENL [b, t1, t2] (DISJ_CASES (SPEC b BOOL_CASES_AX) thT3 thF3)\n end);\n\n\nval TYPE_DEFINITION_THM = save_thm(\"TYPE_DEFINITION_THM\",\n  let val P   = ``P:'a-> bool``\n      val rep = ``rep :'b -> 'a``\n  in\n    GEN P (GEN rep\n      (RIGHT_BETA(AP_THM\n          (RIGHT_BETA (AP_THM TYPE_DEFINITION P)) rep)))\n  end);\n\nval ONTO_THM = save_thm(\n  \"ONTO_THM\",\n  let val f = mk_var(\"f\", Type.alpha --> Type.beta)\n  in\n      GEN f (RIGHT_BETA (AP_THM ONTO_DEF f))\n  end);\n\nval ONE_ONE_THM = save_thm(\n  \"ONE_ONE_THM\",\n  let val f = mk_var(\"f\", Type.alpha --> Type.beta)\n  in\n      GEN f (RIGHT_BETA (AP_THM ONE_ONE_DEF f))\n  end);\n\n(*---------------------------------------------------------------------------*\n * ABS_REP_THM                                                               *\n *  |- !P. (?rep. TYPE_DEFINITION P rep) ==>                                 *\n *         ?rep abs. (!a. abs (rep a) = a) /\\ !r. P r = (rep (abs r) = r)    *\n *---------------------------------------------------------------------------*)\n\nval ABS_REP_THM = save_thm(\"ABS_REP_THM\",\n   let val th1 = ASSUME ``?rep:'b->'a. TYPE_DEFINITION P rep``\n       val th2 = MK_EXISTS (SPEC ``P:'a->bool`` TYPE_DEFINITION_THM)\n       val def = EQ_MP th2 th1\n       val asm = ASSUME (snd(dest_exists(concl def)))\n       val (asm1,asm2)  = CONJ_PAIR asm\n       val rep_eq =\n         let val th1 = DISCH ``a:'b=a'``\n                         (AP_TERM ``rep:'b->'a`` (ASSUME ``a:'b=a'``))\n         in IMP_ANTISYM_RULE (SPECL [``a:'b``,``a':'b``] asm1) th1\n         end\n       val ABS = ``\\r:'a. @a:'b. r = rep a``\n       val absd =  RIGHT_BETA (AP_THM (REFL ABS) ``rep (a:'b):'a``)\n       val lem = SYM(SELECT_RULE(EXISTS (``?a':'b.a=a'``,``a:'b``)\n                                        (REFL ``a:'b``)))\n       val TH1 = GEN ``a:'b``\n                     (TRANS(TRANS absd (SELECT_EQ ``a':'b`` rep_eq)) lem)\n       val t1 = SELECT_RULE(EQ_MP (SPEC ``r:'a`` asm2)\n                                  (ASSUME ``(P:'a->bool) r``))\n       val absd2 =  RIGHT_BETA (AP_THM (REFL ABS) ``r:'a``)\n       val v = mk_var(\"v\",type_of(rhs (concl absd2)))\n       val (t1l,t1r) = dest_eq (concl t1)\n       (* val rep = fst(strip_comb t1r) *)\n       val rep = rator t1r\n       val template = mk_eq(t1l, mk_comb(rep,v))\n       val imp1 = DISCH ``(P:'a->bool) r``\n                    (SYM (SUBST [v |-> SYM absd2] template t1))\n       val t2 = EXISTS (``?a:'b. r:'a = rep a``, ``^ABS r``)\n                       (SYM(ASSUME ``rep(^ABS (r:'a):'b) = r``))\n       val imp2 = DISCH ``rep(^ABS (r:'a):'b) = r``\n                        (EQ_MP (SYM (SPEC ``r:'a`` asm2)) t2)\n       val TH2 = GEN ``r:'a`` (IMP_ANTISYM_RULE imp1 imp2)\n       val CTH = CONJ TH1 TH2\n       val ath = subst [ABS |-> ``abs:'a->'b``] (concl CTH)\n       val eth1 = EXISTS (``?abs:'a->'b. ^ath``, ABS) CTH\n       val eth2 = EXISTS (``?rep:'b->'a. ^(concl eth1)``,\n                          ``rep:'b->'a``) eth1\n       val result = DISCH (concl th1) (CHOOSE (``rep:'b->'a``,def) eth2)\n   in\n   GEN ``P:'a->bool`` result\n   end);\n\n(*---------------------------------------------------------------------------\n    LET_RAND =  P (let x = M in N x) = (let x = M in P (N x))\n ---------------------------------------------------------------------------*)\n\nval LET_RAND = save_thm(\"LET_RAND\",\n let val tm1 = ``\\x:'a. P (N x:'b):bool``\n     val tm2 = ``M:'a``\n     val tm3 = ``\\x:'a. N x:'b``\n     val P   = ``P:'b -> bool``\n     val LET_THM1 = RIGHT_BETA (SPEC tm2 (SPEC tm1\n                    (Thm.INST_TYPE [beta |-> bool] LET_THM)))\n     val LET_THM2 = AP_TERM P (RIGHT_BETA (SPEC tm2 (SPEC tm3 LET_THM)))\n in TRANS LET_THM2 (SYM LET_THM1)\n end);\n\n\n(*---------------------------------------------------------------------------\n    LET_RATOR =  (let x = M in N x) b = (let x = M in N x b)\n ---------------------------------------------------------------------------*)\n\nval LET_RATOR = save_thm(\"LET_RATOR\",\n let val M = ``M:'a``\n     val b = ``b:'b``\n     val tm1 = ``\\x:'a. N x:'b->'c``\n     val tm2 = ``\\x:'a. N x ^b:'c``\n     val LET_THM1 = AP_THM (RIGHT_BETA (SPEC M (SPEC tm1\n                   (Thm.INST_TYPE [beta |-> (beta --> gamma)] LET_THM)))) b\n     val LET_THM2 = RIGHT_BETA (SPEC M (SPEC tm2\n                      (Thm.INST_TYPE [beta |-> gamma] LET_THM)))\n in TRANS LET_THM1 (SYM LET_THM2)\n end);\n\n\n(*---------------------------------------------------------------------------\n           !P. (!x y. P x y) = (!y x. P x y)\n ---------------------------------------------------------------------------*)\n\nval SWAP_FORALL_THM = save_thm(\"SWAP_FORALL_THM\",\n  let val P = mk_var(\"P\", ``:'a->'b->bool``)\n      val x = mk_var(\"x\", Type.alpha)\n      val y = mk_var(\"y\", Type.beta)\n      val Pxy = list_mk_comb (P,[x,y])\n      val th1 = ASSUME (list_mk_forall [x,y] Pxy)\n      val th2 = DISCH_ALL (GEN y (GEN x (SPEC y (SPEC x th1))))\n      val th3 = ASSUME (list_mk_forall [y,x] Pxy)\n      val th4 = DISCH_ALL (GEN x (GEN y (SPEC x (SPEC y th3))))\n  in\n     GEN P (IMP_ANTISYM_RULE th2 th4)\n  end);\n\n(*---------------------------------------------------------------------------\n           !P. (?x y. P x y) = (?y x. P x y)\n ---------------------------------------------------------------------------*)\n\nval SWAP_EXISTS_THM = save_thm(\"SWAP_EXISTS_THM\",\n  let val P = mk_var(\"P\", ``:'a->'b->bool``)\n      val x = mk_var(\"x\", Type.alpha)\n      val y = mk_var(\"y\", Type.beta)\n      val Pxy = list_mk_comb (P,[x,y])\n      val tm1 = list_mk_exists[x] Pxy\n      val tm2 = list_mk_exists[y] tm1\n      val tm3 = list_mk_exists[y] Pxy\n      val tm4 = list_mk_exists[x] tm3\n      val th1 = ASSUME Pxy\n      val th2 = EXISTS(tm2,y) (EXISTS (tm1,x) th1)\n      val th3 = ASSUME (list_mk_exists [y] Pxy)\n      val th4 = CHOOSE(y,th3) th2\n      val th5 = CHOOSE(x,ASSUME (list_mk_exists [x,y] Pxy)) th4\n      val th6 = EXISTS(tm4,x) (EXISTS (tm3,y) th1)\n      val th7 = ASSUME (list_mk_exists[x] Pxy)\n      val th8 = CHOOSE(x,th7) th6\n      val th9 = CHOOSE(y,ASSUME (list_mk_exists [y,x] Pxy)) th8\n  in\n     GEN P (IMP_ANTISYM_RULE (DISCH_ALL th5) (DISCH_ALL th9))\n  end);\n\n(*---------------------------------------------------------------------------\n   EXISTS_UNIQUE_THM\n\n     (?!x. P x) = (?x. P x) /\\ (!x y. P x /\\ P y ==> (x = y))\n ---------------------------------------------------------------------------*)\n\nval EXISTS_UNIQUE_THM = save_thm(\"EXISTS_UNIQUE_THM\",\n let val th1 = RIGHT_BETA (AP_THM EXISTS_UNIQUE_DEF ``\\x:'a. P x:bool``)\n     val th2 = CONV_RULE (RAND_CONV (RAND_CONV\n                (QUANT_CONV (QUANT_CONV (RATOR_CONV\n                    (RAND_CONV (RAND_CONV BETA_CONV))))))) th1\n in\n   CONV_RULE (RAND_CONV (RAND_CONV (QUANT_CONV (QUANT_CONV (RATOR_CONV\n               (RAND_CONV (RATOR_CONV (RAND_CONV BETA_CONV)))))))) th2\n end);\n\n(* ----------------------------------------------------------------------\n    EXISTS_UNIQUE_ALT'\n    |- !P. (?!x. P x) <=> ?x. !y. P y <=> (y = x)\n   ---------------------------------------------------------------------- *)\n\nval EXISTS_UNIQUE_ALT' = save_thm(\n  \"EXISTS_UNIQUE_ALT'\",\n  let\n    val eu_r = ASSUME (rhs (concl EXISTS_UNIQUE_THM))\n    val (eu1, eu2) = CONJ_PAIR eu_r\n    val P = mk_var(\"P\", alpha --> bool)\n    val x = mk_var(\"x\", alpha)\n    val y = mk_var(\"y\", alpha)\n    val c = mk_var(\"c\", alpha)\n    val yeqx = mk_eq(y,x)\n    val Px = mk_comb(P, x)\n    val Py = mk_comb(P, y)\n    val th1a = MP (SPECL [y,x] eu2) (CONJ (ASSUME Py) (ASSUME Px)) |> DISCH Py\n    val th1b = EQ_MP (SYM (AP_TERM P (ASSUME yeqx))) (ASSUME Px) |> DISCH yeqx\n    val th1_noex = IMP_ANTISYM_RULE th1a th1b |> GEN y\n    val th1_noch = EXISTS(mk_exists(x,concl th1_noex), x) th1_noex\n    val th1 = CHOOSE(x,eu1) th1_noch\n    val pyyeq = concl th1\n    val pyyeqc = subst [x |-> c] (#2 (dest_exists pyyeq))\n    val pyyeqc_th = ASSUME pyyeqc\n    val th2a = pyyeqc_th |> SPEC c |> C EQ_MP (REFL c) o SYM\n                         |> EXISTS(mk_exists(x,Px), c)\n    val (pxy_x,pxy_y) = ASSUME (mk_conj(Px,Py)) |> CONJ_PAIR\n    val th2b1 = pyyeqc_th |> SPEC x |> C EQ_MP (ASSUME Px) |> PROVE_HYP pxy_x\n    val th2b2 = pyyeqc_th |> SPEC y |> C EQ_MP (ASSUME Py) |> PROVE_HYP pxy_y\n    val th2b = TRANS th2b1 (SYM th2b2) |> DISCH (mk_conj(Px,Py)) |> GENL [x,y]\n    val th2 = CHOOSE (c, ASSUME pyyeq) (CONJ th2a th2b)\n    val eqn = IMP_ANTISYM_RULE (DISCH_ALL th1) (DISCH_ALL th2)\n  in\n    TRANS EXISTS_UNIQUE_THM eqn\n  end);\n\n(*---------------------------------------------------------------------------\n  LET_CONG =\n    |- !f g M N.  (M = N) /\\ (!x. (x = N) ==> (f x = g x))\n                            ==>\n                   (LET f M = LET g N)\n ---------------------------------------------------------------------------*)\n\nval LET_CONG = save_thm(\"LET_CONG\",\n  let val f = mk_var(\"f\",alpha-->beta)\n      val g = mk_var(\"g\",alpha-->beta)\n      val M = mk_var(\"M\",alpha)\n      val N = mk_var(\"N\",alpha)\n      val x = mk_var (\"x\",alpha)\n      val MeqN = mk_eq(M,N)\n      val x_eq_N = mk_eq(x,N)\n      val fx_eq_gx = mk_eq(mk_comb(f,x),mk_comb(g,x))\n      val ctm = mk_forall(x, mk_imp(x_eq_N,fx_eq_gx))\n      val th  = RIGHT_BETA(AP_THM(RIGHT_BETA(AP_THM LET_DEF f)) M)\n      val th1 = ASSUME MeqN\n      val th2 = MP (SPEC N (ASSUME ctm)) (REFL N)\n      val th3 = SUBS [SYM th1] th2\n      val th4 = TRANS (TRANS th th3) (MK_COMB (REFL g,th1))\n      val th5 = RIGHT_BETA(AP_THM(RIGHT_BETA(AP_THM LET_DEF g)) N)\n      val th6 = TRANS th4 (SYM th5)\n      val th7 = SUBS [SPECL [MeqN, ctm, concl th6] AND_IMP_INTRO]\n                     (DISCH MeqN (DISCH ctm th6))\n  in\n    GENL [f,g,M,N] th7\n  end);\n\n(*---------------------------------------------------------------------------\n  IMP_CONG =\n    |- !x x' y y'. (x = x') /\\ (x' ==> (y = y'))\n                            ==>\n                   (x ==> y = x' ==> y')\n ---------------------------------------------------------------------------*)\n\nval IMP_CONG = save_thm(\"IMP_CONG\",\n let val x = mk_var(\"x\",Type.bool)\n     val x' = mk_var(\"x'\",Type.bool)\n     val y = mk_var(\"y\",Type.bool)\n     val y' = mk_var(\"y'\",Type.bool)\n     val x_eq_x' = mk_eq(x,x')\n     val ctm = mk_imp(x', mk_eq(y,y'))\n     val x_imp_y = mk_imp(x,y)\n     val x'_imp_y' = mk_imp(x',y')\n     val th = ASSUME x_eq_x'\n     val th1 = UNDISCH(ASSUME ctm)\n     val th2 = ASSUME x_imp_y\n     val th3 = DISCH x_imp_y (DISCH x' (UNDISCH(SUBS [th,th1] th2)))\n     val th4 = ASSUME x'_imp_y'\n     val th5 = UNDISCH (SUBS [SYM th] (DISCH x' th1))\n     val th6 = DISCH x'_imp_y' (DISCH x (UNDISCH(SUBS [SYM th,SYM th5] th4)))\n     val th7 = IMP_ANTISYM_RULE th3 th6\n     val th8 = DISCH x_eq_x' (DISCH ctm th7)\n     val th9 = SUBS [SPECL [x_eq_x', ctm, concl th7] AND_IMP_INTRO] th8\n in\n   GENL [x,x',y,y'] th9\n end);\n\n(*---------------------------------------------------------------------------\n  AND_CONG = |- !P P' Q Q'.\n                  (Q ==> (P = P')) /\\ (P' ==> (Q = Q'))\n                                   ==>\n                            (P /\\ Q = P' /\\ Q')\n ---------------------------------------------------------------------------*)\n\nval AND_CONG = save_thm(\"AND_CONG\",\n let val P = mk_var(\"P\",Type.bool)\n     val P' = mk_var(\"P'\",Type.bool)\n     val Q = mk_var(\"Q\",Type.bool)\n     val Q' = mk_var(\"Q'\",Type.bool)\n     val PandQ = mk_conj(P,Q)\n     val P'andQ' = mk_conj(P',Q')\n     val ctm1 = mk_imp(Q,  mk_eq(P,P'))\n     val ctm2 = mk_imp(P', mk_eq(Q,Q'))\n     val th1 = ASSUME PandQ\n     val th2 = MP (ASSUME ctm1) (CONJUNCT2 th1)\n     val th3 = MP (ASSUME ctm2) (SUBS [th2] (CONJUNCT1 th1))\n     val th4 = DISCH PandQ (SUBS[th2,th3] th1)\n     val th5 = ASSUME P'andQ'\n     val th6 = MP (ASSUME ctm2) (CONJUNCT1 th5)\n     val th7 = MP (ASSUME ctm1) (SUBS [SYM th6] (CONJUNCT2 th5))\n     val th8 = DISCH P'andQ' (SUBS[SYM th6,SYM th7] th5)\n     val th9 = IMP_ANTISYM_RULE th4 th8\n     val th10 = SUBS [SPECL [ctm1,ctm2,concl th9] AND_IMP_INTRO]\n                     (DISCH ctm1 (DISCH ctm2 th9))\n in\n   GENL [P,P',Q,Q'] th10\n end);\n\n(*---------------------------------------------------------------------------\n  LEFT_AND_CONG =\n       |- !P P' Q Q'.\n          (P = P') /\\ (P' ==> (Q = Q'))\n                  ==>\n          (P /\\ Q = P' /\\ Q')\n ---------------------------------------------------------------------------*)\n\nval LEFT_AND_CONG = save_thm(\"LEFT_AND_CONG\",\n let val P = mk_var(\"P\",Type.bool)\n     val P' = mk_var(\"P'\",Type.bool)\n     val Q = mk_var(\"Q\",Type.bool)\n     val Q' = mk_var(\"Q'\",Type.bool)\n     val PandQ = mk_conj(P,Q)\n     val P'andQ' = mk_conj(P',Q')\n     val ctm1 = mk_eq(P,P')\n     val ctm2 = mk_imp(P', mk_eq(Q,Q'))\n     val th1 = ASSUME PandQ\n     val th2 = ASSUME ctm1\n     val th3 = SUBS [th2] (CONJUNCT1 th1)\n     val th3a = MP (ASSUME ctm2) th3\n     val th4 = DISCH PandQ (SUBS[th2,th3a] th1)\n     val th5 = ASSUME P'andQ'\n     val th6 = SUBS [SYM th2] (CONJUNCT1 th5)\n     val th7 = SYM(MP (ASSUME ctm2) (CONJUNCT1 th5))\n     val th8 = DISCH P'andQ' (SUBS[SYM th2,th7] th5)\n     val th9 = IMP_ANTISYM_RULE th4 th8\n     val th10 = SUBS [SPECL [ctm1,ctm2,concl th9] AND_IMP_INTRO]\n                     (DISCH ctm1 (DISCH ctm2 th9))\n in\n   GENL [P,P',Q,Q'] th10\n end);\n\n(*---------------------------------------------------------------------------\n   val OR_CONG =\n       |- !P P' Q Q'.\n         (~Q ==> (P = P')) /\\ (~P' ==> (Q = Q'))\n                           ==>\n                   (P \\/ Q = P' \\/ Q')\n ---------------------------------------------------------------------------*)\n\nval OR_CONG = save_thm(\"OR_CONG\",\n let val P = mk_var(\"P\",Type.bool)\n     val P' = mk_var(\"P'\",Type.bool)\n     val Q = mk_var(\"Q\",Type.bool)\n     val Q' = mk_var(\"Q'\",Type.bool)\n     val notQ = mk_neg Q\n     val notP' = mk_neg P'\n     val PorQ = mk_disj(P,Q)\n     val P'orQ' = mk_disj(P',Q')\n     val PeqP'= mk_eq(P,P')\n     val QeqQ'= mk_eq(Q,Q')\n     val ctm1 = mk_imp(notQ,PeqP')\n     val ctm2 = mk_imp(notP',QeqQ')\n     val th1 = ASSUME PorQ\n     val th2 = ASSUME P\n     val th3 = ASSUME Q\n     val th4 = ASSUME ctm1\n     val th5 = ASSUME ctm2\n     val th6 = SUBS [SPEC Q (CONJUNCT1 NOT_CLAUSES)]\n                    (SUBS [SPECL[notQ, PeqP'] IMP_DISJ_THM] th4)\n     val th7 = SUBS [SPEC P' (CONJUNCT1 NOT_CLAUSES)]\n                    (SUBS [SPECL[notP', QeqQ'] IMP_DISJ_THM] th5)\n     val th8 = ASSUME P'\n     val th9 = DISJ1 th8 Q'\n     val th10 = ASSUME QeqQ'\n     val th11 = SUBS [th10] th3\n     val th12 = DISJ2 P' th11\n     val th13 = ASSUME PeqP'\n     val th14 = MK_COMB(REFL(mk_const(\"\\\\/\",bool-->bool-->bool)),th13)\n     val th15 = EQ_MP (MK_COMB (th14,th10)) th1\n     val th16 = DISJ_CASES th6 th12 th15\n     val th17 = DISCH PorQ (DISJ_CASES th7 th9 th16)\n     val th18 = ASSUME P'orQ'\n     val th19 = DISJ2 P th3\n     val th20 = DISJ1 (SUBS [SYM th13] th8) Q\n     val th21 = EQ_MP (SYM (MK_COMB(th14,th10))) th18\n     val th22 = DISJ_CASES th7 th20 th21\n     val th23 = DISCH P'orQ' (DISJ_CASES th6 th19 th22)\n     val th24 = IMP_ANTISYM_RULE th17 th23\n     val th25 = SUBS [SPECL [ctm1,ctm2,concl th24] AND_IMP_INTRO]\n                     (DISCH ctm1 (DISCH ctm2 th24))\n in\n   GENL [P,P',Q,Q'] th25\n end);\n\n(*---------------------------------------------------------------------------\n   val LEFT_OR_CONG =\n       |- !P P' Q Q'.\n         (P = P') /\\ (~P' ==> (Q = Q'))\n                  ==>\n          (P \\/ Q = P' \\/ Q')\n ---------------------------------------------------------------------------*)\n\nval LEFT_OR_CONG = save_thm(\"LEFT_OR_CONG\",\n let fun mk_boolvar s = mk_var(s,Type.bool)\n     val [P,P',Q,Q'] = map mk_boolvar [\"P\",\"P'\",\"Q\",\"Q'\"]\n     val notP = mk_neg P\n     val notP' = mk_neg P'\n     val PorQ = mk_disj(P,Q)\n     val P'orQ' = mk_disj(P',Q')\n     val PeqP' = mk_eq(P,P')\n     val ctm = mk_imp(notP',mk_eq(Q,Q'))\n     val th1 = ASSUME ctm\n     val th2 = ASSUME PeqP'\n     val th3 = DISJ1 (SUBS [th2] (ASSUME P)) Q'\n     val th4 = MP th1 (SUBS [th2] (ASSUME notP))\n     val th5 = DISJ2 P' (SUBS [th4] (ASSUME Q))\n     val th6 = DISJ_CASES (SPEC P EXCLUDED_MIDDLE) th3 th5\n     val th7 = DISCH PorQ (DISJ_CASES (ASSUME PorQ) th3 th6)\n     val th8 = DISJ1 (SUBS [SYM th2] (ASSUME P')) Q\n     val th9 = MP th1 (ASSUME notP')\n     val th10 = DISJ2 P (SUBS [SYM th9] (ASSUME Q'))\n     val th11 = DISJ_CASES (SPEC P' EXCLUDED_MIDDLE) th8 th10\n     val th12 = DISCH P'orQ' (DISJ_CASES (ASSUME P'orQ') th8 th11)\n     val th13 = DISCH PeqP' (DISCH ctm (IMP_ANTISYM_RULE th7 th12))\n     val th14 = SUBS[SPECL [PeqP',ctm,mk_eq(PorQ,P'orQ')] AND_IMP_INTRO] th13\n in\n   GENL [P,P',Q,Q'] th14\n end);\n\n(*---------------------------------------------------------------------------\n   val COND_CONG =\n    |- !P Q x x' y y'.\n         (P = Q) /\\ (Q ==> (x = x')) /\\ (~Q ==> (y = y'))\n                 ==>\n         ((if P then x else y) = (if Q then x' else y'))\n ---------------------------------------------------------------------------*)\n\nfun mk_cond {cond,larm,rarm} = ``if ^cond then ^larm else ^rarm``;\n\nval COND_CONG = save_thm(\"COND_CONG\",\n let val P = mk_var(\"P\",Type.bool)\n     val Q = mk_var(\"Q\",Type.bool)\n     val x = mk_var(\"x\",alpha)\n     val x' = mk_var(\"x'\",alpha)\n     val y  = mk_var(\"y\",alpha)\n     val y' = mk_var(\"y'\",alpha)\n     val PeqQ = mk_eq(P,Q)\n     val ctm1 = mk_imp(Q, mk_eq(x,x'))\n     val ctm2 = mk_imp(mk_neg Q, mk_eq(y,y'))\n     val target = mk_eq(mk_cond{cond=P,larm=x,rarm=y},\n                        mk_cond{cond=Q,larm=x',rarm=y'})\n     val OR_ELIM = MP (SPECL[target,P,mk_neg P] OR_ELIM_THM)\n                      (SPEC P EXCLUDED_MIDDLE)\n     val th1 = ASSUME P\n     val th2 = EQT_INTRO th1\n     val th3 = CONJUNCT1 (SPECL [x,y] COND_CLAUSES)\n     val th3a = CONJUNCT1 (SPECL [x',y'] COND_CLAUSES)\n     val th4 = SUBS [SYM th2] th3\n     val th4a = SUBS [SYM th2] th3a\n     val th5 = ASSUME PeqQ\n     val th6 = ASSUME ctm1\n     val th7 = ASSUME ctm2\n     val th8 = UNDISCH (SUBS [SYM th5] th6)\n     val th9 = TRANS th4 th8\n     val th10 = TRANS th9 (SYM (SUBS [th5] th4a))\n     val th11 = EQF_INTRO (ASSUME (mk_neg P))\n     val th12 = CONJUNCT2 (SPECL [x,y] COND_CLAUSES)\n     val th13 = CONJUNCT2 (SPECL [x',y'] COND_CLAUSES)\n     val th14 = SUBS [SYM th11] th12\n     val th15 = SUBS [SYM th11] th13\n     val th16 = UNDISCH (SUBS [SYM th5] th7)\n     val th17 = TRANS th14 th16\n     val th18 = TRANS th17 (SYM (SUBS [th5] th15))\n     val th19 = MP (MP OR_ELIM (DISCH P th10)) (DISCH (mk_neg P) th18)\n     val th20 = DISCH PeqQ (DISCH ctm1 (DISCH ctm2 th19))\n     val th21 = SUBS [SPECL [ctm1, ctm2,concl th19] AND_IMP_INTRO] th20\n     val cnj  = mk_conj(ctm1,ctm2)\n     val th22 = SUBS [SPECL [PeqQ,cnj,concl th19] AND_IMP_INTRO] th21\n in\n   GENL [P,Q,x,x',y,y'] th22\n end);\n\n(* ----------------------------------------------------------------------\n\n    RES_FORALL_CONG\n       |- (P = Q) ==> (!x. x IN Q ==> (f x = g x)) ==>\n          (RES_FORALL P f = RES_FORALL Q g)\n\n    RES_EXISTS_CONG\n       |- (P = Q) ==> (!x. x IN Q ==> (f x = g x)) ==>\n          (RES_EXISTS P f = RES_EXISTS P g)\n   ---------------------------------------------------------------------- *)\n\nval (RES_FORALL_CONG, RES_EXISTS_CONG) = let\n  (* stuff in common to both *)\n  val aset_ty = alpha --> bool\n  val [P,Q,f,g] = map (fn s => mk_var(s, aset_ty)) [\"P\", \"Q\", \"f\", \"g\"]\n  val PeqQ_t = mk_eq(P, Q)\n  val PeqQ_th = ASSUME PeqQ_t\n  val x = mk_var(\"x\", alpha)\n  val fx_t = mk_comb(f, x)\n  val gx_t = mk_comb(g, x)\n  val IN_t = prim_mk_const {Thy = \"bool\", Name = \"IN\"}\n  val xINP_t = list_mk_comb(IN_t, [x, P])\n  val xINP_th = ASSUME xINP_t\n  val xINQ_t = list_mk_comb(IN_t, [x, Q])\n  val xINQ_th = ASSUME xINQ_t\n  val xINP_eq_xINQ_th = AP_TERM (mk_comb(IN_t, x)) PeqQ_th\n  val (xINP_imp_xINQ, xINQ_imp_xINP) = EQ_IMP_RULE xINP_eq_xINQ_th\n  val feqg_t = mk_forall(x, mk_imp(xINQ_t, mk_eq(mk_comb(f,x), mk_comb(g, x))))\n  val feqg_th = SPEC x (ASSUME feqg_t)\n  val feqg_th = MP feqg_th xINQ_th\n  val (f_imp_g_th, g_imp_f_th) = EQ_IMP_RULE feqg_th\n\n  fun mk_res th args =\n      List.foldl (RIGHT_BETA o uncurry (C AP_THM)) th args\n\n  (* forall thm *)\n  val resfa_t = prim_mk_const {Thy = \"bool\", Name = \"RES_FORALL\"}\n  val res_pf_t = list_mk_comb(resfa_t, [P, f])\n  val res_qg_t = list_mk_comb(resfa_t, [Q, g])\n  val resfa_pf_eqn = mk_res RES_FORALL_DEF [P, f]\n  val resfa_qg_eqn = mk_res RES_FORALL_DEF [Q, g]\n\n  val resfa_pf_eq_th = SPEC x (EQ_MP resfa_pf_eqn (ASSUME res_pf_t))\n  val g_th = MP f_imp_g_th (MP resfa_pf_eq_th xINP_th)\n  val xinq_imp_g_th =\n      GEN x (DISCH xINQ_t (PROVE_HYP (UNDISCH xINQ_imp_xINP) g_th))\n  val rfa_pf_imp_rfa_qg =\n      DISCH res_pf_t (EQ_MP (SYM resfa_qg_eqn) xinq_imp_g_th)\n\n  val resfa_qg_eq_th = SPEC x (EQ_MP resfa_qg_eqn (ASSUME res_qg_t))\n  val f_th = MP g_imp_f_th (MP resfa_qg_eq_th xINQ_th)\n  val xinp_imp_f_th =\n      GEN x (DISCH xINP_t (PROVE_HYP (UNDISCH xINP_imp_xINQ) f_th))\n  val rfa_qg_imp_rfa_pf =\n      DISCH res_qg_t (EQ_MP (SYM resfa_pf_eqn) xinp_imp_f_th)\n  val fa_eqn = IMP_ANTISYM_RULE rfa_pf_imp_rfa_qg rfa_qg_imp_rfa_pf\n\n  (* exists thm *)\n  val resex_t = prim_mk_const {Thy = \"bool\", Name = \"RES_EXISTS\"}\n  val res_pf_t = list_mk_comb(resex_t, [P, f])\n  val res_qg_t = list_mk_comb(resex_t, [Q, g])\n  val resex_pf_eqn = mk_res RES_EXISTS_DEF [P, f]\n  val resex_qg_eqn = mk_res RES_EXISTS_DEF [Q, g]\n\n  val pf_exbody_th = EQ_MP resex_pf_eqn (ASSUME res_pf_t)\n  val pf_body_th = ASSUME(mk_conj(xINP_t, fx_t))\n  val (new_xINP_th, fx_th) = CONJ_PAIR pf_body_th\n  val new_xINQ_th = MP xINP_imp_xINQ new_xINP_th\n  val new_gx_th = PROVE_HYP new_xINQ_th (MP f_imp_g_th fx_th)\n  val qg_exists =\n      EXISTS(rhs (concl resex_qg_eqn), x) (CONJ new_xINQ_th new_gx_th)\n  val pf_chosen = CHOOSE(x,EQ_MP resex_pf_eqn (ASSUME res_pf_t)) qg_exists\n  val ex_pf_imp_qg = DISCH res_pf_t (EQ_MP (SYM resex_qg_eqn) pf_chosen)\n\n  val qg_exbody_th = EQ_MP resex_qg_eqn (ASSUME res_qg_t)\n  val qg_body_th = ASSUME(mk_conj(xINQ_t, gx_t))\n  val (new_xINQ_th, gx_th) = CONJ_PAIR qg_body_th\n  val new_xINP_th = MP xINQ_imp_xINP new_xINQ_th\n  val new_fx_th = PROVE_HYP new_xINQ_th (MP g_imp_f_th gx_th)\n  val pf_exists =\n      EXISTS (rhs (concl resex_pf_eqn), x) (CONJ new_xINP_th new_fx_th)\n  val qg_chosen = CHOOSE(x, EQ_MP resex_qg_eqn (ASSUME res_qg_t)) pf_exists\n  val ex_qg_imp_pf = DISCH res_qg_t (EQ_MP (SYM resex_pf_eqn) qg_chosen)\n\n  val ex_eqn = IMP_ANTISYM_RULE ex_pf_imp_qg ex_qg_imp_pf\n\nin\n  (save_thm(\"RES_FORALL_CONG\", DISCH PeqQ_t (DISCH feqg_t fa_eqn)),\n   save_thm(\"RES_EXISTS_CONG\", DISCH PeqQ_t (DISCH feqg_t ex_eqn)))\nend\n\n(* ------------------------------------------------------------------------- *)\n(* Monotonicity.                                                             *)\n(* ------------------------------------------------------------------------- *)\n\n\n(* ------------------------------------------------------------------------- *)\n(* MONO_AND |- (x ==> y) /\\ (z ==> w) ==> (x /\\ z ==> y /\\ w)                *)\n(* ------------------------------------------------------------------------- *)\n\nval MONO_AND = save_thm(\"MONO_AND\",\n let val tm1 = ``x ==> y``\n     val tm2 = ``z ==> w``\n     val tm3 = ``x /\\ z``\n     val tm4 = ``y /\\ w``\n     val th1 = ASSUME tm1\n     val th2 = ASSUME tm2\n     val th3 = ASSUME tm3\n     val th4 = CONJUNCT1 th3\n     val th5 = CONJUNCT2 th3\n     val th6 = MP th1 th4\n     val th7 = MP th2 th5\n     val th8 = CONJ th6 th7\n     val th9 = itlist DISCH [tm1,tm2,tm3] th8\n     val th10 = SPEC ``^tm3 ==> ^tm4`` (SPEC tm2 (SPEC tm1 AND_IMP_INTRO))\n in\n    EQ_MP th10 th9\n end);\n\n(* ------------------------------------------------------------------------- *)\n(* MONO_OR |- (x ==> y) /\\ (z ==> w) ==> (x \\/ z ==> y \\/ w)                 *)\n(* ------------------------------------------------------------------------- *)\n\nval MONO_OR = save_thm(\"MONO_OR\",\n let val tm1 = ``x ==> y``\n     val tm2 = ``z ==> w``\n     val tm3 = ``x \\/ z``\n     val tm4 = ``y \\/ w``\n     val th1 = ASSUME tm1\n     val th2 = ASSUME tm2\n     val th3 = ASSUME tm3\n     val th4 = DISJ1 (MP th1 (ASSUME ``x:bool``)) ``w:bool``\n     val th5 = DISJ2 ``y:bool`` (MP th2 (ASSUME ``z:bool``))\n     val th6 = DISJ_CASES th3 th4 th5\n     val th7 = DISCH tm1 (DISCH tm2 (DISCH tm3 th6))\n     val th8 = SPEC ``^tm3 ==> ^tm4`` (SPEC tm2 (SPEC tm1 AND_IMP_INTRO))\n in\n    EQ_MP th8 th7\n end);\n\n(* ------------------------------------------------------------------------- *)\n(* MONO_IMP |- (y ==> x) /\\ (z ==> w) ==> ((x ==> z) ==> (y ==> w))          *)\n(* ------------------------------------------------------------------------- *)\n\nval MONO_IMP = save_thm(\"MONO_IMP\",\n let val tm1 = ``y ==> x``\n     val tm2 = ``z ==> w``\n     val tm3 = ``x ==> z``\n     val tm4 = ``y ==> w``\n     val tm5 = ``y:bool``\n     val th1 = ASSUME tm1\n     val th2 = ASSUME tm2\n     val th3 = ASSUME tm3\n     val th4 = MP th1 (ASSUME tm5)\n     val th5 = MP th3 th4\n     val th6 = MP th2 th5\n     val th7 = DISCH tm1 (DISCH tm2 (DISCH tm3 (DISCH tm5 th6)))\n     val th8 = SPEC ``^tm3 ==> ^tm4`` (SPEC tm2 (SPEC tm1 AND_IMP_INTRO))\n in\n    EQ_MP th8 th7\n end);\n\n(* ------------------------------------------------------------------------- *)\n(* MONO_NOT |- (y ==> x) ==> (~x ==> ~y)                                     *)\n(* ------------------------------------------------------------------------- *)\n\nval MONO_NOT = save_thm(\"MONO_NOT\",\n let val tm1 = ``y ==> x``\n     val tm2 = ``~x``\n     val tm3 = ``y:bool``\n     val th1 = ASSUME tm1\n     val th2 = ASSUME tm2\n     val th3 = ASSUME tm3\n     val th4 = MP th1 th3\n     val th5 = DISCH tm3 (MP th2 th4)\n     val th6 = EQ_MP (SYM (RIGHT_BETA (AP_THM NOT_DEF tm3))) th5\n in\n    DISCH tm1 (DISCH tm2 th6)\n end);\n\n(* ------------------------------------------------------------------------- *)\n(* MONO_NOT_EQ |- (y ==> x) = (~x ==> ~y)                                     *)\n(* ------------------------------------------------------------------------- *)\n\nval MONO_NOT_EQ = save_thm(\"MONO_NOT_EQ\",\n let val tm1 = ``x:bool``\n     val tm2 = ``y:bool``\n     val th1 = INST [tm1 |-> mk_neg tm2, tm2 |-> mk_neg tm1] MONO_NOT\n\n     val th2 = SUBST [``x1:bool`` |-> SPEC tm1 (CONJUNCT1 NOT_CLAUSES),\n                      ``x2:bool`` |-> SPEC tm2 (CONJUNCT1 NOT_CLAUSES)]\n                     ``(~x ==> ~y) ==> (x2 ==> x1)`` th1\n\n     val th3 = IMP_ANTISYM_RULE MONO_NOT th2\n in\n     th3\n end);\n\n(* ------------------------------------------------------------------------- *)\n(* MONO_ALL |- (!x. P x ==> Q x) ==> (!x. P x) ==> !x. Q x                   *)\n(* ------------------------------------------------------------------------- *)\n\nval MONO_ALL = save_thm(\"MONO_ALL\",\n let val tm1 = ``!x:'a. P x ==> Q x``\n     val tm2 = ``!x:'a. P x``\n     val tm3 = ``x:'a``\n     val th1 = ASSUME tm1\n     val th2 = ASSUME tm2\n     val th3 = SPEC tm3 th1\n     val th4 = SPEC tm3 th2\n     val th5 = GEN tm3 (MP th3 th4)\n in\n    DISCH tm1 (DISCH tm2 th5)\n end);\n\n(* ------------------------------------------------------------------------- *)\n(* MONO_EXISTS =  [] |- (!x. P x ==> Q x) ==> (?x. P x) ==> ?x. Q x          *)\n(* ------------------------------------------------------------------------- *)\n\nval MONO_EXISTS = save_thm(\"MONO_EXISTS\",\n let val tm1 = ``!x:'a. P x ==> Q x``\n     val tm2 = ``?x:'a. P x``\n     val tm3 = ``@x:'a. P x``\n     val tm4 = ``\\x:'a. P x:bool``\n     val th1 = ASSUME tm1\n     val th2 = ASSUME tm2\n     val th3 = SPEC tm3 th1\n     val th4 = RIGHT_BETA(RIGHT_BETA (AP_THM EXISTS_DEF tm4))\n     val th5 = EQ_MP th4 th2\n     val th6 = MP th3 th5\n in\n    DISCH tm1 (DISCH tm2 (EXISTS (``?x:'a. Q x``, tm3) th6))\n end);\n\n(* ------------------------------------------------------------------------- *)\n(* MONO_COND |- (x ==> y) ==> (z ==> w)                                      *)\n(*              ==> (if b then x else z) ==> (if b then y else w)            *)\n(* ------------------------------------------------------------------------- *)\n\nval MONO_COND = save_thm(\"MONO_COND\",\n let val tm1 = ``x ==> y``\n     val tm2 = ``z ==> w``\n     val tm3 = ``if b then x else z:bool``\n     val tm4 = ``b:bool``\n     val tm5 = ``x:bool``\n     val tm6 = ``z:bool``\n     val tm7 = ``y:bool``\n     val tm8 = ``w:bool``\n     val th1 = ASSUME tm1\n     val th2 = ASSUME tm2\n     val th3 = ASSUME tm3\n     val th4 = SPEC tm6 (SPEC tm5 (INST_TYPE [alpha |-> bool] COND_CLAUSES))\n     val th5 = CONJUNCT1 th4\n     val th6 = CONJUNCT2 th4\n     val th7 = SPEC tm4 BOOL_CASES_AX\n     val th8 = ASSUME ``b = T``\n     val th9 = ASSUME ``b = F``\n     val th10 = SUBST [tm4 |-> th8] (concl th3) th3\n     val th11 = SUBST [tm4 |-> th9] (concl th3) th3\n     val th12 = EQ_MP th5 th10\n     val th13 = EQ_MP th6 th11\n     val th14 = MP th1 th12\n     val th15 = MP th2 th13\n     val th16 = INST [tm5 |-> tm7, tm6 |-> tm8] th4\n     val th17 = SYM (CONJUNCT1 th16)\n     val th18 = SYM (CONJUNCT2 th16)\n     val th19 = EQ_MP th17 th14\n     val th20 = EQ_MP th18 th15\n     val th21 = DISCH tm3 th19\n     val th22 = DISCH tm3 th20\n     val th23 = SUBST [tm4 |-> th8] (concl th21) th21\n     val th24 = SUBST [tm4 |-> th9] (concl th22) th22\n     val v = ``v:bool``\n     val T = mk_const(\"T\",bool)\n     val template = subst [T |-> v] (concl th23)\n     val th25 = SUBST [v |-> SYM th8] template th23\n     val th26 = SUBST [v |-> SYM th9] template th24\n in\n    DISCH tm1 (DISCH tm2 (DISJ_CASES th7 th25 th26))\n end);\n\n(* ------------------------------------------------------------------------- *)\n(* EXISTS_REFL |- !a. ?x. x = a                                              *)\n(* ------------------------------------------------------------------------- *)\n\nval EXISTS_REFL = save_thm(\"EXISTS_REFL\",\n let val a = ``a:'a``\n     val th1 = REFL a\n     val th2 = EXISTS (``?x:'a. x = a``, a) th1\n in GEN a th2\n end);\n\n(* ------------------------------------------------------------------------- *)\n(* EXISTS_UNIQUE_REFL |- !a. ?!x. x = a                                      *)\n(* ------------------------------------------------------------------------- *)\n\nval EXISTS_UNIQUE_REFL = save_thm(\"EXISTS_UNIQUE_REFL\",\n let val a = ``a:'a``\n     val P = ``\\x:'a. x = a``\n     val tmx = ``^P x``\n     val tmy= ``^P y``\n     val ex = ``?x. ^P x``\n     val th1 = SPEC a EXISTS_REFL\n     val th2 = ABS ``x:'a`` (BETA_CONV tmx)\n     val th3 = AP_TERM ``$? :('a->bool)->bool`` th2\n     val th4 = EQ_MP (SYM th3) th1\n     val th5 = ASSUME (mk_conj(tmx,tmy))\n     val th6 = CONJUNCT1 th5\n     val th7 = CONJUNCT2 th5\n     val th8 = EQ_MP (BETA_CONV (concl th6)) th6\n     val th9 = EQ_MP (BETA_CONV (concl th7)) th7\n     val th10 = TRANS th8 (SYM th9)\n     val th11 = DISCH (hd(hyp th10)) th10\n     val th12 = GEN ``x:'a`` (GEN ``y:'a`` th11)\n     val th13 = INST [``P:'a->bool`` |-> P] EXISTS_UNIQUE_THM\n     val th14 = EQ_MP (SYM th13) (CONJ th4 th12)\n     val th15 = AP_TERM ``$?! :('a->bool)->bool`` th2\n in\n     GEN a (EQ_MP th15 th14)\n end);\n\n\n(* ------------------------------------------------------------------------- *)\n(* Unwinding.                                                                *)\n(* ------------------------------------------------------------------------- *)\n\n\n(* ------------------------------------------------------------------------- *)\n(* UNWIND1_THM |- !P a. (?x. (a = x) /\\ P x) = P a                           *)\n(* ------------------------------------------------------------------------- *)\n\nval UNWIND_THM1 = save_thm(\"UNWIND_THM1\",\n let val P = ``P:'a->bool``\n     val a = ``a:'a``\n     val Pa = ``^P ^a``\n     val v = ``v:'a``\n     val tm1 = ``?x:'a. (a = x) /\\ P x``\n     val th1 = ASSUME tm1\n     val th2 = ASSUME ``(a:'a = v) /\\ P v``\n     val th3 = CONJUNCT1 th2\n     val th4 = CONJUNCT2 th2\n     val th5 = SUBST [v |-> SYM th3] (concl th4) th4\n     val th6 = DISCH tm1 (CHOOSE (v,th1) th5)\n     val th7 = ASSUME Pa\n     val th8 = CONJ (REFL a) th7\n     val th9 = EXISTS (tm1,a) th8\n     val th10 = DISCH Pa th9\n     val th11 = SPEC Pa (SPEC tm1 IMP_ANTISYM_AX)\n in\n    GEN P (GEN a (MP (MP th11 th6) th10))\n end);\n\n\n(* ------------------------------------------------------------------------- *)\n(* UNWIND_THM2  |- !P a. (?x. (x = a) /\\ P x) = P a                          *)\n(* ------------------------------------------------------------------------- *)\n\nval UNWIND_THM2 = save_thm(\"UNWIND_THM2\",\n let val P = ``P:'a->bool``\n     val a = ``a:'a``\n     val Px = ``^P x``\n     val Pa = ``^P ^a``\n     val u = ``u:'a``\n     val v = ``v:'a``\n     val a_eq_x = ``a:'a = x``\n     val x_eq_a = ``x:'a = a``\n     val th1 = SPEC a (SPEC P UNWIND_THM1)\n     val th2 = REFL Pa\n     val th3 = DISCH a_eq_x (SYM (ASSUME a_eq_x))\n     val th4 = DISCH x_eq_a (SYM (ASSUME x_eq_a))\n     val th5 = SPEC a_eq_x (SPEC x_eq_a IMP_ANTISYM_AX)\n     val th6 = MP (MP th5 th4) th3\n     val th7 = MK_COMB (MK_COMB (REFL ``$/\\``, th6), REFL Px)\n     val th8 = MK_COMB (REFL``$? :('a->bool)->bool``,\n                        ABS ``x:'a`` th7)\n     val th9 = MK_COMB(MK_COMB (REFL``$= :bool->bool->bool``, th8),th2)\n     val th10 = EQ_MP (SYM th9) th1\n in\n    GEN P (GEN a th10)\n end);\n\n\n(* ------------------------------------------------------------------------- *)\n(* UNWIND_FORALL_THM1   |- !f v. (!x. (v = x) ==> f x) = f v                 *)\n(* ------------------------------------------------------------------------- *)\n\nval UNWIND_FORALL_THM1 = save_thm(\"UNWIND_FORALL_THM1\",\n let val f = ``f : 'a -> bool``\n     val v = ``v:'a``\n     val fv = ``^f ^v``\n     val tm1 = ``!x:'a. (v = x) ==> f x``\n     val tm2 = ``v:'a = x``\n     val th1 = ASSUME tm1\n     val th2 = ASSUME fv\n     val th3 = DISCH tm1 (MP (SPEC v th1) (REFL v))\n     val th4 = ASSUME tm2\n     val th5 = SUBST [v |-> th4] (concl th2) th2\n     val th6 = DISCH fv (GEN ``x:'a`` (DISCH tm2 th5))\n     val th7 = MP (MP (SPEC tm1 (SPEC fv IMP_ANTISYM_AX)) th6) th3\n in\n   GEN f (GEN v (SYM th7))\n end);\n\n\n(* ------------------------------------------------------------------------- *)\n(* UNWIND_FORALL_THM2   |- !f v. (!x. (x = v) ==> f x) = f v                 *)\n(* ------------------------------------------------------------------------- *)\n\nval UNWIND_FORALL_THM2 = save_thm(\"UNWIND_FORALL_THM2\",\n let val f   = ``f:'a->bool``\n     val v   = ``v:'a``\n     val fv  = ``^f ^v``\n     val tm1 = ``!x:'a. (x = v) ==> f x``\n     val tm2 = ``x:'a = v``\n     val th1 = ASSUME tm1\n     val th2 = ASSUME fv\n     val th3 = DISCH tm1 (MP (SPEC v th1) (REFL v))\n     val th4 = ASSUME tm2\n     val th5 = SUBST [v |-> SYM th4] (concl th2) th2\n     val th6 = DISCH fv (GEN ``x:'a`` (DISCH tm2 th5))\n     val th7 = MP (MP (SPEC tm1 (SPEC fv IMP_ANTISYM_AX)) th6) th3\n in\n   GEN f (GEN v (SYM th7))\n end);\n\n\n(* ------------------------------------------------------------------------- *)\n(* Skolemization:    |- !P. (!x. ?y. P x y) <=> ?f. !x. P x (f x)            *)\n(* ------------------------------------------------------------------------- *)\n\nval SKOLEM_THM = save_thm(\"SKOLEM_THM\",\n let val P = ``P:'a -> 'b -> bool``\n     val x = ``x:'a``\n     val y = ``y:'b``\n     val f = ``f:'a->'b``\n     val tm1 = ``!x. ?y. ^P x y``\n     val tm2 = ``?f. !x. ^P x (f x)``\n     val tm4 = ``\\x. @y. ^P x y``\n     val tm5 = ``(\\x. @y. ^P x y) x``\n     val th1 = ASSUME tm1\n     val th2 = ASSUME tm2\n     val th3 = SPEC x th1\n     val th4 = INST_TYPE [alpha |-> beta] SELECT_AX\n     val th5 = SPEC y (SPEC ``\\y. ^P x y`` th4)\n     val th6 = BETA_CONV (fst(dest_imp(concl th5)))\n     val th7 = BETA_CONV (snd(dest_imp(concl th5)))\n     val th8 = MK_COMB (MK_COMB (REFL ``$==>``,th6),th7)\n     val th9 = EQ_MP th8 th5\n     val th10 = MP th9 (ASSUME(fst(dest_imp(concl th9))))\n     val th11 = CHOOSE (y,th3) th10\n     val th12 = SYM (BETA_CONV tm5)\n     val th13 = SUBST [``v:'b`` |-> th12] ``^P x v`` th11\n     val th14 = DISCH tm1 (EXISTS (tm2,tm4) (GEN x th13))\n     val th15 = ASSUME ``!x. ^P x (f x)``\n     val th16 = SPEC x th15\n     val th17 = GEN x (EXISTS(``?y. ^P x y``,``f (x:'a):'b``) th16)\n     val th18 = DISCH tm2 (CHOOSE (f,th2) th17)\n     val th19 = MP (MP (SPEC tm1 (SPEC tm2 IMP_ANTISYM_AX)) th18) th14\n in\n     GEN P (SYM th19)\n end);\n\n\n(*---------------------------------------------------------------------------\n    Support for pattern matching on booleans.\n\n    bool_case_thm =\n        |- (!e0 e1. bool_case e0 e1 T = e0) /\\\n            !e0 e1. bool_case e0 e1 F = e1\n ---------------------------------------------------------------------------*)\n\nval bool_case_thm = let\n  val (vs,_) = strip_forall (concl COND_CLAUSES)\nin\n  save_thm(\"bool_case_thm\",\n           COND_CLAUSES |> SPECL vs |> CONJUNCTS |> map (GENL vs) |> LIST_CONJ)\nend\n\n(* ------------------------------------------------------------------------- *)\n(*    bool_case_ID = |- !x b. bool_case x x b = x                            *)\n(* ------------------------------------------------------------------------- *)\n\nval bool_case_ID = save_thm(\"bool_case_ID\", COND_ID)\n\n\n(* ------------------------------------------------------------------------- *)\n(* boolAxiom  |- !e0 e1. ?fn. (fn T = e0) /\\ (fn F = e1)                     *)\n(* ------------------------------------------------------------------------- *)\n\nval boolAxiom = save_thm(\"boolAxiom\",\n let\n   val ([e0,e1], _) = strip_forall (concl COND_CLAUSES)\n   val (th2, th3) = CONJ_PAIR (SPECL [e0, e1] COND_CLAUSES)\n   val f_t = ``\\b. if b then ^e0 else ^e1``\n   val f_T = TRANS (BETA_CONV (mk_comb(f_t, T))) th2\n   val f_F = TRANS (BETA_CONV (mk_comb(f_t, F))) th3\n   val th4 = CONJ f_T f_F\n   val th5 = EXISTS (``?fn. (fn T = ^e0) /\\ (fn F = ^e1)``, f_t) th4\n in\n    GEN e0 (GEN e1 th5)\n end);\n\n(* ------------------------------------------------------------------------- *)\n(* bool_INDUCT |- !P. P T /\\ P F ==> !b. P b                                 *)\n(* ------------------------------------------------------------------------- *)\n\nval bool_INDUCT = save_thm(\"bool_INDUCT\",\n let val P = ``P:bool -> bool``\n     val b = ``b:bool``\n     val v = ``v:bool``\n     val tm1 = ``^P T /\\ ^P F``\n     val th1 = SPEC b BOOL_CASES_AX\n     val th2 = ASSUME tm1\n     val th3 = CONJUNCT1 th2\n     val th4 = CONJUNCT2 th2\n     val th5 = ASSUME ``b = T``\n     val th6 = ASSUME ``b = F``\n     val th7 = SUBST [v |-> SYM th5] ``^P ^v`` th3\n     val th8 = SUBST [v |-> SYM th6] ``^P ^v`` th4\n     val th9 = GEN b (DISJ_CASES th1 th7 th8)\n in\n     GEN P (DISCH tm1 th9)\n end);\n\n(* ---------------------------------------------------------------------------\n   |- !P Q x x' y y'.\n         (P = Q) /\\ (Q ==> (x = x')) /\\ (~Q ==> (y = y')) ==>\n         ((case P of T -> x || F -> y) = (case Q of T -> x' || F -> y'))\n  --------------------------------------------------------------------------- *)\n\nval bool_case_CONG = save_thm(\"bool_case_CONG\", COND_CONG)\n\nval FORALL_BOOL = save_thm\n(\"FORALL_BOOL\",\n let val tm1 = ``!b:bool. P b``\n     val tm2 = ``P T /\\ P F``\n     val th1 = ASSUME tm1\n     val th2 = CONJ (SPEC T th1) (SPEC F th1)\n     val th3 = DISCH tm1 th2\n     val th4 = ASSUME tm2\n     val th5 = MP (SPEC ``P:bool->bool`` bool_INDUCT) th4\n     val th6 = DISCH tm2 th5\n in\n   IMP_ANTISYM_RULE th3 th6\n end);\n\n\n(*---------------------------------------------------------------------------\n          Results about Unique existence.\n ---------------------------------------------------------------------------*)\n\nlocal\n  val LAND_CONV = RATOR_CONV o RAND_CONV\n  val P = mk_var(\"P\",   Type.alpha --> Type.bool)\n  val p = mk_var(\"p\",   Type.bool)\n  val q = mk_var(\"q\",   Type.bool)\n  val Q = mk_var(\"Q\",   Type.alpha --> Type.bool)\n  val x = mk_var(\"x\",   Type.alpha)\n  val y = mk_var(\"y\",   Type.alpha)\n  val Px = mk_comb(P, x)\n  val Py = mk_comb(P, y)\n  val Qx = mk_comb(Q, x)\n  val Qy = mk_comb(Q, y)\n  val uex_t = mk_const(\"?!\", (alpha --> bool) --> bool)\n  val exP = mk_exists(x, Px)\n  val exQ = mk_exists(x, Qx)\n  val uexP = mk_exists1(x, Px)\n  val uexQ = mk_exists1(x, Qx)\n  val pseudo_mp = let\n    val lhs_t = mk_conj(p, mk_imp(p, q))\n    val rhs_t = mk_conj(p, q)\n    val lhs_thm = ASSUME lhs_t\n    val (p_thm, pimpq) = CONJ_PAIR lhs_thm\n    val dir1 = DISCH_ALL (CONJ p_thm (MP pimpq p_thm))\n    val rhs_thm = ASSUME rhs_t\n    val (p_thm, q_thm) = CONJ_PAIR rhs_thm\n    val dir2 = DISCH_ALL (CONJ p_thm (DISCH p q_thm))\n  in\n    IMP_ANTISYM_RULE dir1 dir2\n  end\nin\n  val UEXISTS_OR_THM = let\n    val subdisj_t = mk_abs(x, mk_disj(Px, Qx))\n    val lhs_t = mk_comb(uex_t, subdisj_t)\n    val lhs_thm = ASSUME lhs_t\n    val lhs_eq = AP_THM EXISTS_UNIQUE_DEF subdisj_t\n    val lhs_expanded = CONV_RULE BETA_CONV (EQ_MP lhs_eq lhs_thm)\n    val (expq0, univ) =  CONJ_PAIR lhs_expanded\n    val expq = EQ_MP (SPEC_ALL EXISTS_OR_THM) expq0\n    val univ1 = SPEC_ALL univ\n    val univ2 = CONV_RULE (LAND_CONV (LAND_CONV BETA_CONV)) univ1\n    val univ3 = CONV_RULE (LAND_CONV (RAND_CONV BETA_CONV)) univ2\n    val P_half = let\n      val asm = ASSUME (mk_conj(Px,Py))\n      val (Px_thm, Py_thm) = CONJ_PAIR asm\n      val PxQx_thm = DISJ1 Px_thm Qx\n      val PyQy_thm = DISJ1 Py_thm Qy\n      val resolvent = CONJ PxQx_thm PyQy_thm\n      val rhs =\n        GENL [x,y]\n        (DISCH (mk_conj(Px,Py)) (PROVE_HYP resolvent (UNDISCH univ3)))\n    in\n      DISJ1 (EQ_MP (SYM EXISTS_UNIQUE_THM) (CONJ (ASSUME exP) rhs)) uexQ\n    end\n    val Q_half = let\n      val asm = ASSUME (mk_conj(Qx,Qy))\n      val (Qx_thm, Qy_thm) = CONJ_PAIR asm\n      val PxQx_thm = DISJ2 Px Qx_thm\n      val PyQy_thm = DISJ2 Py Qy_thm\n      val resolvent = CONJ PxQx_thm PyQy_thm\n      val rhs =\n        GENL [x,y]\n        (DISCH (mk_conj(Qx,Qy)) (PROVE_HYP resolvent (UNDISCH univ3)))\n      val uex_expanded = SYM (INST [P |-> Q] EXISTS_UNIQUE_THM)\n    in\n      DISJ2 uexP (EQ_MP uex_expanded (CONJ (ASSUME exQ) rhs))\n    end\n  in\n    save_thm(\"UEXISTS_OR_THM\",\n             GENL [P, Q] (DISCH_ALL (DISJ_CASES expq P_half Q_half)))\n  end;\n\n  val UEXISTS_SIMP = let\n    fun mCONV_RULE c thm = TRANS thm (c  (rhs (concl thm)))\n    val xeqy = mk_eq(x,y)\n    val t = mk_var(\"t\",   bool)\n    val abst = mk_abs(x, t)\n    val uext_t = mk_exists1(x,t)\n    val exp0 = AP_THM EXISTS_UNIQUE_DEF abst\n    val exp1 = mCONV_RULE BETA_CONV exp0\n    val exp2 = mCONV_RULE (LAND_CONV (K (SPEC t EXISTS_SIMP))) exp1\n    val exp3 =\n      mCONV_RULE (RAND_CONV\n                  (QUANT_CONV\n                   (QUANT_CONV (LAND_CONV (LAND_CONV BETA_CONV))))) exp2\n    val exp4 =\n      mCONV_RULE (RAND_CONV\n                  (QUANT_CONV\n                   (QUANT_CONV (LAND_CONV (RAND_CONV BETA_CONV))))) exp3\n    val exp5 =\n      mCONV_RULE (RAND_CONV\n                  (QUANT_CONV\n                   (QUANT_CONV (LAND_CONV (K (SPEC t AND_CLAUSE5)))))) exp4\n    val pushy0 =\n      SPECL [t, mk_abs(y,xeqy)]\n      RIGHT_FORALL_IMP_THM\n    val pushy1 =\n      CONV_RULE (LAND_CONV (QUANT_CONV (RAND_CONV BETA_CONV))) pushy0\n    val pushy2 =\n      CONV_RULE (RAND_CONV (RAND_CONV (QUANT_CONV BETA_CONV))) pushy1\n    val exp6 =\n      mCONV_RULE (RAND_CONV (QUANT_CONV (K pushy2))) exp5\n    val pushx0 = SPECL [t, mk_abs(x, mk_forall(y,xeqy))]\n                       RIGHT_FORALL_IMP_THM\n    val pushx1 =\n      CONV_RULE (LAND_CONV (QUANT_CONV (RAND_CONV BETA_CONV))) pushx0\n    val pushx2 =\n      CONV_RULE (RAND_CONV (RAND_CONV (QUANT_CONV BETA_CONV))) pushx1\n    val exp7 =\n      mCONV_RULE (RAND_CONV (K pushx2)) exp6\n    val mp' = Thm.INST [p |-> t, q |-> list_mk_forall [x,y] xeqy] pseudo_mp\n  in\n    save_thm(\"UEXISTS_SIMP\", mCONV_RULE (K mp') exp7)\n  end\nend\n\n\n(*---------------------------------------------------------------------------\n     The definition of restricted abstraction.\n ---------------------------------------------------------------------------*)\n\nval RES_ABSTRACT_EXISTS =\n  let\n    fun B_CONV n = funpow n RATOR_CONV BETA_CONV\n    fun RHS th = rhs (concl th)\n    val p = ``p : 'a -> bool``\n    val m = ``m : 'a -> 'b``\n    val m1 = ``m1 : 'a -> 'b``\n    val m2 = ``m2 : 'a -> 'b``\n    val x = ``x : 'a``\n    val witness = ``\\p m x. if x IN p then ^m x else ARB x``\n    val A1 = B_CONV 2 ``^witness ^p ^m ^x``\n    val A2 = TRANS A1 (B_CONV 1 (RHS A1))\n    val A3 = TRANS A2 (BETA_CONV (RHS A2))\n    val A4 = EQT_INTRO (ASSUME ``^x IN ^p``)\n    val A5 = RATOR_CONV (RATOR_CONV (RAND_CONV (K A4))) (RHS A3)\n    val A6 = INST_TYPE [alpha |-> beta] COND_CLAUSE1\n    val A7 = SPECL [``^m ^x``, ``ARB ^x : 'b``] A6\n    val A8 = DISCH ``^x IN ^p`` (TRANS (TRANS A3 A5) A7)\n    val A9 = GENL [``^p``, ``^m``, ``^x``] A8\n    (* Completed the first clause of the definition *)\n    val B1 = SPEC ``^x IN ^p`` EXCLUDED_MIDDLE\n    val B2 = UNDISCH A8\n    val B3 = INST [m |-> m1] B2\n    val B4 = INST [m |-> m2] B2\n    val B5 = SPEC_ALL (ASSUME ``!x. x IN ^p ==> (^m1 x = ^m2 x)``)\n    val B6 = TRANS B3 (TRANS (UNDISCH B5) (SYM B4))\n    val B7 = INST [m |-> m1] A3\n    val B8 = INST [m |-> m2] A3\n    val B9 = SYM (SPEC ``^x IN ^p`` EQ_CLAUSE4)\n    val B10 = EQ_MP B9 (ASSUME ``~(^x IN ^p)``)\n    val B11 = INST_TYPE [alpha |-> beta] COND_CLAUSE2\n    val B12 = RATOR_CONV (RATOR_CONV (RAND_CONV (K B10))) (RHS B7)\n    val B13 = TRANS B12 (SPECL [``^m1 ^x``, ``ARB ^x : 'b``] B11)\n    val B14 = RATOR_CONV (RATOR_CONV (RAND_CONV (K B10))) (RHS B8)\n    val B15 = TRANS B14 (SPECL [``^m2 ^x``, ``ARB ^x : 'b``] B11)\n    val B16 = TRANS (TRANS B7 B13) (SYM (TRANS B8 B15))\n    val B17 = DISJ_CASES B1 B6 B16\n    val B18 = ABS x B17\n    val B19 = CONV_RULE (RATOR_CONV (RAND_CONV ETA_CONV)) B18\n    val B20 = CONV_RULE (RAND_CONV ETA_CONV) B19\n    val B21 = DISCH ``!x. x IN ^p ==> (^m1 x = ^m2 x)`` B20\n    val B22 = GENL [p, m1, m2] B21\n    (* Cleaning up *)\n    val C1 = CONJ A9 B22\n    val C2 = EXISTS\n      (``?f.\n               (!p (m : 'a -> 'b) x. x IN p ==> (f p m x = m x)) /\\\n               (!p m1 m2.\n                  (!x. x IN p ==> (m1 x = m2 x)) ==> (f p m1 = f p m2))``,\n       ``\\p (m : 'a -> 'b) x. (if x IN p then m x else ARB x)``) C1\n  in\n    C2\n  end;\n\nval RES_ABSTRACT_DEF =\n  Definition.new_specification\n  (\"RES_ABSTRACT_DEF\", [\"RES_ABSTRACT\"], RES_ABSTRACT_EXISTS);\n\nval _ = associate_restriction (\"\\\\\", \"RES_ABSTRACT\");\n\n\nval (RES_FORALL_THM, RES_EXISTS_THM, RES_EXISTS_UNIQUE_THM, RES_SELECT_THM) =\n    let\n      val Pf = map (fn s => mk_var(s, alpha --> bool)) [\"P\", \"f\"]\n      fun mk_eq th =\n          GENL Pf (List.foldl (RIGHT_BETA o uncurry (C AP_THM)) th Pf)\n    in\n      (save_thm(\"RES_FORALL_THM\", mk_eq RES_FORALL_DEF),\n       save_thm(\"RES_EXISTS_THM\", mk_eq RES_EXISTS_DEF),\n       save_thm(\"RES_EXISTS_UNIQUE_THM\", mk_eq RES_EXISTS_UNIQUE_DEF),\n       save_thm(\"RES_SELECT_THM\", mk_eq RES_SELECT_DEF))\n    end\n\n\n(* (!x::P. T) = T *)\nval RES_FORALL_TRUE = let\n  val x = mk_var(\"x\", alpha)\n  val T = concl TRUTH\n  val KT = mk_abs(x, T)\n  val P = mk_var(\"P\", alpha --> bool)\n  val th0 = SPECL[P,KT] RES_FORALL_THM\n  val th1 = CONV_RULE (RAND_CONV (QUANT_CONV (RAND_CONV BETA_CONV))) th0\n  val xINP_t = (rand o rator o #2 o dest_forall o rhs o concl) th1\n  val timpT_th = List.nth(CONJUNCTS (SPEC xINP_t IMP_CLAUSES), 1)\n  val th2 = CONV_RULE (RAND_CONV (QUANT_CONV (K timpT_th))) th1\nin\n  save_thm(\"RES_FORALL_TRUE\", TRANS th2 (SPEC T FORALL_SIMP))\nend\n\n(* (?x::P. F) = F *)\nval RES_EXISTS_FALSE = let\n  val x = mk_var(\"x\", alpha)\n  val F = prim_mk_const{Thy = \"bool\", Name = \"F\"}\n  val KF = mk_abs(x, F)\n  val P = mk_var(\"P\", alpha --> bool)\n  val th0 = SPECL [P, KF] RES_EXISTS_THM\n  val th1 = CONV_RULE (RAND_CONV (QUANT_CONV (RAND_CONV BETA_CONV))) th0\n  val xINP_t = (rand o rator o #2 o dest_exists o rhs o concl) th1\n  val tandF_th = List.nth(CONJUNCTS (SPEC xINP_t AND_CLAUSES), 3)\n  val th2 = CONV_RULE (RAND_CONV (QUANT_CONV (K tandF_th))) th1\nin\n  save_thm(\"RES_EXISTS_FALSE\", TRANS th2 (SPEC F EXISTS_SIMP))\nend\n\n(*---------------------------------------------------------------------------\n     From Joe Hurd : case analysis on the (4) functions in the\n     type :bool -> bool.\n\n     val BOOL_FUN_CASES_THM =\n     |- !f. (f = \\b. T) \\/ (f = \\b. F) \\/ (f = \\b. b) \\/ (f = \\b. ~b)\n ---------------------------------------------------------------------------*)\n\nval BOOL_FUN_CASES_THM =\n let val x       = mk_var(\"x\",bool)\n     val f       = mk_var(\"f\",bool-->bool)\n     val KF      = ``\\b:bool.F``\n     val KT      = ``\\b:bool.T``\n     val Ibool   = ``\\b:bool.b``\n     val dual    = ``\\b. ~b``\n     val fT      = mk_comb(f,T)\n     val fF      = mk_comb(f,F)\n     val fT_eq_T = mk_eq(fT,T)\n     val fF_eq_T = mk_eq(fF,T)\n     val fT_eq_F = mk_eq(fT,F)\n     val fF_eq_F = mk_eq(fF,F)\n     val final   = ``(f = ^KT) \\/ (f = ^KF) \\/ (f = ^Ibool) \\/ (f = ^dual)``\n     val a0 = TRANS (ASSUME fT_eq_T) (SYM (BETA_CONV (mk_comb(KT,T))))\n     val a1 = TRANS (ASSUME fF_eq_T) (SYM (BETA_CONV (mk_comb(KT,F))))\n     val a2 = BOOL_CASE ``f x = ^KT x`` x x a0 a1\n     val a3 = EXT (GEN x a2)\n     val a  = DISJ1 a3 ``(f = \\b. F) \\/ (f = \\b. b) \\/ (f = \\b. ~b)``\n     val b0 = TRANS (ASSUME fT_eq_F) (SYM (BETA_CONV (mk_comb(KF,T))))\n     val b1 = TRANS (ASSUME fF_eq_F) (SYM (BETA_CONV (mk_comb(KF,F))))\n     val b2 = BOOL_CASE ``f x = ^KF x`` x x b0 b1\n     val b3 = EXT (GEN x b2)\n     val b4 = DISJ1 b3 ``(f = ^Ibool) \\/ (f = \\b. ~b)``\n     val b  = DISJ2 ``f = ^KT`` b4\n     val c0 = TRANS (ASSUME fT_eq_T) (SYM (BETA_CONV (mk_comb(Ibool,T))))\n     val c1 = TRANS (ASSUME fF_eq_F) (SYM (BETA_CONV (mk_comb(Ibool,F))))\n     val c2 = BOOL_CASE ``f x = ^Ibool x`` x x c0 c1\n     val c3 = EXT (GEN x c2)\n     val c4 = DISJ1 c3 ``f = ^dual``\n     val c5 = DISJ2 ``f = ^KF`` c4\n     val c  = DISJ2 ``f = ^KT`` c5\n     val d0 = TRANS (ASSUME fT_eq_F)\n                (TRANS (SYM (CONJUNCT1 (CONJUNCT2 NOT_CLAUSES)))\n                       (SYM (BETA_CONV (mk_comb(dual,T)))))\n     val d1 = TRANS (ASSUME fF_eq_T)\n               (TRANS (SYM (CONJUNCT2 (CONJUNCT2 NOT_CLAUSES)))\n                      (SYM (BETA_CONV (mk_comb(dual,F)))))\n     val d2 = BOOL_CASE ``f x = ^dual x`` x x d0 d1\n     val d3 = EXT (GEN x d2)\n     val d4 = DISJ2 ``f = ^Ibool`` d3\n     val d5 = DISJ2 ``f = ^KF`` d4\n     val d  = DISJ2 ``f = ^KT`` d5\n     val ad0 = DISCH fT_eq_T a\n     val ad1 = DISCH fT_eq_F d\n     val ad2 = BOOL_CASE ``(f T = x) ==> ^final`` x x ad0 ad1\n     val ad3 = SPEC fT (GEN x ad2)\n     val ad  = MP ad3 (REFL fT)\n     val bc0 = DISCH fT_eq_T c\n     val bc1 = DISCH fT_eq_F b\n     val bc2 = BOOL_CASE ``(f T = x) ==> ^final`` x x bc0 bc1\n     val bc3 = SPEC fT (GEN x bc2)\n     val bc  = MP bc3 (REFL fT)\n     val abcd0 = DISCH fF_eq_T ad\n     val abcd1 = DISCH fF_eq_F bc\n     val abcd2 = BOOL_CASE ``(f F = x) ==> ^final`` x x abcd0 abcd1\n     val abcd3 = SPEC fF (GEN x abcd2)\n     val abcd  = MP abcd3 (REFL fF)\nin\n   save_thm(\"BOOL_FUN_CASES_THM\", GEN f abcd)\nend;\n\n(*---------------------------------------------------------------------------\n     Another from Joe Hurd : consequence of BOOL_FUN_CASES_THM\n\n     BOOL_FUN_INDUCT =\n     |- !P. P (\\b. T) /\\ P (\\b. F) /\\ P (\\b. b) /\\ P (\\b. ~b) ==> !f. P f\n ---------------------------------------------------------------------------*)\n\n  fun or_imp th0 =\n    let val (disj1, disj2) = dest_disj (concl th0)\n        val th1 = SYM (SPEC disj1 (CONJUNCT1 NOT_CLAUSES))\n        val th2 = MK_COMB (REFL disjunction, th1)\n        val th3 = MK_COMB (th2, REFL disj2)\n        val th4 = EQ_MP th3 th0\n        val th5 = SYM (SPECL [mk_neg disj1, disj2] IMP_DISJ_THM)\n    in\n      EQ_MP th5 th4\n    end\n\n  fun imp_and th0 =\n    let val (ant, conseq) = dest_imp (concl th0)\n      val (ant', conseq') = dest_imp conseq\n      val th1 = SPECL [ant, ant', conseq'] AND_IMP_INTRO\n    in\n      EQ_MP th1 th0\n    end\n\n\nval BOOL_FUN_INDUCT =\n let val f = mk_var(\"f\",bool-->bool)\n     val g = mk_var(\"g\",bool-->bool)\n     val f_eq_g = mk_eq(f,g)\n     val P = mk_var(\"P\",(bool-->bool) --> bool)\n     val KF    = ``\\b:bool.F``\n     val KT    = ``\\b:bool.T``\n     val Ibool = ``\\b:bool.b``\n     val dual  = ``\\b. ~b``\n     val f0 = ASSUME (mk_neg(mk_comb(P,f)))\n     val f1 = ASSUME (mk_neg(mk_neg(f_eq_g)))\n     val f2 = EQ_MP (SPEC f_eq_g (CONJUNCT1 NOT_CLAUSES)) f1\n     val f3 = MK_COMB (REFL P, f2)\n     val f4 = MK_COMB (REFL negation, f3)\n     val f5 = UNDISCH (NOT_ELIM (EQ_MP f4 f0))\n     val f6 = CCONTR (mk_neg(f_eq_g)) f5\n     val f7  = GEN g (DISCH (mk_comb(P,g)) f6)\n     val a0 = SPEC f BOOL_FUN_CASES_THM\n     val a1 = MP (or_imp a0) (UNDISCH (SPEC KT f7))\n     val a2 = MP (or_imp a1) (UNDISCH (SPEC KF f7))\n     val a3 = MP (or_imp a2) (UNDISCH (SPEC Ibool f7))\n     val a  = MP (NOT_ELIM (UNDISCH (SPEC dual f7))) a3\n     val b0 = CCONTR (mk_comb(P,f)) a\n     val b1 = GEN f b0\n     val b2 = DISCH (mk_comb(P,dual)) b1\n     val b3 = imp_and (DISCH (mk_comb(P,Ibool)) b2)\n     val b4 = imp_and (DISCH (mk_comb(P,KF)) b3)\n     val b  = imp_and (DISCH (mk_comb(P,KT)) b4)\nin\n   save_thm(\"BOOL_FUN_INDUCT\", GEN P b)\nend;\n\n(*---------------------------------------------------------------------------\n     literal_case_THM = |- !f x. literal_case f x = f x\n ---------------------------------------------------------------------------*)\n\nval literal_case_THM = save_thm(\"literal_case_THM\",\n let val f = ``f:'a->'b``\n     val x = ``x:'a``\n in\n  GEN f (GEN x\n    (RIGHT_BETA(AP_THM (RIGHT_BETA(AP_THM literal_case_DEF f)) x)))\n end);\n\n(*---------------------------------------------------------------------------*)\n(*    literal_case_RAND =                                                    *)\n(*        |- P (literal_case (\\x. N x) M) = (literal_case (\\x. P (N x)) M)   *)\n(*---------------------------------------------------------------------------*)\n\nval literal_case_RAND = save_thm(\"literal_case_RAND\",\n let val tm1 = ``\\x:'a. P (N x:'b):'c``\n     val tm2 = ``M:'a``\n     val tm3 = ``\\x:'a. N x:'b``\n     val P   = ``P:'b ->'c``\n     val literal_case_THM1 = RIGHT_BETA (SPEC tm2 (SPEC tm1\n                    (Thm.INST_TYPE [beta |-> gamma] literal_case_THM)))\n     val literal_case_THM2 = AP_TERM P (RIGHT_BETA (SPEC tm2 (SPEC tm3 literal_case_THM)))\n in TRANS literal_case_THM2 (SYM literal_case_THM1)\n end);\n\n(*---------------------------------------------------------------------------*)\n(*    literal_case_RATOR =                                                   *)\n(*         |- (literal_case (\\x. N x) M) b = (literal_case (\\x. N x b) M)    *)\n(*---------------------------------------------------------------------------*)\n\nval literal_case_RATOR = save_thm(\"literal_case_RATOR\",\n let val M = ``M:'a``\n     val b = ``b:'b``\n     val tm1 = ``\\x:'a. N x:'b->'c``\n     val tm2 = ``\\x:'a. N x ^b:'c``\n     val literal_case_THM1 = AP_THM (RIGHT_BETA (SPEC M (SPEC tm1\n                   (Thm.INST_TYPE [beta |-> (beta --> gamma)] literal_case_THM)))) b\n     val literal_case_THM2 = RIGHT_BETA (SPEC M (SPEC tm2\n                      (Thm.INST_TYPE [beta |-> gamma] literal_case_THM)))\n in TRANS literal_case_THM1 (SYM literal_case_THM2)\n end);\n\n(*---------------------------------------------------------------------------\n  literal_case_CONG =\n    |- !f g M N.  (M = N) /\\ (!x. (x = N) ==> (f x = g x))\n                            ==>\n                   (literal_case f M = literal_case g N)\n ---------------------------------------------------------------------------*)\n\nval literal_case_CONG = save_thm(\"literal_case_CONG\",\n  let val f = mk_var(\"f\",alpha-->beta)\n      val g = mk_var(\"g\",alpha-->beta)\n      val M = mk_var(\"M\",alpha)\n      val N = mk_var(\"N\",alpha)\n      val x = mk_var (\"x\",alpha)\n      val MeqN = mk_eq(M,N)\n      val x_eq_N = mk_eq(x,N)\n      val fx_eq_gx = mk_eq(mk_comb(f,x),mk_comb(g,x))\n      val ctm = mk_forall(x, mk_imp(x_eq_N,fx_eq_gx))\n      val th  = RIGHT_BETA(AP_THM(RIGHT_BETA(AP_THM literal_case_DEF f)) M)\n      val th1 = ASSUME MeqN\n      val th2 = MP (SPEC N (ASSUME ctm)) (REFL N)\n      val th3 = SUBS [SYM th1] th2\n      val th4 = TRANS (TRANS th th3) (MK_COMB (REFL g,th1))\n      val th5 = RIGHT_BETA(AP_THM(RIGHT_BETA(AP_THM literal_case_DEF g)) N)\n      val th6 = TRANS th4 (SYM th5)\n      val th7 = SUBS [SPECL [MeqN, ctm, concl th6] AND_IMP_INTRO]\n                     (DISCH MeqN (DISCH ctm th6))\n  in\n    GENL [f,g,M,N] th7\n  end);\n\n(*---------------------------------------------------------------------------*)\n(* Sometime useful rewrite, but you will want a higher-order version.        *)\n(*  |- literal_case (\\x. bool_case t u (x=a)) a = t                          *)\n(*---------------------------------------------------------------------------*)\n\nval literal_case_id = save_thm\n(\"literal_case_id\",\n let val a = mk_var(\"a\", alpha)\n    val x = mk_var(\"x\", alpha)\n    val t = mk_var(\"t\",beta)\n    val u = mk_var(\"u\",beta)\n    val eq = mk_eq(x,a)\n    val bcase = inst [alpha |-> beta]\n                     (prim_mk_const{Name = \"COND\",Thy=\"bool\"})\n    val g = mk_abs(x,list_mk_comb(bcase,[eq, t, u]))\n    val lit_thm = RIGHT_BETA(SPEC a (SPEC g literal_case_THM))\n    val Teq = SYM (EQT_INTRO(REFL a))\n    val ifT = CONJUNCT1(SPECL[t,u] (INST_TYPE[alpha |-> beta] COND_CLAUSES))\n    val ifeq = SUBS [Teq] ifT\n in\n    TRANS lit_thm ifeq\n end);\n\n(*---------------------------------------------------------------------------\n         Support for parsing \"case\" expressions\n ---------------------------------------------------------------------------*)\n\nval _ = new_constant(GrammarSpecials.core_case_special,\n                     ``:'a -> ('a -> 'b) -> 'b``);\n\nval _ = new_constant(GrammarSpecials.case_split_special,\n                     ``:('a -> 'b) -> ('a -> 'b) -> 'a -> 'b``);\nval _ = new_constant(GrammarSpecials.case_arrow_special,\n                     ``:'a -> 'b -> 'a -> 'b``);\n\nval _ = let open GrammarSpecials\n        in app (fn s => remove_ovl_mapping s {Name=s,Thy=\"bool\"})\n               [case_split_special, case_arrow_special]\n        end\n\nval _ = add_rule{pp_elements = [HardSpace 1, TOK \"=>\", BreakSpace(1,2)],\n                 fixity = Infix(NONASSOC, 12),\n                 (* allowing for insertion of .| infix at looser precedence\n                    level *)\n                 block_style = (AroundEachPhrase, (PP.CONSISTENT, 0)),\n                 paren_style = OnlyIfNecessary,\n                 term_name = GrammarSpecials.case_arrow_special}\n\nval _ = add_rule{pp_elements = [PPBlock([TOK \"case\", BreakSpace(1,2),\n                                         TM, BreakSpace(1,2), TOK \"of\"],\n                                        (PP.CONSISTENT, 0)),\n                                BreakSpace(1,2)],\n                 fixity = Prefix 1,\n                 block_style = (AroundEachPhrase, (PP.CONSISTENT, 0)),\n                 paren_style = Always,\n                 term_name = GrammarSpecials.core_case_special};\n\nval _ = add_rule{pp_elements = [PPBlock([TOK \"case\", BreakSpace(1,2),\n                                         TM, BreakSpace(1,2), TOK \"of\"],\n                                        (PP.CONSISTENT, 0)),\n                                BreakSpace(1,2), TM, BreakSpace(1,0),\n                                TOK \"|\", HardSpace 1],\n                 fixity = Prefix 1,\n                 block_style = (AroundEachPhrase, (PP.CONSISTENT, 0)),\n                 paren_style = Always,\n                 term_name = GrammarSpecials.core_case_special};\n\nval _ = add_rule{pp_elements = [PPBlock([TOK \"case\", BreakSpace(1,2),\n                                         TM, BreakSpace(1,2), TOK \"of\"],\n                                        (PP.CONSISTENT, 0)),\n                                TOK \"|\", HardSpace 1],\n                 fixity = Prefix 1,\n                 block_style = (AroundEachPhrase, (PP.CONSISTENT, 0)),\n                 paren_style = Always,\n                 term_name = GrammarSpecials.core_case_special};\n\n\nval _ = add_rule{pp_elements = [PPBlock([TOK \"case\", BreakSpace(1,2),\n                                         TM, BreakSpace(1,2), TOK \"of\"],\n                                        (PP.CONSISTENT, 0)),\n                                BreakSpace(1,2), TM, BreakSpace(1,0),\n                                TOK \"|\", HardSpace 1, TM, BreakSpace(1,0),\n                                TOK \"|\", HardSpace 1],\n                 fixity = Prefix 1,\n                 block_style = (AroundEachPhrase, (PP.CONSISTENT, 0)),\n                 paren_style = Always,\n                 term_name = GrammarSpecials.core_case_special};\n\nval BOUNDED_THM = save_thm(\"BOUNDED_THM\",\n    let val v = ``v:bool``\n    in\n      GEN v (RIGHT_BETA(AP_THM BOUNDED_DEF v))\n    end);\n\n(*---------------------------------------------------------------------------*)\n(* LCOMM_THM : derive \"left-commutativity\" from associativity and            *)\n(* commutativity. Used in permutative rewriting, e.g., simpLib entrypoints   *)\n(*                                                                           *)\n(*  LCOMM_THM  |- !f. (!x y. f x y = f y x) ==>                              *)\n(*                    (!x y z. f x (f y z) = f (f x y) z) ==>                *)\n(*                    (!x y z. f x (f y z) = f y (f x z))                    *)\n(*---------------------------------------------------------------------------*)\n\nval LCOMM_THM = save_thm(\"LCOMM_THM\",\n let val x = mk_var(\"x\",alpha)\n     val y = mk_var(\"y\",alpha)\n     val z = mk_var(\"z\",alpha)\n     val f = mk_var(\"f\",alpha --> alpha --> alpha)\n     val comm = ``!x y. ^f x y = f y x``\n     val assoc = ``!x y z. ^f x (f y z) = f (f x y) z``\n     val comm_thm = ASSUME comm\n     val assoc_thm = ASSUME assoc\n     val th0 = SPEC (list_mk_comb(f,[y,z])) (SPEC x comm_thm)\n     val th1 = SYM (SPECL [y,z,x] assoc_thm)\n     val th2 = TRANS th0 th1\n     val th3 = AP_TERM (mk_comb(f,y)) (SPECL[z,x] comm_thm)\n in\n   GEN f (DISCH assoc (DISCH comm (GENL [x,y,z] (TRANS th2 th3))))\n end);\n\n\nval DATATYPE_TAG_THM = save_thm(\"DATATYPE_TAG_THM\",\n    let val x = mk_var(\"x\",alpha)\n    in GEN x (RIGHT_BETA (AP_THM DATATYPE_TAG_DEF x))\n    end);\n\n\nval DATATYPE_BOOL = save_thm(\"DATATYPE_BOOL\",\n let val thm1 = INST_TYPE [alpha |-> bool] DATATYPE_TAG_THM\n     val bvar = mk_var(\"bool\",bool--> bool-->bool)\n in\n    SPEC (list_mk_comb(bvar,[T,F])) thm1\n end);\n\n(* ----------------------------------------------------------------------\n    Set up the \"itself\" type constructor and its one value\n   ---------------------------------------------------------------------- *)\n\nval ITSELF_TYPE_DEF = let\n  val itself_exists = SPEC ``ARB:'a`` EXISTS_REFL\n  val eq_sym_eq' =\n      AP_TERM ``$? :('a -> bool) -> bool``\n              (ABS ``x:'a`` (SPECL [``x:'a``, ``ARB:'a``] EQ_SYM_EQ))\nin\n  new_type_definition(\"itself\", EQ_MP eq_sym_eq' itself_exists)\nend\nval _ = new_constant(\"the_value\", ``:'a itself``)\n\n(* prove uniqueness of the itself value:\n     |- !i:'a itself. i = (:'a)\n*)\nval ITSELF_UNIQUE = let\n  val typedef_asm = ASSUME (#2 (dest_exists (concl ITSELF_TYPE_DEF)))\n  val typedef_eq0 =\n      AP_THM (INST_TYPE [beta |-> ``:'a itself``] TYPE_DEFINITION)\n             ``$= (ARB:'a)``\n  val typedef_eq0 = RIGHT_BETA typedef_eq0\n  val typedef_eq = AP_THM typedef_eq0 ``rep:'a itself -> 'a``\n  val typedef_eq = RIGHT_BETA typedef_eq\n  val (typedef_11, typedef_onto) = CONJ_PAIR (EQ_MP typedef_eq typedef_asm)\n  val onto' = INST [``x:'a`` |-> ``(rep:'a itself -> 'a) i``]\n                   (#2 (EQ_IMP_RULE (SPEC_ALL typedef_onto)))\n  val allreps_arb = let\n    val ex' = EXISTS (``?x':'a itself. rep i = rep x':'a``, ``i:'a itself``)\n                     (REFL ``(rep:'a itself -> 'a) i``)\n  in\n    SYM (MP onto' ex')\n  end\n  val allreps_repthevalue =\n      TRANS allreps_arb\n            (SYM (INST [``i:'a itself`` |-> ``bool$the_value``] allreps_arb))\n  val all_eq_thevalue =\n      GEN_ALL (MP (SPECL [``i:'a itself``, ``bool$the_value``] typedef_11)\n                  allreps_repthevalue)\nin\n  save_thm(\"ITSELF_UNIQUE\",\n           CHOOSE (``rep:'a itself -> 'a``, ITSELF_TYPE_DEF) all_eq_thevalue)\nend\n\n(* prove a datatype axiom for the type, allowing definitions of the form\n    f (:'a) = ...\n*)\nval itself_Axiom = let\n  val witness = ``(\\x:'a itself. e : 'b)``\n  val fn_behaves = BETA_CONV  (mk_comb(witness, ``(:'a)``))\n  val fn_exists = EXISTS (``?f:'a itself -> 'b. f (:'a) = e``, witness)\n                  fn_behaves\nin\n  save_thm(\"itself_Axiom\", GEN_ALL fn_exists)\nend\n\n(* prove induction *)\nval itself_induction = let\n  val pval = ASSUME ``P (:'a) : bool``\n  val pi =\n      EQ_MP (SYM (AP_TERM ``P:'a itself -> bool`` (SPEC_ALL ITSELF_UNIQUE)))\n            pval\nin\n  save_thm(\"itself_induction\", GEN_ALL (DISCH_ALL (GEN_ALL pi)))\nend\n\n(* define case operator *)\nval itself_case_thm = let\n  val witness = ``\\(i:'a itself) (b:'b). b``\n  val witness_applied1 = BETA_CONV (mk_comb(witness, ``(:'a)``))\n  val witness_applied2 = RIGHT_BETA (AP_THM witness_applied1 ``b:'b``)\nin\n  new_specification(\"itself_case_thm\",\n                    [\"itself_case\"],\n                    EXISTS (``?f:'a itself -> 'b -> 'b. !b. f (:'a) b = b``,\n                            witness)\n                           (GEN_ALL witness_applied2))\nend\nval _ = overload_on(\"case\", ``itself_case``)\n\n(* FORALL_itself : |- (!x:'a itself. P x) <=> P (:'a)\n   EXISTS_itself : |- (?x:'a itself. P x) <=> P (:'a)\n*)\nlocal\n  val P = mk_var(\"P\", “:'a itself -> bool”)\n  val x = mk_var(\"x\", “:'a itself”)\n  val Px = mk_comb(P, x)\n  val APx = mk_forall(x, Px)\n  val itself = “(:'a)”\n  val Pitself = mk_comb(P, itself)\n  val imp1 = APx |> ASSUME |> SPEC itself |> DISCH_ALL\n  val unique = AP_TERM P (ITSELF_UNIQUE |> SPEC x |> SYM)\n  val imp2 = EQ_MP unique (ASSUME Pitself) |> GEN x |> DISCH_ALL\n  val fa = IMP_ANTISYM_RULE imp1 imp2\n  val not_not = NOT_CLAUSES |> CONJUNCT1 |> SPEC Px\n  (* exists half *)\n  val imp1 = CHOOSE (x, ASSUME (mk_exists(x,Px)))\n                    (EQ_MP (SYM unique) (ASSUME Px)) |> DISCH_ALL\n  val imp2 = EXISTS(mk_exists(x,Px),itself) (ASSUME Pitself) |> DISCH_ALL\nin\n  val FORALL_itself = save_thm(\"FORALL_itself\", fa)\n  val EXISTS_itself = save_thm(\"EXISTS_itself\", IMP_ANTISYM_RULE imp1 imp2)\nend;\n\n(*---------------------------------------------------------------------------*)\n(* Pulling FORALL and EXISTS up through /\\ and ==>                           *)\n(*---------------------------------------------------------------------------*)\n\nlocal\n  val flip = INST [Pb |-> Qb, Qab |-> Pab]\n  val PULL_EXISTS1 = LEFT_FORALL_IMP_THM |> SPEC_ALL |> SYM\n  val PULL_EXISTS2 = LEFT_EXISTS_AND_THM |> SPEC_ALL |> SYM\n  val PULL_EXISTS3 = RIGHT_EXISTS_AND_THM |> SPEC_ALL |> SYM |> flip\n  val PULL_FORALL1 = RIGHT_FORALL_IMP_THM |> SPEC_ALL |> SYM |> flip\n  val PULL_FORALL2 = LEFT_AND_FORALL_THM |> SPEC_ALL\n  val PULL_FORALL3 = RIGHT_AND_FORALL_THM |> SPEC_ALL |> flip\nin\n  val PULL_EXISTS = save_thm(\"PULL_EXISTS\",\n    LIST_CONJ [PULL_EXISTS1, PULL_EXISTS2, PULL_EXISTS3] |> GENL [Pab, Qb])\n  val PULL_FORALL = save_thm(\"PULL_FORALL\",\n    LIST_CONJ [PULL_FORALL1, PULL_FORALL2, PULL_FORALL3] |> GENL [Pab, Qb])\nend\n\n(*---------------------------------------------------------------------------*)\n(* PEIRCE  =  |- ((P ==> Q) ==> P) ==> P                                     *)\n(*---------------------------------------------------------------------------*)\n\nval PEIRCE = save_thm\n(\"PEIRCE\",\n let val th1 = ASSUME ``(P ==> Q) ==> P``\n     val th2 = ASSUME ``P:bool``\n     val th3 = ASSUME ``~P``\n     val th4 = MP th3 th2\n     val th5 = MP (SPEC ``Q:bool`` FALSITY) th4\n     val th6 = DISCH ``P:bool`` th5\n     val th7 = MP th1 th6\n     val th8 = MP th3 th7\n     val th9 = DISCH ``~P`` th8\n     val th10 = MP (SPEC ``~P`` IMP_F) th9\n     val th11 = SUBS [SPEC ``P:bool`` (CONJUNCT1 NOT_CLAUSES)] th10\n in\n   DISCH ``(P ==> Q) ==> P`` th11\n end);\n\n(* ----------------------------------------------------------------------\n    JRH_INDUCT_UTIL : !P t. (!x. (x = t) ==> P x) ==> $? P\n\n    Used multiple times in places relevant to inductive definitions and/or\n    algebraic types.\n   ---------------------------------------------------------------------- *)\n\nval JRH_INDUCT_UTIL = let\n  val asm_t = ``!x:'a. (x = t) ==> P x``\n  val asm = ASSUME asm_t\n  val t = ``t:'a``\n  val P = ``P : 'a -> bool``\n  val Pt = MP (SPEC t asm) (REFL t)\n  val ExPx = EXISTS (``?x:'a. P x``, t) Pt\n  val P_eta = SPEC P (INST_TYPE [beta |-> bool] ETA_AX)\n  val ExP_eta = AP_TERM ``(?) : ('a -> bool) -> bool`` P_eta\nin\n  save_thm(\"JRH_INDUCT_UTIL\", GENL [P, t] (DISCH asm_t (EQ_MP ExP_eta ExPx)))\nend\n(* Parsing additions *)\n\n(* not an element of *)\nval _ = overload_on (\"NOTIN\", ``\\x:'a y:('a -> bool). ~(x IN y)``)\nval _ = set_fixity \"NOTIN\" (Infix(NONASSOC, 425))\nval _ = unicode_version {u = UChar.not_elementof, tmnm = \"NOTIN\"}\nval _ = TeX_notation {hol=\"NOTIN\", TeX = (\"\\\\HOLTokenNotIn{}\",1)}\nval _ = TeX_notation {hol=UChar.not_elementof,\n                      TeX = (\"\\\\HOLTokenNotIn{}\",1)}\n\n(* not iff *)\nval _ = overload_on (\"<=/=>\", ``$<> : bool -> bool -> bool``)\nval _ = set_fixity \"<=/=>\" (Infix(NONASSOC, 100))\nval _ = unicode_version {u = UChar.not_iff, tmnm = \"<=/=>\"}\nval _ = TeX_notation {hol=\"<=/=>\", TeX = (\"\\\\HOLTokenNotEquiv{}\",3)}\nval _ = TeX_notation {hol=UChar.not_iff,\n                      TeX = (\"\\\\HOLTokenNotEquiv{}\",3)}\n\nlocal open boolpp in end\nval _ = add_ML_dependency \"boolpp\"\nval _ = add_user_printer (\"bool.COND\", ``COND gd tr fl``)\nval _ = add_user_printer (\"bool.LET\", ``LET f x``)\nval _ = add_absyn_postprocessor \"bool.LET\"\n\nval DISJ_EQ_IMP = save_thm(\"DISJ_EQ_IMP\",\n  let\n    val lemma = NOT_CLAUSES |> CONJUNCT1 |> SPEC ``A:bool``\n  in\n    IMP_DISJ_THM\n    |> SPECL [``~A:bool``,``B:bool``]\n    |> SYM\n    |> CONV_RULE\n      ((RATOR_CONV o RAND_CONV o RATOR_CONV o RAND_CONV)\n         (fn tm => lemma))\n    |> GENL [``A:bool``,``B:bool``]\n  end);\n\nval _ = export_theory()\nin end\n\\<close>\nML \\<open>Context_Var.reset_temp()\\<close>\nML \\<open>\nval _ = transfer_thms :=\n  SOME {ex_equiv = IsaHOLThmTransfer.exists_schematic,\n        bool_ex_Ex = IsaHOLThmTransfer.bool_ex_Ex,\n        bool_exI = bool_exI, \n        typedef_equiv = IsaHOLThmTransfer.type_definition_equiv}\n\\<close>\n\nML \\<open>Holmake build_heap (make_modules [\"boolTheory\"]) \"HOL/src/bool\"\\<close>\n\n\nsubsection \\<open>Different ML types (and therefore pretty printing (set up in \\<open>HOL4_Core_Isabelle\\<close>)) for Theorems\\<close>\nML \\<open>val Thm = Thm.Thm\\<close>\nML \\<open>val Thm' = Thm.Thm'\\<close>\nML \\<open>boolTheory.IMP_F_EQ_F\\<close>\nML \\<open>Thm' boolTheory.IMP_F_EQ_F\\<close>\nML \\<open>Thm (Thm' boolTheory.IMP_F_EQ_F)\\<close>\n\nend", "meta": {"author": "immler", "repo": "hol4isabelle", "sha": "e4c53d70ed1354b152bc3b65126a1b4a849288c9", "save_path": "github-repos/isabelle/immler-hol4isabelle", "path": "github-repos/isabelle/immler-hol4isabelle/hol4isabelle-e4c53d70ed1354b152bc3b65126a1b4a849288c9/Bool_Kernel_Isabelle.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.29034436174122547}}
{"text": "section \\<open>Operational Semantics\\<close>\n\ntheory RG_Tran\nimports RG_Com\nbegin\n\nsubsection \\<open>Semantics of Component Programs\\<close>\n\nsubsubsection \\<open>Environment transitions\\<close>\n\ntype_synonym 'a conf = \"(('a com) option) \\<times> 'a\"\n\ninductive_set\n  etran :: \"('a conf \\<times> 'a conf) set\" \n  and etran' :: \"'a conf \\<Rightarrow> 'a conf \\<Rightarrow> bool\"  (\"_ -e\\<rightarrow> _\" [81,81] 80)\nwhere\n  \"P -e\\<rightarrow> Q \\<equiv> (P,Q) \\<in> etran\"\n| Env: \"(P, s) -e\\<rightarrow> (P, t)\"\n\nlemma etranE: \"c -e\\<rightarrow> c' \\<Longrightarrow> (\\<And>P s t. c = (P, s) \\<Longrightarrow> c' = (P, t) \\<Longrightarrow> Q) \\<Longrightarrow> Q\"\n  by (induct c, induct c', erule etran.cases, blast)\n\nsubsubsection \\<open>Component transitions\\<close>\n\ninductive_set\n  ctran :: \"('a conf \\<times> 'a conf) set\"\n  and ctran' :: \"'a conf \\<Rightarrow> 'a conf \\<Rightarrow> bool\"   (\"_ -c\\<rightarrow> _\" [81,81] 80)\n  and ctrans :: \"'a conf \\<Rightarrow> 'a conf \\<Rightarrow> bool\"   (\"_ -c*\\<rightarrow> _\" [81,81] 80)\nwhere\n  \"P -c\\<rightarrow> Q \\<equiv> (P,Q) \\<in> ctran\"\n| \"P -c*\\<rightarrow> Q \\<equiv> (P,Q) \\<in> ctran^*\"\n\n| Basic:  \"(Some(Basic f), s) -c\\<rightarrow> (None, f s)\"\n\n| Seq1:   \"(Some P0, s) -c\\<rightarrow> (None, t) \\<Longrightarrow> (Some(Seq P0 P1), s) -c\\<rightarrow> (Some P1, t)\"\n\n| Seq2:   \"(Some P0, s) -c\\<rightarrow> (Some P2, t) \\<Longrightarrow> (Some(Seq P0 P1), s) -c\\<rightarrow> (Some(Seq P2 P1), t)\"\n\n| CondT: \"s\\<in>b  \\<Longrightarrow> (Some(Cond b P1 P2), s) -c\\<rightarrow> (Some P1, s)\"\n| CondF: \"s\\<notin>b \\<Longrightarrow> (Some(Cond b P1 P2), s) -c\\<rightarrow> (Some P2, s)\"\n\n| WhileF: \"s\\<notin>b \\<Longrightarrow> (Some(While b P), s) -c\\<rightarrow> (None, s)\"\n| WhileT: \"s\\<in>b  \\<Longrightarrow> (Some(While b P), s) -c\\<rightarrow> (Some(Seq P (While b P)), s)\"\n\n| Await:  \"\\<lbrakk>s\\<in>b; (Some P, s) -c*\\<rightarrow> (None, t)\\<rbrakk> \\<Longrightarrow> (Some(Await b P), s) -c\\<rightarrow> (None, t)\" \n\nmonos \"rtrancl_mono\"\n\nsubsection \\<open>Semantics of Parallel Programs\\<close>\n\ntype_synonym 'a par_conf = \"('a par_com) \\<times> 'a\"\n\ninductive_set\n  par_etran :: \"('a par_conf \\<times> 'a par_conf) set\"\n  and par_etran' :: \"['a par_conf,'a par_conf] \\<Rightarrow> bool\" (\"_ -pe\\<rightarrow> _\" [81,81] 80)\nwhere\n  \"P -pe\\<rightarrow> Q \\<equiv> (P,Q) \\<in> par_etran\"\n| ParEnv:  \"(Ps, s) -pe\\<rightarrow> (Ps, t)\"\n\ninductive_set\n  par_ctran :: \"('a par_conf \\<times> 'a par_conf) set\"\n  and par_ctran' :: \"['a par_conf,'a par_conf] \\<Rightarrow> bool\" (\"_ -pc\\<rightarrow> _\" [81,81] 80)\nwhere\n  \"P -pc\\<rightarrow> Q \\<equiv> (P,Q) \\<in> par_ctran\"\n| ParComp: \"\\<lbrakk>i<length Ps; (Ps!i, s) -c\\<rightarrow> (r, t)\\<rbrakk> \\<Longrightarrow> (Ps, s) -pc\\<rightarrow> (Ps[i:=r], t)\"\n\nlemma par_ctranE: \"c -pc\\<rightarrow> c' \\<Longrightarrow>\n  (\\<And>i Ps s r t. c = (Ps, s) \\<Longrightarrow> c' = (Ps[i := r], t) \\<Longrightarrow> i < length Ps \\<Longrightarrow>\n     (Ps ! i, s) -c\\<rightarrow> (r, t) \\<Longrightarrow> P) \\<Longrightarrow> P\"\n  by (induct c, induct c', erule par_ctran.cases, blast)\n\nsubsection \\<open>Computations\\<close>\n\nsubsubsection \\<open>Sequential computations\\<close>\n\ntype_synonym 'a confs = \"'a conf list\"\n\ninductive_set cptn :: \"'a confs set\"\nwhere\n  CptnOne: \"[(P,s)] \\<in> cptn\"\n| CptnEnv: \"(P, t)#xs \\<in> cptn \\<Longrightarrow> (P,s)#(P,t)#xs \\<in> cptn\"\n| CptnComp: \"\\<lbrakk>(P,s) -c\\<rightarrow> (Q,t); (Q, t)#xs \\<in> cptn \\<rbrakk> \\<Longrightarrow> (P,s)#(Q,t)#xs \\<in> cptn\"\n\ndefinition cp :: \"('a com) option \\<Rightarrow> 'a \\<Rightarrow> ('a confs) set\" where\n  \"cp P s \\<equiv> {l. l!0=(P,s) \\<and> l \\<in> cptn}\"  \n\nsubsubsection \\<open>Parallel computations\\<close>\n\ntype_synonym 'a par_confs = \"'a par_conf list\"\n\ninductive_set par_cptn :: \"'a par_confs set\"\nwhere\n  ParCptnOne: \"[(P,s)] \\<in> par_cptn\"\n| ParCptnEnv: \"(P,t)#xs \\<in> par_cptn \\<Longrightarrow> (P,s)#(P,t)#xs \\<in> par_cptn\"\n| ParCptnComp: \"\\<lbrakk> (P,s) -pc\\<rightarrow> (Q,t); (Q,t)#xs \\<in> par_cptn \\<rbrakk> \\<Longrightarrow> (P,s)#(Q,t)#xs \\<in> par_cptn\"\n\ndefinition par_cp :: \"'a par_com \\<Rightarrow> 'a \\<Rightarrow> ('a par_confs) set\" where\n  \"par_cp P s \\<equiv> {l. l!0=(P,s) \\<and> l \\<in> par_cptn}\"  \n\nsubsection\\<open>Modular Definition of Computation\\<close>\n\ndefinition lift :: \"'a com \\<Rightarrow> 'a conf \\<Rightarrow> 'a conf\" where\n  \"lift Q \\<equiv> \\<lambda>(P, s). (if P=None then (Some Q,s) else (Some(Seq (the P) Q), s))\"\n\ninductive_set cptn_mod :: \"('a confs) set\"\nwhere\n  CptnModOne: \"[(P, s)] \\<in> cptn_mod\"\n| CptnModEnv: \"(P, t)#xs \\<in> cptn_mod \\<Longrightarrow> (P, s)#(P, t)#xs \\<in> cptn_mod\"\n| CptnModNone: \"\\<lbrakk>(Some P, s) -c\\<rightarrow> (None, t); (None, t)#xs \\<in> cptn_mod \\<rbrakk> \\<Longrightarrow> (Some P,s)#(None, t)#xs \\<in>cptn_mod\"\n| CptnModCondT: \"\\<lbrakk>(Some P0, s)#ys \\<in> cptn_mod; s \\<in> b \\<rbrakk> \\<Longrightarrow> (Some(Cond b P0 P1), s)#(Some P0, s)#ys \\<in> cptn_mod\"\n| CptnModCondF: \"\\<lbrakk>(Some P1, s)#ys \\<in> cptn_mod; s \\<notin> b \\<rbrakk> \\<Longrightarrow> (Some(Cond b P0 P1), s)#(Some P1, s)#ys \\<in> cptn_mod\"\n| CptnModSeq1: \"\\<lbrakk>(Some P0, s)#xs \\<in> cptn_mod; zs=map (lift P1) xs \\<rbrakk>\n                 \\<Longrightarrow> (Some(Seq P0 P1), s)#zs \\<in> cptn_mod\"\n| CptnModSeq2: \n  \"\\<lbrakk>(Some P0, s)#xs \\<in> cptn_mod; fst(last ((Some P0, s)#xs)) = None; \n  (Some P1, snd(last ((Some P0, s)#xs)))#ys \\<in> cptn_mod; \n  zs=(map (lift P1) xs)@ys \\<rbrakk> \\<Longrightarrow> (Some(Seq P0 P1), s)#zs \\<in> cptn_mod\"\n\n| CptnModWhile1: \n  \"\\<lbrakk> (Some P, s)#xs \\<in> cptn_mod; s \\<in> b; zs=map (lift (While b P)) xs \\<rbrakk> \n  \\<Longrightarrow> (Some(While b P), s)#(Some(Seq P (While b P)), s)#zs \\<in> cptn_mod\"\n| CptnModWhile2: \n  \"\\<lbrakk> (Some P, s)#xs \\<in> cptn_mod; fst(last ((Some P, s)#xs))=None; s \\<in> b; \n  zs=(map (lift (While b P)) xs)@ys; \n  (Some(While b P), snd(last ((Some P, s)#xs)))#ys \\<in> cptn_mod\\<rbrakk> \n  \\<Longrightarrow> (Some(While b P), s)#(Some(Seq P (While b P)), s)#zs \\<in> cptn_mod\"\n\nsubsection \\<open>Equivalence of Both Definitions.\\<close>\n\nlemma last_length: \"((a#xs)!(length xs))=last (a#xs)\"\n  by (induct xs) auto\n\nlemma div_seq [rule_format]: \"list \\<in> cptn_mod \\<Longrightarrow>\n (\\<forall>s P Q zs. list=(Some (Seq P Q), s)#zs \\<longrightarrow>\n  (\\<exists>xs. (Some P, s)#xs \\<in> cptn_mod  \\<and> (zs=(map (lift Q) xs) \\<or>\n  ( fst(((Some P, s)#xs)!length xs)=None \\<and> \n  (\\<exists>ys. (Some Q, snd(((Some P, s)#xs)!length xs))#ys \\<in> cptn_mod  \n  \\<and> zs=(map (lift (Q)) xs)@ys)))))\"\napply(erule cptn_mod.induct)\napply simp_all\n    apply clarify\n    apply(force intro:CptnModOne)\n   apply clarify\n   apply(erule_tac x=Pa in allE)\n   apply(erule_tac x=Q in allE)\n   apply simp\n   apply clarify\n   apply(erule disjE)\n    apply(rule_tac x=\"(Some Pa,t)#xsa\" in exI)\n    apply(rule conjI)\n     apply clarify\n     apply(erule CptnModEnv)\n    apply(rule disjI1)\n    apply(simp add:lift_def)\n   apply clarify\n   apply(rule_tac x=\"(Some Pa,t)#xsa\" in exI)\n   apply(rule conjI)\n    apply(erule CptnModEnv)\n   apply(rule disjI2)\n   apply(rule conjI)\n    apply(case_tac xsa,simp,simp)\n   apply(rule_tac x=\"ys\" in exI)\n   apply(rule conjI)\n    apply simp\n   apply(simp add:lift_def)\n  apply clarify\n  apply(erule ctran.cases,simp_all)\n apply clarify\n apply(rule_tac x=\"xs\" in exI)\n apply simp\n apply clarify\napply(rule_tac x=\"xs\" in exI)\napply(simp add: last_length)\ndone\n\nlemma cptn_onlyif_cptn_mod_aux [rule_format]:\n  \"\\<forall>s Q t xs.((Some a, s), Q, t) \\<in> ctran \\<longrightarrow> (Q, t) # xs \\<in> cptn_mod \n  \\<longrightarrow> (Some a, s) # (Q, t) # xs \\<in> cptn_mod\"\napply(induct a)\napply simp_all\n\\<comment>\\<open>basic\\<close>\napply clarify\napply(erule ctran.cases,simp_all)\napply(rule CptnModNone,rule Basic,simp)\napply clarify\napply(erule ctran.cases,simp_all)\n\\<comment>\\<open>Seq1\\<close>\napply(rule_tac xs=\"[(None,ta)]\" in CptnModSeq2)\n  apply(erule CptnModNone)\n  apply(rule CptnModOne)\n apply simp\napply simp\napply(simp add:lift_def)\n\\<comment>\\<open>Seq2\\<close>\napply(erule_tac x=sa in allE)\napply(erule_tac x=\"Some P2\" in allE)\napply(erule allE,erule impE, assumption)\napply(drule div_seq,simp)\napply clarify\napply(erule disjE)\n apply clarify\n apply(erule allE,erule impE, assumption)\n apply(erule_tac CptnModSeq1)\n apply(simp add:lift_def)\napply clarify \napply(erule allE,erule impE, assumption)\napply(erule_tac CptnModSeq2)\n  apply (simp add:last_length)\n apply (simp add:last_length)\napply(simp add:lift_def)\n\\<comment>\\<open>Cond\\<close>\napply clarify\napply(erule ctran.cases,simp_all)\napply(force elim: CptnModCondT)\napply(force elim: CptnModCondF)\n\\<comment>\\<open>While\\<close>\napply  clarify\napply(erule ctran.cases,simp_all)\napply(rule CptnModNone,erule WhileF,simp)\napply(drule div_seq,force)\napply clarify\napply (erule disjE)\n apply(force elim:CptnModWhile1)\napply clarify\napply(force simp add:last_length elim:CptnModWhile2)\n\\<comment>\\<open>await\\<close>\napply clarify\napply(erule ctran.cases,simp_all)\napply(rule CptnModNone,erule Await,simp+)\ndone\n\nlemma cptn_onlyif_cptn_mod [rule_format]: \"c \\<in> cptn \\<Longrightarrow> c \\<in> cptn_mod\"\napply(erule cptn.induct)\n  apply(rule CptnModOne)\n apply(erule CptnModEnv)\napply(case_tac P)\n apply simp\n apply(erule ctran.cases,simp_all)\napply(force elim:cptn_onlyif_cptn_mod_aux)\ndone\n\nlemma lift_is_cptn: \"c\\<in>cptn \\<Longrightarrow> map (lift P) c \\<in> cptn\"\napply(erule cptn.induct)\n  apply(force simp add:lift_def CptnOne)\n apply(force intro:CptnEnv simp add:lift_def)\napply(force simp add:lift_def intro:CptnComp Seq2 Seq1 elim:ctran.cases)\ndone\n\nlemma cptn_append_is_cptn [rule_format]: \n \"\\<forall>b a. b#c1\\<in>cptn \\<longrightarrow>  a#c2\\<in>cptn \\<longrightarrow> (b#c1)!length c1=a \\<longrightarrow> b#c1@c2\\<in>cptn\"\napply(induct c1)\n apply simp\napply clarify\napply(erule cptn.cases,simp_all)\n apply(force intro:CptnEnv)\napply(force elim:CptnComp)\ndone\n\nlemma last_lift: \"\\<lbrakk>xs\\<noteq>[]; fst(xs!(length xs - (Suc 0)))=None\\<rbrakk> \n \\<Longrightarrow> fst((map (lift P) xs)!(length (map (lift P) xs)- (Suc 0)))=(Some P)\"\n  by (cases \"(xs ! (length xs - (Suc 0)))\") (simp add:lift_def)\n\nlemma last_fst [rule_format]: \"P((a#x)!length x) \\<longrightarrow> \\<not>P a \\<longrightarrow> P (x!(length x - (Suc 0)))\" \n  by (induct x) simp_all\n\nlemma last_fst_esp: \n \"fst(((Some a,s)#xs)!(length xs))=None \\<Longrightarrow> fst(xs!(length xs - (Suc 0)))=None\" \napply(erule last_fst)\napply simp\ndone\n\nlemma last_snd: \"xs\\<noteq>[] \\<Longrightarrow> \n  snd(((map (lift P) xs))!(length (map (lift P) xs) - (Suc 0)))=snd(xs!(length xs - (Suc 0)))\"\n  by (cases \"(xs ! (length xs - (Suc 0)))\") (simp_all add:lift_def)\n\nlemma Cons_lift: \"(Some (Seq P Q), s) # (map (lift Q) xs) = map (lift Q) ((Some P, s) # xs)\"\n  by (simp add:lift_def)\n\nlemma Cons_lift_append: \n  \"(Some (Seq P Q), s) # (map (lift Q) xs) @ ys = map (lift Q) ((Some P, s) # xs)@ ys \"\n  by (simp add:lift_def)\n\nlemma lift_nth: \"i<length xs \\<Longrightarrow> map (lift Q) xs ! i = lift Q  (xs! i)\"\n  by (simp add:lift_def)\n\nlemma snd_lift: \"i< length xs \\<Longrightarrow> snd(lift Q (xs ! i))= snd (xs ! i)\"\n  by (cases \"xs!i\") (simp add:lift_def)\n\nlemma cptn_if_cptn_mod: \"c \\<in> cptn_mod \\<Longrightarrow> c \\<in> cptn\"\napply(erule cptn_mod.induct)\n        apply(rule CptnOne)\n       apply(erule CptnEnv)\n      apply(erule CptnComp,simp)\n     apply(rule CptnComp)\n      apply(erule CondT,simp)\n    apply(rule CptnComp)\n     apply(erule CondF,simp)\n\\<comment>\\<open>Seq1\\<close>\napply(erule cptn.cases,simp_all)\n  apply(rule CptnOne)\n apply clarify\n apply(drule_tac P=P1 in lift_is_cptn)\n apply(simp add:lift_def)\n apply(rule CptnEnv,simp)\napply clarify\napply(simp add:lift_def)\napply(rule conjI)\n apply clarify\n apply(rule CptnComp)\n  apply(rule Seq1,simp)\n apply(drule_tac P=P1 in lift_is_cptn)\n apply(simp add:lift_def)\napply clarify\napply(rule CptnComp)\n apply(rule Seq2,simp)\napply(drule_tac P=P1 in lift_is_cptn)\napply(simp add:lift_def)\n\\<comment>\\<open>Seq2\\<close>\napply(rule cptn_append_is_cptn)\n  apply(drule_tac P=P1 in lift_is_cptn)\n  apply(simp add:lift_def)\n apply simp\napply(simp split: if_split_asm)\napply(frule_tac P=P1 in last_lift)\n apply(rule last_fst_esp)\n apply (simp add:last_length)\napply(simp add:Cons_lift lift_def split_def last_conv_nth)\n\\<comment>\\<open>While1\\<close>\napply(rule CptnComp)\n apply(rule WhileT,simp)\napply(drule_tac P=\"While b P\" in lift_is_cptn)\napply(simp add:lift_def)\n\\<comment>\\<open>While2\\<close>\napply(rule CptnComp)\n apply(rule WhileT,simp)\napply(rule cptn_append_is_cptn)\n  apply(drule_tac P=\"While b P\" in lift_is_cptn)\n  apply(simp add:lift_def)\n apply simp\napply(simp split: if_split_asm)\napply(frule_tac P=\"While b P\" in last_lift)\n apply(rule last_fst_esp,simp add:last_length)\napply(simp add:Cons_lift lift_def split_def last_conv_nth)\ndone\n\ntheorem cptn_iff_cptn_mod: \"(c \\<in> cptn) = (c \\<in> cptn_mod)\"\napply(rule iffI)\n apply(erule cptn_onlyif_cptn_mod)\napply(erule cptn_if_cptn_mod)\ndone\n\nsection \\<open>Validity  of Correctness Formulas\\<close>\n\nsubsection \\<open>Validity for Component Programs.\\<close>\n\ntype_synonym 'a rgformula =\n  \"'a com \\<times> 'a set \\<times> ('a \\<times> 'a) set \\<times> ('a \\<times> 'a) set \\<times> 'a set\"\n\ndefinition assum :: \"('a set \\<times> ('a \\<times> 'a) set) \\<Rightarrow> ('a confs) set\" where\n  \"assum \\<equiv> \\<lambda>(pre, rely). {c. snd(c!0) \\<in> pre \\<and> (\\<forall>i. Suc i<length c \\<longrightarrow> \n               c!i -e\\<rightarrow> c!(Suc i) \\<longrightarrow> (snd(c!i), snd(c!Suc i)) \\<in> rely)}\"\n\ndefinition comm :: \"(('a \\<times> 'a) set \\<times> 'a set) \\<Rightarrow> ('a confs) set\" where\n  \"comm \\<equiv> \\<lambda>(guar, post). {c. (\\<forall>i. Suc i<length c \\<longrightarrow> \n               c!i -c\\<rightarrow> c!(Suc i) \\<longrightarrow> (snd(c!i), snd(c!Suc i)) \\<in> guar) \\<and> \n               (fst (last c) = None \\<longrightarrow> snd (last c) \\<in> post)}\"\n\ndefinition com_validity :: \"'a com \\<Rightarrow> 'a set \\<Rightarrow> ('a \\<times> 'a) set \\<Rightarrow> ('a \\<times> 'a) set \\<Rightarrow> 'a set \\<Rightarrow> bool\" \n                 (\"\\<Turnstile> _ sat [_, _, _, _]\" [60,0,0,0,0] 45) where\n  \"\\<Turnstile> P sat [pre, rely, guar, post] \\<equiv> \n   \\<forall>s. cp (Some P) s \\<inter> assum(pre, rely) \\<subseteq> comm(guar, post)\"\n\nsubsection \\<open>Validity for Parallel Programs.\\<close>\n\ndefinition All_None :: \"(('a com) option) list \\<Rightarrow> bool\" where\n  \"All_None xs \\<equiv> \\<forall>c\\<in>set xs. c=None\"\n\ndefinition par_assum :: \"('a set \\<times> ('a \\<times> 'a) set) \\<Rightarrow> ('a par_confs) set\" where\n  \"par_assum \\<equiv> \\<lambda>(pre, rely). {c. snd(c!0) \\<in> pre \\<and> (\\<forall>i. Suc i<length c \\<longrightarrow> \n             c!i -pe\\<rightarrow> c!Suc i \\<longrightarrow> (snd(c!i), snd(c!Suc i)) \\<in> rely)}\"\n\ndefinition par_comm :: \"(('a \\<times> 'a) set \\<times> 'a set) \\<Rightarrow> ('a par_confs) set\" where\n  \"par_comm \\<equiv> \\<lambda>(guar, post). {c. (\\<forall>i. Suc i<length c \\<longrightarrow>   \n        c!i -pc\\<rightarrow> c!Suc i \\<longrightarrow> (snd(c!i), snd(c!Suc i)) \\<in> guar) \\<and> \n         (All_None (fst (last c)) \\<longrightarrow> snd( last c) \\<in> post)}\"\n\ndefinition par_com_validity :: \"'a  par_com \\<Rightarrow> 'a set \\<Rightarrow> ('a \\<times> 'a) set \\<Rightarrow> ('a \\<times> 'a) set \n\\<Rightarrow> 'a set \\<Rightarrow> bool\"  (\"\\<Turnstile> _ SAT [_, _, _, _]\" [60,0,0,0,0] 45) where\n  \"\\<Turnstile> Ps SAT [pre, rely, guar, post] \\<equiv> \n   \\<forall>s. par_cp Ps s \\<inter> par_assum(pre, rely) \\<subseteq> par_comm(guar, post)\"\n\nsubsection \\<open>Compositionality of the Semantics\\<close>\n\nsubsubsection \\<open>Definition of the conjoin operator\\<close>\n\ndefinition same_length :: \"'a par_confs \\<Rightarrow> ('a confs) list \\<Rightarrow> bool\" where\n  \"same_length c clist \\<equiv> (\\<forall>i<length clist. length(clist!i)=length c)\"\n \ndefinition same_state :: \"'a par_confs \\<Rightarrow> ('a confs) list \\<Rightarrow> bool\" where\n  \"same_state c clist \\<equiv> (\\<forall>i <length clist. \\<forall>j<length c. snd(c!j) = snd((clist!i)!j))\"\n\ndefinition same_program :: \"'a par_confs \\<Rightarrow> ('a confs) list \\<Rightarrow> bool\" where\n  \"same_program c clist \\<equiv> (\\<forall>j<length c. fst(c!j) = map (\\<lambda>x. fst(nth x j)) clist)\"\n\ndefinition compat_label :: \"'a par_confs \\<Rightarrow> ('a confs) list \\<Rightarrow> bool\" where\n  \"compat_label c clist \\<equiv> (\\<forall>j. Suc j<length c \\<longrightarrow> \n         (c!j -pc\\<rightarrow> c!Suc j \\<and> (\\<exists>i<length clist. (clist!i)!j -c\\<rightarrow> (clist!i)! Suc j \\<and> \n                       (\\<forall>l<length clist. l\\<noteq>i \\<longrightarrow> (clist!l)!j -e\\<rightarrow> (clist!l)! Suc j))) \\<or> \n         (c!j -pe\\<rightarrow> c!Suc j \\<and> (\\<forall>i<length clist. (clist!i)!j -e\\<rightarrow> (clist!i)! Suc j)))\"\n\ndefinition conjoin :: \"'a par_confs \\<Rightarrow> ('a confs) list \\<Rightarrow> bool\"  (\"_ \\<propto> _\" [65,65] 64) where\n  \"c \\<propto> clist \\<equiv> (same_length c clist) \\<and> (same_state c clist) \\<and> (same_program c clist) \\<and> (compat_label c clist)\"\n\nsubsubsection \\<open>Some previous lemmas\\<close>\n\nlemma list_eq_if [rule_format]: \n  \"\\<forall>ys. xs=ys \\<longrightarrow> (length xs = length ys) \\<longrightarrow> (\\<forall>i<length xs. xs!i=ys!i)\"\n  by (induct xs) auto\n\nlemma list_eq: \"(length xs = length ys \\<and> (\\<forall>i<length xs. xs!i=ys!i)) = (xs=ys)\"\napply(rule iffI)\n apply clarify\n apply(erule nth_equalityI)\n apply simp+\ndone\n\nlemma nth_tl: \"\\<lbrakk> ys!0=a; ys\\<noteq>[] \\<rbrakk> \\<Longrightarrow> ys=(a#(tl ys))\"\n  by (cases ys) simp_all\n\nlemma nth_tl_if [rule_format]: \"ys\\<noteq>[] \\<longrightarrow> ys!0=a \\<longrightarrow> P ys \\<longrightarrow> P (a#(tl ys))\"\n  by (induct ys) simp_all\n\nlemma nth_tl_onlyif [rule_format]: \"ys\\<noteq>[] \\<longrightarrow> ys!0=a \\<longrightarrow> P (a#(tl ys)) \\<longrightarrow> P ys\"\n  by (induct ys) simp_all\n\nlemma seq_not_eq1: \"Seq c1 c2\\<noteq>c1\"\n  by (induct c1) auto\n\nlemma seq_not_eq2: \"Seq c1 c2\\<noteq>c2\"\n  by (induct c2) auto\n\nlemma if_not_eq1: \"Cond b c1 c2 \\<noteq>c1\"\n  by (induct c1) auto\n\nlemma if_not_eq2: \"Cond b c1 c2\\<noteq>c2\"\n  by (induct c2) auto\n\nlemmas seq_and_if_not_eq [simp] = seq_not_eq1 seq_not_eq2 \nseq_not_eq1 [THEN not_sym] seq_not_eq2 [THEN not_sym] \nif_not_eq1 if_not_eq2 if_not_eq1 [THEN not_sym] if_not_eq2 [THEN not_sym]\n\nlemma prog_not_eq_in_ctran_aux:\n  assumes c: \"(P,s) -c\\<rightarrow> (Q,t)\"\n  shows \"P\\<noteq>Q\" using c\n  by (induct x1 \\<equiv> \"(P,s)\" x2 \\<equiv> \"(Q,t)\" arbitrary: P s Q t) auto\n\nlemma prog_not_eq_in_ctran [simp]: \"\\<not> (P,s) -c\\<rightarrow> (P,t)\"\napply clarify\napply(drule prog_not_eq_in_ctran_aux)\napply simp\ndone\n\nlemma prog_not_eq_in_par_ctran_aux [rule_format]: \"(P,s) -pc\\<rightarrow> (Q,t) \\<Longrightarrow> (P\\<noteq>Q)\"\napply(erule par_ctran.induct)\napply(drule prog_not_eq_in_ctran_aux)\napply clarify\napply(drule list_eq_if)\n apply simp_all\napply force\ndone\n\nlemma prog_not_eq_in_par_ctran [simp]: \"\\<not> (P,s) -pc\\<rightarrow> (P,t)\"\napply clarify\napply(drule prog_not_eq_in_par_ctran_aux)\napply simp\ndone\n\nlemma tl_in_cptn: \"\\<lbrakk> a#xs \\<in>cptn; xs\\<noteq>[] \\<rbrakk> \\<Longrightarrow> xs\\<in>cptn\"\n  by (force elim: cptn.cases)\n\nlemma tl_zero[rule_format]: \n  \"P (ys!Suc j) \\<longrightarrow> Suc j<length ys \\<longrightarrow> ys\\<noteq>[] \\<longrightarrow> P (tl(ys)!j)\"\n  by (induct ys) simp_all\n\nsubsection \\<open>The Semantics is Compositional\\<close>\n\nlemma aux_if [rule_format]: \n  \"\\<forall>xs s clist. (length clist = length xs \\<and> (\\<forall>i<length xs. (xs!i,s)#clist!i \\<in> cptn) \n  \\<and> ((xs, s)#ys \\<propto> map (\\<lambda>i. (fst i,s)#snd i) (zip xs clist)) \n   \\<longrightarrow> (xs, s)#ys \\<in> par_cptn)\"\napply(induct ys)\n apply(clarify)\n apply(rule ParCptnOne)\napply(clarify)\napply(simp add:conjoin_def compat_label_def)\napply clarify\napply(erule_tac x=\"0\" and P=\"\\<lambda>j. H j \\<longrightarrow> (P j \\<or> Q j)\" for H P Q in all_dupE, simp)\napply(erule disjE)\n\\<comment>\\<open>first step is a Component step\\<close>\n apply clarify \n apply simp\n apply(subgoal_tac \"a=(xs[i:=(fst(clist!i!0))])\")\n  apply(subgoal_tac \"b=snd(clist!i!0)\",simp)\n   prefer 2\n   apply(simp add: same_state_def)\n   apply(erule_tac x=i in allE,erule impE,assumption, \n         erule_tac x=1 and P=\"\\<lambda>j. (H j) \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE, simp)\n  prefer 2\n  apply(simp add:same_program_def)\n  apply(erule_tac x=1 and P=\"\\<lambda>j. H j \\<longrightarrow> (fst (s j))=(t j)\" for H s t in allE,simp)\n  apply(rule nth_equalityI,simp)\n  apply clarify\n  apply(case_tac \"i=ia\",simp,simp)\n  apply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE)\n  apply(drule_tac t=i in not_sym,simp)\n  apply(erule etranE,simp)\n apply(rule ParCptnComp)\n  apply(erule ParComp,simp)\n\\<comment>\\<open>applying the induction hypothesis\\<close>\n apply(erule_tac x=\"xs[i := fst (clist ! i ! 0)]\" in allE)\n apply(erule_tac x=\"snd (clist ! i ! 0)\" in allE)\n apply(erule mp)\n apply(rule_tac x=\"map tl clist\" in exI,simp)\n apply(rule conjI,clarify)\n  apply(case_tac \"i=ia\",simp)\n   apply(rule nth_tl_if)\n     apply(force simp add:same_length_def length_Suc_conv)\n    apply simp\n   apply(erule allE,erule impE,assumption,erule tl_in_cptn)\n   apply(force simp add:same_length_def length_Suc_conv)\n  apply(rule nth_tl_if)\n    apply(force simp add:same_length_def length_Suc_conv)\n   apply(simp add:same_state_def)\n   apply(erule_tac x=ia in allE, erule impE, assumption, \n     erule_tac x=1 and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE)\n   apply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE)\n   apply(drule_tac t=i  in not_sym,simp)\n   apply(erule etranE,simp)\n  apply(erule allE,erule impE,assumption,erule tl_in_cptn)\n  apply(force simp add:same_length_def length_Suc_conv)\n apply(simp add:same_length_def same_state_def)\n apply(rule conjI)\n  apply clarify\n  apply(case_tac j,simp,simp)\n  apply(erule_tac x=ia in allE, erule impE, assumption,\n        erule_tac x=\"Suc(Suc nat)\" and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE,simp)\n  apply(force simp add:same_length_def length_Suc_conv)\n apply(rule conjI)\n  apply(simp add:same_program_def)\n  apply clarify\n  apply(case_tac j,simp)\n   apply(rule nth_equalityI,simp)\n   apply clarify\n   apply(case_tac \"i=ia\",simp,simp)\n  apply(erule_tac x=\"Suc(Suc nat)\" and P=\"\\<lambda>j. H j \\<longrightarrow> (fst (s j))=(t j)\" for H s t in allE,simp)\n  apply(rule nth_equalityI,simp,simp)\n  apply(force simp add:length_Suc_conv)\n apply(rule allI,rule impI)\n apply(erule_tac x=\"Suc j\" and P=\"\\<lambda>j. H j \\<longrightarrow> (I j \\<or> J j)\" for H I J in allE,simp)\n apply(erule disjE) \n  apply clarify\n  apply(rule_tac x=ia in exI,simp)\n  apply(case_tac \"i=ia\",simp)\n   apply(rule conjI)\n    apply(force simp add: length_Suc_conv)\n   apply clarify\n   apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE,erule impE,assumption)\n   apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE,erule impE,assumption)\n   apply simp\n   apply(case_tac j,simp)\n    apply(rule tl_zero)\n      apply(erule_tac x=l in allE, erule impE, assumption, \n            erule_tac x=1 and P=\"\\<lambda>j.  (H j) \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE,simp)\n      apply(force elim:etranE intro:Env)\n     apply force\n    apply force\n   apply simp\n   apply(rule tl_zero)\n     apply(erule tl_zero)\n      apply force\n     apply force\n    apply force\n   apply force\n  apply(rule conjI,simp)\n   apply(rule nth_tl_if)\n     apply force\n    apply(erule_tac x=ia  in allE, erule impE, assumption,\n          erule_tac x=1 and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE)\n    apply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE)\n    apply(drule_tac t=i  in not_sym,simp)\n    apply(erule etranE,simp)\n   apply(erule tl_zero)\n    apply force\n   apply force\n  apply clarify\n  apply(case_tac \"i=l\",simp)\n   apply(rule nth_tl_if)\n     apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n    apply simp\n   apply(erule_tac P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE,erule impE,assumption,erule impE,assumption)\n   apply(erule tl_zero,force)\n   apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n   apply(rule nth_tl_if)\n     apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n    apply(erule_tac x=l  in allE, erule impE, assumption,\n          erule_tac x=1 and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE)\n    apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE,erule impE, assumption,simp)\n    apply(erule etranE,simp)\n   apply(rule tl_zero)\n    apply force\n   apply force\n  apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n apply(rule disjI2)\n apply(case_tac j,simp)\n  apply clarify\n  apply(rule tl_zero)\n    apply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> I j\\<in>etran\" for H I in allE,erule impE, assumption)\n    apply(case_tac \"i=ia\",simp,simp)\n    apply(erule_tac x=ia  in allE, erule impE, assumption,\n    erule_tac x=1 and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE)\n    apply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE,erule impE, assumption,simp)\n    apply(force elim:etranE intro:Env)\n   apply force\n  apply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n apply simp\n apply clarify\n apply(rule tl_zero)\n   apply(rule tl_zero,force)\n    apply force\n   apply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n  apply force\n apply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n\\<comment>\\<open>first step is an environmental step\\<close>\napply clarify\napply(erule par_etran.cases)\napply simp\napply(rule ParCptnEnv)\napply(erule_tac x=\"Ps\" in allE)\napply(erule_tac x=\"t\" in allE)\napply(erule mp)\napply(rule_tac x=\"map tl clist\" in exI,simp)\napply(rule conjI)\n apply clarify\n apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<in> cptn\" for H I in allE,simp)\n apply(erule cptn.cases)\n   apply(simp add:same_length_def)\n   apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n  apply(simp add:same_state_def)\n  apply(erule_tac x=i  in allE, erule impE, assumption,\n   erule_tac x=1 and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE,simp)\n apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> J j \\<in>etran\" for H J in allE,simp)\n apply(erule etranE,simp)\napply(simp add:same_state_def same_length_def)\napply(rule conjI,clarify)\n apply(case_tac j,simp,simp)\n apply(erule_tac x=i  in allE, erule impE, assumption,\n       erule_tac x=\"Suc(Suc nat)\" and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE,simp)\n apply(rule tl_zero)\n   apply(simp)\n  apply force\n apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\napply(rule conjI)\n apply(simp add:same_program_def)\n apply clarify\n apply(case_tac j,simp)\n  apply(rule nth_equalityI,simp)\n  apply clarify\n  apply simp\n apply(erule_tac x=\"Suc(Suc nat)\" and P=\"\\<lambda>j. H j \\<longrightarrow> (fst (s j))=(t j)\" for H s t in allE,simp)\n apply(rule nth_equalityI,simp,simp)\n apply(force simp add:length_Suc_conv)\napply(rule allI,rule impI)\napply(erule_tac x=\"Suc j\" and P=\"\\<lambda>j. H j \\<longrightarrow> (I j \\<or> J j)\" for H I J in allE,simp)\napply(erule disjE) \n apply clarify\n apply(rule_tac x=i in exI,simp)\n apply(rule conjI)\n  apply(erule_tac x=i and P=\"\\<lambda>i. H i \\<longrightarrow> J i \\<in>etran\" for H J in allE, erule impE, assumption)\n  apply(erule etranE,simp)\n  apply(erule_tac x=i  in allE, erule impE, assumption,\n        erule_tac x=1 and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE,simp)\n  apply(rule nth_tl_if)\n   apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n  apply simp\n apply(erule tl_zero,force) \n  apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n apply clarify\n apply(erule_tac x=l and P=\"\\<lambda>i. H i \\<longrightarrow> J i \\<in>etran\" for H J in allE, erule impE, assumption)\n apply(erule etranE,simp)\n apply(erule_tac x=l  in allE, erule impE, assumption,\n       erule_tac x=1 and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE,simp)\n apply(rule nth_tl_if)\n   apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n  apply simp\n  apply(rule tl_zero,force)\n  apply force\n apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\napply(rule disjI2)\napply simp\napply clarify\napply(case_tac j,simp)\n apply(rule tl_zero)\n   apply(erule_tac x=i and P=\"\\<lambda>i. H i \\<longrightarrow> J i \\<in>etran\" for H J in allE, erule impE, assumption)\n   apply(erule_tac x=i and P=\"\\<lambda>i. H i \\<longrightarrow> J i \\<in>etran\" for H J in allE, erule impE, assumption)\n   apply(force elim:etranE intro:Env)\n  apply force\n apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\napply simp\napply(rule tl_zero)\n  apply(rule tl_zero,force)\n   apply force\n  apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n apply force\napply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\ndone\n\nlemma aux_onlyif [rule_format]: \"\\<forall>xs s. (xs, s)#ys \\<in> par_cptn \\<longrightarrow> \n  (\\<exists>clist. (length clist = length xs) \\<and> \n  (xs, s)#ys \\<propto> map (\\<lambda>i. (fst i,s)#(snd i)) (zip xs clist) \\<and> \n  (\\<forall>i<length xs. (xs!i,s)#(clist!i) \\<in> cptn))\"\napply(induct ys)\n apply(clarify)\n apply(rule_tac x=\"map (\\<lambda>i. []) [0..<length xs]\" in exI)\n apply(simp add: conjoin_def same_length_def same_state_def same_program_def compat_label_def)\n apply(rule conjI)\n  apply(rule nth_equalityI,simp,simp)\n apply(force intro: cptn.intros)\napply(clarify)\napply(erule par_cptn.cases,simp)\n apply simp\n apply(erule_tac x=\"xs\" in allE)\n apply(erule_tac x=\"t\" in allE,simp)\n apply clarify\n apply(rule_tac x=\"(map (\\<lambda>j. (P!j, t)#(clist!j)) [0..<length P])\" in exI,simp)\n apply(rule conjI)\n  prefer 2\n  apply clarify\n  apply(rule CptnEnv,simp)\n apply(simp add:conjoin_def same_length_def same_state_def)\n apply (rule conjI)\n  apply clarify\n  apply(case_tac j,simp,simp)\n apply(rule conjI)\n  apply(simp add:same_program_def)\n  apply clarify\n  apply(case_tac j,simp)\n   apply(rule nth_equalityI,simp,simp)\n  apply simp\n  apply(rule nth_equalityI,simp,simp)\n apply(simp add:compat_label_def)\n apply clarify\n apply(case_tac j,simp)\n  apply(simp add:ParEnv)\n  apply clarify\n  apply(simp add:Env)\n apply simp\n apply(erule_tac x=nat in allE,erule impE, assumption)\n apply(erule disjE,simp)\n  apply clarify\n  apply(rule_tac x=i in exI,simp)\n apply force\napply(erule par_ctran.cases,simp)\napply(erule_tac x=\"Ps[i:=r]\" in allE)\napply(erule_tac x=\"ta\" in allE,simp)\napply clarify\napply(rule_tac x=\"(map (\\<lambda>j. (Ps!j, ta)#(clist!j)) [0..<length Ps]) [i:=((r, ta)#(clist!i))]\" in exI,simp)\napply(rule conjI)\n prefer 2\n apply clarify\n apply(case_tac \"i=ia\",simp)\n  apply(erule CptnComp)\n  apply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> (I j \\<in> cptn)\" for H I in allE,simp)\n apply simp\n apply(erule_tac x=ia in allE)\n apply(rule CptnEnv,simp)\napply(simp add:conjoin_def)\napply (rule conjI)\n apply(simp add:same_length_def)\n apply clarify\n apply(case_tac \"i=ia\",simp,simp)\napply(rule conjI)\n apply(simp add:same_state_def)\n apply clarify\n apply(case_tac j, simp, simp (no_asm_simp))\n apply(case_tac \"i=ia\",simp,simp)\napply(rule conjI)\n apply(simp add:same_program_def)\n apply clarify\n apply(case_tac j,simp)\n  apply(rule nth_equalityI,simp,simp)\n apply simp\n apply(rule nth_equalityI,simp,simp)\n apply(erule_tac x=nat and P=\"\\<lambda>j. H j \\<longrightarrow> (fst (a j))=((b j))\" for H a b in allE)\n apply(case_tac nat)\n  apply clarify\n  apply(case_tac \"i=ia\",simp,simp)\n apply clarify\n apply(case_tac \"i=ia\",simp,simp)\napply(simp add:compat_label_def)\napply clarify\napply(case_tac j)\n apply(rule conjI,simp)\n  apply(erule ParComp,assumption)\n  apply clarify\n  apply(rule_tac x=i in exI,simp)\n apply clarify\n apply(rule Env)\napply simp\napply(erule_tac x=nat and P=\"\\<lambda>j. H j \\<longrightarrow> (P j \\<or> Q j)\" for H P Q in allE,simp)\napply(erule disjE)\n apply clarify\n apply(rule_tac x=ia in exI,simp)\n apply(rule conjI)\n  apply(case_tac \"i=ia\",simp,simp)\n apply clarify\n apply(case_tac \"i=l\",simp)\n  apply(case_tac \"l=ia\",simp,simp)\n  apply(erule_tac x=l in allE,erule impE,assumption,erule impE, assumption,simp)\n apply simp\n apply(erule_tac x=l in allE,erule impE,assumption,erule impE, assumption,simp)\napply clarify\napply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> (P j)\\<in>etran\" for H P in allE, erule impE, assumption)\napply(case_tac \"i=ia\",simp,simp)\ndone\n\nlemma one_iff_aux: \"xs\\<noteq>[] \\<Longrightarrow> (\\<forall>ys. ((xs, s)#ys \\<in> par_cptn) = \n (\\<exists>clist. length clist= length xs \\<and> \n ((xs, s)#ys \\<propto> map (\\<lambda>i. (fst i,s)#(snd i)) (zip xs clist)) \\<and> \n (\\<forall>i<length xs. (xs!i,s)#(clist!i) \\<in> cptn))) = \n (par_cp (xs) s = {c. \\<exists>clist. (length clist)=(length xs) \\<and>\n (\\<forall>i<length clist. (clist!i) \\<in> cp(xs!i) s) \\<and> c \\<propto> clist})\" \napply (rule iffI)\n apply(rule subset_antisym)\n  apply(rule subsetI) \n  apply(clarify)\n  apply(simp add:par_cp_def cp_def)\n  apply(case_tac x)\n   apply(force elim:par_cptn.cases)\n  apply simp\n  apply(rename_tac a list)\n  apply(erule_tac x=\"list\" in allE)\n  apply clarify\n  apply simp\n  apply(rule_tac x=\"map (\\<lambda>i. (fst i, s) # snd i) (zip xs clist)\" in exI,simp)\n apply(rule subsetI) \n apply(clarify)\n apply(case_tac x)\n  apply(erule_tac x=0 in allE)\n  apply(simp add:cp_def conjoin_def same_length_def same_program_def same_state_def compat_label_def)\n  apply clarify\n  apply(erule cptn.cases,force,force,force)\n apply(simp add:par_cp_def conjoin_def  same_length_def same_program_def same_state_def compat_label_def)\n apply clarify\n apply(erule_tac x=0 and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in all_dupE)\n apply(subgoal_tac \"a = xs\")\n  apply(subgoal_tac \"b = s\",simp)\n   prefer 3\n   apply(erule_tac x=0 and P=\"\\<lambda>j. H j \\<longrightarrow> (fst (s j))=((t j))\" for H s t in allE)\n   apply (simp add:cp_def)\n   apply(rule nth_equalityI,simp,simp)\n  prefer 2\n  apply(erule_tac x=0 in allE)\n  apply (simp add:cp_def)\n  apply(erule_tac x=0 and P=\"\\<lambda>j. H j \\<longrightarrow> (\\<forall>i. T i \\<longrightarrow> (snd (d j i))=(snd (e j i)))\" for H T d e in allE,simp)\n  apply(erule_tac x=0 and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE,simp)\n apply(erule_tac x=list in allE)\n apply(rule_tac x=\"map tl clist\" in exI,simp) \n apply(rule conjI)\n  apply clarify\n  apply(case_tac j,simp)\n   apply(erule_tac x=i  in allE, erule impE, assumption,\n        erule_tac x=\"0\" and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE,simp)\n  apply(erule_tac x=i  in allE, erule impE, assumption,\n        erule_tac x=\"Suc nat\" and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE)\n  apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n  apply(case_tac \"clist!i\",simp,simp)\n apply(rule conjI)\n  apply clarify\n  apply(rule nth_equalityI,simp,simp)\n  apply(case_tac j)\n   apply clarify\n   apply(erule_tac x=i in allE)\n   apply(simp add:cp_def)\n  apply clarify\n  apply simp\n  apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n  apply(case_tac \"clist!i\",simp,simp)\n apply(thin_tac \"H = (\\<exists>i. J i)\" for H J)\n apply(rule conjI)\n  apply clarify\n  apply(erule_tac x=j in allE,erule impE, assumption,erule disjE)\n   apply clarify\n   apply(rule_tac x=i in exI,simp)\n   apply(case_tac j,simp)\n    apply(rule conjI)\n     apply(erule_tac x=i in allE)\n     apply(simp add:cp_def)\n     apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n     apply(case_tac \"clist!i\",simp,simp)\n    apply clarify\n    apply(erule_tac x=l in allE)\n    apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE)\n    apply clarify\n    apply(simp add:cp_def)\n    apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n    apply(case_tac \"clist!l\",simp,simp)\n   apply simp\n   apply(rule conjI)\n    apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n    apply(case_tac \"clist!i\",simp,simp)\n   apply clarify\n   apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE)\n   apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n   apply(case_tac \"clist!l\",simp,simp)\n  apply clarify\n  apply(erule_tac x=i in allE)\n  apply(simp add:cp_def)\n  apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n  apply(case_tac \"clist!i\",simp)\n  apply(rule nth_tl_if,simp,simp)\n  apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (P j)\\<in>etran\" for H P in allE, erule impE, assumption,simp)\n  apply(simp add:cp_def)\n  apply clarify\n  apply(rule nth_tl_if)\n   apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n   apply(case_tac \"clist!i\",simp,simp)\n  apply force\n apply force\napply clarify\napply(rule iffI)\n apply(simp add:par_cp_def)\n apply(erule_tac c=\"(xs, s) # ys\" in equalityCE)\n  apply simp\n  apply clarify\n  apply(rule_tac x=\"map tl clist\" in exI)\n  apply simp\n  apply (rule conjI)\n   apply(simp add:conjoin_def cp_def)\n   apply(rule conjI)\n    apply clarify\n    apply(unfold same_length_def)\n    apply clarify\n    apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,simp)\n   apply(rule conjI)\n    apply(simp add:same_state_def)\n    apply clarify\n    apply(erule_tac x=i in allE, erule impE, assumption,\n       erule_tac x=j and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE)\n    apply(case_tac j,simp)\n    apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n    apply(case_tac \"clist!i\",simp,simp)\n   apply(rule conjI)\n    apply(simp add:same_program_def)\n    apply clarify\n    apply(rule nth_equalityI,simp,simp)\n    apply(case_tac j,simp)\n    apply clarify\n    apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n    apply(case_tac \"clist!i\",simp,simp)\n   apply clarify\n   apply(simp add:compat_label_def)\n   apply(rule allI,rule impI)\n   apply(erule_tac x=j in allE,erule impE, assumption)\n   apply(erule disjE)\n    apply clarify\n    apply(rule_tac x=i in exI,simp)\n    apply(rule conjI)\n     apply(erule_tac x=i in allE)\n     apply(case_tac j,simp)\n      apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n      apply(case_tac \"clist!i\",simp,simp)\n     apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n     apply(case_tac \"clist!i\",simp,simp)\n    apply clarify\n    apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE)\n    apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n    apply(case_tac \"clist!l\",simp,simp)\n    apply(erule_tac x=l in allE,simp)\n   apply(rule disjI2)\n   apply clarify\n   apply(rule tl_zero)\n     apply(case_tac j,simp,simp)\n     apply(rule tl_zero,force)   \n      apply force\n     apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n    apply force\n   apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n  apply clarify\n  apply(erule_tac x=i in allE)\n  apply(simp add:cp_def)\n  apply(rule nth_tl_if)\n    apply(simp add:conjoin_def)\n    apply clarify\n    apply(simp add:same_length_def)\n    apply(erule_tac x=i in allE,simp)\n   apply simp\n  apply simp\n apply simp\napply clarify\napply(erule_tac c=\"(xs, s) # ys\" in equalityCE)\n apply(simp add:par_cp_def)\napply simp\napply(erule_tac x=\"map (\\<lambda>i. (fst i, s) # snd i) (zip xs clist)\" in allE)\napply simp\napply clarify\napply(simp add:cp_def)\ndone\n\ntheorem one: \"xs\\<noteq>[] \\<Longrightarrow> \n par_cp xs s = {c. \\<exists>clist. (length clist)=(length xs) \\<and> \n               (\\<forall>i<length clist. (clist!i) \\<in> cp(xs!i) s) \\<and> c \\<propto> clist}\"\napply(frule one_iff_aux)\napply(drule sym)\napply(erule iffD2)\napply clarify\napply(rule iffI)\n apply(erule aux_onlyif)\napply clarify\napply(force intro:aux_if)\ndone\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/HOL/Hoare_Parallel/RG_Tran.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5851011686727231, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.2902650793947616}}
{"text": "theory Mapping_Code\n  imports \"Containers.Mapping_Impl\"\nbegin\n\nlift_definition set_of_idx :: \"('a, 'b set) mapping \\<Rightarrow> 'b set\" is\n  \"\\<lambda>m. \\<Union>(ran m)\" .\n\nlemma set_of_idx_code[code]:\n  fixes t :: \"('a :: ccompare, 'b set) mapping_rbt\"\n  shows \"set_of_idx (RBT_Mapping t) =\n    (case ID CCOMPARE('a) of None \\<Rightarrow> Code.abort (STR ''set_of_idx RBT_Mapping: ccompare = None'') (\\<lambda>_. set_of_idx (RBT_Mapping t))\n    | Some _ \\<Rightarrow> \\<Union>(snd ` set (RBT_Mapping2.entries t)))\"\n  unfolding RBT_Mapping_def\n  by transfer (auto simp: ran_def rbt_comp_lookup[OF ID_ccompare'] ord.is_rbt_def linorder.rbt_lookup_in_tree[OF comparator.linorder[OF ID_ccompare']] split: option.splits)+\n\nlemma mapping_combine[code]:\n  fixes t :: \"('a :: ccompare, 'b) mapping_rbt\"\n  shows \"Mapping.combine f (RBT_Mapping t) (RBT_Mapping u) =\n    (case ID CCOMPARE('a) of None \\<Rightarrow> Code.abort (STR ''combine RBT_Mapping: ccompare = None'') (\\<lambda>_. Mapping.combine f (RBT_Mapping t) (RBT_Mapping u))\n    | Some _ \\<Rightarrow> RBT_Mapping (RBT_Mapping2.join (\\<lambda>_. f) t u))\"\n  by (auto simp add: Mapping.combine.abs_eq Mapping_inject lookup_join split: option.split)\n\nlift_definition mapping_join :: \"('b \\<Rightarrow> 'b \\<Rightarrow> 'b) \\<Rightarrow> ('a, 'b) mapping \\<Rightarrow> ('a, 'b) mapping \\<Rightarrow> ('a, 'b) mapping\" is\n  \"\\<lambda>f m m' x. case m x of None \\<Rightarrow> None | Some y \\<Rightarrow> (case m' x of None \\<Rightarrow> None | Some y' \\<Rightarrow> Some (f y y'))\" .\n\nlemma mapping_join_code[code]:\n  fixes t :: \"('a :: ccompare, 'b) mapping_rbt\"\n  shows \"mapping_join f (RBT_Mapping t) (RBT_Mapping u) =\n    (case ID CCOMPARE('a) of None \\<Rightarrow> Code.abort (STR ''mapping_join RBT_Mapping: ccompare = None'') (\\<lambda>_. mapping_join f (RBT_Mapping t) (RBT_Mapping u))\n    | Some _ \\<Rightarrow> RBT_Mapping (RBT_Mapping2.meet (\\<lambda>_. f) t u))\"\n  by (auto simp add: mapping_join.abs_eq Mapping_inject lookup_meet split: option.split)\n\ncontext fixes dummy :: \"'a :: ccompare\" begin\n\nlift_definition diff ::\n  \"('a, 'b) mapping_rbt \\<Rightarrow> ('a, 'b) mapping_rbt \\<Rightarrow> ('a, 'b) mapping_rbt\" is \"rbt_comp_minus ccomp\"\n  by (auto 4 3 intro: linorder.rbt_minus_is_rbt ID_ccompare ord.is_rbt_rbt_sorted simp: rbt_comp_minus[OF ID_ccompare'])\n\nend\n\ncontext assumes ID_ccompare_neq_None: \"ID CCOMPARE('a :: ccompare) \\<noteq> None\"\nbegin\n\nlemma lookup_diff:\n  \"RBT_Mapping2.lookup (diff (t1 :: ('a, 'b) mapping_rbt) t2) =\n  (\\<lambda>k. case RBT_Mapping2.lookup t1 k of None \\<Rightarrow> None | Some v1 \\<Rightarrow> (case RBT_Mapping2.lookup t2 k of None \\<Rightarrow> Some v1 | Some v2 \\<Rightarrow> None))\"\n  by transfer (auto simp add: fun_eq_iff linorder.rbt_lookup_rbt_minus[OF mapping_linorder] ID_ccompare_neq_None restrict_map_def split: option.splits)\n\nend\n\nlift_definition mapping_antijoin :: \"('a, 'b) mapping \\<Rightarrow> ('a, 'b) mapping \\<Rightarrow> ('a, 'b) mapping\" is\n  \"\\<lambda>m m' x. case m x of None \\<Rightarrow> None | Some y \\<Rightarrow> (case m' x of None \\<Rightarrow> Some y | Some y' \\<Rightarrow> None)\" .\n\nlemma mapping_antijoin_code[code]:\n  fixes t :: \"('a :: ccompare, 'b) mapping_rbt\"\n  shows \"mapping_antijoin (RBT_Mapping t) (RBT_Mapping u) =\n    (case ID CCOMPARE('a) of None \\<Rightarrow> Code.abort (STR ''mapping_antijoin RBT_Mapping: ccompare = None'') (\\<lambda>_. mapping_antijoin (RBT_Mapping t) (RBT_Mapping u))\n    | Some _ \\<Rightarrow> RBT_Mapping (diff t u))\"\n  by (auto simp add: mapping_antijoin.abs_eq Mapping_inject lookup_diff split: option.split)\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Eval_FO/Mapping_Code.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5851011542032312, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.29026507221653597}}
{"text": "theory LaunchburyMoreFree\nimports Terms Heap Launchbury\nbegin\n\ntext {*\nThis variant of the original semantics allocates an additional free variable in the application case.\nThis is a prelimary step towards the equivalence of the original and the stacked semantics.\n*}\n\ninductive\n  reds :: \"heap \\<Rightarrow> exp \\<Rightarrow> var list \\<Rightarrow> heap \\<Rightarrow> exp \\<Rightarrow> bool\"\n  (\"_ : _ \\<Down>*\\<^bsub>_\\<^esub> _ : _\" [50,50,50,50] 50)\nwhere\n  Lambda:\n    \"\\<Gamma> : (Lam [x]. e) \\<Down>*\\<^bsub>L\\<^esub> \\<Gamma> : (Lam [x]. e)\" \n | Application: \"\\<lbrakk>\n    atom y \\<sharp> (\\<Gamma>,e,x,L,\\<Delta>,\\<Theta>,z) ;\n    atom (n::var) \\<sharp> (\\<Gamma>,e,x,L,\\<Delta>,\\<Theta>,z) ;\n    n \\<noteq> y;\n    \\<Gamma> : e \\<Down>*\\<^bsub>n#x#L\\<^esub> \\<Delta> : (Lam [y]. e');\n    \\<Delta> : e'[y ::= x] \\<Down>*\\<^bsub>L\\<^esub> \\<Theta> : z\n  \\<rbrakk>  \\<Longrightarrow>\n    \\<Gamma> : App e x \\<Down>*\\<^bsub>L\\<^esub> \\<Theta> : z\" \n | Variable: \"\\<lbrakk>\n    (x,e) \\<in> set \\<Gamma>; delete x \\<Gamma> : e \\<Down>*\\<^bsub>x#L\\<^esub> \\<Delta> : z \\<rbrakk> \\<Longrightarrow> \\<Gamma> : Var x \\<Down>*\\<^bsub>L\\<^esub> (x, z) # \\<Delta> : z\"\n | Let: \"\\<lbrakk>\n    set (bn as) \\<sharp>* (\\<Gamma>, L);\n    distinctVars (asToHeap as);\n    asToHeap as @ \\<Gamma> : body \\<Down>*\\<^bsub>L\\<^esub> \\<Delta> : z\n  \\<rbrakk> \\<Longrightarrow>\n    \\<Gamma> : Let as body \\<Down>*\\<^bsub>L\\<^esub> \\<Delta> : z\"\n\nequivariance reds\n\nnominal_inductive reds\n  avoids Application: \"y\" and \"n\"\n    by(auto simp add: fresh_star_def fresh_Pair)\n\nlemma reds_less_free:\n  \"\\<Gamma> : e \\<Down>*\\<^bsub>L\\<^esub> \\<Delta> : z \\<Longrightarrow> \\<Gamma> : e \\<Down>\\<^bsub>L\\<^esub> \\<Delta> : z\"\nproof(induct rule: LaunchburyMoreFree.reds.induct)\ncase (Application y \\<Gamma> e x L \\<Delta> \\<Theta> z n e')\n  show ?case\n  proof(rule Launchbury.reds.Application)\n    show \"atom y \\<sharp> (\\<Gamma>, e, x, L, \\<Delta>, \\<Theta>, z)\"\n      by fact\n    show  \"\\<Gamma> : e \\<Down>\\<^bsub>x # L\\<^esub> \\<Delta> : Lam [y]. e'\"\n      apply (rule reds_smaller_L[OF Application.hyps(5)])\n      by auto\n    show \"\\<Delta> : e'[y::=x] \\<Down>\\<^bsub>L\\<^esub> \\<Theta> : z\"\n      by fact\n  qed\nqed (auto intro: reds_smaller_L Launchbury.reds.intros simp add: fresh_star_Pair)\n\n\nlemma reds_with_n_doesnt_forget:\n  \"\\<Gamma> : e \\<Down>*\\<^bsub>L\\<^esub> \\<Delta> : z \\<Longrightarrow> heapVars \\<Gamma> \\<subseteq> heapVars \\<Delta>\"\nby (metis reds_less_free reds_doesnt_forget)\n\nlemma reds_with_n_fresh:\" \\<lbrakk> \\<Gamma> : e \\<Down>*\\<^bsub>L\\<^esub> \\<Delta> : z;\n   atom (x::var) \\<sharp> (\\<Gamma>, e)\n  \\<rbrakk> \\<Longrightarrow> atom x \\<sharp> (\\<Delta>, z) \\<or> x \\<in> (heapVars \\<Delta> - set L)\"\n  by (metis reds_less_free reds_fresh)\n\nlemma reds_with_n_add_var_L: \"\\<lbrakk> \\<Gamma> : e \\<Down>*\\<^bsub>L\\<^esub> \\<Delta> : z;\n   atom (x::var) \\<sharp> (\\<Gamma>, e, \\<Delta>, z);\n   set L' = insert x (set L)\n  \\<rbrakk> \\<Longrightarrow> \\<Gamma> : e \\<Down>*\\<^bsub>L'\\<^esub> \\<Delta> : z\"\nproof(nominal_induct avoiding : L' rule: reds.strong_induct)\ncase (Lambda \\<Gamma> x e L L')\n  show ?case\n    by (rule reds.Lambda)\nnext\ncase (Application y \\<Gamma> e xa L \\<Delta> \\<Theta> z n e' L')\n  show ?case\n  proof(rule reds.Application)\n    show \"atom y \\<sharp> (\\<Gamma>, e, xa, L', \\<Delta>, \\<Theta>, z)\"\n      using Application\n      by (auto simp add: fresh_Pair)\n  \n    show \"atom n \\<sharp> (\\<Gamma>, e, xa, L', \\<Delta>, \\<Theta>, z)\"\n      using Application\n      by (auto simp add: fresh_Pair)\n\n    show \"n \\<noteq> y\" by fact\n\n    have \"x \\<notin> heapVars \\<Theta>\"\n      using `atom x \\<sharp> (\\<Gamma>, App e xa, \\<Theta>, z)`\n      apply (simp add: fresh_Pair)\n      by (metis heapVars_not_fresh)\n    hence \"x \\<notin> heapVars \\<Delta>\"\n      by (metis set_mp reds_with_n_doesnt_forget[OF Application.hyps(20)])\n\n    have \"atom x \\<sharp> (\\<Gamma>, e)\"\n      using `atom x \\<sharp> (\\<Gamma>, App e xa, \\<Theta>, z)`\n      by (simp add: fresh_Pair)\n    from reds_with_n_fresh[OF Application.hyps(18) this] `x \\<notin> heapVars \\<Delta>`\n    have \"atom x \\<sharp> (\\<Delta>, Lam [y]. e')\"\n      by auto\n    hence \"atom x \\<sharp> (\\<Gamma>, e, \\<Delta>, Lam [y]. e')\"\n      using `atom x \\<sharp> (\\<Gamma>, App e xa, \\<Theta>, z)`\n      by (simp add: fresh_Pair)\n    moreover\n    have \"set (n # xa # L') = insert x (set (n # xa # L))\"\n      using `set L' = _` by auto\n    ultimately\n    show \"\\<Gamma> : e \\<Down>*\\<^bsub>n # xa # L'\\<^esub> \\<Delta> : Lam [y]. e'\"\n      by (rule Application.hyps(19))\n\n    have \"atom x \\<sharp> (\\<Delta>, e'[y::=xa])\"\n      using `atom x \\<sharp> (\\<Delta>, Lam [y]. e')` `atom x \\<sharp> (\\<Gamma>, App e xa, \\<Theta>, z)` `atom y \\<sharp> xa`\n      apply (auto simp add: fresh_Pair)\n      apply (rule subst_pres_fresh[rule_format])\n      apply simp\n      done\n    from reds_with_n_fresh[OF Application.hyps(20) this] `x \\<notin> heapVars \\<Theta>`\n    have \"atom x \\<sharp> (\\<Theta>, z)\" by auto\n    hence \"atom x \\<sharp> (\\<Delta>, e'[y::=xa], \\<Theta>, z)\"\n      using `atom x \\<sharp> (\\<Delta>, e'[y::=xa])`\n      by (simp add: fresh_Pair)\n    then\n    show \"\\<Delta> : e'[y::=xa] \\<Down>*\\<^bsub>L'\\<^esub> \\<Theta> : z \"\n      by (rule Application.hyps(21)[OF _ `set L' = _`])\n  qed\nnext \ncase (Variable xa e \\<Gamma> L \\<Delta> z L')\n  have \"atom x \\<sharp> (delete xa \\<Gamma>, e, \\<Delta>, z)\"\n    using Variable.prems(1)\n    by (auto simp add: fresh_Pair fresh_Cons intro: fresh_delete fresh_heap_expr[OF _ Variable(1)])\n  moreover\n  have \"set (xa # L') = insert x (set (xa # L))\"\n    using Variable.prems(2) by auto\n  ultimately\n  show ?case\n    by (rule reds.Variable[OF Variable(1) Variable.hyps(3)])\nnext\ncase (Let as \\<Gamma> L body \\<Delta> z L')\n  have \"x \\<notin> heapVars \\<Delta>\"\n    using Let.prems(1)\n    apply (auto simp add: fresh_Pair)\n    by (metis heapVars_not_fresh)+\n  hence \"x \\<notin> heapVars (asToHeap as @ \\<Gamma>)\"\n      by (metis set_mp reds_with_n_doesnt_forget[OF Let.hyps(4)])\n  hence \"atom x \\<notin> set (bn as)\"\n    by (auto simp add: set_bn_to_atom_heapVars)\n  hence \"set (bn as) \\<sharp>* x\"\n    by (auto simp add: fresh_star_def fresh_at_base)\n    \n  hence \"set (bn as) \\<sharp>* set L'\"\n    using Let(2) Let.prems(2)\n    by (auto simp add: fresh_star_def fresh_finite_insert fresh_set)\n  hence \"set (bn as) \\<sharp>* (\\<Gamma>, L')\" \n    using Let(1-4)\n    by (simp add: fresh_star_Pair fresh_star_set )\n  moreover\n  have \"atom x \\<sharp> (asToHeap as @ \\<Gamma>, body, \\<Delta>, z)\"\n    using Let.prems(1) `atom x \\<notin> set (bn as)`\n    by (auto simp add: fresh_Pair fresh_append fresh_fun_eqvt_app[OF asToHeap_eqvt])\n  ultimately\n  show ?case\n    by (rule reds.Let[OF _ Let.hyps(3) Let.hyps(5)[OF _ Let.prems(2)]])\nqed\n\nlemma reds_more_free:\n  \"\\<Gamma> : e \\<Down>\\<^bsub>L\\<^esub> \\<Delta> : z \\<Longrightarrow> \\<Gamma> : e \\<Down>*\\<^bsub>L\\<^esub> \\<Delta> : z\"\nproof(nominal_induct rule: Launchbury.reds.strong_induct)\ncase (Application y \\<Gamma> e x L \\<Delta> \\<Theta> z e')\n  obtain n :: var where\n    fresh: \"atom n \\<sharp> (\\<Gamma>, e, x, L, \\<Delta>, \\<Theta>, z, y, Lam [y]. e')\" \n    by (rule obtain_fresh)\n\n  show ?case\n  proof (rule reds.Application)\n    show \"atom y \\<sharp> (\\<Gamma>, e, x, L, \\<Delta>, \\<Theta>, z)\"\n      using Application\n      by (auto simp add: fresh_Pair)\n    show \"atom n \\<sharp> (\\<Gamma>, e, x, L, \\<Delta>, \\<Theta>, z)\"\n      using fresh\n      by (auto simp add: fresh_Pair)\n   show \"n \\<noteq> y\"\n      using fresh\n      by (auto simp add: fresh_Pair fresh_at_base)\n\n    note `\\<Gamma> : e \\<Down>*\\<^bsub>x # L\\<^esub> \\<Delta> : Lam [y]. e'`\n    moreover\n    have \"atom n \\<sharp> (\\<Gamma>, e, \\<Delta>, Lam [y]. e')\"\n      using fresh by (auto simp add: fresh_Pair)\n    ultimately\n    show \"\\<Gamma> : e \\<Down>*\\<^bsub>n # x # L\\<^esub> \\<Delta> : Lam [y]. e'\"\n      by (rule reds_with_n_add_var_L, simp)\n\n    show \"\\<Delta> : e'[y::=x] \\<Down>*\\<^bsub>L\\<^esub> \\<Theta> : z\"\n      by fact\n  qed\nqed (auto intro: reds.intros simp add: fresh_star_Pair)\n\nlemma reds_more_free_eq:\n  \"(\\<Gamma> : e \\<Down>*\\<^bsub>L\\<^esub> \\<Delta> : z) \\<longleftrightarrow> (\\<Gamma> : e \\<Down>\\<^bsub>L\\<^esub> \\<Delta> : z)\"\n  by (metis reds_less_free reds_more_free)\n\nlemmas reds_with_n_strong_induct = LaunchburyMoreFree.reds.strong_induct[unfolded reds_more_free_eq, consumes 1, case_names Lambda Application Variable Let]\nlemmas reds_with_n_induct = LaunchburyMoreFree.reds.induct[unfolded reds_more_free_eq, consumes 1, case_names Lambda Application Variable Let]\n\n(* This can be shown for reds directly, but we needed it here, and after we got the equality we can transfer it easily. *)\nlemmas reds_add_var_L = reds_with_n_add_var_L[unfolded reds_more_free_eq]\n\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Launchbury/LaunchburyMoreFree.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5544704649604274, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.2902211242444728}}
{"text": "(*  Title:       BDD\n\n    Author:      Veronika Ortner and Norbert Schirmer, 2004\n    Maintainer:  Norbert Schirmer,  norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  \nShareReduceRepListProof.thy\n\nCopyright (C) 2004 Veronika Ortner and Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection \\<open>Proof of Procedure ShareReduceRepList\\<close>\ntheory ShareReduceRepListProof imports ShareRepProof begin\n\nlemma (in ShareReduceRepList_impl) ShareReduceRepList_modifies:\n  shows \"\\<forall>\\<sigma>. \\<Gamma>\\<turnstile>{\\<sigma>}  PROC ShareReduceRepList (\\<acute>nodeslist)\n        {t. t may_only_modify_globals \\<sigma> in [rep]}\"\n  apply (hoare_rule HoarePartial.ProcRec1)\n  apply (vcg spec=modifies)\n  done\n\nlemma hd_filter_app: \"\\<lbrakk>filter P xs \\<noteq> []; zs=xs@ys\\<rbrakk> \\<Longrightarrow> \n       hd (filter P zs) =  hd (filter P xs)\"\n  by (induct xs arbitrary: n m) auto\n\n\nlemma (in ShareReduceRepList_impl) ShareReduceRepList_spec_total: \ndefines \"var_eq \\<equiv> (\\<lambda>ns var. (\\<forall>no1 \\<in> set ns. \\<forall>no2 \\<in> set ns. no1\\<rightarrow>var = no2\\<rightarrow>var))\"\nshows\n  \"\\<forall>\\<sigma> ns. \\<Gamma>\\<turnstile>\\<^sub>t\n   \\<lbrace>\\<sigma>. List \\<acute>nodeslist \\<acute>next ns \\<and>\n       (\\<forall>no \\<in> set ns.\n            no \\<noteq> Null \\<and> ((no\\<rightarrow>\\<acute>low = Null) = (no\\<rightarrow>\\<acute>high = Null)) \\<and> \n             no\\<rightarrow>\\<acute>low \\<notin> set ns \\<and> no\\<rightarrow>\\<acute>high \\<notin> set ns \\<and>\n             (isLeaf_pt no \\<acute>low \\<acute>high = (no\\<rightarrow>\\<acute>var \\<le> 1)) \\<and>\n             (no\\<rightarrow>\\<acute>low \\<noteq> Null \\<longrightarrow> (no\\<rightarrow>\\<acute>low)\\<rightarrow>\\<acute>rep \\<noteq> Null) \\<and>\n             ((\\<acute>rep \\<propto> \\<acute>low) no \\<notin> set ns)) \\<and>\n        var_eq ns \\<acute>var\\<rbrace> \n    PROC  ShareReduceRepList (\\<acute>nodeslist)\n   \\<lbrace>(\\<forall>no. no \\<notin> set ns \\<longrightarrow> no\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>rep = no\\<rightarrow>\\<acute>rep)  \\<and>\n    (\\<forall>no \\<in> set ns. no\\<rightarrow>\\<acute>rep \\<noteq> Null \\<and> \n      (if ((\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>low) no = (\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>high) no \\<and> no\\<rightarrow> \\<^bsup>\\<sigma>\\<^esup>low \\<noteq> Null) \n       then (no\\<rightarrow>\\<acute>rep = (\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>low) no )\n       else ((no\\<rightarrow>\\<acute>rep) \\<in> set ns \\<and> no\\<rightarrow>\\<acute>rep\\<rightarrow>\\<acute>rep = no\\<rightarrow>\\<acute>rep \\<and> \n             (\\<forall> no1 \\<in> set ns. \n                 ((\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>high) no1 = (\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>high) no \\<and> \n                 (\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>low) no1 = (\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>low) no) = (no\\<rightarrow>\\<acute>rep = no1\\<rightarrow>\\<acute>rep)))))\\<rbrace>\"\napply (hoare_rule HoareTotal.ProcNoRec1)\napply (hoare_rule anno=\n       \" \\<acute>node :== \\<acute>nodeslist;;\n         WHILE (\\<acute>node \\<noteq> Null ) \n         INV \\<lbrace>\\<exists>prx sfx. List \\<acute>node \\<acute>next sfx \\<and> \n              List \\<acute>nodeslist \\<acute>next ns \\<and> ns=prx@sfx \\<and> \n              (\\<forall>no \\<in> set ns.\n                 no \\<noteq> Null \\<and> ((no\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>low = Null) = (no\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>high = Null)) \\<and> \n                 no\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>low \\<notin> set ns \\<and> no\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>high \\<notin> set ns \\<and>\n                 (isLeaf_pt no  \\<^bsup>\\<sigma>\\<^esup>low \\<^bsup>\\<sigma>\\<^esup>high = (no\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>var \\<le> 1)) \\<and>\n                 (no\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>low \\<noteq> Null \\<longrightarrow> (no\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>low)\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>rep \\<noteq> Null) \\<and>\n                 ((\\<^bsup>\\<sigma>\\<^esup>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>low) no  \\<notin> set ns)) \\<and>\n              var_eq ns \\<acute>var \\<and>\n              (\\<forall>no.  no \\<notin> set prx \\<longrightarrow> no\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>rep = no \\<rightarrow>\\<acute>rep)  \\<and>\n              (\\<forall> no \\<in> set prx. no\\<rightarrow>\\<acute>rep \\<noteq> Null \\<and> \n               (if ((\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>low) no = (\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>high) no \\<and> no\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>low \\<noteq> Null) \n                then (no\\<rightarrow>\\<acute>rep = (\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>low) no )\n                else ((no\\<rightarrow>\\<acute>rep)=hd (filter (\\<lambda>sn. repNodes_eq sn no \\<^bsup>\\<sigma>\\<^esup>low \\<^bsup>\\<sigma>\\<^esup>high \\<acute>rep) \n                                     prx) \\<and> \n                     ((no\\<rightarrow>\\<acute>rep)\\<rightarrow>\\<acute>rep) = no\\<rightarrow>\\<acute>rep \\<and> \n                     (\\<forall>no1 \\<in> set prx. \n                        ((\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>high) no1 = (\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>high) no \\<and> \n                         (\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>low) no1 = (\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>low) no) = \n                         (no\\<rightarrow>\\<acute>rep = no1\\<rightarrow>\\<acute>rep))))) \\<and>\n                 \\<acute>nodeslist= \\<^bsup>\\<sigma>\\<^esup>nodeslist \\<and> \\<acute>high=\\<^bsup>\\<sigma>\\<^esup>high \\<and> \\<acute>low=\\<^bsup>\\<sigma>\\<^esup>low \\<and> \\<acute>var=\\<^bsup>\\<sigma>\\<^esup>var\\<rbrace>\n         VAR MEASURE (length (list \\<acute>node \\<acute>next))\n         DO\n         IF (\\<not> isLeaf_pt \\<acute>node \\<acute>low \\<acute>high \\<and> \n            \\<acute>node \\<rightarrow> \\<acute>low \\<rightarrow> \\<acute>rep = \\<acute>node \\<rightarrow> \\<acute>high \\<rightarrow> \\<acute>rep )\n         THEN \\<acute>node \\<rightarrow> \\<acute>rep :== \\<acute>node \\<rightarrow> \\<acute>low \\<rightarrow> \\<acute>rep\n         ELSE CALL ShareRep (\\<acute>nodeslist , \\<acute>node)   \n         FI;;\n         \\<acute>node :==\\<acute>node \\<rightarrow> \\<acute>next\n         OD\" in HoareTotal.annotateI)\napply (vcg spec=spec_total)\napply   (rule_tac x=\"[]\" in exI)\napply   (rule_tac x=\"ns\" in exI)\nusing [[simp_depth_limit = 2]]\napply   (simp (no_asm_use))\nprefer 2\nusing [[simp_depth_limit = 4]]\napply (clarsimp)\nprefer 2\napply  (rule conjI)\napply   clarify\napply   (rule conjI)\napply    (clarsimp simp add: List_list) (* termination *)\napply   (simp only: List_not_Null simp_thms triv_forall_equality)\napply   clarify\napply   (simp only: triv_forall_equality)\napply   (rename_tac sfx)\napply   (rule_tac x=\"prx@[node]\" in exI)\napply   (rule_tac x=\"sfx\" in exI)\napply   (rule conjI)\napply    assumption\napply   (rule conjI)\napply    (simp (no_asm))\napply   (rule conjI)\napply    (assumption)\nprefer 2\napply   clarify\napply   (simp only: List_not_Null simp_thms triv_forall_equality)\napply   clarify\napply   (simp only: triv_forall_equality)\napply   (rename_tac sfx)\napply   (rule_tac x=\"prx@node#sfx\" in exI) (* Precondition for ShareRep *)\napply   (rule conjI)\napply    assumption\napply   (rule conjI)\napply    (rule ballI)\napply    (frule_tac x=no in bspec, assumption)\napply    (drule_tac x=node in bspec)\napply     (simp (no_asm_use))\napply    (elim conjE)\napply    (rule conjI)\napply     assumption\napply    (rule conjI)\napply     assumption\napply    (unfold var_eq_def)\napply    (drule_tac x=node in bspec, simp)\napply    (drule_tac x=no in bspec,assumption)\napply    (simp add: isLeaf_pt_def )\napply   (rule conjI)\napply    (simp (no_asm))\napply   (clarify)\napply   (rule conjI)\napply    (subgoal_tac \"List node next (node#sfx)\") (* termination *)\napply     (simp only: List_list)\napply     (simp (no_asm))\napply    (simp (no_asm_simp))\napply   (rule_tac x=\"prx@[node]\" in exI)\napply   (rule_tac x=\"sfx\" in exI)\napply   (rule conjI)\napply    assumption\napply   (rule conjI)\napply    (simp (no_asm))\napply   (rule conjI)\napply    (assumption)\nusing [[simp_depth_limit = 100]]\nproof - (* From invariant to postcondition *)\n  fix var low high rep nodeslist ns repa \"next\" no\n  assume ns: \"List nodeslist next ns\"\n  assume no_in_ns: \"no \\<in> set ns\"\n  assume while_inv: \"\\<forall>no\\<in>set ns.\n           repa no \\<noteq> Null \\<and>\n           (if (repa \\<propto> low) no = (repa \\<propto> high) no \\<and> high no \\<noteq> Null\n            then repa no = (repa \\<propto> low) no\n            else repa no = hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa] \\<and>\n                 repa (repa no) = repa no \\<and>\n                 (\\<forall>no1\\<in>set ns.\n                     ((repa \\<propto> high) no1 = (repa \\<propto> high) no \\<and>\n                      (repa \\<propto> low) no1 = (repa \\<propto> low) no) =\n                     (repa no = repa no1)))\"\n  assume pre: \"\\<forall>no\\<in>set ns.\n           no \\<noteq> Null \\<and>\n           (low no = Null) = (high no = Null) \\<and>\n           low no \\<notin> set ns \\<and>\n           high no \\<notin> set ns \\<and>\n           isLeaf_pt no low high = (var no \\<le> Suc 0) \\<and>\n           (low no \\<noteq> Null \\<longrightarrow> rep (low no) \\<noteq> Null) \\<and> (rep \\<propto> low) no \\<notin> set ns\"\n  assume same_var: \"\\<forall>no1\\<in>set ns. \\<forall>no2\\<in>set ns. var no1 = var no2\"\n  assume share_case: \"(repa \\<propto> low) no = (repa \\<propto> high) no \\<longrightarrow> high no = Null\"\n  assume unmodif: \"\\<forall>no. no \\<notin> set ns \\<longrightarrow> rep no = repa no\"\n  show \"hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa] \\<in> set ns \\<and>\n        repa (hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa]) =\n        hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa]\"\n  proof -\n    from no_in_ns pre obtain\n      no_nNull: \" no \\<noteq> Null\" and\n      no_balanced: \"(low no = Null) = (high no = Null)\" and\n      isLeaf_var: \"isLeaf_pt no low high = (var no \\<le> Suc 0)\"\n      by blast\n    have repNodes_eq_same_node: \"repNodes_eq no no low high repa\"\n      by (simp add: repNodes_eq_def)\n    from no_in_ns have ns_nempty: \"ns \\<noteq> []\"\n      by auto\n    from no_in_ns repNodes_eq_same_node \n    have repNodes_not_empty: \"[sn\\<leftarrow>ns . repNodes_eq sn no low high repa] \\<noteq> []\"\n      by (rule filter_not_empty)\n    then have hd_term_in_ns: \"hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa] \\<in> set ns\"\n      by (rule hd_filter_in_list)\n    with while_inv obtain \n      repa_hd_nNull: \"repa  (hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa]) \\<noteq> Null\"\n      by auto\n    let ?hd = \"hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa]\"\n    from hd_term_in_ns  pre obtain\n      hd_nNull: \" ?hd \\<noteq> Null\" and\n      hd_balanced: \n        \"(low (hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa]) = Null) = \n         (high (hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa]) = Null)\" and\n      hd_isLeaf_var: \n      \"isLeaf_pt (hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa]) low high = \n      (var (hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa]) \\<le> Suc 0)\"\n      by blast\n    have \"repa (hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa]) = \n      hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa]\"\n    proof (cases \"high no = Null\")\n      case True\n      with no_balanced have \"low no = Null\"\n        by simp\n      with True have no_Leaf: \"isLeaf_pt no low high\"\n        by (simp add: isLeaf_pt_def)\n      with isLeaf_var have varno: \"var no <= 1\"\n        by simp\n      from same_var [rule_format, OF no_in_ns hd_term_in_ns] varno\n      have \"var (hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa]) \\<le> 1\"\n        by simp\n      with hd_isLeaf_var have \n        \"isLeaf_pt (hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa]) low high\"\n        by simp\n      with while_inv hd_term_in_ns repNodes_not_empty show ?thesis\n        apply (simp add: isLeaf_pt_def)\n        apply (erule_tac x=\n          \"hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa]\" in ballE)\n        prefer 2\n        apply simp\n        apply (simp (no_asm_use) add: repNodes_eq_def)\n        apply (rule filter_hd_P_rep_indep)\n        apply   (simp (no_asm_simp))\n        apply  (simp (no_asm_simp))\n        apply assumption\n        done\n    next\n      assume hno_nNull:  \"high no \\<noteq> Null\"\n      with share_case have repchildren_neq: \"(repa \\<propto> low) no \\<noteq> (repa \\<propto> high) no\"\n        by simp\n      from repNodes_not_empty have \n        \"repNodes_eq  (hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa]) no low high repa\"\n        by (rule hd_filter_prop)\n      then \n      have \"(repa \\<propto> low) (hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa]) = \n              (repa \\<propto> low) no \\<and> \n            (repa \\<propto> high) (hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa]) = \n              (repa \\<propto> high) no\"\n        by (simp add: repNodes_eq_def)\n      with repchildren_neq have \n        \"(repa \\<propto> low) (hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa])\n        \\<noteq> (repa \\<propto> high) (hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa])\"\n        by simp\n      with while_inv hd_term_in_ns repNodes_not_empty show ?thesis\n        apply (simp add: isLeaf_pt_def)\n        apply (erule_tac x=\n          \"hd [sn\\<leftarrow>ns . repNodes_eq sn no low high repa]\" in ballE)\n        prefer 2\n        apply simp\n        apply (simp (no_asm_use) add: repNodes_eq_def)\n        apply (rule filter_hd_P_rep_indep)\n        apply simp\n        apply fastforce\n        apply fastforce\n        done\n    qed\n    with hd_term_in_ns\n    show ?thesis\n      by simp\n  qed\nnext\n  (* invariant to invariant, THEN part  --  REDUCING*)\n  fix var low high rep nodeslist repa \"next\" node prx sfx\n  assume ns: \"List nodeslist next (prx @ node # sfx)\"\n  assume sfx: \"List (next node) next sfx\"\n  assume node_not_Null: \"node \\<noteq> Null\"\n  assume nodes_balanced_ordered: \"\\<forall>no\\<in>set (prx @ node # sfx).\n           no \\<noteq> Null \\<and>\n           (low no = Null) = (high no = Null) \\<and>\n           low no \\<notin> set (prx @ node # sfx) \\<and>\n           high no \\<notin> set (prx @ node # sfx) \\<and>\n           isLeaf_pt no low high = (var no \\<le> (1::nat)) \\<and>\n           (low no \\<noteq> Null \\<longrightarrow> rep (low no) \\<noteq> Null) \\<and>\n           (rep \\<propto> low) no \\<notin> set (prx @ node # sfx)\"\n  assume all_nodes_same_var: \"\\<forall>no1\\<in>set (prx @ node # sfx).\n           \\<forall>no2\\<in>set (prx @ node # sfx). var no1 = var no2\"\n  assume rep_repa_nc: \"\\<forall>no. no \\<notin> set prx \\<longrightarrow> rep no = repa no\"\n  assume while_inv: \"\\<forall>no\\<in>set prx.\n           repa no \\<noteq> Null \\<and>\n           (if (repa \\<propto> low) no = (repa \\<propto> high) no \\<and> low no \\<noteq> Null\n            then repa no = (repa \\<propto> low) no\n            else repa no = hd [sn\\<leftarrow>prx . repNodes_eq sn no low high repa] \\<and>\n                 repa (repa no) = repa no \\<and>\n                 (\\<forall>no1\\<in>set prx.\n                     ((repa \\<propto> high) no1 = (repa \\<propto> high) no \\<and>\n                      (repa \\<propto> low) no1 = (repa \\<propto> low) no) =\n                     (repa no = repa no1)))\"\n  assume not_Leaf: \"\\<not> isLeaf_pt node low high\" \n  assume repchildren_eq_nln: \"repa (low node) = repa (high node)\"\n  show \"(\\<forall>no. no \\<notin> set (prx @ [node]) \\<longrightarrow>\n                rep no = (repa(node := repa (high node))) no) \\<and>\n        (\\<forall>no\\<in>set (prx @ [node]).\n              (repa(node := repa (high node))) no \\<noteq> Null \\<and>\n              (if (repa(node := repa (high node)) \\<propto> low) no =\n                  (repa(node := repa (high node)) \\<propto> high) no \\<and>\n                  low no \\<noteq> Null\n               then (repa(node := repa (high node))) no =\n                    (repa(node := repa (high node)) \\<propto> low) no\n               else (repa(node := repa (high node))) no =\n                    hd [sn\\<leftarrow>prx @ [node] .\n                        repNodes_eq sn no low high\n                         (repa(node := repa (high node)))] \\<and>\n                    (repa(node := repa (high node)))\n                     ((repa(node := repa (high node))) no) =\n                    (repa(node := repa (high node))) no \\<and>\n                    (\\<forall>no1\\<in>set (prx @ [node]).\n                        ((repa(node := repa (high node)) \\<propto> high) no1 =\n                         (repa(node := repa (high node)) \\<propto> high) no \\<and>\n                         (repa(node := repa (high node)) \\<propto> low) no1 =\n                         (repa(node := repa (high node)) \\<propto> low) no) =\n                        ((repa(node := repa (high node))) no =\n                         (repa(node := repa (high node))) no1))))\"\n    (is \"?NodesUnmodif \\<and> ?NodesModif\")\n  proof -\n    \\<comment> \\<open>This proof was originally conducted without the\n          substitution @{term \"repa (low node) = repa (high node)\"} preformed.\n          So don't be confused if we show everythin for @{text \"repa (low node)\"}.\\<close>\n    from rep_repa_nc\n    have nodes_unmodif: ?NodesUnmodif\n      by auto\n    hence rep_Sucna_nc:\n      \"(\\<forall>no. no \\<notin> set (prx @ [node]) \n      \\<longrightarrow> rep no = (repa(node := repa (low (node )))) no)\"\n      by auto\n    have nodes_modif: ?NodesModif (is \"\\<forall>no\\<in>set (prx @ [node]). ?P no \\<and> ?Q no\")\n    proof (rule ballI)\n      fix no\n      assume no_in_take_Sucna: \" no \\<in> set (prx @ [node])\"\n      show \"?P no \\<and> ?Q no\"\n      proof (cases \"no = node\")\n        case False\n        note no_noteq_nln=this\n        with no_in_take_Sucna \n        have no_in_take_n: \"no \\<in> set prx\"\n          by auto\n        with no_in_take_n while_inv obtain \n          repa_no_nNull: \" repa no \\<noteq> Null\" and\n          repa_cases: \"(if (repa \\<propto> low) no = (repa \\<propto> high) no \\<and> low no \\<noteq> Null \n          then repa no = (repa \\<propto> low) no\n          else  repa no = hd [sn\\<leftarrow>prx . repNodes_eq sn no low high repa] \n          \\<and> repa (repa no) = repa no \\<and> \n          (\\<forall>no1\\<in>set prx. ((repa \\<propto> high) no1 = (repa \\<propto> high) no \n          \\<and> (repa \\<propto> low) no1 = (repa \\<propto> low) no) \n          = (repa no = repa no1)))\"\n          using [[simp_depth_limit = 2]]\n          by auto \n        from no_in_take_n \n        have no_in_nodeslist: \"no \\<in> set (prx @ node # sfx)\"\n          by auto\n        from repa_no_nNull no_noteq_nln have ext_repa_nNull: \"?P no\"\n          by auto\n        from no_in_nodeslist nodes_balanced_ordered obtain\n          nln_nNull: \"node \\<noteq> Null\" and\n          nln_balanced_children: \"(low node = Null) = (high node = Null)\" and\n          lnln_notin_nodeslist: \"low node \\<notin> set (prx @ node # sfx)\" and\n          hnln_notin_nodeslist: \"high node \\<notin> set (prx @ node # sfx)\" and\n          isLeaf_var_nln: \"isLeaf_pt node low high = (var node \\<le> 1)\" and\n          node_nNull_rap_nNull_nln: \"(low node \\<noteq> Null \n          \\<longrightarrow> rep (low node) \\<noteq> Null)\" and\n          nln_varrep_le_var: \"(rep \\<propto> low) node \\<notin> set (prx @ node # sfx)\"\n          apply (erule_tac x=\"node\" in ballE)\n          apply auto\n          done\n        from  no_in_nodeslist nodes_balanced_ordered no_in_take_Sucna \n        obtain \n          no_nNull: \"no \\<noteq> Null\" and\n          balanced_children: \"(low no = Null) = (high no = Null)\" and\n          lno_notin_nodeslist: \"low no \\<notin> set (prx @ node # sfx)\" and\n          hno_notin_nodeslist: \"high no \\<notin> set (prx @ node # sfx)\" and\n          isLeaf_var_no: \"isLeaf_pt no low high = (var no \\<le> 1)\" and\n          node_nNull_rep_nNull: \"(low no \\<noteq> Null \\<longrightarrow> rep (low no) \\<noteq> Null)\" and\n          varrep_le_var: \"(rep \\<propto> low) no \\<notin> set (prx @ node # sfx)\"\n          apply -\n          apply (erule_tac x=no in ballE)\n          apply auto\n          done\n        from lno_notin_nodeslist  \n        have ext_rep_null_comp_low: \n          \"(repa (node := repa (low node)) \\<propto> low) no = (repa \\<propto> low) no\"\n          by (auto simp add: null_comp_def)\n        from hno_notin_nodeslist \n        have ext_rep_null_comp_high: \n          \"(repa (node := repa (low node)) \\<propto> high) no = (repa \\<propto> high) no\"\n          by (auto simp add: null_comp_def)\n        have share_reduce_if: \"?Q no\"\n        proof (cases \"(repa (node := repa (low node)) \\<propto> low) no = \n            (repa(node := repa (low node)) \\<propto> high) no \\<and> low no \\<noteq> Null\")\n          case True\n          then obtain \n            red_case: \"(repa (node := repa (low node)) \\<propto> low) no = \n            (repa(node := repa (low node)) \\<propto> high) no\" and\n            lno_nNull: \"low no \\<noteq> Null\"\n            by simp\n          from lno_nNull balanced_children have hno_nNull: \"high no \\<noteq> Null\"\n            by simp\n          from True ext_rep_null_comp_low ext_rep_null_comp_high \n          have repchildren_eq_no: \"(repa \\<propto> low) no = (repa \\<propto> high) no\"\n            by simp\n          with repa_cases lno_nNull have \"repa no = (repa \\<propto> low) no\"\n            by auto\n          with ext_rep_null_comp_low no_noteq_nln \n          have \"(repa(node := repa (low node))) no = \n            (repa (node := repa (low node)) \\<propto> low) no\"\n            by simp\n          with True repchildren_eq_nln show ?thesis\n            by auto\n        next\n          assume share_case_ext: \n            \" \\<not> ((repa(node := repa (low node)) \\<propto> low) no = \n            (repa(node := repa (low node)) \\<propto> high) no \\<and> low no \\<noteq> Null)\"\n          from not_Leaf isLeaf_var_nln \n          have \"1 < var node\"\n            by simp\n          with all_nodes_same_var \n          have all_nodes_nl_Suc0_l_var: \"\\<forall>x \\<in> set (prx @ node # sfx). 1 < var x\"\n            using [[simp_depth_limit=1]]\n            by auto\n          with nodes_balanced_ordered \n          have all_nodes_nl_noLeaf: \n            \"\\<forall>x \\<in> set (prx @ node # sfx). \\<not> isLeaf_pt x low high\"\n            apply -\n            apply rule\n            apply (drule_tac x=x in bspec,assumption)\n            apply (drule_tac x=x in bspec,assumption)\n            apply auto\n            done\n          from nodes_balanced_ordered \n          have all_nodes_nl_balanced: \n            \"\\<forall>x \\<in> set (prx @ node # sfx). (low x = Null) = (high x = Null)\"\n            apply -\n            apply rule\n            apply (drule_tac x=x in bspec,assumption)\n            apply auto\n            done\n          from all_nodes_nl_Suc0_l_var no_in_nodeslist \n          have Suc0_l_var_no: \"1 < var no\"\n            by auto\n          with isLeaf_var_no have no_nLeaf: \" \\<not> isLeaf_pt no low high\"\n            by simp\n          with balanced_children have lno_nNull: \"low no \\<noteq> Null\"\n            by (simp add: isLeaf_pt_def)\n          with balanced_children have hno_nNull: \"high no \\<noteq> Null\"\n            by simp\n          with share_case_ext ext_rep_null_comp_low ext_rep_null_comp_high lno_nNull \n          have repchildren_neq_no: \"(repa \\<propto> low) no \\<noteq> (repa \\<propto> high) no\"\n            by (simp add: null_comp_def)\n          with repa_cases \n          have share_case_inv: \n          \"repa no = hd [sn\\<leftarrow>prx . repNodes_eq sn no low high repa] \\<and> \n            repa (repa no) = repa no \\<and> \n            (\\<forall>no1\\<in>set prx. ((repa \\<propto> high) no1 = (repa \\<propto> high) no \\<and> \n            (repa \\<propto> low) no1 = (repa \\<propto> low) no) = (repa no = repa no1))\"\n            by auto\n          then have repa_no: \"repa no = hd [sn\\<leftarrow>prx . repNodes_eq sn no low high repa]\"\n            by simp\n          from Suc0_l_var_no have \"\\<forall>x \\<in> set (prx @ node # sfx). 1 < var no\"\n            by auto\n          from no_in_take_n have \"[sn\\<leftarrow>prx . repNodes_eq sn no low high repa] \\<noteq> []\"\n            apply -\n            apply (rule filter_not_empty)\n            apply (auto simp add: repNodes_eq_def)\n            done\n          then have \"repNodes_eq \n            (hd [sn\\<leftarrow>prx. repNodes_eq sn no low high repa]) no low high repa\"\n            by (rule hd_filter_prop)\n          with repa_no \n          have rep_children_eq_no_repa_no: \n            \"(repa \\<propto> low) (repa no) = (repa \\<propto> low) no \\<and> \n             (repa \\<propto> high) (repa no) = (repa \\<propto> high) no\"\n            by (simp add: repNodes_eq_def) \n          from lno_notin_nodeslist rep_repa_nc \n          have rep_repa_nc_low_no: \"rep (low no) = repa (low no)\"\n            apply -\n            apply (erule_tac x=\"low no\" in allE)\n            apply auto\n            done\n          have \"\\<forall>x \\<in> set (prx @ [node]). \n            repNodes_eq x no low high (repa(node := repa (low node))) = \n            repNodes_eq x no low high repa\"\n          proof (rule ballI, unfold repNodes_eq_def)\n            fix x\n            assume x_in_take_Sucn: \" x \\<in> set (prx @ [node])\"\n            hence x_in_nodeslist: \"x \\<in> set (prx @ node # sfx)\"\n              by auto\n            with all_nodes_nl_noLeaf nodes_balanced_ordered \n            have children_nNull_x: \"low x \\<noteq> Null \\<and> high x \\<noteq> Null\"\n              apply -\n              apply (drule_tac x=x in bspec,assumption)\n              apply (drule_tac x=x in bspec,assumption)\n              apply (auto simp add: isLeaf_pt_def) \n              done\n            from x_in_nodeslist nodes_balanced_ordered \n            have \"low x \\<notin> set (prx @ node # sfx) \\<and> high x \\<notin> set (prx @ node # sfx)\"\n              apply -\n              apply (drule_tac x=x in bspec,assumption)\n              apply auto\n              done\n            with lno_notin_nodeslist hno_notin_nodeslist \n              children_nNull_x lno_nNull hno_nNull\n            show \"((repa(node := repa (low node)) \\<propto> high) x = \n              (repa(node := repa (low node)) \\<propto> high) no \\<and>\n              (repa(node := repa (low node)) \\<propto> low) x = \n              (repa(node := repa (low node)) \\<propto> low) no) =\n              ((repa \\<propto> high) x = (repa \\<propto> high) no \\<and> \n              (repa \\<propto> low) x = (repa \\<propto> low) no)\"\n              by (simp add: null_comp_def)\n          qed\n          then have filter_extrep_rep: \n            \"[sn\\<leftarrow>(prx @ [node]). repNodes_eq sn no low high \n                                   (repa(node := repa (low node)))] = \n            [sn\\<leftarrow>(prx @ [node]) . repNodes_eq sn no low high repa]\"\n            by (rule P_eq_list_filter)\n          from no_in_take_n \n          have filter_n_notempty: \"[sn\\<leftarrow>prx. repNodes_eq sn no low high repa] \\<noteq> []\"\n            apply (rule filter_not_empty)\n            apply (simp add: repNodes_eq_def)\n            done\n          then have \"hd [sn\\<leftarrow>prx. repNodes_eq sn no low high repa] = \n            hd [sn\\<leftarrow>prx@[node]. repNodes_eq sn no low high repa]\"\n            by auto\n          with no_noteq_nln filter_extrep_rep repa_no \n          have ext_repa_no: \"(repa(node:= repa (low node))) no = \n            hd [sn\\<leftarrow>prx@[node] . repNodes_eq sn no low high \n            (repa(node := repa (low node)))]\"\n            by simp\n          have \"(repa(node := repa (low node))) (repa no) = repa no\"\n          proof (cases \"repa no =  node\")\n            case True\n            note rno_nln=this\n            from rep_repa_nc_low_no rep_children_eq_no_repa_no lno_nNull \n              node_nNull_rep_nNull \n            have low_rep_no_nNull: \"low (repa no) \\<noteq> Null\"\n              apply (simp add: null_comp_def)\n              apply auto\n              done\n            with nodes_balanced_ordered rno_nln \n            have high_rap_no_nNull: \"high (repa no) \\<noteq> Null\"\n              apply -\n              apply (drule_tac x=\"repa no\" in bspec)\n              apply auto\n              done\n            with low_rep_no_nNull rno_nln rep_children_eq_no_repa_no \n            have \"repa (low node) = (repa \\<propto> low) no \\<and> \n              repa (high node) = (repa \\<propto> high) no\" \n              by (simp add: null_comp_def)\n            with repchildren_eq_nln have \" (repa \\<propto> low) no = (repa \\<propto> high) no\"\n              by simp\n            with repchildren_neq_no show ?thesis\n              by simp\n          next\n            assume rno_not_nln: \"repa no \\<noteq> node\"\n            from share_case_inv have \"repa (repa no) = repa no\"\n              by auto\n            with rno_not_nln show ?thesis\n              by simp\n          qed\n          with no_noteq_nln have ext_repa_ext_repa: \n            \"(repa(node := repa (low node))) \n            ((repa(node := repa (low node))) no) \n            = (repa(node := repa (low node))) no\" \n            by simp\n          have \"(\\<forall>no1\\<in>set (prx@[node]).\n            ((repa(node := repa (low node)) \\<propto> high) no1 = \n            (repa(node  := repa (low node)) \\<propto> high) no \\<and>\n            (repa(node  := repa (low node)) \\<propto> low) no1 = \n            (repa(node  := repa (low node)) \\<propto> low) no) =\n            ((repa(node  := repa (low node))) no = \n            (repa(node  := repa (low node))) no1))\"\n          proof (rule ballI)\n            fix no1\n            assume no1_in_take_Sucn: \" no1 \\<in> set (prx@[node])\"\n            hence no1_in_nodeslist: \"no1 \\<in> set (prx @ node # sfx)\"\n              by auto\n            show \"((repa(node := repa (low node)) \\<propto> high) no1 = \n                 (repa(node := repa (low node)) \\<propto> high) no \\<and>\n                 (repa(node := repa (low node)) \\<propto> low) no1 = \n                 (repa(node := repa (low node)) \\<propto> low) no) =\n                 ((repa(node := repa (low node))) no = \n                  (repa(node := repa (low node))) no1)\"\n            proof (cases \"no1 = node\")\n              case True\n              show ?thesis\n              proof (rule, elim conjE)\n                assume ext_repa_no_no1: \n                  \"(repa(node := repa (low node))) no = \n                    (repa(node := repa (low node))) no1\"\n                with True no_noteq_nln \n                have repa_no_repa_low_nln: \"repa no = repa (low node)\"\n                  by simp\n                from filter_n_notempty \n                have repa_no_in_take_n:  \n                  \"hd [sn\\<leftarrow>prx. repNodes_eq sn no low high repa] \n                    \\<in> set prx \"\n                  apply -\n                  apply (rule hd_filter_in_list)\n                  apply auto\n                  done\n                with repa_no \n                have repa_no_in_nodeslist: \"repa no \\<in> set (prx @ node # sfx)\"\n                  by auto\n                from lnln_notin_nodeslist rep_repa_nc \n                have rep_repa_low_nln: \"rep (low node) = repa (low node)\"\n                  by auto\n                from all_nodes_nl_noLeaf nln_balanced_children\n                have \"low node \\<noteq> Null\"\n                  by (auto simp add: isLeaf_pt_def)\n                with rep_repa_low_nln lnln_notin_nodeslist lno_nNull \n                  nln_varrep_le_var \n                have \"repa (low node) \\<notin> set (prx @ node # sfx)\"\n                  by (simp add: null_comp_def) \n                with repa_no_repa_low_nln repa_no_in_nodeslist \n                show \"(repa(node := repa (low node)) \\<propto> high) no1 = \n                  (repa(node := repa (low node)) \\<propto> high) no \\<and>\n                  (repa(node := repa (low node)) \\<propto> low) no1 = \n                  (repa(node := repa (low node)) \\<propto> low) no\"\n                  by simp\n              next\n                assume no_no1_high: \n                  \"(repa(node := repa (low node)) \\<propto> high) no1 = \n                  (repa(node := repa (low node)) \\<propto> high) no\"\n                assume no_no1_low: \n                  \"(repa(node := repa (low node)) \\<propto> low) no1 = \n                  (repa(node := repa (low node)) \\<propto> low) no\"\n                from True repchildren_eq_nln \n                have repachildren_eq_no1: \" repa (low no1) = repa (high no1)\"\n                  by simp\n                from not_Leaf True nln_balanced_children \n                have children_nNull_no1: \"(low no1) \\<noteq> Null \\<and> high no1 \\<noteq> Null\"\n                  by (simp add: isLeaf_pt_def)\n                with repachildren_eq_no1 \n                have repchildren_eq_no1: \"(repa \\<propto> low) no1 = (repa \\<propto> high) no1\"\n                  by (simp add: null_comp_def)\n                from no_no1_low children_nNull_no1 lno_nNull \n                  lnln_notin_nodeslist lno_notin_nodeslist True \n                have rep_low_eq_no_no1: \"(repa \\<propto> low) no1 = (repa \\<propto> low) no\"\n                  by (simp add: null_comp_def)\n                from no_no1_high children_nNull_no1 hno_nNull \n                  hnln_notin_nodeslist hno_notin_nodeslist True \n                have rep_high_eq_no_no1: \"(repa \\<propto> high) no1 = (repa \\<propto> high) no\"\n                  by (simp add: null_comp_def)\n                with rep_low_eq_no_no1 repchildren_eq_no1 \n                have \"(repa \\<propto> low) no = (repa \\<propto> high) no\"\n                  by simp\n                with repchildren_neq_no \n                show \"(repa(node := repa (low node))) no = \n                  (repa(node := repa (low node))) no1\"\n                  by simp\n              qed\n            next\n              assume no1_neq_nln: \"no1 \\<noteq> node\"\n              from no1_in_nodeslist nodes_balanced_ordered \n              have children_notin_nl_no1: \n              \"low no1 \\<notin> set (prx @ node # sfx) \\<and> high no1 \\<notin> set (prx @ node # sfx)\"\n                apply -\n                apply (drule_tac x=no1 in bspec,assumption)\n                by auto\n              from no1_neq_nln no1_in_take_Sucn \n              have no1_in_take_n: \"no1 \\<in> set prx\"\n                by auto\n              from no1_in_nodeslist all_nodes_nl_noLeaf all_nodes_nl_balanced \n              have children_nNull_no1: \"(low no1) \\<noteq> Null \\<and> high no1 \\<noteq> Null\"\n                by  (auto simp add: isLeaf_pt_def)\n              show ?thesis\n              proof (rule, elim conjE)\n                assume ext_repa_high_no1_no: \n                \"(repa(node := repa (low node)) \\<propto> high) no1 \n                  = (repa(node := repa (low node)) \\<propto> high) no\" \n                assume ext_repa_low_no1_no: \n                  \"(repa(node := repa (low node)) \\<propto> low) no1 \n                  = (repa(node := repa (low node)) \\<propto> low) no\"\n                from children_nNull_no1 hno_nNull ext_repa_high_no1_no \n                  children_notin_nl_no1 \n                  hno_notin_nodeslist \n                have repa_high_no1_no: \"(repa \\<propto> high) no1 = (repa \\<propto> high) no\"\n                  by (simp add: null_comp_def)\n                from children_nNull_no1 lno_nNull ext_repa_low_no1_no \n                  children_notin_nl_no1 lno_notin_nodeslist \n                have repa_low_no1_no: \"(repa \\<propto> low) no1 = (repa \\<propto> low) no\"\n                  by (simp add: null_comp_def)\n                from repchildren_neq_no repa_high_no1_no repa_low_no1_no \n                have \"(repa \\<propto> low) no1 \\<noteq> (repa \\<propto> high) no1\"\n                  by simp\n                from no1_in_take_n share_case_inv repa_high_no1_no repa_low_no1_no \n                have \"repa no = repa no1\"\n                  by auto\n                with no_noteq_nln no1_neq_nln \n                show \" (repa(node := repa (low node))) no = \n                  (repa(node := repa (low node))) no1\"\n                  by simp\n              next\n                assume \"(repa(node := repa (low node))) no = \n                  (repa(node := repa (low node))) no1\"\n                with no_noteq_nln no1_neq_nln \n                have \"repa no = repa no1\"\n                  by simp\n                with share_case_inv no1_in_take_n \n                have \"((repa \\<propto> high) no1 = (repa \\<propto> high) no \\<and> \n                  (repa \\<propto> low) no1 = (repa \\<propto> low) no)\"\n                  by auto\n                with children_notin_nl_no1 children_nNull_no1 lno_notin_nodeslist \n                  hno_notin_nodeslist lno_nNull hno_nNull \n                show \"(repa(node := repa (low node)) \\<propto> high) no1 = \n                (repa(node := repa (low node)) \\<propto> high) no \\<and>\n                (repa(node := repa (low node)) \\<propto> low) no1 = \n                (repa(node := repa (low node)) \\<propto> low) no\"\n                  by (auto simp add: null_comp_def)\n              qed \n            qed\n          qed\n          from ext_repa_ext_repa ext_repa_no share_case_ext repchildren_eq_nln this \n          show ?thesis\n            using [[simp_depth_limit=4]]\n            by auto \n        qed\n        with ext_repa_nNull show ?thesis\n          by auto\n      next\n        assume no_nln: \"no = node\"\n        hence no_in_nodeslist: \"no \\<in> set (prx @ node # sfx)\"\n          by simp\n        from no_nln not_Leaf no_in_nodeslist \n          nodes_balanced_ordered [rule_format, OF this] obtain  \n          low_no_nNull: \"low no \\<noteq> Null\" and\n          high_no_nNull: \"high no \\<noteq> Null\" and\n          rep_low_no_nNull: \"rep (low no) \\<noteq> Null\" and\n          lno_notin_nl: \"low no \\<notin> set (prx @ node # sfx)\" and\n          hno_notin_nl: \"high no \\<notin> set (prx @ node # sfx)\" and\n          children_nNull_no: \"(low no \\<noteq> Null) \\<and> (high no \\<noteq> Null)\"\n          apply (unfold isLeaf_pt_def)\n          apply blast\n          done\n        then have \"low no \\<notin> set prx\"\n          by auto\n        with rep_repa_nc no_nln rep_low_no_nNull \n        have \"(repa(node := repa (low node))) no \\<noteq> Null\"\n          by simp\n        moreover\n        have \"(if (repa(node := repa (low node)) \\<propto> low) no = \n                  (repa(node := repa (low node)) \\<propto> high) no \\<and> low no \\<noteq> Null\n          then (repa(node := repa (low node))) no = \n               (repa(node := repa (low node)) \\<propto> low) no\n          else (repa(node := repa (low node))) no =\n            hd [sn\\<leftarrow>prx@[node]. repNodes_eq sn no low high \n                (repa(node := repa (low node)))] \\<and>\n          (repa(node := repa (low node))) \n            ((repa(node := repa (low node))) no) =\n            (repa(node := repa (low node))) no \\<and>\n          (\\<forall>no1\\<in>set (prx@[node]).\n            ((repa(node := repa (low node)) \\<propto> high) no1 = \n            (repa(node := repa (low node)) \\<propto> high) no \\<and>\n            (repa(node := repa (low node)) \\<propto> low) no1 = \n            (repa(node := repa (low node)) \\<propto> low) no) =\n            ((repa(node := repa (low node))) no = \n            (repa(node := repa (low node))) no1)))\"\n        proof (cases \"(repa(node := repa (low node)) \\<propto> low) no = \n          (repa(node := repa (low node)) \\<propto> high) no \\<and> low no \\<noteq> Null\")\n          case True\n          note red_case=this\n          with children_nNull_no lno_notin_nl hno_notin_nl \n          have \"(repa \\<propto> low) no = (repa \\<propto> high) no\"\n            by (auto simp add: null_comp_def)\n          from children_nNull_no lno_notin_nl \n          have ext_repa_eq_repa_low: \"(repa(node := repa (low node)) \\<propto> low) no \n            = (repa \\<propto> low) no \"\n            by (auto simp add: null_comp_def)\n          from children_nNull_no hno_notin_nl \n          have ext_repa_eq_repa_high: \n            \"(repa(node := repa (low node)) \\<propto> high) no \n            = (repa \\<propto> high) no \"\n            by (auto simp add: null_comp_def)\n          from no_nln children_nNull_no \n          have \"repa (low node) = (repa \\<propto> low) no\"\n            by (simp add: null_comp_def)\n          with red_case ext_repa_eq_repa_high ext_repa_eq_repa_low no_nln \n          show ?thesis \n            using [[simp_depth_limit=2]]\n            by (auto simp del: null_comp_not_Null)\n        next\n          assume share_case: \" \\<not> ((repa(node := repa (low node)) \\<propto> low) no \n            = (repa(node := repa (low node)) \\<propto> high) no \\<and> low no \\<noteq> Null)\"\n          with low_no_nNull have \"(repa(node := repa (low node)) \\<propto> low) no \n            \\<noteq> (repa(node := repa (low node)) \\<propto> high) no\"\n            by simp\n          with children_nNull_no lno_notin_nl hno_notin_nl \n          have \"(repa \\<propto> low) no \\<noteq> (repa \\<propto> high) no\"\n            by (auto simp add: null_comp_def)\n          with children_nNull_no have \"repa (low no) \\<noteq> repa (high no)\"\n            by (simp add: null_comp_def)\n          with repchildren_eq_nln no_nln show ?thesis\n            by simp\n        qed\n        ultimately show ?thesis\n          using repchildren_eq_nln\n          apply -\n          apply (simp only:)\n          apply (simp (no_asm))\n          done\n      qed\n    qed\n    from nodes_unmodif nodes_modif\n    show ?thesis by iprover\n  qed\nnext\n  fix var low high rep nodeslist repa \"next\" node prx sfx repb\n  assume ns: \"List nodeslist next (prx @ node # sfx)\"\n  assume sfx: \"List (next node) next sfx\"\n  assume nodes_balanced_ordered: \"\\<forall>no\\<in>set (prx @ node # sfx).\n           no \\<noteq> Null \\<and>\n           (low no = Null) = (high no = Null) \\<and>\n           low no \\<notin> set (prx @ node # sfx) \\<and>\n           high no \\<notin> set (prx @ node # sfx) \\<and>\n           isLeaf_pt no low high = (var no \\<le> (1::nat)) \\<and>\n           (low no \\<noteq> Null \\<longrightarrow> rep (low no) \\<noteq> Null) \\<and>\n           (rep \\<propto> low) no \\<notin> set (prx @ node # sfx)\"\n  assume all_nodes_same_var: \"\\<forall>no1\\<in>set (prx @ node # sfx).\n           \\<forall>no2\\<in>set (prx @ node # sfx). var no1 = var no2\"\n  assume rep_repa_nc: \"\\<forall>no. no \\<notin> set prx \\<longrightarrow> rep no = repa no\"\n  assume while_inv: \"\\<forall>no\\<in>set prx.\n           repa no \\<noteq> Null \\<and>\n           (if (repa \\<propto> low) no = (repa \\<propto> high) no \\<and> low no \\<noteq> Null\n            then repa no = (repa \\<propto> low) no\n            else repa no = hd [sn\\<leftarrow>prx . repNodes_eq sn no low high repa] \\<and>\n                 repa (repa no) = repa no \\<and>\n                 (\\<forall>no1\\<in>set prx.\n                     ((repa \\<propto> high) no1 = (repa \\<propto> high) no \\<and>\n                      (repa \\<propto> low) no1 = (repa \\<propto> low) no) =\n                     (repa no = repa no1)))\"\n  assume share_cond: \n    \"\\<not> (\\<not> isLeaf_pt node low high \\<and> repa (low node) = repa (high node))\"\n  assume repb_node: \n          \"repb node = hd [sn\\<leftarrow>prx @ node # sfx . repNodes_eq sn node low high repa]\"\n  assume repa_repb_nc: \"\\<forall>pt. pt \\<noteq> node \\<longrightarrow> repa pt = repb pt\" \n  assume var_repb_node: \"var (repb node) = var node\"\n  show \"(\\<forall>no. no \\<notin> set (prx @ [node]) \\<longrightarrow> rep no = repb no) \\<and>\n          (\\<forall>no\\<in>set (prx @ [node]).\n              repb no \\<noteq> Null \\<and>\n              (if (repb \\<propto> low) no = (repb \\<propto> high) no \\<and> low no \\<noteq> Null\n               then repb no = (repb \\<propto> low) no\n               else repb no =\n                    hd [sn\\<leftarrow>prx @ [node] . repNodes_eq sn no low high repb] \\<and>\n                    repb (repb no) = repb no \\<and>\n                    (\\<forall>no1\\<in>set (prx @ [node]).\n                        ((repb \\<propto> high) no1 = (repb \\<propto> high) no \\<and>\n                         (repb \\<propto> low) no1 = (repb \\<propto> low) no) =\n                        (repb no = repb no1))))\"\n  proof -\n    have rep_repb_nc: \"(\\<forall>no. no \\<notin> set (prx @ [node]) \\<longrightarrow> rep no = repb no)\"\n    proof (intro allI impI)\n      fix no\n      assume no_notin_take_Sucn: \"no \\<notin> set (prx @ [node])\"\n      with rep_repa_nc \n      have rep_repa_nc_Sucn: \"rep no = repa no\"\n        by auto\n      from no_notin_take_Sucn have \"no \\<noteq> node\"\n        by auto\n      with repa_repb_nc have \"repa no = repb no\"\n        by auto\n      with rep_repa_nc_Sucn show \"rep no = repb no\"\n        by simp\n    qed\n    moreover\n    have repb_no_share_def: \n      \"(\\<forall>no\\<in>set (prx @ [node]). \n      \\<not> ((repb \\<propto> low) no = (repb \\<propto> high) no \\<and> low no \\<noteq> Null) \\<longrightarrow> \n          repb no = hd [sn\\<leftarrow>(prx @ [node]) . repNodes_eq sn no low high repb])\" \n    proof (intro ballI impI)\n      fix no\n      assume no_in_take_Sucn: \" no \\<in> set (prx @ [node])\"\n      assume share_prop: \"\\<not> ((repb \\<propto> low) no = (repb \\<propto> high) no \\<and> low no \\<noteq> Null)\"\n      from share_prop have share_or: \n        \"(repb \\<propto> low) no \\<noteq> (repb \\<propto> high) no \\<or> low no = Null\"\n        using [[simp_depth_limit=2]]\n        by simp\n      from no_in_take_Sucn have no_in_nl: \"no \\<in> set (prx @ node # sfx)\"\n        by auto\n      from nodes_balanced_ordered [rule_format, OF this] obtain\n        no_nNull: \"no \\<noteq> Null\" and\n        balanced_no: \"(low no = Null) = (high no = Null)\" and\n        lno_notin_nl: \"low no \\<notin> set (prx @ node # sfx)\" and\n        hno_notin_nl: \"high no \\<notin> set (prx @ node # sfx)\" and\n        isLeaf_var_no: \"isLeaf_pt no low high = (var no \\<le> 1)\"\n        by auto\n      have nodes_notin_nl_neq_nln: \"\\<forall>p. p \\<notin> set (prx @ node # sfx) \\<longrightarrow> p \\<noteq> node \"\n        by auto \n      show \" repb no = hd [sn\\<leftarrow>(prx @ [node]). repNodes_eq sn no low high repb]\"\n      proof (cases \"no = node\")\n        case False\n        note no_notin_nl=this\n        with no_in_take_Sucn have no_in_take_n: \"no \\<in> set prx\"\n          by auto\n        from False repa_repb_nc have repb_repa_no: \"repb no = repa no\" \n          by auto\n        with while_inv [rule_format, OF no_in_take_n] no_in_take_n obtain \n          repa_no_nNull: \"repa no \\<noteq> Null\" and\n          while_share_red_exp: \n          \"(if (repa \\<propto> low) no = (repa \\<propto> high) no \\<and> low no \\<noteq> Null \n              then repa no = (repa \\<propto> low) no\n              else repa no = hd [sn\\<leftarrow>prx . repNodes_eq sn no low high repa] \\<and>\n              repa (repa no) = repa no \\<and> \n              (\\<forall>no1\\<in>set prx. ((repa \\<propto> high) no1 = (repa \\<propto> high) no \\<and> \n              (repa \\<propto> low) no1 = (repa \\<propto> low) no) = (repa no = repa no1)))\"\n          using [[simp_depth_limit = 2]]\n          by auto \n        from no_in_take_n \n        have filter_take_n_notempty: \"[sn\\<leftarrow>prx. \n          repNodes_eq sn no low high repa] \\<noteq> []\"\n          apply -\n          apply (rule filter_not_empty)\n          apply (auto simp add: repNodes_eq_def)\n          done\n        then have hd_term_n_Sucn: \n          \"hd [sn\\<leftarrow>prx. repNodes_eq sn no low high repa] \n              = hd [sn\\<leftarrow>prx@[node] . repNodes_eq sn no low high repa]\"\n          by auto\n        thus ?thesis\n        proof (cases \"low no = Null\")\n          case True\n          note lno_Null=this\n          with balanced_no have hno_Null: \"high no = Null\" \n            by simp\n          from lno_Null hno_Null have isLeaf_no: \"isLeaf_pt no low high\"\n            by (simp add: isLeaf_pt_def)\n          from True while_share_red_exp \n          have while_low_Null: \n            \"repa no = hd [sn\\<leftarrow>prx. repNodes_eq sn no low high repa] \\<and>\n             repa (repa no) = repa no \\<and> \n             (\\<forall>no1\\<in>set prx. ((repa \\<propto> high) no1 = (repa \\<propto> high) no \n             \\<and> (repa \\<propto> low) no1 = (repa \\<propto> low) no) = (repa no = repa no1))\"\n            by auto\n          have all_nodes_in_nl_Leafs: \n            \"\\<forall>x \\<in> set (prx @ node # sfx). isLeaf_pt x low high\"\n          proof (intro ballI)\n            fix x\n            assume x_in_nodeslist: \"x \\<in> set (prx @ node # sfx)\"\n            from isLeaf_no isLeaf_var_no have \"var no \\<le> 1\"\n              by simp\n            with all_nodes_same_var [rule_format, OF x_in_nodeslist no_in_nl]\n            have \"var x \\<le> 1\"\n              by simp\n            with nodes_balanced_ordered [rule_format, OF x_in_nodeslist]\n            show \"isLeaf_pt x low high\"\n              by (auto simp add: isLeaf_pt_def)  \n          qed\n          have \"\\<forall> x \\<in> set (prx@[node]). repNodes_eq x no low high repb \n                = repNodes_eq x no low high repa\"\n          proof (rule ballI)\n            fix x\n            assume x_in_take_Sucn: \"x \\<in> set (prx@[node])\"\n            hence x_in_nodeslist: \"x \\<in> set (prx @ node # sfx)\"\n              by auto\n            with all_nodes_in_nl_Leafs have \"isLeaf_pt x low high\"\n              by auto\n            with isLeaf_no repa_repb_nc show \"repNodes_eq x no low high repb \n                  = repNodes_eq x no low high repa\"\n              by (simp add: repNodes_eq_def null_comp_def isLeaf_pt_def)\n          qed\n          then have \" [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repa] \n                = [sn\\<leftarrow>(prx@[node]) . repNodes_eq sn no low high repb]\"\n            apply -\n            apply (rule P_eq_list_filter)\n            apply simp\n            done\n          with hd_term_n_Sucn while_low_Null repb_repa_no show ?thesis \n            by auto\n        next\n          assume lno_nNull: \" low no \\<noteq> Null\"\n          with balanced_no have hno_nNull: \"high no \\<noteq> Null\"\n            by simp\n          with lno_nNull have no_nLeaf: \"\\<not> isLeaf_pt no low high\"\n            by (simp add: isLeaf_pt_def)\n          with isLeaf_var_no have Sucn_s_varno: \"1 < var no\"\n            by auto\n          with no_in_nl all_nodes_same_var \n          have all_nodes_nl_var: \"\\<forall> x \\<in> set (prx @ node # sfx). 1 < var x\"\n            apply -\n            apply (rule ballI)\n            apply (drule_tac x=no in bspec,assumption)\n            apply (drule_tac x=x in bspec,assumption)\n            apply auto\n            done\n          with nodes_balanced_ordered \n          have all_nodes_nl_nLeaf: \n            \"\\<forall>x \\<in> set (prx @ node # sfx). \\<not> isLeaf_pt x low high\"\n            apply -\n            apply (rule ballI)\n            apply (drule_tac x=x in bspec,assumption)\n            apply (drule_tac x=x in bspec,assumption)\n            apply auto\n            done\n          from lno_nNull share_or \n          have repbchildren_eq_no: \"(repb \\<propto> low) no \\<noteq> (repb \\<propto> high) no\"\n            by simp\n          with lno_nNull hno_nNull lno_notin_nl hno_notin_nl repa_repb_nc  \n            nodes_notin_nl_neq_nln \n          have repachildren_eq_no: \"(repa \\<propto> low) no \\<noteq> (repa \\<propto> high) no\"\n            using [[simp_depth_limit=2]]\n            by (simp add: null_comp_def) \n          with while_share_red_exp \n          have repa_no_def: \n            \"repa no = hd [sn\\<leftarrow>prx . repNodes_eq sn no low high repa] \"\n            by auto\n          with no_notin_nl repa_repb_nc \n          have \"repb no =  hd [sn\\<leftarrow>prx. repNodes_eq sn no low high repa] \"\n            by simp\n          with hd_term_n_Sucn \n          have repb_no_hd_term_repa: \"repb no = \n                 hd [sn\\<leftarrow>prx@[node] . repNodes_eq sn no low high repa] \"\n            by simp\n          have \"\\<forall>x \\<in> set (prx@[node]). \n            repNodes_eq x no low high repa = repNodes_eq x no low high repb\" \n          proof (intro ballI)\n            fix x\n            assume x_in_take_Sucn: \"x \\<in> set (prx@[node]) \"\n            hence x_in_nodeslist: \"x \\<in> set (prx @ node # sfx)\"\n              by auto\n            with all_nodes_nl_nLeaf have x_nLeaf: \"\\<not> isLeaf_pt x low high\"\n              by auto\n            from nodes_balanced_ordered [rule_format, OF x_in_nodeslist] obtain\n              balanced_x: \"(low x = Null) = (high x = Null)\" and\n              lx_notin_nl: \"low x \\<notin> set (prx @ node # sfx)\" and\n              hx_notin_nl: \"high x \\<notin> set (prx @ node # sfx)\" \n              by auto\n            with nodes_notin_nl_neq_nln lno_notin_nl hno_notin_nl lno_nNull \n              hno_nNull repa_repb_nc \n            show \" repNodes_eq x no low high repa = repNodes_eq x no low high repb\"\n              by (simp add: repNodes_eq_def null_comp_def)\n          qed\n          then have \" [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repa] = \n            [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb]\"\n            apply -\n            apply (rule P_eq_list_filter)\n            apply auto\n            done\n          with repb_no_hd_term_repa show ?thesis\n            by simp\n        qed\n      next \n        assume no_nln: \"no = node\"\n        with repb_node have repb_no_def: \"repb no = \n          hd [sn\\<leftarrow>(prx @ node # sfx). repNodes_eq sn node low high repa]\" \n          by simp\n        show ?thesis\n        proof (cases \"isLeaf_pt no low high\")\n          case True\n          note isLeaf_no=this\n          have \"\\<forall>x \\<in> set (prx @ node # sfx). repNodes_eq x no low high repb \n            = repNodes_eq x no low high repa\"\n          proof (rule ballI)\n            fix x\n            assume x_in_nodeslist: \"x \\<in> set (prx @ node # sfx)\"\n            have all_nodes_in_nl_Leafs: \n              \"\\<forall>x \\<in> set (prx @ node # sfx). isLeaf_pt x low high\"\n            proof (intro ballI)\n              fix x\n              assume x_in_nodeslist: \" x \\<in> set (prx @ node # sfx)\"\n              from isLeaf_no isLeaf_var_no have \"var no \\<le> 1\"\n                by simp\n              with all_nodes_same_var [rule_format, OF x_in_nodeslist no_in_nl]\n              have \"var x \\<le> 1\"\n                by simp\n              with nodes_balanced_ordered [rule_format, OF x_in_nodeslist]\n              show \"isLeaf_pt x low high\"\n                by (auto simp add: isLeaf_pt_def)\n            qed\n            with x_in_nodeslist have \"isLeaf_pt x low high\"\n              by auto\n            with isLeaf_no repa_repb_nc \n            show \"repNodes_eq x no low high repb = repNodes_eq x no low high repa\"\n              by (simp add: repNodes_eq_def null_comp_def isLeaf_pt_def)\n          qed\n          with repb_no_def no_nln have repb_no_whole_nl: \"repb no = \n            hd [sn\\<leftarrow> (prx @ node # sfx). repNodes_eq sn node low high repb]\"\n            apply -\n            apply (subgoal_tac \n              \"[sn\\<leftarrow> (prx@node#sfx). repNodes_eq sn node low high repa] \n              = [sn\\<leftarrow>(prx @ node # sfx) . repNodes_eq sn node low high repb]\")\n            apply simp\n            apply (rule P_eq_list_filter)\n            apply auto\n            done\n          from no_in_take_Sucn no_nln \n          have \"[sn\\<leftarrow> (prx@[node]). repNodes_eq sn node low high repb]  \\<noteq> []\"\n            apply -\n            apply (rule filter_not_empty)\n            apply (auto simp add: repNodes_eq_def)\n            done\n          then\n          have \"hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn node low high repb] = \n                hd [sn\\<leftarrow>(prx @ node # sfx). repNodes_eq sn node low high repb]\"\n            apply -\n            apply (rule hd_filter_app [symmetric])\n            apply auto\n            done\n          with repb_no_whole_nl no_nln show ?thesis\n            by simp         \n        next\n          assume no_nLeaf: \" \\<not> isLeaf_pt no low high\"\n          with share_or balanced_no have \"(repb \\<propto> low) no \\<noteq> (repb \\<propto> high) no\"\n            using [[simp_depth_limit=2]]\n            by (simp add: isLeaf_pt_def)\n          from no_nLeaf share_cond no_nln have \"repa (low no) \\<noteq> repa (high no)\"\n            by auto\n          with no_nLeaf balanced_no have \"(repa \\<propto> low) no \\<noteq> (repa \\<propto> high) no \"\n            by (simp add: null_comp_def isLeaf_pt_def)\n          have \"\\<forall> x \\<in> set (prx@node#sfx). repNodes_eq x no low high repb \n            = repNodes_eq x no low high repa\"\n          proof (rule ballI)\n            fix x\n            assume x_in_nodeslist: \" x \\<in> set (prx@node#sfx)\"\n            have all_nodes_in_nl_Leafs: \n              \"\\<forall>x \\<in> set (prx@node#sfx). \\<not> isLeaf_pt x low high\"\n            proof (intro ballI)\n              fix x\n              assume x_in_nodeslist: \" x \\<in> set (prx@node#sfx)\"\n              from no_nLeaf isLeaf_var_no have \"1 < var no \"\n                by simp\n              with all_nodes_same_var [rule_format, OF x_in_nodeslist no_in_nl]\n              have \"1 < var x\" \n                by auto\n              with nodes_balanced_ordered [rule_format, OF x_in_nodeslist]\n              show \"\\<not> isLeaf_pt x low high\"\n                apply (unfold isLeaf_pt_def)\n                apply fastforce\n                done\n            qed\n            with x_in_nodeslist have x_nLeaf: \"\\<not> isLeaf_pt x low high\"\n              by auto\n            from nodes_balanced_ordered [rule_format, OF x_in_nodeslist]\n            have \"(low x = Null) = (high x = Null) \n                  \\<and> low x \\<notin> set (prx@node#sfx) \\<and> high x \\<notin> set (prx@node#sfx)\"\n              by auto\n            with x_nLeaf balanced_no no_nLeaf repa_repb_nc \n              nodes_notin_nl_neq_nln lno_notin_nl hno_notin_nl\n            show \"repNodes_eq x no low high repb = repNodes_eq x no low high repa\"\n              using [[simp_depth_limit=2]]\n              by (simp add: repNodes_eq_def null_comp_def isLeaf_pt_def)\n          qed\n          with repb_no_def no_nln \n          have repb_no_whole_nl: \n            \"repb no = hd [sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn node low high repb]\"\n            apply -\n            apply (subgoal_tac \n                  \"[sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn node low high repa] \n                  = [sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn node low high repb]\")\n            apply simp\n            apply (rule P_eq_list_filter)\n            apply auto\n            done\n          from no_in_take_Sucn no_nln \n          have \"[sn\\<leftarrow>(prx@[node]) . repNodes_eq sn node low high repb]  \\<noteq> []\"\n            apply -\n            apply (rule filter_not_empty)\n            apply (auto simp add: repNodes_eq_def)\n            done\n          then have \n            \"hd [sn\\<leftarrow> (prx@[node]) . repNodes_eq sn node low high repb] = \n            hd [sn\\<leftarrow>(prx@node#sfx) . repNodes_eq sn node low high repb]\"\n            apply -\n            apply (rule hd_filter_app [symmetric])\n            apply auto\n            done\n          with repb_no_whole_nl no_nln show ?thesis\n            by simp        \n        qed\n      qed\n    qed\n    have repb_no_red_def: \"(\\<forall>no\\<in>set (prx@[node]).(repb \\<propto> low) no = (repb \\<propto> high) no \n      \\<and> low no \\<noteq> Null \\<longrightarrow>  repb no = (repb \\<propto> low) no)\" \n    proof (intro ballI impI)\n      fix no\n      assume no_in_take_Sucn: \"no \\<in> set (prx@[node])\"\n      assume red_cond_no: \" (repb \\<propto> low) no = (repb \\<propto> high) no \\<and> low no \\<noteq> Null\"\n      from no_in_take_Sucn have no_in_nl: \"no \\<in> set (prx@node#sfx)\"\n        by auto\n      from nodes_balanced_ordered [rule_format, OF this]obtain\n        no_nNull: \"no \\<noteq> Null\" and\n        balanced_no: \"(low no = Null) = (high no = Null)\" and\n        lno_notin_nl: \"low no \\<notin> set (prx@node#sfx)\" and\n        hno_notin_nl: \"high no \\<notin> set (prx@node#sfx)\" and\n        isLeaf_var_no: \"isLeaf_pt no low high = (var no \\<le> 1)\"\n        by auto\n      have nodes_notin_nl_neq_nln: \"\\<forall> p. p \\<notin> set (prx@node#sfx) \\<longrightarrow> p \\<noteq> node\"\n        by auto\n      show \" repb no = (repb \\<propto> low) no\"\n      proof (cases \"no = node\")\n        case False\n        note no_notin_nl=this\n        with no_in_take_Sucn have no_in_take_n: \"no \\<in> set prx\"\n          by auto\n        from False repa_repb_nc have repb_repa_no: \"repb no = repa no\" \n          by auto\n        with while_inv [rule_format, OF no_in_take_n] obtain \n          repa_no_nNull: \"repa no \\<noteq> Null\" and\n          while_share_red_exp: \n          \"(if (repa \\<propto> low) no = (repa \\<propto> high) no \\<and> low no \\<noteq> Null \n          then repa no = (repa \\<propto> low) no\n          else repa no = hd [sn\\<leftarrow>prx. repNodes_eq sn no low high repa] \\<and>\n          repa (repa no) = repa no \\<and> \n          (\\<forall>no1\\<in>set prx. ((repa \\<propto> high) no1 = (repa \\<propto> high) no \\<and> \n          (repa \\<propto> low) no1 = (repa \\<propto> low) no) = (repa no = repa no1)))\"\n          using [[simp_depth_limit=2]]\n          by auto\n        from red_cond_no nodes_notin_nl_neq_nln lno_notin_nl \n          hno_notin_nl while_share_red_exp balanced_no repa_repb_nc \n        have red_repa_no: \"repa no = (repa \\<propto> low) no\"\n          by (auto simp add: null_comp_def)\n        from red_cond_no nodes_notin_nl_neq_nln lno_notin_nl repa_repb_nc \n        have \"(repb \\<propto> low) no =  (repa \\<propto> low) no\"\n          by (auto simp add: null_comp_def)\n        with red_repa_no no_notin_nl balanced_no repa_repb_nc \n        have \"repb no = (repb \\<propto> low) no\"\n          by auto\n        with red_cond_no show ?thesis\n          by auto\n      next\n        assume \"no = node\"\n        with share_cond \n        have share_cond_pre: \n          \"isLeaf_pt no low high \\<or> repa (low no) \\<noteq> repa (high no)\" \n          by simp\n        show ?thesis\n        proof (cases \"isLeaf_pt no low high\")\n          case True\n          with red_cond_no show ?thesis\n            by (simp add: isLeaf_pt_def)\n        next\n          assume no_nLeaf: \"\\<not> isLeaf_pt no low high\"\n          with share_cond_pre \n          have \"repa (low no) \\<noteq> repa (high no)\"\n            by simp\n          with no_nLeaf lno_notin_nl hno_notin_nl nodes_notin_nl_neq_nln \n            balanced_no repa_repb_nc\n          have \"repb (low no) \\<noteq> repb (high no)\"\n            using [[simp_depth_limit=2]]\n            by (auto simp add: isLeaf_pt_def)\n          with no_nLeaf balanced_no have \"(repb \\<propto> low) no \\<noteq> (repb \\<propto> high) no\"\n            by (simp add: null_comp_def isLeaf_pt_def)\n          with red_cond_no show ?thesis\n            by simp\n        qed\n      qed\n    qed\n    have while_while: \"(\\<forall>no\\<in>set (prx@[node]).\n          repb no \\<noteq> Null \\<and>\n          (if (repb \\<propto> low) no = (repb \\<propto> high) no \\<and> low no \\<noteq> Null \n          then repb no = (repb \\<propto> low) no\n          else repb no = hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb] \\<and>\n          repb (repb no) = repb no \\<and>\n          (\\<forall>no1\\<in>set ((prx@[node])). ((repb \\<propto> high) no1 = (repb \\<propto> high) no \n          \\<and> (repb \\<propto> low) no1 = (repb \\<propto> low) no) = (repb no = repb no1))))\"\n      (is \"\\<forall>no\\<in>set (prx@[node]). ?P no \\<and> ?Q no\")\n    proof (intro ballI)\n      fix no\n      assume no_in_take_Sucn: \"no \\<in> set (prx@[node])\"\n      hence no_in_nl: \"no \\<in> set (prx@node#sfx)\"\n        by auto\n      from nodes_balanced_ordered [rule_format, OF this] obtain\n        no_nNull: \"no \\<noteq> Null\" and\n        balanced_no: \"(low no = Null) = (high no = Null)\" and\n        lno_notin_nl: \"low no \\<notin> set (prx@node#sfx)\" and\n        hno_notin_nl: \"high no \\<notin> set (prx@node#sfx)\" and\n        isLeaf_var_no: \"isLeaf_pt no low high = (var no \\<le> 1)\"\n        by auto\n      from no_in_take_Sucn \n      have filter_take_Sucn_not_empty: \n            \"[sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb] \\<noteq> []\"\n        apply -\n        apply (rule filter_not_empty)\n        apply (auto simp add: repNodes_eq_def)\n        done\n      then have hd_filter_Sucn_in_Sucn: \n            \"hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb] \\<in> \n            set (prx@[node])\"\n        by (rule hd_filter_in_list)\n      have nodes_notin_nl_neq_nln: \"\\<forall>p. p \\<notin> set (prx@node#sfx) \\<longrightarrow> p \\<noteq> node\"\n        by auto\n      show \"?P no \\<and> ?Q no\"\n      proof (cases \"no = node\")\n        case False\n        note no_notin_nl=this\n        with no_in_take_Sucn \n        have no_in_take_n: \"no \\<in> set prx\"\n          by auto\n        from False repa_repb_nc have repb_repa_no: \"repb no = repa no\" \n          by auto\n        with while_inv [rule_format, OF no_in_take_n] obtain \n          repa_no_nNull: \"repa no \\<noteq> Null\" and\n          while_share_red_exp: \n          \"(if (repa \\<propto> low) no = (repa \\<propto> high) no \\<and> low no \\<noteq> Null \n              then repa no = (repa \\<propto> low) no\n              else repa no = hd [sn\\<leftarrow>prx. repNodes_eq sn no low high repa] \\<and>\n              repa (repa no) = repa no \\<and> \n              (\\<forall>no1\\<in>set prx. ((repa \\<propto> high) no1 = (repa \\<propto> high) no \\<and> \n              (repa \\<propto> low) no1 = (repa \\<propto> low) no) = (repa no = repa no1)))\"\n          using [[simp_depth_limit=2]]\n          by auto\n        from repb_repa_no repa_no_nNull have repb_no_nNull: \"?P no\"\n          by simp\n        have \"?Q no\"\n        proof (cases \"(repb \\<propto> low) no = (repb \\<propto> high) no \\<and> low no \\<noteq> Null\")\n          case True\n          with no_in_take_Sucn repb_no_red_def show ?thesis\n            by auto\n        next\n          assume share_case_repb: \n            \" \\<not> ((repb \\<propto> low) no = (repb \\<propto> high) no \\<and> low no \\<noteq> Null)\"\n          with repb_no_share_def no_in_take_Sucn \n          have repb_no_def: \"repb no = hd [sn\\<leftarrow> (prx@[node]). \n            repNodes_eq sn no low high repb]\"\n            by auto\n          with share_case_repb \n          have \"(repb \\<propto> low) no \\<noteq> (repb \\<propto> high) no \\<or> low no = Null\"\n            using [[simp_depth_limit=2]]\n            by simp\n          thus ?thesis\n          proof (cases \"low no = Null\")\n            case True\n            note lno_Null=this\n            with balanced_no have hno_Null: \"high no = Null\" \n              by simp\n            from lno_Null hno_Null have isLeaf_no: \"isLeaf_pt no low high\"\n              by (simp add: isLeaf_pt_def)\n            from True while_share_red_exp \n            have while_low_Null: \n              \"repa no = hd [sn\\<leftarrow>prx. repNodes_eq sn no low high repa] \\<and>\n                  repa (repa no) = repa no \\<and> \n                  (\\<forall>no1\\<in>set prx. ((repa \\<propto> high) no1 = (repa \\<propto> high) no \n              \\<and> (repa \\<propto> low) no1 = (repa \\<propto> low) no) = (repa no = repa no1))\"\n              by auto\n            from no_in_take_n \n            have \"[sn\\<leftarrow>prx. repNodes_eq sn no low high repa] \\<noteq> []\"\n              apply -\n              apply (rule filter_not_empty)\n              apply (auto simp add: repNodes_eq_def)\n              done\n            then have hd_term_n_Sucn: \"hd [sn\\<leftarrow>prx. repNodes_eq sn no low high repa] = \n                  hd [sn\\<leftarrow>(prx@[node]) . repNodes_eq sn no low high repa]\"\n              apply -\n              apply (rule hd_filter_app [symmetric])\n              apply auto\n              done\n            have all_nodes_in_nl_Leafs: \n              \"\\<forall>x \\<in> set (prx@node#sfx). isLeaf_pt x low high\"\n            proof (intro ballI)\n              fix x\n              assume x_in_nodeslist: \" x \\<in> set (prx@node#sfx)\"\n              from isLeaf_no isLeaf_var_no have \"var no \\<le> 1\"\n                by simp\n              with all_nodes_same_var [rule_format, OF x_in_nodeslist no_in_nl] \n              have \"var x \\<le> 1\" \n                by simp\n              with nodes_balanced_ordered [rule_format, OF x_in_nodeslist]\n              show \"isLeaf_pt x low high\"\n                by (auto simp add: isLeaf_pt_def)\n            qed\n            from no_in_take_Sucn have \n              filter_Sucn_no_notempty: \n              \"[sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb] \\<noteq> []\"\n              apply -\n              apply (rule filter_not_empty)\n              apply (auto simp add: repNodes_eq_def)\n              done\n            then have hd_term_in_take_Sucn: \n              \"hd [sn\\<leftarrow>(prx@[node]) . repNodes_eq sn no low high repb] \n                  \\<in> set (prx@[node])\"\n              by (rule hd_filter_in_list)\n            then have hd_term_in_nl: \n              \"hd [sn\\<leftarrow>(prx@[node]) . repNodes_eq sn no low high repb] \n              \\<in> set (prx@node#sfx)\"\n              by auto \n            with all_nodes_in_nl_Leafs \n            have hd_term_Leaf: \"isLeaf_pt (hd [sn\\<leftarrow> (prx@[node]). \n              repNodes_eq sn no low high repb]) low high \"\n              by auto            \n            from while_low_Null have \"repa (repa no) = repa no\"\n              by auto\n            with no_notin_nl repa_repb_nc \n            have repa_repb_no_repb: \"repa (repb no) = repb no\"\n              by auto\n            have repb_repb_no: \"repb (repb no) = repb no\" \n            proof (cases \"repb no = node\")\n              case False\n              with repa_repb_nc repa_repb_no_repb show ?thesis\n                by auto\n            next\n              assume repb_no_nln: \" repb no = node\"\n              with hd_term_Leaf isLeaf_no all_nodes_in_nl_Leafs  \n              have nested_hd_repa_repb: \n                \"hd [sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn \n                   (hd [sn\\<leftarrow>(prx@[node]) . repNodes_eq sn no low high repb]) \n                        low high repa] =  \n                 hd [sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn \n                    ( hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb]) \n                        low high repb]\"\n                by (simp add: isLeaf_pt_def repNodes_eq_def null_comp_def)\n              from  hd_term_in_take_Sucn \n              have \"[sn\\<leftarrow>(prx@[node]). repNodes_eq sn \n                      (hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb]) \n                       low high repb] \\<noteq> []\"\n                apply -\n                apply (rule filter_not_empty)\n                apply (auto simp add: repNodes_eq_def)\n                done\n              then have \"hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn \n                    ( hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb]) \n                          low high repb] = \n                    hd [sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn \n                    ( hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb]) \n                           low high repb]\"\n                apply -\n                apply (rule hd_filter_app [symmetric])\n                apply auto\n                done\n              then have hd_term_nodeslist_Sucn: \n                \"hd [sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn \n                    ( hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb]) \n                             low high repb] =\n                    hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn \n                    ( hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb]) \n                          low high repb]\"\n                by simp\n              from no_in_take_Sucn filter_Sucn_no_notempty \n              have filter_filter: \"hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn  \n                    (hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb]) \n                          low high repb] =  \n                    hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb]\"\n                apply -\n                apply (rule filter_hd_P_rep_indep)\n                apply (auto simp add: repNodes_eq_def)\n                done\n              from repb_no_def repb_no_nln repb_node \n              have \"repb (repb no) =  hd [sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn \n                    ( hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb]) \n                           low high repa]\"\n                by simp\n              with nested_hd_repa_repb \n              have \"repb (repb no) =  hd [sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn \n                    (hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb]) \n                        low high repb]\"\n                by simp\n              with hd_term_nodeslist_Sucn \n              have \"repb (repb no) =  hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn \n                    ( hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb]) \n                         low high repb]\"\n                by simp\n              with filter_filter \n              have \"repb (repb no) = hd [sn\\<leftarrow>(prx@[node]). \n                repNodes_eq sn no low high repb]\"\n                by simp\n              with repb_no_def show ?thesis\n                by simp\n            qed\n            have two_nodes_repb: \"(\\<forall>no1\\<in>set (prx@[node]). \n                  ((repb \\<propto> high) no1 = (repb \\<propto> high) no \n                  \\<and> (repb \\<propto> low) no1 = (repb \\<propto> low) no) = (repb no = repb no1))\"\n            proof (intro ballI)\n              fix no1\n              assume no1_in_take_Sucn: \" no1 \\<in> set (prx@[node])\"\n              then have \"no1 \\<in> set (prx@node#sfx)\" by auto\n              with all_nodes_in_nl_Leafs \n              have isLeaf_no1: \"isLeaf_pt no1 low high\"\n                by auto\n              with isLeaf_no \n              have repbchildren_eq_no_no1: \"(repb \\<propto> high) no1 = (repb \\<propto> high) no \n                \\<and> (repb \\<propto> low) no1 = (repb \\<propto> low) no\"\n                by (simp add: null_comp_def isLeaf_pt_def)\n              from isLeaf_no1 isLeaf_no \n              have repachildren_eq_no_no1: \"(repa \\<propto> high) no1 = (repa \\<propto> high) no \n                \\<and> (repa \\<propto> low) no1 = (repa \\<propto> low) no\"\n                by (simp add: null_comp_def isLeaf_pt_def)\n              from while_low_Null \n              have while_low_same_rep: \"(\\<forall>no1\\<in>set prx. \n                ((repa \\<propto> high) no1 = (repa \\<propto> high) no \n                    \\<and> (repa \\<propto> low) no1 = (repa \\<propto> low) no) = (repa no = repa no1))\"\n                by auto\n              show \"((repb \\<propto> high) no1 = (repb \\<propto> high) no \\<and> \n                    (repb \\<propto> low) no1 = (repb \\<propto> low) no) = (repb no = repb no1)\"\n              proof (cases \"no1 = node\")\n                case False\n                with no1_in_take_Sucn have \"no1 \\<in> set prx\"\n                  by auto\n                with while_low_same_rep repachildren_eq_no_no1 \n                have \"repa no = repa no1\"\n                  by auto\n                with repa_repb_nc no_notin_nl False repbchildren_eq_no_no1 \n                show ?thesis \n                  by auto\n              next\n                assume no1_nln: \"no1 = node\"\n                hence no1_in_take_Sucn: \"no1 \\<in> set (prx@[node])\"\n                  by auto\n                hence no1_in_nl: \"no1 \\<in> set (prx@node#sfx)\"\n                  by auto\n                from nodes_balanced_ordered [rule_format, OF this] have \n                  balanced_no1: \"(low no1 = Null) = (high no1 = Null)\"\n                  by auto\n                with no1_in_take_Sucn repb_no_share_def isLeaf_no1 \n                have repb_no1: \"repb no1 = hd [sn\\<leftarrow>(prx@[node]). \n                  repNodes_eq sn no1 low high repb]\"\n                  by (auto simp add: isLeaf_pt_def)\n                from balanced_no1 isLeaf_no1 isLeaf_no balanced_no \n                have repbchildren_eq_no1_no: \"(repb \\<propto> high) no1 = (repb \\<propto> high) no \n                      \\<and> (repb \\<propto> low) no1 = (repb \\<propto> low) no\"\n                  by (simp add: null_comp_def isLeaf_pt_def)\n                have \"\\<forall> x \\<in> set (prx@[node]).  repNodes_eq x no low high repb \n                  =  repNodes_eq x no1 low high repb\"\n                proof (intro ballI)\n                  fix x\n                  assume x_in_take_Sucn: \" x \\<in> set (prx@[node])\"\n                  with repbchildren_eq_no1_no show \"repNodes_eq x no low high repb \n                    = repNodes_eq x no1 low high repb\"\n                    by (simp add: repNodes_eq_def)\n                qed\n                then have \" [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb] \n                      = [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no1 low high repb]\"\n                  by (rule P_eq_list_filter)\n                with repb_no_def repb_no1 have repb_no_no1: \"repb no = repb no1\"\n                  by simp\n                with repbchildren_eq_no1_no show ?thesis\n                  by simp\n              qed\n            qed\n            with repb_repb_no repb_no_share_def no_in_take_Sucn share_case_repb \n            show ?thesis\n              using [[simp_depth_limit=4]]\n              by auto\n          next\n            assume lno_nNull: \"low no \\<noteq> Null\"\n            with share_case_repb \n            have repbchildren_neq_no: \"(repb \\<propto> low) no \\<noteq> (repb \\<propto> high) no\"\n              by auto\n            from balanced_no lno_nNull \n            have hno_nNull: \"high no \\<noteq> Null\"\n              by simp\n            with repbchildren_neq_no lno_nNull repa_repb_nc \n              lno_notin_nl hno_notin_nl nodes_notin_nl_neq_nln \n            have repachildren_neq_no: \"(repa \\<propto> low) no \\<noteq> (repa \\<propto> high) no\"\n              using [[simp_depth_limit=2]]\n              by (auto simp add: null_comp_def)\n            with while_share_red_exp \n            have repa_while_inv: \"repa (repa no) = repa no \n              \\<and> (\\<forall>no1\\<in>set prx. ((repa \\<propto> high) no1 = (repa \\<propto> high) no \n              \\<and> (repa \\<propto> low) no1 = (repa \\<propto> low) no) = (repa no = repa no1))\"\n              by auto\n            from lno_nNull hno_nNull \n            have no_nLeaf: \"\\<not> isLeaf_pt no low high\"\n              by (simp add: isLeaf_pt_def)\n            have all_nodes_in_nl_nLeafs: \n              \"\\<forall>x \\<in> set (prx@node#sfx). \\<not> isLeaf_pt x low high\"\n            proof (intro ballI)\n              fix x\n              assume x_in_nodeslist: \" x \\<in> set (prx@node#sfx)\"\n              from no_nLeaf isLeaf_var_no have \"1 < var no \"\n                by simp\n              with all_nodes_same_var [rule_format, OF x_in_nodeslist no_in_nl] \n              have \"1 < var x\"\n                by simp\n              with nodes_balanced_ordered [rule_format, OF x_in_nodeslist]\n              show \" \\<not> isLeaf_pt x low high\"\n                using [[simp_depth_limit = 2]]\n                by (auto simp add: isLeaf_pt_def)\n            qed\n            have repb_repb_no: \"repb (repb no) = repb no\"\n            proof -\n              from repa_while_inv no_notin_nl repa_repb_nc \n              have \"repa (repb no) = repb no\"\n                by simp\n              from hd_filter_Sucn_in_Sucn repb_no_def \n              have repb_no_in_take_Sucn: \"repb no \\<in> set (prx@[node])\"\n                by simp\n              hence repb_no_in_nl: \"repb no \\<in> set (prx@node#sfx)\"\n                by auto\n              from all_nodes_in_nl_nLeafs repb_no_in_nl \n              have repb_no_nLeaf: \"\\<not> isLeaf_pt (repb no) low high\"\n                by auto\n              from nodes_balanced_ordered [rule_format, OF repb_no_in_nl]\n              have \"(low (repb no) = Null) = (high (repb no) = Null) \n                \\<and> low (repb no) \\<notin> set (prx@node#sfx) \\<and> \n                high (repb no) \\<notin> set (prx@node#sfx)\"\n                by auto\n              from filter_take_Sucn_not_empty \n              have \" repNodes_eq (hd [sn\\<leftarrow>(prx@[node]). \n                repNodes_eq sn no low high repb]) no low high repb\"\n                by (rule hd_filter_prop)\n              with repb_no_def have \"repNodes_eq (repb no) no low high repb\"\n                by simp\n              then have \"(repb \\<propto> low) (repb no) = (repb \\<propto> low) no \n                \\<and> (repb \\<propto> high) (repb no) = (repb \\<propto> high) no\"\n                by (simp add: repNodes_eq_def)\n              with repbchildren_neq_no have \"(repb \\<propto> low) (repb no) \n                \\<noteq> (repb \\<propto> high) (repb no)\"\n                by simp\n              with repb_no_in_take_Sucn repb_no_share_def \n              have repb_repb_no_double_hd: \n                \"repb (repb no) = hd [sn\\<leftarrow>(prx@[node]). \n                repNodes_eq sn (repb no) low high repb]\"\n                by auto\n              from filter_take_Sucn_not_empty \n              have \" hd [sn\\<leftarrow>(prx@[node]). \n                repNodes_eq sn (repb no) low high repb] = repb no\"\n                apply (simp only: repb_no_def )\n                apply (rule filter_hd_P_rep_indep)\n                apply (auto simp add: repNodes_eq_def)\n                done\n              with repb_repb_no_double_hd show ?thesis\n                by simp\n            qed\n            have \"(\\<forall>no1\\<in>set (prx@[node]). \n                ((repb \\<propto> high) no1 = (repb \\<propto> high) no \\<and> \n                (repb \\<propto> low) no1 = (repb \\<propto> low) no) = (repb no = repb no1))\"\n            proof (intro ballI)\n              fix no1\n              assume no1_in_take_Sucn: \"no1 \\<in> set (prx@[node])\"\n              hence no1_in_nl: \"no1 \\<in> set (prx@node#sfx)\"\n                by auto\n              from all_nodes_in_nl_nLeafs no1_in_nl \n              have no1_nLeaf: \"\\<not> isLeaf_pt no1 low high\"\n                by auto\n              from nodes_balanced_ordered [rule_format, OF no1_in_nl]\n              have no1_props: \"(low no1 = Null) = (high no1 = Null) \n                \\<and> low no1 \\<notin> set (prx@node#sfx) \\<and> high no1 \\<notin> set (prx@node#sfx)\"\n                by auto\n              show \"((repb \\<propto> high) no1 = (repb \\<propto> high) no \n                \\<and> (repb \\<propto> low) no1 = (repb \\<propto> low) no) = (repb no = repb no1)\"\n              proof (cases \"no1 = node\")\n                case False\n                note no1_neq_nln=this\n                with no1_in_take_Sucn \n                have no1_in_take_n: \"no1 \\<in> set prx\"\n                  by auto\n                with repa_while_inv have \"((repa \\<propto> high) no1 = (repa \\<propto> high) no \n                  \\<and> (repa \\<propto> low) no1 = (repa \\<propto> low) no) = (repa no = repa no1)\"\n                  by fastforce\n                with no1_props no1_nLeaf no_nLeaf balanced_no lno_notin_nl \n                  hno_notin_nl nodes_notin_nl_neq_nln no_notin_nl \n                  no1_neq_nln repa_repb_nc\n                show ?thesis\n                  using [[simp_depth_limit=1]]\n                  by (auto simp add: null_comp_def isLeaf_pt_def)\n              next\n                assume no1_nln: \" no1 = node\"\n                show ?thesis\n                proof\n                  assume repbchildren_eq_no1_no: \n                    \"(repb \\<propto> high) no1 = (repb \\<propto> high) no \n                    \\<and> (repb \\<propto> low) no1 = (repb \\<propto> low) no\"\n                  with repbchildren_neq_no \n                  have \"(repb \\<propto> high) no1 \\<noteq> (repb \\<propto> low) no1\"\n                    by auto\n                  with repb_no_share_def no1_in_take_Sucn \n                  have repb_no1_def: \" repb no1 = hd [sn\\<leftarrow>(prx@[node]). \n                    repNodes_eq sn no1 low high repb]\"\n                    by auto\n                  have filter_no1_eq_filter_no: \"[sn\\<leftarrow>(prx@[node]). \n                    repNodes_eq sn no1 low high repb] =  \n                    [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb]\"\n                  proof -\n                    have \"\\<forall>x \\<in> set (prx@[node]). \n                      repNodes_eq x no1 low high repb = \n                      repNodes_eq x no low high repb\"\n                    proof (intro ballI)\n                      fix x\n                      assume x_in_take_Sucn: \"x \\<in> set (prx@[node])\"\n                      with repbchildren_eq_no1_no \n                      show \"repNodes_eq x no1 low high repb = \n                        repNodes_eq x no low high repb\"\n                        by (simp add: repNodes_eq_def)\n                    qed\n                    then show ?thesis\n                      by (rule P_eq_list_filter)\n                  qed\n                  with repb_no1_def repb_no_def show \" repb no = repb no1\"\n                    by simp\n                next\n                  assume repb_no_no1_eq: \"repb no = repb no1\"\n                  from no1_nln repb_node repb_no_def have repb_no1_def: \n                    \"repb no1 =  \n                    hd [sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn node low high repa]\"\n                    by auto\n                  with no1_nln repb_no_def repb_no_no1_eq \n                  have repb_Sucn_repa_nl_hd: \" hd [sn\\<leftarrow>(prx@[node]). \n                    repNodes_eq sn no low high repb] = \n                    hd [sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn no1 low high repa]\"\n                    by simp\n                  from filter_take_Sucn_not_empty \n                  have \" hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb] \n                    =  hd [sn\\<leftarrow>(prx@node#sfx) . repNodes_eq sn no low high repb]\"\n                    apply -\n                    apply (rule hd_filter_app [symmetric])\n                    apply auto\n                    done\n                  then have hd_Sucn_hd_whole_list: \n                    \"hd [sn\\<leftarrow>(prx@[node]) . \n                    repNodes_eq sn no low high repb] =  \n                    hd [sn\\<leftarrow> (prx@node#sfx). repNodes_eq sn no low high repb]\"\n                    by simp\n                  have hd_nl_repb_repa: \n                    \"[sn\\<leftarrow> (prx@node#sfx). repNodes_eq sn no low high repb] \n                    = [sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn no low high repa]\"\n                  proof -\n                    have \"\\<forall>x \\<in> set (prx@node#sfx).  \n                      repNodes_eq x no low high repb =  \n                      repNodes_eq x no low high repa\"\n                    proof (intro ballI)\n                      fix x\n                      assume x_in_nl: \"x \\<in> set (prx@node#sfx)\"\n                      from all_nodes_in_nl_nLeafs x_in_nl \n                      have x_nLeaf: \"\\<not> isLeaf_pt x low high\"\n                        by auto\n                      from  nodes_balanced_ordered [rule_format, OF x_in_nl]\n                      have x_props: \"(low x = Null) = (high x = Null) \\<and> \n                        low x \\<notin> set (prx@node#sfx) \\<and> high x \\<notin> set (prx@node#sfx)\"\n                        by auto\n                      with x_nLeaf lno_nNull hno_nNull lno_notin_nl hno_notin_nl \n                        nodes_notin_nl_neq_nln repa_repb_nc \n                      show \"repNodes_eq x no low high repb = \n                        repNodes_eq x no low high repa\"\n                        using [[simp_depth_limit=1]]\n                        by (simp add: repNodes_eq_def isLeaf_pt_def null_comp_def)\n                    qed\n                    then show ?thesis\n                      by (rule P_eq_list_filter)\n                  qed\n                  with repb_Sucn_repa_nl_hd hd_Sucn_hd_whole_list \n                  have filter_nl_no_no1: \n                    \"hd [sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn no low high repa] \n                    =  hd [sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn no1 low high repa]\"\n                    by simp\n                  from no_in_nl have filter_no_not_empty: \n                    \"[sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn no low high repa] \\<noteq> []\"\n                    apply -\n                    apply (rule filter_not_empty)\n                    apply (auto simp add: repNodes_eq_def)\n                    done\n                  from no1_in_nl have filter_no1_not_empty: \n                    \"[sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn no1 low high repa] \\<noteq> []\"\n                    apply -\n                    apply (rule filter_not_empty)\n                    apply (auto simp add: repNodes_eq_def)\n                    done\n                  from repb_no_def hd_Sucn_hd_whole_list hd_nl_repb_repa \n                  have \"repb no =\n                    hd [sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn no low high repa]\" \n                    by simp\n                  with hd_filter_prop [OF filter_no_not_empty ]\n                  have repNodes_no_repa: \"repNodes_eq (repb no) no low high repa\"\n                    by auto\n                  from repb_no1_def no1_nln \n                  have \n                    \"repb no1 = hd [sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn no1 \n                    low high repa]\"\n                    by simp\n                  with hd_filter_prop [OF filter_no1_not_empty ]\n                  have \"repNodes_eq (repb no1) no1 low high repa\"\n                    by auto\n                  with filter_nl_no_no1 repNodes_no_repa repb_no_no1_eq \n                  have \"(repa \\<propto> high) no1 = \n                    (repa \\<propto> high) no \\<and> (repa \\<propto> low) no1 = (repa \\<propto> low) no\"\n                    by (simp add: repNodes_eq_def)\n                  with hno_nNull no1_props no1_nLeaf lno_nNull lno_notin_nl \n                    hno_notin_nl nodes_notin_nl_neq_nln repa_repb_nc\n                  show \"(repb \\<propto> high) no1 = \n                    (repb \\<propto> high) no \\<and> (repb \\<propto> low) no1 = (repb \\<propto> low) no\"\n                    using [[simp_depth_limit=1]]\n                    by (auto simp add: isLeaf_pt_def null_comp_def)\n                qed\n              qed\n            qed\n            with repb_repb_no repb_no_share_def share_case_repb no_in_take_Sucn \n            show ?thesis\n              using [[simp_depth_limit=1]]\n              by auto\n          qed\n        qed\n        with repb_no_nNull show ?thesis\n          by simp\n      next\n        assume no_nln: \"no = node\"\n        with repb_node have repb_no_def: \n          \"repb no = hd [sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn no low high repa]\"\n          by simp\n        from no_nln have \"no \\<in> set (prx@node#sfx)\"\n          by auto\n        then have filter_nl_repa_not_empty: \n          \"[sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn no low high repa] \\<noteq> []\"\n          apply -\n          apply (rule filter_not_empty)\n          apply (auto simp add: repNodes_eq_def)\n          done\n        then have hd_filter_nl_in_nl: \n          \"hd [sn\\<leftarrow>(prx@node#sfx). repNodes_eq sn no low high repa] \\<in> set (prx@node#sfx)\"\n          by (rule hd_filter_in_list)\n        with repb_no_def \n        have repb_no_in_nodeslist: \"repb no \\<in> set (prx@node#sfx)\"\n          by simp\n        from nodes_balanced_ordered [rule_format,OF this]\n        have repb_no_nNull: \"repb no \\<noteq> Null\"\n          by auto\n        from share_cond no_nln have share_cond_or: \n          \"isLeaf_pt no low high \\<or> repa (low no) \\<noteq> repa (high no)\"\n          by auto\n        have share_reduce_if: \" (if (repb \\<propto> low) no = (repb \\<propto> high) no \\<and> low no \\<noteq> Null \n              then repb no = (repb \\<propto> low) no\n              else repb no = hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb] \\<and>\n              repb (repb no) = repb no \n              \\<and> (\\<forall>no1\\<in>set (prx@[node]). ((repb \\<propto> high) no1 = (repb \\<propto> high) no \n              \\<and> (repb \\<propto> low) no1 = (repb \\<propto> low) no) = (repb no = repb no1)))\"\n        proof (cases \"isLeaf_pt no low high\")\n          case True\n          note isLeaf_no=this\n          then have lno_Null: \"low no = Null\" by (simp add: isLeaf_pt_def)\n          from isLeaf_no no_in_take_Sucn repb_no_share_def \n          have repb_no_repb_def: \"repb no \n                = hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb]\"\n            by (auto simp add: isLeaf_pt_def)\n          from isLeaf_no nodes_balanced_ordered [rule_format, OF no_in_nl]\n          have var_no: \"var no \\<le> 1\" \n            by auto\n          have all_nodes_nl_var_l_1: \"\\<forall>x \\<in> set (prx@node#sfx). var x \\<le> 1\"\n          proof (intro ballI)\n            fix x\n            assume x_in_nl: \" x \\<in> set (prx@node#sfx)\"\n            from all_nodes_same_var [rule_format, OF x_in_nl no_in_nl] var_no \n            show \" var x \\<le> 1\"\n              by auto\n          qed              \n          have all_nodes_nl_Leafs: \"\\<forall>x \\<in> set (prx@node#sfx). isLeaf_pt x low high\" \n          proof (intro ballI)\n            fix x\n            assume x_in_nl: \" x \\<in> set (prx@node#sfx)\"\n            with all_nodes_nl_var_l_1 have \"var x \\<le> 1\"\n              by auto\n            with nodes_balanced_ordered [rule_format, OF x_in_nl ]\n            show \"isLeaf_pt x low high\"\n              by auto\n          qed \n          have repb_repb_no: \"repb (repb no) = repb no\"\n          proof -\n            from repb_no_share_def no_in_take_Sucn lno_Null \n            have repb_no_def: \" repb no = \n              hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb]\"\n              by auto\n            with hd_filter_Sucn_in_Sucn \n            have repb_no_in_take_Sucn: \"repb no \\<in> set (prx@[node])\"\n              by simp\n            hence repb_no_in_nl: \"repb no \\<in> set (prx@[node])\"\n              by auto\n            with all_nodes_nl_Leafs \n            have repb_no_Leaf: \"isLeaf_pt (repb no) low high\" \n              by auto\n            with repb_no_in_take_Sucn repb_no_share_def \n            have repb_repb_no_def: \"repb (repb no) = \n              hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn (repb no) low high repb] \"\n              by (auto simp add: isLeaf_pt_def)\n            from filter_take_Sucn_not_empty \n            show ?thesis\n              apply (simp only: repb_repb_no_def  )\n              apply (simp only: repb_no_def)\n              apply (rule filter_hd_P_rep_indep)\n              apply (auto simp add: repNodes_eq_def)\n              done\n          qed\n          have two_nodes_repb: \"(\\<forall>no1\\<in>set (prx@[node]). \n                ((repb \\<propto> high) no1 = (repb \\<propto> high) no \\<and> \n                (repb \\<propto> low) no1 = (repb \\<propto> low) no) = (repb no = repb no1))\"\n          proof (intro ballI)\n            fix no1 \n            assume no1_in_take_Sucn: \"no1 \\<in> set (prx@[node])\"\n            from no1_in_take_Sucn \n            have \"no1 \\<in> set (prx@node#sfx)\"\n              by auto\n            with all_nodes_nl_Leafs \n            have isLeaf_no1: \"isLeaf_pt no1 low high\"\n              by auto\n            with repb_no_share_def no1_in_take_Sucn \n            have repb_no1_def: \"repb no1 =  \n                  hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no1 low high repb]\" \n              by (auto simp add: isLeaf_pt_def)\n            show \"((repb \\<propto> high) no1 = (repb \\<propto> high) no \n                  \\<and> (repb \\<propto> low) no1 = (repb \\<propto> low) no) = (repb no = repb no1)\"\n            proof \n              assume repbchildren_eq_no1_no: \"(repb \\<propto> high) no1 = (repb \\<propto> high) no \n                    \\<and> (repb \\<propto> low) no1 = (repb \\<propto> low) no\"\n              have \"[sn\\<leftarrow>(prx@[node]). repNodes_eq sn no1 low high repb] \n                    = [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb]\"\n              proof -\n                have \"\\<forall>x \\<in> set (prx@[node]). \n                      repNodes_eq x no1 low high repb = repNodes_eq x no low high repb\"\n                proof (intro ballI)\n                  fix x\n                  assume x_in_take_Sucn: \" x \\<in> set (prx@[node])\"\n                  with repbchildren_eq_no1_no \n                  show \" repNodes_eq x no1 low high repb = repNodes_eq x no low high repb\"\n                    by (simp add: repNodes_eq_def)\n                qed\n                then show ?thesis\n                  by (rule P_eq_list_filter)\n              qed\n              with repb_no1_def repb_no_repb_def \n              show \"repb no = repb no1\"\n                by simp\n            next\n              assume repb_no_no1: \"repb no = repb no1\"\n              with isLeaf_no isLeaf_no1 \n              show \"(repb \\<propto> high) no1 = (repb \\<propto> high) no \n                \\<and> (repb \\<propto> low) no1 = (repb \\<propto> low) no\"\n                by (simp add: null_comp_def isLeaf_pt_def)\n            qed\n          qed\n          with repb_repb_no lno_Null no_in_take_Sucn repb_no_share_def show ?thesis\n            by auto\n        next\n          assume no_nLeaf: \"\\<not> isLeaf_pt no low high\"\n          with balanced_no obtain \n            lno_nNull: \"low no \\<noteq> Null\" and \n            hno_nNull: \"high no \\<noteq> Null\"\n            by (simp add: isLeaf_pt_def)\n          from no_nLeaf nodes_balanced_ordered [rule_format, OF no_in_nl]\n          have var_no: \"1 < var no\" \n            by auto\n          have all_nodes_nl_var_l_1: \"\\<forall>x \\<in> set (prx@node#sfx). 1 < var x\"\n          proof (intro ballI)\n            fix x\n            assume x_in_nl: \" x \\<in> set (prx@node#sfx)\"\n            with all_nodes_same_var [rule_format, OF x_in_nl no_in_nl] var_no \n            show \"1 < var x\"\n              by simp\n          qed         \n          have all_nodes_nl_nLeafs: \"\\<forall> x \\<in> set (prx@node#sfx). \\<not> isLeaf_pt x low high\" \n          proof (intro ballI)\n            fix x\n            assume x_in_nl: \" x \\<in> set (prx@node#sfx)\"\n            with all_nodes_nl_var_l_1 have \"1 < var x\"\n              by auto\n            with nodes_balanced_ordered [rule_format, OF x_in_nl] show \" \\<not> isLeaf_pt x low high\"\n              by auto\n          qed \n          from no_nLeaf share_cond_or \n          have repachildren_neq_no: \"repa (low no) \\<noteq> repa (high no)\"\n            by auto\n          with lno_nNull hno_nNull \n          have \"(repa \\<propto> low) no \\<noteq> (repa \\<propto> high) no\"\n            by (simp add: null_comp_def)\n          with repa_repb_nc lno_notin_nl hno_notin_nl \n            nodes_notin_nl_neq_nln lno_nNull hno_nNull \n          have repbchildren_neq_no: \"(repb \\<propto> low) no \\<noteq> (repb \\<propto> high) no\"\n            using [[simp_depth_limit=1]]\n            by (auto simp add: null_comp_def)\n          have repb_repb_no: \"repb (repb no) = repb no\"\n          proof -\n            from repb_no_share_def no_in_take_Sucn repbchildren_neq_no \n            have repb_no_def: \"repb no = \n              hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb]\"\n              by auto\n            from filter_take_Sucn_not_empty \n            have \"repNodes_eq (repb no) no low high repb\"\n              apply (simp only: repb_no_def)\n              apply (rule hd_filter_prop)\n              apply simp\n              done\n            with repbchildren_neq_no \n            have repbchildren_neq_repb_no: \"(repb \\<propto> low) (repb no) \\<noteq> (repb \\<propto> high) (repb no)\"\n              by (simp add: repNodes_eq_def)\n            from filter_take_Sucn_not_empty \n            have \"repb no \\<in> set (prx@[node])\"\n              apply (simp only: repb_no_def )\n              apply (rule hd_filter_in_list)\n              apply simp\n              done\n            with repbchildren_neq_repb_no repb_no_share_def \n            have repb_repb_no_def: \" repb (repb no) = \n              hd [sn\\<leftarrow>(prx@[node]) . repNodes_eq sn (repb no) low high repb] \"\n              by auto\n            from filter_take_Sucn_not_empty show ?thesis\n              apply (simp only: repb_repb_no_def )\n              apply (simp only: repb_no_def)\n              apply (rule filter_hd_P_rep_indep)\n              apply (auto simp add: repNodes_eq_def)\n              done\n          qed\n          have two_nodes_repb: \"(\\<forall>no1\\<in>set (prx@[node]). \n            ((repb \\<propto> high) no1 = (repb \\<propto> high) no \\<and> \n            (repb \\<propto> low) no1 = (repb \\<propto> low) no) = (repb no = repb no1))\"\n            (is \"(\\<forall>no1\\<in>set (prx@[node]). ?P no1)\")\n          proof (intro ballI)\n            fix no1\n            assume no1_in_take_Sucn: \" no1 \\<in> set (prx@[node])\"\n            hence no1_in_nodeslist: \"no1 \\<in> set (prx@node#sfx)\"\n              by auto\n            with all_nodes_nl_nLeafs \n            have no1_nLeaf: \"\\<not> isLeaf_pt no1 low high\"\n              by auto\n            show \"?P no1\"\n            proof\n              assume repbchildren_eq_no1_no: \"(repb \\<propto> high) no1 = (repb \\<propto> high) no \n                \\<and> (repb \\<propto> low) no1 = (repb \\<propto> low) no\"\n              with repbchildren_neq_no have \"(repb \\<propto> high) no1 \\<noteq> (repb \\<propto> low) no1\"\n                by auto\n              with no1_in_take_Sucn repb_no_share_def have repb_no1_def: \"repb no1 = \n                hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no1 low high repb]\"\n                by auto\n              from repb_no_share_def no_in_take_Sucn repbchildren_neq_no \n              have repb_no_def: \"repb no = \n                hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb]\"\n                by auto\n              have \"[sn\\<leftarrow>(prx@[node]). repNodes_eq sn no1 low high repb] = \n                [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb]\"\n              proof -\n                have \"\\<forall> x \\<in> set (prx@[node]). \n                  repNodes_eq x no1 low high repb = repNodes_eq x no low high repb\"\n                proof (intro ballI)\n                  fix x\n                  assume x_in_take_Sucn: \" x \\<in> set (prx@[node])\"\n                  with repbchildren_eq_no1_no \n                  show \" repNodes_eq x no1 low high repb = repNodes_eq x no low high repb\"\n                    by (simp add: repNodes_eq_def)\n                qed\n                then show ?thesis\n                  by (rule P_eq_list_filter)\n              qed\n              with repb_no_def repb_no1_def show \" repb no = repb no1\"\n                by simp\n            next\n              assume repb_no_no1: \"repb no = repb no1\"\n              from repb_no_share_def no_in_take_Sucn repbchildren_neq_no \n              have repb_no_def: \"repb no = \n                hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no low high repb]\"\n                by auto\n              from filter_take_Sucn_not_empty \n              have \"repb no \\<in> set (prx@[node])\"\n                apply (simp only: repb_no_def)\n                apply (rule hd_filter_in_list)\n                apply simp\n                done\n              then have repb_no_in_nl: \"repb no \\<in> set (prx@node#sfx)\"\n                by auto\n              from filter_take_Sucn_not_empty \n              have repNodes_repb_no: \"repNodes_eq (repb no) no low high repb\"\n                apply (simp only: repb_no_def)\n                apply (rule hd_filter_prop)\n                apply simp\n                done\n              show \"(repb \\<propto> high) no1 = (repb \\<propto> high) no \n                \\<and> (repb \\<propto> low) no1 = (repb \\<propto> low) no\"\n              proof (cases \"(repb \\<propto> low) no1 = (repb \\<propto> high) no1\")\n                case True\n                note red_cond=this\n                from no1_in_nodeslist all_nodes_nl_nLeafs\n                have no1_nLeaf: \"\\<not> isLeaf_pt no1 low high\"\n                  by auto\n                from nodes_balanced_ordered [rule_format, OF no1_in_nodeslist]\n                have no1_props: \"(low no1 \\<notin> set (prx@node#sfx)) \n                      \\<and> (high no1 \\<notin> set (prx@node#sfx)) \\<and>(low no1 = Null) = (high no1 = Null) \n                      \\<and> ((rep \\<propto> low) no1 \\<notin> set (prx@node#sfx))\"\n                  by auto\n                with red_cond no1_nLeaf no1_in_take_Sucn repb_no_red_def \n                have repb_no1_def: \"repb no1 = (repb \\<propto> low) no1\"\n                  by (auto simp add: isLeaf_pt_def)\n                with no1_nLeaf no1_props have \"repb no1 = repb (low no1)\"\n                  by (simp add: null_comp_def isLeaf_pt_def)\n                from no1_props no1_nLeaf have \"rep (low no1) \\<notin> set (prx@node#sfx)\"\n                  by (auto simp add: isLeaf_pt_def null_comp_def)\n                with rep_repb_nc no1_props \n                have \"repb (low no1) \\<notin> set (prx@node#sfx)\"\n                  by auto\n                with repb_no1_def repb_no_no1 no1_props no1_nLeaf \n                have \"repb no \\<notin> set (prx@node#sfx)\"\n                  by (simp add: isLeaf_pt_def null_comp_def)\n                with repb_no_in_nl show ?thesis\n                  by simp\n              next\n                assume \"(repb \\<propto> low) no1 \\<noteq> (repb \\<propto> high) no1\"\n                with repb_no_share_def no1_in_take_Sucn \n                have repb_no1_def: \" repb no1 = \n                  hd [sn\\<leftarrow>(prx@[node]). repNodes_eq sn no1 low high repb]\"\n                  by auto\n                from no1_in_take_Sucn \n                have \"[sn\\<leftarrow>(prx@[node]). repNodes_eq sn no1 low high repb] \\<noteq> []\" \n                  apply -\n                  apply (rule filter_not_empty)\n                  apply (auto simp add: repNodes_eq_def)\n                  done\n                then \n                have repNodes_repb_no1: \"repNodes_eq (repb no1) no1 low high repb\"\n                  apply (simp only: repb_no1_def ) \n                  apply (rule hd_filter_prop)\n                  apply simp\n                  done\n                with repNodes_repb_no repb_no_no1 \n                have \"repNodes_eq no1 no low high repb\"\n                  by (simp add: repNodes_eq_def)\n                then show ?thesis\n                  by (simp add: repNodes_eq_def)\n              qed\n            qed\n          qed\n          with repb_repb_no repb_no_share_def no_in_take_Sucn repbchildren_neq_no\n          show ?thesis\n            using [[simp_depth_limit=2]]\n            by fastforce\n        qed\n        with repb_no_nNull show ?thesis\n          by simp\n      qed\n    qed\n    with rep_repb_nc show ?thesis\n      by (intro conjI)\n  qed\nqed\n\nend\n\n\n\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/BDD/ShareReduceRepListProof.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.2902211242444727}}
{"text": "theory RingBuffer_BD_latest_2\nimports Main HOL.List\nbegin \n\n\n(*\n      W_step_side                           R_step_side\n\nLOCAL preserves inv    (2)            LOCAL preserves inv    (1) \n\nLOCAL shows preW       (done)         LOCAL shows preR       (done) \n\nGLOBAL preserves preR  (done)         GLOBAL preserves preW  (done)  \n*)\n\n\ndatatype PCW =\n  A1 | A2 | A3 | A4 | A5 | A6 | A7 | A8\n| Enqueue | idleW | OOM | FinishedW |  Write | BTS\n\ndatatype PCR =\n Release | idleR | Read\n\ndatatype F = W | R | Q | B | D | None\ndatatype Pointer = Head | Tail\nconsts N :: nat   (*size of buffer, input*)\nconsts n :: nat   (*number of Arr\\<^sub>W entries*)\n\ndefinition \"F1_set={W,B,Q,R}\"\ndefinition \"W_pre_acquire_set={A1,A2,A3,A4,A5,A6,A7,A8,idleW,FinishedW,OOM,BTS}\"\ndefinition \"W_post_acquire_set={Write,Enqueue}\"\ndefinition \"R_pre_dequeue_set={idleR}\"\ndefinition \"R_post_dequeue_set={Read, Release}\"\n\nlemmas sets [simp]= F1_set_def W_pre_acquire_set_def W_post_acquire_set_def\n                              R_pre_dequeue_set_def R_post_dequeue_set_def\n\n(*Recorded variables*)\nrecord rb_state =\n  H :: nat\n  T :: nat\n  hW ::  nat               (*local copy of W*)\n  tW ::  nat               (*local copy of W*)\n  offset :: nat\n  q :: \"(nat \\<times> nat) list\"\n  tempR :: \"(nat \\<times> nat)\"          (*local copy of word by R*)\n\n\n  data_index :: \"(nat \\<times> nat) \\<Rightarrow> nat\"   (*state of the buffer contents*)\n  pcW :: PCW           (*records program counter of W*)\n  pcR :: PCR           (*records program counter of W*)\n  Data:: \"nat  \\<Rightarrow> nat\"     (*returns a word Data_i*)\n\n  tR :: nat\n  numReads :: nat     (* how many words the reader has read *)\n  numWrites :: nat    (* how many words the writer has written *)\n  numEnqs :: nat  (* how many words from Data the writer has enqueued  *)\n  numDeqs :: nat  (* how many words from Data the reader has retrieved *)\n  ownT ::  F\n  ownD :: \"nat \\<Rightarrow> F\" (* ownership of Data indices *)\n  ownB :: \"nat \\<Rightarrow> F\" (* ownership of bytes in buffer *)\n\n  \n\ndefinition \"con_assms s \\<equiv>   0 < N \\<and> 0<n  \\<and> N>n \\<and> numEnqs s\\<le>n \\<and> (numDeqs s\\<le>numEnqs s)\n                             \\<and> (\\<forall>i.(i<n)\\<longrightarrow>Data s i\\<le>N \\<and> Data s i>0 )\"\n\ndefinition push_H :: \"nat \\<Rightarrow> rb_state \\<Rightarrow> rb_state\" (\"`H := _\" [200])\n  where \n  \"push_H v \\<equiv> \\<lambda>s. s \\<lparr>H := v\\<rparr>\"\ndefinition push_T :: \"nat \\<Rightarrow> rb_state \\<Rightarrow> rb_state\" (\"`T := _\" [200])\n  where \n  \"push_T v \\<equiv> \\<lambda>s. s \\<lparr>T := v\\<rparr>\"\ndefinition write_data_index :: \"nat \\<times> nat \\<Rightarrow> nat \\<Rightarrow> rb_state \\<Rightarrow> rb_state\" (\"`B.write _ := _\" [200])  where\n  \"write_data_index a v  \\<equiv>  \n      \\<lambda>s. s \\<lparr> data_index  := \\<lambda> x. if  a = x  then v else data_index s x \\<rparr>\"  \ndefinition change_writes :: \"nat \\<Rightarrow> rb_state \\<Rightarrow> rb_state\" (\"`numWrites := _\" [200])\n  where \n  \"change_writes v \\<equiv> \\<lambda>s. s \\<lparr>numWrites := v\\<rparr>\"\ndefinition change_reads :: \"nat \\<Rightarrow> rb_state \\<Rightarrow> rb_state\" (\"`numReads := _\" [200])\n  where \n  \"change_reads v \\<equiv> \\<lambda>s. s \\<lparr>numReads := v\\<rparr>\"\ndefinition push_offset :: \"nat \\<Rightarrow> rb_state \\<Rightarrow> rb_state\" (\"`offset := _\" [200])\n  where \n  \"push_offset v \\<equiv> \\<lambda>s. s \\<lparr>offset := v\\<rparr>\"\n\n\ndefinition trans_ownT :: \"F \\<Rightarrow> F \\<Rightarrow> rb_state \\<Rightarrow> rb_state \\<Rightarrow> rb_state\" (\"transownT [_ _ _]\" [200]) where\n  \"trans_ownT a b s \\<equiv> if ownT s = a then (\\<lambda>s. s \\<lparr> ownT := b \\<rparr>)\n                                    else (\\<lambda>s. s \\<lparr> ownT := ownT s\\<rparr>)\"\n\ndefinition transfer_ownB :: \"F \\<Rightarrow> F \\<Rightarrow> rb_state \\<Rightarrow> rb_state\" (\"transownB [_ _]\" [200]) where\n  \"transfer_ownB a b \\<equiv> (\\<lambda>s. s \\<lparr> ownB := \\<lambda> i. if (ownB s i = a)\\<and>i\\<le>N then b else (ownB s) i\\<rparr>)\"\n\ndefinition set_ownB :: \"nat\\<times>nat\\<Rightarrow> F \\<Rightarrow> rb_state \\<Rightarrow> rb_state\" (\"setownB [_ _]\" [200]) where\n  \"set_ownB x a \\<equiv> (\\<lambda>s. s \\<lparr> ownB := \\<lambda> i. if ((i\\<ge>fst(x)) \\<and> (i<snd(x))) then a else (ownB s) i\\<rparr>)\"\n\ndefinition transfer_ownD :: \"nat\\<Rightarrow> F \\<Rightarrow> rb_state \\<Rightarrow> rb_state\" (\"transownD [_ _]\" [200]) where\n  \"transfer_ownD x a \\<equiv> (\\<lambda>s. s \\<lparr> ownD := \\<lambda> i. if i=x then a else (ownD s) i\\<rparr>)\"\n\n\n\n\n(*-----------------------*)\n\ndefinition set_hW :: \"nat \\<Rightarrow> rb_state \\<Rightarrow> rb_state\" (\"`hW := _\" [200])  where\n  \"set_hW v  \\<equiv> \\<lambda>s. s \\<lparr> hW  := v\\<rparr>\"\ndefinition set_tW :: \"nat \\<Rightarrow> rb_state \\<Rightarrow> rb_state\" (\"`tW := _\" [200])  where\n  \"set_tW v  \\<equiv> \\<lambda>s. s \\<lparr> tW  := v\\<rparr>\"\ndefinition set_tR :: \"nat \\<Rightarrow> rb_state \\<Rightarrow> rb_state\" (\"`tR := _\" [200])  where\n  \"set_tR v  \\<equiv> \\<lambda>s. s \\<lparr> tR  := v\\<rparr>\"\ndefinition set_tempR :: \"(nat \\<times> nat) \\<Rightarrow> rb_state \\<Rightarrow> rb_state\" (\"`tempR := _\" [200]) where\n  \"set_tempR v \\<equiv> \\<lambda>s. s \\<lparr> tempR := v\\<rparr>\"\ndefinition update_numEnqs :: \"nat \\<Rightarrow> rb_state \\<Rightarrow> rb_state\" (\"`numEnqs := _\" [200]) where\n  \"update_numEnqs v\\<equiv> \\<lambda>s. s \\<lparr> numEnqs := v\\<rparr>\"\ndefinition update_numDeqs :: \"nat \\<Rightarrow> rb_state \\<Rightarrow> rb_state\" (\"`numDeqs := _\" [200]) where\n  \"update_numDeqs v\\<equiv> \\<lambda>s. s \\<lparr> numDeqs := v\\<rparr>\"\ndefinition update_pcW :: \"PCW \\<Rightarrow> rb_state \\<Rightarrow> rb_state\" (\"`pcW := _\" [200]) where\n  \"update_pcW v \\<equiv> \\<lambda>s. s \\<lparr> pcW := v\\<rparr>\"\ndefinition update_pcR :: \"PCR \\<Rightarrow> rb_state \\<Rightarrow> rb_state\" (\"`pcR := _\" [200]) where\n  \"update_pcR v \\<equiv> \\<lambda>s. s \\<lparr> pcR := v\\<rparr>\"\nabbreviation update_b_err :: \"rb_state \\<Rightarrow> rb_state\" (\"ERROOM\") where\n  \"update_b_err \\<equiv> \\<lambda>s. s \\<lparr> pcW := OOM \\<rparr>\"\nabbreviation update_bts_err :: \"rb_state \\<Rightarrow> rb_state\" (\"ERRBTS\") where\n  \"update_bts_err \\<equiv> \\<lambda>s. s \\<lparr> pcW := BTS \\<rparr>\"\ndefinition update_q :: \"(nat \\<times> nat) list \\<Rightarrow> rb_state \\<Rightarrow> rb_state\" (\"`q := _\" [200])\n  where \n  \"update_q v  \\<equiv> \\<lambda>s. s \\<lparr>q := v\\<rparr>\"\nlemmas functs [simp] = push_H_def push_T_def set_hW_def set_tW_def\n                        update_numEnqs_def update_numDeqs_def\n                        set_tempR_def \n                        update_pcW_def update_pcR_def\n                        transfer_ownB_def transfer_ownD_def trans_ownT_def\n                        update_q_def\n                        push_offset_def write_data_index_def\n                        change_writes_def change_reads_def\n                        set_tR_def set_ownB_def\n\n\n\n\n\n(*  Define the if statement \"guards\"  *)\n\ndefinition \"off bo \\<equiv> fst bo\"\ndefinition \"len bo \\<equiv> snd bo\"\ndefinition \"grd1 s \\<equiv> (tW s = hW s) \\<and> (Data s (numEnqs s) \\<le> N)\"\ndefinition \"grd2 s \\<equiv> (tW s > hW s) \\<and> (Data s (numEnqs s) < (tW s - hW s))\"\ndefinition \"grd3 s \\<equiv> tW s < hW s\"\ndefinition \"grd4 s \\<equiv> Data s (numEnqs s) \\<le> N - hW s\"\ndefinition \"grd5 s \\<equiv> Data s (numEnqs s) < tW s\"\ndefinition \"no_space_for_word s \\<equiv> (grd1 s \\<longrightarrow> \\<not>(Data s (numEnqs s) \\<le> N))\\<and>\n                                  (grd2 s \\<longrightarrow> \\<not>(Data s (numEnqs s) < (tW s - hW s)))\\<and>\n                                  (grd3 s \\<longrightarrow> \\<not>(Data s (numEnqs s) \\<le> N - hW s \\<or> Data s (numEnqs s) < tW s))\"\nlemmas grd_simps [simp] = off_def len_def grd1_def grd2_def grd3_def grd4_def grd5_def no_space_for_word_def \n(***********************************************************************)\n\n\n\n\n\n(*  Initial State  *)\n\ndefinition \"init s \\<equiv> (H s = 0) \\<and> (T s = 0) \\<and> (offset s = 0) \\<and> q s = [] \\<and> (hW s = 0) \\<and> (tW s = 0) \\<and> (tR s = 0)\n                        \\<and> numReads s = 0 \\<and> numWrites s = 0 \\<and> (numEnqs s = 0) \\<and> (numDeqs s = 0)\n                        \\<and> ( pcW s = idleW)\n                        \\<and> ( pcR s = idleR)\n                        \\<and> (\\<forall>l. (l<n) \\<longrightarrow>  ((Data s l > 0)\\<and>(Data s l \\<le> N)))\n                        \\<and> (\\<forall>i. (i<n) \\<longrightarrow>  ownD s i = W)\n                        \\<and> (\\<forall>i. (i<N) \\<longrightarrow>  ownB s i = B)\n                        \\<and> (ownB s N = None)\n                        \\<and> (ownT s = Q)\n                        \\<and> (tempR s = (0,0))\n                        \\<and> (\\<forall>i. (i\\<le>N)\\<longrightarrow>(\\<forall>j.(j\\<le>N)\\<longrightarrow>data_index s (i,j) <n))\"\n(***********************************************************************)\n\n\n\ndefinition \"case_1 s  \\<equiv> \\<exists>a b c d. (0\\<le>a \\<and> a\\<le>b \\<and> b\\<le>c \\<and> c\\<le>d \\<and> d\\<le>N \n                                        \\<and>(\\<forall>i.(0\\<le>i \\<and> i<a)\\<longrightarrow>ownB s i = B)\n                                        \\<and>(\\<forall>i.(a\\<le>i \\<and> i<b)\\<longrightarrow>ownB s i = R)\n                                        \\<and>(\\<forall>i.(b\\<le>i \\<and> i<c)\\<longrightarrow>ownB s i = Q)\n                                        \\<and>(\\<forall>i.(c\\<le>i \\<and> i<d)\\<longrightarrow>ownB s i = W)\n                                        \\<and>(\\<forall>i.(d\\<le>i \\<and> i<N)\\<longrightarrow>ownB s i = B)\n                                        \\<and>(ownB s N = None)\n                                \\<comment>\\<open>general case rules\\<close>\n                                      \\<comment>\\<open>rules are simple\\<close>\n                                \\<comment>\\<open>describe T using ownB\\<close>\n                                  \\<and>(T s = a)\n                                \\<comment>\\<open>describe H using ownB\\<close>\n                                  \\<and>(H s = d)\n                                \\<comment>\\<open>describe W view (tempW) using ownB\\<close>\n                                  \\<and>(d>c\\<longrightarrow>offset s=c)\n                                  \\<and>(d>c\\<longrightarrow>Data s (numEnqs s)=d-c)\n                                \\<comment>\\<open>describe R view (tempR) using ownB\\<close>\n                                  \\<and>(b>a\\<longrightarrow>fst(tempR s)=a)\n                                  \\<and>(b>a\\<longrightarrow>snd(tempR s)=b-a)\n                                \\<comment>\\<open>describe Q view (hd(Q), last(Q)) using ownB\\<close>\n                                  \\<and>(length(q s)\\<le>c-b)\n                                  \\<and>(c>b\\<longrightarrow>length(q s)>0)\n                                  \\<and>(c>b\\<longrightarrow>fst(hd(q s)) =b)\n                                  \\<and>(c>b\\<longrightarrow>fst(last(q s))+snd(last(q s)) =c)\n                                \\<comment>\\<open>describe ownT using ownB\\<close>\n                                  \\<and>(ownT s = R\\<longrightarrow>b>a)\n                                  \\<and>((b=a\\<and>c>b)\\<longrightarrow>ownT s = Q)\n                                  \\<and>((b=a\\<and>c=b)\\<longrightarrow>ownT s \\<in> {Q,W})\n                                  \\<and> (ownT s=W\\<longrightarrow>((c=0\\<and>d>0)\\<or>(H s=T s)))\n)\"\n\n\nlemma can_a_equal_d:\n  assumes \"\\<forall>i.(i<N)\\<longrightarrow>ownB s i=B\"\n  and \"ownT s=Q\"\n  and \"H s=k\"\n  and \"T s=k\"\n  and \"k<N\"  (*this allows H=T\\<noteq>N*)\n  and \"q s=[]\"\n  and \"ownB s N=None\"\n  shows \"case_1 s\"\n  using assms apply (simp add:case_1_def)\n  apply (rule_tac exI [where x =\"k\"])\n  apply (rule_tac exI [where x =\"k\"])\n  apply simp\n  apply (rule_tac exI [where x =\"k\"])\n  by simp\n\n\n\ndefinition \"case_2 s  \\<equiv> \\<exists>a b c d e f. (0\\<le>a \\<and> a\\<le>b \\<and> b\\<le>c \\<and> c<d \\<and> d\\<le>e \\<and> e\\<le>f \\<and> f\\<le>N\n                                        \\<and>(\\<forall>i.(0\\<le>i \\<and> i<a)\\<longrightarrow>ownB s i = R)\n                                        \\<and>(\\<forall>i.(a\\<le>i \\<and> i<b)\\<longrightarrow>ownB s i = Q)\n                                        \\<and>(\\<forall>i.(b\\<le>i \\<and> i<c)\\<longrightarrow>ownB s i = W)\n                                        \\<and>(\\<forall>i.(c\\<le>i \\<and> i<d)\\<longrightarrow>ownB s i = B)\n                                        \\<and>(\\<forall>i.(d\\<le>i \\<and> i<e)\\<longrightarrow>ownB s i = R)\n                                        \\<and>(\\<forall>i.(e\\<le>i \\<and> i<f)\\<longrightarrow>ownB s i = Q)\n                                        \\<and>(\\<forall>i.(f\\<le>i \\<and> i<N)\\<longrightarrow>ownB s i = D)\n                                        \\<and>(ownB s N = None)\n                                \\<comment>\\<open>general case rules\\<close>\n                                  \\<and>(a>0\\<longrightarrow>e=d)                  \\<comment>\\<open>only 1 continuous read\\<close>  \n                                  \\<and>(e>d\\<longrightarrow>a=0)                  \\<comment>\\<open>only 1 continuous read\\<close>  \n                                  \\<and>(f>e\\<longrightarrow>a=0)                  \\<comment>\\<open>only 1 continuous queue\\<close> \n                                  \\<and>(c>0)                  \\<comment>\\<open>create the overlap, any way possible\\<close> \n                                \\<comment>\\<open>describe T using ownB\\<close>\n                                  \\<and>(T s = d)\n                                \\<comment>\\<open>describe H using ownB\\<close>\n                                  \\<and>(H s = c)\n                                \\<comment>\\<open>describe W view (tempW) using ownB\\<close>\n                                  \\<and>(c>b\\<longrightarrow>offset s = b)\n                                  \\<and>(c>b\\<longrightarrow>Data s (numEnqs s) = c-b)\n                                \\<comment>\\<open>describe R view (tempR) using ownB\\<close>\n                                  \\<and>(a>0\\<longrightarrow>fst(tempR s)=0) \n                                  \\<and>(a>0\\<longrightarrow>snd(tempR s)=a)  \n                                  \\<and>(e>d\\<longrightarrow>fst(tempR s)=d) \n                                  \\<and>(e>d\\<longrightarrow>snd(tempR s)=e-d)  \n                                \\<comment>\\<open>describe Q view (hd(Q), last(Q)) using ownB\\<close>\n                                  \\<and>(length(q s)\\<le>(f-e+b-a))\n                                  \\<and>((f>e\\<or>b>a)\\<longrightarrow>length(q s)>0)\n                                  \\<and>(f>e\\<longrightarrow>fst(hd(q s)) =e)\n                                  \\<and>((f=e\\<and>b>a)\\<longrightarrow>fst(hd(q s)) =a)\n                                  \\<and>(b>a\\<longrightarrow>fst(last(q s))+snd(last(q s)) =b)\n                                  \\<and>((b=a\\<and>f>e)\\<longrightarrow>fst(last(q s))+snd(last(q s)) =f)\n                                \\<comment>\\<open>describe ownT using ownB\\<close>\n                                  \\<and>(ownT s = R\\<longrightarrow>(a>0\\<or>e>d))\n                                  \\<and>((a=0\\<and>e=d)\\<longrightarrow>ownT s = Q)\n                                  \\<and>(ownT s\\<noteq>W)\n)\"\n\n\n\nlemma natural:\n  assumes \"a\\<in>{0,3,4}\"\n  shows \"a\\<in>\\<nat>\"\n  using assms apply simp\n  by auto\n\n\n\nlemma case_split:\n  shows \"H s\\<ge>T s\\<Longrightarrow> (case_1 s \\<or> case_2 s) \\<Longrightarrow> case_1 s\"\n  apply (simp add:case_1_def case_2_def) apply clarify\n  by linarith\n\n\nlemma case_split_2:\n  shows \"H s\\<ge>T s\\<Longrightarrow> (case_1 s \\<or> case_2 s) \\<Longrightarrow>\\<not> case_2 s\"\n  by (simp add:case_1_def case_2_def) \n\nlemma case_split_3:\n  shows \"H s<T s\\<Longrightarrow> (case_1 s \\<or> case_2 s) \\<Longrightarrow> case_2 s\"\n  apply (simp add:case_1_def case_2_def) apply clarify\n  by linarith\n\n\nlemma case_split_4:\n  shows \"H s<T s\\<Longrightarrow> (case_1 s \\<or> case_2 s) \\<Longrightarrow>\\<not> case_1 s\"\n  by (simp add:case_1_def case_2_def)\n\n\nlemma case_split_5:\n  shows \"(case_1 s \\<and> case_2 s) \\<Longrightarrow>False\"\n  apply (simp add:case_1_def case_2_def) \n  apply clarify\n  apply (case_tac \"H s\\<ge>T s\") \n  apply(subgoal_tac \"case_1 s\") prefer 2 \n  apply (metis leD)\n  apply (metis case_split_4)\n  apply(subgoal_tac \"T s>H s\") prefer 2\n  apply blast\n  apply(subgoal_tac \"case_2 s\") prefer 2\n  apply (metis le_trans)\n  using case_split_2 [where s=s] \n  by (metis le_trans)\n\n\n\n\n(*\ndeclare [[show_types]]\n*)\n\n\n\n\n(*   State of the queue   *)\n(*   What Q should look like   *)\n\ndefinition  \"end x \\<equiv> fst x + snd x\"\n\nlemmas end_simp [simp] = end_def \n\ndefinition \"Q_boundness s \\<equiv> (\\<forall>x. (x \\<in> set (q s)) \\<longrightarrow> end x \\<le> N)\" \n\ndefinition \"Q_offsets_differ s \\<equiv> (\\<forall>i j.(i<length(q s)\\<and> j<length(q s)\\<and> i\\<noteq>j)\\<longrightarrow>(fst(q s!i)\\<noteq>fst(q s!j)))\"\n\ndefinition \"Q_gap_structure s   \\<equiv> \n          (\\<forall>i. (i < length(q s) \\<and> i > 0) \\<longrightarrow>((end(q s!(i-1)) = fst(q s!i))\\<or> (fst(q s!i) =0)))\"\n\ndefinition \"Q_has_no_uroboros s \\<equiv>\n(\\<forall>x. x \\<in> set (q s)\\<longrightarrow> fst x \\<noteq> end (last (q s)))\"\n\ndefinition \"Q_has_no_overlaps s \\<equiv>\n(\\<forall> x y. (x \\<in> set (q s) \\<and> y \\<in> set (q s)) \\<longrightarrow> (fst(x) < fst(y) \\<longrightarrow> end x \\<le> fst y))\"\n\ndefinition \"Q_elem_size s       \\<equiv> \\<forall>x.(x\\<in>set(q s))\\<longrightarrow>snd(x)>0\"\n\ndefinition \"Q_basic_struct s \\<equiv> Q_boundness s \\<and> Q_gap_structure s \\<and> Q_offsets_differ s\n                              \\<and> Q_has_no_overlaps s \\<and> Q_has_no_uroboros s \\<and> Q_elem_size s\"\n\n\nlemmas Q_basic_lemmas = Q_basic_struct_def  Q_has_no_overlaps_def \n                        Q_gap_structure_def Q_has_no_uroboros_def\n                        Q_boundness_def     Q_offsets_differ_def\n                        Q_elem_size_def\n\nlemma proof_no_overlaps:\n  assumes \"Q_gap_structure s\"\n  and \"Q_offsets_differ s\"\n  and \"\\<forall>i.(i<length(q s))\\<longrightarrow> snd(q s!i)>0\"\n  and \"length(q s)>1\"\n  and \"Q_has_no_overlaps s\"\nshows \"\\<forall>x y.(x\\<in>set(q s)\\<and>y\\<in>set(q s)\\<and>length(q s)>1\\<and>fst(x)\\<noteq>fst(y))\\<longrightarrow>\n  (\\<forall>j.(fst(x)\\<le>j \\<and> j<end(x))\\<longrightarrow>(j<fst(y)\\<or>j\\<ge>end(y)))\"\n  using assms apply (simp add:Q_basic_lemmas) \n  apply safe \n  by (smt (verit, best) bot_nat_0.not_eq_extremum diff_is_0_eq le_trans linorder_neqE_nat zero_less_diff)\n\nlemma tail_preserves_Q_boundness:\n  assumes \"Q_boundness s\"\n  and \"tl(q s)\\<noteq>[]\"\nshows \"(\\<forall>x. (x \\<in> set (tl(q s))) \\<longrightarrow> end x \\<le> N)\"\n  using assms  apply (simp add:Q_boundness_def)\n  by (simp add: list.set_sel(2) tl_Nil)\n\nlemma tail_preserves_Q_offsets_differ:\n  assumes \"Q_offsets_differ s\"\n  and \"tl(q s)\\<noteq>[]\"\nshows \"(\\<forall>i j.(i<length(tl(q s))\\<and> j<length(tl(q s))\\<and> i\\<noteq>j)\\<longrightarrow>(fst((tl(q s))!i)\\<noteq>fst((tl(q s))!j)))\"\n  using assms  apply (simp add:Q_offsets_differ_def) \n  by (simp add: Nitpick.size_list_simp(2) nth_tl tl_Nil)\n\nlemma tail_preserves_Q_gap_structure:\n  assumes \"Q_gap_structure s\"\n  and \"tl(q s)\\<noteq>[]\"\nshows \"(\\<forall>i. (i < length(tl(q s)) \\<and> i > 0) \\<longrightarrow>((end((tl(q s))!(i-1)) = fst((tl(q s))!i))\\<or> (fst((tl(q s))!i) =0)))\"\n  using assms  apply (simp add:Q_gap_structure_def) \n  by (smt (verit) One_nat_def Suc_pred add_diff_cancel_left' length_tl less_Suc_eq less_diff_conv not_less_eq nth_tl plus_1_eq_Suc)\n\nlemma tail_preserves_Q_has_no_uroboros:\n  assumes \"Q_has_no_uroboros s\"\n  and \"tl(q s)\\<noteq>[]\"\nshows \"(\\<forall>x. x \\<in> set (tl(q s)) \\<longrightarrow> fst x \\<noteq> end (last (tl(q s))))\"\n  using assms  apply (simp add:Q_has_no_uroboros_def)\n  by (metis last_tl list.sel(2) list.set_sel(2))\n\nlemma tail_preserves_Q_has_no_overlaps:\n  assumes \"Q_has_no_overlaps s\"\n  and \"tl(q s)\\<noteq>[]\"\nshows \"(\\<forall> x y. (fst(x) < fst(y) \\<and> x \\<in> set (tl(q s)) \\<and> y \\<in> set (tl(q s))) \\<longrightarrow> (end x \\<le> fst y))\"\n  using assms  apply (simp add:Q_has_no_overlaps_def) \n  by (metis list.sel(2) list.set_sel(2))\n\nlemma tail_preserves_Q_basic_struct:\n  assumes \"Q_basic_struct s\"\n  and \"tl(q s)\\<noteq>[]\"\nshows \"(\\<forall>x. (x \\<in> set (tl(q s))) \\<longrightarrow> end x \\<le> N) \\<and> \n       (\\<forall>i j.(i<length(tl(q s))\\<and> j<length(tl(q s))\\<and> i\\<noteq>j)\\<longrightarrow>(fst((tl(q s))!i)\\<noteq>fst((tl(q s))!j))) \\<and>\n       (\\<forall>i. (i < length(tl(q s)) \\<and> i > 0) \\<longrightarrow>((end((tl(q s))!(i-1)) = fst((tl(q s))!i))\\<or> (fst((tl(q s))!i) =0)))\\<and>\n       (\\<forall>x. x \\<in> set (tl(q s)) \\<longrightarrow> fst x \\<noteq> end (last (tl(q s)))) \\<and>\n       (\\<forall> x y. (fst(x) < fst(y) \\<and> x \\<in> set (tl(q s)) \\<and> y \\<in> set (tl(q s))) \\<longrightarrow> (end x \\<le> fst y))\"\n  using assms  apply (simp add:Q_basic_lemmas)\n  apply(intro conjI impI)\n  apply (metis list.sel(2) list.set_sel(2))\n  using tail_preserves_Q_offsets_differ apply (metis One_nat_def Q_basic_struct_def assms(1) length_tl)\n  using tail_preserves_Q_gap_structure apply (metis One_nat_def Q_basic_struct_def assms(1) end_simp length_tl)\n  using tail_preserves_Q_has_no_uroboros apply (metis Q_basic_struct_def assms(1) end_simp old.prod.inject prod.collapse)\n  by (metis list.sel(2) list.set_sel(2))\n\n\n\n\n\n\n\n\n\n\n\n(*\n(*have the idea of \"can fit between T-N or not\"*)\ndefinition \"T_is_outside_Q s    \\<equiv> (\\<forall>i.(i<length(q s) \\<and> q s\\<noteq>[])\\<longrightarrow>(end(q s!i)<T s))\"\n\ndefinition \"tempR_describes_T s \\<equiv> ((fst(tempR s) =0) \\<longrightarrow> (T s=0 \\<or> T_is_outside_Q s))\n                                 \\<and>((fst(tempR s) >0) \\<longrightarrow> (T s=fst(tempR s)))\"\n\ndefinition \"Q_describes_T s     \\<equiv> ((fst(hd(q s)) =0) \\<longrightarrow> (T s=0 \\<or> T_is_outside_Q s))\n                                 \\<and>((fst(hd(q s)) >0) \\<longrightarrow> (T s=fst(hd(q s))))\"\n*)\n\n\n(*have the idea of \"can we describe ownB s i=R\"*)\n(*\ndefinition \"R_owns_no_bytes s   \\<equiv> (\\<forall>i.(i\\<ge>0)\\<longrightarrow>ownB s i\\<noteq>R)\"\n\ndefinition \"tempR_describes_ownB s \\<equiv> (\\<forall>i.(i<fst(tempR s))\\<longrightarrow>ownB s i\\<noteq>R)\n                                    \\<and>(\\<forall>i.(i\\<ge>end(tempR s))\\<longrightarrow>ownB s i\\<noteq>R)\n                                    \\<and>(\\<forall>i.(fst(tempR s)\\<le>i \\<and> i<end(tempR s))\\<longrightarrow>ownB s i=R)\"\n*)\n\n\n\n\n\n\ndefinition \"tempR_bounded s     \\<equiv> end(tempR s)\\<le>N\"\ndefinition \"Q_no_overlap_tempR s\\<equiv> (\\<forall>x. (x \\<in> set (q s))\\<longrightarrow>\n                  ((fst(tempR s)<fst(x)\\<and>end(tempR s)\\<le> fst(x))\n                  \\<or>(fst(x)<fst(tempR s)\\<and>end(x)<fst(tempR s))))\"\ndefinition \"Q_relates_tempR s   \\<equiv> (end(tempR s) = fst(hd (q s))) \\<or> (fst(hd(q s)) = 0)\"\nlemmas tmepR_extra_lemmas [simp] = tempR_bounded_def Q_no_overlap_tempR_def Q_relates_tempR_def\n\n\n(*   Relating Q to other variables   *)\n(*\ndefinition \"Q_bytes s     \\<equiv> {i  . \\<exists> k l. (k, l) \\<in> set(q s) \\<and> k \\<le> i \\<and> i < k+l}\"\n\ndefinition \"Q_bytes_inv s \\<equiv> \\<forall> i. i \\<in> Q_bytes s \\<longleftrightarrow>  ownB s i = Q\"\n\n*)\n\n\n\n  \n\n\n\n\ndefinition \"Q_holds_bytes s     \\<equiv> q s\\<noteq>[]\\<longrightarrow>(\\<forall>i.(i\\<in>set(q s))\\<longrightarrow>(\\<forall>j.(fst(i)\\<le>j \\<and> j<end(i))\\<longrightarrow>ownB s j=Q))\"\n\ndefinition \"Q_reflects_writes s \\<equiv> (\\<forall>i.(i<length(q s))\\<longrightarrow>data_index s (q s!i) = ((numDeqs s) +i))\"\n\ndefinition \"Q_elem_rel s        \\<equiv> (\\<forall>i.(i<length(q s))\\<longrightarrow>snd(q s!i) =Data s ((numDeqs s) +i))\"\n\ndefinition \"Q_reflects_ownD s   \\<equiv> (\\<forall>i.(i<length(q s))\\<longrightarrow>ownD s (i+(numDeqs s)) =B)\"\n\n\n\n\n\nlemma tail_preserves_Q_holds_bytes:\n  assumes \"Q_holds_bytes s\"\n  and \"(tl(q s))\\<noteq>[]\"\nshows \"(tl(q s))\\<noteq>[]\\<longrightarrow>(\\<forall>i.(i\\<in>set(tl(q s)))\\<longrightarrow>(\\<forall>j.(fst(i)\\<le>j \\<and> j<end(i))\\<longrightarrow>ownB s j=Q))\"\n  using assms  apply (simp add:Q_holds_bytes_def)\n  by (metis list.sel(2) list.set_sel(2))\n\nlemma tail_preserves_Q_reflects_writes:\n  assumes \"Q_reflects_writes s\"\n  and \"(tl(q s))\\<noteq>[]\"\nshows \"(\\<forall>i.(i<length(tl(q s)))\\<longrightarrow>data_index s ((tl(q s))!i) = ((numDeqs s) +i +1))\"\n  using assms  apply (simp add:Q_reflects_writes_def)\n  by (simp add: nth_tl)\n\nlemma tail_preserves_Q_elem_size:\n  assumes \"Q_elem_rel s\"\n  and \"(tl(q s))\\<noteq>[]\"\nshows \"(\\<forall>i.(i<length(tl(q s)))\\<longrightarrow>snd((tl(q s))!i) =Data s ((numDeqs s) +i +1))\"\n  using assms  apply (simp add:Q_elem_size_def)\n  by (simp add: Q_elem_rel_def nth_tl)\n\nlemma tail_preserves_Q_reflects_ownD:\n  assumes \"Q_reflects_ownD s\"\n  and \"(tl(q s))\\<noteq>[]\"\nshows \"(\\<forall>i.(i<length(tl(q s)))\\<longrightarrow>ownD s (i+(numDeqs s) +1) =B)\"\n  using assms  apply (simp add:Q_reflects_ownD_def) \n  by (metis One_nat_def Suc_eq_plus1 add.assoc less_diff_conv plus_1_eq_Suc)\n\nlemma Q_offsets_imply_tail_offsets:\n  assumes \"Q_offsets_differ s\"\n  shows \"(\\<forall>i j.(i<length(tl(q s))\\<and> j<length(tl(q s))\\<and> i\\<noteq>j)\\<longrightarrow>(fst(tl(q s)!i)\\<noteq>fst(tl(q s)!j)))\"\n  using assms apply (simp add:Q_offsets_differ_def)\n  by (metis (no_types, lifting) Nat.lessE One_nat_def Suc_pred length_tl less_Suc_eq_0_disj nth_tl old.nat.inject zero_less_diff)\n\nlemma Q_head_relates_tail:\n  assumes \"Q_offsets_differ s\"\n  shows \"\\<forall>i.(i<length(tl(q s)))\\<longrightarrow>fst(q s!0)\\<noteq> fst(tl(q s)!i)\"\n  using assms apply (simp add:Q_offsets_differ_def)\n  by (metis One_nat_def Suc_pred length_tl less_Suc_eq_0_disj not_less_eq nth_tl zero_less_diff)\n\nlemma Exists_one_implies_exist_no_more:\n  assumes \"Q_offsets_differ s\"\n  and \"Q_gap_structure s\"\nshows \"if \\<exists>j.(fst(q s!j) =0 \\<and> j<length(q s)) then (\\<exists>j.(\\<forall>i.(i<length(q s) \\<and> i\\<noteq>j \\<and> i>0)\\<longrightarrow>(end(q s!(i-1)) =fst(q s!i))))\n  else (\\<forall>i.(i>0 \\<and> i<length(q s))\\<longrightarrow>end(q s!(i-1)) = fst(q s!i))\"\n  using assms apply (simp add:Q_basic_lemmas)\n  apply (case_tac \"\\<exists>j.(fst(q s!j) =0 \\<and> j<length(q s))\", simp_all)\n  apply (metis gr_implies_not0)\n  by (metis less_nat_zero_code)\n  \nlemma Q_hd_zero_implies_structure:\n  assumes \"Q_offsets_differ s\"\n  and \"Q_gap_structure s\"\n  and \"fst(hd(q s)) =0\"\nshows \"\\<forall>i.(i>0 \\<and> i<length(q s))\\<longrightarrow>end(q s!(i-1)) =fst(q s!i)\"\n  using assms apply(simp add:Q_basic_lemmas)\n  by (metis drop0 hd_drop_conv_nth less_Suc_eq_0_disj less_imp_Suc_add not_gr_zero)\n\nlemma data_index_preserved_lemma:\n  assumes \"Q_reflects_writes s\"\n  and \"length(q s)>0\"\n  shows \"data_index s(q s!0) = numDeqs s\"\n  using assms by (simp add:Q_reflects_writes_def)\n\n\ndefinition \"Q_structure s \\<equiv>q s\\<noteq>[]\\<longrightarrow>(Q_basic_struct s \\<and> \n                                      \\<comment> \\<open>Q_holds_bytes s \\<and>\\<close>\n                                      Q_reflects_writes s \\<and> \n                                      Q_elem_rel s \\<and> \n                                      Q_reflects_ownD s)\"\n\n\n \nlemmas Q_lemmas = Q_holds_bytes_def Q_reflects_writes_def Q_reflects_ownD_def\n                  Q_structure_def Q_relates_tempR_def Q_elem_rel_def\n                  Q_elem_size_def Q_no_overlap_tempR_def\n\n\n\nlemma head_q0:\n  assumes \"length(q s)>0\"\n  shows \"hd(q s) = (q s!0)\"\n  using assms apply (simp add:Q_reflects_writes_def)\n  by (simp add: hd_conv_nth)\n\nlemma overlap:\n  assumes \"Q_structure s \\<and> length(q s)>1\"\n  shows \"\\<nexists>k.(\\<forall>i j.(i<length(q s)\\<and> j<length(q s)\\<and> i\\<noteq>j)\\<longrightarrow>(k\\<ge>fst(q s!i)\\<and> k<end(q s!i)\\<and>k\\<ge>fst(q s!j)\\<and>k<end(q s!j)))\"\n  using assms apply simp \n  apply(simp add:Q_lemmas Q_basic_lemmas) \n  apply(elim conjE impE) apply clarify \n  apply simp \n  by (smt One_nat_def Suc_lessD add_diff_cancel_left' le_0_eq le_less_trans less_numeral_extra(1) not_less nth_mem plus_1_eq_Suc prod.collapse)\n\nlemma Q_has_0_elem:\n  assumes \"Q_gap_structure s\"\n  and \"Q_offsets_differ s\"\n  and \"hd(q s) =(0,a)\"\nshows \"fst(hd(q s)) =0\\<longrightarrow>(\\<forall>i.(i<length(q s)\\<and> i>0)\\<longrightarrow>end(q s!(i-1)) =fst(q s!i))\"\n  using assms apply auto\n  apply (simp add:Q_gap_structure_def Q_offsets_differ_def)\n  by (metis gr_implies_not_zero head_q0 not_gr_zero old.prod.inject prod.collapse)\n\n\nlemma Q_gap_lemmas_1:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  shows \"last(q s)\\<in>set(q s)\"\n  using assms by (simp add:con_assms_def)\n\nlemma Q_gap_lemmas_2:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  shows \"\\<forall>i.(i<length(q s))\\<longrightarrow>(q s!i)\\<in>set(q s)\"\n  using assms by (simp add:con_assms_def)\n\nlemma Q_gap_lemmas_3:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  shows \"\\<forall>x y.(x\\<in>set(q s) \\<and> y\\<in>set(q s) \\<and> fst(y)\\<noteq>fst(x))\\<longrightarrow>(fst(x)>fst(y)\\<or>fst(y)>fst(x))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n  by linarith\n\n\nlemma Q_gap_lemmas_4:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  shows \"\\<forall>x y.(x\\<in>set(q s) \\<and> y\\<in>set(q s) \\<and> fst(y)>fst(x))\\<longrightarrow>end(y)>fst(x)\"\n  using assms by (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n\nlemma Q_gap_lemmas_5:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  shows \"\\<forall>x y.(x\\<in>set(q s) \\<and> y\\<in>set(q s) \\<and> fst(y)>fst(x))\\<longrightarrow>(fst(y)\\<ge>end(x))\"\n  using assms by (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n\nlemma Q_gap_lemmas_6:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  shows \"\\<forall>x y.(x\\<in>set(q s) \\<and> y\\<in>set(q s) \\<and> fst(y)>fst(x))\\<longrightarrow>(end(y)>end(x))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n  by (smt (verit, best) diff_add_inverse diff_is_0_eq le_add1 le_neq_implies_less le_trans length_greater_0_conv list.size(3))\n\nlemma Q_gap_lemmas_7:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  shows \"\\<forall>x y.(x\\<in>set(q s) \\<and> y\\<in>set(q s) \\<and> fst(y)\\<ge>end(x))\\<longrightarrow>(end(y)>fst(x))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n  by (metis add_leD1 le_neq_implies_less less_add_same_cancel1 trans_less_add1)\n\nlemma Q_gap_lemmas_8:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  shows \"\\<forall>x y.(x\\<in>set(q s) \\<and> y\\<in>set(q s) \\<and> fst(y)\\<ge>end(x))\\<longrightarrow>(fst(y)>fst(x))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n  by (metis add_leD1 diff_add_0 diff_add_inverse diff_diff_cancel minus_nat.diff_0 nat_less_le)\n\nlemma Q_gap_lemmas_9:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  shows \"\\<forall>x y.(x\\<in>set(q s) \\<and> y\\<in>set(q s) \\<and> fst(y)\\<ge>end(x))\\<longrightarrow>(end(y)>end(x))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n  by (metis le_eq_less_or_eq less_add_same_cancel1 trans_less_add1)\n\nlemma Q_gap_lemmas_10:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  shows \"\\<forall>x y.(x\\<in>set(q s) \\<and> y\\<in>set(q s) \\<and> end(y)>fst(x) \\<and> fst(y)\\<noteq>fst(x))\\<longrightarrow>(fst(y)>fst(x))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n  by (metis le_antisym less_or_eq_imp_le nat_neq_iff)\n\nlemma Q_gap_lemmas_11:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  shows \"\\<forall>x y.(x\\<in>set(q s) \\<and> y\\<in>set(q s) \\<and> end(y)>fst(x) \\<and> fst(y)\\<noteq>fst(x))\\<longrightarrow>(end(y)>end(x))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n  by (smt (verit, ccfv_SIG) diff_add_inverse diff_is_0_eq le_antisym le_trans less_or_eq_imp_le nat_neq_iff)\n\n\nlemma Q_gap_lemmas_12:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  shows \"\\<forall>x y.(x\\<in>set(q s) \\<and> y\\<in>set(q s) \\<and> end(y)>fst(x) \\<and> fst(y)\\<noteq>fst(x))\\<longrightarrow>(fst(y)\\<ge>end(x))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n  by (metis le_antisym less_or_eq_imp_le nat_neq_iff)\n\n\nlemma Q_gap_lemmas_13:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  shows \"\\<forall>x y.(x\\<in>set(q s) \\<and> y\\<in>set(q s) \\<and> end(y)>end(x))\\<longrightarrow>(end(y)>fst(x))\"\n  using assms by (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n\n\n\nlemma Q_gap_lemmas_14:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  shows \"\\<forall>x y.(x\\<in>set(q s) \\<and> y\\<in>set(q s) \\<and> end(y)>end(x) \\<and> fst(y)\\<noteq>fst(x))\\<longrightarrow>(fst(y)\\<ge>end(x))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n  by (metis diff_diff_left diff_is_0_eq less_nat_zero_code linorder_neqE_nat zero_less_diff)\n\n\nlemma Q_gap_lemmas_15:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  shows \"\\<forall>x y.(x\\<in>set(q s) \\<and> y\\<in>set(q s) \\<and> end(y)>end(x))\\<longrightarrow>(fst(y)\\<noteq>fst(x))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n  by (metis fst_conv in_set_conv_nth nat_neq_iff old.prod.inject)\n\nlemma Q_gap_lemmas_16_B:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  and \"x\\<in>set(q s)\" \n  and \"y\\<in>set(q s)\" \n  and \"end(y)>end(x)\"\nshows \"fst(y)\\<ge>end(x)\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas) \n  using Q_gap_lemmas_14 Q_gap_lemmas_15\n  by (metis assms(1) assms(2) end_simp fst_conv snd_conv)\n\n\nlemma Q_gap_lemmas_16:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  shows \"\\<forall>x y.(x\\<in>set(q s) \\<and> y\\<in>set(q s) \\<and> end(y)>end(x))\\<longrightarrow>(fst(y)\\<ge>end(x))\"\n  using Q_gap_lemmas_16_B assms by blast\n\n\n\nlemma Q_gap_lemmas_17:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  shows \"\\<forall>x y.(x\\<in>set(q s) \\<and> y\\<in>set(q s) \\<and> end(y)>end(x))\\<longrightarrow>(fst(y)>fst(x))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n  by (metis Q_gap_lemmas_15 Q_gap_lemmas_10 add_lessD1 assms(1) assms(2) end_simp fst_conv snd_conv)\n\n\n\n\n\nlemma Q_gap_lemmas_1_list:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> j<length(q s) \\<and> i\\<noteq>j)\\<longrightarrow>(fst(q s!i)>fst(q s!j) \\<or>\n                                                     fst(q s!i)<fst(q s!j))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas) \n  by (meson nat_neq_iff)\n\n\nlemma Q_gap_lemmas_2_list:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> j<length(q s) \\<and> fst(q s!i)>fst(q s!j))\\<longrightarrow>\n                            (end(q s!i)>fst(q s!j))\"\n  using assms by (simp add:con_assms_def Q_lemmas Q_basic_lemmas) \n\n\nlemma Q_gap_lemmas_3_list:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> j<length(q s) \\<and> fst(q s!i)>fst(q s!j))\\<longrightarrow>\n                            (end(q s!i)>end(q s!j))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n  by (metis Q_gap_lemmas_6 assms(1) end_simp length_pos_if_in_set nth_mem)\n\n\nlemma Q_gap_lemmas_4_list:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> j<length(q s) \\<and> fst(q s!i)>fst(q s!j))\\<longrightarrow>\n                            (fst(q s!i)\\<ge>end(q s!j))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n  by (metis Q_gap_lemmas_2 assms(1) assms(2) prod.collapse)\n\n\n\nlemma Q_gap_lemmas_5_list:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> j<length(q s) \\<and> fst(q s!i)\\<ge>end(q s!j))\\<longrightarrow>\n                            (fst(q s!i)>fst(q s!j))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n  by (metis Q_gap_lemmas_8 assms(1) end_simp length_pos_if_in_set nth_mem)\n\n\n\nlemma Q_gap_lemmas_6_list:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> j<length(q s) \\<and> fst(q s!i)\\<ge>end(q s!j))\\<longrightarrow>\n                            (end(q s!i)>fst(q s!j))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n  by (metis Q_gap_lemmas_7 assms(1) end_simp length_pos_if_in_set nth_mem)\n\n\nlemma Q_gap_lemmas_7_list:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> j<length(q s) \\<and> fst(q s!i)\\<ge>end(q s!j))\\<longrightarrow>\n                            (end(q s!i)>end(q s!j))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n  by (metis le_eq_less_or_eq less_add_same_cancel1 nth_mem surjective_pairing trans_less_add1)\n\n\nlemma Q_gap_lemmas_8_list:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> j<length(q s) \\<and> end(q s!i)>fst(q s!j) \\<and> i\\<noteq>j)\\<longrightarrow>\n                            (fst(q s!i)>fst(q s!j))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas) \n  using Q_gap_lemmas_10\n  by (metis assms(1) end_simp length_pos_if_in_set nth_mem)\n\nlemma Q_gap_lemmas_9_list_B:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  and \"i<length(q s)\" \n  and \"j<length(q s)\" \n  and \"end(q s!i)>fst(q s!j)\" \n  and \"i\\<noteq>j\"\nshows \"end(q s!i)>end(q s!j)\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas) \n  by (metis Q_gap_lemmas_11 assms(1) end_simp length_pos_if_in_set nth_mem)\n\n\nlemma Q_gap_lemmas_9_list:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> j<length(q s) \\<and> end(q s!i)>fst(q s!j) \\<and> i\\<noteq>j)\\<longrightarrow>\n                            (end(q s!i)>end(q s!j))\"\n  using assms Q_gap_lemmas_9_list_B by blast\n\n\nlemma Q_gap_lemmas_10_list:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> j<length(q s) \\<and> end(q s!i)>fst(q s!j) \\<and> i\\<noteq>j)\\<longrightarrow>\n                            (fst(q s!i)\\<ge>end(q s!j))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n  using Q_gap_lemmas_12\n  by (metis assms(1) end_simp length_pos_if_in_set nth_mem)\n\n\n\nlemma Q_gap_lemmas_11_list:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> j<length(q s) \\<and> end(q s!i)>end(q s!j))\\<longrightarrow>\n                            (end(q s!i)>fst(q s!j))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n  by (metis add_lessD1)\n\n\nlemma Q_gap_lemmas_12_list:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> j<length(q s) \\<and> end(q s!i)>end(q s!j))\\<longrightarrow>\n                            (fst(q s!i)\\<ge>end(q s!j))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n  using Q_gap_lemmas_16 \n  by (metis Q_gap_lemmas_2 assms(1) assms(2) end_simp)\n\n\nlemma Q_gap_lemmas_13_list:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> j<length(q s) \\<and> end(q s!i)>end(q s!j))\\<longrightarrow>\n                            (fst(q s!i)>fst(q s!j))\"\n  using assms apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas)\n  using Q_gap_lemmas_17\n  by (metis Q_gap_lemmas_2 assms(1) assms(2) end_simp)\n\n\n\n\n  \n\n\n\n(**********)\nlemma ownB_lemma:\n  assumes \"length(q s) =2\"\n  and \"Q_holds_bytes s\"\n  and \"Q_has_no_overlaps s\"\n  and \"Q_offsets_differ s\"\n  and \"s' = (`q:= (tl(q s)) \\<circ> (setownB [(fst(hd(q s)),(end(hd(q s)))) R])) s\"\nshows \"Q_holds_bytes s' \"\n  using assms apply (simp add:Q_lemmas Q_basic_lemmas)\n  apply (intro conjI impI) apply clarify apply safe\n  apply simp\n      apply simp\n     apply auto[1]\n  apply(case_tac \"a<fst(hd(q s))\", simp_all)\n  defer\n  apply(case_tac \"fst(hd(q s))<a\", simp_all)\n\n  apply (smt Suc_1 head_q0 le_less_trans length_greater_0_conv list.set_sel(2) not_less nth_mem plus_1_eq_Suc prod.collapse zero_less_two)\n  apply(case_tac \"fst(hd(q s)) =fst(a,b)\") \n  apply (metis (mono_tags, hide_lams) One_nat_def Suc_1 Suc_leI diff_Suc_1 diff_is_0_eq' hd_conv_nth in_set_conv_nth length_tl lessI list.sel(2) nat.simps(3) nth_tl zero_less_Suc)\n  apply(simp add:fst_def) \n  apply (metis (no_types, lifting) One_nat_def Suc_1 add_diff_cancel_left' in_set_conv_nth length_tl less_one nat_neq_iff nth_tl plus_1_eq_Suc zero_less_two)\n  apply (metis list.sel(2) list.set_sel(2)) \n  by (metis (no_types, lifting) hd_in_set le_add_diff_inverse2 length_0_conv list.set_sel(2) prod.collapse trans_le_add2 verit_comp_simplify1(3) zero_neq_numeral)\n\n(*\nlemma ownB_lemma2:\n  assumes \"Q_holds_bytes s\"\n  and \"Q_structure s\"\n  and \"\\<forall>i.(i<n)\\<longrightarrow>Data s i>0\"\n  and \"q s\\<noteq>[]\"\n  and \"s' = (`q:= (tl(q s)) \\<circ> (setownB [(fst(hd(q s)),(end(hd(q s)))) R]) \\<circ> (`tempR := (hd(q s))) \n          \\<circ> (transownT [Q R s])\n          \\<circ> (`numDeqs :=(numDeqs s+1))) s\"\nshows \"Q_holds_bytes s'\"\n  using assms apply (simp add:Q_lemmas Q_basic_lemmas)\n  apply(elim conjE impE) \n  apply(case_tac \"ownT s=Q\", simp_all)\n   apply(case_tac \"length(q s) =1\", simp_all)\n  apply (metis diff_Suc_1 length_pos_if_in_set length_tl less_numeral_extra(3))\n   apply(case_tac \"length(q s) =2\", simp_all)\n  apply (smt Suc_1 add_diff_cancel_left' fst_conv fst_def hd_conv_nth in_set_conv_nth le_less_trans length_tl less_2_cases_iff less_Suc0 nat_arith.rule0 not_less nth_tl plus_1_eq_Suc prod.collapse)\n  apply clarify apply safe\n  apply(case_tac \"fst(hd(q s)) >a\", simp add:fst_def snd_def)\n  apply (smt fst_def hd_in_set le_imp_less_Suc le_less_trans list.set_sel(2) not_less_eq prod.collapse)\n       defer\n  apply(case_tac \"fst(hd(q s))<a\", simp add:fst_def snd_def)\n  apply (meson list.set_sel(2))\n  apply (meson list.set_sel(2))\n  apply(case_tac \"fst(hd(q s)) =fst(a,b)\", simp add:fst_def snd_def) \n  apply (smt One_nat_def Suc_mono Suc_pred fst_conv fst_def hd_conv_nth in_set_conv_nth length_greater_0_conv length_tl less_antisym not_less_zero nth_tl zero_induct)\n     apply(simp add:fst_def snd_def)\n  apply (smt Suc_leI fst_def hd_in_set le_trans linorder_neqE_nat list.set_sel(2) not_less_eq_eq prod.collapse snd_def)\n  apply(simp add:fst_def snd_def)\n  apply (meson list.set_sel(2))\n  apply (meson list.set_sel(2))\n  apply clarsimp \n  apply (case_tac \"a<fst(hd(q s))\", simp_all add:fst_def snd_def)\n  apply (case_tac \"a>fst(hd(q s))\", simp_all add:fst_def snd_def)\n  apply (smt fst_def hd_in_set le_less_trans list.set_sel(2) not_less prod.collapse snd_def)\n  by (smt One_nat_def Suc_mono Suc_pred fst_conv fst_def hd_conv_nth in_set_conv_nth length_greater_0_conv length_tl less_antisym not_less_zero nth_tl zero_induct)\n  \nlemma Q_type_1:\n  assumes \"q s=[(3,2),(5,2),(0,1)] \\<and> N=10\"\n  shows \"Q_basic_struct s\"\n  using assms apply(simp add:Q_basic_struct_def) \n  apply(intro conjI impI)\n  apply(simp add:Q_boundness_def)\n  apply(simp add:Q_gap_structure_def)\n  using less_Suc_eq apply force\n  apply(simp add:Q_offsets_differ_def)\n  using less_Suc_eq apply fastforce\n  apply(simp add:Q_has_no_overlaps_def)\n  using less_Suc_eq apply force\n  by(simp add:Q_has_no_uroboros_def) \n\nlemma Q_tail_props:\n  shows \"\\<forall>i.(i<length(q s) \\<and> i>0)\\<longrightarrow>(((q s)!i) = (tl(q s)!(i-1)))\"\n  apply simp\n  by (simp add: diff_less_mono nth_tl)\n\nlemma Q_basic_preserved:\n  assumes \"Q_basic_struct s\"\n  and \"s' = (`q:= (tl(q s))) s\"\n  shows \"Q_basic_struct s'\"\n  using assms apply(simp add:Q_basic_struct_def)\n  apply(intro conjI impI)\n  apply(simp add:Q_basic_struct_def Q_boundness_def) \n  apply (metis list.sel(2) list.set_sel(2))\n     apply(simp add:Q_basic_struct_def Q_gap_structure_def)\n    defer\n     apply(simp add:Q_offsets_differ_def)\n  apply (metis One_nat_def Suc_eq_plus1 diff_Suc_1 length_tl less_diff_conv nth_tl)\n    apply(simp add:Q_has_no_overlaps_def)\n    apply (metis list.sel(2) list.set_sel(2))\n  prefer 2 \n   apply (metis One_nat_def assms(1) end_simp length_tl less_nat_zero_code list.size(3) tail_preserves_Q_basic_struct)\n  using assms Q_tail_props apply (simp add:Q_has_no_uroboros_def Q_basic_struct_def)\n  by (smt (z3) assms(1) empty_iff end_simp fst_conv in_set_butlastD list.set(1) tail_preserves_Q_basic_struct)\n(*\nlemma Q_basic_preserved2:\n  assumes \"Q_structure s\"\n  and \"ownT s=Q\"\n  and \"s' =((`q:= (tl(q s)))\n          \\<circ> (`pcR := Read) \n          \\<circ> (`tempR := (hd(q s))) \n          \\<circ> (transownT [Q R s])\n          \\<circ> (`numDeqs :=(numDeqs s+1))\n          \\<circ> (setownB [(fst(hd(q s)),(end(hd(q s)))) R]))  s\"\n  shows \"Q_structure s'\"\n  using assms apply simp\n  apply(simp add:Q_structure_def)                                        \n  apply(intro conjI impI)\n      apply(simp add:Q_basic_struct_def)\n      apply(intro conjI impI)\n  apply(simp add:Q_boundness_def)\n  apply (metis list.sel(2) list.set_sel(2))\n  apply(simp add:Q_gap_structure_def)\n  apply (smt One_nat_def Q_tail_props Suc_diff_le Suc_leI Suc_mono Suc_pred length_greater_0_conv less_SucI list.sel(2))\n  apply(simp add:Q_offsets_differ_def)\n  apply (metis (no_types, lifting) Nitpick.size_list_simp(2) One_nat_def Suc_mono length_tl list.sel(2) nat.inject nth_tl)\n  apply(simp add:Q_has_no_overlaps_def) \n  apply (metis (no_types, lifting) list.sel(2) list.set_sel(2))\n  apply(simp add:Q_has_no_uroboros_def)\n  apply (metis butlast_tl last_tl list.sel(2) list.set_sel(2))\n  using ownB_lemma2 apply (simp add:Q_holds_bytes_def)\n     apply clarify\n  apply safe \n  apply simp_all apply(case_tac \"fst(hd(q s))>a\", simp_all)\n       apply(simp add:Q_lemmas Q_basic_lemmas fst_def snd_def)\n  apply (smt fst_def hd_in_set le_imp_less_Suc le_less_trans list.sel(2) list.set_sel(2) not_less_eq prod.collapse)\n       defer\n  apply(case_tac \"fst(hd(q s))<a\", simp_all)\n  apply (metis list.sel(2) list.set_sel(2))\n  apply (metis list.sel(2) list.set_sel(2))\n     defer defer defer \n  apply(case_tac \"fst(hd(q s)) =fst(a,b)\", simp add:fst_def snd_def Q_lemmas Q_basic_lemmas) \n  apply (smt One_nat_def Suc_mono Suc_pred fst_conv fst_def hd_conv_nth in_set_conv_nth length_greater_0_conv length_tl less_antisym list.sel(2) not_less_zero nth_tl zero_induct)\n  apply(simp add:Q_basic_struct_def Q_has_no_overlaps_def fst_def snd_def)\n  apply clarify\n  apply(simp add:Q_lemmas Q_basic_lemmas fst_def snd_def butlast_def)\n  apply (smt fst_def hd_in_set le_less_trans linorder_neqE_nat list.sel(2) list.set_sel(2) not_less prod.collapse snd_def)\n  (*finally Q_holds_bytes done*)\n  apply(simp add:Q_reflects_writes_def)\n  apply (simp add: nth_tl)\n   apply(simp add:Q_elem_size_def)\n  apply (simp add: nth_tl)\n  apply(simp add:Q_reflects_ownD_def)\n  using less_diff_conv by auto\n  *)\n\n*)\n\n(*tempR used to be part of Q so:.....*)\n\n definition \"tempR_boundness s \\<equiv> (end (tempR s) \\<le> N)\" \n\ndefinition \"tempR_offsets_differ s \\<equiv> (\\<forall>i.(i<length(q s))\\<longrightarrow>(fst(q s!i)\\<noteq>fst(tempR s)))\"\n\ndefinition \"tempR_gap_structure s   \\<equiv> (end(tempR s) = fst(hd(q s)))\\<or> (fst(hd(q s)) =0)\"\n\ndefinition \"tempR_has_no_uroboros s \\<equiv> (fst (tempR s) \\<noteq> end (last (q s)))\"\n\ndefinition \"tempR_has_no_overlaps s \\<equiv>(\\<forall>i.(i<length(q s))\\<longrightarrow>((fst(tempR s)<fst(q s!i)\\<longrightarrow>end(tempR s)\\<le>fst(q s!i))\n                                                           \\<and>(fst(tempR s)>fst(q s!i)\\<longrightarrow>end(q s!i)\\<le>fst(tempR s))))\"\n\ndefinition \"tempR_basic_struct s \\<equiv> tempR_boundness s \\<and> (q s\\<noteq>[]\\<longrightarrow> (tempR_gap_structure s \\<and> tempR_offsets_differ s\n                              \\<and> tempR_has_no_overlaps s \\<and> tempR_has_no_uroboros s)) \"\n\n\nlemmas tempR_basic_lemmas = tempR_basic_struct_def  tempR_has_no_overlaps_def \n                            tempR_gap_structure_def tempR_has_no_uroboros_def\n                            tempR_boundness_def     tempR_offsets_differ_def\n\n\ndefinition \"tempR_holds_bytes s     \\<equiv> (\\<forall>j.(fst(tempR s)\\<le>j \\<and> j<end(tempR s))\\<longrightarrow>ownB s j=R)\"\n\ndefinition \"tempR_reflects_writes s \\<equiv> (data_index s (tempR s) = ((numDeqs s) -1))\"\n\ndefinition \"tempR_elem_size s       \\<equiv> (snd(tempR s) =Data s ((numDeqs s) -1))\"\n\n\ndefinition \"tempR_structure s \\<equiv>(tempR_basic_struct s \\<and> \n                                      tempR_holds_bytes s \\<and> tempR_reflects_writes s \\<and> tempR_elem_size s)\"\n\n\nlemmas tempR_lemmas = tempR_holds_bytes_def tempR_reflects_writes_def \n                      tempR_elem_size_def   tempR_structure_def\n                      \n\n\n(*tempW will be part of Q so:.....*)\ndefinition \"tempW s \\<equiv> (offset s, Data s (numEnqs s))\"\n\n definition \"tempW_boundness s \\<equiv> (end (tempW s) \\<le> N)\" \n\ndefinition \"tempW_offsets_differ s \\<equiv> (\\<forall>i.(i<length(q s))\\<longrightarrow>(fst(q s!i)\\<noteq>fst(tempW s)))\"\n\ndefinition \"tempW_gap_structure s   \\<equiv> (fst(tempW s) = end(last(q s)))\\<or> (fst(tempW s) =0)\"\n\ndefinition \"tempW_has_no_uroboros s \\<equiv> (end((tempW s)) \\<noteq> fst (hd (q s)))\"\n\ndefinition \"tempW_has_no_overlaps s \\<equiv>(\\<forall>i.(i<length(q s))\\<longrightarrow>((fst(tempW s)<fst(q s!i)\\<longrightarrow>end(tempW s)<fst(q s!i))\n                                                           \\<and>(fst(tempW s)>fst(q s!i)\\<longrightarrow>end(q s!i)\\<le>fst(tempW s))))\"\n\ndefinition \"tempW_basic_struct s \\<equiv> tempW_boundness s \\<and> (q s\\<noteq>[]\\<longrightarrow> (tempW_gap_structure s \\<and> tempW_offsets_differ s\n                              \\<and> tempW_has_no_overlaps s \\<and> tempW_has_no_uroboros s))\"\n\n\nlemmas tempW_basic_lemmas = tempW_basic_struct_def  tempW_has_no_overlaps_def \n                            tempW_gap_structure_def tempW_has_no_uroboros_def\n                            tempW_boundness_def     tempW_offsets_differ_def\n                            tempW_def\n\n\ndefinition \"tempW_holds_bytes s     \\<equiv> (\\<forall>j.(fst(tempW s)\\<le>j \\<and> j<end(tempW s))\\<longrightarrow>ownB s j=W)\"\n\ndefinition \"tempW_reflects_writes s \\<equiv> (data_index s (offset s, Data s (numEnqs s)) = numEnqs s)\"\n\ndefinition \"tempW_structure s \\<equiv>(tempW_basic_struct s \\<and> \n                                      tempW_holds_bytes s )\"\n\n\nlemmas tempW_lemmas = tempW_holds_bytes_def tempW_reflects_writes_def \n                      tempW_structure_def\n\n\n\n\n\n\n\n\n\n\n\n\n\n(*Writer Thread Behaviour*)\n\n\nfun rbW_step :: \"PCW \\<Rightarrow> rb_state \\<Rightarrow> rb_state\" where\n  \"rbW_step A1 s = ((`hW := (H s)) \\<circ> (`tW := (T s)) \\<circ> (`pcW := A2)) s \"\n| \"rbW_step A2 s = (if grd1 s then ((`pcW := A3) \\<circ> (transownT [Q W s]))\n                     else if grd2 s then (`pcW := A4) \n                     else if grd3 s then (`pcW := A5) \n                     else (`pcW :=A8)) s\"\n| \"rbW_step A3 s = ((`T := 0) \\<circ> (`H := (Data s (numEnqs s))) \\<circ> (`offset := 0) \\<circ> (`pcW := Write) \n                        \\<circ> setownB [(0,(Data s (numEnqs s))) W]) s\" \n| \"rbW_step A4 s = ((`H := ((hW s) + (Data s (numEnqs s)))) \\<circ> (`offset := (hW s)) \\<circ> (`pcW := Write)\n                        \\<circ> setownB [(hW s,hW s+Data s (numEnqs s)) W]) s\"\n| \"rbW_step A5 s = (if grd4 s then (`pcW := A6)  \n                     else if grd5 s then (`pcW := A7)\n                     else (`pcW := A8)) s\"\n| \"rbW_step A6 s = (`H := ((hW s) + (Data s (numEnqs s))) \\<circ> (`offset := (hW s)) \\<circ> (`pcW := Write)\n                        \\<circ> setownB [(hW s,hW s+Data s (numEnqs s)) W]) s\"\n| \"rbW_step A7 s = ((`H := (Data s (numEnqs s))) \\<circ> (`offset := 0) \\<circ> (`pcW := Write)\n                        \\<circ> (setownB [(hW s,N) D])\n                        \\<circ> (setownB [(0,Data s (numEnqs s)) W])) s\"\n| \"rbW_step A8 s = (if ((Data s (numEnqs s))>N) then ERRBTS s\n                        else (ERROOM \\<circ> (`tW := (T s))) s)\"\n\n| \"rbW_step Write s = s\"\n| \"rbW_step Enqueue s = s\"| \"rbW_step idleW s = s\" | \"rbW_step FinishedW s = s\"| \"rbW_step BTS s = s\"| \"rbW_step OOM s = s\"\n\n\n\ndefinition \"B_acquire s s' \\<equiv> s' = (`pcW := A1) s\"\n\ndefinition \"Q_enqueue s s' \\<equiv> s' = (`q:=(append (q s) [(offset s,Data s (numEnqs s))])\n                     \\<circ> `pcW := idleW\n                     \\<circ>  transownB [W Q]\n                     \\<circ> `numEnqs := (numEnqs s + 1)\n                     \\<circ>  transownT [W Q s]) s\"\n\ndefinition \"B_write s s' \\<equiv> s' = ((`B.write ((offset s), (Data s (numEnqs s))):= (numEnqs s))\n                      \\<circ> (transownD [(numWrites s) B]) \\<circ> `pcW := Enqueue \\<circ> (`numWrites := ((numWrites s )+1))) s\"\n\ndefinition cW_step :: \"PCW \\<Rightarrow> rb_state \\<Rightarrow> rb_state \\<Rightarrow> bool\" where\n \"cW_step pcw s s' \\<equiv> \n    case pcw of\n        idleW     \\<Rightarrow>  if ((numEnqs s) < n) then B_acquire s s'\n                          else s' = (`pcW := FinishedW ) s\n      | Write     \\<Rightarrow>  B_write s s'   \n      | Enqueue   \\<Rightarrow>  Q_enqueue s s'\n      | OOM       \\<Rightarrow>  if tW s \\<noteq> T s then s' = (`pcW := idleW ) s else s = s'\n      | FinishedW \\<Rightarrow>  s = s'\n      | BTS       \\<Rightarrow>  s = s'\n      | _         \\<Rightarrow>  s' = rbW_step pcw s \"\n\n\nlemmas W_functs [simp] = B_acquire_def B_write_def Q_enqueue_def\n(*---------Tailored assertions to Writer-------*)\ndefinition \"pre_acquire_inv s   \\<equiv> (\\<forall>j.(j\\<ge>0\\<and> j\\<le>N)\\<longrightarrow>ownB s j\\<noteq>W)\n                                \\<and> (ownT s \\<noteq> W)\n                                \\<and> (T s=H s \\<longrightarrow> (\\<forall>i.(i\\<ge>0 \\<and> i<N)\\<longrightarrow>ownB s i=B) \\<and> ownT s = Q \\<and> q s= [] \\<and> numDeqs s = numEnqs s)\n                                \\<and> (T s>H s \\<longrightarrow> (\\<forall>i.(i\\<ge>H s \\<and> i<T s)\\<longrightarrow>ownB s i=B))\n                                \\<and> (T s<H s \\<longrightarrow> (\\<forall>i.((i\\<ge>H s \\<and> i<N) \\<or> i<T s)\\<longrightarrow>ownB s i=B))\n                                \\<and> (numWrites s=numEnqs s)\n                                \\<and> (numEnqs s=0\\<longrightarrow>q s=[]) \n                                \\<and> (numEnqs s\\<le>n)\n                                \\<and> (numEnqs s>0\\<longleftrightarrow>H s>0)\n                                \\<and> (numEnqs s=0\\<longleftrightarrow>H s=0)\n\"\ndefinition \"pre_A1_inv s        \\<equiv> (T s=H s\\<longrightarrow>((\\<forall>i.(i\\<ge>0 \\<and> i<N)\\<longrightarrow>ownB s i=B) \\<and> ownT s =Q \\<and> q s=[]))\n                                \\<and> (\\<forall>j.(j\\<ge>0\\<and> j\\<le>N)\\<longrightarrow>ownB s j\\<noteq>W)\n                                \\<and> (ownT s \\<noteq>W)\n                                \\<and> (T s>H s \\<longrightarrow> (\\<forall>i.(i\\<ge>H s \\<and> i<T s)\\<longrightarrow>ownB s i=B))\n                                \\<and> (T s<H s \\<longrightarrow> (\\<forall>i.((i\\<ge>H s \\<and> i<N) \\<or> i<T s)\\<longrightarrow>ownB s i=B))\n                                \\<and> (numWrites s=numEnqs s)\n                                \\<and> (numEnqs s<n)\n                                \\<and> (numEnqs s>0\\<longleftrightarrow>H s>0)\n                                \\<and> (numEnqs s=0\\<longleftrightarrow>H s=0)\n                                \\<and> (T s = 0 \\<and> H s = 0) = (numWrites s = 0)\n                                \" \ndefinition \"pre_A2_inv s        \\<equiv> (tW s=hW s\\<longrightarrow>((\\<forall>i.(i\\<ge>0 \\<and> i<N)\\<longrightarrow>ownB s i=B) \\<and> ownT s =Q \\<and> q s=[] \\<and> tW s=T s))\n                                \\<and> (tW s>hW s \\<longrightarrow> ((\\<forall>i.(i\\<ge>hW s \\<and> i<tW s)\\<longrightarrow>ownB s i=B) \\<and> (T s\\<ge>tW s \\<or> T s\\<le>H s)))\n                                \\<and> (tW s<hW s \\<longrightarrow> ((\\<forall>i.((i\\<ge>hW s \\<and> i<N) \\<or> i<tW s)\\<longrightarrow>ownB s i=B) \\<and> T s\\<ge>tW s \\<and> H s\\<ge>T s))\n                                \\<and> (\\<forall>j.(j\\<ge>0\\<and> j\\<le>N)\\<longrightarrow>ownB s j\\<noteq>W)\n                                \\<and> (ownT s \\<noteq>W)\n                                \\<and> (numWrites s=numEnqs s)\n                                \\<and> (numEnqs s<n)\n                                \\<and> (H s=hW s)\n                                \\<and> (numEnqs s=0\\<longrightarrow>q s=[])\n                                \\<and> (numEnqs s>0\\<longleftrightarrow>H s>0)\n                                \\<and> (numEnqs s=0\\<longleftrightarrow>H s=0)\n                                \\<and> (T s = 0 \\<and> H s = 0) = (numWrites s = 0)\n                                \" \ndefinition \"pre_A3_inv s        \\<equiv> ((\\<forall>i.(i\\<ge>0 \\<and> i<N)\\<longrightarrow>ownB s i=B))\n                                \\<and> (grd1 s)\n                                \\<and> (ownT s =W)\n                                \\<and> (numWrites s=numEnqs s)\n                                \\<and> (numEnqs s<n)\n                                \\<and> (H s=hW s) \\<and> q s=[]\n                                \\<and> (numEnqs s=0\\<longrightarrow>q s=[])\n                                \\<and> (numEnqs s>0\\<longleftrightarrow>H s>0)\n                                \\<and> (numEnqs s=0\\<longleftrightarrow>H s=0)\n                                \\<and> (T s=tW s)\n                                \\<and> (T s = 0 \\<and> H s = 0) = (numWrites s = 0)\n                                \" \ndefinition \"pre_A4_inv s        \\<equiv> (\\<forall>i.(i\\<ge>hW s \\<and> i<tW s)\\<longrightarrow>ownB s i=B)\n                                \\<and> (grd2 s) \\<and> (\\<not>grd1 s)\n                                \\<and> (\\<forall>j.(j\\<ge>0\\<and> j\\<le>N)\\<longrightarrow>ownB s j\\<noteq>W)\n                                \\<and> (ownT s \\<noteq>W)\n                                \\<and> (numWrites s=numEnqs s) \n                                \\<and> (numEnqs s<n)\n                                \\<and> (H s=hW s)\n                                \\<and> (numEnqs s=0\\<longrightarrow>q s=[])\n                                \\<and> (numEnqs s>0\\<longleftrightarrow>H s>0)\n                                \\<and> (numEnqs s=0\\<longleftrightarrow>H s=0)\n                                \\<and> (T s\\<ge>tW s \\<or> T s\\<le>H s)\n                                \\<and> (T s = 0 \\<and> H s = 0) = (numWrites s = 0)\n                                \" \ndefinition \"pre_A5_inv s        \\<equiv> (\\<forall>i.((i\\<ge>hW s \\<and> i<N) \\<or> i<tW s)\\<longrightarrow>ownB s i=B)\n                                \\<and> (grd3 s) \\<and> (\\<not>grd1 s) \\<and> (\\<not>grd2 s)\n                                \\<and> (\\<forall>j.(j\\<ge>0\\<and> j\\<le>N)\\<longrightarrow>ownB s j\\<noteq>W)\n                                \\<and> (ownT s \\<noteq>W)\n                                \\<and> (numWrites s=numEnqs s)\n                                \\<and> (numEnqs s<n)\n                                \\<and> (H s=hW s)\n                                \\<and> (numEnqs s=0\\<longrightarrow>q s=[])\n                                \\<and> (numEnqs s>0\\<longleftrightarrow>H s>0)\n                                \\<and> (numEnqs s=0\\<longleftrightarrow>H s=0)\n                                \\<and> (T s\\<ge>tW s \\<and> T s\\<le>H s)\n                                \\<and> (T s = 0 \\<and> H s = 0) = (numWrites s = 0)\n                                \" \ndefinition \"pre_A6_inv s        \\<equiv> (\\<forall>i.((i\\<ge>hW s \\<and> i<N) \\<or> i<tW s)\\<longrightarrow>ownB s i=B)\n                                \\<and> (grd4 s) \\<and> (grd3 s) \\<and> (\\<not>grd1 s) \\<and> (\\<not>grd2 s)\n                                \\<and> (\\<forall>j.(j\\<ge>0\\<and> j\\<le>N)\\<longrightarrow>ownB s j\\<noteq>W)\n                                \\<and> (ownT s \\<noteq>W)\n                                \\<and> (numWrites s=numEnqs s) \n                                \\<and> (numEnqs s<n)\n                                \\<and> (H s=hW s)\n                                \\<and> (numEnqs s=0\\<longrightarrow>q s=[])\n                                \\<and> (numEnqs s>0\\<longleftrightarrow>H s>0)\n                                \\<and> (numEnqs s=0\\<longleftrightarrow>H s=0)\n                                \\<and> (T s\\<ge>tW s \\<and> T s\\<le>H s)\n                                \\<and> (T s = 0 \\<and> H s = 0) = (numWrites s = 0)\n                                \" \ndefinition \"pre_A7_inv s        \\<equiv> (\\<forall>i.((i\\<ge>hW s \\<and> i<N) \\<or> i<tW s)\\<longrightarrow>ownB s i=B)\n                                \\<and> (grd5 s) \\<and> (grd3 s) \\<and> (\\<not>grd1 s) \\<and> (\\<not>grd2 s) \\<and> (\\<not>grd4 s)\n                                \\<and> (\\<forall>j.(j\\<ge>0\\<and> j\\<le>N)\\<longrightarrow>ownB s j\\<noteq>W)\n                                \\<and> (ownT s \\<noteq>W)\n                                \\<and> (numWrites s=numEnqs s) \n                                \\<and> (numEnqs s<n) \n                                \\<and> (H s=hW s)\n                                \\<and> (numEnqs s=0\\<longrightarrow>q s=[])\n                                \\<and> (numEnqs s>0\\<longleftrightarrow>H s>0)\n                                \\<and> (numEnqs s=0\\<longleftrightarrow>H s=0)\n                                \\<and> (T s\\<ge>tW s \\<and> T s\\<le>H s)\n                                \\<and> (T s = 0 \\<and> H s = 0) = (numWrites s = 0)\n                                \" \ndefinition \"pre_A8_inv s        \\<equiv> (tW s\\<le>hW s \\<longrightarrow>(\\<forall>i.((i\\<ge>hW s \\<and> i<N) \\<or> i<tW s)\\<longrightarrow>ownB s i=B))\n                                \\<and> (tW s>hW s \\<longrightarrow>(\\<forall>i.(hW s \\<le>i \\<and> i<tW s)\\<longrightarrow>ownB s i=B))\n                                \\<and> (\\<forall>j.(j\\<ge>0\\<and> j\\<le>N)\\<longrightarrow>ownB s j\\<noteq>W)\n                                \\<and> (ownT s \\<noteq>W)\n                                \\<and> (numWrites s=numEnqs s)\n                                \\<and> (no_space_for_word s) \n                                \\<and> (numEnqs s<n)\n                                \\<and> (H s=hW s)\n                                \\<and> (numEnqs s=0\\<longrightarrow>q s=[])\n                                \\<and> (numEnqs s>0\\<longleftrightarrow>H s>0)\n                                \\<and> (numEnqs s=0\\<longleftrightarrow>H s=0)\n                                \\<and> (T s\\<ge>tW s \\<or> T s\\<le>H s)\n                                \\<and> (T s = 0 \\<and> H s = 0) = (numWrites s = 0)\n\"\ndefinition \"pre_write_inv s     \\<equiv> (\\<forall>i.(i\\<ge>offset s \\<and> i< ((offset s)+(Data s (numEnqs s))))\\<longrightarrow>ownB s i=W)\n                                \\<and> ((tW s>hW s)\\<longrightarrow>(\\<forall>i.(i\\<ge>((offset s)+(Data s (numEnqs s)))\\<and>i<tW s)\\<longrightarrow>ownB s i =B))\n                                \\<and> ((tW s<hW s \\<and> offset s\\<noteq>0)\\<longrightarrow>(\\<forall>i.((i\\<ge>((offset s)+(Data s (numEnqs s))) \\<and> i<N)\\<or>i<tW s)\\<longrightarrow>ownB s i =B))\n                                \\<and> ((tW s<hW s \\<and> offset s=0)\\<longrightarrow>((\\<forall>i.(i\\<ge>((offset s)+(Data s (numEnqs s))) \\<and> i<tW s)\\<longrightarrow>ownB s i =B) \\<and> (\\<forall>i.(i\\<ge>hW s \\<and> i<N)\\<longrightarrow>ownB s i=D)))\n                                \\<and> (tW s=hW s\\<longrightarrow>(ownT s=W \\<and> q s=[]))\n                                \\<and> (numWrites s=numEnqs s)\n                                \\<and> (numEnqs s<n)\n                                \\<and> (tempW_structure s)\n                                \\<and> (ownD s(numWrites s) =W)\n                                \\<and> (numEnqs s=0\\<longrightarrow>q s=[]) \n                                \\<and> (offset s=hW s \\<or> offset s=0)\n                                \\<and> (H s=offset s + Data s (numEnqs s))\n                                \" \ndefinition \"pre_enqueue_inv s   \\<equiv> (\\<forall>i.(i\\<ge>offset s \\<and> i< end(tempW s))\\<longrightarrow>ownB s i=W)\n                                \\<and> (\\<forall>i.(i<offset s \\<or> (i\\<ge> end(tempW s)\\<and>i\\<le>N))\\<longrightarrow>ownB s i\\<noteq>W)\n                                \\<and> ((tW s>hW s)\\<longrightarrow>(\\<forall>i.(i\\<ge>end(tempW s)\\<and>i<tW s)\\<longrightarrow>ownB s i =B))\n                                \\<and> ((tW s<hW s \\<and> offset s\\<noteq>0)\\<longrightarrow>(\\<forall>i.((i\\<ge>end(tempW s) \\<and> i<N)\\<or>i<tW s)\\<longrightarrow>ownB s i =B))\n                                \\<and> ((tW s<hW s \\<and> offset s=0)\\<longrightarrow>((\\<forall>i.(i\\<ge>end(tempW s) \\<and> i<tW s)\\<longrightarrow>ownB s i =B) \\<and> (\\<forall>i.(i\\<ge>hW s \\<and> i<N)\\<longrightarrow>ownB s i=D)))\n                                \\<and> (tW s=hW s\\<longrightarrow>(ownT s=W \\<and> q s=[]))\n                                \\<and> (numWrites s=numEnqs s +1)\n                                \\<and> (numEnqs s<n)\n                                \\<and> ((ownT s = W)\\<longrightarrow>q s=[])\n                                \\<and> (tempW_structure s)\n                                \\<and> (tempW_reflects_writes s)\n                                \\<and> (ownD s(numEnqs s) =B)\n                                \\<and> (numEnqs s=0\\<longrightarrow>q s=[]) \n                                \\<and> (offset s=hW s \\<or> offset s=0)\n                                \\<and> (H s=offset s + Data s (numEnqs s))\n                                \" \ndefinition \"pre_OOM_inv s       \\<equiv> (\\<forall>j.(j\\<ge>0\\<and> j\\<le>N)\\<longrightarrow>ownB s j\\<noteq>W)\n                                \\<and> (ownT s \\<noteq>W)\n                                \\<and> (tW s>hW s \\<longrightarrow> (\\<forall>i.(i\\<ge>tW s \\<and> i<hW s)\\<longrightarrow>ownB s i=B))\n                                \\<and> (tW s<hW s \\<longrightarrow> (\\<forall>i.((i\\<ge>hW s \\<and> i<N) \\<or> i<tW s)\\<longrightarrow>ownB s i=B))\n                                \\<and> (numWrites s=numEnqs s) \n                                \\<and> (numEnqs s<n)\n                                \\<and> (H s=hW s)\n                                \\<and> (numEnqs s=0\\<longrightarrow>q s=[]) \n                                \\<and> (numEnqs s>0\\<longleftrightarrow>H s>0)\n                                \\<and> (numEnqs s=0\\<longleftrightarrow>H s=0)\n                                \\<and> (T s = 0 \\<and> H s = 0) = (numWrites s = 0)\n                                \" \ndefinition \"pre_finished_inv s  \\<equiv> (\\<forall>j.(j\\<ge>0\\<and> j\\<le>N)\\<longrightarrow>ownB s j\\<noteq>W)\n                                \\<and> (ownT s \\<noteq>W)\n                                \\<and> (numWrites s=numEnqs s)\n                                \\<and> (numEnqs s=n)\n                                \\<and> (H s>0)\n                                \" \ndefinition \"pre_BTS_inv s       \\<equiv> (\\<forall>j.(j\\<ge>0\\<and> j\\<le>N)\\<longrightarrow>ownB s j\\<noteq>W)\n                                \\<and> (ownT s \\<noteq>W)\n                                \\<and> (numWrites s=numEnqs s)\n                                \\<and> (numEnqs s<n)\n                                \\<and> (H s=hW s)\n                                \\<and> (numEnqs s=0\\<longrightarrow>q s=[]) \n                                \\<and> (numEnqs s>0\\<longleftrightarrow>H s>0)\n                                \\<and> (numEnqs s=0\\<longleftrightarrow>H s=0)\n                                \\<and> (T s = 0 \\<and> H s = 0) = (numWrites s = 0)\n                                \" \n\nlemmas writer_lemmas  = pre_A1_inv_def pre_A2_inv_def pre_A3_inv_def pre_A4_inv_def\n                              pre_A5_inv_def pre_A6_inv_def pre_A7_inv_def pre_A8_inv_def\n                              pre_BTS_inv_def pre_OOM_inv_def pre_acquire_inv_def\n                              pre_finished_inv_def pre_enqueue_inv_def pre_write_inv_def\n(***********************************************************************)\n\n\n(*Reader Thread Behaviour*)\n\ndefinition \"B_release s s' \\<equiv> s' = (`T := (end(tempR s)) \n                        \\<circ> (`pcR := idleR) \n                        \\<circ> (`tempR := (0,0))\n                        \\<circ> (transownB [R B]) \n                        \\<circ> (if tR s\\<noteq> fst(tempR s) then setownB [(tR s,N) B] else id) \n                        \\<circ> transownT [R Q s]) s\"\n\ndefinition \"B_read s s' \\<equiv> s' = (((transownD [(data_index s (tempR s)) R]) \n                        \\<circ> (`pcR := Release)) \n                        \\<circ> (`numReads := (numReads s+1))  \n                        \\<circ> (`tR := (T s))) s\"\n\ndefinition \"Q_dequeue s s' \\<equiv>  s' = ((`q:= (tl(q s)))\n                                          \\<circ> (`pcR := Read)\n                                          \\<circ> (`tempR := (hd(q s)))\n                                          \\<circ> (transownT [Q R s])\n                                          \\<circ> (`numDeqs :=(numDeqs s+1))\n                                          \\<circ> (setownB [(off(hd(q s)),(end(hd(q s)))) R])) s\"\n\ndefinition cR_step :: \"PCR \\<Rightarrow> rb_state \\<Rightarrow> rb_state \\<Rightarrow> bool\" where\n \"cR_step pcr s s' \\<equiv> \n    case pcr of\n        idleR \\<Rightarrow> if (q s=[]) then (s=s') else (Q_dequeue s s')\n      | Read \\<Rightarrow>  B_read s s' \n      | Release \\<Rightarrow>  B_release s s'\"\n\n\nlemmas R_functs [simp] = B_release_def B_read_def Q_dequeue_def\n(*---------Tailored assertions to Reader-------*)\ndefinition \"pre_dequeue_inv s \\<equiv>  (tempR s = (0,0))\n                              \\<and> (numDeqs s \\<le> n)\n                              \\<and> (numDeqs s \\<ge> 0)\n                              \\<and> (numDeqs s = numReads s)\n                              \\<and> (numDeqs s \\<le> numEnqs s)\n                              \\<and> (pcR s = idleR)\n                              \\<and> (q s\\<noteq>[] \\<longrightarrow> ownT s=Q)\n                              \\<and> (q s\\<noteq>[] \\<longrightarrow> H s>0)\n                              \\<and> ((T s\\<noteq>fst(hd(q s))\\<and>q s\\<noteq>[])\\<longrightarrow>(\\<forall>x j.(x\\<in>set(q s) \\<and> j<N \\<and> j\\<ge>T s)\\<longrightarrow>end(x)<j))\n                              \\<and> (q s\\<noteq>[]\\<longrightarrow>(\\<forall>i.(fst(hd(q s))\\<le>i \\<and> i<end(hd(q s)))\\<longrightarrow>ownB s i = Q))\n                              \\<and> (\\<forall>i.(i<fst(tempR s) \\<or> (i\\<ge>end(tempR s)\\<and> i\\<le>N))\\<longrightarrow>ownB s i \\<noteq> R)\n\n\"\n\ndefinition \"pre_Read_inv s    \\<equiv>  (snd(tempR s) = Data s (numReads s))\n                              \\<and> (numReads s=data_index s (tempR s))\n                              \\<and> (numDeqs s\\<le>n) \n                              \\<and> (numDeqs s\\<ge>0) \n                              \\<and> (numReads s+1=numDeqs s)\n                              \\<and> (numDeqs s\\<ge>1)\n                              \\<and> (numEnqs s\\<ge>numDeqs s) \n                              \\<and> (pcR s=Read)\n                              \\<and> (ownT s = R)\n                              \\<and> (ownD s (numReads s) = B)\n                              \\<and> (tempR s\\<noteq>(0,0))\n                              \\<and> (tempR_structure s)\n                              \\<and> (\\<forall>i.(fst(tempR s)\\<le>i \\<and> i<end(tempR s))\\<longrightarrow>ownB s i = R)\n                              \\<and> (\\<forall>i.(i<fst(tempR s) \\<or> (i\\<ge>end(tempR s)\\<and> i\\<le>N))\\<longrightarrow>ownB s i \\<noteq> R)\n\n                              \\<and> (H s>0)\n\"\n\ndefinition \"pre_Release_inv s \\<equiv> (snd(tempR s) = Data s (numReads s -1))\n                              \\<and> (data_index s (tempR s) = numReads s -1)\n                              \\<and> (q s\\<noteq>[]\\<longrightarrow>(numReads s=data_index s (hd(q s))))\n                              \\<and> (ownT s = R)\n                              \\<and> (numEnqs s\\<ge>numDeqs s)\n                              \\<and> (ownD s (numReads s -1) = R)\n                              \\<and> (numDeqs s\\<le>n \\<and> numDeqs s\\<ge>1)\n                              \\<and> (numDeqs s = numReads s)\n                              \\<and> (pcR s=Release)\n                              \\<and> (tR s=T s)\n                              \\<and> (tempR s\\<noteq>(0,0))\n                              \\<and> (tempR_structure s)\n                              \\<and> (\\<forall>i.(fst(tempR s)\\<le>i \\<and> i<end(tempR s))\\<longrightarrow>ownB s i = R)\n                              \\<and> (\\<forall>i.(i<fst(tempR s) \\<or> (i\\<ge>end(tempR s)\\<and> i\\<le>N))\\<longrightarrow>ownB s i \\<noteq> R)\n\n\n                              \\<and> (H s>0)\n\" \n\n\n\nlemmas reader_lemmas  = pre_Release_inv_def pre_Read_inv_def pre_dequeue_inv_def\n(***********************************************************************)\n\n\n\nlemma Q_structure_preserved1:\n  assumes \"Q_structure s\"\n  and \"pre_dequeue_inv s\"\n  and \"q s\\<noteq>[]\"\n  and \"Q_dequeue s s'\"\n  shows \"Q_structure s'\"\n  using assms apply(simp add:Q_structure_def pre_dequeue_inv_def)\n  apply (intro conjI impI)\n  apply(simp add:Q_basic_struct_def)\n  apply(intro conjI impI)\n  apply(simp add:Q_boundness_def )\n  apply (metis  list.set_sel(2))\n  apply(simp add:Q_gap_structure_def) \n  apply (metis (no_types, hide_lams) One_nat_def Q_gap_structure_def end_simp length_tl tail_preserves_Q_gap_structure)\n  apply(simp add:Q_offsets_differ_def)\n  apply (metis (no_types, lifting) One_nat_def add.commute add_right_cancel length_tl less_diff_conv nth_tl plus_1_eq_Suc)\n  apply(simp add:Q_has_no_overlaps_def)\n  apply (metis (no_types, lifting) list.set_sel(2))\n  apply(simp add:Q_has_no_uroboros_def)\n  apply (metis butlast_tl last_tl list.sel(2) list.set_sel(2))\n  apply(simp add:Q_reflects_writes_def) apply(simp add:Q_elem_size_def)\n  apply (meson list.set_sel(2)) apply(simp add:Q_reflects_writes_def)\n  apply (metis One_nat_def Suc_eq_plus1 add_Suc_right length_tl less_diff_conv nth_tl)\n  apply(simp add:Q_reflects_ownD_def) apply(simp add:Q_elem_rel_def) \n  apply (metis (no_types, hide_lams) One_nat_def Q_structure_def Suc_eq_plus1_left add.commute assms(1) length_tl tail_preserves_Q_elem_size)\n  apply(simp add:Q_reflects_ownD_def)\n  by (metis Nat.add_0_right add_Suc add_Suc_right less_diff_conv)\n\nlemma Q_structure_preserved2:\n  assumes \"Q_structure s\"\n  and \"ownT s=R\"\n  and \"pre_Read_inv s\"\n  and \"B_read s s'\"\n  shows \"Q_structure s'\"\n  using assms apply(simp add:Q_structure_def)\n  apply(intro conjI impI) apply(simp add:Q_basic_struct_def) apply(intro conjI impI)\n  apply(simp add:Q_boundness_def)\n  apply(simp add:Q_gap_structure_def)\n  apply(simp add:Q_offsets_differ_def)\n  apply(simp add:Q_has_no_overlaps_def)\n  apply(simp add:Q_has_no_uroboros_def)\n  apply(simp add:Q_elem_size_def)\n  apply(simp add:Q_holds_bytes_def)\n  apply(simp add:Q_reflects_writes_def)\n  apply(simp add:Q_elem_size_def)\n  apply(simp add:Q_reflects_ownD_def)\n  apply(simp add:Q_elem_rel_def)\n  apply(simp add:Q_reflects_ownD_def)\n  by(simp add:Q_structure_def pre_Read_inv_def)\n\nlemma Q_structure_preserved3:\n  assumes \"Q_structure s\"\n  and \"pre_Release_inv s\"\n  and \"s' = (`T := (off(tempR s) +len(tempR s)) \n          \\<circ> (`pcR := idleR) \n          \\<circ> (`tempR := (0,0))\n          \\<circ> (transownB [R B]) \n          \\<circ> (if tR s\\<noteq> fst(tempR s) then setownB [(tR s,N) B] else id) \n          \\<circ> transownT [R Q s]) s\"\n  shows \"Q_structure s'\"\n  using assms \n  apply (simp add:Q_structure_def) \n  apply(intro conjI impI)\n  apply(simp add:Q_basic_struct_def)\n  apply(intro conjI impI) \n  apply(simp add:pre_Release_inv_def Q_boundness_def)\n  apply(simp add:pre_Release_inv_def Q_gap_structure_def)\n  apply(simp add:pre_Release_inv_def Q_offsets_differ_def)\n  apply(simp add:pre_Release_inv_def Q_has_no_overlaps_def)\n  apply(simp add:pre_Release_inv_def Q_has_no_uroboros_def)\n  apply(simp add:pre_Release_inv_def Q_holds_bytes_def tempR_lemmas tempR_basic_lemmas)\n  apply(simp add:pre_Release_inv_def Q_reflects_writes_def)\n  apply(simp add:pre_Release_inv_def Q_elem_size_def)\n  apply(simp add:pre_Release_inv_def Q_reflects_ownD_def)\n  apply(simp add:pre_Release_inv_def Q_basic_lemmas)\n  apply(simp add:pre_Release_inv_def Q_reflects_writes_def)\n  apply(simp add:pre_Release_inv_def Q_elem_rel_def)\n  apply(simp add:pre_Release_inv_def Q_reflects_ownD_def)\n  apply(simp add:pre_Release_inv_def Q_basic_lemmas)\n  apply(simp add:pre_Release_inv_def Q_reflects_writes_def)\n  apply(simp add:pre_Release_inv_def Q_elem_rel_def)\n  apply(simp add:pre_Release_inv_def Q_reflects_ownD_def)\n  apply(simp add:pre_Release_inv_def Q_basic_lemmas)\n  apply(simp add:pre_Release_inv_def Q_reflects_writes_def)\n  apply(simp add:pre_Release_inv_def Q_elem_rel_def)\n  apply(simp add:pre_Release_inv_def Q_reflects_ownD_def)\n  apply(simp add:pre_Release_inv_def Q_basic_lemmas)\n  apply(simp add:pre_Release_inv_def Q_reflects_writes_def)\n  apply(simp add:pre_Release_inv_def Q_elem_rel_def)\n  by(simp add:pre_Release_inv_def Q_reflects_ownD_def)\n\n  \n\n\n\n\n\ndefinition \"inRange v \\<equiv> 0 \\<le> v \\<and> v \\<le> N\"\ndefinition \"inRangeHT s \\<equiv> inRange (H s) \\<and> inRange (T s)\"\ndefinition \"H0_T0 s \\<equiv> H s = 0 \\<longrightarrow> T s = 0\"\ndefinition \"inRangeht s \\<equiv> inRange (hW s) \\<and> inRange (tW s)\"\ndefinition \"basic_pointer_movement s \\<equiv> inRangeHT s \\<and> inRangeht s \\<and> H0_T0 s \"\n\nlemmas basic_pointer_movement_lemmas [simp] = basic_pointer_movement_def inRangeHT_def inRangeht_def H0_T0_def inRange_def\n\n\ndefinition \"mainInv s \\<equiv> \\<forall> i. (i<numReads s \\<longrightarrow> ownD s i=R) \n                           \\<and> (numReads s \\<le> i \\<and> i < numWrites s \\<longrightarrow> ownD s i = B) \n                           \\<and> (numWrites s \\<le> i \\<and> i < n \\<longrightarrow> ownD s i = W) \"\ndefinition \"counter_bounds s \\<equiv> numReads s \\<le>n \\<and> numWrites s\\<le>n \\<and> numEnqs s\\<le>n \\<and> numDeqs s \\<le> n\"\ndefinition \"counter_q_rel s \\<equiv> (numEnqs s-numDeqs s=length(q s))\\<and> numWrites s\\<ge>numReads s \\<and> numEnqs s\\<ge>numDeqs s\" \n\n\n(*new lemmas, take 2*)\ndefinition \"data_index_bouded s \\<equiv> \\<forall>i. (i\\<le>N)\\<longrightarrow>(\\<forall>j.(j\\<le>N)\\<longrightarrow>data_index s (i,j)<n)\"\n\n\n\n\nlemmas invariant_lemmas [simp] = con_assms_def mainInv_def\n                          counter_q_rel_def \n                          counter_bounds_def data_index_bouded_def\n                          \n\ndefinition \"Q_ownB_rel s        \\<equiv> \\<forall>j.(ownB s j=Q \\<and> j<N)\\<longrightarrow>(\\<exists>a b. ((a, b)\\<in>set(q s)\\<and> a\\<le>j \\<and> j<a+b))\"\n\ndefinition \"ran_indices a b \\<equiv> {i . a \\<le> i \\<and> i < b}\"\n\ndefinition \"Q_indices s \\<equiv> \\<Union> {ran_indices a (a + b) | a b. (a, b) \\<in> set(q s)}\"\n\ndefinition \"Q_tail_indices s \\<equiv> \\<Union> {ran_indices a (a + b) | a b. (a, b) \\<in> set(tl(q s))}\"\n\nlemma ran_ind_imp_Q_ind:\n  \"\\<forall>i a b. (i\\<in> ran_indices a b \\<and> (a, b)\\<in>set(q s))\\<longrightarrow>i\\<in>Q_indices s\"\n  apply(simp add:Q_indices_def ran_indices_def) \n  by (smt (z3) add.assoc add_lessD1 less_add_eq_less mem_Collect_eq)\n\nlemma Q_ind_imp_tail_ind_1:\n  \"tl(q s)\\<noteq>[] \\<Longrightarrow> hd(q s) = (q s!0)\"\n  apply (simp add:hd_def) \n  by (metis Nil_tl hd_conv_nth hd_def)\n\nlemma Q_ind_imp_tail_ind_2:\n  \"tl(q s)\\<noteq> [] \\<Longrightarrow>i\\<in>Q_indices s\\<Longrightarrow> \\<exists>a b.((a,b)\\<in>set(tl(q s))\\<and>a\\<le>i \\<and> i<b)\\<Longrightarrow>i\\<in>Q_tail_indices s\"\n  apply(simp add:Q_indices_def ran_indices_def Q_tail_indices_def) \n  by (metis (no_types, lifting) leD leI le_iff_add mem_Collect_eq nat_add_left_cancel_less trans_le_add2)\n\nlemma Q_ind_imp_tail_ind_3:\n  \"tl(q s)\\<noteq> [] \\<Longrightarrow>i\\<in>Q_indices s\\<Longrightarrow> s'=(s\\<lparr>ownB := \\<lambda>i. if fst (hd (q s)) \\<le> i \\<and> i < fst (hd (q s)) + snd (hd (q s)) then R else ownB s i,\n                   numDeqs := Suc (numDeqs s), ownT := R, tempR := hd (q s), pcR := Read, q := tl (q s)\\<rparr>)\n \\<Longrightarrow>\\<exists>a b.((a,b)\\<in>set(tl(q s))\\<and>a\\<le>i \\<and> i<b)\\<Longrightarrow>i\\<in>Q_indices s'\"\n  apply(simp add:Q_indices_def ran_indices_def Q_tail_indices_def) \n  by (metis (no_types, lifting) leD leI le_iff_add mem_Collect_eq nat_add_left_cancel_less trans_le_add2)\n\n\n\n(*\n[(1, 3), (4,1)]\nran_indices 1 4 = {1,2,3}\nran_indicies 4,5 = {4}\nQ_indicies s = {1,2,3,4}\n*)\n\ndefinition \"Q_owns_bytes s \\<equiv> \\<forall>i.(i\\<in>Q_indices s)\\<longleftrightarrow>(i\\<le>N \\<and> ownB s i=Q)\"\n\ndefinition \"Q_tail_owns_bytes s \\<equiv> \\<forall>i.(i\\<in>Q_tail_indices s)\\<longleftrightarrow>(i\\<le>N \\<and> ownB s i=Q \\<and> i\\<notin>ran_indices (fst(hd(q s))) (end(hd(q s))))\"\n\n\n\n(*------------------------ Invariant ------------------------------------*)\ndefinition inv  where\n\"inv   s \\<equiv> basic_pointer_movement s \n               \\<and> mainInv s\n               \\<and> counter_q_rel s\n               \\<and> counter_bounds s \n               \\<and> Q_structure s\n               \\<and> data_index_bouded s\n               \\<and> (case_1 s \\<or> case_2 s)\n               \\<and> Q_owns_bytes s\n\"\n\ndefinition pre_W where\n  \"pre_W pcw s \\<equiv> (case pcw of\n      idleW \\<Rightarrow> pre_acquire_inv s \n    | A1 \\<Rightarrow> pre_A1_inv s \n    | A2 \\<Rightarrow> pre_A2_inv s \n    | A3 \\<Rightarrow> pre_A3_inv s \n    | A4 \\<Rightarrow> pre_A4_inv s \n    | A5 \\<Rightarrow> pre_A5_inv s \n    | A6 \\<Rightarrow> pre_A6_inv s \n    | A7 \\<Rightarrow> pre_A7_inv s \n    | A8 \\<Rightarrow> pre_A8_inv s \n    | Write \\<Rightarrow> pre_write_inv s \n    | OOM \\<Rightarrow> pre_OOM_inv s \n    | BTS \\<Rightarrow> pre_BTS_inv s \n    | Enqueue \\<Rightarrow> pre_enqueue_inv s  \n    | FinishedW \\<Rightarrow> pre_finished_inv s)\"\n\ndefinition pre_R where\n  \"pre_R pcr s \\<equiv>\n  (case pcr of\n     idleR \\<Rightarrow> pre_dequeue_inv s \n    | Read \\<Rightarrow> pre_Read_inv s  \n    | Release \\<Rightarrow> pre_Release_inv s)\"\n\n\nlemmas inv_simps =  inv_def cW_step_def cR_step_def init_def\n\n\n\n\n\nlemma Q_not_empty:\n  \"q s \\<noteq> [] \\<Longrightarrow> \\<forall>x.(x\\<in>set(q s))\\<longrightarrow>snd(x)>0 \\<Longrightarrow> Q_indices s\\<noteq>{}\"\n  apply (simp add: Q_indices_def ran_indices_def)\n  apply (rule_tac exI [where x =\"{i. fst(hd(q s)) \\<le> i \\<and> i < end(hd(q s))}\"])\n  apply safe defer apply(simp add:end_def)\n  apply auto \n  apply (metis add.commute le_refl less_add_same_cancel2 list.set_sel(1) prod.exhaust_sel)\n  apply (rule_tac exI [where x =\"fst(hd(q s))\"])\n  apply (rule_tac exI [where x =\"snd(hd(q s))\"])\n  by simp\n\n\nlemma case_1_Q_struct:\n  assumes \"case_1 s\"\n  and \"Q_structure s\"\n  and \"Q_owns_bytes s\"\nshows \"\\<forall>i.(i>0 \\<and> i<length(q s))\\<longrightarrow>fst(q s!i) = end(q s!(i-1))\"\n  apply (cases \"q s = []\")\n  apply simp\n  using assms apply (simp add:Q_lemmas Q_basic_lemmas case_1_def Q_owns_bytes_def Q_indices_def ran_indices_def) \n  apply clarify\n  apply(subgoal_tac \"fst(q s!0) = b\") prefer 2 \n  apply (metis Zero_not_Suc diff_self_eq_0 hd_conv_nth le_neq_implies_less less_natE)\n  apply(subgoal_tac \"end(q s!(length(q s)-1)) = c\") prefer 2\n  apply (metis Suc_diff_Suc Zero_not_Suc diff_0_eq_0 diff_self_eq_0 end_simp last_conv_nth le_neq_implies_less)\n  apply(subgoal_tac \"\\<forall>a b aa. (a,b)\\<in>set(q s) \\<and> (\\<exists>b.(aa, b)\\<in>set(q s)) \\<longrightarrow> a<aa\\<longrightarrow>a+b\\<le>aa\") prefer 2 \n  apply blast\n  apply(subgoal_tac \"\\<forall>a b. (a,b)\\<in>set(q s)\\<longrightarrow>(\\<exists>i.(i<length(q s) \\<and> (q s!i) = (a,b)))\") prefer 2\n  apply (metis in_set_conv_nth)\n  apply(subgoal_tac \"\\<forall>i j.(i<length(q s)\\<and>j<length(q s))\\<longrightarrow>(\\<exists>a b aa bb.((a,b)\\<in>set(q s)\\<and>(aa,bb)\\<in>set(q s)))\")\n  prefer 2 \n  apply (metis last_in_set surjective_pairing)\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s) \\<and> i>0)\\<longrightarrow>(fst(q s!i) = 0 \\<or> fst(q s!i) = end(q s!(i-1)))\")\n  prefer 2 \n  apply (metis (no_types, lifting) One_nat_def end_simp)\n  apply(case_tac \"ownB s 0 = Q\") \n  apply (metis (no_types, lifting) F.distinct(11) F.distinct(19) le_numeral_extra(3) length_greater_0_conv not_gr0)\n  apply(subgoal_tac \"ownB s 0\\<noteq>Q\") prefer 2 apply blast\n  (*trying to use the fact that ownB s 0\\<noteq>Q and Q_gap_structure to show that all \n    Q entries start where the last left off, rather than any starting from 0*)\n  apply(subgoal_tac \"(\\<exists>a b.((a,b)\\<in>set(q s) \\<and> a = 0))\\<longrightarrow>ownB s 0=Q\")\n  prefer 2\n  apply (metis (no_types, lifting) add_gr_0 mem_Collect_eq nat_le_linear)\n  apply(subgoal_tac \"ownB s 0\\<noteq>Q\\<longrightarrow>(\\<nexists>a b.((a,b)\\<in>set(q s) \\<and> a = 0))\")\n  prefer 2 \n  apply meson\n  apply(subgoal_tac \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>a\\<noteq>0\") prefer 2\n  apply metis\n  apply(subgoal_tac \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>(\\<exists>i.(i<length(q s) \\<and> (a,b)=(q s!i)))\") prefer 2\n  apply metis\n  apply(subgoal_tac \"\\<forall>a b i.((a,b)\\<in>set(q s)\\<and>(q s!i) = (a, b))\\<longrightarrow>a=fst(q s!i)\") prefer 2\n  apply (metis fst_conv)\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s))\\<longrightarrow>fst(q s!i)\\<noteq>0\") prefer 2\n  apply (metis nth_mem prod.collapse)\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s)\\<and>i>0)\\<longrightarrow>(fst(q s!i) =end(q s!(i-1)) \\<or> fst(q s!i) =0)\")\n  prefer 2 \n  apply (metis (no_types, hide_lams))\n  apply(subgoal_tac \"(\\<forall>i.(i<length(q s))\\<longrightarrow>fst(q s!i)\\<noteq>0) \\<and> (\\<forall>i.(i<length(q s)\\<and>i>0)\\<longrightarrow>(fst(q s!i) =end(q s!(i-1)) \\<or> fst(q s!i) =0))\n                      \\<longrightarrow>(\\<forall>i.(i<length(q s)\\<and>i>0)\\<longrightarrow>(fst(q s!i) =end(q s!(i-1))))\")\n  prefer 2 \n  apply (metis (no_types, hide_lams))\n  by (metis (no_types, lifting))\n\nlemma ran_indices_lem:\n  \"Q_structure s \\<Longrightarrow> \\<forall>i.(i<length(q s))\\<longrightarrow> fst(q s!i) \\<in> ran_indices (fst(q s ! i)) (fst(q s!i)+snd(q s!i))\"\n  apply (simp add: Q_lemmas Q_basic_lemmas ran_indices_def)\n  by (metis bot_nat_0.not_eq_extremum length_0_conv length_pos_if_in_set nth_mem prod.exhaust_sel)\n\nlemma ran_indices_lem2:\n  \"q s \\<noteq> [] \\<Longrightarrow> Q_structure s \\<Longrightarrow> case_1 s \\<Longrightarrow> \\<forall>i.(i\\<ge>end(last(q s)) \\<and> i\\<le>N)\\<longrightarrow>ownB s i\\<noteq>Q\"\n  apply (simp add: Q_lemmas Q_basic_lemmas ran_indices_def case_1_def)\n  by (metis F.distinct(19) F.distinct(21) F.distinct(23) F.distinct(3) diff_is_0_eq length_greater_0_conv less_nat_zero_code linorder_neqE_nat zero_less_diff)\n  \n\nlemma ran_indices_lem3:              \n  \"q s \\<noteq> [] \\<Longrightarrow> Q_structure s \\<Longrightarrow> case_1 s \\<Longrightarrow> end(last(q s)) \\<le> N \\<Longrightarrow> ownB s (end(last(q s))) \\<noteq>Q\"\n  apply (simp add: Q_lemmas Q_basic_lemmas ran_indices_def case_1_def) \n  by (metis F.distinct(19) F.distinct(23) F.distinct(3) diff_self_eq_0 eq_imp_le le_neq_implies_less le_zero_eq length_0_conv)\n \nlemma ran_indices_lem4:\n  \"q s \\<noteq> [] \\<Longrightarrow> Q_structure s \\<Longrightarrow> case_1 s \\<Longrightarrow>  end(last(q s))\\<le>N\"\n  by (simp add: Q_lemmas Q_basic_lemmas ran_indices_def case_1_def)\n\nlemma ran_indices_lem5:\n  \"q s\\<noteq>[] \\<Longrightarrow>Q_structure s \\<Longrightarrow> case_1 s \\<Longrightarrow> Q_owns_bytes s \\<Longrightarrow> \\<forall>i.(i<length(q s)) \\<longrightarrow> fst(q s!i)\\<in>Q_indices s\"\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  by (metis (mono_tags, lifting) mem_Collect_eq nth_mem prod.collapse ran_indices_def ran_indices_lem)\n\n\nlemma case_1_Q_struct_inf:\n  assumes \"Q_structure s\"\n  and \"case_1 s\"\n  and \"Q_owns_bytes s\"\nshows  \"\\<forall>i<length (q s). fst (q s ! i) < end(q s!(length(q s)-1))\"\n  apply(case_tac \"q s=[]\")\n  apply simp\n  using assms apply(case_tac \"length (q s) =1\") \n  apply(simp add:Q_lemmas Q_basic_lemmas )\n  apply (metis lessI nth_mem prod.collapse)\n  apply safe[1]\n  apply(subgoal_tac \"\\<forall>i.(i<N \\<and> i\\<ge>end(last(q s)))\\<longrightarrow> ownB s i\\<noteq>Q\") prefer 2\n  apply(simp add:case_1_def) \n  apply (metis assms(2) end_simp less_or_eq_imp_le ran_indices_lem2)\n  apply(simp add:case_1_def)\n  apply clarify\n  apply(subgoal_tac \"end(last(q s)) = c\") prefer 2\n  apply (metis diff_self_eq_0 end_simp le_zero_eq nat_less_le)\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s))\\<longrightarrow>ownB s (fst(q s!i)) = Q\") prefer 2\n  using ran_indices_lem [where s = s] \n   defer \n   apply(subgoal_tac \"ownB s c \\<noteq>Q\") prefer 2 \n  apply (metis assms(2) ran_indices_lem3 ran_indices_lem4)\n   apply clarify\n  apply(subgoal_tac \"\\<forall>i.(ownB s i =Q \\<and> i\\<le>N)\\<longrightarrow>i<end(last(q s))\") prefer 2\n  apply (metis (no_types, lifting) assms(2) nat_le_linear nat_less_le ran_indices_lem2)\n  apply(subgoal_tac \"(\\<forall>i.(i\\<ge>end(last(q s)) \\<and> i\\<le>N)\\<longrightarrow>ownB s i\\<noteq>Q)\\<longrightarrow>(\\<forall>i.(ownB s i=Q \\<and> i\\<le>N)\\<longrightarrow>i<end(last(q s)))\") prefer 2\n  apply(unfold Q_owns_bytes_def Q_indices_def ran_indices_def)[1]\n  apply blast\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s))\\<longrightarrow>ownB s (fst(q s!i)) =Q\") prefer 2 \n  apply blast\n  apply(subgoal_tac \"\\<forall>i.(ownB s i=Q \\<and> i\\<le>N)\\<longrightarrow>i<end(last(q s))\") prefer 2\n  apply blast\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s))\\<longrightarrow>(\\<exists>a b. (a,b)\\<in>set(q s) \\<and> a=fst(q s!i))\") prefer 2\n  apply (metis nth_mem prod.exhaust_sel)\n  apply(unfold Q_lemmas Q_basic_lemmas)\n  apply(subgoal_tac \"\\<nexists>j.(j<length(q s) \\<and> ownB s (fst(q s!j))\\<noteq>Q)\") prefer 2\n  apply metis\n  apply(subgoal_tac \"\\<forall>i.(ownB s i = Q \\<and> i\\<le>N)\\<longrightarrow>i<end(last(q s))\") prefer 2\n  apply meson\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s))\\<longrightarrow> fst(q s!i) \\<in> {j. ownB s j = Q}\") prefer 2\n  apply (metis (mono_tags, lifting) mem_Collect_eq)\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s)) \\<longrightarrow> end(q s!i)\\<le>N\") prefer 2\n  apply (metis nth_mem)\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s))\\<longrightarrow>snd(q s!i)>0\") prefer 2\n  apply (metis nth_mem)\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s))\\<longrightarrow>fst(q s!i)<end(q s!i)\") prefer 2\n  apply (metis (no_types, lifting) end_simp less_add_same_cancel1)\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s))\\<longrightarrow>fst(q s!i)<N\") prefer 2 \n  apply (metis (no_types, lifting) F.distinct(23) add_leD1 end_simp nat_less_le)\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s))\\<longrightarrow> fst(q s!i) \\<in> {j. j<N}\") prefer 2 \n  apply (metis mem_Collect_eq)\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s))\\<longrightarrow>fst(q s!i) \\<in> {j. ownB s j = Q \\<and> j<N}\") prefer 2 \n  apply (metis (no_types, lifting) mem_Collect_eq)\n  apply (metis (no_types, lifting) One_nat_def end_simp last_conv_nth less_imp_le_nat)\n  apply clarify\n  by (metis Q_owns_bytes_def assms(1) assms(2) ran_indices_lem5)\n\n(*******************************************************************)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n(**********************Supporting lemmas for LOCAL W transitions*********************************)\n\n\nlemma case_trans_A2_to_A3_1:\n  shows \"s'=(s\\<lparr>ownT := W, pcW := A3\\<rparr>) \\<Longrightarrow> case_1 s \n            \\<Longrightarrow> (i\\<le>N)\\<longrightarrow>ownB s' i = ownB s i\"\n  by (simp add:case_1_def cW_step_def)\n\nlemma case_trans_A2_to_A3_2:\n  shows \"s'=(s\\<lparr>ownT := W, pcW := A3\\<rparr>) \\<Longrightarrow> T s=H s\\<Longrightarrow> case_1 s \n            \\<Longrightarrow> case_1 s'\"\n  apply (simp add:case_1_def cW_step_def)\n  apply clarify\n  by (smt (z3) diff_is_0_eq le_trans less_irrefl_nat zero_less_diff)\n\n\nlemma case_trans_A2_to_A4_1:\n  shows \"s'=(s\\<lparr>pcW := A4\\<rparr>) \\<Longrightarrow> case_1 s \n            \\<Longrightarrow> (i\\<le>N)\\<longrightarrow>ownB s' i = ownB s i\"\n  by (simp add:case_1_def cW_step_def)\n\nlemma case_trans_A2_to_A4_2:\n  shows \"s'=(s\\<lparr>pcW := A4\\<rparr>) \\<Longrightarrow> case_1 s \n            \\<Longrightarrow> case_1 s'\"\n  by (simp add:case_1_def cW_step_def)\n\nlemma case_trans_A2_to_A4_3:\n  shows \"s'=(s\\<lparr>pcW := A4\\<rparr>) \\<Longrightarrow> case_2 s \\<Longrightarrow> T s>H s\n            \\<Longrightarrow> case_2 s'\"\n  by (simp add:case_2_def cW_step_def)\n\n\n\n\nlemma case_trans_A2_to_A5_1:\n  shows \"s'=(s\\<lparr>pcW := A5\\<rparr>) \\<Longrightarrow> case_1 s \n            \\<Longrightarrow> (i\\<le>N)\\<longrightarrow>ownB s' i = ownB s i\"\n  by (simp add:case_1_def cW_step_def)\n\nlemma case_trans_A2_to_A5_2:\n  shows \"s'=(s\\<lparr>pcW := A5\\<rparr>) \\<Longrightarrow> case_1 s \n            \\<Longrightarrow> case_1 s'\"\n  by (simp add:case_1_def cW_step_def)\n\nlemma case_trans_A2_to_A5_3:\n  shows \"s'=(s\\<lparr>pcW := A5\\<rparr>) \\<Longrightarrow> case_2 s \\<Longrightarrow> T s\\<le>H s\n            \\<Longrightarrow> case_2 s'\"\n  by (simp add:case_2_def cW_step_def)\n\n\n\n\n\n\n\nlemma case_trans_A2_to_A8_1:\n  shows \"s'=(s\\<lparr>pcW := A8\\<rparr>) \\<Longrightarrow> case_1 s \n            \\<Longrightarrow> (i\\<le>N)\\<longrightarrow>ownB s' i = ownB s i\"\n  by (simp add:case_1_def cW_step_def)\n\n\nlemma case_trans_A2_to_A8_2:\n  shows \"s'=(s\\<lparr>pcW := A8\\<rparr>) \\<Longrightarrow> case_1 s \n            \\<Longrightarrow> case_1 s'\"\n  by (simp add:case_1_def cW_step_def)\n\nlemma case_trans_A2_to_A8_3:\n  shows \"s'=(s\\<lparr>pcW := A8\\<rparr>) \\<Longrightarrow> case_2 s \\<Longrightarrow> T s\\<le>H s\n            \\<Longrightarrow> case_2 s'\"\n  by (simp add:case_2_def cW_step_def)\n\nlemma case_trans_A2_to_A8_4:\n  shows \"s'=(s\\<lparr>pcW := A8\\<rparr>) \\<Longrightarrow> case_2 s \\<Longrightarrow> T s>H s\n            \\<Longrightarrow> case_2 s'\"\n  by (simp add:case_2_def cW_step_def)\n\nlemma case_trans_A3_1:\n  shows \"pre_A3_inv s \\<Longrightarrow> case_2 s \\<Longrightarrow> False\"\n  by (simp add:case_2_def pre_A3_inv_def)\n\nlemma case_trans_A3_2:\n  shows \"pre_A3_inv s \\<Longrightarrow>con_assms s\\<Longrightarrow>inv s\\<Longrightarrow> case_1 s\"\n  apply (simp add:pre_A3_inv_def con_assms_def basic_pointer_movement_def inv_def)\n  apply(subgoal_tac \"H s=T s\") prefer 2\n  apply simp apply clarify \n  apply(subgoal_tac \"\\<not>case_2 s\") prefer 2\n  apply (metis case_split_2 less_or_eq_imp_le)\n  by blast\n\nlemma case_trans_A3_to_write_1:\n  shows \"pre_A3_inv s \\<Longrightarrow>s'=(s\\<lparr>ownB := \\<lambda>i. if i < Data s (numEnqs s) then W else ownB s i,\n             pcW := Write, offset := 0, H := Data s (numEnqs s), T := 0\\<rparr>)\\<Longrightarrow>inv s\\<Longrightarrow> H s'\\<ge>T s'\"\n  by (simp add:pre_A3_inv_def inv_def)\n\nlemma case_trans_A3_to_write_2:\n  shows \"pre_A3_inv s \\<Longrightarrow>s'=(s\\<lparr>ownB := \\<lambda>i. if i < Data s (numEnqs s) then W else ownB s i,\n             pcW := Write, offset := 0, H := Data s (numEnqs s), T := 0\\<rparr>)\\<Longrightarrow>inv s\\<Longrightarrow> \\<not>case_2 s'\"\n  by (simp add:pre_A3_inv_def inv_def case_2_def)\n\nlemma case_trans_A3_to_write_3:\n  shows \"pre_A3_inv s \\<Longrightarrow>s'=(s\\<lparr>ownB := \\<lambda>i. if i < Data s (numEnqs s) then W else ownB s i,\n             pcW := Write, offset := 0, H := Data s (numEnqs s), T := 0\\<rparr>)\\<Longrightarrow>inv s\\<Longrightarrow> con_assms s\\<Longrightarrow> (i\\<ge>T s' \\<and> i<H s')\\<longrightarrow>ownB s' i=W\"\n  by (simp add:pre_A3_inv_def inv_def case_1_def)\n\nlemma case_trans_A3_to_write_4:\n  shows \"pre_A3_inv s \\<Longrightarrow>s'=(s\\<lparr>ownB := \\<lambda>i. if i < Data s (numEnqs s) then W else ownB s i,\n             pcW := Write, offset := 0, H := Data s (numEnqs s), T := 0\\<rparr>)\\<Longrightarrow>inv s\\<Longrightarrow> con_assms s\\<Longrightarrow> (i\\<ge>H s'\\<and> i<N)\\<longrightarrow>ownB s' i=B\"\n  by (simp add:pre_A3_inv_def inv_def case_1_def)\n\nlemma case_trans_A3_to_write_7:\n  shows \"pre_A3_inv s \\<Longrightarrow>s'=(s\\<lparr>ownB := \\<lambda>i. if i < Data s (numEnqs s) then W else ownB s i,\n             pcW := Write, offset := 0, H := Data s (numEnqs s), T := 0\\<rparr>)\\<Longrightarrow>inv s\\<Longrightarrow> con_assms s\\<Longrightarrow> case_1 s'\"\n  apply (simp add:pre_A3_inv_def inv_def case_1_def)\n  apply (rule_tac exI [where x =\"0\"])\n  apply (rule_tac exI [where x =\"0\"]) apply simp\n  apply (subgoal_tac \"Data s (numEnqs s)\\<le>N\")\n  apply (metis case_split_2 le_refl)\n  by blast\n\n\nlemma case_trans_A4_1:\n  shows \"pre_A4_inv s \\<Longrightarrow> T s\\<ge>tW s\\<Longrightarrow> case_1 s \\<Longrightarrow> False\"\n  apply (simp add:case_1_def pre_A4_inv_def)\n  by (metis diff_is_0_eq le_trans less_nat_zero_code)\n\nlemma case_trans_A4_2:\n  shows \"pre_A4_inv s \\<Longrightarrow> T s\\<le>hW s\\<Longrightarrow> case_2 s \\<Longrightarrow> False\"\n  apply (simp add:case_2_def pre_A4_inv_def) \n  by (metis le_antisym less_irrefl_nat less_or_eq_imp_le)\n\nlemma case_trans_A4_3:\n  shows \"pre_A4_inv s \\<Longrightarrow> T s>hW s \\<and> T s<tW s  \\<Longrightarrow> False\"\n  by (simp add:case_2_def pre_A4_inv_def) \n\nlemma case_trans_A4_4:\n  shows \"pre_A4_inv s \\<Longrightarrow> inv s\\<Longrightarrow> T s\\<ge>tW s\\<Longrightarrow> case_2 s\"\n  apply (simp add: pre_A4_inv_def inv_def) using case_trans_A4_1 [where s=s]\n  by (metis case_split_4 less_eqE trans_less_add1) \n\n\nlemma case_trans_A4_5:\n  shows \"pre_A4_inv s \\<Longrightarrow> inv s\\<Longrightarrow> T s\\<le>hW s\\<Longrightarrow> case_1 s\"\n  apply (simp add: pre_A4_inv_def inv_def) using case_trans_A4_2 [where s=s]\n  by (metis RingBuffer_BD_latest_2.case_split) \n\n\nlemma case_trans_A4_to_write_1:\n  shows \"pre_A4_inv s \\<Longrightarrow> T s\\<ge>tW s  \\<Longrightarrow> s'=(s\\<lparr>ownB := \\<lambda>i. if hW s \\<le> i \\<and> i < hW s + Data s (numEnqs s) then W else ownB s i, pcW := Write,\n          offset := hW s, H := hW s + Data s (numEnqs s)\\<rparr>) \\<Longrightarrow> inv s \\<Longrightarrow>\n    (i<offset s')\\<longrightarrow>ownB s i=ownB s' i\"\n  by (simp add:case_2_def pre_A4_inv_def inv_def) \n\nlemma case_trans_A4_to_write_2:\n  shows \"pre_A4_inv s \\<Longrightarrow> T s\\<ge>tW s  \\<Longrightarrow> s'=(s\\<lparr>ownB := \\<lambda>i. if hW s \\<le> i \\<and> i < hW s + Data s (numEnqs s) then W else ownB s i, pcW := Write,\n          offset := hW s, H := hW s + Data s (numEnqs s)\\<rparr>) \\<Longrightarrow> inv s \\<Longrightarrow>\n    (i\\<ge>H s')\\<longrightarrow>ownB s i=ownB s' i\"\n  by (simp add:case_2_def pre_A4_inv_def inv_def) \n\nlemma case_trans_A4_to_write_3:\n  shows \"pre_A4_inv s \\<Longrightarrow> T s\\<ge>tW s  \\<Longrightarrow> s'=(s\\<lparr>ownB := \\<lambda>i. if hW s \\<le> i \\<and> i < hW s + Data s (numEnqs s) then W else ownB s i, pcW := Write,\n          offset := hW s, H := hW s + Data s (numEnqs s)\\<rparr>) \\<Longrightarrow> inv s \\<Longrightarrow>\n    (hW s \\<le>i \\<and> i<H s')\\<longrightarrow>W=ownB s' i\"\n  by (simp add:case_2_def pre_A4_inv_def inv_def) \n\nlemma case_trans_A4_to_write_4:\n  shows \"pre_A4_inv s \\<Longrightarrow> T s\\<ge>tW s  \\<Longrightarrow> s'=(s\\<lparr>ownB := \\<lambda>i. if hW s \\<le> i \\<and> i < hW s + Data s (numEnqs s) then W else ownB s i, pcW := Write,\n          offset := hW s, H := hW s + Data s (numEnqs s)\\<rparr>) \\<Longrightarrow> inv s \\<Longrightarrow>\n    T s'=T s\"\n  by (simp add:case_2_def pre_A4_inv_def inv_def) \n\nlemma case_trans_A4_to_write_5:\n  shows \"pre_A4_inv s \\<Longrightarrow> T s\\<ge>tW s  \\<Longrightarrow> s'=(s\\<lparr>ownB := \\<lambda>i. if hW s \\<le> i \\<and> i < hW s + Data s (numEnqs s) then W else ownB s i, pcW := Write,\n          offset := hW s, H := hW s + Data s (numEnqs s)\\<rparr>) \\<Longrightarrow> inv s \\<Longrightarrow> con_assms s \\<Longrightarrow>\n    T s'> H s' \\<and> H s<H s' \\<and> T s=T s' \\<and> offset s'=hW s \\<and> Data s (numEnqs s) = Data s' (numEnqs s') \\<and> H s'-H s=Data s (numEnqs s) \\<and> tempR s=tempR s' \\<and> q s=q s' \\<and> ownT s=ownT s'\"\n  apply (simp add:case_2_def pre_A4_inv_def inv_def) \n  by (simp add: le_Suc_ex less_diff_conv) \n\n\nlemma case_trans_A4_to_write_6:\n  shows \"pre_A4_inv s \\<Longrightarrow> T s\\<ge>tW s  \\<Longrightarrow> s'=(s\\<lparr>ownB := \\<lambda>i. if hW s \\<le> i \\<and> i < hW s + Data s (numEnqs s) then W else ownB s i, pcW := Write,\n          offset := hW s, H := hW s + Data s (numEnqs s)\\<rparr>) \\<Longrightarrow>con_assms s \\<Longrightarrow> inv s \\<Longrightarrow>\n    case_2 s\"\n  using case_trans_A4_4 [where s=s] \n  by blast\n\nlemma case_trans_A4_to_write_7:\n  shows \"pre_A4_inv s \\<Longrightarrow> T s\\<ge>tW s  \\<Longrightarrow> s'=(s\\<lparr>ownB := \\<lambda>i. if hW s \\<le> i \\<and> i < hW s + Data s (numEnqs s) then W else ownB s i, pcW := Write,\n          offset := hW s, H := hW s + Data s (numEnqs s)\\<rparr>) \\<Longrightarrow>con_assms s \\<Longrightarrow> inv s \\<Longrightarrow>\n    case_2 s'\"\n  apply(subgoal_tac \"H s'<T s'\") prefer 2 \n  using case_trans_A4_to_write_5 [where s=s and s'=s']\n  apply blast\n  apply(subgoal_tac \"H s<H s'\") prefer 2 \n  using case_trans_A4_to_write_5 [where s=s and s'=s']\n  apply blast\n  apply(subgoal_tac \"T s=T s'\") prefer 2 \n  using case_trans_A4_to_write_5 [where s=s and s'=s']\n  apply blast\n  apply(subgoal_tac \"q s=q s'\") prefer 2 \n  using case_trans_A4_to_write_5 [where s=s and s'=s']\n  apply blast\n  apply(subgoal_tac \"ownT s=ownT s'\") prefer 2 \n  using case_trans_A4_to_write_5 [where s=s and s'=s']\n  apply blast\n  apply(subgoal_tac \"Data s (numEnqs s) = Data s' (numEnqs s')\") prefer 2 \n  using case_trans_A4_to_write_5 [where s=s and s'=s']\n   apply blast\n  apply(subgoal_tac \"H s'-H s=Data s (numEnqs s)\") prefer 2 \n  using case_trans_A4_to_write_5 [where s=s and s'=s']\n  apply blast\n  apply(subgoal_tac \"\\<forall>i.(i<offset s')\\<longrightarrow>ownB s i=ownB s' i\") prefer 2\n  using case_trans_A4_to_write_1 [where s=s and s'=s']\n  apply blast\n  apply(subgoal_tac \"\\<forall>i.(hW s \\<le>i \\<and> i<H s')\\<longrightarrow>W=ownB s' i\") prefer 2\n  using case_trans_A4_to_write_3 [where s=s and s'=s']\n  apply blast\n  apply(subgoal_tac \"\\<forall>i.(i\\<ge>H s')\\<longrightarrow>ownB s i=ownB s' i\") prefer 2\n  using case_trans_A4_to_write_2 [where s=s and s'=s']\n  apply blast\n  apply(subgoal_tac \"offset s'=hW s\") prefer 2\n  using case_trans_A4_to_write_5 [where s=s and s'=s']\n  apply blast\n  apply(subgoal_tac \"tempR s = tempR s'\") prefer 2\n  using case_trans_A4_to_write_5 [where s=s and s'=s']\n  apply blast\n  apply(unfold inv_def)[1]\n  apply(subgoal_tac \"case_2 s\") prefer 2\n  using case_trans_A4_to_write_6 [where s=s and s'=s']\n  using RingBuffer_BD_latest_2.inv_def apply blast \n  apply(subgoal_tac \"\\<not>case_1 s\") prefer 2\n  using case_trans_A4_1 apply blast\n  apply(unfold pre_A4_inv_def grd1_def grd2_def basic_pointer_movement_def)[1]\n  apply(clarify) \n  apply(thin_tac \"case_2 s\")\n  apply(thin_tac \"\\<not>case_1 s\")\n  apply(thin_tac \"mainInv s\")\n   apply(unfold case_2_def)[1]\n    (*apply instance*) apply clarify\n  apply(rule_tac ?x = \"a\" in exI)\n  apply(rule_tac ?x = \"b\" in exI) \n  apply(rule_tac exI [where x =\"H s'\"])\n  apply(rule_tac exI [where x =\"T s'\"])\n  apply(rule_tac ?x = \"e\" in exI)\n  apply(rule_tac ?x = \"f\" in exI)\n  apply (intro conjI impI)\n  apply blast \n  apply meson\n  apply (metis le_trans less_imp_le_nat)\n  apply meson\n  apply metis\n  apply blast\n  apply meson\n  apply clarify\n  apply(subgoal_tac \"i<a\\<longrightarrow>ownB s i=R\") prefer 2\n  apply (metis zero_le)\n  apply(subgoal_tac \"hW s = b\") prefer 2\n  apply (metis F.distinct(17) F.distinct(23) nat_le_linear nat_less_le zero_le)\n  apply(subgoal_tac \"(i<offset s')\\<longrightarrow>ownB s i=ownB s' i\") prefer 2\n  using case_trans_A4_to_write_1 [where s=s and s'=s']\n  apply metis\n  apply (metis le_trans nat_less_le)\n  apply(subgoal_tac \"i\\<ge>a \\<and> i<b\\<longrightarrow>ownB s i=Q\") prefer 2\n  apply (metis zero_le)\n  apply(subgoal_tac \"(i<offset s')\\<longrightarrow>ownB s i=ownB s' i\") prefer 2\n  using case_trans_A4_to_write_1 [where s=s and s'=s']\n  apply metis\n  apply (metis le_trans nat_less_le)\n  apply (metis le_eq_less_or_eq le_trans)\n  apply(subgoal_tac \"(i\\<ge>H s')\\<longrightarrow>ownB s i=ownB s' i\") prefer 2\n  using case_trans_A4_to_write_1 [where s=s and s'=s']\n  apply metis\n  apply (metis le_trans less_or_eq_imp_le)\n  apply(subgoal_tac \"(i\\<ge>H s')\\<longrightarrow>ownB s i=ownB s' i\") prefer 2\n  using case_trans_A4_to_write_1 [where s=s and s'=s']\n  apply metis\n  apply (metis le_trans less_or_eq_imp_le)\n  apply(subgoal_tac \"(i\\<ge>H s')\\<longrightarrow>ownB s i=ownB s' i\") prefer 2\n  using case_trans_A4_to_write_1 [where s=s and s'=s']\n  apply metis\n  apply (metis le_trans less_or_eq_imp_le)\n  apply(subgoal_tac \"(i\\<ge>H s')\\<longrightarrow>ownB s i=ownB s' i\") prefer 2\n  using case_trans_A4_to_write_1 [where s=s and s'=s']\n  apply metis\n  apply (metis le_trans less_or_eq_imp_le)\n  apply(subgoal_tac \"(i\\<ge>H s')\\<longrightarrow>ownB s i=ownB s' i\") prefer 2\n  using case_trans_A4_to_write_1 [where s=s and s'=s']\n  apply metis\n  apply (metis le_trans less_or_eq_imp_le)\n  apply meson\n  apply metis\n  apply metis\n  apply (metis gr_zeroI less_nat_zero_code)\n  apply meson\n  apply force\n  apply (metis F.distinct(17) F.distinct(23) less_eq_nat.simps(1) nat_le_linear nat_less_le)\n  apply(subgoal_tac \"b=H s\") prefer 2\n  apply (metis F.distinct(17) F.distinct(23) less_eq_nat.simps(1) nat_le_linear nat_less_le)\n  apply(subgoal_tac \"H s'-H s=Data s (numEnqs s)\") prefer 2\n  apply meson\n  apply metis\n  apply metis\n  apply metis\n  apply metis\n  apply metis\n  apply metis\n  apply metis\n  apply metis\n  apply metis\n  apply metis\n  apply metis\n  apply metis\n  apply metis\n  by metis\n\n\n\n\nlemma case_trans_A4_to_write_8:\n  shows \"pre_A4_inv s \\<Longrightarrow> T s\\<le>H s  \\<Longrightarrow> s'=(s\\<lparr>ownB := \\<lambda>i. if hW s \\<le> i \\<and> i < hW s + Data s (numEnqs s) then W else ownB s i, pcW := Write,\n          offset := hW s, H := hW s + Data s (numEnqs s)\\<rparr>) \\<Longrightarrow>con_assms s \\<Longrightarrow> inv s \\<Longrightarrow>\n    case_1 s\"\n  using case_trans_A4_5 [where s=s] apply (simp add:case_1_def)\n  by (simp add: pre_A4_inv_def)\n\n\nlemma case_trans_A4_to_write_9:\n  shows \"pre_A4_inv s \\<Longrightarrow> T s\\<le>H s  \\<Longrightarrow> s'=(s\\<lparr>ownB := \\<lambda>i. if hW s \\<le> i \\<and> i < hW s + Data s (numEnqs s) then W else ownB s i, pcW := Write,\n          offset := hW s, H := hW s + Data s (numEnqs s)\\<rparr>) \\<Longrightarrow>con_assms s \\<Longrightarrow> inv s \\<Longrightarrow>\n    case_1 s'\"\n  apply(simp add:inv_def)\n  using case_trans_A4_to_write_8 [where s=s] \n  apply (meson case_split_2) apply(simp add:pre_A4_inv_def)\n  apply(simp add:case_1_def)\n  apply(intro conjI impI) prefer 2\n   apply clarify\n  apply(rule_tac ?x = \"T s\" in exI)\n  apply(rule_tac ?x = b in exI) apply(intro conjI impI) prefer 2\n  apply(rule_tac ?x = \"hW s\" in exI)\n  apply(intro conjI impI)\n  apply(linarith)\n  apply(linarith)\n  apply clarify apply(intro conjI impI) apply clarify\n  apply linarith\n  apply metis\n  apply (metis le_neq_implies_less le_trans less_imp_le_nat)\n  apply (metis le_eq_less_or_eq)\n  apply blast\n  apply (metis add_leE)\n  apply blast\n  apply blast\n  apply blast\n  apply (metis add_diff_cancel_left')\n  apply meson\n  apply meson\n  apply (metis le_refl nat_less_le)\n  apply (metis nat_less_le)\n  apply (metis le_neq_implies_less)\n  apply (metis le_refl nat_less_le)\n  apply meson\n  apply (metis nat_less_le)\n  apply (metis le_antisym)\n  apply blast\n  by (metis (no_types, lifting) add.commute add_lessD1 less_diff_conv less_eqE less_imp_add_positive not_add_less1)\n\n\n\n\n\n\nlemma case_trans_A5_1:\n  shows \"pre_A5_inv s \\<Longrightarrow> inv s\\<Longrightarrow> case_1 s\"\n  apply (simp add: pre_A5_inv_def inv_def)\n  by (metis RingBuffer_BD_latest_2.case_split) \n\nlemma case_trans_A5_2:\n  shows \"pre_A5_inv s \\<Longrightarrow> inv s\\<Longrightarrow> \\<not>case_2 s\"\n  apply (simp add: pre_A5_inv_def inv_def)\n  by (metis case_split_2)\n\n\nlemma case_trans_A5_to_A6_1:\n  shows \"pre_A5_inv s  \\<Longrightarrow> s'=(s\\<lparr>pcW := A6\\<rparr>) \\<Longrightarrow>con_assms s \\<Longrightarrow> inv s \\<Longrightarrow>\n    i\\<le>N\\<longrightarrow>ownB s i=ownB s' i\"\n  by(simp add:case_1_def pre_A5_inv_def inv_def)\n\n\nlemma case_trans_A5_to_A6_2:\n  shows \"pre_A5_inv s  \\<Longrightarrow> s'=(s\\<lparr>pcW := A6\\<rparr>) \\<Longrightarrow>con_assms s \\<Longrightarrow> inv s \\<Longrightarrow>\n    case_1 s' = case_1 s\"\n  by(simp add:case_1_def)\n\nlemma case_trans_A5_to_A6_3:\n  shows \"pre_A5_inv s  \\<Longrightarrow> s'=(s\\<lparr>pcW := A6\\<rparr>) \\<Longrightarrow>con_assms s \\<Longrightarrow> inv s \\<Longrightarrow>\n    case_1 s'\"\n  using case_trans_A5_to_A6_2 [where s=s and s'=s']\n  using case_trans_A5_1 by blast\n\n\nlemma case_trans_A5_to_A6_4:\n  shows \"pre_A5_inv s  \\<Longrightarrow> s'=(s\\<lparr>pcW := A7\\<rparr>) \\<Longrightarrow>con_assms s \\<Longrightarrow> inv s \\<Longrightarrow>\n    i\\<le>N\\<longrightarrow>ownB s i=ownB s' i\"\n  by(simp add:case_1_def pre_A5_inv_def inv_def)\n\nlemma case_trans_A5_to_A6_5:\n  shows \"pre_A5_inv s  \\<Longrightarrow> s'=(s\\<lparr>pcW := A7\\<rparr>) \\<Longrightarrow>con_assms s \\<Longrightarrow> inv s \\<Longrightarrow>\n    case_1 s' = case_1 s\"\n  by(simp add:case_1_def)\n\nlemma case_trans_A5_to_A6_6:\n  shows \"pre_A5_inv s  \\<Longrightarrow> s'=(s\\<lparr>pcW := A7\\<rparr>) \\<Longrightarrow>con_assms s \\<Longrightarrow> inv s \\<Longrightarrow>\n    case_1 s'\"\n  using case_trans_A5_to_A6_5 [where s=s and s'=s']\n  using case_trans_A5_1 by blast\n\n\nlemma case_trans_A5_to_A6_7:\n  shows \"pre_A5_inv s  \\<Longrightarrow> s'=(s\\<lparr>pcW := A8\\<rparr>) \\<Longrightarrow>con_assms s \\<Longrightarrow> inv s \\<Longrightarrow>\n    i\\<le>N\\<longrightarrow>ownB s i=ownB s' i\"\n  by(simp add:case_1_def pre_A5_inv_def inv_def)\n\n\nlemma case_trans_A5_to_A6_8:\n  shows \"pre_A5_inv s  \\<Longrightarrow> s'=(s\\<lparr>pcW := A8\\<rparr>) \\<Longrightarrow>con_assms s \\<Longrightarrow> inv s \\<Longrightarrow>\n    case_1 s' = case_1 s\"\n  by(simp add:case_1_def)\n\n\nlemma case_trans_A5_to_A6_9:\n  shows \"pre_A5_inv s  \\<Longrightarrow> s'=(s\\<lparr>pcW := A8\\<rparr>) \\<Longrightarrow>con_assms s \\<Longrightarrow> inv s \\<Longrightarrow>\n    case_1 s'\"\n  using case_trans_A5_to_A6_7 [where s=s and s'=s']\n  by (metis case_trans_A2_to_A8_2 case_trans_A5_1)\n\n\nlemma case_trans_A6_1:\n  shows \"pre_A6_inv s \\<Longrightarrow> inv s\\<Longrightarrow> case_1 s\"\n  apply (simp add: pre_A6_inv_def inv_def) \n  by (metis RingBuffer_BD_latest_2.case_split) \n\nlemma case_trans_A6_2:\n  shows \"pre_A6_inv s \\<Longrightarrow> inv s\\<Longrightarrow> case_2 s \\<Longrightarrow> False\"\n  apply (simp add: pre_A6_inv_def inv_def)\n  by (metis case_split_2)\n\n\n\nlemma case_trans_A6_to_write_1:\n  shows \"pre_A6_inv s \\<Longrightarrow> s' = s\n    \\<lparr>ownB := \\<lambda>i. if hW s \\<le> i \\<and> i < hW s + Data s (numEnqs s) then W else ownB s i,\n       pcW := Write, offset := hW s, H := hW s + Data s (numEnqs s)\\<rparr>\\<Longrightarrow>inv s\\<Longrightarrow> H s'\\<ge>T s'\"\n  by (simp add:pre_A6_inv_def inv_def)\n\nlemma case_trans_A6_to_write_2:\n  shows \"pre_A6_inv s \\<Longrightarrow> s' = s\n    \\<lparr>ownB := \\<lambda>i. if hW s \\<le> i \\<and> i < hW s + Data s (numEnqs s) then W else ownB s i,\n       pcW := Write, offset := hW s, H := hW s + Data s (numEnqs s)\\<rparr>\\<Longrightarrow>inv s\\<Longrightarrow>con_assms s\\<Longrightarrow> \\<not>case_2 s'\"\n  by (simp add:pre_A6_inv_def inv_def case_2_def)\n\nlemma case_trans_A6_to_write_3:\n  shows \"pre_A6_inv s \\<Longrightarrow> s' = s\n    \\<lparr>ownB := \\<lambda>i. if hW s \\<le> i \\<and> i < hW s + Data s (numEnqs s) then W else ownB s i,\n       pcW := Write, offset := hW s, H := hW s + Data s (numEnqs s)\\<rparr>\\<Longrightarrow>inv s\\<Longrightarrow> con_assms s\\<Longrightarrow> (i\\<ge>hW s' \\<and> i<H s')\\<longrightarrow>ownB s' i=W\"\n  by (simp add:pre_A6_inv_def inv_def case_1_def)\n\nlemma case_trans_A6_to_write_4:\n  shows \"pre_A6_inv s \\<Longrightarrow> s' = s\n    \\<lparr>ownB := \\<lambda>i. if hW s \\<le> i \\<and> i < hW s + Data s (numEnqs s) then W else ownB s i,\n       pcW := Write, offset := hW s, H := hW s + Data s (numEnqs s)\\<rparr>\\<Longrightarrow>inv s\\<Longrightarrow> con_assms s\\<Longrightarrow> (i\\<ge>H s'\\<and> i<N)\\<longrightarrow>ownB s' i=B\"\n  by (simp add:pre_A6_inv_def inv_def case_1_def)\n\nlemma case_trans_A6_to_write_7:\n  shows \"pre_A6_inv s \\<Longrightarrow> s' = s\n    \\<lparr>ownB := \\<lambda>i. if hW s \\<le> i \\<and> i < hW s + Data s (numEnqs s) then W else ownB s i,\n       pcW := Write, offset := hW s, H := hW s + Data s (numEnqs s)\\<rparr>\\<Longrightarrow>inv s\\<Longrightarrow> con_assms s\\<Longrightarrow> case_1 s'\"\n  apply(subgoal_tac \"\\<not>case_2 s\") prefer 2\n  using case_trans_A6_to_write_2 [where s=s and s'=s']\n  using case_trans_A6_2 apply blast\n  apply (simp add:pre_A6_inv_def inv_def case_1_def)\n  apply(intro conjI impI) \n  apply (metis (no_types, lifting) add_le_cancel_left le_add_diff_inverse le_antisym less_imp_le_nat nat_neq_iff)\n  apply clarify\n  apply (rule_tac exI [where x =\"T s\"]) \n  apply(rule_tac ?x = \"b\" in exI) apply (intro conjI impI)\n  apply blast \n  apply(rule_tac ?x = \"c\" in exI)\n  apply (intro conjI impI)\n  apply linarith\n  apply linarith \n  apply (metis le_trans nat_less_le)\n  apply (metis le_trans nat_less_le)\n  apply (metis le_trans nat_less_le)\n  apply (metis F.distinct(17) F.distinct(23) le_refl nat_less_le nat_neq_iff)\n  apply (metis)\n  apply (metis le_trans nat_less_le)\n  apply (metis le_neq_implies_less le_refl le_trans)\n  apply (metis Nat.add_diff_assoc2 diff_self_eq_0 le_refl le_trans nat_less_le plus_nat.add_0)\n  apply meson\n  apply meson\n  apply meson\n  apply meson\n  apply meson\n  apply meson\n  apply meson\n  apply meson\n  by meson\n\n\nlemma case_trans_A7_1:\n  shows \"pre_A7_inv s \\<Longrightarrow> inv s\\<Longrightarrow> case_1 s\"\n  apply (simp add: pre_A7_inv_def inv_def) \n  by (metis RingBuffer_BD_latest_2.case_split) \n\nlemma case_trans_A7_2:\n  shows \"pre_A7_inv s \\<Longrightarrow> inv s\\<Longrightarrow> case_2 s \\<Longrightarrow> False\"\n  apply (simp add: pre_A7_inv_def inv_def)\n  by (metis case_split_2)\n\nlemma case_trans_A7_to_write_1:\n  shows \"pre_A7_inv s \\<Longrightarrow> s' = (s\\<lparr>ownB :=\n          \\<lambda>i. if hW s \\<le> i \\<and> i < N then D\n              else ownB (s\\<lparr>ownB := \\<lambda>i. if i < Data s (numEnqs s) then W else ownB s i\\<rparr>) i,\n          pcW := Write, offset := 0, H := Data s (numEnqs s)\\<rparr>)\\<Longrightarrow>inv s\\<Longrightarrow> H s'<T s'\"\n  by (simp add:pre_A7_inv_def inv_def)\n\nlemma case_trans_A7_to_write_2:\n  shows \"pre_A7_inv s \\<Longrightarrow> s' = (s\\<lparr>ownB :=\n          \\<lambda>i. if hW s \\<le> i \\<and> i < N then D\n              else ownB (s\\<lparr>ownB := \\<lambda>i. if i < Data s (numEnqs s) then W else ownB s i\\<rparr>) i,\n          pcW := Write, offset := 0, H := Data s (numEnqs s)\\<rparr>)\\<Longrightarrow>inv s\\<Longrightarrow>con_assms s\\<Longrightarrow> \\<not>case_1 s'\"\n  by (simp add:pre_A7_inv_def inv_def case_1_def)\n  \n\n\n\nlemma case_trans_A7_to_write_3:\n  shows \"pre_A7_inv s \\<Longrightarrow> s' = (s\\<lparr>ownB :=\n          \\<lambda>i. if hW s \\<le> i \\<and> i < N then D\n              else ownB (s\\<lparr>ownB := \\<lambda>i. if i < Data s (numEnqs s) then W else ownB s i\\<rparr>) i,\n          pcW := Write, offset := 0, H := Data s (numEnqs s)\\<rparr>)\\<Longrightarrow>inv s\\<Longrightarrow> con_assms s\\<Longrightarrow> (i\\<ge>0 \\<and> i<H s')\\<longrightarrow>ownB s' i=W\"\n  by (simp add:pre_A7_inv_def inv_def case_2_def)\n\nlemma case_trans_A7_to_write_4:\n  shows \"pre_A7_inv s \\<Longrightarrow> s' = (s\\<lparr>ownB :=\n          \\<lambda>i. if hW s \\<le> i \\<and> i < N then D\n              else ownB (s\\<lparr>ownB := \\<lambda>i. if i < Data s (numEnqs s) then W else ownB s i\\<rparr>) i,\n          pcW := Write, offset := 0, H := Data s (numEnqs s)\\<rparr>)\\<Longrightarrow>inv s\\<Longrightarrow> con_assms s\\<Longrightarrow> (i\\<ge>hW s\\<and> i<N)\\<longrightarrow>ownB s' i=D\"\n  by (simp add:pre_A7_inv_def inv_def case_2_def)\n\nlemma case_trans_A7_to_write_7:\n  shows \"pre_A7_inv s \\<Longrightarrow> s' = (s\\<lparr>ownB :=\n          \\<lambda>i. if hW s \\<le> i \\<and> i < N then D\n              else ownB (s\\<lparr>ownB := \\<lambda>i. if i < Data s (numEnqs s) then W else ownB s i\\<rparr>) i,\n          pcW := Write, offset := 0, H := Data s (numEnqs s)\\<rparr>)\\<Longrightarrow>inv s\\<Longrightarrow> con_assms s\\<Longrightarrow> case_2 s'\"\n  apply(subgoal_tac \"\\<not>case_2 s\") prefer 2\n  using case_trans_A7_to_write_2 [where s=s and s'=s']\n  using case_trans_A7_2 apply blast \n  apply (simp add:pre_A7_inv_def inv_def) apply(thin_tac \"\\<not>case_2 s\") apply(simp add:case_1_def case_2_def)\n  \n  apply clarify\n  apply(rule_tac ?x = \"0\" in exI) \n  apply(rule_tac ?x = \"0\" in exI) apply (intro conjI impI)\n  apply blast \n  apply(rule_tac ?x = \"Data s (numEnqs s)\" in exI)\n  apply (intro conjI impI)\n  apply linarith\n  apply(rule_tac ?x = \"T s\" in exI)\n  apply (intro conjI impI) \n  apply linarith \n  apply(rule_tac ?x = \"b\" in exI) \n  apply (intro conjI impI) \n  apply linarith \n  apply(rule_tac ?x = \"c\" in exI) \n  apply (intro conjI impI) \n  apply linarith \n  apply (metis le_trans)\n  apply blast\n  apply blast\n  apply blast  \n  apply (metis le_antisym le_trans nat_less_le) \n  apply (metis le_antisym le_trans nat_less_le)\n  apply (metis le_antisym le_trans nat_less_le)\n  apply (metis le_trans nat_le_linear nat_less_le)\n  apply blast\n  apply fastforce\n  apply blast  \n  apply blast  \n  apply metis\n  apply blast\n  apply blast\n  apply blast \n  apply (metis diff_zero) \n  apply force\n  apply fastforce\n  apply meson\n  apply meson\n  apply (metis add_implies_diff)\n  apply meson\n  apply force\n  apply meson\n  apply force\n  apply fastforce\n  apply meson\n  apply meson\n  by (metis le_neq_implies_less)\n  \n\n\n\n\nlemma case_trans_Enqueue_to_idleW_case_1_1:\n  shows \"pre_enqueue_inv s \\<Longrightarrow> inv s\\<Longrightarrow> s'= (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s),\n          ownB :=\n            \\<lambda>i. if ownB s i = W \\<and> i \\<le> N then Q else ownB (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s)\\<rparr>) i,\n          pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr>) \\<Longrightarrow>case_1 s \\<Longrightarrow> con_assms s\n      \\<Longrightarrow> H s\\<ge>T s\"\n  apply (simp add: pre_enqueue_inv_def inv_def case_1_def) \n  by (metis le_trans)\n\nlemma case_trans_Enqueue_to_idleW_case_1_2:\n  shows \"pre_enqueue_inv s \\<Longrightarrow> inv s\\<Longrightarrow> s'= (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s),\n          ownB :=\n            \\<lambda>i. if ownB s i = W \\<and> i \\<le> N then Q else ownB (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s)\\<rparr>) i,\n          pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr>) \\<Longrightarrow>case_1 s \\<Longrightarrow> con_assms s\n      \\<Longrightarrow> H s'\\<ge>T s'\"\n  apply (simp add: pre_enqueue_inv_def inv_def case_1_def) \n  by (metis le_trans)\n\nlemma case_trans_Enqueue_to_idleW_case_1_3:\n  shows \"pre_enqueue_inv s \\<Longrightarrow> inv s\\<Longrightarrow> s'= (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s),\n          ownB :=\n            \\<lambda>i. if ownB s i = W \\<and> i \\<le> N then Q else ownB (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s)\\<rparr>) i,\n          pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr>) \\<Longrightarrow>case_1 s \\<Longrightarrow> con_assms s\n      \\<Longrightarrow> i<offset s\\<Longrightarrow>ownB s i=ownB s' i\"\n  by (simp add: pre_enqueue_inv_def inv_def case_1_def) \n\nlemma case_trans_Enqueue_to_idleW_case_1_4:\n  shows \"pre_enqueue_inv s \\<Longrightarrow> inv s\\<Longrightarrow> s'= (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s),\n          ownB :=\n            \\<lambda>i. if ownB s i = W \\<and> i \\<le> N then Q else ownB (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s)\\<rparr>) i,\n          pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr>) \\<Longrightarrow>case_1 s \\<Longrightarrow> con_assms s\n      \\<Longrightarrow> i\\<ge>H s'\\<and> i\\<le>N\\<Longrightarrow>ownB s i=ownB s' i\"\n  apply (simp add: pre_enqueue_inv_def inv_def case_1_def)\n  by (metis F.distinct(5) F.distinct(9) nat_less_le)\n\nlemma case_trans_Enqueue_to_idleW_case_1_5:\n  shows \"pre_enqueue_inv s \\<Longrightarrow> inv s\\<Longrightarrow> s'= (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s),\n          ownB :=\n            \\<lambda>i. if ownB s i = W \\<and> i \\<le> N then Q else ownB (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s)\\<rparr>) i,\n          pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr>) \\<Longrightarrow>case_1 s \\<Longrightarrow> con_assms s\n      \\<Longrightarrow> offset s \\<le> i \\<and> i < offset s + Data s (numEnqs s) \\<Longrightarrow>Q=ownB s' i\"\n  by (simp add: pre_enqueue_inv_def inv_def case_1_def tempW_def) \n\n\n\n\n\nlemma case_trans_Enqueue_to_idleW_case_1_6:\n  shows \"pre_enqueue_inv s \\<Longrightarrow> inv s\\<Longrightarrow> q s = [] \\<Longrightarrow> s'= (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s),\n          ownB :=\n            \\<lambda>i. if ownB s i = W \\<and> i \\<le> N then Q else ownB (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s)\\<rparr>) i,\n          pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr>) \\<Longrightarrow>case_1 s \\<Longrightarrow> con_assms s\n     \\<Longrightarrow>case_1 s'\"\n  apply(simp add:inv_def)\n  apply(subgoal_tac \"\\<not>case_2 s \") prefer 2\n  apply (meson case_split_5) apply(thin_tac \"\\<not> case_2 s\")\n  apply (simp add: pre_enqueue_inv_def inv_def case_1_def tempW_def) \n  apply clarify apply simp\n  apply(rule_tac ?x = \"T s\" in exI)\n  apply(rule_tac ?x = \"b\" in exI) apply (intro conjI impI)\n  apply meson\n  apply(rule_tac ?x = \"offset s + Data s (numEnqs s)\" in exI)\n  apply (intro conjI impI)\n  apply (metis F.distinct(5))\n  apply (metis (mono_tags, hide_lams) le_trans less_or_eq_imp_le linorder_neqE_nat) \n  apply (metis F.distinct(5)) \n  apply (metis F.distinct(1))\n  apply (metis le_trans less_or_eq_imp_le)\n  apply (metis Suc_leI not_less_eq_eq)\n  apply blast\n  apply (metis less_irrefl_nat)\n  apply (metis less_irrefl_nat)\n  apply meson\n  apply meson \n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply (metis F.distinct(1) F.distinct(5) Suc_pred bot_nat_0.not_eq_extremum diff_0_eq_0 diff_Suc_Suc diff_diff_cancel diff_diff_left diff_is_0_eq diff_is_0_eq' diff_self_eq_0 le_refl less_nat_zero_code linorder_neqE_nat nat_add_left_cancel_less nat_le_linear not0_implies_Suc old.nat.inject zero_less_Suc zero_less_diff)\n  apply metis\n  by metis\n            \n            \n\n\n\n\n\nlemma case_trans_Write_to_Enqueue_case_1:\n  shows \"pre_write_inv s \\<Longrightarrow> inv s\\<Longrightarrow> s'=s\\<lparr>numWrites := Suc (numWrites s), pcW := Enqueue,\n       ownD :=\n         \\<lambda>i. if i = numWrites s then B\n             else ownD (s\\<lparr>numWrites := Suc (numWrites s), pcW := Enqueue\\<rparr>) i,\n       data_index :=\n         \\<lambda>x. if (offset s, Data s (numEnqs s)) = x then numEnqs s\n             else data_index\n                   (s\\<lparr>numWrites := Suc (numWrites s), pcW := Enqueue,\n                        ownD :=\n                          \\<lambda>i. if i = numWrites s then B\n                              else ownD (s\\<lparr>numWrites := Suc (numWrites s), pcW := Enqueue\\<rparr>) i\\<rparr>)\n                   x\\<rparr> \\<Longrightarrow>case_1 s \\<Longrightarrow> con_assms s\n     \\<Longrightarrow>case_1 s'\"\n  by (simp add:pre_write_inv_def case_1_def)\n\n\nlemma case_trans_Write_to_Enqueue_case_2:\n  shows \"pre_write_inv s \\<Longrightarrow> inv s\\<Longrightarrow> s'=s\\<lparr>numWrites := Suc (numWrites s), pcW := Enqueue,\n       ownD :=\n         \\<lambda>i. if i = numWrites s then B\n             else ownD (s\\<lparr>numWrites := Suc (numWrites s), pcW := Enqueue\\<rparr>) i,\n       data_index :=\n         \\<lambda>x. if (offset s, Data s (numEnqs s)) = x then numEnqs s\n             else data_index\n                   (s\\<lparr>numWrites := Suc (numWrites s), pcW := Enqueue,\n                        ownD :=\n                          \\<lambda>i. if i = numWrites s then B\n                              else ownD (s\\<lparr>numWrites := Suc (numWrites s), pcW := Enqueue\\<rparr>) i\\<rparr>)\n                   x\\<rparr> \\<Longrightarrow>case_2 s \\<Longrightarrow> con_assms s\n     \\<Longrightarrow>case_2 s'\"\n  by (simp add:pre_write_inv_def case_2_def)\n\nlemma case_trans_Write_to_Enqueue_case_3:\n  shows \"pre_write_inv s \\<Longrightarrow> inv s\\<Longrightarrow> s'=s\\<lparr>numWrites := Suc (numWrites s), pcW := Enqueue,\n       ownD :=\n         \\<lambda>i. if i = numWrites s then B\n             else ownD (s\\<lparr>numWrites := Suc (numWrites s), pcW := Enqueue\\<rparr>) i,\n       data_index :=\n         \\<lambda>x. if (offset s, Data s (numEnqs s)) = x then numEnqs s\n             else data_index\n                   (s\\<lparr>numWrites := Suc (numWrites s), pcW := Enqueue,\n                        ownD :=\n                          \\<lambda>i. if i = numWrites s then B\n                              else ownD (s\\<lparr>numWrites := Suc (numWrites s), pcW := Enqueue\\<rparr>) i\\<rparr>)\n                   x\\<rparr> \\<Longrightarrow>case_1 s \\<or> case_2 s \\<Longrightarrow> con_assms s\n     \\<Longrightarrow>case_1 s' \\<or> case_2 s'\"\n  by (simp add:pre_write_inv_def case_1_def case_2_def)\n\nlemma case_trans_Write_to_Enqueue_case_4:\n  shows \" s'=s\\<lparr>numWrites := Suc (numWrites s), pcW := Enqueue,\n       ownD :=\n         \\<lambda>i. if i = numWrites s then B\n             else ownD (s\\<lparr>numWrites := Suc (numWrites s), pcW := Enqueue\\<rparr>) i,\n       data_index :=\n         \\<lambda>x. if (offset s, Data s (numEnqs s)) = x then numEnqs s\n             else data_index\n                   (s\\<lparr>numWrites := Suc (numWrites s), pcW := Enqueue,\n                        ownD :=\n                          \\<lambda>i. if i = numWrites s then B\n                              else ownD (s\\<lparr>numWrites := Suc (numWrites s), pcW := Enqueue\\<rparr>) i\\<rparr>)\n                   x\\<rparr> \n     \\<Longrightarrow>\\<forall>i::nat. ownB s i=ownB s' i \\<and> T s = T s' \\<and> H s = H s' \\<and> offset s = offset s' \\<and> tempR s=tempR s' \\<and> q s=q s'\"\n  by simp \n\n(************************************* queue transition lemmas **************************************************)\n\n\n\nlemma peculiar_1:\n  assumes \"Q_gap_structure s\"\n  and \"Q_offsets_differ s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\n  shows \"fst(q s!1) = end(q s!0) \\<or> fst(q s!1) =0\"\n  using assms apply(simp add:Q_gap_structure_def Q_offsets_differ_def Q_structure_def) \n  by (metis One_nat_def diff_add_zero length_greater_0_conv length_tl less_numeral_extra(1) plus_1_eq_Suc zero_less_diff)\n  \nlemma peculiar_2:\n  assumes \"Q_gap_structure s\"\n  and \"Q_offsets_differ s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\n  shows \"(end(hd(q s)) = fst(hd(tl(q s)))\\<and> fst(hd(tl(q s)))\\<noteq>0) \\<or> fst(hd(tl(q s))) =0\"\n  using assms apply(simp add:Q_gap_structure_def Q_offsets_differ_def Q_structure_def) \n  by (metis Nitpick.size_list_simp(2) One_nat_def diff_add_zero hd_conv_nth less_Suc_eq_0_disj not_gr_zero nth_tl plus_1_eq_Suc)\n  \nlemma peculiar_3:\n  assumes \"Q_structure s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\nshows \"(end(hd(q s)) = fst(hd(tl(q s)))\\<and> fst(hd(tl(q s)))\\<noteq>0) \\<or> fst(hd(tl(q s))) =0\"\n  using peculiar_1 peculiar_2 Q_structure_def Q_basic_struct_def \nproof -\n  have \"Q_basic_struct s\"\nby (metis (no_types) Nil_tl Q_structure_def assms(1) assms(3))\nthen show ?thesis\nby (metis Nil_tl Q_basic_struct_def assms(3) peculiar_2)\nqed\n\nlemma peculiar_4:\n  assumes \"Q_offsets_differ s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\nshows \"\\<forall>i.(i<length(q s) \\<and> i>0)\\<longrightarrow>fst(q s!0) \\<noteq> fst(q s!i)\"\n  using assms by (simp add:Q_offsets_differ_def) \n\nlemma peculiar_5:\n  assumes \"Q_offsets_differ s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\nshows \"\\<forall>i.(i<length(q s) \\<and> i>0)\\<longrightarrow>fst(hd(q s)) \\<noteq> fst(q s!i)\"\n  using assms peculiar_4 \n  by (simp add: peculiar_4 hd_conv_nth)\n\nlemma peculiar_6:\n  assumes \"Q_offsets_differ s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\nshows \"\\<forall>i.(i<length(tl(q s)))\\<longrightarrow>fst(hd(q s)) \\<noteq> fst(tl(q s)!i)\"\n  using peculiar_4 peculiar_5 \n  by (simp add: Q_head_relates_tail assms(1) assms(2) hd_conv_nth)\n\nlemma peculiar_7:\n  assumes \"Q_offsets_differ s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\nshows \"\\<forall>i.(i<(length((q s))-1))\\<longrightarrow>fst(hd(q s)) \\<noteq> fst(tl(q s)!i)\"\n  using assms peculiar_6 \n  by (simp add: peculiar_6)\n\nlemma peculiar_8:\n  assumes \"Q_has_no_overlaps s\"\n  and \"Q_has_no_uroboros s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\nshows \"\\<forall>x.(x\\<in>set(q s) \\<and> x\\<noteq>hd(q s) \\<and> fst(hd(q s))<fst(x))\\<longrightarrow>end(hd(q s))\\<le>fst(x)\"\n  using assms Q_has_no_overlaps_def Q_has_no_uroboros_def\n  using hd_in_set by blast\n\nlemma peculiar_9:\n  assumes \"Q_has_no_overlaps s\"\n  and \"Q_has_no_uroboros s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\nshows \"\\<forall>x.(x\\<in>set(tl(q s)) \\<and> fst(hd(q s))<fst(x))\\<longrightarrow>end(hd(q s))\\<le>fst(x)\"\n  using peculiar_8 \n  by (metis assms(1) assms(2) assms(3) assms(4) dual_order.irrefl list.set_sel(2))\n\nlemma peculiar_10:\n  assumes \"Q_has_no_overlaps s\"\n  and \"Q_has_no_uroboros s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\nshows \"\\<forall>i.(i<(length(q s)-1) \\<and> fst(hd(q s))<fst(tl(q s)!i))\\<longrightarrow>end(hd(q s))\\<le>fst(tl(q s)!i)\"\n  by (metis assms(1) assms(2) assms(3) assms(4) length_tl nth_mem peculiar_9)\n\nlemma peculiar_11:\n  assumes \"Q_has_no_overlaps s\"\n  and \"Q_has_no_uroboros s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\nshows \"\\<forall>x.(x\\<in>set(q s) \\<and> x\\<noteq>hd(q s) \\<and> fst(hd(q s))>fst(x))\\<longrightarrow>fst(hd(q s))\\<ge>end(x)\"\n  using assms Q_has_no_overlaps_def Q_has_no_uroboros_def \n  using hd_in_set by blast\n\nlemma peculiar_12:\n  assumes \"Q_has_no_overlaps s\"\n  and \"Q_has_no_uroboros s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\nshows \"\\<forall>x.(x\\<in>set(tl(q s)) \\<and> fst(hd(q s))>fst(x))\\<longrightarrow>fst(hd(q s))\\<ge>end(x)\"\n  using assms Q_has_no_overlaps_def peculiar_11 \n  by (metis list.set_sel(2))\n\nlemma peculiar_13:\n  assumes \"Q_has_no_overlaps s\"\n  and \"Q_has_no_uroboros s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\nshows \"\\<forall>i.(i<(length(q s)-1) \\<and> fst(hd(q s))>fst(tl(q s)!i))\\<longrightarrow>fst(hd(q s))\\<ge>end(tl(q s)!i)\"\n  using assms peculiar_12 \n  by (metis length_tl nth_mem)\n\nlemma peculiar_14:\n  assumes \"Q_has_no_overlaps s\"\n  and \"Q_has_no_uroboros s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\nshows \"(\\<forall>i.(i<(length(q s)-1) \\<and> fst(hd(q s))>fst(tl(q s)!i))\\<longrightarrow>fst(hd(q s))\\<ge>end(tl(q s)!i))\n      \\<and>(\\<forall>i.(i<(length(q s)-1) \\<and> fst(hd(q s))<fst(tl(q s)!i))\\<longrightarrow>end(hd(q s))\\<le>fst(tl(q s)!i))\"\n  using peculiar_13 peculiar_10 \n  using assms(1) assms(2) assms(3) assms(4) by blast\n\nlemma peculiar_15:\n  assumes \"Q_has_no_overlaps s\"\n  and \"Q_has_no_uroboros s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\nshows \"\\<forall>i<length (q s) - Suc 0.\n       (fst (hd (q s)) < fst (tl (q s) ! i) \\<longrightarrow>\n        fst (hd (q s)) + snd (hd (q s)) \\<le> fst (tl (q s) ! i)) \\<and>\n       (fst (tl (q s) ! i) < fst (hd (q s)) \\<longrightarrow>\n        fst (tl (q s) ! i) + snd (tl (q s) ! i) \\<le> fst (hd (q s)))\"\n  using peculiar_14 \n  by (metis One_nat_def assms(1) assms(2) assms(3) assms(4) end_simp)\n\n\nlemma peculiar_16:\n  assumes \"Q_structure s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\nshows \"\\<forall>i<length (q s) - Suc 0.\n       (fst (hd (q s)) < fst (tl (q s) ! i) \\<longrightarrow>\n        fst (hd (q s)) + snd (hd (q s)) \\<le> fst (tl (q s) ! i)) \\<and>\n       (fst (tl (q s) ! i) < fst (hd (q s)) \\<longrightarrow>\n        fst (tl (q s) ! i) + snd (tl (q s) ! i) \\<le> fst (hd (q s)))\"\n  using peculiar_15 Q_structure_def \n  using Q_basic_struct_def assms(1) assms(2) assms(3) by auto\n\nlemma peculiar_17 :\n  assumes \"inv s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\nshows \"\\<forall>i<length (q s) - Suc 0.\n       (fst (hd (q s)) < fst (tl (q s) ! i) \\<longrightarrow>\n        fst (hd (q s)) + snd (hd (q s)) \\<le> fst (tl (q s) ! i)) \\<and>\n       (fst (tl (q s) ! i) < fst (hd (q s)) \\<longrightarrow>\n        fst (tl (q s) ! i) + snd (tl (q s) ! i) \\<le> fst (hd (q s)))\"\n  using peculiar_16 inv_def Q_structure_def \n  using assms(1) assms(2) assms(3) by blast\n\nlemma peculiar_18:\n  assumes \"Q_has_no_uroboros s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\nshows \"fst (q s!0) \\<noteq> end (last (q s))\"\n  using Q_has_no_uroboros_def \n  by (metis assms(1) assms(2) assms(3) butlast.simps(2) list.exhaust_sel list.set_intros(1) nth_Cons_0)\n\nlemma peculiar_19:\n  assumes \"Q_structure s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\nshows \"fst (q s!0) \\<noteq> end (last (q s))\"\n  using Q_has_no_uroboros_def Q_structure_def peculiar_18 \n  using Q_basic_struct_def assms(1) assms(2) assms(3) by blast\n\nlemma peculiar_20:\n  assumes \"Q_structure s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\nshows \"fst (hd(q s)) \\<noteq> end (last (q s))\"\n  using peculiar_19\n  by (metis assms(1) assms(2) assms(3) hd_conv_nth)\n\nlemma peculiar_21:\n  assumes \"Q_structure s\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\nshows \"fst (hd(q s)) \\<noteq> end (last (tl(q s)))\"\n  using peculiar_20\n  by (metis assms(1) assms(2) assms(3) last_tl)\n\nlemma peculiar_22:\n  assumes \"Q_structure s\"\n  and \"tempR_structure s\"\n  and \"fst(tempR s) =0\"\nshows \"\\<forall>i.(i<length(q s)\\<and> i>0)\\<longrightarrow>fst(q s!i) = end(q s!(i-1))\"\n  using assms apply (simp add:Q_lemmas Q_basic_lemmas tempR_lemmas tempR_basic_lemmas)\n  by (metis length_0_conv less_nat_zero_code)\n\nlemma peculiar_23:\n  assumes \"Q_structure s\"\n  and \"tempR_structure s\"\n  and \"fst(tempR s) =0\"\nshows \"\\<forall>i.(i<length(q s))\\<longrightarrow>fst(q s!i) >0\"\n  using assms apply (simp add:Q_lemmas Q_basic_lemmas tempR_lemmas tempR_basic_lemmas)\n  by (metis length_0_conv less_nat_zero_code)\n\nlemma peculiar_24:\n  assumes \"Q_structure s\"\n  and \"tempR_structure s\"\n  and \"fst(tempR s) =0\"\n  and \"q s\\<noteq>[]\" and \"tl(q s)\\<noteq>[]\"\nshows \"fst(q s!0) =end(tempR s)\"\n  using assms apply (simp add:Q_lemmas Q_basic_lemmas tempR_lemmas tempR_basic_lemmas)\n  by (metis hd_conv_nth length_greater_0_conv zero_less_iff_neq_zero)\n\nlemma peculiar_25:\n  assumes \"Q_offsets_differ s\"\n  and \"Q_gap_structure s\"\n  and \"fst(hd(q s)) =0\"\n  and \"tl(q s)\\<noteq>[]\"\nshows \"\\<forall>i.(i<length(q s)\\<and>i>0)\\<longrightarrow>fst(q s!i) = end(q s!(i-1))\"\n  using assms \n  by (metis Q_hd_zero_implies_structure)\n\nlemma peculiar_26:\n  assumes \"Q_offsets_differ s\"\n  and \"Q_gap_structure s\"\n  and \"fst(hd(q s)) =0\"\n  and \"tl(q s)\\<noteq>[]\"\nshows \"\\<forall>i.(i<length(q s)\\<and>i>0)\\<longrightarrow>(q s!i) = (tl(q s)!(i-1))\"\n  using assms apply(simp add:Q_lemmas Q_basic_lemmas)\n  by (metis Nitpick.size_list_simp(2) Suc_pred add_less_cancel_left list.sel(2) nth_tl plus_1_eq_Suc)\n\n\nlemma peculiar_27:\n  assumes \"Q_offsets_differ s\"\n  and \"Q_gap_structure s\"\n  and \"fst(hd(q s)) =0\"\n  and \"tl(q s)\\<noteq>[]\"\nshows \"\\<forall>i.(i<length(q s)\\<and>i>1)\\<longrightarrow>fst(tl(q s)!(i-1)) = end(tl(q s)!(i-2))\"\n  using assms apply(simp add:Q_lemmas Q_basic_lemmas)\n  by (smt (verit, ccfv_SIG) Nitpick.size_list_simp(2) Suc_diff_Suc add_less_cancel_left assms(1) assms(2) diff_less less_trans_Suc list.sel(2) nth_tl numeral_1_eq_Suc_0 numeral_2_eq_2 numerals(1) peculiar_26 peculiar_5 plus_1_eq_Suc zero_less_two)\n\n\n\n\nlemma peculiar_28:\n  assumes \"Q_offsets_differ s\"\n  and \"Q_gap_structure s\"\n  and \"Q_has_no_uroboros s\"\n  and \"fst(hd(q s)) =0\"\n  and \"tl(q s)\\<noteq>[]\"\n  and \"butlast(tl(q s))\\<noteq>[]\"\nshows \"last(tl(q s)) =last(q s)\"\n  using assms \n  by (simp add: last_tl)\n\n\n\nlemma peculiar_29:\n  assumes \"Q_offsets_differ s\"\n  and \"Q_gap_structure s\"\n  and \"Q_has_no_uroboros s\"\n  and \"fst(hd(q s)) =0\"\n  and \"tl(q s)\\<noteq>[]\"\n  and \"butlast(tl(q s))\\<noteq>[]\"\nshows \"\\<forall>i.(i<length(butlast(tl(q s))))\\<longrightarrow>(tl(q s)!i) = (q s!(i+1))\"\n  using assms \n  by (simp add: peculiar_26)\n\nlemma peculiar_30:\n  assumes \"Q_offsets_differ s\"\n  and \"Q_gap_structure s\"\n  and \"Q_has_no_uroboros s\"\n  and \"fst(hd(q s)) =0\"\n  and \"tl(q s)\\<noteq>[]\"\n  and \"butlast(tl(q s))\\<noteq>[]\"\nshows \"end(last(q s)) = end(last(tl(q s)))\"\n  using assms \n  by (simp add: last_tl)\n\n\nlemma peculiar_31:\n  assumes \"Q_offsets_differ s\"\n  and \"Q_gap_structure s\"\n  and \"Q_has_no_uroboros s\"\n  and \"fst(hd(q s)) =0\"\n  and \"tl(q s)\\<noteq>[]\"\n  and \"butlast(tl(q s))\\<noteq>[]\"\nshows \"\\<forall>i.(i<(length(tl(q s))-1))\\<longrightarrow>fst(tl(q s)!i) \\<noteq>end(last(tl(q s)))\"\n  using assms peculiar_30 peculiar_29 apply simp\n  unfolding Q_lemmas Q_basic_lemmas apply safe apply(subgoal_tac \"last(tl(q s)) =(tl(q s)!(length(tl(q s))-1))\")\n  prefer 2 \n  apply (simp add: last_conv_nth) apply simp\n  by (metis One_nat_def Suc_eq_plus1 Suc_lessD assms(5) diff_Suc_eq_diff_pred in_set_conv_nth last_tl length_butlast length_tl less_diff_conv nth_butlast nth_tl prod.exhaust_sel)\n\n\n\nlemma tail_preserves_struct:\n  \"Q_gap_structure s \\<Longrightarrow> fst (q s ! 0) = 0 \\<Longrightarrow>\\<forall> i . i<length (q s) \\<longrightarrow> snd(q s ! i) > 0 \\<Longrightarrow>\n  Q_offsets_differ s \\<Longrightarrow> length(q s)>0 \\<Longrightarrow>\n\\<forall> i . (i<length (q s) \\<and> i>0)\\<longrightarrow> fst(q s ! i) > fst (q s ! 0)\"\n  apply(simp add:Q_gap_structure_def Q_offsets_differ_def)\n  by (metis gr_implies_not_zero not_gr_zero)\n\n\nlemma queue_is_finite_set:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\nshows \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longleftrightarrow>(\\<exists>i.(i<length(q s) \\<and> (a, b) =(q s!i)))\"\n  using assms apply(simp add:Q_lemmas Q_basic_lemmas)\n  by (metis in_set_conv_nth)\n  \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n(*******************************LOCAL W_step shows inv s'*************************************)\n\n\nlemma W_inv_A1_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = A1\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"    \nshows \"inv s'\"\n  using assms apply(simp add:inv_def pre_W_def cW_step_def pre_A1_inv_def)\n  apply (intro conjI impI)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"case_1 s\")\n  apply(simp add:case_1_def)\n  apply(simp add:case_2_def)\n  by(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n\n\n\n\nlemma W_inv_A2_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = A2\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"    \nshows \"inv s'\"\n  using assms apply(simp add:inv_def pre_W_def cW_step_def pre_A2_inv_def)\n  apply(case_tac \"tW s = hW s\", simp_all)\n  apply(intro conjI impI)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply (elim conjE disjE)\n  apply(case_tac \"case_1 s'\") \n  using case_trans_A2_to_A3_2 [where s=s]\n  apply blast \n  using \\<open>\\<And>s'. \\<lbrakk>s' = s\\<lparr>ownT := W, pcW := A3\\<rparr>; T s = H s; case_1 s\\<rbrakk> \\<Longrightarrow> case_1 s'\\<close> apply presburger\n  apply (metis case_split_2 le_refl)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(case_tac \"hW s < tW s \\<and> Data s (numEnqs s) < tW s - hW s\", simp_all)\n  apply(intro conjI impI)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply (elim conjE disjE)\n  apply(subgoal_tac \"\\<not>case_1 s\") prefer 2\n  apply (metis case_split_4 less_eqE trans_less_add1)\n  apply meson\n  apply(subgoal_tac \"case_2 s'\")\n  apply blast apply simp\n  using  case_trans_A2_to_A4_3 [where s=s]\n  apply (meson case_split_2 not_less)\n  apply (metis case_trans_A2_to_A4_2)\n  apply (metis case_split_2)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(case_tac \"tW s < hW s\", simp_all)\n  apply(intro conjI impI)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply (metis case_split_2 case_trans_A2_to_A5_2)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(intro conjI impI)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply (elim conjE disjE)\n  apply (metis case_split_4 less_eqE linorder_neqE_nat trans_less_add1)\n  apply (metis case_split_2 case_trans_A2_to_A8_4 linear nat_less_le)\n  apply (metis case_trans_A2_to_A8_2)\n  apply (metis case_split_2)\n  by(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n\n\n\nlemma W_inv_A3_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = A3\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"    \nshows \"inv s'\"\n  using assms apply(simp add:inv_def pre_W_def cW_step_def pre_A3_inv_def)\n  apply(intro conjI impI)\n  apply(simp add:Q_lemmas Q_basic_lemmas) defer\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def) \n  apply(subgoal_tac \"case_1 s\") prefer 2 \n  apply (metis RingBuffer_BD_latest_2.case_split le_refl)\n  apply(subgoal_tac \"\\<not>case_2 s'\") prefer 2 \n  using case_trans_A3_to_write_2 [where s=s and s'=s'] \n  apply (simp add: assms(1) pre_A3_inv_def)\n  apply simp\n  using case_trans_A3_to_write_7 [where s=s]\n  by (simp add: assms(1) pre_A3_inv_def)\n\n\nlemma W_inv_A4_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = A4\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"    \nshows \"inv s'\"\n  using assms apply(simp add:inv_def pre_W_def cW_step_def)\n  apply(intro conjI impI)  apply(simp add:inv_def pre_W_def cW_step_def pre_A4_inv_def)\n  apply (simp add: less_diff_conv)  apply(simp add:inv_def pre_W_def cW_step_def pre_A4_inv_def)\n  apply(simp add:Q_lemmas Q_basic_lemmas) defer  apply(simp add:inv_def pre_W_def cW_step_def pre_A4_inv_def)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)  \n  apply (metis (no_types, lifting) F.distinct(19) add.commute add_lessD1 canonically_ordered_monoid_add_class.lessE less_diff_conv) \n  apply(case_tac \"T s\\<ge>tW s\")\n  apply(subgoal_tac \"case_2 s'\") prefer 2 \n  using case_trans_A4_to_write_7 [where s=s and s'=s'] \n  apply (simp add: assms(1) assms(2) pre_A4_inv_def)\n  apply meson \n  using case_trans_A4_to_write_9 [where s=s and s'=s'] \n  using assms(1) pre_A4_inv_def by auto\n\n\n\nlemma W_inv_A5_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = A5\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"    \nshows \"inv s'\"\n  using assms apply(simp add:inv_def pre_W_def cW_step_def pre_A5_inv_def)\n  apply(case_tac \"Data s (numEnqs s) \\<le> N - hW s\", simp_all) defer\n  apply(case_tac \"Data s (numEnqs s) < tW s\", simp_all) defer defer\n  apply(intro conjI impI) apply(simp add:Q_lemmas Q_basic_lemmas)\n  prefer 2 \n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def) defer\n  apply(intro conjI impI) apply(simp add:Q_lemmas Q_basic_lemmas)\n  prefer 2 \n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def) defer\n  apply(intro conjI impI) apply(simp add:Q_lemmas Q_basic_lemmas)\n  prefer 2 \n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def) defer\n  using case_trans_A5_to_A6_3 [where s=s and s'=s'] \n  apply (metis PCW.simps(187) assms(1) assms(2) assms(4) pre_W_def)\n  using case_trans_A5_to_A6_6 [where s=s and s'=s']\n  apply (simp add: assms(1) pre_A5_inv_def)\n  using case_trans_A5_to_A6_9 [where s=s and s'=s']\n  by (metis case_split_2 case_trans_A2_to_A8_2)\n\n\n\nlemma W_inv_A6_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = A6\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"    \nshows \"inv s'\"\n  using assms apply(simp add:inv_def pre_W_def cW_step_def pre_A6_inv_def)\n  apply(intro conjI impI)\n  apply (metis Nat.le_diff_conv2 add.commute)\n  apply(simp add:Q_lemmas Q_basic_lemmas) prefer 2\n   apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def) prefer 2 \n  using case_trans_A6_to_write_7 [where s=s and s'=s']\n  apply (metis (no_types, lifting) PCW.simps(188) assms(1) assms(2) assms(4) pre_W_def)\n  by (smt (z3) F.distinct(19) diff_add_inverse le_diff_iff le_neq_implies_less le_trans less_imp_add_positive less_or_eq_imp_le not_add_less1)\n\n\n\nlemma W_inv_A7_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = A7\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"    \nshows \"inv s'\"\n  using assms apply(simp add:inv_def pre_W_def cW_step_def pre_A7_inv_def)\n  apply(intro conjI impI)\n  apply(simp add:Q_lemmas Q_basic_lemmas) prefer 2\n   apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def) \n  using case_trans_A7_to_write_7 [where s=s and s'=s'] \n  by (metis (no_types, lifting) PCW.simps(189) assms(1) assms(2) assms(4) pre_W_def)\n  \n\n\n\n\nlemma W_inv_A8_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = A8\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"    \nshows \"inv s'\"\n  using assms apply(simp add:inv_def pre_W_def cW_step_def pre_A8_inv_def)\n  apply(intro conjI impI)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"N < Data s (numEnqs s)\", simp_all)\n  apply (metis leD)\n  apply (metis leD)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"case_1 s\") apply(simp) apply(simp add:case_1_def) \n  apply(simp add:case_2_def)\n  by(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n\n\n\n\n\nlemma W_inv_Enqueue_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = Enqueue\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"    \nshows \"inv s'\"\n  using assms apply(simp add:inv_def pre_W_def cW_step_def pre_enqueue_inv_def)\n  apply(intro conjI impI)\n  apply (metis Suc_diff_le length_0_conv)\n  defer\n  defer \n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(simp add:tempW_def)\n  apply(case_tac \"case_1 s\") apply simp apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:case_1_def) apply clarify apply(intro conjI impI)\n  apply (metis F.distinct(5) diff_is_0_eq' less_nat_zero_code linorder_neqE_nat nat_le_linear zero_less_diff)\n  apply (metis (mono_tags, hide_lams) F.distinct(5) F.distinct(9) le_antisym less_Suc_eq_le minus_nat.diff_0 not_less_eq plus_nat.add_0)\n  apply(subgoal_tac \"i<N \\<and> ownB s i=W\\<longrightarrow>offset s\\<le>i \\<and> i<offset s + Data s (numEnqs s)\") prefer 2\n  apply (metis nat_less_le)\n  apply(subgoal_tac \"i>N \\<and> ownB s i=W\\<longrightarrow>i>offset s + Data s (numEnqs s)\")\n  apply (metis (no_types, lifting) diff_is_0_eq le_eq_less_or_eq linorder_neqE_nat zero_less_diff)\n  apply(subgoal_tac \"end(tempW s)\\<le>N\", unfold tempW_def)[1] prefer 2\n  apply (metis end_simp fst_conv snd_conv) \n  apply (metis (no_types, lifting) less_trans_Suc nat_less_le nat_neq_iff not_less_eq_eq)\n  apply(subgoal_tac \"case_2 s\") apply simp apply(thin_tac \"\\<not>case_1 s\")[1]\n  prefer 2 apply blast apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:case_2_def) apply clarify \n  using Suc_diff_le apply presburger\n  defer defer\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply clarify\n  apply(intro conjI impI)\n  apply(rule_tac ?x = \"{i. offset s \\<le> i \\<and> i < offset s + Data s (numEnqs s)}\" in exI)\n  apply (intro conjI impI)\n  apply metis\n  apply(case_tac \"case_1 s\") apply(simp)\n  apply(simp add:case_1_def) apply clarify apply(intro conjI impI)\n  apply (metis F.distinct(5) diff_is_0_eq' less_nat_zero_code linorder_neqE_nat nat_le_linear zero_less_diff)\n  apply (metis (no_types, lifting) Suc_le_lessD fst_conv not_less_eq_eq snd_conv tempW_def)\n  apply(subgoal_tac \"case_2 s\") apply simp apply(thin_tac \"\\<not>case_1 s\")[1]\n  prefer 2 apply blast apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:case_2_def) apply clarify \n  apply (intro conjI impI)\n  apply (metis le_eq_less_or_eq nat_le_linear)\n  apply(subgoal_tac \"i\\<ge>H s\\<and>i<T s\\<longrightarrow>ownB s i=B\") prefer 2\n  apply metis\n  apply(subgoal_tac \"i\\<ge>T s\\<and>i<e\\<longrightarrow>ownB s i=R\") prefer 2\n  apply metis\n  apply(subgoal_tac \"i\\<ge>e\\<and>i<f\\<longrightarrow>ownB s i=Q\") prefer 2\n  apply metis\n  apply(subgoal_tac \"i\\<ge>f\\<and>i<N\\<longrightarrow>ownB s i=D\") prefer 2\n  apply metis\n  apply(subgoal_tac \"i\\<ge>H s\\<and>i<N\\<longrightarrow>ownB s i\\<noteq>W\") prefer 2 \n  apply (metis F.distinct(1) F.distinct(3) F.distinct(5) F.distinct(7) diff_is_0_eq neq0_conv zero_less_diff)\n  apply (metis (no_types, lifting) diff_is_0_eq gr0I zero_less_diff)\n  apply(clarsimp)\n  apply(intro iffI)\n  apply clarify apply simp\n  apply(case_tac \"(a, b) \\<in> set (q s)\") apply simp \n  apply (metis (no_types, lifting) mem_Collect_eq)\n  apply(subgoal_tac \"(i\\<le>N \\<and> ownB s i\\<noteq>Q)\\<longrightarrow>(\\<nexists>a b. ((a,b)\\<in>set(q s)\\<and> a\\<le>i \\<and> i<a+b))\")\n  prefer 2 \n  apply (metis fst_eqD snd_eqD tempW_def)\n  apply(subgoal_tac \"a = offset s \\<and> b = Data s (numEnqs s)\") prefer 2\n  apply meson\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply clarify apply simp\n  apply(subgoal_tac \"ownB s i=Q \\<and> i\\<le>N\\<longleftrightarrow>(\\<exists>x. (\\<exists>a b. x = {i. a \\<le> i \\<and> i < a + b} \\<and> (a, b) \\<in> set (q s)) \\<and> i \\<in> x)\")\n  prefer 2 \n  apply presburger\n  apply simp\n  apply metis\n  apply clarify\n\n\n  sorry\n\n\n\n\n\nlemma W_inv_idleW_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = idleW\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"    \nshows \"inv s'\"\n  using assms apply(simp add:inv_def pre_W_def cW_step_def pre_acquire_inv_def)\n  apply(intro conjI impI)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply (metis leD)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \"case_1 s\") apply(simp) apply(simp add:case_1_def) \n  apply(simp add:case_2_def)\n  apply(case_tac \"case_1 s\") apply(simp) apply(simp add:case_1_def) \n  apply(subgoal_tac \"case_2 (s\\<lparr>pcW := FinishedW\\<rparr>)\")\n  apply blast apply simp apply(thin_tac \"\\<not> case_1 s \") \n  apply(simp add:case_2_def)\n  prefer 2 \n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply clarify\n  apply(rule_tac ?x = \"a\" in exI)\n  apply(rule_tac ?x = \"b\" in exI)\n  apply(intro conjI impI) apply metis\n  apply(rule_tac ?x = \"H s\" in exI)\n  apply(intro conjI impI) \n  apply blast\n  apply(rule_tac ?x = \"T s\" in exI)\n  apply(intro conjI impI) \n  apply blast\n  apply(rule_tac ?x = \"e\" in exI)\n  apply(intro conjI impI) \n  apply blast\n  apply(rule_tac ?x = \"f\" in exI)\n  apply(intro conjI impI) \n  apply blast\n  apply blast\n  apply blast\n  apply blast\n  apply blast\n  apply blast\n  apply blast\n  apply blast\n  apply blast\n  apply blast\n  apply blast\n  apply blast\n  apply blast\n  apply blast\n  apply blast\n  apply blast \n  apply meson\n  apply metis\n  apply meson\n  apply meson\n  apply meson\n  apply meson\n  apply meson\n  apply meson\n  apply meson\n  apply meson\n  apply meson\n  apply meson\n  apply meson\n  apply meson\n  by meson\n\n\n\n\n\n\n\nlemma W_inv_OOM_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = OOM\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"    \nshows \"inv s'\"\n  using assms apply(simp add:inv_def pre_W_def cW_step_def pre_OOM_inv_def)\n  apply(intro conjI impI)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(case_tac \"case_1 s\") apply simp apply(simp add:case_1_def)\n  apply(simp add:case_2_def)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  by(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n\n\n\n\n\nlemma W_inv_FinishedW_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = FinishedW\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"    \nshows \"inv s'\"\n  using assms by(simp add:inv_def pre_W_def cW_step_def pre_OOM_inv_def)\n\n\n\n\nlemma W_inv_Write_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = Write\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"    \nshows \"inv s'\"\n  using assms apply simp\n  apply(subgoal_tac \"case_1 s \\<or> case_2 s\") prefer 2 using inv_def pre_W_def\n  apply blast\n  apply(subgoal_tac \"pre_write_inv s\") prefer 2 using inv_def pre_W_def assms\n  apply (metis PCW.simps(195))\n  apply(simp add:pre_W_def cW_step_def)\n  apply(simp add:inv_def)\n  apply(intro conjI impI) \n  apply (simp add: pre_write_inv_def) defer\n  apply (simp add: pre_write_inv_def) defer defer defer \n  apply(subgoal_tac \"case_1 s' \\<or> case_2 s'\")\n  apply meson using case_trans_Write_to_Enqueue_case_3 [where s=s and s'=s']\n  using assms(1) assms(2) apply blast\n  apply(simp add:Q_indices_def ran_indices_def Q_owns_bytes_def)\n  sorry\n\n\n\n\nlemma W_inv_BTS_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = BTS\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"    \nshows \"inv s'\"\n  using assms by(simp add:inv_def pre_W_def cW_step_def pre_OOM_inv_def)\n\n\n\n\nlemma local_pre_W_inv: \n  assumes \"con_assms s\"\n  and \"pcw = pcW s\"\n  and \"pre_W pcw s\"\n  and \"inv s\"\n  and \"cW_step pcw s s'\"\nshows \"inv s'\"\n  using assms apply(case_tac \"pcW s\") \n  using W_inv_A1_lemma [where s=s and s'=s'] apply blast\n  using W_inv_A2_lemma [where s=s and s'=s'] apply blast\n  using W_inv_A3_lemma [where s=s and s'=s'] apply blast\n  using W_inv_A4_lemma [where s=s and s'=s'] apply blast\n  using W_inv_A5_lemma [where s=s and s'=s'] apply blast\n  using W_inv_A6_lemma [where s=s and s'=s'] apply blast \n  using W_inv_A7_lemma [where s=s and s'=s'] apply blast\n  using W_inv_A8_lemma [where s=s and s'=s'] apply blast \n  using W_inv_Enqueue_lemma [where s=s and s'=s'] apply blast             (*hard- Queue*)\n  using W_inv_idleW_lemma [where s=s and s'=s'] apply blast \n  using W_inv_OOM_lemma [where s=s and s'=s'] apply blast    \n  using W_inv_FinishedW_lemma [where s=s and s'=s'] apply blast \n  using W_inv_Write_lemma [where s=s and s'=s'] apply blast               (*Queue*)\n  using W_inv_BTS_lemma [where s=s and s'=s'] by blast   \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n(*******************************LOCAL W_step shows preW*************************************)\n\n\nlemma W_local_A1_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = A1\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"\nshows \"pre_W (pcW s') s'\"\n  using assms apply simp\n  by(simp add:inv_def pre_W_def cW_step_def pre_A1_inv_def pre_A2_inv_def)\n\nlemma W_local_A2_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = A2\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"\nshows \"pre_W (pcW s') s'\"\n  using assms apply simp\n  apply(simp add:inv_def pre_W_def cW_step_def pre_A2_inv_def pre_A3_inv_def)\n  apply(case_tac \"tW s = hW s\") apply simp_all \n  apply(case_tac \"hW s < tW s \\<and> Data s (numEnqs s) < tW s - hW s\") \n  apply(simp_all add: pre_A4_inv_def)\n  apply metis\n  apply(case_tac \"tW s < hW s\", simp_all) \n  apply(simp add:pre_A5_inv_def) \n  apply(simp add:pre_A8_inv_def)\n  by metis\n\n\n\n\nlemma W_local_A3_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = A3\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"\nshows \"pre_W (pcW s') s'\"\n  using assms apply simp\n  apply(simp add:inv_def pre_W_def cW_step_def pre_A3_inv_def pre_write_inv_def)\n  by(simp add:tempW_lemmas tempW_basic_lemmas)\n\n\n\nlemma W_local_A4_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = A4\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"\nshows \"pre_W (pcW s') s'\"\n  using assms apply simp\n  apply(simp add:inv_def pre_W_def cW_step_def pre_A4_inv_def pre_write_inv_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(intro conjI impI)\n  apply (simp add: less_diff_conv)\n  apply(case_tac \"case_1 s\") apply(subgoal_tac \"\\<not>case_2 s\") apply simp \n  apply(thin_tac \"\\<not> case_2 s\")\n  apply(simp add:case_1_def)\n  apply (metis cancel_comm_monoid_add_class.diff_cancel le_eq_less_or_eq length_0_conv less_nat_zero_code)\n  apply (metis case_split_5)\n  apply(subgoal_tac \"case_2 s\") apply simp \n  apply(thin_tac \"\\<not>case_1 s\") \n  apply(simp add:case_2_def) \n  apply (metis (no_types, lifting) add_diff_cancel_left' cancel_comm_monoid_add_class.diff_cancel diff_is_0_eq diff_zero le_trans length_greater_0_conv nat_less_le)\n  apply (metis)\n  apply(simp add:Q_lemmas Q_basic_lemmas tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(case_tac \"case_1 s\") apply(subgoal_tac \"\\<not>case_2 s\") apply simp\n  apply(thin_tac \"\\<not> case_2 s\")\n  apply(simp add:case_1_def)\n  apply (metis (no_types, hide_lams) diff_is_0_eq' le_eq_less_or_eq length_pos_if_in_set nth_mem prod.exhaust_sel zero_less_diff)\n  apply (metis case_split_5)\n  apply(subgoal_tac \"case_2 s\") apply simp \n  apply(thin_tac \"\\<not>case_1 s\") \n  apply(simp add:case_2_def)\n  apply clarify \n  apply(subgoal_tac \"ownB s (H s) \\<noteq> Q\") prefer 2 \n  apply (metis F.distinct(19) le_refl)\n  apply(subgoal_tac \"\\<forall>i. (\\<exists>x. (\\<exists>a b. x = {i. a \\<le> i \\<and> i < a + b} \\<and> (a, b) \\<in> set (q s)) \\<and> i \\<in> x) = (i \\<le> N \\<and> ownB s i = Q)\") prefer 2\n  apply blast\n  apply(subgoal_tac \"i<length(q s) \\<longrightarrow> snd(q s!i) > 0\") prefer 2\n  apply (metis nth_mem prod.collapse)\n  apply(subgoal_tac \"hW s = end(last(q s))\") prefer 2 \n  apply (metis add.commute add_diff_inverse_nat diff_is_0_eq' end_simp le_eq_less_or_eq le_trans minus_nat.diff_0 nat_less_le)\n  apply (metis end_simp nth_mem prod.collapse)\n  apply metis\n  apply(simp add:Q_lemmas Q_basic_lemmas) (*doable*)\n  defer \n  apply(case_tac \"case_1 s\") apply(subgoal_tac \"\\<not>case_2 s\") apply simp \n  apply(thin_tac \"\\<not> case_2 s\")\n  apply(simp add:case_1_def)\n  apply(simp add:Q_indices_def Q_owns_bytes_def ran_indices_def)\n  apply (metis (no_types, lifting) add_leD1 cancel_comm_monoid_add_class.diff_cancel le_eq_less_or_eq le_zero_eq length_0_conv)\n  apply (metis case_split_5)\n  apply(subgoal_tac \"case_2 s\") apply simp \n  apply(thin_tac \"\\<not>case_1 s\") \n  apply(simp add:case_2_def)\n  apply(simp add:Q_indices_def Q_owns_bytes_def ran_indices_def)\n  apply(clarify)\n  apply(case_tac \"fst(hd(q s)) = 0\") \n  apply (metis add_is_0)\n  apply(subgoal_tac \"fst(hd(q s)) = e\") prefer 2\n  apply (metis (no_types, lifting) add_diff_cancel_right' add_lessD1 cancel_comm_monoid_add_class.diff_cancel le_neq_implies_less length_greater_0_conv not_add_less1 ordered_cancel_comm_monoid_diff_class.add_diff_inverse)\n  apply(subgoal_tac \"hW s<T s\") prefer 2\n  apply blast\n  apply(subgoal_tac \" hW s + Data s (numEnqs s) = hW s\") prefer 2\n  apply (metis add.commute diff_add less_diff_conv nat_less_le trans_less_add2)\n  apply(subgoal_tac \"T s \\<le> fst(hd(q s))\") prefer 2\n  apply meson\n  apply(subgoal_tac \"d> Data s (numEnqs s) + hW s \") prefer 2 \n  apply (metis add.commute less_add_same_cancel2)\n  apply(subgoal_tac \"d=e\") prefer 2 \n  apply (metis less_add_same_cancel1)\n  apply (metis not_add_less2)\n  apply blast\n  apply(clarify)\n  apply(intro conjI impI)\n  apply(case_tac \"case_1 s\") apply(subgoal_tac \"\\<not>case_2 s\") apply simp \n  apply(thin_tac \"\\<not> case_2 s\")\n  apply(simp add:case_1_def)\n  apply(simp add:Q_indices_def Q_owns_bytes_def ran_indices_def)\n  apply(subgoal_tac \"\\<forall>j. j<length(q s) \\<longrightarrow> hW s > fst(q s!j)\")\n  apply (metis Suc_lessD less_natE not_add_less1)\n  apply(subgoal_tac \"\\<forall> a b j. ((a,b)\\<in>set(q s) \\<and> a\\<le>j \\<and> j<a+b) \\<longrightarrow> ownB s (j) = Q\") prefer 2\n  apply (metis (no_types, lifting) mem_Collect_eq)\n  apply(clarify)\n  apply(subgoal_tac \"\\<forall>i.(ownB s i=Q \\<and> i\\<le>N) \\<longrightarrow> i<c\") prefer 2\n  apply (metis (no_types, lifting) F.distinct(19) F.distinct(23) le_eq_less_or_eq linorder_neqE_nat)\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s))\\<longrightarrow> ownB s (fst(q s!0)) = Q\") prefer 2\n  apply (metis cancel_comm_monoid_add_class.diff_cancel hd_conv_nth le_eq_less_or_eq less_nat_zero_code)\n  apply(subgoal_tac \"c\\<le>hW s\") prefer 2\n  apply blast\n  apply(subgoal_tac \"fst(q s!j) + snd(q s!j) \\<le>N\") prefer 2 \n  apply (metis nth_mem prod.collapse)\n  apply(subgoal_tac \"fst(q s!j) \\<le>N\") prefer 2 \n  apply (metis add_leD1)\n  apply (metis (no_types, lifting) le_eq_less_or_eq less_add_same_cancel1 nth_mem prod.collapse)\n  apply (metis case_split_5)\n  apply(simp add:Q_indices_def Q_owns_bytes_def ran_indices_def)\n  apply(case_tac \"case_1 s\") apply(subgoal_tac \"\\<not>case_2 s\") apply simp \n  apply (metis case_split_5)\n  apply(simp add:case_2_def)\n  apply(thin_tac \"\\<not> case_1 s\")\n  apply clarify\n  apply(case_tac \"H s \\<ge> T s\") \n  apply (metis le_imp_less_Suc less_or_eq_imp_le not_less_eq)\n  apply(subgoal_tac \"H s < T s \") prefer 2\n  apply metis\n  apply(thin_tac \"\\<not> T s \\<le> H s\")\n  apply(subgoal_tac \"\\<forall>i.(hW s \\<le>i \\<and> i<hW s + Data s (numEnqs s)) \\<longrightarrow> ownB s i = B\") prefer 2 \n  apply (metis (no_types, lifting) Suc_lessD add.commute less_diff_conv less_trans_Suc)\n  apply(case_tac \"e=f\") \n  apply(subgoal_tac \"\\<forall>i.(ownB s i = Q \\<and> i\\<le>N)\\<longrightarrow>i<b\") prefer 2\n  apply (metis (no_types, hide_lams) F.distinct(11) F.distinct(19) F.distinct(21) F.distinct(23) F.distinct(3) Suc_pred bot_nat_0.not_eq_extremum diff_Suc_Suc diff_diff_cancel diff_is_0_eq old.nat.inject zero_less_Suc zero_less_diff)\n  apply(subgoal_tac \"\\<forall>a b j.((a,b)\\<in>set(q s) \\<and> a\\<le>j \\<and> j<a+b)\\<longrightarrow>ownB s j = Q\") prefer 2 \n  apply (metis (no_types, lifting) mem_Collect_eq)\n  apply(subgoal_tac \"\\<forall>i. i<length(q s) \\<longrightarrow> (q s!i) \\<in> set(q s)\") prefer 2 \n  apply (metis nth_mem)\n  apply(subgoal_tac \"fst(q s!i)< fst(q s!i) + snd(q s!i)\") prefer 2 \n  apply (metis less_add_same_cancel1 prod.collapse) \n  apply(subgoal_tac \"\\<forall>a b. (a,b)\\<in>set(q s) \\<longrightarrow> ownB s (a) = Q\") prefer 2\n  apply (metis (no_types, hide_lams) Nat.add_0_right le_refl nat_add_left_cancel_less)\n  apply(subgoal_tac \"\\<forall>i. (i<length(q s)) \\<longrightarrow> (\\<exists>a b. ((a,b)\\<in>set(q s) \\<and> a=fst(q s!i) \\<and> b = snd(q s!i)))\") prefer 2\n  apply (metis prod.collapse)\n  apply(subgoal_tac \"\\<forall>i. i<length(q s) \\<longrightarrow> ownB s (fst(q s!i)) = Q\") prefer 2 \n  apply (metis (no_types, hide_lams))\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s) \\<and> fst(q s!i) < N)\\<longrightarrow> fst(q s!i)<b\") prefer 2 \n  apply (metis less_imp_le_nat)\n  apply(subgoal_tac \"fst(q s!i) + snd(q s!i)\\<le>N\") prefer 2 \n  apply (metis less_add_same_cancel1 prod.collapse)\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s))\\<longrightarrow> fst(q s!i)<b\") prefer 2 \n  apply (metis (no_types, lifting) add_leD1)\n  apply (metis (no_types, lifting) add_lessD1 le_imp_less_Suc less_imp_add_positive not_less_eq)\n  apply(case_tac \"fst(q s!i) < hW s\") \n  apply linarith\n  apply(subgoal_tac \"\\<forall>a b j.((a,b)\\<in>set(q s) \\<and> a\\<le>j \\<and> j<a+b)\\<longrightarrow>ownB s j = Q\") prefer 2 \n  apply (metis (no_types, lifting) mem_Collect_eq)\n  apply(subgoal_tac \"\\<forall>i. i<length(q s) \\<longrightarrow> (q s!i) \\<in> set(q s)\") prefer 2 \n  apply (metis nth_mem)\n  apply(subgoal_tac \"fst(q s!i)< fst(q s!i) + snd(q s!i)\") prefer 2 \n  apply (metis less_add_same_cancel1 prod.collapse) \n  apply(subgoal_tac \"\\<forall>a b. (a,b)\\<in>set(q s) \\<longrightarrow> ownB s (a) = Q\") prefer 2\n  apply (metis (no_types, hide_lams) Nat.add_0_right le_refl nat_add_left_cancel_less)\n  apply(subgoal_tac \"\\<forall>i. (i<length(q s)) \\<longrightarrow> (\\<exists>a b. ((a,b)\\<in>set(q s) \\<and> a=fst(q s!i) \\<and> b = snd(q s!i)))\") prefer 2\n  apply (metis prod.collapse)\n  apply(subgoal_tac \"\\<forall>i. i<length(q s) \\<longrightarrow> ownB s (fst(q s!i)) = Q\") prefer 2 \n  apply (metis (no_types, hide_lams))\n  apply(subgoal_tac \"fst(q s!i) + snd(q s!i)\\<le>N\") prefer 2 \n  apply (metis less_add_same_cancel1 prod.collapse)\n  apply(subgoal_tac \"fst(q s!i) \\<ge>e\") \n  apply (metis (no_types, lifting) F.distinct(19) add.commute less_diff_conv less_or_eq_imp_le linorder_neqE_nat)\n  apply (metis (no_types, hide_lams) F.distinct(11) F.distinct(19) bot_nat_0.not_eq_extremum diff_is_0_eq diff_self_eq_0 zero_less_diff)\n  apply(simp add:Q_indices_def Q_owns_bytes_def ran_indices_def)\n  apply(case_tac \"case_1 s\") apply simp apply(simp add:case_1_def)\n  apply clarify \n  apply(subgoal_tac \"\\<forall>a b j.((a,b)\\<in>set(q s) \\<and> a\\<le>j \\<and> j<a+b)\\<longrightarrow>ownB s j = Q\") prefer 2 \n  apply (metis (no_types, lifting) mem_Collect_eq)\n  apply(subgoal_tac \"\\<forall>i. i<length(q s) \\<longrightarrow> (q s!i) \\<in> set(q s)\") prefer 2 \n  apply (metis nth_mem)\n  apply(subgoal_tac \"fst(q s!i)< fst(q s!i) + snd(q s!i)\") prefer 2 \n  apply (metis less_add_same_cancel1 prod.collapse) \n  apply(subgoal_tac \"\\<forall>a b. (a,b)\\<in>set(q s) \\<longrightarrow> ownB s (a) = Q\") prefer 2\n  apply (metis (no_types, hide_lams) Nat.add_0_right le_refl nat_add_left_cancel_less)\n  apply(subgoal_tac \"\\<forall>i. (i<length(q s)) \\<longrightarrow> (\\<exists>a b. ((a,b)\\<in>set(q s) \\<and> a=fst(q s!i) \\<and> b = snd(q s!i)))\") prefer 2\n  apply (metis prod.collapse)\n  apply(subgoal_tac \"\\<forall>a b j.((a,b)\\<in>set(q s) \\<and> a\\<le>j \\<and> j\\<le>a+b-1)\\<longrightarrow>ownB s j = Q\") prefer 2 \n  apply (metis Suc_diff_1 add_gr_0 le_imp_less_Suc)\n  apply(subgoal_tac \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>a+b\\<le>hW s\")\n  apply (metis (no_types, lifting) less_or_eq_imp_le)\n  apply(subgoal_tac \"\\<forall>i.(ownB s i = Q \\<and> i\\<le>N) \\<longrightarrow> i<c\") prefer 2 \n  apply (metis (no_types, lifting) F.distinct(19) F.distinct(23) le_eq_less_or_eq linorder_neqE_nat)\n  apply(subgoal_tac \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>a+b\\<le>N\") prefer 2 \n  apply blast\n  apply(subgoal_tac \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>b>0\") prefer 2\n  apply blast\n  apply(subgoal_tac \"\\<forall>a b.((a,b)\\<in>set(q s) \\<and> a\\<le>a+b-1 \\<and> a+b-1\\<le>a+b-1)\\<longrightarrow>ownB s (a+b-1) = Q\") prefer 2 \n  apply (metis Suc_diff_1 add_gr_0 le_imp_less_Suc)\n  apply(subgoal_tac \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>a\\<le>a+b-1 \\<and> a+b-1\\<le>a+b-1\") prefer 2 \n  apply (metis Suc_diff_1 add_gr_0 le_eq_less_or_eq less_Suc_eq_le less_add_same_cancel1)\n  apply(subgoal_tac \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>ownB s (a+b-1) = Q\") prefer 2 \n  apply (metis (no_types, lifting))\n  apply(subgoal_tac \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>a+b-1 <c\") prefer 2 \n  apply (metis diff_le_self le_trans)\n  apply(subgoal_tac \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>a+b-1 <a+b\") prefer 2 \n  apply (metis Suc_pred' add_gr_0 lessI)\n  apply(subgoal_tac \"hW s\\<ge>c\") prefer 2\n  apply blast\n  apply(subgoal_tac \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>a+b-1 <hW s\") prefer 2\n  apply (metis eq_imp_le nat_less_le)\n  apply (metis (no_types, lifting) Suc_leI Suc_pred' add_gr_0)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply(clarify)\n  apply(case_tac \"e=f\") \n  apply(subgoal_tac \"\\<forall>i.(ownB s i = Q \\<and> i\\<le>N)\\<longrightarrow>i<b\") prefer 2\n  apply (metis (no_types, hide_lams) F.distinct(11) F.distinct(19) F.distinct(21) F.distinct(23) F.distinct(3) Suc_pred bot_nat_0.not_eq_extremum diff_Suc_Suc diff_diff_cancel diff_is_0_eq old.nat.inject zero_less_Suc zero_less_diff)\n  apply(subgoal_tac \"\\<forall>a b j.((a,b)\\<in>set(q s) \\<and> a\\<le>j \\<and> j<a+b)\\<longrightarrow>ownB s j = Q\") prefer 2 \n  apply (metis (no_types, lifting) mem_Collect_eq)\n  apply(subgoal_tac \"\\<forall>a b j.((a,b)\\<in>set(q s) \\<and> a\\<le>j \\<and> j\\<le>a+b-1)\\<longrightarrow>ownB s j = Q\") prefer 2 \n  apply (metis Suc_diff_1 add_gr_0 le_imp_less_Suc)\n  apply(subgoal_tac \"\\<forall>i. i<length(q s) \\<longrightarrow> (q s!i) \\<in> set(q s)\") prefer 2 \n  apply (metis nth_mem)\n  apply(subgoal_tac \"fst(q s!i)< fst(q s!i) + snd(q s!i)\") prefer 2 \n  apply (metis less_add_same_cancel1 prod.collapse) \n  apply(subgoal_tac \"\\<forall>a b. (a,b)\\<in>set(q s) \\<longrightarrow> b>0\") prefer 2 \n  apply blast\n  apply(subgoal_tac \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>a\\<le>a+b-1 \\<and> a+b-1\\<le>a+b\") prefer 2 \n  apply (metis Suc_diff_1 add_gr_0 diff_le_self less_Suc_eq_le less_add_same_cancel1)\n  apply(subgoal_tac \"\\<forall>a b. (a,b)\\<in>set(q s) \\<longrightarrow> ownB s (a+b-1) = Q\") prefer 2\n  apply (metis (no_types, hide_lams) Nat.add_0_right le_refl nat_add_left_cancel_less)\n  apply(subgoal_tac \"\\<forall>i. (i<length(q s)) \\<longrightarrow> (\\<exists>a b. ((a,b)\\<in>set(q s) \\<and> a=fst(q s!i) \\<and> b = snd(q s!i)))\") prefer 2\n  apply (metis prod.collapse)\n  apply(subgoal_tac \"\\<forall>i. i<length(q s) \\<longrightarrow> ownB s (fst(q s!i)+snd(q s!i)-1) = Q\") prefer 2 \n  apply (metis (no_types, lifting))\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s) \\<and> fst(q s!i)+snd(q s!i)-1 \\<le> N)\\<longrightarrow> fst(q s!i)+snd(q s!i)-1<b\") prefer 2 \n  apply (metis (no_types, lifting))\n  apply(subgoal_tac \"fst(q s!i) + snd(q s!i)\\<le>N\") prefer 2 \n  apply (metis less_add_same_cancel1 prod.collapse)\n  apply(subgoal_tac \"fst(q s!i) + snd(q s!i)-1\\<le>N\") prefer 2 \n  apply linarith\n  apply(subgoal_tac \"i<length(q s)\") prefer 2 \n  apply blast\n  apply(subgoal_tac \"fst(q s!i)+snd(q s!i)-1<b\") prefer 2 \n  apply (metis (no_types, lifting))\n  apply (metis Suc_leI diff_Suc_1 le_trans less_natE)\n  apply(case_tac \"fst(q s!i) > hW s\") \n  apply linarith\n  apply(subgoal_tac \"\\<forall>a b j.((a,b)\\<in>set(q s) \\<and> a\\<le>j \\<and> j<a+b)\\<longrightarrow>ownB s j = Q\") prefer 2 \n  apply (metis (no_types, lifting) mem_Collect_eq)\n  apply(subgoal_tac \"\\<forall>a b j.((a,b)\\<in>set(q s) \\<and> a\\<le>j \\<and> j\\<le>a+b-1)\\<longrightarrow>ownB s j = Q\") prefer 2 \n  apply (metis Suc_pred' add_gr_0 le_imp_less_Suc)\n  apply(subgoal_tac \"\\<forall>i. i<length(q s) \\<longrightarrow> (q s!i) \\<in> set(q s)\") prefer 2 \n  apply (metis nth_mem)\n  apply(subgoal_tac \"fst(q s!i)< fst(q s!i) + snd(q s!i)\") prefer 2 \n  apply (metis less_add_same_cancel1 prod.collapse) \n  apply(subgoal_tac \"\\<forall>a b. (a,b)\\<in>set(q s) \\<longrightarrow> ownB s (a) = Q\") prefer 2\n  apply (metis (no_types, hide_lams) Nat.add_0_right le_refl nat_add_left_cancel_less)\n  apply(subgoal_tac \"\\<forall>a b. (a,b)\\<in>set(q s) \\<longrightarrow> b>0\") prefer 2\n  apply meson\n  apply(subgoal_tac \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>a\\<le>a+b-1\\<and> a+b-1\\<le>a+b-1\") prefer 2  \n  apply (metis Suc_diff_1 add_gr_0 le_eq_less_or_eq less_Suc_eq_le less_add_same_cancel1)\n  apply(subgoal_tac \"\\<forall>a b j.((a,b)\\<in>set(q s))\\<longrightarrow>ownB s (a+b-1) = Q\") prefer 2 \n  apply (metis (no_types, lifting))\n  apply(subgoal_tac \"\\<forall>i. (i<length(q s)) \\<longrightarrow> (\\<exists>a b. ((a,b)\\<in>set(q s) \\<and> a=fst(q s!i) \\<and> b = snd(q s!i)))\") prefer 2\n  apply (metis prod.collapse)\n  apply(subgoal_tac \"\\<forall>i. i<length(q s) \\<longrightarrow> ownB s (fst(q s!i)+snd(q s!i)-1) = Q\") prefer 2 \n  apply (metis (no_types, hide_lams))\n  apply(subgoal_tac \"fst(q s!i) + snd(q s!i)\\<le>N\") prefer 2 \n  apply (metis less_add_same_cancel1 prod.collapse) \n  apply(subgoal_tac \"fst(q s!i) < hW s\") prefer 2 \n  apply blast\n  by (metis (no_types, hide_lams) F.distinct(19) diff_is_0_eq' less_nat_zero_code linorder_neqE_nat nat_le_linear zero_less_diff)\n\n\n\n    \n\n\nlemma W_local_A5_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = A5\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"\nshows \"pre_W (pcW s') s'\"\n  using assms apply simp\n  apply(simp add:inv_def pre_W_def cW_step_def pre_A5_inv_def pre_write_inv_def)\n  apply(case_tac \"Data s (numEnqs s) \\<le> N - hW s\", simp_all)\n  apply(simp_all add: pre_A6_inv_def)\n  apply(case_tac \"Data s (numEnqs s) < tW s\", simp_all)\n  apply(simp_all add: pre_A7_inv_def)  \n  by(simp_all add: pre_A8_inv_def)\n\n\nlemma W_local_A6_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = A6\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"\nshows \"pre_W (pcW s') s'\"\n  using assms apply simp\n  apply(simp add:cW_step_def pre_W_def)\n  apply(simp add:inv_def pre_A6_inv_def)\n  apply(subgoal_tac \"H s\\<ge>T s\") prefer 2 \n  apply meson apply(subgoal_tac \"\\<not>case_2 s\") prefer 2\n  apply (metis case_split_2)\n  apply(subgoal_tac \"case_1 s\") prefer 2\n  apply blast\n  apply(thin_tac \"\\<not>case_2 s\") \n  apply(simp add:pre_write_inv_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(intro conjI impI)\n  apply (metis Nat.le_diff_conv2 add.commute)\n  apply(simp add:case_1_def)\n  apply (metis cancel_comm_monoid_add_class.diff_cancel le_eq_less_or_eq le_zero_eq length_0_conv)\n  apply (metis (no_types, hide_lams) F.distinct(19) Q_owns_bytes_def diff_self_eq_0 le_eq_less_or_eq less_nat_zero_code ran_indices_lem5)\n  apply(simp add:case_1_def)\n  defer\n  apply(simp add:case_1_def)\n  apply (metis (no_types, lifting) cancel_comm_monoid_add_class.diff_cancel le_eq_less_or_eq le_zero_eq length_0_conv trans_le_add1)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:Q_indices_def Q_owns_bytes_def ran_indices_def)\n  apply(subgoal_tac \"hW s = H s\") prefer 2 \n  apply presburger\n  apply(clarify)\n  apply(intro conjI impI)\n  apply(subgoal_tac \"\\<forall>i.(ownB s i = Q \\<and> i\\<le>N)\\<longrightarrow>i<c\") prefer 2 \n  apply (metis (no_types, lifting) F.distinct(19) F.distinct(23) le_eq_less_or_eq linorder_neqE_nat)\n  apply(subgoal_tac \"\\<forall>a b j.((a,b)\\<in>set(q s)\\<and>a \\<le> j \\<and> j<a+b ) \\<longrightarrow> ownB s j = Q\") prefer 2\n  apply (metis (no_types, lifting) mem_Collect_eq)\n  apply(subgoal_tac \"\\<forall>a b.(a,b)\\<in>set(q s) \\<longrightarrow> ownB s (a) = Q\") prefer 2 \n  apply (metis (no_types, hide_lams) Nat.add_0_right le_refl nat_add_left_cancel_less)\n  apply(subgoal_tac \"\\<forall>a b.(a,b)\\<in>set(q s) \\<longrightarrow> a<N\") prefer 2 \n  apply (metis F.distinct(23) add_leD1 nat_less_le)\n  apply(subgoal_tac \"\\<forall>a b.(a,b)\\<in>set(q s) \\<longrightarrow> a<hW s\")\n  apply (metis (no_types, lifting) le_eq_less_or_eq nth_mem prod.collapse)\n  apply (metis le_neq_implies_less less_or_eq_imp_le)\n  apply(subgoal_tac \"\\<forall>i.(ownB s i = Q \\<and> i\\<le>N)\\<longrightarrow>i<c\") prefer 2 \n  apply (metis (no_types, lifting) F.distinct(19) F.distinct(23) le_eq_less_or_eq linorder_neqE_nat)\n  apply(subgoal_tac \"\\<forall>a b j.((a,b)\\<in>set(q s)\\<and>a \\<le> j \\<and> j<a+b ) \\<longrightarrow> ownB s j = Q\") prefer 2\n  apply (metis (no_types, lifting) mem_Collect_eq)\n  apply(subgoal_tac \"\\<forall>a b.(a,b)\\<in>set(q s)\\<longrightarrow>a \\<le> a+b-1 \\<and> a+b-1<a+b\") prefer 2 \n  apply (metis Suc_diff_1 add_gr_0 diff_less less_Suc_eq_le less_add_same_cancel1 less_one)\n  apply(subgoal_tac \"\\<forall>a b.(a,b)\\<in>set(q s) \\<longrightarrow> ownB s (a+b-1) = Q\") prefer 2\n  apply (metis (no_types, lifting))\n  apply(subgoal_tac \"\\<exists>a b.((a,b)\\<in>set(q s) \\<and> a=fst(q s!i) \\<and> b=Data s (numDeqs s + i))\") prefer 2\n  apply (metis nth_mem prod.collapse)\n  by (metis (no_types, hide_lams) diff_is_0_eq' linorder_neqE_nat nat_le_linear zero_less_diff)\n\n\n\n\nlemma W_local_A7_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = A7\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"\nshows \"pre_W (pcW s') s'\"\n  using assms apply simp\n  apply(simp add:cW_step_def pre_W_def)\n  apply(simp add:inv_def pre_A7_inv_def)\n  apply(subgoal_tac \"H s\\<ge>T s\") prefer 2 \n  apply meson apply(subgoal_tac \"\\<not>case_2 s\") prefer 2\n  apply (metis case_split_2)\n  apply(subgoal_tac \"case_1 s\") prefer 2\n  apply blast\n  apply(thin_tac \"\\<not>case_2 s\") \n  apply(simp add:pre_write_inv_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(intro conjI impI)\n  apply (metis (no_types, hide_lams) F.distinct(19) Q_owns_bytes_def bot_nat_0.not_eq_extremum less_nat_zero_code ran_indices_lem5)\n  apply(simp add:case_1_def) \n  defer\n  apply(simp add:case_1_def)\n  apply (metis F.distinct(19) cancel_comm_monoid_add_class.diff_cancel diff_is_0_eq le_neq_implies_less le_zero_eq length_0_conv)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:Q_indices_def Q_owns_bytes_def ran_indices_def)\n  apply(subgoal_tac \"hW s = H s\") prefer 2 \n  apply presburger\n  apply(clarify)\n  apply(subgoal_tac \"\\<forall>i.(ownB s i = Q \\<and> i\\<le>N)\\<longrightarrow>i\\<ge>b\") prefer 2 \n  apply (metis (no_types, hide_lams) F.distinct(11) F.distinct(19) diff_is_0_eq' linorder_neqE_nat nat_le_linear zero_less_diff)\n  apply(subgoal_tac \"\\<forall>a b j.((a,b)\\<in>set(q s)\\<and>a \\<le> j \\<and> j<a+b ) \\<longrightarrow> ownB s j = Q\") prefer 2\n  apply (metis (no_types, lifting) mem_Collect_eq)\n  apply(subgoal_tac \"\\<forall>a b.(a,b)\\<in>set(q s) \\<longrightarrow> ownB s (a) = Q\") prefer 2 \n  apply (metis (no_types, hide_lams) Nat.add_0_right le_refl nat_add_left_cancel_less)\n  apply(subgoal_tac \"\\<forall>a b.(a,b)\\<in>set(q s) \\<longrightarrow> a<N\") prefer 2 \n  apply (metis F.distinct(23) add_leD1 nat_less_le)\n  apply(subgoal_tac \"\\<forall>i.(i\\<le>Data s (numEnqs s))\\<longrightarrow>ownB s i = B\") prefer 2 \n  apply (metis add_lessD1 nat_le_iff_add)\n  apply(subgoal_tac \"\\<forall>a b.(a,b)\\<in>set(q s) \\<longrightarrow> a>Data s (numEnqs s)\") prefer 2\n  apply (metis F.distinct(19) Suc_le_lessD not_less_eq_eq)\n  by (metis nth_mem prod.collapse)\n   \n   \n\n\n\nlemma W_local_A8_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = A8\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"\nshows \"pre_W (pcW s') s'\"\n  using assms apply simp\n  apply(simp add:cW_step_def pre_W_def)\n  apply(simp add:inv_def pre_A8_inv_def)\n  apply(case_tac \"N < Data s (numEnqs s)\") \n  apply (metis leD) apply(intro conjI impI) \n  apply linarith apply(simp add:pre_OOM_inv_def) apply(intro conjI impI)\n  defer \n  apply(case_tac \"case_1 s\") apply simp  apply(simp add:case_1_def)\n  apply metis\n  apply meson apply(case_tac \"case_1 s\") apply simp  apply(simp add:case_1_def)\n  apply metis\n  apply(simp add:case_2_def)\n  by (metis le_antisym less_or_eq_imp_le)\n\n\n\n\n\nlemma W_local_Enqueue_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = Enqueue\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"\nshows \"pre_W (pcW s') s'\"\n  using assms apply simp\n  apply(simp add:cW_step_def pre_W_def)\n  apply(simp add:inv_def pre_enqueue_inv_def)\n  apply(intro conjI impI) \n  apply(simp add:pre_acquire_inv_def) apply(intro conjI impI)\n  apply(case_tac \"case_1 s\") apply(simp) apply(simp add:case_1_def) \n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply (metis F.distinct(5) eq_imp_le less_add_same_cancel1)\n  apply(subgoal_tac \"case_2 s\") prefer 2\n  apply blast apply(thin_tac \"\\<not>case_1 s\") apply(simp add:case_2_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas) \n  apply clarify\n  apply(intro conjI impI)\n  apply(case_tac \"case_1 s\") apply(simp) apply(simp add:case_1_def) apply(subgoal_tac \"case_2 s\") prefer 2\n  apply blast apply(simp) apply(thin_tac \"\\<not>case_1 s\") apply(simp add:case_2_def)\n  apply(case_tac \"case_1 s\") apply(simp) apply(simp add:case_1_def) apply(subgoal_tac \"case_2 s\") prefer 2\n  apply blast apply(simp) apply(thin_tac \"\\<not>case_1 s\") apply(simp add:case_2_def)\n  apply(case_tac \"case_1 s\") apply(simp) apply(simp add:case_1_def)\n  apply (metis add_cancel_left_left less_imp_le_nat old.prod.inject prod.collapse tempW_def)\n  apply(subgoal_tac \"case_2 s\") prefer 2\n  apply blast apply(simp) apply(thin_tac \"\\<not>case_1 s\") apply(simp add:case_2_def)\n  apply(simp add:pre_acquire_inv_def)\n  apply(intro conjI impI) \n  apply(case_tac \"case_1 s\") apply(simp) apply(simp add:case_1_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply (metis F.distinct(5) le_eq_less_or_eq less_add_same_cancel1)\n  apply(subgoal_tac \"case_2 s\") prefer 2\n  apply blast apply(simp) apply(thin_tac \"\\<not>case_1 s\") apply(simp add:case_2_def)\n  apply (metis F.distinct(5) le_eq_less_or_eq less_add_same_cancel1)\n  apply(case_tac \"case_1 s\") apply(simp) apply(simp add:case_1_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply (metis F.distinct(5) le_eq_less_or_eq less_add_same_cancel1)\n  apply(subgoal_tac \"case_2 s\") prefer 2\n  apply blast apply(simp) apply(thin_tac \"\\<not>case_1 s\") apply(simp add:case_2_def)\n  apply (metis F.distinct(5) le_eq_less_or_eq less_add_same_cancel1)\n  apply(case_tac \"case_1 s\") apply(simp) apply(simp add:case_1_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply (metis F.distinct(5) le_eq_less_or_eq less_add_same_cancel1)\n  apply(subgoal_tac \"case_2 s\") prefer 2\n  apply blast apply(simp) apply(thin_tac \"\\<not>case_1 s\") apply(simp add:case_2_def)\n  by (metis Suc_diff_Suc Zero_not_Suc diff_is_0_eq' less_or_eq_imp_le)\n\n\n\nlemma W_local_idleW_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = idleW\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"\nshows \"pre_W (pcW s') s'\"\n  using assms apply simp\n  apply(simp add:cW_step_def pre_W_def)\n  apply(simp add:inv_def pre_acquire_inv_def) \n  apply(case_tac \" numEnqs s < n\", simp_all)\n  apply(simp add: pre_A1_inv_def) \n  apply blast\n  by(simp add: pre_finished_inv_def) \n\n\n\nlemma W_local_OOM_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = OOM\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"\nshows \"pre_W (pcW s') s'\"\n  using assms apply simp\n  apply(simp add:cW_step_def pre_W_def)\n  apply(simp add:inv_def pre_OOM_inv_def)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(simp add:inv_def pre_acquire_inv_def)\n  apply(case_tac \"case_1 s\") apply(simp ) apply(simp add:case_1_def)\n  apply(intro conjI impI) \n  apply (metis eq_imp_le less_imp_le_nat linorder_neqE_nat)\n  apply (metis le_neq_implies_less le_refl)\n  apply (metis diff_self_eq_0 le_neq_implies_less le_refl le_zero_eq length_0_conv)\n  apply (metis diff_self_eq_0 le_antisym le_refl nat_less_le zero_less_diff)\n  apply metis\n  apply metis\n  apply(simp add:case_2_def)\n  apply(intro conjI impI) \n  apply (metis)\n  apply (metis)\n  apply (metis)\n  apply (metis)\n  apply metis \n  apply (metis le_antisym nat_less_le)\n  apply(simp add:pre_OOM_inv_def)\n  by blast\n\n\n\nlemma W_local_FinishedW_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = FinishedW\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"\nshows \"pre_W (pcW s') s'\"\n  using assms apply simp\n  by(simp add:cW_step_def pre_W_def)\n\n\n\n\nlemma W_local_Write_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = Write\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"\nshows \"pre_W (pcW s') s'\"\n  using assms apply simp\n  apply(simp add:pre_W_def cW_step_def)\n  apply(simp add:inv_def pre_write_inv_def)\n  apply(simp add:pre_enqueue_inv_def)\n  apply(intro conjI impI)\n  apply clarify\n  apply(case_tac \"case_1 s\") apply(simp) apply(simp add:case_1_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(subgoal_tac \"case_2 s\") prefer 2\n  apply blast apply(simp) apply(thin_tac \"\\<not>case_1 s\") apply(simp add:case_2_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(case_tac \"case_1 s\") apply(simp) apply(simp add:case_1_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas) apply clarify\n  apply(intro conjI impI)\n  apply(subgoal_tac \"i<T s\\<longrightarrow>ownB s i=B\") prefer 2\n  apply metis\n  apply(subgoal_tac \"T s\\<le>i \\<and> i<b\\<longrightarrow>ownB s i = R\") prefer 2 \n  apply metis\n  apply(subgoal_tac \"b\\<le>i \\<and> i<c\\<longrightarrow>ownB s i = Q\") prefer 2 \n  apply metis\n  apply (metis (mono_tags, lifting) F.distinct(1) F.distinct(3) F.distinct(5) Suc_le_lessD le_eq_less_or_eq not_less_eq_eq trans_less_add1)\n  apply(subgoal_tac \"end(tempW s)\\<le>i \\<and> i<N\\<longrightarrow> ownB s i = B\") prefer 2\n  apply metis\n  apply (metis F.distinct(5) F.distinct(9) le_neq_implies_less)\n  apply(subgoal_tac \"case_2 s\") prefer 2\n  apply blast apply(simp) apply(thin_tac \"\\<not>case_1 s\") apply(simp add:case_2_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(clarify)\n  apply(intro conjI impI) \n  apply (metis F.distinct(1) F.distinct(3) eq_imp_le linorder_neqE_nat nat_less_le trans_less_add1)\n  apply (metis F.distinct(1) F.distinct(3) F.distinct(5) F.distinct(7) F.distinct(9) le_neq_implies_less less_or_eq_imp_le linorder_neqE_nat)\n  apply(case_tac \"case_1 s\") apply(simp) apply(simp add:case_1_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas) \n  apply(subgoal_tac \"case_2 s\") prefer 2\n  apply blast apply(simp) apply(thin_tac \"\\<not>case_1 s\") apply(simp add:case_2_def) \n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(case_tac \"case_1 s\") apply(simp add:case_1_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas) \n  apply(subgoal_tac \"case_2 s\") prefer 2 \n  apply blast apply(simp) apply(thin_tac \"\\<not>case_1 s\") apply(simp add:case_2_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(case_tac \"case_1 s\") apply(simp add:case_1_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas) \n  apply(subgoal_tac \"case_2 s\") prefer 2 \n  apply blast apply(simp) apply(thin_tac \"\\<not>case_1 s\") apply(simp add:case_2_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(case_tac \"case_1 s\") apply(simp add:case_1_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas) \n  apply (metis bot_nat_0.extremum_unique diff_is_0_eq le_trans length_0_conv)\n  apply(subgoal_tac \"case_2 s\") prefer 2 \n  apply blast apply(simp) apply(thin_tac \"\\<not>case_1 s\") apply(simp add:case_2_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  by(simp add:tempW_lemmas tempW_basic_lemmas)\n\n\n\n\n\nlemma W_local_BTS_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcW s = BTS\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"\nshows \"pre_W (pcW s') s'\"\n  using assms apply simp\n  by(simp add:cW_step_def pre_W_def)\n\n\n\nlemma local_pre_W_pre: \n  assumes \"con_assms s\"\n  and \"pcw = pcW s\"\n  and \"pre_W pcw s\"\n  and \"inv s\"\n  and \"cW_step pcw s s'\"\nshows \"pre_W (pcW s') s'\"\n  using assms apply(case_tac \"pcW s\") \n  using W_local_A1_lemma [where s=s and s'=s'] apply blast \n  using W_local_A2_lemma [where s=s and s'=s'] apply blast \n  using W_local_A3_lemma [where s=s and s'=s'] apply blast  \n  using W_local_A4_lemma [where s=s and s'=s'] apply blast   \n  using W_local_A5_lemma [where s=s and s'=s'] apply blast  \n  using W_local_A6_lemma [where s=s and s'=s'] apply blast    \n  using W_local_A7_lemma [where s=s and s'=s'] apply blast     \n  using W_local_A8_lemma [where s=s and s'=s'] apply blast       \n  using W_local_Enqueue_lemma [where s=s and s'=s'] apply blast  \n  using W_local_idleW_lemma [where s=s and s'=s'] apply blast    \n  using W_local_OOM_lemma [where s=s and s'=s'] apply blast         \n  using W_local_FinishedW_lemma [where s=s and s'=s'] apply blast   \n  using W_local_Write_lemma [where s=s and s'=s'] apply blast   \n  using W_local_BTS_lemma [where s=s and s'=s'] by blast       \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n(**********************Supporting lemmas for R trans*********************************)\nlemma R_idle_to_nidle_lemma_case_1_1:\n  \"case_1 s\\<Longrightarrow>con_assms s \\<Longrightarrow> pcR s = idleR\\<Longrightarrow>pre_R (pcR s) s\n  \\<Longrightarrow>s'=(s\\<lparr>ownB := \\<lambda>i. if fst (hd (q s)) \\<le> i \\<and> i < fst (hd (q s)) + snd (hd (q s)) then R else ownB s i,\n          numDeqs := Suc (numDeqs s), ownT := R, tempR := hd (q s), pcR := Read, q := tl (q s)\\<rparr>)\n\\<Longrightarrow>inv s\n\\<Longrightarrow>i<fst(hd(q s))\\<longrightarrow>ownB s i=ownB s' i\"\n  by(simp add:case_1_def) \n\n\nlemma R_idle_to_nidle_lemma_case_1_2:\n  \"case_1 s\\<Longrightarrow>con_assms s \\<Longrightarrow> pcR s = idleR\\<Longrightarrow>pre_R (pcR s) s\n  \\<Longrightarrow>s'=(s\\<lparr>ownB := \\<lambda>i. if fst (hd (q s)) \\<le> i \\<and> i < fst (hd (q s)) + snd (hd (q s)) then R else ownB s i,\n          numDeqs := Suc (numDeqs s), ownT := R, tempR := hd (q s), pcR := Read, q := tl (q s)\\<rparr>)\n\\<Longrightarrow>inv s\n\\<Longrightarrow>i>end(hd(q s))\\<longrightarrow>ownB s i=ownB s' i\"\n  by(simp add:case_1_def) \n\n\n\nlemma R_idle_to_nidle_lemma_case_1_3:\n  \"case_1 s\\<Longrightarrow>con_assms s \\<Longrightarrow> pcR s = idleR\\<Longrightarrow>pre_R (pcR s) s\n  \\<Longrightarrow>s'=(s\\<lparr>ownB := \\<lambda>i. if fst (hd (q s)) \\<le> i \\<and> i < fst (hd (q s)) + snd (hd (q s)) then R else ownB s i,\n          numDeqs := Suc (numDeqs s), ownT := R, tempR := hd (q s), pcR := Read, q := tl (q s)\\<rparr>)\n\\<Longrightarrow>inv s\n\\<Longrightarrow>fst(hd(q s))\\<le>i \\<and> i<end(hd(q s))\\<longrightarrow>R=ownB s' i\"\n  by(simp add:case_1_def) \n\n\n\nlemma R_idle_to_nidle_lemma_case_1_4:\n  \"case_1 s\\<Longrightarrow>con_assms s \\<Longrightarrow> pcR s = idleR\\<Longrightarrow>pre_R (pcR s) s\n  \\<Longrightarrow>s'=(s\\<lparr>ownB := \\<lambda>i. if fst (hd (q s)) \\<le> i \\<and> i < fst (hd (q s)) + snd (hd (q s)) then R else ownB s i,\n          numDeqs := Suc (numDeqs s), ownT := R, tempR := hd (q s), pcR := Read, q := tl (q s)\\<rparr>)\n\\<Longrightarrow>inv s\n\\<Longrightarrow>T s=T s'\\<and>H s=H s'\\<and>offset s=offset s'\\<and>ownT s'=R\"\n  by(simp add:case_1_def) \n\n\nlemma sum_of_things:\n  \"q s!0 = (2,3) \\<Longrightarrow> (length(q s) = 1)\\<longrightarrow>\\<Sum>{j. j=(snd(q s!0))} = 3\"\n  by simp \n\nlemma sum_of_things_2:\n  \"q s=[(0,1)] \\<Longrightarrow> length(q s) = 1\"\n  by simp\n\n\nlemma sum_of_things_3:\n  \" length(q s)>0 \\<Longrightarrow> \\<forall>i. i<length(q s) \\<longrightarrow> snd(q s!i) =1\\<Longrightarrow> (\\<Sum>i::nat=0..length(q s)-1. 1) = length(q s)\"\n  by auto \n\nlemma sum_of_things_4:\n  \" length(q s)>1 \\<Longrightarrow> \\<forall>i. i<length(q s) \\<longrightarrow> snd(q s!i) =1\\<Longrightarrow> (\\<Sum>i::nat=0..(length(q s)-1). snd(q s!i)) = length(q s)\"\n  by auto\n\nlemma sum_of_things_5:\n  \"n>0\\<Longrightarrow> (\\<Sum>i::nat=0..n. k) = (\\<Sum>i::nat=1..n. k) + k \"\nproof (induct n)\n  show \"0 = n \\<Longrightarrow>\n    0 < n \\<Longrightarrow>\n    (\\<Sum>i = 0..n. k) = (\\<Sum>i = 1..n. k) + k\" by simp\nnext show \"\\<And>x. (x = n \\<Longrightarrow>\n          0 < n \\<Longrightarrow>\n          (\\<Sum>i = 0..n. k) =\n          (\\<Sum>i = 1..n. k) + k) \\<Longrightarrow>\n         Suc x = n \\<Longrightarrow>\n         0 < n \\<Longrightarrow>\n         (\\<Sum>i = 0..n. k) =\n         (\\<Sum>i = 1..n. k) + k\" \n    by (metis add.commute add_diff_cancel_left' le_add1 plus_1_eq_Suc sum.atLeast0_atMost_Suc_shift sum.atLeastAtMost_shift_0)\nqed\n\n\n\nlemma sum_of_things_6:\n  \"length(q s) =n+2\\<Longrightarrow> (\\<Sum>i::nat=0..(length(q s)-1). 1) = (\\<Sum>i::nat=1..(length(q s)-1). 1) + 1 \"\n  apply auto\nproof (induct n)\n  case 0\n  then show ?case  \n    by simp\nnext\n  case (Suc x)\n  then show ?case \n    by (metis add.commute add.right_neutral nat.distinct(1) not_gr_zero plus_1_eq_Suc sum_of_things_5)\nqed\n\n\nlemma sum_of_things_7:\n  \"length(q s) =n+2\\<Longrightarrow> \\<forall>i. (i<length(q s)) \\<longrightarrow> snd(q s!i) =1\\<Longrightarrow>\n (\\<Sum>i::nat=0..(length(q s)-1). snd(q s!i)) = (\\<Sum>i::nat=1..(length(q s)-1). snd(q s!i)) + snd(q s!0) \"\n  by auto\n\n\nlemma sum_of_things_8:\n  \"length(q s) =n+2\\<Longrightarrow>\n (\\<Sum>i::nat=0..(length(q s)-1). snd(q s!i)) = (\\<Sum>i::nat=1..(length(q s)-1). snd(q s!i)) + snd(q s!0) \"\n  apply auto\nproof (induct n)\n  case 0\n  then show ?case \n    by auto\nnext \n  case (Suc x)\n  then show ?case\n    by (simp add: sum.atLeast_Suc_atMost)\nqed\n\n\nlemma sum_of_things_9:\n  \" length(q s)=n+2 \\<Longrightarrow> \\<forall>i. (i<length(q s) \\<and> i>0) \\<longrightarrow> snd(q s!i) =1\\<Longrightarrow> \n(\\<Sum>i::nat=0..(length(q s)-1). snd(q s!i)) = (\\<Sum>i::nat=1..(length(q s)-1). snd(q s!i)) + snd(q s!0) \"\n  apply auto \nproof (induct n) case 0 then show ?case   by auto\nnext  case (Suc x) then show ?case  by (simp add: sum.atLeast_Suc_atMost)\nqed  \n\n\nlemma sum_of_things_10:\n  \" length(q s)\\<ge>2 \\<Longrightarrow> \\<forall>i. (i<length(q s) \\<and> i>0) \\<longrightarrow> snd(q s!i) =1\\<Longrightarrow> \n(\\<Sum>i::nat=0..(length(q s)-1). snd(q s!i)) = (\\<Sum>i::nat=1..(length(q s)-1). snd(q s!i)) + snd(q s!0) \"\n  apply auto\n  by (metis add.commute sum.atLeast_Suc_atMost zero_le)\n\nlemma sum_of_things_11:\n  \" length(q s) = n+2 \\<Longrightarrow> \\<forall>i. (i<length(q s) \\<and> i>0) \\<longrightarrow> snd(q s!i) =1\\<Longrightarrow> \n(\\<Sum>i::nat=0..(length(q s)-1). snd(q s!i)) = length(q s)-1 + snd(q s!0) \"\n  apply auto \nproof (induct n) case 0 then show ?case   by auto\nnext  case (Suc x) then show ?case by (simp add: sum.atLeast_Suc_atMost)\nqed  \n\n\nlemma sum_of_things_12:\n  \" length(q s) = n+2 \\<Longrightarrow> \\<forall>i. (i<length(q s) \\<and> i>0) \\<longrightarrow> snd(q s!i) =1\\<Longrightarrow> \n(\\<Sum>i::nat=1..(length(q s)-1). snd(q s!i)) = length(q s)-1  \"\n  by auto \n\nlemma sum_of_things_13:\n  \" \\<forall>n.(n\\<ge>0) \\<longrightarrow>length(q s) = n+2 \\<Longrightarrow> \\<forall>i. (i<length(q s) \\<and> i>0) \\<longrightarrow> snd(q s!i) =1\\<Longrightarrow> \n(\\<Sum>i::nat=1..(length(q s)-1). snd(q s!i)) = length(q s)-1  \"\n  using sum_of_things_12 [where s=s] \n  by blast\n\nlemma sum_of_things_14:\n  \" \\<forall>k.(k\\<ge>2)\\<longrightarrow>length(q s) = k \\<Longrightarrow> \\<forall>i. (i<length(q s) \\<and> i>0) \\<longrightarrow> snd(q s!i) =1\\<Longrightarrow> \n(\\<Sum>i::nat=1..(length(q s)-1). snd(q s!i)) = length(q s)-1  \"\n  using sum_of_things_13 [where s=s]\n  using le_add2 by blast\n\n\n\n\n\n\nlemma R_idle_to_nidle_lemma_case_1_5_preliminary:\n  \"case_1 s\\<Longrightarrow>con_assms s \\<Longrightarrow> pcR s = idleR\\<Longrightarrow>pre_R (pcR s) s\n  \\<Longrightarrow>inv s \\<Longrightarrow>q s\\<noteq>[] \\<Longrightarrow> tl(q s)\\<noteq>[]\n\\<Longrightarrow>length (q s) - Suc 0 \\<le> end(last(q s)) - end(hd (q s))\"\n  apply(simp add:inv_def Q_lemmas Q_basic_lemmas)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(simp add:pre_R_def pre_dequeue_inv_def)\n  apply(simp add:case_1_def)\n  apply clarify\n  apply(subgoal_tac  \"i<length(q s) \\<and> j<length(q s) \\<and> fst(q s!j)>fst(q s!i)\\<longrightarrow> fst(q s!j)\\<ge>end(q s!i)\") prefer 2 \n  apply (metis (no_types, lifting) end_simp nth_mem prod.collapse)\n  apply(subgoal_tac \"\\<nexists>i.(ownB s i = Q \\<and> i<b)\") prefer 2 \n  apply (metis F.distinct(19) le_neq_implies_less)\n  apply(subgoal_tac \"\\<forall>a b j. ((a,b)\\<in>set(q s) \\<and> j\\<ge>a \\<and> j<a+b) \\<longrightarrow> ownB s (j) = Q\") prefer 2\n  apply (metis (no_types, lifting) mem_Collect_eq)\n  apply(subgoal_tac \"\\<forall>a b j. ((a,b)\\<in>set(q s) \\<and> j=a ) \\<longrightarrow> ownB s (j) = Q\") prefer 2 \n  apply (metis (no_types, hide_lams) Nat.add_0_right le_refl nat_add_left_cancel_less)\n  apply(subgoal_tac \"\\<forall>a b.(a,b)\\<in>set(q s) \\<longrightarrow> (\\<exists>i.(i<length(q s) \\<and> fst(q s!i) = a))\") prefer 2\n  apply (metis fst_conv in_set_conv_nth)\n  apply(subgoal_tac \"(i<length(q s)) \\<longrightarrow> ownB s (fst(q s!i)) =Q\") prefer 2 \n  apply (metis nth_mem prod.collapse)\n  apply(subgoal_tac \"i<length(q s) \\<and> i>0 \\<longrightarrow> fst(q s!0) < fst(q s!i)\") prefer 2 \n  apply (metis (no_types, lifting) Q_ind_imp_tail_ind_1 diff_self_eq_0 le_0_eq le_eq_less_or_eq nat_neq_iff)\n  apply(subgoal_tac \"i<length(q s) \\<and> i>0 \\<longrightarrow> end(q s!0) \\<le> fst(q s!i)\") prefer 2 \n  apply (metis (no_types, lifting) Q_ind_imp_tail_ind_1 end_simp list.set_sel(1) nth_mem prod.collapse)\n  \n  apply(subgoal_tac \"length(q s)>1\") prefer 2 \n  apply (metis Suc_le_eq diff_is_0_eq length_0_conv length_tl not_less_eq_eq)\n\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s)) \\<longrightarrow> ownB s (fst(q s!i)) = Q\") prefer 2\n  apply (metis nth_mem prod.collapse)\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s)\\<and> i>0)\\<longrightarrow>fst(q s!i)>fst(q s!0)\") prefer 2 \n  apply (metis (no_types, lifting) Q_ind_imp_tail_ind_1 diff_self_eq_0 le_neq_implies_less less_nat_zero_code linorder_neqE_nat)\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s)\\<and> i>0)\\<longrightarrow>fst(q s!i)\\<ge>end(q s!0)\") prefer 2\n  apply (metis (no_types, lifting) Q_ind_imp_tail_ind_1 end_simp list.set_sel(1) nth_mem prod.collapse)\n  apply(subgoal_tac \"i<length(q s) \\<longrightarrow> ownB s (fst(q s!i)) = Q\") prefer 2\n  apply blast\n  (*split cases for ownB s 0 = Q and ownB s 0 \\<noteq> Q*)\n  apply(case_tac \"b=0\")\n  apply(subgoal_tac \"ownB s 0 = Q\") prefer 2 \n  apply (metis le_neq_implies_less less_nat_zero_code minus_nat.diff_0)\n  apply(subgoal_tac \"fst(q s!0) = 0\") prefer 2 \n  apply (metis F.distinct(3) Q_ind_imp_tail_ind_1 le_neq_implies_less)\n  apply(subgoal_tac \"\\<forall>i. i < length (q s) \\<and> 0 < i \\<longrightarrow>\n           fst (q s ! (i - Suc 0)) + snd (q s ! (i - Suc 0)) = fst (q s ! i)\")\n  prefer 2 \n  apply (metis (no_types, lifting))\n  apply(thin_tac \"\\<forall>i. i < length (q s) \\<and> 0 < i \\<longrightarrow> fst (q s ! (i - Suc 0)) + snd (q s ! (i - Suc 0)) = fst (q s ! i) \\<or>fst (q s ! i) = 0\")\n  sorry\n\n\n\n\n\n\nlemma R_idle_to_nidle_lemma_case_1_5:\n  \"case_1 s\\<Longrightarrow>con_assms s \\<Longrightarrow> pcR s = idleR\\<Longrightarrow>pre_R (pcR s) s\n  \\<Longrightarrow>s'=(s\\<lparr>ownB := \\<lambda>i. if fst (hd (q s)) \\<le> i \\<and> i < fst (hd (q s)) + snd (hd (q s)) then R else ownB s i,\n          numDeqs := Suc (numDeqs s), ownT := R, tempR := hd (q s), pcR := Read, q := tl (q s)\\<rparr>)\n\\<Longrightarrow>inv s \\<Longrightarrow>q s\\<noteq>[]\n\\<Longrightarrow>case_1 s'\"\n  apply(simp add:case_1_def inv_def) \n  apply(clarify) apply(intro conjI impI)\n   apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(subgoal_tac \"c\\<le>N\") prefer 2\n    apply linarith\n  apply(subgoal_tac \"q s\\<noteq>[]\\<longrightarrow>hd(q s) \\<in>set(q s)\") prefer 2 \n  apply (metis list.set_sel(1))\n  apply(subgoal_tac \"q s\\<noteq>[]\") prefer 2 \n  apply blast\n  apply (metis diff_is_0_eq less_nat_zero_code prod.collapse zero_less_diff)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(rule_tac ?x = \"T s\" in exI)\n  apply(rule_tac ?x = \"end(hd(q s))\" in exI)\n  apply(intro conjI impI)\n  apply (metis cancel_comm_monoid_add_class.diff_cancel end_simp le_0_eq le_neq_implies_less length_0_conv trans_le_add1)\n  apply(rule_tac ?x = \"c\" in exI)\n  apply(simp add:pre_R_def  pre_dequeue_inv_def) \n  apply(intro conjI impI)\n  apply (metis (no_types, lifting) F.distinct(19) F.distinct(3) diff_is_0_eq le_0_eq le_neq_implies_less length_0_conv nat_le_linear)\n  apply (metis Suc_leI diff_is_0_eq' le_0_eq le_neq_implies_less le_trans length_0_conv not_less_eq_eq)              \n  apply (metis (no_types, lifting) cancel_comm_monoid_add_class.diff_cancel end_simp le_0_eq le_neq_implies_less length_0_conv nat_le_linear)\n  apply (metis diff_is_0_eq end_simp le_0_eq le_add1 le_eq_less_or_eq le_trans length_0_conv zero_less_diff)\n  apply (metis (no_types, hide_lams) F.distinct(3))\n  apply (metis (no_types, hide_lams) F.distinct(19))\n  apply (metis diff_self_eq_0 le_0_eq le_eq_less_or_eq length_0_conv)\n  apply (metis diff_add_inverse diff_self_eq_0 le_0_eq le_eq_less_or_eq length_0_conv)\n  defer\n  defer\n  apply(subgoal_tac \"i<(length(q s))\\<and>i>0\\<longrightarrow> fst(q s!(i-1)) + snd(q s!(i-1)) = fst(q s!i) \\<or> fst(q s!i) = 0\") prefer 2\n  apply (metis (no_types, lifting) One_nat_def)\n  apply(subgoal_tac \"T s \\<ge> 0\") prefer 2\n  apply blast\n  apply(subgoal_tac \"hd(tl(q s)) = q s!1\") prefer 2 \n  apply (metis (no_types, lifting) One_nat_def bot_nat_0.extremum_uniqueI diff_add_inverse2 diff_self_eq_0 hd_conv_nth last_conv_nth le_neq_implies_less length_greater_0_conv length_tl less_diff_conv list.size(3) nth_tl)\n  apply(subgoal_tac \"hd(q s) = q s!0\") prefer 2\n  apply (metis hd_conv_nth)\n  apply(case_tac \"b = 0\") \n  apply(subgoal_tac \"fst(hd(q s)) = 0\") prefer 2\n  apply force \n  apply(subgoal_tac \"i<length(q s) \\<and> j<length(q s) \\<and> i\\<noteq>j \\<longrightarrow> fst(q s!i) \\<noteq>fst(q s!j)\") prefer 2 \n  apply (metis (no_types, lifting))\n  apply(subgoal_tac \"i<(length(q s))\\<and>i>0\\<and> fst(q s!0) = 0\\<longrightarrow> fst(q s!(i-1)) + snd(q s!(i-1)) = fst(q s!i)\") prefer 2\n  apply (metis (no_types, lifting) length_greater_0_conv)\n  apply(case_tac \"length(q s) > 1\") \n  apply(subgoal_tac \"fst(q s!0) = 0\\<longrightarrow> fst(q s!(0)) + snd(q s!(0)) = fst(q s!1)\") prefer 2\n  apply (metis (no_types, lifting) One_nat_def diff_Suc_1 length_greater_0_conv less_one)\n  apply presburger\n  apply (metis diff_self_eq_0 last_conv_nth length_0_conv less_nat_zero_code less_one nat_neq_iff)\n  apply(subgoal_tac \"b>0\") prefer 2 \n  apply force\n  apply(subgoal_tac \"ownB s 0 \\<noteq> Q\") prefer 2 \n  apply (metis F.distinct(19) le_neq_implies_less)\n  apply(subgoal_tac \" \\<forall>i. (\\<exists>x. (\\<exists>a b. x = {i. a \\<le> i \\<and> i < a + b} \\<and> (a, b) \\<in> set (q s)) \\<and> i \\<in> x) = (i \\<le> N \\<and> ownB s i = Q)\") prefer 2 \n  apply blast\n  apply(subgoal_tac \"0\\<le>N\") prefer 2\n  apply blast\n  apply(subgoal_tac \"(\\<nexists>x. (\\<exists>a b. x = {i. a \\<le> i \\<and> i < a + b} \\<and> (a, b) \\<in> set (q s)) \\<and> 0 \\<in> x)\")\n  prefer 2\n  apply presburger\n  apply(subgoal_tac \"\\<nexists>a b. (a,b) \\<in> set(q s) \\<and> a=0\") prefer 2 \n  apply (metis (no_types, lifting) bot_nat_0.extremum mem_Collect_eq plus_nat.add_0)\n  apply(subgoal_tac \"i<length(q s) \\<longrightarrow> (q s!i) \\<in> set(q s)\") prefer 2 \n  apply (metis nth_mem)\n  apply(subgoal_tac \"(sta,wlength)\\<in>set(q s) \\<longrightarrow> (\\<exists>i.(i<length(q s) \\<and> (sta,wlength) = q s!i))\") prefer 2\n  apply (metis in_set_conv_nth)\n  apply(subgoal_tac \"\\<forall>sta wlength. (sta,wlength)\\<in>set(q s) \\<longrightarrow> sta\\<noteq>0\") prefer 2 \n  apply metis\n  apply(subgoal_tac \"i<length(q s) \\<longrightarrow>fst(q s!i)\\<noteq>0\") prefer 2\n  apply (metis prod.collapse)\n  apply(subgoal_tac \"i<(length(q s))\\<and>i>0\\<longrightarrow> fst(q s!(i-1)) + snd(q s!(i-1)) = fst(q s!i)\") prefer 2\n  apply (metis prod.collapse)\n  apply(case_tac \"length(q s)>1\") \n  apply (metis (no_types, lifting) One_nat_def diff_Suc_1 less_one nth_mem prod.collapse)\n  apply(case_tac \"length(q s) = 0\")\n  apply fastforce\n  apply(subgoal_tac \"length(q s) = 1\") prefer 2\n  apply linarith\n  apply(subgoal_tac \"length(tl(q s)) = 0\") prefer 2\n  apply (metis diff_self_eq_0 length_tl)\n  apply (metis diff_self_eq_0 last_conv_nth le_neq_implies_less less_irrefl_nat not_one_le_zero)\n  apply(case_tac \"length(q s) \\<le>1\")\n  apply (metis bot_nat_0.extremum_uniqueI diff_add_inverse2 diff_is_0_eq' head_q0 last_conv_nth le_neq_implies_less length_greater_0_conv less_diff_conv less_numeral_extra(3))\n  apply (metis (no_types, lifting) One_nat_def diff_is_0_eq last_tl le_Suc_eq le_neq_implies_less length_tl list.size(3))\n  apply (metis (no_types, lifting) diff_add_inverse diff_is_0_eq' le_0_eq le_eq_less_or_eq length_0_conv linorder_neqE_nat list.set_sel(1) nat_less_le not_add_less1 prod.collapse)\n  apply (metis diff_add_inverse diff_is_0_eq' le_eq_less_or_eq less_nat_zero_code list.set_sel(1) prod.collapse)\n  apply (metis diff_is_0_eq le_zero_eq length_0_conv)\n  defer\n  apply(subgoal_tac \"i\\<ge>end(hd(q s)) \\<and> i<c \\<longrightarrow> ownB s i = Q \\<and> i\\<le>N\") prefer 2 \n  apply (metis add_leD1 diff_self_eq_0 end_simp le_0_eq le_eq_less_or_eq le_trans length_0_conv)\n  apply(subgoal_tac \"\\<forall>i. (\\<exists>x. (\\<exists>a b. x = {i. a \\<le> i \\<and> i < a + b} \\<and> (a, b) \\<in> set (q s)) \\<and> i \\<in> x) = (i \\<le> N \\<and> ownB s i = Q)\")\n  prefer 2\n  apply blast\n  apply(subgoal_tac \"ownB s (end(hd(q s))) = Q\") prefer 2 \n  apply (metis diff_self_eq_0 end_simp le_0_eq le_add1 le_eq_less_or_eq length_0_conv)\n  (*difficult and time consuming, need help here*)\n  apply(subgoal_tac \"numEnqs s - numDeqs s >1\") \n  using One_nat_def apply presburger\n  apply(case_tac \"tl(q s) = []\") \n  apply (metis bot_nat_0.extremum_uniqueI diff_add_inverse2 diff_self_eq_0 hd_conv_nth last_conv_nth le_neq_implies_less length_0_conv length_tl less_diff_conv)\n  apply (metis Suc_le_eq diff_is_0_eq length_0_conv length_tl not_less_eq_eq)\n  apply(case_tac \"tl(q s) = []\") \n  apply (metis Nitpick.size_list_simp(2) diff_0_eq_0 diff_Suc_Suc zero_le) \n\n  apply(subgoal_tac \"i\\<ge>end(hd(q s)) \\<and> i<c \\<longrightarrow> ownB s i = Q \\<and> i\\<le>N\") prefer 2 \n  apply (metis add_leD1 diff_self_eq_0 end_simp le_0_eq le_eq_less_or_eq le_trans length_0_conv)\n  apply(subgoal_tac \"\\<forall>i. (\\<exists>x. (\\<exists>a b. x = {i. a \\<le> i \\<and> i < a + b} \\<and> (a, b) \\<in> set (q s)) \\<and> i \\<in> x) = (i \\<le> N \\<and> ownB s i = Q)\")\n  prefer 2\n  apply blast\n  (*difficult and time consuming, need help here*)\n  apply(subgoal_tac \"numEnqs s - numDeqs s >1\") prefer 2\n  apply (metis Suc_le_eq diff_is_0_eq length_0_conv length_tl not_less_eq_eq)\n  apply(subgoal_tac \"hd(q s) \\<in> set(q s) \\<and> hd(q s) = (q s!0)\") prefer 2 \n  apply (metis Q_ind_imp_tail_ind_1 list.set_sel(1))\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s) \\<and> i>0) \\<longrightarrow> end((q s)!(i-1)) = fst(q s!i) \\<or> fst(q s!i) = 0\") prefer 2 \n  apply (metis (no_types, lifting) One_nat_def end_simp)\n  apply(subgoal_tac \"\\<forall>i. (i\\<le>N \\<and> ownB s i = Q)\\<longrightarrow> i\\<ge>0\") prefer 2 \n  apply blast\n  apply(case_tac \"ownB s 0 = Q\")\n  apply(subgoal_tac \"fst(q s!0) = 0\") prefer 2 \n  apply (metis F.distinct(19) bot_nat_0.not_eq_extremum diff_0_eq_0 le_eq_less_or_eq)\n  apply(subgoal_tac \"i<length(q s) \\<and> i>0 \\<longrightarrow> fst(q s!i) > 0\") prefer 2\n  apply (metis (no_types, lifting) gr0I length_greater_0_conv)\n  apply(subgoal_tac \"(a,wlen)\\<in>set(q s) \\<and> (aa,bb)\\<in>set(q s) \\<and> aa>a\\<longrightarrow> a+wlen\\<le>aa\")\n  prefer 2 \n  apply (metis (no_types, lifting))\n  apply(subgoal_tac \"length(q s) = length(tl(q s)) + 1\") prefer 2\n  apply (metis Nat.add_0_right One_nat_def Suc_diff_1 add_Suc_right length_pos_if_in_set length_tl)\n  apply(subgoal_tac \"tl(q s) \\<noteq> []\") prefer 2\n    apply blast\n  apply(subgoal_tac \"c = end(last(q s))\") prefer 2 \n    apply (metis diff_self_eq_0 end_simp le_neq_implies_less less_nat_zero_code)\n  \n  sorry\n\n\n\n\nlemma R_idle_to_nidle_lemma_case_1_6:\n  \"case_2 s\\<Longrightarrow>con_assms s \\<Longrightarrow> pcR s = idleR\\<Longrightarrow>pre_R (pcR s) s\n  \\<Longrightarrow>s'=(s\\<lparr>ownB := \\<lambda>i. if fst (hd (q s)) \\<le> i \\<and> i < fst (hd (q s)) + snd (hd (q s)) then R else ownB s i,\n          numDeqs := Suc (numDeqs s), ownT := R, tempR := hd (q s), pcR := Read, q := tl (q s)\\<rparr>)\n\\<Longrightarrow>inv s \\<Longrightarrow>q s\\<noteq>[]\n\\<Longrightarrow>case_2 s'\"\n  apply(simp add:case_2_def inv_def)\n  apply(simp add:Q_lemmas Q_basic_lemmas) apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(clarify) apply(intro conjI impI)\n  apply (metis (no_types, lifting) le_antisym less_imp_le_nat list.set_sel(1) nat_neq_iff prod.collapse)\n  sorry\n\n\nlemma R_idle_to_nidle_lemma_case_1_7:\n  \"con_assms s \\<Longrightarrow> pcR s = idleR\\<Longrightarrow>pre_R (pcR s) s\n  \\<Longrightarrow>s'=(s\\<lparr>ownB := \\<lambda>i. if fst (hd (q s)) \\<le> i \\<and> i < fst (hd (q s)) + snd (hd (q s)) then R else ownB s i,\n          numDeqs := Suc (numDeqs s), ownT := R, tempR := hd (q s), pcR := Read, q := tl (q s)\\<rparr>)\n\\<Longrightarrow>inv s \\<Longrightarrow>q s\\<noteq>[]\n\\<Longrightarrow>Q_owns_bytes s'\"\n  sorry\n\n\nlemma R_read_to_release_lemma_1:\n  \"con_assms s \\<Longrightarrow> pcR s = Read\\<Longrightarrow>pre_Read_inv s\n  \\<Longrightarrow>s'=(s\\<lparr>tR := T s, numReads := Suc (data_index s (tempR s)),\n          pcR := Release,\n          ownD :=\n            \\<lambda>i. if i = data_index s (tempR s) then R\n                 else ownD\n                       (s\\<lparr>tR := T s,\n                            numReads := Suc (data_index s (tempR s)),\n                            pcR := Release\\<rparr>)\n                       i\\<rparr>)\n\\<Longrightarrow>inv s \n\\<Longrightarrow>i>0\\<longrightarrow>ownB s' i = ownB s i \\<and> T s = T s' \\<and> H s = H s' \\<and>\n  tempR s = tempR s' \\<and> offset s = offset s' \\<and> Data s (numEnqs s) = Data s' (numEnqs s')\n  \\<and> q s = q s' \\<and> ownT s = ownT s'\"\n  by simp\n\n\nlemma R_read_to_release_lemma_case_1:\n  \"con_assms s \\<Longrightarrow> pcR s = Read\\<Longrightarrow>pre_Read_inv s\n  \\<Longrightarrow>s'=(s\\<lparr>tR := T s, numReads := Suc (data_index s (tempR s)),\n          pcR := Release,\n          ownD :=\n            \\<lambda>i. if i = data_index s (tempR s) then R\n                 else ownD\n                       (s\\<lparr>tR := T s,\n                            numReads := Suc (data_index s (tempR s)),\n                            pcR := Release\\<rparr>)\n                       i\\<rparr>)\n\\<Longrightarrow>inv s \n\\<Longrightarrow>case_1 s\n\\<Longrightarrow>case_1 s'\"\n  by(simp add:case_1_def)\n\nlemma R_read_to_release_lemma_case_2:\n  \"con_assms s \\<Longrightarrow> pcR s = Read\\<Longrightarrow>pre_Read_inv s\n  \\<Longrightarrow>s'=(s\\<lparr>tR := T s, numReads := Suc (data_index s (tempR s)),\n          pcR := Release,\n          ownD :=\n            \\<lambda>i. if i = data_index s (tempR s) then R\n                 else ownD\n                       (s\\<lparr>tR := T s,\n                            numReads := Suc (data_index s (tempR s)),\n                            pcR := Release\\<rparr>)\n                       i\\<rparr>)\n\\<Longrightarrow>inv s \n\\<Longrightarrow>case_2 s\n\\<Longrightarrow>case_2 s'\"\n  by(simp add:case_2_def)\n\nlemma R_read_to_release_lemma_2:\n  \"con_assms s \\<Longrightarrow> pcR s = Read\\<Longrightarrow>pre_Read_inv s\n  \\<Longrightarrow>s'=(s\\<lparr>tR := T s, numReads := Suc (data_index s (tempR s)),\n          pcR := Release,\n          ownD :=\n            \\<lambda>i. if i = data_index s (tempR s) then R\n                 else ownD\n                       (s\\<lparr>tR := T s,\n                            numReads := Suc (data_index s (tempR s)),\n                            pcR := Release\\<rparr>)\n                       i\\<rparr>)\n\\<Longrightarrow>inv s \n\\<Longrightarrow>Q_owns_bytes s\n\\<Longrightarrow>Q_owns_bytes s'\"\n  by(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n\nlemma T_modification_rule:\n  \"s'=(s\\<lparr>T := fst (tempR s) + Data s (numReads s - Suc 0)\\<rparr>) \\<Longrightarrow> T s' = fst (tempR s) + Data s (numReads s - Suc 0)\"\n  by simp\n\nlemma T_modification_rule_2:\n  \"s'=(s\\<lparr>ownT := Q,\n          ownB :=\n            \\<lambda>i. if (if T s \\<le> i \\<and> i < N then B else ownB (s\\<lparr>ownT := Q\\<rparr>) i) = R \\<and> i \\<le> N then B\n                else ownB (setownB [(tR s, N) B] (s\\<lparr>ownT := Q\\<rparr>)) i,\n          tempR := (0, 0), pcR := idleR, T := fst (tempR s) + Data s (numReads s - Suc 0)\\<rparr>) \\<Longrightarrow> T s' = fst (tempR s) + Data s (numReads s - Suc 0)\"\n  by simp\n\nlemma T_push:\n  \" T s = fst (tempR s) \\<Longrightarrow>s'=s \\<lparr>ownT := Q,\n          ownB :=\n            \\<lambda>i. if ownB s i = R \\<and> i \\<le> N then B\n                else ownB ((if T s \\<noteq> fst (tempR s) then setownB [(tR s, N) B] else id) (s\\<lparr>ownT := Q\\<rparr>)) i,\n          tempR := (0, 0), pcR := idleR, T := fst (tempR s) + Data s (numReads s - Suc 0)\\<rparr> \\<Longrightarrow>\nT s' = fst (tempR s) + Data s (numReads s - Suc 0)\"\n  by simp\n\nlemma T_push_2 :\n  \" T s = fst (tempR s) \\<Longrightarrow>s'=(s\\<lparr>ownT := Q, ownB := \\<lambda>i. if ownB s i = R \\<and> i \\<le> N then B else ownB (id (s\\<lparr>ownT := Q\\<rparr>)) i, tempR := (0, 0), pcR := idleR,\n          T := fst (tempR s) + Data s (numReads s - Suc 0)\\<rparr>) \\<Longrightarrow>\nT s' = fst (tempR s) + Data s (numReads s - Suc 0)\"\n  by simp\n\nlemma R_release_to_idle_lemma_1:\n  \"con_assms s \\<Longrightarrow> pcR s = Release \\<Longrightarrow> pre_Release_inv s\n  \\<Longrightarrow> s'=s \\<lparr>ownT := Q,\n          ownB :=\n            \\<lambda>i. if ownB s i = R \\<and> i \\<le> N then B\n                else ownB ((if T s \\<noteq> fst (tempR s) then setownB [(tR s, N) B] else id) (s\\<lparr>ownT := Q\\<rparr>)) i,\n          tempR := (0, 0), pcR := idleR, T := fst (tempR s) + Data s (numReads s - Suc 0)\\<rparr>\n\\<Longrightarrow>inv s \\<Longrightarrow> T s = fst (tempR s)\n\\<Longrightarrow>case_1 s\n\\<Longrightarrow>case_1 s'\"\n  apply (simp add:inv_def)       \n  apply(simp add:pre_Release_inv_def tempR_lemmas tempR_basic_lemmas)\n  apply(subgoal_tac \"T s' = fst (tempR s) + Data s (numReads s - Suc 0)\") prefer 2 \n  using T_push [where s =s and s'=s'] \n  apply fastforce\n  apply(simp add:case_1_def)\n  apply clarify \n  apply(rule_tac ?x = \"b\" in exI)\n  apply(rule_tac ?x = \"b\" in exI) \n  apply(intro conjI impI)\n  apply fastforce \n  apply(rule_tac ?x = \"c\" in exI) \n  apply(intro conjI impI) \n  apply blast\n  apply blast \n  apply (metis (no_types, lifting) le_trans less_or_eq_imp_le linorder_neqE_nat)\n  apply (metis Suc_leI not_less_eq_eq)\n  apply (metis F.distinct(11)) \n  apply (metis F.distinct(1)) \n  apply metis    \n  apply meson\n  apply (metis le_add_diff_inverse)\n  apply meson\n  apply meson\n  apply fastforce\n  apply blast\n  apply blast\n  apply meson\n  apply meson\n  by meson\n\n\nlemma R_release_nequal_case_2:\n  \"con_assms s \\<Longrightarrow> pcR s = Release \\<Longrightarrow> pre_Release_inv s\n\\<Longrightarrow>inv s \\<Longrightarrow> T s \\<noteq> fst (tempR s)\n\\<Longrightarrow>case_2 s\"\n  apply (simp add:inv_def)       \n  apply(simp add:pre_Release_inv_def tempR_lemmas tempR_basic_lemmas)\n  apply(case_tac \"case_1 s\", simp_all) \n  apply(simp add:case_1_def)\n  apply(subgoal_tac \"H s>T s\") prefer 2 \n  apply metis\n  apply(simp add:case_2_def)\n  by metis\n\n\nlemma R_release_nequal_case_2_2:\n  \"con_assms s \\<Longrightarrow> pcR s = Release \\<Longrightarrow> pre_Release_inv s\n\\<Longrightarrow>inv s \\<Longrightarrow> T s \\<noteq> fst (tempR s) \\<Longrightarrow> s' = s\n    \\<lparr>ownT := Q,\n       ownB :=\n         \\<lambda>i. if (if T s \\<le> i \\<and> i < N then B else ownB (s\\<lparr>ownT := Q\\<rparr>) i) = R \\<and> i \\<le> N then B\n             else ownB ((if T s \\<noteq> fst (tempR s) then setownB [(tR s, N) B] else id) (s\\<lparr>ownT := Q\\<rparr>)) i,\n       tempR := (0, 0), pcR := idleR, T := fst (tempR s) + Data s (numReads s - Suc 0)\\<rparr>\n\\<Longrightarrow>case_1 s'\"\n  apply(subgoal_tac \"case_2 s\") prefer 2 using  R_release_nequal_case_2 [where s=s]\n  apply blast\n  apply (simp add:inv_def)\n  apply(simp add:pre_Release_inv_def tempR_lemmas tempR_basic_lemmas)\n  apply(subgoal_tac \"H s < T s\") prefer 2 \n  apply(simp add:case_2_def)\n  apply meson\n  apply(simp add:case_2_def case_1_def)\n  apply clarify\n  apply(rule_tac ?x = \"a\" in exI)\n  apply(rule_tac ?x = \"a\" in exI)\n  apply(intro conjI impI)\n  apply blast\n  apply(rule_tac ?x = \"b\" in exI)\n  apply(intro conjI impI)\n  apply blast\n  apply blast\n  apply (metis add_cancel_left_left le_trans less_or_eq_imp_le)\n  apply (metis le_antisym less_irrefl_nat less_or_eq_imp_le)\n  apply (metis F.distinct(11) F.distinct(21) gr0_conv_Suc nat.discI nat_less_le)\n  apply (metis F.distinct(1))\n  apply (metis nat_le_linear nat_less_le)\n  apply meson\n  apply (metis add_cancel_right_left)\n  apply fastforce\n  apply meson\n  apply force\n  apply blast\n  apply (metis add_cancel_left_left diff_self_eq_0 le_neq_implies_less)\n  apply meson\n  apply (metis le_neq_implies_less)\n  by meson\n\n\nlemma R_release_nequal_case_1_1:\n  \"con_assms s \\<Longrightarrow> pcR s = Release \\<Longrightarrow> pre_Release_inv s\n\\<Longrightarrow>inv s \\<Longrightarrow> T s = fst (tempR s) \\<Longrightarrow> s'=(s\\<lparr>ownT := Q, ownB := \\<lambda>i. if ownB s i = R \\<and> i \\<le> N then B else ownB (id (s\\<lparr>ownT := Q\\<rparr>)) i, tempR := (0, 0), pcR := idleR,\n          T := fst (tempR s) + Data s (numReads s - Suc 0)\\<rparr>) \\<Longrightarrow> case_1 s\n\\<Longrightarrow>case_1 s'\"\n  apply (simp add:inv_def)       \n  apply(simp add:pre_Release_inv_def tempR_lemmas tempR_basic_lemmas)\n  apply(subgoal_tac \"T s' = fst (tempR s) + Data s (numReads s - Suc 0)\") prefer 2 \n  using T_push_2 [where s=s and s'=s']\n  apply fastforce\n  apply(simp add:case_1_def) \n  apply clarify \n  apply(rule_tac ?x = \"b\" in exI)\n  apply(rule_tac ?x = \"b\" in exI) \n  apply(intro conjI impI)\n  apply fastforce \n  apply(rule_tac ?x = \"c\" in exI) \n  apply(intro conjI impI) \n  apply blast\n  apply blast\n  apply (metis diff_commute diff_diff_cancel diff_is_0_eq' less_nat_zero_code linorder_neqE_nat nat_le_linear zero_less_diff)\n  apply (metis le_imp_less_Suc not_less_eq)\n  apply (metis F.distinct(11))\n  apply (metis F.distinct(1))\n  apply metis\n  apply blast\n  apply (metis le_add_diff_inverse)\n  apply meson\n  apply fastforce\n  apply fastforce\n  apply force\n  apply blast\n  apply meson\n  apply fastforce\n  by meson\n\n\n\nlemma R_release_equal_case_2_3:\n  \"con_assms s \\<Longrightarrow> pcR s = Release \\<Longrightarrow> pre_Release_inv s\n\\<Longrightarrow>inv s \\<Longrightarrow> T s = fst (tempR s) \\<Longrightarrow> s'=(s\\<lparr>ownT := Q, ownB := \\<lambda>i. if ownB s i = R \\<and> i \\<le> N then B else ownB (id (s\\<lparr>ownT := Q\\<rparr>)) i, tempR := (0, 0), pcR := idleR,\n          T := fst (tempR s) + Data s (numReads s - Suc 0)\\<rparr>) \\<Longrightarrow> case_2 s\n\\<Longrightarrow>case_2 s'\"\n  apply (simp add:inv_def)       \n  apply(simp add:pre_Release_inv_def tempR_lemmas tempR_basic_lemmas)\n  apply(subgoal_tac \"T s' = fst (tempR s) + Data s (numReads s - Suc 0)\") prefer 2 \n  using T_push_2 [where s =s and s'=s'] \n  apply fastforce apply(simp_all)\n  apply(simp add:case_2_def)\n  apply clarify \n  apply(rule_tac ?x = \"0\" in exI)\n  apply(rule_tac ?x = \"b\" in exI) \n  apply(intro conjI impI)\n  apply fastforce \n  apply(rule_tac ?x = \"H s\" in exI) \n  apply(intro conjI impI) \n  apply fastforce\n  apply(rule_tac ?x = \"e\" in exI)\n  apply(intro conjI impI) \n  apply (metis le_add_diff_inverse trans_less_add1)\n  apply(rule_tac ?x = \"e\" in exI)\n  apply(intro conjI impI) \n  apply fastforce\n  apply(rule_tac ?x = \"f\" in exI)\n  apply(intro conjI impI) \n  apply fastforce\n  apply blast\n  apply blast\n  apply (metis F.distinct(11) less_nat_zero_code)\n  apply (metis F.distinct(1))\n  apply (metis (mono_tags, hide_lams) diff_is_0_eq' le_trans linorder_neqE_nat nat_le_linear zero_less_diff)\n  apply (metis le_imp_less_Suc not_less_eq)\n  apply (metis F.distinct(11))\n  apply (metis F.distinct(15))\n  apply fastforce\n  apply blast\n  apply blast\n  apply blast\n  apply blast\n  apply (metis gr_implies_not_zero le_add_diff_inverse)\n  apply blast\n  apply meson\n  apply meson\n  apply blast\n  apply fastforce\n  apply blast\n  apply (metis less_nat_zero_code)\n  apply meson\n  apply (metis less_nat_zero_code)\n  apply meson\n  apply (metis less_nat_zero_code)\n  apply (metis less_nat_zero_code)\n  by force\n\n\n\n  \n\n\n\n\nlemma Q_continues_to_own_through_release:\n  \"Q_owns_bytes s \\<Longrightarrow> inv s \\<Longrightarrow> cR_step (pcR s) s s' \\<Longrightarrow> pcR s = Release \n  \\<Longrightarrow> pre_Release_inv s\n  \\<Longrightarrow> Q_owns_bytes s'\"\n  apply simp\n  apply(simp add:Q_lemmas Q_basic_lemmas inv_def pre_Release_inv_def)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply metis\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\") \n  by (metis F.distinct(21) nat_less_le)\n\n\n\nlemma Q_structure_continues_to_own_through_release:\n  \"Q_structure s \\<Longrightarrow> inv s \\<Longrightarrow> cR_step (pcR s) s s' \\<Longrightarrow> pcR s = Release \n  \\<Longrightarrow> pre_Release_inv s\n  \\<Longrightarrow> Q_structure s'\"\n  apply simp\n  apply(simp add:Q_lemmas Q_basic_lemmas inv_def pre_Release_inv_def)\n  by(simp add:cR_step_def)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n(************************************Local R_step shows inv  *********************************************)\n\n\nlemma R_local_release_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcR s = Release\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"inv s'\"\n  using assms apply simp \n  apply(subgoal_tac \"Q_owns_bytes s\") prefer 2\n  using inv_def\n  apply blast\n  apply(subgoal_tac \"inv s\") prefer 2 \n  apply blast\n  apply(subgoal_tac \"cR_step (pcR s) s s'\") prefer 2\n  apply metis\n  apply(subgoal_tac \"pcR s = Release \") prefer 2\n   apply metis \n  apply(subgoal_tac \"pre_Release_inv s\") prefer 2 \n  apply(simp add:pre_R_def)\n  apply(subgoal_tac \"Q_owns_bytes s'\") prefer 2\n  using Q_continues_to_own_through_release [where s=s and s'=s'] \n  apply blast\n  apply(subgoal_tac \"Q_structure s\") prefer 2 using inv_def\n  apply blast\n  apply(subgoal_tac \"Q_structure s'\") prefer 2 \n  using Q_structure_continues_to_own_through_release [where s=s and s'=s']\n  apply blast\n(*prelimiaries go here*)\n  apply(simp add:inv_def)\n  apply(subgoal_tac \"inv s\") prefer 2 \n  using assms(1) apply linarith\n  apply(simp add:pre_R_def)\n  apply(subgoal_tac \"B_release s s'\") prefer 2 using B_release_def [where s=s and s'=s']\n  apply (metis PCR.simps(7) cR_step_def) \n  apply(subgoal_tac \"ownT s = R\") prefer 2 using pre_Release_inv_def [where s=s] \n  apply presburger\n  apply(subgoal_tac \"Q_structure s'\")\n  using Q_structure_preserved3 [where s=s and s'=s']  prefer 2 \n  apply (metis \\<open>B_release s s' \\<equiv> s' = (`T := end (tempR s) \\<circ> `pcR := idleR \\<circ> `tempR := (0, 0) \\<circ> transownB [R B] \\<circ> (if tR s \\<noteq> fst (tempR s) then setownB [(tR s, N) B] else id) \\<circ> transownT [R Q s]) s\\<close> end_simp len_def off_def)\n  apply(simp add:pre_Release_inv_def)\n  apply(intro conjI impI) apply(simp add:tempR_lemmas tempR_basic_lemmas) prefer 2\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply(case_tac \"T s \\<noteq> fst (tempR s)\", simp_all)\n  apply(subgoal_tac \"T s \\<noteq> fst (tempR s)\") prefer 2 \n  apply blast\n  apply(subgoal_tac \"pre_R Release s\") prefer 2 using assms \n  apply presburger\n  apply(simp add:pre_R_def)\n  apply(subgoal_tac \"pre_Release_inv s\") prefer 2\n  apply blast\n  apply(subgoal_tac \"case_2 s\") prefer 2\n  using R_release_nequal_case_2 [where s=s]\n  using assms(2) apply fastforce\n  apply(simp_all)\n  apply(subgoal_tac \"case_1 s'\") prefer 2 using R_release_nequal_case_2_2 [where s'=s' and s=s] \n  using assms(2) apply blast\n  apply presburger\n  apply(case_tac \"case_1 s\", simp_all)\n  apply(case_tac[!] \"T s = fst(tempR s)\") apply(simp_all)\n  apply(subgoal_tac \"case_1 s'\") \n  using R_release_nequal_case_1_1 [where s=s and s'=s'] \n  apply presburger\n  apply(subgoal_tac \"pre_R (pcR s) s\") prefer 2 \n  using assms(4) apply blast\n  apply(simp add:pre_R_def) apply(subgoal_tac \"pre_Release_inv s\") prefer 2 \n  apply blast\n  using R_release_nequal_case_1_1 [where s=s and s'=s']\n  using assms(2) apply presburger\n  apply(subgoal_tac \"case_2 s'\")\n  using R_release_equal_case_2_3 [where s=s and s'=s']\n  apply presburger\n  apply(subgoal_tac \"pre_R (pcR s) s\") prefer 2 \n  using assms(4) apply blast\n  apply(simp add:pre_R_def) apply(subgoal_tac \"pre_Release_inv s\") prefer 2 \n  apply blast\n  using R_release_equal_case_2_3 [where s=s and s'=s']\n  using assms(2) by presburger\n\n\n\nlemma R_local_idle_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcR s = idleR\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"inv s'\"\n  using assms apply simp\n  apply(simp add:pre_R_def cR_step_def)\n  apply(case_tac \"q s=[]\")  apply(case_tac \"pcR s'\") apply (simp,simp,simp)\n  apply(subgoal_tac \"Q_structure s'\") prefer 2 \n  using Q_structure_preserved1 [where s=s and s'=s'] inv_def\n  apply meson \n  apply (simp add: RingBuffer_BD_latest_2.inv_def)  apply simp\n  apply(simp add:pre_dequeue_inv_def)\n  apply(subgoal_tac \"s'=(s\\<lparr>ownB := \\<lambda>i. if fst (hd (q s)) \\<le> i \\<and> i < fst (hd (q s)) + snd (hd (q s)) then R else ownB s i,\n          numDeqs := Suc (numDeqs s), ownT := R, tempR := hd (q s), pcR := Read, q := tl (q s)\\<rparr>)\n\") prefer 2 \n  apply presburger\n  apply(subgoal_tac \"Q_owns_bytes s'\") prefer 2\n  using R_idle_to_nidle_lemma_case_1_7 [where s=s and s'=s'] assms\n  apply fastforce\n  apply(simp add:inv_def)\n  apply(clarify)\n  apply(intro conjI impI)\n  apply (metis add.right_neutral add_Suc_right diff_diff_left)\n  apply (metis diff_is_0_eq length_0_conv not_less_eq_eq)\n  apply (metis diff_is_0_eq' le_trans length_0_conv not_less_eq_eq)\n  apply(case_tac \"case_1 s\") apply simp \n  apply(subgoal_tac \"case_1 s'\\<longrightarrow>case_1 s' \\<or> case_2 s'\") prefer 2\n  apply linarith\n  apply(subgoal_tac \"case_1 s'\") \n  apply blast\n  apply simp \n  using R_idle_to_nidle_lemma_case_1_5 [where s=s and s'=s'] \n  using assms(1) assms(2) assms(4) \n  apply presburger\n  apply(subgoal_tac \"case_2 s\") prefer 2\n  apply blast\n  apply(thin_tac \"\\<not>case_1 s\") apply simp \n  using R_idle_to_nidle_lemma_case_1_6 [where s=s and s'=s'] \n  using assms(1) assms(2) assms(4) by presburger\n\n\n\nlemma R_local_read_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcR s = Read\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"inv s'\"\n  using assms apply simp\n  apply(simp add:inv_def)\n  apply(simp add:pre_R_def)\n  apply(subgoal_tac \"B_read s s'\") prefer 2 using B_read_def [where s=s and s'=s'] \n   apply (metis PCR.simps(9) cR_step_def)\n  apply(subgoal_tac \"ownT s = R\") prefer 2 using pre_Read_inv_def [where s=s] \n  apply presburger\n  apply(subgoal_tac \"Q_structure s'\")\n  using Q_structure_preserved2 [where s=s and s'=s']  prefer 2\n  apply blast\n  apply(simp add:pre_Read_inv_def)\n  apply(intro conjI impI)\n  apply (metis F.distinct(5) le_antisym le_eq_less_or_eq not_less_eq_eq)\n  apply (metis F.distinct(5) Suc_leI le_eq_less_or_eq not_less_eq_eq)\n   apply(case_tac \"case_1 s\")\n    apply(subgoal_tac \"case_1 s'\")\n     apply fastforce\n  apply(subgoal_tac \"pre_Read_inv s\") prefer 2\n  apply (metis PCR.simps(9) assms(4) pre_R_def)\n  using R_read_to_release_lemma_case_1 [where s=s and s'=s']\n  using assms(1) assms(2) apply fastforce\n  apply(subgoal_tac \"case_2 s\") prefer 2\n    apply blast\n   apply(thin_tac \"\\<not>case_1 s\") \n  apply(subgoal_tac \"case_2 s'\")\n  apply force\n  using R_read_to_release_lemma_case_2 [where s=s and s'=s']\n  apply (metis PCR.simps(9) assms(1) assms(2) assms(4) pre_R_def)\n  using R_read_to_release_lemma_2 [where s=s and s'=s']\n  by (metis PCR.simps(9) assms(1) assms(2) assms(4) pre_R_def)\n\n\nlemma R_step_preserves_inv:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"inv s'\"\n  using assms apply(case_tac \"pcR s\") \n  using R_local_release_lemma [where s=s and s'=s'] apply blast           (*done*)\n  using R_local_idle_lemma [where s=s and s'=s'] apply blast           (*done, check preliminaries*)\n  using R_local_read_lemma [where s=s and s'=s'] by blast           (*done*)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n(*******************************Local R pre post lemmas*************************************)\nlemma R_local_release_pre_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcR s = Release\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"pre_R (pcR s') s'\"\n  using assms apply(simp add:pre_R_def) apply clarify\n  apply(subgoal_tac \"ownT s' \\<noteq> R\") prefer 2 \n  apply(simp add:pre_dequeue_inv_def)\n  apply(simp add:cR_step_def)\n  apply(subgoal_tac \"ownT s = R\") prefer 2 \n  apply(simp add:pre_Release_inv_def)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"tR s = fst(tempR s)\") apply simp_all\n  apply(simp add:pre_dequeue_inv_def)\n   apply(intro conjI impI)\n  apply(simp add:pre_Release_inv_def)\n  apply(simp add:pre_Release_inv_def)\n  apply(simp add:pre_Release_inv_def tempR_lemmas tempR_basic_lemmas)\n  apply(simp add:inv_def Q_lemmas Q_basic_lemmas)\n  apply(subgoal_tac \"hd(q s)\\<in>set(q s)\") prefer 2 \n  apply (metis hd_in_set)\n  apply(subgoal_tac \"fst(q s!0) = 0\") prefer 2 \n  apply (metis hd_conv_nth)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(case_tac \"case_1 s \") apply simp apply(simp add:case_1_def)\n  apply (metis diff_self_eq_0 le_neq_implies_less length_pos_if_in_set less_nat_zero_code)\n  apply(simp) apply(thin_tac \"\\<not> case_1 s\") apply(simp add:case_2_def)\n  apply(clarify)\n  apply(subgoal_tac \"e=f\") prefer 2\n  apply (metis gr_implies_not0 le_neq_implies_less)\n  apply(subgoal_tac \"(i<N \\<and> ownB s i = Q )\\<longrightarrow> i<ba\") prefer 2 \n  apply (metis (mono_tags, hide_lams) F.distinct(11) F.distinct(19) F.distinct(21) F.distinct(3) diff_is_0_eq neq0_conv zero_less_diff)\n  apply(subgoal_tac \"aa=0\") prefer 2\n  apply (metis gr_implies_not0)\n  apply(subgoal_tac \"a+b\\<le>ba\")\n  apply (metis (no_types, lifting) Suc_le_eq le_add1 le_trans not_less_eq_eq)\n  apply(subgoal_tac \"(a\\<le>i \\<and> i<a+b) \\<longrightarrow> (ownB s i = Q)\") prefer 2\n  apply (metis (no_types, lifting) mem_Collect_eq)\n  apply(subgoal_tac \"a = i\\<longrightarrow> ownB s i = Q\") prefer 2\n  apply (metis le_refl less_add_same_cancel1)\n  apply(subgoal_tac \"fst(tempR s) = T s \\<longrightarrow> ownB s (T s) =R\") prefer 2\n  apply (metis gr_implies_not0 le_refl)\n  apply(subgoal_tac \"T s > ba\") prefer 2\n  apply (metis le0 less_nat_zero_code nat_neq_iff)\n  apply(subgoal_tac \"a=i\\<longrightarrow>i<ba\") prefer 2 \n  apply (metis (no_types, lifting) F.distinct(23) le_add1 le_neq_implies_less le_trans)\n  apply(subgoal_tac \"a+b-1 = i \\<longrightarrow>ownB s i=Q\") prefer 2\n  apply (metis Suc_diff_1 add_gr_0 lessI less_Suc_eq_le less_add_same_cancel1)\n  apply(subgoal_tac \"\\<nexists>i.(i\\<ge>ba \\<and> ownB s i = Q \\<and> i\\<le>N)\") prefer 2 \n  apply (metis (no_types, hide_lams) F.distinct(11) F.distinct(19) F.distinct(21) F.distinct(23) F.distinct(3) bot_nat_0.not_eq_extremum diff_diff_cancel diff_is_0_eq diff_self_eq_0 zero_less_diff)\n  apply(subgoal_tac \"a=i \\<and> ownB s i = Q \\<longrightarrow> i<ba\") prefer 2\n  apply meson\n  defer defer\n  apply(simp add:pre_dequeue_inv_def)\n  apply(intro conjI impI)\n  apply(simp add:pre_Release_inv_def)\n  apply(simp add:pre_Release_inv_def)\n  apply(simp add:pre_Release_inv_def tempR_lemmas tempR_basic_lemmas)\n  apply(simp add:inv_def Q_lemmas Q_basic_lemmas)\n  apply(subgoal_tac \"fst(hd(q s)) = 0\") prefer 2 \n  apply blast\n  apply(case_tac \"case_1 s\") apply(simp) apply(simp add:case_1_def)\n  apply metis\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis head_q0 length_greater_0_conv)\n  prefer 3 \n  apply(simp add:inv_def)\n  apply(case_tac \"case_1 s\") apply(simp) apply(simp add:case_1_def pre_Release_inv_def)\n  apply(simp add:inv_def Q_lemmas Q_basic_lemmas)\n  apply(simp add:pre_Release_inv_def tempR_lemmas tempR_basic_lemmas) \n  apply(simp add:Q_indices_def Q_owns_bytes_def ran_indices_def)\n  apply(clarify) apply(intro conjI impI)\n  apply (metis (no_types, lifting) bot_nat_0.extremum_uniqueI diff_self_eq_0 le_neq_implies_less length_0_conv)\n  apply(subgoal_tac \"hd(q s) \\<in> set(q s)\") prefer 2\n  apply (metis hd_in_set)\n  apply(subgoal_tac \"i\\<le>N\") prefer 2\n  apply (metis (no_types, lifting) le_trans less_or_eq_imp_le prod.collapse)\n  apply(subgoal_tac \"\\<forall>i. (\\<exists>x. (\\<exists>a b. x = {i. a \\<le> i \\<and> i < a + b} \\<and> (a, b) \\<in> set (q s)) \\<and> i \\<in> x) = (i \\<le> N \\<and> ownB s i = Q)\") prefer 2 apply blast\n  apply(subgoal_tac \"\\<forall>a b i.((a,b)\\<in>set(q s) \\<and> i\\<ge>a \\<and> i<a+b) \\<longrightarrow> ownB s i=Q\") prefer 2 \n  apply (metis (no_types, lifting) mem_Collect_eq)\n  apply (metis (no_types, lifting) prod.collapse)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply(simp add:case_1_def pre_Release_inv_def)\n  apply(simp add:inv_def Q_lemmas Q_basic_lemmas)\n  apply(simp add:pre_Release_inv_def tempR_lemmas tempR_basic_lemmas) \n  apply(simp add:Q_indices_def Q_owns_bytes_def ran_indices_def)\n  apply(clarify) apply(intro conjI impI) \n  apply(subgoal_tac \"\\<forall>i. (\\<exists>x. (\\<exists>a b. x = {i. a \\<le> i \\<and> i < a + b} \\<and> (a, b) \\<in> set (q s)) \\<and> i \\<in> x) = (i \\<le> N \\<and> ownB s i = Q)\") prefer 2 apply blast\n  apply(subgoal_tac \"hd(q s) \\<in> set(q s)\") prefer 2\n  apply (metis hd_in_set)\n  apply(subgoal_tac \"a = 0\") prefer 2 \n  apply (metis less_nat_zero_code)\n  apply(case_tac \"fst(hd(q s)) = e\") \n  apply (metis gr_implies_not0)\n  apply(subgoal_tac \"fst(hd(q s)) = 0\") prefer 2\n  apply metis\n  apply(subgoal_tac \"b\\<le>H s\") prefer 2\n  apply fastforce\n  apply(subgoal_tac \"H s< T s\") prefer 2\n  apply fastforce\n  apply(subgoal_tac \"b< T s\") prefer 2\n  apply (metis le0 le_refl less_nat_zero_code nat_neq_iff)\n  apply(subgoal_tac \"i\\<ge>end(hd(q s))\") \n  apply (metis Suc_leI end_simp not_less_eq_eq)\n  apply(subgoal_tac \"e = f\") prefer 2 \n  apply (metis le_neq_implies_less)\n  apply(subgoal_tac \"\\<forall>a b i.((a,b)\\<in>set(q s) \\<and> i\\<ge>a \\<and> i<a+b) \\<longrightarrow> ownB s i=Q\") prefer 2 \n  apply (metis (no_types, lifting) mem_Collect_eq)\n  apply(subgoal_tac \"i\\<ge>T s\") prefer 2\n  apply (metis less_Suc_eq_le not_less_eq)\n  apply(subgoal_tac \"\\<forall>i.(i\\<ge>a \\<and> i<end(hd(q s))) \\<longrightarrow> ownB s i = Q\")\n  prefer 2 \n  apply (metis (no_types, lifting) end_simp prod.collapse)\n  apply (metis F.distinct(11) less_Suc_eq_le not_less_eq)\n  apply(subgoal_tac \"\\<forall>a b i.((a,b)\\<in>set(q s) \\<and> i\\<ge>a \\<and> i<a+b) \\<longrightarrow> ownB s i=Q\") prefer 2 \n  apply (metis (no_types, lifting) mem_Collect_eq)\n  apply (metis (no_types, lifting) list.set_sel(1) prod.collapse)\n  apply(simp add:inv_def)\n  apply(case_tac \"case_1 s\") apply simp \n  apply(simp add:case_1_def pre_Release_inv_def)\n  apply(simp add:inv_def Q_lemmas Q_basic_lemmas)\n  apply(simp add:pre_Release_inv_def tempR_lemmas tempR_basic_lemmas) \n  apply(simp add:Q_indices_def Q_owns_bytes_def ran_indices_def)\n  apply metis\n  apply(simp add:case_2_def pre_Release_inv_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply(simp add:inv_def Q_lemmas Q_basic_lemmas)\n  apply(simp add:pre_Release_inv_def tempR_lemmas tempR_basic_lemmas) \n  apply(simp add:Q_indices_def Q_owns_bytes_def ran_indices_def)\n  apply(clarify)\n  apply(intro conjI impI)\n  apply(subgoal_tac \"\\<forall>a b i.((a,b)\\<in>set(q s) \\<and> i\\<ge>a \\<and> i<a+b) \\<longrightarrow> ownB s i=Q\") prefer 2 \n  apply (metis (no_types, lifting) mem_Collect_eq)\n  apply (metis (no_types, hide_lams) F.distinct(21) less_imp_Suc_add list.set_sel(1) nat.distinct(1) nat_less_le prod.exhaust_sel)\n  apply (metis head_q0 length_greater_0_conv)\n  apply(subgoal_tac \"\\<forall>a b i.((a,b)\\<in>set(q s) \\<and> i\\<ge>a \\<and> i<a+b) \\<longrightarrow> ownB s i=Q\") prefer 2 \n  apply (metis (no_types, lifting) mem_Collect_eq)\n  apply (metis (no_types, lifting) list.set_sel(1) prod.collapse)\n  apply(subgoal_tac \"\\<forall>a b i.((a,b)\\<in>set(q s) \\<and> i\\<ge>a \\<and> i<a+b) \\<longrightarrow> ownB s i=Q\") prefer 2 \n  apply (metis (no_types, lifting) mem_Collect_eq)\n  apply(subgoal_tac \"aa=0\") prefer 2\n  apply blast\n  apply(subgoal_tac \"\\<forall>a b.((a,b)\\<in>set(q s)) \\<longrightarrow> a+b\\<le>N\") prefer 2\n  apply meson\n  apply(subgoal_tac \"\\<forall>a b i.((a,b)\\<in>set(q s) \\<and> i\\<ge>a \\<and> i<a+b) \\<longrightarrow> ownB s i=Q\") prefer 2 \n  apply (metis (no_types, lifting) mem_Collect_eq)\n  apply(subgoal_tac \"\\<forall>j.(a\\<le>j \\<and> j<b+a) \\<longrightarrow> ownB s j = Q\") prefer 2\n  apply (metis add.commute)\n  by (metis (no_types, hide_lams) Suc_eq_plus1 add_diff_inverse_nat add_leD1 diff_add_inverse2 diff_le_self less_eq_Suc_le zero_less_diff)\n\n\n\n\nlemma R_local_idle_pre_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcR s = idleR\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"pre_R (pcR s') s'\"\n  using assms apply(simp add:pre_R_def) apply clarify\n  apply(case_tac \"q s=[]\") \n  using cR_step_def apply auto[1] apply(subgoal_tac \"ownT s = Q\") prefer 2 \n  apply(simp add:pre_dequeue_inv_def)\n  apply(simp add:cR_step_def)\n  apply(simp add:pre_Read_inv_def)\n  apply(intro conjI impI)\n  apply(simp add:inv_def)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:pre_dequeue_inv_def)\n  apply (metis add_cancel_right_right head_q0 length_greater_0_conv)\n  apply(simp add:inv_def)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:pre_dequeue_inv_def)\n  apply (metis add_cancel_right_right head_q0 length_greater_0_conv)\n  apply(simp add:inv_def)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:pre_dequeue_inv_def)\n  apply (metis diff_is_0_eq' le_trans length_0_conv not_less_eq_eq)\n  apply(simp add:inv_def)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:pre_dequeue_inv_def)\n  apply(simp add:inv_def)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:pre_dequeue_inv_def)\n  apply (metis diff_is_0_eq' length_0_conv not_less_eq_eq)\n  apply(simp add:inv_def)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:pre_dequeue_inv_def)\n  apply (metis length_greater_0_conv plus_nat.add_0)\n  apply(simp add:inv_def)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:pre_dequeue_inv_def)\n  apply (metis hd_in_set less_nat_zero_code)\n  apply(simp add:inv_def)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:pre_dequeue_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply(intro conjI impI) \n  apply(subgoal_tac \"(\\<forall>i. i < length (q s) \\<and> 0 < i \\<longrightarrow>\n         fst (q s ! (i - Suc 0)) + snd (q s ! (i - Suc 0)) = fst (q s ! i) \\<or> fst (q s ! i) = 0)\") prefer 2\n  apply presburger\n  apply(subgoal_tac \"fst(hd(q s)) = fst(q s!0)\") prefer 2\n  apply (metis Q_ind_imp_tail_ind_1)\n  apply(subgoal_tac \"fst(hd(tl(q s))) = fst(q s!1)\") prefer 2 \n  apply (metis One_nat_def hd_conv_nth length_greater_0_conv nth_tl)\n  apply (metis (no_types, lifting) One_nat_def Q_ind_imp_tail_ind_1 diff_Suc_1 length_greater_0_conv length_tl less_one zero_less_diff)\n  apply(subgoal_tac \"fst(hd(q s)) = fst(q s!0)\") prefer 2\n  apply (metis Q_ind_imp_tail_ind_1)\n  apply(subgoal_tac \"fst(hd(tl(q s))) = fst(q s!1)\") prefer 2 \n  apply (metis One_nat_def hd_conv_nth length_greater_0_conv nth_tl)\n  apply (metis (no_types, lifting) One_nat_def Suc_eq_plus1 Suc_neq_Zero length_greater_0_conv length_tl less_diff_conv nth_tl)\n  apply(subgoal_tac \"fst(hd(q s)) = fst(q s!0)\") prefer 2\n  apply (metis Q_ind_imp_tail_ind_1)\n  apply(subgoal_tac \"fst(hd(tl(q s))) = fst(q s!1)\") prefer 2 \n  apply (metis One_nat_def hd_conv_nth length_greater_0_conv nth_tl)\n  apply(subgoal_tac \"i<length(q s) - Suc 0 \\<longrightarrow> (tl (q s) ! i )\\<in>set (q s)\") prefer 2\n  apply (metis One_nat_def length_tl list.set_sel(2) nth_mem)\n  apply(subgoal_tac \"(hd (q s))\\<in>set (q s)\") prefer 2\n  apply (metis hd_in_set)\n  apply simp apply clarify\n  apply (intro conjI impI) apply(subgoal_tac \"snd(hd(q s)) = snd(q s!0)\") prefer 2 \n  apply (metis Q_ind_imp_tail_ind_1) apply simp \n  apply(subgoal_tac \"\\<forall>a b aa. (a, b) \\<in> set (q s) \\<and> (\\<exists>b. (aa, b) \\<in> set (q s)) \\<longrightarrow> a < aa \\<longrightarrow> a + b \\<le> aa\") prefer 2\n  apply blast\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s) -1)\\<longrightarrow>(tl(q s)!i)\\<in>set(q s)\") prefer 2\n  apply (metis length_tl list.set_sel(2) nth_mem)\n  apply(subgoal_tac \"tl(q s)!ia \\<in>set(q s)\") prefer 2\n  apply (metis One_nat_def)\n  apply(subgoal_tac \"fst(tl(q s)!ia) >fst(hd(q s))\") prefer 2\n  apply presburger\n  apply (metis (no_types, lifting) list.set_sel(1) prod.collapse)\n  apply(subgoal_tac \"\\<forall>a b aa. (a, b) \\<in> set (q s) \\<and> (\\<exists>b. (aa, b) \\<in> set (q s)) \\<longrightarrow> a < aa \\<longrightarrow> a + b \\<le> aa\") prefer 2\n  apply blast\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s) -1)\\<longrightarrow>(tl(q s)!i)\\<in>set(q s)\") prefer 2\n  apply (metis length_tl list.set_sel(2) nth_mem)\n  apply(subgoal_tac \"tl(q s)!ia \\<in>set(q s)\") prefer 2\n  apply (metis One_nat_def)\n  apply(subgoal_tac \"fst(tl(q s)!ia) <fst(hd(q s))\") prefer 2\n  apply presburger\n  apply (metis (no_types, lifting) list.set_sel(1) prod.collapse)\n  apply(subgoal_tac \"hd(q s)\\<in>set(q s)\") prefer 2 \n  apply (metis hd_in_set)\n  apply(subgoal_tac \"last (tl (q s))\\<in>set(q s)\") prefer 2\n  apply (metis last_in_set last_tl) \n  apply (metis fst_conv last_tl surj_pair)\n  apply (metis Nat.add_0_right hd_conv_nth length_greater_0_conv)\n  apply (metis add_cancel_right_right head_q0 length_greater_0_conv) defer\n  apply(simp add:inv_def)\n  apply(case_tac \"case_1 s\") apply(simp) apply(simp add:case_1_def) \n  apply (metis bot_nat_0.extremum_uniqueI bot_nat_0.not_eq_extremum diff_is_0_eq' length_greater_0_conv)\n  apply(simp) apply(thin_tac \"\\<not> case_1 s\") apply(simp add:case_2_def)\n  apply meson\n  apply(simp add:inv_def)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(subgoal_tac \"hd(q s)\\<in>set(q s)\") prefer 2 \n  apply (metis hd_in_set) \n  apply(case_tac \"case_1 s\") apply simp apply(simp add:case_1_def)\n  apply(simp add:pre_dequeue_inv_def)\n  apply (metis F.distinct(13) bot_nat_0.extremum_uniqueI diff_self_eq_0 le_neq_implies_less length_0_conv)\n  apply simp apply(thin_tac \"\\<not>case_1 s\")  apply(simp add:case_2_def)\n  apply(simp add:pre_dequeue_inv_def)\n  by (metis diff_self_eq_0 fst_conv le0 le_trans length_greater_0_conv nat_less_le plus_nat.add_0 snd_conv)\n\n\n\n\nlemma R_local_read_pre_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pcR s = Read\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"pre_R (pcR s') s'\"\n  using assms apply(simp add:pre_R_def) apply clarify\n  apply(simp add:cR_step_def)\n  apply(simp add:pre_Release_inv_def)\n  apply(intro conjI impI)\n  apply(simp add:pre_Read_inv_def)\n  apply(simp add:pre_Read_inv_def)\n  apply(simp add:inv_def) apply(simp add:Q_lemmas Q_basic_lemmas) apply(subgoal_tac \"hd(q s)\\<in>set(q s)\")\n  prefer 2 \n  apply (meson list.set_sel(1))\n  apply (metis Nat.add_0_right hd_conv_nth length_pos_if_in_set)\n  apply(simp add:pre_Read_inv_def)\n  apply(simp add:pre_Read_inv_def)\n  apply(simp add:pre_Read_inv_def)\n  apply(simp add:pre_Read_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply(intro conjI impI)\n  apply(simp add:pre_Read_inv_def tempR_lemmas tempR_basic_lemmas)\n  apply(simp add:pre_Read_inv_def tempR_lemmas tempR_basic_lemmas)\n  apply(subgoal_tac \"snd (tempR s) = Data s (numDeqs s - Suc 0)\") prefer 2\n  apply blast\n  apply metis\n  apply(simp add:pre_Read_inv_def tempR_lemmas tempR_basic_lemmas)\n  apply(simp add:pre_Read_inv_def tempR_lemmas tempR_basic_lemmas)\n  apply(subgoal_tac \"snd (tempR s) = Data s (numDeqs s - Suc 0)\") prefer 2\n  apply blast \n  apply force\n  apply(simp add:pre_Read_inv_def tempR_lemmas tempR_basic_lemmas)\n  apply(simp add:pre_Read_inv_def tempR_lemmas tempR_basic_lemmas)\n  apply(simp add:pre_Read_inv_def tempR_lemmas tempR_basic_lemmas)\n  apply(simp add:pre_Read_inv_def tempR_lemmas tempR_basic_lemmas)\n  apply(simp add:pre_Read_inv_def tempR_lemmas tempR_basic_lemmas)\n  apply(simp add:pre_Read_inv_def tempR_lemmas tempR_basic_lemmas)\n  apply(simp add:pre_Read_inv_def tempR_lemmas tempR_basic_lemmas)\n  by(simp add:pre_Read_inv_def tempR_lemmas tempR_basic_lemmas)\n\n\nlemma R_local_pre_lemma:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"pre_R (pcR s') s'\"\n  using assms apply(case_tac \"pcR s\") \n  using R_local_release_pre_lemma [where s=s and s'=s'] apply blast           (*done*)\n  using R_local_idle_pre_lemma [where s=s and s'=s'] apply blast           (*done*)\n  using R_local_read_pre_lemma [where s=s and s'=s'] by blast           (*done*)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n(*******************************GLOBAL W_step shows preR*************************************)\n\n\nlemma pcR_doesnt_change_with_W:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_R (pcR s) s\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"\nshows \"pcR s'=pcR s\"\n using assms apply simp\n  apply(case_tac \"pcW s \", simp add:cW_step_def)\n  apply(simp add:cW_step_def)\n  apply(simp add:cW_step_def)\n  apply(simp add:cW_step_def)\n  apply(simp add:cW_step_def)\n  apply(simp add:cW_step_def)\n  apply(simp add:cW_step_def)\n  apply(simp add:cW_step_def)\n  apply(simp add:cW_step_def)\n  apply(simp add:cW_step_def) apply(cases \"numEnqs s < n\") \n  apply(simp add:B_acquire_def) apply(simp add:B_acquire_def) \n  apply(simp add:cW_step_def) apply(cases \"tW s \\<noteq> T s\") \n  apply(simp add:cW_step_def) \n  apply(simp add:cW_step_def) \n  apply(simp add:cW_step_def) \n  apply(simp add:cW_step_def) \n  by(simp add:cW_step_def) \n\n\nlemma supporting_strange:\n  \"\\<forall>i<(length (q s)).\n       (fst (tempR s) < fst ((q s @ [(offset s, Data s (numEnqs s))]) ! i) \\<longrightarrow>\n        fst (tempR s) + snd (tempR s) \\<le> fst ((q s @ [(offset s, Data s (numEnqs s))]) ! i)) \\<and>\n       (fst ((q s @ [(offset s, Data s (numEnqs s))]) ! i) < fst (tempR s) \\<longrightarrow>\n        fst ((q s @ [(offset s, Data s (numEnqs s))]) ! i) +\n        snd ((q s @ [(offset s, Data s (numEnqs s))]) ! i)\n        \\<le> fst (tempR s)) \\<Longrightarrow> \n       (fst (tempR s) < fst ((offset s, Data s (numEnqs s))) \\<longrightarrow>\n        fst (tempR s) + snd (tempR s) \\<le> fst ((offset s, Data s (numEnqs s)))) \\<and>\n       (fst ((offset s, Data s (numEnqs s))) < fst (tempR s) \\<longrightarrow>\n        fst ((offset s, Data s (numEnqs s))) +\n        snd ((offset s, Data s (numEnqs s)))\n        \\<le> fst (tempR s))\n\\<Longrightarrow>\n \\<forall>i<Suc (length (q s)).\n       (fst (tempR s) < fst ((q s @ [(offset s, Data s (numEnqs s))]) ! i) \\<longrightarrow>\n        fst (tempR s) + snd (tempR s) \\<le> fst ((q s @ [(offset s, Data s (numEnqs s))]) ! i)) \\<and>\n       (fst ((q s @ [(offset s, Data s (numEnqs s))]) ! i) < fst (tempR s) \\<longrightarrow>\n        fst ((q s @ [(offset s, Data s (numEnqs s))]) ! i) +\n        snd ((q s @ [(offset s, Data s (numEnqs s))]) ! i)\n        \\<le> fst (tempR s))\"\n  by (metis less_SucE nth_append_length)\n\n\n\nlemma preRead_doesnt_change_with_W:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_Read_inv s\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"\nshows \"pre_Read_inv s'\"\n  using assms apply simp\n  apply(simp add:pre_Read_inv_def) \n  apply(intro conjI impI)\n  apply(simp add:pre_W_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply(cases \"pcW s\", simp_all)\n  apply(simp_all add:cW_step_def)\n  apply(cases \"numEnqs s<n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(simp add:pre_W_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply(cases \"pcW s\", simp_all)\n  apply(cases \"numEnqs s<n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(simp add:pre_write_inv_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:inv_def)\n  apply (metis F.distinct(1) eq_imp_le fst_eqD less_add_same_cancel1 snd_eqD)\n  apply(cases \"pcW s\", simp_all)\n  apply(cases \"numEnqs s<n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all)\n  apply(cases \"numEnqs s<n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all)\n  apply(cases \"numEnqs s<n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all)\n  apply(cases \"numEnqs s<n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all)\n  apply(cases \"numEnqs s<n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all)\n  apply(cases \"numEnqs s<n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all)\n  apply metis\n  apply(case_tac \"tW s = hW s \\<and> Data s (numEnqs s) \\<le> N\", simp_all)\n  apply metis\n  apply(case_tac \" hW s < tW s \\<and> Data s (numEnqs s) < tW s - hW s\", simp_all, metis)\n  apply(case_tac \"tW s < hW s\", simp_all, metis, metis, metis, metis)\n  apply(case_tac \" Data s (numEnqs s) \\<le> N - hW s\", simp_all, metis)\n  apply(case_tac \" Data s (numEnqs s) < tW s\", simp_all, metis, metis, metis, metis, metis, metis)\n  apply(case_tac \"numEnqs s < n\", simp_all, metis, metis)\n  apply(cases \"tW s \\<noteq> T s\", simp_all, metis, metis, metis, metis, metis)\n  apply(case_tac \"pcW s\", simp_all add:cW_step_def)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)  \n  apply(cases \"pcW s\", simp_all) \n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply metis\n  apply(case_tac \" tW s = hW s \\<and> Data s (numEnqs s) \\<le> N\", simp_all) \n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply metis\n  apply(case_tac \"hW s < tW s \\<and> Data s (numEnqs s) < tW s - hW s\", simp_all)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply metis\n  apply(case_tac \"tW s < hW s\", simp_all)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply metis\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply metis\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply(intro conjI impI)\n  apply metis\n  apply (metis (no_types, lifting))\n  apply(simp add:pre_W_def pre_A3_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply(intro conjI impI)\n  apply metis\n  apply (metis (no_types, lifting))\n  apply(simp add:pre_W_def pre_A4_inv_def)\n  apply (metis (no_types, lifting) F.distinct(13) Suc_lessD add.commute less_diff_conv less_trans_Suc)\n  apply(case_tac \" Data s (numEnqs s) \\<le> N - hW s\", simp_all)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply(simp add:pre_W_def pre_A5_inv_def)\n  apply metis\n  apply(case_tac \"Data s (numEnqs s) < tW s\", simp_all)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply(simp add:pre_W_def pre_A5_inv_def)\n  apply metis\n  apply(simp add:pre_W_def pre_A5_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply metis\n  apply(simp add:pre_W_def pre_A6_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply(intro conjI impI)\n  apply metis\n  apply (metis (no_types, lifting))\n  apply (metis (mono_tags, hide_lams) F.distinct(13) le_trans less_or_eq_imp_le nat_neq_iff)\n  apply(simp add:pre_W_def pre_A7_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply(intro conjI impI)\n  apply metis\n  apply (metis (no_types, lifting))\n  apply(clarify)\n  apply(intro conjI impI)\n  apply (metis F.distinct(13) Suc_lessD less_trans_Suc)\n  apply (metis (mono_tags, hide_lams) F.distinct(13) le_trans less_or_eq_imp_le linorder_neqE_nat)\n  apply(case_tac \"N < Data s (numEnqs s)\", simp_all)\n  apply(simp add:pre_W_def pre_A8_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply metis\n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply metis\n  apply(simp add:pre_W_def pre_A8_inv_def)  defer\n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(simp add:pre_W_def pre_acquire_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply metis\n  apply(simp add:pre_W_def pre_acquire_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply metis\n  apply(simp add:pre_W_def pre_OOM_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply metis\n  apply metis\n  apply(simp add:pre_W_def pre_write_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply (metis (no_types, lifting) F.distinct(1) Nat.add_0_right eq_imp_le fst_eqD nat_add_left_cancel_less snd_eqD)\n  defer\n  defer\n  defer \n  apply(simp add:pre_W_def pre_enqueue_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply(intro conjI impI)\n  apply(simp add: tempW_def)\n  apply(case_tac \"q s\\<noteq>[]\") \n  apply (metis (no_types, hide_lams) hd_append2)\n  apply(subgoal_tac \"q s=[]\") prefer 2 \n  apply force\n  apply(subgoal_tac \"tempR s \\<noteq>(0,0)\") prefer 2 \n  apply blast\n  apply(case_tac \"offset s = 0\")\n  apply (metis append_Nil fst_conv list.sel(1))\n  apply(simp add:inv_def)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply clarify \n  apply(subgoal_tac \"c=b\") prefer 2 \n  apply (metis le_neq_implies_less)\n  apply(subgoal_tac \"end(tempR s) = b\") prefer 2 \n  apply (metis end_simp le_add_diff_inverse)\n  apply(subgoal_tac \"offset s = hW s\") prefer 2\n  apply meson \n  apply(subgoal_tac \"i\\<ge>c \\<and> i<H s \\<longrightarrow>ownB s i = W\") prefer 2\n  apply metis\n  apply(subgoal_tac \"H s\\<le>N\") prefer 2 \n  apply metis\n  apply(subgoal_tac \"(i<c \\<or> i\\<ge>H s \\<and> i\\<le>N) \\<longrightarrow>ownB s i\\<noteq>W\") prefer 2 \n  apply (metis F.distinct(1) F.distinct(5) bot_nat_0.not_eq_extremum diff_is_0_eq zero_less_diff)\n  apply (metis F.distinct(1) add_leD1 end_simp le_eq_less_or_eq linorder_neqE_nat nat_less_le)  \n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\") \n  apply clarify \n  apply (metis eq_imp_le le_add1 le_neq_implies_less plus_nat.add_0)\n  apply(simp add: tempW_def)\n  apply(case_tac \"q s=[]\")\n  apply (metis (no_types, lifting) F.distinct(1) Nat.add_0_right Suc_le_lessD Suc_lessD Suc_pred add_lessD1 fst_eqD le_add_diff_inverse less_Suc0 less_Suc_eq_le less_add_same_cancel1 list.size(3) nat_add_left_cancel_le nth_Cons_0 self_append_conv2)\n  apply(subgoal_tac \"q s\\<noteq>[]\") prefer 2 \n  apply blast\n  apply(subgoal_tac \"\\<forall>i<length (q s). fst ((q s) ! i) \\<noteq> fst (tempR s)\") prefer 2\n  apply presburger\n  apply(subgoal_tac \"fst((offset s, Data s (numEnqs s))) \\<noteq> fst(tempR s)\") \n  apply (metis less_SucE nth_append nth_append_length)\n  apply(subgoal_tac \"offset s \\<noteq> fst(tempR s)\") prefer 2 \n  apply (metis (no_types, lifting) F.distinct(1) Suc_le_lessD Suc_lessD Suc_pred add_lessD1 le_add_diff_inverse le_refl less_add_same_cancel1)\n  apply(case_tac \"case_1 s\", simp_all) \n  apply(subgoal_tac \"Data s (numReads s) = snd(tempR s)\") prefer 2 \n  apply presburger\n  apply(subgoal_tac \"Data s (numDeqs s - Suc 0) = snd(tempR s)\") prefer 2\n  apply presburger \n  apply(simp add:inv_def Q_lemmas Q_basic_lemmas)\n  apply(subgoal_tac \"\\<forall>i<length (q s).\n       (fst (tempR s) < fst ((q s ) ! i) \\<longrightarrow>\n        fst (tempR s) + Data s (numDeqs s - Suc 0) \\<le> fst ((q s ) ! i)) \\<and>\n       (fst ((q s) ! i) < fst (tempR s) \\<longrightarrow>\n        fst ((q s) ! i) + snd ((q s ) ! i)\n        \\<le> fst (tempR s))\")\n       prefer 2 \n  apply (metis (no_types, lifting) gr_implies_not0 length_0_conv)\n  apply(subgoal_tac \"(fst (tempR s) < fst(offset s, Data s (numEnqs s)) \\<longrightarrow>\n        fst (tempR s) + Data s (numDeqs s - Suc 0) \\<le> fst(offset s, Data s (numEnqs s))) \\<and>\n       (fst(offset s, Data s (numEnqs s)) < fst (tempR s) \\<longrightarrow>\n        fst(offset s, Data s (numEnqs s)) +\n        snd(offset s, Data s (numEnqs s))\n        \\<le> fst (tempR s))\") \n  apply(subgoal_tac \"((q s @ [(offset s, Data s (numEnqs s))]) ! length (q s)) = (offset s, Data s (numEnqs s))\") prefer 2 \n  apply (metis nth_append_length)\n  apply(subgoal_tac \"\\<forall>i<(length (q s)).\n       (fst (tempR s) < fst ((q s @ [(offset s, Data s (numEnqs s))]) ! i) \\<longrightarrow>\n        fst (tempR s) + snd (tempR s) \\<le> fst ((q s @ [(offset s, Data s (numEnqs s))]) ! i)) \\<and>\n       (fst ((q s @ [(offset s, Data s (numEnqs s))]) ! i) < fst (tempR s) \\<longrightarrow>\n        fst ((q s @ [(offset s, Data s (numEnqs s))]) ! i) +\n        snd ((q s @ [(offset s, Data s (numEnqs s))]) ! i)\n        \\<le> fst (tempR s))\") prefer 2 \n  apply (metis (no_types, hide_lams) nth_append)\n  using supporting_strange [where s=s] \n  apply presburger\n  apply(intro conjI impI)\n  apply (metis (no_types, lifting) Nat.add_0_right fst_eqD le_eq_less_or_eq less_add_same_cancel1 less_nat_zero_code nat_neq_iff snd_eqD tempW_def)\n  apply(simp add:inv_def)\n  apply(case_tac \"case_1 s\", simp_all) apply (simp add:case_1_def)\n  apply(clarify)\n  apply (metis (no_types, lifting) F.distinct(1) diff_is_0_eq le_refl less_imp_le_nat not_gr0 prod.collapse prod.inject tempW_def zero_less_diff)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\") \n  apply clarify\n  apply (metis less_or_eq_imp_le zero_less_iff_neq_zero)\n  apply(simp add: tempW_def)\n  apply(subgoal_tac \"fst((offset s, Data s (numEnqs s))) + snd((offset s, Data s (numEnqs s)))  \\<noteq> fst(tempR s)\")\n  apply (metis fst_eqD snd_eqD)\n  apply(subgoal_tac \"offset s \\<noteq> fst(tempR s)\") prefer 2 \n  apply (metis (no_types, lifting) F.distinct(1) Suc_le_lessD Suc_lessD Suc_pred add_lessD1 le_add_diff_inverse le_refl less_add_same_cancel1)\n  apply(simp add:inv_def)\n  apply(case_tac \"case_1 s\", simp_all)\n  apply(simp add:case_1_def)\n  apply(clarify)\n  apply linarith\n  apply(simp add:case_2_def) apply (thin_tac \"\\<not>case_1 s\") \n  apply(clarify)\n  apply (metis add_gr_0 nat_neq_iff)\n  apply(case_tac \"pcW s\", simp_all add:inv_def)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply(simp add:pre_W_def pre_A3_inv_def)\n  apply(simp add:case_2_def)\n  apply(simp add:pre_W_def pre_A3_inv_def)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply(simp add:pre_W_def pre_A4_inv_def)\n  apply (metis (no_types, lifting) le_add_diff_inverse le_eq_less_or_eq less_trans_Suc not_less_eq_eq)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not> case_1 s\")\n  apply(simp add:pre_W_def pre_A4_inv_def) \n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply(clarify)\n  apply(subgoal_tac \"fst(tempR s) = 0 \\<or> fst(tempR s) = T s\") prefer 2\n  apply meson\n  apply(case_tac \"fst(tempR s) = T s\")\n  apply(subgoal_tac \"hW s = b\") prefer 2 \n  apply (metis le_imp_less_Suc le_refl le_trans not_less_less_Suc_eq)\n  apply(subgoal_tac \"T s > hW s + Data s (numEnqs s)\") prefer 2 \n  apply(subgoal_tac \"ownB s (T s) = R\") prefer 2\n  apply (metis gr_implies_not0 le_refl)\n  apply(subgoal_tac \"tW s = T s\") prefer 2\n  apply (metis (no_types, lifting) add.commute le_trans less_diff_conv nat_less_le)\n  apply(subgoal_tac \"Data s (numEnqs s) < (tW s - hW s)\") prefer 2 \n  apply fastforce\n  apply (metis add.commute less_diff_conv)\n  apply (metis Suc_leI le_trans less_or_eq_imp_le not_less_eq_eq)\n  apply(subgoal_tac \"fst(tempR s) = 0\") prefer 2\n  apply fastforce\n  apply(subgoal_tac \"end(tempR s) = a\") prefer 2 \n  apply (metis add_cancel_left_left end_simp)\n  apply(subgoal_tac \"hW s\\<ge>a\") prefer 2 \n  apply (metis le_trans)\n  apply (metis Suc_leI end_simp le_trans not_less_eq_eq)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply(simp add:pre_W_def pre_A6_inv_def) \n  apply (metis le_add_diff_inverse le_trans less_or_eq_imp_le)\n  apply(simp add:case_2_def)\n  apply(simp add:pre_W_def pre_A6_inv_def)\n  apply (metis Suc_leI not_less_eq_eq)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply(simp add:pre_W_def pre_A7_inv_def) \n  apply clarify\n  apply(intro conjI impI)\n  apply linarith\n  apply (metis le_add_diff_inverse le_trans less_or_eq_imp_le)\n  apply(simp add:case_2_def)\n  apply(simp add:pre_W_def pre_A7_inv_def)\n  apply clarify\n  apply(intro conjI impI)\n  apply linarith\n  apply (metis Suc_leI not_less_eq_eq)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  prefer 2\n  apply(case_tac \"pcW s\", simp_all)\n  apply(simp add:pre_W_def pre_A3_inv_def)\n  apply(simp add:pre_W_def pre_A4_inv_def)\n  apply(simp add:pre_W_def pre_A6_inv_def)\n  apply(simp add:pre_W_def pre_A7_inv_def)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(case_tac \"pcW s \", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  by(case_tac \"tW s \\<noteq> T s\", simp_all)\n  \n\n\n\nlemma preIdleR_doesnt_change_with_W:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_dequeue_inv s\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"\nshows \"pre_dequeue_inv s'\"\n  using assms apply simp\n  apply(simp add:pre_dequeue_inv_def) \n  apply(intro conjI impI)\n  apply(simp add:pre_W_def)\n  apply(cases \"pcW s\", simp_all add:cW_step_def  B_acquire_def)\n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all add:cW_step_def  B_acquire_def)\n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all add:cW_step_def  B_acquire_def)\n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all add:cW_step_def  B_acquire_def)\n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all add:cW_step_def  B_acquire_def)\n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all add:cW_step_def  B_acquire_def pre_W_def)\n  apply(cases \"tW s = hW s \\<and> Data s (numEnqs s) \\<le> N\", simp_all)\n  apply(cases \"ownT s = Q\", simp_all)\n  apply(simp add:pre_A2_inv_def)\n  apply(cases \"hW s < tW s \\<and> Data s (numEnqs s) < tW s - hW s\", simp_all)\n  apply(cases \"tW s < hW s\", simp_all)\n  apply(cases \"Data s (numEnqs s) \\<le> N - hW s\", simp_all)\n  apply(cases \"Data s (numEnqs s) < tW s\", simp_all)\n  apply(cases \"N < Data s (numEnqs s)\", simp_all)\n  apply(cases \"ownT s = W\", simp_all add:pre_enqueue_inv_def inv_def)\n  apply(case_tac \"case_1 s\") apply simp apply(simp add:case_1_def)\n  apply (metis nat_less_le)\n  apply simp apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis nat_less_le)\n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all add:cW_step_def  B_acquire_def)\n  apply(cases \"tW s = hW s \\<and> Data s (numEnqs s) \\<le> N\", simp_all)\n  apply(cases \"ownT s = W\", simp_all add:pre_enqueue_inv_def inv_def)\n  apply(cases \"ownT s = W\", simp_all add:pre_A2_inv_def inv_def)\n  apply(cases \"hW s < tW s \\<and> Data s (numEnqs s) < tW s - hW s\", simp_all)\n  apply(cases \"tW s < hW s\", simp_all)\n  apply(simp add:pre_A3_inv_def)\n  apply(simp add:pre_A4_inv_def)\n  apply(simp add:pre_A5_inv_def)\n  apply(simp add:pre_A6_inv_def)\n  apply(simp add:pre_A7_inv_def)\n  apply(simp add:pre_A8_inv_def)\n  apply(cases \"N < Data s (numEnqs s)\", simp_all)\n  apply(simp add:pre_acquire_inv_def)\n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all) defer\n  apply(cases \"pcW s\", simp_all add:cW_step_def  B_acquire_def)\n  apply(cases \"tW s = hW s \\<and> Data s (numEnqs s) \\<le> N\", simp_all add:pre_enqueue_inv_def inv_def)\n  apply(cases \"ownT s = W\", simp_all add:pre_A2_inv_def inv_def)\n  apply(cases \"hW s < tW s \\<and> Data s (numEnqs s) < tW s - hW s\", simp_all)\n  apply(cases \"tW s < hW s\", simp_all)\n  apply(simp add:pre_A3_inv_def)\n  apply(simp add:pre_A4_inv_def)\n  apply (metis (no_types, lifting) F.distinct(19) add.commute add_lessD1 less_diff_conv less_imp_add_positive)\n  apply(simp add:pre_A5_inv_def)\n  apply(cases \"Data s (numEnqs s) \\<le> N - hW s\", simp_all)\n  apply(cases \"Data s (numEnqs s) < tW s\", simp_all)\n  apply(simp add:pre_A6_inv_def)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply clarify\n  apply(subgoal_tac \"offset s = hW s\") prefer 2\n  apply (metis (no_types, lifting) F.distinct(19) F.distinct(23) add_lessD1 diff_is_0_eq' le_0_eq le_eq_less_or_eq length_0_conv nat_le_iff_add)\n  apply (metis (no_types, lifting) F.distinct(19) add_lessD1 diff_self_eq_0 le_0_eq le_add_diff_inverse le_neq_implies_less length_0_conv)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\") \n  apply (metis Suc_leI not_less_eq_eq)\n  apply(simp add:pre_A7_inv_def) \n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply clarify\n  apply (metis (no_types, lifting) F.distinct(19) F.distinct(23) add_lessD1 diff_is_0_eq' le_0_eq le_eq_less_or_eq length_0_conv nat_le_iff_add)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\") \n  apply (metis Suc_leI not_less_eq_eq)\n  apply(simp add:pre_A8_inv_def)\n  apply(cases \"N < Data s (numEnqs s)\", simp_all)\n  apply(cases \"ownT s = W\", simp_all)\n  apply (metis fst_conv le_trans nat_less_le snd_conv tempW_def)\n  apply(simp add:Q_lemmas Q_basic_lemmas Q_indices_def Q_owns_bytes_def ran_indices_def)\n  apply(case_tac \"case_1 s\", simp_all)\n  apply(simp add:case_1_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(case_tac \"q s=[]\")\n  apply(subgoal_tac \"fst(hd (q s @ [(offset s, Data s (numEnqs s))])) = offset s\") prefer 2\n  apply (metis append_self_conv2 list.sel(1) old.prod.inject prod.collapse)\n  apply(subgoal_tac \"snd(hd (q s @ [(offset s, Data s (numEnqs s))])) = Data s (numEnqs s)\") prefer 2\n  apply (metis append_self_conv2 list.sel(1) old.prod.inject prod.collapse)\n  apply (metis le_trans less_imp_le_nat)\n  apply(subgoal_tac \"fst(hd (q s @ [(offset s, Data s (numEnqs s))])) = fst(hd(q s))\") prefer 2\n  apply (metis (no_types, lifting) hd_append2)\n  apply(subgoal_tac \"snd(hd (q s @ [(offset s, Data s (numEnqs s))])) = snd(hd(q s))\") prefer 2\n  apply (metis (no_types, lifting) hd_append2)\n  apply presburger\n  apply(simp add:case_2_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(case_tac \"q s=[]\")\n  apply(subgoal_tac \"fst(hd (q s @ [(offset s, Data s (numEnqs s))])) = offset s\") prefer 2\n  apply (metis append_self_conv2 list.sel(1) old.prod.inject prod.collapse)\n  apply(subgoal_tac \"snd(hd (q s @ [(offset s, Data s (numEnqs s))])) = Data s (numEnqs s)\") prefer 2\n  apply (metis append_self_conv2 list.sel(1) old.prod.inject prod.collapse)\n  apply (metis le_trans less_imp_le_nat)\n  apply(subgoal_tac \"fst(hd (q s @ [(offset s, Data s (numEnqs s))])) = fst(hd(q s))\") prefer 2\n  apply (metis (no_types, lifting) hd_append2)\n  apply(subgoal_tac \"snd(hd (q s @ [(offset s, Data s (numEnqs s))])) = snd(hd(q s))\") prefer 2\n  apply (metis (no_types, lifting) hd_append2)\n  apply presburger\n  apply(case_tac \"numEnqs s< n\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(case_tac \"pcW s\", simp_all)\n  apply(case_tac \"numEnqs s< n\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(case_tac \"pcW s\", simp_all)\n  apply(case_tac \"tW s = hW s \\<and> Data s (numEnqs s) \\<le> N\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)\n  apply(case_tac \" hW s < tW s \\<and> Data s (numEnqs s) < tW s - hW s \", simp_all)\n  apply(case_tac \"tW s < hW s\", simp_all)\n  apply(simp add:Q_lemmas Q_basic_lemmas Q_indices_def Q_owns_bytes_def ran_indices_def)\n  apply (simp add: pre_A3_inv_def)\n  apply(case_tac \" Data s (numEnqs s) \\<le> N - hW s\", simp_all)\n  apply(case_tac \"Data s (numEnqs s) < tW s\", simp_all)\n  apply(case_tac \"N < Data s (numEnqs s)\", simp_all)\n  apply(case_tac \"ownT s = W\", simp_all)\n  apply(simp add:Q_lemmas Q_basic_lemmas Q_indices_def Q_owns_bytes_def ran_indices_def)\n  apply(simp add:pre_enqueue_inv_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply clarify\n  apply (metis (no_types, hide_lams) Nat.add_0_right diff_is_0_eq le_refl nat_add_left_cancel_less nat_neq_iff zero_less_diff)\n  apply(simp add:case_2_def) \n  apply(simp add:Q_lemmas Q_basic_lemmas Q_indices_def Q_owns_bytes_def ran_indices_def)\n  apply(simp add:pre_enqueue_inv_def)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply clarify\n  apply (metis (no_types, hide_lams) diff_self_eq_0 fst_eqD hd_append le_zero_eq length_0_conv less_add_same_cancel1 less_or_eq_imp_le list.sel(1) nat_less_le snd_eqD tempW_def)\n  apply(simp add:case_2_def) \n  apply(subgoal_tac \"\\<forall>a b j.\n       ((a, b) \\<in> set (q s)) \\<and> j < N \\<and> T s \\<le> j \\<longrightarrow>\n       a + b < j\") prefer 2\n  apply (metis (no_types, lifting) hd_append length_greater_0_conv length_pos_if_in_set)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(subgoal_tac \"offset s + Data s (numEnqs s)<T s\") prefer 2 \n  apply force\n  apply(subgoal_tac \"\\<forall> j. T s \\<le> j \\<longrightarrow>\n       offset s + Data s (numEnqs s) < j\") prefer 2 \n  apply (metis (mono_tags, hide_lams) diff_is_0_eq le_trans nat_less_le zero_less_diff)\n  apply (metis (no_types, lifting))\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  by(case_tac \"tW s \\<noteq> T s\", simp_all)\n  \n\n\n\n\n\n\n\nlemma preRelease_doesnt_change_with_W:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_Release_inv s\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"\nshows \"pre_Release_inv s'\"\n  using assms apply simp\n  apply(simp add:pre_Release_inv_def) \n  apply(intro conjI impI)\n  apply(simp add:cW_step_def)\n  apply(cases \"pcW s\", simp_all) \n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(simp_all add:cW_step_def)\n  apply(cases \"pcW s\", simp_all) \n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(simp add:pre_W_def pre_write_inv_def)\n  apply (metis F.distinct(1) fst_eqD less_add_same_cancel1 nat_le_linear snd_eqD)\n  apply(cases \"pcW s\", simp_all) \n  apply(cases \"tW s = hW s \\<and> Data s (numEnqs s) \\<le> N\", simp_all)\n  apply(cases \"hW s < tW s \\<and> Data s (numEnqs s) < tW s - hW s\", simp_all)\n  apply(cases \"tW s < hW s\", simp_all)\n  apply(case_tac \"Data s (numEnqs s) \\<le> N - hW s\", simp_all)\n  apply(case_tac \"Data s (numEnqs s) < tW s\", simp_all)\n  apply(case_tac \"N < Data s (numEnqs s)\", simp_all)\n  apply(simp add:pre_W_def pre_enqueue_inv_def)\n  apply(simp add:inv_def Q_lemmas Q_basic_lemmas)\n  apply (metis Nat.le_imp_diff_is_add hd_append length_0_conv list.sel(1) plus_nat.add_0 tempW_reflects_writes_def)\n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(simp add:pre_W_def pre_write_inv_def)\n  apply(simp add:inv_def Q_lemmas Q_basic_lemmas)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply (metis fst_eqD head_q0 length_greater_0_conv)\n  apply(cases \"pcW s\", simp_all) \n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all) \n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all) \n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(simp add:pre_W_def pre_write_inv_def)\n  apply (metis F.distinct(1))\n  apply(cases \"pcW s\", simp_all) \n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all) \n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all) \n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all) \n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all) \n  apply(simp add:pre_W_def pre_A3_inv_def)\n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all) \n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all) defer\n  apply(cases \"pcW s\", simp_all) \n  apply(simp add:pre_W_def pre_A3_inv_def)\n  apply(simp add:pre_W_def pre_A4_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply (metis (no_types, lifting) F.distinct(13) Suc_lessD add.commute less_diff_conv less_trans_Suc) \n  apply(simp add:pre_W_def pre_A6_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply (metis (mono_tags, hide_lams) F.distinct(13) le_antisym le_trans less_or_eq_imp_le nat_neq_iff)\n  apply(simp add:pre_W_def pre_A7_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply (metis (no_types, hide_lams) F.distinct(13) Suc_lessD less_trans_Suc)  \n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all) \n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply(cases \"pcW s\", simp_all) \n  apply(simp add:pre_W_def pre_A3_inv_def)\n  apply(simp add:pre_W_def pre_A4_inv_def)\n  apply(simp add:pre_W_def pre_A6_inv_def)\n  apply(simp add:pre_W_def pre_A7_inv_def)\n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)     (*tempR doesnt change:*)\n  apply(cases \"pcW s\", simp_all) \n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply metis\n  apply(case_tac \" tW s = hW s \\<and> Data s (numEnqs s) \\<le> N\", simp_all) \n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply metis\n  apply(case_tac \"hW s < tW s \\<and> Data s (numEnqs s) < tW s - hW s\", simp_all)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply metis\n  apply(case_tac \"tW s < hW s\", simp_all)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply metis\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply metis\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply(intro conjI impI)\n  apply metis\n  apply (metis (no_types, lifting))\n  apply(simp add:pre_W_def pre_A3_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply(intro conjI impI)\n  apply metis\n  apply (metis (no_types, lifting))\n  apply(simp add:pre_W_def pre_A4_inv_def)\n  apply (metis (no_types, lifting) F.distinct(13) Suc_lessD add.commute less_diff_conv less_trans_Suc)\n  apply(case_tac \" Data s (numEnqs s) \\<le> N - hW s\", simp_all)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply(simp add:pre_W_def pre_A5_inv_def)\n  apply metis\n  apply(case_tac \"Data s (numEnqs s) < tW s\", simp_all)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply(simp add:pre_W_def pre_A5_inv_def)\n  apply metis\n  apply(simp add:pre_W_def pre_A5_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply metis\n  apply(simp add:pre_W_def pre_A6_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply(intro conjI impI)\n  apply metis\n  apply (metis (no_types, lifting))\n  apply (metis (mono_tags, hide_lams) F.distinct(13) le_trans less_or_eq_imp_le nat_neq_iff)\n  apply(simp add:pre_W_def pre_A7_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas) \n  apply(intro conjI impI)\n  apply metis\n  apply (metis (no_types, lifting))\n  apply(clarify)\n  apply(intro conjI impI)\n  apply (metis F.distinct(13) Suc_lessD less_trans_Suc)\n  apply (metis (mono_tags, hide_lams) F.distinct(13) le_trans less_or_eq_imp_le linorder_neqE_nat)\n  apply(case_tac \"N < Data s (numEnqs s)\", simp_all)\n  apply(simp add:pre_W_def pre_A8_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply metis\n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply metis\n  apply(simp add:pre_W_def pre_A8_inv_def)  defer\n  apply(cases \"numEnqs s < n\", simp_all)\n  apply(simp add:pre_W_def pre_acquire_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply metis\n  apply(simp add:pre_W_def pre_acquire_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply metis\n  apply(simp add:pre_W_def pre_OOM_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply(cases \"tW s \\<noteq> T s\", simp_all)\n  apply metis\n  apply metis\n  apply(simp add:pre_W_def pre_write_inv_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply (metis (no_types, lifting) F.distinct(1) Nat.add_0_right eq_imp_le fst_eqD nat_add_left_cancel_less snd_eqD)\n  apply(simp add:pre_W_def pre_enqueue_inv_def)   \n  apply(simp add:tempR_lemmas tempR_basic_lemmas)\n  apply(intro conjI impI)\n  (*solved trivially by case ownership observation*)\n  apply(simp add: tempW_def)\n  apply(case_tac \"q s\\<noteq>[]\") \n  apply (metis (no_types, hide_lams) hd_append2)\n  apply(subgoal_tac \"q s=[]\") prefer 2 \n  apply force\n  apply(subgoal_tac \"tempR s \\<noteq>(0,0)\") prefer 2 \n  apply blast\n  apply(case_tac \"offset s = 0\")\n  apply (metis append_Nil fst_conv list.sel(1))\n  apply(simp add:inv_def)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply clarify \n  apply(subgoal_tac \"c=b\") prefer 2 \n  apply (metis le_neq_implies_less)\n  apply(subgoal_tac \"end(tempR s) = b\") prefer 2 \n  apply (metis end_simp le_add_diff_inverse)\n  apply(subgoal_tac \"offset s = hW s\") prefer 2\n  apply meson \n  apply(subgoal_tac \"i\\<ge>c \\<and> i<H s \\<longrightarrow>ownB s i = W\") prefer 2\n  apply metis\n  apply(subgoal_tac \"H s\\<le>N\") prefer 2 \n  apply metis\n  apply(subgoal_tac \"(i<c \\<or> i\\<ge>H s \\<and> i\\<le>N) \\<longrightarrow>ownB s i\\<noteq>W\") prefer 2 \n  apply (metis F.distinct(1) F.distinct(5) bot_nat_0.not_eq_extremum diff_is_0_eq zero_less_diff)\n  apply (metis F.distinct(1) add_leD1 end_simp le_eq_less_or_eq linorder_neqE_nat nat_less_le)  \n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\") \n  apply clarify \n  apply (metis eq_imp_le le_add1 le_neq_implies_less plus_nat.add_0)\n  apply(simp add: tempW_def)\n  apply(case_tac \"q s=[]\")\n  apply (metis (no_types, lifting) F.distinct(1) Nat.add_0_right Suc_le_lessD Suc_lessD Suc_pred add_lessD1 fst_eqD le_add_diff_inverse less_Suc0 less_Suc_eq_le less_add_same_cancel1 list.size(3) nat_add_left_cancel_le nth_Cons_0 self_append_conv2)\n  apply(subgoal_tac \"q s\\<noteq>[]\") prefer 2 \n  apply blast\n  apply(subgoal_tac \"\\<forall>i<length (q s). fst ((q s) ! i) \\<noteq> fst (tempR s)\") prefer 2\n  apply presburger\n  apply(subgoal_tac \"fst((offset s, Data s (numEnqs s))) \\<noteq> fst(tempR s)\") \n  apply (metis less_SucE nth_append nth_append_length)\n  apply(subgoal_tac \"offset s \\<noteq> fst(tempR s)\") prefer 2 \n  apply (metis (no_types, lifting) F.distinct(1) Suc_le_lessD Suc_lessD Suc_pred add_lessD1 le_add_diff_inverse le_refl less_add_same_cancel1)\n  apply(case_tac \"case_1 s\", simp_all) \n  apply(subgoal_tac \"\\<forall>i<length (q s).\n       (fst (tempR s) < fst ((q s ) ! i) \\<longrightarrow>\n        fst (tempR s) + Data s (numReads s - Suc 0) \\<le> fst ((q s ) ! i)) \\<and>\n       (fst ((q s) ! i) < fst (tempR s) \\<longrightarrow>\n        fst ((q s) ! i) + snd ((q s ) ! i)\n        \\<le> fst (tempR s))\")\n  prefer 2 \n  apply (metis (no_types, lifting) gr_implies_not0 length_0_conv)\n  apply(subgoal_tac \"(fst (tempR s) < fst(offset s, Data s (numEnqs s)) \\<longrightarrow>\n        fst (tempR s) + Data s (numReads s - Suc 0) \\<le> fst(offset s, Data s (numEnqs s))) \\<and>\n       (fst(offset s, Data s (numEnqs s)) < fst (tempR s) \\<longrightarrow>\n        end(offset s, Data s (numEnqs s))\n        \\<le> fst (tempR s))\")\n  apply (smt (z3) end_simp less_SucE nth_append nth_append_length)\n  apply(intro conjI impI)\n  apply (metis (no_types, lifting) Nat.add_0_right fst_eqD le_eq_less_or_eq less_add_same_cancel1 less_nat_zero_code nat_neq_iff snd_eqD tempW_def)\n  apply(simp add:inv_def)\n  apply(case_tac \"case_1 s\", simp_all) apply (simp add:case_1_def)\n  apply(clarify)\n  apply (metis (no_types, lifting) F.distinct(1) diff_is_0_eq le_refl less_imp_le_nat not_gr0 prod.collapse prod.inject tempW_def zero_less_diff)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\") \n  apply clarify\n  apply (metis less_or_eq_imp_le zero_less_iff_neq_zero)\n  apply(simp add: tempW_def)\n  apply(subgoal_tac \"end((offset s, Data s (numEnqs s))) \\<noteq> fst(tempR s)\") \n  apply (metis end_simp fst_conv snd_conv)\n  apply(subgoal_tac \"offset s \\<noteq> fst(tempR s)\") prefer 2 \n  apply (metis (no_types, lifting) F.distinct(1) Suc_le_lessD Suc_lessD Suc_pred add_lessD1 le_add_diff_inverse le_refl less_add_same_cancel1)\n  apply(simp add:inv_def)\n  apply(case_tac \"case_1 s\", simp_all)\n  apply(simp add:case_1_def)\n  apply(clarify)\n  apply linarith\n  apply(simp add:case_2_def) apply (thin_tac \"\\<not>case_1 s\") \n  apply(clarify)\n  by (metis add_gr_0 nat_neq_iff)\n\n\n\n\nlemma GLOBAL_W_step_shows_preR:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_R (pcR s) s\"\n  and \"pre_W (pcW s) s\"\n  and \"cW_step (pcW s) s s'\"\nshows \"pre_R (pcR s') s'\"\n  using assms apply simp\n  apply(subgoal_tac \"pcR s' = pcR s\") prefer 2\n  using pcR_doesnt_change_with_W [where s=s and s'=s']\n  apply simp\n  apply(simp add:pre_R_def) apply(case_tac \"pcR s\") apply simp_all\n  using preRelease_doesnt_change_with_W [where s=s and s'=s'] apply simp    \n  using preIdleR_doesnt_change_with_W [where s=s and s'=s'] apply simp     \n  using preRead_doesnt_change_with_W [where s=s and s'=s'] \n  by simp\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n(*******************************GLOBAL R_step shows preW*************************************)\n\nlemma pcW_doesnt_change_with_R:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_R (pcR s) s\"\n  and \"pre_W (pcW s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"pcW s'=pcW s\"\n using assms apply simp\n  apply(case_tac \"pcR s \", simp_all add:cR_step_def)\n  by(case_tac \"q s=[]\", simp_all)\n\n\nlemma ownB_by_W_doesnt_change_after_release:\n  \"inv s \\<Longrightarrow> con_assms s \\<Longrightarrow> pre_Release_inv s \\<Longrightarrow> cR_step Release s s'\n  \\<Longrightarrow>ownB s i = W \\<and> i\\<le>N \\<Longrightarrow> ownB s' i = W \\<and> i\\<le>N\"\n  apply(simp add:inv_def)\n  apply(simp add:cR_step_def)\n  apply(simp add:pre_Release_inv_def)\n  apply(case_tac \"T s \\<noteq> fst (tempR s)\") \n  apply(case_tac \"case_1 s\") apply simp apply(simp add:case_1_def)\n  apply metis\n  apply simp apply(simp add:case_2_def)\n  apply (metis F.distinct(7) nat_less_le) \n  apply(case_tac \"case_1 s\") apply simp by(simp add:case_1_def)\n  \nlemma ownB_not_by_W_doesnt_change_after_release:\n  \"inv s \\<Longrightarrow> con_assms s \\<Longrightarrow> pre_Release_inv s \\<Longrightarrow> cR_step Release s s'\n  \\<Longrightarrow>ownB s i \\<noteq> W \\<and> i\\<le>N \\<Longrightarrow> ownB s' i \\<noteq> W \\<and> i\\<le>N\"\n  apply(simp add:inv_def)\n  by(simp add:cR_step_def)\n\n\nlemma ownB_by_W_doesnt_change_after_read:\n  \"inv s \\<Longrightarrow> con_assms s \\<Longrightarrow> pre_Read_inv s \\<Longrightarrow> cR_step Read s s'\n  \\<Longrightarrow>ownB s i = W \\<and> i\\<le>N \\<Longrightarrow> ownB s' i = W \\<and> i\\<le>N\"\n  apply(simp add:inv_def)\n  by(simp add:cR_step_def)\n\n\nlemma ownB_not_by_W_doesnt_change_after_read:\n  \"inv s \\<Longrightarrow> con_assms s \\<Longrightarrow> pre_Read_inv s \\<Longrightarrow> cR_step Read s s'\n  \\<Longrightarrow>ownB s i \\<noteq> W \\<and> i\\<le>N \\<Longrightarrow> ownB s' i \\<noteq> W \\<and> i\\<le>N\"\n  apply(simp add:inv_def)\n  by(simp add:cR_step_def)\n\n\nlemma ownB_by_W_doesnt_change_after_dequeue:\n  \"inv s \\<Longrightarrow> con_assms s \\<Longrightarrow> pre_dequeue_inv s \\<Longrightarrow> cR_step idleR s s'\n  \\<Longrightarrow>ownB s i = W \\<and> i\\<le>N \\<Longrightarrow> ownB s' i = W \\<and> i\\<le>N\"\n  apply(simp add:inv_def)\n  apply(simp add:cR_step_def)\n  apply(simp add:pre_dequeue_inv_def)\n  apply(case_tac \"q s=[]\")\n  apply presburger\n  apply(case_tac \"case_1 s\") apply simp apply(simp add:case_1_def) \n  apply (metis (no_types, hide_lams) F.distinct(3))\n  apply simp apply(simp add:case_2_def)\n  by (metis (no_types, hide_lams) F.distinct(3))\n\n\nlemma ownB_not_by_W_doesnt_change_after_dequeue:\n  \"inv s \\<Longrightarrow> con_assms s \\<Longrightarrow> pre_dequeue_inv s \\<Longrightarrow> cR_step idleR s s'\n  \\<Longrightarrow>ownB s i \\<noteq> W \\<and> i\\<le>N \\<Longrightarrow> ownB s' i \\<noteq> W \\<and> i\\<le>N\"\n  apply(simp add:inv_def)\n  apply(simp add:cR_step_def)\n  apply(simp add:pre_dequeue_inv_def)\n  apply(case_tac \"q s=[]\")\n  apply presburger\n  apply(case_tac \"case_1 s\") apply simp by(simp add:case_1_def) \n\nlemma ownB_by_W_doesnt_change_with_R:\n  \"inv s \\<Longrightarrow> con_assms s  \\<Longrightarrow> cR_step (pcR s) s s' \\<Longrightarrow> pcR s = Release \\<longrightarrow> pre_Release_inv s \\<Longrightarrow>\n     pcR s = Read \\<longrightarrow> pre_Read_inv s \\<Longrightarrow> pcR s = idleR \\<longrightarrow> pre_dequeue_inv s\n  \\<Longrightarrow>ownB s i = W \\<and> i\\<le>N \\<Longrightarrow> ownB s' i = W \\<and> i\\<le>N\"\n  apply(case_tac \"pcR s \") apply simp_all\n  using ownB_by_W_doesnt_change_after_release [where s=s and s'=s' and i=i]\n  apply auto[1] \n  using ownB_by_W_doesnt_change_after_dequeue [where s=s and s'=s' and i=i]\n  apply auto[1]\n  using ownB_by_W_doesnt_change_after_read [where s=s and s'=s' and i=i]\n  by auto[1]\n\nlemma ownB_not_by_W_doesnt_change_with_R:\n  \"inv s \\<Longrightarrow> con_assms s  \\<Longrightarrow> cR_step (pcR s) s s' \\<Longrightarrow> pcR s = Release \\<longrightarrow> pre_Release_inv s \\<Longrightarrow>\n     pcR s = Read \\<longrightarrow> pre_Read_inv s \\<Longrightarrow> pcR s = idleR \\<longrightarrow> pre_dequeue_inv s\n  \\<Longrightarrow>ownB s i \\<noteq> W \\<and> i\\<le>N \\<Longrightarrow> ownB s' i \\<noteq> W \\<and> i\\<le>N\"\n  apply(case_tac \"pcR s \") apply simp_all\n  using ownB_not_by_W_doesnt_change_after_release [where s=s and s'=s' and i=i]\n  apply auto[1] \n  using ownB_not_by_W_doesnt_change_after_dequeue [where s=s and s'=s' and i=i]\n  apply auto[1]\n  using ownB_not_by_W_doesnt_change_after_read [where s=s and s'=s' and i=i]\n  by auto[1]\n\n\nlemma ownB_by_B_doesnt_change_after_release:\n  \"inv s \\<Longrightarrow> con_assms s \\<Longrightarrow> pre_Release_inv s \\<Longrightarrow> cR_step Release s s'\n  \\<Longrightarrow>ownB s i = B \\<and> i\\<le>N \\<Longrightarrow> ownB s' i = B \\<and> i\\<le>N\"\n  apply(simp add:inv_def)\n  by(simp add:cR_step_def)\n\n\nlemma ownB_by_B_doesnt_change_after_read:\n  \"inv s \\<Longrightarrow> con_assms s \\<Longrightarrow> pre_Read_inv s \\<Longrightarrow> cR_step Read s s'\n  \\<Longrightarrow>ownB s i = B \\<and> i\\<le>N \\<Longrightarrow> ownB s' i = B \\<and> i\\<le>N\"\n  apply(simp add:inv_def)\n  by(simp add:cR_step_def)\n\n\nlemma ownB_by_B_doesnt_change_after_dequeue:\n  \"inv s \\<Longrightarrow> con_assms s \\<Longrightarrow> pre_dequeue_inv s \\<Longrightarrow> cR_step idleR s s'\n  \\<Longrightarrow>ownB s i = B \\<and> i\\<le>N \\<Longrightarrow> ownB s' i = B \\<and> i\\<le>N\"\n  apply(simp add:inv_def)\n  apply(simp add:cR_step_def)\n  apply(simp add:pre_dequeue_inv_def)\n  apply(case_tac \"q s=[]\")\n  apply presburger\n  apply(case_tac \"case_1 s\") apply simp apply(simp add:case_1_def)\n  apply (metis (no_types, hide_lams) F.distinct(19))\n  apply(case_tac \"q s=[]\", simp_all)\n  by force\n\nlemma ownB_by_B_doesnt_change_with_R:\n  \"inv s \\<Longrightarrow> con_assms s  \\<Longrightarrow> cR_step (pcR s) s s' \\<Longrightarrow> pcR s = Release \\<longrightarrow> pre_Release_inv s \\<Longrightarrow>\n     pcR s = Read \\<longrightarrow> pre_Read_inv s \\<Longrightarrow> pcR s = idleR \\<longrightarrow> pre_dequeue_inv s\n  \\<Longrightarrow>ownB s i = B \\<and> i\\<le>N \\<Longrightarrow> ownB s' i = B \\<and> i\\<le>N\"\n  apply(case_tac \"pcR s \") apply simp_all\n  using ownB_by_B_doesnt_change_after_release [where s=s and s'=s' and i=i]\n  apply auto[1] \n  using ownB_by_B_doesnt_change_after_dequeue [where s=s and s'=s' and i=i]\n  apply auto[1]\n  using ownB_by_B_doesnt_change_after_read [where s=s and s'=s' and i=i]\n  by auto[1]\n\n\n\nlemma ownB_by_D_doesnt_change_after_release:\n  \"inv s \\<Longrightarrow> con_assms s \\<Longrightarrow> pre_Release_inv s \\<Longrightarrow> cR_step Release s s' \\<Longrightarrow>tR s = fst(tempR s)\n  \\<Longrightarrow>ownB s i = D \\<and> i\\<le>N \\<Longrightarrow> ownB s' i = D \\<and> i\\<le>N\"\n  apply(simp add:inv_def)\n  by(simp add:cR_step_def)\n  \n\nlemma ownB_by_D_doesnt_change_after_read:\n  \"inv s \\<Longrightarrow> con_assms s \\<Longrightarrow> pre_Read_inv s \\<Longrightarrow> cR_step Read s s'\n  \\<Longrightarrow>ownB s i = D \\<and> i\\<le>N \\<Longrightarrow> ownB s' i = D \\<and> i\\<le>N\"\n  apply(simp add:inv_def)\n  by(simp add:cR_step_def)\n\n\n\nlemma ownB_by_D_doesnt_change_after_dequeue:\n  \"inv s \\<Longrightarrow> con_assms s \\<Longrightarrow> pre_dequeue_inv s \\<Longrightarrow> cR_step idleR s s'\n  \\<Longrightarrow>ownB s i = D \\<and> i\\<le>N \\<Longrightarrow> ownB s' i = D \\<and> i\\<le>N\"\n  apply(simp add:inv_def)\n  apply(simp add:cR_step_def)\n  apply(simp add:pre_dequeue_inv_def)\n  apply(case_tac \"q s=[]\", simp_all) \n  by force\n\n\nlemma W_items_dont_change_with_R:\n  \"cR_step (pcR s) s s' \n  \\<Longrightarrow>offset s = offset s' \\<and> Data s (numEnqs s) = Data s' (numEnqs s') \\<and> numEnqs s = numEnqs s' \"\n  apply(case_tac \"pcR s \") apply simp_all apply(simp_all add:cR_step_def)\n  by(cases \"q s=[]\", simp_all) \n\nlemma W_items_dont_change_with_R_2:\n  \"cR_step (pcR s) s s' \n  \\<Longrightarrow>tempW s = tempW s' \\<and> tW s = tW s' \\<and> hW s = hW s' \\<and> data_index s = data_index s'\"\n  apply(case_tac \"pcR s \") apply simp_all apply(simp_all add:cR_step_def tempW_def)\n  by(cases \"q s=[]\", simp_all) \n\nlemma W_items_dont_change_with_R_3:\n  \"cR_step (pcR s) s s' \n  \\<Longrightarrow>numWrites s=numWrites s' \\<and> H s= H s'\"\n  apply(case_tac \"pcR s \") apply simp_all apply(simp_all add:cR_step_def tempW_def)\n  by(cases \"q s=[]\", simp_all) \n\nlemma ownB_by_D_relation_with_R:\n  \"inv s \\<Longrightarrow>con_assms s  \\<Longrightarrow> pre_Read_inv s \\<Longrightarrow> pre_enqueue_inv s \\<Longrightarrow>  \noffset s \\<noteq> fst(tempR s)\"\n  apply (simp add:inv_def pre_Read_inv_def pre_enqueue_inv_def)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply(clarify)\n  apply(case_tac \"q s=[]\")\n  apply(subgoal_tac \"b=c\") prefer 2\n  apply (metis nat_less_le) apply(unfold tempW_lemmas tempW_basic_lemmas)\n  apply(subgoal_tac \"offset s = c\") prefer 2\n  apply (metis F.distinct(1) F.distinct(5) fst_conv le_iff_add less_or_eq_imp_le nat_less_le snd_conv)\n  apply(subgoal_tac \"offset s = b\") prefer 2 \n  apply force\n  apply(subgoal_tac \"fst(tempR s )\\<ge>T s\") prefer 2 \n  apply linarith apply(unfold tempR_lemmas tempR_basic_lemmas)\n  apply(subgoal_tac \"snd( tempR s )>0\")\n  apply metis\n  apply metis\n  apply(subgoal_tac \"b<c\") prefer 2 \n  apply (metis diff_self_eq_0 le_zero_eq length_0_conv nat_less_le)\n  apply(subgoal_tac \"offset s = c\") prefer 2\n  apply (metis F.distinct(1) F.distinct(5) fst_conv le_iff_add less_or_eq_imp_le nat_less_le snd_conv)\n  apply(subgoal_tac \"snd(tempR s)>0\") \n  apply (metis end_simp)\n  apply (metis end_simp)\n  apply simp\n  apply(simp add:case_2_def)\n  apply clarify\n  apply(case_tac \"q s=[]\")\n  apply(subgoal_tac \"d = fst(tempR s)\") prefer 2 \n  apply (metis F.distinct(1) Nat.add_0_right le0 less_nat_zero_code nat_add_left_cancel_less)\n  apply(subgoal_tac \"fst(tempW s) = b\") prefer 2 \n  apply (metis F.distinct(1) diff_is_0_eq le0 nat_neq_iff zero_less_diff)\n  apply(subgoal_tac \"snd(tempW s) > 0\") prefer 2\n  apply (metis snd_eqD tempW_def)\n  apply (metis fst_eqD le_neq_implies_less tempW_def)\n  by (metis F.distinct(1) add_gr_0 le0)\n\n\nlemma R_doesnt_change_q_read_release:\n  \"inv s \\<Longrightarrow> cR_step (pcR s) s s' \\<Longrightarrow> pcR s\\<noteq>idleR \\<Longrightarrow> q s=q s'\"\n  apply(simp add:inv_def cR_step_def)\n  by(case_tac \"pcR s\", simp_all)\n\nlemma R_changes_q_dequeue:\n  \"inv s \\<Longrightarrow> cR_step (pcR s) s s' \\<Longrightarrow> pcR s=idleR \\<Longrightarrow>q s\\<noteq>[] \\<Longrightarrow> tl(q s)=q s'\"\n  by(simp add:inv_def cR_step_def)\n\nlemma strange_but_Q_1:\n  \"q s\\<noteq>[] \\<Longrightarrow> hd(q s) = q s!0\"\n  by (simp add: hd_conv_nth)\n\nlemma strange_but_Q_2:\n  \"length(q s)>1 \\<Longrightarrow>hd(tl(q s)) = tl(q s)!0\"\n  by (metis One_nat_def hd_conv_nth length_tl less_nat_zero_code list.size(3) zero_less_diff)\n\nlemma strange_but_Q_3:\n  \"length(q s)>1 \\<Longrightarrow>tl(q s)\\<noteq>[]\"\n  by (metis Nitpick.size_list_simp(2) One_nat_def less_numeral_extra(4) not_one_less_zero)\n\nlemma strange_but_Q_4:\n  \"length(q s)>1 \\<Longrightarrow>hd(tl(q s)) = q s!1\"\n  by (simp add: nth_tl strange_but_Q_2)\n\nlemma R_doesnt_change_ownD_release_dequeue:\n  \"cR_step (pcR s) s s'\\<Longrightarrow> pcR s\\<noteq>Read \\<Longrightarrow>\n  ownD s= ownD s'\"\n  apply(simp add: cR_step_def) \n  apply(case_tac \"pcR s\", simp_all)\n  by(case_tac \"q s=[]\", simp_all)\n\nlemma R_doesnt_change_ownD_read_except:\n  \"cR_step (pcR s) s s'\\<Longrightarrow> pcR s=Read \\<Longrightarrow> \n  i\\<ge>0 \\<and> i\\<noteq> data_index s (tempR s) \\<longrightarrow> ownD s i= ownD s' i\"\n  by(simp add: cR_step_def) \n\nlemma Q_empty_R_step_result:\n  \"cR_step (pcR s) s s' \\<Longrightarrow> q s=[] \\<Longrightarrow> pcR s=idleR \\<Longrightarrow>\nq s'=[]\"\n  by (simp add:cR_step_def)\n\nlemma Q_W_relation_through_R_1:\n  \"cR_step (pcR s) s s' \\<Longrightarrow> q s'\\<noteq>[] \\<Longrightarrow> q s\\<noteq>[] \\<Longrightarrow> pcR s = idleR \\<Longrightarrow>\n\\<forall>i<length (q s).\n       (offset s < fst (q s ! i) \\<longrightarrow> offset s + Data s (numEnqs s) < fst (q s ! i)) \\<and>\n       (fst (q s ! i) < offset s \\<longrightarrow> fst (q s ! i) + snd (q s ! i) \\<le> offset s)\n\\<Longrightarrow>\n\\<forall>i<length (q s').\n       (offset s' < fst (q s' ! i) \\<longrightarrow> offset s' + Data s' (numEnqs s') < fst (q s' ! i)) \\<and>\n       (fst (q s' ! i) < offset s' \\<longrightarrow> fst (q s' ! i) + snd (q s' ! i) \\<le> offset s')\"\n  apply(simp add:cR_step_def)\n  by (simp add: length_greater_0_conv nth_tl)\n\nlemma Q_W_relation_through_R_2:\n  \"cR_step (pcR s) s s'  \\<Longrightarrow> pcR s = Read \\<Longrightarrow>\n\\<forall>i<length (q s).\n       (offset s < fst (q s ! i) \\<longrightarrow> offset s + Data s (numEnqs s) < fst (q s ! i)) \\<and>\n       (fst (q s ! i) < offset s \\<longrightarrow> fst (q s ! i) + snd (q s ! i) \\<le> offset s)\n\\<Longrightarrow>\n\\<forall>i<length (q s').\n       (offset s' < fst (q s' ! i) \\<longrightarrow> offset s' + Data s' (numEnqs s') < fst (q s' ! i)) \\<and>\n       (fst (q s' ! i) < offset s' \\<longrightarrow> fst (q s' ! i) + snd (q s' ! i) \\<le> offset s')\"\n  by(simp add:cR_step_def)\n\n\nlemma Q_W_relation_through_R_3:\n  \"cR_step (pcR s) s s' \\<Longrightarrow> pcR s = Release \\<Longrightarrow>\n\\<forall>i<length (q s).\n       (offset s < fst (q s ! i) \\<longrightarrow> offset s + Data s (numEnqs s) < fst (q s ! i)) \\<and>\n       (fst (q s ! i) < offset s \\<longrightarrow> fst (q s ! i) + snd (q s ! i) \\<le> offset s)\n\\<Longrightarrow>\n\\<forall>i<length (q s').\n       (offset s' < fst (q s' ! i) \\<longrightarrow> offset s' + Data s' (numEnqs s') < fst (q s' ! i)) \\<and>\n       (fst (q s' ! i) < offset s' \\<longrightarrow> fst (q s' ! i) + snd (q s' ! i) \\<le> offset s')\"\n  by(simp add:cR_step_def) \n\n\n\n\nlemma pre_write_doesnt_change_with_R:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_write_inv s\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"pre_write_inv s'\"\n  using assms apply simp\n  apply(simp add:pre_write_inv_def)\n  apply(subgoal_tac \"end(tempW s )\\<le>N\") prefer 2 apply(simp_all add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:pre_R_def)\n  apply(intro conjI impI)\n  apply(case_tac[!] \"pcR s\")\n  apply simp_all apply(subgoal_tac \"\\<forall>i. offset s \\<le> i \\<and> i < fst (tempW s) + snd (tempW s) \\<longrightarrow> ownB s i = W\") prefer 2 \n  apply (metis fst_eqD snd_eqD tempW_def)\n  apply(subgoal_tac \"hW s = hW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using PCR.distinct(1) PCR.distinct(3) assms(2) apply presburger\n  apply(subgoal_tac \"tW s = tW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using PCR.distinct(1) PCR.distinct(3) assms(2) apply presburger\n  using ownB_by_W_doesnt_change_after_release [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (metis W_items_dont_change_with_R assms(2) le_trans less_or_eq_imp_le)\n  using ownB_by_W_doesnt_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  apply (metis PCR.distinct(1) PCR.distinct(5) W_items_dont_change_with_R assms(2) le_trans less_or_eq_imp_le)\n  using ownB_by_W_doesnt_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (metis PCR.distinct(3) PCR.distinct(5) W_items_dont_change_with_R assms(2) le_trans less_or_eq_imp_le)\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using PCR.distinct(1) PCR.distinct(3) assms(2) apply presburger\n  apply(subgoal_tac \"tW s \\<le>N\") prefer 2\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply (metis RingBuffer_BD_latest_2.inv_def basic_pointer_movement_def inRange_def inRangeht_def)\n  using ownB_by_B_doesnt_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (smt (z3) PCR.distinct(1) PCR.distinct(3) W_items_dont_change_with_R assms(2) le_trans less_or_eq_imp_le)\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using PCR.distinct(1) PCR.distinct(5) assms(2) apply presburger\n  apply(subgoal_tac \"tW s \\<le>N\") prefer 2\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply (metis RingBuffer_BD_latest_2.inv_def basic_pointer_movement_def inRange_def inRangeht_def)\n  using ownB_by_B_doesnt_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (smt (z3) PCR.distinct(1) PCR.distinct(5) W_items_dont_change_with_R assms(2) le_trans less_or_eq_imp_le)\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using PCR.distinct(3) PCR.distinct(5) assms(2) apply presburger\n  apply(subgoal_tac \"tW s \\<le>N\") prefer 2\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply (metis RingBuffer_BD_latest_2.inv_def basic_pointer_movement_def inRange_def inRangeht_def)\n  using ownB_by_B_doesnt_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  apply (smt (z3) PCR.distinct(3) PCR.distinct(5) W_items_dont_change_with_R assms(2) le_trans less_or_eq_imp_le)\n  apply clarify   \n  apply(intro conjI impI)\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using PCR.distinct(1) PCR.distinct(3) assms(2) apply presburger\n  apply(subgoal_tac \"tW s \\<le>N\") prefer 2\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:inv_def) \n  using ownB_by_B_doesnt_change_with_R [where s=s and s'=s']\n  apply (metis PCR.distinct(1) PCR.distinct(3) W_items_dont_change_with_R assms(1) assms(2) less_or_eq_imp_le)\n  using ownB_by_B_doesnt_change_with_R [where s=s and s'=s']\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (smt (z3) PCR.distinct(1) PCR.distinct(3) W_items_dont_change_with_R assms(2) le_add_same_cancel1 le_trans less_or_eq_imp_le not_gr_zero)\n  apply clarify\n  apply(intro conjI impI)        \n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using PCR.distinct(1) PCR.distinct(5) assms(2) apply presburger\n  apply(subgoal_tac \"tW s \\<le>N\") prefer 2\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:inv_def) \n  apply (metis assms(1) assms(2) less_or_eq_imp_le ownB_by_B_doesnt_change_after_dequeue prod.inject tempW_def)\n  using ownB_by_B_doesnt_change_with_R [where s=s and s'=s']\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  apply (metis PCR.distinct(1) PCR.distinct(5) add_leD1 assms(2) fst_conv less_le_not_le order_trans tempW_def)\n  apply clarify\n  apply(intro conjI impI)        \n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using PCR.distinct(3) PCR.distinct(5) assms(2) apply presburger\n  apply(subgoal_tac \"tW s \\<le>N\") prefer 2\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:inv_def) \n  apply (metis assms(1) assms(2) less_or_eq_imp_le ownB_by_B_doesnt_change_after_read prod.inject tempW_def)\n  using ownB_by_B_doesnt_change_with_R [where s=s and s'=s']\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (metis PCR.distinct(3) PCR.distinct(5) add_leD1 assms(2) fst_conv less_le_not_le order_trans tempW_def)\n  apply clarify       \n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using PCR.distinct(1) PCR.distinct(3) assms(2) apply presburger\n  apply(subgoal_tac \"tW s \\<le>N\") prefer 2\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:inv_def) \n  using ownB_by_B_doesnt_change_with_R [where s=s and s'=s']\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (smt (z3) PCR.distinct(1) PCR.distinct(3) W_items_dont_change_with_R assms(2) le_trans less_or_eq_imp_le)\n  apply clarify       \n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using PCR.distinct(1) PCR.distinct(5) assms(2) apply presburger\n  apply(subgoal_tac \"tW s \\<le>N\") prefer 2\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:inv_def) \n  using ownB_by_B_doesnt_change_with_R [where s=s and s'=s']\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  apply (smt (z3) PCR.distinct(1) PCR.distinct(5) W_items_dont_change_with_R assms(2) le_trans less_or_eq_imp_le)\n  apply clarify\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using PCR.distinct(3) PCR.distinct(5) assms(2) apply presburger\n  apply(subgoal_tac \"tW s \\<le>N\") prefer 2\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:inv_def) \n  using ownB_by_B_doesnt_change_with_R [where s=s and s'=s']\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (smt (z3) PCR.distinct(3) PCR.distinct(5) W_items_dont_change_with_R assms(2) le_trans less_or_eq_imp_le)\n  apply(case_tac \"tR s = fst(tempR s)\")\n  using ownB_by_D_doesnt_change_after_release [where s=s and s'=s'] \n  apply (metis W_items_dont_change_with_R \\<open>cR_step (pcR s) s s' \\<Longrightarrow> tempW s = tempW s' \\<and> tW s = tW s' \\<and> hW s = hW s' \\<and> data_index s = data_index s'\\<close> assms(2) nat_less_le)\n  apply (simp add:inv_def)\n  apply(case_tac \"case_1 s\", simp_all)\n  apply(simp add: case_1_def) \n  apply (metis (no_types, hide_lams) F.distinct(25) F.distinct(7) \\<open>cR_step (pcR s) s s' \\<Longrightarrow> tempW s = tempW s' \\<and> tW s = tW s' \\<and> hW s = hW s' \\<and> data_index s = data_index s'\\<close> le0 le_refl nat_less_le nat_neq_iff prod.inject tempW_def)\n  apply(thin_tac \"\\<not>case_1 s\")\n  apply(simp add:pre_Release_inv_def)\n  apply(subgoal_tac \"T s\\<noteq>fst(tempR s)\") prefer 2 \n  apply blast\n  apply(simp add:case_2_def)\n  apply clarify\n  apply(subgoal_tac \"fst(tempR s) = T s \\<or> fst(tempR s) = 0\") prefer 2 \n  apply meson\n  apply(subgoal_tac \"fst(tempR s) = 0\") prefer 2 \n  apply presburger\n  apply(subgoal_tac \"ownB s (fst(tempR s)) = R\") prefer 2\n  apply metis\n  apply(subgoal_tac \"ownB s (offset s) = W\") prefer 2 \n  apply (metis Nat.add_0_right le_refl nat_add_left_cancel_less)\n  apply (metis F.distinct(1) W_items_dont_change_with_R)\n  using ownB_by_D_doesnt_change_after_dequeue [where s=s and s'=s'] \n  using W_items_dont_change_with_R \\<open>cR_step (pcR s) s s' \\<Longrightarrow> tempW s = tempW s' \\<and> tW s = tW s' \\<and> hW s = hW s' \\<and> data_index s = data_index s'\\<close> assms(2) less_or_eq_imp_le \n  apply presburger\n  using ownB_by_D_doesnt_change_after_read [where s=s and s'=s'] \n  using W_items_dont_change_with_R \\<open>cR_step (pcR s) s s' \\<Longrightarrow> tempW s = tempW s' \\<and> tW s = tW s' \\<and> hW s = hW s' \\<and> data_index s = data_index s'\\<close> assms(2) less_or_eq_imp_le \n  apply presburger\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using PCR.distinct(1) PCR.distinct(3) assms(2) apply presburger\n  apply (simp add: pre_Release_inv_def) \n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using PCR.distinct(1) PCR.distinct(5) assms(2) apply presburger\n  apply (simp add: pre_dequeue_inv_def inv_def Q_lemmas Q_basic_lemmas cR_step_def) \n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using PCR.distinct(3) PCR.distinct(5) assms(2) apply presburger\n  apply(simp add: pre_Read_inv_def) \n  apply(simp add:cR_step_def)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)\n  apply(simp add:cR_step_def)\n  apply(simp add:cR_step_def)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(simp add:cR_step_def)\n  apply(simp add:cR_step_def)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(simp add:cR_step_def)\n  apply(simp add:cR_step_def)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(simp add:cR_step_def)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)\n  apply (metis last_tl)\n  apply (metis last_tl)\n  apply(simp add:cR_step_def)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (metis assms(5))\n  apply(subgoal_tac \"(\\<forall>i<length (q s). fst (q s ! i) \\<noteq> offset s)\") prefer 2 \n  apply presburger\n  apply(subgoal_tac \"(\\<forall>i<length (tl(q s)). fst (tl(q s) ! i) \\<noteq> offset s)\") prefer 2\n  apply (metis Suc_diff_Suc diff_Suc_eq_diff_pred diff_add_0 length_tl linordered_semidom_class.add_diff_inverse nat.discI nth_tl)\n  apply(subgoal_tac \"length(q s) - Suc 0 = length(tl(q s))\") prefer 2 \n  apply (metis One_nat_def length_tl)\n  apply presburger\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (metis assms(5))\n  apply(subgoal_tac \"(\\<forall>i<length (q s). fst (q s ! i) \\<noteq> offset s)\") prefer 2 \n  apply presburger\n  apply(subgoal_tac \"(\\<forall>i<length (tl(q s)). fst (tl(q s) ! i) \\<noteq> offset s)\") prefer 2                  \n  apply (metis Suc_diff_Suc diff_Suc_eq_diff_pred diff_add_0 length_tl linordered_semidom_class.add_diff_inverse nat.discI nth_tl)\n  apply (metis One_nat_def length_tl)\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (metis assms(5))\n  apply(subgoal_tac \"(\\<forall>i<length (q s). fst (q s ! i) \\<noteq> offset s)\") prefer 2 \n  apply (metis length_0_conv less_nat_zero_code)\n  apply(subgoal_tac \"offset s' = offset s\") prefer 2\n  apply (metis fst_conv tempW_def)\n  apply(subgoal_tac \"q s= q s'\") \n  apply metis\n  using R_doesnt_change_q_read_release [where s=s and s'=s']\n  apply (metis PCR.distinct(5) assms(5))                \n  using Q_W_relation_through_R_3 [where s=s and s'=s'] \n  apply (simp add: \\<open>\\<lbrakk>RingBuffer_BD_latest_2.inv s; cR_step (pcR s) s s'; pcR s \\<noteq> idleR\\<rbrakk> \\<Longrightarrow> q s = q s'\\<close>)\n  apply(subgoal_tac \"q s\\<noteq>[]\") prefer 2 \n  apply (metis Q_empty_R_step_result)\n  using Q_W_relation_through_R_1 [where s=s and s'=s']\n  apply presburger       \n  using Q_W_relation_through_R_2 [where s=s and s'=s']\n  apply (simp add: \\<open>\\<lbrakk>RingBuffer_BD_latest_2.inv s; cR_step (pcR s) s s'; pcR s \\<noteq> idleR\\<rbrakk> \\<Longrightarrow> q s = q s'\\<close>)\n  apply(subgoal_tac \"q s=q s'\") prefer 2 \n  using R_doesnt_change_q_read_release [where s=s and s'=s']\n  using PCR.distinct(1) apply presburger\n  apply(subgoal_tac \"offset s + Data s (numEnqs s) \\<noteq> fst (hd (q s))\") prefer 2 \n  apply metis\n  apply(subgoal_tac \"tempW s=tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (metis)\n  apply (metis W_items_dont_change_with_R)\n  apply(subgoal_tac \"offset s + Data s (numEnqs s) \\<noteq> fst (hd (q s))\") prefer 2   \n  using cR_step_def apply force\n  apply(subgoal_tac \"i<length(q s)\\<longrightarrow>offset s + Data s (numEnqs s) \\<noteq> fst(q s ! i)\") prefer 2 \n  apply (metis diff_add_zero length_0_conv less_irrefl_nat less_nat_zero_code linordered_semidom_class.add_diff_inverse)\n  apply(subgoal_tac \"q s\\<noteq>[]\") prefer 2 \n  using PCR.simps(8) cR_step_def apply force\n  apply(subgoal_tac \"fst(hd(q s')) = fst(hd(tl(q s)))\") prefer 2 \n  using R_changes_q_dequeue apply presburger\n  apply(subgoal_tac \"tempW s=tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using PCR.distinct(1) PCR.distinct(5) assms(2) apply presburger\n  apply(subgoal_tac \"offset s' = offset s\") prefer 2\n  apply (metis fst_conv tempW_def)\n  apply(subgoal_tac \"fst(hd(tl(q s))) = fst(q s!1)\") prefer 2\n  using strange_but_Q_4 [where s=s] fst_def \n  apply (metis R_changes_q_dequeue length_greater_0_conv length_tl zero_less_diff)\n  apply (metis R_changes_q_dequeue cancel_comm_monoid_add_class.diff_cancel le_iff_add length_0_conv length_tl less_one linorder_neqE_nat nat_less_le snd_conv tempW_def)\n  apply(subgoal_tac \"q s=q s'\") prefer 2 \n  using R_doesnt_change_q_read_release [where s=s and s'=s']\n  using PCR.distinct(5) apply presburger\n  apply(subgoal_tac \"offset s + Data s (numEnqs s) \\<noteq> fst (hd (q s))\") prefer 2 \n  apply metis\n  apply(subgoal_tac \"tempW s=tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (metis)\n  apply (metis W_items_dont_change_with_R)\n  apply clarify\n  using W_items_dont_change_with_R [where s=s and s'=s']\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using ownB_by_W_doesnt_change_with_R [where s=s and s'=s' and i=j]\n  apply (metis \\<open>\\<And>i. \\<lbrakk>RingBuffer_BD_latest_2.inv s; con_assms s; pre_Release_inv s; cR_step Release s s'; ownB s i = W \\<and> i \\<le> N\\<rbrakk> \\<Longrightarrow> ownB s' i = W \\<and> i \\<le> N\\<close> assms(1) assms(2) le_trans less_imp_le_nat)\n  apply clarify\n  using W_items_dont_change_with_R [where s=s and s'=s']\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using ownB_by_W_doesnt_change_with_R [where s=s and s'=s' and i=j]\n  apply (metis PCR.distinct(1) PCR.distinct(5) \\<open>\\<And>i. \\<lbrakk>RingBuffer_BD_latest_2.inv s; con_assms s; cR_step (pcR s) s s'; pcR s = Release \\<longrightarrow> pre_Release_inv s; pcR s = Read \\<longrightarrow> pre_Read_inv s; pcR s = idleR \\<longrightarrow> pre_dequeue_inv s; ownB s i = W \\<and> i \\<le> N\\<rbrakk> \\<Longrightarrow> ownB s' i = W \\<and> i \\<le> N\\<close> assms(2) le_trans less_imp_le_nat)\n  using W_items_dont_change_with_R [where s=s and s'=s']\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using ownB_by_W_doesnt_change_with_R [where s=s and s'=s' and i=j]\n  apply (metis PCR.distinct(3) PCR.distinct(5) \\<open>\\<And>i. \\<lbrakk>RingBuffer_BD_latest_2.inv s; con_assms s; cR_step (pcR s) s s'; pcR s = Release \\<longrightarrow> pre_Release_inv s; pcR s = Read \\<longrightarrow> pre_Read_inv s; pcR s = idleR \\<longrightarrow> pre_dequeue_inv s; ownB s i = W \\<and> i \\<le> N\\<rbrakk> \\<Longrightarrow> ownB s' i = W \\<and> i \\<le> N\\<close> assms(2) le_trans less_imp_le_nat)\n  apply(subgoal_tac \"numWrites s= numWrites s'\") prefer 2\n  apply (metis W_items_dont_change_with_R_3 assms(5))\n  using R_doesnt_change_ownD_release_dequeue [where s=s and s'=s']\n  apply (metis PCR.distinct(3))\n  apply(subgoal_tac \"numWrites s= numWrites s'\") prefer 2\n  apply (metis W_items_dont_change_with_R_3 assms(5))\n  using R_doesnt_change_ownD_release_dequeue [where s=s and s'=s']\n  apply (metis PCR.distinct(5))\n  apply(subgoal_tac \"numWrites s= numWrites s'\") prefer 2\n  apply (metis W_items_dont_change_with_R_3 assms(5))\n  apply(subgoal_tac \"numWrites s \\<noteq> data_index s (tempR s) \") prefer 2 \n  apply(simp add:pre_Read_inv_def)\n  using R_doesnt_change_ownD_read_except [where s=s and s'=s']\n  apply (metis less_eq_nat.simps(1))\n  apply(subgoal_tac \"q s=q s'\") prefer 2\n  using R_doesnt_change_q_read_release [where s=s and s'=s']\n  using PCR.distinct(1) apply presburger\n  apply (metis W_items_dont_change_with_R)\n  apply(simp add:inv_def pre_dequeue_inv_def)\n  apply(subgoal_tac \"numEnqs s= 0\") prefer 2\n  using W_items_dont_change_with_R apply presburger\n  apply(subgoal_tac \"numDeqs s = 0\") prefer 2\n  apply (metis less_nat_zero_code nat_less_le)\n  apply(subgoal_tac \"q s=[]\") prefer 2\n  apply meson\n  apply(simp add:cR_step_def) \n  apply(subgoal_tac \"q s=q s'\") prefer 2\n  using R_doesnt_change_q_read_release [where s=s and s'=s']\n  using PCR.distinct(5) apply presburger\n  apply (metis W_items_dont_change_with_R)\n  using W_items_dont_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  apply metis\n  using W_items_dont_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  apply metis\n  using W_items_dont_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  apply metis\n  using W_items_dont_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using W_items_dont_change_with_R_3 [where s=s and s'=s']\n  apply (metis)\n  using W_items_dont_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using W_items_dont_change_with_R_3 [where s=s and s'=s']\n  apply (metis)\n  using W_items_dont_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using W_items_dont_change_with_R_3 [where s=s and s'=s']\n  by (metis)\n\n\n\nlemma pre_enqueue_doesnt_change_with_R:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_enqueue_inv s\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"pre_enqueue_inv s'\"\n  using assms apply simp\n  apply(simp add:pre_enqueue_inv_def)\n  apply(subgoal_tac \"end(tempW s )\\<le>N\") prefer 2 apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:pre_R_def)\n  apply(intro conjI impI)\n  apply(case_tac[!] \"pcR s\")\n  apply simp_all apply(subgoal_tac \"\\<forall>i. offset s \\<le> i \\<and> i < fst (tempW s) + snd (tempW s) \\<longrightarrow> ownB s i = W\") prefer 2\n  apply metis   apply(subgoal_tac \"\\<forall>i. offset s > i \\<or> i \\<ge> fst (tempW s) + snd (tempW s) \\<and> i\\<le>N \\<longrightarrow> ownB s i \\<noteq> W\") prefer 2\n  apply metis\n  apply(subgoal_tac \"hW s = hW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using PCR.distinct(1) PCR.distinct(3) assms(2) apply presburger\n  apply(subgoal_tac \"tW s = tW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using PCR.distinct(1) PCR.distinct(3) assms(2) apply presburger\n  using ownB_by_W_doesnt_change_after_release [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  apply (metis PCR.distinct(1) PCR.distinct(3) W_items_dont_change_with_R assms(2) end_simp le_trans less_or_eq_imp_le)\n  using ownB_by_W_doesnt_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  apply (metis PCR.distinct(1) PCR.distinct(5) W_items_dont_change_with_R assms(2) le_trans less_or_eq_imp_le)\n  using ownB_by_W_doesnt_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (metis PCR.distinct(3) PCR.distinct(5) W_items_dont_change_with_R assms(2) le_trans less_or_eq_imp_le)\n  apply clarify\n  apply (intro conjI impI)\n  using ownB_not_by_W_doesnt_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (metis PCR.distinct(1) PCR.distinct(3) add_leD1 assms(2) fst_conv less_le_not_le order_trans tempW_def)\n  using ownB_not_by_W_doesnt_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (metis PCR.distinct(1) PCR.distinct(3) add_leD1 assms(2) fst_conv less_le_not_le order_trans tempW_def)\n  using ownB_not_by_W_doesnt_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply clarify\n  apply (intro conjI impI)\n  using ownB_not_by_W_doesnt_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (metis PCR.distinct(1) PCR.distinct(5) add_leD1 assms(2) fst_conv le_imp_less_Suc nat_le_linear not_less_eq order_trans tempW_def)\n  using ownB_not_by_W_doesnt_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (metis PCR.distinct(1) PCR.distinct(5) add_leD1 assms(2) fst_conv le_imp_less_Suc nat_le_linear not_less_eq order_trans tempW_def)\n  apply clarify\n  apply (intro conjI impI) \n  apply(subgoal_tac \"i<offset s \\<longrightarrow>ownB s i\\<noteq>W\") prefer 2 \n  apply presburger\n  apply(subgoal_tac \"offset s = offset s'\") prefer 2 \n  using PCR.distinct(3) PCR.distinct(5) W_items_dont_change_with_R assms(2) apply presburger\n  using ownB_not_by_W_doesnt_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (metis PCR.distinct(3) PCR.distinct(5) add_leD1 assms(2) fst_conv less_le_not_le order_trans tempW_def)\n  using ownB_not_by_W_doesnt_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using PCR.distinct(3) PCR.distinct(5) assms(2) apply presburger\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using PCR.distinct(1) PCR.distinct(3) assms(2) apply presburger\n  apply(subgoal_tac \"tW s \\<le>N\") prefer 2\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply (metis RingBuffer_BD_latest_2.inv_def basic_pointer_movement_def inRange_def inRangeht_def)\n  using ownB_by_B_doesnt_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  apply (metis PCR.distinct(1) PCR.distinct(3) assms(2) le_trans less_or_eq_imp_le)\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using PCR.distinct(1) PCR.distinct(5) assms(2) apply presburger\n  apply(subgoal_tac \"tW s \\<le>N\") prefer 2\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply (metis RingBuffer_BD_latest_2.inv_def basic_pointer_movement_def inRange_def inRangeht_def)\n  using ownB_by_B_doesnt_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (metis PCR.distinct(1) PCR.distinct(5) assms(2) le_trans less_or_eq_imp_le)\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using PCR.distinct(3) PCR.distinct(5) assms(2) apply presburger\n  apply(subgoal_tac \"tW s \\<le>N\") prefer 2\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply (metis RingBuffer_BD_latest_2.inv_def basic_pointer_movement_def inRange_def inRangeht_def)\n  using ownB_by_B_doesnt_change_with_R [where s=s and s'=s'] \n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  apply (metis PCR.distinct(3) PCR.distinct(5) assms(2) le_trans less_or_eq_imp_le)\n  apply clarify\n  apply(intro conjI impI)        \n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using PCR.distinct(1) PCR.distinct(3) assms(2) apply presburger\n  apply(subgoal_tac \"tW s \\<le>N\") prefer 2\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:inv_def)\n  apply (metis assms(1) assms(2) less_or_eq_imp_le ownB_by_B_doesnt_change_after_release prod.inject tempW_def)\n  using ownB_by_B_doesnt_change_with_R [where s=s and s'=s']\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  apply (metis PCR.distinct(1) PCR.distinct(3) add_leD1 assms(2) fst_conv less_le_not_le order_trans tempW_def)\n  apply clarify\n  apply(intro conjI impI)        \n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using PCR.distinct(1) PCR.distinct(5) assms(2) apply presburger\n  apply(subgoal_tac \"tW s \\<le>N\") prefer 2\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:inv_def) \n  apply (metis assms(1) assms(2) less_or_eq_imp_le ownB_by_B_doesnt_change_after_dequeue prod.inject tempW_def)\n  using ownB_by_B_doesnt_change_with_R [where s=s and s'=s']\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  apply (metis PCR.distinct(1) PCR.distinct(5) add_leD1 assms(2) fst_conv less_le_not_le order_trans tempW_def)\n  apply clarify\n  apply(intro conjI impI)        \n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using PCR.distinct(3) PCR.distinct(5) assms(2) apply presburger\n  apply(subgoal_tac \"tW s \\<le>N\") prefer 2\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:inv_def) \n  apply (metis assms(1) assms(2) less_or_eq_imp_le ownB_by_B_doesnt_change_after_read prod.inject tempW_def)\n  using ownB_by_B_doesnt_change_with_R [where s=s and s'=s']\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (metis PCR.distinct(3) PCR.distinct(5) add_leD1 assms(2) fst_conv less_le_not_le order_trans tempW_def)\n  apply clarify       \n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using PCR.distinct(1) PCR.distinct(3) assms(2) apply presburger\n  apply(subgoal_tac \"tW s \\<le>N\") prefer 2\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:inv_def) \n  using ownB_by_B_doesnt_change_with_R [where s=s and s'=s']\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  apply (metis PCR.distinct(1) PCR.distinct(3) add_leD1 assms(2) fst_conv less_le_not_le order_trans tempW_def)\n  apply clarify       \n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using PCR.distinct(1) PCR.distinct(5) assms(2) apply presburger\n  apply(subgoal_tac \"tW s \\<le>N\") prefer 2\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:inv_def) \n  using ownB_by_B_doesnt_change_with_R [where s=s and s'=s']\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  apply (metis PCR.distinct(1) PCR.distinct(5) add_leD1 assms(2) fst_conv less_le_not_le order_trans tempW_def)\n  apply clarify\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  using PCR.distinct(3) PCR.distinct(5) assms(2) apply presburger\n  apply(subgoal_tac \"tW s \\<le>N\") prefer 2\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:inv_def) \n  using ownB_by_B_doesnt_change_with_R [where s=s and s'=s']\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (metis PCR.distinct(3) PCR.distinct(5) add_leD1 assms(2) fst_conv less_le_not_le order_trans tempW_def)\n  apply(case_tac \"tR s = fst(tempR s)\")\n  using ownB_by_D_doesnt_change_after_release [where s=s and s'=s'] \n  apply (metis W_items_dont_change_with_R \\<open>cR_step (pcR s) s s' \\<Longrightarrow> tempW s = tempW s' \\<and> tW s = tW s' \\<and> hW s = hW s' \\<and> data_index s = data_index s'\\<close> assms(2) nat_less_le)\n  apply (simp add:inv_def)\n  apply(case_tac \"case_1 s\", simp_all)\n  apply(simp add: case_1_def)\n  apply (metis F.distinct(15) F.distinct(21) F.distinct(25) F.distinct(7) W_items_dont_change_with_R \\<open>cR_step (pcR s) s s' \\<Longrightarrow> tempW s = tempW s' \\<and> tW s = tW s' \\<and> hW s = hW s' \\<and> data_index s = data_index s'\\<close> less_eq_Suc_le not_less_eq_eq)\n  apply(thin_tac \"\\<not>case_1 s\")\n  apply(simp add:pre_Release_inv_def)\n  apply(subgoal_tac \"T s\\<noteq>fst(tempR s)\") prefer 2 \n  apply blast\n  apply(simp add:case_2_def)\n  apply clarify\n  apply(subgoal_tac \"fst(tempR s) = T s \\<or> fst(tempR s) = 0\") prefer 2 \n  apply meson\n  apply(subgoal_tac \"fst(tempR s) = 0\") prefer 2 \n  apply presburger\n  apply(subgoal_tac \"ownB s (fst(tempR s)) = R\") prefer 2\n  apply metis\n  apply(subgoal_tac \"ownB s (offset s) = W\") prefer 2 \n  apply (metis \\<open>cR_step (pcR s) s s' \\<Longrightarrow> tempW s = tempW s' \\<and> tW s = tW s' \\<and> hW s = hW s' \\<and> data_index s = data_index s'\\<close> fst_eqD nat_le_iff_add plus_nat.add_0 snd_eqD tempW_def)\n  apply (metis F.distinct(1) W_items_dont_change_with_R)\n  using ownB_by_D_doesnt_change_after_dequeue [where s=s and s'=s'] \n  using W_items_dont_change_with_R \\<open>cR_step (pcR s) s s' \\<Longrightarrow> tempW s = tempW s' \\<and> tW s = tW s' \\<and> hW s = hW s' \\<and> data_index s = data_index s'\\<close> assms(2) less_or_eq_imp_le \n  apply presburger\n  using ownB_by_D_doesnt_change_after_read [where s=s and s'=s'] \n  using W_items_dont_change_with_R \\<open>cR_step (pcR s) s s' \\<Longrightarrow> tempW s = tempW s' \\<and> tW s = tW s' \\<and> hW s = hW s' \\<and> data_index s = data_index s'\\<close> assms(2) less_or_eq_imp_le \n  apply presburger\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using PCR.distinct(1) PCR.distinct(3) assms(2) apply presburger\n  apply (simp add: pre_Release_inv_def) \n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using PCR.distinct(1) PCR.distinct(5) assms(2) apply presburger\n  apply (simp add: pre_dequeue_inv_def inv_def Q_lemmas Q_basic_lemmas cR_step_def) \n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using PCR.distinct(3) PCR.distinct(5) assms(2) apply presburger\n  apply(simp add: pre_Read_inv_def) \n  apply(simp add:cR_step_def)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)\n  apply(simp add:cR_step_def)\n  apply(simp add:cR_step_def)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(simp add:cR_step_def)\n  apply(simp add:cR_step_def)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(simp add:cR_step_def)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)\n  apply(simp add:cR_step_def)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(intro conjI impI)\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using PCR.distinct(1) PCR.distinct(3) assms(2) apply presburger \n  apply (metis fst_conv snd_conv tempW_def)\n  apply (metis PCR.distinct(1) R_doesnt_change_q_read_release W_items_dont_change_with_R)\n  apply (metis PCR.distinct(1) R_doesnt_change_q_read_release W_items_dont_change_with_R)\n  apply (metis (no_types, lifting) PCR.distinct(1) R_doesnt_change_q_read_release W_items_dont_change_with_R assms(1) assms(5))\n  apply (metis PCR.distinct(1) R_doesnt_change_q_read_release W_items_dont_change_with_R) \n  apply (metis W_items_dont_change_with_R \\<open>\\<And>i. \\<lbrakk>RingBuffer_BD_latest_2.inv s; con_assms s; pre_Release_inv s; cR_step Release s s'; ownB s i = W \\<and> i \\<le> N\\<rbrakk> \\<Longrightarrow> ownB s' i = W \\<and> i \\<le> N\\<close> assms(2) le_trans less_imp_le_nat)\n  prefer 2\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(intro conjI impI)\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using PCR.distinct(1) PCR.distinct(3) assms(2) apply presburger \n  apply (metis fst_conv snd_conv tempW_def) \n  apply (metis PCR.distinct(5) R_doesnt_change_q_read_release W_items_dont_change_with_R)\n  apply (metis PCR.distinct(5) R_doesnt_change_q_read_release W_items_dont_change_with_R)\n  apply (metis (no_types, lifting) PCR.distinct(5) R_doesnt_change_q_read_release W_items_dont_change_with_R assms(1) assms(5))\n  apply (metis PCR.distinct(5) R_doesnt_change_q_read_release W_items_dont_change_with_R)\n  apply (metis PCR.distinct(3) PCR.distinct(5) W_items_dont_change_with_R \\<open>\\<And>i. \\<lbrakk>RingBuffer_BD_latest_2.inv s; con_assms s; cR_step (pcR s) s s'; pcR s = Release \\<longrightarrow> pre_Release_inv s; pcR s = Read \\<longrightarrow> pre_Read_inv s; pcR s = idleR \\<longrightarrow> pre_dequeue_inv s; ownB s i = W \\<and> i \\<le> N\\<rbrakk> \\<Longrightarrow> ownB s' i = W \\<and> i \\<le> N\\<close> \\<open>\\<And>i. \\<lbrakk>RingBuffer_BD_latest_2.inv s; con_assms s; cR_step (pcR s) s s'; pcR s = Release \\<longrightarrow> pre_Release_inv s; pcR s = Read \\<longrightarrow> pre_Read_inv s; pcR s = idleR \\<longrightarrow> pre_dequeue_inv s; ownB s i \\<noteq> W \\<and> i \\<le> N\\<rbrakk> \\<Longrightarrow> ownB s' i \\<noteq> W \\<and> i \\<le> N\\<close> assms(2) le_trans less_imp_le_nat)\n  apply(simp add:tempW_lemmas tempW_basic_lemmas)   \n  apply(intro conjI impI) apply(simp add:pre_dequeue_inv_def)\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply presburger               \n  apply (metis fst_conv snd_conv tempW_def) \n  apply(case_tac \"length(q s)>1\", simp_all)\n  apply(subgoal_tac \"last(q s) = last(tl(q s))\") prefer 2 \n  apply (metis R_changes_q_dequeue last_tl)\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply presburger    \n  apply(subgoal_tac \"q s\\<noteq>[]\") prefer 2\n  apply (metis length_0_conv less_nat_zero_code)\n  apply (simp add: R_changes_q_dequeue W_items_dont_change_with_R)\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply presburger    \n  apply(subgoal_tac \"length(q s) = 1 \\<longrightarrow> tl(q s) = []\") prefer 2 \n  apply (metis cancel_comm_monoid_add_class.diff_cancel length_greater_0_conv length_tl not_gr0)\n  apply(case_tac \"q s=[]\") prefer 2 \n  apply (metis One_nat_def R_changes_q_dequeue Suc_lessI length_greater_0_conv)\n  apply(simp add:pre_dequeue_inv_def)\n  apply(subgoal_tac \"q s= []\") prefer 2\n  apply blast\n  apply(subgoal_tac \"q s'=[]\") prefer 2\n  using Q_empty_R_step_result [where s=s and s'=s'] \n  apply presburger\n  apply linarith\n  apply(subgoal_tac \"q s\\<noteq>[]\") prefer 2\n  using \\<open>\\<lbrakk>cR_step (pcR s) s s'; q s = []; pcR s = idleR\\<rbrakk> \\<Longrightarrow> q s' = []\\<close> apply presburger\n  apply(subgoal_tac \"q s'= tl(q s)\") prefer 2\n  using R_changes_q_dequeue apply presburger\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply presburger  \n  apply (metis in_set_conv_nth list.set_sel(2) prod.inject tempW_def)\n  using Q_W_relation_through_R_1 [where s=s and s'=s']\n  using \\<open>\\<lbrakk>cR_step (pcR s) s s'; q s = []; pcR s = idleR\\<rbrakk> \\<Longrightarrow> q s' = []\\<close> apply presburger\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply presburger  \n  apply(subgoal_tac \"q s'= tl(q s)\") prefer 2\n  using R_changes_q_dequeue \n  using \\<open>\\<lbrakk>cR_step (pcR s) s s'; q s = []; pcR s = idleR\\<rbrakk> \\<Longrightarrow> q s' = []\\<close> apply presburger\n  apply(subgoal_tac \"offset s = offset s' \\<and>  numEnqs s = numEnqs s'\") prefer 2\n  using W_items_dont_change_with_R [where s=s and s'=s']\n  apply presburger\n  apply (metis Nat.add_0_right \\<open>\\<lbrakk>cR_step (pcR s) s s'; q s = []; pcR s = idleR\\<rbrakk> \\<Longrightarrow> q s' = []\\<close> \\<open>cR_step (pcR s) s s' \\<Longrightarrow> offset s = offset s' \\<and> Data s (numEnqs s) = Data s' (numEnqs s') \\<and> numEnqs s = numEnqs s'\\<close> hd_in_set in_set_conv_nth less_not_refl list.set_sel(2) nat_add_left_cancel_less)\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply presburger  \n  apply(subgoal_tac \"offset s = offset s'\") prefer 2\n  using \\<open>cR_step (pcR s) s s' \\<Longrightarrow> offset s = offset s' \\<and> Data s (numEnqs s) = Data s' (numEnqs s') \\<and> numEnqs s = numEnqs s'\\<close> apply presburger\n  apply(subgoal_tac \"Data s' (numEnqs s') = Data s (numEnqs s)\") prefer 2 \n  apply (metis \\<open>cR_step (pcR s) s s' \\<Longrightarrow> offset s = offset s' \\<and> Data s (numEnqs s) = Data s' (numEnqs s') \\<and> numEnqs s = numEnqs s'\\<close>)\n  apply(subgoal_tac \"\\<forall>j. offset s \\<le> j \\<and> j < offset s + Data s (numEnqs s) \\<longrightarrow> ownB s j = W\") prefer 2 \n  apply presburger\n  apply(clarify)  \n  using ownB_by_W_doesnt_change_after_dequeue [where s=s and s'=s' and i=j]\n  apply (metis PCR.distinct(1) PCR.distinct(5) \\<open>\\<And>i. \\<lbrakk>RingBuffer_BD_latest_2.inv s; con_assms s; cR_step (pcR s) s s'; pcR s = Release \\<longrightarrow> pre_Release_inv s; pcR s = Read \\<longrightarrow> pre_Read_inv s; pcR s = idleR \\<longrightarrow> pre_dequeue_inv s; ownB s i = W \\<and> i \\<le> N\\<rbrakk> \\<Longrightarrow> ownB s' i = W \\<and> i \\<le> N\\<close> assms(2) le_trans less_or_eq_imp_le)\n  apply(simp add:tempW_reflects_writes_def)\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using PCR.distinct(1) PCR.distinct(3) assms(2) apply presburger\n  apply(simp add: pre_Read_inv_def)\n  apply(subgoal_tac \"data_index s (offset s, Data s (numEnqs s)) = numEnqs s\") prefer 2\n  apply meson\n  apply(subgoal_tac \"data_index s = data_index s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using PCR.distinct(1) PCR.distinct(3) assms(2) apply presburger\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (metis W_items_dont_change_with_R)\n  apply(simp add:tempW_reflects_writes_def)\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using PCR.distinct(1) PCR.distinct(5) assms(2) apply presburger\n  apply(simp add: pre_Read_inv_def)\n  apply(subgoal_tac \"data_index s (offset s, Data s (numEnqs s)) = numEnqs s\") prefer 2\n  apply meson\n  apply(subgoal_tac \"data_index s = data_index s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using PCR.distinct(1) PCR.distinct(5) assms(2) apply presburger\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (metis W_items_dont_change_with_R)\n  apply(simp add:tempW_reflects_writes_def)\n  apply(subgoal_tac \"hW s = hW s' \\<and> tW s = tW s' \\<and> tempW s = tempW s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  using PCR.distinct(3) PCR.distinct(5) assms(2) apply presburger\n  apply(simp add: pre_Read_inv_def)\n  apply(subgoal_tac \"data_index s (offset s, Data s (numEnqs s)) = numEnqs s\") prefer 2\n  apply meson\n  apply(subgoal_tac \"data_index s = data_index s'\") prefer 2\n  using W_items_dont_change_with_R_2 [where s=s and s'=s']\n  apply (metis)\n  using W_items_dont_change_with_R_2 [where s=s and s'=s'] \n  apply (metis W_items_dont_change_with_R)\n  apply(simp add:cR_step_def)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(simp add:cR_step_def)\n  apply(simp add:pre_Read_inv_def)\n  apply(simp add:cR_step_def)\n  apply(case_tac \" tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \" ownT s = R\", simp_all)\n  apply(case_tac \" ownT s = R\", simp_all)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \" ownT s = Q\", simp_all)\n  apply(simp add:cR_step_def)\n  apply(simp add:cR_step_def)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(simp add:cR_step_def)\n  apply(simp add:cR_step_def)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"q s=[]\", simp_all)\n  by(simp add:cR_step_def)\n\n\n\n\n\n\n\n\nlemma pre_A1_doesnt_change_with_R:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_A1_inv s\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"pre_A1_inv s'\"\n  using assms apply simp\n  apply(simp add:pre_A1_inv_def) \n  apply(intro conjI impI)\n  apply(simp add:cR_step_def)\n  apply(cases \"pcR s\", simp_all) \n  apply(cases \" tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all) \n  apply(simp add:pre_R_def pre_Release_inv_def inv_def) \n  apply(case_tac \"case_1 s\") apply simp apply(simp add:case_1_def) apply metis\n  apply(simp) apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis (no_types, hide_lams) diff_is_0_eq le0 nat_neq_iff zero_less_diff)\n  apply(simp add:pre_R_def pre_Release_inv_def inv_def)\n  apply(simp add:pre_R_def pre_Release_inv_def inv_def)\n  apply(case_tac \"case_1 s\") apply simp apply(simp add:case_1_def) \n  apply (metis Nat.add_diff_assoc diff_diff_left diff_is_0_eq' linorder_neqE_nat nat_le_linear zero_less_diff)\n  apply(simp) apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis not_add_less1)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(case_tac \" ownT s = Q \", simp_all)\n  apply(simp add:pre_R_def pre_Release_inv_def inv_def)\n  apply(cases \"pcR s\", simp_all)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all) \n  apply(simp add:pre_R_def pre_Release_inv_def inv_def)\n  apply(case_tac \"ownT s = R\", simp_all) \n  apply(simp add:pre_R_def pre_Release_inv_def inv_def)\n  apply(simp add:pre_R_def pre_dequeue_inv_def inv_def)\n  apply(simp add:cR_step_def)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(simp add:pre_R_def pre_Read_inv_def inv_def cR_step_def)\n  apply(simp add:pre_R_def pre_Read_inv_def inv_def cR_step_def)\n  apply(cases \"pcR s\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all) \n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac \"case_1 s\") apply simp apply(simp add:case_1_def) apply metis\n  apply(simp) apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis diff_self_eq_0 le_antisym le_neq_implies_less length_greater_0_conv less_imp_Suc_add nat.distinct(1) plus_nat.add_0)\n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac \"ownT s = R\", simp_all) \n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac \"case_1 s\") apply simp apply(simp add:case_1_def) \n  apply (metis bot_nat_0.extremum_uniqueI diff_self_eq_0 le_add_diff_inverse le_antisym length_0_conv)\n  apply(simp) apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis not_add_less1)\n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(case_tac \" ownT s = Q \", simp_all)\n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(cases \"pcR s\", simp_all)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(cases \"pcR s\", simp_all)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(cases \"pcR s\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all) \n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac \"case_1 s\") apply simp apply(simp add:case_1_def) apply metis\n  apply(simp) apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis add_cancel_right_left le_refl)\n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac \"ownT s = R\", simp_all) \n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac \"case_1 s\") apply simp apply(simp add:case_1_def) \n  apply (metis le_add_diff_inverse le_eq_less_or_eq)\n  apply(simp) apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis (no_types, hide_lams) le_add_diff_inverse le_trans less_or_eq_imp_le linorder_neqE_nat nat_less_le)\n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(case_tac \" ownT s = Q \", simp_all)\n  apply(simp add:pre_R_def pre_dequeue_inv_def inv_def)\n  apply(case_tac \"case_1 s\") apply simp apply(simp add:case_1_def)\n  apply (metis le_antisym nat_less_le)\n  apply(simp) apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis (no_types, lifting) F.distinct(19))\n  apply(case_tac \"case_1 s\") apply simp apply(simp add:case_1_def) \n  apply (metis F.distinct(13) F.distinct(17) le_eq_less_or_eq)\n  apply(simp) apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply(simp add:pre_R_def pre_dequeue_inv_def inv_def)\n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(cases \"pcR s\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all) \n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac \"case_1 s\") apply simp apply(simp add:case_1_def) \n  apply (metis le_add_diff_inverse le_eq_less_or_eq)\n  apply(simp) apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis (no_types, hide_lams) le_add_diff_inverse le_trans less_or_eq_imp_le linorder_neqE_nat nat_less_le)\n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac \"ownT s = R\", simp_all) \n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply (metis le_eq_less_or_eq nat_le_linear)\n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(case_tac \" ownT s = Q \", simp_all)\n  apply(simp add:pre_R_def pre_dequeue_inv_def inv_def)\n  apply (metis (no_types, hide_lams) F.distinct(19))\n  apply(simp add:pre_R_def pre_dequeue_inv_def inv_def)\n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(cases \"pcR s\", simp_all)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(cases \"pcR s\", simp_all)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(cases \"pcR s\", simp_all)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(cases \"pcR s\", simp_all)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(cases \"pcR s\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all) \n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac \"ownT s = R\", simp_all) \n  apply(simp add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  by(case_tac \"q s = []\", simp_all)\n\n\n\nlemma pre_A2_doesnt_change_with_R:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_A2_inv s\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"pre_A2_inv s'\"\n  using assms apply simp\n  apply(simp add:pre_A2_inv_def) \n  apply(intro conjI impI)\n  apply(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac[!] \"pcR s\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all) \n  apply(case_tac \"ownT s = R\", simp_all) \n  apply(case_tac \"q s = []\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all) \n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all) \n  apply(case_tac \"ownT s = R\", simp_all) \n  apply(case_tac \"q s = []\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all) \n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all) \n  apply(case_tac \"ownT s = R\", simp_all) \n  apply(case_tac \"q s = []\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all) \n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def) \n  apply(case_tac \"q s = []\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all) \n  apply(case_tac \"q s = []\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all) \n  apply(simp_all add:pre_R_def pre_dequeue_inv_def inv_def cR_step_def) \n  apply (metis (no_types, hide_lams) F.distinct(19))\n  apply(case_tac \"T s \\<noteq> fst (tempR s)\", simp_all)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply metis\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis add_cancel_right_left le_trans)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis (no_types, lifting) F.distinct(13) eq_imp_le less_imp_le_nat linorder_neqE_nat trans_le_add1)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis Suc_leI not_less_eq_eq trans_le_add1)\n  apply(case_tac \"q s = []\", simp_all)\n  apply metis\n  apply metis\n  apply metis\n  apply(case_tac \"T s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis (no_types, lifting) F.distinct(19))\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis Suc_leI not_less_eq_eq trans_le_add1)\n  apply(case_tac \"T s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis (no_types, lifting) F.distinct(19))\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis Suc_leI not_less_eq_eq trans_le_add1)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(case_tac \"T s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis (no_types, lifting) F.distinct(19))\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis Suc_leI not_less_eq_eq trans_le_add1)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis le_add_diff_inverse le_eq_less_or_eq)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis Suc_leI not_less_eq_eq)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(case_tac \"T s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(case_tac \"q s = []\", simp_all)\n  apply(case_tac \"q s = []\", simp_all)\n  apply blast\n  by(simp_all add:pre_R_def pre_Read_inv_def inv_def cR_step_def)\n\n\n\n\n\nlemma pre_A3_doesnt_change_with_R:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_A3_inv s\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"pre_A3_inv s'\"\n  using assms apply simp\n  apply(simp add:pre_A3_inv_def) \n  apply(intro conjI impI)\n  apply(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac[!] \"pcR s\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  by(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n\n\n\n\nlemma pre_A4_doesnt_change_with_R:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_A4_inv s\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"pre_A4_inv s'\"\n  using assms apply simp\n  apply(simp add:pre_A4_inv_def) \n  apply(intro conjI impI)\n  apply(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac[!] \"pcR s\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)\n  apply(simp_all add:pre_R_def pre_dequeue_inv_def inv_def cR_step_def)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis (no_types, lifting) F.distinct(19))\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis (no_types, hide_lams) F.distinct(19))\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis (no_types, lifting) F.distinct(19))\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis add_cancel_right_left le_trans)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis F.distinct(13) eq_imp_le less_imp_le_nat linorder_neqE_nat trans_le_add1)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis Suc_leI not_less_eq_eq trans_le_add1)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply metis+\n  apply(case_tac \"q s=[]\", simp_all)\n  by metis+\n  \n\n\n\nlemma pre_A5_doesnt_change_with_R:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_A5_inv s\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"pre_A5_inv s'\"\n  using assms apply simp\n  apply(simp add:pre_A5_inv_def) \n  apply(intro conjI impI)\n  apply(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac[!] \"pcR s\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)\n  apply(simp_all add:pre_R_def pre_dequeue_inv_def inv_def cR_step_def)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis (no_types, lifting) F.distinct(19))\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis (no_types, hide_lams) F.distinct(19))\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis (no_types, lifting) F.distinct(19))\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis add_cancel_right_left le_trans)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis F.distinct(13) eq_imp_le less_imp_le_nat linorder_neqE_nat trans_le_add1)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis Suc_leI not_less_eq_eq trans_le_add1)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis le_add_diff_inverse le_trans)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis Suc_leI not_less_eq_eq)\n  apply(case_tac \"q s=[]\", simp_all)\n  by(case_tac \"q s=[]\", simp_all)\n  \n\n\n\nlemma pre_A6_doesnt_change_with_R:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_A6_inv s\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"pre_A6_inv s'\"\n  using assms apply simp\n  apply(simp add:pre_A6_inv_def) \n  apply(intro conjI impI)\n  apply(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac[!] \"pcR s\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)\n  apply(simp_all add:pre_R_def pre_dequeue_inv_def inv_def cR_step_def)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis (no_types, lifting) F.distinct(19))\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis (no_types, hide_lams) F.distinct(19))\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis (no_types, lifting) F.distinct(19))\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis add_cancel_right_left le_trans)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"T s \\<noteq> fst (tempR s)\", simp_all)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis F.distinct(13) eq_imp_le less_imp_le_nat linorder_neqE_nat trans_le_add1)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis Suc_leI not_less_eq_eq trans_le_add1)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis le_add_diff_inverse le_trans)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis Suc_leI not_less_eq_eq)\n  apply(case_tac \"q s=[]\", simp_all)\n  by(case_tac \"q s=[]\", simp_all)\n\n\n\n\n\n\nlemma pre_A7_doesnt_change_with_R:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_A7_inv s\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"pre_A7_inv s'\"\n  using assms apply simp\n  apply(simp add:pre_A7_inv_def) \n  apply(intro conjI impI)\n  apply(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac[!] \"pcR s\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)\n  apply(simp_all add:pre_R_def pre_dequeue_inv_def inv_def cR_step_def)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis (no_types, lifting) F.distinct(19))\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis (no_types, hide_lams) F.distinct(19))\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis (no_types, lifting) F.distinct(19))\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis add_cancel_right_left le_trans)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"T s \\<noteq> fst (tempR s)\", simp_all)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis F.distinct(13) eq_imp_le less_imp_le_nat linorder_neqE_nat trans_le_add1)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis Suc_leI not_less_eq_eq trans_le_add1)\n  apply(simp add:tempR_lemmas tempR_basic_lemmas Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis le_add_diff_inverse le_trans)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis Suc_leI not_less_eq_eq)\n  apply(case_tac \"q s=[]\", simp_all)\n  by(case_tac \"q s=[]\", simp_all)\n\n\n\n\n\nlemma pre_A8_doesnt_change_with_R:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_A8_inv s\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"pre_A8_inv s'\"\n  using assms apply simp\n  apply(simp add:pre_A8_inv_def) \n  apply(intro conjI impI)\n  apply(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac[!] \"pcR s\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)\n  apply(simp_all add:pre_R_def pre_dequeue_inv_def inv_def cR_step_def)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis (no_types, lifting) F.distinct(19))\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis (no_types, hide_lams) F.distinct(19))\n  apply(case_tac \"q s=[]\", simp_all) \n  apply (metis (no_types, lifting) F.distinct(19))\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all) \n  apply metis\n  apply metis\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply metis\n  apply metis\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all) \n  apply(case_tac \"ownT s =R\", simp_all) \n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all) \n  apply(case_tac \"ownT s =R\", simp_all) \n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all) \n  apply(case_tac \"ownT s =R\", simp_all) \n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all) \n  apply(case_tac \"ownT s =R\", simp_all) \n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all) \n  apply(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis (no_types, lifting) F.distinct(19))\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis add_cancel_right_left le_trans)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis le_add_diff_inverse le_eq_less_or_eq)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis Suc_leI not_less_eq_eq trans_le_add1)\n  apply(case_tac \"q s=[]\", simp_all) \n  apply metis+\n  apply(case_tac \"q s=[]\", simp_all)\n  by metis+\n\n\n\n\n\nlemma pre_acquire_doesnt_change_with_R:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_acquire_inv s\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"pre_acquire_inv s'\"\n  using assms apply simp\n  apply(simp add:pre_acquire_inv_def) \n  apply(intro conjI impI)\n  apply(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac[!] \"pcR s\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply metis\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis eq_imp_le less_imp_le_nat linorder_neqE_nat plus_nat.add_0)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis diff_is_0_eq' linorder_neqE_nat nat_le_linear zero_less_diff)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis eq_imp_le less_imp_le_nat linorder_neqE_nat plus_nat.add_0)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all) \n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis diff_is_0_eq' linorder_neqE_nat nat_le_linear zero_less_diff)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis add_cancel_right_left diff_add_inverse2 le_0_eq le_antisym length_0_conv nat_less_le)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis bot_nat_0.extremum_uniqueI diff_self_eq_0 le_add_diff_inverse le_antisym length_0_conv)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis not_add_less1)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis bot_nat_0.extremum_uniqueI diff_self_eq_0 le_add_diff_inverse le_antisym length_0_conv)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis le_antisym le_neq_implies_less less_imp_Suc_add nat.distinct(1) ordered_cancel_comm_monoid_diff_class.le_imp_diff_is_add plus_nat.add_0)\n  apply(case_tac \"ownT s =R\", simp_all) \n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def) \n  apply (metis Nat.add_0_right diff_self_eq_0 le_add_diff_inverse le_antisym le_zero_eq)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis not_add_less1)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis bot_nat_0.extremum_uniqueI diff_self_eq_0 le_add_diff_inverse le_antisym length_0_conv)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis less_or_eq_imp_le plus_nat.add_0)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis le_add_diff_inverse le_eq_less_or_eq)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis le_add_diff_inverse le_trans less_nat_zero_code less_or_eq_imp_le nat_less_le nat_neq_iff)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)\n  apply(simp add:pre_dequeue_inv_def)\n  apply (metis (mono_tags, hide_lams) F.distinct(19))\n  apply(simp add:pre_dequeue_inv_def)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply (metis le_add_diff_inverse le_eq_less_or_eq)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply (metis plus_nat.add_0)\n  apply (metis le_add_diff_inverse le_trans less_nat_zero_code less_or_eq_imp_le nat_less_le nat_neq_iff)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)\n  apply(simp add:pre_dequeue_inv_def)\n  apply (metis (mono_tags, hide_lams) F.distinct(19))\n  apply(simp add:pre_dequeue_inv_def)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  by(case_tac \"q s=[]\", simp_all)\n\n\n\nlemma pre_OOM_doesnt_change_with_R:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_OOM_inv s\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"pre_OOM_inv s'\"\n  using assms apply simp\n  apply(simp add:pre_OOM_inv_def) \n  apply(intro conjI impI)\n  apply(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac[!] \"pcR s\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)\n  apply(simp_all add:pre_R_def pre_dequeue_inv_def inv_def cR_step_def)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all) \n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all) \n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"case_1 s\", simp_all) apply(simp add:case_1_def)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(simp add:case_2_def) apply(thin_tac \"\\<not>case_1 s\")\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac \"q s=[]\", simp_all) \n  apply (metis (no_types, lifting) F.distinct(19))\n  apply(case_tac \"q s=[]\", simp_all) \n  apply(case_tac \"q s=[]\", simp_all) \n  apply(case_tac \"q s=[]\", simp_all) \n  apply(case_tac \"T s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all) \n  apply(case_tac \"q s=[]\", simp_all) \n  apply(case_tac \"q s=[]\", simp_all) \n  apply(case_tac \"q s=[]\", simp_all) \n  apply blast\n  by(simp_all add:pre_R_def pre_Read_inv_def inv_def cR_step_def)\n  \n\n\n\n\nlemma pre_finished_doesnt_change_with_R:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_finished_inv s\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"pre_finished_inv s'\"\n  using assms apply simp\n  apply(simp add:pre_finished_inv_def) \n  apply(intro conjI impI)\n  apply(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac[!] \"pcR s\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  by(case_tac \"q s=[]\", simp_all)\n\n\n\n\n\n\nlemma pre_BTS_doesnt_change_with_R:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_BTS_inv s\"\n  and \"pre_R (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"pre_BTS_inv s'\"\n  using assms apply simp\n  apply(simp add:pre_BTS_inv_def) \n  apply(intro conjI impI)\n  apply(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac[!] \"pcR s\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s =R\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)\n  apply(simp_all add:pre_R_def pre_dequeue_inv_def inv_def cR_step_def)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply(case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n  apply(case_tac \"ownT s = R\", simp_all)\n  apply(simp_all add:pre_R_def pre_Release_inv_def inv_def cR_step_def)\n  apply(case_tac \"q s=[]\", simp_all)\n  apply blast\n  by(simp_all add:pre_R_def pre_Read_inv_def inv_def cR_step_def)\n \n\n\n\n(*******************************GLOBAL R_step preserves preW*************************************)\n\n\n\nlemma GLOBAL_R_step_shows_preW:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"pre_R (pcR s) s\"\n  and \"pre_W (pcW s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"pre_W (pcW s') s'\"\n  using assms apply simp\n  apply(subgoal_tac \"pcW s' = pcW s\") prefer 2\n  using pcW_doesnt_change_with_R [where s=s and s'=s']\n  apply simp\n  apply(simp add:pre_W_def) apply(case_tac \"pcW s\") apply simp_all\n  using pre_A1_doesnt_change_with_R [where s=s and s'=s'] apply simp\n  using pre_A2_doesnt_change_with_R [where s=s and s'=s'] apply simp\n  using pre_A3_doesnt_change_with_R [where s=s and s'=s'] apply simp\n  using pre_A4_doesnt_change_with_R [where s=s and s'=s'] apply simp\n  using pre_A5_doesnt_change_with_R [where s=s and s'=s'] apply simp\n  using pre_A6_doesnt_change_with_R [where s=s and s'=s'] apply simp\n  using pre_A7_doesnt_change_with_R [where s=s and s'=s'] apply simp\n  using pre_A8_doesnt_change_with_R [where s=s and s'=s'] apply simp\n  using pre_enqueue_doesnt_change_with_R [where s=s and s'=s'] apply simp \n  using pre_acquire_doesnt_change_with_R [where s=s and s'=s'] apply simp\n  using pre_OOM_doesnt_change_with_R [where s=s and s'=s'] apply simp\n  using pre_finished_doesnt_change_with_R [where s=s and s'=s'] apply simp\n  using pre_write_doesnt_change_with_R [where s=s and s'=s'] apply simp  \n  using pre_BTS_doesnt_change_with_R [where s=s and s'=s'] by simp\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n(*writer side enqueue------------------------*)\nlemma enqueue_preserves_Q_n_n:\n  assumes \"q s\\<noteq>[]\"\n  and \"Q_structure s\"\n  and \"Q_enqueue s s'\"\n  and \"numDeqs s<numEnqs s\"\n  and \"length(q s) = numEnqs s-numDeqs s\"\n  and \"pre_enqueue_inv s\"\n  and \"ownD s(numEnqs s) =B\"\n  and \"ownT s \\<noteq>W\"\n  and \"numWrites s\\<ge>numReads s\"\nshows \"Q_structure s'\"\n  using assms apply (simp)\n  apply (case_tac \"ownT s = W\", simp_all)\n  apply(simp add:Q_structure_def) apply(intro conjI impI)\n  apply(simp add:Q_basic_lemmas) apply(intro conjI impI)\n  apply(simp add:pre_enqueue_inv_def) \n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:pre_enqueue_inv_def) \n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(subgoal_tac \"\\<forall>i. i < length (q s) \\<and> 0 < i \\<longrightarrow>\n        fst ((q s @ [(offset s, Data s (numEnqs s))]) ! (i - Suc 0)) +\n        snd ((q s @ [(offset s, Data s (numEnqs s))]) ! (i - Suc 0)) =\n        fst ((q s @ [(offset s, Data s (numEnqs s))]) ! i) \\<or>\n        fst ((q s @ [(offset s, Data s (numEnqs s))]) ! i) = 0\") prefer 2 apply clarify \n  apply (smt (z3) Suc_lessD Suc_pred nat_neq_iff nth_append)\n  apply(subgoal_tac \"fst(tempW s) =end(last(q s)) \\<or> fst(tempW s) =0\")\n  prefer 2 \n  apply (metis end_simp fst_conv tempW_def)\n  apply(subgoal_tac \"last(q s) =(q s!(length(q s)-1))\") prefer 2\n  apply (metis last_conv_nth)\n  apply clarify\n  apply(subgoal_tac \"offset s =0\\<longrightarrow>(\\<forall>i.(i<length(q s))\\<longrightarrow>fst(q s!i)\\<noteq>0)\") prefer 2\n  apply metis\n  apply(subgoal_tac \"(\\<exists>i.(i<length(q s)\\<and>fst(q s!i) =0))\\<longrightarrow>offset s\\<noteq>0\") prefer 2\n  apply blast\n  apply(case_tac \"offset s=0\")\n  apply (metis (no_types, lifting) One_nat_def diff_Suc_less end_simp less_antisym nat_neq_iff nth_append nth_append_length tempW_def)\n  apply (metis (no_types, lifting) One_nat_def diff_Suc_less end_simp less_antisym nat_neq_iff nth_append nth_append_length tempW_def)\n  apply(simp add:pre_enqueue_inv_def) \n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply (smt (z3) less_antisym nth_append nth_append_length prod.collapse prod.inject)\n  apply(simp add:pre_enqueue_inv_def) \n  apply(simp add:tempW_lemmas tempW_basic_lemmas)  apply clarify\n  apply(case_tac \"a = offset s \\<and> b = Data s (numEnqs s)\", simp_all)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply (metis (no_types, lifting) fst_eqD in_set_conv_nth less_imp_le_nat)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"aa = offset s \\<and> ba = Data s (numEnqs s)\", simp_all)\n  apply (metis (no_types, lifting) fst_conv in_set_conv_nth snd_conv)\n  apply (metis (no_types, hide_lams))\n  apply(simp add:pre_enqueue_inv_def) \n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:Q_lemmas Q_basic_lemmas) \n  apply (metis (no_types, lifting) fst_eqD in_set_conv_nth nat_neq_iff not_add_less1)\n  apply(simp add:pre_enqueue_inv_def) \n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:pre_enqueue_inv_def) \n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(subgoal_tac \"\\<forall>i<length (q s).\n       data_index s ((q s) ! i) = numDeqs s + i\") prefer 2\n  apply presburger\n  apply(subgoal_tac \"\n       data_index s ((offset s, Data s (numEnqs s))) = numDeqs s + length (q s)\")\n   apply (simp add: nth_append)\n  apply (metis le_add_diff_inverse less_SucE less_imp_le_nat)\n  apply (metis le_add_diff_inverse less_imp_le_nat)\n  apply(simp add:pre_enqueue_inv_def) \n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply (metis (no_types, lifting) le_add_diff_inverse less_SucE less_imp_le_nat nth_append nth_append_length snd_eqD)\n  apply(simp add:pre_enqueue_inv_def) \n  apply(simp add:tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  by (metis le_add_diff_inverse2 less_SucE less_imp_le_nat)\n\n\nlemma enqueue_preserves_Q_n_o:\n  assumes \"q s\\<noteq>[]\n  \\<and> Q_structure s\n  \\<and> Q_enqueue s s'\n  \\<and> numDeqs s<numEnqs s\n  \\<and> numWrites s\\<ge>numReads s\n  \\<and> length(q s) = numEnqs s-numDeqs s\n  \\<and> pre_enqueue_inv s\n  \\<and> ownD s(numEnqs s) =B\n  \\<and> ownT s =W\"\n  shows \"Q_structure s'\"\n  using assms apply (simp)\n  apply (case_tac \"ownT s = W\", simp_all)\n  apply(simp add:Q_structure_def)\n  apply(intro conjI impI)\n  apply(simp add:Q_basic_lemmas)\n  apply(intro conjI impI) apply(simp add:pre_enqueue_inv_def)\n  apply blast\n  apply(simp add:pre_enqueue_inv_def)\n  apply blast\n  apply(simp add:pre_enqueue_inv_def)\n  apply blast\n  apply(simp add:pre_enqueue_inv_def)\n  apply(simp add:pre_enqueue_inv_def)\n  apply(simp add:pre_enqueue_inv_def)\n  apply meson\n  apply(simp add:pre_enqueue_inv_def)\n  apply blast\n  apply(simp add:pre_enqueue_inv_def)\n  apply blast\n  apply(simp add:pre_enqueue_inv_def)\n  by blast\n\n\nlemma enqueue_preserves_Q_e_o:\n  assumes \"q s=[]\n  \\<and> Q_structure s\n  \\<and> Q_enqueue s s'\n  \\<and> numDeqs s=numEnqs s\n  \\<and> length(q s) = numEnqs s-numDeqs s\n  \\<and> pre_enqueue_inv s\n  \\<and> numWrites s\\<ge>numReads s\n  \\<and> ownD s(numEnqs s) =B\n  \\<and> ownT s =W\"\n  shows \"Q_structure s'\"\n  using assms apply simp\n  apply(case_tac \"ownT s = W\", simp_all)\n  apply(simp add:Q_structure_def) apply(intro conjI impI)\n  apply(simp add:Q_basic_lemmas) apply(intro conjI impI)\n  apply(simp add:pre_enqueue_inv_def tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:pre_enqueue_inv_def tempW_lemmas tempW_basic_lemmas)\n  apply (metis gr0I)\n  apply(simp add:pre_enqueue_inv_def tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:Q_holds_bytes_def)\n  apply(simp add:pre_enqueue_inv_def tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:Q_reflects_writes_def)\n  apply(simp add:pre_enqueue_inv_def tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:Q_elem_size_def)\n  apply(simp add:pre_enqueue_inv_def tempW_lemmas tempW_basic_lemmas)\n  by(simp add:Q_reflects_ownD_def)\n\n\nlemma enqueue_preserves_Q_e_n:\n  assumes \"q s=[]\n  \\<and> Q_structure s\n  \\<and> Q_enqueue s s'\n  \\<and> numDeqs s=numEnqs s\n  \\<and> length(q s) = numEnqs s-numDeqs s\n  \\<and> pre_enqueue_inv s\n  \\<and> numWrites s\\<ge>numReads s\n  \\<and> ownD s(numEnqs s) =B\n  \\<and> ownT s \\<noteq>W\"\n  shows \"Q_structure s'\"\n  using assms apply simp\n  apply(case_tac \"ownT s = W\", simp_all)\n  apply(simp add:Q_structure_def) apply(intro conjI impI)\n  apply(simp add:Q_basic_lemmas) apply(intro conjI impI)\n  apply(simp add:pre_enqueue_inv_def tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:pre_enqueue_inv_def tempW_lemmas tempW_basic_lemmas)\n  apply (metis gr0I)\n  apply(simp add:pre_enqueue_inv_def tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:Q_holds_bytes_def)\n  apply(simp add:pre_enqueue_inv_def tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:Q_reflects_writes_def)\n  apply(simp add:pre_enqueue_inv_def tempW_lemmas tempW_basic_lemmas)\n  apply(simp add:Q_elem_size_def)\n  apply(simp add:pre_enqueue_inv_def tempW_lemmas tempW_basic_lemmas)\n  by(simp add:Q_reflects_ownD_def)\n\n\nlemma enqueue_preserves_Q:\n  assumes \"Q_structure s\n  \\<and> Q_enqueue s s'\n  \\<and> length(q s) = numEnqs s-numDeqs s\n  \\<and> pre_enqueue_inv s\n  \\<and> numWrites s\\<ge>numReads s\n  \\<and> numEnqs s\\<ge>numDeqs s\n  \\<and> ownD s(numEnqs s) =B\"\n  shows \"Q_structure s'\"\n  using assms apply simp\n  apply(case_tac \"q s=[]\")\n   apply(case_tac[!] \"ownT s = W\", simp_all) \n     defer defer defer\n(*4*)\n  apply(subgoal_tac \"q s\\<noteq>[]\n  \\<and> Q_structure s\n  \\<and> Q_enqueue s s'\n  \\<and> numDeqs s<numEnqs s\n  \\<and> length(q s) = numEnqs s-numDeqs s\n  \\<and> pre_enqueue_inv s\n  \\<and> numWrites s\\<ge>numReads s\n  \\<and> ownD s(numEnqs s) =B\n  \\<and> ownT s \\<noteq>W\") using enqueue_preserves_Q_n_n \n  apply presburger\n  apply (metis assms length_greater_0_conv zero_less_diff) defer defer\n(*3*)\n  apply(subgoal_tac \"q s\\<noteq>[]\n  \\<and> Q_structure s\n  \\<and> Q_enqueue s s'\n  \\<and> numDeqs s<numEnqs s\n  \\<and> length(q s) = numEnqs s-numDeqs s\n  \\<and> pre_enqueue_inv s\n  \\<and> numWrites s\\<ge>numReads s\n  \\<and> ownD s(numEnqs s) =B\n  \\<and> ownT s =W\") prefer 2 \n  apply (metis assms length_greater_0_conv zero_less_diff) using enqueue_preserves_Q_n_o\nproof -\nassume a1: \"Q_structure s \\<and> s' = s \\<lparr>ownT := Q, numEnqs := Suc (numEnqs s), ownB := \\<lambda>i. if ownB s i = W then Q else ownB ((if ownT s = W then ownT_update (\\<lambda>_. Q) else (\\<lambda>s. s\\<lparr>ownT := ownT s\\<rparr>)) s \\<lparr>numEnqs := Suc (numEnqs s)\\<rparr>) i, pcW := idleW, q := q s @ [(offset s, Data s (numEnqs s))]\\<rparr> \\<and> length (q s) = numEnqs s - numDeqs s \\<and> pre_enqueue_inv s \\<and> numReads s \\<le> numWrites s \\<and> numDeqs s \\<le> numEnqs s \\<and> ownD s (numEnqs s) = B\"\nassume \"q s \\<noteq> []\"\n  assume a2: \"ownT s = W\"\n  assume a3: \"q s \\<noteq> [] \\<and> Q_structure s \\<and> Q_enqueue s s' \\<and> numDeqs s < numEnqs s \\<and> length (q s) = numEnqs s - numDeqs s \\<and> pre_enqueue_inv s \\<and> numReads s \\<le> numWrites s \\<and> ownD s (numEnqs s) = B \\<and> ownT s = W\"\n  have \"\\<forall>r. W \\<noteq> ownT s \\<or> B \\<noteq> ownD s (numEnqs s) \\<or> \\<not> pre_enqueue_inv s \\<or> Q_structure r \\<or> \\<not> numReads s \\<le> numWrites s \\<or> \\<not> numDeqs s < numEnqs s \\<or> \\<not> Q_enqueue s r \\<or> \\<not> Q_structure s \\<or> [] = q s\"\n    using a1 by (smt (z3) enqueue_preserves_Q_n_o)\n  then have \"Q_structure (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s), ownB := \\<lambda>n. if ownB s n = W then Q else ownB ((if ownT s = W then ownT_update (\\<lambda>f. Q) else (\\<lambda>r. r\\<lparr>ownT := ownT r\\<rparr>)) s \\<lparr>numEnqs := Suc (numEnqs s)\\<rparr>) n, pcW := idleW, q := q s @ [(offset s, Data s (numEnqs s))]\\<rparr>)\"\n    using a3 a1 by (metis (full_types))\n  then show \"Q_structure (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s), ownB := \\<lambda>n. if ownB s n = W then Q else ownB (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s)\\<rparr>) n, pcW := idleW, q := q s @ [(offset s, Data s (numEnqs s))]\\<rparr>)\"\n    using a2 by presburger\nnext\n  show \"Q_structure s \\<and>\n    s' = s\n    \\<lparr>numEnqs := Suc (numEnqs s),\n       ownB :=\n         \\<lambda>i. if ownB s i = W then Q\n             else ownB\n                   ((if ownT s = W then ownT_update (\\<lambda>_. Q) else (\\<lambda>s. s\\<lparr>ownT := ownT s\\<rparr>))\n                     s\n                    \\<lparr>numEnqs := Suc (numEnqs s)\\<rparr>)\n                   i,\n       pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr> \\<and>\n    numEnqs s \\<le> numDeqs s \\<and>\n    pre_enqueue_inv s \\<and>\n    numReads s \\<le> numWrites s \\<and> numDeqs s \\<le> numEnqs s \\<and> ownD s (numEnqs s) = B \\<Longrightarrow>\n    q s = [] \\<Longrightarrow>\n    ownT s \\<noteq> W \\<Longrightarrow>\n    (\\<And>s s'.\n        q s \\<noteq> [] \\<and>\n        Q_structure s \\<and>\n        Q_enqueue s s' \\<and>\n        numDeqs s < numEnqs s \\<and>\n        numReads s \\<le> numWrites s \\<and>\n        length (q s) = numEnqs s - numDeqs s \\<and>\n        pre_enqueue_inv s \\<and> ownD s (numEnqs s) = B \\<and> ownT s = W \\<Longrightarrow>\n        Q_structure s') \\<Longrightarrow>\n    Q_structure\n     (s\\<lparr>numEnqs := Suc (numEnqs s),\n          ownB :=\n            \\<lambda>i. if ownB s i = W then Q\n                else ownB (s\\<lparr>ownT := ownT s, numEnqs := Suc (numEnqs s)\\<rparr>) i,\n          pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr>)\"\n(*2*)\n  apply(subgoal_tac \"q s=[]\n  \\<and> Q_structure s\n  \\<and> Q_enqueue s s'\n  \\<and> numEnqs s = numDeqs s\n  \\<and> length(q s) = numEnqs s-numDeqs s\n  \\<and> pre_enqueue_inv s\n  \\<and> numWrites s\\<ge>numReads s\n  \\<and> ownD s(numEnqs s) =B\n  \\<and> ownT s \\<noteq>W\") prefer 2 \n    apply(subgoal_tac \"q s=[]\") prefer 2 apply blast\n    apply(subgoal_tac \"ownT s \\<noteq>W\") prefer 2 apply blast\n    apply(subgoal_tac \"ownD s(numEnqs s) =B\") prefer 2 apply blast\n    apply(subgoal_tac \"pre_enqueue_inv s\") prefer 2 apply blast\n    apply(subgoal_tac \"length(q s) = numEnqs s-numDeqs s\") prefer 2 using assms apply blast \n    apply(subgoal_tac \"Q_structure s\") prefer 2 apply blast\n    apply(subgoal_tac \"Q_enqueue s s'\") prefer 2 using assms apply blast\n    apply(subgoal_tac \"q s=[]\\<longrightarrow>length(q s) = 0\") prefer 2 \n    apply blast\n    apply(subgoal_tac \"numEnqs s = numDeqs s\") \n    apply blast\n    apply(subgoal_tac \"q s\\<noteq>[]\\<longrightarrow>length(q s)\\<ge>0\") prefer 2 \n    apply blast\n    apply(subgoal_tac \"q s=[]\\<longrightarrow>length(q s) =0\") prefer 2\n    apply blast \n    apply(subgoal_tac \"length(q s)\\<ge>0\") prefer 2\n    apply blast\n    apply(subgoal_tac \"numEnqs s \\<ge>0\") prefer 2\n    apply blast\n    apply(subgoal_tac \"numDeqs s \\<ge>0\") prefer 2\n    apply blast\n    apply(subgoal_tac \"(length(q s) = numEnqs s-numDeqs s \\<and> length(q s)\\<ge>0 \\<and> \n                      numEnqs s\\<ge>0 \\<and> numDeqs s\\<ge>0 \\<and> length(q s) = 0)\\<longrightarrow>numEnqs s-numDeqs s=0\") prefer 2\n    apply presburger \n    using dual_order.antisym apply blast\n    using enqueue_preserves_Q_e_n \n  proof -\n    assume a1: \"Q_structure s \\<and> s' = s \\<lparr>numEnqs := Suc (numEnqs s), ownB := \\<lambda>i. if ownB s i = W then Q else ownB ((if ownT s = W then ownT_update (\\<lambda>_. Q) else (\\<lambda>s. s\\<lparr>ownT := ownT s\\<rparr>)) s \\<lparr>numEnqs := Suc (numEnqs s)\\<rparr>) i, pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr> \\<and> numEnqs s \\<le> numDeqs s \\<and> pre_enqueue_inv s \\<and> numReads s \\<le> numWrites s \\<and> numDeqs s \\<le> numEnqs s \\<and> ownD s (numEnqs s) = B\"\n    assume \"q s = []\"\n    assume a2: \"ownT s \\<noteq> W\"\n    assume a3: \"q s = [] \\<and> Q_structure s \\<and> Q_enqueue s s' \\<and> numEnqs s = numDeqs s \\<and> length (q s) = numEnqs s - numDeqs s \\<and> pre_enqueue_inv s \\<and> numReads s \\<le> numWrites s \\<and> ownD s (numEnqs s) = B \\<and> ownT s \\<noteq> W\"\n    then have \"\\<forall>r. numDeqs s - numDeqs s \\<noteq> length (q s) \\<or> B \\<noteq> ownD s (numEnqs s) \\<or> Q_structure r \\<or> \\<not> Q_enqueue s r \\<or> [] \\<noteq> q s\"\n      by (metis (full_types) enqueue_preserves_Q_e_n)\n    then have \"Q_structure (s\\<lparr>numEnqs := Suc (numEnqs s), ownB := \\<lambda>n. if ownB s n = W then Q else ownB ((if ownT s = W then ownT_update (\\<lambda>f. Q) else (\\<lambda>r. r\\<lparr>ownT := ownT r\\<rparr>)) s \\<lparr>numEnqs := Suc (numEnqs s)\\<rparr>) n, pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr>)\"\n      using a3 a1 by (metis (full_types))\n    then show ?thesis\n      using a2 by presburger\n  qed\nnext \n(*1*)\n  show \"Q_structure s \\<and>\n    s' = s\n    \\<lparr>ownT := Q, numEnqs := Suc (numEnqs s),\n       ownB :=\n         \\<lambda>i. if ownB s i = W then Q\n             else ownB\n                   ((if ownT s = W then ownT_update (\\<lambda>_. Q) else (\\<lambda>s. s\\<lparr>ownT := ownT s\\<rparr>))\n                     s\n                    \\<lparr>numEnqs := Suc (numEnqs s)\\<rparr>)\n                   i,\n       pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr> \\<and>\n    numEnqs s \\<le> numDeqs s \\<and>\n    pre_enqueue_inv s \\<and>\n    numReads s \\<le> numWrites s \\<and> numDeqs s \\<le> numEnqs s \\<and> ownD s (numEnqs s) = B \\<Longrightarrow>\n    q s = [] \\<Longrightarrow>\n    ownT s = W \\<Longrightarrow>\n    (\\<And>s s'.\n        q s \\<noteq> [] \\<and>\n        Q_structure s \\<and>\n        Q_enqueue s s' \\<and>\n        numDeqs s < numEnqs s \\<and>\n        numReads s \\<le> numWrites s \\<and>\n        length (q s) = numEnqs s - numDeqs s \\<and>\n        pre_enqueue_inv s \\<and> ownD s (numEnqs s) = B \\<and> ownT s = W \\<Longrightarrow>\n        Q_structure s') \\<Longrightarrow>\n    Q_structure\n     (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s),\n          ownB :=\n            \\<lambda>i. if ownB s i = W then Q\n                else ownB (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s)\\<rparr>) i,\n          pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr>)\"\n  apply(subgoal_tac \"q s=[]\n  \\<and> Q_structure s\n  \\<and> Q_enqueue s s'\n  \\<and> numDeqs s=numEnqs s\n  \\<and> length(q s) = numEnqs s-numDeqs s\n  \\<and> pre_enqueue_inv s\n  \\<and> ownD s(numEnqs s) =B\n  \\<and> ownT s =W\") prefer 2 \n    using assms verit_la_disequality apply blast using enqueue_preserves_Q_e_o\nproof -\nassume a1: \"Q_structure s \\<and> s' = s \\<lparr>ownT := Q, numEnqs := Suc (numEnqs s), ownB := \\<lambda>i. if ownB s i = W then Q else ownB ((if ownT s = W then ownT_update (\\<lambda>_. Q) else (\\<lambda>s. s\\<lparr>ownT := ownT s\\<rparr>)) s \\<lparr>numEnqs := Suc (numEnqs s)\\<rparr>) i, pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr> \\<and> numEnqs s \\<le> numDeqs s \\<and> pre_enqueue_inv s \\<and> numReads s \\<le> numWrites s \\<and> numDeqs s \\<le> numEnqs s \\<and> ownD s (numEnqs s) = B\"\n  assume \"q s = []\"\nassume a2: \"ownT s = W\"\nassume a3: \"q s = [] \\<and> Q_structure s \\<and> Q_enqueue s s' \\<and> numDeqs s = numEnqs s \\<and> length (q s) = numEnqs s - numDeqs s \\<and> pre_enqueue_inv s \\<and> ownD s (numEnqs s) = B \\<and> ownT s = W\"\nthen have \"\\<forall>r. B \\<noteq> ownD s (numEnqs s) \\<or> Q_structure r \\<or> \\<not> Q_enqueue s r\"\nusing a1 enqueue_preserves_Q_e_o by blast\n  then have \"Q_structure (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s), ownB := \\<lambda>n. if ownB s n = W then Q else ownB ((if ownT s = W then ownT_update (\\<lambda>f. Q) else (\\<lambda>r. r\\<lparr>ownT := ownT r\\<rparr>)) s \\<lparr>numEnqs := Suc (numEnqs s)\\<rparr>) n, pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr>)\"\nusing a3 a1 by (metis (full_types))\n  then show ?thesis\n    using a2 by presburger\nqed\nqed\n\n\n\n\n(*----------enqueue end-----------------------*)\n\n\n\n\n\n\n(*****************old stuff************************************************************)\n\n\n\n(*\n\nlemma Q_no_buffer_overlap_lemma_2:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  and \"con_assms s\"\n  and \"case_1 s\"\nshows \"\\<exists>b c.(b<c\\<and> c\\<le>N \\<and> (\\<forall>i.(b\\<ge>i\\<and>c<i)\\<longrightarrow>ownB s i=Q) \\<and> b=fst(q s ! 0) \\<and> c=end(last(q s)))\"\n  using assms apply simp\n  apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas case_1_def) \n  by (metis (no_types, lifting) assms(2) diff_is_0_eq' head_q0 le_eq_less_or_eq less_trans_Suc not_less_eq_eq)\n\nlemma Q_no_buffer_overlap_lemma_3:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  and \"con_assms s\"\n  and \"case_1 s\"\nshows \"fst(hd(q s))<end(last(q s))\"\n  using assms apply simp\n  apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas case_1_def) \n  by (metis (no_types, lifting) assms(2) diff_is_0_eq' head_q0 le_eq_less_or_eq less_trans_Suc not_less_eq_eq)\n\nlemma Q_no_buffer_overlap_lemma_4:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  and \"con_assms s\"\n  and \"case_1 s\"\n  and \"ownB s 0 = Q\"\nshows \"\\<forall>i.(i<length(q s) \\<and> i>0)\\<longrightarrow>fst(q s!i) = end(q s!(i-1))\"\n  using assms apply simp\n  apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas case_1_def)\n  by (metis F.distinct(11) F.distinct(19) F.distinct(3) assms(2) head_q0 le_add2 le_add_same_cancel2 not_gr0)\n\n\n\nlemma Q_no_buffer_overlap_lemma_5:\n  assumes \"Q_structure s\"\n  and \"length(q s) >0\"\n  and \"inv s\"\n  and \"con_assms s\"\n  and \"case_1 s\"\nshows \"\\<forall>i.(i<length(q s) \\<and> i>0)\\<longrightarrow>fst(q s!i) = end(q s!(i-1))\"\n  using assms apply simp\n  apply (simp add:con_assms_def Q_lemmas Q_basic_lemmas case_1_def inv_def) \n  using case_1_Q_struct [where s=s]\n  by (metis One_nat_def assms(1) assms(5) end_simp)\n\n\nlemma Q_no_buffer_overlap_lemma_6:\n  assumes \"Q_structure s\"\n  and \"length(q s)>0\"\n  and \"inv s\"\n  and \"con_assms s\"\n  and \"case_1 s\"\nshows \"\\<forall>i j.(i=j+1 \\<and> i<length(q s) \\<and> j\\<ge>0)\\<longrightarrow>fst(q s!i) = end(q s!j)\"\n  using Q_no_buffer_overlap_lemma_5 \n  by (metis add_diff_cancel_right' add_nonneg_pos assms(1) assms(2) assms(3) assms(4) assms(5) zero_less_one)\n\n\nlemma Q_no_buffer_overlap_lemma_7:\n  assumes \"Q_structure s\"\n  and \"length(q s)>0\"\n  and \"inv s\"\n  and \"con_assms s\"\n  and \"case_1 s\"\nshows \"\\<forall>i j.(i=j+1 \\<and> i<length(q s) \\<and> j\\<ge>0)\\<longrightarrow>fst(q s!i) > fst(q s!j)\"\n  by (metis Q_gap_lemmas_5_list Q_no_buffer_overlap_lemma_6 add_lessD1 assms(1) assms(2) assms(3) assms(4) assms(5) nat_le_linear)\n  \n\nlemma Q_no_buffer_overlap_lemma_8:\n  assumes \"Q_structure s\"\n  and \"length(q s)>0\"\n  and \"inv s\"\n  and \"con_assms s\"\n  and \"case_1 s\"\nshows \"\\<forall>i j.( i<length(q s) \\<and> j>0 \\<and> i>j \\<and> fst(q s!i)>fst(q s!j))\\<longrightarrow>fst(q s!i) > fst(q s!(j-1))\"\n  using Q_no_buffer_overlap_lemma_5 assms(1) assms(3) assms(4) assms(5) by fastforce\n\n\n\nlemma Q_no_buffer_overlap_lemma_9:\n  assumes \"Q_structure s\"\n  and \"length(q s)>0\"\n  and \"inv s\"\n  and \"con_assms s\"\n  and \"case_1 s\"\nshows \"\\<forall>i.(ownB s i = Q \\<and> i<N)\\<longrightarrow>(\\<exists>a b.((a,b)\\<in>set(q s)\\<and> a\\<le>i \\<and> i<a+b))\"\n  using assms apply simp\n  apply(simp add:inv_def Q_lemmas Q_basic_lemmas con_assms_def case_1_def)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def butlast_def)\n  by (metis (no_types, lifting) mem_Collect_eq)\n  \n\nlemma Q_overlap_lemma_1:\n  assumes \"Q_structure s\"\n  and \"length(q s)>0\"\n  and \"inv s\"\n  and \"con_assms s\"\nshows \"\\<forall>i.(ownB s i = Q \\<and> i<N)\\<longrightarrow>(\\<exists>a b.((a,b)\\<in>set(q s)\\<and> a\\<le>i \\<and> i<a+b))\"\n  using assms apply simp\n  apply(simp add:inv_def Q_lemmas Q_basic_lemmas con_assms_def case_1_def)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def butlast_def)\n  by (metis (no_types, lifting) mem_Collect_eq)\n\n  \nlemma Q_overlap_lemma_2:\n  assumes \"Q_structure s\"\n  and \"length(q s)>0\"\n  and \"inv s\"\n  and \"con_assms s\"\n  and \"case_1 s\"\nshows \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>(\\<forall>j.(a\\<le>j \\<and> j<a+b)\\<longrightarrow>ownB s j = Q)\"\n  using assms apply simp\n  apply(simp add:inv_def Q_lemmas Q_basic_lemmas con_assms_def case_1_def)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def butlast_def)\n  by (metis (no_types, lifting) mem_Collect_eq)\n\n\nlemma Q_overlap_lemma_3:\n  assumes \"Q_structure s\"\n  and \"length(q s)>0\"\n  and \"inv s\"\n  and \"con_assms s\"\n  and \"case_2 s\"\nshows \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>(\\<forall>j.(a\\<le>j \\<and> j<a+b)\\<longrightarrow>ownB s j = Q)\"\n  using assms apply simp\n  apply(simp add:inv_def Q_lemmas Q_basic_lemmas con_assms_def case_2_def)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def butlast_def)\n  by (metis (no_types, lifting) mem_Collect_eq)\n\nlemma Q_overlap_lemma_4_B:\n  assumes \"Q_structure s\"\n  and \"length(q s)>0\"\n  and \"inv s\"\n  and \"con_assms s\"\n  and \"(a,b)\\<in>set(q s)\"\n  and \"a\\<le>j\" \n  and \"j<a+b\"\nshows \"ownB s j = Q\"\n  using assms apply (simp add:inv_def)\n  apply(case_tac \"case_1 s\") \n  using Q_overlap_lemma_2 [where s=s] \n  using assms(3) assms(4) apply blast\n  using Q_overlap_lemma_3 [where s=s] \n  using assms(3) assms(4) by blast\n\nlemma Q_overlap_lemma_4:\n  assumes \"Q_structure s\"\n  and \"length(q s)>0\"\n  and \"inv s\"\n  and \"con_assms s\"\nshows \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>(\\<forall>j.(a\\<le>j \\<and> j<a+b)\\<longrightarrow>ownB s j = Q)\"\n  using  Q_overlap_lemma_4_B \n  using assms(1) assms(2) assms(3) assms(4) by blast\n\n\nlemma Q_overlap_lemma_5:\n  assumes \"Q_structure s\"\n  and \"length(q s)>0\"\n  and \"inv s\"\n  and \"con_assms s\"\nshows \"\\<forall>i.(i<length(q s))\\<longrightarrow>(\\<forall>j.(fst(q s!i)\\<le>j \\<and> j<end(q s!i))\\<longrightarrow>ownB s j = Q)\"\n  using assms Q_overlap_lemma_4 [where s=s]\n  by (metis Q_gap_lemmas_2 end_simp prod.collapse)\n  \n\n\n\n\n\nlemma Q_buffer_overlap_lemma_A4_1:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"length(q s)>0\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> j<length(q s)\\<and>fst(q s!i)<fst(q s!j))\\<longrightarrow>end(q s!i)\\<le>fst(q s!j)\"\n  using Q_gap_lemmas_4_list assms(3) assms(5)\n  by auto\n\n\nlemma Q_buffer_overlap_lemma_A4_2:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pcW s = A4\"\n  and \"pre_A4_inv s\"\n  and \"length(q s)>0\"\nshows \"hW s = end(last(q s))\"\n  using assms apply(simp add:inv_def pre_A4_inv_def case_2_def)\n  by (metis (no_types, hide_lams) F.distinct(23) assms(7) diff_add_inverse2 le_antisym le_eq_less_or_eq linorder_neqE_nat zero_less_iff_neq_zero)\n\n\nlemma Q_buffer_overlap_lemma_A4_3:\n  assumes \"inv s\"\n  and \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pcW s = A4\"\n  and \"pre_A4_inv s\"\n  and \"length(q s)>0\"\nshows \"tW s>hW s\"\n  using assms by(simp add:inv_def pre_A4_inv_def case_2_def) \n\n\n\nlemma Q_buffer_overlap_lemma_A4_4:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pcW s = A4\"\n  and \"pre_A4_inv s\"\n  and \"length(q s)>0\"\nshows \"(\\<exists>i.(ownB s i=R\\<and>i<N))\\<longrightarrow>ownB s (T s) = R\"\n  using assms apply(simp add:inv_def pre_A4_inv_def case_2_def) \n  apply clarify apply(subgoal_tac \"T s=c\") prefer 2\n  apply (metis F.distinct(13) bot_nat_0.extremum bot_nat_0.not_eq_extremum)\n  apply clarify\n  apply(case_tac \"T s \\<noteq>d\") prefer 2 \n  apply (metis F.distinct(13) F.distinct(15) diff_is_0_eq' linorder_neqE_nat nat_le_linear zero_less_diff)\n  by (metis le_neq_implies_less le_refl)\n\n\n\nlemma Q_buffer_overlap_lemma_A4_5:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pcW s = A4\"\n  and \"pre_A4_inv s\"\n  and \"length(q s)>0\"\nshows \"\\<forall>i j.(j<fst(q s!i)\\<and>i<length(q s))\\<longrightarrow>j<end(q s!i)\"\n  using assms by(simp add:inv_def pre_A4_inv_def case_2_def) \n\n\nlemma Q_buffer_overlap_lemma_A4_6:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pcW s = A4\"\n  and \"pre_A4_inv s\"\n  and \"length(q s)>0\"\nshows \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>a\\<in>ran_indices a (a+b)\"\n  by (metis assms(2) fst_conv in_set_conv_nth ran_indices_lem snd_conv)\n\n\nlemma Q_buffer_overlap_lemma_A4_7:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pcW s = A4\"\n  and \"pre_A4_inv s\"\n  and \"length(q s)>0\"\nshows \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>a\\<in>Q_indices s\"\n  using assms apply(simp add:inv_def pre_A4_inv_def case_2_def) \n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:Q_indices_def ran_indices_def)\n  apply(subgoal_tac \"\\<exists>l k.((l,k)\\<in>set(q s))\") prefer 2 \n  apply (metis list.set_sel(1) surjective_pairing)\n  using Q_buffer_overlap_lemma_A4_6 \n  by (metis assms(1) assms(2) assms(3) assms(5) assms(6) ran_indices_def)\n\n\nlemma Q_buffer_overlap_lemma_A4_8:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pcW s = A4\"\n  and \"pre_A4_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\nshows \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>ownB s a=Q\"\n  using assms apply(simp add:inv_def pre_A4_inv_def case_2_def) \n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  using Q_buffer_overlap_lemma_A4_7\n  by (metis Q_owns_bytes_def assms(1) assms(2) assms(3) assms(5) assms(6))\n\n\n\nlemma Q_buffer_overlap_lemma_A4_9:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pcW s = A4\"\n  and \"pre_A4_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"t<N\"\n  and \"ownB s t \\<noteq> Q\"\nshows \"t\\<notin>Q_indices s\"\n  using assms apply(simp add:inv_def pre_A4_inv_def case_2_def) \n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  using Q_owns_bytes_def\n  by metis\n\nlemma Q_buffer_overlap_lemma_A4_10:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pcW s = A4\"\n  and \"pre_A4_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"t<N\"\n  and \"ownB s t \\<noteq> Q\"\nshows \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>(a>t\\<or>t>a)\"\n  using assms apply(simp add:inv_def pre_A4_inv_def case_2_def) \n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  using Q_buffer_overlap_lemma_A4_9 Q_buffer_overlap_lemma_A4_7 Q_buffer_overlap_lemma_A4_8 \n        Q_owns_bytes_def Q_indices_def\n  by (metis assms(1) assms(2) assms(3) assms(5) assms(6) linorder_neqE_nat)\n\n\nlemma Q_buffer_overlap_lemma_A4_11:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pcW s = A4\"\n  and \"pre_A4_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\nshows \"\\<forall>a b j.((a,b)\\<in>set(q s) \\<and> a\\<le>j \\<and> j<(a+b))\\<longrightarrow>j\\<in>ran_indices a (a+b)\"\n  using assms apply(simp add:inv_def pre_A4_inv_def case_2_def) \n  by(simp add:Q_lemmas Q_basic_lemmas ran_indices_def)\n\n\nlemma Q_buffer_overlap_lemma_A4_12:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pcW s = A4\"\n  and \"pre_A4_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\nshows \"\\<forall>a b j.((a,b)\\<in>set(q s) \\<and> a\\<le>j \\<and> j<(a+b))\\<longrightarrow>j\\<in>Q_indices s\"\n  using assms apply(simp add:inv_def pre_A4_inv_def case_2_def) \n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add: Q_owns_bytes_def Q_indices_def ran_indices_def)\n  by (metis (no_types, lifting) mem_Collect_eq)\n\nlemma Q_buffer_overlap_lemma_A4_13:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pcW s = A4\"\n  and \"pre_A4_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\nshows \"\\<forall>a b j.((a,b)\\<in>set(q s) \\<and> a\\<le>j \\<and> j<(a+b))\\<longrightarrow>ownB s j=Q\"\n  using assms apply(simp add:inv_def pre_A4_inv_def case_2_def) \n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add: Q_owns_bytes_def Q_indices_def ran_indices_def)\n  by (metis (no_types, lifting) mem_Collect_eq)\n\n\n\nlemma Q_buffer_overlap_lemma_A4_14:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pcW s = A4\"\n  and \"pre_A4_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\nshows \"\\<forall>a b j.((a,b)\\<in>set(q s) \\<and> a\\<le>j \\<and> j<(a+b))\\<longrightarrow>ownB s j=Q\"\n  using assms apply(simp add:inv_def pre_A4_inv_def case_2_def) \n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add: Q_owns_bytes_def Q_indices_def ran_indices_def)\n  by (metis (no_types, lifting) mem_Collect_eq)\n\n\n\nlemma Q_buffer_overlap_lemma_A4_15:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pcW s = A4\"\n  and \"pre_A4_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"t<N\"\n  and \"ownB s t \\<noteq> Q\"\nshows \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>t\\<notin>Q_indices s\"\n  using assms apply(simp add:inv_def pre_A4_inv_def case_2_def) \n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  by(simp add: Q_owns_bytes_def Q_indices_def ran_indices_def)\n\n\nlemma Q_buffer_overlap_lemma_A4_16:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pcW s = A4\"\n  and \"pre_A4_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"t<N\"\n  and \"ownB s t \\<noteq> Q\"\nshows \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>t\\<notin>ran_indices a (a+b)\"\n  using assms apply(simp add:inv_def pre_A4_inv_def case_2_def) \n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add: Q_owns_bytes_def Q_indices_def ran_indices_def)\n  by (metis (no_types, lifting) mem_Collect_eq)\n\n\nlemma if_not_in_ran_indices_then:\n  assumes \"i<N\"\n  and \"l<N\"\n  and \"k<N\"\n  and \"i\\<notin>ran_indices l k\"\nshows \"i\\<ge>k \\<or> i<l\"\n  using assms apply(simp add:ran_indices_def)\n  by auto\n\n\nlemma Q_buffer_overlap_lemma_A4_17:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pcW s = A4\"\n  and \"pre_A4_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"t<N\"\n  and \"ownB s t \\<noteq> Q\"\nshows \"\\<forall>a b.((a,b)\\<in>set(q s)\\<and> t\\<notin>ran_indices a (a+b))\\<longrightarrow>(t<a \\<or> t\\<ge>(a+b))\"\n  using assms apply(simp add:inv_def pre_A4_inv_def case_2_def) \n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add: Q_owns_bytes_def Q_indices_def ran_indices_def)\n  by (metis Suc_le_lessD not_less_eq_eq)\n\n\n\nlemma Q_buffer_overlap_lemma_A4_18:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pcW s = A4\"\n  and \"pre_A4_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"t<N\"\n  and \"ownB s t \\<noteq> Q\"\nshows \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>(t<a \\<or> t\\<ge>(a+b))\"\n  using assms apply(simp add:inv_def pre_A4_inv_def case_2_def) \n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add: Q_owns_bytes_def Q_indices_def ran_indices_def) \n  using Q_buffer_overlap_lemma_A4_16 Q_buffer_overlap_lemma_A4_17\n  by (metis (no_types, lifting) assms(1) assms(2) assms(3) assms(5) assms(6) assms(7))\n\n\n\n\n\nlemma Q_no_buffer_overlap_lemma_19:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"hW s>tW s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\nshows \"\\<forall>j.(ownB s j=Q \\<and> j<N)\\<longrightarrow>(j\\<in>Q_indices s)\"\n  using assms apply simp\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  by(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n\nlemma Q_buffer_overlap_lemma_20:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"hW s>tW s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\nshows \"\\<forall>a b j.((a,b)\\<in>set(q s)\\<and>a\\<le>j \\<and> j<a+b)\\<longrightarrow>j\\<in>ran_indices a (a+b)\"\n  using assms apply simp\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  by(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n\nlemma Q_buffer_overlap_lemma_21_B:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"hW s>tW s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"(a,b)\\<in>set(q s)\" \n  and \"j\\<in>ran_indices a (a+b)\"\nshows \"j\\<in>Q_indices s\"\n  using assms apply simp\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  by auto\n\n\nlemma Q_buffer_overlap_lemma_21:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"hW s>tW s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\nshows \"\\<forall>a b j.((a,b)\\<in>set(q s)\\<and>j\\<in>ran_indices a (a+b))\\<longrightarrow>j\\<in>Q_indices s\"\n  using Q_buffer_overlap_lemma_21_B assms(1) assms(2) assms(3) assms(4) assms(5) by blast\n\n\nlemma Q_buffer_overlap_lemma_22:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"hW s>tW s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\nshows \"\\<forall>a b j.((a,b)\\<in>set(q s)\\<and>j\\<in>ran_indices a (a+b))\\<longrightarrow>ownB s j=Q\"\n  using assms apply simp\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  by auto\n\n\n\nlemma Q_buffer_overlap_lemma_23:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"hW s>tW s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\nshows \"\\<forall>a b j.((a,b)\\<in>set(q s)\\<and>ownB s j=Q\\<and>j\\<in>ran_indices a (a+b))\\<longrightarrow>j<N\"\n  using assms apply simp\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  by (metis le_antisym le_neq_implies_less le_trans less_or_eq_imp_le)\n\n\nlemma Q_buffer_overlap_lemma_24:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"hW s>tW s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\nshows \"\\<forall>j.(j\\<in>Q_indices s\\<and>j<N)\\<longrightarrow>(\\<exists>a b.((a,b)\\<in>set(q s)\\<and> a\\<le>j \\<and> j<(a+b)))\"\n  using assms apply simp\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  by (metis (mono_tags, lifting) mem_Collect_eq)\n\n\nlemma Q_buffer_overlap_lemma_25:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"hW s>tW s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\nshows \"\\<forall>j a b.((a,b)\\<in>set(q s)\\<and> a\\<le>j \\<and> j<(a+b))\\<longrightarrow>j<N\"\n  using assms apply simp\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  by (metis le_antisym le_neq_implies_less le_trans less_or_eq_imp_le)\n\nlemma Q_buffer_overlap_lemma_26:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"hW s>tW s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\nshows \"\\<forall>j.(j\\<in>Q_indices s)\\<longrightarrow>(\\<exists>a b.((a,b)\\<in>set(q s)\\<and> a\\<le>j \\<and> j<(a+b)))\"\n  using assms apply simp\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  by (metis (mono_tags, lifting) mem_Collect_eq)\n\n\nlemma Q_buffer_overlap_lemma_27:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"hW s>tW s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\nshows \"\\<forall>j.(j\\<in>Q_indices s)\\<longrightarrow>(j<N)\"\n  using assms apply simp\n  using Q_buffer_overlap_lemma_26 [where s=s]\n  using Q_buffer_overlap_lemma_25 [where s=s]\n  using assms(1) by blast\n\n\n\nlemma Q_buffer_overlap_lemma_28:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"hW s>tW s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\nshows \"\\<forall>j.(j\\<in>Q_indices s)\\<longrightarrow>(ownB s j=Q)\"\n  using assms apply simp\n  using Q_buffer_overlap_lemma_26 [where s=s]\n  using Q_buffer_overlap_lemma_25 [where s=s]\n  using assms(1) \n  using Q_owns_bytes_def by blast\n\n\nlemma Q_buffer_overlap_lemma_29:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"hW s>tW s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\nshows \"\\<forall>j.(j\\<notin>Q_indices s\\<and>j<N)\\<longrightarrow>(ownB s j\\<noteq>Q)\"\n  using assms apply simp\n  using Q_buffer_overlap_lemma_26 [where s=s]\n  using Q_buffer_overlap_lemma_25 [where s=s]\n  using assms(1) \n  using Q_owns_bytes_def by blast\n\n\n\n\nlemma Q_buffer_overlap_lemma_35:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_1 s\"\n  and \"hW s>tW s\"\n  and \"\\<forall>i.(i<N)\\<longrightarrow>ownB s i\\<noteq>W\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>i.(i\\<ge>hW s \\<and> i<N)\\<longrightarrow>ownB s i\\<noteq>Q\"\n  using assms apply simp\n  apply(simp add:case_1_def)\n  apply clarify\n  by (metis F.distinct(19) F.distinct(21) diff_is_0_eq less_nat_zero_code linorder_neqE_nat zero_less_diff)\n\n\n\nlemma Q_buffer_overlap_lemma_36:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_1 s\"\n  and \"pre_A6_inv s\"\n  and \"\\<forall>i.(i<N)\\<longrightarrow>ownB s i\\<noteq>W\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>i.(i<tW s)\\<longrightarrow>ownB s i\\<noteq>Q\"\n  using assms apply simp\n  apply(simp add:case_1_def)\n  apply clarify\n  by (smt (z3) F.distinct(19) pre_A6_inv_def)\n  \n\nlemma Q_buffer_overlap_lemma_37:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_1 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>i.(ownB s i=Q)\\<longrightarrow>i\\<ge>tW s\"\n  using Q_buffer_overlap_lemma_36 [where s=s] assms \n  apply simp\n  by (smt (verit, best) F.distinct(19) leI pre_A6_inv_def)\n\n\n\nlemma Q_buffer_overlap_lemma_38:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>i.(ownB s i=Q \\<and> i<N)\\<longrightarrow>i\\<in>Q_indices s\"\n  using Q_buffer_overlap_lemma_36 [where s=s] assms \n  apply simp \n  using Q_owns_bytes_def by auto\n\n\nlemma Q_buffer_overlap_lemma_39:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>i.(i\\<in>Q_indices s)\\<longrightarrow>(ownB s i=Q \\<and> i<N)\"\n  using Q_buffer_overlap_lemma_36 [where s=s] assms \n  apply simp \n  by (smt (verit, ccfv_SIG) Q_buffer_overlap_lemma_27 Q_owns_bytes_def assms(1) assms(4) grd3_def pre_A6_inv_def)\n  \n\n\nlemma Q_buffer_overlap_lemma_40:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_1 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>i.(i\\<ge>hW s \\<and> i<tW s)\\<longrightarrow>ownB s i = B\"\n  using Q_buffer_overlap_lemma_36 [where s=s] assms \n  apply simp \n  using pre_A6_inv_def\n  by auto\n\n\nlemma Q_buffer_overlap_lemma_41:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_1 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> j\\<ge>fst(q s!i) \\<and> j<end(q s!i))\\<longrightarrow>ownB s j = Q\"\n  using Q_buffer_overlap_lemma_36 [where s=s] assms \n  apply simp \n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(subgoal_tac \"\\<forall>a b i.((a,b)\\<in>set(q s) \\<and> i\\<ge>a \\<and> i<(a+b))\\<longrightarrow>ownB s i=Q\") prefer 2\n  apply blast\n  by (metis (mono_tags, hide_lams) nth_mem prod.collapse)\n\n\n\nlemma Q_buffer_overlap_lemma_42:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_1 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> j<end(q s!i) \\<and> ownB s j \\<noteq> Q)\\<longrightarrow>j<fst(q s!i)\"\n  using Q_buffer_overlap_lemma_36 [where s=s] assms \n  apply simp \n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(subgoal_tac \"\\<forall>a b i.((a,b)\\<in>set(q s) \\<and> i\\<ge>a \\<and> i<(a+b))\\<longrightarrow>ownB s i=Q\") prefer 2\n  apply blast\n  by (metis (mono_tags, lifting) eq_imp_le less_imp_le_nat linorder_neqE_nat nth_mem surjective_pairing)\n\n\n\nlemma Q_buffer_overlap_lemma_43:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_1 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> j\\<ge>fst(q s!i) \\<and> ownB s j \\<noteq> Q)\\<longrightarrow>j\\<ge>end(q s!i)\"\n  using Q_buffer_overlap_lemma_36 [where s=s] assms \n  apply simp \n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(subgoal_tac \"\\<forall>a b i.((a,b)\\<in>set(q s) \\<and> i\\<ge>a \\<and> i<(a+b))\\<longrightarrow>ownB s i=Q\") prefer 2\n  apply blast\n  by (metis (mono_tags, lifting) eq_imp_le less_imp_le_nat linorder_neqE_nat nth_mem surjective_pairing)\n\n\nlemma Q_buffer_overlap_lemma_44:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_1 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> ownB s j \\<noteq> Q \\<and> hW s < end(q s!i) \\<and> j> hW s)\\<longrightarrow>j<fst(q s!i)\"\n  using Q_buffer_overlap_lemma_36 [where s=s] assms \n  apply simp \n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(subgoal_tac \"\\<forall>a b i.((a,b)\\<in>set(q s) \\<and> i\\<ge>a \\<and> i<(a+b))\\<longrightarrow>ownB s i=Q\") prefer 2\n  apply blast \n  apply(simp add:pre_A6_inv_def case_1_def)\n  apply clarify\n  apply(subgoal_tac \"hW s = c\") prefer 2\n  apply (metis le_neq_implies_less le_refl le_trans)\n  apply(subgoal_tac \"\\<forall>i.(i>hW s \\<and> i<N)\\<longrightarrow>ownB s i\\<noteq>Q\") prefer 2\n  apply (metis F.distinct(19) less_imp_le_nat)\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s))\\<longrightarrow>fst(q s!i)<hW s\") prefer 2\n  apply (metis (no_types, lifting) F.distinct(19) Q_buffer_overlap_lemma_39 assms(1) assms(3) assms(4) assms(5) assms(6) linorder_neqE_nat ran_indices_lem5)\n  using Q_buffer_overlap_lemma_35 [where s=s] Q_gap_lemmas_2 assms(1) assms(3) assms(6)\nproof -\n  fix a :: nat and b :: nat and i :: nat and j :: nat and c :: nat and d :: nat and e :: nat\n  assume a1: \"hW s = H s\"\nassume a2: \"\\<forall>a b i. (a, b) \\<in> set (q s) \\<and> a \\<le> i \\<and> i < a + b \\<longrightarrow> ownB s i = Q\"\nassume a3: \"\\<forall>i. (H s \\<le> i \\<and> i < N \\<longrightarrow> ownB s i = B) \\<and> (i < tW s \\<longrightarrow> ownB s i = B)\"\nassume a4: \"Data s (numEnqs s) \\<le> N - H s\"\n  assume a5: \"\\<forall>i<n. Data s i \\<le> N \\<and> 0 < Data s i\"\n  assume a6: \"c \\<le> H s\"\n  assume a7: \"H s \\<le> e\"\n  assume a8: \"e \\<le> N\"\n  assume a9: \"numEnqs s < n\"\n  assume a10: \"\\<forall>i. H s \\<le> i \\<and> i < e \\<longrightarrow> ownB s i = B\"\n  assume a11: \"e < N \\<longrightarrow> 0 < H s \\<and> H s < e \\<and> a = 0\"\n  assume a12: \"i < length (q s)\"\n  assume a13: \"H s < fst (q s ! i) + snd (q s ! i)\"\n  assume a14: \"hW s = c\"\n  assume a15: \"\\<forall>i<length (q s). fst (q s ! i) < hW s\"\n  have f16: \"H s = c\"\n    using a14 a1 by metis\n  then have f17: \"Q = ownB s c\"\n    using a15 a14 a13 a12 a2 by (metis nat_less_le nth_mem prod.collapse)\n  then have f18: \"N = e\"\n    using f16 a11 a10 a8 a6 by (metis (no_types) F.distinct(19) nat_less_le)\n  then have \"c = e\"\n    using f17 f16 a7 a6 a3 by (metis (no_types) F.distinct(19) nat_less_le)\n  then have \"0 = Data s (numEnqs s)\"\n    using f18 f16 a4 by simp\n  then show \"j < fst (q s ! i)\"\n    using a9 a5 nat_less_le by blast\nqed\n\n\n\nlemma Q_buffer_overlap_lemma_45:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_1 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> hW s < end(q s!i))\\<longrightarrow>hW s<fst(q s!i)\"\n  using Q_buffer_overlap_lemma_36 [where s=s] assms \n  apply simp \n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(subgoal_tac \"\\<forall>a b i.((a,b)\\<in>set(q s) \\<and> i\\<ge>a \\<and> i<(a+b))\\<longrightarrow>ownB s i=Q\") prefer 2\n  apply blast \n  apply(simp add:pre_A6_inv_def case_1_def)\n  apply clarify\n  apply(subgoal_tac \"hW s = c\") prefer 2\n  apply (metis le_neq_implies_less le_refl le_trans)\n  apply(subgoal_tac \"\\<forall>i.(i>hW s \\<and> i<N)\\<longrightarrow>ownB s i\\<noteq>Q\") prefer 2\n  apply (metis F.distinct(19) less_imp_le_nat)\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s))\\<longrightarrow>fst(q s!i)<hW s\") prefer 2\n  apply (metis (no_types, lifting) F.distinct(19) Q_buffer_overlap_lemma_39 assms(1) assms(3) assms(4) assms(5) assms(6) linorder_neqE_nat ran_indices_lem5)\n  by (metis (no_types, lifting) F.distinct(19) Q_buffer_overlap_lemma_25 Q_gap_lemmas_2 assms(1) assms(3) assms(5) assms(6) less_imp_le_nat prod.collapse)\n  \n\nlemma Q_buffer_overlap_lemma_46:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_1 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> hW s < fst(q s!i))\\<longrightarrow>hW s + Data s (numEnqs s)<fst(q s!i)\"\n  using Q_buffer_overlap_lemma_36 [where s=s] assms \n  apply simp \n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(subgoal_tac \"\\<forall>a b i.((a,b)\\<in>set(q s) \\<and> i\\<ge>a \\<and> i<(a+b))\\<longrightarrow>ownB s i=Q\") prefer 2\n  apply blast \n  apply(simp add:pre_A6_inv_def case_1_def)\n  apply clarify\n  apply(subgoal_tac \"hW s = c\") prefer 2\n  apply (metis le_neq_implies_less le_refl le_trans)\n  apply(subgoal_tac \"\\<forall>i.(i>hW s \\<and> i<N)\\<longrightarrow>ownB s i\\<noteq>Q\") prefer 2\n  apply (metis F.distinct(19) less_imp_le_nat)\n  apply(subgoal_tac \"\\<forall>i.(i<length(q s))\\<longrightarrow>fst(q s!i)<hW s\") prefer 2\n  apply (metis (no_types, lifting) F.distinct(19) Q_buffer_overlap_lemma_39 assms(1) assms(3) assms(4) assms(5) assms(6) linorder_neqE_nat ran_indices_lem5)\n  by (metis less_imp_add_positive not_add_less1)\n  \n\n\n\n\nlemma Q_buffer_overlap_lemma_47:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> j\\<ge>fst(q s!i) \\<and> j<end(q s!i))\\<longrightarrow>ownB s j = Q\"\n  using Q_buffer_overlap_lemma_36 [where s=s] assms \n  apply simp \n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(subgoal_tac \"\\<forall>a b i.((a,b)\\<in>set(q s) \\<and> i\\<ge>a \\<and> i<(a+b))\\<longrightarrow>ownB s i=Q\") prefer 2\n  apply blast\n  by (metis (mono_tags, hide_lams) nth_mem prod.collapse)\n\n\n\nlemma Q_buffer_overlap_lemma_48:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> j<end(q s!i) \\<and> ownB s j \\<noteq> Q)\\<longrightarrow>j<fst(q s!i)\"\n  using Q_buffer_overlap_lemma_36 [where s=s] assms \n  apply simp \n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(subgoal_tac \"\\<forall>a b i.((a,b)\\<in>set(q s) \\<and> i\\<ge>a \\<and> i<(a+b))\\<longrightarrow>ownB s i=Q\") prefer 2\n  apply blast\n  by (metis (mono_tags, lifting) eq_imp_le less_imp_le_nat linorder_neqE_nat nth_mem surjective_pairing)\n\n\n\nlemma Q_buffer_overlap_lemma_49:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>i j.(i<length(q s) \\<and> j\\<ge>fst(q s!i) \\<and> ownB s j \\<noteq> Q)\\<longrightarrow>j\\<ge>end(q s!i)\"\n  using Q_buffer_overlap_lemma_36 [where s=s] assms \n  apply simp \n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  apply(subgoal_tac \"\\<forall>a b i.((a,b)\\<in>set(q s) \\<and> i\\<ge>a \\<and> i<(a+b))\\<longrightarrow>ownB s i=Q\") prefer 2\n  apply blast\n  by (metis (mono_tags, lifting) eq_imp_le less_imp_le_nat linorder_neqE_nat nth_mem surjective_pairing)\n\n\nlemma Q_buffer_overlap_lemma_50:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>i.(i\\<ge> hW s)\\<longrightarrow>ownB s i\\<noteq>Q\"\n  using Q_buffer_overlap_lemma_36 [where s=s] assms \n  apply simp \n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  by (smt (verit) F.distinct(19) Q_buffer_overlap_lemma_39 Q_owns_bytes_def assms(1) assms(5) assms(6) pre_A6_inv_def)\n  \n\n\nlemma Q_buffer_overlap_lemma_51:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>(\\<forall>j.(a\\<le>j \\<and> j<a+b)\\<longrightarrow>ownB s j = Q)\"\n  using Q_buffer_overlap_lemma_36 [where s=s] assms \n  apply simp \n  apply(simp add:Q_owns_bytes_def Q_indices_def ran_indices_def)\n  using Q_overlap_lemma_4 [where s=s]\n  using assms(1) by blast\n  \n  \n\nlemma Q_buffer_overlap_lemma_52:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>a b j.((a,b)\\<in>set(q s) \\<and> (a\\<le>j \\<and> j<a+b) )\\<longrightarrow>ownB s j = Q\"\n  using Q_buffer_overlap_lemma_51 [where s=s]  assms\n  by blast\n\n\nlemma Q_buffer_overlap_lemma_53:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>a b.((a,b)\\<in>set(q s) \\<and> b>0)\\<longrightarrow>ownB s a = Q\"\n  using Q_buffer_overlap_lemma_52 [where s=s]  assms apply simp\n  by (meson le_refl less_add_same_cancel1)\n\nlemma Q_buffer_overlap_lemma_54:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>b>0\"\n  using Q_buffer_overlap_lemma_52 [where s=s]  assms apply simp\n  by(simp add:Q_lemmas Q_basic_lemmas)\n\n\nlemma Q_buffer_overlap_lemma_55:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>a b.((a,b)\\<in>set(q s))\\<longrightarrow>ownB s a = Q\"\n  using Q_buffer_overlap_lemma_52 [where s=s] Q_buffer_overlap_lemma_54 [where s=s] assms\n  by (meson le_refl less_add_same_cancel1)\n\n\nlemma Q_buffer_overlap_lemma_56:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>a b j.((a,b)\\<in>set(q s) \\<and> ownB s j\\<noteq> Q )\\<longrightarrow>a\\<noteq>j\"\n  using Q_buffer_overlap_lemma_52 [where s=s] Q_buffer_overlap_lemma_54 [where s=s] assms\n  by (meson le_refl less_add_same_cancel1)\n\n\nlemma Q_buffer_overlap_lemma_57:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>a b j.((a,b)\\<in>set(q s) \\<and> ownB s j\\<noteq> Q \\<and> j\\<ge>hW s \\<and> j<hW s + Data s (numEnqs s))\\<longrightarrow>a\\<noteq>j\"\n  using Q_buffer_overlap_lemma_52 [where s=s] Q_buffer_overlap_lemma_54 [where s=s] assms\n  by (meson le_refl less_add_same_cancel1)\n\nlemma Q_buffer_overlap_lemma_58:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>a b j.((a,b)\\<in>set(q s) \\<and> ownB s j\\<noteq> Q \\<and> j\\<ge>hW s \\<and> j<hW s + Data s (numEnqs s))\\<longrightarrow>a>j \\<or> a<j\"\n  using Q_buffer_overlap_lemma_57 [where s=s] Q_buffer_overlap_lemma_54 [where s=s] assms\n  using less_linear by blast\n\n\nlemma Q_buffer_overlap_lemma_59:\n  assumes \"con_assms s\"\n  and \"Q_structure s\"\n  and \"case_2 s\"\n  and \"pre_A6_inv s\"\n  and \"length(q s)>0\"\n  and \"Q_owns_bytes s\"\n  and \"hW s=H s\"\nshows \"\\<forall>a b j.((a,b)\\<in>set(q s) \\<and> ownB s j\\<noteq> Q \\<and> j\\<ge>hW s \\<and> j<hW s + Data s (numEnqs s))\\<longrightarrow>a>j \\<or> a<j\"\n  using Q_buffer_overlap_lemma_57 [where s=s] Q_buffer_overlap_lemma_54 [where s=s] assms\n  using less_linear by blast\n*)\n\n\n(*local W case split*)\n(*\nlemma A6_case2_hW_fst:\n  assumes \"case_2 s\"\n  and \"tW s<hW s\"\n  and \"(\\<forall>i.((i\\<ge>hW s \\<and> i<N) \\<or> i<tW s)\\<longrightarrow>ownB s i=B)\"\nshows \"tW s=0\"\n  using assms apply(simp add:case_2_def)\n  apply(clarify) apply(subgoal_tac \"\\<forall>i.(i>a\\<and>i<N)\\<longrightarrow>ownB s i=B\")\n  prefer 2 sledgehammer\n*)\n\n\n\n\n\n(*\nlemma inv_holds_for_W: \n  assumes \"con_assms s\"\n  and \"pcw = pcW s\"\n  and \"pre_W pcw s\"\n  and \"inv s\"\n  and \"cW_step pcw s s'\"\nshows \"inv s'\"\n  using assms apply(simp add:inv_def)\n  apply(intro conjI impI)\n  apply(simp add:Q_lemmas Q_basic_lemmas cW_step_def)\n  apply(case_tac \"pcW s\", simp_all)\n  apply (metis (no_types, hide_lams) F.distinct(3) PCW.simps(185) pre_A3_inv_def pre_W_def)\n  apply(simp add:pre_W_def pre_A4_inv_def)\n  apply (simp add: le_add_diff_inverse2 less_diff_conv)\n  apply(simp add:pre_W_def pre_A6_inv_def)\n  apply (metis Nat.le_diff_conv2 add.commute)\n  apply(simp add:pre_W_def pre_A7_inv_def)\n  apply(case_tac \"numEnqs s<n\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(simp add:pre_W_def pre_A7_inv_def)\n  apply(simp add:Q_lemmas Q_basic_lemmas cW_step_def)\n  apply(case_tac \"pcW s\", simp_all)\n  apply(case_tac \"numEnqs s<n\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(simp add:pre_W_def pre_A7_inv_def)\n  apply(simp add:Q_lemmas Q_basic_lemmas cW_step_def)\n  apply(case_tac \"pcW s\", simp_all)\n  apply(case_tac \"numEnqs s<n\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(simp add:pre_W_def pre_A7_inv_def)\n  apply(simp add:Q_lemmas Q_basic_lemmas cW_step_def)\n  apply(case_tac \"pcW s\", simp_all)\n  apply(case_tac \"numEnqs s<n\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(simp add:pre_W_def pre_A7_inv_def)\n  apply(simp add:Q_lemmas Q_basic_lemmas cW_step_def) (*11*)\n  apply(case_tac \"pcW s\", simp_all)\n  apply(case_tac \"tW s = hW s \\<and> Data s (numEnqs s) \\<le> N\", simp_all)\n  apply(case_tac \"ownT s = Q\", simp_all)   \n  apply(case_tac \"hW s < tW s \\<and> Data s (numEnqs s) < tW s - hW s\", simp_all)\n  apply(case_tac \"tW s < hW s\", simp_all)\n  apply (metis pre_A4_inv_def)\n  apply(case_tac \"Data s (numEnqs s) \\<le> N - hW s\", simp_all)\n  apply(case_tac \"Data s (numEnqs s) < tW s\", simp_all) \n  apply (simp add: pre_A6_inv_def)   \n  apply (simp add: pre_A7_inv_def)   \n  apply (simp add: pre_A8_inv_def)   \n  apply(case_tac \"N < Data s (numEnqs s)\", simp_all)\n  apply(case_tac \"ownT s = W\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \" tW s \\<noteq> T s\", simp_all) (*10*)\n  apply(simp add:pre_W_def pre_A7_inv_def)\n  apply(simp add:Q_lemmas Q_basic_lemmas cW_step_def)\n  apply(case_tac \"pcW s\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \" tW s \\<noteq> T s\", simp_all)\n  apply(simp add:pre_W_def pre_A7_inv_def)  (*9*)\n  apply(simp add:Q_lemmas Q_basic_lemmas cW_step_def)\n  apply(case_tac \"pcW s\", simp_all)\n  apply(case_tac \"ownT s = W\", simp_all)\n  using Suc_diff_le apply presburger\n  using Suc_diff_le apply presburger\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \" tW s \\<noteq> T s\", simp_all)  (*8*)\n  apply(simp add:pre_W_def pre_A7_inv_def)\n  apply(simp add:cW_step_def)\n  apply(case_tac \"pcW s\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \" tW s \\<noteq> T s\", simp_all)  (*7*)\n  apply(simp add:pre_W_def pre_A7_inv_def)\n  apply(simp add:cW_step_def)\n  apply(case_tac \"pcW s\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \" tW s \\<noteq> T s\", simp_all)  (*6*)\n  apply(simp add:pre_W_def pre_write_inv_def)\n  apply(simp add:cW_step_def)\n  apply(case_tac \"pcW s\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \" tW s \\<noteq> T s\", simp_all)  (*5*)\n  apply(simp add:pre_W_def cW_step_def) apply(case_tac \"pcW s\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(simp add:pre_write_inv_def)        (*4*)\n  apply(simp add:pre_W_def pre_write_inv_def)\n  apply(simp add:cW_step_def)\n  apply(case_tac \"pcW s\", simp_all)\n  apply(case_tac \"ownT s = W\", simp_all)\n  apply(simp add:pre_enqueue_inv_def)  \n  apply(simp add:pre_enqueue_inv_def)  \n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \" tW s \\<noteq> T s\", simp_all)  (*3*)\n  apply(simp add:pre_W_def pre_write_inv_def)\n  apply(simp add:cW_step_def)\n  apply(case_tac \"pcW s\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \" tW s \\<noteq> T s\", simp_all)  (*2*)\n   defer\n  apply(simp add:cW_step_def)\n  apply(simp add:pre_W_def) apply(case_tac \"pcW s\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  using pre_write_inv_def apply auto[1]    (*1*)\n  apply(simp add:cW_step_def)\n  apply(case_tac \"pcW s\", simp_all)\n  apply(simp add:pre_W_def pre_A1_inv_def)\n  apply(subgoal_tac \"Q_structure s=Q_structure s'\")\n  apply meson apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:pre_W_def pre_A2_inv_def)\n  apply(case_tac \"tW s = hW s\", simp_all)\n  apply(subgoal_tac \"Q_structure s=Q_structure s'\")\n  apply meson apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"hW s < tW s \\<and> Data s (numEnqs s) < tW s - hW s\", simp_all)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(case_tac \" tW s < hW s\", simp_all)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:pre_W_def pre_A3_inv_def)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply (metis F.distinct(3))\n  apply(simp add:pre_W_def pre_A4_inv_def)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply (metis (no_types, lifting) F.distinct(11) Suc_lessD add.commute less_diff_conv less_trans_Suc)\n  apply(case_tac \"Data s (numEnqs s) \\<le> N - hW s\", simp_all)\n  apply(simp add:pre_W_def pre_A5_inv_def)  \n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:pre_W_def pre_A6_inv_def)  \n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply (metis F.distinct(11) le_trans less_eq_Suc_le)\n  apply(simp add:pre_W_def pre_A7_inv_def)  \n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply (metis (no_types, hide_lams) F.distinct(11) less_Suc_eq less_trans_Suc not_less_eq)\n  apply(case_tac \"N < Data s (numEnqs s)\", simp_all)\n  apply(simp add:pre_W_def pre_A8_inv_def) \n  apply (metis leD)\n  apply(simp add:pre_W_def pre_A8_inv_def) \n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  defer\n  apply(case_tac \"numEnqs s < n\", simp_all) \n  apply(simp add:pre_W_def pre_acquire_inv_def) \n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(simp add:pre_W_def pre_acquire_inv_def) \n  apply(simp add:Q_lemmas Q_basic_lemmas)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  apply(simp add:pre_W_def pre_OOM_inv_def) \n    apply(simp add:Q_lemmas Q_basic_lemmas)       (*this case is concerning pre_write *)\n  apply(simp add:pre_W_def pre_write_inv_def)\n \n  apply(subgoal_tac \"con_assms s\n  \\<and> pcw = Write\n  \\<and> pre_write_inv s\n  \\<and> Q_structure s\n  \\<and> numEnqs s - numDeqs s = length (q s)\n  \\<and> (\\<forall>i. (i < numReads s \\<longrightarrow> ownD s i = R) \\<and>\n            (numReads s \\<le> i \\<and> i < numWrites s \\<longrightarrow> ownD s i = B) \\<and> \n            (numWrites s \\<le> i \\<and> i < n \\<longrightarrow> ownD s i = W))\n  \\<and> numReads s \\<le> numWrites s \\<and> numReads s \\<le> n \\<and> numWrites s \\<le> n\n  \\<and> B_write s s'\n  \\<and> tempW_structure s\")  \n  using write_doesnt_change_Q_struct\n  apply (metis (no_types, lifting))\n  apply (intro conjI impI)\n  using assms(1) apply blast\n  using assms(1) apply blast\n  apply (metis (mono_tags, hide_lams) PCW.simps(195) assms(3) pre_W_def)\n  apply meson\n  apply fastforce\n  apply presburger\n  using less_imp_le_nat apply presburger\n  apply meson  apply simp prefer 2 \n  apply meson\n  apply(simp add:B_write_def)\n  apply presburger \n  \n(*last subgoal!!!\napply (insert data_index_reduce2[where s = s])\n*) \n  apply(subgoal_tac \"Q_structure s\n  \\<and> Q_enqueue s s'\n  \\<and> length(q s) = numEnqs s-numDeqs s\n  \\<and> pre_enqueue_inv s\n  \\<and> numWrites s\\<ge>numReads s\n  \\<and> numEnqs s\\<ge>numDeqs s\n  \\<and> ownD s(numEnqs s) =B\") prefer 2 \n  apply(intro conjI impI)\n  apply blast \n  apply simp\n  apply presburger\n  apply (simp add: pre_W_def)\n  apply blast\n  apply blast\n  apply (simp add: pre_W_def pre_enqueue_inv_def)\n  apply(intro conjI impI)\n  apply(case_tac \"ownT s = W \", simp_all)\n   apply(case_tac[!] \"q s=[]\", simp_all )\n     defer defer defer\n(*4*)\n  apply(subgoal_tac \"q s\\<noteq>[]\n  \\<and> Q_structure s\n  \\<and> Q_enqueue s s'\n  \\<and> numDeqs s<numEnqs s\n  \\<and> length(q s) = numEnqs s-numDeqs s\n  \\<and> pre_enqueue_inv s\n  \\<and> numWrites s\\<ge>numReads s\n  \\<and> ownD s(numEnqs s) =B\n  \\<and> ownT s \\<noteq>W\") using enqueue_preserves_Q_n_n \n      apply presburger\n  apply(intro conjI impI)\n  apply blast\n  apply blast apply simp\n  apply (metis length_greater_0_conv zero_less_diff)\n  apply linarith\n  apply blast\n  apply blast\n  apply blast\n  apply blast\n    defer\n(*3*)\n  apply(subgoal_tac \"q s\\<noteq>[]\n  \\<and> Q_structure s\n  \\<and> Q_enqueue s s'\n  \\<and> numDeqs s<numEnqs s\n  \\<and> length(q s) = numEnqs s-numDeqs s\n  \\<and> pre_enqueue_inv s\n  \\<and> numWrites s\\<ge>numReads s\n  \\<and> ownD s(numEnqs s) =B\n  \\<and> ownT s =W\") prefer 2\n  apply(intro conjI impI)\n  apply blast\n  apply blast apply simp\n  apply (simp add: pre_enqueue_inv_def)\n  apply linarith\n  apply blast\n  apply linarith\n  apply linarith\n  apply blast\n  using enqueue_preserves_Q_n_o\nproof -\nassume a1: \"s' = s \\<lparr>ownT := Q, numEnqs := Suc (numEnqs s), ownB := \\<lambda>i. if ownB s i = W then Q else ownB ((if ownT s = W then ownT_update (\\<lambda>_. Q) else (\\<lambda>s. s\\<lparr>ownT := ownT s\\<rparr>)) s \\<lparr>numEnqs := Suc (numEnqs s)\\<rparr>) i, pcW := idleW, q := q s @ [(offset s, Data s (numEnqs s))]\\<rparr>\"\nassume \"Q_structure s \\<and> length (q s) = numEnqs s - numDeqs s \\<and> pre_enqueue_inv s \\<and> numReads s \\<le> numWrites s \\<and> numDeqs s \\<le> numEnqs s \\<and> ownD s (numEnqs s) = B\"\nassume a2: \"ownT s = W\"\nassume \"q s \\<noteq> []\"\n  assume \"q s \\<noteq> [] \\<and> Q_structure s \\<and> Q_enqueue s s' \\<and> numDeqs s < numEnqs s \\<and> length (q s) = numEnqs s - numDeqs s \\<and> pre_enqueue_inv s \\<and> numReads s \\<le> numWrites s \\<and> ownD s (numEnqs s) = B \\<and> ownT s = W\"\n  then have \"Q_structure (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s), ownB := \\<lambda>n. if ownB s n = W then Q else ownB ((if ownT s = W then ownT_update (\\<lambda>f. Q) else (\\<lambda>r. r\\<lparr>ownT := ownT r\\<rparr>)) s \\<lparr>numEnqs := Suc (numEnqs s)\\<rparr>) n, pcW := idleW, q := q s @ [(offset s, Data s (numEnqs s))]\\<rparr>)\"\n    using a1 enqueue_preserves_Q_n_o by blast\n  then show \"Q_structure (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s), ownB := \\<lambda>n. if ownB s n = W then Q else ownB (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s)\\<rparr>) n, pcW := idleW, q := q s @ [(offset s, Data s (numEnqs s))]\\<rparr>)\"\n    using a2 by presburger\nnext\n\n  show \"0 < N \\<and> 0 < n \\<and> n < N \\<and> numEnqs s \\<le> n \\<and> (\\<forall>i<n. Data s i \\<le> N \\<and> 0 < Data s i) \\<Longrightarrow>\n    pcw = Enqueue \\<Longrightarrow>\n    pre_W Enqueue s \\<Longrightarrow>\n    H s \\<le> N \\<and>\n    T s \\<le> N \\<and>\n    hW s \\<le> N \\<and>\n    tW s \\<le> N \\<and>\n    (H s = 0 \\<longrightarrow> T s = 0) \\<and>\n    (\\<forall>i. (i < numReads s \\<longrightarrow> ownD s i = R) \\<and>\n         (numReads s \\<le> i \\<and> i < numWrites s \\<longrightarrow> ownD s i = B) \\<and>\n         (numWrites s \\<le> i \\<and> i < n \\<longrightarrow> ownD s i = W)) \\<and>\n    numReads s \\<le> n \\<and> numWrites s \\<le> n \\<and> (\\<forall>i\\<le>N. \\<forall>j\\<le>N. data_index s (i, j) < n) \\<Longrightarrow>\n    s' = s\n    \\<lparr>numEnqs := Suc (numEnqs s),\n       ownB := \\<lambda>i. if ownB s i = W then Q else ownB (s\\<lparr>numEnqs := Suc (numEnqs s)\\<rparr>) i, pcW := idleW,\n       q := [(offset s, Data s (numEnqs s))]\\<rparr> \\<Longrightarrow>\n    pcW s = Enqueue \\<Longrightarrow>\n    Q_structure s \\<and>\n    s\\<lparr>numEnqs := Suc (numEnqs s),\n        ownB :=\n          \\<lambda>i. if ownB s i = W then Q\n              else ownB\n                    ((if ownT s = W then ownT_update (\\<lambda>_. Q) else (\\<lambda>s. s\\<lparr>ownT := ownT s\\<rparr>)) s\n                     \\<lparr>numEnqs := Suc (numEnqs s)\\<rparr>)\n                    i,\n        pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr> =\n    s\\<lparr>numEnqs := Suc (numEnqs s),\n        ownB := \\<lambda>i. if ownB s i = W then Q else ownB (s\\<lparr>numEnqs := Suc (numEnqs s)\\<rparr>) i, pcW := idleW,\n        q := [(offset s, Data s (numEnqs s))]\\<rparr> \\<and>\n    numEnqs s \\<le> numDeqs s \\<and>\n    pre_enqueue_inv s \\<and> numReads s \\<le> numWrites s \\<and> numDeqs s \\<le> numEnqs s \\<and> ownD s (numEnqs s) = B \\<Longrightarrow>\n    ownT s \\<noteq> W \\<Longrightarrow>\n    q s = [] \\<Longrightarrow>\n    Q_structure\n     (s\\<lparr>numEnqs := Suc (numEnqs s),\n          ownB :=\n            \\<lambda>i. if ownB s i = W then Q else ownB (s\\<lparr>ownT := ownT s, numEnqs := Suc (numEnqs s)\\<rparr>) i,\n          pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr>)\"\n(*2*)\n  apply(subgoal_tac \"q s=[]\n  \\<and> Q_structure s\n  \\<and> Q_enqueue s s'\n  \\<and> numEnqs s = numDeqs s\n  \\<and> length(q s) = numEnqs s-numDeqs s\n  \\<and> pre_enqueue_inv s\n  \\<and> numWrites s\\<ge>numReads s\n  \\<and> ownD s(numEnqs s) =B\n  \\<and> ownT s \\<noteq>W\") prefer 2 \n    apply(intro conjI impI)\n    apply blast\n    apply blast \n    apply simp\n    apply linarith\n    apply (metis diff_is_0_eq' list.size(3))\n    apply linarith\n    apply blast\n    apply blast\n    apply blast\n    using enqueue_preserves_Q_e_n\nproof -\n  assume a1: \"s' = s \\<lparr>numEnqs := Suc (numEnqs s), ownB := \\<lambda>i. if ownB s i = W then Q else ownB (s\\<lparr>numEnqs := Suc (numEnqs s)\\<rparr>) i, pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr>\"\n  assume a2: \"Q_structure s \\<and> s\\<lparr>numEnqs := Suc (numEnqs s), ownB := \\<lambda>i. if ownB s i = W then Q else ownB ((if ownT s = W then ownT_update (\\<lambda>_. Q) else (\\<lambda>s. s\\<lparr>ownT := ownT s\\<rparr>)) s \\<lparr>numEnqs := Suc (numEnqs s)\\<rparr>) i, pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr> = s\\<lparr>numEnqs := Suc (numEnqs s), ownB := \\<lambda>i. if ownB s i = W then Q else ownB (s\\<lparr>numEnqs := Suc (numEnqs s)\\<rparr>) i, pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr> \\<and> numEnqs s \\<le> numDeqs s \\<and> pre_enqueue_inv s \\<and> numReads s \\<le> numWrites s \\<and> numDeqs s \\<le> numEnqs s \\<and> ownD s (numEnqs s) = B\"\n  assume a3: \"ownT s \\<noteq> W\"\n  assume \"q s = []\"\n  assume a4: \"q s = [] \\<and> Q_structure s \\<and> Q_enqueue s s' \\<and> numEnqs s = numDeqs s \\<and> length (q s) = numEnqs s - numDeqs s \\<and> pre_enqueue_inv s \\<and> numReads s \\<le> numWrites s \\<and> ownD s (numEnqs s) = B \\<and> ownT s \\<noteq> W\"\n  then have \"\\<forall>r. numDeqs s - numDeqs s \\<noteq> length (q s) \\<or> B \\<noteq> ownD s (numEnqs s) \\<or> Q_structure r \\<or> \\<not> Q_enqueue s r \\<or> [] \\<noteq> q s\"\n    by (metis (no_types) enqueue_preserves_Q_e_n)\n  then have \"Q_structure (s\\<lparr>numEnqs := Suc (numEnqs s), ownB := \\<lambda>n. if ownB s n = W then Q else ownB ((if ownT s = W then ownT_update (\\<lambda>f. Q) else (\\<lambda>r. r\\<lparr>ownT := ownT r\\<rparr>)) s \\<lparr>numEnqs := Suc (numEnqs s)\\<rparr>) n, pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr>)\"\n    using a4 a2 a1 by metis\n  then show ?thesis\n    using a3 by presburger\nnext\nqed\n(*1*)\n  show \"0 < N \\<and> 0 < n \\<and> n < N \\<and> numEnqs s \\<le> n \\<and> (\\<forall>i<n. Data s i \\<le> N \\<and> 0 < Data s i) \\<Longrightarrow>\n    pcw = Enqueue \\<Longrightarrow>\n    pre_W Enqueue s \\<Longrightarrow>\n    H s \\<le> N \\<and>\n    T s \\<le> N \\<and>\n    hW s \\<le> N \\<and>\n    tW s \\<le> N \\<and>\n    (H s = 0 \\<longrightarrow> T s = 0) \\<and>\n    (\\<forall>i. (i < numReads s \\<longrightarrow> ownD s i = R) \\<and>\n         (numReads s \\<le> i \\<and> i < numWrites s \\<longrightarrow> ownD s i = B) \\<and>\n         (numWrites s \\<le> i \\<and> i < n \\<longrightarrow> ownD s i = W)) \\<and>\n    numReads s \\<le> n \\<and> numWrites s \\<le> n \\<and> (\\<forall>i\\<le>N. \\<forall>j\\<le>N. data_index s (i, j) < n) \\<Longrightarrow>\n    s' = s\n    \\<lparr>ownT := Q, numEnqs := Suc (numEnqs s),\n       ownB :=\n         \\<lambda>i. if ownB s i = W then Q\n             else ownB\n                   ((if ownT s = W then ownT_update (\\<lambda>_. Q) else (\\<lambda>s. s\\<lparr>ownT := ownT s\\<rparr>)) s\n                    \\<lparr>numEnqs := Suc (numEnqs s)\\<rparr>)\n                   i,\n       pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr> \\<Longrightarrow>\n    pcW s = Enqueue \\<Longrightarrow>\n    Q_structure s \\<and>\n    numEnqs s \\<le> numDeqs s \\<and>\n    pre_enqueue_inv s \\<and> numReads s \\<le> numWrites s \\<and> numDeqs s \\<le> numEnqs s \\<and> ownD s (numEnqs s) = B \\<Longrightarrow>\n    ownT s = W \\<Longrightarrow>\n    q s = [] \\<Longrightarrow>\n    Q_structure\n     (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s),\n          ownB := \\<lambda>i. if ownB s i = W then Q else ownB (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s)\\<rparr>) i,\n          pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr>)\"\n  apply(subgoal_tac \"q s=[]\n  \\<and> Q_structure s\n  \\<and> Q_enqueue s s'\n  \\<and> numDeqs s=numEnqs s\n  \\<and> length(q s) = numEnqs s-numDeqs s\n  \\<and> pre_enqueue_inv s\n  \\<and> ownD s(numEnqs s) =B\n  \\<and> ownT s =W\") prefer 2 \n    apply(intro conjI impI)\n    apply blast \n    apply blast \n    apply simp\n    apply linarith\n    apply (metis diff_is_0_eq' list.size(3))\n    apply linarith\n    apply blast\n    apply blast\n    using enqueue_preserves_Q_e_o\nproof -\n  assume a1: \"s' = s \\<lparr>ownT := Q, numEnqs := Suc (numEnqs s), ownB := \\<lambda>i. if ownB s i = W then Q else ownB ((if ownT s = W then ownT_update (\\<lambda>_. Q) else (\\<lambda>s. s\\<lparr>ownT := ownT s\\<rparr>)) s \\<lparr>numEnqs := Suc (numEnqs s)\\<rparr>) i, pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr>\"\nassume a2: \"Q_structure s \\<and> numEnqs s \\<le> numDeqs s \\<and> pre_enqueue_inv s \\<and> numReads s \\<le> numWrites s \\<and> numDeqs s \\<le> numEnqs s \\<and> ownD s (numEnqs s) = B\"\nassume a3: \"ownT s = W\"\nassume \"q s = []\"\nassume \"q s = [] \\<and> Q_structure s \\<and> Q_enqueue s s' \\<and> numDeqs s = numEnqs s \\<and> length (q s) = numEnqs s - numDeqs s \\<and> pre_enqueue_inv s \\<and> ownD s (numEnqs s) = B \\<and> ownT s = W\"\nthen have \"Q_structure (s\\<lparr>ownT := Q, numEnqs := Suc (numEnqs s), ownB := \\<lambda>n. if ownB s n = W then Q else ownB ((if ownT s = W then ownT_update (\\<lambda>f. Q) else (\\<lambda>r. r\\<lparr>ownT := ownT r\\<rparr>)) s \\<lparr>numEnqs := Suc (numEnqs s)\\<rparr>) n, pcW := idleW, q := [(offset s, Data s (numEnqs s))]\\<rparr>)\"\nusing a2 a1 by (meson enqueue_preserves_Q_e_o)\nthen show ?thesis\nusing a3 by presburger\nqed\nqed\n\n*)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n(*\n\n\nlemma local_pre_R:\n  assumes \"con_assms s\"\n  and \"pcr = pcR s\"\n  and \"pre_R pcr s\"\n  and \"inv s\"\n  and \"cR_step pcr s s'\"\nshows \"pre_R (pcR s') s'\"\nproof (cases \"pcR s\")\n  case Release\n  then show ?thesis \n    apply (simp add: pre_R_def)\n  proof (cases \"pcR s'\")\n    show \"pcR s = Release \\<Longrightarrow>\n    pcR s' = Release \\<Longrightarrow>\n    case pcR s' of\n    Release \\<Rightarrow> pre_Release_inv s'\n    | idleR \\<Rightarrow> pre_dequeue_inv s'\n    | Read \\<Rightarrow> pre_Read_inv s'\" \n        using assms by(simp add:cR_step_def pre_Read_inv_def pre_Release_inv_def pre_dequeue_inv_def)\n    next \n      show \"pcR s = Release \\<Longrightarrow>\n    pcR s' = Read \\<Longrightarrow>\n    case pcR s' of Release \\<Rightarrow> pre_Release_inv s'\n    | idleR \\<Rightarrow> pre_dequeue_inv s' | Read \\<Rightarrow> pre_Read_inv s'\"\n        using assms by(simp add:cR_step_def pre_Read_inv_def pre_Release_inv_def pre_dequeue_inv_def)\n    next\n      show \"pcR s = Release \\<Longrightarrow>\n    pcR s' = idleR \\<Longrightarrow>\n    case pcR s' of Release \\<Rightarrow> pre_Release_inv s'\n    | idleR \\<Rightarrow> pre_dequeue_inv s'\n    | Read \\<Rightarrow> pre_Read_inv s'\"\n        using assms apply(simp add:cR_step_def pre_Read_inv_def pre_Release_inv_def pre_dequeue_inv_def)\n        apply (case_tac \"tR s \\<noteq> fst (tempR s)\", simp_all)\n        apply (case_tac[!] \"ownT s = R\", simp_all)\n        apply (intro conjI impI)\n        apply(simp add:cR_step_def pre_Read_inv_def pre_Release_inv_def pre_dequeue_inv_def RingBuffer_BD.inv_def pre_R_def)\n        apply(simp add:cR_step_def pre_Read_inv_def pre_Release_inv_def pre_dequeue_inv_def RingBuffer_BD.inv_def pre_R_def)\n        \n        apply(simp add:cR_step_def pre_Read_inv_def pre_Release_inv_def pre_dequeue_inv_def RingBuffer_BD.inv_def pre_R_def)\n        apply(simp add:Q_lemmas Q_basic_lemmas) \n              apply(subgoal_tac \"(\\<forall>a b j. (a, b) \\<in> set (q s) \\<and> j < N \\<and> tR s \\<le> j \\<longrightarrow> a + b < j)\")\n        prefer 2 \n        apply presburger\n              apply(subgoal_tac \"end(tempR s)<T s\")\n        prefer 2 \n        apply (metis end_simp)\n        apply(simp add:tempR_lemmas tempR_basic_lemmas)\n        apply (metis add_lessD1 hd_conv_nth length_pos_if_in_set less_irrefl_nat less_nat_zero_code linorder_neqE_nat tempR_describes_T_def)\n        apply(simp add:Q_describes_T_def)\n        apply(simp add:cR_step_def pre_Read_inv_def pre_Release_inv_def pre_dequeue_inv_def RingBuffer_BD.inv_def pre_R_def)\n        apply(simp add:tempR_lemmas tempR_basic_lemmas)\n        apply (metis bot_nat_0.not_eq_extremum hd_conv_nth length_greater_0_conv not_add_less1 tempR_describes_T_def)\n        apply(simp add:R_owns_no_bytes_def)\n        apply(simp add:Tail_and_ownB_idleR_def)\n        apply(simp add:cR_step_def pre_Read_inv_def pre_Release_inv_def pre_dequeue_inv_def RingBuffer_BD.inv_def pre_R_def)\n        apply(simp add:Q_lemmas Q_basic_lemmas) \n        apply(simp add:tempR_lemmas tempR_basic_lemmas)\n        apply safe[1]\n        apply (metis add_less_same_cancel1 less_nat_zero_code tempR_describes_T_def)\n        apply (metis end_simp tempR_describes_ownB_def)\n        apply (metis not_add_less1 tempR_describes_T_def)\n        apply (metis not_add_less1 tempR_describes_T_def)\n        apply (metis end_simp tempR_describes_ownB_def)\n        apply (metis not_add_less1 tempR_describes_T_def)\n        apply clarsimp apply(simp add:Tail_and_ownB_not_idleR_1_def Tail_and_ownB_not_idleR_2_def)\n        apply(simp add:tempR_describes_T_def T_is_outside_Q_def tempR_describes_ownB_def)\n        apply clarify\n        apply(subgoal_tac \"fst(q s!0) = end(tempR s)\") prefer 2\n        apply (metis end_simp hd_conv_nth plus_nat.add_0)\n        apply(subgoal_tac \"\\<forall>i. i < length (q s) \\<and> 0 < i \\<longrightarrow>\n             fst (q s ! (i - Suc 0)) + snd (q s ! (i - Suc 0)) =\n             fst (q s ! i)\") prefer 2\n        apply (metis (no_types, lifting) less_irrefl_nat)\n        apply(subgoal_tac \"fst(q s!(length(q s)-1)) = fst(last(q s))\") prefer 2\n        apply (metis last_conv_nth)\n        apply (subgoal_tac \"fst (last (q s)) + snd (last (q s)) > fst (hd (q s))\")\n        apply (meson less_or_eq_imp_le)\n        apply (metis (no_types, lifting) diff_less le_add1 le_trans length_greater_0_conv less_one)\n        apply (metis end_simp tempR_describes_ownB_def)\n        apply(simp add:tempR_describes_ownB_def tempR_describes_T_def T_is_outside_Q_def Tail_and_ownB_not_idleR_1_def Tail_and_ownB_not_idleR_2_def)\n        apply clarify\n        apply(subgoal_tac \"\\<forall>i. i < length (q s) \\<and> 0 < i \\<longrightarrow>\n             fst (q s ! (i - Suc 0)) + snd (q s ! (i - Suc 0)) =\n             fst (q s ! i)\") prefer 2\n        apply (metis (no_types, lifting) gr_implies_not0)\n  defer\n        apply (metis (mono_tags, hide_lams) add_less_same_cancel1 hd_conv_nth length_0_conv less_nat_zero_code linorder_neqE_nat tempR_describes_T_def)\n        apply (metis end_simp tempR_describes_ownB_def)\n        apply (metis diff_less_Suc hd_conv_nth length_0_conv less_diff_conv linorder_neqE_nat not_less_eq tempR_describes_T_def zero_less_diff)\n        apply(simp add:inv_def pre_R_def pre_Release_inv_def)\n        prefer 2\n        apply(simp add:inv_def pre_R_def pre_Release_inv_def)\n        apply(intro conjI impI)\n        apply(simp add:inv_def pre_R_def pre_Release_inv_def)\n        apply(simp add:inv_def pre_R_def pre_Release_inv_def) \n        apply(subgoal_tac \"con_assms s\n  \\<and> q s\\<noteq>[]\n  \\<and> fst(hd(q s)) =0\n  \\<and> fst(tempR s) \\<noteq>0\n  \\<and> pre_Release_inv s\n  \\<and> snd(tempR s) = Data s (numReads s -1)\n  \\<and> data_index s (tempR s) = numReads s -1\n  \\<and> ownT s = R\n  \\<and> numEnqs s\\<ge>numDeqs s\n  \\<and> ownD s (numReads s -1) = R\n  \\<and> numDeqs s\\<le>n \\<and> numDeqs s\\<ge>1\n  \\<and> numDeqs s = numReads s\n  \\<and> pcR s=Release\n  \\<and> tR s=T s\n  \\<and> tempR_structure s\n  \\<and> Q_structure s\n  \\<and> B_release s s'\") apply(unfold pre_Release_inv_def)[1] \n        using Release_wrap_1 inv_def \n        apply (smt (z3) add_diff_inverse_nat add_lessD1 le_add_diff_inverse not_add_less1 struct_of_wrap_1)\n        apply(intro conjI impI)\n        using assms(1) apply blast\n        using assms(1) apply blast \n        apply(simp add:inv_def pre_R_def pre_Release_inv_def tempR_lemmas) \n        apply (metis end_simp tempR_basic_struct_def tempR_gap_structure_def)\n        apply(simp add:inv_def pre_R_def pre_Release_inv_def tempR_lemmas tempR_describes_T_def T_is_outside_Q_def) \n        apply (metis end_simp head_q0 length_0_conv less_nat_zero_code linorder_neqE_nat tempR_basic_struct_def tempR_gap_structure_def tempR_offsets_differ_def)\n        apply (metis PCR.simps(7) pre_R_def)\n        apply(simp add:inv_def pre_R_def pre_Release_inv_def tempR_lemmas tempR_describes_T_def T_is_outside_Q_def) \n        apply(simp add:inv_def pre_R_def pre_Release_inv_def tempR_lemmas tempR_describes_T_def T_is_outside_Q_def) \n        apply(simp add:inv_def pre_R_def pre_Release_inv_def tempR_lemmas tempR_describes_T_def T_is_outside_Q_def) \n        apply(simp add:inv_def pre_R_def pre_Release_inv_def tempR_lemmas tempR_describes_T_def T_is_outside_Q_def) \n        apply(simp add:inv_def pre_R_def pre_Release_inv_def tempR_lemmas tempR_describes_T_def T_is_outside_Q_def) \n        apply(simp add:inv_def pre_R_def pre_Release_inv_def tempR_lemmas tempR_describes_T_def T_is_outside_Q_def) \n        apply(simp add:inv_def pre_R_def pre_Release_inv_def tempR_lemmas tempR_describes_T_def T_is_outside_Q_def) \n        apply(simp add:inv_def pre_R_def pre_Release_inv_def tempR_lemmas tempR_describes_T_def T_is_outside_Q_def) \n        apply(simp add:inv_def pre_R_def pre_Release_inv_def tempR_lemmas tempR_describes_T_def T_is_outside_Q_def) \n        apply(simp add:inv_def pre_R_def pre_Release_inv_def tempR_lemmas tempR_describes_T_def T_is_outside_Q_def) \n        apply(simp add:inv_def pre_R_def pre_Release_inv_def tempR_lemmas tempR_describes_T_def T_is_outside_Q_def) \n        apply(simp add:inv_def pre_R_def pre_Release_inv_def tempR_lemmas tempR_describes_T_def T_is_outside_Q_def) \n        apply (metis (no_types, lifting) PCR.simps(7) assms(5) cR_step_def)\n        (**)\n defer\n        apply(simp add:R_owns_no_bytes_def)\n        apply(simp add:Tail_and_ownB_idleR_def)\n          apply(intro conjI impI) apply clarify apply(intro conjI impI)\n        apply(simp add:pre_R_def pre_Release_inv_def)\n        apply (metis end_simp tempR_describes_ownB_def)\n        apply(simp add:pre_R_def pre_Release_inv_def tempR_describes_ownB_def Tail_and_ownB_not_idleR_1_def Tail_and_ownB_not_idleR_2_def)\n        apply(subgoal_tac \"fst (last (q s)) + snd (last (q s)) < T s\")\n        apply presburger apply(simp add:inv_def Q_lemmas Q_basic_lemmas tempR_lemmas tempR_basic_lemmas)\n        apply clarify\n        apply(subgoal_tac \"end(q s!(length(q s)-1)) = end(last(q s))\") prefer 2\n        apply (metis last_conv_nth) \n\n(*should be solved by:\napply (smt (z3) Nat.add_0_right diff_add_inverse diff_is_0_eq' diff_less last_conv_nth le_neq_implies_less le_trans length_greater_0_conv less_numeral_extra(1) less_or_eq_imp_le nat_neq_iff)\nso defer*) \n          defer\n        apply simp apply(subgoal_tac \"end(last(q s)) = (T s -1)\") \n        apply (metis Suc_diff_1 Suc_leI bot_nat_0.extremum bot_nat_0.not_eq_extremum end_simp le_trans)\n        apply (metis add_lessD1 diff_Suc_1 gr0_conv_Suc last_conv_nth le_less_Suc_eq length_greater_0_conv less_or_eq_imp_le)\n        \n(*1st subgoal is left to check, should be trivially solved outside of the proof*)\n        sorry qed\n\nnext\n  case Read\n  then show ?thesis using assms apply (simp add:pre_R_def inv_def pre_Read_inv_def)\n    apply(case_tac \"pcR s'\", simp_all add:cR_step_def)\n    apply(simp add:pre_Release_inv_def)\n    apply(intro conjI impI)\n    apply(simp add:Q_lemmas Q_basic_lemmas)\n    apply (metis Nat.add_0_right hd_conv_nth length_greater_0_conv)\n    apply(simp add:Q_lemmas Q_basic_lemmas tempR_lemmas tempR_basic_lemmas)\n    apply (metis (no_types, hide_lams))\n    apply(simp add:tempR_describes_T_def T_is_outside_Q_def) \n    apply(simp add:tempR_describes_ownB_def)\n    apply(simp add:Tail_and_ownB_not_idleR_1_def)\n    apply(simp add:Tail_and_ownB_not_idleR_2_def)\n    by metis\nnext\n  case idleR\n  then show ?thesis using assms apply (simp add:pre_R_def inv_def pre_dequeue_inv_def)\n    apply(case_tac \"pcR s'\", simp_all add:cR_step_def Q_dequeue_def)\n    apply(case_tac \"q s=[]\", simp_all) \n    apply(case_tac \"q s=[]\", simp_all)\n    apply (metis assms(1) con_assms_def le_antisym less_eq_nat.simps(1) pre_dequeue_inv_def)\n    apply(case_tac \"q s=[]\", simp_all)\n    apply(simp add:pre_Read_inv_def)\n    apply(intro conjI impI)\n    apply(simp add:Q_lemmas Q_basic_lemmas)\n    apply (simp add: hd_conv_nth)\n    apply(simp add:Q_lemmas Q_basic_lemmas)\n    apply (simp add: hd_conv_nth)\n    apply (metis diff_is_0_eq' le_trans length_0_conv not_less_eq_eq)\n    apply (metis Suc_leI length_greater_0_conv zero_less_diff)\n    apply (metis Q_reflects_ownD_def Q_structure_def le_iff_add length_0_conv nat_less_le plus_nat.add_0)\n    apply (metis Q_elem_size_def Q_reflects_writes_def Q_structure_def head_q0 length_pos_if_in_set less_SucI list.set_sel(1) not_less_eq snd_conv zero_le)\n    apply(simp add:tempR_structure_def)\n          apply(intro conjI impI)\n             apply(simp add:tempR_basic_struct_def) apply(intro conjI impI) \n                apply(simp add:Q_lemmas Q_basic_lemmas tempR_basic_lemmas)\n                apply(simp add:Q_lemmas Q_basic_lemmas tempR_basic_lemmas)\n    apply(subgoal_tac \"hd(q s) = (q s!0) \\<and> hd(tl(q s)) = (q s!1)\")\n    apply (metis (no_types, lifting) One_nat_def diff_Suc_1 length_greater_0_conv length_tl less_one zero_less_diff)\n    apply (metis One_nat_def hd_conv_nth length_greater_0_conv nth_tl)\n    apply(simp add:tempR_offsets_differ_def)\n    apply(simp add:Q_lemmas Q_basic_lemmas tempR_basic_lemmas)\n    apply(subgoal_tac \"\\<forall>i.(i<(length(q s)-1))\\<longrightarrow>fst(tl(q s)!i) = fst(q s!(i+1))\")\n    apply (metis (no_types, lifting) One_nat_def add_diff_inverse_nat hd_conv_nth length_greater_0_conv lessI less_add_eq_less less_diff_conv less_nat_zero_code less_numeral_extra(3))\n    apply (metis Suc_eq_plus1 length_tl nth_tl)\n    apply(simp add:tempR_has_no_overlaps_def)\n    using peculiar_16 apply auto[1]\n    apply(simp add:tempR_has_no_uroboros_def)\n    using peculiar_21 apply auto[1]\n    apply(simp add:tempR_holds_bytes_def)\n    apply(simp add:tempR_reflects_writes_def)\n    apply(simp add:Q_lemmas Q_basic_lemmas tempR_basic_lemmas)\n    apply (metis Nat.add_0_right hd_conv_nth length_greater_0_conv)\n    apply(simp add:tempR_elem_size_def)\n    apply(simp add:Q_lemmas Q_basic_lemmas tempR_basic_lemmas)\n    apply (metis add_cancel_right_right hd_conv_nth length_greater_0_conv)\n    apply(simp add:tempR_describes_T_def T_is_outside_Q_def Q_describes_T_def)\n    apply(simp add:Q_lemmas Q_basic_lemmas tempR_basic_lemmas)\n    apply(case_tac \"fst(hd(q s)) \\<noteq>0\")\n    apply blast\n    apply clarify\n    apply(simp add: Tail_and_ownB_idleR_def)\n    apply(subgoal_tac \"fst(hd(q s)) \\<noteq> T s\") prefer 2\n    apply linarith\n    apply(subgoal_tac \"last(q s) = (q s!(length(q s)-1))\") prefer 2\n    apply (metis last_conv_nth)\n    apply (metis (no_types, lifting) One_nat_def Q_tail_props add_diff_cancel_right' add_gr_0 less_diff_conv zero_less_Suc)\n    apply(simp add:tempR_describes_ownB_def)\n    apply (metis R_owns_no_bytes_def zero_le)\n    apply(simp add:Tail_and_ownB_not_idleR_1_def Tail_and_ownB_idleR_def R_owns_no_bytes_def Q_lemmas Q_basic_lemmas) \n    apply clarify\n    apply(intro conjI impI)\n    apply (metis (no_types, lifting) hd_in_set less_Suc_eq not_less_eq prod.collapse)\n    apply(simp add:Q_describes_T_def)\n    apply(simp add:Tail_and_ownB_not_idleR_2_def Tail_and_ownB_idleR_def Q_describes_T_def R_owns_no_bytes_def Q_lemmas Q_basic_lemmas) \n    apply (metis (no_types, lifting) add_leD1 add_less_same_cancel2 bot_nat_0.not_eq_extremum last_tl not_add_less2)\n    apply (meson list.set_sel(2))\n    apply(simp add:Q_lemmas Q_basic_lemmas Q_describes_T_def T_is_outside_Q_def)\n    by (metis hd_conv_nth length_greater_0_conv plus_nat.add_0)\nqed\n\n*)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n(*(*\n\n(*------------------------showing progress----------------------*)\n(*\nlemma tries_are_bounded:\n  assumes \"con_assms s\"\n  and \"cW_step pcw s s'\"\n  and \"inv pcw pcr s\"\nshows \"tries s'\\<le>N\"\n  using assms\n  apply (simp_all add:cW_step_def)\n  using less_le_trans apply auto[1]\n  apply (case_tac \"pcw\", simp_all)\n  using less_imp_le_nat apply blast\n  using less_imp_le_nat apply blast\n  using less_imp_le_nat apply blast\n  using less_imp_le_nat apply blast\n  using less_imp_le_nat apply blast\n  using less_imp_le_nat apply blast\n  using less_imp_le_nat apply blast\n  using less_imp_le_nat apply blast\n  apply(case_tac \"numEnqs s < n\", simp_all add:less_imp_le)\n  apply(case_tac \"tW s \\<noteq> T s\", simp_all)\n  using Suc_leI apply blast\n  by (meson less_imp_le_nat)\n\n\nlemma when_W_moves_prog_less:\n  assumes \"con_assms s\"\n  and \"inv (pcW s) (pcR s) s\"\n  and \"cW_step (pcW s) s s'\"\nshows \"lex_prog s s'\"\nproof - \n  from assms(1) have sp1: \"numEnqs s \\<le> n \\<and> numDeqs s \\<le> n\"\n    using con_assms_def by auto\n  from assms show ?thesis\n  apply (simp_all add:cW_step_def inv_def  progress_lemmas tries_left_def)\n  apply(case_tac \"pcW s\", simp_all)\n  apply(case_tac[!] \"pcR s\", simp_all)\n  apply (simp_all add: diff_less_mono2)\n  apply (case_tac[!] \"tW s = T s\", simp_all add:cW_step_def)\n  apply(case_tac[1-6] \"numEnqs s < n\", simp_all)\n  using diff_less_mono2 by auto\nqed\n\nlemma W_counter_implies_notown:\n  assumes \"con_assms s\"\n  and \"mainInv s\"\nshows \"\\<forall>i.(i<numEnqs s)\\<longrightarrow>ownD s i \\<in> {R,B}\"\n  using assms\n  apply (simp_all add:inv_def)\n  by (meson le_less_linear)\n\n\nlemma least_prog_W_implies:\n  assumes \"con_assms s\"\n  and \"inv (pcW s) pcr s\"\n  and \"cW_step (pcW s) s s'\"\n  and \"inv (pcW s') pcr s'\"\n  and \"lex_prog s s'\"\nshows \"end_W_prog s'=True\\<longrightarrow>end_W_prog s \\<or> ((\\<forall>i.(i<n)\\<longrightarrow>ownD s' i\\<noteq>W) \\<and> (pcW s=idleW) \\<and> numEnqs s=n)\"\n  using assms W_counter_implies_notown\n  apply (simp_all add: end_W_prog_def progress_lemmas tries_left_def cW_step_def inv_def)\n  apply (case_tac \"pcW s\", simp_all)\n  apply(case_tac \"numEnqs s < n\", simp_all)\n  apply(case_tac \"pcr\", simp_all)\n  apply (metis F.distinct(1) F.distinct(5) le_less_linear)\n  apply (metis F.distinct(1) F.distinct(5) le_less_linear)\n  apply (metis F.distinct(1) F.distinct(5) le_less_linear)\n  by(case_tac \"tW s \\<noteq> T s\", simp_all)\n\n\nlemma when_R_moves_prog_less:\n  assumes \"con_assms s\"\n  and \"inv (pcW s) (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\nshows \"lex_prog s s'\"\n  using assms apply (simp_all add:inv_def cR_step_def progress_lemmas)\n  apply(case_tac \"pcR s\", simp_all add:tries_left_def)\n  apply(case_tac[!] \"pcW s\", simp_all)\n                      apply(case_tac[!] \"q s=[]\", simp_all add: Let_def)\n                      apply clarify\noops\n  apply(case_tac \" T s < fst (hd (q s)) + snd (hd (q s))\", simp_all)\n  apply(case_tac \" T s < fst (hd (q s)) + snd (hd (q s))\", simp_all)\n  apply (metis (no_types, lifting) add_less_mono diff_less_mono2 diff_self_eq_0 length_greater_0_conv lessI less_le_trans mult_2 nat_add_left_cancel_less nat_less_le)\n  apply (metis (no_types, lifting) add_less_mono diff_less_mono2 diff_self_eq_0 length_greater_0_conv lessI less_le_trans mult_2 nat_add_left_cancel_less nat_less_le)\n  apply(case_tac \" T s < fst (hd (q s)) + snd (hd (q s))\", simp_all)\n  apply (metis diff_less_mono2 length_greater_0_conv lessI zero_less_diff)\n  apply (metis diff_less_mono2 diff_self_eq_0 le_eq_less_or_eq length_0_conv lessI)\n  sorry\n\n\n\n\nlemma least_prog_R_implies:\n  assumes \"con_assms s\"\n  and \"inv (pcW s) (pcR s) s\"\n  and \"cR_step (pcR s) s s'\"\n  and \"inv (pcW s) (pcR s) s'\"\n  and \"lex_prog s s'\"\nshows \"end_R_prog s'=True\\<longrightarrow>(end_R_prog s \\<or> ((\\<forall>i.(i<n)\\<longrightarrow>ownD s' i=R) \\<and> pcR s=Release))\\<and>end_W_prog s\"\n  using assms apply (simp_all add: end_R_prog_def end_W_prog_def tries_left_def cR_step_def inv_def)\n  apply(case_tac \"pcR s\", simp_all)\n  by(case_tac \"q s=[]\", simp_all add:Let_def)\n\n\nlemma initial_progress:\n  assumes  \"cR_step (pcR s) s s' \\<or> cW_step (pcW s) s s'\"\n  and \"inv (pcW s) (pcR s) s\"\n  and \"init s'\"\n  and \"con_assms s\"\nshows \"lex_prog s s'\\<longrightarrow>s=s'\"\n  using assms apply(simp_all add:cR_step_def cW_step_def init_def progress_lemmas tries_left_def inv_def)\n  apply(case_tac \"pcR s\", simp_all)\n  apply(case_tac \"pcW s\", simp_all)\n  apply (metis add.commute add_less_mono diff_less less_le_trans less_nat_zero_code mult.commute mult_2_right nat_le_iff_add order_less_irrefl zero_less_iff_neq_zero)\n  apply (metis add.commute add_cancel_right_left add_cancel_right_right add_is_0 diff_less diff_zero le_iff_add length_0_conv length_greater_0_conv less_add_eq_less less_irrefl_nat less_le_trans mult.commute mult_2_right nat_diff_split zero_less_iff_neq_zero)\n  apply (metis (no_types, hide_lams) add.commute diff_less le_iff_add le_less_trans less_eq_nat.simps(1) less_le_trans mult.commute mult_2_right order_less_irrefl trans_less_add2)\n  apply (metis add.commute add_strict_mono diff_less le_iff_add less_le_trans less_nat_zero_code less_not_refl mult.commute mult_2_right zero_less_iff_neq_zero)\n  apply (metis add_is_0 diff_diff_cancel diff_le_self nat_0_less_mult_iff nat_less_le not_le zero_less_diff zero_less_numeral)\n  apply (metis add.commute diff_less le0 le_less_trans less_le_trans mult.commute mult_2_right nat_le_iff_add order_less_irrefl trans_less_add2)\n  apply (metis add.commute diff_less le_iff_add le_less_trans less_eq_nat.simps(1) less_le_trans less_not_refl mult.commute mult_2_right trans_less_add2)\n  apply (metis add.commute diff_less le0 le_less_trans less_le_trans less_not_refl mult.commute mult_2_right nat_le_iff_add trans_less_add1)\n  apply (metis add.commute add_cancel_right_right diff_less gr_implies_not0 le0 le_iff_add le_less_trans le_neq_implies_less less_add_eq_less less_le_trans mult.commute mult_2_right order_less_irrefl zero_le)\n  apply (metis add_is_0 diff_diff_cancel diff_self_eq_0 nat_0_less_mult_iff nat_less_le zero_less_diff zero_less_numeral)\n  apply (metis add.commute diff_less le_iff_add le_less_trans less_le_trans mult.commute mult_2_right order_less_irrefl trans_less_add2 zero_le)\n  apply (metis diff_add_zero diff_diff_cancel less_numeral_extra(3) mult_2)\n  apply (metis add.commute diff_less le_iff_add less_le_trans mult.commute mult_2_right order_less_irrefl)\n  apply (metis add.commute diff_less le_iff_add less_le_trans less_not_refl mult.commute mult_2_right)\n  apply (simp add: leD)\n  by (simp add: leD)\n  \n\n\n\n(*--------------------------------------------------------------*)\n\n\n\n(*--------------lexicographical progress------------------------------*)\ndefinition \"ltpcW i j \\<equiv> \n(i \\<noteq> j \\<and>\n(i=FinishedW)\n\\<or>(i \\<in> {Enqueue, OOM, BTS} \\<and> j\\<noteq>FinishedW)\n\\<or> (i \\<in> {A8, Write} \\<and> j \\<notin> {Enqueue, OOM, BTS, FinishedW})\n\\<or> (i \\<in> {A6, A7} \\<and> j \\<in> {idleW, A1, A2, A3, A4, A5})\n\\<or> (i \\<in> {A3, A4, A5} \\<and> j \\<in> {idleW, A1, A2})\n\\<or> (i = A2 \\<and> j \\<in> {idleW, A1})\n\\<or> (i = A1 \\<and> j = idleW)) \n\"\n\ndefinition \"ltpcR i j \\<equiv> \ni = idleR \\<and> j =Release \\<or> i=Release \\<and> j=Read \\<or> i=Read \\<and> j=idleR\"\n\ndefinition \"state_pv s \\<equiv> (2*n - numEnqs s - numDeqs s)\"\ndefinition \"tries_left s \\<equiv> N-tries s\"\n\ndefinition \"lex_prog s s' \\<equiv> s = s' \\<or> \n(state_pv s' < state_pv s \n\\<or> (state_pv s' = state_pv s \\<and> tries_left s' < tries_left s)\n\\<or> (state_pv s' = state_pv s \\<and> tries_left s' = tries_left s \\<and> ltpcR (pcR s') (pcR s)) \n\\<or> (state_pv s' = state_pv s \\<and> tries_left s' = tries_left s \\<and> ltpcW (pcW s') (pcW s)))\"\n\nlemmas progress_lemmas = ltpcW_def ltpcR_def state_pv_def lex_prog_def \n\ndefinition \"end_W_prog s \\<equiv> ((n-numEnqs s)=0) \\<and> tries_left s=N \\<and> pcW s=FinishedW\" \ndefinition \"end_R_prog s \\<equiv> end_W_prog s\\<and> pcR s=idleR \\<and> numDeqs s=numEnqs s\"\ndefinition \"start_state_prog s\\<equiv> state_pv s=2*n \\<and> pcR s=idleR \\<and> pcW s=idleW \\<and> tries_left s=N\"\n*)\n(*a\n\\<and> right_to_addresses s\n               \\<and> no_ownB s\n               \\<and> H_T_ownB s\n               \\<and> Buff_entries_transfer_numDeqs s*)*)*)\n", "meta": {"author": "MSemenyuk", "repo": "PhD_Isabelle", "sha": "179f5d346a721b15940a271323e3487f4ea51338", "save_path": "github-repos/isabelle/MSemenyuk-PhD_Isabelle", "path": "github-repos/isabelle/MSemenyuk-PhD_Isabelle/PhD_Isabelle-179f5d346a721b15940a271323e3487f4ea51338/Amazon Ring Buffer/RingBuffer_BD_latest_2_____________backup.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6513548782017745, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.29019783603099414}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: GPL-2.0-only\n *)\n\ntheory PolicySystemSAC\nimports\n  ArchNoninterference\n  \"Access.ExampleSystem\"\nbegin\n\ntext \\<open>\n  Reads/Affects sets:\n  - NicA, NicB, NicD: reads all except T\n       affects {RM, R, NicA, NicB, NicD}\n  - NicC: reads all except T, affects self only\n  - R:  reads all except T\n        affects {NicA, NicB, NicD, R, RM, NTFN3}\n  - RM: reads all except T\n        affects {SC, EP, RM, R, NicA, NicB, NicD, NTFN2}\n  - SC: reads all except T\n        affects {EP, SC, NicC, RM, R, NicA, NicB, NicD, NTFN1}\n  - EP: reads all except T\n        affects {EP, SC, NicC, RM, R, NicA, NicB, NicD}\n  - NTFN1: reads all except T, affects {NTFN1, SC, NicC}\n  - NTFN2: ''                , affects {NTFN2, RM, R, NicA, NicB, NicD}\n  - NTFN3: ''                , affects {NTFN3, R, NicB, NicD}\n  - T: reads T, affects all except EP\n\\<close>\n\nsubsection \\<open>Definitions\\<close>\n\ndatatype SACLabels =\n    NicA | NicB | NicC | NicD\n  | R | RM |  SC | EP\n  | T | NTFN1 | NTFN2 | NTFN3\n\ndefinition complete_AgentAuthGraph where\n  \"complete_AgentAuthGraph g \\<equiv>\n     g \\<union> {(y,a,y) | a y. True}\n       \\<union> {(x,a,y) | x a y. (x,Control,y) \\<in> g }\n       \\<union> {(x,a,y)|x a y. \\<exists>z. (x,Control,z) \\<in> g \\<and> (z, Control,y) \\<in> g} \"\ndeclare complete_AgentAuthGraph_def [simp]\n\nabbreviation partition_label where\n  \"partition_label l \\<equiv> OrdinaryLabel l\"\n\ndefinition SACGraph where\n  \"SACGraph \\<equiv>\n  { (partition_label R, Read,  partition_label NicB), (partition_label R, Write, partition_label NicB),\n    (partition_label R, Read,  partition_label NicD), (partition_label R, Write, partition_label NicD),\n    (partition_label SC, Read,  partition_label NicC), (partition_label SC, Write, partition_label NicC),\n    (partition_label SC, SyncSend, partition_label EP),\n    (partition_label RM, Receive, partition_label EP),\n    (partition_label RM, Control, partition_label R),\n    (partition_label RM, Control, partition_label NicA),\n    (partition_label RM, Control, partition_label NicB),\n    (partition_label RM, Control, partition_label NicD),\n    (partition_label T, Notify, partition_label NTFN1),\n    (partition_label T, Notify, partition_label NTFN2),\n    (partition_label T, Notify, partition_label NTFN3),\n    (partition_label SC, Receive, partition_label NTFN1),\n    (partition_label RM, Receive, partition_label NTFN2),\n    (partition_label R, Receive, partition_label NTFN3)\n  }\"\ndeclare SACGraph_def [simp]\n\ndefinition SACAuthGraph  where\n  \"SACAuthGraph = complete_AgentAuthGraph SACGraph\"\ndeclare SACAuthGraph_def [simp]\n\ndefinition SACAllLabels where\n  \"SACAllLabels \\<equiv> {partition_label NicB, partition_label RM, partition_label R, partition_label NicA, partition_label NicD, partition_label EP, partition_label SC, partition_label NicC}\"\n\ndefinition RMControls where\n  \"RMControls = {partition_label RM, partition_label R, partition_label NicA, partition_label NicB, partition_label NicD}\"\ndeclare RMControls_def [simp]\n\nlemma reads_all_rm_controlled_subjects : \"\\<lbrakk>partition_label RM \\<in> subjectReads SACAuthGraph (partition_label x); l \\<in> RMControls\\<rbrakk> \\<Longrightarrow> l \\<in> subjectReads SACAuthGraph (partition_label x)\"\n  apply (simp only:RMControls_def)\n  apply (erule insertE, rule_tac t=\"partition_label RM\" in reads_read_thread_read_pages, simp, simp)+\n  apply simp\ndone\n\nlemma reads_ntfn3_via_r : \"partition_label R \\<in> subjectReads SACAuthGraph (partition_label x) \\<Longrightarrow> partition_label NTFN3 \\<in> subjectReads SACAuthGraph (partition_label x)\"\n  apply (rule_tac ep=\"partition_label NTFN3\" and t=\"partition_label R\" and auth=\"Receive\" and auth'=\"Notify\" and a=\"partition_label T\" in reads_read_queued_thread_read_ep)\n  apply simp_all\ndone\n\nlemma reads_ntfn2_via_rm : \"partition_label RM \\<in> subjectReads SACAuthGraph (partition_label x) \\<Longrightarrow> partition_label NTFN2 \\<in> subjectReads SACAuthGraph (partition_label x)\"\n  apply (rule_tac ep=\"partition_label NTFN2\" and t=\"partition_label RM\" and auth=\"Receive\" and auth'=\"Notify\" and a=\"partition_label T\" in reads_read_queued_thread_read_ep)\n  apply simp_all\ndone\n\nlemma reads_ntfn1_via_sc : \"partition_label SC \\<in> subjectReads SACAuthGraph (partition_label x) \\<Longrightarrow> partition_label NTFN1 \\<in> subjectReads SACAuthGraph (partition_label x)\"\n  apply (rule_tac ep=\"partition_label NTFN1\" and t=\"partition_label SC\" and auth=\"Receive\" and auth'=\"Notify\" and a=\"partition_label T\" in reads_read_queued_thread_read_ep)\n  apply simp_all\ndone\n\nsubsection \\<open>NicA, NicB, NicD reads/affects\\<close>\n\nlemma reads_Control_rev':\n  \"(x,Control,y) \\<in> aag \\<Longrightarrow>\n    x \\<in> subjectReads (complete_AgentAuthGraph aag) y\"\n  apply(rule reads_read_page_read_thread)\n   apply(rule reads_lrefl)\n  apply simp\n  done\n\nlemma reads_Control_rev:\n  \"(x,Control,y) \\<in> SACGraph \\<Longrightarrow>\n   x \\<in> subjectReads SACAuthGraph y\"\n  apply(subst SACAuthGraph_def)\n  apply(erule reads_Control_rev')\n  done\n\n\nlemma abdrm_reads_ep : \"x \\<in> {NicA, NicB, NicD, RM} \\<Longrightarrow> partition_label EP \\<in> subjectReads SACAuthGraph (partition_label x)\"\n  apply (rule_tac t = \"partition_label RM\" and a = \"partition_label SC\" and auth' = \"SyncSend\" and auth = \"Receive\" in reads_read_queued_thread_read_ep)\n      apply (simp+)[4]\n  apply safe\n     apply(fastforce intro: reads_Control_rev simp del: complete_AgentAuthGraph_def)\n    apply(fastforce intro: reads_Control_rev simp del: complete_AgentAuthGraph_def)\n   apply(fastforce intro: reads_Control_rev simp del: complete_AgentAuthGraph_def)\n  done\n\nlemma abdrm_reads_sc : \"x \\<in> {NicA, NicB, NicD, RM} \\<Longrightarrow> partition_label SC \\<in> subjectReads SACAuthGraph (partition_label x)\"\n    apply (rule_tac b = \"partition_label SC\" and ep = \"partition_label EP\" in read_sync_ep_read_senders)\n      apply (simp del: SACAuthGraph_def add: abdrm_reads_ep, simp)\ndone\n\nlemma abd_reads_rm : \"x \\<in> {NicA, NicB, NicD} \\<Longrightarrow> partition_label RM \\<in> subjectReads SACAuthGraph (partition_label x)\"\n  apply (rule reads_Control_rev)\n  apply auto\ndone\n\nlemma abd_reads_c : \"x \\<in> {NicA, NicB, NicD} \\<Longrightarrow> partition_label NicC \\<in> subjectReads SACAuthGraph (partition_label x)\"\n  apply (rule_tac t = \"partition_label SC\" in reads_read_thread_read_pages)\n  apply (rule abdrm_reads_sc, simp, blast, simp)\ndone\n\nlemma abd_reads_r : \"x \\<in> {NicA, NicB, NicD} \\<Longrightarrow> partition_label R \\<in> subjectReads SACAuthGraph (partition_label x)\"\n  apply (rule_tac p=\"partition_label R\" and t=\"partition_label RM\" in reads_read_thread_read_pages)\n  apply (rule abd_reads_rm, simp, simp)\ndone\n\nlemma abd_reads_ntfn3 : \"x \\<in> {NicA, NicB, NicD} \\<Longrightarrow> partition_label NTFN3 \\<in> subjectReads SACAuthGraph (partition_label x)\"\n  apply (rule_tac ep=\"partition_label NTFN3\" and t=\"partition_label R\" and auth=\"Receive\" and auth'=\"Notify\" and a=\"partition_label T\" in reads_read_queued_thread_read_ep)\n  apply (simp_all add: abd_reads_r del:SACAuthGraph_def, simp_all)\ndone\n\nlemma abd_reads_all_bw : \"x \\<in> {NicA, NicB, NicD} \\<Longrightarrow> {partition_label NicB, partition_label RM, partition_label R, partition_label NicA, partition_label NicD, partition_label EP, partition_label SC, partition_label NicC, partition_label NTFN1, partition_label NTFN2, partition_label NTFN3} \\<subseteq> subjectReads SACAuthGraph (partition_label x)\"\n  apply (rule subsetI)\n  (* refl cases *)\n  apply (case_tac \"partition_label x = xa\")\n  apply simp\n  (* non refl cases *)\n  apply (case_tac \"xa \\<in> RMControls\")\n    apply (rule reads_all_rm_controlled_subjects, rule abd_reads_rm, simp, simp)\n  apply (erule_tac a = xa in insertE, simp)\n  apply (erule_tac a = xa in insertE, simp only:, rule abd_reads_rm, simp)\n  apply (erule_tac a = xa in insertE, simp)\n  apply (erule_tac a = xa in insertE, simp)\n  apply (erule_tac a = xa in insertE, simp)\n  apply (erule_tac a = xa in insertE, simp only:, rule abdrm_reads_ep, simp, blast)\n  apply (erule_tac a = xa in insertE, simp only:, rule abdrm_reads_sc, simp, blast)\n  apply (erule_tac a = xa in insertE, simp only:, rule abd_reads_c, simp)\n  apply (erule_tac a = xa in insertE, simp only:, rule reads_ntfn1_via_sc, rule abdrm_reads_sc, simp, blast)\n  apply (erule_tac a = xa in insertE, simp only:, rule reads_ntfn2_via_rm, rule abd_reads_rm, simp)\n  apply (erule_tac a = xa in insertE, simp only:, rule reads_ntfn3_via_r, rule abd_reads_r, simp)\n  apply simp\ndone\n\nlemma abd_reads : \"x \\<in> {NicA, NicB, NicD} \\<Longrightarrow> subjectReads SACAuthGraph (partition_label x) = {partition_label NicB, partition_label RM, partition_label R, partition_label NicA, partition_label NicD, partition_label EP, partition_label SC, partition_label NicC, partition_label NTFN1, partition_label NTFN2, partition_label NTFN3}\"\n   apply (rule subset_antisym)\n   defer\n   apply (rule abd_reads_all_bw)\n   apply (simp)\n   apply (rule subsetI)\n     apply (erule subjectReads.induct)\n     (* warning: slow *)\n     by (simp, blast?)+\n\n\ndefinition abd_affects_set where\n \"abd_affects_set \\<equiv> {NicB, RM, R, NicA, NicD,\n                     EP, NTFN2}\" (* these two added for NTFN binding *)\ndeclare abd_affects_set_def[simp]\n\nlemma abd_affects_bw : \"x \\<in> {NicA, NicB, NicD} \\<Longrightarrow> partition_label ` abd_affects_set \\<subseteq> subjectAffects SACAuthGraph (partition_label x)\"\n  apply (simp only:abd_affects_set_def)\n  apply (rule subsetI)\n  (* refl cases *)\n  apply (case_tac \"partition_label x = xa\")\n    apply (simp add: affects_lrefl)\n  (* non-refl cases *)\n  apply (simp only: image_insert)\n  apply (erule_tac a = xa in insertE)\n    apply (rule_tac auth = SyncSend and ep = \"partition_label x\" and l' = \"partition_label RM\" in affects_send)\n    apply (simp, simp, simp, simp)\n  apply (erule_tac a = xa in insertE)\n    apply (simp only:)\n    apply (rule_tac ep = \"partition_label x\" and l' = \"partition_label RM\" in affects_recv)\n      apply (simp)\n      apply (auto)[1]\n  apply (erule_tac a = xa in insertE)\n    apply (simp only:)\n    apply (rule_tac auth = SyncSend and ep = \"partition_label x\" and l' = \"partition_label RM\" in affects_send)\n    apply (simp, simp, simp, simp)\n  apply (erule_tac a = xa in insertE)\n    apply (simp only:)\n    apply (clarify)\n    apply (erule notE)\n    apply (rule_tac auth = SyncSend and ep = \"partition_label x\" and l' = \"partition_label RM\" in affects_send)\n    apply (simp, simp, simp, simp)\n  apply (erule_tac a = xa in insertE)\n    apply (rule_tac auth = SyncSend and ep = \"partition_label x\" and l' = \"partition_label RM\" in affects_send)\n    apply (simp, simp, simp, simp)\n  apply (erule_tac a = xa in insertE)\n    apply (rule_tac ep = \"xa\" and l = \"partition_label x\" in affects_ep_bound_trans)\n    apply (rule_tac x = \"partition_label RM\" in exI)\n    apply (rule_tac x = \"partition_label x\" in exI)\n    apply (intro conjI)\n    apply (simp,simp,simp)\n  apply (erule_tac a = xa in insertE)\n    apply (rule_tac ep = \"xa\" and l = \"partition_label x\" in affects_ep_bound_trans)\n    apply (rule_tac x = \"partition_label RM\" in exI)\n    apply (rule_tac x = \"partition_label x\" in exI)\n    apply (intro conjI)\n    apply (simp,simp,simp,simp)\n  done\n\nlemma abd_affects : \"x \\<in> {NicA, NicB, NicD} \\<Longrightarrow> subjectAffects SACAuthGraph (partition_label x) = partition_label ` abd_affects_set\"\n   apply (rule subset_antisym)\n   defer\n   apply (rule abd_affects_bw)\n   apply (simp)\n   apply (rule subsetI)\n     apply (erule subjectAffects.induct)\n     by auto\n\nsubsection \\<open>NicC reads/affects\\<close>\n\nlemma c_reads_sc : \"partition_label SC \\<in> subjectReads SACAuthGraph (partition_label NicC)\"\n  apply (rule_tac b = \"partition_label NicC\" in reads_read_page_read_thread)\n  apply (rule reads_lrefl)\n  apply (simp)\ndone\n\nlemma c_reads_ep : \"partition_label EP \\<in> subjectReads SACAuthGraph (partition_label NicC)\"\n  apply (rule_tac a = \"partition_label EP\" and ep = \"partition_label EP\" and t = \"partition_label SC\" and auth = \"SyncSend\" and auth' = \"Reset\" in reads_read_queued_thread_read_ep)\n  apply (simp,simp,simp,simp)\n  apply (rule c_reads_sc)\ndone\n\nlemma c_reads_rm : \"partition_label RM \\<in> subjectReads SACAuthGraph (partition_label NicC)\"\n  apply (rule_tac ep = \"partition_label EP\" in read_sync_ep_read_receivers)\n   apply (rule c_reads_ep)\n   apply (simp)\ndone\n\nlemma c_reads_any_controlled_by_rm : \"x \\<in> {partition_label R, partition_label NicA, partition_label NicB, partition_label NicD} \\<Longrightarrow> x \\<in> subjectReads SACAuthGraph (partition_label NicC)\"\n  apply (rule_tac t = \"partition_label RM\" in reads_read_thread_read_pages)\n    apply (rule c_reads_rm)\n    apply auto\ndone\n\nlemma c_reads : \"subjectReads SACAuthGraph (partition_label NicC) = {partition_label NicB, partition_label RM, partition_label R, partition_label NicA, partition_label NicD, partition_label EP, partition_label SC, partition_label NicC, partition_label NTFN1, partition_label NTFN2, partition_label NTFN3}\"\n  apply (rule subset_antisym)\n    defer\n    (* backward *)\n    apply (rule subsetI)\n      apply (case_tac \"x \\<in> {partition_label R, partition_label NicA, partition_label NicB, partition_label NicD}\")\n        apply (rule c_reads_any_controlled_by_rm, assumption)\n        apply (erule insertE, simp)\n        apply (erule insertE, simp only:, rule c_reads_rm)\n        apply (erule insertE, simp, erule insertE, simp, erule insertE, simp)\n        apply (erule insertE, simp only:, rule c_reads_ep)\n        apply (erule insertE, simp only:, rule c_reads_sc)\n        apply (erule insertE, simp only:, rule reads_lrefl)\n        apply (erule insertE, simp only:, rule reads_ntfn1_via_sc, rule c_reads_sc)\n        apply (erule insertE, simp only:, rule reads_ntfn2_via_rm, rule c_reads_rm)\n        apply (erule insertE, simp only:, rule reads_ntfn3_via_r, rule c_reads_any_controlled_by_rm, simp)\n        apply simp\n    (* forward *)\n    apply (rule subsetI)\n    apply (erule subjectReads.induct)\n    by (simp, blast?)+\n\nlemma c_affects_self_only : \"x \\<in> {partition_label NicC} \\<Longrightarrow> x \\<in> subjectAffects SACAuthGraph (partition_label NicC)\"\n  apply (erule insertE)\n    apply (simp only:, rule affects_lrefl)\n    apply simp\ndone\n\nlemma c_affects : \"subjectAffects SACAuthGraph (partition_label NicC) = {partition_label NicC}\"\n  apply (rule subset_antisym)\n  defer\n    (* backward *)\n    apply (rule subsetI)\n    apply (rule c_affects_self_only, assumption)\n    (* forward *)\n    apply (rule subsetI)\n    apply (erule subjectAffects.induct)\n    by (simp, blast?)+\n\nsubsection \\<open>R reads/affects\\<close>\n\nlemma r_reads_bd : \"x \\<in> {partition_label NicB, partition_label NicD} \\<Longrightarrow> x \\<in> subjectReads SACAuthGraph (partition_label R)\"\n  apply (rule reads_read)\n  apply auto\ndone\n\nlemma r_reads_ep : \"partition_label EP \\<in> subjectReads SACAuthGraph (partition_label R)\"\n    apply (rule_tac a=\"partition_label SC\" and auth'=\"SyncSend\" and ep=\"partition_label EP\" and t=\"partition_label RM\" and auth=\"Receive\" in reads_read_queued_thread_read_ep)\n    apply (simp, simp, simp, simp, rule reads_Control_rev, simp)\ndone\n\nlemma r_reads_sc : \"partition_label SC \\<in> subjectReads SACAuthGraph (partition_label R)\"\n    apply (rule_tac ep=\"partition_label EP\" and b=\"partition_label SC\" in read_sync_ep_read_senders)\n    apply (rule r_reads_ep, simp)\ndone\n\nlemma r_reads_a : \"partition_label NicA \\<in> subjectReads SACAuthGraph (partition_label R)\"\n  apply (rule_tac a=\"partition_label NicA\" and auth'=\"Reset\" and ep=\"partition_label NicA\" and t=\"partition_label RM\" and auth=\"Receive\" in reads_read_queued_thread_read_ep)\n  apply (simp_all add:reads_Control_rev[simplified])\ndone\n\nlemma r_reads_c : \"partition_label NicC \\<in> subjectReads SACAuthGraph (partition_label R)\"\n  apply (rule_tac t=\"partition_label SC\" in reads_read_thread_read_pages)\n  apply (rule r_reads_sc, simp)\ndone\n\nlemma r_reads : \"subjectReads SACAuthGraph (partition_label R) = {partition_label NicB, partition_label RM, partition_label R, partition_label NicA, partition_label NicD, partition_label EP, partition_label SC, partition_label NicC, partition_label NTFN1, partition_label NTFN2, partition_label NTFN3}\"\n  apply (rule subset_antisym)\n    defer\n    (* backward *)\n    apply (rule subsetI)\n    apply (erule insertE, rule r_reads_bd, simp)\n    apply (erule insertE, rule reads_Control_rev, simp)\n    apply (erule insertE, simp only:, rule reads_lrefl)\n    apply (erule insertE, simp only:, rule r_reads_a)\n    apply (erule insertE, rule r_reads_bd, simp)\n    apply (erule insertE, simp only:, rule r_reads_ep)\n    apply (erule insertE, simp only:, rule r_reads_sc)\n    apply (erule insertE, simp only:, rule r_reads_c)\n    apply (erule insertE, simp only:, rule reads_ntfn1_via_sc, rule r_reads_sc)\n    apply (erule insertE, simp only:, rule reads_ntfn2_via_rm, rule reads_Control_rev, simp)\n    apply (erule insertE, simp only:, rule reads_ntfn3_via_r, rule reads_lrefl)\n    apply simp\n    (* forward *)\n    apply (rule subsetI)\n    apply (erule subjectReads.induct)\n    by (simp, blast?)+\n\nlemma r_affects_bd : \"x \\<in> {partition_label NicB, partition_label NicD} \\<Longrightarrow> x \\<in> subjectAffects SACAuthGraph (partition_label R)\"\n  apply (rule_tac auth=\"Write\" in affects_write)\n  apply auto\ndone\n\nlemma r_affects_rm : \"partition_label RM \\<in> subjectAffects SACAuthGraph (partition_label R)\"\n  apply (rule_tac l=\"partition_label R\" and ep=\"partition_label R\" in affects_recv)\n  apply simp_all\ndone\n\nlemma r_affects_a : \"partition_label NicA \\<in> subjectAffects SACAuthGraph (partition_label R)\"\n  apply (rule_tac l=\"partition_label R\" and ep=\"partition_label R\" and l'=\"partition_label RM\" and auth=\"Receive\" in affects_reset)\n  apply auto\ndone\n\nlemma r_affects_ntfn3 : \"partition_label NTFN3 \\<in> subjectAffects SACAuthGraph (partition_label R)\"\n  apply (rule_tac l=\"partition_label R\" and auth=\"Receive\" in affects_ep)\n  apply simp_all\ndone\n\nlemma r_affects_ntfn2 : \"partition_label NTFN2 \\<in> subjectAffects SACAuthGraph (partition_label R)\"\n  apply (rule_tac l=\"partition_label R\" in affects_ep_bound_trans)\n  by auto\n\nlemma r_affects_ep : \"partition_label EP \\<in> subjectAffects SACAuthGraph (partition_label R)\"\n  apply (rule_tac l=\"partition_label R\" in affects_ep_bound_trans)\n  by auto\n\nlemma r_affects : \"subjectAffects SACAuthGraph (partition_label R) =\n                   {partition_label NicB, partition_label NicD, partition_label R,\n                    partition_label RM, partition_label NicA, partition_label NTFN3,\n                    partition_label EP, partition_label NTFN2 \\<comment> \\<open>these 2 added for NTFN binding\\<close> }\"\n  apply (rule subset_antisym)\n  defer\n  (* backward *)\n  apply (rule subsetI)\n  apply (erule insertE, rule r_affects_bd, simp)\n  apply (erule insertE, rule r_affects_bd, simp)\n  apply (erule insertE, simp only:, rule affects_lrefl)\n  apply (erule insertE, simp only:, rule r_affects_rm)\n  apply (erule insertE, simp only:, rule r_affects_a)\n  apply (erule insertE, simp only:, rule r_affects_ntfn3)\n  apply (erule insertE, simp only:, rule r_affects_ep)\n  apply (erule insertE, simp only:, rule r_affects_ntfn2)\n  apply simp\n  (* forward *)\n  apply (rule subsetI)\n  apply (erule subjectAffects.induct)\n  by (simp, blast?)+\n\nsubsection \\<open>RM reads/affects\\<close>\n\nlemma rm_reads_sc : \"partition_label SC \\<in> subjectReads SACAuthGraph (partition_label RM)\"\n  apply (rule_tac ep=\"partition_label EP\" in read_sync_ep_read_senders)\n  apply (simp_all add:reads_ep)\ndone\n\nlemma rm_reads_c : \"partition_label NicC \\<in> subjectReads SACAuthGraph (partition_label RM)\"\n  apply (rule_tac t=\"partition_label SC\" in reads_read_thread_read_pages)\n  apply (rule rm_reads_sc, simp)\ndone\n\nlemma rm_reads : \"subjectReads SACAuthGraph (partition_label RM) = {partition_label NicB, partition_label RM, partition_label R, partition_label NicA, partition_label NicD, partition_label EP, partition_label SC, partition_label NicC, partition_label NTFN1, partition_label NTFN2, partition_label NTFN3}\"\n  apply (rule subset_antisym)\n  defer\n  (* backward *)\n  apply (rule subsetI)\n  apply (erule insertE, simp only:, rule reads_read, simp)\n  apply (erule insertE, simp only:, rule reads_lrefl)\n  apply (erule insertE, simp only:, rule reads_read, simp)\n  apply (erule insertE, simp only:, rule reads_read, simp)\n  apply (erule insertE, simp only:, rule reads_read, simp)\n  apply (erule insertE, simp only:, rule reads_ep, simp, simp)\n  apply (erule insertE, simp only:, rule rm_reads_sc)\n  apply (erule insertE, simp only:, rule rm_reads_c)\n  apply (erule insertE, simp only:, rule reads_ntfn1_via_sc, rule rm_reads_sc)\n  apply (erule insertE, simp only:, rule reads_ntfn2_via_rm, rule reads_lrefl)\n  apply (erule insertE, simp only:, rule reads_ntfn3_via_r, rule reads_read, simp)\n  apply simp\n  (* forward *)\n  apply (rule subsetI)\n  apply (erule subjectReads.induct)\n  by (simp, blast?)+\n\nlemma rm_affects_via_control : \"x \\<in> {partition_label R, partition_label NicA, partition_label NicB, partition_label NicD} \\<Longrightarrow> x \\<in> subjectAffects SACAuthGraph (partition_label RM)\"\n  apply (rule_tac l=\"partition_label RM\" and auth=\"Control\" in affects_write)\n  apply (simp, simp)\ndone\n\nlemma rm_affects_ep : \"partition_label EP \\<in> subjectAffects SACAuthGraph (partition_label RM)\"\n  apply (rule_tac auth=\"Receive\" in affects_ep)\n  apply simp_all\ndone\n\nlemma rm_affects_sc : \"partition_label SC \\<in> subjectAffects SACAuthGraph (partition_label RM)\"\n  apply (rule_tac l=\"partition_label RM\" and ep=\"partition_label EP\" in affects_recv)\n  apply simp_all\ndone\n\nlemma rm_affects_ntfn2 : \"partition_label NTFN2 \\<in> subjectAffects SACAuthGraph (partition_label RM)\"\n  apply (rule_tac l=\"partition_label RM\" and auth=\"Receive\" in affects_ep)\n  apply simp_all\ndone\n\nlemma rm_affects_ntfn3 : \"partition_label NTFN3 \\<in> subjectAffects SACAuthGraph (partition_label RM)\"\n  apply (rule_tac l=\"partition_label RM\" in affects_ep_bound_trans)\n  apply clarsimp\n  by auto\n\n\nlemma rm_affects : \"subjectAffects SACAuthGraph (partition_label RM) =\n                    {partition_label NicA, partition_label NicB, partition_label NicD,\n                     partition_label R, partition_label SC, partition_label EP,\n                     partition_label RM, partition_label NTFN2,\n                     partition_label NTFN3 \\<comment> \\<open>added for NTFN binding\\<close>}\"\n  apply (rule subset_antisym)\n  defer\n  (* backward *)\n  apply (rule subsetI)\n  apply (erule insertE, simp only:, rule rm_affects_via_control, simp)\n  apply (erule insertE, simp only:, rule rm_affects_via_control, simp)\n  apply (erule insertE, simp only:, rule rm_affects_via_control, simp)\n  apply (erule insertE, simp only:, rule rm_affects_via_control, simp)\n  apply (erule insertE, simp only:, rule rm_affects_sc)\n  apply (erule insertE, simp only:, rule rm_affects_ep)\n  apply (erule insertE, simp only:, rule affects_lrefl)\n  apply (erule insertE, simp only:, rule rm_affects_ntfn2)\n  apply (erule insertE, simp only:, rule rm_affects_ntfn3)\n  apply simp\n  (* forward *)\n  apply (rule subsetI)\n  apply (erule subjectAffects.induct)\n  by (simp, blast?)+\n\nsubsection \\<open>SC\\<close>\n\nlemma sc_reads_rm : \"partition_label RM \\<in> subjectReads SACAuthGraph (partition_label SC)\"\n  apply (rule_tac ep=\"partition_label EP\" and b=\"partition_label RM\" in read_sync_ep_read_receivers)\n  apply (simp_all add:reads_ep)\ndone\n\nlemma sc_reads : \"subjectReads SACAuthGraph (partition_label SC) = {partition_label NicB, partition_label RM, partition_label R, partition_label NicA, partition_label NicD, partition_label EP, partition_label SC, partition_label NicC, partition_label NTFN1, partition_label NTFN2, partition_label NTFN3}\"\n  apply (rule subset_antisym)\n  defer\n  (* backward *)\n  apply (rule subsetI)\n  apply (erule insertE, rule reads_all_rm_controlled_subjects, rule sc_reads_rm, simp)\napply (erule insertE, rule reads_all_rm_controlled_subjects, rule sc_reads_rm, simp)\napply (erule insertE, rule reads_all_rm_controlled_subjects, rule sc_reads_rm, simp)\napply (erule insertE, rule reads_all_rm_controlled_subjects, rule sc_reads_rm, simp)\napply (erule insertE, rule reads_all_rm_controlled_subjects, rule sc_reads_rm, simp)\n  apply (erule insertE, simp only:, rule_tac auth=\"SyncSend\" in reads_ep, simp, simp)\n  apply (erule insertE, simp only:, rule reads_lrefl)\n  apply (erule insertE, simp only:, rule reads_read, simp)\n  apply (erule insertE, simp only:, rule reads_ntfn1_via_sc, rule reads_lrefl)\n  apply (erule insertE, simp only:, rule reads_ntfn2_via_rm, rule sc_reads_rm)\n  apply (erule insertE, simp only:, rule reads_ntfn3_via_r, rule reads_all_rm_controlled_subjects, rule sc_reads_rm, simp)\n  apply simp\n  (* forward *)\n  apply (rule subsetI)\n  apply (erule subjectReads.induct)\n  apply (simp, blast?)+\ndone\n\nlemma sc_affects_all_rm_controls : \"l \\<in> RMControls \\<Longrightarrow> l \\<in> subjectAffects SACAuthGraph (partition_label SC)\"\n  apply (simp only:RMControls_def)\n  apply (erule insertE, rule_tac l=\"partition_label SC\" and auth=\"SyncSend\" and ep=\"partition_label EP\" and l'=\"partition_label RM\" in affects_send, simp, simp, simp, simp)+\n  apply simp\ndone\n\nlemma sc_affects : \"subjectAffects SACAuthGraph (partition_label SC) = {partition_label NicB, partition_label RM, partition_label R, partition_label NicA, partition_label NicD, partition_label EP, partition_label SC, partition_label NicC, partition_label NTFN1}\"\n  apply (rule subset_antisym)\n  defer\n  (* backward *)\n  apply (rule subsetI)\n  apply (erule insertE, rule sc_affects_all_rm_controls, simp)\n  apply (erule insertE, rule sc_affects_all_rm_controls, simp)\n  apply (erule insertE, rule sc_affects_all_rm_controls, simp)\n  apply (erule insertE, rule sc_affects_all_rm_controls, simp)\n  apply (erule insertE, rule sc_affects_all_rm_controls, simp)\n  apply (erule insertE, simp only:, rule_tac l=\"partition_label SC\" and auth=\"SyncSend\" in affects_ep, simp, simp)\n  apply (erule insertE, simp only:, rule affects_lrefl)\n  apply (erule insertE, simp only:, rule_tac l=\"partition_label SC\" and auth=\"Write\" in affects_write, simp, simp)\n  apply (erule insertE, simp only:, rule_tac l=\"partition_label SC\" and auth=\"Receive\" in affects_ep, simp, simp)\n  apply simp\n  (* forward *)\n  apply (rule subsetI)\n  apply (erule subjectAffects.induct)\n  apply (simp, blast?)+\ndone\n\nsubsection \\<open>EP\\<close>\n\nlemma ep_reads_sc : \"partition_label SC \\<in> subjectReads SACAuthGraph (partition_label EP)\"\n  apply (rule_tac ep=\"partition_label EP\" in read_sync_ep_read_senders)\n  apply (rule reads_lrefl, simp_all)\ndone\n\nlemma ep_reads_rm : \"partition_label RM \\<in> subjectReads SACAuthGraph (partition_label EP)\"\n  apply (rule_tac ep=\"partition_label EP\" and b=\"partition_label RM\" in read_sync_ep_read_receivers)\n  apply (rule reads_lrefl, simp)\ndone\n\nlemma ep_reads_c : \"partition_label NicC \\<in> subjectReads SACAuthGraph (partition_label EP)\"\n  apply (rule_tac t=\"partition_label SC\" and p=\"partition_label NicC\" in reads_read_thread_read_pages)\n  apply (rule ep_reads_sc, simp)\ndone\n\nlemma ep_reads : \"subjectReads SACAuthGraph (partition_label EP) = {partition_label NicB, partition_label RM, partition_label R, partition_label NicA, partition_label NicD, partition_label EP, partition_label SC, partition_label NicC, partition_label NTFN1, partition_label NTFN2, partition_label NTFN3}\"\n  apply (rule subset_antisym)\n  defer\n  (* backward *)\n  apply (rule subsetI)\n  apply (erule insertE, rule reads_all_rm_controlled_subjects, rule ep_reads_rm, simp)\n  apply (erule insertE, simp only:, rule ep_reads_rm)\n  apply (erule insertE, rule reads_all_rm_controlled_subjects, rule ep_reads_rm, simp)\n  apply (erule insertE, rule reads_all_rm_controlled_subjects, rule ep_reads_rm, simp)\n  apply (erule insertE, rule reads_all_rm_controlled_subjects, rule ep_reads_rm, simp)\n  apply (erule insertE, simp only:, rule reads_lrefl)\n  apply (erule insertE, simp only:, rule ep_reads_sc)\n  apply (erule insertE, simp only:, rule ep_reads_c)\n  apply (erule insertE, simp only:, rule reads_ntfn1_via_sc, rule ep_reads_sc)\n  apply (erule insertE, simp only:, rule reads_ntfn2_via_rm, rule ep_reads_rm)\n  apply (erule insertE, simp only:, rule reads_ntfn3_via_r, rule reads_all_rm_controlled_subjects, rule ep_reads_rm, simp)\n  apply simp\n  (* forward *)\n  apply (rule subsetI)\n  apply (erule subjectReads.induct)\n  apply (simp, blast?)+\ndone\n\nlemma ep_affects_sc : \"partition_label SC \\<in> subjectAffects SACAuthGraph (partition_label EP)\"\n  apply (rule_tac l=\"partition_label EP\" and ep=\"partition_label EP\" in affects_recv)\n  apply simp_all\ndone\n\nlemma ep_affects_c : \"partition_label NicC \\<in> subjectAffects SACAuthGraph (partition_label EP)\"\n  apply (rule_tac l=\"partition_label EP\" and l'=\"partition_label SC\" and auth=\"SyncSend\" and ep=\"partition_label EP\" in affects_reset)\n  apply simp_all\ndone\n\nlemma ep_affects_ntfn2 : \"partition_label NTFN2 \\<in> subjectAffects SACAuthGraph (partition_label EP)\"\n  apply (rule_tac ep=\"partition_label NTFN2\" in affects_ep_bound_trans)\n  by auto\n\nlemma ep_affects_rm_controls : \"x \\<in> RMControls \\<Longrightarrow> x \\<in> subjectAffects SACAuthGraph (partition_label EP)\"\n  apply (rule_tac l=\"partition_label EP\" and ep=\"partition_label EP\" and auth=\"SyncSend\" and l'=\"partition_label RM\" in affects_send)\n  apply (simp_all)\ndone\n\nlemma ep_affects: \"subjectAffects SACAuthGraph (partition_label EP) = {partition_label EP, partition_label SC, partition_label NicC, partition_label NTFN2} \\<union> RMControls\"\n  apply (rule subset_antisym)\n  defer\n  (* backward *)\n  apply (rule subsetI)\n  apply (erule UnE)\n  apply (erule insertE, simp only:, rule affects_lrefl)\n  apply (erule insertE, simp only:, rule ep_affects_sc)\n  apply (erule insertE, simp only:, rule ep_affects_c)\n  apply (erule insertE, simp only:, rule ep_affects_ntfn2)\n  apply simp\n  apply (rule ep_affects_rm_controls, simp)\n  (* forward *)\n  apply (rule subsetI)\n  apply (erule subjectAffects.induct)\n  by (simp, blast?)+\n\nsubsection \\<open>NTFN1,2,3\\<close>\n\nsubsubsection \\<open>NTFN1 reads SC, EP, RM, R\\<close>\n\nlemma ntfn1_reads_sc : \"partition_label SC \\<in> subjectReads SACAuthGraph (partition_label NTFN1)\"\n  apply (rule_tac ep=\"partition_label NTFN1\" in read_sync_ep_read_receivers)\n  apply (rule reads_lrefl, simp)\ndone\n\nlemma ntfn1_reads_ep : \"partition_label EP \\<in> subjectReads SACAuthGraph (partition_label NTFN1)\"\n  apply (rule_tac ep=\"partition_label EP\" and auth=\"SyncSend\" and t=\"partition_label SC\" and auth'=\"Reset\" and a=\"partition_label EP\" in reads_read_queued_thread_read_ep)\n  apply (simp, simp, simp, simp, rule ntfn1_reads_sc)\ndone\n\nlemma ntfn1_reads_rm : \"partition_label RM \\<in> subjectReads SACAuthGraph (partition_label NTFN1)\"\n  apply (rule_tac b=\"partition_label RM\" and ep=\"partition_label EP\" in read_sync_ep_read_receivers)\n  apply (rule ntfn1_reads_ep, simp)\ndone\n\nsubsubsection \\<open>NTFN2 reads SC, EP, RM, R\\<close>\n\nlemma ntfn2_reads_rm : \"partition_label RM \\<in> subjectReads SACAuthGraph (partition_label NTFN2)\"\n  apply (rule_tac ep=\"partition_label NTFN2\" in read_sync_ep_read_receivers)\n  apply (rule reads_lrefl, simp)\ndone\n\nlemma ntfn2_reads_ep : \"partition_label EP \\<in> subjectReads SACAuthGraph (partition_label NTFN2)\"\n  apply (rule_tac ep=\"partition_label EP\" and auth=\"Receive\" and t=\"partition_label RM\" and auth'=\"Reset\" and a=\"partition_label EP\" in reads_read_queued_thread_read_ep)\n  apply (simp, simp, simp, simp, rule ntfn2_reads_rm)\ndone\n\nlemma ntfn2_reads_sc : \"partition_label SC \\<in> subjectReads SACAuthGraph (partition_label NTFN2)\"\n  apply (rule_tac b=\"partition_label SC\" and ep=\"partition_label EP\" in read_sync_ep_read_senders)\n  apply (rule ntfn2_reads_ep, simp)\ndone\n\nsubsubsection \\<open>NTFN3 reads SC, EP, RM, R\\<close>\n\nlemma ntfn3_reads_r : \"partition_label R \\<in> subjectReads SACAuthGraph (partition_label NTFN3)\"\n  apply (rule_tac ep=\"partition_label NTFN3\" in read_sync_ep_read_receivers)\n  apply (rule reads_lrefl, simp)\ndone\n\nlemma ntfn3_reads_rm : \"partition_label RM \\<in> subjectReads SACAuthGraph (partition_label NTFN3)\"\n  apply (rule_tac b=\"partition_label R\" in reads_read_page_read_thread)\n  apply (rule ntfn3_reads_r, simp)\ndone\n\nlemma ntfn3_reads_ep : \"partition_label EP \\<in> subjectReads SACAuthGraph (partition_label NTFN3)\"\n  apply (rule_tac t=\"partition_label RM\" and auth=\"Receive\" and auth'=\"SyncSend\" and a=\"partition_label SC\" in reads_read_queued_thread_read_ep)\n  apply (simp, simp, simp, simp, rule ntfn3_reads_rm)\ndone\n\nlemma ntfn3_reads_sc : \"partition_label SC \\<in> subjectReads SACAuthGraph (partition_label NTFN3)\"\n  apply (rule_tac ep=\"partition_label EP\" in read_sync_ep_read_senders)\n  apply (rule ntfn3_reads_ep, simp)\ndone\n\nsubsubsection \\<open>NTFN1,2,3 reads C\\<close>\n\nlemma ntfn123_reads_c : \"x \\<in> {NTFN1, NTFN2, NTFN3} \\<Longrightarrow> partition_label NicC \\<in> subjectReads SACAuthGraph (partition_label x)\"\n  apply (rule_tac t=\"partition_label SC\" in reads_read_thread_read_pages)\n  apply (erule insertE, simp only:, rule ntfn1_reads_sc, erule insertE, simp only:, rule ntfn2_reads_sc, erule insertE, simp only:, rule ntfn3_reads_sc, simp)\n  apply simp\ndone\n\nsubsubsection \\<open>NTFN1,2,3 reads each other\\<close>\n\nlemma ntfn13_reads_ntfn2 : \"l \\<in> {NTFN1, NTFN3} \\<Longrightarrow> partition_label NTFN2 \\<in> subjectReads SACAuthGraph (partition_label l)\"\n  apply (rule_tac t=\"partition_label RM\" and auth=\"Receive\" and auth'=\"Reset\" and a=\"partition_label NTFN2\" in reads_read_queued_thread_read_ep)\n  apply (simp, simp, simp, simp)\n  apply (erule insertE, simp only:, rule ntfn1_reads_rm, erule insertE, simp only:, rule ntfn3_reads_rm, simp)\ndone\n\nlemma ntfn12_reads_ntfn3 : \"l \\<in> {NTFN1, NTFN2} \\<Longrightarrow> partition_label NTFN3 \\<in> subjectReads SACAuthGraph (partition_label l)\"\n  apply (rule_tac t=\"partition_label R\" and auth=\"Receive\" and auth'=\"Reset\" and a=\"partition_label NTFN3\" in reads_read_queued_thread_read_ep)\n  apply (simp, simp, simp, simp)\n  apply (erule insertE, simp only:, rule reads_all_rm_controlled_subjects, rule ntfn1_reads_rm, simp, erule insertE, simp only:, rule reads_all_rm_controlled_subjects, rule ntfn2_reads_rm, simp_all)\ndone\n\nlemma ntfn23_reads_ntfn1 : \"l \\<in> {NTFN2, NTFN3} \\<Longrightarrow> partition_label NTFN1 \\<in> subjectReads SACAuthGraph (partition_label l)\"\n  apply (rule_tac t=\"partition_label SC\" and auth=\"Receive\" and auth'=\"Reset\" and a=\"partition_label NTFN1\" in reads_read_queued_thread_read_ep)\n  apply (simp, simp, simp, simp)\n  apply (erule insertE, simp only:, rule ntfn2_reads_sc, erule insertE, simp only:, rule ntfn3_reads_sc, simp)\ndone\n\nsubsubsection \\<open>NTFN1,2,3 reads\\<close>\ndeclare SACAuthGraph_def[simp del]\n\nlemma ntfn123_reads_rm : \"l \\<in> {NTFN1, NTFN2, NTFN3} \\<Longrightarrow> partition_label RM \\<in> subjectReads SACAuthGraph (partition_label l)\"\nby (auto simp:ntfn1_reads_rm ntfn2_reads_rm ntfn3_reads_rm)\n\nlemma ntfn123_reads_sc : \"l \\<in> {NTFN1, NTFN2, NTFN3} \\<Longrightarrow> partition_label SC \\<in> subjectReads SACAuthGraph (partition_label l)\"\nby (auto simp:ntfn1_reads_sc ntfn2_reads_sc ntfn3_reads_sc)\n\nlemma ntfn123_reads_ep : \"l \\<in> {NTFN1, NTFN2, NTFN3} \\<Longrightarrow> partition_label EP \\<in> subjectReads SACAuthGraph (partition_label l)\"\nby (auto simp:ntfn1_reads_ep ntfn2_reads_ep ntfn3_reads_ep)\n\nlemma ntfn123_reads_ntfn123 : \"\\<lbrakk>l \\<in> {NTFN1, NTFN2, NTFN3}; x \\<in> {NTFN1, NTFN2, NTFN3}\\<rbrakk> \\<Longrightarrow> partition_label l \\<in> subjectReads SACAuthGraph (partition_label x)\"\nby (auto simp:ntfn12_reads_ntfn3 ntfn13_reads_ntfn2 ntfn23_reads_ntfn1)\n\nlemma ntfn123_reads : \"l \\<in> {NTFN1, NTFN2, NTFN3} \\<Longrightarrow> subjectReads SACAuthGraph (partition_label l) = {partition_label NicB, partition_label RM, partition_label R, partition_label NicA, partition_label NicD, partition_label EP, partition_label SC, partition_label NicC, partition_label NTFN1, partition_label NTFN2, partition_label NTFN3}\"\n  apply (rule subset_antisym)\n  defer\n  (* backward *)\n  apply (rule subsetI)\n  apply (erule_tac a=x in insertE, rule reads_all_rm_controlled_subjects, rule ntfn123_reads_rm, simp, simp)\n  apply (erule_tac a=x in insertE, simp only:, rule ntfn123_reads_rm, simp)\n  apply (erule_tac a=x in insertE, rule reads_all_rm_controlled_subjects, rule ntfn123_reads_rm, simp, simp)\n  apply (erule_tac a=x in insertE, rule reads_all_rm_controlled_subjects, rule ntfn123_reads_rm, simp, simp)\n  apply (erule_tac a=x in insertE, rule reads_all_rm_controlled_subjects, rule ntfn123_reads_rm, simp, simp)\n  apply (erule_tac a=x in insertE, simp only:, rule ntfn123_reads_ep, simp)\n  apply (erule_tac a=x in insertE, simp only:, rule ntfn123_reads_sc, simp)\n  apply (erule_tac a=x in insertE, simp only:, rule ntfn123_reads_c, simp)\n  apply (auto simp:ntfn123_reads_ntfn123)[1]\n  (* forward *)\n  apply (rule subsetI)\n  apply (erule subjectReads.induct)\n  by (simp add:SACAuthGraph_def, blast?)+\n\nsubsubsection \\<open>NTFN1,2,3 affects\\<close>\n\nlemma ntfn1_affects_sc : \"partition_label SC \\<in> subjectAffects SACAuthGraph (partition_label NTFN1)\"\n  apply (rule_tac l''=\"partition_label SC\" and l'=\"partition_label SC\" and ep=\"partition_label NTFN1\" and auth=\"Notify\" and l=\"partition_label NTFN1\" in affects_send)\n  apply (simp_all add:SACAuthGraph_def)\ndone\n\nlemma ntfn1_affects_c : \"partition_label NicC \\<in> subjectAffects SACAuthGraph (partition_label NTFN1)\"\n  apply (rule_tac l'=\"partition_label SC\" and ep=\"partition_label NTFN1\" and l=\"partition_label NTFN1\" and auth=\"Notify\" in affects_send)\n  apply (simp_all add:SACAuthGraph_def)\ndone\n\nlemma ntfn1_affects : \"subjectAffects SACAuthGraph (partition_label NTFN1) = {partition_label NTFN1, partition_label SC, partition_label NicC}\"\n  apply (rule subset_antisym)\n  defer\n  (* backward *)\n  apply (rule subsetI)\n  apply (erule insertE, simp only:, rule affects_lrefl)\n  apply (erule insertE, simp only:, rule ntfn1_affects_sc)\n  apply (erule insertE, simp only:, rule ntfn1_affects_c)\n  apply simp\n  (* forward *)\n  apply (rule subsetI)\n  apply (erule subjectAffects.induct)\n  apply (simp add:SACAuthGraph_def, blast?)+\ndone\n\nlemma ntfn2_affects_rm : \"partition_label RM \\<in> subjectAffects SACAuthGraph (partition_label NTFN2)\"\n  apply (rule_tac l'=\"partition_label RM\" and ep=\"partition_label NTFN2\" and auth=\"Notify\" and l=\"partition_label NTFN2\" in affects_send)\n  apply (simp_all add:SACAuthGraph_def)\ndone\n\nlemma ntfn2_affects_ep : \"partition_label EP \\<in> subjectAffects SACAuthGraph (partition_label NTFN2)\"\n  apply (rule affects_ep_bound_trans)\n  by (auto simp: SACAuthGraph_def)\n\nlemma ntfn2_affects_rm_controls : \"x \\<in> RMControls \\<Longrightarrow> x \\<in> subjectAffects SACAuthGraph (partition_label NTFN2)\"\n  apply (rule_tac l=\"partition_label NTFN2\" and ep=\"partition_label NTFN2\" and auth=\"SyncSend\" and l'=\"partition_label RM\" in affects_send)\n  apply (simp_all add:SACAuthGraph_def)\ndone\n\nlemma ntfn2_affects : \"subjectAffects SACAuthGraph (partition_label NTFN2) = {partition_label NTFN2, partition_label RM, partition_label EP} \\<union> RMControls\"\n  apply (rule subset_antisym)\n  defer\n  (* backward *)\n  apply (rule subsetI)\n  apply (erule UnE)\n  apply (erule insertE, simp only:, rule affects_lrefl)\n  apply (erule insertE, simp only:, rule ntfn2_affects_rm)\n  apply (erule insertE, simp only:, rule ntfn2_affects_ep)\n  apply simp\n  apply (rule ntfn2_affects_rm_controls, simp)\n  (* forward *)\n  apply (rule subsetI)\n  apply (erule subjectAffects.induct)\n  by (simp add:SACAuthGraph_def, blast?)+\n\nlemma ntfn3_affects_r : \"partition_label R \\<in> subjectAffects SACAuthGraph (partition_label NTFN3)\"\n  apply (rule_tac l'=\"partition_label R\" and ep=\"partition_label NTFN3\" and auth=\"Notify\" and l=\"partition_label NTFN3\" in affects_send)\n  apply (simp_all add:SACAuthGraph_def)\ndone\n\nlemma ntfn3_affects_bd : \"l \\<in> {NicB, NicD} \\<Longrightarrow> partition_label l \\<in> subjectAffects SACAuthGraph (partition_label NTFN3)\"\n  apply (rule_tac l'=\"partition_label R\" and ep=\"partition_label NTFN3\" and l=\"partition_label NTFN3\" and auth=\"Notify\" in affects_send)\n  apply (simp add:SACAuthGraph_def, blast?)+\ndone\n\nlemma ntfn3_affects : \"subjectAffects SACAuthGraph (partition_label NTFN3) = {partition_label NTFN3, partition_label R} \\<union> {partition_label NicB, partition_label NicD}\"\n  apply (rule subset_antisym)\n  defer\n  (* backward *)\n  apply (rule subsetI, erule UnE)\n  apply (erule insertE, simp only:, rule affects_lrefl)\n  apply (erule insertE, simp only:, rule ntfn3_affects_r, simp)\n  apply (auto simp:ntfn3_affects_bd)[1]\n  (* forward *)\n  apply (rule subsetI)\n  apply (erule subjectAffects.induct)\n  apply (simp add:SACAuthGraph_def, blast?)+\ndone\n\nsubsection \\<open>T\\<close>\n\nlemma t_reads : \"subjectReads SACAuthGraph (partition_label T) = {partition_label T}\"\n  apply (rule subset_antisym)\n  defer\n  apply (rule subsetI, erule insertE, simp only:, rule reads_lrefl, simp)\n  apply (rule subsetI, erule subjectReads.induct)\n  apply (simp add:SACAuthGraph_def, blast?)+\ndone\n\nlemma t_affects_ntfn123 : \"l \\<in> {NTFN1, NTFN2, NTFN3} \\<Longrightarrow>  partition_label l \\<in> subjectAffects SACAuthGraph (partition_label T)\"\n  apply (rule_tac auth=\"Notify\" in affects_ep)\n  apply (simp_all add:SACAuthGraph_def, blast)\ndone\n\nlemma t_affects_sc : \"partition_label SC \\<in> subjectAffects SACAuthGraph (partition_label T)\"\n  apply (rule_tac l''=\"partition_label SC\" and l'=\"partition_label SC\" and ep=\"partition_label NTFN1\" and auth=\"Notify\" and l=\"partition_label T\" in affects_send)\n  apply (simp_all add:SACAuthGraph_def)\ndone\n\nlemma t_affects_rm : \"partition_label RM \\<in> subjectAffects SACAuthGraph (partition_label T)\"\n  apply (rule_tac l''=\"partition_label RM\" and l'=\"partition_label RM\" and ep=\"partition_label NTFN2\" and auth=\"Notify\" and l=\"partition_label T\" in affects_send)\n  apply (simp_all add:SACAuthGraph_def)\ndone\n\nlemma t_affects_r : \"partition_label R \\<in> subjectAffects SACAuthGraph (partition_label T)\"\n  apply (rule_tac l''=\"partition_label R\" and l'=\"partition_label R\" and ep=\"partition_label NTFN3\" and auth=\"Notify\" and l=\"partition_label T\" in affects_send)\n  apply (simp_all add:SACAuthGraph_def)\ndone\n\nlemma t_affects_ep : \"partition_label EP \\<in> subjectAffects SACAuthGraph (partition_label T)\"\n  apply (rule affects_ep_bound_trans)\n  by (auto simp: SACAuthGraph_def)\n\nlemma t_affects_c : \"partition_label NicC \\<in> subjectAffects SACAuthGraph (partition_label T)\"\n  apply (rule_tac l''=\"partition_label NicC\" and l'=\"partition_label SC\" and ep=\"partition_label NTFN1\" and auth=\"Notify\" and l=\"partition_label T\" in affects_send)\n  apply (simp_all add:SACAuthGraph_def)\ndone\n\nlemma t_affects_a : \"partition_label NicA \\<in> subjectAffects SACAuthGraph (partition_label T)\"\n  apply (rule_tac l''=\"partition_label NicA\" and l'=\"partition_label RM\" and ep=\"partition_label NTFN2\" and auth=\"Notify\" and l=\"partition_label T\" in affects_send)\n  apply (simp_all add:SACAuthGraph_def)\ndone\n\nlemma t_affects_bd : \"l \\<in> {NicB, NicD} \\<Longrightarrow> partition_label l \\<in> subjectAffects SACAuthGraph (partition_label T)\"\n  apply (rule_tac l'=\"partition_label R\" and ep=\"partition_label NTFN3\" and auth=\"Notify\" and l=\"partition_label T\" in affects_send)\n  apply (simp_all add:SACAuthGraph_def, blast)\ndone\n\nlemma t_affects : \"subjectAffects SACAuthGraph (partition_label T) = {partition_label NTFN1, partition_label NTFN2, partition_label NTFN3} \\<union> {partition_label T, partition_label SC, partition_label RM, partition_label R, partition_label NicA, partition_label NicB, partition_label NicD, partition_label NicC, partition_label EP}\"\n  apply (rule subset_antisym)\n  defer\n  (* backward *)\n  apply (rule subsetI, erule UnE)\n  apply (auto simp:t_affects_ntfn123)[1]\n  apply (erule insertE, simp only:, rule affects_lrefl)\n  apply (erule insertE, simp only:, rule t_affects_sc)\n  apply (erule insertE, simp only:, rule t_affects_rm)\n  apply (erule insertE, simp only:, rule t_affects_r)\n  apply (erule insertE, simp only:, rule t_affects_a)\n  apply (erule insertE, simp only:, rule t_affects_bd, simp)\n  apply (erule insertE, simp only:, rule t_affects_bd, simp)\n  apply (erule insertE, simp only:, rule t_affects_c)\n  apply (erule insertE, simp only:, rule t_affects_ep)\n  apply simp\n  (* forward *)\n  apply (rule subsetI, erule subjectAffects.induct)\n  by (simp add:SACAuthGraph_def, blast?)+\n\nsubsection \\<open>Policy\\<close>\n\nlemmas SAC_reads = sc_reads ep_reads c_reads rm_reads r_reads abd_reads ntfn123_reads t_reads\n\nlemmas SAC_affects = sc_affects ep_affects c_affects rm_affects r_affects abd_affects ntfn1_affects ntfn2_affects ntfn3_affects t_affects\n\ndefinition SACFlowDoms where\n  \"SACFlowDoms \\<equiv> {Partition EP, Partition SC, Partition NicC, Partition RM, Partition R, Partition NicA, Partition NicB, Partition NicD, Partition NTFN1, Partition NTFN2, Partition NTFN3}\"\ndeclare SACFlowDoms_def [simp]\n\ndefinition SACPolicyFlows :: \"(SACLabels partition \\<times> SACLabels partition) set\" where\n  \"SACPolicyFlows \\<equiv>\n     {(PSched,d)| d. True}\n   \\<union> {(Partition l, Partition k)| l k. (k = T \\<longrightarrow> l = T)}\"\n\nlemma SAC_partsSubjectAffects_exceptT : \"x \\<noteq> T \\<Longrightarrow> partsSubjectAffects SACAuthGraph x = SACFlowDoms\"\n  apply (rule equalityI)\n  defer\n  apply (rule subsetI)\n    apply (simp add:partsSubjectAffects_def image_def label_can_affect_partition_def)\n    apply (case_tac x)\n     apply ((erule disjE, clarify, simp add:SAC_affects SAC_reads, blast?)+, simp add:SAC_affects SAC_reads, blast?)+\n  apply (rule subsetI)\n    apply (simp add:partsSubjectAffects_def image_def label_can_affect_partition_def)\n    apply (clarify)\n    apply (case_tac x)\n      apply (case_tac[!] xaa)\n        apply (auto simp: SAC_affects SAC_reads)\ndone\n\nlemma SAC_partsSubjectAffects_T : \"(partsSubjectAffects SACAuthGraph T) = {Partition NTFN1, Partition NTFN2, Partition NTFN3} \\<union> {Partition T, Partition SC, Partition RM, Partition R, Partition NicA, Partition NicB, Partition NicD, Partition NicC, Partition EP}\"\n    apply (rule equalityI)\n    apply (rule subsetI)\n    apply (simp add: partsSubjectAffects_def image_def label_can_affect_partition_def SAC_affects SAC_reads)\n    apply (clarify)\n    apply (case_tac xa, simp_all)[1]\n    apply (rule subsetI)\n    apply (simp add: partsSubjectAffects_def image_def label_can_affect_partition_def SAC_affects SAC_reads)\n    apply (erule disjE, simp add: SAC_reads) (* Do not collapse this in with a blast? because attempting blast takes too long *)\n    apply ((erule disjE)?, simp add: SAC_reads, blast)+\ndone\n\nlemma SAC_policyFlows : \"policyFlows SACAuthGraph = SACPolicyFlows\"\n  apply (rule subset_antisym)\n  (* forward *)\n  apply (rule subsetI)\n  apply clarify\n  apply (erule policyFlows.cases)\n    (* subject case *)\n    apply (clarsimp simp:SACPolicyFlows_def)\n    apply (case_tac \"d = Partition T\")\n      apply (case_tac l, auto simp:SAC_partsSubjectAffects_T SAC_partsSubjectAffects_exceptT)[1]\n      apply (case_tac l, auto simp:SAC_partsSubjectAffects_T SAC_partsSubjectAffects_exceptT)[1]\n    (* scheduler case *)\n    apply (simp add:SACPolicyFlows_def)\n  (* backward *)\n  apply (rule subsetI)\n  apply (clarsimp simp:SACPolicyFlows_def)\n  apply (erule disjE)\n    (* scheduler flows to all *)\n    apply (simp add:PSched_flows_to_all)\n    (* all subjects flow to all subjects *)\n    apply (clarify, simp)\n    apply (rule policy_affects)\n    apply (case_tac l, case_tac[1-12] k, auto simp:SAC_partsSubjectAffects_T SAC_partsSubjectAffects_exceptT)\ndone\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/proof/infoflow/PolicySystemSAC.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318479832805, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.29017637595003615}}
{"text": "theory AltCutEnv\n  imports PermEnvMisc LiftEnv AltNormEnv\nbegin\n\n  (* ##### cut-family lemmas *)  \n    \ndefinition cut_use_env where\n  \"cut_use_env r_s = (\\<lambda> x. if r_s x = UsePerm then NoPerm else r_s x)\"\n    \nlemma self_cut_leq_use_env: \"leq_use_env (cut_use_env r_s) r_s\"  \n  apply (simp add: leq_use_env_def)\n  apply (simp add: cut_use_env_def)\n  apply (auto)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n  done\n\nlemma cut_leq_use_env: \"\\<lbrakk> leq_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> leq_use_env (cut_use_env r_x) r_s\"      \n  apply (rule_tac r_sb=\"r_x\" in trans_leq_use_env)\n   apply (auto)\n  apply (rule_tac self_cut_leq_use_env)\n  done\n  \nlemma strong_cut_use_env: \"strong_use_env (cut_use_env r_s)\"\n  apply (simp add: strong_use_env_def)\n  apply (simp add: cut_use_env_def)\n  done\n  \nlemma mini_disj_strong_use_env: \"\\<lbrakk> leq_use_env r_x (diff_use_env r_s r_ex); strong_use_env r_ex \\<rbrakk> \\<Longrightarrow> mini_disj_use_env r_x r_ex\"  \n  apply (simp add: leq_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: strong_use_env_def)\n  apply (simp add: diff_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (case_tac \"r_ex x\")\n    apply (auto)\n  done\n  \nlemma diff_cut_leq_use_env: \"\\<lbrakk> leq_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> leq_use_env (diff_use_env r_x (cut_use_env r_ex)) (diff_use_env r_s r_ex)\"\n  apply (simp add: leq_use_env_def)\n  apply (simp add: cut_use_env_def)\n  apply (simp add: diff_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_ex x\")\n    apply (auto)\n  done      \n \nlemma dist_diff_leq_use_env_cut: \"\\<lbrakk> leq_use_env r_x r_s; leq_use_env (cut_use_env r_exb) r_exa \\<rbrakk> \\<Longrightarrow> leq_use_env (diff_use_env r_x r_exa) (diff_use_env r_s r_exb)\"\n  apply (simp add: leq_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (simp add: diff_use_env_def)\n  apply (simp add: cut_use_env_def)\n  apply (case_tac \"r_exa x\")\n    apply (auto)\n   apply (case_tac \"r_exb x\")\n     apply (auto)\n  apply (case_tac \"r_exb x\")\n    apply (auto)\n  done    \n    \nlemma lhs_diff_leq_use_env: \"\\<lbrakk> leq_use_env (diff_use_env r_x r_ex) r_s; leq_use_env (cut_use_env r_ex) r_s \\<rbrakk> \\<Longrightarrow> leq_use_env r_x r_s\"    \n  apply (simp add: leq_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (simp add: diff_use_env_def)\n  apply (simp add: cut_use_env_def)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n   apply (case_tac \"r_ex x\")\n     apply (auto)\n   apply (case_tac \"r_s x\")\n     apply (auto)\n  apply (case_tac \"r_ex x\")\n    apply (auto)   \n  done    \n    \nlemma lift_cut_leq_use_env: \"\\<lbrakk> is_own r; leq_use_env r_x (lift_use_env r_s r) \\<rbrakk> \\<Longrightarrow> leq_use_env r_x (cut_use_env (lift_use_env r_s r))\"    \n  apply (simp add: leq_use_env_def)\n  apply (simp add: cut_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n  apply (simp add: is_own_def)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n  done\n    \n    (* -- unsorted *)\n    \nlemma strong_lift_use_env: \"\\<lbrakk> is_own r \\<rbrakk> \\<Longrightarrow> strong_use_env (lift_use_env r_s r)\"    \n  apply (simp add: is_own_def)\n  apply (simp add: strong_use_env_def)\n  done    \n  \nend", "meta": {"author": "anon-ef", "repo": "perm_lang_ef2", "sha": "0fcb6e4c175193cc7b94f297a8aaa605f502d711", "save_path": "github-repos/isabelle/anon-ef-perm_lang_ef2", "path": "github-repos/isabelle/anon-ef-perm_lang_ef2/perm_lang_ef2-0fcb6e4c175193cc7b94f297a8aaa605f502d711/perm_ref/AltCutEnv.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318337259584, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.29017636909969685}}
{"text": "\\<^marker>\\<open>creator Andreas Vollert\\<close>\n\ntheory IMP_Minus_To_IMP_Minus_Minus_State_Translations_IMP\n  imports\n    Primitives_IMP_Minus\n    Binary_Arithmetic_IMP\n    IMP_Minus_To_IMP_Minus_Minus_State_Translations_nat\n    IMP_Minus.Com\nbegin\n\nunbundle IMP_Minus_Minus_Com.no_com_syntax\n\n\nsubsection \\<open>Useful Definitions and Lemmas\\<close>\n\nabbreviation \"hash_encode_char_as_nat \\<equiv> 35\"\nlemma hash_encode_char_val: \"encode_char (CHR ''#'') = hash_encode_char_as_nat\"\n  by (simp add: encode_char_def)\n\nabbreviation \"dollar_encode_char_as_nat \\<equiv> 36\"\nlemma dollar_encode_char_val: \"encode_char (CHR ''$'') = dollar_encode_char_as_nat\"\n  by (simp add: encode_char_def)\n\nabbreviation \"dollar_vname_encode_as_nat \\<equiv> 703\"\nlemma dollar_vname_encode_val: \"vname_encode ''$'' = dollar_vname_encode_as_nat\"\n  by (simp add: vname_encode_def encode_char_def prod_encode_def triangle_def)\n\nlemma hd_nat_noteq_zero: \"hd_nat n \\<noteq> 0 \\<Longrightarrow> n > 0\"\n  by (induction n)\n    (simp add: hd_nat_def fst_nat_def prod_decode_def prod_decode_aux.simps, simp)\n\nsubsection \\<open>dropWhile_char\\<close>\n\nsubsubsection \\<open>dropWhile_char_loop\\<close>\n\nrecord dropWhile_char_loop_state =\n  dropWhile_char_loop_n::nat\n  dropWhile_char_loop_ret::nat\n\nabbreviation \"dropWhile_char_loop_prefix \\<equiv> ''dropWhile_char_loop.''\"\nabbreviation \"dropWhile_char_loop_n_str \\<equiv> ''n''\"\nabbreviation \"dropWhile_char_loop_ret_str \\<equiv> ''ret''\"\n\nfunction dropWhile_char_loop:: \"nat \\<Rightarrow> nat\" where\n  \"dropWhile_char_loop n =\n (if hd_nat n = encode_char (CHR ''#'')\n          then dropWhile_char_loop (tl_nat n)\n          else n\n    )\"\n  by simp+\ntermination\n  by (relation \"measure id\", simp)\n    (simp add: hash_encode_char_val pos_tl_less hd_nat_noteq_zero)\n\ndefinition \"dropWhile_char_loop_state_upd s \\<equiv>\n      let\n        tl_xs' = dropWhile_char_loop_n s;\n        tl_ret' = 0;\n        tl_state = \\<lparr>tl_xs = tl_xs', tl_ret = tl_ret'\\<rparr>;\n        tl_ret_state = tl_imp tl_state;\n        dropWhile_char_loop_n' = tl_ret tl_ret_state;\n        dropWhile_char_loop_ret' = dropWhile_char_loop_ret s;\n        ret = \\<lparr>dropWhile_char_loop_n = dropWhile_char_loop_n',\n               dropWhile_char_loop_ret = dropWhile_char_loop_ret'\\<rparr>\n      in\n        ret\"\n\ndefinition \"dropWhile_char_loop_imp_compute_loop_condition s \\<equiv>\n  (let hd_xs' = dropWhile_char_loop_n s;\n       hd_ret' = 0;\n       hd_state = \\<lparr>hd_xs = hd_xs', hd_ret = hd_ret'\\<rparr>;\n       hd_ret_state = hd_imp hd_state;\n       EQUAL_neq_zero_a' = hd_ret hd_ret_state;\n       EQUAL_neq_zero_b' = hash_encode_char_as_nat;\n       EQUAL_neq_zero_ret' = 0;\n       EQUAL_neq_zero_state = \\<lparr>EQUAL_neq_zero_a = EQUAL_neq_zero_a',\n                               EQUAL_neq_zero_b = EQUAL_neq_zero_b',\n                               EQUAL_neq_zero_ret = EQUAL_neq_zero_ret'\\<rparr>;\n       EQUAL_neq_zero_ret_state = EQUAL_neq_zero_imp EQUAL_neq_zero_state;\n       condition = EQUAL_neq_zero_ret EQUAL_neq_zero_ret_state\n   in condition\n  )\"\n\ndefinition \"dropWhile_char_loop_imp_after_loop s \\<equiv>\n  (let\n    dropWhile_char_loop_n' = dropWhile_char_loop_n s;\n    dropWhile_char_loop_ret' = dropWhile_char_loop_n s;\n    ret = \\<lparr>dropWhile_char_loop_n = dropWhile_char_loop_n',\n           dropWhile_char_loop_ret = dropWhile_char_loop_ret'\\<rparr>\n   in ret\n  )\"\n\nlemmas dropWhile_char_loop_imp_subprogram_simps =\n  dropWhile_char_loop_imp_after_loop_def\n  dropWhile_char_loop_state_upd_def\n  dropWhile_char_loop_imp_compute_loop_condition_def\n\nfunction dropWhile_char_loop_imp:: \"dropWhile_char_loop_state \\<Rightarrow> dropWhile_char_loop_state\" where\n  \"dropWhile_char_loop_imp s =\n  (if dropWhile_char_loop_imp_compute_loop_condition s \\<noteq> 0\n         then (let next_iteration = dropWhile_char_loop_imp (dropWhile_char_loop_state_upd s)\n               in next_iteration)\n         else (let ret = dropWhile_char_loop_imp_after_loop s in ret))\"\n  by simp+\ntermination\n  by (relation \"measure dropWhile_char_loop_n\", simp)\n    (simp add: dropWhile_char_loop_imp_subprogram_simps tl_imp_correct EQUAL_neq_zero_imp_correct\n      hd_imp_correct split:if_splits, simp only: hd_nat_noteq_zero pos_tl_less)\n\ndeclare dropWhile_char_loop_imp.simps [simp del]\n\nlemma dropWhile_char_loop_imp_correct[let_function_correctness]:\n  \"dropWhile_char_loop_ret (dropWhile_char_loop_imp s) =\n    dropWhile_char_loop (dropWhile_char_loop_n s)\"\n  by (induction \"dropWhile_char_loop_n s\" arbitrary: s rule: dropWhile_char_loop.induct)\n    (subst dropWhile_char_loop_imp.simps, simp add: dropWhile_char_loop_imp_subprogram_simps\n      tl_imp_correct hd_imp_correct EQUAL_neq_zero_imp_correct hash_encode_char_val)\n\ndefinition \"dropWhile_char_loop_state_upd_time t s \\<equiv>\n      let\n        tl_xs' = dropWhile_char_loop_n s;\n        t = t + 2;\n        tl_ret' = 0;\n        t = t + 2;\n        tl_state = \\<lparr>tl_xs = tl_xs', tl_ret = tl_ret'\\<rparr>;\n        tl_ret_state = tl_imp tl_state;\n        t = t + tl_imp_time 0 tl_state;\n        dropWhile_char_loop_n' = tl_ret tl_ret_state;\n        t = t + 2;\n        dropWhile_char_loop_ret' = dropWhile_char_loop_ret s;\n        t = t + 2;\n        ret = t\n      in\n        ret\"\n\ndefinition \"dropWhile_char_loop_imp_compute_loop_condition_time t s \\<equiv>\n  (let hd_xs' = dropWhile_char_loop_n s;\n       t = t + 2;\n       hd_ret' = 0;\n       t = t + 2;\n       hd_state = \\<lparr>hd_xs = hd_xs', hd_ret = hd_ret'\\<rparr>;\n       hd_ret_state = hd_imp hd_state;\n       t = t + hd_imp_time 0 hd_state;\n       EQUAL_neq_zero_a' = hd_ret hd_ret_state;\n       t = t + 2;\n       EQUAL_neq_zero_b' = hash_encode_char_as_nat;\n       t = t + 2;\n       EQUAL_neq_zero_ret' = 0;\n       t = t + 2;\n       EQUAL_neq_zero_state = \\<lparr>EQUAL_neq_zero_a = EQUAL_neq_zero_a',\n                               EQUAL_neq_zero_b = EQUAL_neq_zero_b',\n                               EQUAL_neq_zero_ret = EQUAL_neq_zero_ret'\\<rparr>;\n       EQUAL_neq_zero_ret_state = EQUAL_neq_zero_imp EQUAL_neq_zero_state;\n       t = t + EQUAL_neq_zero_imp_time 0 EQUAL_neq_zero_state;\n       condition = EQUAL_neq_zero_ret EQUAL_neq_zero_ret_state;\n       t = t + 2;\n       ret = t\n   in ret\n  )\"\n\ndefinition \"dropWhile_char_loop_imp_after_loop_time (t::nat) (s::dropWhile_char_loop_state) \\<equiv>\n  (let\n    dropWhile_char_n' = dropWhile_char_loop_n s;\n    t = t + 2;\n    dropWhile_char_ret' = dropWhile_char_loop_n s;\n    t = t + 2;\n    ret = t\n   in ret\n  )\"\n\nlemmas dropWhile_char_loop_imp_subprogram_simps_time =\n  dropWhile_char_loop_imp_after_loop_time_def\n  dropWhile_char_loop_state_upd_time_def\n  dropWhile_char_loop_imp_compute_loop_condition_time_def\n\nfunction dropWhile_char_loop_imp_time:: \"nat \\<Rightarrow> dropWhile_char_loop_state \\<Rightarrow> nat\" where\n  \"dropWhile_char_loop_imp_time t s =\n   dropWhile_char_loop_imp_compute_loop_condition_time 0 s +\n  (if dropWhile_char_loop_imp_compute_loop_condition s \\<noteq> 0\n   then\n    (let\n        t = t + 1;\n        next_iteration\n          = dropWhile_char_loop_imp_time (t + dropWhile_char_loop_state_upd_time 0 s)\n                                         (dropWhile_char_loop_state_upd s)\n     in next_iteration)\n  else\n    (let\n        t = t + 2;\n        ret = t + dropWhile_char_loop_imp_after_loop_time 0 s\n     in ret)\n  )\"\n  by auto\ntermination\n  apply (relation \"measure (dropWhile_char_loop_n \\<circ> snd)\", simp)\n  apply (subst dropWhile_char_loop_state_upd_def)\n  apply (simp add: dropWhile_char_loop_imp_compute_loop_condition_def tl_imp_correct\n      EQUAL_neq_zero_imp_correct hd_imp_correct split: if_splits)\n  by (simp only: pos_tl_less hd_nat_noteq_zero)\n\ndeclare dropWhile_char_loop_imp_time.simps [simp del]\n\nlemmas dropWhile_char_loop_imp_subprogram_time_simps =\n  dropWhile_char_loop_imp_subprogram_simps\n  dropWhile_char_loop_imp_after_loop_time_def\n  dropWhile_char_loop_state_upd_time_def\n  dropWhile_char_loop_imp_compute_loop_condition_time_def\n\nlemma dropWhile_char_loop_imp_time_acc:\n  \"(dropWhile_char_loop_imp_time (Suc t) s) = Suc (dropWhile_char_loop_imp_time t s)\"\n  by (induction t s rule: dropWhile_char_loop_imp_time.induct)\n    ((subst (1 2) dropWhile_char_loop_imp_time.simps);\n      (simp add: dropWhile_char_loop_state_upd_def))\n\nlemma dropWhile_char_loop_imp_time_acc_2_aux:\n  \"(dropWhile_char_loop_imp_time t s) =\n    t + (dropWhile_char_loop_imp_time 0 s)\"\n  by (induction t arbitrary: s)\n    (simp add: dropWhile_char_loop_imp_time_acc)+\n\nlemma dropWhile_char_loop_imp_time_acc_2:\n  \"t \\<noteq> 0 \\<Longrightarrow> (dropWhile_char_loop_imp_time t s) =\n    t + (dropWhile_char_loop_imp_time 0 s)\"\n  by (rule dropWhile_char_loop_imp_time_acc_2_aux)\n\nlemma dropWhile_char_loop_imp_time_acc_3:\n  \"(dropWhile_char_loop_imp_time (a + b) s) =\n    a + (dropWhile_char_loop_imp_time b s)\"\n  by (induction a arbitrary: b s)\n    (simp add: dropWhile_char_loop_imp_time_acc)+\n\nabbreviation \"dropWhile_char_loop_while_cond \\<equiv> ''condition''\"\n\ndefinition \"dropWhile_char_loop_IMP_init_while_cond \\<equiv>\n  (hd_prefix @ hd_xs_str) ::= (A (V dropWhile_char_loop_n_str));;\n  \\<comment> \\<open>(hd_ret' = 0;\\<close>\n  (hd_prefix @ hd_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>(hd_state = \\<lparr>hd_xs = hd_xs', hd_ret = hd_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>(hd_ret_state = hd_imp hd_state;\\<close>\n  invoke_subprogram hd_prefix hd_IMP_Minus;;\n  \\<comment> \\<open>(EQUAL_neq_zero_a' = hd_ret hd_ret_state;\\<close>\n  (EQUAL_neq_zero_prefix @ EQUAL_neq_zero_a_str) ::= (A (V (hd_prefix @ hd_ret_str)));;\n  \\<comment> \\<open>(EQUAL_neq_zero_b' = hash_encode_char_as_nat;\\<close>\n  (EQUAL_neq_zero_prefix @ EQUAL_neq_zero_b_str) ::= (A (N hash_encode_char_as_nat));;\n  \\<comment> \\<open>(EQUAL_neq_zero_ret' = 0;\\<close>\n  (EQUAL_neq_zero_prefix @ EQUAL_neq_zero_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>(EQUAL_neq_zero_state = \\<lparr>EQUAL_neq_zero_a = EQUAL_neq_zero_a',\\<close>\n  \\<comment> \\<open>(                       EQUAL_neq_zero_b = EQUAL_neq_zero_b',\\<close>\n  \\<comment> \\<open>(                       EQUAL_neq_zero_ret = EQUAL_neq_zero_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>(EQUAL_neq_zero_ret_state = EQUAL_neq_zero_imp EQUAL_neq_zero_state;\\<close>\n  invoke_subprogram EQUAL_neq_zero_prefix EQUAL_neq_zero_IMP_Minus;;\n  dropWhile_char_loop_while_cond ::= (A (V (EQUAL_neq_zero_prefix @ EQUAL_neq_zero_ret_str)))\n  \"\n\ndefinition \"dropWhile_char_loop_IMP_loop_body \\<equiv>\n  \\<comment> \\<open>tl_xs' = dropWhile_char_loop_n s;\\<close>\n  (tl_prefix @ tl_xs_str) ::= (A (V dropWhile_char_loop_n_str));;\n  \\<comment> \\<open>tl_ret' = 0;\\<close>\n  (tl_prefix @ tl_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>tl_state = \\<lparr>tl_xs = tl_xs', tl_ret = tl_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>tl_ret_state = tl_imp tl_state;\\<close>\n  invoke_subprogram tl_prefix tl_IMP_Minus;;\n  \\<comment> \\<open>dropWhile_char_loop_n' = tl_ret tl_ret_state;\\<close>\n  dropWhile_char_loop_n_str ::= (A (V (tl_prefix @ tl_ret_str)));;\n  \\<comment> \\<open>dropWhile_char_loop_ret' = dropWhile_char_ret s;\\<close>\n  dropWhile_char_loop_ret_str ::= (A (V dropWhile_char_loop_ret_str))\n  \"\n\ndefinition \"dropWhile_char_loop_IMP_after_loop \\<equiv>\n  \\<comment> \\<open>  dropWhile_char_loop_n' = dropWhile_char_loop_n s;\\<close>\n  dropWhile_char_loop_n_str ::= (A (V dropWhile_char_loop_n_str));;\n  \\<comment> \\<open>  dropWhile_char_loop_ret' = dropWhile_char_loop_n s;\\<close>\n  dropWhile_char_loop_ret_str ::= (A (V dropWhile_char_loop_n_str))\n  \"\n\ndefinition dropWhile_char_loop_IMP_Minus where\n  \"dropWhile_char_loop_IMP_Minus \\<equiv>\n  dropWhile_char_loop_IMP_init_while_cond;;\n  WHILE dropWhile_char_loop_while_cond \\<noteq>0 DO (\n    dropWhile_char_loop_IMP_loop_body;;\n    dropWhile_char_loop_IMP_init_while_cond\n  );;\n  dropWhile_char_loop_IMP_after_loop\"\n\nabbreviation\n  \"dropWhile_char_loop_IMP_vars \\<equiv>\n  {dropWhile_char_loop_n_str, dropWhile_char_loop_ret_str}\"\n\nlemmas dropWhile_char_loop_IMP_subprogram_simps =\n  dropWhile_char_loop_IMP_init_while_cond_def\n  dropWhile_char_loop_IMP_loop_body_def\n  dropWhile_char_loop_IMP_after_loop_def\n\ndefinition \"dropWhile_char_loop_imp_to_HOL_state p s =\n  \\<lparr>dropWhile_char_loop_n = (s (add_prefix p dropWhile_char_loop_n_str)),\n   dropWhile_char_loop_ret = (s (add_prefix p dropWhile_char_loop_ret_str))\\<rparr>\"\n\nlemmas dropWhile_char_loop_state_translators =\n  hd_imp_to_HOL_state_def\n  tl_imp_to_HOL_state_def\n  dropWhile_char_loop_imp_to_HOL_state_def\n  AND_neq_zero_imp_to_HOL_state_def\n  EQUAL_neq_zero_imp_to_HOL_state_def\n  NOTEQUAL_neq_zero_imp_to_HOL_state_def\n\nlemmas dropWhile_char_loop_complete_simps =\n  dropWhile_char_loop_IMP_subprogram_simps\n  dropWhile_char_loop_imp_subprogram_simps\n  dropWhile_char_loop_state_translators\n\nlemmas dropWhile_char_loop_complete_time_simps =\n  dropWhile_char_loop_imp_subprogram_time_simps\n  dropWhile_char_loop_imp_time_acc_2\n  dropWhile_char_loop_imp_time_acc_3\n  dropWhile_char_loop_state_translators\n\nlemma dropWhile_char_loop_IMP_Minus_correct_function:\n  \"(invoke_subprogram p dropWhile_char_loop_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p dropWhile_char_loop_ret_str) =\n       dropWhile_char_loop_ret (dropWhile_char_loop_imp (dropWhile_char_loop_imp_to_HOL_state p s))\"\n  apply(induction \"dropWhile_char_loop_imp_to_HOL_state p s\" arbitrary: s s' t\n      rule: dropWhile_char_loop_imp.induct)\n  apply(subst dropWhile_char_loop_imp.simps)\n  apply(simp only: dropWhile_char_loop_IMP_Minus_def prefix_simps)\n\n  apply(erule Seq_E)+\n  apply(erule While_tE)\n  subgoal\n    apply(simp only: dropWhile_char_loop_IMP_init_while_cond_def prefix_simps)\n    apply(erule Seq_E)+\n    apply(erule hd_IMP_Minus_correct[where vars = \"dropWhile_char_loop_IMP_vars\"])\n    subgoal premises p using p(13) by fastforce\n    apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"dropWhile_char_loop_IMP_vars\"])\n    subgoal premises p using p(15) by fastforce\n    by(force simp: dropWhile_char_loop_complete_simps Let_def)\n\n  apply(erule Seq_E)+\n  apply(dest_com_gen)\n\n  subgoal\n    apply(simp only: dropWhile_char_loop_IMP_init_while_cond_def prefix_simps)\n    apply(erule Seq_E)+\n    apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"dropWhile_char_loop_IMP_vars\"])\n    subgoal premises p using p(20) by fastforce\n    apply(erule hd_IMP_Minus_correct[where vars = \"dropWhile_char_loop_IMP_vars\"])\n    subgoal premises p using p(22) by fastforce\n    by(fastforce_sorted_premises simp: dropWhile_char_loop_complete_simps Let_def)\n\n  subgoal\n\n    apply(simp only: dropWhile_char_loop_IMP_init_while_cond_def prefix_simps\n        dropWhile_char_loop_IMP_loop_body_def)\n    apply(erule Seq_E)+\n    apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"dropWhile_char_loop_IMP_vars\"])\n    subgoal premises p using p(24) by fastforce\n    apply(erule hd_IMP_Minus_correct[where vars = \"dropWhile_char_loop_IMP_vars\"])\n    subgoal premises p using p(26) by fastforce\n    apply(erule tl_IMP_Minus_correct[where vars = \"dropWhile_char_loop_IMP_vars\"])\n    subgoal premises p using p(28) by fastforce\n    by(fastforce_sorted_premises simp: dropWhile_char_loop_complete_simps Let_def)\n\n  subgoal\n    apply(simp only: dropWhile_char_loop_IMP_init_while_cond_def prefix_simps\n        dropWhile_char_loop_IMP_loop_body_def)\n    apply(erule Seq_E)+\n    apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"dropWhile_char_loop_IMP_vars\"])\n    subgoal premises p using p(24) by fastforce\n    apply(erule hd_IMP_Minus_correct[where vars = \"dropWhile_char_loop_IMP_vars\"])\n    subgoal premises p using p(26) by fastforce\n    apply(erule tl_IMP_Minus_correct[where vars = \"dropWhile_char_loop_IMP_vars\"])\n    subgoal premises p using p(28) by fastforce\n    by(fastforce_sorted_premises simp: dropWhile_char_loop_complete_simps Let_def)\n\n  done\n\nlemma dropWhile_char_loop_IMP_Minus_correct_effects:\n  \"\\<lbrakk>(invoke_subprogram (p @ dropWhile_char_loop_pref) dropWhile_char_loop_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    v \\<in> vars; \\<not> (prefix dropWhile_char_loop_pref v)\\<rbrakk>\n  \\<Longrightarrow> s (add_prefix p v) = s' (add_prefix p v)\"\n  using com_add_prefix_valid'' com_only_vars prefix_def\n  by blast\n\nlemma dropWhile_char_loop_IMP_Minus_correct_time_loop_condition:\n  \"(invoke_subprogram p dropWhile_char_loop_IMP_init_while_cond, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = dropWhile_char_loop_imp_compute_loop_condition_time\n          0 (dropWhile_char_loop_imp_to_HOL_state p s)\"\n  by (fastforce elim: EQUAL_neq_zero_IMP_Minus_correct hd_IMP_Minus_correct simp: Let_def\n      dropWhile_char_loop_imp_compute_loop_condition_time_def invoke_subprogram_append\n      dropWhile_char_loop_IMP_init_while_cond_def EQUAL_neq_zero_IMP_Minus_correct_time\n      dropWhile_char_loop_imp_subprogram_simps dropWhile_char_loop_imp_time_acc\n      dropWhile_char_loop_state_translators)\n\nlemma dropWhile_char_loop_IMP_Minus_correct_time:\n  \"(invoke_subprogram p dropWhile_char_loop_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = dropWhile_char_loop_imp_time 0 (dropWhile_char_loop_imp_to_HOL_state p s)\"\n  apply(induction \"dropWhile_char_loop_imp_to_HOL_state p s\" arbitrary: s s' t\n      rule: dropWhile_char_loop_imp.induct)\n  apply(subst dropWhile_char_loop_imp_time.simps)\n  apply(simp only: dropWhile_char_loop_IMP_Minus_def prefix_simps)\n\n  apply(erule Seq_tE)+\n  apply(erule While_tE_time)\n  subgoal\n    apply(simp only: dropWhile_char_loop_IMP_subprogram_simps prefix_simps)\n    apply(erule Seq_tE)+\n    apply(erule hd_IMP_Minus_correct[where vars = \"dropWhile_char_loop_IMP_vars\"])\n    subgoal premises p using p(24) by fastforce\n    apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"dropWhile_char_loop_IMP_vars\"])\n    subgoal premises p using p(26) by fastforce\n    by (force simp: dropWhile_char_loop_imp_subprogram_time_simps Let_def\n        dropWhile_char_loop_state_translators)\n\n  apply(erule Seq_tE)+\n  apply(simp add: add.assoc)\n  apply(dest_com_gen_time)\n\n  subgoal\n    apply(simp only: dropWhile_char_loop_IMP_init_while_cond_def prefix_simps)\n    apply(erule Seq_tE)+\n    apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"dropWhile_char_loop_IMP_vars\"])\n    subgoal premises p using p(37) by fastforce\n    apply(erule hd_IMP_Minus_correct[where vars = \"dropWhile_char_loop_IMP_vars\"])\n    subgoal premises p using p(39) by fastforce\n    by (fastforce_sorted_premises simp: dropWhile_char_loop_complete_simps Let_def)\n\n  subgoal\n\n    apply(simp only: dropWhile_char_loop_IMP_init_while_cond_def prefix_simps\n        dropWhile_char_loop_IMP_loop_body_def)\n    apply(erule Seq_tE)+\n    apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"dropWhile_char_loop_IMP_vars\"])\n    subgoal premises p using p(45) by fastforce\n    apply(erule hd_IMP_Minus_correct[where vars = \"dropWhile_char_loop_IMP_vars\"])\n    subgoal premises p using p(47) by fastforce\n    apply(erule tl_IMP_Minus_correct[where vars = \"dropWhile_char_loop_IMP_vars\"])\n    subgoal premises p using p(49) by fastforce\n    by (fastforce_sorted_premises simp: Let_def dropWhile_char_loop_complete_time_simps)\n\n  subgoal\n    apply(simp only: dropWhile_char_loop_IMP_init_while_cond_def prefix_simps\n        dropWhile_char_loop_IMP_loop_body_def)\n    apply(erule Seq_tE)+\n    apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"dropWhile_char_loop_IMP_vars\"])\n    subgoal premises p using p(45) by fastforce\n    apply(erule hd_IMP_Minus_correct[where vars = \"dropWhile_char_loop_IMP_vars\"])\n    subgoal premises p using p(47) by fastforce\n    apply(erule tl_IMP_Minus_correct[where vars = \"dropWhile_char_loop_IMP_vars\"])\n    subgoal premises p using p(49) by fastforce\n    by (fastforce_sorted_premises simp: dropWhile_char_loop_complete_time_simps Let_def)\n\n  done\n\nlemma dropWhile_char_loop_IMP_Minus_correct:\n  \"\\<lbrakk>(invoke_subprogram (p1 @ p2) dropWhile_char_loop_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    \\<And>v. v \\<in> vars \\<Longrightarrow> \\<not> (set p2 \\<subseteq> set v);\n    \\<lbrakk>t = (dropWhile_char_loop_imp_time 0 (dropWhile_char_loop_imp_to_HOL_state (p1 @ p2) s));\n     s' (add_prefix (p1 @ p2) dropWhile_char_loop_ret_str) =\n      dropWhile_char_loop_ret (dropWhile_char_loop_imp\n                                (dropWhile_char_loop_imp_to_HOL_state (p1 @ p2) s));\n     \\<And>v. v \\<in> vars \\<Longrightarrow> s (add_prefix p1 v) = s' (add_prefix p1 v)\\<rbrakk> \\<Longrightarrow> P\\<rbrakk>\n  \\<Longrightarrow> P\"\n  using dropWhile_char_loop_IMP_Minus_correct_function\n  by (auto simp: dropWhile_char_loop_IMP_Minus_correct_time)\n    (meson dropWhile_char_loop_IMP_Minus_correct_effects set_mono_prefix)\n\n\nsubsubsection \\<open>dropWhile_char\\<close>\n\nrecord dropWhile_char_state =\n  dropWhile_char_n::nat\n  dropWhile_char_ret::nat\n\nabbreviation \"dropWhile_char_prefix \\<equiv> ''dropWhile_char_loop.''\"\nabbreviation \"dropWhile_char_n_str \\<equiv> ''n''\"\nabbreviation \"dropWhile_char_ret_str \\<equiv> ''ret''\"\n\nfun dropWhile_char':: \"nat \\<Rightarrow> nat\" where\n  \"dropWhile_char' n =\n  (if n \\<noteq> 0\n   then dropWhile_char_loop n\n   else n)\"\n\nlemma dropWhile_char'_correct: \"dropWhile_char n = dropWhile_char' n\"\n  by (induction n rule: dropWhile_char.induct)\n    (simp add: fst_nat_0 hash_encode_char_val hd_nat_def split: if_splits)\n\ndefinition \"dropWhile_char_state_upd s \\<equiv>\n      let\n        dropWhile_char_loop_n' = dropWhile_char_n s;\n        dropWhile_char_loop_ret' = 0;\n        dropWhile_char_loop_state = \\<lparr>dropWhile_char_loop_n = dropWhile_char_loop_n',\n                                     dropWhile_char_loop_ret = dropWhile_char_loop_ret'\\<rparr>;\n        dropWhile_char_loop_ret_state = dropWhile_char_loop_imp dropWhile_char_loop_state;\n        dropWhile_char_n' = dropWhile_char_n s;\n        dropWhile_char_ret' = dropWhile_char_loop_ret dropWhile_char_loop_ret_state;\n        ret = \\<lparr>dropWhile_char_n = dropWhile_char_n',\n               dropWhile_char_ret = dropWhile_char_ret'\\<rparr>\n      in\n        ret\"\n\nfun dropWhile_char_imp:: \"dropWhile_char_state \\<Rightarrow> dropWhile_char_state\" where\n  \"dropWhile_char_imp s =\n  (if dropWhile_char_n s \\<noteq> 0\n   then dropWhile_char_state_upd s\n   else \\<lparr>dropWhile_char_n = dropWhile_char_n s,\n        dropWhile_char_ret = dropWhile_char_n s\\<rparr>)\"\n\ndeclare dropWhile_char_imp.simps [simp del]\n\nlemma dropWhile_char_imp_correct[let_function_correctness]:\n  \"dropWhile_char_ret (dropWhile_char_imp s) = dropWhile_char' (dropWhile_char_n s)\"\n  by(simp add: dropWhile_char_imp.simps dropWhile_char_state_upd_def Let_def\n      dropWhile_char_loop_imp_correct)\n\nlemmas dropWhile_char_imp_subprogram_simps = dropWhile_char_state_upd_def\n\ndefinition \"dropWhile_char_state_upd_time t s \\<equiv>\n      let\n        dropWhile_char_loop_n' = dropWhile_char_n s;\n        t = t + 2;\n        dropWhile_char_loop_ret' = 0;\n        t = t + 2;\n        dropWhile_char_loop_state = \\<lparr>dropWhile_char_loop_n = dropWhile_char_loop_n',\n                                     dropWhile_char_loop_ret = dropWhile_char_loop_ret'\\<rparr>;\n        dropWhile_char_loop_ret_state = dropWhile_char_loop_imp dropWhile_char_loop_state;\n        t = t + dropWhile_char_loop_imp_time 0 dropWhile_char_loop_state;\n        dropWhile_char_n' = dropWhile_char_n s;\n        t = t + 2;\n        dropWhile_char_ret' = dropWhile_char_loop_ret dropWhile_char_loop_ret_state;\n        t = t + 2;\n        ret = t\n      in\n        ret\"\n\nfun dropWhile_char_imp_time:: \"nat \\<Rightarrow> dropWhile_char_state \\<Rightarrow> nat\" where\n  \"dropWhile_char_imp_time t s =\n  (if dropWhile_char_n s \\<noteq> 0\n   then (let t = t + 1;\n             next = dropWhile_char_state_upd s;\n             t = t + dropWhile_char_state_upd_time 0 s;\n             ret = t\n         in ret)\n   else (let t = t + 1;\n             dropWhile_char_n' = dropWhile_char_n s;\n             t = t + 2;\n             dropWhile_char_ret' = dropWhile_char_n s;\n             t = t + 2;\n             ret = t\n         in ret))\"\n\ndeclare dropWhile_char_imp_time.simps [simp del]\n\nlemmas dropWhile_char_imp_subprogram_simps_time = dropWhile_char_state_upd_time_def\n\nlemma dropWhile_char_imp_time_acc:\n  \"(dropWhile_char_imp_time (Suc t) s) = Suc (dropWhile_char_imp_time t s)\"\n  by (induction t s rule: dropWhile_char_imp_time.induct)\n    (simp add: dropWhile_char_imp_time.simps)\n\nlemma dropWhile_char_imp_time_acc_2:\n  \"(dropWhile_char_imp_time x s) = x + (dropWhile_char_imp_time 0 s)\"\n  by (induction x arbitrary: s) (simp add: dropWhile_char_imp_time_acc)+\n\nlemma dropWhile_char_imp_time_acc_2_simp:\n  \"(dropWhile_char_imp_time (dropWhile_char_state_upd_time 0 s) s') =\n   (dropWhile_char_state_upd_time 0 s) + (dropWhile_char_imp_time 0 s')\"\n  by (rule dropWhile_char_imp_time_acc_2)\n\nlemmas dropWhile_char_complete_time_simps =\n  dropWhile_char_imp_subprogram_simps\n  dropWhile_char_state_upd_time_def\n  dropWhile_char_imp_time_acc\n  dropWhile_char_imp_time_acc_2_simp\n\ndefinition dropWhile_char_IMP_Minus where\n  \"dropWhile_char_IMP_Minus \\<equiv>\n  IF dropWhile_char_n_str \\<noteq>0\n  THEN (\n    (dropWhile_char_loop_prefix @ dropWhile_char_loop_n_str) ::= (A (V dropWhile_char_n_str));;\n    (dropWhile_char_loop_prefix @ dropWhile_char_loop_ret_str) ::= (A (N 0));;\n    invoke_subprogram dropWhile_char_loop_prefix dropWhile_char_loop_IMP_Minus;;\n    dropWhile_char_n_str ::= (A (V dropWhile_char_n_str));;\n    dropWhile_char_ret_str ::= (A (V (dropWhile_char_loop_prefix @ dropWhile_char_loop_ret_str)))\n  )\n  ELSE (\n    dropWhile_char_n_str ::= (A (V dropWhile_char_n_str));;\n    dropWhile_char_ret_str ::= (A (V dropWhile_char_n_str))\n  )\"\n\nabbreviation\n  \"dropWhile_char_IMP_vars \\<equiv>\n  {dropWhile_char_n_str, dropWhile_char_ret_str}\"\n\ndefinition \"dropWhile_char_imp_to_HOL_state p s =\n  \\<lparr>dropWhile_char_n = (s (add_prefix p dropWhile_char_n_str)),\n   dropWhile_char_ret = (s (add_prefix p dropWhile_char_ret_str))\\<rparr>\"\n\nlemmas dropWhile_char_state_translators =\n  dropWhile_char_imp_to_HOL_state_def\n  dropWhile_char_loop_imp_to_HOL_state_def\n\nlemmas dropWhile_char_complete_simps =\n  dropWhile_char_imp_subprogram_simps\n  dropWhile_char_state_translators\n\nlemma dropWhile_char_IMP_Minus_correct_function:\n  \"(invoke_subprogram p dropWhile_char_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p dropWhile_char_ret_str) =\n       dropWhile_char_ret (dropWhile_char_imp (dropWhile_char_imp_to_HOL_state p s))\"\n  by (fastforce elim: dropWhile_char_loop_IMP_Minus_correct simp: dropWhile_char_IMP_Minus_def\n      dropWhile_char_complete_simps invoke_subprogram_append dropWhile_char_imp.simps)\n\nlemma dropWhile_char_IMP_Minus_correct_effects:\n  \"\\<lbrakk>(invoke_subprogram (p @ dropWhile_char_pref) dropWhile_char_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    v \\<in> vars; \\<not> (prefix dropWhile_char_pref v)\\<rbrakk>\n  \\<Longrightarrow> s (add_prefix p v) = s' (add_prefix p v)\"\n  using com_add_prefix_valid'' com_only_vars prefix_def\n  by blast\n\nlemma dropWhile_char_IMP_Minus_correct_time:\n  \"(invoke_subprogram p dropWhile_char_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = dropWhile_char_imp_time 0 (dropWhile_char_imp_to_HOL_state p s)\"\n  by (fastforce elim: dropWhile_char_loop_IMP_Minus_correct simp: dropWhile_char_imp_time.simps\n      dropWhile_char_IMP_Minus_def invoke_subprogram_append dropWhile_char_complete_time_simps\n      dropWhile_char_state_translators Let_def)\n\nlemma dropWhile_char_IMP_Minus_correct:\n  \"\\<lbrakk>(invoke_subprogram (p1 @ p2) dropWhile_char_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    \\<And>v. v \\<in> vars \\<Longrightarrow> \\<not> (set p2 \\<subseteq> set v);\n     \\<lbrakk>t = (dropWhile_char_imp_time 0 (dropWhile_char_imp_to_HOL_state (p1 @ p2) s));\n      s' (add_prefix (p1 @ p2) dropWhile_char_ret_str) =\n        dropWhile_char_ret (dropWhile_char_imp (dropWhile_char_imp_to_HOL_state (p1 @ p2) s));\n      \\<And>v. v \\<in> vars \\<Longrightarrow> s (add_prefix p1 v) = s' (add_prefix p1 v)\\<rbrakk>\n     \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  using dropWhile_char_IMP_Minus_correct_function\n  by (auto simp: dropWhile_char_IMP_Minus_correct_time)\n    (meson dropWhile_char_IMP_Minus_correct_effects set_mono_prefix)\n\n\nsubsection \\<open>takeWhile_char\\<close>\n\nsubsubsection \\<open>takeWhile_char_acc\\<close>\n\nfun takeWhile_char_acc' :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat\" where\n  \"takeWhile_char_acc' acc n =\n    (if n \\<noteq> 0 \\<and> hd_nat n = encode_char (CHR ''#'')\n     then takeWhile_char_acc ((hd_nat n) ## acc) (tl_nat n)\n     else acc\n    )\"\n\nlemma takeWhile_char_acc'_correct: \n  \"takeWhile_char_acc acc n = takeWhile_char_acc' acc n\"\n  by (induction acc n rule: takeWhile_char_acc.induct) simp\n\nrecord takeWhile_char_acc_state =\n  takeWhile_char_acc_acc::nat\n  takeWhile_char_acc_n::nat\n  takeWhile_char_acc_ret::nat\n\nabbreviation \"takeWhile_char_acc_prefix \\<equiv> ''takeWhile_char_acc.''\"\nabbreviation \"takeWhile_char_acc_acc_str \\<equiv> ''acc''\"\nabbreviation \"takeWhile_char_acc_n_str \\<equiv> ''n''\"\nabbreviation \"takeWhile_char_acc_ret_str \\<equiv> ''ret''\"\n\ndefinition \"takeWhile_char_acc_state_upd s \\<equiv>\n  (let\n      hd_xs' = takeWhile_char_acc_n s;\n      hd_ret' = 0;\n      hd_state = \\<lparr>hd_xs = hd_xs',\n                  hd_ret = hd_ret'\\<rparr>;\n      hd_ret_state = hd_imp hd_state;\n      cons_h' = hd_ret hd_ret_state;\n      cons_t' = takeWhile_char_acc_acc s;\n      cons_ret' = 0;\n      cons_state = \\<lparr>cons_h = cons_h',\n                    cons_t = cons_t',\n                    cons_ret = cons_ret'\\<rparr>;\n      cons_ret_state = cons_imp cons_state;\n      takeWhile_char_acc_acc' = cons_ret cons_ret_state;\n      tl_xs' = takeWhile_char_acc_n s;\n      tl_ret' = 0;\n      tl_state = \\<lparr>tl_xs = tl_xs',\n                  tl_ret = tl_ret'\\<rparr>;\n      tl_ret_state = tl_imp tl_state;\n      takeWhile_char_acc_n' = tl_ret tl_ret_state;\n      ret = \\<lparr>takeWhile_char_acc_acc = takeWhile_char_acc_acc',\n             takeWhile_char_acc_n = takeWhile_char_acc_n',\n             takeWhile_char_acc_ret = takeWhile_char_acc_ret s\\<rparr>\n  in\n      ret\n)\"\n\ndefinition \"takeWhile_char_acc_imp_compute_loop_condition s \\<equiv>\n  (let\n      hd_xs' = takeWhile_char_acc_n s;\n      hd_ret' = 0;\n      hd_state = \\<lparr>hd_xs = hd_xs',\n                  hd_ret = hd_ret'\\<rparr>;\n      hd_ret_state = hd_imp hd_state;\n      EQUAL_neq_zero_a' = hd_ret hd_ret_state;\n      EQUAL_neq_zero_b' = hash_encode_char_as_nat;\n      EQUAL_neq_zero_ret' = 0;\n      EQUAL_neq_zero_state = \\<lparr>EQUAL_neq_zero_a = EQUAL_neq_zero_a',\n                              EQUAL_neq_zero_b = EQUAL_neq_zero_b',\n                              EQUAL_neq_zero_ret = EQUAL_neq_zero_ret'\\<rparr>;\n      EQUAL_neq_zero_ret_state = EQUAL_neq_zero_imp EQUAL_neq_zero_state;\n      AND_neq_zero_a' = takeWhile_char_acc_n s;\n      AND_neq_zero_b' = EQUAL_neq_zero_ret EQUAL_neq_zero_ret_state;\n      AND_neq_zero_ret' = 0;\n      AND_neq_zero_state = \\<lparr>AND_neq_zero_a = AND_neq_zero_a',\n                            AND_neq_zero_b = AND_neq_zero_b',\n                            AND_neq_zero_ret = AND_neq_zero_ret'\\<rparr>;\n      AND_neq_zero_ret_state = AND_neq_zero_imp AND_neq_zero_state;\n      condition = AND_neq_zero_ret AND_neq_zero_ret_state\n  in\n      condition\n)\"\n\ndefinition \"takeWhile_char_acc_imp_after_loop s \\<equiv>\n  (let\n      takeWhile_char_acc_ret' = takeWhile_char_acc_acc s;\n      ret = \\<lparr>takeWhile_char_acc_acc = takeWhile_char_acc_acc s,\n             takeWhile_char_acc_n = takeWhile_char_acc_n s,\n             takeWhile_char_acc_ret = takeWhile_char_acc_ret'\\<rparr>\n  in\n      ret\n)\"\n\nlemmas takeWhile_char_acc_imp_subprogram_simps = \n  takeWhile_char_acc_state_upd_def\n  takeWhile_char_acc_imp_compute_loop_condition_def\n  takeWhile_char_acc_imp_after_loop_def\n\nfunction takeWhile_char_acc_imp :: \"takeWhile_char_acc_state \\<Rightarrow> takeWhile_char_acc_state\" where\n  \"takeWhile_char_acc_imp s =\n  (if takeWhile_char_acc_imp_compute_loop_condition s \\<noteq> 0\n   then let next_iteration = takeWhile_char_acc_imp (takeWhile_char_acc_state_upd s)\n        in next_iteration\n   else let ret = takeWhile_char_acc_imp_after_loop s\n        in ret\n  )\"\n  by simp+\ntermination\n  apply (relation \"measure takeWhile_char_acc_n\")\n  apply (simp add: takeWhile_char_acc_imp_subprogram_simps tl_imp_correct\n  EQUAL_neq_zero_imp_correct AND_neq_zero_imp_correct split: if_splits)+\n  done\n\ndeclare takeWhile_char_acc_imp.simps [simp del]\n\nlemma takeWhile_char_acc_imp_correct[let_function_correctness]:\n  \"takeWhile_char_acc_ret (takeWhile_char_acc_imp s) =\n    takeWhile_char_acc (takeWhile_char_acc_acc s) (takeWhile_char_acc_n s)\"\n  apply (induction s rule: takeWhile_char_acc_imp.induct)\n  apply (subst takeWhile_char_acc_imp.simps)\n  apply (subst takeWhile_char_acc.simps)\n  apply (simp del: takeWhile_char_acc.simps add: takeWhile_char_acc_imp_subprogram_simps Let_def\n  AND_neq_zero_imp_correct EQUAL_neq_zero_imp_correct hd_imp_correct tl_imp_correct\n  cons_imp_correct hash_encode_char_val)\n  by fastforce\n\ndefinition \"takeWhile_char_acc_state_upd_time t s \\<equiv>\n  (let\n      hd_xs' = takeWhile_char_acc_n s;\n      t = t + 2;\n      hd_ret' = 0;\n      t = t + 2;\n      hd_state = \\<lparr>hd_xs = hd_xs',\n                  hd_ret = hd_ret'\\<rparr>;\n      hd_ret_state = hd_imp hd_state;\n      t = t + hd_imp_time 0 hd_state;\n      cons_h' = hd_ret hd_ret_state;\n      t = t + 2;\n      cons_t' = takeWhile_char_acc_acc s;\n      t = t + 2;\n      cons_ret' = 0;\n      t = t + 2;\n      cons_state = \\<lparr>cons_h = cons_h',\n                    cons_t = cons_t',\n                    cons_ret = cons_ret'\\<rparr>;\n      cons_ret_state = cons_imp cons_state;\n      t = t + cons_imp_time 0 cons_state;\n      takeWhile_char_acc_acc' = cons_ret cons_ret_state;\n      t = t + 2;\n      tl_xs' = takeWhile_char_acc_n s;\n      t = t + 2;\n      tl_ret' = 0;\n      t = t + 2;\n      tl_state = \\<lparr>tl_xs = tl_xs',\n                  tl_ret = tl_ret'\\<rparr>;\n      tl_ret_state = tl_imp tl_state;\n      t = t + tl_imp_time 0 tl_state;\n      takeWhile_char_acc_n' = tl_ret tl_ret_state;\n      t = t + 2;\n      ret = \\<lparr>takeWhile_char_acc_acc = takeWhile_char_acc_acc',\n             takeWhile_char_acc_n = takeWhile_char_acc_n',\n             takeWhile_char_acc_ret = takeWhile_char_acc_ret s\\<rparr>\n  in\n      t\n)\"\n\ndefinition \"takeWhile_char_acc_imp_compute_loop_condition_time t s \\<equiv>\n  (let\n      hd_xs' = takeWhile_char_acc_n s;\n      t = t + 2;\n      hd_ret' = 0;\n      t = t + 2;\n      hd_state = \\<lparr>hd_xs = hd_xs',\n                  hd_ret = hd_ret'\\<rparr>;\n      hd_ret_state = hd_imp hd_state;\n      t = t + hd_imp_time 0 hd_state;\n      EQUAL_neq_zero_a' = hd_ret hd_ret_state;\n      t = t + 2;\n      EQUAL_neq_zero_b' = hash_encode_char_as_nat;\n      t = t + 2;\n      EQUAL_neq_zero_ret' = 0;\n      t = t + 2;\n      EQUAL_neq_zero_state = \\<lparr>EQUAL_neq_zero_a = EQUAL_neq_zero_a',\n                              EQUAL_neq_zero_b = EQUAL_neq_zero_b',\n                              EQUAL_neq_zero_ret = EQUAL_neq_zero_ret'\\<rparr>;\n      EQUAL_neq_zero_ret_state = EQUAL_neq_zero_imp EQUAL_neq_zero_state;\n      t = t + EQUAL_neq_zero_imp_time 0 EQUAL_neq_zero_state;\n      AND_neq_zero_a' = takeWhile_char_acc_n s;\n      t = t + 2;\n      AND_neq_zero_b' = EQUAL_neq_zero_ret EQUAL_neq_zero_ret_state;\n      t = t + 2;\n      AND_neq_zero_ret' = 0;\n      t = t + 2;\n      AND_neq_zero_state = \\<lparr>AND_neq_zero_a = AND_neq_zero_a',\n                            AND_neq_zero_b = AND_neq_zero_b',\n                            AND_neq_zero_ret = AND_neq_zero_ret'\\<rparr>;\n      AND_neq_zero_ret_state = AND_neq_zero_imp AND_neq_zero_state;\n      t = t + AND_neq_zero_imp_time 0 AND_neq_zero_state;\n      condition = AND_neq_zero_ret AND_neq_zero_ret_state;\n      t = t + 2\n  in\n      t\n)\"\n\ndefinition \"takeWhile_char_acc_imp_after_loop_time t s \\<equiv>\n  (let\n      takeWhile_char_acc_ret' = takeWhile_char_acc_acc s;\n      t = t + 2;\n      ret = \\<lparr>takeWhile_char_acc_acc = takeWhile_char_acc_acc s,\n             takeWhile_char_acc_n = takeWhile_char_acc_n s,\n             takeWhile_char_acc_ret = takeWhile_char_acc_ret'\\<rparr>\n  in\n      t\n)\"\n\nlemmas takeWhile_char_acc_imp_subprogram_time_simps = \n  takeWhile_char_acc_state_upd_time_def\n  takeWhile_char_acc_imp_compute_loop_condition_time_def\n  takeWhile_char_acc_imp_after_loop_time_def\n  takeWhile_char_acc_imp_subprogram_simps\n\nfunction takeWhile_char_acc_imp_time :: \"nat \\<Rightarrow> takeWhile_char_acc_state \\<Rightarrow> nat\" where\n  \"takeWhile_char_acc_imp_time t s =\n  takeWhile_char_acc_imp_compute_loop_condition_time 0 s +\n  (if takeWhile_char_acc_imp_compute_loop_condition s \\<noteq> 0\n    then\n      (let\n        t = t + 1;\n        next_iteration =\n          takeWhile_char_acc_imp_time (t + takeWhile_char_acc_state_upd_time 0 s)\n                         (takeWhile_char_acc_state_upd s)\n       in next_iteration)\n    else\n      (let\n        t = t + 2;\n        ret = t + takeWhile_char_acc_imp_after_loop_time 0 s\n       in ret)\n  )\"\n  by auto\ntermination\n  apply (relation \"measure (takeWhile_char_acc_n \\<circ> snd)\")\n  by (simp add: takeWhile_char_acc_imp_subprogram_time_simps Let_def AND_neq_zero_imp_correct\n  EQUAL_neq_zero_imp_correct hd_imp_correct tl_imp_correct\n  cons_imp_correct hash_encode_char_val split: if_splits)+\n\ndeclare takeWhile_char_acc_imp_time.simps [simp del]  \n\nlemma takeWhile_char_acc_imp_time_acc:\n  \"(takeWhile_char_acc_imp_time (Suc t) s) = Suc (takeWhile_char_acc_imp_time t s)\"\n  by (induction t s rule: takeWhile_char_acc_imp_time.induct)\n    ((subst (1 2) takeWhile_char_acc_imp_time.simps);\n      (simp add: takeWhile_char_acc_state_upd_def))            \n\nlemma takeWhile_char_acc_imp_time_acc_2_aux:\n  \"(takeWhile_char_acc_imp_time t s) = t + (takeWhile_char_acc_imp_time 0 s)\"\n  by (induction t arbitrary: s) (simp add: takeWhile_char_acc_imp_time_acc)+            \n\nlemma takeWhile_char_acc_imp_time_acc_2:\n  \"t \\<noteq> 0 \\<Longrightarrow> (takeWhile_char_acc_imp_time t s) = t + (takeWhile_char_acc_imp_time 0 s)\"\n  by (rule takeWhile_char_acc_imp_time_acc_2_aux)            \n\nlemma takeWhile_char_acc_imp_time_acc_3:\n  \"(takeWhile_char_acc_imp_time (a + b) s) = a + (takeWhile_char_acc_imp_time b s)\"\n  by (induction a arbitrary: b s) (simp add: takeWhile_char_acc_imp_time_acc)+ \n\nabbreviation \"takeWhile_char_acc_while_cond \\<equiv> ''condition''\"\n\ndefinition \"takeWhile_char_acc_IMP_init_while_cond \\<equiv>\n  \\<comment> \\<open>  hd_xs' = takeWhile_char_acc_n s;\\<close>\n  (hd_prefix @ hd_xs_str) ::= (A (V takeWhile_char_acc_n_str));;\n  \\<comment> \\<open>  hd_ret' = 0;\\<close>\n  (hd_prefix @ hd_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  hd_state = \\<lparr>hd_xs = hd_xs',\\<close>\n  \\<comment> \\<open>              hd_ret = hd_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  hd_ret_state = hd_imp hd_state;\\<close>\n  (invoke_subprogram hd_prefix hd_IMP_Minus);;\n  \\<comment> \\<open>  EQUAL_neq_zero_a' = hd_ret hd_ret_state;\\<close>\n  (EQUAL_neq_zero_prefix @ EQUAL_neq_zero_a_str) ::= (A (V (hd_prefix @ hd_ret_str)));;\n  \\<comment> \\<open>  EQUAL_neq_zero_b' = hash_encode_char_as_nat;\\<close>\n  (EQUAL_neq_zero_prefix @ EQUAL_neq_zero_b_str) ::= (A (N hash_encode_char_as_nat));;\n  \\<comment> \\<open>  EQUAL_neq_zero_ret' = 0;\\<close>\n  (EQUAL_neq_zero_prefix @ EQUAL_neq_zero_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  EQUAL_neq_zero_state = \\<lparr>EQUAL_neq_zero_a = EQUAL_neq_zero_a',\\<close>\n  \\<comment> \\<open>                          EQUAL_neq_zero_b = EQUAL_neq_zero_b',\\<close>\n  \\<comment> \\<open>                          EQUAL_neq_zero_ret = EQUAL_neq_zero_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  EQUAL_neq_zero_ret_state = EQUAL_neq_zero_imp EQUAL_neq_zero_state;\\<close>\n  (invoke_subprogram EQUAL_neq_zero_prefix EQUAL_neq_zero_IMP_Minus);;\n  \\<comment> \\<open>  AND_neq_zero_a' = takeWhile_char_acc_n s;\\<close>\n  (AND_neq_zero_prefix @ AND_neq_zero_a_str) ::= (A (V takeWhile_char_acc_n_str));;\n  \\<comment> \\<open>  AND_neq_zero_b' = EQUAL_neq_zero_ret EQUAL_neq_zero_ret_state;\\<close>\n  (AND_neq_zero_prefix @ AND_neq_zero_b_str) ::= (A (V (EQUAL_neq_zero_prefix @ EQUAL_neq_zero_ret_str)));;\n  \\<comment> \\<open>  AND_neq_zero_ret' = 0;\\<close>\n  (AND_neq_zero_prefix @ AND_neq_zero_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  AND_neq_zero_state = \\<lparr>AND_neq_zero_a = AND_neq_zero_a',\\<close>\n  \\<comment> \\<open>                        AND_neq_zero_b = AND_neq_zero_b',\\<close>\n  \\<comment> \\<open>                        AND_neq_zero_ret = AND_neq_zero_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  AND_neq_zero_ret_state = AND_neq_zero_imp AND_neq_zero_state;\\<close>\n  (invoke_subprogram AND_neq_zero_prefix AND_neq_zero_IMP_Minus);;\n  \\<comment> \\<open>  condition = AND_neq_zero_ret AND_neq_zero_ret_state\\<close>\n  (takeWhile_char_acc_while_cond) ::= (A (V (AND_neq_zero_prefix @ AND_neq_zero_ret_str)))\n\"\n\ndefinition \"takeWhile_char_acc_IMP_loop_body \\<equiv>\n  \\<comment> \\<open>  hd_xs' = takeWhile_char_acc_n s;\\<close>\n  (hd_prefix @ hd_xs_str) ::= (A (V takeWhile_char_acc_n_str));;\n  \\<comment> \\<open>  hd_ret' = 0;\\<close>\n  (hd_prefix @ hd_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  hd_state = \\<lparr>hd_xs = hd_xs',\\<close>\n  \\<comment> \\<open>              hd_ret = hd_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  hd_ret_state = hd_imp hd_state;\\<close>\n  (invoke_subprogram hd_prefix hd_IMP_Minus);;\n  \\<comment> \\<open>  cons_h' = hd_ret hd_ret_state;\\<close>\n  (cons_prefix @ cons_h_str) ::= (A (V (hd_prefix @ hd_ret_str)));;\n  \\<comment> \\<open>  cons_t' = takeWhile_char_acc_acc s;\\<close>\n  (cons_prefix @ cons_t_str) ::= (A (V takeWhile_char_acc_acc_str));;\n  \\<comment> \\<open>  cons_ret' = 0;\\<close>\n  (cons_prefix @ cons_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  cons_state = \\<lparr>cons_h = cons_h',\\<close>\n  \\<comment> \\<open>                cons_t = cons_t',\\<close>\n  \\<comment> \\<open>                cons_ret = cons_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  cons_ret_state = cons_imp cons_state;\\<close>\n  (invoke_subprogram cons_prefix cons_IMP_Minus);;\n  \\<comment> \\<open>  takeWhile_char_acc_acc' = cons_ret cons_ret_state;\\<close>\n  (takeWhile_char_acc_acc_str) ::= (A (V (cons_prefix @ cons_ret_str)));;\n  \\<comment> \\<open>  tl_xs' = takeWhile_char_acc_n s;\\<close>\n  (tl_prefix @ tl_xs_str) ::= (A (V takeWhile_char_acc_n_str));;\n  \\<comment> \\<open>  tl_ret' = 0;\\<close>\n  (tl_prefix @ tl_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  tl_state = \\<lparr>tl_xs = tl_xs',\\<close>\n  \\<comment> \\<open>              tl_ret = tl_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  tl_ret_state = tl_imp tl_state;\\<close>\n  (invoke_subprogram tl_prefix tl_IMP_Minus);;\n  \\<comment> \\<open>  takeWhile_char_acc_n' = tl_ret tl_ret_state;\\<close>\n  (takeWhile_char_acc_n_str) ::= (A (V (tl_prefix @ tl_ret_str)))\n  \\<comment> \\<open>  ret = \\<lparr>takeWhile_char_acc_acc = takeWhile_char_acc_acc',\\<close>\n  \\<comment> \\<open>         takeWhile_char_acc_n = takeWhile_char_acc_n',\\<close>\n  \\<comment> \\<open>         takeWhile_char_acc_ret = takeWhile_char_acc_ret s\\<rparr>\\<close>\n\"\n\ndefinition \"takeWhile_char_acc_IMP_after_loop \\<equiv>\n  \\<comment> \\<open>  takeWhile_char_acc_ret' = takeWhile_char_acc_acc s;\\<close>\n  (takeWhile_char_acc_ret_str) ::= (A (V takeWhile_char_acc_acc_str))\n  \\<comment> \\<open>  ret = \\<lparr>takeWhile_char_acc_acc = takeWhile_char_acc_acc s,\\<close>\n  \\<comment> \\<open>         takeWhile_char_acc_n = takeWhile_char_acc_n s,\\<close>\n  \\<comment> \\<open>         takeWhile_char_acc_ret = takeWhile_char_acc_ret'\\<rparr>\\<close>\n\"\n\ndefinition takeWhile_char_acc_IMP_Minus where\n  \"takeWhile_char_acc_IMP_Minus \\<equiv>\n  takeWhile_char_acc_IMP_init_while_cond;;\n  WHILE takeWhile_char_acc_while_cond \\<noteq>0 DO (\n    takeWhile_char_acc_IMP_loop_body;;\n    takeWhile_char_acc_IMP_init_while_cond\n  );;\n  takeWhile_char_acc_IMP_after_loop\"\n\nabbreviation \"takeWhile_char_acc_IMP_vars \\<equiv>\n  {takeWhile_char_acc_acc_str, takeWhile_char_acc_n_str, takeWhile_char_acc_ret_str}\"\n\nlemmas takeWhile_char_acc_IMP_subprogram_simps =\n  takeWhile_char_acc_IMP_init_while_cond_def\n  takeWhile_char_acc_IMP_loop_body_def\n  takeWhile_char_acc_IMP_after_loop_def\n\ndefinition \"takeWhile_char_acc_imp_to_HOL_state p s =\n  \\<lparr>takeWhile_char_acc_acc = (s (add_prefix p takeWhile_char_acc_acc_str)),\n   takeWhile_char_acc_n = (s (add_prefix p takeWhile_char_acc_n_str)),\n   takeWhile_char_acc_ret = (s (add_prefix p takeWhile_char_acc_ret_str))\\<rparr>\"\n\nlemmas takeWhile_char_acc_state_translators =\n  takeWhile_char_acc_imp_to_HOL_state_def\n  EQUAL_neq_zero_imp_to_HOL_state_def\n  AND_neq_zero_imp_to_HOL_state_def\n  hd_imp_to_HOL_state_def\n  cons_imp_to_HOL_state_def\n  tl_imp_to_HOL_state_def\n\nlemmas takeWhile_char_acc_complete_simps =\n  takeWhile_char_acc_IMP_subprogram_simps\n  takeWhile_char_acc_imp_subprogram_simps\n  takeWhile_char_acc_state_translators\n\nlemma takeWhile_char_acc_IMP_Minus_correct_function:\n  \"(invoke_subprogram p takeWhile_char_acc_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p takeWhile_char_acc_ret_str)\n      = takeWhile_char_acc_ret\n          (takeWhile_char_acc_imp (takeWhile_char_acc_imp_to_HOL_state p s))\"\n  apply(induction \"takeWhile_char_acc_imp_to_HOL_state p s\" arbitrary: s s' t\n    rule: takeWhile_char_acc_imp.induct)\n  apply(subst takeWhile_char_acc_imp.simps)\n  apply(simp only: takeWhile_char_acc_IMP_Minus_def prefix_simps)\n  apply(erule Seq_E)+\n  apply(erule While_tE)\n\n  subgoal\n    apply(simp only: takeWhile_char_acc_IMP_subprogram_simps prefix_simps)\n    apply(erule Seq_E)+\n    apply(erule hd_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(17) by fastforce\n    apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(19) by fastforce\n    apply(erule AND_neq_zero_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(21) by fastforce\n    by(fastforce simp: takeWhile_char_acc_IMP_subprogram_simps\n        takeWhile_char_acc_imp_subprogram_simps\n        takeWhile_char_acc_state_translators)\n\n  apply(erule Seq_E)+\n  apply(dest_com_gen)\n\n  subgoal\n      apply(simp only: takeWhile_char_acc_IMP_init_while_cond_def prefix_simps)\n      apply(erule Seq_E)+\n      apply(erule hd_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n      subgoal premises p using p(28) by fastforce\n      apply(erule hd_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n      subgoal premises p using p(30) by fastforce\n      apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n      subgoal premises p using p(32) by fastforce\n      apply(erule AND_neq_zero_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n      subgoal premises p using p(34) by fastforce\n      by(fastforce simp add: takeWhile_char_acc_complete_simps)\n\n  subgoal\n      apply(subst (asm) takeWhile_char_acc_IMP_init_while_cond_def)\n      apply(simp only: takeWhile_char_acc_IMP_loop_body_def prefix_simps)\n      apply(erule Seq_E)+\n      apply(erule hd_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n      subgoal premises p using p(28) by fastforce\n      apply(erule hd_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n      subgoal premises p using p(30) by fastforce\n      apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n      subgoal premises p using p(32) by fastforce\n      apply(erule AND_neq_zero_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n      subgoal premises p using p(34) by fastforce\n      apply(erule cons_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n      subgoal premises p using p(36) by fastforce\n      apply(erule tl_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n      subgoal premises p using p(38) by fastforce\n      by (fastforce_sorted_premises2 simp: takeWhile_char_acc_imp_subprogram_simps Let_def\n        takeWhile_char_acc_state_translators)\n\n  subgoal\n      apply(simp only: takeWhile_char_acc_IMP_init_while_cond_def prefix_simps\n          takeWhile_char_acc_IMP_loop_body_def)\n      apply(erule Seq_E)+\n      apply(erule hd_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n      subgoal premises p using p(39) by fastforce\n      apply(erule hd_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n      subgoal premises p using p(41) by fastforce\n      apply(erule hd_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n      subgoal premises p using p(43) by fastforce\n      apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n      subgoal premises p using p(45) by fastforce\n      apply(erule AND_neq_zero_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n      subgoal premises p using p(47) by fastforce\n      apply(erule cons_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n      subgoal premises p using p(49) by fastforce\n      apply(erule tl_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n      subgoal premises p using p(51) by fastforce\n      by (fastforce_sorted_premises2 simp: takeWhile_char_acc_imp_subprogram_simps Let_def\n        takeWhile_char_acc_state_translators)\n  done\n\nlemma takeWhile_char_acc_IMP_Minus_correct_effects:\n  \"\\<lbrakk>(invoke_subprogram (p @ takeWhile_char_acc_pref) takeWhile_char_acc_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    v \\<in> vars; \\<not> (prefix takeWhile_char_acc_pref v)\\<rbrakk>\n   \\<Longrightarrow> s (add_prefix p v) = s' (add_prefix p v)\"\n  using com_add_prefix_valid'' com_only_vars prefix_def\n  by blast \n\nlemmas takeWhile_char_acc_complete_time_simps =\n  takeWhile_char_acc_imp_subprogram_time_simps\n  takeWhile_char_acc_imp_time_acc\n  takeWhile_char_acc_imp_time_acc_2\n  takeWhile_char_acc_imp_time_acc_3\n  takeWhile_char_acc_state_translators\n\nlemma takeWhile_char_acc_IMP_Minus_correct_time:\n  \"(invoke_subprogram p takeWhile_char_acc_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = takeWhile_char_acc_imp_time 0 (takeWhile_char_acc_imp_to_HOL_state p s)\"\n  apply(induction \"takeWhile_char_acc_imp_to_HOL_state p s\" arbitrary: s s' t\n      rule: takeWhile_char_acc_imp.induct)\n  apply(subst takeWhile_char_acc_imp_time.simps)\n  apply(simp only: takeWhile_char_acc_IMP_Minus_def prefix_simps)\n\n  apply(erule Seq_tE)+\n  apply(erule While_tE_time)\n\n  subgoal\n    apply(simp only: takeWhile_char_acc_IMP_subprogram_simps prefix_simps)\n    apply(erule Seq_tE)+\n    apply(erule hd_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(30) by fastforce\n    apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(32) by fastforce\n    apply(erule AND_neq_zero_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(34) by fastforce\n    by (force simp: takeWhile_char_acc_imp_subprogram_time_simps Let_def \n        takeWhile_char_acc_state_translators)\n\n  apply(erule Seq_tE)+\n  apply(simp add: add.assoc)\n  apply(dest_com_gen_time)\n\n  subgoal\n    apply(simp only: takeWhile_char_acc_IMP_init_while_cond_def prefix_simps)\n    apply(erule Seq_tE)+\n    apply(erule hd_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(53) by fastforce\n    apply(erule hd_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(55) by fastforce\n    apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(57) by fastforce\n    apply(erule AND_neq_zero_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(59) by fastforce\n    by(fastforce simp add: takeWhile_char_acc_complete_simps)\n\n  subgoal\n    apply(subst (asm) takeWhile_char_acc_IMP_init_while_cond_def)\n    apply(simp only: takeWhile_char_acc_IMP_loop_body_def prefix_simps)\n    apply(erule Seq_tE)+\n    apply(erule hd_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(53) by fastforce\n    apply(erule hd_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(55) by fastforce\n    apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(57) by fastforce\n    apply(erule AND_neq_zero_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(59) by fastforce\n    apply(erule cons_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(61) by fastforce\n    apply(erule tl_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(63) by fastforce\n    by (fastforce_sorted_premises simp: Let_def\n        takeWhile_char_acc_complete_time_simps)\n\n  subgoal\n    apply(simp only: prefix_simps takeWhile_char_acc_IMP_init_while_cond_def\n        takeWhile_char_acc_IMP_loop_body_def)\n    apply(erule Seq_tE)+\n    apply(erule hd_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(75) by fastforce\n    apply(erule hd_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(77) by fastforce\n    apply(erule hd_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(79) by fastforce\n    apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(81) by fastforce\n    apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(83) by fastforce\n    apply(erule AND_neq_zero_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(85) by fastforce\n    apply(erule AND_neq_zero_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(87) by fastforce\n    apply(erule cons_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(89) by fastforce\n    apply(erule tl_IMP_Minus_correct[where vars = \"takeWhile_char_acc_IMP_vars\"])\n    subgoal premises p using p(91) by fastforce\n    apply(simp only: takeWhile_char_acc_complete_time_simps Let_def)\n    by (fastforce_sorted_premises simp: Let_def\n        takeWhile_char_acc_complete_time_simps)\n\n  done \n\nlemma takeWhile_char_acc_IMP_Minus_correct:\n  \"\\<lbrakk>(invoke_subprogram (p1 @ p2) takeWhile_char_acc_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    \\<And>v. v \\<in> vars \\<Longrightarrow> \\<not> (set p2 \\<subseteq> set v);\n    \\<lbrakk>t = (takeWhile_char_acc_imp_time 0 (takeWhile_char_acc_imp_to_HOL_state (p1 @ p2) s));\n     s' (add_prefix (p1 @ p2) takeWhile_char_acc_ret_str) =\n          takeWhile_char_acc_ret (takeWhile_char_acc_imp\n                                        (takeWhile_char_acc_imp_to_HOL_state (p1 @ p2) s));\n     \\<And>v. v \\<in> vars \\<Longrightarrow> s (add_prefix p1 v) = s' (add_prefix p1 v)\\<rbrakk>\n   \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  using takeWhile_char_acc_IMP_Minus_correct_function\n    takeWhile_char_acc_IMP_Minus_correct_time\n    takeWhile_char_acc_IMP_Minus_correct_effects\n  by (meson set_mono_prefix)\n\nsubsubsection \\<open>takeWhile_char_tail\\<close>\n\nrecord takeWhile_char_tail_state =\n  takeWhile_char_tail_ys::nat\n  takeWhile_char_tail_ret::nat\n\nabbreviation \"takeWhile_char_tail_prefix \\<equiv> ''takeWhile_char_tail.''\"\nabbreviation \"takeWhile_char_tail_ys_str \\<equiv> ''ys''\"\nabbreviation \"takeWhile_char_tail_ret_str \\<equiv> ''ret''\"\n\ndefinition \"takeWhile_char_tail_state_upd s =\n  (let\n      takeWhile_char_acc_acc' = 0;\n      takeWhile_char_acc_n' = takeWhile_char_tail_ys s;\n      takeWhile_char_acc_ret' = 0;\n      takeWhile_char_acc_state = \\<lparr>takeWhile_char_acc_acc = takeWhile_char_acc_acc',\n                                  takeWhile_char_acc_n = takeWhile_char_acc_n',\n                                  takeWhile_char_acc_ret = takeWhile_char_acc_ret'\\<rparr>;\n      takeWhile_char_acc_ret_state = takeWhile_char_acc_imp takeWhile_char_acc_state;\n      reverse_nat_n' = takeWhile_char_acc_ret takeWhile_char_acc_ret_state;\n      reverse_nat_ret' = 0;\n      reverse_nat_state = \\<lparr>reverse_nat_n = reverse_nat_n',\n                           reverse_nat_ret = reverse_nat_ret'\\<rparr>;\n      reverse_nat_ret_state = reverse_nat_imp reverse_nat_state;\n      takeWhile_char_tail_ret' = reverse_nat_ret reverse_nat_ret_state;\n      ret = \\<lparr>takeWhile_char_tail_ys = takeWhile_char_tail_ys s,\n             takeWhile_char_tail_ret = takeWhile_char_tail_ret'\\<rparr>\n  in\n      ret\n  )\"\n\nfunction takeWhile_char_tail_imp:: \"takeWhile_char_tail_state \\<Rightarrow> takeWhile_char_tail_state\" where\n  \"takeWhile_char_tail_imp s =\n  (let\n      ret = takeWhile_char_tail_state_upd s\n    in\n      ret\n  )\"\n  by simp+\ntermination\n  by (relation \"measure takeWhile_char_tail_ys\") simp\n\ndeclare takeWhile_char_tail_imp.simps [simp del]\n\nlemma takeWhile_char_tail_imp_correct:\n  \"takeWhile_char_tail_ret (takeWhile_char_tail_imp s) =\n    takeWhile_char_tail (takeWhile_char_tail_ys s)\"\n  apply (simp only: takeWhile_char_acc_imp_correct takeWhile_char_tail_def \n    takeWhile_char_tail_imp.simps takeWhile_char_tail_state_upd_def \n    reverse_nat_imp_correct Let_def)\n  by simp\n\nfunction takeWhile_char_tail_imp_time :: \"nat \\<Rightarrow> takeWhile_char_tail_state \\<Rightarrow> nat\" where\n  \"takeWhile_char_tail_imp_time t s =\n  (let\n      takeWhile_char_acc_acc' = 0;\n      t = t + 2;\n      takeWhile_char_acc_n' = takeWhile_char_tail_ys s;\n      t = t + 2;\n      takeWhile_char_acc_ret' = 0;\n      t = t + 2;\n      takeWhile_char_acc_state = \\<lparr>takeWhile_char_acc_acc = takeWhile_char_acc_acc',\n                                  takeWhile_char_acc_n = takeWhile_char_acc_n',\n                                  takeWhile_char_acc_ret = takeWhile_char_acc_ret'\\<rparr>;\n      takeWhile_char_acc_ret_state = takeWhile_char_acc_imp takeWhile_char_acc_state;\n      t = t + takeWhile_char_acc_imp_time 0 takeWhile_char_acc_state;\n      reverse_nat_n' = takeWhile_char_acc_ret takeWhile_char_acc_ret_state;\n      t = t + 2;\n      reverse_nat_ret' = 0;\n      t = t + 2;\n      reverse_nat_state = \\<lparr>reverse_nat_n = reverse_nat_n',\n                           reverse_nat_ret = reverse_nat_ret'\\<rparr>;\n      reverse_nat_ret_state = reverse_nat_imp reverse_nat_state;\n      t = t + reverse_nat_imp_time 0 reverse_nat_state;\n      takeWhile_char_tail_ret' = reverse_nat_ret reverse_nat_ret_state;\n      t = t + 2;\n      ret = \\<lparr>takeWhile_char_tail_ys = takeWhile_char_tail_ys s,\n             takeWhile_char_tail_ret = takeWhile_char_tail_ret'\\<rparr>\n  in\n      t\n  )\"\n  by auto\ntermination\n  by (relation \"measure (takeWhile_char_tail_ys \\<circ> snd)\") simp\n\ndeclare takeWhile_char_tail_imp_time.simps [simp del]\n\nlemma takeWhile_char_tail_imp_time_acc:\n  \"(takeWhile_char_tail_imp_time (Suc t) s) = Suc (takeWhile_char_tail_imp_time t s)\"\n  by (induction t s rule: takeWhile_char_tail_imp_time.induct)\n    ((subst (1 2) takeWhile_char_tail_imp_time.simps);\n      (simp add: takeWhile_char_tail_state_upd_def Let_def))            \n\nlemma takeWhile_char_tail_imp_time_acc_2_aux:\n  \"(takeWhile_char_tail_imp_time t s) = t + (takeWhile_char_tail_imp_time 0 s)\"\n  by (induction t arbitrary: s) (simp add: takeWhile_char_tail_imp_time_acc)+            \n\nlemma takeWhile_char_tail_imp_time_acc_2:\n  \"t \\<noteq> 0 \\<Longrightarrow> (takeWhile_char_tail_imp_time t s) = t + (takeWhile_char_tail_imp_time 0 s)\"\n  by (rule takeWhile_char_tail_imp_time_acc_2_aux)            \n\nlemma takeWhile_char_tail_imp_time_acc_3:\n  \"(takeWhile_char_tail_imp_time (a + b) s) = a + (takeWhile_char_tail_imp_time b s)\"\n  by (induction a arbitrary: b s) (simp add: takeWhile_char_tail_imp_time_acc)+  \n\ndefinition takeWhile_char_tail_IMP_Minus where\n  \"takeWhile_char_tail_IMP_Minus \\<equiv>\n  \\<comment> \\<open>  takeWhile_char_acc_acc' = 0;\\<close>\n  (takeWhile_char_acc_prefix @ takeWhile_char_acc_acc_str) ::= (A (N 0));;\n  \\<comment> \\<open>  takeWhile_char_acc_n' = takeWhile_char_tail_ys s;\\<close>\n  (takeWhile_char_acc_prefix @ takeWhile_char_acc_n_str) ::= (A (V takeWhile_char_tail_ys_str));;\n  \\<comment> \\<open>  takeWhile_char_acc_ret' = 0;\\<close>\n  (takeWhile_char_acc_prefix @ takeWhile_char_acc_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  takeWhile_char_acc_state = \\<lparr>takeWhile_char_acc_acc = takeWhile_char_acc_acc',\\<close>\n  \\<comment> \\<open>                              takeWhile_char_acc_n = takeWhile_char_acc_n',\\<close>\n  \\<comment> \\<open>                              takeWhile_char_acc_ret = takeWhile_char_acc_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  takeWhile_char_acc_ret_state = takeWhile_char_acc_imp takeWhile_char_acc_state;\\<close>\n  (invoke_subprogram takeWhile_char_acc_prefix takeWhile_char_acc_IMP_Minus);;\n  \\<comment> \\<open>  reverse_nat_n' = takeWhile_char_acc_ret takeWhile_char_acc_ret_state;\\<close>\n  (reverse_nat_prefix @ reverse_nat_n_str) ::= (A (V (takeWhile_char_acc_prefix @ takeWhile_char_acc_ret_str)));;\n  \\<comment> \\<open>  reverse_nat_ret' = 0;\\<close>\n  (reverse_nat_prefix @ reverse_nat_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  reverse_nat_state = \\<lparr>reverse_nat_n = reverse_nat_n',\\<close>\n  \\<comment> \\<open>                       reverse_nat_ret = reverse_nat_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  reverse_nat_ret_state = reverse_nat_imp reverse_nat_state;\\<close>\n  (invoke_subprogram reverse_nat_prefix reverse_nat_IMP_Minus);;\n  \\<comment> \\<open>  takeWhile_char_tail_ret' = reverse_nat_ret reverse_nat_ret_state;\\<close>\n  (takeWhile_char_tail_ret_str) ::= (A (V (reverse_nat_prefix @ reverse_nat_ret_str)))\n  \\<comment> \\<open>  ret = \\<lparr>takeWhile_char_tail_ys = takeWhile_char_tail_ys s,\\<close>\n  \\<comment> \\<open>         takeWhile_char_tail_ret = takeWhile_char_tail_ret'\\<rparr>\\<close>\n\"\n\nabbreviation \"takeWhile_char_tail_IMP_vars \\<equiv>\n  {takeWhile_char_tail_ys_str, takeWhile_char_tail_ret_str}\"\n\ndefinition \"takeWhile_char_tail_imp_to_HOL_state p s =\n  \\<lparr>takeWhile_char_tail_ys = (s (add_prefix p takeWhile_char_tail_ys_str)),\n   takeWhile_char_tail_ret = (s (add_prefix p takeWhile_char_tail_ret_str))\\<rparr>\"\n\nlemmas takeWhile_char_tail_state_translators =\n  takeWhile_char_tail_imp_to_HOL_state_def\n  takeWhile_char_acc_imp_to_HOL_state_def\n  reverse_nat_imp_to_HOL_state_def\n\nlemma takeWhile_char_tail_IMP_Minus_correct_function:\n  \"(invoke_subprogram p takeWhile_char_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p takeWhile_char_tail_ret_str)\n      = takeWhile_char_tail_ret\n          (takeWhile_char_tail_imp (takeWhile_char_tail_imp_to_HOL_state p s))\"\n  apply(subst takeWhile_char_tail_imp.simps)\n  apply(simp only: takeWhile_char_tail_IMP_Minus_def prefix_simps)\n  apply(erule Seq_E)+\n  apply(erule takeWhile_char_acc_IMP_Minus_correct[where vars = \"takeWhile_char_tail_IMP_vars\"])\n  subgoal premises p using p(8) by fastforce\n  apply(erule reverse_nat_IMP_Minus_correct[where vars = \"takeWhile_char_tail_IMP_vars\"])\n  subgoal premises p using p(10) by fastforce\n  by (fastforce simp: takeWhile_char_tail_state_translators takeWhile_char_tail_state_upd_def)\n\nlemma takeWhile_char_tail_IMP_Minus_correct_effects:\n  \"\\<lbrakk>(invoke_subprogram (p @ takeWhile_char_tail_pref) takeWhile_char_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    v \\<in> vars; \\<not> (prefix takeWhile_char_tail_pref v)\\<rbrakk>\n   \\<Longrightarrow> s (add_prefix p v) = s' (add_prefix p v)\"\n  using com_add_prefix_valid'' com_only_vars prefix_def\n  by blast\n\nlemma takeWhile_char_tail_IMP_Minus_correct_time:\n  \"(invoke_subprogram p takeWhile_char_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = takeWhile_char_tail_imp_time 0 (takeWhile_char_tail_imp_to_HOL_state p s)\"\n  apply(subst takeWhile_char_tail_imp_time.simps)\n  apply(simp only: takeWhile_char_tail_IMP_Minus_def prefix_simps)\n  apply(erule Seq_tE)+\n  apply(erule takeWhile_char_acc_IMP_Minus_correct[where vars = \"takeWhile_char_tail_IMP_vars\"])\n  subgoal premises p using p(15) by fastforce\n  apply(erule reverse_nat_IMP_Minus_correct[where vars = \"takeWhile_char_tail_IMP_vars\"])\n  subgoal premises p using p(17) by fastforce\n  by (fastforce simp add: Let_def takeWhile_char_tail_state_translators)\n\nlemma takeWhile_char_tail_IMP_Minus_correct:\n  \"\\<lbrakk>(invoke_subprogram (p1 @ p2) takeWhile_char_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    \\<And>v. v \\<in> vars \\<Longrightarrow> \\<not> (set p2 \\<subseteq> set v);\n    \\<lbrakk>t = (takeWhile_char_tail_imp_time 0 (takeWhile_char_tail_imp_to_HOL_state (p1 @ p2) s));\n     s' (add_prefix (p1 @ p2) takeWhile_char_tail_ret_str) =\n          takeWhile_char_tail_ret (takeWhile_char_tail_imp\n                                        (takeWhile_char_tail_imp_to_HOL_state (p1 @ p2) s));\n     \\<And>v. v \\<in> vars \\<Longrightarrow> s (add_prefix p1 v) = s' (add_prefix p1 v)\\<rbrakk>\n   \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  using takeWhile_char_tail_IMP_Minus_correct_function\n    takeWhile_char_tail_IMP_Minus_correct_time\n    takeWhile_char_tail_IMP_Minus_correct_effects\n  by (meson set_mono_prefix)\n\n\nsubsection \\<open>var_to_var_bit\\<close>\n\nsubsubsection \\<open>var_to_var_bit_tail_aux1\\<close>\n\nfun var_to_var_bit_tail_aux1 :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat\" where\n  \"var_to_var_bit_tail_aux1 t l = \n    (if length_nat t > 0 \\<and> hd_nat t = encode_char (CHR ''$'')\n     then some_nat (prod_encode(tl_nat t, l))\n     else 0\n  )\"\n\nlemma var_to_var_bit_tail_aux1_correct: \n  \"var_to_var_bit_tail_aux1 (dropWhile_char v) (length_nat (takeWhile_char_tail v) - 1) =\n  (if length_nat (dropWhile_char v) > 0 \\<and> hd_nat (dropWhile_char v) = encode_char (CHR ''$'')\n     then some_nat (prod_encode(tl_nat (dropWhile_char v), (length_nat (takeWhile_char_tail v) - 1)))\n     else 0\n  )\"\n  using var_to_var_bit_tail_aux1.simps by blast\n\nlemma var_to_var_bit_tail_aux1_correct2:\n  \"var_to_var_bit_tail_aux1 (dropWhile_char v) (length_nat (takeWhile_char_tail v) - 1) =\n  (let t = dropWhile_char v;\n       l = length_nat (takeWhile_char_tail v) - 1\n   in (if length_nat t > 0 \\<and> hd_nat t = encode_char (CHR ''$'')\n       then some_nat (prod_encode(tl_nat t, l))\n       else 0))\"\n  using var_to_var_bit_tail_aux1_correct \n  by (smt (verit, best))\n\nrecord var_to_var_bit_tail_aux1_state =\n  var_to_var_bit_tail_aux1_t::nat\n  var_to_var_bit_tail_aux1_l::nat\n  var_to_var_bit_tail_aux1_ret::nat\n\nabbreviation \"var_to_var_bit_tail_aux1_prefix \\<equiv> ''var_to_var_bit_tail_aux1.''\"\nabbreviation \"var_to_var_bit_tail_aux1_t_str \\<equiv> ''t''\"\nabbreviation \"var_to_var_bit_tail_aux1_l_str \\<equiv> ''l''\"\nabbreviation \"var_to_var_bit_tail_aux1_ret_str \\<equiv> ''ret''\"\n\ndefinition \"var_to_var_bit_tail_aux1_state_upd s \\<equiv>\n  (let\n      length_xs' = var_to_var_bit_tail_aux1_t s;\n      length_ret' = 0;\n      length_state = \\<lparr>length_xs = length_xs',\n                      length_ret = length_ret'\\<rparr>;\n      length_ret_state = length_imp length_state;\n      length_result = length_ret length_ret_state;\n      hd_xs' = var_to_var_bit_tail_aux1_t s;\n      hd_ret' = 0;\n      hd_state = \\<lparr>hd_xs = hd_xs',\n                  hd_ret = hd_ret'\\<rparr>;\n      hd_ret_state = hd_imp hd_state;\n      EQUAL_neq_zero_a' = hd_ret hd_ret_state;\n      EQUAL_neq_zero_b' = dollar_encode_char_as_nat;\n      EQUAL_neq_zero_ret' = 0;\n      EQUAL_neq_zero_state = \\<lparr>EQUAL_neq_zero_a = EQUAL_neq_zero_a',\n                              EQUAL_neq_zero_b = EQUAL_neq_zero_b',\n                              EQUAL_neq_zero_ret = EQUAL_neq_zero_ret'\\<rparr>;\n      EQUAL_neq_zero_ret_state = EQUAL_neq_zero_imp EQUAL_neq_zero_state;\n      AND_neq_zero_a' = length_result;\n      AND_neq_zero_b' = EQUAL_neq_zero_ret EQUAL_neq_zero_ret_state;\n      AND_neq_zero_ret' = 0;\n      AND_neq_zero_state = \\<lparr>AND_neq_zero_a = AND_neq_zero_a',\n                            AND_neq_zero_b = AND_neq_zero_b',\n                            AND_neq_zero_ret = AND_neq_zero_ret'\\<rparr>;\n      AND_neq_zero_ret_state = AND_neq_zero_imp AND_neq_zero_state;\n      AND_neq_zero_result = AND_neq_zero_ret AND_neq_zero_ret_state\n  in\n  (if AND_neq_zero_result \\<noteq> 0 then\n    (let\n      tl_xs' = var_to_var_bit_tail_aux1_t s;\n      tl_ret' = 0;\n      tl_state = \\<lparr>tl_xs = tl_xs',\n                  tl_ret = tl_ret'\\<rparr>;\n      tl_ret_state = tl_imp tl_state;\n      prod_encode_a' = tl_ret tl_ret_state;\n      prod_encode_b' = var_to_var_bit_tail_aux1_l s;\n      prod_encode_ret' = 0;\n      prod_encode_state = \\<lparr>prod_encode_a = prod_encode_a',\n                           prod_encode_b = prod_encode_b',\n                           prod_encode_ret = prod_encode_ret'\\<rparr>;\n      prod_encode_ret_state = prod_encode_imp prod_encode_state;\n      some_nat_n' = prod_encode_ret prod_encode_ret_state;\n      some_nat_ret' = 0;\n      some_nat_state = \\<lparr>some_nat_n = some_nat_n',\n                        some_nat_ret = some_nat_ret'\\<rparr>;\n      some_nat_ret_state = some_nat_imp some_nat_state;\n      var_to_var_bit_tail_aux1_ret' = some_nat_ret some_nat_ret_state;\n      ret = \\<lparr>var_to_var_bit_tail_aux1_t = var_to_var_bit_tail_aux1_t s,\n             var_to_var_bit_tail_aux1_l = var_to_var_bit_tail_aux1_l s,\n             var_to_var_bit_tail_aux1_ret = var_to_var_bit_tail_aux1_ret'\\<rparr>\n    in\n      ret\n    )\n  else\n    (let\n      var_to_var_bit_tail_aux1_ret' = 0;\n      ret = \\<lparr>var_to_var_bit_tail_aux1_t = var_to_var_bit_tail_aux1_t s,\n             var_to_var_bit_tail_aux1_l = var_to_var_bit_tail_aux1_l s,\n             var_to_var_bit_tail_aux1_ret = var_to_var_bit_tail_aux1_ret'\\<rparr>\n    in\n      ret\n    )\n  )\n)\"\n\nfunction var_to_var_bit_tail_aux1_imp ::\n  \"var_to_var_bit_tail_aux1_state \\<Rightarrow> var_to_var_bit_tail_aux1_state\" where\n  \"var_to_var_bit_tail_aux1_imp s =\n  (let \n      ret = var_to_var_bit_tail_aux1_state_upd s\n    in \n      ret\n  )\"\n  by simp+\ntermination\n  by (relation \"measure var_to_var_bit_tail_aux1_t\") simp\n\ndeclare var_to_var_bit_tail_aux1_imp.simps [simp del]\n\nlemma var_to_var_bit_tail_aux1_imp_correct[let_function_correctness]:\n  \"var_to_var_bit_tail_aux1_ret (var_to_var_bit_tail_aux1_imp s) =\n    var_to_var_bit_tail_aux1 (var_to_var_bit_tail_aux1_t s) (var_to_var_bit_tail_aux1_l s)\"\n  by (simp add: var_to_var_bit_tail_aux1_imp.simps Let_def var_to_var_bit_tail_aux1_state_upd_def\n  length_imp_correct2 dollar_encode_char_val hd_imp_correct EQUAL_neq_zero_imp_correct AND_neq_zero_imp_correct\n  tl_imp_correct prod_encode_imp_correct some_nat_imp_correct) \n\nfunction var_to_var_bit_tail_aux1_imp_time ::\n  \"nat \\<Rightarrow> var_to_var_bit_tail_aux1_state \\<Rightarrow> nat\" where\n  \"var_to_var_bit_tail_aux1_imp_time t s =\n  (let\n      length_xs' = var_to_var_bit_tail_aux1_t s;\n      t = t + 2;\n      length_ret' = 0;\n      t = t + 2;\n      length_state = \\<lparr>length_xs = length_xs',\n                      length_ret = length_ret'\\<rparr>;\n      length_ret_state = length_imp length_state;\n      t = t + length_imp_time 0 length_state;\n      length_result = length_ret length_ret_state;\n      t = t + 2;\n      hd_xs' = var_to_var_bit_tail_aux1_t s;\n      t = t + 2;\n      hd_ret' = 0;\n      t = t + 2;\n      hd_state = \\<lparr>hd_xs = hd_xs',\n                  hd_ret = hd_ret'\\<rparr>;\n      hd_ret_state = hd_imp hd_state;\n      t = t + hd_imp_time 0 hd_state;\n      EQUAL_neq_zero_a' = hd_ret hd_ret_state;\n      t = t + 2;\n      EQUAL_neq_zero_b' = dollar_encode_char_as_nat;\n      t = t + 2;\n      EQUAL_neq_zero_ret' = 0;\n      t = t + 2;\n      EQUAL_neq_zero_state = \\<lparr>EQUAL_neq_zero_a = EQUAL_neq_zero_a',\n                              EQUAL_neq_zero_b = EQUAL_neq_zero_b',\n                              EQUAL_neq_zero_ret = EQUAL_neq_zero_ret'\\<rparr>;\n      EQUAL_neq_zero_ret_state = EQUAL_neq_zero_imp EQUAL_neq_zero_state;\n      t = t + EQUAL_neq_zero_imp_time 0 EQUAL_neq_zero_state;\n      AND_neq_zero_a' = length_result;\n      t = t + 2;\n      AND_neq_zero_b' = EQUAL_neq_zero_ret EQUAL_neq_zero_ret_state;\n      t = t + 2;\n      AND_neq_zero_ret' = 0;\n      t = t + 2;\n      AND_neq_zero_state = \\<lparr>AND_neq_zero_a = AND_neq_zero_a',\n                            AND_neq_zero_b = AND_neq_zero_b',\n                            AND_neq_zero_ret = AND_neq_zero_ret'\\<rparr>;\n      AND_neq_zero_ret_state = AND_neq_zero_imp AND_neq_zero_state;\n      t = t + AND_neq_zero_imp_time 0 AND_neq_zero_state;\n      AND_neq_zero_result = AND_neq_zero_ret AND_neq_zero_ret_state;\n      t = t + 2\n  in\n  (if AND_neq_zero_result \\<noteq> 0 then\n    (let\n      t = t + 1;\n      tl_xs' = var_to_var_bit_tail_aux1_t s;\n      t = t + 2;\n      tl_ret' = 0;\n      t = t + 2;\n      tl_state = \\<lparr>tl_xs = tl_xs',\n                  tl_ret = tl_ret'\\<rparr>;\n      tl_ret_state = tl_imp tl_state;\n      t = t + tl_imp_time 0 tl_state;\n      prod_encode_a' = tl_ret tl_ret_state;\n      t = t + 2;\n      prod_encode_b' = var_to_var_bit_tail_aux1_l s;\n      t = t + 2;\n      prod_encode_ret' = 0;\n      t = t + 2;\n      prod_encode_state = \\<lparr>prod_encode_a = prod_encode_a',\n                           prod_encode_b = prod_encode_b',\n                           prod_encode_ret = prod_encode_ret'\\<rparr>;\n      prod_encode_ret_state = prod_encode_imp prod_encode_state;\n      t = t + prod_encode_imp_time 0 prod_encode_state;\n      some_nat_n' = prod_encode_ret prod_encode_ret_state;\n      t = t + 2;\n      some_nat_ret' = 0;\n      t = t + 2;\n      some_nat_state = \\<lparr>some_nat_n = some_nat_n',\n                        some_nat_ret = some_nat_ret'\\<rparr>;\n      some_nat_ret_state = some_nat_imp some_nat_state;\n      t = t + some_nat_imp_time 0 some_nat_state;\n      var_to_var_bit_tail_aux1_ret' = some_nat_ret some_nat_ret_state;\n      t = t + 2;\n      ret = \\<lparr>var_to_var_bit_tail_aux1_t = var_to_var_bit_tail_aux1_t s,\n             var_to_var_bit_tail_aux1_l = var_to_var_bit_tail_aux1_l s,\n             var_to_var_bit_tail_aux1_ret = var_to_var_bit_tail_aux1_ret'\\<rparr>\n    in\n      t\n    )\n  else\n    (let\n      t = t + 1;\n      var_to_var_bit_tail_aux1_ret' = 0;\n      t = t + 2;\n      ret = \\<lparr>var_to_var_bit_tail_aux1_t = var_to_var_bit_tail_aux1_t s,\n             var_to_var_bit_tail_aux1_l = var_to_var_bit_tail_aux1_l s,\n             var_to_var_bit_tail_aux1_ret = var_to_var_bit_tail_aux1_ret'\\<rparr>\n    in\n      t\n    )\n  )\n)\"\n  by auto\ntermination\n  by (relation \"measure (var_to_var_bit_tail_aux1_t \\<circ> snd)\") simp\n\ndeclare var_to_var_bit_tail_aux1_imp_time.simps [simp del]\n\nlemma var_to_var_bit_tail_aux1_imp_time_acc:\n  \"(var_to_var_bit_tail_aux1_imp_time (Suc t) s) = Suc (var_to_var_bit_tail_aux1_imp_time t s)\"\n  by (induction t s rule: var_to_var_bit_tail_aux1_imp_time.induct)\n    ((subst (1 2) var_to_var_bit_tail_aux1_imp_time.simps);\n      (simp add: var_to_var_bit_tail_aux1_state_upd_def Let_def))            \n\nlemma var_to_var_bit_tail_aux1_imp_time_acc_2_aux:\n  \"(var_to_var_bit_tail_aux1_imp_time t s) = t + (var_to_var_bit_tail_aux1_imp_time 0 s)\"\n  by (induction t arbitrary: s) (simp add: var_to_var_bit_tail_aux1_imp_time_acc)+            \n\nlemma var_to_var_bit_tail_aux1_imp_time_acc_2:\n  \"t \\<noteq> 0 \\<Longrightarrow> (var_to_var_bit_tail_aux1_imp_time t s) = t + (var_to_var_bit_tail_aux1_imp_time 0 s)\"\n  by (rule var_to_var_bit_tail_aux1_imp_time_acc_2_aux)            \n\nlemma var_to_var_bit_tail_aux1_imp_time_acc_3:\n  \"(var_to_var_bit_tail_aux1_imp_time (a + b) s) = a + (var_to_var_bit_tail_aux1_imp_time b s)\"\n  by (induction a arbitrary: b s) (simp add: var_to_var_bit_tail_aux1_imp_time_acc)+ \n\nabbreviation \"var_to_var_bit_tail_aux1_length_result \\<equiv> ''length_result''\"\nabbreviation \"var_to_var_bit_tail_aux1_AND_neq_zero_result \\<equiv> ''AND_neq_zero_result''\"\n\nabbreviation \"var_to_var_bit_tail_aux1_IMP_if \\<equiv>\n  \\<comment> \\<open>  tl_xs' = var_to_var_bit_tail_aux1_t s;\\<close>\n  (tl_prefix @ tl_xs_str) ::= (A (V var_to_var_bit_tail_aux1_t_str));;\n  \\<comment> \\<open>  tl_ret' = 0;\\<close>\n  (tl_prefix @ tl_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  tl_state = \\<lparr>tl_xs = tl_xs',\\<close>\n  \\<comment> \\<open>              tl_ret = tl_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  tl_ret_state = tl_imp tl_state;\\<close>\n  (invoke_subprogram tl_prefix tl_IMP_Minus);;\n  \\<comment> \\<open>  prod_encode_a' = tl_ret tl_ret_state;\\<close>\n  (prod_encode_prefix @ prod_encode_a_str) ::= (A (V (tl_prefix @ tl_ret_str)));;\n  \\<comment> \\<open>  prod_encode_b' = var_to_var_bit_tail_aux1_l s;\\<close>\n  (prod_encode_prefix @ prod_encode_b_str) ::= (A (V var_to_var_bit_tail_aux1_l_str));;\n  \\<comment> \\<open>  prod_encode_ret' = 0;\\<close>\n  (prod_encode_prefix @ prod_encode_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  prod_encode_state = \\<lparr>prod_encode_a = prod_encode_a',\\<close>\n  \\<comment> \\<open>                       prod_encode_b = prod_encode_b',\\<close>\n  \\<comment> \\<open>                       prod_encode_ret = prod_encode_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  prod_encode_ret_state = prod_encode_imp prod_encode_state;\\<close>\n  (invoke_subprogram prod_encode_prefix prod_encode_IMP_Minus);;\n  \\<comment> \\<open>  some_nat_n' = prod_encode_ret prod_encode_ret_state;\\<close>\n  (some_nat_prefix @ some_nat_n_str) ::= (A (V (prod_encode_prefix @ prod_encode_ret_str)));;\n  \\<comment> \\<open>  some_nat_ret' = 0;\\<close>\n  (some_nat_prefix @ some_nat_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  some_nat_state = \\<lparr>some_nat_n = some_nat_n',\\<close>\n  \\<comment> \\<open>                    some_nat_ret = some_nat_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  some_nat_ret_state = some_nat_imp some_nat_state;\\<close>\n  (invoke_subprogram some_nat_prefix some_nat_IMP_Minus);;\n  \\<comment> \\<open>  var_to_var_bit_tail_aux1_ret' = some_nat_ret some_nat_ret_state;\\<close>\n  (var_to_var_bit_tail_aux1_ret_str) ::= (A (V (some_nat_prefix @ some_nat_ret_str)))\n  \\<comment> \\<open>  ret = \\<lparr>var_to_var_bit_tail_aux1_t = var_to_var_bit_tail_aux1_t s,\\<close>\n  \\<comment> \\<open>         var_to_var_bit_tail_aux1_l = var_to_var_bit_tail_aux1_l s,\\<close>\n  \\<comment> \\<open>         var_to_var_bit_tail_aux1_ret = var_to_var_bit_tail_aux1_ret'\\<rparr>\\<close>\n\"\n\nabbreviation \"var_to_var_bit_tail_aux1_IMP_else \\<equiv>\n  \\<comment> \\<open>  var_to_var_bit_tail_aux1_ret' = 0;\\<close>\n  (var_to_var_bit_tail_aux1_ret_str) ::= (A (N 0))\n  \\<comment> \\<open>  ret = \\<lparr>var_to_var_bit_tail_aux1_t = var_to_var_bit_tail_aux1_t s,\\<close>\n  \\<comment> \\<open>         var_to_var_bit_tail_aux1_l = var_to_var_bit_tail_aux1_l s,\\<close>\n  \\<comment> \\<open>         var_to_var_bit_tail_aux1_ret = var_to_var_bit_tail_aux1_ret'\\<rparr>\\<close>\n\"\n\ndefinition var_to_var_bit_tail_aux1_IMP_Minus where\n  \"var_to_var_bit_tail_aux1_IMP_Minus \\<equiv>\n  \\<comment> \\<open>  length_xs' = var_to_var_bit_tail_aux1_t s;\\<close>\n  (length_prefix @ length_xs_str) ::= (A (V var_to_var_bit_tail_aux1_t_str));;\n  \\<comment> \\<open>  length_ret' = 0;\\<close>\n  (length_prefix @ length_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  length_state = \\<lparr>length_xs = length_xs',\\<close>\n  \\<comment> \\<open>                  length_ret = length_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  length_ret_state = length_imp length_state;\\<close>\n  (invoke_subprogram length_prefix length_IMP_Minus);;\n  \\<comment> \\<open>  length_result = length_ret length_ret_state;\\<close>\n  (var_to_var_bit_tail_aux1_length_result) ::= (A (V (length_prefix @ length_ret_str)));;\n  \\<comment> \\<open>  hd_xs' = var_to_var_bit_tail_aux1_t s;\\<close>\n  (hd_prefix @ hd_xs_str) ::= (A (V var_to_var_bit_tail_aux1_t_str));;\n  \\<comment> \\<open>  hd_ret' = 0;\\<close>\n  (hd_prefix @ hd_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  hd_state = \\<lparr>hd_xs = hd_xs',\\<close>\n  \\<comment> \\<open>              hd_ret = hd_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  hd_ret_state = hd_imp hd_state;\\<close>\n  (invoke_subprogram hd_prefix hd_IMP_Minus);;\n  \\<comment> \\<open>  EQUAL_neq_zero_a' = hd_ret hd_ret_state;\\<close>\n  (EQUAL_neq_zero_prefix @ EQUAL_neq_zero_a_str) ::= (A (V (hd_prefix @ hd_ret_str)));;\n  \\<comment> \\<open>  EQUAL_neq_zero_b' = dollar_encode_char_as_nat;\\<close>\n  (EQUAL_neq_zero_prefix @ EQUAL_neq_zero_b_str) ::= (A (N dollar_encode_char_as_nat));;\n  \\<comment> \\<open>  EQUAL_neq_zero_ret' = 0;\\<close>\n  (EQUAL_neq_zero_prefix @ EQUAL_neq_zero_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  EQUAL_neq_zero_state = \\<lparr>EQUAL_neq_zero_a = EQUAL_neq_zero_a',\\<close>\n  \\<comment> \\<open>                          EQUAL_neq_zero_b = EQUAL_neq_zero_b',\\<close>\n  \\<comment> \\<open>                          EQUAL_neq_zero_ret = EQUAL_neq_zero_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  EQUAL_neq_zero_ret_state = EQUAL_neq_zero_imp EQUAL_neq_zero_state;\\<close>\n  (invoke_subprogram EQUAL_neq_zero_prefix EQUAL_neq_zero_IMP_Minus);;\n  \\<comment> \\<open>  AND_neq_zero_a' = length_result;\\<close>\n  (AND_neq_zero_prefix @ AND_neq_zero_a_str) ::= (A (V var_to_var_bit_tail_aux1_length_result));;\n  \\<comment> \\<open>  AND_neq_zero_b' = EQUAL_neq_zero_ret EQUAL_neq_zero_ret_state;\\<close>\n  (AND_neq_zero_prefix @ AND_neq_zero_b_str) ::= (A (V (EQUAL_neq_zero_prefix @ EQUAL_neq_zero_ret_str)));;\n  \\<comment> \\<open>  AND_neq_zero_ret' = 0;\\<close>\n  (AND_neq_zero_prefix @ AND_neq_zero_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  AND_neq_zero_state = \\<lparr>AND_neq_zero_a = AND_neq_zero_a',\\<close>\n  \\<comment> \\<open>                        AND_neq_zero_b = AND_neq_zero_b',\\<close>\n  \\<comment> \\<open>                        AND_neq_zero_ret = AND_neq_zero_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  AND_neq_zero_ret_state = AND_neq_zero_imp AND_neq_zero_state;\\<close>\n  (invoke_subprogram AND_neq_zero_prefix AND_neq_zero_IMP_Minus);;\n  \\<comment> \\<open>  AND_neq_zero_result = AND_neq_zero_ret AND_neq_zero_ret_state\\<close>\n  (var_to_var_bit_tail_aux1_AND_neq_zero_result) ::= (A (V (AND_neq_zero_prefix @ AND_neq_zero_ret_str)));;\n  \\<comment> \\<open>(if AND_neq_zero_result \\<noteq> 0 then\\<close>\n  (IF var_to_var_bit_tail_aux1_AND_neq_zero_result \\<noteq>0 THEN\n    var_to_var_bit_tail_aux1_IMP_if\n  \\<comment> \\<open>else\\<close>\n  ELSE\n    var_to_var_bit_tail_aux1_IMP_else\n  )\n\"\n\nabbreviation \"var_to_var_bit_tail_aux1_IMP_vars \\<equiv>\n  {var_to_var_bit_tail_aux1_t_str, var_to_var_bit_tail_aux1_l_str, var_to_var_bit_tail_aux1_ret_str, \n  var_to_var_bit_tail_aux1_length_result, var_to_var_bit_tail_aux1_AND_neq_zero_result}\"\n\ndefinition \"var_to_var_bit_tail_aux1_imp_to_HOL_state p s =\n  \\<lparr>var_to_var_bit_tail_aux1_t = (s (add_prefix p var_to_var_bit_tail_aux1_t_str)),\n   var_to_var_bit_tail_aux1_l = (s (add_prefix p var_to_var_bit_tail_aux1_l_str)),\n   var_to_var_bit_tail_aux1_ret = (s (add_prefix p var_to_var_bit_tail_aux1_ret_str))\\<rparr>\"\n\nlemmas var_to_var_bit_tail_aux1_state_translators =\n  var_to_var_bit_tail_aux1_imp_to_HOL_state_def\n  length_imp_to_HOL_state_def\n  hd_imp_to_HOL_state_def\n  EQUAL_neq_zero_imp_to_HOL_state_def\n  AND_neq_zero_imp_to_HOL_state_def\n  tl_imp_to_HOL_state_def\n  prod_encode_imp_to_HOL_state_def\n  some_nat_imp_to_HOL_state_def\n\nlemma var_to_var_bit_tail_aux1_IMP_Minus_correct_function:\n  \"(invoke_subprogram p var_to_var_bit_tail_aux1_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p var_to_var_bit_tail_aux1_ret_str)\n      = var_to_var_bit_tail_aux1_ret\n          (var_to_var_bit_tail_aux1_imp (var_to_var_bit_tail_aux1_imp_to_HOL_state p s))\"\n  apply(subst var_to_var_bit_tail_aux1_imp.simps)\n  apply(simp only: var_to_var_bit_tail_aux1_IMP_Minus_def prefix_simps)\n  apply(erule Seq_E)+\n  apply(erule length_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux1_IMP_vars\"])\n  subgoal premises p using p(17) by fastforce\n  apply(erule hd_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux1_IMP_vars\"])\n  subgoal premises p using p(19) by fastforce\n  apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux1_IMP_vars\"])\n  subgoal premises p using p(21) by fastforce\n  apply(erule AND_neq_zero_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux1_IMP_vars\"])\n  subgoal premises p using p(23) by fastforce\n  apply(erule If_E)\n  subgoal\n    apply(erule Seq_E)+\n    apply(erule tl_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux1_IMP_vars\"])\n    subgoal premises p using p(36) by fastforce\n    apply(erule prod_encode_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux1_IMP_vars\"])\n    subgoal premises p using p(38) by fastforce\n    apply(erule some_nat_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux1_IMP_vars\"])\n    subgoal premises p using p(40) by fastforce\n    by (fastforce_sorted_premises2 simp: var_to_var_bit_tail_aux1_state_translators Let_def\n        var_to_var_bit_tail_aux1_state_upd_def)\n  subgoal\n    by (fastforce_sorted_premises2 simp: var_to_var_bit_tail_aux1_state_translators Let_def\n        var_to_var_bit_tail_aux1_state_upd_def)\n  done\n\nlemma var_to_var_bit_tail_aux1_IMP_Minus_correct_effects:\n  \"\\<lbrakk>(invoke_subprogram (p @ var_to_var_bit_tail_aux1_pref) var_to_var_bit_tail_aux1_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    v \\<in> vars; \\<not> (prefix var_to_var_bit_tail_aux1_pref v)\\<rbrakk>\n   \\<Longrightarrow> s (add_prefix p v) = s' (add_prefix p v)\"\n  using com_add_prefix_valid'' com_only_vars prefix_def\n  by blast\n\nlemma var_to_var_bit_tail_aux1_IMP_Minus_correct_time:\n  \"(invoke_subprogram p var_to_var_bit_tail_aux1_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = var_to_var_bit_tail_aux1_imp_time 0 (var_to_var_bit_tail_aux1_imp_to_HOL_state p s)\"\n  apply(subst var_to_var_bit_tail_aux1_imp_time.simps)\n  apply(simp only: var_to_var_bit_tail_aux1_IMP_Minus_def prefix_simps)\n  apply(erule Seq_tE)+\n  apply(erule length_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux1_IMP_vars\"])\n  subgoal premises p using p(33) by fastforce\n  apply(erule hd_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux1_IMP_vars\"])\n  subgoal premises p using p(35) by fastforce\n  apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux1_IMP_vars\"])\n  subgoal premises p using p(37) by fastforce\n  apply(erule AND_neq_zero_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux1_IMP_vars\"])\n  subgoal premises p using p(39) by fastforce\n  apply(erule If_tE)\n  subgoal\n    apply(erule Seq_tE)+\n    apply(erule tl_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux1_IMP_vars\"])\n    subgoal premises p using p(63) by fastforce\n    apply(erule prod_encode_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux1_IMP_vars\"])\n    subgoal premises p using p(65) by fastforce\n    apply(erule some_nat_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux1_IMP_vars\"])\n    subgoal premises p using p(67) by fastforce\n    by (fastforce_sorted_premises2 simp: Let_def var_to_var_bit_tail_aux1_state_translators)\n  subgoal\n    by (fastforce_sorted_premises2 simp: Let_def var_to_var_bit_tail_aux1_state_translators)\n  done \n\nlemma var_to_var_bit_tail_aux1_IMP_Minus_correct:\n  \"\\<lbrakk>(invoke_subprogram (p1 @ p2) var_to_var_bit_tail_aux1_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    \\<And>v. v \\<in> vars \\<Longrightarrow> \\<not> (set p2 \\<subseteq> set v);\n    \\<lbrakk>t = (var_to_var_bit_tail_aux1_imp_time 0 (var_to_var_bit_tail_aux1_imp_to_HOL_state (p1 @ p2) s));\n     s' (add_prefix (p1 @ p2) var_to_var_bit_tail_aux1_ret_str) =\n          var_to_var_bit_tail_aux1_ret (var_to_var_bit_tail_aux1_imp\n                                        (var_to_var_bit_tail_aux1_imp_to_HOL_state (p1 @ p2) s));\n     \\<And>v. v \\<in> vars \\<Longrightarrow> s (add_prefix p1 v) = s' (add_prefix p1 v)\\<rbrakk>\n   \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  using var_to_var_bit_tail_aux1_IMP_Minus_correct_function\n    var_to_var_bit_tail_aux1_IMP_Minus_correct_time\n    var_to_var_bit_tail_aux1_IMP_Minus_correct_effects\n  by (meson set_mono_prefix)\n\nsubsubsection \\<open>var_to_var_bit_tail_aux2\\<close>\n\nfun var_to_var_bit_tail_aux2 :: \"nat \\<Rightarrow> nat\" where\n  \"var_to_var_bit_tail_aux2 v = \n    (if hd_nat v = encode_char (CHR ''#'')\n     then var_to_var_bit_tail_aux1 (dropWhile_char v) (length_nat (takeWhile_char_tail v) - 1)\n     else 0\n  )\"\n\nlemma var_to_var_bit_tail_aux2_correct: \n  \"var_to_var_bit_tail_aux2 v =\n  (if hd_nat v = encode_char (CHR ''#'')\n   then (let t = dropWhile_char v;\n             l = length_nat (takeWhile_char_tail v) - 1\n         in (if length_nat t > 0 \\<and> hd_nat t = encode_char (CHR ''$'')\n             then some_nat (prod_encode(tl_nat t, l))\n             else 0))\n   else 0)\"\n  using var_to_var_bit_tail_aux1_correct\n  by (smt (verit, best) var_to_var_bit_tail_aux2.elims)\n\nrecord var_to_var_bit_tail_aux2_state =\n  var_to_var_bit_tail_aux2_v::nat\n  var_to_var_bit_tail_aux2_ret::nat\n\nabbreviation \"var_to_var_bit_tail_aux2_prefix \\<equiv> ''var_to_var_bit_tail_aux2.''\"\nabbreviation \"var_to_var_bit_tail_aux2_v_str \\<equiv> ''v''\"\nabbreviation \"var_to_var_bit_tail_aux2_ret_str \\<equiv> ''ret''\"\n\ndefinition \"var_to_var_bit_tail_aux2_state_upd s \\<equiv>\n  (let\n      hd_xs' = var_to_var_bit_tail_aux2_v s;\n      hd_ret' = 0;\n      hd_state = \\<lparr>hd_xs = hd_xs',\n                  hd_ret = hd_ret'\\<rparr>;\n      hd_ret_state = hd_imp hd_state;\n      EQUAL_neq_zero_a' = hd_ret hd_ret_state;\n      EQUAL_neq_zero_b' = hash_encode_char_as_nat;\n      EQUAL_neq_zero_ret' = 0;\n      EQUAL_neq_zero_state = \\<lparr>EQUAL_neq_zero_a = EQUAL_neq_zero_a',\n                              EQUAL_neq_zero_b = EQUAL_neq_zero_b',\n                              EQUAL_neq_zero_ret = EQUAL_neq_zero_ret'\\<rparr>;\n      EQUAL_neq_zero_ret_state = EQUAL_neq_zero_imp EQUAL_neq_zero_state;\n      EQUAL_neq_zero_result = EQUAL_neq_zero_ret EQUAL_neq_zero_ret_state\n  in\n  (if EQUAL_neq_zero_result \\<noteq> 0 then\n    (let\n      dropWhile_char_n' = var_to_var_bit_tail_aux2_v s;\n      dropWhile_char_ret' = 0;\n      dropWhile_char_state = \\<lparr>dropWhile_char_n = dropWhile_char_n',\n                              dropWhile_char_ret = dropWhile_char_ret'\\<rparr>;\n      dropWhile_char_ret_state = dropWhile_char_imp dropWhile_char_state;\n      dropWhile_char_result = dropWhile_char_ret dropWhile_char_ret_state;\n      takeWhile_char_tail_ys' = var_to_var_bit_tail_aux2_v s;\n      takeWhile_char_tail_ret' = 0;\n      takeWhile_char_tail_state = \\<lparr>takeWhile_char_tail_ys = takeWhile_char_tail_ys',\n                                   takeWhile_char_tail_ret = takeWhile_char_tail_ret'\\<rparr>;\n      takeWhile_char_tail_ret_state = takeWhile_char_tail_imp takeWhile_char_tail_state;\n      length_xs' = takeWhile_char_tail_ret takeWhile_char_tail_ret_state;\n      length_ret' = 0;\n      length_state = \\<lparr>length_xs = length_xs',\n                      length_ret = length_ret'\\<rparr>;\n      length_ret_state = length_imp length_state;\n      var_to_var_bit_tail_aux1_t' = dropWhile_char_result;\n      var_to_var_bit_tail_aux1_l' = length_ret length_ret_state - 1;\n      var_to_var_bit_tail_aux1_ret' = 0;\n      var_to_var_bit_tail_aux1_state = \\<lparr>var_to_var_bit_tail_aux1_t = var_to_var_bit_tail_aux1_t',\n                                        var_to_var_bit_tail_aux1_l = var_to_var_bit_tail_aux1_l',\n                                        var_to_var_bit_tail_aux1_ret = var_to_var_bit_tail_aux1_ret'\\<rparr>;\n      var_to_var_bit_tail_aux1_ret_state = var_to_var_bit_tail_aux1_imp var_to_var_bit_tail_aux1_state;\n      var_to_var_bit_tail_aux2_ret' = var_to_var_bit_tail_aux1_ret var_to_var_bit_tail_aux1_ret_state;\n      ret = \\<lparr>var_to_var_bit_tail_aux2_v = var_to_var_bit_tail_aux2_v s,\n             var_to_var_bit_tail_aux2_ret = var_to_var_bit_tail_aux2_ret'\\<rparr>\n    in\n      ret\n    )\n  else\n    (let\n      var_to_var_bit_tail_aux2_ret' = 0;\n      ret = \\<lparr>var_to_var_bit_tail_aux2_v = var_to_var_bit_tail_aux2_v s,\n             var_to_var_bit_tail_aux2_ret = var_to_var_bit_tail_aux2_ret'\\<rparr>\n    in\n      ret\n    )\n  )\n)\"\n\nfunction var_to_var_bit_tail_aux2_imp ::\n  \"var_to_var_bit_tail_aux2_state \\<Rightarrow> var_to_var_bit_tail_aux2_state\" where\n  \"var_to_var_bit_tail_aux2_imp s =\n  (let \n      ret = var_to_var_bit_tail_aux2_state_upd s\n    in \n      ret\n  )\"\n  by simp+\ntermination\n  by (relation \"measure var_to_var_bit_tail_aux2_v\") simp\n\ndeclare var_to_var_bit_tail_aux2_imp.simps [simp del]\n\nlemma var_to_var_bit_tail_aux2_imp_correct[let_function_correctness]:\n  \"var_to_var_bit_tail_aux2_ret (var_to_var_bit_tail_aux2_imp s) =\n    var_to_var_bit_tail_aux2 (var_to_var_bit_tail_aux2_v s)\"\n  apply (simp only: var_to_var_bit_tail_aux2_imp.simps Let_def var_to_var_bit_tail_aux2_state_upd_def\n  hd_imp_correct hash_encode_char_val EQUAL_neq_zero_imp_correct dropWhile_char_imp_correct\n  takeWhile_char_tail_imp_correct length_imp_correct2 var_to_var_bit_tail_aux1_imp_correct\n  var_to_var_bit_tail_aux2.simps)\n  by (smt (verit, best) EQUAL_neq_zero_state.select_convs(1) EQUAL_neq_zero_state.select_convs(2)\n  dropWhile_char'_correct dropWhile_char_state.select_convs(1) hd_state.select_convs(1) length_imp_correct\n  length_state.select_convs(1) length_state.select_convs(2) minus_nat.diff_0\n  takeWhile_char_tail_state.select_convs(1) var_to_var_bit_tail_aux1_state.select_convs(1)\n  var_to_var_bit_tail_aux1_state.select_convs(2) var_to_var_bit_tail_aux2_state.select_convs(2) zero_neq_one)  \n\nfunction var_to_var_bit_tail_aux2_imp_time ::\n  \"nat \\<Rightarrow> var_to_var_bit_tail_aux2_state \\<Rightarrow> nat\" where\n  \"var_to_var_bit_tail_aux2_imp_time t s =\n  (let\n      hd_xs' = var_to_var_bit_tail_aux2_v s;\n      t = t + 2;\n      hd_ret' = 0;\n      t = t + 2;\n      hd_state = \\<lparr>hd_xs = hd_xs',\n                  hd_ret = hd_ret'\\<rparr>;\n      hd_ret_state = hd_imp hd_state;\n      t = t + hd_imp_time 0 hd_state;\n      EQUAL_neq_zero_a' = hd_ret hd_ret_state;\n      t = t + 2;\n      EQUAL_neq_zero_b' = hash_encode_char_as_nat;\n      t = t + 2;\n      EQUAL_neq_zero_ret' = 0;\n      t = t + 2;\n      EQUAL_neq_zero_state = \\<lparr>EQUAL_neq_zero_a = EQUAL_neq_zero_a',\n                              EQUAL_neq_zero_b = EQUAL_neq_zero_b',\n                              EQUAL_neq_zero_ret = EQUAL_neq_zero_ret'\\<rparr>;\n      EQUAL_neq_zero_ret_state = EQUAL_neq_zero_imp EQUAL_neq_zero_state;\n      t = t + EQUAL_neq_zero_imp_time 0 EQUAL_neq_zero_state;\n      EQUAL_neq_zero_result = EQUAL_neq_zero_ret EQUAL_neq_zero_ret_state;\n      t = t + 2\n  in\n  (if EQUAL_neq_zero_result \\<noteq> 0 then\n    (let\n      t = t + 1;\n      dropWhile_char_n' = var_to_var_bit_tail_aux2_v s;\n      t = t + 2;\n      dropWhile_char_ret' = 0;\n      t = t + 2;\n      dropWhile_char_state = \\<lparr>dropWhile_char_n = dropWhile_char_n',\n                              dropWhile_char_ret = dropWhile_char_ret'\\<rparr>;\n      dropWhile_char_ret_state = dropWhile_char_imp dropWhile_char_state;\n      t = t + dropWhile_char_imp_time 0 dropWhile_char_state;\n      dropWhile_char_result = dropWhile_char_ret dropWhile_char_ret_state;\n      t = t + 2;\n      takeWhile_char_tail_ys' = var_to_var_bit_tail_aux2_v s;\n      t = t + 2;\n      takeWhile_char_tail_ret' = 0;\n      t = t + 2;\n      takeWhile_char_tail_state = \\<lparr>takeWhile_char_tail_ys = takeWhile_char_tail_ys',\n                                   takeWhile_char_tail_ret = takeWhile_char_tail_ret'\\<rparr>;\n      takeWhile_char_tail_ret_state = takeWhile_char_tail_imp takeWhile_char_tail_state;\n      t = t + takeWhile_char_tail_imp_time 0 takeWhile_char_tail_state;\n      length_xs' = takeWhile_char_tail_ret takeWhile_char_tail_ret_state;\n      t = t + 2;\n      length_ret' = 0;\n      t = t + 2;\n      length_state = \\<lparr>length_xs = length_xs',\n                      length_ret = length_ret'\\<rparr>;\n      length_ret_state = length_imp length_state;\n      t = t + length_imp_time 0 length_state;\n      var_to_var_bit_tail_aux1_t' = dropWhile_char_result;\n      t = t + 2;\n      var_to_var_bit_tail_aux1_l' = length_ret length_ret_state - 1;\n      t = t + 2;\n      var_to_var_bit_tail_aux1_ret' = 0;\n      t = t + 2;\n      var_to_var_bit_tail_aux1_state = \\<lparr>var_to_var_bit_tail_aux1_t = var_to_var_bit_tail_aux1_t',\n                                        var_to_var_bit_tail_aux1_l = var_to_var_bit_tail_aux1_l',\n                                        var_to_var_bit_tail_aux1_ret = var_to_var_bit_tail_aux1_ret'\\<rparr>;\n      var_to_var_bit_tail_aux1_ret_state = var_to_var_bit_tail_aux1_imp var_to_var_bit_tail_aux1_state;\n      t = t + var_to_var_bit_tail_aux1_imp_time 0 var_to_var_bit_tail_aux1_state;\n      var_to_var_bit_tail_aux2_ret' = var_to_var_bit_tail_aux1_ret var_to_var_bit_tail_aux1_ret_state;\n      t = t + 2;\n      ret = \\<lparr>var_to_var_bit_tail_aux2_v = var_to_var_bit_tail_aux2_v s,\n             var_to_var_bit_tail_aux2_ret = var_to_var_bit_tail_aux2_ret'\\<rparr>\n    in\n      t\n    )\n  else\n    (let\n      t = t + 1;\n      var_to_var_bit_tail_aux2_ret' = 0;\n      t = t + 2;\n      ret = \\<lparr>var_to_var_bit_tail_aux2_v = var_to_var_bit_tail_aux2_v s,\n             var_to_var_bit_tail_aux2_ret = var_to_var_bit_tail_aux2_ret'\\<rparr>\n    in\n      t\n    )\n  )\n)\"\n  by auto\ntermination\n  by (relation \"measure (var_to_var_bit_tail_aux2_v \\<circ> snd)\") simp\n\ndeclare var_to_var_bit_tail_aux2_imp_time.simps [simp del]\n\nlemma var_to_var_bit_tail_aux2_imp_time_acc:\n  \"(var_to_var_bit_tail_aux2_imp_time (Suc t) s) = Suc (var_to_var_bit_tail_aux2_imp_time t s)\"\n  by (induction t s rule: var_to_var_bit_tail_aux2_imp_time.induct)\n    ((subst (1 2) var_to_var_bit_tail_aux2_imp_time.simps);\n      (simp add: var_to_var_bit_tail_aux2_state_upd_def Let_def))            \n\nlemma var_to_var_bit_tail_aux2_imp_time_acc_2_aux:\n  \"(var_to_var_bit_tail_aux2_imp_time t s) = t + (var_to_var_bit_tail_aux2_imp_time 0 s)\"\n  by (induction t arbitrary: s) (simp add: var_to_var_bit_tail_aux2_imp_time_acc)+            \n\nlemma var_to_var_bit_tail_aux2_imp_time_acc_2:\n  \"t \\<noteq> 0 \\<Longrightarrow> (var_to_var_bit_tail_aux2_imp_time t s) = t + (var_to_var_bit_tail_aux2_imp_time 0 s)\"\n  by (rule var_to_var_bit_tail_aux2_imp_time_acc_2_aux)            \n\nlemma var_to_var_bit_tail_aux2_imp_time_acc_3:\n  \"(var_to_var_bit_tail_aux2_imp_time (a + b) s) = a + (var_to_var_bit_tail_aux2_imp_time b s)\"\n  by (induction a arbitrary: b s) (simp add: var_to_var_bit_tail_aux2_imp_time_acc)+  \n\nabbreviation \"var_to_var_bit_tail_aux2_EQUAL_neq_zero_result \\<equiv> ''EQUAL_neq_zero_result''\"\nabbreviation \"var_to_var_bit_tail_aux2_dropWhile_char_result \\<equiv> ''dropWhile_char_result''\"\n\nabbreviation \"var_to_var_bit_tail_aux2_IMP_if \\<equiv>\n  \\<comment> \\<open>  dropWhile_char_n' = var_to_var_bit_tail_aux2_v s;\\<close>\n  (dropWhile_char_prefix @ dropWhile_char_n_str) ::= (A (V var_to_var_bit_tail_aux2_v_str));;\n  \\<comment> \\<open>  dropWhile_char_ret' = 0;\\<close>\n  (dropWhile_char_prefix @ dropWhile_char_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  dropWhile_char_state = \\<lparr>dropWhile_char_n = dropWhile_char_n',\\<close>\n  \\<comment> \\<open>                          dropWhile_char_ret = dropWhile_char_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  dropWhile_char_ret_state = dropWhile_char_imp dropWhile_char_state;\\<close>\n  (invoke_subprogram dropWhile_char_prefix dropWhile_char_IMP_Minus);;\n  \\<comment> \\<open>  dropWhile_char_result = dropWhile_char_ret dropWhile_char_ret_state;\\<close>\n  (var_to_var_bit_tail_aux2_dropWhile_char_result) ::=\n    (A (V (dropWhile_char_prefix @ dropWhile_char_ret_str)));;\n  \\<comment> \\<open>  takeWhile_char_tail_ys' = var_to_var_bit_tail_aux2_v s;\\<close>\n  (takeWhile_char_tail_prefix @ takeWhile_char_tail_ys_str) ::= (A (V var_to_var_bit_tail_aux2_v_str));;\n  \\<comment> \\<open>  takeWhile_char_tail_ret' = 0;\\<close>\n  (takeWhile_char_tail_prefix @ takeWhile_char_tail_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  takeWhile_char_tail_state = \\<lparr>takeWhile_char_tail_ys = takeWhile_char_tail_ys',\\<close>\n  \\<comment> \\<open>                               takeWhile_char_tail_ret = takeWhile_char_tail_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  takeWhile_char_tail_ret_state = takeWhile_char_tail_imp takeWhile_char_tail_state;\\<close>\n  (invoke_subprogram takeWhile_char_tail_prefix takeWhile_char_tail_IMP_Minus);;\n  \\<comment> \\<open>  length_xs' = takeWhile_char_tail_ret takeWhile_char_tail_ret_state;\\<close>\n  (length_prefix @ length_xs_str) ::= (A (V (takeWhile_char_tail_prefix @ takeWhile_char_tail_ret_str)));;\n  \\<comment> \\<open>  length_ret' = 0;\\<close>\n  (length_prefix @ length_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  length_state = \\<lparr>length_xs = length_xs',\\<close>\n  \\<comment> \\<open>                  length_ret = length_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  length_ret_state = length_imp length_state;\\<close>\n  (invoke_subprogram length_prefix length_IMP_Minus);;\n  \\<comment> \\<open>  var_to_var_bit_tail_aux1_t' = dropWhile_char_result;\\<close>\n  (var_to_var_bit_tail_aux1_prefix @ var_to_var_bit_tail_aux1_t_str) ::=\n    (A (V var_to_var_bit_tail_aux2_dropWhile_char_result));; \n  \\<comment> \\<open>  var_to_var_bit_tail_aux1_l' = length_ret length_ret_state - 1;\\<close>\n  (var_to_var_bit_tail_aux1_prefix @ var_to_var_bit_tail_aux1_l_str) ::=\n    (Sub (V (length_prefix @ length_ret_str)) (N 1));;\n  \\<comment> \\<open>  var_to_var_bit_tail_aux1_ret' = 0;\\<close>\n  (var_to_var_bit_tail_aux1_prefix @ var_to_var_bit_tail_aux1_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  var_to_var_bit_tail_aux1_state = \\<lparr>var_to_var_bit_tail_aux1_t = var_to_var_bit_tail_aux1_t',\\<close>\n  \\<comment> \\<open>                                    var_to_var_bit_tail_aux1_l = var_to_var_bit_tail_aux1_l',\\<close>\n  \\<comment> \\<open>                                    var_to_var_bit_tail_aux1_ret = var_to_var_bit_tail_aux1_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  var_to_var_bit_tail_aux1_ret_state = var_to_var_bit_tail_aux1_imp var_to_var_bit_tail_aux1_state;\\<close>\n  (invoke_subprogram var_to_var_bit_tail_aux1_prefix var_to_var_bit_tail_aux1_IMP_Minus);;\n  \\<comment> \\<open>  var_to_var_bit_tail_aux2_ret' = var_to_var_bit_tail_aux1_ret var_to_var_bit_tail_aux1_ret_state;\\<close>\n  (var_to_var_bit_tail_aux2_ret_str) ::=\n    (A (V (var_to_var_bit_tail_aux1_prefix @ var_to_var_bit_tail_aux1_ret_str)))\n  \\<comment> \\<open>  ret = \\<lparr>var_to_var_bit_tail_aux2_v = var_to_var_bit_tail_aux2_v s,\\<close>\n  \\<comment> \\<open>         var_to_var_bit_tail_aux2_ret = var_to_var_bit_tail_aux2_ret'\\<rparr>\\<close>\n\"\n\nabbreviation \"var_to_var_bit_tail_aux2_IMP_else \\<equiv>\n  \\<comment> \\<open>  var_to_var_bit_tail_aux2_ret' = 0;\\<close>\n  (var_to_var_bit_tail_aux2_ret_str) ::= (A (N 0))\n  \\<comment> \\<open>  ret = \\<lparr>var_to_var_bit_tail_aux2_v = var_to_var_bit_tail_aux2_v s,\\<close>\n  \\<comment> \\<open>         var_to_var_bit_tail_aux2_ret = var_to_var_bit_tail_aux2_ret'\\<rparr>\\<close>\n\"\n\ndefinition var_to_var_bit_tail_aux2_IMP_Minus where\n  \"var_to_var_bit_tail_aux2_IMP_Minus \\<equiv>\n  \\<comment> \\<open>  hd_xs' = var_to_var_bit_tail_aux2_v s;\\<close>\n  (hd_prefix @ hd_xs_str) ::= (A (V var_to_var_bit_tail_aux2_v_str));;\n  \\<comment> \\<open>  hd_ret' = 0;\\<close>\n  (hd_prefix @ hd_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  hd_state = \\<lparr>hd_xs = hd_xs',\\<close>\n  \\<comment> \\<open>              hd_ret = hd_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  hd_ret_state = hd_imp hd_state;\\<close>\n  (invoke_subprogram hd_prefix hd_IMP_Minus);;\n  \\<comment> \\<open>  EQUAL_neq_zero_a' = hd_ret hd_ret_state;\\<close>\n  (EQUAL_neq_zero_prefix @ EQUAL_neq_zero_a_str) ::= (A (V (hd_prefix @ hd_ret_str)));;\n  \\<comment> \\<open>  EQUAL_neq_zero_b' = hash_encode_char_as_nat;\\<close>\n  (EQUAL_neq_zero_prefix @ EQUAL_neq_zero_b_str) ::= (A (N hash_encode_char_as_nat));;\n  \\<comment> \\<open>  EQUAL_neq_zero_ret' = 0;\\<close>\n  (EQUAL_neq_zero_prefix @ EQUAL_neq_zero_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  EQUAL_neq_zero_state = \\<lparr>EQUAL_neq_zero_a = EQUAL_neq_zero_a',\\<close>\n  \\<comment> \\<open>                          EQUAL_neq_zero_b = EQUAL_neq_zero_b',\\<close>\n  \\<comment> \\<open>                          EQUAL_neq_zero_ret = EQUAL_neq_zero_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  EQUAL_neq_zero_ret_state = EQUAL_neq_zero_imp EQUAL_neq_zero_state;\\<close>\n  (invoke_subprogram EQUAL_neq_zero_prefix EQUAL_neq_zero_IMP_Minus);;\n  \\<comment> \\<open>  EQUAL_neq_zero_result = EQUAL_neq_zero_ret EQUAL_neq_zero_ret_state\\<close>\n  (var_to_var_bit_tail_aux2_EQUAL_neq_zero_result) ::=\n    (A (V (EQUAL_neq_zero_prefix @ EQUAL_neq_zero_ret_str)));;\n  \\<comment> \\<open>(if EQUAL_neq_zero_result \\<noteq> 0 then\\<close>\n  (IF var_to_var_bit_tail_aux2_EQUAL_neq_zero_result \\<noteq>0 THEN\n    var_to_var_bit_tail_aux2_IMP_if\n  \\<comment> \\<open>else\\<close>\n  ELSE\n    var_to_var_bit_tail_aux2_IMP_else\n  )\n\"\n\nabbreviation \"var_to_var_bit_tail_aux2_IMP_vars \\<equiv>\n  {var_to_var_bit_tail_aux2_v_str, var_to_var_bit_tail_aux2_ret_str,\n  var_to_var_bit_tail_aux2_EQUAL_neq_zero_result, var_to_var_bit_tail_aux2_dropWhile_char_result}\"\n\ndefinition \"var_to_var_bit_tail_aux2_imp_to_HOL_state p s =\n  \\<lparr>var_to_var_bit_tail_aux2_v = (s (add_prefix p var_to_var_bit_tail_aux2_v_str)),\n   var_to_var_bit_tail_aux2_ret = (s (add_prefix p var_to_var_bit_tail_aux2_ret_str))\\<rparr>\"\n\nlemmas var_to_var_bit_tail_aux2_state_translators =\n  var_to_var_bit_tail_aux2_imp_to_HOL_state_def\n  hd_imp_to_HOL_state_def\n  EQUAL_neq_zero_imp_to_HOL_state_def\n  dropWhile_char_imp_to_HOL_state_def\n  takeWhile_char_tail_imp_to_HOL_state_def\n  length_imp_to_HOL_state_def\n  var_to_var_bit_tail_aux1_imp_to_HOL_state_def\n\nlemma var_to_var_bit_tail_aux2_IMP_Minus_correct_function:\n  \"(invoke_subprogram p var_to_var_bit_tail_aux2_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p var_to_var_bit_tail_aux2_ret_str)\n      = var_to_var_bit_tail_aux2_ret\n          (var_to_var_bit_tail_aux2_imp (var_to_var_bit_tail_aux2_imp_to_HOL_state p s))\"\n  apply(subst var_to_var_bit_tail_aux2_imp.simps)\n  apply(simp only: var_to_var_bit_tail_aux2_IMP_Minus_def prefix_simps)\n  apply(erule Seq_E)+\n  apply(erule hd_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux2_IMP_vars\"])\n  subgoal premises p using p(9) by fastforce\n  apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux2_IMP_vars\"])\n  subgoal premises p using p(11) by fastforce\n  apply(erule If_E)\n  subgoal\n    apply(erule Seq_E)+\n    apply(erule dropWhile_char_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux2_IMP_vars\"])\n    subgoal premises p using p(28) by fastforce\n    apply(erule takeWhile_char_tail_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux2_IMP_vars\"])\n    subgoal premises p using p(30) by fastforce\n    apply(erule length_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux2_IMP_vars\"])\n    subgoal premises p using p(32) by fastforce\n    apply(erule var_to_var_bit_tail_aux1_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux2_IMP_vars\"])\n    subgoal premises p using p(34) by fastforce\n    by (fastforce_sorted_premises2 simp: var_to_var_bit_tail_aux2_state_translators Let_def\n        var_to_var_bit_tail_aux2_state_upd_def) \n  subgoal\n    by (fastforce_sorted_premises2 simp: var_to_var_bit_tail_aux2_state_translators Let_def\n        var_to_var_bit_tail_aux2_state_upd_def)\n  done\n\nlemma var_to_var_bit_tail_aux2_IMP_Minus_correct_effects:\n  \"\\<lbrakk>(invoke_subprogram (p @ var_to_var_bit_tail_aux2_pref) var_to_var_bit_tail_aux2_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    v \\<in> vars; \\<not> (prefix var_to_var_bit_tail_aux2_pref v)\\<rbrakk>\n   \\<Longrightarrow> s (add_prefix p v) = s' (add_prefix p v)\"\n  using com_add_prefix_valid'' com_only_vars prefix_def\n  by blast  \n\nlemma var_to_var_bit_tail_aux2_IMP_Minus_correct_time:\n  \"(invoke_subprogram p var_to_var_bit_tail_aux2_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = var_to_var_bit_tail_aux2_imp_time 0 (var_to_var_bit_tail_aux2_imp_to_HOL_state p s)\"\n  apply(subst var_to_var_bit_tail_aux2_imp_time.simps)\n  apply(simp only: var_to_var_bit_tail_aux2_IMP_Minus_def prefix_simps)\n  apply(erule Seq_tE)+\n  apply(erule hd_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux2_IMP_vars\"])\n  subgoal premises p using p(17) by fastforce\n  apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux2_IMP_vars\"])\n  subgoal premises p using p(19) by fastforce\n  apply(erule If_tE)\n  subgoal\n    apply(erule Seq_tE)+\n    apply(erule dropWhile_char_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux2_IMP_vars\"])\n    subgoal premises p using p(51) by fastforce\n    apply(erule takeWhile_char_tail_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux2_IMP_vars\"])\n    subgoal premises p using p(53) by fastforce\n    apply(erule length_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux2_IMP_vars\"])\n    subgoal premises p using p(55) by fastforce\n    apply(erule var_to_var_bit_tail_aux1_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_aux2_IMP_vars\"])\n    subgoal premises p using p(57) by fastforce\n    by (fastforce_sorted_premises2 simp: Let_def var_to_var_bit_tail_aux2_state_translators) \n  subgoal\n    by (fastforce_sorted_premises2 simp: Let_def var_to_var_bit_tail_aux2_state_translators)\n  done\n\nlemma var_to_var_bit_tail_aux2_IMP_Minus_correct:\n  \"\\<lbrakk>(invoke_subprogram (p1 @ p2) var_to_var_bit_tail_aux2_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    \\<And>v. v \\<in> vars \\<Longrightarrow> \\<not> (set p2 \\<subseteq> set v);\n    \\<lbrakk>t = (var_to_var_bit_tail_aux2_imp_time 0 (var_to_var_bit_tail_aux2_imp_to_HOL_state (p1 @ p2) s));\n     s' (add_prefix (p1 @ p2) var_to_var_bit_tail_aux2_ret_str) =\n          var_to_var_bit_tail_aux2_ret (var_to_var_bit_tail_aux2_imp\n                                        (var_to_var_bit_tail_aux2_imp_to_HOL_state (p1 @ p2) s));\n     \\<And>v. v \\<in> vars \\<Longrightarrow> s (add_prefix p1 v) = s' (add_prefix p1 v)\\<rbrakk>\n   \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  using var_to_var_bit_tail_aux2_IMP_Minus_correct_function\n    var_to_var_bit_tail_aux2_IMP_Minus_correct_time\n    var_to_var_bit_tail_aux2_IMP_Minus_correct_effects\n  by (meson set_mono_prefix)\n\nsubsubsection \\<open>var_to_var_bit_tail\\<close>\n\nfun var_to_var_bit_tail' :: \"nat \\<Rightarrow> nat\" where\n  \"var_to_var_bit_tail' v =\n    (if length_nat v > 0\n     then var_to_var_bit_tail_aux2 v\n     else 0\n  )\"\n\nlemma var_to_var_bit_tail'_correct: \n  \"var_to_var_bit_tail v = var_to_var_bit_tail' v\"\n  using var_to_var_bit_tail_aux2_correct var_to_var_bit_tail_def by simp\n\nrecord var_to_var_bit_tail_state =\n  var_to_var_bit_tail_v::nat\n  var_to_var_bit_tail_ret::nat\n\nabbreviation \"var_to_var_bit_tail_prefix \\<equiv> ''var_to_var_bit_tail.''\"\nabbreviation \"var_to_var_bit_tail_v_str \\<equiv> ''v''\"\nabbreviation \"var_to_var_bit_tail_ret_str \\<equiv> ''ret''\"\n\ndefinition \"var_to_var_bit_tail_state_upd s \\<equiv>\n  (let\n      length_xs' = var_to_var_bit_tail_v s;\n      length_ret' = 0;\n      length_state = \\<lparr>length_xs = length_xs',\n                      length_ret = length_ret'\\<rparr>;\n      length_ret_state = length_imp length_state;\n      length_result = length_ret length_ret_state\n  in\n  (if length_result \\<noteq> 0 then\n    (let\n      var_to_var_bit_tail_aux2_v' = var_to_var_bit_tail_v s;\n      var_to_var_bit_tail_aux2_ret' = 0;\n      var_to_var_bit_tail_aux2_state = \\<lparr>var_to_var_bit_tail_aux2_v = var_to_var_bit_tail_aux2_v',\n                                        var_to_var_bit_tail_aux2_ret = var_to_var_bit_tail_aux2_ret'\\<rparr>;\n      var_to_var_bit_tail_aux2_ret_state = var_to_var_bit_tail_aux2_imp var_to_var_bit_tail_aux2_state;\n      var_to_var_bit_tail_ret' = var_to_var_bit_tail_aux2_ret var_to_var_bit_tail_aux2_ret_state;\n      ret = \\<lparr>var_to_var_bit_tail_v = var_to_var_bit_tail_v s,\n             var_to_var_bit_tail_ret = var_to_var_bit_tail_ret'\\<rparr>\n    in\n      ret\n    )\n  else\n    (let\n      var_to_var_bit_tail_ret' = 0;\n      ret = \\<lparr>var_to_var_bit_tail_v = var_to_var_bit_tail_v s,\n             var_to_var_bit_tail_ret = var_to_var_bit_tail_ret'\\<rparr>\n    in\n      ret\n    )\n  )\n)\"\n\nfunction var_to_var_bit_tail_imp ::\n  \"var_to_var_bit_tail_state \\<Rightarrow> var_to_var_bit_tail_state\" where\n  \"var_to_var_bit_tail_imp s =\n  (let \n      ret = var_to_var_bit_tail_state_upd s\n    in \n      ret\n  )\"\n  by simp+\ntermination\n  by (relation \"measure var_to_var_bit_tail_v\") simp\n\ndeclare var_to_var_bit_tail_imp.simps [simp del]\n\nlemma var_to_var_bit_tail_imp_correct_aux:\n  \"var_to_var_bit_tail_ret (var_to_var_bit_tail_imp s) =\n    var_to_var_bit_tail' (var_to_var_bit_tail_v s)\"\n  apply (simp only: var_to_var_bit_tail_imp.simps Let_def var_to_var_bit_tail_state_upd_def\n  length_imp_correct2 var_to_var_bit_tail_aux2_imp_correct var_to_var_bit_tail'.simps)\n  by (simp add: length_imp_correct2)  \n\nlemma var_to_var_bit_tail_imp_correct[let_function_correctness]:\n  \"var_to_var_bit_tail_ret (var_to_var_bit_tail_imp s) =\n    var_to_var_bit_tail (var_to_var_bit_tail_v s)\"\n  using var_to_var_bit_tail_imp_correct_aux var_to_var_bit_tail'_correct\n  by simp\n\nfunction var_to_var_bit_tail_imp_time ::\n  \"nat \\<Rightarrow> var_to_var_bit_tail_state \\<Rightarrow> nat\" where\n  \"var_to_var_bit_tail_imp_time t s =\n  (let\n      length_xs' = var_to_var_bit_tail_v s;\n      t = t + 2;\n      length_ret' = 0;\n      t = t + 2;\n      length_state = \\<lparr>length_xs = length_xs',\n                      length_ret = length_ret'\\<rparr>;\n      length_ret_state = length_imp length_state;\n      t = t + length_imp_time 0 length_state;\n      length_result = length_ret length_ret_state;\n      t = t + 2\n  in\n  (if length_result \\<noteq> 0 then\n    (let\n      t = t + 1;\n      var_to_var_bit_tail_aux2_v' = var_to_var_bit_tail_v s;\n      t = t + 2;\n      var_to_var_bit_tail_aux2_ret' = 0;\n      t = t + 2;\n      var_to_var_bit_tail_aux2_state = \\<lparr>var_to_var_bit_tail_aux2_v = var_to_var_bit_tail_aux2_v',\n                                        var_to_var_bit_tail_aux2_ret = var_to_var_bit_tail_aux2_ret'\\<rparr>;\n      var_to_var_bit_tail_aux2_ret_state = var_to_var_bit_tail_aux2_imp var_to_var_bit_tail_aux2_state;\n      t = t + var_to_var_bit_tail_aux2_imp_time 0 var_to_var_bit_tail_aux2_state;\n      var_to_var_bit_tail_ret' = var_to_var_bit_tail_aux2_ret var_to_var_bit_tail_aux2_ret_state;\n      t = t + 2;\n      ret = \\<lparr>var_to_var_bit_tail_v = var_to_var_bit_tail_v s,\n             var_to_var_bit_tail_ret = var_to_var_bit_tail_ret'\\<rparr>\n    in\n      t\n    )\n  else\n    (let\n      t = t + 1;\n      var_to_var_bit_tail_ret' = 0;\n      t = t + 2;\n      ret = \\<lparr>var_to_var_bit_tail_v = var_to_var_bit_tail_v s,\n             var_to_var_bit_tail_ret = var_to_var_bit_tail_ret'\\<rparr>\n    in\n      t\n    )\n  )\n)\"\n  by auto\ntermination\n  by (relation \"measure (var_to_var_bit_tail_v \\<circ> snd)\") simp\n\ndeclare var_to_var_bit_tail_imp_time.simps [simp del]\n\nlemma var_to_var_bit_tail_imp_time_acc:\n  \"(var_to_var_bit_tail_imp_time (Suc t) s) = Suc (var_to_var_bit_tail_imp_time t s)\"\n  by (induction t s rule: var_to_var_bit_tail_imp_time.induct)\n    ((subst (1 2) var_to_var_bit_tail_imp_time.simps);\n      (simp add: var_to_var_bit_tail_state_upd_def Let_def))            \n\nlemma var_to_var_bit_tail_imp_time_acc_2_aux:\n  \"(var_to_var_bit_tail_imp_time t s) = t + (var_to_var_bit_tail_imp_time 0 s)\"\n  by (induction t arbitrary: s) (simp add: var_to_var_bit_tail_imp_time_acc)+            \n\nlemma var_to_var_bit_tail_imp_time_acc_2:\n  \"t \\<noteq> 0 \\<Longrightarrow> (var_to_var_bit_tail_imp_time t s) = t + (var_to_var_bit_tail_imp_time 0 s)\"\n  by (rule var_to_var_bit_tail_imp_time_acc_2_aux)            \n\nlemma var_to_var_bit_tail_imp_time_acc_3:\n  \"(var_to_var_bit_tail_imp_time (a + b) s) = a + (var_to_var_bit_tail_imp_time b s)\"\n  by (induction a arbitrary: b s) (simp add: var_to_var_bit_tail_imp_time_acc)+   \n\nabbreviation \"var_to_var_bit_tail_length_result \\<equiv> ''length_result''\"\n\nabbreviation \"var_to_var_bit_tail_IMP_if \\<equiv>\n  \\<comment> \\<open>  var_to_var_bit_tail_aux2_v' = var_to_var_bit_tail_v s;\\<close>\n  (var_to_var_bit_tail_aux2_prefix @ var_to_var_bit_tail_aux2_v_str) ::=\n    (A (V var_to_var_bit_tail_v_str));;\n  \\<comment> \\<open>  var_to_var_bit_tail_aux2_ret' = 0;\\<close>\n  (var_to_var_bit_tail_aux2_prefix @ var_to_var_bit_tail_aux2_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  var_to_var_bit_tail_aux2_state = \\<lparr>var_to_var_bit_tail_aux2_v = var_to_var_bit_tail_aux2_v',\\<close>\n  \\<comment> \\<open>                                    var_to_var_bit_tail_aux2_ret = var_to_var_bit_tail_aux2_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  var_to_var_bit_tail_aux2_ret_state = var_to_var_bit_tail_aux2_imp var_to_var_bit_tail_aux2_state;\\<close>\n  (invoke_subprogram var_to_var_bit_tail_aux2_prefix var_to_var_bit_tail_aux2_IMP_Minus);;\n  \\<comment> \\<open>  var_to_var_bit_tail_ret' = var_to_var_bit_tail_aux2_ret var_to_var_bit_tail_aux2_ret_state;\\<close>\n  (var_to_var_bit_tail_ret_str) ::=\n    (A (V (var_to_var_bit_tail_aux2_prefix @ var_to_var_bit_tail_aux2_ret_str)))\n  \\<comment> \\<open>  ret = \\<lparr>var_to_var_bit_tail_v = var_to_var_bit_tail_v s,\\<close>\n  \\<comment> \\<open>         var_to_var_bit_tail_ret = var_to_var_bit_tail_ret'\\<rparr>\\<close>\n\"\n\nabbreviation \"var_to_var_bit_tail_IMP_else \\<equiv>\n  \\<comment> \\<open>  var_to_var_bit_tail_ret' = 0;\\<close>\n  (var_to_var_bit_tail_ret_str) ::= (A (N 0))\n  \\<comment> \\<open>  ret = \\<lparr>var_to_var_bit_tail_v = var_to_var_bit_tail_v s,\\<close>\n  \\<comment> \\<open>         var_to_var_bit_tail_ret = var_to_var_bit_tail_ret'\\<rparr>\\<close>\n\"\n\ndefinition var_to_var_bit_tail_IMP_Minus where\n  \"var_to_var_bit_tail_IMP_Minus \\<equiv>\n  \\<comment> \\<open>  length_xs' = var_to_var_bit_tail_v s;\\<close>\n  (length_prefix @ length_xs_str) ::= (A (V var_to_var_bit_tail_v_str));;\n  \\<comment> \\<open>  length_ret' = 0;\\<close>\n  (length_prefix @ length_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  length_state = \\<lparr>length_xs = length_xs',\\<close>\n  \\<comment> \\<open>                  length_ret = length_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  length_ret_state = length_imp length_state;\\<close>\n  (invoke_subprogram length_prefix length_IMP_Minus);;\n  \\<comment> \\<open>  length_result = length_ret length_ret_state\\<close>\n  (var_to_var_bit_tail_length_result) ::= (A (V (length_prefix @ length_ret_str)));;\n  \\<comment> \\<open>(if length_result \\<noteq> 0 then\\<close>\n  (IF var_to_var_bit_tail_length_result \\<noteq>0 THEN\n    var_to_var_bit_tail_IMP_if\n  \\<comment> \\<open>else\\<close>\n  ELSE\n    var_to_var_bit_tail_IMP_else\n  )\n\"\n\nabbreviation \"var_to_var_bit_tail_IMP_vars \\<equiv>\n  {var_to_var_bit_tail_v_str, var_to_var_bit_tail_ret_str, var_to_var_bit_tail_length_result}\"\n\ndefinition \"var_to_var_bit_tail_imp_to_HOL_state p s =\n  \\<lparr>var_to_var_bit_tail_v = (s (add_prefix p var_to_var_bit_tail_v_str)),\n   var_to_var_bit_tail_ret = (s (add_prefix p var_to_var_bit_tail_ret_str))\\<rparr>\"\n\nlemmas var_to_var_bit_tail_state_translators =\n  var_to_var_bit_tail_imp_to_HOL_state_def\n  length_imp_to_HOL_state_def\n  var_to_var_bit_tail_aux2_imp_to_HOL_state_def\n\nlemma var_to_var_bit_tail_IMP_Minus_correct_function:\n  \"(invoke_subprogram p var_to_var_bit_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p var_to_var_bit_tail_ret_str)\n      = var_to_var_bit_tail_ret\n          (var_to_var_bit_tail_imp (var_to_var_bit_tail_imp_to_HOL_state p s))\"\n  apply(subst var_to_var_bit_tail_imp.simps)\n  apply(simp only: var_to_var_bit_tail_IMP_Minus_def prefix_simps)\n  apply(erule Seq_E)+\n  apply(erule length_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_IMP_vars\"])\n  subgoal premises p using p(5) by fastforce\n  apply(erule If_E)\n  subgoal\n    apply(erule Seq_E)+\n    apply(erule var_to_var_bit_tail_aux2_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_IMP_vars\"])\n    subgoal premises p using p(11) by fastforce\n    by(fastforce simp: var_to_var_bit_tail_state_translators\n    var_to_var_bit_tail_state_upd_def) \n  subgoal\n    by(fastforce simp: var_to_var_bit_tail_state_translators\n    var_to_var_bit_tail_state_upd_def)   \n  done\n\nlemma var_to_var_bit_tail_IMP_Minus_correct_effects:\n  \"\\<lbrakk>(invoke_subprogram (p @ var_to_var_bit_tail_pref) var_to_var_bit_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    v \\<in> vars; \\<not> (prefix var_to_var_bit_tail_pref v)\\<rbrakk>\n   \\<Longrightarrow> s (add_prefix p v) = s' (add_prefix p v)\"\n  using com_add_prefix_valid'' com_only_vars prefix_def\n  by blast\n\nlemma var_to_var_bit_tail_IMP_Minus_correct_time:\n  \"(invoke_subprogram p var_to_var_bit_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = var_to_var_bit_tail_imp_time 0 (var_to_var_bit_tail_imp_to_HOL_state p s)\"\n  apply(subst var_to_var_bit_tail_imp_time.simps)\n  apply(simp only: var_to_var_bit_tail_IMP_Minus_def prefix_simps)\n  apply(erule Seq_tE)+\n  apply(erule length_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_IMP_vars\"])\n  subgoal premises p using p(9) by fastforce\n  apply(erule If_tE)\n  subgoal\n    apply(erule Seq_tE)+\n    apply(erule var_to_var_bit_tail_aux2_IMP_Minus_correct[where vars = \"var_to_var_bit_tail_IMP_vars\"])\n    subgoal premises p using p(19) by fastforce\n    by(fastforce simp add: Let_def var_to_var_bit_tail_state_translators)\n  subgoal\n    by(fastforce simp add: Let_def var_to_var_bit_tail_state_translators)\n  done\n\nlemma var_to_var_bit_tail_IMP_Minus_correct:\n  \"\\<lbrakk>(invoke_subprogram (p1 @ p2) var_to_var_bit_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    \\<And>v. v \\<in> vars \\<Longrightarrow> \\<not> (set p2 \\<subseteq> set v);\n    \\<lbrakk>t = (var_to_var_bit_tail_imp_time 0 (var_to_var_bit_tail_imp_to_HOL_state (p1 @ p2) s));\n     s' (add_prefix (p1 @ p2) var_to_var_bit_tail_ret_str) =\n          var_to_var_bit_tail_ret (var_to_var_bit_tail_imp\n                                        (var_to_var_bit_tail_imp_to_HOL_state (p1 @ p2) s));\n     \\<And>v. v \\<in> vars \\<Longrightarrow> s (add_prefix p1 v) = s' (add_prefix p1 v)\\<rbrakk>\n   \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  using var_to_var_bit_tail_IMP_Minus_correct_function\n    var_to_var_bit_tail_IMP_Minus_correct_time\n    var_to_var_bit_tail_IMP_Minus_correct_effects\n  by (meson set_mono_prefix)\n\nsubsection \\<open>n_hashes\\<close>\n\nsubsubsection \\<open>n_hashes_acc\\<close>\n\nrecord n_hashes_acc_state =\n  n_hashes_acc_acc::nat\n  n_hashes_acc_n::nat\n  n_hashes_acc_ret::nat\n\nabbreviation \"n_hashes_acc_prefix \\<equiv> ''n_hashes_acc.''\"\nabbreviation \"n_hashes_acc_acc_str \\<equiv> ''acc''\"\nabbreviation \"n_hashes_acc_n_str \\<equiv> ''n''\"\nabbreviation \"n_hashes_acc_ret_str \\<equiv> ''ret''\"\n\ndefinition \"n_hashes_acc_state_upd s \\<equiv>\n      let\n        cons_h' = hash_encode_char_as_nat;\n        cons_t' = n_hashes_acc_acc s;\n        cons_ret' = 0;\n        cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n        cons_ret_state = cons_imp cons_state;\n        n_hashes_acc_acc' = cons_ret cons_ret_state;\n        n_hashes_acc_n' = n_hashes_acc_n s - 1;\n        ret = \\<lparr>n_hashes_acc_acc = n_hashes_acc_acc',\n               n_hashes_acc_n = n_hashes_acc_n',\n               n_hashes_acc_ret = n_hashes_acc_ret s\\<rparr>\n      in\n        ret\n\"\n\ndefinition \"n_hashes_acc_imp_compute_loop_condition s \\<equiv>\n  (let\n    condition = n_hashes_acc_n s\n   in condition\n  )\"\n\ndefinition \"n_hashes_acc_imp_after_loop s \\<equiv>\n  (let\n    ret = \\<lparr>n_hashes_acc_acc = n_hashes_acc_acc s,\n           n_hashes_acc_n = n_hashes_acc_n s,\n           n_hashes_acc_ret = n_hashes_acc_acc s\\<rparr>\n   in ret\n  )\"\n\nlemmas n_hashes_acc_imp_subprogram_simps =\n  n_hashes_acc_imp_after_loop_def\n  n_hashes_acc_state_upd_def\n  n_hashes_acc_imp_compute_loop_condition_def\n\nfunction n_hashes_acc_imp:: \"n_hashes_acc_state \\<Rightarrow> n_hashes_acc_state\" where\n  \"n_hashes_acc_imp s =\n  (if n_hashes_acc_imp_compute_loop_condition s \\<noteq> 0\n   then\n    (let next_iteration = n_hashes_acc_imp (n_hashes_acc_state_upd s)\n      in next_iteration)\n  else\n    (let ret = n_hashes_acc_imp_after_loop s in ret)\n  )\"\n  by simp+\ntermination by (relation \"measure (\\<lambda>s. n_hashes_acc_n s)\")\n    (simp add: n_hashes_acc_imp_subprogram_simps)+\n\ndeclare n_hashes_acc_imp.simps [simp del]\n\nlemma n_hashes_acc_imp_correct[let_function_correctness]:\n  \"n_hashes_acc_ret (n_hashes_acc_imp s) = n_hashes_acc (n_hashes_acc_acc s) (n_hashes_acc_n s)\"\n  apply(induction s rule: n_hashes_acc_imp.induct)\n  apply(subst n_hashes_acc_imp.simps)\n  apply(simp add: n_hashes_acc_imp_subprogram_simps cons_imp_correct)\n  by (metis Suc_pred hash_encode_char_val n_hashes_acc.simps(2))\n\ndefinition \"n_hashes_acc_state_upd_time t s \\<equiv>\n      let\n        cons_h' = hash_encode_char_as_nat;\n        t = t + 2;\n        cons_t' = n_hashes_acc_acc s;\n        t = t + 2;\n        cons_ret' = 0;\n        t = t + 2;\n        cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n        cons_ret_state = cons_imp cons_state;\n        t = t + cons_imp_time 0 cons_state;\n        n_hashes_acc_acc' = cons_ret cons_ret_state;\n        t = t + 2;\n        n_hashes_acc_n' = n_hashes_acc_n s - 1;\n        t = t + 2;\n        ret = t\n      in\n        ret\n\"\n\ndefinition \"n_hashes_acc_imp_compute_loop_condition_time t s \\<equiv>\n  (let\n    condition = n_hashes_acc_n s;\n    t = t + 2;\n    ret = t\n   in ret\n  )\"\n\ndefinition \"n_hashes_acc_imp_after_loop_time t s \\<equiv>\n  (let\n    t = t + 2;\n    ret = t\n   in ret\n  )\"\n\nfunction n_hashes_acc_imp_time:: \"nat \\<Rightarrow> n_hashes_acc_state \\<Rightarrow> nat\" where\n  \"n_hashes_acc_imp_time t s =\n  n_hashes_acc_imp_compute_loop_condition_time 0 s +\n  (if n_hashes_acc_imp_compute_loop_condition s \\<noteq> 0\n   then\n    (let\n        t = t + 1;\n        next_iteration\n          = n_hashes_acc_imp_time (t + n_hashes_acc_state_upd_time 0 s) (n_hashes_acc_state_upd s)\n     in next_iteration)\n  else\n    (let\n        t = t + 2;\n        ret = t + n_hashes_acc_imp_after_loop_time 0 s\n     in ret)\n  )\"\n  by auto\ntermination\n  by (relation \"measure (\\<lambda>(t,s). n_hashes_acc_n s)\")\n    (simp add: n_hashes_acc_imp_subprogram_simps)+\n\nlemmas n_hashes_acc_imp_subprogram_time_simps =\n  n_hashes_acc_imp_subprogram_simps\n  n_hashes_acc_imp_after_loop_time_def\n  n_hashes_acc_state_upd_time_def\n  n_hashes_acc_imp_compute_loop_condition_time_def\n\nlemmas [simp del] = n_hashes_acc_imp_time.simps\n\nlemma n_hashes_acc_imp_time_acc:\n  \"(n_hashes_acc_imp_time (Suc t) s) = Suc (n_hashes_acc_imp_time t s)\"\n  by (induction t s rule: n_hashes_acc_imp_time.induct)\n    ((subst (1 2) n_hashes_acc_imp_time.simps); (simp add: n_hashes_acc_state_upd_def))\n\nlemma n_hashes_acc_imp_time_acc_2_aux:\n  \"(n_hashes_acc_imp_time t s) = t + (n_hashes_acc_imp_time 0 s)\"\n  by (induction t arbitrary: s) (simp add: n_hashes_acc_imp_time_acc)+\n\nlemma n_hashes_acc_imp_time_acc_2:\n  \"t \\<noteq> 0 \\<Longrightarrow> (n_hashes_acc_imp_time t s) = t + (n_hashes_acc_imp_time 0 s)\"\n  by (rule n_hashes_acc_imp_time_acc_2_aux)\n\nlemma n_hashes_acc_imp_time_acc_3:\n  \"(n_hashes_acc_imp_time (a + b) s) = a + (n_hashes_acc_imp_time b s)\"\n  by (induction a arbitrary: b s) (simp add: n_hashes_acc_imp_time_acc)+\n\nabbreviation \"n_hashes_acc_while_cond \\<equiv> ''condition''\"\n\ndefinition \"n_hashes_acc_IMP_init_while_cond \\<equiv>\n  \\<comment> \\<open>condition = n_hashes_n s\\<close>\n  n_hashes_acc_while_cond ::= (A (V n_hashes_acc_n_str))\"\n\ndefinition \"n_hashes_acc_IMP_loop_body \\<equiv>\n  \\<comment> \\<open>cons_h' = hash_encode_char_as_nat;\\<close>\n  ((cons_prefix @ cons_h_str) ::= (A (N hash_encode_char_as_nat)));;\n  \\<comment> \\<open>cons_t' = n_hashes_acc_acc s;\\<close>\n  ((cons_prefix @ cons_t_str) ::= (A (V n_hashes_acc_acc_str)));;\n  \\<comment> \\<open>cons_ret' = 0;\\<close>\n  ((cons_prefix @ cons_ret_str) ::= (A (N 0)));;\n  \\<comment> \\<open>cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>cons_ret_state = cons_imp cons_state;\\<close>\n  (invoke_subprogram cons_prefix cons_IMP_Minus);;\n  \\<comment> \\<open>n_hashes_acc_acc' = cons_ret cons_ret_state;\\<close>\n  ((n_hashes_acc_acc_str) ::= (A (V (cons_prefix @ cons_ret_str))));;\n  \\<comment> \\<open>n_hashes_acc_n' = n_hashes_acc_n s - 1\\<close>\n  ((n_hashes_acc_n_str) ::= (Sub (V n_hashes_acc_n_str) (N 1)))\"\n\ndefinition \"n_hashes_acc_IMP_after_loop \\<equiv>\n  \\<comment> \\<open>ret = \\<lparr>n_hashes_acc_acc = n_hashes_acc_acc s,\n           n_hashes_acc_n = n_hashes_acc_n s,\n           n_hashes_acc_ret = n_hashes_acc_acc s\\<rparr>\\<close>\n  ((n_hashes_acc_ret_str) ::= (A (V n_hashes_acc_acc_str)))\"\n\ndefinition n_hashes_acc_IMP_Minus where\n  \"n_hashes_acc_IMP_Minus \\<equiv>\n  n_hashes_acc_IMP_init_while_cond;;\n  WHILE n_hashes_acc_while_cond \\<noteq>0 DO (\n    n_hashes_acc_IMP_loop_body;;\n    n_hashes_acc_IMP_init_while_cond\n  );;\n  n_hashes_acc_IMP_after_loop\"\n\nabbreviation\n  \"n_hashes_acc_IMP_vars \\<equiv>\n  {n_hashes_acc_acc_str, n_hashes_acc_n_str, n_hashes_acc_ret_str}\"\n\nlemmas n_hashes_acc_IMP_subprogram_simps =\n  n_hashes_acc_IMP_init_while_cond_def\n  n_hashes_acc_IMP_loop_body_def\n  n_hashes_acc_IMP_after_loop_def\n\ndefinition \"n_hashes_acc_imp_to_HOL_state p s =\n  \\<lparr>n_hashes_acc_acc = (s (add_prefix p n_hashes_acc_acc_str)),\n   n_hashes_acc_n = (s (add_prefix p n_hashes_acc_n_str)),\n   n_hashes_acc_ret = (s (add_prefix p n_hashes_acc_ret_str))\\<rparr>\"\n\nlemmas n_hashes_acc_state_translators =\n  cons_imp_to_HOL_state_def\n  n_hashes_acc_imp_to_HOL_state_def\n\nlemmas n_hashes_acc_complete_simps =\n  n_hashes_acc_IMP_subprogram_simps\n  n_hashes_acc_imp_subprogram_simps\n  n_hashes_acc_state_translators\n\nlemma n_hashes_acc_IMP_Minus_correct_function:\n  \"(invoke_subprogram p n_hashes_acc_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p n_hashes_acc_ret_str)\n      = n_hashes_acc_ret (n_hashes_acc_imp (n_hashes_acc_imp_to_HOL_state p s))\"\n  apply(induction \"n_hashes_acc_imp_to_HOL_state p s\" arbitrary: s s' t\n      rule: n_hashes_acc_imp.induct)\n  apply(subst n_hashes_acc_imp.simps)\n  apply(simp only: n_hashes_acc_IMP_Minus_def prefix_simps)\n  apply (subst n_hashes_acc_imp_subprogram_simps)\n  apply(vcg n_hashes_acc_IMP_vars)\n  apply (subst n_hashes_acc_imp_to_HOL_state_def)+\n  subgoal\n    by (fastforce simp: n_hashes_acc_complete_simps Let_def)\n  subgoal\n    by (fastforce simp: n_hashes_acc_complete_simps Let_def)\n  subgoal\n    apply(subst n_hashes_acc_imp_subprogram_simps)\n    apply(simp only: prefix_simps n_hashes_acc_IMP_loop_body_def)\n    apply(vcg n_hashes_acc_IMP_vars)\n    by (fastforce_sorted_premises simp: n_hashes_acc_complete_simps Let_def)\n  subgoal\n    apply(simp only: prefix_simps n_hashes_acc_IMP_loop_body_def)\n    apply(vcg n_hashes_acc_IMP_vars)\n    by (fastforce_sorted_premises simp: n_hashes_acc_complete_simps Let_def)\n  done\n\nlemma n_hashes_acc_IMP_Minus_correct_effects:\n  \"\\<lbrakk>(invoke_subprogram (p @ n_hashes_acc_pref) n_hashes_acc_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    v \\<in> vars; \\<not> (prefix n_hashes_acc_pref v)\\<rbrakk>\n  \\<Longrightarrow> s (add_prefix p v) = s' (add_prefix p v)\"\n  using com_add_prefix_valid'' com_only_vars prefix_def\n  by blast\n\nlemma n_hashes_acc_IMP_Minus_correct_time_loop_condition:\n  \"(invoke_subprogram p n_hashes_acc_IMP_init_while_cond, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = n_hashes_acc_imp_compute_loop_condition_time 0 (n_hashes_acc_imp_to_HOL_state p s)\"\n  by (subst n_hashes_acc_imp_compute_loop_condition_time_def)\n    (auto simp: n_hashes_acc_IMP_init_while_cond_def)\n\nlemmas n_hashes_acc_complete_time_simps =\n  n_hashes_acc_imp_subprogram_time_simps\n  n_hashes_acc_imp_time_acc_2\n  n_hashes_acc_imp_time_acc_3\n  n_hashes_acc_state_translators\n\nlemma n_hashes_acc_IMP_Minus_correct_time:\n  \"(invoke_subprogram p n_hashes_acc_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = n_hashes_acc_imp_time 0 (n_hashes_acc_imp_to_HOL_state p s)\"\n  apply(induction \"n_hashes_acc_imp_to_HOL_state p s\" arbitrary: s s' t\n      rule: n_hashes_acc_imp.induct)\n  apply(subst n_hashes_acc_imp_time.simps)\n  apply(simp only: n_hashes_acc_IMP_Minus_def prefix_simps)\n  apply(erule Seq_tE)+\n  apply(erule While_tE_time)\n  subgoal\n    by (fastforce simp: n_hashes_acc_IMP_subprogram_simps n_hashes_acc_imp_subprogram_time_simps\n        n_hashes_acc_state_translators)\n\n  apply(erule Seq_tE)+\n  apply(clarsimp simp: add.assoc)\n  apply(dest_com_gen_time)\n\n  subgoal\n    apply(simp only: n_hashes_acc_IMP_init_while_cond_def\n        n_hashes_acc_IMP_loop_body_def prefix_simps)\n    apply(erule Seq_E)+\n    apply(erule cons_IMP_Minus_correct[where vars = \"n_hashes_acc_IMP_vars\"], fastforce)\n    by (fastforce_sorted_premises simp: n_hashes_acc_complete_time_simps)\n\n  subgoal\n    apply(subst (asm) n_hashes_acc_IMP_init_while_cond_def)\n    apply(simp only: prefix_simps n_hashes_acc_IMP_loop_body_def)\n    apply(erule Seq_E)+\n    apply(erule cons_IMP_Minus_correct[where vars = \"n_hashes_acc_IMP_vars\"], fastforce)\n    by (fastforce_sorted_premises simp: n_hashes_acc_complete_time_simps)\n\n  subgoal\n    apply(simp only: n_hashes_acc_IMP_init_while_cond_def prefix_simps\n        n_hashes_acc_IMP_loop_body_def)\n    apply(erule Seq_tE)+\n    apply(erule cons_IMP_Minus_correct[where vars = \"n_hashes_acc_IMP_vars\"], fastforce)\n    by (fastforce_sorted_premises simp: n_hashes_acc_complete_time_simps)\n  done\n\nlemma n_hashes_acc_IMP_Minus_correct:\n  \"\\<lbrakk>(invoke_subprogram (p1 @ p2) n_hashes_acc_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    \\<And>v. v \\<in> vars \\<Longrightarrow> \\<not> (set p2 \\<subseteq> set v);\n     \\<lbrakk>t = (n_hashes_acc_imp_time 0 (n_hashes_acc_imp_to_HOL_state (p1 @ p2) s));\n      s' (add_prefix (p1 @ p2) n_hashes_acc_ret_str) =\n        n_hashes_acc_ret (n_hashes_acc_imp (n_hashes_acc_imp_to_HOL_state (p1 @ p2) s));\n      \\<And>v. v \\<in> vars \\<Longrightarrow> s (add_prefix p1 v) = s' (add_prefix p1 v)\\<rbrakk>\n     \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  using n_hashes_acc_IMP_Minus_correct_function\n  by (auto simp: n_hashes_acc_IMP_Minus_correct_time)\n    (meson n_hashes_acc_IMP_Minus_correct_effects set_mono_prefix)\n\n\nsubsubsection \\<open>n_hashes_tail\\<close>\n\nrecord n_hashes_tail_state =\n  n_hashes_tail_n::nat\n  n_hashes_tail_ret::nat\n\nabbreviation \"n_hashes_tail_prefix \\<equiv> ''n_hashes_tail.''\"\nabbreviation \"n_hashes_tail_n_str \\<equiv> ''n''\"\nabbreviation \"n_hashes_tail_ret_str \\<equiv> ''ret''\"\n\ndefinition \"n_hashes_tail_state_upd s =\n  (let\n      n_hashes_acc_acc' = 0;\n      n_hashes_acc_n' = n_hashes_tail_n s;\n      n_hashes_acc_ret' = 0;\n      n_hashes_acc_state = \\<lparr>n_hashes_acc_acc = n_hashes_acc_acc',\n                            n_hashes_acc_n = n_hashes_acc_n',\n                            n_hashes_acc_ret = n_hashes_acc_ret'\\<rparr>;\n      n_hashes_acc_ret_state = n_hashes_acc_imp n_hashes_acc_state;\n      reverse_nat_n' = n_hashes_acc_ret n_hashes_acc_ret_state;\n      reverse_nat_ret' = 0;\n      reverse_nat_state = \\<lparr>reverse_nat_n = reverse_nat_n',\n                             reverse_nat_ret = reverse_nat_ret'\\<rparr>;\n      reverse_nat_ret_state = reverse_nat_imp reverse_nat_state;\n      n_hashes_tail_ret' = reverse_nat_ret reverse_nat_ret_state;\n      n_hashes_tail_n' = n_hashes_tail_n s;\n      ret = \\<lparr>n_hashes_tail_n = n_hashes_tail_n',\n             n_hashes_tail_ret = n_hashes_tail_ret'\\<rparr>\n    in\n      ret\n  )\"\n\nfunction n_hashes_tail_imp:: \"n_hashes_tail_state \\<Rightarrow> n_hashes_tail_state\" where\n  \"n_hashes_tail_imp s =\n  (let\n      ret = n_hashes_tail_state_upd s\n    in\n      ret\n  )\"\n  by simp+\ntermination\n  by (relation \"measure (\\<lambda>s. n_hashes_tail_n s)\") simp\n\ndeclare n_hashes_tail_imp.simps [simp del]\n\nlemma n_hashes_tail_imp_correct[let_function_correctness]:\n  \"n_hashes_tail_ret (n_hashes_tail_imp s) = n_hashes_tail (n_hashes_tail_n s)\"\n  by (simp add: n_hashes_acc_imp_correct n_hashes_tail_def n_hashes_tail_imp.simps\n      n_hashes_tail_state_upd_def reverse_nat_imp_correct)\n\nfunction n_hashes_tail_imp_time:: \"nat \\<Rightarrow> n_hashes_tail_state \\<Rightarrow> nat\" where\n  \"n_hashes_tail_imp_time t s =\n  (let\n      n_hashes_acc_acc' = 0;\n      t = t + 2;\n      n_hashes_acc_n' = n_hashes_tail_n s;\n      t = t + 2;\n      n_hashes_acc_ret' = 0;\n      t = t + 2;\n      n_hashes_acc_state = \\<lparr>n_hashes_acc_acc = n_hashes_acc_acc',\n                            n_hashes_acc_n = n_hashes_acc_n',\n                            n_hashes_acc_ret = n_hashes_acc_ret'\\<rparr>;\n      n_hashes_acc_ret_state = n_hashes_acc_imp n_hashes_acc_state;\n      t = t + n_hashes_acc_imp_time 0 n_hashes_acc_state;\n      reverse_nat_n' = n_hashes_acc_ret n_hashes_acc_ret_state;\n      t = t + 2;\n      reverse_nat_ret' = 0;\n      t = t + 2;\n      reverse_nat_state = \\<lparr>reverse_nat_n = reverse_nat_n',\n                             reverse_nat_ret = reverse_nat_ret'\\<rparr>;\n      reverse_nat_ret_state = reverse_nat_imp reverse_nat_state;\n      t = t + reverse_nat_imp_time 0 reverse_nat_state;\n      n_hashes_tail_ret' = reverse_nat_ret reverse_nat_ret_state;\n      t = t + 2;\n      ret = t\n    in\n      ret\n  )\"\n  by auto\ntermination\n  by (relation \"measure (\\<lambda>(t, s). n_hashes_tail_n s)\") simp\n\nlemmas [simp del] = n_hashes_tail_imp_time.simps\n\nlemma n_hashes_tail_imp_time_acc:\n  \"(n_hashes_tail_imp_time (Suc t) s) = Suc (n_hashes_tail_imp_time t s)\"\n  by (simp add: n_hashes_tail_imp_time.simps Let_def)\n\nlemma n_hashes_tail_imp_time_acc_2:\n  \"(n_hashes_tail_imp_time x s) = x + (n_hashes_tail_imp_time 0 s)\"\n  by (simp add: n_hashes_tail_imp_time.simps Let_def)\n\ndefinition n_hashes_tail_IMP_Minus where\n  \"n_hashes_tail_IMP_Minus \\<equiv>\n    \\<comment> \\<open>n_hashes_acc_acc' = 0;\\<close>\n    (n_hashes_acc_prefix @ n_hashes_acc_acc_str) ::= (A (N 0));;\n    \\<comment> \\<open>n_hashes_acc_n' = n_hashes_tail_n s;\\<close>\n    (n_hashes_acc_prefix @ n_hashes_acc_n_str) ::= (A (V n_hashes_tail_n_str));;\n    \\<comment> \\<open>n_hashes_acc_ret' = 0;\\<close>\n    (n_hashes_acc_prefix @ n_hashes_acc_ret_str) ::= (A (N 0));;\n    \\<comment> \\<open>n_hashes_acc_state = \\<lparr>n_hashes_acc_acc = n_hashes_acc_acc',\\<close>\n    \\<comment> \\<open>                      n_hashes_acc_n = n_hashes_acc_n',\\<close>\n    \\<comment> \\<open>                      n_hashes_acc_ret = n_hashes_acc_ret'\\<rparr>;\\<close>\n    \\<comment> \\<open>n_hashes_acc_ret_state = n_hashes_acc_imp n_hashes_acc_state;\\<close>\n    invoke_subprogram n_hashes_acc_prefix n_hashes_acc_IMP_Minus;;\n    \\<comment> \\<open>reverse_nat_n' = n_hashes_acc_ret n_hashes_acc_ret_state;\\<close>\n    (reverse_nat_prefix @ reverse_nat_n_str)\n      ::= (A (V (n_hashes_acc_prefix @ n_hashes_acc_ret_str)));;\n    \\<comment> \\<open>reverse_nat_ret' = 0;\\<close>\n    (reverse_nat_prefix @ reverse_nat_ret_str) ::= (A (N 0));;\n    \\<comment> \\<open>reverse_nat_state = \\<lparr>reverse_nat_n = reverse_nat_n',\\<close>\n    \\<comment> \\<open>                       reverse_nat_ret = reverse_nat_ret'\\<rparr>;\\<close>\n    \\<comment> \\<open>reverse_nat_ret_state = reverse_nat_imp reverse_nat_state;\\<close>\n    invoke_subprogram reverse_nat_prefix reverse_nat_IMP_Minus;;\n    \\<comment> \\<open>n_hashes_tail_ret' = reverse_nat_ret reverse_nat_ret_state;\\<close>\n    n_hashes_tail_ret_str ::= (A (V (reverse_nat_prefix @ reverse_nat_ret_str)))\n\"\n\nabbreviation\n  \"n_hashes_tail_IMP_vars \\<equiv>\n  {n_hashes_tail_n_str, n_hashes_tail_ret_str}\"\n\ndefinition \"n_hashes_tail_imp_to_HOL_state p s =\n  \\<lparr>n_hashes_tail_n = (s (add_prefix p n_hashes_tail_n_str)),\n   n_hashes_tail_ret = (s (add_prefix p n_hashes_tail_ret_str))\\<rparr>\"\n\nlemmas n_hashes_tail_state_translators =\n  n_hashes_acc_imp_to_HOL_state_def\n  reverse_nat_imp_to_HOL_state_def\n  n_hashes_tail_imp_to_HOL_state_def\n\nlemma n_hashes_tail_IMP_Minus_correct_function:\n  \"(invoke_subprogram p n_hashes_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p n_hashes_tail_ret_str)\n      = n_hashes_tail_ret (n_hashes_tail_imp (n_hashes_tail_imp_to_HOL_state p s))\"\n  by (fastforce elim: reverse_nat_IMP_Minus_correct n_hashes_acc_IMP_Minus_correct\n      simp: n_hashes_tail_state_translators n_hashes_tail_state_upd_def\n      n_hashes_tail_IMP_Minus_def invoke_subprogram_append n_hashes_tail_imp.simps)\n\nlemma n_hashes_tail_IMP_Minus_correct_effects:\n  \"\\<lbrakk>(invoke_subprogram (p @ n_hashes_tail_pref) n_hashes_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    v \\<in> vars; \\<not> (prefix n_hashes_tail_pref v)\\<rbrakk>\n  \\<Longrightarrow> s (add_prefix p v) = s' (add_prefix p v)\"\n  using com_add_prefix_valid'' com_only_vars prefix_def\n  by blast\n\nlemma n_hashes_tail_IMP_Minus_correct_time:\n  \"(invoke_subprogram p n_hashes_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = n_hashes_tail_imp_time 0 (n_hashes_tail_imp_to_HOL_state p s)\"\n  by (fastforce elim: n_hashes_acc_IMP_Minus_correct reverse_nat_IMP_Minus_correct\n      simp: n_hashes_tail_imp_time.simps n_hashes_tail_imp_time_acc n_hashes_tail_imp_time_acc_2\n      n_hashes_tail_state_translators Let_def n_hashes_tail_IMP_Minus_def invoke_subprogram_append)\n\nlemma n_hashes_tail_IMP_Minus_correct:\n  \"\\<lbrakk>(invoke_subprogram (p1 @ p2) n_hashes_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    \\<And>v. v \\<in> vars \\<Longrightarrow> \\<not> (set p2 \\<subseteq> set v);\n     \\<lbrakk>t = (n_hashes_tail_imp_time 0 (n_hashes_tail_imp_to_HOL_state (p1 @ p2) s));\n      s' (add_prefix (p1 @ p2) n_hashes_tail_ret_str) =\n        n_hashes_tail_ret (n_hashes_tail_imp (n_hashes_tail_imp_to_HOL_state (p1 @ p2) s));\n      \\<And>v. v \\<in> vars \\<Longrightarrow> s (add_prefix p1 v) = s' (add_prefix p1 v)\\<rbrakk>\n     \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  using n_hashes_tail_IMP_Minus_correct_time n_hashes_tail_IMP_Minus_correct_function\n    n_hashes_tail_IMP_Minus_correct_effects\n  by (meson set_mono_prefix)\n\n\nsubsection \\<open>var_bit_to_var_nat\\<close>\n\nrecord var_bit_to_var_nat_state =\n  var_bit_to_var_nat_n::nat\n  var_bit_to_var_nat_ret::nat\n\nabbreviation \"var_bit_to_var_nat_prefix \\<equiv> ''var_bit_to_var_nat.''\"\nabbreviation \"var_bit_to_var_nat_n_str \\<equiv> ''n''\"\nabbreviation \"var_bit_to_var_nat_ret_str \\<equiv> ''ret''\"\n\ndefinition \"var_bit_to_var_nat_state_upd s =\n  (let\n      snd'_state_p' = var_bit_to_var_nat_n s;\n      snd'_state = \\<lparr>snd'_state_p = snd'_state_p'\\<rparr>;\n      snd'_ret_state = snd'_imp snd'_state;\n      n_hashes_tail_n' = snd'_state_p snd'_ret_state + 1;\n      n_hashes_tail_ret' = 0;\n      n_hashes_tail_state = \\<lparr>n_hashes_tail_n = n_hashes_tail_n',\n                             n_hashes_tail_ret = n_hashes_tail_ret'\\<rparr>;\n      n_hashes_tail_ret_state = n_hashes_tail_imp n_hashes_tail_state;\n      append_nat_xs' = n_hashes_tail_ret n_hashes_tail_ret_state;\n      append_nat_ys' = dollar_vname_encode_as_nat;\n      append_nat_ret' = 0;\n      append_nat_state = \\<lparr>append_nat_xs = append_nat_xs',\n                          append_nat_ys = append_nat_ys',\n                          append_nat_ret = append_nat_ret'\\<rparr>;\n      append_nat_ret_state = append_nat_imp append_nat_state;\n      fst'_state_p' = var_bit_to_var_nat_n s;\n      fst'_state = \\<lparr>fst'_state_p = fst'_state_p'\\<rparr>;\n      fst'_ret_state = fst'_imp fst'_state;\n      append_nat_xs' = append_nat_ret append_nat_ret_state;\n      append_nat_ys' = fst'_state_p fst'_ret_state;\n      append_nat_ret' = 0;\n      append_nat_state = \\<lparr>append_nat_xs = append_nat_xs',\n                          append_nat_ys = append_nat_ys',\n                          append_nat_ret = append_nat_ret'\\<rparr>;\n      append_nat_ret_state = append_nat_imp append_nat_state;\n      var_bit_to_var_nat_n' = var_bit_to_var_nat_n s;\n      var_bit_to_var_nat_ret' = append_nat_ret append_nat_ret_state;\n      ret = \\<lparr>var_bit_to_var_nat_n = var_bit_to_var_nat_n',\n             var_bit_to_var_nat_ret = var_bit_to_var_nat_ret'\\<rparr>\n    in\n      ret\n  )\"\n\nfunction var_bit_to_var_nat_imp:: \"var_bit_to_var_nat_state \\<Rightarrow> var_bit_to_var_nat_state\" where\n  \"var_bit_to_var_nat_imp s =\n  (let\n      ret = var_bit_to_var_nat_state_upd s\n    in\n      ret\n  )\"\n  by simp+\ntermination\n  by (relation \"measure var_bit_to_var_nat_n\") simp\n\ndeclare var_bit_to_var_nat_imp.simps [simp del]\n\nlemma var_bit_to_var_nat_imp_correct[let_function_correctness]:\n  \"var_bit_to_var_nat_ret (var_bit_to_var_nat_imp s) = var_bit_to_var_nat (var_bit_to_var_nat_n s)\"\n  by (simp add: n_hashes_tail_imp_correct var_bit_to_var_nat_def var_bit_to_var_nat_imp.simps\n      fst_nat_fst'_nat snd_nat_snd'_nat var_bit_to_var_nat_state_upd_def subtail_n_hashes\n      snd'_imp_correct fst'_imp_correct append_nat_imp_correct dollar_vname_encode_val)\n\nfunction var_bit_to_var_nat_imp_time:: \"nat \\<Rightarrow> var_bit_to_var_nat_state \\<Rightarrow> nat\" where\n  \"var_bit_to_var_nat_imp_time t s =\n  (let\n      snd'_state_p' = var_bit_to_var_nat_n s;\n      t = t + 2;\n      snd'_state = \\<lparr>snd'_state_p = snd'_state_p'\\<rparr>;\n      snd'_ret_state = snd'_imp snd'_state;\n      t = t + snd'_imp_time 0 snd'_state;\n      n_hashes_tail_n' = snd'_state_p snd'_ret_state + 1;\n      t = t + 2;\n      n_hashes_tail_ret' = 0;\n      t = t + 2;\n      n_hashes_tail_state = \\<lparr>n_hashes_tail_n = n_hashes_tail_n',\n                             n_hashes_tail_ret = n_hashes_tail_ret'\\<rparr>;\n      n_hashes_tail_ret_state = n_hashes_tail_imp n_hashes_tail_state;\n      t = t + n_hashes_tail_imp_time 0 n_hashes_tail_state;\n      append_nat_xs' = n_hashes_tail_ret n_hashes_tail_ret_state;\n      t = t + 2;\n      append_nat_ys' = dollar_vname_encode_as_nat;\n      t = t + 2;\n      append_nat_ret' = 0;\n      t = t + 2;\n      append_nat_state = \\<lparr>append_nat_xs = append_nat_xs',\n                          append_nat_ys = append_nat_ys',\n                          append_nat_ret = append_nat_ret'\\<rparr>;\n      append_nat_ret_state = append_nat_imp append_nat_state;\n      t = t + append_nat_imp_time 0 append_nat_state;\n      fst'_state_p' = var_bit_to_var_nat_n s;\n      t = t + 2;\n      fst'_state = \\<lparr>fst'_state_p = fst'_state_p'\\<rparr>;\n      fst'_ret_state = fst'_imp fst'_state;\n      t = t + fst'_imp_time 0 fst'_state;\n      append_nat_xs' = append_nat_ret append_nat_ret_state;\n      t = t + 2;\n      append_nat_ys' = fst'_state_p fst'_ret_state;\n      t = t + 2;\n      append_nat_ret' = 0;\n      t = t + 2;\n      append_nat_state = \\<lparr>append_nat_xs = append_nat_xs',\n                          append_nat_ys = append_nat_ys',\n                          append_nat_ret = append_nat_ret'\\<rparr>;\n      append_nat_ret_state = append_nat_imp append_nat_state;\n      t = t + append_nat_imp_time 0 append_nat_state;\n      var_bit_to_var_nat_n' = var_bit_to_var_nat_n s;\n      t = t + 2;\n      var_bit_to_var_nat_ret' = append_nat_ret append_nat_ret_state;\n      t = t + 2;\n      ret = t\n    in\n      ret\n  )\"\n  by auto\ntermination\n  by (relation \"measure (var_bit_to_var_nat_n \\<circ> snd)\") simp\n\nlemmas [simp del] = var_bit_to_var_nat_imp_time.simps\n\nlemma var_bit_to_var_nat_imp_time_acc:\n  \"(var_bit_to_var_nat_imp_time (Suc t) s) = Suc (var_bit_to_var_nat_imp_time t s)\"\n  by (simp add: var_bit_to_var_nat_imp_time.simps Let_def)\n\nlemma var_bit_to_var_nat_imp_time_acc_2:\n  \"(var_bit_to_var_nat_imp_time x s) = x + (var_bit_to_var_nat_imp_time 0 s)\"\n  by (simp add: var_bit_to_var_nat_imp_time.simps Let_def)\n\ndefinition var_bit_to_var_nat_IMP_Minus where\n  \"var_bit_to_var_nat_IMP_Minus \\<equiv>\n  \\<comment> \\<open>snd'_state_p' = var_bit_to_var_nat_n s;\\<close>\n  (snd'_prefix @ snd'_p_str) ::= (A (V var_bit_to_var_nat_n_str));;\n  \\<comment> \\<open>snd'_state = \\<lparr>snd'_state_p = snd'_state_p'\\<rparr>;\\<close>\n  \\<comment> \\<open>snd'_ret_state = snd'_imp snd'_state;\\<close>\n  invoke_subprogram snd'_prefix snd'_IMP_Minus;;\n  \\<comment> \\<open>n_hashes_tail_n' = snd'_state_p snd'_ret_state + 1;\\<close>\n  (n_hashes_tail_prefix @ n_hashes_tail_n_str) ::= (Plus (V (snd'_prefix @ snd'_p_str)) (N 1));;\n  \\<comment> \\<open>n_hashes_tail_ret' = 0;\\<close>\n  (n_hashes_tail_prefix @ n_hashes_tail_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>n_hashes_tail_state = \\<lparr>n_hashes_tail_n = n_hashes_tail_n',\\<close>\n  \\<comment> \\<open>                       n_hashes_tail_ret = n_hashes_tail_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>n_hashes_tail_ret_state = n_hashes_tail_imp n_hashes_tail_state;\\<close>\n  invoke_subprogram n_hashes_tail_prefix n_hashes_tail_IMP_Minus;;\n  \\<comment> \\<open>append_nat_xs' = n_hashes_tail_ret n_hashes_tail_ret_state;\\<close>\n  (append_nat_prefix @ append_nat_xs_str)\n    ::= (A (V (n_hashes_tail_prefix @ n_hashes_tail_ret_str)));;\n  \\<comment> \\<open>append_nat_ys' = dollar_vname_encode_as_nat;\\<close>\n  (append_nat_prefix @ append_nat_ys_str) ::= (A (N dollar_vname_encode_as_nat));;\n  \\<comment> \\<open>append_nat_ret' = 0;\\<close>\n  (append_nat_prefix @ append_nat_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>append_nat_state = \\<lparr>append_nat_xs = append_nat_xs',\\<close>\n  \\<comment> \\<open>                    append_nat_ys = append_nat_ys',\\<close>\n  \\<comment> \\<open>                    append_nat_ret = append_nat_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>append_nat_ret_state = append_nat_imp append_nat_state;\\<close>\n  invoke_subprogram append_nat_prefix append_nat_IMP_Minus;;\n  \\<comment> \\<open>fst'_state_p' = var_bit_to_var_nat_n s;\\<close>\n  (fst'_prefix @ fst'_p_str) ::= (A (V var_bit_to_var_nat_n_str));;\n  \\<comment> \\<open>fst'_state = \\<lparr>fst'_state_p = fst'_state_p'\\<rparr>;\\<close>\n  \\<comment> \\<open>fst'_ret_state = fst'_imp fst'_state;\\<close>\n  invoke_subprogram fst'_prefix fst'_IMP_Minus;;\n  \\<comment> \\<open>append_nat_xs' = append_nat_ret append_nat_ret_state;\\<close>\n  (append_nat_prefix @ append_nat_xs_str) ::= (A (V (append_nat_prefix @ append_nat_ret_str)));;\n  \\<comment> \\<open>append_nat_ys' = fst'_state_p fst'_ret_state;\\<close>\n  (append_nat_prefix @ append_nat_ys_str) ::= (A (V (fst'_prefix @ fst'_p_str)));;\n  \\<comment> \\<open>append_nat_ret' = 0;\\<close>\n  (append_nat_prefix @ append_nat_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>append_nat_state = \\<lparr>append_nat_xs = append_nat_xs',\\<close>\n  \\<comment> \\<open>                    append_nat_ys = append_nat_ys',\\<close>\n  \\<comment> \\<open>                    append_nat_ret = append_nat_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>append_nat_ret_state = append_nat_imp append_nat_state;\\<close>\n  invoke_subprogram append_nat_prefix append_nat_IMP_Minus;;\n  \\<comment> \\<open>var_bit_to_var_nat_n' = var_bit_to_var_nat_n s;\\<close>\n  var_bit_to_var_nat_n_str ::= (A (V var_bit_to_var_nat_n_str));;\n  \\<comment> \\<open>var_bit_to_var_nat_ret' = append_nat_ret append_nat_ret_state;\\<close>\n  var_bit_to_var_nat_ret_str ::= (A (V (append_nat_prefix @ append_nat_ret_str)))\n\"\n\nabbreviation\n  \"var_bit_to_var_nat_IMP_vars \\<equiv>\n  {var_bit_to_var_nat_n_str, var_bit_to_var_nat_ret_str}\"\n\ndefinition \"var_bit_to_var_nat_imp_to_HOL_state p s =\n  \\<lparr>var_bit_to_var_nat_n = (s (add_prefix p var_bit_to_var_nat_n_str)),\n   var_bit_to_var_nat_ret = (s (add_prefix p var_bit_to_var_nat_ret_str))\\<rparr>\"\n\nlemmas var_bit_to_var_nat_state_translators =\n  fst'_imp_to_HOL_state_def\n  snd'_imp_to_HOL_state_def\n  n_hashes_tail_imp_to_HOL_state_def\n  append_nat_imp_to_HOL_state_def\n  var_bit_to_var_nat_imp_to_HOL_state_def\n\nlemma var_bit_to_var_nat_IMP_Minus_correct_function:\n  \"(invoke_subprogram p var_bit_to_var_nat_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p var_bit_to_var_nat_ret_str)\n      = var_bit_to_var_nat_ret (var_bit_to_var_nat_imp (var_bit_to_var_nat_imp_to_HOL_state p s))\"\n  apply (subst var_bit_to_var_nat_imp.simps)\n  apply (simp only: var_bit_to_var_nat_IMP_Minus_def prefix_simps)\n  apply (erule Seq_E)+\n\n  apply (erule snd'_IMP_Minus_correct[where\n        vars = \"insert (append_nat_prefix @ append_nat_ret_str) var_bit_to_var_nat_IMP_vars\"])\n  subgoal premises p using p(17) by fastforce\n  apply (erule n_hashes_tail_IMP_Minus_correct[where\n        vars = \"insert (append_nat_prefix @ append_nat_ret_str) var_bit_to_var_nat_IMP_vars\"])\n  subgoal premises p using p(19) by fastforce\n  apply (erule append_nat_IMP_Minus_correct[where vars = \"var_bit_to_var_nat_IMP_vars\"])\n  subgoal premises p using p(21) by fastforce\n  apply (erule fst'_IMP_Minus_correct[where\n        vars = \"insert (append_nat_prefix @ append_nat_ret_str) var_bit_to_var_nat_IMP_vars\"])\n  subgoal premises p using p(23) by fastforce\n  apply (erule append_nat_IMP_Minus_correct[where vars = \"var_bit_to_var_nat_IMP_vars\"])\n  subgoal premises p using p(25) by fastforce\n\n  by (fastforce simp: var_bit_to_var_nat_state_translators var_bit_to_var_nat_state_upd_def)\n\nlemma var_bit_to_var_nat_IMP_Minus_correct_effects:\n  \"\\<lbrakk>(invoke_subprogram (p @ var_bit_to_var_nat_pref) var_bit_to_var_nat_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    v \\<in> vars; \\<not> (prefix var_bit_to_var_nat_pref v)\\<rbrakk>\n  \\<Longrightarrow> s (add_prefix p v) = s' (add_prefix p v)\"\n  using com_add_prefix_valid'' com_only_vars prefix_def\n  by blast\n\nlemma var_bit_to_var_nat_IMP_Minus_correct_time:\n  \"(invoke_subprogram p var_bit_to_var_nat_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = var_bit_to_var_nat_imp_time 0 (var_bit_to_var_nat_imp_to_HOL_state p s)\"\n  apply (subst var_bit_to_var_nat_imp_time.simps)\n  apply (simp only: var_bit_to_var_nat_IMP_Minus_def prefix_simps)\n  apply (erule Seq_tE)+\n\n  apply (erule snd'_IMP_Minus_correct[where\n        vars = \"insert (append_nat_prefix @ append_nat_ret_str) var_bit_to_var_nat_IMP_vars\"])\n  subgoal premises p using p(33) by fastforce\n  apply (erule n_hashes_tail_IMP_Minus_correct[where\n        vars = \"insert (append_nat_prefix @ append_nat_ret_str) var_bit_to_var_nat_IMP_vars\"])\n  subgoal premises p using p(35) by fastforce\n  apply (erule append_nat_IMP_Minus_correct[where vars = \"var_bit_to_var_nat_IMP_vars\"])\n  subgoal premises p using p(37) by fastforce\n  apply (erule fst'_IMP_Minus_correct[where\n        vars = \"insert (append_nat_prefix @ append_nat_ret_str) var_bit_to_var_nat_IMP_vars\"])\n  subgoal premises p using p(39) by fastforce\n  apply (erule append_nat_IMP_Minus_correct[where vars = \"var_bit_to_var_nat_IMP_vars\"])\n  subgoal premises p using p(41) by fastforce\n\n  by (fastforce simp add: Let_def var_bit_to_var_nat_state_translators)\n\nlemma var_bit_to_var_nat_IMP_Minus_correct:\n  \"\\<lbrakk>(invoke_subprogram (p1 @ p2) var_bit_to_var_nat_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    \\<And>v. v \\<in> vars \\<Longrightarrow> \\<not> (set p2 \\<subseteq> set v);\n     \\<lbrakk>t = (var_bit_to_var_nat_imp_time 0 (var_bit_to_var_nat_imp_to_HOL_state (p1 @ p2) s));\n      s' (add_prefix (p1 @ p2) var_bit_to_var_nat_ret_str) =\n        var_bit_to_var_nat_ret\n          (var_bit_to_var_nat_imp (var_bit_to_var_nat_imp_to_HOL_state (p1 @ p2) s));\n      \\<And>v. v \\<in> vars \\<Longrightarrow> s (add_prefix p1 v) = s' (add_prefix p1 v)\\<rbrakk>\n     \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  using var_bit_to_var_nat_IMP_Minus_correct_time var_bit_to_var_nat_IMP_Minus_correct_function\n    var_bit_to_var_nat_IMP_Minus_correct_effects\n  by (meson set_mono_prefix)\n\n\nsubsection \\<open>operand_bit_to_var\\<close>\n\nsubsubsection \\<open>operand_bit_to_var_acc\\<close>\n\nfun operand_bit_to_var_acc':: \"nat \\<Rightarrow> nat \\<Rightarrow> nat\" where\n  \"operand_bit_to_var_acc' acc p  =\n  (if snd_nat p \\<noteq> 0\n   then (operand_bit_to_var_acc' ((fst_nat p) ## acc) (prod_encode (fst_nat p, snd_nat p - 1)))\n   else acc\n  )\"\n\nlemma operand_bit_to_var_acc'_correct:\n  \"operand_bit_to_var_acc' acc n = operand_bit_to_var_acc acc n\"\n  by (induction acc n rule : operand_bit_to_var_acc.induct) simp\n\nrecord operand_bit_to_var_acc_state =\n  operand_bit_to_var_acc_acc::nat\n  operand_bit_to_var_acc_n::nat\n  operand_bit_to_var_acc_ret::nat\n\nabbreviation \"operand_bit_to_var_acc_prefix \\<equiv> ''operand_bit_to_var_acc.''\"\nabbreviation \"operand_bit_to_var_acc_acc_str \\<equiv> ''acc''\"\nabbreviation \"operand_bit_to_var_acc_n_str \\<equiv> ''n''\"\nabbreviation \"operand_bit_to_var_acc_ret_str \\<equiv> ''ret''\"\n\ndefinition \"operand_bit_to_var_acc_state_upd s \\<equiv>\n  let\n    fst'_state_p' = operand_bit_to_var_acc_n s;\n    fst'_state = \\<lparr>fst'_state_p = fst'_state_p'\\<rparr>;\n    fst'_ret_state = fst'_imp fst'_state;\n    fst'_result = fst'_state_p fst'_ret_state;\n    snd'_state_p' = operand_bit_to_var_acc_n s;\n    snd'_state = \\<lparr>snd'_state_p = snd'_state_p'\\<rparr>;\n    snd'_ret_state = snd'_imp snd'_state;\n    snd'_result = snd'_state_p snd'_ret_state;\n    prod_encode_a' = fst'_result;\n    prod_encode_b' = snd'_result - 1;\n    prod_encode_ret' = 0;\n    prod_encode_state = \\<lparr>prod_encode_a = prod_encode_a',\n                         prod_encode_b = prod_encode_b',\n                         prod_encode_ret = prod_encode_ret'\\<rparr>;\n    prod_encode_ret_state = prod_encode_imp prod_encode_state;\n    prod_result = prod_encode_ret prod_encode_ret_state;\n    cons_h' = fst'_result;\n    cons_t' = operand_bit_to_var_acc_acc s;\n    cons_ret' = 0;\n    cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n    cons_ret_state = cons_imp cons_state;\n    cons_result = cons_ret cons_ret_state;\n    operand_bit_to_var_acc_acc' = cons_result;\n    operand_bit_to_var_acc_n' = prod_result;\n    operand_bit_to_var_acc_ret' = operand_bit_to_var_acc_ret s;\n    ret = \\<lparr>operand_bit_to_var_acc_acc = operand_bit_to_var_acc_acc',\n           operand_bit_to_var_acc_n = operand_bit_to_var_acc_n',\n           operand_bit_to_var_acc_ret = operand_bit_to_var_acc_ret'\\<rparr>\n  in\n    ret\n\"\n\ndefinition \"operand_bit_to_var_acc_imp_compute_loop_condition s \\<equiv>\n  let\n    snd'_state_p' = operand_bit_to_var_acc_n s;\n    snd'_state = \\<lparr>snd'_state_p = snd'_state_p'\\<rparr>;\n    snd'_ret_state = snd'_imp snd'_state;\n    condition = snd'_state_p snd'_ret_state\n  in condition\n\"\n\ndefinition \"operand_bit_to_var_acc_imp_after_loop s \\<equiv>\n  let\n    operand_bit_to_var_acc_acc' = operand_bit_to_var_acc_acc s;\n    operand_bit_to_var_acc_n' = operand_bit_to_var_acc_n s;\n    operand_bit_to_var_acc_ret' = operand_bit_to_var_acc_acc s;\n    ret = \\<lparr>operand_bit_to_var_acc_acc = operand_bit_to_var_acc_acc',\n           operand_bit_to_var_acc_n = operand_bit_to_var_acc_n',\n           operand_bit_to_var_acc_ret = operand_bit_to_var_acc_ret'\\<rparr>\n  in ret\n\"\n\nlemmas operand_bit_to_var_acc_imp_subprogram_simps =\n  operand_bit_to_var_acc_imp_after_loop_def\n  operand_bit_to_var_acc_state_upd_def\n  operand_bit_to_var_acc_imp_compute_loop_condition_def\n\nfunction operand_bit_to_var_acc_imp::\n  \"operand_bit_to_var_acc_state \\<Rightarrow> operand_bit_to_var_acc_state\" where\n  \"operand_bit_to_var_acc_imp s =\n  (if operand_bit_to_var_acc_imp_compute_loop_condition s \\<noteq> 0\n   then\n    (let next_iteration = operand_bit_to_var_acc_imp (operand_bit_to_var_acc_state_upd s)\n      in next_iteration)\n  else\n    (let ret = operand_bit_to_var_acc_imp_after_loop s in ret)\n  )\"\n  by simp+\ntermination\n  apply (relation \"measure operand_bit_to_var_acc_n\")\n   apply (simp add: operand_bit_to_var_acc_imp_subprogram_simps Let_def snd'_imp_correct\n      fst'_imp_correct prod_encode_imp_correct fst'_nat_def snd'_nat_def prod_encode_def\n      nat_less_le triangle_tsqrt_le triangle_nat_le_eq_le le_diff_conv)+\n  by (metis add_cancel_right_left add_diff_cancel_left' diff_diff_cancel diff_is_0_eq less_Suc0\n      nat_le_linear not_gr_zero triangle_tsqrt_le tsqrt_alt_inverse_triangle)\n\ndeclare operand_bit_to_var_acc_imp.simps [simp del]\n\nlemma operand_bit_to_var_acc_imp_correct[let_function_correctness]:\n  \"operand_bit_to_var_acc_ret (operand_bit_to_var_acc_imp s) =\n    operand_bit_to_var_acc' (operand_bit_to_var_acc_acc s) (operand_bit_to_var_acc_n s)\"\n  apply (induction s rule: operand_bit_to_var_acc_imp.induct)\n  apply (subst operand_bit_to_var_acc_imp.simps)\n  apply (subst operand_bit_to_var_acc'.simps)\n  by (simp del: operand_bit_to_var_acc'.simps add: operand_bit_to_var_acc_imp_subprogram_simps\n      snd'_imp_correct fst'_imp_correct prod_encode_imp_correct cons_imp_correct fst_nat_fst'_nat\n      snd_nat_snd'_nat Let_def)\n\ndefinition \"operand_bit_to_var_acc_state_upd_time t s \\<equiv>\n  let\n    fst'_state_p' = operand_bit_to_var_acc_n s;\n    t = t + 2;\n    fst'_state = \\<lparr>fst'_state_p = fst'_state_p'\\<rparr>;\n    fst'_ret_state = fst'_imp fst'_state;\n    t = t + fst'_imp_time 0 fst'_state;\n    fst'_result = fst'_state_p fst'_ret_state;\n    t = t + 2;\n    snd'_state_p' = operand_bit_to_var_acc_n s;\n    t = t + 2;\n    snd'_state = \\<lparr>snd'_state_p = snd'_state_p'\\<rparr>;\n    snd'_ret_state = snd'_imp snd'_state;\n    t = t + snd'_imp_time 0 snd'_state;\n    snd'_result = snd'_state_p snd'_ret_state;\n    t = t + 2;\n    prod_encode_a' = fst'_result;\n    t = t + 2;\n    prod_encode_b' = snd'_result - 1;\n    t = t + 2;\n    prod_encode_ret' = 0;\n    t = t + 2;\n    prod_encode_state = \\<lparr>prod_encode_a = prod_encode_a',\n                         prod_encode_b = prod_encode_b',\n                         prod_encode_ret = prod_encode_ret'\\<rparr>;\n    prod_encode_ret_state = prod_encode_imp prod_encode_state;\n    t = t + prod_encode_imp_time 0 prod_encode_state;\n    prod_result = prod_encode_ret prod_encode_ret_state;\n    t = t + 2;\n    cons_h' = fst'_result;\n    t = t + 2;\n    cons_t' = operand_bit_to_var_acc_acc s;\n    t = t + 2;\n    cons_ret' = 0;\n    t = t + 2;\n    cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n    cons_ret_state = cons_imp cons_state;\n    t = t + cons_imp_time 0 cons_state;\n    cons_result = cons_ret cons_ret_state;\n    t = t + 2;\n    operand_bit_to_var_acc_acc' = cons_result;\n    t = t + 2;\n    operand_bit_to_var_acc_n' = prod_result;\n    t = t + 2;\n    operand_bit_to_var_acc_ret' = operand_bit_to_var_acc_ret s;\n    t = t + 2;\n    ret = t\n  in\n    ret\n\"\n\ndefinition \"operand_bit_to_var_acc_imp_compute_loop_condition_time t s \\<equiv>\n  (let\n    snd'_state_p' = operand_bit_to_var_acc_n s;\n    t = t + 2;\n    snd'_state = \\<lparr>snd'_state_p = snd'_state_p'\\<rparr>;\n    snd'_ret_state = snd'_imp snd'_state;\n    t = t + snd'_imp_time 0 snd'_state;\n    condition = snd'_state_p snd'_ret_state;\n    t = t + 2;\n    ret = t\n   in ret\n  )\"\n\ndefinition \"operand_bit_to_var_acc_imp_after_loop_time t s \\<equiv>\n  (let\n    operand_bit_to_var_acc_ret' = operand_bit_to_var_acc_acc s;\n    t = t + 2;\n    ret = t\n   in ret\n  )\"\n\nlemmas operand_bit_to_var_acc_imp_subprogram_time_simps =\n  operand_bit_to_var_acc_imp_subprogram_simps\n  operand_bit_to_var_acc_imp_after_loop_time_def\n  operand_bit_to_var_acc_state_upd_time_def\n  operand_bit_to_var_acc_imp_compute_loop_condition_time_def\n\nfunction operand_bit_to_var_acc_imp_time:: \"nat \\<Rightarrow> operand_bit_to_var_acc_state \\<Rightarrow> nat\" where\n  \"operand_bit_to_var_acc_imp_time t s =\n  operand_bit_to_var_acc_imp_compute_loop_condition_time 0 s +\n  (if operand_bit_to_var_acc_imp_compute_loop_condition s \\<noteq> 0\n   then\n    (let\n        t = t + 1;\n        next_iteration\n          = operand_bit_to_var_acc_imp_time (t + operand_bit_to_var_acc_state_upd_time 0 s)\n                                            (operand_bit_to_var_acc_state_upd s)\n     in next_iteration)\n  else\n    (let\n        t = t + 2;\n        ret = t + operand_bit_to_var_acc_imp_after_loop_time 0 s\n     in ret)\n  )\"\n  by auto\ntermination\n  apply (relation \"measure (operand_bit_to_var_acc_n \\<circ> snd)\")\n   apply (simp add: operand_bit_to_var_acc_imp_subprogram_time_simps Let_def snd'_imp_correct\n      fst'_imp_correct prod_encode_imp_correct fst'_nat_def snd'_nat_def prod_encode_def\n      nat_less_le triangle_tsqrt_le triangle_nat_le_eq_le le_diff_conv)+\n  by (metis add_cancel_right_left add_diff_cancel_left' diff_diff_cancel diff_is_0_eq less_Suc0\n      nat_le_linear not_gr_zero triangle_tsqrt_le tsqrt_alt_inverse_triangle)\n\nlemmas [simp del] = operand_bit_to_var_acc_imp_time.simps\n\nlemma operand_bit_to_var_acc_imp_time_acc:\n  \"(operand_bit_to_var_acc_imp_time (Suc t) s) = Suc (operand_bit_to_var_acc_imp_time t s)\"\n  by (induction t s rule: operand_bit_to_var_acc_imp_time.induct)\n    ((subst (1 2) operand_bit_to_var_acc_imp_time.simps);\n      (simp add: operand_bit_to_var_acc_state_upd_def))\n\nlemma operand_bit_to_var_acc_imp_time_acc_2_aux:\n  \"(operand_bit_to_var_acc_imp_time x s) = x + (operand_bit_to_var_acc_imp_time 0 s)\"\n  by (induction x arbitrary: s)\n    (simp add: operand_bit_to_var_acc_imp_time_acc)+\n\nlemma operand_bit_to_var_acc_imp_time_acc_2:\n  \"x \\<noteq> 0 \\<Longrightarrow> (operand_bit_to_var_acc_imp_time x s) = x + (operand_bit_to_var_acc_imp_time 0 s)\"\n  by (rule operand_bit_to_var_acc_imp_time_acc_2_aux)\n\nlemma operand_bit_to_var_acc_imp_time_acc_3:\n  \"operand_bit_to_var_acc_imp_time (a + b) s = a + (operand_bit_to_var_acc_imp_time b s)\"\n  by (induction a arbitrary: b s) (simp add: operand_bit_to_var_acc_imp_time_acc)+\n\nabbreviation \"operand_bit_to_var_acc_while_cond \\<equiv> ''condition''\"\nabbreviation \"operand_bit_to_var_acc_fst'_result \\<equiv> ''fst'_result''\"\nabbreviation \"operand_bit_to_var_acc_snd'_result \\<equiv> ''snd'_result''\"\nabbreviation \"operand_bit_to_var_acc_prod_encode_result \\<equiv> ''prod_encode_result''\"\nabbreviation \"operand_bit_to_var_acc_cons_result \\<equiv> ''cons_result''\"\n\ndefinition \"operand_bit_to_var_acc_IMP_init_while_cond \\<equiv>\n  \\<comment> \\<open>    snd'_state_p' = operand_bit_to_var_acc_n s;\\<close>\n  (snd'_prefix @ snd'_p_str) ::= (A (V operand_bit_to_var_acc_n_str));;\n  \\<comment> \\<open>    snd'_state = \\<lparr>snd'_state_p = snd'_state_p'\\<rparr>;\\<close>\n  \\<comment> \\<open>    snd'_ret_state = snd'_imp snd'_state;\\<close>\n  invoke_subprogram snd'_prefix snd'_IMP_Minus;;\n  \\<comment> \\<open>    condition = snd'_state_p snd'_ret_state\\<close>\n  operand_bit_to_var_acc_while_cond ::= (A (V (snd'_prefix @ snd'_p_str)))\n\"\n\ndefinition \"operand_bit_to_var_acc_IMP_loop_body \\<equiv>\n  \\<comment> \\<open>fst'_state_p' = operand_bit_to_var_acc_n s;\\<close>\n  (fst'_prefix @ fst'_p_str) ::= (A (V operand_bit_to_var_acc_n_str));;\n  \\<comment> \\<open>fst'_state = \\<lparr>fst'_state_p = fst'_state_p'\\<rparr>;\\<close>\n  \\<comment> \\<open>fst'_ret_state = fst'_imp fst'_state;\\<close>\n  invoke_subprogram fst'_prefix fst'_IMP_Minus;;\n  operand_bit_to_var_acc_fst'_result ::= (A (V (fst'_prefix @ fst'_p_str)));;\n  \\<comment> \\<open>snd'_state_p' = operand_bit_to_var_acc_n s;\\<close>\n  (snd'_prefix @ snd'_p_str) ::= (A (V operand_bit_to_var_acc_n_str));;\n  \\<comment> \\<open>snd'_state = \\<lparr>snd'_state_p = snd'_state_p'\\<rparr>;\\<close>\n  \\<comment> \\<open>snd'_ret_state = snd'_imp snd'_state;\\<close>\n  invoke_subprogram snd'_prefix snd'_IMP_Minus;;\n  operand_bit_to_var_acc_snd'_result ::= (A (V (snd'_prefix @ snd'_p_str)));;\n  \\<comment> \\<open>prod_encode_a' = fst'_state_p fst'_ret_state;\\<close>\n  (prod_encode_prefix @ prod_encode_a_str) ::= (A (V operand_bit_to_var_acc_fst'_result));;\n  \\<comment> \\<open>prod_encode_b' = snd'_state_p snd'_ret_state - 1;\\<close>\n  (prod_encode_prefix @ prod_encode_b_str) ::= (Sub (V operand_bit_to_var_acc_snd'_result) (N 1));;\n  \\<comment> \\<open>prod_encode_ret' = 0;\\<close>\n  (prod_encode_prefix @ prod_encode_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>prod_encode_state = \\<lparr>prod_encode_a = prod_encode_a',\\<close>\n  \\<comment> \\<open>                     prod_encode_b = prod_encode_b',\\<close>\n  \\<comment> \\<open>                     prod_encode_ret = prod_encode_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>prod_encode_ret_state = prod_encode_imp prod_encode_state;\\<close>\n  invoke_subprogram prod_encode_prefix prod_encode_IMP_Minus;;\n  operand_bit_to_var_acc_prod_encode_result ::= (A (V (prod_encode_prefix @ prod_encode_ret_str)));;\n  \\<comment> \\<open>cons_h' = fst'_state_p fst'_ret_state;\\<close>\n  (cons_prefix @ cons_h_str) ::= (A (V operand_bit_to_var_acc_fst'_result));;\n  \\<comment> \\<open>cons_t' = operand_bit_to_var_acc_acc s;\\<close>\n  (cons_prefix @ cons_t_str) ::= (A (V operand_bit_to_var_acc_acc_str));;\n  \\<comment> \\<open>cons_ret' = 0;\\<close>\n  (cons_prefix @ cons_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>cons_ret_state = cons_imp cons_state;\\<close>\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n  operand_bit_to_var_acc_cons_result ::= (A (V (cons_prefix @ cons_ret_str)));;\n  \\<comment> \\<open>operand_bit_to_var_acc_acc' = cons_ret cons_ret_state;\\<close>\n  operand_bit_to_var_acc_acc_str ::= (A (V operand_bit_to_var_acc_cons_result));;\n  \\<comment> \\<open>operand_bit_to_var_acc_n' = prod_encode_ret prod_encode_ret_state;\\<close>\n  operand_bit_to_var_acc_n_str ::= (A (V operand_bit_to_var_acc_prod_encode_result));;\n  \\<comment> \\<open>operand_bit_to_var_acc_ret' = operand_bit_to_var_acc_ret s;\\<close>\n  operand_bit_to_var_acc_ret_str ::= (A (V operand_bit_to_var_acc_ret_str))\n  \\<comment> \\<open>ret = \\<lparr>operand_bit_to_var_acc_acc = operand_bit_to_var_acc_acc',\\<close>\n  \\<comment> \\<open>       operand_bit_to_var_acc_n = operand_bit_to_var_acc_n',\\<close>\n  \\<comment> \\<open>       operand_bit_to_var_acc_ret = operand_bit_to_var_acc_ret'\\<rparr>\\<close>\n\"\n\ndefinition \"operand_bit_to_var_acc_IMP_after_loop \\<equiv>\n  \\<comment> \\<open>operand_bit_to_var_acc_ret' = operand_bit_to_var_acc_acc s;\\<close>\n  operand_bit_to_var_acc_ret_str ::= (A (V operand_bit_to_var_acc_acc_str))\n  \\<comment> \\<open>ret = \\<lparr>operand_bit_to_var_acc_acc = operand_bit_to_var_acc_acc',\\<close>\n  \\<comment> \\<open>       operand_bit_to_var_acc_n = operand_bit_to_var_acc_n',\\<close>\n  \\<comment> \\<open>       operand_bit_to_var_acc_ret = operand_bit_to_var_acc_ret'\\<rparr>\\<close>\n\"\n\ndefinition operand_bit_to_var_acc_IMP_Minus where\n  \"operand_bit_to_var_acc_IMP_Minus \\<equiv>\n  operand_bit_to_var_acc_IMP_init_while_cond;;\n  WHILE operand_bit_to_var_acc_while_cond \\<noteq>0 DO (\n    operand_bit_to_var_acc_IMP_loop_body;;\n    operand_bit_to_var_acc_IMP_init_while_cond\n  );;\n  operand_bit_to_var_acc_IMP_after_loop\"\n\nabbreviation\n  \"operand_bit_to_var_acc_IMP_vars \\<equiv>\n  {operand_bit_to_var_acc_acc_str, operand_bit_to_var_acc_n_str, operand_bit_to_var_acc_ret_str,\n   operand_bit_to_var_acc_fst'_result, operand_bit_to_var_acc_snd'_result,\n   operand_bit_to_var_acc_prod_encode_result, operand_bit_to_var_acc_cons_result}\"\n\nlemmas operand_bit_to_var_acc_IMP_subprogram_simps =\n  operand_bit_to_var_acc_IMP_init_while_cond_def\n  operand_bit_to_var_acc_IMP_loop_body_def\n  operand_bit_to_var_acc_IMP_after_loop_def\n\ndefinition \"operand_bit_to_var_acc_imp_to_HOL_state p s =\n  \\<lparr>operand_bit_to_var_acc_acc = (s (add_prefix p operand_bit_to_var_acc_acc_str)),\n   operand_bit_to_var_acc_n = (s (add_prefix p operand_bit_to_var_acc_n_str)),\n   operand_bit_to_var_acc_ret = (s (add_prefix p operand_bit_to_var_acc_ret_str))\\<rparr>\"\n\nlemmas operand_bit_to_var_acc_state_translators =\n  fst'_imp_to_HOL_state_def\n  snd'_imp_to_HOL_state_def\n  prod_encode_imp_to_HOL_state_def\n  cons_imp_to_HOL_state_def\n  operand_bit_to_var_acc_imp_to_HOL_state_def\n\nlemmas operand_bit_to_var_acc_complete_simps =\n  operand_bit_to_var_acc_IMP_subprogram_simps\n  operand_bit_to_var_acc_imp_subprogram_simps\n  operand_bit_to_var_acc_state_translators\n\nlemma operand_bit_to_var_acc_IMP_Minus_correct_function:\n  \"(invoke_subprogram p operand_bit_to_var_acc_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p operand_bit_to_var_acc_ret_str)\n      = operand_bit_to_var_acc_ret\n          (operand_bit_to_var_acc_imp (operand_bit_to_var_acc_imp_to_HOL_state p s))\"\n  apply(induction \"operand_bit_to_var_acc_imp_to_HOL_state p s\" arbitrary: s s' t\n      rule: operand_bit_to_var_acc_imp.induct)\n  apply(subst operand_bit_to_var_acc_imp.simps)\n  apply(simp only: operand_bit_to_var_acc_IMP_Minus_def prefix_simps)\n  apply(erule Seq_E)+\n  apply(erule While_tE)\n\n  subgoal\n    apply(simp only: operand_bit_to_var_acc_IMP_subprogram_simps)\n    apply(simp only: prefix_simps)\n    apply(erule Seq_E)+\n    apply(erule snd'_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(8) by fastforce\n    by(fastforce simp: operand_bit_to_var_acc_IMP_subprogram_simps\n        operand_bit_to_var_acc_imp_subprogram_simps\n        operand_bit_to_var_acc_state_translators)\n\n  apply(erule Seq_E)+\n  apply(dest_com_gen)\n\n  subgoal\n    apply(simp only: operand_bit_to_var_acc_IMP_init_while_cond_def prefix_simps)\n    apply(erule Seq_E)+\n    apply(erule snd'_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(10) by fastforce\n    by(fastforce_sorted_premises simp: operand_bit_to_var_acc_complete_simps)\n\n  subgoal\n    apply(subst (asm) operand_bit_to_var_acc_IMP_init_while_cond_def)\n    apply(simp only: operand_bit_to_var_acc_IMP_loop_body_def prefix_simps)\n    apply(erule Seq_E)+\n    apply(erule snd'_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(26) by fastforce\n    apply(erule snd'_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(28) by fastforce\n    apply(erule fst'_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(30) by fastforce\n    apply(erule cons_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(32) by fastforce\n    apply(erule prod_encode_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(34) by fastforce\n    by (fastforce_sorted_premises simp: operand_bit_to_var_acc_imp_subprogram_simps\n        operand_bit_to_var_acc_state_translators Let_def)\n\n  subgoal\n    apply(simp only: operand_bit_to_var_acc_IMP_init_while_cond_def prefix_simps\n        operand_bit_to_var_acc_IMP_loop_body_def)\n    apply(erule Seq_E)+\n    apply(erule snd'_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(28) by fastforce\n    apply(erule snd'_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(30) by fastforce\n    apply(erule snd'_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(32) by fastforce\n    apply(erule fst'_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(34) by fastforce\n    apply(erule cons_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(36) by fastforce\n    apply(erule prod_encode_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(38) by fastforce\n    by (fastforce_sorted_premises simp: operand_bit_to_var_acc_imp_subprogram_simps\n        operand_bit_to_var_acc_state_translators Let_def)\n  done\n\nlemma operand_bit_to_var_acc_IMP_Minus_correct_effects:\n  \"\\<lbrakk>(invoke_subprogram (p @ operand_bit_to_var_acc_pref)\n                       operand_bit_to_var_acc_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    v \\<in> vars; \\<not> (prefix operand_bit_to_var_acc_pref v)\\<rbrakk>\n   \\<Longrightarrow> s (add_prefix p v) = s' (add_prefix p v)\"\n  using com_add_prefix_valid'' com_only_vars prefix_def\n  by blast\n\nlemmas operand_bit_to_var_acc_complete_time_simps =\n  operand_bit_to_var_acc_imp_subprogram_time_simps\n  operand_bit_to_var_acc_imp_time_acc_2\n  operand_bit_to_var_acc_imp_time_acc_3\n  operand_bit_to_var_acc_state_translators\n\nlemma operand_bit_to_var_acc_IMP_Minus_correct_time:\n  \"(invoke_subprogram p operand_bit_to_var_acc_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = operand_bit_to_var_acc_imp_time 0 (operand_bit_to_var_acc_imp_to_HOL_state p s)\"\n  apply(induction \"operand_bit_to_var_acc_imp_to_HOL_state p s\" arbitrary: s s' t\n      rule: operand_bit_to_var_acc_imp.induct)\n  apply(subst operand_bit_to_var_acc_imp_time.simps)\n  apply(simp only: operand_bit_to_var_acc_IMP_Minus_def prefix_simps)\n\n  apply(erule Seq_tE)+\n  apply(erule While_tE_time)\n\n  subgoal\n    apply(simp only: operand_bit_to_var_acc_IMP_subprogram_simps prefix_simps)\n    apply(erule Seq_tE)+\n    apply(erule snd'_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(12) by fastforce\n    by (force simp: operand_bit_to_var_acc_IMP_subprogram_simps\n        operand_bit_to_var_acc_imp_subprogram_time_simps operand_bit_to_var_acc_state_translators)\n\n  apply(erule Seq_tE)+\n  apply(simp add: add.assoc)\n  apply(dest_com_gen_time)\n\n  subgoal\n    apply(simp only: operand_bit_to_var_acc_IMP_init_while_cond_def prefix_simps)\n    apply(erule Seq_E)+\n    apply(erule snd'_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(13) by fastforce\n    by(fastforce_sorted_premises simp: operand_bit_to_var_acc_complete_simps)\n\n  subgoal\n    apply(subst (asm) operand_bit_to_var_acc_IMP_init_while_cond_def)\n    apply(simp only: operand_bit_to_var_acc_IMP_loop_body_def prefix_simps)\n    apply(erule Seq_E)+\n    apply(erule snd'_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(29) by fastforce\n    apply(erule snd'_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(31) by fastforce\n    apply(erule fst'_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(33) by fastforce\n    apply(erule cons_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(35) by fastforce\n    apply(erule prod_encode_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(37) by fastforce\n    by(fastforce_sorted_premises simp: operand_bit_to_var_acc_complete_time_simps Let_def)\n\n  subgoal\n    apply(simp only: prefix_simps operand_bit_to_var_acc_IMP_init_while_cond_def\n        operand_bit_to_var_acc_IMP_loop_body_def)\n    apply(erule Seq_tE)+\n    apply(erule snd'_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(53) by fastforce\n    apply(erule snd'_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(55) by fastforce\n    apply(erule snd'_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(57) by fastforce\n    apply(erule fst'_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(59) by fastforce\n    apply(erule cons_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(61) by fastforce\n    apply(erule prod_encode_IMP_Minus_correct[where vars = \"operand_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(63) by fastforce\n    by(fastforce_sorted_premises simp: Let_def operand_bit_to_var_acc_complete_time_simps)\n  done\n\nlemma operand_bit_to_var_acc_IMP_Minus_correct:\n  \"\\<lbrakk>(invoke_subprogram (p1 @ p2) operand_bit_to_var_acc_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    \\<And>v. v \\<in> vars \\<Longrightarrow> \\<not> (set p2 \\<subseteq> set v);\n    \\<lbrakk>t = (operand_bit_to_var_acc_imp_time 0 (operand_bit_to_var_acc_imp_to_HOL_state (p1 @ p2) s));\n     s' (add_prefix (p1 @ p2) operand_bit_to_var_acc_ret_str) =\n          operand_bit_to_var_acc_ret (operand_bit_to_var_acc_imp\n                                        (operand_bit_to_var_acc_imp_to_HOL_state (p1 @ p2) s));\n     \\<And>v. v \\<in> vars \\<Longrightarrow> s (add_prefix p1 v) = s' (add_prefix p1 v)\\<rbrakk>\n   \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  using operand_bit_to_var_acc_IMP_Minus_correct_function\n  by (auto simp: operand_bit_to_var_acc_IMP_Minus_correct_time)\n    (meson operand_bit_to_var_acc_IMP_Minus_correct_effects set_mono_prefix)\n\n\nsubsubsection \\<open>operand_bit_to_var_tail\\<close>\n\nrecord operand_bit_to_var_tail_state =\n  operand_bit_to_var_tail_n::nat\n  operand_bit_to_var_tail_ret::nat\n\nabbreviation \"operand_bit_to_var_tail_prefix \\<equiv> ''operand_bit_to_var_tail.''\"\nabbreviation \"operand_bit_to_var_tail_n_str \\<equiv> ''n''\"\nabbreviation \"operand_bit_to_var_tail_ret_str \\<equiv> ''ret''\"\n\ndefinition \"operand_bit_to_var_tail_state_upd s =\n  (let\n      fst'_state_p' = operand_bit_to_var_tail_n s;\n      fst'_state = \\<lparr>fst'_state_p = fst'_state_p'\\<rparr>;\n      fst'_ret_state = fst'_imp fst'_state;\n      fst'_result = fst'_state_p fst'_ret_state;\n      cons_h' = fst'_result;\n      cons_t' = 0;\n      cons_ret' = 0;\n      cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n      cons_ret_state = cons_imp cons_state;\n      cons_result = cons_ret cons_ret_state;\n      operand_bit_to_var_acc_acc' = cons_result;\n      operand_bit_to_var_acc_n' = operand_bit_to_var_tail_n s;\n      operand_bit_to_var_acc_ret' = 0;\n      operand_bit_to_var_acc_state =\n        \\<lparr>operand_bit_to_var_acc_acc = operand_bit_to_var_acc_acc',\n         operand_bit_to_var_acc_n = operand_bit_to_var_acc_n',\n         operand_bit_to_var_acc_ret = operand_bit_to_var_acc_ret'\\<rparr>;\n      operand_bit_to_var_acc_ret_state = operand_bit_to_var_acc_imp operand_bit_to_var_acc_state;\n      operand_bit_to_var_acc_result = operand_bit_to_var_acc_ret operand_bit_to_var_acc_ret_state;\n      operand_bit_to_var_tail_n' = operand_bit_to_var_tail_n s;\n      operand_bit_to_var_tail_ret' = operand_bit_to_var_acc_result;\n      ret = \\<lparr>operand_bit_to_var_tail_n = operand_bit_to_var_tail_n',\n             operand_bit_to_var_tail_ret = operand_bit_to_var_tail_ret'\\<rparr>\n    in\n      ret\n  )\"\n\nfunction operand_bit_to_var_tail_imp::\n  \"operand_bit_to_var_tail_state \\<Rightarrow> operand_bit_to_var_tail_state\" where\n  \"operand_bit_to_var_tail_imp s =\n  (let\n      ret = operand_bit_to_var_tail_state_upd s\n    in\n      ret\n  )\"\n  by simp+\ntermination\n  by (relation \"measure (\\<lambda>s. operand_bit_to_var_tail_n s)\") simp\n\ndeclare operand_bit_to_var_tail_imp.simps [simp del]\n\nlemma operand_bit_to_var_tail_imp_correct[let_function_correctness]:\n  \"operand_bit_to_var_tail_ret (operand_bit_to_var_tail_imp s) =\n    operand_bit_to_var_tail (operand_bit_to_var_tail_n s)\"\n  by(simp add: operand_bit_to_var_tail_imp.simps operand_bit_to_var_tail_state_upd_def\n      fst'_imp_correct cons_imp_correct)\n    (simp only: operand_bit_to_var_tail_def operand_bit_to_var_acc_imp_correct\n      operand_bit_to_var_acc'_correct operand_bit_to_var_acc_state.simps fst_nat_fst'_nat)\n\nfunction operand_bit_to_var_tail_imp_time:: \"nat \\<Rightarrow> operand_bit_to_var_tail_state \\<Rightarrow> nat\" where\n  \"operand_bit_to_var_tail_imp_time t s =\n    (let\n      fst'_state_p' = operand_bit_to_var_tail_n s;\n      t = t + 2;\n      fst'_state = \\<lparr>fst'_state_p = fst'_state_p'\\<rparr>;\n      fst'_ret_state = fst'_imp fst'_state;\n      t = t + fst'_imp_time 0 fst'_state;\n      fst'_result = fst'_state_p fst'_ret_state;\n      t = t + 2;\n      cons_h' = fst'_result;\n      t = t + 2;\n      cons_t' = 0;\n      t = t + 2;\n      cons_ret' = 0;\n      t = t + 2;\n      cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n      cons_ret_state = cons_imp cons_state;\n      t = t + cons_imp_time 0 cons_state;\n      cons_result = cons_ret cons_ret_state;\n      t = t + 2;\n      operand_bit_to_var_acc_acc' = cons_result;\n      t = t + 2;\n      operand_bit_to_var_acc_n' = operand_bit_to_var_tail_n s;\n      t = t + 2;\n      operand_bit_to_var_acc_ret' = 0;\n      t = t + 2;\n      operand_bit_to_var_acc_state =\n        \\<lparr>operand_bit_to_var_acc_acc = operand_bit_to_var_acc_acc',\n         operand_bit_to_var_acc_n = operand_bit_to_var_acc_n',\n         operand_bit_to_var_acc_ret = operand_bit_to_var_acc_ret'\\<rparr>;\n      operand_bit_to_var_acc_ret_state = operand_bit_to_var_acc_imp operand_bit_to_var_acc_state;\n      t = t + operand_bit_to_var_acc_imp_time 0 operand_bit_to_var_acc_state;\n      operand_bit_to_var_acc_result = operand_bit_to_var_acc_ret operand_bit_to_var_acc_ret_state;\n      t = t + 2;\n      operand_bit_to_var_tail_n' = operand_bit_to_var_tail_n s;\n      t = t + 2;\n      operand_bit_to_var_tail_ret' = operand_bit_to_var_acc_result;\n      t = t + 2;\n      ret = \\<lparr>operand_bit_to_var_tail_n = operand_bit_to_var_tail_n',\n             operand_bit_to_var_tail_ret = operand_bit_to_var_tail_ret'\\<rparr>\n    in\n      t\n  )\"\n  by auto\ntermination\n  by (relation \"measure (\\<lambda>(t, s). operand_bit_to_var_tail_n s)\") simp\n\nlemmas [simp del] = operand_bit_to_var_tail_imp_time.simps\n\nlemma operand_bit_to_var_tail_imp_time_acc:\n  \"(operand_bit_to_var_tail_imp_time (Suc t) s) = Suc (operand_bit_to_var_tail_imp_time t s)\"\n  by (induction t s rule: operand_bit_to_var_tail_imp_time.induct)\n    ((subst (1 2) operand_bit_to_var_tail_imp_time.simps); (simp add: Let_def))\n\nlemma operand_bit_to_var_tail_imp_time_acc_2_aux:\n  \"(operand_bit_to_var_tail_imp_time x s) = x + (operand_bit_to_var_tail_imp_time 0 s)\"\n  by (induction x arbitrary: s)\n    (simp add: operand_bit_to_var_tail_imp_time_acc)+\n\nlemma operand_bit_to_var_tail_imp_time_acc_2:\n  \"x \\<noteq> 0 \\<Longrightarrow> (operand_bit_to_var_tail_imp_time x s) = x + (operand_bit_to_var_tail_imp_time 0 s)\"\n  by (rule operand_bit_to_var_tail_imp_time_acc_2_aux)\n\nlemma operand_bit_to_var_tail_imp_time_acc_3:\n  \"operand_bit_to_var_tail_imp_time (a + b) s = a + (operand_bit_to_var_tail_imp_time b s)\"\n  by (induction a arbitrary: b s) (simp add: operand_bit_to_var_tail_imp_time_acc)+\n\nabbreviation \"operand_bit_to_var_tail_fst'_result \\<equiv> ''fst'_result''\"\nabbreviation \"operand_bit_to_var_tail_cons_result \\<equiv> ''cons_result''\"\nabbreviation\n  \"operand_bit_to_var_tail_operand_bit_to_var_tail_result \\<equiv> ''operand_bit_to_var_tail_result''\"\n\ndefinition \"operand_bit_to_var_tail_IMP_Minus \\<equiv>\n  \\<comment> \\<open>    fst'_state_p' = operand_bit_to_var_tail_n s;\\<close>\n  (fst'_prefix @ fst'_p_str) ::= (A (V operand_bit_to_var_tail_n_str));;\n  \\<comment> \\<open>    fst'_state = \\<lparr>fst'_state_p = fst'_state_p'\\<rparr>;\\<close>\n  \\<comment> \\<open>    fst'_ret_state = fst'_imp fst'_state;\\<close>\n  invoke_subprogram fst'_prefix fst'_IMP_Minus;;\n  \\<comment> \\<open>    fst'_result = fst'_state_p fst'_ret_state;\\<close>\n  operand_bit_to_var_tail_fst'_result ::= (A (V (fst'_prefix @ fst'_p_str)));;\n  \\<comment> \\<open>    cons_h' = fst'_result;\\<close>\n  (cons_prefix @ cons_h_str) ::= (A (V operand_bit_to_var_tail_fst'_result));;\n  \\<comment> \\<open>    cons_t' = 0;\\<close>\n  (cons_prefix @ cons_t_str) ::= (A (N 0));;\n  \\<comment> \\<open>    cons_ret' = 0;\\<close>\n  (cons_prefix @ cons_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>    cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>    cons_ret_state = cons_imp cons_state;\\<close>\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n  \\<comment> \\<open>    cons_result = cons_ret cons_ret_state;\\<close>\n  operand_bit_to_var_tail_cons_result ::= (A (V (cons_prefix @ cons_ret_str)));;\n  \\<comment> \\<open>    operand_bit_to_var_acc_acc' = cons_result;\\<close>\n  (operand_bit_to_var_acc_prefix @ operand_bit_to_var_acc_acc_str) ::=\n    (A (V operand_bit_to_var_tail_cons_result));;\n  \\<comment> \\<open>    operand_bit_to_var_acc_n' = operand_bit_to_var_tail_n s;\\<close>\n  (operand_bit_to_var_acc_prefix @ operand_bit_to_var_acc_n_str) ::=\n    (A (V operand_bit_to_var_tail_n_str));;\n  \\<comment> \\<open>    operand_bit_to_var_acc_ret' = 0;\\<close>\n  (operand_bit_to_var_acc_prefix @ operand_bit_to_var_acc_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>    operand_bit_to_var_acc_state =\\<close>\n  \\<comment> \\<open>      \\<lparr>operand_bit_to_var_acc_acc = operand_bit_to_var_acc_acc',\\<close>\n  \\<comment> \\<open>       operand_bit_to_var_acc_n = operand_bit_to_var_acc_n',\\<close>\n  \\<comment> \\<open>       operand_bit_to_var_acc_ret = operand_bit_to_var_acc_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>    operand_bit_to_var_acc_ret_state =\n            operand_bit_to_var_acc_imp operand_bit_to_var_acc_state;\\<close>\n  invoke_subprogram operand_bit_to_var_acc_prefix operand_bit_to_var_acc_IMP_Minus;;\n  \\<comment> \\<open>    operand_bit_to_var_acc_result =\n            operand_bit_to_var_acc_ret operand_bit_to_var_acc_ret_state;\\<close>\n  operand_bit_to_var_tail_operand_bit_to_var_tail_result ::=\n    (A (V (operand_bit_to_var_acc_prefix @ operand_bit_to_var_acc_ret_str)));;\n  \\<comment> \\<open>    operand_bit_to_var_tail_n' = operand_bit_to_var_tail_n s;\\<close>\n  operand_bit_to_var_tail_n_str ::= (A (V operand_bit_to_var_tail_n_str));;\n  \\<comment> \\<open>    operand_bit_to_var_tail_ret' = operand_bit_to_var_acc_result;\\<close>\n  operand_bit_to_var_tail_ret_str ::= (A (V operand_bit_to_var_tail_operand_bit_to_var_tail_result))\n  \\<comment> \\<open>    ret = \\<lparr>operand_bit_to_var_tail_n = operand_bit_to_var_tail_n',\\<close>\n  \\<comment> \\<open>           operand_bit_to_var_tail_ret = operand_bit_to_var_tail_ret'\\<rparr>\\<close>\n  \"\n\nabbreviation\n  \"operand_bit_to_var_tail_IMP_vars \\<equiv>\n  {operand_bit_to_var_tail_n_str, operand_bit_to_var_tail_ret_str,\n   operand_bit_to_var_tail_fst'_result, operand_bit_to_var_tail_cons_result,\n   operand_bit_to_var_tail_operand_bit_to_var_tail_result}\"\n\ndefinition \"operand_bit_to_var_tail_imp_to_HOL_state p s =\n  \\<lparr>operand_bit_to_var_tail_n = (s (add_prefix p operand_bit_to_var_tail_n_str)),\n   operand_bit_to_var_tail_ret = (s (add_prefix p operand_bit_to_var_tail_ret_str))\\<rparr>\"\n\nlemmas operand_bit_to_var_tail_state_translators =\n  fst'_imp_to_HOL_state_def\n  cons_imp_to_HOL_state_def\n  operand_bit_to_var_acc_imp_to_HOL_state_def\n  operand_bit_to_var_tail_imp_to_HOL_state_def\n\nlemma operand_bit_to_var_tail_IMP_Minus_correct_function:\n  \"(invoke_subprogram p operand_bit_to_var_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p operand_bit_to_var_tail_ret_str)\n      = operand_bit_to_var_tail_ret\n  (operand_bit_to_var_tail_imp (operand_bit_to_var_tail_imp_to_HOL_state p s))\"\n  apply(simp only: operand_bit_to_var_tail_IMP_Minus_def prefix_simps)\n  apply(erule Seq_E)+\n  apply(erule fst'_IMP_Minus_correct[where vars=operand_bit_to_var_tail_IMP_vars])\n  subgoal premises p using p(15) by fastforce\n  apply(erule cons_IMP_Minus_correct[where vars=operand_bit_to_var_tail_IMP_vars])\n  subgoal premises p using p(17) by fastforce\n  apply(erule operand_bit_to_var_acc_IMP_Minus_correct[where vars=operand_bit_to_var_tail_IMP_vars])\n  subgoal premises p using p(19) by fastforce\n  by (fastforce simp: operand_bit_to_var_tail_state_translators operand_bit_to_var_tail_imp.simps\n      operand_bit_to_var_tail_state_upd_def)\n\nlemma operand_bit_to_var_tail_IMP_Minus_correct_effects:\n  \"\\<lbrakk>(invoke_subprogram (p @ operand_bit_to_var_tail_pref) operand_bit_to_var_tail_IMP_Minus, s)\n      \\<Rightarrow>\\<^bsup>t\\<^esup> s'; v \\<in> vars; \\<not> (prefix operand_bit_to_var_tail_pref v)\\<rbrakk>\n  \\<Longrightarrow> s (add_prefix p v) = s' (add_prefix p v)\"\n  using com_add_prefix_valid'' com_only_vars prefix_def\n  by blast\n\nlemma operand_bit_to_var_tail_IMP_Minus_correct_time:\n  \"(invoke_subprogram p operand_bit_to_var_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = operand_bit_to_var_tail_imp_time 0 (operand_bit_to_var_tail_imp_to_HOL_state p s)\"\n  apply(simp only: operand_bit_to_var_tail_IMP_Minus_def prefix_simps)\n  apply(erule Seq_tE)+\n  apply(erule fst'_IMP_Minus_correct[where vars=operand_bit_to_var_tail_IMP_vars])\n  subgoal premises p using p(29) by fastforce\n  apply(erule cons_IMP_Minus_correct[where vars=operand_bit_to_var_tail_IMP_vars])\n  subgoal premises p using p(31) by fastforce\n  apply(erule operand_bit_to_var_acc_IMP_Minus_correct[where vars=operand_bit_to_var_tail_IMP_vars])\n  subgoal premises p using p(33) by fastforce\n  by (fastforce simp: operand_bit_to_var_tail_state_translators Let_def\n      operand_bit_to_var_tail_imp_time.simps operand_bit_to_var_tail_state_upd_def )\n\nlemma operand_bit_to_var_tail_IMP_Minus_correct[functional_correctness]:\n  \"\\<lbrakk>(invoke_subprogram (p1 @ p2) operand_bit_to_var_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    \\<And>v. v \\<in> vars \\<Longrightarrow> \\<not> (set p2 \\<subseteq> set v);\n     \\<lbrakk>t = (operand_bit_to_var_tail_imp_time 0\n            (operand_bit_to_var_tail_imp_to_HOL_state (p1 @ p2) s));\n      s' (add_prefix (p1 @ p2) operand_bit_to_var_tail_ret_str) =\n        operand_bit_to_var_tail_ret\n          (operand_bit_to_var_tail_imp (operand_bit_to_var_tail_imp_to_HOL_state (p1 @ p2) s));\n      \\<And>v. v \\<in> vars \\<Longrightarrow> s (add_prefix p1 v) = s' (add_prefix p1 v)\\<rbrakk>\n     \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  using operand_bit_to_var_tail_IMP_Minus_correct_time\n    operand_bit_to_var_tail_IMP_Minus_correct_function\n    operand_bit_to_var_tail_IMP_Minus_correct_effects\n  by (meson set_mono_prefix)\n\n\nsubsection \\<open>var_to_operand_bit_nat\\<close>\n\nfun var_to_operand_bit_tail':: \"nat \\<Rightarrow> nat\" where\n  \"var_to_operand_bit_tail' v  =\n  (let l = length_nat v in\n  (if l \\<noteq> 0 then (\n      let r = (prod_encode (hd_nat v, l - 1)) in\n      if  v = operand_bit_to_var_tail r then\n        r + 1\n      else 0)\n   else 0))\"\n\nlemma var_to_operand_bit_tail'_correct:\n  \"var_to_operand_bit_tail' v = var_to_operand_bit_tail v\"\n  unfolding var_to_operand_bit_tail_def\n  using some_nat_def var_to_operand_bit_tail'.simps\n  by (smt (verit, del_insts) Zero_not_Suc add.commute length_nat.elims plus_1_eq_Suc)\n\n\nsubsubsection \\<open>var_to_operand_bit_tail_aux\\<close>\n\nfun var_to_operand_bit_tail_aux :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat\" where\n  \"var_to_operand_bit_tail_aux v l =\n  (let r = (prod_encode (hd_nat v, l - 1))\n  in if v = operand_bit_to_var_tail r\n     then r + 1\n     else 0\n  )\"\n\nrecord var_to_operand_bit_tail_aux_state =\n  var_to_operand_bit_tail_aux_v::nat\n  var_to_operand_bit_tail_aux_l::nat\n  var_to_operand_bit_tail_aux_ret::nat\n\nabbreviation \"var_to_operand_bit_tail_aux_prefix \\<equiv> ''var_to_operand_bit_tail_aux.''\"\nabbreviation \"var_to_operand_bit_tail_aux_v_str \\<equiv> ''v''\"\nabbreviation \"var_to_operand_bit_tail_aux_l_str \\<equiv> ''l''\"\nabbreviation \"var_to_operand_bit_tail_aux_ret_str \\<equiv> ''ret''\"\n\ndefinition \"var_to_operand_bit_tail_aux_state_upd s =\n  (let\n      hd_xs' = var_to_operand_bit_tail_aux_v s;\n      hd_ret' = 0;\n      hd_state = \\<lparr>hd_xs = hd_xs', \n                  hd_ret = hd_ret'\\<rparr>;\n      hd_ret_state = hd_imp hd_state;\n      prod_encode_a' = hd_ret hd_ret_state;\n      prod_encode_b' = var_to_operand_bit_tail_aux_l s - 1;\n      prod_encode_ret' = 0;\n      prod_encode_state = \\<lparr>prod_encode_a = prod_encode_a',\n                           prod_encode_b = prod_encode_b',\n                           prod_encode_ret = prod_encode_ret'\\<rparr>;\n      prod_encode_ret_state = prod_encode_imp prod_encode_state;\n      prod_encode_result = prod_encode_ret prod_encode_ret_state;\n      operand_bit_to_var_tail_n' = prod_encode_result;\n      operand_bit_to_var_tail_ret' = 0;\n      operand_bit_to_var_tail_state = \\<lparr>operand_bit_to_var_tail_n = operand_bit_to_var_tail_n',\n                                       operand_bit_to_var_tail_ret = operand_bit_to_var_tail_ret'\\<rparr>;\n      operand_bit_to_var_tail_ret_state = operand_bit_to_var_tail_imp operand_bit_to_var_tail_state;\n      EQUAL_neq_zero_a' = var_to_operand_bit_tail_aux_v s;\n      EQUAL_neq_zero_b' = operand_bit_to_var_tail_ret operand_bit_to_var_tail_ret_state;\n      EQUAL_neq_zero_ret' = 0;\n      EQUAL_neq_zero_state = \\<lparr>EQUAL_neq_zero_a = EQUAL_neq_zero_a',\n                              EQUAL_neq_zero_b = EQUAL_neq_zero_b',\n                              EQUAL_neq_zero_ret = EQUAL_neq_zero_ret'\\<rparr>;\n      EQUAL_neq_zero_ret_state = EQUAL_neq_zero_imp EQUAL_neq_zero_state;\n      EQUAL_neq_zero_result = EQUAL_neq_zero_ret EQUAL_neq_zero_ret_state\n  in\n  (if EQUAL_neq_zero_result \\<noteq> 0 then\n    (let\n      var_to_operand_bit_tail_aux_ret' = prod_encode_result + 1;\n      ret = \\<lparr>var_to_operand_bit_tail_aux_v = var_to_operand_bit_tail_aux_v s,\n             var_to_operand_bit_tail_aux_l = var_to_operand_bit_tail_aux_l s,\n             var_to_operand_bit_tail_aux_ret = var_to_operand_bit_tail_aux_ret'\\<rparr>\n    in\n      ret\n    )\n  else\n    (let\n      var_to_operand_bit_tail_aux_ret' = 0;\n      ret = \\<lparr>var_to_operand_bit_tail_aux_v = var_to_operand_bit_tail_aux_v s,\n             var_to_operand_bit_tail_aux_l = var_to_operand_bit_tail_aux_l s,\n             var_to_operand_bit_tail_aux_ret = var_to_operand_bit_tail_aux_ret'\\<rparr>\n    in\n      ret\n    )\n  )\n)\"\n\nfunction var_to_operand_bit_tail_aux_imp ::\n  \"var_to_operand_bit_tail_aux_state \\<Rightarrow> var_to_operand_bit_tail_aux_state\" where\n  \"var_to_operand_bit_tail_aux_imp s =\n  (let \n      ret = var_to_operand_bit_tail_aux_state_upd s\n    in \n      ret\n  )\"\n  by simp+\ntermination\n  by (relation \"measure var_to_operand_bit_tail_aux_v\") simp\n\ndeclare var_to_operand_bit_tail_aux_imp.simps [simp del]\n\nlemma var_to_operand_bit_tail_aux_imp_correct[let_function_correctness]:\n  \"var_to_operand_bit_tail_aux_ret (var_to_operand_bit_tail_aux_imp s) =\n    var_to_operand_bit_tail_aux (var_to_operand_bit_tail_aux_v s) (var_to_operand_bit_tail_aux_l s)\"\n  apply (simp only: var_to_operand_bit_tail_aux_imp.simps Let_def prod_encode_imp_correct hd_imp_correct\n  EQUAL_neq_zero_imp_correct operand_bit_to_var_tail_imp_correct var_to_operand_bit_tail_aux_state_upd_def)\n  by simp   \n\nfunction var_to_operand_bit_tail_aux_imp_time ::\n  \"nat \\<Rightarrow> var_to_operand_bit_tail_aux_state \\<Rightarrow> nat\" where\n  \"var_to_operand_bit_tail_aux_imp_time t s =\n  (let\n      hd_xs' = var_to_operand_bit_tail_aux_v s;\n      t = t + 2;\n      hd_ret' = 0;\n      t = t + 2;\n      hd_state = \\<lparr>hd_xs = hd_xs', \n                  hd_ret = hd_ret'\\<rparr>;\n      hd_ret_state = hd_imp hd_state;    \n      t = t + hd_imp_time 0 hd_state;\n      prod_encode_a' = hd_ret hd_ret_state;\n      t = t + 2;\n      prod_encode_b' = var_to_operand_bit_tail_aux_l s - 1;\n      t = t + 2;\n      prod_encode_ret' = 0;\n      t = t + 2;\n      prod_encode_state = \\<lparr>prod_encode_a = prod_encode_a',\n                           prod_encode_b = prod_encode_b',\n                           prod_encode_ret = prod_encode_ret'\\<rparr>;\n      prod_encode_ret_state = prod_encode_imp prod_encode_state;\n      t = t + prod_encode_imp_time 0 prod_encode_state;\n      prod_encode_result = prod_encode_ret prod_encode_ret_state;\n      t = t + 2;\n      operand_bit_to_var_tail_n' = prod_encode_result;\n      t = t + 2;\n      operand_bit_to_var_tail_ret' = 0;\n      t = t + 2;\n      operand_bit_to_var_tail_state = \\<lparr>operand_bit_to_var_tail_n = operand_bit_to_var_tail_n',\n                                       operand_bit_to_var_tail_ret = operand_bit_to_var_tail_ret'\\<rparr>;\n      operand_bit_to_var_tail_ret_state = operand_bit_to_var_tail_imp operand_bit_to_var_tail_state;\n      t = t + operand_bit_to_var_tail_imp_time 0 operand_bit_to_var_tail_state;\n      EQUAL_neq_zero_a' = var_to_operand_bit_tail_aux_v s;\n      t = t + 2;\n      EQUAL_neq_zero_b' = operand_bit_to_var_tail_ret operand_bit_to_var_tail_ret_state;\n      t = t + 2;\n      EQUAL_neq_zero_ret' = 0;\n      t = t + 2;\n      EQUAL_neq_zero_state = \\<lparr>EQUAL_neq_zero_a = EQUAL_neq_zero_a',\n                              EQUAL_neq_zero_b = EQUAL_neq_zero_b',\n                              EQUAL_neq_zero_ret = EQUAL_neq_zero_ret'\\<rparr>;\n      EQUAL_neq_zero_ret_state = EQUAL_neq_zero_imp EQUAL_neq_zero_state;\n      t = t + EQUAL_neq_zero_imp_time 0 EQUAL_neq_zero_state;\n      EQUAL_neq_zero_result = EQUAL_neq_zero_ret EQUAL_neq_zero_ret_state;\n      t = t + 2\n  in\n  (if EQUAL_neq_zero_result \\<noteq> 0 then\n    (let\n      t = t + 1;\n      var_to_operand_bit_tail_aux_ret' = prod_encode_result + 1;\n      t = t + 2;\n      ret = \\<lparr>var_to_operand_bit_tail_aux_v = var_to_operand_bit_tail_aux_v s,\n             var_to_operand_bit_tail_aux_l = var_to_operand_bit_tail_aux_l s,\n             var_to_operand_bit_tail_aux_ret = var_to_operand_bit_tail_aux_ret'\\<rparr>\n    in\n      t\n    )\n  else\n    (let\n      t = t + 1;\n      var_to_operand_bit_tail_aux_ret' = 0;\n      t = t + 2;\n      ret = \\<lparr>var_to_operand_bit_tail_aux_v = var_to_operand_bit_tail_aux_v s,\n             var_to_operand_bit_tail_aux_l = var_to_operand_bit_tail_aux_l s,\n             var_to_operand_bit_tail_aux_ret = var_to_operand_bit_tail_aux_ret'\\<rparr>\n    in\n      t\n    )\n  )\n)\"\n  by auto\ntermination\n  by (relation \"measure (var_to_operand_bit_tail_aux_v \\<circ> snd)\") simp\n\ndeclare var_to_operand_bit_tail_aux_imp_time.simps [simp del]\n\nlemma var_to_operand_bit_tail_aux_imp_time_acc:\n  \"(var_to_operand_bit_tail_aux_imp_time (Suc t) s) = Suc (var_to_operand_bit_tail_aux_imp_time t s)\"\n  by (induction t s rule: var_to_operand_bit_tail_aux_imp_time.induct)\n    ((subst (1 2) var_to_operand_bit_tail_aux_imp_time.simps);\n      (simp add: var_to_operand_bit_tail_aux_state_upd_def Let_def))            \n\nlemma var_to_operand_bit_tail_aux_imp_time_acc_2_aux:\n  \"(var_to_operand_bit_tail_aux_imp_time t s) = t + (var_to_operand_bit_tail_aux_imp_time 0 s)\"\n  by (induction t arbitrary: s) (simp add: var_to_operand_bit_tail_aux_imp_time_acc)+            \n\nlemma var_to_operand_bit_tail_aux_imp_time_acc_2:\n  \"t \\<noteq> 0 \\<Longrightarrow> (var_to_operand_bit_tail_aux_imp_time t s) = t + (var_to_operand_bit_tail_aux_imp_time 0 s)\"\n  by (rule var_to_operand_bit_tail_aux_imp_time_acc_2_aux)            \n\nlemma var_to_operand_bit_tail_aux_imp_time_acc_3:\n  \"(var_to_operand_bit_tail_aux_imp_time (a + b) s) = a + (var_to_operand_bit_tail_aux_imp_time b s)\"\n  by (induction a arbitrary: b s) (simp add: var_to_operand_bit_tail_aux_imp_time_acc)+     \n\nabbreviation \"var_to_operand_bit_tail_aux_prod_encode_result \\<equiv> ''prod_encode_result''\"\nabbreviation \"var_to_operand_bit_tail_aux_EQUAL_neq_zero_result \\<equiv> ''EQUAL_neq_zero_result''\"\n\nabbreviation \"var_to_operand_bit_tail_aux_IMP_if \\<equiv>\n  \\<comment> \\<open>  var_to_operand_bit_tail_aux_ret' = prod_encode_result + 1;\\<close>\n  (var_to_operand_bit_tail_aux_ret_str) ::= (Plus (V var_to_operand_bit_tail_aux_prod_encode_result) (N 1))\n  \\<comment> \\<open>  ret = \\<lparr>var_to_operand_bit_tail_aux_v = var_to_operand_bit_tail_aux_v s,\\<close>\n  \\<comment> \\<open>         var_to_operand_bit_tail_aux_l = var_to_operand_bit_tail_aux_l s,\\<close>\n  \\<comment> \\<open>         var_to_operand_bit_tail_aux_ret = var_to_operand_bit_tail_aux_ret'\\<rparr>\\<close>\n\"\n\nabbreviation \"var_to_operand_bit_tail_aux_IMP_else \\<equiv>\n  \\<comment> \\<open>  var_to_operand_bit_tail_aux_ret' = 0;\\<close>\n  (var_to_operand_bit_tail_aux_ret_str) ::= (A (N 0))\n  \\<comment> \\<open>  ret = \\<lparr>var_to_operand_bit_tail_aux_v = var_to_operand_bit_tail_aux_v s,\\<close>\n  \\<comment> \\<open>         var_to_operand_bit_tail_aux_l = var_to_operand_bit_tail_aux_l s,\\<close>\n  \\<comment> \\<open>         var_to_operand_bit_tail_aux_ret = var_to_operand_bit_tail_aux_ret'\\<rparr>\\<close>\n\"\n\ndefinition var_to_operand_bit_tail_aux_IMP_Minus where\n  \"var_to_operand_bit_tail_aux_IMP_Minus \\<equiv>\n  \\<comment> \\<open>  hd_xs' = var_to_operand_bit_tail_aux_v s;\\<close>\n  (hd_prefix @ hd_xs_str) ::= (A (V var_to_operand_bit_tail_aux_v_str));;\n  \\<comment> \\<open>  hd_ret' = 0;\\<close>\n  (hd_prefix @ hd_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  hd_state = \\<lparr>hd_xs = hd_xs',\\<close>\n  \\<comment> \\<open>              hd_ret = hd_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  hd_ret_state = hd_imp hd_state;\\<close>\n  (invoke_subprogram hd_prefix hd_IMP_Minus);;\n  \\<comment> \\<open>  prod_encode_a' = hd_ret hd_ret_state;\\<close>\n  (prod_encode_prefix @ prod_encode_a_str) ::= (A (V (hd_prefix @ hd_ret_str)));;\n  \\<comment> \\<open>  prod_encode_b' = var_to_operand_bit_tail_aux_l s - 1;\\<close>\n  (prod_encode_prefix @ prod_encode_b_str) ::= (Sub (V var_to_operand_bit_tail_aux_l_str) (N 1));;\n  \\<comment> \\<open>  prod_encode_ret' = 0;\\<close>\n  (prod_encode_prefix @ prod_encode_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  prod_encode_state = \\<lparr>prod_encode_a = prod_encode_a',\\<close>\n  \\<comment> \\<open>                       prod_encode_b = prod_encode_b',\\<close>\n  \\<comment> \\<open>                       prod_encode_ret = prod_encode_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  prod_encode_ret_state = prod_encode_imp prod_encode_state;\\<close>\n  (invoke_subprogram prod_encode_prefix prod_encode_IMP_Minus);;\n  \\<comment> \\<open>  prod_encode_result = prod_encode_ret prod_encode_ret_state;\\<close>\n  (var_to_operand_bit_tail_aux_prod_encode_result) ::= (A (V (prod_encode_prefix @ prod_encode_ret_str)));;\n  \\<comment> \\<open>  operand_bit_to_var_tail_n' = prod_encode_result;\\<close>\n  (operand_bit_to_var_tail_prefix @ operand_bit_to_var_tail_n_str) ::=\n    (A (V var_to_operand_bit_tail_aux_prod_encode_result));;\n  \\<comment> \\<open>  operand_bit_to_var_tail_ret' = 0;\\<close>\n  (operand_bit_to_var_tail_prefix @ operand_bit_to_var_tail_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  operand_bit_to_var_tail_state = \\<lparr>operand_bit_to_var_tail_n = operand_bit_to_var_tail_n',\\<close>\n  \\<comment> \\<open>                                   operand_bit_to_var_tail_ret = operand_bit_to_var_tail_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  operand_bit_to_var_tail_ret_state = operand_bit_to_var_tail_imp operand_bit_to_var_tail_state;\\<close>\n  (invoke_subprogram operand_bit_to_var_tail_prefix operand_bit_to_var_tail_IMP_Minus);;\n  \\<comment> \\<open>  EQUAL_neq_zero_a' = var_to_operand_bit_tail_aux_v s;\\<close>\n  (EQUAL_neq_zero_prefix @ EQUAL_neq_zero_a_str) ::= (A (V var_to_operand_bit_tail_aux_v_str));;\n  \\<comment> \\<open>  EQUAL_neq_zero_b' = operand_bit_to_var_tail_ret operand_bit_to_var_tail_ret_state;\\<close>\n  (EQUAL_neq_zero_prefix @ EQUAL_neq_zero_b_str) ::=\n    (A (V (operand_bit_to_var_tail_prefix @ operand_bit_to_var_tail_ret_str)));;\n  \\<comment> \\<open>  EQUAL_neq_zero_ret' = 0;\\<close>\n  (EQUAL_neq_zero_prefix @ EQUAL_neq_zero_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  EQUAL_neq_zero_state = \\<lparr>EQUAL_neq_zero_a = EQUAL_neq_zero_a',\\<close>\n  \\<comment> \\<open>                          EQUAL_neq_zero_b = EQUAL_neq_zero_b',\\<close>\n  \\<comment> \\<open>                          EQUAL_neq_zero_ret = EQUAL_neq_zero_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  EQUAL_neq_zero_ret_state = EQUAL_neq_zero_imp EQUAL_neq_zero_state;\\<close>\n  (invoke_subprogram EQUAL_neq_zero_prefix EQUAL_neq_zero_IMP_Minus);;\n  \\<comment> \\<open>  EQUAL_neq_zero_result = EQUAL_neq_zero_ret EQUAL_neq_zero_ret_state\\<close>\n  (var_to_operand_bit_tail_aux_EQUAL_neq_zero_result) ::=\n    (A (V (EQUAL_neq_zero_prefix @ EQUAL_neq_zero_ret_str)));;\n  \\<comment> \\<open>(if EQUAL_neq_zero_result \\<noteq> 0 then\\<close>\n  (IF var_to_operand_bit_tail_aux_EQUAL_neq_zero_result \\<noteq>0 THEN\n    var_to_operand_bit_tail_aux_IMP_if\n  \\<comment> \\<open>else\\<close>\n  ELSE\n    var_to_operand_bit_tail_aux_IMP_else\n  )\n\"\n\nabbreviation \"var_to_operand_bit_tail_aux_IMP_vars \\<equiv>\n  {var_to_operand_bit_tail_aux_v_str, var_to_operand_bit_tail_aux_l_str, var_to_operand_bit_tail_aux_ret_str,\n  var_to_operand_bit_tail_aux_prod_encode_result, var_to_operand_bit_tail_aux_EQUAL_neq_zero_result}\"\n\ndefinition \"var_to_operand_bit_tail_aux_imp_to_HOL_state p s =\n  \\<lparr>var_to_operand_bit_tail_aux_v = (s (add_prefix p var_to_operand_bit_tail_aux_v_str)),\n   var_to_operand_bit_tail_aux_l = (s (add_prefix p var_to_operand_bit_tail_aux_l_str)),\n   var_to_operand_bit_tail_aux_ret = (s (add_prefix p var_to_operand_bit_tail_aux_ret_str))\\<rparr>\"\n\nlemmas var_to_operand_bit_tail_aux_state_translators =\n  var_to_operand_bit_tail_aux_imp_to_HOL_state_def\n  hd_imp_to_HOL_state_def\n  prod_encode_imp_to_HOL_state_def\n  operand_bit_to_var_tail_imp_to_HOL_state_def\n  EQUAL_neq_zero_imp_to_HOL_state_def\n\nlemma var_to_operand_bit_tail_aux_IMP_Minus_correct_function:\n  \"(invoke_subprogram p var_to_operand_bit_tail_aux_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p var_to_operand_bit_tail_aux_ret_str)\n      = var_to_operand_bit_tail_aux_ret\n          (var_to_operand_bit_tail_aux_imp (var_to_operand_bit_tail_aux_imp_to_HOL_state p s))\"\n  apply(subst var_to_operand_bit_tail_aux_imp.simps)\n  apply(simp only: var_to_operand_bit_tail_aux_IMP_Minus_def prefix_simps)\n  apply(erule Seq_E)+\n  apply(erule hd_IMP_Minus_correct[where vars = \"var_to_operand_bit_tail_aux_IMP_vars\"])\n  subgoal premises p using p(17) by fastforce\n  apply(erule prod_encode_IMP_Minus_correct[where vars = \"var_to_operand_bit_tail_aux_IMP_vars\"])\n  subgoal premises p using p(19) by fastforce\n  apply(erule operand_bit_to_var_tail_IMP_Minus_correct[where vars = \"var_to_operand_bit_tail_aux_IMP_vars\"])\n  subgoal premises p using p(21) by fastforce\n  apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"var_to_operand_bit_tail_aux_IMP_vars\"])\n  subgoal premises p using p(23) by fastforce\n  apply(erule If_E)\n  subgoal\n    by (fastforce_sorted_premises2 simp: var_to_operand_bit_tail_aux_state_translators Let_def\n        var_to_operand_bit_tail_aux_state_upd_def)   \n  subgoal\n    by (fastforce_sorted_premises2 simp: var_to_operand_bit_tail_aux_state_translators Let_def\n        var_to_operand_bit_tail_aux_state_upd_def) \n  done\n\nlemma var_to_operand_bit_tail_aux_IMP_Minus_correct_effects:\n  \"\\<lbrakk>(invoke_subprogram (p @ var_to_operand_bit_tail_aux_pref) var_to_operand_bit_tail_aux_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    v \\<in> vars; \\<not> (prefix var_to_operand_bit_tail_aux_pref v)\\<rbrakk>\n   \\<Longrightarrow> s (add_prefix p v) = s' (add_prefix p v)\"\n  using com_add_prefix_valid'' com_only_vars prefix_def\n  by blast            \n\nlemma var_to_operand_bit_tail_aux_IMP_Minus_correct_time:\n  \"(invoke_subprogram p var_to_operand_bit_tail_aux_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = var_to_operand_bit_tail_aux_imp_time 0 (var_to_operand_bit_tail_aux_imp_to_HOL_state p s)\"\n  apply(subst var_to_operand_bit_tail_aux_imp_time.simps)\n  apply(simp only: var_to_operand_bit_tail_aux_IMP_Minus_def prefix_simps)\n  apply(erule Seq_tE)+\n  apply(erule hd_IMP_Minus_correct[where vars = \"var_to_operand_bit_tail_aux_IMP_vars\"])\n  subgoal premises p using p(33) by fastforce\n  apply(erule prod_encode_IMP_Minus_correct[where vars = \"var_to_operand_bit_tail_aux_IMP_vars\"])\n  subgoal premises p using p(35) by fastforce\n  apply(erule operand_bit_to_var_tail_IMP_Minus_correct[where vars = \"var_to_operand_bit_tail_aux_IMP_vars\"])\n  subgoal premises p using p(37) by fastforce\n  apply(erule EQUAL_neq_zero_IMP_Minus_correct[where vars = \"var_to_operand_bit_tail_aux_IMP_vars\"])\n  subgoal premises p using p(39) by fastforce\n  apply(erule If_tE)\n  subgoal \n    by (fastforce_sorted_premises2 simp: Let_def var_to_operand_bit_tail_aux_state_translators)\n  subgoal \n    by (fastforce_sorted_premises2 simp: Let_def var_to_operand_bit_tail_aux_state_translators)\n  done\n\nlemma var_to_operand_bit_tail_aux_IMP_Minus_correct:\n  \"\\<lbrakk>(invoke_subprogram (p1 @ p2) var_to_operand_bit_tail_aux_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    \\<And>v. v \\<in> vars \\<Longrightarrow> \\<not> (set p2 \\<subseteq> set v);\n    \\<lbrakk>t = (var_to_operand_bit_tail_aux_imp_time 0 (var_to_operand_bit_tail_aux_imp_to_HOL_state (p1 @ p2) s));\n     s' (add_prefix (p1 @ p2) var_to_operand_bit_tail_aux_ret_str) =\n          var_to_operand_bit_tail_aux_ret (var_to_operand_bit_tail_aux_imp\n                                        (var_to_operand_bit_tail_aux_imp_to_HOL_state (p1 @ p2) s));\n     \\<And>v. v \\<in> vars \\<Longrightarrow> s (add_prefix p1 v) = s' (add_prefix p1 v)\\<rbrakk>\n   \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  using var_to_operand_bit_tail_aux_IMP_Minus_correct_function\n    var_to_operand_bit_tail_aux_IMP_Minus_correct_time\n    var_to_operand_bit_tail_aux_IMP_Minus_correct_effects\n  by (meson set_mono_prefix)\n\n\nsubsubsection \\<open>var_to_operand_bit_tail\\<close>\n\nfun var_to_operand_bit_tail'' :: \"nat \\<Rightarrow> nat\" where\n  \"var_to_operand_bit_tail'' v  =\n  (let l = length_nat v \n  in (if l \\<noteq> 0 \n      then var_to_operand_bit_tail_aux v l\n      else 0)\n  )\"\n\nlemma var_to_operand_bit_tail''_correct:\n  \"var_to_operand_bit_tail'' v = var_to_operand_bit_tail v\"\n  unfolding var_to_operand_bit_tail_def\n  using some_nat_def var_to_operand_bit_tail''.simps\n  var_to_operand_bit_tail'_correct\n  by (metis var_to_operand_bit_tail''.elims var_to_operand_bit_tail'.simps\n  var_to_operand_bit_tail_aux.elims var_to_operand_bit_tail_def)\n\nrecord var_to_operand_bit_tail_state =\n  var_to_operand_bit_tail_v::nat\n  var_to_operand_bit_tail_ret::nat\n\nabbreviation \"var_to_operand_bit_tail_prefix \\<equiv> ''var_to_operand_bit_tail.''\"\nabbreviation \"var_to_operand_bit_tail_v_str \\<equiv> ''v''\"\nabbreviation \"var_to_operand_bit_tail_ret_str \\<equiv> ''ret''\"\n\ndefinition \"var_to_operand_bit_tail_state_upd s =\n  (let\n      length_xs' = var_to_operand_bit_tail_v s;\n      length_ret' = 0;\n      length_state = \\<lparr>length_xs = length_xs',\n                      length_ret = length_ret'\\<rparr>;\n      length_ret_state = length_imp length_state;\n      length_result = length_ret length_ret_state\n  in\n  (if length_result \\<noteq> 0 then\n    (let\n      var_to_operand_bit_tail_aux_v' = var_to_operand_bit_tail_v s;\n      var_to_operand_bit_tail_aux_l' = length_result;\n      var_to_operand_bit_tail_aux_ret' = 0;\n      var_to_operand_bit_tail_aux_state = \\<lparr>var_to_operand_bit_tail_aux_v = var_to_operand_bit_tail_aux_v',\n                                           var_to_operand_bit_tail_aux_l = var_to_operand_bit_tail_aux_l',\n                                           var_to_operand_bit_tail_aux_ret = var_to_operand_bit_tail_aux_ret'\\<rparr>;\n      var_to_operand_bit_tail_aux_ret_state = var_to_operand_bit_tail_aux_imp var_to_operand_bit_tail_aux_state;\n      var_to_operand_bit_tail_ret' = var_to_operand_bit_tail_aux_ret var_to_operand_bit_tail_aux_ret_state;\n      ret = \\<lparr>var_to_operand_bit_tail_v = var_to_operand_bit_tail_v s,\n             var_to_operand_bit_tail_ret = var_to_operand_bit_tail_ret'\\<rparr>\n    in\n      ret\n    )\n  else\n    (let\n      var_to_operand_bit_tail_ret' = 0;\n      ret = \\<lparr>var_to_operand_bit_tail_v = var_to_operand_bit_tail_v s,\n             var_to_operand_bit_tail_ret = var_to_operand_bit_tail_ret'\\<rparr>\n    in\n      ret\n    )\n  )\n)\"\n\nfunction var_to_operand_bit_tail_imp ::\n  \"var_to_operand_bit_tail_state \\<Rightarrow> var_to_operand_bit_tail_state\" where\n  \"var_to_operand_bit_tail_imp s =\n  (let \n      ret = var_to_operand_bit_tail_state_upd s\n    in \n      ret\n  )\"\n  by simp+\ntermination\n  by (relation \"measure var_to_operand_bit_tail_v\") simp\n\ndeclare var_to_operand_bit_tail_imp.simps [simp del]\n\nlemma var_to_operand_bit_tail_imp_correct_aux:\n  \"var_to_operand_bit_tail_ret (var_to_operand_bit_tail_imp s) =\n    var_to_operand_bit_tail'' (var_to_operand_bit_tail_v s)\"\n  by (simp add: var_to_operand_bit_tail_imp.simps Let_def length_imp_correct2\n  var_to_operand_bit_tail_aux_imp_correct var_to_operand_bit_tail_state_upd_def)\n\nlemma var_to_operand_bit_tail_imp_correct[let_function_correctness]:\n  \"var_to_operand_bit_tail_ret (var_to_operand_bit_tail_imp s) =\n    var_to_operand_bit_tail (var_to_operand_bit_tail_v s)\"\n  using var_to_operand_bit_tail_imp_correct_aux var_to_operand_bit_tail''_correct\n  by simp\n\nfunction var_to_operand_bit_tail_imp_time ::\n  \"nat \\<Rightarrow> var_to_operand_bit_tail_state \\<Rightarrow> nat\" where\n  \"var_to_operand_bit_tail_imp_time t s =\n  (let\n      length_xs' = var_to_operand_bit_tail_v s;\n      t = t + 2;\n      length_ret' = 0;\n      t = t + 2;\n      length_state = \\<lparr>length_xs = length_xs',\n                      length_ret = length_ret'\\<rparr>;\n      length_ret_state = length_imp length_state;\n      t = t + length_imp_time 0 length_state;\n      length_result = length_ret length_ret_state;\n      t = t + 2\n  in\n  (if length_result \\<noteq> 0 then\n    (let\n      t = t + 1;\n      var_to_operand_bit_tail_aux_v' = var_to_operand_bit_tail_v s;\n      t = t + 2;\n      var_to_operand_bit_tail_aux_l' = length_result;\n      t = t + 2;\n      var_to_operand_bit_tail_aux_ret' = 0;\n      t = t + 2;\n      var_to_operand_bit_tail_aux_state = \\<lparr>var_to_operand_bit_tail_aux_v = var_to_operand_bit_tail_aux_v',\n                                           var_to_operand_bit_tail_aux_l = var_to_operand_bit_tail_aux_l',\n                                           var_to_operand_bit_tail_aux_ret = var_to_operand_bit_tail_aux_ret'\\<rparr>;\n      var_to_operand_bit_tail_aux_ret_state = var_to_operand_bit_tail_aux_imp var_to_operand_bit_tail_aux_state;\n      t = t + var_to_operand_bit_tail_aux_imp_time 0 var_to_operand_bit_tail_aux_state;\n      var_to_operand_bit_tail_ret' = var_to_operand_bit_tail_aux_ret var_to_operand_bit_tail_aux_ret_state;\n      t = t + 2;\n      ret = \\<lparr>var_to_operand_bit_tail_v = var_to_operand_bit_tail_v s,\n             var_to_operand_bit_tail_ret = var_to_operand_bit_tail_ret'\\<rparr>\n    in\n      t\n    )\n  else\n    (let\n      t = t + 1;\n      var_to_operand_bit_tail_ret' = 0;\n      t = t + 2;\n      ret = \\<lparr>var_to_operand_bit_tail_v = var_to_operand_bit_tail_v s,\n             var_to_operand_bit_tail_ret = var_to_operand_bit_tail_ret'\\<rparr>\n    in\n      t\n    )\n  )\n)\"\n  by auto\ntermination\n  by (relation \"measure (var_to_operand_bit_tail_v \\<circ> snd)\") simp\n\ndeclare var_to_operand_bit_tail_imp_time.simps [simp del]\n\nlemma var_to_operand_bit_tail_imp_time_acc:\n  \"(var_to_operand_bit_tail_imp_time (Suc t) s) = Suc (var_to_operand_bit_tail_imp_time t s)\"\n  by (induction t s rule: var_to_operand_bit_tail_imp_time.induct)\n    ((subst (1 2) var_to_operand_bit_tail_imp_time.simps);\n      (simp add: var_to_operand_bit_tail_state_upd_def Let_def))            \n\nlemma var_to_operand_bit_tail_imp_time_acc_2_aux:\n  \"(var_to_operand_bit_tail_imp_time t s) = t + (var_to_operand_bit_tail_imp_time 0 s)\"\n  by (induction t arbitrary: s) (simp add: var_to_operand_bit_tail_imp_time_acc)+            \n\nlemma var_to_operand_bit_tail_imp_time_acc_2:\n  \"t \\<noteq> 0 \\<Longrightarrow> (var_to_operand_bit_tail_imp_time t s) = t + (var_to_operand_bit_tail_imp_time 0 s)\"\n  by (rule var_to_operand_bit_tail_imp_time_acc_2_aux)            \n\nlemma var_to_operand_bit_tail_imp_time_acc_3:\n  \"(var_to_operand_bit_tail_imp_time (a + b) s) = a + (var_to_operand_bit_tail_imp_time b s)\"\n  by (induction a arbitrary: b s) (simp add: var_to_operand_bit_tail_imp_time_acc)+    \n\nabbreviation \"var_to_operand_bit_tail_length_result \\<equiv> ''length_result''\"\n\nabbreviation \"var_to_operand_bit_tail_IMP_if \\<equiv>\n  \\<comment> \\<open>  var_to_operand_bit_tail_aux_v' = var_to_operand_bit_tail_v s;\\<close>\n  (var_to_operand_bit_tail_aux_prefix @ var_to_operand_bit_tail_aux_v_str) ::= \n    (A (V var_to_operand_bit_tail_v_str));;\n  \\<comment> \\<open>  var_to_operand_bit_tail_aux_l' = length_result;\\<close>\n  (var_to_operand_bit_tail_aux_prefix @ var_to_operand_bit_tail_aux_l_str) ::= \n    (A (V var_to_operand_bit_tail_length_result));;\n  \\<comment> \\<open>  var_to_operand_bit_tail_aux_ret' = 0;\\<close>\n  (var_to_operand_bit_tail_aux_prefix @ var_to_operand_bit_tail_aux_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  var_to_operand_bit_tail_aux_state = \\<lparr>var_to_operand_bit_tail_aux_v = var_to_operand_bit_tail_aux_v',\\<close>\n  \\<comment> \\<open>                                       var_to_operand_bit_tail_aux_l = var_to_operand_bit_tail_aux_l',\\<close>\n  \\<comment> \\<open>                                       var_to_operand_bit_tail_aux_ret = var_to_operand_bit_tail_aux_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  var_to_operand_bit_tail_aux_ret_state = var_to_operand_bit_tail_aux_imp var_to_operand_bit_tail_aux_state;\\<close>\n  (invoke_subprogram var_to_operand_bit_tail_aux_prefix var_to_operand_bit_tail_aux_IMP_Minus);;\n  \\<comment> \\<open>  var_to_operand_bit_tail_ret' = var_to_operand_bit_tail_aux_ret var_to_operand_bit_tail_aux_ret_state;\\<close>\n  (var_to_operand_bit_tail_ret_str) ::= \n    (A (V (var_to_operand_bit_tail_aux_prefix @ var_to_operand_bit_tail_aux_ret_str)))\n  \\<comment> \\<open>  ret = \\<lparr>var_to_operand_bit_tail_v = var_to_operand_bit_tail_v s,\\<close>\n  \\<comment> \\<open>         var_to_operand_bit_tail_ret = var_to_operand_bit_tail_ret'\\<rparr>\\<close>\n\"\n\nabbreviation \"var_to_operand_bit_tail_IMP_else \\<equiv>\n  \\<comment> \\<open>  var_to_operand_bit_tail_ret' = 0;\\<close>\n  (var_to_operand_bit_tail_ret_str) ::= (A (N 0))\n  \\<comment> \\<open>  ret = \\<lparr>var_to_operand_bit_tail_v = var_to_operand_bit_tail_v s,\\<close>\n  \\<comment> \\<open>         var_to_operand_bit_tail_ret = var_to_operand_bit_tail_ret'\\<rparr>\\<close>\n\"\n\ndefinition var_to_operand_bit_tail_IMP_Minus where\n  \"var_to_operand_bit_tail_IMP_Minus \\<equiv>\n  \\<comment> \\<open>  length_xs' = var_to_operand_bit_tail_v s;\\<close>\n  (length_prefix @ length_xs_str) ::= (A (V var_to_operand_bit_tail_v_str));;\n  \\<comment> \\<open>  length_ret' = 0;\\<close>\n  (length_prefix @ length_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  length_state = \\<lparr>length_xs = length_xs',\\<close>\n  \\<comment> \\<open>                  length_ret = length_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  length_ret_state = length_imp length_state;\\<close>\n  (invoke_subprogram length_prefix length_IMP_Minus);;\n  \\<comment> \\<open>  length_result = length_ret length_ret_state\\<close>\n  (var_to_operand_bit_tail_length_result) ::= (A (V (length_prefix @ length_ret_str)));;\n  \\<comment> \\<open>(if length_result \\<noteq> 0 then\\<close>\n  (IF var_to_operand_bit_tail_length_result \\<noteq>0 THEN\n    var_to_operand_bit_tail_IMP_if\n  \\<comment> \\<open>else\\<close>\n  ELSE\n    var_to_operand_bit_tail_IMP_else\n  )\n\"\n\nabbreviation \"var_to_operand_bit_tail_IMP_vars \\<equiv>\n  {var_to_operand_bit_tail_v_str, var_to_operand_bit_tail_ret_str,\n  var_to_operand_bit_tail_length_result}\"\n\ndefinition \"var_to_operand_bit_tail_imp_to_HOL_state p s =\n  \\<lparr>var_to_operand_bit_tail_v = (s (add_prefix p var_to_operand_bit_tail_v_str)),\n   var_to_operand_bit_tail_ret = (s (add_prefix p var_to_operand_bit_tail_ret_str))\\<rparr>\"\n\nlemmas var_to_operand_bit_tail_state_translators =\n  var_to_operand_bit_tail_imp_to_HOL_state_def\n  length_imp_to_HOL_state_def\n  var_to_operand_bit_tail_aux_imp_to_HOL_state_def\n\nlemma var_to_operand_bit_tail_IMP_Minus_correct_function:\n  \"(invoke_subprogram p var_to_operand_bit_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p var_to_operand_bit_tail_ret_str)\n      = var_to_operand_bit_tail_ret\n          (var_to_operand_bit_tail_imp (var_to_operand_bit_tail_imp_to_HOL_state p s))\"\n  apply(subst var_to_operand_bit_tail_imp.simps)\n  apply(simp only: var_to_operand_bit_tail_IMP_Minus_def prefix_simps)\n  apply(erule Seq_E)+\n  apply(erule length_IMP_Minus_correct[where vars = \"var_to_operand_bit_tail_IMP_vars\"])\n  subgoal premises p using p(5) by fastforce\n  apply(erule If_E)\n  subgoal\n    apply(erule Seq_E)+\n    apply(erule var_to_operand_bit_tail_aux_IMP_Minus_correct[where vars = \"var_to_operand_bit_tail_IMP_vars\"])\n    subgoal premises p using p(12) by fastforce\n    by (fastforce_sorted_premises2 simp: var_to_operand_bit_tail_state_translators Let_def\n        var_to_operand_bit_tail_state_upd_def)   \n  subgoal\n    by (fastforce_sorted_premises2 simp: var_to_operand_bit_tail_state_translators Let_def\n        var_to_operand_bit_tail_state_upd_def)\n  done\n\nlemma var_to_operand_bit_tail_IMP_Minus_correct_effects:\n  \"\\<lbrakk>(invoke_subprogram (p @ var_to_operand_bit_tail_pref) var_to_operand_bit_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    v \\<in> vars; \\<not> (prefix var_to_operand_bit_tail_pref v)\\<rbrakk>\n   \\<Longrightarrow> s (add_prefix p v) = s' (add_prefix p v)\"\n  using com_add_prefix_valid'' com_only_vars prefix_def\n  by blast  \n\nlemma var_to_operand_bit_tail_IMP_Minus_correct_time:\n  \"(invoke_subprogram p var_to_operand_bit_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = var_to_operand_bit_tail_imp_time 0 (var_to_operand_bit_tail_imp_to_HOL_state p s)\"\n  apply(subst var_to_operand_bit_tail_imp_time.simps)\n  apply(simp only: var_to_operand_bit_tail_IMP_Minus_def prefix_simps)\n  apply(erule Seq_tE)+\n  apply(erule length_IMP_Minus_correct[where vars = \"var_to_operand_bit_tail_IMP_vars\"])\n  subgoal premises p using p(9) by fastforce\n  apply(erule If_tE)\n  subgoal \n    apply(erule Seq_tE)+\n    apply(erule var_to_operand_bit_tail_aux_IMP_Minus_correct[where vars = \"var_to_operand_bit_tail_IMP_vars\"])\n    subgoal premises p using p(21) by fastforce\n    by (fastforce_sorted_premises2 simp: Let_def var_to_operand_bit_tail_state_translators)\n  subgoal \n    by (fastforce_sorted_premises2 simp: Let_def var_to_operand_bit_tail_state_translators)\n  done\n\nlemma var_to_operand_bit_tail_IMP_Minus_correct:\n  \"\\<lbrakk>(invoke_subprogram (p1 @ p2) var_to_operand_bit_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    \\<And>v. v \\<in> vars \\<Longrightarrow> \\<not> (set p2 \\<subseteq> set v);\n    \\<lbrakk>t = (var_to_operand_bit_tail_imp_time 0 (var_to_operand_bit_tail_imp_to_HOL_state (p1 @ p2) s));\n     s' (add_prefix (p1 @ p2) var_to_operand_bit_tail_ret_str) =\n          var_to_operand_bit_tail_ret (var_to_operand_bit_tail_imp\n                                        (var_to_operand_bit_tail_imp_to_HOL_state (p1 @ p2) s));\n     \\<And>v. v \\<in> vars \\<Longrightarrow> s (add_prefix p1 v) = s' (add_prefix p1 v)\\<rbrakk>\n   \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  using var_to_operand_bit_tail_IMP_Minus_correct_function\n    var_to_operand_bit_tail_IMP_Minus_correct_time\n    var_to_operand_bit_tail_IMP_Minus_correct_effects\n  by (meson set_mono_prefix)\n\n\n\nsubsection \\<open>map_IMP_Minus_State_To_IMP_Minus_Minus_partial\\<close>\n\nsubsubsection \\<open>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc\\<close>\n\nfun map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc':: \"nat \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> nat\" where\n  \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc' acc k n =\n    (if n \\<noteq> 0\n     then\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc'\n       ((prod_encode (fst_nat (hd_nat n), nth_bit_tail (snd_nat (hd_nat n)) k)) ## acc) k (tl_nat n)\n     else acc\n    )\"\n\nlemma map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc'_correct:\n  \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc' acc k n =\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc acc k n\"\n  by(induction acc k n rule: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc.induct)\n    (simp add: subtail_nth_bit)\n\nrecord map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state =\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc::nat\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k::nat\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n::nat\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret::nat\n\nabbreviation \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_prefix \\<equiv>\n  ''map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc.''\"\nabbreviation \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc_str \\<equiv> ''acc''\"\nabbreviation \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k_str \\<equiv> ''k''\"\nabbreviation \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n_str \\<equiv> ''n''\"\nabbreviation \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret_str \\<equiv> ''ret''\"\n\ndefinition \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state_upd s \\<equiv>\n  let\n    hd_xs' = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n s;\n    hd_ret' = 0;\n    hd_state = \\<lparr>hd_xs = hd_xs', hd_ret = hd_ret'\\<rparr>;\n    hd_ret_state = hd_imp hd_state;\n    hd_result = hd_ret hd_ret_state;\n    tl_xs' = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n s;\n    tl_ret' = 0;\n    tl_state = \\<lparr>tl_xs = tl_xs', tl_ret = tl_ret'\\<rparr>;\n    tl_ret_state = tl_imp tl_state;\n    tl_result = tl_ret tl_ret_state;\n    fst'_state_p' = hd_result;\n    fst'_state = \\<lparr>fst'_state_p = fst'_state_p'\\<rparr>;\n    fst'_ret_state = fst'_imp fst'_state;\n    fst'_result = fst'_state_p fst'_ret_state;\n    snd'_state_p' = hd_result;\n    snd'_state = \\<lparr>snd'_state_p = snd'_state_p'\\<rparr>;\n    snd'_ret_state = snd'_imp snd'_state;\n    snd'_result = snd'_state_p snd'_ret_state;\n    nth_bit_tail_acc' = snd'_result;\n    nth_bit_tail_n' = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k s;\n    nth_bit_tail_ret' = 0;\n    nth_bit_tail_state = \\<lparr>nth_bit_tail_acc = nth_bit_tail_acc',\n                          nth_bit_tail_n = nth_bit_tail_n',\n                          nth_bit_tail_ret = nth_bit_tail_ret'\\<rparr>;\n    nth_bit_tail_ret_state = nth_bit_tail_imp nth_bit_tail_state;\n    nth_bit_tail_result = nth_bit_tail_ret nth_bit_tail_ret_state;\n    prod_encode_a' = fst'_result;\n    prod_encode_b' = nth_bit_tail_result;\n    prod_encode_ret' = 0;\n    prod_encode_state = \\<lparr>prod_encode_a = prod_encode_a',\n                         prod_encode_b = prod_encode_b',\n                         prod_encode_ret = prod_encode_ret'\\<rparr>;\n    prod_encode_ret_state = prod_encode_imp prod_encode_state;\n    prod_result = prod_encode_ret prod_encode_ret_state;\n    cons_h' = prod_result;\n    cons_t' = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc s;\n    cons_ret' = 0;\n    cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n    cons_ret_state = cons_imp cons_state;\n    cons_result = cons_ret cons_ret_state;\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc' = cons_result;\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k' =\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k s;\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n' = tl_result;\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret' =\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret s;\n    ret = \\<lparr>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc =\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc',\n           map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k =\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k',\n           map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n =\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n',\n           map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret =\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret'\\<rparr>\n  in ret\n\"\n\ndefinition \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_compute_loop_condition s \\<equiv>\n  let\n    condition = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n s\n  in condition\n\"\n\ndefinition \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_after_loop s \\<equiv>\n  let\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc' =\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc s;\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k' =\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k s;\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n' =\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n s;\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret' =\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc s;\n    ret = \\<lparr>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc =\n            map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc',\n           map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k =\n            map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k',\n           map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n =\n            map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n',\n           map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret =\n            map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret'\\<rparr>\n  in ret\n\"\n\nlemmas map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_subprogram_simps =\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state_upd_def\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_compute_loop_condition_def\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_after_loop_def\n\nfunction map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp::\n  \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state \\<Rightarrow>\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state\"\n  where\n    \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp s =\n  (if map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_compute_loop_condition s \\<noteq> 0\n   then\n    let next_iteration =\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp\n        (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state_upd s)\n    in next_iteration\n   else\n    let ret = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_after_loop s\n    in ret\n  )\"\n  by simp+\ntermination\n  apply (relation \"measure map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n\")\n  by (simp add: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_subprogram_simps\n      hd_imp_correct tl_imp_correct fst'_imp_correct snd'_imp_correct nth_bit_tail_imp_correct\n      prod_encode_imp_correct cons_imp_correct Let_def)+\n\ndeclare map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp.simps [simp del]\n\nlemma map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_correct[let_function_correctness]:\n  \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret\n    (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp s) =\n   map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc'\n    (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc s)\n    (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k s)\n    (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n s)\"\n  apply (induction s rule: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp.induct)\n  apply (subst map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp.simps)\n  apply (subst map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc'.simps)\n  by (simp del: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc'.simps\n      add: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_subprogram_simps Let_def\n      fst_nat_fst'_nat snd_nat_snd'_nat hd_imp_correct tl_imp_correct fst'_imp_correct\n      snd'_imp_correct nth_bit_tail_imp_correct prod_encode_imp_correct cons_imp_correct\n      nth_bit_tail'_correct)\n\ndefinition \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state_upd_time t s \\<equiv>\n  let\n    hd_xs' = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n s;\n    t = t + 2;\n    hd_ret' = 0;\n    t = t + 2;\n    hd_state = \\<lparr>hd_xs = hd_xs', hd_ret = hd_ret'\\<rparr>;\n    hd_ret_state = hd_imp hd_state;\n    t = t + hd_imp_time 0 hd_state;\n    hd_result = hd_ret hd_ret_state;\n    t = t + 2;\n    tl_xs' = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n s;\n    t = t + 2;\n    tl_ret' = 0;\n    t = t + 2;\n    tl_state = \\<lparr>tl_xs = tl_xs', tl_ret = tl_ret'\\<rparr>;\n    tl_ret_state = tl_imp tl_state;\n    t = t + tl_imp_time 0 tl_state;\n    tl_result = tl_ret tl_ret_state;\n    t = t + 2;\n    fst'_state_p' = hd_result;\n    t = t + 2;\n    fst'_state = \\<lparr>fst'_state_p = fst'_state_p'\\<rparr>;\n    fst'_ret_state = fst'_imp fst'_state;\n    t = t + fst'_imp_time 0 fst'_state;\n    fst'_result = fst'_state_p fst'_ret_state;\n    t = t + 2;\n    snd'_state_p' = hd_result;\n    t = t + 2;\n    snd'_state = \\<lparr>snd'_state_p = snd'_state_p'\\<rparr>;\n    snd'_ret_state = snd'_imp snd'_state;\n    t = t + snd'_imp_time 0 snd'_state;\n    snd'_result = snd'_state_p snd'_ret_state;\n    t = t + 2;\n    nth_bit_tail_acc' = snd'_result;\n    t = t + 2;\n    nth_bit_tail_n' = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k s;\n    t = t + 2;\n    nth_bit_tail_ret' = 0;\n    t = t + 2;\n    nth_bit_tail_state = \\<lparr>nth_bit_tail_acc = nth_bit_tail_acc',\n                          nth_bit_tail_n = nth_bit_tail_n',\n                          nth_bit_tail_ret = nth_bit_tail_ret'\\<rparr>;\n    nth_bit_tail_ret_state = nth_bit_tail_imp nth_bit_tail_state;\n    t = t + nth_bit_tail_imp_time 0 nth_bit_tail_state;\n    nth_bit_tail_result = nth_bit_tail_ret nth_bit_tail_ret_state;\n    t = t + 2;\n    prod_encode_a' = fst'_result;\n    t = t + 2;\n    prod_encode_b' =nth_bit_tail_result;\n    t = t + 2;\n    prod_encode_ret' = 0;\n    t = t + 2;\n    prod_encode_state = \\<lparr>prod_encode_a = prod_encode_a',\n                         prod_encode_b = prod_encode_b',\n                         prod_encode_ret = prod_encode_ret'\\<rparr>;\n    prod_encode_ret_state = prod_encode_imp prod_encode_state;\n    t = t + prod_encode_imp_time 0 prod_encode_state;\n    prod_result = prod_encode_ret prod_encode_ret_state;\n    t = t + 2;\n    cons_h' = prod_result;\n    t = t + 2;\n    cons_t' = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc s;\n    t = t + 2;\n    cons_ret' = 0;\n    t = t + 2;\n    cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n    cons_ret_state = cons_imp cons_state;\n    t = t + cons_imp_time 0 cons_state;\n    cons_result = cons_ret cons_ret_state;\n    t = t + 2;\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc' = cons_result;\n    t = t + 2;\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k' =\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k s;\n    t = t + 2;\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n' = tl_result;\n    t = t + 2;\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret' =\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret s;\n    t = t + 2;\n    ret = \\<lparr>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc =\n            map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc',\n           map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k =\n            map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k',\n           map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n =\n            map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n',\n           map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret =\n            map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret'\\<rparr>\n  in\n    t\n\"\n\ndefinition\n  \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_compute_loop_condition_time t s \\<equiv>\n  let\n    condition = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n s;\n    t = t + 2\n  in\n    t\n\"\n\ndefinition \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_after_loop_time t s \\<equiv>\n  let\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc' =\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc s;\n    t = t + 2;\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k' =\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k s;\n    t = t + 2;\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n' =\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n s;\n    t = t + 2;\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret' =\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc s;\n    t = t + 2;\n    ret = \\<lparr>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc =\n            map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc',\n           map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k =\n            map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k',\n           map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n =\n            map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n',\n           map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret =\n            map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret'\\<rparr>\n  in\n    t\n\"\n\nlemmas map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_subprogram_time_simps =\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state_upd_time_def\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_compute_loop_condition_time_def\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_after_loop_time_def\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_subprogram_simps\n\nfunction map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time::\n  \"nat \\<Rightarrow> map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state \\<Rightarrow> nat\" where\n  \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time t s =\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_compute_loop_condition_time 0 s +\n  (if map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_compute_loop_condition s \\<noteq> 0\n    then\n      (let\n        t = t + 1;\n        next_iteration =\n          map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time\n            (t + map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state_upd_time 0 s)\n            (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state_upd s)\n       in next_iteration)\n    else\n      (let\n        t = t + 2;\n        ret = t + map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_after_loop_time 0 s\n       in ret)\n  )\"\n  by auto\ntermination\n  by (relation \"measure (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n \\<circ> snd)\")\n    (simp add: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_subprogram_time_simps\n      tl_imp_correct Let_def)+\n\ndeclare map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time.simps [simp del]\n\nlemma map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time_acc:\n  \"(map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time (Suc t) s) =\n    Suc (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time t s)\"\n  by (induction t s rule: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time.induct)\n    ((subst (1 2) map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time.simps);\n      (simp add: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state_upd_def))\n\nlemma map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time_acc_2_aux:\n  \"(map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time t s) =\n    t + (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time 0 s)\"\n  by (induction t arbitrary: s)\n    (simp add: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time_acc)+\n\nlemma map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time_acc_2:\n  \"t \\<noteq> 0 \\<Longrightarrow> (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time t s) =\n    t + (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time 0 s)\"\n  by (rule map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time_acc_2_aux)\n\nlemma map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time_acc_3:\n  \"(map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time (a + b) s) =\n    a + (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time b s)\"\n  by (induction a arbitrary: b s)\n    (simp add: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time_acc)+\n\nabbreviation \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_while_cond \\<equiv> ''condition''\"\n\nabbreviation \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_hd_result \\<equiv> ''hd_result''\"\nabbreviation \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_tl_result \\<equiv> ''tl_result''\"\nabbreviation \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_fst'_result \\<equiv> ''fst'_result''\"\nabbreviation \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_snd'_result \\<equiv> ''snd'_result''\"\nabbreviation\n  \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_nth_bit_tail_result \\<equiv> ''nth_bit_tail_result''\"\nabbreviation\n  \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_prod_encode_result \\<equiv> ''prod_encode_result''\"\nabbreviation \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_cons_result \\<equiv> ''cons_result''\"\n\ndefinition \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_init_while_cond \\<equiv>\n  \\<comment> \\<open>condition = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n s\\<close>\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_while_cond ::=\n    (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n_str))\n\"\n\ndefinition \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_loop_body \\<equiv>\n  \\<comment> \\<open>hd_xs' = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n s;\\<close>\n  (hd_prefix @ hd_xs_str) ::= (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n_str));;\n  \\<comment> \\<open>hd_ret' = 0;\\<close>\n  (hd_prefix @ hd_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>hd_state = \\<lparr>hd_xs = hd_xs', hd_ret = hd_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>hd_ret_state = hd_imp hd_state;\\<close>\n  invoke_subprogram hd_prefix hd_IMP_Minus;;\n  \\<comment> \\<open>hd_result = hd_ret hd_ret_state;\\<close>\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_hd_result ::=\n    (A (V (hd_prefix @ hd_ret_str)));;\n  \\<comment> \\<open>tl_xs' = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n s;\\<close>\n  (tl_prefix @ tl_xs_str) ::= (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n_str));;\n  \\<comment> \\<open>tl_ret' = 0;\\<close>\n  (tl_prefix @ tl_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>tl_state = \\<lparr>tl_xs = tl_xs', tl_ret = tl_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>tl_ret_state = tl_imp tl_state;\\<close>\n  invoke_subprogram tl_prefix tl_IMP_Minus;;\n  \\<comment> \\<open>tl_result = tl_ret tl_ret_state;\\<close>\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_tl_result ::=\n    (A (V (tl_prefix @ tl_ret_str)));;\n  \\<comment> \\<open>fst'_state_p' = hd_result;\\<close>\n  (fst'_prefix @ fst'_p_str) ::=\n    (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_hd_result));;\n  \\<comment> \\<open>fst'_state = \\<lparr>fst'_state_p = fst'_state_p'\\<rparr>;\\<close>\n  \\<comment> \\<open>fst'_ret_state = fst'_imp fst'_state;\\<close>\n  invoke_subprogram fst'_prefix fst'_IMP_Minus;;\n  \\<comment> \\<open>fst'_result = fst'_state_p fst'_ret_state;\\<close>\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_fst'_result ::=\n    (A (V (fst'_prefix @ fst'_p_str)));;\n  \\<comment> \\<open>snd'_state_p' = hd_result;\\<close>\n  (snd'_prefix @ snd'_p_str) ::=\n    (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_hd_result));;\n  \\<comment> \\<open>snd'_state = \\<lparr>snd'_state_p = snd'_state_p'\\<rparr>;\\<close>\n  \\<comment> \\<open>snd'_ret_state = snd'_imp snd'_state;\\<close>\n  invoke_subprogram snd'_prefix snd'_IMP_Minus;;\n  \\<comment> \\<open>snd'_result = snd'_state_p snd'_ret_state;\\<close>\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_snd'_result ::=\n    (A (V (snd'_prefix @ snd'_p_str)));;\n  \\<comment> \\<open>nth_bit_tail_acc' = snd'_result;\\<close>\n  (nth_bit_tail_prefix @ nth_bit_tail_acc_str) ::=\n    (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_snd'_result));;\n  \\<comment> \\<open>nth_bit_tail_n' = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k s;\\<close>\n  (nth_bit_tail_prefix @ nth_bit_tail_n_str) ::=\n    (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k_str));;\n  \\<comment> \\<open>nth_bit_tail_ret' = 0;\\<close>\n  (nth_bit_tail_prefix @ nth_bit_tail_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>nth_bit_tail_state = \\<lparr>nth_bit_tail_acc = nth_bit_tail_acc',\\<close>\n  \\<comment> \\<open>                      nth_bit_tail_n = nth_bit_tail_n',\\<close>\n  \\<comment> \\<open>                      nth_bit_tail_ret = nth_bit_tail_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>nth_bit_tail_ret_state = nth_bit_tail_imp nth_bit_tail_state;\\<close>\n  invoke_subprogram nth_bit_tail_prefix nth_bit_tail_IMP_Minus;;\n  \\<comment> \\<open>nth_bit_tail_result = nth_bit_tail_ret nth_bit_tail_ret_state;\\<close>\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_nth_bit_tail_result ::=\n    (A (V (nth_bit_tail_prefix @ nth_bit_tail_ret_str)));;\n  \\<comment> \\<open>prod_encode_a' = fst'_result;\\<close>\n  (prod_encode_prefix @ prod_encode_a_str) ::=\n    (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_fst'_result));;\n  \\<comment> \\<open>prod_encode_b' =nth_bit_tail_result;\\<close>\n  (prod_encode_prefix @ prod_encode_b_str) ::=\n    (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_nth_bit_tail_result));;\n  \\<comment> \\<open>prod_encode_ret' = 0;\\<close>\n  (prod_encode_prefix @ prod_encode_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>prod_encode_state = \\<lparr>prod_encode_a = prod_encode_a',\\<close>\n  \\<comment> \\<open>                     prod_encode_b = prod_encode_b',\\<close>\n  \\<comment> \\<open>                     prod_encode_ret = prod_encode_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>prod_encode_ret_state = prod_encode_imp prod_encode_state;\\<close>\n  invoke_subprogram prod_encode_prefix prod_encode_IMP_Minus;;\n  \\<comment> \\<open>prod_result = prod_encode_ret prod_encode_ret_state;\\<close>\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_prod_encode_result ::=\n    (A (V (prod_encode_prefix @ prod_encode_ret_str)));;\n  \\<comment> \\<open>cons_h' = prod_result;\\<close>\n  (cons_prefix @ cons_h_str) ::=\n    (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_prod_encode_result));;\n  \\<comment> \\<open>cons_t' = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc s;\\<close>\n  (cons_prefix @ cons_t_str) ::=\n    (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc_str));;\n  \\<comment> \\<open>cons_ret' = 0;\\<close>\n  (cons_prefix @ cons_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>cons_ret_state = cons_imp cons_state;\\<close>\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n  \\<comment> \\<open>cons_result = cons_ret cons_ret_state;\\<close>\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_cons_result ::=\n    (A (V (cons_prefix @ cons_ret_str)));;\n  \\<comment> \\<open>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc' = cons_result;\\<close>\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc_str ::=\n    (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_cons_result));;\n  \\<comment> \\<open>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k' =\\<close>\n  \\<comment> \\<open>  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k s;\\<close>\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k_str ::=\n    (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k_str));;\n  \\<comment> \\<open>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n' = tl_result;\\<close>\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n_str ::=\n    (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_tl_result));;\n  \\<comment> \\<open>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret' =\\<close>\n  \\<comment> \\<open>  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret s;\\<close>\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret_str ::=\n    (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret_str))\n\"\n\ndefinition \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_after_loop \\<equiv>\n  \\<comment> \\<open>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc' =\n        map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc s;\\<close>\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc_str ::=\n    (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc_str));;\n  \\<comment> \\<open>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k' =\n        map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k s;\\<close>\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k_str ::=\n    (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k_str));;\n  \\<comment> \\<open>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n' =\n        map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n s;\\<close>\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n_str ::=\n    (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n_str));;\n  \\<comment> \\<open>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret' =\n        map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc s;\\<close>\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret_str ::=\n    (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc_str))\n\"\n\ndefinition map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_Minus where\n  \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_Minus \\<equiv>\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_init_while_cond;;\n  WHILE map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_while_cond \\<noteq>0 DO (\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_loop_body;;\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_init_while_cond\n  );;\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_after_loop\"\n\nabbreviation \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_vars \\<equiv>\n  {map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc_str,\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k_str,\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n_str,\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret_str,\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_hd_result,\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_tl_result,\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_fst'_result,\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_snd'_result,\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_nth_bit_tail_result,\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_prod_encode_result,\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_cons_result}\"\n\nlemmas map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_subprogram_simps =\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_init_while_cond_def\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_loop_body_def\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_after_loop_def\n\ndefinition \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_to_HOL_state p s =\n  \\<lparr>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc =\n    (s (add_prefix p map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc_str)),\n   map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k =\n    (s (add_prefix p map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k_str)),\n   map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n =\n    (s (add_prefix p map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n_str)),\n   map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret =\n    (s (add_prefix p map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret_str))\\<rparr>\"\n\nlemmas map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state_translators =\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_to_HOL_state_def\n  hd_imp_to_HOL_state_def\n  tl_imp_to_HOL_state_def\n  fst'_imp_to_HOL_state_def\n  snd'_imp_to_HOL_state_def\n  nth_bit_tail_imp_to_HOL_state_def\n  prod_encode_imp_to_HOL_state_def\n  cons_imp_to_HOL_state_def\n\nlemmas map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_complete_simps =\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_subprogram_simps\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_subprogram_simps\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state_translators\n\ndeclare nth_bit_tail_IMP_Minus_correct[functional_correctness]\n\nlemma map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state_cong:\n  \"\\<lbrakk>a1 = a2; b1 = b2; c1 = c2; d1 = d2\\<rbrakk>\n  \\<Longrightarrow> \\<lparr>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc = a1,\n   map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k = b1,\n   map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n = c1,\n   map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret = d1 \\<rparr> =\n   \\<lparr>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc = a2,\n   map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k = b2,\n   map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n = c2,\n   map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret = d2 \\<rparr>\"\n  by blast\n\ndeclare\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state_cong[let_lemmas]\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state.simps[state_simps]\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state.defs(1)[symmetric, state_defs]\n  arg_cong4[where f=map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state.make, state_congs]\n  arg_cong[where f=map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp, let_lemmas]\n  arg_cong[where f=map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret, let_lemmas]\n  arg_cong[where f=map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp, state_congs]\n  arg_cong[where f=map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret, state_congs]\n\n\nlemma map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_Minus_correct_function:\n  \"(invoke_subprogram p map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s'\n    \\<Longrightarrow> s' (add_prefix p map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret_str)\n      = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret\n          (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp\n            (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_to_HOL_state p s))\"\n  apply(induction \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_to_HOL_state p s\" arbitrary: s s' t\n    rule: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp.induct)\n  apply(subst map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp.simps)\n  apply(simp only: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_Minus_def prefix_simps)\n  apply(erule Seq_E)+\n  apply(erule While_tE)\n\n  subgoal\n    by(fastforce simp: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_subprogram_simps\n        map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_subprogram_simps\n        map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state_translators)\n\n  apply(erule Seq_E)+\n  apply(dest_com_gen)\n\n  subgoal\n      apply(simp only: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_init_while_cond_def prefix_simps)\n      by(fastforce simp add: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_complete_simps)\n\n  subgoal\n      apply(subst (asm) map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_init_while_cond_def)\n      apply(simp only: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_loop_body_def prefix_simps)\n      apply(erule Seq_E)+\n      apply(erule hd_IMP_Minus_correct[where vars = \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_vars\"])\n      subgoal premises p using p(38) by fastforce\n      apply(erule tl_IMP_Minus_correct[where vars = \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_vars\"])\n      subgoal premises p using p(40) by fastforce\n      apply(erule fst'_IMP_Minus_correct[where vars = \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_vars\"])\n      subgoal premises p using p(42) by fastforce\n      apply(erule snd'_IMP_Minus_correct[where vars = \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_vars\"])\n      subgoal premises p using p(44) by fastforce\n      apply(erule nth_bit_tail_IMP_Minus_correct[where vars = \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_vars\"])\n      subgoal premises p using p(46) by fastforce\n      apply(erule prod_encode_IMP_Minus_correct[where vars = \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_vars\"])\n      subgoal premises p using p(48) by fastforce\n      apply(erule cons_IMP_Minus_correct[where vars = \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_vars\"])\n      subgoal premises p using p(50) by fastforce\n      by (fastforce_sorted_premises2 simp: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_subprogram_simps\n        Let_def map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state_translators)\n\n  subgoal\n      apply(simp only: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_init_while_cond_def prefix_simps\n          map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_loop_body_def)\n      apply(erule Seq_E)+\n      apply(erule hd_IMP_Minus_correct[where vars = \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_vars\"])\n      subgoal premises p using p(38) by fastforce\n      apply(erule tl_IMP_Minus_correct[where vars = \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_vars\"])\n      subgoal premises p using p(40) by fastforce\n      apply(erule fst'_IMP_Minus_correct[where vars = \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_vars\"])\n      subgoal premises p using p(42) by fastforce\n      apply(erule snd'_IMP_Minus_correct[where vars = \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_vars\"])\n      subgoal premises p using p(44) by fastforce\n      apply(erule nth_bit_tail_IMP_Minus_correct[where vars = \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_vars\"])\n      subgoal premises p using p(46) by fastforce\n      apply(erule prod_encode_IMP_Minus_correct[where vars = \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_vars\"])\n      subgoal premises p using p(48) by fastforce\n      apply(erule cons_IMP_Minus_correct[where vars = \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_vars\"])\n      subgoal premises p using p(50) by fastforce\n      by (fastforce_sorted_premises2 simp: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_subprogram_simps\n        Let_def map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state_translators)\n  done\n\nlemma map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_Minus_correct_effects:\n  \"\\<lbrakk>(invoke_subprogram (p @ map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_pref)\n                       map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    v \\<in> vars; \\<not> (prefix map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_pref v)\\<rbrakk>\n   \\<Longrightarrow> s (add_prefix p v) = s' (add_prefix p v)\"\n  using com_add_prefix_valid'' com_only_vars prefix_def\n  by blast\n\nlemmas map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_complete_time_simps =\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_subprogram_time_simps\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time_acc_2\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time_acc_3\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state_translators\n\nlemma map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_Minus_correct_time:\n  \"(invoke_subprogram p map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s'\n    \\<Longrightarrow> t = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time 0\n              (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_to_HOL_state p s)\"\n  apply(induction \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_to_HOL_state p s\"\n      arbitrary: s s' t rule: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp.induct)\n  apply(subst map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time.simps)\n  apply(simp only: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_Minus_def prefix_simps)\n\n  apply(erule Seq_tE)+\n  apply(erule While_tE_time)\n\n  subgoal\n    apply(subst (asm) (3) map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_init_while_cond_def)\n    apply(subst (asm) (2) map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_after_loop_def)\n    apply(simp only: prefix_simps)\n    apply(erule Seq_tE)+\n    by (force simp: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_subprogram_simps\n        map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_subprogram_time_simps\n        map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state_translators)\n\n  apply(erule Seq_tE)+\n  apply(simp add: add.assoc)\n  apply(dest_com_gen_time)\n\n  subgoal\n    apply(subst (asm) (1) map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_init_while_cond_def)\n    apply(simp only: prefix_simps)\n    by(fastforce simp add: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_complete_simps)\n\n  subgoal\n    apply(subst (asm) (1) map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_init_while_cond_def)\n    apply(subst (asm) (1) map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_loop_body_def)\n    apply(simp only: prefix_simps)\n    apply(vcg map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_vars)\n    subgoal\n      apply(simp only: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_subprogram_simps Let_def)\n      by(timeit \\<open>propagate_state_pipeline p state_translators: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state_translators\\<close>)\n    done\n\n  subgoal\n    apply(subst (asm) (1) map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_init_while_cond_def)\n    apply(subst (asm) (1) map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_loop_body_def)\n    apply(simp only: prefix_simps)\n    apply(vcg_time map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_vars)\n    by(timeit \\<open>fastforce_sorted_premises simp: Let_def\n        map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_complete_time_simps\\<close>)\n  done\n\nlemma map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_Minus_correct:\n  \"\\<lbrakk>(invoke_subprogram (p1 @ p2)\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    \\<And>v. v \\<in> vars \\<Longrightarrow> \\<not> (set p2 \\<subseteq> set v);\n    \\<lbrakk>t = (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time 0\n            (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_to_HOL_state (p1 @ p2) s));\n     s' (add_prefix (p1 @ p2) map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret_str) =\n          map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret\n            (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp\n              (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_to_HOL_state (p1 @ p2) s));\n     \\<And>v. v \\<in> vars \\<Longrightarrow> s (add_prefix p1 v) = s' (add_prefix p1 v)\\<rbrakk>\n   \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  using map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_Minus_correct_function\n  by (auto simp: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_Minus_correct_time)\n    (meson map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_Minus_correct_effects\n      set_mono_prefix)\n\nsubsubsection \\<open>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail\\<close>\n\nrecord map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_state =\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_k::nat\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ys::nat\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ret::nat\n\nabbreviation \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_prefix \\<equiv>\n  ''map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail.''\"\nabbreviation \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_k_str \\<equiv> ''k''\"\nabbreviation \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ys_str \\<equiv> ''ys''\"\nabbreviation \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ret_str \\<equiv> ''ret''\"\n\ndefinition \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_state_upd s =\n  (let\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc' = 0;\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k' =\n        map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_k s;\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n' =\n        map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ys s;\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret' = 0;\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state =\n        \\<lparr>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc',\n         map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k',\n         map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n',\n         map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret'\\<rparr>;\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret_state =\n        map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state;\n      reverse_nat_n' =\n        map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret_state;\n      reverse_nat_ret' = 0;\n      reverse_nat_state = \\<lparr>reverse_nat_n = reverse_nat_n',\n                           reverse_nat_ret = reverse_nat_ret'\\<rparr>;\n      reverse_nat_ret_state = reverse_nat_imp reverse_nat_state;\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ret' = reverse_nat_ret reverse_nat_ret_state;\n      ret = \\<lparr>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_k = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_k s,\n             map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ys = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ys s,\n             map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ret = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ret'\\<rparr>\n  in\n      ret\n  )\"\n\nfunction map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp ::\n  \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_state \\<Rightarrow> map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_state\" where\n  \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp s =\n  (let \n      ret = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_state_upd s\n    in \n      ret\n  )\"\n  by simp+\ntermination\n  by (relation \"measure map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_k\") simp\n\ndeclare map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp.simps [simp del]\n\nlemma map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_correct[let_function_correctness]:\n  \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ret (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp s) =\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail \n      (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_k s)\n      (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ys s)\"\n  apply (simp only: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp.simps Let_def\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_correct reverse_nat_imp_correct\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_state_upd_def\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc'_correct)\n  by (simp add: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_def)\n\nfunction map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time ::\n  \"nat \\<Rightarrow> map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_state \\<Rightarrow> nat\" where\n  \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time t s =\n  (let\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc' = 0;\n      t = t + 2;\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k' =\n        map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_k s;\n      t = t + 2;\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n' =\n        map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ys s;\n      t = t + 2;\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret' = 0;\n      t = t + 2;\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state =\n        \\<lparr>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc',\n         map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k',\n         map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n',\n         map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret'\\<rparr>;\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret_state =\n        map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state;\n      t = t + \n        map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_time 0 map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state;\n      reverse_nat_n' =\n        map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret_state;\n      t = t + 2;\n      reverse_nat_ret' = 0;\n      t = t + 2;\n      reverse_nat_state = \\<lparr>reverse_nat_n = reverse_nat_n',\n                           reverse_nat_ret = reverse_nat_ret'\\<rparr>;\n      reverse_nat_ret_state = reverse_nat_imp reverse_nat_state;\n      t = t + reverse_nat_imp_time 0 reverse_nat_state;\n      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ret' = reverse_nat_ret reverse_nat_ret_state;\n      t = t + 2;\n      ret = \\<lparr>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_k = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_k s,\n             map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ys = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ys s,\n             map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ret = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ret'\\<rparr>\n  in\n      t\n  )\"\n  by auto\ntermination\n  by (relation \"measure (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_k \\<circ> snd)\") simp\n\ndeclare map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time.simps [simp del]\n\nlemma map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time_acc:\n  \"(map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time (Suc t) s) = Suc (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time t s)\"\n  by (induction t s rule: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time.induct)\n    ((subst (1 2) map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time.simps);\n      (simp add: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_state_upd_def Let_def))            \n\nlemma map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time_acc_2_aux:\n  \"(map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time t s) = t + (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time 0 s)\"\n  by (induction t arbitrary: s) (simp add: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time_acc)+            \n\nlemma map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time_acc_2:\n  \"t \\<noteq> 0 \\<Longrightarrow> (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time t s) = t + (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time 0 s)\"\n  by (rule map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time_acc_2_aux)            \n\nlemma map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time_acc_3:\n  \"(map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time (a + b) s) = a + (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time b s)\"\n  by (induction a arbitrary: b s) (simp add: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time_acc)+  \n\ndefinition map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_IMP_Minus where\n  \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_IMP_Minus \\<equiv>\n  \\<comment> \\<open>  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc' = 0;\\<close>\n  (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_prefix @ \n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc_str) ::= (A (N 0));;\n  \\<comment> \\<open>  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k' =\\<close>\n  \\<comment> \\<open>    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_k s;\\<close>\n  (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_prefix @ \n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k_str) ::= (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_k_str));;\n  \\<comment> \\<open>  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n' =\\<close>\n  \\<comment> \\<open>    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ys s;\\<close>\n  (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_prefix @ \n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n_str) ::= (A (V map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ys_str));;\n  \\<comment> \\<open>  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret' = 0;\\<close>\n  (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_prefix @ \n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state =\\<close>\n  \\<comment> \\<open>     \\<lparr>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_acc',\\<close>\n  \\<comment> \\<open>      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_k',\\<close>\n  \\<comment> \\<open>      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_n',\\<close>\n  \\<comment> \\<open>      map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret_state =\\<close>\n  \\<comment> \\<open>     map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_state;\\<close>\n  (invoke_subprogram map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_prefix \n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_Minus);;\n  \\<comment> \\<open>  reverse_nat_n' =\\<close>\n  \\<comment> \\<open>     map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret_state;\\<close>\n  (reverse_nat_prefix @ reverse_nat_n_str) ::= (A (V (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_prefix @\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_ret_str)));;\n  \\<comment> \\<open>  reverse_nat_ret' = 0;\\<close>\n  (reverse_nat_prefix @ reverse_nat_ret_str) ::= (A (N 0));;\n  \\<comment> \\<open>  reverse_nat_state = \\<lparr>reverse_nat_n = reverse_nat_n',\\<close>\n  \\<comment> \\<open>                       reverse_nat_ret = reverse_nat_ret'\\<rparr>;\\<close>\n  \\<comment> \\<open>  reverse_nat_ret_state = reverse_nat_imp reverse_nat_state;\\<close>\n  (invoke_subprogram reverse_nat_prefix reverse_nat_IMP_Minus);;\n  \\<comment> \\<open>  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ret' = reverse_nat_ret reverse_nat_ret_state;\\<close>\n  (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ret_str) ::= (A (V (reverse_nat_prefix @ reverse_nat_ret_str)))\n  \\<comment> \\<open>  ret = \\<lparr>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_k = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_k s,\\<close>\n  \\<comment> \\<open>         map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ys = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ys s,\\<close>\n  \\<comment> \\<open>         map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ret = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ret'\\<rparr>\\<close>\n\"\n\nabbreviation \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_IMP_vars \\<equiv>\n  {map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_k_str, map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ys_str,\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ret_str}\"\n\ndefinition \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_to_HOL_state p s =\n  \\<lparr>map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_k = (s (add_prefix p map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_k_str)),\n   map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ys = (s (add_prefix p map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ys_str)),\n   map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ret = (s (add_prefix p map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ret_str))\\<rparr>\"\n\nlemmas map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_state_translators =\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_to_HOL_state_def\n  map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_imp_to_HOL_state_def\n  reverse_nat_imp_to_HOL_state_def\n\nlemma map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_IMP_Minus_correct_function:\n  \"(invoke_subprogram p map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ret_str)\n      = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ret\n          (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_to_HOL_state p s))\"\n  apply(subst map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp.simps)\n  apply(simp only: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_IMP_Minus_def prefix_simps)\n  apply(erule Seq_E)+\n  apply(erule map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_Minus_correct[where vars = \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_IMP_vars\"])\n  subgoal premises p using p(9) by fastforce\n  apply(erule reverse_nat_IMP_Minus_correct[where vars = \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_IMP_vars\"])\n  subgoal premises p using p(11) by fastforce\n  by(fastforce simp: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_state_translators\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_state_upd_def) \n\nlemma map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_IMP_Minus_correct_effects:\n  \"\\<lbrakk>(invoke_subprogram (p @ map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_pref) map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    v \\<in> vars; \\<not> (prefix map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_pref v)\\<rbrakk>\n   \\<Longrightarrow> s (add_prefix p v) = s' (add_prefix p v)\"\n  using com_add_prefix_valid'' com_only_vars prefix_def\n  by blast \n\nlemma map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_IMP_Minus_correct_time:\n  \"(invoke_subprogram p map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time 0 (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_to_HOL_state p s)\"\n  apply(subst map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time.simps)\n  apply(simp only: map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_IMP_Minus_def prefix_simps)\n  apply(erule Seq_tE)+\n  apply(erule map_IMP_Minus_State_To_IMP_Minus_Minus_partial_acc_IMP_Minus_correct[where vars = \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_IMP_vars\"])\n  subgoal premises p using p(17) by fastforce\n  apply(erule reverse_nat_IMP_Minus_correct[where vars = \"map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_IMP_vars\"])\n  subgoal premises p using p(19) by fastforce\n  by(fastforce simp add: Let_def map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_state_translators)  \n\nlemma map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_IMP_Minus_correct:\n  \"\\<lbrakk>(invoke_subprogram (p1 @ p2) map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    \\<And>v. v \\<in> vars \\<Longrightarrow> \\<not> (set p2 \\<subseteq> set v);\n    \\<lbrakk>t = (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_time 0 (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_to_HOL_state (p1 @ p2) s));\n     s' (add_prefix (p1 @ p2) map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ret_str) =\n          map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_ret (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp\n                                        (map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_imp_to_HOL_state (p1 @ p2) s));\n     \\<And>v. v \\<in> vars \\<Longrightarrow> s (add_prefix p1 v) = s' (add_prefix p1 v)\\<rbrakk>\n   \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  using map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_IMP_Minus_correct_function\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_IMP_Minus_correct_time\n    map_IMP_Minus_State_To_IMP_Minus_Minus_partial_tail_IMP_Minus_correct_effects\n  by (meson set_mono_prefix)\n\nsubsection \\<open>IMP_Minus_State_To_IMP_Minus_Minus_partial\\<close>\n\nsubsubsection \\<open>IMP_Minus_State_To_IMP_Minus_Minus_partial_tail\\<close>\n\n(* TODO *)\n\n\nend", "meta": {"author": "AlexiosFan", "repo": "BA_NP_Reduction", "sha": "0e37ddc58cb822b0a09b2ce7c15e7b88652e154c", "save_path": "github-repos/isabelle/AlexiosFan-BA_NP_Reduction", "path": "github-repos/isabelle/AlexiosFan-BA_NP_Reduction/BA_NP_Reduction-0e37ddc58cb822b0a09b2ce7c15e7b88652e154c/poly-reductions/Cook_Levin/IMP-_To_SAS+/IMP-_To_IMP--/IMP_Minus_To_IMP_Minus_Minus_State_Translations_IMP.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.603931819468636, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.2901763622493575}}
{"text": "(*\n * Copyright 2016, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the GNU General Public License version 2. Note that NO WARRANTY is provided.\n * See \"LICENSE_GPLv2.txt\" for details.\n *\n * @TAG(NICTA_GPL)\n *)\n\ntheory StringMap\n\n(* assumes CParser or AutoCorres to find StaticFun *)\nimports StaticFun\n\nbegin\n\ndatatype LexOrdString = LexOrdString \"string\"\n\ninstantiation LexOrdString :: linorder begin\n\ndefinition\n  less_LexOrdString_def[simp]:\n  \"(s < t) = (case s of LexOrdString s' \\<Rightarrow> case t of LexOrdString t' \\<Rightarrow>\n    (s', t') \\<in> lexord {(c, c'). nat_of_char c < nat_of_char c'})\"\n\ndefinition\n  le_LexOrdString_def[simp]:\n  \"(s \\<le> t) = ((s :: LexOrdString) < t \\<or> s = t)\"\n\nlemma nat_of_char_trans:\n  \"transP (\\<lambda>c c'. nat_of_char c < nat_of_char c')\"\n  by (auto intro!: transI)\n\ninstance\n  apply intro_classes\n      apply (clarsimp split: LexOrdString.split)\n      apply safe[1]\n       apply (drule(1) lexord_trans[OF _ _ nat_of_char_trans])\n       apply (simp add: lexord_irreflexive)\n      apply (simp add: lexord_irreflexive)\n     apply (clarsimp)\n    apply (clarsimp split: LexOrdString.split_asm)\n    apply safe[1]\n    apply (erule(1) lexord_trans)\n    apply (rule nat_of_char_trans)\n   apply (clarsimp split: LexOrdString.split_asm)\n   apply safe[1]\n   apply (drule(1) lexord_trans[OF _ _ nat_of_char_trans])\n   apply (simp add: lexord_irreflexive)\n  apply (clarsimp split: LexOrdString.split)\n  apply (cut_tac x=list and y=lista in lexord_linear)\n   defer\n   apply blast\n  apply (auto simp: nat_of_char_eq_iff)\n  done\n\nend\n\nML {*\n\nstructure StringMap = struct\n\nfun define_string_map name assocs ctxt = let\n    val th_names = map (prefix (Binding.name_of name ^ \"_\") o fst) assocs\n    val mappings = map (apfst HOLogic.mk_string) assocs\n  in StaticFun.define_tree_and_save_thms name th_names mappings\n    @{term LexOrdString} @{thms nat_of_char_def} ctxt end\n\nend\n\n*}\n\ntext {* Testing *}\n\n(*\nlocal_setup {* StringMap.define_string_map @{binding foo}\n  [(\"x\", @{term \"1 :: nat\"}), (\"y\", @{term \"2 :: nat\"})]\n  #> snd\n*}\n*)\n\nend\n", "meta": {"author": "crizkallah", "repo": "cogent", "sha": "cb16e8169d4389e32dc4aecf4eb9f57173264006", "save_path": "github-repos/isabelle/crizkallah-cogent", "path": "github-repos/isabelle/crizkallah-cogent/cogent-cb16e8169d4389e32dc4aecf4eb9f57173264006/cogent/isa/StringMap.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6187804478040617, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.2900784738701338}}
{"text": "theory Incredible_Completeness\nimports Natural_Deduction Incredible_Deduction Build_Incredible_Tree\nbegin\n\ntext \\<open>\nThis theory takes the tree produced in @{theory Incredible_Proof_Machine.Build_Incredible_Tree}, globalizes it using\n@{term globalize}, and then builds the incredible proof graph out of it.\n\\<close>\n\ntype_synonym 'form vertex = \"('form \\<times> nat list)\"\ntype_synonym ('form, 'var) edge'' = \"('form vertex, 'form, 'var) edge'\"\n\nlocale Solved_Task =\n  Abstract_Task  freshenLC renameLCs lconsts closed subst subst_lconsts subst_renameLCs anyP antecedent consequent rules assumptions conclusions\n   for freshenLC :: \"nat \\<Rightarrow> 'var \\<Rightarrow> 'var\" \n    and renameLCs :: \"('var \\<Rightarrow> 'var) \\<Rightarrow> 'form \\<Rightarrow> 'form\" \n    and lconsts :: \"'form \\<Rightarrow> 'var set\" \n    and closed :: \"'form \\<Rightarrow> bool\"\n    and subst :: \"'subst \\<Rightarrow> 'form \\<Rightarrow> 'form\" \n    and subst_lconsts :: \"'subst \\<Rightarrow> 'var set\" \n    and subst_renameLCs :: \"('var \\<Rightarrow> 'var) \\<Rightarrow> ('subst \\<Rightarrow> 'subst)\"\n    and anyP :: \"'form\"\n    and antecedent :: \"'rule \\<Rightarrow> ('form, 'var) antecedent list\" \n    and consequent :: \"'rule \\<Rightarrow> 'form list\" \n    and rules :: \"'rule stream\" \n    and assumptions :: \"'form list\" \n    and conclusions :: \"'form list\" +\n  assumes solved: solved\nbegin\n\ntext \\<open>Let us get our hand on concrete trees.\\<close>\n\ndefinition ts :: \"'form \\<Rightarrow> (('form entailment) \\<times> ('rule \\<times> 'form) NatRule) tree\" where\n  \"ts c = (SOME t. snd (fst (root t)) = c \\<and> fst (fst (root t)) |\\<subseteq>| ass_forms \\<and> wf t \\<and> tfinite t)\"\n\nlemma\n  assumes \"c |\\<in>| conc_forms\"\n  shows ts_conc: \"snd (fst (root (ts c))) = c\"\n  and   ts_context: \"fst (fst (root (ts c))) |\\<subseteq>| ass_forms\"\n  and   ts_wf: \"wf (ts c)\"\n  and   ts_finite[simp]: \"tfinite (ts c)\"\n  unfolding atomize_conj conj_assoc ts_def\n  apply (rule someI_ex)\n  using solved assms\n  by (force simp add: solved_def)\n\nabbreviation it' where\n  \"it' c \\<equiv> globalize [fidx conc_forms c, 0] (freshenLC v_away) (to_it (ts c))\"\n\n\n\ndefinition vertices :: \"'form vertex fset\"  where\n  \"vertices = Abs_fset (Union ( set (map (\\<lambda> c. insert (c, []) ((\\<lambda> p. (c, 0 # p)) ` (it_paths (it' c))))  conclusions)))\"\n\nlemma mem_vertices: \"v |\\<in>| vertices \\<longleftrightarrow>  (fst v \\<in> set conclusions \\<and> (snd v = [] \\<or> snd v \\<in> ((#) 0) ` it_paths (it' (fst v))))\"\n  unfolding vertices_def fmember.rep_eq ffUnion.rep_eq \n  by (cases v)(auto simp add: Abs_fset_inverse Bex_def )\n\nlemma prefixeq_vertices: \"(c,is) |\\<in>| vertices \\<Longrightarrow> prefix is' is \\<Longrightarrow> (c, is') |\\<in>| vertices\"\n  by (cases is') (auto simp add: mem_vertices intro!: imageI elim: it_paths_prefix)\n\nlemma none_vertices[simp]: \"(c, []) |\\<in>| vertices \\<longleftrightarrow> c \\<in> set conclusions\"\n  by (simp add: mem_vertices)\n\nlemma some_vertices[simp]: \"(c, i#is) |\\<in>| vertices \\<longleftrightarrow> c \\<in> set conclusions \\<and> i = 0 \\<and> is \\<in> it_paths (it' c)\"\n  by (auto simp add: mem_vertices)\n\nlemma vertices_cases[consumes 1, case_names None Some]:\n  assumes \"v |\\<in>| vertices\"\n  obtains c where \"c \\<in> set conclusions\" and \"v = (c, [])\"\n      |   c \"is\" where \"c \\<in> set conclusions\" and \"is \\<in> it_paths (it' c)\" and \"v = (c, 0#is)\"\nusing assms by (cases v; rename_tac \"is\"; case_tac \"is\"; auto)\n\nlemma vertices_induct[consumes 1, case_names None Some]:\n  assumes \"v |\\<in>| vertices\"\n  assumes \"\\<And> c. c \\<in> set conclusions \\<Longrightarrow> P (c, [])\"\n  assumes \"\\<And> c is . c \\<in> set conclusions \\<Longrightarrow> is \\<in> it_paths (it' c) \\<Longrightarrow> P (c, 0#is)\"\n  shows \"P v\"\nusing assms by (cases v; rename_tac \"is\"; case_tac \"is\"; auto)\n\nfun nodeOf :: \"'form vertex \\<Rightarrow> ('form, 'rule) graph_node\" where\n  \"nodeOf (pf, []) = Conclusion pf\"\n| \"nodeOf (pf, i#is) = iNodeOf (tree_at (it' pf) is)\"\n\nfun inst where\n  \"inst (c,[]) = empty_subst\"\n |\"inst (c, i#is) = iSubst (tree_at (it' c) is)\" \n\nlemma terminal_is_nil[simp]: \"v |\\<in>| vertices \\<Longrightarrow> outPorts (nodeOf v) = {||} \\<longleftrightarrow> snd v = []\"\n by (induction v rule: nodeOf.induct)\n    (auto elim: iNodeOf_outPorts[rotated] iwf_it)\n\nsublocale Vertex_Graph nodes inPorts outPorts vertices nodeOf.\n\ndefinition edge_from :: \"'form \\<Rightarrow> nat list => ('form vertex \\<times> ('form,'var) out_port)\" where \n  \"edge_from c is = ((c, 0 # is),  Reg (iOutPort (tree_at (it' c) is)))\"\n\nlemma fst_edge_from[simp]: \"fst (edge_from c is) = (c, 0 # is)\"\n  by (simp add: edge_from_def)\n\nfun in_port_at :: \"('form \\<times> nat list) \\<Rightarrow> nat \\<Rightarrow> ('form,'var) in_port\" where\n    \"in_port_at (c, [])  _  = plain_ant c\"\n  | \"in_port_at (c, _#is) i = inPorts' (iNodeOf (tree_at (it' c) is)) ! i\"\n\ndefinition edge_to :: \"'form \\<Rightarrow> nat list => ('form vertex \\<times> ('form,'var) in_port)\"  where\n \"edge_to c is =\n    (case rev is of   []   \\<Rightarrow> ((c, []),           in_port_at (c, []) 0)\n                    | i#is \\<Rightarrow> ((c, 0 # (rev is)), in_port_at (c, (0#rev is)) i))\"\n\nlemma edge_to_Nil[simp]: \"edge_to c [] = ((c, []), plain_ant c)\"\n  by (simp add: edge_to_def)\n\nlemma edge_to_Snoc[simp]: \"edge_to c (is@[i]) = ((c, 0 # is), in_port_at ((c, 0 # is)) i)\"\n  by (simp add: edge_to_def)\n\ndefinition edge_at :: \"'form \\<Rightarrow> nat list => ('form, 'var) edge''\"  where\n   \"edge_at c is = (edge_from c is, edge_to c is)\"\n\nlemma fst_edge_at[simp]: \"fst (edge_at c is) = edge_from c is\" by (simp add: edge_at_def)\nlemma snd_edge_at[simp]: \"snd (edge_at c is) = edge_to c is\" by (simp add: edge_at_def)\n\n\nlemma hyps_exist':\n  assumes \"c \\<in> set conclusions\"\n  assumes \"is \\<in> it_paths (it' c)\"\n  assumes \"tree_at (it' c) is = (HNode i s ants)\"\n  shows \"subst s (freshen i anyP) \\<in> hyps_along (it' c) is\"\nproof-\n  from assms(1)\n  have \"plain_iwf (it' c) (fst (root (ts c)))\" by (rule iwf_it)\n  moreover\n  note assms(2,3)\n  moreover\n  have \"fst (fst (root (ts c))) |\\<subseteq>| ass_forms\"\n    by (simp add: assms(1) ts_context)\n  ultimately\n  show ?thesis by (rule iwf_hyps_exist)\nqed\n\n\ndefinition hyp_edge_to :: \"'form \\<Rightarrow> nat list => ('form vertex \\<times> ('form,'var) in_port)\" where\n  \"hyp_edge_to c is = ((c, 0 # is),  plain_ant anyP)\"\n\n(* TODO: Replace n and s by \"subst s (freshen n anyP)\" *)\ndefinition hyp_edge_from :: \"'form \\<Rightarrow> nat list => nat \\<Rightarrow> 'subst \\<Rightarrow> ('form vertex \\<times> ('form,'var) out_port)\" where\n  \"hyp_edge_from c is n s = \n    ((c, 0 # hyp_port_path_for (it' c) is (subst s (freshen n anyP))),\n     hyp_port_h_for (it' c) is (subst s (freshen n anyP)))\"\n\ndefinition hyp_edge_at  :: \"'form \\<Rightarrow> nat list => nat \\<Rightarrow> 'subst \\<Rightarrow> ('form, 'var) edge''\" where\n  \"hyp_edge_at c is n s = (hyp_edge_from c is n s, hyp_edge_to c is)\"\n\nlemma fst_hyp_edge_at[simp]:\n  \"fst (hyp_edge_at c is n s) = hyp_edge_from c is n s\" by (simp add:hyp_edge_at_def) \nlemma snd_hyp_edge_at[simp]:\n  \"snd (hyp_edge_at c is n s) = hyp_edge_to c is\" by (simp add:hyp_edge_at_def)\n\ninductive_set edges where\n  regular_edge: \"c \\<in> set conclusions \\<Longrightarrow> is \\<in> it_paths (it' c) \\<Longrightarrow> edge_at c is \\<in> edges\"\n  | hyp_edge: \"c \\<in> set conclusions \\<Longrightarrow> is \\<in> it_paths (it' c) \\<Longrightarrow> tree_at (it' c) is = HNode n s ants \\<Longrightarrow> hyp_edge_at c is n s \\<in> edges\"\n\nsublocale Pre_Port_Graph nodes inPorts outPorts vertices nodeOf edges.\n\nlemma edge_from_valid_out_port:\n  assumes \"p \\<in> it_paths (it' c)\"\n  assumes \"c \\<in> set conclusions\"\n  shows \"valid_out_port (edge_from c p)\"\nusing assms\nby (auto simp add: edge_from_def intro: iwf_outPort iwf_it)\n\nlemma edge_to_valid_in_port:\n  assumes \"p \\<in> it_paths (it' c)\"\n  assumes \"c \\<in> set conclusions\"\n  shows \"valid_in_port (edge_to c p)\"\n  using assms\n  apply (auto simp add: edge_to_def inPorts_fset_of split: list.split elim!: it_paths_SnocE)\n  apply (rule nth_mem)\n  apply (drule (1) iwf_length_inPorts[OF iwf_it])\n  apply auto\n  done\n\nlemma hyp_edge_from_valid_out_port:\n  assumes \"is \\<in> it_paths (it' c)\"\n  assumes \"c \\<in> set conclusions\"\n  assumes \"tree_at (it' c) is = HNode n s ants\"\n  shows \"valid_out_port (hyp_edge_from c is n s)\"\nusing assms\nby(auto simp add: hyp_edge_from_def intro: hyp_port_outPort it_paths_strict_prefix hyp_port_strict_prefix hyps_exist')\n\nlemma hyp_edge_to_valid_in_port:\n  assumes \"is \\<in> it_paths (it' c)\"\n  assumes \"c \\<in> set conclusions\"\n  assumes \"tree_at (it' c) is = HNode n s ants\"\n  shows \"valid_in_port (hyp_edge_to c is)\"\nusing assms by (auto simp add: hyp_edge_to_def)\n\n\ninductive scope' :: \"'form vertex \\<Rightarrow> ('form,'var) in_port \\<Rightarrow> 'form \\<times> nat list \\<Rightarrow> bool\" where\n  \"c \\<in> set conclusions \\<Longrightarrow>\n   is' \\<in> ((#) 0) ` it_paths (it' c) \\<Longrightarrow>\n   prefix (is@[i]) is' \\<Longrightarrow> \n   ip = in_port_at (c,is) i \\<Longrightarrow>\n   scope' (c, is) ip (c, is')\"\n\ninductive_simps scope_simp: \"scope' v i v'\"\ninductive_cases scope_cases: \"scope' v i v'\"\n\nlemma scope_valid:\n  \"scope' v i v' \\<Longrightarrow> v' |\\<in>| vertices\"\nby (auto elim: scope_cases)\n\nlemma scope_valid_inport:\n  \"v' |\\<in>| vertices \\<Longrightarrow> scope' v ip  v' \\<longleftrightarrow> (\\<exists> i. fst v = fst v' \\<and> prefix (snd v@[i]) (snd v') \\<and> ip = in_port_at v i)\"\nby (cases v; cases v')  (auto simp add: scope'.simps mem_vertices)\n\ndefinition terminal_path_from :: \"'form \\<Rightarrow> nat list => ('form, 'var) edge'' list\" where\n   \"terminal_path_from c is = map (edge_at c) (rev (prefixes is))\"\n\nlemma terminal_path_from_Nil[simp]:\n  \"terminal_path_from c [] = [edge_at c []]\"\n  by (simp add: terminal_path_from_def)\n\nlemma terminal_path_from_Snoc[simp]:\n  \"terminal_path_from c (is @ [i]) = edge_at  c (is@[i]) # terminal_path_from c is\"\n  by (simp add: terminal_path_from_def)\n\nlemma path_terminal_path_from:\n  \"c \\<in> set conclusions \\<Longrightarrow>\n  is \\<in> it_paths (it' c) \\<Longrightarrow>\n  path (c, 0 # is) (c, []) (terminal_path_from c is)\"\nby (induction \"is\" rule: rev_induct)\n   (auto simp add: path_cons_simp intro!: regular_edge elim: it_paths_SnocE)\n\nlemma edge_step:\n  assumes \"(((a, b), ba), ((aa, bb), bc)) \\<in> edges\"\n  obtains \n    i where \"a = aa\" and \"b = bb@[i]\" and \"bc = in_port_at (aa,bb) i\"  and \"hyps (nodeOf (a, b)) ba = None\"\n  | i where \"a = aa\" and \"prefix (b@[i]) bb\" and \"hyps (nodeOf (a, b)) ba = Some (in_port_at (a,b) i)\"\nusing assms\nproof(cases rule: edges.cases[consumes 1, case_names Reg Hyp])\n  case (Reg c \"is\")\n  then obtain i where  \"a = aa\" and \"b = bb@[i]\" and \"bc = in_port_at (aa,bb) i\"  and \"hyps (nodeOf (a, b)) ba = None\"\n    by (auto elim!: edges.cases simp add: edge_at_def edge_from_def edge_to_def split: list.split list.split_asm)\n  thus thesis by (rule that)\nnext\n  case (Hyp c \"is\" n s)\n  let ?i = \"hyp_port_i_for (it' c) is (subst s (freshen n anyP))\"\n  from Hyp have \"a = aa\" and \"prefix (b@[?i]) bb\" and\n    \"hyps (nodeOf (a, b)) ba = Some (in_port_at (a,b) ?i)\"\n  by (auto simp add: edge_at_def edge_from_def edge_to_def hyp_edge_at_def hyp_edge_to_def hyp_edge_from_def\n      intro: hyp_port_prefix hyps_exist' hyp_port_hyps)\n  thus thesis by (rule that)\nqed\n\nlemma path_has_prefixes:\n  assumes \"path v v' pth\"\n  assumes \"snd v' = []\"\n  assumes \"prefix (is' @ [i]) (snd v)\"\n  shows \"((fst v, is'), (in_port_at (fst v, is') i)) \\<in> snd ` set pth\"\n  using assms\n  by (induction rule: path.induct)(auto elim!: edge_step dest: prefix_snocD)\n  \nlemma in_scope: \"valid_in_port (v', p') \\<Longrightarrow> v \\<in> scope (v', p') \\<longleftrightarrow> scope' v' p' v\"\nproof\n  assume \"v \\<in> scope (v', p')\"\n  hence \"v |\\<in>| vertices\" and \"\\<And> pth t.  path v t pth \\<Longrightarrow> terminal_vertex t \\<Longrightarrow> (v', p') \\<in> snd ` set pth\"\n    by (auto simp add: scope.simps)\n  from this\n  show \"scope' v' p' v\"\n  proof (induction  rule: vertices_induct)\n    case (None c)\n    from None(2)[of \"(c, [])\" \"[]\", simplified, OF None(1)]\n    have False.\n    thus \"scope' v' p' (c, [])\"..\n  next\n    case (Some c \"is\")\n\n    from \\<open>c \\<in> set conclusions\\<close> \\<open>is \\<in> it_paths (it' c)\\<close>\n    have \"path (c, 0#is) (c, []) (terminal_path_from c is)\"\n      by (rule path_terminal_path_from)\n    moreover\n    from \\<open>c \\<in> set conclusions\\<close>\n    have \"terminal_vertex (c, [])\" by simp\n    ultimately\n    have \"(v', p') \\<in> snd ` set (terminal_path_from c is)\"\n      by (rule Some(3))\n    hence \"(v',p') \\<in> set (map (edge_to c) (prefixes is))\"\n      unfolding terminal_path_from_def by auto\n    then obtain is' where \"prefix is' is\" and \"(v',p') = edge_to c is'\"\n      by auto\n    show \"scope' v' p' (c, 0#is)\"\n    proof(cases \"is'\" rule: rev_cases)\n      case Nil\n      with \\<open>(v',p') = edge_to c is'\\<close>\n      have \"v' = (c, [])\" and \"p' = plain_ant c\"\n        by (auto simp add: edge_to_def)\n      with \\<open>c \\<in> set conclusions\\<close> \\<open>is \\<in> it_paths (it' c)\\<close>\n      show ?thesis  by (auto intro!: scope'.intros)\n    next\n      case (snoc is'' i)\n      with \\<open>(v',p') = edge_to c is'\\<close>\n      have \"v' = (c, 0 # is'')\" and \"p' = in_port_at v' i\"\n        by (auto simp add: edge_to_def)\n      with \\<open>c \\<in> set conclusions\\<close> \\<open>is \\<in> it_paths (it' c)\\<close> \\<open>prefix is' is\\<close>[unfolded snoc]\n      show ?thesis\n        by (auto intro!: scope'.intros)\n    qed\n  qed\nnext\n  assume \"valid_in_port (v', p')\"\n  assume \"scope' v' p' v\"\n  then obtain c is' i \"is\" where\n    \"v' = (c, is')\" and \"v = (c, is)\" and \"c \\<in> set conclusions\" and\n    \"p' = in_port_at v' i\" and\n    \"is \\<in> (#) 0 ` it_paths (it' c)\" and  \"prefix (is' @ [i]) is\"\n    by (auto simp add: scope'.simps)\n\n  from \\<open>scope' v' p' v\\<close>\n  have \"(c, is) |\\<in>| vertices\" unfolding \\<open>v = _\\<close> by (rule scope_valid)\n  hence \"(c, is) \\<in> scope ((c, is'), p')\"\n  proof(rule scope.intros)\n    fix pth t\n    assume \"path (c,is) t pth\"\n    \n    assume \"terminal_vertex t\"\n    hence \"snd t = []\" by auto\n\n    from path_has_prefixes[OF \\<open>path (c,is) t pth\\<close> \\<open>snd t = []\\<close>, simplified, OF \\<open>prefix (is' @ [i]) is\\<close>]\n    show \"((c, is'), p') \\<in> snd ` set pth\" unfolding \\<open>p' = _ \\<close> \\<open>v' = _ \\<close>.\n  qed\n  thus \"v \\<in> scope (v', p')\" using \\<open>v =_\\<close> \\<open>v' = _\\<close> by simp\nqed\n\nsublocale Port_Graph nodes inPorts outPorts vertices nodeOf edges\nproof\n  show \"nodeOf ` fset vertices \\<subseteq> sset nodes\"\n    apply (auto simp add: fmember.rep_eq[symmetric] mem_vertices)\n    apply (auto simp add: stream.set_map dest: iNodeOf_tree_at[OF iwf_it])\n    done\n  next\n\n  have \"\\<forall> e \\<in> edges. valid_out_port (fst e) \\<and> valid_in_port (snd e)\"\n    by (auto elim!: edges.cases simp add: edge_at_def\n        dest: edge_from_valid_out_port edge_to_valid_in_port\n        dest: hyp_edge_from_valid_out_port hyp_edge_to_valid_in_port)\n    \n  thus \"\\<forall>(ps1, ps2)\\<in>edges. valid_out_port ps1 \\<and> valid_in_port ps2\" by auto\nqed\n  \n\nsublocale Scoped_Graph nodes inPorts outPorts vertices nodeOf edges hyps..\n\nlemma hyps_free_path_length:\n  assumes \"path v v' pth\"\n  assumes \"hyps_free pth\"\n  shows \"length pth + length (snd v') = length (snd v)\"\nusing assms by induction (auto elim!: edge_step )\n\nfun vidx :: \"'form vertex \\<Rightarrow> nat\" where\n   \"vidx (c, [])   = isidx [fidx conc_forms c]\"\n  |\"vidx (c, _#is) = iAnnot (tree_at (it' c) is)\"\n\nlemma my_vidx_inj: \"inj_on vidx (fset vertices)\"\n  by (rule inj_onI)\n     (auto simp add:  mem_vertices[unfolded fmember.rep_eq] iAnnot_globalize simp del: iAnnot.simps)\n\nlemma vidx_not_v_away[simp]: \"v |\\<in>| vertices \\<Longrightarrow> vidx v \\<noteq> v_away\"\n  by (cases v rule:vidx.cases) (auto simp add: iAnnot_globalize  simp del: iAnnot.simps)\n\nsublocale Instantiation inPorts outPorts nodeOf hyps  nodes edges vertices labelsIn labelsOut freshenLC renameLCs lconsts closed subst subst_lconsts subst_renameLCs anyP vidx inst\nproof\n  show \"inj_on vidx (fset vertices)\" by (rule my_vidx_inj)\nqed\n\nsublocale  Well_Scoped_Graph nodes inPorts outPorts vertices nodeOf edges hyps\nproof\n  fix v\\<^sub>1 p\\<^sub>1 v\\<^sub>2 p\\<^sub>2 p'\n  assume assms: \"((v\\<^sub>1, p\\<^sub>1), (v\\<^sub>2, p\\<^sub>2)) \\<in> edges\" \"hyps (nodeOf v\\<^sub>1) p\\<^sub>1 = Some p'\"\n  from assms(1) hyps_correct[OF assms(2)]\n  have \"valid_out_port (v\\<^sub>1, p\\<^sub>1)\" and \"valid_in_port (v\\<^sub>2, p\\<^sub>2)\" and \"valid_in_port (v\\<^sub>1, p')\" and \"v\\<^sub>2 |\\<in>| vertices\"\n    using valid_edges by auto\n\n  from assms\n  have \"\\<exists> i. fst v\\<^sub>1 = fst v\\<^sub>2 \\<and> prefix (snd v\\<^sub>1@[i]) (snd v\\<^sub>2) \\<and> p' = in_port_at v\\<^sub>1 i\"\n    by (cases v\\<^sub>1; cases v\\<^sub>2; auto elim!: edge_step)\n  hence \"scope' v\\<^sub>1 p' v\\<^sub>2\"\n    unfolding scope_valid_inport[OF \\<open>v\\<^sub>2 |\\<in>| vertices\\<close>].\n  hence \"v\\<^sub>2 \\<in> scope (v\\<^sub>1, p')\"\n    unfolding in_scope[OF \\<open>valid_in_port (v\\<^sub>1, p')\\<close>].\n  thus \"(v\\<^sub>2, p\\<^sub>2) = (v\\<^sub>1, p') \\<or> v\\<^sub>2 \\<in> scope (v\\<^sub>1, p')\" ..\nqed\n\nsublocale Acyclic_Graph nodes inPorts outPorts vertices nodeOf edges hyps \nproof\n  fix v pth\n  assume \"path v v pth\" and \"hyps_free pth\"\n  from hyps_free_path_length[OF this]\n  show \"pth = []\" by simp\nqed\n\nsublocale Saturated_Graph nodes inPorts outPorts vertices nodeOf edges\nproof\n  fix v p\n  assume \"valid_in_port (v, p)\"\n  thus \"\\<exists>e\\<in>edges. snd e = (v, p)\"\n  proof(induction v)\n    fix c cis\n    assume \"valid_in_port ((c, cis), p)\"\n    hence \"c \\<in> set conclusions\" by (auto simp add: mem_vertices)\n\n    show \"\\<exists>e\\<in>edges. snd e = ((c, cis), p)\"\n    proof(cases cis)\n      case Nil\n      with \\<open>valid_in_port ((c, cis), p)\\<close>\n      have [simp]: \"p = plain_ant c\" by simp\n\n      have \"[] \\<in> it_paths (it' c)\" by simp\n      with \\<open>c \\<in> set conclusions\\<close>\n      have \"edge_at c [] \\<in> edges\" by (rule regular_edge)\n      moreover\n      have \"snd (edge_at c []) = ((c, []), plain_ant c)\"\n        by (simp add: edge_to_def)\n      ultimately\n      show ?thesis by (auto simp add: Nil simp del: snd_edge_at)\n    next\n      case (Cons c' \"is\")\n      with \\<open>valid_in_port ((c, cis), p)\\<close>\n      have [simp]: \"c' = 0\" and \"is \\<in> it_paths (it' c)\"\n        and \"p |\\<in>| inPorts (iNodeOf (tree_at (it' c) is))\" by auto\n       \n      from this(3) obtain i where\n        \"i < length (inPorts' (iNodeOf (tree_at (it' c) is)))\" and\n        \"p = inPorts' (iNodeOf (tree_at (it' c) is)) ! i\"\n          by (auto simp add: inPorts_fset_of in_set_conv_nth)\n\n      show ?thesis\n      proof (cases \"tree_at (it' c) is\")\n        case [simp]: (RNode r ants)\n        show ?thesis\n        proof(cases r)\n          case I\n          hence \"\\<not> isHNode (tree_at (it' c) is)\" by simp\n          from iwf_length_inPorts_not_HNode[OF iwf_it[OF \\<open>c \\<in> set conclusions\\<close>]  \\<open>is \\<in> it_paths (it' c)\\<close> this]\n               \\<open>i < length (inPorts' (iNodeOf (tree_at (it' c) is)))\\<close>\n          have \"i < length (children (tree_at (it' c) is))\" by simp\n          with \\<open>is \\<in> it_paths (it' c)\\<close>\n          have \"is@[i] \\<in> it_paths (it' c)\" by (rule it_path_SnocI)\n          from \\<open>c \\<in> set conclusions\\<close> this\n          have \"edge_at c (is@[i]) \\<in> edges\" by (rule regular_edge)\n          moreover\n          have \"snd (edge_at c (is@[i])) = ((c, 0 # is),  inPorts' (iNodeOf (tree_at (it' c) is)) ! i)\"\n            by (simp add: edge_to_def)\n          ultimately\n          show ?thesis by (auto simp add: Cons \\<open>p = _\\<close> simp del: snd_edge_at)\n        next\n          case (H n s)\n          hence \"tree_at (it' c) is = HNode n s ants\" by simp\n          from \\<open>c \\<in> set conclusions\\<close> \\<open>is \\<in> it_paths (it' c)\\<close>  this\n          have \"hyp_edge_at c is n s \\<in> edges\"..\n          moreover\n          from H \\<open>p |\\<in>| inPorts (iNodeOf (tree_at (it' c) is))\\<close>\n          have [simp]: \"p = plain_ant anyP\" by simp\n  \n          have \"snd (hyp_edge_at c is n s) = ((c, 0 # is), p)\"\n            by (simp add: hyp_edge_to_def)\n          ultimately\n          show ?thesis by (auto simp add: Cons simp del: snd_hyp_edge_at)\n        qed\n      qed\n     qed\n   qed\nqed\n\nsublocale Pruned_Port_Graph nodes inPorts outPorts vertices nodeOf edges\nproof\n  fix v \n  assume \"v |\\<in>| vertices\"\n  thus \"\\<exists>pth v'. path v v' pth \\<and> terminal_vertex v'\"\n  proof(induct rule: vertices_induct)\n    case (None c)\n    hence \"terminal_vertex (c,[])\" by simp\n    with path.intros(1)\n    show ?case by blast\n  next\n    case (Some c \"is\")\n    hence \"path (c, 0 # is) (c, []) (terminal_path_from c is)\"\n      by (rule path_terminal_path_from)\n    moreover\n    have \"terminal_vertex (c,[])\" using Some(1) by simp\n    ultimately\n    show ?case by blast\n  qed\nqed\n\nsublocale Well_Shaped_Graph  nodes inPorts outPorts vertices nodeOf edges hyps..\n\nsublocale sol:Solution inPorts outPorts nodeOf hyps nodes vertices  labelsIn labelsOut freshenLC renameLCs lconsts closed subst subst_lconsts subst_renameLCs anyP vidx inst edges\nproof\n  fix v\\<^sub>1 p\\<^sub>1 v\\<^sub>2 p\\<^sub>2\n  assume \"((v\\<^sub>1, p\\<^sub>1), (v\\<^sub>2, p\\<^sub>2)) \\<in> edges\"\n  thus \"labelAtOut v\\<^sub>1 p\\<^sub>1 = labelAtIn v\\<^sub>2 p\\<^sub>2\"\n  proof(cases rule:edges.cases)\n    case (regular_edge c \"is\")\n   \n    from \\<open>((v\\<^sub>1, p\\<^sub>1), v\\<^sub>2, p\\<^sub>2) = edge_at c is\\<close>\n    have \"(v\\<^sub>1,p\\<^sub>1) = edge_from c is\" using fst_edge_at by (metis fst_conv)\n    hence [simp]: \"v\\<^sub>1 = (c, 0 # is)\" by (simp add: edge_from_def)\n\n    show ?thesis\n    proof(cases \"is\" rule:rev_cases)\n      case Nil\n      let \"?t'\" = \"it' c\"\n      have \"labelAtOut v\\<^sub>1 p\\<^sub>1 = subst (iSubst ?t') (freshen (vidx v\\<^sub>1) (iOutPort ?t'))\"\n        using regular_edge Nil by (simp add: labelAtOut_def edge_at_def edge_from_def)\n      also have \"vidx v\\<^sub>1 = iAnnot ?t'\" by (simp add:  Nil)\n      also have \"subst (iSubst ?t') (freshen (iAnnot ?t') (iOutPort ?t')) = snd (fst (root (ts c)))\"\n        unfolding iwf_subst_freshen_outPort[OF iwf_it[OF \\<open>c \\<in> set conclusions\\<close>]]..\n      also have \"\\<dots> = c\" using \\<open>c \\<in> set conclusions\\<close> by (simp add: ts_conc)\n      also have \"\\<dots> = labelAtIn v\\<^sub>2 p\\<^sub>2\"\n        using  \\<open>c \\<in> set conclusions\\<close>  regular_edge Nil\n        by (simp add: labelAtIn_def edge_at_def freshen_closed conclusions_closed closed_no_lconsts)\n      finally show ?thesis.\n    next\n      case (snoc is' i)\n      let \"?t1\" = \"tree_at (it' c) (is'@[i])\"\n      let \"?t2\" = \"tree_at (it' c) is'\"\n      have \"labelAtOut v\\<^sub>1 p\\<^sub>1 = subst (iSubst ?t1) (freshen (vidx v\\<^sub>1) (iOutPort ?t1))\"\n        using regular_edge snoc by (simp add: labelAtOut_def edge_at_def edge_from_def)\n      also have \"vidx v\\<^sub>1 = iAnnot ?t1\" using snoc regular_edge(3) by simp\n      also have \"subst (iSubst ?t1) (freshen (iAnnot ?t1) (iOutPort ?t1))\n          = subst (iSubst ?t2) (freshen (iAnnot ?t2) (a_conc (inPorts' (iNodeOf ?t2) ! i)))\"\n        by (rule iwf_edge_match[OF iwf_it[OF \\<open>c \\<in> set conclusions\\<close>] \\<open>is \\<in> it_paths (it' c)\\<close>[unfolded snoc]])\n      also have \"iAnnot ?t2 = vidx (c, 0 # is')\" by simp\n      also have \"subst (iSubst ?t2) (freshen (vidx (c, 0 # is')) (a_conc (inPorts' (iNodeOf ?t2) ! i))) = labelAtIn v\\<^sub>2 p\\<^sub>2\"\n        using regular_edge snoc by (simp add: labelAtIn_def edge_at_def)\n      finally show ?thesis.\n  qed\n  next\n    case (hyp_edge c \"is\" n s ants)\n    let ?f = \"subst s (freshen n anyP)\"\n    let ?h = \"hyp_port_h_for (it' c) is ?f\"\n    let ?his = \"hyp_port_path_for (it' c) is ?f\"\n    let \"?t1\" = \"tree_at (it' c) ?his\"\n    let \"?t2\" = \"tree_at (it' c) is\"\n\n    from \\<open>c \\<in> set conclusions\\<close> \\<open>is \\<in> it_paths (it' c)\\<close> \\<open>tree_at (it' c) is = HNode n s ants\\<close>\n    have \"?f \\<in> hyps_along (it' c) is\"\n      by (rule hyps_exist')\n\n    from \\<open>((v\\<^sub>1, p\\<^sub>1), v\\<^sub>2, p\\<^sub>2) = hyp_edge_at c is n s\\<close>\n    have \"(v\\<^sub>1,p\\<^sub>1) = hyp_edge_from c is n s\" using fst_hyp_edge_at by (metis fst_conv)\n    hence [simp]: \"v\\<^sub>1 = (c, 0 # ?his)\" by (simp add: hyp_edge_from_def)\n\n\n    have \"labelAtOut v\\<^sub>1 p\\<^sub>1 = subst (iSubst ?t1) (freshen (vidx v\\<^sub>1) (labelsOut (iNodeOf ?t1) ?h))\"\n      using hyp_edge by (simp add: hyp_edge_at_def hyp_edge_from_def labelAtOut_def)\n    also have \"vidx v\\<^sub>1 = iAnnot ?t1\" by simp\n    also have \"subst (iSubst ?t1) (freshen (iAnnot ?t1) (labelsOut (iNodeOf ?t1) ?h)) = ?f\" using \\<open>?f \\<in> hyps_along (it' c) is\\<close> by (rule local.hyp_port_eq[symmetric])\n    also have \"\\<dots> = subst (iSubst ?t2) (freshen (iAnnot ?t2) anyP)\"  using hyp_edge by simp\n    also have \"subst (iSubst ?t2) (freshen (iAnnot ?t2) anyP) = labelAtIn v\\<^sub>2 p\\<^sub>2\"\n        using hyp_edge by (simp add: labelAtIn_def  hyp_edge_at_def hyp_edge_to_def)\n    finally show ?thesis.\n  qed\nqed\n\n\nlemma node_disjoint_fresh_vars:\n  assumes \"n \\<in> sset nodes\"\n  assumes \"i < length (inPorts' n)\"\n  assumes \"i' < length (inPorts' n)\"\n  shows \"a_fresh (inPorts' n ! i) \\<inter> a_fresh (inPorts' n ! i') = {} \\<or> i = i'\"\n  using assms no_multiple_local_consts\n  by (fastforce simp add: nodes_def stream.set_map)\n\nsublocale Well_Scoped_Instantiation  freshenLC renameLCs lconsts closed subst subst_lconsts subst_renameLCs anyP inPorts outPorts nodeOf hyps  nodes vertices labelsIn labelsOut vidx inst edges local_vars\nproof\n  fix v p var v'\n  assume \"valid_in_port (v, p)\"\n  hence \"v |\\<in>| vertices\" by simp\n  \n  obtain c \"is\" where \"v = (c,is)\"  by (cases v, auto)\n\n  from \\<open>valid_in_port (v, p)\\<close> \\<open>v= _\\<close>\n  have \"(c,is) |\\<in>| vertices\"  and \"p |\\<in>| inPorts (nodeOf (c, is))\"  by simp_all\n  hence \"c \\<in> set conclusions\" by (simp add: mem_vertices)\n  \n  from \\<open>p |\\<in>| _\\<close> obtain i where\n    \"i < length (inPorts' (nodeOf (c, is)))\" and\n    \"p = inPorts' (nodeOf (c, is)) ! i\" by (auto simp add: inPorts_fset_of in_set_conv_nth)\n  hence \"p = in_port_at (c, is) i\" by (cases \"is\") auto\n\n  assume \"v' |\\<in>| vertices\"\n  then obtain c' is' where \"v' = (c',is')\" by (cases v', auto)\n\n  assume \"var \\<in> local_vars (nodeOf v) p\"\n  hence \"var \\<in> a_fresh p\" by simp\n\n  assume \"freshenLC (vidx v) var \\<in> subst_lconsts (inst v')\"\n  then obtain is'' where \"is' = 0#is''\" and \"is'' \\<in> it_paths (it' c')\"\n    using \\<open>v' |\\<in>| vertices\\<close>\n    by (cases is') (auto simp add: \\<open>v'=_\\<close>)\n\n  note \\<open>freshenLC (vidx v) var \\<in> subst_lconsts (inst v')\\<close>\n  also\n  have \"subst_lconsts (inst v') = subst_lconsts (iSubst (tree_at (it' c') is''))\"\n    by (simp add: \\<open>v'=_\\<close> \\<open>is'=_\\<close>)\n  also\n  from \\<open>is'' \\<in> it_paths (it' c')\\<close>\n  have \"\\<dots> \\<subseteq> fresh_at_path (it' c') is'' \\<union> range (freshenLC v_away)\"\n    by (rule globalize_local_consts)\n  finally\n  have \"freshenLC (vidx v) var \\<in> fresh_at_path (it' c') is''\"\n    using \\<open>v |\\<in>| vertices\\<close> by auto\n  then obtain is''' where \"prefix is''' is''\"  and \"freshenLC (vidx v) var \\<in> fresh_at (it' c') is'''\"\n    unfolding fresh_at_path_def by auto\n  then obtain i' is'''' where \"prefix (is''''@[i']) is''\" \n      and \"freshenLC (vidx v) var \\<in> fresh_at (it' c') (is''''@[i'])\"\n    using append_butlast_last_id[where xs = is''', symmetric]\n    apply (cases \"is''' = []\")\n    apply (auto simp del: fresh_at_snoc append_butlast_last_id)\n    apply metis\n    done\n\n  from  \\<open>is'' \\<in> it_paths (it' c')\\<close> \\<open>prefix (is''''@[i']) is''\\<close>\n  have \"(is''''@[i']) \\<in> it_paths (it' c')\" by (rule it_paths_prefix)\n  hence \"is'''' \\<in> it_paths (it' c')\" using append_prefixD it_paths_prefix by blast\n\n  from this \\<open>freshenLC (vidx v) var \\<in> fresh_at (it' c') (is''''@[i'])\\<close>\n  have \"c = c' \\<and> is = 0 # is'''' \\<and> var \\<in> a_fresh (inPorts' (iNodeOf (tree_at (it' c') is'''')) ! i')\"\n    unfolding fresh_at_def' using \\<open>v |\\<in>| vertices\\<close>  \\<open>v' |\\<in>| vertices\\<close>\n    apply (cases \"is\")\n    apply (auto split: if_splits simp add:  iAnnot_globalize it_paths_butlast \\<open>v=_\\<close> \\<open>v'=_\\<close> \\<open>is'=_\\<close> simp del: iAnnot.simps)\n    done\n  hence \"c' = c\" and \"is = 0 # is''''\" and \"var \\<in> a_fresh (inPorts' (iNodeOf (tree_at (it' c') is'''')) ! i')\" by simp_all\n\n  from \\<open>(is''''@[i']) \\<in> it_paths (it' c')\\<close>\n  have \"i' < length (inPorts' (nodeOf (c, is)))\"\n    using iwf_length_inPorts[OF iwf_it[OF \\<open>c \\<in> set conclusions\\<close>]]\n    by (auto elim!: it_paths_SnocE simp add: \\<open>is=_\\<close> \\<open>c' = _\\<close> order.strict_trans2)\n\n  have \"nodeOf (c, is) \\<in> sset nodes\"\n    unfolding \\<open>is = _\\<close> \\<open>c' = _\\<close> nodeOf.simps\n    by (rule iNodeOf_tree_at[OF iwf_it[OF \\<open>c \\<in> set conclusions\\<close>]  \\<open>is'''' \\<in> it_paths (it' c')\\<close>[unfolded \\<open>c' = _\\<close>]])\n    \n  from \\<open>var \\<in> a_fresh (inPorts' (iNodeOf (tree_at (it' c') is'''')) ! i')\\<close>\n       \\<open>var \\<in> a_fresh p\\<close> \\<open>p = inPorts' (nodeOf (c, is)) ! i\\<close>\n       node_disjoint_fresh_vars[OF\n          \\<open>nodeOf (c, is) \\<in> sset nodes\\<close>\n          \\<open>i < length (inPorts' (nodeOf (c, is)))\\<close> \\<open>i' < length (inPorts' (nodeOf (c, is)))\\<close>]\n  have \"i' = i\" by (auto simp add: \\<open>is=_\\<close> \\<open>c'=c\\<close>)\n   \n  from  \\<open>prefix (is''''@[i']) is''\\<close>\n  have \"prefix (is @ [i']) is'\" by (simp add: \\<open>is'=_\\<close> \\<open>is=_\\<close>)\n\n \n  from \\<open>c \\<in> set conclusions\\<close>  \\<open>is'' \\<in> it_paths (it' c')\\<close> \\<open>prefix (is @ [i']) is'\\<close>\n      \\<open>p = in_port_at (c, is) i\\<close>\n  have \"scope' v p v'\"\n  unfolding \\<open>v=_\\<close> \\<open>v'=_\\<close> \\<open>c' = _\\<close> \\<open>is' = _\\<close>  \\<open>i'=_\\<close> by (auto intro: scope'.intros)\n  thus \"v' \\<in> scope (v, p)\" using \\<open>valid_in_port (v, p)\\<close> by (simp add: in_scope)\nqed\n\nsublocale Scoped_Proof_Graph freshenLC renameLCs lconsts closed subst subst_lconsts subst_renameLCs anyP  inPorts outPorts nodeOf hyps nodes vertices labelsIn labelsOut vidx inst edges local_vars..\n\n(* interpretation of @{term Tasked_Proof_Graph} has to be named to avoid name clashes in @{term Abstract_Task}. *)\nsublocale tpg:Tasked_Proof_Graph freshenLC renameLCs lconsts closed subst subst_lconsts subst_renameLCs anyP antecedent consequent rules assumptions conclusions\n  vertices nodeOf edges vidx inst\nproof\n  show \"set (map Conclusion conclusions) \\<subseteq> nodeOf ` fset vertices\"\n  proof-\n  {\n    fix c\n    assume \"c \\<in> set conclusions\"\n    hence \"(c, []) |\\<in>| vertices\" by simp\n    hence \"nodeOf (c, []) \\<in> nodeOf ` fset vertices\"\n      unfolding fmember.rep_eq by (rule imageI)\n    hence \"Conclusion c \\<in> nodeOf ` fset vertices\"  by simp\n  } thus ?thesis by auto\n  qed\nqed  \n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Incredible_Proof_Machine/Incredible_Completeness.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5583270090337583, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.2900627858147763}}
{"text": "(* \n   Title: The pi-calculus   \n   Author/Maintainer: Jesper Bengtson (jebe.dk), 2012\n*)\ntheory Weak_Late_Cong_Subst_Pres\n  imports Weak_Late_Cong_Subst Weak_Late_Cong_Pres\nbegin\n\nlemma tauPres:\n  fixes P :: pi\n  and   Q :: pi\n  \n  assumes \"P \\<simeq>\\<^sup>s Q\"\n\n  shows \"\\<tau>.(P) \\<simeq>\\<^sup>s \\<tau>.(Q)\"\nusing assms\nby(force simp add: substClosed_def Weak_Late_Cong_Pres.tauPres)\n\nlemma inputPres:\n  fixes P :: pi\n  and   Q :: pi\n  and   a :: name\n  and   x :: name\n\n  assumes PeqQ: \"P \\<simeq>\\<^sup>s Q\"\n\n  shows \"a<x>.P \\<simeq>\\<^sup>s a<x>.Q\"\nproof(auto simp add: substClosed_def)\n  fix \\<sigma> :: \"(name \\<times> name) list\"\n  {\n    fix P Q a x \\<sigma>\n    assume \"P \\<simeq>\\<^sup>s Q\"\n    then have \"P[<\\<sigma>>] \\<simeq>\\<^sup>s Q[<\\<sigma>>]\" by(rule partUnfold)\n    then have \"\\<forall>y. (P[<\\<sigma>>])[x::=y] \\<simeq> (Q[<\\<sigma>>])[x::=y]\"\n      apply(auto simp add: substClosed_def)\n      by(erule_tac x=\"[(x, y)]\" in allE) auto\n    moreover assume \"x \\<sharp> \\<sigma>\"\n    ultimately have \"(a<x>.P)[<\\<sigma>>] \\<simeq> (a<x>.Q)[<\\<sigma>>]\" using weakBisimEqvt\n      by(force intro: Weak_Late_Cong_Pres.inputPres)\n  }\n  note Goal = this\n\n  obtain y::name where \"y \\<sharp> P\" and \"y \\<sharp> Q\" and \"y \\<sharp> \\<sigma>\"\n    by(generate_fresh \"name\") auto\n  from `P \\<simeq>\\<^sup>s Q` have \"([(x, y)] \\<bullet> P) \\<simeq>\\<^sup>s ([(x, y)] \\<bullet> Q)\" by(rule eqvtI)\n  hence \"(a<y>.([(x, y)] \\<bullet> P))[<\\<sigma>>] \\<simeq> (a<y>.([(x, y)] \\<bullet> Q))[<\\<sigma>>]\" using `y \\<sharp> \\<sigma>` by(rule Goal)\n  moreover from `y \\<sharp> P` `y \\<sharp> Q` have \"a<x>.P = a<y>.([(x, y)] \\<bullet> P)\" and \"a<x>.Q = a<y>.([(x, y)] \\<bullet> Q)\"\n    by(simp add: pi.alphaInput)+\n\n  ultimately show \"(a<x>.P)[<\\<sigma>>] \\<simeq> (a<x>.Q)[<\\<sigma>>]\" by simp\nqed\n\nlemma outputPres:\n  fixes P :: pi\n  and   Q :: pi\n  \n  assumes \"P \\<simeq>\\<^sup>s Q\"\n\n  shows \"a{b}.P \\<simeq>\\<^sup>s a{b}.Q\"\nusing assms\nby(force simp add: substClosed_def Weak_Late_Cong_Pres.outputPres)\n\n\n\n  assumes \"P \\<simeq>\\<^sup>s Q\"\n\n  shows \"[a\\<frown>b]P \\<simeq>\\<^sup>s [a\\<frown>b]Q\"\nusing assms\nby(force simp add: substClosed_def Weak_Late_Cong_Pres.matchPres)\n\nlemma sumPres:\n  fixes P :: pi\n  and   Q :: pi\n  and   R :: pi\n\n  assumes \"P \\<simeq>\\<^sup>s Q\"\n\n  shows \"P \\<oplus> R \\<simeq>\\<^sup>s Q \\<oplus> R\"\nusing assms\nby(force simp add: substClosed_def Weak_Late_Cong_Pres.sumPres)\n\nlemma parPres:\n  fixes P :: pi\n  and   Q :: pi\n  and   R :: pi\n\n  assumes \"P \\<simeq>\\<^sup>s Q\"\n\n  shows \"P \\<parallel> R \\<simeq>\\<^sup>s Q \\<parallel> R\"\nusing assms\nby(force simp add: substClosed_def Weak_Late_Cong_Pres.parPres)\n\n\n\n  assumes PeqQ: \"P \\<simeq>\\<^sup>s Q\"\n  \n  shows \"<\\<nu>x>P \\<simeq>\\<^sup>s <\\<nu>x>Q\"\nproof(auto simp add: substClosed_def)\n  fix s::\"(name \\<times> name) list\"\n\n  have Goal: \"\\<And>P Q x s. \\<lbrakk>P[<s>] \\<leadsto><weakBisim> Q[<s>]; x \\<sharp> s\\<rbrakk> \\<Longrightarrow> (<\\<nu>x>P)[<s>] \\<leadsto><weakBisim> (<\\<nu>x>Q)[<s>]\"\n    by(force intro: Weak_Late_Step_Sim_Pres.resPres Weak_Late_Bisim_Pres.resPres Weak_Late_Bisim.eqvt)\n  \n  have \"\\<exists>c::name. c \\<sharp> (P, Q, s)\"  by(blast intro: name_exists_fresh)\n  then obtain c::name where cFreshP: \"c \\<sharp> P\" and cFreshQ: \"c \\<sharp> Q\" and cFreshs: \"c \\<sharp> s\"\n    by(force simp add: fresh_prod)\n\n  from PeqQ have \"P[<([(x, c)] \\<bullet> s)>] \\<leadsto><weakBisim> Q[<([(x, c)] \\<bullet> s)>]\" and \n                 \"Q[<([(x, c)] \\<bullet> s)>] \\<leadsto><weakBisim> P[<([(x, c)] \\<bullet> s)>]\"\n    by(force simp add: congruenceSubstDef)+\n\n  hence \"([(x, c)] \\<bullet> (P[<([(x, c)] \\<bullet> s)>])) \\<leadsto><weakBisim> ([(x, c)] \\<bullet> (Q[<([(x, c)] \\<bullet> s)>]))\" and \n        \"([(x, c)] \\<bullet> (Q[<([(x, c)] \\<bullet> s)>])) \\<leadsto><weakBisim> ([(x, c)] \\<bullet> (P[<([(x, c)] \\<bullet> s)>]))\"\n    by(blast intro: Weak_Late_Step_Sim.eqvtI Weak_Late_Bisim.eqvt)+\n\n  hence \"([(x, c)] \\<bullet> P)[<s>] \\<leadsto><weakBisim> ([(x, c)] \\<bullet> Q)[<s>]\" and\n        \"([(x, c)] \\<bullet> Q)[<s>] \\<leadsto><weakBisim> ([(x, c)] \\<bullet> P)[<s>]\" by simp+\n\n  with cFreshs have \"(<\\<nu>c>([(x, c)] \\<bullet> P))[<s>] \\<leadsto><weakBisim> (<\\<nu>c>([(x, c)] \\<bullet> Q))[<s>]\" and\n                    \"(<\\<nu>c>([(x, c)] \\<bullet> Q))[<s>] \\<leadsto><weakBisim> (<\\<nu>c>([(x, c)] \\<bullet> P))[<s>]\"\n    by(blast intro: Goal)+\n\n  moreover from cFreshP cFreshQ have \"<\\<nu>x>P = <\\<nu>c>([(x, c)] \\<bullet> P)\" and \"<\\<nu>x>Q = <\\<nu>c>([(x, c)] \\<bullet> Q)\"\n    by(simp add: alphaRes)+\n\n  ultimately show \"(<\\<nu>x>P)[<s>] \\<simeq> (<\\<nu>x>Q)[<s>]\"\n    by(simp add: congruence_def)\nqed\n\nlemma congruenceBang:\n  fixes P :: pi\n  and   Q :: pi\n  \n  assumes \"P \\<simeq>\\<^sup>s Q\"\n\n  shows \"!P \\<simeq>\\<^sup>s !Q\"\nusing assms\nby(force simp add: substClosed_def intro: Weak_Late_Cong_Pres.congruenceBang)\n\nend", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Pi_Calculus/Weak_Late_Cong_Subst_Pres.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5583269943353744, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.29006277817865245}}
{"text": "           (*-------------------------------------------*\n            |                2 Buffers                  |\n            |                                           |\n            |                June 2009                  |\n            |                                           |\n            |        CSP-Prover on Isabelle2016         |\n            |                    May 2016  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory TwoBuff\nimports CSP_F\nbegin\n\n(*=============================================================*\n |                                                             |\n |                           Process                           |\n |                                                             |\n *=============================================================*)\n\n(*********************************************************\n               process names and events\n *********************************************************)\n\ndatatype Event = inC | outC | midC\ndatatype PN = Buff1 | Buff1' | Buff2 | Buff2' | Buff2''\n\n(*********************************************************\n                  Recursivey Process\n *********************************************************)\n\nprimrec\t\n  PNdef :: \"PN => (PN, Event) proc\"\nwhere\n \"PNdef   (Buff1) = inC -> $Buff1'\"\n|\"PNdef  (Buff1') = outC -> $Buff1\"\n\n|\"PNdef   (Buff2) = inC -> $Buff2'\"\n|\"PNdef  (Buff2') = inC -> $Buff2'' [+] outC -> $Buff2\"\n|\"PNdef (Buff2'') = outC -> $Buff2'\"\n\n(*\ndefs (overloaded) Set_PNfun_def [simp]: \"PNfun == PNdef\"\n*)\n\n\noverloading Set_PNdef == \n  \"PNfun :: (PN, Event) pnfun\"\nbegin\n  definition \"PNfun == PNdef\"\nend\n  \ndeclare Set_PNdef_def [simp]\n\n(* ------------------ *\n      guardedness\n * ------------------ *)\n\nlemma guardedfun_PN[simp]:\n      \"guardedfun PNdef\"\nby (simp add: guardedfun_def, rule allI, induct_tac p, simp_all)\n(*\ndefs FPmode_def [simp]: \"FPmode == CMSmode\"\n*)\n\noverloading FPmode == \n  \"FPmode :: fpmode\"\nbegin\n  definition \"FPmode == CMSmode\"\nend\n\ndeclare FPmode_def [simp]\n\n(*********************************************************\n                     Composition\n *********************************************************)\n\nabbreviation\n Link :: \"(PN, Event) proc => (PN, Event) proc => (PN, Event) proc\"\n        (\"(1_ /<---> _)\" [76,77] 76)\nwhere \"P <---> Q == (P[[outC<-->midC]] |[{midC}]| \n                     Q[[inC<-->midC]]) -- {midC}\"\n\nabbreviation\n LinkBuff2 :: \"(PN, Event) proc\"\nwhere \"LinkBuff2 == $Buff1 <---> $Buff1\"\n\n(*********************************************************\n                  for automatising\n *********************************************************)\n\ndeclare simp_event_set [simp]\n\nlemma Link_cong: \"Q =F R ==> P <---> Q =F P <---> R\"\nby (simp)\n\n(*********************************************************\n                    verification\n *********************************************************)\n\nprimrec\n  Buff2_to_LinkBuff2 :: \"PN => (PN, Event) proc\"\nwhere\n  \"Buff2_to_LinkBuff2 (Buff1) = $Buff1\"\n |\"Buff2_to_LinkBuff2 (Buff1') = $Buff1'\"\n |\"Buff2_to_LinkBuff2 (Buff2) = LinkBuff2\"\n |\"Buff2_to_LinkBuff2 (Buff2') = $Buff1' <---> $Buff1\"\n |\"Buff2_to_LinkBuff2 (Buff2'') = $Buff1' <---> $Buff1'\"\n\ntheorem Buff2_eq_LinkBuff2:\n   \"$Buff2 =F LinkBuff2\"\n\n(* by finxed point induction *)\napply (rule cspF_fp_induct_left[of _ \"Buff2_to_LinkBuff2\"])\napply (simp+, induct_tac p, auto, cspF_unwind+)\n\n(* by sequentialising *)\napply (cspF_auto | auto)+\ndone\n\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/NBuff/TwoBuff.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5583269796369905, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.2900627705425286}}
{"text": "(* \n   Title: Psi-calculi   \n   Author/Maintainer: Jesper Bengtson (jebe@itu.dk), 2012\n*)\ntheory Close_Subst\n  imports Agent\nbegin\n\ncontext substPsi\nbegin\n\ndefinition closeSubst :: \"('b::fs_name \\<times> ('a::fs_name, 'b, 'c::fs_name) psi \\<times> ('a, 'b, 'c) psi) set \\<Rightarrow> ('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\nwhere \"closeSubst Rel \\<equiv> {(\\<Psi>, P, Q) | \\<Psi> P Q. (\\<forall>\\<sigma>. wellFormedSubst \\<sigma> \\<longrightarrow> (\\<Psi>, P[<\\<sigma>>], Q[<\\<sigma>>]) \\<in> Rel)}\"\n\nlemma closeSubstI:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<And>\\<sigma>. wellFormedSubst \\<sigma> \\<Longrightarrow> (\\<Psi>, P[<\\<sigma>>], Q[<\\<sigma>>]) \\<in> Rel\"\n\n  shows \"(\\<Psi>, P, Q) \\<in> closeSubst Rel\"\nusing assms\nby(unfold closeSubst_def) auto\n\nlemma closeSubstE:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   \\<sigma> :: \"(name list \\<times> 'a list) list\"\n\n  assumes \"(\\<Psi>, P, Q) \\<in> closeSubst Rel\"\n  and     \"wellFormedSubst \\<sigma>\"\n\n  shows \"(\\<Psi>, P[<\\<sigma>>], Q[<\\<sigma>>]) \\<in> Rel\"\nusing assms\nby(unfold closeSubst_def) auto\n\nlemma closeSubstClosed:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   p :: \"name prm\"\n\n  assumes \"eqvt Rel\"\n  and     \"(\\<Psi>, P, Q) \\<in> closeSubst Rel\"\n\n  shows \"(p \\<bullet> \\<Psi>, p \\<bullet> P, p \\<bullet> Q) \\<in> closeSubst Rel\"\nproof(rule closeSubstI)\n  fix \\<sigma>\n  assume \"wellFormedSubst(\\<sigma>::(name list \\<times> 'a list) list)\"\n  with `(\\<Psi>, P, Q) \\<in> closeSubst Rel` `wellFormedSubst \\<sigma>`\n  have \"(\\<Psi>, P[<(rev p \\<bullet> \\<sigma>)>], Q[<(rev p \\<bullet> \\<sigma>)>]) \\<in> Rel\"\n    by(rule_tac closeSubstE) auto\n  hence \"(p \\<bullet> \\<Psi>, p \\<bullet> (P[<(rev p \\<bullet> \\<sigma>)>]), p \\<bullet> (Q[<(rev p \\<bullet> \\<sigma>)>])) \\<in> Rel\"\n    by(drule_tac p=p in eqvtI[OF `eqvt Rel`]) (simp add: eqvts)\n  thus \"(p \\<bullet> \\<Psi>, (p \\<bullet> P)[<\\<sigma>>], (p \\<bullet> Q)[<\\<sigma>>]) \\<in> Rel\"\n    by(simp del: seqSubs_def add: eqvts)\nqed\n\nlemma closeSubstEqvt:\n  assumes \"eqvt Rel\"\n\n  shows \"eqvt(closeSubst Rel)\"\nproof(auto simp add: eqvt_def)\n  fix \\<Psi> P Q p\n  assume \"(\\<Psi>, P, Q) \\<in> closeSubst Rel\"\n  thus \"((p::name prm) \\<bullet> \\<Psi>, p \\<bullet> P, p \\<bullet> Q) \\<in> closeSubst Rel\"\n    by(drule_tac p=p in closeSubstClosed[OF `eqvt Rel`]) (simp add: eqvts)\nqed\n\nlemma closeSubstUnfold:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   \\<sigma> :: \"(name list \\<times> 'a list) list\"\n\n  assumes \"(\\<Psi>, P, Q) \\<in> closeSubst Rel\"\n  and     \"wellFormedSubst \\<sigma>\"\n\n  shows \"(\\<Psi>, P[<\\<sigma>>], Q[<\\<sigma>>]) \\<in> closeSubst Rel\"\nproof(rule closeSubstI)\n  fix \\<sigma>'::\"(name list \\<times> 'a list) list\"\n  assume \"wellFormedSubst \\<sigma>'\"\n  with `wellFormedSubst \\<sigma>` have \"wellFormedSubst(\\<sigma>@\\<sigma>')\" by simp\n  with `(\\<Psi>, P, Q) \\<in> closeSubst Rel` have \"(\\<Psi>, P[<(\\<sigma>@\\<sigma>')>], Q[<(\\<sigma>@\\<sigma>')>]) \\<in> Rel\"\n    by(rule closeSubstE)\n  thus \"(\\<Psi>, P[<\\<sigma>>][<\\<sigma>'>], Q[<\\<sigma>>][<\\<sigma>'>]) \\<in> Rel\"\n    by simp\nqed\n\nend\n\nend\n  \n\n  \n\n\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Psi_Calculi/Close_Subst.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5621765155565326, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.28986940757271795}}
{"text": "(*\n * Copyright Florian Haftmann\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\nsection \\<open>Ancient comprehensive Word Library\\<close>\n\ntheory Word_Lib_Sumo\nimports\n  \"HOL-Library.Word\"\n  Aligned\n  Bit_Comprehension\n  Bit_Comprehension_Int\n  Bit_Shifts_Infix_Syntax\n  Bits_Int\n  Bitwise_Signed\n  Bitwise\n  Enumeration_Word\n  Generic_set_bit\n  Hex_Words\n  Least_significant_bit\n  More_Arithmetic\n  More_Divides\n  More_Sublist\n  Even_More_List\n  More_Misc\n  Strict_part_mono\n  Legacy_Aliases\n  Most_significant_bit\n  Next_and_Prev\n  Norm_Words\n  Reversed_Bit_Lists\n  Rsplit\n  Signed_Words\n  Syntax_Bundles\n  Typedef_Morphisms\n  Type_Syntax\n  Word_EqI\n  Word_Lemmas\n  Word_8\n  Word_16\n  Word_32\n  Word_Syntax\n  Signed_Division_Word\n  Singleton_Bit_Shifts\n  More_Word_Operations\n  Many_More\n  Word_Lemmas_Internal\n  Word_Lemmas_Prefix\nbegin\n\nunbundle bit_operations_syntax\nunbundle bit_projection_infix_syntax\n\ndeclare word_induct2[induct type]\ndeclare word_nat_cases[cases type]\n\ndeclare signed_take_bit_Suc [simp]\n\n(* these generate take_bit terms, which we often don't want for concrete lengths *)\nlemmas of_int_and_nat = unsigned_of_nat unsigned_of_int signed_of_int signed_of_nat\n\nbundle no_take_bit\nbegin\ndeclare of_int_and_nat[simp del]\nend\n\nlemmas bshiftr1_def = bshiftr1_eq\nlemmas is_down_def = is_down_eq\nlemmas is_up_def = is_up_eq\nlemmas mask_def = mask_eq\nlemmas scast_def = scast_eq\nlemmas shiftl1_def = shiftl1_eq\nlemmas shiftr1_def = shiftr1_eq\nlemmas sshiftr1_def = sshiftr1_eq\nlemmas sshiftr_def = sshiftr_eq_funpow_sshiftr1\nlemmas to_bl_def = to_bl_eq\nlemmas ucast_def = ucast_eq\nlemmas unat_def = unat_eq_nat_uint\nlemmas word_cat_def = word_cat_eq\nlemmas word_reverse_def = word_reverse_eq_of_bl_rev_to_bl\nlemmas word_roti_def = word_roti_eq_word_rotr_word_rotl\nlemmas word_rotl_def = word_rotl_eq\nlemmas word_rotr_def = word_rotr_eq\nlemmas word_sle_def = word_sle_eq\nlemmas word_sless_def = word_sless_eq\n\nlemmas uint_0 = uint_nonnegative\nlemmas uint_lt = uint_bounded\nlemmas uint_mod_same = uint_idem\nlemmas of_nth_def = word_set_bits_def\n\nlemmas of_nat_word_eq_iff = word_of_nat_eq_iff\nlemmas of_nat_word_eq_0_iff = word_of_nat_eq_0_iff\nlemmas of_int_word_eq_iff = word_of_int_eq_iff\nlemmas of_int_word_eq_0_iff = word_of_int_eq_0_iff\n\nlemmas word_next_def = word_next_unfold\n\nlemmas word_prev_def = word_prev_unfold\n\nlemmas is_aligned_def = is_aligned_iff_dvd_nat\n\nlemmas word_and_max_simps =\n  word8_and_max_simp\n  word16_and_max_simp\n  word32_and_max_simp\n\nlemma distinct_lemma: \"f x \\<noteq> f y \\<Longrightarrow> x \\<noteq> y\" by auto\n\nlemmas and_bang = word_and_nth\n\nlemmas sdiv_int_def = signed_divide_int_def\nlemmas smod_int_def = signed_modulo_int_def\n\n(* shortcut for some specific lengths *)\nlemma word_fixed_sint_1[simp]:\n  \"sint (1::8 word) = 1\"\n  \"sint (1::16 word) = 1\"\n  \"sint (1::32 word) = 1\"\n  \"sint (1::64 word) = 1\"\n  by (auto simp: sint_word_ariths)\n\ndeclare of_nat_diff [simp]\n\n(* Haskellish names/syntax *)\nnotation (input)\n  bit (\"testBit\")\n\nlemmas cast_simps = cast_simps ucast_down_bl\n\n(* shadows the slightly weaker Word.nth_ucast *)\nlemma nth_ucast:\n  \"(ucast (w::'a::len word)::'b::len word) !! n =\n   (w !! n \\<and> n < min LENGTH('a) LENGTH('b))\"\n  by (auto simp add: bit_simps not_le dest: bit_imp_le_length)\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/lib/Word_Lib/Word_Lib_Sumo.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5621765155565326, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.2898694075727179}}
{"text": "(*  Title:       Conflict analysis/Flowgraphs\n    Author:      Peter Lammich <peter.lammich@uni-muenster.de>\n    Maintainer:  Peter Lammich <peter.lammich@uni-muenster.de>\n*)\nheader \"Flowgraphs\"\ntheory Flowgraph\nimports Main Misc\nbegin\ntext_raw {*\\label{thy:Flowgraph}*}\n\ntext {*\n  We use a flowgraph-based program model that extends the one we used previously \\cite{LM07}. \n  A program is represented as an edge annotated graph and a set of procedures. The nodes of the graph are partitioned by the procedures, i.e. every node belongs to exactly one procedure. There are no edges\n  between nodes of different procedures. Every procedure has a distinguished entry and return node and a set of monitors it synchronizes on. Additionally, the program has a distinguished {\\em main} procedure.\n  The edges are annotated with statements. A statement is either a base statement, a procedure call or a thread creation (spawn). Procedure calls and thread creations refer to the called procedure or to the initial procedure\n  of the spawned thread, respectively.\n\n  We require that the main procedure and any initial procedure of a spawned thread does not to synchronize on any monitors. This avoids that spawning of a procedure together with entering a monitor is available in our \n  model as an atomic step, which would be an unrealistic assumption for practical problems. Technically, our model would become strictly more powerful without this assumption.\n\n\n  If we allowed this, our model would become strictly more powerful, \n*}\n\nsubsection \"Definitions\"\n  \ndatatype ('p,'ba) edgeAnnot = Base 'ba | Call 'p | Spawn 'p\ntype_synonym ('n,'p,'ba) edge = \"('n \\<times> ('p,'ba) edgeAnnot \\<times> 'n)\"\n\nrecord ('n,'p,'ba,'m) flowgraph_rec =\n  edges :: \"('n,'p,'ba) edge set\" -- \"Set of annotated edges\"\n  main :: \"'p\" -- \"Main procedure\"\n  entry :: \"'p \\<Rightarrow> 'n\" -- \"Maps a procedure to its entry point\"\n  return :: \"'p \\<Rightarrow> 'n\" -- \"Maps a procedure to its return point\"\n  mon :: \"'p \\<Rightarrow> 'm set\" -- \"Maps procedures to the set of monitors they allocate\"\n  proc_of :: \"'n \\<Rightarrow> 'p\" -- \"Maps a node to the procedure it is contained in\"\n\ndefinition \n  \"initialproc fg p == p=main fg \\<or> (\\<exists>u v. (u,Spawn p,v)\\<in>edges fg)\"\n\nlemma main_is_initial[simp]: \"initialproc fg (main fg)\"\n  by (unfold initialproc_def) simp\n\nlocale flowgraph =\n  fixes fg :: \"('n,'p,'ba,'m,'more) flowgraph_rec_scheme\" (structure)\n  (* Type annotation unnecessary, but perhaps makes it more readable\n     for the unaware reader ;) *)\n  -- \"Edges are inside procedures only\"\n  assumes edges_part: \"(u,a,v)\\<in>edges fg \\<Longrightarrow> proc_of fg u = proc_of fg v\" \n  -- \"The entry point of a procedure must be in that procedure\"\n  assumes entry_valid[simp]: \"proc_of fg (entry fg p) = p\" \n  -- \"The return point of a procedure must be in that procedure\"\n  assumes return_valid[simp]: \"proc_of fg (return fg p) = p\" \n  -- \"Initial procedures do not synchronize on any monitors\"\n  assumes initial_no_mon[simp]: \"initialproc fg p \\<Longrightarrow> mon fg p = {}\" \n\nsubsection \"Basic properties\"\nlemma (in flowgraph) spawn_no_mon[simp]: \n  \"(u, Spawn p, v) \\<in> edges fg \\<Longrightarrow> mon fg p = {}\" \n  using initial_no_mon by (unfold initialproc_def, blast)\nlemma (in flowgraph) main_no_mon[simp]: \"mon fg (main fg) = {}\" \n  using initial_no_mon by (unfold initialproc_def, blast)\n\n\n\nlemma (in flowgraph) entry_entry_same_proc[simp]: \n  \"entry fg p = entry fg p' \\<Longrightarrow> p=p'\"\n  apply (subgoal_tac \"proc_of fg (entry fg p) = proc_of fg (entry fg p')\")\n  apply (simp (no_asm_use))\n  by simp\n\nlemma (in flowgraph) return_return_same_proc[simp]: \n  \"return fg p = return fg p' \\<Longrightarrow> p=p'\"\n  apply (subgoal_tac \"proc_of fg (return fg p) = proc_of fg (entry fg p')\")\n  apply (simp (no_asm_use))\n  by simp\n\nsubsection \"Extra assumptions for flowgraphs\"\ntext_raw {*\\label{sec:Flowgraph:extra_asm}*}\ntext {*\n  In order to simplify the definition of our restricted schedules (cf. Section~\\ref{thy:Normalization}), we make some extra constraints on flowgraphs. \n  Note that these are no real restrictions, as we can always rewrite flowgraphs to match these constraints, preserving the set of conflicts. We leave it to future work to consider such a rewriting formally. \n\n  The background of this restrictions is that we want to start an execution of a thread with a procedure call that never returns. This will allow easier technical treatment in Section~\\ref{thy:Normalization}. Here we enforce this\n  semantic restrictions by syntactic properties of the flowgraph.\n*}\n\ntext {* The return node of a procedure is called {\\em isolated}, if it has no incoming edges and is different from the entry node. A procedure with an isolated return node will never return. \n  See Section~\\ref{sec:Normalization:eflowgraph} for a proof of this. *}\ndefinition \n  \"isolated_ret fg p == \n    (\\<forall>u l. \\<not>(u,l,return fg p)\\<in>edges fg) \\<and> entry fg p \\<noteq> return fg p\"\n\ntext {* The following syntactic restrictions guarantee that each thread's execution starts with a non-returning call. See Section~\\ref{sec:Normalization:eflowgraph} for a proof of this. *}\nlocale eflowgraph = flowgraph +\n  -- \"Initial procedure's entry node isn't equal to its return node\"\n  assumes initial_no_ret: \"initialproc fg p \\<Longrightarrow> entry fg p \\<noteq> return fg p\" \n  -- \"The only outgoing edges of initial procedures' entry nodes are call edges to procedures with isolated return node\"\n  assumes initial_call_no_ret: \"\\<lbrakk>initialproc fg p; (entry fg p,l,v)\\<in>edges fg\\<rbrakk> \n    \\<Longrightarrow> \\<exists>p'. l=Call p' \\<and> isolated_ret fg p'\" \n\nsubsection {* Example Flowgraph*}\ntext_raw {* \\label{sec:Flowgraph:ex_flowgraph} *}\ntext {* This section contains a check that there exists a (non-trivial) flowgraph, i.e. that the assumptions made in the @{text flowgraph} and @{text eflowgraph} \n  locales are consistent and have at least one non-trivial model. *}\ndefinition \n  \"example_fg == \\<lparr> \n    edges = {((0::nat,0::nat),Call 1,(0,1)), ((1,0),Spawn 0,(1,0)), \n             ((1,0),Call 0, (1,0))}, \n    main = 0, \n    entry = \\<lambda>p. (p,0), \n    return = \\<lambda>p. (p,1), \n    mon = \\<lambda>p. if p=1 then {0} else {}, \n    proc_of= \\<lambda> (p,x). p \\<rparr>\"\n\nlemma exists_eflowgraph: \"eflowgraph example_fg\"\n  apply (unfold_locales)\n  apply (unfold example_fg_def)\n  apply simp\n  apply fast\n  apply simp\n  apply simp\n  apply (simp add: initialproc_def)\n  apply (simp add: initialproc_def)\n  apply (simp add: initialproc_def isolated_ret_def)\n  done\n\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Program-Conflict-Analysis/Flowgraph.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5621765155565326, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.2898694075727179}}
{"text": "(*  Title:      HOL/Auth/WooLam.thy\n    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory\n    Copyright   1996  University of Cambridge\n*)\n\nsection\\<open>The Woo-Lam Protocol\\<close>\n\ntheory WooLam imports Public begin\n\ntext\\<open>Simplified version from page 11 of\n  Abadi and Needham (1996). \n  Prudent Engineering Practice for Cryptographic Protocols.\n  IEEE Trans. S.E. 22(1), pages 6-15.\n\nNote: this differs from the Woo-Lam protocol discussed by Lowe (1996):\n  Some New Attacks upon Security Protocols.\n  Computer Security Foundations Workshop\n\\<close>\n\ninductive_set woolam :: \"event list set\"\n  where\n         (*Initial trace is empty*)\n   Nil:  \"[] \\<in> woolam\"\n\n         (** These rules allow agents to send messages to themselves **)\n\n         (*The spy MAY say anything he CAN say.  We do not expect him to\n           invent new nonces here, but he can also use NS1.  Common to\n           all similar protocols.*)\n | Fake: \"[| evsf \\<in> woolam;  X \\<in> synth (analz (spies evsf)) |]\n          ==> Says Spy B X  # evsf \\<in> woolam\"\n\n         (*Alice initiates a protocol run*)\n | WL1:  \"evs1 \\<in> woolam ==> Says A B (Agent A) # evs1 \\<in> woolam\"\n\n         (*Bob responds to Alice's message with a challenge.*)\n | WL2:  \"[| evs2 \\<in> woolam;  Says A' B (Agent A) \\<in> set evs2 |]\n          ==> Says B A (Nonce NB) # evs2 \\<in> woolam\"\n\n         (*Alice responds to Bob's challenge by encrypting NB with her key.\n           B is *not* properly determined -- Alice essentially broadcasts\n           her reply.*)\n | WL3:  \"[| evs3 \\<in> woolam;\n             Says A  B (Agent A)  \\<in> set evs3;\n             Says B' A (Nonce NB) \\<in> set evs3 |]\n          ==> Says A B (Crypt (shrK A) (Nonce NB)) # evs3 \\<in> woolam\"\n\n         (*Bob forwards Alice's response to the Server.  NOTE: usually\n           the messages are shown in chronological order, for clarity.\n           But here, exchanging the two events would cause the lemma\n           WL4_analz_spies to pick up the wrong assumption!*)\n | WL4:  \"[| evs4 \\<in> woolam;\n             Says A'  B X         \\<in> set evs4;\n             Says A'' B (Agent A) \\<in> set evs4 |]\n          ==> Says B Server \\<lbrace>Agent A, Agent B, X\\<rbrace> # evs4 \\<in> woolam\"\n\n         (*Server decrypts Alice's response for Bob.*)\n | WL5:  \"[| evs5 \\<in> woolam;\n             Says B' Server \\<lbrace>Agent A, Agent B, Crypt (shrK A) (Nonce NB)\\<rbrace>\n               \\<in> set evs5 |]\n          ==> Says Server B (Crypt (shrK B) \\<lbrace>Agent A, Nonce NB\\<rbrace>)\n                 # evs5 \\<in> woolam\"\n\n\ndeclare Says_imp_knows_Spy [THEN analz.Inj, dest]\ndeclare parts.Body  [dest]\ndeclare analz_into_parts [dest]\ndeclare Fake_parts_insert_in_Un  [dest]\n\n\n(*A \"possibility property\": there are traces that reach the end*)\nlemma \"\\<exists>NB. \\<exists>evs \\<in> woolam.\n             Says Server B (Crypt (shrK B) \\<lbrace>Agent A, Nonce NB\\<rbrace>) \\<in> set evs\"\napply (intro exI bexI)\napply (rule_tac [2] woolam.Nil\n                    [THEN woolam.WL1, THEN woolam.WL2, THEN woolam.WL3,\n                     THEN woolam.WL4, THEN woolam.WL5], possibility)\ndone\n\n(*Could prove forwarding lemmas for WL4, but we do not need them!*)\n\n(**** Inductive proofs about woolam ****)\n\n(** Theorems of the form X \\<notin> parts (spies evs) imply that NOBODY\n    sends messages containing X! **)\n\n(*Spy never sees a good agent's shared key!*)\nlemma Spy_see_shrK [simp]:\n     \"evs \\<in> woolam ==> (Key (shrK A) \\<in> parts (spies evs)) = (A \\<in> bad)\"\nby (erule woolam.induct, force, simp_all, blast+)\n\nlemma Spy_analz_shrK [simp]:\n     \"evs \\<in> woolam ==> (Key (shrK A) \\<in> analz (spies evs)) = (A \\<in> bad)\"\nby auto\n\nlemma Spy_see_shrK_D [dest!]:\n     \"[|Key (shrK A) \\<in> parts (knows Spy evs);  evs \\<in> woolam|] ==> A \\<in> bad\"\nby (blast dest: Spy_see_shrK)\n\n\n(**** Autheticity properties for Woo-Lam ****)\n\n(*** WL4 ***)\n\n(*If the encrypted message appears then it originated with Alice*)\nlemma NB_Crypt_imp_Alice_msg:\n     \"[| Crypt (shrK A) (Nonce NB) \\<in> parts (spies evs);\n         A \\<notin> bad;  evs \\<in> woolam |]\n      ==> \\<exists>B. Says A B (Crypt (shrK A) (Nonce NB)) \\<in> set evs\"\nby (erule rev_mp, erule woolam.induct, force, simp_all, blast+)\n\n(*Guarantee for Server: if it gets a message containing a certificate from\n  Alice, then she originated that certificate.  But we DO NOT know that B\n  ever saw it: the Spy may have rerouted the message to the Server.*)\nlemma Server_trusts_WL4 [dest]:\n     \"[| Says B' Server \\<lbrace>Agent A, Agent B, Crypt (shrK A) (Nonce NB)\\<rbrace>\n           \\<in> set evs;\n         A \\<notin> bad;  evs \\<in> woolam |]\n      ==> \\<exists>B. Says A B (Crypt (shrK A) (Nonce NB)) \\<in> set evs\"\nby (blast intro!: NB_Crypt_imp_Alice_msg)\n\n\n(*** WL5 ***)\n\n(*Server sent WL5 only if it received the right sort of message*)\nlemma Server_sent_WL5 [dest]:\n     \"[| Says Server B (Crypt (shrK B) \\<lbrace>Agent A, NB\\<rbrace>) \\<in> set evs;\n         evs \\<in> woolam |]\n      ==> \\<exists>B'. Says B' Server \\<lbrace>Agent A, Agent B, Crypt (shrK A) NB\\<rbrace>\n             \\<in> set evs\"\nby (erule rev_mp, erule woolam.induct, force, simp_all, blast+)\n\n(*If the encrypted message appears then it originated with the Server!*)\nlemma NB_Crypt_imp_Server_msg [rule_format]:\n     \"[| Crypt (shrK B) \\<lbrace>Agent A, NB\\<rbrace> \\<in> parts (spies evs);\n         B \\<notin> bad;  evs \\<in> woolam |]\n      ==> Says Server B (Crypt (shrK B) \\<lbrace>Agent A, NB\\<rbrace>) \\<in> set evs\"\nby (erule rev_mp, erule woolam.induct, force, simp_all, blast+)\n\n(*Guarantee for B.  If B gets the Server's certificate then A has encrypted\n  the nonce using her key.  This event can be no older than the nonce itself.\n  But A may have sent the nonce to some other agent and it could have reached\n  the Server via the Spy.*)\nlemma B_trusts_WL5:\n     \"[| Says S B (Crypt (shrK B) \\<lbrace>Agent A, Nonce NB\\<rbrace>) \\<in> set evs;\n         A \\<notin> bad;  B \\<notin> bad;  evs \\<in> woolam  |]\n      ==> \\<exists>B. Says A B (Crypt (shrK A) (Nonce NB)) \\<in> set evs\"\nby (blast dest!: NB_Crypt_imp_Server_msg)\n\n\n(*B only issues challenges in response to WL1.  Not used.*)\nlemma B_said_WL2:\n     \"[| Says B A (Nonce NB) \\<in> set evs;  B \\<noteq> Spy;  evs \\<in> woolam |]\n      ==> \\<exists>A'. Says A' B (Agent A) \\<in> set evs\"\nby (erule rev_mp, erule woolam.induct, force, simp_all, blast+)\n\n\n(**CANNOT be proved because A doesn't know where challenges come from...*)\nlemma \"[| A \\<notin> bad;  B \\<noteq> Spy;  evs \\<in> woolam |]\n  ==> Crypt (shrK A) (Nonce NB) \\<in> parts (spies evs) \\<and>\n      Says B A (Nonce NB) \\<in> set evs\n      \\<longrightarrow> Says A B (Crypt (shrK A) (Nonce NB)) \\<in> set evs\"\napply (erule rev_mp, erule woolam.induct, force, simp_all, blast, auto)\noops\n\nend\n", "meta": {"author": "m-fleury", "repo": "isabelle-emacs", "sha": "756c662195e138a1941d22d4dd7ff759cbf6b6b9", "save_path": "github-repos/isabelle/m-fleury-isabelle-emacs", "path": "github-repos/isabelle/m-fleury-isabelle-emacs/isabelle-emacs-756c662195e138a1941d22d4dd7ff759cbf6b6b9/src/HOL/Auth/WooLam.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5621765008857981, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.289869400008195}}
{"text": "theory a3\nimports\n  \"AutoCorres.AutoCorres\"\n  \"AutoCorres.TypHeapSimple\"\nbegin\n\n(* To run this file you need the AutoCorres tool used\n   in the lecture.\n\n  1. Download AutoCorres from \n       \\url{http://www.cse.unsw.edu.au/~cs4161/autocorres-1.6.1.tar}\n\n  2. Unpack the .tar.gz file, which will create the directory autocorres-1.6.1\n       tar -xzf autocorres-1.6.1.tar.gz\n\n  3. Build the AutoCorres heap\n     L4V_ARCH=X64 isabelle build -v -b -d autocorres-1.6.1 AutoCorres\n\n  4. Load this file using the AutoCorres heap\n     L4V_ARCH=X64 isabelle jedit -d autocorres-1.6.1 -l AutoCorres a3.thy\n\n*)\n\nsection \"Question: Reverse \"\n\n(* Hints: \n    - use find_theorems to find Isabelle library theorems about existing concepts.\n    - you are allowed to use sledgehammer and other automation\n    - if you can't prove one of the lemmas below, you can still assume it in the rest of the proof\n    - the function @{const int} converts an Isabelle nat to an int\n    - the function @{const nat} converts an Isabelle int to a nat\n    - If you want to use apply style, you could the tactic @{text insert assms} \n      to insert assumptions into your proof.\n*)\n\n(* Parse the input file. *)\ninstall_C_file \"reverse.c\"\n\n(* Abstract the input file. *)\nautocorres[unsigned_word_abs=reverse] \"reverse.c\"\n\n\nsection \\<open>utility lemmas\\<close>\n\n(* This makes an intro rule which can be used with rule_tac, as opposed to\n    using whileLoop_add_inv and subst. *)\nlemma whileLoop_add_invI:\n  assumes \"\\<lbrace> P \\<rbrace> whileLoop_inv c b init I (measure M) \\<lbrace> Q \\<rbrace>!\"\n  shows \"\\<lbrace> P \\<rbrace> whileLoop c b init \\<lbrace> Q \\<rbrace>!\"\n  by (metis assms whileLoop_inv_def)\n\nlemma pointer_add_ldistrib_add:\n  \"p +\\<^sub>p (a + b) = (p +\\<^sub>p a) +\\<^sub>p b\"\n  unfolding ptr_add_def\n  by (simp add: algebra_simps)\n\nlemma heap_w32_update_comp: \n  \"heap_w32_update (f \\<circ> g) s = heap_w32_update f (heap_w32_update g s)\"\n  by simp\n\ntext \\<open> This assumes that pointers are wellbehaved \\<close>\ndefinition wellbehaved_pointers :: \"('a :: c_type) ptr \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"wellbehaved_pointers p n \\<equiv> \n    \\<forall>i j :: int. i < n \\<longrightarrow> j < n \\<longrightarrow> ((p +\\<^sub>p i :: 'a ptr) = p +\\<^sub>p j) \\<longleftrightarrow> (i = j)\"\n\nlemma wellbehaved_pointers_D:\n  fixes n :: nat\n  and i j :: int\n  assumes\n    \"wellbehaved_pointers p n\"\n    \"i < n\"\n    \"j < n\"\n  shows\n    \"(p +\\<^sub>p i = p +\\<^sub>p j) \\<longleftrightarrow> (i = j)\"\n  using assms\n  by (simp add: wellbehaved_pointers_def)\n\nlemma int_geq_0_less_Suc_eq_0_disj:\n  fixes a b :: int\n  assumes\n    \"0 \\<le> a\"\n    \"0 \\<le> b\"\n  shows\n    \"a < 1 + b \\<longleftrightarrow> a = 0 \\<or> (\\<exists>a'. a = 1 + a' \\<and> 0 \\<le> a' \\<and> a' < b)\"\n  using assms\n  by presburger\n\nlemma geq_step_Suc:\n  \"(\\<forall>x\\<ge>m. P x) = (P m \\<and> (\\<forall>x\\<ge>Suc m. P x))\"\n  by (metis Suc_leD dual_order.antisym not_less_eq_eq)\n\nlemma gr_is_geq_Suc:\n  \"(\\<forall>x>m. P x) = ((\\<forall>x\\<ge>Suc m. P x))\"\n  by (simp add: Suc_le_eq)\n\nlemma leq_minus_split:\n    \"i \\<le> n - m \\<longleftrightarrow> i \\<le> n - Suc m \\<or> i = n - m\"\n  by linarith\n\nlemma gr_minus_Suc:\n  assumes\n    \"m > n\"\n  shows\n    \"(\\<forall>x>m - Suc n. P x) \\<longleftrightarrow> P (m - n) \\<and> (\\<forall>x>m - n. P x)\"\n  using assms\n  apply (simp add: gr_is_geq_Suc Suc_diff_Suc)\n  apply (subst (1) le_less)\n  apply (simp add: Suc_le_eq split_all_conj)\n  apply fast\n  done\n\n\n(*******************************************************************************)\n\nprimrec\n  arr_is_valid :: \"lifted_globals \\<Rightarrow> word32 ptr \\<Rightarrow> nat \\<Rightarrow> bool\"\nwhere\n    \"arr_is_valid s p 0 = True\"\n  | \"arr_is_valid s p (Suc n) = (is_valid_w32 s p \\<and> arr_is_valid s (p +\\<^sub>p 1) n)\"\n\n\nlemma arr_is_valid_update_heap:\n  \"arr_is_valid (heap_w32_update f s) p n \\<longleftrightarrow> arr_is_valid s p n\"\n  by (induct n arbitrary: p) simp+\n\nlemma arr_is_valid_conv_all_nth:\n  \"arr_is_valid s p n \\<longleftrightarrow> (\\<forall>i<n. is_valid_w32 s (p +\\<^sub>p int i))\"\n  by (induct n arbitrary: p)                 \n    (simp add: All_less_Suc2 pointer_add_ldistrib_add)+\n\nlemma arr_is_validD:\n  \"arr_is_valid s p n \\<Longrightarrow> i < n \\<Longrightarrow> is_valid_w32 s (p +\\<^sub>p int i)\"\n  using arr_is_valid_conv_all_nth\n  by blast\n\nlemma arr_is_valid_intD:\n  \"arr_is_valid s p n \\<Longrightarrow> 0 \\<le> i \\<Longrightarrow> nat i < n \\<Longrightarrow> is_valid_w32 s (p +\\<^sub>p i)\"\n  using arr_is_valid_conv_all_nth\n  by auto\n\nlemma arr_is_valid_smaller:\n  \"arr_is_valid s p n \\<Longrightarrow> m \\<le> n \\<Longrightarrow> arr_is_valid s p m\"\n  by (simp add: arr_is_valid_conv_all_nth)\n\n\nsubsection \\<open> arr_is_valid \\<close>\n\nprimrec\n  arr_list :: \"lifted_globals \\<Rightarrow> word32 ptr \\<Rightarrow> nat \\<Rightarrow> word32 list\"\nwhere\n    \"arr_list s p 0 = []\"\n  | \"arr_list s p (Suc n) = (heap_w32 s p) # arr_list s (p +\\<^sub>p 1) n\"\n\n\nlemma heap_to_arr_list_lookup:\n  fixes i :: int\n  assumes\n    \"0 \\<le> i\"\n    \"i < n\"\n  shows \"heap_w32 s (p +\\<^sub>p i) = arr_list s p n ! nat i\"\n  using assms\n  apply (induct n arbitrary: p i)\n   apply simp\n  apply (clarsimp simp add: nth_Cons int_geq_0_less_Suc_eq_0_disj split: nat.splits)\n  apply (force simp add: pointer_add_ldistrib_add dest: Suc_nat_eq_nat_zadd1)\n  done\n\nlemma arr_list_to_heap_lookup:\n  assumes \"i < n\"\n  shows \"arr_list s p n ! i = heap_w32 s (p +\\<^sub>p int i)\"\n  using assms\n  by (induct n arbitrary: p i) (force simp: less_Suc_eq_0_disj pointer_add_ldistrib_add)+\n\n\nlemma arr_list_length: \"length (arr_list s p n) = n\"\n  by (induct n arbitrary: p) force+\n\nlemma arr_list_empty_iff: \"arr_list s p n = [] \\<longleftrightarrow> n = 0\"\n  by (metis arr_list.simps(1) arr_list_length)\n\nlemma arr_list_heap_update:\n  assumes\n    \"wellbehaved_pointers p n\"\n    \"0 \\<le> i\"\n    \"nat i < n\"\n    \"arr_is_valid s p n\"\n  shows\n    \"arr_list (heap_w32_update (\\<lambda>h. h(p +\\<^sub>p i := v)) s) p n = (arr_list s p n)[nat i := v]\"\n  using assms\n  by (force simp add:\n      list_eq_iff_nth_eq arr_list_to_heap_lookup fun_upd_def\n      arr_list_length wellbehaved_pointers_def)\n\nlemma arr_list_heap_update_comp:\n  assumes\n    \"wellbehaved_pointers p n\"\n    \"0 \\<le> i\"\n    \"nat i < n\"\n    \"arr_is_valid s p n\"\n  shows\n    \"arr_list (heap_w32_update ((\\<lambda>a. a(p +\\<^sub>p i := v)) \\<circ> f) s) p n = (arr_list (heap_w32_update f s) p n)[nat i := v]\"\n  using assms\n  apply -\n  apply (subst heap_w32_update_comp)\n  apply (subst arr_list_heap_update)\n      apply blast\n     apply blast\n    apply blast\n    apply (simp add: arr_is_valid_update_heap)\n  apply blast\n  done\n\nlemmas arr_list_heap_update_simps = arr_list_heap_update arr_list_heap_update_comp\n\n(*******************************************************************************)\n\ncontext reverse begin\n\n\nsection \\<open> Reverse \\<close>\n\n\n(* The monadic definition that autocorres produces for the C code: *)\nthm reverse'_def\n\nsubsection \\<open> Reverse invariant \\<close>\n\n(* Hint: The invariant for the reverse function is split into three parts.\n         In the following three definitions xs is the input list, \n         xs' is the modified list, and i, j are list indices. *)\n\n(*  Replace True with the correct invariant in each of the following three definitions. *)\n\ndefinition left_invariant :: \"word32 list \\<Rightarrow> word32 list \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"left_invariant xs xs' i j \\<equiv> \\<forall>k. k < i \\<longrightarrow> xs' ! k = xs ! (length xs - k - 1)\"\n\ndefinition middle_invariant :: \"word32 list \\<Rightarrow> word32 list \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"middle_invariant xs xs' i j \\<equiv> \\<forall>k. i \\<le> k \\<longrightarrow> k \\<le> j \\<longrightarrow> xs' ! k = xs ! k\"\n\ndefinition right_invariant :: \"word32 list \\<Rightarrow> word32 list \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"right_invariant xs xs' i j \\<equiv> \\<forall>k. j < k \\<longrightarrow> k < length xs \\<longrightarrow> xs'!k = xs!(length xs - k - 1)\"\n\ndefinition reverse_inv :: \"word32 list \\<Rightarrow> word32 list \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"reverse_inv xs xs' i j \\<equiv>\n    left_invariant xs xs' i j \\<and> \\<comment> \\<open> everything less than i is ...  \\<close>\n    middle_invariant xs xs' i j \\<and> \\<comment> \\<open> everything between i and j is ... \\<close>\n    right_invariant xs xs' i j\" \\<comment> \\<open> everything larger than j is ...  \\<close>  \n\nlemmas reverse_invariant_def = left_invariant_def middle_invariant_def right_invariant_def reverse_inv_def\n\n\n(* Replace SOMETHING in the following lemmas by something that would allow you  \n    to prove reverse_correct. *)\n\n\nlemma left_invariant_step:\n  assumes\n    \"length xs' = length xs\"\n    \"i < length xs - Suc i\"\n    \"middle_invariant xs xs' i (length xs - Suc i)\"\n    \"left_invariant xs xs' i (length xs - Suc i)\"\n  shows\n    \"left_invariant xs \n    (xs'[i := xs' ! (length xs - Suc i),length xs - Suc i:= xs'! i])\n    (Suc i) (length xs - Suc (Suc i))\"\n  using assms \n  unfolding left_invariant_def middle_invariant_def \n  apply clarsimp\n  by (metis (no_types, hide_lams) less_imp_diff_less linorder_neqE_nat not_less_eq nth_list_update_eq nth_list_update_neq)\n\nlemma right_invariant_step:\n  assumes\n    \"length xs' = length xs\"\n    \"i < length xs - Suc i\"\n    \"middle_invariant xs xs' i (length xs - Suc i)\"\n    \"right_invariant xs xs' i (length xs - Suc i)\"\n  shows\n    \"right_invariant xs \n    (xs'[i := xs' ! (length xs - Suc i),length xs - Suc i:= xs'! i]) \n    (Suc i) (length xs - Suc (Suc i))\"\n  using assms \n  unfolding middle_invariant_def right_invariant_def \n  apply clarsimp \n  proof -\n    fix k :: nat\n    assume a1: \"length xs - Suc (Suc i) < k\"\n    assume a2: \"\\<forall>k>length xs - Suc i. k < length xs \\<longrightarrow> xs' ! k = xs ! (length xs - Suc k)\"\n    assume a3: \"k < length xs\"\n    have f4: \"length xs - Suc i = k \\<or> \\<not> k < length xs - Suc i\"\n      using a1 by (metis (no_types) leq_minus_split less_Suc_eq_le nat_less_le not_less_eq)\n    have \"\\<not> length xs - Suc i \\<le> i\"\n      by (meson assms(2) less_Suc_eq_le not_less_eq)\n    then have f5: \"i \\<le> length xs\"\n      by (meson i_hate_words_helper nat_le_linear)\n    have f6: \"\\<not> length xs < i\"\n      by (meson assms(2) less_Suc_eq less_imp_diff_less not_less_eq)\n    have \"\\<forall>n. n - Suc n = 0\"\n      by simp\n    then show \"xs'[i := xs ! (length xs - Suc i), length xs - Suc i := xs ! i] ! k = xs ! (length xs - Suc k)\"\n      using f6 f5 f4 a3 a2 by (metis (no_types) Suc_diff_Suc assms(1) assms(2) diff_diff_cancel length_list_update linorder_neqE_nat not_less_zero nth_list_update_eq nth_list_update_neq)\n  qed\n\nlemma middle_invariant_step:\n  assumes\n    \"length xs' = length xs\"\n    \"i < length xs - Suc i\"\n    \"middle_invariant xs xs' i (length xs - Suc i)\"\n  shows\n    \"middle_invariant xs \n    (xs'[i := xs' ! (length xs - Suc i),length xs - Suc i:= xs'! i])\n     (Suc i) (length xs - Suc (Suc i))\"\n  using assms unfolding middle_invariant_def by clarsimp \n\n\ntext \\<open> Show the precondition implies the invariant \\<close>\nlemma pre_impl_inv:\n  assumes\n    \"n < UINT_MAX\"\n    \"arr_is_valid s p n\"\n    \"xs = arr_list s p n\"\n    \"0 < n\"\n  shows\n    \"xs \\<noteq> []\"\n    \"reverse_inv (arr_list s p n) (arr_list s p n) 0 (n - Suc 0)\"\n  using assms\n  unfolding reverse_inv_def left_invariant_def middle_invariant_def right_invariant_def\n  by (auto simp add: arr_list_empty_iff arr_list_length)\n   \ntext \\<open> Show the invariant implies the postcondition \\<close>\n\nlemma left_all_is_rev:\n  \"left_invariant xs (rev(xs)) (length xs - 1) 0\"\n  unfolding left_invariant_def \n  by (simp add: nth_rev)\n\nlemma \n  \"i < length xs \\<longrightarrow> left_invariant xs (rev(xs)) i (length xs -i -1)\"\n  unfolding left_invariant_def\n  by (simp add: nth_rev)\n\nlemma for_k_impl_rev:\n  \"length xs = length ys \\<Longrightarrow>  \\<forall>k. k < length xs \\<longrightarrow> ys! k  = xs ! (length xs - k - 1) \\<Longrightarrow> ys = rev xs\"\n  apply clarsimp\n  apply (induct xs  arbitrary:ys )\n  apply simp \n  by (metis length_rev nth_equalityI nth_rev_alt rev_rev_ident) \n\nlemma inv_impl_post:\n  assumes\n    \"reverse_inv xs (arr_list s p (length xs)) r (length xs - Suc r)\"\n    \"arr_is_valid s p (length xs)\"\n    \"length xs - Suc r \\<le> r\"\n  shows \"arr_list s p (length xs) = rev xs\"\n  using assms\n  unfolding reverse_inv_def left_invariant_def middle_invariant_def right_invariant_def\n  apply clarsimp\n  using for_k_impl_rev \n  by (smt arr_list_length diff_diff_cancel length_rev less_imp_diff_less linorder_neqE_nat\n      nat_less_le nth_equalityI rev_nth) \n  \n\ntext \\<open> Show the invariant is preserved by the loop \\<close>\nlemma invariant_preservation:\n  assumes\n    \"i < length xs - Suc i\"\n    \"arr_is_valid s p (length xs)\"\n    \"reverse_inv xs (arr_list s p (length xs)) i (length xs - Suc i)\"\n  shows\n    \"reverse_inv xs\n    ((arr_list s p (length xs))[i := xs ! (length xs - Suc i),length xs - Suc i:= xs! i])\n     (Suc i) (length xs - Suc (Suc i))\"\n  using assms \n  unfolding reverse_inv_def left_invariant_def middle_invariant_def right_invariant_def\n  apply safe \n    apply clarsimp \n    apply (metis (no_types, hide_lams) arr_list_length less_antisym less_imp_diff_less not_less_eq nth_list_update_eq nth_list_update_neq)\n   apply simp \n  apply clarsimp \n  proof -\n    fix k :: nat\n    assume a1: \"\\<forall>k>length xs - Suc i. k < length xs \\<longrightarrow> arr_list s p (length xs) ! k = xs ! (length xs - Suc k)\"\n    assume a2: \"k < length xs\"\n    assume a3: \"length xs - Suc (Suc i) < k\"\n    have f4: \"\\<forall>n na. \\<not> (n::nat) \\<le> na \\<or> \\<not> na < n\"\n      using less_Suc_eq_le not_less_eq by presburger\n    then have f5: \"length xs - Suc i = k \\<or> \\<not> k \\<le> length xs - Suc i\"\n      using a3 by (metis (no_types) leq_minus_split)\n    have f6: \"i \\<le> length xs\"\n      using assms(1) by linarith\n    have f7: \"Suc i \\<le> length xs\"\n      by (meson assms(1) less_Suc_eq_le less_imp_diff_less not_less_eq)\n    have \"\\<not> k \\<le> i\"\n      using f5 f4 by (meson assms(1) le_trans nat_less_le)\n      moreover\n      { assume \"length xs - k \\<noteq> i \\<and> k \\<noteq> i\"\n        then have \"(arr_list s p (length xs)) [i := xs ! (length xs - Suc i), length xs - Suc i := xs ! i] ! k = xs ! (length xs - Suc k) \\<or> length xs - Suc i \\<noteq> k \\<and> k \\<noteq> i\"\n          using f6 f4 a2 by (metis (no_types) arr_list_length diff_diff_cancel length_list_update leq_minus_split nat_less_le not_less_eq_eq nth_list_update_eq) }\n      ultimately show \"(arr_list s p (length xs)) [i := xs ! (length xs - Suc i), length xs - Suc i := xs ! i] ! k = xs ! (length xs - Suc k)\"\n        using f7 f5 a2 a1 by (metis (no_types) diff_diff_cancel nat_le_linear nat_less_le not_less_eq_eq nth_list_update_neq)\n    qed\n\ntext \\<open> Show reverse is correct \\<close>\n\nlemma inv_impl_mid: \"reverse_inv xs xs' i j  \\<Longrightarrow> middle_invariant xs xs' i j\"\n  unfolding reverse_inv_def by blast \n\nlemma mid_impl_access_origin: \n  \"\\<lbrakk>middle_invariant xs xs' i j ; ine \\<ge> i ;  ine \\<le> j\\<rbrakk> \\<Longrightarrow> xs ! ine = xs'! ine\"\n  unfolding middle_invariant_def by simp \n\n\nlemma state_access_is_arr_access: \n  \"xs = arr_list s p n \\<Longrightarrow> x < n \\<and> x \\<ge> 0 \\<Longrightarrow> xs ! x = heap_w32 s (p +\\<^sub>p int (x))\"\n  by (simp add: arr_list_to_heap_lookup)\n\nlemma mid_impl_access_state_origin:\n  \"\\<lbrakk>i < j; i \\<ge> 0; j < n;length xs = n;xs' = arr_list s p n;\n   middle_invariant xs xs' i j ; ine \\<ge> i ;  ine \\<le> j\\<rbrakk>\n   \\<Longrightarrow> heap_w32 s (p +\\<^sub>p int (ine)) =  xs ! ine \"\n  unfolding middle_invariant_def \n  by (simp add: arr_list_to_heap_lookup)\n\nlemma mid_impl_access_heap : \"\\<lbrakk>\n  i < j; i \\<ge> 0; j < n;length xs = n;xs' = arr_list s p n;n < UINT_MAX;\n   middle_invariant xs xs' i j ; ine \\<ge> i ;  ine \\<le> j; k \\<ge>0 ; k < n \\<rbrakk>\n  \\<Longrightarrow> xs [k := heap_w32 s (p +\\<^sub>p int (ine)) ] = xs [k := xs ! ine]\" \n  unfolding middle_invariant_def \n  apply clarsimp \n  by (simp add: arr_list_to_heap_lookup)\n\nlemma pointer_add_simp:\n  fixes r :: nat\n    and s :: lifted_globals\n  assumes a1: \"r < length xs - Suc r\"\n  assumes a2: \"n = length xs\"\n  assumes a3: \"arr_is_valid s p (length xs)\"\n  shows \"is_valid_w32 s (p +\\<^sub>p (int (length xs) - (1 + int r)))\" \n  proof - \n    have f4: \"r < n - Suc r\"\n      using a2 a1 by meson\n    then have \"Suc r < n\"\n      by linarith\n    then have f5: \"\\<not> n < Suc r\"\n      by linarith\n    have \"n - Suc r < n\"\n      using f4 by linarith\n    then show \"is_valid_w32 s (p +\\<^sub>p (int (length xs) - (1 + int r)))\"\n      using f5 a3 a2 by (metis (no_types) add_diff_cancel_left' add_diff_inverse_nat arr_is_validD of_nat_Suc of_nat_add)\n  qed \n\nlemma reverse_correct:\n  \"\\<lbrace> \\<lambda>s. wellbehaved_pointers p n \\<and>\n         length xs < UINT_MAX \\<and>\n         arr_is_valid s p (length xs) \\<and>\n         arr_list s p n = xs \\<and>\n         n = length xs \\<and>\n         n > 0\n   \\<rbrace>\n       reverse' p n\n   \\<lbrace> \\<lambda>r s. arr_is_valid s p (length xs) \\<and> \n           arr_list s p n = rev xs \\<rbrace>!\"\n  unfolding reverse'_def\n  apply (wp | clarsimp)+\n    apply (rule_tac\n      I= \"\\<lambda> i s. \n        wellbehaved_pointers p n \\<and>\n        n = length xs \\<and>\n        n < UINT_MAX \\<and>\n        n > 0 \\<and>\n        i < n \\<and>\n        n - i - 1 < n \\<and>\n        arr_is_valid s p (length xs) \\<and>\n        reverse_inv xs (arr_list s p n) i (length xs - i - 1) \n      \"\n      and M = \"\\<lambda> (i,_) . length xs - i\"\n      in whileLoop_add_invI)\n    apply (wp | clarsimp )+\n      apply (auto simp add: arr_list_heap_update_simps)[2]\n  using arr_is_valid_update_heap apply blast\n       apply (frule invariant_preservation) \n         apply simp+\n       apply (frule inv_impl_mid, subst heap_to_arr_list_lookup[where ?n = \"length xs\"], fastforce+) +\n       apply (simp add: nat_minus_as_int reverse_invariant_def(2)) \n     apply (simp add: pointer_add_simp)\n  using arr_is_validD apply auto[1]\n  using reverse.inv_impl_post apply auto[1]\n   apply (wp| clarsimp)\n  using reverse.pre_impl_inv(2) by fastforce\n\nend\n", "meta": {"author": "tecty", "repo": "COMP4161-Ass3", "sha": "da85f3f4d0bfcfb118913bd77a937e982f991351", "save_path": "github-repos/isabelle/tecty-COMP4161-Ass3", "path": "github-repos/isabelle/tecty-COMP4161-Ass3/COMP4161-Ass3-da85f3f4d0bfcfb118913bd77a937e982f991351/a3.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5156199157230156, "lm_q2_score": 0.5621765008857981, "lm_q1q2_score": 0.289869400008195}}
{"text": "section \\<open>Map Interface\\<close>\ntheory IICF_Map     \nimports \"../../Sepref\"\nbegin\n  \nsubsection \\<open>Parametricity for Maps\\<close>\ndefinition [to_relAPP]: \"map_rel K V \\<equiv> (K \\<rightarrow> \\<langle>V\\<rangle>option_rel)\n  \\<inter> { (mi,m). dom mi \\<subseteq> Domain K \\<and> dom m \\<subseteq> Range K }\"\n(*\ndefinition [to_relAPP]: \"map_rel K V \\<equiv> (K \\<rightarrow> \\<langle>V\\<rangle>option_rel)\n  \\<inter> { (mi,m). dom mi \\<subseteq> Domain K \\<and> dom m \\<subseteq> Range K \n      \\<and> ran mi \\<subseteq> Domain V \\<and> ran m \\<subseteq> Range V }\"\n*)\n\nlemma bi_total_map_rel_eq:\n  \"\\<lbrakk>IS_RIGHT_TOTAL K; IS_LEFT_TOTAL K\\<rbrakk> \\<Longrightarrow> \\<langle>K,V\\<rangle>map_rel = K \\<rightarrow> \\<langle>V\\<rangle>option_rel\"\n  unfolding map_rel_def IS_RIGHT_TOTAL_def IS_LEFT_TOTAL_def\n  by (auto dest: fun_relD)\n  \n\n\nlemma map_rel_empty1_simp[simp]: \n  \"(Map.empty,m)\\<in>\\<langle>K,V\\<rangle>map_rel \\<longleftrightarrow> m=Map.empty\"\n  apply (auto simp: map_rel_def)\n  by (meson RangeE domIff option_rel_simp(1) subsetCE tagged_fun_relD_none)\n\nlemma map_rel_empty2_simp[simp]: \n  \"(m,Map.empty)\\<in>\\<langle>K,V\\<rangle>map_rel \\<longleftrightarrow> m=Map.empty\"\n  apply (auto simp: map_rel_def)\n  by (meson Domain.cases domIff fun_relD2 option_rel_simp(2) subset_eq)\n\nlemma map_rel_obtain1:\n  assumes 1: \"(m,n)\\<in>\\<langle>K,V\\<rangle>map_rel\"\n  assumes 2: \"n l = Some w\"\n  obtains k v where \"m k = Some v\" \"(k,l)\\<in>K\" \"(v,w)\\<in>V\"\n  using 1 unfolding map_rel_def\nproof clarsimp\n  assume R: \"(m, n) \\<in> K \\<rightarrow> \\<langle>V\\<rangle>option_rel\"\n  assume \"dom n \\<subseteq> Range K\"\n  with 2 obtain k where \"(k,l)\\<in>K\" by auto\n  moreover from fun_relD[OF R this] have \"(m k, n l) \\<in> \\<langle>V\\<rangle>option_rel\" .\n  with 2 obtain v where \"m k = Some v\" \"(v,w)\\<in>V\" by (cases \"m k\"; auto)\n  ultimately show thesis by - (rule that)\nqed\n\nlemma map_rel_obtain2:\n  assumes 1: \"(m,n)\\<in>\\<langle>K,V\\<rangle>map_rel\"\n  assumes 2: \"m k = Some v\"\n  obtains l w where \"n l = Some w\" \"(k,l)\\<in>K\" \"(v,w)\\<in>V\"\n  using 1 unfolding map_rel_def\nproof clarsimp\n  assume R: \"(m, n) \\<in> K \\<rightarrow> \\<langle>V\\<rangle>option_rel\"\n  assume \"dom m \\<subseteq> Domain K\"\n  with 2 obtain l where \"(k,l)\\<in>K\" by auto\n  moreover from fun_relD[OF R this] have \"(m k, n l) \\<in> \\<langle>V\\<rangle>option_rel\" .\n  with 2 obtain w where \"n l = Some w\" \"(v,w)\\<in>V\" by (cases \"n l\"; auto)\n  ultimately show thesis by - (rule that)\nqed\n\n\n\nsubsection \\<open>Interface Type\\<close>\n\nsepref_decl_intf ('k,'v) i_map is \"'k \\<rightharpoonup> 'v\"\n\n\n\nsubsection \\<open>Operations\\<close>\n\n\ncontext\n  fixes t ::  \"unit \\<Rightarrow> nat\"\nbegin\n  definition \"mop_map_empty  = SPECT [ Map.empty \\<mapsto> t ()]\"\n\n  lemma  mop_map_empty: \"tt \\<le> lst (SPECT [ Map.empty \\<mapsto> t () ]) Q \n        \\<Longrightarrow> tt \\<le> lst (mop_map_empty ) Q\" unfolding mop_map_empty_def by simp\n\n  sepref_register \"mop_map_empty\" \nend\n\n\ncontext\n  fixes t ::  \"(( 'a \\<Rightarrow> 'b option) * 'a) * 'b \\<Rightarrow> nat\"\nbegin\n  definition \"mop_map_update m k v = SPECT [ m(k \\<mapsto> v) \\<mapsto> t ((m,k),v)]\"\n\n\n  lemma  mop_map_update: \"tt \\<le> lst (SPECT [ m(k \\<mapsto> v) \\<mapsto> t ((m,k),v)])  Q\n        \\<Longrightarrow> tt \\<le> lst (mop_map_update m k v) Q\" unfolding mop_map_update_def by simp\n\n  sepref_register \"mop_map_update\" \nend\n\n\ncontext\n  fixes t ::  \"('a \\<Rightarrow> 'b option) * 'a \\<Rightarrow> nat\"\nbegin\n  definition \"mop_map_dom_member m x = SPECT (emb (\\<lambda>b. b \\<longleftrightarrow> x\\<in>dom m) (t (m,x)))\"\n\n\n  lemma  mop_map_dom_member: \"tt \\<le> lst (SPECT (emb (\\<lambda>b. b \\<longleftrightarrow> x\\<in>dom m) (t (m,x))))  Q\n        \\<Longrightarrow> tt \\<le> lst (mop_map_dom_member m x) Q\" unfolding mop_map_dom_member_def by simp\n\n  sepref_register \"mop_map_dom_member\" \nend\n\ncontext\n  fixes t ::  \"('a \\<Rightarrow> 'b option) * 'a \\<Rightarrow> nat\"\nbegin\n  definition \"mop_map_lookup m x = do {\n        ASSERT (x\\<in>dom m);\n        SPECT [  (the (m x)) \\<mapsto> t (m,x)]\n      }\"\n\n\n  lemma  mop_map_lookup: \"tt \\<le> lst (SPECT [  (the (m x)) \\<mapsto> t (m,x)]) Q\n        \\<Longrightarrow> x : dom m \n        \\<Longrightarrow> tt \\<le> lst (mop_map_lookup m x) Q\" unfolding mop_map_lookup_def by simp\n\n  lemma progress_mop_map_lookup[progress_rules]: \"t (m,x) > 0 \\<Longrightarrow> progress (mop_map_lookup m x)\"\n      unfolding mop_map_lookup_def by (auto intro!: progress_rules simp add:   zero_enat_def) \n\n  sepref_register \"mop_map_lookup\"\nend\n\nend\n", "meta": {"author": "maxhaslbeck", "repo": "Sepreftime", "sha": "c1c987b45ec886d289ba215768182ac87b82f20d", "save_path": "github-repos/isabelle/maxhaslbeck-Sepreftime", "path": "github-repos/isabelle/maxhaslbeck-Sepreftime/Sepreftime-c1c987b45ec886d289ba215768182ac87b82f20d/Refine_Imperative_HOL/IICF/Intf/IICF_Map.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5888891451980403, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.2898442505212363}}
{"text": "(*  Title:       Conflict analysis/Flowgraphs\n    Author:      Peter Lammich <peter.lammich@uni-muenster.de>\n    Maintainer:  Peter Lammich <peter.lammich@uni-muenster.de>\n*)\nsection \"Flowgraphs\"\ntheory Flowgraph\nimports Main Misc\nbegin\ntext_raw \\<open>\\label{thy:Flowgraph}\\<close>\n\ntext \\<open>\n  We use a flowgraph-based program model that extends the one we used previously \\cite{LM07}. \n  A program is represented as an edge annotated graph and a set of procedures. The nodes of the graph are partitioned by the procedures, i.e. every node belongs to exactly one procedure. There are no edges\n  between nodes of different procedures. Every procedure has a distinguished entry and return node and a set of monitors it synchronizes on. Additionally, the program has a distinguished {\\em main} procedure.\n  The edges are annotated with statements. A statement is either a base statement, a procedure call or a thread creation (spawn). Procedure calls and thread creations refer to the called procedure or to the initial procedure\n  of the spawned thread, respectively.\n\n  We require that the main procedure and any initial procedure of a spawned thread does not to synchronize on any monitors. This avoids that spawning of a procedure together with entering a monitor is available in our \n  model as an atomic step, which would be an unrealistic assumption for practical problems. Technically, our model would become strictly more powerful without this assumption.\n\n\n  If we allowed this, our model would become strictly more powerful, \n\\<close>\n\nsubsection \"Definitions\"\n  \ndatatype ('p,'ba) edgeAnnot = Base 'ba | Call 'p | Spawn 'p\ntype_synonym ('n,'p,'ba) edge = \"('n \\<times> ('p,'ba) edgeAnnot \\<times> 'n)\"\n\nrecord ('n,'p,'ba,'m) flowgraph_rec =\n  edges :: \"('n,'p,'ba) edge set\" \\<comment> \\<open>Set of annotated edges\\<close>\n  main :: \"'p\" \\<comment> \\<open>Main procedure\\<close>\n  entry :: \"'p \\<Rightarrow> 'n\" \\<comment> \\<open>Maps a procedure to its entry point\\<close>\n  return :: \"'p \\<Rightarrow> 'n\" \\<comment> \\<open>Maps a procedure to its return point\\<close>\n  mon :: \"'p \\<Rightarrow> 'm set\" \\<comment> \\<open>Maps procedures to the set of monitors they allocate\\<close>\n  proc_of :: \"'n \\<Rightarrow> 'p\" \\<comment> \\<open>Maps a node to the procedure it is contained in\\<close>\n\ndefinition \n  \"initialproc fg p == p=main fg \\<or> (\\<exists>u v. (u,Spawn p,v)\\<in>edges fg)\"\n\nlemma main_is_initial[simp]: \"initialproc fg (main fg)\"\n  by (unfold initialproc_def) simp\n\nlocale flowgraph =\n  fixes fg :: \"('n,'p,'ba,'m,'more) flowgraph_rec_scheme\" (structure)\n  (* Type annotation unnecessary, but perhaps makes it more readable\n     for the unaware reader ;) *)\n  \\<comment> \\<open>Edges are inside procedures only\\<close>\n  assumes edges_part: \"(u,a,v)\\<in>edges fg \\<Longrightarrow> proc_of fg u = proc_of fg v\" \n  \\<comment> \\<open>The entry point of a procedure must be in that procedure\\<close>\n  assumes entry_valid[simp]: \"proc_of fg (entry fg p) = p\" \n  \\<comment> \\<open>The return point of a procedure must be in that procedure\\<close>\n  assumes return_valid[simp]: \"proc_of fg (return fg p) = p\" \n  \\<comment> \\<open>Initial procedures do not synchronize on any monitors\\<close>\n  assumes initial_no_mon[simp]: \"initialproc fg p \\<Longrightarrow> mon fg p = {}\" \n\nsubsection \"Basic properties\"\nlemma (in flowgraph) spawn_no_mon[simp]: \n  \"(u, Spawn p, v) \\<in> edges fg \\<Longrightarrow> mon fg p = {}\" \n  using initial_no_mon by (unfold initialproc_def, blast)\nlemma (in flowgraph) main_no_mon[simp]: \"mon fg (main fg) = {}\" \n  using initial_no_mon by (unfold initialproc_def, blast)\n\n\n\nlemma (in flowgraph) entry_entry_same_proc[simp]: \n  \"entry fg p = entry fg p' \\<Longrightarrow> p=p'\"\n  apply (subgoal_tac \"proc_of fg (entry fg p) = proc_of fg (entry fg p')\")\n  apply (simp (no_asm_use))\n  by simp\n\nlemma (in flowgraph) return_return_same_proc[simp]: \n  \"return fg p = return fg p' \\<Longrightarrow> p=p'\"\n  apply (subgoal_tac \"proc_of fg (return fg p) = proc_of fg (entry fg p')\")\n  apply (simp (no_asm_use))\n  by simp\n\nsubsection \"Extra assumptions for flowgraphs\"\ntext_raw \\<open>\\label{sec:Flowgraph:extra_asm}\\<close>\ntext \\<open>\n  In order to simplify the definition of our restricted schedules (cf. Section~\\ref{thy:Normalization}), we make some extra constraints on flowgraphs. \n  Note that these are no real restrictions, as we can always rewrite flowgraphs to match these constraints, preserving the set of conflicts. We leave it to future work to consider such a rewriting formally. \n\n  The background of this restrictions is that we want to start an execution of a thread with a procedure call that never returns. This will allow easier technical treatment in Section~\\ref{thy:Normalization}. Here we enforce this\n  semantic restrictions by syntactic properties of the flowgraph.\n\\<close>\n\ntext \\<open>The return node of a procedure is called {\\em isolated}, if it has no incoming edges and is different from the entry node. A procedure with an isolated return node will never return. \n  See Section~\\ref{sec:Normalization:eflowgraph} for a proof of this.\\<close>\ndefinition \n  \"isolated_ret fg p == \n    (\\<forall>u l. \\<not>(u,l,return fg p)\\<in>edges fg) \\<and> entry fg p \\<noteq> return fg p\"\n\ntext \\<open>The following syntactic restrictions guarantee that each thread's execution starts with a non-returning call. See Section~\\ref{sec:Normalization:eflowgraph} for a proof of this.\\<close>\nlocale eflowgraph = flowgraph +\n  \\<comment> \\<open>Initial procedure's entry node isn't equal to its return node\\<close>\n  assumes initial_no_ret: \"initialproc fg p \\<Longrightarrow> entry fg p \\<noteq> return fg p\" \n  \\<comment> \\<open>The only outgoing edges of initial procedures' entry nodes are call edges to procedures with isolated return node\\<close>\n  assumes initial_call_no_ret: \"\\<lbrakk>initialproc fg p; (entry fg p,l,v)\\<in>edges fg\\<rbrakk> \n    \\<Longrightarrow> \\<exists>p'. l=Call p' \\<and> isolated_ret fg p'\" \n\nsubsection \\<open>Example Flowgraph\\<close>\ntext_raw \\<open>\\label{sec:Flowgraph:ex_flowgraph}\\<close>\ntext \\<open>This section contains a check that there exists a (non-trivial) flowgraph, i.e. that the assumptions made in the \\<open>flowgraph\\<close> and \\<open>eflowgraph\\<close> \n  locales are consistent and have at least one non-trivial model.\\<close>\ndefinition \n  \"example_fg == \\<lparr> \n    edges = {((0::nat,0::nat),Call 1,(0,1)), ((1,0),Spawn 0,(1,0)), \n             ((1,0),Call 0, (1,0))}, \n    main = 0, \n    entry = \\<lambda>p. (p,0), \n    return = \\<lambda>p. (p,1), \n    mon = \\<lambda>p. if p=1 then {0} else {}, \n    proc_of= \\<lambda> (p,x). p \\<rparr>\"\n\nlemma exists_eflowgraph: \"eflowgraph example_fg\"\n  apply (unfold_locales)\n  apply (unfold example_fg_def)\n  apply simp\n  apply fast\n  apply simp\n  apply simp\n  apply (simp add: initialproc_def)\n  apply (simp add: initialproc_def)\n  apply (simp add: initialproc_def isolated_ret_def)\n  done\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Program-Conflict-Analysis/Flowgraph.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5888891307678321, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.28984424341885906}}
{"text": "theory LaunchburyMoreFree\nimports Terms Heap Launchbury\nbegin\n\ntext {*\nThis variant of the original semantics allocates an additional free variable in the application case.\nThis is a prelimary step towards the equivalence of the original and the stacked semantics.\n*}\n\ninductive\n  reds :: \"heap \\<Rightarrow> exp \\<Rightarrow> var list \\<Rightarrow> heap \\<Rightarrow> exp \\<Rightarrow> bool\"\n  (\"_ : _ \\<Down>*\\<^bsub>_\\<^esub> _ : _\" [50,50,50,50] 50)\nwhere\n  Lambda:\n    \"\\<Gamma> : (Lam [x]. e) \\<Down>*\\<^bsub>L\\<^esub> \\<Gamma> : (Lam [x]. e)\" \n | Application: \"\\<lbrakk>\n    atom y \\<sharp> (\\<Gamma>,e,x,L,\\<Delta>,\\<Theta>,z) ;\n    atom (n::var) \\<sharp> (\\<Gamma>,e,x,L,\\<Delta>,\\<Theta>,z) ;\n    n \\<noteq> y;\n    \\<Gamma> : e \\<Down>*\\<^bsub>n#x#L\\<^esub> \\<Delta> : (Lam [y]. e');\n    \\<Delta> : e'[y ::= x] \\<Down>*\\<^bsub>L\\<^esub> \\<Theta> : z\n  \\<rbrakk>  \\<Longrightarrow>\n    \\<Gamma> : App e x \\<Down>*\\<^bsub>L\\<^esub> \\<Theta> : z\" \n | Variable: \"\\<lbrakk>\n    (x,e) \\<in> set \\<Gamma>; delete x \\<Gamma> : e \\<Down>*\\<^bsub>x#L\\<^esub> \\<Delta> : z \\<rbrakk> \\<Longrightarrow> \\<Gamma> : Var x \\<Down>*\\<^bsub>L\\<^esub> (x, z) # \\<Delta> : z\"\n | Let: \"\\<lbrakk>\n    set (bn as) \\<sharp>* (\\<Gamma>, L);\n    asToHeap as @ \\<Gamma> : body \\<Down>*\\<^bsub>L\\<^esub> \\<Delta> : z\n  \\<rbrakk> \\<Longrightarrow>\n    \\<Gamma> : Let as body \\<Down>*\\<^bsub>L\\<^esub> \\<Delta> : z\"\n\nequivariance reds\n\nnominal_inductive reds\n  avoids Application: \"y\" and \"n\"\n    by(auto simp add: fresh_star_def fresh_Pair)\n\nlemma reds_less_free:\n  \"\\<Gamma> : e \\<Down>*\\<^bsub>L\\<^esub> \\<Delta> : z \\<Longrightarrow> \\<Gamma> : e \\<Down>\\<^bsub>L\\<^esub> \\<Delta> : z\"\nproof(induct rule: LaunchburyMoreFree.reds.induct)\ncase (Application y \\<Gamma> e x L \\<Delta> \\<Theta> z n e')\n  show ?case\n  proof(rule Launchbury.reds.Application)\n    show \"atom y \\<sharp> (\\<Gamma>, e, x, L, \\<Delta>, \\<Theta>, z)\"\n      by fact\n    show  \"\\<Gamma> : e \\<Down>\\<^bsub>x # L\\<^esub> \\<Delta> : Lam [y]. e'\"\n      apply (rule reds_smaller_L[OF Application.hyps(5)])\n      by auto\n    show \"\\<Delta> : e'[y::=x] \\<Down>\\<^bsub>L\\<^esub> \\<Theta> : z\"\n      by fact\n  qed\nqed (auto intro: reds_smaller_L Launchbury.reds.intros simp add: fresh_star_Pair)\n\n\nlemma reds_with_n_doesnt_forget:\n  \"\\<Gamma> : e \\<Down>*\\<^bsub>L\\<^esub> \\<Delta> : z \\<Longrightarrow> heapVars \\<Gamma> \\<subseteq> heapVars \\<Delta>\"\nby (metis reds_less_free reds_doesnt_forget)\n\nlemma reds_with_n_fresh:\" \\<lbrakk> \\<Gamma> : e \\<Down>*\\<^bsub>L\\<^esub> \\<Delta> : z;\n   atom (x::var) \\<sharp> (\\<Gamma>, e)\n  \\<rbrakk> \\<Longrightarrow> atom x \\<sharp> (\\<Delta>, z) \\<or> x \\<in> (heapVars \\<Delta> - set L)\"\n  by (metis reds_less_free reds_fresh)\n\nlemma reds_with_n_add_var_L: \"\\<lbrakk> \\<Gamma> : e \\<Down>*\\<^bsub>L\\<^esub> \\<Delta> : z;\n   atom (x::var) \\<sharp> (\\<Gamma>, e, \\<Delta>, z);\n   set L' = insert x (set L)\n  \\<rbrakk> \\<Longrightarrow> \\<Gamma> : e \\<Down>*\\<^bsub>L'\\<^esub> \\<Delta> : z\"\nproof(nominal_induct avoiding : L' rule: reds.strong_induct)\ncase (Lambda \\<Gamma> x e L L')\n  show ?case\n    by (rule reds.Lambda)\nnext\ncase (Application y \\<Gamma> e xa L \\<Delta> \\<Theta> z n e' L')\n  show ?case\n  proof(rule reds.Application)\n    show \"atom y \\<sharp> (\\<Gamma>, e, xa, L', \\<Delta>, \\<Theta>, z)\"\n      using Application\n      by (auto simp add: fresh_Pair)\n  \n    show \"atom n \\<sharp> (\\<Gamma>, e, xa, L', \\<Delta>, \\<Theta>, z)\"\n      using Application\n      by (auto simp add: fresh_Pair)\n\n    show \"n \\<noteq> y\" by fact\n\n    have \"x \\<notin> heapVars \\<Theta>\"\n      using `atom x \\<sharp> (\\<Gamma>, App e xa, \\<Theta>, z)`\n      apply (simp add: fresh_Pair)\n      by (metis heapVars_not_fresh)\n    hence \"x \\<notin> heapVars \\<Delta>\"\n      by (metis set_mp reds_with_n_doesnt_forget[OF Application.hyps(20)])\n\n    have \"atom x \\<sharp> (\\<Gamma>, e)\"\n      using `atom x \\<sharp> (\\<Gamma>, App e xa, \\<Theta>, z)`\n      by (simp add: fresh_Pair)\n    from reds_with_n_fresh[OF Application.hyps(18) this] `x \\<notin> heapVars \\<Delta>`\n    have \"atom x \\<sharp> (\\<Delta>, Lam [y]. e')\"\n      by auto\n    hence \"atom x \\<sharp> (\\<Gamma>, e, \\<Delta>, Lam [y]. e')\"\n      using `atom x \\<sharp> (\\<Gamma>, App e xa, \\<Theta>, z)`\n      by (simp add: fresh_Pair)\n    moreover\n    have \"set (n # xa # L') = insert x (set (n # xa # L))\"\n      using `set L' = _` by auto\n    ultimately\n    show \"\\<Gamma> : e \\<Down>*\\<^bsub>n # xa # L'\\<^esub> \\<Delta> : Lam [y]. e'\"\n      by (rule Application.hyps(19))\n\n    have \"atom x \\<sharp> (\\<Delta>, e'[y::=xa])\"\n      using `atom x \\<sharp> (\\<Delta>, Lam [y]. e')` `atom x \\<sharp> (\\<Gamma>, App e xa, \\<Theta>, z)` `atom y \\<sharp> xa`\n      by (auto simp add: fresh_Pair  subst_pres_fresh)\n    from reds_with_n_fresh[OF Application.hyps(20) this] `x \\<notin> heapVars \\<Theta>`\n    have \"atom x \\<sharp> (\\<Theta>, z)\" by auto\n    hence \"atom x \\<sharp> (\\<Delta>, e'[y::=xa], \\<Theta>, z)\"\n      using `atom x \\<sharp> (\\<Delta>, e'[y::=xa])`\n      by (simp add: fresh_Pair)\n    then\n    show \"\\<Delta> : e'[y::=xa] \\<Down>*\\<^bsub>L'\\<^esub> \\<Theta> : z \"\n      by (rule Application.hyps(21)[OF _ `set L' = _`])\n  qed\nnext \ncase (Variable xa e \\<Gamma> L \\<Delta> z L')\n  have \"atom x \\<sharp> (delete xa \\<Gamma>, e, \\<Delta>, z)\"\n    using Variable.prems(1)\n    by (auto simp add: fresh_Pair fresh_Cons intro: fresh_delete fresh_heap_expr[OF _ Variable(1)])\n  moreover\n  have \"set (xa # L') = insert x (set (xa # L))\"\n    using Variable.prems(2) by auto\n  ultimately\n  show ?case\n    by (rule reds.Variable[OF Variable(1) Variable.hyps(3)])\nnext\ncase (Let as \\<Gamma> L body \\<Delta> z L')\n  have \"x \\<notin> heapVars \\<Delta>\"\n    using Let.prems(1)\n    apply (auto simp add: fresh_Pair)\n    by (metis heapVars_not_fresh)+\n  hence \"x \\<notin> heapVars (asToHeap as @ \\<Gamma>)\"\n      by (metis set_mp reds_with_n_doesnt_forget[OF Let.hyps(3)])\n  hence \"atom x \\<notin> set (bn as)\"\n    by (auto simp add: set_bn_to_atom_heapVars)\n  hence \"set (bn as) \\<sharp>* x\"\n    by (auto simp add: fresh_star_def fresh_at_base)\n    \n  hence \"set (bn as) \\<sharp>* set L'\"\n    using Let(2) Let.prems(2)\n    by (auto simp add: fresh_star_def fresh_finite_insert fresh_set)\n  hence \"set (bn as) \\<sharp>* (\\<Gamma>, L')\" \n    using Let(1-4)\n    by (simp add: fresh_star_Pair fresh_star_set )\n  moreover\n  have \"atom x \\<sharp> (asToHeap as @ \\<Gamma>, body, \\<Delta>, z)\"\n    using Let.prems(1) `atom x \\<notin> set (bn as)`\n    by (auto simp add: fresh_Pair fresh_append fresh_fun_eqvt_app[OF asToHeap_eqvt])\n  ultimately\n  show ?case\n    by (rule reds.Let[OF _ Let.hyps(4)[OF _ Let.prems(2)]])\nqed\n\nlemma reds_more_free:\n  \"\\<Gamma> : e \\<Down>\\<^bsub>L\\<^esub> \\<Delta> : z \\<Longrightarrow> \\<Gamma> : e \\<Down>*\\<^bsub>L\\<^esub> \\<Delta> : z\"\nproof(nominal_induct rule: Launchbury.reds.strong_induct)\ncase (Application y \\<Gamma> e x L \\<Delta> \\<Theta> z e')\n  obtain n :: var where\n    fresh: \"atom n \\<sharp> (\\<Gamma>, e, x, L, \\<Delta>, \\<Theta>, z, y, Lam [y]. e')\" \n    by (rule obtain_fresh)\n\n  show ?case\n  proof (rule reds.Application)\n    show \"atom y \\<sharp> (\\<Gamma>, e, x, L, \\<Delta>, \\<Theta>, z)\"\n      using Application\n      by (auto simp add: fresh_Pair)\n    show \"atom n \\<sharp> (\\<Gamma>, e, x, L, \\<Delta>, \\<Theta>, z)\"\n      using fresh\n      by (auto simp add: fresh_Pair)\n   show \"n \\<noteq> y\"\n      using fresh\n      by (auto simp add: fresh_Pair fresh_at_base)\n\n    note `\\<Gamma> : e \\<Down>*\\<^bsub>x # L\\<^esub> \\<Delta> : Lam [y]. e'`\n    moreover\n    have \"atom n \\<sharp> (\\<Gamma>, e, \\<Delta>, Lam [y]. e')\"\n      using fresh by (auto simp add: fresh_Pair)\n    ultimately\n    show \"\\<Gamma> : e \\<Down>*\\<^bsub>n # x # L\\<^esub> \\<Delta> : Lam [y]. e'\"\n      by (rule reds_with_n_add_var_L, simp)\n\n    show \"\\<Delta> : e'[y::=x] \\<Down>*\\<^bsub>L\\<^esub> \\<Theta> : z\"\n      by fact\n  qed\nqed (auto intro: reds.intros simp add: fresh_star_Pair)\n\nlemma reds_more_free_eq:\n  \"(\\<Gamma> : e \\<Down>*\\<^bsub>L\\<^esub> \\<Delta> : z) \\<longleftrightarrow> (\\<Gamma> : e \\<Down>\\<^bsub>L\\<^esub> \\<Delta> : z)\"\n  by (metis reds_less_free reds_more_free)\n\nlemmas reds_with_n_strong_induct = LaunchburyMoreFree.reds.strong_induct[unfolded reds_more_free_eq, consumes 1, case_names Lambda Application Variable Let]\nlemmas reds_with_n_induct = LaunchburyMoreFree.reds.induct[unfolded reds_more_free_eq, consumes 1, case_names Lambda Application Variable Let]\n\n(* This can be shown for reds directly, but we needed it here, and after we got the equality we can transfer it easily. *)\nlemmas reds_add_var_L = reds_with_n_add_var_L[unfolded reds_more_free_eq]\n\nend\n", "meta": {"author": "nomeata", "repo": "isa-launchbury", "sha": "2caa8d7d588e218aef1c49f2f327597af06d116e", "save_path": "github-repos/isabelle/nomeata-isa-launchbury", "path": "github-repos/isabelle/nomeata-isa-launchbury/isa-launchbury-2caa8d7d588e218aef1c49f2f327597af06d116e/Scratchpad/LaunchburyMoreFree.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.4921881357207956, "lm_q1q2_score": 0.28984424341885906}}
{"text": "section {*I\\_epda\\_lemmas*}\ntheory\n  I_epda_lemmas\n\nimports\n  I_epda_main\n\nbegin\n\nlemma epda_read_in_epda_events: \"\n  valid_epda M\n  \\<Longrightarrow> e \\<in> epda_delta M\n  \\<Longrightarrow> Some a = edge_event e\n  \\<Longrightarrow> a \\<in> epda_events M\"\n  apply(simp add: valid_epda_def)\n  apply(clarsimp)\n  apply(erule_tac\n      x = \"e\"\n      in ballE)\n   apply(auto)\n  apply(simp add: valid_epda_step_label_def)\n  apply(erule conjE)+\n  apply(simp add: option_to_set_def)\n  apply(force)\n  done\n\nlemma valid_epda_initial_in_states: \"\n  valid_epda M\n  \\<Longrightarrow> epda_initial M \\<in> epda_states M\"\n  apply(simp add: valid_epda_def)\n  done\n\nlemma valid_epda_box_in_gamma: \"\n  valid_epda G\n  \\<Longrightarrow> epda_box G \\<in> epda_gamma G\"\n  apply(simp add: valid_epda_def)\n  done\n\ndefinition valid_pda :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"valid_pda G \\<equiv>\n  valid_epda G\n  \\<and> (\\<forall>e \\<in> epda_delta G. length (edge_pop e) = 1)\"\n\ndefinition valid_dpda :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"valid_dpda G \\<equiv>\n  valid_pda G\n  \\<and> epdaS.is_forward_edge_deterministic_accessible G\"\n\ndefinition empty_push_edge :: \"\n  ('state, 'event, 'stack) epda_step_label\n  \\<Rightarrow> bool\"\n  where\n    \"empty_push_edge e \\<equiv>\n  edge_push e = []\"\n\ndefinition strict_empty_push_edge :: \"\n  ('state, 'event, 'stack) epda_step_label\n  \\<Rightarrow> bool\"\n  where\n    \"strict_empty_push_edge e \\<equiv>\n  edge_push e = []\n  \\<and> edge_event e = None\"\n\ndefinition multiple_push_edge :: \"\n  ('state, 'event, 'stack) epda_step_label\n  \\<Rightarrow> bool\"\n  where\n    \"multiple_push_edge e \\<equiv>\n  length (edge_push e) > Suc 0\"\n\ndefinition strict_multiple_push_edge :: \"\n  ('state, 'event, 'stack) epda_step_label\n  \\<Rightarrow> bool\"\n  where\n    \"strict_multiple_push_edge e \\<equiv>\n  suffix (edge_push e) (edge_pop e)\n  \\<and> edge_event e = None\"\n\ndefinition pop_edges_seperated :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"pop_edges_seperated G \\<equiv>\n  \\<forall>e \\<in> epda_delta G.\n  empty_push_edge e\n  \\<longrightarrow> strict_empty_push_edge e\"\n\ndefinition pop_edges_seperated_ALT :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"pop_edges_seperated_ALT G \\<equiv>\n  \\<forall>e \\<in> epda_delta G.\n    edge_push e = [] \\<longrightarrow> edge_event e = None\"\n\nlemma pop_edges_seperated_ALT_vs_pop_edges_seperated: \"\n  pop_edges_seperated_ALT G = pop_edges_seperated G\"\n  apply(simp add: pop_edges_seperated_ALT_def pop_edges_seperated_def empty_push_edge_def strict_empty_push_edge_def)\n  done\n\ndefinition push_edges_seperated :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"push_edges_seperated G \\<equiv>\n  \\<forall>e \\<in> epda_delta G.\n  multiple_push_edge e\n  \\<longrightarrow> strict_multiple_push_edge e\"\n\ndefinition push_edges_seperated_ALT :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"push_edges_seperated_ALT G \\<equiv>\n  \\<forall>e \\<in> epda_delta G.\n  length (edge_push e) > Suc 0\n  \\<longrightarrow> (suffix (edge_push e) (edge_pop e) \\<and> edge_event e = None)\"\n\nlemma push_edges_seperated_ALT_vs_push_edges_seperated: \"\n  push_edges_seperated_ALT G = push_edges_seperated G\"\n  apply(simp add: multiple_push_edge_def strict_multiple_push_edge_def push_edges_seperated_ALT_def push_edges_seperated_def)\n  done\n\ndefinition valid_simple_dpda :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"valid_simple_dpda G \\<equiv>\n  valid_dpda G\n  \\<and> (\\<forall>e \\<in> epda_delta G.\n      case edge_event e of\n      Some a \\<Rightarrow>\n          edge_pop e = edge_push e\n      | None \\<Rightarrow>\n          edge_push e = []\n          \\<or> (\\<exists>w. edge_push e = w # edge_pop e))\"\n\ndefinition valid_dfa :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"valid_dfa G \\<equiv>\n  valid_dpda G\n  \\<and> (\\<forall>e \\<in> epda_delta G.\n      edge_event e \\<noteq> None\n      \\<and> edge_pop e = [epda_box G]\n      \\<and> edge_push e = [epda_box G])\"\n\n(*prevention can occur due to stacks; designed for DFA only*)\ndefinition some_step_from_every_configuration :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"some_step_from_every_configuration G \\<equiv>\n  \\<forall>q \\<in> epda_states G.\n  \\<forall>A \\<in> epda_events G.\n  \\<exists>e \\<in> epda_delta G.\n    edge_src e = q\n    \\<and> edge_event e = Some A\"\n\ndefinition epdaS_accessible_states :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> 'state set\"\n  where\n    \"epdaS_accessible_states G \\<equiv>\n  {q \\<in> epda_states G.\n    \\<exists>d n.\n    epdaS.derivation G d\n    \\<and> (case get_configuration (d n) of\n        None \\<Rightarrow> False\n        | Some c \\<Rightarrow> epdaS_conf_state c = q)\n    \\<and> (case get_configuration (d 0) of\n        None \\<Rightarrow> False\n        | Some c \\<Rightarrow> c \\<in> epdaS_initial_configurations G)}\"\n\ndefinition n_step_epdaS_accessible_states :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> nat\n  \\<Rightarrow> 'state set\"\n  where\n    \"n_step_epdaS_accessible_states G n \\<equiv>\n  {q. \\<exists>d c.\n      epdaS.derivation_initial G d\n      \\<and> get_configuration (d n) = Some c\n      \\<and> epdaS_conf_state c = q}\"\n\ndefinition at_most_n_epdaS_accessible_states :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> nat\n  \\<Rightarrow> 'state set\"\n  where\n    \"at_most_n_epdaS_accessible_states G n \\<equiv>\n  {q. \\<exists>d c k.\n      k \\<le> n\n      \\<and> epdaS.derivation_initial G d\n      \\<and> get_configuration (d k) = Some c\n      \\<and> epdaS_conf_state c = q}\"\n\ndefinition all_states_accessible :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"all_states_accessible G \\<equiv>\n  epda_states G \\<subseteq> epdaS_accessible_states G\"\n\ndefinition epdaS_accessible_edges :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda_step_label set\"\n  where\n    \"epdaS_accessible_edges G \\<equiv>\n  {e \\<in> epda_delta G.\n  \\<exists>d n c.\n  epdaS.derivation_initial G d\n  \\<and> d n = Some (pair (Some e) c)}\"\n\ndefinition all_edges_accessible :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"all_edges_accessible G \\<equiv>\n  epda_delta G \\<subseteq> epdaS_accessible_edges G\"\n\ndefinition accessible :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"accessible G \\<equiv>\n  all_states_accessible G\n  \\<and> all_edges_accessible G\"\n\nlemma valid_epda_accessible_implies_accessible: \"\n  valid_epda G\n  \\<Longrightarrow> accessible G\n  \\<Longrightarrow> epdaS.accessible G\"\n  apply(simp add: epdaS.accessible_def accessible_def all_states_accessible_def all_edges_accessible_def epda_destinations_def epdaS.get_accessible_destinations_def)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(rename_tac xa)(*strict*)\n   apply(thin_tac \"epda_delta G \\<subseteq> epdaS_accessible_edges G\")\n   apply(subgoal_tac \"xa \\<in> epdaS_accessible_states G\")\n    apply(rename_tac xa)(*strict*)\n    apply(thin_tac \"epda_states G \\<subseteq> epdaS_accessible_states G\")\n    apply(simp add: epdaS_accessible_states_def)\n    apply(clarsimp)\n    apply(rename_tac xa d n)(*strict*)\n    apply(rule_tac\n      x = \"d\"\n      in exI)\n    apply(simp add: get_configuration_def)\n    apply(subgoal_tac \"\\<exists>c. d 0 = Some (pair None c)\")\n     apply(rename_tac xa d n)(*strict*)\n     apply(subgoal_tac \"\\<exists>e c. d n = Some (pair e c)\")\n      apply(rename_tac xa d n)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac d n c e ca)(*strict*)\n      apply(rule conjI)\n       apply(rename_tac d n c e ca)(*strict*)\n       apply(simp add: epdaS.derivation_initial_def)\n      apply(rename_tac d n c e ca)(*strict*)\n      apply(rule_tac\n      x = \"n\"\n      in exI)\n      apply(rule_tac\n      x = \"e\"\n      in exI)\n      apply(rule_tac\n      x = \"ca\"\n      in exI)\n      apply(clarsimp)\n      apply(simp add: epdaS_get_destinations_def)\n     apply(rename_tac xa d n)(*strict*)\n     apply(case_tac \"d n\")\n      apply(rename_tac xa d n)(*strict*)\n      apply(force)\n     apply(rename_tac xa d n a)(*strict*)\n     apply(subgoal_tac \"\\<exists>e c. d n = Some (pair e c)\")\n      apply(rename_tac xa d n a)(*strict*)\n      prefer 2\n      apply(rule_tac\n      m = \"n\"\n      in epdaS.pre_some_position_is_some_position)\n        apply(rename_tac xa d n a)(*strict*)\n        apply(force)\n       apply(rename_tac xa d n a)(*strict*)\n       apply(force)\n      apply(rename_tac xa d n a)(*strict*)\n      apply(force)\n     apply(rename_tac xa d n a)(*strict*)\n     apply(force)\n    apply(rename_tac xa d n)(*strict*)\n    apply (metis epdaS.some_position_has_details_at_0)\n   apply(rename_tac xa)(*strict*)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac xa)(*strict*)\n  apply(thin_tac \"epda_states G \\<subseteq> epdaS_accessible_states G\")\n  apply(subgoal_tac \"xa \\<in> epdaS_accessible_edges G\")\n   apply(rename_tac xa)(*strict*)\n   apply(thin_tac \"epda_delta G \\<subseteq> epdaS_accessible_edges G\")\n   apply(simp add: epdaS_accessible_edges_def)\n   apply(clarsimp)\n   apply(rename_tac xa d n c)(*strict*)\n   apply(rule_tac\n      x = \"d\"\n      in exI)\n   apply(simp add: get_configuration_def)\n   apply(rule_tac\n      x = \"n\"\n      in exI)\n   apply(rule_tac\n      x = \"Some xa\"\n      in exI)\n   apply(rule_tac\n      x = \"c\"\n      in exI)\n   apply(clarsimp)\n   apply(simp add: epdaS_get_destinations_def)\n  apply(rename_tac xa)(*strict*)\n  apply(force)\n  done\n\nlemma at_most_n_epdaS_accessible_states_by_n_step_epdaS_accessible_states: \"\n  at_most_n_epdaS_accessible_states G n = \\<Union>{n_step_epdaS_accessible_states G k | k. k\\<le>n}\"\n  apply(rule order_antisym)\n   apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   apply(simp add: at_most_n_epdaS_accessible_states_def)\n   apply(clarsimp)\n   apply(rename_tac d c k)(*strict*)\n   apply(rule_tac\n      x = \"n_step_epdaS_accessible_states G k\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac d c k)(*strict*)\n    apply(rule_tac\n      x = \"k\"\n      in exI)\n    apply(clarsimp)\n   apply(rename_tac d c k)(*strict*)\n   apply(simp add: n_step_epdaS_accessible_states_def)\n   apply(rule_tac\n      x = \"d\"\n      in exI)\n   apply(clarsimp)\n  apply(clarsimp)\n  apply(rename_tac x k)(*strict*)\n  apply(simp add: n_step_epdaS_accessible_states_def at_most_n_epdaS_accessible_states_def)\n  apply(clarsimp)\n  apply(rename_tac k d c)(*strict*)\n  apply(rule_tac\n      x = \"d\"\n      in exI)\n  apply(clarsimp)\n  apply(rule_tac\n      x = \"c\"\n      in exI)\n  apply(clarsimp)\n  apply(rule_tac\n      x = \"k\"\n      in exI)\n  apply(clarsimp)\n  done\n\nlemma epdaS_accessible_states_by_n_step_epdaS_accessible_states: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS_accessible_states G = \\<Union>{n_step_epdaS_accessible_states G k | k. True}\"\n  apply(rule order_antisym)\n   apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   apply(simp add: n_step_epdaS_accessible_states_def)\n   apply(simp add: epdaS_accessible_states_def)\n   apply(clarsimp)\n   apply(rename_tac x d n)(*strict*)\n   apply(subgoal_tac \"\\<exists>c. d 0 = Some (pair None c)\")\n    apply(rename_tac x d n)(*strict*)\n    prefer 2\n    apply (metis epdaS.some_position_has_details_at_0)\n   apply(rename_tac x d n)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x d n c)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(case_tac \"d n\")\n    apply(rename_tac x d n c)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac x d n c a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac x d n c a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d n c option b)(*strict*)\n   apply(rule_tac\n      x = \"n_step_epdaS_accessible_states G n\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac d n c option b)(*strict*)\n    apply(rule_tac\n      x = \"n\"\n      in exI)\n    apply(rule order_antisym)\n     apply(rename_tac d n c option b)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac d n c option b x)(*strict*)\n     apply(simp add: n_step_epdaS_accessible_states_def)\n     apply(clarsimp)\n     apply(rename_tac d n c option b da ca)(*strict*)\n     apply(rule_tac\n      x = \"da\"\n      in exI)\n     apply(clarsimp)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac d n c option b)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d n c option b da ca)(*strict*)\n    apply(simp add: n_step_epdaS_accessible_states_def)\n    apply(rule_tac\n      x = \"da\"\n      in exI)\n    apply(clarsimp)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac d n c option b)(*strict*)\n   apply(simp add: n_step_epdaS_accessible_states_def)\n   apply(rule_tac\n      x = \"d\"\n      in exI)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n   apply(simp add: epdaS.derivation_initial_def)\n  apply(clarsimp)\n  apply(rename_tac x k)(*strict*)\n  apply(simp add: n_step_epdaS_accessible_states_def epdaS_accessible_states_def)\n  apply(clarsimp)\n  apply(rename_tac k d c)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac k d c)(*strict*)\n   apply(subgoal_tac \"c \\<in> epdaS_configurations G\")\n    apply(rename_tac k d c)(*strict*)\n    apply(simp add: epdaS_configurations_def)\n    apply(clarsimp)\n   apply(rename_tac k d c)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(case_tac \"d k\")\n    apply(rename_tac k d c)(*strict*)\n    apply(force)\n   apply(rename_tac k d c a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"a\")\n   apply(rename_tac k d c a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac k d c option)(*strict*)\n   apply(rule epdaS.belongs_configurations)\n    apply(rename_tac k d c option)(*strict*)\n    apply(rule epdaS.derivation_initial_belongs)\n     apply(rename_tac k d c option)(*strict*)\n     apply(force)\n    apply(rename_tac k d c option)(*strict*)\n    apply(force)\n   apply(rename_tac k d c option)(*strict*)\n   apply(force)\n  apply(rename_tac k d c)(*strict*)\n  apply(rule_tac\n      x = \"d\"\n      in exI)\n  apply(simp add: get_configuration_def)\n  apply(rule conjI)\n   apply(rename_tac k d c)(*strict*)\n   apply(rule epdaS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac k d c)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac k d c)(*strict*)\n   apply(rule_tac\n      x = \"k\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac k d c)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. d 0 = Some (pair None c)\")\n   apply(rename_tac k d c)(*strict*)\n   prefer 2\n   apply(rule epdaS.some_position_has_details_at_0)\n   apply(rule epdaS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac k d c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k d c ca)(*strict*)\n  apply(simp add: epdaS.derivation_initial_def)\n  done\n\nlemma n_step_epdaS_accessible_states_are_states: \"\n  valid_epda G\n  \\<Longrightarrow> n_step_epdaS_accessible_states G n \\<subseteq> epda_states G\"\n  apply(simp add: n_step_epdaS_accessible_states_def)\n  apply(clarsimp)\n  apply(rename_tac d c)(*strict*)\n  apply(subgoal_tac \"c \\<in> epdaS_configurations G\")\n   apply(rename_tac d c)(*strict*)\n   apply(simp add: epdaS_configurations_def)\n   apply(clarsimp)\n  apply(rename_tac d c)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(case_tac \"d n\")\n   apply(rename_tac d c)(*strict*)\n   apply(force)\n  apply(rename_tac d c a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"a\")\n  apply(rename_tac d c a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d c option)(*strict*)\n  apply(rule epdaS.belongs_configurations)\n   apply(rename_tac d c option)(*strict*)\n   apply(rule epdaS.derivation_initial_belongs)\n    apply(rename_tac d c option)(*strict*)\n    apply(force)\n   apply(rename_tac d c option)(*strict*)\n   apply(force)\n  apply(rename_tac d c option)(*strict*)\n  apply(force)\n  done\n\nlemma at_most_n_epdaS_accessible_states_are_states: \"\n  valid_epda G\n  \\<Longrightarrow> at_most_n_epdaS_accessible_states G n \\<subseteq> epda_states G\"\n  apply(simp add: at_most_n_epdaS_accessible_states_def)\n  apply(clarsimp)\n  apply(rename_tac d c k)(*strict*)\n  apply(subgoal_tac \"c \\<in> epdaS_configurations G\")\n   apply(rename_tac d c k)(*strict*)\n   apply(simp add: epdaS_configurations_def)\n   apply(clarsimp)\n  apply(rename_tac d c k)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(case_tac \"d k\")\n   apply(rename_tac d c k)(*strict*)\n   apply(force)\n  apply(rename_tac d c k a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"a\")\n  apply(rename_tac d c k a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d c k option)(*strict*)\n  apply(rule epdaS.belongs_configurations)\n   apply(rename_tac d c k option)(*strict*)\n   apply(rule epdaS.derivation_initial_belongs)\n    apply(rename_tac d c k option)(*strict*)\n    apply(force)\n   apply(rename_tac d c k option)(*strict*)\n   apply(force)\n  apply(rename_tac d c k option)(*strict*)\n  apply(force)\n  done\n\nlemma derivation_stays_in_states: \"\n  valid_epda M\n  \\<Longrightarrow> set w \\<subseteq> epda_events M\n  \\<Longrightarrow> set s \\<subseteq> epda_gamma M\n  \\<Longrightarrow> set h1 \\<subseteq> epda_events M\n  \\<Longrightarrow> epdaS.derivation M d\n  \\<Longrightarrow> d 0 = Some (pair None \\<lparr>epdaS_conf_state = q, epdaS_conf_scheduler = w, epdaS_conf_stack = s\\<rparr>)\n  \\<Longrightarrow> q \\<in> epda_states M\n  \\<Longrightarrow> d i = Some (pair e1 \\<lparr>epdaS_conf_state = qi, epdaS_conf_scheduler = wi, epdaS_conf_stack = si\\<rparr>)\n  \\<Longrightarrow> qi\\<in> epda_states M\"\n  apply(subgoal_tac \"\\<lparr>epdaS_conf_state = qi, epdaS_conf_scheduler = wi, epdaS_conf_stack = si\\<rparr> \\<in> epdaS_configurations M\")\n   prefer 2\n   apply(rule epdaS.stays_in_configuration)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(simp add: epdaS_configurations_def)\n    apply(force)\n   apply(force)\n  apply(simp add: epdaS_configurations_def)\n  done\n\nlemma epda_is_is_forward_target_deterministic_accessible: \"\n  valid_epda M\n  \\<Longrightarrow> epdaS.is_forward_target_deterministic_accessible M\"\n  apply(simp add: epdaS.is_forward_target_deterministic_accessible_def)\n  apply(auto)\n  apply(rename_tac c c1 c2 e)(*strict*)\n  apply(simp add: epdaS_step_relation_def)\n  apply(auto)\n  done\n\nlemma epda_is_is_forward_target_deterministic: \"\n  valid_epda M\n  \\<Longrightarrow> epdaS.is_forward_target_deterministic M\"\n  apply(simp add: epdaS.is_forward_target_deterministic_def)\n  apply(auto)\n  apply(rename_tac c c1 c2 e)(*strict*)\n  apply(simp add: epdaS_step_relation_def)\n  apply(auto)\n  done\n\nlemma epda_is_backward_target_deterministic: \"\n  valid_epda M\n  \\<Longrightarrow> epdaS.is_backward_target_deterministic M\"\n  apply(simp add: epdaS.is_backward_target_deterministic_def)\n  apply(auto)\n  apply(rename_tac c c1 c2 e)(*strict*)\n  apply(unfold epdaS_step_relation_def)\n  apply(force)\n  done\n\nlemma DFA_derivation_drops_stepwise: \"\n  valid_dfa M\n  \\<Longrightarrow> epdaS.derivation M d\n  \\<Longrightarrow> maximum_of_domain d m\n  \\<Longrightarrow> n\\<le>m\n  \\<Longrightarrow> d 0 = Some (pair None c1)\n  \\<Longrightarrow> d n = Some (pair e c2)\n  \\<Longrightarrow> (epdaS_conf_scheduler c2 = drop n (epdaS_conf_scheduler c1))\n  \\<and> (length (epdaS_conf_scheduler c1) = n + (length (epdaS_conf_scheduler c2)))\"\n  apply(subgoal_tac \"\\<forall>d c1 e c2 m. epdaS.derivation M d \\<and> maximum_of_domain d m \\<and> n\\<le>m \\<and> d 0 = Some (pair None c1) \\<and> d n = Some (pair e c2) \\<longrightarrow> ((epdaS_conf_scheduler c2 = drop n (epdaS_conf_scheduler c1)) \\<and>(length (epdaS_conf_scheduler c1) = n + (length (epdaS_conf_scheduler c2))))\")\n   apply(force)\n  apply(thin_tac \"epdaS.derivation M d\")\n  apply(thin_tac \"maximum_of_domain d m\")\n  apply(thin_tac \"n\\<le>m\")\n  apply(thin_tac \"d 0 = Some (pair None c1)\")\n  apply(thin_tac \"d n = Some (pair e c2)\")\n  apply(induct n)\n   apply(clarsimp)\n  apply(rename_tac n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n d c1 e c2 m)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d n = Some (pair e c)\")\n   apply(rename_tac n d c1 e c2 m)(*strict*)\n   prefer 2\n   apply(rule epdaS.some_position_has_details_before_max_dom)\n     apply(rename_tac n d c1 e c2 m)(*strict*)\n     apply(blast)\n    apply(rename_tac n d c1 e c2 m)(*strict*)\n    apply(blast)\n   apply(rename_tac n d c1 e c2 m)(*strict*)\n   apply(arith)\n  apply(rename_tac n d c1 e c2 m)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac n d c1 e c2 m ea c)(*strict*)\n  apply(erule_tac\n      x = \"derivation_take d n\"\n      in allE)\n  apply(erule_tac\n      x = \"c1\"\n      in allE)\n  apply(erule_tac\n      x = \"ea\"\n      in allE)\n  apply(erule_tac\n      x = \"c\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac n d c1 e c2 m ea c)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac n d c1 e c2 m ea c)(*strict*)\n    apply(rule_tac epdaS.derivation_take_preserves_derivation)\n    apply(blast)\n   apply(rename_tac n d c1 e c2 m ea c)(*strict*)\n   apply(rule_tac\n      x = \"n\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac n d c1 e c2 m ea c)(*strict*)\n    apply(rule_tac\n      m = \"m-n\"\n      in epdaS.derivation_take_preserves_generates_maximum_of_domain)\n     apply(rename_tac n d c1 e c2 m ea c)(*strict*)\n     apply(blast)\n    apply(rename_tac n d c1 e c2 m ea c)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac n d c1 e c2 m ea c)(*strict*)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac n d c1 e c2 m ea c)(*strict*)\n  apply(erule conjE)+\n  apply(rename_tac n d c1 e c2 m ea c)(*strict*)\n  apply(subgoal_tac \"\\<exists>e'. e = Some e'\")\n   apply(rename_tac n d c1 e c2 m ea c)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"\\<exists>e c. d (Suc n) = Some (pair (Some e) c)\")\n    apply(rename_tac n d c1 e c2 m ea c)(*strict*)\n    prefer 2\n    apply(rule epdaS.some_position_has_details_before_max_dom_after_0)\n      apply(rename_tac n d c1 e c2 m ea c)(*strict*)\n      apply(blast)+\n   apply(rename_tac n d c1 e c2 m ea c)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac n d c1 e c2 m ea c)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac n d c1 e c2 m ea c e')(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n d c1 c2 m ea c e')(*strict*)\n  apply(subgoal_tac \"epdaS_step_relation M c e' c2\")\n   apply(rename_tac n d c1 c2 m ea c e')(*strict*)\n   prefer 2\n   apply(rule epdaS.position_change_due_to_step_relation)\n     apply(rename_tac n d c1 c2 m ea c e')(*strict*)\n     apply(blast)+\n  apply(rename_tac n d c1 c2 m ea c e')(*strict*)\n  apply(subgoal_tac \"\\<exists>a. edge_event e' = Some a\")\n   apply(rename_tac n d c1 c2 m ea c e')(*strict*)\n   prefer 2\n   apply(simp add: valid_dfa_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x = \"e'\"\n      in ballE)\n    apply(rename_tac n d c1 c2 m ea c e')(*strict*)\n    apply(clarsimp)\n   apply(rename_tac n d c1 c2 m ea c e')(*strict*)\n   apply(simp add: epdaS_step_relation_def)\n  apply(rename_tac n d c1 c2 m ea c e')(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n d c1 c2 m ea c e' a)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac n d c1 c2 m ea c e' a)(*strict*)\n   apply(simp add: epdaS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac n d c1 c2 m ea c e' a w)(*strict*)\n   apply(case_tac c2)\n   apply(rename_tac n d c1 c2 m ea c e' a w epdaS_conf_statea epdaS_conf_schedulera epdaS_conf_stacka)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n d c1 m ea c e' a w epdaS_conf_schedulera)(*strict*)\n   apply(case_tac c)\n   apply(rename_tac n d c1 m ea c e' a w epdaS_conf_schedulera epdaS_conf_statea epdaS_conf_scheduleraa epdaS_conf_stacka)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n d c1 m ea e' a w epdaS_conf_schedulera)(*strict*)\n   apply(case_tac e')\n   apply(rename_tac n d c1 m ea e' a w epdaS_conf_schedulera edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n d c1 m ea a w epdaS_conf_schedulera edge_src edge_pop edge_push edge_trg)(*strict*)\n   apply(simp add: option_to_list_def)\n   apply(rule_tac\n      t = \"drop (Suc n) (epdaS_conf_scheduler c1)\"\n      and s = \"drop (Suc 0) (drop n (epdaS_conf_scheduler c1))\"\n      in ssubst)\n    apply(rename_tac n d c1 m ea a w epdaS_conf_schedulera edge_src edge_pop edge_push edge_trg)(*strict*)\n    apply(rule sym)\n    apply(rule_tac\n      t = \"Suc n\"\n      and s = \"Suc 0+n\"\n      in ssubst)\n     apply(rename_tac n d c1 m ea a w epdaS_conf_schedulera edge_src edge_pop edge_push edge_trg)(*strict*)\n     apply(arith)\n    apply(rename_tac n d c1 m ea a w epdaS_conf_schedulera edge_src edge_pop edge_push edge_trg)(*strict*)\n    apply(rule drop_drop)\n   apply(rename_tac n d c1 m ea a w epdaS_conf_schedulera edge_src edge_pop edge_push edge_trg)(*strict*)\n   apply(force)\n  apply(rename_tac n d c1 c2 m ea c e' a)(*strict*)\n  apply(subgoal_tac \"length (epdaS_conf_scheduler c) = Suc (length(epdaS_conf_scheduler c2))\")\n   apply(rename_tac n d c1 c2 m ea c e' a)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac n d c1 c2 m ea c e' a)(*strict*)\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac n d c1 c2 m ea c e' a w)(*strict*)\n  apply(simp add: option_to_list_def)\n  done\n\nlemma InductOverReachables: \"\n  valid_epda M\n  \\<Longrightarrow> P (epda_initial M)\n  \\<Longrightarrow> (\\<forall>p e q cp cq. cp \\<in> epdaS_configurations M \\<longrightarrow> cq \\<in> epdaS_configurations M \\<longrightarrow> p\\<in> (epdaS_accessible_states M) \\<longrightarrow> P p \\<longrightarrow> epdaS_conf_state cp = p \\<longrightarrow> epdaS_conf_state cq = q \\<longrightarrow> epdaS_step_relation M cp e cq \\<longrightarrow> e \\<in> epda_step_labels M \\<longrightarrow> P q)\n  \\<Longrightarrow> p \\<in> (epdaS_accessible_states M)\n  \\<Longrightarrow> P p\"\n  apply(subgoal_tac \"\\<exists>n. p\\<in> (epda_states M) \\<and> (\\<exists>d. epdaS.derivation M d \\<and> (case get_configuration (d n) of None \\<Rightarrow> False | Some c \\<Rightarrow> epdaS_conf_state c = p)\\<and> (case get_configuration (d 0) of None \\<Rightarrow> False | Some c \\<Rightarrow> c \\<in> epdaS_initial_configurations M))\")\n   prefer 2\n   apply(simp add: epdaS_accessible_states_def)\n   apply(force)\n  apply(erule exE)\n  apply(rename_tac n)(*strict*)\n  apply(erule conjE)+\n  apply(erule exE)+\n  apply(rename_tac n d)(*strict*)\n  apply(erule conjE)+\n  apply(rule_tac\n      n = \"n\"\n      and f = \"\\<lambda>n. {q\\<in> (epda_states M). \\<exists>d. epdaS.derivation M d \\<and> (case get_configuration (d n) of None \\<Rightarrow> False | Some c \\<Rightarrow> epdaS_conf_state c = q)\\<and> (case get_configuration (d 0) of None \\<Rightarrow> False | Some c \\<Rightarrow> c \\<in> epdaS_initial_configurations M)}\"\n      in BEST_INDUCT2)\n   apply(rename_tac n d)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(force)\n  apply(rename_tac n d)(*strict*)\n  apply(rule allI)\n  apply(rename_tac n d k)(*strict*)\n  apply(rule impI)+\n  apply(rule allI)+\n  apply(rename_tac n d k x l)(*strict*)\n  apply(rule impI)+\n  apply(clarsimp)\n  apply(rename_tac n d k x l da)(*strict*)\n  apply(case_tac \"l<k\")\n   apply(rename_tac n d k x l da)(*strict*)\n   apply(erule_tac\n      x = \"x\"\n      and P = \"\\<lambda>x. \\<forall>l<k. x \\<in> epda_states M \\<and> (\\<exists>d. epdaS.derivation M d \\<and> (case get_configuration (d l) of None \\<Rightarrow> False | Some c \\<Rightarrow> epdaS_conf_state c = x) \\<and> (case get_configuration (d 0) of None \\<Rightarrow> False | Some c \\<Rightarrow> c \\<in> epdaS_initial_configurations M)) \\<longrightarrow> P x\"\n      in allE)\n   apply(rename_tac n d k x l da)(*strict*)\n   apply(clarsimp)\n   apply(erule_tac\n      x = \"l\"\n      and P = \"\\<lambda>l. l < k \\<longrightarrow> (\\<exists>d. epdaS.derivation M d \\<and> (case get_configuration (d l) of None \\<Rightarrow> False | Some c \\<Rightarrow> epdaS_conf_state c = x) \\<and> (case get_configuration (d 0) of None \\<Rightarrow> False | Some c \\<Rightarrow> c \\<in> epdaS_initial_configurations M)) \\<longrightarrow> P x\"\n      in allE)\n   apply(rename_tac n d k x l da)(*strict*)\n   apply(erule impE)\n    apply(rename_tac n d k x l da)(*strict*)\n    apply(arith)\n   apply(rename_tac n d k x l da)(*strict*)\n   apply(force)\n  apply(rename_tac n d k x l da)(*strict*)\n  apply(subgoal_tac \"l = k\")\n   apply(rename_tac n d k x l da)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac n d k x l da)(*strict*)\n  apply(thin_tac \"\\<not> l < k\")\n  apply(thin_tac \"l \\<le> k\")\n  apply(clarsimp)\n  apply(rename_tac n d k x da)(*strict*)\n  apply(case_tac k)\n   apply(rename_tac n d k x da)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n d x da)(*strict*)\n   apply(subgoal_tac \"x = epda_initial M\")\n    apply(rename_tac n d x da)(*strict*)\n    apply(force)\n   apply(rename_tac n d x da)(*strict*)\n   apply(case_tac \"get_configuration (da 0)\")\n    apply(rename_tac n d x da)(*strict*)\n    apply(force)\n   apply(rename_tac n d x da a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n d da a)(*strict*)\n   apply(simp add: epdaS_initial_configurations_def)\n  apply(rename_tac n d k x da nat)(*strict*)\n  apply(subgoal_tac \"\\<exists>ek ck. da k = Some (pair (Some ek) ck)\")\n   apply(rename_tac n d k x da nat)(*strict*)\n   prefer 2\n   apply(simp add: get_configuration_def)\n   apply(case_tac \"da k\")\n    apply(rename_tac n d k x da nat)(*strict*)\n    apply(force)\n   apply(rename_tac n d k x da nat a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n d x da nat a)(*strict*)\n   apply(case_tac a)\n   apply(rename_tac n d x da nat a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n d da nat option b)(*strict*)\n   apply(case_tac option)\n    apply(rename_tac n d da nat option b)(*strict*)\n    apply(rule_tac\n      d = \"da\"\n      in epdaS.derivation_Always_PreEdge_prime)\n     apply(rename_tac n d da nat option b)(*strict*)\n     apply(force)\n    apply(rename_tac n d da nat option b)(*strict*)\n    apply(force)\n   apply(rename_tac n d da nat option b a)(*strict*)\n   apply(force)\n  apply(rename_tac n d k x da nat)(*strict*)\n  apply(subgoal_tac \"\\<exists>enat cnat. da nat = Some (pair enat cnat)\")\n   apply(rename_tac n d k x da nat)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac n d x da nat ek ck)(*strict*)\n   apply(case_tac \"da nat\")\n    apply(rename_tac n d x da nat ek ck)(*strict*)\n    apply(rule_tac\n      d = \"da\"\n      and n = \"nat\"\n      in epdaS.derivationNoFromNone)\n      apply(rename_tac n d x da nat ek ck)(*strict*)\n      apply(force)\n     apply(rename_tac n d x da nat ek ck)(*strict*)\n     apply(force)\n    apply(rename_tac n d x da nat ek ck)(*strict*)\n    apply(force)\n   apply(rename_tac n d x da nat ek ck a)(*strict*)\n   apply(case_tac a)\n   apply(rename_tac n d x da nat ek ck a option b)(*strict*)\n   apply(force)\n  apply(rename_tac n d k x da nat)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac n d k x da nat ek enat ck cnat)(*strict*)\n  apply(subgoal_tac \"\\<exists>q. q \\<in> epda_states M \\<and> (epdaS.derivation M da \\<and> (case get_configuration (da nat) of None \\<Rightarrow> False | Some c \\<Rightarrow> epdaS_conf_state c = q)\\<and> (case get_configuration (da 0) of None \\<Rightarrow> False | Some c \\<Rightarrow> epdaS_conf_state c = epda_initial M))\")\n   apply(rename_tac n d k x da nat ek enat ck cnat)(*strict*)\n   prefer 2\n   apply(simp add: get_configuration_def)\n   apply(case_tac \"da 0\")\n    apply(rename_tac n d k x da nat ek enat ck cnat)(*strict*)\n    apply(force)\n   apply(rename_tac n d k x da nat ek enat ck cnat a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n d da nat ek enat ck cnat a)(*strict*)\n   apply(case_tac \"da nat\")\n    apply(rename_tac n d da nat ek enat ck cnat a)(*strict*)\n    apply(force)\n   apply(rename_tac n d da nat ek enat ck cnat a aa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n d da nat ek enat ck cnat a)(*strict*)\n   apply(case_tac a)\n   apply(rename_tac n d da nat ek enat ck cnat a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n d da nat ek enat ck cnat option b)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac n d da nat ek enat ck cnat option b)(*strict*)\n    apply(subgoal_tac \"cnat \\<in> epdaS_configurations M\")\n     apply(rename_tac n d da nat ek enat ck cnat option b)(*strict*)\n     prefer 2\n     apply(rule_tac\n      d = \"da\"\n      and m = \"0\"\n      in epdaS.stays_in_configuration)\n          apply(rename_tac n d da nat ek enat ck cnat option b)(*strict*)\n          apply(force)\n         apply(rename_tac n d da nat ek enat ck cnat option b)(*strict*)\n         apply(force)\n        apply(rename_tac n d da nat ek enat ck cnat option b)(*strict*)\n        apply(force)\n       apply(rename_tac n d da nat ek enat ck cnat option b)(*strict*)\n       apply(subgoal_tac \"epdaS_initial_configurations M \\<subseteq> epdaS_configurations M\")\n        apply(rename_tac n d da nat ek enat ck cnat option b)(*strict*)\n        apply(force)\n       apply(rename_tac n d da nat ek enat ck cnat option b)(*strict*)\n       apply(rule epdaS.AX_initial_configuration_belongs)\n       apply(force)\n      apply(rename_tac n d da nat ek enat ck cnat option b)(*strict*)\n      apply(force)\n     apply(rename_tac n d da nat ek enat ck cnat option b)(*strict*)\n     apply(simp add: epdaS_configurations_def)\n    apply(rename_tac n d da nat ek enat ck cnat option b)(*strict*)\n    apply(case_tac cnat)\n    apply(rename_tac n d da nat ek enat ck cnat option b epdaS_conf_statea epdaS_conf_scheduler epdaS_conf_stack)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac n d da nat ek enat ck option b epdaS_conf_statea epdaS_conf_scheduler epdaS_conf_stack)(*strict*)\n    apply(simp add: epdaS_configurations_def)\n   apply(rename_tac n d da nat ek enat ck cnat option b)(*strict*)\n   apply(simp add: epdaS_initial_configurations_def)\n  apply(rename_tac n d k x da nat ek enat ck cnat)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac n d k x da nat ek enat ck cnat q)(*strict*)\n  apply(erule conjE)+\n  apply(simp add: get_configuration_def)\n  apply(case_tac \"d 0\")\n   apply(rename_tac n d k x da nat ek enat ck cnat q)(*strict*)\n   apply(force)\n  apply(rename_tac n d k x da nat ek enat ck cnat q a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n d da nat ek enat ck cnat a)(*strict*)\n  apply(case_tac \"d n\")\n   apply(rename_tac n d da nat ek enat ck cnat a)(*strict*)\n   apply(force)\n  apply(rename_tac n d da nat ek enat ck cnat a aa)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"a\")\n  apply(rename_tac n d da nat ek enat ck cnat a aa option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n d da nat ek enat ck cnat aa option b)(*strict*)\n  apply(case_tac \"aa\")\n  apply(rename_tac n d da nat ek enat ck cnat aa option b optiona ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n d da nat ek enat ck cnat option b optiona ba)(*strict*)\n  apply(case_tac \"da 0\")\n   apply(rename_tac n d da nat ek enat ck cnat option b optiona ba)(*strict*)\n   apply(force)\n  apply(rename_tac n d da nat ek enat ck cnat option b optiona ba a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"da nat\")\n   apply(rename_tac n d da nat ek enat ck cnat option b optiona ba a)(*strict*)\n   apply(force)\n  apply(rename_tac n d da nat ek enat ck cnat option b optiona ba a aa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n d da nat ek enat ck cnat option b optiona ba a)(*strict*)\n  apply(case_tac \"a\")\n  apply(rename_tac n d da nat ek enat ck cnat option b optiona ba a optionb bb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n  apply(erule_tac\n      x = \"epdaS_conf_state cnat\"\n      and P = \"\\<lambda>x. \\<forall>l<Suc nat. x \\<in> epda_states M \\<and> (\\<exists>d. epdaS.derivation M d \\<and> (case case_option None (case_derivation_configuration (\\<lambda>e. Some)) (d l) of None \\<Rightarrow> False | Some c \\<Rightarrow> epdaS_conf_state c = x) \\<and> (case case_option None (case_derivation_configuration (\\<lambda>e. Some)) (d 0) of None \\<Rightarrow> False | Some c \\<Rightarrow> c \\<in> epdaS_initial_configurations M)) \\<longrightarrow> P x\"\n      in allE)\n  apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n  apply(erule_tac\n      x = \"nat\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n   apply(force)\n  apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n  apply(erule impE)\n   apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n   apply(clarsimp)\n   apply(rule_tac\n      x = \"da\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n  apply(erule_tac\n      x = \"epdaS_conf_state cnat\"\n      in allE)\n  apply(erule_tac\n      x = \"ek\"\n      in allE)\n  apply(erule_tac\n      x = \"epdaS_conf_state ck\"\n      in allE)\n  apply(erule_tac\n      x = \"cnat\"\n      in allE)\n  apply(clarsimp)\n  apply(subgoal_tac \"cnat \\<in> epdaS_configurations M\")\n   apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d = \"da\"\n      and m = \"0\"\n      in epdaS.stays_in_configuration)\n        apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n        apply(force)\n       apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n       apply(force)\n      apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n      apply(force)\n     apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n     apply(subgoal_tac \"epdaS_initial_configurations M \\<subseteq> epdaS_configurations M\")\n      apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n      apply(force)\n     apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n     apply(rule epdaS.AX_initial_configuration_belongs)\n     apply(force)\n    apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n    apply(force)\n   apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n   apply(erule impE)\n    apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n    apply(rule_tac\n      d = \"da\"\n      in epdaS.belongs_configurations)\n     apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n     apply(rule epdaS.derivation_initial_belongs)\n      apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n      apply(force)\n     apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n     apply(simp add: epdaS.derivation_initial_def)\n     apply(simp add: epdaS.derivation_def)\n     apply(erule_tac\n      x = \"0\"\n      and P = \"\\<lambda>x. case x of 0 \\<Rightarrow> case da 0 of None \\<Rightarrow> False | Some (pair None c) \\<Rightarrow> True | Some (pair (Some e) c) \\<Rightarrow> False | Suc i' \\<Rightarrow> case da x of None \\<Rightarrow> True | Some (pair i1 i2) \\<Rightarrow> case da i' of None \\<Rightarrow> False | Some (pair i'1 i'2) \\<Rightarrow> case i1 of None \\<Rightarrow> False | Some i1v \\<Rightarrow> epdaS_step_relation M i'2 i1v i2\"\n      in allE)\n     apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n     apply(clarsimp)\n     apply(case_tac \"optionb\")\n      apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb a)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n    apply(force)\n   apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n   apply(force)\n  apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n  apply(erule impE)\n   apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n   apply(force)\n  apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n  apply(erule_tac\n      x = \"ck\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n   apply(rule_tac\n      d = \"da\"\n      and m = \"0\"\n      in epdaS.stays_in_configuration)\n        apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n        apply(force)\n       apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n       apply(force)\n      apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n      apply(force)\n     apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n     apply(subgoal_tac \"epdaS_initial_configurations M \\<subseteq> epdaS_configurations M\")\n      apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n      apply(force)\n     apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n     apply(rule epdaS.AX_initial_configuration_belongs)\n     apply(force)\n    apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n    apply(force)\n   apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n   apply(force)\n  apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n  apply(erule impE)\n   apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n   apply(simp add: epdaS_accessible_states_def)\n   apply(rule_tac\n      x = \"da\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n    apply(force)\n   apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n    apply(rule_tac\n      x = \"nat\"\n      in exI)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n  apply(erule impE)\n   apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n   apply(force)\n  apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n  apply(subgoal_tac \"epdaS_step_relation M cnat ek ck\")\n   apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d = \"da\"\n      in epdaS.position_change_due_to_step_relation)\n     apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n     apply(force)\n    apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n    apply(force)\n   apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n   apply(force)\n  apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n  apply(erule impE)\n   apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n   apply(force)\n  apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n  apply(erule impE)\n   apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n   apply(subgoal_tac \"ek \\<in> epda_step_labels M \\<and> ck \\<in> epdaS_configurations M\")\n    apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n    apply(force)\n   apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n   apply(rule epdaS.AX_step_relation_preserves_belongs)\n     apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n     apply(force)\n    apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n    apply(force)\n   apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n   apply(force)\n  apply(rename_tac n d da nat ek enat ck cnat option b optiona ba optionb bb)(*strict*)\n  apply(force)\n  done\n\nlemma epda_earliest_word_removal_position: \"\n  epdaS.derivation G d\n  \\<Longrightarrow> d 0 = Some (pair None c)\n  \\<Longrightarrow> d n = Some (pair e cn)\n  \\<Longrightarrow> \\<not> P c\n  \\<Longrightarrow> P cn\n  \\<Longrightarrow> P = (\\<lambda>c. \\<not>(\\<exists>z. w@z = epdaS_conf_scheduler c))\n  \\<Longrightarrow> \\<exists>k\\<le>n. (\\<forall>i<k. \\<not> (case d i of None \\<Rightarrow> False | Some (pair e c) \\<Rightarrow> P c)) \\<and>\n                  (case d k of None \\<Rightarrow> False | Some (pair e c) \\<Rightarrow> P c)\"\n  apply(rule epdaS.existence_of_earliest_satisfaction_point)\n    apply(force)\n   apply(force)\n  apply(force)\n  done\n\nlemma epda_drop_terminals: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.derivation G d\n  \\<Longrightarrow> d i = Some (pair e c)\n  \\<Longrightarrow> case d (i+j) of None \\<Rightarrow> True | Some (pair e' c') \\<Rightarrow> \\<exists>w. w@(epdaS_conf_scheduler c') = (epdaS_conf_scheduler c)\"\n  apply(rule_tac\n      m = \"i\"\n      and n = \"j\"\n      in epdaS.property_preseved_under_steps_is_invariant2)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac ia)(*strict*)\n  apply(case_tac \"d (Suc ia)\")\n   apply(rename_tac ia)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ia a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac ia a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ia option b)(*strict*)\n  apply(case_tac option)\n   apply(rename_tac ia option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac ia b)(*strict*)\n   apply(rule epdaS.derivation_Always_PreEdge_prime)\n    apply(rename_tac ia b)(*strict*)\n    apply(force)\n   apply(rename_tac ia b)(*strict*)\n   apply(force)\n  apply(rename_tac ia option b a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ia b a)(*strict*)\n  apply(case_tac \"d ia\")\n   apply(rename_tac ia b a)(*strict*)\n   apply(rule epdaS.derivationNoFromNone)\n     apply(rename_tac ia b a)(*strict*)\n     apply(force)\n    apply(rename_tac ia b a)(*strict*)\n    apply(force)\n   apply(rename_tac ia b a)(*strict*)\n   apply(force)\n  apply(rename_tac ia b a aa)(*strict*)\n  apply(clarsimp)\n  apply(case_tac aa)\n  apply(rename_tac ia b a aa option ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ia b a option ba w)(*strict*)\n  apply(subgoal_tac \"epdaS_step_relation G ba a b\")\n   apply(rename_tac ia b a option ba w)(*strict*)\n   prefer 2\n   apply(rule epdaS.position_change_due_to_step_relation)\n     apply(rename_tac ia b a option ba w)(*strict*)\n     apply(force)\n    apply(rename_tac ia b a option ba w)(*strict*)\n    apply(force)\n   apply(rename_tac ia b a option ba w)(*strict*)\n   apply(force)\n  apply(rename_tac ia b a option ba w)(*strict*)\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac ia b a option ba w wa)(*strict*)\n  apply(rule_tac\n      t = \"epdaS_conf_scheduler c\"\n      and s = \"w @ option_to_list (edge_event a) @ epdaS_conf_scheduler b\"\n      in ssubst)\n   apply(rename_tac ia b a option ba w wa)(*strict*)\n   apply(force)\n  apply(rename_tac ia b a option ba w wa)(*strict*)\n  apply(simp (no_asm))\n  done\n\nlemma epda_Nonblockingness2: \"\n  valid_epda G\n  \\<Longrightarrow> Nonblockingness2 (epdaS.unmarked_language G) (epdaS.marked_language G)\"\n  apply(simp add: Nonblockingness2_def)\n  apply(simp add: epdaS.marked_language_def epdaS.unmarked_language_def prefix_closure_def prefix_def)\n  apply(clarsimp)\n  apply(rename_tac x d c)(*strict*)\n  apply(simp add: epdaS_initial_configurations_def epdaS_marked_effect_def epdaS_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac x d c ca i e cb)(*strict*)\n  apply(simp add: epdaS_marking_configurations_def)\n  apply(clarsimp)\n  apply(case_tac \"x\")\n   apply(rename_tac x d c ca i e cb)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d ca i e cb)(*strict*)\n   apply(rule_tac\n      x = \"der1 (ca\\<lparr>epdaS_conf_scheduler:= []\\<rparr>)\"\n      in exI)\n   apply(rename_tac d ca i e cb)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d ca i e cb)(*strict*)\n    apply(simp add: epdaS.derivation_initial_def)\n    apply(rule conjI)\n     apply(rename_tac d ca i e cb)(*strict*)\n     apply(rule epdaS.der1_is_derivation)\n    apply(rename_tac d ca i e cb)(*strict*)\n    apply(simp add: der1_def)\n    apply(simp add: epdaS_initial_configurations_def epdaS_configurations_def)\n    apply(clarsimp)\n   apply(rename_tac d ca i e cb)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d ca i e cb)(*strict*)\n    apply(simp add: epdaS_unmarked_effect_def)\n    apply(simp add: der1_def)\n   apply(rename_tac d ca i e cb)(*strict*)\n   apply(rule epdaS.der1_is_derivation)\n  apply(rename_tac x d c ca i e cb a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>k\\<le>i. (\\<forall>i<k. \\<not> (case d i of None \\<Rightarrow> False | Some (pair e c') \\<Rightarrow> (\\<lambda>x. length (epdaS_conf_scheduler x) \\<le> length c)c')) \\<and> (case d k of None \\<Rightarrow> False | Some (pair e c') \\<Rightarrow> (\\<lambda>x. length (epdaS_conf_scheduler x) \\<le> length c) c')\")\n   apply(rename_tac x d c ca i e cb a list)(*strict*)\n   prefer 2\n   apply(rule epdaS.existence_of_earliest_satisfaction_point)\n     apply(rename_tac x d c ca i e cb a list)(*strict*)\n     apply(force)\n    apply(rename_tac x d c ca i e cb a list)(*strict*)\n    apply(force)\n   apply(rename_tac x d c ca i e cb a list)(*strict*)\n   apply(force)\n  apply(rename_tac x d c ca i e cb a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d c ca i e cb a list k)(*strict*)\n  apply(case_tac \"d k\")\n   apply(rename_tac d c ca i e cb a list k)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d c ca i e cb a list k aa)(*strict*)\n  apply(case_tac aa)\n  apply(rename_tac d c ca i e cb a list k aa option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d c ca i e cb a list k option b)(*strict*)\n  apply(rule_tac\n      x = \"\\<lambda>n. (case (derivation_take d k) n of None \\<Rightarrow> None | Some (pair e c') \\<Rightarrow> Some (pair e (c'\\<lparr>epdaS_conf_scheduler:= take (length (epdaS_conf_scheduler c') - length c) (epdaS_conf_scheduler c')\\<rparr>)))\"\n      in exI)\n  apply(rename_tac d c ca i e cb a list k option b)(*strict*)\n  apply(subgoal_tac \"epdaS.derivation G (\\<lambda>n. case_option None (case_derivation_configuration (\\<lambda>e c'. Some (pair e (c'\\<lparr>epdaS_conf_scheduler := take (length (epdaS_conf_scheduler c') - length c) (epdaS_conf_scheduler c')\\<rparr>)))) (derivation_take d k n)) \\<and> (case case_option None (case_derivation_configuration (\\<lambda>e c'. Some (pair e (c'\\<lparr>epdaS_conf_scheduler := take (length (epdaS_conf_scheduler c') - length c) (epdaS_conf_scheduler c')\\<rparr>)))) (derivation_take d k 0) of None \\<Rightarrow> False | Some (pair a b) \\<Rightarrow> b \\<in> epdaS_initial_configurations G \\<and> a = None)\")\n   apply(rename_tac d c ca i e cb a list k option b)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d c ca i e cb a list k option b)(*strict*)\n    apply(simp add: epdaS.derivation_initial_def)\n   apply(rename_tac d c ca i e cb a list k option b)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d c ca i e cb a list k option b)(*strict*)\n    apply(simp add: epdaS_unmarked_effect_def)\n    apply(rule_tac\n      x = \"ca\\<lparr>epdaS_conf_scheduler:= a#list\\<rparr>\"\n      in exI)\n    apply(clarsimp)\n    apply(rule conjI)\n     apply(rename_tac d c ca i e cb a list k option b)(*strict*)\n     apply(simp add: derivation_take_def)\n     apply(case_tac ca)\n     apply(rename_tac d c ca i e cb a list k option b epdaS_conf_statea epdaS_conf_schedulera epdaS_conf_stack)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d c ca i e cb a list k option b)(*strict*)\n    apply(rule_tac\n      x = \"b\\<lparr>epdaS_conf_scheduler:= []\\<rparr>\"\n      in exI)\n    apply(clarsimp)\n    apply(rule_tac\n      x = \"k\"\n      in exI)\n    apply(rule_tac\n      x = \"option\"\n      in exI)\n    apply(simp add: derivation_take_def)\n   apply(rename_tac d c ca i e cb a list k option b)(*strict*)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac d c ca i e cb a list k option b)(*strict*)\n  apply(simp add: derivation_take_def)\n  apply(simp (no_asm) add: epdaS.derivation_def)\n  apply(rule conjI)\n   apply(rename_tac d c ca i e cb a list k option b)(*strict*)\n   prefer 2\n   apply(case_tac ca)\n   apply(rename_tac d c ca i e cb a list k option b epdaS_conf_statea epdaS_conf_schedulera epdaS_conf_stack)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d c i e cb a list k option b epdaS_conf_statea epdaS_conf_stack)(*strict*)\n   apply(simp add: epdaS.derivation_initial_def)\n   apply(simp add: epdaS_initial_configurations_def)\n   apply(simp add: epdaS_configurations_def)\n   apply(rule conjI)\n    apply(rename_tac d c i e cb a list k option b epdaS_conf_statea epdaS_conf_stack)(*strict*)\n    apply(rule valid_epda_initial_in_states)\n    apply(force)\n   apply(rename_tac d c i e cb a list k option b epdaS_conf_statea epdaS_conf_stack)(*strict*)\n   apply(rule valid_epda_box_in_gamma)\n   apply(force)\n  apply(rename_tac d c ca i e cb a list k option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d c ca i e cb a list k option b ia)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac d c ca i e cb a list k option b ia)(*strict*)\n   apply(clarsimp)\n   apply(case_tac ia)\n    apply(rename_tac d c ca i e cb a list k option b ia)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d c ca i e cb a list k option b ia nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d c ca i e cb a list k option b nat)(*strict*)\n   apply(case_tac \"d (Suc nat)\")\n    apply(rename_tac d c ca i e cb a list k option b nat)(*strict*)\n    apply(case_tac \"Suc nat = k\")\n     apply(rename_tac d c ca i e cb a list k option b nat)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d c ca i e cb a list k option b nat)(*strict*)\n    apply(rule_tac\n      M = \"G\"\n      and d = \"d\"\n      and n = \"k\"\n      and i = \"Suc nat\"\n      in epdaS.derivationNoFromNone2)\n       apply(rename_tac d c ca i e cb a list k option b nat)(*strict*)\n       apply(force)\n      apply(rename_tac d c ca i e cb a list k option b nat)(*strict*)\n      apply(force)\n     apply(rename_tac d c ca i e cb a list k option b nat)(*strict*)\n     apply(force)\n    apply(rename_tac d c ca i e cb a list k option b nat)(*strict*)\n    apply(force)\n   apply(rename_tac d c ca i e cb a list k option b nat aa)(*strict*)\n   apply(case_tac \"d nat\")\n    apply(rename_tac d c ca i e cb a list k option b nat aa)(*strict*)\n    apply(rule_tac\n      M = \"G\"\n      and d = \"d\"\n      and n = \"k\"\n      and i = \"nat\"\n      in epdaS.derivationNoFromNone2)\n       apply(rename_tac d c ca i e cb a list k option b nat aa)(*strict*)\n       apply(force)\n      apply(rename_tac d c ca i e cb a list k option b nat aa)(*strict*)\n      apply(force)\n     apply(rename_tac d c ca i e cb a list k option b nat aa)(*strict*)\n     apply(force)\n    apply(rename_tac d c ca i e cb a list k option b nat aa)(*strict*)\n    apply(force)\n   apply(rename_tac d c ca i e cb a list k option b nat aa ab)(*strict*)\n   apply(clarsimp)\n   apply(case_tac aa)\n   apply(rename_tac d c ca i e cb a list k option b nat aa ab optiona ba)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d c ca i e cb a list k option b nat ab optiona ba)(*strict*)\n   apply(case_tac ab)\n   apply(rename_tac d c ca i e cb a list k option b nat ab optiona ba optionb bb)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d c ca i e cb a list k option b nat optiona ba optionb bb)(*strict*)\n   apply(case_tac optiona)\n    apply(rename_tac d c ca i e cb a list k option b nat optiona ba optionb bb)(*strict*)\n    apply(rule epdaS.derivation_Always_PreEdge_prime)\n     apply(rename_tac d c ca i e cb a list k option b nat optiona ba optionb bb)(*strict*)\n     apply(force)\n    apply(rename_tac d c ca i e cb a list k option b nat optiona ba optionb bb)(*strict*)\n    apply(force)\n   apply(rename_tac d c ca i e cb a list k option b nat optiona ba optionb bb aa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa)(*strict*)\n   apply(subgoal_tac \"epdaS_step_relation G bb aa ba\")\n    apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa)(*strict*)\n    prefer 2\n    apply(rule epdaS.position_change_due_to_step_relation)\n      apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa)(*strict*)\n      apply(force)\n     apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa)(*strict*)\n     apply(force)\n    apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa)(*strict*)\n    apply(force)\n   apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa)(*strict*)\n   apply(subgoal_tac \"\\<exists>a z. a#z@c = epdaS_conf_scheduler bb\")\n    apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa ab z)(*strict*)\n    apply(simp add: epdaS_step_relation_def)\n    apply(clarsimp)\n    apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa ab z w)(*strict*)\n    apply(simp add: option_to_list_def)\n    apply(case_tac aa)\n    apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa ab z w edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb ab z w edge_event edge_pop edge_push)(*strict*)\n    apply(case_tac edge_event)\n     apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb ab z w edge_event edge_pop edge_push)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb ab z w edge_event edge_pop edge_push aa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb z w edge_pop edge_push aa)(*strict*)\n    apply(rule List.take_all)\n    apply(erule_tac\n      x = \"nat\"\n      in allE)\n    apply(clarsimp)\n    apply(force)\n   apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa)(*strict*)\n   apply(erule_tac\n      x = \"nat\"\n      in allE)\n   apply(clarsimp)\n   apply(subgoal_tac \"\\<exists>w. w@epdaS_conf_scheduler bb = a#list@c\")\n    apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa)(*strict*)\n    prefer 2\n    apply(subgoal_tac \"case d (0+nat) of None \\<Rightarrow> True | Some (pair e' c') \\<Rightarrow> \\<exists>w. w@(epdaS_conf_scheduler c') = (epdaS_conf_scheduler ca)\")\n     apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa)(*strict*)\n     prefer 2\n     apply(rule epda_drop_terminals)\n       apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa)(*strict*)\n       apply(force)\n      apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa)(*strict*)\n      apply(force)\n     apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa)(*strict*)\n     apply(force)\n    apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa)(*strict*)\n    apply(force)\n   apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa w)(*strict*)\n   apply(subgoal_tac \"prefix (a#list) w \\<or> prefix w (a#list) \")\n    apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa w)(*strict*)\n    apply(simp add: prefix_def)\n    apply(erule disjE)\n     apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa w)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa cc)(*strict*)\n     apply(subgoal_tac \"a#list@cc@epdaS_conf_scheduler bb = a#list@c\")\n      apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa cc)(*strict*)\n      prefer 2\n      apply(clarsimp)\n     apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa cc)(*strict*)\n     apply(subgoal_tac \"cc @ epdaS_conf_scheduler bb = c\")\n      apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa cc)(*strict*)\n      apply(force)\n     apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa cc)(*strict*)\n     apply(force)\n    apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa w cc)(*strict*)\n    apply(subgoal_tac \"a#list@c = w @ epdaS_conf_scheduler bb\")\n     apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa w cc)(*strict*)\n     prefer 2\n     apply(clarsimp)\n    apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa w cc)(*strict*)\n    apply(subgoal_tac \"w@cc@c = w @ epdaS_conf_scheduler bb\")\n     apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa w cc)(*strict*)\n     prefer 2\n     apply(rule_tac\n      t = \"w@cc@c\"\n      and s = \"(w@cc)@c\"\n      in ssubst)\n      apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa w cc)(*strict*)\n      apply(simp (no_asm_use))\n     apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa w cc)(*strict*)\n     apply(rule_tac\n      t = \"w@cc\"\n      and s = \"a#list\"\n      in ssubst)\n      apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa w cc)(*strict*)\n      apply(force)\n     apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa w cc)(*strict*)\n     apply(force)\n    apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa w cc)(*strict*)\n    apply(case_tac cc)\n     apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa w cc)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa w cc ab lista)(*strict*)\n    apply(force)\n   apply(rename_tac d c ca i e cb a list k option b nat ba optionb bb aa w)(*strict*)\n   apply(rule_tac\n      b = \"c\"\n      and d = \"epdaS_conf_scheduler bb\"\n      in mutual_prefix_prefix)\n   apply(force)\n  apply(rename_tac d c ca i e cb a list k option b ia)(*strict*)\n  apply(clarsimp)\n  apply(case_tac ia)\n   apply(rename_tac d c ca i e cb a list k option b ia)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d c ca i e cb a list k option b ia nat)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma epda_earliest_word_removal_position_prime: \"\n  epdaS.derivation G d\n  \\<Longrightarrow> d 0 = Some (pair None c)\n  \\<Longrightarrow> d n = Some (pair e cn)\n  \\<Longrightarrow> \\<not> P c\n  \\<Longrightarrow> P cn\n  \\<Longrightarrow> P = (\\<lambda>c. \\<not>(\\<exists>z. z@ca@epdaS_conf_scheduler cn = epdaS_conf_scheduler c))\n  \\<Longrightarrow> \\<exists>k\\<le>n. (\\<forall>i<k. \\<not> (case d i of None \\<Rightarrow> False | Some (pair e c) \\<Rightarrow> P c)) \\<and>\n                  (case d k of None \\<Rightarrow> False | Some (pair e c) \\<Rightarrow> P c)\"\n  apply(rule epdaS.existence_of_earliest_satisfaction_point)\n    apply(force)\n   apply(force)\n  apply(force)\n  done\n\nlemma epda_maximal_context_preserves_derivation_prime: \"\n  valid_epda M\n  \\<Longrightarrow> dh 0 = Some (pair None c)\n  \\<Longrightarrow> epdaS.belongs M dh\n  \\<Longrightarrow> epdaS.derivation M dh\n  \\<Longrightarrow> maximum_of_domain dh n\n  \\<Longrightarrow> dh n = Some (pair e ca)\n  \\<Longrightarrow> epdaS_conf_scheduler c = w @ epdaS_conf_scheduler ca\n  \\<Longrightarrow> epdaS.derivation M\n           (derivation_map dh\n             (\\<lambda>c. c\\<lparr>epdaS_conf_scheduler :=\n                      take (length (epdaS_conf_scheduler c) - length (epdaS_conf_scheduler ca)) (epdaS_conf_scheduler c) @ v\\<rparr>))\"\n  apply(simp (no_asm_simp) add: epdaS.derivation_def)\n  apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(case_tac i)\n   apply(rename_tac i)(*strict*)\n   apply(clarsimp)\n   apply(simp add: derivation_map_def)\n  apply(rename_tac i nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat)(*strict*)\n  apply(simp add: derivation_map_def)\n  apply(case_tac \"dh (Suc nat)\")\n   apply(rename_tac nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac nat a)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. dh nat = Some (pair e c)\")\n   apply(rename_tac nat a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m = \"Suc nat\"\n      in epdaS.pre_some_position_is_some_position)\n     apply(rename_tac nat a)(*strict*)\n     apply(force)\n    apply(rename_tac nat a)(*strict*)\n    apply(force)\n   apply(rename_tac nat a)(*strict*)\n   apply(force)\n  apply(rename_tac nat a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat a ea cb)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. dh (Suc nat) = Some (pair (Some e) c)\")\n   apply(rename_tac nat a ea cb)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m = \"Suc nat\"\n      in epdaS.pre_some_position_is_some_position_prime)\n      apply(rename_tac nat a ea cb)(*strict*)\n      apply(force)\n     apply(rename_tac nat a ea cb)(*strict*)\n     apply(force)\n    apply(rename_tac nat a ea cb)(*strict*)\n    apply(force)\n   apply(rename_tac nat a ea cb)(*strict*)\n   apply(force)\n  apply(rename_tac nat a ea cb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat ea cb eaa caa)(*strict*)\n  apply(subgoal_tac \"epdaS_step_relation M cb eaa caa\")\n   apply(rename_tac nat ea cb eaa caa)(*strict*)\n   apply(simp add: derivation_map_def)\n   apply(simp add: epda_step_labels_def epdaS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac nat ea cb eaa caa wa)(*strict*)\n   apply(case_tac \"edge_event eaa\")\n    apply(rename_tac nat ea cb eaa caa wa)(*strict*)\n    apply(clarsimp)\n    apply(simp add: option_to_list_def)\n   apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n   apply(clarsimp)\n   apply(simp add: option_to_list_def)\n   apply(subgoal_tac \"Suc (length (epdaS_conf_scheduler caa)) - length (epdaS_conf_scheduler ca) \\<ge> Suc 0\")\n    apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n   apply(subgoal_tac \"length (epdaS_conf_scheduler caa) \\<ge> length (epdaS_conf_scheduler ca)\")\n    apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n    apply(force)\n   apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n   apply(subgoal_tac \"Suc nat\\<le>n\")\n    apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n    apply(subgoal_tac \"\\<exists>w. epdaS_string_state caa = w @ (epdaS_string_state ca)\")\n     apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n     prefer 2\n     apply(rule_tac\n      j = \"n-(Suc nat)\"\n      in epdaS.derivation_monotonically_dec)\n          apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n          apply(force)\n         apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n         apply(force)\n        apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n        apply(force)\n       apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n       apply(force)\n      apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n      apply(force)\n     apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n     apply(force)\n    apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac nat ea cb eaa caa wa a waa)(*strict*)\n    apply(simp add: epdaS_string_state_def)\n   apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n   apply(case_tac \"Suc nat > n\")\n    apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n   apply(rule_tac\n      m = \"Suc nat\"\n      and n = \"n\"\n      in epdaS.no_some_beyond_maximum_of_domain)\n      apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n      apply(force)\n     apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n     apply(force)\n    apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n    apply(force)\n   apply(rename_tac nat ea cb eaa caa wa a)(*strict*)\n   apply(force)\n  apply(rename_tac nat ea cb eaa caa)(*strict*)\n  apply(rule epdaS.position_change_due_to_step_relation)\n    apply(rename_tac nat ea cb eaa caa)(*strict*)\n    apply(force)+\n  done\n\nlemma epda_maximal_context_preserves_derivation_with_Crop: \"\n  valid_epda M\n  \\<Longrightarrow> dh 0 = Some (pair None c)\n  \\<Longrightarrow> epdaS.belongs M dh\n  \\<Longrightarrow> epdaS.derivation M dh\n  \\<Longrightarrow> maximum_of_domain dh n\n  \\<Longrightarrow> dh n = Some (pair e ca)\n  \\<Longrightarrow> epdaS_conf_scheduler c = w @ epdaS_conf_scheduler ca\n  \\<Longrightarrow> dh n1 = Some (pair e2 c2)\n  \\<Longrightarrow> n1\\<le>n\n  \\<Longrightarrow> dh (n1 + min n2 (n - n1)) = Some (pair e1 c1)\n  \\<Longrightarrow> epdaS.derivation M\n        (derivation_map (derivation_take (derivation_drop dh n1) (min n2 (n - n1)))\n          (\\<lambda>c. c\\<lparr>epdaS_conf_scheduler :=\n                   take (length (epdaS_conf_scheduler c) - length (epdaS_conf_scheduler ca)) (epdaS_conf_scheduler c)\\<rparr>))\"\n  apply(simp (no_asm_simp) add: epdaS.derivation_def)\n  apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(case_tac i)\n   apply(rename_tac i)(*strict*)\n   apply(clarsimp)\n   apply(simp add: derivation_map_def derivation_take_def derivation_drop_def)\n  apply(rename_tac i nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat)(*strict*)\n  apply(simp add: derivation_map_def derivation_take_def derivation_drop_def)\n  apply(clarsimp)\n  apply(case_tac \"dh (Suc (nat + n1))\")\n   apply(rename_tac nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac nat a)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. dh ((nat + n1)) = Some (pair e c)\")\n   apply(rename_tac nat a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m = \"(Suc (nat + n1))\"\n      in epdaS.pre_some_position_is_some_position)\n     apply(rename_tac nat a)(*strict*)\n     apply(force)\n    apply(rename_tac nat a)(*strict*)\n    apply(force)\n   apply(rename_tac nat a)(*strict*)\n   apply(force)\n  apply(rename_tac nat a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat a ea cb)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. dh (Suc (nat + n1)) = Some (pair (Some e) c)\")\n   apply(rename_tac nat a ea cb)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m = \"(Suc (nat + n1))\"\n      in epdaS.pre_some_position_is_some_position_prime)\n      apply(rename_tac nat a ea cb)(*strict*)\n      apply(force)\n     apply(rename_tac nat a ea cb)(*strict*)\n     apply(force)\n    apply(rename_tac nat a ea cb)(*strict*)\n    apply(force)\n   apply(rename_tac nat a ea cb)(*strict*)\n   apply(force)\n  apply(rename_tac nat a ea cb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat ea cb eaa caa)(*strict*)\n  apply(simp add: derivation_map_def derivation_take_def derivation_drop_def)\n  apply(subgoal_tac \"epdaS_step_relation M cb eaa caa\")\n   apply(rename_tac nat ea cb eaa caa)(*strict*)\n   apply(case_tac nat)\n    apply(rename_tac nat ea cb eaa caa)(*strict*)\n    apply(simp add: epdaS_step_relation_def)\n    apply(clarsimp)\n    apply(rename_tac ea caa wa)(*strict*)\n    apply(case_tac \"edge_event ea\")\n     apply(rename_tac ea caa wa)(*strict*)\n     apply(clarsimp)\n     apply(simp add: option_to_list_def)\n    apply(rename_tac ea caa wa a)(*strict*)\n    apply(simp add: option_to_list_def)\n    apply(subgoal_tac \"length (epdaS_conf_scheduler caa) \\<ge> length (epdaS_conf_scheduler ca)\")\n     apply(rename_tac ea caa wa a)(*strict*)\n     apply(force)\n    apply(rename_tac ea caa wa a)(*strict*)\n    apply(subgoal_tac \"\\<exists>w. epdaS_string_state caa = w @ (epdaS_string_state ca)\")\n     apply(rename_tac ea caa wa a)(*strict*)\n     prefer 2\n     apply(rule_tac\n      j = \"n-(Suc n1)\"\n      in epdaS.derivation_monotonically_dec)\n          apply(rename_tac ea caa wa a)(*strict*)\n          apply(force)\n         apply(rename_tac ea caa wa a)(*strict*)\n         apply(force)\n        apply(rename_tac ea caa wa a)(*strict*)\n        apply(force)\n       apply(rename_tac ea caa wa a)(*strict*)\n       apply(force)\n      apply(rename_tac ea caa wa a)(*strict*)\n      apply(force)\n     apply(rename_tac ea caa wa a)(*strict*)\n     apply(force)\n    apply(rename_tac ea caa wa a)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac ea caa wa a waa)(*strict*)\n    apply(simp add: epdaS_string_state_def)\n   apply(rename_tac nat ea cb eaa caa nata)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac ea cb eaa caa nata)(*strict*)\n   apply(simp add: epdaS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac ea cb eaa caa nata wa)(*strict*)\n   apply(case_tac \"edge_event eaa\")\n    apply(rename_tac ea cb eaa caa nata wa)(*strict*)\n    apply(clarsimp)\n    apply(simp add: option_to_list_def)\n   apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n   apply(simp add: option_to_list_def)\n   apply(subgoal_tac \"length (epdaS_conf_scheduler caa) \\<ge> length (epdaS_conf_scheduler ca)\")\n    apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n    apply(force)\n   apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n   apply(subgoal_tac \"\\<exists>w. epdaS_string_state caa = w @ (epdaS_string_state ca)\")\n    apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n    prefer 2\n    apply(rule_tac\n      j = \"n-(Suc (Suc (nata + n1)))\"\n      in epdaS.derivation_monotonically_dec)\n         apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n         apply(force)\n        apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n        apply(force)\n       apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n       apply(force)\n      apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n      apply(force)\n     apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n     apply(force)\n    apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n    apply(rule_tac\n      t = \"(Suc (Suc (nata + n1)) + (n - Suc (Suc (nata + n1))))\"\n      and s = \"n\"\n      in ssubst)\n     apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n     apply(force)\n    apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n    apply(force)\n   apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac ea cb eaa caa nata wa a waa)(*strict*)\n   apply(simp add: epdaS_string_state_def)\n  apply(rename_tac nat ea cb eaa caa)(*strict*)\n  apply(rule epdaS.position_change_due_to_step_relation)\n    apply(rename_tac nat ea cb eaa caa)(*strict*)\n    apply(force)+\n  done\n\nlemma epda_maximal_context_preserves_derivation_with_Crop_prime: \"\n  valid_epda M\n  \\<Longrightarrow> dh 0 = Some (pair None c)\n  \\<Longrightarrow> epdaS.belongs M dh\n  \\<Longrightarrow> epdaS.derivation M dh\n  \\<Longrightarrow> maximum_of_domain dh n\n  \\<Longrightarrow> dh n = Some (pair e ca)\n  \\<Longrightarrow> epdaS_conf_scheduler c = w @ epdaS_conf_scheduler ca\n  \\<Longrightarrow> dh n1 = Some (pair e2 c2)\n  \\<Longrightarrow> n1\\<le>n\n  \\<Longrightarrow> dh (n1 + min n2 (n - n1)) = Some (pair e1 c1)\n  \\<Longrightarrow> epdaS.derivation M\n        (derivation_map (derivation_take (derivation_drop dh n1) (min n2 (n - n1)))\n          (\\<lambda>c. c\\<lparr>epdaS_conf_scheduler :=\n                   take (length (epdaS_conf_scheduler c) - length (epdaS_conf_scheduler ca)) (epdaS_conf_scheduler c)@v\\<rparr>))\"\n  apply(simp (no_asm_simp) add: epdaS.derivation_def)\n  apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(case_tac i)\n   apply(rename_tac i)(*strict*)\n   apply(clarsimp)\n   apply(simp add: derivation_map_def derivation_take_def derivation_drop_def)\n  apply(rename_tac i nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat)(*strict*)\n  apply(simp add: derivation_map_def derivation_take_def derivation_drop_def)\n  apply(clarsimp)\n  apply(case_tac \"dh (Suc (nat + n1))\")\n   apply(rename_tac nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac nat a)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. dh ((nat + n1)) = Some (pair e c)\")\n   apply(rename_tac nat a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m = \"(Suc (nat + n1))\"\n      in epdaS.pre_some_position_is_some_position)\n     apply(rename_tac nat a)(*strict*)\n     apply(force)\n    apply(rename_tac nat a)(*strict*)\n    apply(force)\n   apply(rename_tac nat a)(*strict*)\n   apply(force)\n  apply(rename_tac nat a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat a ea cb)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. dh (Suc (nat + n1)) = Some (pair (Some e) c)\")\n   apply(rename_tac nat a ea cb)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m = \"(Suc (nat + n1))\"\n      in epdaS.pre_some_position_is_some_position_prime)\n      apply(rename_tac nat a ea cb)(*strict*)\n      apply(force)\n     apply(rename_tac nat a ea cb)(*strict*)\n     apply(force)\n    apply(rename_tac nat a ea cb)(*strict*)\n    apply(force)\n   apply(rename_tac nat a ea cb)(*strict*)\n   apply(force)\n  apply(rename_tac nat a ea cb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat ea cb eaa caa)(*strict*)\n  apply(simp add: derivation_map_def derivation_take_def derivation_drop_def)\n  apply(subgoal_tac \"epdaS_step_relation M cb eaa caa\")\n   apply(rename_tac nat ea cb eaa caa)(*strict*)\n   apply(case_tac nat)\n    apply(rename_tac nat ea cb eaa caa)(*strict*)\n    apply(simp add: epdaS_step_relation_def)\n    apply(clarsimp)\n    apply(rename_tac ea caa wa)(*strict*)\n    apply(case_tac \"edge_event ea\")\n     apply(rename_tac ea caa wa)(*strict*)\n     apply(clarsimp)\n     apply(simp add: option_to_list_def)\n    apply(rename_tac ea caa wa a)(*strict*)\n    apply(simp add: option_to_list_def)\n    apply(subgoal_tac \"length (epdaS_conf_scheduler caa) \\<ge> length (epdaS_conf_scheduler ca)\")\n     apply(rename_tac ea caa wa a)(*strict*)\n     apply(force)\n    apply(rename_tac ea caa wa a)(*strict*)\n    apply(subgoal_tac \"\\<exists>w. epdaS_string_state caa = w @ (epdaS_string_state ca)\")\n     apply(rename_tac ea caa wa a)(*strict*)\n     prefer 2\n     apply(rule_tac\n      j = \"n-(Suc n1)\"\n      in epdaS.derivation_monotonically_dec)\n          apply(rename_tac ea caa wa a)(*strict*)\n          apply(force)\n         apply(rename_tac ea caa wa a)(*strict*)\n         apply(force)\n        apply(rename_tac ea caa wa a)(*strict*)\n        apply(force)\n       apply(rename_tac ea caa wa a)(*strict*)\n       apply(force)\n      apply(rename_tac ea caa wa a)(*strict*)\n      apply(force)\n     apply(rename_tac ea caa wa a)(*strict*)\n     apply(force)\n    apply(rename_tac ea caa wa a)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac ea caa wa a waa)(*strict*)\n    apply(simp add: epdaS_string_state_def)\n   apply(rename_tac nat ea cb eaa caa nata)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac ea cb eaa caa nata)(*strict*)\n   apply(simp add: epdaS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac ea cb eaa caa nata wa)(*strict*)\n   apply(case_tac \"edge_event eaa\")\n    apply(rename_tac ea cb eaa caa nata wa)(*strict*)\n    apply(clarsimp)\n    apply(simp add: option_to_list_def)\n   apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n   apply(simp add: option_to_list_def)\n   apply(subgoal_tac \"length (epdaS_conf_scheduler caa) \\<ge> length (epdaS_conf_scheduler ca)\")\n    apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n    apply(force)\n   apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n   apply(subgoal_tac \"\\<exists>w. epdaS_string_state caa = w @ (epdaS_string_state ca)\")\n    apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n    prefer 2\n    apply(rule_tac\n      j = \"n-(Suc (Suc (nata + n1)))\"\n      in epdaS.derivation_monotonically_dec)\n         apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n         apply(force)\n        apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n        apply(force)\n       apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n       apply(force)\n      apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n      apply(force)\n     apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n     apply(force)\n    apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n    apply(rule_tac\n      t = \"(Suc (Suc (nata + n1)) + (n - Suc (Suc (nata + n1))))\"\n      and s = \"n\"\n      in ssubst)\n     apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n     apply(force)\n    apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n    apply(force)\n   apply(rename_tac ea cb eaa caa nata wa a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac ea cb eaa caa nata wa a waa)(*strict*)\n   apply(simp add: epdaS_string_state_def)\n  apply(rename_tac nat ea cb eaa caa)(*strict*)\n  apply(rule epdaS.position_change_due_to_step_relation)\n    apply(rename_tac nat ea cb eaa caa)(*strict*)\n    apply(force)+\n  done\n\nlemma epda_maximal_context_preserves_belongs: \"\n  valid_epda M\n  \\<Longrightarrow> dh 0 = Some (pair None c)\n  \\<Longrightarrow> epdaS.belongs M dh\n  \\<Longrightarrow> epdaS.derivation M dh\n  \\<Longrightarrow> maximum_of_domain dh n\n  \\<Longrightarrow> dh n = Some (pair e ca)\n  \\<Longrightarrow> epdaS_conf_scheduler c = w @ epdaS_conf_scheduler ca\n  \\<Longrightarrow> dh n1 = Some (pair e2 c2)\n  \\<Longrightarrow> n1\\<le>n\n  \\<Longrightarrow> dh (n1 + min n2 (n - n1)) = Some (pair e1 c1)\n  \\<Longrightarrow> epdaS.belongs M (derivation_map (derivation_take (derivation_drop dh n1) (min n2 (n - n1))) (\\<lambda>c. c\\<lparr>epdaS_conf_scheduler := take (length (epdaS_conf_scheduler c) - length (epdaS_conf_scheduler ca)) (epdaS_conf_scheduler c)\\<rparr>))\"\n  apply(rule epdaS.derivation_belongs)\n     apply(force)\n    apply(simp add: derivation_map_def derivation_take_def derivation_drop_def)\n   apply(simp add: epdaS.belongs_def)\n   apply(erule_tac\n      x = \"n1\"\n      in allE)\n   apply(clarsimp)\n   apply(simp add: epdaS_configurations_def)\n   apply(clarsimp)\n   apply(rename_tac q i s x)(*strict*)\n   apply(rule_tac\n      A = \"set (take (length i - length (epdaS_conf_scheduler ca)) i)\"\n      in set_mp)\n    apply(rename_tac q i s x)(*strict*)\n    apply(rule_tac\n      B = \"set i\"\n      in subset_trans)\n     apply(rename_tac q i s x)(*strict*)\n     apply(rule set_take_subset)\n    apply(rename_tac q i s x)(*strict*)\n    apply(force)\n   apply(rename_tac q i s x)(*strict*)\n   apply(force)\n  apply(rule epda_maximal_context_preserves_derivation_with_Crop)\n           apply(force)+\n  done\n\nlemma epda_maximal_context_preserves_belongs_prime: \"\n  valid_epda M\n  \\<Longrightarrow> dh 0 = Some (pair None c)\n  \\<Longrightarrow> epdaS.belongs M dh\n  \\<Longrightarrow> epdaS.derivation M dh\n  \\<Longrightarrow> maximum_of_domain dh n\n  \\<Longrightarrow> dh n = Some (pair e ca)\n  \\<Longrightarrow> epdaS_conf_scheduler c = w @ epdaS_conf_scheduler ca\n  \\<Longrightarrow> dh n1 = Some (pair e2 c2)\n  \\<Longrightarrow> n1\\<le>n\n  \\<Longrightarrow> dh (n1 + min n2 (n - n1)) = Some (pair e1 c1)\n  \\<Longrightarrow> set v \\<subseteq> epda_events M\n  \\<Longrightarrow> epdaS.belongs M (derivation_map (derivation_take (derivation_drop dh n1) (min n2 (n - n1))) (\\<lambda>c. c\\<lparr>epdaS_conf_scheduler := take (length (epdaS_conf_scheduler c) - length (epdaS_conf_scheduler ca)) (epdaS_conf_scheduler c) @ v\\<rparr>))\"\n  apply(rule epdaS.derivation_belongs)\n     apply(force)\n    apply(simp add: derivation_map_def derivation_take_def derivation_drop_def)\n   apply(simp add: epdaS.belongs_def)\n   apply(erule_tac\n      x = \"n1\"\n      in allE)\n   apply(clarsimp)\n   apply(simp add: epdaS_configurations_def)\n   apply(clarsimp)\n   apply(rename_tac q i s x)(*strict*)\n   apply(rule_tac\n      A = \"set (take (length i - length (epdaS_conf_scheduler ca)) i)\"\n      in set_mp)\n    apply(rename_tac q i s x)(*strict*)\n    apply(rule_tac\n      B = \"set i\"\n      in subset_trans)\n     apply(rename_tac q i s x)(*strict*)\n     apply(rule set_take_subset)\n    apply(rename_tac q i s x)(*strict*)\n    apply(force)\n   apply(rename_tac q i s x)(*strict*)\n   apply(force)\n  apply(rule epda_maximal_context_preserves_derivation_with_Crop_prime)\n           apply(force)+\n  done\n\nlemma may_terminated_by_EndStrY: \"\n  w \\<in> may_terminated_by A y\n  \\<Longrightarrow> \\<exists>x. w = x@[y]\n  \\<Longrightarrow> w \\<in> must_terminated_by A y\"\n  apply(simp add: must_terminated_by_def may_terminated_by_def kleene_star_def append_language_def)\n  apply(force)\n  done\n\nlemma epda_push_also_must_terminated_by: \"\n  valid_epda G\n  \\<Longrightarrow> e \\<in> epda_delta G\n  \\<Longrightarrow> edge_pop e \\<in> must_terminated_by (epda_gamma G) (epda_box G)\n  \\<Longrightarrow> edge_push e \\<in> must_terminated_by (epda_gamma G) (epda_box G)\"\n  apply(simp add: valid_epda_def)\n  apply(clarsimp)\n  apply(erule_tac\n      x = \"e\"\n      in ballE)\n   apply(simp add: valid_epda_step_label_def)\n  apply(force)\n  done\n\nlemma epda_box_stays_at_bottom_prime: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.derivation_initial G d\n  \\<Longrightarrow> d i = Some (pair e c)\n  \\<Longrightarrow> \\<exists>w. epdaS_conf_stack c = w @ [epda_box G]\"\n  apply(induct i arbitrary: e c)\n   apply(rename_tac e c)(*strict*)\n   apply(simp add: epdaS.derivation_initial_def epdaS_initial_configurations_def)\n  apply(rename_tac i e c)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d i = Some (pair e1 c1) \\<and> SSd (Suc SSn) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation SSG c1 e2 c2\" for SSd SSn SSG)\n   apply(rename_tac i e c)(*strict*)\n   prefer 2\n   apply(rule epdaS.step_detail_before_some_position)\n     apply(rename_tac i e c)(*strict*)\n     apply(simp add: epdaS.derivation_initial_def)\n     apply(force)\n    apply(rename_tac i e c)(*strict*)\n    apply(force)\n   apply(rename_tac i e c)(*strict*)\n   apply(force)\n  apply(rename_tac i e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1)(*strict*)\n  apply(erule_tac\n      x = \"e1\"\n      in meta_allE)\n  apply(erule_tac\n      x = \"c1\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1 w)(*strict*)\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1 w wa)(*strict*)\n  apply(subgoal_tac \"valid_epda_step_label G e2\")\n   apply(rename_tac i c e1 e2 c1 w wa)(*strict*)\n   apply(case_tac wa)\n    apply(rename_tac i c e1 e2 c1 w wa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i c e1 e2 c1 w)(*strict*)\n    apply(subgoal_tac \"edge_push e2 \\<in> must_terminated_by (epda_gamma G) (epda_box G)\")\n     apply(rename_tac i c e1 e2 c1 w)(*strict*)\n     prefer 2\n     apply(rule epda_push_also_must_terminated_by)\n       apply(rename_tac i c e1 e2 c1 w)(*strict*)\n       apply(force)\n      apply(rename_tac i c e1 e2 c1 w)(*strict*)\n      apply(force)\n     apply(rename_tac i c e1 e2 c1 w)(*strict*)\n     apply(rule may_terminated_by_EndStrY)\n      apply(rename_tac i c e1 e2 c1 w)(*strict*)\n      apply(simp add: valid_epda_step_label_def)\n     apply(rename_tac i c e1 e2 c1 w)(*strict*)\n     apply(rule_tac\n      x = \"w\"\n      in exI)\n     apply(force)\n    apply(rename_tac i c e1 e2 c1 w)(*strict*)\n    apply(simp add: must_terminated_by_def kleene_star_def append_language_def)\n    apply(force)\n   apply(rename_tac i c e1 e2 c1 w wa a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. wa = w' @ [x']\")\n    apply(rename_tac i c e1 e2 c1 w wa a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac i c e1 e2 c1 w wa a list)(*strict*)\n   apply(thin_tac \"wa = a # list\")\n   apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1 w wa)(*strict*)\n  apply(simp add: valid_epda_def)\n  done\n\nlemma epda_box_stays_at_bottom: \"\n  valid_epda G\n  \\<Longrightarrow> c \\<in> epdaS.get_accessible_configurations G\n  \\<Longrightarrow> \\<exists>w. epdaS_conf_stack c = w@[epda_box G]\"\n  apply(simp add: epdaS.get_accessible_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac d i)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(case_tac \"d i\")\n   apply(rename_tac d i)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d i a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac d i a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i option)(*strict*)\n  apply(rename_tac e)\n  apply(rename_tac d i e)(*strict*)\n  apply(rule epda_box_stays_at_bottom_prime)\n    apply(rename_tac d i e)(*strict*)\n    apply(force)\n   apply(rename_tac d i e)(*strict*)\n   apply(force)\n  apply(rename_tac d i e)(*strict*)\n  apply(force)\n  done\n\nlemma epda_stack_is_must_terminated_by_prime: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.derivation_initial G d\n  \\<Longrightarrow> d i = Some (pair e c)\n  \\<Longrightarrow> epdaS_conf_stack c \\<in> must_terminated_by (epda_gamma G) (epda_box G)\"\n  apply(induct i arbitrary: e c)\n   apply(rename_tac e c)(*strict*)\n   apply(simp add: epdaS.derivation_initial_def epdaS_initial_configurations_def)\n   apply(simp add: must_terminated_by_def kleene_star_def append_language_def)\n  apply(rename_tac i e c)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d i = Some (pair e1 c1) \\<and> SSd (Suc SSn) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation SSG c1 e2 c2\" for SSd SSn SSG)\n   apply(rename_tac i e c)(*strict*)\n   prefer 2\n   apply(rule epdaS.step_detail_before_some_position)\n     apply(rename_tac i e c)(*strict*)\n     apply(simp add: epdaS.derivation_initial_def)\n     apply(force)\n    apply(rename_tac i e c)(*strict*)\n    apply(force)\n   apply(rename_tac i e c)(*strict*)\n   apply(force)\n  apply(rename_tac i e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1)(*strict*)\n  apply(erule_tac\n      x = \"e1\"\n      in meta_allE)\n  apply(erule_tac\n      x = \"c1\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1 w)(*strict*)\n  apply(subgoal_tac \"valid_epda_step_label G e2\")\n   apply(rename_tac i c e1 e2 c1 w)(*strict*)\n   prefer 2\n   apply(simp add: valid_epda_def)\n  apply(rename_tac i c e1 e2 c1 w)(*strict*)\n  apply(simp add: must_terminated_by_def kleene_star_def append_language_def)\n  apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1 w a)(*strict*)\n  apply(case_tac w)\n   apply(rename_tac i c e1 e2 c1 w a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i c e1 e2 c1 a)(*strict*)\n   apply(simp add: valid_epda_step_label_def)\n   apply(clarsimp)\n   apply(simp add: may_terminated_by_def must_terminated_by_def kleene_star_def append_language_def)\n  apply(rename_tac i c e1 e2 c1 w a aa list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. w = w' @ [x']\")\n   apply(rename_tac i c e1 e2 c1 w a aa list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac i c e1 e2 c1 w a aa list)(*strict*)\n  apply(thin_tac \"w = aa # list\")\n  apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1 w' x)(*strict*)\n  apply(simp add: valid_epda_step_label_def)\n  apply(clarsimp)\n  apply(simp add: may_terminated_by_def must_terminated_by_def kleene_star_def append_language_def)\n  apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1 w' x a aa)(*strict*)\n  apply(force)\n  done\n\nlemma epda_stack_is_must_terminated_by: \"\n  valid_epda G\n  \\<Longrightarrow> c \\<in> epdaS.get_accessible_configurations G\n  \\<Longrightarrow> epdaS_conf_stack c \\<in> must_terminated_by (epda_gamma G) (epda_box G)\"\n  apply(simp add: epdaS.get_accessible_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac d i)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(case_tac \"d i\")\n   apply(rename_tac d i)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d i a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac d i a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i option)(*strict*)\n  apply(rename_tac e)\n  apply(rename_tac d i e)(*strict*)\n  apply(rule epda_stack_is_must_terminated_by_prime)\n    apply(rename_tac d i e)(*strict*)\n    apply(force)\n   apply(rename_tac d i e)(*strict*)\n   apply(force)\n  apply(rename_tac d i e)(*strict*)\n  apply(force)\n  done\n\nlemma valid_epda_push_in_gamma: \"\n  valid_epda G\n  \\<Longrightarrow> e \\<in> epda_delta G\n  \\<Longrightarrow> set(edge_push e) \\<subseteq> epda_gamma G\"\n  apply(simp add: valid_epda_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(erule_tac\n      x = \"e\"\n      in ballE)\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: valid_epda_step_label_def)\n  apply(simp add: may_terminated_by_def kleene_star_def append_language_def)\n  apply(force)\n  done\n\nlemma valid_epda_pop_in_gamma: \"\n  valid_epda G\n  \\<Longrightarrow> e \\<in> epda_delta G\n  \\<Longrightarrow> set(edge_pop e) \\<subseteq> epda_gamma G\"\n  apply(simp add: valid_epda_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(erule_tac\n      x = \"e\"\n      in ballE)\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: valid_epda_step_label_def)\n  apply(simp add: may_terminated_by_def kleene_star_def append_language_def)\n  apply(force)\n  done\n\nlemma valid_simple_dpda_to_valid_dpda: \"\n  valid_simple_dpda G\n  \\<Longrightarrow> valid_dpda G\"\n  apply(simp add: valid_simple_dpda_def)\n  done\n\nlemma valid_dpda_to_valid_pda: \"\n  valid_dpda G\n  \\<Longrightarrow> valid_pda G\"\n  apply(simp add: valid_dpda_def)\n  done\n\nlemma valid_pda_to_valid_epda: \"\n  valid_pda G\n  \\<Longrightarrow> valid_epda G\"\n  apply(simp add: valid_pda_def)\n  done\n\nlemma DPDA_to_epdaH_determinism: \"\n  valid_dpda G\n  \\<Longrightarrow> epdaH.is_forward_edge_deterministicHist_DB_long G\"\n  apply(subgoal_tac \"epdaH.is_forward_edge_deterministicHist_DB_long G\")\n   prefer 2\n   apply(rule epdaHS2HF_FEdetermHist)\n    apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n   apply(subgoal_tac \"epdaHS.is_forward_edge_deterministic_accessible G\")\n    prefer 2\n    apply(subgoal_tac \"epdaS.is_forward_edge_deterministic_accessible G\")\n     prefer 2\n     apply(simp add: valid_simple_dpda_def valid_dpda_def)\n    apply(rule_tac\n      ?G1.0 = \"G\"\n      in epdaS_vs_epdaHS.preserve_FEdetermR1)\n     apply(clarsimp)\n     apply(simp add: valid_dpda_to_valid_pda valid_pda_to_valid_epda valid_simple_dpda_to_valid_dpda)\n    apply(force)\n   apply(subgoal_tac \"epdaHS.is_forward_edge_deterministicHist_DB_long G\")\n    prefer 2\n    apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n    apply(clarsimp)\n    apply (metis epdaHS.is_forward_edge_deterministic_accessible_implies_is_forward_edge_deterministicHist_DB_long)\n   apply(force)\n  apply(force)\n  done\n\nlemma epda_is_forward_edge_deterministicHist_DB_long_from_epdaH_to_epdaHS: \"\n  valid_epda M\n  \\<Longrightarrow> epdaH.is_forward_edge_deterministicHist_DB_long M\n  \\<Longrightarrow> epdaHS.is_forward_edge_deterministicHist_DB_long M\"\n  apply(simp add: epdaH.is_forward_edge_deterministicHist_DB_long_def epdaHS.is_forward_edge_deterministicHist_DB_long_def)\n  apply(clarsimp)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n  apply(erule_tac\n      x = \"epdaHvHS_Lin2BraConf c\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n   apply(rule_tac\n      x = \"epdaH_vs_epdaHS.Lin2BraDer d\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n    apply(rule epdaH_vs_epdaHS.Lin2BraConf_preserves_initiality_lift)\n     apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n     apply(force)\n    apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n    apply(force)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n   apply(simp add: epdaH_vs_epdaHS.Lin2BraDer_def derivation_map_def)\n   apply(case_tac \"d n\")\n    apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 a)(*strict*)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n   apply(case_tac a)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 option)(*strict*)\n   apply(rule_tac\n      x = \"n\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n  apply(erule_tac\n      x = \"epdaHvHS_Lin2BraConf c1\"\n      in allE)\n  apply(erule_tac\n      x = \"epdaHvHS_Lin2BraConf c2\"\n      in allE)\n  apply(erule_tac\n      x = \"e1\"\n      in allE)\n  apply(erule_tac\n      x = \"e2\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n  apply(rule_tac\n      x = \"w1\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n   apply(subgoal_tac \"c1 \\<in> epdaHS_configurations M\")\n    apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n    prefer 2\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n     prefer 2\n     apply(rule epdaHS.get_accessible_configurations_are_configurations)\n     apply(force)\n    apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n    apply(subgoal_tac \"c \\<in> epdaHS_configurations M\")\n     apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n     prefer 2\n     apply(rule_tac A=\"ATS.get_accessible_configurations epdaHS_initial_configurations\n        epdaHS_step_relation M\" in set_mp)\n      apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n      apply(force)\n     apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n     apply(simp add: epdaHS.get_accessible_configurations_def)\n     apply(case_tac \"d n\")\n      apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n      apply(force)\n     apply(rename_tac c d c1 c2 e1 e2 n w1 w2 a)(*strict*)\n     apply(clarsimp)\n     apply(case_tac \"a\")\n     apply(rename_tac c d c1 c2 e1 e2 n w1 w2 a option conf)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c d c1 c2 e1 e2 n w1 w2 option)(*strict*)\n     apply(rule_tac x=\"d\" in exI)\n     apply(clarsimp)\n     apply(simp add: get_configuration_def)\n     apply(rule_tac x=\"n\" in exI)\n     apply(clarsimp)\n    apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n    apply(rule epdaHS.AX_step_relation_preserves_belongsC)\n      apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n      apply(force)\n     apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n     apply(force)\n    apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n    apply(force)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n   apply(simp add: epda_effects_def epdaHS_configurations_def)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n  apply(rule_tac\n      x = \"w2\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n   apply(subgoal_tac \"c2 \\<in> epdaHS_configurations M\")\n    apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n    prefer 2\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n     prefer 2\n     apply(rule epdaHS.get_accessible_configurations_are_configurations)\n     apply(force)\n    apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n    apply(subgoal_tac \"c \\<in> epdaHS_configurations M\")\n     apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n     prefer 2\n     apply(rule_tac A=\"ATS.get_accessible_configurations epdaHS_initial_configurations\n        epdaHS_step_relation M\" in set_mp)\n      apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n      apply(force)\n     apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n     apply(simp add: epdaHS.get_accessible_configurations_def)\n     apply(case_tac \"d n\")\n      apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n      apply(force)\n     apply(rename_tac c d c1 c2 e1 e2 n w1 w2 a)(*strict*)\n     apply(clarsimp)\n     apply(case_tac \"a\")\n     apply(rename_tac c d c1 c2 e1 e2 n w1 w2 a option conf)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c d c1 c2 e1 e2 n w1 w2 option)(*strict*)\n     apply(rule_tac x=\"d\" in exI)\n     apply(clarsimp)\n     apply(simp add: get_configuration_def)\n     apply(rule_tac x=\"n\" in exI)\n     apply(clarsimp)\n    apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n    apply(rule epdaHS.AX_step_relation_preserves_belongsC)\n      apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n      apply(force)\n     apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n     apply(force)\n    apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n    apply(force)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n   apply(simp add: epda_effects_def epdaHS_configurations_def)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n   apply(simp add: epdaH_step_relation_def epdaHvHS_Lin2BraConf_def epdaHS_step_relation_def)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n   apply(simp add: epdaH_step_relation_def epdaHvHS_Lin2BraConf_def epdaHS_step_relation_def)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n   apply(simp add: epdaH_step_relation_def epdaHvHS_Lin2BraConf_def epdaHS_step_relation_def)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n   apply(simp add: epdaH_step_relation_def epdaHvHS_Lin2BraConf_def epdaHS_step_relation_def)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n  apply(force)\n  done\n\nlemma epda_epdaS_is_forward_edge_deterministic_accessible_equal_to_epdaH_is_forward_edge_deterministicHist_DB_long: \"\n  valid_epda M\n  \\<Longrightarrow> epdaS.is_forward_edge_deterministic_accessible M \\<longleftrightarrow> epdaH.is_forward_edge_deterministicHist_DB_long M\"\n  apply(rule order_antisym)\n   apply(clarsimp)\n   apply(rule epdaHS2HF_DEdetermR_FEdetermHist_DB)\n    apply(force)\n   apply(rule_tac\n      ?G1.0 = \"M\"\n      in epdaS_vs_epdaHS.preserve_FEdetermR1)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(rule epdaS_vs_epdaHS.preserve_FEdetermR2)\n   apply(force)\n  apply(rule_tac\n      t = \"epdaHS.is_forward_edge_deterministic_accessible M\"\n      in ssubst)\n   apply(rule I_epda_HS.epdaHS.AX_is_forward_edge_deterministic_correspond_SB)\n   apply(force)\n  apply(rule_tac\n      t = \"ATS_determHIST_SB.is_forward_edge_deterministicHist_SB_long epdaHS_initial_configurations epdaHS_step_relation epda_effects (@) (@) epdaHS_conf_history epda_fixed_scheduler_extendable epdaHS_get_fixed_scheduler M\"\n      in ssubst)\n   apply(rule I_epda_HS.epdaHS.AX_is_forward_edge_deterministic_correspond_DB_SB)\n   apply(force)\n  apply(rule epda_is_forward_edge_deterministicHist_DB_long_from_epdaH_to_epdaHS)\n   apply(force)\n  apply(force)\n  done\n\nlemma DPDA_is_is_forward_deterministicHist_SB: \"\n  valid_dpda G\n  \\<Longrightarrow> epdaH.is_forward_deterministicHist_SB G\"\n  apply(simp add: valid_dpda_def valid_pda_def)\n  apply(rule_tac\n      t = \"epdaH.is_forward_deterministicHist_SB G\"\n      and s = \"epdaH.is_forward_deterministicHist_DB G\"\n      in ssubst)\n   apply (rule epdaH.is_forward_deterministic_correspond_DB_SB)\n   apply(force)\n  apply(simp add: epdaH.is_forward_deterministicHist_DB_def)\n  apply(rule conjI)\n   apply (metis epdaH_is_forward_target_deterministicHist_DB_long)\n  apply(rule epdaHS2HF_FEdetermHist)\n   apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n  apply(subgoal_tac \"epdaHS.is_forward_edge_deterministic_accessible G\")\n   prefer 2\n   apply(subgoal_tac \"epdaS.is_forward_edge_deterministic_accessible G\")\n    prefer 2\n    apply(simp add: valid_simple_dpda_def valid_dpda_def)\n   apply (simp add: valid_dpda_to_valid_pda valid_pda_to_valid_epda valid_simple_dpda_to_valid_dpda)\n   apply(rule epdaS_vs_epdaHS.preserve_FEdetermR1)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"epdaHS.is_forward_edge_deterministicHist_DB_long G\")\n   prefer 2\n   apply(clarsimp)\n   apply (metis epdaHS.is_forward_edge_deterministic_accessible_implies_is_forward_edge_deterministicHist_DB_long)\n  apply(force)\n  done\n\ntheorem Nonblockingness_DPDA_without_empty_steps_from_final_states_is_Livelock_free: \"\n  valid_dpda M\n  \\<Longrightarrow> epdaH_no_livelocks_from_marking_states M\n  \\<Longrightarrow> epdaH.Nonblockingness_branching_restricted M\n  \\<Longrightarrow> \\<not> epdaH_livelock M\"\n  apply(simp add: epdaH_livelock_def)\n  apply(clarsimp)\n  apply(rename_tac d N)(*strict*)\n  apply(rule ccontr)\n  apply(clarsimp)\n  apply(rename_tac d N)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d N)(*strict*)\n   prefer 2\n   apply(rule_tac\n      n = \"N\"\n      and P = \"\\<lambda>N. \\<forall>n\\<ge>N. epdaH_conf_history (the (get_configuration (d n))) = epdaH_conf_history (the (get_configuration (d N))) \"\n      in ex_least_nat_le_prime)\n   apply(rename_tac d N)(*strict*)\n   apply(simp (no_asm))\n  apply(rename_tac d N)(*strict*)\n  apply(thin_tac \"\\<forall>n\\<ge>N. epdaH_conf_history (the (get_configuration (d n))) = epdaH_conf_history (the (get_configuration (d N)))\")\n  apply(rename_tac d N)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d N k)(*strict*)\n  apply(thin_tac \"k\\<le>N\")\n  apply(rename_tac d N k)(*strict*)\n  apply(subgoal_tac \"\\<forall>i\\<ge>k. epdaH_conf_state (the (get_configuration (d i))) \\<notin> epda_marking M\")\n   apply(rename_tac d N k)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac d k i)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d k i)(*strict*)\n    prefer 2\n    apply(rule_tac\n      G = \"M\"\n      and d = \"d\"\n      and n = \"i\"\n      and m = \"Suc i\"\n      in epdaH.step_detail_before_some_position)\n      apply(rename_tac d k i)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def)\n      apply(rule epdaH.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac d k i)(*strict*)\n     apply(force)\n    apply(rename_tac d k i)(*strict*)\n    apply(force)\n   apply(rename_tac d k i)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d k i e1 e2 c1 c2)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(simp add: epdaH_no_livelocks_from_marking_states_def)\n   apply(erule_tac\n      x = \"d\"\n      in allE)\n   apply(erule_tac\n      x = \"Suc i\"\n      and P = \"\\<lambda>x. epdaH.derivation_initial M d \\<and> (\\<exists>e. (\\<exists>c. d x = Some (pair (Some e) c)) \\<and> edge_src e \\<in> epda_marking M \\<and> edge_event e = None) \\<longrightarrow> (\\<exists>m>x. d m = None \\<or> (\\<exists>e'. (\\<exists>c'. d m = Some (pair (Some e') c')) \\<and> (\\<exists>y. edge_event e' = Some y)))\"\n      in allE)\n   apply(rename_tac d k i e1 e2 c1 c2)(*strict*)\n   apply(erule impE)\n    apply(rename_tac d k i e1 e2 c1 c2)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac d k i e1 e2 c1 c2)(*strict*)\n     apply(force)\n    apply(rename_tac d k i e1 e2 c1 c2)(*strict*)\n    apply(clarsimp)\n    apply(simp add: epdaH_step_relation_def)\n    apply(clarsimp)\n    apply(rename_tac d k i e1 e2 c1 c2 w)(*strict*)\n    apply(erule_tac x = \"i\" and P = \"\\<lambda>i. k \\<le> i \\<longrightarrow> epdaH_conf_history (the (case d i of None \\<Rightarrow> None | Some (pair e c) \\<Rightarrow> Some c)) = epdaH_conf_history (the (case d k of None \\<Rightarrow> None | Some (pair e c) \\<Rightarrow> Some c))\" in allE')\n    apply(rename_tac d k i e1 e2 c1 c2 w)(*strict*)\n    apply(erule_tac\n      x = \"Suc i\"\n      and P = \"\\<lambda>i. k \\<le> i \\<longrightarrow> epdaH_conf_history (the (case d i of None \\<Rightarrow> None | Some (pair e c) \\<Rightarrow> Some c)) = epdaH_conf_history (the (case d k of None \\<Rightarrow> None | Some (pair e c) \\<Rightarrow> Some c))\"\n      in allE)\n    apply(rename_tac d k i e1 e2 c1 c2 w)(*strict*)\n    apply(clarsimp)\n    apply(case_tac e2)\n    apply(rename_tac d k i e1 e2 c1 c2 w edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n    apply(case_tac edge_eventa)\n     apply(rename_tac d k i e1 e2 c1 c2 w edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d k i e1 e2 c1 c2 w edge_srca edge_eventa edge_popa edge_pusha edge_trga a)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d k i e1 c1 c2 w edge_pop edge_push a)(*strict*)\n    apply(simp add: option_to_list_def)\n   apply(rename_tac d k i e1 e2 c1 c2)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d k i e1 e2 c1 c2 m)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac d k i e1 e2 c1 c2 m)(*strict*)\n    apply(erule_tac\n      x = \"m\"\n      in allE)+\n    apply(force)\n   apply(rename_tac d k i e1 e2 c1 c2 m)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d k i e1 e2 c1 c2 m e' c' y)(*strict*)\n   apply(case_tac m)\n    apply(rename_tac d k i e1 e2 c1 c2 m e' c' y)(*strict*)\n    apply(force)\n   apply(rename_tac d k i e1 e2 c1 c2 m e' c' y nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d k i e1 e2 c1 c2 e' c' y nat)(*strict*)\n   apply(erule_tac x = \"nat\" and P = \"\\<lambda>i. k \\<le> i \\<longrightarrow> epdaH_conf_history (the (case d i of None \\<Rightarrow> None | Some (pair e c) \\<Rightarrow> Some c)) = epdaH_conf_history (the (case d k of None \\<Rightarrow> None | Some (pair e c) \\<Rightarrow> Some c))\" in allE')\n   apply(rename_tac d k i e1 e2 c1 c2 e' c' y nat)(*strict*)\n   apply(erule_tac\n      x = \"Suc nat\"\n      and P = \"\\<lambda>i. k \\<le> i \\<longrightarrow> epdaH_conf_history (the (case d i of None \\<Rightarrow> None | Some (pair e c) \\<Rightarrow> Some c)) = epdaH_conf_history (the (case d k of None \\<Rightarrow> None | Some (pair e c) \\<Rightarrow> Some c))\"\n      in allE)\n   apply(rename_tac d k i e1 e2 c1 c2 e' c' y nat)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d k i e1 e2 c1 c2 e' c' y nat)(*strict*)\n    prefer 2\n    apply(rule_tac\n      G = \"M\"\n      and d = \"d\"\n      and n = \"nat\"\n      and m = \"Suc nat\"\n      in epdaH.step_detail_before_some_position)\n      apply(rename_tac d k i e1 e2 c1 c2 e' c' y nat)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def)\n      apply(rule epdaH.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac d k i e1 e2 c1 c2 e' c' y nat)(*strict*)\n     apply(force)\n    apply(rename_tac d k i e1 e2 c1 c2 e' c' y nat)(*strict*)\n    apply(force)\n   apply(rename_tac d k i e1 e2 c1 c2 e' c' y nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d k i e1 e2 c1 c2 e' c' y nat e1a c1a)(*strict*)\n   apply(simp add: epdaH_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac d k i e1 e2 c1 c2 e' c' y nat e1a c1a w wa)(*strict*)\n   apply(simp add: option_to_list_def)\n  apply(rename_tac d N k)(*strict*)\n  apply(thin_tac \"epdaH_no_livelocks_from_marking_states M\")\n  apply(erule_tac x = \"0\" and P = \"\\<lambda>x. \\<exists>y. d x = Some y\" in allE')\n  apply(erule exE)+\n  apply(rename_tac d N k y)(*strict*)\n  apply(case_tac y)\n  apply(rename_tac d N k y option b)(*strict*)\n  apply(subgoal_tac \"option = None \\<and> b \\<in> epdaH_initial_configurations M\")\n   apply(rename_tac d N k y option b)(*strict*)\n   prefer 2\n   apply(simp add: epdaH.derivation_initial_def)\n  apply(rename_tac d N k y option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d k b)(*strict*)\n  apply(simp add: epdaH_initial_configurations_def)\n  apply(clarsimp)\n  apply(case_tac b)\n  apply(rename_tac d k b epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d k)(*strict*)\n  apply(case_tac \"\\<exists>j<k. epdaH_conf_state (the (get_configuration (d j))) \\<in> epda_marking M\")\n   apply(rename_tac d k)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac d k)(*strict*)\n   apply(simp add: epdaH.Nonblockingness_branching_restricted_def)\n   apply(erule_tac\n      x = \"derivation_take d k\"\n      in allE)\n   apply(erule_tac\n      x = \"k\"\n      and P = \"\\<lambda>n. epdaH.derivation_initial M (derivation_take d k) \\<and> maximum_of_domain (derivation_take d k) n \\<longrightarrow> (\\<exists>dc. epdaH.derivation M dc \\<and> epdaH.belongs M dc \\<and> (\\<exists>n'. maximum_of_domain dc n') \\<and> derivation_append_fit (derivation_take d k) dc n \\<and> epdaH_marking_condition M (derivation_append (derivation_take d k) dc n))\"\n      in allE)\n   apply(rename_tac d k)(*strict*)\n   apply(erule impE)\n    apply(rename_tac d k)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac d k)(*strict*)\n     apply(rule epdaH.derivation_take_preserves_derivation_initial)\n     apply(force)\n    apply(rename_tac d k)(*strict*)\n    apply(rule maximum_of_domain_derivation_take)\n    apply(force)\n   apply(rename_tac d k)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d k dc n')(*strict*)\n   apply(simp add: epdaH_marking_condition_def)\n   apply(clarsimp)\n   apply(rename_tac d k dc n' i e c)(*strict*)\n   apply(thin_tac \"\\<forall>j e' c'. i < j \\<and> derivation_append (derivation_take d k) dc k j = Some (pair e' c') \\<longrightarrow> epdaH_string_state c = epdaH_string_state c'\")\n   apply(rename_tac d k dc n' i e c)(*strict*)\n   apply(simp add: epdaH_marking_configurations_def)\n   apply(clarsimp)\n   apply(thin_tac \"c \\<in> epdaH_configurations M\")\n   apply(case_tac c)\n   apply(rename_tac d k dc n' i e c epdaH_conf_statea epdaH_conf_historya epdaH_conf_stack)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d k dc n' i e epdaH_conf_statea epdaH_conf_historya epdaH_conf_stack)(*strict*)\n   apply(rename_tac q1 h1 s1)\n   apply(rename_tac d k dc n' i e q1 h1 s1)(*strict*)\n   apply(case_tac \"i\\<le>k\")\n    apply(rename_tac d k dc n' i e q1 h1 s1)(*strict*)\n    apply(erule_tac\n      x = \"i\"\n      and P = \"\\<lambda>i. \\<exists>y. d i = Some y\"\n      in allE)\n    apply(clarsimp)\n    apply(rename_tac d k dc n' i e q1 h1 s1 y)(*strict*)\n    apply(erule_tac\n      x = \"i\"\n      and P = \"\\<lambda>i. k \\<le> i \\<longrightarrow> epdaH_conf_state (the (get_configuration (d i))) \\<notin> epda_marking M\"\n      in allE)\n    apply(erule_tac\n      x = \"i\"\n      and P = \"\\<lambda>i. i < k \\<longrightarrow> epdaH_conf_state (the (get_configuration (d i))) \\<notin> epda_marking M\"\n      in allE)\n    apply(clarsimp)\n    apply(simp add: derivation_append_def derivation_append_fit_def derivation_take_def)\n    apply(clarsimp)\n    apply(rename_tac d k dc n' i e q1 h1 s1)(*strict*)\n    apply(case_tac \"k = i\")\n     apply(rename_tac d k dc n' i e q1 h1 s1)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac d dc n' i e q1 h1 s1)(*strict*)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac d k dc n' i e q1 h1 s1)(*strict*)\n    apply(subgoal_tac \"i<k\")\n     apply(rename_tac d k dc n' i e q1 h1 s1)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac d k dc n' i e q1 h1 s1)(*strict*)\n    apply(clarsimp)\n    apply(simp (no_asm_use) add: get_configuration_def)\n    apply(force)\n   apply(rename_tac d k dc n' i e q1 h1 s1)(*strict*)\n   apply(subgoal_tac \"k<i\")\n    apply(rename_tac d k dc n' i e q1 h1 s1)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac d k dc n' i e q1 h1 s1)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d k dc n' i e q1 h1 s1)(*strict*)\n    prefer 2\n    apply(rule_tac\n      M = \"M\"\n      and g = \"dc\"\n      in epdaH.some_position_has_details_at_0)\n    apply(force)\n   apply(rename_tac d k dc n' i e q1 h1 s1)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n   apply(thin_tac \"\\<forall>j<k. epdaH_conf_state (the (get_configuration (d j))) \\<notin> epda_marking M\")\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n    prefer 2\n    apply(rule_tac\n      G = \"M\"\n      and ?d1.0 = \"d\"\n      and ?d2.0 = \"derivation_append (derivation_take d k) dc k\"\n      and x = \"k\"\n      and y = \"k\"\n      and n = \"i-k\"\n      and m = \"i-k\"\n      in epdaH.is_forward_deterministicHist_derivations_coincide)\n               apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n               apply(simp add: valid_dpda_def valid_pda_def)\n              apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n              apply(force)\n             apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n             apply(rule epdaH.derivation_append_preserves_derivation_initial)\n               apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n               apply(simp add: valid_dpda_def valid_pda_def)\n              apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n              apply(rule epdaH.derivation_take_preserves_derivation_initial)\n              apply(force)\n             apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n             apply(rule epdaH.derivation_append_preserves_derivation)\n               apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n               apply(rule epdaH.derivation_take_preserves_derivation)\n               apply(rule epdaH.derivation_initial_is_derivation)\n               apply(force)\n              apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n              apply(force)\n             apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n             apply(simp add: derivation_take_def)\n             apply(case_tac \"d k\")\n              apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n              apply(erule_tac\n      x = \"k\"\n      in allE)+\n              apply(force)\n             apply(rename_tac d k dc n' i e q1 h1 s1 c a)(*strict*)\n             apply(clarsimp)\n             apply(case_tac a)\n             apply(rename_tac d k dc n' i e q1 h1 s1 c a option b)(*strict*)\n             apply(clarsimp)\n             apply(rename_tac d k dc n' i e q1 h1 s1 c option b)(*strict*)\n             apply(simp add: derivation_append_fit_def)\n            apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n            apply(subgoal_tac \"epdaH.is_forward_deterministicHist_SB M\")\n             apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n             apply(force)\n            apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n            apply(rule DPDA_is_is_forward_deterministicHist_SB)\n            apply(force)\n           apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n           apply(simp add: derivation_append_def derivation_append_fit_def derivation_take_def)\n          apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n          apply(force)\n         apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n         apply(force)\n        apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n        apply(force)\n       apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n       apply(force)\n      apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n      apply(force)\n     apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n     apply(rule_tac\n      t = \"k+(i-k)\"\n      and s = \"i\"\n      in ssubst)\n      apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n      apply(force)\n     apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n     apply(rule_tac\n      t = \"epdaH_conf_history (the (get_configuration (d i)))\"\n      and s = \"epdaH_conf_history (the (get_configuration (d k)))\"\n      in ssubst)\n      apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n      apply(erule_tac\n      x = \"i\"\n      and P = \"\\<lambda>i. k \\<le> i \\<longrightarrow> epdaH_conf_history (the (get_configuration (d i))) = epdaH_conf_history (the (get_configuration (d k)))\"\n      in allE)\n      apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n      apply(force)\n     apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n     apply(erule_tac x = \"k\" and P = \"\\<lambda>k. \\<exists>y. d k = Some y\" in allE')\n     apply(clarify)\n     apply(rename_tac d k dc n' i e q1 h1 s1 c y)(*strict*)\n     apply(case_tac y)\n     apply(rename_tac d k dc n' i e q1 h1 s1 c y option b)(*strict*)\n     apply(rule_tac\n      t = \"epdaH_conf_history (the (get_configuration (d k)))\"\n      and s = \"epdaH_conf_history (the (get_configuration (dc 0)))\"\n      in ssubst)\n      apply(rename_tac d k dc n' i e q1 h1 s1 c y option b)(*strict*)\n      apply(simp (no_asm_use) only: derivation_append_fit_def derivation_take_def)\n      apply(simp (no_asm_use))\n      apply(clarsimp)\n      apply(rename_tac d k dc n' i e q1 h1 s1 c option)(*strict*)\n      apply(simp add: get_configuration_def)\n     apply(rename_tac d k dc n' i e q1 h1 s1 c y option b)(*strict*)\n     apply(rule_tac\n      t = \"epdaH_conf_history (the (get_configuration (derivation_append (derivation_take d k) dc k i)))\"\n      and s = \"epdaH_conf_history (the (get_configuration (dc (i-k))))\"\n      in ssubst)\n      apply(rename_tac d k dc n' i e q1 h1 s1 c y option b)(*strict*)\n      apply(simp (no_asm_use) only: derivation_append_fit_def derivation_take_def derivation_append_def)\n      apply(clarsimp)\n     apply(rename_tac d k dc n' i e q1 h1 s1 c y option b)(*strict*)\n     apply(subgoal_tac \"X\" for X)\n      apply(rename_tac d k dc n' i e q1 h1 s1 c y option b)(*strict*)\n      prefer 2\n      apply(rule_tac\n      G = \"M\"\n      and d = \"dc\"\n      and n = \"0\"\n      and m = \"i-k\"\n      in epdaH.steps_extend_history_derivation)\n          apply(rename_tac d k dc n' i e q1 h1 s1 c y option b)(*strict*)\n          apply(simp add: valid_dpda_def valid_pda_def)\n         apply(rename_tac d k dc n' i e q1 h1 s1 c y option b)(*strict*)\n         apply(force)\n        apply(rename_tac d k dc n' i e q1 h1 s1 c y option b)(*strict*)\n        prefer 2\n        apply(clarsimp)\n        apply(rename_tac d k dc n' i e q1 h1 s1 c option b)(*strict*)\n        apply(simp add: get_configuration_def)\n       apply(rename_tac d k dc n' i e q1 h1 s1 c y option b)(*strict*)\n       apply(rule_tac\n      d = \"dc\"\n      in epdaH.belongs_configurations)\n        apply(rename_tac d k dc n' i e q1 h1 s1 c y option b)(*strict*)\n        apply(force)\n       apply(rename_tac d k dc n' i e q1 h1 s1 c y option b)(*strict*)\n       apply(force)\n      apply(rename_tac d k dc n' i e q1 h1 s1 c y option b)(*strict*)\n      apply(simp (no_asm_use) only: derivation_append_fit_def derivation_take_def derivation_append_def)\n      apply(clarsimp)\n      apply(rename_tac d k dc n' i e q1 h1 s1 c option)(*strict*)\n      apply(simp add: get_configuration_def)\n     apply(rename_tac d k dc n' i e q1 h1 s1 c y option b)(*strict*)\n     apply(simp add: get_configuration_def)\n     apply(clarsimp)\n     apply(rename_tac d k dc n' i e q1 s1 c option b h)(*strict*)\n     apply(simp (no_asm_use) only: derivation_append_fit_def derivation_take_def derivation_append_def)\n     apply(clarsimp)\n    apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n    apply(force)\n   apply(rename_tac d k dc n' i e q1 h1 s1 c)(*strict*)\n   apply(erule_tac\n      x = \"i\"\n      in allE)+\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d k)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d k j)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d k j)(*strict*)\n   prefer 2\n   apply(rule_tac\n      n = \"k\"\n      and x = \"j\"\n      and P = \"\\<lambda>j. epdaH_conf_state (the (get_configuration (d j))) \\<in> epda_marking M\"\n      in ex_max_limited)\n    apply(rename_tac d k j)(*strict*)\n    apply(force)\n   apply(rename_tac d k j)(*strict*)\n   apply(force)\n  apply(rename_tac d k j)(*strict*)\n  apply(thin_tac \"j < k\")\n  apply(thin_tac \"epdaH_conf_state (the (get_configuration (d j))) \\<in> epda_marking M\")\n  apply(clarsimp)\n  apply(rename_tac d k ka)(*strict*)\n  apply(case_tac k)\n   apply(rename_tac d k ka)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(erule_tac\n      x = \"0\"\n      in allE)+\n   apply(clarsimp)\n  apply(rename_tac d k ka nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d ka nat)(*strict*)\n  apply(rename_tac k)\n  apply(rename_tac d ka k)(*strict*)\n  apply(subgoal_tac \"epdaH_conf_history (the (get_configuration (d k))) \\<noteq> epdaH_conf_history (the (get_configuration (d (Suc k))))\")\n   apply(rename_tac d ka k)(*strict*)\n   prefer 2\n   apply(erule_tac\n      x = \"k\"\n      and P = \"\\<lambda>x. x < Suc k \\<longrightarrow> (\\<exists>n\\<ge>x. epdaH_conf_history (the (get_configuration (d n))) \\<noteq> epdaH_conf_history (the (get_configuration (d x))))\"\n      in allE)\n   apply(rename_tac d ka k)(*strict*)\n   apply(erule impE)\n    apply(rename_tac d ka k)(*strict*)\n    apply(force)\n   apply(rename_tac d ka k)(*strict*)\n   apply(erule exE)+\n   apply(rename_tac d ka k n)(*strict*)\n   apply(erule conjE)+\n   apply(case_tac \"n = k\")\n    apply(rename_tac d ka k n)(*strict*)\n    apply(force)\n   apply(rename_tac d ka k n)(*strict*)\n   apply(erule_tac\n      x = \"n\"\n      and P = \"\\<lambda>n. Suc k \\<le> n \\<longrightarrow> epdaH_conf_history (the (get_configuration (d n))) = epdaH_conf_history (the (get_configuration (d (Suc k))))\"\n      in allE)\n   apply(rename_tac d ka k n)(*strict*)\n   apply(erule impE)\n    apply(rename_tac d ka k n)(*strict*)\n    apply(force)\n   apply(rename_tac d ka k n)(*strict*)\n   apply(force)\n  apply(rename_tac d ka k)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d ka k)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G = \"M\"\n      and d = \"d\"\n      and n = \"k\"\n      and m = \"Suc k\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac d ka k)(*strict*)\n     apply(rule epdaH.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac d ka k)(*strict*)\n    apply(erule_tac\n      x = \"Suc k\"\n      in allE)+\n    apply(force)\n   apply(rename_tac d ka k)(*strict*)\n   apply(force)\n  apply(rename_tac d ka k)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac d ka k e1 e2 c1 c2)(*strict*)\n  apply(erule conjE)+\n  apply(simp add: epdaH_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac d ka k e1 e2 c1 c2 w)(*strict*)\n  apply(case_tac c1)\n  apply(rename_tac d ka k e1 e2 c1 c2 w epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n  apply(case_tac c2)\n  apply(rename_tac d ka k e1 e2 c1 c2 w epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka epdaH_conf_stateaa epdaH_conf_historyaa epdaH_conf_stackaa)(*strict*)\n  apply(case_tac e2)\n  apply(rename_tac d ka k e1 e2 c1 c2 w epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka epdaH_conf_stateaa epdaH_conf_historyaa epdaH_conf_stackaa edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d ka k e1 w epdaH_conf_historya edge_src edge_event edge_pop edge_push edge_trg)(*strict*)\n  apply(rename_tac h src read pop push trg)\n  apply(rename_tac d ka k e1 w h src read pop push trg)(*strict*)\n  apply(case_tac \"read\")\n   apply(rename_tac d ka k e1 w h src read pop push trg)(*strict*)\n   apply(simp add: get_configuration_def option_to_list_def)\n  apply(rename_tac d ka k e1 w h src read pop push trg a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d ka k e1 w h src pop push trg a)(*strict*)\n  apply(thin_tac \"epdaH_conf_history (the (get_configuration (Some (pair e1 \\<lparr>epdaH_conf_state = src, epdaH_conf_history = h, epdaH_conf_stack = pop @ w\\<rparr>)))) \\<noteq> epdaH_conf_history (the (get_configuration (Some (pair (Some \\<lparr>edge_src = src, edge_event = Some a, edge_pop = pop, edge_push = push, edge_trg = trg\\<rparr>) \\<lparr>epdaH_conf_state = trg, epdaH_conf_history = h @ option_to_list (Some a), epdaH_conf_stack = push @ w\\<rparr>))))\")\n  apply(rename_tac d ka k e1 w h src pop push trg a)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(rename_tac d ka k e1 w h src pop push trg a)(*strict*)\n  apply(simp add: epdaH.Nonblockingness_branching_restricted_def)\n  apply(erule_tac\n      x = \"derivation_take d (Suc k)\"\n      in allE)\n  apply(erule_tac\n      x = \"Suc k\"\n      and P = \"\\<lambda>n. epdaH.derivation_initial M (derivation_take d (Suc k)) \\<and> maximum_of_domain (derivation_take d (Suc k)) n \\<longrightarrow> (\\<exists>dc. epdaH.derivation M dc \\<and> epdaH.belongs M dc \\<and> (\\<exists>n'. maximum_of_domain dc n') \\<and> derivation_append_fit (derivation_take d (Suc k)) dc n \\<and> epdaH_marking_condition M (derivation_append (derivation_take d (Suc k)) dc n))\"\n      in allE)\n  apply(rename_tac d ka k e1 w h src pop push trg a)(*strict*)\n  apply(erule impE)\n   apply(rename_tac d ka k e1 w h src pop push trg a)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d ka k e1 w h src pop push trg a)(*strict*)\n    apply(rule epdaH.derivation_take_preserves_derivation_initial)\n    apply(force)\n   apply(rename_tac d ka k e1 w h src pop push trg a)(*strict*)\n   apply(rule maximum_of_domain_derivation_take)\n   apply(force)\n  apply(rename_tac d ka k e1 w h src pop push trg a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d ka k e1 w h src pop push trg a dc n')(*strict*)\n  apply(simp add: epdaH_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e c)(*strict*)\n  apply(simp add: epdaH_marking_configurations_def)\n  apply(clarsimp)\n  apply(thin_tac \"c \\<in> epdaH_configurations M\")\n  apply(case_tac c)\n  apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e c epdaH_conf_statea epdaH_conf_historya epdaH_conf_stack)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e epdaH_conf_statea epdaH_conf_historya epdaH_conf_stack)(*strict*)\n  apply(rename_tac q1 h1 s1)\n  apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 h1 s1)(*strict*)\n  apply(case_tac \"i = Suc k\")\n   apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 h1 s1)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1)(*strict*)\n   apply(simp add: derivation_append_def derivation_append_fit_def derivation_take_def)\n   apply(clarsimp)\n   apply(rename_tac d ka k e1 w h src pop push a dc n' q1)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d ka k e1 w h src pop push a dc n' q1)(*strict*)\n    prefer 2\n    apply(rule_tac\n      M = \"M\"\n      and g = \"dc\"\n      in epdaH.some_position_has_details_at_0)\n    apply(force)\n   apply(rename_tac d ka k e1 w h src pop push a dc n' q1)(*strict*)\n   apply(clarsimp)\n   apply(erule_tac\n      x = \"Suc k\"\n      in allE)+\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 h1 s1)(*strict*)\n  apply(case_tac \"i<Suc k\")\n   apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 h1 s1)(*strict*)\n   apply(clarsimp)\n   apply(erule_tac\n      x = \"Suc k\"\n      and P = \"\\<lambda>j. \\<forall>e' c'. i < j \\<and> derivation_append (derivation_take d (Suc k)) dc (Suc k) j = Some (pair e' c') \\<longrightarrow> epdaH_string_state \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = h1, epdaH_conf_stack = s1\\<rparr> = epdaH_string_state c'\"\n      in allE)\n   apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 h1 s1)(*strict*)\n   apply(simp add: derivation_append_def derivation_append_fit_def derivation_take_def)\n   apply(simp add: epdaH_string_state_def)\n   apply(clarsimp)\n   apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 s1)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 s1)(*strict*)\n    prefer 2\n    apply(rule_tac\n      G = \"M\"\n      and d = \"d\"\n      and n = \"i\"\n      and m = \"k - i\"\n      in epdaH.steps_extend_history_derivation)\n        apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 s1)(*strict*)\n        apply(simp add: valid_dpda_def valid_pda_def)\n       apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 s1)(*strict*)\n       apply(simp add: epdaH.derivation_initial_def)\n      apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 s1)(*strict*)\n      prefer 2\n      apply(clarsimp)\n      apply(simp add: get_configuration_def)\n     apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 s1)(*strict*)\n     apply(rule_tac\n      d = \"d\"\n      in epdaH.belongs_configurations)\n      apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 s1)(*strict*)\n      apply(rule epdaH.derivation_initial_belongs)\n       apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 s1)(*strict*)\n       apply(simp add: valid_dpda_def valid_pda_def)\n      apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 s1)(*strict*)\n      apply(force)\n     apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 s1)(*strict*)\n     apply(force)\n    apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 s1)(*strict*)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 s1)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 h1 s1)(*strict*)\n  apply(subgoal_tac \"Suc k<i\")\n   apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 h1 s1)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 h1 s1)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"derivation_append (derivation_take d (Suc k)) dc (Suc k) i = dc (i-Suc k)\")\n   apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 h1 s1)(*strict*)\n   prefer 2\n   apply(simp (no_asm_use) only: derivation_append_fit_def derivation_take_def derivation_append_def)\n   apply(clarsimp)\n  apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 h1 s1)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>x. Suc k+Suc x = i\")\n   apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 h1 s1)(*strict*)\n   prefer 2\n   apply (metis add_Suc_right add_Suc_shift less_iff_Suc_add)\n  apply(rename_tac d ka k e1 w h src pop push trg a dc n' i e q1 h1 s1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n   prefer 2\n   apply(rule_tac\n      M = \"M\"\n      and g = \"dc\"\n      in epdaH.some_position_has_details_at_0)\n   apply(force)\n  apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x c)(*strict*)\n  apply(subgoal_tac \"c = \\<lparr>epdaH_conf_state = trg, epdaH_conf_history = h @ [a], epdaH_conf_stack = push @ w\\<rparr>\")\n   apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x c)(*strict*)\n   prefer 2\n   apply(simp (no_asm_use) only: derivation_append_fit_def derivation_take_def derivation_append_def)\n   apply(clarsimp)\n  apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G = \"M\"\n      and ?d1.0 = \"d\"\n      and ?d2.0 = \"derivation_append (derivation_take d (Suc k)) dc (Suc k)\"\n      and x = \"Suc k\"\n      and y = \"Suc k\"\n      and n = \"(Suc ((x)))\"\n      and m = \"(Suc ((x)))\"\n      in epdaH.is_forward_deterministicHist_derivations_coincide)\n              apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n              apply(simp add: valid_dpda_def valid_pda_def)\n             apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n             apply(force)\n            apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n            apply(rule epdaH.derivation_append_preserves_derivation_initial)\n              apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n              apply(simp add: valid_dpda_def valid_pda_def)\n             apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n             apply(rule epdaH.derivation_take_preserves_derivation_initial)\n             apply(force)\n            apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n            apply(rule epdaH.derivation_append_preserves_derivation)\n              apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n              apply(rule epdaH.derivation_take_preserves_derivation)\n              apply(rule epdaH.derivation_initial_is_derivation)\n              apply(force)\n             apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n             apply(force)\n            apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n            apply(simp add: derivation_take_def)\n           apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n           apply(rule DPDA_is_is_forward_deterministicHist_SB)\n           apply(force)\n          apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n          apply(simp add: derivation_append_def derivation_append_fit_def derivation_take_def)\n         apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n         apply(force)\n        apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n        apply(simp add: derivation_append_def derivation_append_fit_def derivation_take_def)\n       apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n       apply(force)\n      apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n      apply(force)\n     apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n     apply(force)\n    apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n     prefer 2\n     apply(rule_tac\n      G = \"M\"\n      and d = \"dc\"\n      and n = \"0\"\n      and m = \"Suc x\"\n      in epdaH.steps_extend_history_derivation)\n         apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n         apply(simp add: valid_dpda_def valid_pda_def)\n        apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n        apply(force)\n       apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n       prefer 2\n       apply(clarsimp)\n       apply(simp add: get_configuration_def)\n      apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n      apply(rule_tac\n      d = \"dc\"\n      in epdaH.belongs_configurations)\n       apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n       apply(force)\n      apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n      apply(force)\n     apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n     apply(simp (no_asm_use) only: derivation_append_fit_def derivation_take_def derivation_append_def)\n     apply(clarsimp)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n    apply(simp add: get_configuration_def)\n    apply(clarsimp)\n   apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n   apply(simp (no_asm_use) only: derivation_append_fit_def derivation_take_def derivation_append_def)\n   apply(force)\n  apply(rename_tac d ka k e1 w h src pop push trg a dc n' e q1 h1 s1 x)(*strict*)\n  apply(erule_tac\n      x = \"Suc (Suc(k+x))\"\n      in allE)+\n  apply(clarsimp)\n  apply(simp add: get_configuration_def)\n  done\n\ntheorem epdaS_to_epdaHS_accessible: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.accessible G\n  \\<Longrightarrow> epdaHS.accessible G\"\n  apply(simp add: epdaHS.accessible_def epdaS.accessible_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(subgoal_tac \"x \\<in> epdaS.get_accessible_destinations G\")\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(thin_tac \"epda_destinations G \\<subseteq> epdaS.get_accessible_destinations G\")\n  apply(rename_tac x)(*strict*)\n  apply(thin_tac \"x \\<in> epda_destinations G\")\n  apply(simp add: epdaS.get_accessible_destinations_def epdaHS.get_accessible_destinations_def)\n  apply(clarsimp)\n  apply(rename_tac x d i e c)(*strict*)\n  apply(simp add: epdaS_get_destinations_def)\n  apply(case_tac c)\n  apply(rename_tac x d i e c epdaS_conf_statea epdaS_conf_scheduler epdaS_conf_stack)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d i e epdaS_conf_state epdaS_conf_scheduler epdaS_conf_stack)(*strict*)\n  apply(rename_tac n e q i s)\n  apply(rename_tac x d n e q i s)(*strict*)\n  apply(rule_tac\n      x = \"epdaS2epdaHS_derivation G d\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac x d n e q i s)(*strict*)\n   apply(rule epdaS2epdaHS_derivation_preserves_derivation_initial)\n    apply(rename_tac x d n e q i s)(*strict*)\n    apply(simp add: valid_dpda_def valid_pda_def)\n   apply(rename_tac x d n e q i s)(*strict*)\n   apply(force)\n  apply(rename_tac x d n e q i s)(*strict*)\n  apply(rule_tac\n      x = \"n\"\n      in exI)\n  apply(simp add: epdaS2epdaHS_derivation_def epdaHS_get_destinations_def)\n  done\n\ntheorem epdaHS_to_epdaH_accessible: \"\n  valid_epda G\n  \\<Longrightarrow> epdaHS.accessible G\n  \\<Longrightarrow> epdaH.accessible G\"\n  apply(simp add: epdaHS.accessible_def epdaH.accessible_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(subgoal_tac \"x \\<in> epdaHS.get_accessible_destinations G\")\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(thin_tac \"epda_destinations G \\<subseteq> epdaHS.get_accessible_destinations G\")\n  apply(rename_tac x)(*strict*)\n  apply(thin_tac \"x \\<in> epda_destinations G\")\n  apply(simp add: epdaH.get_accessible_destinations_def epdaHS.get_accessible_destinations_def)\n  apply(clarsimp)\n  apply(rename_tac x d i e c)(*strict*)\n  apply(simp add: epdaHS_get_destinations_def)\n  apply(case_tac c)\n  apply(rename_tac x d i e c epdaHS_conf_statea epdaHS_conf_history epdaHS_conf_scheduler epdaHS_conf_stack)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d i e epdaHS_conf_state epdaHS_conf_history epdaHS_conf_scheduler epdaHS_conf_stack)(*strict*)\n  apply(rename_tac n e q i s)\n  apply(rename_tac x d ia n e q i s)(*strict*)\n  apply(rule_tac\n      x = \"epdaH_vs_epdaHS.Lin2BraDer d\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac x d ia n e q i s)(*strict*)\n   apply(rule epdaH_vs_epdaHS.Lin2BraConf_preserves_initiality_lift)\n    apply(rename_tac x d ia n e q i s)(*strict*)\n    apply(simp add: valid_dpda_def valid_pda_def)\n   apply(rename_tac x d ia n e q i s)(*strict*)\n   apply(force)\n  apply(rename_tac x d ia n e q i s)(*strict*)\n  apply(rule_tac\n      x = \"ia\"\n      in exI)\n  apply(simp add: epdaHvHS_Lin2BraConf_def derivation_map_def epdaH_vs_epdaHS.Lin2BraDer_def epdaH_get_destinations_def)\n  done\n\ntheorem epdaS_to_epdaH_accessible: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.accessible G\n  \\<Longrightarrow> epdaH.accessible G\"\n  apply (metis epdaHS_to_epdaH_accessible epdaS_to_epdaHS_accessible)\n  done\n\ndefinition only_executing_edges_from_marking_states :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"only_executing_edges_from_marking_states G \\<equiv>\n  \\<forall>e \\<in> epda_delta G.\n  edge_event e = None\n  \\<longrightarrow> edge_src e \\<notin> epda_marking G\"\n\nlemma epda_no_empty_steps_from_marking_states__vs__only_executing_edges_from_marking_states: \"\n  valid_epda G\n  \\<Longrightarrow> epda_no_empty_steps_from_marking_states G \\<longleftrightarrow> only_executing_edges_from_marking_states G\"\n  apply(simp add: epda_no_empty_steps_from_marking_states_def only_executing_edges_from_marking_states_def)\n  apply(rule antisym)\n   apply(clarsimp)\n   apply(force)\n  apply(clarsimp)\n  apply(force)\n  done\n\nlemma DPDA_only_executing_edges_from_marking_states_implies_epdaH_non_ambiguous_hlp: \"\n  valid_dpda G\n  \\<Longrightarrow> only_executing_edges_from_marking_states G\n  \\<Longrightarrow> epdaH.derivation_initial G d1\n  \\<Longrightarrow> epdaH.derivation_initial G d2\n  \\<Longrightarrow> q1 \\<in> epda_marking G\n  \\<Longrightarrow> q2 \\<in> epda_marking G\n  \\<Longrightarrow> d1 0 = d2 0\n  \\<Longrightarrow> d1 n1 = Some (pair option \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = h, epdaH_conf_stack = s1\\<rparr>)\n  \\<Longrightarrow> d2 n2 = Some (pair optiona \\<lparr>epdaH_conf_state = q2, epdaH_conf_history = h, epdaH_conf_stack = s2\\<rparr>)\n  \\<Longrightarrow> n1 \\<le> n2\n  \\<Longrightarrow> d2 n1 = Some (pair option \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = h, epdaH_conf_stack = s1\\<rparr>)\n  \\<Longrightarrow> n1 < n2\n  \\<Longrightarrow> False\"\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac\n      d = \"d2\"\n      and n = \"n1\"\n      and m = \"n2\"\n      in epdaH.step_detail_before_some_position)\n     apply(simp add: epdaH.derivation_initial_def)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac e2 c2)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac e2 c2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G = \"G\"\n      and n = \"Suc n1\"\n      and m = \"n2-Suc n1\"\n      in epdaH.steps_extend_history_derivation)\n       apply(rename_tac e2 c2)(*strict*)\n       apply(simp add: valid_dpda_def valid_pda_def)\n      apply(rename_tac e2 c2)(*strict*)\n      apply(simp add: epdaH.derivation_initial_def)\n     apply(rename_tac e2 c2)(*strict*)\n     prefer 2\n     apply(clarsimp)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac e2 c2)(*strict*)\n    apply(rule_tac\n      d = \"d2\"\n      in epdaH.belongs_configurations)\n     apply(rename_tac e2 c2)(*strict*)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(rename_tac e2 c2)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def)\n     apply(rename_tac e2 c2)(*strict*)\n     apply(force)\n    apply(rename_tac e2 c2)(*strict*)\n    apply(force)\n   apply(rename_tac e2 c2)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac e2 c2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac e2 c2 h)(*strict*)\n  apply(simp add: epdaH_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac e2 c2 w)(*strict*)\n  apply(case_tac c2)\n  apply(rename_tac e2 c2 w epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac e2 w epdaH_conf_history)(*strict*)\n  apply(rename_tac h)\n  apply(rename_tac e2 w h)(*strict*)\n  apply(case_tac e2)\n  apply(rename_tac e2 w h edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac w h edge_src edge_event edge_pop edge_push edge_trg)(*strict*)\n  apply(rename_tac qs re po pu qt)\n  apply(rename_tac w h qs re po pu qt)(*strict*)\n  apply(case_tac re)\n   apply(rename_tac w h qs re po pu qt)(*strict*)\n   prefer 2\n   apply(rename_tac w h qs re po pu qt a)(*strict*)\n   apply(simp add: option_to_list_def)\n  apply(rename_tac w h qs re po pu qt)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac w h qs po pu qt)(*strict*)\n  apply(simp add: only_executing_edges_from_marking_states_def)\n  apply(erule_tac\n      x = \"\\<lparr>edge_src = qs, edge_event = None, edge_pop = po, edge_push = pu, edge_trg = qt\\<rparr>\"\n      in ballE)\n   apply(rename_tac w h qs po pu qt)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac w h qs po pu qt)(*strict*)\n  apply(force)\n  done\n\ntheorem DPDA_only_executing_edges_from_marking_states_implies_epdaH_non_ambiguous: \"\n  valid_dpda G\n  \\<Longrightarrow> only_executing_edges_from_marking_states G\n  \\<Longrightarrow> epdaH_non_ambiguous G\"\n  apply(simp add: epdaH_non_ambiguous_def)\n  apply(clarsimp)\n  apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2)(*strict*)\n  apply(subgoal_tac \"d1 0 = d2 0\")\n   apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2)(*strict*)\n   prefer 2\n   apply(simp add: epdaH.derivation_initial_def)\n   apply(case_tac \"d1 0\")\n    apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 b)(*strict*)\n   apply(case_tac \"d2 0\")\n    apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 b)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 b a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 b a option ba)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 b ba)(*strict*)\n   apply(simp add: epdaH_initial_configurations_def)\n  apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2)(*strict*)\n  apply(case_tac \"d1 n1\")\n   apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 a)(*strict*)\n  apply(case_tac a)\n  apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 option b)(*strict*)\n  apply(case_tac \"d2 n2\")\n   apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 option b)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 option b a)(*strict*)\n  apply(case_tac a)\n  apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 option b a optiona ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 option b optiona ba)(*strict*)\n  apply(subgoal_tac \"b = \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = h, epdaH_conf_stack = s1\\<rparr>\")\n   apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 option b optiona ba)(*strict*)\n   prefer 2\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 option b optiona ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 option optiona ba)(*strict*)\n  apply(thin_tac \"get_configuration (Some (pair option \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = h, epdaH_conf_stack = s1\\<rparr>)) = Some \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = h, epdaH_conf_stack = s1\\<rparr>\")\n  apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 option optiona ba)(*strict*)\n  apply(subgoal_tac \"ba = \\<lparr>epdaH_conf_state = q2, epdaH_conf_history = h, epdaH_conf_stack = s2\\<rparr>\")\n   apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 option optiona ba)(*strict*)\n   prefer 2\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 option optiona ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 option optiona)(*strict*)\n  apply(thin_tac \"get_configuration (Some (pair optiona \\<lparr>epdaH_conf_state = q2, epdaH_conf_history = h, epdaH_conf_stack = s2\\<rparr>)) = Some \\<lparr>epdaH_conf_state = q2, epdaH_conf_history = h, epdaH_conf_stack = s2\\<rparr>\")\n  apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 option optiona)(*strict*)\n  apply(rename_tac e1 e2)\n  apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n  apply(subgoal_tac \"n1 = n2\")\n   apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n   prefer 2\n   apply(case_tac \"n1<n2\")\n    apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n    apply(subgoal_tac \"False\")\n     apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n     apply(force)\n    apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n     prefer 2\n     apply(rule_tac\n      G = \"G\"\n      and ?d1.0 = \"d1\"\n      and ?d2.0 = \"d2\"\n      and x = \"0\"\n      and y = \"0\"\n      and n = \"n1\"\n      and m = \"n2\"\n      in epdaH.is_forward_deterministicHist_derivations_coincide)\n                apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n                apply(simp add: valid_dpda_def valid_pda_def)\n               apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n               apply(force)\n              apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n              apply(force)\n             apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n             apply (metis DPDA_is_is_forward_deterministicHist_SB)\n            apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n            apply(simp add: epdaH.derivation_initial_def)\n           apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n           apply(force)\n          apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n          apply(force)\n         apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n         apply(force)\n        apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n        apply(force)\n       apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n       apply(force)\n      apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n      apply(clarsimp)\n      apply(simp add: epda_effects_def)\n      apply(simp add: get_configuration_def)\n     apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n     apply(simp)\n    apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n    apply(clarsimp)\n    apply(case_tac \"d2 n1\")\n     apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2 a)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n    apply(rule_tac\n      ?q1.0 = \"q1\"\n      and ?q2.0 = \"q2\"\n      and ?d1.0 = \"d1\"\n      and ?d2.0 = \"d2\"\n      and ?n1.0 = \"n1\"\n      and ?n2.0 = \"n2\"\n      in DPDA_only_executing_edges_from_marking_states_implies_epdaH_non_ambiguous_hlp)\n               apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n               apply(force)\n              apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n              apply(force)\n             apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n             apply(force)\n            apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n            apply(force)\n           apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n           apply(force)\n          apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n          apply(force)\n         apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n         apply(force)\n        apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n        apply(force)\n       apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n       apply(force)\n      apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n      apply(force)\n     apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n     apply(force)\n    apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n    apply(force)\n   apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n   apply(case_tac \"n2<n1\")\n    apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n    apply(thin_tac \"\\<not> n1 < n2\")\n    apply(subgoal_tac \"False\")\n     apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n     apply(force)\n    apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n     prefer 2\n     apply(rule_tac\n      G = \"G\"\n      and ?d1.0 = \"d2\"\n      and ?d2.0 = \"d1\"\n      and x = \"0\"\n      and y = \"0\"\n      and n = \"n2\"\n      and m = \"n1\"\n      in epdaH.is_forward_deterministicHist_derivations_coincide)\n                apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n                apply(simp add: valid_dpda_def valid_pda_def)\n               apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n               apply(force)\n              apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n              apply(force)\n             apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n             apply (metis DPDA_is_is_forward_deterministicHist_SB)\n            apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n            apply(simp add: epdaH.derivation_initial_def)\n           apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n           apply(force)\n          apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n          apply(force)\n         apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n         apply(force)\n        apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n        apply(force)\n       apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n       apply(force)\n      apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n      apply(clarsimp)\n      apply(simp add: epda_effects_def)\n      apply(simp add: get_configuration_def)\n     apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n     apply(simp)\n    apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n    apply(clarsimp)\n    apply(case_tac \"d1 n2\")\n     apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2 a)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n    apply(rule_tac\n      ?q1.0 = \"q2\"\n      and ?q2.0 = \"q1\"\n      and ?d1.0 = \"d2\"\n      and ?d2.0 = \"d1\"\n      and ?n1.0 = \"n2\"\n      and ?n2.0 = \"n1\"\n      in DPDA_only_executing_edges_from_marking_states_implies_epdaH_non_ambiguous_hlp)\n               apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n               apply(force)\n              apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n              apply(force)\n             apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n             apply(force)\n            apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n            apply(force)\n           apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n           apply(force)\n          apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n          apply(force)\n         apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n         apply(force)\n        apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n        apply(force)\n       apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n       apply(force)\n      apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n      apply(force)\n     apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n     apply(force)\n    apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n    apply(force)\n   apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n   apply(force)\n  apply(rename_tac d1 d2 n1 n2 q1 q2 h s1 s2 e1 e2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i)(*strict*)\n   prefer 2\n   apply(rule_tac\n      g = \"d1\"\n      and n = \"i\"\n      and m = \"n2\"\n      in epdaH.pre_some_position_is_some_position)\n     apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n     apply(force)\n    apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i)(*strict*)\n    apply(force)\n   apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i)(*strict*)\n   apply(force)\n  apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i)(*strict*)\n   prefer 2\n   apply(rule_tac\n      g = \"d2\"\n      and n = \"i\"\n      and m = \"n2\"\n      in epdaH.pre_some_position_is_some_position)\n     apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n    apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i)(*strict*)\n    apply(force)\n   apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i)(*strict*)\n   apply(force)\n  apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i e ea c ca)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i e ea c ca)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G = \"G\"\n      and n = \"i\"\n      and m = \"n2-i\"\n      in epdaH.steps_extend_history_derivation)\n       apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i e ea c ca)(*strict*)\n       apply(simp add: valid_dpda_def valid_pda_def)\n      apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i e ea c ca)(*strict*)\n      apply(simp add: epdaH.derivation_initial_def)\n     apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i e ea c ca)(*strict*)\n     prefer 2\n     apply(clarsimp)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i e ea c ca)(*strict*)\n    apply(rule_tac\n      d = \"d2\"\n      in epdaH.belongs_configurations)\n     apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i e ea c ca)(*strict*)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i e ea c ca)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def)\n     apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i e ea c ca)(*strict*)\n     apply(force)\n    apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i e ea c ca)(*strict*)\n    apply(force)\n   apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i e ea c ca)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i e ea c ca)(*strict*)\n  apply(case_tac \"d2 0\")\n   apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i e ea c ca)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca ha)(*strict*)\n   apply(simp add: epdaH.derivation_initial_def)\n  apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i e ea c ca a)(*strict*)\n  apply(case_tac a)\n  apply(rename_tac d1 d2 n2 q1 q2 h s1 s2 e1 e2 i e ea c ca a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G = \"G\"\n      and n = \"0\"\n      and m = \"i\"\n      in epdaH.steps_extend_history_derivation)\n       apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n       apply(simp add: valid_dpda_def valid_pda_def)\n      apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n      apply(simp add: epdaH.derivation_initial_def)\n     apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n     prefer 2\n     apply(clarsimp)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n    apply(rule_tac\n      d = \"d2\"\n      in epdaH.belongs_configurations)\n     apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def)\n     apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n     apply(force)\n    apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n    apply(force)\n   apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G = \"G\"\n      and d = \"d1\"\n      and n = \"i\"\n      and m = \"n2-i\"\n      in epdaH.steps_extend_history_derivation)\n       apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n       apply(simp add: valid_dpda_def valid_pda_def)\n      apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n      apply(simp add: epdaH.derivation_initial_def)\n     apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n     prefer 2\n     apply(clarsimp)\n     apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha h)(*strict*)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n    apply(rule_tac\n      d = \"d1\"\n      in epdaH.belongs_configurations)\n     apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def)\n     apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n     apply(force)\n    apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n    apply(force)\n   apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n  apply(case_tac \"d1 0\")\n   apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha a)(*strict*)\n  apply(case_tac a)\n  apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha a optiona ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha h hb)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha h hb)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G = \"G\"\n      and n = \"0\"\n      and m = \"i\"\n      in epdaH.steps_extend_history_derivation)\n       apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha h hb)(*strict*)\n       apply(simp add: valid_dpda_def valid_pda_def)\n      apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha h hb)(*strict*)\n      apply(simp add: epdaH.derivation_initial_def)\n     apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha h hb)(*strict*)\n     prefer 2\n     apply(clarsimp)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha h hb)(*strict*)\n    apply(rule_tac\n      d = \"d1\"\n      in epdaH.belongs_configurations)\n     apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha h hb)(*strict*)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha h hb)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def)\n     apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha h hb)(*strict*)\n     apply(force)\n    apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha h hb)(*strict*)\n    apply(force)\n   apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha h hb)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha h hb)(*strict*)\n  apply(clarsimp)\n  apply(case_tac ca)\n  apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha h hb epdaH_conf_state epdaH_conf_historya epdaH_conf_stack)(*strict*)\n  apply(case_tac b)\n  apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c ca option b ha h hb epdaH_conf_state epdaH_conf_historya epdaH_conf_stack epdaH_conf_statea epdaH_conf_historyaa epdaH_conf_stacka)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c option ha h hb epdaH_conf_state epdaH_conf_stack epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n  apply(case_tac c)\n  apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea c option ha h hb epdaH_conf_state epdaH_conf_stack epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka epdaH_conf_stateb epdaH_conf_historyb epdaH_conf_stackb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1 e2 i e ea option ha h hb epdaH_conf_state epdaH_conf_stack epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka epdaH_conf_stateb epdaH_conf_history epdaH_conf_stackb)(*strict*)\n  apply(rename_tac e1 ha h hb qx1 sx1 qx2 hx2 sx3 qs5 h4 s3)\n  apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha h hb qx1 sx1 qx2 hx2 sx3 qs5 h4 s3)(*strict*)\n  apply(subgoal_tac \"hx2 = []\")\n   apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha h hb qx1 sx1 qx2 hx2 sx3 qs5 h4 s3)(*strict*)\n   prefer 2\n   apply(simp add: epdaH.derivation_initial_def epdaH_initial_configurations_def)\n  apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha h hb qx1 sx1 qx2 hx2 sx3 qs5 h4 s3)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha h hb qx1 sx1 qx2 sx3 qs5 h4 s3)(*strict*)\n  apply(subgoal_tac \"prefix h h4 \\<or> SSX\" for SSX)\n   apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha h hb qx1 sx1 qx2 sx3 qs5 h4 s3)(*strict*)\n   prefer 2\n   apply(rule mutual_prefix_prefix)\n   apply(force)\n  apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha h hb qx1 sx1 qx2 sx3 qs5 h4 s3)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha h hb qx1 sx1 qx2 sx3 qs5 h4 s3)(*strict*)\n   prefer 2\n   apply(simp add: prefix_def)\n   apply(clarsimp)\n   apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha qx1 sx1 qx2 sx3 qs5 h4 s3 c)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha qx1 sx1 qx2 sx3 qs5 h4 s3 c)(*strict*)\n    prefer 2\n    apply(rule_tac\n      G = \"G\"\n      and ?d1.0 = \"d1\"\n      and ?d2.0 = \"d2\"\n      and x = \"0\"\n      and y = \"0\"\n      and n = \"i\"\n      and m = \"i\"\n      in epdaH.is_forward_deterministicHist_derivations_coincide)\n               apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha qx1 sx1 qx2 sx3 qs5 h4 s3 c)(*strict*)\n               apply(simp add: valid_dpda_def valid_pda_def)\n              apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha qx1 sx1 qx2 sx3 qs5 h4 s3 c)(*strict*)\n              apply(force)\n             apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha qx1 sx1 qx2 sx3 qs5 h4 s3 c)(*strict*)\n             apply(force)\n            apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha qx1 sx1 qx2 sx3 qs5 h4 s3 c)(*strict*)\n            apply (metis DPDA_is_is_forward_deterministicHist_SB)\n           apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha qx1 sx1 qx2 sx3 qs5 h4 s3 c)(*strict*)\n           apply(simp add: epdaH.derivation_initial_def)\n          apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha qx1 sx1 qx2 sx3 qs5 h4 s3 c)(*strict*)\n          apply(force)\n         apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha qx1 sx1 qx2 sx3 qs5 h4 s3 c)(*strict*)\n         apply(force)\n        apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha qx1 sx1 qx2 sx3 qs5 h4 s3 c)(*strict*)\n        apply(force)\n       apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha qx1 sx1 qx2 sx3 qs5 h4 s3 c)(*strict*)\n       apply(force)\n      apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha qx1 sx1 qx2 sx3 qs5 h4 s3 c)(*strict*)\n      apply(force)\n     apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha qx1 sx1 qx2 sx3 qs5 h4 s3 c)(*strict*)\n     apply(clarsimp)\n     apply(simp add: epda_effects_def)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha qx1 sx1 qx2 sx3 qs5 h4 s3 c)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha qx1 sx1 qx2 sx3 qs5 h4 s3 c)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 ha h hb qx1 sx1 qx2 sx3 qs5 h4 s3)(*strict*)\n  apply(simp add: prefix_def)\n  apply(clarsimp)\n  apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 h hb qx1 sx1 qx2 sx3 qs5 s3 c)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 h hb qx1 sx1 qx2 sx3 qs5 s3 c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G = \"G\"\n      and ?d1.0 = \"d2\"\n      and ?d2.0 = \"d1\"\n      and x = \"0\"\n      and y = \"0\"\n      and n = \"i\"\n      and m = \"i\"\n      in epdaH.is_forward_deterministicHist_derivations_coincide)\n              apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 h hb qx1 sx1 qx2 sx3 qs5 s3 c)(*strict*)\n              apply(simp add: valid_dpda_def valid_pda_def)\n             apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 h hb qx1 sx1 qx2 sx3 qs5 s3 c)(*strict*)\n             apply(force)\n            apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 h hb qx1 sx1 qx2 sx3 qs5 s3 c)(*strict*)\n            apply(force)\n           apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 h hb qx1 sx1 qx2 sx3 qs5 s3 c)(*strict*)\n           apply (metis DPDA_is_is_forward_deterministicHist_SB)\n          apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 h hb qx1 sx1 qx2 sx3 qs5 s3 c)(*strict*)\n          apply(simp add: epdaH.derivation_initial_def)\n         apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 h hb qx1 sx1 qx2 sx3 qs5 s3 c)(*strict*)\n         apply(force)\n        apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 h hb qx1 sx1 qx2 sx3 qs5 s3 c)(*strict*)\n        apply(force)\n       apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 h hb qx1 sx1 qx2 sx3 qs5 s3 c)(*strict*)\n       apply(force)\n      apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 h hb qx1 sx1 qx2 sx3 qs5 s3 c)(*strict*)\n      apply(force)\n     apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 h hb qx1 sx1 qx2 sx3 qs5 s3 c)(*strict*)\n     apply(force)\n    apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 h hb qx1 sx1 qx2 sx3 qs5 s3 c)(*strict*)\n    apply(clarsimp)\n    apply(simp add: epda_effects_def)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 h hb qx1 sx1 qx2 sx3 qs5 s3 c)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d1 d2 n2 q1 q2 s1 s2 e1a e2 i e ea e1 h hb qx1 sx1 qx2 sx3 qs5 s3 c)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma DFA_one_symbol_per_step: \"\n  valid_dfa G\n  \\<Longrightarrow> epdaH.derivation_initial G d\n  \\<Longrightarrow> d n = Some (pair e c)\n  \\<Longrightarrow> length(epdaH_conf_history c) = n\"\n  apply(induct n arbitrary: e c)\n   apply(rename_tac e c)(*strict*)\n   apply(clarsimp)\n   apply(simp add: epdaH.derivation_initial_def epdaH_initial_configurations_def)\n  apply(rename_tac n e c)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac n e c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G = \"G\"\n      and d = \"d\"\n      and n = \"n\"\n      and m = \"Suc n\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac n e c)(*strict*)\n     apply(rule epdaH.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac n e c)(*strict*)\n    apply(force)\n   apply(rename_tac n e c)(*strict*)\n   apply(force)\n  apply(rename_tac n e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n c e1 e2 c1)(*strict*)\n  apply(simp add: epdaH_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac n c e1 e2 c1 w)(*strict*)\n  apply(erule_tac\n      x = \"e1\"\n      in meta_allE)\n  apply(erule_tac\n      x = \"c1\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(rename_tac c e1 e2 c1 w)(*strict*)\n  apply(case_tac e2)\n  apply(rename_tac c e1 e2 c1 w edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c e1 c1 w edge_event edge_pop edge_push)(*strict*)\n  apply(case_tac edge_event)\n   apply(rename_tac c e1 c1 w edge_event edge_pop edge_push)(*strict*)\n   prefer 2\n   apply(rename_tac c e1 c1 w edge_event edge_pop edge_push a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c e1 c1 w edge_pop edge_push a)(*strict*)\n   apply(simp add: option_to_list_def)\n  apply(rename_tac c e1 c1 w edge_event edge_pop edge_push)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c e1 c1 w edge_pop edge_push)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(simp add: valid_dfa_def)\n  apply(rename_tac c e1 c1 w edge_popa edge_pusha)(*strict*)\n  apply(force)\n  done\n\nlemma DFA_stack_consists_only_of_box: \"\n  valid_dfa G\n  \\<Longrightarrow> epdaH.derivation_initial G d\n  \\<Longrightarrow> d n = Some (pair e c)\n  \\<Longrightarrow> epdaH_conf_stack c = [epda_box G]\"\n  apply(induct n arbitrary: e c)\n   apply(rename_tac e c)(*strict*)\n   apply(simp add: epdaH.derivation_initial_def epdaH_initial_configurations_def)\n  apply(rename_tac n e c)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac n e c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G = \"G\"\n      and d = \"d\"\n      and n = \"n\"\n      and m = \"Suc n\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac n e c)(*strict*)\n     apply(rule epdaH.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac n e c)(*strict*)\n    apply(force)\n   apply(rename_tac n e c)(*strict*)\n   apply(force)\n  apply(rename_tac n e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n c e1 e2 c1)(*strict*)\n  apply(simp add: epdaH_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac n c e1 e2 c1 w)(*strict*)\n  apply(erule_tac\n      x = \"e1\"\n      in meta_allE)\n  apply(erule_tac\n      x = \"c1\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(case_tac e2)\n  apply(rename_tac n c e1 e2 c1 w edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n c e1 c1 w edge_event edge_pop edge_push)(*strict*)\n  apply(simp add: valid_dfa_def valid_dpda_def valid_pda_def)\n  apply(rename_tac n c e1 c1 w edge_eventa edge_popa edge_pusha)(*strict*)\n  apply(clarsimp)\n  apply(erule_tac\n      x = \"\\<lparr>edge_src = epdaH_conf_state c1, edge_event = edge_eventa, edge_pop = edge_popa, edge_push = edge_pusha, edge_trg = epdaH_conf_state c\\<rparr>\"\n      in ballE)\n   apply(rename_tac n c e1 c1 w edge_eventa edge_popa edge_pusha)(*strict*)\n   prefer 2\n   apply(rename_tac n c e1 c1 w edge_event edge_pop edge_push)(*strict*)\n   apply(force)\n  apply(rename_tac n c e1 c1 w edge_eventa edge_popa edge_pusha)(*strict*)\n  apply(clarsimp)\n  done\n\ndefinition epda_operational_controllable ::\n  \"('spec_state, 'event, 'gamma) epda\n  \\<Rightarrow> ('plant_state, 'event, 'gamma_unused) epda\n  \\<Rightarrow> 'event set\n  \\<Rightarrow> bool\"\n  where\n    \"epda_operational_controllable S P SigmaUC \\<equiv>\n  \\<forall>d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u.\n  epdaH.derivation_initial S d1\n  \\<longrightarrow> d1 n1 = Some (pair e1 c1)\n  \\<longrightarrow> epdaH.derivation_initial P d2\n  \\<longrightarrow> d2 n2 = Some (pair e2 c2)\n  \\<longrightarrow> d2 (Suc n2) = Some (pair e2' c2')\n  \\<longrightarrow> epdaH_conf_history c1 = epdaH_conf_history c2\n  \\<longrightarrow> epdaH_conf_history c2' = epdaH_conf_history c2 @ [u]\n  \\<longrightarrow> u \\<in> SigmaUC\n  \\<longrightarrow> (\\<exists>dc nC eC cC.\n        epdaH.derivation S dc\n        \\<and> dc 0 = Some (pair None c1)\n        \\<and> dc nC = Some (pair eC cC)\n        \\<and> epdaH_conf_history cC = epdaH_conf_history c2')\"\n\ndefinition epda_to_des :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> 'event DES\"\n  where\n    \"epda_to_des G \\<equiv>\n  DES (epdaH.unmarked_language G) (epdaH.marked_language G)\"\n\nlemma epdaS_epda_sub_preserves_derivation: \"\n  valid_epda G1\n  \\<Longrightarrow> valid_epda G2\n  \\<Longrightarrow> epda_sub G1 G2\n  \\<Longrightarrow> epdaS.derivation G1 d\n  \\<Longrightarrow> epdaS.derivation G2 d\"\n  apply(simp (no_asm) add: epdaS.derivation_def)\n  apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(case_tac i)\n   apply(rename_tac i)(*strict*)\n   apply(simp add: epdaS.derivation_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x = \"0\"\n      in allE)\n   apply(clarsimp)\n  apply(rename_tac i nat)(*strict*)\n  apply(case_tac \"d(Suc nat)\")\n   apply(rename_tac i nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac i nat a)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac i nat a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      n = \"nat\"\n      and m = \"Suc nat\"\n      and G = \"G1\"\n      in epdaS.step_detail_before_some_position)\n     apply(rename_tac i nat a)(*strict*)\n     apply(force)\n    apply(rename_tac i nat a)(*strict*)\n    apply(force)\n   apply(rename_tac i nat a)(*strict*)\n   apply(force)\n  apply(rename_tac i nat a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat e1 e2 c1 c2)(*strict*)\n  apply(simp add: epdaS_step_relation_def epda_sub_def)\n  apply(clarsimp)\n  apply(rename_tac nat e1 e2 c1 c2 w)(*strict*)\n  apply(force)\n  done\n\nlemma epdaS_epda_sub_preserves_derivation_initial: \"\n  valid_epda G1\n  \\<Longrightarrow> valid_epda G2\n  \\<Longrightarrow> epda_sub G1 G2\n  \\<Longrightarrow> epdaS.derivation_initial G1 d\n  \\<Longrightarrow> epdaS.derivation_initial G2 d\"\n  apply(subgoal_tac \"epdaS.derivation G2 d\")\n   prefer 2\n   apply(rule epdaS_epda_sub_preserves_derivation)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(simp add: epdaS.derivation_initial_def)\n  apply(simp add: epdaS.derivation_initial_def)\n  apply(clarsimp)\n  apply(case_tac \"d 0\")\n   apply(clarsimp)\n  apply(rename_tac a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac b)(*strict*)\n  apply(simp add: epdaS_initial_configurations_def epdaS_configurations_def epda_sub_def)\n  apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(force)\n  done\n\nlemma epda_sub_preserves_is_forward_edge_deterministic_accessible: \"\n  valid_dpda G\n  \\<Longrightarrow> valid_pda G'\n  \\<Longrightarrow> epda_sub G' G\n  \\<Longrightarrow> epdaS.is_forward_edge_deterministic_accessible G'\"\n  apply(simp add: valid_dpda_def epdaS.is_forward_edge_deterministic_accessible_def)\n  apply(clarsimp)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(erule_tac\n      x = \"c\"\n      in ballE)\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   apply(erule_tac\n      x = \"c1\"\n      in allE)\n   apply(erule_tac\n      x = \"c2\"\n      in allE)\n   apply(erule_tac\n      x = \"e1\"\n      in allE)\n   apply(erule_tac\n      x = \"e2\"\n      in allE)\n   apply(erule impE)\n    apply(rename_tac c c1 c2 e1 e2)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   apply(simp add: epdaS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac c c1 c2 e1 e2 w wa)(*strict*)\n   apply(simp add: epda_sub_def)\n   apply(clarsimp)\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(simp add: epdaS.get_accessible_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac c c1 c2 e1 e2 d i)(*strict*)\n  apply(erule_tac\n      x = \"d\"\n      in allE)\n  apply(case_tac \"d i\")\n   apply(rename_tac c c1 c2 e1 e2 d i)(*strict*)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac c c1 c2 e1 e2 d i a)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(case_tac a)\n  apply(rename_tac c c1 c2 e1 e2 d i a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c c1 c2 e1 e2 d i option)(*strict*)\n  apply(rename_tac e)\n  apply(rename_tac c c1 c2 e1 e2 d i e)(*strict*)\n  apply(erule impE)\n   apply(rename_tac c c1 c2 e1 e2 d i e)(*strict*)\n   prefer 2\n   apply(erule_tac\n      x = \"i\"\n      in allE)\n   apply(clarsimp)\n  apply(rename_tac c c1 c2 e1 e2 d i e)(*strict*)\n  apply(rule epdaS_epda_sub_preserves_derivation_initial)\n     apply(rename_tac c c1 c2 e1 e2 d i e)(*strict*)\n     prefer 3\n     apply(force)\n    apply(rename_tac c c1 c2 e1 e2 d i e)(*strict*)\n    apply(simp add: valid_pda_def)\n   apply(rename_tac c c1 c2 e1 e2 d i e)(*strict*)\n   apply(simp add: valid_pda_def)\n  apply(rename_tac c c1 c2 e1 e2 d i e)(*strict*)\n  apply(force)\n  done\n\nlemma epdaS_to_epdaHS_unmarked_language: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.unmarked_language G = epdaHS.unmarked_language G\"\n  apply(rule order_antisym)\n   apply(rule_tac\n      t = \"epdaS.unmarked_language G\"\n      and s = \"epdaS.finite_unmarked_language G\"\n      in ssubst)\n    apply (metis epdaS_inst_AX_unmarked_language_finite)\n   apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac x)(*strict*)\n    prefer 2\n    apply(rule_tac\n      ?o1.0 = \"x\"\n      in epdaS_vs_epdaHS.ATS_Bisimulation_Derivation_Strong1_unmarked_language_translation1)\n     apply(rename_tac x)(*strict*)\n     apply(force)\n    apply(rename_tac x)(*strict*)\n    apply(force)\n   apply(rename_tac x)(*strict*)\n   apply(clarsimp)\n  apply(rule_tac\n      t = \"epdaHS.unmarked_language G\"\n      and s = \"epdaHS.finite_unmarked_language G\"\n      in ssubst)\n   apply (metis epdaHS_inst_AX_unmarked_language_finite)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(rule_tac\n      ?o2.0 = \"x\"\n      in epdaS_vs_epdaHS.ATS_Bisimulation_Derivation_Strong1_unmarked_language_translation2)\n    apply(rename_tac x)(*strict*)\n    apply(force)\n   apply(rename_tac x)(*strict*)\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma epdaH_to_epdaHS_unmarked_language: \"\n  valid_epda G\n  \\<Longrightarrow> epdaH.unmarked_language G = epdaHS.unmarked_language G\"\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule epdaH_vs_epdaHS_Nonblockingness_and_lang_transfer)\n   apply(force)\n  apply(force)\n  done\n\nlemma epdaS_to_epdaH_unmarked_language: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.unmarked_language G = epdaH.unmarked_language G\"\n  apply(rule_tac\n      t = \"epdaS.unmarked_language G\"\n      and s = \"epdaHS.unmarked_language G\"\n      in ssubst)\n   apply(rule epdaS_to_epdaHS_unmarked_language)\n   apply(force)\n  apply(rule sym)\n  apply(rule epdaH_to_epdaHS_unmarked_language)\n  apply(force)\n  done\n\nlemma epdaS_to_epdaHS_mlang: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.marked_language G = epdaHS.marked_language G\"\n  apply(rule order_antisym)\n   apply(rule_tac\n      t = \"epdaS.marked_language G\"\n      and s = \"epdaS.finite_marked_language G\"\n      in ssubst)\n    apply (metis epdaS_inst_lang_finite)\n   apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac x)(*strict*)\n    prefer 2\n    apply(rule_tac\n      ?o1.0 = \"x\"\n      in epdaS_vs_epdaHS.ATS_Bisimulation_Derivation_Strong1_marked_language_translation1)\n     apply(rename_tac x)(*strict*)\n     apply(force)\n    apply(rename_tac x)(*strict*)\n    apply(force)\n   apply(rename_tac x)(*strict*)\n   apply(clarsimp)\n  apply(rule_tac\n      t = \"epdaHS.marked_language G\"\n      and s = \"epdaHS.finite_marked_language G\"\n      in ssubst)\n   apply (metis epdaHS_inst_lang_finite)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(rule_tac\n      ?o2.0 = \"x\"\n      in epdaS_vs_epdaHS.ATS_Bisimulation_Derivation_Strong1_marked_language_translation2)\n    apply(rename_tac x)(*strict*)\n    apply(force)\n   apply(rename_tac x)(*strict*)\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma epdaH_to_epdaHS_mlang: \"\n  valid_epda G\n  \\<Longrightarrow> epdaH.marked_language G = epdaHS.marked_language G\"\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule epdaH_vs_epdaHS_Nonblockingness_and_lang_transfer)\n   apply(force)\n  apply(force)\n  done\n\nlemma epdaS_to_epdaH_mlang: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.marked_language G = epdaH.marked_language G\"\n  apply(rule_tac\n      t = \"epdaS.marked_language G\"\n      and s = \"epdaHS.marked_language G\"\n      in ssubst)\n   apply(rule epdaS_to_epdaHS_mlang)\n   apply(force)\n  apply(rule sym)\n  apply(rule epdaH_to_epdaHS_mlang)\n  apply(force)\n  done\n\nlemma epdaS_to_epdaH_nonblockingness_language: \"\n  valid_epda G\n  \\<Longrightarrow> (nonblockingness_language (epdaS.unmarked_language G) (epdaS.marked_language G)) \\<longleftrightarrow> (nonblockingness_language (epdaH.unmarked_language G) (epdaH.marked_language G))\"\n  apply(rule_tac\n      t = \"epdaS.unmarked_language G\"\n      and s = \"epdaH.unmarked_language G\"\n      in ssubst)\n   apply(rule epdaS_to_epdaH_unmarked_language)\n   apply(force)\n  apply(rule_tac\n      t = \"epdaS.marked_language G\"\n      and s = \"epdaH.marked_language G\"\n      in ssubst)\n   apply(rule epdaS_to_epdaH_mlang)\n   apply(force)\n  apply(force)\n  done\n\nlemma epda_empty_in_epdaH_unmarked_language: \"\n  valid_epda G\n  \\<Longrightarrow> [] \\<in> epdaH.unmarked_language G\"\n  apply(simp (no_asm) add: epdaH.unmarked_language_def)\n  apply(rule_tac\n      x = \"der1 \\<lparr>epdaH_conf_state = epda_initial G, epdaH_conf_history = [], epdaH_conf_stack = [epda_box G]\\<rparr>\"\n      in exI)\n  apply(rule conjI)\n   apply(simp add: epdaH.derivation_initial_def)\n   apply(rule conjI)\n    apply(simp add: epdaH.der1_is_derivation)\n   apply(simp add: der1_def)\n   apply(simp add: epdaH_initial_configurations_def epdaH_configurations_def valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rule conjI)\n   apply(simp add: epdaH_unmarked_effect_def)\n   apply(rule_tac\n      x = \"0\"\n      in exI)\n   apply(simp add: der1_def)\n  apply(simp add: epdaH.der1_is_derivation)\n  done\n\nlemma epdaH_unmarked_languageuage_prefix_closed: \"\n  valid_epda G\n  \\<Longrightarrow> x@v \\<in> epdaH.unmarked_language G\n  \\<Longrightarrow> x \\<in> epdaH.unmarked_language G\"\n  apply(simp add: epdaH.unmarked_language_def)\n  apply(clarsimp)\n  apply(rename_tac d)(*strict*)\n  apply(rule_tac\n      x = \"d\"\n      in exI)\n  apply(clarsimp)\n  apply(simp add: epdaH_unmarked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac d i e c)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d i e c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      n = \"i\"\n      and P = \"\\<lambda>n. n\\<le>i \\<and> prefix x (epdaH_conf_history (the(get_configuration(d n)))) \"\n      in ex_least_nat_le_prime)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n   apply(simp add: prefix_def)\n   apply(force)\n  apply(rename_tac d i e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e c k)(*strict*)\n  apply(case_tac k)\n   apply(rename_tac d i e c k)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i e c)(*strict*)\n   apply(simp add: epdaH.derivation_initial_def)\n   apply(case_tac \"d 0\")\n    apply(rename_tac d i e c)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d i e c a)(*strict*)\n   apply(case_tac a)\n   apply(rename_tac d i e c a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i e c b)(*strict*)\n   apply(simp add: epdaH_initial_configurations_def)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n   apply(simp add: prefix_def)\n   apply(clarsimp)\n   apply(rule_tac\n      x = \"0\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac d i e c k nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e c nat)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d i e c nat)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d = \"d\"\n      and n = \"nat\"\n      and m = \"i\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac d i e c nat)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n    apply(rename_tac d i e c nat)(*strict*)\n    apply(force)\n   apply(rename_tac d i e c nat)(*strict*)\n   apply(force)\n  apply(rename_tac d i e c nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e c nat e1 e2 c1 c2)(*strict*)\n  apply(simp add: get_configuration_def prefix_def)\n  apply(clarsimp)\n  apply(rename_tac d i e c nat e1 e2 c1 c2 ca)(*strict*)\n  apply(case_tac c2)\n  apply(rename_tac d i e c nat e1 e2 c1 c2 ca epdaH_conf_state epdaH_conf_historya epdaH_conf_stack)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e c nat e1 e2 c1 ca epdaH_conf_state epdaH_conf_stack)(*strict*)\n  apply(simp add: epdaH_step_relation_def)\n  apply(rename_tac d i e c nat e1 e2 c1 ca epdaH_conf_statea epdaH_conf_stacka)(*strict*)\n  apply(rename_tac q2 s2)\n  apply(rename_tac d i e c nat e1 e2 c1 ca q2 s2)(*strict*)\n  apply(case_tac c1)\n  apply(rename_tac d i e c nat e1 e2 c1 ca q2 s2 epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n  apply(rename_tac q1 h1 s1)\n  apply(rename_tac d i e c nat e1 e2 c1 ca q2 s2 q1 h1 s1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e c nat e1 e2 ca h1 w)(*strict*)\n  apply(case_tac e2)\n  apply(rename_tac d i e c nat e1 e2 ca h1 w edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e c nat e1 ca h1 w edge_src edge_event edge_pop edge_push edge_trg)(*strict*)\n  apply(rename_tac qs re po pu qt)\n  apply(rename_tac d i e c nat e1 ca h1 w qs re po pu qt)(*strict*)\n  apply(case_tac re)\n   apply(rename_tac d i e c nat e1 ca h1 w qs re po pu qt)(*strict*)\n   apply(simp add: option_to_list_def)\n   apply(clarsimp)\n   apply(rename_tac d i e c nat e1 ca w qs po pu qt)(*strict*)\n   apply(rule_tac\n      x = \"nat\"\n      in exI)\n   apply(clarsimp)\n   apply(erule_tac\n      x = \"nat\"\n      in allE)\n   apply(force)\n  apply(rename_tac d i e c nat e1 ca h1 w qs re po pu qt a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e c nat e1 ca h1 w qs po pu qt a)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(rule_tac\n      xs = \"ca\"\n      in rev_cases)\n   apply(rename_tac d i e c nat e1 ca h1 w qs po pu qt a)(*strict*)\n   prefer 2\n   apply(rename_tac d i e c nat e1 ca h1 w qs po pu qt a ys y)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i e c nat e1 w qs po pu qt a ys)(*strict*)\n   apply(force)\n  apply(rename_tac d i e c nat e1 ca h1 w qs po pu qt a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e c nat e1 h1 w qs po pu qt a)(*strict*)\n  apply(rule_tac\n      x = \"Suc nat\"\n      in exI)\n  apply(clarsimp)\n  done\n\nlemma epdaH_coincide_strict_prefix: \"\n  valid_dpda G\n  \\<Longrightarrow> epdaH.derivation_initial G d1\n  \\<Longrightarrow> epdaH.derivation_initial G d2\n  \\<Longrightarrow> get_configuration (d1 i1) = Some c1\n  \\<Longrightarrow> get_configuration (d2 i2) = Some c2\n  \\<Longrightarrow> strict_prefix (epdaH_conf_history c1) (epdaH_conf_history c2)\n  \\<Longrightarrow> i1 \\<le> i2 \\<and> (\\<forall>i. i\\<le>i1 \\<longrightarrow> d1 i = d2 i)\"\n  apply(case_tac \"d1 0\")\n   apply(simp add: epdaH.derivation_initial_def)\n  apply(rename_tac a)(*strict*)\n  apply(case_tac a)\n  apply(rename_tac a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac option b)(*strict*)\n  apply(case_tac \"d2 0\")\n   apply(rename_tac option b)(*strict*)\n   apply(simp add: epdaH.derivation_initial_def)\n  apply(rename_tac option b a)(*strict*)\n  apply(case_tac a)\n  apply(rename_tac option b a optiona ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac option b optiona ba)(*strict*)\n  apply(case_tac option)\n   apply(rename_tac option b optiona ba)(*strict*)\n   prefer 2\n   apply(rename_tac option b optiona ba a)(*strict*)\n   apply(simp add: epdaH.derivation_def epdaH.derivation_initial_def)\n  apply(rename_tac option b optiona ba)(*strict*)\n  apply(case_tac optiona)\n   apply(rename_tac option b optiona ba)(*strict*)\n   prefer 2\n   apply(rename_tac option b optiona ba a)(*strict*)\n   apply(simp add: epdaH.derivation_def epdaH.derivation_initial_def)\n  apply(rename_tac option b optiona ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac b ba)(*strict*)\n  apply(subgoal_tac \"b = ba \\<and> b \\<in> epdaH_initial_configurations G\")\n   apply(rename_tac b ba)(*strict*)\n   prefer 2\n   apply(simp add: epdaH_initial_configurations_def epdaH.derivation_initial_def)\n  apply(rename_tac b ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ba)(*strict*)\n  apply(case_tac \"d1 i1 \")\n   apply(rename_tac ba)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac ba a)(*strict*)\n  apply(case_tac \"d2 i2 \")\n   apply(rename_tac ba a)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac ba a aa)(*strict*)\n  apply(case_tac a)\n  apply(rename_tac ba a aa option b)(*strict*)\n  apply(case_tac aa)\n  apply(rename_tac ba a aa option b optiona bb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ba option b optiona bb)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac ba option optiona)(*strict*)\n  apply(rename_tac c0 e1 e2)\n  apply(rename_tac c0 e1 e2)(*strict*)\n  apply(rule context_conjI)\n   apply(rename_tac c0 e1 e2)(*strict*)\n   apply(case_tac \"i2 < i1\")\n    apply(rename_tac c0 e1 e2)(*strict*)\n    apply(subgoal_tac \"False\")\n     apply(rename_tac c0 e1 e2)(*strict*)\n     apply(force)\n    apply(rename_tac c0 e1 e2)(*strict*)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac c0 e1 e2)(*strict*)\n     prefer 2\n     apply(rule_tac\n      g = \"d1\"\n      and n = \"i2\"\n      and m = \"i1\"\n      in epdaH.pre_some_position_is_some_position)\n       apply(rename_tac c0 e1 e2)(*strict*)\n       apply(simp add: epdaH.derivation_initial_def)\n      apply(rename_tac c0 e1 e2)(*strict*)\n      apply(force)\n     apply(rename_tac c0 e1 e2)(*strict*)\n     apply(force)\n    apply(rename_tac c0 e1 e2)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c0 e1 e2 e c)(*strict*)\n    apply(case_tac c1)\n    apply(rename_tac c0 e1 e2 e c epdaH_conf_state epdaH_conf_historya epdaH_conf_stack)(*strict*)\n    apply(case_tac c2)\n    apply(rename_tac c0 e1 e2 e c epdaH_conf_state epdaH_conf_historya epdaH_conf_stack epdaH_conf_statea epdaH_conf_historyaa epdaH_conf_stacka)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c0 e1 e2 e c epdaH_conf_state epdaH_conf_history epdaH_conf_stack epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n    apply(rename_tac qx1 hx1 sx1 qx2 hx2 sx2)\n    apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n     prefer 2\n     apply(rule_tac\n      G = \"G\"\n      and ?d1.0 = \"d1\"\n      and ?d2.0 = \"d2\"\n      and x = \"0\"\n      and y = \"0\"\n      and n = \"i2\"\n      and m = \"i2\"\n      in epdaH.is_forward_deterministicHist_derivations_coincide)\n                apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n                apply(simp add: valid_dpda_def valid_pda_def)\n               apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n               apply(force)\n              apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n              apply(force)\n             apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n             apply (metis DPDA_is_is_forward_deterministicHist_SB)\n            apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n            apply(force)\n           apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n           apply(force)\n          apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n          apply(force)\n         apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n         apply(force)\n        apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n        apply(force)\n       apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n       apply(force)\n      apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n      apply(clarsimp)\n      apply(simp add: get_configuration_def)\n      apply(simp add: strict_prefix_def)\n      apply(clarsimp)\n      apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 sx2 ca)(*strict*)\n      apply(subgoal_tac \"X\" for X)\n       apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 sx2 ca)(*strict*)\n       prefer 2\n       apply(rule_tac\n      d = \"d1\"\n      and G = \"G\"\n      and n = \"i2\"\n      and m = \"i1-i2\"\n      in epdaH.steps_extend_history_derivation)\n           apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 sx2 ca)(*strict*)\n           apply(simp add: valid_dpda_def valid_pda_def)\n          apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 sx2 ca)(*strict*)\n          apply(simp add: epdaH.derivation_initial_def)\n         apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 sx2 ca)(*strict*)\n         prefer 2\n         apply(clarsimp)\n         apply(simp add: get_configuration_def)\n        apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 sx2 ca)(*strict*)\n        apply(rule_tac\n      d = \"d1\"\n      in epdaH.belongs_configurations)\n         apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 sx2 ca)(*strict*)\n         apply(rule epdaH.derivation_initial_belongs)\n          apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 sx2 ca)(*strict*)\n          apply(simp add: valid_dpda_def valid_pda_def)\n         apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 sx2 ca)(*strict*)\n         apply(force)\n        apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 sx2 ca)(*strict*)\n        apply(force)\n       apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 sx2 ca)(*strict*)\n       apply(simp add: get_configuration_def)\n      apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 sx2 ca)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac c0 e1 e2 e c qx1 sx1 qx2 sx2 ca h)(*strict*)\n      apply(simp add: epda_effects_def)\n      apply(subgoal_tac \"\\<lparr>epdaH_conf_state = qx2, epdaH_conf_history = epdaH_conf_history c @ h @ ca, epdaH_conf_stack = sx2\\<rparr> \\<in> epdaH_configurations G\")\n       apply(rename_tac c0 e1 e2 e c qx1 sx1 qx2 sx2 ca h)(*strict*)\n       apply(simp add: epdaH_configurations_def)\n      apply(rename_tac c0 e1 e2 e c qx1 sx1 qx2 sx2 ca h)(*strict*)\n      apply(rule_tac\n      d = \"d2\"\n      in epdaH.belongs_configurations)\n       apply(rename_tac c0 e1 e2 e c qx1 sx1 qx2 sx2 ca h)(*strict*)\n       apply(rule epdaH.derivation_initial_belongs)\n        apply(rename_tac c0 e1 e2 e c qx1 sx1 qx2 sx2 ca h)(*strict*)\n        apply(simp add: valid_dpda_def valid_pda_def)\n       apply(rename_tac c0 e1 e2 e c qx1 sx1 qx2 sx2 ca h)(*strict*)\n       apply(force)\n      apply(rename_tac c0 e1 e2 e c qx1 sx1 qx2 sx2 ca h)(*strict*)\n      apply(force)\n     apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac c0 e1 e2 e c qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c0 e1 e2 qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac c0 e1 e2 qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n     prefer 2\n     apply(rule_tac\n      d = \"d1\"\n      and G = \"G\"\n      and n = \"i2\"\n      and m = \"i1-i2\"\n      in epdaH.steps_extend_history_derivation)\n         apply(rename_tac c0 e1 e2 qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n         apply(simp add: valid_dpda_def valid_pda_def)\n        apply(rename_tac c0 e1 e2 qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n        apply(simp add: epdaH.derivation_initial_def)\n       apply(rename_tac c0 e1 e2 qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n       prefer 2\n       apply(clarsimp)\n       apply(simp add: get_configuration_def)\n      apply(rename_tac c0 e1 e2 qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n      apply(rule_tac\n      d = \"d1\"\n      in epdaH.belongs_configurations)\n       apply(rename_tac c0 e1 e2 qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n       apply(rule epdaH.derivation_initial_belongs)\n        apply(rename_tac c0 e1 e2 qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n        apply(simp add: valid_dpda_def valid_pda_def)\n       apply(rename_tac c0 e1 e2 qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n       apply(force)\n      apply(rename_tac c0 e1 e2 qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n      apply(force)\n     apply(rename_tac c0 e1 e2 qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac c0 e1 e2 qx1 hx1 sx1 qx2 hx2 sx2)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c0 e1 e2 qx1 sx1 qx2 hx2 sx2 h)(*strict*)\n    apply(simp add: strict_prefix_def)\n   apply(rename_tac c0 e1 e2)(*strict*)\n   apply(force)\n  apply(rename_tac c0 e1 e2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c0 e1 e2 i)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac c0 e1 e2 i)(*strict*)\n   prefer 2\n   apply(rule_tac\n      g = \"d1\"\n      and n = \"i\"\n      and m = \"i1\"\n      in epdaH.pre_some_position_is_some_position)\n     apply(rename_tac c0 e1 e2 i)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n    apply(rename_tac c0 e1 e2 i)(*strict*)\n    apply(force)\n   apply(rename_tac c0 e1 e2 i)(*strict*)\n   apply(force)\n  apply(rename_tac c0 e1 e2 i)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac c0 e1 e2 i)(*strict*)\n   prefer 2\n   apply(rule_tac\n      g = \"d2\"\n      and n = \"i\"\n      and m = \"i2\"\n      in epdaH.pre_some_position_is_some_position)\n     apply(rename_tac c0 e1 e2 i)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n    apply(rename_tac c0 e1 e2 i)(*strict*)\n    apply(force)\n   apply(rename_tac c0 e1 e2 i)(*strict*)\n   apply(force)\n  apply(rename_tac c0 e1 e2 i)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c0 e1 e2 i e ea c ca)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac c0 e1 e2 i e ea c ca)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d = \"d1\"\n      and G = \"G\"\n      and n = \"i\"\n      and m = \"i1-i\"\n      in epdaH.steps_extend_history_derivation)\n       apply(rename_tac c0 e1 e2 i e ea c ca)(*strict*)\n       apply(simp add: valid_dpda_def valid_pda_def)\n      apply(rename_tac c0 e1 e2 i e ea c ca)(*strict*)\n      apply(simp add: epdaH.derivation_initial_def)\n     apply(rename_tac c0 e1 e2 i e ea c ca)(*strict*)\n     prefer 2\n     apply(clarsimp)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac c0 e1 e2 i e ea c ca)(*strict*)\n    apply(rule_tac\n      d = \"d1\"\n      in epdaH.belongs_configurations)\n     apply(rename_tac c0 e1 e2 i e ea c ca)(*strict*)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(rename_tac c0 e1 e2 i e ea c ca)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def)\n     apply(rename_tac c0 e1 e2 i e ea c ca)(*strict*)\n     apply(force)\n    apply(rename_tac c0 e1 e2 i e ea c ca)(*strict*)\n    apply(force)\n   apply(rename_tac c0 e1 e2 i e ea c ca)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac c0 e1 e2 i e ea c ca)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c0 e1 e2 i e ea c ca h)(*strict*)\n  apply(simp add: strict_prefix_def)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac c0 e1 e2 i e ea c ca h)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d = \"d2\"\n      and G = \"G\"\n      and n = \"i\"\n      and m = \"i2-i\"\n      in epdaH.steps_extend_history_derivation)\n       apply(rename_tac c0 e1 e2 i e ea c ca h)(*strict*)\n       apply(simp add: valid_dpda_def valid_pda_def)\n      apply(rename_tac c0 e1 e2 i e ea c ca h)(*strict*)\n      apply(simp add: epdaH.derivation_initial_def)\n     apply(rename_tac c0 e1 e2 i e ea c ca h)(*strict*)\n     prefer 2\n     apply(clarsimp)\n     apply(rename_tac c0 e1 e2 i e ea c ca h cb)(*strict*)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac c0 e1 e2 i e ea c ca h)(*strict*)\n    apply(rule_tac\n      d = \"d2\"\n      in epdaH.belongs_configurations)\n     apply(rename_tac c0 e1 e2 i e ea c ca h)(*strict*)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(rename_tac c0 e1 e2 i e ea c ca h)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def)\n     apply(rename_tac c0 e1 e2 i e ea c ca h)(*strict*)\n     apply(force)\n    apply(rename_tac c0 e1 e2 i e ea c ca h)(*strict*)\n    apply(force)\n   apply(rename_tac c0 e1 e2 i e ea c ca h)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac c0 e1 e2 i e ea c ca h)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c0 e1 e2 i e ea c ca h ha cb)(*strict*)\n  apply(subgoal_tac \"prefix (epdaH_conf_history c) (epdaH_conf_history ca) \\<or> SSX\" for SSX)\n   apply(rename_tac c0 e1 e2 i e ea c ca h ha cb)(*strict*)\n   prefer 2\n   apply(rule mutual_prefix_prefix)\n   apply(force)\n  apply(rename_tac c0 e1 e2 i e ea c ca h ha cb)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac c0 e1 e2 i e ea c ca h ha cb)(*strict*)\n   apply(simp add: prefix_def)\n   apply(clarsimp)\n   apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n    prefer 2\n    apply(rule_tac\n      G = \"G\"\n      and ?d1.0 = \"d1\"\n      and ?d2.0 = \"d2\"\n      and x = \"0\"\n      and y = \"0\"\n      and n = \"i\"\n      and m = \"i\"\n      in epdaH.is_forward_deterministicHist_derivations_coincide)\n               apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n               apply(simp add: valid_dpda_def valid_pda_def)\n              apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n              apply(force)\n             apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n             apply(force)\n            apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n            apply (metis DPDA_is_is_forward_deterministicHist_SB)\n           apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n           apply(force)\n          apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n          apply(force)\n         apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n         apply(force)\n        apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n        apply(force)\n       apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n       apply(force)\n      apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n      apply(force)\n     apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n     apply(clarsimp)\n     apply(simp add: get_configuration_def)\n     apply(rule_tac\n      x = \"cc\"\n      in bexI)\n      apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n     apply(subgoal_tac \"ca \\<in> epdaH_configurations G\")\n      apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n      apply(simp add: epdaH_configurations_def)\n      apply(clarsimp)\n      apply(rename_tac c0 e1 e2 i e ea c h ha cb cc q s)(*strict*)\n      apply(simp add: epda_effects_def)\n     apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n     apply(rule_tac\n      d = \"d2\"\n      in epdaH.belongs_configurations)\n      apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n      apply(rule epdaH.derivation_initial_belongs)\n       apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n       apply(simp add: valid_dpda_def valid_pda_def)\n      apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n      apply(force)\n     apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n     apply(force)\n    apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac c0 e1 e2 i e ea c ca h ha cb)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac c0 e1 e2 i e ea c ca h ha cb)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G = \"G\"\n      and ?d1.0 = \"d2\"\n      and ?d2.0 = \"d1\"\n      and x = \"0\"\n      and y = \"0\"\n      and n = \"i\"\n      and m = \"i\"\n      in epdaH.is_forward_deterministicHist_derivations_coincide)\n              apply(rename_tac c0 e1 e2 i e ea c ca h ha cb)(*strict*)\n              apply(simp add: valid_dpda_def valid_pda_def)\n             apply(rename_tac c0 e1 e2 i e ea c ca h ha cb)(*strict*)\n             apply(force)\n            apply(rename_tac c0 e1 e2 i e ea c ca h ha cb)(*strict*)\n            apply(force)\n           apply(rename_tac c0 e1 e2 i e ea c ca h ha cb)(*strict*)\n           apply (metis DPDA_is_is_forward_deterministicHist_SB)\n          apply(rename_tac c0 e1 e2 i e ea c ca h ha cb)(*strict*)\n          apply(force)\n         apply(rename_tac c0 e1 e2 i e ea c ca h ha cb)(*strict*)\n         apply(force)\n        apply(rename_tac c0 e1 e2 i e ea c ca h ha cb)(*strict*)\n        apply(force)\n       apply(rename_tac c0 e1 e2 i e ea c ca h ha cb)(*strict*)\n       apply(force)\n      apply(rename_tac c0 e1 e2 i e ea c ca h ha cb)(*strict*)\n      apply(force)\n     apply(rename_tac c0 e1 e2 i e ea c ca h ha cb)(*strict*)\n     apply(force)\n    apply(rename_tac c0 e1 e2 i e ea c ca h ha cb)(*strict*)\n    apply(clarsimp)\n    apply(simp add: get_configuration_def)\n    apply(simp add: prefix_def)\n    apply(clarsimp)\n    apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n    apply(rule_tac\n      x = \"cc\"\n      in bexI)\n     apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n    apply(subgoal_tac \"c \\<in> epdaH_configurations G\")\n     apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n     apply(simp add: epdaH_configurations_def)\n     apply(clarsimp)\n     apply(rename_tac c0 e1 e2 i e ea ca h cb cc q s)(*strict*)\n     apply(simp add: epda_effects_def)\n    apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n    apply(rule_tac\n      d = \"d1\"\n      in epdaH.belongs_configurations)\n     apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def)\n     apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n     apply(force)\n    apply(rename_tac c0 e1 e2 i e ea c ca h ha cb cc)(*strict*)\n    apply(force)\n   apply(rename_tac c0 e1 e2 i e ea c ca h ha cb)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac c0 e1 e2 i e ea c ca h ha cb)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma epdaH_first_time_shorter_than_some_time: \"\n  valid_dpda G\n  \\<Longrightarrow> epdaH.derivation_initial G d1\n  \\<Longrightarrow> epdaH.derivation_initial G d2\n  \\<Longrightarrow> get_configuration (d1 n1) = Some c1\n  \\<Longrightarrow> get_configuration (d2 n2) = Some c2\n  \\<Longrightarrow> epdaH_conf_history c1 = epdaH_conf_history c2\n  \\<Longrightarrow> (\\<forall>k<n1. epdaH_conf_history (the(get_configuration(d1 k))) \\<noteq> epdaH_conf_history c1)\n  \\<Longrightarrow> n1\\<le>n2\"\n  apply(subgoal_tac \"\\<exists>c. c \\<in> epdaH_initial_configurations G \\<and> d1 0 = Some (pair None c) \\<and> d2 0 = Some (pair None c)\")\n   prefer 2\n   apply(case_tac \"d1 0\")\n    apply(clarsimp)\n    apply(simp add: epdaH.derivation_initial_def epdaH.derivation_def)\n   apply(rename_tac a)(*strict*)\n   apply(case_tac \"d2 0\")\n    apply(rename_tac a)(*strict*)\n    apply(clarsimp)\n    apply(simp add: epdaH.derivation_initial_def epdaH.derivation_def)\n   apply(rename_tac a aa)(*strict*)\n   apply(case_tac a)\n   apply(rename_tac a aa option b)(*strict*)\n   apply(case_tac aa)\n   apply(rename_tac a aa option b optiona ba)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac option b optiona ba)(*strict*)\n   apply(simp add: epdaH.derivation_initial_def epdaH.derivation_def)\n   apply(clarsimp)\n   apply(rename_tac b ba)(*strict*)\n   apply(simp add: epdaH_initial_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac c)(*strict*)\n  apply(case_tac \"d1 n1\")\n   apply(rename_tac c)(*strict*)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac c a)(*strict*)\n  apply(case_tac \"d2 n2\")\n   apply(rename_tac c a)(*strict*)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac c a aa)(*strict*)\n  apply(clarsimp)\n  apply(simp add: get_configuration_def)\n  apply(case_tac a)\n  apply(rename_tac c a aa option b)(*strict*)\n  apply(case_tac aa)\n  apply(rename_tac c a aa option b optiona ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c option optiona)(*strict*)\n  apply(rename_tac e1 e2)\n  apply(rename_tac c e1 e2)(*strict*)\n  apply(case_tac \"n2<n1\")\n   apply(rename_tac c e1 e2)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac c e1 e2)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac c e1 e2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G = \"G\"\n      and ?d1.0 = \"d2\"\n      and ?d2.0 = \"d1\"\n      and x = \"0\"\n      and y = \"0\"\n      and n = \"n2\"\n      and m = \"n1\"\n      in epdaH.is_forward_deterministicHist_derivations_coincide)\n              apply(rename_tac c e1 e2)(*strict*)\n              apply(simp add: valid_dpda_def valid_pda_def)\n             apply(rename_tac c e1 e2)(*strict*)\n             apply(force)\n            apply(rename_tac c e1 e2)(*strict*)\n            apply(force)\n           apply(rename_tac c e1 e2)(*strict*)\n           apply (metis DPDA_is_is_forward_deterministicHist_SB)\n          apply(rename_tac c e1 e2)(*strict*)\n          apply(simp add: epdaH.derivation_initial_def)\n         apply(rename_tac c e1 e2)(*strict*)\n         apply(force)\n        apply(rename_tac c e1 e2)(*strict*)\n        apply(force)\n       apply(rename_tac c e1 e2)(*strict*)\n       apply(force)\n      apply(rename_tac c e1 e2)(*strict*)\n      apply(force)\n     apply(rename_tac c e1 e2)(*strict*)\n     apply(force)\n    apply(rename_tac c e1 e2)(*strict*)\n    apply(clarsimp)\n    apply(simp add: epda_effects_def)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac c e1 e2)(*strict*)\n   apply(simp)\n  apply(rename_tac c e1 e2)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac c e1 e2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d = \"d1\"\n      and n = \"n2\"\n      and m = \"n1\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac c e1 e2)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n    apply(rename_tac c e1 e2)(*strict*)\n    apply(force)\n   apply(rename_tac c e1 e2)(*strict*)\n   apply(force)\n  apply(rename_tac c e1 e2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G = \"G\"\n      and d = \"d1\"\n      and n = \"Suc n2\"\n      and m = \"n1-Suc n2\"\n      in epdaH.steps_extend_history_derivation)\n       apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n       apply(simp add: valid_dpda_def valid_pda_def)\n      apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n      apply(simp add: epdaH.derivation_initial_def)\n     apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n     prefer 2\n     apply(simp add: get_configuration_def)\n    apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n    apply(rule_tac\n      d = \"d1\"\n      in epdaH.belongs_configurations)\n     apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def)\n     apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n     apply(force)\n    apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n    apply(force)\n   apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c e1 e1a e2a c2a h)(*strict*)\n  apply(simp add: epdaH_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac c e1 e1a e2a c2a w)(*strict*)\n  apply(case_tac \"e2a\")\n  apply(rename_tac c e1 e1a e2a c2a w edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n  apply(rename_tac qs re po pu qt)\n  apply(rename_tac c e1 e1a e2a c2a w qs re po pu qt)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c e1 e1a c2a w re po pu)(*strict*)\n  apply(case_tac re)\n   apply(rename_tac c e1 e1a c2a w re po pu)(*strict*)\n   prefer 2\n   apply(rename_tac c e1 e1a c2a w re po pu a)(*strict*)\n   apply(simp add: option_to_list_def)\n  apply(rename_tac c e1 e1a c2a w re po pu)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(clarsimp)\n  apply(rename_tac c e1 e1a c2a w po pu)(*strict*)\n  apply(erule_tac\n      x = \"n2\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac c e1 e1a c2a w po pu)(*strict*)\n   apply(force)\n  apply(rename_tac c e1 e1a c2a w po pu)(*strict*)\n  apply(force)\n  done\n\nlemma epdaH_coincide_on_stable_configurations: \"\n  valid_dpda G\n  \\<Longrightarrow> epdaH.derivation_initial G d1\n  \\<Longrightarrow> epdaH.derivation_initial G d2\n  \\<Longrightarrow> get_configuration (d1 n1) = Some c1\n  \\<Longrightarrow> get_configuration (d2 n2) = Some c2\n  \\<Longrightarrow> (\\<forall>e\\<in> epda_delta G. edge_event e = None \\<longrightarrow> (\\<forall>c'. \\<not>epdaH_step_relation G c1 e c'))\n  \\<Longrightarrow> (\\<forall>e\\<in> epda_delta G. edge_event e = None \\<longrightarrow> (\\<forall>c'. \\<not>epdaH_step_relation G c2 e c'))\n  \\<Longrightarrow> epdaH_conf_history c1 = epdaH_conf_history c2\n  \\<Longrightarrow> n1 = n2 \\<and> (\\<forall>i\\<le>n1. d1 i = d2 i)\"\n  apply(subgoal_tac \"\\<exists>c. c \\<in> epdaH_initial_configurations G \\<and> d1 0 = Some (pair None c) \\<and> d2 0 = Some (pair None c)\")\n   prefer 2\n   apply(case_tac \"d1 0\")\n    apply(clarsimp)\n    apply(simp add: epdaH.derivation_initial_def epdaH.derivation_def)\n   apply(rename_tac a)(*strict*)\n   apply(case_tac \"d2 0\")\n    apply(rename_tac a)(*strict*)\n    apply(clarsimp)\n    apply(simp add: epdaH.derivation_initial_def epdaH.derivation_def)\n   apply(rename_tac a aa)(*strict*)\n   apply(case_tac a)\n   apply(rename_tac a aa option conf)(*strict*)\n   apply(case_tac aa)\n   apply(rename_tac a aa option conf optiona confa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac option conf optiona confa)(*strict*)\n   apply(simp add: epdaH.derivation_initial_def epdaH.derivation_def)\n   apply(clarsimp)\n   apply(rename_tac conf confa)(*strict*)\n   apply(simp add: epdaH_initial_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac c)(*strict*)\n  apply(case_tac \"d1 n1\")\n   apply(rename_tac c)(*strict*)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac c a)(*strict*)\n  apply(case_tac \"d2 n2\")\n   apply(rename_tac c a)(*strict*)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac c a aa)(*strict*)\n  apply(clarsimp)\n  apply(simp add: get_configuration_def)\n  apply(case_tac a)\n  apply(rename_tac c a aa option conf)(*strict*)\n  apply(case_tac aa)\n  apply(rename_tac c a aa option conf optiona confa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c option optiona)(*strict*)\n  apply(rename_tac e1 e2)\n  apply(rename_tac c e1 e2)(*strict*)\n  apply(rule context_conjI)\n   apply(rename_tac c e1 e2)(*strict*)\n   apply(case_tac \"n1<n2\")\n    apply(rename_tac c e1 e2)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac c e1 e2)(*strict*)\n     prefer 2\n     apply(rule_tac\n      G = \"G\"\n      and ?d1.0 = \"d1\"\n      and ?d2.0 = \"d2\"\n      and x = \"0\"\n      and y = \"0\"\n      and n = \"n1\"\n      and m = \"n2\"\n      in epdaH.is_forward_deterministicHist_derivations_coincide)\n                apply(rename_tac c e1 e2)(*strict*)\n                apply(simp add: valid_dpda_def valid_pda_def)\n               apply(rename_tac c e1 e2)(*strict*)\n               apply(force)\n              apply(rename_tac c e1 e2)(*strict*)\n              apply(force)\n             apply(rename_tac c e1 e2)(*strict*)\n             apply (metis DPDA_is_is_forward_deterministicHist_SB)\n            apply(rename_tac c e1 e2)(*strict*)\n            apply(simp add: epdaH.derivation_initial_def)\n           apply(rename_tac c e1 e2)(*strict*)\n           apply(force)\n          apply(rename_tac c e1 e2)(*strict*)\n          apply(force)\n         apply(rename_tac c e1 e2)(*strict*)\n         apply(force)\n        apply(rename_tac c e1 e2)(*strict*)\n        apply(force)\n       apply(rename_tac c e1 e2)(*strict*)\n       apply(force)\n      apply(rename_tac c e1 e2)(*strict*)\n      apply(clarsimp)\n      apply(simp add: epda_effects_def)\n      apply(simp add: get_configuration_def)\n     apply(rename_tac c e1 e2)(*strict*)\n     apply(simp)\n    apply(rename_tac c e1 e2)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac c e1 e2)(*strict*)\n     prefer 2\n     apply(rule_tac\n      d = \"d2\"\n      and n = \"n1\"\n      and m = \"n2\"\n      in epdaH.step_detail_before_some_position)\n       apply(rename_tac c e1 e2)(*strict*)\n       apply(simp add: epdaH.derivation_initial_def)\n      apply(rename_tac c e1 e2)(*strict*)\n      apply(force)\n     apply(rename_tac c e1 e2)(*strict*)\n     apply(force)\n    apply(rename_tac c e1 e2)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c e2 e1a e2a c2a)(*strict*)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac c e2 e1a e2a c2a)(*strict*)\n     prefer 2\n     apply(rule_tac\n      G = \"G\"\n      and d = \"d2\"\n      and n = \"Suc n1\"\n      and m = \"n2-Suc n1\"\n      in epdaH.steps_extend_history_derivation)\n         apply(rename_tac c e2 e1a e2a c2a)(*strict*)\n         apply(simp add: valid_dpda_def valid_pda_def)\n        apply(rename_tac c e2 e1a e2a c2a)(*strict*)\n        apply(simp add: epdaH.derivation_initial_def)\n       apply(rename_tac c e2 e1a e2a c2a)(*strict*)\n       prefer 2\n       apply(simp add: get_configuration_def)\n      apply(rename_tac c e2 e1a e2a c2a)(*strict*)\n      apply(rule_tac\n      d = \"d2\"\n      in epdaH.belongs_configurations)\n       apply(rename_tac c e2 e1a e2a c2a)(*strict*)\n       apply(rule epdaH.derivation_initial_belongs)\n        apply(rename_tac c e2 e1a e2a c2a)(*strict*)\n        apply(simp add: valid_dpda_def valid_pda_def)\n       apply(rename_tac c e2 e1a e2a c2a)(*strict*)\n       apply(force)\n      apply(rename_tac c e2 e1a e2a c2a)(*strict*)\n      apply(force)\n     apply(rename_tac c e2 e1a e2a c2a)(*strict*)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac c e2 e1a e2a c2a)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c e2 e1a e2a c2a h)(*strict*)\n    apply(simp add: epdaH_step_relation_def)\n    apply(clarsimp)\n    apply(rename_tac c e2 e1a e2a c2a w)(*strict*)\n    apply(case_tac \"e2a\")\n    apply(rename_tac c e2 e1a e2a c2a w edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n    apply(rename_tac qs re po pu qt)\n    apply(rename_tac c e2 e1a e2a c2a w qs re po pu qt)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c e2 e1a c2a w re po pu)(*strict*)\n    apply(case_tac re)\n     apply(rename_tac c e2 e1a c2a w re po pu)(*strict*)\n     prefer 2\n     apply(rename_tac c e2 e1a c2a w re po pu a)(*strict*)\n     apply(simp add: option_to_list_def)\n    apply(rename_tac c e2 e1a c2a w re po pu)(*strict*)\n    apply(simp add: option_to_list_def)\n    apply(clarsimp)\n    apply(rename_tac c e2 e1a c2a w po pu)(*strict*)\n    apply(erule_tac\n      x = \"\\<lparr>edge_src = epdaH_conf_state c1, edge_event = None, edge_pop = po, edge_push = pu, edge_trg = epdaH_conf_state c2a\\<rparr>\"\n      and P = \"\\<lambda>e. edge_event e = None \\<longrightarrow> (\\<forall>c'. epdaH_conf_history c' = epdaH_conf_history c2a \\<longrightarrow> epdaH_conf_state c' = edge_trg e \\<longrightarrow> epdaH_conf_state c1 = edge_src e \\<longrightarrow> (\\<forall>wa. po @ w = edge_pop e @ wa \\<longrightarrow> epdaH_conf_stack c' \\<noteq> edge_push e @ wa))\"\n      in ballE)\n     apply(rename_tac c e2 e1a c2a w po pu)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac c e2 e1a c2a w po pu)(*strict*)\n    apply(force)\n   apply(rename_tac c e1 e2)(*strict*)\n   apply(case_tac \"n2<n1\")\n    apply(rename_tac c e1 e2)(*strict*)\n    apply(thin_tac \"\\<not> n1 < n2\")\n    apply(clarsimp)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac c e1 e2)(*strict*)\n     prefer 2\n     apply(rule_tac\n      G = \"G\"\n      and ?d1.0 = \"d2\"\n      and ?d2.0 = \"d1\"\n      and x = \"0\"\n      and y = \"0\"\n      and n = \"n2\"\n      and m = \"n1\"\n      in epdaH.is_forward_deterministicHist_derivations_coincide)\n                apply(rename_tac c e1 e2)(*strict*)\n                apply(simp add: valid_dpda_def valid_pda_def)\n               apply(rename_tac c e1 e2)(*strict*)\n               apply(force)\n              apply(rename_tac c e1 e2)(*strict*)\n              apply(force)\n             apply(rename_tac c e1 e2)(*strict*)\n             apply (metis DPDA_is_is_forward_deterministicHist_SB)\n            apply(rename_tac c e1 e2)(*strict*)\n            apply(simp add: epdaH.derivation_initial_def)\n           apply(rename_tac c e1 e2)(*strict*)\n           apply(force)\n          apply(rename_tac c e1 e2)(*strict*)\n          apply(force)\n         apply(rename_tac c e1 e2)(*strict*)\n         apply(force)\n        apply(rename_tac c e1 e2)(*strict*)\n        apply(force)\n       apply(rename_tac c e1 e2)(*strict*)\n       apply(force)\n      apply(rename_tac c e1 e2)(*strict*)\n      apply(clarsimp)\n      apply(simp add: epda_effects_def)\n      apply(simp add: get_configuration_def)\n     apply(rename_tac c e1 e2)(*strict*)\n     apply(simp)\n    apply(rename_tac c e1 e2)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac c e1 e2)(*strict*)\n     prefer 2\n     apply(rule_tac\n      d = \"d1\"\n      and n = \"n2\"\n      and m = \"n1\"\n      in epdaH.step_detail_before_some_position)\n       apply(rename_tac c e1 e2)(*strict*)\n       apply(simp add: epdaH.derivation_initial_def)\n      apply(rename_tac c e1 e2)(*strict*)\n      apply(force)\n     apply(rename_tac c e1 e2)(*strict*)\n     apply(force)\n    apply(rename_tac c e1 e2)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n     prefer 2\n     apply(rule_tac\n      G = \"G\"\n      and d = \"d1\"\n      and n = \"Suc n2\"\n      and m = \"n1-Suc n2\"\n      in epdaH.steps_extend_history_derivation)\n         apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n         apply(simp add: valid_dpda_def valid_pda_def)\n        apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n        apply(simp add: epdaH.derivation_initial_def)\n       apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n       prefer 2\n       apply(simp add: get_configuration_def)\n      apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n      apply(rule_tac\n      d = \"d1\"\n      in epdaH.belongs_configurations)\n       apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n       apply(rule epdaH.derivation_initial_belongs)\n        apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n        apply(simp add: valid_dpda_def valid_pda_def)\n       apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n       apply(force)\n      apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n      apply(force)\n     apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac c e1 e1a e2a c2a)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c e1 e1a e2a c2a h)(*strict*)\n    apply(simp add: epdaH_step_relation_def)\n    apply(clarsimp)\n    apply(rename_tac c e1 e1a e2a c2a w)(*strict*)\n    apply(case_tac \"e2a\")\n    apply(rename_tac c e1 e1a e2a c2a w edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n    apply(rename_tac qs re po pu qt)\n    apply(rename_tac c e1 e1a e2a c2a w qs re po pu qt)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c e1 e1a c2a w re po pu)(*strict*)\n    apply(case_tac re)\n     apply(rename_tac c e1 e1a c2a w re po pu)(*strict*)\n     prefer 2\n     apply(rename_tac c e1 e1a c2a w re po pu a)(*strict*)\n     apply(simp add: option_to_list_def)\n    apply(rename_tac c e1 e1a c2a w re po pu)(*strict*)\n    apply(simp add: option_to_list_def)\n    apply(clarsimp)\n    apply(rename_tac c e1 e1a c2a w po pu)(*strict*)\n    apply(erule_tac\n      x = \"\\<lparr>edge_src = epdaH_conf_state c2, edge_event = None, edge_pop = po, edge_push = pu, edge_trg = epdaH_conf_state c2a\\<rparr>\"\n      and P = \"\\<lambda>x. edge_event x = None \\<longrightarrow> (\\<forall>c'. epdaH_conf_history c' = epdaH_conf_history c2a \\<longrightarrow> epdaH_conf_state c' = edge_trg x \\<longrightarrow> epdaH_conf_state c2 = edge_src x \\<longrightarrow> (\\<forall>wa. po @ w = edge_pop x @ wa \\<longrightarrow> epdaH_conf_stack c' \\<noteq> edge_push x @ wa))\"\n      in ballE)\n     apply(rename_tac c e1 e1a c2a w po pu)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac c e1 e1a c2a w po pu)(*strict*)\n    apply(force)\n   apply(rename_tac c e1 e2)(*strict*)\n   apply(force)\n  apply(rename_tac c e1 e2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c e1 e2 i)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac c e1 e2 i)(*strict*)\n   prefer 2\n   apply(rule_tac\n      g = \"d1\"\n      and n = \"i\"\n      and m = \"n2\"\n      in epdaH.pre_some_position_is_some_position)\n     apply(rename_tac c e1 e2 i)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n    apply(rename_tac c e1 e2 i)(*strict*)\n    apply(force)\n   apply(rename_tac c e1 e2 i)(*strict*)\n   apply(force)\n  apply(rename_tac c e1 e2 i)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac c e1 e2 i)(*strict*)\n   prefer 2\n   apply(rule_tac\n      g = \"d2\"\n      and n = \"i\"\n      and m = \"n2\"\n      in epdaH.pre_some_position_is_some_position)\n     apply(rename_tac c e1 e2 i)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n    apply(rename_tac c e1 e2 i)(*strict*)\n    apply(force)\n   apply(rename_tac c e1 e2 i)(*strict*)\n   apply(force)\n  apply(rename_tac c e1 e2 i)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c e1 e2 i e ea ca cb)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac c e1 e2 i e ea ca cb)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d = \"d1\"\n      and G = \"G\"\n      and n = \"i\"\n      and m = \"n2-i\"\n      in epdaH.steps_extend_history_derivation)\n       apply(rename_tac c e1 e2 i e ea ca cb)(*strict*)\n       apply(simp add: valid_dpda_def valid_pda_def)\n      apply(rename_tac c e1 e2 i e ea ca cb)(*strict*)\n      apply(simp add: epdaH.derivation_initial_def)\n     apply(rename_tac c e1 e2 i e ea ca cb)(*strict*)\n     prefer 2\n     apply(clarsimp)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac c e1 e2 i e ea ca cb)(*strict*)\n    apply(rule_tac\n      d = \"d1\"\n      in epdaH.belongs_configurations)\n     apply(rename_tac c e1 e2 i e ea ca cb)(*strict*)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(rename_tac c e1 e2 i e ea ca cb)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def)\n     apply(rename_tac c e1 e2 i e ea ca cb)(*strict*)\n     apply(force)\n    apply(rename_tac c e1 e2 i e ea ca cb)(*strict*)\n    apply(force)\n   apply(rename_tac c e1 e2 i e ea ca cb)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac c e1 e2 i e ea ca cb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c e1 e2 i e ea ca cb h)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac c e1 e2 i e ea ca cb h)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d = \"d2\"\n      and G = \"G\"\n      and n = \"i\"\n      and m = \"n2-i\"\n      in epdaH.steps_extend_history_derivation)\n       apply(rename_tac c e1 e2 i e ea ca cb h)(*strict*)\n       apply(simp add: valid_dpda_def valid_pda_def)\n      apply(rename_tac c e1 e2 i e ea ca cb h)(*strict*)\n      apply(simp add: epdaH.derivation_initial_def)\n     apply(rename_tac c e1 e2 i e ea ca cb h)(*strict*)\n     prefer 2\n     apply(clarsimp)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac c e1 e2 i e ea ca cb h)(*strict*)\n    apply(rule_tac\n      d = \"d2\"\n      in epdaH.belongs_configurations)\n     apply(rename_tac c e1 e2 i e ea ca cb h)(*strict*)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(rename_tac c e1 e2 i e ea ca cb h)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def)\n     apply(rename_tac c e1 e2 i e ea ca cb h)(*strict*)\n     apply(force)\n    apply(rename_tac c e1 e2 i e ea ca cb h)(*strict*)\n    apply(force)\n   apply(rename_tac c e1 e2 i e ea ca cb h)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac c e1 e2 i e ea ca cb h)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c e1 e2 i e ea ca cb h ha)(*strict*)\n  apply(subgoal_tac \"prefix (epdaH_conf_history ca) (epdaH_conf_history cb) \\<or> SSX\" for SSX)\n   apply(rename_tac c e1 e2 i e ea ca cb h ha)(*strict*)\n   prefer 2\n   apply(rule mutual_prefix_prefix)\n   apply(force)\n  apply(rename_tac c e1 e2 i e ea ca cb h ha)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac c e1 e2 i e ea ca cb h ha)(*strict*)\n   apply(simp add: prefix_def)\n   apply(clarsimp)\n   apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n    prefer 2\n    apply(rule_tac\n      G = \"G\"\n      and ?d1.0 = \"d1\"\n      and ?d2.0 = \"d2\"\n      and x = \"0\"\n      and y = \"0\"\n      and n = \"i\"\n      and m = \"i\"\n      in epdaH.is_forward_deterministicHist_derivations_coincide)\n               apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n               apply(simp add: valid_dpda_def valid_pda_def)\n              apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n              apply(force)\n             apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n             apply(force)\n            apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n            apply (metis DPDA_is_is_forward_deterministicHist_SB)\n           apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n           apply(force)\n          apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n          apply(force)\n         apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n         apply(force)\n        apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n        apply(force)\n       apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n       apply(force)\n      apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n      apply(force)\n     apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n     apply(clarsimp)\n     apply(simp add: get_configuration_def)\n     apply(rule_tac\n      x = \"cc\"\n      in bexI)\n      apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n     apply(subgoal_tac \"cb \\<in> epdaH_configurations G\")\n      apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n      apply(simp add: epdaH_configurations_def)\n      apply(clarsimp)\n      apply(rename_tac c e1 e2 i e ea ca ha cc q s)(*strict*)\n      apply(simp add: epda_effects_def)\n     apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n     apply(rule_tac\n      d = \"d2\"\n      in epdaH.belongs_configurations)\n      apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n      apply(rule epdaH.derivation_initial_belongs)\n       apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n       apply(simp add: valid_dpda_def valid_pda_def)\n      apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n      apply(force)\n     apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n     apply(force)\n    apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac c e1 e2 i e ea ca cb h ha)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac c e1 e2 i e ea ca cb h ha)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G = \"G\"\n      and ?d1.0 = \"d2\"\n      and ?d2.0 = \"d1\"\n      and x = \"0\"\n      and y = \"0\"\n      and n = \"i\"\n      and m = \"i\"\n      in epdaH.is_forward_deterministicHist_derivations_coincide)\n              apply(rename_tac c e1 e2 i e ea ca cb h ha)(*strict*)\n              apply(simp add: valid_dpda_def valid_pda_def)\n             apply(rename_tac c e1 e2 i e ea ca cb h ha)(*strict*)\n             apply(force)\n            apply(rename_tac c e1 e2 i e ea ca cb h ha)(*strict*)\n            apply(force)\n           apply(rename_tac c e1 e2 i e ea ca cb h ha)(*strict*)\n           apply (metis DPDA_is_is_forward_deterministicHist_SB)\n          apply(rename_tac c e1 e2 i e ea ca cb h ha)(*strict*)\n          apply(force)\n         apply(rename_tac c e1 e2 i e ea ca cb h ha)(*strict*)\n         apply(force)\n        apply(rename_tac c e1 e2 i e ea ca cb h ha)(*strict*)\n        apply(force)\n       apply(rename_tac c e1 e2 i e ea ca cb h ha)(*strict*)\n       apply(force)\n      apply(rename_tac c e1 e2 i e ea ca cb h ha)(*strict*)\n      apply(force)\n     apply(rename_tac c e1 e2 i e ea ca cb h ha)(*strict*)\n     apply(force)\n    apply(rename_tac c e1 e2 i e ea ca cb h ha)(*strict*)\n    apply(clarsimp)\n    apply(simp add: get_configuration_def)\n    apply(simp add: prefix_def)\n    apply(clarsimp)\n    apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n    apply(rule_tac\n      x = \"cc\"\n      in bexI)\n     apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n    apply(subgoal_tac \"ca \\<in> epdaH_configurations G\")\n     apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n     apply(simp add: epdaH_configurations_def)\n     apply(clarsimp)\n     apply(rename_tac c e1 e2 i e ea cb h cc q s)(*strict*)\n     apply(simp add: epda_effects_def)\n    apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n    apply(rule_tac\n      d = \"d1\"\n      in epdaH.belongs_configurations)\n     apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def)\n     apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n     apply(force)\n    apply(rename_tac c e1 e2 i e ea ca cb h ha cc)(*strict*)\n    apply(force)\n   apply(rename_tac c e1 e2 i e ea ca cb h ha)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac c e1 e2 i e ea ca cb h ha)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma DPDA_conflicting_edges: \"\n  valid_dpda G\n  \\<Longrightarrow> epdaH.derivation_initial G d\n  \\<Longrightarrow> d n = Some (pair e c)\n  \\<Longrightarrow> epdaH_step_relation G c e1 c1\n  \\<Longrightarrow> epdaH_step_relation G c e2 c2\n  \\<Longrightarrow> edge_event e1 = None\n  \\<Longrightarrow> edge_event e2 \\<noteq> None\n  \\<Longrightarrow> Q\"\n  apply(subgoal_tac \" epdaH.is_forward_deterministicHist_SB G\")\n   prefer 2\n   apply (metis DPDA_is_is_forward_deterministicHist_SB)\n  apply(simp add: epdaH.is_forward_edge_deterministicHist_SB_long_def epdaH.is_forward_deterministicHist_SB_def)\n  apply(clarsimp)\n  apply(rename_tac y)(*strict*)\n  apply(erule_tac\n      x = \"c\"\n      in ballE)\n   apply(rename_tac y)(*strict*)\n   prefer 2\n   apply(simp add: epdaH.get_accessible_configurations_def)\n   apply(erule_tac\n      x = \"d\"\n      in allE)\n   apply(clarsimp)\n   apply(erule_tac\n      x = \"n\"\n      in allE)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac y)(*strict*)\n  apply(erule_tac\n      x = \"c1\"\n      in allE)\n  apply(erule_tac\n      x = \"c2\"\n      in allE)\n  apply(erule_tac\n      x = \"e1\"\n      in allE)\n  apply(erule_tac\n      x = \"e2\"\n      in allE)\n  apply(clarsimp)\n  apply(erule impE)\n   apply(rename_tac y)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac y)(*strict*)\n  apply(rule_tac\n      x = \"[]\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac y)(*strict*)\n   apply(simp add: epdaH_step_relation_def option_to_list_def epda_effects_def)\n  apply(rename_tac y)(*strict*)\n  apply(rule_tac\n      x = \"[y]\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac y)(*strict*)\n   apply(simp add: epdaH_step_relation_def option_to_list_def epda_effects_def valid_dpda_def valid_pda_def valid_epda_def)\n   apply(clarsimp)\n   apply(rename_tac y w)(*strict*)\n   apply(erule_tac\n      x = \"e2\"\n      in ballE)\n    apply(rename_tac y w)(*strict*)\n    apply(simp add: valid_epda_step_label_def may_terminated_by_def option_to_set_def)\n   apply(rename_tac y w)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac y)(*strict*)\n  apply(simp add: epdaH_step_relation_def option_to_list_def)\n  apply(rule_tac\n      t = \"ATS_History.history_fragment_prefixes epda_effects (@) G [y] = ATS_History.history_fragment_prefixes epda_effects (@) G []\"\n      and s = \"ATS_History.history_fragment_prefixes epda_effects (@) G [] \\<subseteq> ATS_History.history_fragment_prefixes epda_effects (@) G [y] \\<and> ATS_History.history_fragment_prefixes epda_effects (@) G [y] \\<subseteq> ATS_History.history_fragment_prefixes epda_effects (@) G []\"\n      in ssubst)\n   apply(rename_tac y)(*strict*)\n   apply(force)\n  apply(rename_tac y)(*strict*)\n  apply(rule_tac\n      t = \"ATS_History.history_fragment_prefixes epda_effects (@) G [] \\<subseteq> ATS_History.history_fragment_prefixes epda_effects (@) G [y]\"\n      in subst)\n   apply(rename_tac y)(*strict*)\n   apply(rule I_epda_HS_H.prefix_to_history_fragment_prefixes)\n    apply(rename_tac y)(*strict*)\n    apply(simp add: epda_effects_def)\n   apply(rename_tac y)(*strict*)\n   apply(simp add: epda_effects_def)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def valid_epda_step_label_def)\n   apply(clarsimp)\n   apply(rename_tac y w)(*strict*)\n   apply(erule_tac\n      x = \"e2\"\n      and P = \"\\<lambda>e2. edge_src e2 \\<in> epda_states G \\<and> edge_trg e2 \\<in> epda_states G \\<and> option_to_set (edge_event e2) \\<subseteq> epda_events G \\<and> edge_pop e2 \\<in> may_terminated_by (epda_gamma G) (epda_box G) \\<and> edge_push e2 \\<in> may_terminated_by (epda_gamma G) (epda_box G) \\<and> (edge_pop e2 \\<in> must_terminated_by (epda_gamma G) (epda_box G)) = (edge_push e2 \\<in> must_terminated_by (epda_gamma G) (epda_box G))\"\n      in ballE)\n    apply(rename_tac y w)(*strict*)\n    apply(clarsimp)\n    apply(simp add: option_to_set_def)\n   apply(rename_tac y w)(*strict*)\n   apply(simp add: epdaH_step_relation_def option_to_list_def)\n  apply(rename_tac y)(*strict*)\n  apply(rule_tac\n      t = \"ATS_History.history_fragment_prefixes epda_effects (@) G [y] \\<subseteq> ATS_History.history_fragment_prefixes epda_effects (@) G []\"\n      in subst)\n   apply(rename_tac y)(*strict*)\n   apply(rule I_epda_HS_H.prefix_to_history_fragment_prefixes)\n    apply(rename_tac y)(*strict*)\n    apply(simp add: epda_effects_def)\n    apply(simp add: valid_dpda_def valid_pda_def valid_epda_def valid_epda_step_label_def)\n    apply(clarsimp)\n    apply(rename_tac y w)(*strict*)\n    apply(erule_tac\n      x = \"e2\"\n      and P = \"\\<lambda>e2. edge_src e2 \\<in> epda_states G \\<and> edge_trg e2 \\<in> epda_states G \\<and> option_to_set (edge_event e2) \\<subseteq> epda_events G \\<and> edge_pop e2 \\<in> may_terminated_by (epda_gamma G) (epda_box G) \\<and> edge_push e2 \\<in> may_terminated_by (epda_gamma G) (epda_box G) \\<and> (edge_pop e2 \\<in> must_terminated_by (epda_gamma G) (epda_box G)) = (edge_push e2 \\<in> must_terminated_by (epda_gamma G) (epda_box G))\"\n      in ballE)\n     apply(rename_tac y w)(*strict*)\n     apply(clarsimp)\n     apply(simp add: option_to_set_def)\n    apply(rename_tac y w)(*strict*)\n    apply(simp add: epdaH_step_relation_def option_to_list_def)\n   apply(rename_tac y)(*strict*)\n   apply(simp add: epda_effects_def)\n  apply(rename_tac y)(*strict*)\n  apply(simp add: prefix_def)\n  done\n\ntheorem epda_Cont_to_epda_operational_controllable: \"\n  valid_dpda G\n  \\<Longrightarrow> valid_dfa P\n  \\<Longrightarrow> controllable_sublanguage (epdaH.unmarked_language G) (alphabet_to_language SigmaUC) (epdaH.unmarked_language P) (epdaH.unmarked_language G)\n  \\<Longrightarrow> epda_operational_controllable G P SigmaUC\"\n  apply(simp add: epda_operational_controllable_def)\n  apply(clarsimp)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n  apply(case_tac c1)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u epdaH_conf_state epdaH_conf_historya epdaH_conf_stack)(*strict*)\n  apply(case_tac c2)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u epdaH_conf_state epdaH_conf_historya epdaH_conf_stack epdaH_conf_statea epdaH_conf_historyaa epdaH_conf_stacka)(*strict*)\n  apply(case_tac c2')\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u epdaH_conf_state epdaH_conf_historya epdaH_conf_stack epdaH_conf_statea epdaH_conf_historyaa epdaH_conf_stacka epdaH_conf_stateb epdaH_conf_historyb epdaH_conf_stackb)(*strict*)\n  apply(rename_tac q1 h1 s1 q2 h2 s2 q2' h2' s2')\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u q1 h1 s1 q2 h2 s2 q2' h2' s2')(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 n1 e1 d2 n2 e2 e2' u q1 s1 q2 h2 s2 q2' s2')(*strict*)\n  apply(simp add: controllable_sublanguage_def)\n  apply(erule_tac\n      x = \"h2\"\n      in ballE)\n   apply(rename_tac d1 n1 e1 d2 n2 e2 e2' u q1 s1 q2 h2 s2 q2' s2')(*strict*)\n   prefer 2\n   apply(subgoal_tac \"h2 \\<in> epdaH.unmarked_language G\")\n    apply(rename_tac d1 n1 e1 d2 n2 e2 e2' u q1 s1 q2 h2 s2 q2' s2')(*strict*)\n    apply(force)\n   apply(rename_tac d1 n1 e1 d2 n2 e2 e2' u q1 s1 q2 h2 s2 q2' s2')(*strict*)\n   apply(thin_tac \"h2 \\<notin> epdaH.unmarked_language G\")\n   apply(simp add: epdaH.unmarked_language_def)\n   apply(rule_tac\n      x = \"d1\"\n      in exI)\n   apply(clarsimp)\n   apply(simp add: epdaH.derivation_initial_def)\n   apply(simp add: epdaH_unmarked_effect_def)\n   apply(rule_tac\n      x = \"n1\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac d1 n1 e1 d2 n2 e2 e2' u q1 s1 q2 h2 s2 q2' s2')(*strict*)\n  apply(simp add: controllable_word_def)\n  apply(erule_tac\n      x = \"[u]\"\n      in ballE)\n   apply(rename_tac d1 n1 e1 d2 n2 e2 e2' u q1 s1 q2 h2 s2 q2' s2')(*strict*)\n   prefer 2\n   apply(simp add: alphabet_to_language_def)\n  apply(rename_tac d1 n1 e1 d2 n2 e2 e2' u q1 s1 q2 h2 s2 q2' s2')(*strict*)\n  apply(erule impE)\n   apply(rename_tac d1 n1 e1 d2 n2 e2 e2' u q1 s1 q2 h2 s2 q2' s2')(*strict*)\n   apply(simp add: epdaH.unmarked_language_def)\n   apply(rule_tac\n      x = \"d2\"\n      in exI)\n   apply(clarsimp)\n   apply(simp add: epdaH.derivation_initial_def)\n   apply(simp add: epdaH_unmarked_effect_def)\n   apply(rule_tac\n      x = \"Suc n2\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac d1 n1 e1 d2 n2 e2 e2' u q1 s1 q2 h2 s2 q2' s2')(*strict*)\n  apply(simp add: epdaH.unmarked_language_def)\n  apply(clarsimp)\n  apply(rename_tac d1 n1 e1 d2 n2 e2 e2' u q1 s1 q2 h2 s2 q2' s2' d)(*strict*)\n  apply(thin_tac \"epdaH.derivation_initial P d2\")\n  apply(thin_tac \"d2 n2 = Some (pair e2 \\<lparr>epdaH_conf_state = q2, epdaH_conf_history = h2, epdaH_conf_stack = s2\\<rparr>)\")\n  apply(rename_tac d1 n1 e1 d2 n2 e2 e2' u q1 s1 q2 h2 s2 q2' s2' d)(*strict*)\n  apply(thin_tac \"d2 (Suc n2) = Some (pair e2' \\<lparr>epdaH_conf_state = q2', epdaH_conf_history = h2 @ [u], epdaH_conf_stack = s2'\\<rparr>)\")\n  apply(rename_tac d1 n1 e1 d2 n2 e2 e2' u q1 s1 q2 h2 s2 q2' s2' d)(*strict*)\n  apply(simp add: epdaH_unmarked_effect_def)\n  apply(rename_tac d1 n1 e1 u q1 s1 h2 d)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 n1 e1 u q1 s1 h2 d i e c)(*strict*)\n  apply(case_tac c)\n  apply(rename_tac d1 n1 e1 u q1 s1 h2 d i e c epdaH_conf_state epdaH_conf_historya epdaH_conf_stack)(*strict*)\n  apply(rename_tac q h s)\n  apply(rename_tac d1 n1 e1 u q1 s1 h2 d i e c q h s)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 n1 e1 u q1 s1 h2 d i e q s)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1 n1 e1 u q1 s1 h2 d i e q s)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G = \"G\"\n      and ?d1.0 = \"d1\"\n      and ?d2.0 = \"d\"\n      and ?i1.0 = \"n1\"\n      and ?i2.0 = \"i\"\n      in epdaH_coincide_strict_prefix)\n        apply(rename_tac d1 n1 e1 u q1 s1 h2 d i e q s)(*strict*)\n        apply(force)\n       apply(rename_tac d1 n1 e1 u q1 s1 h2 d i e q s)(*strict*)\n       apply(force)\n      apply(rename_tac d1 n1 e1 u q1 s1 h2 d i e q s)(*strict*)\n      apply(force)\n     apply(rename_tac d1 n1 e1 u q1 s1 h2 d i e q s)(*strict*)\n     apply(clarsimp)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac d1 n1 e1 u q1 s1 h2 d i e q s)(*strict*)\n    apply(clarsimp)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac d1 n1 e1 u q1 s1 h2 d i e q s)(*strict*)\n   apply(simp add: strict_prefix_def)\n  apply(rename_tac d1 n1 e1 u q1 s1 h2 d i e q s)(*strict*)\n  apply(clarsimp)\n  apply(erule_tac\n      x = \"n1\"\n      in allE)\n  apply(clarsimp)\n  apply(case_tac \"i = n1\")\n   apply(rename_tac d1 n1 e1 u q1 s1 h2 d i e q s)(*strict*)\n   prefer 2\n   apply(rule_tac\n      x = \"derivation_drop d n1\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac d1 n1 e1 u q1 s1 h2 d i e q s)(*strict*)\n    apply(rule_tac\n      m = \"i-n1\"\n      in epdaH.derivation_drop_preserves_derivation_prime)\n     apply(rename_tac d1 n1 e1 u q1 s1 h2 d i e q s)(*strict*)\n     apply(force)\n    apply(rename_tac d1 n1 e1 u q1 s1 h2 d i e q s)(*strict*)\n    apply(force)\n   apply(rename_tac d1 n1 e1 u q1 s1 h2 d i e q s)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d1 n1 e1 u q1 s1 h2 d i e q s)(*strict*)\n    apply(simp add: derivation_drop_def)\n   apply(rename_tac d1 n1 e1 u q1 s1 h2 d i e q s)(*strict*)\n   apply(rule_tac\n      x = \"i-n1\"\n      in exI)\n   apply(simp add: derivation_drop_def)\n  apply(rename_tac d1 n1 e1 u q1 s1 h2 d i e q s)(*strict*)\n  apply(clarsimp)\n  done\n\ntheorem epda_epda_operational_controllable_to_Cont: \"\n  valid_dpda G\n  \\<Longrightarrow> valid_dfa P\n  \\<Longrightarrow> epda_operational_controllable G P SigmaUC\n  \\<Longrightarrow> controllable_sublanguage (epdaH.unmarked_language G) (alphabet_to_language SigmaUC) (epdaH.unmarked_language P) (epdaH.unmarked_language G)\"\n  apply(simp add: controllable_sublanguage_def controllable_word_def)\n  apply(clarsimp)\n  apply(rename_tac w' u)(*strict*)\n  apply(simp add: alphabet_to_language_def)\n  apply(clarsimp)\n  apply(rename_tac w' v)(*strict*)\n  apply(simp add: epdaH.unmarked_language_def)\n  apply(clarsimp)\n  apply(rename_tac w' v d da)(*strict*)\n  apply(thin_tac \"epdaH.derivation G d\")\n  apply(thin_tac \"epdaH.derivation P da\")\n  apply(simp add: epdaH_unmarked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac v d da i ia e ea c ca)(*strict*)\n  apply(case_tac c)\n  apply(rename_tac v d da i ia e ea c ca epdaH_conf_state epdaH_conf_historya epdaH_conf_stack)(*strict*)\n  apply(case_tac ca)\n  apply(rename_tac v d da i ia e ea c ca epdaH_conf_state epdaH_conf_historya epdaH_conf_stack epdaH_conf_statea epdaH_conf_historyaa epdaH_conf_stacka)(*strict*)\n  apply(rename_tac q1 h1 s1 q2 h2 s2)\n  apply(rename_tac v d da i ia e ea c ca q1 h1 s1 q2 h2 s2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac v d da i ia e ea q1 h1 s1 q2 s2)(*strict*)\n  apply(case_tac ia)\n   apply(rename_tac v d da i ia e ea q1 h1 s1 q2 s2)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac v d da i e ea q1 h1 s1 q2 s2)(*strict*)\n   apply(simp add: epdaH.derivation_initial_def)\n   apply(clarsimp)\n   apply(rename_tac v d da i e q1 h1 s1 q2 s2)(*strict*)\n   apply(case_tac \"da 0\")\n    apply(rename_tac v d da i e q1 h1 s1 q2 s2)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac v d da i e q1 h1 s1 q2 s2 a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac v d da i e q1 h1 s1 q2 s2)(*strict*)\n   apply(simp add: epdaH_initial_configurations_def)\n  apply(rename_tac v d da i ia e ea q1 h1 s1 q2 s2 nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac v d da i e ea q1 h1 s1 q2 s2 nat)(*strict*)\n  apply(rename_tac ia)\n  apply(rename_tac v d da i e ea q1 h1 s1 q2 s2 ia)(*strict*)\n  apply(simp add: epda_operational_controllable_def)\n  apply(erule_tac\n      x = \"d\"\n      in allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x = \"i\"\n      in allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x = \"da\"\n      in allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x = \"ia\"\n      in allE)\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac v d da i e ea q1 h1 s1 q2 s2 ia)(*strict*)\n   prefer 2\n   apply(rule_tac\n      n = \"ia\"\n      and m = \"Suc ia\"\n      and G = \"P\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac v d da i e ea q1 h1 s1 q2 s2 ia)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n     apply(force)\n    apply(rename_tac v d da i e ea q1 h1 s1 q2 s2 ia)(*strict*)\n    apply(force)\n   apply(rename_tac v d da i e ea q1 h1 s1 q2 s2 ia)(*strict*)\n   apply(force)\n  apply(rename_tac v d da i e ea q1 h1 s1 q2 s2 ia)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac v d da i e q1 h1 s1 q2 s2 ia e1 e2 c1)(*strict*)\n  apply(case_tac c1)\n  apply(rename_tac v d da i e q1 h1 s1 q2 s2 ia e1 e2 c1 epdaH_conf_state epdaH_conf_historya epdaH_conf_stack)(*strict*)\n  apply(rename_tac q3 h3 s3)\n  apply(rename_tac v d da i e q1 h1 s1 q2 s2 ia e1 e2 c1 q3 h3 s3)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac v d da i e q1 h1 s1 q2 s2 ia e1 e2 q3 h3 s3)(*strict*)\n  apply(subgoal_tac \"h1 = h3\")\n   apply(rename_tac v d da i e q1 h1 s1 q2 s2 ia e1 e2 q3 h3 s3)(*strict*)\n   prefer 2\n   apply(simp add: epdaH_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac v d da i e q1 h1 s1 ia e1 e2 h3 w)(*strict*)\n   apply(case_tac \"e2\")\n   apply(rename_tac v d da i e q1 h1 s1 ia e1 e2 h3 w edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n   apply(rename_tac qs re po pu qt)\n   apply(rename_tac v d da i e q1 h1 s1 ia e1 e2 h3 w qs re po pu qt)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac v d da i e q1 h1 s1 ia e1 h3 w qs re po pu qt)(*strict*)\n   apply(case_tac re)\n    apply(rename_tac v d da i e q1 h1 s1 ia e1 h3 w qs re po pu qt)(*strict*)\n    apply(simp add: valid_dfa_def)\n    apply(force)\n   apply(rename_tac v d da i e q1 h1 s1 ia e1 h3 w qs re po pu qt a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac v d da i e q1 h1 s1 ia e1 h3 w qs po pu qt a)(*strict*)\n   apply(simp add: option_to_list_def)\n  apply(rename_tac v d da i e q1 h1 s1 q2 s2 ia e1 e2 q3 h3 s3)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac v d da i e q1 s1 q2 s2 ia e1 e2 q3 h3 s3 dc nC eC cC)(*strict*)\n  apply(case_tac nC)\n   apply(rename_tac v d da i e q1 s1 q2 s2 ia e1 e2 q3 h3 s3 dc nC eC cC)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac v d da i e q1 s1 q2 s2 ia e1 e2 q3 h3 s3 dc nC eC cC nat)(*strict*)\n  apply(rule_tac\n      x = \"derivation_append d dc i\"\n      in exI)\n  apply(rule context_conjI)\n   apply(rename_tac v d da i e q1 s1 q2 s2 ia e1 e2 q3 h3 s3 dc nC eC cC nat)(*strict*)\n   apply(rule epdaH.derivation_append_preserves_derivation_initial)\n     apply(rename_tac v d da i e q1 s1 q2 s2 ia e1 e2 q3 h3 s3 dc nC eC cC nat)(*strict*)\n     apply(simp add: valid_dfa_def valid_dpda_def valid_pda_def)\n    apply(rename_tac v d da i e q1 s1 q2 s2 ia e1 e2 q3 h3 s3 dc nC eC cC nat)(*strict*)\n    apply(force)\n   apply(rename_tac v d da i e q1 s1 q2 s2 ia e1 e2 q3 h3 s3 dc nC eC cC nat)(*strict*)\n   apply(rule epdaH.derivation_append_preserves_derivation)\n     apply(rename_tac v d da i e q1 s1 q2 s2 ia e1 e2 q3 h3 s3 dc nC eC cC nat)(*strict*)\n     apply(rule epdaH.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac v d da i e q1 s1 q2 s2 ia e1 e2 q3 h3 s3 dc nC eC cC nat)(*strict*)\n    apply(force)\n   apply(rename_tac v d da i e q1 s1 q2 s2 ia e1 e2 q3 h3 s3 dc nC eC cC nat)(*strict*)\n   apply(force)\n  apply(rename_tac v d da i e q1 s1 q2 s2 ia e1 e2 q3 h3 s3 dc nC eC cC nat)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac v d da i e q1 s1 q2 s2 ia e1 e2 q3 h3 s3 dc nC eC cC nat)(*strict*)\n   apply(rule_tac\n      x = \"i+nC\"\n      in exI)\n   apply(simp add: derivation_append_def der2_def)\n  apply(rename_tac v d da i e q1 s1 q2 s2 ia e1 e2 q3 h3 s3 dc nC eC cC nat)(*strict*)\n  apply(rule epdaH.derivation_initial_is_derivation)\n  apply(force)\n  done\n\ntheorem epda_epda_operational_controllable_vs_Cont: \"\n  valid_dpda G\n  \\<Longrightarrow> valid_dfa P\n  \\<Longrightarrow> epda_operational_controllable G P SigmaUC \\<longleftrightarrow> controllable_sublanguage (epdaH.unmarked_language G) (alphabet_to_language SigmaUC) (epdaH.unmarked_language P) (epdaH.unmarked_language G)\"\n  apply (metis epda_Cont_to_epda_operational_controllable epda_epda_operational_controllable_to_Cont)\n  done\n\ntheorem epda_Cont_eq_to_epda_operational_controllable_eq: \"\n  valid_dpda G\n  \\<Longrightarrow> valid_dpda G'\n  \\<Longrightarrow> valid_dfa P\n  \\<Longrightarrow> controllable_sublanguage (epdaH.unmarked_language G) (alphabet_to_language SigmaUC) (epdaH.unmarked_language P) (epdaH.unmarked_language G) \\<longleftrightarrow>\n  controllable_sublanguage (epdaH.unmarked_language G') (alphabet_to_language SigmaUC) (epdaH.unmarked_language P) (epdaH.unmarked_language G')\n  \\<Longrightarrow> epda_operational_controllable G P SigmaUC \\<longleftrightarrow> epda_operational_controllable G' P SigmaUC\"\n  apply(metis epda_Cont_to_epda_operational_controllable epda_epda_operational_controllable_to_Cont)\n  done\n\ntheorem epda_Cont_eq_to_epda_operational_controllable_eq2: \"\n  valid_dpda G\n  \\<Longrightarrow> valid_dpda G'\n  \\<Longrightarrow> valid_dfa P\n  \\<Longrightarrow> epdaH.unmarked_language G = epdaH.unmarked_language G'\n  \\<Longrightarrow> epda_operational_controllable G P SigmaUC \\<longleftrightarrow> epda_operational_controllable G' P SigmaUC\"\n  apply(rule epda_Cont_eq_to_epda_operational_controllable_eq)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(force)\n  done\n\nlemma epda_marking_states_change_preserves_determinism: \"\n  valid_dpda G\n  \\<Longrightarrow> epdaS.is_forward_edge_deterministic_accessible (G\\<lparr>epda_marking:= Q\\<rparr>)\"\n  apply(simp add: valid_dpda_def epdaS.is_forward_edge_deterministic_accessible_def)\n  apply(clarsimp)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(erule_tac\n      x = \"c\"\n      in ballE)\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   apply(erule_tac\n      x = \"c1\"\n      in allE)\n   apply(erule_tac\n      x = \"c2\"\n      in allE)\n   apply(erule_tac\n      x = \"e1\"\n      in allE)\n   apply(erule_tac\n      x = \"e2\"\n      in allE)\n   apply(simp add: epdaS_step_relation_def)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(simp add: epdaS.get_accessible_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac c c1 c2 e1 e2 d i)(*strict*)\n  apply(erule_tac\n      x = \"d\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac c c1 c2 e1 e2 d i)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2 d i)(*strict*)\n  apply(thin_tac \"epdaS_step_relation (G\\<lparr>epda_marking := Q\\<rparr>) c e1 c1\")\n  apply(thin_tac \"epdaS_step_relation (G\\<lparr>epda_marking := Q\\<rparr>) c e2 c2\")\n  apply(thin_tac \"get_configuration (d i) = Some c\")\n  apply(simp add: epdaS.derivation_initial_def)\n  apply(rename_tac d)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"d 0\")\n   apply(rename_tac d)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac d a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d b)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac d b)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_initial_configurations_def epdaS_configurations_def)\n  apply(rename_tac d b)(*strict*)\n  apply(thin_tac \"b \\<in> epdaS_initial_configurations (G\\<lparr>epda_marking := Q\\<rparr>)\")\n  apply(simp (no_asm) add: epdaS.derivation_def)\n  apply(clarsimp)\n  apply(rename_tac d b i)(*strict*)\n  apply(case_tac i)\n   apply(rename_tac d b i)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d b i nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d b nat)(*strict*)\n  apply(case_tac \"d (Suc nat)\")\n   apply(rename_tac d b nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d b nat a)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d b nat a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      n = \"nat\"\n      and m = \"Suc nat\"\n      in epdaS.step_detail_before_some_position)\n     apply(rename_tac d b nat a)(*strict*)\n     apply(force)\n    apply(rename_tac d b nat a)(*strict*)\n    apply(force)\n   apply(rename_tac d b nat a)(*strict*)\n   apply(force)\n  apply(rename_tac d b nat a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d b nat e1 e2 c1 c2)(*strict*)\n  apply(simp add: epdaS_step_relation_def)\n  done\n\nlemma epdaH_epda_stack_is_must_terminated_by_prime: \"\n  valid_epda G\n  \\<Longrightarrow> epdaH.derivation_initial G d\n  \\<Longrightarrow> d i = Some (pair e c)\n  \\<Longrightarrow> epdaH_conf_stack c \\<in> must_terminated_by (epda_gamma G) (epda_box G)\"\n  apply(induct i arbitrary: e c)\n   apply(rename_tac e c)(*strict*)\n   apply(simp add: epdaH.derivation_initial_def epdaH_initial_configurations_def)\n   apply(simp add: must_terminated_by_def kleene_star_def append_language_def)\n  apply(rename_tac i e c)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d i = Some (pair e1 c1) \\<and> SSd (Suc SSn) = Some (pair (Some e2) c2) \\<and> epdaH_step_relation SSG c1 e2 c2\" for SSd SSn SSG)\n   apply(rename_tac i e c)(*strict*)\n   prefer 2\n   apply(rule epdaH.step_detail_before_some_position)\n     apply(rename_tac i e c)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n     apply(force)\n    apply(rename_tac i e c)(*strict*)\n    apply(force)\n   apply(rename_tac i e c)(*strict*)\n   apply(force)\n  apply(rename_tac i e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1)(*strict*)\n  apply(erule_tac\n      x = \"e1\"\n      in meta_allE)\n  apply(erule_tac\n      x = \"c1\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(simp add: epdaH_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1 w)(*strict*)\n  apply(subgoal_tac \"valid_epda_step_label G e2\")\n   apply(rename_tac i c e1 e2 c1 w)(*strict*)\n   prefer 2\n   apply(simp add: valid_epda_def)\n  apply(rename_tac i c e1 e2 c1 w)(*strict*)\n  apply(simp add: must_terminated_by_def kleene_star_def append_language_def)\n  apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1 w a)(*strict*)\n  apply(case_tac w)\n   apply(rename_tac i c e1 e2 c1 w a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i c e1 e2 c1 a)(*strict*)\n   apply(simp add: valid_epda_step_label_def)\n   apply(clarsimp)\n   apply(simp add: may_terminated_by_def must_terminated_by_def kleene_star_def append_language_def)\n  apply(rename_tac i c e1 e2 c1 w a aa list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. w = w' @ [x']\")\n   apply(rename_tac i c e1 e2 c1 w a aa list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac i c e1 e2 c1 w a aa list)(*strict*)\n  apply(thin_tac \"w = aa # list\")\n  apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1 w' x)(*strict*)\n  apply(simp add: valid_epda_step_label_def)\n  apply(clarsimp)\n  apply(simp add: may_terminated_by_def must_terminated_by_def kleene_star_def append_language_def)\n  apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1 w' x a aa)(*strict*)\n  apply(force)\n  done\n\nlemma epdaH_epda_stack_is_must_terminated_by: \"\n  valid_epda G\n  \\<Longrightarrow> c \\<in> epdaH.get_accessible_configurations G\n  \\<Longrightarrow> epdaH_conf_stack c \\<in> must_terminated_by (epda_gamma G) (epda_box G)\"\n  apply(simp add: epdaH.get_accessible_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac d i)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(case_tac \"d i\")\n   apply(rename_tac d i)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d i a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac d i a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i option)(*strict*)\n  apply(rename_tac e)\n  apply(rename_tac d i e)(*strict*)\n  apply(rule epdaH_epda_stack_is_must_terminated_by_prime)\n    apply(rename_tac d i e)(*strict*)\n    apply(force)\n   apply(rename_tac d i e)(*strict*)\n   apply(force)\n  apply(rename_tac d i e)(*strict*)\n  apply(force)\n  done\n\nlemma DPDA_to_epdaH_determinism_SB_FE: \"\n  valid_dpda G\n  \\<Longrightarrow> epdaH.is_forward_edge_deterministicHist_SB_long G\"\n  apply(subgoal_tac \"epdaH.is_forward_edge_deterministicHist_DB_long G\")\n   prefer 2\n   apply(rule DPDA_to_epdaH_determinism)\n   apply(force)\n  apply(simp add: valid_dpda_def valid_pda_def)\n  apply(clarsimp)\n  apply(rule_tac\n      t = \"epdaH.is_forward_edge_deterministicHist_SB_long G\"\n      in ssubst)\n   apply(rule epdaH.AX_is_forward_edge_deterministic_correspond_DB_SB)\n   apply(force)\n  apply(force)\n  done\n\nlemma DPDA_to_epdaH_determinism_SB_F: \"\n  valid_dpda G\n  \\<Longrightarrow> epdaH.is_forward_deterministicHist_SB G\"\n  apply(rule I_epda_lemmas.DPDA_is_is_forward_deterministicHist_SB)\n  apply(force)\n  done\n\ninterpretation \"epdaH_vs_epdaH\" : L_Controllable\n  (* TSstructure *)\n  \"valid_epda\"\n  (* configurations *)\n  \"epdaH_configurations\"\n  (* initial_configurations *)\n  \"epdaH_initial_configurations\"\n  (* step_labels *)\n  \"epda_step_labels\"\n  (* step_relation *)\n  \"epdaH_step_relation\"\n  (* effects *)\n  \"epda_effects\"\n  (* marking_condition *)\n  \"epdaH_marking_condition\"\n  (* marked_effect *)\n  \"epdaH_marked_effect\"\n  (* unmarked_effect *)\n  \"epdaH_unmarked_effect\"\n  (* TSstructure *)\n  \"valid_epda\"\n  (* configurations *)\n  \"epdaH_configurations\"\n  (* initial_configurations *)\n  \"epdaH_initial_configurations\"\n  (* step_labels *)\n  \"epda_step_labels\"\n  (* step_relation *)\n  \"epdaH_step_relation\"\n  (* effects *)\n  \"epda_effects\"\n  (* marking_condition *)\n  \"epdaH_marking_condition\"\n  (* marked_effect *)\n  \"epdaH_marked_effect\"\n  (* unmarked_effect *)\n  \"epdaH_unmarked_effect\"\n  apply(simp add: L_Controllable_def LOCALE_DEFS_ALL LOCALE_DEFS_autHF)\n  apply(simp add: epdaH_inst_AX_initial_configuration_belongs epdaH_inst_AX_step_relation_preserves_belongs epdaH_inst_ATS_axioms)\n  done\n\nlemma epda_unmarked_language_is_prefix_closure: \"\n  valid_epda G\n  \\<Longrightarrow> epdaH.derivation_initial G d\n  \\<Longrightarrow> maximum_of_domain d n\n  \\<Longrightarrow> d n = Some (pair e c)\n  \\<Longrightarrow> epdaH_unmarked_effect G d = prefix_closure {epdaH_conf_history c}\"\n  apply(induct n arbitrary: d e c)\n   apply(rename_tac d e c)(*strict*)\n   apply(simp add: epdaH_unmarked_effect_def epdaH.derivation_initial_def epdaH_initial_configurations_def prefix_def prefix_closure_def)\n   apply(clarsimp)\n   apply(rename_tac d c)(*strict*)\n   apply(rule antisym)\n    apply(rename_tac d c)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d c i e ca)(*strict*)\n    apply(case_tac i)\n     apply(rename_tac d c i e ca)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d c i e ca nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d c e ca nat)(*strict*)\n    apply (metis Suc_le_D Zero_not_Suc epdaH.allPreMaxDomSome_prime option.discI)\n   apply(rename_tac d c)(*strict*)\n   apply(clarsimp)\n   apply(rule_tac\n      x = \"0\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac n d e c)(*strict*)\n  apply(erule_tac\n      x = \"derivation_take d n\"\n      in meta_allE)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d n = Some (pair e1 c1) \\<and> SSd (Suc SSn) = Some (pair (Some e2) c2) \\<and> epdaH_step_relation SSG c1 e2 c2\" for SSd SSn SSG)\n   apply(rename_tac n d e c)(*strict*)\n   prefer 2\n   apply(rule epdaH.step_detail_before_some_position)\n     apply(rename_tac n d e c)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n     apply(force)\n    apply(rename_tac n d e c)(*strict*)\n    apply(force)\n   apply(rename_tac n d e c)(*strict*)\n   apply(force)\n  apply(rename_tac n d e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n d c e1 e2 c1)(*strict*)\n  apply(erule_tac\n      x = \"e1\"\n      in meta_allE)\n  apply(erule_tac\n      x = \"c1\"\n      in meta_allE)\n  apply(erule meta_impE)\n   apply(rename_tac n d c e1 e2 c1)(*strict*)\n   apply(rule epdaH.derivation_take_preserves_derivation_initial)\n   apply(force)\n  apply(rename_tac n d c e1 e2 c1)(*strict*)\n  apply(erule meta_impE)\n   apply(rename_tac n d c e1 e2 c1)(*strict*)\n   apply (metis maximum_of_domain_derivation_take option.discI)\n  apply(rename_tac n d c e1 e2 c1)(*strict*)\n  apply(erule meta_impE)\n   apply(rename_tac n d c e1 e2 c1)(*strict*)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac n d c e1 e2 c1)(*strict*)\n  apply(simp add: epdaH_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac n d c e1 e2 c1 w)(*strict*)\n  apply(case_tac c1)\n  apply(rename_tac n d c e1 e2 c1 w epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n  apply(rename_tac q1 h1 s1)\n  apply(rename_tac n d c e1 e2 c1 w q1 h1 s1)(*strict*)\n  apply(case_tac c)\n  apply(rename_tac n d c e1 e2 c1 w q1 h1 s1 epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n  apply(rename_tac q2 h2 s2)\n  apply(rename_tac n d c e1 e2 c1 w q1 h1 s1 q2 h2 s2)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(clarsimp)\n  apply(rename_tac n d e1 e2 w h1)(*strict*)\n  apply(simp add: epdaH_unmarked_effect_def)\n  apply(rule antisym)\n   apply(rename_tac n d e1 e2 w h1)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n d e1 e2 w h1 i e c)(*strict*)\n   apply(case_tac \"i = Suc n\")\n    apply(rename_tac n d e1 e2 w h1 i e c)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac n d e1 e2 w h1)(*strict*)\n    apply(simp add: epdaH_unmarked_effect_def epdaH.derivation_initial_def epdaH_initial_configurations_def prefix_def prefix_closure_def)\n   apply(rename_tac n d e1 e2 w h1 i e c)(*strict*)\n   apply(case_tac \"i = n\")\n    apply(rename_tac n d e1 e2 w h1 i e c)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac n d e2 w h1 e)(*strict*)\n    apply(simp add: epdaH_unmarked_effect_def epdaH.derivation_initial_def epdaH_initial_configurations_def prefix_def prefix_closure_def)\n   apply(rename_tac n d e1 e2 w h1 i e c)(*strict*)\n   apply(subgoal_tac \"i\\<le>Suc n\")\n    apply(rename_tac n d e1 e2 w h1 i e c)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d = \"d\"\n      and i = \"i\"\n      and n = \"Suc n\"\n      in epdaH.allPreMaxDomSome_prime)\n      apply(rename_tac n d e1 e2 w h1 i e c)(*strict*)\n      apply(simp add: epdaH.derivation_initial_def)\n      apply(force)\n     apply(rename_tac n d e1 e2 w h1 i e c)(*strict*)\n     apply(force)\n    apply(rename_tac n d e1 e2 w h1 i e c)(*strict*)\n    apply(force)\n   apply(rename_tac n d e1 e2 w h1 i e c)(*strict*)\n   apply(subgoal_tac \"i<n\")\n    apply(rename_tac n d e1 e2 w h1 i e c)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac n d e1 e2 w h1 i e c)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"\\<exists>h\\<in> epda_effects G. epdaH_conf_history \\<lparr>epdaH_conf_state = edge_src e2, epdaH_conf_history = h1, epdaH_conf_stack = edge_pop e2 @ w\\<rparr> = epdaH_conf_history c @ h\")\n    apply(rename_tac n d e1 e2 w h1 i e c)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d = \"d\"\n      and n = \"i\"\n      and m = \"n-i\"\n      in epdaH.steps_extend_history_derivation)\n        apply(rename_tac n d e1 e2 w h1 i e c)(*strict*)\n        apply(force)\n       apply(rename_tac n d e1 e2 w h1 i e c)(*strict*)\n       apply(simp add: epdaH.derivation_initial_def)\n      apply(rename_tac n d e1 e2 w h1 i e c)(*strict*)\n      apply (metis (no_types, hide_lams) epdaH.derivation_initial_configurations)\n     apply(rename_tac n d e1 e2 w h1 i e c)(*strict*)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac n d e1 e2 w h1 i e c)(*strict*)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac n d e1 e2 w h1 i e c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n d e1 e2 w i e c h)(*strict*)\n   apply(simp add: epda_effects_def)\n   apply(simp add: prefix_closure_def prefix_def)\n  apply(rename_tac n d e1 e2 w h1)(*strict*)\n  apply(simp (no_asm) add: prefix_closure_def prefix_def)\n  apply(clarsimp)\n  apply(rename_tac n d e1 e2 w h1 x c)(*strict*)\n  apply(case_tac \"edge_event e2\")\n   apply(rename_tac n d e1 e2 w h1 x c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n d e1 e2 w x c)(*strict*)\n   apply(subgoal_tac \"x\\<in> {w. \\<exists>i e c. derivation_take d n i = Some (pair e c) \\<and> w = epdaH_conf_history c}\")\n    apply(rename_tac n d e1 e2 w x c)(*strict*)\n    prefer 2\n    apply(rule_tac\n      A = \"prefix_closure {x @ c}\"\n      in set_mp)\n     apply(rename_tac n d e1 e2 w x c)(*strict*)\n     apply(force)\n    apply(rename_tac n d e1 e2 w x c)(*strict*)\n    apply(simp (no_asm) add: prefix_closure_def prefix_def)\n   apply(rename_tac n d e1 e2 w x c)(*strict*)\n   apply(thin_tac \"{w. \\<exists>i e c. derivation_take d n i = Some (pair e c) \\<and> w = epdaH_conf_history c} = prefix_closure {x @ c}\")\n   apply(clarsimp)\n   apply(rename_tac n d e1 e2 w c i e ca)(*strict*)\n   apply(rule_tac\n      x = \"i\"\n      in exI)\n   apply(simp add: derivation_take_def)\n   apply(case_tac \"i\\<le>n\")\n    apply(rename_tac n d e1 e2 w c i e ca)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac n d e1 e2 w c i e ca)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac n d e1 e2 w h1 x c a)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n      xs = \"c\"\n      in rev_cases)\n   apply(rename_tac n d e1 e2 w h1 x c a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n d e1 e2 w h1 a)(*strict*)\n   apply(rule_tac\n      x = \"Suc n\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac n d e1 e2 w h1 x c a ys y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n d e1 e2 w x a ys)(*strict*)\n  apply(subgoal_tac \"x\\<in> {w. \\<exists>i e c. derivation_take d n i = Some (pair e c) \\<and> w = epdaH_conf_history c}\")\n   apply(rename_tac n d e1 e2 w x a ys)(*strict*)\n   prefer 2\n   apply(rule_tac\n      A = \"prefix_closure {x @ ys}\"\n      in set_mp)\n    apply(rename_tac n d e1 e2 w x a ys)(*strict*)\n    apply(force)\n   apply(rename_tac n d e1 e2 w x a ys)(*strict*)\n   apply(simp (no_asm) add: prefix_closure_def prefix_def)\n  apply(rename_tac n d e1 e2 w x a ys)(*strict*)\n  apply(thin_tac \"{w. \\<exists>i e c. derivation_take d n i = Some (pair e c) \\<and> w = epdaH_conf_history c} = prefix_closure {x @ ys}\")\n  apply(clarsimp)\n  apply(rename_tac n d e1 e2 w a ys i e c)(*strict*)\n  apply(rule_tac\n      x = \"i\"\n      in exI)\n  apply(simp add: derivation_take_def)\n  apply(case_tac \"i\\<le>n\")\n   apply(rename_tac n d e1 e2 w a ys i e c)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac n d e1 e2 w a ys i e c)(*strict*)\n  apply(clarsimp)\n  done\n\ntheorem DES_controllability_vs_controllable_sublanguage: \"\n  DES_controllability \\<Sigma>UC P C \\<longleftrightarrow>\n  controllable_sublanguage (des_langUM C) (alphabet_to_language \\<Sigma>UC) (des_langUM P) (des_langUM C)\"\n  apply(rule order_antisym)\n   apply(clarsimp)\n   apply(simp add: DES_controllability_def controllable_sublanguage_def controllable_language_def controllable_word_def alphabet_to_language_def append_alphabet_def append_language_def)\n   apply(force)\n  apply(clarsimp)\n  apply(simp add: DES_controllability_def controllable_sublanguage_def controllable_language_def controllable_word_def alphabet_to_language_def append_alphabet_def append_language_def)\n  apply(force)\n  done\n\ntheorem DES_controllability_implies_operational_controllability: \"\n  valid_dfa P\n  \\<Longrightarrow> valid_dpda C\n  \\<Longrightarrow> epda_events P = epda_events C\n  \\<Longrightarrow> \\<Sigma>UC \\<subseteq> epda_events P\n  \\<Longrightarrow> ucont = (\\<lambda>w. (\\<exists>v. \\<exists>x\\<in> \\<Sigma>UC. w = v@[x]))\n  \\<Longrightarrow> DES_controllability \\<Sigma>UC (epda_to_des P) (epda_to_des C)\n  \\<Longrightarrow> epdaH_vs_epdaH.controllable C P ucont\"\n  apply(simp add: epdaH_vs_epdaH.controllable_def)\n  apply(clarsimp)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n  apply(subgoal_tac \"v @ [x] \\<notin> epdaH_unmarked_effect P dP\")\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n  apply(subgoal_tac \"edge_event eP' = Some x\")\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   prefer 2\n   apply(thin_tac \"epdaH_unmarked_effect P dP = epdaH_unmarked_effect C dC\")\n   apply(simp add: epdaH_unmarked_effect_def)\n   apply(clarsimp)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n   apply(case_tac \"i = Suc nP\")\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x e c)(*strict*)\n    apply(simp add: derivation_append_def der2_def)\n    apply(clarsimp)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' v x c)(*strict*)\n    apply(case_tac c)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' v x c epdaH_conf_state epdaH_conf_historya epdaH_conf_stack)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' v x epdaH_conf_state epdaH_conf_stack)(*strict*)\n    apply(rename_tac q s)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' v x q s)(*strict*)\n    apply(simp add: epdaH_step_relation_def)\n    apply(clarsimp)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' v x w)(*strict*)\n    apply(simp add: valid_dfa_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x = \"eP'\"\n      in ballE)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' v x w)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' v x w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' v x w y)(*strict*)\n    apply(simp add: option_to_list_def)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n   apply(case_tac \"Suc nP < i\")\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n    apply(simp add: derivation_append_def der2_def)\n    apply(case_tac \"i - nP = Suc 0\")\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n     apply(force)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n    apply(force)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n   apply(subgoal_tac \"i<Suc nP\")\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"\\<exists>i'. i+i' = nP\")\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n    prefer 2\n    apply(rule_tac\n      x = \"nP-i\"\n      in exI)\n    apply(force)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac dP eP cP dC nC eC cC eP' cP' v x i e c i')(*strict*)\n   apply(case_tac c)\n   apply(rename_tac dP eP cP dC nC eC cC eP' cP' v x i e c i' epdaH_conf_state epdaH_conf_historya epdaH_conf_stack)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac dP eP cP dC nC eC cC eP' cP' v x i e i' epdaH_conf_state epdaH_conf_stack)(*strict*)\n   apply(rename_tac q s)\n   apply(rename_tac dP eP cP dC nC eC cC eP' cP' v x i e i' q s)(*strict*)\n   apply(simp add: epdaH_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac dP eP cP dC nC eC cC eP' cP' v x i e i' q s w)(*strict*)\n   apply(simp add: valid_dfa_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x = \"eP'\"\n      in ballE)\n    apply(rename_tac dP eP cP dC nC eC cC eP' cP' v x i e i' q s w)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac dP eP cP dC nC eC cC eP' cP' v x i e i' q s w)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac dP eP cP dC nC eC cC eP' cP' v x i e i' q s w y)(*strict*)\n   apply(simp add: option_to_list_def)\n   apply(erule_tac\n      x = \"i\"\n      in allE)+\n   apply(simp add: derivation_append_def der2_def)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n  apply(subgoal_tac \"v @ [x] \\<in> epdaH.unmarked_language C\")\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   prefer 2\n   apply(rule_tac\n      A = \"{w. \\<exists>a\\<in> epdaH.unmarked_language C. \\<exists>b. (\\<exists>v\\<in> \\<Sigma>UC. b = [v]) \\<and> w = a @ b} \\<inter> epdaH.unmarked_language P\"\n      in set_mp)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n    apply(simp add: DES_controllability_def epda_to_des_def des_langUM_def des_langM_def controllable_language_def append_alphabet_def append_language_def alphabet_to_language_def)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   apply(thin_tac \"DES_controllability \\<Sigma>UC (epda_to_des P) (epda_to_des C)\")\n   apply(simp (no_asm))\n   apply(rule propSym)\n   apply(rule context_conjI)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n    apply(thin_tac \"epdaH_unmarked_effect P dP = epdaH_unmarked_effect C dC\")\n    apply(simp add: epdaH_unmarked_effect_def epdaH.unmarked_language_def)\n    apply(clarsimp)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n    apply(rule_tac\n      x = \"derivation_append dP (der2 cP eP' cP') nP\"\n      in exI)\n    apply(rule context_conjI)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n     apply(rule epdaH.derivation_append_preserves_derivation_initial)\n       apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n       apply(simp add: valid_dfa_def valid_dpda_def valid_pda_def)\n      apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n      apply(force)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n     apply(rule epdaH.derivation_append_preserves_derivation)\n       apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n       apply(simp add: epdaH.derivation_initial_def)\n      apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n      apply(rule epdaH.der2_is_derivation)\n      apply(force)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n     apply(clarsimp)\n     apply(simp add: der2_def)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n     apply(rule_tac\n      x = \"Suc nP\"\n      in exI)\n     apply(simp add: derivation_append_def der2_def)\n     apply(erule_tac\n      x = \"i\"\n      in allE)+\n     apply(case_tac \"i<nP\")\n      apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n     apply(clarsimp)\n     apply(case_tac \"i = nP\")\n      apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n     apply(clarsimp)\n     apply(case_tac \"i - nP = Suc 0\")\n      apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n     apply(force)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n    apply(simp add: epdaH.derivation_initial_def)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   apply(rule_tac\n      x = \"v\"\n      in bexI)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n    apply(force)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   apply(rule_tac\n      A = \"epdaH_unmarked_effect C dC\"\n      in set_mp)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n    apply(simp add: epdaH_unmarked_effect_def epdaH.unmarked_language_def)\n    apply(clarsimp)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i d ia e ea c ca ib eb cb)(*strict*)\n    apply(rule_tac\n      x = \"dC\"\n      in exI)\n    apply(clarsimp)\n    apply(rule conjI)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i d ia e ea c ca ib eb cb)(*strict*)\n     apply(force)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i d ia e ea c ca ib eb cb)(*strict*)\n    apply(simp add: epdaH.derivation_initial_def)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   apply(rule_tac\n      A = \"epdaH_unmarked_effect P dP\"\n      in set_mp)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n    apply(force)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   apply(thin_tac \"epdaH_unmarked_effect P dP = epdaH_unmarked_effect C dC\")\n   apply(thin_tac \"v @ [x] \\<in> epdaH.unmarked_language P\")\n   apply(simp add: epdaH_unmarked_effect_def)\n   apply(clarsimp)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n   apply(simp add: derivation_append_def der2_def)\n   apply(erule_tac\n      x = \"i\"\n      in allE)+\n   apply(case_tac \"i<nP\")\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n    apply(force)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"i = nP\")\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"i - nP = Suc 0\")\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' v x i c)(*strict*)\n    apply(subgoal_tac \"i = Suc nP\")\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' v x i c)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' v x i c)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' v x c)(*strict*)\n    apply(rule_tac\n      x = \"nP\"\n      in exI)\n    apply(clarsimp)\n    apply(simp add: epdaH_step_relation_def option_to_list_def)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i e c)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n  apply(subgoal_tac \"epdaH_conf_history cC = epdaH_conf_history cP\")\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"epdaH_unmarked_effect P dP = prefix_closure {epdaH_conf_history cP}\")\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n    prefer 2\n    apply(rule epda_unmarked_language_is_prefix_closure)\n       apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n       apply(simp add: valid_dfa_def valid_pda_def valid_dpda_def)\n      apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n      apply(force)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n     apply(force)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n    apply(force)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   apply(subgoal_tac \"epdaH_unmarked_effect C dC = prefix_closure {epdaH_conf_history cC}\")\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n    prefer 2\n    apply(rule epda_unmarked_language_is_prefix_closure)\n       apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n       apply(simp add: valid_dfa_def valid_pda_def valid_dpda_def)\n      apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n      apply(force)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n     apply(force)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n    apply(force)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   apply(rule prefix_closure_single_eq)\n   apply(force)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n  apply(subgoal_tac \"epdaH_conf_history cC = v\")\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   prefer 2\n   apply(thin_tac \"epdaH_unmarked_effect P dP = epdaH_unmarked_effect C dC\")\n   apply(simp add: epdaH.unmarked_language_def epdaH_unmarked_effect_def epdaH_step_relation_def option_to_list_def derivation_append_def der2_def)\n   apply(clarsimp)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i d e c ia ea ca w)(*strict*)\n   apply(case_tac c)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i d e c ia ea ca w epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n   apply(case_tac cP)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i d e c ia ea ca w epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka epdaH_conf_stateaa epdaH_conf_historyaa epdaH_conf_stackaa)(*strict*)\n   apply(case_tac cP')\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i d e c ia ea ca w epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka epdaH_conf_stateaa epdaH_conf_historyaa epdaH_conf_stackaa epdaH_conf_stateb epdaH_conf_historyb epdaH_conf_stackb)(*strict*)\n   apply(case_tac cC)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i d e c ia ea ca w epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka epdaH_conf_stateaa epdaH_conf_historyaa epdaH_conf_stackaa epdaH_conf_stateb epdaH_conf_historyb epdaH_conf_stackb epdaH_conf_statec epdaH_conf_historyc epdaH_conf_stackc)(*strict*)\n   apply(case_tac ca)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x i d e c ia ea ca w epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka epdaH_conf_stateaa epdaH_conf_historyaa epdaH_conf_stackaa epdaH_conf_stateb epdaH_conf_historyb epdaH_conf_stackb epdaH_conf_statec epdaH_conf_historyc epdaH_conf_stackc epdaH_conf_stated epdaH_conf_historyd epdaH_conf_stackd)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac dP nP eP dC nC eC eP' v x i d e ia ea w epdaH_conf_state epdaH_conf_stack epdaH_conf_historya epdaH_conf_statec epdaH_conf_stackc epdaH_conf_stated epdaH_conf_stackd)(*strict*)\n   apply(case_tac \"i\\<le>nP\")\n    apply(rename_tac dP nP eP dC nC eC eP' v x i d e ia ea w epdaH_conf_state epdaH_conf_stack epdaH_conf_historya epdaH_conf_statec epdaH_conf_stackc epdaH_conf_stated epdaH_conf_stackd)(*strict*)\n    apply(clarsimp)\n    apply(erule_tac\n      x = \"i\"\n      in allE)\n    apply(force)\n   apply(rename_tac dP nP eP dC nC eC eP' v x i d e ia ea w epdaH_conf_state epdaH_conf_stack epdaH_conf_historya epdaH_conf_statec epdaH_conf_stackc epdaH_conf_stated epdaH_conf_stackd)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"i-nP = Suc 0\")\n    apply(rename_tac dP nP eP dC nC eC eP' v x i d e ia ea w epdaH_conf_state epdaH_conf_stack epdaH_conf_historya epdaH_conf_statec epdaH_conf_stackc epdaH_conf_stated epdaH_conf_stackd)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac dP nP eP dC nC eC eP' v x i d e ia ea w epdaH_conf_state epdaH_conf_stack epdaH_conf_historya epdaH_conf_statec epdaH_conf_stackc epdaH_conf_stated epdaH_conf_stackd)(*strict*)\n   apply(subgoal_tac \"i = Suc nP\")\n    apply(rename_tac dP nP eP dC nC eC eP' v x i d e ia ea w epdaH_conf_state epdaH_conf_stack epdaH_conf_historya epdaH_conf_statec epdaH_conf_stackc epdaH_conf_stated epdaH_conf_stackd)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac dP nP eP dC nC eC eP' v x i d e ia ea w epdaH_conf_state epdaH_conf_stack epdaH_conf_historya epdaH_conf_statec epdaH_conf_stackc epdaH_conf_stated epdaH_conf_stackd)(*strict*)\n   apply(force)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n  apply(simp add: epdaH.unmarked_language_def epdaH_unmarked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G = \"C\"\n      and ?d1.0 = \"dC\"\n      and ?d2.0 = \"d\"\n      and ?i1.0 = \"nC\"\n      and ?i2.0 = \"ia\"\n      in epdaH_coincide_strict_prefix)\n        apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n        apply(force)\n       apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n       apply(force)\n      apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n      apply(force)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n     apply(clarsimp)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n    apply(clarsimp)\n    apply(simp add: get_configuration_def)\n   apply(simp add: strict_prefix_def)\n   apply(rule_tac\n      x = \"[x]\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n  apply(rule_tac\n      x = \"map the (drop nC (get_labels d ia))\"\n      in exI)\n  apply(rule_tac\n      x = \"ea\"\n      in exI)\n  apply(rule_tac\n      x = \"ca\"\n      in exI)\n  apply(rule_tac\n      x = \"derivation_drop (derivation_take d ia) nC\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n   apply(rule_tac\n      m = \"ia-nC\"\n      in epdaH.derivation_drop_preserves_derivation_prime)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n    apply(rule_tac epdaH.derivation_take_preserves_derivation)\n    apply(simp add: epdaH.derivation_initial_def)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n   apply(simp add: derivation_take_def derivation_drop_def)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n   apply(clarsimp)\n   apply(rule_tac\n      t = \"length (get_labels d ia)\"\n      and s = \"ia\"\n      in ssubst)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n    apply (metis get_labels_length)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n   apply(simp add: derivation_take_def derivation_drop_def)\n   apply(clarsimp)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n   apply(clarsimp)\n   apply(rule_tac\n      t = \"length (get_labels d ia)\"\n      and s = \"ia\"\n      in ssubst)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n    apply (metis get_labels_length)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n   apply(simp add: maximum_of_domain_def derivation_take_def derivation_drop_def)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n   apply(clarsimp)\n   apply(rule_tac\n      t = \"length (get_labels d ia)\"\n      and s = \"ia\"\n      in ssubst)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n    apply (metis get_labels_length)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n   apply(rule_tac\n      t = \"map (Some \\<circ> the) (drop nC (get_labels d ia))\"\n      and s = \"drop nC (map (Some \\<circ> the) (get_labels d ia))\"\n      in ssubst)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n    apply (metis drop_map)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n   apply(rule_tac\n      t = \"map (Some \\<circ> the) (get_labels d ia)\"\n      in subst)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n    apply(rule epdaH.get_labels_the_Some_on_defined_positions)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n     apply(force)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n    apply(force)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n   apply(rule_tac\n      t = \"get_labels (derivation_drop (derivation_take d ia) nC) (ia - nC)\"\n      in ssubst)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n    apply(rule get_labels_derivation_drop)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n   apply(clarsimp)\n   apply(rule_tac\n      t = \"get_labels (derivation_take d ia) ia\"\n      in subst)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n    apply(rule_tac\n      G = \"C\"\n      in epdaH.get_labels_derivation_take)\n      apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n    apply(force)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n   apply(force)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' x i d e c ia ea ca)(*strict*)\n  apply(rule_tac\n      x = \"ia\"\n      in exI)\n  apply(clarsimp)\n  apply(simp add: derivation_append_def derivation_drop_def derivation_take_def)\n  apply(clarsimp)\n  done\n\ntheorem epda_operational_controllable_implies_operational_controllabilityX: \"\n  valid_dfa P\n  \\<Longrightarrow> valid_dpda C\n  \\<Longrightarrow> epda_events P = epda_events C\n  \\<Longrightarrow> \\<Sigma>UC \\<subseteq> epda_events P\n  \\<Longrightarrow> ucont = (\\<lambda>w. (\\<exists>v. \\<exists>x\\<in> \\<Sigma>UC. w = v@[x]))\n  \\<Longrightarrow> epda_operational_controllable C P \\<Sigma>UC\n  \\<Longrightarrow> epdaH_vs_epdaH.controllableX C P ucont\"\n  apply(simp add: epdaH_vs_epdaH.controllableX_def epda_operational_controllable_def)\n  apply(clarsimp)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n  apply(erule_tac x=\"dC\" in allE)\n  apply(clarsimp)\n  apply(erule_tac x=\"nC\" in allE)\n  apply(clarsimp)\n  apply(subgoal_tac \"ATS.derivation_initial epdaH_initial_configurations\n        epdaH_step_relation P (derivation_append dP (der2 cP eP' cP') nP)\")\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   prefer 2\n   apply(rule epdaH.derivation_append_preserves_derivation_initial)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n     apply(simp add: valid_dfa_def valid_dpda_def valid_pda_def)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n    apply(force)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   apply(rule epdaH.derivation_append_preserves_derivation)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n    apply(rule epdaH.der2_is_derivation)\n    apply(force)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   apply(simp add: der2_def)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n  apply(erule_tac x=\"derivation_append dP (der2 cP eP' cP') nP\" in allE)\n  apply(erule impE)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   apply(force)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n  apply(erule_tac x=\"nP\" in allE)\n  apply(erule_tac x=\"eP\" in allE)\n  apply(erule_tac x=\"cP\" in allE)\n  apply(erule impE)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   apply(simp add: derivation_append_def der2_def)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n  apply(erule_tac x=\"Some eP'\" in allE)\n  apply(erule_tac x=\"cP'\" in allE)\n  apply(erule impE)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   apply(simp add: derivation_append_def der2_def)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n  apply(erule impE)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   apply(thin_tac \"v @ [x]\n       \\<in> epdaH_unmarked_effect P\n           (derivation_append dP (der2 cP eP' cP') nP)\")\n   apply(thin_tac \"v @ [x] \\<notin> epdaH_unmarked_effect C dC\")\n   apply(subgoal_tac \"epdaH_unmarked_effect P dP = prefix_closure {epdaH_conf_history cP}\")\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n    prefer 2\n    apply(rule epda_unmarked_language_is_prefix_closure)\n       apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n       apply(simp add: valid_dfa_def valid_pda_def valid_dpda_def)\n      apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n      apply(force)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n     apply(force)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n    apply(force)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   apply(subgoal_tac \"epdaH_unmarked_effect C dC = prefix_closure {epdaH_conf_history cC}\")\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n    prefer 2\n    apply(rule epda_unmarked_language_is_prefix_closure)\n       apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n       apply(simp add: valid_dfa_def valid_pda_def valid_dpda_def)\n      apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n      apply(force)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n     apply(force)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n    apply(force)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   apply(rule prefix_closure_single_eq)\n   apply(force)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n  apply(erule_tac x=\"x\" in allE)\n  apply(clarsimp)\n  apply(subgoal_tac \"epdaH_unmarked_effect P (derivation_append dP (der2 cP eP' cP') nP) = prefix_closure {epdaH_conf_history cP'}\")\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   prefer 2\n   apply(rule epda_unmarked_language_is_prefix_closure)\n      apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n      apply(simp add: valid_dfa_def valid_pda_def valid_dpda_def)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n     apply(force)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n    apply(rule concat_has_max_dom)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n     apply(force)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n    apply(rule der2_maximum_of_domain)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   apply(simp add: derivation_append_def der2_def)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n  apply(subgoal_tac \"epdaH_unmarked_effect C dC = prefix_closure {epdaH_conf_history cC}\")\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   prefer 2\n   apply(rule epda_unmarked_language_is_prefix_closure)\n      apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n      apply(simp add: valid_dfa_def valid_pda_def valid_dpda_def)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n     apply(force)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n    apply(force)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   apply(force)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n  apply(subgoal_tac \"epdaH_conf_history cP @ [x] = epdaH_conf_history cP'\")\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"v @ [x] \\<notin> epdaH_unmarked_effect P dP\")\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   apply(thin_tac \"v @ [x] \\<notin> epdaH_unmarked_effect C dC\")\n   apply(thin_tac \"ATS.derivation_initial epdaH_initial_configurations\n        epdaH_step_relation C dC\")\n   apply(thin_tac \"maximum_of_domain dC nC\")\n   apply(thin_tac \"dC nC = Some (pair eC cC)\")\n   apply(thin_tac \"epdaH_unmarked_effect P dP = epdaH_unmarked_effect C dC\")\n   apply(thin_tac \"epdaH_unmarked_effect C dC = prefix_closure {epdaH_conf_history cC}\")\n   apply(simp add: epdaH_unmarked_effect_def)\n   apply(rename_tac dP nP eP cP cC eP' cP' v x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac dP nP eP cP cC eP' cP' v x i e c)(*strict*)\n   apply(case_tac \"i\\<le>nP\")\n    apply(rename_tac dP nP eP cP cC eP' cP' v x i e c)(*strict*)\n    apply(erule_tac x=\"i\" in allE)\n    apply(simp add: derivation_append_def)\n   apply(rename_tac dP nP eP cP cC eP' cP' v x i e c)(*strict*)\n   apply(case_tac \"i=Suc nP\")\n    apply(rename_tac dP nP eP cP cC eP' cP' v x i e c)(*strict*)\n    prefer 2\n    apply(simp add: derivation_append_def)\n    apply(simp add: der2_def)\n    apply(case_tac \"i-nP\")\n     apply(rename_tac dP nP eP cP cC eP' cP' v x i e c)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac dP nP eP cP cC eP' cP' v x i e c nat)(*strict*)\n    apply(clarsimp)\n    apply(case_tac nat)\n     apply(rename_tac dP nP eP cP cC eP' cP' v x i e c nat)(*strict*)\n     apply(force)\n    apply(rename_tac dP nP eP cP cC eP' cP' v x i e c nat nata)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac dP nP eP cP cC eP' cP' v x i e c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac dP nP eP cP cC eP' cP' v x e c)(*strict*)\n   apply(simp add: derivation_append_def)\n   apply(simp add: der2_def)\n   apply(clarsimp)\n   apply(rename_tac dP nP eP cP cC eP' v x c)(*strict*)\n   apply(case_tac c)\n   apply(rename_tac dP nP eP cP cC eP' v x c epdaH_conf_state epdaH_conf_historya epdaH_conf_stack)(*strict*)\n   apply(case_tac cP)\n   apply(rename_tac dP nP eP cP cC eP' v x c epdaH_conf_state epdaH_conf_historya epdaH_conf_stack epdaH_conf_statea epdaH_conf_historyaa epdaH_conf_stacka)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac dP nP eP cC eP' v x epdaH_conf_state epdaH_conf_stack epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n   apply(simp add: epdaH_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac dP nP eP cC eP' v x epdaH_conf_historya w)(*strict*)\n   apply(case_tac \"edge_event eP'\")\n    apply(rename_tac dP nP eP cC eP' v x epdaH_conf_historya w)(*strict*)\n    prefer 2\n    apply(rename_tac dP nP eP cC eP' v x epdaH_conf_historya w a)(*strict*)\n    apply(clarsimp)\n    apply(simp add: option_to_list_def)\n   apply(rename_tac dP nP eP cC eP' v x epdaH_conf_historya w)(*strict*)\n   apply(simp add: option_to_list_def)\n   apply(clarsimp)\n   apply(rename_tac dP nP eP eP' v x w)(*strict*)\n   apply(erule_tac x=\"nP\" in allE)\n   apply(force)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n  apply(subgoal_tac \"epdaH_conf_history cP' = epdaH_conf_history cP @ [x]\")\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   prefer 2\n   apply(rule prefix_closure_single_eq)\n   apply(rule_tac t=\"epdaH_conf_history cP @ [x]\" and s=\"epdaH_conf_history cP'\" in ssubst)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   apply(force)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n  apply(erule impE)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n   apply(force)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n  apply(clarify)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n  apply(rule_tac x=\"map the (get_labels dc nCa)\" in exI)\n  apply(rule_tac x=\"eCa\" in exI)\n  apply(rule_tac x=\"cCa\" in exI)\n  apply(rule_tac x=\"derivation_take dc nCa\" in exI)\n  apply(rule conjI)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n   apply(rule epdaH.derivation_take_preserves_derivation)\n   apply(force)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n  apply(rule_tac t=\"length (get_labels dc nCa)\" and s=\"nCa\" in ssubst)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n   apply(rule get_labels_length)\n   apply(blast)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n   apply(simp (no_asm) add: derivation_take_def)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n  apply(rule_tac t=\"length(map the (get_labels dc nCa))\" and s=\"length((get_labels dc nCa))\" in ssubst)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n   apply(rule length_map)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n  apply(rule_tac t=\"length (get_labels dc nCa)\" and s=\"nCa\" in ssubst)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n   apply(rule get_labels_length)\n   apply(blast)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n   apply(simp (no_asm) add: derivation_take_def)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n   apply(rule maximum_of_domain_derivation_take)\n   apply(blast)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n   apply(rule_tac t=\"get_labels (derivation_take dc nCa) nCa\" and s=\"get_labels dc nCa\" in subst)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n    apply(rule_tac G=\"C\" in epdaH.get_labels_derivation_take)\n      apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n      apply(unfold valid_dfa_def valid_dpda_def valid_pda_def)[1]\n      apply(force)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n     apply(force)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n    apply(blast)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n   apply(simp (no_asm))\n   apply(rule epdaH.get_labels_the_Some_on_defined_positions)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n    apply(blast)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n   apply(blast)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n  apply(rule_tac t=\"epdaH_unmarked_effect P (derivation_append dP (der2 cP eP' cP') nP)\" and s=\"prefix_closure {epdaH_conf_history cP'}\" in ssubst)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n   apply(force)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n  apply(rule_tac t=\"epdaH_unmarked_effect C dC\" and s=\"prefix_closure {epdaH_conf_history cC}\" in ssubst)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n   apply(force)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n  apply(rule_tac t=\"epdaH_unmarked_effect C\n        (derivation_append dC (derivation_take dc nCa) nC)\"  and s=\"prefix_closure {epdaH_conf_history cCa}\" in ssubst)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n   apply(rule_tac e=\"if nCa = 0 then eC else eCa\" and G=\"C\" and n=\"nC+nCa\" in epda_unmarked_language_is_prefix_closure)\n      apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n      apply(unfold valid_dfa_def valid_pda_def valid_dpda_def)[1]\n      apply(force)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n     apply(rule_tac epdaH.derivation_append_preserves_derivation_initial)\n       apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n       apply(unfold valid_dfa_def valid_pda_def valid_dpda_def)[1]\n       apply(force)\n      apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n      apply(force)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n     apply(rule_tac epdaH.derivation_append_preserves_derivation)\n       apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n       apply(unfold epdaH.derivation_initial_def)[1]\n       apply(force)\n      apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n      apply(rule_tac epdaH.derivation_take_preserves_derivation)\n      apply(unfold epdaH.derivation_initial_def)[1]\n      apply(force)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n     apply(unfold maximum_of_domain_def derivation_take_def)[1]\n     apply(simp (no_asm))\n     apply(clarify)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa y ya)(*strict*)\n     apply(simp (no_asm_simp))\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n    apply(rule concat_has_max_dom)\n     apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n     apply(force)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n    apply(rule maximum_of_domain_derivation_take)\n    apply(blast)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n   apply(unfold derivation_append_def derivation_take_def)[1]\n   apply(simp (no_asm))\n   apply(rule conjI)\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n    apply(clarify)\n    apply(simp (no_asm_simp))\n    apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc eCa cCa)(*strict*)\n    apply(thin_tac \"v @ [x]\n       \\<in> epdaH_unmarked_effect P\n           (\\<lambda>x. if x \\<le> nP then dP x else der2 cP eP' cP' (x - nP))\")\n    apply(thin_tac \"ATS.derivation_initial epdaH_initial_configurations\n        epdaH_step_relation P\n        (\\<lambda>x. if x \\<le> nP then dP x else der2 cP eP' cP' (x - nP))\")\n    apply(thin_tac \"epdaH_unmarked_effect P\n        (\\<lambda>x. if x \\<le> nP then dP x else der2 cP eP' cP' (x - nP)) =\n       prefix_closure {epdaH_conf_history cP'}\")\n    apply(thin_tac \"epdaH_unmarked_effect C dC =\n       prefix_closure {epdaH_conf_history cC}\")\n    apply(clarsimp)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n   apply(thin_tac \"v @ [x]\n       \\<in> epdaH_unmarked_effect P\n           (\\<lambda>x. if x \\<le> nP then dP x else der2 cP eP' cP' (x - nP))\")\n   apply(thin_tac \"ATS.derivation_initial epdaH_initial_configurations\n        epdaH_step_relation P\n        (\\<lambda>x. if x \\<le> nP then dP x else der2 cP eP' cP' (x - nP))\")\n   apply(thin_tac \"epdaH_unmarked_effect P\n        (\\<lambda>x. if x \\<le> nP then dP x else der2 cP eP' cP' (x - nP)) =\n       prefix_closure {epdaH_conf_history cP'}\")\n   apply(thin_tac \"epdaH_unmarked_effect C dC =\n       prefix_closure {epdaH_conf_history cC}\")\n   apply(clarsimp)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n  apply(rule_tac t=\"epdaH_conf_history cCa\" and s=\"epdaH_conf_history cP @ [x]\" in ssubst)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n   apply(force)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n  apply(rule_tac t=\"epdaH_conf_history cP'\" and s=\"epdaH_conf_history cP @ [x]\" in ssubst)\n   apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n   apply(force)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x dc nCa eCa cCa)(*strict*)\n  apply(force)\n  done\n\ntheorem operational_controllability_implies_DES_controllability: \"\n  valid_dfa P\n  \\<Longrightarrow> valid_dpda C\n  \\<Longrightarrow> epda_events P = epda_events C\n  \\<Longrightarrow> \\<Sigma>UC \\<subseteq> epda_events P\n  \\<Longrightarrow> ucont = (\\<lambda>w. (\\<exists>v. \\<exists>x\\<in> \\<Sigma>UC. w = v@[x]))\n  \\<Longrightarrow> epdaH_vs_epdaH.controllable C P ucont\n  \\<Longrightarrow> epda_operational_controllable C P \\<Sigma>UC\"\n  apply(simp add: epda_operational_controllable_def epdaH_vs_epdaH.controllable_def)\n  apply(clarsimp)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n  apply(erule_tac\n      x = \"derivation_take d2 n2\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n   apply(rule epdaH.derivation_take_preserves_derivation_initial)\n   apply(force)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n  apply(erule_tac\n      x = \"n2\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n   apply(rule maximum_of_domain_derivation_take)\n   apply(force)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n  apply(erule_tac\n      x = \"e2\"\n      in allE)\n  apply(erule_tac\n      x = \"c2\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n  apply(erule_tac\n      x = \"derivation_take d1 n1\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n   apply(rule epdaH.derivation_take_preserves_derivation_initial)\n   apply(force)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n  apply(erule_tac\n      x = \"n1\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n   apply(rule maximum_of_domain_derivation_take)\n   apply(force)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n  apply(erule_tac\n      x = \"e1\"\n      in allE)\n  apply(erule_tac\n      x = \"c1\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n  apply(erule impE)\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n   apply(rule_tac\n      t = \"epdaH_unmarked_effect P (derivation_take d2 n2)\"\n      in ssubst)\n    apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n    apply(rule_tac\n      n = \"n2\"\n      in epda_unmarked_language_is_prefix_closure)\n       apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n       apply(simp add: valid_dfa_def valid_dpda_def valid_pda_def)\n      apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n      apply(rule epdaH.derivation_take_preserves_derivation_initial)\n      apply(force)\n     apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n     apply(rule maximum_of_domain_derivation_take)\n     apply(force)\n    apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n    apply(simp add: derivation_take_def)\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n   apply(rule_tac\n      t = \"epdaH_unmarked_effect C (derivation_take d1 n1)\"\n      in ssubst)\n    apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n    apply(rule_tac\n      n = \"n1\"\n      in epda_unmarked_language_is_prefix_closure)\n       apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n       apply(simp add: valid_dfa_def valid_dpda_def valid_pda_def)\n      apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n      apply(rule epdaH.derivation_take_preserves_derivation_initial)\n      apply(force)\n     apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n     apply(rule maximum_of_domain_derivation_take)\n     apply(force)\n    apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n    apply(simp add: derivation_take_def)\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n   apply(rule_tac\n      t = \"epdaH_conf_history c2\"\n      and s = \"epdaH_conf_history c1\"\n      in ssubst)\n    apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n   apply(force)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d2 n2 = Some (pair e1 c1) \\<and> SSd (Suc SSn) = Some (pair (Some e2) c2) \\<and> epdaH_step_relation SSG c1 e2 c2\" for SSd SSn SSG)\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m = \"Suc n2\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n     apply(force)\n    apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n    apply(force)\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n   apply(force)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 e2' c2' u)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a)(*strict*)\n  apply(erule_tac\n      x = \"e2a\"\n      in allE)\n  apply(erule_tac\n      x = \"c2'\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a)(*strict*)\n   apply(force)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a)(*strict*)\n  apply(erule_tac\n      x = \"epdaH_conf_history c2 @ [u]\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a)(*strict*)\n   apply(force)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a)(*strict*)\n  apply(erule impE)\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a)(*strict*)\n    apply(simp add: epdaH_unmarked_effect_def)\n    apply(rule_tac\n      x = \"Suc n2\"\n      in exI)\n    apply(simp add: derivation_append_def derivation_take_def der2_def)\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a)(*strict*)\n   apply(rule_tac\n      t = \"epdaH_unmarked_effect C (derivation_take d1 n1)\"\n      in ssubst)\n    apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a)(*strict*)\n    apply(rule_tac\n      n = \"n1\"\n      in epda_unmarked_language_is_prefix_closure)\n       apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a)(*strict*)\n       apply(simp add: valid_dfa_def valid_dpda_def valid_pda_def)\n      apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a)(*strict*)\n      apply(rule epdaH.derivation_take_preserves_derivation_initial)\n      apply(force)\n     apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a)(*strict*)\n     apply(rule maximum_of_domain_derivation_take)\n     apply(force)\n    apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a)(*strict*)\n    apply(simp add: derivation_take_def)\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a)(*strict*)\n   apply(simp (no_asm) add: prefix_closure_def prefix_def)\n   apply(force)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a \\<pi>P' e cC' dC')(*strict*)\n  apply(rule_tac\n      x = \"dC'\"\n      in exI)\n  apply(clarsimp)\n  apply(simp add: epdaH_unmarked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a \\<pi>P' e cC' dC' i ea c)(*strict*)\n  apply(case_tac \"i\\<le>n1\")\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a \\<pi>P' e cC' dC' i ea c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      x = \"i-n1\"\n      in exI)\n   apply(simp add: derivation_append_def derivation_take_def)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a \\<pi>P' e cC' dC' i ea c)(*strict*)\n  apply(subgoal_tac \"False\")\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a \\<pi>P' e cC' dC' i ea c)(*strict*)\n   apply(force)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a \\<pi>P' e cC' dC' i ea c)(*strict*)\n  apply(subgoal_tac \"d1 i = Some (pair ea c)\")\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a \\<pi>P' e cC' dC' i ea c)(*strict*)\n   prefer 2\n   apply(simp add: derivation_append_def derivation_take_def get_configuration_def)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a \\<pi>P' e cC' dC' i ea c)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a \\<pi>P' e cC' dC' i ea c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G = \"C\"\n      and d = \"d1\"\n      and n = \"i\"\n      and m = \"n1-i\"\n      in epdaH.steps_extend_history_derivation)\n       apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a \\<pi>P' e cC' dC' i ea c)(*strict*)\n       apply(simp add: valid_dpda_def valid_pda_def valid_dfa_def)\n      apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a \\<pi>P' e cC' dC' i ea c)(*strict*)\n      apply(simp add: epdaH.derivation_initial_def)\n     apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a \\<pi>P' e cC' dC' i ea c)(*strict*)\n     prefer 2\n     apply(simp add: derivation_append_def derivation_take_def get_configuration_def)\n    apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a \\<pi>P' e cC' dC' i ea c)(*strict*)\n    apply(rule_tac\n      d = \"d1\"\n      in epdaH.belongs_configurations)\n     apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a \\<pi>P' e cC' dC' i ea c)(*strict*)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a \\<pi>P' e cC' dC' i ea c)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def valid_dfa_def)\n     apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a \\<pi>P' e cC' dC' i ea c)(*strict*)\n     apply(force)\n    apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a \\<pi>P' e cC' dC' i ea c)(*strict*)\n    apply(force)\n   apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a \\<pi>P' e cC' dC' i ea c)(*strict*)\n   apply(simp add: derivation_append_def derivation_take_def get_configuration_def)\n  apply(rename_tac d1 n1 e1 c1 d2 n2 e2 c2 c2' u e2a \\<pi>P' e cC' dC' i ea c)(*strict*)\n  apply(clarsimp)\n  done\n\ntheorem controllable_vs_controllableX_part1: \"\n  valid_dfa P\n  \\<Longrightarrow> valid_dpda C\n  \\<Longrightarrow> epda_events P = epda_events C\n  \\<Longrightarrow> \\<Sigma>UC \\<subseteq> epda_events P\n  \\<Longrightarrow> ucont = (\\<lambda>w. (\\<exists>v. \\<exists>x\\<in> \\<Sigma>UC. w = v@[x]))\n  \\<Longrightarrow> epdaH_vs_epdaH.controllableX C P ucont\n  \\<Longrightarrow> epdaH_vs_epdaH.controllable C P ucont\"\n  apply(simp add: epdaH_vs_epdaH.controllable_def epdaH_vs_epdaH.controllableX_def)\n  apply(clarsimp)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x)(*strict*)\n  apply(erule_tac x=\"dP\" in allE)\n  apply(clarsimp)\n  apply(erule_tac x=\"nP\" in allE)\n  apply(clarsimp)\n  apply(erule_tac x=\"dC\" in allE)\n  apply(clarsimp)\n  apply(erule_tac x=\"nC\" in allE)\n  apply(clarsimp)\n  apply(erule_tac x=\"eP'\" in allE)\n  apply(erule_tac x=\"cP'\" in allE)\n  apply(clarsimp)\n  apply(erule_tac x=\"v@[x]\" in allE)\n  apply(clarsimp)\n  apply(rename_tac dP nP eP cP dC nC eC cC eP' cP' v x \\<pi>P' e cC' dC')(*strict*)\n  apply(rule_tac x=\"\\<pi>P'\" in exI)\n  apply(rule_tac x=\"e\" in exI)\n  apply(rule_tac x=\"cC'\" in exI)\n  apply(rule_tac x=\"dC'\" in exI)\n  apply(clarsimp)\n  apply (metis Diff_iff)\n  done\n\ntheorem DES_controllability_implies_operational_controllabilityX: \"\n  valid_dfa P\n  \\<Longrightarrow> valid_dpda C\n  \\<Longrightarrow> epda_events P = epda_events C\n  \\<Longrightarrow> \\<Sigma>UC \\<subseteq> epda_events P\n  \\<Longrightarrow> ucont = (\\<lambda>w. (\\<exists>v. \\<exists>x\\<in> \\<Sigma>UC. w = v@[x]))\n  \\<Longrightarrow> DES_controllability \\<Sigma>UC (epda_to_des P) (epda_to_des C)\n  \\<Longrightarrow> epdaH_vs_epdaH.controllableX C P ucont\"\n  apply(rule epda_operational_controllable_implies_operational_controllabilityX)\n       apply(force)\n      apply(force)\n     apply(force)\n    prefer 2\n    apply(force)\n   apply(force)\n  apply(rule operational_controllability_implies_DES_controllability)\n       apply(force)\n      apply(force)\n     apply(force)\n    prefer 2\n    apply(force)\n   apply(force)\n  apply(rule DES_controllability_implies_operational_controllability)\n       apply(force)\n      apply(force)\n     apply(force)\n    prefer 2\n    apply(force)\n   apply(force)\n  apply(force)\n  done\n\ntheorem EPDA_relationship_among_controllability_notions: \"\n  valid_dfa P\n  \\<Longrightarrow> valid_dpda C\n  \\<Longrightarrow> epda_events P = epda_events C\n  \\<Longrightarrow> \\<Sigma>UC \\<subseteq> epda_events P\n  \\<Longrightarrow> ucont = (\\<lambda>w. (\\<exists>v. \\<exists>x\\<in> \\<Sigma>UC. w = v@[x]))\n  \\<Longrightarrow>\n  (epdaH_vs_epdaH.controllable C P ucont\n    \\<longleftrightarrow> epdaH_vs_epdaH.controllableX C P ucont)\n  \\<and> (epdaH_vs_epdaH.controllable C P ucont\n    \\<longleftrightarrow> epda_operational_controllable C P \\<Sigma>UC)\n  \\<and> (epda_operational_controllable C P \\<Sigma>UC\n    \\<longleftrightarrow> DES_controllability \\<Sigma>UC (epda_to_des P) (epda_to_des C))\n  \\<and> (DES_controllability \\<Sigma>UC (epda_to_des P) (epda_to_des C)\n    \\<longleftrightarrow> controllable_sublanguage (epdaH.unmarked_language C) (alphabet_to_language \\<Sigma>UC) (epdaH.unmarked_language P) (epdaH.unmarked_language C))\"\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule impI)\n   apply(rule_tac \\<Sigma>UC=\"\\<Sigma>UC\" in epda_operational_controllable_implies_operational_controllabilityX)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule impI)\n   apply(rule_tac \\<Sigma>UC=\"\\<Sigma>UC\" in operational_controllability_implies_DES_controllability)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule impI)\n   apply(rule_tac \\<Sigma>UC=\"\\<Sigma>UC\" in DES_controllability_implies_operational_controllability)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac \\<Sigma>UC=\"\\<Sigma>UC\" and P=\"(epda_to_des P)\" and C=\"(epda_to_des C)\" in DES_controllability_vs_controllable_sublanguage)\n  apply(simp add: epda_to_des_def des_langUM_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac SigmaUC=\"\\<Sigma>UC\" in epda_epda_operational_controllable_vs_Cont)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac P=\"L_Controllable.controllableX epdaH_initial_configurations epdaH_step_relation\n     epdaH_unmarked_effect epdaH_initial_configurations epdaH_step_relation\n     epdaH_unmarked_effect C P ucont\" in impI)\n   apply(rule_tac \\<Sigma>UC=\"\\<Sigma>UC\" in controllable_vs_controllableX_part1)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(rule context_conjI)\n   apply(rule antisym)\n    apply(simp (no_asm))\n    apply(rule impI)\n    apply(rule_tac P=\"epda_operational_controllable C P \\<Sigma>UC\" in mp)\n     prefer 2\n     apply(force)\n    apply(force)\n   apply(simp (no_asm))\n   apply(rule impI)\n   apply(force)\n  apply(rule context_conjI)\n   apply(rule antisym)\n    apply(simp (no_asm))\n   apply(simp (no_asm))\n   apply(force)\n  apply(rule antisym)\n   apply(simp (no_asm))\n   apply(force)\n  apply(simp (no_asm))\n  apply(force)\n  done\n\ntheorem livelock_implies_epdaH_has_livelock: \"\n  valid_epda G\n  \\<Longrightarrow> epdaH_livelock G\n  \\<Longrightarrow> epdaH.has_livelock G\"\n  apply(simp add: epdaH_livelock_def epdaH.has_livelock_def epdaH.derivation_livelock_def)\n  apply(erule exE)+\n  apply(rename_tac d)(*strict*)\n  apply(rule_tac\n      x = \"d\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac d)(*strict*)\n   apply(force)\n  apply(rename_tac d)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac d)(*strict*)\n   apply(force)\n  apply(rename_tac d)(*strict*)\n  apply(erule conjE)+\n  apply(erule exE)+\n  apply(rename_tac d N)(*strict*)\n  apply(rule_tac\n      x = \"N\"\n      in exI)\n  apply(rule allI)\n  apply(rename_tac d N n)(*strict*)\n  apply(case_tac \"d N\")\n   apply(rename_tac d N n)(*strict*)\n   apply(erule_tac\n      x = \"N\"\n      in allE)+\n   apply(force)\n  apply(rename_tac d N n a)(*strict*)\n  apply(case_tac a)\n  apply(rename_tac d N n a option conf)(*strict*)\n  apply(rename_tac eN cN)\n  apply(rename_tac d N n a eN cN)(*strict*)\n  apply(erule_tac\n      x = \"n\"\n      in allE)+\n  apply(clarsimp)\n  apply(rename_tac d N n eN cN y)(*strict*)\n  apply(case_tac y)\n  apply(rename_tac d N n eN cN y option conf)(*strict*)\n  apply(rename_tac en cn)\n  apply(rename_tac d N n eN cN y en cn)(*strict*)\n  apply(rule_tac\n      t = \"epdaH_unmarked_effect G (derivation_take d N)\"\n      in ssubst)\n   apply(rename_tac d N n eN cN y en cn)(*strict*)\n   apply(rule_tac\n      n = \"N\"\n      in epda_unmarked_language_is_prefix_closure)\n      apply(rename_tac d N n eN cN y en cn)(*strict*)\n      apply(force)\n     apply(rename_tac d N n eN cN y en cn)(*strict*)\n     apply(rule epdaH.derivation_take_preserves_derivation_initial)\n     apply(force)\n    apply(rename_tac d N n eN cN y en cn)(*strict*)\n    apply (metis epdaH.derivation_initial_is_derivation maximum_of_domain_derivation_take epdaH.pre_some_position_is_some_position option.distinct(1))\n   apply(rename_tac d N n eN cN y en cn)(*strict*)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac d N n eN cN y en cn)(*strict*)\n  apply(rule_tac\n      t = \"epdaH_unmarked_effect G (derivation_take d n)\"\n      in ssubst)\n   apply(rename_tac d N n eN cN y en cn)(*strict*)\n   apply(rule_tac\n      n = \"n\"\n      in epda_unmarked_language_is_prefix_closure)\n      apply(rename_tac d N n eN cN y en cn)(*strict*)\n      apply(force)\n     apply(rename_tac d N n eN cN y en cn)(*strict*)\n     apply(rule epdaH.derivation_take_preserves_derivation_initial)\n     apply(force)\n    apply(rename_tac d N n eN cN y en cn)(*strict*)\n    apply (metis epdaH.derivation_initial_is_derivation maximum_of_domain_derivation_take epdaH.pre_some_position_is_some_position option.distinct(1))\n   apply(rename_tac d N n eN cN y en cn)(*strict*)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac d N n eN cN y en cn)(*strict*)\n  apply(rule_tac\n      t = \"epdaH_conf_history cN\"\n      and s = \"epdaH_conf_history cn\"\n      in ssubst)\n   apply(rename_tac d N n eN cN y en cn)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac d N n eN cN y en cn)(*strict*)\n  apply(simp add: get_configuration_def)\n  done\n\ntheorem epdaH_has_livelock_implies_livelock: \"\n  valid_epda G\n  \\<Longrightarrow> epdaH.has_livelock G\n  \\<Longrightarrow> epdaH_livelock G\"\n  apply(simp add: epdaH_livelock_def epdaH.has_livelock_def epdaH.derivation_livelock_def)\n  apply(erule exE)+\n  apply(rename_tac d)(*strict*)\n  apply(rule_tac\n      x = \"d\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac d)(*strict*)\n   apply(force)\n  apply(rename_tac d)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac d)(*strict*)\n   apply(force)\n  apply(rename_tac d)(*strict*)\n  apply(erule conjE)+\n  apply(erule exE)+\n  apply(rename_tac d N)(*strict*)\n  apply(rule_tac\n      x = \"N\"\n      in exI)\n  apply(rule allI)\n  apply(rename_tac d N n)(*strict*)\n  apply(case_tac \"d N\")\n   apply(rename_tac d N n)(*strict*)\n   apply(erule_tac\n      x = \"N\"\n      in allE)+\n   apply(force)\n  apply(rename_tac d N n a)(*strict*)\n  apply(case_tac a)\n  apply(rename_tac d N n a option conf)(*strict*)\n  apply(rename_tac eN cN)\n  apply(rename_tac d N n a eN cN)(*strict*)\n  apply(erule_tac\n      x = \"n\"\n      in allE)+\n  apply(clarsimp)\n  apply(rename_tac d N n eN cN y)(*strict*)\n  apply(case_tac y)\n  apply(rename_tac d N n eN cN y option conf)(*strict*)\n  apply(rename_tac en cn)\n  apply(rename_tac d N n eN cN y en cn)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d N n eN cN y en cn)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d = \"derivation_take d N\"\n      and n = \"N\"\n      in epda_unmarked_language_is_prefix_closure)\n      apply(rename_tac d N n eN cN y en cn)(*strict*)\n      apply(force)\n     apply(rename_tac d N n eN cN y en cn)(*strict*)\n     apply(rule epdaH.derivation_take_preserves_derivation_initial)\n     apply(force)\n    apply(rename_tac d N n eN cN y en cn)(*strict*)\n    apply (metis epdaH.derivation_initial_is_derivation maximum_of_domain_derivation_take epdaH.pre_some_position_is_some_position option.distinct(1))\n   apply(rename_tac d N n eN cN y en cn)(*strict*)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac d N n eN cN y en cn)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d N n eN cN y en cn)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d = \"derivation_take d n\"\n      and n = \"n\"\n      in epda_unmarked_language_is_prefix_closure)\n      apply(rename_tac d N n eN cN y en cn)(*strict*)\n      apply(force)\n     apply(rename_tac d N n eN cN y en cn)(*strict*)\n     apply(rule epdaH.derivation_take_preserves_derivation_initial)\n     apply(force)\n    apply(rename_tac d N n eN cN y en cn)(*strict*)\n    apply (metis epdaH.derivation_initial_is_derivation maximum_of_domain_derivation_take epdaH.pre_some_position_is_some_position option.distinct(1))\n   apply(rename_tac d N n eN cN y en cn)(*strict*)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac d N n eN cN y en cn)(*strict*)\n  apply (metis prefix_closure_single_eq)\n  done\n\ncorollary epda_inter_semantic_relationship: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.marked_language G = epdaH.marked_language G\n  \\<and> epdaS.marked_language G = epdaHS.marked_language G\n  \\<and> epdaS.unmarked_language G = epdaH.unmarked_language G\n  \\<and> epdaS.unmarked_language G = epdaHS.unmarked_language G\n  \\<and> (epdaS.is_forward_edge_deterministic_accessible G \\<longleftrightarrow> epdaH.is_forward_edge_deterministicHist_SB G)\n  \\<and> (epdaS.is_forward_edge_deterministic_accessible G \\<longleftrightarrow> epdaHS.is_forward_edge_deterministic_accessible G)\n  \\<and> (epdaS.Nonblockingness_linear_DB G \\<longleftrightarrow> epdaHS.Nonblockingness_linear_DB G)\n  \\<and> (epdaS.Nonblockingness_linear_DB G \\<longleftrightarrow> epdaH.Nonblockingness_branching G)\"\n  apply(rule conjI)\n   apply (metis epdaS_to_epdaH_mlang)\n  apply(rule conjI)\n   apply (metis epdaS_to_epdaHS_mlang)\n  apply(rule conjI)\n   apply (metis epdaS_to_epdaH_unmarked_language)\n  apply(rule conjI)\n   apply (metis epdaS_to_epdaHS_unmarked_language)\n  apply(rule conjI)\n   apply(metis epdaH.AX_is_forward_edge_deterministic_correspond_DB_SB epdaH.is_forward_edge_deterministicHist_SB_vs_is_forward_edge_deterministicHist_SB_long epda_epdaS_is_forward_edge_deterministic_accessible_equal_to_epdaH_is_forward_edge_deterministicHist_DB_long)\n  apply(rule conjI)\n   apply(metis epdaS_vs_epdaHS.preservation_of_determinism epdaS_vs_epdaHS_TSstructure_rel_def)\n  apply(rule context_conjI)\n   apply (metis epdaS_vs_epdaHS.preservation_of_Nonblockingnessness epdaS_vs_epdaHS_TSstructure_rel_def)\n  apply (metis epdaH_vs_epdaHS_Nonblockingness_and_lang_transfer)\n  done\n\ntheorem epdaH_dependency_between_determinism_properties: \"\n  valid_epda G\n  \\<Longrightarrow>\n  epdaH.is_forward_target_deterministic_accessible G\n  \\<and> (epdaH.is_forward_target_deterministic_accessible G\n  \\<longleftrightarrow> epdaH.is_forward_target_deterministicHist_SB G)\n  \\<and> (epdaH.is_forward_target_deterministic_accessible G\n  \\<longleftrightarrow> epdaH.is_forward_target_deterministicHist_DB G)\n  \\<and> (epdaH.is_forward_target_deterministicHist_SB G\n  \\<longleftrightarrow> epdaH.is_forward_target_deterministicHist_DB G)\n  \\<and> (epdaH.is_forward_edge_deterministic_accessible G\n  \\<longrightarrow> epdaH.is_forward_edge_deterministicHist_SB G)\n  \\<and> (epdaH.is_forward_edge_deterministic_accessible G\n  \\<longrightarrow> epdaH.is_forward_edge_deterministicHist_DB G)\n  \\<and> (epdaH.is_forward_edge_deterministicHist_SB G\n  \\<longleftrightarrow> epdaH.is_forward_edge_deterministicHist_DB G)\"\n  apply(rule conjI)\n   apply (metis epdaH_inst_AX_is_forward_target_deterministic_correspond_DB epdaH_is_forward_target_deterministicHist_DB_long)\n  apply(rule conjI)\n   apply (metis epdaH.AX_is_forward_target_deterministic_correspond_SB epdaH.is_forward_target_deterministicHist_SB_vs_is_forward_target_deterministicHist_SB_long)\n  apply(rule conjI)\n   apply (metis epdaH.AX_is_forward_target_deterministic_correspond_DB epdaH.is_forward_target_deterministicHist_DB_vs_is_forward_target_deterministicHist_DB_long)\n  apply(rule context_conjI)\n   apply (metis epdaH.is_forward_target_deterministicHist_DB_vs_is_forward_target_deterministicHist_DB_long epdaH.is_forward_target_deterministicHist_SB_vs_is_forward_target_deterministicHist_SB_long epdaH_inst_AX_is_forward_target_deterministic_correspond_DB epdaH_inst_AX_is_forward_target_deterministic_correspond_SB)\n  apply(rule context_conjI)\n   apply (metis epdaH.is_forward_edge_deterministic_accessible_implies_is_forward_edge_deterministicHist_SB)\n  apply(rule conjI)\n   apply (metis epdaH.is_forward_edge_deterministicHist_DB_vs_is_forward_edge_deterministicHist_DB_long epdaH.is_forward_edge_deterministic_accessible_implies_is_forward_edge_deterministicHist_DB_long)\n  apply (metis epdaH.AX_is_forward_edge_deterministic_correspond_DB_SB epdaH.is_forward_edge_deterministicHist_DB_vs_is_forward_edge_deterministicHist_DB_long epdaH.is_forward_edge_deterministicHist_SB_vs_is_forward_edge_deterministicHist_SB_long)\n  done\n\ncorollary epdaH_operational_Nonblockingness_SB_DB_Restriction: \"\n  valid_epda G\n  \\<Longrightarrow> (epdaH.Nonblockingness_branching_restricted G \\<longleftrightarrow> epdaH.Nonblockingness_branching G)\n  \\<and> (epdaH.Nonblockingness_branching_restricted_DB G \\<longleftrightarrow> epdaH.Nonblockingness_branching G)\"\n  apply(rule conjI)\n   apply(rule antisym)\n    apply(simp add: epdaH.Nonblockingness_branching_restricted_def epdaH.Nonblockingness_branching_def)\n   apply(simp add: epdaH.Nonblockingness_branching_restricted_def epdaH.Nonblockingness_branching_def)\n  apply(rule antisym)\n   apply(simp add: epdaH.Nonblockingness_branching_restricted_DB_def epdaH.Nonblockingness_branching_def)\n  apply(simp add: epdaH.Nonblockingness_branching_restricted_DB_def epdaH.Nonblockingness_branching_def)\n  done\n\ncorollary epdaH_language_Nonblockingness_from_operational_Nonblockingness: \"\n  valid_epda G\n  \\<Longrightarrow> epdaH.Nonblockingness_branching G\n  \\<Longrightarrow> nonblockingness_language (epdaH.unmarked_language G) (epdaH.marked_language G)\"\n  apply(metis epdaH.AX_BF_Bra_OpLa)\n  done\n\ncorollary epdaH_operational_Nonblockingness_from_language_Nonblockingness: \"\n  valid_epda G\n  \\<Longrightarrow> epdaH.is_forward_edge_deterministicHist_SB G\n  \\<Longrightarrow> nonblockingness_language (epdaH.unmarked_language G) (epdaH.marked_language G)\n  \\<Longrightarrow> epdaH.Nonblockingness_branching G\"\n  apply (metis epdaH.is_forward_deterministicHist_SB_def epdaH.is_forward_edge_deterministicHist_SB_vs_is_forward_edge_deterministicHist_SB_long epdaH_inst_AX_BF_BraSBRest_DetHSB_LaOp_axioms epdaH_inst_AX_is_forward_target_deterministic_correspond_SB epdaH_is_forward_target_deterministic_accessible epdaH_operational_Nonblockingness_SB_DB_Restriction)\n  done\n\ntheorem epdaHS_dependency_between_determinism_properties: \"\n  valid_epda G\n  \\<Longrightarrow>\n  epdaHS.is_forward_target_deterministic_accessible G\n  \\<and> (epdaHS.is_forward_target_deterministic_accessible G\n  \\<longleftrightarrow> epdaHS.is_forward_target_deterministicHist_SB G)\n  \\<and> (epdaHS.is_forward_target_deterministic_accessible G\n  \\<longleftrightarrow> epdaHS.is_forward_target_deterministicHist_DB G)\n  \\<and> (epdaHS.is_forward_target_deterministicHist_SB G\n  \\<longleftrightarrow> epdaHS.is_forward_target_deterministicHist_DB G)\n  \\<and> (epdaHS.is_forward_edge_deterministic_accessible G\n  \\<longleftrightarrow> epdaHS.is_forward_edge_deterministicHist_SB G)\n  \\<and> (epdaHS.is_forward_edge_deterministic_accessible G\n  \\<longleftrightarrow> epdaHS.is_forward_edge_deterministicHist_DB G)\n  \\<and> (epdaHS.is_forward_edge_deterministicHist_SB G\n  \\<longleftrightarrow> epdaHS.is_forward_edge_deterministicHist_DB G)\"\n  apply(rule conjI)\n   apply(rule epdaHS_is_forward_target_deterministic_accessible)\n   apply(force)\n  apply(rule conjI)\n   apply (metis epdaHS.is_forward_target_deterministicHist_SB_vs_is_forward_target_deterministicHist_SB_long epdaHS.is_forward_target_deterministic_accessible_implies_is_forward_target_deterministicHist_SB_long epdaHS_is_forward_target_deterministic_accessible)\n  apply(rule conjI)\n   apply (metis epdaHS.is_forward_target_deterministicHist_DB_vs_is_forward_target_deterministicHist_DB_long epdaHS.is_forward_target_deterministic_accessible_implies_is_forward_target_deterministicHist_DB_long epdaHS_is_forward_target_deterministic_accessible)\n  apply(rule conjI)\n   apply (metis epdaHS.is_forward_target_deterministicHist_DB_vs_is_forward_target_deterministicHist_DB_long epdaHS.is_forward_target_deterministicHist_SB_vs_is_forward_target_deterministicHist_SB_long epdaHS_inst_AX_is_forward_target_deterministic_correspond_DB epdaHS_inst_AX_is_forward_target_deterministic_correspond_SB)\n  apply(rule conjI)\n   apply (metis epdaHS.AX_is_forward_edge_deterministic_correspond_SB epdaHS.is_forward_edge_deterministicHist_SB_vs_is_forward_edge_deterministicHist_SB_long)\n  apply(rule conjI)\n   apply (metis epdaHS.AX_is_forward_edge_deterministic_correspond_DB epdaHS.is_forward_edge_deterministicHist_DB_vs_is_forward_edge_deterministicHist_DB_long)\n  apply (metis epdaHS.AX_is_forward_edge_deterministic_correspond_DB_SB epdaHS.is_forward_edge_deterministicHist_DB_vs_is_forward_edge_deterministicHist_DB_long epdaHS.is_forward_edge_deterministicHist_SB_vs_is_forward_edge_deterministicHist_SB_long)\n  done\n\ncorollary epdaHS_operational_Nonblockingness_SB_DB_Restriction: \"\n  valid_epda G\n  \\<Longrightarrow> (epdaHS.Nonblockingness_linear G\n        \\<longleftrightarrow> epdaHS.Nonblockingness_linear_restricted G)\n  \\<and> (epdaHS.Nonblockingness_linear_DB G\n        \\<longleftrightarrow> epdaHS.Nonblockingness_linear_restricted_DB G)\n  \\<and> (epdaHS.Nonblockingness_linear G\n        \\<longleftrightarrow> epdaHS.Nonblockingness_linear_DB G)\n  \\<and> (epdaHS.Nonblockingness_linear_restricted G\n        \\<longleftrightarrow> epdaHS.Nonblockingness_linear_restricted_DB G)\"\n  apply(rule conjI)\n   apply(simp add: epdaHS.Nonblockingness_linear_restricted_DB_def epdaHS.Nonblockingness_linear_restricted_def epdaHS.Nonblockingness_linear_def epdaHS.Nonblockingness_linear_DB_def)\n  apply(rule conjI)\n   apply(simp add: epdaHS.Nonblockingness_linear_restricted_DB_def epdaHS.Nonblockingness_linear_restricted_def epdaHS.Nonblockingness_linear_def epdaHS.Nonblockingness_linear_DB_def)\n  apply(rule conjI)\n   apply (metis epdaHS.Nonblockingness_linear_vs_Nonblockingness_linear_DB)\n  apply(metis epdaHS.Nonblockingness_linear_restricted_SB_vs_Nonblockingness_linear_restricted_DB_1 epdaHS.Nonblockingness_linear_restricted_SB_vs_Nonblockingness_linear_restricted_DB_2)\n  done\n\ncorollary epdaHS_language_Nonblockingness_from_operational_Nonblockingness: \"\n  valid_epda G\n  \\<Longrightarrow> epdaHS.Nonblockingness_linear G\n  \\<Longrightarrow> nonblockingness_language (epdaHS.unmarked_language G) (epdaHS.marked_language G)\"\n  apply(metis epdaHS.AX_BF_LinSB_OpLa)\n  done\n\ncorollary epdaHS_operational_Nonblockingness_from_language_Nonblockingness: \"\n  valid_epda G\n  \\<Longrightarrow> epdaHS.is_forward_edge_deterministic_accessible G\n  \\<Longrightarrow> nonblockingness_language (epdaHS.unmarked_language G) (epdaHS.marked_language G)\n  \\<Longrightarrow> epdaHS.Nonblockingness_linear G\"\n  apply(subgoal_tac \"epdaHS.is_forward_deterministic_accessible G\")\n   apply(thin_tac \"epdaHS.is_forward_edge_deterministic_accessible G\")\n   apply (metis epdaHS.AX_BF_LinSBRest_DetR_LaOp epdaHS_operational_Nonblockingness_SB_DB_Restriction)\n  apply (metis epdaHS.is_forward_deterministic_accessible_def epdaHS_is_forward_target_deterministic_accessible)\n  done\n\ntheorem epdaS_dependency_between_determinism_properties: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.is_forward_target_deterministic_accessible G\"\n  apply (metis epda_is_is_forward_target_deterministic_accessible)\n  done\n\ncorollary epdaS_operational_Nonblockingness_SB_DB_Restriction: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.Nonblockingness_linear_DB G \\<longleftrightarrow> epdaS.Nonblockingness_linear_restricted_DB G\"\n  apply(simp add: epdaS.Nonblockingness_linear_restricted_DB_def epdaS.Nonblockingness_linear_DB_def)\n  done\n\ncorollary epdaS_language_Nonblockingness_from_operational_Nonblockingness: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.Nonblockingness_linear_DB G\n  \\<Longrightarrow> nonblockingness_language (epdaS.unmarked_language G) (epdaS.marked_language G)\"\n  apply(metis epdaS.AX_BF_LinDB_OpLa)\n  done\n\ncorollary epdaS_operational_Nonblockingness_from_language_Nonblockingness: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.is_forward_edge_deterministic_accessible G\n  \\<Longrightarrow> nonblockingness_language (epdaS.unmarked_language G) (epdaS.marked_language G)\n  \\<Longrightarrow> epdaS.Nonblockingness_linear_DB G\n      \\<and> epdaS.Nonblockingness_linear_restricted_DB G\"\n  apply(subgoal_tac \"epdaS.is_forward_deterministic_accessible G\")\n   apply(rule_tac\n      t=\"epdaS.Nonblockingness_linear_DB G\"\n      and s=\"epdaS.Nonblockingness_linear_restricted_DB G\"\n      in ssubst)\n    apply(simp add: epdaS.Nonblockingness_linear_DB_def epdaS.Nonblockingness_linear_restricted_DB_def)\n   apply(metis epdaS.AX_BF_LinDBRest_DetR_LaOp)\n  apply(simp only: epdaS.is_forward_deterministic_accessible_def)\n  apply(rule conjI)\n   prefer 2\n   apply(force)\n  apply(thin_tac \"epdaS.is_forward_edge_deterministic_accessible G\")\n  apply(thin_tac \"nonblockingness_language (epdaS.unmarked_language G) (epdaS.marked_language G)\")\n  apply(metis epda_is_is_forward_target_deterministic_accessible)\n  done\n\ncorollary epda_inter_semantics_determinsim_relationship: \"\n  valid_epda G\n  \\<Longrightarrow>\n  (epdaS.is_forward_target_deterministic_accessible G\n  \\<longleftrightarrow> epdaHS.is_forward_target_deterministic_accessible G)\n  \\<and> (epdaS.is_forward_target_deterministic_accessible G\n  \\<longleftrightarrow> epdaH.is_forward_target_deterministic_accessible G)\n  \\<and> (epdaS.is_forward_edge_deterministic_accessible G\n  \\<longleftrightarrow> epdaHS.is_forward_edge_deterministic_accessible G)\n  \\<and> (epdaH.is_forward_edge_deterministicHist_SB G\n  \\<longleftrightarrow> epdaHS.is_forward_edge_deterministicHist_SB G)\"\n  apply(rule_tac\n      t=\"epdaS.is_forward_target_deterministic_accessible G\"\n      and s=\"True\"\n      in ssubst)\n   apply (metis epdaS_dependency_between_determinism_properties)\n  apply(rule_tac\n      t=\"epdaHS.is_forward_target_deterministic_accessible G\"\n      and s=\"True\"\n      in ssubst)\n   apply (metis epdaHS_is_forward_target_deterministic_accessible)\n  apply(rule_tac\n      t=\"epdaH.is_forward_target_deterministic_accessible G\"\n      and s=\"True\"\n      in ssubst)\n   apply (metis epdaH_dependency_between_determinism_properties)\n  apply(rule conjI)\n   apply(force)\n  apply(rule conjI)\n   apply(force)\n  apply(rule conjI)\n   apply (metis epdaS_vs_epdaHS.preservation_of_determinism epdaS_vs_epdaHS_TSstructure_rel_def)\n  apply (metis epdaHS.AX_is_forward_edge_deterministic_correspond_SB epdaHS.is_forward_edge_deterministicHist_SB_vs_is_forward_edge_deterministicHist_SB_long epdaH_vs_epdaHS.is_forward_edge_deterministic_accessible_vs_is_forward_edge_deterministicHist_SB)\n  done\n\nlemma epda_unmarked_language_prefix_closed: \"\n  valid_epda P\n  \\<Longrightarrow> Nonblockingness2 (epdaH.unmarked_language P) (epdaH.unmarked_language P)\"\n  apply(simp add: Nonblockingness2_def)\n  apply(simp add: epdaH.marked_language_def epdaH.unmarked_language_def prefix_closure_def prefix_def)\n  apply(clarsimp)\n  apply(rename_tac x d c)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. d 0 = Some (pair None c)\")\n   apply(rename_tac x d c)(*strict*)\n   prefer 2\n   apply(rule epdaH.some_position_has_details_at_0)\n   apply(force)\n  apply(rename_tac x d c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d c ca)(*strict*)\n  apply(subgoal_tac \"ca \\<in> epdaH_initial_configurations P\")\n   apply(rename_tac x d c ca)(*strict*)\n   prefer 2\n   apply(simp add: epdaH.derivation_initial_def)\n  apply(rename_tac x d c ca)(*strict*)\n  apply(simp add: epdaH_initial_configurations_def)\n  apply(clarsimp)\n  apply(case_tac ca)\n  apply(rename_tac x d c ca epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d c)(*strict*)\n  apply(simp add: epdaH_unmarked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac x d c i e ca)(*strict*)\n  apply(rule_tac\n      x=\"d\"\n      in exI)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>k\\<le>i. (\\<forall>i<k. \\<not> (\\<lambda>k. \\<exists>c' e. d k = Some (pair e c') \\<and> length(epdaH_conf_history c')\\<ge>(length x)) i) \\<and> (\\<lambda>k. \\<exists>c' e. d k = Some (pair e c') \\<and> length(epdaH_conf_history c')\\<ge>(length x)) k\")\n   apply(rename_tac x d c i e ca)(*strict*)\n   prefer 2\n   apply(rule ex_least_nat_le_prime)\n   apply(clarsimp)\n   apply(case_tac ca)\n   apply(rename_tac x d c i e ca epdaH_conf_state epdaH_conf_historya epdaH_conf_stack)(*strict*)\n   apply(force)\n  apply(rename_tac x d c i e ca)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d c i e ca k c' ea)(*strict*)\n  apply(case_tac k)\n   apply(rename_tac x d c i e ca k c' ea)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i e ca)(*strict*)\n   apply(rule_tac\n      x=\"0\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac x d c i e ca k c' ea nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d c i e ca c' ea nat)(*strict*)\n  apply(erule_tac\n      x=\"nat\"\n      in allE)\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac x d c i e ca c' ea nat)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"d\"\n      and n=\"nat\"\n      and m=\"i\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac x d c i e ca c' ea nat)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n    apply(rename_tac x d c i e ca c' ea nat)(*strict*)\n    apply(force)\n   apply(rename_tac x d c i e ca c' ea nat)(*strict*)\n   apply(force)\n  apply(rename_tac x d c i e ca c' ea nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d c i e ca c' nat e1 e2 c1)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. epdaH_conf_history ca = (epdaH_conf_history c1)@w\")\n   apply(rename_tac x d c i e ca c' nat e1 e2 c1)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac x d c i e ca c' nat e1 e2 c1)(*strict*)\n    prefer 2\n    apply(rule_tac\n      n=\"nat\"\n      and m=\"i-nat\"\n      in epdaH.steps_extend_history_derivation)\n        apply(rename_tac x d c i e ca c' nat e1 e2 c1)(*strict*)\n        apply(force)\n       apply(rename_tac x d c i e ca c' nat e1 e2 c1)(*strict*)\n       apply(force)\n      apply(rename_tac x d c i e ca c' nat e1 e2 c1)(*strict*)\n      prefer 2\n      apply(simp add: get_configuration_def)\n     apply(rename_tac x d c i e ca c' nat e1 e2 c1)(*strict*)\n     apply(rule epdaH.belongs_configurations)\n      apply(rename_tac x d c i e ca c' nat e1 e2 c1)(*strict*)\n      apply(rule epdaH.derivation_initial_belongs)\n       apply(rename_tac x d c i e ca c' nat e1 e2 c1)(*strict*)\n       apply(force)\n      apply(rename_tac x d c i e ca c' nat e1 e2 c1)(*strict*)\n      apply(force)\n     apply(rename_tac x d c i e ca c' nat e1 e2 c1)(*strict*)\n     apply(force)\n    apply(rename_tac x d c i e ca c' nat e1 e2 c1)(*strict*)\n    apply(clarsimp)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac x d c i e ca c' nat e1 e2 c1)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x d c i e ca c' nat e1 e2 c1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. epdaH_conf_history c' = (epdaH_conf_history c1)@w\")\n   apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n    prefer 2\n    apply(rule_tac\n      n=\"nat\"\n      and m=\"Suc 0\"\n      in epdaH.steps_extend_history_derivation)\n        apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n        apply(force)\n       apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n       apply(force)\n      apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n      prefer 2\n      apply(simp add: get_configuration_def)\n     apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n     apply(rule epdaH.belongs_configurations)\n      apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n      apply(rule epdaH.derivation_initial_belongs)\n       apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n       apply(force)\n      apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n      apply(force)\n     apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n     apply(force)\n    apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n    apply(clarsimp)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. epdaH_conf_history ca = (epdaH_conf_history c')@w\")\n   apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n    prefer 2\n    apply(rule_tac\n      n=\"Suc nat\"\n      and m=\"i-Suc nat\"\n      in epdaH.steps_extend_history_derivation)\n        apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n        apply(force)\n       apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n       apply(force)\n      apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n      prefer 2\n      apply(simp add: get_configuration_def)\n     apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n     apply(rule epdaH.belongs_configurations)\n      apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n      apply(rule epdaH.derivation_initial_belongs)\n       apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n       apply(force)\n      apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n      apply(force)\n     apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n     apply(force)\n    apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac x d c i e ca c' nat e1 e2 c1 w wa)(*strict*)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x d c i e ca c' nat e1 e2 c1 w)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d c i e ca c' nat e1 e2 c1 wa wb)(*strict*)\n  apply(rule_tac\n      x=\"Suc nat\"\n      in exI)\n  apply(clarsimp)\n  apply(simp add: epdaH_step_relation_def valid_epda_def)\n  apply(clarsimp)\n  apply(rename_tac x d c i e ca c' nat e1 e2 c1 wb w)(*strict*)\n  apply(erule_tac\n      x=\"e2\"\n      in ballE)\n   apply(rename_tac x d c i e ca c' nat e1 e2 c1 wb w)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac x d c i e ca c' nat e1 e2 c1 wb w)(*strict*)\n  apply(case_tac ca)\n  apply(rename_tac x d c i e ca c' nat e1 e2 c1 wb w epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n  apply(rename_tac q h s)\n  apply(rename_tac x d c i e ca c' nat e1 e2 c1 wb w q h s)(*strict*)\n  apply(case_tac c1)\n  apply(rename_tac x d c i e ca c' nat e1 e2 c1 wb w q h s epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n  apply(rename_tac q1 h1 s1)\n  apply(rename_tac x d c i e ca c' nat e1 e2 c1 wb w q h s q1 h1 s1)(*strict*)\n  apply(case_tac c')\n  apply(rename_tac x d c i e ca c' nat e1 e2 c1 wb w q h s q1 h1 s1 epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n  apply(rename_tac q2 h2 s2)\n  apply(rename_tac x d c i e ca c' nat e1 e2 c1 wb w q h s q1 h1 s1 q2 h2 s2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d c i e nat e1 e2 wb w q s h1)(*strict*)\n  apply(case_tac \"edge_event e2\")\n   apply(rename_tac x d c i e nat e1 e2 wb w q s h1)(*strict*)\n   apply(clarsimp)\n   apply(simp add: option_to_list_def)\n  apply(rename_tac x d c i e nat e1 e2 wb w q s h1 a)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(subgoal_tac \"length x = Suc (length h1)\")\n   apply(rename_tac x d c i e nat e1 e2 wb w q s h1 a)(*strict*)\n   prefer 2\n   apply (metis le_SucE)\n  apply(rename_tac x d c i e nat e1 e2 wb w q s h1 a)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"prefix h1 x \\<or> prefix x h1\")\n   apply(rename_tac x d c i e nat e1 e2 wb w q s h1 a)(*strict*)\n   prefer 2\n   apply(rule mutual_prefix_prefix)\n   apply(rule sym)\n   apply(force)\n  apply(rename_tac x d c i e nat e1 e2 wb w q s h1 a)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac x d c i e nat e1 e2 wb w q s h1 a)(*strict*)\n   prefer 2\n   apply(simp add: prefix_def)\n   apply(clarsimp)\n  apply(rename_tac x d c i e nat e1 e2 wb w q s h1 a)(*strict*)\n  apply(simp add: prefix_def)\n  apply(clarsimp)\n  apply(rename_tac d c i e nat e1 e2 wb w q s h1 a ca)(*strict*)\n  apply(case_tac ca)\n   apply(rename_tac d c i e nat e1 e2 wb w q s h1 a ca)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d c i e nat e1 e2 wb w q s h1 a ca aa list)(*strict*)\n  apply(clarsimp)\n  done\n\ncorollary epda_inter_semantics_language_relationship: \"\n  valid_epda G\n  \\<Longrightarrow>\n  (epdaH.marked_language G \\<subseteq> epdaH.unmarked_language G)\n  \\<and> (epdaS.marked_language G = epdaHS.marked_language G)\n  \\<and> (epdaHS.marked_language G = epdaH.marked_language G)\n  \\<and> (epdaS.unmarked_language G = epdaHS.unmarked_language G)\n  \\<and> (epdaHS.unmarked_language G = epdaH.unmarked_language G)\n  \\<and> (epdaH.unmarked_language G = prefix_closure (epdaH.unmarked_language G))\"\n  apply(rule context_conjI)\n   apply (metis epdaH.lang_inclusion)\n  apply(rule context_conjI)\n   apply (metis epdaS_to_epdaHS_mlang)\n  apply(rule context_conjI)\n   apply (metis epdaH_to_epdaHS_mlang)\n  apply(rule context_conjI)\n   apply (metis epdaS_vs_epdaHS_Nonblockingness_and_lang_transfer)\n  apply(rule context_conjI)\n   apply (metis epdaS_to_epdaH_unmarked_language)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule epda_unmarked_language_prefix_closed)\n   apply(force)\n  apply(simp add: Nonblockingness2_def)\n  apply(rule antisym)\n   apply(simp add: prefix_closure_def prefix_def)\n   apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   apply(force)\n  apply(force)\n  done\n\ncorollary epda_inter_semantics_Nonblockingnessness_relationship: \"\n  valid_epda G\n  \\<Longrightarrow> (epdaHS.Nonblockingness_linear G \\<longleftrightarrow> epdaH.Nonblockingness_branching G)\n  \\<and> (epdaH.Nonblockingness_branching G \\<longleftrightarrow> epdaS.Nonblockingness_linear_DB G)\"\n  apply(rule context_conjI)\n   apply (metis epdaH_vs_epdaHS.bfbra_to_bflin epdaH_vs_epdaHS.bflin_to_bfbra)\n  apply(subgoal_tac \"(epdaHS.Nonblockingness_linear G \\<longleftrightarrow> epdaS.Nonblockingness_linear_DB G)\")\n   prefer 2\n   apply(subgoal_tac \"(epdaHS.Nonblockingness_linear_DB G \\<longleftrightarrow> epdaS.Nonblockingness_linear_DB G) \\<and> epdaHS.unmarked_language G = epdaS.unmarked_language G \\<and> epdaHS.marked_language G = epdaS.marked_language G\")\n    prefer 2\n    apply(rule epdaS_vs_epdaHS_Nonblockingness_and_lang_transfer)\n    apply(force)\n   apply(rule_tac\n      t=\"epdaHS.Nonblockingness_linear G\"\n      and s=\"epdaHS.Nonblockingness_linear_DB G\"\n      in ssubst)\n    prefer 2\n    apply(force)\n   apply (metis epdaHS_operational_Nonblockingness_SB_DB_Restriction)\n  apply(rule_tac\n      t=\"epdaHS.Nonblockingness_linear G\"\n      and s=\"epdaS.Nonblockingness_linear_DB G\"\n      in ssubst)\n   apply(force)\n  apply(metis)\n  done\n\ndefinition epdaHS_accessible_edges :: \"('q,'a,'b)epda \\<Rightarrow> ('q,'a,'b)epda_step_label set\" where\n  \"epdaHS_accessible_edges M \\<equiv> {e\\<in> (epda_delta M). \\<exists>d n c. epdaHS.derivation_initial M d \\<and> d n = Some (pair (Some e) c)}\"\n\nlemma epdaHS_accessible_edges_vs_epdaH_accessible_edges_1: \"\n  valid_epda G\n  \\<Longrightarrow> epdaHS_accessible_edges G \\<subseteq> epdaH_accessible_edges G\"\n  apply(simp add: epdaHS_accessible_edges_def epdaH_accessible_edges_def)\n  apply(clarsimp)\n  apply(rename_tac x d n c)(*strict*)\n  apply(rule_tac\n      x=\"ATS_Branching_Versus_Linear1.Lin2BraDer epdaHvHS_Lin2BraConf d\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac x d n c)(*strict*)\n   apply(rule epdaH_vs_epdaHS.Lin2BraConf_preserves_initiality_lift)\n    apply(rename_tac x d n c)(*strict*)\n    apply(force)\n   apply(rename_tac x d n c)(*strict*)\n   apply(force)\n  apply(rename_tac x d n c)(*strict*)\n  apply(rule_tac\n      x=\"n\"\n      in exI)\n  apply(simp add: epdaH_vs_epdaHS.Lin2BraDer_def derivation_map_def)\n  done\n\nlemma epdaHS_accessible_edges_vs_epdaH_accessible_edges_2: \"\n  valid_epda G\n  \\<Longrightarrow> epdaH_accessible_edges G \\<subseteq> epdaHS_accessible_edges G\"\n  apply(simp add: epdaHS_accessible_edges_def epdaH_accessible_edges_def)\n  apply(clarsimp)\n  apply(rename_tac x d n c)(*strict*)\n  apply(rule_tac\n      x=\"epdaH_vs_epdaHS.Bra2LinDer G d n\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac x d n c)(*strict*)\n   apply(rule epdaH_vs_epdaHS.AX_Bra2LinConf_preserves_initiality_lift)\n     apply(rename_tac x d n c)(*strict*)\n     apply(force)\n    apply(rename_tac x d n c)(*strict*)\n    apply(force)\n   apply(rename_tac x d n c)(*strict*)\n   apply(force)\n  apply(rename_tac x d n c)(*strict*)\n  apply(rule_tac\n      x=\"n\"\n      in exI)\n  apply(simp add: epdaH_vs_epdaHS.Bra2LinDer_def)\n  done\n\nlemma epdaH_accessible_edges_vs_epdaHS_accessible_edges: \"\n  valid_epda G\n  \\<Longrightarrow> epdaH_accessible_edges G = epdaHS_accessible_edges G\"\n  apply (metis epdaHS_accessible_edges_vs_epdaH_accessible_edges_1 epdaHS_accessible_edges_vs_epdaH_accessible_edges_2 equalityI)\n  done\n\nlemma epdaHS_accessible_edges_vs_epdaS_accessible_edges_1: \"\n  valid_epda G\n  \\<Longrightarrow> epdaHS_accessible_edges G \\<subseteq> epdaS_accessible_edges G\"\n  apply(simp add: epdaS_accessible_edges_def epdaHS_accessible_edges_def)\n  apply(clarsimp)\n  apply(rename_tac x d n c)(*strict*)\n  apply(rule_tac\n      x=\"epdaHS2epdaS_derivation d\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac x d n c)(*strict*)\n   apply(rule epdaHS2epdaS_derivation_preserves_derivation_initial)\n    apply(rename_tac x d n c)(*strict*)\n    apply(force)\n   apply(rename_tac x d n c)(*strict*)\n   apply(force)\n  apply(rename_tac x d n c)(*strict*)\n  apply(simp add: epdaHS2epdaS_derivation_def)\n  apply(rule_tac\n      x=\"n\"\n      in exI)\n  apply(clarsimp)\n  done\n\nlemma epdaHS_accessible_edges_vs_epdaS_accessible_edges_2: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS_accessible_edges G \\<subseteq> epdaHS_accessible_edges G\"\n  apply(simp add: epdaS_accessible_edges_def epdaHS_accessible_edges_def)\n  apply(clarsimp)\n  apply(rename_tac x d n c)(*strict*)\n  apply(rule_tac\n      x=\"epdaS2epdaHS_derivation G d\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac x d n c)(*strict*)\n   apply(rule epdaS2epdaHS_derivation_preserves_derivation_initial)\n    apply(rename_tac x d n c)(*strict*)\n    apply(force)\n   apply(rename_tac x d n c)(*strict*)\n   apply(force)\n  apply(rename_tac x d n c)(*strict*)\n  apply(simp add: epdaS2epdaHS_derivation_def)\n  apply(rule_tac\n      x=\"n\"\n      in exI)\n  apply(clarsimp)\n  done\n\nlemma epdaS_accessible_edges_vs_epdaHS_accessible_edges: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS_accessible_edges G = epdaHS_accessible_edges G\"\n  apply (metis epdaHS_accessible_edges_vs_epdaS_accessible_edges_1 epdaHS_accessible_edges_vs_epdaS_accessible_edges_2 equalityI)\n  done\n\nlemma epdaH_accessible_edges_vs_epdaS_accessible_edges: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS_accessible_edges G = epdaH_accessible_edges G\"\n  apply (metis epdaH_accessible_edges_vs_epdaHS_accessible_edges epdaS_accessible_edges_vs_epdaHS_accessible_edges)\n  done\n\nlemma accessible_implies_accessible: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.accessible G\n  \\<Longrightarrow> accessible G\"\n  apply(simp add: accessible_def)\n  apply(rule conjI)\n   apply(simp add: all_states_accessible_def epdaS.accessible_def epda_destinations_def)\n   apply(erule conjE)\n   apply(thin_tac \"edge ` epda_delta G\n    \\<subseteq> ATS_Destinations.get_accessible_destinations epdaS_initial_configurations\n        epdaS_step_relation epda_destinations epdaS_get_destinations G\")\n   apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   apply(subgoal_tac \"state x \\<in> epdaS.get_accessible_destinations G\")\n    apply(rename_tac x)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac x)(*strict*)\n   apply(thin_tac \"state ` epda_states G\n         \\<subseteq> ATS_Destinations.get_accessible_destinations epdaS_initial_configurations\n             epdaS_step_relation epda_destinations epdaS_get_destinations G\")\n   apply(simp add: epdaS.get_accessible_destinations_def epdaS_get_destinations_def)\n   apply(clarsimp)\n   apply(rename_tac x d i e c)(*strict*)\n   apply(erule_tac disjE)\n    apply(rename_tac x d i e c)(*strict*)\n    prefer 2\n    apply(case_tac e)\n     apply(rename_tac x d i e c)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac x d i e c a)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac x d i e c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i e c)(*strict*)\n   apply(simp add: epdaS_accessible_states_def)\n   apply(rule_tac x=\"d\" in exI)\n   apply(rule conjI)\n    apply(rename_tac d i e c)(*strict*)\n    apply(simp add: epdaS.derivation_initial_def)\n   apply(rename_tac d i e c)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d i e c)(*strict*)\n    apply(rule_tac x=\"i\" in exI)\n    apply(clarsimp)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac d i e c)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(case_tac \"d 0\")\n    apply(rename_tac d i e c)(*strict*)\n    apply(clarsimp)\n    apply(simp add: epdaS.derivation_initial_def)\n   apply(rename_tac d i e c a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac d i e c a option conf)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i e c option conf)(*strict*)\n   apply(simp add: epdaS.derivation_initial_def epdaS_initial_configurations_def)\n  apply(simp add: all_edges_accessible_def  epdaS.accessible_def epda_destinations_def)\n  apply(erule conjE)\n  apply(thin_tac \"state ` epda_states G\n    \\<subseteq> ATS_Destinations.get_accessible_destinations epdaS_initial_configurations\n        epdaS_step_relation epda_destinations epdaS_get_destinations G \")\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(subgoal_tac \"edge x \\<in> epdaS.get_accessible_destinations G\")\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(thin_tac \"edge ` epda_delta G\n         \\<subseteq> ATS_Destinations.get_accessible_destinations epdaS_initial_configurations\n             epdaS_step_relation epda_destinations epdaS_get_destinations G\")\n  apply(simp add: epdaS.get_accessible_destinations_def epdaS_get_destinations_def)\n  apply(clarsimp)\n  apply(rename_tac x d i e c)(*strict*)\n  apply(case_tac e)\n   apply(rename_tac x d i e c)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x d i e c a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i c a)(*strict*)\n  apply(simp add: epdaS_accessible_edges_def)\n  apply(rule_tac x=\"d\" in exI)\n  apply(rule conjI)\n   apply(rename_tac d i c a)(*strict*)\n   apply(simp add: epdaS.derivation_initial_def)\n  apply(rename_tac d i c a)(*strict*)\n  apply(rule_tac x=\"i\" in exI)\n  apply(clarsimp)\n  done\n\ntheorem epdaH_to_epdaHS_accessible: \"\n  valid_epda G\n  \\<Longrightarrow> epdaH.accessible G\n  \\<Longrightarrow> epdaHS.accessible G\"\n  apply(simp add: epdaHS.accessible_def epdaH.accessible_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(subgoal_tac \"x \\<in> epdaH.get_accessible_destinations G\")\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(thin_tac \"epda_destinations G \\<subseteq> epdaH.get_accessible_destinations G\")\n  apply(rename_tac x)(*strict*)\n  apply(thin_tac \"x \\<in> epda_destinations G\")\n  apply(simp add: epdaHS.get_accessible_destinations_def epdaH.get_accessible_destinations_def)\n  apply(clarsimp)\n  apply(rename_tac x d i e c)(*strict*)\n  apply(simp add: epdaH_get_destinations_def)\n  apply(case_tac c)\n  apply(rename_tac x d i e c epdaH_conf_statea epdaH_conf_history epdaH_conf_stack)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d i e q h s)(*strict*)\n  apply(rule_tac\n      x = \"epdaH_vs_epdaHS.Bra2LinDer G d i\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac x d i e q h s)(*strict*)\n   apply(rule epdaH_vs_epdaHS.AX_Bra2LinConf_preserves_initiality_lift)\n     apply(rename_tac x d i e q h s)(*strict*)\n     apply(simp add: valid_dpda_def valid_pda_def)\n    apply(rename_tac x d i e q h s)(*strict*)\n    apply(force)\n   apply(rename_tac x d i e q h s)(*strict*)\n   apply(simp add: epda_destinations_def)\n  apply(rename_tac x d i e q h s)(*strict*)\n  apply(rule_tac\n      x = \"i\"\n      in exI)\n  apply(simp add: epdaHvHS_Bra2LinConf_def derivation_map_def epdaH_vs_epdaHS.Bra2LinDer_def epdaHS_get_destinations_def)\n  done\n\ntheorem epdaHS_to_epdaS_accessible: \"\n  valid_epda G\n  \\<Longrightarrow> epdaHS.accessible G\n  \\<Longrightarrow> epdaS.accessible G\"\n  apply(simp add: epdaS.accessible_def epdaHS.accessible_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(subgoal_tac \"x \\<in> epdaHS.get_accessible_destinations G\")\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(thin_tac \"epda_destinations G \\<subseteq> epdaHS.get_accessible_destinations G\")\n  apply(rename_tac x)(*strict*)\n  apply(thin_tac \"x \\<in> epda_destinations G\")\n  apply(simp add: epdaS.get_accessible_destinations_def epdaHS.get_accessible_destinations_def)\n  apply(clarsimp)\n  apply(rename_tac x d i e c)(*strict*)\n  apply(simp add: epdaHS_get_destinations_def)\n  apply(case_tac c)\n  apply(rename_tac x d i e c epdaHS_conf_statea epdaHS_conf_history epdaHS_conf_scheduler epdaHS_conf_stack)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d n e q h i s)(*strict*)\n  apply(rule_tac\n      x = \"epdaHS2epdaS_derivation d\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac x d n e q h i s)(*strict*)\n   apply (metis epdaHS2epdaS_derivation_preserves_derivation_initial)\n  apply(rename_tac x d n e q h i s)(*strict*)\n  apply(rule_tac\n      x = \"n\"\n      in exI)\n  apply(simp add: epdaS_get_destinations_def epdaHS2epdaS_derivation_def epdaHS_get_destinations_def)\n  done\n\ntheorem accessible_vs_accessible: \"\n  valid_epda G\n  \\<Longrightarrow>\n  (epdaS.accessible G \\<longleftrightarrow> accessible G)\n  \\<and> (epdaS.accessible G \\<longleftrightarrow> epdaHS.accessible G)\n  \\<and> (epdaHS.accessible G \\<longleftrightarrow> epdaH.accessible G)\"\n  apply(rule conjI)\n   apply(rule antisym)\n    apply(clarsimp)\n    apply(rule accessible_implies_accessible)\n     apply(force)\n    apply(force)\n   apply(clarsimp)\n   apply(rule valid_epda_accessible_implies_accessible)\n    apply(force)\n   apply(force)\n  apply(rule conjI)\n   apply(rule antisym)\n    apply(clarsimp)\n    apply(rule epdaS_to_epdaHS_accessible)\n     apply(force)\n    apply(force)\n   apply(clarsimp)\n   apply(rule epdaHS_to_epdaS_accessible)\n    apply(force)\n   apply(force)\n  apply(rule antisym)\n   apply(clarsimp)\n   apply(rule epdaHS_to_epdaH_accessible)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(rule epdaH_to_epdaHS_accessible)\n   apply(force)\n  apply(force)\n  done\n\nlemma epda_box_stays_at_bottom_epdaH: \"\n  valid_epda G\n  \\<Longrightarrow> epdaH.derivation_initial G d\n  \\<Longrightarrow> d i = Some (pair e c)\n  \\<Longrightarrow> \\<exists>w. epdaH_conf_stack c = w @ [epda_box G]\"\n  apply(induct i arbitrary: e c)\n   apply(rename_tac e c)(*strict*)\n   apply(simp add: epdaH.derivation_initial_def epdaH_initial_configurations_def)\n  apply(rename_tac i e c)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d i = Some (pair e1 c1) \\<and> SSd (Suc SSn) = Some (pair (Some e2) c2) \\<and> epdaH_step_relation SSG c1 e2 c2\" for SSd SSn SSG)\n   apply(rename_tac i e c)(*strict*)\n   prefer 2\n   apply(rule epdaH.step_detail_before_some_position)\n     apply(rename_tac i e c)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n     apply(force)\n    apply(rename_tac i e c)(*strict*)\n    apply(force)\n   apply(rename_tac i e c)(*strict*)\n   apply(force)\n  apply(rename_tac i e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1)(*strict*)\n  apply(erule_tac\n      x=\"e1\"\n      in meta_allE)\n  apply(erule_tac\n      x=\"c1\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1 w)(*strict*)\n  apply(simp add: epdaH_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1 w wa)(*strict*)\n  apply(subgoal_tac \"valid_epda_step_label G e2\")\n   apply(rename_tac i c e1 e2 c1 w wa)(*strict*)\n   apply(case_tac wa)\n    apply(rename_tac i c e1 e2 c1 w wa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i c e1 e2 c1 w)(*strict*)\n    apply(subgoal_tac \"edge_push e2 \\<in> must_terminated_by (epda_gamma G) (epda_box G)\")\n     apply(rename_tac i c e1 e2 c1 w)(*strict*)\n     prefer 2\n     apply(rule epda_push_also_must_terminated_by)\n       apply(rename_tac i c e1 e2 c1 w)(*strict*)\n       apply(force)\n      apply(rename_tac i c e1 e2 c1 w)(*strict*)\n      apply(force)\n     apply(rename_tac i c e1 e2 c1 w)(*strict*)\n     apply(rule may_terminated_by_EndStrY)\n      apply(rename_tac i c e1 e2 c1 w)(*strict*)\n      apply(simp add: valid_epda_step_label_def)\n     apply(rename_tac i c e1 e2 c1 w)(*strict*)\n     apply(rule_tac\n      x=\"w\"\n      in exI)\n     apply(force)\n    apply(rename_tac i c e1 e2 c1 w)(*strict*)\n    apply(simp add: must_terminated_by_def kleene_star_def append_language_def)\n    apply(force)\n   apply(rename_tac i c e1 e2 c1 w wa a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. wa = w' @ [x']\")\n    apply(rename_tac i c e1 e2 c1 w wa a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac i c e1 e2 c1 w wa a list)(*strict*)\n   apply(thin_tac \"wa = a # list\")\n   apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1 w wa)(*strict*)\n  apply(simp add: valid_epda_def)\n  done\n\nlemma never_not_present_implies_always_present: \"\n  valid_simple_dpda G\n  \\<Longrightarrow> epdaH.derivation_initial G d\n  \\<Longrightarrow> maximum_of_domain d nX\n  \\<Longrightarrow> d n = Some (pair e1 c1)\n  \\<Longrightarrow> epdaH_conf_stack c1 = v1 @ x1 # w\n  \\<Longrightarrow> (\\<forall>xa \\<le> nX. n \\<le> xa \\<longrightarrow> (\\<forall>e c. d xa = Some (pair e c) \\<longrightarrow> epdaH_conf_stack c \\<noteq> x1 # w))\n  \\<Longrightarrow> (\\<forall>e2 c2. d (n+k) = Some (pair e2 c2) \\<longrightarrow> (\\<exists>v2. epdaH_conf_stack c2 = v2 @ x1 # w))\"\n  apply(induct k)\n   apply(clarsimp)\n  apply(rename_tac k)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k e2 c2)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d (n+k) = Some (pair e1 c1) \\<and> SSd (Suc SSn) = Some (pair (Some e2) c2) \\<and> epdaH_step_relation SSG c1 e2 c2\" for SSd SSn SSG)\n   apply(rename_tac k e2 c2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"(Suc(n+k))\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac k e2 c2)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n     apply(force)\n    apply(rename_tac k e2 c2)(*strict*)\n    apply(force)\n   apply(rename_tac k e2 c2)(*strict*)\n   apply(force)\n  apply(rename_tac k e2 c2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k c2 e1a e2a c1a v2)(*strict*)\n  apply(subgoal_tac \"\\<exists>x. edge_pop e2a=[x]\")\n   apply(rename_tac k c2 e1a e2a c1a v2)(*strict*)\n   prefer 2\n   apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"e2a\"\n      and P=\"\\<lambda>e2a. length (edge_pop e2a) = Suc 0\"\n      in ballE)\n    apply(rename_tac k c2 e1a e2a c1a v2)(*strict*)\n    prefer 2\n    apply(simp add: epdaH_step_relation_def)\n   apply(rename_tac k c2 e1a e2a c1a v2)(*strict*)\n   apply(case_tac \"edge_pop e2a\")\n    apply(rename_tac k c2 e1a e2a c1a v2)(*strict*)\n    apply(force)\n   apply(rename_tac k c2 e1a e2a c1a v2 a list)(*strict*)\n   apply(case_tac list)\n    apply(rename_tac k c2 e1a e2a c1a v2 a list)(*strict*)\n    apply(force)\n   apply(rename_tac k c2 e1a e2a c1a v2 a list aa lista)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac k c2 e1a e2a c1a v2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k c2 e1a e2a c1a v2 x)(*strict*)\n  apply(simp add: valid_simple_dpda_def)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"e2a\"\n      in ballE)\n   apply(rename_tac k c2 e1a e2a c1a v2 x)(*strict*)\n   prefer 2\n   apply(simp add: epdaH_step_relation_def)\n  apply(rename_tac k c2 e1a e2a c1a v2 x)(*strict*)\n  apply(simp add: epdaH_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac k c2 e1a e2a c1a v2 x wa)(*strict*)\n  apply(case_tac v1)\n   apply(rename_tac k c2 e1a e2a c1a v2 x wa)(*strict*)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"n\"\n      in allE)\n   apply(erule impE)\n    apply(rename_tac k c2 e1a e2a c1a v2 x wa)(*strict*)\n    apply (rule epdaH.allPreMaxDomSome_prime)\n      apply(rename_tac k c2 e1a e2a c1a v2 x wa)(*strict*)\n      apply(rule epdaH.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac k c2 e1a e2a c1a v2 x wa)(*strict*)\n     apply(force)\n    apply(rename_tac k c2 e1a e2a c1a v2 x wa)(*strict*)\n    apply(force)\n   apply(rename_tac k c2 e1a e2a c1a v2 x wa)(*strict*)\n   apply(force)\n  apply(rename_tac k c2 e1a e2a c1a v2 x wa a list)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"edge_event e2a\")\n   apply(rename_tac k c2 e1a e2a c1a v2 x wa a list)(*strict*)\n   apply(clarsimp)\n   apply(erule disjE)\n    apply(rename_tac k c2 e1a e2a c1a v2 x wa a list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac k c2 e1a e2a c1a v2 x a list)(*strict*)\n    apply(case_tac v2)\n     apply(rename_tac k c2 e1a e2a c1a v2 x a list)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac k c2 e1a e2a c1a a list)(*strict*)\n     apply(erule_tac\n      x=\"(n+k)\"\n      in allE)\n     apply(erule impE)\n      apply(rename_tac k c2 e1a e2a c1a a list)(*strict*)\n      apply (metis epdaH.allPreMaxDomSome_prime epdaH.derivation_initial_is_derivation not_None_eq)\n     apply(rename_tac k c2 e1a e2a c1a a list)(*strict*)\n     apply(erule impE)\n      apply(rename_tac k c2 e1a e2a c1a a list)(*strict*)\n      apply(force)\n     apply(rename_tac k c2 e1a e2a c1a a list)(*strict*)\n     apply(erule_tac\n      x=\"e1a\"\n      in allE)\n     apply(erule_tac\n      x=\"c1a\"\n      in allE)\n     apply(erule impE)\n      apply(rename_tac k c2 e1a e2a c1a a list)(*strict*)\n      apply(force)\n     apply(rename_tac k c2 e1a e2a c1a a list)(*strict*)\n     apply(force)\n    apply(rename_tac k c2 e1a e2a c1a v2 x a list aa lista)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac k c2 e1a e2a c1a x a list lista)(*strict*)\n    apply(case_tac c2)\n    apply(rename_tac k c2 e1a e2a c1a x a list lista epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac k c2 e1a e2a c1a v2 x wa a list)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac k c2 e1a e2a c1a v2 x wa a list xa)(*strict*)\n   apply(rule_tac\n      x=\"xa # v2\"\n      in exI)\n   apply(force)\n  apply(rename_tac k c2 e1a e2a c1a v2 x wa a list aa)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n      x=\"v2\"\n      in exI)\n  apply(force)\n  done\n\nlemma existence_of_removal: \"\n  valid_pda G\n  \\<Longrightarrow> epdaH.derivation G d\n  \\<Longrightarrow> epdaH.belongs G d\n  \\<Longrightarrow> d n1 = Some (pair e1 c1)\n  \\<Longrightarrow> d n2 = Some (pair e2 c2)\n  \\<Longrightarrow> n1 \\<le> n2\n  \\<Longrightarrow> epdaH_conf_stack c1 = w1 @ x # w2 @ w3\n  \\<Longrightarrow> epdaH_conf_stack c2 = w3\n  \\<Longrightarrow> \\<exists>n e c. d n = Some (pair e c) \\<and> n1 \\<le> n \\<and> n \\<le> n2 \\<and> epdaH_conf_stack c = x # w2 @ w3\"\n  apply(case_tac \"n1=n2\")\n   apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>k \\<le> (n2-n1). (\\<forall>i<k. \\<not>(\\<lambda>n. (case (derivation_drop d n1) n of None \\<Rightarrow> False| Some (pair e c) \\<Rightarrow> SSP c)) i) & ((\\<lambda>n. (case (derivation_drop d n1) n of None \\<Rightarrow> False| Some (pair e c) \\<Rightarrow> SSP c)))k\" for SSP)\n   prefer 2\n   apply(rule_tac\n      P=\"\\<lambda>c. \\<not>(suffix (epdaH_conf_stack c) (x # w2@w3))\"\n      in epdaH.existence_of_earliest_satisfaction_point)\n     apply(rule_tac\n      m=\"n2-n1\"\n      in epdaH.derivation_drop_preserves_derivation_prime)\n      apply(force)\n     apply(force)\n    apply(simp add: derivation_drop_def)\n   apply(simp add: suffix_def)\n  apply(clarsimp)\n  apply(rename_tac k)(*strict*)\n  apply(simp add: derivation_drop_def)\n  apply(case_tac k)\n   apply(rename_tac k)(*strict*)\n   apply(clarsimp)\n   apply(simp add: suffix_def)\n  apply(rename_tac k nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat)(*strict*)\n  apply(case_tac \"d(Suc (nat+n1))\")\n   apply(rename_tac nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac nat a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac nat a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat option b)(*strict*)\n  apply(simp add: suffix_def)\n  apply(subgoal_tac \"\\<exists>k. Suc nat+k+n1=n2\")\n   apply(rename_tac nat option b)(*strict*)\n   prefer 2\n   apply(rule_tac\n      x=\"n2-n1-Suc nat\"\n      in exI)\n   apply(force)\n  apply(rename_tac nat option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat option b k)(*strict*)\n  apply(subgoal_tac \"\\<forall>i<Suc nat. \\<not> case_option False (case_derivation_configuration (\\<lambda>e c. \\<not> epdaH_conf_stack c \\<sqsupseteq> (x # w2 @ epdaH_conf_stack c2))) (d (i + n1))\")\n   apply(rename_tac nat option b k)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac nat option b k i)(*strict*)\n   apply(erule_tac\n      x=\"i\"\n      in allE)\n   apply(clarsimp)\n   apply(case_tac i)\n    apply(rename_tac nat option b k i)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac nat option b k i nata)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac nat option b k)(*strict*)\n  apply(thin_tac \"\\<forall>i<Suc nat. \\<not> case_option False (case_derivation_configuration (\\<lambda>e c. \\<not> epdaH_conf_stack c \\<sqsupseteq> (x # w2 @ epdaH_conf_stack c2))) (if i = 0 then case_option undefined (case_derivation_configuration (\\<lambda>e c. Some (pair None c))) (d n1) else d (i + n1))\")\n  apply(rename_tac nat option b k)(*strict*)\n  apply(erule_tac\n      x=\"nat\"\n      in allE)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d (nat+n1) = Some (pair e1 c1) \\<and> SSd (Suc SSn) = Some (pair (Some e2) c2) \\<and> epdaH_step_relation SSG c1 e2 c2\" for SSd SSn SSG)\n   apply(rename_tac nat option b k)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc(nat+n1)\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac nat option b k)(*strict*)\n     apply(force)\n    apply(rename_tac nat option b k)(*strict*)\n    apply(force)\n   apply(rename_tac nat option b k)(*strict*)\n   apply(force)\n  apply(rename_tac nat option b k)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat b k e1a e2a c1a)(*strict*)\n  apply(rule_tac\n      x=\"nat+n1\"\n      in exI)\n  apply(clarsimp)\n  apply(simp add: suffix_def)\n  apply(simp add: epdaH_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac nat b k e1a e2a c1a c w)(*strict*)\n  apply(subgoal_tac \"\\<exists>x. edge_pop e2a=[x] \")\n   apply(rename_tac nat b k e1a e2a c1a c w)(*strict*)\n   prefer 2\n   apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"e2a\"\n      in ballE)\n    apply(rename_tac nat b k e1a e2a c1a c w)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac nat b k e1a e2a c1a c w)(*strict*)\n   apply(case_tac \"edge_pop e2a\")\n    apply(rename_tac nat b k e1a e2a c1a c w)(*strict*)\n    apply(force)\n   apply(rename_tac nat b k e1a e2a c1a c w a list)(*strict*)\n   apply(case_tac list)\n    apply(rename_tac nat b k e1a e2a c1a c w a list)(*strict*)\n    apply(force)\n   apply(rename_tac nat b k e1a e2a c1a c w a list aa lista)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac nat b k e1a e2a c1a c w)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat b k e1a e2a c1a c w xa)(*strict*)\n  apply(case_tac c)\n   apply(rename_tac nat b k e1a e2a c1a c w xa)(*strict*)\n   apply(force)\n  apply(rename_tac nat b k e1a e2a c1a c w xa a list)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma successor_min_stack_is_not_empty: \"\n  valid_simple_dpda G\n  \\<Longrightarrow> epdaH.derivation_initial G d\n  \\<Longrightarrow> d (Suc n) = Some (pair (Some e2) c)\n  \\<Longrightarrow> maximum_of_domain d nX\n  \\<Longrightarrow> d n = Some (pair e1 cn)\n  \\<Longrightarrow> epdaH_step_relation G cn e2 c\n  \\<Longrightarrow> edge_event e2 = None\n  \\<Longrightarrow> edge_pop e2 = [x]\n  \\<Longrightarrow> edge_push e2 = [xa, x]\n  \\<Longrightarrow> Some q2 = min_stack d (tl (epdaH_conf_stack cn)) n nX\n  \\<Longrightarrow> min_stack d (tl (epdaH_conf_stack c)) (Suc n) nX = None\n  \\<Longrightarrow> P\"\n  apply(simp add: epdaH_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac w)(*strict*)\n  apply(simp add: min_stack_def)\n  apply(case_tac \"\\<forall>x \\<le> nX. n \\<le> x \\<longrightarrow> (\\<forall>e c. d x = Some (pair e c) \\<longrightarrow> epdaH_conf_stack c \\<noteq> w)\")\n   apply(rename_tac w)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac w)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac xb e ca)(*strict*)\n  apply(case_tac \"\\<forall>xa \\<le> nX. Suc n \\<le> xa \\<longrightarrow> (\\<forall>e c. d xa = Some (pair e c) \\<longrightarrow> epdaH_conf_stack c \\<noteq> x # epdaH_conf_stack ca)\")\n   apply(rename_tac xb e ca)(*strict*)\n   prefer 2\n   apply(clarsimp)\n  apply(rename_tac xb e ca)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"n=xb\")\n   apply(rename_tac xb e ca)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac xb e ca)(*strict*)\n  apply(case_tac \"Suc n=xb\")\n   apply(rename_tac xb e ca)(*strict*)\n   apply(clarify)\n   apply(case_tac c)\n   apply(rename_tac xb e ca epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n   apply(case_tac cn)\n   apply(rename_tac xb e ca epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka epdaH_conf_stateaa epdaH_conf_historyaa epdaH_conf_stackaa)(*strict*)\n   apply(case_tac ca)\n   apply(rename_tac xb e ca epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka epdaH_conf_stateaa epdaH_conf_historyaa epdaH_conf_stackaa epdaH_conf_stateb epdaH_conf_historyb epdaH_conf_stackb)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac xb e ca)(*strict*)\n  apply(subgoal_tac \"\\<exists>k e c. d k= Some (pair e c) \\<and> Suc n \\<le> k \\<and> k \\<le> xb \\<and> epdaH_conf_stack c=x # []@(epdaH_conf_stack ca)\")\n   apply(rename_tac xb e ca)(*strict*)\n   prefer 2\n   apply(rule existence_of_removal)\n          apply(rename_tac xb e ca)(*strict*)\n          apply(simp add: valid_simple_dpda_def valid_dpda_def)\n          apply(force)\n         apply(rename_tac xb e ca)(*strict*)\n         apply(rule epdaH.derivation_initial_is_derivation)\n         apply(force)\n        apply(rename_tac xb e ca)(*strict*)\n        apply(rule epdaH.derivation_initial_belongs)\n         apply(rename_tac xb e ca)(*strict*)\n         apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n        apply(rename_tac xb e ca)(*strict*)\n        apply(force)\n       apply(rename_tac xb e ca)(*strict*)\n       apply(force)\n      apply(rename_tac xb e ca)(*strict*)\n      apply(force)\n     apply(rename_tac xb e ca)(*strict*)\n     apply(force)\n    apply(rename_tac xb e ca)(*strict*)\n    apply(force)\n   apply(rename_tac xb e ca)(*strict*)\n   apply(force)\n  apply(rename_tac xb e ca)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac xb e ca k ea caa)(*strict*)\n  apply(erule_tac\n      x=\"k\"\n      in allE)\n  apply(clarsimp)\n  done\n\nlemma min_stack_is_in_states: \"\n  valid_epda G\n  \\<Longrightarrow> epdaH.derivation_initial G d\n  \\<Longrightarrow> maximum_of_domain d nX\n  \\<Longrightarrow> d n = Some (pair e c)\n  \\<Longrightarrow> min_stack d (tl (epdaH_conf_stack c)) n nX = Some qs\n  \\<Longrightarrow> qs \\<in> epda_states G\"\n  apply(simp add: min_stack_def)\n  apply(case_tac \"\\<forall>x \\<le> nX. n \\<le> x \\<longrightarrow> (\\<forall>e ca. d x = Some (pair e ca) \\<longrightarrow> epdaH_conf_stack ca \\<noteq> tl (epdaH_conf_stack c))\")\n   apply(clarsimp)\n  apply(clarsimp)\n  apply(rename_tac x ea ca)(*strict*)\n  apply(subgoal_tac \"\\<exists>e cx. d (Min ({ i. (n \\<le> i \\<and> i \\<le> nX \\<and> (\\<exists>e cx. d i = Some (pair e cx) \\<and> epdaH_conf_stack cx = tl (epdaH_conf_stack c)))})) = Some (pair e cx)\")\n   apply(rename_tac x ea ca)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x ea ca eaa cx)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(subgoal_tac \"cx \\<in> epdaH_configurations G\")\n    apply(rename_tac x ea ca eaa cx)(*strict*)\n    apply(simp add: epdaH_configurations_def)\n    apply(clarsimp)\n   apply(rename_tac x ea ca eaa cx)(*strict*)\n   apply(rule epdaH.belongs_configurations)\n    apply(rename_tac x ea ca eaa cx)(*strict*)\n    apply(rule epdaH.derivation_initial_belongs)\n     apply(rename_tac x ea ca eaa cx)(*strict*)\n     apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n    apply(rename_tac x ea ca eaa cx)(*strict*)\n    apply(force)\n   apply(rename_tac x ea ca eaa cx)(*strict*)\n   apply(force)\n  apply(rename_tac x ea ca)(*strict*)\n  apply(rule_tac\n      m=\"x\"\n      in epdaH.pre_some_position_is_some_position)\n    apply(rename_tac x ea ca)(*strict*)\n    apply(rule epdaH.derivation_initial_is_derivation)\n    apply(force)\n   apply(rename_tac x ea ca)(*strict*)\n   apply(force)\n  apply(rename_tac x ea ca)(*strict*)\n  apply(rule Min_le)\n   apply(rename_tac x ea ca)(*strict*)\n   apply(rule_tac\n      B=\"{i. n \\<le> i \\<and> i \\<le> nX}\"\n      in finite_subset)\n    apply(rename_tac x ea ca)(*strict*)\n    apply(force)\n   apply(rename_tac x ea ca)(*strict*)\n   apply (metis finite_Collect_conjI finite_Collect_le_nat)\n  apply(rename_tac x ea ca)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma min_stack_preserved1: \"\n  valid_simple_dpda G\n  \\<Longrightarrow> epdaH.derivation_initial G d\n  \\<Longrightarrow> d (Suc n) = Some (pair e2 c2)\n  \\<Longrightarrow> maximum_of_domain d nX\n  \\<Longrightarrow> d n = Some (pair e1 c1)\n  \\<Longrightarrow> epdaH_conf_stack c1 \\<noteq> wb\n  \\<Longrightarrow> epdaH_conf_stack c2 \\<noteq> wb\n  \\<Longrightarrow> Some q2 = min_stack d wb n nX\n  \\<Longrightarrow> min_stack d wb n nX = min_stack d wb (Suc n) nX\"\n  apply(simp add: min_stack_def)\n  apply(clarsimp)\n  apply(rename_tac x e c)(*strict*)\n  apply(case_tac \"\\<forall>x \\<le> nX. n \\<le> x \\<longrightarrow> (\\<forall>e ca. d x = Some (pair e ca) \\<longrightarrow> epdaH_conf_stack ca \\<noteq> epdaH_conf_stack c)\")\n   apply(rename_tac x e c)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x e c xa ea ca)(*strict*)\n  apply(case_tac \"x=n\")\n   apply(rename_tac x e c xa ea ca)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x e c xa ea ca)(*strict*)\n  apply(rule context_conjI)\n   apply(rename_tac x e c xa ea ca)(*strict*)\n   apply(rule_tac\n      x=\"x\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac x e c xa ea ca)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x e c xa ea ca xb eb cb)(*strict*)\n  apply(rule_tac\n      f=\"\\<lambda>x. epdaH_conf_state (the (get_configuration (d (Min x))))\"\n      in HOL.arg_cong)\n  apply(rename_tac x e c xa ea ca xb eb cb)(*strict*)\n  apply(rule order_antisym)\n   apply(rename_tac x e c xa ea ca xb eb cb)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x e c xa ea ca xb eb cb xc ec cc)(*strict*)\n   apply(case_tac \"xc=n\")\n    apply(rename_tac x e c xa ea ca xb eb cb xc ec cc)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac x e c xa ea ca xb eb cb xc ec cc)(*strict*)\n   apply(force)\n  apply(rename_tac x e c xa ea ca xb eb cb)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma min_stack_preserved2: \"\n  valid_simple_dpda G\n  \\<Longrightarrow> epdaH.derivation_initial G d\n  \\<Longrightarrow> d (Suc n) = Some (pair e2 c2)\n  \\<Longrightarrow> maximum_of_domain d nX\n  \\<Longrightarrow> d n = Some (pair e1 c1)\n  \\<Longrightarrow> epdaH_conf_stack c1 \\<noteq> wb\n  \\<Longrightarrow> epdaH_conf_stack c2 \\<noteq> wb\n  \\<Longrightarrow> None = min_stack d wb n nX\n  \\<Longrightarrow> min_stack d wb n nX = min_stack d wb (Suc n) nX\"\n  apply(simp add: min_stack_def)\n  apply(clarsimp)\n  apply(rename_tac x e c)(*strict*)\n  apply(case_tac \"\\<forall>x \\<le> nX. n \\<le> x \\<longrightarrow> (\\<forall>e ca. d x = Some (pair e ca) \\<longrightarrow> epdaH_conf_stack ca \\<noteq> epdaH_conf_stack c)\")\n   apply(rename_tac x e c)(*strict*)\n   prefer 2\n   apply(clarsimp)\n  apply(rename_tac x e c)(*strict*)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"x\"\n      in allE)\n  apply(force)\n  done\n\nlemma min_stack_preserved: \"\n  valid_simple_dpda G\n  \\<Longrightarrow> epdaH.derivation_initial G d\n  \\<Longrightarrow> d (Suc n) = Some (pair e2 c2)\n  \\<Longrightarrow> maximum_of_domain d nX\n  \\<Longrightarrow> d n = Some (pair e1 c1)\n  \\<Longrightarrow> epdaH_conf_stack c1 \\<noteq> wb\n  \\<Longrightarrow> epdaH_conf_stack c2 \\<noteq> wb\n  \\<Longrightarrow> min_stack d wb n nX = min_stack d wb (Suc n) nX\"\n  apply(case_tac \"min_stack d wb n nX\")\n   apply(rule min_stack_preserved2)\n          apply(force)+\n  apply(rename_tac a)(*strict*)\n  apply(rule min_stack_preserved1)\n         apply(rename_tac a)(*strict*)\n         apply(force)+\n  done\n\nlemma valid_pda_edge_pop_single: \"\n  valid_pda G\n  \\<Longrightarrow> e \\<in> epda_delta G\n  \\<Longrightarrow> \\<exists>x. edge_pop e = [x]\"\n  apply(simp add: valid_pda_def)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"e\"\n      in ballE)\n   prefer 2\n   apply(force)\n  apply(case_tac \"edge_pop e\")\n   apply(force)\n  apply(rename_tac a list)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma epdaS_unused_stack_modification_preserves_derivation2: \"\n  valid_pda G\n  \\<Longrightarrow> epdaS.derivation G d\n  \\<Longrightarrow> epdaS.belongs G d\n  \\<Longrightarrow> \\<forall>k \\<le> j. \\<forall>e c. d k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ aa # s)\n  \\<Longrightarrow> epdaS.derivation G (derivation_map (derivation_take d j) (\\<lambda>c. c\\<lparr>epdaS_conf_stack := butn (epdaS_conf_stack c) (length s) @ s'\\<rparr>))\"\n  apply(simp (no_asm) add: epdaS.derivation_def)\n  apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(case_tac i)\n   apply(rename_tac i)(*strict*)\n   apply(clarsimp)\n   apply(simp add: derivation_map_def derivation_take_def)\n   apply(subgoal_tac \"\\<exists>c. d 0 = Some (pair None c)\")\n    apply(clarsimp)\n   apply (rule epdaS.some_position_has_details_at_0)\n   apply(force)\n  apply(rename_tac i nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat)(*strict*)\n  apply(case_tac \"d (Suc nat)\")\n   apply(rename_tac nat)(*strict*)\n   apply(simp add: derivation_map_def derivation_take_def)\n  apply(rename_tac nat a)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d nat = Some (pair e1 c1) \\<and> d (Suc nat) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation G c1 e2 c2\")\n   apply(rename_tac nat a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc nat\"\n      in epdaS.step_detail_before_some_position)\n     apply(rename_tac nat a)(*strict*)\n     apply(force)\n    apply(rename_tac nat a)(*strict*)\n    apply(force)\n   apply(rename_tac nat a)(*strict*)\n   apply(force)\n  apply(rename_tac nat a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat e1 e2 c1 c2)(*strict*)\n  apply(simp add: derivation_map_def derivation_take_def)\n  apply(clarsimp)\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac nat e1 e2 c1 c2 w)(*strict*)\n  apply(subgoal_tac \"\\<forall>e c. d nat = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ aa # s)\")\n   apply(rename_tac nat e1 e2 c1 c2 w)(*strict*)\n   apply(subgoal_tac \"\\<forall>e c. d (Suc nat) = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ aa # s)\")\n    apply(rename_tac nat e1 e2 c1 c2 w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac nat e1 e2 c1 c2 w wa)(*strict*)\n    apply(simp add: butn_def)\n    apply(subgoal_tac \"\\<exists>x. edge_pop e2 = [x]\")\n     apply(rename_tac nat e1 e2 c1 c2 w wa)(*strict*)\n     prefer 2\n     apply(rule valid_pda_edge_pop_single)\n      apply(rename_tac nat e1 e2 c1 c2 w wa)(*strict*)\n      apply(simp add: valid_simple_dpda_def valid_dpda_def)\n     apply(rename_tac nat e1 e2 c1 c2 w wa)(*strict*)\n     apply(force)\n    apply(rename_tac nat e1 e2 c1 c2 w wa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac nat e1 e2 c1 c2 w wa x)(*strict*)\n    apply(case_tac wa)\n     apply(rename_tac nat e1 e2 c1 c2 w wa x)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac nat e1 e2 c1 c2 w wa x a list)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac nat e1 e2 c1 c2 w)(*strict*)\n   apply(erule_tac\n      x=\"Suc nat\"\n      in allE)\n   apply(force)\n  apply(rename_tac nat e1 e2 c1 c2 w)(*strict*)\n  apply(erule_tac\n      x=\"nat\"\n      in allE)\n  apply(force)\n  done\n\nlemma F_SDPDA_TO_CFG_STD__minimal_stack_does_not_occur: \"\n  valid_simple_dpda G\n  \\<Longrightarrow> epdaS.derivation G d\n  \\<Longrightarrow> d (Suc k) \\<noteq> None\n  \\<Longrightarrow> i < Suc k\n  \\<Longrightarrow> \\<forall>i < Suc k. epdaS_conf_stack (the (get_configuration (d (Suc i)))) \\<noteq> A # s\n  \\<Longrightarrow> epdaS_conf_stack (the (get_configuration (d (Suc 0)))) = w @ B # A # s\n  \\<Longrightarrow> \\<exists>w. epdaS_conf_stack (the (get_configuration (d (Suc i)))) = w @ B # A # s\"\n  apply(induct i)\n   apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i wa y)(*strict*)\n  apply(erule_tac\n      x=\"Suc i\"\n      in allE)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d (Suc i) = Some (pair e1 c1) \\<and> d (Suc (Suc i)) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation G c1 e2 c2\")\n   apply(rename_tac i wa y)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc k\"\n      in epdaS.step_detail_before_some_position)\n     apply(rename_tac i wa y)(*strict*)\n     apply(force)\n    apply(rename_tac i wa y)(*strict*)\n    apply(force)\n   apply(rename_tac i wa y)(*strict*)\n   apply(force)\n  apply(rename_tac i wa y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i wa y e1 e2 c1 c2)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac i wa y e1 e2 c1 c2 waa)(*strict*)\n  apply(simp add: valid_simple_dpda_def)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"e2\"\n      in ballE)\n   apply(rename_tac i wa y e1 e2 c1 c2 waa)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac i wa y e1 e2 c1 c2 waa)(*strict*)\n  apply(subgoal_tac \"\\<exists>x. edge_pop e2=[x]\")\n   apply(rename_tac i wa y e1 e2 c1 c2 waa)(*strict*)\n   apply(case_tac \"edge_event e2\")\n    apply(rename_tac i wa y e1 e2 c1 c2 waa)(*strict*)\n    prefer 2\n    apply(rename_tac i wa y e1 e2 c1 c2 waa a)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i wa y e1 e2 c1 c2 waa a x)(*strict*)\n    apply(rule_tac\n      x=\"wa\"\n      in exI)\n    apply(force)\n   apply(rename_tac i wa y e1 e2 c1 c2 waa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i wa y e1 e2 c1 c2 waa x)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac i wa y e1 e2 c1 c2 waa x)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i wa y e1 e2 c1 c2 x)(*strict*)\n    apply(case_tac wa)\n     apply(rename_tac i wa y e1 e2 c1 c2 x)(*strict*)\n     apply(force)\n    apply(rename_tac i wa y e1 e2 c1 c2 x a list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i y e1 e2 c1 c2 x list)(*strict*)\n    apply(rule_tac\n      x=\"list\"\n      in exI)\n    apply(force)\n   apply(rename_tac i wa y e1 e2 c1 c2 waa x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i wa y e1 e2 c1 c2 waa x xa)(*strict*)\n   apply(rule_tac\n      x=\"xa # wa\"\n      in exI)\n   apply(force)\n  apply(rename_tac i wa y e1 e2 c1 c2 waa)(*strict*)\n  apply(rule_tac\n      G=\"G\"\n      in valid_pda_edge_pop_single)\n   apply(rename_tac i wa y e1 e2 c1 c2 waa)(*strict*)\n   apply(simp add: valid_dpda_def)\n  apply(rename_tac i wa y e1 e2 c1 c2 waa)(*strict*)\n  apply(force)\n  done\n\nlemma epdaS_unused_stack_modification_preserves_derivation: \"\n  valid_pda G\n  \\<Longrightarrow> epdaS.derivation G d1\n  \\<Longrightarrow> epdaS.belongs G d1\n  \\<Longrightarrow> maximum_of_domain d1 (Suc j)\n  \\<Longrightarrow> d1 0 = Some (pair None \\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = x1, epdaS_conf_stack = B # s\\<rparr>)\n  \\<Longrightarrow> \\<forall>k \\<le> j. \\<forall>e c. d1 k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ B # s)\n  \\<Longrightarrow> d1 (Suc j) = Some (pair e' \\<lparr>epdaS_conf_state = qs, epdaS_conf_scheduler = [], epdaS_conf_stack = s\\<rparr>)\n  \\<Longrightarrow> epdaS.derivation G (derivation_map d1 (\\<lambda>c. c\\<lparr>epdaS_conf_stack := butn (epdaS_conf_stack c) (length s) @ A # sa\\<rparr>))\"\n  apply(simp (no_asm) add: epdaS.derivation_def)\n  apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(case_tac i)\n   apply(rename_tac i)(*strict*)\n   apply(clarsimp)\n   apply(simp add: derivation_map_def)\n  apply(rename_tac i nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat)(*strict*)\n  apply(case_tac \"d1 (Suc nat)\")\n   apply(rename_tac nat)(*strict*)\n   apply(simp add: derivation_map_def)\n  apply(rename_tac nat a)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d1 nat = Some (pair e1 c1) \\<and> d1 (Suc nat) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation G c1 e2 c2\")\n   apply(rename_tac nat a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc nat\"\n      in epdaS.step_detail_before_some_position)\n     apply(rename_tac nat a)(*strict*)\n     apply(force)\n    apply(rename_tac nat a)(*strict*)\n    apply(force)\n   apply(rename_tac nat a)(*strict*)\n   apply(force)\n  apply(rename_tac nat a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat e1 e2 c1 c2)(*strict*)\n  apply(simp add: derivation_map_def)\n  apply(subgoal_tac \"Suc nat \\<le> Suc j\")\n   apply(rename_tac nat e1 e2 c1 c2)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"(\\<forall>e c. d1 nat = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ B # s))\")\n    apply(rename_tac nat e1 e2 c1 c2)(*strict*)\n    apply(erule_tac\n      x=\"e1\"\n      in allE)\n    apply(erule_tac\n      x=\"c1\"\n      in allE)\n    apply(erule impE)\n     apply(rename_tac nat e1 e2 c1 c2)(*strict*)\n     apply(force)\n    apply(rename_tac nat e1 e2 c1 c2)(*strict*)\n    apply(erule exE)+\n    apply(rename_tac nat e1 e2 c1 c2 w)(*strict*)\n    apply(rule_tac\n      t=\"butn (epdaS_conf_stack c1) (length s)\"\n      and s=\"w @ [B]\"\n      in ssubst)\n     apply(rename_tac nat e1 e2 c1 c2 w)(*strict*)\n     apply(simp add: butn_def)\n    apply(rename_tac nat e1 e2 c1 c2 w)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"\\<exists>w. epdaS_conf_stack c2 = w @ s\")\n     apply(rename_tac nat e1 e2 c1 c2 w)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac nat e1 e2 c1 c2 w wa)(*strict*)\n     apply(simp add: butn_def)\n     apply(simp add: epdaS_step_relation_def)\n     apply(clarsimp)\n     apply(rename_tac nat e1 e2 c1 c2 w wa wb)(*strict*)\n     apply(subgoal_tac \"\\<exists>x. edge_pop e2=[x]\")\n      apply(rename_tac nat e1 e2 c1 c2 w wa wb)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac nat e1 e2 c1 c2 w wa wb x)(*strict*)\n      apply(case_tac w)\n       apply(rename_tac nat e1 e2 c1 c2 w wa wb x)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac nat e1 e2 c1 c2 w wa wb x a list)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac nat e1 e2 c1 c2 w wa wb)(*strict*)\n     apply(rule_tac\n      G=\"G\"\n      in valid_pda_edge_pop_single)\n      apply(rename_tac nat e1 e2 c1 c2 w wa wb)(*strict*)\n      apply(simp add: valid_dpda_def)\n     apply(rename_tac nat e1 e2 c1 c2 w wa wb)(*strict*)\n     apply(force)\n    apply(rename_tac nat e1 e2 c1 c2 w)(*strict*)\n    apply(case_tac \"nat=j\")\n     apply(rename_tac nat e1 e2 c1 c2 w)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac nat e1 e2 c1 c2 w)(*strict*)\n    apply(erule_tac\n      x=\"Suc nat\"\n      in allE)\n    apply(clarsimp)\n   apply(rename_tac nat e1 e2 c1 c2)(*strict*)\n   apply(erule_tac\n      x=\"nat\"\n      in allE)\n   apply(clarsimp)\n  apply(rename_tac nat e1 e2 c1 c2)(*strict*)\n  apply (metis epdaS.allPreMaxDomSome_prime not_None_eq)\n  done\n\nlemma epdaS_produce_from_before_pop_append: \"\n  valid_pda G\n  \\<Longrightarrow> \\<lparr>edge_src = src, edge_event = None, edge_pop = [A], edge_push = [B, A], edge_trg = trg\\<rparr> \\<in> epda_delta G\n  \\<Longrightarrow> x1 \\<in> epdaS_produce_from_before_pop G trg B qs\n  \\<Longrightarrow> x2 \\<in> epdaS_produce_from_before_pop G qs A qt\n  \\<Longrightarrow> x1 @ x2 \\<in> epdaS_produce_from_before_pop G src A qt\"\n  apply(simp add: epdaS_produce_from_before_pop_def)\n  apply(clarsimp)\n  apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n  apply(subgoal_tac \"\\<exists>d1. epdaS.derivation G d1 \\<and> epdaS.belongs G d1 \\<and> maximum_of_domain d1 (Suc j) \\<and> d1 0 = Some (pair None \\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = x1, epdaS_conf_stack = B # s\\<rparr>) \\<and> d1 j = Some (pair e \\<lparr>epdaS_conf_state = q, epdaS_conf_scheduler = [], epdaS_conf_stack = B # s\\<rparr>) \\<and> (\\<forall>k \\<le> j. \\<forall>e c. d1 k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ B # s)) \\<and> d1 (Suc j) = Some (pair e' \\<lparr>epdaS_conf_state = qs, epdaS_conf_scheduler = [], epdaS_conf_stack = s\\<rparr>) \")\n   apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n   prefer 2\n   apply(rule_tac\n      x=\"derivation_take d (Suc j)\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n    apply(rule epdaS.derivation_take_preserves_derivation)\n    apply(force)\n   apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n    apply(rule epdaS.derivation_take_preserves_belongs)\n    apply(force)\n   apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n    apply(rule maximum_of_domain_derivation_take)\n    apply(force)\n   apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n    apply(simp add: derivation_take_def)\n   apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n    apply(simp add: derivation_take_def)\n   apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d da q s qa sa j ja e ea e' e'event k eb c)(*strict*)\n    apply(erule_tac\n      x=\"k\"\n      and P=\"\\<lambda>x. x \\<le> j \\<longrightarrow> (\\<forall>e c. d x = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ B # s))\"\n      in allE)\n    apply(rename_tac d da q s qa sa j ja e ea e' e'event k eb c)(*strict*)\n    apply(clarsimp)\n    apply(simp add: derivation_take_def)\n   apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n  apply(subgoal_tac \"\\<exists>d2. epdaS.derivation G d2 \\<and> epdaS.belongs G d2 \\<and> maximum_of_domain d2 (Suc ja) \\<and> d2 0 = Some (pair None \\<lparr>epdaS_conf_state = qs, epdaS_conf_scheduler = x2, epdaS_conf_stack = A # sa\\<rparr>) \\<and> d2 ja = Some (pair ea \\<lparr>epdaS_conf_state = qa, epdaS_conf_scheduler = [], epdaS_conf_stack = A # sa\\<rparr>) \\<and> (\\<forall>k \\<le> ja. \\<forall>e c. d2 k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ A # sa)) \\<and> d2 (Suc ja) = Some (pair e'event \\<lparr>epdaS_conf_state = qt, epdaS_conf_scheduler = [], epdaS_conf_stack = sa\\<rparr>) \")\n   apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n   prefer 2\n   apply(rule_tac\n      x=\"derivation_take da (Suc ja)\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n    apply(rule epdaS.derivation_take_preserves_derivation)\n    apply(force)\n   apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n    apply(rule epdaS.derivation_take_preserves_belongs)\n    apply(force)\n   apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n    apply(rule maximum_of_domain_derivation_take)\n    apply(force)\n   apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n    apply(simp add: derivation_take_def)\n   apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n    apply(simp add: derivation_take_def)\n   apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d da q s qa sa j ja e ea e' e'event d1 k eb c)(*strict*)\n    apply(simp add: derivation_take_def)\n   apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac d da q s qa sa j ja e ea e' e'event)(*strict*)\n  apply(thin_tac \"epdaS.derivation G d\")\n  apply(thin_tac \"epdaS.derivation G da\")\n  apply(thin_tac \"epdaS.belongs G d\")\n  apply(thin_tac \"epdaS.belongs G da\")\n  apply(thin_tac \"d 0 = Some (pair None \\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = x1, epdaS_conf_stack = B # s\\<rparr>)\")\n  apply(thin_tac \"da 0 = Some (pair None \\<lparr>epdaS_conf_state = qs, epdaS_conf_scheduler = x2, epdaS_conf_stack = A # sa\\<rparr>)\")\n  apply(thin_tac \"d j = Some (pair e \\<lparr>epdaS_conf_state = q, epdaS_conf_scheduler = [], epdaS_conf_stack = B # s\\<rparr>)\")\n  apply(thin_tac \"da ja = Some (pair ea \\<lparr>epdaS_conf_state = qa, epdaS_conf_scheduler = [], epdaS_conf_stack = A # sa\\<rparr>)\")\n  apply(thin_tac \"\\<forall>k \\<le> j. \\<forall>e c. d k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ B # s)\")\n  apply(thin_tac \"d (Suc j) = Some (pair e' \\<lparr>epdaS_conf_state = qs, epdaS_conf_scheduler = [], epdaS_conf_stack = s\\<rparr>)\")\n  apply(thin_tac \"\\<forall>k \\<le> ja. \\<forall>e c. da k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ A # sa)\")\n  apply(thin_tac \"da (Suc ja) = Some (pair e'event \\<lparr>epdaS_conf_state = qt, epdaS_conf_scheduler = [], epdaS_conf_stack = sa\\<rparr>)\")\n  apply(clarsimp)\n  apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n  apply(subgoal_tac \"\\<exists>d1. epdaS.derivation G d1 \\<and> epdaS.belongs G d1 \\<and> maximum_of_domain d1 (Suc j) \\<and> d1 0 = Some (pair None \\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = x1, epdaS_conf_stack = B # A # sa\\<rparr>) \\<and> d1 j = Some (pair e \\<lparr>epdaS_conf_state = q, epdaS_conf_scheduler = [], epdaS_conf_stack = B # A # sa\\<rparr>) \\<and> (\\<forall>k \\<le> j. \\<forall>e c. d1 k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ B # A # sa)) \\<and> d1 (Suc j) = Some (pair e' \\<lparr>epdaS_conf_state = qs, epdaS_conf_scheduler = [], epdaS_conf_stack = A # sa\\<rparr>) \")\n   apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      x=\"derivation_map d1 (\\<lambda>c. c\\<lparr>epdaS_conf_stack := butn (epdaS_conf_stack c) (length s) @ (A # sa)\\<rparr>)\"\n      in exI)\n   apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n   apply(rule context_conjI)\n    apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n    apply(rule epdaS_unused_stack_modification_preserves_derivation)\n          apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n          apply(force)\n         apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n         apply(force)\n        apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n        apply(force)\n       apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n       apply(force)\n      apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n      apply(force)\n     apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n     apply(force)\n    apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n    apply(force)\n   apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n    apply(rule epdaS.derivation_belongs)\n       apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n       apply(simp add: valid_pda_def)\n      apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n      apply(simp add: derivation_map_def)\n     apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n     apply(simp add: butn_def)\n     apply(subgoal_tac \"\\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = x1, epdaS_conf_stack = B # s\\<rparr> \\<in> epdaS_configurations G\")\n      apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n      apply(subgoal_tac \"\\<lparr>epdaS_conf_state = qs, epdaS_conf_scheduler = x2, epdaS_conf_stack = A # sa\\<rparr> \\<in> epdaS_configurations G\")\n       apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n       apply(simp add: epdaS_configurations_def)\n      apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n      apply(rule_tac\n      d=\"d2\"\n      in epdaS.belongs_configurations)\n       apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n       apply(force)\n      apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n      apply(force)\n     apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n     apply(rule_tac\n      d=\"d1\"\n      in epdaS.belongs_configurations)\n      apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n      apply(force)\n     apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n     apply(force)\n    apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n    apply(force)\n   apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n    apply(rule derivation_map_preserves_maximum_of_domain)\n    apply(force)\n   apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n    apply(simp add: derivation_map_def butn_def)\n   apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n    apply(simp add: derivation_map_def butn_def)\n   apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2 k eb c)(*strict*)\n    apply(erule_tac\n      x=\"k\"\n      and P=\"\\<lambda>x. x \\<le> j \\<longrightarrow> (\\<forall>e c. d1 x = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ B # s))\"\n      in allE)\n    apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2 k eb c)(*strict*)\n    apply(clarsimp)\n    apply(simp add: derivation_map_def butn_def)\n    apply(case_tac \"d1 k\")\n     apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2 k eb c)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2 k eb c a)(*strict*)\n    apply(clarsimp)\n    apply(case_tac a)\n    apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2 k eb c a option b)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n   apply(simp add: derivation_map_def butn_def)\n  apply(rename_tac q s qa sa j ja e ea e' e'event d1 d2)(*strict*)\n  apply(thin_tac \"epdaS.derivation G d1\")\n  apply(thin_tac \"epdaS.belongs G d1\")\n  apply(thin_tac \"maximum_of_domain d1 (Suc j)\")\n  apply(thin_tac \"d1 0 = Some (pair None \\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = x1, epdaS_conf_stack = B # s\\<rparr>)\")\n  apply(thin_tac \"d1 j = Some (pair e \\<lparr>epdaS_conf_state = q, epdaS_conf_scheduler = [], epdaS_conf_stack = B # s\\<rparr>)\")\n  apply(thin_tac \"\\<forall>k \\<le> j. \\<forall>e c. d1 k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ B # s)\")\n  apply(thin_tac \"d1 (Suc j) = Some (pair e' \\<lparr>epdaS_conf_state = qs, epdaS_conf_scheduler = [], epdaS_conf_stack = s\\<rparr>)\")\n  apply(clarsimp)\n  apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n  apply(rule_tac\n      x=\"derivation_append (der2 \\<lparr>epdaS_conf_state = src, epdaS_conf_scheduler = x1 @ x2, epdaS_conf_stack = A # sa\\<rparr> \\<lparr>edge_src = src, edge_event = None, edge_pop = [A], edge_push = [B, A], edge_trg = trg\\<rparr> \\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = x1 @ x2, epdaS_conf_stack = B # A # sa\\<rparr>) (derivation_append (derivation_map d1 (\\<lambda>c. c\\<lparr>epdaS_conf_scheduler := take (length (epdaS_conf_scheduler c) - length (epdaS_conf_scheduler \\<lparr>epdaS_conf_state = qs, epdaS_conf_scheduler = [], epdaS_conf_stack = A # sa\\<rparr>)) (epdaS_conf_scheduler c) @ x2\\<rparr>)) d2 (Suc j)) (Suc 0)\"\n      in exI)\n  apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n  apply(rule context_conjI)\n   apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n   apply(rule epdaS.derivation_append_preserves_derivation)\n     apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n     apply(rule epdaS.der2_is_derivation)\n     apply(simp add: epdaS_step_relation_def)\n     apply(simp add: option_to_list_def)\n    apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n    apply(rule epdaS.derivation_append_preserves_derivation)\n      apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n      apply(rule epda_maximal_context_preserves_derivation_prime)\n            apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n            apply(simp add: valid_pda_def)\n           apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n           apply(force)\n          apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n          apply(force)\n         apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n         apply(force)\n        apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n        apply(force)\n       apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n       apply(force)\n      apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n      apply(force)\n     apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n     apply(force)\n    apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n    apply(simp add: derivation_map_def)\n   apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n   apply(simp add: der2_def derivation_append_def derivation_map_def)\n  apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n   apply(rule_tac\n      ca=\"\\<lparr>epdaS_conf_state = src, epdaS_conf_scheduler = x1 @ x2, epdaS_conf_stack = A # sa\\<rparr>\"\n      in epdaS.derivation_belongs)\n      apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n      apply(simp add: valid_pda_def)\n     apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n     apply(simp add: der2_def derivation_append_def derivation_map_def)\n    apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n    apply(subgoal_tac \"valid_epda_step_label G \\<lparr>edge_src = src, edge_event = None, edge_pop = [A], edge_push = [B, A], edge_trg = trg\\<rparr>\")\n     apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n     apply(subgoal_tac \"\\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = x1, epdaS_conf_stack = B # A # sa\\<rparr> \\<in> epdaS_configurations G\")\n      apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n      apply(subgoal_tac \"\\<lparr>epdaS_conf_state = qs, epdaS_conf_scheduler = x2, epdaS_conf_stack = A # sa\\<rparr> \\<in> epdaS_configurations G\")\n       apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n       apply(simp add: epdaS_configurations_def valid_epda_step_label_def)\n      apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n      apply(rule_tac\n      d=\"d2\"\n      in epdaS.belongs_configurations)\n       apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n       apply(force)\n      apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n      apply(force)\n     apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n     apply(rule_tac\n      d=\"d1\"\n      in epdaS.belongs_configurations)\n      apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n      apply(force)\n     apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n     apply(force)\n    apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n    apply(simp add: valid_pda_def valid_epda_def)\n   apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n   apply(simp add: der2_def derivation_append_def derivation_map_def)\n  apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n  apply(rule_tac\n      x=\"qa\"\n      in exI)\n  apply(rule_tac\n      x=\"sa\"\n      in exI)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n   apply(simp add: der2_def derivation_append_def derivation_map_def)\n  apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n  apply(rule_tac\n      x=\"Suc j+ja+Suc 0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n   apply(rule_tac\n      x=\"if ja=0 then e' else ea\"\n      in exI)\n   apply(simp add: der2_def derivation_append_def derivation_map_def)\n   apply(clarsimp)\n  apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n   apply(simp add: der2_def derivation_append_def derivation_map_def)\n  apply(rename_tac q qa sa j ja e ea e' e'event d2 d1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 k eb c)(*strict*)\n  apply(case_tac k)\n   apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 k eb c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 eb c)(*strict*)\n   apply(simp add: der2_def derivation_append_def derivation_map_def)\n   apply(clarsimp)\n  apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 k eb c nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 eb c nat)(*strict*)\n  apply(case_tac \"nat \\<le> j\")\n   apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 eb c nat)(*strict*)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"nat\"\n      and P=\"\\<lambda>nat. nat \\<le> j \\<longrightarrow> (\\<forall>e c. d1 nat = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ B # A # sa))\"\n      in allE)\n   apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 eb c nat)(*strict*)\n   apply(clarsimp)\n   apply(simp add: der2_def derivation_append_def derivation_map_def)\n   apply(case_tac nat)\n    apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 eb c nat)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 eb c nat nata)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 eb c nata)(*strict*)\n   apply(case_tac \"d1 (Suc nata)\")\n    apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 eb c nata)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 eb c nata a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 eb c nata a option b)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 eb c nat)(*strict*)\n  apply(case_tac \"Suc nat=j\")\n   apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 eb c nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 eb c nat)(*strict*)\n  apply(clarsimp)\n  apply(simp add: der2_def derivation_append_def derivation_map_def)\n  apply(case_tac \"nat \\<le> Suc j\")\n   apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 eb c nat)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"nat=Suc j\")\n    apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 eb c nat)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 eb c nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 eb c nat)(*strict*)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"nat - Suc j\"\n      and P=\"\\<lambda>x. x \\<le> ja \\<longrightarrow> (\\<forall>e c. d2 x = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ A # sa))\"\n      in allE)\n  apply(rename_tac q qa sa j ja e ea e' e'event d2 d1 eb c nat)(*strict*)\n  apply(clarsimp)\n  done\n\ndefinition epdaS_produce_and_eliminate_from :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> 'state\n  \\<Rightarrow> 'stack\n  \\<Rightarrow> 'event list set\"\n  where\n    \"epdaS_produce_and_eliminate_from G qi A \\<equiv>\n  {w. \\<exists>d qf s.\n  qf \\<in> epda_marking G\n  \\<and> epdaS.derivation G d\n  \\<and> epdaS.belongs G d\n  \\<and> d 0 = Some (pair None\n      \\<lparr>epdaS_conf_state = qi,\n      epdaS_conf_scheduler = w,\n      epdaS_conf_stack = A # s\\<rparr>)\n  \\<and> (\\<exists>j e s'.\n    d j = Some (pair e\n          \\<lparr>epdaS_conf_state = qf,\n          epdaS_conf_scheduler = [],\n          epdaS_conf_stack = s' @ A # s\\<rparr>)\n    \\<and> (\\<forall>k \\<le> j. \\<forall>e c.\n        d k = Some (pair e c)\n        \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ [A] @ s)))}\"\n\nlemma epdaS_produce_and_eliminate_from_Cons: \"\n  valid_epda G\n  \\<Longrightarrow> \\<lparr>edge_src = src, edge_event = Some a, edge_pop = [y], edge_push = [y], edge_trg = trg\\<rparr> \\<in> epda_delta G\n  \\<Longrightarrow> w \\<in> epdaS_produce_and_eliminate_from G trg y\n  \\<Longrightarrow> a # w \\<in> epdaS_produce_and_eliminate_from G src y\"\n  apply(simp add: epdaS_produce_and_eliminate_from_def)\n  apply(clarsimp)\n  apply(rename_tac d qf s j e s')(*strict*)\n  apply(rule_tac\n      x=\"derivation_append (der2 \\<lparr>epdaS_conf_state = src, epdaS_conf_scheduler = a # w, epdaS_conf_stack = y # s\\<rparr> \\<lparr>edge_src = src, edge_event = Some a, edge_pop = [y], edge_push = [y], edge_trg = trg\\<rparr> \\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = w, epdaS_conf_stack = y # s\\<rparr>) d (Suc 0)\"\n      in exI)\n  apply(rename_tac d qf s j e s')(*strict*)\n  apply(rule_tac\n      x=\"qf\"\n      in exI)\n  apply(clarsimp)\n  apply(rule context_conjI)\n   apply(rename_tac d qf s j e s')(*strict*)\n   apply(rule epdaS.derivation_append_preserves_derivation)\n     apply(rename_tac d qf s j e s')(*strict*)\n     apply(rule epdaS.der2_is_derivation)\n     apply(simp add: epdaS_step_relation_def option_to_list_def)\n    apply(rename_tac d qf s j e s')(*strict*)\n    apply(force)\n   apply(rename_tac d qf s j e s')(*strict*)\n   apply(simp add: der2_def)\n  apply(rename_tac d qf s j e s')(*strict*)\n  apply(rule conjI)\n   apply(rename_tac d qf s j e s')(*strict*)\n   apply(rule epdaS.derivation_belongs)\n      apply(rename_tac d qf s j e s')(*strict*)\n      apply(force)\n     apply(rename_tac d qf s j e s')(*strict*)\n     apply(simp add: derivation_append_def der2_def)\n    apply(rename_tac d qf s j e s')(*strict*)\n    apply(subgoal_tac \"\\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = w, epdaS_conf_stack = y # s\\<rparr> \\<in> epdaS_configurations G\")\n     apply(rename_tac d qf s j e s')(*strict*)\n     apply(subgoal_tac \"valid_epda_step_label G \\<lparr>edge_src = src, edge_event = Some a, edge_pop = [y], edge_push = [y], edge_trg = trg\\<rparr>\")\n      apply(rename_tac d qf s j e s')(*strict*)\n      apply(simp add: epdaS_configurations_def valid_epda_step_label_def option_to_set_def)\n     apply(rename_tac d qf s j e s')(*strict*)\n     apply(simp add: valid_epda_def)\n    apply(rename_tac d qf s j e s')(*strict*)\n    apply(rule epdaS.belongs_configurations)\n     apply(rename_tac d qf s j e s')(*strict*)\n     apply(force)\n    apply(rename_tac d qf s j e s')(*strict*)\n    apply(force)\n   apply(rename_tac d qf s j e s')(*strict*)\n   apply(force)\n  apply(rename_tac d qf s j e s')(*strict*)\n  apply(rule_tac\n      x=\"s\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac d qf s j e s')(*strict*)\n   apply(simp add: derivation_append_def der2_def)\n  apply(rename_tac d qf s j e s')(*strict*)\n  apply(rule_tac\n      x=\"Suc j\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac d qf s j e s')(*strict*)\n   apply(simp add: derivation_append_def der2_def)\n   apply(clarsimp)\n  apply(rename_tac d qf s j e s')(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d qf s j e s' k ea c)(*strict*)\n  apply(case_tac k)\n   apply(rename_tac d qf s j e s' k ea c)(*strict*)\n   apply(simp add: derivation_append_def der2_def)\n   apply(clarsimp)\n  apply(rename_tac d qf s j e s' k ea c nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d qf s j e s' ea c nat)(*strict*)\n  apply(erule_tac\n      x=\"nat\"\n      in allE)\n  apply(clarsimp)\n  apply(simp add: derivation_append_def der2_def)\n  apply(case_tac nat)\n   apply(rename_tac d qf s j e s' ea c nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d qf s j e s' ea c nat nata)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma epdaS_produce_and_eliminate_from_Cons2: \"\n  valid_pda G\n  \\<Longrightarrow> \\<lparr>edge_src = src, edge_event = None, edge_pop = [y], edge_push = [aa, y], edge_trg = trg\\<rparr> \\<in> epda_delta G\n  \\<Longrightarrow> w \\<in> epdaS_produce_and_eliminate_from G trg aa\n  \\<Longrightarrow> w \\<in> epdaS_produce_and_eliminate_from G src y\"\n  apply(simp add: epdaS_produce_and_eliminate_from_def)\n  apply(clarsimp)\n  apply(rename_tac d qf s j e s')(*strict*)\n  apply(subgoal_tac \"\\<exists>d. epdaS.derivation G d \\<and> epdaS.belongs G d \\<and> maximum_of_domain d j \\<and> d 0 = Some (pair None \\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = w, epdaS_conf_stack = aa # y # s\\<rparr>) \\<and> (\\<forall>k \\<le> j. \\<forall>e c. d k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ aa # y # s)) \\<and> d j = Some (pair e \\<lparr>epdaS_conf_state = qf, epdaS_conf_scheduler = [], epdaS_conf_stack = s' @ aa # y # s\\<rparr>) \")\n   apply(rename_tac d qf s j e s')(*strict*)\n   prefer 2\n   apply(rule_tac\n      x=\"derivation_map (derivation_take d j) (\\<lambda>c. c\\<lparr>epdaS_conf_stack := butn (epdaS_conf_stack c) (length s) @ y # s\\<rparr>)\"\n      in exI)\n   apply(rule context_conjI)\n    apply(rename_tac d qf s j e s')(*strict*)\n    apply(rule epdaS_unused_stack_modification_preserves_derivation2)\n       apply(rename_tac d qf s j e s')(*strict*)\n       apply(force)\n      apply(rename_tac d qf s j e s')(*strict*)\n      apply(force)\n     apply(rename_tac d qf s j e s')(*strict*)\n     apply(force)\n    apply(rename_tac d qf s j e s')(*strict*)\n    apply(force)\n   apply(rename_tac d qf s j e s')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d qf s j e s')(*strict*)\n    apply(rule epdaS.derivation_belongs)\n       apply(rename_tac d qf s j e s')(*strict*)\n       apply(simp add: valid_pda_def)\n      apply(rename_tac d qf s j e s')(*strict*)\n      apply(simp add: derivation_map_def derivation_take_def)\n     apply(rename_tac d qf s j e s')(*strict*)\n     apply(simp add: butn_def)\n     apply(subgoal_tac \"\\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = w, epdaS_conf_stack = aa # s\\<rparr> \\<in> epdaS_configurations G\")\n      apply(rename_tac d qf s j e s')(*strict*)\n      apply(subgoal_tac \"valid_epda_step_label G \\<lparr>edge_src = src, edge_event = None, edge_pop = [y], edge_push = [aa, y], edge_trg = trg\\<rparr>\")\n       apply(rename_tac d qf s j e s')(*strict*)\n       apply(simp add: valid_epda_step_label_def epdaS_configurations_def)\n       apply(rule_tac\n      w=\"[y]\"\n      in may_terminated_by_decompose2)\n         apply(rename_tac d qf s j e s')(*strict*)\n         apply(force)\n        apply(rename_tac d qf s j e s')(*strict*)\n        apply(force)\n       apply(rename_tac d qf s j e s')(*strict*)\n       apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def valid_epda_def)\n      apply(rename_tac d qf s j e s')(*strict*)\n      apply(simp add: valid_pda_def valid_epda_def)\n     apply(rename_tac d qf s j e s')(*strict*)\n     apply(rule epdaS.belongs_configurations)\n      apply(rename_tac d qf s j e s')(*strict*)\n      apply(force)\n     apply(rename_tac d qf s j e s')(*strict*)\n     apply(force)\n    apply(rename_tac d qf s j e s')(*strict*)\n    apply(force)\n   apply(rename_tac d qf s j e s')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d qf s j e s')(*strict*)\n    apply(rule derivation_map_preserves_maximum_of_domain)\n    apply(rule maximum_of_domain_derivation_take)\n    apply(force)\n   apply(rename_tac d qf s j e s')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d qf s j e s')(*strict*)\n    apply(simp add: derivation_map_def derivation_take_def)\n    apply(simp add: butn_def)\n   apply(rename_tac d qf s j e s')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d qf s j e s')(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d qf s j e s' k ea c)(*strict*)\n    apply(simp add: derivation_map_def derivation_take_def)\n    apply(erule_tac\n      x=\"k\"\n      in allE)\n    apply(clarsimp)\n    apply(case_tac \"d k\")\n     apply(rename_tac d qf s j e s' k ea c)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d qf s j e s' k ea c a)(*strict*)\n    apply(clarsimp)\n    apply(case_tac a)\n    apply(rename_tac d qf s j e s' k ea c a option b)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d qf s j e s' k ea b wa)(*strict*)\n    apply(simp add: butn_def)\n   apply(rename_tac d qf s j e s')(*strict*)\n   apply(simp add: derivation_map_def derivation_take_def)\n   apply(simp add: butn_def)\n  apply(rename_tac d qf s j e s')(*strict*)\n  apply(thin_tac \"epdaS.derivation G d\")\n  apply(thin_tac \"epdaS.belongs G d\")\n  apply(thin_tac \"d 0 = Some (pair None \\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = w, epdaS_conf_stack = aa # s\\<rparr>)\")\n  apply(thin_tac \"\\<forall>k \\<le> j. \\<forall>e c. d k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ aa # s)\")\n  apply(thin_tac \"d j = Some (pair e \\<lparr>epdaS_conf_state = qf, epdaS_conf_scheduler = [], epdaS_conf_stack = s' @ aa # s\\<rparr>)\")\n  apply(clarsimp)\n  apply(rename_tac qf s j e s' d)(*strict*)\n  apply(rule_tac\n      x=\"derivation_append (der2 \\<lparr>epdaS_conf_state = src, epdaS_conf_scheduler = w, epdaS_conf_stack = y # s\\<rparr> \\<lparr>edge_src = src, edge_event = None, edge_pop = [y], edge_push = [aa, y], edge_trg = trg\\<rparr> \\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = w, epdaS_conf_stack = aa # y # s\\<rparr>) d (Suc 0)\"\n      in exI)\n  apply(rename_tac qf s j e s' d)(*strict*)\n  apply(rule_tac\n      x=\"qf\"\n      in exI)\n  apply(clarsimp)\n  apply(rule context_conjI)\n   apply(rename_tac qf s j e s' d)(*strict*)\n   apply(rule epdaS.derivation_append_preserves_derivation)\n     apply(rename_tac qf s j e s' d)(*strict*)\n     apply(rule epdaS.der2_is_derivation)\n     apply(simp add: epdaS_step_relation_def option_to_list_def)\n    apply(rename_tac qf s j e s' d)(*strict*)\n    apply(force)\n   apply(rename_tac qf s j e s' d)(*strict*)\n   apply(simp add: der2_def)\n  apply(rename_tac qf s j e s' d)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac qf s j e s' d)(*strict*)\n   apply(rule epdaS.derivation_belongs)\n      apply(rename_tac qf s j e s' d)(*strict*)\n      apply(simp add: valid_pda_def)\n     apply(rename_tac qf s j e s' d)(*strict*)\n     apply(simp add: derivation_append_def der2_def)\n    apply(rename_tac qf s j e s' d)(*strict*)\n    apply(subgoal_tac \"\\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = w, epdaS_conf_stack = aa # y # s\\<rparr> \\<in> epdaS_configurations G\")\n     apply(rename_tac qf s j e s' d)(*strict*)\n     apply(subgoal_tac \"valid_epda_step_label G \\<lparr>edge_src = src, edge_event = None, edge_pop = [y], edge_push = [aa, y], edge_trg = trg\\<rparr>\")\n      apply(rename_tac qf s j e s' d)(*strict*)\n      apply(simp add: valid_epda_step_label_def epdaS_configurations_def)\n     apply(rename_tac qf s j e s' d)(*strict*)\n     apply(simp add: valid_pda_def valid_epda_def)\n    apply(rename_tac qf s j e s' d)(*strict*)\n    apply(rule epdaS.belongs_configurations)\n     apply(rename_tac qf s j e s' d)(*strict*)\n     apply(force)\n    apply(rename_tac qf s j e s' d)(*strict*)\n    apply(force)\n   apply(rename_tac qf s j e s' d)(*strict*)\n   apply(force)\n  apply(rename_tac qf s j e s' d)(*strict*)\n  apply(rule_tac\n      x=\"s\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac qf s j e s' d)(*strict*)\n   apply(simp add: derivation_append_def der2_def)\n  apply(rename_tac qf s j e s' d)(*strict*)\n  apply(rule_tac\n      x=\"Suc j\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac qf s j e s' d)(*strict*)\n   apply(simp add: derivation_append_def der2_def)\n   apply(clarsimp)\n  apply(rename_tac qf s j e s' d)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac qf s j e s' d k ea c)(*strict*)\n  apply(case_tac k)\n   apply(rename_tac qf s j e s' d k ea c)(*strict*)\n   apply(simp add: derivation_append_def der2_def)\n   apply(clarsimp)\n  apply(rename_tac qf s j e s' d k ea c nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac qf s j e s' d ea c nat)(*strict*)\n  apply(erule_tac\n      x=\"nat\"\n      in allE)\n  apply(clarsimp)\n  apply(simp add: derivation_append_def der2_def)\n  apply(case_tac nat)\n   apply(rename_tac qf s j e s' d ea c nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac qf s j e s' d ea c nat nata)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma epdaS_produce_and_eliminate_from_epdaS_produce_from_before_pop_append: \"\n  valid_simple_dpda G\n  \\<Longrightarrow> \\<lparr>edge_src = src, edge_event = None, edge_pop = [A], edge_push = [B, A], edge_trg = trg\\<rparr> \\<in> epda_delta G\n  \\<Longrightarrow> r' \\<in> epdaS_produce_and_eliminate_from G qs A\n  \\<Longrightarrow> l' \\<in> epdaS_produce_from_before_pop G trg B qs\n  \\<Longrightarrow> l' @ r' \\<in> epdaS_produce_and_eliminate_from G src A\"\n  apply(simp add: epdaS_produce_and_eliminate_from_def epdaS_produce_from_before_pop_def)\n  apply(clarsimp)\n  apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n  apply(subgoal_tac \"\\<exists>d1. epdaS.derivation G d1 \\<and> epdaS.belongs G d1 \\<and> maximum_of_domain d1 (Suc j) \\<and> d1 0 = Some (pair None \\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = l', epdaS_conf_stack = B # s\\<rparr>) \\<and> d1 j = Some (pair e \\<lparr>epdaS_conf_state = q, epdaS_conf_scheduler = [], epdaS_conf_stack = B # s\\<rparr>) \\<and> (\\<forall>k \\<le> j. \\<forall>e c. d1 k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ B # s)) \\<and> d1 (Suc j) = Some (pair e' \\<lparr>epdaS_conf_state = qs, epdaS_conf_scheduler = [], epdaS_conf_stack = s\\<rparr>) \")\n   apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n   prefer 2\n   apply(rule_tac\n      x=\"derivation_take da (Suc j)\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n    apply(rule epdaS.derivation_take_preserves_derivation)\n    apply(force)\n   apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n    apply(rule epdaS.derivation_take_preserves_belongs)\n    apply(force)\n   apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n    apply(rule maximum_of_domain_derivation_take)\n    apply(force)\n   apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n    apply(simp add: derivation_take_def)\n   apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n    apply(simp add: derivation_take_def)\n   apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d da qf q s j sa e ja e' ea s' k eb c)(*strict*)\n    apply(erule_tac\n      x=\"k\"\n      and P=\"\\<lambda>k. k \\<le> j \\<longrightarrow> (\\<forall>e c. da k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ B # s))\"\n      in allE)\n    apply(rename_tac d da qf q s j sa e ja e' ea s' k eb c)(*strict*)\n    apply(clarsimp)\n    apply(simp add: derivation_take_def)\n   apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n  apply(thin_tac \"epdaS.belongs G da\")\n  apply(thin_tac \" da 0 = Some (pair None \\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = l', epdaS_conf_stack = B # s\\<rparr>)\")\n  apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n  apply(thin_tac \" da j = Some (pair e \\<lparr>epdaS_conf_state = q, epdaS_conf_scheduler = [], epdaS_conf_stack = B # s\\<rparr>)\")\n  apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n  apply(thin_tac \" \\<forall>k \\<le> j. \\<forall>e c. da k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ B # s)\")\n  apply(thin_tac \" da (Suc j) = Some (pair e' \\<lparr>epdaS_conf_state = qs, epdaS_conf_scheduler = [], epdaS_conf_stack = s\\<rparr>)\")\n  apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n  apply(subgoal_tac \"\\<exists>d2. epdaS.derivation G d2 \\<and> epdaS.belongs G d2 \\<and> maximum_of_domain d2 ja \\<and> d2 0 = Some (pair None \\<lparr>epdaS_conf_state = qs, epdaS_conf_scheduler = r', epdaS_conf_stack = A # sa\\<rparr>) \\<and> d2 ja = Some (pair ea \\<lparr>epdaS_conf_state = qf, epdaS_conf_scheduler = [], epdaS_conf_stack = s' @A # sa\\<rparr>) \\<and> (\\<forall>k \\<le> ja. \\<forall>e c. d2 k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ A # sa)) \")\n   apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n   prefer 2\n   apply(rule_tac\n      x=\"derivation_take d ja\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n    apply(rule epdaS.derivation_take_preserves_derivation)\n    apply(force)\n   apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n    apply(rule epdaS.derivation_take_preserves_belongs)\n    apply(force)\n   apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n    apply(rule maximum_of_domain_derivation_take)\n    apply(force)\n   apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n    apply(simp add: derivation_take_def)\n   apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n    apply(simp add: derivation_take_def)\n   apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d da qf q s j sa e ja e' ea s' d1 k eb c)(*strict*)\n   apply(erule_tac\n      x=\"k\"\n      and P=\"\\<lambda>k. k \\<le> ja \\<longrightarrow> (\\<forall>e c. d k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ A # sa))\"\n      in allE)\n   apply(rename_tac d da qf q s j sa e ja e' ea s' d1 k eb c)(*strict*)\n   apply(clarsimp)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n  apply(thin_tac \"epdaS.derivation G d\")\n  apply(thin_tac \" epdaS.belongs G d\")\n  apply(thin_tac \" d 0 = Some (pair None \\<lparr>epdaS_conf_state = qs, epdaS_conf_scheduler = r', epdaS_conf_stack = A # sa\\<rparr>)\")\n  apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n  apply(thin_tac \" \\<forall>k \\<le> ja. \\<forall>e c. d k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ A # sa)\")\n  apply(thin_tac \" d ja = Some (pair ea \\<lparr>epdaS_conf_state = qf, epdaS_conf_scheduler = [], epdaS_conf_stack = s' @ A # sa\\<rparr>)\")\n  apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n  apply(subgoal_tac \"\\<exists>d1. epdaS.derivation G d1 \\<and> epdaS.belongs G d1 \\<and> maximum_of_domain d1 (Suc j) \\<and> d1 0 = Some (pair None \\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = l', epdaS_conf_stack = B # A # sa\\<rparr>) \\<and> d1 j = Some (pair e \\<lparr>epdaS_conf_state = q, epdaS_conf_scheduler = [], epdaS_conf_stack = B # A # sa\\<rparr>) \\<and> (\\<forall>k \\<le> j. \\<forall>e c. d1 k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ B # A # sa)) \\<and> d1 (Suc j) = Some (pair e' \\<lparr>epdaS_conf_state = qs, epdaS_conf_scheduler = [], epdaS_conf_stack = A # sa\\<rparr>) \")\n   apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n   prefer 2\n   apply(subgoal_tac \"\\<lparr>epdaS_conf_state = qs, epdaS_conf_scheduler = r', epdaS_conf_stack = A # sa\\<rparr> \\<in> epdaS_configurations G\")\n    apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n    prefer 2\n    apply(clarsimp)\n    apply(rename_tac da qf q s j sa e ja e' ea s' d1 d2)(*strict*)\n    apply(rule_tac\n      d=\"d2\"\n      in epdaS.belongs_configurations)\n     apply(rename_tac da qf q s j sa e ja e' ea s' d1 d2)(*strict*)\n     apply(force)\n    apply(rename_tac da qf q s j sa e ja e' ea s' d1 d2)(*strict*)\n    apply(force)\n   apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n   apply(thin_tac \"\\<exists>d2. epdaS.derivation G d2 \\<and> epdaS.belongs G d2 \\<and> maximum_of_domain d2 ja \\<and> d2 0 = Some (pair None \\<lparr>epdaS_conf_state = qs, epdaS_conf_scheduler = r', epdaS_conf_stack = A # sa\\<rparr>) \\<and> d2 ja = Some (pair ea \\<lparr>epdaS_conf_state = qf, epdaS_conf_scheduler = [], epdaS_conf_stack = s' @ A # sa\\<rparr>) \\<and> (\\<forall>k \\<le> ja. \\<forall>e c. d2 k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ A # sa))\")\n   apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n   apply(clarsimp)\n   apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n   apply(rule_tac\n      x=\"derivation_map d1 (\\<lambda>c. c\\<lparr>epdaS_conf_stack := butn (epdaS_conf_stack c) (length s) @ (A # sa)\\<rparr>)\"\n      in exI)\n   apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n   apply(rule context_conjI)\n    apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n    apply(rule epdaS_unused_stack_modification_preserves_derivation)\n          apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n          apply(simp add: valid_simple_dpda_def valid_dpda_def)\n         apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n         apply(force)\n        apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n        apply(force)\n       apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n       apply(force)\n      apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n      apply(force)\n     apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n     apply(force)\n    apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n    apply(force)\n   apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n    apply(rule epdaS.derivation_belongs)\n       apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n       apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n      apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n      apply(simp add: derivation_map_def)\n     apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n     apply(simp add: butn_def)\n     apply(subgoal_tac \"\\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = l', epdaS_conf_stack = B # s\\<rparr> \\<in> epdaS_configurations G\")\n      apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n      apply(simp add: epdaS_configurations_def)\n     apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n     apply(rule_tac\n      d=\"d1\"\n      in epdaS.belongs_configurations)\n      apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n      apply(force)\n     apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n     apply(force)\n    apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n    apply(force)\n   apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n    apply(rule derivation_map_preserves_maximum_of_domain)\n    apply(force)\n   apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n    apply(simp add: derivation_map_def butn_def)\n   apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n    apply(simp add: derivation_map_def butn_def)\n   apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac da qf q s j sa e e' d1 k ea c)(*strict*)\n    apply(erule_tac\n      x=\"k\"\n      in allE)\n    apply(clarsimp)\n    apply(simp add: derivation_map_def butn_def)\n    apply(case_tac \"d1 k\")\n     apply(rename_tac da qf q s j sa e e' d1 k ea c)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac da qf q s j sa e e' d1 k ea c a)(*strict*)\n    apply(clarsimp)\n    apply(case_tac a)\n    apply(rename_tac da qf q s j sa e e' d1 k ea c a option b)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac da qf q s j sa e e' d1)(*strict*)\n   apply(simp add: derivation_map_def butn_def)\n  apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n  apply(thin_tac \"\\<exists>d1. epdaS.derivation G d1 \\<and> epdaS.belongs G d1 \\<and> maximum_of_domain d1 (Suc j) \\<and> d1 0 = Some (pair None \\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = l', epdaS_conf_stack = B # s\\<rparr>) \\<and> d1 j = Some (pair e \\<lparr>epdaS_conf_state = q, epdaS_conf_scheduler = [], epdaS_conf_stack = B # s\\<rparr>) \\<and> (\\<forall>k \\<le> j. \\<forall>e c. d1 k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ B # s)) \\<and> d1 (Suc j) = Some (pair e' \\<lparr>epdaS_conf_state = qs, epdaS_conf_scheduler = [], epdaS_conf_stack = s\\<rparr>)\")\n  apply(rename_tac d da qf q s j sa e ja e' ea s')(*strict*)\n  apply(clarsimp)\n  apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n  apply(rule_tac\n      x=\"derivation_append (der2 \\<lparr>epdaS_conf_state = src, epdaS_conf_scheduler = l'@r', epdaS_conf_stack = A # sa\\<rparr> \\<lparr>edge_src = src, edge_event = None, edge_pop = [A], edge_push = [B, A], edge_trg = trg\\<rparr> \\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = l'@r', epdaS_conf_stack = B # A # sa\\<rparr>) (derivation_append (derivation_map d1 (\\<lambda>c. c\\<lparr>epdaS_conf_scheduler := take (length (epdaS_conf_scheduler c) - length (epdaS_conf_scheduler \\<lparr>epdaS_conf_state = qs, epdaS_conf_scheduler = [], epdaS_conf_stack = A # sa\\<rparr>)) (epdaS_conf_scheduler c) @ r'\\<rparr>)) d2 (Suc j)) (Suc 0)\"\n      in exI)\n  apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n  apply(rule_tac\n      x=\"qf\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n  apply(rule context_conjI)\n   apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n   apply(rule epdaS.derivation_append_preserves_derivation)\n     apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n     apply(rule epdaS.der2_is_derivation)\n     apply(simp add: epdaS_step_relation_def)\n     apply(simp add: option_to_list_def)\n    apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n    apply(rule epdaS.derivation_append_preserves_derivation)\n      apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n      apply(rule epda_maximal_context_preserves_derivation_prime)\n            apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n            apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n           apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n           apply(force)\n          apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n          apply(force)\n         apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n         apply(force)\n        apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n        apply(force)\n       apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n       apply(force)\n      apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n      apply(force)\n     apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n     apply(force)\n    apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n    apply(simp add: derivation_map_def)\n   apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n   apply(simp add: der2_def derivation_append_def derivation_map_def)\n  apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n   apply(rule_tac\n      ca=\"\\<lparr>epdaS_conf_state = src, epdaS_conf_scheduler = l'@r', epdaS_conf_stack = A # sa\\<rparr>\"\n      in epdaS.derivation_belongs)\n      apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n      apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n     apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n     apply(simp add: der2_def derivation_append_def derivation_map_def)\n    apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n    apply(subgoal_tac \"valid_epda_step_label G \\<lparr>edge_src = src, edge_event = None, edge_pop = [A], edge_push = [B, A], edge_trg = trg\\<rparr>\")\n     apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n     apply(subgoal_tac \"\\<lparr>epdaS_conf_state = trg, epdaS_conf_scheduler = l', epdaS_conf_stack = B # A # sa\\<rparr> \\<in> epdaS_configurations G\")\n      apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n      apply(subgoal_tac \"\\<lparr>epdaS_conf_state = qs, epdaS_conf_scheduler = r', epdaS_conf_stack = A # sa\\<rparr> \\<in> epdaS_configurations G\")\n       apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n       apply(simp add: epdaS_configurations_def valid_epda_step_label_def)\n      apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n      apply(rule_tac\n      d=\"d2\"\n      in epdaS.belongs_configurations)\n       apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n       apply(force)\n      apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n      apply(force)\n     apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n     apply(rule_tac\n      d=\"d1\"\n      in epdaS.belongs_configurations)\n      apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n      apply(force)\n     apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n     apply(force)\n    apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n    apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n   apply(simp add: der2_def derivation_append_def derivation_map_def)\n  apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n  apply(rule_tac\n      x=\"sa\"\n      in exI)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n   apply(simp add: der2_def derivation_append_def derivation_map_def)\n  apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n  apply(rule_tac\n      x=\"Suc j+ja+Suc 0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n   apply(rule_tac\n      x=\"if ja=0 then e' else ea\"\n      in exI)\n   apply(simp add: der2_def derivation_append_def derivation_map_def)\n   apply(clarsimp)\n  apply(rename_tac da qf q j sa e ja e' ea s' d2 d1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 k eb c)(*strict*)\n  apply(case_tac k)\n   apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 k eb c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 eb c)(*strict*)\n   apply(simp add: der2_def derivation_append_def derivation_map_def)\n   apply(clarsimp)\n  apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 k eb c nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 eb c nat)(*strict*)\n  apply(case_tac \"nat \\<le> j\")\n   apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 eb c nat)(*strict*)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"nat\"\n      and P=\"\\<lambda>nat. nat \\<le> j \\<longrightarrow> (\\<forall>e c. d1 nat = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ B # A # sa))\"\n      in allE)\n   apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 eb c nat)(*strict*)\n   apply(clarsimp)\n   apply(simp add: der2_def derivation_append_def derivation_map_def)\n   apply(case_tac nat)\n    apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 eb c nat)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 eb c nat nata)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 eb c nata)(*strict*)\n   apply(case_tac \"d1 (Suc nata)\")\n    apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 eb c nata)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 eb c nata a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 eb c nata a option b)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 eb c nat)(*strict*)\n  apply(case_tac \"Suc nat=j\")\n   apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 eb c nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 eb c nat)(*strict*)\n  apply(clarsimp)\n  apply(simp add: der2_def derivation_append_def derivation_map_def)\n  apply(case_tac \"nat \\<le> Suc j\")\n   apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 eb c nat)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"nat=Suc j\")\n    apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 eb c nat)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 eb c nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 eb c nat)(*strict*)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"nat - Suc j\"\n      and P=\"\\<lambda>x. x \\<le> ja \\<longrightarrow> (\\<forall>e c. d2 x = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ A # sa))\"\n      in allE)\n  apply(rename_tac da qf q j sa e ja e' ea s' d2 d1 eb c nat)(*strict*)\n  apply(clarsimp)\n  done\n\ntheorem epda_sub_preserves_epdaH_marked_language: \"\n  valid_epda G\n  \\<Longrightarrow> valid_epda G'\n  \\<Longrightarrow> epda_sub G' G\n  \\<Longrightarrow> epdaH.marked_language G' \\<subseteq> epdaH.marked_language G\"\n  apply(simp add: epdaH.marked_language_def)\n  apply(clarsimp)\n  apply(rename_tac x d)(*strict*)\n  apply(rule_tac x=\"d\" in exI)\n  apply(rule context_conjI)\n   apply(rename_tac x d)(*strict*)\n   apply(rule_tac epda_sub_preserves_derivation_initial)\n      apply(rename_tac x d)(*strict*)\n      prefer 3\n      apply(force)\n     apply(rename_tac x d)(*strict*)\n     apply(force)\n    apply(rename_tac x d)(*strict*)\n    apply(force)\n   apply(rename_tac x d)(*strict*)\n   apply(force)\n  apply(rename_tac x d)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac x d)(*strict*)\n   apply(simp add: epdaH_marked_effect_def)\n   apply(clarsimp)\n   apply(rename_tac d i e c)(*strict*)\n   apply(rule_tac x=\"i\" in exI)\n   apply(rule_tac x=\"e\" in exI)\n   apply(rule_tac x=\"c\" in exI)\n   apply(clarsimp)\n   apply(simp add: epdaH_marking_configurations_def epdaH_configurations_def epda_sub_def)\n   apply(force)\n  apply(rename_tac x d)(*strict*)\n  apply(simp add: epdaH.derivation_initial_def)\n  apply(clarsimp)\n  apply(case_tac \"d 0\")\n   apply(rename_tac x d)(*strict*)\n   apply(force)\n  apply(rename_tac x d a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac x d a option conf)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d conf)(*strict*)\n  apply(simp add: epdaH_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac x d conf i e c)(*strict*)\n  apply(rule_tac x=\"i\" in exI)\n  apply(rule_tac x=\"e\" in exI)\n  apply(rule_tac x=\"c\" in exI)\n  apply(clarsimp)\n  apply(simp add: epdaH_marking_configurations_def epdaH_configurations_def epda_sub_def)\n  apply(force)\n  done\n\ntheorem epda_sub_preserves_epdaH_unmarked_language: \"\n  valid_epda G\n  \\<Longrightarrow> valid_epda G'\n  \\<Longrightarrow> epda_sub G' G\n  \\<Longrightarrow> epdaH.unmarked_language G' \\<subseteq> epdaH.unmarked_language G\"\n  apply(simp add: epdaH.unmarked_language_def)\n  apply(clarsimp)\n  apply(rename_tac x d)(*strict*)\n  apply(rule_tac x=\"d\" in exI)\n  apply(rule context_conjI)\n   apply(rename_tac x d)(*strict*)\n   apply(rule_tac epda_sub_preserves_derivation_initial)\n      apply(rename_tac x d)(*strict*)\n      prefer 3\n      apply(force)\n     apply(rename_tac x d)(*strict*)\n     apply(force)\n    apply(rename_tac x d)(*strict*)\n    apply(force)\n   apply(rename_tac x d)(*strict*)\n   apply(force)\n  apply(rename_tac x d)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac x d)(*strict*)\n   apply(simp add: epdaH_unmarked_effect_def)\n  apply(rename_tac x d)(*strict*)\n  apply(simp add: epdaH.derivation_initial_def)\n  done\n\ndefinition epdaH_accessible_states :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> 'state set\"\n  where\n    \"epdaH_accessible_states G \\<equiv>\n  {epdaH_conf_state c | d n e c.\n    epdaH.derivation_initial G d\n    \\<and> d n = Some (pair e c)}\"\n\nlemma epda_initial_in_epdaH_accessible_states: \"\n  valid_epda G\n  \\<Longrightarrow> epda_initial G \\<in> epdaH_accessible_states G\"\n  apply(simp add: epdaH_accessible_states_def)\n  apply(rule_tac x=\"der1 \\<lparr>epdaH_conf_state=epda_initial G,epdaH_conf_history=[],epdaH_conf_stack=[epda_box G]\\<rparr>\" in exI)\n  apply(rule_tac x=\"0\" in exI)\n  apply(rule_tac x=\"None\" in exI)\n  apply(rule_tac x=\"\\<lparr>epdaH_conf_state=epda_initial G,epdaH_conf_history=[],epdaH_conf_stack=[epda_box G]\\<rparr>\" in exI)\n  apply(rule conjI)\n   apply(force)\n  apply(rule conjI)\n   apply(simp add: epdaH.derivation_initial_def)\n   apply(rule conjI)\n    apply(rule epdaH.der1_is_derivation)\n   apply(simp add: der1_def epdaH_initial_configurations_def epdaH_configurations_def valid_epda_def)\n  apply(simp add: der1_def epdaH_initial_configurations_def epdaH_configurations_def valid_epda_def)\n  done\n\nlemma epdaS_step_relation_injective_on_edge: \"\n  valid_pda G\n  \\<Longrightarrow> epdaS_step_relation G c e1 c'\n  \\<Longrightarrow> epdaS_step_relation G c e2 c'\n  \\<Longrightarrow> e1 = e2\"\n  apply(subgoal_tac \"\\<exists>x. edge_pop e1 = [x]\")\n   prefer 2\n   apply(simp add: valid_pda_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"e1\"\n      in ballE)\n    prefer 2\n    apply(simp add: epdaS_step_relation_def)\n   apply (metis insert_Nil last_triv)\n  apply(subgoal_tac \"\\<exists>x. edge_pop e2 = [x]\")\n   prefer 2\n   apply(simp add: valid_pda_def)\n   apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   apply(erule_tac\n      x=\"e2\"\n      in ballE)\n    apply(rename_tac x)(*strict*)\n    prefer 2\n    apply(simp add: epdaS_step_relation_def)\n   apply(rename_tac x)(*strict*)\n   apply (metis insert_Nil last_triv)\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac x w)(*strict*)\n  apply(case_tac e1)\n  apply(rename_tac x w edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n  apply(case_tac e2)\n  apply(rename_tac x w edge_srca edge_eventa edge_popa edge_pusha edge_trga edge_srcaa edge_eventaa edge_popaa edge_pushaa edge_trgaa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x w edge_event edge_push edge_eventa)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(case_tac \"edge_event\")\n   apply(rename_tac x w edge_event edge_push edge_eventa)(*strict*)\n   apply(case_tac \"edge_eventa\")\n    apply(rename_tac x w edge_event edge_push edge_eventa)(*strict*)\n    apply(force)\n   apply(rename_tac x w edge_event edge_push edge_eventa a)(*strict*)\n   apply(force)\n  apply(rename_tac x w edge_event edge_push edge_eventa a)(*strict*)\n  apply(case_tac \"edge_eventa\")\n   apply(rename_tac x w edge_event edge_push edge_eventa a)(*strict*)\n   apply(force)\n  apply(rename_tac x w edge_event edge_push edge_eventa a aa)(*strict*)\n  apply(force)\n  done\n\nlemma epda_edge_event_in_effects: \"\n  valid_epda G\n  \\<Longrightarrow> e \\<in> epda_delta G\n  \\<Longrightarrow> option_to_list (edge_event e) \\<in> epda_effects G\"\n  apply(simp add: valid_epda_def valid_epda_step_label_def option_to_list_def option_to_set_def epda_effects_def)\n  done\n\nlemma apply_epdaS_is_forward_edge_deterministic_accessible_with_compatible_post_configurations: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.is_forward_edge_deterministic_accessible G\n  \\<Longrightarrow> epdaH.derivation_initial G d\n  \\<Longrightarrow> d n = Some (pair e c)\n  \\<Longrightarrow> epdaH_step_relation G c e1 c1\n  \\<Longrightarrow> epdaH_step_relation G c e2 c2\n  \\<Longrightarrow> epdaH_conf_history c1@v1=epdaH_conf_history c2@v2\n  \\<Longrightarrow> e1=e2\"\n  apply(subgoal_tac \"epdaH.is_forward_edge_deterministicHist_DB_long SSG\" for SSG)\n   prefer 2\n   apply(rule I_epda_HS_H.epdaHS2HF_DEdetermR_FEdetermHist_DB)\n    apply(force)\n   apply(subgoal_tac \"epdaHS.is_forward_deterministic_accessible G\")\n    apply(simp add: epdaHS.is_forward_deterministic_accessible_def)\n   apply(rule epdaS_vs_epdaHS_is_forward_deterministic_accessible_preserved)\n    apply(force)\n   apply(simp add: epdaS.is_forward_deterministic_accessible_def)\n   apply (metis epda_is_is_forward_target_deterministic_accessible)\n  apply(simp add: epdaH.is_forward_edge_deterministicHist_DB_long_def)\n  apply(erule_tac\n      x=\"c\"\n      in allE)\n  apply(erule impE)\n   apply(rule_tac\n      x=\"d\"\n      in exI)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n   apply(rule_tac\n      x=\"n\"\n      in exI)\n   apply(clarsimp)\n  apply(erule_tac\n      x=\"c1\"\n      in allE)\n  apply(erule_tac\n      x=\"c2\"\n      in allE)\n  apply(erule_tac\n      x=\"e1\"\n      in allE)\n  apply(erule_tac\n      x=\"e2\"\n      in allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"option_to_list (edge_event e1)\"\n      in allE)\n  apply(erule impE)\n   apply(rule epda_edge_event_in_effects)\n    apply(force)\n   apply(simp add: epdaH_step_relation_def)\n  apply(erule_tac\n      x=\"option_to_list (edge_event e2)\"\n      in allE)\n  apply(erule impE)\n   apply(simp add: epdaH_step_relation_def)\n  apply(erule impE)\n   apply(simp add: epdaH_step_relation_def)\n  apply(erule impE)\n   apply(rule epda_edge_event_in_effects)\n    apply(force)\n   apply(simp add: epdaH_step_relation_def)\n  apply(simp add: epdaH_step_relation_def)\n  apply(simp add: epdaH.history_fragment_prefixes_def)\n  apply(clarsimp)\n  apply(rename_tac x xa w wa hf'' hf''a)(*strict*)\n  apply(simp add: option_to_list_def epda_effects_def)\n  apply(case_tac \"edge_event e1\")\n   apply(rename_tac x xa w wa hf'' hf''a)(*strict*)\n   apply(case_tac \"edge_event e2\")\n    apply(rename_tac x xa w wa hf'' hf''a)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac x xa w wa hf'' hf''a a)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x xa w wa hf'' hf''a a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"edge_event e2\")\n   apply(rename_tac x xa w wa hf'' hf''a a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x w wa hf'' a)(*strict*)\n   apply(case_tac x)\n    apply(rename_tac x w wa hf'' a)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac x w wa hf'' a aa list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x xa w wa hf'' hf''a a aa)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma EDPDA_derivations_coincide: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.is_forward_edge_deterministic_accessible G\n  \\<Longrightarrow> epdaH.derivation_initial G d1\n  \\<Longrightarrow> epdaH.derivation_initial G d2\n  \\<Longrightarrow> d1 n1 = Some (pair e1 c1)\n  \\<Longrightarrow> d2 (n1 + n) = Some (pair e2 c2)\n  \\<Longrightarrow> epdaH_conf_history c1 = epdaH_conf_history c2\n  \\<Longrightarrow> i\\<le>n1\n  \\<Longrightarrow> d1 i = d2 i\"\n  apply(induct i)\n   apply(clarsimp)\n   apply(simp add: epdaH.derivation_initial_def epdaH_initial_configurations_def)\n   apply(case_tac \"d1 0\")\n    apply(clarsimp)\n   apply(rename_tac a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"d2 0\")\n    apply(rename_tac a)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac a aa)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac a aa option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac aa b)(*strict*)\n   apply(case_tac aa)\n   apply(rename_tac aa b option ba)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac b ba)(*strict*)\n   apply(simp add: epdaH.derivation_initial_def epdaH_initial_configurations_def)\n  apply(rename_tac i)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d1 i = Some (pair e1 c1) \\<and> d1 (Suc i) = Some (pair (Some e2) c2) \\<and> epdaH_step_relation G c1 e2 c2\")\n   apply(rename_tac i)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"n1\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac i)(*strict*)\n     apply(rule epdaH.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac i)(*strict*)\n    apply(force)\n   apply(rename_tac i)(*strict*)\n   apply(force)\n  apply(rename_tac i)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i e1a e2a c1a c2a)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d2 i = Some (pair e1 c1) \\<and> d2 (Suc i) = Some (pair (Some e2) c2) \\<and> epdaH_step_relation G c1 e2 c2\")\n   apply(rename_tac i e1a e2a c1a c2a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"n1+n\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac i e1a e2a c1a c2a)(*strict*)\n     apply(rule epdaH.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac i e1a e2a c1a c2a)(*strict*)\n    apply(force)\n   apply(rename_tac i e1a e2a c1a c2a)(*strict*)\n   apply(force)\n  apply(rename_tac i e1a e2a c1a c2a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n  apply(subgoal_tac \"e2a=e2aa\")\n   apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i e1a c1a c2a e2a c2aa)(*strict*)\n   apply(simp add: epdaH_step_relation_def)\n   apply(clarsimp)\n  apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n  apply(subgoal_tac \"\\<exists>h\\<in> epda_effects G. epdaH_conf_history c1 = epdaH_conf_history c2a @ h\")\n   apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"d1\"\n      and n=\"Suc i\"\n      and m=\"n1-Suc i\"\n      in epdaH.steps_extend_history_derivation)\n       apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n       apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n      apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n      apply(simp add: epdaH.derivation_initial_def)\n     apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n     apply(rule_tac\n      d=\"d1\"\n      in epdaH.belongs_configurations)\n      apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n      apply(rule epdaH.derivation_initial_belongs)\n       apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n       apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n      apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n      apply(force)\n     apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n     apply(force)\n    apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n  apply(subgoal_tac \"\\<exists>h\\<in> epda_effects G. epdaH_conf_history c2 = epdaH_conf_history c2aa @ h\")\n   apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"d2\"\n      and n=\"Suc i\"\n      and m=\"n1+n-Suc i\"\n      in epdaH.steps_extend_history_derivation)\n       apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n       apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n      apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n      apply(simp add: epdaH.derivation_initial_def)\n     apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n     apply(rule_tac\n      d=\"d2\"\n      in epdaH.belongs_configurations)\n      apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n      apply(rule epdaH.derivation_initial_belongs)\n       apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n       apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n      apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n      apply(force)\n     apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n     apply(force)\n    apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac i e1a e2a c1a c2a e2aa c2aa)(*strict*)\n  apply(simp add: epda_effects_def)\n  apply(clarsimp)\n  apply(rename_tac i e1a e2a c1a c2a e2aa c2aa h ha)(*strict*)\n  apply(subgoal_tac \"e2a=e2aa\")\n   apply(rename_tac i e1a e2a c1a c2a e2aa c2aa h ha)(*strict*)\n   prefer 2\n   apply(rule_tac\n      ?v2.0=\"ha\"\n      and ?v1.0=\"h\"\n      and d=\"d1\"\n      and n=\"i\"\n      in apply_epdaS_is_forward_edge_deterministic_accessible_with_compatible_post_configurations)\n         apply(rename_tac i e1a e2a c1a c2a e2aa c2aa h ha)(*strict*)\n         apply(force)\n        apply(rename_tac i e1a e2a c1a c2a e2aa c2aa h ha)(*strict*)\n        apply(force)\n       apply(rename_tac i e1a e2a c1a c2a e2aa c2aa h ha)(*strict*)\n       apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n      apply(rename_tac i e1a e2a c1a c2a e2aa c2aa h ha)(*strict*)\n      apply(force)\n     apply(rename_tac i e1a e2a c1a c2a e2aa c2aa h ha)(*strict*)\n     apply(force)\n    apply(rename_tac i e1a e2a c1a c2a e2aa c2aa h ha)(*strict*)\n    apply(force)\n   apply(rename_tac i e1a e2a c1a c2a e2aa c2aa h ha)(*strict*)\n   apply(force)\n  apply(rename_tac i e1a e2a c1a c2a e2aa c2aa h ha)(*strict*)\n  apply(force)\n  done\n\nlemma SDPDA_derivations_coincide2: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.is_forward_edge_deterministic_accessible G\n  \\<Longrightarrow> epdaH.derivation_initial G d1\n  \\<Longrightarrow> epdaH.derivation_initial G d2\n  \\<Longrightarrow> d1 n1 = Some (pair e1 c1)\n  \\<Longrightarrow> d1 (Suc n1) = Some (pair e1' c1')\n  \\<Longrightarrow> d2 n2 = Some (pair e2 c2)\n  \\<Longrightarrow> d2 (Suc n2) = Some (pair e2' c2')\n  \\<Longrightarrow> epdaH_conf_history c1=epdaH_conf_history c2\n  \\<Longrightarrow> epdaH_conf_history c1'=epdaH_conf_history c2'\n  \\<Longrightarrow> epdaH_conf_history c1'=epdaH_conf_history c1@[a]\n  \\<Longrightarrow> n1\\<le>n2\n  \\<Longrightarrow> n1=n2 \\<and> (\\<forall>i\\<le>n1. d1 i = d2 i)\"\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>n. n1+n=n2\")\n   prefer 2\n   apply(rule_tac\n      x=\"n2-n1\"\n      in exI)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac n)(*strict*)\n  apply(subgoal_tac \"(\\<forall>i\\<le>n1. d1 i = d2 i)\")\n   apply(rename_tac n)(*strict*)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"n1\"\n      in allE)\n   apply(clarsimp)\n   apply(case_tac n)\n    apply(rename_tac n)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac n nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac nat)(*strict*)\n   apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d1 n1 = Some (pair e1 c1) \\<and> d1 (Suc n1) = Some (pair (Some e2) c2) \\<and> epdaH_step_relation G c1 e2 c2\")\n    apply(rename_tac nat)(*strict*)\n    prefer 2\n    apply(rule_tac\n      m=\"Suc n1\"\n      in epdaH.step_detail_before_some_position)\n      apply(rename_tac nat)(*strict*)\n      apply(rule epdaH.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac nat)(*strict*)\n     apply(force)\n    apply(rename_tac nat)(*strict*)\n    apply(force)\n   apply(rename_tac nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac nat e2a)(*strict*)\n   apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d2 n1 = Some (pair e1 c1) \\<and> d2 (Suc n1) = Some (pair (Some e2) c2) \\<and> epdaH_step_relation G c1 e2 c2\")\n    apply(rename_tac nat e2a)(*strict*)\n    prefer 2\n    apply(rule_tac\n      m=\"Suc (n1+nat)\"\n      in epdaH.step_detail_before_some_position)\n      apply(rename_tac nat e2a)(*strict*)\n      apply(rule epdaH.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac nat e2a)(*strict*)\n     apply(force)\n    apply(rename_tac nat e2a)(*strict*)\n    apply(force)\n   apply(rename_tac nat e2a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac nat e2a e2aa c2a)(*strict*)\n   apply(subgoal_tac \"\\<exists>h\\<in> epda_effects G. epdaH_conf_history c2 = epdaH_conf_history c2a @ h\")\n    apply(rename_tac nat e2a e2aa c2a)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"d2\"\n      and n=\"Suc n1\"\n      and m=\"nat\"\n      in epdaH.steps_extend_history_derivation)\n        apply(rename_tac nat e2a e2aa c2a)(*strict*)\n        apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n       apply(rename_tac nat e2a e2aa c2a)(*strict*)\n       apply(simp add: epdaH.derivation_initial_def)\n      apply(rename_tac nat e2a e2aa c2a)(*strict*)\n      apply(rule_tac\n      d=\"d2\"\n      in epdaH.belongs_configurations)\n       apply(rename_tac nat e2a e2aa c2a)(*strict*)\n       apply(rule epdaH.derivation_initial_belongs)\n        apply(rename_tac nat e2a e2aa c2a)(*strict*)\n        apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n       apply(rename_tac nat e2a e2aa c2a)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2a e2aa c2a)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2a e2aa c2a)(*strict*)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac nat e2a e2aa c2a)(*strict*)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac nat e2a e2aa c2a)(*strict*)\n   apply(simp add: epda_effects_def)\n   apply(clarsimp)\n   apply(rename_tac nat e2a e2aa c2a h)(*strict*)\n   apply(subgoal_tac \"e2a=e2aa\")\n    apply(rename_tac nat e2a e2aa c2a h)(*strict*)\n    prefer 2\n    apply(rule_tac\n      ?v2.0=\"h@[a]\"\n      and ?v1.0=\"[]\"\n      and d=\"d1\"\n      and n=\"n1\"\n      in apply_epdaS_is_forward_edge_deterministic_accessible_with_compatible_post_configurations)\n          apply(rename_tac nat e2a e2aa c2a h)(*strict*)\n          apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n         apply(rename_tac nat e2a e2aa c2a h)(*strict*)\n         apply(force)\n        apply(rename_tac nat e2a e2aa c2a h)(*strict*)\n        apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n       apply(rename_tac nat e2a e2aa c2a h)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2a e2aa c2a h)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2a e2aa c2a h)(*strict*)\n     apply(force)\n    apply(rename_tac nat e2a e2aa c2a h)(*strict*)\n    apply(force)\n   apply(rename_tac nat e2a e2aa c2a h)(*strict*)\n   apply(rule_tac\n      t=\"epdaH_conf_history c1'\"\n      and s=\"epdaH_conf_history c2'\"\n      in ssubst)\n    apply(rename_tac nat e2a e2aa c2a h)(*strict*)\n    apply(force)\n   apply(rename_tac nat e2a e2aa c2a h)(*strict*)\n   apply(rule_tac\n      t=\"epdaH_conf_history c2'\"\n      and s=\"epdaH_conf_history c2a @ h @ [a]\"\n      in ssubst)\n    apply(rename_tac nat e2a e2aa c2a h)(*strict*)\n    apply(force)\n   apply(rename_tac nat e2a e2aa c2a h)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac nat e2a c2a h)(*strict*)\n   apply(simp add: epdaH_step_relation_def)\n  apply(rename_tac n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n i)(*strict*)\n  apply(rule EDPDA_derivations_coincide)\n         apply(rename_tac n i)(*strict*)\n         apply(force)+\n  done\n\nlemma SDPDA_derivations_coincide3: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.is_forward_edge_deterministic_accessible G\n  \\<Longrightarrow> epdaH.derivation_initial G d1\n  \\<Longrightarrow> epdaH.derivation_initial G d2\n  \\<Longrightarrow> d1 n1 = Some (pair e1 c1)\n  \\<Longrightarrow> d1 (Suc n1) = Some (pair e1' c1')\n  \\<Longrightarrow> d2 n2 = Some (pair e2 c2)\n  \\<Longrightarrow> d2 (Suc n2) = Some (pair e2' c2')\n  \\<Longrightarrow> epdaH_conf_history c1=epdaH_conf_history c2\n  \\<Longrightarrow> epdaH_conf_history c1'=epdaH_conf_history c2'\n  \\<Longrightarrow> epdaH_conf_history c1'=epdaH_conf_history c1@[a]\n  \\<Longrightarrow> n1=n2 \\<and> (\\<forall>i\\<le>n1. d1 i = d2 i)\"\n  apply(case_tac \"n1\\<le>n2\")\n   apply(rule_tac\n      a=\"a\"\n      in SDPDA_derivations_coincide2)\n              apply(force)+\n  apply(subgoal_tac \"n2 = n1 \\<and> (\\<forall>i\\<le>n2. d2 i = d1 i)\")\n   apply(force)\n  apply(rule_tac\n      a=\"a\"\n      in SDPDA_derivations_coincide2)\n             apply(force)+\n  done\n\ndefinition duplicate_markingH :: \"('q,'a,'b)epda \\<Rightarrow> bool\" where\n  \"duplicate_markingH G \\<equiv> (\\<exists>d. epdaH.derivation_initial G d \\<and> (\\<exists>i j.\n  d (i+j+Suc 0) \\<noteq> None\n  \\<and> epdaH_conf_state (the(get_configuration (d i))) \\<in> epda_marking G\n  \\<and> epdaH_conf_state (the(get_configuration (d (i+j+Suc 0)))) \\<in> epda_marking G\n  \\<and> epdaH_conf_history (the(get_configuration (d i))) = epdaH_conf_history (the(get_configuration (d (i+j+Suc 0))))\n  ))\"\n\nlemma EDPDA_derivations_coincide4: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.is_forward_edge_deterministic_accessible G\n  \\<Longrightarrow> \\<not> duplicate_markingH G\n  \\<Longrightarrow> epdaH.derivation_initial G d1\n  \\<Longrightarrow> epdaH.derivation_initial G d2\n  \\<Longrightarrow> d1 n1 = Some (pair e1 c1)\n  \\<Longrightarrow> c1 \\<in> epdaH_marking_configurations G\n  \\<Longrightarrow> d2 n2 = Some (pair e2 c2)\n  \\<Longrightarrow> c2 \\<in> epdaH_marking_configurations G\n  \\<Longrightarrow> epdaH_conf_history c1=epdaH_conf_history c2\n  \\<Longrightarrow> n1\\<le>n2\n  \\<Longrightarrow> n1=n2 \\<and> (\\<forall>i\\<le>n1. d1 i = d2 i)\"\n  apply(subgoal_tac \"\\<exists>n. n1+n=n2\")\n   apply(clarsimp)\n   apply(rename_tac n)(*strict*)\n   apply(subgoal_tac \"(\\<forall>i\\<le>n1. d1 i = d2 i)\")\n    apply(rename_tac n)(*strict*)\n    prefer 2\n    apply(clarsimp)\n    apply(rename_tac n i)(*strict*)\n    apply(rule EDPDA_derivations_coincide)\n           apply(rename_tac n i)(*strict*)\n           apply(force)\n          apply(rename_tac n i)(*strict*)\n          apply(force)\n         apply(rename_tac n i)(*strict*)\n         apply(force)\n        apply(rename_tac n i)(*strict*)\n        apply(force)\n       apply(rename_tac n i)(*strict*)\n       apply(force)\n      apply(rename_tac n i)(*strict*)\n      apply(force)\n     apply(rename_tac n i)(*strict*)\n     apply(force)\n    apply(rename_tac n i)(*strict*)\n    apply(force)\n   apply(rename_tac n)(*strict*)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"n1\"\n      in allE)\n   apply(clarsimp)\n   apply(simp add: duplicate_markingH_def)\n   apply(erule_tac\n      x=\"d2\"\n      in allE)\n   apply(clarsimp)\n   apply(case_tac n)\n    apply(rename_tac n)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac n nat)(*strict*)\n   apply(erule_tac\n      x=\"n1\"\n      in allE)\n   apply(erule_tac\n      x=\"nat\"\n      in allE)\n   apply(clarsimp)\n   apply(rename_tac nat)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(simp add: epdaH_marking_configurations_def)\n  apply(rule_tac\n      x=\"n2-n1\"\n      in exI)\n  apply(force)\n  done\n\nlemma EDPDA_derivations_coincide5: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.is_forward_edge_deterministic_accessible G\n  \\<Longrightarrow> \\<not> duplicate_markingH G\n  \\<Longrightarrow> epdaH.derivation_initial G d1\n  \\<Longrightarrow> epdaH.derivation_initial G d2\n  \\<Longrightarrow> d1 n1 = Some (pair e1 c1)\n  \\<Longrightarrow> c1 \\<in> epdaH_marking_configurations G\n  \\<Longrightarrow> d2 n2 = Some (pair e2 c2)\n  \\<Longrightarrow> c2 \\<in> epdaH_marking_configurations G\n  \\<Longrightarrow> epdaH_conf_history c1=epdaH_conf_history c2\n  \\<Longrightarrow> n1=n2 \\<and> (\\<forall>i\\<le>n1. d1 i = d2 i)\"\n  apply(case_tac \"n1\\<le>n2\")\n   apply(rule EDPDA_derivations_coincide4)\n             apply(force)+\n  apply(subgoal_tac \"n2 = n1 \\<and> (\\<forall>i\\<le>n2. d2 i = d1 i)\")\n   apply(force)\n  apply(rule EDPDA_derivations_coincide4)\n            apply(force)+\n  done\n\nlemma epdaS_apply_is_forward_edge_deterministic_accessible: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.is_forward_edge_deterministic_accessible G\n  \\<Longrightarrow> c \\<in> epdaS.get_accessible_configurations G\n  \\<Longrightarrow> x \\<in> epda_delta G\n  \\<Longrightarrow> y \\<in> epda_delta G\n  \\<Longrightarrow> edge_src x=edge_src y\n  \\<Longrightarrow> edge_src x=epdaS_conf_state c\n  \\<Longrightarrow> prefix (edge_pop x) (epdaS_conf_stack c)\n  \\<Longrightarrow> prefix (edge_pop y) (epdaS_conf_stack c)\n  \\<Longrightarrow> prefix (option_to_list(edge_event x)) (epdaS_conf_scheduler c)\n  \\<Longrightarrow> prefix (option_to_list(edge_event y)) (epdaS_conf_scheduler c)\n  \\<Longrightarrow> x=y\"\n  apply(simp add: epdaS.is_forward_edge_deterministic_accessible_def)\n  apply(erule_tac\n      x=\"c\"\n      in ballE)\n   prefer 2\n   apply(force)\n  apply(erule_tac\n      x=\"\\<lparr>epdaS_conf_state=edge_trg x,epdaS_conf_scheduler=drop(length(option_to_list (edge_event x)))(epdaS_conf_scheduler c),epdaS_conf_stack=(edge_push x)@(drop(length(edge_pop x))(epdaS_conf_stack c))\\<rparr>\"\n      in allE)\n  apply(erule_tac\n      x=\"\\<lparr>epdaS_conf_state=edge_trg y,epdaS_conf_scheduler=drop(length(option_to_list (edge_event y)))(epdaS_conf_scheduler c),epdaS_conf_stack=(edge_push y)@(drop(length(edge_pop y))(epdaS_conf_stack c))\\<rparr>\"\n      in allE)\n  apply(erule_tac\n      x=\"x\"\n      in allE)\n  apply(erule_tac\n      x=\"y\"\n      in allE)\n  apply(erule impE)\n   prefer 2\n   apply(force)\n  apply(simp add: epdaS_step_relation_def)\n  apply(case_tac c)\n  apply(rename_tac epdaS_conf_statea epdaS_conf_schedulera epdaS_conf_stacka)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac epdaS_conf_scheduler epdaS_conf_stack)(*strict*)\n  apply(simp add: prefix_def)\n  apply(clarsimp)\n  apply(rename_tac c ca cb cc)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac c ca cb cc)(*strict*)\n   apply (metis List.drop_append dropPrecise)\n  apply(rename_tac c ca cb cc)(*strict*)\n  apply (metis List.drop_append dropPrecise)\n  done\n\nlemma valid_simple_dpda_edge_alt: \"\n  valid_simple_dpda G\n  \\<Longrightarrow> x \\<in> epda_delta G\n  \\<Longrightarrow> (\\<exists>s1 s2. edge_pop x=[s1] \\<and>\n  ((edge_event x \\<noteq> None \\<and> edge_push x=[s1])\n  \\<or> (edge_event x = None \\<and> edge_push x=[s2,s1])\n  \\<or> (edge_event x = None \\<and> edge_push x=[])))\"\n  apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"x\"\n      and P=\"\\<lambda>x. length (edge_pop x) = Suc 0\"\n      in ballE)\n   prefer 2\n   apply(force)\n  apply(erule_tac\n      x=\"x\"\n      in ballE)\n   prefer 2\n   apply(force)\n  apply(case_tac \"edge_event x\")\n   apply(clarsimp)\n   apply(case_tac \"edge_pop x\")\n    apply(clarsimp)\n   apply(rename_tac a list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"edge_push x\")\n   apply(rename_tac a)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac a aa list)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma epdaS_apply_is_forward_edge_deterministic_accessibleE_with_ReachableEdge: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.is_forward_edge_deterministic_accessible G\n  \\<Longrightarrow> x \\<in> epdaS_accessible_edges G\n  \\<Longrightarrow> y \\<in> epda_delta G\n  \\<Longrightarrow> edge_src x=edge_src y\n  \\<Longrightarrow> edge_pop x = edge_pop y\n  \\<Longrightarrow> prefix (option_to_list (edge_event y)) (option_to_list (edge_event x))\n  \\<Longrightarrow> x=y\"\n  apply(simp add: epdaS_accessible_edges_def)\n  apply(clarsimp)\n  apply(rename_tac d n c)(*strict*)\n  apply(simp add: epdaS.is_forward_edge_deterministic_accessible_def)\n  apply(case_tac n)\n   apply(rename_tac d n c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d c)(*strict*)\n   apply(simp add: epdaS.derivation_initial_def epdaS_initial_configurations_def)\n  apply(rename_tac d n c nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d c nat)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d nat = Some (pair e1 c1) \\<and> d (Suc nat) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation G c1 e2 c2\")\n   apply(rename_tac d c nat)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc nat\"\n      in epdaS.step_detail_before_some_position)\n     apply(rename_tac d c nat)(*strict*)\n     apply(rule epdaS.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac d c nat)(*strict*)\n    apply(force)\n   apply(rename_tac d c nat)(*strict*)\n   apply(force)\n  apply(rename_tac d c nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d c nat e1 c1)(*strict*)\n  apply(erule_tac\n      x=\"c1\"\n      in ballE)\n   apply(rename_tac d c nat e1 c1)(*strict*)\n   apply(erule_tac\n      x=\"c\"\n      in allE)\n   apply(subgoal_tac \"\\<exists>c. epdaS_step_relation G c1 y c\")\n    apply(rename_tac d c nat e1 c1)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d c nat e1 c1)(*strict*)\n   prefer 2\n   apply(simp add: epdaS.get_accessible_configurations_def)\n   apply(erule_tac\n      x=\"d\"\n      in allE)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"nat\"\n      in allE)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d c nat e1 c1)(*strict*)\n  apply(rule_tac\n      x=\"\\<lparr>epdaS_conf_state=edge_trg y,epdaS_conf_scheduler=drop(length(option_to_list (edge_event y)))(epdaS_conf_scheduler c1),epdaS_conf_stack=(edge_push y)@(drop(length(edge_pop y))(epdaS_conf_stack c1))\\<rparr>\"\n      in exI)\n  apply(simp add: epdaS_step_relation_def prefix_def)\n  apply(clarsimp)\n  apply(rename_tac d c nat e1 c1 ca w)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(case_tac \"edge_event x\")\n   apply(rename_tac d c nat e1 c1 ca w)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d c nat e1 c1 ca w a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"edge_event y\")\n   apply(rename_tac d c nat e1 c1 ca w a)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d c nat e1 c1 ca w a aa)(*strict*)\n  apply(clarsimp)\n  done\n\ndefinition duplicate_marking :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"duplicate_marking G \\<equiv>\n  \\<exists>d. epdaS.derivation_initial G d\n  \\<and> (\\<exists>i j. d (i + j + Suc 0) \\<noteq> None\n     \\<and> epdaS_conf_state (the (get_configuration (d i))) \\<in> epda_marking G\n     \\<and> epdaS_conf_state (the (get_configuration (d (i + j + Suc 0))))\n          \\<in> epda_marking G\n     \\<and> epdaS_conf_scheduler (the (get_configuration (d i)))\n        = epdaS_conf_scheduler (the (get_configuration (d (i + j + Suc 0)))))\"\n\ndefinition duplicate_marking_ALT :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"duplicate_marking_ALT G \\<equiv>\n  \\<exists>d i j.\n    epdaS.derivation_initial G d\n    \\<and> d (i + j + Suc 0) \\<noteq> None\n    \\<and> epdaS_conf_state (the (get_configuration (d i)))\n        \\<in> epda_marking G\n    \\<and> epdaS_conf_state (the (get_configuration (d (i + j + Suc 0))))\n        \\<in> epda_marking G\n    \\<and> epdaS_conf_scheduler (the (get_configuration (d i)))\n        = epdaS_conf_scheduler (the (get_configuration (d (i + j + Suc 0))))\"\n\nlemma duplicate_marking_ALT_vs_duplicate_marking: \"\n  duplicate_marking_ALT G = duplicate_marking G\"\n  apply(simp add: duplicate_marking_ALT_def duplicate_marking_def)\n  done\n\nlemma duplicate_marking_to_duplicate_markingH: \"\n  valid_epda G\n  \\<Longrightarrow> \\<not> duplicate_marking G\n  \\<Longrightarrow> \\<not> duplicate_markingH G\"\n  apply(simp add: duplicate_marking_def duplicate_markingH_def)\n  apply(clarsimp)\n  apply(rename_tac d i j y)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d i j y)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"d\"\n      in epdaH_vs_epdaHS.Bra2LinDer_preserves_derivation)\n      apply(rename_tac d i j y)(*strict*)\n      apply(force)\n     apply(rename_tac d i j y)(*strict*)\n     apply(rule epdaH.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac d i j y)(*strict*)\n    apply(rule epdaH.derivation_initial_belongs)\n     apply(rename_tac d i j y)(*strict*)\n     apply(force)\n    apply(rename_tac d i j y)(*strict*)\n    apply(force)\n   apply(rename_tac d i j y)(*strict*)\n   apply(force)\n  apply(rename_tac d i j y)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d i j y)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"d\"\n      in epdaH_vs_epdaHS.Bra2LinDer_preserves_belongs)\n      apply(rename_tac d i j y)(*strict*)\n      apply(force)\n     apply(rename_tac d i j y)(*strict*)\n     apply(rule epdaH.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac d i j y)(*strict*)\n    apply(rule epdaH.derivation_initial_belongs)\n     apply(rename_tac d i j y)(*strict*)\n     apply(force)\n    apply(rename_tac d i j y)(*strict*)\n    apply(force)\n   apply(rename_tac d i j y)(*strict*)\n   apply(force)\n  apply(rename_tac d i j y)(*strict*)\n  apply(subgoal_tac \"epdaS.derivation_initial G (epdaHS2epdaS_derivation (epdaH_vs_epdaHS.Bra2LinDer G d (Suc (i + j))))\")\n   apply(rename_tac d i j y)(*strict*)\n   prefer 2\n   apply(rule epdaHS2epdaS_derivation_preserves_derivation_initial)\n    apply(rename_tac d i j y)(*strict*)\n    apply(force)\n   apply(rename_tac d i j y)(*strict*)\n   apply(rule epdaHS.derivation_initialI)\n    apply(rename_tac d i j y)(*strict*)\n    apply(force)\n   apply(rename_tac d i j y)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i j y c)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(subgoal_tac \"c \\<in> epdaHS_configurations G\")\n    apply(rename_tac d i j y c)(*strict*)\n    prefer 2\n    apply(rule epdaHS.belongs_configurations)\n     apply(rename_tac d i j y c)(*strict*)\n     apply(force)\n    apply(rename_tac d i j y c)(*strict*)\n    apply(force)\n   apply(rename_tac d i j y c)(*strict*)\n   apply(simp add: epdaH_vs_epdaHS.Bra2LinDer_def)\n   apply(case_tac y)\n   apply(rename_tac d i j y c option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i j c option b)(*strict*)\n   apply(case_tac \"d 0\")\n    apply(rename_tac d i j c option b)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d i j c option b a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac d i j c option b a optiona ba)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i j option b ba)(*strict*)\n   apply(simp add: epdaHvHS_Bra2LinConf_def)\n   apply(simp add: epdaH_vs_epdaHS.Bra2LinDer'_def)\n   apply(simp add: epdaHS_initial_configurations_def)\n   apply(simp add: epdaH.derivation_initial_def)\n   apply(clarsimp)\n   apply(simp add: epdaH_initial_configurations_def)\n  apply(rename_tac d i j y)(*strict*)\n  apply(erule_tac\n      x=\"(epdaHS2epdaS_derivation (epdaH_vs_epdaHS.Bra2LinDer G d (Suc (i + j))))\"\n      in allE)\n  apply(rename_tac d i j y)(*strict*)\n  apply(erule impE)\n   apply(rename_tac d i j y)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d i j y)(*strict*)\n  apply(erule_tac\n      x=\"i\"\n      in allE)\n  apply(erule_tac\n      x=\"j\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac d i j y)(*strict*)\n   apply(simp add: epdaHvHS_Bra2LinConf_def epdaH_vs_epdaHS.Bra2LinDer_def get_configuration_def epdaHS2epdaS_derivation_def epdaH_vs_epdaHS.Bra2LinDer'_def)\n   apply(case_tac y)\n   apply(rename_tac d i j y option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i j option b)(*strict*)\n   apply(simp add: epdaHvHS_Bra2LinConf_def epdaH_vs_epdaHS.Bra2LinDer_def get_configuration_def epdaHS2epdaS_derivation_def epdaH_vs_epdaHS.Bra2LinDer'_def get_configuration_def)\n  apply(rename_tac d i j y)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d i = Some (pair e c)\")\n   apply(rename_tac d i j y)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc (i+j)\"\n      in epdaH.pre_some_position_is_some_position)\n     apply(rename_tac d i j y)(*strict*)\n     apply(rule epdaH.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac d i j y)(*strict*)\n    apply(force)\n   apply(rename_tac d i j y)(*strict*)\n   apply(force)\n  apply(rename_tac d i j y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i j y e c)(*strict*)\n  apply(erule impE)\n   apply(rename_tac d i j y e c)(*strict*)\n   apply(simp add: epdaHvHS_Bra2LinConf_def epdaH_vs_epdaHS.Bra2LinDer_def get_configuration_def epdaHS2epdaS_derivation_def epdaH_vs_epdaHS.Bra2LinDer'_def)\n   apply(case_tac y)\n   apply(rename_tac d i j y e c option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i j e c option b)(*strict*)\n   apply(simp add: epdaHvHS_Bra2LinConf_def epdaH_vs_epdaHS.Bra2LinDer_def get_configuration_def epdaHS2epdaS_derivation_def epdaH_vs_epdaHS.Bra2LinDer'_def get_configuration_def)\n  apply(rename_tac d i j y e c)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac d i j y e c)(*strict*)\n   apply(simp add: epdaHvHS_Bra2LinConf_def epdaH_vs_epdaHS.Bra2LinDer_def get_configuration_def epdaHS2epdaS_derivation_def epdaH_vs_epdaHS.Bra2LinDer'_def)\n   apply(case_tac y)\n   apply(rename_tac d i j y e c option b)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d i j y e c)(*strict*)\n  apply(simp add: epdaHvHS_Bra2LinConf_def epdaH_vs_epdaHS.Bra2LinDer_def get_configuration_def epdaHS2epdaS_derivation_def epdaH_vs_epdaHS.Bra2LinDer'_def)\n  apply(case_tac y)\n  apply(rename_tac d i j y e c option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i j e c option b)(*strict*)\n  apply(simp add: epdaHvHS_Bra2LinConf_def epdaH_vs_epdaHS.Bra2LinDer_def get_configuration_def epdaHS2epdaS_derivation_def epdaH_vs_epdaHS.Bra2LinDer'_def get_configuration_def)\n  apply(subgoal_tac \"nat_seq (Suc (i + j)) (i + j)=[]\")\n   apply(rename_tac d i j e c option b)(*strict*)\n   prefer 2\n   apply (metis lessI nat_seqEmpty)\n  apply(rename_tac d i j e c option b)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"foldl (@) [] (map (\\<lambda>n. case_option undefined (case_derivation_configuration (\\<lambda>e1 c1. case_option undefined (case_derivation_configuration (\\<lambda>a c2. case a of Some e2 \\<Rightarrow> epdaHvHS_Bra2LinStep c1 e2 c2)) (d (Suc n)))) (d n)) (nat_seq i (i + j)))=[]\")\n   apply(rename_tac d i j e c option b)(*strict*)\n   apply(force)\n  apply(rename_tac d i j e c option b)(*strict*)\n  apply(rule foldl_empty)\n  apply(rename_tac d i j e c option b a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i j e c option b n)(*strict*)\n  apply(subgoal_tac \"i\\<le>n \\<and> n\\<le> i+j\")\n   apply(rename_tac d i j e c option b n)(*strict*)\n   prefer 2\n   apply (metis nat_seq_in_interval)\n  apply(rename_tac d i j e c option b n)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d n = Some (pair e1 c1) \\<and> d (Suc n) = Some (pair (Some e2) c2) \\<and> epdaH_step_relation G c1 e2 c2\")\n   apply(rename_tac d i j e c option b n)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc (i+j)\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac d i j e c option b n)(*strict*)\n     apply(rule epdaH.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac d i j e c option b n)(*strict*)\n    apply(force)\n   apply(rename_tac d i j e c option b n)(*strict*)\n   apply(force)\n  apply(rename_tac d i j e c option b n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n  apply(simp add: epdaHvHS_Bra2LinStep_def)\n  apply(subgoal_tac \"\\<exists>h\\<in> epda_effects G. epdaH_conf_history SSc' = epdaH_conf_history SSc @ h\" for SSc' SSc)\n   apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"d\"\n      and n=\"i\"\n      and m=\"n-i\"\n      in epdaH.steps_extend_history_derivation)\n       apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n       apply(force)\n      apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n      apply(rule epdaH.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n     prefer 2\n     apply(simp add: get_configuration_def)\n    apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n    apply(rule epdaH.belongs_configurations)\n     apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n      apply(force)\n     apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n     apply(force)\n    apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n  apply(subgoal_tac \"\\<exists>h\\<in> epda_effects G. epdaH_conf_history SSc' = epdaH_conf_history SSc @ h\" for SSc' SSc)\n   apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"d\"\n      and n=\"n\"\n      and m=\"Suc 0\"\n      in epdaH.steps_extend_history_derivation)\n       apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n       apply(force)\n      apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n      apply(rule epdaH.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n     prefer 2\n     apply(simp add: get_configuration_def)\n    apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n    apply(rule epdaH.belongs_configurations)\n     apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n      apply(force)\n     apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n     apply(force)\n    apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n  apply(subgoal_tac \"\\<exists>h\\<in> epda_effects G. epdaH_conf_history SSc' = epdaH_conf_history SSc @ h\" for SSc' SSc)\n   apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"d\"\n      and n=\"Suc n\"\n      and m=\"(i+j) - n\"\n      in epdaH.steps_extend_history_derivation)\n       apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n       apply(force)\n      apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n      apply(rule epdaH.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n     prefer 2\n     apply(simp add: get_configuration_def)\n    apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n    apply(rule epdaH.belongs_configurations)\n     apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n      apply(force)\n     apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n     apply(force)\n    apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n  apply(erule bexE)+\n  apply(rename_tac d i j e c option b n e1 e2 c1 c2 h ha hb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i j e c option b n e1 e2 c1 c2)(*strict*)\n  apply(simp add: epda_effects_def)\n  apply(simp add: epdaH_step_relation_def)\n  done\n\nlemma equal_configurations_at_identical_position_in_marking_derivations: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.is_forward_edge_deterministic_accessible G\n  \\<Longrightarrow> \\<not> duplicate_markingH G\n  \\<Longrightarrow> epdaH.derivation_initial G d1\n  \\<Longrightarrow> epdaH.derivation_initial G d2\n  \\<Longrightarrow> maximum_of_domain d2 m2\n  \\<Longrightarrow> d2 m2 = Some (pair e2' c2')\n  \\<Longrightarrow> c2' \\<in> epdaH_marking_configurations G\n  \\<Longrightarrow> d1 n1 = Some (pair e1 c)\n  \\<Longrightarrow> d2 n2 = Some (pair e2 c)\n  \\<Longrightarrow> n1\\<le>n2\n  \\<Longrightarrow> n1=n2\"\n  apply(subgoal_tac \"d1 n1=d2 n1\")\n   prefer 2\n   apply(rule_tac\n      ?n1.0=\"n1\"\n      and ?n.0=\"n2-n1\"\n      in EDPDA_derivations_coincide)\n          apply(force)\n         apply(force)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(clarsimp)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(thin_tac \"epdaH.derivation_initial G d1\")\n  apply(thin_tac \"d1 n1 = Some (pair e1 c)\")\n  apply(subgoal_tac \"\\<exists>n. n1+n=n2\")\n   prefer 2\n   apply(rule_tac\n      x=\"n2-n1\"\n      in exI)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac n)(*strict*)\n  apply(subgoal_tac \"n1+n\\<le>m2\")\n   apply(rename_tac n)(*strict*)\n   prefer 2\n   apply (metis epdaH.allPreMaxDomSome_prime epdaH.derivation_initial_is_derivation not_None_eq)\n  apply(rename_tac n)(*strict*)\n  apply(subgoal_tac \"\\<exists>m. n1+n+m=m2\")\n   apply(rename_tac n)(*strict*)\n   prefer 2\n   apply(rule_tac\n      x=\"m2-n1-n\"\n      in exI)\n   apply(force)\n  apply(rename_tac n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n m)(*strict*)\n  apply(case_tac m)\n   apply(rename_tac n m)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n)(*strict*)\n   apply(case_tac n)\n    apply(rename_tac n)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac n nat)(*strict*)\n   apply(simp add: duplicate_markingH_def)\n   apply(erule_tac\n      x=\"d2\"\n      in allE)\n   apply(clarsimp)\n   apply(rename_tac nat)(*strict*)\n   apply(erule_tac\n      x=\"n1\"\n      in allE)\n   apply(erule_tac\n      x=\"nat\"\n      in allE)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n   apply(simp add: epdaH_marking_configurations_def)\n  apply(rename_tac n m nat)(*strict*)\n  apply(subgoal_tac \" n1+m=n1+n+m \\<and> (\\<forall>i\\<le>n1+m. (derivation_append (derivation_take d2 n1) (derivation_drop d2 (n1+n)) n1) i = d2 i)\")\n   apply(rename_tac n m nat)(*strict*)\n   apply(force)\n  apply(rename_tac n m nat)(*strict*)\n  apply(rule_tac\n      ?e1.0=\"e2'\"\n      and ?c1.0=\"c2'\"\n      in EDPDA_derivations_coincide5)\n           apply(rename_tac n m nat)(*strict*)\n           apply(force)\n          apply(rename_tac n m nat)(*strict*)\n          apply(force)\n         apply(rename_tac n m nat)(*strict*)\n         apply(force)\n        apply(rename_tac n m nat)(*strict*)\n        apply(rule epdaH.derivation_append_preserves_derivation_initial)\n          apply(rename_tac n m nat)(*strict*)\n          apply(force)\n         apply(rename_tac n m nat)(*strict*)\n         apply(rule epdaH.derivation_take_preserves_derivation_initial)\n         apply(force)\n        apply(rename_tac n m nat)(*strict*)\n        apply(rule epdaH.derivation_append_preserves_derivation)\n          apply(rename_tac n m nat)(*strict*)\n          apply(rule epdaH.derivation_take_preserves_derivation)\n          apply(rule epdaH.derivation_initial_is_derivation)\n          apply(force)\n         apply(rename_tac n m nat)(*strict*)\n         apply(rule_tac\n      m=\"m\"\n      in epdaH.derivation_drop_preserves_derivation)\n          apply(rename_tac n m nat)(*strict*)\n          apply(rule epdaH.derivation_initial_is_derivation)\n          apply(force)\n         apply(rename_tac n m nat)(*strict*)\n         apply(clarsimp)\n        apply(rename_tac n m nat)(*strict*)\n        apply(simp add: derivation_take_def derivation_drop_def)\n       apply(rename_tac n m nat)(*strict*)\n       apply(force)\n      apply(rename_tac n m nat)(*strict*)\n      apply(simp add: derivation_append_def derivation_take_def derivation_drop_def)\n      apply(clarsimp)\n      apply(rename_tac n nat)(*strict*)\n      apply(rule_tac\n      t=\"Suc (nat + (n1 + n))\"\n      and s=\"Suc (n1 + n + nat)\"\n      in ssubst)\n       apply(rename_tac n nat)(*strict*)\n       apply(force)\n      apply(rename_tac n nat)(*strict*)\n      apply(force)\n     apply(rename_tac n m nat)(*strict*)\n     apply(force)\n    apply(rename_tac n m nat)(*strict*)\n    apply(force)\n   apply(rename_tac n m nat)(*strict*)\n   apply(force)\n  apply(rename_tac n m nat)(*strict*)\n  apply(force)\n  done\n\ndefinition every_state_in_some_accessible_configuration :: \"('q,'a,'b)epda \\<Rightarrow> bool\" where\n  \"every_state_in_some_accessible_configuration G = (\\<forall>q\\<in> epda_states G. \\<forall>w. set w \\<subseteq> epda_events G \\<longrightarrow> \\<lparr>epdaS_conf_state=q,epdaS_conf_scheduler=w,epdaS_conf_stack=[epda_box G]\\<rparr>\\<in> epdaS.get_accessible_configurations G)\"\n\ndefinition every_state_in_some_accessible_configurationEx :: \"('q,'a,'b)epda \\<Rightarrow> bool\" where\n  \"every_state_in_some_accessible_configurationEx G = (\\<forall>q\\<in> epda_states G. \\<exists>w. set w \\<subseteq> epda_events G \\<and> \\<lparr>epdaS_conf_state=q,epdaS_conf_scheduler=w,epdaS_conf_stack=[epda_box G]\\<rparr>\\<in> epdaS.get_accessible_configurations G)\"\n\nlemma epda_input_replacement_preserves_derivation: \"\n  valid_epda G\n  \\<Longrightarrow> set w \\<subseteq> epda_events G\n  \\<Longrightarrow> set wa \\<subseteq> epda_events G\n  \\<Longrightarrow> epdaS.derivation_initial G d\n  \\<Longrightarrow> d i = Some (derivation_configuration.pair e \\<lparr>epdaS_conf_state = q, epdaS_conf_scheduler = wa, epdaS_conf_stack = s\\<rparr>)\n  \\<Longrightarrow> d 0 = Some (pair None c)\n  \\<Longrightarrow> epdaS_conf_scheduler c = wb @ wa\n  \\<Longrightarrow> epdaS.derivation G (derivation_map (derivation_take d i) (\\<lambda>c. c\\<lparr>epdaS_conf_scheduler := the (right_quotient_word (epdaS_conf_scheduler c) wa) @ w\\<rparr>))\"\n  apply(induct i arbitrary: e q wa wb s)\n   apply(rename_tac e q wa wb s)(*strict*)\n   apply(simp add: epdaS.derivation_def)\n   apply(clarsimp)\n   apply(rename_tac q wa s i)(*strict*)\n   apply(case_tac i)\n    apply(rename_tac q wa s i)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q wa s)(*strict*)\n    apply(simp add: derivation_map_def derivation_take_def)\n   apply(rename_tac q wa s i nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac q wa s nat)(*strict*)\n   apply(simp add: derivation_map_def derivation_take_def)\n  apply(rename_tac i e q wa wb s)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d i = Some (pair e1 c1) \\<and> d (Suc i) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation G c1 e2 c2\")\n   apply(rename_tac i e q wa wb s)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc i\"\n      in epdaS.step_detail_before_some_position)\n     apply(rename_tac i e q wa wb s)(*strict*)\n     apply(rule epdaS.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac i e q wa wb s)(*strict*)\n    apply(force)\n   apply(rename_tac i e q wa wb s)(*strict*)\n   apply(force)\n  apply(rename_tac i e q wa wb s)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i q wa wb s e1 e2 c1)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. epdaS_string_state c = w @ epdaS_string_state c1\")\n   apply(rename_tac i q wa wb s e1 e2 c1)(*strict*)\n   prefer 2\n   apply(rule epdaS.derivation_monotonically_dec)\n        apply(rename_tac i q wa wb s e1 e2 c1)(*strict*)\n        apply(force)\n       apply(rename_tac i q wa wb s e1 e2 c1)(*strict*)\n       apply(force)\n      apply(rename_tac i q wa wb s e1 e2 c1)(*strict*)\n      apply(rule epdaS.derivation_initial_belongs)\n       apply(rename_tac i q wa wb s e1 e2 c1)(*strict*)\n       apply(force)\n      apply(rename_tac i q wa wb s e1 e2 c1)(*strict*)\n      apply(force)\n     apply(rename_tac i q wa wb s e1 e2 c1)(*strict*)\n     apply(rule epdaS.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac i q wa wb s e1 e2 c1)(*strict*)\n    apply(force)\n   apply(rename_tac i q wa wb s e1 e2 c1)(*strict*)\n   apply(force)\n  apply(rename_tac i q wa wb s e1 e2 c1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i q wa wb s e1 e2 c1 wc)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. epdaS_string_state c1 = w @ epdaS_string_state \\<lparr>epdaS_conf_state = q, epdaS_conf_scheduler = wa, epdaS_conf_stack = s\\<rparr>\")\n   apply(rename_tac i q wa wb s e1 e2 c1 wc)(*strict*)\n   prefer 2\n   apply(rule_tac\n      i=\"i\"\n      and j=\"Suc 0\"\n      in epdaS.derivation_monotonically_dec)\n        apply(rename_tac i q wa wb s e1 e2 c1 wc)(*strict*)\n        apply(force)\n       apply(rename_tac i q wa wb s e1 e2 c1 wc)(*strict*)\n       apply(force)\n      apply(rename_tac i q wa wb s e1 e2 c1 wc)(*strict*)\n      apply(rule epdaS.derivation_initial_belongs)\n       apply(rename_tac i q wa wb s e1 e2 c1 wc)(*strict*)\n       apply(force)\n      apply(rename_tac i q wa wb s e1 e2 c1 wc)(*strict*)\n      apply(force)\n     apply(rename_tac i q wa wb s e1 e2 c1 wc)(*strict*)\n     apply(rule epdaS.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac i q wa wb s e1 e2 c1 wc)(*strict*)\n    apply(force)\n   apply(rename_tac i q wa wb s e1 e2 c1 wc)(*strict*)\n   apply(force)\n  apply(rename_tac i q wa wb s e1 e2 c1 wc)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i q wa wb s e1 e2 c1 wc wca)(*strict*)\n  apply(simp add: epdaS_string_state_def)\n  apply(clarsimp)\n  apply(rename_tac i q wa s e1 e2 c1 wb wc)(*strict*)\n  apply(erule_tac\n      x=\"e1\"\n      in meta_allE)\n  apply(erule_tac\n      x=\"epdaS_conf_state c1\"\n      in meta_allE)\n  apply(erule_tac\n      x=\"epdaS_conf_scheduler c1\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"wb\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"epdaS_conf_stack c1\"\n      in meta_allE)\n  apply(erule meta_impE)\n   apply(rename_tac i q wa s e1 e2 c1 wb wc)(*strict*)\n   apply(subgoal_tac \"c1 \\<in> epdaS_configurations G\")\n    apply(rename_tac i q wa s e1 e2 c1 wb wc)(*strict*)\n    apply(simp add: epdaS_configurations_def)\n    apply(clarsimp)\n    apply(rename_tac i q wa s e1 e2 wb wc x qa sa)(*strict*)\n    apply(force)\n   apply(rename_tac i q wa s e1 e2 c1 wb wc)(*strict*)\n   apply(rule epdaS.belongs_configurations)\n    apply(rename_tac i q wa s e1 e2 c1 wb wc)(*strict*)\n    apply(rule epdaS.derivation_initial_belongs)\n     apply(rename_tac i q wa s e1 e2 c1 wb wc)(*strict*)\n     apply(force)\n    apply(rename_tac i q wa s e1 e2 c1 wb wc)(*strict*)\n    apply(force)\n   apply(rename_tac i q wa s e1 e2 c1 wb wc)(*strict*)\n   apply(force)\n  apply(rename_tac i q wa s e1 e2 c1 wb wc)(*strict*)\n  apply(clarsimp)\n  apply(simp add: epdaS.derivation_def)\n  apply(clarsimp)\n  apply(rename_tac i q wa s e1 e2 c1 wb wc ia)(*strict*)\n  apply(case_tac \"ia\\<le>i\")\n   apply(rename_tac i q wa s e1 e2 c1 wb wc ia)(*strict*)\n   apply(erule_tac\n      x=\"ia\"\n      in allE)\n   apply(case_tac ia)\n    apply(rename_tac i q wa s e1 e2 c1 wb wc ia)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i q wa s e1 e2 c1 wb wc)(*strict*)\n    apply(simp add: derivation_map_def derivation_take_def)\n   apply(rename_tac i q wa s e1 e2 c1 wb wc ia nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i q wa s e1 e2 c1 wb wc nat)(*strict*)\n   apply(case_tac \"d (Suc nat)\")\n    apply(rename_tac i q wa s e1 e2 c1 wb wc nat)(*strict*)\n    apply(simp add: derivation_map_def derivation_take_def)\n   apply(rename_tac i q wa s e1 e2 c1 wb wc nat a)(*strict*)\n   apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d nat = Some (pair e1 c1) \\<and> d (Suc nat) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation G c1 e2 c2\")\n    apply(rename_tac i q wa s e1 e2 c1 wb wc nat a)(*strict*)\n    prefer 2\n    apply(rule_tac\n      m=\"Suc nat\"\n      in epdaS.step_detail_before_some_position)\n      apply(rename_tac i q wa s e1 e2 c1 wb wc nat a)(*strict*)\n      apply(rule epdaS.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac i q wa s e1 e2 c1 wb wc nat a)(*strict*)\n     apply(force)\n    apply(rename_tac i q wa s e1 e2 c1 wb wc nat a)(*strict*)\n    apply(force)\n   apply(rename_tac i q wa s e1 e2 c1 wb wc nat a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2)(*strict*)\n   apply(simp add: derivation_map_def derivation_take_def)\n   apply(subgoal_tac \"\\<exists>w. epdaS_string_state c1a = w @ epdaS_string_state c2\")\n    apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2)(*strict*)\n    prefer 2\n    apply(rule_tac\n      i=\"nat\"\n      and j=\"Suc 0\"\n      in epdaS.derivation_monotonically_dec)\n         apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2)(*strict*)\n         apply(force)\n        apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2)(*strict*)\n        apply(force)\n       apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2)(*strict*)\n       apply(rule epdaS.derivation_initial_belongs)\n        apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2)(*strict*)\n        apply(force)\n       apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2)(*strict*)\n       apply(force)\n      apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2)(*strict*)\n      apply(rule epdaS.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2)(*strict*)\n     apply(force)\n    apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2)(*strict*)\n    apply(force)\n   apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba)(*strict*)\n   apply(simp add: epdaS_string_state_def)\n   apply(subgoal_tac \"\\<exists>w. epdaS_string_state c = w @ epdaS_string_state c1a\")\n    apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba)(*strict*)\n    prefer 2\n    apply(rule_tac\n      i=\"0\"\n      and j=\"nat\"\n      in epdaS.derivation_monotonically_dec)\n         apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba)(*strict*)\n         apply(force)\n        apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba)(*strict*)\n        apply(force)\n       apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba)(*strict*)\n       apply(rule epdaS.derivation_initial_belongs)\n        apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba)(*strict*)\n        apply(force)\n       apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba)(*strict*)\n       apply(force)\n      apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba)(*strict*)\n      apply(rule epdaS.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba)(*strict*)\n     apply(force)\n    apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba)(*strict*)\n    apply(force)\n   apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd)(*strict*)\n   apply(simp add: epdaS_string_state_def)\n   apply(subgoal_tac \"\\<exists>w. epdaS_string_state c2 = w @ epdaS_string_state c1\")\n    apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd)(*strict*)\n    prefer 2\n    apply(rule_tac\n      i=\"Suc nat\"\n      and j=\"i-Suc nat\"\n      in epdaS.derivation_monotonically_dec)\n         apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd)(*strict*)\n         apply(force)\n        apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd)(*strict*)\n        apply(force)\n       apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd)(*strict*)\n       apply(rule epdaS.derivation_initial_belongs)\n        apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd)(*strict*)\n        apply(force)\n       apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd)(*strict*)\n       apply(force)\n      apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd)(*strict*)\n      apply(rule epdaS.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd)(*strict*)\n     apply(force)\n    apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd)(*strict*)\n    apply(force)\n   apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd we)(*strict*)\n   apply(simp add: epdaS_string_state_def)\n   apply(subgoal_tac \"right_quotient_word (wba @ we @ wc @ wa) wa = Some(wba @ we @ wc)\")\n    apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd we)(*strict*)\n    prefer 2\n    apply(rule_tac\n      t=\"wba @ we @ wc @ wa\"\n      and s=\"(wba @ we @ wc) @ wa\"\n      in ssubst)\n     apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd we)(*strict*)\n     apply(force)\n    apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd we)(*strict*)\n    apply (metis right_quotient_word_removes_right_addition)\n   apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd we)(*strict*)\n   apply(subgoal_tac \"right_quotient_word (we @ wc @ wa) wa = Some(we @ wc)\")\n    apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd we)(*strict*)\n    prefer 2\n    apply(rule_tac\n      t=\"we @ wc @ wa\"\n      and s=\"(we @ wc) @ wa\"\n      in ssubst)\n     apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd we)(*strict*)\n     apply(force)\n    apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd we)(*strict*)\n    apply (metis right_quotient_word_removes_right_addition)\n   apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd we)(*strict*)\n   apply(subgoal_tac \"right_quotient_word (wba @ we @ wc @ wa) (wc@wa) = Some(wba @ we)\")\n    apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd we)(*strict*)\n    prefer 2\n    apply(rule_tac\n      t=\"wba @ we @ wc @ wa\"\n      and s=\"(wba @ we) @ (wc @ wa)\"\n      in ssubst)\n     apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd we)(*strict*)\n     apply(force)\n    apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd we)(*strict*)\n    apply (metis right_quotient_word_removes_right_addition)\n   apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd we)(*strict*)\n   apply(subgoal_tac \"right_quotient_word (we @ wc @ wa) (wc@wa) = Some we\")\n    apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd we)(*strict*)\n    prefer 2\n    apply(rule_tac\n      t=\"we @ wc @ wa\"\n      and s=\"we @ (wc @ wa)\"\n      in ssubst)\n     apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd we)(*strict*)\n     apply(force)\n    apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd we)(*strict*)\n    apply (metis right_quotient_word_removes_right_addition)\n   apply(rename_tac i q wa s e1 e2 c1 wb wc nat e1a e2a c1a c2 wba wd we)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i q wa s e1 e2 c1 wc nat e1a e2a c1a c2 wb wd we)(*strict*)\n   apply(simp add: epdaS_step_relation_def)\n  apply(rename_tac i q wa s e1 e2 c1 wb wc ia)(*strict*)\n  apply(thin_tac \"\\<forall>ia. case ia of 0 \\<Rightarrow> (case derivation_map (derivation_take d i) (\\<lambda>c. c\\<lparr>epdaS_conf_scheduler := the (right_quotient_word (epdaS_conf_scheduler c) (wc @ wa)) @ w\\<rparr>) 0 of None \\<Rightarrow> False | Some (pair None c) \\<Rightarrow> True | Some (pair (Some e) c) \\<Rightarrow> False) | Suc i' \\<Rightarrow> (case derivation_map (derivation_take d i) (\\<lambda>c. c\\<lparr>epdaS_conf_scheduler := the (right_quotient_word (epdaS_conf_scheduler c) (wc @ wa)) @ w\\<rparr>) ia of None \\<Rightarrow> True | Some (pair i1 i2) \\<Rightarrow> (case derivation_map (derivation_take d i) (\\<lambda>c. c\\<lparr>epdaS_conf_scheduler := the (right_quotient_word (epdaS_conf_scheduler c) (wc @ wa)) @ w\\<rparr>) i' of None \\<Rightarrow> False | Some (pair i'1 i'2) \\<Rightarrow> (case i1 of None \\<Rightarrow> False | Some i1v \\<Rightarrow> epdaS_step_relation G i'2 i1v i2)))\")\n  apply(rename_tac i q wa s e1 e2 c1 wb wc ia)(*strict*)\n  apply(case_tac \"ia\")\n   apply(rename_tac i q wa s e1 e2 c1 wb wc ia)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac i q wa s e1 e2 c1 wb wc ia nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i q wa s e1 e2 c1 wb wc nat)(*strict*)\n  apply(case_tac \"d (Suc nat)\")\n   apply(rename_tac i q wa s e1 e2 c1 wb wc nat)(*strict*)\n   apply(simp add: derivation_map_def derivation_take_def)\n  apply(rename_tac i q wa s e1 e2 c1 wb wc nat a)(*strict*)\n  apply(case_tac \"Suc nat > Suc i\")\n   apply(rename_tac i q wa s e1 e2 c1 wb wc nat a)(*strict*)\n   apply(simp add: derivation_map_def derivation_take_def)\n  apply(rename_tac i q wa s e1 e2 c1 wb wc nat a)(*strict*)\n  apply(subgoal_tac \"nat=i\")\n   apply(rename_tac i q wa s e1 e2 c1 wb wc nat a)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac i q wa s e1 e2 c1 wb wc nat a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i q wa s e1 e2 c1 wb wc)(*strict*)\n  apply(simp add: derivation_map_def derivation_take_def)\n  apply(subgoal_tac \"right_quotient_word (wc @ wa) wa = Some wc\")\n   apply(rename_tac i q wa s e1 e2 c1 wb wc)(*strict*)\n   prefer 2\n   apply (metis right_quotient_word_removes_right_addition)\n  apply(rename_tac i q wa s e1 e2 c1 wb wc)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"right_quotient_word wa wa = Some []\")\n   apply(rename_tac i q wa s e1 e2 c1 wb wc)(*strict*)\n   prefer 2\n   apply (metis right_quotient_word_full)\n  apply(rename_tac i q wa s e1 e2 c1 wb wc)(*strict*)\n  apply(clarsimp)\n  apply(simp add: epdaS_step_relation_def)\n  done\n\nlemma epda_input_replacement_preserves_derivation_initial: \"\n  valid_epda G\n  \\<Longrightarrow> set w \\<subseteq> epda_events G\n  \\<Longrightarrow> set wa \\<subseteq> epda_events G\n  \\<Longrightarrow> epdaS.derivation_initial G d\n  \\<Longrightarrow> d i = Some (pair e \\<lparr>epdaS_conf_state = q, epdaS_conf_scheduler = wa, epdaS_conf_stack = [epda_box G]\\<rparr>)\n  \\<Longrightarrow> d 0 = Some (pair None c)\n  \\<Longrightarrow> epdaS_conf_scheduler c = wb @ wa\n  \\<Longrightarrow> epdaS.derivation_initial G (derivation_map (derivation_take d i) (\\<lambda>c. c\\<lparr>epdaS_conf_scheduler := the (right_quotient_word (epdaS_conf_scheduler c) wa) @ w\\<rparr>))\"\n  apply(simp (no_asm) add: epdaS.derivation_initial_def)\n  apply(rule conjI)\n   prefer 2\n   apply(simp add: epdaS.derivation_initial_def)\n   apply(simp add: derivation_map_def)\n   apply(simp add: derivation_take_def)\n   apply(clarsimp)\n   apply(simp add: epdaS_initial_configurations_def epdaS_configurations_def)\n   apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   apply(subgoal_tac \"right_quotient_word (wb @ wa) wa = Some wb\")\n    apply(rename_tac x)(*strict*)\n    prefer 2\n    apply (metis right_quotient_word_removes_right_addition)\n   apply(rename_tac x)(*strict*)\n   apply(force)\n  apply(rule epda_input_replacement_preserves_derivation)\n        apply(force)+\n  done\n\nlemma DFA_Connected_from_ConnectedEx: \"\n  valid_dfa G\n  \\<Longrightarrow> every_state_in_some_accessible_configurationEx G\n  \\<Longrightarrow> every_state_in_some_accessible_configuration G\"\n  apply(simp add: every_state_in_some_accessible_configurationEx_def)\n  apply(simp add: every_state_in_some_accessible_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac q w)(*strict*)\n  apply(erule_tac\n      x=\"q\"\n      in ballE)\n   apply(rename_tac q w)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac q w wa)(*strict*)\n   prefer 2\n   apply(rename_tac q w)(*strict*)\n   apply(force)\n  apply(rename_tac q w wa)(*strict*)\n  apply(simp add: epdaS.get_accessible_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac q w wa d i)(*strict*)\n  apply(case_tac \"d i\")\n   apply(rename_tac q w wa d i)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac q w wa d i a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac q w wa d i a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac q w wa d i option b)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac q w wa d i option)(*strict*)\n  apply(fold get_configuration_def)\n  apply(rename_tac e)\n  apply(rename_tac q w wa d i e)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. d 0 = Some (pair None c)\")\n   apply(rename_tac q w wa d i e)(*strict*)\n   prefer 2\n   apply(rule epdaS.some_position_has_details_at_0)\n   apply(rule epdaS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac q w wa d i e)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac q w wa d i e c)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. epdaS_string_state c = w @ epdaS_string_state \\<lparr>epdaS_conf_state = q, epdaS_conf_scheduler = wa, epdaS_conf_stack = [epda_box G]\\<rparr>\")\n   apply(rename_tac q w wa d i e c)(*strict*)\n   prefer 2\n   apply(rule epdaS.derivation_monotonically_dec)\n        apply(rename_tac q w wa d i e c)(*strict*)\n        apply(simp add: valid_dfa_def valid_dpda_def valid_pda_def)\n        apply(force)\n       apply(rename_tac q w wa d i e c)(*strict*)\n       apply(force)\n      apply(rename_tac q w wa d i e c)(*strict*)\n      apply(rule epdaS.derivation_initial_belongs)\n       apply(rename_tac q w wa d i e c)(*strict*)\n       apply(simp add: valid_dfa_def valid_dpda_def valid_pda_def)\n      apply(rename_tac q w wa d i e c)(*strict*)\n      apply(force)\n     apply(rename_tac q w wa d i e c)(*strict*)\n     apply(rule epdaS.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac q w wa d i e c)(*strict*)\n    apply(force)\n   apply(rename_tac q w wa d i e c)(*strict*)\n   apply(force)\n  apply(rename_tac q w wa d i e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac q w wa d i e c wb)(*strict*)\n  apply(simp add: epdaS_string_state_def)\n  apply(rule_tac\n      x=\"derivation_map (derivation_take d i) (\\<lambda>c. c\\<lparr>epdaS_conf_scheduler:=the(right_quotient_word (epdaS_conf_scheduler c) wa) @ w\\<rparr>)\"\n      in exI)\n  apply(rule context_conjI)\n   apply(rename_tac q w wa d i e c wb)(*strict*)\n   apply(rule epda_input_replacement_preserves_derivation_initial)\n         apply(rename_tac q w wa d i e c wb)(*strict*)\n         apply(simp add: valid_dfa_def valid_dpda_def valid_pda_def)\n        apply(rename_tac q w wa d i e c wb)(*strict*)\n        apply(force)\n       apply(rename_tac q w wa d i e c wb)(*strict*)\n       apply(force)\n      apply(rename_tac q w wa d i e c wb)(*strict*)\n      apply(force)\n     apply(rename_tac q w wa d i e c wb)(*strict*)\n     apply(force)\n    apply(rename_tac q w wa d i e c wb)(*strict*)\n    apply(force)\n   apply(rename_tac q w wa d i e c wb)(*strict*)\n   apply(force)\n  apply(rename_tac q w wa d i e c wb)(*strict*)\n  apply(rule_tac\n      x=\"i\"\n      in exI)\n  apply(simp add: get_configuration_def derivation_map_def derivation_take_def)\n  apply (metis right_quotient_word_full option.sel)\n  done\n\nlemma DFA_not_none_read: \"\n  valid_dfa M\n  \\<Longrightarrow> e \\<in> epda_delta M\n  \\<Longrightarrow> edge_event e \\<noteq> None\"\n  apply(simp add: valid_dfa_def)\n  done\n\nlemma DFA_push_pop_eq: \"\n  valid_dfa M\n  \\<Longrightarrow> e \\<in> epda_delta M\n  \\<Longrightarrow> edge_push e = edge_pop e\"\n  apply(simp add: valid_dfa_def)\n  done\n\nlemma DFA_derivation_input_restriction_still_simulates: \"\n  valid_dfa M\n  \\<Longrightarrow> epdaS.derivation M d1\n  \\<Longrightarrow> epdaS.derivation M d2\n  \\<Longrightarrow> every_state_in_some_accessible_configuration M\n  \\<Longrightarrow> maximum_of_domain d1 n1\n  \\<Longrightarrow> maximum_of_domain d2 n2\n  \\<Longrightarrow> d1 0 = Some (pair None c)\n  \\<Longrightarrow> d2 0 = Some (pair None (c\\<lparr>epdaS_conf_scheduler:=take i (epdaS_conf_scheduler c)\\<rparr>))\n  \\<Longrightarrow> i \\<le> length (epdaS_conf_scheduler c)\n  \\<Longrightarrow> j\\<le> i\n  \\<Longrightarrow> i\\<le> n1\n  \\<Longrightarrow> i\\<le> n2\n  \\<Longrightarrow> case_option undefined (\\<lambda>x. x) (get_configuration (d2 j)) =\n  case_option undefined (\\<lambda>c. c\\<lparr>epdaS_conf_scheduler:=take (i - j) (epdaS_conf_scheduler c)\\<rparr>) (get_configuration (d1 j))\"\n  apply(induct j)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac j)(*strict*)\n  apply(clarsimp)\n  apply(simp add: get_configuration_def)\n  apply(subgoal_tac \"\\<exists>e c. d1 j = Some (pair e c)\")\n   apply(rename_tac j)(*strict*)\n   prefer 2\n   apply(rule epdaS.some_position_has_details_before_max_dom)\n     apply(rename_tac j)(*strict*)\n     apply(force)\n    apply(rename_tac j)(*strict*)\n    apply(force)\n   apply(rename_tac j)(*strict*)\n   apply(force)\n  apply(rename_tac j)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d2 j = Some (pair e c)\")\n   apply(rename_tac j)(*strict*)\n   prefer 2\n   apply(rule epdaS.some_position_has_details_before_max_dom)\n     apply(rename_tac j)(*strict*)\n     apply(force)\n    apply(rename_tac j)(*strict*)\n    apply(force)\n   apply(rename_tac j)(*strict*)\n   apply(force)\n  apply(rename_tac j)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d1 (Suc j) = Some (pair (Some e) c)\")\n   apply(rename_tac j)(*strict*)\n   prefer 2\n   apply(rule epdaS.some_position_has_details_before_max_dom_after_0)\n     apply(rename_tac j)(*strict*)\n     apply(force)\n    apply(rename_tac j)(*strict*)\n    apply(force)\n   apply(rename_tac j)(*strict*)\n   apply(force)\n  apply(rename_tac j)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d2 (Suc j) = Some (pair (Some e) c)\")\n   apply(rename_tac j)(*strict*)\n   prefer 2\n   apply(rule epdaS.some_position_has_details_before_max_dom_after_0)\n     apply(rename_tac j)(*strict*)\n     apply(force)\n    apply(rename_tac j)(*strict*)\n    apply(force)\n   apply(rename_tac j)(*strict*)\n   apply(force)\n  apply(rename_tac j)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac j e ea eb ec ca caa cb cc)(*strict*)\n  apply(subgoal_tac \"epdaS_step_relation M ca eb cb\")\n   apply(rename_tac j e ea eb ec ca caa cb cc)(*strict*)\n   prefer 2\n   apply(rule epdaS.position_change_due_to_step_relation)\n     apply(rename_tac j e ea eb ec ca caa cb cc)(*strict*)\n     apply(force)\n    apply(rename_tac j e ea eb ec ca caa cb cc)(*strict*)\n    apply(force)\n   apply(rename_tac j e ea eb ec ca caa cb cc)(*strict*)\n   apply(force)\n  apply(rename_tac j e ea eb ec ca caa cb cc)(*strict*)\n  apply(subgoal_tac \"epdaS_step_relation M caa ec cc\")\n   apply(rename_tac j e ea eb ec ca caa cb cc)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"d2\"\n      in epdaS.position_change_due_to_step_relation)\n     apply(rename_tac j e ea eb ec ca caa cb cc)(*strict*)\n     apply(force)\n    apply(rename_tac j e ea eb ec ca caa cb cc)(*strict*)\n    apply(force)\n   apply(rename_tac j e ea eb ec ca caa cb cc)(*strict*)\n   apply(force)\n  apply(rename_tac j e ea eb ec ca caa cb cc)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac j e ea eb ec ca cb cc)(*strict*)\n  apply(subgoal_tac \"edge_event eb \\<noteq> None \\<and> edge_pop eb = [epda_box M] \\<and> edge_push eb = [epda_box M]\")\n   apply(rename_tac j e ea eb ec ca cb cc)(*strict*)\n   prefer 2\n   apply(simp only: valid_dfa_def)\n   apply(erule conjE)+\n   apply(erule_tac\n      x=\"eb\"\n      in ballE)\n    apply(rename_tac j e ea eb ec ca cb cc)(*strict*)\n    apply(force)\n   apply(rename_tac j e ea eb ec ca cb cc)(*strict*)\n   apply(simp add: epdaS_step_relation_def)\n  apply(rename_tac j e ea eb ec ca cb cc)(*strict*)\n  apply(subgoal_tac \"edge_event ec \\<noteq> None \\<and> edge_pop ec = [epda_box M] \\<and> edge_push ec = [epda_box M]\")\n   apply(rename_tac j e ea eb ec ca cb cc)(*strict*)\n   prefer 2\n   apply(simp only: valid_dfa_def)\n   apply(erule conjE)+\n   apply(erule_tac\n      x=\"ec\"\n      in ballE)\n    apply(rename_tac j e ea eb ec ca cb cc)(*strict*)\n    apply(force)\n   apply(rename_tac j e ea eb ec ca cb cc)(*strict*)\n   apply(simp add: epdaS_step_relation_def)\n  apply(rename_tac j e ea eb ec ca cb cc)(*strict*)\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac j e ea eb ec ca cb cc y ya w)(*strict*)\n  apply(case_tac cc)\n  apply(rename_tac j e ea eb ec ca cb cc y ya w epdaS_conf_statea epdaS_conf_schedulera epdaS_conf_stacka)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac j e ea eb ec ca cb y ya w epdaS_conf_schedulera)(*strict*)\n  apply(rename_tac i1)\n  apply(rename_tac j e ea eb ec ca cb y ya w i1)(*strict*)\n  apply(case_tac cb)\n  apply(rename_tac j e ea eb ec ca cb y ya w i1 epdaS_conf_statea epdaS_conf_schedulera epdaS_conf_stacka)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac j e ea eb ec ca y ya w i1 epdaS_conf_schedulera)(*strict*)\n  apply(rename_tac i2)\n  apply(rename_tac j e ea eb ec ca y ya w i1 i2)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(clarsimp)\n  apply(rename_tac j e ea eb ec ca ya w i2)(*strict*)\n  apply(case_tac ca)\n  apply(rename_tac j e ea eb ec ca ya w i2 epdaS_conf_statea epdaS_conf_schedulera epdaS_conf_stacka)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac j e ea eb ec ya w i2)(*strict*)\n  apply(rename_tac h1)\n  apply(rename_tac j e ea eb ec ya w h1)(*strict*)\n  apply(case_tac ec)\n  apply(rename_tac j e ea eb ec ya w h1 edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac j e ea eb ya w h1 edge_trga)(*strict*)\n  apply(rename_tac pop1 push1 trg1)\n  apply(rename_tac j e ea eb ya pop1 push1 trg1)(*strict*)\n  apply(case_tac eb)\n  apply(rename_tac j e ea eb ya pop1 push1 trg1 edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac j e ea ya pop1 push1 trg1 edge_src edge_trg)(*strict*)\n  apply(rename_tac src2 trg2)\n  apply(rename_tac j e ea ya pop1 push1 trg1 src2 trg2)(*strict*)\n  apply(thin_tac \"d1 j = Some (pair e \\<lparr>epdaS_conf_state = src2, epdaS_conf_scheduler = ya # push1, epdaS_conf_stack = epda_box M # pop1\\<rparr>)\")\n  apply(rename_tac j e ea ya pop1 push1 trg1 src2 trg2)(*strict*)\n  apply(thin_tac \"d1 (Suc j) = Some (pair (Some \\<lparr>edge_src = src2, edge_event = Some ya, edge_pop = [epda_box M], edge_push = [epda_box M], edge_trg = trg2\\<rparr>) \\<lparr>epdaS_conf_state = trg2, epdaS_conf_scheduler = push1, epdaS_conf_stack = epda_box M # pop1\\<rparr>)\")\n  apply(rename_tac j e ea ya pop1 push1 trg1 src2 trg2)(*strict*)\n  apply(thin_tac \"d2 j = Some (pair ea \\<lparr>epdaS_conf_state = src2, epdaS_conf_scheduler = ya # take (i - Suc j) push1, epdaS_conf_stack = epda_box M # pop1\\<rparr>)\")\n  apply(rename_tac j e ea ya pop1 push1 trg1 src2 trg2)(*strict*)\n  apply(thin_tac \"d2 (Suc j) = Some (pair (Some \\<lparr>edge_src = src2, edge_event = Some ya, edge_pop = [epda_box M], edge_push = [epda_box M], edge_trg = trg1\\<rparr>) \\<lparr>epdaS_conf_state = trg1, epdaS_conf_scheduler = take (i - Suc j) push1, epdaS_conf_stack = epda_box M # pop1\\<rparr>)\")\n  apply(rename_tac j e ea ya pop1 push1 trg1 src2 trg2)(*strict*)\n  apply(simp add: valid_dfa_def valid_dpda_def epdaS.is_forward_edge_deterministic_accessible_def)\n  apply(rename_tac j ya trg1 src2 trg2)(*strict*)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"\\<lparr>epdaS_conf_state = src2, epdaS_conf_scheduler = [ya], epdaS_conf_stack = [epda_box M]\\<rparr>\"\n      in ballE)\n   apply(rename_tac j ya trg1 src2 trg2)(*strict*)\n   prefer 2\n   apply(simp add: every_state_in_some_accessible_configuration_def)\n   apply(erule_tac\n      x=\"src2\"\n      in ballE)\n    apply(rename_tac j ya trg1 src2 trg2)(*strict*)\n    prefer 2\n    apply(simp add: valid_pda_def valid_epda_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"\\<lparr>edge_src = src2, edge_event = Some ya, edge_pop = [epda_box M], edge_push = [epda_box M], edge_trg = trg2\\<rparr>\"\n      and P=\"\\<lambda>x. valid_epda_step_label M x\"\n      in ballE)\n     apply(rename_tac j ya trg1 src2 trg2)(*strict*)\n     apply(simp add: valid_epda_step_label_def)\n    apply(rename_tac j ya trg1 src2 trg2)(*strict*)\n    apply(force)\n   apply(rename_tac j ya trg1 src2 trg2)(*strict*)\n   apply(erule_tac\n      x=\"[ya]\"\n      in allE)\n   apply(erule impE)\n    apply(rename_tac j ya trg1 src2 trg2)(*strict*)\n    apply(simp add: valid_pda_def valid_epda_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"\\<lparr>edge_src = src2, edge_event = Some ya, edge_pop = [epda_box M], edge_push = [epda_box M], edge_trg = trg2\\<rparr>\"\n      and P=\"\\<lambda>x. valid_epda_step_label M x\"\n      in ballE)\n     apply(rename_tac j ya trg1 src2 trg2)(*strict*)\n     apply(simp add: valid_epda_step_label_def)\n     apply(simp add: option_to_set_def)\n    apply(rename_tac j ya trg1 src2 trg2)(*strict*)\n    apply(force)\n   apply(rename_tac j ya trg1 src2 trg2)(*strict*)\n   apply(force)\n  apply(rename_tac j ya trg1 src2 trg2)(*strict*)\n  apply(erule_tac\n      x=\"\\<lparr>epdaS_conf_state = trg1, epdaS_conf_scheduler = [], epdaS_conf_stack = [epda_box M]\\<rparr>\"\n      in allE)\n  apply(rename_tac j ya trg1 src2 trg2)(*strict*)\n  apply(erule_tac\n      x=\"\\<lparr>epdaS_conf_state = trg2, epdaS_conf_scheduler = [], epdaS_conf_stack = [epda_box M]\\<rparr>\"\n      in allE)\n  apply(rename_tac j ya trg1 src2 trg2)(*strict*)\n  apply(erule_tac\n      x=\"\\<lparr>edge_src = src2, edge_event = Some ya, edge_pop = [epda_box M], edge_push = [epda_box M], edge_trg = trg1\\<rparr>\"\n      in allE)\n  apply(rename_tac j ya trg1 src2 trg2)(*strict*)\n  apply(erule_tac\n      x=\"\\<lparr>edge_src = src2, edge_event = Some ya, edge_pop = [epda_box M], edge_push = [epda_box M], edge_trg = trg2\\<rparr>\"\n      in allE)\n  apply(rename_tac j ya trg1 src2 trg2)(*strict*)\n  apply(erule impE)\n   apply(rename_tac j ya trg1 src2 trg2)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac j ya trg1 src2 trg2)(*strict*)\n  apply(simp add: epdaS_step_relation_def option_to_list_def)\n  done\n\nlemma valid_dfa_Connected_use_FEdetermR: \"\n  valid_dfa G\n  \\<Longrightarrow> every_state_in_some_accessible_configuration G\n  \\<Longrightarrow> e1 \\<in> epda_delta G\n  \\<Longrightarrow> e2 \\<in> epda_delta G\n  \\<Longrightarrow> edge_src e1=edge_src e2\n  \\<Longrightarrow> edge_event e1=edge_event e2\n  \\<Longrightarrow> edge_trg e1=p\n  \\<Longrightarrow> edge_trg e2=q\n  \\<Longrightarrow> p=q\"\n  apply(simp add: valid_dfa_def valid_dpda_def epdaS.is_forward_edge_deterministic_accessible_def)\n  apply(simp add: every_state_in_some_accessible_configuration_def)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"edge_src e1\"\n      in ballE)\n   prefer 2\n   apply(simp add: valid_dfa_def valid_dpda_def valid_pda_def valid_epda_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"e1\"\n      and P=\"\\<lambda>e1. (\\<exists>y. edge_event e1 = Some y) \\<and> edge_pop e1 = [epda_box G] \\<and> edge_push e1 = [epda_box G]\"\n      in ballE)\n    apply(simp add: valid_epda_step_label_def)\n   apply(force)\n  apply(erule_tac\n      x=\"case edge_event e1 of None \\<Rightarrow> [] | Some x \\<Rightarrow> [x]\"\n      in allE)\n  apply(erule_tac\n      x=\"\\<lparr>epdaS_conf_state = edge_src e1, epdaS_conf_scheduler = case edge_event e1 of None \\<Rightarrow> [] | Some x \\<Rightarrow> [x], epdaS_conf_stack = [epda_box G]\\<rparr>\"\n      in ballE)\n   prefer 2\n   apply(erule impE)\n    prefer 2\n    apply(force)\n   apply(simp add: valid_dfa_def valid_dpda_def valid_pda_def valid_epda_def)\n   apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   apply(erule_tac\n      x=\"e1\"\n      and P=\"\\<lambda>e1. valid_epda_step_label G e1\"\n      in ballE)\n    apply(rename_tac x)(*strict*)\n    apply(simp add: valid_epda_step_label_def option_to_set_def)\n    apply(force)\n   apply(rename_tac x)(*strict*)\n   apply(force)\n  apply(erule_tac\n      x=\"\\<lparr>epdaS_conf_state = edge_trg e1, epdaS_conf_scheduler = [], epdaS_conf_stack = [epda_box G]\\<rparr>\"\n      in allE)\n  apply(erule_tac\n      x=\"\\<lparr>epdaS_conf_state = edge_trg e2, epdaS_conf_scheduler = [], epdaS_conf_stack = [epda_box G]\\<rparr>\"\n      in allE)\n  apply(erule_tac\n      x=\"e1\"\n      in allE)\n  apply(erule_tac\n      x=\"e2\"\n      in allE)\n  apply(erule_tac\n      P=\"epdaS_step_relation G \\<lparr>epdaS_conf_state = edge_src e1, epdaS_conf_scheduler = case edge_event e1 of None \\<Rightarrow> [] | Some x \\<Rightarrow> [x], epdaS_conf_stack = [epda_box G]\\<rparr> e1 \\<lparr>epdaS_conf_state = edge_trg e1, epdaS_conf_scheduler = [], epdaS_conf_stack = [epda_box G]\\<rparr> \\<and> epdaS_step_relation G \\<lparr>epdaS_conf_state = edge_src e1, epdaS_conf_scheduler = case edge_event e1 of None \\<Rightarrow> [] | Some x \\<Rightarrow> [x], epdaS_conf_stack = [epda_box G]\\<rparr> e2 \\<lparr>epdaS_conf_state = edge_trg e2, epdaS_conf_scheduler = [], epdaS_conf_stack = [epda_box G]\\<rparr>\"\n      in impE)\n   prefer 2\n   apply(force)\n  apply(simp add: epdaS_step_relation_def)\n  apply(simp add: option_to_list_def)\n  done\n\nlemma DFA_always_box_stack: \"\n  valid_dfa G\n  \\<Longrightarrow> epdaS.derivation_initial G d\n  \\<Longrightarrow> d n = Some (pair e c)\n  \\<Longrightarrow> epdaS_conf_stack c = [epda_box G]\"\n  apply(induct n arbitrary: e c)\n   apply(rename_tac e c)(*strict*)\n   apply(simp add: epdaS.derivation_initial_def epdaS_initial_configurations_def)\n  apply(rename_tac n e c)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d n = Some (pair e1 c1) \\<and> d (Suc n) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation G c1 e2 c2\")\n   apply(rename_tac n e c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc n\"\n      in epdaS.step_detail_before_some_position)\n     apply(rename_tac n e c)(*strict*)\n     apply(rule epdaS.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac n e c)(*strict*)\n    apply(force)\n   apply(rename_tac n e c)(*strict*)\n   apply(force)\n  apply(rename_tac n e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n c e1 e2 c1)(*strict*)\n  apply(erule_tac\n      x=\"e1\"\n      in meta_allE)\n  apply(erule_tac\n      x=\"c1\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac n c e1 e2 c1 w)(*strict*)\n  apply(unfold valid_dfa_def)\n  apply(erule conjE)+\n  apply(erule_tac\n      x=\"e2\"\n      in ballE)\n   apply(rename_tac n c e1 e2 c1 w)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac n c e1 e2 c1 w)(*strict*)\n  apply(clarify)\n  apply(rename_tac n c e1 e2 c1 w y)(*strict*)\n  apply(thin_tac \"valid_dpda G\")\n  apply(thin_tac \"epdaS.derivation_initial G d\")\n  apply(rename_tac n c e1 e2 c1 w y)(*strict*)\n  apply(thin_tac \"epdaS_conf_stack c1 = edge_pop e2 @ w\")\n  apply(force)\n  done\n\nlemma epda_no_use_epda_box_implies_stack_content: \"\n  valid_epda G\n  \\<Longrightarrow> (\\<forall>r\\<in> epda_delta G. epda_box G \\<notin> set (edge_pop r) \\<and> epda_box G \\<notin> set (edge_push r))\n  \\<Longrightarrow> epdaS.derivation_initial G d\n  \\<Longrightarrow> d n = Some (pair e c)\n  \\<Longrightarrow> \\<exists>w. epda_box G \\<notin> set w \\<and> epdaS_conf_stack c = w @ [epda_box G]\"\n  apply(induct n arbitrary: e c)\n   apply(rename_tac e c)(*strict*)\n   apply(simp add: epdaS.derivation_initial_def)\n   apply(clarsimp)\n   apply(rename_tac c)(*strict*)\n   apply(simp add: epdaS_initial_configurations_def)\n  apply(rename_tac n e c)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d n = Some (pair e1 c1) \\<and> d (Suc n) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation G c1 e2 c2\")\n   apply(rename_tac n e c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc n\"\n      in epdaS.step_detail_before_some_position)\n     apply(rename_tac n e c)(*strict*)\n     apply(rule epdaS.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac n e c)(*strict*)\n    apply(force)\n   apply(rename_tac n e c)(*strict*)\n   apply(force)\n  apply(rename_tac n e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n c e1 e2 c1)(*strict*)\n  apply(erule_tac\n      x=\"e1\"\n      in meta_allE)\n  apply(erule_tac\n      x=\"c1\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(rename_tac n c e1 e2 c1 w)(*strict*)\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac n c e1 e2 c1 w wa)(*strict*)\n  apply(erule_tac\n      x=\"e2\"\n      in ballE)\n   apply(rename_tac n c e1 e2 c1 w wa)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac n c e1 e2 c1 w wa)(*strict*)\n  apply(clarsimp)\n  apply(case_tac wa)\n   apply(rename_tac n c e1 e2 c1 w wa)(*strict*)\n   apply (metis append_self_conv in_set_conv_decomp)\n  apply(rename_tac n c e1 e2 c1 w wa a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. wa = w' @ [x']\")\n   apply(rename_tac n c e1 e2 c1 w wa a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac n c e1 e2 c1 w wa a list)(*strict*)\n  apply(thin_tac \"wa=a#list\")\n  apply(clarsimp)\n  done\n\ndefinition epda_no_nil_popping_edges :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"epda_no_nil_popping_edges M \\<equiv>\n  \\<forall>e \\<in> epda_delta M. edge_pop e \\<noteq> []\"\n\nlemma epda_preserves_epda_box: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.derivation_initial G d\n  \\<Longrightarrow> d i = Some (pair e c)\n  \\<Longrightarrow> suffix (epdaS_conf_stack c) [epda_box G]\"\n  apply(induct i arbitrary: e c)\n   apply(rename_tac e c)(*strict*)\n   apply(simp add: suffix_def)\n   apply(simp add: epdaS.derivation_initial_def)\n   apply(clarsimp)\n   apply(rename_tac c)(*strict*)\n   apply(simp add: epdaS_initial_configurations_def)\n  apply(rename_tac i e c)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d i = Some (pair e1 c1) \\<and> d (Suc i) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation G c1 e2 c2\")\n   apply(rename_tac i e c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc i\"\n      in epdaS.step_detail_before_some_position)\n     apply(rename_tac i e c)(*strict*)\n     apply(simp add: epdaS.derivation_initial_def)\n    apply(rename_tac i e c)(*strict*)\n    apply(force)\n   apply(rename_tac i e c)(*strict*)\n   apply(force)\n  apply(rename_tac i e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1)(*strict*)\n  apply(erule_tac\n      x=\"e1\"\n      in meta_allE)\n  apply(erule_tac\n      x=\"c1\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1 w)(*strict*)\n  apply(simp add: valid_epda_def)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"e2\"\n      in ballE)\n   apply(rename_tac i c e1 e2 c1 w)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac i c e1 e2 c1 w)(*strict*)\n  apply(simp add: valid_epda_step_label_def)\n  apply(clarsimp)\n  apply(simp add: suffix_def)\n  apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1 w ca)(*strict*)\n  apply(subgoal_tac \"prefix (edge_pop e2) ca \\<or> prefix ca (edge_pop e2)\")\n   apply(rename_tac i c e1 e2 c1 w ca)(*strict*)\n   prefer 2\n   apply(rule mutual_prefix_prefix)\n   apply(force)\n  apply(rename_tac i c e1 e2 c1 w ca)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac i c e1 e2 c1 w ca)(*strict*)\n   apply(simp add: prefix_def)\n   apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1 w ca)(*strict*)\n  apply(simp add: prefix_def)\n  apply(clarsimp)\n  apply(rename_tac i c e1 e2 c1 w ca cb)(*strict*)\n  apply(case_tac e2)\n  apply(rename_tac i c e1 e2 c1 w ca cb edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i c e1 c1 w ca cb edge_event edge_push)(*strict*)\n  apply(simp add: may_terminated_by_def must_terminated_by_def kleene_star_def append_language_def)\n  apply(case_tac cb)\n   apply(rename_tac i c e1 c1 w ca cb edge_event edge_push)(*strict*)\n   apply(force)\n  apply(rename_tac i c e1 c1 w ca cb edge_event edge_push a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i c e1 c1 ca edge_event aa ab)(*strict*)\n  apply(force)\n  done\n\nlemma epda_nonempty_stack: \"\n  valid_epda G\n  \\<Longrightarrow> c \\<in> epdaS.get_accessible_configurations G\n  \\<Longrightarrow> epdaS_conf_stack c \\<noteq> []\"\n  apply(simp add: epdaS.get_accessible_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac d i)(*strict*)\n  apply(case_tac \"d i\")\n   apply(rename_tac d i)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d i a)(*strict*)\n  apply(clarsimp)\n  apply(simp add: get_configuration_def)\n  apply(case_tac a)\n  apply(rename_tac d i a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i option)(*strict*)\n  apply(subgoal_tac \"suffix (epdaS_conf_stack c) [epda_box G]\")\n   apply(rename_tac d i option)(*strict*)\n   apply(simp add: suffix_def)\n  apply(rename_tac d i option)(*strict*)\n  apply(metis epda_preserves_epda_box)\n  done\n\ndefinition epda_no_mass_popping_edges :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"epda_no_mass_popping_edges M \\<equiv>\n  \\<forall>e \\<in> epda_delta M. length (edge_pop e) \\<le> Suc 0\"\n\nlemma epda_stack_in_gamma: \"\n  valid_epda G\n  \\<Longrightarrow> c \\<in> epdaS_configurations G\n  \\<Longrightarrow> set (epdaS_conf_stack c) \\<subseteq> epda_gamma G\"\n  apply(simp add: epdaS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac x q i s)(*strict*)\n  apply(force)\n  done\n\nlemma F_DPDA_EB_Nonblockingness_branching_restricted_hlp: \"\n  valid_dpda G\n  \\<Longrightarrow> nonblockingness_language (epdaS.unmarked_language G) (epdaS.marked_language G)\n  \\<Longrightarrow> epdaS.accessible G\n  \\<Longrightarrow> epdaH.Nonblockingness_branching_restricted G\"\n  apply(rule epdaH.AX_BF_BraSBRest_DetHDB_LaOp)\n    apply(simp add: valid_dpda_def valid_pda_def)\n   apply(simp add: epdaH.is_forward_deterministicHist_DB_def)\n   apply(rule conjI)\n    apply(simp add: epdaH.is_forward_target_deterministicHist_DB_long_def)\n    apply(clarsimp)\n    apply(rename_tac c d c1 c2 n e w1 w2)(*strict*)\n    apply(simp add: epdaH_step_relation_def)\n    apply(clarsimp)\n   apply (metis DPDA_to_epdaH_determinism)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac\n      G=\"G\"\n      in epdaH_vs_epdaHS_Nonblockingness_and_lang_transfer)\n   apply(simp add: valid_dpda_def valid_pda_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac\n      G=\"G\"\n      in epdaH_vs_epdaHS_Nonblockingness_and_lang_transfer)\n   apply(simp add: valid_dpda_def valid_pda_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac\n      G=\"G\"\n      in epdaS_vs_epdaHS_Nonblockingness_and_lang_transfer)\n   apply(simp add: valid_dpda_def valid_pda_def)\n  apply(clarsimp)\n  done\n\ndefinition epda_to_des_opt :: \"\n  ('states, 'event, 'stack) epda option\n  \\<Rightarrow> 'event DES\"\n  where\n    \"epda_to_des_opt M \\<equiv> (case M of None \\<Rightarrow> bot | Some M \\<Rightarrow> epda_to_des M)\"\n\nlemma epda_to_des_not_empty: \"\n  valid_epda C\n  \\<Longrightarrow> epda_to_des C = DES {} {}\n  \\<Longrightarrow> Q\"\n  apply(simp add: epda_to_des_def)\n  apply(clarsimp)\n  apply(subgoal_tac \"[] \\<in> epdaH.unmarked_language C\")\n   apply(force)\n  apply(rule epda_empty_in_epdaH_unmarked_language)\n  apply(simp add: valid_dpda_def valid_pda_def)\n  done\n\nlemma epda_to_des_enforces_IsDES: \"\n  valid_epda G\n  \\<Longrightarrow> IsDES (epda_to_des G)\"\n  apply(simp add: IsDES_def)\n  apply(simp add: DES_specification_satisfied_def epda_to_des_def des_langUM_def des_langM_def less_eq_DES_ext_def lesseqDES_def nonblockingness_language_def DES_nonblockingness_def)\n  apply(rule conjI)\n   apply(rule epdaH.lang_inclusion)\n   apply(force)\n  apply(rule antisym)\n   apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   apply(simp add: prefix_closure_def prefix_def)\n   apply(clarsimp)\n   apply(rename_tac x c)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac x c)(*strict*)\n    prefer 2\n    apply(rule_tac\n      x=\"x\"\n      and v=\"c\"\n      in epdaH_unmarked_languageuage_prefix_closed)\n     apply(rename_tac x c)(*strict*)\n     apply(force)\n    apply(rename_tac x c)(*strict*)\n    apply(force)\n   apply(rename_tac x c)(*strict*)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: prefix_closure_def prefix_def)\n  apply(rule_tac\n      x=\"x\"\n      in exI)\n  apply(clarsimp)\n  done\n\nlemma epdaH_prefixes_of_marked_words_are_unmarked_words: \"\n  valid_epda G\n  \\<Longrightarrow> x@v \\<in> epdaH.marked_language G\n  \\<Longrightarrow> x \\<in> epdaH.unmarked_language G\"\n  apply(simp add: epdaH.unmarked_language_def)\n  apply(simp add: epdaH.marked_language_def)\n  apply(clarsimp)\n  apply(rename_tac d)(*strict*)\n  apply(rule_tac\n      x=\"d\"\n      in exI)\n  apply(clarsimp)\n  apply(simp add: epdaH_marked_effect_def epdaH_unmarked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac d i e c)(*strict*)\n  apply(thin_tac \"\\<forall>j e' c'. i < j \\<and> d j = Some (pair e' c') \\<longrightarrow> epdaH_string_state c = epdaH_string_state c'\")\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d i e c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      n=\"i\"\n      and P=\"\\<lambda>n. n\\<le>i \\<and> prefix x (epdaH_conf_history (the(get_configuration(d n)))) \"\n      in ex_least_nat_le_prime)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n   apply(simp add: prefix_def)\n   apply(force)\n  apply(rename_tac d i e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e c k)(*strict*)\n  apply(case_tac k)\n   apply(rename_tac d i e c k)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i e c)(*strict*)\n   apply(simp add: epdaH.derivation_initial_def)\n   apply(case_tac \"d 0\")\n    apply(rename_tac d i e c)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d i e c a)(*strict*)\n   apply(case_tac a)\n   apply(rename_tac d i e c a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i e c b)(*strict*)\n   apply(simp add: epdaH_initial_configurations_def)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n   apply(simp add: prefix_def)\n   apply(clarsimp)\n   apply(rule_tac\n      x=\"0\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac d i e c k nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e c nat)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d i e c nat)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"d\"\n      and n=\"nat\"\n      and m=\"i\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac d i e c nat)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n    apply(rename_tac d i e c nat)(*strict*)\n    apply(force)\n   apply(rename_tac d i e c nat)(*strict*)\n   apply(force)\n  apply(rename_tac d i e c nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e c nat e1 e2 c1 c2)(*strict*)\n  apply(simp add: get_configuration_def prefix_def)\n  apply(clarsimp)\n  apply(rename_tac d i e c nat e1 e2 c1 c2 ca)(*strict*)\n  apply(case_tac c2)\n  apply(rename_tac d i e c nat e1 e2 c1 c2 ca epdaH_conf_state epdaH_conf_historya epdaH_conf_stack)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e c nat e1 e2 c1 ca epdaH_conf_state epdaH_conf_stack)(*strict*)\n  apply(simp add: epdaH_step_relation_def)\n  apply(rename_tac d i e c nat e1 e2 c1 ca epdaH_conf_statea epdaH_conf_stacka)(*strict*)\n  apply(rename_tac q2 s2)\n  apply(rename_tac d i e c nat e1 e2 c1 ca q2 s2)(*strict*)\n  apply(case_tac c1)\n  apply(rename_tac d i e c nat e1 e2 c1 ca q2 s2 epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n  apply(rename_tac q1 h1 s1)\n  apply(rename_tac d i e c nat e1 e2 c1 ca q2 s2 q1 h1 s1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e c nat e1 e2 ca h1 w)(*strict*)\n  apply(case_tac e2)\n  apply(rename_tac d i e c nat e1 e2 ca h1 w edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e c nat e1 ca h1 w edge_src edge_event edge_pop edge_push edge_trg)(*strict*)\n  apply(rename_tac qs re po pu qt)\n  apply(rename_tac d i e c nat e1 ca h1 w qs re po pu qt)(*strict*)\n  apply(case_tac re)\n   apply(rename_tac d i e c nat e1 ca h1 w qs re po pu qt)(*strict*)\n   apply(simp add: option_to_list_def)\n   apply(clarsimp)\n   apply(rename_tac d i e c nat e1 ca w qs po pu qt)(*strict*)\n   apply(rule_tac\n      x=\"nat\"\n      in exI)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"nat\"\n      in allE)\n   apply(force)\n  apply(rename_tac d i e c nat e1 ca h1 w qs re po pu qt a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e c nat e1 ca h1 w qs po pu qt a)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(rule_tac\n      xs=\"ca\"\n      in rev_cases)\n   apply(rename_tac d i e c nat e1 ca h1 w qs po pu qt a)(*strict*)\n   prefer 2\n   apply(rename_tac d i e c nat e1 ca h1 w qs po pu qt a ys y)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i e c nat e1 w qs po pu qt a ys)(*strict*)\n   apply(force)\n  apply(rename_tac d i e c nat e1 ca h1 w qs po pu qt a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e c nat e1 h1 w qs po pu qt a)(*strict*)\n  apply(rule_tac\n      x=\"Suc nat\"\n      in exI)\n  apply(clarsimp)\n  done\n\nlemma duplicate_markingH_to_duplicate_marking: \"\n  valid_epda G\n  \\<Longrightarrow> \\<not> duplicate_markingH G\n  \\<Longrightarrow> \\<not> duplicate_marking G\"\n  apply(simp add: duplicate_markingH_def duplicate_marking_def)\n  apply(clarsimp)\n  apply(rename_tac d i j y)(*strict*)\n  apply(subgoal_tac \"epdaHS.derivation_initial SSP (epdaS2epdaHS_derivation SSP SSd)\" for SSP SSd)\n   apply(rename_tac d i j y)(*strict*)\n   prefer 2\n   apply(rule epdaS2epdaHS_derivation_preserves_derivation_initial)\n    apply(rename_tac d i j y)(*strict*)\n    apply(force)\n   apply(rename_tac d i j y)(*strict*)\n   apply(force)\n  apply(rename_tac d i j y)(*strict*)\n  apply(subgoal_tac \"epdaH.derivation_initial SSG (ATS_Branching_Versus_Linear1.Lin2BraDer epdaHvHS_Lin2BraConf SSd)\" for SSG SSd)\n   apply(rename_tac d i j y)(*strict*)\n   prefer 2\n   apply(rule epdaH_vs_epdaHS.Lin2BraConf_preserves_initiality_lift)\n    apply(rename_tac d i j y)(*strict*)\n    apply(force)\n   apply(rename_tac d i j y)(*strict*)\n   apply(force)\n  apply(rename_tac d i j y)(*strict*)\n  apply(erule_tac\n      x=\"(ATS_Branching_Versus_Linear1.Lin2BraDer epdaHvHS_Lin2BraConf (epdaS2epdaHS_derivation G d))\"\n      in allE)\n  apply(rename_tac d i j y)(*strict*)\n  apply(erule impE)\n   apply(rename_tac d i j y)(*strict*)\n   apply(force)\n  apply(rename_tac d i j y)(*strict*)\n  apply(erule_tac\n      x=\"i\"\n      in allE)\n  apply(erule_tac\n      x=\"j\"\n      in allE)\n  apply(subgoal_tac \"\\<exists>e c. d i = Some (pair e c)\")\n   apply(rename_tac d i j y)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc (i+j)\"\n      in epdaS.pre_some_position_is_some_position)\n     apply(rename_tac d i j y)(*strict*)\n     apply(rule epdaS.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac d i j y)(*strict*)\n    apply(force)\n   apply(rename_tac d i j y)(*strict*)\n   apply(force)\n  apply(rename_tac d i j y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i j y e c)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d (Suc (i+j)) = Some (pair e c)\")\n   apply(rename_tac d i j y e c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc (i+j)\"\n      in epdaS.pre_some_position_is_some_position)\n     apply(rename_tac d i j y e c)(*strict*)\n     apply(rule epdaS.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac d i j y e c)(*strict*)\n    apply(force)\n   apply(rename_tac d i j y e c)(*strict*)\n   apply(force)\n  apply(rename_tac d i j y e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i j e c ea ca)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(erule impE)\n   apply(rename_tac d i j e c ea ca)(*strict*)\n   apply(simp add: epdaS2epdaHS_derivation_def get_configuration_def ATS_Branching_Versus_Linear1.Lin2BraDer_def epdaS.derivation_initial_def epdaS_initial_configurations_def)\n   apply(clarsimp)\n   apply(case_tac \"d 0\")\n    apply(rename_tac d i j e c ea ca)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d i j e c ea ca a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac d i j e c ea ca a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i j e c ea ca b)(*strict*)\n   apply(simp add: get_configuration_def epdaS2epdaHS_derivation_def get_configuration_def ATS_Branching_Versus_Linear1.Lin2BraDer_def epdaS.derivation_initial_def epdaS_initial_configurations_def epdaH_vs_epdaHS.Lin2BraDer_def derivation_map_def epdaHvHS_Lin2BraConf_def)\n  apply(rename_tac d i j e c ea ca)(*strict*)\n  apply(erule impE)\n   apply(rename_tac d i j e c ea ca)(*strict*)\n   apply(simp add: epdaS2epdaHS_derivation_def get_configuration_def ATS_Branching_Versus_Linear1.Lin2BraDer_def epdaS.derivation_initial_def epdaS_initial_configurations_def)\n   apply(clarsimp)\n   apply(case_tac \"d 0\")\n    apply(rename_tac d i j e c ea ca)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d i j e c ea ca a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac d i j e c ea ca a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i j e c ea ca b)(*strict*)\n   apply(simp add: get_configuration_def epdaS2epdaHS_derivation_def get_configuration_def ATS_Branching_Versus_Linear1.Lin2BraDer_def epdaS.derivation_initial_def epdaS_initial_configurations_def epdaH_vs_epdaHS.Lin2BraDer_def derivation_map_def epdaHvHS_Lin2BraConf_def)\n  apply(rename_tac d i j e c ea ca)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac d i j e c ea ca)(*strict*)\n   apply(simp add: epdaS2epdaHS_derivation_def get_configuration_def ATS_Branching_Versus_Linear1.Lin2BraDer_def epdaS.derivation_initial_def epdaS_initial_configurations_def)\n   apply(clarsimp)\n   apply(case_tac \"d 0\")\n    apply(rename_tac d i j e c ea ca)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d i j e c ea ca a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac d i j e c ea ca a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i j e c ea ca b)(*strict*)\n   apply(simp add: epdaS2epdaHS_derivation_def get_configuration_def ATS_Branching_Versus_Linear1.Lin2BraDer_def epdaS.derivation_initial_def epdaS_initial_configurations_def epdaH_vs_epdaHS.Lin2BraDer_def derivation_map_def epdaHvHS_Lin2BraConf_def)\n  apply(rename_tac d i j e c ea ca)(*strict*)\n  apply(simp add: epdaS2epdaHS_derivation_def get_configuration_def ATS_Branching_Versus_Linear1.Lin2BraDer_def epdaS.derivation_initial_def epdaS_initial_configurations_def)\n  apply(clarsimp)\n  apply(case_tac \"d 0\")\n   apply(rename_tac d i j e c ea ca)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d i j e c ea ca a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac d i j e c ea ca a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i j e c ea ca b)(*strict*)\n  apply(simp add: epdaS2epdaHS_derivation_def get_configuration_def ATS_Branching_Versus_Linear1.Lin2BraDer_def epdaS.derivation_initial_def epdaS_initial_configurations_def epdaH_vs_epdaHS.Lin2BraDer_def derivation_map_def epdaHvHS_Lin2BraConf_def)\n  done\n\nlemma epdaH_trans_der_context: \"\n  valid_epda G\n  \\<Longrightarrow> epdaH.trans_der G d c \\<pi> c'\n  \\<Longrightarrow> C = (\\<lambda>c. c\\<lparr>epdaH_conf_history:=h@(epdaH_conf_history c),epdaH_conf_stack:=(epdaH_conf_stack c)@s\\<rparr>)\n  \\<Longrightarrow> set s \\<subseteq> epda_gamma G\n  \\<Longrightarrow> set h \\<subseteq> epda_events G\n  \\<Longrightarrow> C c = c0\n  \\<Longrightarrow> C c' = c0'\n  \\<Longrightarrow> epdaH.trans_der G (derivation_map d C) c0 \\<pi> c0'\"\n  apply(rule epdaH.trans_der_context)\n       apply(force)\n      apply(force)\n     apply(clarsimp)\n     apply(rename_tac a e b)(*strict*)\n     apply(simp add: epdaH_step_relation_def)\n     apply(clarsimp)\n    apply(clarsimp)\n    apply(rename_tac ca)(*strict*)\n    apply(simp add: epdaH_configurations_def)\n    apply(clarsimp)\n   apply(force)\n  apply(force)\n  done\n\nlemma epdaH_trans_der_concatExtend: \"\n  valid_epda G\n  \\<Longrightarrow> epdaH.trans_der G d1 c1 \\<pi>1 c1'\n  \\<Longrightarrow> epdaH.trans_der G d2 c2 \\<pi>2 c2'\n  \\<Longrightarrow> epdaH_conf_state c1'=epdaH_conf_state c2\n  \\<Longrightarrow> epdaH_conf_history c1'=h@epdaH_conf_history c2\n  \\<Longrightarrow> epdaH_conf_stack c1'=epdaH_conf_stack c2@s\n  \\<Longrightarrow> epdaH.trans_der G (derivation_append d1 (derivation_map d2 (\\<lambda>c. c\\<lparr>epdaH_conf_history:=h@(epdaH_conf_history c),epdaH_conf_stack:=(epdaH_conf_stack c)@s\\<rparr>)) (length \\<pi>1)) c1 (\\<pi>1@\\<pi>2) ((\\<lambda>c. c\\<lparr>epdaH_conf_history:=h@(epdaH_conf_history c),epdaH_conf_stack:=(epdaH_conf_stack c)@s\\<rparr>) c2')\"\n  apply(subgoal_tac \"epdaH.trans_der G (derivation_map d2 (\\<lambda>c. c\\<lparr>epdaH_conf_history:=h@(epdaH_conf_history c),epdaH_conf_stack:=(epdaH_conf_stack c)@s\\<rparr>)) ((\\<lambda>c. c\\<lparr>epdaH_conf_history:=h@(epdaH_conf_history c),epdaH_conf_stack:=(epdaH_conf_stack c)@s\\<rparr>) c2) \\<pi>2 ((\\<lambda>c. c\\<lparr>epdaH_conf_history:=h@(epdaH_conf_history c),epdaH_conf_stack:=(epdaH_conf_stack c)@s\\<rparr>) c2')\")\n   prefer 2\n   apply(rule epdaH_trans_der_context)\n         apply(force)\n        apply(force)\n       apply(force)\n      apply(subgoal_tac \"c1' \\<in> epdaH_configurations G\")\n       apply(simp add: epdaH_configurations_def)\n       apply(clarsimp)\n       apply(rename_tac x)(*strict*)\n       apply(force)\n      apply(simp add: epdaH.trans_der_def)\n      apply(clarsimp)\n      apply(rename_tac e ea)(*strict*)\n      apply(rule epdaH.belongs_configurations)\n       apply(rename_tac e ea)(*strict*)\n       apply(force)\n      apply(rename_tac e ea)(*strict*)\n      apply(force)\n     apply(subgoal_tac \"c1' \\<in> epdaH_configurations G\")\n      apply(simp add: epdaH_configurations_def)\n      apply(clarsimp)\n      apply(rename_tac x)(*strict*)\n      apply(force)\n     apply(simp add: epdaH.trans_der_def)\n     apply(clarsimp)\n     apply(rename_tac e ea)(*strict*)\n     apply(rule epdaH.belongs_configurations)\n      apply(rename_tac e ea)(*strict*)\n      apply(force)\n     apply(rename_tac e ea)(*strict*)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(thin_tac \"epdaH.trans_der G d2 c2 \\<pi>2 c2'\")\n  apply(subgoal_tac \"epdaH.trans_der SSG (derivation_append SSd1 SSd2 (length SSrenPI10)) SSc1 (SSrenPI10 @ SSrenPI20) SSc2'\" for SSG SSd1 SSd2 SSc1 SSrenPI10 SSrenPI20 SSc2')\n   prefer 2\n   apply(rule_tac\n      ?d1.0=\"d1\"\n      and ?d2.0=\"(derivation_map d2 (\\<lambda>c. c\\<lparr>epdaH_conf_history := h @ epdaH_conf_history c, epdaH_conf_stack := epdaH_conf_stack c @ s\\<rparr>))\"\n      in epdaH.trans_der_concat)\n      apply(simp add: valid_dpda_def valid_pda_def)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(force)\n  done\n\nlemma epdaH_trans_der_concatExtend_prime: \"\n  valid_epda G\n  \\<Longrightarrow> epdaH.trans_der G d1 c1 \\<pi>1 c1'\n  \\<Longrightarrow> epdaH.trans_der G d2 c2 \\<pi>2 c2'\n  \\<Longrightarrow> epdaH_conf_state c1'=epdaH_conf_state c2\n  \\<Longrightarrow> epdaH_conf_history c1'=h@epdaH_conf_history c2\n  \\<Longrightarrow> epdaH_conf_stack c1'=epdaH_conf_stack c2@s\n  \\<Longrightarrow> \\<exists>d. epdaH.trans_der G d c1 (\\<pi>1@\\<pi>2) ((\\<lambda>c. c\\<lparr>epdaH_conf_history:=h@(epdaH_conf_history c),epdaH_conf_stack:=(epdaH_conf_stack c)@s\\<rparr>) c2')\"\n  apply(rule_tac\n      x=\"(derivation_append d1 (derivation_map d2 (\\<lambda>c. c\\<lparr>epdaH_conf_history:=h@(epdaH_conf_history c),epdaH_conf_stack:=(epdaH_conf_stack c)@s\\<rparr>)) (length \\<pi>1))\"\n      in exI)\n  apply(rule epdaH_trans_der_concatExtend)\n       apply(force)+\n  done\n\nlemma epdaH_nonconflicting_reachable_derivations_are_mutual_prefixing: \"\n  valid_dpda G\n  \\<Longrightarrow> epdaH.trans_der G d \\<lparr>epdaH_conf_state=epda_initial G,epdaH_conf_history=[],epdaH_conf_stack=[epda_box G]\\<rparr> \\<pi> \\<lparr>epdaH_conf_state=q,epdaH_conf_history=h,epdaH_conf_stack=[X]@s\\<rparr>\n  \\<Longrightarrow> epdaH.trans_der G d1 \\<lparr>epdaH_conf_state=q,epdaH_conf_history=[],epdaH_conf_stack=[X]\\<rparr> \\<pi>1 \\<lparr>epdaH_conf_state=q',epdaH_conf_history=[],epdaH_conf_stack=s1\\<rparr>\n  \\<Longrightarrow> epdaH.trans_der G d2 \\<lparr>epdaH_conf_state=q,epdaH_conf_history=[],epdaH_conf_stack=[X]\\<rparr> \\<pi>2 \\<lparr>epdaH_conf_state=q',epdaH_conf_history=b#h',epdaH_conf_stack=s2\\<rparr>\n  \\<Longrightarrow> strict_prefix \\<pi>1 \\<pi>2\"\n  apply(subgoal_tac \"\\<exists>d1'. epdaH.trans_der G d1' \\<lparr>epdaH_conf_state=epda_initial G,epdaH_conf_history=[],epdaH_conf_stack=[epda_box G]\\<rparr> (\\<pi>@\\<pi>1) \\<lparr>epdaH_conf_state=q',epdaH_conf_history=h,epdaH_conf_stack=s1@s\\<rparr>\")\n   apply(subgoal_tac \"\\<exists>d2'. epdaH.trans_der G d2' \\<lparr>epdaH_conf_state=epda_initial G,epdaH_conf_history=[],epdaH_conf_stack=[epda_box G]\\<rparr> (\\<pi>@\\<pi>2) \\<lparr>epdaH_conf_state=q',epdaH_conf_history=h@b#h',epdaH_conf_stack=s2@s\\<rparr>\")\n    apply(thin_tac \"epdaH.trans_der G d \\<lparr>epdaH_conf_state = epda_initial G, epdaH_conf_history = [], epdaH_conf_stack = [epda_box G]\\<rparr> \\<pi> \\<lparr>epdaH_conf_state = q, epdaH_conf_history = h, epdaH_conf_stack = [X] @ s\\<rparr>\")\n    apply(thin_tac \"epdaH.trans_der G d1 \\<lparr>epdaH_conf_state = q, epdaH_conf_history = [], epdaH_conf_stack = [X]\\<rparr> \\<pi>1 \\<lparr>epdaH_conf_state = q', epdaH_conf_history = [], epdaH_conf_stack = s1\\<rparr>\")\n    apply(thin_tac \"epdaH.trans_der G d2 \\<lparr>epdaH_conf_state = q, epdaH_conf_history = [], epdaH_conf_stack = [X]\\<rparr> \\<pi>2 \\<lparr>epdaH_conf_state = q', epdaH_conf_history = b # h', epdaH_conf_stack = s2\\<rparr>\")\n    apply(clarsimp)\n    apply(rename_tac d1' d2')(*strict*)\n    apply(simp add: epdaH.trans_der_def)\n    apply(clarsimp)\n    apply(rename_tac d1' d2' e ea)(*strict*)\n    apply(case_tac \"length \\<pi> + length \\<pi>1 = length \\<pi> + length \\<pi>2\")\n     apply(rename_tac d1' d2' e ea)(*strict*)\n     apply(subgoal_tac \"Some (pair e \\<lparr>epdaH_conf_state = q', epdaH_conf_history = h, epdaH_conf_stack = s1 @ s\\<rparr>)=Some (pair ea \\<lparr>epdaH_conf_state = q', epdaH_conf_history = h @ b # h', epdaH_conf_stack = s2 @ s\\<rparr>)\")\n      apply(rename_tac d1' d2' e ea)(*strict*)\n      apply(force)\n     apply(rename_tac d1' d2' e ea)(*strict*)\n     apply(rule_tac\n      x=\"0\"\n      and m=\"length \\<pi>+length \\<pi>2\"\n      and n=\"length \\<pi>+length \\<pi>1\"\n      and y=\"0\"\n      and G=\"G\"\n      and ?d1.0=\"d1'\"\n      and ?d2.0=\"d2'\"\n      in epdaH.is_forward_deterministicHist_derivations_coincide)\n                apply(rename_tac d1' d2' e ea)(*strict*)\n                apply(simp add: valid_dpda_def valid_pda_def)\n               apply(rename_tac d1' d2' e ea)(*strict*)\n               apply(simp add: epdaH.derivation_initial_def epdaH_initial_configurations_def epdaH_configurations_def valid_dpda_def valid_pda_def valid_epda_def)\n              apply(rename_tac d1' d2' e ea)(*strict*)\n              apply(simp add: epdaH.derivation_initial_def epdaH_initial_configurations_def epdaH_configurations_def valid_dpda_def valid_pda_def valid_epda_def)\n             apply(rename_tac d1' d2' e ea)(*strict*)\n             apply(simp add: valid_dpda_def valid_pda_def)\n             apply(rule_tac\n      t=\"epdaH.is_forward_deterministicHist_SB G\"\n      and s=\"epdaH.is_forward_deterministicHist_DB G\"\n      in ssubst)\n              apply(rename_tac d1' d2' e ea)(*strict*)\n              apply (rule epdaH.is_forward_deterministic_correspond_DB_SB)\n              apply(force)\n             apply(rename_tac d1' d2' e ea)(*strict*)\n             apply(simp add: epdaH.is_forward_deterministicHist_DB_def)\n             apply(rule conjI)\n              apply(rename_tac d1' d2' e ea)(*strict*)\n              apply (metis epdaH_is_forward_target_deterministicHist_DB_long)\n             apply(rename_tac d1' d2' e ea)(*strict*)\n             apply(rule epdaHS2HF_FEdetermHist)\n              apply(rename_tac d1' d2' e ea)(*strict*)\n              apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n             apply(rename_tac d1' d2' e ea)(*strict*)\n             apply(subgoal_tac \"epdaHS.is_forward_edge_deterministic_accessible G\")\n              apply(rename_tac d1' d2' e ea)(*strict*)\n              prefer 2\n              apply(subgoal_tac \"epdaS.is_forward_edge_deterministic_accessible G\")\n               apply(rename_tac d1' d2' e ea)(*strict*)\n               prefer 2\n               apply(simp add: valid_simple_dpda_def valid_dpda_def)\n              apply(rename_tac d1' d2' e ea)(*strict*)\n              apply(rule_tac\n      ?G1.0=\"G\"\n      in epdaS_vs_epdaHS.preserve_FEdetermR1)\n               apply(rename_tac d1' d2' e ea)(*strict*)\n               apply(simp add: valid_dpda_to_valid_pda valid_pda_to_valid_epda valid_simple_dpda_to_valid_dpda)\n              apply(rename_tac d1' d2' e ea)(*strict*)\n              apply(force)\n             apply(rename_tac d1' d2' e ea)(*strict*)\n             apply(subgoal_tac \"epdaHS.is_forward_edge_deterministicHist_DB_long G\")\n              apply(rename_tac d1' d2' e ea)(*strict*)\n              prefer 2\n              apply(clarsimp)\n              apply (metis epdaHS.is_forward_edge_deterministic_accessible_implies_is_forward_edge_deterministicHist_DB_long)\n             apply(rename_tac d1' d2' e ea)(*strict*)\n             apply(force)\n            apply(rename_tac d1' d2' e ea)(*strict*)\n            apply(force)\n           apply(rename_tac d1' d2' e ea)(*strict*)\n           apply(force)\n          apply(rename_tac d1' d2' e ea)(*strict*)\n          apply(force)\n         apply(rename_tac d1' d2' e ea)(*strict*)\n         apply(force)\n        apply(rename_tac d1' d2' e ea)(*strict*)\n        apply(force)\n       apply(rename_tac d1' d2' e ea)(*strict*)\n       apply(force)\n      apply(rename_tac d1' d2' e ea)(*strict*)\n      apply(clarsimp)\n      apply(rule_tac\n      x=\"b#h'\"\n      in bexI)\n       apply(rename_tac d1' d2' e ea)(*strict*)\n       apply(simp add: get_configuration_def)\n      apply(rename_tac d1' d2' e ea)(*strict*)\n      apply(simp add: epda_effects_def)\n      apply(subgoal_tac \"\\<lparr>epdaH_conf_state = q', epdaH_conf_history = h @ b # h', epdaH_conf_stack = s2 @ s\\<rparr> \\<in> epdaH_configurations G\")\n       apply(rename_tac d1' d2' e ea)(*strict*)\n       apply(simp add: epdaH_configurations_def)\n      apply(rename_tac d1' d2' e ea)(*strict*)\n      apply(rule_tac\n      d=\"d2'\"\n      in epdaH.belongs_configurations)\n       apply(rename_tac d1' d2' e ea)(*strict*)\n       apply(force)\n      apply(rename_tac d1' d2' e ea)(*strict*)\n      apply(force)\n     apply(rename_tac d1' d2' e ea)(*strict*)\n     apply(force)\n    apply(rename_tac d1' d2' e ea)(*strict*)\n    apply(clarsimp)\n    apply(case_tac \"length \\<pi> + length \\<pi>1 < length \\<pi> + length \\<pi>2\")\n     apply(rename_tac d1' d2' e ea)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"drop 0 (get_labels d1' (0+((length \\<pi> + length \\<pi>1)))) = drop 0 (get_labels d2' (0+(length \\<pi> + length \\<pi>1))) \\<and> (\\<forall>i\\<le>(length \\<pi> + length \\<pi>1). d1' (0+i) = d2' (0+i))\")\n      apply(rename_tac d1' d2' e ea)(*strict*)\n      apply(clarsimp)\n      apply(simp add: strict_prefix_def)\n      apply(rule_tac\n      x=\"drop(length \\<pi>1) \\<pi>2\"\n      in exI)\n      apply(rule conjI)\n       apply(rename_tac d1' d2' e ea)(*strict*)\n       apply(force)\n      apply(rename_tac d1' d2' e ea)(*strict*)\n      apply(subgoal_tac \"get_labels d2' (length \\<pi> + length \\<pi>1) = map Some \\<pi> @ map Some (take(length \\<pi>1) \\<pi>2)\")\n       apply(rename_tac d1' d2' e ea)(*strict*)\n       apply(clarsimp)\n       apply (metis append_Nil append_take_drop_id_hlp length_append length_map length_map_Some length_shorter_append2 map_append takeShorter)\n      apply(rename_tac d1' d2' e ea)(*strict*)\n      apply(rule_tac\n      m=\"length \\<pi>2-length \\<pi>1\"\n      and v=\"map Some (drop(length \\<pi>1)\\<pi>2)\"\n      in get_labels_drop_tail)\n       apply(rename_tac d1' d2' e ea)(*strict*)\n       apply(clarsimp)\n       apply (metis append_Nil append_take_drop_id_hlp length_append length_map length_map_Some length_shorter_append2 map_append takeShorter)\n      apply(rename_tac d1' d2' e ea)(*strict*)\n      apply(clarsimp)\n      apply(force)\n     apply(rename_tac d1' d2' e ea)(*strict*)\n     apply(rule_tac\n      x=\"0\"\n      and m=\"length \\<pi>+length \\<pi>2\"\n      and n=\"length \\<pi>+length \\<pi>1\"\n      and y=\"0\"\n      and G=\"G\"\n      and ?d1.0=\"d1'\"\n      and ?d2.0=\"d2'\"\n      in epdaH.same_steps_for_compatible_histories)\n                apply(rename_tac d1' d2' e ea)(*strict*)\n                apply(simp add: valid_dpda_def valid_pda_def)\n               apply(rename_tac d1' d2' e ea)(*strict*)\n               apply(simp add: epdaH.derivation_initial_def epdaH_initial_configurations_def epdaH_configurations_def valid_dpda_def valid_pda_def valid_epda_def)\n              apply(rename_tac d1' d2' e ea)(*strict*)\n              apply(simp add: epdaH.derivation_initial_def epdaH_initial_configurations_def epdaH_configurations_def valid_dpda_def valid_pda_def valid_epda_def)\n             apply(rename_tac d1' d2' e ea)(*strict*)\n             apply(simp add: valid_dpda_def valid_pda_def)\n             apply(rule_tac\n      t=\"epdaH.is_forward_deterministicHist_SB G\"\n      and s=\"epdaH.is_forward_deterministicHist_DB G\"\n      in ssubst)\n              apply(rename_tac d1' d2' e ea)(*strict*)\n              apply (rule epdaH.is_forward_deterministic_correspond_DB_SB)\n              apply(force)\n             apply(rename_tac d1' d2' e ea)(*strict*)\n             apply(simp add: epdaH.is_forward_deterministicHist_DB_def)\n             apply(rule conjI)\n              apply(rename_tac d1' d2' e ea)(*strict*)\n              apply (metis epdaH_is_forward_target_deterministicHist_DB_long)\n             apply(rename_tac d1' d2' e ea)(*strict*)\n             apply(rule epdaHS2HF_FEdetermHist)\n              apply(rename_tac d1' d2' e ea)(*strict*)\n              apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n             apply(rename_tac d1' d2' e ea)(*strict*)\n             apply(subgoal_tac \"epdaHS.is_forward_edge_deterministic_accessible G\")\n              apply(rename_tac d1' d2' e ea)(*strict*)\n              prefer 2\n              apply(subgoal_tac \"epdaS.is_forward_edge_deterministic_accessible G\")\n               apply(rename_tac d1' d2' e ea)(*strict*)\n               prefer 2\n               apply(simp add: valid_simple_dpda_def valid_dpda_def)\n              apply(rename_tac d1' d2' e ea)(*strict*)\n              apply(rule_tac\n      ?G1.0=\"G\"\n      in epdaS_vs_epdaHS.preserve_FEdetermR1)\n               apply(rename_tac d1' d2' e ea)(*strict*)\n               apply (simp add: valid_dpda_to_valid_pda valid_pda_to_valid_epda valid_simple_dpda_to_valid_dpda)\n              apply(rename_tac d1' d2' e ea)(*strict*)\n              apply(force)\n             apply(rename_tac d1' d2' e ea)(*strict*)\n             apply(subgoal_tac \"epdaHS.is_forward_edge_deterministicHist_DB_long G\")\n              apply(rename_tac d1' d2' e ea)(*strict*)\n              prefer 2\n              apply(clarsimp)\n              apply (metis epdaHS.is_forward_edge_deterministic_accessible_implies_is_forward_edge_deterministicHist_DB_long)\n             apply(rename_tac d1' d2' e ea)(*strict*)\n             apply(force)\n            apply(rename_tac d1' d2' e ea)(*strict*)\n            apply(force)\n           apply(rename_tac d1' d2' e ea)(*strict*)\n           apply(force)\n          apply(rename_tac d1' d2' e ea)(*strict*)\n          apply(force)\n         apply(rename_tac d1' d2' e ea)(*strict*)\n         apply(force)\n        apply(rename_tac d1' d2' e ea)(*strict*)\n        apply(force)\n       apply(rename_tac d1' d2' e ea)(*strict*)\n       apply(force)\n      apply(rename_tac d1' d2' e ea)(*strict*)\n      apply(clarsimp)\n      apply(rule_tac\n      x=\"b#h'\"\n      in bexI)\n       apply(rename_tac d1' d2' e ea)(*strict*)\n       apply(simp add: get_configuration_def)\n      apply(rename_tac d1' d2' e ea)(*strict*)\n      apply(simp add: epda_effects_def)\n      apply(subgoal_tac \"\\<lparr>epdaH_conf_state = q', epdaH_conf_history = h @ b # h', epdaH_conf_stack = s2 @ s\\<rparr> \\<in> epdaH_configurations G\")\n       apply(rename_tac d1' d2' e ea)(*strict*)\n       apply(simp add: epdaH_configurations_def)\n      apply(rename_tac d1' d2' e ea)(*strict*)\n      apply(rule_tac\n      d=\"d2'\"\n      in epdaH.belongs_configurations)\n       apply(rename_tac d1' d2' e ea)(*strict*)\n       apply(force)\n      apply(rename_tac d1' d2' e ea)(*strict*)\n      apply(force)\n     apply(rename_tac d1' d2' e ea)(*strict*)\n     apply(force)\n    apply(rename_tac d1' d2' e ea)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"length \\<pi>2 < length \\<pi>1\")\n     apply(rename_tac d1' d2' e ea)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac d1' d2' e ea)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"False\")\n     apply(rename_tac d1' d2' e ea)(*strict*)\n     apply(force)\n    apply(rename_tac d1' d2' e ea)(*strict*)\n    apply(subgoal_tac \"\\<exists>k\\<le>(length \\<pi>+length \\<pi>2). (\\<forall>i<k. \\<not> (case SSd i of None \\<Rightarrow> False | Some (pair e c) \\<Rightarrow> SSP c)) \\<and> (case SSd k of None \\<Rightarrow> False | Some (pair e c) \\<Rightarrow> SSP c)\" for SSd SSP)\n     apply(rename_tac d1' d2' e ea)(*strict*)\n     prefer 2\n     apply(rule_tac\n      d=\"d2'\"\n      and P=\"\\<lambda>c. \\<exists>w. epdaH_conf_history c=h@[b]@w\"\n      in epdaH.existence_of_earliest_satisfaction_point)\n       apply(rename_tac d1' d2' e ea)(*strict*)\n       apply(force)\n      apply(rename_tac d1' d2' e ea)(*strict*)\n      apply(force)\n     apply(rename_tac d1' d2' e ea)(*strict*)\n     apply(force)\n    apply(rename_tac d1' d2' e ea)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1' d2' e ea k)(*strict*)\n    apply(case_tac k)\n     apply(rename_tac d1' d2' e ea k)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1' d2' e ea k nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1' d2' e ea nat)(*strict*)\n    apply(rename_tac k)\n    apply(rename_tac d1' d2' e ea k)(*strict*)\n    apply(erule_tac\n      x=\"k\"\n      in allE)\n    apply(clarsimp)\n    apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d2' k = Some (pair e1 c1) \\<and> SSd (Suc (SSn)) = Some (pair (Some e2) c2) \\<and> epdaH_step_relation G c1 e2 c2\" for SSd SSn)\n     apply(rename_tac d1' d2' e ea k)(*strict*)\n     prefer 2\n     apply(rule_tac\n      m=\"length \\<pi>+length \\<pi>2\"\n      in epdaH.step_detail_before_some_position)\n       apply(rename_tac d1' d2' e ea k)(*strict*)\n       apply(force)\n      apply(rename_tac d1' d2' e ea k)(*strict*)\n      apply(force)\n     apply(rename_tac d1' d2' e ea k)(*strict*)\n     apply(force)\n    apply(rename_tac d1' d2' e ea k)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 w)(*strict*)\n    apply(subgoal_tac \"epdaH_conf_history c1 = h \\<and> w = []\")\n     apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 w)(*strict*)\n     prefer 2\n     apply(simp add: epdaH_step_relation_def)\n     apply(clarsimp)\n     apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 w wa)(*strict*)\n     apply(case_tac \"edge_event e2\")\n      apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 w wa)(*strict*)\n      apply(simp add: option_to_list_def)\n      apply(erule_tac\n      x=\"w\"\n      in allE)\n      apply(force)\n     apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 w wa a)(*strict*)\n     apply(simp add: option_to_list_def)\n     apply(subgoal_tac \"w=[] \\<or> (\\<exists>w' a'. w=w'@[a'])\")\n      apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 w wa a)(*strict*)\n      prefer 2\n      apply(rule case_list)\n     apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 w wa a)(*strict*)\n     apply(erule disjE)\n      apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 w wa a)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 w wa a)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 wa a w')(*strict*)\n     apply(erule_tac\n      x=\"w'\"\n      in allE)\n     apply(force)\n    apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1' d2' e ea k e1 e2 c1 c2)(*strict*)\n    apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d1' k = Some (pair e1 c1) \\<and> SSd (Suc (SSn)) = Some (pair (Some e2) c2) \\<and> epdaH_step_relation G c1 e2 c2\" for SSd SSn)\n     apply(rename_tac d1' d2' e ea k e1 e2 c1 c2)(*strict*)\n     prefer 2\n     apply(rule_tac\n      m=\"length \\<pi>+length \\<pi>1\"\n      in epdaH.step_detail_before_some_position)\n       apply(rename_tac d1' d2' e ea k e1 e2 c1 c2)(*strict*)\n       apply(force)\n      apply(rename_tac d1' d2' e ea k e1 e2 c1 c2)(*strict*)\n      apply(force)\n     apply(rename_tac d1' d2' e ea k e1 e2 c1 c2)(*strict*)\n     apply(force)\n    apply(rename_tac d1' d2' e ea k e1 e2 c1 c2)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a)(*strict*)\n    apply(subgoal_tac \"\\<exists>h\\<in> epda_effects SSG. epdaH_conf_history SSc' = epdaH_conf_history SSc @ h\" for SSG SSc' SSc)\n     apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a)(*strict*)\n     prefer 2\n     apply(rule_tac\n      m=\"Suc 0\"\n      and n=\"k\"\n      and d=\"d1'\"\n      in epdaH.steps_extend_history_derivation)\n         apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a)(*strict*)\n         apply(simp add: valid_dpda_def valid_pda_def)\n         apply(force)\n        apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a)(*strict*)\n        apply(force)\n       apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a)(*strict*)\n       prefer 2\n       apply(simp add: get_configuration_def)\n      apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a)(*strict*)\n      apply(rule_tac\n      d=\"d1'\"\n      in epdaH.belongs_configurations)\n       apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a)(*strict*)\n       apply(force)\n      apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a)(*strict*)\n      apply(force)\n     apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a)(*strict*)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h)(*strict*)\n    apply(subgoal_tac \"\\<exists>h\\<in> epda_effects SSG. epdaH_conf_history SSc' = epdaH_conf_history SSc @ h\" for SSG SSc' SSc)\n     apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h)(*strict*)\n     prefer 2\n     apply(rule_tac\n      m=\"length \\<pi>+length \\<pi>1-Suc k\"\n      and n=\"Suc k\"\n      and d=\"d1'\"\n      in epdaH.steps_extend_history_derivation)\n         apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h)(*strict*)\n         apply(simp add: valid_dpda_def valid_pda_def)\n         apply(force)\n        apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h)(*strict*)\n        apply(force)\n       apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h)(*strict*)\n       prefer 2\n       apply(simp add: get_configuration_def)\n      apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h)(*strict*)\n      apply(rule_tac\n      d=\"d1'\"\n      in epdaH.belongs_configurations)\n       apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h)(*strict*)\n       apply(force)\n      apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h)(*strict*)\n      apply(force)\n     apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h)(*strict*)\n     apply(rule_tac\n      t=\"(Suc k + (length \\<pi> + length \\<pi>1 - Suc k))\"\n      and s=\"length \\<pi> + length \\<pi>1\"\n      in ssubst)\n      apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h)(*strict*)\n      apply(force)\n     apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h)(*strict*)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n    apply(subgoal_tac \"d1' k = d2' k\")\n     apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n     prefer 2\n     apply(subgoal_tac \"drop 0 (get_labels d1' (0+k)) = drop 0 (get_labels d2' (0+(k))) \\<and> (\\<forall>i\\<le>(k). d1' (0+i) = d2' (0+i))\")\n      apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n     apply(rule_tac\n      x=\"0\"\n      and m=\"length \\<pi>+length \\<pi>2\"\n      and n=\"k\"\n      and y=\"0\"\n      and G=\"G\"\n      and ?d1.0=\"d1'\"\n      and ?d2.0=\"d2'\"\n      in epdaH.same_steps_for_compatible_histories)\n                apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n                apply(simp add: valid_dpda_def valid_pda_def)\n               apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n               apply(simp add: epdaH.derivation_initial_def epdaH_initial_configurations_def epdaH_configurations_def valid_dpda_def valid_pda_def valid_epda_def)\n              apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n              apply(simp add: epdaH.derivation_initial_def epdaH_initial_configurations_def epdaH_configurations_def valid_dpda_def valid_pda_def valid_epda_def)\n             apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n             apply(simp add: valid_dpda_def valid_pda_def)\n             apply(rule_tac\n      t=\"epdaH.is_forward_deterministicHist_SB G\"\n      and s=\"epdaH.is_forward_deterministicHist_DB G\"\n      in ssubst)\n              apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n              apply (rule epdaH.is_forward_deterministic_correspond_DB_SB)\n              apply(force)\n             apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n             apply(simp add: epdaH.is_forward_deterministicHist_DB_def)\n             apply(rule conjI)\n              apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n              apply (metis epdaH_is_forward_target_deterministicHist_DB_long)\n             apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n             apply(rule epdaHS2HF_FEdetermHist)\n              apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n              apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n             apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n             apply(subgoal_tac \"epdaHS.is_forward_edge_deterministic_accessible G\")\n              apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n              prefer 2\n              apply(subgoal_tac \"epdaS.is_forward_edge_deterministic_accessible G\")\n               apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n               prefer 2\n               apply(simp add: valid_simple_dpda_def valid_dpda_def)\n              apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n              apply(rule_tac\n      ?G1.0=\"G\"\n      in epdaS_vs_epdaHS.preserve_FEdetermR1)\n               apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n               apply(simp add: valid_dpda_to_valid_pda valid_pda_to_valid_epda valid_simple_dpda_to_valid_dpda)\n              apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n              apply(force)\n             apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n             apply(subgoal_tac \"epdaHS.is_forward_edge_deterministicHist_DB_long G\")\n              apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n              prefer 2\n              apply(clarsimp)\n              apply (metis epdaHS.is_forward_edge_deterministic_accessible_implies_is_forward_edge_deterministicHist_DB_long)\n             apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n             apply(force)\n            apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n            apply(force)\n           apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n           apply(force)\n          apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n          apply(force)\n         apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n         apply(force)\n        apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n        apply(force)\n       apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n       apply(force)\n      apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n      apply(simp add: get_configuration_def)\n      apply(simp add: epda_effects_def)\n      apply(subgoal_tac \"\\<lparr>epdaH_conf_state = q', epdaH_conf_history = epdaH_conf_history c1a @ h @ ha @ b # h', epdaH_conf_stack = s2 @ s\\<rparr> \\<in> epdaH_configurations G\")\n       apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n       apply(simp add: epdaH_configurations_def)\n      apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n      apply(rule_tac\n      d=\"d2'\"\n      in epdaH.belongs_configurations)\n       apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n       apply(force)\n      apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n      apply(force)\n     apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n     apply(force)\n    apply(rename_tac d1' d2' e ea k e1 e2 c1 c2 e1a e2a c1a c2a h ha)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n    apply(subgoal_tac \"d1' (Suc k) = d2' (Suc k)\")\n     apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n     prefer 2\n     apply(subgoal_tac \"drop 0 (get_labels d1' (0+(Suc k))) = drop 0 (get_labels d2' (0+(Suc k))) \\<and> (\\<forall>i\\<le>(Suc k). d1' (0+i) = d2' (0+i))\")\n      apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n     apply(rule_tac\n      x=\"0\"\n      and m=\"length \\<pi>+length \\<pi>2\"\n      and n=\"Suc k\"\n      and y=\"0\"\n      and G=\"G\"\n      and ?d1.0=\"d1'\"\n      and ?d2.0=\"d2'\"\n      in epdaH.same_steps_for_compatible_histories)\n                apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n                apply(simp add: valid_dpda_def valid_pda_def)\n               apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n               apply(simp add: epdaH.derivation_initial_def epdaH_initial_configurations_def epdaH_configurations_def valid_dpda_def valid_pda_def valid_epda_def)\n              apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n              apply(simp add: epdaH.derivation_initial_def epdaH_initial_configurations_def epdaH_configurations_def valid_dpda_def valid_pda_def valid_epda_def)\n             apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n             apply(simp add: valid_dpda_def valid_pda_def)\n             apply(rule_tac\n      t=\"epdaH.is_forward_deterministicHist_SB G\"\n      and s=\"epdaH.is_forward_deterministicHist_DB G\"\n      in ssubst)\n              apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n              apply (rule epdaH.is_forward_deterministic_correspond_DB_SB)\n              apply(force)\n             apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n             apply(simp add: epdaH.is_forward_deterministicHist_DB_def)\n             apply(rule conjI)\n              apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n              apply (metis epdaH_is_forward_target_deterministicHist_DB_long)\n             apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n             apply(rule epdaHS2HF_FEdetermHist)\n              apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n              apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n             apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n             apply(subgoal_tac \"epdaHS.is_forward_edge_deterministic_accessible G\")\n              apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n              prefer 2\n              apply(subgoal_tac \"epdaS.is_forward_edge_deterministic_accessible G\")\n               apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n               prefer 2\n               apply(simp add: valid_simple_dpda_def valid_dpda_def)\n              apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n              apply(rule_tac\n      ?G1.0=\"G\"\n      in epdaS_vs_epdaHS.preserve_FEdetermR1)\n               apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n               apply(simp add: valid_dpda_to_valid_pda valid_pda_to_valid_epda valid_simple_dpda_to_valid_dpda)\n              apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n              apply(force)\n             apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n             apply(subgoal_tac \"epdaHS.is_forward_edge_deterministicHist_DB_long G\")\n              apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n              prefer 2\n              apply(clarsimp)\n              apply (metis epdaHS.is_forward_edge_deterministic_accessible_implies_is_forward_edge_deterministicHist_DB_long)\n             apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n             apply(force)\n            apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n            apply(force)\n           apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n           apply(force)\n          apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n          apply(force)\n         apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n         apply(force)\n        apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n        apply(force)\n       apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n       apply(force)\n      apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n      apply(simp add: get_configuration_def)\n      apply(simp add: epda_effects_def)\n      apply(subgoal_tac \"\\<lparr>epdaH_conf_state = q', epdaH_conf_history = epdaH_conf_history c1a @ b # h', epdaH_conf_stack = s2 @ s\\<rparr> \\<in> epdaH_configurations G\")\n       apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n       apply(simp add: epdaH_configurations_def)\n      apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n      apply(rule_tac\n      d=\"d2'\"\n      in epdaH.belongs_configurations)\n       apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n       apply(force)\n      apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n      apply(force)\n     apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n     apply(force)\n    apply(rename_tac d1' d2' e ea k e2 c2 e1a e2a c1a c2a)(*strict*)\n    apply(clarsimp)\n   apply(thin_tac \"\\<exists>d1'. epdaH.trans_der G d1' \\<lparr>epdaH_conf_state = epda_initial G, epdaH_conf_history = [], epdaH_conf_stack = [epda_box G]\\<rparr> (\\<pi> @ \\<pi>1) \\<lparr>epdaH_conf_state = q', epdaH_conf_history = h, epdaH_conf_stack = s1 @ s\\<rparr>\")\n   apply(thin_tac \"epdaH.trans_der G d1 \\<lparr>epdaH_conf_state = q, epdaH_conf_history = [], epdaH_conf_stack = [X]\\<rparr> \\<pi>1 \\<lparr>epdaH_conf_state = q', epdaH_conf_history = [], epdaH_conf_stack = s1\\<rparr>\")\n   apply(subgoal_tac \"\\<exists>d. epdaH.trans_der SSG d SSc1 (SSrenPI10 @ SSrenPI20) (SSc2'\\<lparr>epdaH_conf_history := SSh @ epdaH_conf_history SSc2', epdaH_conf_stack := epdaH_conf_stack SSc2' @ SSs\\<rparr>)\" for SSG SSc1 SSrenPI10 SSrenPI20 SSh SSc2' SSs)\n    prefer 2\n    apply(rule_tac\n      ?d1.0=\"d\"\n      and ?d2.0=\"d2\"\n      and h=\"h\"\n      and s=\"s\"\n      in epdaH_trans_der_concatExtend_prime)\n         apply(simp add: valid_dpda_def valid_pda_def)\n         apply(force)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(clarsimp)\n  apply(thin_tac \"epdaH.trans_der G d2 \\<lparr>epdaH_conf_state = q, epdaH_conf_history = [], epdaH_conf_stack = [X]\\<rparr> \\<pi>2 \\<lparr>epdaH_conf_state = q', epdaH_conf_history = b # h', epdaH_conf_stack = s2\\<rparr>\")\n  apply(subgoal_tac \"\\<exists>d. epdaH.trans_der SSG d SSc1 (SSrenPI10 @ SSrenPI20) (SSc2'\\<lparr>epdaH_conf_history := SSh @ epdaH_conf_history SSc2', epdaH_conf_stack := epdaH_conf_stack SSc2' @ SSs\\<rparr>)\" for SSG SSc1 SSrenPI10 SSrenPI20 SSh SSc2' SSs)\n   prefer 2\n   apply(rule_tac\n      ?d1.0=\"d\"\n      and ?d2.0=\"d1\"\n      and h=\"h\"\n      and s=\"s\"\n      in epdaH_trans_der_concatExtend_prime)\n        apply(simp add: valid_dpda_def valid_pda_def)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  done\n\nlemma epda_is_forward_target_deterministic: \"\n  valid_epda G\n  \\<Longrightarrow> epdaH.is_forward_target_deterministic G\"\n  apply(simp add: epdaH.is_forward_target_deterministic_def)\n  apply(clarsimp)\n  apply(rename_tac c c1 c2 e)(*strict*)\n  apply(simp add: epdaH_step_relation_def)\n  apply(clarsimp)\n  done\n\nlemma epdaHS2epdaS_derivation_preserves_derivation: \"\n  valid_epda P\n  \\<Longrightarrow> epdaHS.derivation P d\n  \\<Longrightarrow> epdaS.derivation P (epdaHS2epdaS_derivation d)\"\n  apply(simp add: epdaHS2epdaS_derivation_def)\n  apply(simp add: epdaS.derivation_def)\n  apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(case_tac \"i\")\n   apply(rename_tac i)(*strict*)\n   apply(clarsimp)\n   apply(simp add: epdaHS.derivation_def)\n   apply(case_tac \"d 0\")\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"0\"\n      in allE)\n    apply(clarsimp)\n   apply(rename_tac a)(*strict*)\n   apply(case_tac a)\n   apply(rename_tac a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac option b)(*strict*)\n   apply(erule_tac\n      x=\"0\"\n      in allE)\n   apply(clarsimp)\n  apply(rename_tac i nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat)(*strict*)\n  apply(case_tac \"d (Suc nat)\")\n   apply(rename_tac nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac nat a)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d nat = Some (pair e1 c1) \\<and> d (Suc nat) = Some (pair (Some e2) c2) \\<and> epdaHS_step_relation P c1 e2 c2\")\n   apply(rename_tac nat a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc nat\"\n      in epdaHS.step_detail_before_some_position)\n     apply(rename_tac nat a)(*strict*)\n     apply(simp add: epdaHS.derivation_initial_def)\n    apply(rename_tac nat a)(*strict*)\n    apply(force)\n   apply(rename_tac nat a)(*strict*)\n   apply(force)\n  apply(rename_tac nat a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat e1 e2 c1 c2)(*strict*)\n  apply(simp add: epdaS_step_relation_def epdaHS_step_relation_def)\n  done\n\nlemma epdaS2epdaHS_derivation_preserves_derivation: \"\n  valid_epda P\n  \\<Longrightarrow> epdaS.belongs P d\n  \\<Longrightarrow> epdaS.derivation P d\n  \\<Longrightarrow> epdaHS.derivation P (epdaS2epdaHS_derivation P d)\"\n  apply(simp add: epdaS2epdaHS_derivation_def)\n  apply(simp add: epdaHS.derivation_def)\n  apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(case_tac \"i\")\n   apply(rename_tac i)(*strict*)\n   apply(clarsimp)\n   apply(simp add: epdaS.derivation_def)\n   apply(case_tac \"d 0\")\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"0\"\n      in allE)\n    apply(force)\n   apply(rename_tac a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac option b)(*strict*)\n   apply(erule_tac\n      x=\"0\"\n      in allE)\n   apply(force)\n  apply(rename_tac i nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat)(*strict*)\n  apply(case_tac \"d (Suc nat)\")\n   apply(rename_tac nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac nat a)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d nat = Some (pair e1 c1) \\<and> d (Suc nat) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation P c1 e2 c2\")\n   apply(rename_tac nat a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc nat\"\n      in epdaS.step_detail_before_some_position)\n     apply(rename_tac nat a)(*strict*)\n     apply(simp add: epdaS.derivation_initial_def)\n    apply(rename_tac nat a)(*strict*)\n    apply(force)\n   apply(rename_tac nat a)(*strict*)\n   apply(force)\n  apply(rename_tac nat a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat e1 e2 c1 c2)(*strict*)\n  apply(simp add: epdaS_step_relation_def epdaHS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac nat e1 e2 c1 c2 w)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. d 0 = Some (pair None c)\")\n   apply(rename_tac nat e1 e2 c1 c2 w)(*strict*)\n   prefer 2\n   apply(rule epdaS.some_position_has_details_at_0)\n   apply(force)\n  apply(rename_tac nat e1 e2 c1 c2 w)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n  apply(subgoal_tac \"valid_epda_step_label P e2\")\n   apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n   prefer 2\n   apply(simp add: valid_epda_def)\n  apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n  apply(simp add: valid_epda_step_label_def)\n  apply(subgoal_tac \"\\<exists>w. epdaS_string_state c = w @ (epdaS_string_state c1)\")\n   apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      j=\"nat\"\n      in epdaS.derivation_monotonically_dec)\n        apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n        apply(force)\n       apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n       apply(force)\n      apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n      apply(force)\n     apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n     apply(force)\n    apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n    apply(force)\n   apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n   apply(force)\n  apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n  apply(simp add: epdaS_string_state_def)\n  apply(clarsimp)\n  apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. epdaS_string_state c1 = w @ (epdaS_string_state c2)\")\n   apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n   prefer 2\n   apply(rule_tac\n      j=\"Suc 0\"\n      in epdaS.derivation_monotonically_dec)\n        apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n        apply(force)\n       apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n       apply(force)\n      apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n      apply(force)\n     apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n     apply(force)\n    apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n    apply(force)\n   apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n   apply(force)\n  apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n  apply(subgoal_tac \"c \\<in> epdaS_configurations P\")\n   apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n   prefer 2\n   apply(rule epdaS.belongs_configurations)\n    apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n    apply(force)\n   apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n   apply(force)\n  apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n  apply(simp add: epdaS_string_state_def)\n  apply(rule_tac\n      t=\"right_quotient_word (wa @ option_to_list (edge_event e2) @ epdaS_conf_scheduler c2) (epdaS_conf_scheduler c2)\"\n      and s=\"Some(wa @ option_to_list (edge_event e2))\"\n      in ssubst)\n   apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n   apply(rule right_quotient_word_Some_by_append)\n   apply(force)\n  apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n  apply(clarsimp)\n  apply(rule sym)\n  apply(rule_tac\n      t=\"right_quotient_word (wa @ option_to_list (edge_event e2) @ epdaS_conf_scheduler c2) (option_to_list (edge_event e2) @ epdaS_conf_scheduler c2)\"\n      and s=\"Some wa\"\n      in ssubst)\n   apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n   apply(rule right_quotient_word_Some_by_append)\n   apply(force)\n  apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n  apply(force)\n  done\n\nlemma epdaS2epdaHS_derivation_preserves_belongs: \"\n  valid_epda P\n  \\<Longrightarrow> epdaS.belongs P d\n  \\<Longrightarrow> epdaS.derivation P d\n  \\<Longrightarrow> epdaHS.belongs P (epdaS2epdaHS_derivation P d)\"\n  apply(subgoal_tac \"\\<exists>c. d 0 = Some (pair None c)\")\n   prefer 2\n   apply(rule epdaS.some_position_has_details_at_0)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac c)(*strict*)\n  apply(rule_tac epdaHS.derivation_belongs)\n     apply(rename_tac c)(*strict*)\n     apply(force)\n    apply(rename_tac c)(*strict*)\n    prefer 3\n    apply(rule epdaS2epdaHS_derivation_preserves_derivation)\n      apply(rename_tac c)(*strict*)\n      apply(force)\n     apply(rename_tac c)(*strict*)\n     apply(force)\n    apply(rename_tac c)(*strict*)\n    apply(force)\n   apply(rename_tac c)(*strict*)\n   apply(simp add: epdaS2epdaHS_derivation_def)\n  apply(rename_tac c)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(rule_tac\n      t=\"right_quotient_word (epdaS_conf_scheduler c) (epdaS_conf_scheduler c)\"\n      and s=\"Some []\"\n      in ssubst)\n   apply(rename_tac c)(*strict*)\n   apply (metis right_quotient_word_full)\n  apply(rename_tac c)(*strict*)\n  apply(subgoal_tac \"c \\<in> epdaS_configurations P\")\n   apply(rename_tac c)(*strict*)\n   apply(simp add: epdaHS_configurations_def epdaS_configurations_def)\n   apply(clarsimp)\n  apply(rename_tac c)(*strict*)\n  apply(rule epdaS.belongs_configurations)\n   apply(rename_tac c)(*strict*)\n   apply(force)\n  apply(rename_tac c)(*strict*)\n  apply(force)\n  done\n\nlemma translate_epdaS_der_to_epdaH_der: \"\nvalid_dpda G\n  \\<Longrightarrow> epdaS.derivation G d\n  \\<Longrightarrow> epdaS.belongs G d\n  \\<Longrightarrow> d 0 = Some (pair None \\<lparr>epdaS_conf_state = q1, epdaS_conf_scheduler = hx, epdaS_conf_stack = ba # s\\<rparr>)\n  \\<Longrightarrow> d j = Some (pair e \\<lparr>epdaS_conf_state = q, epdaS_conf_scheduler = [], epdaS_conf_stack = ba # s\\<rparr>)\n  \\<Longrightarrow> \\<forall>k\\<le>j. \\<forall>e c. d k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ ba # s)\n  \\<Longrightarrow> d (Suc j) = Some (pair e' \\<lparr>epdaS_conf_state = q2, epdaS_conf_scheduler = [], epdaS_conf_stack = s\\<rparr>)\n  \\<Longrightarrow> \\<exists>d1'. epdaH.derivation G d1' \\<and> epdaH.belongs G d1' \\<and> d1' 0 = Some (pair None \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = [], epdaH_conf_stack = ba # s\\<rparr>) \\<and> d1' j = Some (pair e \\<lparr>epdaH_conf_state = q, epdaH_conf_history = hx, epdaH_conf_stack = ba # s\\<rparr>) \\<and> (\\<forall>k\\<le>j. \\<forall>e c. d1' k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaH_conf_stack c = w @ ba # s)) \\<and> d1' (Suc j) = Some (pair e' \\<lparr>epdaH_conf_state = q2, epdaH_conf_history = hx, epdaH_conf_stack = s\\<rparr>)\"\n  apply(simp add: valid_dpda_def valid_pda_def)\n  apply(rule_tac\n      x=\"epdaH_vs_epdaHS.Lin2BraDer (epdaS2epdaHS_derivation G d)\"\n      in exI)\n  apply(rule context_conjI)\n   apply(rule epdaH_vs_epdaHS.Lin2BraConf_preserves_steps_lift)\n     apply(force)\n    apply(rule epdaS2epdaHS_derivation_preserves_derivation)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(rule epdaS2epdaHS_derivation_preserves_belongs)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(rule conjI)\n   apply(rule epdaH_vs_epdaHS.Lin2BraDer_preserves_belongs)\n     apply(force)\n    apply(rule epdaS2epdaHS_derivation_preserves_derivation)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(rule epdaS2epdaHS_derivation_preserves_belongs)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(rule conjI)\n   apply(simp add: get_configuration_def epdaHvHS_Lin2BraConf_def epdaH_vs_epdaHS.Lin2BraDer_def epdaS2epdaHS_derivation_def derivation_map_def)\n   apply(rule_tac\n      t=\"right_quotient_word hx hx\"\n      and s=\"Some []\"\n      in ssubst)\n    apply (metis right_quotient_word_full)\n   apply(force)\n  apply(rule conjI)\n   apply(simp add: get_configuration_def epdaHvHS_Lin2BraConf_def epdaH_vs_epdaHS.Lin2BraDer_def epdaS2epdaHS_derivation_def derivation_map_def)\n   apply(rule_tac\n      t=\"right_quotient_word hx []\"\n      and s=\"Some hx\"\n      in ssubst)\n    apply (metis right_quotient_word_neutral)\n   apply(force)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(rename_tac k ea c)(*strict*)\n   apply(subgoal_tac \"\\<exists>e c. d k = Some (pair e c)\")\n    apply(rename_tac k ea c)(*strict*)\n    prefer 2\n    apply(rule_tac\n      m=\"j\"\n      in epdaS.pre_some_position_is_some_position)\n      apply(rename_tac k ea c)(*strict*)\n      apply(force)\n     apply(rename_tac k ea c)(*strict*)\n     apply(force)\n    apply(rename_tac k ea c)(*strict*)\n    apply(force)\n   apply(rename_tac k ea c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac k ea c eaa ca)(*strict*)\n   apply(erule_tac\n      x=\"k\"\n      in allE)\n   apply(clarsimp)\n   apply(rename_tac k ea c eaa ca w)(*strict*)\n   apply(simp add: get_configuration_def epdaHvHS_Lin2BraConf_def epdaH_vs_epdaHS.Lin2BraDer_def epdaS2epdaHS_derivation_def derivation_map_def)\n   apply(clarsimp)\n  apply(simp add: get_configuration_def epdaHvHS_Lin2BraConf_def epdaH_vs_epdaHS.Lin2BraDer_def epdaS2epdaHS_derivation_def derivation_map_def)\n  apply(clarsimp)\n  apply(rule_tac\n      t=\"right_quotient_word hx []\"\n      and s=\"Some hx\"\n      in ssubst)\n   apply (metis right_quotient_word_neutral)\n  apply(force)\n  done\n\nlemma DPDA_edge_pop_single: \"\n  valid_dpda G\n  \\<Longrightarrow> e \\<in> epda_delta G\n  \\<Longrightarrow> \\<exists>x. edge_pop e=[x]\"\n  apply(simp add: valid_dpda_def valid_pda_def)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"e\"\n      in ballE)\n   apply(case_tac \"e\")\n   apply(rename_tac edge_src edge_event edge_popa edge_push edge_trg)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac edge_src edge_event edge_pop edge_push edge_trg)(*strict*)\n   apply(case_tac edge_pop)\n    apply(rename_tac edge_src edge_event edge_pop edge_push edge_trg)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac edge_src edge_event edge_pop edge_push edge_trg a list)(*strict*)\n   apply(clarsimp)\n  apply(force)\n  done\n\nlemma epdaH_drop_unused_stack: \"\n       valid_dpda G\n  \\<Longrightarrow> \\<exists>d1'. epdaH.derivation G d1' \\<and> epdaH.belongs G d1' \\<and> d1' 0 = Some (pair None \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = [], epdaH_conf_stack = ba # s\\<rparr>) \\<and> d1' j = Some (pair e \\<lparr>epdaH_conf_state = q, epdaH_conf_history = \\<alpha>, epdaH_conf_stack = ba # s\\<rparr>) \\<and> (\\<forall>k\\<le>j. \\<forall>e c. d1' k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaH_conf_stack c = w @ ba # s)) \\<and> d1' (Suc j) = Some (pair e' \\<lparr>epdaH_conf_state = q2, epdaH_conf_history = \\<alpha>, epdaH_conf_stack = s\\<rparr>)\n  \\<Longrightarrow> \\<exists>d1'. epdaH.derivation G d1' \\<and> epdaH.belongs G d1' \\<and> d1' 0 = Some (pair None \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = [], epdaH_conf_stack = [ba]\\<rparr>) \\<and> d1' j = Some (pair e \\<lparr>epdaH_conf_state = q, epdaH_conf_history = \\<alpha>, epdaH_conf_stack = [ba]\\<rparr>) \\<and> (\\<forall>k\\<le>j. \\<forall>e c. d1' k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaH_conf_stack c = w @ [ba])) \\<and> d1' (Suc j) = Some (pair e' \\<lparr>epdaH_conf_state = q2, epdaH_conf_history = \\<alpha>, epdaH_conf_stack = []\\<rparr>)\"\n  apply(clarsimp)\n  apply(rename_tac d1')(*strict*)\n  apply(rule_tac\n      x=\"derivation_map (derivation_take d1' (Suc j)) (\\<lambda>c. c\\<lparr>epdaH_conf_stack:=butn(epdaH_conf_stack c)(length s)\\<rparr>)\"\n      in exI)\n  apply(rule context_conjI)\n   apply(rename_tac d1')(*strict*)\n   apply(rule_tac\n      P=\"\\<lambda>c. (\\<exists>w. epdaH_conf_stack c = w @ ba # s)\"\n      in epdaH.derivation_map_preserves_derivation23_VAR2)\n     apply(rename_tac d1')(*strict*)\n     apply(force)\n    apply(rename_tac d1')(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1' i ea c)(*strict*)\n    apply(erule_tac\n      x=\"i\"\n      in allE)\n    apply(clarsimp)\n   apply(rename_tac d1')(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d1' a ea b w)(*strict*)\n   apply(simp add: epdaH_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac d1' a ea b w wa)(*strict*)\n   apply(case_tac a)\n   apply(rename_tac d1' a ea b w wa epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d1' ea b w wa epdaH_conf_historya)(*strict*)\n   apply(case_tac b)\n   apply(rename_tac d1' ea b w wa epdaH_conf_historya epdaH_conf_statea epdaH_conf_historyaa epdaH_conf_stacka)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d1' ea w wa)(*strict*)\n   apply(rule_tac\n      t=\"edge_pop ea @ wa\"\n      and s=\"w @ ba # s\"\n      in ssubst)\n    apply(rename_tac d1' ea w wa)(*strict*)\n    apply(force)\n   apply(rename_tac d1' ea w wa)(*strict*)\n   apply(rule_tac\n      t=\"butn (w @ ba # s) (length s)\"\n      and s=\"w@[ba]\"\n      in ssubst)\n    apply(rename_tac d1' ea w wa)(*strict*)\n    apply(rule_tac\n      t=\"w@ba#s\"\n      and s=\"(w@[ba])@s\"\n      in ssubst)\n     apply(rename_tac d1' ea w wa)(*strict*)\n     apply(force)\n    apply(rename_tac d1' ea w wa)(*strict*)\n    apply (metis butn_prefix_closureise)\n   apply(rename_tac d1' ea w wa)(*strict*)\n   apply(subgoal_tac \"\\<exists>x. edge_pop ea=[x]\")\n    apply(rename_tac d1' ea w wa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1' ea w wa x)(*strict*)\n    apply(case_tac w)\n     apply(rename_tac d1' ea w wa x)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac d1' ea)(*strict*)\n     apply (metis butn_prefix_closureise)\n    apply(rename_tac d1' ea w wa x a list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1' ea x list)(*strict*)\n    apply(rule_tac\n      t=\"edge_push ea @ list @ ba # s\"\n      and s=\"(edge_push ea @ list @ [ba]) @ s\"\n      in ssubst)\n     apply(rename_tac d1' ea x list)(*strict*)\n     apply(force)\n    apply(rename_tac d1' ea x list)(*strict*)\n    apply (metis butn_prefix_closureise)\n   apply(rename_tac d1' ea w wa)(*strict*)\n   apply(rule DPDA_edge_pop_single)\n    apply(rename_tac d1' ea w wa)(*strict*)\n    apply(force)\n   apply(rename_tac d1' ea w wa)(*strict*)\n   apply(force)\n  apply(rename_tac d1')(*strict*)\n  apply(rule conjI)\n   apply(rename_tac d1')(*strict*)\n   apply(rule epdaH.derivation_belongs)\n      apply(rename_tac d1')(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def)\n     apply(rename_tac d1')(*strict*)\n     apply(simp add: derivation_map_def derivation_take_def)\n    apply(rename_tac d1')(*strict*)\n    apply(subgoal_tac \"\\<lparr>epdaH_conf_state = q1, epdaH_conf_history = [], epdaH_conf_stack = ba # s\\<rparr> \\<in> epdaH_configurations G\")\n     apply(rename_tac d1')(*strict*)\n     apply(simp add: epdaH_configurations_def)\n     apply(rule_tac\n      t=\"ba#s\"\n      and s=\"[ba]@s\"\n      in ssubst)\n      apply(rename_tac d1')(*strict*)\n      apply(force)\n     apply(rename_tac d1')(*strict*)\n     apply(rule_tac\n      t=\"butn ([ba] @ s) (length s)\"\n      and s=\"[ba]\"\n      in ssubst)\n      apply(rename_tac d1')(*strict*)\n      apply (metis butn_prefix_closureise)\n     apply(rename_tac d1')(*strict*)\n     apply(force)\n    apply(rename_tac d1')(*strict*)\n    apply(rule epdaH.belongs_configurations)\n     apply(rename_tac d1')(*strict*)\n     apply(force)\n    apply(rename_tac d1')(*strict*)\n    apply(force)\n   apply(rename_tac d1')(*strict*)\n   apply(force)\n  apply(rename_tac d1')(*strict*)\n  apply(rule conjI)\n   apply(rename_tac d1')(*strict*)\n   apply(simp add: derivation_map_def derivation_take_def)\n   apply(rule_tac\n      t=\"ba#s\"\n      and s=\"[ba]@s\"\n      in ssubst)\n    apply(rename_tac d1')(*strict*)\n    apply(force)\n   apply(rename_tac d1')(*strict*)\n   apply(rule_tac\n      t=\"butn ([ba] @ s) (length s)\"\n      and s=\"[ba]\"\n      in ssubst)\n    apply(rename_tac d1')(*strict*)\n    apply (metis butn_prefix_closureise)\n   apply(rename_tac d1')(*strict*)\n   apply(force)\n  apply(rename_tac d1')(*strict*)\n  apply(rule conjI)\n   apply(rename_tac d1')(*strict*)\n   apply(simp add: derivation_map_def derivation_take_def)\n   apply(rule_tac\n      t=\"ba#s\"\n      and s=\"[ba]@s\"\n      in ssubst)\n    apply(rename_tac d1')(*strict*)\n    apply(force)\n   apply(rename_tac d1')(*strict*)\n   apply(rule_tac\n      t=\"butn ([ba] @ s) (length s)\"\n      and s=\"[ba]\"\n      in ssubst)\n    apply(rename_tac d1')(*strict*)\n    apply (metis butn_prefix_closureise)\n   apply(rename_tac d1')(*strict*)\n   apply(force)\n  apply(rename_tac d1')(*strict*)\n  apply(rule conjI)\n   apply(rename_tac d1')(*strict*)\n   apply(simp add: derivation_map_def derivation_take_def)\n   apply(clarsimp)\n   apply(rename_tac d1' k ea c)(*strict*)\n   apply(erule_tac\n      x=\"k\"\n      in allE)\n   apply(clarsimp)\n   apply(subgoal_tac \"\\<exists>e c. d1' k = Some (pair e c)\")\n    apply(rename_tac d1' k ea c)(*strict*)\n    prefer 2\n    apply(rule_tac\n      m=\"Suc j\"\n      in epdaH.pre_some_position_is_some_position)\n      apply(rename_tac d1' k ea c)(*strict*)\n      apply(force)\n     apply(rename_tac d1' k ea c)(*strict*)\n     apply(force)\n    apply(rename_tac d1' k ea c)(*strict*)\n    apply(force)\n   apply(rename_tac d1' k ea c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d1' k ea ca w)(*strict*)\n   apply(rule_tac\n      t=\"w@ba#s\"\n      and s=\"(w@[ba])@s\"\n      in ssubst)\n    apply(rename_tac d1' k ea ca w)(*strict*)\n    apply(force)\n   apply(rename_tac d1' k ea ca w)(*strict*)\n   apply(rule_tac\n      x=\"w\"\n      in exI)\n   apply (metis butn_prefix_closureise)\n  apply(rename_tac d1')(*strict*)\n  apply(simp add: derivation_map_def derivation_take_def)\n  apply (metis butn_empty_prime_prime)\n  done\n\nlemma lessI_X: \"\n  n\\<noteq>(0::nat)\n  \\<Longrightarrow> a+n=b\n  \\<Longrightarrow> a<b\"\n  apply(force)\n  done\n\nlemma Reachable_epdaS_produce_from_before_pop_CFGprodXORelim: \"\n  valid_dpda G\n  \\<Longrightarrow> epdaH.trans_der G dX \\<lparr>epdaH_conf_state=epda_initial G,epdaH_conf_history=[],epdaH_conf_stack=[epda_box G]\\<rparr> \\<pi> \\<lparr>epdaH_conf_state=q1,epdaH_conf_history=h,epdaH_conf_stack=[ba]@sX\\<rparr>\n  \\<Longrightarrow> [] \\<in> epdaS_produce_from_before_pop G q1 ba q2\n  \\<Longrightarrow> \\<exists>\\<alpha>. b#\\<alpha> \\<in> epdaS_produce_from_before_pop G q1 ba q2\n  \\<Longrightarrow> Q\"\n  apply(simp add: epdaS_produce_from_before_pop_def)\n  apply(clarsimp)\n  apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n  apply(subgoal_tac \"\\<exists>d1'. epdaH.derivation G d1' \\<and> epdaH.belongs G d1' \\<and> d1' 0 = Some (pair None \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = [], epdaH_conf_stack = ba # s\\<rparr>) \\<and> d1' j = Some (pair e \\<lparr>epdaH_conf_state = q, epdaH_conf_history = [], epdaH_conf_stack = ba # s\\<rparr>) \\<and> (\\<forall>k\\<le>j. \\<forall>e c. d1' k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaH_conf_stack c = w @ ba # s)) \\<and> d1' (Suc j) = Some (pair e' \\<lparr>epdaH_conf_state = q2, epdaH_conf_history = [], epdaH_conf_stack = s\\<rparr>)\")\n   apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n   prefer 2\n   apply(thin_tac \"da 0 = Some (pair None \\<lparr>epdaS_conf_state = q1, epdaS_conf_scheduler = b # \\<alpha>, epdaS_conf_stack = ba # sa\\<rparr>)\")\n   apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n   apply(thin_tac \"epdaS.derivation G da\")\n   apply(thin_tac \"epdaS.belongs G da\")\n   apply(thin_tac \"da ja = Some (pair ea \\<lparr>epdaS_conf_state = qa, epdaS_conf_scheduler = [], epdaS_conf_stack = ba # sa\\<rparr>)\")\n   apply(thin_tac \"\\<forall>k\\<le>ja. \\<forall>e c. da k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ ba # sa)\")\n   apply(thin_tac \"da (Suc ja) = Some (pair e'a \\<lparr>epdaS_conf_state = q2, epdaS_conf_scheduler = [], epdaS_conf_stack = sa\\<rparr>)\")\n   apply(thin_tac \"epdaH.trans_der G dX \\<lparr>epdaH_conf_state = epda_initial G, epdaH_conf_history = [], epdaH_conf_stack = [epda_box G]\\<rparr> \\<pi> \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = h, epdaH_conf_stack = ba # sX\\<rparr>\")\n   apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n   apply(rule translate_epdaS_der_to_epdaH_der)\n         apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n         apply(force)\n        apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n        apply(force)\n       apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n       apply(force)\n      apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n      apply(force)\n     apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n     apply(force)\n    apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n    apply(force)\n   apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n   apply(force)\n  apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n  apply(subgoal_tac \"\\<exists>d2'. epdaH.derivation G d2' \\<and> epdaH.belongs G d2' \\<and> d2' 0 = Some (pair None \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = [], epdaH_conf_stack = ba # sa\\<rparr>) \\<and> d2' ja = Some (pair ea \\<lparr>epdaH_conf_state = qa, epdaH_conf_history = b#\\<alpha>, epdaH_conf_stack = ba # sa\\<rparr>) \\<and> (\\<forall>k\\<le>ja. \\<forall>e c. d2' k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaH_conf_stack c = w @ ba # sa)) \\<and> d2' (Suc ja) = Some (pair e'a \\<lparr>epdaH_conf_state = q2, epdaH_conf_history = b#\\<alpha>, epdaH_conf_stack = sa\\<rparr>)\")\n   apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n   prefer 2\n   apply(thin_tac \"epdaS.derivation G d\")\n   apply(thin_tac \"epdaS.belongs G d\")\n   apply(thin_tac \"d 0 = Some (pair None \\<lparr>epdaS_conf_state = q1, epdaS_conf_scheduler = [], epdaS_conf_stack = ba # s\\<rparr>)\")\n   apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n   apply(thin_tac \"d j = Some (pair e \\<lparr>epdaS_conf_state = q, epdaS_conf_scheduler = [], epdaS_conf_stack = ba # s\\<rparr>)\")\n   apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n   apply(thin_tac \"\\<forall>k\\<le>j. \\<forall>e c. d k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ ba # s)\")\n   apply(thin_tac \"d (Suc j) = Some (pair e' \\<lparr>epdaS_conf_state = q2, epdaS_conf_scheduler = [], epdaS_conf_stack = s\\<rparr>)\")\n   apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n   apply(thin_tac \"\\<exists>d1'. epdaH.derivation G d1' \\<and> epdaH.belongs G d1' \\<and> d1' 0 = Some (pair None \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = [], epdaH_conf_stack = ba # s\\<rparr>) \\<and> d1' j = Some (pair e \\<lparr>epdaH_conf_state = q, epdaH_conf_history = [], epdaH_conf_stack = ba # s\\<rparr>) \\<and> (\\<forall>k\\<le>j. \\<forall>e c. d1' k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaH_conf_stack c = w @ ba # s)) \\<and> d1' (Suc j) = Some (pair e' \\<lparr>epdaH_conf_state = q2, epdaH_conf_history = [], epdaH_conf_stack = s\\<rparr>)\")\n   apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n   apply(thin_tac \"epdaH.trans_der G dX \\<lparr>epdaH_conf_state = epda_initial G, epdaH_conf_history = [], epdaH_conf_stack = [epda_box G]\\<rparr> \\<pi> \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = h, epdaH_conf_stack = ba # sX\\<rparr>\")\n   apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n   apply(rule translate_epdaS_der_to_epdaH_der)\n         apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n         apply(force)\n        apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n        apply(force)\n       apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n       apply(force)\n      apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n      apply(force)\n     apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n     apply(force)\n    apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n    apply(force)\n   apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n   apply(force)\n  apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n  apply(thin_tac \"epdaS.derivation G d\")\n  apply(thin_tac \"epdaS.belongs G d\")\n  apply(thin_tac \"d 0 = Some (pair None \\<lparr>epdaS_conf_state = q1, epdaS_conf_scheduler = [], epdaS_conf_stack = ba # s\\<rparr>)\")\n  apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n  apply(thin_tac \"d j = Some (pair e \\<lparr>epdaS_conf_state = q, epdaS_conf_scheduler = [], epdaS_conf_stack = ba # s\\<rparr>)\")\n  apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n  apply(thin_tac \"\\<forall>k\\<le>j. \\<forall>e c. d k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ ba # s)\")\n  apply(thin_tac \"d (Suc j) = Some (pair e' \\<lparr>epdaS_conf_state = q2, epdaS_conf_scheduler = [], epdaS_conf_stack = s\\<rparr>)\")\n  apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n  apply(thin_tac \"da 0 = Some (pair None \\<lparr>epdaS_conf_state = q1, epdaS_conf_scheduler = b # \\<alpha>, epdaS_conf_stack = ba # sa\\<rparr>)\")\n  apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n  apply(thin_tac \"epdaS.derivation G da\")\n  apply(thin_tac \"epdaS.belongs G da\")\n  apply(thin_tac \"da ja = Some (pair ea \\<lparr>epdaS_conf_state = qa, epdaS_conf_scheduler = [], epdaS_conf_stack = ba # sa\\<rparr>)\")\n  apply(thin_tac \"\\<forall>k\\<le>ja. \\<forall>e c. da k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaS_conf_stack c = w @ ba # sa)\")\n  apply(thin_tac \"da (Suc ja) = Some (pair e'a \\<lparr>epdaS_conf_state = q2, epdaS_conf_scheduler = [], epdaS_conf_stack = sa\\<rparr>)\")\n  apply(subgoal_tac \"\\<exists>d1'. epdaH.derivation G d1' \\<and> epdaH.belongs G d1' \\<and> d1' 0 = Some (pair None \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = [], epdaH_conf_stack = [ba]\\<rparr>) \\<and> d1' j = Some (pair e \\<lparr>epdaH_conf_state = q, epdaH_conf_history = [], epdaH_conf_stack = [ba]\\<rparr>) \\<and> (\\<forall>k\\<le>j. \\<forall>e c. d1' k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaH_conf_stack c = w @ [ba])) \\<and> d1' (Suc j) = Some (pair e' \\<lparr>epdaH_conf_state = q2, epdaH_conf_history = [], epdaH_conf_stack = []\\<rparr>)\")\n   apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n   prefer 2\n   apply(thin_tac \"\\<exists>d2'. epdaH.derivation G d2' \\<and> epdaH.belongs G d2' \\<and> d2' 0 = Some (pair None \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = [], epdaH_conf_stack = ba # sa\\<rparr>) \\<and> d2' ja = Some (pair ea \\<lparr>epdaH_conf_state = qa, epdaH_conf_history = b # \\<alpha>, epdaH_conf_stack = ba # sa\\<rparr>) \\<and> (\\<forall>k\\<le>ja. \\<forall>e c. d2' k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaH_conf_stack c = w @ ba # sa)) \\<and> d2' (Suc ja) = Some (pair e'a \\<lparr>epdaH_conf_state = q2, epdaH_conf_history = b # \\<alpha>, epdaH_conf_stack = sa\\<rparr>)\")\n   apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n   apply(thin_tac \"epdaH.trans_der G dX \\<lparr>epdaH_conf_state = epda_initial G, epdaH_conf_history = [], epdaH_conf_stack = [epda_box G]\\<rparr> \\<pi> \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = h, epdaH_conf_stack = ba # sX\\<rparr>\")\n   apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n   apply(rule_tac\n      s=\"s\"\n      in epdaH_drop_unused_stack)\n    apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n    apply(force)\n   apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n   apply(force)\n  apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n  apply(subgoal_tac \"\\<exists>d2'. epdaH.derivation G d2' \\<and> epdaH.belongs G d2' \\<and> d2' 0 = Some (pair None \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = [], epdaH_conf_stack = [ba]\\<rparr>) \\<and> d2' ja = Some (pair ea \\<lparr>epdaH_conf_state = qa, epdaH_conf_history = b#\\<alpha>, epdaH_conf_stack = [ba]\\<rparr>) \\<and> (\\<forall>k\\<le>ja. \\<forall>e c. d2' k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaH_conf_stack c = w @ [ba])) \\<and> d2' (Suc ja) = Some (pair e'a \\<lparr>epdaH_conf_state = q2, epdaH_conf_history = b#\\<alpha>, epdaH_conf_stack = []\\<rparr>)\")\n   apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n   prefer 2\n   apply(thin_tac \"\\<exists>d1'. epdaH.derivation G d1' \\<and> epdaH.belongs G d1' \\<and> d1' 0 = Some (pair None \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = [], epdaH_conf_stack = ba # s\\<rparr>) \\<and> d1' j = Some (pair e \\<lparr>epdaH_conf_state = q, epdaH_conf_history = [], epdaH_conf_stack = ba # s\\<rparr>) \\<and> (\\<forall>k\\<le>j. \\<forall>e c. d1' k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaH_conf_stack c = w @ ba # s)) \\<and> d1' (Suc j) = Some (pair e' \\<lparr>epdaH_conf_state = q2, epdaH_conf_history = [], epdaH_conf_stack = s\\<rparr>)\")\n   apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n   apply(thin_tac \"\\<exists>d1'. epdaH.derivation G d1' \\<and> epdaH.belongs G d1' \\<and> d1' 0 = Some (pair None \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = [], epdaH_conf_stack = [ba]\\<rparr>) \\<and> d1' j = Some (pair e \\<lparr>epdaH_conf_state = q, epdaH_conf_history = [], epdaH_conf_stack = [ba]\\<rparr>) \\<and> (\\<forall>k\\<le>j. \\<forall>e c. d1' k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaH_conf_stack c = w @ [ba])) \\<and> d1' (Suc j) = Some (pair e' \\<lparr>epdaH_conf_state = q2, epdaH_conf_history = [], epdaH_conf_stack = []\\<rparr>)\")\n   apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n   apply(thin_tac \"epdaH.trans_der G dX \\<lparr>epdaH_conf_state = epda_initial G, epdaH_conf_history = [], epdaH_conf_stack = [epda_box G]\\<rparr> \\<pi> \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = h, epdaH_conf_stack = ba # sX\\<rparr>\")\n   apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n   apply(rule_tac\n      s=\"sa\"\n      in epdaH_drop_unused_stack)\n    apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n    apply(force)\n   apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n   apply(force)\n  apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n  apply(thin_tac \"\\<exists>d1'. epdaH.derivation G d1' \\<and> epdaH.belongs G d1' \\<and> d1' 0 = Some (pair None \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = [], epdaH_conf_stack = ba # s\\<rparr>) \\<and> d1' j = Some (pair e \\<lparr>epdaH_conf_state = q, epdaH_conf_history = [], epdaH_conf_stack = ba # s\\<rparr>) \\<and> (\\<forall>k\\<le>j. \\<forall>e c. d1' k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaH_conf_stack c = w @ ba # s)) \\<and> d1' (Suc j) = Some (pair e' \\<lparr>epdaH_conf_state = q2, epdaH_conf_history = [], epdaH_conf_stack = s\\<rparr>)\")\n  apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n  apply(thin_tac \"\\<exists>d2'. epdaH.derivation G d2' \\<and> epdaH.belongs G d2' \\<and> d2' 0 = Some (pair None \\<lparr>epdaH_conf_state = q1, epdaH_conf_history = [], epdaH_conf_stack = ba # sa\\<rparr>) \\<and> d2' ja = Some (pair ea \\<lparr>epdaH_conf_state = qa, epdaH_conf_history = b # \\<alpha>, epdaH_conf_stack = ba # sa\\<rparr>) \\<and> (\\<forall>k\\<le>ja. \\<forall>e c. d2' k = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaH_conf_stack c = w @ ba # sa)) \\<and> d2' (Suc ja) = Some (pair e'a \\<lparr>epdaH_conf_state = q2, epdaH_conf_history = b # \\<alpha>, epdaH_conf_stack = sa\\<rparr>)\")\n  apply(rename_tac d \\<alpha> da q s qa sa j ja e ea e' e'a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n  apply(subgoal_tac \"strict_prefix (map the (get_labels d1' (Suc j))) (map the (get_labels d2' (Suc ja)))\")\n   apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n   apply(subgoal_tac \"Suc j<Suc ja\")\n    apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n    prefer 2\n    apply(simp only: strict_prefix_def)\n    apply(erule exE)+\n    apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n    apply(rule_tac\n      n=\"length c\"\n      in lessI_X)\n     apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n     apply(force)\n    apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n    apply(rule_tac\n      t=\"Suc j + length c\"\n      and s=\"length(map the (get_labels d1' (Suc j)) @ c)\"\n      in ssubst)\n     apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n     apply(simp (no_asm))\n     apply (metis get_labels_length)\n    apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n    apply(rule_tac\n      t=\"map the (get_labels d1' (Suc j)) @ c\"\n      and s=\"map the (get_labels d2' (Suc ja))\"\n      in ssubst)\n     apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n     apply(force)\n    apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n    apply(simp (no_asm))\n    apply (metis get_labels_length)\n   apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"d1' (Suc j) = d2' (Suc j)\")\n    apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"Suc j\"\n      and P=\"\\<lambda>X. X \\<le> ja \\<longrightarrow> (\\<forall>e c. d2' X = Some (pair e c) \\<longrightarrow> (\\<exists>w. epdaH_conf_stack c = w @ [ba]))\"\n      in allE)\n    apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n    apply(erule impE)\n     apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n     apply(force)\n    apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n    apply(force)\n   apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n   apply(subgoal_tac \"(\\<forall>i\\<le>Suc j. d1' i = d2' i)\")\n    apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n    apply(force)\n   apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n   apply(rule_tac\n      x=\"0\"\n      and y=\"ja-j\"\n      and n=\"Suc j\"\n      in epdaH.equal_labels_is_forward_target_deterministic_coinciding_positions)\n           apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n           apply(simp add: valid_dpda_def valid_pda_def)\n           apply(force)\n          apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n          apply(rule epda_is_forward_target_deterministic)\n          apply(simp add: valid_dpda_def valid_pda_def)\n         apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n         apply(force)\n        apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n        apply(force)\n       apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n       apply(force)\n      apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n      apply(simp add: strict_prefix_def)\n      apply(clarsimp)\n      apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n      apply(subgoal_tac \"get_labels SSd (SSn + SSm) = get_labels SSd SSn @ drop SSn (get_labels SSd (SSn + SSm))\" for SSd SSn SSm)\n       apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n       prefer 2\n       apply(rule_tac\n      d=\"d2'\"\n      and n=\"Suc j\"\n      and m=\"Suc ja-Suc j\"\n      in get_labels_decomp)\n      apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n      apply(clarsimp)\n      apply(subgoal_tac \"get_labels d1' (Suc j) = map (Some \\<circ> the) (get_labels SSd SSn)\" for SSd SSn)\n       apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n       prefer 2\n       apply(rule epdaH.get_labels_the_Some_on_defined_positions)\n        apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n        apply(force)\n       apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n       apply(force)\n      apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n      apply(subgoal_tac \"get_labels d2' (Suc j) = map (Some \\<circ> the) (get_labels SSd SSn)\" for SSd SSn)\n       apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n       prefer 2\n       apply(rule epdaH.get_labels_the_Some_on_defined_positions)\n        apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n        apply(force)\n       apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n       apply(subgoal_tac \"\\<exists>e c. d2' (Suc j) = Some (pair e c)\")\n        apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n        prefer 2\n        apply(rule_tac\n      m=\"Suc ja\"\n      in epdaH.pre_some_position_is_some_position)\n          apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n          apply(force)\n         apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n         apply(force)\n        apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n        apply(force)\n       apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n       apply(force)\n      apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n      apply(subgoal_tac \"get_labels d2' (Suc ja) = map (Some \\<circ> the) (get_labels SSd SSn)\" for SSd SSn)\n       apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n       prefer 2\n       apply(rule epdaH.get_labels_the_Some_on_defined_positions)\n        apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n        apply(force)\n       apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n       apply(force)\n      apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n      apply(rule_tac\n      v=\"drop (Suc j) (get_labels d2' (Suc ja))\"\n      in append_injr)\n      apply(rule_tac\n      t=\"get_labels d2' (Suc j) @ drop (Suc j) (get_labels d2' (Suc ja))\"\n      and s=\"get_labels d2' (Suc ja)\"\n      in ssubst)\n       apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n       apply(force)\n      apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n      apply(rule_tac\n      t=\"get_labels d2' (Suc ja)\"\n      and s=\"map (Some \\<circ> the) (get_labels d2' (Suc ja))\"\n      in ssubst)\n       apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n       apply(force)\n      apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n      apply(rule_tac\n      t=\"map (Some \\<circ> the) (get_labels d2' (Suc ja))\"\n      and s=\" map Some (map the (get_labels d2' (Suc ja))) \"\n      in ssubst)\n       apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n       apply(force)\n      apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n      apply(rule_tac\n      t=\"map the (get_labels d2' (Suc ja))\"\n      and s=\"map the (get_labels d1' (Suc j)) @ c\"\n      in ssubst)\n       apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n       apply(force)\n      apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n      apply(rule_tac\n      t=\"map Some (map the (get_labels d1' (Suc j)) @ c)\"\n      and s=\" (map Some (map the (get_labels d1' (Suc j)))) @ map Some c\"\n      in ssubst)\n       apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n       apply (metis map_append)\n      apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n      apply(rule_tac\n      t=\"map Some (map the (get_labels d1' (Suc j)))\"\n      and s=\"get_labels d1' (Suc j)\"\n      in ssubst)\n       apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n       apply(force)\n      apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n      apply(rule_tac\n      t=\"drop (Suc j) (get_labels d1' (Suc j) @ map Some c)\"\n      and s=\"map Some c\"\n      in ssubst)\n       apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n       apply(subgoal_tac \"length (get_labels d1' (Suc j)) = Suc j\")\n        apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n        apply(force)\n       apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n       apply (metis get_labels_length)\n      apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' c)(*strict*)\n      apply(force)\n     apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n     apply(force)\n    apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n    apply(force)\n   apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n   apply(force)\n  apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n  apply(rule_tac\n      d=\"dX\"\n      and ?d1.0=\"d1'\"\n      and ?d2.0=\"d2'\"\n      and b=\"b\"\n      and h'=\"\\<alpha>\"\n      and ?s2.0=\"[]\"\n      in epdaH_nonconflicting_reachable_derivations_are_mutual_prefixing)\n     apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n     apply(force)\n    apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n    apply(force)\n   apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n   apply(simp add: epdaH.trans_der_def)\n   apply(clarsimp)\n   apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' eb)(*strict*)\n   apply(rule_tac\n      t=\"length (get_labels d1' (Suc j))\"\n      and s=\"Suc j\"\n      in ssubst)\n    apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' eb)(*strict*)\n    apply (metis get_labels_length)\n   apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' eb)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' eb)(*strict*)\n    apply(rule epdaH.get_labels_the_Some_on_defined_positions)\n     apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' eb)(*strict*)\n     apply(force)\n    apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' eb)(*strict*)\n    apply(force)\n   apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' eb)(*strict*)\n   apply(force)\n  apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2')(*strict*)\n  apply(simp add: epdaH.trans_der_def)\n  apply(clarsimp)\n  apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' eb)(*strict*)\n  apply(rule_tac\n      t=\"length (get_labels d2' (Suc ja))\"\n      and s=\"Suc ja\"\n      in ssubst)\n   apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' eb)(*strict*)\n   apply (metis get_labels_length)\n  apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' eb)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' eb)(*strict*)\n   apply(rule epdaH.get_labels_the_Some_on_defined_positions)\n    apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' eb)(*strict*)\n    apply(force)\n   apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' eb)(*strict*)\n   apply(force)\n  apply(rename_tac \\<alpha> q qa j ja e ea e' e'a d1' d2' eb)(*strict*)\n  apply(force)\n  done\n\nlemma epdaS_required_edges__vs__epdaH_required_edges__part1: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS_required_edges G \\<subseteq> epdaH_required_edges G\"\n  apply(simp add:   epdaS_required_edges_def epdaH_required_edges_def)\n  apply(clarsimp)\n  apply(rule_tac\n      x=\"epdaH_vs_epdaHS.Lin2BraDer (epdaS2epdaHS_derivation G d)\"\n      in exI)\n  apply(rule context_conjI)\n   apply(rule epdaH_vs_epdaHS.Lin2BraConf_preserves_initiality_lift)\n    apply(force)\n   apply (metis epdaS2epdaHS_derivation_preserves_derivation_initial)\n  apply(rule_tac x=\"n\" in exI)\n  apply(rule context_conjI)\n   apply(simp add: epdaS2epdaHS_derivation_def epdaH_vs_epdaHS.Lin2BraDer_def derivation_map_def)\n  apply(clarsimp)\n  apply(rule_tac x=\"k\" in exI)\n  apply(rule context_conjI)\n   apply(simp add: epdaS2epdaHS_derivation_def epdaH_vs_epdaHS.Lin2BraDer_def derivation_map_def)\n  apply(simp add: epdaS2epdaHS_derivation_def epdaH_vs_epdaHS.Lin2BraDer_def derivation_map_def)\n  apply(clarsimp)\n  apply(simp add: epdaS2epdaHS_derivation_def epdaH_vs_epdaHS.Lin2BraDer_def derivation_map_def epdaHvHS_Lin2BraConf_def epdaS_marking_configurations_def epdaH_marking_configurations_def epdaH_configurations_def epdaS_configurations_def)\n  apply(clarsimp)\n  apply(subgoal_tac \"right_quotient_word (epdaS_conf_scheduler (the (get_configuration (d 0))))\n                        [] =Some (epdaS_conf_scheduler (the (get_configuration (d 0))))\")\n   prefer 2\n   apply (metis right_quotient_word_neutral)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e c. d 0 = Some (pair e c)\")\n   apply(rename_tac k ea c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"n\"\n      in epdaS.pre_some_position_is_some_position)\n     apply(simp add: epdaS.derivation_initial_def)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(simp add: get_configuration_def)\n  apply(subgoal_tac \"cb \\<in> epdaS_configurations G\")\n   apply(simp add: epdaS_configurations_def)\n   apply(force)\n  apply(rule epdaS.belongs_configurations)\n   apply(rule epdaS.derivation_initial_belongs)\n    apply(force)\n   apply(force)\n  apply(force)\n  done\n\nlemma epdaS_required_edges__vs__epdaH_required_edges__part2: \"\n  valid_epda G\n  \\<Longrightarrow> epdaH_required_edges G \\<subseteq> epdaS_required_edges G\"\n  apply(simp add:   epdaS_required_edges_def epdaH_required_edges_def)\n  apply(clarsimp)\n  apply(rule_tac x=\"epdaHS2epdaS_derivation (epdaH_vs_epdaHS.Bra2LinDer G d k)\" in exI)\n  apply(rule context_conjI)\n   apply(rule epdaHS2epdaS_derivation_preserves_derivation_initial)\n    apply(force)\n   apply(rule epdaHS.derivation_initialI)\n    apply(rule epdaH_vs_epdaHS.Bra2LinDer_preserves_derivation)\n       apply(force)\n      apply(rule epdaH.derivation_initial_is_derivation)\n      apply(force)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(clarsimp)\n   apply(subgoal_tac \"X\" for X)\n    prefer 2\n    apply(rule_tac\n      d=\"d\" and n=\"k\"\n      in epdaH_vs_epdaHS.Bra2LinDer_preserves_belongs)\n       apply(force)\n      apply(rule epdaH.derivation_initial_is_derivation)\n      apply(force)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(simp add: get_configuration_def)\n   apply(subgoal_tac \"cb \\<in> epdaHS_configurations G\")\n    prefer 2\n    apply(rule_tac e=\"None\" and i=\"0\" in epdaHS.belongs_configurations)\n     apply(force)\n    apply(force)\n   apply(simp add: epdaH_vs_epdaHS.Bra2LinDer_def)\n   apply(case_tac cb)\n   apply(clarsimp)\n   apply(case_tac \"d 0\")\n    apply(clarsimp)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(clarsimp)\n   apply(simp add: epdaHvHS_Bra2LinConf_def)\n   apply(simp add: epdaH_vs_epdaHS.Bra2LinDer'_def)\n   apply(simp add: epdaHS_initial_configurations_def)\n   apply(simp add: epdaH.derivation_initial_def)\n   apply(clarsimp)\n   apply(simp add: epdaH_initial_configurations_def)\n  apply(rule_tac x=\"n\" in exI)\n  apply(rule conjI)\n   apply(simp add: epdaHS2epdaS_derivation_def epdaH_vs_epdaHS.Bra2LinDer_def)\n  apply(rule_tac x=\"k\" in exI)\n  apply(clarsimp)\n  apply(simp add: epdaHS2epdaS_derivation_def epdaH_vs_epdaHS.Bra2LinDer_def epdaHvHS_Bra2LinConf_def epdaS_marking_configurations_def epdaH_marking_configurations_def)\n  apply(rule context_conjI)\n   apply(simp add: epdaHS2epdaS_derivation_def epdaH_vs_epdaHS.Bra2LinDer_def epdaH_vs_epdaHS.Bra2LinDer'_def epdaHvHS_Bra2LinConf_def epdaS_marking_configurations_def epdaH_marking_configurations_def)\n   apply(case_tac k)\n    apply(force)\n   apply(clarsimp)\n   apply(subgoal_tac \"nat_seq (Suc (nat)) (nat)=[]\")\n    prefer 2\n    apply (metis lessI nat_seqEmpty)\n   apply(force)\n  apply(clarsimp)\n  apply(simp add: epdaS_configurations_def epdaH_configurations_def)\n  apply(clarsimp)\n  done\n\nlemma epdaS_required_edges__vs__epdaH_required_edges: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS_required_edges G = epdaH_required_edges G\"\n  apply(rule antisym)\n   apply(simp add: epdaS_required_edges__vs__epdaH_required_edges__part1 epdaS_required_edges__vs__epdaH_required_edges__part2)\n  apply(simp add: epdaS_required_edges__vs__epdaH_required_edges__part1 epdaS_required_edges__vs__epdaH_required_edges__part2)\n  done\n\nlemma stable_configuration_can_be_reached: \"\n  valid_dpda G \n  \\<Longrightarrow> \\<not> epdaH_livelock G \n  \\<Longrightarrow> c \\<in> epdaH.get_accessible_configurations G \n  \\<Longrightarrow> \\<exists>d n e c'. epdaH.derivation G d \\<and> epdaH.belongs G d \\<and> d 0 = Some (pair None c) \\<and> d n = Some (pair e c') \\<and> epdaH_conf_history c = epdaH_conf_history c' \\<and> (\\<forall>e' c''. epdaH_step_relation G c' e' c'' \\<longrightarrow> edge_event e' \\<noteq> None)\"\n  apply(simp add: epdaH.get_accessible_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac d i)(*strict*)\n  apply(case_tac \"d i\")\n   apply(rename_tac d i)(*strict*)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d i a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac d i a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i option b)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac d i option)(*strict*)\n  apply(rename_tac e)\n  apply(rename_tac d i e)(*strict*)\n  apply(case_tac \"\\<forall>n. \\<exists>c' e d. epdaH.derivation G d \\<and> epdaH.belongs G d \\<and> d 0 = Some (pair None c) \\<and> d n = Some (pair e c') \\<and> epdaH_conf_history c=epdaH_conf_history c' \")\n   apply(rename_tac d i e)(*strict*)\n   apply(subgoal_tac \"False\")\n    apply(rename_tac d i e)(*strict*)\n    apply(force)\n   apply(rename_tac d i e)(*strict*)\n   apply(simp add: epdaH_livelock_def)\n   apply(erule_tac\n      x=\"derivation_append d (\\<lambda>x. SOME y. \\<exists>c' e d. y=Some (pair e c') \\<and> epdaH.derivation G d \\<and> epdaH.belongs G d \\<and> d 0 = Some (pair None c) \\<and> d x = Some (pair e c') \\<and> epdaH_conf_history c = epdaH_conf_history c') i\"\n      in allE)\n   apply(rename_tac d i e)(*strict*)\n   apply(erule impE)\n    apply(rename_tac d i e)(*strict*)\n    apply(rule epdaH.derivation_append_preserves_derivation_initial)\n      apply(rename_tac d i e)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def)\n     apply(rename_tac d i e)(*strict*)\n     apply(force)\n    apply(rename_tac d i e)(*strict*)\n    apply(rule epdaH.derivation_append_preserves_derivation)\n      apply(rename_tac d i e)(*strict*)\n      apply(simp add: epdaH.derivation_initial_def)\n     apply(rename_tac d i e)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n     apply(simp (no_asm) add: epdaH.derivation_def)\n     apply(fold epdaH.derivation_def)\n     apply(clarsimp)\n     apply(rename_tac d i e ia)(*strict*)\n     apply(case_tac ia)\n      apply(rename_tac d i e ia)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac d i e)(*strict*)\n      apply(case_tac \"d 0\")\n       apply(rename_tac d i e)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac d i e a)(*strict*)\n      apply(clarsimp)\n      apply(case_tac a)\n      apply(rename_tac d i e a option b)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac d i e b)(*strict*)\n      apply(erule_tac\n      x=\"0\"\n      in allE)\n      apply(clarsimp)\n      apply(rename_tac d i e b da)(*strict*)\n      apply(rule_tac\n      t=\"(SOME y. \\<exists>c' e. y = Some (pair e c') \\<and> (\\<exists>d. epdaH.derivation G d \\<and> epdaH.belongs G d \\<and> d 0 = Some (pair None c) \\<and> d 0 = Some (pair e c') \\<and> epdaH_conf_history c = epdaH_conf_history c'))\"\n      and s=\"Some(pair None c)\"\n      in ssubst)\n       apply(rename_tac d i e b da)(*strict*)\n       prefer 2\n       apply(force)\n      apply(rename_tac d i e b da)(*strict*)\n      apply(rule some_equality)\n       apply(rename_tac d i e b da)(*strict*)\n       apply(clarsimp)\n       apply(rule_tac\n      x=\"der1 c\"\n      in exI)\n       apply(rule conjI)\n        apply(rename_tac d i e b da)(*strict*)\n        apply(rule epdaH.der1_is_derivation)\n       apply(rename_tac d i e b da)(*strict*)\n       apply(rule conjI)\n        apply(rename_tac d i e b da)(*strict*)\n        apply(rule epdaH.der1_belongs)\n        apply(rule epdaH.belongs_configurations)\n         apply(rename_tac d i e b da)(*strict*)\n         apply(force)\n        apply(rename_tac d i e b da)(*strict*)\n        apply(force)\n       apply(rename_tac d i e b da)(*strict*)\n       apply(simp add: der1_def)\n      apply(rename_tac d i e b da y)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac d i e ia nat)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac d i e nat)(*strict*)\n     apply(erule_tac x=\"Suc nat\" in allE')\n     apply(erule_tac\n      x=\"nat\"\n      in allE)\n     apply(clarsimp)\n     apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n     apply(rule_tac\n      t=\"(SOME y. \\<exists>c'event e. y = Some (pair e c'event) \\<and> (\\<exists>d. epdaH.derivation G d \\<and> epdaH.belongs G d \\<and> d 0 = Some (pair None c) \\<and> d (Suc nat) = Some (pair e c'event) \\<and> epdaH_conf_history c' = epdaH_conf_history c'event))\"\n      and s=\"Some (pair ea c')\"\n      in ssubst)\n      apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n      apply(rule some_equality)\n       apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n       apply(clarsimp)\n       apply(rule_tac\n      x=\"da\"\n      in exI)\n       apply(rule conjI)\n        apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n        apply(force)\n       apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n       apply(rule conjI)\n        apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n        apply(force)\n       apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac d i e nat c' c'event ea eb da db y)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n      apply(subgoal_tac \"X\" for X)\n       apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n       prefer 2\n       apply(rule_tac\n      G=\"G\"\n      and ?d1.0=\"derivation_append d da i\"\n      and ?d2.0=\"derivation_append d dc i\"\n      and x=\"i\"\n      and y=\"i\"\n      and n=\"Suc nat\"\n      and m=\"Suc nat\"\n      in epdaH.is_forward_deterministicHist_derivations_coincide)\n                  apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                  apply(simp add: valid_dpda_def valid_pda_def)\n                 apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                 apply(rule epdaH.derivation_append_preserves_derivation_initial)\n                   apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                   apply(simp add: valid_dpda_def valid_pda_def)\n                  apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                  apply(simp add: epdaH.derivation_initial_def)\n                 apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                 apply(rule epdaH.derivation_append_preserves_derivation)\n                   apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                   apply(force)\n                  apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                  apply(force)\n                 apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                 apply(clarsimp)\n                apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                apply(rule epdaH.derivation_append_preserves_derivation_initial)\n                  apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                  apply(simp add: valid_dpda_def valid_pda_def)\n                 apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                 apply(simp add: epdaH.derivation_initial_def)\n                apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                apply(rule epdaH.derivation_append_preserves_derivation)\n                  apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                  apply(force)\n                 apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                 apply(force)\n                apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                apply(clarsimp)\n               apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n               apply (metis DPDA_is_is_forward_deterministicHist_SB)\n              apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n              apply(simp add: derivation_append_def)\n             apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n             apply(simp add: derivation_append_def)\n            apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n            apply(simp add: derivation_append_def)\n           apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n           apply(force)\n          apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n          apply(simp add: derivation_append_def)\n         apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n         apply(simp add: derivation_append_def)\n        apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n        apply(simp add: derivation_append_def)\n        apply(simp add: get_configuration_def epda_effects_def)\n       apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n       apply(force)\n      apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n     apply(clarsimp)\n     apply(rule_tac\n      t=\"(SOME y. \\<exists>c'event e. y = Some (pair e c'event) \\<and> (\\<exists>d. epdaH.derivation G d \\<and> epdaH.belongs G d \\<and> d 0 = Some (pair None c) \\<and> d nat = Some (pair e c'event) \\<and> epdaH_conf_history c' = epdaH_conf_history c'event))\"\n      and s=\"Some (pair eb c'event)\"\n      in ssubst)\n      apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n      apply(rule some_equality)\n       apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n       apply(clarsimp)\n       apply(rule_tac\n      x=\"db\"\n      in exI)\n       apply(rule conjI)\n        apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n        apply(force)\n       apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n       apply(rule conjI)\n        apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n        apply(force)\n       apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac d i e nat c' c'event ea eb da db y)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n      apply(subgoal_tac \"X\" for X)\n       apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n       prefer 2\n       apply(rule_tac\n      G=\"G\"\n      and ?d1.0=\"derivation_append d db i\"\n      and ?d2.0=\"derivation_append d dc i\"\n      and x=\"i\"\n      and y=\"i\"\n      and n=\"nat\"\n      and m=\"nat\"\n      in epdaH.is_forward_deterministicHist_derivations_coincide)\n                  apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                  apply(simp add: valid_dpda_def valid_pda_def)\n                 apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                 apply(rule epdaH.derivation_append_preserves_derivation_initial)\n                   apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                   apply(simp add: valid_dpda_def valid_pda_def)\n                  apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                  apply(simp add: epdaH.derivation_initial_def)\n                 apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                 apply(rule epdaH.derivation_append_preserves_derivation)\n                   apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                   apply(force)\n                  apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                  apply(force)\n                 apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                 apply(clarsimp)\n                apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                apply(rule epdaH.derivation_append_preserves_derivation_initial)\n                  apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                  apply(simp add: valid_dpda_def valid_pda_def)\n                 apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                 apply(simp add: epdaH.derivation_initial_def)\n                apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                apply(rule epdaH.derivation_append_preserves_derivation)\n                  apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                  apply(force)\n                 apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                 apply(force)\n                apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n                apply(clarsimp)\n               apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n               apply (metis DPDA_is_is_forward_deterministicHist_SB)\n              apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n              apply(simp add: derivation_append_def)\n             apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n             apply(simp add: derivation_append_def)\n            apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n            apply(simp add: derivation_append_def)\n           apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n           apply(force)\n          apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n          apply(simp add: derivation_append_def)\n         apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n         apply(simp add: derivation_append_def)\n        apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n        apply(simp add: derivation_append_def)\n        apply(simp add: get_configuration_def epda_effects_def)\n       apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n       apply(force)\n      apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n      apply(case_tac nat)\n       apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac d i e nat c' c'event ea eb da db c'eventa ec dc nata)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n     apply(subgoal_tac \"X\" for X)\n      apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n      prefer 2\n      apply(rule_tac\n      d=\"da\"\n      and n=\"nat\"\n      and m=\"Suc nat\"\n      in epdaH.step_detail_before_some_position)\n        apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n        apply(force)\n       apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n       apply(force)\n      apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n      apply(force)\n     apply(rename_tac d i e nat c' c'event ea eb da db)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n     apply(subgoal_tac \"epdaH_conf_history c1 = epdaH_conf_history c'\")\n      apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n      apply(subgoal_tac \"X\" for X)\n       apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n       prefer 2\n       apply(rule_tac\n      G=\"G\"\n      and ?d1.0=\"derivation_append d db i\"\n      and ?d2.0=\"derivation_append d da i\"\n      and x=\"i\"\n      and y=\"i\"\n      and n=\"nat\"\n      and m=\"nat\"\n      in epdaH.is_forward_deterministicHist_derivations_coincide)\n                  apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n                  apply(simp add: valid_dpda_def valid_pda_def)\n                 apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n                 apply(rule epdaH.derivation_append_preserves_derivation_initial)\n                   apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n                   apply(simp add: valid_dpda_def valid_pda_def)\n                  apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n                  apply(simp add: epdaH.derivation_initial_def)\n                 apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n                 apply(rule epdaH.derivation_append_preserves_derivation)\n                   apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n                   apply(force)\n                  apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n                  apply(force)\n                 apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n                 apply(clarsimp)\n                apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n                apply(rule epdaH.derivation_append_preserves_derivation_initial)\n                  apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n                  apply(simp add: valid_dpda_def valid_pda_def)\n                 apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n                 apply(simp add: epdaH.derivation_initial_def)\n                apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n                apply(rule epdaH.derivation_append_preserves_derivation)\n                  apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n                  apply(force)\n                 apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n                 apply(force)\n                apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n                apply(clarsimp)\n               apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n               apply (metis DPDA_is_is_forward_deterministicHist_SB)\n              apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n              apply(simp add: derivation_append_def)\n             apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n             apply(simp add: derivation_append_def)\n            apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n            apply(simp add: derivation_append_def)\n           apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n           apply(force)\n          apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n          apply(simp add: derivation_append_def)\n         apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n         apply(simp add: derivation_append_def)\n        apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n        apply(simp add: derivation_append_def)\n        apply(simp add: get_configuration_def epda_effects_def)\n       apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n      apply(case_tac nat)\n       apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1 nata)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n     apply(subgoal_tac \"X\" for X)\n      apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n      prefer 2\n      apply(rule_tac\n      G=\"G\"\n      and d=\"da\"\n      and n=\"nat\"\n      and m=\"Suc 0\"\n      in epdaH.steps_extend_history_derivation)\n          apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n          apply(simp add: valid_dpda_def valid_pda_def)\n         apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n         apply(force)\n        apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n        prefer 2\n        apply(clarsimp)\n        apply(simp add: get_configuration_def epda_effects_def)\n       apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n       apply(rule_tac\n      d=\"da\"\n      in epdaH.belongs_configurations)\n        apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n        apply(force)\n       apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n       apply(force)\n      apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n      apply(clarsimp)\n      apply(simp add: get_configuration_def epda_effects_def)\n     apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1 h)(*strict*)\n     apply(subgoal_tac \"X\" for X)\n      apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1 h)(*strict*)\n      prefer 2\n      apply(rule_tac\n      G=\"G\"\n      and d=\"da\"\n      and n=\"0\"\n      and m=\"nat\"\n      in epdaH.steps_extend_history_derivation)\n          apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1 h)(*strict*)\n          apply(simp add: valid_dpda_def valid_pda_def)\n         apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1 h)(*strict*)\n         apply(force)\n        apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1 h)(*strict*)\n        prefer 2\n        apply(clarsimp)\n        apply(simp add: get_configuration_def epda_effects_def)\n       apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1 h)(*strict*)\n       apply(rule_tac\n      d=\"da\"\n      in epdaH.belongs_configurations)\n        apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1 h)(*strict*)\n        apply(force)\n       apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1 h)(*strict*)\n       apply(force)\n      apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1 h)(*strict*)\n      apply(clarsimp)\n      apply(simp add: get_configuration_def epda_effects_def)\n     apply(rename_tac d i e nat c' c'event eb da db e1 e2 c1 h)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d i e)(*strict*)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"(SOME y. \\<exists>c' e. y = Some (pair e c') \\<and> (\\<exists>d. epdaH.derivation G d \\<and> epdaH.belongs G d \\<and> d 0 = Some (pair None c) \\<and> d 0 = Some (pair e c') \\<and> epdaH_conf_history c = epdaH_conf_history c'))\"\n      and s=\"Some(pair None c)\"\n      in ssubst)\n     apply(rename_tac d i e)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac d i e)(*strict*)\n    apply(rule some_equality)\n     apply(rename_tac d i e)(*strict*)\n     apply(clarsimp)\n     apply(rule_tac\n      x=\"der1 c\"\n      in exI)\n     apply(rule conjI)\n      apply(rename_tac d i e)(*strict*)\n      apply(rule epdaH.der1_is_derivation)\n     apply(rename_tac d i e)(*strict*)\n     apply(rule conjI)\n      apply(rename_tac d i e)(*strict*)\n      apply(rule epdaH.der1_belongs)\n      apply(rule epdaH.belongs_configurations)\n       apply(rename_tac d i e)(*strict*)\n       apply(rule epdaH.derivation_initial_belongs)\n        apply(rename_tac d i e)(*strict*)\n        apply(simp add: valid_dpda_def valid_pda_def)\n       apply(rename_tac d i e)(*strict*)\n       apply(force)\n      apply(rename_tac d i e)(*strict*)\n      apply(force)\n     apply(rename_tac d i e)(*strict*)\n     apply(simp add: der1_def)\n    apply(rename_tac d i e y)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d i e)(*strict*)\n   apply(clarsimp)\n   apply(erule disjE)\n    apply(rename_tac d i e)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d i e n)(*strict*)\n    apply(simp add: derivation_append_def)\n    apply(case_tac \"n\\<le>i\")\n     apply(rename_tac d i e n)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"X\" for X)\n      apply(rename_tac d i e n)(*strict*)\n      prefer 2\n      apply(rule_tac\n      g=\"d\"\n      and n=\"n\"\n      and m=\"i\"\n      in epdaH.pre_some_position_is_some_position)\n        apply(rename_tac d i e n)(*strict*)\n        apply(simp add: epdaH.derivation_initial_def)\n        apply(force)\n       apply(rename_tac d i e n)(*strict*)\n       apply(force)\n      apply(rename_tac d i e n)(*strict*)\n      apply(force)\n     apply(rename_tac d i e n)(*strict*)\n     apply(force)\n    apply(rename_tac d i e n)(*strict*)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"n-i\"\n      in allE)\n    apply(clarsimp)\n    apply(rename_tac d i e n c' ea da)(*strict*)\n    apply(subgoal_tac \"(SOME y. \\<exists>c'event e. y = Some (pair e c'event) \\<and> (\\<exists>d. epdaH.derivation G d \\<and> epdaH.belongs G d \\<and> d 0 = Some (pair None c) \\<and> d (n - i) = Some (pair e c'event) \\<and> epdaH_conf_history c' = epdaH_conf_history c'event)) = Some (pair ea c')\")\n     apply(rename_tac d i e n c' ea da)(*strict*)\n     apply(force)\n    apply(rename_tac d i e n c' ea da)(*strict*)\n    apply(rule some_equality)\n     apply(rename_tac d i e n c' ea da)(*strict*)\n     apply(clarsimp)\n     apply(rule_tac\n      x=\"da\"\n      in exI)\n     apply(rule conjI)\n      apply(rename_tac d i e n c' ea da)(*strict*)\n      apply(force)\n     apply(rename_tac d i e n c' ea da)(*strict*)\n     apply(rule conjI)\n      apply(rename_tac d i e n c' ea da)(*strict*)\n      apply(force)\n     apply(rename_tac d i e n c' ea da)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d i e n c' ea da y)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n     prefer 2\n     apply(rule_tac\n      G=\"G\"\n      and ?d1.0=\"derivation_append d da i\"\n      and ?d2.0=\"derivation_append d db i\"\n      and x=\"i\"\n      and y=\"i\"\n      and n=\"n-i\"\n      and m=\"n-i\"\n      in epdaH.is_forward_deterministicHist_derivations_coincide)\n                apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n                apply(simp add: valid_dpda_def valid_pda_def)\n               apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n               apply(rule epdaH.derivation_append_preserves_derivation_initial)\n                 apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n                 apply(simp add: valid_dpda_def valid_pda_def)\n                apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n                apply(simp add: epdaH.derivation_initial_def)\n               apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n               apply(rule epdaH.derivation_append_preserves_derivation)\n                 apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n                 apply(simp add: epdaH.derivation_initial_def)\n                apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n                apply(force)\n               apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n               apply(force)\n              apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n              apply(rule epdaH.derivation_append_preserves_derivation_initial)\n                apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n                apply(simp add: valid_dpda_def valid_pda_def)\n               apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n               apply(simp add: epdaH.derivation_initial_def)\n              apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n              apply(rule epdaH.derivation_append_preserves_derivation)\n                apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n                apply(simp add: epdaH.derivation_initial_def)\n               apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n               apply(force)\n              apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n              apply(clarsimp)\n             apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n             apply(thin_tac \"(SOME y. \\<exists>c' e. y = Some (pair e c') \\<and> (\\<exists>d. epdaH.derivation G d \\<and> epdaH.belongs G d \\<and> d 0 = Some (pair None c) \\<and> d (n - i) = Some (pair e c') \\<and> epdaH_conf_history c'event = epdaH_conf_history c')) = None\")\n             apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n             apply (metis DPDA_is_is_forward_deterministicHist_SB)\n            apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n            apply(simp add: derivation_append_def)\n           apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n           apply(simp add: derivation_append_def)\n          apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n          apply(simp add: derivation_append_def)\n         apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n         apply(force)\n        apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n        apply(simp add: derivation_append_def)\n       apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n       apply(simp add: derivation_append_def)\n      apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n      apply(simp add: derivation_append_def)\n      apply(simp add: get_configuration_def epda_effects_def)\n     apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n     apply(force)\n    apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n    apply(force)\n   apply(rename_tac d i e)(*strict*)\n   apply(erule_tac\n      x=\"i\"\n      and P=\"\\<lambda>N. \\<exists>n\\<ge>N. epdaH_conf_history (the (get_configuration (derivation_append d (\\<lambda>x. SOME y. \\<exists>c' e. y = Some (pair e c') \\<and> (\\<exists>d. epdaH.derivation G d \\<and> epdaH.belongs G d \\<and> d 0 = Some (pair None c) \\<and> d x = Some (pair e c') \\<and> epdaH_conf_history c = epdaH_conf_history c')) i n))) \\<noteq> epdaH_conf_history (the (get_configuration (derivation_append d (\\<lambda>x. SOME y. \\<exists>c' e. y = Some (pair e c') \\<and> (\\<exists>d. epdaH.derivation G d \\<and> epdaH.belongs G d \\<and> d 0 = Some (pair None c) \\<and> d x = Some (pair e c') \\<and> epdaH_conf_history c = epdaH_conf_history c')) i N)))\"\n      in allE)\n   apply(rename_tac d i e)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i e n)(*strict*)\n   apply(simp add: derivation_append_def get_configuration_def)\n   apply(case_tac \"n=i\")\n    apply(rename_tac d i e n)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d i e n)(*strict*)\n   apply(subgoal_tac \"i<n\")\n    apply(rename_tac d i e n)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac d i e n)(*strict*)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"n-i\"\n      in allE)\n   apply(clarsimp)\n   apply(rename_tac d i e n c' ea da)(*strict*)\n   apply(subgoal_tac \"(SOME y. \\<exists>c'event e. y = Some (pair e c'event) \\<and> (\\<exists>d. epdaH.derivation G d \\<and> epdaH.belongs G d \\<and> d 0 = Some (pair None c) \\<and> d (n - i) = Some (pair e c'event) \\<and> epdaH_conf_history c' = epdaH_conf_history c'event)) = Some (pair ea c')\")\n    apply(rename_tac d i e n c' ea da)(*strict*)\n    apply(force)\n   apply(rename_tac d i e n c' ea da)(*strict*)\n   apply(rule some_equality)\n    apply(rename_tac d i e n c' ea da)(*strict*)\n    apply(clarsimp)\n    apply(rule_tac\n      x=\"da\"\n      in exI)\n    apply(rule conjI)\n     apply(rename_tac d i e n c' ea da)(*strict*)\n     apply(force)\n    apply(rename_tac d i e n c' ea da)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac d i e n c' ea da)(*strict*)\n     apply(force)\n    apply(rename_tac d i e n c' ea da)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d i e n c' ea da y)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n    prefer 2\n    apply(rule_tac\n      G=\"G\"\n      and ?d1.0=\"derivation_append d da i\"\n      and ?d2.0=\"derivation_append d db i\"\n      and x=\"i\"\n      and y=\"i\"\n      and n=\"n-i\"\n      and m=\"n-i\"\n      in epdaH.is_forward_deterministicHist_derivations_coincide)\n               apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n               apply(simp add: valid_dpda_def valid_pda_def)\n              apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n              apply(rule epdaH.derivation_append_preserves_derivation_initial)\n                apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n                apply(simp add: valid_dpda_def valid_pda_def)\n               apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n               apply(simp add: epdaH.derivation_initial_def)\n              apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n              apply(rule epdaH.derivation_append_preserves_derivation)\n                apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n                apply(simp add: epdaH.derivation_initial_def)\n               apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n               apply(force)\n              apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n              apply(force)\n             apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n             apply(rule epdaH.derivation_append_preserves_derivation_initial)\n               apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n               apply(simp add: valid_dpda_def valid_pda_def)\n              apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n              apply(simp add: epdaH.derivation_initial_def)\n             apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n             apply(rule epdaH.derivation_append_preserves_derivation)\n               apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n               apply(simp add: epdaH.derivation_initial_def)\n              apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n              apply(force)\n             apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n             apply(clarsimp)\n            apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n            apply(thin_tac \"epdaH_conf_history (the (case_option None (case_derivation_configuration (\\<lambda>e. Some)) (SOME y. \\<exists>c' e. y = Some (pair e c') \\<and> (\\<exists>d. epdaH.derivation G d \\<and> epdaH.belongs G d \\<and> d 0 = Some (pair None c) \\<and> d (n - i) = Some (pair e c') \\<and> epdaH_conf_history c'event = epdaH_conf_history c')))) \\<noteq> epdaH_conf_history c'event\")\n            apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n            apply (metis DPDA_is_is_forward_deterministicHist_SB)\n           apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n           apply(simp add: derivation_append_def)\n          apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n          apply(simp add: derivation_append_def)\n         apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n         apply(simp add: derivation_append_def)\n        apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n        apply(force)\n       apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n       apply(simp add: derivation_append_def)\n      apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n      apply(simp add: derivation_append_def)\n     apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n     apply(simp add: derivation_append_def)\n     apply(simp add: get_configuration_def epda_effects_def)\n    apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n    apply(force)\n   apply(rename_tac d i e n c' ea da c'event eb db)(*strict*)\n   apply(force)\n  apply(rename_tac d i e)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e n)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d i e n)(*strict*)\n   prefer 2\n   apply(rule_tac\n      P=\"\\<lambda>n. \\<exists>d e c'. epdaH.derivation G d \\<and> epdaH.belongs G d \\<and> d 0 = Some (pair None c) \\<and> d n = Some (pair e c') \\<and> epdaH_conf_history c=epdaH_conf_history c' \"\n      and x=\"0\"\n      and n=\"n\"\n      in ex_max_limited)\n    apply(rename_tac d i e n)(*strict*)\n    apply(rule_tac\n      x=\"der1 c\"\n      in exI)\n    apply(rule_tac\n      x=\"None\"\n      in exI)\n    apply(rule_tac\n      x=\"c\"\n      in exI)\n    apply(rule conjI)\n     apply(rename_tac d i e n)(*strict*)\n     apply(rule epdaH.der1_is_derivation)\n    apply(rename_tac d i e n)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac d i e n)(*strict*)\n     apply(rule epdaH.der1_belongs)\n     apply(rule_tac\n      d=\"d\"\n      in epdaH.belongs_configurations)\n      apply(rename_tac d i e n)(*strict*)\n      apply(rule epdaH.derivation_initial_belongs)\n       apply(rename_tac d i e n)(*strict*)\n       apply(simp add: valid_dpda_def valid_pda_def)\n      apply(rename_tac d i e n)(*strict*)\n      apply(force)\n     apply(rename_tac d i e n)(*strict*)\n     apply(force)\n    apply(rename_tac d i e n)(*strict*)\n    apply(simp add: der1_def)\n   apply(rename_tac d i e n)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d i e n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e n k da ea c')(*strict*)\n  apply(rule_tac\n      x=\"da\"\n      in exI)\n  apply(clarsimp)\n  apply(rule_tac\n      x=\"k\"\n      in exI)\n  apply(clarsimp)\n  apply(rename_tac d i e n k da ea c' e' x)(*strict*)\n  apply(case_tac e')\n  apply(rename_tac d i e n k da ea c' e' x edge_src edge_eventa edge_pop edge_push edge_trg)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e n k da ea c' x edge_src edge_event edge_pop edge_push edge_trg)(*strict*)\n  apply(rename_tac qs r po pu qt)\n  apply(rename_tac d i e n k da ea c' x qs r po pu qt)(*strict*)\n  apply(case_tac r)\n   apply(rename_tac d i e n k da ea c' x qs r po pu qt)(*strict*)\n   prefer 2\n   apply(rename_tac d i e n k da ea c' x qs r po pu qt a)(*strict*)\n   apply(force)\n  apply(rename_tac d i e n k da ea c' x qs r po pu qt)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n  apply(case_tac \"k=n\")\n   apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i e n da ea c' x qs po pu qt)(*strict*)\n   apply(erule_tac\n      x=\"c'\"\n      in allE)\n   apply(erule_tac\n      x=\"ea\"\n      in allE)\n   apply(erule_tac\n      x=\"da\"\n      in allE)\n   apply(clarsimp)\n  apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n  apply(subgoal_tac \"k<n\")\n   apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"Suc k\"\n      in allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"derivation_append da (der2 c' \\<lparr>edge_src = qs, edge_event = None, edge_pop = po, edge_push = pu, edge_trg = qt\\<rparr> x) k\"\n      in allE)\n  apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n  apply(erule impE)\n   apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n   apply(simp add: derivation_append_def)\n  apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n  apply(erule impE)\n   apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n   apply(rule epdaH.derivation_append_preserves_belongs)\n     apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n     apply(simp add: valid_dpda_def valid_pda_def)\n    apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n    apply(force)\n   apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n   apply(rule epdaH.derivation_append_preserves_derivation)\n     apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n     apply(force)\n    apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n    apply(rule epdaH.der2_is_derivation)\n    apply(force)\n   apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n   apply(clarsimp)\n   apply(simp add: der2_def)\n  apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n  apply(erule impE)\n   apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n   apply(rule epdaH.derivation_append_preserves_derivation)\n     apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n     apply(force)\n    apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n    apply(rule epdaH.der2_is_derivation)\n    apply(force)\n   apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n   apply(clarsimp)\n   apply(simp add: der2_def)\n  apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n  apply(erule_tac\n      x=\"Some \\<lparr>edge_src = qs, edge_event = None, edge_pop = po, edge_push = pu, edge_trg = qt\\<rparr>\"\n      in allE)\n  apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n  apply(thin_tac \"\\<forall>c'event e d. d n = Some (pair e c'event) \\<longrightarrow> d 0 = Some (pair None c) \\<longrightarrow> epdaH.belongs G d \\<longrightarrow> epdaH.derivation G d \\<longrightarrow> epdaH_conf_history c' \\<noteq> epdaH_conf_history c'event\")\n  apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n  apply(erule_tac\n      x=\"x\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n   apply(simp add: derivation_append_def der2_def)\n  apply(rename_tac d i e n k da ea c' x qs po pu qt)(*strict*)\n  apply(simp add: epdaH_step_relation_def)\n  apply(simp add: option_to_list_def)\n  done\n\nlemma epda_to_des__of__valid_epda__not_empty: \"\n  valid_epda G\n  \\<Longrightarrow> epda_to_des G \\<noteq> bot\"\n  apply(simp add: epda_to_des_def botDES_def bot_DES_ext_def)\n  apply(clarsimp)\n  apply (metis empty_iff epda_empty_in_epdaH_unmarked_language)\n  done\n\ndefinition epdaH_livelock_freedom :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"epdaH_livelock_freedom G \\<equiv>\n  \\<not> epdaH.has_livelock G\"\n\ndefinition epdaH_deadlock_freedom :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"epdaH_deadlock_freedom G \\<equiv>\n  \\<forall>d n e c.\n    epdaH.derivation_initial G d\n    \\<longrightarrow> maximum_of_domain d n\n    \\<longrightarrow> (\\<not> epdaH_marking_condition G d)\n    \\<longrightarrow> d n = Some (pair e c)\n    \\<longrightarrow> (\\<exists>e' c'. epdaH_step_relation G c e' c')\"\n\ndefinition epdaH_accessible :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"epdaH_accessible G \\<equiv>\n    (\\<forall>e \\<in> epda_delta G. \\<exists>d n c. \n      epdaH.derivation_initial G d \n      \\<and> d n = Some (pair (Some e) c))\n  \\<and> (\\<forall>q \\<in> epda_states G. \\<exists>d n e c. \n      epdaH.derivation_initial G d \n      \\<and> d n = Some (pair e c)\n      \\<and> q = epdaH_conf_state c)\"\n\nlemma epdaH_accessible__to__epdaHaccessible: \"\n  epdaH_accessible G\n  \\<Longrightarrow> epdaH.accessible G\" \n  apply(simp add: epdaH.accessible_def epdaH_accessible_def epdaH.get_accessible_destinations_def epda_destinations_def epdaH_get_destinations_def)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(erule_tac x=\"xa\" in ballE)\n    apply(clarsimp)\n    apply(rule_tac x=\"d\" in exI)\n    apply(clarsimp)\n    apply(rule_tac x=\"n\" in exI)\n    apply(clarsimp)\n   apply(force)\n  apply(clarsimp)\n  apply(erule_tac x=\"xa\" in ballE)\n   apply(clarsimp)\n   apply(rule_tac x=\"d\" in exI)\n   apply(clarsimp)\n   apply(rule_tac x=\"n\" in exI)\n   apply(clarsimp)\n  apply(force)\n  done\n\nlemma epdaHaccessible__to__epdaH_accessible: \"\n  epdaH.accessible G\n  \\<Longrightarrow> epdaH_accessible G\" \n  apply(simp add: epdaH.accessible_def epdaH_accessible_def epdaH.get_accessible_destinations_def epda_destinations_def epdaH_get_destinations_def)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(subgoal_tac \"edge e \\<in> {x. (x \\<in> epda_destinations.state ` epda_states G \\<or> x \\<in> edge ` epda_delta G) \\<and>\n                (\\<exists>d. ATS.derivation_initial epdaH_initial_configurations epdaH_step_relation G d \\<and>\n                     (\\<exists>i e c. d i = Some (pair e c) \\<and>\n                              (x = epda_destinations.state (epdaH_conf_state c) \\<or>\n                               x \\<in> (case e of None \\<Rightarrow> {} | Some e' \\<Rightarrow> {edge e'}))))}\")\n    prefer 2\n    apply(rule_tac A=\"edge ` epda_delta G\" in set_mp)\n     apply(force)\n    apply(force)\n   apply(clarsimp)\n   apply(rule_tac x=\"d\" in exI)\n   apply(clarsimp)\n   apply(rule_tac x=\"i\" in exI)\n   apply(clarsimp)\n   apply(case_tac ea)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(subgoal_tac \"epda_destinations.state q \\<in> {x. (x \\<in> epda_destinations.state ` epda_states G \\<or> x \\<in> edge ` epda_delta G) \\<and>\n                (\\<exists>d. ATS.derivation_initial epdaH_initial_configurations epdaH_step_relation G d \\<and>\n                     (\\<exists>i e c. d i = Some (pair e c) \\<and>\n                              (x = epda_destinations.state (epdaH_conf_state c) \\<or>\n                               x \\<in> (case e of None \\<Rightarrow> {} | Some e' \\<Rightarrow> {edge e'}))))}\")\n   prefer 2\n   apply(rule_tac A=\"epda_destinations.state ` epda_states G\" in set_mp)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(rule_tac x=\"d\" in exI)\n  apply(clarsimp)\n  apply(rule_tac x=\"i\" in exI)\n  apply(clarsimp)\n  apply(case_tac c)\n  apply(clarsimp)\n  apply(case_tac e)\n   apply(clarsimp)\n  apply(force)\n  done\n\nlemma epdaH_Nonblockingness2: \"\n  valid_epda G\n  \\<Longrightarrow> Nonblockingness2 (epdaH.unmarked_language G) (epdaH.marked_language G)\"\n  apply(subgoal_tac \"Nonblockingness2 (epdaS.unmarked_language G) (epdaS.marked_language G)\")\n   prefer 2\n   apply(rule epda_Nonblockingness2)\n   apply(force)\n  apply (metis epdaS_to_epdaH_mlang epdaS_to_epdaH_unmarked_language)\n  done\n\nlemma cfg_like_characterization_of_determinism_for_epda_part1: \"\n  valid_epda G\n  \\<Longrightarrow> epdaH.is_forward_deterministicHist_SB G\n  \\<Longrightarrow> epdaH.derivation_initial G d1\n  \\<Longrightarrow> d1 n1 = Some (pair e1 c1)\n  \\<Longrightarrow> epdaH_conf_history c1 = v\n  \\<Longrightarrow> d1 (Suc n1) = Some (pair e1' c1')\n  \\<Longrightarrow> epdaH_conf_history c1' = v @ [b]\n  \\<Longrightarrow> epdaH.derivation_initial G d2\n  \\<Longrightarrow> d2 n2 = Some (pair e2 c2)\n  \\<Longrightarrow> epdaH_conf_history c2 = v\n  \\<Longrightarrow> d2 (Suc n2) = Some (pair e2' c2')\n  \\<Longrightarrow> epdaH_conf_history c2' = v @ [b]\n  \\<Longrightarrow> n1 = n2 \\<and> (\\<forall>i\\<le>n1. d1 i = d2 i)\"\n  oops\n\nlemma cfg_like_characterization_of_determinism_for_epda_part2: \"\n  valid_epda G\n  \\<Longrightarrow> epdaH.is_forward_deterministicHist_SB G\n  \\<Longrightarrow> epdaH.derivation_initial G d1\n  \\<Longrightarrow> d1 n1 = Some (pair e1 c1)\n  \\<Longrightarrow> epdaH_conf_history c1 = v\n  \\<Longrightarrow> epdaH.derivation_initial G d2\n  \\<Longrightarrow> d2 n2 = Some (pair e2 c2)\n  \\<Longrightarrow> epdaH_conf_history c2 = v\n  \\<Longrightarrow> d2 (Suc n2) = Some (pair e2' c2')\n  \\<Longrightarrow> epdaH_conf_history c2' = v @ [b]\n  \\<Longrightarrow> n1 \\<le> n2 \\<and> (\\<forall>i\\<le>n1. d1 i = d2 i)\"\n  oops\n\nend\n\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_07/I_epda_lemmas.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5660185498374789, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.2896410905224101}}
{"text": "\nheader {* Abstract syntax for Hybrid CSP. *}\n\ntheory HCSP_Com \n  imports  Main\n\"DCSequents/DCSequent\"\nbegin\n\n\n\ntype_synonym cname = string\ntype_synonym time = real\ntype_synonym bexp = fform\ntype_synonym Inv = fform\ntype_synonym Rg = fform\ntype_synonym mid = \"fform * fform\"\n\ndatatype typeid = R | S | B\n\ndatatype proc\n= \"Skip\"\n| \"Stop\"\n| Ass \"exp\" \"exp\"          (\"_ := _\" [99, 95] 94)   \n| Send \"cname\" \"exp\"         (\"_!!_\" [110,108] 100)      \n| Receive \"cname\" \"exp\"    (\"_??_\" [110,108] 100) \n| Seq \"proc\" \"mid\" \" proc\"                   (\"_; _ ; _\"        [91,90 ] 90)\n| Cond \"bexp\" \"proc\"                 (\"IF _ _\"   [95,94]93)\n| Nondeter \"typeid\" \"string\" \"bexp\" \"proc\"                 (\"NON _ _ : _ _\"   [95,94]93)\n| Pref   \"proc\" \"proc\"                  (\"_\\<rightarrow>_\"   [95,94]93)           \n| join \"proc\" \"proc\"                   (infixr \"[[\" 90)\n| meet \"proc\" \"proc\"                  (\"_<<_\" [90,90] 90)\n| Par    \"proc\" \"proc\"                  (infixr \"||\" 89)\n| Rep    \"proc\"                               (\"_*\"[91] 90)\n| RepA    \"proc\"                              (\"_***\"[91] 90)\n| RepN    \"proc\" \"nat\"                               (\"_**_\"[91,92] 90)\n| Cont  \"Inv\" \"bexp\" \"Rg\"                (\"<_&&_> : _\" [95,96]94)\n| TimeOut \"proc\" \"time\" \"proc\"    (\"_|>_ _\" [95,96,94]94)\n| Interp   \"proc\" \"proc\" (\"_[[>_\"[95,94]94)\n| empty \"exp\" (\"empty _\" 94)\n| addL \"exp\" \"exp\" (\"addL _ _\" 94)\n| delL \"exp\" (\"delL _\" 94)\n\ndefinition isEmpty :: \"exp => fform\" where\n\"isEmpty(e1) == (case e1 of\n        (List ls) => (case ls of [] => WTrue | _ => WFalse) |\n        _ => WFalse)\"\n\ndefinition readL :: \"exp => exp\" where\n\"readL(e1) == (case e1 of\n      (List ls) => hd(ls) |\n      _ => (Real 0))\"\n\ntype_synonym pair = \"exp * exp\"\n\n\nprimrec map :: \"pair list => exp => exp\" where\n\"map ([]) (a) = a\" |\n\"map (x#xs) (a) = (if (fst (x) = a) then (snd (x)) else (map (xs) (a)))\"\n\n\nlemma \"map ([(RVar ''x'', Real 2), (RVar ''y'', RVar z)],  RVar ''x'') = (Real 2)\"\napply (induct, auto)\ndone\n\nlemma fact1 : \"map ([(RVar ''x'', Real 2), (RVar ''y'', RVar z)]) (RVar ''z'') = RVar ''z''\"\napply (induct, auto)\ndone\n\n(*Expression substitution: \"map\" records the substitution mapping.*)\nprimrec substE :: \"pair list => exp => exp\" where\n\"substE (mp, (RVar x)) = map (mp, (RVar x))\"  |\n\"substE (mp, (SVar x)) = map (mp, (SVar x))\"  |\n\"substE (mp, (BVar x)) = map (mp, (BVar x))\"  |\n\"substE (mp, (List x)) = List x\"  |\n\"substE (mp, (Real m)) = map (mp, (Real m))\"  |\n\"substE (mp, (Bool b)) = map (mp, (Bool b))\"  |\n\"substE (mp, (String s)) = map (mp, (String s))\"  |\n\"substE (mp, (e1 [+] e2)) = substE (mp, e1) [+] substE (mp, e2)\"  |\n\"substE (mp, (e1 [-] e2)) = substE (mp, e1) [-] substE (mp, e2)\"|\n\"substE (mp, (e1 [*] e2)) = substE (mp, e1) [*] substE (mp, e2)\"|\n\"substE (mp, (e1 [**] e2)) = substE (mp, e1) [**] substE (mp, e2)\"\n\nlemma \"(% x. x [+] x = RVar ''z'' [+] RVar ''z'') (RVar ''z'')\"\napply auto\ndone\n\nlemma \"substE ([(RVar ''x'', Real 1), (RVar ''y'', RVar ''z'')], (RVar ''y'' [+] RVar ''z'')) \n        = RVar ''z'' [+] RVar ''z''\"\napply (induct, auto)\ndone \n\n\n(*Tip: for theory built on Pure, application is written by f(x) rather than f x as usual. *)\n\nprimrec lVarE :: \"pair list => string => pair list\" where\n\"lVarE ([],s) = []\" |\n\"lVarE (x#xs,s) = (if (fst (x) = (RVar s)) then xs else x#lVarE(xs, s))\"\n\nprimrec inExp :: \"string => exp => bool\" where\n\"inExp (s, (RVar x)) = (s=x)\"  |\n\"inExp (s, (SVar x)) = (s=x)\"  |\n\"inExp (s, (BVar x)) = (s=x)\"  |\n\"inExp (s, (Real m)) = (False)\"  |\n\"inExp (s, (Bool b)) = (False)\"  |\n\"inExp (s, (String r)) = (False)\"  |\n\"inExp (s, (e1 [+] e2)) = (inExp (s, e1) | inExp (s, e2))\"  |\n\"inExp (s, (e1 [-] e2)) = (inExp (s, e1) | inExp (s, e2))\"|\n\"inExp (s, (e1 [*] e2)) = (inExp (s, e1) | inExp (s, e2))\"\n\nprimrec inPairL :: \"pair list => string => bool\" where\n\"inPairL ([],s) = False\" |\n\"inPairL (x#xs,s) = (if (inExp (s, fst (x))) then True else inPairL(xs, s))\"\n\nprimrec inPairR :: \"pair list => string => bool\" where\n\"inPairR ([],s) = False\" |\n\"inPairR (x#xs,s) = (if (inExp (s, snd (x))) then True else inPairR(xs, s))\"\n\n(*Check if the quantifiers of a formula occur in mp*)\nprimrec inPairForm :: \"pair list => fform => bool\" where\n \"inPairForm (mp) (WTrue) = False\" |\n \"inPairForm (mp) (WFalse) = False\" |\n \"inPairForm (mp) (e1 [=] e2) =False\" |\n \"inPairForm (mp) (e1 [<] e2) = False\" |\n \"inPairForm (mp) (e1 [>] e2) =False\" |\n \"inPairForm (mp) ([~]p) = (inPairForm (mp) (p))\" |\n \"inPairForm (mp) (p [&] q) = ((inPairForm (mp) (p)) | (inPairForm (mp) (q)))\" |\n \"inPairForm (mp) (p [|] q) = ((inPairForm (mp) (p)) | (inPairForm (mp) (q)))\" |\n \"inPairForm (mp) (p [-->] q) = ((inPairForm (mp) (p)) | (inPairForm (mp) (q)))\" |\n \"inPairForm (mp) (p [<->] q) = ((inPairForm (mp) (p)) | (inPairForm (mp) (q)))\" |\n \"inPairForm (mp) (WALL i p) = (inPairL (mp, i) | inPairR (mp, i) | inPairForm (mp)(p))\" |\n \"inPairForm (mp) (WEX i p) = (inPairL (mp, i) | inPairR (mp, i) | inPairForm (mp)(p))\"\n\n(*Formula sustitution.*)\nprimrec substF :: \"pair list => fform => fform\" where\n \"substF (mp) (WTrue) = WTrue\" |\n \"substF (mp) (WFalse) = WFalse\" |\n \"substF (mp) (e1 [=] e2) = ((substE (mp, e1)) [=] (substE (mp, e2)))\" |\n \"substF (mp) (e1 [<] e2) = ((substE (mp, e1)) [<] (substE (mp, e2)))\" |\n \"substF (mp) (e1 [>] e2) = (substE (mp, e1) [>] substE (mp, e2))\" |\n \"substF (mp) ([~]p) = ([~](substF (mp) (p)))\" |\n \"substF (mp) (p [&] q) = ((substF (mp) (p)) [&] (substF (mp) (q)))\" |\n \"substF (mp) (p [|] q) = ((substF (mp) (p)) [|] (substF (mp) (q)))\" |\n \"substF (mp) (p [-->] q) = ((substF (mp) (p)) [-->] (substF (mp) (q)))\" |\n \"substF (mp) (p [<->] q) = ((substF (mp) (p)) [<->] (substF (mp) (q)))\" |\n \"substF (mp) (WALL i p) = (if ((~inPairL (mp, i)) & (~inPairR (mp, i))) then (WALL i (substF (mp)(p))) \n                           else WFalse)\" |\n \"substF (mp) (WEX i p) = (if ((~inPairL (mp, i)) & (~inPairR (mp, i))) then (WEX i (substF (mp)(p))) \n                           else WFalse)\"\n\nlemma allEX : \"substF([(RVar ''x'', RVar ''m''), (RVar ''y'', RVar ''z'')], \n                 ((RVar ''x'')[=]Real 2) [&] (WALL ''w'' ((RVar ''w'') [>] (RVar ''z''))))\n             = (((RVar ''m'')[=]Real 2) [&] (WALL ''w'' ((RVar ''w'') [>] (RVar ''z''))))\"\napply auto\ndone\n\n\nlemma fact : \"substF ([(RVar ''x'', Real 2), (RVar ''y'', RVar ''z'')]) (RVar ''x'' [>] Real 1) = (Real 2 [>] Real 1)\"\napply (induct, auto)\ndone\n\n\nend\n\n\n\n\n", "meta": {"author": "submission", "repo": "Sim2HCSP", "sha": "b30be89b32d4468091e0c62613db5027f249dbc4", "save_path": "github-repos/isabelle/submission-Sim2HCSP", "path": "github-repos/isabelle/submission-Sim2HCSP/Sim2HCSP-b30be89b32d4468091e0c62613db5027f249dbc4/HHLProver/HCSP_Com.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5660185351961015, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.28964108303017416}}
{"text": "section \\<open>Lasso Finding Algorithm for Generalized B\\\"uchi Graphs \\label{sec:gbg}\\<close>\ntheory Gabow_GBG\nimports \n  Gabow_Skeleton \n  CAVA_Automata.Lasso\n  Find_Path\nbegin\n\n(* TODO: convenience locale, consider merging this with invariants *)\nlocale igb_fr_graph = \n  igb_graph G + fr_graph G\n  for G :: \"('Q,'more) igb_graph_rec_scheme\"\n\nlemma igb_fr_graphI:\n  assumes \"igb_graph G\"\n  assumes \"finite ((g_E G)\\<^sup>* `` g_V0 G)\"\n  shows \"igb_fr_graph G\"\nproof -\n  interpret igb_graph G by fact\n  show ?thesis using assms(2) by unfold_locales\nqed\n\ntext \\<open>\n  We implement an algorithm that computes witnesses for the \n  non-emptiness of Generalized B\\\"uchi Graphs (GBG).\n\\<close>\n\nsection \\<open>Specification\\<close>\ncontext igb_graph\nbegin\n  definition ce_correct \n    \\<comment> \\<open>Specifies a correct counter-example\\<close>\n    where\n    \"ce_correct Vr Vl \\<equiv> (\\<exists>pr pl. \n        Vr \\<subseteq> E\\<^sup>*``V0 \\<and> Vl \\<subseteq> E\\<^sup>*``V0 \\<comment> \\<open>Only reachable nodes are covered\\<close>\n      \\<and> set pr\\<subseteq>Vr \\<and> set pl\\<subseteq>Vl     \\<comment> \\<open>The paths are inside the specified sets\\<close>\n      \\<and> Vl\\<times>Vl \\<subseteq> (E \\<inter> Vl\\<times>Vl)\\<^sup>*      \\<comment> \\<open>\\<open>Vl\\<close> is mutually connected\\<close>\n      \\<and> Vl\\<times>Vl \\<inter> E \\<noteq> {}            \\<comment> \\<open>\\<open>Vl\\<close> is non-trivial\\<close>\n      \\<and> is_lasso_prpl (pr,pl))    \\<comment> \\<open>Paths form a lasso\\<close>\n    \"     \n\n  definition find_ce_spec :: \"('Q set \\<times> 'Q set) option nres\" where\n    \"find_ce_spec \\<equiv> SPEC (\\<lambda>r. case r of\n      None \\<Rightarrow> (\\<forall>prpl. \\<not>is_lasso_prpl prpl)\n    | Some (Vr,Vl) \\<Rightarrow> ce_correct Vr Vl\n    )\"\n\n  definition find_lasso_spec :: \"('Q list \\<times> 'Q list) option nres\" where\n    \"find_lasso_spec \\<equiv> SPEC (\\<lambda>r. case r of\n      None \\<Rightarrow> (\\<forall>prpl. \\<not>is_lasso_prpl prpl)\n    | Some prpl \\<Rightarrow> is_lasso_prpl prpl\n    )\"\n\nend\n\nsection \\<open>Invariant Extension\\<close>\n\ntext \\<open>Extension of the outer invariant:\\<close>\ncontext igb_fr_graph\nbegin\n  definition no_acc_over\n    \\<comment> \\<open>Specifies that there is no accepting cycle touching a set of nodes\\<close>\n    where\n    \"no_acc_over D \\<equiv> \\<not>(\\<exists>v\\<in>D. \\<exists>pl. pl\\<noteq>[] \\<and> path E v pl v \\<and> \n    (\\<forall>i<num_acc. \\<exists>q\\<in>set pl. i\\<in>acc q))\"\n\n  definition \"fgl_outer_invar_ext \\<equiv> \\<lambda>it (brk,D). \n    case brk of None \\<Rightarrow> no_acc_over D | Some (Vr,Vl) \\<Rightarrow> ce_correct Vr Vl\"\n\n  definition \"fgl_outer_invar \\<equiv> \\<lambda>it (brk,D). case brk of \n    None \\<Rightarrow> outer_invar it D \\<and> no_acc_over D\n  | Some (Vr,Vl) \\<Rightarrow> ce_correct Vr Vl\"\n  \nend\n\ntext \\<open>Extension of the inner invariant:\\<close>\nlocale fgl_invar_loc = \n  invar_loc G v0 D0 p D pE \n  + igb_graph G\n  for G :: \"('Q, 'more) igb_graph_rec_scheme\"\n  and v0 D0 and brk :: \"('Q set \\<times> 'Q set) option\" and p D pE +\n  assumes no_acc: \"brk=None \\<Longrightarrow> \\<not>(\\<exists>v pl. pl\\<noteq>[] \\<and> path lvE v pl v \\<and> \n    (\\<forall>i<num_acc. \\<exists>q\\<in>set pl. i\\<in>acc q))\" \\<comment> \\<open>No accepting cycle over \n      visited edges\\<close>\n  assumes acc: \"brk=Some (Vr,Vl) \\<Longrightarrow> ce_correct Vr Vl\"\nbegin\n  lemma locale_this: \"fgl_invar_loc G v0 D0 brk p D pE\"\n    by unfold_locales\n  lemma invar_loc_this: \"invar_loc G v0 D0 p D pE\" by unfold_locales\n  lemma eas_gba_graph_this: \"igb_graph G\" by unfold_locales\nend\n\ndefinition (in igb_graph) \"fgl_invar v0 D0 \\<equiv> \n  \\<lambda>(brk, p, D, pE). fgl_invar_loc G v0 D0 brk p D pE\"\n\nsection \\<open>Definition of the Lasso-Finding Algorithm\\<close>\n\ncontext igb_fr_graph\nbegin\n  definition find_ce :: \"('Q set \\<times> 'Q set) option nres\" where\n    \"find_ce \\<equiv> do {\n      let D = {};\n      (brk,_)\\<leftarrow>FOREACHci fgl_outer_invar V0 \n        (\\<lambda>(brk,_). brk=None) \n        (\\<lambda>v0 (brk,D0). do {\n          if v0\\<notin>D0 then do {\n            let s = (None,initial v0 D0);\n\n            (brk,p,D,pE) \\<leftarrow> WHILEIT (fgl_invar v0 D0)\n              (\\<lambda>(brk,p,D,pE). brk=None \\<and> p \\<noteq> []) (\\<lambda>(_,p,D,pE). \n            do {\n              \\<comment> \\<open>Select edge from end of path\\<close>\n              (vo,(p,D,pE)) \\<leftarrow> select_edge (p,D,pE);\n\n              ASSERT (p\\<noteq>[]);\n              case vo of \n                Some v \\<Rightarrow> do {\n                  if v \\<in> \\<Union>(set p) then do {\n                    \\<comment> \\<open>Collapse\\<close>\n                    let (p,D,pE) = collapse v (p,D,pE);\n\n                    ASSERT (p\\<noteq>[]);\n\n                    if \\<forall>i<num_acc. \\<exists>q\\<in>last p. i\\<in>acc q then\n                      RETURN (Some (\\<Union>(set (butlast p)),last p),p,D,pE)\n                    else\n                      RETURN (None,p,D,pE)\n                  } else if v\\<notin>D then do {\n                    \\<comment> \\<open>Edge to new node. Append to path\\<close>\n                    RETURN (None,push v (p,D,pE))\n                  } else RETURN (None,p,D,pE)\n                }\n              | None \\<Rightarrow> do {\n                  \\<comment> \\<open>No more outgoing edges from current node on path\\<close>\n                  ASSERT (pE \\<inter> last p \\<times> UNIV = {});\n                  RETURN (None,pop (p,D,pE))\n                }\n            }) s;\n            ASSERT (brk=None \\<longrightarrow> (p=[] \\<and> pE={}));\n            RETURN (brk,D)\n          } else \n            RETURN (brk,D0)\n      }) (None,D);\n      RETURN brk\n    }\"\nend\n\nsection \\<open>Invariant Preservation\\<close>\n\n\ncontext igb_fr_graph\nbegin\n\n  definition \"fgl_invar_part \\<equiv> \\<lambda>(brk, p, D, pE). \n    fgl_invar_loc_axioms G brk p D pE\"\n\n  lemma fgl_outer_invarI[intro?]:\n    \"\\<lbrakk>\n      brk=None \\<Longrightarrow> outer_invar it D; \n      \\<lbrakk>brk=None \\<Longrightarrow> outer_invar it D\\<rbrakk> \\<Longrightarrow> fgl_outer_invar_ext it (brk,D)\\<rbrakk> \n      \\<Longrightarrow> fgl_outer_invar it (brk,D)\"\n    unfolding outer_invar_def fgl_outer_invar_ext_def fgl_outer_invar_def\n    apply (auto split: prod.splits option.splits)\n    done\n\n  lemma fgl_invarI[intro?]:\n    \"\\<lbrakk> invar v0 D0 PDPE; \n       invar v0 D0 PDPE \\<Longrightarrow> fgl_invar_part (B,PDPE)\\<rbrakk> \n     \\<Longrightarrow> fgl_invar v0 D0 (B,PDPE)\"\n    unfolding invar_def fgl_invar_part_def fgl_invar_def\n    apply (simp split: prod.split_asm)\n    apply intro_locales\n    apply (simp add: invar_loc_def)\n    apply assumption\n    done\n\n\n  lemma fgl_invar_initial: \n    assumes OINV: \"fgl_outer_invar it (None,D0)\"\n    assumes A: \"v0\\<in>it\" \"v0\\<notin>D0\"\n    shows \"fgl_invar_part (None, initial v0 D0)\"\n  proof -\n    from OINV interpret outer_invar_loc G it D0 \n      by (simp add: fgl_outer_invar_def outer_invar_def)\n\n    from OINV have no_acc: \"no_acc_over D0\"\n      by (simp add: fgl_outer_invar_def fgl_outer_invar_ext_def)\n\n    {\n      fix v pl\n\n      assume \"pl \\<noteq> []\" and P: \"path (vE [{v0}] D0 (E \\<inter> {v0} \\<times> UNIV)) v pl v\"\n      hence 1: \"v\\<in>D0\"\n        by (cases pl) (auto simp: path_cons_conv vE_def touched_def)\n      have 2: \"path E v pl v\" using path_mono[OF vE_ss_E P] .\n      note 1 2\n    } note AUX1=this\n\n\n    show ?thesis\n      unfolding fgl_invar_part_def\n      apply (simp split: prod.splits add: initial_def)\n      apply unfold_locales\n      using \\<open>v0\\<notin>D0\\<close>\n      using AUX1 no_acc unfolding no_acc_over_def apply blast\n      by simp\n  qed\n\n  lemma fgl_invar_pop:\n    assumes INV: \"fgl_invar v0 D0 (None,p,D,pE)\"\n    assumes INV': \"invar v0 D0 (pop (p,D,pE))\"\n    assumes NE[simp]: \"p\\<noteq>[]\"\n    assumes NO': \"pE \\<inter> last p \\<times> UNIV = {}\"\n    shows \"fgl_invar_part (None, pop (p,D,pE))\"\n  proof -\n    from INV interpret fgl_invar_loc G v0 D0 None p D pE \n      by (simp add: fgl_invar_def)\n\n    show ?thesis\n      apply (unfold fgl_invar_part_def pop_def)\n      apply (simp split: prod.splits)\n      apply unfold_locales\n      unfolding vE_pop[OF NE]\n\n      using no_acc apply auto []\n      apply simp\n      done\n  qed\n\n  lemma fgl_invar_collapse_ce_aux:\n    assumes INV: \"invar v0 D0 (p, D, pE)\"\n    assumes NE[simp]: \"p\\<noteq>[]\"\n    assumes NONTRIV: \"vE p D pE \\<inter> (last p \\<times> last p) \\<noteq> {}\"\n    assumes ACC: \"\\<forall>i<num_acc. \\<exists>q\\<in>last p. i\\<in>acc q\"\n    shows \"fgl_invar_part (Some (\\<Union>(set (butlast p)), last p), p, D, pE)\"\n  proof -\n    from INV interpret invar_loc G v0 D0 p D pE by (simp add: invar_def)\n    txt \\<open>The last collapsed node on the path contains states from all \n      accepting sets.\n      As it is strongly connected and reachable, we get a counter-example. \n      Here, we explicitely construct the lasso.\\<close>\n\n    let ?Er = \"E \\<inter> (\\<Union>(set (butlast p)) \\<times> UNIV)\"\n\n    txt \\<open>We choose a node in the last Cnode, that is reachable only using\n      former Cnodes.\\<close>\n\n    obtain w where \"(v0,w)\\<in>?Er\\<^sup>*\" \"w\\<in>last p\"\n    proof cases\n      assume \"length p = 1\"\n      hence \"v0\\<in>last p\"\n        using root_v0 \n        by (cases p) auto\n      thus thesis by (auto intro: that)\n    next\n      assume \"length p\\<noteq>1\"\n      hence \"length p > 1\" by (cases p) auto\n      hence \"Suc (length p - 2) < length p\" by auto\n      from p_connected'[OF this] obtain u v where\n        UIP: \"u\\<in>p!(length p - 2)\" and VIP: \"v\\<in>p!(length p - 1)\" and \"(u,v)\\<in>lvE\"\n        using \\<open>length p > 1\\<close> by auto\n      from root_v0 have V0IP: \"v0\\<in>p!0\" by (cases p) auto\n      \n      from VIP have \"v\\<in>last p\" by (cases p rule: rev_cases) auto\n\n      from pathI[OF V0IP UIP] \\<open>length p > 1\\<close> have \n        \"(v0,u)\\<in>(lvE \\<inter> \\<Union>(set (butlast p)) \\<times> \\<Union>(set (butlast p)))\\<^sup>*\"\n        (is \"_ \\<in> \\<dots>\\<^sup>*\")  \n        by (simp add: path_seg_butlast)\n      also have \"\\<dots> \\<subseteq> ?Er\" using lvE_ss_E by auto\n      finally (rtrancl_mono_mp[rotated]) have \"(v0,u)\\<in>?Er\\<^sup>*\" .\n      also note \\<open>(u,v)\\<in>lvE\\<close> UIP hence \"(u,v)\\<in>?Er\" using lvE_ss_E \\<open>length p > 1\\<close> \n        apply (auto simp: Bex_def in_set_conv_nth)\n        by (metis One_nat_def Suc_lessE \\<open>Suc (length p - 2) < length p\\<close> \n          diff_Suc_1 length_butlast nth_butlast)\n      finally show ?thesis by (rule that) fact \n    qed\n    then obtain \"pr\" where \n      P_REACH: \"path E v0 pr w\" and \n      R_SS: \"set pr \\<subseteq> \\<Union>(set (butlast p))\"\n      apply -\n      apply (erule rtrancl_is_path)\n      apply (frule path_nodes_edges)\n      apply (auto \n        dest!: order_trans[OF _ image_Int_subset] \n        dest: path_mono[of _ E, rotated])\n      done\n\n    have [simp]: \"last p = p!(length p - 1)\" by (cases p rule: rev_cases) auto\n\n    txt \\<open>From that node, we construct a lasso by inductively appending a path\n      for each accepting set\\<close>\n    {\n      fix na\n      assume na_def: \"na = num_acc\"\n\n      have \"\\<exists>pl. pl\\<noteq>[] \n        \\<and> path (lvE \\<inter> last p\\<times>last p) w pl w \n        \\<and> (\\<forall>i<num_acc. \\<exists>q\\<in>set pl. i\\<in>acc q)\"\n        using ACC\n        unfolding na_def[symmetric]\n      proof (induction na)\n        case 0 \n\n        from NONTRIV obtain u v \n          where \"(u,v)\\<in>lvE \\<inter> last p \\<times> last p\" \"u\\<in>last p\" \"v\\<in>last p\"\n          by auto\n        from cnode_connectedI \\<open>w\\<in>last p\\<close> \\<open>u\\<in>last p\\<close> \n        have \"(w,u)\\<in>(lvE \\<inter> last p \\<times> last p)\\<^sup>*\"\n          by auto\n        also note \\<open>(u,v)\\<in>lvE \\<inter> last p \\<times> last p\\<close>\n        also (rtrancl_into_trancl1) from cnode_connectedI \\<open>v\\<in>last p\\<close> \\<open>w\\<in>last p\\<close> \n        have \"(v,w)\\<in>(lvE \\<inter> last p \\<times> last p)\\<^sup>*\"\n          by auto\n        finally obtain pl where \"pl\\<noteq>[]\" \"path (lvE \\<inter> last p \\<times> last p) w pl w\"\n          by (rule trancl_is_path)\n        thus ?case by auto\n      next\n        case (Suc n)\n        from Suc.prems have \"\\<forall>i<n. \\<exists>q\\<in>last p. i\\<in>acc q\" by auto\n        with Suc.IH obtain pl where IH: \n          \"pl\\<noteq>[]\" \n          \"path (lvE \\<inter> last p \\<times> last p) w pl w\" \n          \"\\<forall>i<n. \\<exists>q\\<in>set pl. i\\<in>acc q\" \n          by blast\n  \n        from Suc.prems obtain v where \"v\\<in>last p\" and \"n\\<in>acc v\" by auto\n        from cnode_connectedI \\<open>w\\<in>last p\\<close> \\<open>v\\<in>last p\\<close> \n        have \"(w,v)\\<in>(lvE \\<inter> last p \\<times> last p)\\<^sup>*\" by auto\n        then obtain pl1 where P1: \"path (lvE \\<inter> last p \\<times> last p) w pl1 v\" \n          by (rule rtrancl_is_path)\n        also from cnode_connectedI \\<open>w\\<in>last p\\<close> \\<open>v\\<in>last p\\<close> \n        have \"(v,w)\\<in>(lvE \\<inter> last p \\<times> last p)\\<^sup>*\" by auto\n        then obtain pl2 where P2: \"path (lvE \\<inter> last p \\<times> last p) v pl2 w\"\n          by (rule rtrancl_is_path)\n        also (path_conc) note IH(2)\n        finally (path_conc) have \n          P: \"path (lvE \\<inter> last p \\<times> last p) w (pl1@pl2@pl) w\"\n          by simp\n        moreover from IH(1) have \"pl1@pl2@pl \\<noteq> []\" by simp\n        moreover have \"\\<forall>i'<n. \\<exists>q\\<in>set (pl1@pl2@pl). i'\\<in>acc q\" using IH(3) by auto\n        moreover have \"v\\<in>set (pl1@pl2@pl)\" using P1 P2 P IH(1)\n          apply (cases pl2, simp_all add: path_cons_conv path_conc_conv)\n          apply (cases pl, simp_all add: path_cons_conv)\n          apply (cases pl1, simp_all add: path_cons_conv)\n          done\n        with \\<open>n\\<in>acc v\\<close> have \"\\<exists>q\\<in>set (pl1@pl2@pl). n\\<in>acc q\" by auto\n        ultimately show ?case\n          apply (intro exI conjI)\n          apply assumption+\n          apply (auto elim: less_SucE)\n          done\n      qed\n    }\n    then obtain pl where pl: \"pl\\<noteq>[]\" \"path (lvE \\<inter> last p\\<times>last p) w pl w\" \n      \"\\<forall>i<num_acc. \\<exists>q\\<in>set pl. i\\<in>acc q\" by blast\n    hence \"path E w pl w\" and L_SS: \"set pl \\<subseteq> last p\"\n      apply -\n      apply (frule path_mono[of _ E, rotated])\n      using lvE_ss_E\n      apply auto [2]\n\n      apply (drule path_nodes_edges)\n      apply (drule order_trans[OF _ image_Int_subset])\n      apply auto []\n      done\n\n    have LASSO: \"is_lasso_prpl (pr,pl)\"\n      unfolding is_lasso_prpl_def is_lasso_prpl_pre_def\n      using \\<open>path E w pl w\\<close> P_REACH pl by auto\n    \n    from p_sc have \"last p \\<times> last p \\<subseteq> (lvE \\<inter> last p \\<times> last p)\\<^sup>*\" by auto\n    with lvE_ss_E have VL_CLOSED: \"last p \\<times> last p \\<subseteq> (E \\<inter> last p \\<times> last p)\\<^sup>*\"\n      apply (erule_tac order_trans)\n      apply (rule rtrancl_mono)\n      by blast\n\n    have NONTRIV': \"last p \\<times> last p \\<inter> E \\<noteq> {}\"\n      by (metis Int_commute NONTRIV disjoint_mono lvE_ss_E subset_refl)\n\n    from order_trans[OF path_touched touched_reachable]\n    have LP_REACH: \"last p \\<subseteq> E\\<^sup>*``V0\" \n      and BLP_REACH: \"\\<Union>(set (butlast p)) \\<subseteq> E\\<^sup>*``V0\"\n      apply -\n      apply (cases p rule: rev_cases)\n      apply simp\n      apply auto []\n\n      apply (cases p rule: rev_cases)\n      apply simp\n      apply auto []\n      done\n      \n    show ?thesis\n      apply (simp add: fgl_invar_part_def)\n      apply unfold_locales\n      apply simp\n\n      using LASSO R_SS L_SS VL_CLOSED NONTRIV' LP_REACH BLP_REACH\n      unfolding ce_correct_def \n      apply simp \n      apply blast\n      done\n\n  qed\n\n  lemma fgl_invar_collapse_ce:\n    fixes u v\n    assumes INV: \"fgl_invar v0 D0 (None,p,D,pE)\"\n    defines \"pE' \\<equiv> pE - {(u,v)}\"\n    assumes CFMT: \"(p',D',pE'') = collapse v (p,D,pE')\"\n    assumes INV': \"invar v0 D0 (p',D',pE'')\"\n    assumes NE[simp]: \"p\\<noteq>[]\"\n    assumes E: \"(u,v)\\<in>pE\" and \"u\\<in>last p\"\n    assumes BACK: \"v\\<in>\\<Union>(set p)\"\n    assumes ACC: \"\\<forall>i<num_acc. \\<exists>q\\<in>last p'. i\\<in>acc q\"\n    defines i_def: \"i \\<equiv> idx_of p v\"\n    shows \"fgl_invar_part (\n      Some (\\<Union>(set (butlast p')), last p'), \n      collapse v (p,D,pE'))\"\n  proof -\n\n    from CFMT have p'_def: \"p' = collapse_aux p i\" and [simp]: \"D'=D\" \"pE''=pE'\"\n      by (simp_all add: collapse_def i_def)\n\n    from INV interpret fgl_invar_loc G v0 D0 None p D pE \n      by (simp add: fgl_invar_def)\n\n    from idx_of_props[OF BACK] have \"i<length p\" and \"v\\<in>p!i\" \n      by (simp_all add: i_def)\n\n    have \"u\\<in>last p'\" \n      using \\<open>u\\<in>last p\\<close> \\<open>i<length p\\<close> \n      unfolding p'_def collapse_aux_def\n      apply (simp add: last_drop last_snoc)\n      by (metis Misc.last_in_set drop_eq_Nil last_drop not_le)\n    moreover have \"v\\<in>last p'\" \n      using \\<open>v\\<in>p!i\\<close> \\<open>i<length p\\<close> \n      unfolding p'_def collapse_aux_def\n      by (metis UnionI append_Nil Cons_nth_drop_Suc in_set_conv_decomp last_snoc)\n    ultimately have \"vE p' D pE' \\<inter> last p' \\<times> last p' \\<noteq> {}\" \n      unfolding p'_def pE'_def by (auto simp: E)\n    \n    have \"p'\\<noteq>[]\" by (simp add: p'_def collapse_aux_def)\n\n    have [simp]: \"collapse v (p,D,pE') = (p',D,pE')\" \n      unfolding collapse_def p'_def i_def\n      by simp\n\n    show ?thesis\n      apply simp\n      apply (rule fgl_invar_collapse_ce_aux) \n      using INV' apply simp\n      apply fact+\n      done\n  qed\n\n  lemma fgl_invar_collapse_nce:\n    fixes u v\n    assumes INV: \"fgl_invar v0 D0 (None,p,D,pE)\"\n    defines \"pE' \\<equiv> pE - {(u,v)}\"\n    assumes CFMT: \"(p',D',pE'') = collapse v (p,D,pE')\"\n    assumes INV': \"invar v0 D0 (p',D',pE'')\"\n    assumes NE[simp]: \"p\\<noteq>[]\"\n    assumes E: \"(u,v)\\<in>pE\" and \"u\\<in>last p\"\n    assumes BACK: \"v\\<in>\\<Union>(set p)\"\n    assumes NACC: \"j<num_acc\" \"\\<forall>q\\<in>last p'. j\\<notin>acc q\"\n    defines \"i \\<equiv> idx_of p v\"\n    shows \"fgl_invar_part (None, collapse v (p,D,pE'))\"\n  proof -\n    from CFMT have p'_def: \"p' = collapse_aux p i\" and [simp]: \"D'=D\" \"pE''=pE'\"\n      by (simp_all add: collapse_def i_def)\n\n    have [simp]: \"collapse v (p,D,pE') = (p',D,pE')\" \n      by (simp add: collapse_def p'_def i_def)\n\n    from INV interpret fgl_invar_loc G v0 D0 None p D pE \n      by (simp add: fgl_invar_def)\n\n    from INV' interpret inv': invar_loc G v0 D0 p' D pE' by (simp add: invar_def)\n\n    define vE' where \"vE' = vE p' D pE'\"\n\n    have vE'_alt: \"vE' = insert (u,v) lvE\"\n      by (simp add: vE'_def p'_def pE'_def E)\n\n    from idx_of_props[OF BACK] have \"i<length p\" and \"v\\<in>p!i\" \n      by (simp_all add: i_def)\n\n    have \"u\\<in>last p'\" \n      using \\<open>u\\<in>last p\\<close> \\<open>i<length p\\<close>\n      unfolding p'_def collapse_aux_def\n      apply (simp add: last_drop last_snoc)\n      by (metis Misc.last_in_set drop_eq_Nil last_drop leD)\n    moreover have \"v\\<in>last p'\" \n      using \\<open>v\\<in>p!i\\<close> \\<open>i<length p\\<close> \n      unfolding p'_def collapse_aux_def\n      by (metis UnionI append_Nil Cons_nth_drop_Suc in_set_conv_decomp last_snoc)\n    ultimately have \"vE' \\<inter> last p' \\<times> last p' \\<noteq> {}\" \n      unfolding vE'_alt by (auto)\n    \n    have \"p'\\<noteq>[]\" by (simp add: p'_def collapse_aux_def)\n\n    {\n      txt \\<open>\n        We show that no visited strongly connected component contains states\n        from all acceptance sets.\\<close>\n      fix w pl\n      txt \\<open>For this, we chose a non-trivial loop inside the visited edges\\<close>\n      assume P: \"path vE' w pl w\" and NT: \"pl\\<noteq>[]\"\n      txt \\<open>And show that there is one acceptance set disjoint with the nodes\n        of the loop\\<close>\n      have \"\\<exists>i<num_acc. \\<forall>q\\<in>set pl. i\\<notin>acc q\"\n      proof cases\n        assume \"set pl \\<inter> last p' = {}\" \n          \\<comment> \\<open>Case: The loop is outside the last Cnode\\<close>\n        with path_restrict[OF P] \\<open>u\\<in>last p'\\<close> \\<open>v\\<in>last p'\\<close> have \"path lvE w pl w\"\n          apply -\n          apply (drule path_mono[of _ lvE, rotated])\n          unfolding vE'_alt\n          by auto\n        with no_acc NT show ?thesis by auto\n      next\n        assume \"set pl \\<inter> last p' \\<noteq> {}\" \n          \\<comment> \\<open>Case: The loop touches the last Cnode\\<close>\n        txt \\<open>Then, the loop must be completely inside the last CNode\\<close>\n        from inv'.loop_in_lastnode[folded vE'_def, OF P \\<open>p'\\<noteq>[]\\<close> this] \n        have \"w\\<in>last p'\" \"set pl \\<subseteq> last p'\" .\n        with NACC show ?thesis by blast\n      qed\n    } note AUX_no_acc = this\n\n    show ?thesis\n      apply (simp add: fgl_invar_part_def)\n      apply unfold_locales\n      using AUX_no_acc[unfolded vE'_def] apply auto []\n      \n      apply simp\n      done\n  qed\n\n  lemma collapse_ne: \"([],D',pE') \\<noteq> collapse v (p,D,pE)\"\n    by (simp add: collapse_def collapse_aux_def Let_def)\n\n  lemma fgl_invar_push:\n    assumes INV: \"fgl_invar v0 D0 (None,p,D,pE)\"\n    assumes BRK[simp]: \"brk=None\" \n    assumes NE[simp]: \"p\\<noteq>[]\"\n    assumes E: \"(u,v)\\<in>pE\" and UIL: \"u\\<in>last p\"\n    assumes VNE: \"v\\<notin>\\<Union>(set p)\" \"v\\<notin>D\"\n    assumes INV': \"invar v0 D0 (push v (p,D,pE - {(u,v)}))\"\n    shows \"fgl_invar_part (None, push v (p,D,pE - {(u,v)}))\"\n  proof -\n    from INV interpret fgl_invar_loc G v0 D0 None p D pE \n      by (simp add: fgl_invar_def)\n\n    define pE' where \"pE' = (pE - {(u,v)} \\<union> E\\<inter>{v}\\<times>UNIV)\"\n\n    have [simp]: \"push v (p,D,pE - {(u,v)}) = (p@[{v}],D,pE')\"\n      by (simp add: push_def pE'_def)\n\n    from INV' interpret inv': invar_loc G v0 D0 \"(p@[{v}])\" D \"pE'\"\n      by (simp add: invar_def)\n\n    note defs_fold = vE_push[OF E UIL VNE, folded pE'_def]\n\n    {\n      txt \\<open>We show that there still is no loop that contains all accepting\n        nodes. For this, we choose some loop.\\<close>\n      fix w pl\n      assume P: \"path (insert (u,v) lvE) w pl w\" and [simp]: \"pl\\<noteq>[]\"\n      have \"\\<exists>i<num_acc. \\<forall>q\\<in>set pl. i\\<notin>acc q\" \n      proof cases\n        assume \"v\\<in>set pl\" \\<comment> \\<open>Case: The newly pushed last cnode is on the loop\\<close>\n        txt \\<open>Then the loop is entirely on the last cnode\\<close>\n        with inv'.loop_in_lastnode[unfolded defs_fold, OF P]\n        have [simp]: \"w=v\" and SPL: \"set pl = {v}\" by auto\n        txt \\<open>However, we then either have that the last cnode is contained in\n          the last but one cnode, or that there is a visited edge inside the\n          last cnode.\\<close>\n        from P SPL have \"u=v \\<or> (v,v)\\<in>lvE\" \n          apply (cases pl) apply (auto simp: path_cons_conv)\n          apply (case_tac list)\n          apply (auto simp: path_cons_conv)\n          done\n        txt \\<open>Both leads to a contradiction\\<close>\n        hence False proof\n          assume \"u=v\" \\<comment> \\<open>This is impossible, as @{text \"u\"} was on the \n            original path, but @{text \"v\"} was not\\<close>\n          with UIL VNE show False by auto\n        next\n          assume \"(v,v)\\<in>lvE\" \\<comment> \\<open>This is impossible, as all visited edges are\n            from touched nodes, but @{text \"v\"} was untouched\\<close>\n          with vE_touched VNE show False unfolding touched_def by auto\n        qed\n        thus ?thesis ..\n      next\n        assume A: \"v\\<notin>set pl\" \n          \\<comment> \\<open>Case: The newly pushed last cnode is not on the loop\\<close>\n        txt \\<open>Then, the path lays inside the old visited edges\\<close>\n        have \"path lvE w pl w\" \n        proof -\n          have \"w\\<in>set pl\" using P by (cases pl) (auto simp: path_cons_conv)\n          with A show ?thesis using path_restrict[OF P]\n            apply -\n            apply (drule path_mono[of _ lvE, rotated])\n            apply (cases pl, auto) []\n            \n            apply assumption\n            done\n        qed\n        txt \\<open>And thus, the proposition follows from the invariant on the old\n          state\\<close>\n        with no_acc show ?thesis \n          apply simp\n          using \\<open>pl\\<noteq>[]\\<close> \n          by blast\n      qed\n    } note AUX_no_acc = this\n\n    show ?thesis\n      unfolding fgl_invar_part_def\n      apply simp\n      apply unfold_locales\n      unfolding defs_fold\n\n      using AUX_no_acc apply auto []\n      \n      apply simp\n      done\n  qed\n\n\n  lemma fgl_invar_skip:\n    assumes INV: \"fgl_invar v0 D0 (None,p,D,pE)\"\n    assumes BRK[simp]: \"brk=None\" \n    assumes NE[simp]: \"p\\<noteq>[]\"\n    assumes E: \"(u,v)\\<in>pE\" and UIL: \"u\\<in>last p\"\n    assumes VID: \"v\\<in>D\"\n    assumes INV': \"invar v0 D0 (p, D, (pE - {(u,v)}))\"\n    shows \"fgl_invar_part (None, p, D, (pE - {(u,v)}))\"\n  proof -\n    from INV interpret fgl_invar_loc G v0 D0 None p D pE \n      by (simp add: fgl_invar_def)\n    from INV' interpret inv': invar_loc G v0 D0 p D \"(pE - {(u,v)})\" \n      by (simp add: invar_def)\n\n    {\n      txt \\<open>We show that there still is no loop that contains all accepting\n        nodes. For this, we choose some loop.\\<close>\n      fix w pl\n      assume P: \"path (insert (u,v) lvE) w pl w\" and [simp]: \"pl\\<noteq>[]\"\n      from P have \"\\<exists>i<num_acc. \\<forall>q\\<in>set pl. i\\<notin>acc q\" \n      proof (cases rule: path_edge_rev_cases)\n        case no_use \\<comment> \\<open>Case: The loop does not use the new edge\\<close>\n        txt \\<open>The proposition follows from the invariant for the old state\\<close>\n        with no_acc show ?thesis \n          apply simp\n          using \\<open>pl\\<noteq>[]\\<close> \n          by blast\n      next\n        case (split p1 p2) \\<comment> \\<open>Case: The loop uses the new edge\\<close>\n        txt \\<open>As done is closed under transitions, the nodes of the edge have\n          already been visited\\<close>\n        from split(2) D_closed_vE_rtrancl \n        have WID: \"w\\<in>D\" \n          using VID by (auto dest!: path_is_rtrancl)\n        from split(1) WID D_closed_vE_rtrancl have \"u\\<in>D\"\n          apply (cases rule: path_edge_cases)\n          apply (auto dest!: path_is_rtrancl)\n          done\n        txt \\<open>Which is a contradition to the assumptions\\<close>\n        with UIL p_not_D have False by (cases p rule: rev_cases) auto\n        thus ?thesis ..\n      qed\n    } note AUX_no_acc = this\n\n\n    show ?thesis \n      apply (simp add: fgl_invar_part_def)\n      apply unfold_locales\n      unfolding vE_remove[OF NE E]\n\n      using AUX_no_acc apply auto []\n\n      apply simp\n      done\n\n  qed\n\n  lemma fgl_outer_invar_initial: \n    \"outer_invar V0 {} \\<Longrightarrow> fgl_outer_invar_ext V0 (None, {})\"\n    unfolding fgl_outer_invar_ext_def\n    apply (simp add: no_acc_over_def)\n    done\n\n  lemma fgl_outer_invar_brk:\n    assumes INV: \"fgl_invar v0 D0 (Some (Vr,Vl),p,D,pE)\"\n    shows \"fgl_outer_invar_ext anyIt (Some (Vr,Vl), anyD)\"\n  proof -\n    from INV interpret fgl_invar_loc G v0 D0 \"Some (Vr,Vl)\" p D pE\n      by (simp add: fgl_invar_def)\n\n    from acc show ?thesis by (simp add: fgl_outer_invar_ext_def)\n  qed\n\n  lemma fgl_outer_invar_newnode_nobrk:\n    assumes A: \"v0\\<notin>D0\" \"v0\\<in>it\" \n    assumes OINV: \"fgl_outer_invar it (None,D0)\"\n    assumes INV: \"fgl_invar v0 D0 (None,[],D',pE)\"\n    shows \"fgl_outer_invar_ext (it-{v0}) (None,D')\"\n  proof -\n    from OINV interpret outer_invar_loc G it D0 \n      unfolding fgl_outer_invar_def outer_invar_def by simp\n\n    from INV interpret inv: fgl_invar_loc G v0 D0 None \"[]\" D' pE \n      unfolding fgl_invar_def by simp\n\n    from inv.pE_fin have [simp]: \"pE = {}\" by simp\n\n    { fix v pl\n      assume A: \"v\\<in>D'\" \"path E v pl v\"\n      have \"path (E \\<inter> D' \\<times> UNIV) v pl v\"\n        apply (rule path_mono[OF _ path_restrict_closed[OF inv.D_closed A]])\n        by auto\n    } note AUX1=this\n\n    show ?thesis\n      unfolding fgl_outer_invar_ext_def\n      apply simp\n      using inv.no_acc AUX1 \n      apply (auto simp add: vE_def touched_def no_acc_over_def) []\n      done\n  qed\n\n  lemma fgl_outer_invar_newnode:\n    assumes A: \"v0\\<notin>D0\" \"v0\\<in>it\" \n    assumes OINV: \"fgl_outer_invar it (None,D0)\"\n    assumes INV: \"fgl_invar v0 D0 (brk,p,D',pE)\"\n    assumes CASES: \"(\\<exists>Vr Vl. brk = Some (Vr, Vl)) \\<or> p = []\"\n    shows \"fgl_outer_invar_ext (it-{v0}) (brk,D')\"\n    using CASES\n    apply (elim disjE1)\n    using fgl_outer_invar_brk[of v0 D0 _ _ p D' pE] INV \n    apply - \n    apply (auto, assumption) []\n    using fgl_outer_invar_newnode_nobrk[OF A] OINV INV apply auto []\n    done\n\n  lemma fgl_outer_invar_Dnode:\n    assumes \"fgl_outer_invar it (None, D)\" \"v\\<in>D\"\n    shows \"fgl_outer_invar_ext (it - {v}) (None, D)\"\n    using assms\n    by (auto simp: fgl_outer_invar_def fgl_outer_invar_ext_def)\n\n  \n  lemma fgl_fin_no_lasso:\n    assumes A: \"fgl_outer_invar {} (None, D)\"\n    assumes B: \"is_lasso_prpl prpl\"\n    shows \"False\"\n  proof -\n    obtain \"pr\" pl where [simp]: \"prpl = (pr,pl)\" by (cases prpl)\n    from A have NA: \"no_acc_over D\" \n      by (simp add: fgl_outer_invar_def fgl_outer_invar_ext_def)\n\n    from A have \"outer_invar {} D\" by (simp add: fgl_outer_invar_def)\n    with fin_outer_D_is_reachable have [simp]: \"D=E\\<^sup>*``V0\" by simp\n\n    from NA B show False\n      apply (simp add: no_acc_over_def is_lasso_prpl_def is_lasso_prpl_pre_def)\n      apply clarsimp\n      apply (blast dest: path_is_rtrancl)\n      done\n  qed\n\n  lemma fgl_fin_lasso:\n    assumes A: \"fgl_outer_invar it (Some (Vr,Vl), D)\"\n    shows \"ce_correct Vr Vl\"\n    using A by (simp add: fgl_outer_invar_def fgl_outer_invar_ext_def)\n\n\n  lemmas fgl_invar_preserve = \n    fgl_invar_initial fgl_invar_push fgl_invar_pop \n    fgl_invar_collapse_ce fgl_invar_collapse_nce fgl_invar_skip\n    fgl_outer_invar_newnode fgl_outer_invar_Dnode\n    invar_initial outer_invar_initial fgl_invar_initial fgl_outer_invar_initial\n    fgl_fin_no_lasso fgl_fin_lasso\n\nend\n\nsection \\<open>Main Correctness Proof\\<close>\n\ncontext igb_fr_graph\nbegin\n  lemma outer_invar_from_fgl_invarI: \n    \"fgl_outer_invar it (None,D) \\<Longrightarrow> outer_invar it D\"\n    unfolding fgl_outer_invar_def outer_invar_def\n    by (simp split: prod.splits)\n\n  lemma invar_from_fgl_invarI: \"fgl_invar v0 D0 (B,PDPE) \\<Longrightarrow> invar v0 D0 PDPE\"\n    unfolding fgl_invar_def invar_def\n    apply (simp split: prod.splits)\n    unfolding fgl_invar_loc_def by simp\n   \n  theorem find_ce_correct: \"find_ce \\<le> find_ce_spec\"\n  proof -\n    note [simp del] = Union_iff\n\n    show ?thesis\n      unfolding find_ce_def find_ce_spec_def select_edge_def select_def\n      apply (refine_rcg\n        WHILEIT_rule[where R=\"inv_image (abs_wf_rel v0) snd\" for v0]\n        refine_vcg \n      )\n      \n      using [[goals_limit = 5]]\n\n      apply (vc_solve\n        rec: fgl_invarI fgl_outer_invarI\n        intro: invar_from_fgl_invarI outer_invar_from_fgl_invarI\n        dest!: sym[of \"collapse a b\" for a b]\n        simp: collapse_ne\n        simp: pE_fin'[OF invar_from_fgl_invarI] finite_V0\n        solve: invar_preserve \n        solve: asm_rl[of \"_ \\<inter> _ = {}\"]\n        solve: fgl_invar_preserve)\n      done\n  qed\nend\n\nsection \"Emptiness Check\"\ntext \\<open>Using the lasso-finding algorithm, we can define an emptiness check\\<close>\n\ncontext igb_fr_graph\nbegin\n  definition \"abs_is_empty \\<equiv> do {\n    ce \\<leftarrow> find_ce;\n    RETURN (ce = None)\n    }\"\n\n  theorem abs_is_empty_correct: \n    \"abs_is_empty \\<le> SPEC (\\<lambda>res. res \\<longleftrightarrow> (\\<forall>r. \\<not>is_acc_run r))\"\n    unfolding abs_is_empty_def\n    apply (refine_rcg refine_vcg \n      order_trans[OF find_ce_correct, unfolded find_ce_spec_def])\n    unfolding ce_correct_def\n    using lasso_accepted accepted_lasso\n    apply (clarsimp split: option.splits)\n    apply (metis is_lasso_prpl_of_lasso surj_pair)\n    by (metis is_lasso_prpl_conv)\n\n  definition \"abs_is_empty_ce \\<equiv> do {\n    ce \\<leftarrow> find_ce;\n    case ce of\n      None \\<Rightarrow> RETURN None\n    | Some (Vr,Vl) \\<Rightarrow> do {\n        ASSERT (\\<exists>pr pl. set pr \\<subseteq> Vr \\<and> set pl \\<subseteq> Vl \\<and> Vl \\<times> Vl \\<subseteq> (E \\<inter> Vl\\<times>Vl)\\<^sup>* \n          \\<and> is_lasso_prpl (pr,pl));\n        (pr,pl) \\<leftarrow> SPEC (\\<lambda>(pr,pl). \n           set pr \\<subseteq> Vr \n          \\<and> set pl \\<subseteq> Vl \n          \\<and> Vl \\<times> Vl \\<subseteq> (E \\<inter> Vl\\<times>Vl)\\<^sup>*\n          \\<and> is_lasso_prpl (pr,pl));\n        RETURN (Some (pr,pl))\n      }\n    }\"\n\n  theorem abs_is_empty_ce_correct: \"abs_is_empty_ce \\<le> SPEC (\\<lambda>res. case res of\n      None \\<Rightarrow> (\\<forall>r. \\<not>is_acc_run r)\n    | Some (pr,pl) \\<Rightarrow> is_acc_run (pr\\<frown>pl\\<^sup>\\<omega>)\n    )\"\n    unfolding abs_is_empty_ce_def\n    apply (refine_rcg refine_vcg \n      order_trans[OF find_ce_correct, unfolded find_ce_spec_def])\n\n    apply (clarsimp_all simp: ce_correct_def)\n\n    using accepted_lasso finite_reachableE_V0 apply (metis is_lasso_prpl_of_lasso surj_pair)\n    apply blast\n    apply (simp add: lasso_prpl_acc_run)\n    done\n\nend\n\nsection \\<open>Refinement\\<close>\ntext \\<open>\n  In this section, we refine the lasso finding algorithm to use efficient\n  data structures. First, we explicitely keep track of the set of acceptance\n  classes for every c-node on the path. Second, we use Gabow's data structure\n  to represent the path.\n\\<close>\n\nsubsection \\<open>Addition of Explicit Accepting Sets\\<close>\ntext \\<open>In a first step, we explicitely keep track of the current set of\n  acceptance classes for every c-node on the path.\\<close>\n\ntype_synonym 'a abs_gstate = \"nat set list \\<times> 'a abs_state\"\ntype_synonym 'a ce = \"('a set \\<times> 'a set) option\"\ntype_synonym 'a abs_gostate = \"'a ce \\<times> 'a set\"\n\ncontext igb_fr_graph\nbegin\n\n  definition gstate_invar :: \"'Q abs_gstate \\<Rightarrow> bool\" where \n    \"gstate_invar \\<equiv> \\<lambda>(a,p,D,pE). a = map (\\<lambda>V. \\<Union>(acc`V)) p\"\n\n  definition \"gstate_rel \\<equiv> br snd gstate_invar\"\n\n  lemma gstate_rel_sv[relator_props,simp,intro!]: \"single_valued gstate_rel\"\n    by (simp add: gstate_rel_def)\n\n  definition (in -) gcollapse_aux \n    :: \"nat set list \\<Rightarrow> 'a set list \\<Rightarrow> nat \\<Rightarrow> nat set list \\<times> 'a set list\"\n    where \"gcollapse_aux a p i \\<equiv> \n      (take i a @ [\\<Union>(set (drop i a))],take i p @ [\\<Union>(set (drop i p))])\"\n\n  definition (in -) gcollapse :: \"'a \\<Rightarrow> 'a abs_gstate \\<Rightarrow> 'a abs_gstate\" \n    where \"gcollapse v APDPE \\<equiv> \n    let \n      (a,p,D,pE)=APDPE; \n      i=idx_of p v;\n      (a,p) = gcollapse_aux a p i\n    in (a,p,D,pE)\"\n\n  definition \"gpush v s \\<equiv> \n    let\n      (a,s) = s\n    in\n      (a@[acc v],push v s)\"\n\n  definition \"gpop s \\<equiv>\n    let (a,s) = s in (butlast a,pop s)\"\n\n  definition ginitial :: \"'Q \\<Rightarrow> 'Q abs_gostate \\<Rightarrow> 'Q abs_gstate\" \n    where \"ginitial v0 s0 \\<equiv> ([acc v0], initial v0 (snd s0))\"\n\n  definition goinitial :: \"'Q abs_gostate\" where \"goinitial \\<equiv> (None,{})\"\n  definition go_is_no_brk :: \"'Q abs_gostate \\<Rightarrow> bool\" \n    where \"go_is_no_brk s \\<equiv> fst s = None\"\n  definition goD :: \"'Q abs_gostate \\<Rightarrow> 'Q set\" where \"goD s \\<equiv> snd s\"\n  definition goBrk :: \"'Q abs_gostate \\<Rightarrow> 'Q ce\" where \"goBrk s \\<equiv> fst s\"\n  definition gto_outer :: \"'Q ce \\<Rightarrow> 'Q abs_gstate \\<Rightarrow> 'Q abs_gostate\" \n    where \"gto_outer brk s \\<equiv> let (A,p,D,pE)=s in (brk,D)\"\n\n  definition \"gselect_edge s \\<equiv> do {\n    let (a,s)=s; \n    (r,s)\\<leftarrow>select_edge s;\n    RETURN (r,a,s) \n  }\"\n\n  definition gfind_ce :: \"('Q set \\<times> 'Q set) option nres\" where\n    \"gfind_ce \\<equiv> do {\n      let os = goinitial;\n      os\\<leftarrow>FOREACHci fgl_outer_invar V0 (go_is_no_brk) (\\<lambda>v0 s0. do {\n        if v0\\<notin>goD s0 then do {\n          let s = (None,ginitial v0 s0);\n\n          (brk,a,p,D,pE) \\<leftarrow> WHILEIT (\\<lambda>(brk,a,s). fgl_invar v0 (goD s0) (brk,s))\n            (\\<lambda>(brk,a,p,D,pE). brk=None \\<and> p \\<noteq> []) (\\<lambda>(_,a,p,D,pE). \n          do {\n            \\<comment> \\<open>Select edge from end of path\\<close>\n            (vo,(a,p,D,pE)) \\<leftarrow> gselect_edge (a,p,D,pE);\n\n            ASSERT (p\\<noteq>[]);\n            case vo of \n              Some v \\<Rightarrow> do {\n                if v \\<in> \\<Union>(set p) then do {\n                  \\<comment> \\<open>Collapse\\<close>\n                  let (a,p,D,pE) = gcollapse v (a,p,D,pE);\n\n                  ASSERT (p\\<noteq>[]);\n                  ASSERT (a\\<noteq>[]);\n\n                  if last a = {0..<num_acc} then\n                    RETURN (Some (\\<Union>(set (butlast p)),last p),a,p,D,pE)\n                  else\n                    RETURN (None,a,p,D,pE)\n                } else if v\\<notin>D then do {\n                  \\<comment> \\<open>Edge to new node. Append to path\\<close>\n                  RETURN (None,gpush v (a,p,D,pE))\n                } else RETURN (None,a,p,D,pE)\n              }\n            | None \\<Rightarrow> do {\n                \\<comment> \\<open>No more outgoing edges from current node on path\\<close>\n                ASSERT (pE \\<inter> last p \\<times> UNIV = {});\n                RETURN (None,gpop (a,p,D,pE))\n              }\n          }) s;\n          ASSERT (brk=None \\<longrightarrow> (p=[] \\<and> pE={}));\n          RETURN (gto_outer brk (a,p,D,pE))\n        } else RETURN s0\n    }) os;\n    RETURN (goBrk os)\n  }\"\n\n  lemma gcollapse_refine:\n    \"\\<lbrakk>(v',v)\\<in>Id; (s',s)\\<in>gstate_rel\\<rbrakk> \n      \\<Longrightarrow> (gcollapse v' s',collapse v s)\\<in>gstate_rel\"\n    unfolding gcollapse_def collapse_def collapse_aux_def gcollapse_aux_def \n    apply (simp add: gstate_rel_def br_def Let_def)\n    unfolding gstate_invar_def[abs_def]\n    apply (auto split: prod.splits simp: take_map drop_map)\n    done\n\n  \n\n  lemma gpop_refine:\n    \"\\<lbrakk>(s',s)\\<in>gstate_rel\\<rbrakk> \\<Longrightarrow> (gpop s',pop s)\\<in>gstate_rel\"\n    unfolding gpop_def pop_def \n    apply (simp add: gstate_rel_def br_def)\n    unfolding gstate_invar_def[abs_def]\n    apply (auto split: prod.splits simp: map_butlast)\n    done\n\n  lemma ginitial_refine:\n    \"(ginitial x (None, b), initial x b) \\<in> gstate_rel\"\n    unfolding ginitial_def gstate_rel_def br_def gstate_invar_def initial_def\n    by auto\n\n  lemma oinitial_b_refine: \"((None,{}),(None,{}))\\<in>Id\\<times>\\<^sub>rId\" by simp\n\n  lemma gselect_edge_refine: \"\\<lbrakk>(s',s)\\<in>gstate_rel\\<rbrakk> \\<Longrightarrow> gselect_edge s' \n    \\<le>\\<Down>(\\<langle>Id\\<rangle>option_rel \\<times>\\<^sub>r gstate_rel) (select_edge s)\"\n    unfolding gselect_edge_def select_edge_def\n    apply (simp add: pw_le_iff refine_pw_simps prod_rel_sv\n      split: prod.splits option.splits)\n\n    apply (auto simp: gstate_rel_def br_def gstate_invar_def)\n    done\n\n  lemma last_acc_impl:\n    assumes \"p\\<noteq>[]\"\n    assumes \"((a',p',D',pE'),(p,D,pE))\\<in>gstate_rel\"\n    shows \"(last a' = {0..<num_acc}) = (\\<forall>i<num_acc. \\<exists>q\\<in>last p. i\\<in>acc q)\"\n    using assms acc_bound unfolding gstate_rel_def br_def gstate_invar_def\n    by (auto simp: last_map)\n\n  lemma fglr_aux1:\n    assumes V: \"(v',v)\\<in>Id\" and S: \"(s',s)\\<in>gstate_rel\" \n      and P: \"\\<And>a' p' D' pE' p D pE. ((a',p',D',pE'),(p,D,pE))\\<in>gstate_rel \n      \\<Longrightarrow> f' a' p' D' pE' \\<le>\\<Down>R (f p D pE)\"\n    shows \"(let (a',p',D',pE') = gcollapse v' s' in f' a' p' D' pE') \n      \\<le> \\<Down>R (let (p,D,pE) = collapse v s in f p D pE)\"\n    apply (auto split: prod.splits)\n    apply (rule P)\n    using gcollapse_refine[OF V S]\n    apply simp\n    done\n\n  lemma gstate_invar_empty: \n    \"gstate_invar (a,[],D,pE) \\<Longrightarrow> a=[]\"\n    \"gstate_invar ([],p,D,pE) \\<Longrightarrow> p=[]\"\n    by (auto simp add: gstate_invar_def)\n\n  lemma find_ce_refine: \"gfind_ce \\<le>\\<Down>Id find_ce\"\n    unfolding gfind_ce_def find_ce_def\n    unfolding goinitial_def go_is_no_brk_def[abs_def] goD_def goBrk_def \n      gto_outer_def\n    using [[goals_limit = 1]]\n    apply (refine_rcg \n      gselect_edge_refine prod_relI[OF IdI gpop_refine]\n      prod_relI[OF IdI gpush_refine]\n      fglr_aux1 last_acc_impl oinitial_b_refine\n      inj_on_id\n    )\n    apply refine_dref_type\n    apply (simp_all add: ginitial_refine)\n    apply (vc_solve (nopre) \n      solve: asm_rl \n      simp: gstate_rel_def br_def gstate_invar_empty)\n    done\nend\n\nsubsection \\<open>Refinement to Gabow's Data Structure\\<close>\n\nsubsubsection \\<open>Preliminaries\\<close>\ndefinition Un_set_drop_impl :: \"nat \\<Rightarrow> 'a set list \\<Rightarrow> 'a set nres\"\n  \\<comment> \\<open>Executable version of @{text \"\\<Union>set (drop i A)\"}, using indexing to\n  access @{text \"A\"}\\<close>\n  where \"Un_set_drop_impl i A \\<equiv> \n  do {\n    (_,res) \\<leftarrow> WHILET (\\<lambda>(i,res). i < length A) (\\<lambda>(i,res). do {\n      ASSERT (i<length A);\n      let res = A!i \\<union> res;\n      let i = i + 1;\n      RETURN (i,res)\n    }) (i,{});\n    RETURN res\n  }\"\n\nlemma Un_set_drop_impl_correct: \n  \"Un_set_drop_impl i A \\<le> SPEC (\\<lambda>r. r=\\<Union>(set (drop i A)))\"\n  unfolding Un_set_drop_impl_def\n  apply (refine_rcg \n    WHILET_rule[where I=\"\\<lambda>(i',res). res=\\<Union>(set ((drop i (take i' A)))) \\<and> i\\<le>i'\" \n    and R=\"measure (\\<lambda>(i',_). length A - i')\"] \n    refine_vcg)\n  apply (auto simp: take_Suc_conv_app_nth)\n  done\n\nschematic_goal Un_set_drop_code_aux: \n  assumes [autoref_rules]: \"(es_impl,{})\\<in>\\<langle>R\\<rangle>Rs\"\n  assumes [autoref_rules]: \"(un_impl,(\\<union>))\\<in>\\<langle>R\\<rangle>Rs\\<rightarrow>\\<langle>R\\<rangle>Rs\\<rightarrow>\\<langle>R\\<rangle>Rs\"\n  shows \"(?c,Un_set_drop_impl)\\<in>nat_rel \\<rightarrow> \\<langle>\\<langle>R\\<rangle>Rs\\<rangle>as_rel \\<rightarrow> \\<langle>\\<langle>R\\<rangle>Rs\\<rangle>nres_rel\"\n  unfolding Un_set_drop_impl_def[abs_def]\n  apply (autoref (trace, keep_goal))\n  done\nconcrete_definition Un_set_drop_code uses Un_set_drop_code_aux\n\nschematic_goal Un_set_drop_tr_aux: \n  \"RETURN ?c \\<le> Un_set_drop_code es_impl un_impl i A\"\n  unfolding Un_set_drop_code_def\n  by refine_transfer\nconcrete_definition Un_set_drop_tr for es_impl un_impl i A \n  uses Un_set_drop_tr_aux \n\nlemma Un_set_drop_autoref[autoref_rules]: \n  assumes \"GEN_OP es_impl {} (\\<langle>R\\<rangle>Rs)\"\n  assumes \"GEN_OP un_impl (\\<union>) (\\<langle>R\\<rangle>Rs\\<rightarrow>\\<langle>R\\<rangle>Rs\\<rightarrow>\\<langle>R\\<rangle>Rs)\"\n  shows \"(\\<lambda>i A. RETURN (Un_set_drop_tr es_impl un_impl i A),Un_set_drop_impl)\n    \\<in>nat_rel \\<rightarrow> \\<langle>\\<langle>R\\<rangle>Rs\\<rangle>as_rel \\<rightarrow> \\<langle>\\<langle>R\\<rangle>Rs\\<rangle>nres_rel\"\n  apply (intro fun_relI nres_relI)\n  apply (rule order_trans[OF Un_set_drop_tr.refine])\n  using Un_set_drop_code.refine[of es_impl Rs R un_impl, \n    param_fo, THEN nres_relD]\n  using assms\n  by simp\n\n\nsubsubsection \\<open>Actual Refinement\\<close>\n\ntype_synonym 'Q gGS = \"nat set list \\<times> 'Q GS\"\n\ntype_synonym 'Q goGS = \"'Q ce \\<times> 'Q oGS\"\n\ncontext igb_graph\nbegin\n\ndefinition gGS_invar :: \"'Q gGS \\<Rightarrow> bool\"\n  where \"gGS_invar s \\<equiv> \n  let (a,S,B,I,P) = s in \n    GS_invar (S,B,I,P)\n    \\<and> length a = length B\n    \\<and> \\<Union>(set a) \\<subseteq> {0..<num_acc}\n  \"\n\ndefinition gGS_\\<alpha> :: \"'Q gGS \\<Rightarrow> 'Q abs_gstate\"\n  where \"gGS_\\<alpha> s \\<equiv> let (a,s)=s in (a,GS.\\<alpha> s)\"\n\ndefinition \"gGS_rel \\<equiv> br gGS_\\<alpha> gGS_invar\"\n\nlemma gGS_rel_sv[relator_props,intro!,simp]: \"single_valued gGS_rel\"\n  unfolding gGS_rel_def by auto\n\n\ndefinition goGS_invar :: \"'Q goGS \\<Rightarrow> bool\" where\n  \"goGS_invar s \\<equiv> let (brk,ogs)=s in brk=None \\<longrightarrow> oGS_invar ogs\"\n\ndefinition \"goGS_\\<alpha> s \\<equiv> let (brk,ogs)=s in (brk,oGS_\\<alpha> ogs)\"\n\ndefinition \"goGS_rel \\<equiv> br goGS_\\<alpha> goGS_invar\"\n\nlemma goGS_rel_sv[relator_props,intro!,simp]: \"single_valued goGS_rel\"\n  unfolding goGS_rel_def by auto\n\nend\n\n\ncontext igb_fr_graph\nbegin\n  lemma gGS_relE:\n    assumes \"(s',(a,p,D,pE))\\<in>gGS_rel\"\n    obtains S' B' I' P' where \"s'=(a,S',B',I',P')\" \n      and \"((S',B',I',P'),(p,D,pE))\\<in>GS_rel\" \n      and \"length a = length B'\"\n      and \"\\<Union>(set a) \\<subseteq> {0..<num_acc}\"\n    using assms\n    apply (cases s')\n    apply (simp add: gGS_rel_def br_def gGS_\\<alpha>_def GS.\\<alpha>_def)\n    apply (rule that)\n    apply (simp only:)\n    apply (auto simp: GS_rel_def br_def gGS_invar_def GS.\\<alpha>_def)\n    done\n\n\n  definition goinitial_impl :: \"'Q goGS\" \n    where \"goinitial_impl \\<equiv> (None,Map.empty)\"\n  lemma goinitial_impl_refine: \"(goinitial_impl,goinitial)\\<in>goGS_rel\"\n    by (auto \n      simp: goinitial_impl_def goinitial_def goGS_rel_def br_def \n      simp: goGS_\\<alpha>_def goGS_invar_def oGS_\\<alpha>_def oGS_invar_def)\n\n  definition gto_outer_impl :: \"'Q ce \\<Rightarrow> 'Q gGS \\<Rightarrow> 'Q goGS\"\n    where \"gto_outer_impl brk s \\<equiv> let (A,S,B,I,P)=s in (brk,I)\"\n\n  lemma gto_outer_refine:\n    assumes A: \"brk = None \\<longrightarrow> (p=[] \\<and> pE={})\"\n    assumes B: \"(s, (A,p, D, pE)) \\<in> gGS_rel\"\n    assumes C: \"(brk',brk)\\<in>Id\"\n    shows \"(gto_outer_impl brk' s,gto_outer brk (A,p,D,pE))\\<in>goGS_rel\"\n  proof (cases s)\n    fix A S B I P\n    assume [simp]: \"s=(A,S,B,I,P)\"\n    show ?thesis\n      using C\n      apply (cases brk)\n      using assms I_to_outer[of S B I P D]\n      apply (auto \n        simp: goGS_rel_def br_def goGS_\\<alpha>_def gto_outer_def \n              gto_outer_impl_def goGS_invar_def \n        simp: gGS_rel_def oGS_rel_def GS_rel_def gGS_\\<alpha>_def gGS_invar_def \n              GS.\\<alpha>_def) []\n\n      using B apply (auto \n        simp: gto_outer_def gto_outer_impl_def\n        simp: br_def goGS_rel_def goGS_invar_def goGS_\\<alpha>_def oGS_\\<alpha>_def\n        simp: gGS_rel_def gGS_\\<alpha>_def GS.\\<alpha>_def GS.D_\\<alpha>_def\n      )\n\n      done\n  qed\n\n  definition \"gpush_impl v s \\<equiv> let (a,s)=s in (a@[acc v], push_impl v s)\"\n\n\n  lemma gpush_impl_refine:\n    assumes B: \"(s',(a,p,D,pE))\\<in>gGS_rel\"\n    assumes A: \"(v',v)\\<in>Id\" \n    assumes PRE: \"v' \\<notin> \\<Union>(set p)\" \"v' \\<notin> D\"\n    shows \"(gpush_impl v' s', gpush v (a,p,D,pE))\\<in>gGS_rel\"\n  proof -\n    from B obtain S' B' I' P' where [simp]: \"s'=(a,S',B',I',P')\" \n      and OSR: \"((S',B',I',P'),(p,D,pE))\\<in>GS_rel\" and L: \"length a = length B'\" \n      and R: \"\\<Union>(set a) \\<subseteq> {0..<num_acc}\"\n      by (rule gGS_relE)\n    {\n      fix S B I P S' B' I' P'\n      assume \"push_impl v (S, B, I, P) = (S', B', I', P')\"\n      hence \"length B' = Suc (length B)\" \n        by (auto simp add: push_impl_def GS.push_impl_def Let_def)  \n    } note AUX1=this\n\n    from push_refine[OF OSR A PRE] A L acc_bound R show ?thesis\n      unfolding gpush_impl_def gpush_def\n        gGS_rel_def gGS_invar_def gGS_\\<alpha>_def GS_rel_def br_def\n      apply (auto dest: AUX1)\n      done\n  qed\n  \n  definition gpop_impl :: \"'Q gGS \\<Rightarrow> 'Q gGS nres\" \n    where \"gpop_impl s \\<equiv> do {\n    let (a,s)=s;\n    s\\<leftarrow>pop_impl s;\n    ASSERT (a\\<noteq>[]);\n    let a = butlast a;\n    RETURN (a,s)\n  }\"\n\n  lemma gpop_impl_refine:\n    assumes A: \"(s',(a,p,D,pE))\\<in>gGS_rel\"\n    assumes PRE: \"p \\<noteq> []\" \"pE \\<inter> last p \\<times> UNIV = {}\"\n    shows \"gpop_impl s' \\<le> \\<Down>gGS_rel (RETURN (gpop (a,p,D,pE)))\"\n  proof -\n    from A obtain S' B' I' P' where [simp]: \"s'=(a,S',B',I',P')\" \n      and OSR: \"((S',B',I',P'),(p,D,pE))\\<in>GS_rel\" and L: \"length a = length B'\"\n      and R: \"\\<Union>(set a) \\<subseteq> {0..<num_acc}\"\n      by (rule gGS_relE)\n\n    from PRE OSR have [simp]: \"a\\<noteq>[]\" using L\n      by (auto simp add: GS_rel_def br_def GS.\\<alpha>_def GS.p_\\<alpha>_def)\n\n    {\n      fix S B I P S' B' I' P'\n      assume \"nofail (pop_impl ((S, B, I, P)::'a GS))\"\n        \"inres (pop_impl ((S, B, I, P)::'a GS)) (S', B', I', P')\"\n      hence \"length B' = length B - Suc 0\"\n        apply (simp add: pop_impl_def GS.pop_impl_def Let_def\n          refine_pw_simps)\n        apply auto\n        done\n    } note AUX1=this\n\n    from A L show ?thesis\n      unfolding gpop_impl_def gpop_def gGS_rel_def gGS_\\<alpha>_def br_def\n      apply (simp add: Let_def)\n      using pop_refine[OF OSR PRE]\n      apply (simp add: pw_le_iff refine_pw_simps split: prod.splits)\n      unfolding gGS_rel_def gGS_invar_def gGS_\\<alpha>_def GS_rel_def GS.\\<alpha>_def br_def\n      apply (auto dest!: AUX1 in_set_butlastD iff: Sup_le_iff)\n      done\n  qed\n  \n  definition gselect_edge_impl :: \"'Q gGS \\<Rightarrow> ('Q option \\<times> 'Q gGS) nres\" \n    where \"gselect_edge_impl s \\<equiv> \n    do { \n      let (a,s)=s; \n      (vo,s)\\<leftarrow>select_edge_impl s; \n      RETURN (vo,a,s)\n    }\"\n\n  thm select_edge_refine\n  lemma gselect_edge_impl_refine:\n    assumes A: \"(s', a, p, D, pE) \\<in> gGS_rel\" \n    assumes PRE: \"p \\<noteq> []\"\n    shows \"gselect_edge_impl s' \\<le> \\<Down>(Id \\<times>\\<^sub>r gGS_rel) (gselect_edge (a, p, D, pE))\"\n  proof -\n    from A obtain S' B' I' P' where [simp]: \"s'=(a,S',B',I',P')\" \n      and OSR: \"((S',B',I',P'),(p,D,pE))\\<in>GS_rel\" and L: \"length a = length B'\"\n      and R: \"\\<Union>(set a) \\<subseteq> {0..<num_acc}\"\n      by (rule gGS_relE)\n\n    {\n      fix S B I P S' B' I' P' vo\n      assume \"nofail (select_edge_impl ((S, B, I, P)::'a GS))\"\n        \"inres (select_edge_impl ((S, B, I, P)::'a GS)) (vo, (S', B', I', P'))\"\n      hence \"length B' = length B\"\n        apply (simp add: select_edge_impl_def GS.sel_rem_last_def refine_pw_simps\n          split: if_split_asm prod.splits)\n        apply auto\n        done\n    } note AUX1=this\n\n    show ?thesis\n      using select_edge_refine[OF OSR PRE]\n      unfolding gselect_edge_impl_def gselect_edge_def\n      apply (simp add: refine_pw_simps pw_le_iff prod_rel_sv)\n\n      unfolding gGS_rel_def br_def gGS_\\<alpha>_def gGS_invar_def GS_rel_def GS.\\<alpha>_def\n      apply (simp split: prod.splits)\n      apply clarsimp\n      using R\n      apply (auto simp: L dest: AUX1)\n      done\n  qed\n\n\n  term GS.idx_of_impl\n\n  thm GS_invar.idx_of_correct\n\n\n  definition gcollapse_impl_aux :: \"'Q \\<Rightarrow> 'Q gGS \\<Rightarrow> 'Q gGS nres\" where \n    \"gcollapse_impl_aux v s \\<equiv> \n    do { \n      let (A,s)=s;\n      \\<^cancel>\\<open>ASSERT (v\\<in>\\<Union>set (GS.p_\\<alpha> s));\\<close>\n      i \\<leftarrow> GS.idx_of_impl s v;\n      s \\<leftarrow> collapse_impl v s;\n      ASSERT (i < length A);\n      us \\<leftarrow> Un_set_drop_impl i A;\n      let A = take i A @ [us];\n      RETURN (A,s)\n    }\"\n\n  term collapse\n  lemma gcollapse_alt:\n    \"gcollapse v APDPE = ( \n      let \n        (a,p,D,pE)=APDPE; \n        i=idx_of p v;\n        s=collapse v (p,D,pE);\n        us=\\<Union>(set (drop i a));\n        a = take i a @ [us]\n      in (a,s))\"\n    unfolding gcollapse_def gcollapse_aux_def collapse_def collapse_aux_def\n    by auto\n\n  thm collapse_refine\n  lemma gcollapse_impl_aux_refine:\n    assumes A: \"(s', a, p, D, pE) \\<in> gGS_rel\" \n    assumes B: \"(v',v)\\<in>Id\"\n    assumes PRE: \"v\\<in>\\<Union>(set p)\"\n    shows \"gcollapse_impl_aux v' s' \n      \\<le> \\<Down> gGS_rel (RETURN (gcollapse v (a, p, D, pE)))\"\n  proof -\n    note [simp] = Let_def\n\n    from A obtain S' B' I' P' where [simp]: \"s'=(a,S',B',I',P')\" \n      and OSR: \"((S',B',I',P'),(p,D,pE))\\<in>GS_rel\" and L: \"length a = length B'\"\n      and R: \"\\<Union>(set a) \\<subseteq> {0..<num_acc}\"\n      by (rule gGS_relE)\n\n    from B have [simp]: \"v'=v\" by simp\n\n    from OSR have [simp]: \"GS.p_\\<alpha> (S',B',I',P') = p\"\n      by (simp add: GS_rel_def br_def GS.\\<alpha>_def)\n\n    from OSR PRE have PRE': \"v \\<in> \\<Union>(set (GS.p_\\<alpha> (S',B',I',P')))\"\n      by (simp add: GS_rel_def br_def GS.\\<alpha>_def)\n\n    from OSR have GS_invar: \"GS_invar (S',B',I',P')\" \n      by (simp add: GS_rel_def br_def)\n\n    term GS.B\n    {\n      fix s\n      assume \"collapse v (p, D, pE) = (GS.p_\\<alpha> s, GS.D_\\<alpha> s, GS.pE_\\<alpha> s)\"\n      hence \"length (GS.B s) = Suc (idx_of p v)\"\n        unfolding collapse_def collapse_aux_def Let_def\n        apply (cases s)\n        apply (auto simp: GS.p_\\<alpha>_def)\n        apply (drule arg_cong[where f=length])\n        using GS_invar.p_\\<alpha>_disjoint_sym[OF GS_invar]\n          and PRE \\<open>GS.p_\\<alpha> (S', B', I', P') = p\\<close> idx_of_props(1)[of p v]\n        by simp\n    } note AUX1 = this\n\n    show ?thesis\n      unfolding gcollapse_alt gcollapse_impl_aux_def\n      apply simp\n      apply (rule RETURN_as_SPEC_refine)\n      apply (refine_rcg\n        order_trans[OF GS_invar.idx_of_correct[OF GS_invar PRE']] \n        order_trans[OF collapse_refine[OF OSR B PRE, simplified]]\n        refine_vcg\n      )\n      using PRE' apply simp\n      \n      apply (simp add: L)\n\n      using Un_set_drop_impl_correct acc_bound R\n      apply (simp add: refine_pw_simps pw_le_iff)\n      unfolding gGS_rel_def GS_rel_def GS.\\<alpha>_def br_def gGS_\\<alpha>_def gGS_invar_def\n      apply (clarsimp simp: L dest!: AUX1)\n      apply (auto dest!: AUX1 simp: L)\n      apply (force dest!: in_set_dropD) []\n      apply (force dest!: in_set_takeD) []\n      done\n  qed\n\n  definition gcollapse_impl :: \"'Q \\<Rightarrow> 'Q gGS \\<Rightarrow> 'Q gGS nres\" \n    where \"gcollapse_impl v s \\<equiv>     \n    do { \n      let (A,S,B,I,P)=s;\n      i \\<leftarrow> GS.idx_of_impl (S,B,I,P) v;\n      ASSERT (i+1 \\<le> length B);\n      let B = take (i+1) B;\n      ASSERT (i < length A);\n      us\\<leftarrow>Un_set_drop_impl i A;\n      let A = take i A @ [us];\n      RETURN (A,S,B,I,P)\n    }\"\n\n  lemma gcollapse_impl_aux_opt_refine: \n    \"gcollapse_impl v s \\<le> gcollapse_impl_aux v s\"\n    unfolding gcollapse_impl_def gcollapse_impl_aux_def collapse_impl_def \n      GS.collapse_impl_def\n    apply (simp add: refine_pw_simps pw_le_iff split: prod.splits) \n    apply blast\n    done\n  \n  lemma gcollapse_impl_refine:\n    assumes A: \"(s', a, p, D, pE) \\<in> gGS_rel\" \n    assumes B: \"(v',v)\\<in>Id\"\n    assumes PRE: \"v\\<in>\\<Union>(set p)\"\n    shows \"gcollapse_impl v' s' \n    \\<le> \\<Down> gGS_rel (RETURN (gcollapse v (a, p, D, pE)))\"\n    using order_trans[OF \n      gcollapse_impl_aux_opt_refine \n      gcollapse_impl_aux_refine[OF assms]]\n    .\n\n  definition ginitial_impl :: \"'Q \\<Rightarrow> 'Q goGS \\<Rightarrow> 'Q gGS\" \n    where \"ginitial_impl v0 s0 \\<equiv> ([acc v0],initial_impl v0 (snd s0))\"\n  lemma ginitial_impl_refine: \n    assumes A: \"v0\\<notin>goD s0\" \"go_is_no_brk s0\"\n    assumes REL: \"(s0i,s0)\\<in>goGS_rel\" \"(v0i,v0)\\<in>Id\" \n    shows \"(ginitial_impl v0i s0i,ginitial v0 s0)\\<in>gGS_rel\"\n    unfolding ginitial_impl_def ginitial_def \n    using REL initial_refine[OF A(1) _ REL(2), of \"snd s0i\"] A(2)\n    apply (auto \n      simp: gGS_rel_def br_def gGS_\\<alpha>_def gGS_invar_def goGS_rel_def goGS_\\<alpha>_def\n      simp: go_is_no_brk_def goD_def oGS_rel_def GS_rel_def goGS_invar_def\n      split: prod.splits\n\n    )\n    using acc_bound\n    apply (fastforce simp: initial_impl_def GS_initial_impl_def)+\n    done\n\n  definition gpath_is_empty_impl :: \"'Q gGS \\<Rightarrow> bool\"\n    where \"gpath_is_empty_impl s = path_is_empty_impl (snd s)\"\n\n  lemma gpath_is_empty_refine: \n    \"(s,(a,p,D,pE))\\<in>gGS_rel \\<Longrightarrow> gpath_is_empty_impl s \\<longleftrightarrow> p=[]\"\n    unfolding gpath_is_empty_impl_def \n    using path_is_empty_refine\n    by (fastforce simp: gGS_rel_def br_def gGS_invar_def gGS_\\<alpha>_def GS.\\<alpha>_def)\n\n  definition gis_on_stack_impl :: \"'Q \\<Rightarrow> 'Q gGS \\<Rightarrow> bool\" \n    where \"gis_on_stack_impl v s = is_on_stack_impl v (snd s)\"\n\n  lemma gis_on_stack_refine: \n    \"\\<lbrakk>(s,(a,p,D,pE))\\<in>gGS_rel\\<rbrakk> \\<Longrightarrow> gis_on_stack_impl v s \\<longleftrightarrow> v\\<in>\\<Union>(set p)\"\n    unfolding gis_on_stack_impl_def \n    using is_on_stack_refine\n    by (fastforce simp: gGS_rel_def br_def gGS_invar_def gGS_\\<alpha>_def GS.\\<alpha>_def)\n\n  definition gis_done_impl :: \"'Q \\<Rightarrow> 'Q gGS \\<Rightarrow> bool\"\n    where \"gis_done_impl v s \\<equiv> is_done_impl v (snd s)\"\n  thm is_done_refine\n  lemma gis_done_refine: \"(s,(a,p,D,pE))\\<in>gGS_rel \n    \\<Longrightarrow> gis_done_impl v s \\<longleftrightarrow> (v \\<in> D)\"\n    using is_done_refine[of \"(snd s)\" v]\n    by (auto \n      simp: gGS_rel_def br_def gGS_\\<alpha>_def gGS_invar_def GS.\\<alpha>_def \n            gis_done_impl_def)\n\n\n  definition (in -) \"on_stack_less I u v \\<equiv> \n    case I v of \n      Some (STACK j) \\<Rightarrow> j<u\n    | _ \\<Rightarrow> False\"\n\n  definition (in -) \"on_stack_ge I l v \\<equiv> \n    case I v of \n      Some (STACK j) \\<Rightarrow> l\\<le>j\n    | _ \\<Rightarrow> False\"\n\n\n  lemma (in GS_invar) set_butlast_p_refine:\n    assumes PRE: \"p_\\<alpha>\\<noteq>[]\"\n    shows \"Collect (on_stack_less I (last B)) = \\<Union>(set (butlast p_\\<alpha>))\" (is \"?L=?R\")\n  proof (intro equalityI subsetI)\n    from PRE have [simp]: \"B\\<noteq>[]\" by (auto simp: p_\\<alpha>_def)\n\n    have [simp]: \"S\\<noteq>[]\"\n      by (simp add: empty_eq)\n\n    {\n      fix v\n      assume \"v\\<in>?L\"\n      then obtain j where [simp]: \"I v = Some (STACK j)\" and \"j<last B\"\n        by (auto simp: on_stack_less_def split: option.splits node_state.splits)\n\n      from I_consistent[of v j] have [simp]: \"j<length S\" \"v=S!j\" by auto\n      \n      from B0 have \"B!0=0\" by simp\n      from \\<open>j<last B\\<close> have \"j<B!(length B - 1)\" by (simp add: last_conv_nth)\n      from find_seg_bounds[OF \\<open>j<length S\\<close>] find_seg_correct[OF \\<open>j<length S\\<close>]\n      have \"v\\<in>seg (find_seg j)\" \"find_seg j < length B\" by auto\n      moreover with \\<open>j<B!(length B - 1)\\<close> have \"find_seg j < length B - 1\"\n        (* What follows is an unreadable, auto-generated structured proof\n          that replaces the following smt-call:\n        by (smt GS.seg_start_def `seg_start (find_seg j) \\<le> j`)*)\n      proof -\n        have f1: \"\\<And>x\\<^sub>1 x. \\<not> (x\\<^sub>1::nat) < x\\<^sub>1 - x\"\n          using less_imp_diff_less by blast\n        have \"j \\<le> last B\"\n          by (metis \\<open>j < last B\\<close> less_le)\n        hence f2: \"\\<And>x\\<^sub>1. \\<not> last B < x\\<^sub>1 \\<or> \\<not> x\\<^sub>1 \\<le> j\"\n          using f1 by (metis diff_diff_cancel le_trans)\n        have \"\\<And>x\\<^sub>1. seg_end x\\<^sub>1 \\<le> j \\<or> \\<not> x\\<^sub>1 < find_seg j\"\n          by (metis \\<open>seg_start (find_seg j) \\<le> j\\<close> calculation(2) \n            le_trans seg_end_less_start)\n        thus \"find_seg j < length B - 1\"\n          using f1 f2 \n          by (metis GS.seg_start_def \\<open>B \\<noteq> []\\<close> \\<open>j < B ! (length B - 1)\\<close>\n            \\<open>seg_start (find_seg j) \\<le> j\\<close> calculation(2) diff_diff_cancel \n            last_conv_nth nat_neq_iff seg_start_less_end)\n      qed\n      ultimately show \"v\\<in>?R\" \n        by (auto simp: p_\\<alpha>_def map_butlast[symmetric] butlast_upt)\n    }\n\n    {\n      fix v\n      assume \"v\\<in>?R\"\n      then obtain i where \"i<length B - 1\" and \"v\\<in>seg i\"\n        by (auto simp: p_\\<alpha>_def map_butlast[symmetric] butlast_upt)\n      then obtain j where \"j < seg_end i\" and \"v=S!j\"\n        by (auto simp: seg_def)\n      hence \"j<B!(i+1)\" and \"i+1 \\<le> length B - 1\" using \\<open>i<length B - 1\\<close>\n        by (auto simp: seg_end_def last_conv_nth split: if_split_asm)\n      with sorted_nth_mono[OF B_sorted \\<open>i+1 \\<le> length B - 1\\<close>] have \"j<last B\"\n        by (auto simp: last_conv_nth)\n      moreover from \\<open>j < seg_end i\\<close> have \"j<length S\"\n        by (metis GS.seg_end_def add_diff_inverse_nat \\<open>i + 1 \\<le> length B - 1\\<close>\n          add_lessD1 less_imp_diff_less less_le_not_le nat_neq_iff \n          seg_end_bound)\n        (*by (smt `i < length B - 1` seg_end_bound)*)\n      with I_consistent \\<open>v=S!j\\<close> have \"I v = Some (STACK j)\" by auto\n      ultimately show \"v\\<in>?L\"\n        by (auto simp: on_stack_less_def)\n    }\n  qed\n\n  lemma (in GS_invar) set_last_p_refine:\n    assumes PRE: \"p_\\<alpha>\\<noteq>[]\"\n    shows \"Collect (on_stack_ge I (last B)) = last p_\\<alpha>\" (is \"?L=?R\")\n  proof (intro equalityI subsetI)\n    from PRE have [simp]: \"B\\<noteq>[]\" by (auto simp: p_\\<alpha>_def)\n\n    have [simp]: \"S\\<noteq>[]\" by (simp add: empty_eq)\n\n    {\n      fix v\n      assume \"v\\<in>?L\"\n      then obtain j where [simp]: \"I v = Some (STACK j)\" and \"j\\<ge>last B\"\n        by (auto simp: on_stack_ge_def split: option.splits node_state.splits)\n\n      from I_consistent[of v j] have [simp]: \"j<length S\" \"v=S!j\" by auto\n      hence \"v\\<in>seg (length B - 1)\" using \\<open>j\\<ge>last B\\<close>\n        by (auto simp: seg_def last_conv_nth seg_start_def seg_end_def)\n      thus \"v\\<in>last p_\\<alpha>\" by (auto simp: p_\\<alpha>_def last_map)\n    }\n\n    {\n      fix v\n      assume \"v\\<in>?R\"\n      hence \"v\\<in>seg (length B - 1)\"\n        by (auto simp: p_\\<alpha>_def last_map)\n      then obtain j where \"v=S!j\" \"j\\<ge>last B\" \"j<length S\"\n        by (auto simp: seg_def last_conv_nth seg_start_def seg_end_def)\n      with I_consistent have \"I v = Some (STACK j)\" by simp\n      with \\<open>j\\<ge>last B\\<close> show \"v\\<in>?L\" by (auto simp: on_stack_ge_def)\n    }\n  qed\n\n  definition ce_impl :: \"'Q gGS \\<Rightarrow> (('Q set \\<times> 'Q set) option \\<times> 'Q gGS) nres\"\n    where \"ce_impl s \\<equiv> \n    do {\n      let (a,S,B,I,P) = s;\n      ASSERT (B\\<noteq>[]);\n      let bls = Collect (on_stack_less I (last B));\n      let ls = Collect (on_stack_ge I (last B));\n      RETURN (Some (bls, ls),a,S,B,I,P)\n    }\"\n\n  lemma ce_impl_refine:\n    assumes A: \"(s,(a,p,D,pE))\\<in>gGS_rel\"\n    assumes PRE: \"p\\<noteq>[]\"\n    shows \"ce_impl s \\<le> \\<Down>(Id\\<times>\\<^sub>rgGS_rel) \n      (RETURN (Some (\\<Union>(set (butlast p)),last p),a,p,D,pE))\"\n  proof -\n    from A obtain S' B' I' P' where [simp]: \"s=(a,S',B',I',P')\" \n      and OSR: \"((S',B',I',P'),(p,D,pE))\\<in>GS_rel\" and L: \"length a = length B'\"\n      by (rule gGS_relE)\n\n    from OSR have [simp]: \"GS.p_\\<alpha> (S',B',I',P') = p\"\n      by (simp add: GS_rel_def br_def GS.\\<alpha>_def)\n\n    from PRE have NE': \"GS.p_\\<alpha> (S', B', I', P') \\<noteq> []\" by simp\n    hence BNE[simp]: \"B'\\<noteq>[]\" by (simp add: GS.p_\\<alpha>_def)\n\n    from OSR have GS_invar: \"GS_invar (S',B',I',P')\" \n      by (simp add: GS_rel_def br_def)\n\n    show ?thesis\n      using GS_invar.set_butlast_p_refine[OF GS_invar NE']\n      using GS_invar.set_last_p_refine[OF GS_invar NE']\n      unfolding ce_impl_def\n      using A\n      by auto\n  qed\n\n  definition \"last_is_acc_impl s \\<equiv> \n    do {\n      let (a,_)=s;\n      ASSERT (a\\<noteq>[]);\n      RETURN (\\<forall>i<num_acc. i\\<in>last a)\n    }\"\n\n  lemma last_is_acc_impl_refine:\n    assumes A: \"(s,(a,p,D,pE))\\<in>gGS_rel\"\n    assumes PRE: \"a\\<noteq>[]\"\n    shows \"last_is_acc_impl s \\<le> RETURN (last a = {0..<num_acc})\"\n  proof -\n    from A PRE have \"last a \\<subseteq> {0..<num_acc}\"\n      unfolding gGS_rel_def gGS_invar_def br_def gGS_\\<alpha>_def by auto\n    hence C: \"(\\<forall>i<num_acc. i\\<in>last a) \\<longleftrightarrow> (last a = {0..<num_acc})\"\n      by auto\n\n    from A obtain gs where [simp]: \"s=(a,gs)\"\n      by (auto simp: gGS_rel_def gGS_\\<alpha>_def br_def split: prod.splits)\n\n    show ?thesis\n      unfolding last_is_acc_impl_def \n      by (auto simp: gGS_rel_def br_def gGS_\\<alpha>_def C PRE split: prod.splits)\n  qed\n\n  definition go_is_no_brk_impl :: \"'Q goGS \\<Rightarrow> bool\" \n    where \"go_is_no_brk_impl s \\<equiv> fst s = None\"\n  lemma go_is_no_brk_refine: \n    \"(s,s')\\<in>goGS_rel \\<Longrightarrow> go_is_no_brk_impl s \\<longleftrightarrow> go_is_no_brk s'\"\n    unfolding go_is_no_brk_def go_is_no_brk_impl_def\n    by (auto simp: goGS_rel_def br_def goGS_\\<alpha>_def split: prod.splits)\n\n  definition goD_impl :: \"'Q goGS \\<Rightarrow> 'Q oGS\" where \"goD_impl s \\<equiv> snd s\"\n  lemma goD_refine: \n    \"go_is_no_brk s' \\<Longrightarrow> (s,s')\\<in>goGS_rel \\<Longrightarrow> (goD_impl s, goD s')\\<in>oGS_rel\"\n    unfolding goD_impl_def goD_def\n    by (auto \n      simp: goGS_rel_def br_def goGS_\\<alpha>_def goGS_invar_def oGS_rel_def \n            go_is_no_brk_def) \n\n  definition go_is_done_impl :: \"'Q \\<Rightarrow> 'Q goGS \\<Rightarrow> bool\" \n    where \"go_is_done_impl v s \\<equiv> is_done_oimpl v (snd s)\"\n  thm is_done_orefine\n  lemma go_is_done_impl_refine: \"\\<lbrakk>go_is_no_brk s'; (s,s')\\<in>goGS_rel; (v,v')\\<in>Id\\<rbrakk> \n    \\<Longrightarrow> go_is_done_impl v s \\<longleftrightarrow> (v'\\<in>goD s')\"\n    using is_done_orefine\n    unfolding go_is_done_impl_def goD_def go_is_no_brk_def\n    apply (fastforce simp: goGS_rel_def br_def goGS_invar_def goGS_\\<alpha>_def)\n    done\n\n\n  definition goBrk_impl :: \"'Q goGS \\<Rightarrow> 'Q ce\" where \"goBrk_impl \\<equiv> fst\"\n\n  \n\n  definition find_ce_impl :: \"('Q set \\<times> 'Q set) option nres\" where\n    \"find_ce_impl \\<equiv> do {\n      stat_start_nres;\n      let os=goinitial_impl;\n      os\\<leftarrow>FOREACHci (\\<lambda>it os. fgl_outer_invar it (goGS_\\<alpha> os)) V0 \n        (go_is_no_brk_impl) (\\<lambda>v0 s0. \n      do {\n        if \\<not>go_is_done_impl v0 s0 then do {\n\n          let s = (None,ginitial_impl v0 s0);\n\n          (brk,s)\\<leftarrow>WHILEIT \n            (\\<lambda>(brk,s). fgl_invar v0 (oGS_\\<alpha> (goD_impl s0)) (brk,snd (gGS_\\<alpha> s)))\n            (\\<lambda>(brk,s). brk=None \\<and> \\<not>gpath_is_empty_impl s) (\\<lambda>(l,s).\n          do {\n            \\<comment> \\<open>Select edge from end of path\\<close>\n            (vo,s) \\<leftarrow> gselect_edge_impl s;\n\n            case vo of \n              Some v \\<Rightarrow> do {\n                if gis_on_stack_impl v s then do {\n                  s\\<leftarrow>gcollapse_impl v s;\n                  b\\<leftarrow>last_is_acc_impl s;\n                  if b then\n                    ce_impl s\n                  else \n                    RETURN (None,s)\n                } else if \\<not>gis_done_impl v s then do {\n                  \\<comment> \\<open>Edge to new node. Append to path\\<close>\n                  RETURN (None,gpush_impl v s)\n                } else do {\n                  \\<comment> \\<open>Edge to done node. Skip\\<close>\n                  RETURN (None,s)\n                }\n              }\n            | None \\<Rightarrow> do {\n                \\<comment> \\<open>No more outgoing edges from current node on path\\<close>\n                s\\<leftarrow>gpop_impl s;\n                RETURN (None,s)\n              }\n          }) (s);\n          RETURN (gto_outer_impl brk s)\n        } else RETURN s0\n      }) os;\n      stat_stop_nres;\n      RETURN (goBrk_impl os)\n    }\"\n\n  lemma find_ce_impl_refine: \"find_ce_impl \\<le> \\<Down>Id gfind_ce\"\n  proof -\n    note [refine2] = prod_relI[OF IdI[of None] ginitial_impl_refine]\n\n    have [refine]: \"\\<And>s a p D pE. \\<lbrakk>\n      (s,(a,p,D,pE))\\<in>gGS_rel;\n      p \\<noteq> []; pE \\<inter> last p \\<times> UNIV = {}\n      \\<rbrakk> \\<Longrightarrow>\n      gpop_impl s \\<bind> (\\<lambda>s. RETURN (None, s))\n        \\<le> SPEC (\\<lambda>c. (c, None, gpop (a,p,D,pE)) \\<in> Id \\<times>\\<^sub>r gGS_rel)\"\n      apply (drule (2) gpop_impl_refine)\n      apply (fastforce simp add: pw_le_iff refine_pw_simps)\n      done\n\n    note [[goals_limit = 1]]\n\n    note FOREACHci_refine_rcg'[refine del]\n\n    show ?thesis\n      unfolding find_ce_impl_def gfind_ce_def\n      apply (refine_rcg\n        bind_refine'\n        prod_relI IdI\n        inj_on_id\n\n        gselect_edge_impl_refine gpush_impl_refine \n        oinitial_refine ginitial_impl_refine \n        bind_Let_refine2[OF gcollapse_impl_refine]\n        if_bind_cond_refine[OF last_is_acc_impl_refine]\n        ce_impl_refine\n        goinitial_impl_refine\n        gto_outer_refine\n        goBrk_refine\n        FOREACHci_refine_rcg'[where R=goGS_rel, OF inj_on_id]\n      )\n\n      apply refine_dref_type\n    \n      apply (simp_all add: go_is_no_brk_refine go_is_done_impl_refine)\n      apply (auto simp: goGS_rel_def br_def) []\n      apply (auto simp: goGS_rel_def br_def goGS_\\<alpha>_def gGS_\\<alpha>_def gGS_rel_def \n                        goD_def goD_impl_def) []\n\n      apply (auto dest: gpath_is_empty_refine ) []\n      apply (auto dest: gis_on_stack_refine) []\n      apply (auto dest: gis_done_refine) []\n      done\n  qed\n\nend\n\nsection \\<open>Constructing a Lasso from Counterexample\\<close>\n\nsubsection \\<open>Lassos in GBAs\\<close>\n\ncontext igb_fr_graph begin\n\n  definition reconstruct_reach :: \"'Q set \\<Rightarrow> 'Q set \\<Rightarrow> ('Q list \\<times> 'Q) nres\"\n    \\<comment> \\<open>Reconstruct the reaching path of a lasso\\<close>\n    where \"reconstruct_reach Vr Vl \\<equiv> do {\n      res \\<leftarrow> find_path (E\\<inter>Vr\\<times>UNIV) V0 (\\<lambda>v. v\\<in>Vl);\n      ASSERT (res \\<noteq> None);\n      RETURN (the res)\n    }\"\n\n  lemma reconstruct_reach_correct:\n    assumes CEC: \"ce_correct Vr Vl\"\n    shows \"reconstruct_reach Vr Vl \n      \\<le> SPEC (\\<lambda>(pr,va). \\<exists>v0\\<in>V0. path E v0 pr va \\<and> va\\<in>Vl)\"\n  proof -\n    have FIN_aux: \"finite ((E \\<inter> Vr \\<times> UNIV)\\<^sup>* `` V0)\"\n      by (metis finite_reachableE_V0 finite_subset inf_sup_ord(1) inf_sup_ord(2)\n        inf_top.left_neutral reachable_mono)\n    \n    {\n      fix u p v\n      assume P: \"path E u p v\" and SS: \"set p \\<subseteq> Vr\"\n      have \"path (E \\<inter> Vr\\<times>UNIV) u p v\"\n        apply (rule path_mono[OF _ path_restrict[OF P]])\n        using SS by auto\n    } note P_CONV=this\n\n    from CEC obtain v0 \"pr\" va where \"v0\\<in>V0\" \"set pr \\<subseteq> Vr\" \"va\\<in>Vl\" \n      \"path (E \\<inter> Vr\\<times>UNIV) v0 pr va\"\n      unfolding ce_correct_def is_lasso_prpl_def is_lasso_prpl_pre_def\n      by (force simp: neq_Nil_conv path_simps dest: P_CONV)\n    hence 1: \"va \\<in> (E \\<inter> Vr \\<times> UNIV)\\<^sup>* `` V0\" \n      by (auto dest: path_is_rtrancl)\n      \n    show ?thesis\n      using assms unfolding reconstruct_reach_def\n      apply (refine_rcg refine_vcg order_trans[OF find_path_ex_rule])\n      apply (clarsimp_all simp: FIN_aux finite_V0)\n\n      using \\<open>va\\<in>Vl\\<close> 1 apply auto []\n\n      apply (auto dest: path_mono[of \"E \\<inter> Vr \\<times> UNIV\" E, simplified]) []\n      done\n  qed\n\n  definition \"rec_loop_invar Vl va s \\<equiv> let (v,p,cS) = s in \n    va \\<in> E\\<^sup>*``V0 \\<and>\n    path E va p v \\<and>\n    cS = acc v \\<union> (\\<Union>(acc`set p)) \\<and>\n    va \\<in> Vl \\<and> v \\<in> Vl \\<and> set p \\<subseteq> Vl\"\n\n  definition reconstruct_lasso :: \"'Q set \\<Rightarrow> 'Q set \\<Rightarrow> ('Q list \\<times> 'Q list) nres\"\n    \\<comment> \\<open>Reconstruct lasso\\<close>\n    where \"reconstruct_lasso Vr Vl \\<equiv> do {\n    (pr,va) \\<leftarrow> reconstruct_reach Vr Vl;\n    \n    let cS_full = {0..<num_acc};\n    let E = E \\<inter> UNIV\\<times>Vl;\n    \n    (vd,p,_) \\<leftarrow> WHILEIT (rec_loop_invar Vl va) \n      (\\<lambda>(_,_,cS). cS \\<noteq> cS_full) \n      (\\<lambda>(v,p,cS). do {\n        ASSERT (\\<exists>v'. (v,v')\\<in>E\\<^sup>* \\<and> \\<not> (acc v' \\<subseteq> cS));\n        sr \\<leftarrow> find_path E {v} (\\<lambda>v. \\<not> (acc v \\<subseteq> cS));\n        ASSERT (sr \\<noteq> None);\n        let (p_seg,v) = the sr;\n        RETURN (v,p@p_seg,cS \\<union> acc v)\n      }) (va,[],acc va);\n\n    p_close_r \\<leftarrow> (if p=[] then \n        find_path1 E vd ((=) va)\n      else\n        find_path E {vd} ((=) va));\n\n    ASSERT (p_close_r \\<noteq> None);\n    let (p_close,_) = the p_close_r;\n\n    RETURN (pr, p@p_close)\n  }\"\n\n\nlemma (in igb_fr_graph) reconstruct_lasso_correct:\n  assumes CEC: \"ce_correct Vr Vl\"\n  shows \"reconstruct_lasso Vr Vl \\<le> SPEC (is_lasso_prpl)\"\nproof -\n\n  let ?E = \"E \\<inter> UNIV \\<times> Vl\"\n\n  have E_SS: \"E \\<inter> Vl \\<times> Vl \\<subseteq> ?E\" by auto\n\n  from CEC have\n    REACH: \"Vl \\<subseteq> E\\<^sup>*``V0\"\n    and CONN: \"Vl\\<times>Vl \\<subseteq> (E \\<inter> Vl\\<times>Vl)\\<^sup>*\"\n    and NONTRIV: \"Vl\\<times>Vl \\<inter> E \\<noteq> {}\"\n    and NES[simp]: \"Vl\\<noteq>{}\"\n    and ALL: \"\\<Union>(acc`Vl) = {0..<num_acc}\"\n    unfolding ce_correct_def is_lasso_prpl_def\n    apply clarsimp_all\n    apply auto []\n    apply force\n    done\n\n  define term_rel\n    where \"term_rel = (inv_image (finite_psupset {0..<num_acc}) (\\<lambda>(_::'Q,_::'Q list,cS). cS))\"\n  hence WF: \"wf term_rel\" by simp\n\n  { fix va\n    assume \"va \\<in> Vl\"\n    hence \"rec_loop_invar Vl va (va, [], acc va)\"\n      unfolding rec_loop_invar_def using REACH by auto\n  } note INVAR_INITIAL = this\n\n  {\n    fix v p cS va\n    assume \"rec_loop_invar Vl va (v, p, cS)\"\n    hence \"finite ((?E)\\<^sup>* `` {v})\"\n      apply -\n      apply (rule finite_subset[where B=\"E\\<^sup>*``V0\"])\n      unfolding rec_loop_invar_def\n      using REACH\n      apply (clarsimp_all dest!: path_is_rtrancl)\n      apply (drule rtrancl_mono_mp[where U=\"?E\" and V=E, rotated], (auto) [])\n      by (metis rev_ImageI rtrancl_trans)\n  } note FIN1 = this\n\n  {\n    fix va v :: 'Q and p cS\n    assume INV: \"rec_loop_invar Vl va (v,p,cS)\"\n      and NC: \"cS \\<noteq> {0..<num_acc}\"\n\n    from NC INV obtain i where \"i<num_acc\" \"i\\<notin>cS\" \n      unfolding rec_loop_invar_def by auto blast\n\n    with ALL obtain v' where \"v'\\<in>Vl\" \"\\<not> acc v' \\<subseteq> cS\"\n      by simp (smt UN_iff atLeastLessThan_iff le0 subsetCE)\n     \n    moreover with CONN INV have \"(v,v')\\<in>(E \\<inter> Vl \\<times> Vl)\\<^sup>*\"\n      unfolding rec_loop_invar_def by auto\n    hence \"(v,v')\\<in>?E\\<^sup>*\" using rtrancl_mono_mp[OF E_SS] by blast\n    ultimately have \"\\<exists>v'. (v,v')\\<in>(?E)\\<^sup>* \\<and> \\<not> acc v' \\<subseteq> cS\" by auto\n  } note ASSERT1 = this\n\n  {\n    fix va v p cS v' p'\n    assume \"rec_loop_invar Vl va (v, p, cS)\"\n    and \"path (?E) v p' v'\"\n    and \"\\<not> (acc v' \\<subseteq> cS)\"\n    and \"\\<forall>v\\<in>set p'. acc v \\<subseteq> cS\"\n    hence \"rec_loop_invar Vl va (v', p@p', cS \\<union> acc v')\"\n      unfolding rec_loop_invar_def\n      apply simp\n      apply (intro conjI)\n      apply (auto simp: path_simps dest: path_mono[of \"?E\" E, simplified]) []\n\n      apply (cases p')\n      apply (auto simp: path_simps) [2]\n\n      apply (cases p' rule: rev_cases)\n      apply (auto simp: path_simps) [2]\n\n      apply (erule path_set_induct)\n      apply auto [2]\n      done\n  } note INV_PRES = this\n\n  {\n    fix va v p cS v' p'\n    assume \"rec_loop_invar Vl va (v, p, cS)\"\n      and \"path ?E v p' v'\"\n      and \"\\<not> (acc v' \\<subseteq> cS)\"\n      and \"\\<forall>v\\<in>set p'. acc v \\<subseteq> cS\"\n    hence \"((v', p@p', cS \\<union> acc v'), (v,p,cS)) \\<in> term_rel\"\n      unfolding term_rel_def rec_loop_invar_def\n      by (auto simp: finite_psupset_def)\n  } note VAR = this\n\n  have CONN1: \"Vl \\<times> Vl \\<subseteq> (?E)\\<^sup>+\"\n  proof clarify\n    fix a b\n    assume \"a\\<in>Vl\" \"b\\<in>Vl\"\n    from NONTRIV obtain u v where E: \"(u,v)\\<in>(E \\<inter> Vl\\<times>Vl)\" by auto\n    from CONN \\<open>a\\<in>Vl\\<close> E have \"(a,u)\\<in>(E\\<inter>Vl\\<times>Vl)\\<^sup>*\" by auto\n    also note E\n    also (rtrancl_into_trancl1) from CONN \\<open>b\\<in>Vl\\<close> E have \"(v,b)\\<in>(E\\<inter>Vl\\<times>Vl)\\<^sup>*\"\n      by auto\n    finally show \"(a,b)\\<in>(?E)\\<^sup>+\" using trancl_mono[OF _ E_SS] by auto\n  qed\n    \n  {\n    fix va v p cS\n    assume \"rec_loop_invar Vl va (v, p, cS)\"\n    hence \"(v,va) \\<in> (?E)\\<^sup>+\"\n      unfolding rec_loop_invar_def\n      using CONN1\n      by auto\n  } note CLOSE1 = this\n\n  {\n    fix va v p cS\n    assume \"rec_loop_invar Vl va (v, p, cS)\"\n    hence \"(v,va) \\<in> (?E)\\<^sup>*\"\n      unfolding rec_loop_invar_def\n      using CONN rtrancl_mono[OF E_SS]\n      by auto\n  } note CLOSE2 = this\n\n  {\n    fix \"pr\" vd pl va v0\n    assume \"rec_loop_invar Vl va (vd, [], {0..<num_acc})\" \"va \\<in> Vl\" \"v0 \\<in> V0\"\n      \"path E v0 pr va\" \"pl \\<noteq> []\" \"path ?E vd pl va\"\n    hence \"is_lasso_prpl (pr, pl)\"\n      unfolding is_lasso_prpl_def is_lasso_prpl_pre_def rec_loop_invar_def\n      by (auto simp: neq_Nil_conv path_simps\n        dest!: path_mono[of \"?E\" E, simplified]) []\n  } note INV_POST1 = this\n\n  {\n    fix va v p p' \"pr\" v0\n    assume INV: \"rec_loop_invar Vl va (v,p,{0..<num_acc})\" \n      and 1: \"p\\<noteq>[]\" \"path ?E v p' va\"\n      and PR: \"v0\\<in>V0\" \"path E v0 pr va\"\n\n    from INV have \"\\<forall>i<num_acc. \\<exists>q\\<in>insert v (set p). i \\<in> acc q\"\n      unfolding rec_loop_invar_def\n      by auto\n    moreover from INV 1 have \"insert v (set p) \\<subseteq> set p \\<union> set p'\"\n      unfolding rec_loop_invar_def\n      apply (cases p, simp)\n      apply (cases p')\n      apply (auto simp: path_simps)\n      done\n    ultimately have ACC: \"\\<forall>i<num_acc. \\<exists>q\\<in>set p \\<union> set p'. i \\<in> acc q\" by blast\n    \n    from INV 1 have PL: \"path E va (p @ p') va\"\n      by (auto simp: rec_loop_invar_def path_simps \n        dest!: path_mono[of \"?E\" E, simplified]) []\n\n    have \"is_lasso_prpl (pr,p@p')\"\n      unfolding is_lasso_prpl_def is_lasso_prpl_pre_def\n      apply (clarsimp simp: ACC)\n      using PR PL \\<open>p\\<noteq>[]\\<close> by auto\n  } note INV_POST2 = this\n\n  show ?thesis\n    unfolding reconstruct_lasso_def\n    apply (refine_rcg \n      WF\n      order_trans[OF reconstruct_reach_correct]\n      order_trans[OF find_path_ex_rule]\n      order_trans[OF find_path1_ex_rule]\n      refine_vcg \n    )\n\n    apply (vc_solve \n      del: subsetI\n      solve: ASSERT1 INV_PRES asm_rl VAR CLOSE1 CLOSE2 INV_POST1 INV_POST2\n      simp: INVAR_INITIAL FIN1 CEC)\n    done\nqed\n\ndefinition find_lasso where \"find_lasso \\<equiv> do {\n  ce \\<leftarrow> find_ce_spec;\n  case ce of \n    None \\<Rightarrow> RETURN None\n  | Some (Vr,Vl) \\<Rightarrow> do {\n      l \\<leftarrow> reconstruct_lasso Vr Vl;\n      RETURN (Some l)\n    }\n}\"\n\nlemma (in igb_fr_graph) find_lasso_correct: \"find_lasso \\<le> find_lasso_spec\"\n  unfolding find_lasso_spec_def find_lasso_def find_ce_spec_def\n  apply (refine_rcg refine_vcg order_trans[OF reconstruct_lasso_correct])\n  apply auto\n  done\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Gabow_SCC/Gabow_GBG.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5660185205547238, "lm_q2_score": 0.5117166047041652, "lm_q1q2_score": 0.28964107553793805}}
{"text": "section {*L\\_ATS\\_Branching\\_Versus\\_Linear1*}\ntheory\n  L_ATS_Branching_Versus_Linear1\n\nimports\n  L_ATS_Linear\n  L_ATS_Branching\n\nbegin\n\nlemma tl_nth_shift: \"\n  length w>i\n  \\<Longrightarrow> tl w ! i = w!(Suc i)\"\n  apply(case_tac w)\n   apply(clarsimp)\n  apply(rename_tac a list)(*strict*)\n  apply(force)\n  done\n\nlemma bexI_conj: \"\n  P \\<and> Q a \\<and> a \\<in> A\n  \\<Longrightarrow> P \\<and> (\\<exists>x\\<in> A. Q x)\"\n  apply(force)\n  done\n\nlocale ATS_Branching_Versus_Linear1 =\n  GLIN : ATS_Linear\n  \"TSstructure :: 'TSstructure \\<Rightarrow> bool\"\n  \"lin_configurations :: 'TSstructure \\<Rightarrow> 'lin_conf set\"\n  \"lin_initial_configurations :: 'TSstructure \\<Rightarrow> 'lin_conf set\"\n  \"step_labels :: 'TSstructure \\<Rightarrow> 'label set\"\n  \"lin_step_relation :: 'TSstructure \\<Rightarrow> 'lin_conf \\<Rightarrow> 'label \\<Rightarrow> 'lin_conf \\<Rightarrow> bool\"\n  \"effects :: 'TSstructure \\<Rightarrow> 'event list set\"\n  \"lin_marking_condition :: 'TSstructure \\<Rightarrow> ('label, 'lin_conf) derivation \\<Rightarrow> bool\"\n  \"lin_marked_effect :: 'TSstructure \\<Rightarrow> ('label, 'lin_conf) derivation \\<Rightarrow> 'event list set\"\n  \"lin_unmarked_effect :: 'TSstructure \\<Rightarrow> ('label, 'lin_conf) derivation \\<Rightarrow> 'event list set\"\n  \"lin_fixed_schedulers :: 'TSstructure \\<Rightarrow> 'lin_fixed_scheduler set\"\n  \"lin_empty_fixed_scheduler :: 'TSstructure \\<Rightarrow> 'lin_fixed_scheduler\"\n  \"lin_fixed_scheduler_extendable :: 'TSstructure \\<Rightarrow> 'lin_fixed_scheduler \\<Rightarrow> bool\"\n  \"lin_scheduler_fragments :: 'TSstructure \\<Rightarrow> 'lin_scheduler_fragment set\"\n  \"lin_empty_scheduler_fragment :: 'TSstructure \\<Rightarrow> 'lin_scheduler_fragment\"\n  \"lin_join_scheduler_fragments :: 'lin_scheduler_fragment \\<Rightarrow> 'lin_scheduler_fragment \\<Rightarrow> 'lin_scheduler_fragment\"\n  \"lin_unfixed_schedulers :: 'TSstructure \\<Rightarrow> 'lin_unfixed_scheduler set\"\n  \"lin_empty_unfixed_scheduler :: 'TSstructure \\<Rightarrow> 'lin_unfixed_scheduler\"\n  \"lin_unfixed_scheduler_right_quotient :: 'lin_unfixed_scheduler \\<Rightarrow> 'lin_unfixed_scheduler \\<Rightarrow> 'lin_scheduler_fragment option\"\n  \"lin_extend_unfixed_scheduler :: 'lin_scheduler_fragment \\<Rightarrow> 'lin_unfixed_scheduler \\<Rightarrow> 'lin_unfixed_scheduler\"\n  \"lin_unfixed_scheduler_extendable :: 'TSstructure \\<Rightarrow> 'lin_unfixed_scheduler \\<Rightarrow> bool\"\n  \"lin_schedulers :: 'TSstructure \\<Rightarrow> 'lin_scheduler set\"\n  \"lin_initial_schedulers :: 'TSstructure \\<Rightarrow> 'lin_scheduler set\"\n  \"lin_empty_scheduler :: 'TSstructure \\<Rightarrow> 'lin_scheduler\"\n  \"lin_get_scheduler :: 'lin_conf \\<Rightarrow> 'lin_scheduler\"\n  \"lin_join_fixed_scheduler_unfixed_scheduler :: 'lin_fixed_scheduler \\<Rightarrow> 'lin_unfixed_scheduler \\<Rightarrow> 'lin_scheduler\"\n  \"lin_extend_scheduler :: 'lin_scheduler_fragment \\<Rightarrow> 'lin_scheduler \\<Rightarrow> 'lin_scheduler\"\n  \"lin_get_unfixed_scheduler :: 'lin_conf \\<Rightarrow> 'lin_unfixed_scheduler\"\n  \"lin_set_unfixed_scheduler :: 'lin_conf \\<Rightarrow> 'lin_unfixed_scheduler \\<Rightarrow> 'lin_conf\"\n  \"lin_get_fixed_scheduler :: 'lin_conf \\<Rightarrow> 'lin_fixed_scheduler\"\n  \"histories :: 'TSstructure \\<Rightarrow> 'history set\"\n  \"history_fragments :: 'TSstructure \\<Rightarrow> 'history_fragment set\"\n  \"empty_history :: 'TSstructure \\<Rightarrow> 'history\"\n  \"empty_history_fragment :: 'TSstructure \\<Rightarrow> 'history_fragment\"\n  \"lin_set_history :: 'lin_conf \\<Rightarrow> 'history \\<Rightarrow> 'lin_conf\"\n  \"extend_history :: 'history \\<Rightarrow> 'history_fragment \\<Rightarrow> 'history\"\n  \"join_history_fragments :: 'history_fragment \\<Rightarrow> 'history_fragment \\<Rightarrow> 'history_fragment\"\n  \"lin_get_history :: 'lin_conf \\<Rightarrow> 'history\"\n  + GBRA : ATS_Branching\n  \"TSstructure :: 'TSstructure \\<Rightarrow> bool\"\n  \"bra_configurations :: 'TSstructure \\<Rightarrow> 'bra_conf set\"\n  \"bra_initial_configurations :: 'TSstructure \\<Rightarrow> 'bra_conf set\"\n  \"step_labels :: 'TSstructure \\<Rightarrow> 'label set\"\n  \"bra_step_relation :: 'TSstructure \\<Rightarrow> 'bra_conf \\<Rightarrow> 'label \\<Rightarrow> 'bra_conf \\<Rightarrow> bool\"\n  \"effects :: 'TSstructure \\<Rightarrow> 'event list set\"\n  \"bra_marking_condition :: 'TSstructure \\<Rightarrow> ('label, 'bra_conf) derivation \\<Rightarrow> bool\"\n  \"bra_marked_effect :: 'TSstructure \\<Rightarrow> ('label, 'bra_conf) derivation \\<Rightarrow> 'event list set\"\n  \"bra_unmarked_effect :: 'TSstructure \\<Rightarrow> ('label, 'bra_conf) derivation \\<Rightarrow> 'event list set\"\n  \"bra_fixed_schedulers :: 'TSstructure \\<Rightarrow> 'bra_fixed_scheduler set\"\n  \"bra_empty_fixed_scheduler :: 'TSstructure \\<Rightarrow> 'bra_fixed_scheduler\"\n  \"bra_fixed_scheduler_extendable :: 'TSstructure \\<Rightarrow> 'bra_fixed_scheduler \\<Rightarrow> bool\"\n  \"bra_get_fixed_scheduler :: 'bra_conf \\<Rightarrow> 'bra_fixed_scheduler\"\n  \"histories :: 'TSstructure \\<Rightarrow> 'history set\"\n  \"history_fragments :: 'TSstructure \\<Rightarrow> 'history_fragment set\"\n  \"empty_history :: 'TSstructure \\<Rightarrow> 'history\"\n  \"empty_history_fragment :: 'TSstructure \\<Rightarrow> 'history_fragment\"\n  \"bra_set_history :: 'bra_conf \\<Rightarrow> 'history \\<Rightarrow> 'bra_conf\"\n  \"extend_history :: 'history \\<Rightarrow> 'history_fragment \\<Rightarrow> 'history\"\n  \"join_history_fragments :: 'history_fragment \\<Rightarrow> 'history_fragment \\<Rightarrow> 'history_fragment\"\n  \"bra_get_history :: 'bra_conf \\<Rightarrow> 'history\"\n  for\n    TSstructure lin_configurations lin_initial_configurations step_labels lin_step_relation effects lin_marking_condition lin_marked_effect lin_unmarked_effect lin_fixed_schedulers lin_empty_fixed_scheduler lin_fixed_scheduler_extendable lin_scheduler_fragments lin_empty_scheduler_fragment lin_join_scheduler_fragments lin_unfixed_schedulers lin_empty_unfixed_scheduler lin_unfixed_scheduler_right_quotient lin_extend_unfixed_scheduler lin_unfixed_scheduler_extendable lin_schedulers lin_initial_schedulers lin_empty_scheduler lin_get_scheduler lin_join_fixed_scheduler_unfixed_scheduler lin_extend_scheduler lin_get_unfixed_scheduler lin_set_unfixed_scheduler lin_get_fixed_scheduler histories history_fragments empty_history empty_history_fragment lin_set_history extend_history join_history_fragments lin_get_history bra_configurations bra_initial_configurations bra_step_relation bra_marking_condition bra_marked_effect bra_unmarked_effect bra_fixed_schedulers bra_empty_fixed_scheduler bra_fixed_scheduler_extendable bra_get_fixed_scheduler bra_set_history bra_get_history\n    +\n\nfixes Lin2BraConf :: \"'lin_conf \\<Rightarrow> 'bra_conf\"\n\nfixes Bra2LinConf :: \"'bra_conf \\<Rightarrow> 'lin_scheduler \\<Rightarrow> 'lin_conf\"\n\nfixes Bra2LinStep :: \"'bra_conf \\<Rightarrow> 'label \\<Rightarrow> 'bra_conf \\<Rightarrow> 'lin_scheduler_fragment\"\n\nfixes Bra2LinFin :: \"'TSstructure \\<Rightarrow> 'bra_fixed_scheduler \\<Rightarrow> 'lin_scheduler\"\n\nassumes AX_Lin2BraConf_preserves_steps: \"\n  TSstructure G\n  \\<Longrightarrow> c1l \\<in> lin_configurations G\n  \\<Longrightarrow> lin_step_relation G c1l e c2l\n  \\<Longrightarrow> bra_step_relation G (Lin2BraConf c1l) e (Lin2BraConf c2l)\"\n\nassumes AX_Lin2BraConf_preserves_initiality: \"\n  TSstructure G\n  \\<Longrightarrow> cl \\<in> lin_initial_configurations G\n  \\<Longrightarrow> Lin2BraConf cl \\<in> bra_initial_configurations G\"\n\nassumes AX_Lin2BraConf_preserves_configurations: \"\n  TSstructure G\n  \\<Longrightarrow> cl \\<in> lin_configurations G\n  \\<Longrightarrow> Lin2BraConf cl \\<in> bra_configurations G\"\n\nassumes AX_Bra2LinStep_closed: \"\n  TSstructure G\n  \\<Longrightarrow> c1B \\<in> bra_configurations G\n  \\<Longrightarrow> bra_step_relation G c1B e c2B\n  \\<Longrightarrow> Bra2LinStep c1B e c2B \\<in> lin_scheduler_fragments G\"\n\nassumes AX_Bra2LinFin_closed: \"\n  TSstructure G\n  \\<Longrightarrow> cB \\<in> bra_configurations G\n  \\<Longrightarrow> Bra2LinFin G (bra_get_fixed_scheduler cB) \\<in> lin_schedulers G\"\n\nassumes AX_Bra2LinConf_schedl_get: \"\n  TSstructure G\n  \\<Longrightarrow> cB \\<in> bra_configurations G\n  \\<Longrightarrow> s1L \\<in> lin_schedulers G\n  \\<Longrightarrow> lin_get_scheduler (Bra2LinConf cB s1L) = s2L\n  \\<Longrightarrow> s1L = s2L\"\n\nassumes AX_Bra2LinFin_creates_proper_extension: \"\n  TSstructure G\n  \\<Longrightarrow> cB \\<in> bra_configurations G\n  \\<Longrightarrow> Bra2LinConf cB (Bra2LinFin G (bra_get_fixed_scheduler cB)) \\<in> lin_configurations G\"\n\nassumes AX_Bra2LinStep_translates_backwards_Bra2LinConf_closed: \"\n  TSstructure G\n  \\<Longrightarrow> c1B \\<in> bra_configurations G\n  \\<Longrightarrow> bra_step_relation G c1B e c2B\n  \\<Longrightarrow> Bra2LinConf c2B sL \\<in> lin_configurations G\n  \\<Longrightarrow> Bra2LinConf c1B (lin_extend_scheduler (Bra2LinStep c1B e c2B) sL) \\<in> lin_configurations G\"\n\nassumes AX_lin_step_relation_from_Bra2LinStep: \"\n  TSstructure G\n  \\<Longrightarrow> c1B \\<in> bra_configurations G\n  \\<Longrightarrow> bra_step_relation G c1B e c2B\n  \\<Longrightarrow> Bra2LinConf c2B sL \\<in> lin_configurations G\n  \\<Longrightarrow> lin_step_relation G (Bra2LinConf c1B (lin_extend_scheduler (Bra2LinStep c1B e c2B) sL)) e (Bra2LinConf c2B sL)\"\n\nassumes AX_Bra2LinConf_only_modifies_lin_unfixed_scheduler: \"\n  TSstructure G\n  \\<Longrightarrow> Bra2LinConf (Lin2BraConf cL) sL \\<in> lin_configurations G\n  \\<Longrightarrow> lin_set_unfixed_scheduler cL (lin_get_unfixed_scheduler (Bra2LinConf (Lin2BraConf cL) sL)) = Bra2LinConf (Lin2BraConf cL) sL\"\n\nassumes AX_Bra2LinConf_inj: \"\n  TSstructure G\n  \\<Longrightarrow> cB \\<in> bra_configurations G\n  \\<Longrightarrow> Bra2LinConf cB s1L = Bra2LinConf cB s2L\n  \\<Longrightarrow> s1L = s2L\"\n\nassumes AX_equal_by_fixed_unfixed_and_nonscheduler_part: \"\n  TSstructure G\n  \\<Longrightarrow> cB \\<in> bra_configurations G\n  \\<Longrightarrow> cL \\<in> lin_configurations G\n  \\<Longrightarrow> lin_set_unfixed_scheduler (Bra2LinConf cB (Bra2LinFin G (bra_get_fixed_scheduler cB))) (lin_get_unfixed_scheduler cL) = cL\n  \\<Longrightarrow> cB = Lin2BraConf cL\"\n\nassumes AX_Bra2LinConf_preserves_initiality: \"\n  TSstructure G\n  \\<Longrightarrow> sL \\<in> lin_schedulers G\n  \\<Longrightarrow> cB \\<in> bra_initial_configurations G\n  \\<Longrightarrow> Bra2LinConf cB sL \\<in> lin_initial_configurations G\"\n\nassumes AX_Bra2LinConf_preserves_history: \"\n  TSstructure G\n  \\<Longrightarrow> cB \\<in> bra_configurations G\n  \\<Longrightarrow> sL \\<in> lin_schedulers G\n  \\<Longrightarrow> Bra2LinConf cB sL \\<in> lin_configurations G\n  \\<Longrightarrow> lin_get_history (Bra2LinConf cB sL) = bra_get_history cB\"\n\nassumes AX_Lin2BraConf_preserves_history: \"\n  TSstructure G\n  \\<Longrightarrow> cL \\<in> lin_configurations G\n  \\<Longrightarrow> lin_get_history cL = bra_get_history (Lin2BraConf cL)\"\n\ncontext ATS_Branching_Versus_Linear1 begin\n\ndefinition Lin2BraDer :: \"\n  ('label,'lin_conf) derivation\n  \\<Rightarrow> ('label,'bra_conf) derivation\"\n  where\n    \"Lin2BraDer d \\<equiv>\n  derivation_map d Lin2BraConf\"\n\ndefinition Bra2LinDer' :: \"\n  'TSstructure\n  \\<Rightarrow> ('label, 'bra_conf) derivation\n  \\<Rightarrow> nat\n  \\<Rightarrow> nat\n  \\<Rightarrow> 'lin_scheduler_fragment\"\n  where\n    \"Bra2LinDer' G d m n \\<equiv>\n  foldl\n    lin_join_scheduler_fragments\n    (lin_empty_scheduler_fragment G)\n    (map\n      (\\<lambda>n.\n        case d n of Some (pair e1 c1) \\<Rightarrow>\n        (case d (Suc n) of Some (pair (Some e2) c2) \\<Rightarrow>\n        Bra2LinStep c1 e2 c2))\n      (case m of 0 \\<Rightarrow> [] | Suc m' \\<Rightarrow> nat_seq n m'))\"\n\nlemma Bra2LinDer_prime_modificiation_for_presentation: \"\n  (case m of 0 \\<Rightarrow> [] | Suc m' \\<Rightarrow> nat_seq n m') = butlast(nat_seq n m)\"\n  apply(case_tac \"n<m\")\n   prefer 2\n   apply(case_tac \"n=m\")\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"nat_seq m m\"\n      and s=\"[m]\"\n      in ssubst)\n     apply (metis natUptTo_n_n)\n    apply(case_tac m)\n     apply(force)\n    apply(rename_tac nat)(*strict*)\n    apply(clarsimp)\n    apply (metis lessI nat_seqEmpty)\n   apply(case_tac m)\n    apply(clarsimp)\n    apply(case_tac n)\n     apply(force)\n    apply(rename_tac nat)(*strict*)\n    apply(clarsimp)\n    apply (metis butlast.simps(1) nat_seqEmpty zero_less_Suc)\n   apply(rename_tac nat)(*strict*)\n   apply(clarsimp)\n   apply(rule_tac\n      t=\"nat_seq n nat\"\n      and s=\"[]\"\n      in ssubst)\n    apply(rename_tac nat)(*strict*)\n    apply(rule nat_seqEmpty)\n    apply(force)\n   apply(rename_tac nat)(*strict*)\n   apply(rule_tac\n      t=\"nat_seq n (Suc nat)\"\n      and s=\"[]\"\n      in ssubst)\n    apply(rename_tac nat)(*strict*)\n    apply(rule nat_seqEmpty)\n    apply(force)\n   apply(rename_tac nat)(*strict*)\n   apply(force)\n  apply(case_tac m)\n   apply(force)\n  apply(rename_tac nat)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n      t=\"nat_seq n (Suc nat)\"\n      and s=\"nat_seq n nat@[(Suc nat)]\"\n      in ssubst)\n   apply(rename_tac nat)(*strict*)\n   apply(case_tac n)\n    apply(rename_tac nat)(*strict*)\n    apply(clarsimp)\n    apply (metis (no_types, hide_lams) One_nat_def add_Suc_right append.simps(1) append.simps(2) diff_Suc_Suc less_delta_exists minus_nat.diff_0 nat_seq_drop_first nat_seq_last zero_less_Suc)\n   apply(rename_tac nat nata)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac nat nata)(*strict*)\n    prefer 2\n    apply(rule_tac\n      m=\"nata\"\n      and n=\"(Suc nat)\"\n      in nat_seq_last)\n    apply(force)\n   apply(rename_tac nat nata)(*strict*)\n   apply(force)\n  apply(rename_tac nat)(*strict*)\n  apply(force)\n  done\n\ndefinition Bra2LinDer :: \"\n  'TSstructure\n  \\<Rightarrow> ('label, 'bra_conf) derivation\n  \\<Rightarrow> nat\n  \\<Rightarrow> ('label, 'lin_conf) derivation\"\n  where\n    \"Bra2LinDer G d m \\<equiv>\n  (\\<lambda>n.\n    if n > m\n    then None\n    else\n      case d m of\n        None \\<Rightarrow> None\n        | Some (pair em cm) \\<Rightarrow>\n          (case d n of\n            None \\<Rightarrow> None\n            | Some (pair en cn) \\<Rightarrow>\n              Some (pair en (Bra2LinConf cn (lin_extend_scheduler (Bra2LinDer' G d m n) (Bra2LinFin G (bra_get_fixed_scheduler cm)))))))\"\n\nlemma Lin2BraConf_preserves_steps_lift: \"\n  TSstructure G\n  \\<Longrightarrow> GLIN.derivation G d\n  \\<Longrightarrow> GLIN.belongs G d\n  \\<Longrightarrow> GBRA.derivation G (Lin2BraDer d)\"\n  apply(simp add: GBRA.derivation_def)\n  apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(case_tac i)\n   apply(rename_tac i)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"\\<exists>c. d 0 = Some (pair None c)\")\n    prefer 2\n    apply(rule GLIN.some_position_has_details_at_0)\n    apply(force)\n   apply(clarsimp)\n   apply(rename_tac c)(*strict*)\n   apply(simp add: Lin2BraDer_def derivation_map_def)\n  apply(rename_tac i nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat)(*strict*)\n  apply(simp add: Lin2BraDer_def derivation_map_def)\n  apply(case_tac \"d (Suc nat)\")\n   apply(rename_tac nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac nat a)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d nat = Some (pair e1 c1) \\<and> d (Suc nat) = Some (pair (Some e2) c2) \\<and> lin_step_relation G c1 e2 c2\")\n   apply(rename_tac nat a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc nat\"\n      in GLIN.step_detail_before_some_position)\n     apply(rename_tac nat a)(*strict*)\n     apply(force)\n    apply(rename_tac nat a)(*strict*)\n    apply(force)\n   apply(rename_tac nat a)(*strict*)\n   apply(force)\n  apply(rename_tac nat a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat e1 e2 c1 c2)(*strict*)\n  apply(simp add: Lin2BraDer_def derivation_map_def)\n  apply(rule AX_Lin2BraConf_preserves_steps)\n    apply(rename_tac nat e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac nat e1 e2 c1 c2)(*strict*)\n   apply(rule GLIN.belongs_configurations)\n    apply(rename_tac nat e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac nat e1 e2 c1 c2)(*strict*)\n   apply(force)\n  apply(rename_tac nat e1 e2 c1 c2)(*strict*)\n  apply(force)\n  done\n\nlemma Lin2BraConf_preserves_initiality_lift: \"\n  TSstructure G\n  \\<Longrightarrow> GLIN.derivation_initial G d\n  \\<Longrightarrow> GBRA.derivation_initial G (Lin2BraDer d)\"\n  apply(subgoal_tac \"GLIN.belongs G d\")\n   prefer 2\n   apply(rule GLIN.derivation_initial_belongs)\n    apply(force)\n   apply(force)\n  apply(simp add: GLIN.derivation_initial_def GBRA.derivation_initial_def)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>c. d 0 = Some (pair None c)\")\n   prefer 2\n   apply(rule GLIN.some_position_has_details_at_0)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac c)(*strict*)\n  apply(rule context_conjI)\n   apply(rename_tac c)(*strict*)\n   apply(rule Lin2BraConf_preserves_steps_lift)\n     apply(rename_tac c)(*strict*)\n     apply(force)\n    apply(rename_tac c)(*strict*)\n    apply(force)\n   apply(rename_tac c)(*strict*)\n   apply(force)\n  apply(rename_tac c)(*strict*)\n  apply(simp add: Lin2BraDer_def derivation_map_def)\n  apply(rule AX_Lin2BraConf_preserves_initiality)\n   apply(rename_tac c)(*strict*)\n   apply(force)\n  apply(rename_tac c)(*strict*)\n  apply(force)\n  done\n\nlemma Lin2BraConf_preserves_maximum_of_domain: \"\n  TSstructure G\n  \\<Longrightarrow> GLIN.derivation G d\n  \\<Longrightarrow> maximum_of_domain d n\n  \\<Longrightarrow> maximum_of_domain (Lin2BraDer d) n\"\n  apply(simp add: Lin2BraDer_def derivation_map_def maximum_of_domain_def)\n  apply(clarsimp)\n  apply(rename_tac y)(*strict*)\n  apply(case_tac y)\n  apply(rename_tac y option b)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma Bra2LinDer_defined0: \"\n  derivation G d\n  \\<Longrightarrow> Bra2LinDer G d n x \\<noteq> None\n  \\<Longrightarrow> x\\<le>n\"\n  apply(simp add: Bra2LinDer_def)\n  apply (metis option.simps(3) trivNat)\n  done\n\nlemma Bra2LinDer_defined1: \"\n  derivation G d\n  \\<Longrightarrow> Bra2LinDer G d n x \\<noteq> None\n  \\<Longrightarrow> d n \\<noteq> None\n  \\<Longrightarrow> d x \\<noteq> None\"\n  apply(subgoal_tac \"x\\<le>n\")\n   prefer 2\n   apply(rule Bra2LinDer_defined0)\n    apply(force)\n   apply(force)\n  apply(simp add: Bra2LinDer_def)\n  apply(clarsimp)\n  apply(rename_tac y ya)(*strict*)\n  apply(case_tac \"d x\")\n   apply(rename_tac y ya)(*strict*)\n   apply(clarsimp)\n   apply(case_tac ya)\n   apply(rename_tac y ya option b)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac y ya a)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma Bra2LinDer_defined2: \"\n  derivation G d\n  \\<Longrightarrow> d x \\<noteq> None\n  \\<Longrightarrow> d n \\<noteq> None\n  \\<Longrightarrow> x \\<le> n\n  \\<Longrightarrow> Bra2LinDer G d n x \\<noteq> None\"\n  apply(simp add: Bra2LinDer_def)\n  apply(clarsimp)\n  apply(rename_tac y ya)(*strict*)\n  apply(case_tac \"d x\")\n   apply(rename_tac y ya)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac y ya a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac y ya)(*strict*)\n  apply(case_tac y)\n  apply(rename_tac y ya option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ya option b)(*strict*)\n  apply(case_tac ya)\n  apply(rename_tac ya option b optiona ba)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma Bra2LinDer_preserves_step_labels: \"\n  TSstructure G\n  \\<Longrightarrow> GBRA.derivation G d\n  \\<Longrightarrow> d n \\<noteq> None\n  \\<Longrightarrow> d m = Some (pair e c)\n  \\<Longrightarrow> m \\<le> n\n  \\<Longrightarrow> \\<exists>c. Bra2LinDer G d n m = Some (pair e c)\"\n  apply(clarsimp)\n  apply(rename_tac y)(*strict*)\n  apply(simp add: Bra2LinDer_def)\n  apply(case_tac y)\n  apply(rename_tac y option b)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma schedE_generated: \"\n  TSstructure G\n  \\<Longrightarrow> GBRA.derivation G d\n  \\<Longrightarrow> GBRA.belongs G d\n  \\<Longrightarrow> d n \\<noteq> None\n  \\<Longrightarrow> m<n\n  \\<Longrightarrow> foldl lin_join_scheduler_fragments (lin_empty_scheduler_fragment G)\n           (map (\\<lambda>n. case_option undefined\n                      (case_derivation_configuration\n                        (\\<lambda>e1 c1.\n                            case_option undefined\n                             (case_derivation_configuration\n                               (\\<lambda>a c2.\n                                   case a of Some e2 \\<Rightarrow> Bra2LinStep c1 e2 c2))\n                             (d (Suc n))))\n                      (d n))\n             (nat_seq (Suc m) (n - Suc 0)))\n          \\<in> lin_scheduler_fragments G\"\n  apply(induct n)\n   apply(clarsimp)\n  apply(rename_tac n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n y)(*strict*)\n  apply(case_tac \"m=n\")\n   apply(rename_tac n y)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac y)(*strict*)\n   apply(rule_tac\n      t=\"nat_seq (Suc m) m\"\n      and s=\"[]\"\n      in ssubst)\n    apply(rename_tac y)(*strict*)\n    apply (metis lessI nat_seqEmpty)\n   apply(rename_tac y)(*strict*)\n   apply(clarsimp)\n   apply(rule GLIN.AX_empty_scheduler_fragment_in_scheduler_fragments)\n   apply(force)\n  apply(rename_tac n y)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"m<n\")\n   apply(rename_tac n y)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac n y)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"nat_seq (Suc m) (n - Suc 0) @ [n] = nat_seq (Suc m) n\")\n   apply(rename_tac n y)(*strict*)\n   prefer 2\n   apply(rule nat_seq_last)\n   apply(force)\n  apply(rename_tac n y)(*strict*)\n  apply(rule_tac\n      t=\"nat_seq (Suc m) n\"\n      and s=\"nat_seq (Suc m) (n - Suc 0) @ [n]\"\n      in ssubst)\n   apply(rename_tac n y)(*strict*)\n   apply(force)\n  apply(rename_tac n y)(*strict*)\n  apply(rule_tac\n      t=\"map (\\<lambda>n. case d n of Some (pair e1 c1) \\<Rightarrow> case d (Suc n) of Some (pair (Some e2) c2) \\<Rightarrow> Bra2LinStep c1 e2 c2) (nat_seq (Suc m) (n - Suc 0) @ [n])\"\n      and s=\"map (\\<lambda>n. case d n of Some (pair e1 c1) \\<Rightarrow> case d (Suc n) of Some (pair (Some e2) c2) \\<Rightarrow> Bra2LinStep c1 e2 c2) (nat_seq (Suc m) (n - Suc 0))@map (\\<lambda>n. case d n of Some (pair e1 c1) \\<Rightarrow> case d (Suc n) of Some (pair (Some e2) c2) \\<Rightarrow> Bra2LinStep c1 e2 c2) ([n])\"\n      in ssubst)\n   apply(rename_tac n y)(*strict*)\n   apply(rule map_append)\n  apply(rename_tac n y)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d n = Some (pair e1 c1) \\<and> d (Suc n) = Some (pair (Some e2) c2) \\<and> bra_step_relation G c1 e2 c2\")\n   apply(rename_tac n y)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc n\"\n      in GBRA.step_detail_before_some_position)\n     apply(rename_tac n y)(*strict*)\n     apply(force)\n    apply(rename_tac n y)(*strict*)\n    apply(force)\n   apply(rename_tac n y)(*strict*)\n   apply(force)\n  apply(rename_tac n y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n e1 e2 c1 c2)(*strict*)\n  apply(rule GLIN.AX_join_scheduler_fragments_closed)\n    apply(rename_tac n e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac n e1 e2 c1 c2)(*strict*)\n   apply(force)\n  apply(rename_tac n e1 e2 c1 c2)(*strict*)\n  apply(rule AX_Bra2LinStep_closed)\n    apply(rename_tac n e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac n e1 e2 c1 c2)(*strict*)\n   apply(rule GBRA.belongs_configurations)\n    apply(rename_tac n e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac n e1 e2 c1 c2)(*strict*)\n   apply(force)\n  apply(rename_tac n e1 e2 c1 c2)(*strict*)\n  apply(force)\n  done\n\nlemma Bra2LinDer_preserves_configurations: \"\n  TSstructure G\n  \\<Longrightarrow> GBRA.derivation G d\n  \\<Longrightarrow> GBRA.belongs G d\n  \\<Longrightarrow> d n = Some (pair en cn)\n  \\<Longrightarrow> d m = Some (pair em cm)\n  \\<Longrightarrow> m \\<le> n\n  \\<Longrightarrow> Bra2LinDer G d n m = Some (pair em c')\n  \\<Longrightarrow> c' \\<in> lin_configurations G\n  \\<and> (\\<exists>sE \\<in> lin_scheduler_fragments G. c' = Bra2LinConf cm (lin_extend_scheduler sE (Bra2LinFin G (bra_get_fixed_scheduler cn))))\"\n  apply(subgoal_tac \"cn \\<in> bra_configurations G\")\n   prefer 2\n   apply(rule GBRA.belongs_configurations)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"cm \\<in> bra_configurations G\")\n   prefer 2\n   apply(rule GBRA.belongs_configurations)\n    apply(force)\n   apply(force)\n  apply(induct \"n-m\" arbitrary: n m en cn em cm c')\n   apply(rename_tac n m en cn em cm c')(*strict*)\n   apply(clarsimp)\n   apply(rename_tac m en cn c')(*strict*)\n   apply(simp add: Bra2LinDer_def Bra2LinDer'_def)\n   apply(clarsimp)\n   apply(rename_tac m en cn)(*strict*)\n   apply(rule_tac\n      t=\"case_nat [] (nat_seq m) m\"\n      and s=\"[]\"\n      in ssubst)\n    apply(rename_tac m en cn)(*strict*)\n    apply(case_tac m)\n     apply(rename_tac m en cn)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac m en cn nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac en cn nat)(*strict*)\n    apply (metis lessI nat_seqEmpty)\n   apply(rename_tac m en cn)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac m en cn)(*strict*)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"lin_extend_scheduler (lin_empty_scheduler_fragment G) (Bra2LinFin G (bra_get_fixed_scheduler cn))\"\n      and s=\"Bra2LinFin G (bra_get_fixed_scheduler cn)\"\n      in ssubst)\n     apply(rename_tac m en cn)(*strict*)\n     apply(rule GLIN.AX_extend_scheduler_left_neutral)\n      apply(rename_tac m en cn)(*strict*)\n      apply(force)\n     apply(rename_tac m en cn)(*strict*)\n     apply(rule AX_Bra2LinFin_closed)\n      apply(rename_tac m en cn)(*strict*)\n      apply(force)\n     apply(rename_tac m en cn)(*strict*)\n     apply(force)\n    apply(rename_tac m en cn)(*strict*)\n    apply(rule AX_Bra2LinFin_creates_proper_extension)\n     apply(rename_tac m en cn)(*strict*)\n     apply(force)\n    apply(rename_tac m en cn)(*strict*)\n    apply(force)\n   apply(rename_tac m en cn)(*strict*)\n   apply(clarsimp)\n   apply(rule_tac\n      x=\"lin_empty_scheduler_fragment G\"\n      in bexI)\n    apply(rename_tac m en cn)(*strict*)\n    apply(force)\n   apply(rename_tac m en cn)(*strict*)\n   apply(rule GLIN.AX_empty_scheduler_fragment_in_scheduler_fragments)\n   apply(force)\n  apply(rename_tac x n m en cn em cm c')(*strict*)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"n\"\n      in meta_allE)\n  apply(erule_tac\n      x=\"Suc m\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(subgoal_tac \"m<n\")\n   apply(rename_tac x n m en cn em cm c')(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac x n m en cn em cm c')(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d (Suc m) = Some (pair e c)\")\n   apply(rename_tac x n m en cn em cm c')(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"n\"\n      in GBRA.pre_some_position_is_some_position)\n     apply(rename_tac x n m en cn em cm c')(*strict*)\n     apply(force)\n    apply(rename_tac x n m en cn em cm c')(*strict*)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c')(*strict*)\n   apply(force)\n  apply(rename_tac x n m en cn em cm c')(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x n m en cn em cm c' e c)(*strict*)\n  apply(subgoal_tac \"Bra2LinDer G d n (Suc m) \\<noteq> None\")\n   apply(rename_tac x n m en cn em cm c' e c)(*strict*)\n   prefer 2\n   apply(rule Bra2LinDer_defined2)\n      apply(rename_tac x n m en cn em cm c' e c)(*strict*)\n      apply(force)\n     apply(rename_tac x n m en cn em cm c' e c)(*strict*)\n     apply(force)\n    apply(rename_tac x n m en cn em cm c' e c)(*strict*)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c' e c)(*strict*)\n   apply(force)\n  apply(rename_tac x n m en cn em cm c' e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x n m en cn em cm c' e c y)(*strict*)\n  apply(case_tac y)\n  apply(rename_tac x n m en cn em cm c' e c y option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x n m en cn em cm c' e c option b)(*strict*)\n  apply(erule_tac\n      x=\"en\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"cn\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"e\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"c\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"b\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(erule meta_impE)\n   apply(rename_tac x n m en cn em cm c' e c option b)(*strict*)\n   apply(force)\n  apply(rename_tac x n m en cn em cm c' e c option b)(*strict*)\n  apply(simp add: Bra2LinDer_def Bra2LinDer'_def)\n  apply(subgoal_tac \"c \\<in> bra_configurations G\")\n   apply(rename_tac x n m en cn em cm c' e c option b)(*strict*)\n   prefer 2\n   apply(rule GBRA.belongs_configurations)\n    apply(rename_tac x n m en cn em cm c' e c option b)(*strict*)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c' e c option b)(*strict*)\n   apply(force)\n  apply(rename_tac x n m en cn em cm c' e c option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n  apply(subgoal_tac \"case_nat [] (nat_seq (Suc m)) n = nat_seq (Suc m) (n - 1)\")\n   apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n   prefer 2\n   apply(case_tac n)\n    apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c option sE nat)(*strict*)\n   apply(force)\n  apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"case_nat [] (nat_seq m) n = nat_seq m (n - 1)\")\n   apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n   prefer 2\n   apply(case_tac n)\n    apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c option sE nat)(*strict*)\n   apply(force)\n  apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n  apply(clarsimp)\n  apply(thin_tac \"case_nat [] (nat_seq (Suc m)) n = nat_seq (Suc m) (n - Suc 0)\")\n  apply(thin_tac \"case_nat [] (nat_seq m) n = nat_seq m (n - Suc 0)\")\n  apply(subgoal_tac \"foldl lin_join_scheduler_fragments (lin_empty_scheduler_fragment G) (map (\\<lambda>n. case_option undefined (case_derivation_configuration (\\<lambda>e1 c1. case_option undefined (case_derivation_configuration (\\<lambda>a c2. case a of Some e2 \\<Rightarrow> Bra2LinStep c1 e2 c2)) (d (Suc n)))) (d n)) (nat_seq (Suc m) (n - Suc 0))) = sE\")\n   apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n   prefer 2\n   apply(rule_tac\n      s=\"Bra2LinFin G (bra_get_fixed_scheduler cn)\"\n      in GLIN.AX_extend_scheduler_left_injective)\n       apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n       apply(force)\n      apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n      apply(rule schedE_generated)\n          apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n          apply(force)\n         apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n         apply(force)\n        apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n        apply(force)\n       apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n       apply(force)\n      apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n      apply(force)\n     apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n     apply(force)\n    apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n    apply(rule AX_Bra2LinFin_closed)\n     apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n     apply(force)\n    apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n   apply(rule_tac\n      cB=\"c\"\n      in AX_Bra2LinConf_inj)\n     apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n     apply(force)\n    apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n   apply(force)\n  apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n  apply(rule_tac\n      A=\"lin_scheduler_fragments G\"\n      and a=\"((foldl lin_join_scheduler_fragments (lin_empty_scheduler_fragment G) (map (\\<lambda>n. case_option undefined (case_derivation_configuration (\\<lambda>e1 c1. case_option undefined (case_derivation_configuration(\\<lambda>a c2. case a of Some e2 \\<Rightarrow> Bra2LinStep c1 e2 c2)) (d (Suc n)))) (d n)) (nat_seq m (n - Suc 0)))))\"\n      in bexI_conj)\n  apply(rename_tac x n m en cn em cm c option sE)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x n m en cn em cm c option)(*strict*)\n  apply(subgoal_tac \"nat_seq m (n-Suc 0) = [m]@(nat_seq (Suc m) (n-Suc 0))\")\n   apply(rename_tac x n m en cn em cm c option)(*strict*)\n   prefer 2\n   apply(rule nat_seq_drop_first2)\n   apply(force)\n  apply(rename_tac x n m en cn em cm c option)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e c. d (Suc m) = Some (pair (Some e) c)\")\n   apply(rename_tac x n m en cn em cm c option)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc m\"\n      in GBRA.pre_some_position_is_some_position_prime)\n      apply(rename_tac x n m en cn em cm c option)(*strict*)\n      apply(force)\n     apply(rename_tac x n m en cn em cm c option)(*strict*)\n     apply(force)\n    apply(rename_tac x n m en cn em cm c option)(*strict*)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c option)(*strict*)\n   apply(force)\n  apply(rename_tac x n m en cn em cm c option)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x n m en cn em cm c e)(*strict*)\n  apply(rule_tac\n      t=\"lin_join_scheduler_fragments (lin_empty_scheduler_fragment G) (Bra2LinStep cm e c)\"\n      and s=\"Bra2LinStep cm e c\"\n      in ssubst)\n   apply(rename_tac x n m en cn em cm c e)(*strict*)\n   apply(rule GLIN.AX_join_scheduler_fragments_neutral_right)\n    apply(rename_tac x n m en cn em cm c e)(*strict*)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c e)(*strict*)\n   apply(rule AX_Bra2LinStep_closed)\n     apply(rename_tac x n m en cn em cm c e)(*strict*)\n     apply(force)\n    apply(rename_tac x n m en cn em cm c e)(*strict*)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c e)(*strict*)\n   apply(rule GBRA.position_change_due_to_step_relation)\n     apply(rename_tac x n m en cn em cm c e)(*strict*)\n     apply(force)\n    apply(rename_tac x n m en cn em cm c e)(*strict*)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c e)(*strict*)\n   apply(force)\n  apply(rename_tac x n m en cn em cm c e)(*strict*)\n  apply(rule_tac\n      t=\"foldl lin_join_scheduler_fragments (Bra2LinStep cm e c) (map (\\<lambda>n. case d n of Some (pair e1 c1) \\<Rightarrow> case d (Suc n) of Some (pair (Some e2) c2) \\<Rightarrow> Bra2LinStep c1 e2 c2) (nat_seq (Suc m) (n - Suc 0)))\"\n      and s=\" lin_join_scheduler_fragments (Bra2LinStep cm e c) (foldl lin_join_scheduler_fragments (lin_empty_scheduler_fragment G) (map (\\<lambda>n. case d n of Some (pair e1 c1) \\<Rightarrow> case d (Suc n) of Some (pair (Some e2) c2) \\<Rightarrow> Bra2LinStep c1 e2 c2) (nat_seq (Suc m) (n - Suc 0))))\"\n      in ssubst)\n   apply(rename_tac x n m en cn em cm c e)(*strict*)\n   apply(rule GLIN.AX_foldl_join_scheduler_fragments)\n     apply(rename_tac x n m en cn em cm c e)(*strict*)\n     apply(force)\n    apply(rename_tac x n m en cn em cm c e)(*strict*)\n    apply(rule AX_Bra2LinStep_closed)\n      apply(rename_tac x n m en cn em cm c e)(*strict*)\n      apply(force)\n     apply(rename_tac x n m en cn em cm c e)(*strict*)\n     apply(force)\n    apply(rename_tac x n m en cn em cm c e)(*strict*)\n    apply(rule GBRA.position_change_due_to_step_relation)\n      apply(rename_tac x n m en cn em cm c e)(*strict*)\n      apply(force)\n     apply(rename_tac x n m en cn em cm c e)(*strict*)\n     apply(force)\n    apply(rename_tac x n m en cn em cm c e)(*strict*)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c e)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x n m en cn em cm c e na)(*strict*)\n   apply(subgoal_tac \"Suc m\\<le>na \\<and> na \\<le> n-Suc 0\")\n    apply(rename_tac x n m en cn em cm c e na)(*strict*)\n    prefer 2\n    apply(rule nat_seq_in_interval)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c e na)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d na = Some (pair e1 c1) \\<and> d (Suc na) = Some (pair (Some e2) c2) \\<and> bra_step_relation G c1 e2 c2\")\n    apply(rename_tac x n m en cn em cm c e na)(*strict*)\n    prefer 2\n    apply(rule_tac\n      m=\"n\"\n      in GBRA.step_detail_before_some_position)\n      apply(rename_tac x n m en cn em cm c e na)(*strict*)\n      apply(force)\n     apply(rename_tac x n m en cn em cm c e na)(*strict*)\n     apply(force)\n    apply(rename_tac x n m en cn em cm c e na)(*strict*)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c e na)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x n m en cn em cm c e na e1 e2 c1 c2)(*strict*)\n   apply(rule AX_Bra2LinStep_closed)\n     apply(rename_tac x n m en cn em cm c e na e1 e2 c1 c2)(*strict*)\n     apply(force)\n    apply(rename_tac x n m en cn em cm c e na e1 e2 c1 c2)(*strict*)\n    apply(rule GBRA.belongs_configurations)\n     apply(rename_tac x n m en cn em cm c e na e1 e2 c1 c2)(*strict*)\n     apply(force)\n    apply(rename_tac x n m en cn em cm c e na e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c e na e1 e2 c1 c2)(*strict*)\n   apply(force)\n  apply(rename_tac x n m en cn em cm c e)(*strict*)\n  apply(rule_tac\n      t=\"lin_extend_scheduler (lin_join_scheduler_fragments (Bra2LinStep cm e c) (foldl lin_join_scheduler_fragments (lin_empty_scheduler_fragment G) (map (\\<lambda>n. case d n of Some (pair e1 c1) \\<Rightarrow> case d (Suc n) of Some (pair (Some e2) c2) \\<Rightarrow> Bra2LinStep c1 e2 c2) (nat_seq (Suc m) (n - Suc 0))))) (Bra2LinFin G (bra_get_fixed_scheduler cn))\"\n      and s=\"lin_extend_scheduler (Bra2LinStep cm e c) (lin_extend_scheduler (foldl lin_join_scheduler_fragments (lin_empty_scheduler_fragment G) (map (\\<lambda>n. case d n of Some (pair e1 c1) \\<Rightarrow> case d (Suc n) of Some (pair (Some e2) c2) \\<Rightarrow> Bra2LinStep c1 e2 c2) (nat_seq (Suc m) (n - Suc 0)))) (Bra2LinFin G (bra_get_fixed_scheduler cn)))\"\n      in ssubst)\n   apply(rename_tac x n m en cn em cm c e)(*strict*)\n   apply(rule GLIN.AX_extend_scheduler_compatible_to_join_scheduler_fragments)\n      apply(rename_tac x n m en cn em cm c e)(*strict*)\n      apply(force)\n     apply(rename_tac x n m en cn em cm c e)(*strict*)\n     apply(rule AX_Bra2LinStep_closed)\n       apply(rename_tac x n m en cn em cm c e)(*strict*)\n       apply(force)\n      apply(rename_tac x n m en cn em cm c e)(*strict*)\n      apply(rule GBRA.belongs_configurations)\n       apply(rename_tac x n m en cn em cm c e)(*strict*)\n       apply(force)\n      apply(rename_tac x n m en cn em cm c e)(*strict*)\n      apply(force)\n     apply(rename_tac x n m en cn em cm c e)(*strict*)\n     apply(rule GBRA.position_change_due_to_step_relation)\n       apply(rename_tac x n m en cn em cm c e)(*strict*)\n       apply(force)\n      apply(rename_tac x n m en cn em cm c e)(*strict*)\n      apply(force)\n     apply(rename_tac x n m en cn em cm c e)(*strict*)\n     apply(force)\n    apply(rename_tac x n m en cn em cm c e)(*strict*)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c e)(*strict*)\n   apply(rule AX_Bra2LinFin_closed)\n    apply(rename_tac x n m en cn em cm c e)(*strict*)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c e)(*strict*)\n   apply(force)\n  apply(rename_tac x n m en cn em cm c e)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac x n m en cn em cm c e)(*strict*)\n   apply(rule AX_Bra2LinStep_translates_backwards_Bra2LinConf_closed)\n      apply(rename_tac x n m en cn em cm c e)(*strict*)\n      apply(force)\n     apply(rename_tac x n m en cn em cm c e)(*strict*)\n     apply(force)\n    apply(rename_tac x n m en cn em cm c e)(*strict*)\n    apply(rule GBRA.position_change_due_to_step_relation)\n      apply(rename_tac x n m en cn em cm c e)(*strict*)\n      apply(force)\n     apply(rename_tac x n m en cn em cm c e)(*strict*)\n     apply(force)\n    apply(rename_tac x n m en cn em cm c e)(*strict*)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c e)(*strict*)\n   apply(force)\n  apply(rename_tac x n m en cn em cm c e)(*strict*)\n  apply(rule GLIN.AX_join_scheduler_fragments_closed)\n    apply(rename_tac x n m en cn em cm c e)(*strict*)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c e)(*strict*)\n   apply(rule AX_Bra2LinStep_closed)\n     apply(rename_tac x n m en cn em cm c e)(*strict*)\n     apply(force)\n    apply(rename_tac x n m en cn em cm c e)(*strict*)\n    apply(rule GBRA.belongs_configurations)\n     apply(rename_tac x n m en cn em cm c e)(*strict*)\n     apply(force)\n    apply(rename_tac x n m en cn em cm c e)(*strict*)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c e)(*strict*)\n   apply(rule GBRA.position_change_due_to_step_relation)\n     apply(rename_tac x n m en cn em cm c e)(*strict*)\n     apply(force)\n    apply(rename_tac x n m en cn em cm c e)(*strict*)\n    apply(force)\n   apply(rename_tac x n m en cn em cm c e)(*strict*)\n   apply(force)\n  apply(rename_tac x n m en cn em cm c e)(*strict*)\n  apply(force)\n  done\n\nlemma Bra2LinDer_preserves_configurations_prime: \"\n  TSstructure G\n  \\<Longrightarrow> GBRA.derivation G d\n  \\<Longrightarrow> GBRA.belongs G d\n  \\<Longrightarrow> d n = Some (pair en cn)\n  \\<Longrightarrow> d m = Some (pair em cm)\n  \\<Longrightarrow> m \\<le> n\n  \\<Longrightarrow> Bra2LinDer G d n m = Some (pair em c')\n  \\<Longrightarrow> c' \\<in> lin_configurations G\"\n  apply(subgoal_tac \"c' \\<in> lin_configurations G \\<and> (\\<exists>sE \\<in> lin_scheduler_fragments G. c' = Bra2LinConf cm (lin_extend_scheduler sE (Bra2LinFin G (bra_get_fixed_scheduler cn))))\")\n   apply(force)\n  apply(rule Bra2LinDer_preserves_configurations)\n        apply(force)+\n  done\n\nlemma Bra2LinDer_preserves_derivation: \"\n  TSstructure G\n  \\<Longrightarrow> GBRA.derivation G d\n  \\<Longrightarrow> GBRA.belongs G d\n  \\<Longrightarrow> d n \\<noteq> None\n  \\<Longrightarrow> GLIN.derivation G (Bra2LinDer G d n)\"\n  apply(simp add: GLIN.derivation_def)\n  apply(clarsimp)\n  apply(rename_tac y i)(*strict*)\n  apply(case_tac i)\n   apply(rename_tac y i)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac y)(*strict*)\n   apply(subgoal_tac \"\\<exists>c. d 0 = Some (pair None c)\")\n    apply(rename_tac y)(*strict*)\n    prefer 2\n    apply(rule GBRA.some_position_has_details_at_0)\n    apply(force)\n   apply(rename_tac y)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac y c)(*strict*)\n   apply(subgoal_tac \"\\<exists>c. Bra2LinDer G d n 0 = Some (pair None c)\")\n    apply(rename_tac y c)(*strict*)\n    prefer 2\n    apply(rule Bra2LinDer_preserves_step_labels)\n        apply(rename_tac y c)(*strict*)\n        apply(force)\n       apply(rename_tac y c)(*strict*)\n       apply(force)\n      apply(rename_tac y c)(*strict*)\n      apply(force)\n     apply(rename_tac y c)(*strict*)\n     apply(force)\n    apply(rename_tac y c)(*strict*)\n    apply(force)\n   apply(rename_tac y c)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac y i nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac y nat)(*strict*)\n  apply(case_tac \"Bra2LinDer G d n (Suc nat)\")\n   apply(rename_tac y nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac y nat a)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"Suc nat\\<le>n\")\n   apply(rename_tac y nat a)(*strict*)\n   prefer 2\n   apply(rule Bra2LinDer_defined0)\n    apply(rename_tac y nat a)(*strict*)\n    apply(force)\n   apply(rename_tac y nat a)(*strict*)\n   apply(force)\n  apply(rename_tac y nat a)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d nat = Some (pair e1 c1) \\<and> d (Suc nat) = Some (pair (Some e2) c2) \\<and> bra_step_relation G c1 e2 c2\")\n   apply(rename_tac y nat a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc nat\"\n      in GBRA.step_detail_before_some_position)\n     apply(rename_tac y nat a)(*strict*)\n     apply(force)\n    apply(rename_tac y nat a)(*strict*)\n    apply(rule Bra2LinDer_defined1)\n      apply(rename_tac y nat a)(*strict*)\n      apply(force)\n     apply(rename_tac y nat a)(*strict*)\n     apply(force)\n    apply(rename_tac y nat a)(*strict*)\n    apply(force)\n   apply(rename_tac y nat a)(*strict*)\n   apply(force)\n  apply(rename_tac y nat a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac y nat a e1 e2 c1 c2)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. Bra2LinDer G d n (Suc nat) = Some (pair (Some e2) c)\")\n   apply(rename_tac y nat a e1 e2 c1 c2)(*strict*)\n   prefer 2\n   apply(rule Bra2LinDer_preserves_step_labels)\n       apply(rename_tac y nat a e1 e2 c1 c2)(*strict*)\n       apply(force)\n      apply(rename_tac y nat a e1 e2 c1 c2)(*strict*)\n      apply(force)\n     apply(rename_tac y nat a e1 e2 c1 c2)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac y nat a e1 e2 c1 c2)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac y nat a e1 e2 c1 c2)(*strict*)\n   apply(force)\n  apply(rename_tac y nat a e1 e2 c1 c2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac y nat e1 e2 c1 c2 c)(*strict*)\n  apply(subgoal_tac \"Bra2LinDer G d n nat \\<noteq> None\")\n   apply(rename_tac y nat e1 e2 c1 c2 c)(*strict*)\n   prefer 2\n   apply(rule Bra2LinDer_defined2)\n      apply(rename_tac y nat e1 e2 c1 c2 c)(*strict*)\n      apply(force)\n     apply(rename_tac y nat e1 e2 c1 c2 c)(*strict*)\n     apply(force)\n    apply(rename_tac y nat e1 e2 c1 c2 c)(*strict*)\n    apply(force)\n   apply(rename_tac y nat e1 e2 c1 c2 c)(*strict*)\n   apply(force)\n  apply(rename_tac y nat e1 e2 c1 c2 c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac y nat e1 e2 c1 c2 c ya)(*strict*)\n  apply(case_tac ya)\n  apply(rename_tac y nat e1 e2 c1 c2 c ya option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac y nat e1 e2 c1 c2 c option b)(*strict*)\n  apply(case_tac y)\n  apply(rename_tac y nat e1 e2 c1 c2 c option b optiona ba)(*strict*)\n  apply(subgoal_tac \"c \\<in> lin_configurations G \\<and> (\\<exists>sE \\<in> lin_scheduler_fragments G. c = Bra2LinConf c2 (lin_extend_scheduler sE (Bra2LinFin G (bra_get_fixed_scheduler ba))))\")\n   apply(rename_tac y nat e1 e2 c1 c2 c option b optiona ba)(*strict*)\n   prefer 2\n   apply(rule Bra2LinDer_preserves_configurations)\n         apply(rename_tac y nat e1 e2 c1 c2 c option b optiona ba)(*strict*)\n         apply(force)\n        apply(rename_tac y nat e1 e2 c1 c2 c option b optiona ba)(*strict*)\n        apply(force)\n       apply(rename_tac y nat e1 e2 c1 c2 c option b optiona ba)(*strict*)\n       apply(force)\n      apply(rename_tac y nat e1 e2 c1 c2 c option b optiona ba)(*strict*)\n      apply(force)\n     apply(rename_tac y nat e1 e2 c1 c2 c option b optiona ba)(*strict*)\n     apply(force)\n    apply(rename_tac y nat e1 e2 c1 c2 c option b optiona ba)(*strict*)\n    apply(force)\n   apply(rename_tac y nat e1 e2 c1 c2 c option b optiona ba)(*strict*)\n   apply(force)\n  apply(rename_tac y nat e1 e2 c1 c2 c option b optiona ba)(*strict*)\n  apply(subgoal_tac \"b \\<in> lin_configurations G \\<and> (\\<exists>sE \\<in> lin_scheduler_fragments G. b = Bra2LinConf c1 (lin_extend_scheduler sE (Bra2LinFin G (bra_get_fixed_scheduler ba))))\")\n   apply(rename_tac y nat e1 e2 c1 c2 c option b optiona ba)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"nat\"\n      in Bra2LinDer_preserves_configurations)\n         apply(rename_tac y nat e1 e2 c1 c2 c option b optiona ba)(*strict*)\n         apply(force)\n        apply(rename_tac y nat e1 e2 c1 c2 c option b optiona ba)(*strict*)\n        apply(force)\n       apply(rename_tac y nat e1 e2 c1 c2 c option b optiona ba)(*strict*)\n       apply(force)\n      apply(rename_tac y nat e1 e2 c1 c2 c option b optiona ba)(*strict*)\n      apply(force)\n     apply(rename_tac y nat e1 e2 c1 c2 c option b optiona ba)(*strict*)\n     apply(force)\n    apply(rename_tac y nat e1 e2 c1 c2 c option b optiona ba)(*strict*)\n    apply(force)\n   apply(rename_tac y nat e1 e2 c1 c2 c option b optiona ba)(*strict*)\n   apply(simp add: Bra2LinDer_def)\n  apply(rename_tac y nat e1 e2 c1 c2 c option b optiona ba)(*strict*)\n  apply(simp add: Bra2LinDer_def Bra2LinDer'_def)\n  apply(clarsimp)\n  apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa)(*strict*)\n  apply(subgoal_tac \"case_nat [] (nat_seq (Suc nat)) n = nat_seq (Suc nat) (n - 1)\")\n   apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa)(*strict*)\n   prefer 2\n   apply(case_tac n)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa)(*strict*)\n    apply(force)\n   apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa nata)(*strict*)\n   apply(force)\n  apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"case_nat [] (nat_seq nat) n = nat_seq nat (n - 1)\")\n   apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa)(*strict*)\n   prefer 2\n   apply(case_tac n)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa)(*strict*)\n    apply(force)\n   apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa nata)(*strict*)\n   apply(force)\n  apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa)(*strict*)\n  apply(clarsimp)\n  apply(thin_tac \"case_nat [] (nat_seq (Suc nat)) n = nat_seq (Suc nat) (n - Suc 0)\")\n  apply(thin_tac \"case_nat [] (nat_seq nat) n = nat_seq nat (n - Suc 0)\")\n  apply(subgoal_tac \"\\<exists>x. Suc x=n-nat\")\n   apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa)(*strict*)\n   prefer 2\n   apply(rule_tac\n      x=\"n-Suc nat\"\n      in exI)\n   apply(force)\n  apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n  apply(subgoal_tac \"nat_seq nat (n-Suc 0) = [nat]@(nat_seq (Suc nat) (n-Suc 0))\")\n   apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n   prefer 2\n   apply(rule nat_seq_drop_first2)\n   apply(force)\n  apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"sEa = (foldl lin_join_scheduler_fragments (lin_join_scheduler_fragments (lin_empty_scheduler_fragment G) (Bra2LinStep c1 e2 c2)) (map (\\<lambda>n. case_option undefined (case_derivation_configuration (\\<lambda>e1 c1. case_option undefined (case_derivation_configuration (\\<lambda>a c2. case a of Some e2 \\<Rightarrow> Bra2LinStep c1 e2 c2)) (d (Suc n)))) (d n)) (nat_seq (Suc nat) (n - Suc 0))))\")\n   apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n   apply(subgoal_tac \"sE = foldl lin_join_scheduler_fragments (lin_empty_scheduler_fragment G) (map (\\<lambda>n. case_option undefined (case_derivation_configuration (\\<lambda>e1 c1. case_option undefined (case_derivation_configuration (\\<lambda>a c2. case a of Some e2 \\<Rightarrow> Bra2LinStep c1 e2 c2)) (d (Suc n)))) (d n)) (nat_seq (Suc nat) (n - Suc 0)))\")\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n    apply(clarify)\n    apply(rule_tac\n      t=\"lin_join_scheduler_fragments (lin_empty_scheduler_fragment G) (Bra2LinStep c1 e2 c2)\"\n      and s=\"Bra2LinStep c1 e2 c2\"\n      in ssubst)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(rule GLIN.AX_join_scheduler_fragments_neutral_right)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(rule AX_Bra2LinStep_closed)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(rule GBRA.belongs_configurations)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(force)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n    apply(rule_tac\n      t=\" (foldl lin_join_scheduler_fragments (Bra2LinStep c1 e2 c2) (map (\\<lambda>n. case d n of Some (pair e1 c1) \\<Rightarrow> case d (Suc n) of Some (pair (Some e2) c2) \\<Rightarrow> Bra2LinStep c1 e2 c2) (nat_seq (Suc nat) (n - Suc 0)))) \"\n      and s=\" lin_join_scheduler_fragments (Bra2LinStep c1 e2 c2) ((foldl lin_join_scheduler_fragments (lin_empty_scheduler_fragment G) (map (\\<lambda>n. case d n of Some (pair e1 c1) \\<Rightarrow> case d (Suc n) of Some (pair (Some e2) c2) \\<Rightarrow> Bra2LinStep c1 e2 c2) (nat_seq (Suc nat) (n - Suc 0)))))\"\n      in ssubst)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(rule GLIN.AX_foldl_join_scheduler_fragments)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(rule AX_Bra2LinStep_closed)\n        apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n        apply(force)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(rule GBRA.belongs_configurations)\n        apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n        apply(force)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac nat e2 c1 c2 option optiona ba x na)(*strict*)\n     apply(subgoal_tac \"Suc nat\\<le>na \\<and> na \\<le> n-Suc 0\")\n      apply(rename_tac nat e2 c1 c2 option optiona ba x na)(*strict*)\n      prefer 2\n      apply(rule nat_seq_in_interval)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba x na)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d na = Some (pair e1 c1) \\<and> d (Suc na) = Some (pair (Some e2) c2) \\<and> bra_step_relation G c1 e2 c2\")\n      apply(rename_tac nat e2 c1 c2 option optiona ba x na)(*strict*)\n      prefer 2\n      apply(rule_tac\n      m=\"n\"\n      in GBRA.step_detail_before_some_position)\n        apply(rename_tac nat e2 c1 c2 option optiona ba x na)(*strict*)\n        apply(force)\n       apply(rename_tac nat e2 c1 c2 option optiona ba x na)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba x na)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba x na)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac nat e2 c1 c2 option optiona ba x na e1 e2a c1a c2a)(*strict*)\n     apply(rule AX_Bra2LinStep_closed)\n       apply(rename_tac nat e2 c1 c2 option optiona ba x na e1 e2a c1a c2a)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba x na e1 e2a c1a c2a)(*strict*)\n      apply(rule GBRA.belongs_configurations)\n       apply(rename_tac nat e2 c1 c2 option optiona ba x na e1 e2a c1a c2a)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba x na e1 e2a c1a c2a)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba x na e1 e2a c1a c2a)(*strict*)\n     apply(force)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n    apply(rule_tac\n      t=\"lin_extend_scheduler (lin_join_scheduler_fragments (Bra2LinStep c1 e2 c2) (foldl lin_join_scheduler_fragments (lin_empty_scheduler_fragment G) (map (\\<lambda>n. case d n of Some (pair e1 c1) \\<Rightarrow> case d (Suc n) of Some (pair (Some e2) c2) \\<Rightarrow> Bra2LinStep c1 e2 c2) (nat_seq (Suc nat) (n - Suc 0))))) (Bra2LinFin G (bra_get_fixed_scheduler ba))\"\n      and s=\" lin_extend_scheduler (Bra2LinStep c1 e2 c2) (lin_extend_scheduler (foldl lin_join_scheduler_fragments (lin_empty_scheduler_fragment G) (map (\\<lambda>n. case d n of Some (pair e1 c1) \\<Rightarrow> case d (Suc n) of Some (pair (Some e2) c2) \\<Rightarrow> Bra2LinStep c1 e2 c2) (nat_seq (Suc nat) (n - Suc 0)))) (Bra2LinFin G (bra_get_fixed_scheduler ba)))\"\n      in ssubst)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(rule GLIN.AX_extend_scheduler_compatible_to_join_scheduler_fragments)\n        apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n        apply(force)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(rule AX_Bra2LinStep_closed)\n         apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n         apply(force)\n        apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n        apply(rule GBRA.belongs_configurations)\n         apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n         apply(force)\n        apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n        apply(force)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(rule GBRA.position_change_due_to_step_relation)\n         apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n         apply(force)\n        apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n        apply(force)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(rule schedE_generated)\n          apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n          apply(force)\n         apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n         apply(force)\n        apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n        apply(force)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(rule AX_Bra2LinFin_closed)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(rule GBRA.belongs_configurations)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(force)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n    apply(rule AX_lin_step_relation_from_Bra2LinStep)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(rule GBRA.belongs_configurations)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(force)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n    apply(force)\n   apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n   apply(rule_tac\n      s=\"Bra2LinFin G (bra_get_fixed_scheduler ba)\"\n      in GLIN.AX_extend_scheduler_left_injective)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(rule schedE_generated)\n         apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n         apply(force)\n        apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n        apply(force)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(force)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n    apply(rule AX_Bra2LinFin_closed)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(force)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n    apply(rule GBRA.belongs_configurations)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(force)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n    apply(force)\n   apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n   apply(rule_tac\n      cB=\"c2\"\n      in AX_Bra2LinConf_inj)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(force)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n    apply(rule GBRA.belongs_configurations)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(force)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n    apply(force)\n   apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n   apply(force)\n  apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n  apply(rule_tac\n      s=\"Bra2LinFin G (bra_get_fixed_scheduler ba)\"\n      in GLIN.AX_extend_scheduler_left_injective)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(force)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n    apply(rule_tac\n      t=\"lin_join_scheduler_fragments (lin_empty_scheduler_fragment G) (Bra2LinStep c1 e2 c2)\"\n      and s=\"Bra2LinStep c1 e2 c2\"\n      in ssubst)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(rule GLIN.AX_join_scheduler_fragments_neutral_right)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(rule AX_Bra2LinStep_closed)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(rule GBRA.belongs_configurations)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(force)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n    apply(rule_tac\n      t=\" (foldl lin_join_scheduler_fragments (Bra2LinStep c1 e2 c2) (map (\\<lambda>n. case d n of Some (pair e1 c1) \\<Rightarrow> case d (Suc n) of Some (pair (Some e2) c2) \\<Rightarrow> Bra2LinStep c1 e2 c2) (nat_seq (Suc nat) (n - Suc 0)))) \"\n      and s=\" lin_join_scheduler_fragments (Bra2LinStep c1 e2 c2) ((foldl lin_join_scheduler_fragments (lin_empty_scheduler_fragment G) (map (\\<lambda>n. case d n of Some (pair e1 c1) \\<Rightarrow> case d (Suc n) of Some (pair (Some e2) c2) \\<Rightarrow> Bra2LinStep c1 e2 c2) (nat_seq (Suc nat) (n - Suc 0)))))\"\n      in ssubst)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(rule GLIN.AX_foldl_join_scheduler_fragments)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(rule AX_Bra2LinStep_closed)\n        apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n        apply(force)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(rule GBRA.belongs_configurations)\n        apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n        apply(force)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x na)(*strict*)\n     apply(subgoal_tac \"Suc nat\\<le>na \\<and> na \\<le> n-Suc 0\")\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x na)(*strict*)\n      prefer 2\n      apply(rule nat_seq_in_interval)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x na)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d na = Some (pair e1 c1) \\<and> d (Suc na) = Some (pair (Some e2) c2) \\<and> bra_step_relation G c1 e2 c2\")\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x na)(*strict*)\n      prefer 2\n      apply(rule_tac\n      m=\"n\"\n      in GBRA.step_detail_before_some_position)\n        apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x na)(*strict*)\n        apply(force)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x na)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x na)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x na)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x na e1 e2a c1a c2a)(*strict*)\n     apply(rule AX_Bra2LinStep_closed)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x na e1 e2a c1a c2a)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x na e1 e2a c1a c2a)(*strict*)\n      apply(rule GBRA.belongs_configurations)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x na e1 e2a c1a c2a)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x na e1 e2a c1a c2a)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x na e1 e2a c1a c2a)(*strict*)\n     apply(force)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n    apply(rule_tac\n      t=\"lin_extend_scheduler (lin_join_scheduler_fragments (Bra2LinStep c1 e2 c2) (foldl lin_join_scheduler_fragments (lin_empty_scheduler_fragment G) (map (\\<lambda>n. case d n of Some (pair e1 c1) \\<Rightarrow> case d (Suc n) of Some (pair (Some e2) c2) \\<Rightarrow> Bra2LinStep c1 e2 c2) (nat_seq (Suc nat) (n - Suc 0))))) (Bra2LinFin G (bra_get_fixed_scheduler ba))\"\n      and s=\" lin_extend_scheduler (Bra2LinStep c1 e2 c2) (lin_extend_scheduler (foldl lin_join_scheduler_fragments (lin_empty_scheduler_fragment G) (map (\\<lambda>n. case d n of Some (pair e1 c1) \\<Rightarrow> case d (Suc n) of Some (pair (Some e2) c2) \\<Rightarrow> Bra2LinStep c1 e2 c2) (nat_seq (Suc nat) (n - Suc 0)))) (Bra2LinFin G (bra_get_fixed_scheduler ba)))\"\n      in ssubst)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(rule GLIN.AX_extend_scheduler_compatible_to_join_scheduler_fragments)\n        apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n        apply(force)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(rule AX_Bra2LinStep_closed)\n         apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n         apply(force)\n        apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n        apply(rule GBRA.belongs_configurations)\n         apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n         apply(force)\n        apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n        apply(force)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(rule GBRA.position_change_due_to_step_relation)\n         apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n         apply(force)\n        apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n        apply(force)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(rule schedE_generated)\n          apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n          apply(force)\n         apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n         apply(force)\n        apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n        apply(force)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(rule AX_Bra2LinFin_closed)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(rule GBRA.belongs_configurations)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(force)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n    apply(rule GLIN.AX_join_scheduler_fragments_closed)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(rule AX_Bra2LinStep_closed)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(rule GBRA.belongs_configurations)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(force)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n    apply(rule schedE_generated)\n        apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n        apply(force)\n       apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n       apply(force)\n      apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n      apply(force)\n     apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n     apply(force)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n    apply(force)\n   apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n   apply(rule AX_Bra2LinFin_closed)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n    apply(force)\n   apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n   apply(rule GBRA.belongs_configurations)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n    apply(force)\n   apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n   apply(force)\n  apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n  apply(rule_tac\n      cB=\"c1\"\n      in AX_Bra2LinConf_inj)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n    apply(force)\n   apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n   apply(rule GBRA.belongs_configurations)\n    apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n    apply(force)\n   apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n   apply(force)\n  apply(rename_tac nat e2 c1 c2 option optiona ba sE sEa x)(*strict*)\n  apply(force)\n  done\n\nlemma Bra2LinDer_preserves_belongs: \"\n  TSstructure G\n  \\<Longrightarrow> GBRA.derivation G d\n  \\<Longrightarrow> GBRA.belongs G d\n  \\<Longrightarrow> d n \\<noteq> None\n  \\<Longrightarrow> GLIN.belongs G (Bra2LinDer G d n)\"\n  apply(subgoal_tac \"\\<exists>c. d 0 = Some (pair None c)\")\n   prefer 2\n   apply(rule GBRA.some_position_has_details_at_0)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac y c)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. Bra2LinDer G d n 0 = Some (pair None c)\")\n   apply(rename_tac y c)(*strict*)\n   prefer 2\n   apply(rule Bra2LinDer_preserves_step_labels)\n       apply(rename_tac y c)(*strict*)\n       apply(force)\n      apply(rename_tac y c)(*strict*)\n      apply(force)\n     apply(rename_tac y c)(*strict*)\n     apply(force)\n    apply(rename_tac y c)(*strict*)\n    apply(force)\n   apply(rename_tac y c)(*strict*)\n   apply(force)\n  apply(rename_tac y c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac y c ca)(*strict*)\n  apply(case_tac y)\n  apply(rename_tac y c ca option b)(*strict*)\n  apply(subgoal_tac \"ca \\<in> lin_configurations G \\<and> (\\<exists>sE \\<in> lin_scheduler_fragments G. ca = Bra2LinConf SScm (lin_extend_scheduler sE (Bra2LinFin G (bra_get_fixed_scheduler SScn))))\" for SScm SScn)\n   apply(rename_tac y c ca option b)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"0\"\n      and n=\"n\"\n      in Bra2LinDer_preserves_configurations)\n         apply(rename_tac y c ca option b)(*strict*)\n         apply(force)\n        apply(rename_tac y c ca option b)(*strict*)\n        apply(force)\n       apply(rename_tac y c ca option b)(*strict*)\n       apply(force)\n      apply(rename_tac y c ca option b)(*strict*)\n      prefer 4\n      apply(force)\n     apply(rename_tac y c ca option b)(*strict*)\n     apply(force)\n    apply(rename_tac y c ca option b)(*strict*)\n    apply(force)\n   apply(rename_tac y c ca option b)(*strict*)\n   apply(force)\n  apply(rename_tac y c ca option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c option b sE)(*strict*)\n  apply(rule GLIN.derivation_belongs)\n     apply(rename_tac c option b sE)(*strict*)\n     apply(force)\n    apply(rename_tac c option b sE)(*strict*)\n    apply(force)\n   apply(rename_tac c option b sE)(*strict*)\n   apply(force)\n  apply(rename_tac c option b sE)(*strict*)\n  apply(rule Bra2LinDer_preserves_derivation)\n     apply(rename_tac c option b sE)(*strict*)\n     apply(force)\n    apply(rename_tac c option b sE)(*strict*)\n    apply(force)\n   apply(rename_tac c option b sE)(*strict*)\n   apply(force)\n  apply(rename_tac c option b sE)(*strict*)\n  apply(force)\n  done\n\nlemma Bra2LinDer_preserves_maximum_of_domain: \"\n  TSstructure G\n  \\<Longrightarrow> GBRA.derivation G d\n  \\<Longrightarrow> GBRA.belongs G d\n  \\<Longrightarrow> d n \\<noteq> None\n  \\<Longrightarrow> maximum_of_domain (Bra2LinDer G d n) n\"\n  apply(simp add: maximum_of_domain_def)\n  apply(simp add: Bra2LinDer_def)\n  apply(case_tac \"d n\")\n   apply(force)\n  apply(rename_tac a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac a option b)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma Lin2BraDer_preserves_belongs: \"\n  TSstructure G\n  \\<Longrightarrow> GLIN.derivation G d\n  \\<Longrightarrow> GLIN.belongs G d\n  \\<Longrightarrow> GBRA.belongs G (Lin2BraDer d)\"\n  apply(simp add: GBRA.belongs_def)\n  apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(simp add: Lin2BraDer_def derivation_map_def)\n  apply(case_tac \"d i\")\n   apply(rename_tac i)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac i a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac i a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i option b)(*strict*)\n  apply(simp add: GLIN.belongs_def)\n  apply(erule_tac\n      x=\"i\"\n      in allE)\n  apply(clarsimp)\n  apply(rule AX_Lin2BraConf_preserves_configurations)\n   apply(rename_tac i option b)(*strict*)\n   apply(force)\n  apply(rename_tac i option b)(*strict*)\n  apply(force)\n  done\n\nlemma Bra2LinDer_prime_pullout_head: \"\n  TSstructure G\n  \\<Longrightarrow> GBRA.derivation G d\n  \\<Longrightarrow> GBRA.belongs G d\n  \\<Longrightarrow> n<m\n  \\<Longrightarrow> d m \\<noteq> None\n  \\<Longrightarrow> d n = Some (pair e1 c1)\n  \\<Longrightarrow> d (Suc n) = Some (pair (Some e2) c2)\n  \\<Longrightarrow> c1 \\<in> bra_configurations G\n  \\<Longrightarrow> Bra2LinDer' G d m n = lin_join_scheduler_fragments (Bra2LinStep c1 e2 c2) (Bra2LinDer' G d m (Suc n))\"\n  apply(subgoal_tac \"Bra2LinStep c1 e2 c2 \\<in> lin_scheduler_fragments G\")\n   prefer 2\n   apply(rule AX_Bra2LinStep_closed)\n     apply(force)\n    apply(force)\n   apply(rule GBRA.position_change_due_to_step_relation)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(rule_tac\n      t=\"Bra2LinDer' G d m n\"\n      and s=\"foldl lin_join_scheduler_fragments (lin_empty_scheduler_fragment G) (map (\\<lambda>n. case d n of Some (pair e1 c1) \\<Rightarrow> case d (Suc n) of Some (pair (Some e2) c2) \\<Rightarrow> Bra2LinStep c1 e2 c2) (case m of 0 \\<Rightarrow> [] | Suc m' \\<Rightarrow> nat_seq n m'))\"\n      in ssubst)\n   apply(simp add: Bra2LinDer'_def)\n  apply(case_tac m)\n   apply(force)\n  apply(rename_tac nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat y)(*strict*)\n  apply(rule_tac\n      t=\"nat\"\n      and s=\"(Suc nat)-(Suc 0)\"\n      in ssubst)\n   apply(rename_tac nat y)(*strict*)\n   apply(force)\n  apply(rename_tac nat y)(*strict*)\n  apply(rule_tac\n      t=\"nat_seq n ((Suc nat)-Suc 0)\"\n      and s=\"[n]@(nat_seq (Suc n) ((Suc nat)-Suc 0))\"\n      in ssubst)\n   apply(rename_tac nat y)(*strict*)\n   apply(rule_tac\n      x=\"nat-n\"\n      in nat_seq_drop_first2)\n   apply(arith)\n  apply(rename_tac nat y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat y)(*strict*)\n  apply(rule_tac\n      t=\"lin_join_scheduler_fragments (lin_empty_scheduler_fragment G) (Bra2LinStep c1 e2 c2)\"\n      and s=\"Bra2LinStep c1 e2 c2\"\n      in ssubst)\n   apply(rename_tac nat y)(*strict*)\n   apply(rule GLIN.AX_join_scheduler_fragments_neutral_right)\n    apply(rename_tac nat y)(*strict*)\n    apply(force)\n   apply(rename_tac nat y)(*strict*)\n   apply(force)\n  apply(rename_tac nat y)(*strict*)\n  apply(rule_tac\n      t=\"foldl lin_join_scheduler_fragments (Bra2LinStep c1 e2 c2) (map (\\<lambda>n. case_option undefined (case_derivation_configuration (\\<lambda>e1 c1. case_option undefined (case_derivation_configuration (\\<lambda>a c2. case a of Some e2 \\<Rightarrow> Bra2LinStep c1 e2 c2)) (d (Suc n)))) (d n)) (nat_seq (Suc n) nat))\"\n      and s=\"lin_join_scheduler_fragments (Bra2LinStep c1 e2 c2) (foldl lin_join_scheduler_fragments (lin_empty_scheduler_fragment G) (map (\\<lambda>n. case_option undefined (case_derivation_configuration (\\<lambda>e1 c1. case_option undefined (case_derivation_configuration (\\<lambda>a c2. case a of Some e2 \\<Rightarrow> Bra2LinStep c1 e2 c2)) (d (Suc n)))) (d n)) (nat_seq (Suc n) nat)))\"\n      in ssubst)\n   apply(rename_tac nat y)(*strict*)\n   apply(rule GLIN.AX_foldl_join_scheduler_fragments)\n     apply(rename_tac nat y)(*strict*)\n     apply(force)\n    apply(rename_tac nat y)(*strict*)\n    apply(force)\n   apply(rename_tac nat y)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac nat y na)(*strict*)\n   apply(subgoal_tac \"Suc n\\<le>na \\<and> na \\<le> nat\")\n    apply(rename_tac nat y na)(*strict*)\n    prefer 2\n    apply(rule nat_seq_in_interval)\n    apply(force)\n   apply(rename_tac nat y na)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d na = Some (pair e1 c1) \\<and> d (Suc na) = Some (pair (Some e2) c2) \\<and> bra_step_relation G c1 e2 c2\")\n    apply(rename_tac nat y na)(*strict*)\n    prefer 2\n    apply(rule_tac\n      m=\"Suc nat\"\n      in GBRA.step_detail_before_some_position)\n      apply(rename_tac nat y na)(*strict*)\n      apply(force)\n     apply(rename_tac nat y na)(*strict*)\n     apply(force)\n    apply(rename_tac nat y na)(*strict*)\n    apply(force)\n   apply(rename_tac nat y na)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac nat y na e1a e2a c1a c2a)(*strict*)\n   apply(rule AX_Bra2LinStep_closed)\n     apply(rename_tac nat y na e1a e2a c1a c2a)(*strict*)\n     apply(force)\n    apply(rename_tac nat y na e1a e2a c1a c2a)(*strict*)\n    apply(rule GBRA.belongs_configurations)\n     apply(rename_tac nat y na e1a e2a c1a c2a)(*strict*)\n     apply(force)\n    apply(rename_tac nat y na e1a e2a c1a c2a)(*strict*)\n    apply(force)\n   apply(rename_tac nat y na e1a e2a c1a c2a)(*strict*)\n   apply(force)\n  apply(rename_tac nat y)(*strict*)\n  apply(simp add: Bra2LinDer'_def)\n  done\n\nlemma Bra2LinDer_prime_closed: \"\n  TSstructure G\n  \\<Longrightarrow> GBRA.derivation G d\n  \\<Longrightarrow> GBRA.belongs G d\n  \\<Longrightarrow> d n \\<noteq> None\n  \\<Longrightarrow> m\\<le>n\n  \\<Longrightarrow> Bra2LinDer' G d n m \\<in> lin_scheduler_fragments G\"\n  apply(induct \"n-m\" arbitrary: n m)\n   apply(rename_tac n m)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac m y)(*strict*)\n   apply(simp add: Bra2LinDer'_def)\n   apply(rule_tac\n      t=\"case m of 0 \\<Rightarrow> [] | Suc m' \\<Rightarrow> nat_seq m m'\"\n      and s=\"[]\"\n      in ssubst)\n    apply(rename_tac m y)(*strict*)\n    apply(case_tac m)\n     apply(rename_tac m y)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac m y nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac y nat)(*strict*)\n    apply (metis lessI nat_seqEmpty)\n   apply(rename_tac m y)(*strict*)\n   apply(rule_tac\n      t=\"nat_seq m m\"\n      and s=\"[m]\"\n      in ssubst)\n    apply(rename_tac m y)(*strict*)\n    apply (metis natUptTo_n_n)\n   apply(rename_tac m y)(*strict*)\n   apply(clarsimp)\n   apply (metis GLIN.AX_empty_scheduler_fragment_in_scheduler_fragments)\n  apply(rename_tac x n m)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x n m y)(*strict*)\n  apply(erule_tac\n      x=\"n\"\n      in meta_allE)\n  apply(erule_tac\n      x=\"Suc m\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d m = Some (pair e1 c1) \\<and> d (Suc m) = Some (pair (Some e2) c2) \\<and> bra_step_relation G c1 e2 c2\")\n   apply(rename_tac x n m y)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"n\"\n      in GBRA.step_detail_before_some_position)\n     apply(rename_tac x n m y)(*strict*)\n     apply(force)\n    apply(rename_tac x n m y)(*strict*)\n    apply(force)\n   apply(rename_tac x n m y)(*strict*)\n   apply(force)\n  apply(rename_tac x n m y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n  apply(erule meta_impE)\n   apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n   apply(force)\n  apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n  apply(erule meta_impE)\n   apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n   apply(force)\n  apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n  apply(case_tac \"n=m\")\n   apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n  apply(rule_tac\n      t=\"Bra2LinDer' G d n m\"\n      and s=\"lin_join_scheduler_fragments (Bra2LinStep c1 e2 c2) (Bra2LinDer' G d n (Suc m))\"\n      in ssubst)\n   apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n   apply(rule Bra2LinDer_prime_pullout_head)\n          apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n          apply(force)\n         apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n         apply(force)\n        apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n        apply(force)\n       apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n       apply(force)\n      apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n      apply(force)\n     apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n     apply(force)\n    apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n   apply(rule GBRA.belongs_configurations)\n    apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n   apply(force)\n  apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n  apply(rule GLIN.AX_join_scheduler_fragments_closed)\n    apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n   apply(rule AX_Bra2LinStep_closed)\n     apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n     apply(force)\n    apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n    apply(rule GBRA.belongs_configurations)\n     apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n     apply(force)\n    apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n   apply(rule GBRA.position_change_due_to_step_relation)\n     apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n     apply(force)\n    apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n   apply(force)\n  apply(rename_tac x n m y e1 e2 c1 c2)(*strict*)\n  apply(force)\n  done\n\nlemma Bra2LinDer_prime_split: \"\n  TSstructure G\n  \\<Longrightarrow> y\\<le>n\n  \\<Longrightarrow> GBRA.derivation G d\n  \\<Longrightarrow> GBRA.belongs G d\n  \\<Longrightarrow> d (n+x) \\<noteq> None\n  \\<Longrightarrow> Bra2LinDer' G d (n + x) y = lin_join_scheduler_fragments (Bra2LinDer' G d n y) (Bra2LinDer' G d (n + x) n)\"\n  apply(subgoal_tac \"Bra2LinDer' G d (n + x) y \\<in> lin_scheduler_fragments G\")\n   prefer 2\n   apply(rule Bra2LinDer_prime_closed)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"Bra2LinDer' G d n y \\<in> lin_scheduler_fragments G\")\n   prefer 2\n   apply(rule Bra2LinDer_prime_closed)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply (metis GBRA.allPreMaxDomSome GBRA.derivationNoFromNone2_prime maximum_of_domain_def le_iff_add less_iff_Suc_add)\n   apply(force)\n  apply(subgoal_tac \"Bra2LinDer' G d (n + x) n \\<in> lin_scheduler_fragments G\")\n   prefer 2\n   apply(rule Bra2LinDer_prime_closed)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(induct \"n-y\" arbitrary: n y)\n   apply(rename_tac n y)(*strict*)\n   apply(simp add: Bra2LinDer'_def)\n   apply(clarsimp)\n   apply(rename_tac y ya)(*strict*)\n   apply(case_tac \"y+x\")\n    apply(rename_tac y ya)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac ya)(*strict*)\n    apply (metis GLIN.AX_join_scheduler_fragments_neutral_left)\n   apply(rename_tac y ya nat)(*strict*)\n   apply(clarsimp)\n   apply(case_tac y)\n    apply(rename_tac y ya nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac ya nat)(*strict*)\n    apply(rule sym)\n    apply(rule GLIN.AX_join_scheduler_fragments_neutral_right)\n     apply(rename_tac ya nat)(*strict*)\n     apply(force)\n    apply(rename_tac ya nat)(*strict*)\n    apply(force)\n   apply(rename_tac y ya nat nata)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac ya nata)(*strict*)\n   apply(rule_tac\n      t=\"nat_seq (Suc nata) nata\"\n      and s=\"[]\"\n      in ssubst)\n    apply(rename_tac ya nata)(*strict*)\n    apply (metis le_refl less_eq_Suc_le_raw nat_seqEmpty)\n   apply(rename_tac ya nata)(*strict*)\n   apply(clarsimp)\n   apply(rule sym)\n   apply(rule GLIN.AX_join_scheduler_fragments_neutral_right)\n    apply(rename_tac ya nata)(*strict*)\n    apply(force)\n   apply(rename_tac ya nata)(*strict*)\n   apply(force)\n  apply(rename_tac xa n y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac xa n y ya)(*strict*)\n  apply(erule_tac\n      x=\"n\"\n      in meta_allE)\n  apply(erule_tac\n      x=\"Suc y\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(erule meta_impE)\n   apply(rename_tac xa n y ya)(*strict*)\n   apply(force)\n  apply(rename_tac xa n y ya)(*strict*)\n  apply(erule meta_impE)\n   apply(rename_tac xa n y ya)(*strict*)\n   apply(force)\n  apply(rename_tac xa n y ya)(*strict*)\n  apply(erule meta_impE)\n   apply(rename_tac xa n y ya)(*strict*)\n   apply(rule Bra2LinDer_prime_closed)\n       apply(rename_tac xa n y ya)(*strict*)\n       apply(force)\n      apply(rename_tac xa n y ya)(*strict*)\n      apply(force)\n     apply(rename_tac xa n y ya)(*strict*)\n     apply(force)\n    apply(rename_tac xa n y ya)(*strict*)\n    apply(force)\n   apply(rename_tac xa n y ya)(*strict*)\n   apply(force)\n  apply(rename_tac xa n y ya)(*strict*)\n  apply(erule meta_impE)\n   apply(rename_tac xa n y ya)(*strict*)\n   apply(rule Bra2LinDer_prime_closed)\n       apply(rename_tac xa n y ya)(*strict*)\n       apply(force)\n      apply(rename_tac xa n y ya)(*strict*)\n      apply(force)\n     apply(rename_tac xa n y ya)(*strict*)\n     apply(force)\n    apply(rename_tac xa n y ya)(*strict*)\n    apply (metis GBRA.allPreMaxDomSome GBRA.derivationNoFromNone_prime GBRA.derivationNoFromNone2 maximum_of_domain_def le_iff_add less_iff_Suc_add)\n   apply(rename_tac xa n y ya)(*strict*)\n   apply(force)\n  apply(rename_tac xa n y ya)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d y = Some (pair e1 c1) \\<and> d (Suc y) = Some (pair (Some e2) c2) \\<and> bra_step_relation G c1 e2 c2\")\n   apply(rename_tac xa n y ya)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"n+x\"\n      in GBRA.step_detail_before_some_position)\n     apply(rename_tac xa n y ya)(*strict*)\n     apply(force)\n    apply(rename_tac xa n y ya)(*strict*)\n    apply(force)\n   apply(rename_tac xa n y ya)(*strict*)\n   apply(force)\n  apply(rename_tac xa n y ya)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n  apply(subgoal_tac \"Bra2LinDer' G d (n+x) y = lin_join_scheduler_fragments (Bra2LinStep c1 e2 c2) (Bra2LinDer' G d (n+x) (Suc y))\")\n   apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n   prefer 2\n   apply(rule Bra2LinDer_prime_pullout_head)\n          apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n          apply(force)\n         apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n         apply(force)\n        apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n        apply(force)\n       apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n       apply(force)\n      apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n      apply(force)\n     apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n     apply(force)\n    apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n   apply(rule GBRA.belongs_configurations)\n    apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n   apply(force)\n  apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"Bra2LinDer' G d n y = lin_join_scheduler_fragments (Bra2LinStep c1 e2 c2) (Bra2LinDer' G d n (Suc y))\")\n   apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n   prefer 2\n   apply(rule Bra2LinDer_prime_pullout_head)\n          apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n          apply(force)\n         apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n         apply(force)\n        apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n        apply(force)\n       apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n       apply(force)\n      apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n      apply (metis GBRA.allPreMaxDomSome GBRA.derivationNoFromNone_prime GBRA.derivationNoFromNone2 maximum_of_domain_def le_iff_add less_iff_Suc_add)\n     apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n     apply(force)\n    apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n   apply(rule GBRA.belongs_configurations)\n    apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n   apply(force)\n  apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n  apply(clarsimp)\n  apply(rule GLIN.AX_join_scheduler_fragments_associative)\n     apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n     apply(force)\n    apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n    apply (metis AX_Bra2LinStep_closed GBRA.belongs_configurations)\n   apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n   apply(rule Bra2LinDer_prime_closed)\n       apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n       apply(force)\n      apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n      apply(force)\n     apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n     apply(force)\n    apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n    apply (metis GBRA.allPreMaxDomSome GBRA.derivationNoFromNone_prime GBRA.derivationNoFromNone2 maximum_of_domain_def le_iff_add less_iff_Suc_add)\n   apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n   apply(force)\n  apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n  apply(rule Bra2LinDer_prime_closed)\n      apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n      apply(force)\n     apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n     apply(force)\n    apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n   apply(force)\n  apply(rename_tac xa n y ya e1 e2 c1 c2)(*strict*)\n  apply(force)\n  done\n\nlemma Bra2LinConf_closed_wrt_Bra2LinDer_prime: \"\n  TSstructure G\n  \\<Longrightarrow> GBRA.derivation G db\n  \\<Longrightarrow> GBRA.belongs G db\n  \\<Longrightarrow> db n = Some (pair e1 c1)\n  \\<Longrightarrow> n\\<le>m\n  \\<Longrightarrow> db m = Some (pair e2 c2)\n  \\<Longrightarrow> Bra2LinConf c1 (lin_extend_scheduler (Bra2LinDer' G db m n) (Bra2LinFin G (bra_get_fixed_scheduler c2))) \\<in> lin_configurations G\"\n  apply(induct \"m-n\" arbitrary: n m e1 c1 e2 c2)\n   apply(rename_tac n m e1 c1 e2 c2)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n e2 c2)(*strict*)\n   apply(simp add: Bra2LinDer'_def)\n   apply(rule_tac\n      t=\"case n of 0 \\<Rightarrow> [] | Suc m' \\<Rightarrow> nat_seq n m'\"\n      and s=\"[]\"\n      in ssubst)\n    apply(rename_tac n e2 c2)(*strict*)\n    apply(case_tac n)\n     apply(rename_tac n e2 c2)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac n e2 c2 nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac e2 c2 nat)(*strict*)\n    apply (metis lessI nat_seqEmpty)\n   apply(rename_tac n e2 c2)(*strict*)\n   apply(clarsimp)\n   apply(rule_tac\n      t=\"lin_extend_scheduler (lin_empty_scheduler_fragment G) (Bra2LinFin G (bra_get_fixed_scheduler c2))\"\n      and s=\"(Bra2LinFin G (bra_get_fixed_scheduler c2))\"\n      in ssubst)\n    apply(rename_tac n e2 c2)(*strict*)\n    apply(rule GLIN.AX_extend_scheduler_left_neutral)\n     apply(rename_tac n e2 c2)(*strict*)\n     apply(force)\n    apply(rename_tac n e2 c2)(*strict*)\n    apply(rule AX_Bra2LinFin_closed)\n     apply(rename_tac n e2 c2)(*strict*)\n     apply(force)\n    apply(rename_tac n e2 c2)(*strict*)\n    apply (metis GBRA.belongs_configurations)\n   apply(rename_tac n e2 c2)(*strict*)\n   apply (metis AX_Bra2LinFin_creates_proper_extension GBRA.belongs_configurations)\n  apply(rename_tac x n m e1 c1 e2 c2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x n m e1 c1 e2 c2)(*strict*)\n  apply(erule_tac\n      x=\"Suc n\"\n      in meta_allE)\n  apply(erule_tac\n      x=\"m\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e c. db (Suc n) = Some (pair (Some e) c)\")\n   apply(rename_tac x n m e1 c1 e2 c2)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n   apply(erule_tac\n      x=\"Some e\"\n      in meta_allE)\n   apply(erule_tac\n      x=\"c\"\n      in meta_allE)\n   apply(erule_tac\n      x=\"e2\"\n      in meta_allE)\n   apply(erule_tac\n      x=\"c2\"\n      in meta_allE)\n   apply(clarsimp)\n   apply(erule meta_impE)\n    apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n    apply(force)\n   apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n   apply(erule meta_impE)\n    apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n    apply(force)\n   apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n   apply(rule_tac\n      t=\"Bra2LinDer' G db m n\"\n      and s=\"lin_join_scheduler_fragments (Bra2LinStep c1 e (c)) (Bra2LinDer' G db m (Suc n))\"\n      in ssubst)\n    apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n    apply(rule Bra2LinDer_prime_pullout_head)\n           apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n           apply(force)\n          apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n          apply(force)\n         apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n         apply(force)\n        apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n        apply(force)\n       apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n       apply(force)\n      apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n      apply(force)\n     apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n     apply(force)\n    apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n    apply(rule GBRA.belongs_configurations)\n     apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n     apply(force)\n    apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n    apply(force)\n   apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n   apply(rule_tac\n      t=\"lin_extend_scheduler (lin_join_scheduler_fragments (Bra2LinStep c1 e (c)) (Bra2LinDer' G db m (Suc n))) (Bra2LinFin G (bra_get_fixed_scheduler c2)) \"\n      and s=\" lin_extend_scheduler (Bra2LinStep c1 e (c)) (lin_extend_scheduler (Bra2LinDer' G db m (Suc n)) (Bra2LinFin G (bra_get_fixed_scheduler c2)))\"\n      in ssubst)\n    apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n    apply(rule GLIN.AX_extend_scheduler_compatible_to_join_scheduler_fragments)\n       apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n       apply(force)\n      apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n      apply(rule AX_Bra2LinStep_closed)\n        apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n        apply(force)\n       apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n       apply(rule GBRA.belongs_configurations)\n        apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n        apply(force)\n       apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n       apply(force)\n      apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n      apply(rule GBRA.position_change_due_to_step_relation)\n        apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n        apply(force)\n       apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n       apply(force)\n      apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n      apply(force)\n     apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n     apply(rule Bra2LinDer_prime_closed)\n         apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n         apply(force)\n        apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n        apply(force)\n       apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n       apply(force)\n      apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n      apply(force)\n     apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n     apply(force)\n    apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n    apply(rule AX_Bra2LinFin_closed)\n     apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n     apply(force)\n    apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n    apply(rule GBRA.belongs_configurations)\n     apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n     apply(force)\n    apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n    apply(force)\n   apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n   apply(rule AX_Bra2LinStep_translates_backwards_Bra2LinConf_closed)\n      apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n      apply(force)\n     apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n     apply(rule GBRA.belongs_configurations)\n      apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n      apply(force)\n     apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n     apply(force)\n    apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n    apply(rule GBRA.position_change_due_to_step_relation)\n      apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n      apply(force)\n     apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n     apply(force)\n    apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n    apply(force)\n   apply(rename_tac x n m e1 c1 e2 c2 e c)(*strict*)\n   apply(force)\n  apply(rename_tac x n m e1 c1 e2 c2)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. db (Suc n) = Some (pair (Some e) c)\")\n   apply(rename_tac x n m e1 c1 e2 c2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"m\"\n      in GBRA.pre_some_position_is_some_position_prime)\n      apply(rename_tac x n m e1 c1 e2 c2)(*strict*)\n      apply(force)\n     apply(rename_tac x n m e1 c1 e2 c2)(*strict*)\n     apply(force)\n    apply(rename_tac x n m e1 c1 e2 c2)(*strict*)\n    apply(force)\n   apply(rename_tac x n m e1 c1 e2 c2)(*strict*)\n   apply(force)\n  apply(rename_tac x n m e1 c1 e2 c2)(*strict*)\n  apply(simp add: Lin2BraDer_def derivation_map_def)\n  done\n\nlemma AX_Bra2LinConf_preserves_history_lift: \"\n  TSstructure G\n  \\<Longrightarrow> GBRA.derivation G d\n  \\<Longrightarrow> GBRA.belongs G d\n  \\<Longrightarrow> d i = Some (pair e c)\n  \\<Longrightarrow> d n \\<noteq> None\n  \\<Longrightarrow> i\\<le>n\n  \\<Longrightarrow> lin_get_history (the(get_configuration(Bra2LinDer G d n i))) = bra_get_history c\"\n  apply(simp add: Bra2LinDer_def get_configuration_def)\n  apply(case_tac \"d n\")\n   apply(clarsimp)\n  apply(rename_tac a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac option b)(*strict*)\n  apply(rule AX_Bra2LinConf_preserves_history)\n     apply(rename_tac option b)(*strict*)\n     apply(force)\n    apply(rename_tac option b)(*strict*)\n    apply (metis GBRA.belongs_configurations)\n   apply(rename_tac option b)(*strict*)\n   apply (metis Bra2LinDer_prime_closed AX_Bra2LinFin_closed GBRA.belongs_configurations GBRA.derivationNoFromNone GBRA.derivationNoFromNone2 GLIN.AX_extend_scheduler_closed lessI)\n  apply(rename_tac option b)(*strict*)\n  apply (metis Bra2LinConf_closed_wrt_Bra2LinDer_prime)\n  done\n\nlemma AX_Lin2BraConf_preserves_history_lift: \"\n  TSstructure G\n  \\<Longrightarrow> GLIN.derivation G d\n  \\<Longrightarrow> GLIN.belongs G d\n  \\<Longrightarrow> d n = Some (pair e c)\n  \\<Longrightarrow> lin_get_history c = bra_get_history (Lin2BraConf c)\"\n  apply(rule AX_Lin2BraConf_preserves_history)\n   apply(force)+\n  apply (metis GLIN.belongs_configurations)\n  done\n\nend\n\nend\n\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_06_06/L_ATS_Branching_Versus_Linear1.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631556226292, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.2895998946708848}}
{"text": "(*<*)\n(*\n * Knowledge-based programs.\n * (C)opyright 2011, Peter Gammie, peteg42 at gmail.com.\n * License: BSD\n *)\n\ntheory ClockView\nimports\n  KBPsAlg\n  Eval\n  List_local\n  ODList\n  Trie2\n  \"Transitive-Closure.Transitive_Closure_List_Impl\"\n  \"HOL-Library.Mapping\"\nbegin\n(*>*)\n\nsubsection\\<open>The Clock View\\<close>\n\ntext\\<open>\n\n\\label{sec:kbps-theory-clock-view}\n\nThe \\emph{clock view} records the current time and the observation for\nthe most recent state:\n\n\\<close>\n\ndefinition (in Environment)\n  clock_jview :: \"('a, 's, nat \\<times> 'obs) JointView\"\nwhere\n  \"clock_jview \\<equiv> \\<lambda>a t. (tLength t, envObs a (tLast t))\"\n(*<*)\n\ncontext Environment\nbegin\n\nlemma clock_jview_tInit:\n  \"clock_jview a (tInit s) = (0, envObs a s)\"\n  unfolding clock_jview_def by simp\n\nlemma clock_jview_tStep:\n  \"clock_jview a (t \\<leadsto> s) = (Suc (tLength t), envObs a s)\"\n  unfolding clock_jview_def by simp\n\nlemma clock_jview_tStepI[intro]:\n  \"\\<lbrakk> tLength t = Suc n; envObs a (tLast t) = obs \\<rbrakk>\n     \\<Longrightarrow> clock_jview a t = (Suc n, obs)\"\n  unfolding clock_jview_def by (cases t) simp_all\n\nlemma clock_jview_inv:\n  \"clock_jview a t = (n, obs) \\<Longrightarrow> envObs a (tLast t) = obs\"\n  unfolding clock_jview_def by (cases t) simp_all\n\nlemmas clock_jview_simps =\n  clock_jview_tInit\n  clock_jview_tStep\n  clock_jview_inv\n\nlemma clock_jview_eq_inv[iff]:\n  \"clock_jview a t' = clock_jview a t\n    \\<longleftrightarrow> tLength t' = tLength t \\<and> envObs a (tLast t') = envObs a (tLast t)\"\n  by (fastforce simp: clock_jview_def)\n\nend(*>*)\n\ntext\\<open>\n\nThis is the least-information synchronous view, given the requirements\nof \\S\\ref{sec:kbps-views}. We show that finite-state implementations\nexist for all environments with respect to this view as per\n\\citet{Ron:1996}.\n\nThe corresponding incremental view simply increments the counter\nrecords the new observation.\n\n\\<close>\n\ndefinition (in Environment)\n  clock_jviewInit :: \"'a \\<Rightarrow> 'obs \\<Rightarrow> nat \\<times> 'obs\"\nwhere\n  \"clock_jviewInit \\<equiv> \\<lambda>a obs. (0, obs)\"\n\ndefinition (in Environment)\n  clock_jviewIncr :: \"'a \\<Rightarrow> 'obs \\<Rightarrow> nat \\<times> 'obs \\<Rightarrow> nat \\<times> 'obs\"\nwhere\n  \"clock_jviewIncr \\<equiv> \\<lambda>a obs' (l, obs). (l + 1, obs')\"\n\ntext\\<open>\n\nIt is straightforward to demonstrate the assumptions of the\nincremental environment locale (\\S\\ref{sec:kbps-environments}) with\nrespect to an arbitrary environment.\n\n\\<close>\n\nsublocale Environment\n        < Clock: IncrEnvironment jkbp envInit envAction envTrans envVal\n                        clock_jview envObs clock_jviewInit clock_jviewIncr\n(*<*)\n  apply (unfold_locales)\n  apply (simp_all add: clock_jviewInit_def clock_jviewIncr_def clock_jview_def)\n  done\n\n(*>*)\ntext\\<open>\n\nAs we later show, satisfaction of a formula at a trace \\<open>t \\<in>\nClock.jkbpC\\<^bsub>n\\<^esub>\\<close> is determined by the set of final states of traces in\n\\<open>Clock.jkbpCn\\<close>:\n\n\\<close>\n\ncontext Environment\nbegin\n\nabbreviation clock_commonAbs :: \"'s Trace \\<Rightarrow> 's set\" where\n  \"clock_commonAbs t \\<equiv> tLast ` Clock.jkbpCn (tLength t)\"\n\ntext\\<open>\n\nIntuitively this set contains the states that the agents commonly\nconsider possible at time @{term \"n\"}, which is sufficient for\ndetermining knowledge as the clock view ignores paths. Therefore we\ncan simulate trace @{term \"t\"} by pairing this abstraction of @{term\n\"t\"} with its final state:\n\n\\<close>\n\ntype_synonym (in -) 's clock_simWorlds = \"'s set \\<times> 's\"\n\ndefinition clock_sim :: \"'s Trace \\<Rightarrow> 's clock_simWorlds\" where\n  \"clock_sim \\<equiv> \\<lambda>t. (clock_commonAbs t, tLast t)\"\n\ntext\\<open>\n\nIn the Kripke structure for our simulation, we relate worlds for\n@{term \"a\"} if the sets of commonly-held states coincide, and the\nobservation of the final states of the traces is the\nsame. Propositions are evaluated at the final state.\n\n\\<close>\n\ndefinition clock_simRels :: \"'a \\<Rightarrow> 's clock_simWorlds Relation\" where\n  \"clock_simRels \\<equiv> \\<lambda>a. { ((X, s), (X', s')) |X X' s s'.\n                          X = X' \\<and> {s, s'} \\<subseteq> X \\<and> envObs a s = envObs a s' }\"\n\ndefinition clock_simVal :: \"'s clock_simWorlds \\<Rightarrow> 'p \\<Rightarrow> bool\" where\n  \"clock_simVal \\<equiv> envVal \\<circ> snd\"\n\nabbreviation clock_simMC :: \"('a, 'p, 's clock_simWorlds) KripkeStructure\" where\n  \"clock_simMC \\<equiv> mkKripke (clock_sim ` Clock.jkbpC) clock_simRels clock_simVal\"\n(*<*)\n\nlemma clock_simVal_def2[iff]: \"clock_simVal (clock_sim t) = envVal (tLast t)\"\n  unfolding clock_sim_def clock_simVal_def by simp\n\nlemma clock_sim_range:\n  \"sim_range Clock.MC clock_simMC clock_sim\"\n  by (rule sim_rangeI) (simp_all add: clock_sim_def)\n\nlemma clock_simVal:\n  \"sim_val Clock.MC clock_simMC clock_sim\"\n  by (rule sim_valI) (simp add: clock_simVal_def clock_sim_def)\n\nlemma clock_sim_f:\n  \"sim_f Clock.MC clock_simMC clock_sim\"\napply (rule sim_fI)\napply (simp add: clock_simRels_def clock_sim_def)\napply (intro conjI)\n   apply (fastforce intro!: imageI)\n  apply (fastforce intro!: imageI)\n apply (fastforce dest: Clock.mkM_simps(2))\napply (rule_tac x=v in image_eqI)\n apply simp_all\ndone\n\nlemma clock_sim_r:\n  \"sim_r Clock.MC clock_simMC clock_sim\"\n  apply (rule sim_rI)\n  apply (clarsimp simp: clock_simRels_def clock_sim_def cong del: image_cong_simp)\n  apply (rule_tac x=xa in exI)\n  unfolding Clock.mkM_def\n  apply auto\n  done\n\n(*>*)\ntext\\<open>\n\nThat this is in fact a simulation\n(\\S\\ref{sec:kripke-theory-simulations}) is entirely straightforward.\n\n\\<close>\n\nlemma clock_sim:\n  \"sim Clock.MC clock_simMC clock_sim\"\n(*<*)\n  using clock_sim_range clock_simVal clock_sim_f clock_sim_r\n  unfolding sim_def\n  by blast\n(*>*)\n\nend (* context Environment *)\n\ntext\\<open>\n\nThe \\<open>SimIncrEnvironment\\<close> of\n\\S\\ref{sec:kbps-theory-automata-env-sims} only requires that we\nprovide it an @{term \"Environment\"} and a simulation.\n\n\\<close>\n\nsublocale Environment\n        < Clock: SimIncrEnvironment jkbp envInit envAction envTrans envVal\n                  clock_jview envObs clock_jviewInit clock_jviewIncr\n                  clock_sim clock_simRels clock_simVal\n(*<*)\n  by (unfold_locales, simp_all add: clock_sim)\n(*>*)\n\ntext\\<open>\n\nWe next consider algorithmic issues.\n\n\\<close>\n\n(* **************************************** *)\n\nsubsubsection\\<open>Representations\\<close>\n\ntext\\<open>\n\n\\label{sec:kbps-theory-clock-view-rep}\n\nWe now turn to the issue of how to represent equivalence classes of\nstates. As these are used as map keys, it is easiest to represent them\ncanonically. A simple approach is to use \\emph{ordered distinct lists}\nof type @{typ \"'a odlist\"} for the sets and \\emph{tries} for the\nmaps. Therefore we ask that environment states @{typ \"'s\"} belong to\nthe class \\<open>linorder\\<close> of linearly-ordered types, and moreover\nthat the set \\<open>agents\\<close> be effectively presented. We introduce a\nnew locale capturing these requirements:\n\n\\<close>\n\nlocale FiniteLinorderEnvironment =\n  Environment jkbp envInit envAction envTrans envVal envObs\n    for jkbp :: \"('a::{finite, linorder}, 'p, 'aAct) JKBP\"\n    and envInit :: \"('s::{finite, linorder}) list\"\n    and envAction :: \"'s \\<Rightarrow> 'eAct list\"\n    and envTrans :: \"'eAct \\<Rightarrow> ('a \\<Rightarrow> 'aAct) \\<Rightarrow> 's \\<Rightarrow> 's\"\n    and envVal :: \"'s \\<Rightarrow> 'p \\<Rightarrow> bool\"\n    and envObs :: \"'a \\<Rightarrow> 's \\<Rightarrow> 'obs\"\n+ fixes agents :: \"'a odlist\"\n  assumes agents: \"ODList.toSet agents = UNIV\"\n\ncontext FiniteLinorderEnvironment\nbegin\n\ntext\\<open>\n\n\\label{sec:kbps-theory-clock-view-algops}\n\nFor a fixed agent @{term \"a\"}, we can reduce the number of worlds in\n@{term \"clock_simMC\"} by taking its quotient with respect to the\nequivalence relation for @{term \"a\"}. In other words, we represent a\nsimulated equivalence class by a pair of the set of all states\nreachable at a particular time, and the subset of these that @{term\n\"a\"} considers possible. The worlds in our representational Kripke\nstructure are therefore a pair of ordered, distinct lists:\n\n\\<close>\n\ntype_synonym (in -) 's clock_simWorldsRep = \"'s odlist \\<times> 's odlist\"\n\ntext\\<open>\n\nWe can readily abstract a representation to a set of simulated\nequivalence classes:\n\n\\<close>\n\ndefinition (in -)\n  clock_simAbs :: \"'s::linorder clock_simWorldsRep \\<Rightarrow> 's clock_simWorlds set\"\nwhere\n  \"clock_simAbs X \\<equiv> { (ODList.toSet (fst X), s) |s. s \\<in> ODList.toSet (snd X) }\"\n\ntext\\<open>\n\nAssuming @{term \"X\"} represents a simulated equivalence class for\n@{term \"t \\<in> jkbpC\"}, @{term \"clock_simAbs X\"} decomposes into these\ntwo functions:\n\n\\<close>\n\ndefinition\n  agent_abs :: \"'a \\<Rightarrow> 's Trace \\<Rightarrow> 's set\"\nwhere\n  \"agent_abs a t \\<equiv>\n     { tLast t' |t'. t' \\<in> Clock.jkbpC \\<and> clock_jview a t' = clock_jview a t}\"\n\ndefinition\n  common_abs :: \"'s Trace \\<Rightarrow> 's set\"\nwhere\n  \"common_abs t \\<equiv> tLast ` Clock.jkbpCn (tLength t)\"\n(*<*)\n\nlemma aec_refl[intro, simp]:\n  \"t \\<in> Clock.jkbpC \\<Longrightarrow> tLast t \\<in> agent_abs a t\"\n  unfolding agent_abs_def by auto\n\nlemma aec_cec_subset:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and aec: \"ODList.toSet aec = agent_abs a t\"\n      and cec: \"ODList.toSet cec = common_abs t\"\n  shows \"x \\<in> ODList.toSet aec \\<Longrightarrow> x \\<in> ODList.toSet cec\"\n  using assms\n  unfolding agent_abs_def common_abs_def\n  by fastforce\n\nlemma clock_simAbs_refl:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and ec: \"clock_simAbs ec = Clock.sim_equiv_class a t\"\n  shows \"clock_sim t \\<in> clock_simAbs ec\"\n  using assms by simp\n\nlemma common_abs:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n  assumes ec: \"clock_simAbs ec = Clock.sim_equiv_class a t\"\n  shows \"ODList.toSet (fst ec) = common_abs t\"\n  using tC clock_simAbs_refl[OF tC ec]\n  unfolding clock_sim_def clock_simAbs_def common_abs_def\n  by (auto simp: ODList.toSet_def[symmetric])\n\nlemma agent_abs:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n  assumes ec: \"clock_simAbs ec = Clock.sim_equiv_class a t\"\n  shows \"ODList.toSet (snd ec) = agent_abs a t\"\n  using assms\n  unfolding clock_sim_def clock_simAbs_def agent_abs_def\n  apply auto\n  apply (subgoal_tac \"(ODList.toSet (fst ec), x) \\<in> {(ODList.toSet (fst ec), s) |s. s \\<in> ODList.toSet (snd ec)}\")\n  apply auto (* FIXME filthy *)\n  done\n\n(*>*)\ntext\\<open>\n\nThis representation is canonical on the domain of interest (though not\nin general):\n\n\\<close>\n\nlemma clock_simAbs_inj_on:\n  \"inj_on clock_simAbs { x . clock_simAbs x \\<in> Clock.jkbpSEC }\"\n(*<*)\nproof(rule inj_onI)\n  fix x y\n  assume x: \"x \\<in> { x . clock_simAbs x \\<in> Clock.jkbpSEC }\"\n     and y: \"y \\<in> { x . clock_simAbs x \\<in> Clock.jkbpSEC }\"\n     and xy: \"clock_simAbs x = clock_simAbs y\"\n  from x obtain a t\n    where tC: \"t \\<in> Clock.jkbpC\"\n      and ec: \"clock_simAbs x = Clock.sim_equiv_class a t\"\n    by auto\n  from common_abs[OF tC ec] common_abs[OF tC trans[OF xy[symmetric] ec], symmetric]\n  have \"fst x = fst y\" by (blast intro: injD[OF toSet_inj])\n  moreover\n  from agent_abs[OF tC ec] agent_abs[OF tC trans[OF xy[symmetric] ec], symmetric]\n  have \"snd x = snd y\" by (blast intro: injD[OF toSet_inj])\n  ultimately show \"x = y\" by (simp add: prod_eqI)\nqed\n(*>*)\ntext\\<open>\n\nWe could further compress this representation by labelling each\nelement of the set of states reachable at time $n$ with a bit to\nindicate whether the agent considers that state possible.  Note,\nhowever, that the representation would be non-canonical: if \\<open>(s, True)\\<close> is in the representation, indicating that the agent\nconsiders \\<open>s\\<close> possible, then \\<open>(s, False)\\<close> may or may\nnot be. The associated abstraction function is not injective and hence\nwould obfuscate the following. Repairing this would entail introducing\na new type, which would again complicate this development.\n\n\n\nThe following lemmas make use of this Kripke structure, constructed\nfrom the set of final states of a temporal slice @{term \"X\"}:\n\n\\<close>\n\ndefinition\n  clock_repRels :: \"'a \\<Rightarrow> ('s \\<times> 's) set\"\nwhere\n  \"clock_repRels \\<equiv> \\<lambda>a. { (s, s'). envObs a s = envObs a s' }\"\n\nabbreviation\n  clock_repMC :: \"'s set \\<Rightarrow> ('a, 'p, 's) KripkeStructure\"\nwhere\n  \"clock_repMC \\<equiv> \\<lambda>X. mkKripke X clock_repRels envVal\"\n(*<*)\n\nlemma clock_repMC_kripke[intro, simp]: \"kripke (clock_repMC X)\"\n  by (rule kripkeI) simp\n\nlemma clock_repMC_S5n[intro, simp]: \"S5n (clock_repMC X)\"\n  unfolding clock_repRels_def\n  by (intro S5nI equivI refl_onI symI transI) auto\n\n(*>*)\ntext\\<open>\n\nWe can show that this Kripke structure retains sufficient information\nfrom @{term \"Clock.MCS\"} by showing simulation. This is eased by\nintroducing an intermediary structure that focusses on a particular\ntrace:\n\n\\<close>\n\nabbreviation\n  clock_jkbpCSt :: \"'b Trace \\<Rightarrow> 's clock_simWorlds set\"\nwhere\n  \"clock_jkbpCSt t \\<equiv> clock_sim ` Clock.jkbpCn (tLength t)\"\n\nabbreviation\n  clock_simMCt :: \"'b Trace \\<Rightarrow> ('a, 'p, 's clock_simWorlds) KripkeStructure\"\nwhere\n  \"clock_simMCt t \\<equiv> mkKripke (clock_jkbpCSt t) clock_simRels clock_simVal\"\n\ndefinition clock_repSim :: \"'s clock_simWorlds \\<Rightarrow> 's\" where\n  \"clock_repSim \\<equiv> snd\"\n(*<*)\n\nlemma jkbpCSt_jkbpCS_subset:\n  \"clock_jkbpCSt t \\<subseteq> clock_sim ` Clock.jkbpC\"\n  by auto\n\nlemma jkbpCSt_refl[iff]:\n  \"t \\<in> Clock.jkbpC \\<Longrightarrow> clock_sim t \\<in> clock_jkbpCSt t\"\n  by blast\n\nlemma fst_clock_sim[iff]:\n  \"t \\<in> Clock.jkbpC \\<Longrightarrow> fst (clock_sim t) = tLast ` Clock.jkbpCn (tLength t)\"\n  by (simp add: clock_sim_def)\n\nlemma clock_repSim_simps[simp]:\n  \"clock_repSim ` clock_sim ` T = tLast ` T\"\n  \"clock_repSim (clock_sim t) = tLast t\"\n  unfolding clock_repSim_def clock_sim_def\n  by (auto intro!: image_eqI)\n\n(*>*)\ntext\\<open>\\<close>\n\nlemma clock_repSim:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n  shows \"sim (clock_simMCt t)\n             ((clock_repMC \\<circ> fst) (clock_sim t))\n             clock_repSim\"\n(*<*) (is \"sim ?M ?M' ?f\")\nproof\n  show \"sim_range ?M ?M' ?f\"\n  proof\n    show \"worlds ?M' = ?f ` worlds ?M\"\n      unfolding clock_sim_def clock_repSim_def by force\n  next\n    fix a\n    show \"relations ?M' a \\<subseteq> worlds ?M' \\<times> worlds ?M'\"\n      by (simp add: clock_sim_def clock_repSim_def)\n  qed\nnext\n  show \"sim_val ?M ?M' ?f\"\n    by (rule, simp add: clock_sim_def clock_simVal_def clock_repSim_def split: prod.split)\nnext\n  show \"sim_f ?M ?M' ?f\"\n    apply rule\n    unfolding clock_repRels_def clock_repSim_def clock_simRels_def\n    apply (auto iff: clock_sim_def)\n    done\nnext\n  show \"sim_r ?M ?M' ?f\"\n    apply rule\n    unfolding clock_repRels_def clock_repSim_def clock_simRels_def clock_sim_def\n    apply clarsimp\n    done\nqed\n\n(*>*)\ntext\\<open>\n\nThe following sections show how we satisfy the remaining requirements\nof the \\<open>Algorithm\\<close> locale of\nFigure~\\ref{fig:kbps-alg-alg-locale}. Where the proof is routine, we\nsimply present the lemma without proof or comment.\n\nDue to a limitation in the code generator in the present version of\nIsabelle (2011), we need to define the equations we wish to execute\noutside of a locale; the syntax \\<open>(in -)\\<close> achieves this by\nmaking definitons at the theory top-level. We then define (but elide)\nlocale-local abbreviations that supply the locale-bound variables to\nthese definitions.\n\n\\<close>\n\n(* **************************************** *)\n\nsubsubsection\\<open>Initial states\\<close>\n\ntext\\<open>\n\nThe initial states of the automaton for an agent is simply @{term\n\"envInit\"} paired with the partition of @{term \"envInit\"} under the\nagent's observation.\n\n\\<close>\n\ndefinition (in -)\n  clock_simInit :: \"('s::linorder) list \\<Rightarrow> ('a \\<Rightarrow> 's \\<Rightarrow> 'obs)\n                \\<Rightarrow> 'a \\<Rightarrow> 'obs \\<Rightarrow> 's clock_simWorldsRep\"\nwhere\n  \"clock_simInit envInit envObs \\<equiv> \\<lambda>a iobs.\n    let cec = ODList.fromList envInit\n     in (cec, ODList.filter (\\<lambda>s. envObs a s = iobs) cec)\"\n(*<*)\n\nabbreviation\n  clock_simInit :: \"'a \\<Rightarrow> 'obs \\<Rightarrow> 's clock_simWorldsRep\"\nwhere\n  \"clock_simInit \\<equiv> ClockView.clock_simInit envInit envObs\"\n\n(*>*)\ntext\\<open>\\<close>\n\nlemma clock_simInit:\n  assumes \"iobs \\<in> envObs a ` set envInit\"\n  shows \"clock_simAbs (clock_simInit a iobs)\n       = clock_sim ` { t' \\<in> Clock.jkbpC.\n                       clock_jview a t' = clock_jviewInit a iobs }\"\n(*<*)\n  using assms\n  unfolding clock_simInit_def clock_simAbs_def clock_sim_def [abs_def] Let_def\n  apply clarsimp\n  apply rule\n   apply clarsimp\n   apply (rule_tac x=\"tInit s\" in image_eqI)\n    apply (auto simp: Set.image_def Clock.jviewInit)[2]\n  apply clarsimp\n  apply (case_tac xa)\n   apply clarsimp\n   apply rule\n    apply rule\n     apply clarsimp\n    apply clarsimp\n    apply (rule_tac x=\"tInit xa\" in image_eqI)\n    apply (auto intro!: image_eqI simp: Clock.jviewInit)\n  done\n(*>*)\n\n(* **************************************** *)\n\nsubsubsection\\<open>Simulated observations\\<close>\n\ntext\\<open>\n\nAgent @{term \"a\"} will make the same observation at any of the worlds\nthat it considers possible, so we choose the first one in the list:\n\n\\<close>\n\ndefinition (in -)\n  clock_simObs :: \"('a \\<Rightarrow> ('s :: linorder) \\<Rightarrow> 'obs)\n                \\<Rightarrow> 'a \\<Rightarrow> 's clock_simWorldsRep \\<Rightarrow> 'obs\"\nwhere\n  \"clock_simObs envObs \\<equiv> \\<lambda>a. envObs a \\<circ> ODList.hd \\<circ> snd\"\n(*<*)\n\nabbreviation\n  clock_simObs :: \"'a \\<Rightarrow> 's clock_simWorldsRep \\<Rightarrow> 'obs\"\nwhere\n  \"clock_simObs \\<equiv> ClockView.clock_simObs envObs\"\n\n(*>*)\ntext\\<open>\\<close>\n\nlemma clock_simObs:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and ec: \"clock_simAbs ec = Clock.sim_equiv_class a t\"\n  shows \"clock_simObs a ec = envObs a (tLast t)\"\n(*<*)\nproof -\n  have A: \"\\<forall>s \\<in> set (toList (snd ec)). envObs a s = envObs a (tLast t)\"\n    using agent_abs[OF tC ec]\n    by (clarsimp simp: agent_abs_def toSet_def)\n  have B: \"tLast t \\<in> set (toList (snd ec))\"\n    using clock_simAbs_refl[OF assms]\n    unfolding clock_simAbs_def clock_sim_def\n    by (simp add: toSet_def snd_def)\n  show ?thesis\n    unfolding clock_simObs_def by (simp add: list_choose_hd[OF A B] ODList.hd_def)\nqed\n(*>*)\n\n(* **************************************** *)\n\nsubsubsection\\<open>Evaluation\\<close>\n\ntext\\<open>\n\n\\label{sec:kbps-theory-clock-view-eval}\n\nWe define our \\<open>eval\\<close> function in terms of @{term \"evalS\"},\nwhich implements boolean logic over @{typ \"'s odlist\"} in the usual\nway -- see \\S\\ref{sec:kbps-spr-single-agent-eval} for the relevant\nclauses. It requires three functions specific to the representation:\none each for propositions, knowledge and common knowledge.\n\nPropositions define subsets of the worlds considered possible:\n\n\\<close>\n\nabbreviation (in -)\n  clock_evalProp :: \"(('s::linorder) \\<Rightarrow> 'p \\<Rightarrow> bool)\n                  \\<Rightarrow> 's odlist \\<Rightarrow> 'p \\<Rightarrow> 's odlist\"\nwhere\n  \"clock_evalProp envVal \\<equiv> \\<lambda>X p. ODList.filter (\\<lambda>s. envVal s p) X\"\n\ntext\\<open>\n\nThe knowledge relation computes the subset of the\ncommonly-held-possible worlds \\<open>cec\\<close> that agent @{term \"a\"}\nconsiders possible at world @{term \"s\"}:\n\n\\<close>\n\ndefinition (in -)\n  clock_knowledge :: \"('a \\<Rightarrow> ('s :: linorder) \\<Rightarrow> 'obs) \\<Rightarrow> 's odlist\n                  \\<Rightarrow> 'a \\<Rightarrow> 's \\<Rightarrow> 's odlist\"\nwhere\n  \"clock_knowledge envObs cec \\<equiv> \\<lambda>a s.\n     ODList.filter (\\<lambda>s'. envObs a s = envObs a s') cec\"\n\ntext\\<open>\n\n\nSimilarly the common knowledge operation computes the transitive\nclosure of the union of the knowledge relations for the agents \\<open>as\\<close>:\n\n\\<close>\n\ndefinition (in -)\n  clock_commonKnowledge :: \"('a \\<Rightarrow> ('s :: linorder) \\<Rightarrow> 'obs) \\<Rightarrow> 's odlist\n           \\<Rightarrow> 'a list \\<Rightarrow> 's \\<Rightarrow> 's odlist\"\nwhere\n  \"clock_commonKnowledge envObs cec \\<equiv> \\<lambda>as s.\n     let r = \\<lambda>a. ODList.fromList [ (s', s'') . s' \\<leftarrow> toList cec, s'' \\<leftarrow> toList cec,\n                                   envObs a s' = envObs a s'' ];\n         R = toList (ODList.big_union r as)\n      in ODList.fromList (memo_list_trancl R s)\"\n\ntext\\<open>\n\nThe function \\<open>memo_list_trancl\\<close> comes from the executable\ntransitive closure theory of \\citep{AFP:TRANCL}.\n\nThe evaluation function evaluates a subjective knowledge formula on\nthe representation of an equivalence class:\n\n\\<close>\n\ndefinition (in -)\n  eval :: \"(('s :: linorder) \\<Rightarrow> 'p \\<Rightarrow> bool)\n        \\<Rightarrow> ('a \\<Rightarrow> 's \\<Rightarrow> 'obs)\n        \\<Rightarrow> 's clock_simWorldsRep \\<Rightarrow> ('a, 'p) Kform \\<Rightarrow> bool\"\nwhere\n  \"eval envVal envObs \\<equiv> \\<lambda>(cec, aec). evalS (clock_evalProp envVal)\n                                      (clock_knowledge envObs cec)\n                                      (clock_commonKnowledge envObs cec)\n                                      aec\"\n\ntext\\<open>\n\nThis function corresponds with the standard semantics:\n\n\\<close>\n(*<*)\n\nlemma clock_coEC_relation_image:\n  \"s \\<in> ODList.toSet Y\n    \\<Longrightarrow> ODList.toSet (clock_knowledge envObs Y a s) = relations (clock_repMC (ODList.toSet Y)) a `` {s}\"\n  unfolding clock_knowledge_def clock_repRels_def Image_def\n  by auto\n\nlemma clock_commonKnowledge_relation_image_aux:\n  \"(\\<Union>x\\<in>set as. \\<Union>a\\<in>ODList.toSet Y. \\<Union>aa\\<in>ODList.toSet Y \\<inter> {s''. envObs x a = envObs x s''}. {(a, aa)})\n = ((\\<Union>a\\<in>set as. {(s, s'). envObs a s = envObs a s'}) \\<inter> ODList.toSet Y \\<times> ODList.toSet Y)\"\n  by auto\n\nlemma clock_commonKnowledge_relation_image:\n  \"s \\<in> ODList.toSet Y\n    \\<Longrightarrow> ODList.toSet (clock_commonKnowledge envObs Y as s) = (\\<Union>a \\<in> set as. relations (clock_repMC (ODList.toSet Y)) a)\\<^sup>+ `` {s}\"\n  unfolding clock_commonKnowledge_def clock_repRels_def Let_def\n  apply (simp add: memo_list_trancl toSet_def[symmetric] Image_def clock_commonKnowledge_relation_image_aux)\n  done\n\nlemma eval_rec_models:\n  assumes XY: \"ODList.toSet X \\<subseteq> ODList.toSet Y\"\n      and s: \"s \\<in> ODList.toSet X\"\n  shows \"s \\<in> ODList.toSet (eval_rec (clock_evalProp envVal) (clock_knowledge envObs Y) (clock_commonKnowledge envObs Y) X \\<phi>)\n     \\<longleftrightarrow> clock_repMC (ODList.toSet Y), s \\<Turnstile> \\<phi>\"\nusing XY s\nproof(induct \\<phi> arbitrary: X s)\n  case (Kknows a' \\<phi> X s)\n  from \\<open>s \\<in> ODList.toSet X\\<close> clock_coEC_relation_image[OF subsetD[OF Kknows(2) Kknows(3)], where a=a']\n  show ?case\n    apply simp\n    apply rule\n     apply (drule arg_cong[where f=\"ODList.toSet\"])\n     apply (clarsimp simp: odlist_all_iff)\n     apply (cut_tac s3=\"w'\" and X3=\"clock_knowledge envObs Y a' s\" in Kknows.hyps)\n      using Kknows(2) Kknows(3)\n      apply (auto simp add: S5n_rels_closed[OF clock_repMC_S5n])[3]\n\n    apply (clarsimp simp: toSet_eq_iff odlist_all_iff)\n    apply (subst Kknows.hyps)\n      using Kknows(2) Kknows(3)\n      apply (auto simp add: S5n_rels_closed[OF clock_repMC_S5n])\n    done\nnext\n  case (Kcknows as \\<phi> X s)\n  show ?case\n  proof(cases \"as = Nil\")\n    case True with \\<open>s \\<in> ODList.toSet X\\<close> show ?thesis by clarsimp\n  next\n    case False\n    with \\<open>s \\<in> ODList.toSet X\\<close> clock_commonKnowledge_relation_image[OF subsetD[OF Kcknows(2) Kcknows(3)], where as=as]\n    show ?thesis\n      apply simp\n      apply rule\n       apply (drule arg_cong[where f=\"ODList.toSet\"])\n       apply (clarsimp simp: odlist_all_iff)\n       apply (cut_tac s3=\"w'\" and X3=\"clock_commonKnowledge envObs Y as s\" in Kcknows.hyps)\n        using Kcknows(2) Kcknows(3)\n        apply (auto simp add: S5n_rels_closed[OF clock_repMC_S5n])[3]\n        apply (subst (asm) trancl_unfold) back back back\n        apply auto[1] (* FIXME disgusting *)\n\n      apply (clarsimp simp: toSet_eq_iff odlist_all_iff)\n      apply (subst Kcknows.hyps)\n       using Kcknows(2) Kcknows(3)\n       apply (auto simp add: S5n_rels_closed[OF clock_repMC_S5n])\n        apply (subst (asm) trancl_unfold) back back back\n        apply auto[1] (* FIXME disgusting *)\n\n      done\n  qed\nqed simp_all\n\nlemma trc_aux:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and aec: \"ODList.toSet aec = agent_abs a t\"\n      and cec: \"ODList.toSet cec = common_abs t\"\n  shows \"ODList.toSet (big_union (clock_commonKnowledge envObs cec as) (toList aec)) \\<subseteq> ODList.toSet cec\"\n  apply (clarsimp simp: toSet_def[symmetric])\n  apply (subst (asm) clock_commonKnowledge_relation_image)\n   apply (erule aec_cec_subset[OF tC aec cec])\n  apply (subst (asm) trancl_unfold)\n  using assms\n  apply (auto simp: agent_abs_def)\n  done\n\nlemma clock_repMC_aec:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and aec: \"ODList.toSet aec = agent_abs a t\"\n      and cec: \"ODList.toSet cec = common_abs t\"\n      and x: \"x \\<in> ODList.toSet aec\"\n      and xy: \"(x, y) \\<in> relations (clock_repMC (ODList.toSet cec)) a\"\n  shows \"y \\<in> ODList.toSet aec\"\n  using assms\n  unfolding clock_repRels_def agent_abs_def common_abs_def\n  by auto\n\nlemma clock_repMC_cec:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and aec: \"ODList.toSet aec = agent_abs a t\"\n      and cec: \"ODList.toSet cec = common_abs t\"\n      and x: \"x \\<in> ODList.toSet aec\"\n      and y: \"y \\<in> ODList.toSet aec\"\n  shows \"(x, y) \\<in> relations (clock_repMC (ODList.toSet cec)) a\"\n  using assms\n  unfolding clock_repRels_def agent_abs_def common_abs_def\n  by auto\n\nlemma evalS_models:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and aec: \"ODList.toSet aec = agent_abs a t\"\n      and cec: \"ODList.toSet cec = common_abs t\"\n      and subj_phi: \"subjective a \\<phi>\"\n      and s: \"s \\<in> ODList.toSet aec\"\n  shows \"evalS (clock_evalProp envVal) (clock_knowledge envObs cec) (clock_commonKnowledge envObs cec) aec \\<phi>\n     \\<longleftrightarrow> clock_repMC (ODList.toSet cec), s \\<Turnstile> \\<phi>\" (is \"?lhs \\<phi> = ?rhs \\<phi>\")\nusing subj_phi s aec cec\nproof(induct \\<phi> rule: subjective.induct[case_names Kprop Knot Kand Kknows Kcknows])\n  case (Kknows a a' \\<psi>) show ?case\n    apply (clarsimp simp: toSet_eq_iff)\n    apply rule\n     apply clarsimp\n     apply (subgoal_tac \"w' \\<in> ODList.toSet aec\")\n     apply (drule_tac c=\"w'\" in subsetD)\n       apply assumption\n      apply (simp add: eval_rec_models[OF subsetI[OF aec_cec_subset[OF tC aec cec]]])\n     apply (rule clock_repMC_aec[OF tC Kknows(3) Kknows(4), rotated, where x=s])\n       using Kknows\n       apply simp\n      using Kknows\n      apply simp\n\n    apply clarsimp\n    apply (simp add: eval_rec_models[OF subsetI[OF aec_cec_subset[OF tC aec cec]]])\n    using tC Kknows\n    apply (clarsimp simp: agent_abs_def)\n    apply (erule (1) ballE)\n    using Kknows\n    apply (cut_tac x=\"tLast t'\" and y=\"tLast t'a\" in clock_repMC_cec[OF tC Kknows(3) Kknows(4)])\n      unfolding clock_repRels_def\n      apply auto\n    done\nnext\n  case (Kcknows a as \\<psi>)\n  have \"?lhs (Kcknows as \\<psi>)\n      = (\\<forall>y\\<in>ODList.toSet aec.\n           \\<forall>x\\<in>(\\<Union>a\\<in>set as. relations (clock_repMC (ODList.toSet cec)) a)\\<^sup>+ `` {y}.\n              x \\<in> ODList.toSet (eval_rec (clock_evalProp envVal) (clock_knowledge envObs cec) (clock_commonKnowledge envObs cec)\n                       (big_union (clock_commonKnowledge envObs cec as) (toList aec)) \\<psi>))\"\n    (* FIXME dreaming of a cong rule here. *)\n    using toSet_def[symmetric]\n    apply (clarsimp simp: toSet_eq_iff toSet_def[symmetric] subset_eq)\n    apply (rule ball_cong[OF refl])\n    apply (rule ball_cong)\n    apply (subst clock_commonKnowledge_relation_image[OF aec_cec_subset[OF tC Kcknows(3) Kcknows(4)]])\n    apply simp_all\n    done\n  also have \"... = (\\<forall>s\\<in>ODList.toSet aec. clock_repMC (ODList.toSet cec), s \\<Turnstile> Kcknows as \\<psi>)\"\n    apply (rule ball_cong[OF refl])\n    apply simp\n    apply (rule ball_cong[OF refl])\n    apply (subst eval_rec_models[OF trc_aux[OF tC Kcknows(3) Kcknows(4), where as=as], symmetric])\n     apply (simp add: toSet_def[symmetric])\n     apply (rule_tac x=y in bexI)\n      apply (subst clock_commonKnowledge_relation_image[OF aec_cec_subset[OF tC Kcknows(3) Kcknows(4)]])\n      apply assumption\n     apply simp\n     apply (rule refl)\n    done\n  also have \"... = clock_repMC (ODList.toSet cec), s \\<Turnstile> Kknows a (Kcknows as \\<psi>)\"\n    using clock_repMC_aec[OF tC Kcknows(3) Kcknows(4) Kcknows(2)]\n          clock_repMC_cec[OF tC Kcknows(3) Kcknows(4) Kcknows(2)]\n    by (auto cong: ball_cong)\n  also have \"... = clock_repMC (ODList.toSet cec), s \\<Turnstile> Kcknows as \\<psi>\"\n    apply (rule S5n_common_knowledge_fixed_point_simpler[symmetric])\n    using Kcknows\n    apply (auto intro: aec_cec_subset[OF tC Kcknows(3) Kcknows(4) Kcknows(2)])\n    done\n  finally show ?case .\nqed simp_all\n\n(*>*)\nlemma eval_models:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and aec: \"ODList.toSet aec = agent_abs a t\"\n      and cec: \"ODList.toSet cec = common_abs t\"\n      and subj_phi: \"subjective a \\<phi>\"\n      and s: \"s \\<in> ODList.toSet aec\"\n  shows \"eval envVal envObs (cec, aec) \\<phi>\n     \\<longleftrightarrow> clock_repMC (ODList.toSet cec), s \\<Turnstile> \\<phi>\"\n(*<*)\n  unfolding eval_def\n  using evalS_models[OF tC aec cec subj_phi s]\n  apply (simp add: Let_def)\n  done\n\n(*>*)\n\n(* **************************************** *)\n\nsubsubsection\\<open>Simulated actions\\<close>\n\ntext\\<open>\n\nFrom a common equivalence class and a subjective equivalence class for\nagent @{term \"a\"}, we can compute the actions enabled for @{term \"a\"}:\n\n\\<close>\n\ndefinition (in -)\n  clock_simAction :: \"('a, 'p, 'aAct) JKBP \\<Rightarrow> (('s :: linorder) \\<Rightarrow> 'p \\<Rightarrow> bool)\n                  \\<Rightarrow> ('a \\<Rightarrow> 's \\<Rightarrow> 'obs)\n                  \\<Rightarrow> 'a \\<Rightarrow> 's clock_simWorldsRep \\<Rightarrow> 'aAct list\"\nwhere\n  \"clock_simAction jkbp envVal envObs \\<equiv> \\<lambda>a (Y, X).\n     [ action gc. gc \\<leftarrow> jkbp a, eval envVal envObs (Y, X) (guard gc) ]\"\n(*<*)\n\nabbreviation\n  clock_simAction :: \"'a \\<Rightarrow> 's clock_simWorldsRep \\<Rightarrow> 'aAct list\"\nwhere\n  \"clock_simAction \\<equiv> ClockView.clock_simAction jkbp envVal envObs\"\n\n(*>*)\ntext\\<open>\n\nUsing the above result about evaluation, we can relate \\<open>clock_simAction\\<close> to @{term \"jAction\"}. Firstly, \\<open>clock_simAction\\<close> behaves the same as @{term \"jAction\"} using the\n@{term \"clock_repMC\"} structure:\n\n\\<close>\n\nlemma clock_simAction_jAction:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and aec: \"ODList.toSet aec = agent_abs a t\"\n      and cec: \"ODList.toSet cec = common_abs t\"\n  shows \"set (clock_simAction a (cec, aec))\n       = set (jAction (clock_repMC (ODList.toSet cec)) (tLast t) a)\"\n(*<*)\n  unfolding clock_simAction_def jAction_def\n  apply clarsimp\n  apply rule\n   apply clarsimp\n   apply (rule_tac x=xa in bexI)\n    apply simp\n   apply clarsimp\n   apply (subst eval_models[OF tC aec cec, symmetric])\n     using tC aec cec subj\n     apply simp_all\n  apply clarsimp\n  apply (rule_tac x=xa in bexI)\n   apply (rule refl)\n  apply clarsimp\n  apply (subst eval_models[OF tC aec cec])\n    using tC aec cec subj\n    apply simp_all\n  done\n\nlemma clock_submodel_aux:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and s: \"s \\<in> worlds (clock_simMCt t)\"\n  shows \"gen_model Clock.MCS s = gen_model (clock_simMCt t) s\"\nproof(rule gen_model_subset[where T=\"clock_jkbpCSt t\"])\n  fix a\n  let ?X = \"clock_sim ` Clock.jkbpCn (tLength t)\"\n  show \"relations Clock.MCS a \\<inter> ?X \\<times> ?X\n      = relations (clock_simMCt t) a \\<inter> ?X \\<times> ?X\"\n    by (simp add: Int_ac Int_absorb1\n                  relation_mono[OF jkbpCSt_jkbpCS_subset jkbpCSt_jkbpCS_subset])\nnext\n  let ?X = \"clock_sim ` Clock.jkbpCn (tLength t)\"\n  from s show \"(\\<Union>a. relations (clock_simMCt t) a)\\<^sup>* `` {s} \\<subseteq> ?X\"\n    apply (clarsimp simp del: mkKripke_simps)\n    apply (erule kripke_rels_trc_worlds)\n    apply auto\n    done\nnext\n  let ?Y = \"Clock.jkbpCn (tLength t)\"\n  let ?X = \"clock_sim ` ?Y\"\n  from s obtain t'\n    where st': \"s = clock_sim t'\"\n      and t'C: \"t' \\<in> Clock.jkbpC\"\n      and t'O: \"tLength t = tLength t'\"\n    by fastforce\n  { fix t''\n    assume tt': \"(t', t'') \\<in> (\\<Union>a. relations Clock.MC a)\\<^sup>*\"\n    from t'C tt' have t''C: \"t'' \\<in> Clock.jkbpC\"\n      by - (erule kripke_rels_trc_worlds, simp_all)\n    from t'O tt' have t''O: \"tLength t = tLength t''\"\n      by (simp add: Clock.sync_tLength_eq_trc)\n    from t''C t''O have \"t'' \\<in> ?Y\" by fastforce }\n  hence \"(\\<Union>a. relations Clock.MC a)\\<^sup>* `` {t'} \\<subseteq> ?Y\"\n    by clarsimp\n  hence \"clock_sim ` ((\\<Union>a. relations Clock.MC a)\\<^sup>* `` {t'}) \\<subseteq> ?X\"\n    by (rule image_mono)\n  with st' t'C\n  show \"(\\<Union>a. relations Clock.MCS a)\\<^sup>* `` {s} \\<subseteq> ?X\"\n    using sim_trc_commute[OF Clock.mkM_kripke clock_sim, where t=t'] by simp\nqed (insert s, auto)\n\n(*>*)\ntext\\<open>\n\nWe can connect the agent's choice of actions on the \\<open>clock_repMC\\<close> structure to those on the \\<open>Clock.MC\\<close>\nstructure using our earlier results about actions being preserved by\ngenerated models and simulations.\n\n\\<close>\n\nlemma clock_simAction':\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n  assumes aec: \"ODList.toSet aec = agent_abs a t\"\n  assumes cec: \"ODList.toSet cec = common_abs t\"\n  shows \"set (clock_simAction a (cec, aec)) = set (jAction Clock.MC t a)\"\n(*<*) (is \"?lhs = ?rhs\")\nproof -\n  from tC aec cec\n  have \"?lhs = set (jAction (clock_repMC (ODList.toSet cec)) (tLast t) a)\"\n    by (rule clock_simAction_jAction)\n  also from tC aec cec\n  have \"... = set (jAction (clock_simMCt t) (clock_sim t) a)\"\n    by (simp add: simulation_jAction_eq[OF _ clock_repSim] common_abs_def)\n  also from tC\n  have \"... = set (jAction Clock.MCS (clock_sim t) a)\"\n    using gen_model_jAction_eq[OF clock_submodel_aux[OF tC, where s=\"clock_sim t\"], where w'=\"clock_sim t\"]\n          gen_model_world_refl[where w=\"clock_sim t\" and M=\"clock_simMCt t\"]\n    by simp\n  also from tC have \"... = set (jAction Clock.MC t a)\"\n    by (simp add: simulation_jAction_eq[OF _ clock_sim])\n  finally show ?thesis .\nqed\n\n(*>*)\ntext\\<open>\n\nThe @{term \"Algorithm\"} locale requires a specialisation of this\nlemma:\n\n\\<close>\n\nlemma clock_simAction:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n  assumes ec: \"clock_simAbs ec = Clock.sim_equiv_class a t\"\n  shows \"set (clock_simAction a ec) = set (jAction Clock.MC t a)\"\n(*<*)\n  using assms clock_simAction'[OF tC, where cec=\"fst ec\" and aec=\"snd ec\"]\n  apply (simp add: common_abs agent_abs)\n  done\n(*>*)\n\n(* **************************************** *)\n\nsubsubsection\\<open>Simulated transitions\\<close>\n\ntext\\<open>\n\nWe need to determine the image of the set of commonly-held-possible\nstates under the transition function, and also for the agent's\nsubjective equivalence class. We do this with the \\<open>clock_trans\\<close> function:\n\n\\<close>\n\ndefinition (in -)\n  clock_trans :: \"('a :: linorder) odlist \\<Rightarrow> ('a, 'p, 'aAct) JKBP\n              \\<Rightarrow> (('s :: linorder) \\<Rightarrow> 'eAct list)\n              \\<Rightarrow> ('eAct \\<Rightarrow> ('a \\<Rightarrow> 'aAct) \\<Rightarrow> 's \\<Rightarrow> 's)\n              \\<Rightarrow> ('s \\<Rightarrow> 'p \\<Rightarrow> bool) \\<Rightarrow> ('a \\<Rightarrow> 's \\<Rightarrow> 'obs)\n              \\<Rightarrow> 's odlist \\<Rightarrow> 's odlist \\<Rightarrow> 's odlist\"\nwhere\n  \"clock_trans agents jkbp envAction envTrans envVal envObs \\<equiv> \\<lambda>cec X.\n     ODList.fromList (concat\n       [ [ envTrans eact aact s .\n                     eact \\<leftarrow> envAction s,\n                     aact \\<leftarrow> listToFuns (\\<lambda>a. clock_simAction jkbp envVal envObs a\n                                        (cec, clock_knowledge envObs cec a s))\n                                        (toList agents) ] .\n                   s \\<leftarrow> toList X ])\"\n(*<*)\n\nabbreviation\n  clock_trans :: \"'s odlist \\<Rightarrow> 's odlist \\<Rightarrow> 's odlist\"\nwhere\n  \"clock_trans \\<equiv> ClockView.clock_trans agents jkbp envAction envTrans envVal envObs\"\n\nlemma clock_trans_aux:\n  assumes t'C: \"t' \\<in> Clock.jkbpC\"\n      and ec: \"clock_simAbs ec = Clock.sim_equiv_class a' t'\"\n      and tC: \"t \\<in> Clock.jkbpCn (tLength t')\"\n      and eact: \"eact \\<in> set (envAction (tLast t))\"\n  shows \"(aact \\<in> set (listToFuns (\\<lambda>a. clock_simAction a (fst ec, clock_knowledge envObs (fst ec) a (tLast t)))\n                            (toList agents)))\n     \\<longleftrightarrow> (\\<forall>a. aact a \\<in> set (jAction (Clock.MCn (tLength t')) t a))\"\n  using assms\n  apply -\n  apply (frule Clock.jkbpCn_jkbpC_inc)\n  apply (clarsimp simp: listToFuns_ext[OF agents[unfolded toSet_def]])\n  apply (subst clock_simAction')\n     apply (erule Clock.jkbpCn_jkbpC_inc)\n    apply (subst clock_coEC_relation_image)\n     apply (simp add: common_abs common_abs_def toSet_def[symmetric])\n    apply (fastforce simp: common_abs agent_abs_def common_abs_def clock_repRels_def)\n   apply (simp add: common_abs common_abs_def)\n  apply (simp add: Clock.jkbpC_jkbpCn_jAction_eq)\n  done\n\n(*>*)\ntext\\<open>\n\nThe function @{term \"listToFuns\"} exhibits the isomorphism between @{typ\n\"('a \\<times> 'b list) list\"} and @{typ \"('a \\<Rightarrow> 'b) list\"} for finite types\n@{typ \"'a\"}.\n\nWe can show that the transition function works for both the\ncommonly-held set of states and the agent subjective one. The proofs\nare  straightforward.\n\n\\<close>\n\nlemma clock_trans_common:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n  assumes ec: \"clock_simAbs ec = Clock.sim_equiv_class a t\"\n  shows \"ODList.toSet (clock_trans (fst ec) (fst ec))\n       = { s |t' s. t' \\<leadsto> s \\<in> Clock.jkbpC \\<and> tLength t' = tLength t }\"\n(*<*) (is \"?lhs = ?rhs\")\nproof\n  show \"?lhs \\<subseteq> ?rhs\"\n    unfolding clock_trans_def\n    apply (clarsimp simp: toSet_def[symmetric] common_abs[OF assms] common_abs_def)\n    apply (rule_tac x=xa in exI)\n    apply clarsimp\n    apply (rule Clock.jkbpCn_jkbpC_inc[where n=\"Suc (tLength t)\"])\n    apply (auto simp: Let_def iff: clock_trans_aux[OF tC ec])\n    done\nnext\n  show \"?rhs \\<subseteq> ?lhs\"\n    unfolding clock_trans_def\n    apply (clarsimp simp: toSet_def[symmetric] common_abs[OF assms] common_abs_def)\n    apply (drule Clock.jkbpC_tLength_inv[where n=\"Suc (tLength t)\"])\n    apply (auto simp: Let_def iff: clock_trans_aux[OF tC ec])\n    done\nqed\n\n(*>*)\ntext\\<open>\\<close>\n\nlemma clock_trans_agent:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n  assumes ec: \"clock_simAbs ec = Clock.sim_equiv_class a t\"\n  shows \"ODList.toSet (clock_trans (fst ec) (snd ec))\n       = { s |t' s. t' \\<leadsto> s \\<in> Clock.jkbpC \\<and> clock_jview a t' = clock_jview a t }\"\n(*<*) (is \"?lhs = ?rhs\")\nproof\n  show \"?lhs \\<subseteq> ?rhs\"\n    unfolding clock_trans_def\n    apply (clarsimp simp: toSet_def[symmetric] common_abs[OF assms] agent_abs[OF assms] common_abs_def agent_abs_def)\n    apply (rule_tac x=t' in exI)\n    apply clarsimp\n    apply (rule Clock.jkbpCn_jkbpC_inc[where n=\"Suc (tLength t)\"])\n    apply (auto simp: Let_def iff: clock_trans_aux[OF tC ec])\n    done\nnext\n  show \"?rhs \\<subseteq> ?lhs\"\n    unfolding clock_trans_def\n    apply (clarsimp simp: toSet_def[symmetric] common_abs[OF assms] agent_abs[OF assms] common_abs_def agent_abs_def)\n    apply (drule Clock.jkbpC_tLength_inv[where n=\"Suc (tLength t)\"])\n    apply (auto simp: Let_def iff: clock_trans_aux[OF tC ec])\n    done\nqed\n\n(*>*)\ntext\\<open>\n\nNote that the clock semantics disregards paths, so we simply compute\nthe successors of the temporal slice and partition that. Similarly the\nsuccessors of the agent's subjective equivalence class tell us what\nthe set of possible observations are:\n\n\\<close>\n\ndefinition (in -)\n  clock_mkSuccs :: \"('s :: linorder \\<Rightarrow> 'obs) \\<Rightarrow> 'obs \\<Rightarrow> 's odlist\n                \\<Rightarrow> 's clock_simWorldsRep\"\nwhere\n  \"clock_mkSuccs envObs obs Y' \\<equiv> (Y', ODList.filter (\\<lambda>s. envObs s = obs) Y')\"\n\ntext\\<open>\n\nFinally we can define our transition function on simulated states:\n\n\\<close>\n\ndefinition (in -)\n  clock_simTrans :: \"('a :: linorder) odlist \\<Rightarrow> ('a, 'p, 'aAct) JKBP\n              \\<Rightarrow> (('s :: linorder) \\<Rightarrow> 'eAct list)\n              \\<Rightarrow> ('eAct \\<Rightarrow> ('a \\<Rightarrow> 'aAct) \\<Rightarrow> 's \\<Rightarrow> 's)\n              \\<Rightarrow> ('s \\<Rightarrow> 'p \\<Rightarrow> bool) \\<Rightarrow> ('a \\<Rightarrow> 's \\<Rightarrow> 'obs)\n              \\<Rightarrow> 'a \\<Rightarrow> 's clock_simWorldsRep \\<Rightarrow> 's clock_simWorldsRep list\"\nwhere\n  \"clock_simTrans agents jkbp envAction envTrans envVal envObs \\<equiv> \\<lambda>a (Y, X).\n     let X' = clock_trans agents jkbp envAction envTrans envVal envObs Y X;\n        Y' = clock_trans agents jkbp envAction envTrans envVal envObs Y Y\n      in [ clock_mkSuccs (envObs a) obs Y' .\n             obs \\<leftarrow> map (envObs a) (toList X') ]\"\n(*<*)\n\nabbreviation\n  clock_simTrans :: \"'a \\<Rightarrow> 's clock_simWorldsRep \\<Rightarrow> 's clock_simWorldsRep list\"\nwhere\n  \"clock_simTrans \\<equiv> ClockView.clock_simTrans agents jkbp envAction envTrans envVal envObs\"\n\n(*>*)\ntext\\<open>\n\nShowing that this respects the property asked of it by the @{term\n\"Algorithm\"} locale is straightforward:\n\n\\<close>\n\nlemma clock_simTrans:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and ec: \"clock_simAbs ec = Clock.sim_equiv_class a t\"\n  shows \"clock_simAbs ` set (clock_simTrans a ec)\n      = { Clock.sim_equiv_class a (t' \\<leadsto> s)\n          |t' s. t' \\<leadsto> s \\<in> Clock.jkbpC \\<and> clock_jview a t' = clock_jview a t }\"\n(*<*) (is \"?lhs = ?rhs\")\nproof\n  note image_cong_simp [cong del]\n  show \"?lhs \\<subseteq> ?rhs\"\n    unfolding clock_simTrans_def clock_mkSuccs_def\n    using clock_trans_common[OF tC ec] clock_trans_agent[OF tC ec]\n    apply (clarsimp simp: toSet_def[symmetric] clock_simAbs_def Let_def)\n\n    apply (rule_tac x=t' in exI)\n    apply (rule_tac x=xa in exI)\n\n    apply (clarsimp simp: clock_sim_def)\n    apply safe\n\n     apply clarsimp\n     apply (rule_tac x=\"t'a \\<leadsto> s\" in image_eqI)\n      apply (clarsimp simp: Let_def Set.image_def)\n      apply safe\n        apply (rule_tac x=\"t'b \\<leadsto> x\" in exI)\n        apply (clarsimp simp: Let_def Set.image_def)\n        apply (drule_tac t=\"t'b \\<leadsto> x\" in Clock.jkbpC_tLength_inv[OF _ refl])\n        apply (auto simp: Let_def)[1]\n       apply (rule_tac x=\"ta\" in exI)\n       apply simp\n       apply (rule Clock.jkbpCn_jkbpC_inc[where n=\"Suc (tLength t)\"])\n       apply (auto simp: Let_def)[3]\n\n    apply (rule_tac x=\"tLast ta\" in exI)\n    apply (clarsimp simp: Let_def Set.image_def)\n    apply safe\n      apply (rule_tac x=\"taa\" in exI)\n      apply simp\n      apply (rule Clock.jkbpCn_jkbpC_inc[where n=\"Suc (tLength t)\"])\n       apply (auto simp: Let_def)[1]\n     apply (drule_tac t=\"t'a \\<leadsto> x\" in Clock.jkbpC_tLength_inv[OF _ refl])\n     apply (rule_tac x=\"t'a \\<leadsto> x\" in exI)\n     apply (auto simp: Let_def)[1]\n    apply (drule_tac t=\"ta\" in Clock.jkbpC_tLength_inv)\n     apply blast\n    apply (clarsimp simp: Let_def)\n    apply (rule_tac x=\"ta\" in exI)\n    apply simp\n    apply (rule Clock.jkbpCn_jkbpC_inc[where n=\"Suc (tLength t)\"])\n    apply (auto simp: Let_def)\n    done\nnext\n  show \"?rhs \\<subseteq> ?lhs\"\n    unfolding clock_simTrans_def Let_def\n    apply (cases ec)\n    using clock_trans_common[OF tC ec] clock_trans_agent[OF tC ec]\n    apply (clarsimp simp: toSet_def[symmetric] Set.image_def clock_simAbs_def\n                simp del: split_paired_Ex)\n\n    apply (rule_tac x=\"clock_mkSuccs (envObs a) (envObs a s) (clock_trans aa aa)\" in exI)\n    apply safe\n      apply auto[1]\n     apply (rule_tac x=\"tLast x\" in exI)\n     apply (clarsimp simp: clock_trans_common[OF tC ec] clock_mkSuccs_def)\n     apply safe\n       apply (clarsimp simp: clock_sim_def simp del: Clock.jkbpCn.simps)\n       apply rule\n        apply (clarsimp simp: Let_def)\n        apply (rule_tac x=\"ta\" in exI)\n        apply (simp add: Let_def)\n        apply (rule Clock.jkbpCn_jkbpC_inc[where n=\"Suc (tLength t)\"])\n        apply (clarsimp simp: Let_def)\n        apply (rule_tac x=eact in exI)\n        apply (rule_tac x=aact in exI)\n        apply clarsimp\n       apply (clarsimp simp: Let_def Set.image_def)\n       apply (drule_tac t=\"t'a \\<leadsto> xa\" in Clock.jkbpC_tLength_inv[OF _ refl])\n       apply (rule_tac x=\"t'a \\<leadsto> xa\" in exI)\n       apply (auto simp: Let_def)[1]\n      apply (drule_tac t=\"x\" in Clock.jkbpC_tLength_inv[OF _ refl])\n      apply (simp only: Let_def Clock.jkbpCn.simps)\n      apply clarify\n      apply (rule_tac x=\"ta\" in exI)\n      apply simp\n      apply (rule Clock.jkbpCn_jkbpC_inc[where n=\"Suc (tLength t)\"])\n      apply (auto simp: Let_def)[1]\n     apply (clarsimp simp: clock_trans_common[OF tC ec] clock_mkSuccs_def)\n     apply (rule_tac x=\"t'a \\<leadsto> sa\" in exI)\n     apply (clarsimp simp: clock_sim_def Let_def)\n     (* FIXME similar to above *)\n     apply rule\n      apply (clarsimp simp: Set.image_def)\n      apply (rule_tac x=\"t'b \\<leadsto> x\" in exI)\n      apply (drule_tac t=\"t'b \\<leadsto> x\" in Clock.jkbpC_tLength_inv[OF _ refl])\n      apply (auto simp: Let_def)[1]\n    apply clarsimp\n    apply (rule_tac x=\"ta\" in exI)\n    apply auto\n    apply (rule Clock.jkbpCn_jkbpC_inc[where n=\"Suc (tLength t)\"])\n    apply (auto simp: Let_def)\n    done\nqed\n(*>*)\n\nend (* context FiniteLinorderEnvironment *)\n\n(* **************************************** *)\n\nsubsubsection\\<open>Maps\\<close>\n\ntext\\<open>\n\n\\label{sec:kbps-theory-clock-view-maps}\n\nAs mentioned above, the canonicity of our ordered, distinct list\nrepresentation of automaton states allows us to use them as keys in a\ndigital trie; a value of type @{typ \"('key, 'val) trie\"} maps keys of\ntype @{typ \"'key list\"} to values of type @{typ \"'val\"}.\n\nIn this specific case we track automaton transitions using a two-level\nstructure mapping sets of states to an association list mapping\nobservations to sets of states, and for actions automaton states map\ndirectly to agent actions.\n\n\\<close>\n\ntype_synonym ('s, 'obs) clock_trans_trie\n  = \"('s, ('s, ('obs, 's clock_simWorldsRep) mapping) trie) trie\"\ntype_synonym ('s, 'aAct) clock_acts_trie = \"('s, ('s, 'aAct) trie) trie\"\n(*<*)\n\ndefinition\n  trans_MapOps_lookup :: \"('s :: linorder, 'obs) clock_trans_trie\n                        \\<Rightarrow> 's clock_simWorldsRep \\<times> 'obs\n                        \\<rightharpoonup> 's clock_simWorldsRep\"\nwhere\n  \"trans_MapOps_lookup \\<equiv> \\<lambda>m k.\n     Option.bind (trie_odlist_lookup m (fst (fst k))) (\\<lambda>m.\n       (Option.bind (trie_odlist_lookup m (snd (fst k))) (\\<lambda>m.\n         Mapping.lookup m (snd k))))\"\n\ndefinition\n  trans_MapOps_update :: \"('s :: linorder) clock_simWorldsRep \\<times> 'obs \\<Rightarrow> 's clock_simWorldsRep\n                        \\<Rightarrow> ('s :: linorder, 'obs) clock_trans_trie\n                        \\<Rightarrow> ('s :: linorder, 'obs) clock_trans_trie\"\nwhere\n  \"trans_MapOps_update \\<equiv> \\<lambda>k v m.\n     trie_odlist_update_with (fst (fst k)) m empty_trie (\\<lambda>m.\n       trie_odlist_update_with (snd (fst k)) m Mapping.empty (\\<lambda>m.\n          Mapping.update (snd k) v m))\"\n\ndefinition\n  trans_MapOps :: \"(('s :: linorder, 'obs) clock_trans_trie,\n                    's clock_simWorldsRep \\<times> 'obs, 's clock_simWorldsRep) MapOps\"\nwhere\n  \"trans_MapOps \\<equiv>\n     \\<lparr> MapOps.empty = empty_trie,\n       lookup = trans_MapOps_lookup,\n       update = trans_MapOps_update \\<rparr>\"\n\nlemma (in FiniteLinorderEnvironment) trans_MapOps:\n  \"MapOps (\\<lambda>k. (clock_simAbs (fst k), snd k)) (Clock.jkbpSEC \\<times> UNIV) trans_MapOps\"\nproof\n  fix k show \"MapOps.lookup trans_MapOps (MapOps.empty trans_MapOps) k = None\"\n    unfolding trans_MapOps_def trans_MapOps_lookup_def trie_odlist_lookup_def\n    by (auto split: prod.split)\nnext\n  fix e k k' M\n  assume k: \"(clock_simAbs (fst k), snd k) \\<in> Clock.jkbpSEC \\<times> (UNIV :: 'z set)\"\n     and k': \"(clock_simAbs (fst k'), snd k') \\<in> Clock.jkbpSEC \\<times> (UNIV :: 'z set)\"\n  show \"MapOps.lookup trans_MapOps (MapOps.update trans_MapOps k e M) k'\n         = (if (clock_simAbs (fst k'), snd k') = (clock_simAbs (fst k), snd k)\n             then Some e else MapOps.lookup trans_MapOps M k')\"\n  proof(cases \"(clock_simAbs (fst k'), snd k') = (clock_simAbs (fst k), snd k)\")\n    case True hence \"k = k'\"\n      using inj_onD[OF clock_simAbs_inj_on] k k' by (auto iff: prod_eqI)\n    thus ?thesis\n      unfolding trans_MapOps_def trans_MapOps_lookup_def trans_MapOps_update_def trie_odlist_lookup_def trie_odlist_update_with_def\n        by (simp add: lookup_trie_update_with lookup_update split: option.split prod.split) \n  next\n    case False thus ?thesis\n      unfolding trans_MapOps_def trans_MapOps_lookup_def trans_MapOps_update_def trie_odlist_lookup_def trie_odlist_update_with_def\n      by (cases \"fst k = fst k'\")\n       (auto simp add: lookup_empty lookup_update_neq prod_eq_iff lookup_trie_update_with split: option.split prod.split)\n  qed\nqed\n\n(* A map for the agent actions. *)\n\ndefinition\n  acts_MapOps_lookup :: \"('s :: linorder, 'aAct) clock_acts_trie\n                      \\<Rightarrow> 's clock_simWorldsRep\n                      \\<rightharpoonup> 'aAct\"\nwhere\n  \"acts_MapOps_lookup \\<equiv> \\<lambda>m k.\n     Option.bind (trie_odlist_lookup m (fst k)) (\\<lambda>m.\n       (trie_odlist_lookup m (snd k)))\"\n\ndefinition\n  acts_MapOps_update :: \"('s :: linorder) clock_simWorldsRep \\<Rightarrow> 'aAct\n                      \\<Rightarrow> ('s :: linorder, 'aAct) clock_acts_trie\n                      \\<Rightarrow> ('s :: linorder, 'aAct) clock_acts_trie\"\nwhere\n  \"acts_MapOps_update \\<equiv> \\<lambda>k v m.\n     trie_odlist_update_with (fst k) m empty_trie (\\<lambda>m.\n       trie_odlist_update (snd k) v m)\"\n\ndefinition\n  acts_MapOps :: \"(('s :: linorder, 'aAct) clock_acts_trie, 's clock_simWorldsRep, 'aAct) MapOps\"\nwhere\n  \"acts_MapOps \\<equiv>\n     \\<lparr> MapOps.empty = empty_trie,\n       lookup = acts_MapOps_lookup,\n       update = acts_MapOps_update \\<rparr>\"\n\nlemma (in FiniteLinorderEnvironment) acts_MapOps:\n  \"MapOps clock_simAbs Clock.jkbpSEC acts_MapOps\"\nproof\n  fix k show \"MapOps.lookup acts_MapOps (MapOps.empty acts_MapOps) k = None\"\n    unfolding acts_MapOps_def acts_MapOps_lookup_def trie_odlist_lookup_def\n    by auto\nnext\n  fix e k k' M\n  assume k: \"clock_simAbs k \\<in> Clock.jkbpSEC\"\n     and k': \"clock_simAbs k' \\<in> Clock.jkbpSEC\"\n  show \"MapOps.lookup acts_MapOps (MapOps.update acts_MapOps k e M) k'\n         = (if clock_simAbs k' = clock_simAbs k\n             then Some e else MapOps.lookup acts_MapOps M k')\"\n  proof(cases \"clock_simAbs k' = clock_simAbs k\")\n    case True hence \"k = k'\"\n      using inj_onD[OF clock_simAbs_inj_on] k k' by (auto iff: prod_eqI)\n    thus ?thesis\n      unfolding acts_MapOps_def acts_MapOps_lookup_def acts_MapOps_update_def\n      by (auto simp: lookup_trie_update lookup_trie_update_with\n                     trie_odlist_update_with_def trie_odlist_update_def trie_odlist_lookup_def)\n  next\n    case False thus ?thesis\n      unfolding acts_MapOps_def acts_MapOps_lookup_def acts_MapOps_update_def\n      by (auto simp: lookup_trie_update lookup_trie_update_with\n                     trie_odlist_update_with_def trie_odlist_update_def trie_odlist_lookup_def\n               dest: prod_eqI\n              split: option.split)\n  qed\nqed\n\n(*>*)\ntext\\<open>\n\nWe define two records @{term \"acts_MapOps\"} and @{term \"trans_MapOps\"}\nsatisfying the @{term \"MapOps\"} predicate\n(\\S\\ref{sec:kbps-theory-map-ops}). Discharging the obligations in the\n@{term \"Algorithm\"} locale is routine, leaning on the work of\n\\citet{DBLP:conf/itp/LammichL10}.\n\n\\<close>\n\nsubsubsection\\<open>Locale instantiation\\<close>\n\ntext\\<open>\n\nFinally we assemble the algorithm and discharge the proof obligations.\n\n\\<close>\n\nsublocale FiniteLinorderEnvironment\n        < Clock: Algorithm\n            jkbp envInit envAction envTrans envVal\n            clock_jview envObs clock_jviewInit clock_jviewIncr\n            clock_sim clock_simRels clock_simVal\n            clock_simAbs clock_simObs clock_simInit clock_simTrans clock_simAction\n            acts_MapOps trans_MapOps\n(*<*)\n  apply (unfold_locales)\n\n  apply clarify\n  apply (rule clock_simInit)\n  apply simp\n\n  apply clarify\n  apply (erule (1) clock_simObs)\n\n  apply clarify\n  apply (erule (1) clock_simAction)\n\n  apply clarify\n  apply (erule (1) clock_simTrans)\n\n  apply (rule acts_MapOps)\n  apply (rule trans_MapOps)\n\n  done\n\n(*>*)\ntext\\<open>\n\nExplicitly, the algorithm for this case is:\n\n\\<close>\n\ndefinition\n  \"mkClockAuto \\<equiv> \\<lambda>agents jkbp envInit envAction envTrans envVal envObs.\n    mkAlgAuto acts_MapOps\n              trans_MapOps\n              (clock_simObs envObs)\n              (clock_simInit envInit envObs)\n              (clock_simTrans agents jkbp envAction envTrans envVal envObs)\n              (clock_simAction jkbp envVal envObs)\n              (\\<lambda>a. map (clock_simInit envInit envObs a \\<circ> envObs a) envInit)\"\n\nlemma (in FiniteLinorderEnvironment) mkClockAuto_implements:\n  \"Clock.implements\n    (mkClockAuto agents jkbp envInit envAction envTrans envVal envObs)\"\n(*<*)\n  using Clock.k_mkAlgAuto_implements\n  unfolding mkClockAuto_def mkAlgAuto_def Clock.k_frontier_def\n  by simp\n\n(*\n\nWe actually run this unfolding of the algorithm. The lemma is keeping\nus honest.\n\n*)\n\ndefinition\n  \"ClockAutoDFS \\<equiv> \\<lambda>agents jkbp envInit envAction envTrans envVal envObs. \\<lambda>a.\n    alg_dfs acts_MapOps\n            trans_MapOps\n            (clock_simObs envObs a)\n            (clock_simTrans agents jkbp envAction envTrans envVal envObs a)\n            (clock_simAction jkbp envVal envObs a)\n            (map (clock_simInit envInit envObs a \\<circ> envObs a) envInit)\"\n\nlemma (in FiniteLinorderEnvironment)\n  \"mkClockAuto agents jkbp envInit envAction envTrans envVal envObs\n = (\\<lambda>a. alg_mk_auto acts_MapOps trans_MapOps (clock_simInit a) (ClockAutoDFS agents jkbp envInit envAction envTrans envVal envObs a))\"\n  unfolding mkClockAuto_def ClockAutoDFS_def mkAlgAuto_def alg_mk_auto_def by (simp add: Let_def)\n\n(*>*)\ntext\\<open>\n\nWe discuss the clock semantics further in \\S\\ref{sec:kbps-alg-clock}.\n\n\\<close>\n\n(*<*)\nend\n(*>*)\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Evaluation/KBPs/ClockView.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631556226291, "lm_q2_score": 0.476579651063676, "lm_q1q2_score": 0.2895998946708848}}
{"text": "(*****************************************************************************\n * Featherweight-OCL --- A Formal Semantics for UML-OCL Version OCL 2.4\n *                       for the OMG Standard.\n *                       http://www.brucker.ch/projects/hol-testgen/\n *\n * OCL_core.thy --- Core definitions.\n * This file is part of HOL-TestGen.\n *\n * Copyright (c) 2012-2013 Université Paris-Sud, France\n *               2013      IRT SystemX, France\n *\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are\n * met:\n *\n *     * Redistributions of source code must retain the above copyright\n *       notice, this list of conditions and the following disclaimer.\n *\n *     * Redistributions in binary form must reproduce the above\n *       copyright notice, this list of conditions and the following\n *       disclaimer in the documentation and/or other materials provided\n *       with the distribution.\n *\n *     * Neither the name of the copyright holders nor the names of its\n *       contributors may be used to endorse or promote products derived\n *       from this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n ******************************************************************************)\n\nheader{* Formalization I: Core Definitions *}\n\ntheory\n  OCL_core\nimports\n  Main\nbegin\n\nsection{* Preliminaries *}\nsubsection{* Notations for the Option Type *}\n\ntext{*\n  First of all, we will use a more compact notation for the library\n  option type which occur all over in our definitions and which will make\n  the presentation more like a textbook:\n*}\nnotation Some (\"\\<lfloor>(_)\\<rfloor>\")\nnotation None (\"\\<bottom>\")\n\ntext{*\n  The following function (corresponding to @{term the} in the Isabelle/HOL library)\n  is defined as the inverse of the injection @{term Some}.\n*}\nfun    drop :: \"'\\<alpha> option \\<Rightarrow> '\\<alpha>\" (\"\\<lceil>(_)\\<rceil>\")\nwhere  drop_lift[simp]: \"\\<lceil>\\<lfloor>v\\<rfloor>\\<rceil> = v\"\n\n\nsubsection{* Minimal Notions of State and State Transitions *}\ntext{* Next we will introduce the foundational concept of an object id (oid),\nwhich is just some infinite set. *}\n\ntext{* In order to assure executability of as much as possible formulas, we fixed the\ntype of object id's to just natural numbers.*}\ntype_synonym oid = nat\n\ntext{* We refrained from the alternative:\n\\begin{isar}[mathescape]\n$\\text{\\textbf{type-synonym}}$ $\\mathit{oid = ind}$\n\\end{isar}\nwhich is slightly more abstract but non-executable.\n*}\n\ntext{*\n  States are just a partial map from oid's to elements of an object\n  universe @{text \"'\\<AA>\"}, and state transitions pairs of states\n  \\ldots\n*}\nrecord ('\\<AA>)state =\n             heap   :: \"oid \\<rightharpoonup> '\\<AA> \"\n             assocs\\<^sub>2 :: \"oid  \\<rightharpoonup> (oid \\<times> oid) list\"       (* binary associations *)\n             assocs\\<^sub>3 :: \"oid  \\<rightharpoonup> (oid \\<times> oid \\<times> oid) list\" (* ternary associations *)\n\n\ntype_synonym ('\\<AA>)st = \"'\\<AA> state \\<times> '\\<AA> state\"\n\nsubsection{* Prerequisite: An Abstract Interface for OCL Types *}\n\ntext {*\n  To have the possibility to nest collection types,\n  such that we can give semantics to expressions like @{text \"Set{Set{\\<two>},null}\"},\n  it is necessary to introduce a uniform interface for types having\n  the @{text \"invalid\"} (= bottom) element. The reason is that we impose\n  a data-invariant on raw-collection \\inlineisar|types_code| which assures\n  that the @{text \"invalid\"} element is not allowed inside the collection;\n  all raw-collections of this form were identified with the @{text \"invalid\"} element\n  itself. The construction requires that the new collection type is\n  not comparable with the raw-types (consisting of nested option type constructions),\n  such that the data-invariant must be expressed in terms of the interface.\n  In a second step, our base-types will be shown to be instances of this interface.\n *}\n\ntext{*\n  This uniform interface consists in a type class requiring the existence\n  of a bot and a null element. The construction proceeds by\n  abstracting the null (defined by @{text \"\\<lfloor> \\<bottom> \\<rfloor>\"} on\n  @{text \"'a option option\"}) to a @{text null} element, which may\n  have an arbitrary semantic structure, and an undefinedness element @{text \"\\<bottom> \"}\n  to an abstract undefinedness element @{text \"bot\"} (also written\n  @{text \"\\<bottom> \"} whenever no confusion arises). As a consequence, it is necessary\n  to redefine the notions of invalid, defined, valuation etc.\n  on top of this interface. *}\n\ntext{*\n  This interface consists in two abstract type classes @{text bot}\n  and @{text null} for the class of all types comprising a bot and a\n  distinct null element.  *}\n\nclass   bot =\n   fixes  bot :: \"'a\"\n   assumes nonEmpty : \"\\<exists> x. x \\<noteq> bot\"\n   \n\nclass      null = bot +\n   fixes   null :: \"'a\"\n   assumes null_is_valid : \"null \\<noteq> bot\"\n\n\nsubsection{* Accommodation of Basic Types to the Abstract Interface *}\n\ntext{*\n  In the following it is shown that the ``option-option'' type is\n  in fact in the @{text null} class and that function spaces over these\n  classes again ``live'' in these classes. This motivates the default construction\n  of the semantic domain for the basic types (\\inlineocl{Boolean},\n  \\inlineocl{Integer}, \\inlineocl{Real}, \\ldots).\n*}\n\ninstantiation   option  :: (type)bot\nbegin\n   definition bot_option_def: \"(bot::'a option) \\<equiv> (None::'a option)\"\n   instance proof show \"\\<exists>x\\<Colon>'a option. x \\<noteq> bot\"\n                  by(rule_tac x=\"Some x\" in exI, simp add:bot_option_def)\n            qed\nend \n\n\ninstantiation   option  :: (bot)null\nbegin\n   definition null_option_def: \"(null::'a\\<Colon>bot option) \\<equiv>  \\<lfloor> bot \\<rfloor>\"\n   instance proof  show \"(null::'a\\<Colon>bot option) \\<noteq> bot\"\n                   by( simp add:null_option_def bot_option_def)\n            qed\nend\n\n\ninstantiation \"fun\"  :: (type,bot) bot\nbegin\n   definition bot_fun_def: \"bot \\<equiv> (\\<lambda> x. bot)\"\n\n   instance proof  show \"\\<exists>(x::'a \\<Rightarrow> 'b). x \\<noteq> bot\"\n                   apply(rule_tac x=\"\\<lambda> _. (SOME y. y \\<noteq> bot)\" in exI, auto)\n                   apply(drule_tac x=x in fun_cong,auto simp:bot_fun_def)\n                   apply(erule contrapos_pp, simp)\n                   apply(rule some_eq_ex[THEN iffD2])\n                   apply(simp add: nonEmpty)\n                   done\n            qed\nend\n\n\ninstantiation \"fun\"  :: (type,null) null\nbegin\n definition null_fun_def: \"(null::'a \\<Rightarrow> 'b::null) \\<equiv> (\\<lambda> x. null)\"\n\n instance proof\n              show \"(null::'a \\<Rightarrow> 'b::null) \\<noteq> bot\"\n              apply(auto simp: null_fun_def bot_fun_def)\n              apply(drule_tac x=x in fun_cong)\n              apply(erule contrapos_pp, simp add: null_is_valid)\n            done\n          qed\nend\n\ntext{* A trivial consequence of this adaption of the interface is that\nabstract and concrete versions of null are the same on base types\n(as could be expected). *}\n\nsubsection{* The Semantic Space of OCL Types: Valuations *}\n\ntext{* Valuations are now functions from a state pair (built upon\ndata universe @{typ \"'\\<AA>\"}) to an arbitrary null-type (\\ie, containing\nat least a destinguished @{text \"null\"} and @{text \"invalid\"} element). *}\n\ntype_synonym ('\\<AA>,'\\<alpha>) val = \"'\\<AA> st \\<Rightarrow> '\\<alpha>::null\"\n\ntext{* The definitions for the constants and operations based on valuations\nwill be geared towards a format that Isabelle can check to be a ``conservative''\n(\\ie, logically safe) axiomatic definition. By introducing an explicit\ninterpretation function (which happens to be defined just as the identity\nsince we are using a shallow embedding of OCL into HOL), all these definitions\ncan be rewritten into the conventional semantic textbook format  as follows: *}\n\ndefinition Sem :: \"'a \\<Rightarrow> 'a\" (\"I\\<lbrakk>_\\<rbrakk>\")\nwhere \"I\\<lbrakk>x\\<rbrakk> \\<equiv> x\"\n\ntext{* As a consequence of semantic domain definition, any OCL type will\nhave the two semantic constants @{text \"invalid\"} (for exceptional, aborted\ncomputation) and @{text \"null\"}:\n *}\n\ndefinition invalid :: \"('\\<AA>,'\\<alpha>::bot) val\"\nwhere     \"invalid \\<equiv> \\<lambda> \\<tau>. bot\"\n\ntext{* This conservative Isabelle definition of the polymorphic constant\n@{const invalid} is equivalent with the textbook definition: *}\n\nlemma textbook_invalid: \"I\\<lbrakk>invalid\\<rbrakk>\\<tau> = bot\"\nby(simp add: invalid_def Sem_def)\n\n\ntext {* Note that the definition :\n{\\small\n\\begin{isar}[mathescape]\ndefinition null    :: \"('$\\mathfrak{A}$,'\\<alpha>::null) val\"\nwhere     \"null    \\<equiv> \\<lambda> \\<tau>. null\"\n\\end{isar}\n} is not  necessary since we defined the entire function space over null types\nagain as null-types; the crucial definition is @{thm \"null_fun_def\"}.\nThus, the polymorphic constant @{const null} is simply the result of\na general type class construction. Nevertheless, we can derive the\nsemantic textbook definition for the OCL null constant based on the\nabstract null:\n*}\n\nlemma textbook_null_fun: \"I\\<lbrakk>null::('\\<AA>,'\\<alpha>::null) val\\<rbrakk> \\<tau> = (null::'\\<alpha>::null)\"\nby(simp add: null_fun_def Sem_def)\n\n\nsection{* Definition of the Boolean Type *}\n\ntext{* The semantic domain of the (basic) boolean type is now defined as the Standard:\nthe space of valuation to @{typ \"bool option option\"}:*}\n\ntype_synonym ('\\<AA>)Boolean = \"('\\<AA>,bool option option) val\"\n\nsubsection{* Basic Constants *}\n\nlemma bot_Boolean_def : \"(bot::('\\<AA>)Boolean) = (\\<lambda> \\<tau>. \\<bottom>)\"\nby(simp add: bot_fun_def bot_option_def)\n\nlemma null_Boolean_def : \"(null::('\\<AA>)Boolean) = (\\<lambda> \\<tau>. \\<lfloor>\\<bottom>\\<rfloor>)\"\nby(simp add: null_fun_def null_option_def bot_option_def)\n\ndefinition true :: \"('\\<AA>)Boolean\"\nwhere     \"true \\<equiv> \\<lambda> \\<tau>. \\<lfloor>\\<lfloor>True\\<rfloor>\\<rfloor>\"\n\n\ndefinition false :: \"('\\<AA>)Boolean\"\nwhere     \"false \\<equiv>  \\<lambda> \\<tau>. \\<lfloor>\\<lfloor>False\\<rfloor>\\<rfloor>\"\n\nlemma bool_split: \"X \\<tau> = invalid \\<tau> \\<or> X \\<tau> = null \\<tau> \\<or>\n                   X \\<tau> = true \\<tau>    \\<or> X \\<tau> = false \\<tau>\"\napply(simp add: invalid_def null_def true_def false_def)\napply(case_tac \"X \\<tau>\",simp_all add: null_fun_def null_option_def bot_option_def)\napply(case_tac \"a\",simp)\napply(case_tac \"aa\",simp)\napply auto\ndone\n\n\n\n\n\nlemma [simp]: \"true (a, b) = \\<lfloor>\\<lfloor>True\\<rfloor>\\<rfloor>\"\nby(simp add:true_def)\n\nlemma textbook_true: \"I\\<lbrakk>true\\<rbrakk> \\<tau> = \\<lfloor>\\<lfloor>True\\<rfloor>\\<rfloor>\"\nby(simp add: Sem_def true_def)\n\nlemma textbook_false: \"I\\<lbrakk>false\\<rbrakk> \\<tau> = \\<lfloor>\\<lfloor>False\\<rfloor>\\<rfloor>\"\nby(simp add: Sem_def false_def)\n\ntext {*\n\\begin{table}[htbp]\n   \\centering\n   \\begin{tabu}{lX[,c,]}\n      \\toprule\n      Name & Theorem \\\\\n      \\midrule\n      @{thm [source] textbook_invalid}  & @{thm  [display=false] textbook_invalid} \\\\\n      @{thm [source] textbook_null_fun}  & @{thm [display=false] textbook_null_fun} \\\\\n      @{thm [source] textbook_true}   & @{thm  [display=false] textbook_true} \\\\\n      @{thm [source] textbook_false} & @{thm [display=false] textbook_false} \\\\\n      \\bottomrule\n   \\end{tabu}\n   \\caption{Basic semantic constant definitions of the logic (except @{term null})}\n   \\label{tab:sem_basic_constants}\n\\end{table}\n*}\n\nsubsection{* Validity and Definedness *}\n\ntext{* However, this has also the consequence that core concepts like definedness,\nvalidness and even cp have to be redefined on this type class:*}\n\ndefinition valid :: \"('\\<AA>,'a::null)val \\<Rightarrow> ('\\<AA>)Boolean\" (\"\\<upsilon> _\" [100]100)\nwhere   \"\\<upsilon> X \\<equiv>  \\<lambda> \\<tau> . if X \\<tau> = bot \\<tau> then false \\<tau> else true \\<tau>\"\n\nlemma valid1[simp]: \"\\<upsilon> invalid = false\"\n  by(rule ext,simp add: valid_def bot_fun_def bot_option_def\n                        invalid_def true_def false_def)\n\nlemma valid2[simp]: \"\\<upsilon> null = true\"\n  by(rule ext,simp add: valid_def bot_fun_def bot_option_def null_is_valid\n                        null_fun_def invalid_def true_def false_def)\n\nlemma valid3[simp]: \"\\<upsilon> true = true\"\n  by(rule ext,simp add: valid_def bot_fun_def bot_option_def null_is_valid\n                        null_fun_def invalid_def true_def false_def)\n\nlemma valid4[simp]: \"\\<upsilon> false = true\"\n  by(rule ext,simp add: valid_def bot_fun_def bot_option_def null_is_valid\n                        null_fun_def invalid_def true_def false_def)\n\n\nlemma cp_valid: \"(\\<upsilon> X) \\<tau> = (\\<upsilon> (\\<lambda> _. X \\<tau>)) \\<tau>\"\nby(simp add: valid_def)\n\n\n\ndefinition defined :: \"('\\<AA>,'a::null)val \\<Rightarrow> ('\\<AA>)Boolean\" (\"\\<delta> _\" [100]100)\nwhere   \"\\<delta> X \\<equiv>  \\<lambda> \\<tau> . if X \\<tau> = bot \\<tau>  \\<or> X \\<tau> = null \\<tau> then false \\<tau> else true \\<tau>\"\n\ntext{* The generalized definitions of invalid and definedness have the same\nproperties as the old ones : *}\nlemma defined1[simp]: \"\\<delta> invalid = false\"\n  by(rule ext,simp add: defined_def bot_fun_def bot_option_def\n                        null_def invalid_def true_def false_def)\n\nlemma defined2[simp]: \"\\<delta> null = false\"\n  by(rule ext,simp add: defined_def bot_fun_def bot_option_def\n                        null_def null_option_def null_fun_def invalid_def true_def false_def)\n\n\nlemma defined3[simp]: \"\\<delta> true = true\"\n  by(rule ext,simp add: defined_def bot_fun_def bot_option_def null_is_valid null_option_def\n                        null_fun_def invalid_def true_def false_def)\n\nlemma defined4[simp]: \"\\<delta> false = true\"\n  by(rule ext,simp add: defined_def bot_fun_def bot_option_def null_is_valid null_option_def\n                        null_fun_def invalid_def true_def false_def)\n\n\nlemma defined5[simp]: \"\\<delta> \\<delta> X = true\"\n  by(rule ext,\n     auto simp:           defined_def true_def false_def\n                bot_fun_def bot_option_def null_option_def null_fun_def)\n\nlemma defined6[simp]: \"\\<delta> \\<upsilon> X = true\"\n  by(rule ext,\n     auto simp: valid_def defined_def true_def false_def\n                bot_fun_def bot_option_def null_option_def null_fun_def)\n\nlemma valid5[simp]: \"\\<upsilon> \\<upsilon> X = true\"\n  by(rule ext,\n     auto simp: valid_def             true_def false_def\n                bot_fun_def bot_option_def null_option_def null_fun_def)\n\nlemma valid6[simp]: \"\\<upsilon> \\<delta> X = true\"\n  by(rule ext,\n     auto simp: valid_def defined_def true_def false_def\n                bot_fun_def bot_option_def null_option_def null_fun_def)\n\n\nlemma cp_defined:\"(\\<delta> X)\\<tau> = (\\<delta> (\\<lambda> _. X \\<tau>)) \\<tau>\"\nby(simp add: defined_def)\n\ntext{* The definitions above for the constants @{const defined} and @{const valid}\ncan be rewritten into the conventional semantic \"textbook\" format  as follows: *}\n\nlemma textbook_defined: \"I\\<lbrakk>\\<delta>(X)\\<rbrakk> \\<tau> = (if I\\<lbrakk>X\\<rbrakk> \\<tau> = I\\<lbrakk>bot\\<rbrakk> \\<tau>  \\<or> I\\<lbrakk>X\\<rbrakk> \\<tau> = I\\<lbrakk>null\\<rbrakk> \\<tau>\n                                     then I\\<lbrakk>false\\<rbrakk> \\<tau>\n                                     else I\\<lbrakk>true\\<rbrakk> \\<tau>)\"\nby(simp add: Sem_def defined_def)\n\nlemma textbook_valid: \"I\\<lbrakk>\\<upsilon>(X)\\<rbrakk> \\<tau> = (if I\\<lbrakk>X\\<rbrakk> \\<tau> = I\\<lbrakk>bot\\<rbrakk> \\<tau>\n                                   then I\\<lbrakk>false\\<rbrakk> \\<tau>\n                                   else I\\<lbrakk>true\\<rbrakk> \\<tau>)\"\nby(simp add: Sem_def valid_def)\n\n\ntext {* \n\\autoref{tab:sem_definedness} and \\autoref{tab:alglaws_definedness}\nsummarize the results of this section. \n\\begin{table}[htbp]\n   \\centering\n   \\begin{tabu}{lX[,c,]}\n      \\toprule\n      Name & Theorem \\\\\n      \\midrule\n      @{thm [source] textbook_defined}  & @{thm [show_question_marks=false,display=false,margin=45] textbook_defined} \\\\\n      @{thm [source] textbook_valid}   & @{thm [show_question_marks=false,display=false,margin=45] textbook_valid} \\\\\n      \\bottomrule\n   \\end{tabu}\n   \\caption{Basic predicate definitions of the logic.}\n   \\label{tab:sem_definedness}\n\\end{table}\n\\begin{table}[htbp]\n   \\centering\n   \\begin{tabu}{lX[,c,]}\n      \\toprule\n      Name & Theorem \\\\\n      \\midrule\n      @{thm [source] defined1}  & @{thm  defined1} \\\\\n      @{thm [source] defined2}   & @{thm [display=false,margin=35] defined2} \\\\\n      @{thm [source] defined3}   & @{thm [display=false,margin=35] defined3} \\\\\n      @{thm [source] defined4}   & @{thm [display=false,margin=35] defined4} \\\\\n      @{thm [source] defined5}   & @{thm [display=false,margin=35] defined5} \\\\\n      @{thm [source] defined6}   & @{thm [display=false,margin=35] defined6} \\\\\n      \\bottomrule\n   \\end{tabu}\n   \\caption{Laws of the basic predicates of the logic.}\n   \\label{tab:alglaws_definedness}\n\\end{table}\n*}\n\nsection{* The Equalities of OCL *}\ntext{*\n  The OCL contains a particular version of equality, written in\n  Standard documents \\inlineocl+_ = _+ and \\inlineocl+_ <> _+ for its\n  negation, which is referred as \\emph{weak referential equality}\n  hereafter and for which we use the symbol \\inlineisar+_ \\<doteq> _+\n  throughout the formal part of this document. Its semantics is\n  motivated by the desire of fast execution, and similarity to\n  languages like Java and C, but does not satisfy the needs of logical\n  reasoning over OCL expressions and specifications. We therefore\n  introduce a second equality, referred as \\emph{strong equality} or\n  \\emph{logical equality} and written \\inlineisar+_ \\<triangleq> _+\n  which is not present in the current standard but was discussed in\n  prior texts on OCL like the Amsterdam\n  Manifesto~\\cite{cook.ea::amsterdam:2002} and was identified as\n  desirable extension of OCL in the Aachen\n  Meeting~\\cite{brucker.ea:summary-aachen:2013} in the future 2.5 OCL\n  Standard. The purpose of strong equality is to define and reason\n  over OCL. It is therefore a natural task in Featherweight OCL to\n  formally investigate the somewhat quite complex relationship between\n  these two.  *} text{* Strong equality has two motivations: a\n  pragmatic one and a fundamental one.\n  \\begin{enumerate}\n  \\item The pragmatic reason is fairly simple: users of object-oriented languages want \n    something like a ``shallow object value equality''.\n    You will want to say\n    \\inlineisar+ a.boss \\<triangleq>  b.boss@pre +\n    instead of\n\\begin{isar}\n  a.boss \\<doteq> b.boss@pre and  (* just the pointers are equal! *)\n  a.boss.name \\<doteq> b.boss@pre.name@pre and\n  a.boss.age \\<doteq> b.boss@pre.age@pre\n\\end{isar}\n      Breaking a shallow-object equality down to referential equality\n      of attributes is cumbersome, error-prone, and makes\n      specifications difficult to extend (add for example an attribute\n      sex to your class, and check in your OCL specification\n      everywhere that you did it right with your simulation of strong\n      equality).  Therefore, languages like Java offer facilities\n      to handle two different equalities, and it is problematic even\n      in an execution oriented specification language to ignore\n      shallow object equality because it is so common in the code.\n    \\item The fundamental reason goes as follows: whatever you do to\n      reason consistently over a language, you need the concept of\n      equality: you need to know what expressions can be replaced by\n      others because they \\emph{mean the same thing.}  People call\n      this also ``Leibniz Equality'' because this philosopher brought\n      this principle first explicitly to paper and shed some light\n      over it. It is the theoretic foundation of what you do in an\n      optimizing compiler: you replace expressions by \\emph{equal}\n      ones, which you hope are easier to evaluate. In a typed\n      language, strong equality exists uniformly over all types, it is\n      ``polymorphic'' $\\_ = \\_ :: \\alpha * \\alpha \\rightarrow\n      bool$---this is the way that equality is defined in HOL itself.\n      We can express Leibniz principle as one logical rule of\n      surprising simplicity and beauty:\n    \\begin{gather}\n        s = t \\Longrightarrow P(s) = P(t)\n    \\end{gather}\n    ``Whenever we know, that $s$ is equal to $t$, we can replace the\n    sub-expression $s$ in a term $P$ by $t$ and we have that the\n    replacement is equal to the original.''\n\\end{enumerate}\n*}\ntext{*\n  While weak referential equality is defined to be strict in the OCL\n  standard, we will define strong equality as non-strict.  It is quite\n  nasty (but not impossible) to define the logical equality in a\n  strict way (the substitutivity rule above would look more complex),\n  however, whenever references were used, strong equality is needed\n  since references refer to particular states (pre or post), and that\n  they mean the same thing can therefore not be taken for granted.\n*}\n\nsubsection{* Definition *}\ntext{*\n  The strict equality on basic types (actually on all types) must be\n  exceptionally defined on @{term \"null\"}---otherwise the entire\n  concept of null in the language does not make much sense. This is an\n  important exception from the general rule that null\n  arguments---especially if passed as ``self''-argument---lead to\n  invalid results.\n*}\n\n\ntext{*\n  We define strong equality extremely generic, even for types that\n  contain a @{text \"null\"} or @{text \"\\<bottom>\"} element. Strong\n  equality is simply polymorphic in Featherweight OCL, \\ie, is\n  defined identical for all types in OCL and HOL.\n*}\ndefinition StrongEq::\"['\\<AA> st \\<Rightarrow> '\\<alpha>,'\\<AA> st \\<Rightarrow> '\\<alpha>] \\<Rightarrow> ('\\<AA>)Boolean\"  (infixl \"\\<triangleq>\" 30)\nwhere     \"X \\<triangleq> Y \\<equiv>  \\<lambda> \\<tau>. \\<lfloor>\\<lfloor>X \\<tau> = Y \\<tau> \\<rfloor>\\<rfloor>\"\n\ntext{*\n  From this follow already elementary properties like:\n*}\n\n\nlemma [simp,code_unfold]: \"(false \\<triangleq> true) = false\"\nby(rule ext, auto simp: StrongEq_def)\n\n\ntext{*\n  In contrast, referential equality behaves differently for all\n  types---on value types, it is basically strong equality for defined\n  values, but on object types it will compare references---we\n  introduce it as an \\emph{overloaded} concept and will handle it for\n  each type instance individually.\n*}\nconsts StrictRefEq :: \"[('\\<AA>,'a)val,('\\<AA>,'a)val] \\<Rightarrow> ('\\<AA>)Boolean\" (infixl \"\\<doteq>\" 30)\n\n\ntext{*\n  Here is a first instance of a definition of weak equality---for\n  the special case of the type @{typ \"('\\<AA>)Boolean\"}, it is just\n  the strict extension of the logical\n  equality:\n*}\ndefs (overloaded)   StrictRefEq\\<^sub>B\\<^sub>o\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>a\\<^sub>n[code_unfold] :\n      \"(x::('\\<AA>)Boolean) \\<doteq> y \\<equiv> \\<lambda> \\<tau>. if (\\<upsilon> x) \\<tau> = true \\<tau> \\<and> (\\<upsilon> y) \\<tau> = true \\<tau>\n                                    then (x \\<triangleq> y)\\<tau>\n                                    else invalid \\<tau>\"\n\ntext{* which implies elementary properties like: *}                                    \nlemma [simp,code_unfold] : \"(true \\<doteq> false) = false\"\nby(simp add:StrictRefEq\\<^sub>B\\<^sub>o\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>a\\<^sub>n)\nlemma [simp,code_unfold] : \"(false \\<doteq> true) = false\"\nby(simp add:StrictRefEq\\<^sub>B\\<^sub>o\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>a\\<^sub>n)\n\nlemma [simp,code_unfold] : \"(invalid \\<doteq> false) = invalid\"\nby(simp add:StrictRefEq\\<^sub>B\\<^sub>o\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>a\\<^sub>n false_def true_def)\nlemma [simp,code_unfold] : \"(invalid \\<doteq> true) = invalid\"\nby(simp add:StrictRefEq\\<^sub>B\\<^sub>o\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>a\\<^sub>n false_def true_def)\n\nlemma [simp,code_unfold] : \"(false \\<doteq> invalid) = invalid\"\nby(simp add:StrictRefEq\\<^sub>B\\<^sub>o\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>a\\<^sub>n false_def true_def)\nlemma [simp,code_unfold] : \"(true \\<doteq> invalid) = invalid\"\nby(simp add:StrictRefEq\\<^sub>B\\<^sub>o\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>a\\<^sub>n false_def true_def)\n\nlemma [simp,code_unfold] : \"((invalid::('\\<AA>)Boolean) \\<doteq> invalid) = invalid\"\nby(simp add:StrictRefEq\\<^sub>B\\<^sub>o\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>a\\<^sub>n false_def true_def)\ntext{* Thus, the weak equality is \\emph{not} reflexive. *}\n\nlemma null_non_false [simp,code_unfold]:\"(null \\<doteq> false) = false\"\n apply(rule ext, simp add: StrictRefEq\\<^sub>B\\<^sub>o\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>a\\<^sub>n StrongEq_def false_def)\nby (metis OCL_core.drop.simps cp_valid false_def is_none_code(2) is_none_def valid4\n          bot_option_def null_fun_def null_option_def)\n\nlemma null_non_true [simp,code_unfold]:\"(null \\<doteq> true) = false\"\n apply(rule ext, simp add: StrictRefEq\\<^sub>B\\<^sub>o\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>a\\<^sub>n StrongEq_def false_def)\nby(simp add: true_def bot_option_def null_fun_def null_option_def)\n\nlemma false_non_null [simp,code_unfold]:\"(false \\<doteq> null) = false\"\n apply(rule ext, simp add: StrictRefEq\\<^sub>B\\<^sub>o\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>a\\<^sub>n StrongEq_def false_def)\nby (metis OCL_core.drop.simps cp_valid false_def is_none_code(2) is_none_def valid4\n          bot_option_def null_fun_def null_option_def )\n\nlemma true_non_null [simp,code_unfold]:\"(true \\<doteq> null) = false\"\n apply(rule ext, simp add: StrictRefEq\\<^sub>B\\<^sub>o\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>a\\<^sub>n StrongEq_def false_def)\nby(simp add: true_def bot_option_def null_fun_def null_option_def)\n\nsubsection{* Fundamental Predicates on Strong Equality *}\n\ntext{* Equality reasoning in OCL is not humpty dumpty. While strong equality\nis clearly an equivalence: *}\nlemma StrongEq_refl [simp]: \"(X \\<triangleq> X) = true\"\nby(rule ext, simp add: null_def invalid_def true_def false_def StrongEq_def)\n\nlemma StrongEq_sym: \"(X \\<triangleq> Y) = (Y \\<triangleq> X)\"\nby(rule ext, simp add: eq_sym_conv invalid_def true_def false_def StrongEq_def)\n\nlemma StrongEq_trans_strong [simp]:\n  assumes A: \"(X \\<triangleq> Y) = true\"\n  and     B: \"(Y \\<triangleq> Z) = true\"\n  shows   \"(X \\<triangleq> Z) = true\"\n  apply(insert A B) apply(rule ext)\n  apply(simp add: null_def invalid_def true_def false_def StrongEq_def)\n  apply(drule_tac x=x in fun_cong)+\n  by auto\n\ntext{*\n    it is only in a limited sense a congruence, at least from the\n    point of view of this semantic theory. The point is that it is\n    only a congruence on OCL expressions, not arbitrary HOL\n    expressions (with which we can mix Featherweight OCL expressions). A\n    semantic---not syntactic---characterization of OCL expressions is\n    that they are \\emph{context-passing} or \\emph{context-invariant},\n    \\ie, the context of an entire OCL expression, \\ie the pre and\n    post state it referes to, is passed constantly and unmodified to\n    the sub-expressions, \\ie, all sub-expressions inside an OCL\n    expression refer to the same context. Expressed formally, this\n    boils down to:\n*}\nlemma StrongEq_subst :\n  assumes cp: \"\\<And>X. P(X)\\<tau> = P(\\<lambda> _. X \\<tau>)\\<tau>\"\n  and     eq: \"(X \\<triangleq> Y)\\<tau> = true \\<tau>\"\n  shows   \"(P X \\<triangleq> P Y)\\<tau> = true \\<tau>\"\n  apply(insert cp eq)\n  apply(simp add: null_def invalid_def true_def false_def StrongEq_def)\n  apply(subst cp[of X])\n  apply(subst cp[of Y])\n  by simp\n\nlemma defined7[simp]: \"\\<delta> (X \\<triangleq> Y) = true\"\n  by(rule ext,\n     auto simp: defined_def           true_def false_def StrongEq_def\n                bot_fun_def bot_option_def null_option_def null_fun_def)\n\nlemma valid7[simp]: \"\\<upsilon> (X \\<triangleq> Y) = true\"\n  by(rule ext,\n     auto simp: valid_def true_def false_def StrongEq_def\n                bot_fun_def bot_option_def null_option_def null_fun_def)\n\nlemma cp_StrongEq: \"(X \\<triangleq> Y) \\<tau> = ((\\<lambda> _. X \\<tau>) \\<triangleq> (\\<lambda> _. Y \\<tau>)) \\<tau>\"\nby(simp add: StrongEq_def)\n\nsection{* Logical Connectives and their Universal Properties *}\ntext{*\n  It is a design goal to give OCL a semantics that is as closely as\n  possible to a ``logical system'' in a known sense; a specification\n  logic where the logical connectives can not be understood other that\n  having the truth-table aside when reading fails its purpose in our\n  view.\n\n  Practically, this means that we want to give a definition to the\n  core operations to be as close as possible to the lattice laws; this\n  makes also powerful symbolic normalization of OCL specifications\n  possible as a pre-requisite for automated theorem provers. For\n  example, it is still possible to compute without any definedness\n  and validity reasoning the DNF of an OCL specification; be it for\n  test-case generations or for a smooth transition to a two-valued\n  representation of the specification amenable to fast standard\n  SMT-solvers, for example.\n\n  Thus, our representation of the OCL is merely a 4-valued\n  Kleene-Logics with @{term \"invalid\"} as least, @{term \"null\"} as\n  middle and @{term \"true\"} resp.  @{term \"false\"} as unrelated\n  top-elements.\n*}\n\n\ndefinition OclNot :: \"('\\<AA>)Boolean \\<Rightarrow> ('\\<AA>)Boolean\" (\"not\")\nwhere     \"not X \\<equiv>  \\<lambda> \\<tau> . case X \\<tau> of\n                               \\<bottom>     \\<Rightarrow> \\<bottom>\n                           | \\<lfloor> \\<bottom> \\<rfloor>   \\<Rightarrow> \\<lfloor> \\<bottom> \\<rfloor>\n                           | \\<lfloor>\\<lfloor> x \\<rfloor>\\<rfloor>  \\<Rightarrow> \\<lfloor>\\<lfloor> \\<not> x \\<rfloor>\\<rfloor>\"\n\ntext{* with {term \"not\"} we can express the notation:*}\n                           \nsyntax\n  \"notequal\"        :: \"('\\<AA>)Boolean \\<Rightarrow> ('\\<AA>)Boolean \\<Rightarrow> ('\\<AA>)Boolean\"   (infix \"<>\" 40)\ntranslations\n  \"a <> b\" == \"CONST OclNot( a \\<doteq> b)\"\n\n\n                           \nlemma cp_OclNot: \"(not X)\\<tau> = (not (\\<lambda> _. X \\<tau>)) \\<tau>\"\nby(simp add: OclNot_def)\n\nlemma OclNot1[simp]: \"not invalid = invalid\"\n  by(rule ext,simp add: OclNot_def null_def invalid_def true_def false_def bot_option_def)\n\nlemma OclNot2[simp]: \"not null = null\"\n  by(rule ext,simp add: OclNot_def null_def invalid_def true_def false_def\n                        bot_option_def null_fun_def null_option_def )\n\nlemma OclNot3[simp]: \"not true = false\"\n  by(rule ext,simp add: OclNot_def null_def invalid_def true_def false_def)\n\nlemma OclNot4[simp]: \"not false = true\"\n  by(rule ext,simp add: OclNot_def null_def invalid_def true_def false_def)\n\n\nlemma OclNot_not[simp]: \"not (not X) = X\"\n  apply(rule ext,simp add: OclNot_def null_def invalid_def true_def false_def)\n  apply(case_tac \"X x\", simp_all)\n  apply(case_tac \"a\", simp_all)\n  done\n\nlemma OclNot_inject: \"\\<And> x y. not x = not y \\<Longrightarrow> x = y\"\n  by(subst OclNot_not[THEN sym], simp)\n\ndefinition OclAnd :: \"[('\\<AA>)Boolean, ('\\<AA>)Boolean] \\<Rightarrow> ('\\<AA>)Boolean\" (infixl \"and\" 30)\nwhere     \"X and Y \\<equiv>  (\\<lambda> \\<tau> . case X \\<tau> of\n                          \\<lfloor>\\<lfloor>False\\<rfloor>\\<rfloor> \\<Rightarrow>               \\<lfloor>\\<lfloor>False\\<rfloor>\\<rfloor>\n                        | \\<bottom>        \\<Rightarrow> (case Y \\<tau> of\n                                        \\<lfloor>\\<lfloor>False\\<rfloor>\\<rfloor> \\<Rightarrow> \\<lfloor>\\<lfloor>False\\<rfloor>\\<rfloor>\n                                      | _        \\<Rightarrow> \\<bottom>)\n                        | \\<lfloor>\\<bottom>\\<rfloor>      \\<Rightarrow> (case Y \\<tau> of\n                                        \\<lfloor>\\<lfloor>False\\<rfloor>\\<rfloor> \\<Rightarrow> \\<lfloor>\\<lfloor>False\\<rfloor>\\<rfloor>\n                                      | \\<bottom>        \\<Rightarrow> \\<bottom>\n                                      | _        \\<Rightarrow> \\<lfloor>\\<bottom>\\<rfloor>)\n                        | \\<lfloor>\\<lfloor>True\\<rfloor>\\<rfloor>  \\<Rightarrow>               Y \\<tau>)\"\n\n\ntext{*\n  Note that @{term \"not\"} is \\emph{not} defined as a strict function;\n  proximity to lattice laws implies that we \\emph{need} a definition\n  of @{term \"not\"} that satisfies @{text \"not(not(x))=x\"}.\n*}\n\ntext{*\n  In textbook notation, the logical core constructs @{const\n    \"OclNot\"} and @{const \"OclAnd\"} were represented as follows:\n*}\nlemma textbook_OclNot:\n     \"I\\<lbrakk>not(X)\\<rbrakk> \\<tau> =  (case I\\<lbrakk>X\\<rbrakk> \\<tau> of   \\<bottom>   \\<Rightarrow> \\<bottom>\n                                 |  \\<lfloor> \\<bottom> \\<rfloor> \\<Rightarrow> \\<lfloor> \\<bottom> \\<rfloor>\n                                 | \\<lfloor>\\<lfloor> x \\<rfloor>\\<rfloor> \\<Rightarrow> \\<lfloor>\\<lfloor> \\<not> x \\<rfloor>\\<rfloor>)\"\nby(simp add: Sem_def OclNot_def)\n\nlemma textbook_OclAnd:\n     \"I\\<lbrakk>X and Y\\<rbrakk> \\<tau> = (case I\\<lbrakk>X\\<rbrakk> \\<tau> of\n                            \\<bottom>  \\<Rightarrow> (case I\\<lbrakk>Y\\<rbrakk> \\<tau> of\n                                             \\<bottom> \\<Rightarrow>  \\<bottom>\n                                          | \\<lfloor>\\<bottom>\\<rfloor> \\<Rightarrow> \\<bottom>\n                                          | \\<lfloor>\\<lfloor>True\\<rfloor>\\<rfloor> \\<Rightarrow>  \\<bottom>\n                                          | \\<lfloor>\\<lfloor>False\\<rfloor>\\<rfloor> \\<Rightarrow>  \\<lfloor>\\<lfloor>False\\<rfloor>\\<rfloor>)\n                        | \\<lfloor> \\<bottom> \\<rfloor> \\<Rightarrow> (case I\\<lbrakk>Y\\<rbrakk> \\<tau> of\n                                             \\<bottom> \\<Rightarrow>  \\<bottom>\n                                          | \\<lfloor>\\<bottom>\\<rfloor> \\<Rightarrow> \\<lfloor>\\<bottom>\\<rfloor>\n                                          | \\<lfloor>\\<lfloor>True\\<rfloor>\\<rfloor> \\<Rightarrow> \\<lfloor>\\<bottom>\\<rfloor>\n                                          | \\<lfloor>\\<lfloor>False\\<rfloor>\\<rfloor> \\<Rightarrow>  \\<lfloor>\\<lfloor>False\\<rfloor>\\<rfloor>)\n                        | \\<lfloor>\\<lfloor>True\\<rfloor>\\<rfloor> \\<Rightarrow> (case I\\<lbrakk>Y\\<rbrakk> \\<tau> of\n                                             \\<bottom> \\<Rightarrow>  \\<bottom>\n                                          | \\<lfloor>\\<bottom>\\<rfloor> \\<Rightarrow> \\<lfloor>\\<bottom>\\<rfloor>\n                                          | \\<lfloor>\\<lfloor>y\\<rfloor>\\<rfloor> \\<Rightarrow>  \\<lfloor>\\<lfloor>y\\<rfloor>\\<rfloor>)\n                        | \\<lfloor>\\<lfloor>False\\<rfloor>\\<rfloor> \\<Rightarrow>  \\<lfloor>\\<lfloor> False \\<rfloor>\\<rfloor>)\"\nby(simp add: OclAnd_def Sem_def split: option.split bool.split)\n\ndefinition OclOr :: \"[('\\<AA>)Boolean, ('\\<AA>)Boolean] \\<Rightarrow> ('\\<AA>)Boolean\"            (infixl \"or\" 25)\nwhere    \"X or Y \\<equiv> not(not X and not Y)\"\n\ndefinition OclImplies :: \"[('\\<AA>)Boolean, ('\\<AA>)Boolean] \\<Rightarrow> ('\\<AA>)Boolean\"       (infixl \"implies\" 25)\nwhere    \"X implies Y \\<equiv> not X or Y\"\n\nlemma cp_OclAnd:\"(X and Y) \\<tau> = ((\\<lambda> _. X \\<tau>) and (\\<lambda> _. Y \\<tau>)) \\<tau>\"\nby(simp add: OclAnd_def)\n\nlemma cp_OclOr:\"((X::('\\<AA>)Boolean) or Y) \\<tau> = ((\\<lambda> _. X \\<tau>) or (\\<lambda> _. Y \\<tau>)) \\<tau>\"\napply(simp add: OclOr_def)\napply(subst cp_OclNot[of \"not (\\<lambda>_. X \\<tau>) and not (\\<lambda>_. Y \\<tau>)\"])\napply(subst cp_OclAnd[of \"not (\\<lambda>_. X \\<tau>)\" \"not (\\<lambda>_. Y \\<tau>)\"])\nby(simp add: cp_OclNot[symmetric] cp_OclAnd[symmetric] )\n\n\nlemma cp_OclImplies:\"(X implies Y) \\<tau> = ((\\<lambda> _. X \\<tau>) implies (\\<lambda> _. Y \\<tau>)) \\<tau>\"\napply(simp add: OclImplies_def)\napply(subst cp_OclOr[of \"not (\\<lambda>_. X \\<tau>)\" \"(\\<lambda>_. Y \\<tau>)\"])\nby(simp add: cp_OclNot[symmetric] cp_OclOr[symmetric] )\n\nlemma OclAnd1[simp]: \"(invalid and true) = invalid\"\n  by(rule ext,simp add: OclAnd_def null_def invalid_def true_def false_def bot_option_def)\nlemma OclAnd2[simp]: \"(invalid and false) = false\"\n  by(rule ext,simp add: OclAnd_def null_def invalid_def true_def false_def bot_option_def)\nlemma OclAnd3[simp]: \"(invalid and null) = invalid\"\n  by(rule ext,simp add: OclAnd_def null_def invalid_def true_def false_def bot_option_def\n                        null_fun_def null_option_def)\nlemma OclAnd4[simp]: \"(invalid and invalid) = invalid\"\n  by(rule ext,simp add: OclAnd_def null_def invalid_def true_def false_def bot_option_def)\n\nlemma OclAnd5[simp]: \"(null and true) = null\"\n  by(rule ext,simp add: OclAnd_def null_def invalid_def true_def false_def bot_option_def\n                        null_fun_def null_option_def)\nlemma OclAnd6[simp]: \"(null and false) = false\"\n  by(rule ext,simp add: OclAnd_def null_def invalid_def true_def false_def bot_option_def\n                        null_fun_def null_option_def)\nlemma OclAnd7[simp]: \"(null and null) = null\"\n  by(rule ext,simp add: OclAnd_def null_def invalid_def true_def false_def bot_option_def\n                        null_fun_def null_option_def)\nlemma OclAnd8[simp]: \"(null and invalid) = invalid\"\n  by(rule ext,simp add: OclAnd_def null_def invalid_def true_def false_def bot_option_def\n                        null_fun_def null_option_def)\n\nlemma OclAnd9[simp]: \"(false and true) = false\"\n  by(rule ext,simp add: OclAnd_def null_def invalid_def true_def false_def)\nlemma OclAnd10[simp]: \"(false and false) = false\"\n  by(rule ext,simp add: OclAnd_def null_def invalid_def true_def false_def)\nlemma OclAnd11[simp]: \"(false and null) = false\"\n  by(rule ext,simp add: OclAnd_def null_def invalid_def true_def false_def)\nlemma OclAnd12[simp]: \"(false and invalid) = false\"\n  by(rule ext,simp add: OclAnd_def null_def invalid_def true_def false_def)\n\nlemma OclAnd13[simp]: \"(true and true) = true\"\n  by(rule ext,simp add: OclAnd_def null_def invalid_def true_def false_def)\nlemma OclAnd14[simp]: \"(true and false) = false\"\n  by(rule ext,simp add: OclAnd_def null_def invalid_def true_def false_def)\nlemma OclAnd15[simp]: \"(true and null) = null\"\n  by(rule ext,simp add: OclAnd_def null_def invalid_def true_def false_def bot_option_def\n                        null_fun_def null_option_def)\nlemma OclAnd16[simp]: \"(true and invalid) = invalid\"\n  by(rule ext,simp add: OclAnd_def null_def invalid_def true_def false_def bot_option_def\n                        null_fun_def null_option_def)\n\nlemma OclAnd_idem[simp]: \"(X and X) = X\"\n  apply(rule ext,simp add: OclAnd_def null_def invalid_def true_def false_def)\n  apply(case_tac \"X x\", simp_all)\n  apply(case_tac \"a\", simp_all)\n  apply(case_tac \"aa\", simp_all)\n  done\n\nlemma OclAnd_commute: \"(X and Y) = (Y and X)\"\n  by(rule ext,auto simp:true_def false_def OclAnd_def invalid_def\n                   split: option.split option.split_asm\n                          bool.split bool.split_asm)\n\n\nlemma OclAnd_false1[simp]: \"(false and X) = false\"\n  apply(rule ext, simp add: OclAnd_def)\n  apply(auto simp:true_def false_def invalid_def\n             split: option.split option.split_asm)\n  done\n\nlemma OclAnd_false2[simp]: \"(X and false) = false\"\n  by(simp add: OclAnd_commute)\n\n\nlemma OclAnd_true1[simp]: \"(true and X) = X\"\n  apply(rule ext, simp add: OclAnd_def)\n  apply(auto simp:true_def false_def invalid_def\n             split: option.split option.split_asm)\n  done\n\nlemma OclAnd_true2[simp]: \"(X and true) = X\"\n  by(simp add: OclAnd_commute)\n\nlemma OclAnd_bot1[simp]: \"\\<And>\\<tau>. X \\<tau> \\<noteq> false \\<tau> \\<Longrightarrow> (bot and X) \\<tau> = bot \\<tau>\"\n  apply(simp add: OclAnd_def)\n  apply(auto simp:true_def false_def bot_fun_def bot_option_def\n             split: option.split option.split_asm)\ndone\n\nlemma OclAnd_bot2[simp]: \"\\<And>\\<tau>. X \\<tau> \\<noteq> false \\<tau> \\<Longrightarrow> (X and bot) \\<tau> = bot \\<tau>\"\n  by(simp add: OclAnd_commute)\n\nlemma OclAnd_null1[simp]: \"\\<And>\\<tau>. X \\<tau> \\<noteq> false \\<tau> \\<Longrightarrow> X \\<tau> \\<noteq> bot \\<tau> \\<Longrightarrow> (null and X) \\<tau> = null \\<tau>\"\n  apply(simp add: OclAnd_def)\n  apply(auto simp:true_def false_def bot_fun_def bot_option_def null_fun_def null_option_def\n             split: option.split option.split_asm)\ndone\n\n\n\nlemma OclAnd_assoc: \"(X and (Y and Z)) = (X and Y and Z)\"\n  apply(rule ext, simp add: OclAnd_def)\n  apply(auto simp:true_def false_def null_def invalid_def\n             split: option.split option.split_asm\n                    bool.split bool.split_asm)\ndone\n\n\nlemma OclOr1[simp]: \"(invalid or true) = true\"\nby(rule ext, simp add: OclOr_def OclNot_def OclAnd_def null_def invalid_def true_def false_def\n                       bot_option_def)\nlemma OclOr2[simp]: \"(invalid or false) = invalid\"\nby(rule ext, simp add: OclOr_def OclNot_def OclAnd_def null_def invalid_def true_def false_def\n                       bot_option_def)\nlemma OclOr3[simp]: \"(invalid or null) = invalid\"\nby(rule ext, simp add: OclOr_def OclNot_def OclAnd_def null_def invalid_def true_def false_def\n                       bot_option_def null_fun_def null_option_def)\nlemma OclOr4[simp]: \"(invalid or invalid) = invalid\"\nby(rule ext, simp add: OclOr_def OclNot_def OclAnd_def null_def invalid_def true_def false_def\n                       bot_option_def)\n\nlemma OclOr5[simp]: \"(null or true) = true\"\nby(rule ext, simp add: OclOr_def OclNot_def OclAnd_def null_def invalid_def true_def false_def\n                       bot_option_def null_fun_def null_option_def)\nlemma OclOr6[simp]: \"(null or false) = null\"\nby(rule ext, simp add: OclOr_def OclNot_def OclAnd_def null_def invalid_def true_def false_def\n                       bot_option_def null_fun_def null_option_def)\nlemma OclOr7[simp]: \"(null or null) = null\"\nby(rule ext, simp add: OclOr_def OclNot_def OclAnd_def null_def invalid_def true_def false_def\n                       bot_option_def null_fun_def null_option_def)\nlemma OclOr8[simp]: \"(null or invalid) = invalid\"\nby(rule ext, simp add: OclOr_def OclNot_def OclAnd_def null_def invalid_def true_def false_def \n                       bot_option_def null_fun_def null_option_def)\n\n\n\nlemma OclOr_commute: \"(X or Y) = (Y or X)\"\n  by(simp add: OclOr_def OclAnd_commute)\n\nlemma OclOr_false1[simp]: \"(false or Y) = Y\"\n  by(simp add: OclOr_def)\n\nlemma OclOr_false2[simp]: \"(Y or false) = Y\"\n  by(simp add: OclOr_def)\n\nlemma OclOr_true1[simp]: \"(true or Y) = true\"\n  by(simp add: OclOr_def)\n\nlemma OclOr_true2: \"(Y or true) = true\"\n  by(simp add: OclOr_def)\n\nlemma OclOr_bot1[simp]: \"\\<And>\\<tau>. X \\<tau> \\<noteq> true \\<tau> \\<Longrightarrow> (bot or X) \\<tau> = bot \\<tau>\"\n  apply(simp add: OclOr_def OclAnd_def OclNot_def)\n  apply(auto simp:true_def false_def bot_fun_def bot_option_def\n             split: option.split option.split_asm)\ndone\n\nlemma OclOr_bot2[simp]: \"\\<And>\\<tau>. X \\<tau> \\<noteq> true \\<tau> \\<Longrightarrow> (X or bot) \\<tau> = bot \\<tau>\"\n  by(simp add: OclOr_commute)\n\nlemma OclOr_null1[simp]: \"\\<And>\\<tau>. X \\<tau> \\<noteq> true \\<tau> \\<Longrightarrow> X \\<tau> \\<noteq> bot \\<tau> \\<Longrightarrow> (null or X) \\<tau> = null \\<tau>\"\n  apply(simp add: OclOr_def OclAnd_def OclNot_def)\n  apply(auto simp:true_def false_def bot_fun_def bot_option_def null_fun_def null_option_def\n             split: option.split option.split_asm)\n  apply (metis (full_types) bool.simps(3) bot_option_def null_is_valid null_option_def)\nby (metis (full_types) bool.simps(3) option.distinct(1) option.sel)\n\nlemma OclOr_null2[simp]: \"\\<And>\\<tau>. X \\<tau> \\<noteq> true \\<tau> \\<Longrightarrow> X \\<tau> \\<noteq> bot \\<tau> \\<Longrightarrow> (X or null) \\<tau> = null \\<tau>\"\n  by(simp add: OclOr_commute)\n\nlemma OclOr_assoc: \"(X or (Y or Z)) = (X or Y or Z)\"\n  by(simp add: OclOr_def OclAnd_assoc)\n\nlemma OclImplies_true: \"(X implies true) = true\"\n  by (simp add: OclImplies_def OclOr_true2)\n\nlemma deMorgan1: \"not(X and Y) = ((not X) or (not Y))\"\n  by(simp add: OclOr_def)\n\nlemma deMorgan2: \"not(X or Y) = ((not X) and (not Y))\"\n  by(simp add: OclOr_def)\n\n\nsection{* A Standard Logical Calculus for OCL *}\ndefinition OclValid  :: \"[('\\<AA>)st, ('\\<AA>)Boolean] \\<Rightarrow> bool\" (\"(1(_)/ \\<Turnstile> (_))\" 50)\nwhere     \"\\<tau> \\<Turnstile> P \\<equiv> ((P \\<tau>) = true \\<tau>)\"\n\nvalue \"\\<tau> \\<Turnstile> true <> false\"\nvalue \"\\<tau> \\<Turnstile> false <> true\"\n\nsubsection{* Global vs. Local Judgements*}\nlemma transform1: \"P = true \\<Longrightarrow> \\<tau> \\<Turnstile> P\"\nby(simp add: OclValid_def)\n\n\nlemma transform1_rev: \"\\<forall> \\<tau>. \\<tau> \\<Turnstile> P \\<Longrightarrow> P = true\"\nby(rule ext, auto simp: OclValid_def true_def)\n\nlemma transform2: \"(P = Q) \\<Longrightarrow> ((\\<tau> \\<Turnstile> P) = (\\<tau> \\<Turnstile> Q))\"\nby(auto simp: OclValid_def)\n\nlemma transform2_rev: \"\\<forall> \\<tau>. (\\<tau> \\<Turnstile> \\<delta> P) \\<and> (\\<tau> \\<Turnstile> \\<delta> Q) \\<and> (\\<tau> \\<Turnstile> P) = (\\<tau> \\<Turnstile> Q) \\<Longrightarrow> P = Q\"\napply(rule ext,auto simp: OclValid_def true_def defined_def)\napply(erule_tac x=a in allE)\napply(erule_tac x=b in allE)\napply(auto simp: false_def true_def defined_def bot_Boolean_def null_Boolean_def\n                 split: option.split_asm HOL.split_if_asm)\ndone\n(* Something stronger is possible here (consider P null, Q invalid),\n   but this thingi should do for our purpose *)\n\ntext{* However, certain properties (like transitivity) can not\n       be \\emph{transformed} from the global level to the local one,\n       they have to be re-proven on the local level. *}\n\nlemma (*transform3:*)\nassumes H : \"P = true \\<Longrightarrow> Q = true\"\nshows \"\\<tau> \\<Turnstile> P \\<Longrightarrow> \\<tau> \\<Turnstile> Q\"\napply(simp add: OclValid_def)\napply(rule H[THEN fun_cong])\napply(rule ext)\noops\n\nsubsection{* Local Validity and Meta-logic*}\ntext{* \\label{sec:localVal} *}\n\nlemma foundation1[simp]: \"\\<tau> \\<Turnstile> true\"\nby(auto simp: OclValid_def)\n\nlemma foundation2[simp]: \"\\<not>(\\<tau> \\<Turnstile> false)\"\nby(auto simp: OclValid_def true_def false_def)\n\nlemma foundation3[simp]: \"\\<not>(\\<tau> \\<Turnstile> invalid)\"\nby(auto simp: OclValid_def true_def false_def invalid_def bot_option_def)\n\nlemma foundation4[simp]: \"\\<not>(\\<tau> \\<Turnstile> null)\"\nby(auto simp: OclValid_def true_def false_def null_def null_fun_def null_option_def bot_option_def)\n\nlemma bool_split_local[simp]:\n\"(\\<tau> \\<Turnstile> (x \\<triangleq> invalid)) \\<or> (\\<tau> \\<Turnstile> (x \\<triangleq> null)) \\<or> (\\<tau> \\<Turnstile> (x \\<triangleq> true)) \\<or> (\\<tau> \\<Turnstile> (x \\<triangleq> false))\"\napply(insert bool_split[of x \\<tau>], auto)\napply(simp_all add: OclValid_def StrongEq_def true_def null_def invalid_def)\ndone\n\nlemma def_split_local:\n\"(\\<tau> \\<Turnstile> \\<delta> x) = ((\\<not>(\\<tau> \\<Turnstile> (x \\<triangleq> invalid))) \\<and> (\\<not> (\\<tau> \\<Turnstile> (x \\<triangleq> null))))\"\nby(simp add:defined_def true_def false_def invalid_def null_def\n               StrongEq_def OclValid_def bot_fun_def null_fun_def)\n\nlemma foundation5:\n\"\\<tau> \\<Turnstile> (P and Q) \\<Longrightarrow> (\\<tau> \\<Turnstile> P) \\<and> (\\<tau> \\<Turnstile> Q)\"\nby(simp add: OclAnd_def OclValid_def true_def false_def defined_def\n             split: option.split option.split_asm bool.split bool.split_asm)\n\nlemma foundation6:\n\"\\<tau> \\<Turnstile> P \\<Longrightarrow> \\<tau> \\<Turnstile> \\<delta> P\"\nby(simp add: OclNot_def OclValid_def true_def false_def defined_def\n                null_option_def null_fun_def bot_option_def bot_fun_def\n             split: option.split option.split_asm)\n\n\nlemma foundation7[simp]:\n\"(\\<tau> \\<Turnstile> not (\\<delta> x)) = (\\<not> (\\<tau> \\<Turnstile> \\<delta> x))\"\nby(simp add: OclNot_def OclValid_def true_def false_def defined_def\n             split: option.split option.split_asm)\n\nlemma foundation7'[simp]:\n\"(\\<tau> \\<Turnstile> not (\\<upsilon> x)) = (\\<not> (\\<tau> \\<Turnstile> \\<upsilon> x))\"\nby(simp add: OclNot_def OclValid_def true_def false_def valid_def\n             split: option.split option.split_asm)\n\n\ntext{*\n  Key theorem for the $\\delta$-closure: either an expression is\n  defined, or it can be replaced (substituted via @{text \"StrongEq_L_subst2\"};\n  see below) by @{text invalid} or @{text null}. Strictness-reduction rules will\n  usually reduce these substituted terms drastically.\n*}\nlemma foundation8:\n\"(\\<tau> \\<Turnstile> \\<delta> x) \\<or> (\\<tau> \\<Turnstile> (x \\<triangleq> invalid)) \\<or> (\\<tau> \\<Turnstile> (x \\<triangleq> null))\"\nproof -\n  have 1 : \"(\\<tau> \\<Turnstile> \\<delta> x) \\<or> (\\<not>(\\<tau> \\<Turnstile> \\<delta> x))\" by auto\n  have 2 : \"(\\<not>(\\<tau> \\<Turnstile> \\<delta> x)) = ((\\<tau> \\<Turnstile> (x \\<triangleq> invalid)) \\<or> (\\<tau> \\<Turnstile> (x \\<triangleq> null)))\"\n           by(simp only: def_split_local, simp)\n  show ?thesis by(insert 1, simp add:2)\nqed\n\nlemma foundation9:\n\"\\<tau> \\<Turnstile> \\<delta> x \\<Longrightarrow> (\\<tau> \\<Turnstile> not x) = (\\<not> (\\<tau> \\<Turnstile> x))\"\napply(simp add: def_split_local )\nby(auto simp: OclNot_def null_fun_def null_option_def bot_option_def\n                 OclValid_def invalid_def true_def null_def StrongEq_def)\n\n\nlemma foundation10:\n\"\\<tau> \\<Turnstile> \\<delta> x \\<Longrightarrow> \\<tau> \\<Turnstile> \\<delta> y \\<Longrightarrow> (\\<tau> \\<Turnstile> (x and y)) = ( (\\<tau> \\<Turnstile> x) \\<and> (\\<tau> \\<Turnstile> y))\"\napply(simp add: def_split_local)\nby(auto simp: OclAnd_def OclValid_def invalid_def\n              true_def null_def StrongEq_def null_fun_def null_option_def bot_option_def\n        split:bool.split_asm)\n\n\nlemma foundation11:\n\"\\<tau> \\<Turnstile> \\<delta> x \\<Longrightarrow>  \\<tau> \\<Turnstile> \\<delta> y \\<Longrightarrow> (\\<tau> \\<Turnstile> (x or y)) = ( (\\<tau> \\<Turnstile> x) \\<or> (\\<tau> \\<Turnstile> y))\"\napply(simp add: def_split_local)\nby(auto simp: OclNot_def OclOr_def OclAnd_def OclValid_def invalid_def\n              true_def null_def StrongEq_def null_fun_def null_option_def bot_option_def\n        split:bool.split_asm bool.split)\n\n\n\nlemma foundation12:\n\"\\<tau> \\<Turnstile> \\<delta> x \\<Longrightarrow>  \\<tau> \\<Turnstile> \\<delta> y \\<Longrightarrow> (\\<tau> \\<Turnstile> (x implies y)) = ( (\\<tau> \\<Turnstile> x) \\<longrightarrow> (\\<tau> \\<Turnstile> y))\"\napply(simp add: def_split_local)\nby(auto simp: OclNot_def OclOr_def OclAnd_def OclImplies_def bot_option_def\n              OclValid_def invalid_def true_def null_def StrongEq_def null_fun_def null_option_def\n        split:bool.split_asm bool.split)\n\nlemma foundation13:\"(\\<tau> \\<Turnstile> A \\<triangleq> true)    = (\\<tau> \\<Turnstile> A)\"\nby(auto simp: OclNot_def  OclValid_def invalid_def true_def null_def StrongEq_def\n           split:bool.split_asm bool.split)\n\nlemma foundation14:\"(\\<tau> \\<Turnstile> A \\<triangleq> false)   = (\\<tau> \\<Turnstile> not A)\"\nby(auto simp: OclNot_def  OclValid_def invalid_def false_def true_def null_def StrongEq_def\n        split:bool.split_asm bool.split option.split)\n\nlemma foundation15:\"(\\<tau> \\<Turnstile> A \\<triangleq> invalid) = (\\<tau> \\<Turnstile> not(\\<upsilon> A))\"\nby(auto simp: OclNot_def OclValid_def valid_def invalid_def false_def true_def null_def\n              StrongEq_def bot_option_def null_fun_def null_option_def bot_option_def bot_fun_def\n        split:bool.split_asm bool.split option.split)\n\n\n(* ... and the usual rules on strictness, definedness propoagation, and cp ... *)\nlemma foundation16: \"\\<tau> \\<Turnstile> (\\<delta> X) = (X \\<tau> \\<noteq> bot \\<and> X \\<tau> \\<noteq> null)\"\nby(auto simp: OclValid_def defined_def false_def true_def  bot_fun_def null_fun_def\n        split:split_if_asm)\n\n(* correcter rule; the previous is deprecated *)\nlemma foundation16': \"(\\<tau> \\<Turnstile> (\\<delta> X)) = (X \\<tau> \\<noteq> invalid \\<tau> \\<and> X \\<tau> \\<noteq> null \\<tau>)\"\napply(simp add:invalid_def null_def null_fun_def)\nby(auto simp: OclValid_def defined_def false_def true_def  bot_fun_def null_fun_def\n        split:split_if_asm)\n\nlemmas foundation17 = foundation16[THEN iffD1]\n(* correcter rule; the previous is deprecated *)\nlemmas foundation17' = foundation16'[THEN iffD1]\n\nlemma foundation18: \"\\<tau> \\<Turnstile> (\\<upsilon> X) = (X \\<tau> \\<noteq> invalid \\<tau>)\"\nby(auto simp: OclValid_def valid_def false_def true_def bot_fun_def invalid_def\n        split:split_if_asm)\n\n(*legacy*)\nlemma foundation18': \"\\<tau> \\<Turnstile> (\\<upsilon> X) = (X \\<tau> \\<noteq> bot)\"\nby(auto simp: OclValid_def valid_def false_def true_def bot_fun_def\n        split:split_if_asm)\n\n\nlemmas foundation19 = foundation18[THEN iffD1]\n\nlemma foundation20 : \"\\<tau> \\<Turnstile> (\\<delta> X) \\<Longrightarrow> \\<tau> \\<Turnstile> \\<upsilon> X\"\nby(simp add: foundation18 foundation16 invalid_def)\n\nlemma foundation21: \"(not A \\<triangleq> not B) = (A \\<triangleq> B)\"\nby(rule ext, auto simp: OclNot_def StrongEq_def\n                     split: bool.split_asm HOL.split_if_asm option.split)\n\nlemma foundation22: \"(\\<tau> \\<Turnstile> (X \\<triangleq> Y)) = (X \\<tau> = Y \\<tau>)\"\nby(auto simp: StrongEq_def OclValid_def true_def)\n\nlemma foundation23: \"(\\<tau> \\<Turnstile> P) = (\\<tau> \\<Turnstile> (\\<lambda> _ . P \\<tau>))\"\nby(auto simp: OclValid_def true_def)\n\nlemmas cp_validity=foundation23\n\nlemma foundation24:\"(\\<tau> \\<Turnstile> not(X \\<triangleq> Y)) = (X \\<tau> \\<noteq> Y \\<tau>)\"\nby(simp add: StrongEq_def  OclValid_def OclNot_def true_def)\n\n\nlemma defined_not_I : \"\\<tau> \\<Turnstile> \\<delta> (x) \\<Longrightarrow> \\<tau> \\<Turnstile> \\<delta> (not x)\"\n  by(auto simp: OclNot_def null_def invalid_def defined_def valid_def OclValid_def\n                  true_def false_def bot_option_def null_option_def null_fun_def bot_fun_def\n             split: option.split_asm HOL.split_if_asm)\n\nlemma valid_not_I : \"\\<tau> \\<Turnstile> \\<upsilon> (x) \\<Longrightarrow> \\<tau> \\<Turnstile> \\<upsilon> (not x)\"\n  by(auto simp: OclNot_def null_def invalid_def defined_def valid_def OclValid_def\n                  true_def false_def bot_option_def null_option_def null_fun_def bot_fun_def\n          split: option.split_asm option.split HOL.split_if_asm)\n\nlemma defined_and_I : \"\\<tau> \\<Turnstile> \\<delta> (x) \\<Longrightarrow>  \\<tau> \\<Turnstile> \\<delta> (y) \\<Longrightarrow> \\<tau> \\<Turnstile> \\<delta> (x and y)\"\n  apply(simp add: OclAnd_def null_def invalid_def defined_def valid_def OclValid_def\n                  true_def false_def bot_option_def null_option_def null_fun_def bot_fun_def\n             split: option.split_asm HOL.split_if_asm)\n  apply(auto simp: null_option_def split: bool.split)\n  by(case_tac \"ya\",simp_all)\n\nlemma valid_and_I :   \"\\<tau> \\<Turnstile> \\<upsilon> (x) \\<Longrightarrow>  \\<tau> \\<Turnstile> \\<upsilon> (y) \\<Longrightarrow> \\<tau> \\<Turnstile> \\<upsilon> (x and y)\"\n  apply(simp add: OclAnd_def null_def invalid_def defined_def valid_def OclValid_def\n                  true_def false_def bot_option_def null_option_def null_fun_def bot_fun_def\n             split: option.split_asm HOL.split_if_asm)\n  by(auto simp: null_option_def split: option.split bool.split)\n\n\n\nsubsection{* Local Judgements and Strong Equality *}\n\nlemma StrongEq_L_refl: \"\\<tau> \\<Turnstile> (x \\<triangleq> x)\"\nby(simp add: OclValid_def StrongEq_def)\n\n\nlemma StrongEq_L_sym: \"\\<tau> \\<Turnstile> (x \\<triangleq> y) \\<Longrightarrow> \\<tau> \\<Turnstile> (y \\<triangleq> x)\"\nby(simp add: StrongEq_sym)\n\nlemma StrongEq_L_trans: \"\\<tau> \\<Turnstile> (x \\<triangleq> y) \\<Longrightarrow> \\<tau> \\<Turnstile> (y \\<triangleq> z) \\<Longrightarrow> \\<tau> \\<Turnstile> (x \\<triangleq> z)\"\nby(simp add: OclValid_def StrongEq_def true_def)\n\n\n\ntext{* In order to establish substitutivity (which does not\nhold in general HOL formulas) we introduce the following\npredicate that allows for a calculus of the necessary side-conditions.*}\ndefinition cp   :: \"(('\\<AA>,'\\<alpha>) val \\<Rightarrow> ('\\<AA>,'\\<beta>) val) \\<Rightarrow> bool\"\nwhere     \"cp P \\<equiv> (\\<exists> f. \\<forall> X \\<tau>. P X \\<tau> = f (X \\<tau>) \\<tau>)\"\n\n\ntext{* The rule of substitutivity in Featherweight OCL holds only\nfor context-passing expressions, \\ie those that pass\nthe context @{text \"\\<tau>\"} without changing it. Fortunately, all\noperators of the OCL language satisfy this property\n(but not all HOL operators).*}\n\nlemma StrongEq_L_subst1: \"\\<And> \\<tau>. cp P \\<Longrightarrow> \\<tau> \\<Turnstile> (x \\<triangleq> y) \\<Longrightarrow> \\<tau> \\<Turnstile> (P x \\<triangleq> P y)\"\nby(auto simp: OclValid_def StrongEq_def true_def cp_def)\n\nlemma StrongEq_L_subst2:\n\"\\<And> \\<tau>.  cp P \\<Longrightarrow> \\<tau> \\<Turnstile> (x \\<triangleq> y) \\<Longrightarrow> \\<tau> \\<Turnstile> (P x) \\<Longrightarrow> \\<tau> \\<Turnstile> (P y)\"\nby(auto simp: OclValid_def StrongEq_def true_def cp_def)\n\nlemma StrongEq_L_subst2_rev: \"\\<tau> \\<Turnstile> y \\<triangleq> x \\<Longrightarrow> cp P \\<Longrightarrow> \\<tau> \\<Turnstile> P x \\<Longrightarrow> \\<tau> \\<Turnstile> P y\"\napply(erule StrongEq_L_subst2)\napply(erule StrongEq_L_sym)\nby assumption\n\nlemma  StrongEq_L_subst3:\nassumes cp: \"cp P\"\nand     eq: \"\\<tau> \\<Turnstile> x \\<triangleq> y\"\nshows       \"(\\<tau> \\<Turnstile> P x) = (\\<tau> \\<Turnstile> P y)\"\napply(rule iffI)\napply(rule OCL_core.StrongEq_L_subst2[OF cp,OF eq],simp)\napply(rule OCL_core.StrongEq_L_subst2[OF cp,OF eq[THEN StrongEq_L_sym]],simp)\ndone\n\n\nlemma cpI1:\n\"(\\<forall> X \\<tau>. f X \\<tau> = f(\\<lambda>_. X \\<tau>) \\<tau>) \\<Longrightarrow> cp P \\<Longrightarrow> cp(\\<lambda>X. f (P X))\"\napply(auto simp: true_def cp_def)\napply(rule exI, (rule allI)+)\nby(erule_tac x=\"P X\" in allE, auto)\n\nlemma cpI2:\n\"(\\<forall> X Y \\<tau>. f X Y \\<tau> = f(\\<lambda>_. X \\<tau>)(\\<lambda>_. Y \\<tau>) \\<tau>) \\<Longrightarrow>\n cp P \\<Longrightarrow> cp Q \\<Longrightarrow> cp(\\<lambda>X. f (P X) (Q X))\"\napply(auto simp: true_def cp_def)\napply(rule exI, (rule allI)+)\nby(erule_tac x=\"P X\" in allE, auto)\n \nlemma cpI3:\n\"(\\<forall> X Y Z \\<tau>. f X Y Z \\<tau> = f(\\<lambda>_. X \\<tau>)(\\<lambda>_. Y \\<tau>)(\\<lambda>_. Z \\<tau>) \\<tau>) \\<Longrightarrow>\n cp P \\<Longrightarrow> cp Q \\<Longrightarrow> cp R \\<Longrightarrow> cp(\\<lambda>X. f (P X) (Q X) (R X))\"\napply(auto simp: cp_def)\napply(rule exI, (rule allI)+)\nby(erule_tac x=\"P X\" in allE, auto)\n\nlemma cpI4:\n\"(\\<forall> W X Y Z \\<tau>. f W X Y Z \\<tau> = f(\\<lambda>_. W \\<tau>)(\\<lambda>_. X \\<tau>)(\\<lambda>_. Y \\<tau>)(\\<lambda>_. Z \\<tau>) \\<tau>) \\<Longrightarrow>\n cp P \\<Longrightarrow> cp Q \\<Longrightarrow> cp R \\<Longrightarrow> cp S \\<Longrightarrow> cp(\\<lambda>X. f (P X) (Q X) (R X) (S X))\"\napply(auto simp: cp_def)\napply(rule exI, (rule allI)+)\nby(erule_tac x=\"P X\" in allE, auto)\n\nlemma cp_const : \"cp(\\<lambda>_. c)\"\n  by (simp add: cp_def, fast)\n\nlemma cp_id :     \"cp(\\<lambda>X. X)\"\n  by (simp add: cp_def, fast)\n\nlemmas cp_intro[intro!,simp,code_unfold] =\n       cp_const\n       cp_id\n       cp_defined[THEN allI[THEN allI[THEN cpI1], of defined]]\n       cp_valid[THEN allI[THEN allI[THEN cpI1], of valid]]\n       cp_OclNot[THEN allI[THEN allI[THEN cpI1], of not]]\n       cp_OclAnd[THEN allI[THEN allI[THEN allI[THEN cpI2]], of \"op and\"]]\n       cp_OclOr[THEN allI[THEN allI[THEN allI[THEN cpI2]], of \"op or\"]]\n       cp_OclImplies[THEN allI[THEN allI[THEN allI[THEN cpI2]], of \"op implies\"]]\n       cp_StrongEq[THEN allI[THEN allI[THEN allI[THEN cpI2]],\n             of \"StrongEq\"]]\n\nsubsection{* Laws to Establish Definedness ($\\delta$-closure) *}\n\ntext{* For the logical connectives, we have --- beyond\n@{thm foundation6} --- the following facts:  *}\nlemma OclNot_defargs:\n\"\\<tau> \\<Turnstile> (not P) \\<Longrightarrow> \\<tau> \\<Turnstile> \\<delta> P\"\nby(auto simp: OclNot_def OclValid_def true_def invalid_def defined_def false_def\n                 bot_fun_def bot_option_def null_fun_def null_option_def\n        split: bool.split_asm HOL.split_if_asm option.split option.split_asm)\n\nlemma OclNot_contrapos_nn:\n assumes \"\\<tau> \\<Turnstile> \\<delta> A\"\n assumes \"\\<tau> \\<Turnstile> not B\"\n assumes \"\\<tau> \\<Turnstile> A \\<Longrightarrow> \\<tau> \\<Turnstile> B\"\n shows   \"\\<tau> \\<Turnstile> not A\"\nproof -\n have change_not : \"\\<And>a b. (not a \\<tau> = b \\<tau>) = (a \\<tau> = not b \\<tau>)\"\n by (metis OclNot_not cp_OclNot)\n show ?thesis\n  apply(insert assms, simp add: OclValid_def, subst change_not, subst (asm) change_not)\n  apply(simp add: OclNot_def true_def)\n by (metis OclValid_def bool_split defined_def false_def foundation2 true_def\n           bot_fun_def invalid_def)\nqed\n\ntext{* So far, we have only one strict Boolean predicate (-family): the strict equality. *}\n\nsection{* Miscellaneous *}\n\nsubsection{* OCL's if then else endif *}\n\ndefinition OclIf :: \"[('\\<AA>)Boolean , ('\\<AA>,'\\<alpha>::null) val, ('\\<AA>,'\\<alpha>) val] \\<Rightarrow> ('\\<AA>,'\\<alpha>) val\"\n                     (\"if (_) then (_) else (_) endif\" [10,10,10]50)\nwhere \"(if C then B\\<^sub>1 else B\\<^sub>2 endif) = (\\<lambda> \\<tau>. if (\\<delta> C) \\<tau> = true \\<tau>\n                                           then (if (C \\<tau>) = true \\<tau>\n                                                then B\\<^sub>1 \\<tau>\n                                                else B\\<^sub>2 \\<tau>)\n                                           else invalid \\<tau>)\"\n\n\nlemma cp_OclIf:\"((if C then B\\<^sub>1 else B\\<^sub>2 endif) \\<tau> =\n                  (if (\\<lambda> _. C \\<tau>) then (\\<lambda> _. B\\<^sub>1 \\<tau>) else (\\<lambda> _. B\\<^sub>2 \\<tau>) endif) \\<tau>)\"\nby(simp only: OclIf_def, subst cp_defined, rule refl)\n\nlemmas cp_intro'[intro!,simp,code_unfold] =\n       cp_intro\n       cp_OclIf[THEN allI[THEN allI[THEN allI[THEN allI[THEN cpI3]]], of \"OclIf\"]]\n\nlemma OclIf_invalid [simp]: \"(if invalid then B\\<^sub>1 else B\\<^sub>2 endif) = invalid\"\nby(rule ext, auto simp: OclIf_def)\n\nlemma OclIf_null [simp]: \"(if null then B\\<^sub>1 else B\\<^sub>2 endif) = invalid\"\nby(rule ext, auto simp: OclIf_def)\n\nlemma OclIf_true [simp]: \"(if true then B\\<^sub>1 else B\\<^sub>2 endif) = B\\<^sub>1\"\nby(rule ext, auto simp: OclIf_def)\n\nlemma OclIf_true' [simp]: \"\\<tau> \\<Turnstile> P \\<Longrightarrow> (if P then B\\<^sub>1 else B\\<^sub>2 endif)\\<tau> = B\\<^sub>1 \\<tau>\"\napply(subst cp_OclIf,auto simp: OclValid_def)\nby(simp add:cp_OclIf[symmetric])\n\nlemma OclIf_false [simp]: \"(if false then B\\<^sub>1 else B\\<^sub>2 endif) = B\\<^sub>2\"\nby(rule ext, auto simp: OclIf_def)\n\nlemma OclIf_false' [simp]: \"\\<tau> \\<Turnstile> not P \\<Longrightarrow> (if P then B\\<^sub>1 else B\\<^sub>2 endif)\\<tau> = B\\<^sub>2 \\<tau>\"\napply(subst cp_OclIf)\napply(auto simp: foundation14[symmetric] foundation22)\nby(auto simp: cp_OclIf[symmetric])\n\n\nlemma OclIf_idem1[simp]:\"(if \\<delta> X then A else A endif) = A\"\nby(rule ext, auto simp: OclIf_def)\n\nlemma OclIf_idem2[simp]:\"(if \\<upsilon> X then A else A endif) = A\"\nby(rule ext, auto simp: OclIf_def)\n\nlemma OclNot_if[simp]:\n\"not(if P then C else E endif) = (if P then not C else not E endif)\"\n  (* non-trivial but elementary *)\n  apply(rule OclNot_inject, simp)\n  apply(rule ext)\n  apply(subst cp_OclNot, simp add: OclIf_def)\n  apply(subst cp_OclNot[symmetric])+\nby simp\n\n\nsubsection{* A Side-calculus for (Boolean) Constant Terms *}\n\ndefinition \"const X \\<equiv> \\<forall> \\<tau> \\<tau>'. X \\<tau> = X \\<tau>'\"\n\nlemma const_charn: \"const X \\<Longrightarrow> X \\<tau> = X \\<tau>'\"\nby(auto simp: const_def)\n\nlemma const_subst:\n assumes const_X: \"const X\"\n     and const_Y: \"const Y\"\n     and eq :     \"X \\<tau> = Y \\<tau>\"\n     and cp_P:    \"cp P\"\n     and pp :     \"P Y \\<tau> = P Y \\<tau>'\"\n   shows \"P X \\<tau> = P X \\<tau>'\"\nproof -\n   have A: \"\\<And>Y. P Y \\<tau> = P (\\<lambda>_. Y \\<tau>) \\<tau>\"\n      apply(insert cp_P, unfold cp_def)\n      apply(elim exE, erule_tac x=Y in allE', erule_tac x=\\<tau> in allE)\n      apply(erule_tac x=\"(\\<lambda>_. Y \\<tau>)\" in allE, erule_tac x=\\<tau> in allE)\n      by simp\n   have B: \"\\<And>Y. P Y \\<tau>' = P (\\<lambda>_. Y \\<tau>') \\<tau>'\"\n      apply(insert cp_P, unfold cp_def)\n      apply(elim exE, erule_tac x=Y in allE', erule_tac x=\\<tau>' in allE)\n      apply(erule_tac x=\"(\\<lambda>_. Y \\<tau>')\" in allE, erule_tac x=\\<tau>' in allE)\n      by simp   \n   have C: \"X \\<tau>' = Y \\<tau>'\"\n      apply(rule trans, subst const_charn[OF const_X],rule eq)\n      by(rule const_charn[OF const_Y])\n   show ?thesis\n      apply(subst A, subst B, simp add: eq C)\n      apply(subst A[symmetric],subst B[symmetric])\n      by(simp add:pp)\nqed\n\n\nlemma const_imply2 :\n assumes \"\\<And>\\<tau>1 \\<tau>2. P \\<tau>1 = P \\<tau>2 \\<Longrightarrow> Q \\<tau>1 = Q \\<tau>2\"\n shows \"const P \\<Longrightarrow> const Q\"\nby(simp add: const_def, insert assms, blast)\n\nlemma const_imply3 :\n assumes \"\\<And>\\<tau>1 \\<tau>2. P \\<tau>1 = P \\<tau>2 \\<Longrightarrow> Q \\<tau>1 = Q \\<tau>2 \\<Longrightarrow> R \\<tau>1 = R \\<tau>2\"\n shows \"const P \\<Longrightarrow> const Q \\<Longrightarrow> const R\"\nby(simp add: const_def, insert assms, blast)\n\nlemma const_imply4 :\n assumes \"\\<And>\\<tau>1 \\<tau>2. P \\<tau>1 = P \\<tau>2 \\<Longrightarrow> Q \\<tau>1 = Q \\<tau>2 \\<Longrightarrow> R \\<tau>1 = R \\<tau>2 \\<Longrightarrow> S \\<tau>1 = S \\<tau>2\"\n shows \"const P \\<Longrightarrow> const Q \\<Longrightarrow> const R \\<Longrightarrow> const S\"\nby(simp add: const_def, insert assms, blast)\n\nlemma const_lam : \"const (\\<lambda>_. e)\"\nby(simp add: const_def)\n\n\nlemma const_true : \"const true\"\nby(simp add: const_def true_def)\n\nlemma const_false : \"const false\"\nby(simp add: const_def false_def)\n\nlemma const_null : \"const null\"\nby(simp add: const_def null_fun_def)\n\nlemma const_invalid : \"const invalid\"\nby(simp add: const_def invalid_def)\n\nlemma const_bot : \"const bot\"\nby(simp add: const_def bot_fun_def)\n\n\n\nlemma const_defined :\n assumes \"const X\"\n shows \"const (\\<delta> X)\"\nby(rule const_imply2[OF _ assms],\n   simp add: defined_def false_def true_def bot_fun_def bot_option_def null_fun_def null_option_def)\n\nlemma const_valid :\n assumes \"const X\"\n shows \"const (\\<upsilon> X)\"\nby(rule const_imply2[OF _ assms],\n   simp add: valid_def false_def true_def bot_fun_def null_fun_def assms)\n\nlemma const_OclValid1:\n assumes \"const x\"\n shows   \"(\\<tau> \\<Turnstile> \\<delta> x) = (\\<tau>' \\<Turnstile> \\<delta> x)\"\n apply(simp add: OclValid_def)\n apply(subst const_defined[OF assms, THEN const_charn])\n by(simp add: true_def)\n\nlemma const_OclValid2:\n assumes \"const x\"\n shows   \"(\\<tau> \\<Turnstile> \\<upsilon> x) = (\\<tau>' \\<Turnstile> \\<upsilon> x)\"\n apply(simp add: OclValid_def)\n apply(subst const_valid[OF assms, THEN const_charn])\n by(simp add: true_def)\n\n \nlemma const_OclAnd :\n  assumes \"const X\"\n  assumes \"const X'\"\n  shows   \"const (X and X')\"\nby(rule const_imply3[OF _ assms], subst (1 2) cp_OclAnd, simp add: assms OclAnd_def)\n\n\n\nlemma const_OclNot :\n    assumes \"const X\"\n    shows \"const (not X)\"\nby(rule const_imply2[OF _ assms],subst cp_OclNot,simp add: assms OclNot_def)\n\nlemma const_OclOr :\n  assumes \"const X\"\n  assumes \"const X'\"\n  shows \"const (X or X')\"\nby(simp add: assms OclOr_def const_OclNot const_OclAnd)\n\nlemma const_OclImplies :\n  assumes \"const X\"\n  assumes \"const X'\"\n  shows \"const (X implies X')\"\nby(simp add: assms OclImplies_def const_OclNot const_OclOr)\n\nlemma const_StrongEq:\n  assumes \"const X\"\n  assumes \"const X'\"\n  shows   \"const(X \\<triangleq> X')\"\n  apply(simp only: StrongEq_def const_def, intro allI)\n  apply(subst assms(1)[THEN const_charn])\n  apply(subst assms(2)[THEN const_charn])\n  by simp\n  \nlemma const_OclIf :\n  assumes \"const B\"\n      and \"const C1\"\n      and \"const C2\"\n    shows \"const (if B then C1 else C2 endif)\"\n apply(rule const_imply4[OF _ assms], \n       subst (1 2) cp_OclIf, simp only: OclIf_def cp_defined[symmetric])\n apply(simp add: const_defined[OF assms(1), simplified const_def, THEN spec, THEN spec]\n                 const_true[simplified const_def, THEN spec, THEN spec]\n                 assms[simplified const_def, THEN spec, THEN spec]\n                 const_invalid[simplified const_def, THEN spec, THEN spec])\nby (metis (no_types) OCL_core.bot_fun_def OclValid_def const_def const_true defined_def foundation17 \n                     null_fun_def)\n\nlemmas const_ss = const_bot const_null  const_invalid  const_false  const_true  const_lam\n                  const_defined const_valid const_StrongEq const_OclNot const_OclAnd \n                  const_OclOr const_OclImplies const_OclIf\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Featherweight_OCL/OCL_core.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6791787121629466, "lm_q2_score": 0.4263215925474903, "lm_q1q2_score": 0.2895485501936609}}
{"text": "header {* \\isaheader{Dynamic Backward Slice} *}\n\ntheory DynSlice imports DependentLiveVariables BitVector \"../Basic/SemanticsCFG\" begin\n\nsubsection {* Backward slice of paths *}\n\ncontext DynPDG begin\n\nfun slice_path :: \"'edge list \\<Rightarrow> bit_vector\"\n  where \"slice_path [] = []\"\n  | \"slice_path (a#as) = (let n' = last(targetnodes (a#as)) in\n                           (sourcenode a -a#as\\<rightarrow>\\<^sub>d* n')#slice_path as)\"\n\n(*<*)declare Let_def [simp](*>*)\n\nlemma slice_path_length:\n  \"length(slice_path as) = length as\"\nby(induct as) auto\n\n\nlemma slice_path_right_Cons:\n  assumes slice:\"slice_path as = x#xs\"\n  obtains a' as' where \"as = a'#as'\" and \"slice_path as' = xs\"\nproof(atomize_elim)\n  from slice show \"\\<exists>a' as'. as = a'#as' \\<and> slice_path as' = xs\"\n    by(induct as) auto\nqed\n\n\nsubsection {* The proof of the fundamental property of (dynamic) slicing *}\n\nfun select_edge_kinds :: \"'edge list \\<Rightarrow> bit_vector \\<Rightarrow> 'state edge_kind list\"\nwhere \"select_edge_kinds [] [] = []\"\n  | \"select_edge_kinds (a#as) (b#bs) = (if b then kind a\n      else (case kind a of \\<Up>f \\<Rightarrow> \\<Up>id | (Q)\\<^sub>\\<surd> \\<Rightarrow> (\\<lambda>s. True)\\<^sub>\\<surd>))#select_edge_kinds as bs\"\n\n\ndefinition slice_kinds :: \"'edge list \\<Rightarrow> 'state edge_kind list\"\n  where \"slice_kinds as = select_edge_kinds as (slice_path as)\"\n\n\nlemma select_edge_kinds_max_bv:\n  \"select_edge_kinds as (replicate (length as) True) = kinds as\"\nby(induct as,auto simp:kinds_def)\n\n\nlemma slice_path_leqs_information_same_Uses:\n  \"\\<lbrakk>n -as\\<rightarrow>* n'; bs \\<preceq>\\<^sub>b bs'; slice_path as = bs;\n    select_edge_kinds as bs = es; select_edge_kinds as bs' = es'; \n    \\<forall>V xs. (V,xs,as) \\<in> dependent_live_vars n' \\<longrightarrow> state_val s V = state_val s' V;\n    preds es' s'\\<rbrakk> \n  \\<Longrightarrow> (\\<forall>V \\<in> Use n'. state_val (transfers es s) V =\n      state_val (transfers es' s') V) \\<and> preds es s\"\nproof(induct bs bs' arbitrary:as es es' n s s' rule:bv_leqs.induct)\n  case 1\n  from `slice_path as = []` have \"as = []\" by(cases as) auto\n  with `select_edge_kinds as [] = es` `select_edge_kinds as [] = es'`\n  have \"es = []\" and \"es' = []\" by simp_all\n  { fix V assume \"V \\<in> Use n'\"\n    hence \"(V,[],[]) \\<in> dependent_live_vars n'\" by(rule dep_vars_Use)\n    with `\\<forall>V xs. (V,xs,as) \\<in> dependent_live_vars n' \\<longrightarrow>\n                  state_val s V = state_val s' V` `V \\<in> Use n'` `as = []`\n    have \"state_val s V = state_val s' V\" by blast }\n  with `es = []` `es' = []` show ?case by simp\nnext\n  case (2 x xs y ys)\n  note all = `\\<forall>V xs. (V,xs,as) \\<in> dependent_live_vars n' \\<longrightarrow>\n                     state_val s V = state_val s' V`\n  note IH = `\\<And>as es es' n s s'. \\<lbrakk>n -as\\<rightarrow>* n'; xs \\<preceq>\\<^sub>b ys; slice_path as = xs; \n                        select_edge_kinds as xs = es; select_edge_kinds as ys = es';\n                        \\<forall>V xs. (V,xs,as) \\<in> dependent_live_vars n' \\<longrightarrow>\n                                   state_val s V = state_val s' V; \n                           preds es' s'\\<rbrakk>\n            \\<Longrightarrow> (\\<forall>V \\<in> Use n'. state_val (transfers es s) V =\n                state_val (transfers es' s') V) \\<and> preds es s`\n  from `x#xs \\<preceq>\\<^sub>b y#ys` have \"x \\<longrightarrow> y\" and \"xs \\<preceq>\\<^sub>b ys\" by simp_all\n  from `slice_path as = x#xs` obtain a' as' where \"as = a'#as'\"\n    and \"slice_path as' = xs\" by(erule slice_path_right_Cons)\n  from `as = a'#as'` `select_edge_kinds as (x#xs) = es`\n  obtain ex esx where \"es = ex#esx\"\n    and ex:\"ex = (if x then kind a'\n                    else (case kind a' of \\<Up>f \\<Rightarrow> \\<Up>id | (Q)\\<^sub>\\<surd> \\<Rightarrow> (\\<lambda>s. True)\\<^sub>\\<surd>))\"\n    and \"select_edge_kinds as' xs = esx\" by auto\n  from `as = a'#as'` `select_edge_kinds as (y#ys) = es'` obtain ex' esx' \n    where \"es' = ex'#esx'\"\n    and ex':\"ex' = (if y then kind a'\n                    else (case kind a' of \\<Up>f \\<Rightarrow> \\<Up>id | (Q)\\<^sub>\\<surd> \\<Rightarrow> (\\<lambda>s. True)\\<^sub>\\<surd>))\"\n    and \"select_edge_kinds as' ys = esx'\" by auto\n  from `n -as\\<rightarrow>* n'` `as = a'#as'` have [simp]:\"n = sourcenode a'\" \n    and \"valid_edge a'\" and \"targetnode a' -as'\\<rightarrow>* n'\"\n    by(auto elim:path_split_Cons)\n  from `n -as\\<rightarrow>* n'` `as = a'#as'` have \"last(targetnodes as) = n'\"\n    by(fastforce intro:path_targetnode)\n  from `preds es' s'` `es' = ex'#esx'` have \"pred ex' s'\"\n    and \"preds esx' (transfer ex' s')\" by simp_all\n  show ?case\n  proof(cases \"as' = []\")\n    case True\n    hence [simp]:\"as' = []\" by simp\n    with `slice_path as' = xs` `xs \\<preceq>\\<^sub>b ys` \n    have [simp]:\"xs = [] \\<and> ys = []\" by auto(cases ys,auto)+\n    with `select_edge_kinds as' xs = esx` `select_edge_kinds as' ys = esx'`\n    have [simp]:\"esx = []\" and [simp]:\"esx' = []\" by simp_all\n    from True `targetnode a' -as'\\<rightarrow>* n'` \n    have [simp]:\"n' = targetnode a'\" by(auto elim:path.cases)\n    show ?thesis\n    proof(cases x)\n      case True\n      with `x \\<longrightarrow> y` ex ex' have [simp]:\"ex = kind a' \\<and> ex' = kind a'\" by simp\n      have \"pred ex s\"\n      proof(cases ex)\n        case (Predicate Q)\n        with ex ex' True `x \\<longrightarrow> y` have [simp]:\"transfer ex s = s\" \n          and [simp]:\"transfer ex' s' = s'\"\n          by(cases \"kind a'\",auto)+\n        show ?thesis\n        proof(cases \"n -[a']\\<rightarrow>\\<^bsub>cd\\<^esub> n'\")\n          case True\n          { fix V' assume \"V' \\<in> Use n\"\n            with True `valid_edge a'`\n            have \"(V',[],a'#[]@[]) \\<in> dependent_live_vars n'\"\n              by(fastforce intro:dep_vars_Cons_cdep DynPDG_path_Nil \n                          simp:targetnodes_def)\n            with all `as = a'#as'` have \"state_val s V' = state_val s' V'\"\n              by fastforce }\n          with `pred ex' s'` `valid_edge a'`\n          show ?thesis by(fastforce elim:CFG_edge_Uses_pred_equal)\n        next\n          case False\n          from ex True Predicate have \"kind a' = (Q)\\<^sub>\\<surd>\" by(auto split:split_if_asm)\n          from True `slice_path as = x#xs` `as = a'#as'` have \"n -[a']\\<rightarrow>\\<^sub>d* n'\"\n            by(auto simp:targetnodes_def)\n          thus ?thesis\n          proof(induct rule:DynPDG_path.cases)\n            case (DynPDG_path_Nil nx)\n            hence False by simp\n            thus ?case by simp\n          next\n            case (DynPDG_path_Append_cdep nx asx n'' asx' nx')\n            from `[a'] = asx@asx'` \n            have \"(asx = [a'] \\<and> asx' = []) \\<or> (asx = [] \\<and> asx' = [a'])\"\n              by (cases asx) auto\n            hence False\n            proof\n              assume \"asx = [a'] \\<and> asx' = []\"\n              with `n'' -asx'\\<rightarrow>\\<^bsub>cd\\<^esub> nx'` show False\n                by(fastforce elim:DynPDG_edge.cases dest:dyn_control_dependence_path)\n            next\n              assume \"asx = [] \\<and> asx' = [a']\"\n              with `nx -asx\\<rightarrow>\\<^sub>d* n''` have \"nx = n''\" and \"asx' = [a']\"\n                by(auto intro:DynPDG_empty_path_eq_nodes)\n              with `n = nx` `n' = nx'` `n'' -asx'\\<rightarrow>\\<^bsub>cd\\<^esub> nx'` False\n              show False by simp\n            qed\n            thus ?thesis by simp\n          next\n            case (DynPDG_path_Append_ddep nx asx n'' V asx' nx')\n            from `[a'] = asx@asx'` \n            have \"(asx = [a'] \\<and> asx' = []) \\<or> (asx = [] \\<and> asx' = [a'])\"\n              by (cases asx) auto\n            thus ?case\n            proof\n              assume \"asx = [a'] \\<and> asx' = []\"\n              with `n'' -{V}asx'\\<rightarrow>\\<^bsub>dd\\<^esub> nx'` have False\n                by(fastforce elim:DynPDG_edge.cases simp:dyn_data_dependence_def)\n              thus ?thesis by simp\n            next\n              assume \"asx = [] \\<and> asx' = [a']\"\n              with `nx -asx\\<rightarrow>\\<^sub>d* n''` have \"nx = n''\"\n                by(simp add:DynPDG_empty_path_eq_nodes)\n              { fix V' assume \"V' \\<in> Use n\"\n                from `n'' -{V}asx'\\<rightarrow>\\<^bsub>dd\\<^esub> nx'` `asx = [] \\<and> asx' = [a']` `n' = nx'`\n                have \"(V,[],[]) \\<in> dependent_live_vars n'\"\n                  by(fastforce intro:dep_vars_Use elim:DynPDG_edge.cases\n                    simp:dyn_data_dependence_def)\n                with `V' \\<in> Use n` `n'' -{V}asx'\\<rightarrow>\\<^bsub>dd\\<^esub> nx'` `asx = [] \\<and> asx' = [a']`\n                  `n = nx` `nx = n''` `n' = nx'`\n                have \"(V',[],[a']) \\<in> dependent_live_vars n'\"\n                  by(auto elim:dep_vars_Cons_ddep simp:targetnodes_def)\n                with all `as = a'#as'` have \"state_val s V' = state_val s' V'\"\n                  by fastforce }\n              with `pred ex' s'` `valid_edge a'` ex ex' True `x \\<longrightarrow> y` show ?thesis\n                by(fastforce elim:CFG_edge_Uses_pred_equal)\n            qed\n          qed\n        qed\n      qed simp\n      { fix V assume \"V \\<in> Use n'\"\n        from `V \\<in> Use n'` have \"(V,[],[]) \\<in> dependent_live_vars n'\" \n          by(rule dep_vars_Use)\n        have \"state_val (transfer ex s) V = state_val (transfer ex' s') V\"\n        proof(cases \"n -{V}[a']\\<rightarrow>\\<^bsub>dd\\<^esub> n'\")\n          case True\n          hence \"V \\<in> Def n\"\n            by(auto elim:DynPDG_edge.cases simp:dyn_data_dependence_def)\n          have \"\\<And>V. V \\<in> Use n \\<Longrightarrow> state_val s V = state_val s' V\"\n          proof -\n            fix V' assume \"V' \\<in> Use n\"\n            with `(V,[],[]) \\<in> dependent_live_vars n'` True\n            have \"(V',[],[a']) \\<in> dependent_live_vars n'\"\n              by(fastforce intro:dep_vars_Cons_ddep simp:targetnodes_def)\n            with all `as = a'#as'` show \"state_val s V' = state_val s' V'\" by auto\n          qed\n          with `valid_edge a'` `pred ex' s'` `pred ex s`\n          have \"\\<forall>V \\<in> Def n. state_val (transfer (kind a') s) V =\n                              state_val (transfer (kind a') s') V\"\n            by simp(rule CFG_edge_transfer_uses_only_Use,auto)\n          with `V \\<in> Def n` have \"state_val (transfer (kind a') s) V = \n                         state_val (transfer (kind a') s') V\"\n            by simp\n          thus ?thesis by fastforce\n        next\n          case False\n          with `last(targetnodes as) = n'` `as = a'#as'`\n            `(V,[],[]) \\<in> dependent_live_vars n'`\n          have \"(V,[a'],[a']) \\<in> dependent_live_vars n'\"\n            by(fastforce intro:dep_vars_Cons_keep)\n          from `(V,[a'],[a']) \\<in> dependent_live_vars n'` all `as = a'#as'`\n          have states_eq:\"state_val s V = state_val s' V\"\n            by auto\n          from `valid_edge a'` `V \\<in> Use n'` False `pred ex s`\n          have \"state_val (transfers (kinds [a']) s) V = state_val s V\"\n            apply(auto intro!:no_ddep_same_state path_edge simp:targetnodes_def)\n            apply(simp add:kinds_def)\n            by(case_tac as',auto)\n          moreover\n          from `valid_edge a'` `V \\<in> Use n'` False `pred ex' s'`\n          have \"state_val (transfers (kinds [a']) s') V = state_val s' V\"\n            apply(auto intro!:no_ddep_same_state path_edge simp:targetnodes_def)\n            apply(simp add:kinds_def)\n            by(case_tac as',auto)\n          ultimately show ?thesis using states_eq by(auto simp:kinds_def)\n        qed }\n      hence \"\\<forall>V \\<in> Use n'. state_val (transfer ex s) V = \n                                state_val (transfer ex' s') V\" by simp\n      with `pred ex s` `es = ex#esx` `es' = ex'#esx'` show ?thesis by simp\n    next\n      case False\n      with ex have cases_x:\"ex = (case kind a' of \\<Up>f \\<Rightarrow> \\<Up>id | (Q)\\<^sub>\\<surd> \\<Rightarrow> (\\<lambda>s. True)\\<^sub>\\<surd>)\"\n        by simp\n      from cases_x have \"pred ex s\" by(cases \"kind a'\",auto)\n      show ?thesis\n      proof(cases y)\n        case True\n        with ex' have [simp]:\"ex' = kind a'\" by simp\n        { fix V assume \"V \\<in> Use n'\"\n          from `V \\<in> Use n'` have \"(V,[],[]) \\<in> dependent_live_vars n'\"\n            by(rule dep_vars_Use)\n          from `slice_path as = x#xs` `as = a'#as'` `\\<not> x` \n          have \"\\<not> n -[a']\\<rightarrow>\\<^sub>d* n'\" by(simp add:targetnodes_def)\n          hence \"\\<not> n -{V}[a']\\<rightarrow>\\<^bsub>dd\\<^esub> n'\" by(fastforce dest:DynPDG_path_ddep)\n          with `last(targetnodes as) = n'` `as = a'#as'`\n            `(V,[],[]) \\<in> dependent_live_vars n'`\n          have \"(V,[a'],[a']) \\<in> dependent_live_vars n'\"\n            by(fastforce intro:dep_vars_Cons_keep)\n          with all `as = a'#as'` have \"state_val s V = state_val s' V\" by auto\n          from `valid_edge a'` `V \\<in> Use n'` `pred ex' s'`\n            `\\<not> n -{V}[a']\\<rightarrow>\\<^bsub>dd\\<^esub> n'` `last(targetnodes as) = n'` `as = a'#as'`\n          have \"state_val (transfers (kinds [a']) s') V = state_val s' V\"\n            apply(auto intro!:no_ddep_same_state path_edge)\n            apply(simp add:kinds_def)\n            by(case_tac as',auto)\n          with `state_val s V = state_val s' V` cases_x\n          have \"state_val (transfer ex s) V =\n                state_val (transfer ex' s') V\"\n            by(cases \"kind a'\",simp_all add:kinds_def) }\n        hence \"\\<forall>V \\<in> Use n'. state_val (transfer ex s) V =\n                           state_val (transfer ex' s') V\" by simp\n        with `as = a'#as'` `es = ex#esx` `es' = ex'#esx'` `pred ex s` \n        show ?thesis by simp\n      next\n        case False\n        with ex' have cases_y:\"ex' = (case kind a' of \\<Up>f \\<Rightarrow> \\<Up>id | (Q)\\<^sub>\\<surd> \\<Rightarrow> (\\<lambda>s. True)\\<^sub>\\<surd>)\"\n          by simp\n        with cases_x have [simp]:\"ex = ex'\" by(cases \"kind a'\") auto\n        { fix V assume \"V \\<in> Use n'\"\n          from `V \\<in> Use n'` have \"(V,[],[]) \\<in> dependent_live_vars n'\"\n            by(rule dep_vars_Use)\n          from `slice_path as = x#xs` `as = a'#as'` `\\<not> x` \n          have \"\\<not> n -[a']\\<rightarrow>\\<^sub>d* n'\" by(simp add:targetnodes_def)\n          hence no_dep:\"\\<not> n -{V}[a']\\<rightarrow>\\<^bsub>dd\\<^esub> n'\" by(fastforce dest:DynPDG_path_ddep)\n          with `last(targetnodes as) = n'` `as = a'#as'`\n            `(V,[],[]) \\<in> dependent_live_vars n'`\n          have \"(V,[a'],[a']) \\<in> dependent_live_vars n'\"\n            by(fastforce intro:dep_vars_Cons_keep)\n          with all `as = a'#as'` have \"state_val s V = state_val s' V\" by auto }\n        with `as = a'#as'` cases_x `es = ex#esx` `es' = ex'#esx'` `pred ex s`\n        show ?thesis by(cases \"kind a'\",auto)\n      qed\n    qed\n  next\n    case False\n    show ?thesis\n    proof(cases \"\\<forall>V xs. (V,xs,as') \\<in> dependent_live_vars n' \\<longrightarrow>\n                        state_val (transfer ex s) V = state_val (transfer ex' s') V\")\n      case True\n      hence imp':\"\\<forall>V xs. (V,xs,as') \\<in> dependent_live_vars n' \\<longrightarrow>\n                       state_val (transfer ex s) V = state_val (transfer ex' s') V\" .\n      from IH[OF `targetnode a' -as'\\<rightarrow>* n'` `xs \\<preceq>\\<^sub>b ys` `slice_path as' = xs`\n        `select_edge_kinds as' xs = esx` `select_edge_kinds as' ys = esx'` \n        this `preds esx' (transfer ex' s')`]\n      have all':\"\\<forall>V\\<in>Use n'. state_val (transfers esx (transfer ex s)) V =\n                             state_val (transfers esx' (transfer ex' s')) V\"\n        and \"preds esx (transfer ex s)\" by simp_all\n      have \"pred ex s\"\n      proof(cases ex)\n        case (Predicate Q)\n        with `slice_path as = x#xs` `as = a'#as'` `last(targetnodes as) = n'` ex \n        have \"ex = (\\<lambda>s. True)\\<^sub>\\<surd> \\<or> n -a'#as'\\<rightarrow>\\<^sub>d* n'\"\n          by(cases \"kind a'\",auto split:split_if_asm) \n        thus ?thesis\n        proof\n          assume \"ex = (\\<lambda>s. True)\\<^sub>\\<surd>\" thus ?thesis by simp\n        next\n          assume \"n -a'#as'\\<rightarrow>\\<^sub>d* n'\"\n          with `slice_path as = x#xs` `as = a'#as'` `last(targetnodes as) = n'` ex\n          have [simp]:\"ex = kind a'\" by clarsimp\n          with `x \\<longrightarrow> y` ex ex' have [simp]:\"ex' = ex\" by(cases x) auto\n          from `n -a'#as'\\<rightarrow>\\<^sub>d* n'` show ?thesis\n          proof(induct rule:DynPDG_path_rev_cases)\n            case DynPDG_path_Nil\n            hence False by simp\n            thus ?thesis by simp\n          next\n            case (DynPDG_path_cdep_Append n'' asx asx')\n            from `n -asx\\<rightarrow>\\<^bsub>cd\\<^esub> n''`have \"asx \\<noteq> []\"\n              by(auto elim:DynPDG_edge.cases dest:dyn_control_dependence_path)\n            with `n -asx\\<rightarrow>\\<^bsub>cd\\<^esub> n''` `n'' -asx'\\<rightarrow>\\<^sub>d* n'` `a'#as' = asx@asx'`\n            have cdep:\"\\<exists>as1 as2 n''. n -a'#as1\\<rightarrow>\\<^bsub>cd\\<^esub> n'' \\<and> \n                                     n'' -as2\\<rightarrow>\\<^sub>d* n' \\<and> as' = as1@as2\"\n              by(cases asx) auto \n            { fix V assume \"V \\<in> Use n\"\n              with cdep `last(targetnodes as) = n'` `as = a'#as'`\n              have \"(V,[],as) \\<in> dependent_live_vars n'\"\n                by(fastforce intro:dep_vars_Cons_cdep)\n              with all have \"state_val s V = state_val s' V\" by blast }\n            with `valid_edge a'` `pred ex' s'`\n            show ?thesis by(fastforce elim:CFG_edge_Uses_pred_equal)\n          next\n            case (DynPDG_path_ddep_Append V n'' asx asx')\n            from `n -{V}asx\\<rightarrow>\\<^bsub>dd\\<^esub> n''` obtain ai ais where \"asx = ai#ais\"\n              by(cases asx)(auto dest:DynPDG_ddep_edge_CFG_path)\n            with `n -{V}asx\\<rightarrow>\\<^bsub>dd\\<^esub> n''` have \"sourcenode ai = n\"\n              by(fastforce dest:DynPDG_ddep_edge_CFG_path elim:path.cases)\n            from `n -{V}asx\\<rightarrow>\\<^bsub>dd\\<^esub> n''` `asx = ai#ais`\n            have \"last(targetnodes asx) = n''\"\n              by(fastforce intro:path_targetnode dest:DynPDG_ddep_edge_CFG_path)\n            { fix V' assume \"V' \\<in> Use n\"\n              from `n -{V}asx\\<rightarrow>\\<^bsub>dd\\<^esub> n''` have \"(V,[],[]) \\<in> dependent_live_vars n''\"\n                by(fastforce elim:DynPDG_edge.cases dep_vars_Use \n                            simp:dyn_data_dependence_def)\n              with `n'' -asx'\\<rightarrow>\\<^sub>d* n'` have \"(V,[],[]@asx') \\<in> dependent_live_vars n'\"\n                by(rule dependent_live_vars_dep_dependent_live_vars)\n              have \"(V',[],as) \\<in> dependent_live_vars n'\"\n              proof(cases \"asx' = []\")\n                case True\n                with `n'' -asx'\\<rightarrow>\\<^sub>d* n'` have \"n'' = n'\"\n                  by(fastforce intro:DynPDG_empty_path_eq_nodes)\n                with `n -{V}asx\\<rightarrow>\\<^bsub>dd\\<^esub> n''` `V' \\<in> Use n` True `as = a'#as'`\n                  `a'#as' = asx@asx'`\n                show ?thesis by(fastforce intro:dependent_live_vars_ddep_empty_fst)\n              next\n                case False\n                with `n -{V}asx\\<rightarrow>\\<^bsub>dd\\<^esub> n''` `asx = ai#ais`\n                  `(V,[],[]@asx') \\<in> dependent_live_vars n'`\n                have \"(V,ais@[],ais@asx') \\<in> dependent_live_vars n'\"\n                  by(fastforce intro:ddep_dependent_live_vars_keep_notempty)\n                from `n'' -asx'\\<rightarrow>\\<^sub>d* n'` False have \"last(targetnodes asx') = n'\"\n                  by -(rule path_targetnode,rule DynPDG_path_CFG_path)\n                with `(V,ais@[],ais@asx') \\<in> dependent_live_vars n'`\n                  `V' \\<in> Use n` `n -{V}asx\\<rightarrow>\\<^bsub>dd\\<^esub> n''` `asx = ai#ais`\n                  `sourcenode ai = n` `last(targetnodes asx) = n''` False\n                have \"(V',[],ai#ais@asx') \\<in> dependent_live_vars n'\"\n                  by(fastforce intro:dep_vars_Cons_ddep simp:targetnodes_def)\n                with `asx = ai#ais` `a'#as' = asx@asx'` `as = a'#as'`\n                show ?thesis by simp\n              qed\n              with all have \"state_val s V' = state_val s' V'\" by blast }\n            with `pred ex' s'` `valid_edge a'`\n            show ?thesis by(fastforce elim:CFG_edge_Uses_pred_equal)\n          qed\n        qed\n      qed simp\n      with all' `preds esx (transfer ex s)` `es = ex#esx` `es' = ex'#esx'`\n      show ?thesis by simp\n    next\n      case False\n      then obtain V' xs' where \"(V',xs',as') \\<in> dependent_live_vars n'\"\n        and \"state_val (transfer ex s) V' \\<noteq> state_val (transfer ex' s') V'\"\n        by auto\n      show ?thesis\n      proof(cases \"n -a'#as'\\<rightarrow>\\<^sub>d* n'\")\n        case True\n        with `slice_path as = x#xs` `as = a'#as'` `last(targetnodes as) = n'` ex\n        have [simp]:\"ex = kind a'\" by clarsimp\n        with `x \\<longrightarrow> y` ex ex' have [simp]:\"ex' = ex\" by(cases x) auto\n        { fix V assume \"V \\<in> Use (sourcenode a')\"\n          hence \"(V,[],[]) \\<in> dependent_live_vars (sourcenode a')\"\n            by(rule dep_vars_Use)\n          with `n -a'#as'\\<rightarrow>\\<^sub>d* n'` have \"(V,[],[]@a'#as') \\<in> dependent_live_vars n'\"\n            by(fastforce intro:dependent_live_vars_dep_dependent_live_vars)\n          with all `as = a'#as'` have \"state_val s V = state_val s' V\"\n            by fastforce }\n        with `pred ex' s'` `valid_edge a'` have \"pred ex s\"\n          by(fastforce intro:CFG_edge_Uses_pred_equal)\n        show ?thesis\n        proof(cases \"V' \\<in> Def n\")\n          case True\n          with `state_val (transfer ex s) V' \\<noteq> state_val (transfer ex' s') V'`\n            `valid_edge a'` `pred ex' s'` `pred ex s`\n            CFG_edge_transfer_uses_only_Use[of a' s s']\n          obtain V'' where \"V'' \\<in> Use n\"\n            and \"state_val s V'' \\<noteq> state_val s' V''\"\n            by auto\n          from True `(V',xs',as') \\<in> dependent_live_vars n'`\n            `targetnode a' -as'\\<rightarrow>* n'` `last(targetnodes as) = n'` `as = a'#as'`\n            `valid_edge a'` `n = sourcenode a'`[THEN sym]\n          have \"n -{V'}a'#xs'\\<rightarrow>\\<^bsub>dd\\<^esub> last(targetnodes (a'#xs'))\"\n            by -(drule dependent_live_vars_dependent_edge,\n              auto dest!: dependent_live_vars_dependent_edge \n                   dest:DynPDG_ddep_edge_CFG_path path_targetnode \n                   simp del:`n = sourcenode a'`)\n          with `(V',xs',as') \\<in> dependent_live_vars n'` `V'' \\<in> Use n`\n            `last(targetnodes as) = n'` `as = a'#as'`\n          have \"(V'',[],as) \\<in> dependent_live_vars n'\" \n            by(fastforce intro:dep_vars_Cons_ddep)\n          with all have \"state_val s V'' = state_val s' V''\" by blast\n          with `state_val s V'' \\<noteq> state_val s' V''` have False by simp\n          thus ?thesis by simp\n        next\n          case False\n          with `valid_edge a'` `pred ex s`\n          have \"state_val (transfer (kind a') s) V' = state_val s V'\"\n            by(fastforce intro:CFG_edge_no_Def_equal)\n          moreover\n          from False `valid_edge a'` `pred ex' s'`\n          have \"state_val (transfer (kind a') s') V' = state_val s' V'\"\n            by(fastforce intro:CFG_edge_no_Def_equal)\n          ultimately have \"state_val s V' \\<noteq> state_val s' V'\"\n            using `state_val (transfer ex s) V' \\<noteq> state_val (transfer ex' s') V'`\n            by simp\n          from False have \"\\<not> n -{V'}a'#xs'\\<rightarrow>\\<^bsub>dd\\<^esub> \n                           last(targetnodes (a'#xs'))\"\n            by(auto elim:DynPDG_edge.cases simp:dyn_data_dependence_def)\n          with `(V',xs',as') \\<in> dependent_live_vars n'` `last(targetnodes as) = n'`\n            `as = a'#as'`\n          have \"(V',a'#xs',a'#as') \\<in> dependent_live_vars n'\"\n            by(fastforce intro:dep_vars_Cons_keep)\n          with `as = a'#as'` all have \"state_val s V' = state_val s' V'\" by auto\n          with `state_val s V' \\<noteq> state_val s' V'` have False by simp\n          thus ?thesis by simp\n        qed\n      next\n        case False\n        { assume \"V' \\<in> Def n\"\n          with `(V',xs',as') \\<in> dependent_live_vars n'` `targetnode a' -as'\\<rightarrow>* n'`\n            `valid_edge a'`\n          have \"n -a'#as'\\<rightarrow>\\<^sub>d* n'\"\n            by -(drule dependent_live_vars_dependent_edge,\n              auto dest:DynPDG_path_ddep DynPDG_path_Append)\n          with False have \"False\" by simp }\n        hence \"V' \\<notin> Def (sourcenode a')\" by fastforce\n        from False `slice_path as = x#xs` `as = a'#as'`\n          `last(targetnodes as) = n'` `as' \\<noteq> []`\n        have \"\\<not> x\" by(auto simp:targetnodes_def)\n        with ex have cases:\"ex = (case kind a' of \\<Up>f \\<Rightarrow> \\<Up>id | (Q)\\<^sub>\\<surd> \\<Rightarrow> (\\<lambda>s. True)\\<^sub>\\<surd>)\"\n          by simp\n        have \"state_val s V' \\<noteq> state_val s' V'\"\n        proof(cases y)\n          case True\n          with ex' have [simp]:\"ex' = kind a'\" by simp\n          from `V' \\<notin> Def (sourcenode a')` `valid_edge a'` `pred ex' s'`\n          have states_eq:\"state_val (transfer (kind a') s') V' = state_val s' V'\"\n            by(fastforce intro:CFG_edge_no_Def_equal)\n          from cases have \"state_val s V' = state_val (transfer ex s) V'\"\n            by(cases \"kind a'\") auto\n          with states_eq\n            `state_val (transfer ex s) V' \\<noteq> state_val (transfer ex' s') V'`\n          show ?thesis by simp\n        next\n          case False\n          with ex' have \"ex' = (case kind a' of \\<Up>f \\<Rightarrow> \\<Up>id | (Q)\\<^sub>\\<surd> \\<Rightarrow> (\\<lambda>s. True)\\<^sub>\\<surd>)\"\n            by simp\n          with cases have \"state_val s V' = state_val (transfer ex s) V'\"\n            and \"state_val s' V' = state_val (transfer ex' s') V'\"\n            by(cases \"kind a'\",auto)+\n          with `state_val (transfer ex s) V' \\<noteq> state_val (transfer ex' s') V'` \n          show ?thesis by simp\n        qed\n        from `V' \\<notin> Def (sourcenode a')` \n        have \"\\<not> n -{V'}a'#xs'\\<rightarrow>\\<^bsub>dd\\<^esub> last(targetnodes (a'#xs'))\"\n          by(auto elim:DynPDG_edge.cases simp:dyn_data_dependence_def)\n        with `(V',xs',as') \\<in> dependent_live_vars n'` `last(targetnodes as) = n'`\n          `as = a'#as'`\n        have \"(V',a'#xs',a'#as') \\<in> dependent_live_vars n'\"\n          by(fastforce intro:dep_vars_Cons_keep)\n        with `as = a'#as'` all have \"state_val s V' = state_val s' V'\" by auto\n        with `state_val s V' \\<noteq> state_val s' V'` have False by simp\n        thus ?thesis by simp\n      qed\n    qed\n  qed\nqed simp_all\n\n\ntheorem fundamental_property_of_path_slicing:\n  assumes \"n -as\\<rightarrow>* n'\" and \"preds (kinds as) s\"\n  shows \"(\\<forall>V \\<in> Use n'. state_val (transfers (slice_kinds as) s) V = \n                         state_val (transfers (kinds as) s) V)\" \n  and \"preds (slice_kinds as) s\"\nproof -\n  have \"length as = length (slice_path as)\" by(simp add:slice_path_length)\n  hence \"slice_path as \\<preceq>\\<^sub>b replicate (length as) True\"\n    by(simp add:maximal_element)\n  have \"select_edge_kinds as (replicate (length as) True) = kinds as\"\n    by(rule select_edge_kinds_max_bv)\n  with `n -as\\<rightarrow>* n'` `slice_path as \\<preceq>\\<^sub>b replicate (length as) True`\n    `preds (kinds as) s` \n  have \"(\\<forall>V\\<in>Use n'. state_val (transfers (slice_kinds as) s) V =\n       state_val (transfers (kinds as) s) V) \\<and> preds (slice_kinds as) s\"\n    by -(rule slice_path_leqs_information_same_Uses,simp_all add:slice_kinds_def)\n  thus \"\\<forall>V\\<in>Use n'. state_val (transfers (slice_kinds as) s) V =\n    state_val (transfers (kinds as) s) V\" and \"preds (slice_kinds as) s\"\n    by simp_all\nqed\n\nend\n\n\nsubsection {* The fundamental property of (dynamic) slicing related to the semantics *}\n\nlocale BackwardPathSlice_wf = \n  DynPDG sourcenode targetnode kind valid_edge Entry Def Use state_val Exit \n    dyn_control_dependence +\n  CFG_semantics_wf sourcenode targetnode kind valid_edge Entry sem identifies\n  for sourcenode :: \"'edge \\<Rightarrow> 'node\" and targetnode :: \"'edge \\<Rightarrow> 'node\"\n  and kind :: \"'edge \\<Rightarrow> 'state edge_kind\" and valid_edge :: \"'edge \\<Rightarrow> bool\"\n  and Entry :: \"'node\" (\"'('_Entry'_')\") and Def :: \"'node \\<Rightarrow> 'var set\"\n  and Use :: \"'node \\<Rightarrow> 'var set\" and state_val :: \"'state \\<Rightarrow> 'var \\<Rightarrow> 'val\"\n  and dyn_control_dependence :: \"'node \\<Rightarrow> 'node \\<Rightarrow> 'edge list \\<Rightarrow> bool\" \n    (\"_ controls _ via _\" [51, 0, 0] 1000)\n  and Exit :: \"'node\" (\"'('_Exit'_')\") \n  and sem :: \"'com \\<Rightarrow> 'state \\<Rightarrow> 'com \\<Rightarrow> 'state \\<Rightarrow> bool\" \n    (\"((1\\<langle>_,/_\\<rangle>) \\<Rightarrow>/ (1\\<langle>_,/_\\<rangle>))\" [0,0,0,0] 81)\n  and identifies :: \"'node \\<Rightarrow> 'com \\<Rightarrow> bool\" (\"_ \\<triangleq> _\" [51, 0] 80) \n\nbegin\n\ntheorem fundamental_property_of_path_slicing_semantically:\n  assumes \"n \\<triangleq> c\" and \"\\<langle>c,s\\<rangle> \\<Rightarrow> \\<langle>c',s'\\<rangle>\"\n  obtains n' as where \"n -as\\<rightarrow>* n'\" and \"preds (slice_kinds as) s\" \n  and \"n' \\<triangleq> c'\" \n  and \"\\<forall>V \\<in> Use n'. state_val (transfers (slice_kinds as) s) V = \n                     state_val s' V\"\nproof(atomize_elim)\n  from `n \\<triangleq> c` `\\<langle>c,s\\<rangle> \\<Rightarrow> \\<langle>c',s'\\<rangle>` obtain n' as where \"n -as\\<rightarrow>* n'\"\n    and \"transfers (kinds as) s = s'\"\n    and \"preds (kinds as) s\"\n    and \"n' \\<triangleq> c'\"\n    by(fastforce dest:fundamental_property)\n  with `n -as\\<rightarrow>* n'` `preds (kinds as) s` \n  have \"\\<forall>V \\<in> Use n'. state_val (transfers (slice_kinds as) s) V =\n    state_val (transfers (kinds as) s) V\" and \"preds (slice_kinds as) s\"\n    by -(rule fundamental_property_of_path_slicing,simp_all)+\n  with `transfers (kinds as) s = s'` have \"\\<forall>V \\<in> Use n'. \n    state_val (transfers (slice_kinds as) s) V =\n    state_val s' V\" by simp\n  with `n -as\\<rightarrow>* n'` `preds (slice_kinds as) s` `n' \\<triangleq> c'`\n  show \"\\<exists>as n'. n -as\\<rightarrow>* n' \\<and> preds (slice_kinds as) s \\<and> n' \\<triangleq> c' \\<and>\n       (\\<forall>V\\<in>Use n'. state_val (transfers (slice_kinds as) s) V = state_val s' V)\"\n    by blast\nqed\n\n\nend\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Slicing/Dynamic/DynSlice.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6442251064863695, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.28951001779224994}}
{"text": "theory flash11Rev imports flashPub\nbegin\nsection{*Main defintions*}\nlemma NI_FAckVsInv11:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvVsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_InvAck_1VsInv11:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1_HomeVsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_InvAck_2VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_GetXVsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak1VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak2VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak3VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX1VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv11:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10VsInv11:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10_homeVsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX11VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_local'') )  ( Const true ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_local'') )  ( Const true ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_GetVsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_Get_Nak1VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak2VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak3VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put1VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put2VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put3VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_PutVsInv11:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_PutXAcksDoneVsInv11:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_NakVsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Nak_ClearVsInv11:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Nak_HomeVsInv11:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_NakVsInv11:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_Nak_HomeVsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Remote_GetX_PutXVsInv11:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))    ( eqn ( IVar ( Para ''CacheState'' iInv2) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iRule2) )  ( Const CACHE_E ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))    ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iRule2) )  ( Const CACHE_E ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_PutX_HomeVsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Remote_Get_Nak1VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Remote_Get_Nak2VsInv11:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Put1VsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Remote_Get_Put2VsInv11:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutVsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutXVsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_ReplaceVsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_ReplaceHomeVsInv11:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceHomeShrVldVsInv11:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceShrVldVsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_ShWbVsInv11:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_WbVsInv11:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_GetX1VsInv11:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_GetX2VsInv11:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX1VsInv11:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX2VsInv11:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX3VsInv11:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX4VsInv11:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_Get_GetVsInv11:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_Get_PutVsInv11:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_PutXVsInv11:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_ReplaceVsInv11:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_GetVsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_GetXVsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_PutXVsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma PI_Remote_ReplaceVsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma StoreVsInv11:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma StoreHomeVsInv11:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv11  iInv1  iInv2 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash11Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5926665999540697, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.2893892597040113}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory PackedTypes\nimports \"Word_Lib.WordSetup\" CProof\nbegin\n\nsection \\<open>Underlying definitions for the class axioms\\<close>\n\ntext \\<open>field_access / field_update is the identity for packed types\\<close>\n\ndefinition fa_fu_idem :: \"'a field_desc \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"fa_fu_idem fd n \\<equiv>\n     \\<forall>bs bs' v. length bs = n \\<longrightarrow> length bs' = n \\<longrightarrow> field_access fd (field_update fd bs v) bs' = bs\"\n\n(* Is it better to do this or to use a fold over td?  This seems easier to use *)\nprimrec\n  td_fafu_idem :: \"'a field_desc typ_desc \\<Rightarrow> bool\" and\n  td_fafu_idem_struct :: \"'a field_desc typ_struct \\<Rightarrow> bool\" and\n  td_fafu_idem_list :: \" ('a field_desc typ_desc, char list) dt_pair list \\<Rightarrow> bool\" and\n  td_fafu_idem_pair :: \"('a field_desc typ_desc, char list) dt_pair \\<Rightarrow> bool\"\nwhere\n  fai0: \"td_fafu_idem (TypDesc ts n) = td_fafu_idem_struct ts\"\n\n| fai1: \"td_fafu_idem_struct (TypScalar n algn d) = fa_fu_idem d n\"\n| fai2: \"td_fafu_idem_struct (TypAggregate ts) = td_fafu_idem_list ts\"\n\n| fai3: \"td_fafu_idem_list [] = True\"\n| fai4: \"td_fafu_idem_list (x#xs) = (td_fafu_idem_pair x \\<and> td_fafu_idem_list xs)\"\n\n| fai5: \"td_fafu_idem_pair (DTPair x n) = td_fafu_idem x\"\n\nlemmas td_fafu_idem_simps = fai0 fai1 fai2 fai3 fai4 fai5\n\ntext \\<open>field_access is independent of the underlying bytes\\<close>\n\ndefinition  fa_heap_indep :: \"'a field_desc \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"fa_heap_indep fd n \\<equiv>\n     \\<forall>bs bs' v. length bs = n \\<longrightarrow> length bs' = n \\<longrightarrow> field_access fd v bs = field_access fd v bs'\"\n\n\nprimrec\n  td_fa_hi :: \"'a field_desc typ_desc \\<Rightarrow> bool\" and\n  td_fa_hi_struct :: \"'a field_desc typ_struct \\<Rightarrow> bool\" and\n  td_fa_hi_list :: \"('a field_desc typ_desc, char list) dt_pair list \\<Rightarrow> bool\" and\n  td_fa_hi_pair :: \"('a field_desc typ_desc, char list) dt_pair \\<Rightarrow> bool\"\nwhere\n  fahi0: \"td_fa_hi (TypDesc ts n) = td_fa_hi_struct ts\"\n\n| fahi1: \"td_fa_hi_struct (TypScalar n algn d) = fa_heap_indep d n\"\n| fahi2: \"td_fa_hi_struct (TypAggregate ts) = td_fa_hi_list ts\"\n\n| fahi3: \"td_fa_hi_list [] = True\"\n| fahi4: \"td_fa_hi_list (x#xs) = (td_fa_hi_pair x \\<and> td_fa_hi_list xs)\"\n\n| fahi5: \"td_fa_hi_pair (DTPair x n) = td_fa_hi x\"\n\nlemmas td_fa_hi_simps = fahi0 fahi1 fahi2 fahi3 fahi4 fahi5\n\nsection \\<open>Lemmas about td_fafu_idem\\<close>\n\nlemma field_lookup_td_fafu_idem:\n  shows \"\\<And>(s :: 'a field_desc typ_desc) f m n.\n           \\<lbrakk> field_lookup t f m = Some (s, n); td_fafu_idem t \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  and   \"\\<And>(s :: 'a field_desc typ_desc) f m n.\n           \\<lbrakk> field_lookup_struct st f m = Some (s, n); td_fafu_idem_struct st \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  and   \"\\<And>(s :: 'a field_desc typ_desc) f m n.\n           \\<lbrakk> field_lookup_list ts f m = Some (s, n); td_fafu_idem_list ts \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  and   \"\\<And>(s :: 'a field_desc typ_desc) f m n.\n           \\<lbrakk> field_lookup_pair p f m = Some (s, n); td_fafu_idem_pair p \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  by (induct t and st and ts and p) (auto split: if_split_asm option.splits)\n\nlemma field_access_update_same:\n  fixes t :: \"'a :: mem_type field_desc typ_desc\" and st :: \"'a field_desc typ_struct\"\n  shows \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem t; wf_fd t; length bs = size_td t; length bs' = size_td t\\<rbrakk>\n  \\<Longrightarrow> access_ti t (update_ti t bs v) bs' = bs\"\n  and \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem_struct st; wf_fd_struct st; length bs = size_td_struct st; length bs' = size_td_struct st \\<rbrakk>\n  \\<Longrightarrow> access_ti_struct st (update_ti_struct st bs v) bs' = bs\"\n  and \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem_list ts; wf_fd_list ts; length bs = size_td_list ts; length bs' = size_td_list ts\\<rbrakk>\n  \\<Longrightarrow> access_ti_list ts (update_ti_list ts bs v) bs' = bs\"\n  and \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem_pair p; wf_fd_pair p; length bs = size_td_pair p; length bs' = size_td_pair p\\<rbrakk>\n  \\<Longrightarrow> access_ti_pair p (update_ti_pair p bs v) bs' = bs\"\nproof (induct t and st and ts and p)\n  case TypScalar thus ?case by (clarsimp simp: fa_fu_idem_def)\nnext\n  case (Cons_typ_desc p' ts' v bs bs')\n  hence \"fu_commutes (update_ti_pair_t p') (update_ti_list_t ts')\" by clarsimp\n  moreover\n  have \"update_ti_pair p' (take (size_td_pair p') bs) = update_ti_pair_t p' (take (size_td_pair p') bs)\"\n    using Cons_typ_desc.prems by (simp add: update_ti_pair_t_def min_ll)\n  moreover\n  have \"update_ti_list ts' (drop (size_td_pair p') bs) = update_ti_list_t ts' (drop (size_td_pair p') bs)\"\n    using Cons_typ_desc.prems by (simp add: update_ti_list_t_def)\n  ultimately have updeq:\n    \"(update_ti_pair p' (take (size_td_pair p') bs) (update_ti_list ts' (drop (size_td_pair p') bs) v))\n    = (update_ti_list ts' (drop (size_td_pair p') bs) (update_ti_pair p' (take (size_td_pair p') bs) v))\"\n    unfolding fu_commutes_def by simp\n\n  show ?case using Cons_typ_desc.prems\n    by (clarsimp simp add: Cons_typ_desc.hyps) (simp add: updeq  Cons_typ_desc.hyps)\nqed simp+\n\nlemma access_ti_pair_dt_fst:\n  \"access_ti_pair p v bs = access_ti (dt_fst p) v bs\"\n  by (cases p, simp)\n\nlemma size_td_pair_dt_fst:\n  \"size_td_pair p = size_td (dt_fst p)\"\n  by (cases p, simp)\n\nlemma wf_fd_pair_dt_fst:\n  \"wf_fd_pair p = wf_fd (dt_fst p)\"\n  by (cases p, simp)\n\nlemma field_lookup_offset2:\n  assumes fl: \"(field_lookup t f (m + n) = Some (s, q))\"\n  shows   \"field_lookup t f m = Some (s, q - n)\"\nproof -\n  from fl have le: \"m + n \\<le> q\"\n    by (rule field_lookup_offset_le)\n\n  hence \"q = (m + n) + (q - (m + n))\"\n    by simp\n\n  hence \"field_lookup t f (m + n) = Some (s, (m + n) + (q - (m + n)))\" using fl by simp\n\n  hence \"field_lookup t f m = Some (s, m + (q - (m + n)))\"\n    by (rule iffD1 [OF field_lookup_offset'(1)])\n\n  thus ?thesis using le by simp\nqed\n\nlemma field_lookup_offset2_list:\n  assumes fl: \"(field_lookup_list ts f (m + n) = Some (s, q))\"\n  shows   \"field_lookup_list ts f m = Some (s, q - n)\"\nproof -\n  from fl have le: \"m + n \\<le> q\"\n    by (rule field_lookup_offset_le)\n\n  hence \"q = (m + n) + (q - (m + n))\"\n    by simp\n\n  hence \"field_lookup_list ts f (m + n) = Some (s, (m + n) + (q - (m + n)))\" using fl by simp\n\n  hence \"field_lookup_list ts f m = Some (s, m + (q - (m + n)))\"\n    by (rule iffD1 [OF field_lookup_offset'(3)])\n\n  thus ?thesis using le by simp\nqed\n\nlemma field_lookup_offset2_pair:\n  assumes fl: \"(field_lookup_pair p f (m + n) = Some (s, q))\"\n  shows   \"field_lookup_pair p f m = Some (s, q - n)\"\nproof -\n  from fl have le: \"m + n \\<le> q\"\n    by (rule field_lookup_offset_le)\n\n  hence \"q = (m + n) + (q - (m + n))\"\n    by simp\n\n  hence \"field_lookup_pair p f (m + n) = Some (s, (m + n) + (q - (m + n)))\" using fl by simp\n\n  hence \"field_lookup_pair p f m = Some (s, m + (q - (m + n)))\"\n    by (rule iffD1 [OF field_lookup_offset'(4)])\n\n  thus ?thesis using le by simp\nqed\n\nlemma field_lookup_offset_size':\n  shows \"field_lookup t f 0 = Some (t',n) \\<Longrightarrow> size_td t' + n \\<le> size_td t\"\n  apply(drule td_set_field_lookupD)\n  apply(erule td_set_offset_size)\ndone\n\nlemma field_access_update_nth_inner:\n  shows \"\\<And>f (s :: 'a :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk> field_lookup t f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd t;\n  length bs = size_td s; length bs' = size_td t \\<rbrakk>\n  \\<Longrightarrow> access_ti t (update_ti s bs v) bs' ! x = bs ! (x - n)\"\n\n  and \"\\<And>f (s :: 'a  :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk>field_lookup_struct st f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd_struct st;\n  length bs = size_td s; length bs' = size_td_struct st \\<rbrakk>\n  \\<Longrightarrow> access_ti_struct st (update_ti s bs v) bs' ! x = bs ! (x - n)\"\n\n  and \"\\<And>f (s :: 'a  :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk>field_lookup_list ts f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd_list ts;\n  length bs = size_td s; length bs' = size_td_list ts\\<rbrakk>\n  \\<Longrightarrow> access_ti_list ts (update_ti s bs v) bs' ! x = bs ! (x - n)\"\n\n  and \"\\<And>f (s :: 'a  :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk>field_lookup_pair p f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd_pair p;\n  length bs = size_td s; length bs' = size_td_pair p\\<rbrakk>\n  \\<Longrightarrow> access_ti_pair p (update_ti s bs v) bs' ! x = bs ! (x - n)\"\nproof (induct t and st and ts and p)\n  case (TypDesc typ_struct ls f s n x v bs bs')\n\n  show ?case\n  proof (cases \"f = []\")\n    case False thus ?thesis using TypDesc by clarsimp\n  next\n    case True\n    thus ?thesis using TypDesc.prems\n      by (simp add: field_access_update_same)\n  qed\nnext\n  case (Cons_typ_desc p' ts' f s n x v bs bs')\n  have nlex: \"n \\<le> x\" and xln: \"x < n + size_td s\"\n    and lbs: \"length bs = size_td s\" and lbs': \"length bs' = size_td_list (p' # ts')\" by fact+\n  from Cons_typ_desc have wf: \"wf_fd (dt_fst p')\" and wfts: \"wf_fd_list ts'\" by (cases p', auto)\n\n  {\n    assume fl: \"field_lookup_list ts' f (size_td (dt_fst p')) = Some (s, n)\"\n\n    hence mlt: \"size_td (dt_fst p') \\<le> n\"\n      by (rule field_lookup_offset_le)\n\n    hence \"size_td (dt_fst p') \\<le> x\"\n      by (rule order_trans) fact\n\n    hence ?case using wf lbs lbs'\n    proof (simp add: nth_append length_fa_ti access_ti_pair_dt_fst size_td_pair_dt_fst)\n      from fl have fl': \"field_lookup_list ts' f 0 = Some (s, n - size_td (dt_fst p'))\"\n        by (rule field_lookup_offset2_list [where m = 0, simplified])\n\n      show \"access_ti_list ts' (update_ti s bs v) (drop (size_td (dt_fst p')) bs') ! (x - size_td (dt_fst p')) = bs ! (x - n)\"\n        using mlt nlex xln lbs lbs' wf wfts \\<open>td_fafu_idem s\\<close> \\<open>wf_fd s\\<close>\n        by (simp add: Cons_typ_desc.hyps(2) [OF fl'] size_td_pair_dt_fst)\n    qed\n  }\n  moreover\n  {\n    note ih = Cons_typ_desc.hyps(1)[simplified access_ti_pair_dt_fst wf_fd_pair_dt_fst]\n\n    assume fl: \"field_lookup_pair p' f 0 = Some (s, n)\"\n\n    hence \"x < size_td (dt_fst p')\"\n      apply (cases p')\n      apply (simp split: if_split_asm)\n      apply (drule field_lookup_offset_size')\n      apply (rule order_less_le_trans [OF xln])\n      apply simp\n      done\n\n    hence ?case using wf lbs lbs' nlex xln wf wfts \\<open>td_fafu_idem s\\<close> \\<open>wf_fd s\\<close>\n      by (simp add: nth_append length_fa_ti access_ti_pair_dt_fst size_td_pair_dt_fst ih[OF fl])\n  }\n  ultimately show ?case using \\<open>field_lookup_list (p' # ts') f 0 = Some (s, n)\\<close> by (simp split: option.splits)\nqed (clarsimp split: if_split_asm)+\n\nsubsection \\<open>td_fa_hi\\<close>\n\n(* \\<lbrakk> size_of TYPE('a::mem_type) \\<le> length h; size_of TYPE('a) \\<le> length h' \\<rbrakk> \\<Longrightarrow> *)\n\nlemma fa_heap_indepD:\n  \"\\<lbrakk> fa_heap_indep fd n; length bs = n; length bs' = n \\<rbrakk> \\<Longrightarrow>\n  field_access fd v bs = field_access fd v bs'\"\n  unfolding fa_heap_indep_def\n  apply (drule spec, drule spec, drule spec)\n  apply (drule (1) mp)\n  apply (erule (1) mp)\n  done\n\n(* The simplifier spins on the IHs here, hence the proofs for each case *)\nlemma td_fa_hi_heap_independence:\n  shows \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi t; length h = size_td t; length h' = size_td t \\<rbrakk>\n  \\<Longrightarrow> access_ti t v h = access_ti t v h'\"\n  and   \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi_struct st; length h = size_td_struct st; length h' = size_td_struct st\\<rbrakk>\n  \\<Longrightarrow> access_ti_struct st v h = access_ti_struct st v h'\"\n  and   \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi_list ts;  length h = size_td_list ts; length h' = size_td_list ts \\<rbrakk>\n  \\<Longrightarrow> access_ti_list ts v h = access_ti_list ts v h'\"\n  and   \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi_pair p;  length h = size_td_pair p; length h' = size_td_pair p \\<rbrakk>\n  \\<Longrightarrow> access_ti_pair p v h = access_ti_pair p v h'\"\nproof (induct t and st and ts and p)\n  case TypDesc\n  from TypDesc.prems show ?case\n    by (simp) (erule (2) TypDesc.hyps)\nnext\n  case TypScalar\n  from TypScalar.prems show ?case\n    by simp (erule (2) fa_heap_indepD)\nnext\n  case TypAggregate\n  from TypAggregate.prems show ?case\n    by (simp) (erule (2) TypAggregate.hyps)\nnext\n  case Nil_typ_desc thus ?case by simp\nnext\n  case Cons_typ_desc\n  from Cons_typ_desc.prems show ?case\n    apply simp\n    apply (erule conjE)\n    apply (rule arg_cong2 [where f = \"(@)\"])\n    apply (erule Cons_typ_desc.hyps; simp)\n    apply (erule Cons_typ_desc.hyps; simp)\n    done\nnext\n  case DTPair_typ_desc\n  from DTPair_typ_desc.prems show ?case\n    by simp (erule (2) DTPair_typ_desc.hyps)\nqed\n\nsection \\<open>Simp rules for deriving packed props from the type combinators\\<close>\n\nsubsection \\<open>td_fafu_idem\\<close>\n\nlemma td_fafu_idem_final_pad:\n  \"padup (2 ^ align_td t) (size_td t) = 0\n  \\<Longrightarrow> td_fafu_idem (final_pad t) = td_fafu_idem t\"\n  unfolding final_pad_def\n  by (clarsimp simp add: padup_def Let_def)\n\nlemma td_fafu_idem_ti_typ_pad_combine:\n  fixes t :: \"'a :: c_type itself\" and s :: \"'b :: c_type field_desc typ_desc\"\n  assumes pad: \"padup (align_of TYPE('a)) (size_td s) = 0\"\n  shows \"td_fafu_idem (ti_typ_pad_combine t xf xfu nm s) = td_fafu_idem (ti_typ_combine t xf xfu nm s)\"\n  unfolding ti_typ_pad_combine_def using pad\n  by (clarsimp simp: Let_def)\n\nlemma td_fafu_idem_list_append:\n  fixes xs :: \"'a :: c_type field_desc typ_pair list\"\n  shows \"td_fafu_idem_list (xs @ ys) = (td_fafu_idem_list xs \\<and> td_fafu_idem_list ys)\"\n  by (induct xs) simp+\n\nlemma td_fafu_idem_extend_ti:\n  fixes t :: \"'a :: c_type field_desc typ_desc\"\n  assumes as: \"td_fafu_idem s\"\n  and     at: \"td_fafu_idem t\"\n  shows \"td_fafu_idem (extend_ti s t nm)\" using as at\n  by (cases s, rename_tac typ_struct xs)\n     (case_tac typ_struct; simp add: td_fafu_idem_list_append)\n\nlemma fd_cons_access_updateD:\n  \"\\<lbrakk> fd_cons_access_update d n; length bs = n; length bs' = n\\<rbrakk> \\<Longrightarrow>\n   field_access d (field_update d bs v) bs' = field_access d (field_update d bs v') bs'\"\n  unfolding fd_cons_access_update_def by clarsimp\n\nlemma fa_fu_idem_update_desc:\n  fixes a :: \"'a field_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and     fd: \"fd_cons_struct (TypScalar n n' a)\"\n  shows   \"fa_fu_idem (update_desc xf xfu a) n = fa_fu_idem a n\"\nproof\n  assume asm: \"fa_fu_idem (update_desc xf xfu a) n\"\n\n  let ?fu = \"\\<lambda>bs. if length bs = n then field_update a bs else id\"\n  let ?a' = \"\\<lparr> field_access = field_access a, field_update = ?fu \\<rparr>\"\n\n  show \"fa_fu_idem a n\"\n    unfolding fa_fu_idem_def\n  proof (intro impI conjI allI)\n    fix bs :: \"byte list\" and bs' :: \"byte list\" and v\n    assume l: \"length bs = n\" and l': \"length bs' = n\"\n\n    hence \"(\\<forall>v. field_access a (field_update a bs (xf v)) bs' = bs)\n           = (\\<forall>v. field_access a (?fu bs (xf v)) bs' = bs)\" by simp\n\n    also have \"\\<dots> = (\\<forall>v. field_access a (field_update a bs v) bs' = bs)\" using fd\n      apply -\n      apply (rule iffI)\n       apply (rule allI)\n       apply (subst (asm) fd_cons_access_updateD [OF _ l l', where d = ?a', simplified])\n        apply (simp add: fd_cons_struct_def fd_cons_desc_def)\n       apply (fastforce simp: l l')\n      apply (fastforce simp: l l')\n      done\n\n    finally show \"field_access a (field_update a bs v) bs' = bs\" using asm fg l l'\n      by (clarsimp simp add: update_desc_def fa_fu_idem_def fg_cons_def)\n  qed\nnext\n  assume \"fa_fu_idem a n\"\n  thus \"fa_fu_idem (update_desc xf xfu a) n\"\n    unfolding fa_fu_idem_def update_desc_def using fg\n    by (clarsimp simp add: update_desc_def fa_fu_idem_def fg_cons_def)\nqed\n\nlemma td_fafu_idem_map_td_update_desc:\n  assumes fg: \"fg_cons xf xfu\"\n  shows  \"wf_fd t \\<Longrightarrow> td_fafu_idem (map_td (\\<lambda>_ _. update_desc xf xfu) t) = td_fafu_idem t\"\n  and    \"wf_fd_struct st \\<Longrightarrow> td_fafu_idem_struct (map_td_struct (\\<lambda>_ _. update_desc xf xfu) st) = td_fafu_idem_struct st\"\n  and    \"wf_fd_list ts \\<Longrightarrow> td_fafu_idem_list (map_td_list (\\<lambda>_ _. update_desc xf xfu) ts) = td_fafu_idem_list ts\"\n  and    \"wf_fd_pair p \\<Longrightarrow> td_fafu_idem_pair (map_td_pair (\\<lambda>_ _. update_desc xf xfu) p) = td_fafu_idem_pair p\"\n  by (induct t and st and ts and p) (auto elim!: fa_fu_idem_update_desc [OF fg])\n\nlemmas td_fafu_idem_adjust_ti = td_fafu_idem_map_td_update_desc(1)[folded adjust_ti_def]\n\nlemma td_fafu_idem_ti_typ_combine:\n  fixes s :: \"'b :: c_type field_desc typ_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and    tda: \"td_fafu_idem (typ_info_t TYPE('a :: mem_type))\"\n  and    tds: \"td_fafu_idem s\"\n  shows \"td_fafu_idem (ti_typ_combine TYPE('a :: mem_type) xf xfu nm s)\"\n  unfolding ti_typ_combine_def using tda tds\n  apply (clarsimp simp: Let_def)\n  apply (cases s)\n  apply (rename_tac typ_struct xs)\n  apply (case_tac typ_struct)\n   apply simp\n   apply (subst td_fafu_idem_adjust_ti [OF fg wf_fd], assumption)\n  apply (simp add: td_fafu_idem_list_append)\n  apply (subst td_fafu_idem_adjust_ti [OF fg wf_fd], assumption)\n  done\n\nlemma td_fafu_idem_ptr:\n   \"td_fafu_idem (typ_info_t TYPE('a :: c_type ptr))\"\n  apply (clarsimp simp add: fa_fu_idem_def)\n  apply (subst word_rsplit_rcat_size)\n   apply (clarsimp simp add: size_of_def word_size)\n  apply simp\n  done\n\nlemma td_fafu_idem_word:\n   \"td_fafu_idem (typ_info_t TYPE('a :: len8 word))\"\n  apply(clarsimp simp: fa_fu_idem_def)\n  apply (subst word_rsplit_rcat_size)\n   apply (insert len8_dv8)\n   apply (clarsimp simp add: size_of_def word_size)\n   apply (subst dvd_div_mult_self; simp)\n  apply simp\n  done\n\nlemma fg_cons_array [simp]:\n  \"n < card (UNIV :: 'b :: finite set) \\<Longrightarrow>\n   fg_cons (\\<lambda>x. index x n) (\\<lambda>x f. Arrays.update (f :: 'a['b]) n x)\"\n  unfolding fg_cons_def by simp\n\nlemma td_fafu_idem_array_n:\n  \"\\<lbrakk> td_fafu_idem (typ_info_t TYPE('a)); n \\<le> card (UNIV :: 'b set) \\<rbrakk> \\<Longrightarrow>\n   td_fafu_idem (array_tag_n n :: ('a :: mem_type ['b :: finite]) field_desc typ_desc)\"\n  by (induct n; simp add: array_tag_n.simps empty_typ_info_def)\n     (simp add: td_fafu_idem_ti_typ_combine)\n\nlemma td_fafu_idem_array:\n  \"td_fafu_idem (typ_info_t TYPE('a)) \\<Longrightarrow> td_fafu_idem (typ_info_t TYPE('a :: mem_type ['b :: finite]))\"\n  by (clarsimp simp: typ_info_array array_tag_def fa_fu_idem_def td_fafu_idem_array_n)\n\nlemma td_fafu_idem_empty_typ_info:\n  \"td_fafu_idem (empty_typ_info t)\"\n  unfolding empty_typ_info_def\n  by simp\n\nsubsection \\<open>td_fa_hi\\<close>\n\n(* These are mostly identical to the above --- surely there is something which implies both? *)\n\nlemma td_fa_hi_final_pad:\n  \"padup (2 ^ align_td t) (size_td t) = 0\n  \\<Longrightarrow> td_fa_hi (final_pad t) = td_fa_hi t\"\n  unfolding final_pad_def\n  by (clarsimp simp add: padup_def Let_def)\n\nlemma td_fa_hi_ti_typ_pad_combine:\n  fixes t :: \"'a :: c_type itself\" and s :: \"'b :: c_type field_desc typ_desc\"\n  assumes pad: \"padup (align_of TYPE('a)) (size_td s) = 0\"\n  shows \"td_fa_hi (ti_typ_pad_combine t xf xfu nm s) = td_fa_hi (ti_typ_combine t xf xfu nm s)\"\n  unfolding ti_typ_pad_combine_def using pad\n  by (clarsimp simp: Let_def)\n\nlemma td_fa_hi_list_append:\n  fixes xs :: \"'a :: c_type field_desc typ_pair list\"\n  shows \"td_fa_hi_list (xs @ ys) = (td_fa_hi_list xs \\<and> td_fa_hi_list ys)\"\n  by (induct xs) simp+\n\nlemma td_fa_hi_extend_ti:\n  fixes t :: \"'a :: c_type field_desc typ_desc\"\n  assumes as: \"td_fa_hi s\"\n  and     at: \"td_fa_hi t\"\n  shows \"td_fa_hi (extend_ti s t nm)\" using as at\n  by (cases s, rename_tac typ_struct xs)\n     (case_tac typ_struct; simp add: td_fa_hi_list_append)\n\nlemma fa_heap_indep_update_desc:\n  fixes a :: \"'a field_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and     fd: \"fd_cons_struct (TypScalar n n' a)\"\n  shows   \"fa_heap_indep (update_desc xf xfu a) n = fa_heap_indep a n\"\nproof\n  assume asm: \"fa_heap_indep (update_desc xf xfu a) n\"\n\n  have xf_xfu: \"\\<And>v v'. xf (xfu v v') = v\" using fg\n    unfolding fg_cons_def\n    by simp\n\n  show \"fa_heap_indep a n\"\n    unfolding fa_heap_indep_def\n  proof (intro impI conjI allI)\n    fix bs :: \"byte list\" and bs' :: \"byte list\" and v\n    assume l: \"length bs = n\" and l': \"length bs' = n\"\n    with asm\n    have \"field_access (update_desc xf xfu a) (xfu v undefined) bs =\n          field_access (update_desc xf xfu a) (xfu v undefined) bs'\"\n      by (rule fa_heap_indepD)\n\n    thus \"field_access a v bs = field_access a v bs'\"\n      unfolding update_desc_def\n      by (simp add: xf_xfu)\n  qed\nnext\n  assume asm: \"fa_heap_indep a n\"\n  show \"fa_heap_indep (update_desc xf xfu a) n\"\n    unfolding fa_heap_indep_def update_desc_def\n  proof (simp, intro impI conjI allI)\n    fix bs :: \"byte list\" and bs' :: \"byte list\" and v\n    assume l: \"length bs = n\" and l': \"length bs' = n\"\n\n    with asm show \"field_access a (xf v) bs = field_access a (xf v) bs'\"\n      by (rule fa_heap_indepD)\n  qed\nqed\n\nlemma td_fa_hi_map_td_update_desc:\n  assumes fg: \"fg_cons xf xfu\"\n  shows  \"wf_fd t \\<Longrightarrow> td_fa_hi (map_td (\\<lambda>_ _. update_desc xf xfu) t) = td_fa_hi t\"\n  and    \"wf_fd_struct st \\<Longrightarrow> td_fa_hi_struct (map_td_struct (\\<lambda>_ _. update_desc xf xfu) st) = td_fa_hi_struct st\"\n  and    \"wf_fd_list ts \\<Longrightarrow> td_fa_hi_list (map_td_list (\\<lambda>_ _. update_desc xf xfu) ts) = td_fa_hi_list ts\"\n  and    \"wf_fd_pair p \\<Longrightarrow> td_fa_hi_pair (map_td_pair (\\<lambda>_ _. update_desc xf xfu) p) = td_fa_hi_pair p\"\n  by (induct t and st and ts and p) (auto elim!: fa_heap_indep_update_desc [OF fg])\n\nlemmas td_fa_hi_adjust_ti = td_fa_hi_map_td_update_desc(1)[folded adjust_ti_def]\n\nlemma td_fa_hi_ti_typ_combine:\n  fixes s :: \"'b :: c_type field_desc typ_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and    tda: \"td_fa_hi (typ_info_t TYPE('a :: mem_type))\"\n  and    tds: \"td_fa_hi s\"\n  shows \"td_fa_hi (ti_typ_combine TYPE('a :: mem_type) xf xfu nm s)\"\n  unfolding ti_typ_combine_def Let_def using tda tds\n  by (cases s, rename_tac typ_struct xs)\n     (case_tac typ_struct; simp add: td_fa_hi_list_append td_fa_hi_adjust_ti[OF fg wf_fd])\n\nlemma td_fa_hi_ptr:\n   \"td_fa_hi (typ_info_t TYPE('a :: c_type ptr))\"\n  by (clarsimp simp add: fa_heap_indep_def)\n\nlemma td_fa_hi_word:\n   \"td_fa_hi (typ_info_t TYPE('a :: len8 word))\"\n  by (clarsimp simp add: fa_heap_indep_def)\n\nlemma td_fa_hi_array_n:\n  \"\\<lbrakk>td_fa_hi (typ_info_t TYPE('a)); n \\<le> card (UNIV :: 'b set) \\<rbrakk> \\<Longrightarrow> td_fa_hi (array_tag_n n :: ('a :: mem_type ['b :: finite]) field_desc typ_desc)\"\n  by (induct n; simp add: array_tag_n.simps empty_typ_info_def td_fa_hi_ti_typ_combine)\n\nlemma td_fa_hi_array:\n  \"td_fa_hi (typ_info_t TYPE('a)) \\<Longrightarrow> td_fa_hi (typ_info_t TYPE('a :: mem_type ['b :: finite]))\"\n  by (clarsimp simp add: typ_info_array array_tag_def fa_fu_idem_def td_fa_hi_array_n)\n\nlemma td_fa_hi_empty_typ_info:\n  \"td_fa_hi (empty_typ_info t)\"\n  unfolding empty_typ_info_def\n  by simp\n\nsection \\<open>The type class and simp sets\\<close>\n\ntext \\<open>Packed types, with no padding, have the defining property that\n        access is invariant under substitution of the underlying heap and\n        access/update is the identity\\<close>\n\nclass packed_type = mem_type +\n  assumes td_fafu_idem: \"td_fafu_idem (typ_info_t TYPE('a::c_type))\"\n  assumes td_fa_hi:     \"td_fa_hi (typ_info_t TYPE('a::c_type))\"\n\nlemmas td_fafu_idem_intro_simps =\n  \\<comment> \\<open>Axioms\\<close>\n  td_fafu_idem\n  \\<comment> \\<open>Combinators\\<close>\n  td_fafu_idem_final_pad td_fafu_idem_ti_typ_pad_combine td_fafu_idem_ti_typ_combine td_fafu_idem_empty_typ_info\n  \\<comment> \\<open>Constructors\\<close>\n  td_fafu_idem_ptr td_fafu_idem_word td_fafu_idem_array\n\nlemmas td_fa_hi_intro_simps =\n  \\<comment> \\<open>Axioms\\<close>\n  td_fa_hi\n  \\<comment> \\<open>Combinators\\<close>\n  td_fa_hi_final_pad td_fa_hi_ti_typ_pad_combine td_fa_hi_ti_typ_combine td_fa_hi_empty_typ_info\n  \\<comment> \\<open>Constructors\\<close>\n  td_fa_hi_ptr td_fa_hi_word td_fa_hi_array\n\nlemma align_td_array':\n  \"align_td (typ_info_t TYPE('a :: c_type['b :: finite])) = align_td (typ_info_t TYPE('a))\"\n  by (simp add: typ_info_array array_tag_def align_td_array_tag)\n\nlemmas packed_type_intro_simps =\n  td_fafu_idem_intro_simps td_fa_hi_intro_simps align_td_array' size_td_simps size_td_array\n\nlemma access_ti_append':\n  \"\\<And>list.\n   access_ti_list (xs @ ys) t list =\n     access_ti_list xs t (take (size_td_list xs) list) @\n     access_ti_list ys t (drop (size_td_list xs) list)\"\nproof(induct xs)\n  case Nil show ?case by simp\nnext\n  case (Cons x xs) thus ?case by (simp add: min_def ac_simps drop_take)\nqed\n\nsection \\<open>Instances\\<close>\n\ntext \\<open>Words (of multiple of 8 size) are packed\\<close>\n\ninstantiation word :: (len8) packed_type\nbegin\ninstance\n  by (intro_classes; rule td_fafu_idem_word td_fa_hi_word)\nend\n\ntext \\<open>Pointers are always packed\\<close>\n\ninstantiation ptr :: (c_type)packed_type\nbegin\ninstance\n  by (intro_classes; simp add: fa_fu_idem_def word_rsplit_rcat_size word_size fa_heap_indep_def)\nend\n\ntext \\<open>Arrays of packed types are in turn packed\\<close>\n\nclass array_outer_packed = packed_type + array_outer_max_size\nclass array_inner_packed = array_outer_packed + array_inner_max_size\n\ninstance word :: (len8)array_outer_packed ..\ninstance word :: (len8)array_inner_packed ..\n\ninstance array :: (array_outer_packed, array_max_count) packed_type\n  by (intro_classes; simp add: td_fafu_idem_intro_simps td_fa_hi_intro_simps)\n\ninstance array :: (array_inner_packed, array_max_count) array_outer_packed ..\n\nsection \\<open>Theorems about packed types\\<close>\n\nsubsection \\<open>td_fa_hi\\<close>\n\nlemma heap_independence:\n  \"\\<lbrakk>length h = size_of TYPE('a :: packed_type); length h' = size_of TYPE('a) \\<rbrakk>\n  \\<Longrightarrow> access_ti (typ_info_t TYPE('a)) v h = access_ti (typ_info_t TYPE('a)) v h'\"\n  by (rule td_fa_hi_heap_independence(1)[OF td_fa_hi], simp_all add: size_of_def)\n\ntheorem packed_heap_update_collapse:\n fixes u::\"'a::packed_type\"\n fixes v::\"'a\"\n shows \"heap_update p v (heap_update p u h) = heap_update p v h\"\n  unfolding heap_update_def\n  apply(rule ext)\n  apply(case_tac \"x \\<in> {ptr_val p..+size_of TYPE('a)}\")\n   apply(simp add: heap_update_mem_same_point)\n   apply(simp add:to_bytes_def)\n   apply(subst heap_independence, simp)\n    prefer 2\n    apply(rule refl)\n   apply(simp)\n  apply(simp add: heap_update_nmem_same)\n  done\n\nlemma packed_heap_update_collapse_hrs:\n  fixes p :: \"'a :: packed_type ptr\"\n  shows \"hrs_mem_update (heap_update p v) (hrs_mem_update (heap_update p v') hp) =\n         hrs_mem_update (heap_update p v) hp\"\n  unfolding hrs_mem_update_def\n  by (simp add: split_def packed_heap_update_collapse)\n\nsubsection \\<open>td_fafu_idem\\<close>\n\nlemma order_leE:\n  fixes x :: \"'a :: order\"\n  shows \"\\<lbrakk> x \\<le> y; x = y \\<Longrightarrow> P; x < y \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P\"\n  by (auto simp: order_le_less)\n\nlemma of_nat_mono_maybe_le:\n  shows \"\\<lbrakk>X < 2 ^ len_of TYPE('a); Y \\<le> X\\<rbrakk> \\<Longrightarrow> (of_nat Y :: 'a :: len word) \\<le> of_nat X\"\n  apply (erule order_leE)\n   apply simp\n  apply (rule order_less_imp_le)\n  apply (erule (1) of_nat_mono_maybe)\n  done\n\nlemma intvl_le_lower:\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk> x \\<in> {y..+n}; y \\<le> y + of_nat (n - 1); n < 2 ^ len_of TYPE('a) \\<rbrakk> \\<Longrightarrow> y \\<le> x\"\n  apply (drule intvlD)\n  apply (elim conjE exE)\n  apply (erule ssubst)\n  apply (erule word_plus_mono_right2)\n  apply (rule of_nat_mono_maybe_le)\n   apply simp\n  apply simp\n  done\n\nlemma intvl_less_upper:\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk> x \\<in> {y..+n}; y \\<le> y + of_nat (n - 1); n < 2 ^ len_of TYPE('a) \\<rbrakk> \\<Longrightarrow> x \\<le> y + of_nat (n - 1)\"\n  apply (drule intvlD)\n  apply (elim conjE exE)\n  apply (erule ssubst)\n  apply (rule word_plus_mono_right; assumption?)\n  apply (rule of_nat_mono_maybe_le; simp)\n  done\n\nlemma packed_type_access_ti:\n  fixes v :: \"'a :: packed_type\"\n  assumes lbs: \"length bs = size_of TYPE('a)\"\n  shows \"access_ti (typ_info_t TYPE('a)) v bs = access_ti\\<^sub>0 (typ_info_t TYPE('a)) v\"\n  unfolding access_ti\\<^sub>0_def\n  by (rule heap_independence; simp add: lbs size_of_def)\n\nlemma update_ti_update_ti_t:\n  \"length bs = size_td s \\<Longrightarrow> update_ti s bs v = update_ti_t s bs v\"\n  unfolding update_ti_t_def by simp\n\nlemma heap_list_nth:\n  \"m < n \\<Longrightarrow> heap_list hp n p ! m = hp (p + of_nat m)\"\nproof (induct m arbitrary: n p)\n  case (0 n' p')\n  thus ?case by (cases n', simp_all)\nnext\n  case (Suc m' n' p')\n  show ?case\n  proof (cases n')\n    case 0 thus ?thesis using \\<open>Suc m' < n'\\<close> by simp\n  next\n    case (Suc n'')\n    hence \"m' < n''\" using \\<open>Suc m' < n'\\<close> by simp\n    thus ?thesis using Suc\n      by (simp add: Suc.hyps ac_simps)\n  qed\nqed\n\nlemma c_guard_field_lvalue:\n  fixes p :: \"'a :: mem_type ptr\"\n  assumes cg: \"c_guard p\"\n  and     fl: \"field_lookup (typ_info_t TYPE('a)) f 0 = Some (t, n)\"\n  and     eu: \"export_uinfo t = typ_uinfo_t TYPE('b :: mem_type)\"\n  shows   \"c_guard (Ptr &(p\\<rightarrow>f) :: 'b :: mem_type ptr)\"\n  unfolding c_guard_def\nproof (rule conjI)\n  from cg fl eu show \"ptr_aligned (Ptr &(p\\<rightarrow>f) :: 'b ptr)\"\n    by (rule c_guard_ptr_aligned_fl)\nnext\n  from eu have std: \"size_td t = size_of TYPE('b)\" using fl\n    by (simp add: export_size_of)\n\n  from cg have \"c_null_guard p\" unfolding c_guard_def ..\n  thus \"c_null_guard (Ptr &(p\\<rightarrow>f)  :: 'b ptr)\" unfolding c_null_guard_def\n    apply (rule contrapos_nn)\n    apply (rule subsetD [OF field_tag_sub, OF fl])\n    apply (simp add: std)\n    done\nqed\n\n\nlemma c_guard_no_wrap:\n  fixes p :: \"'a :: mem_type ptr\"\n  assumes cgrd: \"c_guard p\"\n  shows   \"ptr_val p \\<le> ptr_val p + of_nat (size_of TYPE('a) - 1)\"\n  using cgrd unfolding c_guard_def c_null_guard_def\n  apply -\n  apply (erule conjE)\n  apply (erule contrapos_np)\n  apply (simp add: intvl_def)\n  apply (drule word_wrap_of_natD)\n  apply (erule exE)\n  apply (rule exI)\n  apply (simp add: nat_le_Suc_less)\n  done\n\ntheorem packed_heap_super_field_update:\n  fixes v :: \"'a :: packed_type\" and p :: \"'b :: packed_type ptr\"\n  assumes fl: \"field_lookup (typ_info_t TYPE('b)) f 0 = Some (t, n)\"\n  and   cgrd: \"c_guard p\"\n  and     eu: \"export_uinfo t = typ_uinfo_t TYPE('a)\"\n  shows   \"heap_update (Ptr &(p\\<rightarrow>f)) v hp = heap_update p (update_ti t (to_bytes_p v) (h_val hp p)) hp\"\n  unfolding heap_update_def to_bytes_def\nproof (simp add: packed_type_access_ti, rule ext)\n  fix x\n  let ?LHS = \"heap_update_list &(p\\<rightarrow>f) (to_bytes_p v) hp x\"\n  let ?RHS = \"heap_update_list (ptr_val p) (to_bytes_p (update_ti t (to_bytes_p v) (h_val hp p))) hp x\"\n\n  from cgrd have al: \"ptr_val p \\<le> ptr_val p + of_nat (size_of TYPE('b) - 1)\" by (rule c_guard_no_wrap)\n\n  have szb: \"size_of TYPE('b) < 2 ^ len_of TYPE(addr_bitsize)\"\n    apply (fold card_word)\n    apply (fold addr_card_def)\n    apply (rule max_size)\n    done\n\n  have szt: \"n + size_td t \\<le> size_of TYPE('b)\"\n    unfolding size_of_def\n    by (subst add.commute, rule field_lookup_offset_size [OF fl])\n  moreover have t0: \"0 < size_td t\" using fl wf_size_desc\n    by (rule field_lookup_wf_size_desc_gt)\n  ultimately have szn: \"n < size_of TYPE('b)\" by simp\n  from szt have szt1: \"n + (size_td t - 1) \\<le> size_of TYPE('b)\"\n    by simp\n\n  have b0: \"0 < size_of (TYPE ('b))\" using wf_size_desc\n    unfolding size_of_def\n    by (rule wf_size_desc_gt)\n\n  have uofn: \"unat (of_nat n :: addr_bitsize word) = n\" using szn szb\n    by (simp add: nat_less_le unat_of_nat_eq)\n\n  from eu have std: \"size_td t = size_of TYPE('a)\" using fl\n    by (simp add: export_size_of)\n\n  hence \"?LHS = (if x \\<in> {&(p\\<rightarrow>f)..+size_td t} then (to_bytes_p v) ! unat (x - &(p\\<rightarrow>f)) else hp x)\"\n    by (simp add: heap_update_mem_same_point heap_update_nmem_same)\n  also have \"... = ?RHS\"\n  proof (simp, intro impI conjI)\n    assume xin: \"x \\<in> {&(p\\<rightarrow>f)..+size_td t}\"\n    have \"to_bytes_p v ! unat (x - &(p\\<rightarrow>f)) = to_bytes_p (update_ti t (to_bytes_p v) (h_val hp p)) ! unat (x - ptr_val p)\"\n    proof (simp add: to_bytes_p_def to_bytes_def, subst field_access_update_nth_inner(1)[OF fl, simplified])\n\n      have \"c_guard (Ptr &(p\\<rightarrow>f) :: 'a ptr)\" using cgrd fl eu\n        by (rule c_guard_field_lvalue)\n      hence pft: \"&(p\\<rightarrow>f) \\<le> &(p\\<rightarrow>f) + of_nat (size_td t - 1)\"\n        apply -\n        apply (drule c_guard_no_wrap)\n        apply (simp add: std)\n        done\n\n      have szt': \"size_td t < 2 ^ len_of TYPE(addr_bitsize)\"\n        apply (subst std)\n        apply (fold card_word)\n        apply (fold addr_card_def)\n        apply (rule max_size)\n        done\n\n      have ofn: \"of_nat n \\<le> x - ptr_val p\"\n      proof (rule le_minus')\n        from xin show \"ptr_val p + of_nat n \\<le> x\" using pft szt'\n          unfolding field_lvalue_def field_lookup_offset_eq [OF fl]\n          by (rule intvl_le_lower)\n      next\n        from szb szn have \"of_nat n \\<le> (of_nat (size_of TYPE('b) - 1) :: addr_bitsize word)\"\n          apply -\n          apply (rule of_nat_mono_maybe_le)\n           apply simp_all\n          done\n        with al show \"ptr_val p \\<le> ptr_val p + of_nat n\"\n          by (rule word_plus_mono_right2)\n      qed\n\n      thus nlt: \"n \\<le> unat (x - ptr_val p)\"\n        by (simp add: word_le_nat_alt uofn)\n      have \"x \\<le> ptr_val p + (of_nat n + of_nat (size_td t - 1))\" using xin pft szt' t0\n        unfolding field_lvalue_def field_lookup_offset_eq [OF fl]\n        apply -\n        apply (drule (2) intvl_less_upper)\n        apply (simp add: add.assoc)\n        done\n      moreover have \"x \\<in> {ptr_val p..+size_of TYPE('b)}\" using fl xin\n        by (rule subsetD [OF field_tag_sub])\n      ultimately have \"x - ptr_val p \\<le> (of_nat n + of_nat (size_td t - 1))\" using al szb\n        apply -\n        apply (rule word_diff_ls(4)[where xa=x and x=x for x, simplified])\n         apply (metis (hide_lams, mono_tags) add.commute of_nat_add)\n        apply (erule (2) intvl_le_lower)\n        done\n      moreover have \"unat (of_nat n + of_nat (size_td t - 1) :: addr_bitsize word) = n + size_td t - 1\"\n        using t0 order_le_less_trans [OF szt1 szb]\n        apply (subst Abs_fnat_homs(1))\n        apply (subst unat_of_nat)\n        apply simp\n        done\n      ultimately have \"unat (x - ptr_val p) \\<le> n + size_td t - 1\"\n        by (simp add: word_le_nat_alt)\n      thus \"unat (x - ptr_val p) < n + size_td t\" using t0\n        by simp\n\n      show \"td_fafu_idem t\"\n        by (rule field_lookup_td_fafu_idem(1)[OF fl td_fafu_idem])\n\n      show \"wf_fd t\"\n        by (rule wf_fd_field_lookupD [OF fl wf_fd])\n\n      show \"length (access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0)) = size_td t\"\n        using wf_fd [where 'a = 'a]\n        by (simp add: length_fa_ti size_of_def std)\n\n      show \"length (replicate (size_of TYPE('b)) 0) = size_td (typ_info_t TYPE('b))\"\n        by (simp add: size_of_def)\n\n      have \"unat (x - &(p\\<rightarrow>f)) = unat ((x - ptr_val p) - of_nat n)\"\n        by (simp add: field_lvalue_def field_lookup_offset_eq [OF fl])\n      also have \"\\<dots> = unat (x - ptr_val p) - n\"\n        by (simp add: unat_sub [OF ofn] uofn)\n      finally have \"unat (x - &(p\\<rightarrow>f)) = unat (x - ptr_val p) - n\" .\n\n      thus \"access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0) ! unat (x - &(p\\<rightarrow>f)) =\n        access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0) ! (unat (x - ptr_val p) - n)\"\n        by simp\n    qed\n\n    thus \"to_bytes_p v ! unat (x - &(p\\<rightarrow>f)) = ?RHS\"\n    proof (subst heap_update_mem_same_point, simp_all)\n      show \"x \\<in> {ptr_val p..+size_of TYPE('b)}\" using fl xin\n        by (rule subsetD [OF field_tag_sub])\n    qed\n  next\n    assume xni: \"x \\<notin> {&(p\\<rightarrow>f)..+size_td t}\"\n    have \"?RHS = (if x \\<in> {ptr_val p..+size_of TYPE('b)}\n          then (to_bytes_p (update_ti t (to_bytes_p v) (h_val hp p))) ! unat (x - ptr_val p) else hp x)\"\n      by (simp add: heap_update_mem_same_point heap_update_nmem_same)\n\n    also\n    {\n      assume xin: \"x \\<in> {ptr_val p..+size_of TYPE('b)}\"\n\n      hence \"access_ti (typ_info_t TYPE('b))\n        (update_ti_t t (access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0)) (h_val hp p))\n        (replicate (size_of TYPE('b)) 0) ! unat (x - ptr_val p) = hp x\"\n      proof (subst field_access_update_nth_disjD [OF fl])\n        have \"x - ptr_val p \\<le> of_nat (size_of TYPE('b) - 1)\"\n        proof (rule word_diff_ls(4)[where xa=x and x=x for x, simplified])\n          from xin show \"x \\<le> of_nat (size_of TYPE('b) - 1) + ptr_val p\" using al szb\n            by (subst add.commute, rule intvl_less_upper)\n          show \"ptr_val p \\<le> x\" using xin al szb\n            by (rule intvl_le_lower)\n        qed\n        thus unx: \"unat (x - ptr_val p) < size_td (typ_info_t TYPE('b))\" using szb b0\n          by (simp add: word_le_nat_alt size_of_def unat_of_nat)\n\n        show \"unat (x - ptr_val p) < n - 0 \\<or> n - 0 + size_td t \\<le> unat (x - ptr_val p)\" using xin xni\n          unfolding field_lvalue_def field_lookup_offset_eq [OF fl]\n          apply -\n          apply (erule intvl_cut)\n           apply simp\n          apply (rule max_size)\n          done\n\n        show \"wf_fd (typ_info_t TYPE('b))\" by (rule wf_fd)\n            (* clag *)\n        show \"length (access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0)) = size_td t\"\n          using wf_fd [where 'a = 'a]\n          by (simp add: length_fa_ti size_of_def std)\n\n        show \"length (replicate (size_of TYPE('b)) 0) = size_td (typ_info_t TYPE('b))\"\n          by (simp add: size_of_def)\n\n        have \"heap_list hp (size_td (typ_info_t TYPE('b))) (ptr_val p) ! unat (x - ptr_val p) = hp x\"\n          apply (subst heap_list_nth)\n           apply (rule unx)\n          apply simp\n          done\n\n        thus \"access_ti (typ_info_t TYPE('b)) (h_val hp p) (replicate (size_of TYPE('b)) 0) ! unat (x - ptr_val p) = hp x\"\n          unfolding h_val_def\n          by (simp add: from_bytes_def update_ti_t_def size_of_def field_access_update_same(1)[OF td_fafu_idem wf_fd])\n      qed\n    }\n    hence \"\\<dots> = hp x\"\n      by (simp add: to_bytes_p_def to_bytes_def update_ti_update_ti_t length_fa_ti [OF wf_fd] std size_of_def)\n    finally show \"hp x = ?RHS\" by simp\n  qed\n  finally show \"?LHS = ?RHS\" .\nqed\n\nsubsection \\<open>Proof automation for packed types\\<close>\n\ndefinition td_packed :: \"'a field_desc typ_desc \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> bool\"\n  where \"td_packed t sz al \\<longleftrightarrow>\n    td_fafu_idem t \\<and> td_fa_hi t \\<and> aggregate t \\<and> size_td t = sz \\<and> align_td t = al\"\n\nlemma packed_type_class_intro:\n  \"td_packed (typ_info_t TYPE('a::mem_type)) s a\n    \\<Longrightarrow> OFCLASS('a::mem_type, packed_type_class)\"\n  by standard (simp_all add: td_packed_def)\n\nlemma td_packed_final_pad:\n  \"\\<lbrakk>td_packed t s a; 2 ^ a dvd s\\<rbrakk> \\<Longrightarrow> td_packed (final_pad t) s a\"\n  by (simp add: padup_dvd [symmetric] td_packed_def final_pad_def)\n\nlemma td_packed_ti_typ_combine:\n  \"\\<lbrakk> td_packed (td::'a::c_type field_desc typ_desc) s a;\n     align_of TYPE('b::packed_type) dvd s; fg_cons xf xfu \\<rbrakk>\n    \\<Longrightarrow> td_packed (ti_typ_combine TYPE('b) xf xfu nm td)\n                  (s + size_td (typ_info_t TYPE('b)))\n                  (max a (align_td (typ_info_t TYPE('b))))\"\n  unfolding td_packed_def\n  apply safe\n      apply (rule td_fafu_idem_ti_typ_combine; assumption?)\n      apply (rule td_fafu_idem)\n     apply (rule td_fa_hi_ti_typ_combine; assumption?)\n     apply (rule td_fa_hi)\n    apply simp\n   apply (simp only: size_td_lt_ti_typ_combine)\n  apply (simp only: align_of_ti_typ_combine)\n  done\n\nlemma td_packed_ti_typ_pad_combine:\n  \"\\<lbrakk> td_packed (td::'a::c_type field_desc typ_desc) s a;\n     align_of TYPE('b::packed_type) dvd s; fg_cons xf xfu \\<rbrakk>\n    \\<Longrightarrow> td_packed (ti_typ_pad_combine TYPE('b) xf xfu nm td)\n                  (s + size_td (typ_info_t TYPE('b)))\n                  (max a (align_td (typ_info_t TYPE('b))))\"\n  apply (subgoal_tac \"padup (align_of TYPE('b)) (size_td td) = 0\")\n   apply (simp add: ti_typ_pad_combine_def Let_def td_packed_ti_typ_combine)\n  apply (simp add: align_of_def padup_dvd td_packed_def)\n  done\n\nlemma td_packed_ti_typ_combine_array:\n  \"\\<lbrakk>td_packed (td::'a::c_type field_desc typ_desc) s a;\n    align_of TYPE('b::packed_type) dvd s; fg_cons xf xfu\\<rbrakk>\n    \\<Longrightarrow> td_packed\n      (ti_typ_combine TYPE('b ['n :: finite]) xf xfu nm td)\n      (s + size_td (typ_info_t TYPE('b)) * CARD('n))\n      (max a (align_td (typ_info_t TYPE('b))))\"\n  by (clarsimp simp: ti_typ_combine_def td_packed_def\n                     packed_type_intro_simps td_fafu_idem_extend_ti\n                     td_fa_hi_extend_ti td_fa_hi_adjust_ti\n                     size_td_extend_ti size_of_def\n                     td_fafu_idem_adjust_ti)\n\nlemma td_packed_ti_typ_pad_combine_array:\n  \"\\<lbrakk> td_packed (td::'a::c_type field_desc typ_desc) s a;\n     align_of TYPE('b::packed_type) dvd s; fg_cons xf xfu \\<rbrakk>\n    \\<Longrightarrow> td_packed (ti_typ_pad_combine TYPE('b ['n :: finite]) xf xfu nm td)\n                  (s + size_td (typ_info_t TYPE('b)) * CARD('n))\n                  (max a (align_td (typ_info_t TYPE('b))))\"\n  apply (subgoal_tac \"padup (align_of TYPE('b['n])) (size_td td) = 0\")\n   apply (simp add: ti_typ_pad_combine_def Let_def)\n   apply (simp add: td_packed_ti_typ_combine_array)\n  apply (simp add: align_of_def padup_dvd td_packed_def align_td_array)\n  done\n\nlemma td_packed_empty_typ_info:\n  \"td_packed (empty_typ_info fn) 0 0\"\n  apply (unfold td_packed_def, safe)\n      apply (rule td_fafu_idem_empty_typ_info)\n     apply (rule td_fa_hi_empty_typ_info)\n    apply (rule aggregate_empty_typ_info)\n   apply (rule size_td_empty_typ_info)\n  apply (rule align_of_empty_typ_info)\n  done\n\nlemmas td_packed_intros =\n  td_packed_final_pad\n  td_packed_empty_typ_info\n  td_packed_ti_typ_combine\n  td_packed_ti_typ_pad_combine\n  td_packed_ti_typ_combine_array\n  td_packed_ti_typ_pad_combine_array\n\n\nend\n", "meta": {"author": "NICTA", "repo": "l4v", "sha": "3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b", "save_path": "github-repos/isabelle/NICTA-l4v", "path": "github-repos/isabelle/NICTA-l4v/l4v-3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b/tools/c-parser/PackedTypes.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6224593312018546, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.28938232119177065}}
{"text": "section {* \\isaheader{Generic Map To Set Converter} *}\ntheory Gen_Map2Set\nimports \n  \"../Intf/Intf_Map\"\n  \"../Intf/Intf_Set\"\n  \"../Intf/Intf_Comp\"\n  \"../../Iterator/Iterator\"\nbegin\n\nlemma map_fst_unit_distinct_eq[simp]:\n  fixes l :: \"('k\\<times>unit) list\"\n  shows \"distinct (map fst l) \\<longleftrightarrow> distinct l\"\n  by (induct l) auto\n\ndefinition \n  map2set_rel :: \"\n    (('ki\\<times>'k) set \\<Rightarrow> (unit\\<times>unit) set \\<Rightarrow> ('mi\\<times>('k\\<rightharpoonup>unit))set) \\<Rightarrow> \n    ('ki\\<times>'k) set \\<Rightarrow> \n    ('mi\\<times>('k set)) set\"\n  where \n  map2set_rel_def_internal: \n  \"map2set_rel R Rk \\<equiv> \\<langle>Rk,Id::(unit\\<times>_) set\\<rangle>R O {(m,dom m)| m. True}\"\n\nlemma map2set_rel_def: \"\\<langle>Rk\\<rangle>(map2set_rel R) \n  = \\<langle>Rk,Id::(unit\\<times>_) set\\<rangle>R O {(m,dom m)| m. True}\"\n  unfolding map2set_rel_def_internal[abs_def] by (simp add: relAPP_def)\n\nlemma map2set_relI:\n  assumes \"(s,m')\\<in>\\<langle>Rk,Id\\<rangle>R\" and \"s'=dom m'\"\n  shows \"(s,s')\\<in>\\<langle>Rk\\<rangle>map2set_rel R\"\n  using assms unfolding map2set_rel_def by blast\n\nlemma map2set_relE:\n  assumes \"(s,s')\\<in>\\<langle>Rk\\<rangle>map2set_rel R\"\n  obtains m' where \"(s,m')\\<in>\\<langle>Rk,Id\\<rangle>R\" and \"s'=dom m'\"\n  using assms unfolding map2set_rel_def by blast\n\nlemma map2set_rel_sv[relator_props]:\n  \"single_valued (\\<langle>Rk,Id\\<rangle>Rm) \\<Longrightarrow> single_valued (\\<langle>Rk\\<rangle>map2set_rel Rm)\"\n  unfolding map2set_rel_def\n  by (auto intro: single_valuedI dest: single_valuedD)\n\nlemma map2set_empty[autoref_rules_raw]:\n  assumes \"PRIO_TAG_GEN_ALGO\"\n  assumes \"GEN_OP e op_map_empty (\\<langle>Rk,Id\\<rangle>R)\"\n  shows \"(e,{})\\<in>\\<langle>Rk\\<rangle>map2set_rel R\"\n  using assms\n  unfolding map2set_rel_def\n  by auto\n\nlemmas [autoref_rel_intf] = \n  REL_INTFI[of \"map2set_rel R\" i_set] for R\n\n\ndefinition \"map2set_insert i k s \\<equiv> i k () s\"\nlemma map2set_insert[autoref_rules_raw]:\n  assumes \"PRIO_TAG_GEN_ALGO\"\n  assumes \"GEN_OP i op_map_update (Rk \\<rightarrow> Id \\<rightarrow> \\<langle>Rk,Id\\<rangle>R \\<rightarrow> \\<langle>Rk,Id\\<rangle>R)\"\n  shows \n    \"(map2set_insert i,Set.insert)\\<in>Rk\\<rightarrow>\\<langle>Rk\\<rangle>map2set_rel R \\<rightarrow> \\<langle>Rk\\<rangle>map2set_rel R\"\n  using assms\n  unfolding map2set_rel_def map2set_insert_def[abs_def]\n  by (force dest: fun_relD)\n\ndefinition \"map2set_memb l k s \\<equiv> case l k s of None \\<Rightarrow> False | Some _ \\<Rightarrow> True\"\nlemma map2set_memb[autoref_rules_raw]:\n  assumes \"PRIO_TAG_GEN_ALGO\"\n  assumes \"GEN_OP l op_map_lookup (Rk \\<rightarrow> \\<langle>Rk,Id\\<rangle>R \\<rightarrow> \\<langle>Id\\<rangle>option_rel)\"\n  shows \"(map2set_memb l ,op\\<in>)\n    \\<in> Rk\\<rightarrow>\\<langle>Rk\\<rangle>map2set_rel R\\<rightarrow>Id\"\n  using assms\n  unfolding map2set_rel_def map2set_memb_def[abs_def]\n  by (force dest: fun_relD split: option.splits)\n  \nlemma map2set_delete[autoref_rules_raw]:\n  assumes \"PRIO_TAG_GEN_ALGO\"\n  assumes \"GEN_OP d op_map_delete (Rk\\<rightarrow>\\<langle>Rk,Id\\<rangle>R\\<rightarrow>\\<langle>Rk,Id\\<rangle>R)\"\n  shows \"(d,op_set_delete)\\<in>Rk\\<rightarrow>\\<langle>Rk\\<rangle>map2set_rel R\\<rightarrow>\\<langle>Rk\\<rangle>map2set_rel R\"\n  using assms\n  unfolding map2set_rel_def\n  by (force dest: fun_relD)\n\nlemma map2set_to_sorted_list[autoref_ga_rules]:\n  fixes it :: \"'m \\<Rightarrow> ('k\\<times>unit) list\"\n  assumes A: \"GEN_ALGO_tag (is_map_to_sorted_list ordR Rk Id R it)\"\n  shows \"is_set_to_sorted_list ordR Rk (map2set_rel R) \n    (it_to_list (map_iterator_dom o (foldli o it)))\"\nproof -\n  { \n    fix l::\"('k\\<times>unit) list\"\n    have \"\\<And>l0. foldli l (\\<lambda>_. True) (\\<lambda>x \\<sigma>. \\<sigma> @ [fst x]) l0 = l0@map fst l\"\n      by (induct l) auto\n  }\n  hence S: \"it_to_list (map_iterator_dom o (foldli o it)) = map fst o it\"\n    unfolding it_to_list_def[abs_def] map_iterator_dom_def[abs_def]\n      set_iterator_image_def set_iterator_image_filter_def\n    by (auto)\n  show ?thesis\n    unfolding S\n    using assms\n    unfolding is_map_to_sorted_list_def is_set_to_sorted_list_def\n    apply clarsimp\n    apply (erule map2set_relE)\n    apply (drule spec, drule spec)\n    apply (drule (1) mp)\n    apply (elim exE conjE)\n    apply (rule_tac x=\"map fst l'\" in exI)\n    apply (rule conjI)\n    apply parametricity\n\n    unfolding it_to_sorted_list_def\n    apply (simp add: map_to_set_dom)\n    apply (simp add: sorted_by_rel_map key_rel_def[abs_def])\n    done\nqed\n\nlemma map2set_to_list[autoref_ga_rules]:\n  fixes it :: \"'m \\<Rightarrow> ('k\\<times>unit) list\"\n  assumes A: \"GEN_ALGO_tag (is_map_to_list Rk Id R it)\"\n  shows \"is_set_to_list Rk (map2set_rel R) \n    (it_to_list (map_iterator_dom o (foldli o it)))\"\n  using assms unfolding is_set_to_list_def is_map_to_list_def\n  by (rule map2set_to_sorted_list)\n\n\n(*lemma map2set_it_simp[iterator_simps]:\n  \"foldli ((map fst o it) x) c f s = foldli (it x) c (\\<lambda>(k,v) s. f k s) s\" \n  by (simp add: foldli_map comp_def fn_fst_conv)\n*)\n\ntext {* Transfering also non-basic operations results in specializations\n  of map-algorithms to also be used for sets *}\nlemma map2set_union[autoref_rules_raw]:\n  assumes \"MINOR_PRIO_TAG (- 9)\"\n  assumes \"GEN_OP u op ++ (\\<langle>Rk,Id\\<rangle>R\\<rightarrow>\\<langle>Rk,Id\\<rangle>R\\<rightarrow>\\<langle>Rk,Id\\<rangle>R)\"\n  shows \"(u,op \\<union>)\\<in>\\<langle>Rk\\<rangle>map2set_rel R\\<rightarrow>\\<langle>Rk\\<rangle>map2set_rel R\\<rightarrow>\\<langle>Rk\\<rangle>map2set_rel R\"\n  using assms\n  unfolding map2set_rel_def\n  by (force dest: fun_relD)\n\nlemmas [autoref_ga_rules] = cmp_unit_eq_linorder \nlemmas [autoref_rules_raw] = param_cmp_unit\n\nlemma cmp_lex_zip_unit[simp]:\n  \"cmp_lex (cmp_prod cmp cmp_unit) (map (\\<lambda>k. (k, ())) l)\n           (map (\\<lambda>k. (k, ())) m) =\n          cmp_lex cmp l m\"\n  apply (induct cmp l m rule: cmp_lex.induct)\n  apply (auto split: comp_res.split)\n  done\n\nlemma cmp_img_zip_unit[simp]:\n  \"cmp_img (\\<lambda>m. map (\\<lambda>k. (k,())) (f m)) (cmp_lex (cmp_prod cmp1 cmp_unit))\n    = cmp_img f (cmp_lex cmp1)\"\n  unfolding cmp_img_def[abs_def]\n  apply (intro ext)\n  apply simp\n  done\n\n(* TODO: Move *)\n\nlemma map2set_finite[relator_props]:\n  assumes \"finite_map_rel (\\<langle>Rk,Id\\<rangle>R)\"\n  shows \"finite_set_rel (\\<langle>Rk\\<rangle>map2set_rel R)\"\n  using assms\n  unfolding map2set_rel_def finite_set_rel_def finite_map_rel_def\n  by auto\n\nlemma map2set_cmp[autoref_rules_raw]:\n  assumes ELO: \"SIDE_GEN_ALGO (eq_linorder cmpk)\"\n  assumes MPAR:\n    \"GEN_OP cmp (cmp_map cmpk cmp_unit) (\\<langle>Rk,Id\\<rangle>R \\<rightarrow> \\<langle>Rk,Id\\<rangle>R \\<rightarrow> Id)\"\n  assumes FIN: \"PREFER finite_map_rel (\\<langle>Rk, Id\\<rangle>R)\"\n  shows \"(cmp,cmp_set cmpk)\\<in>\\<langle>Rk\\<rangle>map2set_rel R \\<rightarrow> \\<langle>Rk\\<rangle>map2set_rel R \\<rightarrow> Id\"\nproof -\n  interpret linorder \"comp2le cmpk\" \"comp2lt cmpk\"\n    using ELO by (simp add: eq_linorder_class_conv)\n\n  show ?thesis\n    using MPAR\n    unfolding cmp_map_def cmp_set_def\n    apply simp\n    apply parametricity\n    apply (drule cmp_extend_paramD)\n    apply (insert FIN, fastforce simp add: finite_map_rel_def) []\n    apply (simp add: sorted_list_of_map_def[abs_def])\n    apply (auto simp: map2set_rel_def cmp_img_def[abs_def] dest: fun_relD) []\n\n    apply (insert map2set_finite[OF FIN[unfolded autoref_tag_defs]],\n      fastforce simp add: finite_set_rel_def)\n    done\nqed\n\nend\n", "meta": {"author": "andredidier", "repo": "phd", "sha": "113f7c8b360a3914a571db13d9513e313954f4b2", "save_path": "github-repos/isabelle/andredidier-phd", "path": "github-repos/isabelle/andredidier-phd/phd-113f7c8b360a3914a571db13d9513e313954f4b2/thesis/Collections/GenCF/Gen/Gen_Map2Set.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5698526514141571, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.28937793727907074}}
{"text": "(*  Title:      JinjaThreads/MM/MM.thy\n    Author:     Andreas Lochbihler\n*)\n\nchapter \\<open>Memory Models\\<close>\n\ntheory MM\nimports\n  \"../Common/Heap\"\nbegin\n\ntype_synonym addr = nat\ntype_synonym thread_id = addr\n\nabbreviation (input) \n  addr2thread_id :: \"addr \\<Rightarrow> thread_id\"\nwhere \"addr2thread_id \\<equiv> \\<lambda>x. x\"\n\nabbreviation (input)\n  thread_id2addr :: \"thread_id \\<Rightarrow> addr\"\nwhere \"thread_id2addr \\<equiv> \\<lambda>x. x\"\n\ninstantiation nat :: addr begin\ndefinition \"hash_addr \\<equiv> int\"\ndefinition \"monitor_finfun_to_list \\<equiv> (finfun_to_list :: nat \\<Rightarrow>f nat \\<Rightarrow> nat list)\"\ninstance\nby(intro_classes)(simp add: monitor_finfun_to_list_nat_def)\nend\n\ndefinition new_Addr :: \"(addr \\<rightharpoonup> 'b) \\<Rightarrow> addr option\"\nwhere \"new_Addr h \\<equiv> if \\<exists>a. h a = None then Some(LEAST a. h a = None) else None\"\n\nlemma new_Addr_SomeD:\n  \"new_Addr h = Some a \\<Longrightarrow> h a = None\"\nby(auto simp add:new_Addr_def split:if_splits intro: LeastI)\n\nlemma new_Addr_SomeI:\n  \"finite (dom h) \\<Longrightarrow> \\<exists>a. new_Addr h = Some a\"\nby(simp add: new_Addr_def) (metis finite_map_freshness infinite_UNIV_nat)\n\nsubsection \\<open>Code generation\\<close>\n\ndefinition gen_new_Addr :: \"(addr \\<rightharpoonup> 'b) \\<Rightarrow> addr \\<Rightarrow> addr option\"\nwhere \"gen_new_Addr h n \\<equiv> if \\<exists>a. a \\<ge> n \\<and> h a = None then Some(LEAST a. a \\<ge> n \\<and> h a = None) else None\"\n\nlemma new_Addr_code_code [code]:\n  \"new_Addr h = gen_new_Addr h 0\"\nby(simp add: new_Addr_def gen_new_Addr_def)\n\nlemma gen_new_Addr_code [code]:\n  \"gen_new_Addr h n = (if h n = None then Some n else gen_new_Addr h (Suc n))\"\napply(simp add: gen_new_Addr_def)\napply(rule impI)\napply(rule conjI)\n apply safe[1]\n  apply(auto intro: Least_equality)[2]\n apply(rule arg_cong[where f=Least])\n apply(rule ext)\n apply auto[1]\n apply(case_tac \"n = ab\")\n  apply simp\n apply simp\napply clarify\napply(subgoal_tac \"a = n\")\n apply simp\n apply(rule Least_equality)\n apply auto[2]\napply(rule ccontr)\napply(erule_tac x=\"a\" in allE)\napply simp\ndone\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/JinjaThreads/MM/MM.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6548947290421275, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.289249323369957}}
{"text": "(* \n   Title: Psi-calculi   \n   Based on the AFP entry by Jesper Bengtson (jebe@itu.dk), 2012\n*)\ntheory Weaken_Transition\n  imports Weakening\nbegin\n\ncontext weak\nbegin\n\ndefinition weakenTransition :: \"'b \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow> 'a frame frame option \\<Rightarrow> 'a action \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow> bool\" (\"_ \\<rhd> _ \\<Longrightarrow>_ @ _ \\<prec> _\" [80, 80, 80, 80, 80] 80)\nwhere\n  \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<pi> @ \\<alpha> \\<prec> P' \\<equiv> (\\<exists>P''' P''. \\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''' \\<and> \\<Psi> \\<rhd> P''' \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> P'' \\<and> \\<Psi> \\<rhd> P'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P') \\<or> (P = P' \\<and> \\<alpha> = \\<tau>)\"\n\nlemma weakenTransitionCases[consumes 1, case_names cBase cStep]:\n  assumes \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<pi> @ \\<alpha> \\<prec> P'\"\n  and \"Prop (\\<tau>) \\<pi> P\"\n  and \"\\<And>P''' P''. \\<lbrakk>\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'''; \\<Psi> \\<rhd> P''' \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> P''; \\<Psi> \\<rhd> P'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\\<rbrakk> \\<Longrightarrow> Prop \\<alpha> \\<pi> P'\"\n\n  shows \"Prop \\<alpha> \\<pi> P'\"\nusing assms\nby(auto simp add: weakenTransition_def)\n\nlemma statImpTauChainDerivative:\n  fixes \\<Psi>   :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n\n  shows \"insert_assertion (extract_frame P) \\<Psi> \\<hookrightarrow>\\<^sub>F insert_assertion (extract_frame P') \\<Psi>\"\nusing assms\nby(induct rule: tau_chain_induct) (auto intro: statImpTauDerivative dest: Frame_stat_imp_trans)\n\nlemma weakenTauChain:\n  fixes \\<Psi>  :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n  and   \\<Psi>' :: 'b\n\n  assumes \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n  shows \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\nusing assms\nproof(induct rule: tau_chain_induct)\n  case(tau_base P)\n  thus ?case by simp\nnext\n  case(tau_step P P' P'')\n  note `\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'`\n  moreover from `\\<Psi> \\<rhd> P' \\<longmapsto>None @ \\<tau> \\<prec> P''` have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P' \\<longmapsto>None @ \\<tau> \\<prec> P''\" by(rule weakenTransition)\n  ultimately show ?case by(auto dest: tau_act_tau_chain)\nqed\n\nend\n\nend\n", "meta": {"author": "IlmariReissumies", "repo": "newpsi", "sha": "201517d55b6ed1632a5bff2a585367278b5bc67b", "save_path": "github-repos/isabelle/IlmariReissumies-newpsi", "path": "github-repos/isabelle/IlmariReissumies-newpsi/newpsi-201517d55b6ed1632a5bff2a585367278b5bc67b/Weaken_Transition.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6548947155710234, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.289249317420134}}
{"text": "(*  Title:      JinjaThreads/MM/MM.thy\n    Author:     Andreas Lochbihler\n*)\n\nheader {* \\chapter{Memory Models} *}\n\ntheory MM\nimports\n  \"../Common/Heap\"\nbegin\n\ntype_synonym addr = nat\ntype_synonym thread_id = addr\n\nabbreviation (input) \n  addr2thread_id :: \"addr \\<Rightarrow> thread_id\"\nwhere \"addr2thread_id \\<equiv> \\<lambda>x. x\"\n\nabbreviation (input)\n  thread_id2addr :: \"thread_id \\<Rightarrow> addr\"\nwhere \"thread_id2addr \\<equiv> \\<lambda>x. x\"\n\ninstantiation nat :: addr begin\ndefinition \"hash_addr \\<equiv> int\"\ndefinition \"monitor_finfun_to_list \\<equiv> (finfun_to_list :: nat \\<Rightarrow>f nat \\<Rightarrow> nat list)\"\ninstance\nby(intro_classes)(simp add: monitor_finfun_to_list_nat_def)\nend\n\ndefinition new_Addr :: \"(addr \\<rightharpoonup> 'b) \\<Rightarrow> addr option\"\nwhere \"new_Addr h \\<equiv> if \\<exists>a. h a = None then Some(LEAST a. h a = None) else None\"\n\nlemma new_Addr_SomeD:\n  \"new_Addr h = Some a \\<Longrightarrow> h a = None\"\nby(auto simp add:new_Addr_def split:if_splits intro: LeastI)\n\nlemma new_Addr_SomeI:\n  \"finite (dom h) \\<Longrightarrow> \\<exists>a. new_Addr h = Some a\"\nby(simp add: new_Addr_def) (metis finite_map_freshness infinite_UNIV_nat)\n\nsubsection {* Code generation *}\n\ndefinition gen_new_Addr :: \"(addr \\<rightharpoonup> 'b) \\<Rightarrow> addr \\<Rightarrow> addr option\"\nwhere \"gen_new_Addr h n \\<equiv> if \\<exists>a. a \\<ge> n \\<and> h a = None then Some(LEAST a. a \\<ge> n \\<and> h a = None) else None\"\n\nlemma new_Addr_code_code [code]:\n  \"new_Addr h = gen_new_Addr h 0\"\nby(simp add: new_Addr_def gen_new_Addr_def)\n\nlemma gen_new_Addr_code [code]:\n  \"gen_new_Addr h n = (if h n = None then Some n else gen_new_Addr h (Suc n))\"\napply(simp add: gen_new_Addr_def)\napply(rule impI)\napply(rule conjI)\n apply safe[1]\n  apply(auto intro: Least_equality)[2]\n apply(rule arg_cong[where f=Least])\n apply(rule ext)\n apply auto[1]\n apply(case_tac \"n = ab\")\n  apply simp\n apply simp\napply clarify\napply(subgoal_tac \"a = n\")\n apply simp\n apply(rule Least_equality)\n apply auto[2]\napply(rule ccontr)\napply(erule_tac x=\"a\" in allE)\napply simp\ndone\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/JinjaThreads/MM/MM.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6723316860482762, "lm_q2_score": 0.43014734858584286, "lm_q1q2_score": 0.28920169212391533}}
{"text": "section {* Refinement calculus *}\n\ntheory utp_refcalc\n  imports utp_designs\nbegin\n\nabbreviation spec_stat :: \"('\\<beta> \\<Longrightarrow> '\\<alpha>) \\<Rightarrow> '\\<alpha> upred \\<Rightarrow> '\\<alpha> upred \\<Rightarrow> '\\<alpha> hrel_des\" where\n\"spec_stat w pre post \\<equiv> (pre \\<turnstile>\\<^sub>n w:[\\<lceil>post\\<rceil>\\<^sub>>])\"\n\nsyntax\n  \"_spec_stat\" :: \"salpha \\<Rightarrow> '\\<alpha> upred \\<Rightarrow> '\\<alpha> upred \\<Rightarrow> '\\<alpha> hrel_des\" (\"_:[_,_]\\<^sub>u\" [70,0,0] 70)\n\ntranslations\n  \"_spec_stat w pre post\" \\<rightleftharpoons> \"CONST spec_stat w pre post\"\n\nlemma rc_strengthen_post:\n  assumes \"`post' \\<Rightarrow> post`\"\n  shows \"w:[pre, post]\\<^sub>u \\<sqsubseteq> w:[pre, post']\\<^sub>u\"\n  using assms by (rel_auto)\n\nlemma rc_weaken_pre:\n  assumes \"`pre \\<Rightarrow> pre'`\"\n  shows \"w:[pre, post]\\<^sub>u \\<sqsubseteq> w:[pre', post]\\<^sub>u\"\n  using assms by (rel_auto)\n\nlemma rc_skip:\n  assumes \"`pre \\<Rightarrow> post`\"\n  shows \"w:[pre, post]\\<^sub>u \\<sqsubseteq> II\\<^sub>D\"\n  using assms by (rel_auto)\n\nlemma rc_seq:\n  assumes \"vwb_lens w\"\n  shows \"w:[pre, post]\\<^sub>u \\<sqsubseteq> w:[pre, mid]\\<^sub>u ;; w:[mid, post]\\<^sub>u\"\n  using assms\n  by (rel_auto, metis vwb_lens.put_eq)\nend", "meta": {"author": "git-vt", "repo": "orca", "sha": "92bda0f9cfe5cc680b9c405fc38f07a960087a36", "save_path": "github-repos/isabelle/git-vt-orca", "path": "github-repos/isabelle/git-vt-orca/orca-92bda0f9cfe5cc680b9c405fc38f07a960087a36/Archive/Programming-Languages-Semantics/WP11-C-semantics/src/IMP-Lenses/theories/utp_refcalc.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.28908008941461566}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory ArraysMemInstance\nimports Arrays CompoundCTypes\nbegin\n\nprimrec\n  array_tag_n :: \"nat \\<Rightarrow> ('a::c_type,'b::finite) array typ_info\"\nwhere\n  atn_base:\n  \"array_tag_n 0 = ((empty_typ_info (typ_name (typ_uinfo_t TYPE('a)) @ ''_array_'' @\n      nat_to_bin_string (CARD('b::finite))))::('a::c_type,'b) array\n          typ_info)\"\n| atn_rec:\n  \"array_tag_n (Suc n) = ((ti_typ_combine TYPE('a::c_type)\n      (\\<lambda>x. index x n) (\\<lambda>x f. update f n x) (replicate n CHR ''1'')\n          (array_tag_n n))::('a,'b::finite) array typ_info)\"\n\ndefinition\n  array_tag :: \"('a::c_type,'b::finite) array itself \\<Rightarrow> ('a,'b) array typ_info\" where\n  \"array_tag t \\<equiv> array_tag_n (CARD('b))\"\n\ninstantiation array :: (c_type,finite) c_type\nbegin\ninstance ..\nend\n\ndefs (overloaded)\n  typ_info_array: \"typ_info_t (w::('a::c_type,'b::finite) array itself) \\<equiv> array_tag w\"\n\nlemma field_names_array_tag_length [rule_format]:\n  \"x \\<in> set (field_names_list (array_tag_n n)) \\<longrightarrow> length x < n\"\napply(induct_tac n)\n apply simp\napply clarsimp\ndone\n\nlemma replicate_mem_field_names_array_tag [simp]:\n  \"replicate n x \\<notin> set (field_names_list (array_tag_n n))\"\napply clarsimp\napply(drule field_names_array_tag_length)\napply simp\ndone\n\nlemma aggregate_array_tag [simp]:\n  \"aggregate (array_tag_n n)\"\napply(case_tac n)\n apply simp+\ndone\n\nlemma wf_desc_array_tag [simp]:\n  \"wf_desc ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info)\"\napply(induct_tac n)\n apply simp+\napply(erule wf_desc_ti_typ_combine)\napply simp\ndone\n\nlemma wf_size_desc_array_tag [simp, rule_format]:\n  \"0 < n \\<longrightarrow> wf_size_desc ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info)\"\napply(induct n)\n apply simp+\napply(case_tac \"n=0\")\n apply simp\napply(rule wf_size_desc_ti_typ_combine)\napply simp\ndone\n\nlemma g_ind_array_tag_udpate [simp]:\n  \"n \\<le> m \\<longrightarrow> n \\<le> CARD('b) \\<longrightarrow>\n      g_ind (lf_set ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info) []) (\\<lambda>x f. update f m x)\"\napply(induct_tac n)\n apply clarsimp+\napply(erule g_ind_ti_typ_combine)\n apply clarsimp+\ndone\n\nlemma fc_array_tag_udpate [simp]:\n  \"n \\<le> m \\<longrightarrow> n \\<le> CARD('b) \\<longrightarrow>\n      fu_commutes (update_ti_t ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info)) (\\<lambda>x f. update f m x)\"\napply(induct_tac n)\n apply clarsimp+\napply(erule fc_ti_typ_combine)\n  apply(clarsimp simp: fg_cons_def)\n apply clarsimp+\ndone\n\nlemma f_ind_array_tag_udpate [simp, rule_format]:\n  \"n \\<le> m \\<longrightarrow> m < CARD('b) \\<longrightarrow>\n      f_ind (\\<lambda>x. index x m) (lf_fd ` lf_set ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info) [])\"\napply(induct_tac n)\n apply clarsimp+\napply(erule f_ind_ti_typ_combine)\n apply clarsimp\napply simp\ndone\n\nlemma fa_fu_g_array_tag_udpate [simp, rule_format]:\n  \"n \\<le> m \\<longrightarrow> m < CARD('b) \\<longrightarrow>\n      fa_ind (lf_fd ` lf_set ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info) []) (\\<lambda>x f. update f m x)\"\napply(induct_tac n)\n apply clarsimp+\napply(erule fa_ind_ti_typ_combine)\napply clarsimp+\ndone\n\nlemma wf_fdp_array_tag [simp, rule_format]:\n  \"n \\<le> CARD('b) \\<longrightarrow>\n      wf_lf (lf_set ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info) [])\"\napply(induct_tac n)\n apply clarsimp+\napply(erule wf_lf_ti_typ_combine)\n      apply simp+\ndone\n\nlemma upd_local_update [simp]:\n  \"upd_local (\\<lambda>x f. update f n x)\"\napply(auto simp: upd_local_def)\napply(subst cart_eq)\napply clarsimp\napply(subst (asm) cart_eq)\napply(drule_tac x=i in spec)\napply clarsimp\napply(case_tac \"i=n\")\n apply simp+\ndone\n\nlemma fu_eq_mask_array_tag [simp, rule_format]:\n  \"n \\<le> CARD('b) \\<longrightarrow> (\\<forall>m. (\\<forall>k v. k < CARD('b) \\<longrightarrow>\n      index ((m v)::('a,'b) array) k = (if n \\<le> k then\n          index (undefined::('a::mem_type,'b::finite) array) k\n          else index v k)) \\<longrightarrow> fu_eq_mask (array_tag_n n) m)\"\napply(induct n)\n apply clarsimp\n apply(rule fu_eq_mask_empty_typ_info)\n apply clarsimp\n apply(subst cart_eq)\n apply simp\napply clarsimp\napply(rule fu_eq_mask_ti_typ_combine)\n     apply(drule_tac x=\"\\<lambda>v. update (m v) n (index undefined n)\" in spec)\n     apply(erule impE)\n      apply clarsimp\n      apply(drule_tac x=k in spec)\n      apply clarsimp\n      apply(case_tac \"k=n\")\n       apply simp\n      apply clarsimp\n     apply(subgoal_tac \"\\<forall>v bs. m (update v n bs) = update (m v) n bs\")\n      apply clarsimp+\n     apply(subst cart_eq)\n     apply clarsimp\n     apply(drule_tac x=i in spec)\n     apply clarsimp\n     apply(case_tac \"i=n\")\n      apply clarsimp+\n     apply(frule_tac x=\"update v n bs\" in spec)\n     apply(drule_tac x=\"v\" in spec)\n     apply clarsimp\n     apply(case_tac \"Suc n \\<le> i\")\n      apply clarsimp+\n    apply(clarsimp simp: fg_cons_def)\n   apply(clarsimp)\n  apply simp\ndone\n\nlemma size_td_array_tag [simp]:\n  \"size_td (((array_tag_n n)::('a,'b::finite) array typ_info)) =\n      n * size_of TYPE('a::c_type)\"\napply(induct_tac n)\n apply simp\napply simp\napply(simp add: size_td_lt_ti_typ_combine size_of_def)\ndone\n\nlemma align_td_array_tag [rule_format]:\n  \"0 < n \\<longrightarrow> align_td ((array_tag_n n)::('a,'b::finite) array typ_info) = (align_td (typ_info_t (TYPE('a::c_type))))\"\napply(induct_tac n)\n apply simp\napply(clarsimp simp: ti_typ_combine_def Let_def)\napply(case_tac \"n = 0\")\n apply(clarsimp simp: align_of_def max_def)+\ndone\n\nlemma align_field_array [simp]:\n  \"align_field ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info)\"\napply(induct_tac n)\n apply simp\napply clarsimp\napply(erule align_field_ti_typ_combine)\napply simp\napply(rule dvd_mult)\napply(subgoal_tac \"align_of TYPE('a) dvd size_of TYPE('a)\")\n apply(simp add: align_of_def)\napply(rule align_size_of)\ndone\n\ninstantiation array :: (mem_type,finite) mem_type_sans_size\nbegin\n\ninstance\napply intro_classes\n     apply(simp_all add: typ_info_array array_tag_def size_of_def\n                         norm_bytes_def)\n\n apply clarsimp\n apply(rule fu_eq_mask)\n  apply(simp add: size_of_def)\n apply(rule fu_eq_mask_array_tag)\n    apply simp+\n\napply(clarsimp simp: align_of_def typ_info_array array_tag_def)\napply(subst align_td_array_tag)\n apply simp\napply(rule dvd_trans)\n apply(subgoal_tac \"align_of TYPE('a) dvd size_of TYPE('a)\")\n  apply(simp only: align_of_def)\n apply(rule align_size_of)\napply(simp add: size_of_def)\ndone\n\nend\n\ndeclare atn_base [simp del]\ndeclare atn_rec [simp del]\n\nlemma size_of_array [simp]:\n  \"size_of TYPE(('a,'b::finite) array) = CARD('b) * size_of TYPE('a::c_type)\"\n  by (simp add: size_of_def typ_info_array array_tag_def)\n\nlemma size_td_array:\n  \"size_td (typ_info_t TYPE(('a,'b::finite) array)) = CARD('b) * size_of TYPE('a::c_type)\"\n  by (simp add: size_of_def typ_info_array array_tag_def)\n\nlemma align_td_array:\n  \"2^align_td (typ_info_t TYPE(('a,'b::finite) array)) = align_of TYPE('a::c_type)\"\napply(simp add: align_of_def typ_info_array array_tag_def)\napply(subst align_td_array_tag)\n apply simp+\ndone\n\n(* Showing arrays are in mem_type requires maximum sizes for objects,\n   and maximum counts for elements *)\nclass oneMB_size = mem_type +\n  assumes oneMB_size_ax: \"size_of TYPE('a::c_type) < 2 ^ 19\"\n\nclass fourthousand_count = finite +\n  assumes fourthousand_count_ax: \"CARD ('a) <= 2 ^ 13\"\n\ninstantiation array :: (oneMB_size, fourthousand_count) mem_type\nbegin\n\ninstance\napply intro_classes\napply simp\napply (subgoal_tac \"addr_card = 2 ^ 13 * 2 ^ 19\")\n  apply (erule ssubst)\n  apply (rule less_le_trans[where y = \"card (UNIV::'b set) * 2 ^ 19\"])\n    apply (rule mult_less_mono2)\n      apply (rule oneMB_size_ax)\n    apply simp\n  apply (rule mult_le_mono1)\n    apply (rule fourthousand_count_ax)\n  apply simp\napply (simp add: addr_card)\ndone\n\nend\n\nclass twoToSix_size = oneMB_size +\n  assumes twoToSix_size_ax: \"size_of TYPE('a::c_type) < 2 ^ 6\"\n\ninstantiation array :: (twoToSix_size, fourthousand_count) oneMB_size\nbegin\n\ninstance\napply intro_classes\napply simp\n  apply (rule order_less_le_trans)\n   apply (rule mult_le_less_imp_less)\n    apply (rule fourthousand_count_ax)\n   apply (rule twoToSix_size_ax)\n  apply simp\n   apply simp\n  apply simp\n  done\n\nend\n\ninstantiation word :: (len8) oneMB_size\nbegin\ninstance\napply intro_classes\napply(simp add: size_of_def)\napply(subgoal_tac \"len_of TYPE('a) \\<le> 128\")\n apply simp\napply(rule len8_width)\ndone\nend\n\ninstantiation word :: (len8) twoToSix_size\nbegin\ninstance\napply intro_classes\napply(simp add: size_of_def)\napply(subgoal_tac \"len_of TYPE('a) \\<le> 128\")\n apply simp\napply(rule len8_width)\ndone\nend\n\ninstantiation ptr :: (c_type) oneMB_size\nbegin\ninstance\napply intro_classes\napply (simp add: size_of_def)\ndone\nend\n\ninstantiation ptr :: (c_type) twoToSix_size\nbegin\ninstance\napply intro_classes\napply (simp add: size_of_def)\ndone\nend\n\nclass lt12 = finite +\n  assumes lt12_ax: \"CARD ('a) < 2 ^ 12\"\nclass lt11 = lt12 +\n  assumes lt11_ax: \"CARD ('a) < 2 ^ 11\"\nclass lt10 = lt11 +\n  assumes lt10_ax: \"CARD ('a) < 2 ^ 10\"\nclass lt9 = lt10 +\n  assumes lt9_ax: \"CARD ('a) < 2 ^ 9\"\nclass lt8 = lt9 +\n  assumes lt8_ax: \"CARD ('a) < 2 ^ 8\"\nclass lt7 = lt8 +\n  assumes lt7_ax: \"CARD ('a) < 2 ^ 7\"\nclass lt6 = lt7 +\n  assumes lt6_ax: \"CARD ('a) < 2 ^ 6\"\nclass lt5 = lt6 +\n  assumes lt5_ax: \"CARD ('a) < 2 ^ 5\"\nclass lt4 = lt5 +\n  assumes lt4_ax: \"CARD ('a) < 2 ^ 4\"\nclass lt3 = lt4 + \n  assumes lt3_ax: \"CARD ('a) < 2 ^ 3\"\nclass lt2 = lt3 +\n  assumes lt2_ax: \"CARD ('a) < 2 ^ 2\"\nclass lt1 = lt2 +\n  assumes lt1_ax: \"CARD ('a) < 2 ^ 1\"\n\ninstantiation bit0 :: (lt12) fourthousand_count\nbegin\ninstance\n  by (intro_classes, insert lt12_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt12) fourthousand_count\nbegin\ninstance\n  by (intro_classes, insert lt12_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt11) lt12\nbegin\ninstance\n  by (intro_classes, insert lt11_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt11) lt12\nbegin\ninstance\n  by (intro_classes, insert lt11_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt10) lt11\nbegin\ninstance\n  by (intro_classes, insert lt10_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt10) lt11\nbegin\ninstance\n  by (intro_classes, insert lt10_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt9) lt10\nbegin\ninstance\n  by (intro_classes, insert lt9_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt9) lt10\nbegin\ninstance\n  by (intro_classes, insert lt9_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt8) lt9\nbegin\ninstance\n  by (intro_classes, insert lt8_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt8) lt9\nbegin\ninstance\n  by (intro_classes, insert lt8_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt7) lt8\nbegin\ninstance\n  by (intro_classes, insert lt7_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt7) lt8\nbegin\ninstance\n  by (intro_classes, insert lt7_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt6) lt7\nbegin\ninstance\n  by (intro_classes, insert lt6_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt6) lt7\nbegin\ninstance\n  by (intro_classes, insert lt6_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt5) lt6\nbegin\ninstance\n  by (intro_classes, insert lt5_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt5) lt6\nbegin\ninstance\n  by (intro_classes, insert lt5_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt4) lt5\nbegin\ninstance\n  by (intro_classes, insert lt4_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt4) lt5\nbegin\ninstance\n  by (intro_classes, insert lt4_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt3) lt4\nbegin\ninstance\n  by (intro_classes, insert lt3_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt3) lt4\nbegin\ninstance\n  by (intro_classes, insert lt3_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt2) lt3\nbegin\ninstance\n  by (intro_classes, insert lt2_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt2) lt3\nbegin\ninstance\n  by (intro_classes, insert lt2_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit0 :: (lt1) lt2\nbegin\ninstance\n  by (intro_classes, insert lt1_ax[where 'a = 'a], simp)\nend\n\ninstantiation bit1 :: (lt1) lt2\nbegin\ninstance\n  by (intro_classes, insert lt1_ax[where 'a = 'a], simp)\nend\n\ninstantiation num1 :: lt1\nbegin\ninstance \n  by (intro_classes, simp_all)\nend\n\n(* don't understand why this also seems to be necessary *)\ninstantiation num1 :: fourthousand_count\nbegin\ninstance\n  by (intro_classes, simp)\nend\n\n(* introduce hackish handling of 8192 type by making a copy of the type\n   under a constructor, and then manually showing that it is an instance of\n   fourthousand_count *)\ndatatype ty8192 = ty8192 \"8192\"\n\nlemma univ8192: \"(UNIV::ty8192 set) = image ty8192 (UNIV::8192 set)\"\napply (simp add: set_eq_iff image_iff)\napply (rule_tac allI)\napply (rule_tac ty8192.induct)\napply simp\ndone\n\ninstance \"ty8192\" :: finite\napply intro_classes\napply (simp add: univ8192)\ndone\n\nlemma card8192[simp]: \"CARD(ty8192) = CARD(8192)\"\napply (simp add: univ8192 card_image inj_on_def)\ndone\n\ninstance \"ty8192\" :: fourthousand_count\nby intro_classes simp\n\n\nend\n", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/c-parser/umm_heap/ArraysMemInstance.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5736783928749127, "lm_q2_score": 0.5039061705290806, "lm_q1q2_score": 0.2890800820688747}}
{"text": "theory Channel_Type_Rep\n  imports Executable_Universe\nbegin\n\ntext \\<open> There follows a class for representing channel types \\<close>\n\nclass pre_uchantyperep =\n  \\<comment> \\<open> A mapping from channel names to types \\<close>\n  fixes uchans :: \"'a itself \\<Rightarrow> (uname \\<Zpfun> utyp)\"\n\n  assumes finite_chans: \"finite (pdom (uchans a))\"\n  and nonempty_chans: \"\\<exists> n. n \\<in> pdom (uchans a)\"\nbegin\n\ndefinition unames :: \"'a itself \\<Rightarrow> uname set\" where\n\"unames a = pdom (uchans a)\"\n\nlemma finite_names: \"finite (unames a)\"\n  by (simp add: local.finite_chans unames_def)\n\nlemma names_nonempty: \"unames a \\<noteq> {}\"\n  using local.nonempty_chans unames_def by auto\n\ntext \\<open> The value carried over the channel \\<close>\n  \nend\n\ntypedef (overloaded) 'c::pre_uchantyperep name = \n  \"{n. n \\<in> unames TYPE('c)}\"\n  by (simp add: nonempty_chans unames_def)\n\n(* The following type should be isomorphic to 'c, but conveys more structure *)\n\ntypedef (overloaded) 'c::pre_uchantyperep event =\n  \"{(n, v). n \\<in> unames TYPE('c) \\<and> utyp_of v = Some ((uchans TYPE('c))(n)\\<^sub>p)}\"\n  morphisms of_event event_of\n  using nonempty_chans unames_def utyp_of_default_uval by blast\n\nsetup_lifting type_definition_event\n\nlift_definition ev_name :: \"'c::pre_uchantyperep event \\<Rightarrow> uname\" is fst .\ndefinition ev_type :: \"'c::pre_uchantyperep event \\<Rightarrow> utyp\"\n  where \"ev_type e = (uchans TYPE('c))(ev_name e)\\<^sub>p\"\nlift_definition ev_val :: \"'c::pre_uchantyperep event \\<Rightarrow> 'a::uvals\" is \"from_uval \\<circ> snd\" .\nlift_definition mk_event :: \"uname \\<Rightarrow> 'a::uvals \\<Rightarrow> 'c::pre_uchantyperep event\"\n  is \"\\<lambda> n v. if (n \\<in> unames TYPE('c) \\<and> (uchans TYPE('c))(n)\\<^sub>p = UTYPE('a))\n             then (n, to_uval v) \n             else (let sn = SOME n. n \\<in> unames TYPE('c) in (sn, default_uval ((uchans TYPE('c))(sn)\\<^sub>p)))\"\n  apply auto\n  apply (metis nonempty_chans old.prod.inject someI unames_def)\n  apply (metis fst_conv snd_conv utyp_of_default_uval)\n  apply (metis nonempty_chans prod.inject someI unames_def)\n  apply (metis fst_conv snd_conv utyp_of_default_uval)\n  done\n\nlemma \n  assumes \"UTYPE('a) = ev_type x\"\n  shows \"mk_event (ev_name x) (ev_val x :: 'a::uvals) = x\"\n  using assms\n  apply (simp add: ev_val_def ev_type_def)\n  apply (transfer)\n  apply auto\n  oops\n\n(*\ntype_synonym 'c chan = unit\n\ndefinition mk_chan :: \"'c name \\<Rightarrow> ('a \\<Longrightarrow>\\<^sub>\\<triangle> 'c) \\<Rightarrow> 'c chan\" where\n\"mk_chan = undefined\"\n*)\n\n(* I want to achieve a type something like \"forall 'a\\<in>unames. (('a, 'c) name, 'a \\<Longrightarrow>\\<^sub>\\<triangle> 'c) *)\n\n\nclass uchantyperep = pre_uchantyperep +\n  fixes uchan_mk :: \"'a event \\<Rightarrow> 'a\"\n  and uchan_dest :: \"'a \\<Rightarrow> 'a event\"\n  assumes \"uchan_dest (uchan_mk x) = x\"\n\nchantype chan = \n  Input :: unit\n  Output :: integer\n\ninstantiation chan :: pre_uchantyperep\nbegin\n\ndefinition uchans_chan :: \"chan itself \\<Rightarrow> String.literal \\<Zpfun> utyp\"\n  where \"uchans_chan x = {STR ''Input'' \\<mapsto> UnitT, STR ''Output'' \\<mapsto> IntT}\"\n\ninstance\n  by (intro_classes, auto simp add: uchans_chan_def)\n\nend\n\n(*\ninstantiation chan :: uchantyperep\nbegin\n\ndefinition uchan_mk_chan :: \"chan event \\<Rightarrow> chan\"\n  where \"uchan_mk_chan e = (if (ev_name e = STR ''Input'') then Input_C (ev_val e)\n                            else Output_C (ev_val e))\"\n\nfun uchan_dest_chan :: \"chan \\<Rightarrow> chan event\" where\n\"uchan_dest (Input_C v) = mk_event (STR ''Input'', to_uval v)\" |\n\"uchan_dest (Output_C v) = mk_event (STR ''Output'', to_uval v)\" \n\ninstance\n  apply (intro_classes)\n  apply (auto simp add: uchan_mk_chan_def)\n*)\n\ndatatype ('e, 'b) chf =\n  ChanF (chf_chn: \"(uname \\<times> uval \\<times> uval \\<Longrightarrow>\\<^sub>\\<triangle> 'e)\") \\<comment> \\<open> The channel, including a name, output value, and input value \\<close>\n        (chf_out: \"uname \\<times> uval\") \\<comment> \\<open> The value output by the process (displayed in the animator) \\<close>\n        (chf_typ: \"utyp\") \\<comment> \\<open> The type of data requested by the animator \\<close>\n        (chf_cont: \"uval \\<Rightarrow> 'b\") \\<comment> \\<open> The continuation for each kind of value received \\<close>\n\ndefinition pfun_of_chfun :: \n  \"('e, 'b) chf \\<Rightarrow> 'e \\<Zpfun> 'b\" where\n\"pfun_of_chfun chf = \n    (\\<lambda> e\\<in>{build\\<^bsub>chf_chn chf\\<^esub> (fst (chf_out chf), snd (chf_out chf), v) | v. v \\<in> uvals (chf_typ chf)} \n    \\<bullet> (chf_cont chf) (snd (snd (the (match\\<^bsub>chf_chn chf\\<^esub> e)))))\"\n\ndefinition\n  \"map_chfun f chf = ChanF (chf_chn chf) (chf_out chf) (chf_typ chf) (f \\<circ> chf_cont chf)\"\n\nlemma map_pfun_pfun_of_chfun: \n  \"map_pfun f (pfun_of_chfun chf) = pfun_of_chfun (map_chfun f chf)\"\n  by (simp add: map_chfun_def pfun_of_chfun_def pfun_eq_iff)\n\nlemma \"pfun_app (pfun_of_chfun chf) e = undefined\"\n  apply (simp add: pfun_of_chfun_def)\n  apply (subst pabs_apply)\n    apply simp\n  oops\n\ndefinition pfun_of_chfuns ::\n  \"('e, 'b) chf list \\<Rightarrow> 'e \\<Zpfun> 'b\" where\n\"pfun_of_chfuns chfs = foldr (\\<lambda> c f. pfun_of_chfun c \\<oplus> f) chfs {}\\<^sub>p\"\n\nlemma map_pfun_pfun_of_chfuns [code]:\n  \"map_pfun f (pfun_of_chfuns chfs) = pfun_of_chfuns (map (map_chfun f) chfs)\"\n  by (induct chfs, simp_all add: pfun_of_chfuns_def map_pfun_pfun_of_chfun)\n\nend", "meta": {"author": "isabelle-utp", "repo": "interaction-trees", "sha": "90510d119364f534d2ab61daf2f274060f0a040e", "save_path": "github-repos/isabelle/isabelle-utp-interaction-trees", "path": "github-repos/isabelle/isabelle-utp-interaction-trees/interaction-trees-90510d119364f534d2ab61daf2f274060f0a040e/simulation/Channel_Type_Rep.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6113819591324418, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.28899014998573397}}
{"text": "section \\<open>Machine\\<close>\ntext \\<open>\n  This theory describes the state of an abstract machine on which binary and assembly programs\n  can be executed.\n\\<close>\n\ntheory Machine\n  imports Main \"HOL-Library.Word\" \"HOL-Library.Stream\"\nbegin\n\nsubsection \\<open>Primitive Values\\<close>\ntext \\<open>Bits and bytes on which the abstract machine operates\\<close>\n\ntype_synonym byte  = \"8 word\"\ntype_synonym bytes = \"byte list\"\n\ntype_synonym addr = \"nat\"\n\nsubsection \\<open>Machine State\\<close>\n\nrecord state =\n  state_rip :: \"addr\"\n  state_mem :: \"addr \\<Rightarrow> byte\"\n\ntype_synonym trace = \"state stream\"\n\nsubsection \\<open>ISA\\<close>\n\ntype_synonym instr = string\n\nlocale isa =\n  fixes isa_instructions :: \"instr set\"\n    and isa_encodings    :: \"bytes set\"\n    and isa_encode       :: \"instr \\<rightharpoonup> bytes\"\n    and isa_decode       :: \"bytes \\<rightharpoonup> instr\"\n    and isa_step_instr   :: \"(instr \\<times> state \\<times> state) set\"\n  assumes isa_encode_valid: \"\\<forall> i \\<in> isa_instructions. \\<exists> bs \\<in> isa_encodings. isa_encode i = Some bs \\<and> isa_decode bs = Some i\"\n      and isa_decode_valid: \"\\<forall> bs \\<in> isa_encodings. \\<exists> i \\<in> isa_instructions. isa_encode i = Some bs \\<and> isa_decode bs = Some i\" \n\ncontext isa\nbegin\n\ndefinition isa_step_bytes :: \"(bytes \\<times> state \\<times> state) set\" where\n  \"isa_step_bytes = { (bs, \\<sigma>\\<^sub>1, \\<sigma>\\<^sub>2). \\<exists> i. Some i = isa_decode bs \\<and> (i, \\<sigma>\\<^sub>1, \\<sigma>\\<^sub>2) \\<in> isa_step_instr }\"\n\nlemma isa_encode_preserves_instr_semantics:\n  assumes \"Some bs = isa_encode i\"\n      and \"i \\<in> isa_instructions\"\n      and \"(i, \\<sigma>\\<^sub>1, \\<sigma>\\<^sub>2)  \\<in> isa_step_instr\"\n    shows \"(bs, \\<sigma>\\<^sub>1, \\<sigma>\\<^sub>2) \\<in> isa_step_bytes\"\n  using assms(1) assms(2) assms(3) isa_encode_valid isa_step_bytes_def by auto\n\nlemma isa_decode_preserves_instr_semantics:\n  assumes \"Some i = isa_decode bs\"\n      and \"(i, \\<sigma>\\<^sub>1, \\<sigma>\\<^sub>2)  \\<in> isa_step_instr\"\n    shows \"(bs, \\<sigma>\\<^sub>1, \\<sigma>\\<^sub>2) \\<in> isa_step_bytes\"\n  using assms(1) assms(2) isa_step_bytes_def by auto\n\nlemma isa_encode_preserves_byte_semantics:\n  assumes \"Some bs = isa_encode i\"\n      and \"i \\<in> isa_instructions\"\n      and \"(bs, \\<sigma>\\<^sub>1, \\<sigma>\\<^sub>2) \\<in> isa_step_bytes\"\n    shows \"(i, \\<sigma>\\<^sub>1, \\<sigma>\\<^sub>2)  \\<in> isa_step_instr\"\n  using assms(1) assms(2) assms(3) isa_encode_valid isa_step_bytes_def by auto\n\nlemma isa_decode_preserves_byte_semantics:\n  assumes \"Some i = isa_decode bs\"\n      and \"(bs, \\<sigma>\\<^sub>1, \\<sigma>\\<^sub>2) \\<in> isa_step_bytes\"\n    shows \"(i, \\<sigma>\\<^sub>1, \\<sigma>\\<^sub>2)  \\<in> isa_step_instr\"\n  by (smt (verit) assms(1) assms(2) curryI curry_case_prod isa_step_bytes_def mem_Collect_eq option.inject)\n\nend\n\nend", "meta": {"author": "proof-by-sledgehammer", "repo": "disassembly-and-decidability", "sha": "d57c82b789859dccfea06b4bc8c660d759b3a866", "save_path": "github-repos/isabelle/proof-by-sledgehammer-disassembly-and-decidability", "path": "github-repos/isabelle/proof-by-sledgehammer-disassembly-and-decidability/disassembly-and-decidability-d57c82b789859dccfea06b4bc8c660d759b3a866/Machine.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.596433160611502, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.28890034460258746}}
{"text": "theory SINVAR_DomainHierarchyNG_impl\nimports SINVAR_DomainHierarchyNG \"../TopoS_Interface_impl\"\nbegin\n\n\nsubsubsection {* SecurityInvariant DomainHierarchy List Implementation *}\n\ncode_identifier code_module SINVAR_DomainHierarchyNG_impl => (Scala) SINVAR_DomainHierarchyNG\n\nfun sinvar :: \"'v list_graph \\<Rightarrow> ('v \\<Rightarrow> domainNameTrust) \\<Rightarrow> bool\" where\n  \"sinvar G nP = (\\<forall> (s, r) \\<in> set (edgesL G). (nP r) \\<sqsubseteq>\\<^sub>t\\<^sub>r\\<^sub>u\\<^sub>s\\<^sub>t (nP s))\"\n\n\nfun verify_globals :: \"'v list_graph \\<Rightarrow> ('v \\<Rightarrow> domainNameTrust) \\<Rightarrow> domainTree \\<Rightarrow> bool\" where\n  \"verify_globals G nP tree = (\\<forall> v \\<in> set (nodesL G). \n    case (nP v) of Unassigned \\<Rightarrow> True | DN (level, trust) \\<Rightarrow> valid_hierarchy_pos tree level\n   )\"\n\n\n\n\ndefinition DomainHierarchyNG_offending_list:: \"'v list_graph \\<Rightarrow> ('v \\<Rightarrow> domainNameTrust) \\<Rightarrow> ('v \\<times> 'v) list list\" where\n  \"DomainHierarchyNG_offending_list G nP = (if sinvar G nP then\n    []\n   else \n    [ [e \\<leftarrow> edgesL G. case e of (s,r) \\<Rightarrow> \\<not> (nP r) \\<sqsubseteq>\\<^sub>t\\<^sub>r\\<^sub>u\\<^sub>s\\<^sub>t (nP s) ] ])\"\n\n\n\nlemma \"DomainHierarchyNG.node_props P = \n  (\\<lambda>i. case node_properties P i of None \\<Rightarrow> SINVAR_DomainHierarchyNG.default_node_properties | Some property \\<Rightarrow> property)\"\nby(fact SecurityInvariant.node_props.simps[OF TopoS_DomainHierarchyNG, of \"P\"])\n\ndefinition \"NetModel_node_props P = (\\<lambda> i. (case (node_properties P) i of Some property \\<Rightarrow> property | None \\<Rightarrow> SINVAR_DomainHierarchyNG.default_node_properties))\"\n(*\n\n(*TODO does this work?*)\nlemma[code_unfold]: \"DomainHierarchyNG.node_props P = NetModel_node_props P\"\nby(simp add: NetModel_node_props_def)\n\ndefinition \"DomainHierarchyNG_eval G P = (valid_list_graph G \\<and> \n  verify_globals G (SecurityInvariant.node_props SINVAR_DomainHierarchyNG.default_node_properties P) (model_global_properties P) \\<and> \n  sinvar G (SecurityInvariant.node_props SINVAR_DomainHierarchyNG.default_node_properties P))\"\n\n\ninterpretation DomainHierarchyNG_impl:TopoS_List_Impl \n  where default_node_properties=SINVAR_DomainHierarchyNG.default_node_properties\n  and sinvar_spec=SINVAR_DomainHierarchyNG.sinvar\n  and sinvar_impl=sinvar\n  and verify_globals_spec=SINVAR_DomainHierarchyNG.verify_globals\n  and verify_globals_impl=verify_globals\n  and receiver_violation=SINVAR_DomainHierarchyNG.receiver_violation\n  and offending_flows_impl=DomainHierarchyNG_offending_list\n  and node_props_impl=NetModel_node_props\n  and eval_impl=DomainHierarchyNG_eval\n apply(unfold TopoS_List_Impl_def)\n apply(rule conjI)\n  apply(simp add: TopoS_DomainHierarchyNG list_graph_to_graph_def)\n apply(rule conjI)\n  apply(simp add: list_graph_to_graph_def DomainHierarchyNG_offending_set DomainHierarchyNG_offending_set_def DomainHierarchyNG_offending_list_def)\n apply(rule conjI)\n  apply(simp only: NetModel_node_props_def)\n  apply(metis DomainHierarchyNG.node_props.simps DomainHierarchyNG.node_props_eq_node_props_formaldef)\n apply(simp only: DomainHierarchyNG_eval_def)\n apply(intro allI)\n apply(rule TopoS_eval_impl_proofrule[OF TopoS_DomainHierarchyNG])\n apply(simp_all add: list_graph_to_graph_def)\ndone\n\n\nsubsubsection {* DomainHierarchyNG packing *}\n  definition SINVAR_LIB_DomainHierarchyNG :: \"('v::vertex, domainNameTrust, domainTree) TopoS_packed\" where\n    \"SINVAR_LIB_DomainHierarchyNG \\<equiv> \n    \\<lparr> nm_name = ''DomainHierarchyNG'', \n      nm_receiver_violation = SINVAR_DomainHierarchyNG.receiver_violation,\n      nm_default = SINVAR_DomainHierarchyNG.default_node_properties, \n      nm_sinvar = sinvar,\n      nm_verify_globals = verify_globals,\n      nm_offending_flows = DomainHierarchyNG_offending_list, \n      nm_node_props = NetModel_node_props,\n      nm_eval = DomainHierarchyNG_eval\n      \\<rparr>\"\n  interpretation SINVAR_LIB_DomainHierarchyNG_interpretation: TopoS_modelLibrary SINVAR_LIB_DomainHierarchyNG \n      SINVAR_DomainHierarchyNG.sinvar SINVAR_DomainHierarchyNG.verify_globals\n    apply(unfold TopoS_modelLibrary_def SINVAR_LIB_DomainHierarchyNG_def)\n    apply(rule conjI)\n     apply(simp)\n    apply(simp)\n    by(unfold_locales)\n\n\n\n\n\n\ntext {*Examples:*}\ndefinition example_TUM_net :: \"vString list_graph\" where\n  \"example_TUM_net \\<equiv> \\<lparr> nodesL=[TopoS_Vertices.V ''Gateway'', TopoS_Vertices.V ''LowerSVR'', TopoS_Vertices.V ''UpperSRV''], \n        edgesL=[\n          (TopoS_Vertices.V ''Gateway'',TopoS_Vertices.V ''LowerSVR''), (TopoS_Vertices.V ''Gateway'',TopoS_Vertices.V ''UpperSRV''), \n          (TopoS_Vertices.V ''LowerSVR'', TopoS_Vertices.V ''Gateway''),\n          (TopoS_Vertices.V ''UpperSRV'', TopoS_Vertices.V ''Gateway'')\n        ] \\<rparr>\"\nvalue \"valid_list_graph example_TUM_net\"\n\ndefinition example_TUM_config :: \"vString \\<Rightarrow> domainNameTrust\" where\n  \"example_TUM_config \\<equiv> ((\\<lambda> e. default_node_properties)\n        (TopoS_Vertices.V ''Gateway'':= DN (''ACD''--''AISD''--Leaf, 1),\n         TopoS_Vertices.V ''LowerSVR'':= DN (''ACD''--''AISD''--Leaf, 0),\n         TopoS_Vertices.V ''UpperSRV'':= DN (''ACD''--Leaf, 0)\n       ))\"\n\ndefinition example_TUM_hierarchy :: \"domainTree\" where\n\"example_TUM_hierarchy \\<equiv> (Department ''ACD'' [\n           Department ''AISD'' []\n       ])\"\n\nvalue \"verify_globals example_TUM_net example_TUM_config example_TUM_hierarchy\"\nvalue \"sinvar     example_TUM_net example_TUM_config\"\n\ndefinition example_TUM_net_invalid where\n\"example_TUM_net_invalid \\<equiv> example_TUM_net\\<lparr>edgesL :=  \n    (TopoS_Vertices.V ''LowerSRV'', TopoS_Vertices.V ''UpperSRV'')#(edgesL example_TUM_net)\\<rparr>\"\n\nvalue \"verify_globals example_TUM_net_invalid example_TUM_config example_TUM_hierarchy\"\nvalue \"sinvar     example_TUM_net_invalid example_TUM_config\"\nvalue \"DomainHierarchyNG_offending_list example_TUM_net_invalid example_TUM_config\"\n\n\nhide_const (open) NetModel_node_props\n\nhide_const (open) sinvar verify_globals \n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Network_Security_Policy_Verification/Security_Invariants/SINVAR_DomainHierarchyNG_impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7025300449389326, "lm_q2_score": 0.411110869232168, "lm_q1q2_score": 0.2888177374365586}}
{"text": "(* @TAG(OTHER_LGPL) *)\n\n(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      StateSpace.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection {* State Space Template *}\ntheory StateSpace imports Hoare\nbegin\n\nrecord 'g state = \"globals\"::'g\n\ndefinition\n  upd_globals:: \"('g \\<Rightarrow> 'g) \\<Rightarrow> ('g,'z) state_scheme \\<Rightarrow> ('g,'z) state_scheme\"\nwhere\n  \"upd_globals upd s = s\\<lparr>globals := upd (globals s)\\<rparr>\" \n\nrecord ('g, 'n, 'val) stateSP = \"'g state\" +\n  locals :: \"'n \\<Rightarrow> 'val\"\n\nlemma upd_globals_conv: \"upd_globals f = (\\<lambda>s. s\\<lparr>globals := f (globals s)\\<rparr>)\"\n  by (rule ext) (simp add: upd_globals_def)\n\nend", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/c-parser/Simpl/StateSpace.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953651858117, "lm_q2_score": 0.5, "lm_q1q2_score": 0.28874768259290584}}
{"text": "theory ref_crdt\n  imports Main\n   \"sorted_list\"\n   fmap_functions\nsystem_model\nstandard_crdts\n    \"~~/src/HOL/Library/Finite_Map\"\n    \"~~/src/HOL/Library/Open_State_Syntax\"\n    \"~~/src/HOL/Library/Code_Target_Numeral\"\nbegin\n\n\n\ndatatype operation = \n    init ref inref\n  | assign ref ref\n  | deref ref\n  | may_delete inref \"ref list\"\n  | reset_inref inref\n  | reset_ref ref\n (* TODO resolve *)\n\ndatatype operation_effector = \n    effector_inref_inuse_enable inref\n  | effector_inref_rev_refs_add inref ref uid\n  | effector_inref_rev_refs_rem inref ref uid\n  | effector_ref_dest_keys_assign ref \"inref option\" uid \"uid set\"\n\ndatatype operation_result =\n    deref_result \"antidoteKey option\"\n  | no_result\n  | may_delete_result bool\n\n\nrecord ref_state =\n  object_key :: \"antidoteKey\"\n  dest_keys :: \"inref option mv_register_state\"\n\nrecord inref_state =\n  inref_object_key :: \"antidoteKey\"\n  rev_refs :: \"(ref \\<times> uid) two_phase_set_state\"\n  inUse :: bool\n\nrecord state =\n  state_refs :: \"(ref, ref_state) fmap\"\n  state_inrefs :: \"(inref, inref_state) fmap\"\n\n\ndefinition initialState :: state where \n\"initialState \\<equiv> \\<lparr>\n  state_refs = fmempty,\n  state_inrefs = fmempty\n \\<rparr>\"                                              \n\ntype_synonym generator_function = \"(operation \\<Rightarrow> uid \\<Rightarrow> state \\<Rightarrow> operation_result \\<times> (operation_effector list))\"\ntype_synonym effector_function = \"(operation_effector \\<Rightarrow> state \\<Rightarrow> state)\"\ntype_synonym execution' = \"(operation, operation_result, operation_effector, state) execution\"\ntype_synonym eventInfo' = \"(operation, operation_result, operation_effector, state) eventInfo\"\n\ndefinition return :: \"'a \\<Rightarrow> operation_effector list \\<Rightarrow> ('a \\<times> operation_effector list)\" where\n\"return r l = (r,l)\"\n\ndefinition skip :: \"operation_effector list \\<Rightarrow> operation_effector list\" where\n\"skip \\<equiv> id\"\n\ndefinition forEach :: \"'a list \\<Rightarrow> ('a \\<Rightarrow> operation_effector list \\<Rightarrow> operation_effector list) \\<Rightarrow>operation_effector list \\<Rightarrow> operation_effector list\" where\n\"forEach list f effs \\<equiv> foldl (\\<lambda>es x. f x es) effs list\"\n\ntext {* forEach loop with state:  *}\n\ndefinition forEachS :: \"'a list \\<Rightarrow> 'b \\<Rightarrow> ('a \\<Rightarrow> 'b \\<Rightarrow> operation_effector list \\<Rightarrow> ('b \\<times> operation_effector list)) \\<Rightarrow>operation_effector list \\<Rightarrow> operation_effector list\" where\n\"forEachS list s f effs \\<equiv> foldl (\\<lambda>(s,es) x. f x s es) (s,effs) list |> snd\"\n\ndefinition set_forEach :: \"('a::linorder) set \\<Rightarrow> ('a \\<Rightarrow> operation_effector list \\<Rightarrow> operation_effector list) \\<Rightarrow>operation_effector list \\<Rightarrow> operation_effector list\" where\n\"set_forEach S \\<equiv> forEach (sorted_list_of_set2 S)\"\n\ndefinition set_forEachS :: \"('a::linorder) set \\<Rightarrow> 'b \\<Rightarrow> ('a \\<Rightarrow> 'b \\<Rightarrow> operation_effector list \\<Rightarrow> ('b \\<times> operation_effector list)) \\<Rightarrow>operation_effector list \\<Rightarrow> operation_effector list\" where\n\"set_forEachS S \\<equiv> forEachS (sorted_list_of_set2 S)\"\n\ndefinition inref_inuse_enable :: \"inref \\<Rightarrow> operation_effector list \\<Rightarrow> operation_effector list\" where \n\"inref_inuse_enable inref list = list@[effector_inref_inuse_enable inref]\"\n\ndefinition inref_rev_refs_add :: \"inref \\<Rightarrow> ref \\<Rightarrow> uid \\<Rightarrow> operation_effector list \\<Rightarrow> operation_effector list\" where \n\"inref_rev_refs_add inref elem uid list = list@[effector_inref_rev_refs_add inref elem uid]\"\n\ndefinition inref_rev_refs_remove :: \"inref \\<Rightarrow> ref \\<Rightarrow> uid \\<Rightarrow> operation_effector list \\<Rightarrow> operation_effector list\" where \n\"inref_rev_refs_remove inref elem uid list = list@[effector_inref_rev_refs_rem inref elem uid]\"\n\ndefinition ref_state :: \"state \\<Rightarrow> ref \\<Rightarrow> ref_state\" where\n\"ref_state state ref \\<equiv> case  (state_refs state).[ref] of \n    Some s \\<Rightarrow> s\n  | None \\<Rightarrow> \\<lparr> object_key = D_antidoteKey (ref_number ref),  dest_keys = {}\\<rparr>\"\n\ndefinition ref_get_object_key :: \"state \\<Rightarrow> ref \\<Rightarrow> antidoteKey\" where\n\"ref_get_object_key state ref \\<equiv> object_key (ref_state state ref)\" \n\ndefinition inref_state :: \"state \\<Rightarrow> inref \\<Rightarrow> inref_state\" where\n\"inref_state state inref \\<equiv> case  (state_inrefs state).[inref] of \n    Some s \\<Rightarrow> s\n  | None \\<Rightarrow> \\<lparr> inref_object_key = D_antidoteKey (inref_number inref), rev_refs = ({},{}), inUse = False\\<rparr>\"\n\ndefinition inref_get_object_key :: \"state \\<Rightarrow> inref \\<Rightarrow> antidoteKey\" where\n\"inref_get_object_key state ref \\<equiv> inref_object_key (inref_state state ref)\" \n\ndefinition ref_dest_keys_assign :: \"ref \\<Rightarrow> inref option \\<Rightarrow> uid \\<Rightarrow> state \\<Rightarrow> operation_effector list \\<Rightarrow> operation_effector list\" where \n\"ref_dest_keys_assign ref key uid state list \\<equiv> list@[effector_ref_dest_keys_assign ref key uid (snd` dest_keys (ref_state state ref))]\"\n\n\n\ndefinition s_update_inref :: \"inref \\<Rightarrow> (inref_state \\<Rightarrow> inref_state) \\<Rightarrow> state \\<Rightarrow> state\" where\n\"s_update_inref inref f S \\<equiv> S\\<lparr>state_inrefs := fmupd inref (f (inref_state S inref)) (state_inrefs S)\\<rparr>\"\n\n\ndefinition s_update_ref :: \"ref \\<Rightarrow> (ref_state \\<Rightarrow> ref_state) \\<Rightarrow> state \\<Rightarrow> state\" where\n\"s_update_ref ref f S \\<equiv> S\\<lparr>state_refs := fmupd ref (f (ref_state S ref)) (state_refs S)\\<rparr>\"\n\n\ndefinition may_delete_check :: \"state \\<Rightarrow> inref \\<Rightarrow> ref set \\<Rightarrow> bool\" where\n\"may_delete_check state inref last_refs \\<equiv> \n   (*let last_keypairs :: (ref \\<times> uid) set = \\<Union> ((\\<lambda>r. dest_keys (ref_state state r)) ` last_refs) in *)\n   (fst ` two_phase_set_get (rev_refs (inref_state state inref))) = last_refs\"\n\nsubsection {* Implementation *}\n\ntext {* We now present the implementation of the reference CRDT: *}\n\ndefinition precondition_impl :: \"operation \\<rightharpoonup> state \\<Rightarrow> bool\" where\n\"precondition_impl opr \\<equiv> case opr of \n    init ref inref \\<Rightarrow> Some (\\<lambda>state. \\<not> inUse (inref_state state inref))\n  | assign x y \\<Rightarrow> None\n  | deref ref \\<Rightarrow> None\n  | may_delete inref remaining \\<Rightarrow> Some (\\<lambda>s. True)\n  | reset_inref inref \\<Rightarrow> Some (\\<lambda>state. may_delete_check state inref {})\n  | reset_ref ref \\<Rightarrow> None\n\"\n\ndefinition localPrecondition_impl :: \"operation \\<Rightarrow> state \\<Rightarrow> bool\" where\n\"localPrecondition_impl opr S \\<equiv> case opr of \n    init ref inref \\<Rightarrow> True\n  | assign x y \\<Rightarrow> \n      mv_reg_count (dest_keys (ref_state S y)) = 1\n    \\<and> mv_reg_get1' (dest_keys (ref_state S y)) \\<noteq> None \n  | deref ref \\<Rightarrow> \n      mv_reg_count (dest_keys (ref_state S ref)) = 1\n    \\<and> mv_reg_get1' (dest_keys (ref_state S ref)) \\<noteq> None\n  | may_delete inref remaining \\<Rightarrow> True\n  | reset_inref inref \\<Rightarrow> True\n  | reset_ref ref \\<Rightarrow> True\n\"\n\nfind_consts \"'a set \\<Rightarrow> 'a\"\n\n\ndefinition effector_impl :: \"effector_function\" where\n\"effector_impl eff S \\<equiv> case eff of\n    effector_inref_inuse_enable inref \\<Rightarrow> \n      s_update_inref inref (\\<lambda>s. s\\<lparr> inUse := True\\<rparr>) S\n  | effector_inref_rev_refs_add inref antidoteKey uid \\<Rightarrow> \n      s_update_inref inref (\\<lambda>s. s\\<lparr>\n                rev_refs := two_phase_set_add (rev_refs s) (antidoteKey, uid ) \\<rparr>) S\n  | effector_inref_rev_refs_rem inref antidoteKey uid \\<Rightarrow> \n      s_update_inref inref (\\<lambda>s. s\\<lparr>\n                rev_refs := two_phase_set_remove (rev_refs s) (antidoteKey, uid ) \\<rparr>) S\n  | effector_ref_dest_keys_assign ref antidoteKey uid oldUids \\<Rightarrow> \n      s_update_ref ref (\\<lambda>s. s\\<lparr>dest_keys := insert (antidoteKey,uid) (Set.filter (\\<lambda>(x,u). u\\<noteq>uid \\<and> u\\<notin>oldUids) (dest_keys s)) \\<rparr>) S\n\"\n\n(** broken version \ndefinition ref_reset_targets :: \"ref \\<Rightarrow> inref option \\<Rightarrow> uid \\<Rightarrow> state \\<Rightarrow> operation_effector list \\<Rightarrow> operation_effector list\" where \n\"ref_reset_targets ref ignoredInref uid state  \\<equiv> exec {\n        let (outkeys :: (inref option\\<times>uid) set) = (dest_keys (ref_state state ref));\n        set_forEachS outkeys True (\\<lambda>(target,uid) first_time. \n          case target of \n              None \\<Rightarrow> return first_time\n            | Some target' => exec {\n                  (if \\<not> (target = ignoredInref \\<and> first_time) then exec {\n                    inref_rev_refs_remove target' ref uid;\n                    return first_time\n                  } else if target = ignoredInref then exec {\n                    return False\n                  } else exec {\n                    return first_time\n                  })\n              })\n      }\"\n**)\n\ndefinition ref_reset_targets :: \"ref \\<Rightarrow> uid \\<Rightarrow> state \\<Rightarrow> operation_effector list \\<Rightarrow> operation_effector list\" where \n\"ref_reset_targets ref uid state  \\<equiv> exec {\n        let (outkeys :: (inref option\\<times>uid) set) = (dest_keys (ref_state state ref));\n        set_forEach outkeys (\\<lambda>(target,uid). \n          case target of \n              None \\<Rightarrow> skip\n            | Some target' => inref_rev_refs_remove target' ref uid\n            )\n      }\"\n\ndefinition ref_reset :: \"ref \\<Rightarrow> inref option \\<Rightarrow> uid \\<Rightarrow> state \\<Rightarrow> operation_effector list \\<Rightarrow> operation_effector list\" where \n\"ref_reset ref ignoredInref uid state  \\<equiv> exec {\n        ref_dest_keys_assign ref None uid state;\n        ref_reset_targets ref uid state\n      }\"\n\ndefinition outref_update :: \"ref \\<Rightarrow> inref option \\<Rightarrow> state \\<Rightarrow> uid \\<Rightarrow> operation_effector list \\<Rightarrow> operation_effector list\" where\n\"outref_update ref inref state uid \\<equiv> exec {\n  (* first insert into new target: *)\n  (case inref of\n     None \\<Rightarrow> skip\n   | Some inref \\<Rightarrow> inref_rev_refs_add inref ref uid);\n  (* then: assign source *)\n  ref_dest_keys_assign ref inref uid state;\n  (* then reset targets: remove from all old targets *)\n  ref_reset_targets ref uid state\n}\"\n\ndefinition generator_impl :: generator_function where\n\"generator_impl opr uid state \\<equiv> [] |> (case opr of \n    init ref inref \\<Rightarrow> exec {\n        inref_inuse_enable inref;\n        outref_update ref (Some inref) state uid;\n        return no_result\n      }\n  | assign outTo outVal \\<Rightarrow> exec {\n        let new_key = mv_reg_get1' (dest_keys (ref_state state outVal));\n        outref_update outTo new_key state uid;\n        return no_result\n      }\n  | deref ref \\<Rightarrow> exec {\n        let inref = mv_reg_get1' (dest_keys (ref_state state ref));\n        let key = (map_option (inref_get_object_key state) inref);\n        return (deref_result key)\n      }\n  | may_delete inref last_refs \\<Rightarrow> exec {\n        return (may_delete_result (may_delete_check state inref (set last_refs)))\n      }\n  | reset_inref inref \\<Rightarrow> exec {\n        return no_result\n      }\n  | reset_ref ref \\<Rightarrow> exec {\n        outref_update ref None state uid;\n        return no_result\n      }\n)\n\"\n\n\n\ndefinition \n\"wellFormed_impl execution \\<equiv> wellFormed execution initialState generator_impl effector_impl localPrecondition_impl precondition_impl\"\n\nfind_consts \"('a \\<Rightarrow> bool) \\<Rightarrow> 'a list \\<Rightarrow> 'a option\"\n\nfun find_smaller :: \"'a rel \\<Rightarrow> 'a \\<Rightarrow> 'a list \\<Rightarrow> 'a option\" where\n  \"find_smaller R x [] = None\"\n| \"find_smaller R x (y#ys) = None\"\n\n\nlemma find_length[simp]: \"find P xs = Some x \\<Longrightarrow> length (remove1 x xs) < length xs\"\n  by (induct xs, auto split: if_splits)\n\nlemma find_length2[simp]: \"find P xs = Some x \\<Longrightarrow> Suc (length (remove1 x xs)) = length xs \"\n  by (induct xs, auto split: if_splits)\n\n\ndefinition findMinimal :: \"'a rel \\<Rightarrow> 'a list \\<Rightarrow> 'a\"   where \n\"findMinimal R xs \\<equiv> case find (\\<lambda>y. \\<forall>x\\<in>set xs. x=y \\<or> (x,y)\\<notin>R) xs of None \\<Rightarrow> hd xs | Some x \\<Rightarrow> x\"\n\n\nlemma findMinimalIn: \"xs\\<noteq>[] \\<Longrightarrow>  findMinimal R xs \\<in> set xs\"\n  apply (auto simp add: findMinimal_def split: option.splits)\n  by (metis (no_types, lifting) find_Some_iff in_set_conv_nth)\n\n\nlemma findMinimal_termination[simp]: \"xs\\<noteq>[] \\<Longrightarrow> length (remove1 (findMinimal R xs) xs) < length xs\"\n  by (simp add: findMinimalIn length_remove1)\n\nlemma findMinimal_termination2[simp]: \"findMinimal R (v # va) \\<noteq> v \\<Longrightarrow> length (remove1 (findMinimal R (v # va)) va) < length va\"\n  by (metis One_nat_def Suc_pred findMinimalIn length_pos_if_in_set length_remove1 lessI list.discI set_ConsD)\n\n\nfun topSort :: \"'a rel \\<Rightarrow> 'a list \\<Rightarrow> 'a list\" where\n  \"topSort R [] = []\"\n| \"topSort R xs = (let m = findMinimal R xs in m#topSort R (remove1 m xs))\" \n\nfind_consts \"('k, 'v) fmap\"\n\ndefinition \"numberEffectors E e \\<equiv> e |> fmlookup (events E) |> the |> event_effectors |> length\"\n\ndefinition execution_addStep :: \"int \\<Rightarrow> operation \\<Rightarrow> (event,nat) fmap \\<Rightarrow> execution' \\<Rightarrow> execution'\" where\n\"execution_addStep eId opr preEventsN E \\<equiv> \nlet\n   e = D_event eId;\n   preEvents = fmdom' preEventsN;\n   (* only existing events *) \n   deps1 :: event set = Set.filter (\\<lambda>e. e\\<in>fmdom' (events E)) preEvents;\n   (* include parallel events which need to be stable *)\n   deps2 = Set.filter (\\<lambda>e. e\\<in>deps1 \\<or> (precondition_impl (event_operation ((events E)![e])) \\<noteq> None \\<and> (\\<exists>e'\\<in>deps1. (e',e)\\<in>happensBefore E ) )) (fmdom' (events E));\n   (* include causal dependencies *)\n   deps3 = downwards_closure deps2 E; (* TODO could be more precise; at the level of effectors instead of events*)\n   (* include parallel events, if stable precondition check required *)\n   deps = (if precondition_impl opr = None then deps3 else parallel_closure deps3 (fmdom' (events E)) (happensBefore E));\n   snapshot = sorted_list_of_set2 deps \n                 |> map (\\<lambda>e. (e, case preEventsN.[e] of \n                                  None \\<Rightarrow> numberEffectors E e\n                                | Some n \\<Rightarrow> if precondition_impl opr \\<noteq> None \\<or>  (\\<exists>e'\\<in>deps. e\\<in>snapshot_events (event_snapshot ((events E)![e']))) \n                                            then numberEffectors E e \n                                            else n\n                             ))  \n                 |> fmap_of_list\n                 |> Snapshot ;\n   precond = (precondition_impl opr orElse (\\<lambda>x. True));\n   execOrder = topSort (happensBefore E) (sorted_list_of_set2 deps); \n   preState :: state = executeEffectors (List.maps (\\<lambda>e. take (snapshot_num snapshot e) (event_effectors ((events E)![e]))) execOrder) initialState effector_impl\nin if \\<not>(localPrecondition_impl opr preState \\<and> precond preState) then\n  E\nelse\n  let (res,eff) = generator_impl opr e preState;\n      postState :: state = executeEffectors eff preState effector_impl  \n  in\n  \\<lparr>\n    events = fmupd e \\<lparr>\n      event_operation = opr,\n      event_result = res,\n      event_effectors = eff,\n      event_executionOrder = execOrder,\n      event_state_pre = preState,\n      event_state_post = postState,\n      event_snapshot = snapshot\n    \\<rparr> (events E)\n  \\<rparr>\n\n\"\n\ndefinition \"emptyExecution \\<equiv> \\<lparr>events = fmempty\\<rparr>\"\n\nrecord trace_event = \n  t_operation :: operation\n  t_deps :: \"(event,nat) fmap\"\n\ndefinition execution_run :: \"trace_event list \\<Rightarrow> execution'\" where\n\"execution_run ops \\<equiv> snd (fold (\\<lambda>e (n,E). (n+1, execution_addStep n (t_operation e) (t_deps e) E)) ops (0, emptyExecution))\"\n\ndefinition forallEvents :: \"execution' \\<Rightarrow> (event \\<Rightarrow> eventInfo' \\<Rightarrow> bool) \\<Rightarrow> bool\" where\n\"forallEvents E P \\<equiv> events E |> fmpred P\"\n\ndefinition forallStates :: \"execution' \\<Rightarrow> (state \\<Rightarrow> bool) \\<Rightarrow> bool\" where\n\"forallStates E P \\<equiv> forallEvents E (\\<lambda>e eInfo. P (event_state_pre eInfo) \\<and> P (event_state_post eInfo))\"\n\n\nsubsection {* Invariants *}\n\n(* if ref exists, inref exists *)\ndefinition invariant1 :: \"execution' \\<Rightarrow> bool\" where\n\"invariant1 E \\<equiv> forallStates E (\\<lambda>s. state_refs s |> fmpred (\\<lambda>r rState. \\<forall>(k,u)\\<in>dest_keys rState. case k of None \\<Rightarrow> True | Some inref \\<Rightarrow> \n   (case (state_inrefs s).[inref] of None \\<Rightarrow> False | Some inrefState \\<Rightarrow> (r,u) \\<in> two_phase_set_get (rev_refs inrefState) )))\"\n\n(* once an inref is unreachable, it remains unreachable *)\ndefinition invariant2 :: \"execution' \\<Rightarrow> bool\" where\n\"invariant2 E \\<equiv> \n(\\<forall>(e,eInfo)\\<in>events' E. \n  \\<forall>(inref,inrefState)\\<in>fmap_entries (state_inrefs (event_state_pre eInfo)). \n two_phase_set_get (rev_refs inrefState) = {}\n   \\<and> stable e E\n  \\<longrightarrow> (\\<forall>(e', eInfo')\\<in>events' E.  (e,e')\\<in>happensBefore E \\<longrightarrow> \n        (case (state_inrefs (event_state_post eInfo')).[inref] of\n            Some inrefState' \\<Rightarrow> two_phase_set_get (rev_refs inrefState') = {}\n          | None \\<Rightarrow> False\n    )))\"\n\n(* if there is a reverse reference, then there is also a forward reference\n(only true, if using transactional semantics )\n *)\ndefinition invariant3 :: \"execution' \\<Rightarrow> bool\" where\n\"invariant3 E \\<equiv> \nforallStates E (\\<lambda>S. \n  \\<forall>(inref,inrefState)\\<in>fmap_entries (state_inrefs S).  \n    \\<forall>(r,u)\\<in>two_phase_set_get (rev_refs inrefState). \n      case state_refs S.[r] of\n         None \\<Rightarrow> False\n       | Some rstate \\<Rightarrow> (Some inref,u)\\<in> dest_keys rstate\n)\n\"\n\n(* some simple postconditions for operations*)\ndefinition invariant4 :: \"execution' \\<Rightarrow> bool\" where\n\"invariant4 E \\<equiv> \n\\<forall>(e,eInfo)\\<in>events' E. \ncase event_operation eInfo of\n    init x y \\<Rightarrow> \n      (let S = event_state_post eInfo in\n      case state_refs S.[x] of\n        None \\<Rightarrow> False\n        | Some rstate \\<Rightarrow> Some y\\<in>fst`dest_keys rstate)\n  | _ \\<Rightarrow> True\n\"\n\n(* finally: if there is a reverse reference, then there is also a forward reference\n *)\ndefinition invariant5 :: \"execution' \\<Rightarrow> bool\" where\n\"invariant5 E \\<equiv>   \nlet \nexecution_order = sorted_list_of_set2 (fmdom' (events E));\neffectors = execution_order |> List.maps (\\<lambda>e'.\n      case (events E).[e'] of Some eInfo' \\<Rightarrow> event_effectors eInfo' | None \\<Rightarrow> []);\nS = executeEffectors effectors initialState effector_impl\n  in\n  \\<forall>(inref,inrefState)\\<in>fmap_entries (state_inrefs S).  \n    \\<forall>(r,u)\\<in>two_phase_set_get (rev_refs inrefState). \n      case state_refs S.[r] of\n         None \\<Rightarrow> False\n       | Some rstate \\<Rightarrow> (Some inref,u)\\<in> dest_keys rstate\n\"\n\n\nexport_code wf_correct_execution_lists in Haskell\nexport_code execution_run in Haskell\n\n\n\n\ndefinition \"transformOp I \\<equiv> let (opr, deps) = I in \\<lparr>t_operation = opr, t_deps = deps\\<rparr>\"\ndefinition \"transformOp2 I \\<equiv> let (opr, deps,xx) = I in trace_event.extend \\<lparr>t_operation = opr, t_deps = deps\\<rparr> xx\"\n\ninstantiation  fmap :: (narrowing,narrowing) narrowing begin\ndefinition \"narrowing_fmap = Quickcheck_Narrowing.apply (Quickcheck_Narrowing.cons fmap_of_list) narrowing\"\ninstance proof qed\nend\n\ninstantiation  trace_event_ext :: (narrowing) narrowing begin\ndefinition \"narrowing_trace_event_ext = Quickcheck_Narrowing.apply (Quickcheck_Narrowing.cons transformOp2) narrowing\"\ninstance proof qed\nend\n\n\ndefinition \"execution_run2 ops \\<equiv> execution_run (map transformOp ops)\"\n\n\ndefinition fmap_key_list where\n\"fmap_key_list m \\<equiv> sorted_list_of_set2 (fmdom' m)\"\n\ndefinition fmap_to_list where\n\"fmap_to_list m \\<equiv> map (\\<lambda>k. (k,m![k])) (fmap_key_list m)\"\n\n\nexport_code sorted_list_of_set2 execution_run2 \ninvariant1 invariant2 invariant3 invariant4 invariant5\n init assign deref may_delete reset_inref reset_ref D_event D_inref D_ref D_antidoteKey \ninteger_of_nat int_of_integer integer_of_nat nat_of_integer fmap_of_list D_event integer_of_int\nevents event_operation event_result event_effectors event_executionOrder event_state_pre event_state_post event_snapshot \nfmlookup fmap_key_list fmap_to_list Snapshot state_refs state_inrefs \nobject_key  dest_keys inref_object_key  rev_refs  inUse\neffector_inref_inuse_enable effector_inref_rev_refs_add effector_inref_rev_refs_rem effector_ref_dest_keys_assign\nin Haskell  (*module_name Ref_crdt*) file \"refcrdt-quickcheck/srcgen\"\n\ntypedef operations = \"UNIV :: (trace_event list) set\"\n  by force\n\n\nfun cleanRef where\n\"cleanRef (D_ref n) = D_ref (n mod 3)\"\nfun cleanInef where\n\"cleanInef (D_inref n) = D_inref 0\"\n\n\nfun cleanOperations :: \"trace_event list \\<Rightarrow> nat \\<Rightarrow> trace_event list\" where\n  \"cleanOperations [] n = []\"\n| \"cleanOperations (ev#evs) n = (if n > 20 then [] else\n  let newOp = (case t_operation ev of\n     init x y \\<Rightarrow> init (cleanRef x) (cleanInef y)\n  | assign x y \\<Rightarrow> assign (cleanRef x) (cleanRef y) \n  | deref x \\<Rightarrow> deref (cleanRef x)\n  | may_delete x xs \\<Rightarrow> may_delete (cleanInef x) []\n  | reset_inref x \\<Rightarrow> reset_inref (cleanInef x)\n  | reset_ref x \\<Rightarrow> reset_ref (cleanRef x)\n)\n  in \\<lparr>t_operation=newOp, deps = fmap_of_list (map (\\<lambda>x. case x of (D_event x,i) \\<Rightarrow> (D_event (x mod (int n)), i)) (fmap_to_list (t_deps ev)))\\<rparr>#cleanOperations evs (Suc n))\"\n\n(*\ninit ref inref\n  | assign ref ref\n  | deref ref\n  | may_delete inref \"ref list\"\n  | reset_inref inref\n  | reset_ref ref\n*)\n\n(*\nlemma \"let E = execution_run (cleanOperations ops 0) in invariant2 E\"\n  quickcheck[random,size=40,timeout=1000,verbose,timeout=1000]\n  oops\n*)\n\nabbreviation \"r1 \\<equiv> D_ref 1\"\nabbreviation \"r2 \\<equiv> D_ref 2\"\nabbreviation \"r3 \\<equiv> D_ref 3\"\n\nabbreviation \"ir1 \\<equiv> D_inref 1\"\nabbreviation \"ir2 \\<equiv> D_inref 2\"\n\nabbreviation \"e i \\<equiv> D_event i\"\n\nvalue \"let ops = [\n (* e0 *)  (init r1 ir1, fmap_of_list []),\n (* e1 *)  (reset_ref r1, fmap_of_list [(e 0,1)])\n   ]; \n   E = execution_run (map transformOp ops) \n   (*ev = e 4;\n   eInfo = the (fmlookup (events E) ev);\n   e' = e 6;\n   eInfo' = the (fmlookup (events E) e');\n  inv = (\n  \\<forall>(inref,inrefState)\\<in>fmap_entries (state_inrefs (event_state_pre eInfo)). \n two_phase_set_get (rev_refs inrefState) = {}\n   \\<and> stable ev E\n  \\<longrightarrow> ( (ev,e')\\<in>happensBefore E \\<longrightarrow> \n        (case (state_inrefs (event_state_post eInfo')).[inref] of\n            Some inrefState' \\<Rightarrow> two_phase_set_get (rev_refs inrefState') = {}\n          | None \\<Rightarrow> False\n    )))*)\n   \n  in (invariant3 E, E)\"\n\n\n\nend", "meta": {"author": "peterzeller", "repo": "ref-crdt", "sha": "b5678901b2489d87a7676188d14addf3778e235f", "save_path": "github-repos/isabelle/peterzeller-ref-crdt", "path": "github-repos/isabelle/peterzeller-ref-crdt/ref-crdt-b5678901b2489d87a7676188d14addf3778e235f/ref_crdt.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6370307944803832, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.28874175514888817}}
{"text": "theory CompositionalityResults\nimports GeneralizedZippingLemma CompositionSupport\nbegin\n\ncontext Compositionality \nbegin\n\n\n(* Theorem 6.4.1 case 1 *)\ntheorem compositionality_BSD: \n\"\\<lbrakk> BSD \\<V>1 Tr\\<^bsub>ES1\\<^esub>; BSD \\<V>2 Tr\\<^bsub>ES2\\<^esub> \\<rbrakk> \\<Longrightarrow> BSD \\<V> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\nproof -\n  assume BSD_Tr1_v1: \"BSD \\<V>1 Tr\\<^bsub>ES1\\<^esub>\"\n  assume BSD_Tr2_v2: \"BSD \\<V>2 Tr\\<^bsub>ES2\\<^esub>\"\n  {\n    fix \\<alpha> \\<beta> c\n    assume c_in_Cv: \"c \\<in> C\\<^bsub>\\<V>\\<^esub>\"\n    assume \\<beta>c\\<alpha>_in_Tr: \"(\\<beta> @ [c] @ \\<alpha>) \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n    assume \\<alpha>_contains_no_c: \"\\<alpha> \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = []\"\n\n    interpret CSES1: CompositionSupport \"ES1\" \"\\<V>\" \"\\<V>1\"  \n      using propSepViews unfolding properSeparationOfViews_def \n      by (simp add: CompositionSupport_def validES1 validV1)\n\n    interpret CSES2: CompositionSupport \"ES2\" \"\\<V>\" \"\\<V>2\"\n      using propSepViews unfolding properSeparationOfViews_def \n      by (simp add: CompositionSupport_def validES2 validV2)\n\n    from \\<beta>c\\<alpha>_in_Tr \n    have  \\<beta>c\\<alpha>_E1_in_Tr1: \"((\\<beta> @ [c] @ \\<alpha>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n      and \\<beta>c\\<alpha>_E2_in_Tr2: \"((\\<beta> @ [c] @ \\<alpha>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n      by (auto, simp add: composeES_def)+\n\n    from composeES_yields_ES validES1 validES2 have \"ES_valid (ES1 \\<parallel> ES2)\"\n      by auto\n\n    with \\<beta>c\\<alpha>_in_Tr have \"set \\<beta> \\<subseteq> E\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n      by (simp add: ES_valid_def traces_contain_events_def, auto)\n    moreover\n    have \"set (\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>) \\<subseteq> V\\<^bsub>\\<V>\\<^esub>\"\n      by (simp add: projection_def, auto)\n    moreover \n    have \"(\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>) \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = (\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>)\"\n      by (simp add: projection_def)\n    moreover\n    from CSES1.BSD_in_subsystem[OF c_in_Cv \\<beta>c\\<alpha>_E1_in_Tr1 BSD_Tr1_v1]\n    obtain \\<alpha>1' \n      where \\<alpha>1'_1: \"((\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<alpha>1') \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n      and \\<alpha>1'_2: \"(\\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>) = (\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>)\"\n      and \"\\<alpha>1' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n      by auto\n    moreover\n    from \\<alpha>1'_1 validES1 have \\<alpha>1'_in_E1: \"set \\<alpha>1' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n      by (simp add: ES_valid_def traces_contain_events_def, auto)\n    moreover\n    from \\<alpha>1'_2 propSepViews have \"((\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) = (\\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>)\"\n      proof -\n        have \"((\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) = \\<alpha> \\<upharpoonleft> (V\\<^bsub>\\<V>\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub>)\"\n          by (simp only: projection_def, auto)\n        with propSepViews have \"((\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) = (\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>)\"\n          unfolding properSeparationOfViews_def by auto\n        moreover\n        from \\<alpha>1'_2 have \"(\\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>) = (\\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>)\"\n          proof -\n            from \\<alpha>1'_in_E1 have \"\\<alpha>1' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<alpha>1'\"\n              by (simp add: list_subset_iff_projection_neutral)\n            hence \"(\\<alpha>1' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n              by simp\n            with Vv_is_Vv1_union_Vv2 have \"(\\<alpha>1' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<upharpoonleft> (V\\<^bsub>\\<V>1\\<^esub> \\<union> V\\<^bsub>\\<V>2\\<^esub>) = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n              by simp\n            hence \"\\<alpha>1' \\<upharpoonleft> (E\\<^bsub>ES1\\<^esub> \\<inter> (V\\<^bsub>\\<V>1\\<^esub> \\<union> V\\<^bsub>\\<V>2\\<^esub>)) = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n              by (simp only: projection_def, auto)\n            hence \"\\<alpha>1' \\<upharpoonleft> (E\\<^bsub>ES1\\<^esub> \\<inter> V\\<^bsub>\\<V>1\\<^esub> \\<union> E\\<^bsub>ES1\\<^esub> \\<inter> V\\<^bsub>\\<V>2\\<^esub>) = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n              by (simp add: Int_Un_distrib)\n            moreover \n            from validV1 have \"E\\<^bsub>ES1\\<^esub> \\<inter> V\\<^bsub>\\<V>1\\<^esub> = V\\<^bsub>\\<V>1\\<^esub>\"\n              by (simp add: isViewOn_def V_valid_def \n                VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n            ultimately have \"\\<alpha>1' \\<upharpoonleft> (V\\<^bsub>\\<V>1\\<^esub> \\<union> E\\<^bsub>ES1\\<^esub> \\<inter> V\\<^bsub>\\<V>2\\<^esub>) = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n              by simp\n            moreover\n            have \"E\\<^bsub>ES1\\<^esub> \\<inter> V\\<^bsub>\\<V>2\\<^esub> \\<subseteq> V\\<^bsub>\\<V>1\\<^esub>\" \n              proof -\n                from propSepViews Vv_is_Vv1_union_Vv2 have \"(V\\<^bsub>\\<V>1\\<^esub> \\<union> V\\<^bsub>\\<V>2\\<^esub>) \\<inter> E\\<^bsub>ES1\\<^esub> = V\\<^bsub>\\<V>1\\<^esub>\"\n                  unfolding properSeparationOfViews_def by simp\n                hence \"(V\\<^bsub>\\<V>1\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<union> V\\<^bsub>\\<V>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub>) = V\\<^bsub>\\<V>1\\<^esub>\"\n                  by auto\n                with validV1 have \"(V\\<^bsub>\\<V>1\\<^esub> \\<union> V\\<^bsub>\\<V>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub>) = V\\<^bsub>\\<V>1\\<^esub>\"\n                  by (simp add: isViewOn_def V_valid_def  \n                    VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n                thus ?thesis\n                  by auto\n              qed\n            ultimately show ?thesis\n               by (simp add: Un_absorb2)\n          qed\n          moreover note \\<alpha>1'_2\n          ultimately show ?thesis\n            by auto\n      qed \n    moreover\n    from CSES2.BSD_in_subsystem[OF c_in_Cv \\<beta>c\\<alpha>_E2_in_Tr2 BSD_Tr2_v2]\n    obtain \\<alpha>2' \n      where \\<alpha>2'_1: \"((\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<alpha>2') \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n      and \\<alpha>2'_2: \"(\\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>) = (\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>)\"\n      and \"\\<alpha>2' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n      by auto\n     moreover\n    from \\<alpha>2'_1 validES2 have \\<alpha>2'_in_E2: \"set \\<alpha>2' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n      by (simp add: ES_valid_def traces_contain_events_def, auto)\n    moreover\n    from \\<alpha>2'_2 propSepViews have \"((\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) = (\\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>)\"\n      proof -\n        have \"((\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) = \\<alpha> \\<upharpoonleft> (V\\<^bsub>\\<V>\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub>)\"\n          by (simp only: projection_def, auto)\n        with propSepViews have \"((\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) = (\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>)\"\n          unfolding properSeparationOfViews_def by auto\n        moreover\n        from \\<alpha>2'_2 have \"(\\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>) = (\\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>)\"\n          proof -\n            from \\<alpha>2'_in_E2 have \"\\<alpha>2' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<alpha>2'\"\n              by (simp add: list_subset_iff_projection_neutral)\n            hence \"(\\<alpha>2' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n              by simp\n            with Vv_is_Vv1_union_Vv2 have \"(\\<alpha>2' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<upharpoonleft> (V\\<^bsub>\\<V>2\\<^esub> \\<union> V\\<^bsub>\\<V>1\\<^esub>) = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n              by (simp add: Un_commute)\n            hence \"\\<alpha>2' \\<upharpoonleft> (E\\<^bsub>ES2\\<^esub> \\<inter> (V\\<^bsub>\\<V>2\\<^esub> \\<union> V\\<^bsub>\\<V>1\\<^esub>)) = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n              by (simp only: projection_def, auto)\n            hence \"\\<alpha>2' \\<upharpoonleft> (E\\<^bsub>ES2\\<^esub> \\<inter> V\\<^bsub>\\<V>2\\<^esub> \\<union> E\\<^bsub>ES2\\<^esub> \\<inter> V\\<^bsub>\\<V>1\\<^esub>) = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n              by (simp add: Int_Un_distrib)\n            moreover \n            from validV2 have \"E\\<^bsub>ES2\\<^esub> \\<inter> V\\<^bsub>\\<V>2\\<^esub> = V\\<^bsub>\\<V>2\\<^esub>\"\n              by (simp add: isViewOn_def V_valid_def \n                VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n            ultimately have \"\\<alpha>2' \\<upharpoonleft> (V\\<^bsub>\\<V>2\\<^esub> \\<union> E\\<^bsub>ES2\\<^esub> \\<inter> V\\<^bsub>\\<V>1\\<^esub>) = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n              by simp\n            moreover\n            have \"E\\<^bsub>ES2\\<^esub> \\<inter> V\\<^bsub>\\<V>1\\<^esub> \\<subseteq> V\\<^bsub>\\<V>2\\<^esub>\" \n              proof -\n                from propSepViews Vv_is_Vv1_union_Vv2 have \"(V\\<^bsub>\\<V>2\\<^esub> \\<union> V\\<^bsub>\\<V>1\\<^esub>) \\<inter> E\\<^bsub>ES2\\<^esub> = V\\<^bsub>\\<V>2\\<^esub>\"\n                  unfolding properSeparationOfViews_def by (simp add: Un_commute)\n                hence \"(V\\<^bsub>\\<V>2\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<union> V\\<^bsub>\\<V>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub>) = V\\<^bsub>\\<V>2\\<^esub>\"\n                  by auto\n                with validV2 have \"(V\\<^bsub>\\<V>2\\<^esub> \\<union> V\\<^bsub>\\<V>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub>) = V\\<^bsub>\\<V>2\\<^esub>\"\n                  by (simp add: isViewOn_def V_valid_def \n                    VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n                thus ?thesis\n                  by auto\n              qed\n            ultimately show ?thesis\n               by (simp add: Un_absorb2)\n          qed\n          moreover note \\<alpha>2'_2\n          ultimately show ?thesis\n            by auto\n      qed\n    moreover note generalized_zipping_lemma\n    ultimately have \"\\<exists>\\<alpha>'. ((\\<beta> @ \\<alpha>') \\<in> (Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>) \\<and> (\\<alpha>' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = (\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>)) \\<and> \\<alpha>' \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = [])\"\n      by blast\n  }\n  thus ?thesis \n    unfolding BSD_def\n    by auto\nqed\n\n(* Theorem 6.4.1 case 2 *)\ntheorem compositionality_BSI: \n\"\\<lbrakk> BSD \\<V>1 Tr\\<^bsub>ES1\\<^esub>; BSD \\<V>2 Tr\\<^bsub>ES2\\<^esub>; BSI \\<V>1 Tr\\<^bsub>ES1\\<^esub>; BSI \\<V>2 Tr\\<^bsub>ES2\\<^esub> \\<rbrakk>\n    \\<Longrightarrow> BSI \\<V> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\nproof -\n  assume BSD1: \"BSD \\<V>1 Tr\\<^bsub>ES1\\<^esub>\"\n     and BSD2: \"BSD \\<V>2 Tr\\<^bsub>ES2\\<^esub>\"\n     and BSI1: \"BSI \\<V>1 Tr\\<^bsub>ES1\\<^esub>\"\n     and BSI2: \"BSI \\<V>2 Tr\\<^bsub>ES2\\<^esub>\"\n\n  {\n    fix \\<alpha> \\<beta> c\n    assume c_in_Cv: \"c \\<in> C\\<^bsub>\\<V>\\<^esub>\"\n    assume \\<beta>\\<alpha>_in_Tr: \"(\\<beta> @ \\<alpha>) \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n    assume \\<alpha>_no_Cv: \"\\<alpha> \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = []\"\n    \n    from \\<beta>\\<alpha>_in_Tr \n    have  \\<beta>\\<alpha>_E1_in_Tr1: \"((\\<beta> @ \\<alpha>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n      and \\<beta>\\<alpha>_E2_in_Tr2: \"((\\<beta> @ \\<alpha>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n      by (simp add: composeES_def)+\n\n    interpret CSES1: CompositionSupport \"ES1\" \"\\<V>\" \"\\<V>1\"\n      using propSepViews unfolding properSeparationOfViews_def\n      by (simp add: CompositionSupport_def validES1 validV1)\n\n    interpret CSES2: CompositionSupport \"ES2\" \"\\<V>\" \"\\<V>2\"\n      using propSepViews unfolding properSeparationOfViews_def \n      by (simp add: CompositionSupport_def validES2 validV2)\n\n    from CSES1.BSD_in_subsystem2[OF \\<beta>\\<alpha>_E1_in_Tr1 BSD1] obtain \\<alpha>1'\n      where \\<beta>E1\\<alpha>1'_in_Tr1: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n      and \\<alpha>1'Vv1_is_\\<alpha>Vv1: \"\\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n      and \\<alpha>1'Cv1_empty: \"\\<alpha>1' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n      by auto\n\n    from CSES2.BSD_in_subsystem2[OF \\<beta>\\<alpha>_E2_in_Tr2 BSD2] obtain \\<alpha>2'\n      where \\<beta>E2\\<alpha>2'_in_Tr2: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n      and \\<alpha>2'Vv2_is_\\<alpha>Vv2: \"\\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n      and \\<alpha>2'Cv2_empty: \"\\<alpha>2' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n      by auto\n  \n    have \"\\<exists> \\<alpha>1''. (set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub> \\<and> ((\\<beta> @ [c]) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub> \n      \\<and> \\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> \\<and> \\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = [])\"\n      proof cases\n        assume cE1_empty: \"[c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = []\"\n        \n        from \\<beta>E1\\<alpha>1'_in_Tr1 validES1 have \"set \\<alpha>1' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n          by (simp add: ES_valid_def traces_contain_events_def, auto)\n        moreover\n        from cE1_empty \\<beta>E1\\<alpha>1'_in_Tr1 have \"((\\<beta> @ [c]) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n          by (simp only: projection_concatenation_commute, auto)\n        moreover\n        note \\<alpha>1'Vv1_is_\\<alpha>Vv1 \\<alpha>1'Cv1_empty\n        ultimately show ?thesis\n          by auto\n      next\n        assume cE1_not_empty: \"[c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<noteq> []\"\n        hence c_in_E1: \"c \\<in> E\\<^bsub>ES1\\<^esub>\"\n          by (simp only: projection_def, auto, split if_split_asm, auto)\n\n        from c_in_Cv c_in_E1 propSepViews have \"c \\<in> C\\<^bsub>\\<V>1\\<^esub>\"\n          unfolding properSeparationOfViews_def by auto\n        moreover\n        note \\<beta>E1\\<alpha>1'_in_Tr1 \\<alpha>1'Cv1_empty BSI1\n        ultimately obtain \\<alpha>1'' \n          where \\<beta>E1c\\<alpha>1''_in_Tr1: \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ [c] @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n          and   \\<alpha>1''Vv1_is_\\<alpha>1'Vv1: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n          and   \\<alpha>1''Cv1_empty: \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n          unfolding BSI_def\n          by blast\n        \n        from validES1 \\<beta>E1c\\<alpha>1''_in_Tr1 have \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n          by (simp add: ES_valid_def traces_contain_events_def, auto)\n        moreover\n        from \\<beta>E1c\\<alpha>1''_in_Tr1 c_in_E1 have \"((\\<beta> @ [c]) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n          by (simp only: projection_concatenation_commute projection_def, auto)\n        moreover\n        from \\<alpha>1''Vv1_is_\\<alpha>1'Vv1 \\<alpha>1'Vv1_is_\\<alpha>Vv1 have \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n          by auto\n        moreover\n        note \\<alpha>1''Cv1_empty\n        ultimately show ?thesis\n          by auto\n      qed\n    then obtain \\<alpha>1''\n      where \\<alpha>1''_in_E1star: \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\" \n      and \\<beta>cE1\\<alpha>1''_in_Tr1: \"((\\<beta> @ [c]) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\" \n      and \\<alpha>1''Vv1_is_\\<alpha>Vv1: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n      and \\<alpha>1''Cv1_empty: \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n      by auto\n\n    have \"\\<exists> \\<alpha>2''. (set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub> \n      \\<and> ((\\<beta> @ [c]) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub> \n      \\<and> \\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> \n      \\<and> \\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = [])\"\n      proof cases\n        assume cE2_empty: \"[c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = []\"\n        \n        from \\<beta>E2\\<alpha>2'_in_Tr2 validES2 have \"set \\<alpha>2' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n          by (simp add: ES_valid_def traces_contain_events_def, auto)\n        moreover\n        from cE2_empty \\<beta>E2\\<alpha>2'_in_Tr2 have \"((\\<beta> @ [c]) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n          by (simp only: projection_concatenation_commute, auto)\n        moreover\n        note \\<alpha>2'Vv2_is_\\<alpha>Vv2 \\<alpha>2'Cv2_empty\n        ultimately show ?thesis\n          by auto\n      next\n        assume cE2_not_empty: \"[c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<noteq> []\"\n        hence c_in_E2: \"c \\<in> E\\<^bsub>ES2\\<^esub>\"\n          by (simp only: projection_def, auto, split if_split_asm, auto)\n\n        from c_in_Cv c_in_E2 propSepViews have \"c \\<in> C\\<^bsub>\\<V>2\\<^esub>\"\n          unfolding properSeparationOfViews_def by auto\n        moreover\n        note \\<beta>E2\\<alpha>2'_in_Tr2 \\<alpha>2'Cv2_empty BSI2\n        ultimately obtain \\<alpha>2'' \n          where \\<beta>E2c\\<alpha>2''_in_Tr2: \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ [c] @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n          and   \\<alpha>2''Vv2_is_\\<alpha>2'Vv2: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n          and   \\<alpha>2''Cv2_empty: \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n          unfolding BSI_def\n          by blast\n        \n        from validES2 \\<beta>E2c\\<alpha>2''_in_Tr2 have \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n          by (simp add: ES_valid_def traces_contain_events_def, auto)\n        moreover\n        from \\<beta>E2c\\<alpha>2''_in_Tr2 c_in_E2 have \"((\\<beta> @ [c]) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n          by (simp only: projection_concatenation_commute projection_def, auto)\n        moreover\n        from \\<alpha>2''Vv2_is_\\<alpha>2'Vv2 \\<alpha>2'Vv2_is_\\<alpha>Vv2 have \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n          by auto\n        moreover\n        note \\<alpha>2''Cv2_empty\n        ultimately show ?thesis\n          by auto\n      qed\n    then obtain \\<alpha>2''\n      where \\<alpha>2''_in_E2star: \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\" \n      and \\<beta>cE2\\<alpha>2''_in_Tr2: \"((\\<beta> @ [c]) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\" \n      and \\<alpha>2''Vv2_is_\\<alpha>Vv2: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n      and \\<alpha>2''Cv2_empty: \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n      by auto \n    \n    (* apply the generalized zipping lemma *)\n    from VIsViewOnE c_in_Cv \\<beta>\\<alpha>_in_Tr have \"set (\\<beta> @ [c]) \\<subseteq> E\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n      by (simp add: isViewOn_def V_valid_def VC_disjoint_def \n        VN_disjoint_def NC_disjoint_def composeES_def, auto)\n    moreover\n    have \"set (\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>) \\<subseteq> V\\<^bsub>\\<V>\\<^esub>\"\n      by (simp add: projection_def, auto)\n    moreover\n    note \\<alpha>1''_in_E1star \\<alpha>2''_in_E2star \\<beta>cE1\\<alpha>1''_in_Tr1 \\<beta>cE2\\<alpha>2''_in_Tr2\n    moreover\n    have \"(\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n      proof -\n        from  \\<alpha>1''Vv1_is_\\<alpha>Vv1 propSepViews have \"\\<alpha> \\<upharpoonleft> (V\\<^bsub>\\<V>\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub>) = \\<alpha>1'' \\<upharpoonleft> (E\\<^bsub>ES1\\<^esub> \\<inter> V\\<^bsub>\\<V>\\<^esub>)\"\n          unfolding properSeparationOfViews_def by (simp add: Int_commute)\n        hence \"\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<alpha>1'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n          by (simp add: projection_def)\n        with \\<alpha>1''_in_E1star show ?thesis\n          by (simp add: list_subset_iff_projection_neutral)\n      qed\n    moreover\n    have \"(\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n      proof -\n        from  \\<alpha>2''Vv2_is_\\<alpha>Vv2 propSepViews have \"\\<alpha> \\<upharpoonleft> (V\\<^bsub>\\<V>\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub>) = \\<alpha>2'' \\<upharpoonleft> (E\\<^bsub>ES2\\<^esub> \\<inter> V\\<^bsub>\\<V>\\<^esub>)\"\n          unfolding properSeparationOfViews_def  by (simp add: Int_commute)\n        hence \"\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<alpha>2'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n          by (simp add: projection_def)\n        with \\<alpha>2''_in_E2star show ?thesis\n          by (simp add: list_subset_iff_projection_neutral)\n      qed\n    moreover\n    note \\<alpha>1''Cv1_empty \\<alpha>2''Cv2_empty generalized_zipping_lemma\n    ultimately have \"\\<exists>\\<alpha>'. (\\<beta> @ [c]) @ \\<alpha>' \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub> \\<and> \\<alpha>' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> \\<and> \\<alpha>' \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = []\"\n      by blast\n  }\n  thus ?thesis\n    unfolding BSI_def\n    by auto\nqed\n\n(* Theorem 6.4.1 case 3 *)\ntheorem compositionality_BSIA: \n\"\\<lbrakk> BSD \\<V>1 Tr\\<^bsub>ES1\\<^esub>; BSD \\<V>2 Tr\\<^bsub>ES2\\<^esub>; BSIA \\<rho>1 \\<V>1 Tr\\<^bsub>ES1\\<^esub>; BSIA \\<rho>2 \\<V>2 Tr\\<^bsub>ES2\\<^esub>; \n  (\\<rho>1 \\<V>1) \\<subseteq> (\\<rho> \\<V>) \\<inter> E\\<^bsub>ES1\\<^esub>; (\\<rho>2 \\<V>2) \\<subseteq> (\\<rho> \\<V>) \\<inter> E\\<^bsub>ES2\\<^esub> \\<rbrakk> \n    \\<Longrightarrow> BSIA \\<rho> \\<V> (Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>)\"\nproof -\n  assume BSD1: \"BSD \\<V>1 Tr\\<^bsub>ES1\\<^esub>\"\n  and BSD2: \"BSD \\<V>2 Tr\\<^bsub>ES2\\<^esub>\"\n  and BSIA1: \"BSIA \\<rho>1 \\<V>1 Tr\\<^bsub>ES1\\<^esub>\"\n  and BSIA2: \"BSIA \\<rho>2 \\<V>2 Tr\\<^bsub>ES2\\<^esub>\"\n  and \\<rho>1v1_subset_\\<rho>v_inter_E1: \"(\\<rho>1 \\<V>1) \\<subseteq> (\\<rho> \\<V>) \\<inter> E\\<^bsub>ES1\\<^esub>\"\n  and \\<rho>2v2_subset_\\<rho>v_inter_E2:\"(\\<rho>2 \\<V>2) \\<subseteq> (\\<rho> \\<V>) \\<inter> E\\<^bsub>ES2\\<^esub>\"\n\n  {\n    fix \\<alpha> \\<beta> c\n    assume c_in_Cv: \"c \\<in> C\\<^bsub>\\<V>\\<^esub>\"\n    assume \\<beta>\\<alpha>_in_Tr: \"(\\<beta> @ \\<alpha>) \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n    assume \\<alpha>_no_Cv: \"\\<alpha> \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = []\"\n    assume Adm: \"(Adm \\<V> \\<rho> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub> \\<beta> c)\"\n    then obtain \\<gamma>\n      where \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v: \"\\<gamma> \\<upharpoonleft> (\\<rho> \\<V>) = \\<beta> \\<upharpoonleft> (\\<rho> \\<V>)\"\n      and \\<gamma>c_in_Tr: \"(\\<gamma> @ [c]) \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n      unfolding Adm_def\n      by auto\n\n    from \\<beta>\\<alpha>_in_Tr \n    have  \\<beta>\\<alpha>_E1_in_Tr1: \"((\\<beta> @ \\<alpha>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n      and \\<beta>\\<alpha>_E2_in_Tr2: \"((\\<beta> @ \\<alpha>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n      by (simp add: composeES_def)+\n\n    interpret CSES1: CompositionSupport \"ES1\" \"\\<V>\" \"\\<V>1\"\n      using propSepViews unfolding properSeparationOfViews_def \n      by (simp add: CompositionSupport_def validES1 validV1)\n\n    interpret CSES2: CompositionSupport \"ES2\" \"\\<V>\" \"\\<V>2\"\n      using propSepViews unfolding properSeparationOfViews_def \n      by (simp add: CompositionSupport_def validES2 validV2)\n\n\n    from CSES1.BSD_in_subsystem2[OF \\<beta>\\<alpha>_E1_in_Tr1 BSD1] obtain \\<alpha>1'\n      where \\<beta>E1\\<alpha>1'_in_Tr1: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n      and \\<alpha>1'Vv1_is_\\<alpha>Vv1: \"\\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n      and \\<alpha>1'Cv1_empty: \"\\<alpha>1' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n      by auto\n\n    from CSES2.BSD_in_subsystem2[OF \\<beta>\\<alpha>_E2_in_Tr2 BSD2] obtain \\<alpha>2'\n      where \\<beta>E2\\<alpha>2'_in_Tr2: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n      and \\<alpha>2'Vv2_is_\\<alpha>Vv2: \"\\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n      and \\<alpha>2'Cv2_empty: \"\\<alpha>2' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n      by auto\n\n    have \"\\<exists> \\<alpha>1''. (set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub> \n      \\<and> ((\\<beta> @ [c]) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub> \n      \\<and> \\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> \n      \\<and> \\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = [])\"\n      proof cases\n        assume cE1_empty: \"[c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = []\"\n        \n        from \\<beta>E1\\<alpha>1'_in_Tr1 validES1 have \"set \\<alpha>1' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n          by (simp add: ES_valid_def traces_contain_events_def, auto)\n        moreover\n        from cE1_empty \\<beta>E1\\<alpha>1'_in_Tr1 have \"((\\<beta> @ [c]) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n          by (simp only: projection_concatenation_commute, auto)\n        moreover\n        note \\<alpha>1'Vv1_is_\\<alpha>Vv1 \\<alpha>1'Cv1_empty\n        ultimately show ?thesis\n          by auto\n      next\n        assume cE1_not_empty: \"[c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<noteq> []\"\n        hence c_in_E1: \"c \\<in> E\\<^bsub>ES1\\<^esub>\"\n          by (simp only: projection_def, auto, split if_split_asm, auto)\n\n        from c_in_Cv c_in_E1 propSepViews have \"c \\<in> C\\<^bsub>\\<V>1\\<^esub>\"\n          unfolding properSeparationOfViews_def by auto\n        moreover\n        note \\<beta>E1\\<alpha>1'_in_Tr1 \\<alpha>1'Cv1_empty\n        moreover\n        have \"(Adm \\<V>1 \\<rho>1 Tr\\<^bsub>ES1\\<^esub> (\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) c)\" \n          proof -\n            from c_in_E1 \\<gamma>c_in_Tr have \"(\\<gamma> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ [c] \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n              by (simp add: projection_def composeES_def)\n            moreover\n            have \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (\\<rho>1 \\<V>1) = \\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (\\<rho>1 \\<V>1)\"\n              proof -\n                from \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v have \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (\\<rho> \\<V>) = \\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (\\<rho> \\<V>)\"\n                  by (metis projection_commute)\n                with \\<rho>1v1_subset_\\<rho>v_inter_E1 have \"\\<gamma> \\<upharpoonleft> (\\<rho>1 \\<V>1) = \\<beta> \\<upharpoonleft> (\\<rho>1 \\<V>1)\"\n                  by (metis Int_subset_iff \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v projection_subset_elim)\n                thus ?thesis\n                  by (metis projection_commute)\n              qed\n           ultimately show ?thesis unfolding Adm_def\n              by auto\n          qed\n        moreover\n        note BSIA1\n        ultimately obtain \\<alpha>1'' \n          where \\<beta>E1c\\<alpha>1''_in_Tr1: \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ [c] @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n          and   \\<alpha>1''Vv1_is_\\<alpha>1'Vv1: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n          and   \\<alpha>1''Cv1_empty: \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n          unfolding BSIA_def\n          by blast\n        \n        from validES1 \\<beta>E1c\\<alpha>1''_in_Tr1 have \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n          by (simp add: ES_valid_def traces_contain_events_def, auto)\n        moreover\n        from \\<beta>E1c\\<alpha>1''_in_Tr1 c_in_E1 have \"((\\<beta> @ [c]) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n          by (simp only: projection_concatenation_commute projection_def, auto)\n        moreover\n        from \\<alpha>1''Vv1_is_\\<alpha>1'Vv1 \\<alpha>1'Vv1_is_\\<alpha>Vv1 have \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n          by auto\n        moreover\n        note \\<alpha>1''Cv1_empty\n        ultimately show ?thesis\n          by auto\n      qed\n    then obtain \\<alpha>1''\n      where \\<alpha>1''_in_E1star: \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\" \n      and \\<beta>cE1\\<alpha>1''_in_Tr1: \"((\\<beta> @ [c]) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\" \n      and \\<alpha>1''Vv1_is_\\<alpha>Vv1: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n      and \\<alpha>1''Cv1_empty: \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n      by auto\n\n    have \"\\<exists> \\<alpha>2''. (set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub> \n      \\<and> ((\\<beta> @ [c]) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub> \n      \\<and> \\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> \n      \\<and> \\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = [])\"\n      proof cases\n        assume cE2_empty: \"[c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = []\"\n        \n        from \\<beta>E2\\<alpha>2'_in_Tr2 validES2 have \"set \\<alpha>2' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n          by (simp add: ES_valid_def traces_contain_events_def, auto)\n        moreover\n        from cE2_empty \\<beta>E2\\<alpha>2'_in_Tr2 have \"((\\<beta> @ [c]) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n          by (simp only: projection_concatenation_commute, auto)\n        moreover\n        note \\<alpha>2'Vv2_is_\\<alpha>Vv2 \\<alpha>2'Cv2_empty\n        ultimately show ?thesis\n          by auto\n      next\n        assume cE2_not_empty: \"[c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<noteq> []\"\n        hence c_in_E2: \"c \\<in> E\\<^bsub>ES2\\<^esub>\"\n          by (simp only: projection_def, auto, split if_split_asm, auto)\n\n        from c_in_Cv c_in_E2 propSepViews have \"c \\<in> C\\<^bsub>\\<V>2\\<^esub>\"\n          unfolding properSeparationOfViews_def by auto\n        moreover\n        note \\<beta>E2\\<alpha>2'_in_Tr2 \\<alpha>2'Cv2_empty\n        moreover\n        have \"(Adm \\<V>2 \\<rho>2 Tr\\<^bsub>ES2\\<^esub> (\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) c)\" \n          proof -\n            from c_in_E2 \\<gamma>c_in_Tr have \"(\\<gamma> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ [c] \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n              by (simp add: projection_def composeES_def)\n            moreover\n            have \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (\\<rho>2 \\<V>2) = \\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (\\<rho>2 \\<V>2)\"\n              proof -\n                from \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v have \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (\\<rho> \\<V>) = \\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (\\<rho> \\<V>)\"\n                  by (metis projection_commute)\n                with \\<rho>2v2_subset_\\<rho>v_inter_E2 have \"\\<gamma> \\<upharpoonleft> (\\<rho>2 \\<V>2) = \\<beta> \\<upharpoonleft> (\\<rho>2 \\<V>2)\"\n                  by (metis Int_subset_iff \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v projection_subset_elim)\n                thus ?thesis\n                  by (metis projection_commute)\n              qed\n           ultimately show ?thesis unfolding Adm_def\n              by auto\n          qed\n        moreover\n        note BSIA2\n        ultimately obtain \\<alpha>2'' \n          where \\<beta>E2c\\<alpha>2''_in_Tr2: \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ [c] @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n          and   \\<alpha>2''Vv2_is_\\<alpha>2'Vv2: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n          and   \\<alpha>2''Cv2_empty: \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n          unfolding BSIA_def\n          by blast\n        \n        from validES2 \\<beta>E2c\\<alpha>2''_in_Tr2 have \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n          by (simp add: ES_valid_def traces_contain_events_def, auto)\n        moreover\n        from \\<beta>E2c\\<alpha>2''_in_Tr2 c_in_E2 have \"((\\<beta> @ [c]) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n          by (simp only: projection_concatenation_commute projection_def, auto)\n        moreover\n        from \\<alpha>2''Vv2_is_\\<alpha>2'Vv2 \\<alpha>2'Vv2_is_\\<alpha>Vv2 have \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n          by auto\n        moreover\n        note \\<alpha>2''Cv2_empty\n        ultimately show ?thesis\n          by auto\n      qed\n    then obtain \\<alpha>2''\n      where \\<alpha>2''_in_E2star: \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\" \n      and \\<beta>cE2\\<alpha>2''_in_Tr2: \"((\\<beta> @ [c]) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\" \n      and \\<alpha>2''Vv2_is_\\<alpha>Vv2: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n      and \\<alpha>2''Cv2_empty: \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n      by auto\n    \n    (* apply the generalized zipping lemma *)\n    from VIsViewOnE c_in_Cv \\<beta>\\<alpha>_in_Tr have \"set (\\<beta> @ [c]) \\<subseteq> E\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n      by (simp add: isViewOn_def V_valid_def VC_disjoint_def \n        VN_disjoint_def NC_disjoint_def composeES_def, auto)\n    moreover\n    have \"set (\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>) \\<subseteq> V\\<^bsub>\\<V>\\<^esub>\"\n      by (simp add: projection_def, auto)\n    moreover\n    note \\<alpha>1''_in_E1star \\<alpha>2''_in_E2star \\<beta>cE1\\<alpha>1''_in_Tr1 \\<beta>cE2\\<alpha>2''_in_Tr2\n    moreover\n    have \"(\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n      proof -\n        from  \\<alpha>1''Vv1_is_\\<alpha>Vv1 propSepViews \n        have \"\\<alpha> \\<upharpoonleft> (V\\<^bsub>\\<V>\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub>) = \\<alpha>1'' \\<upharpoonleft> (E\\<^bsub>ES1\\<^esub> \\<inter> V\\<^bsub>\\<V>\\<^esub>)\"\n         unfolding properSeparationOfViews_def by (simp add: Int_commute)\n        hence \"\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<alpha>1'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n          by (simp add: projection_def)\n        with \\<alpha>1''_in_E1star show ?thesis\n          by (simp add: list_subset_iff_projection_neutral)\n      qed\n    moreover\n    have \"(\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n      proof -\n        from  \\<alpha>2''Vv2_is_\\<alpha>Vv2 propSepViews \n        have \"\\<alpha> \\<upharpoonleft> (V\\<^bsub>\\<V>\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub>) = \\<alpha>2'' \\<upharpoonleft> (E\\<^bsub>ES2\\<^esub> \\<inter> V\\<^bsub>\\<V>\\<^esub>)\"\n          unfolding properSeparationOfViews_def by (simp add: Int_commute)\n        hence \"\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<alpha>2'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n          by (simp add: projection_def)\n        with \\<alpha>2''_in_E2star show ?thesis\n          by (simp add: list_subset_iff_projection_neutral)\n      qed\n    moreover\n    note \\<alpha>1''Cv1_empty \\<alpha>2''Cv2_empty generalized_zipping_lemma\n    ultimately have \"\\<exists>\\<alpha>'. (\\<beta> @ [c]) @ \\<alpha>' \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub> \\<and> \\<alpha>' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> \\<and> \\<alpha>' \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = []\"\n      by blast\n  }\n  thus ?thesis\n    unfolding BSIA_def\n    by auto\nqed\n\n(* Theorem 6.4.1 case 4 *)\ntheorem compositionality_FCD: \n \"\\<lbrakk> BSD \\<V>1 Tr\\<^bsub>ES1\\<^esub>; BSD \\<V>2 Tr\\<^bsub>ES2\\<^esub>; \n  \\<nabla>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> \\<nabla>\\<^bsub>\\<Gamma>1\\<^esub>; \\<nabla>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> \\<nabla>\\<^bsub>\\<Gamma>2\\<^esub>;\n  \\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>; \\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>;\n  ( \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<union> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> ) \\<subseteq> \\<Delta>\\<^bsub>\\<Gamma>\\<^esub>;\n  N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> = {}; N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> = {};\n  FCD \\<Gamma>1 \\<V>1 Tr\\<^bsub>ES1\\<^esub>; FCD \\<Gamma>2 \\<V>2 Tr\\<^bsub>ES2\\<^esub> \\<rbrakk> \n  \\<Longrightarrow> FCD \\<Gamma> \\<V> (Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>)\"\nproof -\n  assume BSD1: \"BSD \\<V>1 Tr\\<^bsub>ES1\\<^esub>\"\n    and BSD2: \"BSD \\<V>2 Tr\\<^bsub>ES2\\<^esub>\"\n    and Nabla_inter_E1_subset_Nabla1: \"\\<nabla>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> \\<nabla>\\<^bsub>\\<Gamma>1\\<^esub>\"\n    and Nabla_inter_E2_subset_Nabla2: \"\\<nabla>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> \\<nabla>\\<^bsub>\\<Gamma>2\\<^esub>\"\n    and Upsilon_inter_E1_subset_Upsilon1: \"\\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n    and Upsilon_inter_E2_subset_Upsilon2: \"\\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n    and Delta1_N1_Delta2_N2_subset_Delta: \"( \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<union> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> ) \\<subseteq> \\<Delta>\\<^bsub>\\<Gamma>\\<^esub>\"\n    and N1_Delta1_E2_disjoint: \"N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> = {}\"\n    and N2_Delta2_E1_disjoint: \"N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> = {}\"\n    and FCD1: \"FCD \\<Gamma>1 \\<V>1 Tr\\<^bsub>ES1\\<^esub>\"\n    and FCD2: \"FCD \\<Gamma>2 \\<V>2 Tr\\<^bsub>ES2\\<^esub>\"\n\n  {\n    fix \\<alpha> \\<beta> c v'\n    assume c_in_Cv_inter_Upsilon: \"c \\<in> (C\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub>)\"\n      and v'_in_Vv_inter_Nabla: \"v' \\<in> (V\\<^bsub>\\<V>\\<^esub> \\<inter> \\<nabla>\\<^bsub>\\<Gamma>\\<^esub>)\"\n      and \\<beta>cv'\\<alpha>_in_Tr: \"(\\<beta> @ [c,v'] @ \\<alpha>) \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\" \n      and \\<alpha>Cv_empty: \"\\<alpha> \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = []\"\n\n    from  \\<beta>cv'\\<alpha>_in_Tr\n    have  \\<beta>cv'\\<alpha>_E1_in_Tr1: \"(((\\<beta> @ [c,v']) @ \\<alpha>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n      and \\<beta>cv'\\<alpha>_E2_in_Tr2: \"(((\\<beta> @ [c,v']) @ \\<alpha>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n      by (simp add: composeES_def)+\n\n    interpret CSES1: CompositionSupport \"ES1\" \"\\<V>\" \"\\<V>1\"\n      using propSepViews unfolding properSeparationOfViews_def \n      by (simp add: CompositionSupport_def validES1 validV1)\n\n    interpret CSES2: CompositionSupport \"ES2\" \"\\<V>\" \"\\<V>2\"\n      using propSepViews unfolding properSeparationOfViews_def \n      by (simp add: CompositionSupport_def validES2 validV2)\n\n    from CSES1.BSD_in_subsystem2[OF \\<beta>cv'\\<alpha>_E1_in_Tr1 BSD1] obtain \\<alpha>1'\n      where \\<beta>cv'E1\\<alpha>1'_in_Tr1: \"(\\<beta> @ [c,v']) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n      and \\<alpha>1'Vv1_is_\\<alpha>Vv1: \"\\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n      and \\<alpha>1'Cv1_empty: \"\\<alpha>1' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n      by auto\n\n    from CSES2.BSD_in_subsystem2[OF \\<beta>cv'\\<alpha>_E2_in_Tr2 BSD2] obtain \\<alpha>2'\n      where \\<beta>cv'E2\\<alpha>2'_in_Tr2: \"(\\<beta> @ [c,v']) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n      and \\<alpha>2'Vv2_is_\\<alpha>Vv2: \"\\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n      and \\<alpha>2'Cv2_empty: \"\\<alpha>2' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n      by auto\n\n    from c_in_Cv_inter_Upsilon v'_in_Vv_inter_Nabla validV1\n    have \"c \\<notin> E\\<^bsub>ES1\\<^esub> \\<or> (c \\<in> E\\<^bsub>ES1\\<^esub> \\<and> v' \\<notin> E\\<^bsub>ES1\\<^esub>) \\<or> (c \\<in> E\\<^bsub>ES1\\<^esub> \\<and> v' \\<in> E\\<^bsub>ES1\\<^esub>)\"\n      by (simp add: isViewOn_def V_valid_def\n        VC_disjoint_def VN_disjoint_def NC_disjoint_def)\n    moreover {\n      assume c_notin_E1: \"c \\<notin> E\\<^bsub>ES1\\<^esub>\"\n     \n      have \"set [] \\<subseteq> (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>)\"\n        by auto\n      moreover\n      from \\<beta>cv'E1\\<alpha>1'_in_Tr1 c_notin_E1 have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ [] @ ([v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n        by (simp only: projection_concatenation_commute projection_def, auto)\n      moreover\n      have \"\\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\" ..\n      moreover\n      note \\<alpha>1'Cv1_empty \n      ultimately have \"\\<exists> \\<alpha>1'' \\<delta>1''. set \\<delta>1'' \\<subseteq> (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>) \n        \\<and> (\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<delta>1'' @ ([v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>        \n        \\<and> \\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> \\<and> \\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n        by blast\n    }\n    moreover {\n      assume c_in_E1: \"c \\<in> E\\<^bsub>ES1\\<^esub>\"\n      and v'_notin_E1: \"v' \\<notin> E\\<^bsub>ES1\\<^esub>\"\n\n      from c_in_E1 c_in_Cv_inter_Upsilon propSepViews\n        Upsilon_inter_E1_subset_Upsilon1 \n      have c_in_Cv1_Upsilon1: \"c \\<in> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>)\"\n        unfolding properSeparationOfViews_def by auto\n      hence c_in_Cv1: \"c \\<in> C\\<^bsub>\\<V>1\\<^esub>\"\n        by auto\n      moreover\n      from \\<beta>cv'E1\\<alpha>1'_in_Tr1 c_in_E1 v'_notin_E1 have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ [c] @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n        by (simp only: projection_concatenation_commute projection_def, auto)\n      moreover\n      note \\<alpha>1'Cv1_empty BSD1\n      ultimately obtain \\<alpha>1''\n        where first: \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n        and second: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n        and third: \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n        unfolding BSD_def\n        by blast\n       \n      have \"set [] \\<subseteq> (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>)\"\n        by auto\n      moreover\n      from first v'_notin_E1 have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ [] @ ([v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n        by (simp add: projection_def)\n      moreover\n      note second third\n      ultimately\n      have \"\\<exists> \\<alpha>1'' \\<delta>1''. set \\<delta>1'' \\<subseteq> (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>) \n        \\<and> (\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<delta>1'' @ ([v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>        \n        \\<and> \\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> \\<and> \\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n        by blast\n    }\n    moreover {\n      assume c_in_E1: \"c \\<in> E\\<^bsub>ES1\\<^esub>\"\n      and v'_in_E1: \"v' \\<in> E\\<^bsub>ES1\\<^esub>\"\n      \n      from c_in_E1 c_in_Cv_inter_Upsilon propSepViews\n        Upsilon_inter_E1_subset_Upsilon1 \n      have c_in_Cv1_Upsilon1: \"c \\<in> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>)\"\n        unfolding properSeparationOfViews_def by auto\n      moreover\n      from v'_in_E1 v'_in_Vv_inter_Nabla propSepViews Nabla_inter_E1_subset_Nabla1\n      have v'_in_Vv1_inter_Nabla1: \"v' \\<in> (V\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<nabla>\\<^bsub>\\<Gamma>1\\<^esub>)\"\n        unfolding properSeparationOfViews_def by auto\n      moreover\n      from \\<beta>cv'E1\\<alpha>1'_in_Tr1 c_in_E1 v'_in_E1 have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ [c,v'] @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n        by (simp add: projection_def)\n      moreover\n      note \\<alpha>1'Cv1_empty FCD1\n      ultimately obtain \\<alpha>1'' \\<delta>1'' \n        where first: \"set \\<delta>1'' \\<subseteq> (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>)\"\n        and second: \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<delta>1'' @ [v'] @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n        and third: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n        and fourth: \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n        unfolding FCD_def\n        by blast\n\n      from second v'_in_E1 have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<delta>1'' @ ([v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n        by (simp add: projection_def)\n      with first third fourth\n      have \"\\<exists> \\<alpha>1'' \\<delta>1''. set \\<delta>1'' \\<subseteq> (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>) \n        \\<and> (\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<delta>1'' @ ([v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>        \n        \\<and> \\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> \\<and> \\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n        unfolding FCD_def\n        by blast\n    }\n    ultimately obtain \\<alpha>1'' \\<delta>1'' \n      where \\<delta>1''_in_Nv1_Delta1_star: \"set \\<delta>1'' \\<subseteq> (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>)\"\n      and \\<beta>E1\\<delta>1''vE1\\<alpha>1''_in_Tr1: \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<delta>1'' @ ([v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n      and \\<alpha>1''Vv1_is_\\<alpha>1'Vv1: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n      and \\<alpha>1''Cv1_empty: \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n      by blast\n    with validV1 have \\<delta>1''_in_E1_star: \"set \\<delta>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n      by (simp add: isViewOn_def V_valid_def \n        VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n\n    from c_in_Cv_inter_Upsilon v'_in_Vv_inter_Nabla validV2\n    have \"c \\<notin> E\\<^bsub>ES2\\<^esub> \\<or> (c \\<in> E\\<^bsub>ES2\\<^esub> \\<and> v' \\<notin> E\\<^bsub>ES2\\<^esub>) \\<or> (c \\<in> E\\<^bsub>ES2\\<^esub> \\<and> v' \\<in> E\\<^bsub>ES2\\<^esub>)\"\n      by (simp add: isViewOn_def V_valid_def \n        VC_disjoint_def VN_disjoint_def NC_disjoint_def)\n    moreover {\n      assume c_notin_E2: \"c \\<notin> E\\<^bsub>ES2\\<^esub>\"\n     \n      have \"set [] \\<subseteq> (N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>)\"\n        by auto\n      moreover\n      from \\<beta>cv'E2\\<alpha>2'_in_Tr2 c_notin_E2 have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ [] @ ([v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n        by (simp only: projection_concatenation_commute projection_def, auto)\n      moreover\n      have \"\\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\" ..\n      moreover\n      note \\<alpha>2'Cv2_empty \n      ultimately have \"\\<exists> \\<alpha>2'' \\<delta>2''. set \\<delta>2'' \\<subseteq> (N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>) \n        \\<and> (\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<delta>2'' @ ([v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>        \n        \\<and> \\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> \\<and> \\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n        by blast\n    }\n    moreover {\n      assume c_in_E2: \"c \\<in> E\\<^bsub>ES2\\<^esub>\"\n      and v'_notin_E2: \"v' \\<notin> E\\<^bsub>ES2\\<^esub>\"\n\n      from c_in_E2 c_in_Cv_inter_Upsilon propSepViews Upsilon_inter_E2_subset_Upsilon2 \n      have c_in_Cv2_Upsilon2: \"c \\<in> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>)\"\n        unfolding properSeparationOfViews_def by auto\n      hence c_in_Cv2: \"c \\<in> C\\<^bsub>\\<V>2\\<^esub>\"\n        by auto\n      moreover\n      from \\<beta>cv'E2\\<alpha>2'_in_Tr2 c_in_E2 v'_notin_E2 have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ [c] @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n        by (simp only: projection_concatenation_commute projection_def, auto)\n      moreover\n      note \\<alpha>2'Cv2_empty BSD2\n      ultimately obtain \\<alpha>2''\n        where first: \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n        and second: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n        and third: \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n        unfolding BSD_def\n        by blast\n       \n      have \"set [] \\<subseteq> (N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>)\"\n        by auto\n      moreover\n      from first v'_notin_E2 have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ [] @ ([v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n        by (simp add: projection_def)\n      moreover\n      note second third\n      ultimately\n      have \"\\<exists> \\<alpha>2'' \\<delta>2''. set \\<delta>2'' \\<subseteq> (N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>) \n        \\<and> (\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<delta>2'' @ ([v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>        \n        \\<and> \\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> \\<and> \\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n        by blast\n    }\n    moreover {\n      assume c_in_E2: \"c \\<in> E\\<^bsub>ES2\\<^esub>\"\n      and v'_in_E2: \"v' \\<in> E\\<^bsub>ES2\\<^esub>\"\n      \n      from c_in_E2 c_in_Cv_inter_Upsilon propSepViews\n        Upsilon_inter_E2_subset_Upsilon2 \n      have c_in_Cv2_Upsilon2: \"c \\<in> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>)\"\n        unfolding properSeparationOfViews_def by auto\n      moreover\n      from v'_in_E2 v'_in_Vv_inter_Nabla propSepViews Nabla_inter_E2_subset_Nabla2\n      have v'_in_Vv2_inter_Nabla2: \"v' \\<in> (V\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<nabla>\\<^bsub>\\<Gamma>2\\<^esub>)\"\n        unfolding properSeparationOfViews_def by auto\n      moreover\n      from \\<beta>cv'E2\\<alpha>2'_in_Tr2 c_in_E2 v'_in_E2 have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ [c,v'] @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n        by (simp add: projection_def)\n      moreover\n      note \\<alpha>2'Cv2_empty FCD2\n      ultimately obtain \\<alpha>2'' \\<delta>2'' \n        where first: \"set \\<delta>2'' \\<subseteq> (N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>)\"\n        and second: \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<delta>2'' @ [v'] @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n        and third: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n        and fourth: \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n        unfolding FCD_def\n        by blast\n\n      from second v'_in_E2 have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<delta>2'' @ ([v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n        by (simp add: projection_def)\n      with first third fourth\n      have \"\\<exists> \\<alpha>2'' \\<delta>2''. set \\<delta>2'' \\<subseteq> (N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>) \n        \\<and> (\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<delta>2'' @ ([v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>        \n        \\<and> \\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> \\<and> \\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n        unfolding FCD_def\n        by blast\n    }\n    ultimately obtain \\<alpha>2'' \\<delta>2'' \n      where \\<delta>2''_in_Nv2_Delta2_star: \"set \\<delta>2'' \\<subseteq> (N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>)\"\n      and \\<beta>E2\\<delta>2''vE2\\<alpha>2''_in_Tr2: \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<delta>2'' @ ([v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n      and \\<alpha>2''Vv2_is_\\<alpha>2'Vv2: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n      and \\<alpha>2''Cv2_empty: \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n      by blast\n    with validV2 have \\<delta>2''_in_E2_star: \"set \\<delta>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n      by (simp add: isViewOn_def V_valid_def  \n        VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n    \n    from \\<delta>1''_in_Nv1_Delta1_star N1_Delta1_E2_disjoint \n    have \\<delta>1''E2_empty: \"\\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = []\"\n      proof -\n        from \\<delta>1''_in_Nv1_Delta1_star have \"\\<delta>1'' = \\<delta>1'' \\<upharpoonleft> (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>)\"\n          by (simp only: list_subset_iff_projection_neutral)\n        hence \"\\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>1'' \\<upharpoonleft> (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n          by simp\n        moreover\n        have \"\\<delta>1'' \\<upharpoonleft> (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>1'' \\<upharpoonleft> (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub>)\"\n          by (simp only: projection_def, auto)\n        with N1_Delta1_E2_disjoint have \"\\<delta>1'' \\<upharpoonleft> (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = []\"\n          by (simp add: projection_def)\n        ultimately show ?thesis\n          by simp\n      qed\n    moreover\n    from \\<delta>2''_in_Nv2_Delta2_star N2_Delta2_E1_disjoint have \\<delta>2''E1_empty: \"\\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = []\"\n      proof -\n        from \\<delta>2''_in_Nv2_Delta2_star have \"\\<delta>2'' = \\<delta>2'' \\<upharpoonleft> (N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>)\"\n          by (simp only: list_subset_iff_projection_neutral)\n        hence \"\\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>2'' \\<upharpoonleft> (N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n          by simp\n        moreover\n        have \"\\<delta>2'' \\<upharpoonleft> (N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>2'' \\<upharpoonleft> (N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub>)\"\n          by (simp only: projection_def, auto)\n        with N2_Delta2_E1_disjoint have \"\\<delta>2'' \\<upharpoonleft> (N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = []\"\n          by (simp add: projection_def)\n        ultimately show ?thesis\n          by simp\n      qed\n    moreover\n    note \\<beta>E1\\<delta>1''vE1\\<alpha>1''_in_Tr1 \\<beta>E2\\<delta>2''vE2\\<alpha>2''_in_Tr2 \\<delta>1''_in_E1_star \\<delta>2''_in_E2_star\n    ultimately have \\<beta>\\<delta>1''\\<delta>2''v'E1\\<alpha>1''_in_Tr1: \"(\\<beta> @ \\<delta>1'' @ \\<delta>2'' @ [v']) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n      and \\<beta>\\<delta>1''\\<delta>2''v'E2\\<alpha>2''_in_Tr2: \"(\\<beta> @ \\<delta>1'' @ \\<delta>2'' @ [v']) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n      by (simp only: projection_concatenation_commute list_subset_iff_projection_neutral, auto, \n          simp only: projection_concatenation_commute list_subset_iff_projection_neutral, auto)\n\n    have \"set (\\<beta> @ \\<delta>1'' @ \\<delta>2'' @ [v']) \\<subseteq> E\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n      proof -\n        from \\<beta>cv'\\<alpha>_in_Tr have \"set \\<beta> \\<subseteq> E\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n          by (simp add: composeES_def)\n        moreover\n        note \\<delta>1''_in_E1_star \\<delta>2''_in_E2_star\n        moreover\n        from v'_in_Vv_inter_Nabla VIsViewOnE\n        have \"v' \\<in> E\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n          by (simp add:isViewOn_def  V_valid_def\n            VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n        ultimately show ?thesis\n          by (simp add: composeES_def, auto)\n      qed\n    moreover\n    have \"set (\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>) \\<subseteq> V\\<^bsub>\\<V>\\<^esub>\"\n      by (simp add: projection_def, auto)\n    moreover\n    from \\<beta>E1\\<delta>1''vE1\\<alpha>1''_in_Tr1 validES1 have \\<alpha>1''_in_E1_star: \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n      by (simp add: ES_valid_def traces_contain_events_def, auto)\n    moreover\n    from \\<beta>E2\\<delta>2''vE2\\<alpha>2''_in_Tr2 validES2 have \\<alpha>2''_in_E2_star: \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n      by (simp add: ES_valid_def traces_contain_events_def, auto)\n    moreover\n    note \\<beta>\\<delta>1''\\<delta>2''v'E1\\<alpha>1''_in_Tr1 \\<beta>\\<delta>1''\\<delta>2''v'E2\\<alpha>2''_in_Tr2\n    moreover \n    have \"(\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n      proof -\n        from  \\<alpha>1''Vv1_is_\\<alpha>1'Vv1 \\<alpha>1'Vv1_is_\\<alpha>Vv1 propSepViews \n        have \"\\<alpha> \\<upharpoonleft> (V\\<^bsub>\\<V>\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub>) = \\<alpha>1'' \\<upharpoonleft> (E\\<^bsub>ES1\\<^esub> \\<inter> V\\<^bsub>\\<V>\\<^esub>)\"\n          unfolding properSeparationOfViews_def by (simp add: Int_commute)\n        hence \"\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<alpha>1'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n          by (simp add: projection_def)\n        with \\<alpha>1''_in_E1_star show ?thesis\n          by (simp add: list_subset_iff_projection_neutral)\n      qed\n    moreover\n    have \"(\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n      proof -\n        from  \\<alpha>2''Vv2_is_\\<alpha>2'Vv2 \\<alpha>2'Vv2_is_\\<alpha>Vv2 propSepViews \n        have \"\\<alpha> \\<upharpoonleft> (V\\<^bsub>\\<V>\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub>) = \\<alpha>2'' \\<upharpoonleft> (E\\<^bsub>ES2\\<^esub> \\<inter> V\\<^bsub>\\<V>\\<^esub>)\"\n          unfolding properSeparationOfViews_def by (simp add: Int_commute)\n        hence \"\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<alpha>2'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n          by (simp add: projection_def)\n        with \\<alpha>2''_in_E2_star show ?thesis\n          by (simp add: list_subset_iff_projection_neutral)\n      qed\n    moreover\n    note \\<alpha>1''Cv1_empty \\<alpha>2''Cv2_empty generalized_zipping_lemma\n    ultimately obtain t\n      where first: \"(\\<beta> @ \\<delta>1'' @ \\<delta>2'' @ [v']) @ t \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n      and second: \"t \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n      and third: \"t \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = []\"\n      by blast\n    \n    from \\<delta>1''_in_Nv1_Delta1_star \\<delta>2''_in_Nv2_Delta2_star \n    have \"set (\\<delta>1'' @ \\<delta>2'') \\<subseteq> (N\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>\\<^esub>)\"\n      proof -\n        have \"set (\\<delta>1'' @ \\<delta>2'') \\<subseteq> \\<Delta>\\<^bsub>\\<Gamma>\\<^esub>\"\n          proof -\n            from \\<delta>1''_in_Nv1_Delta1_star \\<delta>2''_in_Nv2_Delta2_star \n            have \"set (\\<delta>1'' @ \\<delta>2'') \\<subseteq> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<union> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub>\"\n              by auto\n            with Delta1_N1_Delta2_N2_subset_Delta show ?thesis\n              by auto\n          qed\n        moreover\n        have \"set (\\<delta>1'' @ \\<delta>2'') \\<subseteq> N\\<^bsub>\\<V>\\<^esub>\"\n          proof -\n            from \\<delta>1''_in_Nv1_Delta1_star \\<delta>2''_in_Nv2_Delta2_star \n            have \"set (\\<delta>1'' @ \\<delta>2'') \\<subseteq> (N\\<^bsub>\\<V>1\\<^esub> \\<union> N\\<^bsub>\\<V>2\\<^esub>)\"\n              by auto\n            with Nv1_union_Nv2_subsetof_Nv show ?thesis\n              by auto\n          qed\n        ultimately show ?thesis\n          by auto\n      qed\n    moreover\n    from first have \"\\<beta> @ (\\<delta>1'' @ \\<delta>2'') @ [v'] @ t \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n      by auto\n    moreover \n    note second third\n    ultimately have \"\\<exists>\\<alpha>'. \\<exists>\\<gamma>'. (set \\<gamma>') \\<subseteq> (N\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>\\<^esub>) \n      \\<and> ((\\<beta> @ \\<gamma>' @ [v'] @ \\<alpha>') \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>  \n      \\<and> (\\<alpha>' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>) = (\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>) \n      \\<and> \\<alpha>' \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = [])\"\n      by blast\n  }\n  thus ?thesis\n    unfolding FCD_def\n    by auto\nqed\n\n(* Theorem 6.4.1 case 5 *)\ntheorem compositionality_FCI: \n\"\\<lbrakk> BSD \\<V>1 Tr\\<^bsub>ES1\\<^esub>; BSD \\<V>2 Tr\\<^bsub>ES2\\<^esub>; BSIA \\<rho>1 \\<V>1 Tr\\<^bsub>ES1\\<^esub>; BSIA \\<rho>2 \\<V>2 Tr\\<^bsub>ES2\\<^esub>;\n  total ES1 (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>); total ES2 (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>);\n  \\<nabla>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> \\<nabla>\\<^bsub>\\<Gamma>1\\<^esub>; \\<nabla>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> \\<nabla>\\<^bsub>\\<Gamma>2\\<^esub>;\n  \\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>; \\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>;\n  ( \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<union> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> ) \\<subseteq> \\<Delta>\\<^bsub>\\<Gamma>\\<^esub>;\n  (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> = {} \\<and> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>)\n  \\<or> ( N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> = {} \\<and> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>)  ;\n  FCI \\<Gamma>1 \\<V>1 Tr\\<^bsub>ES1\\<^esub>; FCI \\<Gamma>2 \\<V>2 Tr\\<^bsub>ES2\\<^esub> \\<rbrakk> \n  \\<Longrightarrow> FCI \\<Gamma> \\<V> (Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>)\"\nproof -\n  assume BSD1: \"BSD \\<V>1 Tr\\<^bsub>ES1\\<^esub>\" \n    and BSD2: \"BSD \\<V>2 Tr\\<^bsub>ES2\\<^esub>\"\n    and BSIA1: \"BSIA \\<rho>1 \\<V>1 Tr\\<^bsub>ES1\\<^esub>\"\n    and BSIA2: \"BSIA \\<rho>2 \\<V>2 Tr\\<^bsub>ES2\\<^esub>\"\n    and total_ES1_C1_inter_Upsilon1: \"total ES1 (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>)\"\n    and total_ES2_C2_inter_Upsilon2: \"total ES2 (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>)\"\n    and Nabla_inter_E1_subset_Nabla1: \"\\<nabla>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> \\<nabla>\\<^bsub>\\<Gamma>1\\<^esub>\"\n    and Nabla_inter_E2_subset_Nabla2: \"\\<nabla>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> \\<nabla>\\<^bsub>\\<Gamma>2\\<^esub>\"\n    and Upsilon_inter_E1_subset_Upsilon1: \"\\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n    and Upsilon_inter_E2_subset_Upsilon2: \"\\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n    and Delta1_N1_Delta2_N2_subset_Delta: \"( \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<union> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> ) \\<subseteq> \\<Delta>\\<^bsub>\\<Gamma>\\<^esub>\"\n    and very_long_asm: \"(N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> = {} \\<and> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>)\n    \\<or> ( N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> = {} \\<and> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>)\"\n    and FCI1: \"FCI \\<Gamma>1 \\<V>1 Tr\\<^bsub>ES1\\<^esub>\"\n    and FCI2: \"FCI \\<Gamma>2 \\<V>2 Tr\\<^bsub>ES2\\<^esub>\"\n\n  {\n    fix \\<alpha> \\<beta> c v'\n    assume c_in_Cv_inter_Upsilon: \"c \\<in> (C\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub>)\"\n      and v'_in_Vv_inter_Nabla: \"v' \\<in> (V\\<^bsub>\\<V>\\<^esub> \\<inter> \\<nabla>\\<^bsub>\\<Gamma>\\<^esub>)\"\n      and \\<beta>v'\\<alpha>_in_Tr: \"(\\<beta> @ [v'] @ \\<alpha>) \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\" \n      and \\<alpha>Cv_empty: \"\\<alpha> \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = []\"\n\n    from  \\<beta>v'\\<alpha>_in_Tr\n    have  \\<beta>v'\\<alpha>_E1_in_Tr1: \"(((\\<beta> @ [v']) @ \\<alpha>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n      and \\<beta>v'\\<alpha>_E2_in_Tr2: \"(((\\<beta> @ [v']) @ \\<alpha>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n      by (simp add: composeES_def)+\n\n    interpret CSES1: CompositionSupport \"ES1\" \"\\<V>\" \"\\<V>1\"\n      using propSepViews unfolding properSeparationOfViews_def \n      by (simp add: CompositionSupport_def validES1 validV1)\n\n    interpret CSES2: CompositionSupport \"ES2\" \"\\<V>\" \"\\<V>2\"\n      using propSepViews unfolding properSeparationOfViews_def \n      by (simp add: CompositionSupport_def validES2 validV2)\n\n    from CSES1.BSD_in_subsystem2[OF \\<beta>v'\\<alpha>_E1_in_Tr1 BSD1] obtain \\<alpha>1'\n      where \\<beta>v'E1\\<alpha>1'_in_Tr1: \"(\\<beta> @ [v']) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n      and \\<alpha>1'Vv1_is_\\<alpha>Vv1: \"\\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n      and \\<alpha>1'Cv1_empty: \"\\<alpha>1' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n      by auto\n\n    from CSES2.BSD_in_subsystem2[OF \\<beta>v'\\<alpha>_E2_in_Tr2 BSD2] obtain \\<alpha>2'\n      where \\<beta>v'E2\\<alpha>2'_in_Tr2: \"(\\<beta> @ [v']) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n      and \\<alpha>2'Vv2_is_\\<alpha>Vv2: \"\\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n      and \\<alpha>2'Cv2_empty: \"\\<alpha>2' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n      by auto\n\n    note very_long_asm\n    moreover {\n      assume Nv1_inter_Delta1_inter_E2_empty: \"N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> = {}\" \n        and  Nv2_inter_Delta2_inter_E1_subsetof_Upsilon1: \"N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n\n      let ?ALPHA2''_DELTA2'' = \"\\<exists> \\<alpha>2'' \\<delta>2''. (\n        set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub> \\<and> set \\<delta>2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \n        \\<and> \\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta>2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>        \n        \\<and> \\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> \\<and> \\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = [])\"\n\n      from c_in_Cv_inter_Upsilon v'_in_Vv_inter_Nabla  validV2\n      have \"c \\<notin> E\\<^bsub>ES2\\<^esub> \\<or> (c \\<in> E\\<^bsub>ES2\\<^esub> \\<and> v' \\<notin> E\\<^bsub>ES2\\<^esub>) \\<or> (c \\<in> E\\<^bsub>ES2\\<^esub> \\<and> v' \\<in> E\\<^bsub>ES2\\<^esub>)\"\n        by (simp add: isViewOn_def V_valid_def \n          VC_disjoint_def VN_disjoint_def NC_disjoint_def)\n      moreover {\n        assume c_notin_E2: \"c \\<notin> E\\<^bsub>ES2\\<^esub>\"\n\n        from validES2 \\<beta>v'E2\\<alpha>2'_in_Tr2 have \"set \\<alpha>2' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n          by (simp add: ES_valid_def traces_contain_events_def, auto)\n        moreover \n        have \"set [] \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n          by auto\n        moreover \n        from \\<beta>v'E2\\<alpha>2'_in_Tr2 c_notin_E2 \n        have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [] @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n          by (simp add: projection_def)\n        moreover\n        have \"\\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\" ..\n        moreover \n        note \\<alpha>2'Cv2_empty\n        ultimately have ?ALPHA2''_DELTA2''\n          by blast\n      }\n      moreover {\n        assume c_in_E2: \"c \\<in> E\\<^bsub>ES2\\<^esub>\"\n          and  v'_notin_E2: \"v' \\<notin> E\\<^bsub>ES2\\<^esub>\"\n\n        from c_in_E2 c_in_Cv_inter_Upsilon propSepViews \n          Upsilon_inter_E2_subset_Upsilon2\n        have c_in_Cv2_inter_Upsilon2: \"c \\<in> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n          unfolding properSeparationOfViews_def by auto\n        hence \"c \\<in> C\\<^bsub>\\<V>2\\<^esub>\"\n          by auto\n        moreover\n        from \\<beta>v'E2\\<alpha>2'_in_Tr2 v'_notin_E2 have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n          by (simp add: projection_def)\n        moreover\n        note \\<alpha>2'Cv2_empty\n        moreover\n        have \"(Adm \\<V>2 \\<rho>2 Tr\\<^bsub>ES2\\<^esub> (\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) c)\" \n          proof -\n            from validES2 \\<beta>v'E2\\<alpha>2'_in_Tr2 v'_notin_E2 have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n              by (simp add: ES_valid_def traces_prefixclosed_def\n                prefixclosed_def prefix_def projection_concatenation_commute)\n            with total_ES2_C2_inter_Upsilon2 c_in_Cv2_inter_Upsilon2 \n            have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n              by (simp add: total_def)\n            thus ?thesis\n              unfolding Adm_def\n              by blast\n          qed\n        moreover \n        note BSIA2\n        ultimately obtain  \\<alpha>2''\n          where one: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n          and two:   \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n          and three: \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n          unfolding BSIA_def\n          by blast\n\n        from one validES2 have \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n          by (simp add: ES_valid_def traces_contain_events_def, auto)\n        moreover\n        have \"set [] \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n          by auto\n        moreover\n        from one c_in_E2 v'_notin_E2 \n        have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [] @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n          by (simp add: projection_def)\n        moreover \n        note two three\n        ultimately have ?ALPHA2''_DELTA2''\n          by blast\n      }\n      moreover {\n        assume c_in_E2: \"c \\<in> E\\<^bsub>ES2\\<^esub>\"\n          and  v'_in_E2: \"v' \\<in> E\\<^bsub>ES2\\<^esub>\"\n\n        from c_in_E2 c_in_Cv_inter_Upsilon propSepViews\n          Upsilon_inter_E2_subset_Upsilon2\n        have c_in_Cv2_inter_Upsilon2: \"c \\<in> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n          unfolding properSeparationOfViews_def by auto\n        moreover\n        from v'_in_E2 propSepViews v'_in_Vv_inter_Nabla Nabla_inter_E2_subset_Nabla2\n        have \"v' \\<in> V\\<^bsub>\\<V>2\\<^esub> \\<inter> Nabla \\<Gamma>2\"\n          unfolding properSeparationOfViews_def by auto\n        moreover\n        from v'_in_E2  \\<beta>v'E2\\<alpha>2'_in_Tr2 have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [v'] @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n          by (simp add: projection_def)\n        moreover\n        note \\<alpha>2'Cv2_empty FCI2\n        ultimately obtain \\<alpha>2'' \\<delta>2''\n          where one: \"set \\<delta>2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n          and two: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] @ \\<delta>2'' @ [v'] @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n          and three: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n          and four: \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n          unfolding FCI_def\n          by blast\n\n        from two validES2 have \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n          by (simp add: ES_valid_def traces_contain_events_def, auto)\n        moreover\n        note one\n        moreover\n        from two c_in_E2 v'_in_E2 \n        have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta>2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n          by (simp add: projection_def)\n        moreover\n        note three four\n        ultimately have ?ALPHA2''_DELTA2''\n          by blast\n      }\n      ultimately obtain \\<alpha>2'' \\<delta>2''\n        where \\<alpha>2''_in_E2star: \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n        and \\<delta>2''_in_N2_inter_Delta2star:\"set \\<delta>2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n        and \\<beta>E2_cE2_\\<delta>2''_v'E2_\\<alpha>2''_in_Tr2:\n              \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta>2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n        and \\<alpha>2''Vv2_is_\\<alpha>2'Vv2: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n        and \\<alpha>2''Cv2_empty: \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n        by blast\n\n      from c_in_Cv_inter_Upsilon Upsilon_inter_E1_subset_Upsilon1 \n      propSepViews \n      have cE1_in_Cv1_inter_Upsilon1: \"set ([c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n        unfolding properSeparationOfViews_def  by (simp add: projection_def, auto)\n     \n      from \\<delta>2''_in_N2_inter_Delta2star Nv2_inter_Delta2_inter_E1_subsetof_Upsilon1 \n        propSepViews disjoint_Nv2_Vv1 \n      have \\<delta>2''E1_in_Cv1_inter_Upsilon1star: \"set (\\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n        proof -\n          from \\<delta>2''_in_N2_inter_Delta2star \n          have eq: \"\\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>2'' \\<upharpoonleft> (N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub>)\"\n            by (metis Int_commute Int_left_commute Int_lower1 Int_lower2 \n              projection_intersection_neutral subset_trans)\n          \n          from validV1 Nv2_inter_Delta2_inter_E1_subsetof_Upsilon1 propSepViews\n            disjoint_Nv2_Vv1  \n          have \"N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n            unfolding properSeparationOfViews_def\n            by (simp add:isViewOn_def V_valid_def  VC_disjoint_def\n              VN_disjoint_def NC_disjoint_def, auto)\n          thus ?thesis\n            by (subst eq, simp only: projection_def, auto)\n        qed\n      \n      have c\\<delta>2''E1_in_Cv1_inter_Upsilon1star: \"set ((c # \\<delta>2'') \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n        proof -\n          from cE1_in_Cv1_inter_Upsilon1 \\<delta>2''E1_in_Cv1_inter_Upsilon1star\n          have \"set (([c] @ \\<delta>2'') \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n            by (simp only: projection_concatenation_commute, auto)\n          thus ?thesis\n            by auto\n        qed\n\n\n      have \"\\<exists> \\<alpha>1'' \\<delta>1''. set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub> \n        \\<and> set \\<delta>1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\n\\<^esub>        \\<and> \\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta>1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>        \n        \\<and> \\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> \\<and> \\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\n        \\<and> \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n        proof cases\n          assume v'_in_E1: \"v' \\<in> E\\<^bsub>ES1\\<^esub>\"\n          with Nabla_inter_E1_subset_Nabla1 propSepViews v'_in_Vv_inter_Nabla\n          have v'_in_Vv1_inter_Nabla1: \"v' \\<in> V\\<^bsub>\\<V>1\\<^esub> \\<inter> Nabla \\<Gamma>1\"\n            unfolding properSeparationOfViews_def by auto\n\n          have \"\\<lbrakk> (\\<beta> @ [v']) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub> ; \n            \\<alpha>1' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []; set ((c # \\<delta>2'') \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> ; \n            c \\<in> C\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub> ; set \\<delta>2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<rbrakk> \n            \\<Longrightarrow> \\<exists> \\<alpha>1'' \\<delta>1''. (set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub> \\<and> set \\<delta>1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \n              \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\n            \\<and> \\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta>1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>            \n            \\<and> \\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> \\<and> \\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\n            \\<and> \\<delta>1'' \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>) = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>)\"\n            proof (induct \"length ((c # \\<delta>2'') \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>)\" arbitrary: \\<beta> \\<alpha>1' c \\<delta>2'')\n              case 0\n\n              from 0(2) validES1 have \"set \\<alpha>1' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n                by (simp add: ES_valid_def traces_contain_events_def, auto)\n              moreover\n              have \"set [] \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                by auto\n              moreover\n              have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [] @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                proof -\n                  note 0(2)\n                  moreover\n                  from 0(1) have \"c \\<notin> E\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: projection_def, auto)\n                  ultimately show ?thesis\n                    by (simp add: projection_concatenation_commute projection_def)\n                qed\n              moreover\n              have \"\\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\" ..\n              moreover\n              note 0(3)\n              moreover \n              from 0(1) have \"[] \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>) = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                by (simp add: projection_def, split if_split_asm, auto)\n              ultimately show ?case\n                by blast\n            next\n              case (Suc n)\n\n              from projection_split_last[OF Suc(2)] obtain \\<mu> c' \\<nu>\n                where c'_in_E1: \"c' \\<in> E\\<^bsub>ES1\\<^esub>\"\n                and c\\<delta>2''_is_\\<mu>c'\\<nu>: \"c # \\<delta>2'' = \\<mu> @ [c'] @ \\<nu>\"\n                and \\<nu>E1_empty: \"\\<nu> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = []\"\n                and n_is_length_\\<mu>\\<nu>E1: \"n = length ((\\<mu> @ \\<nu>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>)\"\n                by blast\n\n              from Suc(5) c'_in_E1 c\\<delta>2''_is_\\<mu>c'\\<nu> \n              have \"set (\\<mu> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c']) \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                by (simp only: c\\<delta>2''_is_\\<mu>c'\\<nu> projection_concatenation_commute \n                  projection_def, auto)\n              hence c'_in_Cv1_inter_Upsilon1: \"c' \\<in> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                by auto\n              hence c'_in_Cv1: \"c' \\<in> C\\<^bsub>\\<V>1\\<^esub>\" and c'_in_Upsilon1: \"c' \\<in> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                by auto\n              with validV1 have c'_in_E1: \"c' \\<in> E\\<^bsub>ES1\\<^esub>\"\n                by (simp add: isViewOn_def V_valid_def  VC_disjoint_def \n                  VN_disjoint_def NC_disjoint_def, auto)\n\n              show ?case\n                proof (cases \\<mu>)\n                  case Nil (* we apply FCI in this case *)\n                  with c\\<delta>2''_is_\\<mu>c'\\<nu> have c_is_c': \"c = c'\" and \\<delta>2''_is_\\<nu>: \"\\<delta>2'' = \\<nu>\"\n                    by auto\n                  with c'_in_Cv1_inter_Upsilon1 have \"c \\<in> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    by simp\n                  moreover\n                  note v'_in_Vv1_inter_Nabla1\n                  moreover\n                  from v'_in_E1 Suc(3) have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ [v'] @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: projection_concatenation_commute projection_def)\n                  moreover\n                  note Suc(4) FCI1\n                  ultimately obtain \\<alpha>1'' \\<gamma>\n                    where one: \"set \\<gamma> \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    and two: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] @ \\<gamma> @ [v'] @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    and three: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n                    and four: \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n                    unfolding FCI_def\n                    by blast\n\n                  (* we choose \\<delta>1'' = \\<nu> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<gamma> *)\n                  let ?DELTA1'' = \"\\<nu> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<gamma>\"\n\n                  from two validES1 have \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: ES_valid_def traces_contain_events_def, auto)\n                  moreover\n                  from one \\<nu>E1_empty \n                  have \"set ?DELTA1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    by auto\n                  moreover\n                  have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ ?DELTA1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    proof -\n                      from c_is_c' c'_in_E1 have \"[c] = [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                        by (simp add: projection_def)\n                      moreover\n                      from v'_in_E1 have \"[v'] = [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                        by (simp add: projection_def)\n                      moreover\n                      note \\<nu>E1_empty two\n                      ultimately show ?thesis\n                        by auto\n                    qed\n                  moreover\n                  note three four\n                  moreover\n                  have \"?DELTA1'' \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>) = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                    proof -\n                      have \"\\<gamma> \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>) = []\"\n                        proof -\n                          from validV1 have \"N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>) = {}\"\n                            by (simp add: isViewOn_def V_valid_def \n                              VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n                          with projection_intersection_neutral[OF one, of \"C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"]\n                          show ?thesis\n                            by (simp add: projection_def)\n                        qed\n                      with \\<delta>2''_is_\\<nu> \\<nu>E1_empty show ?thesis\n                        by (simp add: projection_concatenation_commute)\n                    qed\n                  ultimately show ?thesis\n                    by blast\n                next\n                  case (Cons x xs) (* we apply the inductive hypothesis in this case *)\n                  with c\\<delta>2''_is_\\<mu>c'\\<nu> have \\<mu>_is_c_xs: \"\\<mu> = [c] @ xs\" \n                    and \\<delta>2''_is_xs_c'_\\<nu>: \"\\<delta>2'' = xs @ [c'] @ \\<nu>\"\n                    by auto\n                  with n_is_length_\\<mu>\\<nu>E1 have \"n = length ((c # (xs @ \\<nu>)) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>)\"\n                    by auto\n                  moreover\n                  note Suc(3,4)\n                  moreover\n                  have \"set ((c # (xs @ \\<nu>)) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    proof -\n                      have res: \"c # (xs @ \\<nu>) = [c] @ (xs @ \\<nu>)\" \n                        by auto\n\n                      from Suc(5) c\\<delta>2''_is_\\<mu>c'\\<nu> \\<mu>_is_c_xs \\<nu>E1_empty\n                      show ?thesis\n                        by (subst res, simp only: c\\<delta>2''_is_\\<mu>c'\\<nu> projection_concatenation_commute \n                          set_append, auto)\n                    qed\n                  moreover\n                  note Suc(6) \n                  moreover\n                  from Suc(7) \\<delta>2''_is_xs_c'_\\<nu> have \"set (xs @ \\<nu>) \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    by auto\n                  moreover note Suc(1)[of c \"xs @ \\<nu>\" \\<beta> \\<alpha>1']\n                  ultimately obtain \\<delta> \\<gamma>\n                    where one: \"set \\<delta> \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n                    and two: \"set \\<gamma> \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    and three: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<gamma> @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta> \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    and four: \"\\<delta> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n                    and five: \"\\<delta> \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n                    and six: \"\\<gamma> \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>) = (xs @ \\<nu>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                    by blast\n\n                  (* apply FCI to insert c' after \\<gamma> *)\n                  let ?BETA = \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<gamma>\"\n\n                  note c'_in_Cv1_inter_Upsilon1 v'_in_Vv1_inter_Nabla1\n                  moreover\n                  from three v'_in_E1 have \"?BETA @ [v'] @ \\<delta> \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: projection_def)\n                  moreover\n                  note five FCI1\n                  ultimately obtain \\<alpha>1'' \\<delta>'\n                    where fci_one: \"set \\<delta>' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    and fci_two: \"?BETA @ [c'] @ \\<delta>' @ [v'] @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    and fci_three: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<delta> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n                    and fci_four:  \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n                    unfolding FCI_def\n                    by blast\n  \n                  let ?DELTA1'' = \"\\<gamma> @ [c'] @ \\<delta>'\"\n\n                  from fci_two validES1 have \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: ES_valid_def traces_contain_events_def, auto)\n                  moreover\n                  have \"set ?DELTA1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    proof -\n                      from Suc(7) c'_in_Cv1_inter_Upsilon1 \\<delta>2''_is_xs_c'_\\<nu> \n                      have \"c' \\<in>  C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                        by auto\n                      with two fci_one show ?thesis\n                        by auto\n                    qed\n                  moreover\n                  from fci_two v'_in_E1 \n                  have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ ?DELTA1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: projection_def)\n                  moreover\n                  from fci_three four have \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n                    by simp\n                  moreover\n                  note fci_four\n                  moreover             \n                  have \"?DELTA1'' \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>) = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                    proof -\n                      have \"\\<delta>' \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>) = []\"\n                        proof -\n                          from fci_one have \"\\<forall> e \\<in> set \\<delta>'. e \\<in> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                            by auto\n                          with validV1 have \"\\<forall> e \\<in> set \\<delta>'. e \\<notin> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                            by (simp add: isViewOn_def V_valid_def\n                              VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n                          thus ?thesis\n                            by (simp add: projection_def)\n                        qed\n                      with c'_in_E1 c'_in_Cv1_inter_Upsilon1 \\<delta>2''_is_xs_c'_\\<nu> \\<nu>E1_empty six \n                      show ?thesis\n                        by (simp only: projection_concatenation_commute projection_def, auto)\n                    qed\n                  ultimately show ?thesis \n                    by blast     \n                qed\n          qed\n          from this[OF \\<beta>v'E1\\<alpha>1'_in_Tr1 \\<alpha>1'Cv1_empty c\\<delta>2''E1_in_Cv1_inter_Upsilon1star \n            c_in_Cv_inter_Upsilon \\<delta>2''_in_N2_inter_Delta2star]\n          obtain \\<alpha>1'' \\<delta>1''\n            where one: \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n            and two: \"set \\<delta>1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n            and three: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta>1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>            \n            \\<and> \\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> \\<and> \\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n            and four: \"\\<delta>1'' \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>) = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n            by blast\n\n          note one two three\n          moreover\n          have \"\\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\" \n            proof -\n              from projection_intersection_neutral[OF two, of \"E\\<^bsub>ES2\\<^esub>\"] \n                Nv1_inter_Delta1_inter_E2_empty validV2 \n              have \"\\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>1'' \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub>)\"\n                by (simp only: Int_Un_distrib2, auto)\n              moreover\n              from validV2 \n              have \"C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> = C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                by (simp add: isViewOn_def V_valid_def \n                  VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n              ultimately have \"\\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>1'' \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>)\"\n                by simp\n              hence \"\\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>1'' \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>) \\<upharpoonleft> (N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>)\"\n                by (simp add: projection_def)\n              with four have \"\\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>)\"\n                by simp\n              hence \"\\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2'' \\<upharpoonleft> (N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                by (simp only: projection_commute)\n              with \\<delta>2''_in_N2_inter_Delta2star show ?thesis\n                by (simp only: list_subset_iff_projection_neutral)\n            qed\n          ultimately show ?thesis\n              by blast\n        next\n          assume v'_notin_E1: \"v' \\<notin> E\\<^bsub>ES1\\<^esub>\"\n\n           have \"\\<lbrakk> (\\<beta> @ [v']) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub> ; \n            \\<alpha>1' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []; set ((c # \\<delta>2'') \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> ; \n             c \\<in> C\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub> ; set \\<delta>2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<rbrakk> \n            \\<Longrightarrow> \\<exists> \\<alpha>1'' \\<delta>1''. (set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub> \\<and> set \\<delta>1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \n                \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\n\\<^esub>            \\<and> \\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta>1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>            \n             \\<and> \\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> \\<and> \\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\n            \\<and> \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>)\"\n            proof (induct \"length ((c # \\<delta>2'') \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>)\" arbitrary: \\<beta> \\<alpha>1' c \\<delta>2'')\n               case 0\n\n              from 0(2) validES1 have \"set \\<alpha>1' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n                by (simp add: ES_valid_def traces_contain_events_def, auto)\n              moreover\n              have \"set [] \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                by auto\n              moreover\n              have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [] @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                proof -\n                  note 0(2)\n                  moreover\n                  from 0(1) have \"c \\<notin> E\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: projection_def, auto)\n                  ultimately show ?thesis\n                    by (simp add: projection_concatenation_commute projection_def)\n                qed\n              moreover\n              have \"\\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\" ..\n              moreover\n              note 0(3)\n              moreover \n              from 0(1) have \"[] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                by (simp add: projection_def, split if_split_asm, auto)\n              ultimately show ?case\n                by blast\n            next\n              case (Suc n)\n\n              from projection_split_last[OF Suc(2)] obtain \\<mu> c' \\<nu>\n                where c'_in_E1: \"c' \\<in> E\\<^bsub>ES1\\<^esub>\"\n                and c\\<delta>2''_is_\\<mu>c'\\<nu>: \"c # \\<delta>2'' = \\<mu> @ [c'] @ \\<nu>\"\n                and \\<nu>E1_empty: \"\\<nu> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = []\"\n                and n_is_length_\\<mu>\\<nu>E1: \"n = length ((\\<mu> @ \\<nu>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>)\"\n                by blast\n\n              from Suc(5) c'_in_E1 c\\<delta>2''_is_\\<mu>c'\\<nu> \n              have \"set (\\<mu> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c']) \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                by (simp only: c\\<delta>2''_is_\\<mu>c'\\<nu> projection_concatenation_commute \n                  projection_def, auto)\n              hence c'_in_Cv1_inter_Upsilon1: \"c' \\<in> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                by auto\n              hence c'_in_Cv1: \"c' \\<in> C\\<^bsub>\\<V>1\\<^esub>\" and c'_in_Upsilon1: \"c' \\<in> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                by auto\n              with validV1 have c'_in_E1: \"c' \\<in> E\\<^bsub>ES1\\<^esub>\"\n                by (simp add: isViewOn_def V_valid_def\n                  VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n\n              show ?case\n                proof (cases \\<mu>)\n                  case Nil (* we just apply BSIA in this case *)\n                  with c\\<delta>2''_is_\\<mu>c'\\<nu> have c_is_c': \"c = c'\" \n                    and \\<delta>2''_is_\\<nu>: \"\\<delta>2'' = \\<nu>\"\n                    by auto\n                  with c'_in_Cv1_inter_Upsilon1 have \"c \\<in> C\\<^bsub>\\<V>1\\<^esub>\"\n                    by simp\n                  moreover\n                  from v'_notin_E1 Suc(3) have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: projection_concatenation_commute projection_def)\n                  moreover\n                  note Suc(4)\n                  moreover\n                  have \"Adm \\<V>1 \\<rho>1 Tr\\<^bsub>ES1\\<^esub> (\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) c\"\n                    proof -\n                      have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                        proof -\n                          from c_is_c' c'_in_Cv1_inter_Upsilon1 \n                          have \"c \\<in> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                            by simp\n                          moreover\n                          from validES1 Suc(3) \n                          have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                            by (simp only: ES_valid_def traces_prefixclosed_def\n                              projection_concatenation_commute \n                              prefixclosed_def prefix_def, auto)\n                          moreover\n                          note total_ES1_C1_inter_Upsilon1\n                          ultimately show ?thesis\n                            unfolding total_def\n                            by blast\n                        qed\n                      thus ?thesis\n                        unfolding Adm_def\n                        by blast                        \n                    qed\n                  moreover\n                  note BSIA1\n                  ultimately obtain \\<alpha>1''\n                    where one: \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ [c] @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    and two: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n                    and three: \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n                    unfolding BSIA_def\n                    by blast\n\n                  let ?DELTA1'' = \"\\<nu> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n\n                  from one validES1 have \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: ES_valid_def traces_contain_events_def, auto)\n                  moreover\n                  from \\<nu>E1_empty\n                  have \"set ?DELTA1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    by simp\n                  moreover\n                  from c_is_c' c'_in_E1 one v'_notin_E1 \\<nu>E1_empty\n                  have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ ?DELTA1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: projection_def)\n                  moreover\n                  note two three\n                  moreover\n                  from \\<nu>E1_empty \\<delta>2''_is_\\<nu> have \"?DELTA1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: projection_def)\n                  ultimately show ?thesis\n                    by blast\n                next\n                  case (Cons x xs) (* apply inductive hypothesis, then BSIA *)\n                  with c\\<delta>2''_is_\\<mu>c'\\<nu>\n                  have \\<mu>_is_c_xs: \"\\<mu> = [c] @ xs\" and \\<delta>2''_is_xs_c'_\\<nu>: \"\\<delta>2'' = xs @ [c'] @ \\<nu>\"\n                    by auto\n                  with n_is_length_\\<mu>\\<nu>E1 have \"n = length ((c # (xs @ \\<nu>)) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>)\"\n                    by auto\n                  moreover\n                  note Suc(3,4)\n                  moreover\n                  have \"set ((c # (xs @ \\<nu>)) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    proof -\n                      have res: \"c # (xs @ \\<nu>) = [c] @ (xs @ \\<nu>)\" \n                        by auto\n\n                      from Suc(5) c\\<delta>2''_is_\\<mu>c'\\<nu> \\<mu>_is_c_xs \\<nu>E1_empty\n                      show ?thesis\n                        by (subst res, simp only: c\\<delta>2''_is_\\<mu>c'\\<nu> projection_concatenation_commute \n                          set_append, auto)\n                    qed\n                  moreover\n                  note Suc(6) \n                  moreover\n                  from Suc(7) \\<delta>2''_is_xs_c'_\\<nu> have \"set (xs @ \\<nu>) \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    by auto\n                  moreover note Suc(1)[of c \"xs @ \\<nu>\" \\<beta> \\<alpha>1']\n                  ultimately obtain \\<delta> \\<gamma>\n                    where one: \"set \\<delta> \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n                    and two: \"set \\<gamma> \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    and three: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<gamma> @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta> \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    and four: \"\\<delta> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n                    and five: \"\\<delta> \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n                    and six: \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = (xs @ \\<nu>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                    by blast\n                  \n                   (* apply BSIA to insert c' after \\<gamma> *)\n                  let ?BETA = \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<gamma>\"\n\n                  from c'_in_Cv1_inter_Upsilon1 have \"c' \\<in> C\\<^bsub>\\<V>1\\<^esub>\"\n                    by auto\n                  moreover\n                  from three v'_notin_E1 have \"?BETA @ \\<delta> \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: projection_def)\n                  moreover\n                  note five \n                  moreover\n                  have \"Adm \\<V>1 \\<rho>1 Tr\\<^bsub>ES1\\<^esub> ?BETA c'\"\n                    proof -\n                      have \"?BETA @ [c'] \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                        proof -\n                          from validES1 three \n                          have \"?BETA \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                            by (simp only: ES_valid_def traces_prefixclosed_def\n                              projection_concatenation_commute \n                              prefixclosed_def prefix_def, auto)\n                          moreover\n                          note c'_in_Cv1_inter_Upsilon1 total_ES1_C1_inter_Upsilon1\n                          ultimately show ?thesis\n                            unfolding total_def\n                            by blast\n                        qed\n                      thus ?thesis\n                        unfolding Adm_def\n                        by blast                        \n                    qed\n                  moreover\n                  note BSIA1\n                  ultimately obtain \\<alpha>1''\n                    where bsia_one: \"?BETA @ [c'] @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    and bsia_two: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<delta> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n                    and bsia_three:  \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n                    unfolding BSIA_def\n                    by blast\n  \n                  let ?DELTA1'' = \"\\<gamma> @ [c']\"\n\n                  from bsia_one validES1 have \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n                    by (simp add:isViewOn_def ES_valid_def traces_contain_events_def, auto)\n                  moreover\n                  have \"set ?DELTA1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    proof -\n                      from Suc(7) c'_in_Cv1_inter_Upsilon1 \\<delta>2''_is_xs_c'_\\<nu> \n                      have \"c' \\<in>  C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                        by auto\n                      with two show ?thesis\n                        by auto\n                    qed\n                  moreover\n                  from bsia_one v'_notin_E1 \n                  have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ ?DELTA1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: projection_def)\n                  moreover\n                  from bsia_two four have \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n                    by simp\n                  moreover\n                  note bsia_three\n                  moreover             \n                  have \"?DELTA1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                    proof -\n                      from validV2 Suc(7) \\<delta>2''_is_xs_c'_\\<nu> \n                      have \"c' \\<in> E\\<^bsub>ES2\\<^esub>\"\n                        by (simp add: isViewOn_def V_valid_def\n                          VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n                      with c'_in_E1 c'_in_Cv1_inter_Upsilon1 \\<delta>2''_is_xs_c'_\\<nu> \\<nu>E1_empty six \n                      show ?thesis\n                        by (simp only: projection_concatenation_commute projection_def, auto)\n                    qed\n                  ultimately show ?thesis \n                    by blast     \n                qed\n            qed\n          from this[OF \\<beta>v'E1\\<alpha>1'_in_Tr1 \\<alpha>1'Cv1_empty c\\<delta>2''E1_in_Cv1_inter_Upsilon1star \n            c_in_Cv_inter_Upsilon \\<delta>2''_in_N2_inter_Delta2star]\n          show ?thesis \n            by blast\n        qed\n      then obtain \\<alpha>1'' \\<delta>1''\n        where \\<alpha>1''_in_E1star: \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n        and \\<delta>1''_in_N1_inter_Delta1star:\"set \\<delta>1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n        and \\<beta>E1_cE1_\\<delta>1''_v'E1_\\<alpha>1''_in_Tr1: \n        \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta>1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n        and \\<alpha>1''Vv1_is_\\<alpha>1'Vv1: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n        and \\<alpha>1''Cv1_empty: \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n        and \\<delta>1''E2_is_\\<delta>2''E1: \"\\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n        by blast\n\n      from \\<beta>E1_cE1_\\<delta>1''_v'E1_\\<alpha>1''_in_Tr1 \\<beta>E2_cE2_\\<delta>2''_v'E2_\\<alpha>2''_in_Tr2 \n        validES1 validES2\n      have \\<delta>1''_in_E1star: \"set \\<delta>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\" and \\<delta>2''_in_E2star: \"set \\<delta>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n        by (simp_all add: ES_valid_def traces_contain_events_def, auto)\n      with \\<delta>1''E2_is_\\<delta>2''E1 merge_property[of \\<delta>1'' \"E\\<^bsub>ES1\\<^esub>\" \\<delta>2'' \"E\\<^bsub>ES2\\<^esub>\"] obtain \\<delta>'\n        where \\<delta>'E1_is_\\<delta>1'': \"\\<delta>' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1''\"\n        and \\<delta>'E2_is_\\<delta>2'': \"\\<delta>' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2''\"\n        and \\<delta>'_contains_only_\\<delta>1''_\\<delta>2''_events: \"set \\<delta>' \\<subseteq> set \\<delta>1'' \\<union> set \\<delta>2''\"\n        unfolding Let_def\n        by auto\n\n      let ?TAU = \"\\<beta> @ [c] @ \\<delta>' @ [v']\"\n      let ?LAMBDA = \"\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n      let ?T1 = \\<alpha>1''\n      let ?T2 = \\<alpha>2''\n\n     (* apply the generalized zipping lemma *)\n     have \"?TAU \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n        proof -\n          from \\<beta>E1_cE1_\\<delta>1''_v'E1_\\<alpha>1''_in_Tr1 \\<delta>'E1_is_\\<delta>1'' validES1 \n          have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta>' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n            by (simp add: ES_valid_def traces_prefixclosed_def\n              prefixclosed_def prefix_def)\n          hence \"(\\<beta> @ [c] @ \\<delta>' @ [v']) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n            by (simp add: projection_def, auto)\n          moreover          \n          from \\<beta>E2_cE2_\\<delta>2''_v'E2_\\<alpha>2''_in_Tr2 \\<delta>'E2_is_\\<delta>2'' validES2 \n          have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta>' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n            by (simp add: ES_valid_def traces_prefixclosed_def\n              prefixclosed_def prefix_def)\n          hence \"(\\<beta> @ [c] @ \\<delta>' @ [v']) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n            by (simp add: projection_def, auto)\n          moreover\n          from \\<beta>v'\\<alpha>_in_Tr c_in_Cv_inter_Upsilon VIsViewOnE\n            \\<delta>'_contains_only_\\<delta>1''_\\<delta>2''_events \\<delta>1''_in_E1star \\<delta>2''_in_E2star\n          have \"set (\\<beta> @ [c] @ \\<delta>' @ [v']) \\<subseteq> E\\<^bsub>ES1\\<^esub> \\<union> E\\<^bsub>ES2\\<^esub>\"\n            unfolding composeES_def isViewOn_def V_valid_def \n              VC_disjoint_def VN_disjoint_def NC_disjoint_def\n            by auto\n          ultimately show ?thesis\n            unfolding composeES_def\n            by auto\n        qed \n      hence \"set ?TAU \\<subseteq> E\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n        unfolding composeES_def\n        by auto\n      moreover\n      have \"set ?LAMBDA \\<subseteq> V\\<^bsub>\\<V>\\<^esub>\"\n        by (simp add: projection_def, auto)\n      moreover\n      note \\<alpha>1''_in_E1star \\<alpha>2''_in_E2star\n      moreover\n      from \\<beta>E1_cE1_\\<delta>1''_v'E1_\\<alpha>1''_in_Tr1 \\<delta>'E1_is_\\<delta>1'' \n      have \"?TAU \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ ?T1 \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n        by (simp only: projection_concatenation_commute, auto)\n      moreover\n      from \\<beta>E2_cE2_\\<delta>2''_v'E2_\\<alpha>2''_in_Tr2 \\<delta>'E2_is_\\<delta>2'' \n      have \"?TAU \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ ?T2 \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n        by (simp only: projection_concatenation_commute, auto)\n      moreover\n      have \"?LAMBDA \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = ?T1 \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n        proof -\n          from propSepViews have \"?LAMBDA \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n            unfolding properSeparationOfViews_def by (simp add: projection_sequence)\n          moreover\n          from \\<alpha>1''_in_E1star propSepViews \n          have \"?T1 \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = ?T1 \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n            unfolding properSeparationOfViews_def \n            by (metis Int_commute projection_intersection_neutral)\n          moreover\n          note \\<alpha>1'Vv1_is_\\<alpha>Vv1 \\<alpha>1''Vv1_is_\\<alpha>1'Vv1\n          ultimately show ?thesis\n            by simp\n        qed\n      moreover\n      have \"?LAMBDA \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = ?T2 \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n        proof -\n          from propSepViews \n          have \"?LAMBDA \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n            unfolding properSeparationOfViews_def  by (simp add: projection_sequence)\n          moreover\n          from \\<alpha>2''_in_E2star propSepViews \n          have \"?T2 \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = ?T2 \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n            unfolding properSeparationOfViews_def\n            by (metis Int_commute projection_intersection_neutral)\n          moreover\n          note \\<alpha>2'Vv2_is_\\<alpha>Vv2 \\<alpha>2''Vv2_is_\\<alpha>2'Vv2\n          ultimately show ?thesis\n            by simp\n        qed\n      moreover\n      note \\<alpha>1''Cv1_empty \\<alpha>2''Cv2_empty generalized_zipping_lemma\n      ultimately obtain t (* show that the conclusion of FCI holds *)\n        where \"?TAU @ t \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n        and  \"t \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = ?LAMBDA\"\n        and \"t \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = []\"\n        by blast\n      moreover\n      have \"set \\<delta>' \\<subseteq> N\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>\\<^esub>\"\n        proof -\n          from \\<delta>'_contains_only_\\<delta>1''_\\<delta>2''_events \n            \\<delta>1''_in_N1_inter_Delta1star \\<delta>2''_in_N2_inter_Delta2star\n          have \"set \\<delta>' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n            by auto\n          with Delta1_N1_Delta2_N2_subset_Delta Nv1_union_Nv2_subsetof_Nv \n          show ?thesis\n            by auto\n        qed\n        ultimately\n        have \"\\<exists>\\<alpha>' \\<gamma>'. (set \\<gamma>' \\<subseteq> N\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>\\<^esub> \\<and> \\<beta> @ [c] @ \\<gamma>' @ [v'] @ \\<alpha>' \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub> \n                    \\<and> \\<alpha>' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> \\<and> \\<alpha>' \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = [])\"\n        by (simp only: append_assoc, blast)\n    }\n    moreover {\n      assume Nv2_inter_Delta2_inter_E1_empty: \"N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> = {}\" \n        and  Nv1_inter_Delta1_inter_E2_subsetof_Upsilon2: \"N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n\n      let ?ALPHA1''_DELTA1'' = \"\\<exists> \\<alpha>1'' \\<delta>1''. (\n        set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub> \\<and> set \\<delta>1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \n        \\<and> \\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta>1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>        \n        \\<and> \\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> \\<and> \\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = [])\"\n\n      from c_in_Cv_inter_Upsilon v'_in_Vv_inter_Nabla validV1\n      have \"c \\<notin> E\\<^bsub>ES1\\<^esub> \\<or> (c \\<in> E\\<^bsub>ES1\\<^esub> \\<and> v' \\<notin> E\\<^bsub>ES1\\<^esub>) \\<or> (c \\<in> E\\<^bsub>ES1\\<^esub> \\<and> v' \\<in> E\\<^bsub>ES1\\<^esub>)\"\n        by (simp add: isViewOn_def V_valid_def \n          VC_disjoint_def VN_disjoint_def NC_disjoint_def)\n      moreover {\n        assume c_notin_E1: \"c \\<notin> E\\<^bsub>ES1\\<^esub>\"\n\n        from validES1 \\<beta>v'E1\\<alpha>1'_in_Tr1 have \"set \\<alpha>1' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n          by (simp add: ES_valid_def traces_contain_events_def, auto)\n        moreover \n        have \"set [] \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n          by auto\n        moreover \n        from \\<beta>v'E1\\<alpha>1'_in_Tr1 c_notin_E1 \n        have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [] @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n          by (simp add: projection_def)\n        moreover\n        have \"\\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\" ..\n        moreover \n        note \\<alpha>1'Cv1_empty\n        ultimately have ?ALPHA1''_DELTA1''\n          by blast\n      }\n      moreover {\n        assume c_in_E1: \"c \\<in> E\\<^bsub>ES1\\<^esub>\"\n          and  v'_notin_E1: \"v' \\<notin> E\\<^bsub>ES1\\<^esub>\"\n\n        from c_in_E1 c_in_Cv_inter_Upsilon propSepViews\n          Upsilon_inter_E1_subset_Upsilon1\n        have c_in_Cv1_inter_Upsilon1: \"c \\<in> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n          unfolding properSeparationOfViews_def by auto\n        hence \"c \\<in> C\\<^bsub>\\<V>1\\<^esub>\"\n          by auto\n        moreover\n        from \\<beta>v'E1\\<alpha>1'_in_Tr1 v'_notin_E1 have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n          by (simp add: projection_def)\n        moreover\n        note \\<alpha>1'Cv1_empty\n        moreover\n        have \"(Adm \\<V>1 \\<rho>1 Tr\\<^bsub>ES1\\<^esub> (\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) c)\" \n          proof -\n            from validES1 \\<beta>v'E1\\<alpha>1'_in_Tr1 v'_notin_E1 have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n              by (simp add: ES_valid_def traces_prefixclosed_def\n                prefixclosed_def prefix_def projection_concatenation_commute)\n            with total_ES1_C1_inter_Upsilon1 c_in_Cv1_inter_Upsilon1\n            have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n              by (simp add: total_def)\n            thus ?thesis\n              unfolding Adm_def\n              by blast\n          qed\n        moreover \n        note BSIA1\n        ultimately obtain  \\<alpha>1''\n          where one: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n          and two:   \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n          and three: \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n          unfolding BSIA_def\n          by blast\n\n        from one validES1 have \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n          by (simp add: ES_valid_def traces_contain_events_def, auto)\n        moreover\n        have \"set [] \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n          by auto\n        moreover\n        from one c_in_E1 v'_notin_E1 \n        have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [] @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n          by (simp add: projection_def)\n        moreover \n        note two three\n        ultimately have ?ALPHA1''_DELTA1''\n          by blast\n      }\n      moreover {\n        assume c_in_E1: \"c \\<in> E\\<^bsub>ES1\\<^esub>\"\n          and  v'_in_E1: \"v' \\<in> E\\<^bsub>ES1\\<^esub>\"\n\n        from c_in_E1 c_in_Cv_inter_Upsilon propSepViews\n          Upsilon_inter_E1_subset_Upsilon1\n        have c_in_Cv1_inter_Upsilon1: \"c \\<in> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n          unfolding properSeparationOfViews_def by auto\n        moreover\n        from v'_in_E1 propSepViews v'_in_Vv_inter_Nabla Nabla_inter_E1_subset_Nabla1\n        have \"v' \\<in> V\\<^bsub>\\<V>1\\<^esub> \\<inter> Nabla \\<Gamma>1\"\n         unfolding properSeparationOfViews_def by auto\n        moreover\n        from v'_in_E1  \\<beta>v'E1\\<alpha>1'_in_Tr1 have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [v'] @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n          by (simp add: projection_def)\n        moreover\n        note \\<alpha>1'Cv1_empty FCI1\n        ultimately obtain \\<alpha>1'' \\<delta>1''\n          where one: \"set \\<delta>1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n          and two: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] @ \\<delta>1'' @ [v'] @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n          and three: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n          and four: \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n          unfolding FCI_def\n          by blast\n\n        from two validES1 have \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n          by (simp add: ES_valid_def traces_contain_events_def, auto)\n        moreover\n        note one\n        moreover\n        from two c_in_E1 v'_in_E1 \n        have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta>1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n          by (simp add: projection_def)\n        moreover\n        note three four\n        ultimately have ?ALPHA1''_DELTA1''\n          by blast\n      }\n      ultimately obtain \\<alpha>1'' \\<delta>1''\n        where \\<alpha>1''_in_E1star: \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n        and \\<delta>1''_in_N1_inter_Delta1star:\"set \\<delta>1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n        and \\<beta>E1_cE1_\\<delta>1''_v'E1_\\<alpha>1''_in_Tr1: \n        \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta>1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n        and \\<alpha>1''Vv1_is_\\<alpha>1'Vv1: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n        and \\<alpha>1''Cv1_empty: \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n        by blast\n\n      from c_in_Cv_inter_Upsilon Upsilon_inter_E2_subset_Upsilon2 propSepViews \n      have cE2_in_Cv2_inter_Upsilon2: \"set ([c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n        unfolding properSeparationOfViews_def by (simp add: projection_def, auto)\n     \n      from \\<delta>1''_in_N1_inter_Delta1star Nv1_inter_Delta1_inter_E2_subsetof_Upsilon2 \n        propSepViews disjoint_Nv1_Vv2 \n      have \\<delta>1''E2_in_Cv2_inter_Upsilon2star: \"set (\\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n        proof -\n          from \\<delta>1''_in_N1_inter_Delta1star have eq: \"\\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>1'' \\<upharpoonleft> (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub>)\"\n            by (metis Int_commute Int_left_commute Int_lower2 Int_lower1 \n              projection_intersection_neutral subset_trans)\n          \n          from validV2 Nv1_inter_Delta1_inter_E2_subsetof_Upsilon2 \n           propSepViews disjoint_Nv1_Vv2  \n          have \"N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n            unfolding properSeparationOfViews_def\n            by (simp add: isViewOn_def V_valid_def VC_disjoint_def \n              VN_disjoint_def NC_disjoint_def, auto)\n          thus ?thesis\n            by (subst eq, simp only: projection_def, auto)\n        qed\n      \n      have c\\<delta>1''E2_in_Cv2_inter_Upsilon2star: \"set ((c # \\<delta>1'') \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n        proof -\n          from cE2_in_Cv2_inter_Upsilon2 \\<delta>1''E2_in_Cv2_inter_Upsilon2star\n          have \"set (([c] @ \\<delta>1'') \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n            by (simp only: projection_concatenation_commute, auto)\n          thus ?thesis\n            by auto\n        qed\n\n\n      have \"\\<exists> \\<alpha>2'' \\<delta>2''. set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>        \n        \\<and> set \\<delta>2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>        \n        \\<and> \\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta>2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>        \n        \\<and> \\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> \\<and> \\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\n        \\<and> \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n        proof cases\n          assume v'_in_E2: \"v' \\<in> E\\<^bsub>ES2\\<^esub>\"\n          with Nabla_inter_E2_subset_Nabla2 \n            propSepViews v'_in_Vv_inter_Nabla\n          have v'_in_Vv2_inter_Nabla2: \"v' \\<in> V\\<^bsub>\\<V>2\\<^esub> \\<inter> Nabla \\<Gamma>2\"\n            unfolding properSeparationOfViews_def by auto\n\n          have \"\\<lbrakk> (\\<beta> @ [v']) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub> ; \n            \\<alpha>2' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []; set ((c # \\<delta>1'') \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> ; \n            c \\<in> C\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub> ; set \\<delta>1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<rbrakk> \n            \\<Longrightarrow> \\<exists> \\<alpha>2'' \\<delta>2''. (set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub> \\<and> set \\<delta>2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \n              \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>            \n            \\<and> \\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta>2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>            \n            \\<and> \\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> \\<and> \\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\n            \\<and> \\<delta>2'' \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>) = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>)\"\n            proof (induct \"length ((c # \\<delta>1'') \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>)\" arbitrary: \\<beta> \\<alpha>2' c \\<delta>1'')\n              case 0\n\n              from 0(2) validES2 have \"set \\<alpha>2' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n                by (simp add: ES_valid_def traces_contain_events_def, auto)\n              moreover\n              have \"set [] \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                by auto\n              moreover\n              have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [] @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                proof -\n                  note 0(2)\n                  moreover\n                  from 0(1) have \"c \\<notin> E\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: projection_def, auto)\n                  ultimately show ?thesis\n                    by (simp add: projection_concatenation_commute projection_def)\n                qed\n              moreover\n              have \"\\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\" ..\n              moreover\n              note 0(3)\n              moreover \n              from 0(1) have \"[] \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>) = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                by (simp add: projection_def, split if_split_asm, auto)\n              ultimately show ?case\n                by blast\n            next\n              case (Suc n)\n\n              from projection_split_last[OF Suc(2)] obtain \\<mu> c' \\<nu>\n                where c'_in_E2: \"c' \\<in> E\\<^bsub>ES2\\<^esub>\"\n                and c\\<delta>1''_is_\\<mu>c'\\<nu>: \"c # \\<delta>1'' = \\<mu> @ [c'] @ \\<nu>\"\n                and \\<nu>E2_empty: \"\\<nu> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = []\"\n                and n_is_length_\\<mu>\\<nu>E2: \"n = length ((\\<mu> @ \\<nu>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>)\"\n                by blast\n\n              from Suc(5) c'_in_E2 c\\<delta>1''_is_\\<mu>c'\\<nu> \n              have \"set (\\<mu> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c']) \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                by (simp only: c\\<delta>1''_is_\\<mu>c'\\<nu> projection_concatenation_commute \n                  projection_def, auto)\n              hence c'_in_Cv2_inter_Upsilon2: \"c' \\<in> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                by auto\n              hence c'_in_Cv2: \"c' \\<in> C\\<^bsub>\\<V>2\\<^esub>\" and c'_in_Upsilon2: \"c' \\<in> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                by auto\n              with validV2 have c'_in_E2: \"c' \\<in> E\\<^bsub>ES2\\<^esub>\"\n                by (simp add: isViewOn_def V_valid_def VC_disjoint_def \n                  VN_disjoint_def NC_disjoint_def, auto)\n\n              show ?case\n                proof (cases \\<mu>)\n                  case Nil (* we apply FCI in this case *)\n                  with c\\<delta>1''_is_\\<mu>c'\\<nu> have c_is_c': \"c = c'\" and \\<delta>1''_is_\\<nu>: \"\\<delta>1'' = \\<nu>\"\n                    by auto\n                  with c'_in_Cv2_inter_Upsilon2 have \"c \\<in> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    by simp\n                  moreover\n                  note v'_in_Vv2_inter_Nabla2\n                  moreover\n                  from v'_in_E2 Suc(3) have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ [v'] @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: projection_concatenation_commute projection_def)\n                  moreover\n                  note Suc(4) FCI2\n                  ultimately obtain \\<alpha>2'' \\<gamma>\n                    where one: \"set \\<gamma> \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    and two: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] @ \\<gamma> @ [v'] @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    and three: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n                    and four: \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n                    unfolding FCI_def\n                    by blast\n\n                  (* we choose \\<delta>2'' = \\<nu> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<gamma> *)\n                  let ?DELTA2'' = \"\\<nu> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<gamma>\"\n\n                  from two validES2 have \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: ES_valid_def traces_contain_events_def, auto)\n                  moreover\n                  from one \\<nu>E2_empty\n                  have \"set ?DELTA2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    by auto\n                  moreover\n                  have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ ?DELTA2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    proof -\n                      from c_is_c' c'_in_E2 have \"[c] = [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                        by (simp add: projection_def)\n                      moreover\n                      from v'_in_E2 have \"[v'] = [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                        by (simp add: projection_def)\n                      moreover\n                      note \\<nu>E2_empty two\n                      ultimately show ?thesis\n                        by auto\n                    qed\n                  moreover\n                  note three four\n                  moreover\n                  have \"?DELTA2'' \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>) = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                    proof -\n                      have \"\\<gamma> \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>) = []\"\n                        proof -\n                          from validV2 have \"N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>) = {}\"\n                            by (simp add: isViewOn_def V_valid_def\n                              VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n                          with projection_intersection_neutral[OF one, of \"C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"]\n                          show ?thesis\n                            by (simp add: projection_def)\n                        qed\n                      with \\<delta>1''_is_\\<nu> \\<nu>E2_empty show ?thesis\n                        by (simp add: projection_concatenation_commute)\n                    qed\n                  ultimately show ?thesis\n                    by blast\n                next\n                  case (Cons x xs) (* we apply the inductive hypothesis in this case *)\n                  with c\\<delta>1''_is_\\<mu>c'\\<nu> have \\<mu>_is_c_xs: \"\\<mu> = [c] @ xs\" \n                    and \\<delta>1''_is_xs_c'_\\<nu>: \"\\<delta>1'' = xs @ [c'] @ \\<nu>\"\n                    by auto\n                  with n_is_length_\\<mu>\\<nu>E2 have \"n = length ((c # (xs @ \\<nu>)) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>)\"\n                    by auto\n                  moreover\n                  note Suc(3,4)\n                  moreover\n                  have \"set ((c # (xs @ \\<nu>)) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    proof -\n                      have res: \"c # (xs @ \\<nu>) = [c] @ (xs @ \\<nu>)\" \n                        by auto\n\n                      from Suc(5) c\\<delta>1''_is_\\<mu>c'\\<nu> \\<mu>_is_c_xs \\<nu>E2_empty\n                      show ?thesis\n                        by (subst res, simp only: c\\<delta>1''_is_\\<mu>c'\\<nu> \n                          projection_concatenation_commute set_append, auto)\n                    qed\n                  moreover\n                  note Suc(6) \n                  moreover\n                  from Suc(7) \\<delta>1''_is_xs_c'_\\<nu> have \"set (xs @ \\<nu>) \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    by auto\n                  moreover note Suc(1)[of c \"xs @ \\<nu>\" \\<beta> \\<alpha>2']\n                  ultimately obtain \\<delta> \\<gamma>\n                    where one: \"set \\<delta> \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n                    and two: \"set \\<gamma> \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    and three: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<gamma> @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta> \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    and four: \"\\<delta> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n                    and five: \"\\<delta> \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n                    and six: \"\\<gamma> \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>) = (xs @ \\<nu>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                    by blast\n\n                  (* apply FCI to insert c' after \\<gamma> *)\n                  let ?BETA = \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<gamma>\"\n\n                  note c'_in_Cv2_inter_Upsilon2 v'_in_Vv2_inter_Nabla2\n                  moreover\n                  from three v'_in_E2 have \"?BETA @ [v'] @ \\<delta> \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: projection_def)\n                  moreover\n                  note five FCI2\n                  ultimately obtain \\<alpha>2'' \\<delta>'\n                    where fci_one: \"set \\<delta>' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    and fci_two: \"?BETA @ [c'] @ \\<delta>' @ [v'] @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    and fci_three: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<delta> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n                    and fci_four:  \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n                    unfolding FCI_def\n                    by blast\n  \n                  let ?DELTA2'' = \"\\<gamma> @ [c'] @ \\<delta>'\"\n\n                  from fci_two validES2 have \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: ES_valid_def traces_contain_events_def, auto)\n                  moreover\n                  have \"set ?DELTA2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    proof -\n                      from Suc(7) c'_in_Cv2_inter_Upsilon2 \\<delta>1''_is_xs_c'_\\<nu> \n                      have \"c' \\<in>  C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                        by auto\n                      with two fci_one show ?thesis\n                        by auto\n                    qed\n                  moreover\n                  from fci_two v'_in_E2 \n                  have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ ?DELTA2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: projection_def)\n                  moreover\n                  from fci_three four have \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n                    by simp\n                  moreover\n                  note fci_four\n                  moreover             \n                  have \"?DELTA2'' \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>) = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                    proof -\n                      have \"\\<delta>' \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>) = []\"\n                        proof -\n                          from fci_one have \"\\<forall> e \\<in> set \\<delta>'. e \\<in> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                            by auto\n                          with validV2 have \"\\<forall> e \\<in> set \\<delta>'. e \\<notin> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                            by (simp add: isViewOn_def V_valid_def\n                              VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n                          thus ?thesis\n                            by (simp add: projection_def)\n                        qed\n                      with c'_in_E2 c'_in_Cv2_inter_Upsilon2 \\<delta>1''_is_xs_c'_\\<nu> \\<nu>E2_empty six \n                      show ?thesis\n                        by (simp only: projection_concatenation_commute projection_def, auto)\n                    qed\n                  ultimately show ?thesis \n                    by blast     \n                qed\n          qed\n          from this[OF \\<beta>v'E2\\<alpha>2'_in_Tr2 \\<alpha>2'Cv2_empty c\\<delta>1''E2_in_Cv2_inter_Upsilon2star \n            c_in_Cv_inter_Upsilon \\<delta>1''_in_N1_inter_Delta1star]\n          obtain \\<alpha>2'' \\<delta>2''\n            where one: \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n            and two: \"set \\<delta>2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n            and three: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta>2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>            \n            \\<and> \\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> \\<and> \\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n            and four: \"\\<delta>2'' \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>) = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n            by blast\n\n          note one two three\n          moreover\n          have \"\\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\" \n            proof -\n              from projection_intersection_neutral[OF two, of \"E\\<^bsub>ES1\\<^esub>\"] \n                Nv2_inter_Delta2_inter_E1_empty validV1 \n              have \"\\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>2'' \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub>)\"\n                by (simp only: Int_Un_distrib2, auto)\n              moreover\n              from validV1 \n              have \"C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> = C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                by (simp add: isViewOn_def V_valid_def VC_disjoint_def \n                  VN_disjoint_def NC_disjoint_def, auto)\n              ultimately have \"\\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>2'' \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>)\"\n                by simp\n              hence \"\\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>2'' \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>) \\<upharpoonleft> (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>)\"\n                by (simp add: projection_def)\n              with four have \"\\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>)\"\n                by simp\n              hence \"\\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1'' \\<upharpoonleft> (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                by (simp only: projection_commute)\n              with \\<delta>1''_in_N1_inter_Delta1star show ?thesis\n                by (simp only: list_subset_iff_projection_neutral)\n            qed\n          ultimately show ?thesis\n              by blast\n        next\n          assume v'_notin_E2: \"v' \\<notin> E\\<^bsub>ES2\\<^esub>\"\n\n          have \n            \"\\<lbrakk> (\\<beta> @ [v']) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub> ; \\<alpha>2' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []; \n                set ((c # \\<delta>1'') \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> ; c \\<in> C\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub> ;\n                set \\<delta>1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<rbrakk> \n            \\<Longrightarrow> \\<exists> \\<alpha>2'' \\<delta>2''.\n             (set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub> \\<and> set \\<delta>2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>            \n             \\<and> \\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta>2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2 \\<^esub>            \n             \\<and> \\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> \\<and> \\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\n            \\<and> \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>)\"\n            proof (induct \"length ((c # \\<delta>1'') \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>)\" arbitrary: \\<beta> \\<alpha>2' c \\<delta>1'')\n               case 0\n\n              from 0(2) validES2 have \"set \\<alpha>2' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n                by (simp add: ES_valid_def traces_contain_events_def, auto)\n              moreover\n              have \"set [] \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                by auto\n              moreover\n              have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [] @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                proof -\n                  note 0(2)\n                  moreover\n                  from 0(1) have \"c \\<notin> E\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: projection_def, auto)\n                  ultimately show ?thesis\n                    by (simp add: projection_concatenation_commute projection_def)\n                qed\n              moreover\n              have \"\\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\" ..\n              moreover\n              note 0(3)\n              moreover \n              from 0(1) have \"[] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                by (simp add: projection_def, split if_split_asm, auto)\n              ultimately show ?case\n                by blast\n            next\n              case (Suc n)\n\n              from projection_split_last[OF Suc(2)] obtain \\<mu> c' \\<nu>\n                where c'_in_E2: \"c' \\<in> E\\<^bsub>ES2\\<^esub>\"\n                and c\\<delta>1''_is_\\<mu>c'\\<nu>: \"c # \\<delta>1'' = \\<mu> @ [c'] @ \\<nu>\"\n                and \\<nu>E2_empty: \"\\<nu> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = []\"\n                and n_is_length_\\<mu>\\<nu>E2: \"n = length ((\\<mu> @ \\<nu>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>)\"\n                by blast\n\n              from Suc(5) c'_in_E2 c\\<delta>1''_is_\\<mu>c'\\<nu> have \"set (\\<mu> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c']) \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                by (simp only: c\\<delta>1''_is_\\<mu>c'\\<nu> projection_concatenation_commute projection_def, auto)\n              hence c'_in_Cv2_inter_Upsilon2: \"c' \\<in> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                by auto\n              hence c'_in_Cv2: \"c' \\<in> C\\<^bsub>\\<V>2\\<^esub>\" and c'_in_Upsilon2: \"c' \\<in> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                by auto\n              with validV2 have c'_in_E2: \"c' \\<in> E\\<^bsub>ES2\\<^esub>\"\n                by (simp add: isViewOn_def V_valid_def VC_disjoint_def\n                  VN_disjoint_def NC_disjoint_def, auto)\n\n              show ?case\n                proof (cases \\<mu>)\n                  case Nil (* we just apply BSIA in this case *)\n                  with c\\<delta>1''_is_\\<mu>c'\\<nu> have c_is_c': \"c = c'\" and \\<delta>1''_is_\\<nu>: \"\\<delta>1'' = \\<nu>\"\n                    by auto\n                  with c'_in_Cv2_inter_Upsilon2 have \"c \\<in> C\\<^bsub>\\<V>2\\<^esub>\"\n                    by simp\n                  moreover\n                  from v'_notin_E2 Suc(3) have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: projection_concatenation_commute projection_def)\n                  moreover\n                  note Suc(4)\n                  moreover\n                  have \"Adm \\<V>2 \\<rho>2 Tr\\<^bsub>ES2\\<^esub> (\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) c\"\n                    proof -\n                      have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                        proof -\n                          from c_is_c' c'_in_Cv2_inter_Upsilon2 have \"c \\<in> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                            by simp\n                          moreover\n                          from validES2 Suc(3) have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                            by (simp only: ES_valid_def traces_prefixclosed_def\n                              projection_concatenation_commute \n                              prefixclosed_def prefix_def, auto)\n                          moreover\n                          note total_ES2_C2_inter_Upsilon2\n                          ultimately show ?thesis\n                            unfolding total_def\n                            by blast\n                        qed\n                      thus ?thesis\n                        unfolding Adm_def\n                        by blast                        \n                    qed\n                  moreover\n                  note BSIA2\n                  ultimately obtain \\<alpha>2''\n                    where one: \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ [c] @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    and two: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n                    and three: \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n                    unfolding BSIA_def\n                    by blast\n\n                  let ?DELTA2'' = \"\\<nu> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n\n                  from one validES2 have \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: ES_valid_def traces_contain_events_def, auto)\n                  moreover\n                  from \\<nu>E2_empty\n                  have \"set ?DELTA2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    by simp\n                  moreover\n                  from c_is_c' c'_in_E2 one v'_notin_E2 \\<nu>E2_empty\n                  have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ ?DELTA2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: projection_def)\n                  moreover\n                  note two three\n                  moreover\n                  from \\<nu>E2_empty \\<delta>1''_is_\\<nu> have \"?DELTA2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: projection_def)\n                  ultimately show ?thesis\n                    by blast\n                next\n                  case (Cons x xs) (* apply inductive hypothesis, then BSIA *)\n                   with c\\<delta>1''_is_\\<mu>c'\\<nu> have \\<mu>_is_c_xs: \"\\<mu> = [c] @ xs\" \n                     and \\<delta>1''_is_xs_c'_\\<nu>: \"\\<delta>1'' = xs @ [c'] @ \\<nu>\"\n                    by auto\n                  with n_is_length_\\<mu>\\<nu>E2 have \"n = length ((c # (xs @ \\<nu>)) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>)\"\n                    by auto\n                  moreover\n                  note Suc(3,4)\n                  moreover\n                  have \"set ((c # (xs @ \\<nu>)) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    proof -\n                      have res: \"c # (xs @ \\<nu>) = [c] @ (xs @ \\<nu>)\" \n                        by auto\n\n                      from Suc(5) c\\<delta>1''_is_\\<mu>c'\\<nu> \\<mu>_is_c_xs \\<nu>E2_empty\n                      show ?thesis\n                        by (subst res, simp only: c\\<delta>1''_is_\\<mu>c'\\<nu> projection_concatenation_commute \n                          set_append, auto)\n                    qed\n                  moreover\n                  note Suc(6) \n                  moreover\n                  from Suc(7) \\<delta>1''_is_xs_c'_\\<nu> have \"set (xs @ \\<nu>) \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    by auto\n                  moreover note Suc(1)[of c \"xs @ \\<nu>\" \\<beta> \\<alpha>2']\n                  ultimately obtain \\<delta> \\<gamma>\n                    where one: \"set \\<delta> \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n                    and two: \"set \\<gamma> \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    and three: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<gamma> @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta> \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    and four: \"\\<delta> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n                    and five: \"\\<delta> \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n                    and six: \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = (xs @ \\<nu>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                    by blast\n                  \n                   (* apply BSIA to insert c' after \\<gamma> *)\n                  let ?BETA = \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<gamma>\"\n\n                  from c'_in_Cv2_inter_Upsilon2 have \"c' \\<in> C\\<^bsub>\\<V>2\\<^esub>\"\n                    by auto\n                  moreover\n                  from three v'_notin_E2 have \"?BETA @ \\<delta> \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: projection_def)\n                  moreover\n                  note five \n                  moreover\n                  have \"Adm \\<V>2 \\<rho>2 Tr\\<^bsub>ES2\\<^esub> ?BETA c'\"\n                    proof -\n                      have \"?BETA @ [c'] \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                        proof -\n                          from validES2 three have \"?BETA \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                            by (simp only: ES_valid_def traces_prefixclosed_def\n                              projection_concatenation_commute prefixclosed_def prefix_def, auto)\n                          moreover\n                          note c'_in_Cv2_inter_Upsilon2 total_ES2_C2_inter_Upsilon2\n                          ultimately show ?thesis\n                            unfolding total_def\n                            by blast\n                        qed\n                      thus ?thesis\n                        unfolding Adm_def\n                        by blast                        \n                    qed\n                  moreover\n                  note BSIA2\n                  ultimately obtain \\<alpha>2''\n                    where bsia_one: \"?BETA @ [c'] @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    and bsia_two: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<delta> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n                    and bsia_three:  \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n                    unfolding BSIA_def\n                    by blast\n  \n                  let ?DELTA2'' = \"\\<gamma> @ [c']\"\n\n                  from bsia_one validES2 have \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: ES_valid_def traces_contain_events_def, auto)\n                  moreover\n                  have \"set ?DELTA2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    proof -\n                      from Suc(7) c'_in_Cv2_inter_Upsilon2 \\<delta>1''_is_xs_c'_\\<nu> \n                      have \"c' \\<in>  C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                        by auto\n                      with two show ?thesis\n                        by auto\n                    qed\n                  moreover\n                  from bsia_one v'_notin_E2 \n                  have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ ?DELTA2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: projection_def)\n                  moreover\n                  from bsia_two four have \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n                    by simp\n                  moreover\n                  note bsia_three\n                  moreover             \n                  have \"?DELTA2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                    proof -\n                      from validV1 Suc(7) \\<delta>1''_is_xs_c'_\\<nu> have \"c' \\<in> E\\<^bsub>ES1\\<^esub>\"\n                        by (simp add: isViewOn_def V_valid_def\n                          VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n                      with c'_in_E2 c'_in_Cv2_inter_Upsilon2 \\<delta>1''_is_xs_c'_\\<nu> \\<nu>E2_empty six \n                      show ?thesis\n                        by (simp only: projection_concatenation_commute \n                          projection_def, auto)\n                    qed\n                  ultimately show ?thesis \n                    by blast     \n                qed\n            qed\n          from this[OF \\<beta>v'E2\\<alpha>2'_in_Tr2 \\<alpha>2'Cv2_empty c\\<delta>1''E2_in_Cv2_inter_Upsilon2star \n            c_in_Cv_inter_Upsilon \\<delta>1''_in_N1_inter_Delta1star]\n          show ?thesis \n            by blast\n        qed\n      then obtain \\<alpha>2'' \\<delta>2''\n        where \\<alpha>2''_in_E2star: \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n        and \\<delta>2''_in_N2_inter_Delta2star:\"set \\<delta>2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n        and \\<beta>E2_cE2_\\<delta>2''_v'E2_\\<alpha>2''_in_Tr2: \n        \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta>2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n        and \\<alpha>2''Vv2_is_\\<alpha>2'Vv2: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n        and \\<alpha>2''Cv2_empty: \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n        and \\<delta>2''E1_is_\\<delta>1''E2: \"\\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n        by blast\n\n      from \\<beta>E2_cE2_\\<delta>2''_v'E2_\\<alpha>2''_in_Tr2 \\<beta>E1_cE1_\\<delta>1''_v'E1_\\<alpha>1''_in_Tr1 \n        validES2 validES1\n      have \\<delta>2''_in_E2star: \"set \\<delta>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\" and \\<delta>1''_in_E1star: \"set \\<delta>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n        by (simp_all add: ES_valid_def traces_contain_events_def, auto)\n      with \\<delta>2''E1_is_\\<delta>1''E2 merge_property[of \\<delta>2'' \"E\\<^bsub>ES2\\<^esub>\" \\<delta>1'' \"E\\<^bsub>ES1\\<^esub>\"] obtain \\<delta>'\n        where \\<delta>'E2_is_\\<delta>2'': \"\\<delta>' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2''\"\n        and \\<delta>'E1_is_\\<delta>1'': \"\\<delta>' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1''\"\n        and \\<delta>'_contains_only_\\<delta>2''_\\<delta>1''_events: \"set \\<delta>' \\<subseteq> set \\<delta>2'' \\<union> set \\<delta>1''\"\n        unfolding Let_def\n        by auto\n\n      let ?TAU = \"\\<beta> @ [c] @ \\<delta>' @ [v']\"\n      let ?LAMBDA = \"\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n      let ?T2 = \\<alpha>2''\n      let ?T1 = \\<alpha>1''\n\n     (* apply the generalized zipping lemma *)\n     have \"?TAU \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n        proof -\n          from \\<beta>E2_cE2_\\<delta>2''_v'E2_\\<alpha>2''_in_Tr2 \\<delta>'E2_is_\\<delta>2'' validES2 \n          have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta>' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n            by (simp add: ES_valid_def traces_prefixclosed_def\n              prefixclosed_def prefix_def)\n          hence \"(\\<beta> @ [c] @ \\<delta>' @ [v']) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n            by (simp add: projection_def, auto)\n          moreover          \n          from \\<beta>E1_cE1_\\<delta>1''_v'E1_\\<alpha>1''_in_Tr1 \\<delta>'E1_is_\\<delta>1'' validES1 \n          have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta>' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n            by (simp add: ES_valid_def traces_prefixclosed_def\n              prefixclosed_def prefix_def)\n          hence \"(\\<beta> @ [c] @ \\<delta>' @ [v']) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n            by (simp add: projection_def, auto)\n          moreover\n          from \\<beta>v'\\<alpha>_in_Tr c_in_Cv_inter_Upsilon VIsViewOnE \\<delta>'_contains_only_\\<delta>2''_\\<delta>1''_events \n            \\<delta>2''_in_E2star \\<delta>1''_in_E1star\n          have \"set (\\<beta> @ [c] @ \\<delta>' @ [v']) \\<subseteq> E\\<^bsub>ES2\\<^esub> \\<union> E\\<^bsub>ES1\\<^esub>\"\n            unfolding composeES_def isViewOn_def V_valid_def VC_disjoint_def \n              VN_disjoint_def NC_disjoint_def\n            by auto\n          ultimately show ?thesis\n            unfolding composeES_def\n            by auto\n        qed \n      hence \"set ?TAU \\<subseteq> E\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n        unfolding composeES_def\n        by auto\n      moreover\n      have \"set ?LAMBDA \\<subseteq> V\\<^bsub>\\<V>\\<^esub>\"\n        by (simp add: projection_def, auto)\n      moreover\n      note \\<alpha>2''_in_E2star \\<alpha>1''_in_E1star\n      moreover\n      from \\<beta>E2_cE2_\\<delta>2''_v'E2_\\<alpha>2''_in_Tr2 \\<delta>'E2_is_\\<delta>2'' \n      have \"?TAU \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ ?T2 \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n        by (simp only: projection_concatenation_commute, auto)\n      moreover\n      from \\<beta>E1_cE1_\\<delta>1''_v'E1_\\<alpha>1''_in_Tr1 \\<delta>'E1_is_\\<delta>1'' \n      have \"?TAU \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ ?T1 \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n        by (simp only: projection_concatenation_commute, auto)\n      moreover\n      have \"?LAMBDA \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = ?T2 \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n        proof -\n          from propSepViews \n          have \"?LAMBDA \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n            unfolding properSeparationOfViews_def  by (simp only: projection_sequence)\n          moreover\n          from \\<alpha>2''_in_E2star propSepViews\n          have \"?T2 \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = ?T2 \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n            unfolding properSeparationOfViews_def\n            by (metis Int_commute projection_intersection_neutral)\n          moreover\n          note \\<alpha>2'Vv2_is_\\<alpha>Vv2 \\<alpha>2''Vv2_is_\\<alpha>2'Vv2\n          ultimately show ?thesis\n            by simp\n        qed\n      moreover\n      have \"?LAMBDA \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = ?T1 \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n        proof -\n          from propSepViews\n          have \"?LAMBDA \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n            unfolding properSeparationOfViews_def  by (simp add: projection_sequence)\n          moreover\n          from \\<alpha>1''_in_E1star propSepViews\n          have \"?T1 \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = ?T1 \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n            unfolding properSeparationOfViews_def \n            by (metis Int_commute projection_intersection_neutral)\n          moreover\n          note \\<alpha>1'Vv1_is_\\<alpha>Vv1 \\<alpha>1''Vv1_is_\\<alpha>1'Vv1\n          ultimately show ?thesis\n            by simp\n        qed\n      moreover\n      note \\<alpha>2''Cv2_empty \\<alpha>1''Cv1_empty generalized_zipping_lemma\n      ultimately obtain t (* show that the conclusion of FCI holds *)\n        where \"?TAU @ t \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n        and  \"t \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = ?LAMBDA\"\n        and \"t \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = []\"\n        by blast\n      moreover\n      have \"set \\<delta>' \\<subseteq> N\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>\\<^esub>\"\n        proof -\n          from \\<delta>'_contains_only_\\<delta>2''_\\<delta>1''_events \\<delta>2''_in_N2_inter_Delta2star\n               \\<delta>1''_in_N1_inter_Delta1star\n          have \"set \\<delta>' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n            by auto\n          with Delta1_N1_Delta2_N2_subset_Delta Nv1_union_Nv2_subsetof_Nv show ?thesis\n            by auto\n        qed\n      ultimately have \"\\<exists>\\<alpha>' \\<gamma>'. (set \\<gamma>' \\<subseteq> N\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>\\<^esub> \\<and> \\<beta> @ [c] @ \\<gamma>' @ [v'] @ \\<alpha>' \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub> \n        \\<and> \\<alpha>' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> \\<and> \\<alpha>' \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = [])\"\n        by (simp only: append_assoc, blast)\n    }\n    ultimately have \"\\<exists>\\<alpha>' \\<gamma>'. (set \\<gamma>' \\<subseteq> N\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>\\<^esub> \\<and> \\<beta> @ [c] @ \\<gamma>' @ [v'] @ \\<alpha>' \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub> \n      \\<and> \\<alpha>' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> \\<and> \\<alpha>' \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = [])\"\n      by blast\n  }\n  thus ?thesis\n    unfolding FCI_def\n    by blast\nqed\n\n\n(* Theorem 6.4.1 case 6 *)\ntheorem compositionality_FCIA: \n  \"\\<lbrakk> BSD \\<V>1 Tr\\<^bsub>ES1\\<^esub>; BSD \\<V>2 Tr\\<^bsub>ES2\\<^esub>; BSIA \\<rho>1 \\<V>1 Tr\\<^bsub>ES1\\<^esub>; BSIA \\<rho>2 \\<V>2 Tr\\<^bsub>ES2\\<^esub>;\n  (\\<rho>1 \\<V>1) \\<subseteq> (\\<rho> \\<V>) \\<inter> E\\<^bsub>ES1\\<^esub>; (\\<rho>2 \\<V>2) \\<subseteq> (\\<rho> \\<V>) \\<inter> E\\<^bsub>ES2\\<^esub>;\n  total ES1 (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>); total ES2 (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>);\n  \\<nabla>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> \\<nabla>\\<^bsub>\\<Gamma>1\\<^esub>; \\<nabla>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> \\<nabla>\\<^bsub>\\<Gamma>2\\<^esub>;\n  \\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>; \\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>;\n  ( \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<union> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> ) \\<subseteq> \\<Delta>\\<^bsub>\\<Gamma>\\<^esub>;\n  (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> = {} \\<and> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>)\n  \\<or> ( N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> = {} \\<and> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>)  ;\n  FCIA \\<rho>1 \\<Gamma>1 \\<V>1 Tr\\<^bsub>ES1\\<^esub>; FCIA \\<rho>2 \\<Gamma>2 \\<V>2 Tr\\<^bsub>ES2\\<^esub> \\<rbrakk> \n  \\<Longrightarrow> FCIA \\<rho> \\<Gamma> \\<V> (Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>)\"\nproof -\n assume BSD1: \"BSD \\<V>1 Tr\\<^bsub>ES1\\<^esub>\" \n    and BSD2: \"BSD \\<V>2 Tr\\<^bsub>ES2\\<^esub>\"\n    and BSIA1: \"BSIA \\<rho>1 \\<V>1 Tr\\<^bsub>ES1\\<^esub>\"\n    and BSIA2: \"BSIA \\<rho>2 \\<V>2 Tr\\<^bsub>ES2\\<^esub>\"\n    and \\<rho>1v1_subset_\\<rho>v_inter_E1: \"(\\<rho>1 \\<V>1) \\<subseteq> (\\<rho> \\<V>) \\<inter> E\\<^bsub>ES1\\<^esub>\"\n    and \\<rho>2v2_subset_\\<rho>v_inter_E2: \"(\\<rho>2 \\<V>2) \\<subseteq> (\\<rho> \\<V>) \\<inter> E\\<^bsub>ES2\\<^esub>\"\n    and total_ES1_C1_inter_Upsilon1_inter_N2_inter_Delta2: \n     \"total ES1 (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>)\"\n    and total_ES2_C2_inter_Upsilon2_inter_N1_inter_Delta1: \n     \"total ES2 (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>)\"\n    and Nabla_inter_E1_subset_Nabla1: \"\\<nabla>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> \\<nabla>\\<^bsub>\\<Gamma>1\\<^esub>\"\n    and Nabla_inter_E2_subset_Nabla2: \"\\<nabla>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> \\<nabla>\\<^bsub>\\<Gamma>2\\<^esub>\"\n    and Upsilon_inter_E1_subset_Upsilon1: \"\\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n    and Upsilon_inter_E2_subset_Upsilon2: \"\\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n    and Delta1_N1_Delta2_N2_subset_Delta: \"( \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<union> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> ) \\<subseteq> \\<Delta>\\<^bsub>\\<Gamma>\\<^esub>\"\n    and very_long_asm: \"(N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> = {} \\<and> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>)\n    \\<or> ( N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> = {} \\<and> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>)\"\n    and FCIA1: \"FCIA \\<rho>1 \\<Gamma>1 \\<V>1 Tr\\<^bsub>ES1\\<^esub>\"\n    and FCIA2: \"FCIA \\<rho>2 \\<Gamma>2 \\<V>2 Tr\\<^bsub>ES2\\<^esub>\"\n\n  {\n    fix \\<alpha> \\<beta> c v'\n    assume c_in_Cv_inter_Upsilon: \"c \\<in> (C\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub>)\"\n      and v'_in_Vv_inter_Nabla: \"v' \\<in> (V\\<^bsub>\\<V>\\<^esub> \\<inter> \\<nabla>\\<^bsub>\\<Gamma>\\<^esub>)\"\n      and \\<beta>v'\\<alpha>_in_Tr: \"(\\<beta> @ [v'] @ \\<alpha>) \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\" \n      and \\<alpha>Cv_empty: \"\\<alpha> \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = []\"\n      and Adm: \"Adm \\<V> \\<rho> (Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>) \\<beta> c\"\n\n    interpret CSES1: CompositionSupport \"ES1\" \"\\<V>\" \"\\<V>1\"\n      using propSepViews unfolding properSeparationOfViews_def \n      by (simp add: CompositionSupport_def validES1 validV1)\n\n    interpret CSES2: CompositionSupport \"ES2\" \"\\<V>\" \"\\<V>2\"\n      using propSepViews unfolding properSeparationOfViews_def \n      by (simp add: CompositionSupport_def validES2 validV2)\n\n    from  \\<beta>v'\\<alpha>_in_Tr\n    have  \\<beta>v'\\<alpha>_E1_in_Tr1: \"(((\\<beta> @ [v']) @ \\<alpha>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n      and \\<beta>v'\\<alpha>_E2_in_Tr2: \"(((\\<beta> @ [v']) @ \\<alpha>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n      by (simp add: composeES_def)+    \n\n    from CSES1.BSD_in_subsystem2[OF \\<beta>v'\\<alpha>_E1_in_Tr1 BSD1] obtain \\<alpha>1'\n      where \\<beta>v'E1\\<alpha>1'_in_Tr1: \"(\\<beta> @ [v']) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n      and \\<alpha>1'Vv1_is_\\<alpha>Vv1: \"\\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n      and \\<alpha>1'Cv1_empty: \"\\<alpha>1' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n      by auto\n\n    from CSES2.BSD_in_subsystem2[OF \\<beta>v'\\<alpha>_E2_in_Tr2 BSD2] obtain \\<alpha>2'\n      where \\<beta>v'E2\\<alpha>2'_in_Tr2: \"(\\<beta> @ [v']) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n      and \\<alpha>2'Vv2_is_\\<alpha>Vv2: \"\\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n      and \\<alpha>2'Cv2_empty: \"\\<alpha>2' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n      by auto\n\n    note very_long_asm\n    moreover {\n      assume Nv1_inter_Delta1_inter_E2_empty: \"N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> = {}\" \n        and  Nv2_inter_Delta2_inter_E1_subsetof_Upsilon1: \"N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n\n      let ?ALPHA2''_DELTA2'' = \"\\<exists> \\<alpha>2'' \\<delta>2''. (\n        set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub> \\<and> set \\<delta>2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \n        \\<and> \\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta>2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>        \n        \\<and> \\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> \\<and> \\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = [])\"\n\n      from c_in_Cv_inter_Upsilon v'_in_Vv_inter_Nabla validV2\n      have \"c \\<notin> E\\<^bsub>ES2\\<^esub> \\<or> (c \\<in> E\\<^bsub>ES2\\<^esub> \\<and> v' \\<notin> E\\<^bsub>ES2\\<^esub>) \\<or> (c \\<in> E\\<^bsub>ES2\\<^esub> \\<and> v' \\<in> E\\<^bsub>ES2\\<^esub>)\"\n        by (simp add: V_valid_def isViewOn_def \n          VC_disjoint_def VN_disjoint_def NC_disjoint_def)\n      moreover {\n        assume c_notin_E2: \"c \\<notin> E\\<^bsub>ES2\\<^esub>\"\n\n        from validES2 \\<beta>v'E2\\<alpha>2'_in_Tr2 have \"set \\<alpha>2' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n          by (simp add: ES_valid_def traces_contain_events_def, auto)\n        moreover \n        have \"set [] \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n          by auto\n        moreover \n        from \\<beta>v'E2\\<alpha>2'_in_Tr2 c_notin_E2 \n        have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [] @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n          by (simp add: projection_def)\n        moreover\n        have \"\\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\" ..\n        moreover \n        note \\<alpha>2'Cv2_empty\n        ultimately have ?ALPHA2''_DELTA2''\n          by blast\n      }\n      moreover {\n        assume c_in_E2: \"c \\<in> E\\<^bsub>ES2\\<^esub>\"\n          and  v'_notin_E2: \"v' \\<notin> E\\<^bsub>ES2\\<^esub>\"\n\n        from c_in_E2 c_in_Cv_inter_Upsilon propSepViews\n          Upsilon_inter_E2_subset_Upsilon2\n        have c_in_Cv2_inter_Upsilon2: \"c \\<in> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n          unfolding properSeparationOfViews_def by auto\n        hence \"c \\<in> C\\<^bsub>\\<V>2\\<^esub>\"\n          by auto\n        moreover\n        from \\<beta>v'E2\\<alpha>2'_in_Tr2 v'_notin_E2 have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n          by (simp add: projection_def)\n        moreover\n        note \\<alpha>2'Cv2_empty\n        moreover\n        have \"Adm \\<V>2 \\<rho>2 Tr\\<^bsub>ES2\\<^esub> (\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) c\"\n        proof -\n          from Adm obtain \\<gamma>\n            where \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v: \"\\<gamma> \\<upharpoonleft> (\\<rho> \\<V>) = \\<beta> \\<upharpoonleft> (\\<rho> \\<V>)\"\n            and \\<gamma>c_in_Tr: \"(\\<gamma> @ [c]) \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n            unfolding Adm_def\n            by auto\n\n          from c_in_E2 \\<gamma>c_in_Tr have \"(\\<gamma> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ [c] \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n            by (simp add: projection_def composeES_def)\n          moreover\n          have \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (\\<rho>2 \\<V>2) = \\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (\\<rho>2 \\<V>2)\"\n          proof -\n            from \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v have \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (\\<rho> \\<V>) = \\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (\\<rho> \\<V>)\"\n              by (metis projection_commute)\n            with \\<rho>2v2_subset_\\<rho>v_inter_E2 have \"\\<gamma> \\<upharpoonleft> (\\<rho>2 \\<V>2) = \\<beta> \\<upharpoonleft> (\\<rho>2 \\<V>2)\"\n              by (metis Int_subset_iff \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v projection_subset_elim)\n            thus ?thesis\n              by (metis projection_commute)\n          qed\n          ultimately show ?thesis unfolding Adm_def\n            by auto\n        qed  \n        moreover \n        note BSIA2\n        ultimately obtain  \\<alpha>2''\n          where one: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n          and two:   \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n          and three: \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n          unfolding BSIA_def\n          by blast\n\n        from one validES2 have \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n          by (simp add: ES_valid_def traces_contain_events_def, auto)\n        moreover\n        have \"set [] \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n          by auto\n        moreover\n        from one c_in_E2 v'_notin_E2 \n        have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [] @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n          by (simp add: projection_def)\n        moreover \n        note two three\n        ultimately have ?ALPHA2''_DELTA2''\n          by blast\n      }\n      moreover {\n        assume c_in_E2: \"c \\<in> E\\<^bsub>ES2\\<^esub>\"\n          and  v'_in_E2: \"v' \\<in> E\\<^bsub>ES2\\<^esub>\"\n\n        from c_in_E2 c_in_Cv_inter_Upsilon propSepViews\n          Upsilon_inter_E2_subset_Upsilon2\n        have c_in_Cv2_inter_Upsilon2: \"c \\<in> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n          unfolding properSeparationOfViews_def by auto\n        moreover\n        from v'_in_E2 propSepViews v'_in_Vv_inter_Nabla Nabla_inter_E2_subset_Nabla2\n        have \"v' \\<in> V\\<^bsub>\\<V>2\\<^esub> \\<inter> Nabla \\<Gamma>2\"\n          unfolding properSeparationOfViews_def by auto\n        moreover\n        from v'_in_E2  \\<beta>v'E2\\<alpha>2'_in_Tr2 have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [v'] @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n          by (simp add: projection_def)\n        moreover\n        note \\<alpha>2'Cv2_empty \n        moreover\n        have \"Adm \\<V>2 \\<rho>2 Tr\\<^bsub>ES2\\<^esub> (\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) c\"\n        proof -\n          from Adm obtain \\<gamma>\n            where \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v: \"\\<gamma> \\<upharpoonleft> (\\<rho> \\<V>) = \\<beta> \\<upharpoonleft> (\\<rho> \\<V>)\"\n            and \\<gamma>c_in_Tr: \"(\\<gamma> @ [c]) \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n            unfolding Adm_def\n            by auto\n\n          from c_in_E2 \\<gamma>c_in_Tr have \"(\\<gamma> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ [c] \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n            by (simp add: projection_def composeES_def)\n          moreover\n          have \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (\\<rho>2 \\<V>2) = \\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (\\<rho>2 \\<V>2)\"\n          proof -\n            from \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v have \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (\\<rho> \\<V>) = \\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (\\<rho> \\<V>)\"\n              by (metis projection_commute)\n            with \\<rho>2v2_subset_\\<rho>v_inter_E2 have \"\\<gamma> \\<upharpoonleft> (\\<rho>2 \\<V>2) = \\<beta> \\<upharpoonleft> (\\<rho>2 \\<V>2)\"\n              by (metis Int_subset_iff \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v projection_subset_elim)\n            thus ?thesis\n              by (metis projection_commute)\n          qed\n          ultimately show ?thesis unfolding Adm_def\n            by auto\n        qed  \n        moreover\n        note FCIA2\n        ultimately obtain \\<alpha>2'' \\<delta>2''\n          where one: \"set \\<delta>2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n          and two: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] @ \\<delta>2'' @ [v'] @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n          and three: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n          and four: \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n          unfolding FCIA_def\n          by blast\n\n        from two validES2 have \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n          by (simp add: ES_valid_def traces_contain_events_def, auto)\n        moreover\n        note one\n        moreover\n        from two c_in_E2 v'_in_E2 \n        have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta>2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n          by (simp add: projection_def)\n        moreover\n        note three four\n        ultimately have ?ALPHA2''_DELTA2''\n          by blast\n      }\n      ultimately obtain \\<alpha>2'' \\<delta>2''\n        where \\<alpha>2''_in_E2star: \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n        and \\<delta>2''_in_N2_inter_Delta2star:\"set \\<delta>2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n        and \\<beta>E2_cE2_\\<delta>2''_v'E2_\\<alpha>2''_in_Tr2:\n              \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta>2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n        and \\<alpha>2''Vv2_is_\\<alpha>2'Vv2: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n        and \\<alpha>2''Cv2_empty: \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n        by blast\n\n      from c_in_Cv_inter_Upsilon Upsilon_inter_E1_subset_Upsilon1 propSepViews\n      have cE1_in_Cv1_inter_Upsilon1: \"set ([c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n        unfolding properSeparationOfViews_def by (simp add: projection_def, auto)\n     \n      from \\<delta>2''_in_N2_inter_Delta2star Nv2_inter_Delta2_inter_E1_subsetof_Upsilon1 \n       propSepViews disjoint_Nv2_Vv1 \n      have \\<delta>2''E1_in_Cv1_inter_Upsilon1star: \"set (\\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n        proof -\n          from \\<delta>2''_in_N2_inter_Delta2star\n          have eq: \"\\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>2'' \\<upharpoonleft> (N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub>)\"\n            by (metis Int_commute Int_left_commute Int_lower1 Int_lower2 \n              projection_intersection_neutral subset_trans)\n          \n          from validV1 Nv2_inter_Delta2_inter_E1_subsetof_Upsilon1 \n            propSepViews disjoint_Nv2_Vv1  \n          have \"N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n            unfolding properSeparationOfViews_def \n            by (simp add: isViewOn_def V_valid_def \n              VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n          thus ?thesis\n            by (subst eq, simp only: projection_def, auto)\n        qed\n      \n      have c\\<delta>2''E1_in_Cv1_inter_Upsilon1star: \"set ((c # \\<delta>2'') \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n        proof -\n          from cE1_in_Cv1_inter_Upsilon1 \\<delta>2''E1_in_Cv1_inter_Upsilon1star\n          have \"set (([c] @ \\<delta>2'') \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n            by (simp only: projection_concatenation_commute, auto)\n          thus ?thesis\n            by auto\n        qed\n\n\n        have \n        \"\\<exists> \\<alpha>1'' \\<delta>1''. set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub> \\<and> set \\<delta>1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>        \n        \\<and> \\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta>1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>        \n        \\<and> \\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> \\<and> \\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\n        \\<and> \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n        proof cases\n          assume v'_in_E1: \"v' \\<in> E\\<^bsub>ES1\\<^esub>\"\n          with Nabla_inter_E1_subset_Nabla1 propSepViews v'_in_Vv_inter_Nabla\n          have v'_in_Vv1_inter_Nabla1: \"v' \\<in> V\\<^bsub>\\<V>1\\<^esub> \\<inter> Nabla \\<Gamma>1\"\n            unfolding properSeparationOfViews_def by auto\n\n          have \"\\<lbrakk> (\\<beta> @ [v']) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub> ; \n            \\<alpha>1' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []; set ((c # \\<delta>2'') \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> ; \n            c \\<in> C\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub> ; set \\<delta>2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>;\n            Adm \\<V> \\<rho> (Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>) \\<beta> c \\<rbrakk> \n            \\<Longrightarrow> \\<exists> \\<alpha>1'' \\<delta>1''.\n            (set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub> \\<and> set \\<delta>1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>            \n            \\<and> \\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta>1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>            \n            \\<and> \\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> \\<and> \\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\n            \\<and> \\<delta>1'' \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>) = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>)\"\n            proof (induct \"length ((c # \\<delta>2'') \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>)\" arbitrary: \\<beta> \\<alpha>1' c \\<delta>2'')\n              case 0\n\n              from 0(2) validES1 have \"set \\<alpha>1' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n                by (simp add: ES_valid_def traces_contain_events_def, auto)\n              moreover\n              have \"set [] \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                by auto\n              moreover\n              have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [] @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                proof -\n                  note 0(2)\n                  moreover\n                  from 0(1) have \"c \\<notin> E\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: projection_def, auto)\n                  ultimately show ?thesis\n                    by (simp add: projection_concatenation_commute projection_def)\n                qed\n              moreover\n              have \"\\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\" ..\n              moreover\n              note 0(3)\n              moreover \n              from 0(1) have \"[] \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>) = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                by (simp add: projection_def, split if_split_asm, auto)\n              ultimately show ?case\n                by blast\n            next\n              case (Suc n)\n\n              from projection_split_last[OF Suc(2)] obtain \\<mu> c' \\<nu>\n                where c'_in_E1: \"c' \\<in> E\\<^bsub>ES1\\<^esub>\"\n                and c\\<delta>2''_is_\\<mu>c'\\<nu>: \"c # \\<delta>2'' = \\<mu> @ [c'] @ \\<nu>\"\n                and \\<nu>E1_empty: \"\\<nu> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = []\"\n                and n_is_length_\\<mu>\\<nu>E1: \"n = length ((\\<mu> @ \\<nu>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>)\"\n                by blast\n\n              from Suc(5) c'_in_E1 c\\<delta>2''_is_\\<mu>c'\\<nu> have \"set (\\<mu> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c']) \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                by (simp only: c\\<delta>2''_is_\\<mu>c'\\<nu> projection_concatenation_commute \n                  projection_def, auto)\n              hence c'_in_Cv1_inter_Upsilon1: \"c' \\<in> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                by auto\n              hence c'_in_Cv1: \"c' \\<in> C\\<^bsub>\\<V>1\\<^esub>\" and c'_in_Upsilon1: \"c' \\<in> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                by auto\n              with validV1 have c'_in_E1: \"c' \\<in> E\\<^bsub>ES1\\<^esub>\"\n                by (simp add: isViewOn_def V_valid_def VC_disjoint_def \n                  VN_disjoint_def NC_disjoint_def, auto)\n\n              show ?case\n                proof (cases \\<mu>)\n                  case Nil (* we apply FCIA in this case *)\n                  with c\\<delta>2''_is_\\<mu>c'\\<nu> have c_is_c': \"c = c'\" and \\<delta>2''_is_\\<nu>: \"\\<delta>2'' = \\<nu>\"\n                    by auto\n                  with c'_in_Cv1_inter_Upsilon1 have \"c \\<in> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    by simp\n                  moreover\n                  note v'_in_Vv1_inter_Nabla1\n                  moreover\n                  from v'_in_E1 Suc(3) have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ [v'] @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: projection_concatenation_commute projection_def)\n                  moreover\n                  note Suc(4)\n                  moreover\n                  have \"Adm \\<V>1 \\<rho>1 Tr\\<^bsub>ES1\\<^esub> (\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) c\"\n                    proof -\n                      from Suc(8) obtain \\<gamma>\n                        where \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v: \"\\<gamma> \\<upharpoonleft> (\\<rho> \\<V>) = \\<beta> \\<upharpoonleft> (\\<rho> \\<V>)\"\n                        and \\<gamma>c_in_Tr: \"(\\<gamma> @ [c]) \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n                        unfolding Adm_def\n                        by auto\n\n                      from c_is_c' c'_in_E1 \\<gamma>c_in_Tr have \"(\\<gamma> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ [c] \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                        by (simp add: projection_def composeES_def)\n                      moreover\n                      have \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (\\<rho>1 \\<V>1) = \\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (\\<rho>1 \\<V>1)\"\n                      proof -\n                        from \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v have \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (\\<rho> \\<V>) = \\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (\\<rho> \\<V>)\"\n                          by (metis projection_commute)\n                        with \\<rho>1v1_subset_\\<rho>v_inter_E1 have \"\\<gamma> \\<upharpoonleft> (\\<rho>1 \\<V>1) = \\<beta> \\<upharpoonleft> (\\<rho>1 \\<V>1)\"\n                          by (metis Int_subset_iff \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v projection_subset_elim)\n                        thus ?thesis\n                          by (metis projection_commute)\n                      qed\n                      ultimately show ?thesis unfolding Adm_def\n                        by auto\n                    qed  \n                  moreover\n                  note FCIA1\n                  ultimately obtain \\<alpha>1'' \\<gamma>\n                    where one: \"set \\<gamma> \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    and two: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] @ \\<gamma> @ [v'] @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    and three: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n                    and four: \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n                    unfolding FCIA_def\n                    by blast\n\n                  (* we choose \\<delta>1'' = \\<nu> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<gamma> *)\n                  let ?DELTA1'' = \"\\<nu> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<gamma>\" \n                    \n                  from two validES1 have \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: ES_valid_def traces_contain_events_def, auto)\n                  moreover\n                  from one \\<nu>E1_empty\n                  have \"set ?DELTA1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    by auto\n                  moreover\n                  have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ ?DELTA1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    proof -\n                      from c_is_c' c'_in_E1 have \"[c] = [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                        by (simp add: projection_def)\n                      moreover\n                      from v'_in_E1 have \"[v'] = [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                        by (simp add: projection_def)\n                      moreover\n                      note \\<nu>E1_empty two\n                      ultimately show ?thesis\n                        by auto\n                    qed\n                  moreover\n                  note three four\n                  moreover\n                  have \"?DELTA1'' \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>) = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                    proof -\n                      have \"\\<gamma> \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>) = []\"\n                        proof -\n                          from validV1 have \"N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>) = {}\"\n                            by (simp add: isViewOn_def V_valid_def\n                              VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n                          with projection_intersection_neutral[OF one, of \"C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"]\n                          show ?thesis\n                            by (simp add: projection_def)\n                        qed\n                      with \\<delta>2''_is_\\<nu> \\<nu>E1_empty show ?thesis\n                        by (simp add: projection_concatenation_commute)\n                    qed\n                  ultimately show ?thesis\n                    by blast\n                next\n                  case (Cons x xs) (* we apply the inductive hypothesis in this case *)\n                  with c\\<delta>2''_is_\\<mu>c'\\<nu>\n                  have \\<mu>_is_c_xs: \"\\<mu> = [c] @ xs\" and \\<delta>2''_is_xs_c'_\\<nu>: \"\\<delta>2'' = xs @ [c'] @ \\<nu>\"\n                    by auto\n                  with n_is_length_\\<mu>\\<nu>E1 have \"n = length ((c # (xs @ \\<nu>)) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>)\"\n                    by auto\n                  moreover\n                  note Suc(3,4)\n                  moreover\n                  have \"set ((c # (xs @ \\<nu>)) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    proof -\n                      have res: \"c # (xs @ \\<nu>) = [c] @ (xs @ \\<nu>)\" \n                        by auto\n\n                      from Suc(5) c\\<delta>2''_is_\\<mu>c'\\<nu> \\<mu>_is_c_xs \\<nu>E1_empty\n                      show ?thesis\n                        by (subst res, simp only: c\\<delta>2''_is_\\<mu>c'\\<nu> \n                          projection_concatenation_commute set_append, auto)\n                    qed\n                  moreover\n                  note Suc(6) \n                  moreover\n                  from Suc(7) \\<delta>2''_is_xs_c'_\\<nu> have \"set (xs @ \\<nu>) \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    by auto\n                  moreover note Suc(8) Suc(1)[of c \"xs @ \\<nu>\" \\<beta> \\<alpha>1']\n                  ultimately obtain \\<delta> \\<gamma>\n                    where one: \"set \\<delta> \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n                    and two: \"set \\<gamma> \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    and three: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<gamma> @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta> \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    and four: \"\\<delta> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n                    and five: \"\\<delta> \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n                    and six: \"\\<gamma> \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>) = (xs @ \\<nu>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                    by blast\n\n                  (* apply FCIA to insert c' after \\<gamma> *)\n                  let ?BETA = \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<gamma>\"\n\n                  note c'_in_Cv1_inter_Upsilon1 v'_in_Vv1_inter_Nabla1\n                  moreover\n                  from three v'_in_E1 have \"?BETA @ [v'] @ \\<delta> \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: projection_def)\n                  moreover\n                  note five \n                  moreover\n                  have \"Adm \\<V>1 \\<rho>1 Tr\\<^bsub>ES1\\<^esub> ?BETA c'\"\n                    proof -\n                      have \"?BETA @ [c'] \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                        proof -\n                          from Suc(7) c'_in_Cv1_inter_Upsilon1 \\<delta>2''_is_xs_c'_\\<nu>\n                          have \"c' \\<in> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                            by auto\n                          moreover\n                          from validES1 three have \"?BETA \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                            by (unfold ES_valid_def traces_prefixclosed_def\n                              prefixclosed_def prefix_def, auto)\n                          moreover\n                          note total_ES1_C1_inter_Upsilon1_inter_N2_inter_Delta2\n                          ultimately show ?thesis\n                            unfolding total_def\n                            by blast\n                        qed\n                      thus ?thesis\n                        unfolding Adm_def\n                        by blast                        \n                    qed\n                  moreover\n                  note FCIA1\n                  ultimately obtain \\<alpha>1'' \\<delta>'\n                    where fcia_one: \"set \\<delta>' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    and fcia_two: \"?BETA @ [c'] @ \\<delta>' @ [v'] @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    and fcia_three: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<delta> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n                    and fcia_four:  \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n                    unfolding FCIA_def\n                    by blast\n  \n                  let ?DELTA1'' = \"\\<gamma> @ [c'] @ \\<delta>'\"\n\n                  from fcia_two validES1 have \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: ES_valid_def traces_contain_events_def, auto)\n                  moreover\n                  have \"set ?DELTA1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    proof -\n                      from Suc(7) c'_in_Cv1_inter_Upsilon1 \\<delta>2''_is_xs_c'_\\<nu> \n                      have \"c' \\<in>  C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                        by auto\n                      with two fcia_one show ?thesis\n                        by auto\n                    qed\n                  moreover\n                  from fcia_two v'_in_E1 \n                  have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ ?DELTA1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: projection_def)\n                  moreover\n                  from fcia_three four have \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n                    by simp\n                  moreover\n                  note fcia_four\n                  moreover             \n                  have \"?DELTA1'' \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>) = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                    proof -\n                      have \"\\<delta>' \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>) = []\"\n                        proof -\n                          from fcia_one have \"\\<forall> e \\<in> set \\<delta>'. e \\<in> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                            by auto\n                          with validV1 have \"\\<forall> e \\<in> set \\<delta>'. e \\<notin> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                            by (simp add: isViewOn_def V_valid_def \n                              VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n                          thus ?thesis\n                            by (simp add: projection_def)\n                        qed\n                      with c'_in_E1 c'_in_Cv1_inter_Upsilon1 \\<delta>2''_is_xs_c'_\\<nu> \\<nu>E1_empty six \n                      show ?thesis\n                        by (simp only: projection_concatenation_commute projection_def, auto)\n                    qed\n                  ultimately show ?thesis \n                    by blast     \n                qed\n          qed\n          from this[OF \\<beta>v'E1\\<alpha>1'_in_Tr1 \\<alpha>1'Cv1_empty c\\<delta>2''E1_in_Cv1_inter_Upsilon1star \n            c_in_Cv_inter_Upsilon \\<delta>2''_in_N2_inter_Delta2star Adm]\n          obtain \\<alpha>1'' \\<delta>1''\n            where one: \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n            and two: \"set \\<delta>1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n            and three: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta>1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>            \n            \\<and> \\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> \\<and> \\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n            and four: \"\\<delta>1'' \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>) = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n            by blast\n\n          note one two three\n          moreover\n          have \"\\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\" \n            proof -\n              from projection_intersection_neutral[OF two, of \"E\\<^bsub>ES2\\<^esub>\"] \n                Nv1_inter_Delta1_inter_E2_empty validV2 \n              have \"\\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>1'' \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub>)\"\n                by (simp only: Int_Un_distrib2, auto)\n              moreover\n              from validV2 \n              have \"C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> = C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                by (simp add:isViewOn_def  V_valid_def  VC_disjoint_def \n                  VN_disjoint_def NC_disjoint_def, auto)\n              ultimately have \"\\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>1'' \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>)\"\n                by simp\n              hence \"\\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>1'' \\<upharpoonleft> (C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>) \\<upharpoonleft> (N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>)\"\n                by (simp add: projection_def)\n              with four have \"\\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>)\"\n                by simp\n              hence \"\\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2'' \\<upharpoonleft> (N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                by (simp only: projection_commute)\n              with \\<delta>2''_in_N2_inter_Delta2star show ?thesis\n                by (simp only: list_subset_iff_projection_neutral)\n            qed\n          ultimately show ?thesis\n              by blast\n        next\n          assume v'_notin_E1: \"v' \\<notin> E\\<^bsub>ES1\\<^esub>\"\n\n           have \"\\<lbrakk> (\\<beta> @ [v']) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub> ; \n            \\<alpha>1' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []; set ((c # \\<delta>2'') \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> ; \n             c \\<in> C\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub> ; set \\<delta>2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>;\n            Adm \\<V> \\<rho> (Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>) \\<beta> c \\<rbrakk> \n            \\<Longrightarrow> \\<exists> \\<alpha>1'' \\<delta>1''. (set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub> \\<and> set \\<delta>1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \n             \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>            \n             \\<and> \\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta>1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>            \n             \\<and> \\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> \\<and> \\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\n            \\<and> \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>)\"\n            proof (induct \"length ((c # \\<delta>2'') \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>)\" arbitrary: \\<beta> \\<alpha>1' c \\<delta>2'')\n               case 0\n\n              from 0(2) validES1 have \"set \\<alpha>1' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n                by (simp add: ES_valid_def traces_contain_events_def, auto)\n              moreover\n              have \"set [] \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                by auto\n              moreover\n              have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [] @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                proof -\n                  note 0(2)\n                  moreover\n                  from 0(1) have \"c \\<notin> E\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: projection_def, auto)\n                  ultimately show ?thesis\n                    by (simp add: projection_concatenation_commute projection_def)\n                qed\n              moreover\n              have \"\\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\" ..\n              moreover\n              note 0(3)\n              moreover \n              from 0(1) have \"[] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                by (simp add: projection_def, split if_split_asm, auto)\n              ultimately show ?case\n                by blast\n            next\n              case (Suc n)\n\n              from projection_split_last[OF Suc(2)] obtain \\<mu> c' \\<nu>\n                where c'_in_E1: \"c' \\<in> E\\<^bsub>ES1\\<^esub>\"\n                and c\\<delta>2''_is_\\<mu>c'\\<nu>: \"c # \\<delta>2'' = \\<mu> @ [c'] @ \\<nu>\"\n                and \\<nu>E1_empty: \"\\<nu> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = []\"\n                and n_is_length_\\<mu>\\<nu>E1: \"n = length ((\\<mu> @ \\<nu>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>)\"\n                by blast\n\n              from Suc(5) c'_in_E1 c\\<delta>2''_is_\\<mu>c'\\<nu> have \"set (\\<mu> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c']) \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                by (simp only: c\\<delta>2''_is_\\<mu>c'\\<nu> projection_concatenation_commute projection_def, auto)\n              hence c'_in_Cv1_inter_Upsilon1: \"c' \\<in> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                by auto\n              hence c'_in_Cv1: \"c' \\<in> C\\<^bsub>\\<V>1\\<^esub>\" and c'_in_Upsilon1: \"c' \\<in> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                by auto\n              with validV1 have c'_in_E1: \"c' \\<in> E\\<^bsub>ES1\\<^esub>\"\n                by (simp add:isViewOn_def V_valid_def VC_disjoint_def \n                  VN_disjoint_def NC_disjoint_def, auto)\n\n              show ?case\n                proof (cases \\<mu>)\n                  case Nil (* we just apply BSIA in this case *)\n                  with c\\<delta>2''_is_\\<mu>c'\\<nu> have c_is_c': \"c = c'\" and \\<delta>2''_is_\\<nu>: \"\\<delta>2'' = \\<nu>\"\n                    by auto\n                  with c'_in_Cv1_inter_Upsilon1 have \"c \\<in> C\\<^bsub>\\<V>1\\<^esub>\"\n                    by simp\n                  moreover\n                  from v'_notin_E1 Suc(3) have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: projection_concatenation_commute projection_def)\n                  moreover\n                  note Suc(4)\n                  moreover\n                  have \"Adm \\<V>1 \\<rho>1 Tr\\<^bsub>ES1\\<^esub> (\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) c\"\n                     proof -\n                      from Suc(8) obtain \\<gamma>\n                        where \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v: \"\\<gamma> \\<upharpoonleft> (\\<rho> \\<V>) = \\<beta> \\<upharpoonleft> (\\<rho> \\<V>)\"\n                        and \\<gamma>c_in_Tr: \"(\\<gamma> @ [c]) \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n                        unfolding Adm_def\n                        by auto\n\n                      from c_is_c' c'_in_E1 \\<gamma>c_in_Tr have \"(\\<gamma> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ [c] \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                        by (simp add: projection_def composeES_def)\n                      moreover\n                      have \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (\\<rho>1 \\<V>1) = \\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (\\<rho>1 \\<V>1)\"\n                      proof -\n                        from \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v have \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (\\<rho> \\<V>) = \\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (\\<rho> \\<V>)\"\n                          by (metis projection_commute)\n                        with \\<rho>1v1_subset_\\<rho>v_inter_E1 have \"\\<gamma> \\<upharpoonleft> (\\<rho>1 \\<V>1) = \\<beta> \\<upharpoonleft> (\\<rho>1 \\<V>1)\"\n                          by (metis Int_subset_iff \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v projection_subset_elim)\n                        thus ?thesis\n                          by (metis projection_commute)\n                      qed\n                      ultimately show ?thesis unfolding Adm_def\n                        by auto\n                    qed  \n                  moreover\n                  note BSIA1\n                  ultimately obtain \\<alpha>1''\n                    where one: \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ [c] @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    and two: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n                    and three: \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n                    unfolding BSIA_def\n                    by blast\n\n                  let ?DELTA1'' = \"\\<nu> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n\n                  from one validES1 have \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: ES_valid_def traces_contain_events_def, auto)\n                  moreover\n                  from \\<nu>E1_empty\n                  have \"set ?DELTA1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    by simp\n                  moreover\n                  from c_is_c' c'_in_E1 one v'_notin_E1 \\<nu>E1_empty\n                  have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ ?DELTA1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: projection_def)\n                  moreover\n                  note two three\n                  moreover\n                  from \\<nu>E1_empty \\<delta>2''_is_\\<nu> have \"?DELTA1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: projection_def)\n                  ultimately show ?thesis\n                    by blast\n                next\n                  case (Cons x xs) (* apply inductive hypothesis, then BSIA *)\n                  with c\\<delta>2''_is_\\<mu>c'\\<nu>\n                  have \\<mu>_is_c_xs: \"\\<mu> = [c] @ xs\" and \\<delta>2''_is_xs_c'_\\<nu>: \"\\<delta>2'' = xs @ [c'] @ \\<nu>\"\n                    by auto\n                  with n_is_length_\\<mu>\\<nu>E1 have \"n = length ((c # (xs @ \\<nu>)) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>)\"\n                    by auto\n                  moreover\n                  note Suc(3,4)\n                  moreover\n                  have \"set ((c # (xs @ \\<nu>)) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    proof -\n                      have res: \"c # (xs @ \\<nu>) = [c] @ (xs @ \\<nu>)\" \n                        by auto\n\n                      from Suc(5) c\\<delta>2''_is_\\<mu>c'\\<nu> \\<mu>_is_c_xs \\<nu>E1_empty\n                      show ?thesis\n                        by (subst res, simp only: c\\<delta>2''_is_\\<mu>c'\\<nu> projection_concatenation_commute \n                          set_append, auto)\n                    qed\n                  moreover\n                  note Suc(6) \n                  moreover\n                  from Suc(7) \\<delta>2''_is_xs_c'_\\<nu> have \"set (xs @ \\<nu>) \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    by auto\n                  moreover note Suc(8) Suc(1)[of c \"xs @ \\<nu>\" \\<beta> \\<alpha>1']\n                  ultimately obtain \\<delta> \\<gamma>\n                    where one: \"set \\<delta> \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n                    and two: \"set \\<gamma> \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    and three: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<gamma> @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta> \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    and four: \"\\<delta> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n                    and five: \"\\<delta> \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n                    and six: \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = (xs @ \\<nu>) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                    by blast\n                  \n                   (* apply BSIA to insert c' after \\<gamma> *)\n                  let ?BETA = \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<gamma>\"\n\n                  from c'_in_Cv1_inter_Upsilon1 have \"c' \\<in> C\\<^bsub>\\<V>1\\<^esub>\"\n                    by auto\n                  moreover\n                  from three v'_notin_E1 have \"?BETA @ \\<delta> \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: projection_def)\n                  moreover\n                  note five \n                  moreover\n                  have \"Adm \\<V>1 \\<rho>1 Tr\\<^bsub>ES1\\<^esub> ?BETA c'\"\n                    proof -\n                      have \"?BETA @ [c'] \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                        proof -\n                          from Suc(7) c'_in_Cv1_inter_Upsilon1 \\<delta>2''_is_xs_c'_\\<nu>\n                          have \"c' \\<in> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                            by auto\n                          moreover\n                          from validES1 three have \"?BETA \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                            by (unfold ES_valid_def traces_prefixclosed_def\n                              prefixclosed_def prefix_def, auto)\n                          moreover\n                          note total_ES1_C1_inter_Upsilon1_inter_N2_inter_Delta2\n                          ultimately show ?thesis\n                            unfolding total_def\n                            by blast\n                        qed\n                      thus ?thesis\n                        unfolding Adm_def\n                        by blast                      \n                    qed\n                  moreover\n                  note BSIA1\n                  ultimately obtain \\<alpha>1''\n                    where bsia_one: \"?BETA @ [c'] @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    and bsia_two: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<delta> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n                    and bsia_three:  \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n                    unfolding BSIA_def\n                    by blast\n  \n                  let ?DELTA1'' = \"\\<gamma> @ [c']\"\n\n                  from bsia_one validES1 have \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: ES_valid_def traces_contain_events_def, auto)\n                  moreover\n                  have \"set ?DELTA1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    proof -\n                      from Suc(7) c'_in_Cv1_inter_Upsilon1 \\<delta>2''_is_xs_c'_\\<nu> \n                      have \"c' \\<in>  C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                        by auto\n                      with two show ?thesis\n                        by auto\n                    qed\n                  moreover\n                  from bsia_one v'_notin_E1 \n                  have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ ?DELTA1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n                    by (simp add: projection_def)\n                  moreover\n                  from bsia_two four have \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n                    by simp\n                  moreover\n                  note bsia_three\n                  moreover             \n                  have \"?DELTA1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n                    proof -\n                      from validV2 Suc(7) \\<delta>2''_is_xs_c'_\\<nu> have \"c' \\<in> E\\<^bsub>ES2\\<^esub>\"\n                        by (simp add: isViewOn_def V_valid_def\n                          VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n                      with c'_in_E1 c'_in_Cv1_inter_Upsilon1 \\<delta>2''_is_xs_c'_\\<nu> \\<nu>E1_empty six \n                      show ?thesis\n                        by (simp only: projection_concatenation_commute projection_def, auto)\n                    qed\n                  ultimately show ?thesis \n                    by blast     \n                qed\n            qed\n          from this[OF \\<beta>v'E1\\<alpha>1'_in_Tr1 \\<alpha>1'Cv1_empty c\\<delta>2''E1_in_Cv1_inter_Upsilon1star \n            c_in_Cv_inter_Upsilon \\<delta>2''_in_N2_inter_Delta2star Adm]\n          show ?thesis \n            by blast\n        qed\n      then obtain \\<alpha>1'' \\<delta>1''\n        where \\<alpha>1''_in_E1star: \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n        and \\<delta>1''_in_N1_inter_Delta1star:\"set \\<delta>1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n        and \\<beta>E1_cE1_\\<delta>1''_v'E1_\\<alpha>1''_in_Tr1: \n          \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta>1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n        and \\<alpha>1''Vv1_is_\\<alpha>1'Vv1: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n        and \\<alpha>1''Cv1_empty: \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n        and \\<delta>1''E2_is_\\<delta>2''E1: \"\\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>\"\n        by blast\n\n      from \\<beta>E1_cE1_\\<delta>1''_v'E1_\\<alpha>1''_in_Tr1 \\<beta>E2_cE2_\\<delta>2''_v'E2_\\<alpha>2''_in_Tr2 validES1 \n        validES2\n      have \\<delta>1''_in_E1star: \"set \\<delta>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\" and \\<delta>2''_in_E2star: \"set \\<delta>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n        by (simp_all add: ES_valid_def traces_contain_events_def, auto)\n      with \\<delta>1''E2_is_\\<delta>2''E1 merge_property[of \\<delta>1'' \"E\\<^bsub>ES1\\<^esub>\" \\<delta>2'' \"E\\<^bsub>ES2\\<^esub>\"] obtain \\<delta>'\n        where \\<delta>'E1_is_\\<delta>1'': \"\\<delta>' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1''\"\n        and \\<delta>'E2_is_\\<delta>2'': \"\\<delta>' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2''\"\n        and \\<delta>'_contains_only_\\<delta>1''_\\<delta>2''_events: \"set \\<delta>' \\<subseteq> set \\<delta>1'' \\<union> set \\<delta>2''\"\n        unfolding Let_def\n        by auto\n\n      let ?TAU = \"\\<beta> @ [c] @ \\<delta>' @ [v']\"\n      let ?LAMBDA = \"\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n      let ?T1 = \\<alpha>1''\n      let ?T2 = \\<alpha>2''\n\n     (* apply the generalized zipping lemma *)\n     have \"?TAU \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n        proof -\n          from \\<beta>E1_cE1_\\<delta>1''_v'E1_\\<alpha>1''_in_Tr1 \\<delta>'E1_is_\\<delta>1'' validES1\n          have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta>' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n            by (simp add: ES_valid_def traces_prefixclosed_def\n              prefixclosed_def prefix_def)\n          hence \"(\\<beta> @ [c] @ \\<delta>' @ [v']) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n            by (simp add: projection_def, auto)\n          moreover          \n          from \\<beta>E2_cE2_\\<delta>2''_v'E2_\\<alpha>2''_in_Tr2 \\<delta>'E2_is_\\<delta>2'' validES2 \n          have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta>' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n            by (simp add: ES_valid_def traces_prefixclosed_def\n              prefixclosed_def prefix_def)\n          hence \"(\\<beta> @ [c] @ \\<delta>' @ [v']) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n            by (simp add: projection_def, auto)\n          moreover\n          from \\<beta>v'\\<alpha>_in_Tr c_in_Cv_inter_Upsilon VIsViewOnE \\<delta>'_contains_only_\\<delta>1''_\\<delta>2''_events \n            \\<delta>1''_in_E1star \\<delta>2''_in_E2star\n          have \"set (\\<beta> @ [c] @ \\<delta>' @ [v']) \\<subseteq> E\\<^bsub>ES1\\<^esub> \\<union> E\\<^bsub>ES2\\<^esub>\"\n            unfolding composeES_def isViewOn_def V_valid_def \n              VC_disjoint_def VN_disjoint_def NC_disjoint_def\n            by auto\n          ultimately show ?thesis\n            unfolding composeES_def\n            by auto\n        qed \n      hence \"set ?TAU \\<subseteq> E\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n        unfolding composeES_def\n        by auto\n      moreover\n      have \"set ?LAMBDA \\<subseteq> V\\<^bsub>\\<V>\\<^esub>\"\n        by (simp add: projection_def, auto)\n      moreover\n      note \\<alpha>1''_in_E1star \\<alpha>2''_in_E2star\n      moreover\n      from \\<beta>E1_cE1_\\<delta>1''_v'E1_\\<alpha>1''_in_Tr1 \\<delta>'E1_is_\\<delta>1'' \n      have \"?TAU \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ ?T1 \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n        by (simp only: projection_concatenation_commute, auto)\n      moreover\n      from \\<beta>E2_cE2_\\<delta>2''_v'E2_\\<alpha>2''_in_Tr2 \\<delta>'E2_is_\\<delta>2'' \n      have \"?TAU \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ ?T2 \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n        by (simp only: projection_concatenation_commute, auto)\n      moreover\n      have \"?LAMBDA \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = ?T1 \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n        proof -\n          from propSepViews have \"?LAMBDA \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n            unfolding properSeparationOfViews_def by (simp only: projection_sequence)\n          moreover\n          from \\<alpha>1''_in_E1star propSepViews \n          have \"?T1 \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = ?T1 \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n            unfolding properSeparationOfViews_def\n            by (metis Int_commute projection_intersection_neutral)\n          moreover\n          note \\<alpha>1'Vv1_is_\\<alpha>Vv1 \\<alpha>1''Vv1_is_\\<alpha>1'Vv1\n          ultimately show ?thesis\n            by simp\n        qed\n      moreover\n      have \"?LAMBDA \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = ?T2 \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n        proof -\n          from propSepViews have \"?LAMBDA \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n            unfolding properSeparationOfViews_def by (simp only: projection_sequence)\n          moreover\n          from \\<alpha>2''_in_E2star propSepViews have \"?T2 \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = ?T2 \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n            unfolding properSeparationOfViews_def\n            by (metis Int_commute projection_intersection_neutral)\n          moreover\n          note \\<alpha>2'Vv2_is_\\<alpha>Vv2 \\<alpha>2''Vv2_is_\\<alpha>2'Vv2\n          ultimately show ?thesis\n            by simp\n        qed\n      moreover\n      note \\<alpha>1''Cv1_empty \\<alpha>2''Cv2_empty generalized_zipping_lemma\n      ultimately obtain t (* show that the conclusion of FCIA holds *)\n        where \"?TAU @ t \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n        and  \"t \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = ?LAMBDA\"\n        and \"t \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = []\"\n        by blast\n      moreover\n      have \"set \\<delta>' \\<subseteq> N\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>\\<^esub>\"\n        proof -\n          from \\<delta>'_contains_only_\\<delta>1''_\\<delta>2''_events \\<delta>1''_in_N1_inter_Delta1star \n            \\<delta>2''_in_N2_inter_Delta2star\n          have \"set \\<delta>' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<union> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n            by auto\n          with Delta1_N1_Delta2_N2_subset_Delta Nv1_union_Nv2_subsetof_Nv \n          show ?thesis\n            by auto\n        qed\n      ultimately have \"\\<exists>\\<alpha>' \\<gamma>'. (set \\<gamma>' \\<subseteq> N\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>\\<^esub> \\<and> \\<beta> @ [c] @ \\<gamma>' @ [v'] @ \\<alpha>' \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub> \n        \\<and> \\<alpha>' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> \\<and> \\<alpha>' \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = [])\"\n        by (simp only: append_assoc, blast)\n    }\n    moreover {\n      assume Nv2_inter_Delta2_inter_E1_empty: \"N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> = {}\" \n        and  Nv1_inter_Delta1_inter_E2_subsetof_Upsilon2: \"N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n\n      let ?ALPHA1''_DELTA1'' = \"\\<exists> \\<alpha>1'' \\<delta>1''. (\n        set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub> \\<and> set \\<delta>1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \n        \\<and> \\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta>1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub> \n        \\<and> \\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> \\<and> \\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = [])\"\n\n      from c_in_Cv_inter_Upsilon v'_in_Vv_inter_Nabla validV1\n      have \"c \\<notin> E\\<^bsub>ES1\\<^esub> \\<or> (c \\<in> E\\<^bsub>ES1\\<^esub> \\<and> v' \\<notin> E\\<^bsub>ES1\\<^esub>) \\<or> (c \\<in> E\\<^bsub>ES1\\<^esub> \\<and> v' \\<in> E\\<^bsub>ES1\\<^esub>)\"\n        by (simp add: isViewOn_def V_valid_def VC_disjoint_def \n          VN_disjoint_def NC_disjoint_def)\n      moreover {\n        assume c_notin_E1: \"c \\<notin> E\\<^bsub>ES1\\<^esub>\"\n\n        from validES1 \\<beta>v'E1\\<alpha>1'_in_Tr1 have \"set \\<alpha>1' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n          by (simp add: ES_valid_def traces_contain_events_def, auto)\n        moreover \n        have \"set [] \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n          by auto\n        moreover \n        from \\<beta>v'E1\\<alpha>1'_in_Tr1 c_notin_E1 \n        have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [] @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n          by (simp add: projection_def)\n        moreover\n        have \"\\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\" ..\n        moreover \n        note \\<alpha>1'Cv1_empty\n        ultimately have ?ALPHA1''_DELTA1''\n          by blast\n      }\n      moreover {\n        assume c_in_E1: \"c \\<in> E\\<^bsub>ES1\\<^esub>\"\n          and  v'_notin_E1: \"v' \\<notin> E\\<^bsub>ES1\\<^esub>\"\n\n        from c_in_E1 c_in_Cv_inter_Upsilon propSepViews\n          Upsilon_inter_E1_subset_Upsilon1\n        have c_in_Cv1_inter_Upsilon1: \"c \\<in> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n          unfolding properSeparationOfViews_def by auto\n        hence \"c \\<in> C\\<^bsub>\\<V>1\\<^esub>\"\n          by auto\n        moreover\n        from \\<beta>v'E1\\<alpha>1'_in_Tr1 v'_notin_E1 have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n          by (simp add: projection_def)\n        moreover\n        note \\<alpha>1'Cv1_empty\n        moreover\n        have \"Adm \\<V>1 \\<rho>1 Tr\\<^bsub>ES1\\<^esub> (\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) c\"\n        proof -\n          from Adm obtain \\<gamma>\n            where \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v: \"\\<gamma> \\<upharpoonleft> (\\<rho> \\<V>) = \\<beta> \\<upharpoonleft> (\\<rho> \\<V>)\"\n            and \\<gamma>c_in_Tr: \"(\\<gamma> @ [c]) \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n            unfolding Adm_def\n            by auto\n\n          from c_in_E1 \\<gamma>c_in_Tr have \"(\\<gamma> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ [c] \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n            by (simp add: projection_def composeES_def)\n          moreover\n          have \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (\\<rho>1 \\<V>1) = \\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (\\<rho>1 \\<V>1)\"\n          proof -\n            from \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v have \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (\\<rho> \\<V>) = \\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (\\<rho> \\<V>)\"\n              by (metis projection_commute)\n            with \\<rho>1v1_subset_\\<rho>v_inter_E1 have \"\\<gamma> \\<upharpoonleft> (\\<rho>1 \\<V>1) = \\<beta> \\<upharpoonleft> (\\<rho>1 \\<V>1)\"\n              by (metis Int_subset_iff \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v projection_subset_elim)\n            thus ?thesis\n              by (metis projection_commute)\n          qed\n          ultimately show ?thesis unfolding Adm_def\n            by auto\n        qed  \n        moreover \n        note BSIA1\n        ultimately obtain  \\<alpha>1''\n          where one: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n          and two:   \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n          and three: \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n          unfolding BSIA_def\n          by blast\n\n        from one validES1 have \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n          by (simp add: ES_valid_def traces_contain_events_def, auto)\n        moreover\n        have \"set [] \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n          by auto\n        moreover\n        from one c_in_E1 v'_notin_E1 \n        have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [] @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n          by (simp add: projection_def)\n        moreover \n        note two three\n        ultimately have ?ALPHA1''_DELTA1''\n          by blast\n      }\n      moreover {\n        assume c_in_E1: \"c \\<in> E\\<^bsub>ES1\\<^esub>\"\n          and  v'_in_E1: \"v' \\<in> E\\<^bsub>ES1\\<^esub>\"\n\n        from c_in_E1 c_in_Cv_inter_Upsilon propSepViews\n          Upsilon_inter_E1_subset_Upsilon1\n        have c_in_Cv1_inter_Upsilon1: \"c \\<in> C\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>1\\<^esub>\"\n          unfolding properSeparationOfViews_def by auto\n        moreover\n        from v'_in_E1 propSepViews v'_in_Vv_inter_Nabla \n          Nabla_inter_E1_subset_Nabla1\n        have \"v' \\<in> V\\<^bsub>\\<V>1\\<^esub> \\<inter> Nabla \\<Gamma>1\"\n          unfolding properSeparationOfViews_def by auto\n        moreover\n        from v'_in_E1  \\<beta>v'E1\\<alpha>1'_in_Tr1 have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [v'] @ \\<alpha>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n          by (simp add: projection_def)\n        moreover\n        note \\<alpha>1'Cv1_empty \n        moreover\n        have \"Adm \\<V>1 \\<rho>1 Tr\\<^bsub>ES1\\<^esub> (\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) c\"\n        proof -\n          from Adm obtain \\<gamma>\n            where \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v: \"\\<gamma> \\<upharpoonleft> (\\<rho> \\<V>) = \\<beta> \\<upharpoonleft> (\\<rho> \\<V>)\"\n            and \\<gamma>c_in_Tr: \"(\\<gamma> @ [c]) \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n            unfolding Adm_def\n            by auto\n\n          from c_in_E1 \\<gamma>c_in_Tr have \"(\\<gamma> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub>) @ [c] \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n            by (simp add: projection_def composeES_def)\n          moreover\n          have \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (\\<rho>1 \\<V>1) = \\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (\\<rho>1 \\<V>1)\"\n          proof -\n            from \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v have \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (\\<rho> \\<V>) = \\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> (\\<rho> \\<V>)\"\n              by (metis projection_commute)\n            with \\<rho>1v1_subset_\\<rho>v_inter_E1 have \"\\<gamma> \\<upharpoonleft> (\\<rho>1 \\<V>1) = \\<beta> \\<upharpoonleft> (\\<rho>1 \\<V>1)\"\n              by (metis Int_subset_iff \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v projection_subset_elim)\n            thus ?thesis\n              by (metis projection_commute)\n          qed\n          ultimately show ?thesis unfolding Adm_def\n            by auto\n        qed  \n        moreover\n        note FCIA1\n        ultimately obtain \\<alpha>1'' \\<delta>1''\n          where one: \"set \\<delta>1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n          and two: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] @ \\<delta>1'' @ [v'] @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n          and three: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n          and four: \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n          unfolding FCIA_def\n          by blast\n\n        from two validES1 have \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n          by (simp add: ES_valid_def traces_contain_events_def, auto)\n        moreover\n        note one\n        moreover\n        from two c_in_E1 v'_in_E1 \n        have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta>1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n          by (simp add: projection_def)\n        moreover\n        note three four\n        ultimately have ?ALPHA1''_DELTA1''\n          by blast\n      }\n      ultimately obtain \\<alpha>1'' \\<delta>1''\n        where \\<alpha>1''_in_E1star: \"set \\<alpha>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n        and \\<delta>1''_in_N1_inter_Delta1star:\"set \\<delta>1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n        and \\<beta>E1_cE1_\\<delta>1''_v'E1_\\<alpha>1''_in_Tr1: \n          \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta>1'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<alpha>1'' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n        and \\<alpha>1''Vv1_is_\\<alpha>1'Vv1: \"\\<alpha>1'' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<alpha>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n        and \\<alpha>1''Cv1_empty: \"\\<alpha>1'' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n        by blast\n\n      from c_in_Cv_inter_Upsilon Upsilon_inter_E2_subset_Upsilon2 propSepViews\n      have cE2_in_Cv2_inter_Upsilon2: \"set ([c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n        unfolding properSeparationOfViews_def by (simp add: projection_def, auto)\n     \n      from \\<delta>1''_in_N1_inter_Delta1star Nv1_inter_Delta1_inter_E2_subsetof_Upsilon2 \n       propSepViews disjoint_Nv1_Vv2 \n      have \\<delta>1''E2_in_Cv2_inter_Upsilon2star: \"set (\\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n        proof -\n          from \\<delta>1''_in_N1_inter_Delta1star \n          have eq: \"\\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>1'' \\<upharpoonleft> (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub>)\"\n            by (metis Int_commute Int_left_commute Int_lower2 Int_lower1 \n              projection_intersection_neutral subset_trans)\n          \n          from validV2 Nv1_inter_Delta1_inter_E2_subsetof_Upsilon2 \n            propSepViews disjoint_Nv1_Vv2  \n          have \"N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n            unfolding properSeparationOfViews_def \n            by (simp add: isViewOn_def V_valid_def VC_disjoint_def \n              VN_disjoint_def NC_disjoint_def, auto)\n          thus ?thesis\n            by (subst eq, simp only: projection_def, auto)\n        qed\n      \n      have c\\<delta>1''E2_in_Cv2_inter_Upsilon2star: \"set ((c # \\<delta>1'') \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n        proof -\n          from cE2_in_Cv2_inter_Upsilon2 \\<delta>1''E2_in_Cv2_inter_Upsilon2star\n          have \"set (([c] @ \\<delta>1'') \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n            by (simp only: projection_concatenation_commute, auto)\n          thus ?thesis\n            by auto\n        qed\n\n\n      have \"\\<exists> \\<alpha>2'' \\<delta>2''. set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>        \n        \\<and> set \\<delta>2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>        \n        \\<and> \\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta>2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>        \n        \\<and> \\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> \\<and> \\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\n        \\<and> \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n        proof cases\n          assume v'_in_E2: \"v' \\<in> E\\<^bsub>ES2\\<^esub>\"\n          with Nabla_inter_E2_subset_Nabla2 propSepViews v'_in_Vv_inter_Nabla\n          have v'_in_Vv2_inter_Nabla2: \"v' \\<in> V\\<^bsub>\\<V>2\\<^esub> \\<inter> Nabla \\<Gamma>2\"\n            unfolding properSeparationOfViews_def by auto\n\n          have \"\\<lbrakk> (\\<beta> @ [v']) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub> ; \n            \\<alpha>2' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []; set ((c # \\<delta>1'') \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> ; \n            c \\<in> C\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub> ; set \\<delta>1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>;\n            Adm \\<V> \\<rho> (Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>) \\<beta> c \\<rbrakk> \n            \\<Longrightarrow> \\<exists> \\<alpha>2'' \\<delta>2''.\n           (set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub> \\<and> set \\<delta>2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>            \n            \\<and> \\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta>2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>            \n            \\<and> \\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> \\<and> \\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\n            \\<and> \\<delta>2'' \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>) = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>)\"\n            proof (induct \"length ((c # \\<delta>1'') \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>)\" arbitrary: \\<beta> \\<alpha>2' c \\<delta>1'')\n              case 0\n\n              from 0(2) validES2 have \"set \\<alpha>2' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n                by (simp add: ES_valid_def traces_contain_events_def, auto)\n              moreover\n              have \"set [] \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                by auto\n              moreover\n              have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [] @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                proof -\n                  note 0(2)\n                  moreover\n                  from 0(1) have \"c \\<notin> E\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: projection_def, auto)\n                  ultimately show ?thesis\n                    by (simp add: projection_concatenation_commute projection_def)\n                qed\n              moreover\n              have \"\\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\" ..\n              moreover\n              note 0(3)\n              moreover \n              from 0(1) have \"[] \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>) = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                by (simp add: projection_def, split if_split_asm, auto)\n              ultimately show ?case\n                by blast\n            next\n              case (Suc n)\n\n              from projection_split_last[OF Suc(2)] obtain \\<mu> c' \\<nu>\n                where c'_in_E2: \"c' \\<in> E\\<^bsub>ES2\\<^esub>\"\n                and c\\<delta>1''_is_\\<mu>c'\\<nu>: \"c # \\<delta>1'' = \\<mu> @ [c'] @ \\<nu>\"\n                and \\<nu>E2_empty: \"\\<nu> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = []\"\n                and n_is_length_\\<mu>\\<nu>E2: \"n = length ((\\<mu> @ \\<nu>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>)\"\n                by blast\n\n              from Suc(5) c'_in_E2 c\\<delta>1''_is_\\<mu>c'\\<nu> have \"set (\\<mu> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c']) \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                by (simp only: c\\<delta>1''_is_\\<mu>c'\\<nu> projection_concatenation_commute \n                  projection_def, auto)\n              hence c'_in_Cv2_inter_Upsilon2: \"c' \\<in> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                by auto\n              hence c'_in_Cv2: \"c' \\<in> C\\<^bsub>\\<V>2\\<^esub>\" and c'_in_Upsilon2: \"c' \\<in> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                by auto\n              with validV2 have c'_in_E2: \"c' \\<in> E\\<^bsub>ES2\\<^esub>\"\n                by (simp add: isViewOn_def V_valid_def\n                  VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n\n              show ?case\n                proof (cases \\<mu>)\n                  case Nil (* we apply FCIA in this case *)\n                  with c\\<delta>1''_is_\\<mu>c'\\<nu> have c_is_c': \"c = c'\" and \\<delta>1''_is_\\<nu>: \"\\<delta>1'' = \\<nu>\"\n                    by auto\n                  with c'_in_Cv2_inter_Upsilon2 have \"c \\<in> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    by simp\n                  moreover\n                  note v'_in_Vv2_inter_Nabla2\n                  moreover\n                  from v'_in_E2 Suc(3) have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ [v'] @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: projection_concatenation_commute projection_def)\n                  moreover\n                  note Suc(4)\n                  moreover\n                  have \"Adm \\<V>2 \\<rho>2 Tr\\<^bsub>ES2\\<^esub> (\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) c\"\n                    proof -\n                      from Suc(8) obtain \\<gamma>\n                        where \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v: \"\\<gamma> \\<upharpoonleft> (\\<rho> \\<V>) = \\<beta> \\<upharpoonleft> (\\<rho> \\<V>)\"\n                        and \\<gamma>c_in_Tr: \"(\\<gamma> @ [c]) \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n                        unfolding Adm_def\n                        by auto\n\n                      from c_is_c' c'_in_E2 \\<gamma>c_in_Tr have \"(\\<gamma> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ [c] \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                        by (simp add: projection_def composeES_def)\n                      moreover\n                      have \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (\\<rho>2 \\<V>2) = \\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (\\<rho>2 \\<V>2)\"\n                      proof -\n                        from \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v have \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (\\<rho> \\<V>) = \\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (\\<rho> \\<V>)\"\n                          by (metis projection_commute)\n                        with \\<rho>2v2_subset_\\<rho>v_inter_E2 have \"\\<gamma> \\<upharpoonleft> (\\<rho>2 \\<V>2) = \\<beta> \\<upharpoonleft> (\\<rho>2 \\<V>2)\"\n                          by (metis Int_subset_iff \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v projection_subset_elim)\n                        thus ?thesis\n                          by (metis projection_commute)\n                      qed\n                      ultimately show ?thesis unfolding Adm_def\n                        by auto\n                    qed  \n                  moreover\n                  note FCIA2\n                  ultimately obtain \\<alpha>2'' \\<gamma>\n                    where one: \"set \\<gamma> \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    and two: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] @ \\<gamma> @ [v'] @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    and three: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n                    and four: \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n                    unfolding FCIA_def\n                    by blast\n\n                  (* we choose \\<delta>2'' = \\<nu> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<gamma> *)\n                  let ?DELTA2'' = \"\\<nu> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<gamma>\" \n                    \n                  from two validES2 have \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: ES_valid_def traces_contain_events_def, auto)\n                  moreover\n                  from one \\<nu>E2_empty\n                  have \"set ?DELTA2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    by auto\n                  moreover\n                  have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ ?DELTA2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    proof -\n                      from c_is_c' c'_in_E2 have \"[c] = [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                        by (simp add: projection_def)\n                      moreover\n                      from v'_in_E2 have \"[v'] = [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                        by (simp add: projection_def)\n                      moreover\n                      note \\<nu>E2_empty two\n                      ultimately show ?thesis\n                        by auto\n                    qed\n                  moreover\n                  note three four\n                  moreover\n                  have \"?DELTA2'' \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>) = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                    proof -\n                      have \"\\<gamma> \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>) = []\"\n                        proof -\n                          from validV2 have \"N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>) = {}\"\n                            by (simp add: isViewOn_def V_valid_def\n                              VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n                          with projection_intersection_neutral[OF one, of \"C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"]\n                          show ?thesis\n                            by (simp add: projection_def)\n                        qed\n                      with \\<delta>1''_is_\\<nu> \\<nu>E2_empty show ?thesis\n                        by (simp add: projection_concatenation_commute)\n                    qed\n                  ultimately show ?thesis\n                    by blast\n                next\n                  case (Cons x xs) (* we apply the inductive hypothesis in this case *)\n                  with c\\<delta>1''_is_\\<mu>c'\\<nu>\n                  have \\<mu>_is_c_xs: \"\\<mu> = [c] @ xs\" and \\<delta>1''_is_xs_c'_\\<nu>: \"\\<delta>1'' = xs @ [c'] @ \\<nu>\"\n                    by auto\n                  with n_is_length_\\<mu>\\<nu>E2 have \"n = length ((c # (xs @ \\<nu>)) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>)\"\n                    by auto\n                  moreover\n                  note Suc(3,4)\n                  moreover\n                  have \"set ((c # (xs @ \\<nu>)) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    proof -\n                      have res: \"c # (xs @ \\<nu>) = [c] @ (xs @ \\<nu>)\" \n                        by auto\n\n                      from Suc(5) c\\<delta>1''_is_\\<mu>c'\\<nu> \\<mu>_is_c_xs \\<nu>E2_empty\n                      show ?thesis\n                        by (subst res, simp only: c\\<delta>1''_is_\\<mu>c'\\<nu> \n                          projection_concatenation_commute set_append, auto)\n                    qed\n                  moreover\n                  note Suc(6) \n                  moreover\n                  from Suc(7) \\<delta>1''_is_xs_c'_\\<nu> have \"set (xs @ \\<nu>) \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    by auto\n                  moreover note Suc(8) Suc(1)[of c \"xs @ \\<nu>\" \\<beta> \\<alpha>2']\n                  ultimately obtain \\<delta> \\<gamma>\n                    where one: \"set \\<delta> \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n                    and two: \"set \\<gamma> \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    and three: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<gamma> @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta> \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    and four: \"\\<delta> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n                    and five: \"\\<delta> \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n                    and six: \"\\<gamma> \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>) = (xs @ \\<nu>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                    by blast\n\n                  (* apply FCIA to insert c' after \\<gamma> *)\n                  let ?BETA = \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<gamma>\"\n\n                  note c'_in_Cv2_inter_Upsilon2 v'_in_Vv2_inter_Nabla2\n                  moreover\n                  from three v'_in_E2 have \"?BETA @ [v'] @ \\<delta> \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: projection_def)\n                  moreover\n                  note five \n                  moreover\n                  have \"Adm \\<V>2 \\<rho>2 Tr\\<^bsub>ES2\\<^esub> ?BETA c'\"\n                    proof -\n                      have \"?BETA @ [c'] \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                        proof -\n                          from Suc(7) c'_in_Cv2_inter_Upsilon2 \\<delta>1''_is_xs_c'_\\<nu>\n                          have \"c' \\<in> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                            by auto\n                          moreover\n                          from validES2 three have \"?BETA \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                            by (unfold ES_valid_def traces_prefixclosed_def\n                              prefixclosed_def prefix_def, auto)\n                          moreover\n                          note total_ES2_C2_inter_Upsilon2_inter_N1_inter_Delta1\n                          ultimately show ?thesis\n                            unfolding total_def\n                            by blast\n                        qed\n                      thus ?thesis\n                        unfolding Adm_def\n                        by blast                        \n                    qed\n                  moreover\n                  note FCIA2\n                  ultimately obtain \\<alpha>2'' \\<delta>'\n                    where fcia_one: \"set \\<delta>' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    and fcia_two: \"?BETA @ [c'] @ \\<delta>' @ [v'] @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    and fcia_three: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<delta> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n                    and fcia_four:  \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n                    unfolding FCIA_def\n                    by blast\n  \n                  let ?DELTA2'' = \"\\<gamma> @ [c'] @ \\<delta>'\"\n\n                  from fcia_two validES2 have \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: ES_valid_def traces_contain_events_def, auto)\n                  moreover\n                  have \"set ?DELTA2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    proof -\n                      from Suc(7) c'_in_Cv2_inter_Upsilon2 \\<delta>1''_is_xs_c'_\\<nu> \n                      have \"c' \\<in>  C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                        by auto\n                      with two fcia_one show ?thesis\n                        by auto\n                    qed\n                  moreover\n                  from fcia_two v'_in_E2 \n                  have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ ?DELTA2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: projection_def)\n                  moreover\n                  from fcia_three four have \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n                    by simp\n                  moreover\n                  note fcia_four\n                  moreover             \n                  have \"?DELTA2'' \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>) = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                    proof -\n                      have \"\\<delta>' \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>) = []\"\n                        proof -\n                          from fcia_one have \"\\<forall> e \\<in> set \\<delta>'. e \\<in> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                            by auto\n                          with validV2 have \"\\<forall> e \\<in> set \\<delta>'. e \\<notin> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                            by (simp add:isViewOn_def V_valid_def \n                              VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n                          thus ?thesis\n                            by (simp add: projection_def)\n                        qed\n                      with c'_in_E2 c'_in_Cv2_inter_Upsilon2 \\<delta>1''_is_xs_c'_\\<nu> \\<nu>E2_empty six \n                      show ?thesis\n                        by (simp only: projection_concatenation_commute projection_def, auto)\n                    qed\n                  ultimately show ?thesis \n                    by blast     \n                qed\n          qed\n          from this[OF \\<beta>v'E2\\<alpha>2'_in_Tr2 \\<alpha>2'Cv2_empty \n            c\\<delta>1''E2_in_Cv2_inter_Upsilon2star c_in_Cv_inter_Upsilon \\<delta>1''_in_N1_inter_Delta1star Adm]\n          obtain \\<alpha>2'' \\<delta>2''\n            where one: \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n            and two: \"set \\<delta>2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n            and three: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta>2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>            \n            \\<and> \\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> \\<and> \\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n            and four: \"\\<delta>2'' \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>) = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n            by blast\n\n          note one two three\n          moreover\n          have \"\\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\" \n            proof -\n              from projection_intersection_neutral[OF two, of \"E\\<^bsub>ES1\\<^esub>\"] \n                Nv2_inter_Delta2_inter_E1_empty validV1 \n              have \"\\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>2'' \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub>)\"\n                by (simp only: Int_Un_distrib2, auto)\n              moreover\n              from validV1\n              have \"C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> = C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                by (simp add: isViewOn_def V_valid_def VC_disjoint_def \n                  VN_disjoint_def NC_disjoint_def, auto)\n              ultimately have \"\\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>2'' \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>)\"\n                by simp\n              hence \"\\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>2'' \\<upharpoonleft> (C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>) \\<upharpoonleft> (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>)\"\n                by (simp add: projection_def)\n              with four have \"\\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>)\"\n                by simp\n              hence \"\\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1'' \\<upharpoonleft> (N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                by (simp only: projection_commute)\n              with \\<delta>1''_in_N1_inter_Delta1star show ?thesis\n                by (simp only: list_subset_iff_projection_neutral)\n            qed\n          ultimately show ?thesis\n              by blast\n        next\n          assume v'_notin_E2: \"v' \\<notin> E\\<^bsub>ES2\\<^esub>\"\n\n           have \"\\<lbrakk> (\\<beta> @ [v']) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub> ; \n            \\<alpha>2' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []; set ((c # \\<delta>1'') \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> ; \n             c \\<in> C\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>\\<^esub> ; set \\<delta>1'' \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>;\n            Adm \\<V> \\<rho> (Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>) \\<beta> c \\<rbrakk> \n            \\<Longrightarrow> \\<exists> \\<alpha>2'' \\<delta>2''.\n             (set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub> \\<and> set \\<delta>2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>            \n             \\<and> \\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta>2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>            \n             \\<and> \\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> \\<and> \\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\n            \\<and> \\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>)\"\n            proof (induct \"length ((c # \\<delta>1'') \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>)\" arbitrary: \\<beta> \\<alpha>2' c \\<delta>1'')\n               case 0\n\n              from 0(2) validES2 have \"set \\<alpha>2' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n                by (simp add: ES_valid_def traces_contain_events_def, auto)\n              moreover\n              have \"set [] \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                by auto\n              moreover\n              have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [] @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                proof -\n                  note 0(2)\n                  moreover\n                  from 0(1) have \"c \\<notin> E\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: projection_def, auto)\n                  ultimately show ?thesis\n                    by (simp add: projection_concatenation_commute projection_def)\n                qed\n              moreover\n              have \"\\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\" ..\n              moreover\n              note 0(3)\n              moreover \n              from 0(1) have \"[] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                by (simp add: projection_def, split if_split_asm, auto)\n              ultimately show ?case\n                by blast\n            next\n              case (Suc n)\n\n              from projection_split_last[OF Suc(2)] obtain \\<mu> c' \\<nu>\n                where c'_in_E2: \"c' \\<in> E\\<^bsub>ES2\\<^esub>\"\n                and c\\<delta>1''_is_\\<mu>c'\\<nu>: \"c # \\<delta>1'' = \\<mu> @ [c'] @ \\<nu>\"\n                and \\<nu>E2_empty: \"\\<nu> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = []\"\n                and n_is_length_\\<mu>\\<nu>E2: \"n = length ((\\<mu> @ \\<nu>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>)\"\n                by blast\n\n              from Suc(5) c'_in_E2 c\\<delta>1''_is_\\<mu>c'\\<nu> have \"set (\\<mu> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c']) \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                by (simp only: c\\<delta>1''_is_\\<mu>c'\\<nu> projection_concatenation_commute projection_def, auto)\n              hence c'_in_Cv2_inter_Upsilon2: \"c' \\<in> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                by auto\n              hence c'_in_Cv2: \"c' \\<in> C\\<^bsub>\\<V>2\\<^esub>\" and c'_in_Upsilon2: \"c' \\<in> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                by auto\n              with validV2 have c'_in_E2: \"c' \\<in> E\\<^bsub>ES2\\<^esub>\"\n                by (simp add:isViewOn_def V_valid_def \n                  VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n\n              show ?case\n                proof (cases \\<mu>)\n                  case Nil (* we just apply BSIA in this case *)\n                  with c\\<delta>1''_is_\\<mu>c'\\<nu> have c_is_c': \"c = c'\" and \\<delta>1''_is_\\<nu>: \"\\<delta>1'' = \\<nu>\"\n                    by auto\n                  with c'_in_Cv2_inter_Upsilon2 have \"c \\<in> C\\<^bsub>\\<V>2\\<^esub>\"\n                    by simp\n                  moreover\n                  from v'_notin_E2 Suc(3) have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ \\<alpha>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: projection_concatenation_commute projection_def)\n                  moreover\n                  note Suc(4)\n                  moreover\n                  have \"Adm \\<V>2 \\<rho>2 Tr\\<^bsub>ES2\\<^esub> (\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) c\"\n                     proof -\n                      from Suc(8) obtain \\<gamma>\n                        where \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v: \"\\<gamma> \\<upharpoonleft> (\\<rho> \\<V>) = \\<beta> \\<upharpoonleft> (\\<rho> \\<V>)\"\n                        and \\<gamma>c_in_Tr: \"(\\<gamma> @ [c]) \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n                        unfolding Adm_def\n                        by auto\n\n                      from c_is_c' c'_in_E2 \\<gamma>c_in_Tr have \"(\\<gamma> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ [c] \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                        by (simp add: projection_def composeES_def)\n                      moreover\n                      have \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (\\<rho>2 \\<V>2) = \\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (\\<rho>2 \\<V>2)\"\n                      proof -\n                        from \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v have \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (\\<rho> \\<V>) = \\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> (\\<rho> \\<V>)\"\n                          by (metis projection_commute)\n                        with \\<rho>2v2_subset_\\<rho>v_inter_E2 \n                        have \"\\<gamma> \\<upharpoonleft> (\\<rho>2 \\<V>2) = \\<beta> \\<upharpoonleft> (\\<rho>2 \\<V>2)\"\n                          by (metis Int_subset_iff \\<gamma>\\<rho>v_is_\\<beta>\\<rho>v projection_subset_elim)\n                        thus ?thesis\n                          by (metis projection_commute)\n                      qed\n                      ultimately show ?thesis unfolding Adm_def\n                        by auto\n                    qed  \n                  moreover\n                  note BSIA2\n                  ultimately obtain \\<alpha>2''\n                    where one: \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ [c] @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    and two: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n                    and three: \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n                    unfolding BSIA_def\n                    by blast\n\n                  let ?DELTA2'' = \"\\<nu> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n\n                  from one validES2 have \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: ES_valid_def traces_contain_events_def, auto)\n                  moreover\n                  from \\<nu>E2_empty\n                  have \"set ?DELTA2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    by simp\n                  moreover\n                  from c_is_c' c'_in_E2 one v'_notin_E2 \\<nu>E2_empty\n                  have \"(\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ ?DELTA2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: projection_def)\n                  moreover\n                  note two three\n                  moreover\n                  from \\<nu>E2_empty \\<delta>1''_is_\\<nu> have \"?DELTA2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: projection_def)\n                  ultimately show ?thesis\n                    by blast\n                next\n                  case (Cons x xs) (* apply inductive hypothesis, then BSIA *)\n                   with c\\<delta>1''_is_\\<mu>c'\\<nu> have \\<mu>_is_c_xs: \"\\<mu> = [c] @ xs\" \n                     and \\<delta>1''_is_xs_c'_\\<nu>: \"\\<delta>1'' = xs @ [c'] @ \\<nu>\"\n                    by auto\n                  with n_is_length_\\<mu>\\<nu>E2 have \"n = length ((c # (xs @ \\<nu>)) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>)\"\n                    by auto\n                  moreover\n                  note Suc(3,4)\n                  moreover\n                  have \"set ((c # (xs @ \\<nu>)) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>) \\<subseteq> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub>\"\n                    proof -\n                      have res: \"c # (xs @ \\<nu>) = [c] @ (xs @ \\<nu>)\" \n                        by auto\n\n                      from Suc(5) c\\<delta>1''_is_\\<mu>c'\\<nu> \\<mu>_is_c_xs \\<nu>E2_empty\n                      show ?thesis\n                        by (subst res, simp only: c\\<delta>1''_is_\\<mu>c'\\<nu> \n                          projection_concatenation_commute set_append, auto)\n                    qed\n                  moreover\n                  note Suc(6) \n                  moreover\n                  from Suc(7) \\<delta>1''_is_xs_c'_\\<nu> have \"set (xs @ \\<nu>) \\<subseteq> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    by auto\n                  moreover note Suc(8) Suc(1)[of c \"xs @ \\<nu>\" \\<beta> \\<alpha>2']\n                  ultimately obtain \\<delta> \\<gamma>\n                    where one: \"set \\<delta> \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n                    and two: \"set \\<gamma> \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    and three: \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<gamma> @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta> \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    and four: \"\\<delta> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n                    and five: \"\\<delta> \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n                    and six: \"\\<gamma> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = (xs @ \\<nu>) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                    by blast\n                  \n                   (* apply BSIA to insert c' after \\<gamma> *)\n                  let ?BETA = \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<gamma>\"\n\n                  from c'_in_Cv2_inter_Upsilon2 have \"c' \\<in> C\\<^bsub>\\<V>2\\<^esub>\"\n                    by auto\n                  moreover\n                  from three v'_notin_E2 have \"?BETA @ \\<delta> \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: projection_def)\n                  moreover\n                  note five \n                  moreover\n                  have \"Adm \\<V>2 \\<rho>2 Tr\\<^bsub>ES2\\<^esub> ?BETA c'\"\n                    proof -\n                      have \"?BETA @ [c'] \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                        proof -\n                          from Suc(7) c'_in_Cv2_inter_Upsilon2 \\<delta>1''_is_xs_c'_\\<nu>\n                          have \"c' \\<in> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                            by auto\n                          moreover\n                          from validES2 three have \"?BETA \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                            by (unfold ES_valid_def traces_prefixclosed_def\n                              prefixclosed_def prefix_def, auto)\n                          moreover\n                          note total_ES2_C2_inter_Upsilon2_inter_N1_inter_Delta1\n                          ultimately show ?thesis\n                            unfolding total_def\n                            by blast\n                        qed\n                      thus ?thesis\n                        unfolding Adm_def\n                        by blast                      \n                    qed\n                  moreover\n                  note BSIA2\n                  ultimately obtain \\<alpha>2''\n                    where bsia_one: \"?BETA @ [c'] @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    and bsia_two: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<delta> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n                    and bsia_three:  \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n                    unfolding BSIA_def\n                    by blast\n  \n                  let ?DELTA2'' = \"\\<gamma> @ [c']\"\n\n                  from bsia_one validES2 have \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: ES_valid_def traces_contain_events_def, auto)\n                  moreover\n                  have \"set ?DELTA2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                    proof -\n                      from Suc(7) c'_in_Cv2_inter_Upsilon2 \\<delta>1''_is_xs_c'_\\<nu> \n                      have \"c' \\<in>  C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n                        by auto\n                      with two show ?thesis\n                        by auto\n                    qed\n                  moreover\n                  from bsia_one v'_notin_E2 \n                  have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ ?DELTA2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n                    by (simp add: projection_def)\n                  moreover\n                  from bsia_two four have \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n                    by simp\n                  moreover\n                  note bsia_three\n                  moreover             \n                  have \"?DELTA2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n                    proof -\n                      from validV1 Suc(7) \\<delta>1''_is_xs_c'_\\<nu> have \"c' \\<in> E\\<^bsub>ES1\\<^esub>\"\n                        by (simp add: isViewOn_def V_valid_def \n                          VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n                      with c'_in_E2 c'_in_Cv2_inter_Upsilon2 \\<delta>1''_is_xs_c'_\\<nu> \\<nu>E2_empty six \n                      show ?thesis\n                        by (simp only: projection_concatenation_commute projection_def, auto)\n                    qed\n                  ultimately show ?thesis \n                    by blast     \n                qed\n            qed\n          from this[OF \\<beta>v'E2\\<alpha>2'_in_Tr2 \\<alpha>2'Cv2_empty c\\<delta>1''E2_in_Cv2_inter_Upsilon2star \n            c_in_Cv_inter_Upsilon \\<delta>1''_in_N1_inter_Delta1star Adm]\n          show ?thesis \n            by blast\n        qed\n      then obtain \\<alpha>2'' \\<delta>2''\n        where \\<alpha>2''_in_E2star: \"set \\<alpha>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n        and \\<delta>2''_in_N2_inter_Delta2star:\"set \\<delta>2'' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> C\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Upsilon>\\<^bsub>\\<Gamma>2\\<^esub> \\<inter> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n        and \\<beta>E2_cE2_\\<delta>2''_v'E2_\\<alpha>2''_in_Tr2: \n        \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta>2'' @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<alpha>2'' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n        and \\<alpha>2''Vv2_is_\\<alpha>2'Vv2: \"\\<alpha>2'' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<alpha>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n        and \\<alpha>2''Cv2_empty: \"\\<alpha>2'' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n        and \\<delta>2''E1_is_\\<delta>1''E2: \"\\<delta>2'' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1'' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub>\"\n        by blast\n\n      from \\<beta>E2_cE2_\\<delta>2''_v'E2_\\<alpha>2''_in_Tr2 \\<beta>E1_cE1_\\<delta>1''_v'E1_\\<alpha>1''_in_Tr1 \n        validES2 validES1\n      have \\<delta>2''_in_E2star: \"set \\<delta>2'' \\<subseteq> E\\<^bsub>ES2\\<^esub>\" and \\<delta>1''_in_E1star: \"set \\<delta>1'' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n        by (simp_all add: ES_valid_def traces_contain_events_def, auto)\n      with \\<delta>2''E1_is_\\<delta>1''E2 merge_property[of \\<delta>2'' \"E\\<^bsub>ES2\\<^esub>\" \\<delta>1'' \"E\\<^bsub>ES1\\<^esub>\"] obtain \\<delta>'\n        where \\<delta>'E2_is_\\<delta>2'': \"\\<delta>' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<delta>2''\"\n        and \\<delta>'E1_is_\\<delta>1'': \"\\<delta>' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<delta>1''\"\n        and \\<delta>'_contains_only_\\<delta>2''_\\<delta>1''_events: \"set \\<delta>' \\<subseteq> set \\<delta>2'' \\<union> set \\<delta>1''\"\n        unfolding Let_def\n        by auto\n\n      let ?TAU = \"\\<beta> @ [c] @ \\<delta>' @ [v']\"\n      let ?LAMBDA = \"\\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n      let ?T2 = \\<alpha>2''\n      let ?T1 = \\<alpha>1''\n\n     (* apply the generalized zipping lemma *)\n     have \"?TAU \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n        proof -\n          from \\<beta>E2_cE2_\\<delta>2''_v'E2_\\<alpha>2''_in_Tr2 \\<delta>'E2_is_\\<delta>2'' validES2\n          have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<delta>' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ [v'] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n            by (simp add: ES_valid_def traces_prefixclosed_def\n              prefixclosed_def prefix_def)\n          hence \"(\\<beta> @ [c] @ \\<delta>' @ [v']) \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n            by (simp add: projection_def, auto)\n          moreover          \n          from \\<beta>E1_cE1_\\<delta>1''_v'E1_\\<alpha>1''_in_Tr1 \\<delta>'E1_is_\\<delta>1'' validES1 \n          have \"\\<beta> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [c] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<delta>' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ [v'] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n            by (simp add: ES_valid_def traces_prefixclosed_def\n              prefixclosed_def prefix_def)\n          hence \"(\\<beta> @ [c] @ \\<delta>' @ [v']) \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n            by (simp add: projection_def, auto)\n          moreover\n          from \\<beta>v'\\<alpha>_in_Tr c_in_Cv_inter_Upsilon VIsViewOnE\n            \\<delta>'_contains_only_\\<delta>2''_\\<delta>1''_events \\<delta>2''_in_E2star \\<delta>1''_in_E1star\n          have \"set (\\<beta> @ [c] @ \\<delta>' @ [v']) \\<subseteq> E\\<^bsub>ES2\\<^esub> \\<union> E\\<^bsub>ES1\\<^esub>\"\n            unfolding composeES_def isViewOn_def V_valid_def \n              VC_disjoint_def VN_disjoint_def NC_disjoint_def\n            by auto\n          ultimately show ?thesis\n            unfolding composeES_def\n            by auto\n        qed \n      hence \"set ?TAU \\<subseteq> E\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n        unfolding composeES_def\n        by auto\n      moreover\n      have \"set ?LAMBDA \\<subseteq> V\\<^bsub>\\<V>\\<^esub>\"\n        by (simp add: projection_def, auto)\n      moreover\n      note \\<alpha>2''_in_E2star \\<alpha>1''_in_E1star\n      moreover\n      from \\<beta>E2_cE2_\\<delta>2''_v'E2_\\<alpha>2''_in_Tr2 \\<delta>'E2_is_\\<delta>2'' \n      have \"?TAU \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ ?T2 \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n        by (simp only: projection_concatenation_commute, auto)\n      moreover\n      from \\<beta>E1_cE1_\\<delta>1''_v'E1_\\<alpha>1''_in_Tr1 \\<delta>'E1_is_\\<delta>1'' \n      have \"?TAU \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ ?T1 \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n        by (simp only: projection_concatenation_commute, auto)\n      moreover\n      have \"?LAMBDA \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = ?T2 \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n        proof -\n          from propSepViews have \"?LAMBDA \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n            unfolding properSeparationOfViews_def by (simp only: projection_sequence)\n          moreover\n          from \\<alpha>2''_in_E2star propSepViews have \"?T2 \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = ?T2 \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n            unfolding properSeparationOfViews_def\n            by (metis Int_commute projection_intersection_neutral)\n          moreover\n          note \\<alpha>2'Vv2_is_\\<alpha>Vv2 \\<alpha>2''Vv2_is_\\<alpha>2'Vv2\n          ultimately show ?thesis\n            by simp\n        qed\n      moreover\n      have \"?LAMBDA \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = ?T1 \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n        proof -\n          from propSepViews have \"?LAMBDA \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n            unfolding properSeparationOfViews_def by (simp only: projection_sequence)\n          moreover\n          from \\<alpha>1''_in_E1star propSepViews have \"?T1 \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = ?T1 \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n            unfolding properSeparationOfViews_def\n            by (metis Int_commute projection_intersection_neutral)\n          moreover\n          note \\<alpha>1'Vv1_is_\\<alpha>Vv1 \\<alpha>1''Vv1_is_\\<alpha>1'Vv1\n          ultimately show ?thesis\n            by simp\n        qed\n      moreover\n      note \\<alpha>2''Cv2_empty \\<alpha>1''Cv1_empty generalized_zipping_lemma\n      ultimately obtain t (* show that the conclusion of FCIA holds *)\n        where \"?TAU @ t \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n        and  \"t \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = ?LAMBDA\"\n        and \"t \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = []\"\n        by blast\n      moreover\n      have \"set \\<delta>' \\<subseteq> N\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>\\<^esub>\"\n        proof -\n          from \\<delta>'_contains_only_\\<delta>2''_\\<delta>1''_events \n            \\<delta>2''_in_N2_inter_Delta2star \\<delta>1''_in_N1_inter_Delta1star\n          have \"set \\<delta>' \\<subseteq> N\\<^bsub>\\<V>2\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>2\\<^esub> \\<union> N\\<^bsub>\\<V>1\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>1\\<^esub>\"\n            by auto\n          with Delta1_N1_Delta2_N2_subset_Delta Nv1_union_Nv2_subsetof_Nv show ?thesis\n            by auto\n        qed\n      ultimately have \"\\<exists>\\<alpha>' \\<gamma>'. (set \\<gamma>' \\<subseteq> N\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>\\<^esub> \\<and> \\<beta> @ [c] @ \\<gamma>' @ [v'] @ \\<alpha>' \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub> \n        \\<and> \\<alpha>' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> \\<and> \\<alpha>' \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = [])\"\n        by (simp only: append_assoc, blast)\n    }\n    ultimately have \"\\<exists>\\<alpha>' \\<gamma>'. (set \\<gamma>' \\<subseteq> N\\<^bsub>\\<V>\\<^esub> \\<inter> \\<Delta>\\<^bsub>\\<Gamma>\\<^esub> \\<and> \\<beta> @ [c] @ \\<gamma>' @ [v'] @ \\<alpha>' \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub> \n      \\<and> \\<alpha>' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = \\<alpha> \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> \\<and> \\<alpha>' \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = [])\"\n      by blast\n  }\n  thus ?thesis\n    unfolding FCIA_def\n    by blast\nqed\n\n(* Theorem 6.4.2 *)\ntheorem compositionality_R: \n\"\\<lbrakk> R \\<V>1 Tr\\<^bsub>ES1\\<^esub>; R \\<V>2 Tr\\<^bsub>ES2\\<^esub> \\<rbrakk> \\<Longrightarrow> R \\<V> (Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>)\"\n  proof -\n    assume R1: \"R \\<V>1 Tr\\<^bsub>ES1\\<^esub>\"\n    and R2: \"R \\<V>2 Tr\\<^bsub>ES2\\<^esub>\"\n\n    {\n      fix \\<tau>'\n      assume \\<tau>'_in_Tr: \"\\<tau>' \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n      hence \\<tau>'E1_in_Tr1: \"\\<tau>' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n        and \\<tau>'E2_in_Tr2: \"\\<tau>' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n        unfolding composeES_def\n        by auto\n      with R1 R2 obtain \\<tau>1' \\<tau>2'\n        where \\<tau>1'_in_Tr1: \"\\<tau>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n        and \\<tau>1'Cv1_empty: \"\\<tau>1' \\<upharpoonleft> C\\<^bsub>\\<V>1\\<^esub> = []\"\n        and \\<tau>1'Vv1_is_\\<tau>'_E1_Vv1: \"\\<tau>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<tau>' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n        and \\<tau>2'_in_Tr2: \"\\<tau>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n        and \\<tau>2'Cv2_empty: \"\\<tau>2' \\<upharpoonleft> C\\<^bsub>\\<V>2\\<^esub> = []\"\n        and \\<tau>2'Vv2_is_\\<tau>'_E2_Vv2: \"\\<tau>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<tau>' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n        unfolding R_def\n        by blast\n\n      have \"set [] \\<subseteq> E\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>\"\n        by auto\n      moreover\n      have \"set (\\<tau>' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>) \\<subseteq> V\\<^bsub>\\<V>\\<^esub>\"\n        by (simp add: projection_def, auto)\n      moreover\n      from validES1 \\<tau>1'_in_Tr1 have \\<tau>1'_in_E1: \"set \\<tau>1' \\<subseteq> E\\<^bsub>ES1\\<^esub>\"\n        by (simp add: ES_valid_def traces_contain_events_def, auto)\n      moreover\n      from validES2 \\<tau>2'_in_Tr2 have \\<tau>2'_in_E2: \"set \\<tau>2' \\<subseteq> E\\<^bsub>ES2\\<^esub>\"\n        by (simp add: ES_valid_def traces_contain_events_def, auto)\n      moreover\n      from \\<tau>1'_in_Tr1 have \"[] \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> @ \\<tau>1' \\<in> Tr\\<^bsub>ES1\\<^esub>\"\n        by (simp add: projection_def)\n      moreover\n      from \\<tau>2'_in_Tr2 have \"[] \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> @ \\<tau>2' \\<in> Tr\\<^bsub>ES2\\<^esub>\"\n        by (simp add: projection_def)\n      moreover\n      have \"\\<tau>' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<tau>1' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n        proof -\n          from projection_intersection_neutral[OF \\<tau>1'_in_E1, of \"V\\<^bsub>\\<V>\\<^esub>\"] propSepViews \n          have \"\\<tau>1' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = \\<tau>1' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n            unfolding properSeparationOfViews_def\n            by (simp add: Int_commute)\n          moreover\n          from  propSepViews have \"\\<tau>' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> = \\<tau>' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n            unfolding properSeparationOfViews_def\n            by (simp add: projection_sequence)\n          moreover {\n            have \" \\<tau>' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<tau>' \\<upharpoonleft> (E\\<^bsub>ES1\\<^esub> \\<inter> V\\<^bsub>\\<V>1\\<^esub>)\"\n              by (simp add: projection_def)\n            moreover\n            from validV1 have \"E\\<^bsub>ES1\\<^esub> \\<inter> V\\<^bsub>\\<V>1\\<^esub> = V\\<^bsub>\\<V>1\\<^esub>\"\n              by (simp add: isViewOn_def V_valid_def \n                VC_disjoint_def VN_disjoint_def NC_disjoint_def, auto)\n            ultimately have \"\\<tau>' \\<upharpoonleft> E\\<^bsub>ES1\\<^esub> \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub> = \\<tau>' \\<upharpoonleft> V\\<^bsub>\\<V>1\\<^esub>\"\n              by simp\n            }\n          moreover\n          note \\<tau>1'Vv1_is_\\<tau>'_E1_Vv1\n          ultimately show ?thesis\n            by simp\n        qed\n      moreover\n      have \"\\<tau>' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<tau>2' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub>\"\n        proof -\n          from projection_intersection_neutral[OF \\<tau>2'_in_E2, of \"V\\<^bsub>\\<V>\\<^esub>\"] propSepViews\n          have \"\\<tau>2' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = \\<tau>2' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n            unfolding properSeparationOfViews_def\n            by (simp add: Int_commute)\n          moreover\n          from  propSepViews have \"\\<tau>' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> = \\<tau>' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n            unfolding properSeparationOfViews_def\n            by (simp add: projection_sequence)\n          moreover {\n            have \" \\<tau>' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<tau>' \\<upharpoonleft> (E\\<^bsub>ES2\\<^esub> \\<inter> V\\<^bsub>\\<V>2\\<^esub>)\"\n              by (simp add: projection_def)\n            moreover\n            from validV2 have \"E\\<^bsub>ES2\\<^esub> \\<inter> V\\<^bsub>\\<V>2\\<^esub> = V\\<^bsub>\\<V>2\\<^esub>\"\n              by (simp add:isViewOn_def V_valid_def VC_disjoint_def \n                VN_disjoint_def NC_disjoint_def, auto)\n            ultimately have \"\\<tau>' \\<upharpoonleft> E\\<^bsub>ES2\\<^esub> \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub> = \\<tau>' \\<upharpoonleft> V\\<^bsub>\\<V>2\\<^esub>\"\n              by simp\n            }\n          moreover\n          note \\<tau>2'Vv2_is_\\<tau>'_E2_Vv2\n          ultimately show ?thesis\n            by simp\n        qed\n      moreover\n      note \\<tau>1'Cv1_empty \\<tau>2'Cv2_empty generalized_zipping_lemma\n      ultimately have \"\\<exists>t. [] @ t \\<in> Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub> \\<and> t \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> = \\<tau>' \\<upharpoonleft> V\\<^bsub>\\<V>\\<^esub> \\<and> t \\<upharpoonleft> C\\<^bsub>\\<V>\\<^esub> = []\"\n        by blast\n    }\n    thus ?thesis\n      unfolding R_def\n      by auto\n  qed\n\nend\n\nlocale CompositionalityStrictBSPs = Compositionality +\n(*adds the additional assumptions of theorem 6.4.3 in Heiko Mantel's phd thesis*)\nassumes N\\<V>_inter_E1_is_N\\<V>1: \"N\\<^bsub>\\<V>\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> = N\\<^bsub>\\<V>1\\<^esub>\"\n    and N\\<V>_inter_E2_is_N\\<V>2: \"N\\<^bsub>\\<V>\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> = N\\<^bsub>\\<V>2\\<^esub>\"\n\n(* sublocale relationship to other compositionality assumptions*)\nsublocale CompositionalityStrictBSPs \\<subseteq> Compositionality\nby (unfold_locales)\n\ncontext CompositionalityStrictBSPs\nbegin\n(*Theorem 6.4.3 Case 1 in Heiko Mantel's pdh thesis*)\ntheorem compositionality_SR: \n\"\\<lbrakk> SR \\<V>1 Tr\\<^bsub>ES1\\<^esub>; SR \\<V>2 Tr\\<^bsub>ES2\\<^esub> \\<rbrakk> \\<Longrightarrow> SR \\<V> (Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>)\" \nproof -\n  assume \"SR \\<V>1 Tr\\<^bsub>ES1\\<^esub>\"\n     and \"SR \\<V>2 Tr\\<^bsub>ES2\\<^esub>\"\n  { \n    let ?\\<V>\\<^sub>1'=\"\\<lparr>V = V\\<^bsub>\\<V>1\\<^esub> \\<union> N\\<^bsub>\\<V>1\\<^esub>, N = {}, C = C\\<^bsub>\\<V>1\\<^esub>\\<rparr>\"\n    let ?\\<V>\\<^sub>2'=\"\\<lparr>V = V\\<^bsub>\\<V>2\\<^esub> \\<union> N\\<^bsub>\\<V>2\\<^esub>, N = {}, C = C\\<^bsub>\\<V>2\\<^esub> \\<rparr>\"\n    let ?\\<V>' =\"\\<lparr>V=V\\<^bsub>\\<V>\\<^esub> \\<union> N\\<^bsub>\\<V>\\<^esub>, N={}, C=C\\<^bsub>\\<V>\\<^esub> \\<rparr>\" \n    (*Show ?\\<V>\\<^sub>1' ?\\<V>\\<^sub>2' ?\\<V>' are views on the respective set of events*)\n    from validV1 have \\<V>\\<^sub>1'IsViewOnE\\<^sub>1: \"isViewOn ?\\<V>\\<^sub>1' E\\<^bsub>ES1\\<^esub> \" \n      unfolding isViewOn_def V_valid_def  VN_disjoint_def NC_disjoint_def VC_disjoint_def by auto\n    from validV2 have \\<V>\\<^sub>2'IsViewOnE\\<^sub>2: \"isViewOn ?\\<V>\\<^sub>2' E\\<^bsub>ES2\\<^esub> \" \n      unfolding isViewOn_def V_valid_def  VN_disjoint_def NC_disjoint_def VC_disjoint_def by auto\n    from VIsViewOnE have \\<V>'IsViewOnE: \"isViewOn  ?\\<V>' E\\<^bsub>(ES1\\<parallel>ES2)\\<^esub>\" \n      unfolding isViewOn_def V_valid_def  VN_disjoint_def NC_disjoint_def VC_disjoint_def by auto\n    \n    (*Show ?\\<V>\\<^sub>1' and ?\\<V>\\<^sub>2' are proper separation of \\<lparr> V=\\<^bsub>\\<V>\\<^esub>, N={}, C=\\<^bsub>\\<V>\\<^esub> \\<rparr> *)\n     from propSepViews  N\\<V>_inter_E1_is_N\\<V>1\n     have \"V\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> = V\\<^bsub>?\\<V>\\<^sub>1'\\<^esub>\"\n       unfolding properSeparationOfViews_def by auto\n     from propSepViews   N\\<V>_inter_E2_is_N\\<V>2\n     have \"V\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> = V\\<^bsub>?\\<V>\\<^sub>2'\\<^esub>\"\n       unfolding properSeparationOfViews_def by auto\n     from propSepViews \n     have  \"C\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> C\\<^bsub>?\\<V>\\<^sub>1'\\<^esub>\"\n       unfolding properSeparationOfViews_def by auto      \n     from propSepViews\n     have  \"C\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> C\\<^bsub>?\\<V>\\<^sub>2'\\<^esub>\"\n       unfolding properSeparationOfViews_def by auto\n     have \"N\\<^bsub>?\\<V>\\<^sub>1'\\<^esub> \\<inter> N\\<^bsub>?\\<V>\\<^sub>2'\\<^esub> ={}\"\n       by auto\n     \n     note properSeparation_\\<V>\\<^sub>1\\<V>\\<^sub>2=\\<open>V\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> = V\\<^bsub>?\\<V>\\<^sub>1'\\<^esub>\\<close> \\<open>V\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> = V\\<^bsub>?\\<V>\\<^sub>2'\\<^esub>\\<close> \n              \\<open>C\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> C\\<^bsub>?\\<V>\\<^sub>1'\\<^esub>\\<close> \\<open>C\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> C\\<^bsub>?\\<V>\\<^sub>2'\\<^esub>\\<close> \\<open>N\\<^bsub>?\\<V>\\<^sub>1'\\<^esub> \\<inter> N\\<^bsub>?\\<V>\\<^sub>2'\\<^esub> ={}\\<close>\n    \n    (*Show ES1\\<parallel>ES2 is a well behaved composition w.r.t.  ?\\<V>\\<^sub>1' and ?\\<V>\\<^sub>2' *)\n     have wbc1: \"N\\<^bsub>?\\<V>\\<^sub>1'\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub>={} \\<and> N\\<^bsub>?\\<V>\\<^sub>2'\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub>={}\"\n       by auto\n     \n     \n    from \\<open>SR \\<V>1 Tr\\<^bsub>ES1\\<^esub>\\<close>  have \"R ?\\<V>\\<^sub>1' Tr\\<^bsub>ES1\\<^esub>\"      \n      using validES1 validV1 BSPTaxonomyDifferentCorrections.SR_implies_R_for_modified_view  \n      unfolding  BSPTaxonomyDifferentCorrections_def by auto\n    from \\<open>SR \\<V>2 Tr\\<^bsub>ES2\\<^esub>\\<close>  have \"R ?\\<V>\\<^sub>2' Tr\\<^bsub>ES2\\<^esub>\"     \n      using validES2 validV2  BSPTaxonomyDifferentCorrections.SR_implies_R_for_modified_view \n      unfolding BSPTaxonomyDifferentCorrections_def by auto   \n \n    from validES1 validES2 composableES1ES2  \\<V>'IsViewOnE \\<V>\\<^sub>1'IsViewOnE\\<^sub>1 \\<V>\\<^sub>2'IsViewOnE\\<^sub>2\n         properSeparation_\\<V>\\<^sub>1\\<V>\\<^sub>2  wbc1\n    have \"Compositionality ES1 ES2 ?\\<V>' ?\\<V>\\<^sub>1' ?\\<V>\\<^sub>2'\" unfolding Compositionality_def \n      by (simp add: properSeparationOfViews_def wellBehavedComposition_def)\n    with \\<open>R ?\\<V>\\<^sub>1' Tr\\<^bsub>ES1\\<^esub>\\<close> \\<open>R ?\\<V>\\<^sub>2' Tr\\<^bsub>ES2\\<^esub>\\<close> have \"R ?\\<V>' Tr\\<^bsub>(ES1\\<parallel>ES2)\\<^esub>\" \n     using Compositionality.compositionality_R by blast\n     \n   from  validES1 validES2 composeES_yields_ES validVC\n   have \"BSPTaxonomyDifferentCorrections (ES1\\<parallel>ES2) \\<V>\"\n      unfolding BSPTaxonomyDifferentCorrections_def by auto \n    with \\<open>R ?\\<V>' Tr\\<^bsub>(ES1\\<parallel>ES2)\\<^esub>\\<close> have \"SR \\<V> Tr\\<^bsub>(ES1\\<parallel>ES2)\\<^esub>\" \n      using BSPTaxonomyDifferentCorrections.R_implies_SR_for_modified_view  by auto \n  }\n  thus ?thesis by auto  \nqed\n\n(*Theorem 6.4.3 Case 2 in Heiko Mantel's pdh thesis*)\ntheorem compositionality_SD: \n\"\\<lbrakk> SD \\<V>1 Tr\\<^bsub>ES1\\<^esub>; SD \\<V>2 Tr\\<^bsub>ES2\\<^esub> \\<rbrakk> \\<Longrightarrow> SD \\<V> (Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>)\" \nproof -\n  assume \"SD \\<V>1 Tr\\<^bsub>ES1\\<^esub>\"\n     and \"SD \\<V>2 Tr\\<^bsub>ES2\\<^esub>\"\n  { \n    let ?\\<V>\\<^sub>1'=\"\\<lparr>V = V\\<^bsub>\\<V>1\\<^esub> \\<union> N\\<^bsub>\\<V>1\\<^esub>, N = {}, C = C\\<^bsub>\\<V>1\\<^esub>\\<rparr>\"\n    let ?\\<V>\\<^sub>2'=\"\\<lparr>V = V\\<^bsub>\\<V>2\\<^esub> \\<union> N\\<^bsub>\\<V>2\\<^esub>, N = {}, C = C\\<^bsub>\\<V>2\\<^esub> \\<rparr>\"\n    let ?\\<V>' =\"\\<lparr>V=V\\<^bsub>\\<V>\\<^esub> \\<union> N\\<^bsub>\\<V>\\<^esub>, N={}, C=C\\<^bsub>\\<V>\\<^esub> \\<rparr>\" \n    (*Show ?\\<V>\\<^sub>1' ?\\<V>\\<^sub>2' ?\\<V>' are views on the respective set of events*)\n    from validV1 have \\<V>\\<^sub>1'IsViewOnE\\<^sub>1: \"isViewOn ?\\<V>\\<^sub>1' E\\<^bsub>ES1\\<^esub> \" \n      unfolding isViewOn_def V_valid_def  VN_disjoint_def NC_disjoint_def VC_disjoint_def by auto\n    from validV2 have \\<V>\\<^sub>2'IsViewOnE\\<^sub>2: \"isViewOn ?\\<V>\\<^sub>2' E\\<^bsub>ES2\\<^esub> \" \n      unfolding isViewOn_def V_valid_def  VN_disjoint_def NC_disjoint_def VC_disjoint_def by auto\n    from VIsViewOnE have \\<V>'IsViewOnE: \"isViewOn  ?\\<V>' E\\<^bsub>(ES1\\<parallel>ES2)\\<^esub>\" \n      unfolding isViewOn_def V_valid_def  VN_disjoint_def NC_disjoint_def VC_disjoint_def by auto\n    \n    (*Show ?\\<V>\\<^sub>1' and ?\\<V>\\<^sub>2' are proper separation of \\<lparr> V=\\<^bsub>\\<V>\\<^esub>, N={}, C=\\<^bsub>\\<V>\\<^esub> \\<rparr> *)\n     from propSepViews  N\\<V>_inter_E1_is_N\\<V>1\n     have \"V\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> = V\\<^bsub>?\\<V>\\<^sub>1'\\<^esub>\" \n       unfolding properSeparationOfViews_def by auto\n     from propSepViews   N\\<V>_inter_E2_is_N\\<V>2\n     have \"V\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> = V\\<^bsub>?\\<V>\\<^sub>2'\\<^esub>\"\n       unfolding properSeparationOfViews_def by auto\n     from propSepViews \n     have  \"C\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> C\\<^bsub>?\\<V>\\<^sub>1'\\<^esub>\"\n       unfolding properSeparationOfViews_def by auto      \n     from propSepViews\n     have  \"C\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> C\\<^bsub>?\\<V>\\<^sub>2'\\<^esub>\"\n       unfolding properSeparationOfViews_def by auto\n     have \"N\\<^bsub>?\\<V>\\<^sub>1'\\<^esub> \\<inter> N\\<^bsub>?\\<V>\\<^sub>2'\\<^esub> ={}\"\n       by auto\n     \n     note properSeparation_\\<V>\\<^sub>1\\<V>\\<^sub>2=\\<open>V\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> = V\\<^bsub>?\\<V>\\<^sub>1'\\<^esub>\\<close> \\<open>V\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> = V\\<^bsub>?\\<V>\\<^sub>2'\\<^esub>\\<close> \n              \\<open>C\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> C\\<^bsub>?\\<V>\\<^sub>1'\\<^esub>\\<close> \\<open>C\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> C\\<^bsub>?\\<V>\\<^sub>2'\\<^esub>\\<close> \\<open>N\\<^bsub>?\\<V>\\<^sub>1'\\<^esub> \\<inter> N\\<^bsub>?\\<V>\\<^sub>2'\\<^esub> ={}\\<close>\n    \n    (*Show ES1\\<parallel>ES2 is a well behaved composition w.r.t.  ?\\<V>\\<^sub>1' and ?\\<V>\\<^sub>2' *)\n     have wbc1: \"N\\<^bsub>?\\<V>\\<^sub>1'\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub>={} \\<and> N\\<^bsub>?\\<V>\\<^sub>2'\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub>={}\"\n       by auto\n     \n     \n    from \\<open>SD \\<V>1 Tr\\<^bsub>ES1\\<^esub>\\<close>  have \"BSD ?\\<V>\\<^sub>1' Tr\\<^bsub>ES1\\<^esub>\"      \n      using validES1 validV1 BSPTaxonomyDifferentCorrections.SD_implies_BSD_for_modified_view\n      unfolding  BSPTaxonomyDifferentCorrections_def by auto\n    from \\<open>SD \\<V>2 Tr\\<^bsub>ES2\\<^esub>\\<close>  have \"BSD ?\\<V>\\<^sub>2' Tr\\<^bsub>ES2\\<^esub>\"     \n      using validES2 validV2 BSPTaxonomyDifferentCorrections.SD_implies_BSD_for_modified_view\n      unfolding BSPTaxonomyDifferentCorrections_def by auto   \n \n    from validES1 validES2 composableES1ES2   \\<V>'IsViewOnE \\<V>\\<^sub>1'IsViewOnE\\<^sub>1 \\<V>\\<^sub>2'IsViewOnE\\<^sub>2\n         properSeparation_\\<V>\\<^sub>1\\<V>\\<^sub>2  wbc1\n    have \"Compositionality ES1 ES2 ?\\<V>' ?\\<V>\\<^sub>1' ?\\<V>\\<^sub>2'\"\n      unfolding Compositionality_def\n      by (simp add: properSeparationOfViews_def wellBehavedComposition_def)\n    with \\<open>BSD ?\\<V>\\<^sub>1' Tr\\<^bsub>ES1\\<^esub>\\<close> \\<open>BSD ?\\<V>\\<^sub>2' Tr\\<^bsub>ES2\\<^esub>\\<close> have \"BSD ?\\<V>' Tr\\<^bsub>(ES1\\<parallel>ES2)\\<^esub>\" \n     using Compositionality.compositionality_BSD by blast\n     \n   from  validES1 validES2 composeES_yields_ES validVC\n   have \"BSPTaxonomyDifferentCorrections (ES1\\<parallel>ES2) \\<V>\"\n      unfolding BSPTaxonomyDifferentCorrections_def by auto \n    with \\<open>BSD ?\\<V>' Tr\\<^bsub>(ES1\\<parallel>ES2)\\<^esub>\\<close> have \"SD \\<V> Tr\\<^bsub>(ES1\\<parallel>ES2)\\<^esub>\" \n      using BSPTaxonomyDifferentCorrections.BSD_implies_SD_for_modified_view  by auto \n  }\n  thus ?thesis by auto  \nqed\n\n(*Theorem 6.4.3 Case 3 in Heiko Mantel's pdh thesis*)\ntheorem compositionality_SI: \n\"\\<lbrakk>SD \\<V>1 Tr\\<^bsub>ES1\\<^esub>; SD \\<V>2 Tr\\<^bsub>ES2\\<^esub>; SI \\<V>1 Tr\\<^bsub>ES1\\<^esub>; SI \\<V>2 Tr\\<^bsub>ES2\\<^esub> \\<rbrakk> \n   \\<Longrightarrow> SI \\<V> (Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>)\" \nproof -\n  assume \"SD \\<V>1 Tr\\<^bsub>ES1\\<^esub>\"\n     and \"SD \\<V>2 Tr\\<^bsub>ES2\\<^esub>\"\n     and \"SI \\<V>1 Tr\\<^bsub>ES1\\<^esub>\"\n     and \"SI \\<V>2 Tr\\<^bsub>ES2\\<^esub>\"\n  { \n    let ?\\<V>\\<^sub>1'=\"\\<lparr>V = V\\<^bsub>\\<V>1\\<^esub> \\<union> N\\<^bsub>\\<V>1\\<^esub>, N = {}, C = C\\<^bsub>\\<V>1\\<^esub>\\<rparr>\"\n    let ?\\<V>\\<^sub>2'=\"\\<lparr>V = V\\<^bsub>\\<V>2\\<^esub> \\<union> N\\<^bsub>\\<V>2\\<^esub>, N = {}, C = C\\<^bsub>\\<V>2\\<^esub> \\<rparr>\"\n    let ?\\<V>' =\"\\<lparr>V=V\\<^bsub>\\<V>\\<^esub> \\<union> N\\<^bsub>\\<V>\\<^esub>, N={}, C=C\\<^bsub>\\<V>\\<^esub> \\<rparr>\" \n    (*Show ?\\<V>\\<^sub>1' ?\\<V>\\<^sub>2' ?\\<V>' are views on the respective set of events*)\n    from validV1 have \\<V>\\<^sub>1'IsViewOnE\\<^sub>1: \"isViewOn ?\\<V>\\<^sub>1' E\\<^bsub>ES1\\<^esub> \" \n      unfolding isViewOn_def V_valid_def  VN_disjoint_def NC_disjoint_def VC_disjoint_def by auto\n    from validV2 have \\<V>\\<^sub>2'IsViewOnE\\<^sub>2: \"isViewOn ?\\<V>\\<^sub>2' E\\<^bsub>ES2\\<^esub> \" \n      unfolding isViewOn_def V_valid_def  VN_disjoint_def NC_disjoint_def VC_disjoint_def by auto\n    from VIsViewOnE have \\<V>'IsViewOnE: \"isViewOn  ?\\<V>' E\\<^bsub>(ES1\\<parallel>ES2)\\<^esub>\" \n      unfolding isViewOn_def V_valid_def  VN_disjoint_def NC_disjoint_def VC_disjoint_def by auto\n    \n    (*Show ?\\<V>\\<^sub>1' and ?\\<V>\\<^sub>2' are proper separation of \\<lparr> V=\\<^bsub>\\<V>\\<^esub>, N={}, C=\\<^bsub>\\<V>\\<^esub> \\<rparr> *)\n     from propSepViews  N\\<V>_inter_E1_is_N\\<V>1\n     have \"V\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> = V\\<^bsub>?\\<V>\\<^sub>1'\\<^esub>\" \n       unfolding properSeparationOfViews_def by auto\n     from propSepViews   N\\<V>_inter_E2_is_N\\<V>2\n     have \"V\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> = V\\<^bsub>?\\<V>\\<^sub>2'\\<^esub>\" \n       unfolding properSeparationOfViews_def by auto\n     from propSepViews \n     have  \"C\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> C\\<^bsub>?\\<V>\\<^sub>1'\\<^esub>\" \n       unfolding properSeparationOfViews_def by auto      \n     from propSepViews\n     have  \"C\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> C\\<^bsub>?\\<V>\\<^sub>2'\\<^esub>\" \n       unfolding properSeparationOfViews_def by auto\n     have \"N\\<^bsub>?\\<V>\\<^sub>1'\\<^esub> \\<inter> N\\<^bsub>?\\<V>\\<^sub>2'\\<^esub> ={}\"\n       by auto\n     \n     note properSeparation_\\<V>\\<^sub>1\\<V>\\<^sub>2=\\<open>V\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> = V\\<^bsub>?\\<V>\\<^sub>1'\\<^esub>\\<close> \\<open>V\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> = V\\<^bsub>?\\<V>\\<^sub>2'\\<^esub>\\<close> \n              \\<open>C\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> C\\<^bsub>?\\<V>\\<^sub>1'\\<^esub>\\<close> \\<open>C\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> C\\<^bsub>?\\<V>\\<^sub>2'\\<^esub>\\<close> \\<open>N\\<^bsub>?\\<V>\\<^sub>1'\\<^esub> \\<inter> N\\<^bsub>?\\<V>\\<^sub>2'\\<^esub> ={}\\<close>\n    \n    (*Show ES1\\<parallel>ES2 is a well behaved composition w.r.t.  ?\\<V>\\<^sub>1' and ?\\<V>\\<^sub>2' *)\n     have wbc1: \"N\\<^bsub>?\\<V>\\<^sub>1'\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub>={} \\<and> N\\<^bsub>?\\<V>\\<^sub>2'\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub>={}\"\n       by auto\n     \n    from \\<open>SD \\<V>1 Tr\\<^bsub>ES1\\<^esub>\\<close>  have \"BSD ?\\<V>\\<^sub>1' Tr\\<^bsub>ES1\\<^esub>\"      \n      using validES1 validV1 BSPTaxonomyDifferentCorrections.SD_implies_BSD_for_modified_view \n      unfolding  BSPTaxonomyDifferentCorrections_def by auto\n    from \\<open>SD \\<V>2 Tr\\<^bsub>ES2\\<^esub>\\<close>  have \"BSD ?\\<V>\\<^sub>2' Tr\\<^bsub>ES2\\<^esub>\"     \n      using validES2 validV2 BSPTaxonomyDifferentCorrections.SD_implies_BSD_for_modified_view \n      unfolding BSPTaxonomyDifferentCorrections_def by auto  \n    from \\<open>SI \\<V>1 Tr\\<^bsub>ES1\\<^esub>\\<close>  have \"BSI ?\\<V>\\<^sub>1' Tr\\<^bsub>ES1\\<^esub>\"      \n      using validES1 validV1 BSPTaxonomyDifferentCorrections.SI_implies_BSI_for_modified_view \n      unfolding  BSPTaxonomyDifferentCorrections_def by auto\n    from \\<open>SI \\<V>2 Tr\\<^bsub>ES2\\<^esub>\\<close>  have \"BSI ?\\<V>\\<^sub>2' Tr\\<^bsub>ES2\\<^esub>\"     \n      using validES2 validV2 BSPTaxonomyDifferentCorrections.SI_implies_BSI_for_modified_view \n      unfolding BSPTaxonomyDifferentCorrections_def by auto   \n\n    from validES1 validES2 composableES1ES2  \\<V>'IsViewOnE \\<V>\\<^sub>1'IsViewOnE\\<^sub>1 \\<V>\\<^sub>2'IsViewOnE\\<^sub>2\n         properSeparation_\\<V>\\<^sub>1\\<V>\\<^sub>2  wbc1\n    have \"Compositionality ES1 ES2 ?\\<V>' ?\\<V>\\<^sub>1' ?\\<V>\\<^sub>2'\" unfolding Compositionality_def \n      by (simp add: properSeparationOfViews_def wellBehavedComposition_def)\n    with \\<open>BSD ?\\<V>\\<^sub>1' Tr\\<^bsub>ES1\\<^esub>\\<close> \\<open>BSD ?\\<V>\\<^sub>2' Tr\\<^bsub>ES2\\<^esub>\\<close> \\<open>BSI  ?\\<V>\\<^sub>1' Tr\\<^bsub>ES1\\<^esub>\\<close> \\<open>BSI ?\\<V>\\<^sub>2' Tr\\<^bsub>ES2\\<^esub>\\<close>\n    have \"BSI ?\\<V>' Tr\\<^bsub>(ES1\\<parallel>ES2)\\<^esub>\" \n     using Compositionality.compositionality_BSI by blast\n     \n   from  validES1 validES2 composeES_yields_ES validVC\n   have \"BSPTaxonomyDifferentCorrections (ES1\\<parallel>ES2) \\<V>\"\n      unfolding BSPTaxonomyDifferentCorrections_def by auto \n    with \\<open>BSI ?\\<V>' Tr\\<^bsub>(ES1\\<parallel>ES2)\\<^esub>\\<close> have \"SI \\<V> Tr\\<^bsub>(ES1\\<parallel>ES2)\\<^esub>\" \n      using BSPTaxonomyDifferentCorrections.BSI_implies_SI_for_modified_view  by auto \n  }\n  thus ?thesis by auto  \nqed\n\n\n(*Theorem 6.4.3 Case 4 in Heiko Mantel's pdh thesis*)\ntheorem compositionality_SIA: \n\"\\<lbrakk>SD \\<V>1 Tr\\<^bsub>ES1\\<^esub>; SD \\<V>2 Tr\\<^bsub>ES2\\<^esub>; SIA \\<rho>1 \\<V>1 Tr\\<^bsub>ES1\\<^esub>; SIA \\<rho>2 \\<V>2 Tr\\<^bsub>ES2\\<^esub>; \n  (\\<rho>1 \\<V>1) \\<subseteq> (\\<rho> \\<V>) \\<inter> E\\<^bsub>ES1\\<^esub>; (\\<rho>2 \\<V>2) \\<subseteq> (\\<rho> \\<V>) \\<inter> E\\<^bsub>ES2\\<^esub> \\<rbrakk>\n   \\<Longrightarrow> SIA \\<rho> \\<V> (Tr\\<^bsub>(ES1 \\<parallel> ES2)\\<^esub>)\"\nproof -\n  assume \"SD \\<V>1 Tr\\<^bsub>ES1\\<^esub>\"\n     and \"SD \\<V>2 Tr\\<^bsub>ES2\\<^esub>\"\n     and \"SIA \\<rho>1 \\<V>1 Tr\\<^bsub>ES1\\<^esub>\"\n     and \"SIA \\<rho>2 \\<V>2 Tr\\<^bsub>ES2\\<^esub>\"\n     and \"(\\<rho>1 \\<V>1) \\<subseteq> (\\<rho> \\<V>) \\<inter> E\\<^bsub>ES1\\<^esub>\"\n     and \"(\\<rho>2 \\<V>2) \\<subseteq> (\\<rho> \\<V>) \\<inter> E\\<^bsub>ES2\\<^esub>\"\n  { \n    let ?\\<V>\\<^sub>1' =\"\\<lparr>V = V\\<^bsub>\\<V>1\\<^esub> \\<union> N\\<^bsub>\\<V>1\\<^esub>, N = {}, C = C\\<^bsub>\\<V>1\\<^esub>\\<rparr>\"\n    let ?\\<V>\\<^sub>2'=\"\\<lparr>V = V\\<^bsub>\\<V>2\\<^esub> \\<union> N\\<^bsub>\\<V>2\\<^esub>, N = {}, C = C\\<^bsub>\\<V>2\\<^esub> \\<rparr>\"\n    let ?\\<V>' =\"\\<lparr>V=V\\<^bsub>\\<V>\\<^esub> \\<union> N\\<^bsub>\\<V>\\<^esub>, N={}, C=C\\<^bsub>\\<V>\\<^esub> \\<rparr>\" \n    \n    (*Fix some intermediate rho's such that (\\<rho>1' ?\\<V>\\<^sub>1') = (\\<rho>1 \\<V>1), (\\<rho>2' ?\\<V>\\<^sub>2') = (\\<rho>2 \\<V>2)  and\n      (\\<rho>' ?\\<V>') = (\\<rho> \\<V>) hold.*)\n    let \"?\\<rho>1'::'a Rho\" =\"\\<lambda>\\<V>. if \\<V>=?\\<V>\\<^sub>1' then \\<rho>1 \\<V>1  else {}\"\n    let \"?\\<rho>2'::'a Rho\" =\"\\<lambda>\\<V>. if \\<V>=?\\<V>\\<^sub>2' then \\<rho>2 \\<V>2  else {}\"\n    let \"?\\<rho>'::'a Rho\" =\"\\<lambda>\\<V>'. if \\<V>'=?\\<V>' then \\<rho> \\<V>  else {}\"\n    \n    have \"(?\\<rho>1' ?\\<V>\\<^sub>1') = (\\<rho>1 \\<V>1)\" by simp \n    have \"(?\\<rho>2' ?\\<V>\\<^sub>2') = (\\<rho>2 \\<V>2)\" by simp\n    have \"(?\\<rho>' ?\\<V>') = (\\<rho> \\<V>)\" by simp\n\n    (*Show ?\\<V>\\<^sub>1' ?\\<V>\\<^sub>2' ?\\<V>' are views on the respective set of events*)\n    from validV1 have \\<V>\\<^sub>1'IsViewOnE\\<^sub>1: \"isViewOn ?\\<V>\\<^sub>1' E\\<^bsub>ES1\\<^esub> \" \n      unfolding isViewOn_def V_valid_def  VN_disjoint_def NC_disjoint_def VC_disjoint_def by auto\n    from validV2 have \\<V>\\<^sub>2'IsViewOnE\\<^sub>2: \"isViewOn ?\\<V>\\<^sub>2' E\\<^bsub>ES2\\<^esub> \" \n      unfolding isViewOn_def V_valid_def  VN_disjoint_def NC_disjoint_def VC_disjoint_def by auto\n    from VIsViewOnE have \\<V>'IsViewOnE: \"isViewOn  ?\\<V>' E\\<^bsub>(ES1\\<parallel>ES2)\\<^esub>\" \n      unfolding isViewOn_def V_valid_def  VN_disjoint_def NC_disjoint_def VC_disjoint_def by auto\n    \n    (*Show ?\\<V>\\<^sub>1' and ?\\<V>\\<^sub>2' are proper separation of \\<lparr> V=\\<^bsub>\\<V>\\<^esub>, N={}, C=\\<^bsub>\\<V>\\<^esub> \\<rparr> *)\n     from propSepViews  N\\<V>_inter_E1_is_N\\<V>1\n     have \"V\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> = V\\<^bsub>?\\<V>\\<^sub>1'\\<^esub>\"\n       unfolding properSeparationOfViews_def by auto\n     from propSepViews   N\\<V>_inter_E2_is_N\\<V>2\n     have \"V\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> = V\\<^bsub>?\\<V>\\<^sub>2'\\<^esub>\"\n       unfolding properSeparationOfViews_def by auto\n     from propSepViews \n     have  \"C\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> C\\<^bsub>?\\<V>\\<^sub>1'\\<^esub>\"\n       unfolding properSeparationOfViews_def by auto      \n     from propSepViews\n     have  \"C\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> C\\<^bsub>?\\<V>\\<^sub>2'\\<^esub>\"\n       unfolding properSeparationOfViews_def by auto\n     have \"N\\<^bsub>?\\<V>\\<^sub>1'\\<^esub> \\<inter> N\\<^bsub>?\\<V>\\<^sub>2'\\<^esub> ={}\"\n       by auto\n     \n     note properSeparation_\\<V>\\<^sub>1\\<V>\\<^sub>2=\\<open>V\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> = V\\<^bsub>?\\<V>\\<^sub>1'\\<^esub>\\<close> \\<open>V\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> = V\\<^bsub>?\\<V>\\<^sub>2'\\<^esub>\\<close> \n              \\<open>C\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub> \\<subseteq> C\\<^bsub>?\\<V>\\<^sub>1'\\<^esub>\\<close> \\<open>C\\<^bsub>?\\<V>'\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub> \\<subseteq> C\\<^bsub>?\\<V>\\<^sub>2'\\<^esub>\\<close> \\<open>N\\<^bsub>?\\<V>\\<^sub>1'\\<^esub> \\<inter> N\\<^bsub>?\\<V>\\<^sub>2'\\<^esub> ={}\\<close>\n    \n    (*Show ES1\\<parallel>ES2 is a well behaved composition w.r.t.  ?\\<V>\\<^sub>1' and ?\\<V>\\<^sub>2' *)\n     have wbc1: \"N\\<^bsub>?\\<V>\\<^sub>1'\\<^esub> \\<inter> E\\<^bsub>ES1\\<^esub>={} \\<and> N\\<^bsub>?\\<V>\\<^sub>2'\\<^esub> \\<inter> E\\<^bsub>ES2\\<^esub>={}\" \n       by auto\n    \n      \n    from \\<open>SD \\<V>1 Tr\\<^bsub>ES1\\<^esub>\\<close>  have \"BSD ?\\<V>\\<^sub>1' Tr\\<^bsub>ES1\\<^esub>\"      \n      using validES1 validV1 BSPTaxonomyDifferentCorrections.SD_implies_BSD_for_modified_view \n      unfolding  BSPTaxonomyDifferentCorrections_def by auto\n    from \\<open>SD \\<V>2 Tr\\<^bsub>ES2\\<^esub>\\<close>  have \"BSD ?\\<V>\\<^sub>2' Tr\\<^bsub>ES2\\<^esub>\"     \n      using validES2 validV2 BSPTaxonomyDifferentCorrections.SD_implies_BSD_for_modified_view \n      unfolding BSPTaxonomyDifferentCorrections_def by auto \n\n    from \\<open>SIA \\<rho>1 \\<V>1 Tr\\<^bsub>ES1\\<^esub>\\<close> \\<open>(?\\<rho>1' ?\\<V>\\<^sub>1') = (\\<rho>1 \\<V>1)\\<close>  have \"BSIA ?\\<rho>1' ?\\<V>\\<^sub>1' Tr\\<^bsub>ES1\\<^esub>\"      \n      using validES1 validV1 BSPTaxonomyDifferentCorrections.SIA_implies_BSIA_for_modified_view \n      unfolding  BSPTaxonomyDifferentCorrections_def by fastforce\n    from \\<open>SIA \\<rho>2 \\<V>2 Tr\\<^bsub>ES2\\<^esub>\\<close> \\<open>(?\\<rho>2' ?\\<V>\\<^sub>2') = (\\<rho>2 \\<V>2)\\<close>  have \"BSIA ?\\<rho>2' ?\\<V>\\<^sub>2' Tr\\<^bsub>ES2\\<^esub>\"     \n      using validES2 validV2 BSPTaxonomyDifferentCorrections.SIA_implies_BSIA_for_modified_view \n      unfolding BSPTaxonomyDifferentCorrections_def by fastforce   \n\n    from validES1 validES2 composableES1ES2  \\<V>'IsViewOnE \\<V>\\<^sub>1'IsViewOnE\\<^sub>1 \\<V>\\<^sub>2'IsViewOnE\\<^sub>2\n         properSeparation_\\<V>\\<^sub>1\\<V>\\<^sub>2  wbc1\n    have \"Compositionality ES1 ES2 ?\\<V>' ?\\<V>\\<^sub>1' ?\\<V>\\<^sub>2'\" \n      unfolding Compositionality_def \n      by (simp add: properSeparationOfViews_def wellBehavedComposition_def)\n    from \\<open>(\\<rho>1 \\<V>1) \\<subseteq> (\\<rho> \\<V>) \\<inter> E\\<^bsub>ES1\\<^esub>\\<close> \\<open>(?\\<rho>1' ?\\<V>\\<^sub>1') = (\\<rho>1 \\<V>1)\\<close> \\<open>(?\\<rho>' ?\\<V>') = (\\<rho> \\<V>)\\<close>\n    have \"?\\<rho>1' ?\\<V>\\<^sub>1'  \\<subseteq>  ?\\<rho>'  ?\\<V>' \\<inter> E\\<^bsub>ES1\\<^esub>\"\n      by auto \n    from \\<open>(\\<rho>2 \\<V>2) \\<subseteq> (\\<rho> \\<V>) \\<inter> E\\<^bsub>ES2\\<^esub>\\<close> \\<open>(?\\<rho>2' ?\\<V>\\<^sub>2') = (\\<rho>2 \\<V>2)\\<close> \\<open>(?\\<rho>' ?\\<V>') = (\\<rho> \\<V>)\\<close>\n    have \"?\\<rho>2' ?\\<V>\\<^sub>2'  \\<subseteq>  ?\\<rho>'  ?\\<V>' \\<inter> E\\<^bsub>ES2\\<^esub>\"\n      by auto   \n\n    from \\<open>Compositionality ES1 ES2 ?\\<V>' ?\\<V>\\<^sub>1' ?\\<V>\\<^sub>2'\\<close> \\<open>BSD ?\\<V>\\<^sub>1' Tr\\<^bsub>ES1\\<^esub>\\<close> \\<open>BSD ?\\<V>\\<^sub>2' Tr\\<^bsub>ES2\\<^esub>\\<close> \n          \\<open>BSIA ?\\<rho>1' ?\\<V>\\<^sub>1' Tr\\<^bsub>ES1\\<^esub>\\<close> \\<open>BSIA ?\\<rho>2' ?\\<V>\\<^sub>2' Tr\\<^bsub>ES2\\<^esub>\\<close> \n          \\<open>?\\<rho>1' ?\\<V>\\<^sub>1'  \\<subseteq>  ?\\<rho>'  ?\\<V>' \\<inter> E\\<^bsub>ES1\\<^esub>\\<close> \\<open>?\\<rho>2' ?\\<V>\\<^sub>2'  \\<subseteq>  ?\\<rho>'  ?\\<V>' \\<inter> E\\<^bsub>ES2\\<^esub>\\<close>\n    have \"BSIA ?\\<rho>' ?\\<V>' Tr\\<^bsub>(ES1\\<parallel>ES2)\\<^esub>\"\n      using Compositionality.compositionality_BSIA by fastforce\n      \n    from  validES1 validES2 composeES_yields_ES validVC \n    have \"BSPTaxonomyDifferentCorrections (ES1\\<parallel>ES2) \\<V>\" \n      unfolding BSPTaxonomyDifferentCorrections_def by auto \n    with \\<open>BSIA ?\\<rho>' ?\\<V>' Tr\\<^bsub>(ES1\\<parallel>ES2)\\<^esub>\\<close> \\<open>(?\\<rho>' ?\\<V>') = (\\<rho> \\<V>)\\<close> have \"SIA \\<rho> \\<V> Tr\\<^bsub>(ES1\\<parallel>ES2)\\<^esub>\" \n      using BSPTaxonomyDifferentCorrections.BSIA_implies_SIA_for_modified_view  by fastforce\n  }\n  thus ?thesis\n    by auto  \nqed\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Modular_Assembly_Kit_Security/Verification/Compositionality/CompositionalityResults.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6370307944803831, "lm_q2_score": 0.4532618480153861, "lm_q1q2_score": 0.28874175514888806}}
{"text": "theory TrivialArityAnal\nimports ArityAnalysisSpec \"Launchbury.Env-Nominal\"\nbegin\n\ndefinition Trivial_Aexp :: \"exp \\<Rightarrow> Arity \\<rightarrow> AEnv\"\n  where \"Trivial_Aexp e = (\\<Lambda> n. (\\<lambda> x. up\\<cdot>0) f|` fv e)\"\n\nlemma Trivial_Aexp_simp: \"Trivial_Aexp e \\<cdot> n = (\\<lambda> x. up\\<cdot>0) f|` fv e\"\n  unfolding Trivial_Aexp_def by simp\n\nlemma edom_Trivial_Aexp[simp]: \"edom (Trivial_Aexp e \\<cdot> n) = fv e\"\n  by (auto simp add: edom_def env_restr_def Trivial_Aexp_def) \n\nlemma Trivial_Aexp_eq[iff]: \"Trivial_Aexp e \\<cdot> n = Trivial_Aexp e' \\<cdot> n' \\<longleftrightarrow> fv e = (fv e' :: var set)\"\n  apply (auto simp add: Trivial_Aexp_simp env_restr_def)\n  apply (metis up_defined)+\n  done\n  \nlemma below_Trivial_Aexp[simp]: \"(ae \\<sqsubseteq> Trivial_Aexp e \\<cdot> n) \\<longleftrightarrow> edom ae \\<subseteq> fv e\"\n  by (auto dest:fun_belowD intro!: fun_belowI  simp add: Trivial_Aexp_def env_restr_def edom_def split:if_splits)\n\n\ninterpretation ArityAnalysis Trivial_Aexp.\ninterpretation EdomArityAnalysis Trivial_Aexp\n  by standard simp\n\n\ninterpretation ArityAnalysisSafe Trivial_Aexp\nproof\n(*\n  fix \\<pi>\n  show \"\\<pi> \\<bullet> Trivial_Aexp = Trivial_Aexp\" by perm_simp rule\nnext\n*)\n  fix n x\n  show \"up\\<cdot>n \\<sqsubseteq> (Trivial_Aexp (Var x)\\<cdot>n) x\"\n    by (simp add: Trivial_Aexp_simp)\nnext\n  fix e x n\n  show \"Trivial_Aexp e\\<cdot>(inc\\<cdot>n) \\<squnion> esing x\\<cdot>(up\\<cdot>0) \\<sqsubseteq> Trivial_Aexp (App e x)\\<cdot>n\"\n    by (auto intro: fun_belowI simp add: Trivial_Aexp_def env_restr_def )\nnext\n  fix y e n\n  show \"env_delete y (Trivial_Aexp e\\<cdot>(pred\\<cdot>n)) \\<sqsubseteq> Trivial_Aexp (Lam [y]. e)\\<cdot>n\"\n    by (auto simp add: Trivial_Aexp_simp env_delete_restr Diff_eq inf_commute)\nnext\n  fix x y :: var and S e a\n  assume \"x \\<notin> S\" and \"y \\<notin> S\"\n  thus \"Trivial_Aexp e[x::=y]\\<cdot>a f|` S = Trivial_Aexp e\\<cdot>a f|` S\"\n    by (auto simp add: Trivial_Aexp_simp fv_subst_eq intro!: arg_cong[where f = \"\\<lambda> S. env_restr S e\" for e])\nnext\n  fix scrut e1 a e2\n  show \"Trivial_Aexp scrut\\<cdot>0 \\<squnion> Trivial_Aexp e1\\<cdot>a \\<squnion> Trivial_Aexp e2\\<cdot>a \\<sqsubseteq> Trivial_Aexp (scrut ? e1 : e2)\\<cdot>a\"\n    by (auto intro: env_restr_mono2 simp add: Trivial_Aexp_simp join_below_iff )\nqed\n\ndefinition Trivial_Aheap :: \"heap \\<Rightarrow> exp \\<Rightarrow> Arity \\<rightarrow> AEnv\" where\n  \"Trivial_Aheap \\<Gamma> e = (\\<Lambda> a. (\\<lambda> x. up\\<cdot>0) f|` domA \\<Gamma>)\"\n\nlemma Trivial_Aheap_eqvt[eqvt]: \"\\<pi> \\<bullet>  (Trivial_Aheap \\<Gamma> e) = Trivial_Aheap (\\<pi> \\<bullet> \\<Gamma>) (\\<pi> \\<bullet> e)\"\n  unfolding Trivial_Aheap_def\n  apply perm_simp\n  apply (simp add: Abs_cfun_eqvt)\n  done\n\nlemma Trivial_Aheap_simp: \"Trivial_Aheap \\<Gamma> e\\<cdot> a = (\\<lambda> x. up\\<cdot>0) f|` domA \\<Gamma>\"\n  unfolding Trivial_Aheap_def by simp\n\nlemma Trivial_fup_Aexp_below_fv: \"fup\\<cdot>(Trivial_Aexp e)\\<cdot>a \\<sqsubseteq> (\\<lambda> x . up\\<cdot>0) f|` fv e\"\n  by (cases a)(auto simp add: Trivial_Aexp_simp)\n\nlemma Trivial_Abinds_below_fv: \"ABinds \\<Gamma>\\<cdot>ae \\<sqsubseteq> (\\<lambda> x . up\\<cdot>0) f|` fv \\<Gamma>\"\n  by (induction \\<Gamma> rule:ABinds.induct)\n     (auto simp add: join_below_iff intro!: below_trans[OF Trivial_fup_Aexp_below_fv] env_restr_mono2 elim: below_trans dest: subsetD[OF fv_delete_subset] simp del: fun_meet_simp)\n\ninterpretation ArityAnalysisLetSafe Trivial_Aexp Trivial_Aheap\nproof\n  fix \\<pi>\n  show \"\\<pi> \\<bullet> Trivial_Aheap = Trivial_Aheap\" by perm_simp rule  \nnext\n  fix \\<Gamma> e ae show \"edom (Trivial_Aheap \\<Gamma> e\\<cdot>ae) \\<subseteq> domA \\<Gamma>\"\n  by (simp add: Trivial_Aheap_simp)\nnext\n  fix \\<Gamma> :: heap and e and a\n  show \"ABinds \\<Gamma>\\<cdot>(Trivial_Aheap \\<Gamma> e\\<cdot>a) \\<squnion> Trivial_Aexp e\\<cdot>a \\<sqsubseteq> Trivial_Aheap \\<Gamma> e\\<cdot>a \\<squnion> Trivial_Aexp (Terms.Let \\<Gamma> e)\\<cdot>a\"\n    by (auto simp add: Trivial_Aheap_simp Trivial_Aexp_simp join_below_iff env_restr_join2 intro!: env_restr_mono2 below_trans[OF Trivial_Abinds_below_fv])\nnext\n  fix x y :: var and \\<Gamma> :: heap and e\n  assume \"x \\<notin> domA \\<Gamma>\" and \"y \\<notin> domA \\<Gamma>\"\n  thus \"Trivial_Aheap \\<Gamma>[x::h=y] e[x::=y] = Trivial_Aheap \\<Gamma> e\"\n    by (auto intro: cfun_eqI simp add: Trivial_Aheap_simp)\nqed\n\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Call_Arity/TrivialArityAnal.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6370307806984444, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.2887417489020611}}
{"text": "theory TopoS_Stateful_Policy_Algorithm\nimports TopoS_Stateful_Policy TopoS_Composition_Theory\nbegin\n\nsection\\<open>Stateful Policy -- Algorithm\\<close>\n\nsubsection\\<open>Some unimportant lemmata\\<close>\n  lemma False_set: \"{(r, s). False} = {}\" by simp\n  lemma valid_reqs_ACS_D: \"valid_reqs M \\<Longrightarrow> valid_reqs (get_ACS M)\"\n    by(simp add: valid_reqs_def get_ACS_def)\n  lemma valid_reqs_IFS_D: \"valid_reqs M \\<Longrightarrow> valid_reqs (get_IFS M)\"\n    by(simp add: valid_reqs_def get_IFS_def)\n  lemma all_security_requirements_fulfilled_ACS_D: \"all_security_requirements_fulfilled M G \\<Longrightarrow>\n    all_security_requirements_fulfilled (get_ACS M) G\"\n    by(simp add: all_security_requirements_fulfilled_def get_ACS_def)\n  lemma all_security_requirements_fulfilled_IFS_D: \"all_security_requirements_fulfilled M G \\<Longrightarrow>\n    all_security_requirements_fulfilled (get_IFS M) G\"\n    by(simp add: all_security_requirements_fulfilled_def get_IFS_def)\n  lemma all_security_requirements_fulfilled_mono_stateful_policy_to_network_graph:\n      \"\\<lbrakk> valid_reqs M; E' \\<subseteq> E; wf_graph \\<lparr> nodes = V, edges = Efix \\<union> E \\<rparr> \\<rbrakk> \\<Longrightarrow>  \n        all_security_requirements_fulfilled M \n          (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = Efix, flows_state = E \\<rparr>)\\<Longrightarrow>\n        all_security_requirements_fulfilled M \n          (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = Efix, flows_state = E' \\<rparr>)\"\n    apply(simp add: stateful_policy_to_network_graph_def all_flows_def)\n    apply(drule all_security_requirements_fulfilled_mono[where E=\"Efix \\<union> E \\<union> backflows E\" and E'=\"Efix \\<union> E' \\<union> backflows E'\" and V=\"V\"])\n       apply(thin_tac \"wf_graph G\" for G)\n       apply(thin_tac \"all_security_requirements_fulfilled M G\" for M G)\n       apply(simp add: backflows_def, blast)\n      apply(thin_tac \"all_security_requirements_fulfilled M G\" for M G)\n      apply(simp add: wf_graph_def)\n      apply(simp add: backflows_def)\n      using [[simproc add: finite_Collect]] apply(auto)[1]\n     apply(simp_all)\n   done\n\n\nsubsection \\<open>Sketch for generating a stateful policy from a simple directed policy\\<close>\n  text\\<open>Having no stateful flows, we trivially get a valid stateful policy.\\<close>\n    lemma trivial_stateful_policy_compliance:\n    \"\\<lbrakk> wf_graph \\<lparr> nodes = V, edges = E \\<rparr>; valid_reqs M; all_security_requirements_fulfilled M \\<lparr> nodes = V, edges = E \\<rparr> \\<rbrakk> \\<Longrightarrow> \n      stateful_policy_compliance \\<lparr> hosts = V, flows_fix = E, flows_state = {} \\<rparr> \\<lparr> nodes = V, edges = E \\<rparr> M\"\n      apply(unfold_locales)\n                   apply(simp_all add: wf_graph_def stateful_policy_to_network_graph_def all_flows_def backflows_def False_set)\n       apply(simp add: get_IFS_def get_ACS_def all_security_requirements_fulfilled_def)\n      apply(clarify)\n      apply(drule valid_reqs_ACS_D) \n      apply(drule all_security_requirements_fulfilled_ACS_D)\n      apply(drule(1) all_security_requirements_fulfilled_imp_get_offending_empty)\n      by force\n\n\n  text\\<open>trying better\\<close>\n\n    text\\<open>First, filtering flows that cause no IFS violations\\<close>\n    (*the edges front of the list are more likely to be kept*)\n    fun filter_IFS_no_violations_accu :: \"'v::vertex graph \\<Rightarrow> 'v SecurityInvariant_configured list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> ('v \\<times> 'v) list\" where\n      \"filter_IFS_no_violations_accu G M accu [] = accu\" |\n      \"filter_IFS_no_violations_accu G M accu (e#Es) = (if\n        all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<lparr> hosts = nodes G, flows_fix = edges G, flows_state = set (e#accu) \\<rparr>)\n        then filter_IFS_no_violations_accu G M (e#accu) Es\n        else filter_IFS_no_violations_accu G M accu Es)\"\n    definition filter_IFS_no_violations :: \"'v::vertex graph \\<Rightarrow> 'v SecurityInvariant_configured list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> ('v \\<times> 'v) list\" where\n      \"filter_IFS_no_violations G M Es = filter_IFS_no_violations_accu G M [] Es\"\n\n\n    lemma filter_IFS_no_violations_subseteq_input: \"set (filter_IFS_no_violations G M Es) \\<subseteq> set Es\"\n    apply(subgoal_tac \"\\<forall> accu. set (filter_IFS_no_violations_accu G M accu Es) \\<subseteq> set Es \\<union> set accu\")\n     apply(erule_tac x=\"[]\" in allE)\n     apply(simp add: filter_IFS_no_violations_def)\n    unfolding filter_IFS_no_violations_def\n    apply(induct_tac Es)\n     apply(simp_all)\n    apply force\n    done\n    lemma filter_IFS_no_violations_accu_correct_induction: \"valid_reqs (get_IFS M) \\<Longrightarrow> wf_graph \\<lparr> nodes = V, edges = E \\<rparr> \\<Longrightarrow>\n            all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = E, flows_state = set (accu) \\<rparr>) \\<Longrightarrow> \n            (set accu) \\<union> (set edgesList) \\<subseteq> E \\<Longrightarrow> \n            all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = E, flows_state = set (filter_IFS_no_violations_accu \\<lparr> nodes = V, edges = E \\<rparr> M accu edgesList) \\<rparr>)\"\n      apply(induction edgesList arbitrary: accu)\n       by(simp_all)\n    lemma filter_IFS_no_violations_correct: \"\\<lbrakk>valid_reqs (get_IFS M); wf_graph G;\n            all_security_requirements_fulfilled (get_IFS M) G; \n            (set edgesList) \\<subseteq> edges G \\<rbrakk> \\<Longrightarrow> \n            all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<lparr> hosts = nodes G, flows_fix = edges G, flows_state = set (filter_IFS_no_violations G M edgesList) \\<rparr>)\"\n    unfolding filter_IFS_no_violations_def\n    apply(case_tac G, simp)\n    apply(drule(1) filter_IFS_no_violations_accu_correct_induction[where accu=\"[]\", simplified])\n      apply(simp_all)\n    by(simp add: stateful_policy_to_network_graph_def all_flows_def backflows_def False_set)\n    lemma filter_IFS_no_violations_accu_no_IFS: \"valid_reqs (get_IFS M) \\<Longrightarrow> wf_graph G \\<Longrightarrow> get_IFS M = [] \\<Longrightarrow>\n            (set accu) \\<union> (set edgesList) \\<subseteq> edges G \\<Longrightarrow> \n            filter_IFS_no_violations_accu G M accu edgesList = rev(edgesList)@accu\"\n      apply(induction edgesList arbitrary: accu)\n       by(simp_all add: all_security_requirements_fulfilled_def)\n\n\n    lemma filter_IFS_no_violations_accu_maximal_induction: \"valid_reqs (get_IFS M) \\<Longrightarrow> wf_graph \\<lparr> nodes = V, edges = E \\<rparr> \\<Longrightarrow> \n      set accu \\<subseteq> E \\<Longrightarrow> set edgesList \\<subseteq> E \\<Longrightarrow>\n        \\<forall> e \\<in> E - (set accu \\<union> set edgesList).\n            \\<not> all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = E, flows_state = {e} \\<union> (set accu) \\<rparr>)\n         \\<Longrightarrow>\n           let stateful = set (filter_IFS_no_violations_accu \\<lparr> nodes = V, edges = E \\<rparr> M accu edgesList) in\n            (\\<forall> e \\<in> E - stateful.\n            \\<not> all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = E, flows_state = {e} \\<union> stateful \\<rparr>))\"\n      proof(induction edgesList arbitrary: accu)\n      case Nil thus ?case by(simp add: Let_def)\n      next\n      case(Cons e Es)\n        from Cons.prems(3) Cons.prems(2) have \"fst ` set accu \\<subseteq> V\" and \"snd ` set accu \\<subseteq> V\"\n          by(auto simp add: wf_graph_def)\n        \\<comment> \\<open>@{const wf_graph} for some complicated structures\\<close>\n        from Cons.prems(2) this Cons.prems(4)  have \"\\<And>ea. ea\\<in>E \\<Longrightarrow> wf_graph \\<lparr> nodes = V, edges = insert e (insert ea (set accu)) \\<rparr>\"\n          by(auto simp add: wf_graph_def)\n        from backflows_wf[OF this] wf_graph_union_edges[OF Cons.prems(2)]\n        have \"\\<And>ea. ea\\<in>E  \\<Longrightarrow> wf_graph \\<lparr> nodes = V, edges = E \\<union> backflows (insert e (insert ea (set accu))) \\<rparr>\" by (simp)\n        hence \"\\<And>ea. ea\\<in>E \\<Longrightarrow> wf_graph \\<lparr> nodes = V, edges = E \\<union> set accu \\<union> backflows (insert e (insert ea (set accu))) \\<rparr>\" \n          by (metis Cons.prems(3) sup.order_iff)\n        from this Cons.prems(4)\n        have \"\\<And>ea. ea\\<in>E \\<Longrightarrow> wf_graph \\<lparr> nodes = V, edges = insert e (insert ea (E \\<union> set accu \\<union> backflows (insert e (insert ea (set accu))))) \\<rparr>\"\n          by(simp add: insert_absorb)\n        hence validgraph1: \"\\<And>ea. ea\\<in>E - (set (e # accu) \\<union> set Es) \\<Longrightarrow> \n          wf_graph \\<lparr> nodes = V, edges = insert e (insert ea (E \\<union> set accu \\<union> backflows (insert e (insert ea (set accu))))) \\<rparr>\" by(simp)\n\n        have validgraph2: \"\\<And> ea. \n         insert ea (E \\<union> set accu \\<union> backflows (insert ea (set accu))) \\<subseteq> insert e (insert ea (E \\<union> set accu \\<union> backflows (insert e (insert ea (set accu)))))\"\n         apply(simp add: backflows_def)\n         by blast\n        \n        from all_security_requirements_fulfilled_mono[OF Cons.prems(1) validgraph2 validgraph1] have neg_mono:\n            \"\\<And>ea. ea \\<in> E - (set (e # accu) \\<union> set Es) \\<Longrightarrow>\n         \\<not> all_security_requirements_fulfilled (get_IFS M) \n            \\<lparr>nodes = V, edges = insert ea (E \\<union> set accu \\<union> backflows (insert ea (set accu)))\\<rparr>\n         \\<Longrightarrow>\n         \\<not> all_security_requirements_fulfilled (get_IFS M) \n            \\<lparr>nodes = V, edges = insert e (insert ea (E \\<union> set accu \\<union> backflows (insert e (insert ea (set accu)))))\\<rparr>\"\n           apply(simp)\n           by blast\n\n         from Cons.prems(5) have \"\\<And>ea. ea\\<in>E - (set (e # accu) \\<union> set Es) \\<Longrightarrow>\n          \\<not> all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \n              \\<lparr>hosts = V, flows_fix = E, flows_state = {ea} \\<union> set (e # accu)\\<rparr>)\"\n           apply(erule_tac x=\"ea\" in ballE)\n           prefer 2\n           apply simp\n          apply(simp only: stateful_policy_to_network_graph_def all_flows_def stateful_policy.select_convs)\n          apply(simp)\n          apply(frule(1) neg_mono[simplified])\n          by(simp)\n         hence goalTrue:\n          \"\\<forall> ea\\<in>E - (set (e # accu) \\<union> set Es). \n            \\<not> all_security_requirements_fulfilled (get_IFS M) \n                (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = {ea} \\<union> set (e # accu)\\<rparr>)\"\n         by simp\n         \n        show ?case\n        apply(simp add: Let_def)\n        apply(rule conjI)\n\n         apply(rule impI)\n         apply(thin_tac \"_\") (*dont't need it*)\n         using Cons.IH[where accu=\"e # accu\", OF Cons.prems(1) Cons.prems(2) _ _ goalTrue, simplified Let_def] Cons.prems(3) Cons.prems(4)\n         apply(auto) [1]\n\n        apply(rule impI)\n        using Cons.IH[where accu=\"accu\", OF Cons.prems(1) Cons.prems(2), simplified Let_def] Cons.prems(5) Cons.prems(3) Cons.prems(4)\n        apply(auto)\n        done\n     qed\n    lemma filter_IFS_no_violations_maximal: \"\\<lbrakk>valid_reqs (get_IFS M); wf_graph G;\n            (set edgesList) = edges G \\<rbrakk> \\<Longrightarrow> \n            let stateful = set (filter_IFS_no_violations G M edgesList) in \n            \\<forall> e \\<in> edges G - stateful.\n              \\<not> all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<lparr> hosts = nodes G, flows_fix = edges G, flows_state = {e} \\<union> stateful \\<rparr>)\"\n    unfolding filter_IFS_no_violations_def\n    apply(case_tac G, simp)\n    apply(drule(1) filter_IFS_no_violations_accu_maximal_induction[where accu=\"[]\" and edgesList=\"edgesList\"])\n       by(simp_all)\n\n    \\<comment> \\<open>It is not only maximal for single flows but all non-empty subsets\\<close>\n    corollary filter_IFS_no_violations_maximal_allsubsets: \n    assumes a1: \"valid_reqs (get_IFS M)\"\n    and     a2: \"wf_graph G\"\n    and     a4: \"(set edgesList) = edges G\"\n    shows   \"let stateful = set (filter_IFS_no_violations G M edgesList) in \n            \\<forall> E \\<subseteq> edges G - stateful. E \\<noteq> {} \\<longrightarrow>\n              \\<not> all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<lparr> hosts = nodes G, flows_fix = edges G, flows_state = E \\<union> stateful \\<rparr>)\"\n    proof -\n      let ?stateful = \"set (filter_IFS_no_violations G M edgesList)\"\n      from filter_IFS_no_violations_maximal[OF a1 a2 a4] have not_fulfilled_single: \n        \"\\<forall>e\\<in>edges G - ?stateful. \\<not> all_security_requirements_fulfilled (get_IFS M)\n                (stateful_policy_to_network_graph \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = {e} \\<union> ?stateful\\<rparr>)\"\n        by(simp add: Let_def)\n      have neg_mono:\n        \"\\<And> e E. e \\<in> E \\<Longrightarrow> E \\<subseteq> edges G - ?stateful \\<Longrightarrow> E \\<noteq> {} \\<Longrightarrow>\n          \\<not> all_security_requirements_fulfilled (get_IFS M) \n              (stateful_policy_to_network_graph \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = {e} \\<union> ?stateful\\<rparr>) \\<Longrightarrow> \n          \\<not> all_security_requirements_fulfilled (get_IFS M) \n              (stateful_policy_to_network_graph \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = E \\<union> ?stateful\\<rparr>)\"\n        proof -\n          fix e E\n          assume h1: \"e \\<in> E\"\n          and    h2: \"E \\<subseteq> edges G - ?stateful\"\n          and    h3: \"E \\<noteq> {}\"\n          and    h4: \"\\<not> all_security_requirements_fulfilled (get_IFS M) \n            (stateful_policy_to_network_graph \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = {e} \\<union> ?stateful\\<rparr>)\"\n  \n          from filter_IFS_no_violations_subseteq_input a4 have \"?stateful \\<subseteq> edges G\" by blast\n          hence \"edges G \\<union> (E \\<union> ?stateful) = edges G\" using h2 by blast\n          from a2 this have validgraph1: \"wf_graph \\<lparr>nodes = nodes G, edges = edges G \\<union> (E \\<union> ?stateful)\\<rparr>\"\n          by(case_tac G, simp)\n  \n          from h1 h2 h3 have subseteq: \"({e} \\<union> ?stateful) \\<subseteq> (E \\<union> ?stateful)\" by blast\n\n          have revimp: \"\\<And>A B. (A \\<Longrightarrow> B) \\<Longrightarrow> (\\<not> B \\<Longrightarrow> \\<not> A)\" by fast\n          \n          from all_security_requirements_fulfilled_mono_stateful_policy_to_network_graph[OF a1 subseteq validgraph1] h4\n          show \"\\<not> all_security_requirements_fulfilled (get_IFS M) \n            (stateful_policy_to_network_graph \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = E \\<union> ?stateful\\<rparr>)\" \n            apply(rule revimp)\n            by assumption\n        qed\n      \n      show ?thesis\n      proof(simp add: Let_def,rule allI,rule impI, rule impI)\n        fix E\n        assume h1: \"E \\<subseteq> edges G - ?stateful\"\n        and    h2: \"E \\<noteq> {}\"\n\n        from  h1 h2 obtain e where e_prop1: \"e \\<in> E\" by blast \n        from this h1 have \"e \\<in> edges G - ?stateful\" by blast\n        from this not_fulfilled_single have e_prop2: \"\\<not> all_security_requirements_fulfilled (get_IFS M)\n          (stateful_policy_to_network_graph \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = {e} \\<union> ?stateful\\<rparr>)\"\n          by simp\n        \n        from neg_mono[OF e_prop1 h1 h2 e_prop2]\n        show \" \\<not> all_security_requirements_fulfilled (get_IFS M)\n               (stateful_policy_to_network_graph \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = E \\<union> set (filter_IFS_no_violations G M edgesList)\\<rparr>)\"\n        .\n      qed\n    qed\n    \n    \\<comment> \\<open>soundness and completeness\\<close>\n    thm filter_IFS_no_violations_correct filter_IFS_no_violations_maximal\n\n\n\n\n\n  text\\<open>Next\\<close>\n    (*\"\\<forall>F \\<in> get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<T> ). F \\<subseteq> backflows (filternew_flows_state \\<T>)\"*)\n    (*first in list are more likely to be kept*)\n    fun filter_compliant_stateful_ACS_accu :: \"'v::vertex graph \\<Rightarrow> 'v SecurityInvariant_configured list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> ('v \\<times> 'v) list\" where\n      \"filter_compliant_stateful_ACS_accu G M accu [] = accu\" |\n      \"filter_compliant_stateful_ACS_accu G M accu (e#Es) = (if\n        e \\<notin> backflows (edges G) \\<and> (\\<forall>F \\<in> get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr> hosts = nodes G, flows_fix = edges G, flows_state = set (e#accu) \\<rparr>). F \\<subseteq> backflows (set (e#accu)))\n        then filter_compliant_stateful_ACS_accu G M (e#accu) Es\n        else filter_compliant_stateful_ACS_accu G M accu Es)\"\n    definition filter_compliant_stateful_ACS :: \"'v::vertex graph \\<Rightarrow> 'v SecurityInvariant_configured list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> ('v \\<times> 'v) list\" where\n      \"filter_compliant_stateful_ACS G M Es = filter_compliant_stateful_ACS_accu G M [] Es\"\n\n\n    lemma filter_compliant_stateful_ACS_subseteq_input: \"set (filter_compliant_stateful_ACS G M Es) \\<subseteq> set Es\"\n      apply(subgoal_tac \"\\<forall> accu. set (filter_compliant_stateful_ACS_accu G M accu Es) \\<subseteq> set Es \\<union> set accu\")\n       apply(erule_tac x=\"[]\" in allE)\n       apply(simp add: filter_compliant_stateful_ACS_def)\n      apply(induct_tac Es)\n       apply(simp_all)\n      apply (metis Un_insert_right set_simps(2) set_subset_Cons set_union subset_trans)\n      done\n    lemma filter_compliant_stateful_ACS_accu_correct_induction: \"valid_reqs (get_ACS M) \\<Longrightarrow> wf_graph \\<lparr> nodes = V, edges = E \\<rparr> \\<Longrightarrow>\n            (set accu) \\<union> (set edgesList) \\<subseteq> E \\<Longrightarrow> \n            \\<forall>F \\<in> get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = E, flows_state = set (accu) \\<rparr>). F \\<subseteq> backflows (set accu) \\<Longrightarrow> \n            (\\<forall>a \\<in> set accu. a \\<notin> (backflows E)) \\<Longrightarrow>\n            \\<T> = \\<lparr> hosts = V, flows_fix = E, flows_state = set (filter_compliant_stateful_ACS_accu \\<lparr> nodes = V, edges = E \\<rparr> M accu edgesList) \\<rparr> \\<Longrightarrow>\n            \\<forall>F \\<in> get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<T>). F \\<subseteq> backflows (filternew_flows_state \\<T>)\"\n      proof(induction edgesList arbitrary: accu)\n        case Nil\n          from Nil(5) have \"backflows (set accu) = backflows {e \\<in> set accu. e \\<notin> backflows E}\" by (metis (lifting) Collect_cong Collect_mem_eq)\n          from this Nil(4) have \"\\<forall>F\\<in>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set accu\\<rparr>). F \\<subseteq> backflows {e \\<in> set accu. e \\<notin> backflows E}\" by simp\n          from this Nil(6) show ?case by(simp add: filternew_flows_state_alt2)\n        next\n        case (Cons e Es)\n          from Cons.IH[OF Cons.prems(1) Cons.prems(2)] Cons.prems(3) Cons.prems(4) Cons.prems(5) Cons.prems(6)\n          show ?case by(simp add: filternew_flows_state_alt2 split: if_split_asm)\n      qed\n\n    \n    lemma filter_compliant_stateful_ACS_accu_no_side_effects: \"valid_reqs (get_ACS M) \\<Longrightarrow> wf_graph G \\<Longrightarrow>\n            \\<forall>F \\<in> get_offending_flows (get_ACS M) \\<lparr>nodes = nodes G, edges = edges G \\<union> backflows (edges G)\\<rparr>. F \\<subseteq> (backflows (edges G)) - (edges G) \\<Longrightarrow>\n            (set accu) \\<union> (set edgesList) \\<subseteq> edges G \\<Longrightarrow> \n            (\\<forall>a \\<in> set accu. a \\<notin> (backflows (edges G))) \\<Longrightarrow>\n            filter_compliant_stateful_ACS_accu G M accu edgesList = rev([ e \\<leftarrow> edgesList. e \\<notin> backflows (edges G)])@accu\"\n      apply(simp add: backflows_minus_backflows)\n      apply(induction edgesList arbitrary: accu)\n       apply(simp)\n      apply(simp add: stateful_policy_to_network_graph_def all_flows_def)\n      apply(rule impI)\n      apply(case_tac G, simp, rename_tac V E)\n      thm Un_set_offending_flows_bound_minus_subseteq'[where X=\"backflows E - E\" and E=\"E \\<union> backflows E\"]\n      apply(drule_tac X=\"backflows E - E\" and E=\"E \\<union> backflows E\" and E'=\"(E \\<union> backflows E) - (insert a (E \\<union> set accu \\<union> backflows (insert a (set accu))))\" in Un_set_offending_flows_bound_minus_subseteq')\n         defer\n         prefer 2\n         apply blast\n        apply auto[1]\n       apply(subgoal_tac \"E \\<union> backflows E - (E \\<union> backflows E - insert a (E \\<union> set accu \\<union> backflows (insert a (set accu)))) = insert a (E \\<union> set accu \\<union> backflows (insert a (set accu)))\")\n        apply(simp)\n        prefer 2\n        apply (metis Un_assoc Un_least Un_mono backflows_subseteq double_diff insert_def insert_subset subset_refl)\n       apply(subgoal_tac \"backflows (insert a (set accu)) \\<subseteq> backflows E - E - (E \\<union> backflows E - insert a (E \\<union> set accu \\<union> backflows (insert a (set accu))))\")\n        apply(blast)\n       apply(simp add: backflows_def)\n       apply fast\n      using FiniteGraph.backflows_wf FiniteGraph.wf_graph_union_edges by metis\n\n\n\n    lemma filter_compliant_stateful_ACS_correct: \n      assumes a1: \"valid_reqs (get_ACS M)\"\n      and     a2: \"wf_graph G\"\n      and     a3: \"set edgesList \\<subseteq> edges G\"  \n      and     a4: \"all_security_requirements_fulfilled (get_ACS M) G\"\n      and     a5: \"\\<T> = \\<lparr> hosts = nodes G, flows_fix = edges G, flows_state = set (filter_compliant_stateful_ACS G M edgesList) \\<rparr>\"\n      shows   \"\\<forall>F \\<in> get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<T>). F \\<subseteq> backflows (filternew_flows_state \\<T>)\"\n      proof -\n        obtain V E where VE: \"G = \\<lparr> nodes = V, edges = E \\<rparr>\" by(case_tac G, blast)\n        from VE a2 have wfVE: \"wf_graph \\<lparr> nodes = V, edges = E \\<rparr>\" by simp\n        from VE a3 have \"set edgesList \\<subseteq> E\" by simp\n\n        from a5 VE have a5': \"\\<T> = \\<lparr>hosts = V, flows_fix = E, flows_state = set (filter_compliant_stateful_ACS_accu \\<lparr>nodes = V, edges = E\\<rparr> M [] edgesList)\\<rparr>\"\n          unfolding filter_compliant_stateful_ACS_def\n          by(simp)\n\n        from all_security_requirements_fulfilled_imp_get_offending_empty[OF a1 a4] VE\n        have \"\\<forall>F\\<in>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = {}\\<rparr>). F \\<subseteq> backflows {}\"\n          by(simp add: stateful_policy_to_network_graph_def all_flows_def backflows_def False_set)\n\n        from filter_compliant_stateful_ACS_accu_correct_induction[where accu=\"[]\" and edgesList=\"edgesList\", simplified, OF a1 wfVE \\<open>set edgesList \\<subseteq> E\\<close> this a5']\n        show ?thesis .\n     qed\n\n\n    lemma filter_compliant_stateful_ACS_accu_induction_maximal:\"\\<lbrakk> valid_reqs (get_ACS M);  wf_graph \\<lparr> nodes = V, edges = E \\<rparr>;\n            (set edgesList) \\<subseteq> E;\n            (set accu) \\<subseteq> E; \n            stateful = set (filter_compliant_stateful_ACS_accu \\<lparr> nodes = V, edges = E \\<rparr> M accu edgesList);\n            \\<forall>e \\<in> E - (set edgesList \\<union> set accu \\<union> {e \\<in> E. e \\<in> backflows E}).\n            \\<not> \\<Union>(get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = E, flows_state = set accu \\<union> {e} \\<rparr>))\n                \\<subseteq> backflows (filternew_flows_state \\<lparr> hosts = V, flows_fix = E, flows_state = set accu \\<union> {e} \\<rparr>)\n            \\<rbrakk> \\<Longrightarrow>\n            \\<forall>e \\<in> E - (stateful \\<union> {e \\<in> E. e \\<in> backflows E}). \\<^cancel>\\<open>E - {computed stateful flows plus trivial stateful flows}\\<close>\n            \\<not> \\<Union>(get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = E, flows_state = stateful \\<union> {e} \\<rparr>))\n                \\<subseteq> backflows (filternew_flows_state \\<lparr> hosts = V, flows_fix = E, flows_state = stateful \\<union> {e} \\<rparr>)\"\n   proof(induction edgesList arbitrary: accu E)\n   case Nil from Nil(5)[simplified] Nil(6) show ?case by(simp)\n   next\n   case (Cons a Es)\n     \\<comment> \\<open>case distinction\\<close>\n     let ?caseDistinction=\"a \\<notin> backflows (E) \\<and>  (\\<forall>F\\<in>get_offending_flows (get_ACS M)\n                 (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set (a # accu)\\<rparr>).\n                    F \\<subseteq> backflows (set (a # accu)))\"\n     from Cons.prems(3) have \"set Es \\<subseteq> E\" by simp\n\n     show ?case\n      proof(cases ?caseDistinction)\n        assume CaseTrue: ?caseDistinction\n        from CaseTrue have \n          \"set (filter_compliant_stateful_ACS_accu \\<lparr>nodes = V, edges = E\\<rparr> M accu (a # Es)) = \n           set (filter_compliant_stateful_ACS_accu \\<lparr>nodes = V, edges = E\\<rparr> M (a # accu) Es)\"\n           by(simp)\n        from this Cons.prems(5) have statefulsimp:\n          \"stateful = set (filter_compliant_stateful_ACS_accu \\<lparr>nodes = V, edges = E\\<rparr> M (a # accu) Es)\" by simp\n        from Cons.prems(3) Cons.prems(4) have \"set (a # accu) \\<subseteq> E\" by simp\n\n        have \"\\<forall>e\\<in>E - (set Es \\<union> set (a # accu) \\<union> {e \\<in> E. e \\<in> backflows E}).\n     \\<not> \\<Union>(get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set (a # accu) \\<union> {e}\\<rparr>))\n        \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set (a # accu) \\<union> {e}\\<rparr>)\"\n          proof(rule ballI)\n            fix e\n            assume h1: \"e \\<in> E - (set Es \\<union> set (a # accu) \\<union> {e \\<in> E. e \\<in> backflows E})\"\n\n            from conjunct1[OF CaseTrue] have filternew_flows_state_moveout_a:\n              \"filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set (a # accu) \\<union> {e}\\<rparr> = \n              {a} \\<union> filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {e}\\<rparr>\"\n              apply(simp add: filternew_flows_state_alt) by blast\n\n            have backflowssubseta: \"\\<And>X. backflows X \\<subseteq> backflows ({a} \\<union> X)\" by(simp add: backflows_def, blast)\n\n            from Cons.prems(6) h1 have \n              \"\\<not> \\<Union>(get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {e}\\<rparr>))\n                \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {e}\\<rparr>)\" by simp\n            from this obtain dat_offender where \n              dat_in: \"dat_offender \\<in> \\<Union>(get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {e}\\<rparr>))\"\n              and dat_offends: \"dat_offender \\<notin> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {e}\\<rparr>)\" by blast\n\n            have wfGraphA: \"wf_graph (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set (a # accu) \\<union> {e}\\<rparr>)\"\n              proof(simp add: stateful_policy_to_network_graph_def all_flows_def)\n              from Cons.prems(2) h1 Cons.prems(3) Cons.prems(4)\n              have \"wf_graph \\<lparr>nodes=V, edges = insert e (insert a (set accu)) \\<rparr>\" \n              apply(auto simp add: wf_graph_def) by force\n              from this backflows_wf\n              have vgh1: \"wf_graph \\<lparr>nodes = V, edges = backflows (insert e (insert a (set accu)))\\<rparr>\" by auto\n              from Cons.prems(2) wf_graph_add_subset_edges h1  Cons.prems(3) Cons.prems(4)\n              have vgh2: \"wf_graph \\<lparr>nodes = V, edges = insert e ((insert a E) \\<union> set accu)\\<rparr>\"\n                proof -\n                  have f1: \"e \\<in> E - (set Es \\<union> insert a (set accu) \\<union> {R \\<in> E. R \\<in> backflows E})\"\n                    using h1 by simp\n                  have f2: \"insert a (set accu) \\<subseteq> E\"\n                    using \\<open>set (a # accu) \\<subseteq> E\\<close> by simp\n                  have f3: \"e \\<in> E\"\n                    using f1 by fastforce\n                  have \"E \\<union> insert a (set accu) = E\"\n                    using f2 by fastforce\n                  thus \"wf_graph \\<lparr>nodes = V, edges = insert e (insert a E \\<union> set accu)\\<rparr>\"\n                    using f3 Cons.prems(2) Un_insert_right insert_absorb sup_commute by fastforce\n                qed\n              from vgh1 vgh2 wf_graph_union_edges\n              show \"wf_graph \\<lparr>nodes = V, edges = insert e (insert a (E \\<union> set accu \\<union> backflows (insert e (insert a (set accu)))))\\<rparr>\" by fastforce\n           qed\n            \n            from dat_in have dat_in_simplified: \n              \"dat_offender \\<in> \\<Union>(get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = insert e (E \\<union> set accu \\<union> backflows (insert e (set accu)))\\<rparr>)\"\n              by(simp add: stateful_policy_to_network_graph_def all_flows_def)\n\n            have subsethlp: \"insert e (E \\<union> set accu \\<union> backflows (insert e (set accu))) \\<subseteq> E \\<union> (set (a # accu) \\<union> {e}) \\<union> backflows (set (a # accu) \\<union> {e})\"\n              apply(simp)\n              apply(rule, blast)\n              apply(rule, blast)\n              apply(rule)\n              apply(simp add: backflows_def, fast)\n              done\n\n            from get_offending_flows_union_mono[OF \n                Cons.prems(1) \n                wfGraphA[simplified stateful_policy_to_network_graph_def all_flows_def graph.select_convs stateful_policy.select_convs],\n                OF subsethlp]\n            dat_in_simplified have dat_in_a: \"dat_offender \\<in> \\<Union>(get_offending_flows (get_ACS M) \n              (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set (a # accu) \\<union> {e}\\<rparr>))\"\n              by(simp add: stateful_policy_to_network_graph_def all_flows_def, fast)\n\n            have \"dat_offender \\<noteq> (snd a, fst a)\"\n              proof(rule ccontr)\n              assume \"\\<not> dat_offender \\<noteq> (snd a, fst a)\"\n              hence hlpassm: \"dat_offender = (snd a, fst a)\" by simp\n              from this obtain a1 a2 where \"dat_offender = (a2, a1)\" by blast\n              \n              \n              have \"\\<Union>(get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = insert e (E \\<union> set accu \\<union> backflows (insert e (set accu)))\\<rparr>) \\<subseteq> \n                  insert e (E \\<union> set accu \\<union> backflows (insert e (set accu)))\"\n                by (metis Cons.prems(1) Sup_le_iff get_offending_flows_subseteq_edges)\n              from this h1 have UN_get_subset: \n                    \"\\<Union>(get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = insert e (E \\<union> set accu \\<union> backflows (insert e (set accu)))\\<rparr>) \\<subseteq> \n                   (E \\<union> set accu \\<union> backflows (insert e (set accu)))\"\n                by blast\n\n            from dat_offends have dat_offends_simplified: \n              \"dat_offender \\<notin> backflows (insert e (set accu)) - E\"\n                by(simp only: filternew_flows_state_alt stateful_policy.select_convs backflows_minus_backflows, simp)\n              \n              from conjunct1[OF CaseTrue] hlpassm have \"dat_offender \\<notin> E\"\n                by(simp add: backflows_def, fastforce)\n              from dat_in_simplified UN_get_subset this have \"dat_offender \\<in> set accu \\<union> backflows (insert e (set accu))\" by blast\n              from this Cons.prems(4) \\<open>dat_offender \\<notin> E\\<close> have \"dat_offender \\<in> backflows (insert e (set accu))\" by blast\n              from dat_offends_simplified[simplified] this have \"dat_offender \\<in> E\" by simp\n              from \\<open>dat_offender \\<notin> E\\<close> \\<open>dat_offender \\<in> E\\<close> show False by simp\n            qed\n\n            from this dat_offends have \n              \"dat_offender \\<notin> backflows ({a} \\<union> filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {e}\\<rparr>)\"\n              apply(simp add: backflows_def) by force\n\n            from dat_in_a this\n            show \"\\<not> \\<Union>(get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set (a # accu) \\<union> {e}\\<rparr>))\n            \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set (a # accu) \\<union> {e}\\<rparr>)\"\n            apply(subst filternew_flows_state_moveout_a) by blast\n          qed\n\n        from Cons.IH[OF Cons.prems(1) Cons.prems(2) \\<open>set Es \\<subseteq> E\\<close> \\<open>set (a # accu) \\<subseteq> E\\<close> statefulsimp this ] show \"?case\" \n          by(simp)\n      next\n        assume CaseFalse: \"\\<not> ?caseDistinction\"\n\n        from CaseFalse have funapplysimp: \n          \"set (filter_compliant_stateful_ACS_accu \\<lparr>nodes = V, edges = E\\<rparr> M accu (a # Es)) = \n           set (filter_compliant_stateful_ACS_accu \\<lparr>nodes = V, edges = E\\<rparr> M accu Es)\"\n           by auto\n        from this Cons.prems(5) have statefulsimp:\n          \"stateful = set (filter_compliant_stateful_ACS_accu \\<lparr>nodes = V, edges = E\\<rparr> M accu Es)\" by simp\n        from Cons.prems(4) have \"set accu \\<subseteq> E\" .\n\n        have \"a \\<in> E - (set Es \\<union> set accu \\<union> {e \\<in> E. e \\<in> backflows E})\\<Longrightarrow> \\<not> \\<Union>(get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {a}\\<rparr>))\n          \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {a}\\<rparr>)\"\n          proof(rule ccontr)\n            assume h1: \"a \\<in> E - (set Es \\<union> set accu \\<union> {e \\<in> E. e \\<in> backflows E})\"\n            and    \"\\<not> \\<not>\\<Union>(get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {a}\\<rparr>)) \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {a}\\<rparr>)\"\n            hence hccontr: \"\\<Union>(get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {a}\\<rparr>)) \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {a}\\<rparr>)\" by simp\n\n            moreover from h1 have stateful_to_graph: \"stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {a}\\<rparr> =  \\<lparr>nodes = V, edges = E \\<union> set accu \\<union> backflows (insert a (set accu))\\<rparr>\"\n              by(simp add: stateful_policy_to_network_graph_def all_flows_def, blast)\n            moreover have \"backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {a}\\<rparr>) = backflows (insert a (set accu)) - E\"\n              by(simp add: filternew_flows_state_alt backflows_minus_backflows)\n            ultimately have hccontr_simp:\n              \"\\<Union>(get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = E \\<union> set accu \\<union> backflows (insert a (set accu))\\<rparr>) \\<subseteq> backflows (insert a (set accu)) - E\" by simp\n\n            from Cons.prems(3) Cons.prems(4) have backaaccusubE: \"backflows (set (a # accu)) \\<subseteq> backflows E\" by(simp add: backflows_def, fastforce)\n            from h1 have \"a \\<notin> backflows E\" by fastforce\n            from backaaccusubE \\<open>a \\<notin> backflows E\\<close> have \"a \\<notin> backflows (insert a (set accu))\" by auto\n\n\n            from \\<open>a \\<notin> backflows E\\<close> CaseFalse have \"\\<not> (\\<forall>F\\<in>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set (a # accu)\\<rparr>). F \\<subseteq> backflows (set (a # accu)))\" by(simp)\n            from this stateful_to_graph have \"\\<not> (\\<forall>F\\<in>get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = E \\<union> set accu \\<union> backflows (insert a (set accu))\\<rparr>. F \\<subseteq> backflows (insert a (set accu)))\" by(simp)\n            from this hccontr_simp show False by blast\n        qed\n        from  Cons.prems(6)[simplified funapplysimp statefulsimp] this\n        have \"\\<forall>e\\<in>E - (set Es \\<union> set accu \\<union> {e \\<in> E. e \\<in> backflows E}).\n       \\<not> \\<Union>(get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {e}\\<rparr>))\n          \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {e}\\<rparr>)\"\n          by auto\n\n        from Cons.IH[OF Cons.prems(1) Cons.prems(2) \\<open>set Es \\<subseteq> E\\<close> \\<open>set accu \\<subseteq> E\\<close> statefulsimp this]\n        show ?case by simp\n      qed\n   qed\n\n\n\n\n\n\n   \n\n    lemma filter_compliant_stateful_ACS_maximal: \"\\<lbrakk> valid_reqs (get_ACS M); wf_graph \\<lparr> nodes = V, edges = E \\<rparr>;\n            (set edgesList) = E;\n            stateful = set (filter_compliant_stateful_ACS \\<lparr> nodes = V, edges = E \\<rparr> M edgesList)\n            \\<rbrakk> \\<Longrightarrow>\n            \\<forall>e \\<in> E - (stateful \\<union> {e \\<in> E. e \\<in> backflows E}). \\<^cancel>\\<open>E - {computed stateful flows plus trivial stateful flows}\\<close>\n            \\<not> \\<Union> (get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = E, flows_state = stateful \\<union> {e} \\<rparr>))\n                \\<subseteq> backflows (filternew_flows_state \\<lparr> hosts = V, flows_fix = E, flows_state = stateful \\<union> {e} \\<rparr>)\"\n    apply(drule(1) filter_compliant_stateful_ACS_accu_induction_maximal[where accu=\"[]\", simplified])\n       apply(blast)\n      apply(simp add: filter_compliant_stateful_ACS_def)\n     apply(simp)\n     apply fastforce\n    apply(simp add: filter_compliant_stateful_ACS_def)\n   done\n\n\n    lemma filter_compliant_stateful_ACS_maximal_allsubsets:\n      assumes a1: \"valid_reqs (get_ACS M)\" and a2: \"wf_graph \\<lparr> nodes = V, edges = E \\<rparr>\"\n      and a3: \"(set edgesList) = E\"\n      and a4: \"stateful = set (filter_compliant_stateful_ACS \\<lparr> nodes = V, edges = E \\<rparr> M edgesList)\"\n      and a5: \"X \\<subseteq> E - (stateful \\<union> backflows E)\" and a6: \"X \\<noteq> {}\"\n      shows \"\n      \\<not> \\<Union>(get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = E, flows_state = stateful \\<union> X \\<rparr>))\n                \\<subseteq> backflows (filternew_flows_state \\<lparr> hosts = V, flows_fix = E, flows_state = stateful \\<union> X \\<rparr>)\"\n    proof(rule ccontr, simp)\n      from a5 have \"X \\<subseteq> E\" by blast\n      assume accontr: \"\\<Union>(get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> X\\<rparr>)) \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> X\\<rparr>)\"\n      hence \"\\<Union>(get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = E \\<union> (stateful \\<union> X) \\<union> backflows (stateful \\<union> X)\\<rparr>) \\<subseteq> backflows (stateful \\<union> X) - E\"\n      by(simp add: stateful_policy_to_network_graph_def all_flows_def filternew_flows_state_alt backflows_minus_backflows)\n      hence \"\\<Union>(get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = E \\<union> X \\<union> backflows (stateful \\<union> X)\\<rparr>) \\<subseteq> backflows (stateful \\<union> X) - E\"\n      using a4 a3 filter_compliant_stateful_ACS_subseteq_input by (metis Diff_subset_conv Un_Diff_cancel Un_assoc a3 bot.extremum_unique sup_bot_right)\n      hence accontr_simp: \"\\<Union>(get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = E \\<union> (backflows stateful) \\<union> (backflows X)\\<rparr>) \\<subseteq> backflows (stateful \\<union> X) - E\"\n      using Set.Un_absorb2[OF \\<open>X \\<subseteq> E\\<close>] backflows_un[of \"stateful\" \"X\"] by (metis Un_assoc)\n      \n      from a2 a5 have \"finite X\" apply(simp add: wf_graph_def) by (metis (full_types) finite_Diff finite_subset)\n      from a6 obtain x where \"x \\<in> X\" by blast\n\n\n      from \\<open>x \\<in> X\\<close> a5 have xX_simp1: \"(backflows X) - (backflows (X - {x}) - E)  = backflows {x}\"\n        apply(simp add: backflows_def) by fast\n      from a5 have \"X \\<inter> stateful = {}\" by auto\n      from \\<open>x \\<in> X\\<close> this have xX_simp2: \"(backflows stateful) - (backflows (X - {x}) - E) = backflows stateful\"\n        apply(simp add: backflows_def) by fast\n      have xX_simp3:\"backflows (stateful \\<union> X) - (backflows (X - {x}) - E) = backflows (stateful \\<union> {x})\"\n        apply(simp only: backflows_un)\n        using xX_simp1 xX_simp2 by blast\n\n      have xX_simp4: \"backflows (stateful \\<union> X) - E - (backflows (X - {x}) - E) = backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> {x}\\<rparr>)\"\n        apply(simp add: filternew_flows_state_alt backflows_minus_backflows)\n        using xX_simp3 by auto\n\n\n      have xX_simp5: \"(E \\<union> backflows stateful \\<union> backflows X) - (backflows (X - {x}) - E) = E \\<union> backflows stateful \\<union> backflows {x}\"\n      using xX_simp3[simplified backflows_un] by blast\n\n      have Eexpand: \"E \\<union> stateful \\<union> {x} = E\" \n      using a4 a3 filter_compliant_stateful_ACS_subseteq_input a5 \\<open>x\\<in>X\\<close> by blast\n\n      have \"backflows (stateful \\<union> X) - E - backflows (X - {x}) = (backflows (stateful \\<union> X) - E) - backflows (X - {x})\" by simp\n      from \\<open>finite X\\<close> backflows_finite have finite: \"finite (backflows (X - {x}) - E)\" by auto\n      from a2 a4 a3 filter_compliant_stateful_ACS_subseteq_input have \"wf_graph \\<lparr>nodes = V, edges = stateful\\<rparr>\" by (metis Diff_partition wf_graph_remove_edges_union)\n      from backflows_wf[OF this] have \"wf_graph \\<lparr>nodes = V, edges = backflows stateful\\<rparr>\" .\n      from a2 \\<open>X \\<subseteq> E\\<close> have \"wf_graph \\<lparr>nodes = V, edges = X\\<rparr>\" by (metis double_diff dual_order.refl wf_graph_remove_edges)\n       from backflows_wf[OF this] have \"wf_graph \\<lparr>nodes = V, edges = backflows X\\<rparr>\" .\n      from this wf_graph_union_edges \\<open>wf_graph \\<lparr>nodes = V, edges = backflows stateful\\<rparr>\\<close> a2 have wfG: \n        \"wf_graph \\<lparr>nodes = V, edges = E \\<union> backflows stateful \\<union> backflows X\\<rparr>\" by metis\n\n      from \\<open>x\\<in>X\\<close> have subset: \"backflows (X - {x}) - E \\<subseteq> E \\<union> backflows stateful \\<union> backflows X\" apply(simp add: backflows_def) by fast\n\n      from Un_set_offending_flows_bound_minus_subseteq'[OF a1 wfG subset accontr_simp] have\n        \"\\<Union>(get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = (E \\<union> backflows stateful \\<union> backflows X) - (backflows (X - {x}) - E)\\<rparr>) \\<subseteq> (backflows (stateful \\<union> X) - E) - (backflows (X - {x}) - E)\" by simp\n      from this xX_simp4 xX_simp5 have trans1:\n        \"\\<Union>(get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = E \\<union> backflows stateful \\<union> backflows {x}\\<rparr>) \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> {x}\\<rparr>)\" by simp\n\n      hence \"\\<Union>(get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = E \\<union> backflows (stateful \\<union> {x})\\<rparr>) \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> {x}\\<rparr>)\"\n      apply(simp only: backflows_un) by (metis Un_assoc)\n      hence contr1: \"\\<Union>(get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> {x}\\<rparr>)) \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> {x}\\<rparr>)\"\n      apply(simp only: stateful_policy_to_network_graph_def all_flows_def stateful_policy.select_convs)\n      using Eexpand by (metis Un_assoc)\n      \n\n      from filter_compliant_stateful_ACS_maximal[OF a1 a2 a3 a4] have\n        \"\\<forall>e\\<in>E - (stateful \\<union> {e \\<in> E. e \\<in> backflows E}). \\<not> \\<Union>(get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> {e}\\<rparr>)) \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> {e}\\<rparr>)\" .\n      from this a5 \\<open>x \\<in> X\\<close> have contr2: \"\\<not> \\<Union>(get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> {x}\\<rparr>)) \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> {x}\\<rparr>)\" by blast\n\n      from contr1 contr2\n      show \"False\" by simp\n    qed\n\n\n    text\\<open>@{term filter_compliant_stateful_ACS} is correct and maximal\\<close>\n    thm filter_compliant_stateful_ACS_correct filter_compliant_stateful_ACS_maximal\n\n\n    text\\<open>Getting those together. We cannot say \\<open>edgesList = E\\<close> here because one filters first. I guess filtering ACS first is easier, ...\\<close>\n\n\n\n\n\n\n\n\n\n\n  definition generate_valid_stateful_policy_IFSACS :: \"'v::vertex graph \\<Rightarrow> 'v SecurityInvariant_configured list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> 'v stateful_policy\" where\n    \"generate_valid_stateful_policy_IFSACS G M edgesList \\<equiv> (let filterIFS = filter_IFS_no_violations G M edgesList in\n        (let filterACS = filter_compliant_stateful_ACS G M filterIFS in \\<lparr> hosts = nodes G, flows_fix = edges G, flows_state = set filterACS \\<rparr>))\"\n\n  lemma generate_valid_stateful_policy_IFSACS_wf_stateful_policy: assumes wfG: \"wf_graph G\"\n          and     edgesList: \"(set edgesList) = edges G\"\n          shows \"wf_stateful_policy (generate_valid_stateful_policy_IFSACS G M edgesList)\"\n   proof -\n    from  wfG show ?thesis\n     apply(simp add: generate_valid_stateful_policy_IFSACS_def wf_stateful_policy_def)\n     apply(auto simp add: wf_graph_def)\n     using edgesList filter_IFS_no_violations_subseteq_input filter_compliant_stateful_ACS_subseteq_input by (metis rev_subsetD)\n   qed\n\n   lemma generate_valid_stateful_policy_IFSACS_select_simps:\n   shows \"hosts (generate_valid_stateful_policy_IFSACS G M edgesList) = nodes G\"\n   and   \"flows_fix (generate_valid_stateful_policy_IFSACS G M edgesList) = edges G\"\n   and   \"flows_state (generate_valid_stateful_policy_IFSACS G M edgesList) \\<subseteq> set edgesList\"\n   proof -\n   show  \"hosts (generate_valid_stateful_policy_IFSACS G M edgesList) = nodes G\"\n      by(simp add: generate_valid_stateful_policy_IFSACS_def)\n    show \"flows_fix (generate_valid_stateful_policy_IFSACS G M edgesList) = edges G\"\n      by(simp add: generate_valid_stateful_policy_IFSACS_def)\n    show \"flows_state (generate_valid_stateful_policy_IFSACS G M edgesList) \\<subseteq> set edgesList\"\n      apply(simp add: generate_valid_stateful_policy_IFSACS_def)\n      using filter_IFS_no_violations_subseteq_input filter_compliant_stateful_ACS_subseteq_input by (metis subset_trans)\n    qed\n\n  lemma generate_valid_stateful_policy_IFSACS_all_security_requirements_fulfilled_IFS: assumes validReqs: \"valid_reqs M\"\n          and     wfG: \"wf_graph G\"\n          and     high_level_policy_valid: \"all_security_requirements_fulfilled M G\"\n          and     edgesList: \"(set edgesList) \\<subseteq> edges G\"\n          shows \"all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph (generate_valid_stateful_policy_IFSACS G M edgesList))\"\n  proof -\n   have simp3: \"flows_state (generate_valid_stateful_policy_IFSACS G M edgesList) \\<subseteq> edges G\" using generate_valid_stateful_policy_IFSACS_select_simps(3) edgesList by fast\n\n    have \"set (filter_compliant_stateful_ACS G M (filter_IFS_no_violations G M edgesList)) \\<subseteq> set (filter_IFS_no_violations G M edgesList)\"\n      using filter_compliant_stateful_ACS_subseteq_input edgesList by (metis)\n    from backflows_subseteq this have \n      \"backflows (set (filter_compliant_stateful_ACS G M (filter_IFS_no_violations G M edgesList))) \\<subseteq> backflows (set (filter_IFS_no_violations G M edgesList))\" by metis\n    hence subseteqhlp1:\n      \"edges G \\<union> backflows (set (filter_compliant_stateful_ACS G M (filter_IFS_no_violations G M edgesList))) \\<subseteq> edges G \\<union> backflows (set (filter_IFS_no_violations G M edgesList))\" by blast\n\n    from high_level_policy_valid have \"all_security_requirements_fulfilled (get_IFS M) G\" by(simp add: all_security_requirements_fulfilled_def get_IFS_def)\n    from filter_IFS_no_violations_correct[OF valid_reqs_IFS_D[OF validReqs] wfG this edgesList] have \n      \"all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = set (filter_IFS_no_violations G M edgesList)\\<rparr>)\" .\n      from this edgesList have goalIFS:\n        \"all_security_requirements_fulfilled (get_IFS M) \\<lparr>nodes = nodes G, edges = edges G \\<union> backflows (set (filter_IFS_no_violations G M edgesList))\\<rparr>\"\n        apply(simp add: stateful_policy_to_network_graph_def all_flows_def)\n        by (metis Un_absorb2 filter_IFS_no_violations_subseteq_input order_trans)\n\n\n      from  wfG filter_IFS_no_violations_subseteq_input[where Es=\"edgesList\" and G=\"G\" and M=\"M\"] edgesList have \n        \"wf_graph \\<lparr>nodes = nodes G, edges = set (filter_IFS_no_violations G M edgesList)\\<rparr>\" \n         apply(case_tac G, simp)\n         by (metis le_iff_sup wf_graph_remove_edges_union)\n      from backflows_wf[OF this] have\n        \"wf_graph \\<lparr>nodes = nodes G, edges = backflows (set (filter_IFS_no_violations G M edgesList))\\<rparr>\" by(simp)\n      from this wf_graph_union_edges wfG have \n        \"wf_graph \\<lparr>nodes = nodes G, edges = edges G \\<union> backflows (set (filter_IFS_no_violations G M edgesList))\\<rparr>\" \n        by (metis graph.cases graph.select_convs(1) graph.select_convs(2))\n\n      from all_security_requirements_fulfilled_mono[OF valid_reqs_IFS_D[OF validReqs] subseteqhlp1 this goalIFS]\n        have \"all_security_requirements_fulfilled (get_IFS M) \\<lparr>nodes = nodes G, edges = edges G \\<union> backflows (set (filter_compliant_stateful_ACS G M (filter_IFS_no_violations G M edgesList)))\\<rparr>\"\n        .\n      thus ?thesis\n        apply(simp add: stateful_policy_to_network_graph_def all_flows_def generate_valid_stateful_policy_IFSACS_select_simps simp3 Un_absorb2)\n        by(simp add: generate_valid_stateful_policy_IFSACS_def)\n  qed\n\n  theorem generate_valid_stateful_policy_IFSACS_stateful_policy_compliance:\n  assumes validReqs: \"valid_reqs M\"\n        and     wfG: \"wf_graph G\"\n        and     high_level_policy_valid: \"all_security_requirements_fulfilled M G\"\n        and     edgesList: \"(set edgesList) = edges G\"\n        and     Tau: \"\\<T> = generate_valid_stateful_policy_IFSACS G M edgesList\"\n    shows \"stateful_policy_compliance \\<T> G M\"\n    proof -\n      have 1: \"wf_stateful_policy \\<T>\"\n        apply(simp add: Tau)\n        by(simp add: generate_valid_stateful_policy_IFSACS_wf_stateful_policy[OF wfG edgesList])\n      have 2: \"wf_stateful_policy (generate_valid_stateful_policy_IFSACS G M edgesList)\"\n        by(simp add: generate_valid_stateful_policy_IFSACS_wf_stateful_policy[OF wfG edgesList])\n      have 3: \"hosts \\<T> = nodes G\"\n        apply(simp add: Tau)\n        by(simp add: generate_valid_stateful_policy_IFSACS_select_simps(1))\n      have 4: \"flows_fix \\<T> \\<subseteq> edges G\"\n        apply(simp add: Tau)\n        by(simp add: generate_valid_stateful_policy_IFSACS_select_simps(2))\n      have 5: \" all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<T>)\"\n        apply(simp add: Tau)\n        using generate_valid_stateful_policy_IFSACS_all_security_requirements_fulfilled_IFS[OF validReqs wfG high_level_policy_valid] edgesList by blast\n      have 6: \"\\<forall>F\\<in>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<T>). F \\<subseteq> backflows (filternew_flows_state \\<T>)\"\n        using filter_compliant_stateful_ACS_correct[OF valid_reqs_ACS_D[OF validReqs] wfG _ _ Tau[simplified generate_valid_stateful_policy_IFSACS_def Let_def]] all_security_requirements_fulfilled_ACS_D[OF high_level_policy_valid]\n        edgesList filter_IFS_no_violations_subseteq_input by metis\n\n    from 1 2 3 4 5 6 validReqs high_level_policy_valid wfG\n    show ?thesis\n    unfolding stateful_policy_compliance_def by simp\n  qed\n\n\n\n\n\n  definition generate_valid_stateful_policy_IFSACS_2 :: \"'v::vertex graph \\<Rightarrow> 'v SecurityInvariant_configured list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> 'v stateful_policy\" where\n    \"generate_valid_stateful_policy_IFSACS_2 G M edgesList \\<equiv> \n    \\<lparr> hosts = nodes G, flows_fix = edges G, flows_state = set (filter_IFS_no_violations G M edgesList) \\<inter> set (filter_compliant_stateful_ACS G M edgesList) \\<rparr>\"\n\n\n  lemma generate_valid_stateful_policy_IFSACS_2_wf_stateful_policy: assumes wfG: \"wf_graph G\"\n          and     edgesList: \"(set edgesList) = edges G\"\n          shows \"wf_stateful_policy (generate_valid_stateful_policy_IFSACS_2 G M edgesList)\"\n   proof -\n    from  wfG show ?thesis\n     apply(simp add: generate_valid_stateful_policy_IFSACS_2_def wf_stateful_policy_def)\n     apply(auto simp add: wf_graph_def)\n     using edgesList filter_IFS_no_violations_subseteq_input by (metis rev_subsetD)\n   qed\n\n   lemma generate_valid_stateful_policy_IFSACS_2_select_simps:\n   shows \"hosts (generate_valid_stateful_policy_IFSACS_2 G M edgesList) = nodes G\"\n   and   \"flows_fix (generate_valid_stateful_policy_IFSACS_2 G M edgesList) = edges G\"\n   and   \"flows_state (generate_valid_stateful_policy_IFSACS_2 G M edgesList) \\<subseteq> set edgesList\"\n   proof -\n   show  \"hosts (generate_valid_stateful_policy_IFSACS_2 G M edgesList) = nodes G\"\n      by(simp add: generate_valid_stateful_policy_IFSACS_2_def)\n    show \"flows_fix (generate_valid_stateful_policy_IFSACS_2 G M edgesList) = edges G\"\n      by(simp add: generate_valid_stateful_policy_IFSACS_2_def)\n    show \"flows_state (generate_valid_stateful_policy_IFSACS_2 G M edgesList) \\<subseteq> set edgesList\"\n      apply(simp add: generate_valid_stateful_policy_IFSACS_2_def)\n      using filter_compliant_stateful_ACS_subseteq_input by (metis inf.coboundedI2)\n    qed\n\n  lemma generate_valid_stateful_policy_IFSACS_2_all_security_requirements_fulfilled_IFS: assumes validReqs: \"valid_reqs M\"\n          and     wfG: \"wf_graph G\"\n          and     high_level_policy_valid: \"all_security_requirements_fulfilled M G\"\n          and     edgesList: \"(set edgesList) \\<subseteq> edges G\"\n          shows \"all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph (generate_valid_stateful_policy_IFSACS_2 G M edgesList))\"\n  proof -\n    have subseteq: \"set (filter_IFS_no_violations G M edgesList) \\<inter> set (filter_compliant_stateful_ACS G M edgesList) \\<subseteq> set (filter_IFS_no_violations G M edgesList)\" by blast\n\n    from wfG filter_IFS_no_violations_subseteq_input edgesList\n    have wfG': \"wf_graph \\<lparr>nodes = nodes G, edges = edges G \\<union> set (filter_IFS_no_violations G M edgesList)\\<rparr>\" \n      by (metis graph_eq_intro Un_absorb2 graph.select_convs(1) graph.select_convs(2) order.trans)\n\n    from high_level_policy_valid have \"all_security_requirements_fulfilled (get_IFS M) G\" by(simp add: all_security_requirements_fulfilled_def get_IFS_def)\n    from filter_IFS_no_violations_correct[OF valid_reqs_IFS_D[OF validReqs] wfG this edgesList] have \n      \"all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = set (filter_IFS_no_violations G M edgesList)\\<rparr>)\" .\n\n\n    from all_security_requirements_fulfilled_mono_stateful_policy_to_network_graph[OF valid_reqs_IFS_D[OF validReqs] subseteq wfG' this]\n    have \"all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph (generate_valid_stateful_policy_IFSACS_2 G M edgesList))\"\n      by(simp add: generate_valid_stateful_policy_IFSACS_2_def)\n    thus ?thesis .\n  qed\n\n\n  lemma generate_valid_stateful_policy_IFSACS_2_filter_compliant_stateful_ACS:\n  assumes validReqs: \"valid_reqs M\"\n        and     wfG: \"wf_graph G\"\n        and     high_level_policy_valid: \"all_security_requirements_fulfilled M G\"\n        and     edgesList: \"(set edgesList) \\<subseteq> edges G\"\n        and     Tau: \"\\<T> = generate_valid_stateful_policy_IFSACS_2 G M edgesList\"\n  shows \"\\<forall>F\\<in>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<T>). F \\<subseteq> backflows (filternew_flows_state \\<T>)\"\n    proof- \n      let ?filterACS = \"set (filter_compliant_stateful_ACS G M edgesList)\"\n      let ?filterIFS = \"set (filter_IFS_no_violations G M edgesList)\"\n      from all_security_requirements_fulfilled_ACS_D[OF high_level_policy_valid] have \"all_security_requirements_fulfilled (get_ACS M) G\" .\n\n      from filter_compliant_stateful_ACS_correct[OF valid_reqs_ACS_D[OF validReqs] wfG edgesList this] have \n        \"\\<forall>F\\<in>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph  \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = ?filterACS\\<rparr>). \n          F \\<subseteq> backflows (?filterACS) - edges G\"\n        apply(simp)\n        apply(simp add: backflows_minus_backflows[symmetric])\n        by(simp add: filternew_flows_state_alt)\n      hence \"\\<forall>F\\<in>get_offending_flows (get_ACS M) \\<lparr>nodes = nodes G, edges = edges G \\<union> backflows (?filterACS)\\<rparr>. F \\<subseteq> backflows (?filterACS) - edges G\"\n        apply(simp add: stateful_policy_to_network_graph_def all_flows_def)\n        using filter_compliant_stateful_ACS_subseteq_input by (metis (lifting, no_types) Un_absorb2 edgesList order_trans)\n      from this validReqs have offending_filterACS_upperbound:\n        \"\\<And>m. m \\<in> set (get_ACS M) \\<Longrightarrow> \n        \\<Union>(c_offending_flows m \\<lparr>nodes = nodes G, edges = edges G \\<union> backflows (?filterACS)\\<rparr>) \\<subseteq> \n          backflows (?filterACS) - edges G\"\n        by(simp add: valid_reqs_def get_offending_flows_def, blast)\n\n      from wfG filter_compliant_stateful_ACS_subseteq_input edgesList have \"wf_graph \\<lparr>nodes = nodes G, edges = ?filterACS\\<rparr>\"\n        by (metis graph.cases graph.select_convs(1) graph.select_convs(2) le_iff_sup wf_graph_remove_edges_union)\n      from this backflows_wf have \"wf_graph \\<lparr>nodes = nodes G, edges = backflows (?filterACS)\\<rparr>\" by blast\n      moreover have \"wf_graph \\<lparr>nodes = nodes G, edges = edges G\\<rparr>\" using wfG by(case_tac G, simp)\n      ultimately have wfG1: \"wf_graph \\<lparr>nodes = nodes G, edges = edges G \\<union> backflows (?filterACS)\\<rparr>\"\n        using wf_graph_union_edges by blast\n        \n      from edgesList have edgesUnsimp: \"edges G \\<union> (?filterACS \\<inter> ?filterIFS) = edges G\"\n        using filter_IFS_no_violations_subseteq_input filter_compliant_stateful_ACS_subseteq_input by blast\n\n      \\<comment> \\<open>We set up a ?REM that we use in the @{thm configured_SecurityInvariant.Un_set_offending_flows_bound_minus_subseteq} lemma\\<close>\n      let ?REM = \"(backflows (?filterACS) - backflows (?filterIFS)) - edges G\"\n\n      have REM_gives_desired_upper_bound: \"(backflows (?filterACS) - edges G) - ?REM = backflows (?filterACS \\<inter> ?filterIFS) - edges G\"\n        by(simp add: backflows_def, blast)\n\n      have REM_gives_desired_edges: \"(edges G \\<union> backflows (?filterACS)) - ?REM = edges G \\<union> (backflows (?filterACS \\<inter> ?filterIFS))\"\n        by(simp add: backflows_def, blast)\n\n      from wfG have \"finite (edges G)\" using wf_graph_def by blast\n      hence \"finite (backflows ?filterACS)\" using backflows_finite by (metis List.finite_set)\n      hence finite1: \"finite (backflows (?filterACS) - backflows (?filterIFS) - edges G)\" by fast\n\n      from configured_SecurityInvariant.Un_set_offending_flows_bound_minus_subseteq[where E'=\"?REM\" and X=\"(backflows (?filterACS) - edges G)\",\n          OF _ wfG1 offending_filterACS_upperbound, simplified REM_gives_desired_upper_bound REM_gives_desired_edges\n          ] valid_reqs_ACS_D[OF validReqs, unfolded valid_reqs_def]\n      have \"\\<And>m. m \\<in> set (get_ACS M) \\<Longrightarrow>\n              \\<forall>F\\<in>c_offending_flows m \\<lparr>nodes = nodes G, edges = edges G \\<union> backflows (?filterACS \\<inter> ?filterIFS)\\<rparr>.\n                  F \\<subseteq> backflows (?filterACS \\<inter> ?filterIFS) - edges G\" by blast\n      hence \"\\<forall>F\\<in>get_offending_flows (get_ACS M)\n         \\<lparr>nodes = nodes G, edges = edges G \\<union> (backflows (?filterACS \\<inter> ?filterIFS))\\<rparr>. F \\<subseteq> backflows (?filterACS \\<inter> ?filterIFS) - edges G\"\n       using get_offending_flows_def by fast\n      hence \"\\<forall>F\\<in>get_offending_flows (get_ACS M)\n         \\<lparr>nodes = nodes G, edges = edges G \\<union> (?filterACS \\<inter> ?filterIFS) \\<union> (backflows (?filterACS \\<inter> ?filterIFS))\\<rparr>.\n       F \\<subseteq> backflows (?filterACS \\<inter> ?filterIFS) - edges G\"\n        by(simp add: edgesUnsimp)\n      hence \"\\<forall>F\\<in>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = ?filterACS \\<inter> ?filterIFS\\<rparr>).\n                F \\<subseteq> backflows (?filterACS \\<inter> ?filterIFS) - edges G\"\n        by(simp add: stateful_policy_to_network_graph_def all_flows_def)\n\n      thus ?thesis\n        apply(simp add: Tau generate_valid_stateful_policy_IFSACS_2_def)\n        apply(simp add: filternew_flows_state_alt backflows_minus_backflows)\n        by (metis inf_commute)\n    qed\n        \n\n\n\n\n  theorem generate_valid_stateful_policy_IFSACS_2_stateful_policy_compliance:\n  assumes validReqs: \"valid_reqs M\"\n        and     wfG: \"wf_graph G\"\n        and     high_level_policy_valid: \"all_security_requirements_fulfilled M G\"\n        and     edgesList: \"(set edgesList) = edges G\"\n        and     Tau: \"\\<T> = generate_valid_stateful_policy_IFSACS_2 G M edgesList\"\n    shows \"stateful_policy_compliance \\<T> G M\"\n    proof -\n      have 1: \"wf_stateful_policy \\<T>\"\n        apply(simp add: Tau)\n        by(simp add: generate_valid_stateful_policy_IFSACS_2_wf_stateful_policy[OF wfG edgesList])\n      have 2: \"wf_stateful_policy (generate_valid_stateful_policy_IFSACS G M edgesList)\"\n        by(simp add: generate_valid_stateful_policy_IFSACS_wf_stateful_policy[OF wfG edgesList])\n      have 3: \"hosts \\<T> = nodes G\"\n        apply(simp add: Tau)\n        by(simp add: generate_valid_stateful_policy_IFSACS_2_select_simps(1))\n      have 4: \"flows_fix \\<T> \\<subseteq> edges G\"\n        apply(simp add: Tau)\n        by(simp add: generate_valid_stateful_policy_IFSACS_2_select_simps(2))\n      have 5: \"all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<T>)\"\n        apply(simp add: Tau)\n        using generate_valid_stateful_policy_IFSACS_2_all_security_requirements_fulfilled_IFS[OF validReqs wfG high_level_policy_valid] edgesList by blast\n      have 6: \"\\<forall>F\\<in>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<T>). F \\<subseteq> backflows (filternew_flows_state \\<T>)\"\n        using generate_valid_stateful_policy_IFSACS_2_filter_compliant_stateful_ACS[OF \n            validReqs wfG high_level_policy_valid]\n        Tau edgesList by auto\n\n    from 1 2 3 4 5 6 validReqs high_level_policy_valid wfG\n    show ?thesis\n    unfolding stateful_policy_compliance_def by simp\n  qed\n\n\n\n\n\n  text\\<open>\n    If there are no IFS requirements and the ACS requirements cause no side effects,\n    effectively, the graph can be considered as undirected graph! \n\\<close>\n  lemma generate_valid_stateful_policy_IFSACS_2_noIFS_noACSsideeffects_imp_fullgraph:\n  assumes validReqs: \"valid_reqs M\"\n        and     wfG: \"wf_graph G\"\n        and     high_level_policy_valid: \"all_security_requirements_fulfilled M G\"\n        and     edgesList: \"(set edgesList) = edges G\"\n        and     no_ACS_sideeffects: \"\\<forall>F \\<in> get_offending_flows (get_ACS M) \\<lparr>nodes = nodes G, edges = edges G \\<union> backflows (edges G)\\<rparr>. F \\<subseteq> (backflows (edges G)) - (edges G)\"\n        and     no_IFS: \"get_IFS M = []\"\n  shows \"stateful_policy_to_network_graph (generate_valid_stateful_policy_IFSACS_2 G M edgesList) = undirected G\"\n  proof -\n    from filter_IFS_no_violations_accu_no_IFS[OF valid_reqs_IFS_D[OF validReqs] wfG no_IFS] edgesList\n      have \"filter_IFS_no_violations G M edgesList = rev edgesList\"\n      by(simp add: filter_IFS_no_violations_def)\n    from this filter_compliant_stateful_ACS_subseteq_input have flows_state_IFS: \"flows_state (generate_valid_stateful_policy_IFSACS_2 G M edgesList) = set (filter_compliant_stateful_ACS G M edgesList)\"\n      by(auto simp add: generate_valid_stateful_policy_IFSACS_2_def)\n\n    have flowsfix: \"flows_fix (generate_valid_stateful_policy_IFSACS_2 G M edgesList) = edges G\" by(simp add: generate_valid_stateful_policy_IFSACS_2_def)\n\n    have hosts: \"hosts (generate_valid_stateful_policy_IFSACS_2 G M edgesList) = nodes G\" by(simp add: generate_valid_stateful_policy_IFSACS_2_def)\n\n    from filter_compliant_stateful_ACS_accu_no_side_effects[OF valid_reqs_ACS_D[OF validReqs] wfG no_ACS_sideeffects] have \n      \"filter_compliant_stateful_ACS G M edgesList = rev [e\\<leftarrow>edgesList . e \\<notin> backflows (edges G)]\"\n      by(simp add: filter_compliant_stateful_ACS_def edgesList)\n    hence filterACS: \"set (filter_compliant_stateful_ACS G M edgesList) = edges G - (backflows (edges G))\" using edgesList by force\n\n    show ?thesis\n      apply(simp add: undirected_backflows stateful_policy_to_network_graph_def all_flows_def)\n      apply(simp add: hosts filterACS flows_state_IFS flowsfix)\n      apply(simp add: backflows_minus_backflows)\n      by fast\n    qed\n  lemma generate_valid_stateful_policy_IFSACS_noIFS_noACSsideeffects_imp_fullgraph:\n  assumes validReqs: \"valid_reqs M\"\n        and     wfG: \"wf_graph G\"\n        and     high_level_policy_valid: \"all_security_requirements_fulfilled M G\"\n        and     edgesList: \"(set edgesList) = edges G\"\n        and     no_ACS_sideeffects: \"\\<forall>F \\<in> get_offending_flows (get_ACS M) \\<lparr>nodes = nodes G, edges = edges G \\<union> backflows (edges G)\\<rparr>. F \\<subseteq> (backflows (edges G)) - (edges G)\"\n        and     no_IFS: \"get_IFS M = []\"\n  shows \"stateful_policy_to_network_graph (generate_valid_stateful_policy_IFSACS G M edgesList) = undirected G\"\n  proof -\n    from filter_IFS_no_violations_accu_no_IFS[OF valid_reqs_IFS_D[OF validReqs] wfG no_IFS] edgesList\n      have \"filter_IFS_no_violations G M edgesList = rev edgesList\"\n      by(simp add: filter_IFS_no_violations_def)\n    from this filter_compliant_stateful_ACS_subseteq_input have flows_state_IFS: \"flows_state (generate_valid_stateful_policy_IFSACS G M edgesList) = set (filter_compliant_stateful_ACS G M (rev edgesList))\"\n      by(simp add: generate_valid_stateful_policy_IFSACS_def)\n\n    have flowsfix: \"flows_fix (generate_valid_stateful_policy_IFSACS G M edgesList) = edges G\" by(simp add: generate_valid_stateful_policy_IFSACS_def)\n\n    have hosts: \"hosts (generate_valid_stateful_policy_IFSACS G M edgesList) = nodes G\" by(simp add: generate_valid_stateful_policy_IFSACS_def)\n\n    from filter_compliant_stateful_ACS_accu_no_side_effects[OF valid_reqs_ACS_D[OF validReqs] wfG no_ACS_sideeffects] have \n      \"filter_compliant_stateful_ACS G M (rev edgesList) = [e\\<leftarrow>edgesList . e \\<notin> backflows (edges G)]\"\n      apply(simp add: filter_compliant_stateful_ACS_def edgesList) by (metis rev_filter rev_swap)\n    hence filterACS: \"set (filter_compliant_stateful_ACS G M (rev edgesList)) = edges G - (backflows (edges G))\" using edgesList by force\n\n    show ?thesis\n      apply(simp add: undirected_backflows stateful_policy_to_network_graph_def all_flows_def)\n      apply(simp add: hosts filterACS flows_state_IFS flowsfix)\n      apply(simp add: backflows_minus_backflows)\n      by fast\n    qed\n\n\n(*\ntext{* In the repo history, we see failed attempts which try to prove that under composition, the IFS and ACS filtering is also maximal.\n       I guess this does not hold in general. Needs a counter example. *}\n\n*)\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Network_Security_Policy_Verification/TopoS_Stateful_Policy_Algorithm.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7154239957834733, "lm_q2_score": 0.4035668537353746, "lm_q1q2_score": 0.2887214110651262}}
{"text": "theory Hoare_Lift_Transform\nimports Hoare_Lift\nbegin\n\n(* Alternative approach to Hoare lifting:\ntransforming predicate transformers. *)\n(* TODO: this probably is no longer needed *)\n(*\n  assume\n  {P} c {Q(P, c)}\n\n  want to derive\n  {Pbig} lift(c) {Qbig(P, c)} where\n  \nidea:\n  Pbig \\<rightarrow> (\\ st . exists rest . Pbig (st + rest))\n*)\n\ndefinition liftt_conc ::\n  \"('a1, 'b1) syn_lifting \\<Rightarrow>\n   ('a1, 'a2, 'b2 :: {Pord, Okay}) lifting \\<Rightarrow>\n   'b1 \\<Rightarrow>\n   (('a2 \\<Rightarrow> bool) \\<Rightarrow> ('a2 \\<Rightarrow> bool)) \\<Rightarrow>\n   (('b2 \\<Rightarrow> bool) \\<Rightarrow> ('b2 \\<Rightarrow> bool))\" where\n\"liftt_conc sl l syn Q1 P2 st_big =\n  (\\<exists> old st_small . st_big = LUpd l (sl syn) st_small old \\<and>\n   P2 old \\<and>\n   Q1 (\\<lambda> st . \\<exists> full . LOut l (sl syn) full = st \\<and> P2 full) st_small)\"\n\nlemma liftt_conc_spec :\n  assumes Valid : \"lifting_valid l S\"\n  assumes V : \"\\<And> P . (sem) % {{P}} x {{(Q P)}}\"\n  assumes Syn : \"l' x' = x\"\n  shows \"\\<And> P' . (lift_map_s l' l sem) % {{P'}} x' {{liftt_conc l' l x' Q P'}}\"\n  using V Syn\n  unfolding HTS_def HT_def liftt_conc_def lift_map_s_def \n  apply(auto)\n  apply(rule_tac x = a in exI)\n  apply(rule_tac x = \"(sem (l' x') (LOut l (l' x') a))\" in exI)\n  apply(auto)\n  apply(atomize)\n  apply(drule_tac x = \"(\\<lambda>st. \\<exists>full. LOut l (l' x') full = st \\<and> P' full)\" in spec)\n  apply(auto)\n  done\nterm \"LOut\"\n\n  (* new idea: a more streamlined version. *)\n(* TODO: give this a better name *)\n(* TODO: do we need Hok? *)\nlemma new_lift :\n  fixes P' :: \"_ \\<Rightarrow> bool\"\n  assumes HP : \"\\<And> st . P st \\<Longrightarrow> P' (LOut l x st)\"\n  assumes HOk : \"\\<And> st . P st \\<Longrightarrow> st \\<in> ok_S\"\n  assumes HV : \"lifting_valid_ok_ext l S\"\n  assumes Hsyn : \"l' x' = x\"\n  assumes HT : \"sem % {{P'}} x {{Q'}}\"\n  shows \"(lift_map_s l' l sem) % \n    {{P}} x' \n    {{(\\<lambda> st . \\<exists> old_big small_new . P old_big \\<and> Q' small_new \\<and> st = LUpd l x small_new old_big \\<and> st \\<in> ok_S)}}\"\nproof(rule HTSI)\n  fix a\n  assume H : \"P a\"\n\n  then have H' : \"P' (LOut l x a)\"\n    using HP\n    by blast\n\n  have Q' : \"Q' (sem x (LOut l x a))\"\n    using HTSE[OF HT H']\n    by auto\n\n  interpret V : lifting_valid_ok_ext l S\n    using HV.\n\n  have Ok' : \"LUpd l x (sem x (LOut l x a)) a \\<in> ok_S\"\n    using V.ok_S_put[OF HOk[OF H]]\n    by auto\n\n  show \" \\<exists>old_big small_new.\n            P old_big \\<and>\n            Q' small_new \\<and>\n            lift_map_s l' l sem x' a = LUpd l x small_new old_big \\<and>\n            lift_map_s l' l sem x' a \\<in> ok_S\"\n    unfolding lift_map_s_def Hsyn LMap_def\n    using H Q' Ok'\n    by blast\nqed\n\n\n(*\ndefinition liftt_pred_validx_s ::\n  \"('a1, 'b1) syn_lifting \\<Rightarrow>\n   ('a1, 'a2, 'b2 :: {Pord, Okay}, 'z) lifting_scheme \\<Rightarrow>\n   ('a1 \\<Rightarrow> 'b2 set) \\<Rightarrow>\n   'b1 \\<Rightarrow>\n   ('a2 \\<Rightarrow> bool) \\<Rightarrow>\n   ('b2 \\<Rightarrow> bool)\"\n*)\n\nend", "meta": {"author": "mmalvarez", "repo": "Gazelle", "sha": "0a80144107b3ec7487725bd88d658843beb6cb82", "save_path": "github-repos/isabelle/mmalvarez-Gazelle", "path": "github-repos/isabelle/mmalvarez-Gazelle/Gazelle-0a80144107b3ec7487725bd88d658843beb6cb82/Hoare/Hoare_Lift_Transform.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6261241772283034, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.2886537516353661}}
{"text": "\\<^marker>\\<open>creator \"Kevin Kappelmann\"\\<close>\nparagraph \\<open>Galois Property\\<close>\ntheory Transport_Compositions_Generic_Galois_Property\n  imports\n    Transport_Compositions_Generic_Base\nbegin\n\ncontext transport_comp\nbegin\n\ninterpretation flip : transport_comp R2 L2 r2 l2 R1 L1 r1 l1\n  rewrites \"flip.t2.unit = \\<epsilon>\\<^sub>1\" and \"flip.t1.counit \\<equiv> \\<eta>\\<^sub>2\"\n  by (simp_all only: t1.flip_unit_eq_counit t2.flip_counit_eq_unit)\n\nlemma half_galois_prop_left_left_rightI:\n  assumes \"((\\<le>\\<^bsub>L1\\<^esub>) \\<^sub>h\\<unlhd> (\\<le>\\<^bsub>R1\\<^esub>)) l1 r1\"\n  and deflationary_counit1: \"deflationary_on (in_codom (\\<le>\\<^bsub>R1\\<^esub>)) (\\<le>\\<^bsub>R1\\<^esub>) \\<epsilon>\\<^sub>1\"\n  and trans_R1: \"transitive (\\<le>\\<^bsub>R1\\<^esub>)\"\n  and \"((\\<le>\\<^bsub>L2\\<^esub>) \\<Rrightarrow>\\<^sub>m (\\<le>\\<^bsub>R2\\<^esub>)) l2\"\n  and \"reflexive_on (in_codom (\\<le>\\<^bsub>L2\\<^esub>)) (\\<le>\\<^bsub>L2\\<^esub>)\"\n  and \"((\\<le>\\<^bsub>R1\\<^esub>) \\<circ>\\<circ> (\\<le>\\<^bsub>L2\\<^esub>) \\<circ>\\<circ> (\\<le>\\<^bsub>R1\\<^esub>)) \\<le> ((\\<le>\\<^bsub>L2\\<^esub>) \\<circ>\\<circ> (\\<le>\\<^bsub>R1\\<^esub>))\"\n  and \"in_codom ((\\<le>\\<^bsub>R1\\<^esub>) \\<circ>\\<circ> (\\<le>\\<^bsub>L2\\<^esub>) \\<circ>\\<circ> (\\<le>\\<^bsub>R1\\<^esub>)) \\<le> in_codom (\\<le>\\<^bsub>L2\\<^esub>)\"\n  and mono_in_codom_r2: \"([in_codom (\\<le>\\<^bsub>R\\<^esub>)] \\<Rrightarrow>\\<^sub>m in_codom (\\<le>\\<^bsub>R1\\<^esub>)) r2\"\n  shows \"((\\<le>\\<^bsub>L\\<^esub>) \\<^sub>h\\<unlhd> (\\<le>\\<^bsub>R\\<^esub>)) l r\"\nproof (rule half_galois_prop_leftI)\n  fix x z assume \"in_codom (\\<le>\\<^bsub>R\\<^esub>) z\" \"x \\<le>\\<^bsub>L\\<^esub> r z\"\n  then show \"l x \\<le>\\<^bsub>R\\<^esub> z\"\n  proof (intro right_rel_if_left_relI)\n    from \\<open>in_codom (\\<le>\\<^bsub>R\\<^esub>) z\\<close> show \"in_codom (\\<le>\\<^bsub>R2\\<^esub>) z\" by blast\n    fix y assume \"y \\<le>\\<^bsub>R1\\<^esub> l1 (r z)\"\n    moreover have \"l1 (r z) \\<le>\\<^bsub>R1\\<^esub> r2 z\"\n    proof -\n      from mono_in_codom_r2 \\<open>in_codom (\\<le>\\<^bsub>R\\<^esub>) z\\<close> have \"in_codom (\\<le>\\<^bsub>R1\\<^esub>) (r2 z)\" by blast\n      with deflationary_counit1 show \"l1 (r z) \\<le>\\<^bsub>R1\\<^esub> r2 z\" by auto\n    qed\n    ultimately show \"y \\<le>\\<^bsub>R1\\<^esub> r2 z\" using trans_R1 by blast\n  next\n    fix y assume \"l1 x \\<le>\\<^bsub>L2\\<^esub> y\"\n    with \\<open>((\\<le>\\<^bsub>L2\\<^esub>) \\<Rrightarrow>\\<^sub>m (\\<le>\\<^bsub>R2\\<^esub>)) l2\\<close> show \"l x \\<le>\\<^bsub>R2\\<^esub> l2 y\" by auto\n  qed (insert assms, auto)\nqed\n\nlemma half_galois_prop_left_left_rightI':\n  assumes \"((\\<le>\\<^bsub>L1\\<^esub>) \\<^sub>h\\<unlhd> (\\<le>\\<^bsub>R1\\<^esub>)) l1 r1\"\n  and deflationary_counit1: \"deflationary_on (in_codom (\\<le>\\<^bsub>R1\\<^esub>)) (\\<le>\\<^bsub>R1\\<^esub>) \\<epsilon>\\<^sub>1\"\n  and trans_R1: \"transitive (\\<le>\\<^bsub>R1\\<^esub>)\"\n  and \"((\\<le>\\<^bsub>L2\\<^esub>) \\<Rrightarrow>\\<^sub>m (\\<le>\\<^bsub>R2\\<^esub>)) l2\"\n  and refl_L2: \"reflexive_on (in_dom (\\<le>\\<^bsub>L2\\<^esub>)) (\\<le>\\<^bsub>L2\\<^esub>)\"\n  and \"((\\<le>\\<^bsub>R1\\<^esub>) \\<circ>\\<circ> (\\<le>\\<^bsub>L2\\<^esub>) \\<circ>\\<circ> (\\<le>\\<^bsub>R1\\<^esub>)) \\<le> ((\\<le>\\<^bsub>R1\\<^esub>) \\<circ>\\<circ> (\\<le>\\<^bsub>L2\\<^esub>))\"\n  and \"in_dom ((\\<le>\\<^bsub>R1\\<^esub>) \\<circ>\\<circ> (\\<le>\\<^bsub>L2\\<^esub>) \\<circ>\\<circ> (\\<le>\\<^bsub>R1\\<^esub>)) \\<le> in_dom (\\<le>\\<^bsub>L2\\<^esub>)\"\n  and mono_in_codom_r2: \"([in_codom (\\<le>\\<^bsub>R\\<^esub>)] \\<Rrightarrow>\\<^sub>m in_codom (\\<le>\\<^bsub>R1\\<^esub>)) r2\"\n  shows \"((\\<le>\\<^bsub>L\\<^esub>) \\<^sub>h\\<unlhd> (\\<le>\\<^bsub>R\\<^esub>)) l r\"\nproof (rule half_galois_prop_leftI)\n  fix x z assume \"in_codom (\\<le>\\<^bsub>R\\<^esub>) z\" \"x \\<le>\\<^bsub>L\\<^esub> r z\"\n  then show \"l x \\<le>\\<^bsub>R\\<^esub> z\"\n  proof (intro right_rel_if_left_relI')\n    from \\<open>in_codom (\\<le>\\<^bsub>R\\<^esub>) z\\<close> show \"in_codom (\\<le>\\<^bsub>R2\\<^esub>) z\" by blast\n    fix y assume \"y \\<le>\\<^bsub>R1\\<^esub> l1 (r z)\"\n    moreover have \"l1 (r z) \\<le>\\<^bsub>R1\\<^esub> r2 z\"\n    proof -\n      from mono_in_codom_r2 \\<open>in_codom (\\<le>\\<^bsub>R\\<^esub>) z\\<close> have \"in_codom (\\<le>\\<^bsub>R1\\<^esub>) (r2 z)\" by blast\n      with deflationary_counit1 show \"l1 (r z) \\<le>\\<^bsub>R1\\<^esub> r2 z\" by auto\n    qed\n    ultimately show \"y \\<le>\\<^bsub>R1\\<^esub> r2 z\" using trans_R1 by blast\n  next\n    assume \"in_dom (\\<le>\\<^bsub>L2\\<^esub>) (l1 x)\"\n    with refl_L2 have \"l1 x \\<le>\\<^bsub>L2\\<^esub> l1 x\" by blast\n    with \\<open>((\\<le>\\<^bsub>L2\\<^esub>) \\<Rrightarrow>\\<^sub>m (\\<le>\\<^bsub>R2\\<^esub>)) l2\\<close> show \"in_codom (\\<le>\\<^bsub>L2\\<^esub>) (l1 x)\" \"l x \\<le>\\<^bsub>R2\\<^esub> l2 (l1 x)\"\n      by auto\n  qed (insert assms, auto)\nqed\n\nlemma half_galois_prop_right_left_rightI:\n  assumes \"((\\<le>\\<^bsub>R1\\<^esub>) \\<Rrightarrow>\\<^sub>m (\\<le>\\<^bsub>L1\\<^esub>)) r1\"\n  and \"((\\<le>\\<^bsub>L1\\<^esub>) \\<unlhd>\\<^sub>h (\\<le>\\<^bsub>R1\\<^esub>)) l1 r1\"\n  and inflationary_counit1: \"inflationary_on (in_codom (\\<le>\\<^bsub>R1\\<^esub>)) (\\<le>\\<^bsub>R1\\<^esub>) \\<epsilon>\\<^sub>1\"\n  and \"((\\<le>\\<^bsub>R2\\<^esub>) \\<^sub>h\\<unlhd> (\\<le>\\<^bsub>L2\\<^esub>)) r2 l2\"\n  and inflationary_unit2: \"inflationary_on (in_dom (\\<le>\\<^bsub>L2\\<^esub>)) (\\<le>\\<^bsub>L2\\<^esub>) \\<eta>\\<^sub>2\"\n  and trans_L2: \"transitive (\\<le>\\<^bsub>L2\\<^esub>)\"\n  and mono_in_dom_l1: \"([in_dom (\\<le>\\<^bsub>L\\<^esub>)] \\<Rrightarrow>\\<^sub>m in_dom (\\<le>\\<^bsub>L2\\<^esub>)) l1\"\n  and \"((\\<le>\\<^bsub>L2\\<^esub>) \\<circ>\\<circ> (\\<le>\\<^bsub>R1\\<^esub>) \\<circ>\\<circ> (\\<le>\\<^bsub>L2\\<^esub>)) \\<le> ((\\<le>\\<^bsub>R1\\<^esub>) \\<circ>\\<circ> (\\<le>\\<^bsub>L2\\<^esub>))\"\n  and \"in_codom ((\\<le>\\<^bsub>L2\\<^esub>) \\<circ>\\<circ> (\\<le>\\<^bsub>R1\\<^esub>) \\<circ>\\<circ> (\\<le>\\<^bsub>L2\\<^esub>)) \\<le> in_codom (\\<le>\\<^bsub>R1\\<^esub>)\"\n  shows \"((\\<le>\\<^bsub>L\\<^esub>) \\<unlhd>\\<^sub>h (\\<le>\\<^bsub>R\\<^esub>)) l r\"\nproof (rule half_galois_prop_rightI)\n  fix x z assume \"in_dom (\\<le>\\<^bsub>L\\<^esub>) x\" \"l x \\<le>\\<^bsub>R\\<^esub> z\"\n  then show \"x \\<le>\\<^bsub>L\\<^esub> r z\"\n  proof (intro flip.right_rel_if_left_relI)\n    fix y assume \"r2 (l x) \\<le>\\<^bsub>L2\\<^esub> y\"\n    moreover have \"l1 x \\<le>\\<^bsub>L2\\<^esub> r2 (l x)\"\n    proof -\n      from mono_in_dom_l1 \\<open>in_dom (\\<le>\\<^bsub>L\\<^esub>) x\\<close> have \"in_dom (\\<le>\\<^bsub>L2\\<^esub>) (l1 x)\" by blast\n      with inflationary_unit2 show \"l1 x \\<le>\\<^bsub>L2\\<^esub> r2 (l x)\" by auto\n    qed\n    ultimately show \"l1 x \\<le>\\<^bsub>L2\\<^esub> y\" using trans_L2 by blast\n    fix y assume \"l1 x \\<le>\\<^bsub>R1\\<^esub> y\"\n    with \\<open>((\\<le>\\<^bsub>L1\\<^esub>) \\<unlhd>\\<^sub>h (\\<le>\\<^bsub>R1\\<^esub>)) l1 r1\\<close> \\<open>in_dom (\\<le>\\<^bsub>L\\<^esub>) x\\<close> show \"x \\<le>\\<^bsub>L1\\<^esub> r1 y\" by blast\n  next\n    assume \"in_codom (\\<le>\\<^bsub>R1\\<^esub>) (r2 z)\"\n    with inflationary_counit1 show \"r2 z \\<le>\\<^bsub>R1\\<^esub> l1 (r z)\" by auto\n    from \\<open>((\\<le>\\<^bsub>R1\\<^esub>) \\<Rrightarrow>\\<^sub>m (\\<le>\\<^bsub>L1\\<^esub>)) r1\\<close> \\<open>in_codom (\\<le>\\<^bsub>R1\\<^esub>) (r2 z)\\<close> show \"in_codom (\\<le>\\<^bsub>L1\\<^esub>) (r z)\"\n      by (auto intro: in_codom_if_rel_if_dep_mono_wrt_rel)\n  qed (insert assms, auto)\nqed\n\nlemma half_galois_prop_right_left_rightI':\n  assumes \"((\\<le>\\<^bsub>R1\\<^esub>) \\<Rrightarrow>\\<^sub>m (\\<le>\\<^bsub>L1\\<^esub>)) r1\"\n  and inflationary_unit1: \"inflationary_on (in_dom (\\<le>\\<^bsub>L1\\<^esub>)) (\\<le>\\<^bsub>L1\\<^esub>) \\<eta>\\<^sub>1\"\n  and inflationary_counit1: \"\\<And>y z. y \\<le>\\<^bsub>R1\\<^esub> r2 z \\<Longrightarrow> y \\<le>\\<^bsub>R1\\<^esub> l1 (r z)\"\n  and \"in_dom (\\<le>\\<^bsub>R1\\<^esub>) \\<le> in_codom (\\<le>\\<^bsub>R1\\<^esub>)\"\n  and \"((\\<le>\\<^bsub>R2\\<^esub>) \\<^sub>h\\<unlhd> (\\<le>\\<^bsub>L2\\<^esub>)) r2 l2\"\n  and inflationary_unit2: \"inflationary_on (in_dom (\\<le>\\<^bsub>L2\\<^esub>)) (\\<le>\\<^bsub>L2\\<^esub>) \\<eta>\\<^sub>2\"\n  and trans_L2: \"transitive (\\<le>\\<^bsub>L2\\<^esub>)\"\n  and mono_in_dom_l1: \"([in_dom (\\<le>\\<^bsub>L\\<^esub>)] \\<Rrightarrow>\\<^sub>m in_dom (\\<le>\\<^bsub>L2\\<^esub>)) l1\"\n  and \"((\\<le>\\<^bsub>L2\\<^esub>) \\<circ>\\<circ> (\\<le>\\<^bsub>R1\\<^esub>) \\<circ>\\<circ> (\\<le>\\<^bsub>L2\\<^esub>)) \\<le> ((\\<le>\\<^bsub>L2\\<^esub>) \\<circ>\\<circ> (\\<le>\\<^bsub>R1\\<^esub>))\"\n  and \"in_dom ((\\<le>\\<^bsub>L2\\<^esub>) \\<circ>\\<circ> (\\<le>\\<^bsub>R1\\<^esub>) \\<circ>\\<circ> (\\<le>\\<^bsub>L2\\<^esub>)) \\<le> in_dom (\\<le>\\<^bsub>R1\\<^esub>)\"\n  shows \"((\\<le>\\<^bsub>L\\<^esub>) \\<unlhd>\\<^sub>h (\\<le>\\<^bsub>R\\<^esub>)) l r\"\nproof (rule half_galois_prop_rightI)\n  fix x z assume \"in_dom (\\<le>\\<^bsub>L\\<^esub>) x\" \"l x \\<le>\\<^bsub>R\\<^esub> z\"\n  then show \"x \\<le>\\<^bsub>L\\<^esub> r z\"\n  proof (intro flip.right_rel_if_left_relI')\n    from \\<open>in_dom (\\<le>\\<^bsub>L\\<^esub>) x\\<close> inflationary_unit1 show \"x \\<le>\\<^bsub>L1\\<^esub> r1 (l1 x)\" by fastforce\n    fix y assume \"y \\<le>\\<^bsub>R1\\<^esub> r2 z\"\n    with inflationary_counit1 show \"y \\<le>\\<^bsub>R1\\<^esub> l1 (r z)\" by auto\n  next\n    fix y\n    from mono_in_dom_l1 \\<open>in_dom (\\<le>\\<^bsub>L\\<^esub>) x\\<close> have \"in_dom (\\<le>\\<^bsub>L2\\<^esub>) (l1 x)\" by blast\n    with inflationary_unit2 have \"l1 x \\<le>\\<^bsub>L2\\<^esub> r2 (l x)\" by auto\n    moreover assume \"r2 (l x) \\<le>\\<^bsub>L2\\<^esub> y\"\n    ultimately show \"l1 x \\<le>\\<^bsub>L2\\<^esub> y\" using trans_L2 by blast\n  qed (insert assms, auto)\nqed\n\nlemma galois_prop_left_rightI:\n  assumes \"((\\<le>\\<^bsub>R1\\<^esub>) \\<Rrightarrow>\\<^sub>m (\\<le>\\<^bsub>L1\\<^esub>)) r1\"\n  and \"((\\<le>\\<^bsub>L1\\<^esub>) \\<unlhd> (\\<le>\\<^bsub>R1\\<^esub>)) l1 r1\"\n  and \"rel_equivalence_on (in_codom (\\<le>\\<^bsub>R1\\<^esub>)) (\\<le>\\<^bsub>R1\\<^esub>) \\<epsilon>\\<^sub>1\"\n  and \"transitive (\\<le>\\<^bsub>R1\\<^esub>)\"\n  and \"((\\<le>\\<^bsub>L2\\<^esub>) \\<Rrightarrow>\\<^sub>m (\\<le>\\<^bsub>R2\\<^esub>)) l2\"\n  and \"((\\<le>\\<^bsub>R2\\<^esub>) \\<^sub>h\\<unlhd> (\\<le>\\<^bsub>L2\\<^esub>)) r2 l2\"\n  and \"inflationary_on (in_dom (\\<le>\\<^bsub>L2\\<^esub>)) (\\<le>\\<^bsub>L2\\<^esub>) \\<eta>\\<^sub>2\"\n  and \"preorder_on (in_field (\\<le>\\<^bsub>L2\\<^esub>)) (\\<le>\\<^bsub>L2\\<^esub>)\"\n  and \"middle_compatible_codom\"\n  shows \"((\\<le>\\<^bsub>L\\<^esub>) \\<unlhd> (\\<le>\\<^bsub>R\\<^esub>)) l r\"\n  using assms by (intro galois_propI\n    half_galois_prop_left_left_rightI half_galois_prop_right_left_rightI\n    flip.mono_in_codom_left_rel_left1_if_in_codom_rel_comp_le\n    mono_in_dom_left_rel_left1_if_in_dom_rel_comp_le\n    in_dom_right1_left2_right1_le_if_right1_left2_right1_le)\n  (auto elim!: preorder_on_in_fieldE\n    intro: reflexive_on_if_le_pred_if_reflexive_on in_field_if_in_codom)\n\nlemma galois_prop_left_rightI':\n  assumes \"((\\<le>\\<^bsub>R1\\<^esub>) \\<Rrightarrow>\\<^sub>m (\\<le>\\<^bsub>L1\\<^esub>)) r1\"\n  and \"((\\<le>\\<^bsub>L1\\<^esub>) \\<^sub>h\\<unlhd> (\\<le>\\<^bsub>R1\\<^esub>)) l1 r1\"\n  and \"inflationary_on (in_dom (\\<le>\\<^bsub>L1\\<^esub>)) (\\<le>\\<^bsub>L1\\<^esub>) \\<eta>\\<^sub>1\"\n  and rel_equiv_counit1: \"rel_equivalence_on (in_field (\\<le>\\<^bsub>R1\\<^esub>)) (\\<le>\\<^bsub>R1\\<^esub>) \\<epsilon>\\<^sub>1\"\n  and trans_R1: \"transitive (\\<le>\\<^bsub>R1\\<^esub>)\"\n  and \"((\\<le>\\<^bsub>L2\\<^esub>) \\<Rrightarrow>\\<^sub>m (\\<le>\\<^bsub>R2\\<^esub>)) l2\"\n  and \"((\\<le>\\<^bsub>R2\\<^esub>) \\<^sub>h\\<unlhd> (\\<le>\\<^bsub>L2\\<^esub>)) r2 l2\"\n  and \"inflationary_on (in_dom (\\<le>\\<^bsub>L2\\<^esub>)) (\\<le>\\<^bsub>L2\\<^esub>) \\<eta>\\<^sub>2\"\n  and \"preorder_on (in_field (\\<le>\\<^bsub>L2\\<^esub>)) (\\<le>\\<^bsub>L2\\<^esub>)\"\n  and \"middle_compatible_dom\"\n  shows \"((\\<le>\\<^bsub>L\\<^esub>) \\<unlhd> (\\<le>\\<^bsub>R\\<^esub>)) l r\"\nproof (rule galois_propI)\n  show \"((\\<le>\\<^bsub>L\\<^esub>) \\<^sub>h\\<unlhd> (\\<le>\\<^bsub>R\\<^esub>)) l r\" using assms\n    by (intro half_galois_prop_left_left_rightI'\n      flip.mono_in_codom_left_rel_left1_if_in_codom_rel_comp_le\n      flip.in_codom_right1_left2_right1_le_if_right1_left2_right1_le)\n    (auto elim!: rel_equivalence_onE preorder_on_in_fieldE\n      intro: deflationary_on_if_le_pred_if_deflationary_on\n        reflexive_on_if_le_pred_if_reflexive_on\n        in_field_if_in_dom in_field_if_in_codom)\n  have \"y \\<le>\\<^bsub>R1\\<^esub> l1 (r1 (r2 z))\" if \"y \\<le>\\<^bsub>R1\\<^esub> r2 z\" for y z\n  proof -\n    note \\<open>y \\<le>\\<^bsub>R1\\<^esub> r2 z\\<close>\n    moreover with rel_equiv_counit1 have \"r2 z \\<le>\\<^bsub>R1\\<^esub> \\<epsilon>\\<^sub>1 (r2 z)\" by auto\n    ultimately show ?thesis using trans_R1 by auto\n  qed\n  moreover have \"in_dom (\\<le>\\<^bsub>R1\\<^esub>) \\<le> in_codom (\\<le>\\<^bsub>R1\\<^esub>)\"\n  proof -\n    from rel_equiv_counit1 trans_R1 have \"reflexive_on (in_field (\\<le>\\<^bsub>R1\\<^esub>)) (\\<le>\\<^bsub>R1\\<^esub>)\"\n      by (intro reflexive_on_in_field_if_transitive_if_rel_equivalence_on) auto\n    then show ?thesis by (simp only: in_codom_eq_in_dom_if_reflexive_on_in_field)\n  qed\n  ultimately show \"((\\<le>\\<^bsub>L\\<^esub>) \\<unlhd>\\<^sub>h (\\<le>\\<^bsub>R\\<^esub>)) l r\" using assms\n    by (intro half_galois_prop_right_left_rightI'\n      mono_in_dom_left_rel_left1_if_in_dom_rel_comp_le)\n    auto\nqed\n\nend\n\n\nend", "meta": {"author": "kappelmann", "repo": "transport-isabelle", "sha": "b6d2cb56ea4abf6e496d1c258d5b3d2a816d75ff", "save_path": "github-repos/isabelle/kappelmann-transport-isabelle", "path": "github-repos/isabelle/kappelmann-transport-isabelle/transport-isabelle-b6d2cb56ea4abf6e496d1c258d5b3d2a816d75ff/Transport/Compositions/Generic/Transport_Compositions_Generic_Galois_Property.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6261241632752915, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.2886537452027935}}
{"text": "(*  Title:      HOL/HOLCF/IOA/Storage/Impl.thy\n    Author:     Olaf Müller\n*)\n\nsection \\<open>The implementation of a memory\\<close>\n\ntheory Impl\nimports IOA.IOA Action\nbegin\n\ndefinition\n  impl_sig :: \"action signature\" where\n  \"impl_sig = (\\<Union>l.{Free l} \\<union> {New},\n               \\<Union>l.{Loc l},\n               {})\"\n\ndefinition\n  impl_trans :: \"(action, nat  * bool)transition set\" where\n  \"impl_trans =\n    {tr. let s = fst(tr); k = fst s; b = snd s;\n             t = snd(snd(tr)); k' = fst t; b' = snd t\n         in\n         case fst(snd(tr))\n         of\n         New       \\<Rightarrow> k' = k \\<and> b'  |\n         Loc l     \\<Rightarrow> b \\<and> l= k \\<and> k'= (Suc k) \\<and> \\<not>b' |\n         Free l    \\<Rightarrow> k'=k \\<and> b'=b}\"\n\ndefinition\n  impl_ioa :: \"(action, nat * bool)ioa\" where\n  \"impl_ioa = (impl_sig, {(0,False)}, impl_trans,{},{})\"\n\nlemma in_impl_asig:\n  \"New \\<in> actions(impl_sig) \\<and>\n    Loc l \\<in> actions(impl_sig) \\<and>\n    Free l \\<in> actions(impl_sig) \"\n  by (simp add: impl_sig_def actions_def asig_projections)\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/HOLCF/IOA/Storage/Impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982315512489, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.2886132449024854}}
{"text": "(*  Title:      JinjaDCI/Common/Type.thy\n\n    Author:     David von Oheimb, Tobias Nipkow, Susannah Mansky\n    Copyright   1999 Technische Universitaet Muenchen, 2019-20 UIUC\n\n    Based on the Jinja theory Common/Type.thy by David von Oheimb and Tobias Nipkow\n*)\n\nsection \\<open> Jinja types \\<close>        \n\ntheory Type imports Auxiliary begin\n\ntype_synonym cname = string \\<comment> \\<open>class names\\<close>\ntype_synonym mname = string \\<comment> \\<open>method name\\<close>\ntype_synonym vname = string \\<comment> \\<open>names for local/field variables\\<close>\n\ndefinition Object :: cname\nwhere\n  \"Object \\<equiv> ''Object''\"\n\ndefinition this :: vname\nwhere\n  \"this \\<equiv> ''this''\"\n\ndefinition clinit :: \"string\" where \"clinit = ''<clinit>''\"\ndefinition init :: \"string\" where \"init = ''<init>''\"\n\ndefinition start_m :: \"string\" where \"start_m = ''<start>''\"\ndefinition Start :: \"string\" where \"Start = ''<Start>''\"\n\nlemma start_m_neq_clinit [simp]: \"start_m \\<noteq> clinit\" by(simp add: start_m_def clinit_def)\nlemma Object_neq_Start [simp]: \"Object \\<noteq> Start\" by(simp add: Object_def Start_def)\nlemma Start_neq_Object [simp]: \"Start \\<noteq> Object\" by(simp add: Object_def Start_def)\n\n\\<comment> \\<open>field/method static flag\\<close>\n\ndatatype staticb = Static | NonStatic\n\n\\<comment> \\<open>types\\<close>\ndatatype ty\n  = Void          \\<comment> \\<open>type of statements\\<close>\n  | Boolean\n  | Integer\n  | NT            \\<comment> \\<open>null type\\<close>\n  | Class cname   \\<comment> \\<open>class type\\<close>\n\ndefinition is_refT :: \"ty \\<Rightarrow> bool\"\nwhere\n  \"is_refT T  \\<equiv>  T = NT \\<or> (\\<exists>C. T = Class C)\"\n\n\n\nlemma [iff]: \"is_refT(Class C)\"\n(*<*)by(simp add:is_refT_def)(*>*)\n\nlemma refTE:\n  \"\\<lbrakk>is_refT T; T = NT \\<Longrightarrow> P; \\<And>C. T = Class C \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P\"\n(*<*)by (auto simp add: is_refT_def)(*>*)\n\nlemma not_refTE:\n  \"\\<lbrakk> \\<not>is_refT T; T = Void \\<or> T = Boolean \\<or> T = Integer \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P\"\n(*<*)by (cases T, auto simp add: is_refT_def)(*>*)\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/JinjaDCI/Common/Type.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.44552953503957266, "lm_q1q2_score": 0.28861323884366746}}
{"text": "(*  Title:      HOL/Auth/n_mutualExOnI_on_inis.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mutualExOnI Protocol Case Study*} \n\ntheory n_mutualExOnI_on_inis imports n_mutualExOnI_on_ini\nbegin\nlemma on_inis:\n  assumes b1: \"f \\<in> (invariants N)\" and b2: \"ini \\<in> {andList (allInitSpecs N)}\" and b3: \"formEval ini s\"\n  shows \"formEval f s\"\n  proof -\n  have c1: \"(\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__1  p__Inv0 p__Inv1)\\<or>\n    (\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__2  p__Inv0 p__Inv1)\\<or>\n    (\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__3  p__Inv0 p__Inv1)\\<or>\n    (\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__4  p__Inv0 p__Inv1)\"\n  apply (cut_tac b1, simp) done\n    moreover {\n      assume d1: \"(\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__1  p__Inv0 p__Inv1)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__1)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__2  p__Inv0 p__Inv1)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__2)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__3  p__Inv0 p__Inv1)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__3)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__4  p__Inv0 p__Inv1)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__4)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n  ultimately show \"formEval f s\"\n  by satx\nqed\n\nend\n", "meta": {"author": "lyj238Gmail", "repo": "newParaVerifier", "sha": "5c2d49bf8e6c46c60efa53c98b0ba5c577d59618", "save_path": "github-repos/isabelle/lyj238Gmail-newParaVerifier", "path": "github-repos/isabelle/lyj238Gmail-newParaVerifier/newParaVerifier-5c2d49bf8e6c46c60efa53c98b0ba5c577d59618/examples/n_mutualExOnI/n_mutualExOnI_on_inis.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982043529715, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.2886132327848495}}
{"text": "(*\n * Copyright 2014, General Dynamics C4 Systems\n *\n * This software may be distributed and modified according to the terms of\n * the GNU General Public License version 2. Note that NO WARRANTY is provided.\n * See \"LICENSE_GPLv2.txt\" for details.\n *\n * @TAG(GD_GPL)\n *)\n\ntheory ArchVSpaceEntries_AI\nimports \"../VSpaceEntries_AI\"\nbegin\n\n\ncontext Arch begin global_naming ARM (*FIXME: arch_split*)\n\nlemma a_type_pdD:\n  \"a_type ko = AArch APageDirectory \\<Longrightarrow> \\<exists>pd. ko = ArchObj (PageDirectory pd)\"\n  by (clarsimp)\n\nprimrec\n  pde_range_sz :: \"pde \\<Rightarrow> nat\"\nwhere\n    \"pde_range_sz (InvalidPDE) = 0\"\n  | \"pde_range_sz (SectionPDE ptr x y z) = 0\"\n  | \"pde_range_sz (SuperSectionPDE ptr x z) = 4\"\n  | \"pde_range_sz (PageTablePDE ptr x z) = 0\"\n\nprimrec\n  pte_range_sz :: \"pte \\<Rightarrow> nat\"\nwhere\n    \"pte_range_sz (InvalidPTE) = 0\"\n  | \"pte_range_sz (LargePagePTE ptr x y) = 4\"\n  | \"pte_range_sz (SmallPagePTE ptr x y) = 0\"\n\nprimrec\n  pde_range :: \"pde \\<Rightarrow> 12 word \\<Rightarrow> 12 word set\"\nwhere\n    \"pde_range (InvalidPDE) p = {}\"\n  | \"pde_range (SectionPDE ptr x y z) p = {p}\"\n  | \"pde_range (SuperSectionPDE ptr x z) p =\n     (if is_aligned p 4 then {x. x && ~~ mask 4 = p && ~~ mask 4} else {p})\"\n  | \"pde_range (PageTablePDE ptr x z) p = {p}\"\n\nprimrec\n  pte_range :: \"pte \\<Rightarrow> word8 \\<Rightarrow> word8 set\"\nwhere\n    \"pte_range (InvalidPTE) p = {}\"\n  | \"pte_range (LargePagePTE ptr x y) p =\n       (if is_aligned p 4 then {x. x && ~~ mask 4 = p && ~~ mask 4} else {p})\"\n  | \"pte_range (SmallPagePTE ptr x y) p = {p}\"\n\nabbreviation \"valid_pt_entries \\<equiv> \\<lambda>pt. valid_entries pte_range pt\"\n\nabbreviation \"valid_pd_entries \\<equiv> \\<lambda>pd. valid_entries pde_range pd\"\n\ndefinition\n  obj_valid_pdpt :: \"kernel_object \\<Rightarrow> bool\"\nwhere\n \"obj_valid_pdpt obj \\<equiv> case obj of\n    ArchObj (PageTable pt) \\<Rightarrow> valid_pt_entries pt \\<and> entries_align pte_range_sz pt\n  | ArchObj (PageDirectory pd) \\<Rightarrow> valid_pd_entries pd \\<and> entries_align pde_range_sz pd\n  | _ \\<Rightarrow> True\"\n\nlemmas obj_valid_pdpt_simps[simp]\n    = obj_valid_pdpt_def\n        [split_simps Structures_A.kernel_object.split\n                     arch_kernel_obj.split]\n\nabbreviation\n  valid_pdpt_objs :: \"'z state \\<Rightarrow> bool\"\nwhere\n \"valid_pdpt_objs s \\<equiv> \\<forall>x \\<in> ran (kheap s). obj_valid_pdpt x\"\n\nlemma valid_pdpt_init[iff]:\n  \"valid_pdpt_objs init_A_st\"\nproof -\n  have P: \"valid_pd_entries (global_pd :: 12 word \\<Rightarrow> _)\"\n    by (clarsimp simp: valid_entries_def)\n  also have Q: \"entries_align pde_range_sz (global_pd :: 12 word \\<Rightarrow> _)\"\n    by (clarsimp simp: entries_align_def)\n  thus ?thesis using P\n    by (auto simp: init_A_st_def init_kheap_def\n            elim!: ranE split: if_split_asm)\nqed\n\nlemma set_object_valid_pdpt[wp]:\n  \"\\<lbrace>valid_pdpt_objs and K (obj_valid_pdpt obj)\\<rbrace>\n      set_object ptr obj\n   \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (simp add: set_object_def, wp)\n  apply (auto simp: fun_upd_def[symmetric] del: ballI elim: ball_ran_updI)\n  done\n\ncrunch valid_pdpt_objs[wp]: cap_insert, cap_swap_for_delete,empty_slot \"valid_pdpt_objs\"\n  (wp: crunch_wps simp: crunch_simps ignore:set_object)\n\ncrunch valid_pdpt_objs[wp]: flush_page \"valid_pdpt_objs\"\n  (wp: crunch_wps simp: crunch_simps)\n\nlemma shift_0x3C_set:\n  \"\\<lbrakk> is_aligned p 6; 8 \\<le> bits; bits < 32; len_of TYPE('a) = bits - 2 \\<rbrakk> \\<Longrightarrow>\n   (\\<lambda>x. ucast (x + p && mask bits >> 2) :: ('a :: len) word) ` set [0 :: word32 , 4 .e. 0x3C]\n        = {x. x && ~~ mask 4 = ucast (p && mask bits >> 2)}\"\n  apply (clarsimp simp: upto_enum_step_def word_shift_by_2 image_image)\n  apply (subst image_cong[where N=\"{x. x < 2 ^ 4}\"])\n    apply (safe, simp_all)[1]\n     apply (drule plus_one_helper2, simp_all)[1]\n    apply (drule minus_one_helper3, simp_all)[1]\n   apply (rule_tac f=\"\\<lambda>x. ucast (x && mask bits >> 2)\" in arg_cong)\n   apply (rule trans[OF add.commute is_aligned_add_or], assumption)\n   apply (rule shiftl_less_t2n, simp_all)[1]\n  apply safe\n   apply (frule upper_bits_unset_is_l2p_32[THEN iffD2, rotated])\n    apply (simp add: word_bits_conv)\n   apply (rule word_eqI)\n   apply (simp add: word_ops_nth_size word_size nth_ucast nth_shiftr\n                    nth_shiftl neg_mask_bang\n                    word_bits_conv)\n   apply (safe, simp_all add: is_aligned_nth)[1]\n   apply (drule_tac x=\"Suc (Suc n)\" in spec)\n   apply simp\n  apply (rule_tac x=\"ucast x && mask 4\" in image_eqI)\n   apply (rule word_eqI)\n   apply (drule_tac x=n in word_eqD)\n   apply (simp add: word_ops_nth_size word_size nth_ucast nth_shiftr\n                    nth_shiftl)\n   apply (safe, simp_all)\n  apply (rule order_less_le_trans, rule and_mask_less_size)\n   apply (simp_all add: word_size)\n  done\n\nlemma mapM_x_store_pte_updates:\n  \"\\<forall>x \\<in> set xs. f x && ~~ mask pt_bits = p \\<Longrightarrow>\n   \\<lbrace>\\<lambda>s. (\\<not> page_table_at p s \\<longrightarrow> Q s) \\<and>\n        (\\<forall>pt. ko_at (ArchObj (PageTable pt)) p s\n           \\<longrightarrow> Q (s \\<lparr> kheap := (kheap s) (p := Some (ArchObj (PageTable (\\<lambda>y. if y \\<in> (\\<lambda>x.\n         ucast (f x && mask pt_bits >> 2)) ` set xs then pte else pt y)))) \\<rparr>))\\<rbrace>\n     mapM_x (\\<lambda>x. store_pte (f x) pte) xs\n   \\<lbrace>\\<lambda>_. Q\\<rbrace>\"\n  apply (induct xs)\n   apply (simp add: mapM_x_Nil)\n   apply wp\n   apply (clarsimp simp: obj_at_def)\n   apply (simp add: a_type_def fun_upd_idem\n             split: Structures_A.kernel_object.split_asm if_split_asm\n                    arch_kernel_obj.split_asm)\n  apply (simp add: mapM_x_Cons)\n  apply (rule hoare_seq_ext, assumption)\n  apply (thin_tac \"valid P f Q\" for P f Q)\n  apply (simp add: store_pte_def set_pt_def set_object_def)\n  apply (wp get_pt_wp get_object_wp)\n  apply (clarsimp simp: obj_at_def a_type_simps)\n  apply (erule rsubst[where P=Q])\n  apply (rule abstract_state.fold_congs[OF refl refl])\n  apply (rule ext, clarsimp)\n  apply (rule ext, clarsimp)\n  done\n\nlemma valid_pt_entries_invalid[simp]:\n  \"valid_pt_entries (\\<lambda>x. InvalidPTE)\"\n   by (simp add:valid_entries_def)\n\nlemma valid_pd_entries_invalid[simp]:\n  \"valid_pd_entries (\\<lambda>x. InvalidPDE)\"\n  by (simp add:valid_entries_def)\n\nlemma entries_align_pte_update:\n \"\\<lbrakk>entries_align pte_range_sz pt;\n  (\\<forall>y. (P y) \\<longrightarrow> is_aligned y (pte_range_sz pte))\\<rbrakk>\n  \\<Longrightarrow> entries_align pte_range_sz (\\<lambda>y. if (P y) then pte else pt y)\"\n  by (simp add:entries_align_def)\n\nlemma entries_align_pde_update:\n \"\\<lbrakk>entries_align pde_range_sz pd;\n  (\\<forall>y. (P y) \\<longrightarrow> is_aligned y (pde_range_sz pde))\\<rbrakk>\n  \\<Longrightarrow> entries_align pde_range_sz (\\<lambda>y. if (P y) then pde else pd y)\"\n  by (simp add:entries_align_def)\n\n\nlemma valid_pdpt_objs_pdD:\n  \"\\<lbrakk>valid_pdpt_objs s;\n    kheap s ptr = Some (ArchObj (arch_kernel_obj.PageDirectory pd))\\<rbrakk>\n   \\<Longrightarrow> valid_pd_entries pd \\<and> entries_align pde_range_sz pd\"\n  by (fastforce simp:ran_def)\n\nlemma valid_pdpt_objs_ptD:\n  \"\\<lbrakk>valid_pdpt_objs s;\n    kheap s ptr = Some (ArchObj (arch_kernel_obj.PageTable pt))\\<rbrakk>\n   \\<Longrightarrow> valid_pt_entries pt \\<and> entries_align pte_range_sz pt\"\n  by (fastforce simp:ran_def)\n\nlemma mapM_x_store_invalid_pte_valid_pdpt:\n  \"\\<lbrace>valid_pdpt_objs and K (is_aligned p 6) \\<rbrace>\n     mapM_x (\\<lambda>x. store_pte (x + p) InvalidPTE) [0, 4 .e. 0x3C]\n   \\<lbrace>\\<lambda>_. valid_pdpt_objs\\<rbrace>\"\n  apply (rule hoare_gen_asm)+\n  apply (rule hoare_pre, rule_tac p=\"p && ~~ mask pt_bits\" in mapM_x_store_pte_updates)\n   apply clarsimp\n   apply (rule mask_out_first_mask_some[where n=6])\n    apply (drule_tac d=x in is_aligned_add_helper)\n     apply (drule subsetD[OF upto_enum_step_subset])\n     apply simp\n     apply (erule order_le_less_trans, simp)\n    apply (simp add: field_simps)\n   apply (simp add: pt_bits_def pageBits_def)\n  apply (clarsimp simp: ranI elim!: ranE split: if_split_asm)\n  apply (intro conjI)\n   apply (simp add: shift_0x3C_set pt_bits_def pageBits_def)\n   apply (rule valid_entries_overwrite_groups\n    [where S = \"{x. x && ~~ mask 4 = ucast (p && mask 10 >> 2)}\"])\n      apply (fastforce simp add: obj_at_def ran_def)\n     apply simp\n    apply clarsimp\n    apply (case_tac v)\n      apply (simp split:if_splits)+\n   apply (clarsimp)\n   apply (case_tac v, simp_all split:if_splits)\n    apply (intro conjI impI)\n     apply (rule disjointI)\n     apply (clarsimp)+\n  apply (rule entries_align_pte_update)\n   apply (clarsimp simp:obj_at_def)\n   apply (drule(1) valid_pdpt_objs_ptD)\n   apply simp\n  apply (simp)\n  done\n\nlemma mapM_x_store_pde_updates:\n  \"\\<forall>x \\<in> set xs. f x && ~~ mask pd_bits = p \\<Longrightarrow>\n   \\<lbrace>\\<lambda>s. (\\<not> page_directory_at p s \\<longrightarrow> Q s) \\<and>\n        (\\<forall>pd. ko_at (ArchObj (PageDirectory pd)) p s\n           \\<longrightarrow> Q (s \\<lparr> kheap := (kheap s) (p := Some (ArchObj (PageDirectory (\\<lambda>y. if y \\<in> (\\<lambda>x.\n         ucast (f x && mask pd_bits >> 2)) ` set xs then pde else pd y)))) \\<rparr>))\\<rbrace>\n     mapM_x (\\<lambda>x. store_pde (f x) pde) xs\n   \\<lbrace>\\<lambda>_. Q\\<rbrace>\"\n  apply (induct xs)\n   apply (simp add: mapM_x_Nil)\n   apply wp\n   apply (clarsimp simp: obj_at_def)\n   apply (simp add: a_type_def fun_upd_idem\n             split: Structures_A.kernel_object.split_asm if_split_asm\n                    arch_kernel_obj.split_asm)\n  apply (simp add: mapM_x_Cons)\n  apply (rule hoare_seq_ext, assumption)\n  apply (thin_tac \"valid P f Q\" for P f Q)\n  apply (simp add: store_pde_def set_pd_def set_object_def)\n  apply (wp get_pd_wp get_object_wp)\n  apply (clarsimp simp: obj_at_def a_type_simps)\n  apply (erule rsubst[where P=Q])\n  apply (rule abstract_state.fold_congs[OF refl refl])\n  apply (rule ext, clarsimp)\n  apply (rule ext, clarsimp)\n  done\n\nlemma mapM_x_store_pde_valid_pdpt_objs:\n  \"\\<lbrace>valid_pdpt_objs and K (is_aligned p 6)\\<rbrace>\n     mapM_x (\\<lambda>x. store_pde (x + p) InvalidPDE) [0, 4 .e. 0x3C]\n   \\<lbrace>\\<lambda>_. valid_pdpt_objs\\<rbrace>\"\n  apply (rule hoare_gen_asm)+\n  apply (rule hoare_pre, rule_tac p=\"p && ~~ mask pd_bits\" in mapM_x_store_pde_updates)\n   apply clarsimp\n   apply (rule mask_out_first_mask_some[where n=6])\n    apply (drule_tac d=x in is_aligned_add_helper)\n     apply (drule subsetD[OF upto_enum_step_subset])\n     apply simp\n     apply (erule order_le_less_trans, simp)\n    apply (simp add: field_simps)\n   apply (simp add: pd_bits_def pageBits_def)\n  apply (clarsimp simp: ranI elim!: ranE split: if_split_asm)\n  apply (simp add: shift_0x3C_set pd_bits_def pageBits_def)\n  apply (rule conjI)\n   apply (rule_tac valid_entries_overwrite_groups\n    [where S = \"{x. x && ~~ mask 4 = ucast (p && mask 14 >> 2)}\"])\n      apply (fastforce simp add: obj_at_def ran_def)\n     apply fastforce\n    apply clarsimp\n    apply (case_tac v, simp_all split:if_splits)\n    apply clarsimp\n    apply (case_tac v, simp_all split:if_splits)\n   apply (intro conjI impI allI)\n   apply (rule disjointI)\n   apply clarsimp\n  apply (rule entries_align_pde_update)\n   apply (clarsimp simp:obj_at_def)\n   apply (drule valid_pdpt_objs_pdD)\n    apply (simp add:pd_bits_def pageBits_def)\n   apply simp\n  apply simp\n  done\n\nlemma store_invalid_pde_valid_pdpt:\n  \"\\<lbrace>valid_pdpt_objs and\n    (\\<lambda>s. \\<forall>pd. ko_at (ArchObj (PageDirectory pd)) (p && ~~ mask pd_bits) s\n      \\<longrightarrow> pde = InvalidPDE)\\<rbrace>\n       store_pde p pde \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (simp add: store_pde_def set_pd_def, wp get_object_wp)\n  apply (clarsimp simp: obj_at_def)\n   apply (intro conjI)\n   apply (rule valid_entries_overwrite_0, simp_all)\n   apply (fastforce simp: ran_def)\n  apply (simp add:fun_upd_def)\n  apply (rule entries_align_pde_update)\n   apply (drule(1) valid_pdpt_objs_pdD)\n   apply simp\n  apply simp\n  done\n\nlemma store_pde_non_master_valid_pdpt:\n  \"\\<lbrace>valid_pdpt_objs and\n        (\\<lambda>s. \\<forall>pd. ko_at (ArchObj (PageDirectory pd)) (p && ~~ mask pd_bits) s\n        \\<longrightarrow> (pde_range_sz (pd (ucast (p && mask pd_bits >> 2) && ~~ mask 4)) = 0\n        \\<and> pde_range_sz pde = 0))\\<rbrace>\n       store_pde p pde \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (simp add: store_pde_def set_pd_def, wp get_object_wp)\n  apply (clarsimp simp: obj_at_def)\n  apply (intro conjI)\n   apply (rule valid_entries_overwrite_0)\n    apply (fastforce simp:ran_def)\n   apply (drule bspec)\n    apply fastforce\n   apply (case_tac \"pd pa\")\n    apply simp_all\n     apply (case_tac pde,simp_all)\n    apply (case_tac pde,simp_all)\n   apply (case_tac pde,simp_all)\n    apply (clarsimp simp: is_aligned_neg_mask_eq)+\n  apply (simp add:fun_upd_def)\n  apply (rule entries_align_pde_update)\n   apply (drule(1) valid_pdpt_objs_pdD,simp)\n  apply simp\n  done\n\nlemma store_invalid_pte_valid_pdpt:\n  \"\\<lbrace>valid_pdpt_objs and\n        (\\<lambda>s. \\<forall>pt. ko_at (ArchObj (PageTable pt)) (p && ~~ mask pt_bits) s\n        \\<longrightarrow> pte = InvalidPTE)\\<rbrace>\n       store_pte p pte \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (simp add: store_pte_def set_pt_def, wp get_object_wp)\n  apply (clarsimp simp: obj_at_def)\n   apply (intro conjI)\n   apply (rule valid_entries_overwrite_0, simp_all)\n   apply (fastforce simp: ran_def)\n  apply (simp add:fun_upd_def)\n  apply (rule entries_align_pte_update)\n   apply (drule (1) valid_pdpt_objs_ptD,simp)\n  apply simp\n  done\n\nlemma store_pte_non_master_valid_pdpt:\n  \"\\<lbrace>valid_pdpt_objs and\n        (\\<lambda>s. \\<forall>pt. ko_at (ArchObj (PageTable pt)) (p && ~~ mask pt_bits) s\n        \\<longrightarrow> (pte_range_sz (pt (ucast (p && mask pt_bits >> 2) && ~~ mask 4)) = 0\n        \\<and> pte_range_sz pte = 0))\\<rbrace>\n       store_pte p pte \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (simp add: store_pte_def set_pt_def, wp get_object_wp)\n  apply (clarsimp simp: obj_at_def)\n  apply (intro conjI)\n   apply (rule valid_entries_overwrite_0)\n    apply (fastforce simp:ran_def)\n   apply (drule bspec)\n    apply fastforce\n   apply (case_tac \"pt pa\")\n     apply simp\n    apply (case_tac pte,simp_all)\n    apply (clarsimp simp: is_aligned_neg_mask_eq)\n   apply (case_tac pte,simp_all)\n  apply (simp add:fun_upd_def)\n  apply (rule entries_align_pte_update)\n   apply (drule (1) valid_pdpt_objs_ptD,simp)\n  apply simp\n  done\n\nlemma unmap_page_valid_pdpt[wp]:\n  \"\\<lbrace>valid_pdpt_objs\\<rbrace> unmap_page sz asid vptr pptr \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (simp add: unmap_page_def mapM_discarded\n             cong: vmpage_size.case_cong)\n  apply (wp)\n    prefer 2\n    apply (rule valid_validE[OF find_pd_for_asid_inv])\n   apply (rule hoare_pre)\n    apply (wp get_object_wp get_pte_wp get_pde_wp lookup_pt_slot_inv_any\n              store_invalid_pte_valid_pdpt\n              store_invalid_pde_valid_pdpt\n              mapM_x_store_invalid_pte_valid_pdpt mapM_x_store_pde_valid_pdpt_objs\n                 | simp add: mapM_x_map\n                 | wpc | simp add: check_mapping_pptr_def)+\n   apply (simp add: fun_upd_def[symmetric] is_aligned_mask[symmetric])\n  apply assumption\n  done\n\ncrunch valid_pdpt_objs[wp]: flush_table \"valid_pdpt_objs\"\n  (wp: crunch_wps simp: crunch_simps)\n\ncrunch kheap[wp]: flush_table \"\\<lambda>s. P (kheap s)\"\n  (wp: crunch_wps simp: crunch_simps)\n\nlemma unmap_page_table_valid_pdpt_objs[wp]:\n  notes hoare_pre [wp_pre del]\n  shows \"\\<lbrace>valid_pdpt_objs\\<rbrace> unmap_page_table asid vptr pt \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (simp add: unmap_page_table_def)\n  apply (wp get_object_wp store_invalid_pde_valid_pdpt | wpc)+\n  apply (simp add: obj_at_def)\n  apply (simp add: page_table_mapped_def)\n  apply (wp get_pde_wp | wpc)+\n  apply simp\n  apply (rule hoare_post_impErr, rule valid_validE,\n         rule find_pd_for_asid_inv, simp_all)\n  done\n\ncrunch valid_pdpt_objs[wp]: finalise_cap, cap_swap_for_delete, empty_slot \"valid_pdpt_objs\"\n  (wp: crunch_wps select_wp preemption_point_inv simp: crunch_simps unless_def ignore:set_object)\n\nlemma preemption_point_valid_pdpt_objs[wp]:\n  \"\\<lbrace>valid_pdpt_objs\\<rbrace> preemption_point \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  by (wp preemption_point_inv | simp)+\n\nlemmas cap_revoke_preservation_valid_pdpt_objs = cap_revoke_preservation[OF _,\n                                                          where E=valid_pdpt_objs,\n                                                          simplified, THEN validE_valid]\n\nlemmas rec_del_preservation_valid_pdpt_objs = rec_del_preservation[OF _ _ _ _,\n                                                    where P=valid_pdpt_objs, simplified]\n\ncrunch valid_pdpt_objs[wp]: cap_delete, cap_revoke \"valid_pdpt_objs\"\n  (wp: rec_del_preservation_valid_pdpt_objs cap_revoke_preservation_valid_pdpt_objs)\n\ncrunch valid_pdpt_objs[wp]: invalidate_tlb_by_asid, page_table_mapped\n   \"valid_pdpt_objs\"\n\nlemma mapM_x_copy_pde_updates:\n  \"\\<lbrakk> \\<forall>x \\<in> set xs. f x && ~~ mask pd_bits = 0; is_aligned p pd_bits;\n               is_aligned p' pd_bits \\<rbrakk> \\<Longrightarrow>\n   \\<lbrace>\\<lambda>s. (\\<not> page_directory_at p s \\<longrightarrow> Q s) \\<and> (\\<not> page_directory_at p' s \\<longrightarrow> Q s) \\<and>\n        (\\<forall>pd pd'. ko_at (ArchObj (PageDirectory pd)) p s\n                \\<and> ko_at (ArchObj (PageDirectory pd')) p' s\n           \\<longrightarrow> Q (s \\<lparr> kheap := (kheap s) (p' := Some (ArchObj (PageDirectory (\\<lambda>y. if y \\<in> (\\<lambda>x.\n         ucast (f x && mask pd_bits >> 2)) ` set xs then pd y else pd' y)))) \\<rparr>))\\<rbrace>\n     mapM_x (\\<lambda>x. get_pde (p + f x) >>= store_pde (p' + f x)) xs\n   \\<lbrace>\\<lambda>_. Q\\<rbrace>\"\n  apply (induct xs)\n   apply (simp add: mapM_x_Nil)\n   apply wp\n   apply (clarsimp simp: obj_at_def fun_upd_idem dest!: a_type_pdD)\n  apply (simp add: mapM_x_Cons)\n  apply wp\n   apply (thin_tac \"valid P f Q\" for P f Q)\n   apply (simp add: store_pde_def set_pd_def set_object_def\n              cong: bind_cong split del: if_split)\n   apply (wp get_object_wp get_pde_wp)\n  apply (clarsimp simp: obj_at_def a_type_simps mask_out_add_aligned[symmetric]\n             split del: if_split)\n  apply (simp add: a_type_simps, safe)\n   apply (erule rsubst[where P=Q])\n   apply (rule abstract_state.fold_congs[OF refl refl])\n   apply (rule ext, clarsimp)\n   apply (rule ext, simp)\n  apply (erule rsubst[where P=Q])\n  apply (rule abstract_state.fold_congs[OF refl refl])\n  apply (rule ext, clarsimp)\n  apply (rule ext, simp add: mask_add_aligned)\n  done\n\nlemma copy_global_mappings_valid_pdpt_objs[wp]:\n  notes hoare_pre [wp_pre del]\n  shows\n  \"\\<lbrace>valid_pdpt_objs and valid_arch_state and pspace_aligned\n            and K (is_aligned p pd_bits)\\<rbrace>\n       copy_global_mappings p \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (rule hoare_gen_asm)\n  apply (simp add: copy_global_mappings_def)\n  apply wp\n   apply (rule_tac P=\"is_aligned global_pd pd_bits\" in hoare_gen_asm)\n   apply (rule mapM_x_copy_pde_updates, simp_all)\n   apply (clarsimp simp: mask_eq_x_eq_0[symmetric])\n   apply (rule less_mask_eq, rule shiftl_less_t2n,\n          simp_all add: pd_bits_def pageBits_def)[1]\n   apply (drule plus_one_helper2, simp+)\n  apply wp\n  apply (clarsimp simp: invs_aligned_pdD ranI\n                 elim!: ranE split: if_split_asm)\n  apply (intro conjI)\n   apply (rule_tac S=\"{x. ucast x \\<ge> (kernel_base >> 20)}\"\n                 in valid_entries_partial_copy)\n      apply (fastforce simp: obj_at_def ran_def)\n     apply (fastforce simp: obj_at_def ran_def)\n    apply (clarsimp simp:image_def)\n    apply (subst (asm) less_mask_eq)\n     apply (rule shiftl_less_t2n)\n      apply (simp add:pd_bits_def pageBits_def word_le_make_less)\n     apply (simp add:pd_bits_def pageBits_def)\n    apply (subst (asm) shiftl_shiftr1)\n     apply simp\n    apply (simp add:word_size)\n    apply (subst (asm) less_mask_eq)\n     apply (simp add:pd_bits_def pageBits_def le_less_trans)\n    apply (case_tac v)\n      apply (simp add:ucast_ucast_len pd_bits_def pageBits_def le_less_trans)+\n    apply (clarsimp split:if_splits)\n     apply (simp add:kernel_base_shift_cast_le)\n     apply (simp add:kernel_base_def)\n     apply (cut_tac y1 = xb and x1 = \"0xE00::12 word\" in ucast_le_migrate[THEN iffD1,rotated -1])\n        apply simp\n       apply (simp add:word_size le_less_trans)\n      apply (simp add:word_size)\n     apply (drule aligned_le_sharp[where n = 4 and a = \"0xE00::12 word\"])\n      apply (simp add:kernel_base_def is_aligned_def)\n     apply (erule order_trans)\n     apply (erule subst)\n     apply (simp add:word_and_le2)\n    apply (subst ucast_ucast_len)\n     apply (simp,word_bitwise)\n    apply simp\n   apply (clarsimp simp:image_def)\n   apply (rule disjointI)\n   apply clarsimp\n   apply (drule_tac x = \"ucast x\" in spec)\n   apply (erule impE)\n    apply (simp add:pd_bits_def pageBits_def)\n    apply word_bitwise\n   apply (subgoal_tac \"kernel_base >> 20 \\<le> ucast x\")\n    apply simp\n    apply (subst (asm) less_mask_eq)\n     apply (rule shiftl_less_t2n)\n      apply (simp add:pd_bits_def pageBits_def word_le_make_less)\n      apply word_bitwise\n     apply (simp add:pd_bits_def pageBits_def)\n    apply (subst (asm) shiftl_shiftr1)\n     apply simp\n    apply (simp add:word_size)\n    apply (subst (asm) less_mask_eq)\n     apply (rule less_le_trans[OF ucast_less])\n      apply simp\n     apply simp\n    apply word_bitwise\n   apply (case_tac v,simp_all)\n   apply (clarsimp split:if_splits)\n   apply (drule aligned_le_sharp[where n = 4])\n    apply (simp add:kernel_base_def is_aligned_def)\n   apply (simp add:word_size kernel_base_def pd_bits_def pageBits_def)\n   apply word_bitwise\n   apply simp\n  apply (clarsimp simp:obj_at_def)\n  apply (subst (asm) is_aligned_neg_mask_eq\n    [where p = p and n = pd_bits,symmetric])\n   apply simp\n  apply (drule(1) valid_pdpt_objs_pdD[rotated])+\n  apply (clarsimp simp:entries_align_def)\n  done\n\nlemma in_pte_rangeD:\n  \"x \\<in> pte_range v y \\<Longrightarrow> x && ~~ mask 4 = y && ~~ mask 4\"\n  by (case_tac v,simp_all split:if_splits)\n\nlemma in_pde_rangeD:\n  \"x \\<in> pde_range v y \\<Longrightarrow> x && ~~ mask 4 = y && ~~ mask 4\"\n  by (case_tac v,simp_all split:if_splits)\n\nlemma mapM_x_store_pte_valid_pdpt2:\n  \"\\<lbrace>valid_pdpt_objs and K (is_aligned ptr pt_bits)\\<rbrace>\n     mapM_x (\\<lambda>x. store_pte x InvalidPTE) [ptr, ptr + 4 .e. ptr + 2 ^ pt_bits - 1]\n   \\<lbrace>\\<lambda>_. valid_pdpt_objs\\<rbrace>\"\n  apply (rule hoare_gen_asm)+\n  apply (rule mapM_x_wp')\n  apply (simp add:store_pte_def set_pt_def)\n  apply (wp get_pt_wp get_object_wp)\n  apply (clarsimp simp: mask_in_range\n    split:Structures_A.kernel_object.splits\n    arch_kernel_obj.splits)\n  apply (rule conjI)\n   apply (rule valid_entries_overwrite_0)\n    apply (fastforce simp:ran_def obj_at_def)\n   apply simp\n  apply (simp add:fun_upd_def obj_at_def)\n  apply (rule entries_align_pte_update)\n   apply (drule (1) valid_pdpt_objs_ptD,simp)\n  apply simp\n  done\n\nlemma mapM_x_store_pde_valid_pdpt2:\n  \"\\<lbrace>valid_pdpt_objs and K (is_aligned pd pd_bits)\\<rbrace>\n       mapM_x (\\<lambda>x. store_pde ((x << 2) + pd) pde.InvalidPDE)\n        [0.e.(kernel_base >> 20) - 1]\n       \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (rule hoare_gen_asm)\n  apply (rule mapM_x_wp')\n  apply (simp add:store_pde_def set_pd_def)\n  apply (wp get_pd_wp get_object_wp)\n  apply (clarsimp simp: mask_in_range\n    split:Structures_A.kernel_object.splits\n    arch_kernel_obj.splits)\n  apply (rule conjI)\n   apply (rule valid_entries_overwrite_0)\n    apply (fastforce simp:ran_def obj_at_def)\n   apply simp\n  apply (simp add:fun_upd_def obj_at_def)\n  apply (rule entries_align_pde_update)\n   apply (drule (1) valid_pdpt_objs_pdD,simp)\n  apply simp\n  done\n\nlemma non_invalid_in_pde_range:\n  \"pde \\<noteq> InvalidPDE\n  \\<Longrightarrow> x \\<in> pde_range pde x\"\n  by (case_tac pde,simp_all)\n\nlemma non_invalid_in_pte_range:\n  \"pte \\<noteq> InvalidPTE\n  \\<Longrightarrow> x \\<in> pte_range pte x\"\n  by (case_tac pte,simp_all)\n\ncrunch valid_pdpt_objs[wp]: cancel_badged_sends \"valid_pdpt_objs\"\n  (simp: crunch_simps filterM_mapM wp: crunch_wps ignore: filterM)\n\ncrunch valid_pdpt_objs[wp]: cap_move, cap_insert \"valid_pdpt_objs\"\n\nlemma invoke_cnode_valid_pdpt_objs[wp]:\n  \"\\<lbrace>valid_pdpt_objs and invs and valid_cnode_inv i\\<rbrace> invoke_cnode i \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (simp add: invoke_cnode_def)\n  apply (rule hoare_pre)\n   apply (wp get_cap_wp | wpc | simp split del: if_split)+\n  done\n\nlemma as_user_valid_pdpt_objs[wp]:\n  \"\\<lbrace>valid_pdpt_objs\\<rbrace> as_user t m \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (simp add: as_user_def split_def)\n  apply wp\n  apply simp\n  done\n\ncrunch valid_pdpt_objs[wp]: invoke_tcb \"valid_pdpt_objs\"\n  (wp: check_cap_inv crunch_wps simp: crunch_simps\n       ignore: check_cap_at)\n\nlemma invoke_domain_valid_pdpt_objs[wp]:\n  \"\\<lbrace>valid_pdpt_objs\\<rbrace> invoke_domain t d \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  by (simp add: invoke_domain_def | wp)+\n\ncrunch valid_pdpt_objs[wp]: set_extra_badge, transfer_caps_loop \"valid_pdpt_objs\"\n  (wp: transfer_caps_loop_pres)\n\ncrunch valid_pdpt_objs[wp]: send_ipc, send_signal,\n    do_reply_transfer, invoke_irq_control, invoke_irq_handler \"valid_pdpt_objs\"\n  (wp: crunch_wps simp: crunch_simps\n         ignore: clearMemory const_on_failure set_object)\n\nlemma valid_pdpt_objs_trans_state[simp]: \"valid_pdpt_objs (trans_state f s) = valid_pdpt_objs s\"\n  apply (simp add: obj_valid_pdpt_def)\n  done\n\nlemma retype_region_valid_pdpt[wp]:\n  \"\\<lbrace>valid_pdpt_objs\\<rbrace> retype_region ptr bits o_bits type dev \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (simp add: retype_region_def split del: if_split)\n  apply (wp | simp only: valid_pdpt_objs_trans_state trans_state_update[symmetric])+\n  apply (clarsimp simp: retype_addrs_fold foldr_upd_app_if ranI\n                 elim!: ranE split: if_split_asm simp del:fun_upd_apply)\n  apply (simp add: default_object_def default_arch_object_def\n            split: Structures_A.kernel_object.splits\n    Structures_A.apiobject_type.split aobject_type.split)+\n  apply (simp add:entries_align_def)\n  done\n\nlemma detype_valid_pdpt[elim!]:\n  \"valid_pdpt_objs s \\<Longrightarrow> valid_pdpt_objs (detype S s)\"\n  by (auto simp add: detype_def ran_def)\n\ncrunch valid_pdpt_objs[wp]: create_cap \"valid_pdpt_objs\"\n  (ignore: clearMemory simp: crunch_simps unless_def)\n\nlemma init_arch_objects_valid_pdpt:\n  \"\\<lbrace>valid_pdpt_objs and pspace_aligned and valid_arch_state\n           and K (\\<exists>us sz. orefs = retype_addrs ptr type n us\n               \\<and> range_cover ptr sz (obj_bits_api type us) n)\\<rbrace>\n     init_arch_objects type ptr n obj_sz orefs\n   \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (rule hoare_gen_asm)+\n  apply (clarsimp simp: init_arch_objects_def\n             split del: if_split)\n  apply (rule hoare_pre)\n   apply (wp | wpc)+\n     apply (rule_tac Q=\"\\<lambda>rv. valid_pdpt_objs and pspace_aligned and valid_arch_state\"\n                  in hoare_post_imp, simp)\n     apply (rule mapM_x_wp')\n     apply (rule hoare_pre, wp copy_global_mappings_valid_pdpt_objs)\n     apply clarsimp\n     apply (drule_tac sz=sz in retype_addrs_aligned)\n        apply (simp add:range_cover_def)\n       apply (drule range_cover.sz,simp add:word_bits_def)\n      apply (simp add:range_cover_def)\n     apply (clarsimp simp:obj_bits_api_def pd_bits_def pageBits_def\n       arch_kobj_size_def default_arch_object_def range_cover_def)+\n   apply wp\n  apply simp\n  done\n\nlemma delete_objects_valid_pdpt:\n  \"\\<lbrace>valid_pdpt_objs\\<rbrace> delete_objects ptr bits \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  by (rule delete_objects_reduct) (wp detype_valid_pdpt)\n\ncrunch valid_pdpt[wp]: reset_untyped_cap \"valid_pdpt_objs\"\n  (wp: mapME_x_inv_wp crunch_wps simp: crunch_simps unless_def)\n\nlemma invoke_untyped_valid_pdpt[wp]:\n  \"\\<lbrace>valid_pdpt_objs and invs and ct_active\n          and valid_untyped_inv ui\\<rbrace>\n       invoke_untyped ui\n   \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (rule hoare_pre, rule invoke_untyped_Q)\n      apply (wp init_arch_objects_valid_pdpt | simp)+\n     apply (auto simp: post_retype_invs_def split: if_split_asm)[1]\n    apply (wp | simp)+\n  done\n\ncrunch valid_pdpt_objs[wp]: perform_asid_pool_invocation,\n     perform_asid_control_invocation \"valid_pdpt_objs\"\n  (ignore: delete_objects wp: delete_objects_valid_pdpt static_imp_wp)\n\nabbreviation (input)\n  \"safe_pt_range \\<equiv> \\<lambda>slots s. obj_at (\\<lambda>ko. \\<exists>pt. ko = ArchObj (PageTable pt)\n                                    \\<and> (\\<forall>x\\<in>set (tl slots). pt (ucast (x && mask pt_bits >> 2))\n                                      = pte.InvalidPTE))\n                              (hd slots && ~~ mask pt_bits) s\"\n\nabbreviation (input)\n  \"safe_pd_range \\<equiv> \\<lambda>slots s. obj_at (\\<lambda>ko. \\<exists>pd. ko = ArchObj (PageDirectory pd)\n                                    \\<and> (\\<forall>x\\<in>set (tl slots). pd (ucast (x && mask pd_bits >> 2))\n                                      = pde.InvalidPDE))\n                              (hd slots && ~~ mask pd_bits) s\"\n\ndefinition\n  \"page_inv_entries_pre entries \\<equiv>\n   let slots = (case entries of Inl (pte, slots) \\<Rightarrow> slots | Inr (pde, slots) \\<Rightarrow> slots)\n   in (if \\<exists>sl. slots = [sl]\n    then case entries of\n        Inl (pte, _) \\<Rightarrow> obj_at (\\<lambda>ko. \\<exists>pt pte. ko = ArchObj (PageTable pt)\n                     \\<and> pt (ucast (hd slots && mask pt_bits >> 2) && ~~ mask 4) = pte\n                     \\<and> pte_range_sz pte = 0)\n                 (hd slots && ~~ mask pt_bits)\n            and K (pte_range_sz pte = 0)\n      | Inr (pde, _) \\<Rightarrow> obj_at (\\<lambda>ko. \\<exists>pd pde. ko = ArchObj (PageDirectory pd)\n                     \\<and> pd (ucast (head slots && mask pd_bits >> 2) && ~~ mask 4)\n                            = pde \\<and> pde_range_sz pde = 0)\n                 (hd slots && ~~ mask pd_bits)\n           and K (pde_range_sz pde = 0)\n    else  (\\<lambda>s. (\\<exists>p. is_aligned p 6 \\<and> slots = map (\\<lambda>x. x + p) [0, 4 .e. 0x3C])))\n   and K (case entries of Inl (pte,slots) \\<Rightarrow> pte \\<noteq> InvalidPTE\n     | Inr (pde,slots) \\<Rightarrow> pde \\<noteq> InvalidPDE)\"\n\ndefinition\n  \"page_inv_entries_safe entries \\<equiv>\n   let slots = (case entries of Inl (pte, slots) \\<Rightarrow> slots | Inr (pde, slots) \\<Rightarrow> slots)\n   in if \\<exists>sl. slots = [sl]\n    then case entries of\n        Inl (pte, _) \\<Rightarrow> obj_at (\\<lambda>ko. \\<exists>pt pte. ko = ArchObj (PageTable pt)\n                     \\<and> pt (ucast (hd slots && mask pt_bits >> 2) && ~~ mask 4) = pte\n                     \\<and> pte_range_sz pte = 0)\n                 (hd slots && ~~ mask pt_bits)\n            and K (pte_range_sz pte = 0)\n      | Inr (pde, _) \\<Rightarrow> obj_at (\\<lambda>ko. \\<exists>pd pde. ko = ArchObj (PageDirectory pd)\n                     \\<and> pd (ucast (head slots && mask pd_bits >> 2) && ~~ mask 4)\n                            = pde \\<and> pde_range_sz pde = 0)\n                 (hd slots && ~~ mask pd_bits)\n           and K (pde_range_sz pde = 0)\n    else  (\\<lambda>s. (\\<exists>p. is_aligned p 6 \\<and> slots = map (\\<lambda>x. x + p) [0, 4 .e. 0x3C]\n                  \\<and> (case entries of\n                     Inl (pte, _) \\<Rightarrow> safe_pt_range slots s\n                   | Inr (pde, _) \\<Rightarrow> safe_pd_range slots s\n                     )))\"\n\ndefinition\n  \"page_inv_duplicates_valid iv \\<equiv> case iv of\n         PageMap asid cap ct_slot entries \\<Rightarrow>\n            page_inv_entries_safe entries\n       | PageRemap asid entries \\<Rightarrow>\n            page_inv_entries_safe entries\n       | _ \\<Rightarrow> \\<top>\"\n\nlemma pte_range_interD:\n \"pte_range pte p \\<inter> pte_range pte' p' \\<noteq> {}\n  \\<Longrightarrow> pte \\<noteq> InvalidPTE \\<and> pte' \\<noteq> InvalidPTE\n      \\<and> p && ~~ mask 4 = p' && ~~ mask 4\"\n  apply (drule int_not_emptyD)\n  apply (case_tac pte,simp_all split:if_splits)\n   apply (case_tac pte',simp_all split:if_splits)\n   apply clarsimp\n   apply (case_tac pte',simp_all split:if_splits)\n  apply (case_tac pte', simp_all split:if_splits)\n  done\n\nlemma pde_range_interD:\n \"pde_range pde p \\<inter> pde_range pde' p' \\<noteq> {}\n  \\<Longrightarrow> pde \\<noteq> InvalidPDE \\<and> pde' \\<noteq> InvalidPDE\n      \\<and> p && ~~ mask 4 = p' && ~~ mask 4\"\n  apply (drule int_not_emptyD)\n  apply (case_tac pde,simp_all split:if_splits)\n     apply (case_tac pde',simp_all split:if_splits)\n    apply (case_tac pde',simp_all split:if_splits)\n   apply clarsimp\n   apply (case_tac pde', simp_all split:if_splits)\n  apply (case_tac pde', simp_all split:if_splits)\n  done\n\nlemma pte_range_sz_le:\n  \"(pte_range_sz pte) \\<le> 4\"\n  by (case_tac pte,simp_all)\n\nlemma pde_range_sz_le:\n  \"(pde_range_sz pde) \\<le> 4\"\n  by (case_tac pde,simp_all)\n\n(* BUG , revisit the following lemmas , moved from ArchAcc_R.thy *)\nlemma mask_pd_bits_shift_ucast_align[simp]:\n  \"is_aligned (ucast (p && mask pd_bits >> 2)::12 word) 4 =\n   is_aligned ((p::word32) >> 2) 4\"\n  by (clarsimp simp: is_aligned_mask mask_def pd_bits) word_bitwise\n\nlemma mask_pt_bits_shift_ucast_align[simp]:\n  \"is_aligned (ucast (p && mask pt_bits >> 2)::word8) 4 =\n   is_aligned ((p::word32) >> 2) 4\"\n  by (clarsimp simp: is_aligned_mask mask_def pt_bits_def pageBits_def)\n     word_bitwise\n\nlemma store_pte_valid_pdpt:\n  \"\\<lbrace>valid_pdpt_objs and page_inv_entries_safe (Inl (pte, slots))\\<rbrace>\n       store_pte (hd slots) pte \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (rule hoare_name_pre_state)\n  apply (clarsimp simp:page_inv_entries_safe_def split:if_splits)\n   apply (clarsimp simp:store_pte_def set_pt_def)\n   apply (wp get_pt_wp get_object_wp)\n   apply (clarsimp simp:obj_at_def\n     split:pte.splits arch_kernel_obj.splits)\n  apply (rule conjI)\n    apply (drule(1) valid_pdpt_objs_ptD)\n    apply (rule valid_entries_overwrite_0)\n     apply simp\n    apply (case_tac pte)\n     apply simp+\n    apply (case_tac \"pta p\",simp_all)\n    apply (clarsimp simp: is_aligned_neg_mask_eq)\n   apply (simp add:fun_upd_def)\n   apply (rule entries_align_pte_update)\n    apply (drule (1) valid_pdpt_objs_ptD,simp)\n   apply simp\n  apply (simp add:hd_map_simp upto_enum_def upto_enum_step_def)\n  apply (clarsimp simp:store_pte_def set_pt_def)\n  apply (wp get_pt_wp get_object_wp)\n  apply (clarsimp simp:obj_at_def\n     split:pte.splits arch_kernel_obj.splits)\n  apply (drule(1) valid_pdpt_objs_ptD)\n  apply (rule conjI)\n   apply (rule valid_entries_overwrite_0)\n    apply simp\n   apply (rule ccontr)\n   apply (drule pte_range_interD)\n   apply clarsimp\n   apply (simp add:ucast_neg_mask)\n   apply (subst (asm) is_aligned_neg_mask_eq[where n = 4])\n    apply (rule is_aligned_shiftr[OF is_aligned_andI1])\n    apply simp\n   apply (drule_tac x = \"((p && ~~ mask pt_bits)  + ((ucast pa) << 2))\" in bspec)\n    apply (clarsimp simp: tl_map_simp upto_0_to_n2 image_def)\n    apply (rule_tac x = \"unat (((ucast pa)::word32) - (p && mask pt_bits >> 2))\" in bexI)\n     apply (simp add:ucast_nat_def shiftl_t2n mask_out_sub_mask)\n     apply (subst shiftl_t2n[where n = 2,simplified field_simps,simplified,symmetric])\n     apply (subst shiftr_shiftl1)\n      apply simp+\n     apply (subst is_aligned_neg_mask_eq)\n      apply (erule is_aligned_andI1[OF is_aligned_weaken])\n      apply simp\n     apply simp\n    apply simp\n    apply (drule_tac s = \"ucast (p && mask pt_bits >> 2)\" in sym)\n    apply (simp add:mask_out_sub_mask field_simps)\n    apply (drule_tac f = \"ucast::(word8\\<Rightarrow>word32)\" in arg_cong)\n    apply (simp add:ucast_pt_index pt_bits_def pageBits_def)\n    apply (simp add:unat_ucast_8_32)\n    apply (rule conjI)\n     apply (subgoal_tac \"unat (pa && mask 4)\\<noteq> 0\")\n      apply simp\n     apply (simp add:unat_gt_0)\n    apply (rule unat_less_helper)\n    apply (rule le_less_trans[OF word_and_le1])\n    apply (simp add:mask_def)\n   apply (simp add:field_simps neg_mask_add_mask)\n   apply (thin_tac \"ucast y = x\" for y x)\n   apply (subst (asm) less_mask_eq[where n = pt_bits])\n    apply (rule shiftl_less_t2n)\n     apply (simp add:pt_bits_def pageBits_def)\n     apply word_bitwise\n    apply (simp add:pt_bits_def pageBits_def)\n   apply (subst (asm) shiftl_shiftr_id)\n    apply simp\n   apply (simp,word_bitwise)\n   apply (simp add:ucast_ucast_id)\n  apply (simp add:fun_upd_def entries_align_def)\n  apply (rule is_aligned_weaken[OF _ pte_range_sz_le])\n  apply (simp add:is_aligned_shiftr)\n  done\n\nlemma store_pde_valid_pdpt:\n  \"\\<lbrace>valid_pdpt_objs and page_inv_entries_safe (Inr (pde, slots))\\<rbrace>\n       store_pde (hd slots) pde \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (rule hoare_name_pre_state)\n  apply (clarsimp simp:page_inv_entries_safe_def split:if_splits)\n   apply (clarsimp simp:store_pde_def set_pd_def)\n   apply (wp get_pd_wp get_object_wp)\n   apply (clarsimp simp:obj_at_def\n     split:pde.splits arch_kernel_obj.splits)\n   apply (drule(1) valid_pdpt_objs_pdD)\n   apply (rule conjI)\n    apply (rule valid_entries_overwrite_0)\n     apply simp\n    apply (case_tac pde,simp_all)\n     apply (case_tac \"pda p\",simp_all)\n     apply (clarsimp simp: is_aligned_neg_mask_eq)\n    apply (case_tac \"pda p\",simp_all)\n    apply (clarsimp simp: is_aligned_neg_mask_eq)\n   apply (simp add:fun_upd_def)\n   apply (rule entries_align_pde_update)\n    apply simp+\n  apply (simp add:hd_map_simp upto_enum_def upto_enum_step_def)\n  apply (clarsimp simp:store_pde_def set_pd_def)\n  apply (wp get_pd_wp get_object_wp)\n  apply (clarsimp simp:obj_at_def\n     split:pde.splits arch_kernel_obj.splits)\n  apply (drule(1) valid_pdpt_objs_pdD)\n  apply (rule conjI)\n   apply (rule valid_entries_overwrite_0)\n    apply simp\n   apply (rule ccontr)\n   apply (drule pde_range_interD)\n   apply clarsimp\n   apply (simp add:ucast_neg_mask)\n   apply (subst (asm) is_aligned_neg_mask_eq[where n = 4])\n    apply (rule is_aligned_shiftr[OF is_aligned_andI1])\n    apply simp\n   apply (drule_tac x = \"((p && ~~ mask pd_bits)  + ((ucast pa) << 2))\" in bspec)\n    apply (clarsimp simp: tl_map_simp upto_0_to_n2 image_def)\n    apply (rule_tac x = \"unat (((ucast pa)::word32) - (p && mask pd_bits >> 2))\" in bexI)\n     apply (simp add:ucast_nat_def shiftl_t2n mask_out_sub_mask)\n     apply (subst shiftl_t2n[where n = 2,simplified field_simps,simplified,symmetric])\n     apply (subst shiftr_shiftl1)\n      apply simp+\n     apply (subst is_aligned_neg_mask_eq)\n      apply (erule is_aligned_andI1[OF is_aligned_weaken])\n      apply simp\n     apply simp\n    apply simp\n    apply (drule_tac s = \"ucast (p && mask pd_bits >> 2)\" in sym)\n    apply (simp add:mask_out_sub_mask field_simps)\n    apply (drule_tac f = \"ucast::(12 word\\<Rightarrow>word32)\" in arg_cong)\n    apply (simp add:ucast_pd_index pd_bits_def pageBits_def)\n    apply (simp add:unat_ucast_12_32)\n    apply (rule conjI)\n     apply (subgoal_tac \"unat (pa && mask 4)\\<noteq> 0\")\n      apply simp\n     apply (simp add:unat_gt_0)\n    apply (rule unat_less_helper)\n    apply (rule le_less_trans[OF word_and_le1])\n    apply (simp add:mask_def)\n   apply (simp add:field_simps neg_mask_add_mask)\n   apply (thin_tac \"ucast y = x\" for y x)\n   apply (subst (asm) less_mask_eq[where n = pd_bits])\n    apply (rule shiftl_less_t2n)\n     apply (simp add:pd_bits_def pageBits_def)\n     apply word_bitwise\n    apply (simp add:pd_bits_def pageBits_def)\n   apply (subst (asm) shiftl_shiftr_id)\n     apply simp\n    apply (simp,word_bitwise)\n   apply (simp add:ucast_ucast_id)\n  apply (simp add:entries_align_def)\n  apply (rule is_aligned_weaken[OF _ pde_range_sz_le])\n  apply (simp add:is_aligned_shiftr)\n  done\n\nlemma set_cap_page_inv_entries_safe:\n  \"\\<lbrace>page_inv_entries_safe x\\<rbrace> set_cap y z \\<lbrace>\\<lambda>_. page_inv_entries_safe x\\<rbrace>\"\n  apply (simp add:page_inv_entries_safe_def set_cap_def split_def\n    get_object_def set_object_def)\n  apply (wp | wpc)+\n  apply (case_tac x)\n  apply (auto simp:obj_at_def\n    Let_def split:if_splits option.splits)\n  done\n\ncrunch valid_pdpt[wp]: pte_check_if_mapped, pde_check_if_mapped \"valid_pdpt_objects\"\n\nlemma perform_page_valid_pdpt[wp]:\n  \"\\<lbrace>valid_pdpt_objs and valid_page_inv pinv and page_inv_duplicates_valid pinv\\<rbrace>\n        perform_page_invocation pinv \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (simp add: perform_page_invocation_def page_inv_duplicates_valid_def)\n  apply (cases pinv,\n         simp_all add: mapM_discarded page_inv_entries_safe_def\n            split: sum.split arch_cap.split option.split,\n         safe intro!: hoare_gen_asm hoare_gen_asm[unfolded K_def],\n         simp_all add: mapM_x_Nil mapM_x_Cons mapM_x_map)\n            apply (wp store_pte_valid_pdpt store_pde_valid_pdpt get_master_pte_wp get_master_pde_wp\n                      store_pte_non_master_valid_pdpt store_pde_non_master_valid_pdpt\n                      mapM_x_wp'[OF store_invalid_pte_valid_pdpt\n                        [where pte=pte.InvalidPTE, simplified]]\n                      mapM_x_wp'[OF store_invalid_pde_valid_pdpt\n                        [where pde=pde.InvalidPDE, simplified]]\n                      set_cap_page_inv_entries_safe\n                      hoare_vcg_imp_lift[OF set_cap_arch_obj_neg] hoare_vcg_all_lift\n                 | clarsimp simp: cte_wp_at_weakenE[OF _ TrueI] obj_at_def\n                                  pte_range_sz_def pde_range_sz_def swp_def valid_page_inv_def\n                                  valid_slots_def page_inv_entries_safe_def pte_check_if_mapped_def\n                                  pde_check_if_mapped_def\n                           split: pte.splits pde.splits\n                 | wp_once hoare_drop_imps)+\n  done\n\ndefinition\n  \"pti_duplicates_valid iv \\<equiv>\n   case iv of PageTableMap cap ct_slot pde pd_slot\n     \\<Rightarrow> obj_at (\\<lambda>ko. \\<exists>pd pde. ko = ArchObj (PageDirectory pd)\n                     \\<and> pd (ucast (pd_slot && mask pd_bits >> 2) && ~~ mask 4)\n                            = pde \\<and> pde_range_sz pde = 0)\n                 (pd_slot && ~~ mask pd_bits)\n\n           and K (pde_range_sz pde = 0)\n  | _ \\<Rightarrow> \\<top>\"\n\n\ndefinition\n  \"invocation_duplicates_valid i \\<equiv>\n   case i of\n     InvokeArchObject (InvokePage pgi) \\<Rightarrow> page_inv_duplicates_valid pgi\n   | InvokeArchObject (InvokePageTable pti) \\<Rightarrow> pti_duplicates_valid pti\n   | _ \\<Rightarrow> \\<top>\"\n\nlemma perform_page_table_valid_pdpt[wp]:\n  \"\\<lbrace>valid_pdpt_objs and valid_pti pinv and pti_duplicates_valid pinv\\<rbrace>\n      perform_page_table_invocation pinv \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (simp add: perform_page_table_invocation_def split_def\n             cong: page_table_invocation.case_cong\n                   option.case_cong cap.case_cong arch_cap.case_cong)\n  apply (rule hoare_pre)\n   apply (wp store_pde_non_master_valid_pdpt hoare_vcg_ex_lift\n             set_cap_arch_obj mapM_x_store_pte_valid_pdpt2\n              | wpc\n              | simp add: swp_def\n              | strengthen all_imp_ko_at_from_ex_strg)+\n  apply (clarsimp simp: pti_duplicates_valid_def valid_pti_def)\n  apply (auto simp: obj_at_def cte_wp_at_caps_of_state valid_cap_simps\n                    cap_aligned_def pt_bits_def pageBits_def\n            intro!: inj_onI)\n  done\n\nlemma perform_page_directory_valid_pdpt[wp]:\n  \"\\<lbrace>valid_pdpt_objs and valid_pdi pinv\\<rbrace>\n      perform_page_directory_invocation pinv \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (simp add: perform_page_directory_invocation_def split_def)\n  apply (rule hoare_pre)\n   apply (wp | wpc | simp)+\n  done\n\nlemma perform_invocation_valid_pdpt[wp]:\n  \"\\<lbrace>invs and ct_active and valid_invocation i and valid_pdpt_objs\n           and invocation_duplicates_valid i\\<rbrace>\n      perform_invocation blocking call i\n         \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (cases i, simp_all)\n  apply (wp send_signal_interrupt_states | simp)+\n  apply (clarsimp simp: invocation_duplicates_valid_def)\n  apply (wp | wpc | simp)+\n  apply (simp add: arch_perform_invocation_def)\n  apply (rule hoare_pre)\n  apply (wp | wpc | simp)+\n  apply (auto simp: valid_arch_inv_def invocation_duplicates_valid_def)\n  done\n\nlemma neg_mask_pt_6_4:\n  \"(ptr && mask pt_bits >> 2) && ~~ mask 4 =\n   (ptr::word32) && ~~ mask 6 && mask pt_bits >> 2\"\n  apply (simp add:pt_bits_def pageBits_def)\n  apply word_bitwise\n  apply (simp add:word_size)\n  done\n\nlemma neg_mask_pd_6_4:\n  \"(ptr && mask pd_bits >> 2) && ~~ mask 4 =\n   (ptr::word32) && ~~ mask 6 && mask pd_bits >> 2\"\n  apply (simp add:pd_bits_def pageBits_def)\n  apply word_bitwise\n  apply (simp add:word_size)\n  done\n\nlemma mask_out_same_pt:\n  \"\\<lbrakk>is_aligned p 6; x < 2 ^ 6 \\<rbrakk> \\<Longrightarrow> p + x && ~~ mask pt_bits = p && ~~ mask pt_bits\"\n  apply (subst mask_lower_twice[symmetric,where n = 6])\n   apply (simp add:pt_bits_def pageBits_def)\n  apply (simp add:is_aligned_add_helper)\n  done\n\nlemma mask_out_same_pd:\n  \"\\<lbrakk>is_aligned p 6; x < 2 ^ 6 \\<rbrakk> \\<Longrightarrow> p + x && ~~ mask pd_bits = p && ~~ mask pd_bits\"\n  apply (subst mask_lower_twice[symmetric,where n = 6])\n   apply (simp add:pd_bits_def pageBits_def)\n  apply (simp add:is_aligned_add_helper)\n  done\n\nlemma ensure_safe_mapping_ensures[wp]:\n  \"\\<lbrace>valid_pdpt_objs and (case entries of (Inl (SmallPagePTE _ _ _, [_])) \\<Rightarrow> \\<top>\n                  | (Inl (SmallPagePTE _ _ _, _)) \\<Rightarrow> \\<bottom>\n                  | (Inl (LargePagePTE _ _ _, [])) \\<Rightarrow> \\<bottom>\n                  | (Inr (SectionPDE _ _ _ _, [_])) \\<Rightarrow> \\<top>\n                  | (Inr (SuperSectionPDE _ _ _, [])) \\<Rightarrow> \\<bottom>\n                  | (Inr (SectionPDE _ _ _ _, _)) \\<Rightarrow> \\<bottom>\n                  | _ \\<Rightarrow> page_inv_entries_pre entries)\\<rbrace>\n     ensure_safe_mapping entries\n   \\<lbrace>\\<lambda>rv. page_inv_entries_safe entries\\<rbrace>,-\"\n  proof -\n    have [simp]:\n      \"\\<And>s a. page_inv_entries_pre (Inl (pte.InvalidPTE, a)) s \\<Longrightarrow>\n      page_inv_entries_safe (Inl (pte.InvalidPTE, a)) s\"\n      apply (clarsimp simp:page_inv_entries_pre_def page_inv_entries_safe_def\n        split:if_splits)\n      done\n    have name_pre:\n      \"\\<And>F P Q. (\\<And>s. P s \\<Longrightarrow> \\<lbrace>op = s \\<rbrace> F \\<lbrace>Q\\<rbrace>, -) \\<Longrightarrow> \\<lbrace>P\\<rbrace> F \\<lbrace>Q\\<rbrace>,-\"\n      apply (simp add:validE_R_def validE_def)\n      apply (rule hoare_name_pre_state)\n      apply assumption\n      done\n    have mask_neg_mask_order[simp]:\n      \"\\<And>a m n. a && ~~ mask m && mask n = a && mask n && ~~ mask m\"\n       by (simp add:word_bw_comms word_bw_lcs)\n    have align_entry_ptD:\n      \"\\<And>pt m x xb xc. \\<lbrakk>pt m = pte.LargePagePTE x xb xc; entries_align pte_range_sz pt\\<rbrakk>\n       \\<Longrightarrow> is_aligned m 4\"\n      apply (simp add:entries_align_def)\n      apply (drule_tac x = m in spec,simp)\n      done\n    have align_entry_pdD:\n      \"\\<And>pd m x xb xc. \\<lbrakk>pd m = pde.SuperSectionPDE x xb xc; entries_align pde_range_sz pd\\<rbrakk>\n       \\<Longrightarrow> is_aligned m 4\"\n      apply (simp add:entries_align_def)\n      apply (drule_tac x = m in spec,simp)\n      done\n    have pt_offset_bitwise[simp]:\"\\<And>a. (ucast ((a::word32) && mask pt_bits && ~~ mask 6  >> 2)::word8)\n      = (ucast (a  && mask pt_bits >> 2)::word8) && ~~ mask 4\"\n    apply (simp add:pt_bits_def pageBits_def mask_def)\n    apply word_bitwise\n    done\n    have pd_offset_bitwise[simp]:\"\\<And>a. (ucast ((a::word32) && mask pd_bits && ~~ mask 6  >> 2)::12 word)\n      = (ucast (a  && mask pd_bits >> 2)::12 word) && ~~ mask 4\"\n    apply (simp add:pt_bits_def pageBits_def mask_def pd_bits_def)\n    apply word_bitwise\n    done\n    have mask_neq_0:\n      \"\\<And>z zs xa p g. \\<lbrakk>[0 :: word32, 4 .e. 0x3C] = z # zs; xa \\<in> set zs; is_aligned p 6; 6 \\<le> g\\<rbrakk>\n         \\<Longrightarrow> (p + xa && mask g >> 2) && mask 4 \\<noteq> 0\"\n     apply (rule ccontr)\n      apply (simp add:is_aligned_mask[symmetric])\n       apply (drule is_aligned_shiftl[where n = 6 and m = 2,simplified])\n      apply (subst (asm) shiftr_shiftl1)\n       apply simp+\n      apply (subst (asm) is_aligned_neg_mask_eq)\n       apply (rule is_aligned_andI1)\n       apply (erule aligned_add_aligned)\n        apply (clarsimp simp :upto_enum_def upto_enum_step_def\n         Fun.comp_def upto_0_to_n2 is_aligned_mult_triv2[where n = 2,simplified])\n       apply simp\n      apply (simp add:is_aligned_mask mask_twice\n        pt_bits_def pageBits_def min_def)\n      apply (subst (asm) is_aligned_mask[symmetric])\n      apply (subst (asm) is_aligned_add_helper)\n       apply simp\n      apply (clarsimp simp :upto_enum_def upto_enum_step_def\n         Fun.comp_def upto_0_to_n2)\n      apply (subst shiftl_t2n\n        [where n = 2,simplified field_simps,simplified,symmetric])+\n      apply (rule shiftl_less_t2n[where m = 6,simplified])\n       apply (rule word_of_nat_less)\n       apply simp\n      apply simp\n     apply (clarsimp simp :upto_enum_def upto_enum_step_def\n         Fun.comp_def upto_0_to_n2)\n     apply (cut_tac x = \"of_nat x\" and n = 2 in word_power_nonzero_32)\n        apply (simp add:word_of_nat_less word_bits_def)+\n      apply (simp add: of_nat_neq_0)\n     apply simp\n     done \n    have neq_pt_offset: \"\\<And>z zs xa (p::word32). \\<lbrakk>[0 , 4 .e. 0x3C] = z # zs;\n        xa \\<in> set zs;is_aligned p 6 \\<rbrakk> \\<Longrightarrow>\n        ucast (p + xa && mask pt_bits >> 2) && ~~ mask 4 \\<noteq> ((ucast (p + xa && mask pt_bits >> 2))::word8)\"\n      apply (rule ccontr)\n      apply (simp add:mask_out_sub_mask ucast_and_mask[symmetric])\n      apply (drule arg_cong[where f = unat])\n      apply (simp add:unat_ucast)\n      apply (subst (asm) mod_less)\n       apply (rule unat_less_helper)\n       apply (rule le_less_trans[OF word_and_le1])\n       apply (simp add:mask_def)\n      apply (simp add:unat_eq_0)\n      apply (drule(2) mask_neq_0[of _ _ _ _ pt_bits])\n       apply (simp add:pt_bits_def pageBits_def)+\n      done\n    have neq_pd_offset: \"\\<And>z zs xa (p::word32). \\<lbrakk>[0 , 4 .e. 0x3C] = z # zs;\n        xa \\<in> set zs;is_aligned p 6 \\<rbrakk> \\<Longrightarrow>\n        ucast (p + xa && mask pd_bits >> 2) && ~~ mask 4 \\<noteq> ((ucast (p + xa && mask pd_bits >> 2)) :: 12 word)\"\n      apply (simp add:mask_out_sub_mask)\n      apply (rule ccontr)\n      apply (simp add:mask_out_sub_mask ucast_and_mask[symmetric])\n      apply (drule arg_cong[where f = unat])\n      apply (simp add:unat_ucast)\n      apply (subst (asm) mod_less)\n       apply (rule unat_less_helper)\n       apply (rule le_less_trans[OF word_and_le1])\n       apply (simp add:mask_def)\n      apply (simp add:unat_eq_0)\n      apply (drule(2) mask_neq_0[of _ _ _ _ pd_bits])\n       apply (simp add:pd_bits_def pageBits_def)+\n      done\n    have invalid_pteI:\n      \"\\<And>a pt x y z. \\<lbrakk>valid_pt_entries pt; (a && ~~ mask 4) \\<noteq> a;\n       pt (a && ~~ mask 4) = pte.LargePagePTE x y z \\<rbrakk>\n       \\<Longrightarrow> pt a = pte.InvalidPTE\"\n      apply (drule(1) valid_entriesD[rotated])\n      apply (case_tac \"pt a\"; simp add:mask_lower_twice is_aligned_neg_mask split:if_splits)\n      apply fastforce\n      done\n    have invalid_pdeI:\n      \"\\<And>a pd x y z. \\<lbrakk>valid_pd_entries pd; (a && ~~ mask 4) \\<noteq> a;\n       pd (a && ~~ mask 4) = pde.SuperSectionPDE x y z \\<rbrakk>\n       \\<Longrightarrow> pd a = pde.InvalidPDE\"\n      apply (drule(1) valid_entriesD[rotated])\n      apply (case_tac \"pd a\",\n        simp_all add:mask_lower_twice is_aligned_neg_mask\n        split:if_splits)\n      apply fastforce\n      done\n    have inj[simp]:\n      \"\\<And>p. is_aligned (p::word32) 6 \\<Longrightarrow> inj_on (\\<lambda>x. toEnum x * 4 + p) {Suc 0..<16}\"\n      apply (clarsimp simp:inj_on_def)\n      apply (subst (asm) shiftl_t2n[where n = 2,simplified field_simps,simplified,symmetric])+\n      apply (drule arg_cong[where f = \"\\<lambda>x. x >> 2\"])\n      apply (simp add:shiftl_shiftr_id word_of_nat_less)\n      apply (simp add:of_nat_inj)\n      done\n\n  show ?thesis\n  apply (rule name_pre)\n  apply (case_tac entries)\n   apply (case_tac a, case_tac aa)\n     apply (simp add:page_inv_entries_pre_def page_inv_entries_safe_def\n       | wp | intro conjI impI)+\n     apply (simp split:list.splits add:page_inv_entries_pre_def)+\n    apply (rename_tac obj_ref vm_attributes cap_rights slot slots)\n    apply (elim conjE exE)\n    apply (subst mapME_x_Cons)\n    apply simp\n    apply wp\n     apply (rule_tac Q' = \"\\<lambda>r s. \\<forall>x \\<in> set slots. obj_at\n                (\\<lambda>ko. \\<exists>pt. ko = ArchObj (PageTable pt) \\<and>\n                 pt (ucast (x && mask pt_bits >> 2)) = pte.InvalidPTE)\n                (hd (slot # slots) && ~~ mask pt_bits) s\" in hoare_post_imp_R)\n      apply (wp mapME_x_accumulate_checks[where Q = \"\\<lambda>s. valid_pdpt_objs s\"] )\n          apply (wp get_master_pte_wp| wpc | simp)+\n         apply clarsimp\n         apply (frule_tac x = xa in mask_out_same_pt)\n          apply (clarsimp simp:upto_enum_def upto_enum_step_def upto_0_to_n2)\n          apply (erule notE)\n          apply (subst shiftl_t2n[where n = 2,simplified field_simps,simplified,symmetric])\n          apply (rule shiftl_less_t2n[where m = 6,simplified])\n           apply (simp add:word_of_nat_less)\n          apply simp\n         apply (frule_tac x = z in mask_out_same_pt)\n          apply (clarsimp simp:upto_enum_def upto_enum_step_def upto_0_to_n2)\n         apply (clarsimp simp:field_simps obj_at_def\n           split:pte.splits)\n         apply (intro conjI impI)\n           apply (clarsimp)\n           apply (drule(1) valid_pdpt_objs_ptD)\n           apply (frule align_entry_ptD,simp)\n           apply (simp add:is_aligned_neg_mask_eq)\n          apply clarsimp\n          apply (drule(1) valid_pdpt_objs_ptD,clarify)\n          apply (erule(4) invalid_pteI[OF _ neq_pt_offset])\n         apply clarsimp\n         apply (drule(1) valid_pdpt_objs_ptD,clarify)\n         apply (frule align_entry_ptD,simp)\n         apply (simp add:is_aligned_neg_mask_eq)\n        apply (wp hoare_drop_imps |wpc|simp)+\n      apply (clarsimp simp:upto_enum_def upto_enum_step_def\n        upto_0_to_n2 Fun.comp_def distinct_map)\n     apply (intro exI conjI,fastforce+)\n     apply (simp add:obj_at_def hd_map_simp\n         upto_0_to_n2 upto_enum_def upto_enum_step_def)\n     apply (frule_tac x = 1 in bspec,fastforce+)\n    apply ((wp hoare_drop_imps |wpc|simp)+)[1]\n   apply (simp add:page_inv_entries_pre_def page_inv_entries_safe_def\n       | wp | intro conjI impI)+\n    apply (simp split:list.splits add:page_inv_entries_pre_def mapME_singleton)\n    apply (wp get_master_pte_wp |wpc | simp)+\n    apply (clarsimp simp:obj_at_def split:pte.splits)\n   apply (clarsimp simp:page_inv_entries_safe_def split:list.splits)\n  apply (simp split:list.splits add:page_inv_entries_pre_def mapME_singleton)\n  apply (case_tac b,case_tac a)\n     apply ((simp add:page_inv_entries_pre_def page_inv_entries_safe_def\n       | wp | intro conjI impI)+)[1]\n    apply simp\n    apply wp[1]\n   apply (simp split:list.splits add:page_inv_entries_pre_def mapME_singleton)\n   apply (wp get_master_pde_wp | wpc | simp)+\n   apply (clarsimp simp:obj_at_def page_inv_entries_safe_def\n     split:pde.splits)\n  apply (simp split:list.splits if_splits\n    add:page_inv_entries_pre_def Let_def page_inv_entries_safe_def)\n  apply (elim conjE exE)\n  apply (subst mapME_x_Cons)\n  apply simp\n  apply wp\n   apply (rule_tac Q' = \"\\<lambda>r s. \\<forall>x \\<in> set x22. obj_at\n       (\\<lambda>ko. \\<exists>pd. ko = ArchObj (PageDirectory pd) \\<and>\n       pd (ucast (x && mask pd_bits >> 2)) = pde.InvalidPDE)\n       (hd (x21 # x22) && ~~ mask pd_bits) s\" in hoare_post_imp_R)\n    apply (wp mapME_x_accumulate_checks[where Q = \"\\<lambda>s. valid_pdpt_objs s\"] )\n        apply (wp get_master_pde_wp| wpc | simp)+\n       apply clarsimp\n       apply (frule_tac x = xa in mask_out_same_pd)\n        apply (clarsimp simp:upto_enum_def upto_enum_step_def upto_0_to_n2)\n        apply (erule notE)\n        apply (subst shiftl_t2n[where n = 2,simplified field_simps,simplified,symmetric])\n        apply (rule shiftl_less_t2n[where m = 6,simplified])\n         apply (simp add:word_of_nat_less)\n        apply simp\n       apply (frule_tac x = z in mask_out_same_pd)\n        apply (clarsimp simp:upto_enum_def upto_enum_step_def upto_0_to_n2)\n       apply (clarsimp simp:field_simps obj_at_def\n           split:pde.splits)\n       apply (drule(1) valid_pdpt_objs_pdD)\n       apply (intro conjI impI)\n          apply clarsimp\n          apply (frule(1) align_entry_pdD)\n          apply (simp add:is_aligned_neg_mask_eq)\n         apply clarsimp\n         apply (frule(1) align_entry_pdD)\n         apply (simp add:is_aligned_neg_mask_eq)\n        apply clarsimp\n        apply (frule(1) align_entry_pdD)\n        apply (simp add:is_aligned_neg_mask_eq)\n       apply clarsimp\n       apply (erule(4) invalid_pdeI[OF _ neq_pd_offset])\n      apply (wp hoare_drop_imps |wpc|simp)+\n    apply (clarsimp simp:upto_enum_def upto_enum_step_def\n        upto_0_to_n2 Fun.comp_def distinct_map)\n   apply (intro exI conjI,fastforce+)\n   apply (simp add:obj_at_def hd_map_simp\n     upto_0_to_n2 upto_enum_def upto_enum_step_def)\n   apply (frule_tac x = 1 in bspec,fastforce+)\n  apply (wp get_master_pde_wp | simp | wpc)+\n  done\nqed\n\nlemma create_mapping_entries_safe[wp]:\n  \"\\<lbrace>\\<exists>\\<rhd>pd and K (vmsz_aligned vptr sz) and K (is_aligned pd pd_bits)\n          and K (vptr < kernel_base)\n          and valid_arch_objs and pspace_aligned and\n          (\\<exists>\\<rhd> (lookup_pd_slot pd vptr && ~~ mask pd_bits))\\<rbrace>\n      create_mapping_entries ptr vptr sz rights attrib pd\n   \\<lbrace>\\<lambda>entries. case entries of (Inl (SmallPagePTE _ _ _, [_])) \\<Rightarrow> \\<top>\n                  | (Inl (SmallPagePTE _ _ _, _)) \\<Rightarrow> \\<bottom>\n                  | (Inl (LargePagePTE _ _ _, [])) \\<Rightarrow> \\<bottom>\n                  | (Inr (SectionPDE _ _ _ _, [_])) \\<Rightarrow> \\<top>\n                  | (Inr (SectionPDE _ _ _ _, _)) \\<Rightarrow> \\<bottom>\n                  | (Inr (SuperSectionPDE _ _ _, [])) \\<Rightarrow> \\<bottom>\n                  | _ \\<Rightarrow> page_inv_entries_pre entries\\<rbrace>,-\"\n  apply (cases sz, simp_all)\n     defer 2\n     apply (wp | simp)+\n   apply (simp split:list.split)\n   apply (subgoal_tac \"lookup_pd_slot pd vptr \\<le> lookup_pd_slot pd vptr + 0x3C\")\n    apply (clarsimp simp:upto_enum_def not_less upto_enum_step_def\n      page_inv_entries_pre_def Let_def)\n    apply (clarsimp simp:upto_enum_step_def upto_enum_def\n                     map_eq_Cons_conv upt_eq_Cons_conv)\n    apply (drule_tac x = \"lookup_pd_slot pd vptr\" in spec)\n    apply (subst (asm) upto_0_to_n2)\n     apply simp\n    apply clarsimp\n    apply (drule lookup_pd_slot_aligned_6)\n     apply (simp add:pd_bits_def pageBits_def)\n    apply simp\n   apply clarsimp\n   apply (erule is_aligned_no_wrap'[OF lookup_pd_slot_aligned_6])\n    apply (simp add:pd_bits pageBits_def)\n   apply simp\n  apply (wp get_pde_wp | simp add:lookup_pt_slot_def | wpc)+\n  apply (clarsimp simp:upto_enum_def upto_enum_step_def\n    page_inv_entries_pre_def Let_def )\n  apply (drule_tac ref = refa in valid_arch_objsD)\n    apply (simp add:obj_at_def)\n   apply simp\n  apply (simp)\n  apply (drule_tac x = \"ucast (lookup_pd_slot pd vptr && mask pd_bits >> 2)\"\n    in bspec)\n   apply simp\n   apply (erule(1) less_kernel_base_mapping_slots)\n  apply (clarsimp simp:not_less[symmetric] split:list.splits)\n  apply (clarsimp simp:page_inv_entries_pre_def\n    Let_def upto_enum_step_def upto_enum_def)\n  apply (subst (asm) upto_0_to_n2)\n   apply simp\n  apply (clarsimp simp:not_less[symmetric])\n  apply (subgoal_tac\n    \"(\\<exists>xa xb. pda (ucast (lookup_pd_slot pd vptr && mask pd_bits >> 2))\n     = pde.PageTablePDE x xa xb)\n     \\<longrightarrow> is_aligned (ptrFromPAddr x + ((vptr >> 12) && 0xFF << 2)) 6\")\n   apply clarsimp\n   apply (subgoal_tac \"\n     ptrFromPAddr x + ((vptr >> 12) && 0xFF << 2) \\<le>\n     ptrFromPAddr x + ((vptr >> 12) && 0xFF << 2) + 0x3C\")\n    apply (clarsimp simp:not_less[symmetric])\n   apply (erule is_aligned_no_wrap')\n   apply simp\n  apply clarsimp\n  apply (rule aligned_add_aligned)\n    apply (erule(1) pt_aligned)\n   apply (rule is_aligned_shiftl[OF is_aligned_andI1])\n   apply (rule is_aligned_shiftr)\n   apply (simp add:vmsz_aligned_def)\n  apply simp\n  done\n\nlemma arch_decode_invocation_valid_pdpt[wp]:\n  notes find_pd_for_asid_inv[wp del]\n  shows\n  \"\\<lbrace>invs and valid_cap (cap.ArchObjectCap cap) and valid_pdpt_objs \\<rbrace>\n   arch_decode_invocation label args cap_index slot cap excaps\n   \\<lbrace>invocation_duplicates_valid o Invocations_A.InvokeArchObject\\<rbrace>,-\"\n  proof -\n    have bitwise:\"\\<And>a. (ucast (((a::word32) && ~~ mask 6) && mask 14 >> 2)::12 word)\n      = (ucast (a  && mask 14 >> 2)::12 word) && ~~ mask 4\"\n      apply (simp add:mask_def)\n      apply word_bitwise\n      done\n    have sz:\n      \"\\<And>vmpage_size. \\<lbrakk>args ! 0 + 2 ^ pageBitsForSize vmpage_size - 1 < kernel_base;\n        vmsz_aligned (args ! 0) vmpage_size\\<rbrakk>\n       \\<Longrightarrow> args ! 0 < kernel_base\"\n      apply (rule le_less_trans[OF is_aligned_no_overflow])\n       apply (simp add:vmsz_aligned_def)\n      apply simp\n      done\n  show ?thesis\n  apply (simp add: arch_decode_invocation_def\n              Let_def split_def get_master_pde_def\n              split del: if_split\n                   cong: arch_cap.case_cong if_cong cap.case_cong\n                         option.case_cong)\n  apply (rule hoare_pre)\n   apply ((wp get_pde_wp\n             ensure_safe_mapping_ensures[THEN hoare_post_imp_R]\n             create_mapping_entries_safe check_vp_wpR\n             find_pd_for_asid_aligned_pd_bits\n               [unfolded pd_bits_def pageBits_def,simplified]\n             | wpc\n             | simp add: invocation_duplicates_valid_def unlessE_def whenE_def\n                         pti_duplicates_valid_def page_inv_duplicates_valid_def\n                         mask_lower_twice pd_bits_def bitwise pageBits_def\n                         not_le sz\n                    del: hoare_True_E_R\n                     split del: if_split\n             | simp only: obj_at_def)+)\n         apply (rule_tac Q'=\"\\<lambda>rv. \\<exists>\\<rhd> rv and K (is_aligned rv pd_bits) and\n                  (\\<exists>\\<rhd> (lookup_pd_slot rv (args ! 0) && ~~ mask pd_bits)) and\n                     valid_arch_objs and pspace_aligned and valid_pdpt_objs\"\n                     and f=\"find_pd_for_asid p\" for p\n                    in hoare_post_imp_R)\n          apply (wp| simp)+\n         apply (fastforce simp:pd_bits_def pageBits_def)\n        apply ((wp get_pde_wp\n             ensure_safe_mapping_ensures[THEN hoare_post_imp_R]\n             create_mapping_entries_safe check_vp_wpR\n             find_pd_for_asid_aligned_pd_bits\n               [unfolded pd_bits_def pageBits_def,simplified]\n             | wpc\n             | simp add: invocation_duplicates_valid_def unlessE_def whenE_def\n                         pti_duplicates_valid_def page_inv_duplicates_valid_def\n                         mask_lower_twice pd_bits_def bitwise pageBits_def\n                         not_le sz\n                    del: hoare_True_E_R\n                     split del: if_split\n             | simp only: obj_at_def)+)\n         apply (rule_tac Q'=\"\\<lambda>rv. \\<exists>\\<rhd> rv and K (is_aligned rv pd_bits) and\n                  (\\<exists>\\<rhd> (lookup_pd_slot rv (snd pa) && ~~ mask pd_bits)) and\n                     valid_arch_objs and pspace_aligned and valid_pdpt_objs and\n                     K ((snd pa) < kernel_base)\"\n                     and f=\"find_pd_for_asid p\" for p\n                    in hoare_post_imp_R)\n          apply (wp| simp)+\n         apply (auto simp:pd_bits_def pageBits_def)[1]\n        apply ((wp get_pde_wp\n             ensure_safe_mapping_ensures[THEN hoare_post_imp_R]\n             create_mapping_entries_safe check_vp_wpR\n             find_pd_for_asid_aligned_pd_bits\n               [unfolded pd_bits_def pageBits_def,simplified]\n             | wpc\n             | simp add: invocation_duplicates_valid_def unlessE_def whenE_def\n                         pti_duplicates_valid_def page_inv_duplicates_valid_def\n                         mask_lower_twice pd_bits_def bitwise pageBits_def\n                         not_le sz\n                    del: hoare_True_E_R\n                     split del: if_split\n             | simp only: obj_at_def)+)\n         apply (rule hoare_post_imp_R[where P=\\<top>])\n          apply (rule hoare_True_E_R)\n         apply auto[1]\n        apply ((wp\n             | wpc\n             | simp add: invocation_duplicates_valid_def unlessE_def whenE_def\n                         pti_duplicates_valid_def page_inv_duplicates_valid_def\n                     del: hoare_True_E_R\n                     split del: if_split\n             | simp only: obj_at_def)+)\n  apply (auto simp:valid_cap_simps)\n  done\nqed\n\nlemma decode_invocation_valid_pdpt[wp]:\n  \"\\<lbrace>invs and valid_cap cap and valid_pdpt_objs\\<rbrace> decode_invocation label args cap_index slot cap excaps\n   \\<lbrace>invocation_duplicates_valid\\<rbrace>,-\"\n  apply (simp add: decode_invocation_def split del: if_split)\n  apply (rule hoare_pre)\n   apply (wp | wpc\n            | simp only: invocation_duplicates_valid_def o_def uncurry_def split_def\n                         Invocations_A.invocation.simps)+\n  apply clarsimp\n  done\n\ncrunch valid_pdpt_objs[wp]: handle_fault, reply_from_kernel \"valid_pdpt_objs\"\n  (simp: crunch_simps wp: crunch_wps)\n\n\nlemma invocation_duplicates_valid_exst_update[simp]:\n  \"invocation_duplicates_valid i (trans_state f s) = invocation_duplicates_valid i s\"\n  apply (clarsimp simp add: invocation_duplicates_valid_def pti_duplicates_valid_def page_inv_duplicates_valid_def page_inv_entries_safe_def split: sum.splits invocation.splits arch_invocation.splits kernel_object.splits page_table_invocation.splits page_invocation.splits)+\n  done\n\n\nlemma set_thread_state_duplicates_valid[wp]:\n  \"\\<lbrace>invocation_duplicates_valid i\\<rbrace> set_thread_state t st \\<lbrace>\\<lambda>rv. invocation_duplicates_valid i\\<rbrace>\"\n  apply (simp add: set_thread_state_def set_object_def)\n  apply (wp|simp)+\n  apply (clarsimp simp: invocation_duplicates_valid_def pti_duplicates_valid_def\n                        page_inv_duplicates_valid_def page_inv_entries_safe_def\n                        Let_def\n                 dest!: get_tcb_SomeD\n                 split: Invocations_A.invocation.split arch_invocation.split_asm\n                        page_table_invocation.split\n                        page_invocation.split sum.split\n                        )\n  apply (auto simp add: obj_at_def page_inv_entries_safe_def)\n  done\n\nlemma handle_invocation_valid_pdpt[wp]:\n  \"\\<lbrace>valid_pdpt_objs and invs and ct_active\\<rbrace>\n        handle_invocation calling blocking \\<lbrace>\\<lambda>rv. valid_pdpt_objs\\<rbrace>\"\n  apply (simp add: handle_invocation_def)\n  apply (wp syscall_valid set_thread_state_ct_st\n               | simp add: split_def | wpc\n               | wp_once hoare_drop_imps)+\n  apply (auto simp: ct_in_state_def elim: st_tcb_ex_cap)\n  done\n\n\ncrunch valid_pdpt[wp]: handle_event, activate_thread,switch_to_thread,\n       switch_to_idle_thread \"valid_pdpt_objs\"\n  (simp: crunch_simps wp: crunch_wps alternative_valid select_wp OR_choice_weak_wp select_ext_weak_wp\n      ignore: without_preemption getActiveIRQ resetTimer ackInterrupt\n              getFAR getDFSR getIFSR OR_choice set_scheduler_action\n              clearExMonitor)\n\nlemma schedule_valid_pdpt[wp]: \"\\<lbrace>valid_pdpt_objs\\<rbrace> schedule :: (unit,unit) s_monad \\<lbrace>\\<lambda>_. valid_pdpt_objs\\<rbrace>\"\n  apply (simp add: schedule_def allActiveTCBs_def)\n  apply (wp alternative_wp select_wp)\n  apply simp\n  done\n\nlemma call_kernel_valid_pdpt[wp]:\n  \"\\<lbrace>invs and (\\<lambda>s. e \\<noteq> Interrupt \\<longrightarrow> ct_running s) and valid_pdpt_objs\\<rbrace>\n      (call_kernel e) :: (unit,unit) s_monad\n   \\<lbrace>\\<lambda>_. valid_pdpt_objs\\<rbrace>\"\n  apply (cases e, simp_all add: call_kernel_def)\n      apply (rule hoare_pre)\n       apply (wp | simp | wpc\n                 | rule conjI | clarsimp simp: ct_in_state_def\n                 | erule pred_tcb_weakenE\n                 | wp_once hoare_drop_imps)+\n  done\n\nend\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/l4v/proof/invariant-abstract/ARM/ArchVSpaceEntries_AI.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6893056295505783, "lm_q2_score": 0.41869690935568665, "lm_q1q2_score": 0.288610136694303}}
{"text": "section \"Implementation Language with Loops\"\ntheory impl_language_loops\n  imports Main \n    \"HOL-Library.Monad_Syntax\"\n    repliss_sem\n    ZFC_utils\n    \"fuzzyrule.fuzzy_goal_cases\"\nbegin\n\ntext \"We need to hide some ZFC constants so that the normal ones are still visible:\"\n\nhide_const (open) \"ZFC_in_HOL.set\"\n\n\n\ntext \"So far, we have assumed that procedure implementations are given by arbitrary state machines.\nHere we define an implementation language using a shallow embedding with the monad syntax package.\n\"\n\n\ntext_raw \\<open>\\DefineSnippet{io_defs_types}{\\<close>\ntype_synonym iref = nat\ntype_synonym 'v store = \"iref \\<rightharpoonup> 'v\"\ntext_raw \\<open>}%EndSnippet\\<close>\n\ndatatype 'a ref = Ref (iref:iref)\ninstantiation ref :: (type) small begin\ninstance proof\n  obtain V_of :: \"nat \\<Rightarrow> V\" and A :: \"V\" where \"inj V_of\" and \"range V_of \\<subseteq> elts A\"\n    by (metis infinite_\\<omega> infinite_countable_subset)\n                    \n\n  have \"\\<exists>(V_of::'a ref \\<Rightarrow> V) A. inj V_of \\<and> range V_of \\<subseteq> elts A\"\n  proof (intro conjI exI)\n    show \"inj (V_of \\<circ> iref)\"\n      by (metis (mono_tags, lifting) \\<open>inj V_of\\<close> comp_apply injD inj_on_def ref.expand)\n\n    show \" range (V_of \\<circ> iref) \\<subseteq> elts A\"\n      using \\<open>range V_of \\<subseteq> elts A\\<close> by auto\n  qed\n\n  show \"small (UNIV::'a ref set)\"\n    by (meson \\<open>\\<exists>V_of A. inj V_of \\<and> range V_of \\<subseteq> elts A\\<close> down small_image_iff)\n\nqed\nend\n\ntext \\<open>The typeclass natConvert is the dual to the typeclass countable. \nA natConvert type is at least as big as the natural numbers, so any natural number can be converted \nto the type using fromNat.\n\\<close>\nclass natConvert =\n  fixes fromNat :: \"nat \\<Rightarrow> 'a\"\n  assumes fromNat_inj: \"inj fromNat\"\n\ndefinition \"toNat \\<equiv> the_inv fromNat\"\n\nlemma \"toNat (fromNat x) = x\"\n  by (simp add: fromNat_inj the_inv_f_f toNat_def)\n\ninstantiation ref :: (type) natConvert begin\ndefinition [simp]: \"fromNat_ref = Ref\"\ninstance \n  apply standard\n  using injI by fastforce\nend\n\n\ndatatype ('c,'b) loopResult = Continue 'c | Break 'b\n\ntext_raw \\<open>\\DefineSnippet{io_defs_datatype}{\\<close>\ndatatype ('a,'op, 'any) io =\n    WaitLocalStep \"'any store \\<Rightarrow> bool \\<times> 'any store \\<times> ('a,'op, 'any) io\"\n  | WaitBeginAtomic \"('a,'op, 'any) io\"\n  | WaitEndAtomic \"('a,'op, 'any) io\"\n  | WaitNewId \"'any \\<Rightarrow> bool\" \"'any \\<Rightarrow> ('a,'op, 'any) io\"\n  | WaitDbOperation 'op \"'any \\<Rightarrow> ('a,'op, 'any) io\"\n  | WaitReturn \"'a\" \n  | Loop 'any \"V\" \"'any \\<Rightarrow> ('a,'op, 'any) io\" \ntext_raw \\<open>}%EndSnippet\\<close>\n\n\\<comment> \\<open>body is an @{typ \\<open>'any \\<Rightarrow> (('any,'any) loopResult, 'op, 'any) io\\<close>} encoded a type V.\n                                            Had to use dynamic typing here as Isabelle has no GADTs. \\<close>\n\n\n\ntext \"Actually show that we can embedd io into ZFCs V type:\"\n\n\n\nfunction (domintros) io_to_V :: \"('a::embeddable,'op::embeddable, 'any::small) io \\<Rightarrow> V\" where\n  \"io_to_V (WaitLocalStep n)  = to_V (0::nat, to_V (\\<lambda>s. let (a,b,c) = n s in to_V (a, b, io_to_V c)))\"\n| \"io_to_V (WaitBeginAtomic n)  =  to_V (1::nat, io_to_V n)\"\n| \"io_to_V (WaitEndAtomic n)  = to_V (2::nat, io_to_V n) \"\n| \"io_to_V (WaitNewId P n)  =  to_V (3::nat, to_V (P, (\\<lambda>x. io_to_V (n x))))\"\n| \"io_to_V (WaitDbOperation op n)  =  to_V (4::nat, to_V (op, (\\<lambda>x. io_to_V (n x))))\"\n| \"io_to_V (WaitReturn s)  =  to_V (5::nat, to_V s)\"\n| \"io_to_V (Loop i body n)  =  to_V (6::nat, to_V (i, body, (\\<lambda>x. io_to_V (n x))))\"\n  by (pat_completeness, auto)\ntermination\nproof auto\n  show \"io_to_V_dom x\" for x\n    apply (induct x, auto simp add: io_to_V.domintros)\n    by (metis io_to_V.domintros(1) range_eqI)\nqed\n\n\nlemma fun_cong2: \"f = g \\<Longrightarrow> \\<forall>x. f x = g x\"\n  by simp\n\n\n\nlemma io_to_V_inj: \"inj io_to_V\"\nproof\n  fix x y :: \"('a::embeddable,'op::embeddable, 'any::small) io\"\n  assume a0: \"x \\<in> UNIV\"\n    and a1: \"y \\<in> UNIV\"\n    and a2: \"io_to_V x = io_to_V y\"\n\n  from `io_to_V x = io_to_V y`\n  show \"x = y\"\n  proof (induct x arbitrary: y)\n    case (WaitLocalStep a y)\n    show ?case\n    proof (cases y)\n      fix c\n      assume \" y = WaitLocalStep c\"\n      hence h: \"io_to_V (WaitLocalStep a) = io_to_V (WaitLocalStep c)\"\n        using WaitLocalStep.prems by blast\n      from h have eq1: \"fst (a x) = fst (c x)\" for x\n        by (auto dest!: to_V_use_inj fun_cong[where x=x] split: prod.splits)\n      from h have eq2: \"fst (snd (a x)) = fst (snd (c x))\" for x\n        by (auto dest!: to_V_use_inj fun_cong[where x=x] split: prod.splits)\n\n      from h have \"io_to_V (snd (snd (a x))) = io_to_V (snd (snd (c x)))\" for x\n        by (auto dest!: to_V_use_inj fun_cong[where x=x] split: prod.splits)\n      have eq3: \"snd (snd (a x)) = snd (snd (c x))\" for x\n\n      proof (rule WaitLocalStep)\n        show \"io_to_V (snd (snd (a x))) = io_to_V (snd (snd (c x)))\"\n          using `io_to_V (snd (snd (a x))) = io_to_V (snd (snd (c x)))` .\n\n        show \"snd (snd (a x)) \\<in> Basic_BNFs.snds (snd (a x))\"\n          by (simp add: snds.simps)\n\n        show \"snd (a x) \\<in> Basic_BNFs.snds (a x)\"\n          by (simp add: snds.intros)\n\n        show \" a x \\<in> range a\"\n          by blast\n      qed\n\n      have \"a = c\"\n        by (auto simp add: prod_eq_iff eq1 eq2 eq3)\n\n      thus \" WaitLocalStep a = y\"\n        using `y = WaitLocalStep c` by simp\n    next\n    qed (insert `io_to_V (WaitLocalStep a) = io_to_V y`, auto dest!: to_V_use_inj)\n  next\n    case (WaitBeginAtomic a)\n     thus ?case by (cases y, auto dest!: to_V_use_inj)\n  next\n    case (WaitEndAtomic a)\n    thus ?case by (cases y, auto dest!: to_V_use_inj)\n  next\n    case (WaitNewId a b)\n    thus ?case \n      by (cases y, auto dest!: to_V_use_inj, meson HOL.ext rangeI)\n  next\n    case (WaitDbOperation a b)\n     thus ?case by (cases y, auto dest!: to_V_use_inj, meson HOL.ext rangeI)\n  next\n    case (WaitReturn r)\n     thus ?case by (cases y, auto dest!: to_V_use_inj)\n  next\n    case (Loop i bdy cont)\n    thus ?case proof (cases y, auto dest!: to_V_use_inj, rename_tac cont')\n      fix cont'\n      assume a0: \"y = Loop i bdy cont'\"\n        and IH: \"\\<And>x3aa y. \\<lbrakk>x3aa \\<in> range cont; io_to_V x3aa = io_to_V y\\<rbrakk> \\<Longrightarrow> x3aa = y\"\n        and a2: \"(\\<lambda>x. io_to_V (cont x)) = (\\<lambda>x. io_to_V (cont' x))\"\n        and a3: \"io_to_V (Loop i bdy cont) = io_to_V y\"\n\n      from a2\n      have \"io_to_V (cont x) = io_to_V (cont' x)\" for x\n        by meson\n      hence \"(cont x) = (cont' x)\" for x\n        by (simp add: IH rangeI)\n      thus \"cont = cont' \"\n        by blast\n    qed\n  qed\nqed\n\n\n\ninstance io :: (embeddable, embeddable, small) embeddable\n  by (standard, force intro: io_to_V_inj)\n\ndefinition loopResult_to_V :: \"('a::embeddable, 'b::embeddable) loopResult \\<Rightarrow> V\" where\n  \"loopResult_to_V l = (case l of \n    (Break x) \\<Rightarrow> to_V (False, x, undefined::'a)\n  | (Continue x) \\<Rightarrow> to_V (True, undefined::'b, x))\"\n\n\nlemma loopResult_to_V_inj: \"inj loopResult_to_V\"\n  by standard (use to_V_use_inj in \\<open>auto simp add: loopResult_to_V_def  split: loopResult.splits\\<close>)\n\n\n\ninstance loopResult :: (embeddable, embeddable) embeddable\n  by (standard, force intro: loopResult_to_V_inj)\n\n\ninstance loopResult :: (small, small) small\nproof (rule show_small_type_class, intro conjI exI)\n\n  have \"\\<exists>(f::'a \\<Rightarrow> V). inj f \\<and>   small (range f)\"\n    using small down to_V_property to_V_small by blast\n\n  show \"inj loopResult_to_V\"\n    by (simp add: loopResult_to_V_inj)\n\n  have \"small (range (to_V :: (bool\\<times>'b\\<times>'a)\\<Rightarrow>V))\"\n    using to_V_small by blast\n\n\n  thus \"small (range (loopResult_to_V::('a,'b) loopResult\\<Rightarrow>V))\"\n  proof (rule smaller_than_small)\n\n    show \"range (loopResult_to_V::('a,'b)  loopResult\\<Rightarrow>V) \\<subseteq>range (to_V :: (bool\\<times>'b\\<times>'a)\\<Rightarrow>V)\"\n      by (auto simp add: loopResult_to_V_def split: loopResult.splits)\n  qed\nqed\n\ndefinition loop_body_from_V :: \"V \\<Rightarrow> 'any \\<Rightarrow> (('any,'any) loopResult, 'op::embeddable, 'any::small) io\" where\n\"loop_body_from_V \\<equiv> from_V\"\n\ndefinition loop_body_to_V :: \"('any \\<Rightarrow> (('any,'any) loopResult, 'op::embeddable, 'any::small) io) \\<Rightarrow> V\" where\n\"loop_body_to_V \\<equiv> to_V\"\n\nlemma loop_body_from_V_rev[simp]: \"loop_body_from_V (loop_body_to_V x) = x\"\n  by (simp add: loop_body_from_V_def loop_body_to_V_def)\n\n\ntext_raw \\<open>\\DefineSnippet{io_defs_bind}{\\<close>\nfunction (*<*) (domintros) (*>*) bind (*<*) :: \"('a, 'op, 'any) io \\<Rightarrow> ('a \\<Rightarrow> ('b, 'op,'any) io) \\<Rightarrow> ('b, 'op,'any) io\" (*>*) (infixl \"\\<bind>io\" 54)  where\n  \"WaitLocalStep n \\<bind>io f = (WaitLocalStep (\\<lambda>s. let (a,b,c) = n s  \n                                                  in (a, b, bind c f)))\"\n| \"WaitBeginAtomic n \\<bind>io f = (WaitBeginAtomic (n \\<bind>io f))\"\n| \"WaitEndAtomic n \\<bind>io f = (WaitEndAtomic (n \\<bind>io f))\"\n| \"WaitNewId P n \\<bind>io f = (WaitNewId P (\\<lambda>i. n i \\<bind>io f))\"\n| \"WaitDbOperation op n \\<bind>io f = (WaitDbOperation op (\\<lambda>i. n i \\<bind>io f))\"\n| \"WaitReturn s \\<bind>io f = (f s)\"\n| \"Loop i body n \\<bind>io f = (Loop i body (\\<lambda>x. n x \\<bind>io f))\"\ntext_raw \\<open>}%EndSnippet\\<close>\n  by (pat_completeness, auto)\ntermination\n  using [[show_sorts]]\nproof auto\n  show \"bind_dom (i, f)\" for i :: \"('a, 'op, 'any) io\" and f :: \"'a \\<Rightarrow> ('d, 'op, 'any) io\"\n    apply (induct i, auto simp add: bind.domintros)\n    by (metis bind.domintros(1) range_eqI)\nqed\n\n\n\n\n\ntext_raw \\<open>\\DefineSnippet{toImpl}{\\<close>\nfun toImpl :: \"(('val store \\<times> uniqueId set \\<times> (('val,'op::{small,valueType}, 'val::{small,valueType}) io)), 'op, 'val) procedureImpl\" where\n  \"toImpl (store, knownUids, WaitLocalStep n) = (\n        let (ok, store', n') = n store \n        in LocalStep (ok \\<and> (finite (dom store) \\<longrightarrow> finite (dom (store')))) \n                      (store', knownUids, n'))\"\n| \"toImpl (store, knownUids, WaitBeginAtomic n) = \n        BeginAtomic (store, knownUids, n)\"\n| \"toImpl (store, knownUids, WaitEndAtomic n) = \n        EndAtomic (store, knownUids,  n)\"\n| \"toImpl (store, knownUids, WaitNewId P n) = \n        NewId (\\<lambda>i. if P i then Some (store, knownUids \\<union> uniqueIds i,  n i) else None)\"\n| \"toImpl (store, knownUids, WaitDbOperation op n) = (\n        if uniqueIds op \\<subseteq> knownUids then \n          DbOperation op (\\<lambda>r. (store, knownUids \\<union> uniqueIds r, n r)) \n        else \n          LocalStep False (store, knownUids, WaitDbOperation op n))\"\n| \"toImpl (store, knownUids, WaitReturn v) = (\n        if uniqueIds v \\<subseteq> knownUids then \n          Return v \n        else \n          LocalStep False (store, knownUids, WaitReturn v))\"\n| \"toImpl (store, knownUids, Loop i body n) = \n        LocalStep True \n            (store, knownUids, (loop_body_from_V body i) \\<bind>io (\\<lambda>r. \n               case r of Break x \\<Rightarrow> n x \n| Continue x \\<Rightarrow> Loop x body n))\"\ntext_raw \\<open>}%EndSnippet\\<close>\n\n\ntext \\<open>\\DefineSnippet{toImpl_simps}{\n  @{thm [display] toImpl.simps}\n}%EndSnippet\\<close>\n\nabbreviation  toImpl' where\n \"toImpl' proc (x :: ('val,'op,'val) io) \\<equiv> ((Map.empty, uniqueIds proc, x) , toImpl)\"\n\n\nadhoc_overloading Monad_Syntax.bind bind\n\ndefinition pause :: \"(unit,'op,'any) io\" where\n\"pause \\<equiv> WaitLocalStep (\\<lambda>s. (True, s, WaitReturn ()))\"\n\ndefinition beginAtomic :: \"(unit,'op,'any) io\" where\n\"beginAtomic \\<equiv> WaitBeginAtomic (WaitReturn ())\"\n\ndefinition endAtomic :: \"(unit,'op,'any) io\" where\n\"endAtomic \\<equiv> WaitEndAtomic (WaitReturn ())\"\n\n\ndefinition newId :: \"('any \\<Rightarrow> bool) \\<Rightarrow> ('any,'op,'any) io\" where\n\"newId P \\<equiv> WaitNewId P (\\<lambda>i. WaitReturn i)\"\n\ndefinition call :: \"'op \\<Rightarrow> ('any,'op,'any) io\" where\n\"call op \\<equiv> WaitDbOperation op (\\<lambda>i. WaitReturn i)\"\n\ndefinition return :: \"'a  \\<Rightarrow> ('a,'op, 'any) io\" where\n\"return x \\<equiv> WaitReturn x\"\n\n\ndefinition atomic ::\"('a,'op, 'any) io \\<Rightarrow> ('a,'op, 'any) io\"  where\n\"atomic f \\<equiv> do {\n  beginAtomic;\n  r \\<leftarrow> f;\n  endAtomic;\n  return r\n}\"\n\n\ndefinition \n\"skip \\<equiv> return default\"\n\n\n\ntext \"Next, we define some operations to work with references: \nWe simply encode references using natural numbers.\"\n\ndefinition \"fromAny x \\<equiv> from_nat (toNat x)\"\ndefinition \"intoAny x \\<equiv> fromNat (to_nat x)\"\n\nlemma fromAny_intoAny[simp]: \"fromAny (intoAny x) = x\"\n  by (simp add: fromAny_def fromNat_inj intoAny_def the_inv_f_f toNat_def)\n\ndefinition freshRefH :: \"nat \\<Rightarrow> nat set \\<Rightarrow> nat\" where\n\"freshRefH mi D \\<equiv> (if finite D then LEAST x. x \\<ge> mi \\<and> (\\<forall>y\\<in>D. x>y) else 0)\"\n\nabbreviation freshRef :: \"nat set \\<Rightarrow> nat\" where\n\"freshRef \\<equiv> freshRefH 0\"\n\n\nlemma freshRef_empty[simp]: \"freshRefH x {} = x\"\n  by (auto simp add: freshRefH_def Least_equality)\n\nlemma freshRef_insert[simp]: \n\"freshRefH mi (insert x S) = freshRefH (max mi (Suc x)) S\"\n  by (auto simp add: freshRefH_def intro!: arg_cong[where f=Least])\n  \n\ndefinition makeRef :: \"'a::countable \\<Rightarrow> ('a ref, 'op, 'any::natConvert) io\" where\n\"makeRef v \\<equiv> WaitLocalStep (\\<lambda>s. let r = freshRef (dom s) in (True, s(r \\<mapsto> intoAny v), WaitReturn (Ref r)))\"\n\ndefinition s_read :: \"('any::natConvert) store \\<Rightarrow> ('a::countable) ref \\<Rightarrow> 'a\" where\n\"s_read s ref \\<equiv> \n    case s (iref ref) of \n      Some v \\<Rightarrow> fromAny v \n    | None  \\<Rightarrow> from_nat 0\"\n\ndefinition read :: \"'a ref \\<Rightarrow> ('a::countable, 'op, 'any::natConvert) io\" where\n\"read ref \\<equiv> WaitLocalStep (\\<lambda>s. case s (iref ref) of \n      Some v \\<Rightarrow> (True, s, WaitReturn (fromAny v)) \n    | None  \\<Rightarrow> (False, s, WaitReturn (from_nat 0)))\"\n\ndefinition assign :: \"('a::countable) ref \\<Rightarrow> 'a \\<Rightarrow> (unit, 'op, 'any::natConvert) io\" (infix \":\\<leftarrow>\" 60) where\n\"assign ref v \\<equiv> WaitLocalStep (\\<lambda>s. case s (iref ref) of \n    Some _ \\<Rightarrow> (True, s((iref ref) \\<mapsto> intoAny v), WaitReturn ()) \n  | None  \\<Rightarrow> (False, s, WaitReturn ())) \"\n\ndefinition update :: \"('a::countable) ref \\<Rightarrow> ('a \\<Rightarrow> 'a) \\<Rightarrow> (unit, 'op, 'any::natConvert) io\" where\n\"update ref upd \\<equiv> WaitLocalStep (\\<lambda>s. case s (iref ref) of \n      Some v \\<Rightarrow> (True, s((iref ref) \\<mapsto> intoAny (upd (fromAny v))), WaitReturn ()) \n    | None  \\<Rightarrow> (False, s, WaitReturn ())) \"\n\n\n\n\nlemma toImpl_simps_newId[simp]:\n\"toImpl (store, u, newId P) = NewId (\\<lambda>i. if P i then Some (store, u \\<union> uniqueIds i, return i) else None)\"\nby (auto simp add: newId_def pause_def beginAtomic_def endAtomic_def call_def return_def intro!: ext split: io.splits)\nlemma toImpl_simps_pause[simp]:\n\"toImpl (store, u, pause) = LocalStep True (store, u, return ())\"\nby (auto simp add: newId_def pause_def beginAtomic_def endAtomic_def call_def return_def intro!: ext split: io.splits)\nlemma toImpl_simps_beginAtomic[simp]:\n\"toImpl (store, u, beginAtomic) = BeginAtomic (store, u, return ())\"\nby (auto simp add: newId_def pause_def beginAtomic_def endAtomic_def call_def return_def intro!: ext split: io.splits)\nlemma toImpl_simps_endAtomic[simp]:\n\"toImpl (store, u, endAtomic) = EndAtomic (store, u, return ())\"\nby (auto simp add: newId_def pause_def beginAtomic_def endAtomic_def call_def return_def intro!: ext split: io.splits)\nlemma toImpl_simps_call[simp]:\n   \"toImpl (store, u, call op ) = (if uniqueIds op \\<subseteq> u then DbOperation op  (\\<lambda>r. (store, u \\<union> uniqueIds r, return r)) else LocalStep False (store, u, call op))\"\n  by (auto simp add: newId_def pause_def beginAtomic_def endAtomic_def call_def return_def intro!: HOL.ext split: io.splits)\nlemma toImpl_simps_return[simp]:\n  \"toImpl (store, u, return x) = (if uniqueIds x \\<subseteq> u then Return x else LocalStep False (store, u, return x))\"\n  by (auto simp add: newId_def pause_def beginAtomic_def endAtomic_def call_def return_def intro!: ext split: io.splits)\n\nschematic_goal \"toImpl (store, u, newId P \\<bind> x) = ?x\"\n by (auto simp add: newId_def pause_def beginAtomic_def endAtomic_def call_def intro!: ext split: io.splits)\n\n\nlemma toImpl_bind_simps_newid[simp]:\n\"toImpl (store, u, newId P \\<bind> x) = NewId (\\<lambda>i. if P i then Some (store, u \\<union> uniqueIds i, x i) else None)\"\n  by (auto simp add: newId_def pause_def beginAtomic_def endAtomic_def call_def intro!: ext split: io.splits)\n\nlemma toImpl_bind_simps_pause[simp]:\n\"toImpl (store, u, pause \\<bind> x) = LocalStep True (store, u, x ())\"\n  by (auto simp add: newId_def pause_def beginAtomic_def endAtomic_def call_def intro!: ext split: io.splits)\n\nlemma toImpl_bind_simps_beginAtomic[simp]:\n\"toImpl (store, u, beginAtomic \\<bind> x) = BeginAtomic (store, u, x ())\"\n  by (auto simp add: newId_def pause_def beginAtomic_def endAtomic_def call_def intro!: ext split: io.splits)\n\nlemma toImpl_bind_simps_endAtomic[simp]:\n\" toImpl (store, u, endAtomic \\<bind> x) = EndAtomic (store, u, x ())\"\n  by (auto simp add: newId_def pause_def beginAtomic_def endAtomic_def call_def intro!: ext split: io.splits)\n\nlemma toImpl_bind_simps_call[simp]:\n\"toImpl (store, u, call op  \\<bind> x) = (if uniqueIds op \\<subseteq> u then DbOperation op  (\\<lambda>r. (store, u \\<union> uniqueIds r, x r)) else LocalStep False (store, u, call op  \\<bind> x))\"\n  by (auto simp add: newId_def pause_def beginAtomic_def endAtomic_def call_def intro!: ext split: io.splits)\n\n\n\nparagraph \"Monad Laws\"\n\ntext \"We prove the typical monad laws: identity of return and associativity.\"\n\ndeclare Basic_BNFs.snds.simps[simp]\ndeclare Basic_BNFs.fsts.simps[simp]\n\n\nlemma return_left_ident[simp]: \n  fixes x and f :: \"'a \\<Rightarrow> ('b,'op, 'any) io\"\n  shows \"return x \\<bind> f = f x\"\n  by (auto simp add: return_def)\n\nlemma right_ident[simp]: \n  fixes m :: \"('a,'op, 'any) io\"\n  shows \"(m \\<bind> return) = m\"\nproof (induct m)\n  case (WaitLocalStep x)\n  then show ?case \n    by (auto simp add: return_def intro!: HOL.ext   split: prod.splits, metis range_eqI)\nnext\n  case (WaitBeginAtomic m)\n  then show ?case  by (auto simp add: return_def)\nnext\n  case (WaitEndAtomic m)\n  then show ?case  by (auto simp add: return_def)\nnext\n  case (WaitNewId x1a x2a)\n  then show ?case  by (auto simp add: return_def)\nnext\n  case (WaitDbOperation x1a x2a)\n  then show ?case  by (auto simp add: return_def)\nnext\n  case (WaitReturn x)\n  then show ?case  by (auto simp add: return_def)\nnext\n  case (Loop x1a m)\n  then show ?case  by (auto simp add: return_def)\nqed\n\n\nlemma bind_assoc[simp]: \n  fixes x :: \"('a,'op, 'any) io\"\n    and y :: \"'a \\<Rightarrow> ('b,'op, 'any) io\"\n    and z :: \"'b \\<Rightarrow> ('c,'op, 'any) io\"\n  shows \"((x \\<bind> y) \\<bind> z) = (x \\<bind> (\\<lambda>a. y a \\<bind> z))\"\nproof (induct x)\n  case (WaitLocalStep x)\n  then show ?case \n    by (auto simp add: return_def intro!: HOL.ext   split: prod.splits, metis rangeI)\nnext\n  case (WaitBeginAtomic x)\n  then show ?case  by auto\nnext\n  case (WaitEndAtomic x)\n  then show ?case  by auto\nnext\n  case (WaitNewId x1a x2a)\n  then show ?case  by auto\nnext\n  case (WaitDbOperation x1a x2a)\n  then show ?case  by auto\nnext\n  case (WaitReturn x)\n  then show ?case  by auto\nnext\n  case (Loop x1a x)\n  then show ?case  by auto\nqed\n\n\n text \\<open>\n \\DefineSnippet{io_bind_monad_rules}{\n    @{thm [display] return_left_ident}\n    @{thm [display] right_ident}\n    @{thm [display] bind_assoc}\n }%EndSnippet\n \\<close>\n\n\n\nlemma atomic_simp1[simp]: \n\"toImpl (s, u, atomic f) = BeginAtomic (s, u, f \\<bind> (\\<lambda>r. endAtomic \\<bind> (\\<lambda>_. return r)))\"\n  by (auto simp add: atomic_def)\n\nlemma atomic_simp2[simp]: \n\"toImpl (s, u, atomic f \\<bind> x) = BeginAtomic (s, u, f \\<bind> (\\<lambda>a. endAtomic \\<bind> (\\<lambda>b. x a)))\"\n  by (auto simp add: atomic_def)\n\n\nsubsection \"Syntactic sugar for loops\"\n\ndefinition loop :: \"'a::countable \\<Rightarrow> ('a \\<Rightarrow> (('a,'b::countable) loopResult, 'op::small, 'any::{small,natConvert} ) io) \\<Rightarrow> ('b, 'op, 'any) io\" where\n\"loop init body \\<equiv> Loop \n      (intoAny init)\n      (loop_body_to_V (\\<lambda>acc. \n          body (fromAny acc) \\<bind>io (\\<lambda>res. return (\n            case res of Continue x \\<Rightarrow> (Continue (intoAny x)) \n                      | Break x \\<Rightarrow> (Break (intoAny x)))))) \n      (return \\<circ> fromAny)\"\n\n\ndefinition while :: \"(bool, 'op::small, 'any::small) io \\<Rightarrow> (unit, 'op, 'any) io\" where\n\"while body \\<equiv> Loop \n      ??? \n      (loop_body_to_V (\\<lambda>_. body \\<bind>io (\\<lambda>x. return ((if x then Break else Continue) ???)))) \n      (return \\<circ> (\\<lambda>_. ()))\"\n\n\ndefinition \"forEach\"  :: \"'e::countable list \\<Rightarrow> ('e \\<Rightarrow> ('a::countable, 'op::small, 'any::{small,natConvert}) io) \\<Rightarrow> ('a list, 'op, 'any) io\" where\n\"forEach elements body \\<equiv> \n    loop (elements,[]) (\\<lambda>(elems, acc).\n        case elems of\n        [] \\<Rightarrow> return (Break (rev acc))\n        | (x#xs) \\<Rightarrow> body x \\<bind>io (\\<lambda>r. return (Continue (xs, r#acc)))   \n    )\"\n  \n\n\n text \\<open>\n \\DefineSnippet{io_language_constructs}{\n    @{thm [display] beginAtomic_def}\n    @{thm [display] endAtomic_def}\n    @{thm [display] newId_def}\n    @{thm [display] call_def}\n    @{thm [display] return_def}\n    @{thm [display] skip_def}\n    @{thm [display] atomic_def}\n }%EndSnippet\n \\<close>\n\n text \\<open>\n \\DefineSnippet{io_language_constructs_refs}{\n    @{thm [display] makeRef_def}\n    @{thm [display] read_def}\n    @{thm [display] assign_def}\n    @{thm [display] update_def}\n }%EndSnippet\n \\<close>\n\n text \\<open>\n \\DefineSnippet{io_language_constructs_loops}{\n    @{thm [display] loop_def}\n    @{thm [display] while_def}\n    @{thm [display] forEach_def}\n }%EndSnippet\n \\<close>\n\n\nend\n\n\n", "meta": {"author": "peterzeller", "repo": "repliss-isabelle", "sha": "f43744678cc9c5a4684e8bd0e9c83510bae1d9a4", "save_path": "github-repos/isabelle/peterzeller-repliss-isabelle", "path": "github-repos/isabelle/peterzeller-repliss-isabelle/repliss-isabelle-f43744678cc9c5a4684e8bd0e9c83510bae1d9a4/impl_language_loops.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5389832354982647, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.2884090823712083}}
{"text": "(*  Title:      HOL/Statespace/StateSpaceLocale.thy\n    Author:     Norbert Schirmer, TU Muenchen\n*)\n\nsection {* Setup for State Space Locales \\label{sec:StateSpaceLocale}*}\n\ntheory StateSpaceLocale imports StateFun \nkeywords \"statespace\" :: thy_decl\nbegin\n\nML_file \"state_space.ML\"\nML_file \"state_fun.ML\"\n\ntext {* For every type that is to be stored in a state space, an\ninstance of this locale is imported in order convert the abstract and\nconcrete values.*}\n\n\nlocale project_inject =\n fixes project :: \"'value \\<Rightarrow> 'a\"\n  and inject :: \"'a \\<Rightarrow> 'value\"\n assumes project_inject_cancel [statefun_simp]: \"project (inject x) = x\"\nbegin\n\nlemma ex_project [statefun_simp]: \"\\<exists>v. project v = x\"\nproof\n  show \"project (inject x) = x\"\n    by (rule project_inject_cancel)\nqed\n\nlemma project_inject_comp_id [statefun_simp]: \"project \\<circ> inject = id\"\n  by (rule ext) (simp add: project_inject_cancel)\n\nlemma project_inject_comp_cancel[statefun_simp]: \"f \\<circ> project \\<circ> inject = f\"\n  by (rule ext) (simp add: project_inject_cancel)\n\nend\n\nend", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/Statespace/StateSpaceLocale.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.28840907444608993}}
{"text": "theory AbstractMultiPaxosR2Correctness\nimports AbstractMultiPaxosR1 AbstractMultiPaxosR2 Simulations\nbegin\n\nlocale ampr2_proof = IOA + quorums quorums + ampr2_ioa quorums leader \n  + r1:ampr1_ioa quorums leader\n  for quorums :: \"'a set set\" and leader :: \"bal \\<Rightarrow> 'a\" + \n  fixes ampr2_ioa :: \"(('v, 'a, 'l) ampr2_state, 'v paxos_action) ioa\"\n    and ampr1_ioa :: \"(('v, 'a, 'l) ampr1_state, 'v paxos_action) ioa\"\n  defines \"ampr2_ioa \\<equiv> ioa\" and \"ampr1_ioa \\<equiv> r1.ioa\"\nbegin\n\ndefinition ref_map where \"ref_map s \\<equiv> \\<lparr>\n  ampr1_state.propCmd = propCmd s,\n  ampr1_state.ballot = ballot s,\n  ampr1_state.vote = (\\<lambda> i a . vote s $ a $ i),\n  ampr1_state.suggestion = suggestion s,\n  ampr1_state.onebs = onebs s,\n  ampr1_state.leader = ampr2_state.leader s\\<rparr>\"\n\nterm \"ampr1_ioa\"\nterm \"ampr2_ioa\"\n\nlemma \"is_ref_map ref_map ampr2_ioa ampr1_ioa\"\nproof (auto simp add:is_ref_map_def simp del:split_paired_Ex)\n  fix s\n  assume \"s \\<in> ioa.start ampr2_ioa\"\n  thus \"ref_map s \\<in> ioa.start ampr1_ioa\" \n    by (simp add:ref_map_def ampr1.simps ampr2_ioa_def ampr1_ioa_def ioa_def start_def)\nnext\n  fix s t a\n  assume a1:\"reachable ampr2_ioa s\" and a2:\"s \\<midarrow>a\\<midarrow>ampr2_ioa\\<longrightarrow> t\"\n  let ?e = \"(ref_map s, [(a, ref_map t)])\"\n  have \"refines ?e s a t ampr1_ioa ref_map\"\n  proof (auto simp add:refines_def ioa_simps trace_match_def trace_def schedule_def filter_act_def)\n    show \"(ref_map s, a, ref_map t) \\<in> ioa.trans ampr1_ioa\" using a2\n    apply (simp add:ampr2_ioa_def ioa_def is_trans_def trans_def)\n    apply (simp add:ampr1_ioa_def ampr1.ioa_def ampr1.trans_def)\n    apply (induct rule:trans_cases_2)\n    apply (simp_all add:simps ampr1.simps ref_map_def)[2]\n    (* join_ballot *)\n    apply (induct a) apply auto[2]\n    apply (auto simp add:ref_map_def ampr1.simps simps)[1]\n    (* do_vote *)\n    apply (induct a) apply auto[2] \n    subgoal premises prems for a i v\n    proof -\n      have \"ampr1.do_vote a i v (ref_map s) (ref_map t)\" using prems\n        by (auto simp add:ref_map_def simps Let_def ampr1.simps fun_eq_iff)\n      thus ?thesis by auto\n    qed\n    (* suggest *)\n    apply (induct a) apply auto[2] \n    subgoal premises prems for a i b v\n    proof -\n      have \"ampr1.suggest a i b v (ref_map s) (ref_map t)\" using prems\n        by (auto simp add:ref_map_def simps Let_def ampr1.simps fun_eq_iff)\n      thus ?thesis by auto\n    qed\n    (* catch_up *)\n    apply (induct a) apply auto[2] \n    subgoal premises prems for l1 l2 i v\n    proof -\n      have \"ampr1.catch_up l1 l2 i v (ref_map s) (ref_map t)\" using prems\n        by (auto simp add:ref_map_def simps Let_def ampr1.simps fun_eq_iff)\n      thus ?thesis by auto\n    qed\n    (* acquire_leadership *)\n    apply (induct a) apply auto[2] \n    subgoal premises prems for aa q\n    proof -\n      have \"ampr1.acquire_leadership aa q (ref_map s) (ref_map t)\" using prems\n        by (auto simp add:ref_map_def simps Let_def ampr1.simps fun_eq_iff)\n      thus ?thesis by auto\n    qed\n    done \n    qed\n  thus \"\\<exists> e . refines e s a t ampr1_ioa ref_map\" by blast\nqed\n\nend", "meta": {"author": "nano-o", "repo": "dist-systems-verif", "sha": "9826370dd5f1c6df6543e64481bfafc3e164674e", "save_path": "github-repos/isabelle/nano-o-dist-systems-verif", "path": "github-repos/isabelle/nano-o-dist-systems-verif/dist-systems-verif-9826370dd5f1c6df6543e64481bfafc3e164674e/Isabelle2/AbstractMultiPaxosR2Correctness.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6825737473266735, "lm_q2_score": 0.4225046348141882, "lm_q1q2_score": 0.28839057184800815}}
{"text": "(*\n * @TAG(OTHER_LGPL)\n *)\n\n(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      HoarePartial.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nheader {* Properties of Total Correctness Hoare Logic *}\n\ntheory HoareTotalProps imports SmallStep HoareTotalDef HoarePartialProps begin\n\nsubsection {* Soundness *}\n\nlemma hoaret_sound: \n assumes hoare: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nusing hoare\nproof (induct)\n  case (Skip \\<Theta> F P A)\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Skip P,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Skip,Normal s\\<rangle> \\<Rightarrow> t\" \"s \\<in> P\"\n    thus \"t \\<in> Normal ` P \\<union> Abrupt ` A\"\n      by cases auto\n  next\n    fix s show \"\\<Gamma>\\<turnstile>Skip \\<down> Normal s\"\n      by (rule terminates.intros)\n  qed\nnext\n  case (Basic \\<Theta> F f P A)\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. f s \\<in> P} (Basic f) P,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Basic f,Normal s\\<rangle> \\<Rightarrow> t\" \"s \\<in> {s. f s \\<in> P}\"\n    thus \"t \\<in> Normal ` P \\<union> Abrupt ` A\"\n      by cases auto\n  next\n    fix s show \"\\<Gamma>\\<turnstile>Basic f \\<down> Normal s\"\n      by (rule terminates.intros)\n  qed\nnext\n  case (Spec \\<Theta> F r Q A)\n  show \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. (\\<forall>t. (s, t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s, t) \\<in> r)} Spec r Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Spec r ,Normal s\\<rangle> \\<Rightarrow> t\" \n           \"s \\<in> {s. (\\<forall>t. (s, t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s, t) \\<in> r)}\"\n    thus \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by cases auto\n  next\n    fix s show \"\\<Gamma>\\<turnstile>Spec r \\<down> Normal s\"\n      by (rule terminates.intros)\n  qed\nnext\n  case (Seq \\<Theta> F P c1 R A c2 Q)\n  have valid_c1: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c1 R,A\" by fact\n  have valid_c2: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c2 Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Seq c1 c2 Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal s\\<rangle> \\<Rightarrow> t\" \n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    from exec P obtain r where\n      exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> r\" and exec_c2:  \"\\<Gamma>\\<turnstile>\\<langle>c2,r\\<rangle> \\<Rightarrow> t\"\n      by cases auto\n    with t_notin_F have \"r \\<notin> Fault ` F\"\n      by (auto dest: Fault_end)\n    from valid_c1 ctxt exec_c1 P this\n    have r: \"r \\<in> Normal ` R \\<union> Abrupt ` A\"\n      by (rule cvalidt_postD)\n    show \"t\\<in>Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases r)\n      case (Normal r')\n      with exec_c2 r\n      show \"t\\<in>Normal ` Q \\<union> Abrupt ` A\"\n        apply -\n        apply (rule cvalidt_postD [OF valid_c2 ctxt _ _ t_notin_F])\n        apply auto\n        done\n    next\n      case (Abrupt r')\n      with exec_c2 have \"t=Abrupt r'\"\n        by (auto elim: exec_elim_cases)\n      with Abrupt r show ?thesis\n        by auto\n    next\n      case Fault with r show ?thesis by blast\n    next\n      case Stuck with r show ?thesis by blast\n    qed\n  next\n    fix s \n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s\\<in>P\"\n    show \"\\<Gamma>\\<turnstile>Seq c1 c2 \\<down> Normal s\"\n    proof -\n      from valid_c1 ctxt P\n      have \"\\<Gamma>\\<turnstile>c1\\<down> Normal s\"\n        by (rule cvalidt_termD)\n      moreover\n      {\n        fix r assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> r\"\n        have \"\\<Gamma>\\<turnstile>c2 \\<down> r\"\n        proof (cases r)\n          case (Normal r')\n          with cvalidt_postD [OF valid_c1 ctxt exec_c1 P]\n          have r: \"r\\<in>Normal ` R\"\n            by auto\n          with cvalidt_termD [OF valid_c2 ctxt] exec_c1\n          show \"\\<Gamma>\\<turnstile>c2 \\<down> r\"\n            by auto\n        qed auto        \n      }\n      ultimately show ?thesis\n        by (iprover intro: terminates.intros)\n    qed\n  qed\nnext\n  case (Cond \\<Theta> F P b c1 Q A c2)\n  have valid_c1: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> b) c1 Q,A\" by fact\n  have valid_c2: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> - b) c2 Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Cond b c1 c2 Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow> t\"\n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases \"s\\<in>b\")\n      case True\n      with exec have \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> t\"\n        by cases auto\n      with P True \n      show ?thesis\n        by - (rule cvalidt_postD [OF valid_c1 ctxt _ _ t_notin_F],auto)\n    next\n      case False\n      with exec P have \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal s\\<rangle> \\<Rightarrow> t\"\n        by cases auto\n      with P False \n      show ?thesis\n        by - (rule cvalidt_postD [OF valid_c2 ctxt _ _ t_notin_F],auto)\n    qed\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s \\<in> P\"\n    thus \"\\<Gamma>\\<turnstile>Cond b c1 c2 \\<down> Normal s\"\n      using cvalidt_termD [OF valid_c1 ctxt] cvalidt_termD [OF valid_c2 ctxt]\n      by (cases \"s \\<in> b\") (auto intro: terminates.intros)\n  qed\nnext\n  case (While r \\<Theta> F P b c A)\n  assume wf: \"wf r\"\n  have valid_c: \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P \\<inter> b) c ({t. (t, \\<sigma>) \\<in> r} \\<inter> P),A\"\n    using While.hyps by iprover\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (While b c) (P \\<inter> - b),A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume wprems: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow> t\" \"s \\<in> P\" \"t \\<notin> Fault ` F\"\n    from wf\n    have \"\\<And>t. \\<lbrakk>\\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow> t; s \\<in> P; t \\<notin> Fault ` F\\<rbrakk> \n                 \\<Longrightarrow> t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\"\n    proof (induct)\n      fix s t\n      assume hyp: \n        \"\\<And>s' t. \\<lbrakk>(s',s)\\<in>r; \\<Gamma>\\<turnstile>\\<langle>While b c,Normal s'\\<rangle> \\<Rightarrow> t; s' \\<in> P; t \\<notin> Fault ` F\\<rbrakk>\n                 \\<Longrightarrow> t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\"\n      assume exec: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow> t\"\n      assume P: \"s \\<in> P\"\n      assume t_notin_F: \"t \\<notin> Fault ` F\"\n      from exec\n      show \"t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\"\n      proof (cases)\n        fix s'\n        assume b: \"s\\<in>b\"\n        assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> s'\" \n        assume exec_w: \"\\<Gamma>\\<turnstile>\\<langle>While b c,s'\\<rangle> \\<Rightarrow> t\"\n        from exec_w t_notin_F have \"s' \\<notin> Fault ` F\"\n          by (auto dest: Fault_end)\n        from exec_c P b valid_c ctxt this\n        have s': \"s' \\<in> Normal ` ({s'. (s', s) \\<in> r} \\<inter> P) \\<union> Abrupt ` A\"\n          by (auto simp add: cvalidt_def validt_def valid_def)\n        show ?thesis\n        proof (cases s')\n          case Normal \n          with exec_w s' t_notin_F\n          show ?thesis\n            by - (rule hyp,auto)\n        next\n          case Abrupt\n          with exec_w have \"t=s'\"\n            by (auto dest: Abrupt_end)\n          with Abrupt s' show ?thesis\n            by blast\n        next\n          case Fault\n          with exec_w have \"t=s'\"\n            by (auto dest: Fault_end)\n          with Fault s' show ?thesis\n            by blast\n        next\n          case Stuck\n          with exec_w have \"t=s'\"\n            by (auto dest: Stuck_end)\n          with Stuck s' show ?thesis\n            by blast\n        qed\n      next\n        assume \"s\\<notin>b\" \"t=Normal s\" with P show ?thesis by simp\n      qed\n    qed\n    with wprems show \"t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\" by blast\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume \"s \\<in> P\"\n    with wf \n    show \"\\<Gamma>\\<turnstile>While b c \\<down> Normal s\"\n    proof (induct)\n      fix s\n      assume hyp: \"\\<And>s'. \\<lbrakk>(s',s)\\<in>r; s' \\<in> P\\<rbrakk> \n                         \\<Longrightarrow> \\<Gamma>\\<turnstile>While b c \\<down> Normal s'\"\n      assume P: \"s \\<in> P\"\n      show \"\\<Gamma>\\<turnstile>While b c \\<down> Normal s\"\n      proof (cases \"s \\<in> b\")\n        case False with P show ?thesis\n          by (blast intro: terminates.intros)\n      next\n        case True\n        with valid_c P ctxt\n        have \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n          by (simp add: cvalidt_def validt_def)\n        moreover\n        {\n          fix s'\n          assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> s'\"\n          have \"\\<Gamma>\\<turnstile>While b c \\<down> s'\"\n          proof (cases s')\n            case (Normal s'')\n            with exec_c P True valid_c ctxt\n            have s': \"s' \\<in> Normal ` ({s'. (s', s) \\<in> r} \\<inter> P)\"\n              by (fastforce simp add: cvalidt_def validt_def valid_def)\n            then show ?thesis\n              by (blast intro: hyp)\n          qed auto\n        }\n        ultimately\n        show ?thesis\n          by (blast intro: terminates.intros)\n      qed\n    qed\n  qed\nnext\n  case (Guard \\<Theta> F g P c Q A  f)\n  have valid_c: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) Guard f g c Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow> t\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    assume P:\"s \\<in> (g \\<inter> P)\"\n    from exec P have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by cases auto\n    from valid_c ctxt this P t_notin_F\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by (rule cvalidt_postD)\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P:\"s \\<in> (g \\<inter> P)\"\n    thus \"\\<Gamma>\\<turnstile>Guard f g c  \\<down> Normal s\"\n      by (auto intro: terminates.intros cvalidt_termD [OF valid_c ctxt])\n  qed\nnext\n  case (Guarantee f F \\<Theta> g P c Q A)\n  have valid_c: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\" by fact\n  have f_F: \"f \\<in> F\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Guard f g c Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow> t\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    assume P:\"s \\<in> P\"\n    from exec f_F t_notin_F have g: \"s \\<in> g\"\n      by cases auto\n    with P have P': \"s \\<in> g \\<inter> P\"\n      by blast\n    from exec g have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by cases auto\n    from valid_c ctxt this P' t_notin_F\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by (rule cvalidt_postD)\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P:\"s \\<in> P\"\n    thus \"\\<Gamma>\\<turnstile>Guard f g c  \\<down> Normal s\"\n      by (auto intro: terminates.intros cvalidt_termD [OF valid_c ctxt])\n  qed\nnext\n  case (CallRec P p Q A Specs r Specs_wf \\<Theta>  F)\n  have p: \"(P,p,Q,A) \\<in> Specs\"  by fact\n  have wf: \"wf r\" by fact\n  have Specs_wf: \n    \"Specs_wf = (\\<lambda>p \\<tau>. (\\<lambda>(P,q,Q,A). (P \\<inter> {s. ((s, q),\\<tau>,p) \\<in> r},q,Q,A)) ` Specs)\" by fact\n  from CallRec.hyps\n  have valid_body: \n    \"\\<forall>(P, p, Q, A)\\<in>Specs. p \\<in> dom \\<Gamma> \\<and>\n        (\\<forall>\\<tau>. \\<Gamma>,\\<Theta> \\<union> Specs_wf p \\<tau>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) the (\\<Gamma> p) Q,A)\" by auto\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  proof -\n    {\n      fix \\<tau>p \n      assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n      from wf\n      have \"\\<And>\\<tau> p P Q A.  \\<lbrakk>\\<tau>p = (\\<tau>,p); (P,p,Q,A) \\<in> Specs\\<rbrakk> \\<Longrightarrow> \n                  \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> (p))) Q,A\"    \n      proof (induct \\<tau>p rule: wf_induct [rule_format, consumes 1, case_names WF])\n        case (WF \\<tau>p \\<tau> p P Q A)\n        have \\<tau>p: \"\\<tau>p = (\\<tau>, p)\" by fact\n        have p: \"(P, p, Q, A) \\<in> Specs\" by fact\n        {\n          fix q P' Q' A'\n          assume q: \"(P',q,Q',A') \\<in> Specs\"\n          have \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' \\<inter> {s. ((s,q), \\<tau>,p) \\<in> r}) (Call q) Q',A'\"\n          proof (rule validtI)\n            fix s t\n            assume exec_q: \n              \"\\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow> t\"\n            assume Pre: \"s \\<in> P' \\<inter> {s. ((s,q), \\<tau>,p) \\<in> r}\"\n            assume t_notin_F: \"t \\<notin> Fault ` F\"\n            from Pre q \\<tau>p\n            have valid_bdy: \n              \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s} \\<inter> P') the (\\<Gamma> q) Q',A'\"\n              by - (rule WF.hyps, auto)\n            from Pre q\n            have Pre': \"s \\<in> {s} \\<inter> P'\"\n              by auto\n            from exec_q show \"t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n            proof (cases)\n              fix bdy \n              assume bdy: \"\\<Gamma> q = Some bdy\"\n              assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal s\\<rangle> \\<Rightarrow> t\"\n              from valid_bdy [simplified bdy option.sel]  t_notin_F exec_bdy Pre'\n              have \"t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n                by (auto simp add: validt_def valid_def)\n              with Pre q \n              show ?thesis\n                by auto\n            next\n              assume \"\\<Gamma> q = None\"\n              with q valid_body have False by auto\n              thus ?thesis ..\n            qed\n          next\n            fix s\n            assume Pre: \"s \\<in> P' \\<inter> {s. ((s,q), \\<tau>,p) \\<in> r}\"\n            from Pre q \\<tau>p\n            have valid_bdy: \n              \"\\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s} \\<inter> P') (the (\\<Gamma> q)) Q',A'\"\n              by - (rule WF.hyps, auto)\n            from Pre q\n            have Pre': \"s \\<in> {s} \\<inter> P'\"\n              by auto\n            from valid_bdy ctxt Pre'\n            have \"\\<Gamma>\\<turnstile>the (\\<Gamma> q) \\<down> Normal s\"\n              by (auto simp add: validt_def)\n            with valid_body q \n            show \"\\<Gamma>\\<turnstile>Call q\\<down> Normal s\"\n              by (fastforce intro: terminates.Call)\n          qed\n        }\n        hence \"\\<forall>(P, p, Q, A)\\<in>Specs_wf p \\<tau>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Call p Q,A\"\n          by (auto simp add: cvalidt_def Specs_wf)\n        with ctxt have \"\\<forall>(P, p, Q, A)\\<in>\\<Theta> \\<union> Specs_wf p \\<tau>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Call p Q,A\"\n          by auto\n        with p valid_body \n        show \"\\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> p)) Q,A\"\n          by (simp add: cvalidt_def) blast\n      qed\n    }\n    note lem = this\n    have valid_body': \n      \"\\<And>\\<tau>. \\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A \\<Longrightarrow> \n      \\<forall>(P,p,Q,A)\\<in>Specs. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> p)) Q,A\"\n      by (auto intro: lem)\n    show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    proof (rule cvalidtI)\n      fix s t\n      assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n      assume exec_call: \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow> t\"\n      assume P: \"s \\<in> P\"\n      assume t_notin_F: \"t \\<notin> Fault ` F\"\n      from exec_call show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      proof (cases)\n        fix bdy \n        assume bdy: \"\\<Gamma> p = Some bdy\"\n        assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal s\\<rangle> \\<Rightarrow> t\"\n        from exec_body bdy p P t_notin_F \n          valid_body' [of \"s\", OF ctxt] \n          ctxt\n        have \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n          apply (simp only: cvalidt_def validt_def valid_def) \n          apply (drule (1) bspec)\n          apply auto\n          done\n        with p P \n        show ?thesis\n          by simp\n      next\n        assume \"\\<Gamma> p = None\"\n        with p valid_body have False by auto\n        thus ?thesis by simp\n      qed\n    next\n      fix s\n      assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n      assume P: \"s \\<in> P\"\n      show \"\\<Gamma>\\<turnstile>Call p \\<down> Normal s\"\n      proof -\n        from ctxt P p valid_body' [of \"s\",OF ctxt]\n        have \"\\<Gamma>\\<turnstile>(the (\\<Gamma> p)) \\<down> Normal s\"\n          by (auto simp add: cvalidt_def validt_def)\n        with valid_body p show ?thesis\n          by (fastforce intro: terminates.Call)\n      qed\n    qed\n  qed\nnext\n  case (DynCom P \\<Theta> F c Q A)\n  hence valid_c: \"\\<forall>s\\<in>P. \\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (c s) Q,A\" by simp\n  show \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P DynCom c Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal s\\<rangle> \\<Rightarrow> t\" \n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    from exec show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases)\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c s,Normal s\\<rangle> \\<Rightarrow> t\"      \n      from cvalidt_postD [OF valid_c [rule_format, OF P] ctxt this P t_notin_F]\n      show ?thesis .\n    qed\n  next\n    fix s \n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s \\<in> P\"\n    show \"\\<Gamma>\\<turnstile>DynCom c \\<down> Normal s\"\n    proof -\n      from cvalidt_termD [OF valid_c [rule_format, OF P] ctxt P]\n      have \"\\<Gamma>\\<turnstile>c s \\<down> Normal s\" .\n      thus ?thesis\n        by (rule terminates.intros)\n    qed\n  qed\nnext\n  case (Throw \\<Theta> F A Q)\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> A Throw Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Throw,Normal s\\<rangle> \\<Rightarrow> t\" \"s \\<in> A\"\n    then show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by cases simp\n  next\n    fix s\n    show \"\\<Gamma>\\<turnstile>Throw \\<down> Normal s\"\n      by (rule terminates.intros)\n  qed\nnext\n  case (Catch \\<Theta> F P c\\<^sub>1 Q R c\\<^sub>2 A)\n  have valid_c1: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,R\" by fact\n  have valid_c2: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Catch c\\<^sub>1 c\\<^sub>2 Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow> t\" \n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    from exec show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases)\n      fix s'\n      assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Abrupt s'\" \n      assume exec_c2: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s'\\<rangle> \\<Rightarrow> t\"\n      from cvalidt_postD [OF valid_c1 ctxt exec_c1 P]\n      have \"Abrupt s' \\<in> Abrupt ` R\"\n        by auto\n      with cvalidt_postD [OF valid_c2 ctxt] exec_c2 t_notin_F\n      show ?thesis\n        by fastforce\n    next\n      assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t\" \n      assume notAbr: \"\\<not> isAbr t\"\n      from cvalidt_postD [OF valid_c1 ctxt exec_c1 P] t_notin_F\n      have \"t \\<in> Normal ` Q \\<union> Abrupt ` R\" .\n      with notAbr\n      show ?thesis\n        by auto\n    qed\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s \\<in> P\"\n    show \"\\<Gamma>\\<turnstile>Catch c\\<^sub>1 c\\<^sub>2 \\<down> Normal s\"  \n    proof -\n      from valid_c1 ctxt P\n      have \"\\<Gamma>\\<turnstile>c\\<^sub>1\\<down> Normal s\"\n        by (rule cvalidt_termD)\n      moreover\n      {\n        fix r assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Abrupt r\"\n        from cvalidt_postD [OF valid_c1 ctxt exec_c1 P]\n        have r: \"Abrupt r\\<in>Normal ` Q \\<union> Abrupt ` R\"\n          by auto\n        hence \"Abrupt r\\<in>Abrupt ` R\" by fast\n        with cvalidt_termD [OF valid_c2 ctxt] exec_c1\n        have \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal r\"\n          by fast\n      }\n      ultimately show ?thesis\n        by (iprover intro: terminates.intros)\n    qed\n  qed\nnext\n  case (Conseq P \\<Theta> F c Q A)\n  hence adapt: \n    \"\\<forall>s \\<in> P. (\\<exists>P' Q' A'. (\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A') \\<and> s \\<in> P'\\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A)\" by blast\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof -\n      from adapt [rule_format, OF P]\n      obtain P' and Q' and A' where \n        valid_P'_Q': \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A'\"\n        and weaken: \"s \\<in> P'\" \"Q' \\<subseteq>  Q\" \"A'\\<subseteq> A\"\n        by blast\n      from exec valid_P'_Q' ctxt t_notin_F\n      have P'_Q': \"Normal s \\<in> Normal ` P' \\<longrightarrow> \n        t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n        by (unfold cvalidt_def validt_def valid_def) blast\n      hence \"s \\<in> P' \\<longrightarrow> t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n        by blast\n      with weaken \n      show ?thesis\n        by blast\n    qed\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s \\<in> P\"\n    show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    proof -\n      from P adapt\n      obtain P' and Q' and  A' where \n        \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A'\"\n        \"s \\<in> P'\"\n        by blast\n      with ctxt\n      show ?thesis\n        by (simp add: cvalidt_def validt_def)\n    qed\n  qed\nnext\n  case (Asm P p Q A \\<Theta> F)\n  assume \"(P, p, Q, A) \\<in> \\<Theta>\"\n  then show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (auto simp add: cvalidt_def )\nnext\n  case ExFalso thus ?case by iprover\nqed\n\nlemma hoaret_sound':\n\"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (drule hoaret_sound)\n  apply (simp add: cvalidt_def)\n  done\n\ntheorem total_to_partial: \n assumes total: \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" shows \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from total have \"\\<Gamma>,{}\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (rule hoaret_sound)\n  hence \"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (simp add: cvalidt_def validt_def cvalid_def)\n  thus ?thesis\n    by (rule hoare_complete)\nqed\n\nsubsection {* Completeness *}\n\nlemma MGT_valid:\n\"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \\<Gamma>\\<turnstile>c\\<down>Normal s} c \n    {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t}, {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\nproof (rule validtI) \n  fix s t\n  assume \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n         \"s \\<in> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \\<Gamma>\\<turnstile>c\\<down>Normal s}\"\n         \"t \\<notin> Fault ` F\"\n  thus \"t \\<in> Normal ` {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t} \\<union> \n            Abrupt ` {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    apply (cases t) \n    apply (auto simp add: final_notin_def)\n    done\nnext\n  fix s\n  assume \"s \\<in> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \\<Gamma>\\<turnstile>c\\<down>Normal s}\"\n  thus \"\\<Gamma>\\<turnstile>c\\<down>Normal s\"\n    by blast\nqed\n\ntext {* The consequence rule where the existential @{term Z} is instantiated\nto @{term s}. Usefull in proof of @{text \"MGT_lemma\"}.*}\nlemma ConseqMGT: \n  assumes modif: \"\\<forall>Z::'a. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z::'a assn) c (Q' Z),(A' Z)\"\n  assumes impl: \"\\<And>s. s \\<in> P \\<Longrightarrow> s \\<in> P' s \\<and> (\\<forall>t. t \\<in> Q' s \\<longrightarrow> t \\<in> Q) \\<and> \n                                            (\\<forall>t. t \\<in> A' s \\<longrightarrow> t \\<in> A)\"\n  shows \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nusing impl \nby - (rule conseq [OF modif],blast)\n\nlemma MGT_implies_complete:\n  assumes MGT: \"\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                                 \\<Gamma>\\<turnstile>c\\<down>Normal s}\n                              c \n                            {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                            {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  assumes valid: \"\\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" \n  shows \"\\<Gamma>,{} \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  using MGT\n  apply (rule ConseqMGT) \n  apply (insert valid)\n  apply (auto simp add: validt_def valid_def intro!: final_notinI)\n  done\n\nlemma conseq_extract_state_indep_prop: \n  assumes state_indep_prop:\"\\<forall>s \\<in> P. R\" \n  assumes to_show: \"R \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule Conseq)\n  apply (clarify)\n  apply (rule_tac x=\"P\" in exI)\n  apply (rule_tac x=\"Q\" in exI)\n  apply (rule_tac x=\"A\" in exI)\n  using state_indep_prop to_show\n  by blast\n\nlemma MGT_lemma:\n  assumes MGT_Calls: \n    \"\\<forall>p \\<in> dom \\<Gamma>. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> \n       {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n           \\<Gamma>\\<turnstile>(Call p)\\<down>Normal s}\n             (Call p)\n       {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n       {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  shows \"\\<And>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                          \\<Gamma>\\<turnstile>c\\<down>Normal s} \n               c \n             {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\nproof (induct c)\n  case Skip\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Skip,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                   \\<Gamma>\\<turnstile>Skip \\<down> Normal s} \n               Skip\n            {t. \\<Gamma>\\<turnstile>\\<langle>Skip,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>Skip,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoaret.Skip [THEN conseqPre])\n       (auto elim: exec_elim_cases simp add: final_notin_def \n             intro: exec.intros terminates.intros)\nnext\n  case (Basic f)\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Basic f,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                 \\<Gamma>\\<turnstile>Basic f \\<down> Normal s} \n                Basic f\n              {t. \\<Gamma>\\<turnstile>\\<langle>Basic f,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Basic f,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoaret.Basic [THEN conseqPre]) \n       (auto elim: exec_elim_cases simp add: final_notin_def \n             intro: exec.intros terminates.intros)\nnext\n  case (Spec r)\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Spec r,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Spec r \\<down> Normal s} \n                Spec r\n              {t. \\<Gamma>\\<turnstile>\\<langle>Spec r,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Spec r,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    apply (rule hoaret.Spec [THEN conseqPre])\n    apply (clarsimp simp add: final_notin_def)\n    apply (case_tac \"\\<exists>t. (Z,t) \\<in> r\")\n    apply (auto elim: exec_elim_cases simp add: final_notin_def intro: exec.intros)\n    done\nnext\n  case (Seq c1 c2) \n  have hyp_c1: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                                \\<Gamma>\\<turnstile>c1\\<down>Normal s}\n                            c1 \n                           {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                           {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" \n    using Seq.hyps by iprover\n  have hyp_c2: \"\\<forall> Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                                 \\<Gamma>\\<turnstile>c2\\<down>Normal s}\n                              c2 \n                            {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                            {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" \n    using Seq.hyps by iprover\n  from hyp_c1 \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                \\<Gamma>\\<turnstile>Seq c1 c2\\<down>Normal s} c1 \n    {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t \\<and> \\<Gamma>\\<turnstile>\\<langle>c2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n        \\<Gamma>\\<turnstile>c2\\<down>Normal t},\n    {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT)\n       (auto dest: Seq_NoFaultStuckD1 [simplified] Seq_NoFaultStuckD2 [simplified]\n             elim: terminates_Normal_elim_cases \n             intro: exec.intros)\n  thus \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                 \\<Gamma>\\<turnstile>Seq c1 c2\\<down>Normal s} \n                Seq c1 c2\n              {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  proof (rule hoaret.Seq )\n    show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t \\<and>\n                    \\<Gamma>\\<turnstile>\\<langle>c2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \\<Gamma>\\<turnstile>c2 \\<down> Normal t}\n                 c2 \n                {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    proof (rule ConseqMGT [OF hyp_c2],safe)\n      fix r t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal r\" \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal r\\<rangle> \\<Rightarrow> Normal t\"\n      then show \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n        by (rule exec.intros)\n    next\n      fix r t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal r\" \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal r\\<rangle> \\<Rightarrow> Abrupt t\"\n      then show \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n        by (rule exec.intros)\n    qed\n  qed\nnext\n  case (Cond b c1 c2) \n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                         \\<Gamma>\\<turnstile>c1\\<down>Normal s} \n                     c1 \n                   {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                   {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" \n    using Cond.hyps by iprover  \n  hence \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                     \\<Gamma>\\<turnstile>(Cond b c1 c2)\\<down>Normal s}\\<inter>b) \n                c1 \n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"  \n    by (rule ConseqMGT)\n       (fastforce simp add: final_notin_def intro: exec.CondTrue \n                 elim: terminates_Normal_elim_cases)\n  moreover\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                               \\<Gamma>\\<turnstile>c2\\<down>Normal s} \n                      c2 \n                    {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                    {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"  \n    using Cond.hyps by iprover  \n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>(Cond b c1 c2)\\<down>Normal s}\\<inter>-b) \n                c2 \n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" \n    by (rule ConseqMGT)\n       (fastforce simp add: final_notin_def intro: exec.CondFalse \n                 elim: terminates_Normal_elim_cases)\n  ultimately\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n               \\<Gamma>\\<turnstile>(Cond b c1 c2)\\<down>Normal s} \n               (Cond b c1 c2)\n              {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoaret.Cond)       \nnext\n  case (While b c)\n  let ?unroll = \"({(s,t). s\\<in>b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t})\\<^sup>*\"\n  let ?P' = \"\\<lambda>Z. {t. (Z,t)\\<in>?unroll \\<and> \n                    (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                         \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                             (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)) \\<and>\n                    \\<Gamma>\\<turnstile>(While b c)\\<down>Normal t}\"\n  let ?A = \"\\<lambda>Z. {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  let ?r = \"{(t,s). \\<Gamma>\\<turnstile>(While b c)\\<down>Normal s \\<and> s\\<in>b \\<and> \n                    \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t}\"\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>  \n                  \\<Gamma>\\<turnstile>(While b c)\\<down>Normal s} \n              (While b c)\n              {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  proof (rule ConseqMGT [where ?P'=\"\\<lambda> Z. ?P' Z\" \n                         and ?Q'=\"\\<lambda> Z. ?P' Z \\<inter> - b\"])\n    have wf_r: \"wf ?r\" by (rule wf_terminates_while)\n    show \"\\<forall> Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (?P' Z) (While b c) (?P' Z \\<inter> - b),(?A Z)\"\n    proof (rule allI, rule hoaret.While [OF wf_r])\n      fix Z\n      from While \n      have hyp_c: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                                  \\<Gamma>\\<turnstile>c\\<down>Normal s}\n                                c\n                              {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                              {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" by iprover\n      show \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> ?P' Z  \\<inter> b) c \n                       ({t. (t, \\<sigma>) \\<in> ?r} \\<inter> ?P' Z),(?A Z)\"\n      proof (rule allI, rule ConseqMGT [OF hyp_c])\n        fix \\<sigma> s\n        assume  \"s\\<in> {\\<sigma>} \\<inter>  \n                   {t. (Z, t) \\<in> ?unroll \\<and> \n                      (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                           \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                               (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                                    \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)) \\<and>\n                      \\<Gamma>\\<turnstile>(While b c)\\<down>Normal t}\n                   \\<inter> b\"\n        then obtain \n          s_eq_\\<sigma>: \"s=\\<sigma>\" and\n          Z_s_unroll: \"(Z,s) \\<in> ?unroll\" and\n          noabort:\"\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                        \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                            (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)\" and\n          while_term:  \"\\<Gamma>\\<turnstile>(While b c)\\<down>Normal s\" and\n          s_in_b: \"s\\<in>b\" \n          by blast\n        show \"s \\<in> {t. t = s \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                       \\<Gamma>\\<turnstile>c\\<down>Normal t} \\<and>\n        (\\<forall>t. t \\<in> {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t} \\<longrightarrow>\n             t \\<in> {t. (t,\\<sigma>) \\<in> ?r} \\<inter>  \n                 {t. (Z, t) \\<in> ?unroll \\<and> \n                     (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow>  e\\<in>b \n                           \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                              (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)) \\<and> \n                      \\<Gamma>\\<turnstile>(While b c)\\<down>Normal t})  \\<and> \n         (\\<forall>t. t \\<in> {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Abrupt t} \\<longrightarrow>\n             t \\<in> {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})\"\n          (is \"?C1 \\<and> ?C2 \\<and> ?C3\")\n        proof (intro conjI)\n          from Z_s_unroll noabort s_in_b while_term show ?C1 \n            by (blast elim: terminates_Normal_elim_cases)\n        next\n          {\n            fix t \n            assume s_t: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t\"\n            with s_eq_\\<sigma> while_term s_in_b have \"(t,\\<sigma>) \\<in> ?r\"\n              by blast\n            moreover\n            from Z_s_unroll s_t s_in_b \n            have \"(Z, t) \\<in> ?unroll\"\n              by (blast intro: rtrancl_into_rtrancl)\n            moreover from while_term s_t s_in_b \n            have \"\\<Gamma>\\<turnstile>(While b c)\\<down>Normal t\"\n              by (blast elim: terminates_Normal_elim_cases)\n            moreover note noabort\n            ultimately \n            have \"(t,\\<sigma>) \\<in> ?r \\<and> (Z, t) \\<in> ?unroll \\<and> \n                  (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                        \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                            (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)) \\<and>\n                  \\<Gamma>\\<turnstile>(While b c)\\<down>Normal t\"\n              by iprover\n          }\n          then show ?C2 by blast\n        next\n          {\n            fix t\n            assume s_t:  \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Abrupt t\" \n            from Z_s_unroll noabort s_t s_in_b\n            have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n              by blast\n          } thus ?C3 by simp\n        qed\n      qed\n    qed\n  next\n    fix s\n    assume P: \"s \\<in> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                       \\<Gamma>\\<turnstile>While b c \\<down> Normal s}\"\n    hence WhileNoFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n      by auto\n    show \"s \\<in> ?P' s \\<and> \n     (\\<forall>t. t\\<in>(?P' s \\<inter> - b)\\<longrightarrow>\n          t\\<in>{t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t})\\<and>\n     (\\<forall>t. t\\<in>?A s \\<longrightarrow> t\\<in>?A Z)\"\n    proof (intro conjI)\n      {\n        fix e\n        assume \"(Z,e) \\<in> ?unroll\" \"e \\<in> b\"\n        from this WhileNoFault\n        have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n               (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)\" (is \"?Prop Z e\")\n        proof (induct rule: converse_rtrancl_induct [consumes 1])\n          assume e_in_b: \"e \\<in> b\"\n          assume WhileNoFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n          with e_in_b WhileNoFault\n          have cNoFault: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n            by (auto simp add: final_notin_def intro: exec.intros)\n          moreover\n          {\n            fix u assume \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow> Abrupt u\"\n            with e_in_b have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal e\\<rangle> \\<Rightarrow> Abrupt u\"\n              by (blast intro: exec.intros)\n          }\n          ultimately\n          show \"?Prop e e\"\n            by iprover\n        next\n          fix Z r\n          assume e_in_b: \"e\\<in>b\" \n          assume WhileNoFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n          assume hyp: \"\\<lbrakk>e\\<in>b;\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\\<rbrakk>\n                       \\<Longrightarrow> ?Prop r e\"\n          assume Z_r:\n            \"(Z, r) \\<in> {(Z, r). Z \\<in> b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal r}\"\n          with WhileNoFault\n          have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n            by (auto simp add: final_notin_def intro: exec.intros)\n          from hyp [OF e_in_b this] obtain\n            cNoFault: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\" and\n            Abrupt_r: \"\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow> Abrupt u \\<longrightarrow> \n                            \\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow> Abrupt u\"\n            by simp\n          \n           {\n            fix u assume \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow> Abrupt u\"\n            with Abrupt_r have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow> Abrupt u\" by simp\n            moreover from  Z_r obtain\n              \"Z \\<in> b\"  \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal r\"\n              by simp\n            ultimately have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u\"\n              by (blast intro: exec.intros)\n          }\n          with cNoFault show \"?Prop Z e\"\n            by iprover\n        qed\n      }\n      with P show \"s \\<in> ?P' s\"\n        by blast\n    next\n      {\n        fix t\n        assume \"termination\": \"t \\<notin> b\"\n        assume \"(Z, t) \\<in> ?unroll\"\n        hence \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n        proof (induct rule: converse_rtrancl_induct [consumes 1])\n          from \"termination\" \n          show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal t\\<rangle> \\<Rightarrow> Normal t\"\n            by (blast intro: exec.WhileFalse)\n        next\n          fix Z r\n          assume first_body: \n                 \"(Z, r) \\<in> {(s, t). s \\<in> b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t}\"\n          assume \"(r, t) \\<in> ?unroll\"\n          assume rest_loop: \"\\<Gamma>\\<turnstile>\\<langle>While b c, Normal r\\<rangle> \\<Rightarrow> Normal t\"\n          show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n          proof -\n            from first_body obtain\n              \"Z \\<in> b\" \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal r\"\n              by fast\n            moreover\n            from rest_loop have\n              \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow> Normal t\"\n              by fast\n            ultimately show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n              by (rule exec.WhileTrue)\n          qed\n        qed\n      }\n      with P\n      show \"(\\<forall>t. t\\<in>(?P' s \\<inter> - b)\n            \\<longrightarrow>t\\<in>{t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t})\"\n        by blast\n    next\n      from P show \"\\<forall>t. t\\<in>?A s \\<longrightarrow> t\\<in>?A Z\"\n        by simp\n    qed\n  qed\nnext\n  case (Call p)\n  from noStuck_Call\n  have \"\\<forall>s \\<in> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                         \\<Gamma>\\<turnstile>Call p\\<down> Normal s}.\n          p \\<in> dom \\<Gamma>\"\n    by (fastforce simp add: final_notin_def)\n  then show ?case\n  proof (rule conseq_extract_state_indep_prop)\n    assume p_defined: \"p \\<in> dom \\<Gamma>\"\n    with MGT_Calls show\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s=Z \\<and> \n                 \\<Gamma>\\<turnstile>\\<langle>Call p ,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\\<and>\n                 \\<Gamma>\\<turnstile>Call  p\\<down>Normal s}\n                (Call p)\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      by (auto)\n  qed\nnext\n  case (DynCom c)\n  have hyp: \n    \"\\<And>s'. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c s',Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                       \\<Gamma>\\<turnstile>c s'\\<down>Normal s} c s'\n      {t. \\<Gamma>\\<turnstile>\\<langle>c s',Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c s',Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using DynCom by simp\n  have hyp':\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n            \\<Gamma>\\<turnstile>DynCom c\\<down>Normal s} \n         (c Z)\n        {t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT [OF hyp]) \n       (fastforce simp add: final_notin_def intro: exec.intros \n          elim: terminates_Normal_elim_cases)\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                 \\<Gamma>\\<turnstile>DynCom c\\<down>Normal s}\n                DynCom c\n             {t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    apply (rule hoaret.DynCom)\n    apply (clarsimp)\n    apply (rule hyp' [simplified])\n    done\nnext\n  case (Guard f g c)\n  have hyp_c: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                              \\<Gamma>\\<turnstile>c\\<down>Normal s} \n                     c \n                   {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                   {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Guard by iprover\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Guard f g c\\<down> Normal s} \n                Guard f g c \n              {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  proof (cases \"f \\<in> F\")\n    case True\n    from hyp_c\n    have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>(g \\<inter> {s. s=Z \\<and> \n                     \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck}\\<union> Fault ` (-F))\\<and>\n                     \\<Gamma>\\<turnstile>Guard f g c\\<down> Normal s})\n                   c\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      apply (rule ConseqMGT)\n      apply (insert True)\n      apply  (auto simp add: final_notin_def intro: exec.intros \n                   elim: terminates_Normal_elim_cases)\n      done\n    from True this\n    show ?thesis\n      by (rule conseqPre [OF Guarantee]) auto\n  next\n    case False\n    from hyp_c\n    have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>(g \\<inter> {s. s \\<in> g \\<and> s=Z \\<and> \n                     \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck}\\<union> Fault ` (-F))\\<and>\n                     \\<Gamma>\\<turnstile>Guard f g c\\<down> Normal s} )\n                   c\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      apply (rule ConseqMGT)\n      apply clarify\n      apply (frule Guard_noFaultStuckD [OF _ False])\n      apply  (auto simp add: final_notin_def intro: exec.intros \n                   elim: terminates_Normal_elim_cases)\n      done\n    then show ?thesis\n      apply (rule conseqPre [OF hoaret.Guard])\n      apply clarify\n      apply (frule Guard_noFaultStuckD [OF _ False])\n      apply auto\n      done\n  qed\nnext\n  case Throw\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Throw,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Throw \\<down> Normal s}\n              Throw\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule conseqPre [OF hoaret.Throw]) \n       (blast intro: exec.intros terminates.intros)\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                        \\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s} \n                    c\\<^sub>1\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                   \\<Gamma>\\<turnstile>Catch c\\<^sub>1 c\\<^sub>2 \\<down> Normal s} \n                c\\<^sub>1\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t \\<and> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal t \\<and>\n                   \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\"\n    by (rule ConseqMGT)\n       (fastforce intro: exec.intros terminates.intros \n                 elim: terminates_Normal_elim_cases\n                 simp add: final_notin_def)\n  moreover\n  have \n    \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                     \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s} c\\<^sub>2\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow>Abrupt s \\<and> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s \\<and> \n                   \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} \n               c\\<^sub>2\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      by (rule ConseqMGT)\n         (fastforce intro: exec.intros terminates.intros \n                   simp add: noFault_def')\n  ultimately\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                   \\<Gamma>\\<turnstile>Catch c\\<^sub>1 c\\<^sub>2 \\<down> Normal s} \n                Catch c\\<^sub>1 c\\<^sub>2\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoaret.Catch )\nqed\n\n\n\n\n      assume \"Z \\<in> g\"\n      from this have \"\\<Gamma>\\<turnstile>(Guard f g c,Normal Z) \\<rightarrow> (c,Normal Z)\"\n        by (rule step.Guard)\n      from step_redexes [OF this c'] obtain c'' where\n        step: \"\\<Gamma>\\<turnstile> (c', Normal Z) \\<rightarrow> (c'', Normal Z)\"  and c'': \"c \\<in> redexes c''\"\n        by blast\n      note steps also note step \n      finally show \"\\<exists>c'. \\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z) \\<and> c \\<in> redexes c'\"\n        using c'' by blast\n    next\n      fix t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\" \n        \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n      thus \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n        using False\n        by (cases \"Z\\<in> g\") (auto simp add: final_notin_def intro: exec.intros )\n    next\n      fix t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\" \n             \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n      thus \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n        using False\n        by (cases \"Z\\<in> g\") (auto simp add: final_notin_def intro: exec.intros )\n    qed\n    then show ?thesis\n      apply (rule conseqPre [OF hoaret.Guard])\n      apply clarify\n      apply (frule Guard_noFaultStuckD [OF _ False])\n      apply auto\n      done\n  qed\nnext\n  case Throw\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Throw,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                  \\<Gamma>\\<turnstile>Call p\\<down>Normal \\<sigma> \\<and>\n                (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and> Throw \\<in> redexes c')}\n              Throw\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule conseqPre [OF hoaret.Throw]) \n       (blast intro: exec.intros terminates.intros)\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have hyp_c1:\n   \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s= Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call p \\<down> Normal \\<sigma> \\<and>\n                (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and> \n                      c\\<^sub>1 \\<in> redexes c')}\n               c\\<^sub>1 \n              {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  have hyp_c2:\n   \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s= Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                     \\<Gamma>\\<turnstile>Call p\\<down> Normal \\<sigma> \\<and>\n                (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and> c\\<^sub>2 \\<in> redexes c')}\n               c\\<^sub>2\n              {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  have\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n               \\<Gamma>\\<turnstile>Call p\\<down> Normal \\<sigma> \\<and>\n            (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>)\\<rightarrow>\\<^sup>+(c',Normal s) \\<and>\n                   Catch c\\<^sub>1 c\\<^sub>2 \\<in> redexes c')}\n            c\\<^sub>1\n           {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n           {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t \\<and> \n               \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault`(-F)) \\<and> \\<Gamma>\\<turnstile>Call p \\<down> Normal \\<sigma> \\<and>\n               (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal t) \\<and> c\\<^sub>2 \\<in> redexes c')}\"\n  proof (rule ConseqMGT [OF hyp_c1],clarify,safe) \n    assume \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n    thus \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n      by (fastforce simp add: final_notin_def intro: exec.intros)\n  next\n    fix c'\n    assume steps: \"\\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z)\" \n    assume c': \"Catch c\\<^sub>1 c\\<^sub>2 \\<in> redexes c'\"\n    from steps redexes_subset [OF this]\n    show \"\\<exists>c'. \\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z) \\<and> c\\<^sub>1 \\<in> redexes c'\"\n      by (auto iff:  root_in_redexes)\n  next\n    fix t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n    thus \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n      by (auto intro: exec.intros)\n  next\n    fix t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\" \n      \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n    thus \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n      by (auto simp add: final_notin_def intro: exec.intros)\n  next\n    fix c' t\n    assume steps_c': \"\\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z)\" \n    assume red: \"Catch c\\<^sub>1 c\\<^sub>2 \\<in> redexes c'\"\n    assume exec_c\\<^sub>1: \"\\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n    show \"\\<exists>c'. \\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal t) \\<and> c\\<^sub>2 \\<in> redexes c'\"\n    proof -\n      note steps_c'\n      also\n      from exec_impl_steps_Normal_Abrupt [OF exec_c\\<^sub>1]\n      have \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal Z) \\<rightarrow>\\<^sup>* (Throw, Normal t)\".\n      from steps_redexes_Catch [OF this red] \n      obtain c'' where\n        steps_c'': \"\\<Gamma>\\<turnstile> (c', Normal Z) \\<rightarrow>\\<^sup>* (c'', Normal t)\" and\n        Catch: \"Catch Throw c\\<^sub>2 \\<in> redexes c''\"\n        by blast\n      note steps_c''\n      also \n      have step_Catch: \"\\<Gamma>\\<turnstile> (Catch Throw c\\<^sub>2,Normal t) \\<rightarrow> (c\\<^sub>2,Normal t)\"\n        by (rule step.CatchThrow)\n      from step_redexes [OF step_Catch Catch]\n      obtain c''' where\n        step_c''': \"\\<Gamma>\\<turnstile> (c'', Normal t) \\<rightarrow> (c''', Normal t)\" and\n        c2: \"c\\<^sub>2 \\<in> redexes c'''\"\n        by blast\n      note step_c'''\n      finally show ?thesis\n        using c2\n        by blast\n    qed\n  qed\n  moreover\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t \\<and> \n                  \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                  \\<Gamma>\\<turnstile>Call p \\<down> Normal \\<sigma> \\<and>\n                  (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal t) \\<and> c\\<^sub>2 \\<in> redexes c')} \n               c\\<^sub>2\n              {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT [OF hyp_c2]) (fastforce intro: exec.intros)\n  ultimately show ?case\n    by (rule hoaret.Catch)\nqed\n\n\ntext {* To prove a procedure implementation correct it suffices to assume\n       only the procedure specifications of procedures that actually\n       occur during evaluation of the body.  \n    *}\n\nlemma Call_lemma:\n assumes A: \n \"\\<forall>q \\<in> dom \\<Gamma>. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> \n                 {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call q\\<down>Normal s \\<and> ((s,q),(\\<sigma>,p)) \\<in> termi_call_steps \\<Gamma>}\n                 (Call q)\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n assumes pdef: \"p \\<in> dom \\<Gamma>\"\n shows \"\\<And>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>  \n              ({\\<sigma>} \\<inter> {s. s=Z \\<and>\\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>  \n                                 \\<Gamma>\\<turnstile>the (\\<Gamma> p)\\<down>Normal s}) \n                 the (\\<Gamma> p) \n              {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (rule conseqPre)\napply (rule Call_lemma' [OF A])\nusing pdef\napply (fastforce intro: terminates.intros tranclp.r_into_trancl [of \"(step \\<Gamma>)\", OF step.Call] root_in_redexes)\ndone\n\nlemma Call_lemma_switch_Call_body:\n assumes \n call: \"\\<forall>q \\<in> dom \\<Gamma>. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> \n                 {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call q\\<down>Normal s \\<and> ((s,q),(\\<sigma>,p)) \\<in> termi_call_steps \\<Gamma>}\n                 (Call q)\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n assumes p_defined: \"p \\<in> dom \\<Gamma>\"\n shows \"\\<And>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>  \n              ({\\<sigma>} \\<inter> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>  \n                                 \\<Gamma>\\<turnstile>Call p\\<down>Normal s}) \n                 the (\\<Gamma> p) \n              {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (simp only: exec_Call_body' [OF p_defined] noFaultStuck_Call_body' [OF p_defined] terminates_Normal_Call_body [OF p_defined])\napply (rule conseqPre)\napply (rule Call_lemma')\napply (rule call)\nusing p_defined\napply (fastforce intro: terminates.intros tranclp.r_into_trancl [of \"(step \\<Gamma>)\", OF step.Call] \nroot_in_redexes)\ndone\n\nlemma MGT_Call:\n\"\\<forall>p \\<in> dom \\<Gamma>. \\<forall>Z. \n  \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n             \\<Gamma>\\<turnstile>(Call p)\\<down>Normal s}\n           (Call p)\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (intro ballI allI)\napply (rule CallRec' [where Procs=\"dom \\<Gamma>\" and\n    P=\"\\<lambda>p Z. {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call p\\<down>Normal s}\" and\n    Q=\"\\<lambda>p Z. {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t}\" and\n    A=\"\\<lambda>p Z. {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" and\n    r=\"termi_call_steps \\<Gamma>\"\n    ]) \napply    simp\napply   simp\napply  (rule wf_termi_call_steps)\napply (intro ballI allI)\napply simp\napply (rule Call_lemma_switch_Call_body [rule_format, simplified])\napply  (rule hoaret.Asm)\napply  fastforce\napply assumption\ndone\n\n\nlemma CollInt_iff: \"{s. P s} \\<inter> {s. Q s} = {s. P s \\<and> Q s}\"\n  by auto\n\nlemma image_Un_conv: \"f ` (\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. {x p Z}) =  (\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. {f (x p Z)})\"\n  by (auto iff: not_None_eq)\n\n\ntext {* Another proof of @{text MGT_Call}, maybe a little more readable *}\nlemma \n\"\\<forall>p \\<in> dom \\<Gamma>. \\<forall>Z. \n  \\<Gamma>,{} \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n             \\<Gamma>\\<turnstile>(Call p)\\<down>Normal s}\n           (Call p)\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\nproof -\n  {\n    fix p Z \\<sigma>\n    assume defined: \"p \\<in> dom \\<Gamma>\"\n    def Specs == \"(\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. \n            {({s. s=Z \\<and> \n              \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n              \\<Gamma>\\<turnstile>Call p\\<down>Normal s},\n             p,\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})})\"\n    def Specs_wf == \"(\\<lambda>p \\<sigma>. (\\<lambda>(P,q,Q,A). \n                       (P \\<inter> {s. ((s,q),\\<sigma>,p) \\<in> termi_call_steps \\<Gamma>}, q, Q, A)) ` Specs)\"\n    have \"\\<Gamma>,Specs_wf p \\<sigma>\n            \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>({\\<sigma>} \\<inter>\n                 {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                  \\<Gamma>\\<turnstile>the (\\<Gamma> p)\\<down>Normal s}) \n                (the (\\<Gamma> p))\n               {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      apply (rule Call_lemma [rule_format, OF _ defined])\n      apply (rule hoaret.Asm)\n      apply (clarsimp simp add: Specs_wf_def Specs_def image_Un_conv)\n      apply (rule_tac x=q in bexI)\n      apply (rule_tac x=Z in exI)\n      apply (clarsimp simp add: CollInt_iff)\n      apply auto\n      done\n    hence \"\\<Gamma>,Specs_wf p \\<sigma>\n            \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>({\\<sigma>} \\<inter>\n                 {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                  \\<Gamma>\\<turnstile>Call p\\<down>Normal s}) \n                (the (\\<Gamma> p))\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      by (simp only: exec_Call_body' [OF defined] \n                   noFaultStuck_Call_body' [OF defined] \n                  terminates_Normal_Call_body [OF defined])\n  } note bdy=this\n  show ?thesis\n    apply (intro ballI allI)\n    apply (rule hoaret.CallRec [where Specs=\"(\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. \n            {({s. s=Z \\<and> \n              \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n              \\<Gamma>\\<turnstile>Call p\\<down>Normal s},\n             p,\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})})\", \n             OF _ wf_termi_call_steps [of \\<Gamma>] refl])\n    apply fastforce\n    apply clarify\n    apply (rule conjI)\n    apply  fastforce\n    apply (rule allI)\n    apply (simp (no_asm_use) only : Un_empty_left)\n    apply (rule bdy)\n    apply auto\n    done\nqed\n\n\ntheorem hoaret_complete: \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (iprover intro: MGT_implies_complete MGT_lemma [OF MGT_Call])\n\nlemma hoaret_complete': \n  assumes cvalid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (cases \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\")\n  case True\n  hence \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (rule hoaret_complete)\n  thus \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (rule hoaret_augment_context) simp\nnext\n  case False\n  with cvalid\n  show ?thesis\n    by (rule ExFalso)\nqed\n\nsubsection {* And Now: Some Useful Rules *}\n\nsubsubsection {* Modify Return *}\n\nlemma ProcModifyReturn_sound:\n  assumes valid_call: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P call init p return' c Q,A\"\n  assumes valid_modif: \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call p) (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \n  assumes res_modif:\n  \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\n  assumes ret_modifAbr: \n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\n  shows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>call init p return c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from exec\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: exec_call_Normal_elim)\n    fix bdy t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\" \n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> \\<Rightarrow> t\" \n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>(Call p ),Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with res_modif have \"Normal (return' s t') = Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy \n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_call)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\" \n    assume t: \"t = Abrupt (return s t')\"\n    also from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>(Call p),Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_callAbrupt)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy f\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Fault f\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callFault)\n    from cvalidt_postD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Stuck\"  \n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callStuck)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    assume \"\\<Gamma> p = None\" \"t=Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callUndefined)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults)\n  assume P: \"s \\<in> P\"\n  from valid_call ctxt P\n  have call: \"\\<Gamma>\\<turnstile>call init p return' c\\<down> Normal s\"\n    by (rule cvalidt_termD)\n  show \"\\<Gamma>\\<turnstile>call init p return c \\<down> Normal s\"\n  proof (cases \"p \\<in> dom \\<Gamma>\")\n    case True\n    with call obtain bdy where \n      bdy: \"\\<Gamma> p = Some bdy\" and termi_bdy: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\" and \n      termi_c: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>c s t \\<down> Normal (return' s t)\"\n      by cases auto \n    {\n      fix t\n      assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n      hence \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n      proof -\n        from exec_bdy bdy\n        have \"\\<Gamma>\\<turnstile>\\<langle>(Call p ),Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n          by (auto simp add: intro: exec.intros)\n        from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P \n          res_modif\n        have \"return' s t = return s t\"\n          by auto\n        with termi_c exec_bdy show ?thesis by auto\n      qed\n    }\n    with bdy termi_bdy\n    show ?thesis\n      by (iprover intro: terminates_call)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates_callUndefined)\n  qed\nqed\n\nlemma ProcModifyReturn:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes res_modif:\n  \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes ret_modifAbr: \n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:    \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call p) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule hoaret_complete') \napply (rule ProcModifyReturn_sound [where Modif=Modif and ModifAbr=ModifAbr, \n        OF _ _ res_modif ret_modifAbr])\napply (rule hoaret_sound [OF spec])\nusing modifies_spec\napply (blast intro: hoare_sound)\ndone\n\nlemma ProcModifyReturnSameFaults_sound:\n  assumes valid_call: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P call init p return' c Q,A\"\n  assumes valid_modif: \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call p (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \n  assumes res_modif:\n  \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\n  assumes ret_modifAbr: \n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\n  shows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>call init p return c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from exec\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: exec_call_Normal_elim)\n    fix bdy t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\" \n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> \\<Rightarrow> t\" \n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>(Call p) ,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with res_modif have \"Normal (return' s t') = Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy \n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_call)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\" \n    assume t: \"t = Abrupt (return s t')\"\n    also \n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call p ,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_callAbrupt)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy f\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Fault f\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callFault)\n    from cvalidt_postD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Stuck\"  \n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callStuck)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    assume \"\\<Gamma> p = None\" \"t=Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callUndefined)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  assume P: \"s \\<in> P\"\n  from valid_call ctxt P\n  have call: \"\\<Gamma>\\<turnstile>call init p return' c\\<down> Normal s\"\n    by (rule cvalidt_termD)\n  show \"\\<Gamma>\\<turnstile>call init p return c \\<down> Normal s\"\n  proof (cases \"p \\<in> dom \\<Gamma>\")\n    case True\n    with call obtain bdy where \n      bdy: \"\\<Gamma> p = Some bdy\" and termi_bdy: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\" and \n      termi_c: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>c s t \\<down> Normal (return' s t)\"\n      by cases auto \n    {\n      fix t\n      assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n      hence \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n      proof -\n        from exec_bdy bdy\n        have \"\\<Gamma>\\<turnstile>\\<langle>(Call p ),Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n          by (auto simp add: intro: exec.intros)\n        from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P \n          res_modif\n        have \"return' s t = return s t\"\n          by auto\n        with termi_c exec_bdy show ?thesis by auto\n      qed\n    }\n    with bdy termi_bdy\n    show ?thesis\n      by (iprover intro: terminates_call)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates_callUndefined)\n  qed\nqed\n\nlemma ProcModifyReturnSameFaults:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes res_modif:\n  \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes ret_modifAbr: \n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:    \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} (Call p) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule hoaret_complete') \napply (rule ProcModifyReturnSameFaults_sound [where Modif=Modif and ModifAbr=ModifAbr,\n          OF _ _ res_modif ret_modifAbr])\napply (rule hoaret_sound [OF spec])\nusing modifies_spec\napply (blast intro: hoare_sound)\ndone\n\n\nsubsubsection {* DynCall *}\n\n\nlemma dynProcModifyReturn_sound:\nassumes valid_call: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes valid_modif: \n    \"\\<forall>s\\<in>P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call (p s)) (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\nshows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  assume P: \"s \\<in> P\"\n  with valid_modif \n  have valid_modif': \n    \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call (p s)) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n    by blast\n  from exec\n  have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return c,Normal s\\<rangle> \\<Rightarrow> t\"\n    by (cases rule: exec_dynCall_Normal_elim)\n  then show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: exec_call_Normal_elim)\n    fix bdy t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\" \n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> \\<Rightarrow> t\" \n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s),Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: exec.Call)\n    from cvalidD [OF valid_modif' [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with ret_modif have \"Normal (return' s t') = \n      Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_call)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\" \n    assume t: \"t = Abrupt (return s t')\"\n    also from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s) ,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif' [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_callAbrupt)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy f\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Fault f\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callFault)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by blast\n  next\n    fix bdy\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Stuck\"  \n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callStuck)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    fix bdy\n    assume \"\\<Gamma> (p s) = None\" \"t=Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callUndefined)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults)\n  assume P: \"s \\<in> P\"\n  from valid_call ctxt P\n  have \"\\<Gamma>\\<turnstile>dynCall init p return' c\\<down> Normal s\"\n    by (rule cvalidt_termD)\n  hence call: \"\\<Gamma>\\<turnstile>call init (p s) return' c\\<down> Normal s\"\n    by cases\n  have \"\\<Gamma>\\<turnstile>call init (p s) return c \\<down> Normal s\"\n  proof (cases \"p s \\<in> dom \\<Gamma>\")\n    case True\n    with call obtain bdy where \n      bdy: \"\\<Gamma> (p s) = Some bdy\" and termi_bdy: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\" and \n      termi_c: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>c s t \\<down> Normal (return' s t)\"\n      by cases auto \n    {\n      fix t\n      assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n      hence \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n      proof -\n        from exec_bdy bdy\n        have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s),Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n          by (auto simp add: intro: exec.intros)\n        from cvalidD [OF valid_modif [rule_format, of s \"init s\"] ctxt' this] P \n          ret_modif\n        have \"return' s t = return s t\"\n          by auto\n        with termi_c exec_bdy show ?thesis by auto\n      qed\n    }\n    with bdy termi_bdy\n    show ?thesis\n      by (iprover intro: terminates_call)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates_callUndefined)\n  qed\n  thus \"\\<Gamma>\\<turnstile>dynCall init p return c \\<down> Normal s\"\n    by (iprover intro: terminates_dynCall)\nqed\n\nlemma dynProcModifyReturn:\nassumes dyn_call: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s) \n           \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s) \n                             \\<longrightarrow> return' s t = return s t\"\nassumes modif: \n    \"\\<forall>s \\<in> P. \\<forall>\\<sigma>.  \n       \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \nshows \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\napply (rule hoaret_complete')\napply (rule dynProcModifyReturn_sound \n        [where Modif=Modif and ModifAbr=ModifAbr,\n            OF hoaret_sound [OF dyn_call] _ ret_modif ret_modifAbr])\napply (intro ballI allI)\napply (rule hoare_sound [OF modif [rule_format]])\napply assumption\ndone\n\nlemma dynProcModifyReturnSameFaults_sound:\nassumes valid_call: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes valid_modif: \n    \"\\<forall>s\\<in>P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\nshows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  assume P: \"s \\<in> P\"\n  with valid_modif \n  have valid_modif': \n    \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} (Call (p s)) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n    by blast\n  from exec\n  have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return c,Normal s\\<rangle> \\<Rightarrow> t\"\n    by (cases rule: exec_dynCall_Normal_elim)\n  then show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: exec_call_Normal_elim)\n    fix bdy t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\" \n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> \\<Rightarrow> t\" \n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s),Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif' [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with ret_modif have \"Normal (return' s t') = \n      Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_call)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\" \n    assume t: \"t = Abrupt (return s t')\"\n    also from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s)  ,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif' [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_callAbrupt)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy f\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Fault f\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callFault)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Stuck\"  \n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callStuck)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    fix bdy\n    assume \"\\<Gamma> (p s) = None\" \"t=Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callUndefined)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  assume P: \"s \\<in> P\"\n  from valid_call ctxt P\n  have \"\\<Gamma>\\<turnstile>dynCall init p return' c\\<down> Normal s\"\n    by (rule cvalidt_termD)\n  hence call: \"\\<Gamma>\\<turnstile>call init (p s) return' c\\<down> Normal s\"\n    by cases\n  have \"\\<Gamma>\\<turnstile>call init (p s) return c \\<down> Normal s\"\n  proof (cases \"p s \\<in> dom \\<Gamma>\")\n    case True\n    with call obtain bdy where \n      bdy: \"\\<Gamma> (p s) = Some bdy\" and termi_bdy: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\" and \n      termi_c: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>c s t \\<down> Normal (return' s t)\"\n      by cases auto \n    {\n      fix t\n      assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n      hence \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n      proof -\n        from exec_bdy bdy\n        have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s),Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n          by (auto simp add: intro: exec.intros)\n        from cvalidD [OF valid_modif [rule_format, of s \"init s\"] ctxt' this] P \n          ret_modif\n        have \"return' s t = return s t\"\n          by auto\n        with termi_c exec_bdy show ?thesis by auto\n      qed\n    }\n    with bdy termi_bdy\n    show ?thesis\n      by (iprover intro: terminates_call)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates_callUndefined)\n  qed\n  thus \"\\<Gamma>\\<turnstile>dynCall init p return c \\<down> Normal s\"\n    by (iprover intro: terminates_dynCall)\nqed\n\nlemma dynProcModifyReturnSameFaults:\nassumes dyn_call: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\nassumes modif: \n    \"\\<forall>s \\<in> P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \nshows \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\napply (rule hoaret_complete')\napply (rule dynProcModifyReturnSameFaults_sound \n        [where Modif=Modif and ModifAbr=ModifAbr,\n          OF hoaret_sound [OF dyn_call] _ ret_modif ret_modifAbr])\napply (intro ballI allI)\napply (rule hoare_sound [OF modif [rule_format]])\napply assumption\ndone\n\nsubsubsection {* Conjunction of Postcondition *}\n\nlemma PostConjI_sound:\n  assumes valid_Q: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes valid_R: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c R,B\"\n  shows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from valid_Q ctxt exec P t_notin_F have \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    by (rule cvalidt_postD)\n  moreover\n  from valid_R ctxt exec P t_notin_F have \"t \\<in> Normal ` R \\<union> Abrupt ` B\"\n    by (rule cvalidt_postD)\n  ultimately show \"t \\<in> Normal ` (Q \\<inter> R) \\<union> Abrupt ` (A \\<inter> B)\"\n    by blast\nnext \n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  from valid_Q ctxt P\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule cvalidt_termD)\nqed\n\nlemma PostConjI:\n  assumes deriv_Q: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" \n  assumes deriv_R: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c R,B\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\napply (rule hoaret_complete')\napply (rule PostConjI_sound)\napply (rule hoaret_sound [OF deriv_Q])\napply (rule hoaret_sound [OF deriv_R])\ndone\n\n\nlemma Merge_PostConj_sound: \n  assumes validF: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes validG: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/G\\<^esub> P' c R,X\"\n  assumes F_G: \"F \\<subseteq> G\"\n  assumes P_P': \"P \\<subseteq> P'\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> X)\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  with F_G have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/G\\<^esub> P (Call p) Q,A\" \n    by (auto intro: validt_augment_Faults)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\" \n  with P_P' have P': \"s \\<in> P'\"\n    by auto\n  assume t_noFault: \"t \\<notin> Fault ` F\"\n  show \"t \\<in> Normal ` (Q \\<inter> R) \\<union> Abrupt ` (A \\<inter> X)\"\n  proof -\n    from cvalidt_postD [OF validF [rule_format] ctxt exec P t_noFault]\n    have \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\n    moreover from this have \"t \\<notin> Fault ` G\"\n      by auto\n    from cvalidt_postD [OF validG [rule_format] ctxt' exec P' this]\n    have \"t \\<in> Normal ` R \\<union> Abrupt ` X\" .\n    ultimately show ?thesis by auto\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  from validF ctxt P\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule cvalidt_termD)\nqed\n\n\n\nlemma Merge_PostConj: \n  assumes validF: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes validG: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/G\\<^esub> P' c R,X\"\n  assumes F_G: \"F \\<subseteq> G\"\n  assumes P_P': \"P \\<subseteq> P'\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> X)\"\napply (rule hoaret_complete')\napply (rule Merge_PostConj_sound [OF _ _ F_G P_P'])\nusing validF apply (blast intro:hoaret_sound)\nusing validG apply (blast intro:hoaret_sound)\ndone\n\n\nsubsubsection {* Guards and Guarantees *}\n\nlemma SplitGuards_sound:\n  assumes valid_c1: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,A\"\n  assumes valid_c2: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>2 UNIV,UNIV\"\n  assumes c: \"(c\\<^sub>1 \\<inter>\\<^sub>g c\\<^sub>2) = Some c\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def) \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases t)\n    case Normal\n    with inter_guards_exec_noFault [OF c exec]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t\" by simp\n    from valid_c1 ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    case Abrupt\n    with inter_guards_exec_noFault [OF c exec]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t\" by simp\n    from valid_c1 ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    case (Fault f)\n    assume t: \"t=Fault f\"\n    with exec inter_guards_exec_Fault [OF c]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Fault f \\<or> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow> Fault f\"\n      by auto\n    then show ?thesis\n    proof (cases rule: disjE [consumes 1])\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Fault f\"\n      from cvalidt_postD [OF valid_c1 ctxt this P] t t_notin_F\n      show ?thesis\n        by blast\n    next\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow> Fault f\"\n      from cvalidD [OF valid_c2 ctxt' this P] t t_notin_F\n      show ?thesis\n        by blast\n    qed\n  next\n    case Stuck\n    with inter_guards_exec_noFault [OF c exec]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t\" by simp\n    from valid_c1 ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n  proof -\n    from valid_c1 ctxt P\n    have \"\\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s\"\n      by (rule cvalidt_termD)\n    with c show ?thesis\n      by (rule inter_guards_terminates)\n  qed\nqed\n\nlemma SplitGuards: \n  assumes c: \"(c\\<^sub>1 \\<inter>\\<^sub>g c\\<^sub>2) = Some c\" \n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,A\" \n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>2 UNIV,UNIV\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule SplitGuards_sound [OF _ _ c])\napply (rule hoaret_sound [OF deriv_c1])\napply (rule hoare_sound [OF deriv_c2])\ndone\n\nlemma CombineStrip_sound:\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes valid_strip: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/{}\\<^esub> P (strip_guards (-F) c) UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n    by (auto simp add: validt_def)\n  from ctxt have ctxt'': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\" \n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases t)\n    case (Normal t')\n    from cvalidt_postD [OF valid ctxt'' exec P] Normal \n    show ?thesis\n      by auto\n  next\n    case (Abrupt t')\n    from cvalidt_postD [OF valid ctxt'' exec P] Abrupt \n    show ?thesis\n      by auto\n  next\n    case (Fault f)\n    show ?thesis\n    proof (cases \"f \\<in> F\")\n      case True\n      hence \"f \\<notin> -F\" by simp\n      with exec Fault\n      have \"\\<Gamma>\\<turnstile>\\<langle>strip_guards (-F) c,Normal s\\<rangle> \\<Rightarrow> Fault f\" \n        by (auto intro: exec_to_exec_strip_guards_Fault)\n      from cvalidD [OF valid_strip ctxt' this P] Fault\n      have False\n        by auto\n      thus ?thesis ..\n    next\n      case False\n      with cvalidt_postD [OF valid ctxt'' exec P] Fault\n      show ?thesis\n        by auto\n    qed\n  next\n    case Stuck\n    from cvalidt_postD [OF valid ctxt'' exec P] Stuck\n    show ?thesis\n      by auto\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  assume P: \"s \\<in> P\"\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n  proof -\n    from valid ctxt' P\n    show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n      by (rule cvalidt_termD)\n  qed\nqed\n\nlemma CombineStrip:\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes deriv_strip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P (strip_guards (-F) c) UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule CombineStrip_sound)\napply  (iprover intro: hoaret_sound [OF deriv])\napply (iprover intro: hoare_sound [OF deriv_strip])\ndone\n\nlemma GuardsFlip_sound:\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes validFlip: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/-F\\<^esub> P c UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  from ctxt have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  from ctxt have ctxtFlip: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^bsub>/-F\\<^esub> P (Call p) Q,A\" \n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\" \n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases t)\n    case (Normal t')\n    from cvalidt_postD [OF valid ctxt' exec P] Normal \n    show ?thesis\n      by auto\n  next\n    case (Abrupt t')\n    from cvalidt_postD [OF valid ctxt' exec P] Abrupt \n    show ?thesis\n      by auto\n  next\n    case (Fault f)\n    show ?thesis\n    proof (cases \"f \\<in> F\")\n      case True\n      hence \"f \\<notin> -F\" by simp\n      with cvalidD [OF validFlip ctxtFlip exec P] Fault\n      have False\n        by auto\n      thus ?thesis ..\n    next\n      case False\n      with cvalidt_postD [OF valid ctxt' exec P] Fault\n      show ?thesis\n        by auto\n    qed\n  next\n    case Stuck\n    from cvalidt_postD [OF valid ctxt' exec P] Stuck\n    show ?thesis\n      by auto\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  assume P: \"s \\<in> P\"\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n  proof -\n    from valid ctxt' P\n    show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n      by (rule cvalidt_termD)\n  qed\nqed\n\n\nlemma GuardsFlip: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes derivFlip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/-F\\<^esub> P c UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule GuardsFlip_sound)\napply  (iprover intro: hoaret_sound [OF deriv])\napply (iprover intro: hoare_sound [OF derivFlip])\ndone\n\nlemma MarkGuardsI_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c,Normal s\\<rangle> \\<Rightarrow> t\" \n  from exec_mark_guards_to_exec [OF exec] obtain t' where\n    exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t'\" and\n    t'_noFault: \"\\<not> isFault t' \\<longrightarrow> t' = t\"\n    by blast\n  assume P: \"s \\<in> P\" \n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof -\n    from cvalidt_postD [OF valid [rule_format] ctxt exec_c P]\n    have \"t' \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by blast\n    with t'_noFault\n    show ?thesis\n      by auto\n  qed\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>mark_guards f c \\<down> Normal s\"\n    by (rule terminates_to_terminates_mark_guards)\nqed\n\nlemma MarkGuardsI: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\"\napply (rule hoaret_complete')\napply (rule MarkGuardsI_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\n\nlemma MarkGuardsD_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\" \n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\" \n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases \"isFault t\")\n    case True\n    with exec_to_exec_mark_guards_Fault exec\n    obtain f' where \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c,Normal s\\<rangle> \\<Rightarrow> Fault f'\"\n      by (fastforce elim: isFaultE)\n    from cvalidt_postD [OF valid [rule_format] ctxt this P]\n    have False\n      by auto\n    thus ?thesis ..\n  next\n    case False\n    from exec_to_exec_mark_guards [OF exec False]\n    obtain f' where \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by auto\n    from cvalidt_postD [OF valid [rule_format] ctxt this P]\n    show ?thesis\n      by auto\n  qed\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>mark_guards f c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule terminates_mark_guards_to_terminates)\nqed\n\nlemma MarkGuardsD: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule MarkGuardsD_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nlemma MergeGuardsI_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P merge_guards c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume exec_merge: \"\\<Gamma>\\<turnstile>\\<langle>merge_guards c,Normal s\\<rangle> \\<Rightarrow> t\"\n  from exec_merge_guards_to_exec [OF exec_merge] \n  have exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" .\n  assume P: \"s \\<in> P\" \n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec P t_notin_F]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>merge_guards c \\<down> Normal s\"\n    by (rule terminates_to_terminates_merge_guards)\nqed\n\nlemma MergeGuardsI: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P merge_guards c Q,A\"\napply (rule hoaret_complete')\napply (rule MergeGuardsI_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nlemma MergeGuardsD_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P merge_guards c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  from exec_to_exec_merge_guards [OF exec] \n  have exec_merge: \"\\<Gamma>\\<turnstile>\\<langle>merge_guards c,Normal s\\<rangle> \\<Rightarrow> t\".\n  assume P: \"s \\<in> P\" \n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec_merge P t_notin_F]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>merge_guards c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule terminates_merge_guards_to_terminates)\nqed\n\n\n\n\nlemma SubsetGuards_sound: \n  assumes c_c': \"c \\<subseteq>\\<^sub>g c'\"\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c' Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  from exec_to_exec_subseteq_guards [OF c_c' exec] obtain t' where\n    exec_c': \"\\<Gamma>\\<turnstile>\\<langle>c',Normal s\\<rangle> \\<Rightarrow> t'\" and\n    t'_noFault: \"\\<not> isFault t' \\<longrightarrow> t' = t\"\n    by blast\n  assume P: \"s \\<in> P\" \n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec_c' P] t'_noFault t_noFault\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    by auto\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have termi_c': \"\\<Gamma>\\<turnstile>c' \\<down> Normal s\".\n  from cvalidt_postD [OF valid ctxt _ P]\n  have noFault_c': \"\\<Gamma>\\<turnstile>\\<langle>c',Normal s\\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\"\n    by (auto simp add: final_notin_def)\n  from termi_c' c_c' noFault_c'\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule terminates_fewer_guards)\nqed\n\nlemma SubsetGuards: \n  assumes c_c': \"c \\<subseteq>\\<^sub>g c'\"\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c' Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule SubsetGuards_sound [OF c_c'])\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nlemma NormalizeD_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  hence exec_norm: \"\\<Gamma>\\<turnstile>\\<langle>normalize c,Normal s\\<rangle> \\<Rightarrow> t\" \n    by (rule exec_to_exec_normalize)\n  assume P: \"s \\<in> P\" \n  assume noFault: \"t \\<notin> Fault ` F\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec_norm P noFault]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>normalize c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule terminates_normalize_to_terminates)\nqed\n\nlemma NormalizeD: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule NormalizeD_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nlemma NormalizeI_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume \"\\<Gamma>\\<turnstile>\\<langle>normalize c,Normal s\\<rangle> \\<Rightarrow> t\" \n  hence exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n    by (rule exec_normalize_to_exec)\n  assume P: \"s \\<in> P\" \n  assume noFault: \"t \\<notin> Fault ` F\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec P noFault]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile> c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>normalize c \\<down> Normal s\"\n    by (rule terminates_to_terminates_normalize)\nqed\n\nlemma NormalizeI: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\napply (rule hoaret_complete')\napply (rule NormalizeI_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nsubsubsection {* Restricting the Procedure Environment *}\n\nlemma validt_restrict_to_validt:\nassumes validt_c: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nshows \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from validt_c\n  have valid_c: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\" by (simp add: validt_def)\n  hence \"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\" by (rule valid_restrict_to_valid)\n  moreover\n  {\n    fix s\n    assume P: \"s \\<in> P\"\n    have \"\\<Gamma>\\<turnstile>c\\<down>Normal s\"\n    proof -\n      from P validt_c have \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>c\\<down>Normal s\"\n        by (auto simp add: validt_def)\n      moreover\n      from P valid_c\n      have \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>{Stuck}\"\n        by (auto simp add: valid_def  final_notin_def)\n      ultimately show ?thesis\n        by (rule terminates_restrict_to_terminates)\n    qed\n   }\n   ultimately show ?thesis\n     by (auto simp add: validt_def)\nqed\n\n\nlemma augment_procs:\nassumes deriv_c: \"\\<Gamma>|\\<^bsub>M\\<^esub>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nshows \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule hoaret_complete)\n  apply (rule validt_restrict_to_validt)\n  apply (insert hoaret_sound [OF deriv_c])\n  by (simp add: cvalidt_def)\n\nsubsubsection {* Miscellaneous *}\n\nlemma augment_Faults:\nassumes deriv_c: \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nassumes F: \"F \\<subseteq> F'\"\nshows \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F'\\<^esub> P c Q,A\"\n  apply (rule hoaret_complete)\n  apply (rule validt_augment_Faults [OF _ F])\n  apply (insert hoaret_sound [OF deriv_c])\n  by (simp add: cvalidt_def)\n\nlemma TerminationPartial_sound:\n  assumes \"termination\": \"\\<forall>s \\<in> P. \\<Gamma>\\<turnstile>c\\<down>Normal s\"\n  assumes partial_corr: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nusing \"termination\" partial_corr \nby (auto simp add: cvalidt_def validt_def cvalid_def)\n\nlemma TerminationPartial:\n  assumes partial_deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes \"termination\": \"\\<forall>s \\<in> P. \\<Gamma>\\<turnstile>c\\<down>Normal s\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule hoaret_complete')\n  apply (rule TerminationPartial_sound [OF \"termination\"])\n  apply (rule hoare_sound [OF partial_deriv])\n  done\n\nlemma TerminationPartialStrip:\n  assumes partial_deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes \"termination\": \"\\<forall>s \\<in> P. strip F' \\<Gamma>\\<turnstile>strip_guards F' c\\<down>Normal s\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from \"termination\" have \"\\<forall>s \\<in> P. \\<Gamma>\\<turnstile>c\\<down>Normal s\"\n    by (auto intro: terminates_strip_guards_to_terminates \n      terminates_strip_to_terminates)\n  with partial_deriv\n  show ?thesis\n    by (rule TerminationPartial)\nqed\n\nlemma SplitTotalPartial:\n  assumes termi: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q',A'\"\n  assumes part: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from hoaret_sound [OF termi] hoare_sound [OF part]\n  have \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (fastforce simp add: cvalidt_def validt_def cvalid_def valid_def)\n  thus ?thesis\n    by (rule hoaret_complete')\nqed\n   \nlemma SplitTotalPartial':\n  assumes termi: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/UNIV\\<^esub> P c Q',A'\"\n  assumes part: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from hoaret_sound [OF termi] hoare_sound [OF part]\n  have \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (fastforce simp add: cvalidt_def validt_def cvalid_def valid_def)\n  thus ?thesis\n    by (rule hoaret_complete')\nqed\n \nend\n", "meta": {"author": "crizkallah", "repo": "checker-verification", "sha": "cd5101e57ef70dcdd1680db2de2f08521605bd7c", "save_path": "github-repos/isabelle/crizkallah-checker-verification", "path": "github-repos/isabelle/crizkallah-checker-verification/checker-verification-cd5101e57ef70dcdd1680db2de2f08521605bd7c/autocorres-1.0/c-parser/hoare-package/HoareTotalProps.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5813031051514763, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.2883808835179325}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\n(*\n * This file contains theorems for dealing with a \"simply\" lifted\n * heap, where each byte of memory can be accessed as one (and only)\n * type.\n *\n * This is a simpler model of Tuch's \"lift_t\" model, where nested\n * struct fields cannot be directly accessed as pointers.\n *)\n\ntheory TypHeapSimple\nimports\n  \"CParser.TypHeapLib\"\nbegin\n\n(*\n * Each address in the heap can contain one of three things:\n *\n *   - A type tag, which inidicates that this address is the first\n *     byte of an object;\n *\n *   - A footprint, which indicates that this address is a latter byte\n *     of an object;\n *\n *   - Nothing, which indicates that this address does not fall inside\n *     an object.\n *)\ndatatype heap_typ_contents =\n    HeapType typ_uinfo\n  | HeapFootprint\n  | HeapEmpty\n\n(*\n * Given a Tuch-style heap representation (where each memory location\n * contains a set of different types, representing nested field types)\n * calculate a single top-level type of the heap.\n *\n * We just want to commit to a single type for this heap location,\n * and nothing more.\n *)\ndefinition\n  heap_type_tag :: \"heap_typ_desc \\<Rightarrow> addr \\<Rightarrow> heap_typ_contents\"\nwhere\n  \"heap_type_tag d a \\<equiv>\n     (if fst (d a) = False \\<or> (\\<forall>x. (snd (d a)) x = None) \\<or> (\\<forall>x. (snd (d a)) x \\<noteq> None) then\n       HeapEmpty\n     else\n       case (snd (d a)) (GREATEST x. snd (d a) x \\<noteq> None) of\n         Some (_, False) \\<Rightarrow> HeapFootprint\n       | Some (x, True) \\<Rightarrow> HeapType x\n       | None \\<Rightarrow> HeapEmpty)\"\n\n(*\n * Determine if the heap has a valid footprint for the given type at\n * the given address.\n *\n * A valid footprint means that the user has committed that the given\n * memory location will only be used for the given type.\n *\n * A \"simple\" footprint differs from the Tuch-style because we only\n * commit to a single type, and have no support for accessing nested\n * structures.\n *)\ndefinition\n  valid_simple_footprint :: \"heap_typ_desc \\<Rightarrow> addr \\<Rightarrow> typ_uinfo \\<Rightarrow> bool\"\nwhere\n  \"valid_simple_footprint d x t \\<equiv>\n    heap_type_tag d x = HeapType t \\<and>\n      (\\<forall>y. y \\<in> {x + 1..+  (size_td t)- Suc 0} \\<longrightarrow> heap_type_tag d y = HeapFootprint)\"\n\nlemma valid_simple_footprintI:\n  \"\\<lbrakk> heap_type_tag d x = HeapType t; \\<And>y. y \\<in> {x + 1..+(size_td t) - Suc 0} \\<Longrightarrow> heap_type_tag d y = HeapFootprint \\<rbrakk>\n      \\<Longrightarrow> valid_simple_footprint d x t\"\n  by (clarsimp simp: valid_simple_footprint_def)\n\nlemma valid_simple_footprintD:\n  \"valid_simple_footprint d x t \\<Longrightarrow> heap_type_tag d x = HeapType t\"\n  by (simp add: valid_simple_footprint_def)\n\nlemma valid_simple_footprintD2:\n  \"\\<lbrakk> valid_simple_footprint d x t; y \\<in> {x + 1..+(size_td t) - Suc 0} \\<rbrakk> \\<Longrightarrow> heap_type_tag d y = HeapFootprint\"\n  by (simp add: valid_simple_footprint_def)\n\nlemma typ_slices_not_empty:\n    \"typ_slices (x::('a::{mem_type} itself)) \\<noteq> []\"\n  apply (clarsimp simp: typ_slices_def)\n  done\n\nlemma last_typ_slice_t:\n    \"(last (typ_slice_t t 0)) = (t, True)\"\n  apply (case_tac t)\n  apply clarsimp\n  done\n\nlemma if_eqI:\n \"\\<lbrakk> a \\<Longrightarrow> x = z; \\<not> a \\<Longrightarrow> y = z \\<rbrakk> \\<Longrightarrow> (if a then x else y) = z\"\n  by simp\n\nlemma heap_type_tag_ptr_retyp:\n    \"snd (s (ptr_val t)) = Map.empty \\<Longrightarrow>\n        heap_type_tag (ptr_retyp (t :: 'a::mem_type ptr) s) (ptr_val t) = HeapType (typ_uinfo_t TYPE('a))\"\n  apply (unfold ptr_retyp_def heap_type_tag_def)\n  apply (subst htd_update_list_index, fastforce, fastforce)+\n  apply (rule if_eqI)\n   apply clarsimp\n   apply (erule disjE)\n    apply (erule_tac x=0 in allE)\n    apply clarsimp\n   apply (erule_tac x=\"length (typ_slice_t (typ_uinfo_t TYPE('a)) 0)\" in allE)\n   apply (clarsimp simp: list_map_eq)\n  apply (clarsimp simp: list_map_eq last_conv_nth [simplified, symmetric] last_typ_slice_t\n            split: option.splits if_split_asm prod.splits)\n  done\n\nlemma not_snd_last_typ_slice_t:\n    \"k \\<noteq> 0 \\<Longrightarrow> \\<not> snd (last (typ_slice_t z k))\"\n  by (case_tac z, clarsimp)\n\nlemma heap_type_tag_ptr_retyp_rest:\n    \"\\<lbrakk> snd (s (ptr_val t + k)) = Map.empty; 0 < k; unat k < size_td (typ_uinfo_t TYPE('a)) \\<rbrakk> \\<Longrightarrow>\n        heap_type_tag (ptr_retyp (t :: 'a::mem_type ptr) s) (ptr_val t + k) = HeapFootprint\"\n  apply (unfold ptr_retyp_def heap_type_tag_def)\n  apply (subst htd_update_list_index, simp, clarsimp,\n      metis intvlI size_of_def word_unat.Rep_inverse)+\n  apply (rule if_eqI)\n   apply clarsimp\n   apply (erule disjE)\n    apply (erule_tac x=0 in allE)\n    apply (clarsimp simp: size_of_def)\n   apply (erule_tac x=\"length (typ_slice_t (typ_uinfo_t TYPE('a)) (unat k))\" in allE)\n   apply (clarsimp simp: size_of_def list_map_eq)\n  apply (clarsimp simp: list_map_eq last_conv_nth [simplified, symmetric] size_of_def\n      split: option.splits if_split_asm prod.splits bool.splits)\n   apply (metis surj_pair)\n  apply (subst (asm) (2) surjective_pairing)\n  apply (subst (asm) not_snd_last_typ_slice_t)\n   apply clarsimp\n   apply unat_arith\n  apply simp\n  done\n\nlemma typ_slices_addr_card [simp]:\n    \"length (typ_slices (x::('a::{mem_type} itself))) < addr_card\"\n  apply (clarsimp simp: typ_slices_def)\n  done\n\nlemma htd_update_list_same':\n  \"\\<lbrakk>0 < unat k; unat k \\<le> addr_card - length v\\<rbrakk> \\<Longrightarrow> htd_update_list (p + k) v h p = h p\"\n  apply (insert htd_update_list_same [where v=v and p=p and h=h and k=\"unat k\"])\n  apply clarsimp\n  done\n\nlemma unat_less_impl_less:\n    \"unat a < unat b \\<Longrightarrow> a < b\"\n  by unat_arith\n\nlemma valid_simple_footprint_ptr_retyp:\n    \"\\<lbrakk> \\<forall>k < size_td (typ_uinfo_t TYPE('a)). snd (s (ptr_val t + of_nat k)) = Map.empty;\n        1 \\<le> size_td (typ_uinfo_t TYPE('a));\n        size_td (typ_uinfo_t TYPE('a)) < addr_card \\<rbrakk>\n        \\<Longrightarrow> valid_simple_footprint (ptr_retyp (t :: 'a::mem_type ptr) s) (ptr_val t) (typ_uinfo_t TYPE('a))\"\n  apply (clarsimp simp: valid_simple_footprint_def)\n  apply (rule conjI)\n   apply (subst heap_type_tag_ptr_retyp)\n    apply (erule allE [where x=\"0\"])\n    apply clarsimp\n   apply clarsimp\n  apply (clarsimp simp: intvl_def)\n  apply (erule_tac x=\"k + 1\" in allE)\n  apply (erule impE)\n   apply (metis One_nat_def less_diff_conv)\n  apply (subst add.assoc, subst heap_type_tag_ptr_retyp_rest)\n     apply clarsimp\n    apply (case_tac \"1 + of_nat k = (0 :: addr)\")\n     apply (metis add.left_neutral intvlI intvl_Suc_nmem size_of_def)\n    apply unat_arith\n   apply clarsimp\n   apply (metis lt_size_of_unat_simps size_of_def Suc_eq_plus1 One_nat_def less_diff_conv of_nat_Suc)\n  apply simp\n  done\n\n(* Determine if the given pointer is valid in the given heap. *)\ndefinition\n  heap_ptr_valid :: \"heap_typ_desc \\<Rightarrow> 'a::c_type ptr \\<Rightarrow> bool\"\nwhere\n  \"heap_ptr_valid d p \\<equiv>\n      valid_simple_footprint d (ptr_val (p::'a ptr)) (typ_uinfo_t TYPE('a))\n        \\<and> c_guard p\"\n\n(*\n * Lift a heap from raw bytes and a heap description into\n * higher-level objects.\n *\n * This differs from Tuch's \"lift_t\" because we only support\n * simple lifting; that is, each byte in the heap may only\n * be accessed as a single type. Accessing struct fields by\n * their pointers is not supported.\n *)\ndefinition\n  simple_lift :: \"heap_raw_state \\<Rightarrow> ('a::c_type) ptr \\<Rightarrow> 'a option\"\nwhere\n  \"simple_lift s p = (\n     if (heap_ptr_valid (hrs_htd s) p) then\n       (Some (h_val (hrs_mem s) p))\n     else\n       None)\"\n\nlemma simple_lift_heap_ptr_valid:\n  \"simple_lift s p = Some x \\<Longrightarrow> heap_ptr_valid (hrs_htd s) p\"\n  apply (clarsimp simp: simple_lift_def split: if_split_asm)\n  done\n\nlemma simple_lift_c_guard:\n  \"simple_lift s p = Some x \\<Longrightarrow> c_guard p\"\n  apply (clarsimp simp: simple_lift_def heap_ptr_valid_def split: if_split_asm)\n  done\n\n(* Two valid footprints will either overlap completely or not at all. *)\nlemma valid_simple_footprint_neq:\n  assumes valid_p: \"valid_simple_footprint d p s\"\n      and valid_q: \"valid_simple_footprint d q t\"\n      and neq: \"p \\<noteq> q\"\n  shows \"p \\<notin> {q..+ (size_td t)}\"\nproof -\n  have heap_type_p: \"heap_type_tag d p = HeapType s\"\n    apply (metis valid_p valid_simple_footprint_def)\n    done\n\n  have heap_type_q: \"heap_type_tag d q = HeapType t\"\n    apply (metis valid_q valid_simple_footprint_def)\n    done\n\n  have heap_type_q_footprint:\n    \"\\<And>x. x \\<in> {(q + 1)..+(size_td t - Suc 0)} \\<Longrightarrow> heap_type_tag d x = HeapFootprint\"\n    apply (insert valid_q)\n    apply (simp add: valid_simple_footprint_def)\n    done\n\n  show ?thesis\n    using heap_type_q_footprint heap_type_p neq\n         intvl_neq_start heap_type_q\n    by (metis heap_typ_contents.simps(2))\nqed\n\n(* Two valid footprints with different types will never overlap. *)\nlemma valid_simple_footprint_type_neq:\n  \"\\<lbrakk> valid_simple_footprint d p s;\n     valid_simple_footprint d q t;\n     s \\<noteq> t \\<rbrakk> \\<Longrightarrow>\n   p \\<notin> {q..+ (size_td t)}\"\n  apply (subgoal_tac \"p \\<noteq> q\")\n   apply (rule valid_simple_footprint_neq, simp_all)[1]\n  apply (clarsimp simp: valid_simple_footprint_def)\n  done\n\nlemma valid_simple_footprint_neq_disjoint:\n  \"\\<lbrakk> valid_simple_footprint d p s; valid_simple_footprint d q t; p \\<noteq> q \\<rbrakk> \\<Longrightarrow>\n      {p..+(size_td s)} \\<inter> {q..+ (size_td t)} = {}\"\n  apply (rule ccontr)\n  apply (fastforce simp: valid_simple_footprint_neq dest!: intvl_inter)\n  done\n\nlemma valid_simple_footprint_type_neq_disjoint:\n  \"\\<lbrakk> valid_simple_footprint d p s;\n     valid_simple_footprint d q t;\n     s \\<noteq> t \\<rbrakk> \\<Longrightarrow>\n   {p..+(size_td s)} \\<inter> {q..+ (size_td t)} = {}\"\n  apply (subgoal_tac \"p \\<noteq> q\")\n   apply (rule valid_simple_footprint_neq_disjoint, simp_all)[1]\n  apply (clarsimp simp: valid_simple_footprint_def)\n  done\n\nlemma heap_ptr_valid_neq_disjoint:\n  \"\\<lbrakk> heap_ptr_valid d (p::'a::c_type ptr);\n     heap_ptr_valid d (q::'b::c_type ptr);\n     ptr_val p \\<noteq> ptr_val q \\<rbrakk> \\<Longrightarrow>\n   {ptr_val p..+size_of TYPE('a)} \\<inter>\n          {ptr_val q..+size_of TYPE('b)} = {}\"\n  apply (clarsimp simp only: size_of_tag [symmetric])\n  apply (rule valid_simple_footprint_neq_disjoint [where d=\"d\"])\n    apply (clarsimp simp: heap_ptr_valid_def)\n   apply (clarsimp simp: heap_ptr_valid_def)\n  apply simp\n  done\n\nlemma heap_ptr_valid_type_neq_disjoint:\n  \"\\<lbrakk> heap_ptr_valid d (p::'a::c_type ptr);\n     heap_ptr_valid d (q::'b::c_type ptr);\n     typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('b) \\<rbrakk> \\<Longrightarrow>\n   {ptr_val p..+size_of TYPE('a)} \\<inter>\n          {ptr_val q..+size_of TYPE('b)} = {}\"\n  apply (subgoal_tac \"ptr_val p \\<noteq> ptr_val q\")\n   apply (rule heap_ptr_valid_neq_disjoint, auto)[1]\n  apply (clarsimp simp: heap_ptr_valid_def valid_simple_footprint_def)\n  done\n\n(* If we update one pointer in the heap, other valid pointers will be unaffected. *)\nlemma heap_ptr_valid_heap_update_other:\n  assumes val_p: \"heap_ptr_valid d (p::'a::mem_type ptr)\"\n      and val_q: \"heap_ptr_valid d (q::'b::c_type ptr)\"\n      and neq: \"ptr_val p \\<noteq> ptr_val q\"\n  shows \"h_val (heap_update p v h) q = h_val h q\"\n  apply (clarsimp simp: h_val_def heap_update_def)\n  apply (subst heap_list_update_disjoint_same)\n   apply simp\n   apply (rule heap_ptr_valid_neq_disjoint [OF val_p val_q neq])\n  apply simp\n  done\n\n(* If we update one type in the heap, other types will be unaffected. *)\nlemma heap_ptr_valid_heap_update_other_typ:\n  assumes val_p: \"heap_ptr_valid d (p::'a::mem_type ptr)\"\n      and val_q: \"heap_ptr_valid d (q::'b::c_type ptr)\"\n      and neq: \"typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('b)\"\n  shows \"h_val (heap_update p v h) q = h_val h q\"\n  apply (clarsimp simp: h_val_def heap_update_def)\n  apply (subst heap_list_update_disjoint_same)\n   apply simp\n   apply (rule heap_ptr_valid_type_neq_disjoint [OF val_p val_q neq])\n  apply simp\n  done\n\n(* Updating the raw heap is equivalent to updating the lifted heap. *)\nlemma simple_lift_heap_update:\n  \"\\<lbrakk> heap_ptr_valid (hrs_htd h) p \\<rbrakk> \\<Longrightarrow>\n      simple_lift (hrs_mem_update (heap_update p v) h)\n          = (simple_lift h)(p := Some (v::'a::mem_type))\"\n  apply (rule ext)\n  apply (clarsimp simp: simple_lift_def hrs_mem_update h_val_heap_update)\n  apply (fastforce simp: heap_ptr_valid_heap_update_other)\n  done\n\n(* Updating the raw heap of one type doesn't affect the lifted heap of other types. *)\nlemma simple_lift_heap_update_other:\n  \"\\<lbrakk> heap_ptr_valid (hrs_htd d) (p::'b::mem_type ptr);\n     typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('b) \\<rbrakk> \\<Longrightarrow>\n   simple_lift (hrs_mem_update (heap_update p v) d) = ((simple_lift d)::'a::c_type typ_heap)\"\n  apply (rule ext)+\n  apply (clarsimp simp: simple_lift_def h_val_heap_update hrs_mem_update)\n  apply (auto intro: heap_ptr_valid_heap_update_other_typ)\n  done\n\nlemma h_val_simple_lift:\n  \"simple_lift h p = Some v \\<Longrightarrow> h_val (hrs_mem h) p = v\"\n  apply (clarsimp simp: simple_lift_def split: if_split_asm)\n  done\n\nlemma h_val_field_simple_lift:\n  \"\\<lbrakk> simple_lift h (pa :: 'a ptr) = Some (v::'a::mem_type);\n     \\<exists>t. field_ti TYPE('a) f = Some t;\n     export_uinfo (the (field_ti TYPE('a) f)) = export_uinfo (typ_info_t TYPE('b :: mem_type)) \\<rbrakk> \\<Longrightarrow>\n   h_val (hrs_mem h) (Ptr &(pa\\<rightarrow>f) :: 'b :: mem_type ptr) = from_bytes (access_ti\\<^sub>0 (the (field_ti TYPE('a) f)) v)\"\n  apply (clarsimp simp: simple_lift_def split: if_split_asm)\n  apply (clarsimp simp: h_val_field_from_bytes)\n  done\n\nlemma simple_lift_heap_update':\n  \"simple_lift h p = Some v' \\<Longrightarrow>\n      simple_lift (hrs_mem_update (heap_update (p::('a::{mem_type}) ptr) v) h)\n          = (simple_lift h)(p := Some v)\"\n  apply (rule simple_lift_heap_update)\n  apply (erule simple_lift_heap_ptr_valid)\n  done\n\nlemma simple_lift_hrs_mem_update_None [simp]:\n    \"(simple_lift (hrs_mem_update a hp) x = None) = (simple_lift hp x = None)\"\n  apply (clarsimp simp: simple_lift_def)\n  done\n\nlemma simple_lift_data_eq:\n   \"\\<lbrakk> h_val (hrs_mem h) p = h_val (hrs_mem h') p';\n     heap_ptr_valid (hrs_htd h) p = heap_ptr_valid (hrs_htd h') p' \\<rbrakk> \\<Longrightarrow>\n    simple_lift h p = simple_lift h' p'\"\n  apply (clarsimp simp: simple_lift_def)\n  done\n\nlemma h_val_heap_update_disjoint:\n  \"\\<lbrakk> {ptr_val p ..+ size_of TYPE('a::c_type)}\n        \\<inter> {ptr_val q ..+ size_of TYPE('b::mem_type)} = {} \\<rbrakk> \\<Longrightarrow>\n      h_val (heap_update (q :: 'b ptr) r h) (p :: 'a ptr) = h_val h p\"\n  apply (clarsimp simp: h_val_def)\n  apply (clarsimp simp: heap_update_def)\n  apply (subst heap_list_update_disjoint_same)\n   apply clarsimp\n   apply blast\n   apply clarsimp\n  done\n\nlemma update_ti_t_valid_size:\n  \"size_of TYPE('b) = size_td t \\<Longrightarrow>\n   update_ti_t t (to_bytes_p (val::'b::mem_type)) obj = update_ti t (to_bytes_p val) obj\"\n  apply (clarsimp simp: update_ti_t_def to_bytes_p_def)\n  done\n\nlemma h_val_field_from_bytes':\n  \"\\<lbrakk> field_ti TYPE('a::{mem_type}) f = Some t;\n     export_uinfo t = export_uinfo (typ_info_t TYPE('b::{mem_type})) \\<rbrakk> \\<Longrightarrow>\n    h_val h (Ptr &(pa\\<rightarrow>f) :: 'b ptr) = from_bytes (access_ti\\<^sub>0 t (h_val h pa))\"\n  apply (insert h_val_field_from_bytes[where f=f and pa=pa and t=t and h=\"(h,x)\"\n                                         and 'a='a and 'b='b for x])\n  apply (clarsimp simp: hrs_mem_def)\n  done\n\nlemma simple_lift_super_field_update_lookup:\n  fixes dummy :: \"'b :: mem_type\"\n  assumes \"field_lookup (typ_info_t TYPE('b::mem_type)) f 0 = Some (s,n)\"\n    and \"typ_uinfo_t TYPE('a) = export_uinfo s\"\n    and \"simple_lift h p = Some v'\"\n  shows \"(super_field_update_t (Ptr (&(p\\<rightarrow>f))) (v::'a::mem_type) ((simple_lift h)::'b ptr \\<Rightarrow> 'b option)) =\n          ((simple_lift h)(p \\<mapsto> field_update (field_desc s) (to_bytes_p v) v'))\"\nproof -\n  from assms have [simp]: \"unat (of_nat n :: addr) = n\"\n     apply (subst unat_of_nat)\n     apply (subst mod_less)\n      apply (drule td_set_field_lookupD)+\n      apply (drule td_set_offset_size)+\n      apply (subst len_of_addr_card)\n      apply (subst (asm) size_of_def [symmetric, where t=\"TYPE('b)\"])+\n      apply (subgoal_tac \"size_of TYPE('b) < addr_card\")\n       apply arith\n      apply simp\n     apply simp\n     done\n  from assms show ?thesis\n    apply (clarsimp simp: super_field_update_t_def)\n    apply (rule ext)\n    apply (clarsimp simp: field_lvalue_def split: option.splits)\n    apply (safe, simp_all)\n       apply (frule_tac v=v and v'=v' in update_field_update)\n       apply (clarsimp simp: field_of_t_def field_of_def typ_uinfo_t_def)\n       apply (frule_tac m=0 in field_names_SomeD2)\n        apply simp\n       apply clarsimp\n       apply (simp add: field_typ_def field_typ_untyped_def)\n       apply (frule field_lookup_export_uinfo_Some)\n       apply (frule_tac s=k in field_lookup_export_uinfo_Some)\n       apply simp\n       apply (drule (1) field_lookup_inject)\n        apply (subst typ_uinfo_t_def [symmetric, where t=\"TYPE('b)\"])\n        apply simp\n       apply simp\n      apply (drule field_of_t_mem)+\n      apply (case_tac h)\n      apply (clarsimp simp: simple_lift_def split: if_split_asm)\n      apply (drule (1) heap_ptr_valid_neq_disjoint)\n       apply simp\n      apply fast\n     apply (clarsimp simp: field_of_t_def field_of_def)\n     apply (subst (asm) td_set_field_lookup)\n      apply simp\n     apply simp\n     apply (frule field_lookup_export_uinfo_Some)\n     apply (simp add: typ_uinfo_t_def)\n    apply (clarsimp simp: field_of_t_def field_of_def)\n    apply (subst (asm) td_set_field_lookup)\n     apply simp\n    apply simp\n    apply (frule field_lookup_export_uinfo_Some)\n    apply (simp add: typ_uinfo_t_def)\n    done\nqed\n\nlemma field_offset_addr_card:\n  \"\\<exists>x. field_lookup (typ_info_t TYPE('a::mem_type)) f 0 = Some x\n    \\<Longrightarrow> field_offset TYPE('a) f < addr_card\"\n  apply (clarsimp simp: field_offset_def field_offset_untyped_def typ_uinfo_t_def)\n  apply (subst field_lookup_export_uinfo_Some)\n   apply assumption\n  apply (frule td_set_field_lookupD)\n  apply (drule td_set_offset_size)\n  apply (insert max_size [where ?'a=\"'a\"])\n  apply (clarsimp simp: size_of_def)\n  done\n\nlemma unat_of_nat_field_offset:\n  \"\\<exists>x. field_lookup (typ_info_t TYPE('a::mem_type)) f 0 = Some x \\<Longrightarrow>\n      unat (of_nat (field_offset TYPE('a) f)  :: addr) = field_offset TYPE('a) f\"\n  apply (subst word_unat.Abs_inverse)\n   apply (clarsimp simp: unats_def)\n   apply (insert field_offset_addr_card [where f=f and ?'a=\"'a\"])[1]\n   apply (fastforce simp: addr_card)\n  apply simp\n  done\n\nlemma field_of_t_field_lookup:\n  assumes a: \"field_lookup (typ_info_t TYPE('a::mem_type)) f 0 = Some (s, n)\"\n  assumes b: \"export_uinfo s = typ_uinfo_t TYPE('b::mem_type)\"\n  assumes n: \"n = field_offset TYPE('a) f\"\n  shows \"field_of_t (Ptr &(ptr\\<rightarrow>f) :: ('b ptr)) (ptr :: 'a ptr)\"\n  apply (clarsimp simp del: field_lookup_offset_eq\n                 simp: field_of_t_def field_of_def)\n  apply (subst td_set_field_lookup)\n   apply (rule wf_desc_typ_tag)\n  apply (rule exI [where x=f])\n  using a[simplified n] b\n  apply (clarsimp simp: typ_uinfo_t_def)\n  apply (subst field_lookup_export_uinfo_Some)\n   apply assumption\n  apply (clarsimp simp del: field_lookup_offset_eq\n                  simp: field_lvalue_def unat_of_nat_field_offset)\n  done\n\nlemma simple_lift_field_update':\n  fixes val :: \"'b :: mem_type\" and ptr :: \"'a :: mem_type ptr\"\n  assumes   fl: \"field_lookup (typ_info_t TYPE('a)) f 0 =\n                     Some (adjust_ti (typ_info_t TYPE('b)) xf xfu, n)\"\n  and   xf_xfu: \"fg_cons xf xfu\"\n  and       cl: \"simple_lift hp ptr = Some z\"\n  shows \"(simple_lift (hrs_mem_update (heap_update (Ptr &(ptr\\<rightarrow>f)) val) hp)) =\n                simple_lift hp(ptr \\<mapsto> xfu val z)\"\n    (is \"?LHS = ?RHS\")\nproof (rule ext)\n  fix p\n\n  have eui: \"typ_uinfo_t TYPE('b) =\n       export_uinfo (adjust_ti (typ_info_t TYPE('b)) xf xfu)\"\n    using xf_xfu\n    apply (subst export_tag_adjust_ti2 [OF _ wf_lf wf_desc])\n    apply (simp add: fg_cons_def )\n    apply (rule meta_eq_to_obj_eq [OF typ_uinfo_t_def])\n    done\n\n  have n_is_field_offset: \"n = field_offset TYPE('a) f\"\n    apply (insert field_lookup_offset_eq [OF fl])\n    apply (clarsimp)\n    done\n\n  have equal_case: \"?LHS ptr = ?RHS ptr\"\n    apply (insert cl)\n    apply (clarsimp simp: simple_lift_def split: if_split_asm)\n    apply (clarsimp simp: hrs_mem_update)\n    apply (subst h_val_super_update_bs)\n     apply (rule field_of_t_field_lookup [OF fl])\n      apply (clarsimp simp: eui)\n     apply (clarsimp simp: n_is_field_offset)\n    apply clarsimp\n    apply (unfold from_bytes_def)\n    apply (subst fi_fu_consistentD [where f=f and s=\"adjust_ti (typ_info_t TYPE('b)) xf xfu\"])\n        apply (clarsimp simp: fl)\n        apply (clarsimp simp: n_is_field_offset field_lvalue_def)\n        apply (metis unat_of_nat_field_offset fl)\n       apply clarsimp\n      apply (clarsimp simp: size_of_def)\n     apply (clarsimp simp: size_of_def)\n    apply clarsimp\n    apply (subst update_ti_s_from_bytes)\n     apply clarsimp\n    apply (subst update_ti_adjust_ti)\n     apply (rule xf_xfu)\n    apply (subst update_ti_s_from_bytes)\n     apply clarsimp\n    apply clarsimp\n    apply (clarsimp simp: h_val_def)\n    done\n\n  show \"?LHS p = ?RHS p\"\n    apply (case_tac \"p = ptr\")\n     apply (erule ssubst)\n     apply (rule equal_case)\n    apply (insert cl)\n    apply (clarsimp simp: simple_lift_def hrs_mem_update split: if_split_asm)\n    apply (rule h_val_heap_update_disjoint)\n    apply (insert field_tag_sub [OF fl, where p=ptr])\n    apply (clarsimp simp: size_of_def)\n    apply (clarsimp simp: heap_ptr_valid_def)\n    apply (frule (1) valid_simple_footprint_neq_disjoint, fastforce)\n    apply clarsimp\n    apply blast\n    done\nqed\n\nlemma simple_lift_field_update:\n  fixes val :: \"'b :: mem_type\" and ptr :: \"'a :: mem_type ptr\"\n  assumes   fl: \"field_ti TYPE('a) f =\n                     Some (adjust_ti (typ_info_t TYPE('b)) xf (xfu o (\\<lambda>x _. x)))\"\n  and   xf_xfu: \"fg_cons xf (xfu o (\\<lambda>x _. x))\"\n  and       cl: \"simple_lift hp ptr = Some z\"\n  shows \"(simple_lift (hrs_mem_update (heap_update (Ptr &(ptr\\<rightarrow>f)) val) hp)) =\n                simple_lift hp(ptr \\<mapsto> xfu (\\<lambda>_. val) z)\"\n    (is \"?LHS = ?RHS\")\n  apply (insert fl [unfolded field_ti_def])\n  apply (clarsimp split: option.splits)\n  apply (subst simple_lift_field_update' [where xf=xf and xfu=\"xfu o (\\<lambda>x _. x)\" and z=z])\n     apply (clarsimp simp: o_def split: option.splits)\n     apply (rule refl)\n    apply (rule xf_xfu)\n   apply (rule cl)\n  apply clarsimp\n  done\n\nlemma simple_heap_diff_types_impl_diff_ptrs:\n  \"\\<lbrakk> heap_ptr_valid h (p::('a::c_type) ptr);\n     heap_ptr_valid h (q::('b::c_type) ptr);\n     typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('b) \\<rbrakk> \\<Longrightarrow>\n   ptr_val p \\<noteq> ptr_val q\"\n  apply (clarsimp simp: heap_ptr_valid_def)\n  apply (clarsimp simp: valid_simple_footprint_def)\n  done\n\nlemma h_val_update_regions_disjoint:\n  \"\\<lbrakk> { ptr_val p ..+ size_of TYPE('a) } \\<inter> { ptr_val x ..+ size_of TYPE('b)} = {} \\<rbrakk> \\<Longrightarrow>\n        h_val (heap_update p (v::('a::mem_type)) h) x = h_val h (x::('b::c_type) ptr)\"\n  apply (clarsimp simp: heap_update_def)\n  apply (clarsimp simp: h_val_def)\n  apply (subst heap_list_update_disjoint_same)\n   apply clarsimp\n  apply clarsimp\n  done\n\nlemma simple_lift_field_update_t:\n  fixes    val :: \"'b :: mem_type\" and ptr :: \"'a :: mem_type ptr\"\n  assumes  fl: \"field_ti TYPE('a) f = Some t\"\n  and      diff: \"typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('c :: c_type)\"\n  and      eu: \"export_uinfo t = export_uinfo (typ_info_t TYPE('b))\"\n  and      cl: \"simple_lift hp ptr = Some z\"\n  shows \"((simple_lift (hrs_mem_update (heap_update (Ptr &(ptr\\<rightarrow>f)) val) hp)) :: 'c ptr \\<Rightarrow> 'c option) =\n             simple_lift hp\"\n  apply (rule ext)\n  apply (case_tac \"simple_lift hp x\")\n   apply clarsimp\n  apply (case_tac \"ptr_val x = ptr_val ptr\")\n   apply clarsimp\n   apply (clarsimp simp: simple_lift_def hrs_mem_update split: if_split_asm)\n   apply (cut_tac simple_lift_heap_ptr_valid [OF cl])\n   apply (drule (1) simple_heap_diff_types_impl_diff_ptrs [OF _ _ diff])\n   apply simp\n  apply (clarsimp simp: simple_lift_def hrs_mem_update split: if_split_asm)\n  apply (rule field_ti_field_lookupE [OF fl])\n  apply (frule_tac p=ptr in field_tag_sub)\n  apply (clarsimp simp: h_val_def heap_update_def)\n  apply (subst heap_list_update_disjoint_same)\n   apply clarsimp\n   apply (cut_tac simple_lift_heap_ptr_valid [OF cl])\n   apply (drule (2) heap_ptr_valid_neq_disjoint)\n   apply (clarsimp simp: export_size_of [unfolded typ_uinfo_t_def, OF eu])\n   apply blast\n  apply simp\n  done\n\nlemma simple_lift_heap_update_other':\n  \"\\<lbrakk> simple_lift h (p::'b::mem_type ptr) = Some v';\n     typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('b) \\<rbrakk> \\<Longrightarrow>\n   simple_lift (hrs_mem_update (heap_update p v) h) = ((simple_lift h)::'a::c_type typ_heap)\"\n  apply (rule simple_lift_heap_update_other)\n   apply (erule simple_lift_heap_ptr_valid)\n  apply simp\n  done\n\n(* If you update bytes inside an object of one type, it won't affect\n * heaps of other types. *)\nlemma simple_lift_heap_update_bytes_in_other:\n  \"\\<lbrakk> simple_lift h (p::'b::mem_type ptr) = Some v';\n     typ_uinfo_t TYPE('b) \\<noteq> typ_uinfo_t TYPE('c);\n     { ptr_val q ..+ size_of TYPE('a)} \\<subseteq> {ptr_val p  ..+ size_of TYPE('b) }  \\<rbrakk> \\<Longrightarrow>\n   simple_lift (hrs_mem_update (heap_update (q::'a::mem_type ptr) v) h) = ((simple_lift h)::'c::mem_type typ_heap)\"\n  apply (rule ext)\n  apply (clarsimp simp: simple_lift_def split: if_split_asm)\n  apply (drule (1) heap_ptr_valid_type_neq_disjoint, simp)\n  apply (clarsimp simp: hrs_mem_update)\n  apply (rule h_val_heap_update_disjoint)\n  apply blast\n  done\n\nlemma typ_name_neq:\n    \"typ_name (export_uinfo (typ_info_t TYPE('a::c_type)))\n        \\<noteq> typ_name (export_uinfo (typ_info_t TYPE('b::c_type)))\n    \\<Longrightarrow> typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('b)\"\n  apply (metis typ_uinfo_t_def)\n  done\n\nlemma of_nat_mod_div_decomp:\n  \"of_nat k\n        = of_nat (k div size_of TYPE('b)) * of_nat (size_of TYPE('b::mem_type)) +\n              of_nat (k mod size_of TYPE('b))\"\n  by (metis mod_div_decomp of_nat_add of_nat_mult)\n\nlemma c_guard_array_c_guard:\n  \"\\<lbrakk> \\<And>x. x < CARD('a) \\<Longrightarrow> c_guard (ptr_coerce p +\\<^sub>p int x :: 'b ptr) \\<rbrakk> \\<Longrightarrow> c_guard ( p :: ('b :: mem_type, 'a :: finite) array ptr)\"\n  apply atomize\n  apply (clarsimp simp: c_guard_def)\n  apply (rule conjI)\n   apply (drule_tac x=0 in spec)\n   apply (clarsimp simp: ptr_aligned_def align_of_def align_td_array)\n  apply (simp add: c_null_guard_def)\n  apply (clarsimp simp: intvl_def)\n  apply (drule_tac x=\"k div size_of TYPE('b)\" in spec)\n  apply (erule impE)\n   apply (metis (full_types) less_nat_zero_code mult_is_0 neq0_conv td_gal_lt)\n  apply clarsimp\n  apply (drule_tac x=\"k mod size_of TYPE('b)\" in spec)\n  apply (clarsimp simp: CTypesDefs.ptr_add_def)\n  apply (subst (asm) add.assoc)\n  apply (subst (asm) of_nat_mod_div_decomp [symmetric])\n  apply clarsimp\n  done\n\nlemma heap_list_update_list':\n  \"\\<lbrakk> n + x \\<le> length v; length v < addr_card; q = (p + of_nat x) \\<rbrakk> \\<Longrightarrow>\n      heap_list (heap_update_list p v h) n q = take n (drop x v)\"\n  by (metis heap_list_update_list)\n\nlemma outside_intvl_range:\n    \"p \\<notin> {a ..+ b} \\<Longrightarrow> p < a \\<or> p \\<ge> a + of_nat b\"\n  apply (clarsimp simp: intvl_def not_le not_less)\n  apply (drule_tac x=\"unat (p-a)\" in spec)\n  apply clarsimp\n  apply (metis add_diff_cancel2 le_less_linear le_unat_uoi\n      mpl_lem not_add_less2 unat_mono word_less_minus_mono_left)\n  done\n\nlemma first_in_intvl:\n  \"b \\<noteq> 0 \\<Longrightarrow> a \\<in> {a ..+ b}\"\n  by (force simp: intvl_def)\n\nlemma zero_not_in_intvl_no_overflow:\n  \"0 \\<notin> {a :: 'a::len word ..+ b} \\<Longrightarrow> unat a + b \\<le> 2 ^ len_of TYPE('a)\"\n  apply (rule ccontr)\n  apply (simp add: intvl_def not_le)\n  apply (drule_tac x=\"2 ^ len_of TYPE('a) - unat a\" in spec)\n  apply (clarsimp simp: not_less)\n  apply (erule disjE)\n   apply (metis (erased) diff_add_inverse less_imp_add_positive of_nat_2p of_nat_add\n                unat_lt2p word_neq_0_conv word_unat.Rep_inverse)\n  apply (metis le_add_diff_inverse le_antisym le_diff_conv le_refl\n               less_imp_le_nat add.commute not_add_less1 unat_lt2p)\n  done\n\nlemma intvl_split:\n  \"\\<lbrakk> n \\<ge> a \\<rbrakk> \\<Longrightarrow> { p :: ('a :: len) word ..+ n } = { p ..+ a } \\<union> { p + of_nat a ..+ (n - a)}\"\n  apply (rule set_eqI, rule iffI)\n   apply (clarsimp simp: intvl_def not_less)\n   apply (rule_tac x=k in exI)\n   apply clarsimp\n   apply (rule classical)\n   apply (drule_tac x=\"k - a\" in spec)\n   apply (clarsimp simp: not_less)\n   apply (metis diff_less_mono not_less)\n  apply (clarsimp simp: intvl_def not_less)\n  apply (rule_tac x=\"unat (x - p)\" in exI)\n  apply clarsimp\n  apply (erule disjE)\n   apply clarsimp\n   apply (metis le_unat_uoi less_or_eq_imp_le not_less order_trans)\n  apply clarsimp\n  apply (metis le_def le_eq_less_or_eq le_unat_uoi less_diff_conv\n    add.commute of_nat_add)\n  done\n\nlemma heap_ptr_valid_range_not_NULL:\n  \"heap_ptr_valid htd (p :: ('a :: c_type) ptr)\n      \\<Longrightarrow> 0 \\<notin> {ptr_val p ..+ size_of TYPE('a)}\"\n  apply (clarsimp simp: heap_ptr_valid_def)\n  apply (metis c_guard_def c_null_guard_def)\n  done\n\nlemma heap_ptr_valid_last_byte_no_overflow:\n  \"heap_ptr_valid htd (p :: ('a :: c_type) ptr)\n      \\<Longrightarrow> unat (ptr_val p) + size_of TYPE('a) \\<le> 2 ^ len_of TYPE(addr_bitsize)\"\n  by (metis c_guard_def c_null_guard_def heap_ptr_valid_def\n        zero_not_in_intvl_no_overflow)\n\nlemma heap_ptr_valid_intersect_array:\n  \"\\<lbrakk> \\<forall>j < n. heap_ptr_valid htd (p +\\<^sub>p int j);\n        heap_ptr_valid htd (q :: ('a :: c_type) ptr) \\<rbrakk>\n         \\<Longrightarrow> (\\<exists>m < n. q = (p +\\<^sub>p int m))\n    \\<or> ({ptr_val p ..+ size_of TYPE ('a) * n} \\<inter> {ptr_val q ..+ size_of TYPE ('a :: c_type)} = {})\"\n  apply (induct n)\n   apply clarsimp\n  apply atomize\n  apply simp\n  apply (case_tac \"n = 0\")\n   apply clarsimp\n   apply (metis heap_ptr_valid_neq_disjoint ptr_val_inj)\n  apply (erule disjE)\n   apply (metis less_Suc_eq)\n  apply (case_tac \"q = p +\\<^sub>p int n\")\n   apply force\n  apply (frule_tac x=n in spec)\n  apply (erule impE, simp)\n  apply (drule (1) heap_ptr_valid_neq_disjoint)\n  apply simp\n  apply (simp add: CTypesDefs.ptr_add_def)\n  apply (rule disjI2)\n  apply (cut_tac a=\" of_nat n * of_nat (size_of TYPE('a))\"\n      and p=\"ptr_val p\" and n=\"n * size_of TYPE('a) + size_of TYPE('a)\" in intvl_split)\n   apply clarsimp\n  apply (clarsimp simp: field_simps Int_Un_distrib2)\n  apply (metis IntI emptyE intvl_empty intvl_inter intvl_self neq0_conv)\n  done\n\n(* Simplification rules for dealing with \"lift_simple\". *)\n\nlemmas simple_lift_simps =\n  typ_name_neq\n  simple_lift_c_guard\n  h_val_simple_lift\n  simple_lift_heap_update'\n  simple_lift_heap_update_other'\n  c_guard_field\n  h_val_field_simple_lift\n  simple_lift_field_update\n  simple_lift_field_update_t\n  c_guard_array_field\n  nat_to_bin_string_simps\n\n(* Old name for the above simpset. *)\nlemmas typ_simple_heap_simps = simple_lift_simps\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/autocorres/TypHeapSimple.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6001883735630721, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.2883777163093083}}
{"text": "(* \n   Title: Psi-calculi   \n   Based on the AFP entry by Jesper Bengtson (jebe@itu.dk), 2012\n*)\ntheory Weak_Cong_Simulation\n  imports Weak_Simulation Tau_Chain\nbegin\n\ncontext env begin\n\ndefinition\n  \"weakCongSimulation\" :: \"'b \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow>\n                       ('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set \\<Rightarrow> \n                       ('a, 'b, 'c) psi \\<Rightarrow> bool\" (\"_ \\<rhd> _ \\<leadsto>\\<guillemotleft>_\\<guillemotright> _\" [80, 80, 80, 80] 80)\nwhere\n  \"\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q \\<equiv> \\<forall>Q'. \\<Psi> \\<rhd> Q \\<longmapsto>None @ \\<tau> \\<prec> Q' \\<longrightarrow> (\\<exists>P'. \\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P' \\<and> (\\<Psi>, P', Q') \\<in> Rel)\"\n\nabbreviation\n  weakCongSimulationNilJudge (\"_ \\<leadsto>\\<guillemotleft>_\\<guillemotright> _\" [80, 80, 80] 80) where \"P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q \\<equiv> \\<one> \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\n\nlemma weakCongSimI[case_names c_tau]:\n  fixes \\<Psi>   :: 'b\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   Rel :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q   :: \"('a, 'b, 'c) psi\"\n  and   C   :: \"'d::fs_name\"\n\n  assumes rTau:  \"\\<And>Q'. \\<Psi> \\<rhd> Q \\<longmapsto>None @ \\<tau> \\<prec> Q' \\<Longrightarrow> \\<exists>P'. \\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P' \\<and> (\\<Psi>, P', Q') \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\nusing assms\nby(auto simp add: weakCongSimulation_def)\n\n\nlemma weakCongSimE:\n  fixes F   :: 'b\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   Rel :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q   :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\n  and \"\\<Psi> \\<rhd> Q \\<longmapsto>None @ \\<tau> \\<prec> Q'\"\n\n  obtains P' where \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\" and \"(\\<Psi>, P', Q') \\<in> Rel\"\nusing assms\nby(auto simp add: weakCongSimulation_def)\n\nlemma weakCongSimClosedAux:\n  fixes \\<Psi>   :: 'b\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   Rel :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q   :: \"('a, 'b, 'c) psi\"\n  and   p   :: \"name prm\"\n\n  assumes EqvtRel: \"eqvt Rel\"\n  and     PSimQ: \"\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\n\n  shows \"(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P) \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> (p \\<bullet> Q)\"\nproof(induct rule: weakCongSimI)\n  case(c_tau Q')\n  from `p \\<bullet> \\<Psi> \\<rhd> p \\<bullet> Q \\<longmapsto>None @ \\<tau> \\<prec> Q'` \n  have \"(rev p \\<bullet> p \\<bullet> \\<Psi>) \\<rhd> (rev p \\<bullet> p \\<bullet> Q) \\<longmapsto>(rev p\\<bullet> None) @ (rev p \\<bullet> (\\<tau> \\<prec> Q'))\"\n    by(blast dest: semantics.eqvt)\n  hence \"\\<Psi> \\<rhd> Q \\<longmapsto>None @ \\<tau> \\<prec> (rev p \\<bullet> Q')\" by(simp add: eqvts)\n  with PSimQ obtain P' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\" and P'RelQ': \"(\\<Psi>, P', rev p \\<bullet> Q') \\<in> Rel\"\n    by(blast dest: weakCongSimE)\n  from PChain have \"(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P) \\<Longrightarrow>\\<^sub>\\<tau> (p \\<bullet> P')\" by(rule tau_step_chainEqvt)\n  moreover from P'RelQ' EqvtRel have \"(p \\<bullet> (\\<Psi>,  P', rev p \\<bullet> Q')) \\<in> Rel\"\n    by(simp only: eqvt_def)\n  hence \"(p \\<bullet> \\<Psi>, p \\<bullet> P', Q') \\<in> Rel\" by(simp add: eqvts)\n  ultimately show ?case\n    by blast\nqed\n\nlemma weakCongSimClosed:\n  fixes \\<Psi>   :: 'b\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   Rel :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q   :: \"('a, 'b, 'c) psi\"\n  and   p   :: \"name prm\"\n\n  assumes EqvtRel: \"eqvt Rel\"\n\n  shows \"\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q \\<Longrightarrow> (p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P) \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> (p \\<bullet> Q)\"\n  and   \"P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q \\<Longrightarrow> (p \\<bullet> P) \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> (p \\<bullet> Q)\"\nusing EqvtRel\nby(force dest: weakCongSimClosedAux simp add: perm_bottom)+\n\nlemma weakCongSimReflexive:\n  fixes Rel :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   \\<Psi>   :: 'b\n  and   P   :: \"('a, 'b, 'c) psi\"\n\n  assumes \"{(\\<Psi>, P, P) | \\<Psi> P. True} \\<subseteq> Rel\"\n\n  shows \"\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> P\"\nusing assms\nby(auto simp add: weakCongSimulation_def dest: rtrancl_into_rtrancl)\n\nlemma weakStepSimTauChain:\n  fixes \\<Psi>   :: 'b\n  and   Q   :: \"('a, 'b, 'c) psi\"\n  and   Q'  :: \"('a, 'b, 'c) psi\"\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   Rel :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n\n  assumes \"\\<Psi> \\<rhd> Q \\<Longrightarrow>\\<^sub>\\<tau> Q'\"\n  and     \"\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\n  and     Sim: \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> Rel \\<Longrightarrow> \\<Psi> \\<rhd> P \\<leadsto><Rel> Q\"\n  \n  obtains P' where \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\" and \"(\\<Psi>, P', Q') \\<in> Rel\"\nproof -\n  assume A: \"\\<And>P'. \\<lbrakk>\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'; (\\<Psi>, P', Q') \\<in> Rel\\<rbrakk> \\<Longrightarrow> thesis\"\n  from `\\<Psi> \\<rhd> Q \\<Longrightarrow>\\<^sub>\\<tau> Q'` `\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q` A show ?thesis\n  proof(induct arbitrary: P thesis rule: tau_step_chain_induct)\n    case(tau_base Q Q' P)\n    with `\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q` `\\<Psi> \\<rhd> Q \\<longmapsto>None @ \\<tau> \\<prec> Q'` obtain P' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\" and P'RelQ': \"(\\<Psi>, P', Q') \\<in> Rel\"\n      by(rule_tac weakCongSimE)\n    thus ?case by(rule tau_base)\n  next\n    case(tau_step Q Q' Q'' P)\n    from `\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q` obtain P' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\" and \"(\\<Psi>, P', Q') \\<in> Rel\"\n      by(rule tau_step)\n    from `(\\<Psi>, P', Q') \\<in> Rel` have \"\\<Psi> \\<rhd> P' \\<leadsto><Rel> Q'\" by(rule Sim)\n    then obtain P'' where P'Chain: \"\\<Psi> \\<rhd> P' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" and \"(\\<Psi>, P'', Q'') \\<in> Rel\"\n      using `\\<Psi> \\<rhd> Q' \\<longmapsto>None @ \\<tau> \\<prec> Q''` by(blast dest: weakSimE)\n    from PChain P'Chain have \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P''\" by simp\n    thus ?case using `(\\<Psi>, P'', Q'') \\<in> Rel` by(rule tau_step)\n  qed\nqed\n\nlemma weakCongSimTransitive:\n  fixes \\<Psi>     :: 'b\n  and   P      :: \"('a, 'b, 'c) psi\"\n  and   Rel    :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q      :: \"('a, 'b, 'c) psi\"\n  and   Rel'   :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   T      :: \"('a, 'b, 'c) psi\"\n  and   Rel''  :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n\n  assumes PRelQ: \"(\\<Psi>, P, Q) \\<in> Rel\"\n  and     PSimQ: \"\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\n  and     QSimR: \"\\<Psi> \\<rhd> Q \\<leadsto>\\<guillemotleft>Rel'\\<guillemotright> R\"\n  and     Set: \"{(\\<Psi>, P, R) | \\<Psi> P R. \\<exists>Q. (\\<Psi>, P, Q) \\<in> Rel \\<and> (\\<Psi>, Q, R) \\<in> Rel'} \\<subseteq> Rel''\"\n  and     Sim: \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> Rel \\<Longrightarrow> \\<Psi> \\<rhd> P \\<leadsto><Rel> Q\"\n\n  shows \"\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>Rel''\\<guillemotright> R\"\nproof(induct rule: weakCongSimI)\n  case(c_tau R')\n  from QSimR `\\<Psi> \\<rhd> R \\<longmapsto>None @ \\<tau> \\<prec> R'` obtain Q' where QChain: \"\\<Psi> \\<rhd> Q \\<Longrightarrow>\\<^sub>\\<tau> Q'\" and Q'RelR': \"(\\<Psi>, Q', R') \\<in> Rel'\" \n    by(blast dest: weakCongSimE)\n  from QChain PSimQ Sim obtain P' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\" and P'RelQ': \"(\\<Psi>, P', Q') \\<in> Rel\"\n    by(rule weakStepSimTauChain)\n  moreover from P'RelQ' Q'RelR' Set have \"(\\<Psi>, P', R') \\<in> Rel''\" by blast\n  ultimately show ?case by blast\nqed\n\nlemma weakCongSimStatEq:\n  fixes \\<Psi>   :: 'b\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   Rel :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q   :: \"('a, 'b, 'c) psi\"\n  and   \\<Psi>'  :: 'b\n\n  assumes PSimQ: \"\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\n  and     \"\\<Psi> \\<simeq> \\<Psi>'\"\n  and     C1: \"\\<And>\\<Psi> P Q \\<Psi>'. \\<lbrakk>(\\<Psi>, P, Q) \\<in> Rel; \\<Psi> \\<simeq> \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', P, Q) \\<in> Rel'\"\n\n  shows \"\\<Psi>' \\<rhd> P \\<leadsto>\\<guillemotleft>Rel'\\<guillemotright> Q\"\nproof(induct rule: weakCongSimI)\n  case(c_tau Q')\n  from `\\<Psi>' \\<rhd> Q \\<longmapsto>None @ \\<tau> \\<prec> Q'` `\\<Psi> \\<simeq> \\<Psi>'`\n  have \"\\<Psi> \\<rhd> Q \\<longmapsto>None @ \\<tau> \\<prec> Q'\" by(metis stat_eq_transition Assertion_stat_eq_sym)\n  with PSimQ obtain P' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\" and P'RelQ': \"(\\<Psi>, P', Q') \\<in> Rel\"\n    by(blast dest: weakCongSimE)\n  \n  from PChain `\\<Psi> \\<simeq> \\<Psi>'` have \"\\<Psi>' \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\" by(rule tau_step_chain_stat_eq)\n  moreover from `(\\<Psi>, P', Q') \\<in> Rel` `\\<Psi> \\<simeq> \\<Psi>'` have \"(\\<Psi>', P', Q') \\<in> Rel'\"\n    by(rule C1)\n  ultimately show ?case by blast\nqed\n\nlemma weakCongSimMonotonic: \n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   A :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   B :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>A\\<guillemotright> Q\"\n  and     \"A \\<subseteq> B\"\n\n  shows \"\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>B\\<guillemotright> Q\"\nusing assms\nby(simp (no_asm) add: weakCongSimulation_def) (blast dest: weakCongSimE)+\n\nlemma strongSimWeakCongSim:\n  fixes \\<Psi>   :: 'b\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   Rel :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q   :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<leadsto>[Rel] Q\"\n  and     \"Rel \\<subseteq> Rel'\"\n  \n  shows \"\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>Rel'\\<guillemotright> Q\"\nusing assms\napply(auto simp add: simulation_def weakCongSimulation_def)\nby(erule_tac x=\\<tau> in allE) (fastforce elim: tau_no_provenance')\n\nend\n\nend\n", "meta": {"author": "IlmariReissumies", "repo": "newpsi", "sha": "201517d55b6ed1632a5bff2a585367278b5bc67b", "save_path": "github-repos/isabelle/IlmariReissumies-newpsi", "path": "github-repos/isabelle/IlmariReissumies-newpsi/newpsi-201517d55b6ed1632a5bff2a585367278b5bc67b/Weak_Cong_Simulation.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6001883592602049, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.28837770943708557}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      HoareTotal.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection \\<open>Derived Hoare Rules for Total Correctness\\<close>\n\ntheory HoareTotal imports HoareTotalProps begin \n\nlemma conseq_no_aux:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A';\n    \\<forall>s. s \\<in> P \\<longrightarrow> (s\\<in>P' \\<and> (Q' \\<subseteq> Q)\\<and> (A' \\<subseteq> A))\\<rbrakk>\n  \\<Longrightarrow>\n  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule conseq [where P'=\"\\<lambda>Z. P'\" and Q'=\"\\<lambda>Z. Q'\" and A'=\"\\<lambda>Z. A'\"]) auto\n\ntext \\<open>If for example a specification for a \"procedure pointer\" parameter \nis in the precondition we can extract it with this rule\\<close>\nlemma conseq_exploit_pre:\n             \"\\<lbrakk>\\<forall>s \\<in> P. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s} \\<inter> P) c Q,A\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule Conseq)\n  apply clarify\n  apply (rule_tac x=\"{s} \\<inter> P\" in exI)  \n  apply (rule_tac x=\"Q\" in exI)  \n  apply (rule_tac x=\"A\" in exI)  \n  by simp\n\n\nlemma conseq:\"\\<lbrakk>\\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z);\n              \\<forall>s. s \\<in> P \\<longrightarrow> (\\<exists> Z. s\\<in>P' Z \\<and> (Q' Z \\<subseteq> Q)\\<and> (A' Z \\<subseteq> A))\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule Conseq') blast\n\n\nlemma Lem:\"\\<lbrakk>\\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z);\n            P \\<subseteq> {s. \\<exists> Z. s\\<in>P' Z \\<and> (Q' Z \\<subseteq> Q) \\<and> (A' Z \\<subseteq> A)}\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (lem x c) Q,A\"\n  apply (unfold lem_def) \n  apply (erule conseq)\n  apply blast\n  done\n\n\nlemma LemAnno:\nassumes conseq:  \"P \\<subseteq> {s. \\<exists>Z. s\\<in>P' Z \\<and> \n                     (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> t \\<in> Q) \\<and> (\\<forall>t. t \\<in> A' Z \\<longrightarrow> t \\<in> A)}\"\nassumes lem: \"\\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (lem x c) Q,A\"\n  apply (rule Lem [OF lem])\n  using conseq\n  by blast\n\nlemma LemAnnoNoAbrupt:\nassumes conseq:  \"P \\<subseteq>  {s. \\<exists>Z. s\\<in>P' Z \\<and> (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> t \\<in> Q)}\"\nassumes lem: \"\\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),{}\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (lem x c) Q,{}\"\n  apply (rule Lem [OF lem])\n  using conseq\n  by blast\n\nlemma TrivPost: \"\\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z)\n                 \\<Longrightarrow>\n                 \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c UNIV,UNIV\"\napply (rule allI)\napply (erule conseq)\napply auto\ndone\n\nlemma TrivPostNoAbr: \"\\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),{}\n                 \\<Longrightarrow>\n                 \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c UNIV,{}\"\napply (rule allI)\napply (erule conseq)\napply auto\ndone\n\nlemma DynComConseq:\n  assumes \"P \\<subseteq> {s. \\<exists>P' Q' A'.  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>P' (c s) Q',A' \\<and> P \\<subseteq> P' \\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A}\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>P DynCom c Q,A\"\n  using assms\n  apply -\n  apply (rule hoaret.DynCom)\n  apply clarsimp\n  apply (rule hoaret.Conseq)\n  apply clarsimp\n  apply blast\n  done\n\nlemma SpecAnno: \n assumes consequence: \"P \\<subseteq> {s. (\\<exists> Z. s\\<in>P' Z \\<and> (Q' Z \\<subseteq> Q) \\<and> (A' Z \\<subseteq> A))}\"\n assumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) (c Z) (Q' Z),(A' Z)\"\n assumes bdy_constant:  \"\\<forall>Z. c Z = c undefined\"\n shows   \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (specAnno P' c Q' A') Q,A\"\nproof -\n  from spec bdy_constant\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) (c undefined) (Q' Z),(A' Z)\"\n    apply - \n    apply (rule allI)\n    apply (erule_tac x=Z in allE)\n    apply (erule_tac x=Z in allE)\n    apply simp\n    done\n  with consequence show ?thesis\n    apply (simp add: specAnno_def)\n    apply (erule conseq)\n    apply blast\n    done\nqed\n\n\n\nlemma SpecAnno': \n \"\\<lbrakk>P \\<subseteq> {s.  \\<exists> Z. s\\<in>P' Z \\<and> \n            (\\<forall>t. t \\<in> Q' Z \\<longrightarrow>  t \\<in> Q) \\<and> (\\<forall>t. t \\<in> A' Z \\<longrightarrow> t \\<in>  A)};\n   \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) (c Z) (Q' Z),(A' Z);\n   \\<forall>Z. c Z = c undefined\n  \\<rbrakk> \\<Longrightarrow>\n    \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (specAnno P' c Q' A') Q,A\"\napply (simp only: subset_iff [THEN sym])\napply (erule (1) SpecAnno)\napply assumption\ndone\n\nlemma SpecAnnoNoAbrupt: \n \"\\<lbrakk>P \\<subseteq> {s.  \\<exists> Z. s\\<in>P' Z \\<and> \n            (\\<forall>t. t \\<in> Q' Z \\<longrightarrow>  t \\<in> Q)};\n   \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) (c Z) (Q' Z),{};\n   \\<forall>Z. c Z = c undefined\n  \\<rbrakk> \\<Longrightarrow>\n    \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (specAnno P' c Q' (\\<lambda>s. {})) Q,A\"\napply (rule SpecAnno')\napply auto\ndone\n\nlemma Skip: \"P \\<subseteq> Q \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Skip Q,A\"\n  by (rule hoaret.Skip [THEN conseqPre],simp)\n\nlemma Basic: \"P \\<subseteq> {s. (f s) \\<in> Q} \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Basic f) Q,A\"\n  by (rule hoaret.Basic [THEN conseqPre])\n\nlemma BasicCond: \n  \"\\<lbrakk>P \\<subseteq> {s. (b s \\<longrightarrow> f s\\<in>Q) \\<and> (\\<not> b s \\<longrightarrow> g s\\<in>Q)}\\<rbrakk> \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Basic (\\<lambda>s. if b s then f s else g s) Q,A\"\n  apply (rule Basic)\n  apply auto\n  done\n\nlemma Spec: \"P \\<subseteq> {s. (\\<forall>t. (s,t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s,t) \\<in> r)} \n            \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Spec r) Q,A\"\nby (rule hoaret.Spec [THEN conseqPre])\n\nlemma SpecIf: \n  \"\\<lbrakk>P \\<subseteq> {s. (b s \\<longrightarrow> f s \\<in> Q) \\<and> (\\<not> b s \\<longrightarrow> g s \\<in> Q \\<and> h s \\<in> Q)}\\<rbrakk> \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Spec (if_rel b f g h) Q,A\"\n  apply (rule Spec)\n  apply (auto simp add: if_rel_def)\n  done\n\nlemma Seq [trans, intro?]: \n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 R,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Seq c\\<^sub>1 c\\<^sub>2 Q,A\"\n  by (rule hoaret.Seq)\n\nlemma SeqSwap: \n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c2 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c1 R,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Seq c1 c2 Q,A\"\n  by (rule Seq)\n\nlemma BSeq:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 R,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (bseq c\\<^sub>1 c\\<^sub>2) Q,A\"\n  by (unfold bseq_def) (rule Seq)\n\nlemma Cond: \n  assumes wp: \"P \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\" \n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P\\<^sub>1 c\\<^sub>1 Q,A\" \n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P\\<^sub>2 c\\<^sub>2 Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) Q,A\"\nproof (rule hoaret.Cond [THEN conseqPre])\n  from deriv_c1 \n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. (s \\<in> b \\<longrightarrow> s \\<in> P\\<^sub>1) \\<and> (s \\<notin> b \\<longrightarrow> s \\<in> P\\<^sub>2)} \\<inter> b) c\\<^sub>1 Q,A\"\n    by (rule conseqPre) blast\nnext\n  from deriv_c2 \n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. (s \\<in> b \\<longrightarrow> s \\<in> P\\<^sub>1) \\<and> (s \\<notin> b \\<longrightarrow> s \\<in> P\\<^sub>2)} \\<inter> - b) c\\<^sub>2 Q,A\"\n    by (rule conseqPre) blast\nqed (insert wp)\n\n\nlemma CondSwap: \n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P1 c1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P2 c2 Q,A; \n    P \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P2)}\\<rbrakk>\n   \\<Longrightarrow> \n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Cond b c1 c2) Q,A\"\n  by (rule Cond)\n\nlemma Cond': \n  \"\\<lbrakk>P \\<subseteq> {s. (b \\<subseteq> P1) \\<and> (- b \\<subseteq> P2)};\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P1 c1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P2 c2 Q,A\\<rbrakk>\n   \\<Longrightarrow> \n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Cond b c1 c2) Q,A\"\n  by (rule CondSwap) blast+\n\nlemma CondInv: \n  assumes wp: \"P \\<subseteq> Q\" \n  assumes inv: \"Q \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\" \n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P\\<^sub>1 c\\<^sub>1 Q,A\" \n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P\\<^sub>2 c\\<^sub>2 Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) Q,A\"\nproof -\n  from wp inv\n  have \"P \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\"\n    by blast\n  from Cond [OF this deriv_c1 deriv_c2]\n  show ?thesis .\nqed\n\nlemma CondInv': \n  assumes wp: \"P \\<subseteq> I\" \n  assumes inv: \"I \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\" \n  assumes wp': \"I \\<subseteq> Q\"\n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P\\<^sub>1 c\\<^sub>1 I,A\" \n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P\\<^sub>2 c\\<^sub>2 I,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) Q,A\"\nproof -\n  from CondInv [OF wp inv deriv_c1 deriv_c2]\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) I,A\" .\n  from conseqPost [OF this wp' subset_refl]\n  show ?thesis .\nqed\n\n\nlemma switchNil:\n  \"P \\<subseteq> Q \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>P (switch v []) Q,A\"\n  by (simp add: Skip)\n \nlemma switchCons:\n  \"\\<lbrakk>P \\<subseteq> {s. (v s \\<in> V \\<longrightarrow> s \\<in> P\\<^sub>1) \\<and> (v s \\<notin> V \\<longrightarrow> s \\<in> P\\<^sub>2)}; \n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>P\\<^sub>1 c Q,A;\n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>P\\<^sub>2 (switch v vs) Q,A\\<rbrakk>\n\\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>P (switch v ((V,c)#vs)) Q,A\"\n  by (simp add: Cond)\n\n \nlemma Guard:\n \"\\<lbrakk>P \\<subseteq> g \\<inter> R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c Q,A\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Guard f g c Q,A\"\napply (rule HoareTotalDef.Guard [THEN conseqPre, of _ _ _ _ R])\napply (erule conseqPre)\napply auto\ndone\n\nlemma GuardSwap:\n \"\\<lbrakk> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> g \\<inter> R\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Guard f g c Q,A\"\n  by (rule Guard)\n\nlemma Guarantee:\n \"\\<lbrakk>P \\<subseteq> {s. s \\<in> g \\<longrightarrow> s \\<in> R}; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c Q,A; f \\<in> F\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\napply (rule Guarantee [THEN conseqPre, of _ _ _ _ _ \"{s. s \\<in> g \\<longrightarrow> s \\<in> R}\"])\napply   assumption\napply  (erule conseqPre)\napply auto\ndone\n\nlemma GuaranteeSwap:\n \"\\<lbrakk> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> {s. s \\<in> g \\<longrightarrow> s \\<in> R}; f \\<in> F\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\n  by (rule Guarantee)\n\n\nlemma GuardStrip:\n \"\\<lbrakk>P \\<subseteq> R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c Q,A; f \\<in> F\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\napply (rule Guarantee [THEN conseqPre])\napply auto\ndone\n\nlemma GuardStripSwap:\n \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> R; f \\<in> F\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\n  by (rule GuardStrip)\n\nlemma GuaranteeStrip:\n \"\\<lbrakk>P \\<subseteq> R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c Q,A; f \\<in> F\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (guaranteeStrip f g c) Q,A\"\n  by (unfold guaranteeStrip_def) (rule GuardStrip)\n\nlemma GuaranteeStripSwap:\n \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> R; f \\<in> F\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (guaranteeStrip f g c) Q,A\"\n  by (unfold guaranteeStrip_def) (rule GuardStrip)\n\nlemma GuaranteeAsGuard:\n \"\\<lbrakk>P \\<subseteq> g \\<inter> R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c Q,A\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P guaranteeStrip f g c Q,A\"\n  by (unfold guaranteeStrip_def) (rule Guard)\n\nlemma GuaranteeAsGuardSwap:\n \"\\<lbrakk> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> g \\<inter> R\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P guaranteeStrip f g c Q,A\"\n  by (rule GuaranteeAsGuard)\n\nlemma GuardsNil:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (guards [] c) Q,A\"\n  by simp\n\n\n\nlemma GuardsConsGuaranteeStrip:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P guaranteeStrip f g (guards gs c) Q,A \\<Longrightarrow> \n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (guards (guaranteeStripPair f g#gs) c) Q,A\"\n  by (simp add: guaranteeStripPair_def guaranteeStrip_def)\n\nlemma While: \n  assumes P_I: \"P \\<subseteq> I\" \n  assumes deriv_body: \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> I \\<inter> b) c ({t. (t, \\<sigma>) \\<in> V} \\<inter> I),A\"\n  assumes I_Q: \"I \\<inter> -b \\<subseteq> Q\" \n  assumes wf: \"wf V\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (whileAnno  b I V c) Q,A\"\nproof -\n  from wf deriv_body P_I I_Q\n  show ?thesis\n    apply (unfold whileAnno_def)\n    apply (erule conseqPrePost [OF HoareTotalDef.While]) \n    apply auto\n    done\nqed\n\n\n\nlemma WhileInvPost: \n  assumes P_I: \"P \\<subseteq> I\" \n  assumes termi_body: \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/UNIV\\<^esub> ({\\<sigma>} \\<inter> I \\<inter> b) c ({t. (t, \\<sigma>) \\<in> V} \\<inter> P),A\"\n  assumes deriv_body: \n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (I \\<inter> b) c I,A\"\n  assumes I_Q: \"I \\<inter> -b \\<subseteq> Q\" \n  assumes wf: \"wf V\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (whileAnno  b I V c) Q,A\"\nproof -\n  have \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> I \\<inter> b) c ({t. (t, \\<sigma>) \\<in> V} \\<inter> I),A\"\n  proof \n    fix \\<sigma>\n    from hoare_sound [OF deriv_body] hoaret_sound [OF termi_body [rule_format, of \\<sigma>]]\n    have \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> I \\<inter> b) c ({t. (t, \\<sigma>) \\<in> V} \\<inter> I),A\"\n      by (fastforce simp add: cvalidt_def validt_def cvalid_def valid_def)\n    then\n    show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> I \\<inter> b) c ({t. (t, \\<sigma>) \\<in> V} \\<inter> I),A\"\n      by (rule hoaret_complete')\n  qed\n\n  from While [OF P_I this I_Q wf]\n  show ?thesis .\nqed\n\n(* *)\nlemma \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> b) c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> b) (Seq c (Guard f Q Skip)) Q,A\"\noops\n\ntext \\<open>@{term \"J\"} will be instantiated by tactic with @{term \"gs' \\<inter> I\"} for\n  those guards that are not stripped.\\<close> \nlemma WhileAnnoG:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (guards gs \n                    (whileAnno  b J V (Seq c (guards gs Skip)))) Q,A \n        \\<Longrightarrow> \n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (whileAnnoG gs b I V c) Q,A\"\n  by (simp add: whileAnnoG_def whileAnno_def while_def)\n\ntext \\<open>This form stems from @{term \"strip_guards F (whileAnnoG gs b I V c)\"}\\<close> \n\n\n\n\nlemma WhileAnnoFix':\nassumes consequence: \"P \\<subseteq> {s. (\\<exists> Z. s\\<in>I Z \\<and> \n                               (\\<forall>t. t \\<in> I Z \\<inter> -b \\<longrightarrow> t \\<in> Q)) }\"\nassumes bdy: \"\\<forall>Z \\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> I Z \\<inter> b) (c Z) ({t. (t, \\<sigma>) \\<in> V Z} \\<inter> I Z),A\"\nassumes bdy_constant:  \"\\<forall>Z. c Z = c undefined\"\nassumes wf: \"\\<forall>Z. wf (V Z)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (whileAnnoFix b I V c) Q,A\"\n  apply (rule WhileAnnoFix [OF _ bdy bdy_constant wf])\n  using consequence by blast\n\nlemma WhileAnnoGFix:\nassumes whileAnnoFix:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (guards gs \n                (whileAnnoFix  b J V (\\<lambda>Z. (Seq (c Z) (guards gs Skip))))) Q,A\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (whileAnnoGFix gs b I V c) Q,A\"\n  using whileAnnoFix\n  by (simp add: whileAnnoGFix_def whileAnnoFix_def while_def)\n\nlemma Bind:\n  assumes adapt: \"P \\<subseteq> {s. s \\<in> P' s}\" \n  assumes c: \"\\<forall>s. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' s) (c (e s)) Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (bind e c) Q,A\" \napply (rule conseq [where P'=\"\\<lambda>Z. {s. s=Z \\<and> s \\<in> P' Z}\" and Q'=\"\\<lambda>Z. Q\" and \nA'=\"\\<lambda>Z. A\"])\napply  (rule allI)\napply  (unfold bind_def)\napply  (rule HoareTotalDef.DynCom)\napply  (rule ballI)\napply  clarsimp\napply  (rule conseqPre)\napply   (rule c [rule_format])\napply  blast\nusing adapt\napply blast\ndone\n\nlemma Block:\nassumes adapt: \"P \\<subseteq> {s. init s \\<in> P' s}\"\nassumes bdy: \"\\<forall>s. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' s) bdy {t. return s t \\<in> R s t},{t. return s t \\<in> A}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (block init bdy return c) Q,A\" \napply (rule conseq [where P'=\"\\<lambda>Z. {s. s=Z \\<and> init s \\<in> P' Z}\" and Q'=\"\\<lambda>Z. Q\" and \nA'=\"\\<lambda>Z. A\"])\nprefer 2\nusing adapt\napply  blast\napply (rule allI)\napply (unfold block_def)\napply (rule HoareTotalDef.DynCom)\napply (rule ballI)\napply clarsimp\napply (rule_tac R=\"{t. return Z t \\<in> R Z t}\" in SeqSwap )\napply  (rule_tac  P'=\"\\<lambda>Z'. {t. t=Z' \\<and> return Z t \\<in> R Z t}\" and \n          Q'=\"\\<lambda>Z'. Q\" and A'=\"\\<lambda>Z'. A\" in conseq)\nprefer 2 apply simp\napply  (rule allI)\napply  (rule HoareTotalDef.DynCom)\napply  (clarsimp)\napply  (rule SeqSwap)\napply   (rule c [rule_format])\napply  (rule Basic)\napply  clarsimp\napply (rule_tac R=\"{t. return Z t \\<in> A}\" in HoareTotalDef.Catch)\napply  (rule_tac R=\"{i. i \\<in> P' Z}\" in Seq)\napply   (rule Basic)\napply   clarsimp\napply  simp\napply  (rule bdy [rule_format])\napply (rule SeqSwap)\napply  (rule Throw)\napply (rule Basic)\napply simp\ndone\n\nlemma BlockSwap:\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes bdy: \"\\<forall>s. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' s) bdy {t. return s t \\<in> R s t},{t. return s t \\<in> A}\"\nassumes adapt: \"P \\<subseteq> {s. init s \\<in> P' s}\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (block init bdy return c) Q,A\"\n  using adapt bdy c\n  by (rule Block)\n\nlemma BlockSpec:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' Z \\<and> \n                             (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t) \\<and>\n                             (\\<forall>t. t \\<in> A' Z \\<longrightarrow> return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes bdy: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) bdy (Q' Z),(A' Z)\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (block init bdy return c) Q,A\" \napply (rule conseq [where P'=\"\\<lambda>Z. {s. init s \\<in> P' Z \\<and> \n                             (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t) \\<and>\n                             (\\<forall>t. t \\<in> A' Z \\<longrightarrow> return s t \\<in> A)}\" and Q'=\"\\<lambda>Z. Q\" and \nA'=\"\\<lambda>Z. A\"])\nprefer 2\nusing adapt\napply  blast\napply (rule allI)\napply (unfold block_def)\napply (rule HoareTotalDef.DynCom)\napply (rule ballI)\napply clarsimp\napply (rule_tac R=\"{t. return s t \\<in> R s t}\" in SeqSwap )\napply  (rule_tac  P'=\"\\<lambda>Z'. {t. t=Z' \\<and> return s t \\<in> R s t}\" and \n          Q'=\"\\<lambda>Z'. Q\" and A'=\"\\<lambda>Z'. A\" in conseq)\nprefer 2 apply simp\napply  (rule allI)\napply  (rule HoareTotalDef.DynCom)\napply  (clarsimp)\napply  (rule SeqSwap)\napply   (rule c [rule_format])\napply  (rule Basic)\napply  clarsimp\napply (rule_tac R=\"{t. return s t \\<in> A}\" in HoareTotalDef.Catch)\napply  (rule_tac R=\"{i. i \\<in> P' Z}\" in Seq)\napply   (rule Basic)\napply   clarsimp\napply  simp\napply  (rule conseq [OF bdy])\napply  clarsimp\napply  blast\napply (rule SeqSwap)\napply  (rule Throw)\napply (rule Basic)\napply simp\ndone\n\n\nlemma Throw: \"P \\<subseteq> A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Throw Q,A\"\n  by (rule hoaret.Throw [THEN conseqPre])\n\nlemmas Catch = hoaret.Catch\nlemma CatchSwap: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,R\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Catch c\\<^sub>1 c\\<^sub>2 Q,A\"\n  by (rule hoaret.Catch)\n\nlemma raise: \"P \\<subseteq> {s. f s \\<in> A} \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P raise f Q,A\"\n  apply (simp add: raise_def)\n  apply (rule Seq)\n  apply  (rule Basic)\n  apply  (assumption)\n  apply (rule Throw)\n  apply (rule subset_refl)\n  done\n\nlemma condCatch: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,((b \\<inter> R) \\<union> (-b \\<inter> A));\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk> \n                  \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P condCatch c\\<^sub>1 b c\\<^sub>2 Q,A\"\n  apply (simp add: condCatch_def)\n  apply (rule Catch)\n  apply  assumption\n  apply (rule CondSwap)\n  apply   (assumption)\n  apply  (rule hoaret.Throw)\n  apply blast\n  done\n\nlemma condCatchSwap: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,((b \\<inter> R) \\<union> (-b \\<inter> A))\\<rbrakk> \n                     \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P condCatch c\\<^sub>1 b c\\<^sub>2 Q,A\"\n  by (rule condCatch)\n\n\nlemma ProcSpec:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' Z \\<and> \n                             (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t) \\<and>\n                             (\\<forall>t. t \\<in> A' Z \\<longrightarrow> return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) Call p (Q' Z),(A' Z)\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nusing adapt c p\napply (unfold call_def) \nby (rule BlockSpec)\n\nlemma ProcSpec':\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' Z \\<and> \n                             (\\<forall>t \\<in> Q' Z. return s t \\<in> R s t) \\<and>\n                             (\\<forall>t \\<in> A' Z. return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) Call p (Q' Z),(A' Z)\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule ProcSpec [OF _ c p])\napply (insert adapt)\napply clarsimp\napply (drule (1) subsetD)\napply (clarsimp)\napply (rule_tac x=Z in exI)\napply blast\ndone\n\n\nlemma ProcSpecNoAbrupt:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' Z \\<and> \n                             (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) Call p (Q' Z),{}\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule ProcSpec [OF _ c p])\nusing adapt\napply simp\ndone\n\nlemma FCall:  \n\"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return (\\<lambda>s t. c (result t))) Q,A\n\\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (fcall init p return result c) Q,A\"\n  by (simp add: fcall_def)\n\nlemma ProcRec:\n  assumes deriv_bodies:  \n   \"\\<forall>p\\<in>Procs. \n    \\<forall>\\<sigma> Z. \\<Gamma>,\\<Theta>\\<union>(\\<Union>q\\<in>Procs. \\<Union>Z. \n       {(P q Z \\<inter> {s. ((s,q), \\<sigma>,p) \\<in> r},q,Q q Z,A q Z)})\n        \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n  assumes wf: \"wf r\"\n  assumes Procs_defined: \"Procs \\<subseteq> dom \\<Gamma>\"\n  shows \"\\<forall>p\\<in>Procs. \\<forall>Z.  \n  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>(P p Z) Call p (Q p Z),(A p Z)\"\n  by (intro strip)\n     (rule HoareTotalDef.CallRec' \n     [OF _  Procs_defined wf deriv_bodies],\n     simp_all)\n\nlemma ProcRec':\n  assumes ctxt: \n   \"\\<Theta>'=(\\<lambda>\\<sigma> p. \\<Theta>\\<union>(\\<Union>q\\<in>Procs. \n                   \\<Union>Z. {(P q Z \\<inter> {s. ((s,q), \\<sigma>,p) \\<in> r},q,Q q Z,A q Z)}))\"\n  assumes deriv_bodies:   \n   \"\\<forall>p\\<in>Procs. \n    \\<forall>\\<sigma> Z. \\<Gamma>,\\<Theta>' \\<sigma> p\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n  assumes wf: \"wf r\"\n  assumes Procs_defined: \"Procs \\<subseteq> dom \\<Gamma>\"\n  shows \"\\<forall>p\\<in>Procs. \\<forall>Z.  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>(P p Z) Call p (Q p Z),(A p Z)\"\n  using ctxt deriv_bodies\n  apply simp\n  apply (erule ProcRec [OF _ wf Procs_defined])\n  done\n \n\nlemma ProcRecList:\n  assumes deriv_bodies:  \n   \"\\<forall>p\\<in>set Procs. \n    \\<forall>\\<sigma> Z. \\<Gamma>,\\<Theta>\\<union>(\\<Union>q\\<in>set Procs. \\<Union>Z. \n       {(P q Z \\<inter> {s. ((s,q), \\<sigma>,p) \\<in> r},q,Q q Z,A q Z)})\n        \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n  assumes wf: \"wf r\"\n  assumes dist: \"distinct Procs\"\n  assumes Procs_defined: \"set Procs \\<subseteq> dom \\<Gamma>\"\n  shows \"\\<forall>p\\<in>set Procs. \\<forall>Z.  \n  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>(P p Z) Call p (Q p Z),(A p Z)\"\n  using deriv_bodies wf Procs_defined\n  by (rule ProcRec)\n\nlemma  ProcRecSpecs:\n  \"\\<lbrakk>\\<forall>\\<sigma>. \\<forall>(P,p,Q,A) \\<in> Specs. \n     \\<Gamma>,\\<Theta>\\<union> ((\\<lambda>(P,q,Q,A). (P \\<inter> {s. ((s,q),(\\<sigma>,p)) \\<in> r},q,Q,A)) ` Specs)\n      \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P) (the (\\<Gamma> p)) Q,A;\n    wf r;\n    \\<forall>(P,p,Q,A) \\<in> Specs. p \\<in> dom \\<Gamma>\\<rbrakk>\n  \\<Longrightarrow> \\<forall>(P,p,Q,A) \\<in> Specs. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\napply (rule ballI)\napply (case_tac x)\napply (rename_tac x P p Q A)\napply simp\napply (rule hoaret.CallRec)\napply auto\ndone\n\nlemma ProcRec1:\n  assumes deriv_body:  \n   \"\\<forall>\\<sigma> Z. \\<Gamma>,\\<Theta>\\<union>(\\<Union>Z. {(P Z \\<inter> {s. ((s,p), \\<sigma>,p) \\<in> r},p,Q Z,A Z)})\n           \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P Z) (the (\\<Gamma> p)) (Q Z),(A Z)\"\n  assumes wf: \"wf r\"\n  assumes p_defined: \"p \\<in> dom \\<Gamma>\"\n  shows \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P Z) Call p (Q Z),(A Z)\"\nproof -\n  from deriv_body wf p_defined\n  have \"\\<forall>p\\<in>{p}. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P Z) Call p (Q Z),(A Z)\"\n    apply - \n    apply (rule ProcRec [where  A=\"\\<lambda>p. A\" and P=\"\\<lambda>p. P\" and Q=\"\\<lambda>p. Q\"])\n    apply simp_all\n    done\n  thus ?thesis\n    by simp\nqed\n\nlemma ProcNoRec1:\n  assumes deriv_body:  \n   \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P Z) (the (\\<Gamma> p)) (Q Z),(A Z)\"\n  assumes p_defined: \"p \\<in> dom \\<Gamma>\"\n  shows \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P Z) Call p (Q Z),(A Z)\"\nproof -\n  have \"\\<forall>\\<sigma> Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P Z) (the (\\<Gamma> p)) (Q Z),(A Z)\"\n    by (blast intro: conseqPre deriv_body [rule_format])\n  with p_defined have \"\\<forall>\\<sigma> Z. \\<Gamma>,\\<Theta>\\<union>(\\<Union>Z. {(P Z \\<inter> {s. ((s,p), \\<sigma>,p) \\<in> {}},\n                         p,Q Z,A Z)})\n             \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P Z) (the (\\<Gamma> p)) (Q Z),(A Z)\"\n    by (blast intro: hoaret_augment_context)\n  from this  \n  show ?thesis \n    by (rule ProcRec1) (auto simp add: p_defined) \nqed\n\nlemma ProcBody:\n assumes WP: \"P \\<subseteq> P'\"\n assumes deriv_body: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' body Q,A\" \n assumes body: \"\\<Gamma> p = Some body\"\n shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Call p Q,A\"\napply (rule conseqPre [OF _ WP])\napply (rule ProcNoRec1 [rule_format, where P=\"\\<lambda>Z. P'\" and Q=\"\\<lambda>Z. Q\" and A=\"\\<lambda>Z. A\"]) \napply  (insert body)\napply  simp\napply  (rule hoaret_augment_context [OF deriv_body])\napply  blast\napply fastforce\ndone\n\nlemma CallBody:\nassumes adapt: \"P \\<subseteq> {s. init s \\<in> P' s}\"\nassumes bdy: \"\\<forall>s. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' s) body {t. return s t \\<in> R s t},{t. return s t \\<in> A}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes body: \"\\<Gamma> p = Some body\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (unfold call_def)\napply (rule Block [OF adapt _ c])\napply (rule allI)\napply (rule ProcBody [where \\<Gamma>=\\<Gamma>, OF _ bdy [rule_format] body])\napply simp\ndone\n\nlemmas ProcModifyReturn = HoareTotalProps.ProcModifyReturn\nlemmas ProcModifyReturnSameFaults = HoareTotalProps.ProcModifyReturnSameFaults\n\nlemma ProcModifyReturnNoAbr:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes result_conform:\n      \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:  \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} Call p (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nby (rule ProcModifyReturn [OF spec result_conform _ modifies_spec]) simp\n\n\nlemma ProcModifyReturnNoAbrSameFaults:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes result_conform:\n      \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:  \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call p (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nby (rule ProcModifyReturnSameFaults [OF spec result_conform _ modifies_spec]) simp\n\n\nlemma DynProc: \n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' s Z \\<and>\n                          (\\<forall>t. t \\<in> Q' s Z \\<longrightarrow>  return s t \\<in> R s t) \\<and>\n                          (\\<forall>t. t \\<in> A' s Z \\<longrightarrow> return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>s\\<in> P. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' s Z) Call (p s) (Q' s Z),(A' s Z)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return c Q,A\"\napply (rule conseq [where P'=\"\\<lambda>Z. {s. s=Z \\<and> s \\<in> P}\"\n  and Q'=\"\\<lambda>Z. Q\" and A'=\"\\<lambda>Z. A\"])\nprefer 2\nusing adapt\napply  blast\napply (rule allI)\napply (unfold dynCall_def call_def block_def)\napply (rule HoareTotalDef.DynCom)\napply clarsimp\napply (rule HoareTotalDef.DynCom)\napply clarsimp\napply (frule in_mono [rule_format, OF adapt])\napply clarsimp\napply (rename_tac Z')\napply (rule_tac R=\"Q' Z Z'\" in Seq)\napply  (rule CatchSwap)\napply   (rule SeqSwap)\napply    (rule Throw) \napply    (rule subset_refl)\napply   (rule Basic)\napply   (rule subset_refl)\napply  (rule_tac R=\"{i. i \\<in> P' Z Z'}\" in Seq)\napply   (rule Basic) \napply   clarsimp\napply  simp\napply  (rule_tac Q'=\"Q' Z Z'\" and A'=\"A' Z Z'\" in conseqPost)\nusing p\napply    clarsimp\napply   simp\napply  clarsimp\napply  (rule_tac  P'=\"\\<lambda>Z''. {t. t=Z'' \\<and> return Z t \\<in> R Z t}\" and \n          Q'=\"\\<lambda>Z''. Q\" and A'=\"\\<lambda>Z''. A\" in conseq)\nprefer 2 apply simp\napply (rule allI)\napply (rule HoareTotalDef.DynCom)\napply clarsimp\napply (rule SeqSwap)\napply  (rule c [rule_format])\napply (rule Basic)\napply clarsimp\ndone\n\nlemma DynProc': \n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' s Z \\<and>\n                          (\\<forall>t \\<in> Q' s Z. return s t \\<in> R s t) \\<and>\n                          (\\<forall>t \\<in> A' s Z. return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>s\\<in> P. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' s Z) Call (p s) (Q' s Z),(A' s Z)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return c Q,A\"\nproof -\n  from adapt have \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' s Z \\<and>\n                          (\\<forall>t. t \\<in> Q' s Z \\<longrightarrow>  return s t \\<in> R s t) \\<and>\n                          (\\<forall>t. t \\<in> A' s Z \\<longrightarrow> return s t \\<in> A)}\"\n    by blast\n  from this c p show ?thesis\n    by (rule DynProc)\nqed\n\nlemma DynProcStaticSpec: \nassumes adapt: \"P \\<subseteq> {s. s \\<in> S \\<and> (\\<exists>Z. init s \\<in> P' Z  \\<and> \n                            (\\<forall>\\<tau>. \\<tau> \\<in> Q' Z \\<longrightarrow> return s \\<tau> \\<in> R s \\<tau>) \\<and>\n                            (\\<forall>\\<tau>. \\<tau> \\<in> A' Z \\<longrightarrow> return s \\<tau> \\<in> A))}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes spec: \"\\<forall>s\\<in>S. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) Call (p s) (Q' Z),(A' Z)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from adapt have P_S: \"P \\<subseteq> S\"\n    by blast\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> S) (dynCall init p return c) Q,A\"\n    apply (rule DynProc [where P'=\"\\<lambda>s Z. P' Z\" and Q'=\"\\<lambda>s Z. Q' Z\" \n                         and A'=\"\\<lambda>s Z. A' Z\", OF _ c])\n    apply  clarsimp\n    apply  (frule in_mono [rule_format, OF adapt])\n    apply  clarsimp\n    using spec\n    apply clarsimp\n    done\n  thus ?thesis\n    by (rule conseqPre) (insert P_S,blast)\nqed\n\n\n\nlemma DynProcProcPar: \nassumes adapt: \"P \\<subseteq> {s. p s = q \\<and> (\\<exists>Z. init s \\<in> P' Z  \\<and> \n                            (\\<forall>\\<tau>. \\<tau> \\<in> Q' Z \\<longrightarrow> return s \\<tau> \\<in> R s \\<tau>) \\<and>\n                            (\\<forall>\\<tau>. \\<tau> \\<in> A' Z \\<longrightarrow> return s \\<tau> \\<in> A))}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) Call q (Q' Z),(A' Z)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\n  apply (rule DynProcStaticSpec [where S=\"{s. p s = q}\",simplified, OF adapt c])\n  using spec\n  apply simp\n  done\n\n\nlemma DynProcProcParNoAbrupt: \nassumes adapt: \"P \\<subseteq> {s. p s = q \\<and> (\\<exists>Z. init s \\<in> P' Z  \\<and> \n                            (\\<forall>\\<tau>. \\<tau> \\<in> Q' Z \\<longrightarrow> return s \\<tau> \\<in> R s \\<tau>))}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) Call q (Q' Z),{}\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -  \n  have \"P \\<subseteq> {s. p s = q \\<and> (\\<exists> Z. init s \\<in> P' Z \\<and> \n                      (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t) \\<and>\n                      (\\<forall>t. t \\<in> {} \\<longrightarrow> return s t \\<in> A))}\"\n    (is \"P \\<subseteq> ?P'\")\n  proof \n    fix s\n    assume P: \"s\\<in>P\"\n    with adapt obtain Z where\n      Pre: \"p s = q \\<and> init s \\<in> P' Z\" and\n      adapt_Norm: \"\\<forall>\\<tau>. \\<tau> \\<in> Q' Z \\<longrightarrow> return s \\<tau> \\<in> R s \\<tau>\" \n      by blast\n    from  adapt_Norm \n    have \"\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t\"\n      by auto\n    then\n    show \"s\\<in>?P'\"\n      using Pre by blast\n  qed\n  note P = this\n  show ?thesis\n    apply -\n    apply (rule DynProcStaticSpec [where S=\"{s. p s = q}\",simplified, OF P c])\n    apply (insert spec)\n    apply auto\n    done\nqed\n\nlemma DynProcModifyReturnNoAbr: \n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause: \n            \"\\<forall>s \\<in> P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} Call (p s)  (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from ret_nrm_modif\n  have \"\\<forall>s t. t  \\<in> (Modif (init s)) \n        \\<longrightarrow> return' s t = return s t\"\n    by iprover\n  then \n  have ret_nrm_modif': \"\\<forall>s t. t \\<in> (Modif (init s)) \n                      \\<longrightarrow> return' s t = return s t\"\n    by simp\n  have ret_abr_modif': \"\\<forall>s t. t \\<in> {} \n                        \\<longrightarrow> return' s t = return s t\"\n    by simp\n  from to_prove ret_nrm_modif' ret_abr_modif' modif_clause show ?thesis\n    by (rule dynProcModifyReturn)\nqed\n\nlemma ProcDynModifyReturnNoAbrSameFaults: \n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause: \n            \"\\<forall>s \\<in> P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} (Call (p s)) (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from ret_nrm_modif\n  have \"\\<forall>s t. t  \\<in> (Modif (init s)) \n        \\<longrightarrow> return' s t = return s t\"\n    by iprover\n  then\n  have ret_nrm_modif': \"\\<forall>s t. t \\<in> (Modif (init s)) \n                      \\<longrightarrow> return' s t = return s t\"\n    by simp\n  have ret_abr_modif': \"\\<forall>s t. t \\<in> {} \n                        \\<longrightarrow> return' s t = return s t\"\n    by simp\n  from to_prove ret_nrm_modif' ret_abr_modif' modif_clause show ?thesis\n    by (rule dynProcModifyReturnSameFaults)\nqed\n\nlemma ProcProcParModifyReturn: \n  assumes q: \"P \\<subseteq> {s. p s = q} \\<inter> P'\"\n   \\<comment>\\<open>@{thm[source] DynProcProcPar} introduces the same constraint as first conjunction in \n         @{term P'}, so the vcg can simplify it.\\<close>\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes ret_abr_modif: \"\\<forall>s t. t \\<in> (ModifAbr (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause: \n          \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call q) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from to_prove have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return' c) Q,A\"\n    by (rule conseqPre) blast\n  from this ret_nrm_modif \n       ret_abr_modif \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return c) Q,A\"\n    by (rule dynProcModifyReturn) (insert modif_clause,auto)\n  from this q show ?thesis\n    by (rule conseqPre) \nqed\n\n\n\nlemma ProcProcParModifyReturnSameFaults: \n  assumes q: \"P \\<subseteq> {s. p s = q} \\<inter> P'\"\n   \\<comment>\\<open>@{thm[source] DynProcProcPar} introduces the same constraint as first conjunction in \n         @{term P'}, so the vcg can simplify it.\\<close>\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes ret_abr_modif: \"\\<forall>s t. t \\<in> (ModifAbr (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause: \n          \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call q (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from to_prove \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return' c) Q,A\"\n    by (rule conseqPre) blast\n  from this ret_nrm_modif \n       ret_abr_modif \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return c) Q,A\"\n    by (rule dynProcModifyReturnSameFaults) (insert modif_clause,auto)\n  from this q show ?thesis\n    by (rule conseqPre) \nqed\n\nlemma ProcProcParModifyReturnNoAbr: \n  assumes q: \"P \\<subseteq> {s. p s = q} \\<inter> P'\"\n   \\<comment>\\<open>@{thm[source] DynProcProcParNoAbrupt} introduces the same constraint as \n      first conjunction in @{term P'}, so the vcg can simplify it.\\<close>\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause: \n            \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call q) (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from to_prove have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return' c) Q,A\"\n    by (rule conseqPre) blast\n  from this ret_nrm_modif \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return c) Q,A\"\n    by (rule DynProcModifyReturnNoAbr) (insert modif_clause,auto)\n  from this q show ?thesis\n    by (rule conseqPre) \nqed\n\n\nlemma ProcProcParModifyReturnNoAbrSameFaults: \n  assumes q: \"P \\<subseteq> {s. p s = q} \\<inter> P'\"\n      \\<comment>\\<open>@{thm[source] DynProcProcParNoAbrupt} introduces the same constraint as \n      first conjunction in @{term P'}, so the vcg can simplify it.\\<close>\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause: \n            \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} (Call q) (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from to_prove have \n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return' c) Q,A\"\n    by (rule conseqPre) blast\n  from this ret_nrm_modif \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return c) Q,A\"\n    by (rule ProcDynModifyReturnNoAbrSameFaults) (insert modif_clause,auto)\n  from this q show ?thesis\n    by (rule conseqPre) \nqed\n\nlemma MergeGuards_iff: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P merge_guards c Q,A = \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (auto intro: MergeGuardsI MergeGuardsD)\n\nlemma CombineStrip': \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c' Q,A\"\n  assumes deriv_strip_triv: \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/{}\\<^esub> P c'' UNIV,UNIV\"\n  assumes c'': \"c''= mark_guards False (strip_guards (-F) c')\"\n  assumes c: \"merge_guards c = merge_guards (mark_guards False c')\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof -\n  from deriv_strip_triv have deriv_strip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c'' UNIV,UNIV\"\n    by (auto intro: hoare_augment_context)\n  from deriv_strip [simplified c'']\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P (strip_guards (- F) c') UNIV,UNIV\"\n    by (rule HoarePartialProps.MarkGuardsD)\n  with deriv \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c' Q,A\"\n    by (rule CombineStrip)\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards False c' Q,A\"\n    by (rule MarkGuardsI)\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P merge_guards (mark_guards False c') Q,A\"\n    by (rule MergeGuardsI)\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P merge_guards c Q,A\"\n    by (simp add: c)\n  thus ?thesis\n    by (rule MergeGuardsD)\nqed\n\nlemma CombineStrip'': \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{True}\\<^esub> P c' Q,A\"\n  assumes deriv_strip_triv: \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/{}\\<^esub> P c'' UNIV,UNIV\"\n  assumes c'': \"c''= mark_guards False (strip_guards ({False}) c')\"\n  assumes c: \"merge_guards c = merge_guards (mark_guards False c')\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\n  apply (rule CombineStrip' [OF deriv deriv_strip_triv _ c]) \n  apply (insert c'')\n  apply (subgoal_tac \"- {True} = {False}\")\n  apply auto\n  done\n\nlemma AsmUN:\n  \"(\\<Union>Z. {(P Z, p, Q Z,A Z)}) \\<subseteq> \\<Theta> \n  \\<Longrightarrow> \n  \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P Z) (Call p) (Q Z),(A Z)\"\n  by (blast intro: hoaret.Asm)\n\n\nlemma hoaret_to_hoarep':\n  \"\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z) \\<Longrightarrow> \\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z)\"\n  by (iprover intro: total_to_partial)\n\nlemma augment_context': \n  \"\\<lbrakk>\\<Theta> \\<subseteq> \\<Theta>'; \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P Z)  p (Q Z),(A Z)\\<rbrakk> \n   \\<Longrightarrow> \\<forall>Z. \\<Gamma>,\\<Theta>'\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z)\"\n  by (iprover intro: hoaret_augment_context)\n\n\nlemma augment_emptyFaults:\n \"\\<lbrakk>\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> (P Z) p (Q Z),(A Z)\\<rbrakk> \\<Longrightarrow> \n    \\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z)\"\n  by (blast intro: augment_Faults)\n\nlemma augment_FaultsUNIV:\n \"\\<lbrakk>\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z)\\<rbrakk> \\<Longrightarrow> \n    \\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/UNIV\\<^esub> (P Z) p (Q Z),(A Z)\"\n  by (blast intro: augment_Faults)\n\nlemma PostConjI [trans]:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c R,B\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\n  by (rule PostConjI)\n\nlemma PostConjI' :\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c R,B\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\n  by (rule PostConjI) iprover+\n\nlemma PostConjE [consumes 1]: \n  assumes conj: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\" \n  assumes E: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c R,B\\<rbrakk> \\<Longrightarrow> S\"\n  shows \"S\"\nproof -\n  from conj have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" by (rule conseqPost) blast+\n  moreover\n  from conj have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c R,B\" by (rule conseqPost) blast+\n  ultimately show \"S\" \n    by (rule E)\nqed\n\nsubsubsection \\<open>Rules for Single-Step Proof \\label{sec:hoare-isar}\\<close>\n\ntext \\<open>\n We are now ready to introduce a set of Hoare rules to be used in\n single-step structured proofs in Isabelle/Isar.  \n\n \\medskip Assertions of Hoare Logic may be manipulated in\n calculational proofs, with the inclusion expressed in terms of sets\n or predicates.  Reversed order is supported as well.\n\\<close>\n\n\nlemma annotateI [trans]:\n\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P anno Q,A; c = anno\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" \n  by (simp)\n\nlemma annotate_normI:\n  assumes deriv_anno: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>P anno Q,A\" \n  assumes norm_eq: \"normalize c = normalize anno\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>P c Q,A\"\nproof -\n  from HoareTotalProps.NormalizeI [OF deriv_anno] norm_eq\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>P normalize c Q,A\"\n    by simp\n  from NormalizeD [OF this]\n  show ?thesis .\nqed\n\n\nlemma annotateWhile:\n\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (whileAnnoG gs b I V c) Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (while gs b c) Q,A\"\n  by (simp add: whileAnnoG_def)\n\n\nlemma reannotateWhile:\n\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (whileAnnoG gs b I V c) Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (whileAnnoG gs b J V c) Q,A\"\n  by (simp add: whileAnnoG_def)\n\nlemma reannotateWhileNoGuard:\n\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (whileAnno b I V c) Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (whileAnno b J V c) Q,A\"\n  by (simp add: whileAnno_def)\n\nlemma [trans] : \"P' \\<subseteq> P \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q,A\"\n  by (rule conseqPre)\n \nlemma [trans]: \"Q \\<subseteq> Q' \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q',A\"\n  by (rule conseqPost) blast+\n\nlemma [trans]:\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. P s} c Q,A \\<Longrightarrow> (\\<And>s. P' s \\<longrightarrow> P s) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. P' s} c Q,A\"\n  by (rule conseqPre) auto\n\nlemma [trans]:\n    \"(\\<And>s. P' s \\<longrightarrow> P s) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. P s} c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. P' s} c Q,A\"\n  by (rule conseqPre) auto\n\nlemma [trans]:\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c {s. Q s},A \\<Longrightarrow> (\\<And>s. Q s \\<longrightarrow> Q' s) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c {s. Q' s},A\"\n  by (rule conseqPost) auto\n\nlemma [trans]:\n    \"(\\<And>s. Q s \\<longrightarrow> Q' s) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c {s. Q s},A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c {s. Q' s},A\"\n  by (rule conseqPost) auto\n\nlemma [intro?]: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Skip P,A\"\n  by (rule Skip) auto\n\nlemma CondInt [trans,intro?]:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> b) c1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> - b) c2 Q,A\\<rbrakk>\n   \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Cond b c1 c2) Q,A\"\n  by (rule Cond) auto\n \nlemma CondConj [trans, intro?]:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. P s \\<and> b s} c1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. P s \\<and> \\<not> b s} c2 Q,A\\<rbrakk>\n   \\<Longrightarrow> \n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. P s} (Cond {s. b s} c1 c2) Q,A\"\n  by (rule Cond) auto\nend\n\n", "meta": {"author": "LVPGroup", "repo": "TimSort", "sha": "16437b6b6e2df9f6d32b2a32be7d0d650d83f980", "save_path": "github-repos/isabelle/LVPGroup-TimSort", "path": "github-repos/isabelle/LVPGroup-TimSort/TimSort-16437b6b6e2df9f6d32b2a32be7d0d650d83f980/Simpl/HoareTotal.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6001883449573376, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.28837770256486284}}
{"text": "theory E3_sound\nimports E3 E3_spec \nbegin\n\n(* TODO: show by induction on m that all derivable items are included in Earley at some stage *) \n\ndefinition loop2_inv :: \"'string => 'string ct_params => ty_impl_loop2 => bool\" where\n  \"loop2_inv s ps s0 ==\n    let nt0 = ps|>ct_nt0 in\n    let nt_items_for_nt = ps|>ct_nt_items_for_nt in\n    let f = % nt. % n. nt_items_for_nt nt (s,n,n) in\n    let tm_items_for_tm = ps|>ct_p_of_tm in\n    let g = % tm. %n. List.map (% x. (tm,n,x)) (tm_items_for_tm tm (s,n,n)) in\n    let ps' = (| \n      sp_nt0=ps|>ct_nt0,\n      sp_nt_items_for_nt=f,\n      sp_tm_items_for_tm=g |)\n    in\n    (! x. x : (s0|>todo_done5) --> x : derivable_items ps') &\n\n    (! x. x : (set (s0|>todo5)) --> x : derivable_items ps') &\n\n    (! (sym::sym) j x. x : ((s0|>blocked5) (j,sym)) --> \n      (case x of (nt,aas,bs,i,j') => (bs ~= []) & (List.hd bs = sym) & (j'=j)) &\n      (NTITM x) : derivable_items ps') &\n\n    (! sym i x. x : ((s0|>complete5) (i,sym)) --> \n      (? j. x=(sym,i,j)) &\n      (? x'. x' : derivable_items ps' & (sym_item_of_complete_item x' = Some x))) &\n\n   (* we dont care about tmoracle and oracle at this point - the correctness of these should follow straightforwardly *)\n\n    True\" (* should be some relation from ty_impl loop2 to E3_spec derivable *)\n\nlemma t1: \"blocked5 (init_state s ps) i = {}\"\n  apply(unfold init_state_def)\n  apply(simp add: impl_mbk_def)\n  apply(simp add: rev_apply_def)\n  apply(case_tac \" ct_nt_items_for_nt ps (ct_nt0 ps) (s, 0, 0)\")\n  apply(simp)\n  apply(simp)\n  done\n  \nlemma t2: \"complete5 (init_state s ps) i = {}\"\n  apply(unfold init_state_def)\n  apply(simp add: impl_mck_def)\n  apply(simp add: rev_apply_def)\n  apply(case_tac \" ct_nt_items_for_nt ps (ct_nt0 ps) (s, 0, 0)\")\n  apply(simp)\n  apply(simp)\n  done  \n  \nlemma t3: \"todo_done5 (init_state s ps) = NTITM ` set (ct_nt_items_for_nt ps (ct_nt0 ps) (s, 0, 0))  \"  \n  apply(unfold init_state_def)\n  apply(simp add: impl_mck_def)\n  apply(simp add: rev_apply_def)\n  apply(case_tac \" ct_nt_items_for_nt ps (ct_nt0 ps) (s, 0, 0)\")\n  apply(simp)\n  apply(simp)\n  done  \n  \ndefinition wf_ct_nt_items_for_nt :: \"(nt => 'string substring => nt_item list) \\<Rightarrow> bool\"\nwhere \"wf_ct_nt_items_for_nt f \\<equiv> \\<forall>n ntitem s i j as. ntitem \\<in> set (f n (s, i, j)) \\<longrightarrow>\n(ntitem = (n, [], (NT n) # as, i, i))\"  \n\ndefinition wf_item_ops :: \"'string ty_ops \\<Rightarrow> bool\"\nwhere \"wf_item_ops tyops \\<equiv> \\<forall>sym i j nt as bs j'. sym_dot_i9 tyops (sym, i, j) = i \\<and> sym_dot_j9 tyops (sym, i, j) = j \\<and> sym6 tyops (sym, i, j) = sym \\<and> with_j9 tyops (nt,as,bs,i,j) j'= (nt,as,bs,i,j') \\<and> shift_a2_b2_c2 tyops (nt,as,bs,i,j) = (nt,(hd bs) # as, tl bs, i, j) \\<and> mk_item tyops = id\"\n\ndefinition impl_maps :: \"'string ty_impl_ctxt \\<Rightarrow> bool\"\nwhere \"impl_maps ctxt \\<equiv> maps ctxt = impl_ctxt_map\"\n\nlemma cut_todo: \"sets ctxt = impl_ctxt_set \\<Longrightarrow> wf_item_ops (item_ops5 ctxt) \\<Longrightarrow> E3.cut ctxt (sym1, as, bs, i, j) (sym2, i2, j2) s0 = s1 \\<Longrightarrow> ( NTITM (sym1, (hd bs) # as, tl bs, i, j2) \\<notin> todo_done5 s0 \\<and> todo5 s1 = (NTITM (sym1, (hd bs) # as, tl bs, i, j2)) # (todo5 s0)) \\<or> (NTITM (sym1, (hd bs) # as, tl bs, i, j2) \\<in> todo_done5 s0 \\<and> s0 = s1)\"\napply(unfold E3.cut_def add_todo_def impl_ctxt_set_def impl_std_def wf_item_ops_def)\napply(simp add: Let_def rev_apply_def wf_item_ops_def )\napply(case_tac \"NTITM (sym1, (hd bs) # as, tl bs, i, j2) \\<in> todo_done5 s0\")\napply(clarsimp)\napply(force)\ndone\n\nlemma t: \"sets ctxt = impl_ctxt_set \\<Longrightarrow> wf_item_ops (item_ops5 ctxt) \\<Longrightarrow>  impl_maps ctxt \\<Longrightarrow> (sym1, as, bs, i, j) \\<in> blocked5 s0 (i', sym2) \\<Longrightarrow>(Finite_Set.fold (\\<lambda>bitm. \\<lambda>x. E3.cut ctxt bitm (sym2, i', j') x) (s0) (blocked5 s0 (i', sym2))) = s1 \\<Longrightarrow> NTITM (sym1, (hd bs) # as, tl bs, i, j') \\<in> set (todo5 s1) \\<or> NTITM (sym1, (hd bs) # as, tl bs, i, j') \\<in> todo_done5 s0\"\napply(unfold E3.cut_def wf_item_ops_def impl_maps_def)\napply(simp add: Let_def rev_apply_def)\napply(unfold impl_ctxt_map_def add_todo_def impl_ctxt_set_def impl_std_def impl_mbk_def)\napply(clarsimp)\napply(unfold Finite_Set.fold_def)\napply(unfold fold_graph_def)\napply(clarsimp)\n\n\n\nlemma sound_init: \"wf_ct_nt_items_for_nt (ct_nt_items_for_nt ps) \\<Longrightarrow> loop2_inv s ps (init_state s ps)\"\n  apply(unfold loop2_inv_def)\n  apply(induct \"ct_nt_items_for_nt ps (ct_nt0 ps) (s, 0, 0)\")\n  apply(simp add: rev_apply_def t1 t2 t3)\n  apply(unfold init_state_def derivable_items_def)\n  apply(simp add: rev_apply_def t1 t2 t3 derivable_items_def)\n  apply(simp add: rev_apply_def t1 t2 t3 wf_ct_nt_items_for_nt_def init_state_def Let_def image_def derivable_items_def impl_mbk_def impl_mck_def )\n  apply(clarify)\nby (metis (erased, hide_lams) not_Cons_self2)\n  \nlemma sound: \"wf_ct_nt_items_for_nt (ct_nt_items_for_nt ps) \\<Longrightarrow> wf_item_ops (item_ops5 ctxt) \\<Longrightarrow> impl_maps ctxt \\<Longrightarrow> loop2_inv s ps s0 ==> loop2 (ctxt::'string ty_impl_ctxt) s0 = s1 ==> loop2_inv s ps s1\"\n  apply(unfold loop2_def loop2_inv_def)\n  apply(simp add: rev_apply_def Let_def)\n  apply(unfold pop_todo_def)\n  apply(induct \"todo5 s0\")\n  apply(simp_all)\n  apply(case_tac \"dest_item (item_ops5 ctxt) a\")\n  apply(case_tac  \"b2_nil (item_ops5 ctxt) prod\")\n  apply(case_tac \"mk_sym_coord (item_ops5 ctxt) (nt2 (item_ops5 ctxt) prod, nt_dot_i9 (item_ops5 ctxt) prod, nt_dot_j9 (item_ops5 ctxt) prod)\")\n  apply(unfold wf_item_ops_def)\n  apply(simp add: rev_apply_def)\n  apply(unfold impl_maps_def)\n  apply(unfold impl_ctxt_map_def)\n  apply(unfold impl_mbk_def)\n  apply(simp)\n  apply(unfold impl_mck_def)\n  apply(simp)\n  apply(unfold update_oracle_def)\n  apply(clarify)\n\n  \n  lemma complete: \"True (* FIXME *)\"\n\nend\n", "meta": {"author": "tomjridge", "repo": "e3_isa", "sha": "ca857f6de5b4111fa129fdc2257584f5c7157067", "save_path": "github-repos/isabelle/tomjridge-e3_isa", "path": "github-repos/isabelle/tomjridge-e3_isa/e3_isa-ca857f6de5b4111fa129fdc2257584f5c7157067/src/E3_sound.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6001883449573376, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.2883777025648628}}
{"text": "theory Preliminary_Library\n  imports Main \"HOL-Library.Word\" \"Word_Lib.Word_Lib_Sumo\" \"HOL-Library.Countable\"\nbegin\n\nsection \\<open>Preliminary Theories\\<close>\ntext \\<open>In this subsection, we provide the type and value system used by the CHERI-C Memory Model.\n      We also provide proofs for the conversion between large words (i.e. bits) and a list of bytes.\n      For primitive bytes that are not $U8_\\tau$ or $S8_\\tau$, we need to be able to convert between\n      their normal representation and list of bytes so that storing values work as intended. \n      The high-level detail is given in the paper~\\cite{park_2022}.\\<close>\nsubsection \\<open>Types and Values\\<close>\ntext \\<open>We first formalise the capability type. We first define \\textit{memory capabilities} as a record,\n      then we define \\textit{tagged capabilities} by extending the record. We state the class \n      comp\\_countable for future work, but countable is sufficient for the block\\_id type.\n      For the permissions, we present only those used by the memory model.\\<close>\nclass comp_countable = countable + zero + ord\n\nrecord ('a :: comp_countable) mem_capability =\n  block_id :: \"'a\" (* block_id *)\n  offset :: int (* offset/address *)\n  base :: nat (* metadata *)\n  len :: nat\n  perm_load :: bool\n  perm_cap_load :: bool\n  perm_store :: bool\n  perm_cap_store :: bool\n  perm_cap_store_local :: bool\n  perm_global :: bool\n\nrecord ('a :: comp_countable) capability = \"'a mem_capability\" + \n  tag :: bool (* tag *)\n\ntext \\<open>cctype corresponds to $\\tau$ in the paper~\\cite{park_2022}, where $\\tau$ is the type system.\\<close>\ndatatype cctype = \n  Uint8\n  | Sint8\n  | Uint16\n  | Sint16\n  | Uint32\n  | Sint32\n  | Uint64\n  | Sint64\n  | Cap\n\ntext \\<open>$'a\\ ccval$ corresponds to $\\mathcal{V}_\\mathcal{C}$ in the paper~\\cite{park_2022}. $'a$ in \n      this instance must be countable. \\<close>\ndatatype 'a ccval = \n  Uint8_v      \"8 word\"\n  | Sint8_v    \"8 sword\"\n  | Uint16_v   \"16 word\"\n  | Sint16_v   \"16 sword\"\n  | Uint32_v   \"32 word\"\n  | Sint32_v   \"32 sword\"\n  | Uint64_v   \"64 word\"\n  | Sint64_v   \"64 sword\"\n  | Cap_v      \"'a capability\"\n  | Cap_v_frag \"'a capability\" \"nat\"\n  | Undef\n\ntext \\<open>memval\\_type infers the type of a value. \\<close>\nfun memval_type :: \"'a ccval \\<Rightarrow> cctype\"\n  where\n  \"memval_type v = (case v of \n     Uint8_v  _ \\<Rightarrow> Uint8\n   | Sint8_v  _ \\<Rightarrow> Sint8\n   | Uint16_v _ \\<Rightarrow> Uint16\n   | Sint16_v _ \\<Rightarrow> Sint16\n   | Uint32_v _ \\<Rightarrow> Uint32\n   | Sint32_v _ \\<Rightarrow> Sint32\n   | Uint64_v _ \\<Rightarrow> Uint64\n   | Sint64_v _ \\<Rightarrow> Sint64\n   | Cap_v    _ \\<Rightarrow> Cap\n   | Cap_v_frag _ _ \\<Rightarrow> Uint8)\"\n\n\nsubsection \\<open>Primitive Value Conversion and Cast Proof\\<close>\ntext \\<open>In this subsection, we provide proofs for the conversion between words and list of words.\n      We also provide proofs that casting primitive values is correct. These will be used by the\n      \\texttt{load} and \\texttt{store} operations in the memory model.\\<close>\nabbreviation encode_u8 :: \"nat \\<Rightarrow> 8 word\"\n  where\n  \"encode_u8 x \\<equiv> word_of_nat x\"\n\nabbreviation decode_u8 :: \"8 word \\<Rightarrow> nat\"\n  where\n  \"decode_u8 b \\<equiv> unat b\"\n\nabbreviation encode_u8_list :: \"8 word \\<Rightarrow> 8 word list\"\n  where\n  \"encode_u8_list w \\<equiv> [w]\"\n\nabbreviation decode_u8_list :: \"8 word list \\<Rightarrow> 8 word\"\n  where\n  \"decode_u8_list ls \\<equiv> hd ls\"\n\nlemma encode_decode_u8_list:\n  \"ls = [b] \\<Longrightarrow> ls = encode_u8_list (decode_u8_list ls)\"\n  by simp\n\nlemma decode_encode_u8_list:\n  \"w = decode_u8_list (encode_u8_list w)\"\n  by simp\n\nlemma encode_decode_u8:\n  \"w = encode_u8 (decode_u8 w)\"\n  by simp\n\nlemma decode_encode_u8:\n  assumes \"i \\<le> 2 ^ LENGTH(8) - 1\"\n  shows \"i = decode_u8 (encode_u8 i)\"\n  by (metis assms le_unat_uoi unat_minus_one_word)\n  \nabbreviation u64_split :: \"64 word \\<Rightarrow> 32 word list\"\n  where\n  \"u64_split x \\<equiv> (word_rsplit :: 64 word \\<Rightarrow> 32 word list) x\"\n\nabbreviation u32_split :: \"32 word \\<Rightarrow> 16 word list\"\n  where\n  \"u32_split x \\<equiv> (word_rsplit :: 32 word \\<Rightarrow> 16 word list) x\"\n\nabbreviation u16_split :: \"16 word \\<Rightarrow> 8 word list\"\n  where\n  \"u16_split x \\<equiv> (word_rsplit :: 16 word \\<Rightarrow> 8 word list) x\"\n\nabbreviation cat_u16 :: \"8 word list \\<Rightarrow> 16 word\"\n  where\n  \"cat_u16 x \\<equiv> (word_rcat :: 8 word list \\<Rightarrow> 16 word) x\"\n\nabbreviation encode_u16 :: \"nat \\<Rightarrow> 8 word list\"\n  where \n  \"encode_u16 x \\<equiv> u16_split (word_of_nat x)\"\n\nabbreviation decode_u16 :: \"8 word list \\<Rightarrow> nat\"\n  where\n  \"decode_u16 x \\<equiv> unat (cat_u16 x)\"\n\nlemma flatten_u16_length:\n  \"length (u16_split vs) = 2\"\n  by (simp add: length_word_rsplit_even_size wsst_TYs(3))\n\nlemma rsplit_rcat_eq:\n  assumes \"LENGTH(('b::len)) mod LENGTH(('a::len)) = 0\"\n    and \"length w = LENGTH('b) div LENGTH('a)\"\n  shows \"(word_rsplit :: 'b word \\<Rightarrow> 'a word list) ((word_rcat :: 'a word list \\<Rightarrow> 'b word) w) = w\"\n  by (simp add: assms mod_0_imp_dvd size_word.rep_eq word_rsplit_rcat_size)\n\nlemma rsplit_rcat_u16_eq:\n  assumes \"w = [a1, a2]\"\n  shows \"(word_rsplit :: 16 word \\<Rightarrow> 8 word list) ((word_rcat :: 8 word list \\<Rightarrow> 16 word) w) = w\"\nproof -\n  have l1: \"length w * 8 = 16\"\n    using assms by clarsimp\n  moreover have l2: \"size ((word_rcat :: 8 word list \\<Rightarrow> 16 word) w) = 16\"\n    using assms\n    by (simp add: size_word.rep_eq)\n  from l1 l2 have \"length w * 8 = size ((word_rcat :: 8 word list \\<Rightarrow> 16 word) w)\"\n    by argo\n  thus ?thesis\n    by (metis l1 l2 len8 word_rsplit_rcat_size)\nqed\n    \n\nlemma encode_decode_u16:\n  assumes \"w = [a, b]\"\n  shows \"w = encode_u16 (decode_u16 w)\"\n  by (simp add: assms rsplit_rcat_eq)\n\nlemma cat_flatten_u16_eq:\n  \"cat_u16 (u16_split w) = w\" \n  by (simp add: word_rcat_rsplit)\n\nlemma decode_encode_u16:\n  assumes \"i \\<le> 2 ^ LENGTH(16) - 1\"\n  shows \"i = decode_u16 (encode_u16 i)\" \n  by (metis assms cat_flatten_u16_eq le_unat_uoi unat_minus_one_word)\n\nabbreviation flatten_u32 :: \"32 word \\<Rightarrow> 8 word list\"\n  where\n  \"flatten_u32 x \\<equiv> (word_rsplit :: 32 word \\<Rightarrow> 8 word list) x\"\n\nabbreviation cat_u32 :: \"8 word list \\<Rightarrow> 32 word\"\n  where\n  \"cat_u32 x \\<equiv> (word_rcat :: 8 word list \\<Rightarrow> 32 word) x\"\n\nabbreviation encode_u32 :: \"nat \\<Rightarrow> 8 word list\"\n  where\n  \"encode_u32 x \\<equiv> flatten_u32 (word_of_nat x)\"\n\nabbreviation decode_u32 :: \"8 word list \\<Rightarrow> nat\"\n  where\n  \"decode_u32 i \\<equiv> unat (cat_u32 i)\"\n\nlemma flatten_u32_length:\n  \"length (flatten_u32 vs) = 4\"\n  by (simp add: length_word_rsplit_even_size wsst_TYs(3))\n\nlemma rsplit_rcat_u32_eq:\n  assumes \"w = [a1, a2, b1, b2]\"\n  shows \"(word_rsplit :: 32 word \\<Rightarrow> 8 word list) ((word_rcat :: 8 word list \\<Rightarrow> 32 word) w) = w\" \n  using rsplit_rcat_eq assms\n  by force\n\nlemma encode_decode_u32:\n  assumes \"w = [a1, a2, b1, b2]\"\n  shows \"w = encode_u32 (decode_u32 w)\" \n  using assms \n  by (simp add: rsplit_rcat_u32_eq)\n\nlemma cat_flatten_u32_eq:\n  \"cat_u32 (flatten_u32 w) = w\" \n  by (simp add: word_rcat_rsplit)\n\nlemma decode_encode_u32:\n  assumes \"i \\<le> 2 ^ LENGTH(32) - 1\"\n  shows \"i = decode_u32 (encode_u32 i)\" \n  by (metis assms le_unat_uoi unat_minus_one_word word_rcat_rsplit)\n\nabbreviation flatten_u64 :: \"64 word \\<Rightarrow> 8 word list\"\n  where\n  \"flatten_u64 x \\<equiv> (word_rsplit :: 64 word \\<Rightarrow> 8 word list) x\"\n\nabbreviation cat_u64 :: \"8 word list \\<Rightarrow> 64 word\"\n  where\n  \"cat_u64 x \\<equiv> word_rcat x\"\n\nabbreviation encode_u64 :: \"nat \\<Rightarrow> 8 word list\"\n  where\n  \"encode_u64 x \\<equiv> flatten_u64 (word_of_nat x)\"\n\nabbreviation decode_u64 :: \"8 word list \\<Rightarrow> nat\"\n  where\n  \"decode_u64 x \\<equiv> unat (cat_u64 x)\"\n\nlemma flatten_u64_length:\n  \"length (flatten_u64 vs) = 8\"\n  by (simp add: length_word_rsplit_even_size wsst_TYs(3))\n\nlemma encode_decode_u64:\n  assumes \"w = [a1, a2, b1, b2, c1, c2, d1, d2]\"\n  shows \"w = encode_u64 (decode_u64 w)\"\n  using assms \n  by (simp add: rsplit_rcat_eq)\n\nlemma cat_flatten_u64_eq:\n  \"cat_u64 (flatten_u64 w) = w\" \n  by (simp add: word_rcat_rsplit)\n\nlemma decode_encode_u64:\n  assumes \"i \\<le> 2 ^ LENGTH(64) - 1\"\n  shows \"i = decode_u64 (encode_u64 i)\" \n  by (metis assms le_unat_uoi unat_minus_one_word word_rcat_rsplit)\n\nabbreviation encode_s8 :: \"int \\<Rightarrow> 8 sword\"\n  where\n  \"encode_s8 x \\<equiv> word_of_int x\"\n\nabbreviation decode_s8 :: \"8 sword \\<Rightarrow> int\"\n  where\n  \"decode_s8 b \\<equiv> sint b\"\n\nabbreviation encode_s8_list :: \"8 sword \\<Rightarrow> 8 word list\"\n  where\n  \"encode_s8_list w \\<equiv> [SCAST(8 signed \\<rightarrow> 8) w]\"\n\nabbreviation decode_s8_list :: \"8 word list \\<Rightarrow> 8 sword\"\n  where\n  \"decode_s8_list ls \\<equiv> UCAST(8 \\<rightarrow> 8 signed) (hd ls)\"\n\nlemma encode_decode_s8_list:\n  \"ls = [b] \\<Longrightarrow> ls = encode_s8_list (decode_s8_list ls)\"\n  by simp\n\nlemma decode_encode_s8_list:\n  \"w = decode_s8_list (encode_s8_list w)\"\n  by simp\n\nlemma encode_decode_s8:\n  \"w = encode_s8 (decode_s8 w)\"\n  by simp\n\nlemma decode_encode_s8:\n  assumes \"- (2 ^ (LENGTH(8) - 1)) \\<le> i\"\n    and \"i < 2 ^ (LENGTH(8) - 1)\"\n  shows \"i = decode_s8 (encode_s8 i)\" \n  by (metis assms More_Word.sint_of_int_eq len_signed)\n  \nabbreviation s64_split :: \"64 sword \\<Rightarrow> 32 word list\"\n  where\n  \"s64_split x \\<equiv> (word_rsplit :: 64 sword \\<Rightarrow> 32 word list) x\"\n\nabbreviation s32_split :: \"32 sword \\<Rightarrow> 16 word list\"\n  where\n  \"s32_split x \\<equiv> (word_rsplit :: 32 sword \\<Rightarrow> 16 word list) x\"\n\nabbreviation s16_split :: \"16 sword \\<Rightarrow> 8 word list\"\n  where\n  \"s16_split x \\<equiv> (word_rsplit :: 16 sword \\<Rightarrow> 8 word list) x\"\n\nabbreviation cat_s16 :: \"8 word list \\<Rightarrow> 16 sword\"\n  where\n  \"cat_s16 x \\<equiv> (word_rcat :: 8 word list \\<Rightarrow> 16 sword) x\"\n\nabbreviation encode_s16 :: \"int \\<Rightarrow> 8 word list\"\n  where \n  \"encode_s16 x \\<equiv> s16_split (word_of_int x)\"\n\nabbreviation decode_s16 :: \"8 word list \\<Rightarrow> int\"\n  where\n  \"decode_s16 x \\<equiv> sint (cat_s16 x)\"\n\nlemma flatten_s16_length:\n  \"length (s16_split vs) = 2\"\n  by (simp add: length_word_rsplit_even_size wsst_TYs(3))\n\nlemma rsplit_rcat_s16_eq:\n  assumes \"w = [a1, a2]\"\n  shows \"(word_rsplit :: 16 sword \\<Rightarrow> 8 word list) ((word_rcat :: 8 word list \\<Rightarrow> 16 sword) w) = w\"\nproof -\n  have l1: \"length w * 8 = 16\"\n    using assms by clarsimp\n  moreover have l2: \"size ((word_rcat :: 8 word list \\<Rightarrow> 16 sword) w) = 16\"\n    using assms\n    by (simp add: size_word.rep_eq)\n  from l1 l2 have \"length w * 8 = size ((word_rcat :: 8 word list \\<Rightarrow> 16 sword) w)\"\n    by argo\n  thus ?thesis\n    by (simp add: word_rsplit_rcat_size)\nqed\n    \n\nlemma encode_decode_s16:\n  assumes \"w = [a, b]\"\n  shows \"w = encode_s16 (decode_s16 w)\"\n  by (simp add: assms rsplit_rcat_eq)\n\nlemma cat_flatten_s16_eq:\n  \"cat_s16 (s16_split w) = w\" \n  by (simp add: word_rcat_rsplit)\n\nlemma decode_encode_s16:\n  assumes \"- (2 ^ (LENGTH(16) - 1)) \\<le> i\"\n    and \"i < 2 ^ (LENGTH(16) - 1)\"\n  shows \"i = decode_s16 (encode_s16 i)\" \n  by (metis assms cat_flatten_s16_eq len_signed sint_of_int_eq)\n\nabbreviation flatten_s32 :: \"32 sword \\<Rightarrow> 8 word list\"\n  where\n  \"flatten_s32 x \\<equiv> (word_rsplit :: 32 sword \\<Rightarrow> 8 word list) x\"\n\nabbreviation cat_s32 :: \"8 word list \\<Rightarrow> 32 sword\"\n  where\n  \"cat_s32 x \\<equiv> (word_rcat :: 8 word list \\<Rightarrow> 32 sword) x\"\n\nabbreviation encode_s32 :: \"int \\<Rightarrow> 8 word list\"\n  where\n  \"encode_s32 x \\<equiv> flatten_s32 (word_of_int x)\"\n\nabbreviation decode_s32 :: \"8 word list \\<Rightarrow> int\"\n  where\n  \"decode_s32 i \\<equiv> sint (cat_s32 i)\"\n\nlemma flatten_s32_length:\n  \"length (flatten_s32 vs) = 4\"\n  by (simp add: length_word_rsplit_even_size wsst_TYs(3))\n\nlemma rsplit_rcat_s32_eq:\n  assumes \"w = [a1, a2, b1, b2]\"\n  shows \"(word_rsplit :: 32 sword \\<Rightarrow> 8 word list) ((word_rcat :: 8 word list \\<Rightarrow> 32 sword) w) = w\" \n  using rsplit_rcat_eq assms\n  by force\n\nlemma encode_decode_s32:\n  assumes \"w = [a1, a2, b1, b2]\"\n  shows \"w = encode_s32 (decode_s32 w)\" \n  using assms \n  by (simp add: rsplit_rcat_s32_eq)\n\nlemma decode_encode_s32:\n  assumes \"- (2 ^ (LENGTH(32) - 1)) \\<le> i\"\n    and \"i < 2 ^ (LENGTH(32) - 1)\"\n  shows \"i = decode_s32 (encode_s32 i)\" \n  by (metis assms len_signed sint_of_int_eq word_rcat_rsplit)\n  \nabbreviation flatten_s64 :: \"64 sword \\<Rightarrow> 8 word list\"\n  where\n  \"flatten_s64 x \\<equiv> (word_rsplit :: 64 sword \\<Rightarrow> 8 word list) x\"\n\nlemma flatten_s64_length:\n  \"length (flatten_s64 vs) = 8\"\n  by (simp add: length_word_rsplit_even_size wsst_TYs(3))\n\nabbreviation cat_s64 :: \"8 word list \\<Rightarrow> 64 sword\"\n  where\n  \"cat_s64 x \\<equiv> word_rcat x\"\n\nabbreviation encode_s64 :: \"int \\<Rightarrow> 8 word list\"\n  where\n  \"encode_s64 x \\<equiv> flatten_s64 (word_of_int x)\"\n\nabbreviation decode_s64 :: \"8 word list \\<Rightarrow> int\"\n  where\n  \"decode_s64 x \\<equiv> sint (cat_s64 x)\"\n\nlemma encode_decode_s64:\n  assumes \"w = [a1, a2, b1, b2, c1, c2, d1, d2]\"\n  shows \"w = encode_s64 (decode_s64 w)\"\n  using assms \n  by (simp add: rsplit_rcat_eq)\n\nlemma decode_encode_s64:\n  assumes \"- (2 ^ (LENGTH(64) - 1)) \\<le> i\"\n    and \"i < 2 ^ (LENGTH(64) - 1)\"\n  shows \"i = decode_s64 (encode_s64 i)\" \n  by (metis assms len_signed sint_of_int_eq word_rcat_rsplit)\n\ndefinition word_of_integer :: \"integer \\<Rightarrow> 'a::len word\"\n  where\n  \"word_of_integer x \\<equiv> word_of_int (int_of_integer x)\"\n\ndefinition sword_of_integer :: \"integer \\<Rightarrow> 'a::len sword\"\n  where\n  \"sword_of_integer x \\<equiv> word_of_int (int_of_integer x)\"\n\ndefinition integer_of_word :: \"'a::len word \\<Rightarrow> integer\"\n  where\n  \"integer_of_word x \\<equiv> integer_of_int (uint x)\"\n\ndefinition integer_of_sword :: \"'a::len sword \\<Rightarrow> integer\"\n  where\n  \"integer_of_sword x \\<equiv> integer_of_int (sint x)\"\n\nlemma word_integer_eq:\n  \"word_of_integer (integer_of_word w) = w\"\n  unfolding word_of_integer_def integer_of_word_def\n  by (metis int_of_integer_of_int integer_of_int_eq_of_int word_uint.Rep_inverse')\n\nlemma sword_integer_eq:\n  \"sword_of_integer (integer_of_sword w) = w\"\n  unfolding sword_of_integer_def integer_of_sword_def\n  by (metis int_of_integer_of_int integer_of_int_eq_of_int word_sint.Rep_inverse')\n\nlemma integer_word_bounded_eq:\n  assumes \"0 \\<le> i\"\n  assumes \"i \\<le> 2 ^ LENGTH('a::len) - 1\"\n  shows \"integer_of_word ((word_of_integer :: integer \\<Rightarrow> 'a word) i) = i\"\n  unfolding integer_of_word_def word_of_integer_def\n  using assms \n  by (metis integer_less_eq_iff integer_of_int_eq_of_int minus_integer.rep_eq of_int_0_le_iff of_int_eq_1_iff of_int_eq_numeral_power_cancel_iff of_int_integer_of word_of_int_inverse zle_diff1_eq)\n\nlemma integer_sword_bounded_eq:\n  assumes \"- (2 ^ (LENGTH('a::len) - 1)) \\<le> i\"\n    and \"i < 2 ^ (LENGTH('a) - 1)\"\n  shows \"integer_of_sword ((sword_of_integer :: integer \\<Rightarrow> 'a sword) i) = i\"\n  unfolding integer_of_sword_def sword_of_integer_def\n  using signed_take_bit_int_eq_self assms \n  by (smt (verit) diff_numeral_special(11) int_of_integer_numeral integer_less_eq_iff integer_of_int_eq_of_int len_signed minus_integer.rep_eq numeral_power_eq_of_int_cancel_iff of_int_integer_of of_int_power_less_of_int_cancel_iff one_integer.rep_eq sint_of_int_eq uminus_integer.rep_eq)\n\ndefinition word8_of_integer :: \"integer \\<Rightarrow> 8 word\"\n  where\n  \"word8_of_integer \\<equiv> word_of_integer\"\n\ndefinition word16_of_integer :: \"integer \\<Rightarrow> 16 word\"\n  where\n  \"word16_of_integer \\<equiv> word_of_integer\"\n\ndefinition word32_of_integer :: \"integer \\<Rightarrow> 32 word\"\n  where\n  \"word32_of_integer \\<equiv> word_of_integer\"\n\ndefinition word64_of_integer :: \"integer \\<Rightarrow> 64 word\"\n  where\n  \"word64_of_integer \\<equiv> word_of_integer\"\n\ndefinition integer_of_word8 :: \"8 word \\<Rightarrow> integer\"\n  where\n  \"integer_of_word8 \\<equiv> integer_of_word\"\n                                \ndefinition integer_of_word16 :: \"16 word \\<Rightarrow> integer\"\n  where\n  \"integer_of_word16 \\<equiv> integer_of_word\"\n\ndefinition integer_of_word32 :: \"32 word \\<Rightarrow> integer\"\n  where\n  \"integer_of_word32 \\<equiv> integer_of_word\"\n\ndefinition integer_of_word64 :: \"64 word \\<Rightarrow> integer\"\n  where\n  \"integer_of_word64 \\<equiv> integer_of_word\"\n\nlemma word8_integer_eq:\n  \"word8_of_integer (integer_of_word8 w) = w\" \n  unfolding word8_of_integer_def integer_of_word8_def\n  using word_integer_eq \n  by blast\n\nlemma word16_integer_eq:\n  \"word16_of_integer (integer_of_word16 w) = w\" \n  unfolding word16_of_integer_def integer_of_word16_def\n  using word_integer_eq \n  by blast\n\nlemma word32_integer_eq:\n  \"word32_of_integer (integer_of_word32 w) = w\" \n  unfolding word32_of_integer_def integer_of_word32_def\n  using word_integer_eq \n  by blast\n\nlemma word64_integer_eq:\n  \"word64_of_integer (integer_of_word64 w) = w\"\n  unfolding word64_of_integer_def integer_of_word64_def\n  using word_integer_eq\n  by blast\n\nlemma integer_word8_bounded_eq:\n   assumes \"0 \\<le> i\"\n    and \"i \\<le> 2 ^ LENGTH(8) - 1\"\n  shows \"integer_of_word8 (word8_of_integer i) = i\"\n  unfolding word8_of_integer_def integer_of_word8_def\n  using integer_word_bounded_eq assms\n  by blast\n\nlemma integer_word16_bounded_eq:\n   assumes \"0 \\<le> i\"\n    and \"i \\<le> 2 ^ LENGTH(16) - 1\"\n  shows \"integer_of_word16 (word16_of_integer i) = i\"\n  unfolding word16_of_integer_def integer_of_word16_def\n  using integer_word_bounded_eq assms\n  by blast\n\nlemma integer_word32_bounded_eq:\n   assumes \"0 \\<le> i\"\n    and \"i \\<le> 2 ^ LENGTH(32) - 1\"\n  shows \"integer_of_word32 (word32_of_integer i) = i\"\n  unfolding word32_of_integer_def integer_of_word32_def\n  using integer_word_bounded_eq assms\n  by blast\n\nlemma integer_word64_bounded_eq:\n   assumes \"0 \\<le> i\"\n    and \"i \\<le> 2 ^ LENGTH(64) - 1\"\n  shows \"integer_of_word64 (word64_of_integer i) = i\"\n  unfolding word64_of_integer_def integer_of_word64_def\n  using integer_word_bounded_eq assms\n  by blast\n\ndefinition sword8_of_integer :: \"integer \\<Rightarrow> 8 sword\"\n  where\n  \"sword8_of_integer \\<equiv> sword_of_integer\"\n\ndefinition sword16_of_integer :: \"integer \\<Rightarrow> 16 sword\"\n  where\n  \"sword16_of_integer \\<equiv> sword_of_integer\"\n\ndefinition sword32_of_integer :: \"integer \\<Rightarrow> 32 sword\"\n  where\n  \"sword32_of_integer \\<equiv> sword_of_integer\"\n\ndefinition sword64_of_integer :: \"integer \\<Rightarrow> 64 sword\"\n  where\n  \"sword64_of_integer \\<equiv> sword_of_integer\"\n\ndefinition integer_of_sword8 :: \"8 sword \\<Rightarrow> integer\"\n  where\n  \"integer_of_sword8 \\<equiv> integer_of_sword\"\n\ndefinition integer_of_sword16 :: \"16 sword \\<Rightarrow> integer\"\n  where\n  \"integer_of_sword16 \\<equiv> integer_of_sword\"\n\ndefinition integer_of_sword32 :: \"32 sword \\<Rightarrow> integer\"\n  where\n  \"integer_of_sword32 \\<equiv> integer_of_sword\"\n\ndefinition integer_of_sword64 :: \"64 sword \\<Rightarrow> integer\"\n  where\n  \"integer_of_sword64 \\<equiv> integer_of_sword\"\n\nlemma sword8_integer_eq:\n  \"sword8_of_integer (integer_of_sword8 w) = w\" \n  unfolding sword8_of_integer_def integer_of_sword8_def\n  using sword_integer_eq \n  by blast\n\nlemma sword16_integer_eq:\n  \"sword16_of_integer (integer_of_sword16 w) = w\" \n  unfolding sword16_of_integer_def integer_of_sword16_def\n  using sword_integer_eq \n  by blast\n\nlemma sword32_integer_eq:\n  \"sword32_of_integer (integer_of_sword32 w) = w\" \n  unfolding sword32_of_integer_def integer_of_sword32_def\n  using sword_integer_eq \n  by blast\n\nlemma sword64_integer_eq:\n  \"sword64_of_integer (integer_of_sword64 w) = w\"\n  unfolding sword64_of_integer_def integer_of_sword64_def\n  using sword_integer_eq\n  by blast\n\nlemma integer_sword8_bounded_eq:\n   assumes \"- (2 ^ (LENGTH(8) - 1)) \\<le> i\"\n    and \"i < 2 ^ (LENGTH(8) - 1)\"\n  shows \"integer_of_sword8 (sword8_of_integer i) = i\"\n  unfolding sword8_of_integer_def integer_of_sword8_def\n  using integer_sword_bounded_eq assms \n  by metis \n\nlemma integer_sword16_bounded_eq:\n   assumes \"- (2 ^ (LENGTH(16) - 1)) \\<le> i\"\n    and \"i < 2 ^ (LENGTH(16) - 1)\"\n  shows \"integer_of_sword16 (sword16_of_integer i) = i\"\n  unfolding sword16_of_integer_def integer_of_sword16_def\n  using integer_sword_bounded_eq assms\n  by metis\n\nlemma integer_sword32_bounded_eq:\n   assumes \"- (2 ^ (LENGTH(32) - 1)) \\<le> i\"\n    and \"i < 2 ^ (LENGTH(32) - 1)\"\n  shows \"integer_of_sword32 (sword32_of_integer i) = i\"\n  unfolding sword32_of_integer_def integer_of_sword32_def\n  using integer_sword_bounded_eq assms \n  by metis\n\nlemma integer_sword64_bounded_eq:\n   assumes \"- (2 ^ (LENGTH(64) - 1)) \\<le> i\"\n    and \"i < 2 ^ (LENGTH(64) - 1)\"\n  shows \"integer_of_sword64 (sword64_of_integer i) = i\"\n  unfolding sword64_of_integer_def integer_of_sword64_def\n  using integer_sword_bounded_eq assms\n  by metis\n\nlemmas flatten_types_length = flatten_u16_length flatten_s16_length flatten_u32_length flatten_s32_length flatten_u64_length flatten_s64_length\n\ntext \\<open>cast\\_val is an executable code that ensures easy casting of values. This value cast function\n      is used within the Gillian \n      framework~\\cite{old_gillian_2020, gillian_2021, maksimovic_2021, fragoso_2020}.\\<close>\ndefinition cast_val ::  \"String.literal \\<Rightarrow> integer \\<Rightarrow> integer\"\n  where\n  \"cast_val s i \\<equiv>\n     if s = STR ''uint8'' then integer_of_word8 (word8_of_integer i) \n     else if s = STR ''int8'' then integer_of_sword8 (sword8_of_integer i)\n     else if s = STR ''uint16'' then integer_of_word16 (word16_of_integer i)\n     else if s = STR ''int16'' then integer_of_sword16 (sword16_of_integer i)\n     else if s = STR ''uint32'' then integer_of_word32 (word32_of_integer i)\n     else if s = STR ''int32'' then integer_of_sword32 (sword32_of_integer i)\n     else if s = STR ''uint64'' then integer_of_word64 (word64_of_integer i)\n     else if s = STR ''int64'' then integer_of_sword64 (sword64_of_integer i)\n     else i\"\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/CHERI-C_Memory_Model/Preliminary_Library.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.28830406150349597}}
{"text": "(*  Title:      ZF/Inductive.thy\n    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory\n    Copyright   1993  University of Cambridge\n\nInductive definitions use least fixedpoints with standard products and sums\nCoinductive definitions use greatest fixedpoints with Quine products and sums\n\nSums are used only for mutual recursion;\nProducts are used only to derive \"streamlined\" induction rules for relations\n*)\n\nsection\\<open>Inductive and Coinductive Definitions\\<close>\n\ntheory Inductive\nimports Fixedpt QPair Nat\nkeywords\n  \"inductive\" \"coinductive\" \"inductive_cases\" \"rep_datatype\" \"primrec\" :: thy_decl and\n  \"domains\" \"intros\" \"monos\" \"con_defs\" \"type_intros\" \"type_elims\"\n    \"elimination\" \"induction\" \"case_eqns\" \"recursor_eqns\" :: quasi_command\nbegin\n\nlemma def_swap_iff: \"a == b ==> a = c \\<longleftrightarrow> c = b\"\n  by blast\n\nlemma def_trans: \"f == g ==> g(a) = b ==> f(a) = b\"\n  by simp\n\nlemma refl_thin: \"!!P. a = a ==> P ==> P\" .\n\nML_file \\<open>ind_syntax.ML\\<close>\nML_file \\<open>Tools/ind_cases.ML\\<close>\nML_file \\<open>Tools/cartprod.ML\\<close>\nML_file \\<open>Tools/inductive_package.ML\\<close>\nML_file \\<open>Tools/induct_tacs.ML\\<close>\nML_file \\<open>Tools/primrec_package.ML\\<close>\n\nML \\<open>\nstructure Lfp =\n  struct\n  val oper      = \\<^Const>\\<open>lfp\\<close>\n  val bnd_mono  = \\<^Const>\\<open>bnd_mono\\<close>\n  val bnd_monoI = @{thm bnd_monoI}\n  val subs      = @{thm def_lfp_subset}\n  val Tarski    = @{thm def_lfp_unfold}\n  val induct    = @{thm def_induct}\n  end;\n\nstructure Standard_Prod =\n  struct\n  val sigma     = \\<^Const>\\<open>Sigma\\<close>\n  val pair      = \\<^Const>\\<open>Pair\\<close>\n  val split_name = \\<^const_name>\\<open>split\\<close>\n  val pair_iff  = @{thm Pair_iff}\n  val split_eq  = @{thm split}\n  val fsplitI   = @{thm splitI}\n  val fsplitD   = @{thm splitD}\n  val fsplitE   = @{thm splitE}\n  end;\n\nstructure Standard_CP = CartProd_Fun (Standard_Prod);\n\nstructure Standard_Sum =\n  struct\n  val sum       = \\<^Const>\\<open>sum\\<close>\n  val inl       = \\<^Const>\\<open>Inl\\<close>\n  val inr       = \\<^Const>\\<open>Inr\\<close>\n  val elim      = \\<^Const>\\<open>case\\<close>\n  val case_inl  = @{thm case_Inl}\n  val case_inr  = @{thm case_Inr}\n  val inl_iff   = @{thm Inl_iff}\n  val inr_iff   = @{thm Inr_iff}\n  val distinct  = @{thm Inl_Inr_iff}\n  val distinct' = @{thm Inr_Inl_iff}\n  val free_SEs  = Ind_Syntax.mk_free_SEs\n            [distinct, distinct', inl_iff, inr_iff, Standard_Prod.pair_iff]\n  end;\n\n\nstructure Ind_Package =\n    Add_inductive_def_Fun\n      (structure Fp=Lfp and Pr=Standard_Prod and CP=Standard_CP\n       and Su=Standard_Sum val coind = false);\n\n\nstructure Gfp =\n  struct\n  val oper      = \\<^Const>\\<open>gfp\\<close>\n  val bnd_mono  = \\<^Const>\\<open>bnd_mono\\<close>\n  val bnd_monoI = @{thm bnd_monoI}\n  val subs      = @{thm def_gfp_subset}\n  val Tarski    = @{thm def_gfp_unfold}\n  val induct    = @{thm def_Collect_coinduct}\n  end;\n\nstructure Quine_Prod =\n  struct\n  val sigma     = \\<^Const>\\<open>QSigma\\<close>\n  val pair      = \\<^Const>\\<open>QPair\\<close>\n  val split_name = \\<^const_name>\\<open>qsplit\\<close>\n  val pair_iff  = @{thm QPair_iff}\n  val split_eq  = @{thm qsplit}\n  val fsplitI   = @{thm qsplitI}\n  val fsplitD   = @{thm qsplitD}\n  val fsplitE   = @{thm qsplitE}\n  end;\n\nstructure Quine_CP = CartProd_Fun (Quine_Prod);\n\nstructure Quine_Sum =\n  struct\n  val sum       = \\<^Const>\\<open>qsum\\<close>\n  val inl       = \\<^Const>\\<open>QInl\\<close>\n  val inr       = \\<^Const>\\<open>QInr\\<close>\n  val elim      = \\<^Const>\\<open>qcase\\<close>\n  val case_inl  = @{thm qcase_QInl}\n  val case_inr  = @{thm qcase_QInr}\n  val inl_iff   = @{thm QInl_iff}\n  val inr_iff   = @{thm QInr_iff}\n  val distinct  = @{thm QInl_QInr_iff}\n  val distinct' = @{thm QInr_QInl_iff}\n  val free_SEs  = Ind_Syntax.mk_free_SEs\n            [distinct, distinct', inl_iff, inr_iff, Quine_Prod.pair_iff]\n  end;\n\n\nstructure CoInd_Package =\n  Add_inductive_def_Fun(structure Fp=Gfp and Pr=Quine_Prod and CP=Quine_CP\n    and Su=Quine_Sum val coind = true);\n\n\\<close>\n\nend\n", "meta": {"author": "lexbailey", "repo": "itrees_isabelle_fork", "sha": "60e0b4893d0f767483ad3a4e43d2001ca10deef3", "save_path": "github-repos/isabelle/lexbailey-itrees_isabelle_fork", "path": "github-repos/isabelle/lexbailey-itrees_isabelle_fork/itrees_isabelle_fork-60e0b4893d0f767483ad3a4e43d2001ca10deef3/src/ZF/Inductive.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.28830406150349597}}
{"text": "theory OpSem\nimports Main HOL.Rat \nbegin\n\ntype_synonym TS = rat (* Timestamp *)\ntype_synonym T = nat (* Thread ID *)\ntype_synonym L = nat (* Location *)\n \ndefinition \"null = (0 :: nat)\"\n\ntype_synonym V = nat\n\n(* bool: true = release/aquire or false = relaxed*)\ndatatype action =\n    Read bool L V\n  | Write bool L V\n  | Update L V V\n\nprint_theorems\n\nfun avar :: \"action \\<Rightarrow> L\" where\n    \"avar (Read _ x v) = x\"\n  | \"avar (Write _ x v) = x\"\n  | \"avar (Update x e v) = x\"\n\nfun wr_val :: \"action \\<Rightarrow> V option\" where\n    \"wr_val (Write _ _ v) =  Some v\"\n  | \"wr_val (Update _ _ v) = Some  v\"\n  | \"wr_val _ = None\"\n\nfun rd_val :: \"action \\<Rightarrow> V option\" where\n    \"rd_val (Read _ _ v) = Some v\"\n  | \"rd_val (Update _ v _) = Some v\"\n  | \"rd_val _ = None\"\n\nfun isRA :: \"action \\<Rightarrow> bool\" where\n    \"isRA (Read b _ _) = b\" \n  | \"isRA (Write b _ _) = b\"\n  | \"isRA (Update _ _ _) = True\"\n\nfun isWr :: \"action \\<Rightarrow> bool\" where\n    \"isWr (Read _ _ _) = False\" \n  | \"isWr (Write _ _ _) = True\"\n  | \"isWr (Update _ _ _) = False\"\n\nfun isRd :: \"action \\<Rightarrow> bool\" where\n    \"isRd (Read _ _ _) = True\" \n  | \"isRd (Write _ _ _) = False\"\n  | \"isRd (Update _ _ _) = False\"\n\nfun isUp :: \"action \\<Rightarrow> bool\" where\n    \"isUp (Read _ _ _) = False\" \n  | \"isUp (Write _ _ _) = False\"\n  | \"isUp (Update _ _ _) = True\"\n\n\nabbreviation \"reads a \\<equiv> a \\<in> (dom rd_val)\"\nabbreviation \"writes a \\<equiv> a \\<in> (dom wr_val)\"\n\n\ntype_synonym View = \"L \\<Rightarrow> T\"\n\ntype_synonym event = \"TS \\<times> T \\<times> action\"\n\ndefinition time_stamp :: \"event \\<Rightarrow> TS\" where \"time_stamp e \\<equiv> fst e\"\ndefinition tid :: \"event \\<Rightarrow> T\" where \"tid e \\<equiv> fst (snd e)\"\ndefinition act :: \"event \\<Rightarrow> action\" where \"act e \\<equiv> snd (snd e)\"\n\ndefinition var :: \"L \\<times> TS \\<Rightarrow> L\" where \"var = fst\"\ndefinition tst :: \"L \\<times> TS \\<Rightarrow> TS\" where \"tst = snd\"\n\n\n\nrecord write_record =\n  val :: V\n  is_releasing :: bool\n\nrecord surrey_state =\n  writes :: \"(L \\<times> TS) set\"\n  thrView :: \"T \\<Rightarrow> L \\<Rightarrow> (L \\<times> TS)\"\n  modView :: \"(L \\<times> TS) \\<Rightarrow> L \\<Rightarrow> (L \\<times> TS)\"\n  mods :: \"(L \\<times> TS) \\<Rightarrow> write_record\"\n  covered :: \"(L \\<times> TS) set\"\n\ndefinition \"value \\<sigma> w \\<equiv>  val (mods \\<sigma> w)\"\ndefinition \"releasing \\<sigma> w \\<equiv>  is_releasing (mods \\<sigma> w)\"\n\ndefinition \"writes_on \\<sigma> x = {w . var w = x \\<and> w \\<in> writes \\<sigma>}\"\ndefinition \"visible_writes \\<sigma> t x \\<equiv> {w \\<in> writes_on \\<sigma> x . tst(thrView \\<sigma> t x) \\<le> tst w}\"\n\n\n\nlemma writes_on_var [simp]: \"w \\<in> writes_on \\<sigma> x \\<Longrightarrow> var w = x\"\n  by (simp add: writes_on_def)\n\nlemma visible_var [simp]: \"w \\<in> visible_writes \\<sigma> t x \\<Longrightarrow> var w = x\"\n  by (auto simp add: visible_writes_def)\n\nlemma visible_writes_in_writes: \"visible_writes \\<sigma> t x \\<subseteq> writes \\<sigma>\"\n  using visible_writes_def writes_on_def by fastforce\n\ndefinition \"valid_fresh_ts \\<sigma> w ts' \\<equiv> tst w < ts' \\<and> (\\<forall> w' \\<in> writes_on \\<sigma> (var w). tst w < tst w' \\<longrightarrow> ts' < tst w')\"\n\ndefinition \"ts_oride m m' x \\<equiv> if tst (m x) \\<le> tst (m' x) then m' x else m x\"\n\ndefinition rev_app :: \"'s \\<Rightarrow> ('s \\<Rightarrow> 't) \\<Rightarrow> 't\" (infixl \";;\" 150)\n  where\n  \"rev_app s f \\<equiv> f s\"\n\n\ndefinition \n  \"update_thrView t nv \\<sigma> \\<equiv> \\<sigma> \\<lparr> thrView := (thrView \\<sigma>)(t := nv)\\<rparr>\"\n\ndefinition \n  \"update_modView w nv \\<sigma> \\<equiv> \\<sigma> \\<lparr> modView := (modView \\<sigma>)(w := nv) \\<rparr>\"\n\ndefinition \n  \"update_mods w nwr \\<sigma> \\<equiv> \\<sigma> \\<lparr> mods := (mods \\<sigma>)(w := nwr)\\<rparr> \\<lparr>writes := writes \\<sigma> \\<union> {w}\\<rparr>\"\n\ndefinition \n  \"add_cv w \\<sigma> \\<equiv> \\<sigma> \\<lparr> covered := covered \\<sigma> \\<union> {w}\\<rparr>\"\n\ndefinition \"syncing \\<sigma> w b \\<equiv> releasing \\<sigma> w \\<and> b\"\n\nlemma [simp]: \"syncing \\<sigma> w False = False\"\n  by (simp add: syncing_def)\n\nlemma [simp]: \"syncing \\<sigma> w True = releasing \\<sigma> w\"\n  by (simp add: syncing_def)\n\ndefinition\n  \"read_trans t b w \\<sigma>  \\<equiv>\n       let new_thr_idx = (thrView \\<sigma> t)(var w := w) in\n       let new_thr_idx' = \n             if syncing \\<sigma> w b then ts_oride new_thr_idx (modView \\<sigma> w) else new_thr_idx in\n          \\<sigma> ;; update_thrView t new_thr_idx'\"\n\nlemma [simp]: \"\\<not> syncing \\<sigma> w b \\<Longrightarrow> thrView (read_trans t b w \\<sigma>) t = (thrView \\<sigma> t)(var w := w)\"\n  by (simp add: read_trans_def rev_app_def update_thrView_def)\n\nlemma syncing_thrView_read_trans [simp]: \"syncing \\<sigma> w b \\<Longrightarrow>\n                     thrView (read_trans t b w \\<sigma>) t = ts_oride ((thrView \\<sigma> t)(var w := w)) (modView \\<sigma> w)\"\n  by (simp add: read_trans_def rev_app_def update_thrView_def)\n\n\nlemma [simp]: \"t' \\<noteq> t \\<Longrightarrow> thrView (read_trans t b w \\<sigma>) t' = (thrView \\<sigma> t')\"\n  apply (simp add: read_trans_def rev_app_def update_thrView_def)\n  by (metis fun_upd_other surrey_state.select_convs(2) surrey_state.surjective surrey_state.update_convs(2))\n\nlemma [simp]: \"var w \\<noteq> x \\<Longrightarrow> b = False \\<Longrightarrow> thrView (read_trans t b w \\<sigma>) t x = thrView \\<sigma> t x\"\n  by (simp add: read_trans_def rev_app_def update_thrView_def Let_def ts_oride_def)\n\nlemma [simp]: \"modView (read_trans t b w \\<sigma>) = modView \\<sigma>\"\n  by(simp add: read_trans_def Let_def rev_app_def update_thrView_def)\n\nlemma [simp]: \"mods (read_trans t b w \\<sigma>) = mods \\<sigma>\"\n  by(simp add: read_trans_def Let_def rev_app_def update_thrView_def)\n                                                            \nlemma [simp]: \"covered (read_trans t b w \\<sigma>) = covered \\<sigma>\"\n  by(simp add: read_trans_def Let_def rev_app_def update_thrView_def)\n\nlemma [simp]: \"writes (read_trans t b w \\<sigma>) = writes \\<sigma>\"\n  by(simp add: read_trans_def Let_def rev_app_def update_thrView_def)\n\nlemma [simp]: \"writes_on (read_trans t b w \\<sigma>) x = writes_on \\<sigma> x\"\n  apply(unfold writes_on_def)\n  by(simp add: read_trans_def Let_def rev_app_def update_thrView_def)\n\n\nlemma [simp]: \"value (read_trans t False w \\<sigma>) x  = value \\<sigma> x\"\n  apply(unfold value_def)\n  by(simp add: read_trans_def Let_def rev_app_def update_thrView_def)\n\n\ndefinition\n  \"write_trans t b w v \\<sigma> ts' \\<equiv>\n          \\<sigma> ;; update_thrView t ((thrView \\<sigma> t)(var w := (var w, ts'))) \n            ;; update_modView (var w, ts') ((thrView \\<sigma> t)(var w := (var w, ts')))\n            ;; update_mods (var w, ts') \\<lparr> val = v, is_releasing = b\\<rparr>\"\n\n\nlemma [simp]: \"thrView (write_trans t b w v \\<sigma> ts') t = (thrView \\<sigma> t)(var w := (var w, ts'))\"\n  by (simp add: write_trans_def rev_app_def add_cv_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"t' \\<noteq> t \\<Longrightarrow> thrView (write_trans t b w v \\<sigma> ts') t' = (thrView \\<sigma> t')\"\n  by (simp add: write_trans_def rev_app_def add_cv_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"var w' = var w \\<Longrightarrow> tst w' = ts' \\<Longrightarrow> modView (write_trans t b w v \\<sigma> ts') w' = (thrView \\<sigma> t)(var w := (var w, ts'))\"\n  apply (simp add: write_trans_def rev_app_def add_cv_def update_thrView_def\n                   update_modView_def update_mods_def)\n  by (metis prod.collapse tst_def var_def)\n\nlemma [simp]: \"var w' \\<noteq> var w \\<Longrightarrow> modView (write_trans t b w v \\<sigma> ts') w' = modView \\<sigma> w'\"\n  by (auto simp add: write_trans_def rev_app_def add_cv_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"var w' \\<noteq> var w \\<Longrightarrow> modView (write_trans t b w v \\<sigma> ts') w' y = modView \\<sigma> w' y\"\n  by (auto simp add: write_trans_def rev_app_def add_cv_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"tst w' \\<noteq> ts' \\<Longrightarrow> modView (write_trans t b w v \\<sigma> ts') w' = modView \\<sigma> w'\"\n  by (auto simp add: write_trans_def rev_app_def add_cv_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"var w' = var w \\<Longrightarrow> tst w' = ts' \\<Longrightarrow> mods (write_trans t b w v \\<sigma> ts') w' = \\<lparr> val = v, is_releasing = b\\<rparr>\"\n  apply (simp add: write_trans_def rev_app_def add_cv_def update_thrView_def\n                   update_modView_def update_mods_def)\n  by (metis prod.collapse tst_def var_def)\n\nlemma [simp]: \"var w' \\<noteq> var w \\<Longrightarrow> mods (write_trans t b w v \\<sigma> ts') w' = mods \\<sigma> w'\"\n  by (auto simp add: write_trans_def rev_app_def add_cv_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"tst w' \\<noteq> ts' \\<Longrightarrow> mods (write_trans t b w v \\<sigma> ts') w' = mods \\<sigma> w'\"\n  by (auto simp add: write_trans_def rev_app_def add_cv_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"covered (write_trans t b w v \\<sigma> ts') = covered \\<sigma>\"\n  by (simp add: write_trans_def rev_app_def add_cv_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"writes (write_trans t b w v \\<sigma> ts') = writes \\<sigma> \\<union> {(var w, ts')}\"\n  by(simp add: Let_def rev_app_def\n                   write_trans_def add_cv_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"x = var w \\<Longrightarrow> writes_on (write_trans t b w v \\<sigma> ts') x = writes_on \\<sigma> x \\<union> {(var w, ts')}\"\n  apply(unfold writes_on_def)\n  apply(simp add: read_trans_def Let_def rev_app_def update_thrView_def)\n  using Collect_cong by auto\n\nlemma [simp]: \"y \\<noteq> var w \\<Longrightarrow> writes_on (write_trans t b w v \\<sigma> ts') y = writes_on \\<sigma> y\"\n  apply(unfold writes_on_def)\n  by(auto simp add: read_trans_def Let_def rev_app_def update_thrView_def)\n\nlemma [simp]: \"w \\<in> writes_on \\<sigma> y \\<Longrightarrow>  w \\<in> writes_on (write_trans t b w' v \\<sigma> ts') y\"\n  apply(unfold writes_on_def)\n  by simp\n\n\n\n\ndefinition \"update_trans t w v' \\<sigma> ts' \\<equiv> \n       let new_thr_idx = (thrView \\<sigma> t)(var w := (var w, ts')) in\n         let new_thr_idx' =\n             if releasing \\<sigma> w\n             then\n                 ts_oride new_thr_idx (modView \\<sigma> w) \n             else\n                 new_thr_idx \n             in\n                 \\<sigma> ;; update_thrView t new_thr_idx' \n                   ;; update_modView (var w, ts') new_thr_idx'\n                   ;; update_mods (var w, ts') \\<lparr> val = v', is_releasing = True\\<rparr>\n                   ;; add_cv w\"\n\n\nlemma [simp]: \"\\<not> releasing \\<sigma> w \\<Longrightarrow>\n                     thrView (update_trans  t w v' \\<sigma> ts') t = (thrView \\<sigma> t)(var w := (var w, ts'))\"\n  by (simp add: Let_def rev_app_def update_modView_def update_mods_def update_thrView_def update_trans_def add_cv_def)\n\nlemma [simp]: \" releasing \\<sigma> w \\<Longrightarrow> \n                  thrView (update_trans  t w v' \\<sigma> ts') t = ts_oride ((thrView \\<sigma> t)(var w := (var w, ts'))) (modView \\<sigma> w)\"\n  by (auto simp add: Let_def update_trans_def add_cv_def rev_app_def update_modView_def update_mods_def update_thrView_def)\n\nlemma [simp]: \"t' \\<noteq> t \\<Longrightarrow> thrView (update_trans  t w v' \\<sigma> ts') t' = (thrView \\<sigma> t')\"\n  by (simp add: Let_def update_trans_def add_cv_def rev_app_def update_modView_def update_mods_def update_thrView_def)\n\n\nlemma [simp]: \"var w' = var w \\<Longrightarrow> tst w' = ts' \\<Longrightarrow>\n             \\<not> releasing \\<sigma> w \\<Longrightarrow> modView (update_trans t w v' \\<sigma> ts') w' = (thrView \\<sigma> t)(var w := (var w, ts'))\"\n  apply (simp add: Let_def update_trans_def rev_app_def add_cv_def update_thrView_def\n                   update_modView_def update_mods_def)\n  by (metis prod.collapse tst_def var_def)\n\nlemma [simp]: \"var w' = var w \\<Longrightarrow> tst w' = ts' \\<Longrightarrow>\n             releasing \\<sigma> w \\<Longrightarrow> modView (update_trans t w v' \\<sigma> ts') w' = ts_oride ((thrView \\<sigma> t)(var w := (var w, ts'))) (modView \\<sigma> w)\"\n  apply (simp add: Let_def update_trans_def rev_app_def add_cv_def update_thrView_def\n                   update_modView_def update_mods_def)\n  by (metis prod.collapse tst_def var_def)\n\nlemma [simp]: \"var w' \\<noteq> var w \\<Longrightarrow> modView (update_trans t w v' \\<sigma> ts') w' = modView \\<sigma> w'\"\n  by (auto simp add: Let_def fun_upd_idem_iff fun_upd_twist rev_app_def update_modView_def update_mods_def update_thrView_def update_trans_def add_cv_def)\n  \nlemma [simp]: \"tst w' \\<noteq> ts' \\<Longrightarrow> modView (update_trans t w v' \\<sigma> ts') w' = modView \\<sigma> w'\"\n  by (auto simp add: Let_def update_trans_def rev_app_def add_cv_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"var w' \\<noteq> var w \\<Longrightarrow> mods (update_trans t w v' \\<sigma> ts') w' = mods \\<sigma> w'\"\n  by (auto simp add: Let_def update_trans_def rev_app_def add_cv_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"tst w' \\<noteq> ts' \\<Longrightarrow> mods (update_trans t w v' \\<sigma> ts') w' = mods \\<sigma> w'\"\n  by (auto simp add: Let_def update_trans_def rev_app_def add_cv_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"var w' = var w \\<Longrightarrow> tst w' = ts' \\<Longrightarrow>\n             mods (update_trans t w v' \\<sigma> ts') w' = \\<lparr> val = v', is_releasing = True\\<rparr>\"\n  apply (simp add: Let_def update_trans_def rev_app_def add_cv_def update_thrView_def\n                   update_modView_def update_mods_def)\n  by (metis prod.collapse tst_def var_def)\n\nlemma [simp]: \"covered (update_trans t w v' \\<sigma> ts')  = covered \\<sigma> \\<union> {w}\"\n  by (simp add: Let_def update_trans_def rev_app_def add_cv_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"writes (update_trans t w v' \\<sigma> ts') = writes \\<sigma> \\<union> {(var w, ts')}\"\n by (auto simp add: Let_def update_trans_def rev_app_def add_cv_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"x = var w \\<Longrightarrow> writes_on (update_trans t w v' \\<sigma> ts') x = writes_on \\<sigma> x \\<union> {(x, ts')}\"\n  apply(unfold writes_on_def)\n  apply(simp add: read_trans_def Let_def rev_app_def update_thrView_def)\n  using Collect_cong by auto\n\nlemma [simp]: \"y \\<noteq> var w \\<Longrightarrow> writes_on (update_trans t w v' \\<sigma> ts') y = writes_on \\<sigma> y\"\n  apply(unfold writes_on_def)\n  by(auto simp add: read_trans_def Let_def rev_app_def update_thrView_def)\n\n\ndefinition step :: \"T \\<Rightarrow> action \\<Rightarrow> surrey_state \\<Rightarrow> surrey_state \\<Rightarrow> bool\"\n  where\n    \"step t a \\<sigma> \\<sigma>'\\<equiv>\n       \\<exists> w. w \\<in> visible_writes \\<sigma> t (avar a) \\<and>\n       (case a of\n         Read b x v \\<Rightarrow>\n           v = value \\<sigma> w \\<and>\n           \\<sigma>' = read_trans t b w \\<sigma>\n       | Write b x v \\<Rightarrow> \\<exists> ts'.\n           w \\<notin> covered \\<sigma> \\<and>\n           valid_fresh_ts \\<sigma> w ts' \\<and>\n           \\<sigma>' = write_trans t b w v \\<sigma> ts'\n       | Update x v v' \\<Rightarrow> \\<exists> ts'.\n           v = value \\<sigma> w \\<and> \n           w \\<notin> covered \\<sigma> \\<and>\n           valid_fresh_ts \\<sigma> w ts' \\<and>\n           \\<sigma>' = update_trans t w v' \\<sigma> ts')\n           \"\n\nlemma step_cases:\n       \"step t a \\<sigma> \\<sigma>'\n          \\<Longrightarrow> \n        \\<lbrakk>\\<And> w b x v. \\<sigma>' = read_trans t b w \\<sigma> \\<and> a = Read b x v \\<and> w \\<in> visible_writes \\<sigma> t (avar a) \\<and>\n          v = value \\<sigma> w \\<Longrightarrow> P \\<sigma> (read_trans t b w \\<sigma>)\\<rbrakk>\n         \\<Longrightarrow>\n       \\<lbrakk>\\<And> w b x v ts'. \\<sigma>' = write_trans t b w v \\<sigma> ts' \\<and> a = Write b x v \\<and> w \\<in> visible_writes \\<sigma> t (avar a) \\<and>\n           w \\<notin> covered \\<sigma> \\<and>\n           valid_fresh_ts \\<sigma> w ts'\n           \\<Longrightarrow> P \\<sigma> (write_trans t b w v \\<sigma> ts') \\<rbrakk>\n         \\<Longrightarrow>\n       \\<lbrakk>\\<And> w x v v' ts'. \\<sigma>' = update_trans t w v' \\<sigma> ts' \\<and> a = Update x v v' \\<and>\n           w \\<in> visible_writes \\<sigma> t (avar a) \\<and>\n           v = value \\<sigma> w \\<and>\n           w \\<notin> covered \\<sigma> \\<and>\n           valid_fresh_ts \\<sigma> w ts'\n           \\<Longrightarrow> P \\<sigma> (update_trans t w v' \\<sigma> ts')\\<rbrakk>\n  \\<Longrightarrow> P \\<sigma> \\<sigma>'\"\n  apply(simp add: step_def) apply(case_tac a) by auto\n\n\n\ndefinition \"WrX x v \\<equiv> Write False x v\"\ndefinition \"WrR x v \\<equiv> Write True x v\"\ndefinition \"RdX x v \\<equiv> Read False x v\"\ndefinition \"RdA x v \\<equiv> Read True x v\"\n\n\n\nabbreviation WrX_state_abbr:: \" surrey_state \\<Rightarrow> L \\<Rightarrow> V \\<Rightarrow> T \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"_ [_ := _]\\<^sub>_ _\" [100,100,100,100,100])\n  where \"\\<sigma> [x := v]\\<^sub>t \\<sigma>' \\<equiv> step t (WrX x v) \\<sigma> \\<sigma>'\"\n\nabbreviation WrR_state_abbr:: \" surrey_state \\<Rightarrow> L \\<Rightarrow> V \\<Rightarrow> T \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"_ [_ :=\\<^sup>R _]\\<^sub>_ _\" [100,100,100,100,100])\n  where \"\\<sigma> [x :=\\<^sup>R v]\\<^sub>t \\<sigma>' \\<equiv> step t (WrR x v) \\<sigma> \\<sigma>'\"\n\nabbreviation RdX_state_abbr:: \" surrey_state \\<Rightarrow> V \\<Rightarrow> L \\<Rightarrow> T \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"_ [_ \\<leftarrow> _]\\<^sub>_ _\" [100,100,100,100,100])\n  where \"\\<sigma> [r \\<leftarrow> x]\\<^sub>t \\<sigma>' \\<equiv> step t (RdX x r) \\<sigma> \\<sigma>'\"\n\nabbreviation RdA_state_abbr:: \" surrey_state \\<Rightarrow> V \\<Rightarrow> L \\<Rightarrow> T \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"_ [_ \\<leftarrow>\\<^sup>A _]\\<^sub>_ _\" [100,100,100,100,100])\n  where \"\\<sigma> [r \\<leftarrow>\\<^sup>A x]\\<^sub>t \\<sigma>' \\<equiv> step t (RdA x r) \\<sigma> \\<sigma>'\"\n\nabbreviation Up_state_abbr:: \" surrey_state \\<Rightarrow> L \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> T \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"_ RMW[_, _, _]\\<^sub>_ _\" [100,100,100,100,100,100])\n  where \"\\<sigma> RMW[x, u, v]\\<^sub>t \\<sigma>' \\<equiv> step t (Update x u v) \\<sigma> \\<sigma>'\"\n\nabbreviation Swap_state_abbr:: \" surrey_state \\<Rightarrow> L \\<Rightarrow> V \\<Rightarrow> T \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"_ SWAP[_, _]\\<^sub>_ _\" [100,100,100,100,100])\n  where \"\\<sigma> SWAP[x, v]\\<^sub>t \\<sigma>' \\<equiv> \\<exists>u . step t (Update x u v) \\<sigma> \\<sigma>'\"\n\n\ndefinition \"initial_state \\<sigma> I \\<equiv>\n                 \\<exists> F . writes \\<sigma> = {(x, F x) | x. True} \\<and>\n                       (\\<forall> t x. thrView \\<sigma> t x = (x, F x)) \\<and>\n                       (\\<forall> w x. modView \\<sigma> w x = (x, F x)) \\<and>\n                       (\\<forall> w. mods \\<sigma> w = \\<lparr> val = I (var w), is_releasing = False \\<rparr>) \\<and>\n                       covered \\<sigma> = {}\"\n\ndefinition\n  \"wfs \\<sigma> \\<equiv>\n      (\\<forall> t x. thrView \\<sigma> t x \\<in> writes_on \\<sigma> x) \\<and>\n      (\\<forall> w x. modView \\<sigma> w x \\<in> writes_on \\<sigma> x) \\<and>\n      (\\<forall> x. finite(writes_on \\<sigma> x)) \\<and>\n      (\\<forall> w. w \\<in> writes \\<sigma> \\<longrightarrow> modView \\<sigma> w (var w) = w) \\<and>\n      covered \\<sigma> \\<subseteq> writes \\<sigma>\"\n\nlemma initially_write_unique: \"initial_state \\<sigma> I \\<Longrightarrow> w \\<in> writes_on \\<sigma> x \\<Longrightarrow> w' \\<in> writes_on \\<sigma> x \\<Longrightarrow> w = w'\"\n  apply(unfold initial_state_def writes_on_def) by auto\n\nlemma initial_wfs: assumes \"initial_state \\<sigma> I\"  shows \"wfs \\<sigma>\"\n  apply(simp add: initial_state_def wfs_def)\n  apply(rule conjI)\n  using assms writes_on_def  apply (smt CollectI fst_conv initial_state_def var_def)\n  apply(rule conjI)\n  using assms writes_on_def initial_state_def apply simp\n  apply (smt CollectI fst_conv initial_state_def var_def writes_on_def)\n  apply rule using initially_write_unique[OF assms(1)] \n  apply (smt CollectI Collect_cong finite.emptyI finite.insertI insert_compr not_finite_existsD singletonD writes_on_def)\n    apply(rule conjI)\n  apply (smt CollectD Pair_inject assms initial_state_def)\n  using assms initial_state_def by fastforce\n\nlemma allI_case: \"\\<lbrakk>\\<And> y. x \\<noteq> y \\<Longrightarrow> P y\\<rbrakk> \\<Longrightarrow> \\<lbrakk>P x\\<rbrakk> \\<Longrightarrow> \\<forall> y. P y\" by fastforce\n\n\nlemma [simp]: \"wfs \\<sigma> \\<Longrightarrow> writes_on \\<sigma> x \\<noteq> {}\"\n  apply(simp add: wfs_def)\n  by (metis empty_iff)\n\nlemma [simp]: \"wfs \\<sigma> \\<Longrightarrow> finite(writes_on \\<sigma> x)\"\n  by(simp add: wfs_def)\n\nlemma [simp]: \"wfs \\<sigma> \\<Longrightarrow> thrView \\<sigma> t x \\<in> writes_on \\<sigma> x\"\n  by(simp add: wfs_def)\n\nlemma [simp]: \"wfs \\<sigma> \\<Longrightarrow> modView \\<sigma> w x \\<in> writes_on \\<sigma> x\"\n  using wfs_def by blast\n\n\nlemma [simp]: \"wfs \\<sigma> \\<Longrightarrow> modView (read_trans t b w \\<sigma>) w x \\<in> writes_on (read_trans t b w \\<sigma>) x\"\n  by auto\n\nlemma [simp]: \"wfs \\<sigma> \\<Longrightarrow> writes_on \\<sigma> x =  writes_on (read_trans t b w \\<sigma>) x\"\n  by auto\n\n\nlemma own_ModView:\n  assumes \"wfs \\<sigma>\"\n      and \"w \\<in> writes \\<sigma>\"\n    shows \"modView \\<sigma> w (var w) = w\"\n  using assms apply(unfold wfs_def)\n  by blast\n\nlemma ts_oride_same_var:\n  assumes \"wfs \\<sigma>\"\n      and \"x = var w\"\n      and \"w \\<in> visible_writes \\<sigma> t (var w)\"\n    shows \"ts_oride ((thrView \\<sigma> t)(var w := w)) (modView \\<sigma> w) x = w\"\n  apply(simp add: ts_oride_def) apply safe using assms\n  apply (meson own_ModView subsetCE visible_writes_in_writes)\n  using assms(2) apply blast \n  using assms(2) by blast\n\nlemma ts_oride_diff_var:\n  assumes \"wfs \\<sigma>\"\n      and \"x \\<noteq> var w\"\n      and \"w \\<in> visible_writes \\<sigma> t (var w)\"\n    shows \"ts_oride ((thrView \\<sigma> t)(var w := w')) (modView \\<sigma> w) x = ts_oride (thrView \\<sigma> t) (modView \\<sigma> w) x\"\n  apply(simp add: ts_oride_def)\n  using assms(2) by blast\n\nlemma ts_oride_split:\n  assumes \"tst (m' x) \\<le> tst (m x) \\<Longrightarrow> P (m x)\"\n      and \"tst (m x) \\<le> tst (m' x) \\<Longrightarrow> P (m' x)\"\n    shows \"P (ts_oride m m' x)\"\n  apply(simp add: ts_oride_def)\n  by (simp add: assms(1) assms(2))\n\n\nlemma wfs_covered_preserved:\n  assumes \"covered \\<sigma> \\<subseteq> writes \\<sigma>\"\n      and \"step t a \\<sigma> \\<sigma>'\"\n    shows \"covered \\<sigma>' \\<subseteq> writes \\<sigma>'\"\n     apply (rule step_cases[OF assms(2)]) apply simp_all\n  using assms(1) apply blast\n  apply (simp add: assms(1) subset_insertI2)\n  using assms(1) visible_writes_in_writes by fastforce\n\nlemma wfs_preserved:\n  assumes \"wfs \\<sigma>\"\n      and \"step t a \\<sigma> \\<sigma>'\"\n    shows \"wfs \\<sigma>'\"\n  apply(unfold wfs_def)\n  apply rule defer apply rule defer apply rule defer defer\n    apply clarsimp defer\n    apply clarsimp\n     apply (rule step_cases[OF assms(2)]) apply simp_all\n  using assms(1) wfs_def apply auto[1]\n  apply(case_tac \"var w = aa\")\n       apply(case_tac \"(aa, b) = (x, ts')\") apply simp\n  apply simp \n       apply(case_tac \"b = ts'\") apply simp using assms(1) wfs_def apply blast\n   apply simp apply(case_tac \"var w = x\") apply simp\n  using assms(1) wfs_def apply blast  apply simp\n  using assms(1) wfs_def apply blast\n   apply simp apply(case_tac \"var w = x\") apply simp \n  using assms(1) wfs_def apply blast apply simp\n  using assms(1) wfs_def apply blast\n     apply(case_tac \"var w = aa\")\n  apply(case_tac \"releasing \\<sigma> w\")\n      apply(case_tac \"(aa, b) = (x, ts')\")\n        apply simp apply (metis assms(1) fun_upd_same ts_oride_def wfs_def)\n       apply(case_tac \"b = ts'\") apply(case_tac \"var w = x\") apply simp\n        apply simp apply(rule ts_oride_split) using assms(1) apply simp\n          using assms(1) apply simp\n          apply(case_tac \"var w = x\") apply simp using assms(1) wfs_def apply blast\n               apply simp using assms(1) wfs_def apply blast\n              apply(case_tac \"(aa, b) = (x, ts')\") apply simp\n          apply simp apply(case_tac \"var w = x\") apply simp using assms(1) wfs_def apply blast\n          apply(case_tac \"b = ts'\")apply simp using assms(1) wfs_def apply blast\n         apply simp using assms(1) wfs_def apply blast\n          apply(case_tac \"var w = x\") apply simp using assms(1) wfs_def apply blast\n             apply simp using assms(1) wfs_def apply blast\n          apply clarsimp apply (rule step_cases[OF assms(2)]) apply simp_all\n          using assms(1) wfs_def apply blast\n             apply(case_tac \"var w = x\") apply simp using assms(1) wfs_def apply blast\n             apply simp using assms(1) wfs_def apply blast\n             apply(case_tac \"var w = x\") apply simp using assms(1) wfs_def apply blast\n            apply simp using assms(1) wfs_def apply blast\n          apply (rule conjI)\n           apply clarsimp  apply (rule step_cases[OF assms(2)]) apply simp_all\n          using assms(1) assms(2) own_ModView step_def apply fastforce\n            apply(case_tac \"var w = x\") apply(case_tac \"(aa, b) = (x, ts')\") apply(case_tac \"var w = aa\")\n               apply simp  apply blast\n          apply(case_tac \"b = ts'\") \n              apply simp using own_ModView[OF assms(1)] apply auto[1]\n             apply simp using own_ModView[OF assms(1)] apply auto[1]\n          using visible_var apply fastforce\n           apply(case_tac \"var w = x\") apply(case_tac \"(aa, b) = (x, ts')\") apply(case_tac \"var w = aa\")\n              apply(case_tac \"releasing \\<sigma> w\")\n          using own_ModView[OF assms(1)] apply simp apply(rule ts_oride_split) \n          apply simp apply simp\n          using leD valid_fresh_ts_def visible_writes_in_writes apply fastforce\n          apply simp apply(case_tac \"releasing \\<sigma> w\") apply simp\n          apply blast apply simp \n          using own_ModView[OF assms(1)] apply auto[1]\n          using visible_var apply force\n          using wfs_covered_preserved assms(1) assms(2) wfs_def apply blast\n          apply (rule step_cases[OF assms(2)])\n            apply(case_tac \"ta = t\") apply(case_tac \"syncing \\<sigma> w b\")\n               apply simp apply(rule ts_oride_split) \n          apply (metis assms(1) fun_upd_apply subsetCE visible_writes_in_writes wfs_def)\n  using assms(1) wfs_def apply blast apply simp \n     apply (metis assms(1) subsetCE visible_writes_in_writes wfs_def)\n    apply simp using assms(1) wfs_def apply blast\n            apply(case_tac \"ta = t\") apply simp\n  using assms(1) wfs_def apply blast\n  apply simp apply(case_tac \"var w = x\") apply simp\n  using assms(1) wfs_def apply blast\n   apply simp using assms(1) wfs_def apply blast\n  apply(case_tac \"ta = t\") apply simp apply(case_tac \"releasing \\<sigma> w\") apply simp\n  apply(case_tac \"var w = x\") apply simp \n     apply (metis assms(1) fun_upd_same ts_oride_def wfs_def)\n  apply simp apply(rule ts_oride_split)\n  using assms(1) apply auto[1] \n  using assms(1) wfs_def apply blast\n  apply simp  \n  using assms(1) wfs_def apply blast\n  apply simp apply(case_tac \"var w = x\") apply simp\n  using assms(1) wfs_def apply blast apply simp\n  using assms(1) wfs_def by blast\n\ndefinition \"lastWr \\<sigma> x \\<equiv> (x, Max (tst`(writes_on \\<sigma> x)))\"\n\n\n\nlemma [simp]: \"var(lastWr \\<sigma> x) = x\" by(simp add: lastWr_def)\n\nlemma last_write_max: \"wfs \\<sigma> \\<Longrightarrow> w \\<in> writes_on \\<sigma> x \\<Longrightarrow> tst w \\<le> tst (lastWr \\<sigma> x)\"\n  by(simp add: lastWr_def)\n\nlemma last_write_write_on [simp]: \"wfs \\<sigma> \\<Longrightarrow>  lastWr \\<sigma> x \\<in> writes_on \\<sigma> x\"\n  apply(simp add: lastWr_def )\n  apply(case_tac \"Max (tst`(writes_on \\<sigma> x)) \\<in> tst`(writes_on \\<sigma> x)\")\n  defer apply simp\n  by (auto simp add: tst_def var_def writes_on_def)\n\nlemma lastWr_visible:\n    \"wfs \\<sigma> \\<Longrightarrow> lastWr \\<sigma> x \\<in> visible_writes \\<sigma> t x\"\n  by (metis (no_types, lifting) CollectI last_write_max last_write_write_on visible_writes_def wfs_def)\n\nlemma lastWr_read_pres: \"lastWr (read_trans t b w \\<sigma>) x = lastWr \\<sigma> x\"\n  by(simp add: lastWr_def)\n\nlemma write_to_different_var [simp]: \"wfs \\<sigma> \\<Longrightarrow> var w \\<noteq> x \\<Longrightarrow> lastWr (write_trans t b w v \\<sigma> ts') x = lastWr \\<sigma> x\"\n  by(simp add: lastWr_def)\n\nlemma [simp]: \"wfs \\<sigma> \\<Longrightarrow> w = (lastWr \\<sigma> x) \\<Longrightarrow> valid_fresh_ts \\<sigma> w ts' \\<Longrightarrow>\n                    lastWr (write_trans t b w v \\<sigma> ts') x = (x, ts')\"\n  apply (simp add: valid_fresh_ts_def)\n  by (simp add: lastWr_def max.strict_order_iff)\n\nlemma [simp]: \"wfs \\<sigma> \\<Longrightarrow> w \\<noteq> lastWr \\<sigma> x \\<Longrightarrow> w \\<in> writes_on \\<sigma> x \\<Longrightarrow> valid_fresh_ts \\<sigma> w ts' \\<Longrightarrow>\n                    lastWr (write_trans t b w v \\<sigma> ts') x = lastWr \\<sigma> x\"\n  apply (subst lastWr_def) apply(case_tac \"var w = x\") apply simp_all defer\n   apply (simp add: lastWr_def)\n apply (simp add: valid_fresh_ts_def)\n  by (metis dual_order.order_iff_strict lastWr_def last_write_max last_write_write_on max.absorb2 prod.exhaust_sel sndI tst_def var_def writes_on_var)\n\nlemma [simp]: \" wfs \\<sigma> \\<Longrightarrow> var w \\<noteq> x \\<Longrightarrow> value (write_trans t b w v \\<sigma> ts')(lastWr \\<sigma> x) = value \\<sigma> (lastWr \\<sigma> x)\"\n by(simp add: value_def)\n  \n\nlemma [simp]: \"wfs \\<sigma> \\<Longrightarrow> w = lastWr \\<sigma> x \\<Longrightarrow> valid_fresh_ts \\<sigma> w ts' \\<Longrightarrow>lastWr (update_trans t w v' \\<sigma> ts') x = (x, ts')\"\n  apply (subst lastWr_def) apply simp\n  by (simp add: lastWr_def less_eq_rat_def max.absorb1 valid_fresh_ts_def)\n\nlemma [simp]: \"wfs \\<sigma> \\<Longrightarrow> w \\<noteq> lastWr \\<sigma> x \\<Longrightarrow> w \\<in> writes_on \\<sigma> x \\<Longrightarrow> valid_fresh_ts \\<sigma> w ts' \\<Longrightarrow>\n                    lastWr (update_trans t w v' \\<sigma> ts') x = lastWr \\<sigma> x\"\n  apply (subst lastWr_def) apply(case_tac \"var w = x\") apply simp_all\n  by (metis lastWr_def last_write_max last_write_write_on less_eq_rat_def max_def prod.collapse snd_conv tst_def valid_fresh_ts_def var_def writes_on_var)\n\nlemma modView_lte_last: \"wfs \\<sigma> \\<Longrightarrow> tst(modView \\<sigma> w x) \\<le> tst(lastWr \\<sigma> x)\"\n  using last_write_max wfs_def by blast\n\n  \n\n\ndefinition \"p_obs \\<sigma> t x u \\<equiv> \\<exists> w. w \\<in> visible_writes \\<sigma> t x \\<and> u = value \\<sigma> w\" \n\ndefinition \"d_obs \\<sigma> view x u \\<equiv> view x = lastWr \\<sigma> x \\<and> value \\<sigma> (lastWr \\<sigma> x) = u\"\n\ndefinition \"d_obs_t \\<sigma> t x u \\<equiv> d_obs \\<sigma> (thrView \\<sigma> t) x u\"\n\ndefinition \"c_obs \\<sigma> x u t y v \\<equiv> \n              \\<forall> w \\<in> visible_writes \\<sigma> t x. value \\<sigma> w = u \\<longrightarrow>\n                         d_obs \\<sigma> (modView \\<sigma> w) y v \\<and>\n                         releasing \\<sigma> w\"\n\nlemma c_obs_intro:\n  assumes \"\\<And> w. \\<lbrakk>w \\<in> writes \\<sigma> ; var w = x ; tst(thrView \\<sigma> t x) \\<le> tst w; value \\<sigma> w = u\\<rbrakk> \\<Longrightarrow> releasing \\<sigma> w\"\n      and \"\\<And> w. \\<lbrakk>w \\<in> writes \\<sigma> ; var w = x ; tst(thrView \\<sigma> t x) \\<le> tst w; value \\<sigma> w = u\\<rbrakk> \\<Longrightarrow> modView \\<sigma> w y = lastWr \\<sigma> y\"\n      and \"\\<And> w. \\<lbrakk>w \\<in> writes \\<sigma> ; var w = x ; tst(thrView \\<sigma> t x) \\<le> tst w; value \\<sigma> w = u\\<rbrakk> \\<Longrightarrow> value \\<sigma> (lastWr \\<sigma> y) = v\"\n  shows \"c_obs \\<sigma> x u t y v\"\n  apply(simp add: c_obs_def d_obs_def)\n  using assms apply(simp add: visible_writes_def)\n  by (metis (mono_tags, lifting) CollectD prod.sel(2) tst_def writes_on_def)  \n\nabbreviation p_obs_abbr:: \"nat  \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow>  surrey_state \\<Rightarrow> bool\" (\"[_ \\<approx>\\<^sub>_ _] _\" [100, 100, 100, 100])\n  where \"[x \\<approx>\\<^sub>t u] \\<sigma> \\<equiv> p_obs \\<sigma> t x u\"\n\nabbreviation d_obs_abbr:: \"nat  \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"[_ =\\<^sub>_ _] _\" [100, 100, 100, 100])\n  where \"[x =\\<^sub>t u] \\<sigma> \\<equiv> d_obs_t \\<sigma> t x u\"\n\nabbreviation c_obs_abbr:: \"nat \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"[_ = _]\\<^sub>_\\<lparr>_ = _ \\<rparr> _\" [100, 100, 100, 100, 100, 100])\n  where \"[x = u]\\<^sub>t\\<lparr>y = v\\<rparr> \\<sigma> \\<equiv> c_obs \\<sigma> x u t y v\"\n\n\n\nlemma d_obs_lastWr_visible: \n  \"wfs \\<sigma> \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma> \\<Longrightarrow> w \\<in> visible_writes \\<sigma> t x \\<Longrightarrow> w = lastWr \\<sigma> x\"\n  apply (simp add: tst_def d_obs_def d_obs_t_def lastWr_def var_def visible_writes_def, auto)\n  by (metis dual_order.antisym lastWr_def last_write_max last_write_write_on prod.collapse tst_def var_def writes_on_var)\n\n\n\nlemma d_obs_implies_p_obs: \n  \"wfs \\<sigma> \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma> \\<Longrightarrow> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  apply(simp add: d_obs_t_def d_obs_def p_obs_def) using lastWr_visible\n  by (metis lastWr_def)\n\n\nlemma d_obs_p_obs_agree: \"wfs \\<sigma> \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma> \\<Longrightarrow> [x \\<approx>\\<^sub>t v] \\<sigma> \\<Longrightarrow> u = v\"\n  apply(unfold p_obs_def d_obs_t_def d_obs_def visible_writes_def)apply clarsimp\n  by (metis eq_snd_iff fst_conv lastWr_def last_write_max leD order.not_eq_order_implies_strict tst_def var_def writes_on_var)\n\nlemma not_p_obs_implies_c_obs: \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma> \\<Longrightarrow> [x = u]\\<^sub>t\\<lparr>y = v\\<rparr> \\<sigma>\"\n  by(auto simp add: p_obs_def c_obs_def)\n\nlemma d_obs_same_val:  \"[x =\\<^sub>t u] \\<sigma> \\<Longrightarrow>  [x =\\<^sub>t v] \\<sigma> \\<Longrightarrow> v = u\"\n  by (simp add: d_obs_def d_obs_t_def)\n\nlemmas update_simps = \n  valid_fresh_ts_def visible_writes_def \n  update_trans_def update_thrView_def update_modView_def \n  rev_app_def Let_def add_cv_def update_mods_def\n\n\n\n\n\n(*********** Transition Inference Rules Follow ****************)\n\nlemma d_obs_Wr_set :  \\<comment> \\<open>Rule: DV-set\\<close>\n  assumes \"wfs \\<sigma>\"\n      and \"wr_val a = Some v\"\n      and \"avar a = x\"\n      and \"d_obs_t \\<sigma> t x u\"\n      and \"step t a \\<sigma> \\<sigma>'\"\n    shows \"d_obs_t \\<sigma>' t x v\"\n  apply(rule step_cases[OF assms(5)])\n  using assms(2) apply simp\n   apply(unfold d_obs_t_def d_obs_def) apply simp apply clarsimp\n   apply(case_tac \"xa = x\")\n    using assms(1) apply simp apply(drule d_obs_lastWr_visible[OF assms(1) assms(4)])\n      apply simp using assms(2) apply simp apply(unfold value_def) \n    using assms(3) visible_var apply(case_tac \"x = aa\") apply simp apply (simp add: lastWr_def) \n    apply clarsimp apply(case_tac \"xa = x\") \n    using assms(1) apply simp  using assms(3) apply auto[1]\n    using assms(1) apply clarsimp apply(case_tac \"xa = x\") apply simp\n      apply(drule d_obs_lastWr_visible[OF assms(1) assms(4)])\n    using assms(2) apply simp apply(case_tac \"releasing \\<sigma> (lastWr \\<sigma> x)\")\n      apply (simp add: ts_oride_def)using modView_lte_last[OF assms(1)]\n      apply (simp add: valid_fresh_ts_def)\n      apply (metis dual_order.antisym less_eq_rat_def less_irrefl order_trans)\n    apply simp\n    using assms(3) visible_var by force\n\ncorollary d_obs_WrX_set :  \n  \"wfs \\<sigma> \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma> \\<Longrightarrow> \\<sigma> [x := v]\\<^sub>t \\<sigma>' \\<Longrightarrow> [x =\\<^sub>t v] \\<sigma>' \"\n  by (metis WrX_def avar.simps(2) d_obs_Wr_set wr_val.simps(1))\n\ncorollary d_obs_WrR_set :  \n  \"wfs \\<sigma> \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma> \\<Longrightarrow> \\<sigma> [x :=\\<^sup>R v]\\<^sub>t \\<sigma>' \\<Longrightarrow> [x =\\<^sub>t v] \\<sigma>' \"\n  by (metis WrR_def avar.simps(2) d_obs_Wr_set wr_val.simps(1))\n\ncorollary d_obs_RMW_set :  \n  \"wfs \\<sigma> \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma> \\<Longrightarrow> \\<sigma> RMW[x,w,v]\\<^sub>t \\<sigma>' \\<Longrightarrow> [x =\\<^sub>t v] \\<sigma>' \"\n  using avar.simps(3) d_obs_Wr_set wr_val.simps(2) by blast\n\n\n\nlemma d_obs_Rd_pres:\n  assumes a1: \"wfs \\<sigma>\"\n      and a2: \"isRd a\"\n      and a4: \"d_obs_t \\<sigma> t x u\"\n      and a5: \"step t a \\<sigma> \\<sigma>'\" \n    shows \"d_obs_t \\<sigma>' t x u\"\n  apply(rule step_cases[OF a5])\n    apply (case_tac \"avar a = x\") apply simp\n   apply (unfold  d_obs_t_def d_obs_def)\n     defer\n  defer\n  using a2 isRd.simps(2) apply blast\n  using a2 isRd.simps(3) apply blast\n  apply (unfold read_trans_def Let_def)\n  apply (case_tac \"b = False\")\n   apply (simp add: d_obs_def d_obs_lastWr_visible d_obs_t_def rev_app_def syncing_def update_thrView_def)\n  using  a1 a4 \n   apply (smt d_obs_def d_obs_lastWr_visible d_obs_t_def fun_upd_triv lastWr_def prod.collapse prod.inject surrey_state.surjective surrey_state.update_convs(2) var_def)\n  using a1 a4 apply (simp add: d_obs_def  d_obs_t_def  lastWr_def  rev_app_def ts_oride_def tst_def update_thrView_def value_def var_def wfs_def writes_on_def)\n  apply clarsimp\n  apply (metis a1 a4 d_obs_lastWr_visible fst_conv lastWr_def snd_conv tst_def var_def visible_var writes_on_def)\n  using assms apply (simp add: d_obs_def  d_obs_t_def  lastWr_def  rev_app_def ts_oride_def tst_def update_thrView_def value_def var_def wfs_def writes_on_def)\n  apply (intro conjI impI)\n  apply (unfold visible_writes_def writes_on_def var_def, simp_all)\n  apply (metis (no_types, lifting) a1 a4 d_obs_def d_obs_t_def dual_order.antisym modView_lte_last old.prod.inject prod.collapse tst_def)\n  by auto\n\ncorollary d_obs_RdX_pres:  \n  \"wfs \\<sigma> \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma> \\<Longrightarrow> \\<sigma> [v \\<leftarrow> x]\\<^sub>t \\<sigma>' \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma>' \"\n  using RdX_def d_obs_Rd_pres by force\n\ncorollary d_obs_RdA_pres:  \n  \"wfs \\<sigma> \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma> \\<Longrightarrow> \\<sigma> [v \\<leftarrow>\\<^sup>A x]\\<^sub>t \\<sigma>' \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma>'\"\n  using RdA_def d_obs_Rd_pres by force\n\nlemma [simp]: \"var w \\<noteq> x \\<Longrightarrow> lastWr (update_trans t w v' \\<sigma> ts') x = lastWr \\<sigma> x\"\n  by(simp add: lastWr_def)\n\n \n\nlemma \"d_obs_other\": \\<comment> \\<open>Rule: DV-Other\\<close>\n  assumes \"wfs \\<sigma>\"\n      and \"avar a \\<noteq> x\"\n      and \"d_obs_t \\<sigma> t x u\"\n      and \"step t a \\<sigma> \\<sigma>'\" \n    shows \"d_obs_t \\<sigma>' t x u\"\n  apply(rule step_cases[OF assms(4)])\n  using assms(2, 3) apply simp\n  apply (unfold  d_obs_t_def d_obs_def)\n  apply (case_tac \"b = False\")\n  apply (simp add: lastWr_def read_trans_def rev_app_def syncing_def update_thrView_def value_def)\n     apply (unfold writes_on_def)\n   apply (metis (no_types, lifting) Collect_cong assms(2) surrey_state.select_convs(1) surrey_state.surjective surrey_state.update_convs(2) visible_var)\n   apply (unfold read_trans_def Let_def) \n   apply (simp add: lastWr_def  rev_app_def ts_oride_def tst_def update_thrView_def value_def var_def  wfs_def writes_on_def)\n   using assms(1,2,3)  apply (unfold tst_def d_obs_def d_obs_t_def wfs_def writes_on_def le_neq_trans modView_lte_last)\n   apply clarsimp\n   apply (metis (no_types, lifting) assms(1) dual_order.antisym fst_conv modView_lte_last prod.collapse snd_conv tst_def var_def visible_var)\n   using assms (2, 3) apply simp \n   apply (unfold d_obs_t_def d_obs_def)\n    apply (intro conjI) \n   using assms(2) apply (metis visible_var)\n   using visible_var \n    apply(case_tac \"b = False\")\n     apply clarsimp \n     apply(rule conjI)\n   using assms(1) \n      apply(unfold visible_writes_def)\n      apply clarsimp\n     apply simp\n    apply simp  \n   using assms (2,3)\n   apply simp \n   apply (simp add: d_obs_t_def d_obs_def)\n   apply clarsimp\n   apply (rule conjI)\n    apply (case_tac \"aa = x\")\n     apply (simp add: var_def writes_on_def)\n    apply simp\n    apply (case_tac \"releasing \\<sigma> (aa, b)\")\n     apply(simp add: ts_oride_def tst_def var_def)\n   apply (metis dual_order.antisym modView_lte_last prod.collapse tst_def)\n     apply(simp add: ts_oride_def tst_def var_def)\n    apply (case_tac \"aa = x\")\n     apply (simp add: var_def writes_on_def)\n   apply simp\n   by(simp add: value_def tst_def)\n\n\ncorollary d_obs_RdX_other: \n  \"wfs \\<sigma> \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma> \\<Longrightarrow> \\<sigma> [v \\<leftarrow> y]\\<^sub>t \\<sigma>' \\<Longrightarrow>[x =\\<^sub>t u] \\<sigma>'\"\n  by (metis RdX_def avar.simps(1) d_obs_other)\n\ncorollary d_obs_RdA_other: \n  \"wfs \\<sigma> \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma> \\<Longrightarrow> \\<sigma> [v \\<leftarrow>\\<^sup>A y]\\<^sub>t \\<sigma>' \\<Longrightarrow>[x =\\<^sub>t u] \\<sigma>'\"\n  by (metis RdA_def avar.simps(1) d_obs_other)\n\ncorollary d_obs_WrX_other: \n  \"wfs \\<sigma> \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma> \\<Longrightarrow> \\<sigma> [y := v]\\<^sub>t \\<sigma>' \\<Longrightarrow>[x =\\<^sub>t u] \\<sigma>'\"\n  by (metis WrX_def avar.simps(2) d_obs_other)\n\ncorollary d_obs_WrR_other:\n  \"wfs \\<sigma> \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma> \\<Longrightarrow> \\<sigma> [y :=\\<^sup>R v]\\<^sub>t \\<sigma>' \\<Longrightarrow>[x =\\<^sub>t u] \\<sigma>'\"\n  by (metis WrR_def avar.simps(2) d_obs_other)\n\ncorollary d_obs_RMW_other:\n  \"wfs \\<sigma> \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma> \\<Longrightarrow> \\<sigma> RMW[y, v, v']\\<^sub>t \\<sigma>' \\<Longrightarrow>[x =\\<^sub>t u] \\<sigma>'\"\n  using d_obs_other by force\n\n\n\n\nlemma p_obs_Rd_intro: \\<comment> \\<open>Rule: OB-Intro\\<close>\n  assumes \"wfs \\<sigma>\"\n      and \"isRd a\"\n  and \"rd_val a = Some v\"\n  and \"avar a = x\"\n  and \"step t a \\<sigma> \\<sigma>'\"\n  shows \"p_obs \\<sigma>' t x v\"\n  using assms\n  apply (simp add: p_obs_def step_def, auto)\n  apply (cases a, auto)\n   apply (simp add: read_trans_def rev_app_def)\n  apply (unfold value_def rev_app_def valid_fresh_ts_def read_trans_def visible_writes_def wfs_def p_obs_def step_def, auto)\n   apply (unfold writes_on_def tst_def update_thrView_def, safe)\n  apply (case_tac \"syncing \\<sigma> (x, ba) x11\", clarsimp)\n  apply (metis (no_types, lifting) eq_refl fun_upd_same sndI ts_oride_def)\n  apply clarsimp\n  by auto[1]\n\ncorollary p_obs_RdX_intro:\n  \"wfs \\<sigma> \\<Longrightarrow> \\<sigma> [v \\<leftarrow> x]\\<^sub>t \\<sigma>' \\<Longrightarrow> [x \\<approx>\\<^sub>t v] \\<sigma>'\"\n  by (metis RdX_def avar.simps(1) isRd.simps(1) p_obs_Rd_intro rd_val.simps(1))\n\ncorollary p_obs_RdA_intro:\n  \"wfs \\<sigma> \\<Longrightarrow> \\<sigma> [v \\<leftarrow>\\<^sup>A x]\\<^sub>t \\<sigma>' \\<Longrightarrow> [x \\<approx>\\<^sub>t v] \\<sigma>'\"\n  by (metis RdA_def avar.simps(1) isRd.simps(1) p_obs_Rd_intro rd_val.simps(1))\n\n\n\n\n\n\nlemma  [simp]: \"var w \\<noteq> y \\<Longrightarrow> lastWr (write_trans t b w u \\<sigma> ts') y =  lastWr \\<sigma> y\"\n  by(simp add: lastWr_def)\n\nlemma [simp]:\n  \"var w' = var w \\<Longrightarrow> tst w' = ts' \\<Longrightarrow> releasing (update_trans t w v' \\<sigma> ts') (var w', tst w')\"\n  by(simp add: releasing_def)\n\nlemma [simp]:\n  \"var w' = var w \\<Longrightarrow> tst w' = ts' \\<Longrightarrow> releasing (write_trans t b w v' \\<sigma> ts') (var w', tst w') = b\"\n  by(simp add: releasing_def)\n\nlemma c_obs_Wr_intro: \n  assumes \"wfs \\<sigma>\"\n  and \"wr_val a = Some u\"\n  and \"avar a = x\"\n  and \"isRA a\"\n  and \"isWr a\"\n  and \"d_obs_t \\<sigma> t y v\"\n  and \"\\<not> p_obs \\<sigma> t' x u\" \n  and \"x \\<noteq> y\"  \n  and \"step t a \\<sigma> \\<sigma>'\"\n  and \"t'\\<noteq> t\"\nshows \"c_obs \\<sigma>' x u t' y v\"\n  apply(rule step_cases[OF assms(9)]) \n  using assms(2) apply auto[1] defer \n  using assms(5) apply auto[1]\n  using assms(2,3,4,5,6,7) apply clarsimp\n  apply (case_tac \"aa \\<noteq> x\")\n  using visible_var apply fastforce\n  apply clarsimp\n  apply(simp add: d_obs_t_def d_obs_def p_obs_def c_obs_def)\n  apply clarsimp\n  apply (case_tac \"aa \\<noteq> x\")\n  using visible_var apply fastforce\n  apply (case_tac \"bb = ts'\") defer\n   apply(case_tac \"value (write_trans t True (x, b) u \\<sigma> ts')(x, bb) = value \\<sigma> (x, bb)\")\n  apply (simp add: visible_writes_def)\n  using assms(10) apply simp apply blast\n   apply(simp add: value_def)\n  apply simp \n  apply(rule conjI)\n   apply clarsimp\n  using assms(8) apply clarsimp \n  using assms apply (simp, auto)\n  by(simp add: releasing_def)\n\n\ncorollary c_obs_WrR_intro: \n  \"wfs \\<sigma> \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow> t' \\<noteq> t \n   \\<Longrightarrow> [y =\\<^sub>t v] \\<sigma> \\<Longrightarrow> \\<not> [x \\<approx>\\<^sub>t' u] \\<sigma>  \n   \\<Longrightarrow> \\<sigma> [x :=\\<^sup>R u]\\<^sub>t \\<sigma>'\n   \\<Longrightarrow> [x = u]\\<^sub>t'\\<lparr>y = v\\<rparr> \\<sigma>'\"\n  by (metis WrR_def avar.simps(2) c_obs_Wr_intro isRA.simps(2) isWr.simps(2) wr_val.simps(1))\n\n\n\nlemma c_obs_Up_intro: \n  assumes as1: \"wfs \\<sigma>\"\n  and as2: \"wr_val a = Some u\"\n  and as3: \"avar a = x\"\n  and as4: \"isUp a\"\n  and as5: \"d_obs_t \\<sigma> t y v\"\n  and as6: \"\\<not> p_obs \\<sigma> t' x u\" \n  and as7: \"x \\<noteq> y\"  \n  and as8: \"step t a \\<sigma> \\<sigma>'\"\n  and as9: \"t' \\<noteq> t\"\nshows \"c_obs \\<sigma>' x u t' y v\"\n  apply(rule step_cases[OF assms(8)]) \n  using as2 apply auto[1]  \n  using as4 apply auto[1] \n  using assms apply safe\nproof -\n  fix aa b xa va v' ts'\n  assume a1: \"wfs \\<sigma>\" and\n         a2: \"wr_val (Update xa (value \\<sigma> (aa, b)) v') = Some u\" and\n         a3: \"isUp (Update xa (value \\<sigma> (aa, b)) v')\" and\n         a4: \"[y =\\<^sub>t v] \\<sigma>\" and\n         a5: \"\\<not> [avar (Update xa (value \\<sigma> (aa, b)) v') \\<approx>\\<^sub>t' u] \\<sigma> \" and\n         a6: \"avar (Update xa (value \\<sigma> (aa, b)) v') \\<noteq> y\" and \n         a7: \"\\<sigma> RMW[xa, value \\<sigma> (aa, b), v']\\<^sub>t (update_trans t (aa, b) v' \\<sigma> ts')\" and \n         a8: \"t' \\<noteq> t\" and\n         a9: \"x = avar (Update xa (value \\<sigma> (aa, b)) v')\" and \n         a10: \"\\<sigma>' = update_trans t (aa, b) v' \\<sigma> ts'\"  and \n         a11: \"a = Update xa (value \\<sigma> (aa, b)) v'\" and \n         a12: \"(aa, b) \\<in> visible_writes \\<sigma> t (avar (Update xa (value \\<sigma> (aa, b)) v'))\" and\n         a13: \"(aa, b) \\<notin> covered \\<sigma>\" and \n         a14: \"valid_fresh_ts \\<sigma> (aa, b) ts'\"\n  show g: \"[avar (Update xa (value \\<sigma> (aa, b)) v') = u]\\<^sub>t'\\<lparr>y = v \\<rparr> (update_trans t (aa, b) v' \\<sigma> ts')\"\n    using a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 apply (simp add: update_simps step_def d_obs_def p_obs_def d_obs_t_def c_obs_def)\n    apply (case_tac \"releasing \\<sigma> (aa, b)\", safe)\n    apply (simp add: tst_def releasing_def)\n    apply ((metis fst_conv var_def writes_on_var)+) [9]\n    using as8 dual_order.antisym fun_upd_other \n    apply (smt as3 as5 d_obs_def d_obs_other d_obs_t_def fun_upd_eqD fun_upd_triv surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(1) surrey_state.update_convs(2) surrey_state.update_convs(3) surrey_state.update_convs(4) surrey_state.update_convs(5))\n    apply auto[1]\n    using as3 as5 as8 d_obs_def d_obs_other d_obs_t_def apply blast\n    using as3 as5 as8 d_obs_def d_obs_other d_obs_t_def apply blast\n    apply auto[1]\n    apply(simp add: releasing_def)\n    apply (smt Pair_inject fun_upd_other fun_upd_same surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(1) surrey_state.update_convs(2) surrey_state.update_convs(3) surrey_state.update_convs(4) surrey_state.update_convs(5) write_record.select_convs(2))                    \n    apply (simp add:tst_def var_def wfs_def wfs_preserved writes_on_def) \n    apply clarify\n    using as8 fst_conv mem_Collect_eq fun_upd_same not_less_iff_gr_or_eq snd_conv\n    apply (smt surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(1) surrey_state.update_convs(2) surrey_state.update_convs(3) surrey_state.update_convs(4) surrey_state.update_convs(5))\n    apply (metis fst_conv var_def writes_on_var)\n    apply (metis fst_conv var_def writes_on_var)\n    apply (metis fst_conv var_def writes_on_var)\n    apply (simp add: tst_def releasing_def) apply auto[1]\n    apply (smt Pair_inject fun_upd_other insert_iff mem_Collect_eq surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(1) surrey_state.update_convs(2) surrey_state.update_convs(4) surrey_state.update_convs(5) value_def writes_on_def)\n    using fst_conv insert_iff fun_upd_apply less_imp_not_less not_less_iff_gr_or_eq \n    apply (smt fun_upd_same surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(1) surrey_state.update_convs(2) surrey_state.update_convs(3) surrey_state.update_convs(4) surrey_state.update_convs(5))\n    apply (case_tac \"releasing \\<sigma> (aa, b)\", auto)[1]\n    using as3 as5 as8 d_obs_def d_obs_other d_obs_t_def apply blast\n    using as3 as5 as8 d_obs_def d_obs_other d_obs_t_def apply blast\n    apply (case_tac \"releasing \\<sigma> (aa, b)\", auto)[1]\n    apply (simp add: tst_def releasing_def value_def) apply auto[1]\n    apply (metis fst_conv var_def writes_on_var)\n    apply (unfold writes_on_def var_def) [1]\n    apply clarsimp apply auto[1]\n    apply (unfold writes_on_def var_def releasing_def value_def) [1]\n    apply clarsimp apply blast\n    apply ((metis fst_conv var_def writes_on_var)+)[9]\n    apply (case_tac \"releasing \\<sigma> (aa, b)\", auto)[1]\n    apply (unfold writes_on_def var_def releasing_def value_def) [1]\n    apply clarsimp \n    using not_less_iff_gr_or_eq apply blast\n    apply (unfold writes_on_def var_def releasing_def value_def) [1]\n    apply clarsimp \n    apply (smt as5 as8 assms(3) d_obs_def d_obs_other d_obs_t_def fun_upd_same fun_upd_triv fun_upd_twist surrey_state.select_convs(2) surrey_state.surjective surrey_state.update_convs(1) surrey_state.update_convs(2) surrey_state.update_convs(3) surrey_state.update_convs(4) surrey_state.update_convs(5))\n    apply auto[1]\n    apply (unfold writes_on_def var_def releasing_def value_def) [1]\n    apply clarsimp \n    using not_less_iff_gr_or_eq apply blast\n    using as3 as5 as8 d_obs_def d_obs_other d_obs_t_def apply blast\n    apply auto[1]\n    apply (unfold writes_on_def var_def releasing_def value_def) [1]\n    apply clarsimp \n    apply blast\n    apply (unfold writes_on_def var_def releasing_def value_def) [1]\n    apply clarsimp \n    apply blast\n    apply (metis fst_conv var_def writes_on_var)\n    apply (metis fst_conv var_def writes_on_var)\n    apply (metis fst_conv var_def writes_on_var)\n    apply auto[1]\n    apply (unfold writes_on_def var_def releasing_def value_def) [1]\n    apply clarsimp \n       apply safe[1]\n    apply (simp add: tst_def a11 a12 a13)\n        apply(simp add: lastWr_def )apply(unfold writes_on_def)apply simp\n    apply (smt Collect_cong Pair_inject fst_conv fun_upd_other fun_upd_same surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(1) surrey_state.update_convs(2) surrey_state.update_convs(3) surrey_state.update_convs(4) surrey_state.update_convs(5) var_def)\n    apply (simp add: tst_def a11 a12 a13)\n        apply(simp add: lastWr_def )apply(unfold writes_on_def)apply simp\n    apply (smt leD less_irrefl tst_def)\n    apply (unfold writes_on_def var_def releasing_def value_def) [1]\n    apply clarsimp \n    apply (smt Pair_inject fun_upd_same surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(1) surrey_state.update_convs(2) surrey_state.update_convs(3) surrey_state.update_convs(4) surrey_state.update_convs(5))\n    apply (unfold writes_on_def var_def releasing_def value_def) [1]\n    apply clarsimp \n    apply blast\n    apply (unfold writes_on_def var_def releasing_def value_def) [1]\n    apply clarsimp \n    by blast\nqed\n\n\ncorollary c_obs_RMW_intro: \n  \"wfs \\<sigma> \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow> t' \\<noteq> t \n   \\<Longrightarrow> [y =\\<^sub>t v] \\<sigma> \\<Longrightarrow> \\<not> [x \\<approx>\\<^sub>t' u] \\<sigma>  \n   \\<Longrightarrow> \\<sigma> RMW[x, w, u]\\<^sub>t \\<sigma>'\n   \\<Longrightarrow> [x = u]\\<^sub>t'\\<lparr>y = v\\<rparr> \\<sigma>'\"\n  using avar.simps(3) c_obs_Up_intro isUp.simps(3) wr_val.simps(2) by blast\n\n\n\n\nlemma c_obs_Rd_d_obs:  \\<comment> \\<open>Transfer\\<close>\n  assumes \"wfs \\<sigma>\"\n  and \"isRd a\"\n  and \"isRA a\"\n  and \"rd_val a = Some u\"\n  and \"avar a = x\"\n  and \"c_obs \\<sigma> x u t y v\"\n  and \"step t a \\<sigma> \\<sigma>'\"\nshows \"d_obs_t \\<sigma>' t y v\"\n  apply(rule step_cases[OF assms(7)]) \n    defer\n  using assms(2) apply simp\n  using assms(2) apply simp\n  using assms(6) apply clarsimp\n  using assms(6) apply clarsimp\n  apply(case_tac \"aa \\<noteq> x\")\n  using assms(5) visible_var apply fastforce\n  apply clarsimp\n  apply (case_tac \"\\<not> syncing \\<sigma> (x,b) True\")\n   apply (metis assms(4) c_obs_def option.sel prod.sel(1) rd_val.simps(1) syncing_def var_def visible_var)\n  apply clarsimp\n  using assms(3, 4, 5) apply clarsimp\n  apply (simp add: c_obs_def d_obs_t_def d_obs_def)\n  apply (rule conjI)\n  using assms(1)\n   apply(unfold  ts_oride_def visible_writes_def wfs_def)\n  apply (simp add: lastWr_def var_def)\n  apply(unfold lastWr_def read_trans_def rev_app_def update_thrView_def value_def writes_on_def)\n  by auto\n\ncorollary c_obs_RdA_d_obs:  \n  \"wfs \\<sigma> \\<Longrightarrow> [x = u]\\<^sub>t\\<lparr>y = v\\<rparr> \\<sigma> \\<Longrightarrow> \\<sigma> [u \\<leftarrow>\\<^sup>A x]\\<^sub>t \\<sigma>' \\<Longrightarrow> [y =\\<^sub>t v] \\<sigma>'\"\n  by (metis RdA_def avar.simps(1) c_obs_Rd_d_obs isRA.simps(1) isRd.simps(1) rd_val.simps(1))\n\n\n\nlemma c_obs_Up_d_obs:\n  assumes \"wfs \\<sigma>\"\n  and \"isUp a\"\n  and \"rd_val a = Some u\"\n  and \"avar a = x\"\n  and \"c_obs \\<sigma> x u t y v\"\n  and \"step t a \\<sigma> \\<sigma>'\"\n  and \"x \\<noteq> y\"\nshows \"d_obs_t \\<sigma>' t y v\"\n  apply(rule step_cases[OF assms(6)]) \n  using assms(2) isUp.simps(1) apply blast\n  using assms(3) apply auto[1]\n  using assms(2,3,4,5,7)\n  apply clarsimp\n  apply(case_tac \"aa \\<noteq> x\")\n   apply(simp add: visible_writes_def)\n   apply(unfold writes_on_def)\n   apply(elim conjE)\n   apply simp\n  apply clarsimp\n  apply(simp add: c_obs_def d_obs_t_def d_obs_def)\n  apply(intro conjI)\n   apply(simp add: ts_oride_def)\n   apply(intro conjI impI)\n  using assms(1) last_write_max wfs_def apply blast\n    apply (simp add: valid_fresh_ts_def)\n  apply(simp add: lastWr_def)\n  apply(unfold writes_on_def, simp, elim conjE)\n  by(simp add: value_def)\n  \ncorollary c_obs_UpRA_d_obs:  \n  \"wfs \\<sigma> \\<Longrightarrow> x\\<noteq>y \\<Longrightarrow> [x = u]\\<^sub>t\\<lparr>y = v\\<rparr> \\<sigma> \\<Longrightarrow> \\<sigma> RMW[x, u, z]\\<^sub>t \\<sigma>' \\<Longrightarrow> [y =\\<^sub>t v] \\<sigma>'\"\n  using avar.simps(3) c_obs_Up_d_obs isUp.simps(3) rd_val.simps(2) by blast\n\n\n\n\n\n\nlemma [simp]: \"z \\<noteq> x \\<Longrightarrow>  visible_writes (write_trans t b (z, ts) v \\<sigma> ts') t x = visible_writes \\<sigma> t x\"\n  by(simp add: visible_writes_def)\n\nlemma [simp]: \"var w \\<noteq> z \\<Longrightarrow>value (write_trans t ba (z, b) va \\<sigma> ts') w =  value \\<sigma> w\"\n  by(simp add: value_def)\n\nlemma [simp]: \"var w \\<noteq> z \\<Longrightarrow> releasing (write_trans t ba (z, b) va \\<sigma> ts') w = releasing \\<sigma> w \"\n  by(simp add: releasing_def)\n\nlemma [simp]: \"var w \\<noteq> z \\<Longrightarrow> z \\<noteq> y \\<Longrightarrow> d_obs(write_trans t ba (z, b) va \\<sigma> ts')(modView \\<sigma> w) y v = d_obs \\<sigma> (modView \\<sigma> w) y v\"\n  by(simp add: d_obs_def)\n  \nlemma c_obs_Rd_pres:\n  assumes \"wfs \\<sigma>\"\n  and \"isRd a\"\n  and \"c_obs \\<sigma> x u t y v\"\n  and \"step t' a \\<sigma> \\<sigma>'\"\n  and \"x \\<noteq> y\"\n  and \"\\<not>isRA a\"\n  and \"t \\<noteq> t'\"\nshows \"c_obs \\<sigma>' x u t y v\"\n  apply(rule step_cases[OF assms(4)]) \n  defer\n  using assms(2) apply auto[2] \n  using assms(1,2,3,5,6,7)\n  apply(elim conjE)\n  apply(simp add: c_obs_def d_obs_def visible_writes_def)\n  apply(unfold writes_on_def, clarsimp)\n  apply(intro conjI)\n    apply(simp add: read_trans_def rev_app_def Let_def update_modView_def update_thrView_def)\n  apply (smt action.simps(10) assms(4) lastWr_read_pres step_def)\n   apply (simp add: lastWr_read_pres)\n  by(simp add: releasing_def)\n\n\ncorollary c_obs_RdX_pres:\n  \"wfs \\<sigma> \\<Longrightarrow>  x \\<noteq> y \\<Longrightarrow> t \\<noteq> t'\n         \\<Longrightarrow> [x=u]\\<^sub>t\\<lparr>y=v\\<rparr> \\<sigma> \\<Longrightarrow> \\<sigma> [k \\<leftarrow> z]\\<^sub>t' \\<sigma>'\n         \\<Longrightarrow> [x=u]\\<^sub>t\\<lparr>y=v\\<rparr> \\<sigma>'\"\n  by (metis (full_types) RdX_def c_obs_Rd_pres isRA.simps(1) isRd.simps(1))\n\n\n\n\nlemma c_obs_Wr_pres:\n  assumes \"wfs \\<sigma>\"\n  and \"avar a = z\"\n  and \"isWr a\"\n  and \"z \\<noteq> y\"\n  and \"z \\<noteq>x\"\n  and \"x \\<noteq> y\"\n  and \"c_obs \\<sigma> x u t y v\"\n  and \"step t a \\<sigma> \\<sigma>'\"\nshows \"c_obs \\<sigma>' x u t y v\"\n  apply(rule step_cases[OF assms(8)]) \n  using assms(3) apply clarsimp defer\n  using assms(3) apply clarsimp\n  using assms(2,3,4,5,6,7) apply clarsimp\n  apply (case_tac \"aa \\<noteq> z\")\n  using visible_var apply force\n  apply clarsimp\n  by (simp add: c_obs_def) \n\ncorollary c_obs_WrX_pres:\n  \"wfs \\<sigma> \\<Longrightarrow> z \\<noteq> y \\<Longrightarrow> z \\<noteq> x \\<Longrightarrow> x \\<noteq> y \n         \\<Longrightarrow> [x=u]\\<^sub>t\\<lparr>y=v\\<rparr> \\<sigma> \\<Longrightarrow> \\<sigma> [z:= w]\\<^sub>t \\<sigma>'\n         \\<Longrightarrow> [x=u]\\<^sub>t\\<lparr>y=v\\<rparr> \\<sigma>'\"\n  by (metis WrX_def avar.simps(2) c_obs_Wr_pres isWr.simps(2))\n\ncorollary c_obs_WrR_pres:\n  \"wfs \\<sigma> \\<Longrightarrow> z \\<noteq> y \\<Longrightarrow> z \\<noteq> x \\<Longrightarrow> x \\<noteq> y \n         \\<Longrightarrow> [x=u]\\<^sub>t\\<lparr>y=v\\<rparr> \\<sigma> \\<Longrightarrow> \\<sigma> [z:=\\<^sup>R w]\\<^sub>t \\<sigma>'\n         \\<Longrightarrow> [x=u]\\<^sub>t\\<lparr>y=v\\<rparr> \\<sigma>'\"\n  by (metis WrR_def avar.simps(2) c_obs_Wr_pres isWr.simps(2))\n\n\n\nlemma d_obs_c_obs: \"wfs \\<sigma> \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma> \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow> u \\<noteq> m \\<Longrightarrow> [x = m]\\<^sub>t\\<lparr>y = v\\<rparr> \\<sigma>\"\n  apply(simp add: d_obs_t_def d_obs_def c_obs_def)\n  using d_obs_def d_obs_p_obs_agree d_obs_t_def p_obs_def by blast\n\n\nlemma [simp]: \"tst (x,b) < ts' \\<Longrightarrow> writes_on (write_trans t ba (x, b) va \\<sigma> ts') x = (writes_on \\<sigma> x) \\<union> {(x,ts')}\"\n by(simp add: visible_writes_def)\n\nlemma visible_writes_write_trans [simp]: \"wfs \\<sigma> \\<Longrightarrow> valid_fresh_ts \\<sigma> w ts' \\<Longrightarrow> t \\<noteq> t' \\<Longrightarrow> var w \\<noteq> x \\<Longrightarrow> \n            visible_writes \\<sigma> t x = visible_writes (write_trans t' b w v \\<sigma> ts') t x\"\n  apply(unfold visible_writes_def) by simp\n\nlemma value_not_change_write_to_different_var [simp]:  \"wfs \\<sigma> \\<Longrightarrow> t \\<noteq> t'  \\<Longrightarrow> w \\<in> visible_writes \\<sigma> t x \\<Longrightarrow> valid_fresh_ts \\<sigma> w' ts' \\<Longrightarrow>\n               var w \\<noteq> var w' \\<Longrightarrow> u = value \\<sigma> w \\<Longrightarrow> u = value (write_trans t' b w' v \\<sigma> ts') w\"\n  apply (unfold  write_trans_def rev_app_def value_def add_cv_def update_mods_def) apply simp\n  apply (rule conjI)\n  using visible_var apply fastforce\n  by (simp add: update_modView_def update_thrView_def)\n\nlemma \"wfs \\<sigma> \\<Longrightarrow> valid_fresh_ts \\<sigma> w ts' \\<Longrightarrow> t \\<noteq> t' \\<Longrightarrow> var w \\<noteq> x \\<Longrightarrow> p_obs \\<sigma> t x u =  p_obs (write_trans t' b w v \\<sigma> ts') t x u\"\n  apply (unfold  p_obs_def)\n  apply (case_tac \" visible_writes \\<sigma> t x \\<noteq> visible_writes (write_trans t' b w v \\<sigma> ts') t x\") \n  apply simp\n  using  value_not_change_write_to_different_var\n  by (metis (full_types) visible_var)     \n\n\nlemma not_p_obs_Wr_pres :  \n  assumes a1: \"wfs \\<sigma>\"\n      and a2: \"isWr a\"\n      and a3: \"avar a \\<noteq> x\"\n      and a4: \"t \\<noteq> t'\"\n      and a5: \"\\<not> p_obs \\<sigma> t x u\"\n      and a6: \"step t' a \\<sigma> \\<sigma>'\"\n    shows a7: \"\\<not> p_obs \\<sigma>' t x u\"\n  apply(rule step_cases[OF a6]) \n  using a2 apply auto[1]\n   defer\n  using a2 apply auto[1]\n  using assms\n  apply simp\n  apply(unfold p_obs_def) \n  apply(case_tac \"var w = x\")\n   apply simp \n  using visible_var apply fastforce\n  apply clarsimp\n  apply (case_tac \"var (aa, b) = x\")\n  using var_def apply auto[1]\n  using visible_writes_write_trans apply simp\n  using visible_var by fastforce\n\ncorollary not_p_obs_WrX_pres:\n  \"wfs \\<sigma> \\<Longrightarrow> y \\<noteq> x \\<Longrightarrow> t \\<noteq> t' \n    \\<Longrightarrow> \\<not> [x \\<approx>\\<^sub>t u] \\<sigma> \\<Longrightarrow> \\<sigma> [y := v]\\<^sub>t' \\<sigma>' \\<Longrightarrow> \\<not> [x \\<approx>\\<^sub>t u] \\<sigma>'\"\n  by (metis WrX_def avar.simps(2) isWr.simps(2) not_p_obs_Wr_pres)\n\ncorollary not_p_obs_WrR_pres:\n  \"wfs \\<sigma> \\<Longrightarrow> y \\<noteq> x \\<Longrightarrow> t \\<noteq> t' \n    \\<Longrightarrow> \\<not> [x \\<approx>\\<^sub>t u] \\<sigma> \\<Longrightarrow> \\<sigma> [y :=\\<^sup>R v]\\<^sub>t' \\<sigma>' \\<Longrightarrow> \\<not> [x \\<approx>\\<^sub>t u] \\<sigma>'\"\n  by (metis WrR_def avar.simps(2) isWr.simps(2) not_p_obs_Wr_pres)\n\nlemma not_p_obs_Up_pres :  \n  assumes a1: \"wfs \\<sigma>\"\n      and a2: \"isUp a\"\n      and a3: \"avar a \\<noteq> x\"\n      and a4: \"t \\<noteq> t'\"\n      and a5: \"\\<not> p_obs \\<sigma> t x u\"\n      and a6: \"step t' a \\<sigma> \\<sigma>'\"\n    shows \"\\<not> p_obs \\<sigma>' t x u\"\n  apply(rule step_cases[OF a6]) \n  using a2 apply auto[2]\n  apply (elim conjE)\nproof - \n  fix w xa v v' ts'\n  assume p1: \"\\<sigma>' = update_trans t' w v' \\<sigma> ts'\" and \n         p2: \"a = Update xa v v'\" and \n         p3: \"w \\<in> visible_writes \\<sigma> t' (avar a)\" and \n         p4: \"v = value \\<sigma> w\" and \n         p5: \"w \\<notin> covered \\<sigma>\" and\n         p6: \"valid_fresh_ts \\<sigma> w ts'\"\n  show \"\\<not> (p_obs (update_trans t' w v' \\<sigma> ts') t x u) \"\n    using p3 p4 p5 p6 \n  apply(simp add: p_obs_def) \n    apply (simp add: Let_def update_trans_def step_def rev_app_def add_cv_def update_mods_def update_modView_def update_thrView_def)\n    apply (case_tac \"releasing \\<sigma> w\", auto)\n     apply (simp add:visible_writes_def  valid_fresh_ts_def ts_oride_def, auto)\n     apply(unfold writes_on_def  tst_def tst_def value_def var_def visible_var visible_writes_def writes_on_def)\n     apply clarsimp\n    apply (smt a3 a4 a5 fst_conv fun_upd_other fun_upd_other insert_iff mem_Collect_eq old.prod.inject p3 p_obs_def snd_conv surrey_state.select_convs(1) surrey_state.select_convs(2) surrey_state.select_convs(4) surrey_state.surjective surrey_state.update_convs(1) surrey_state.update_convs(2) surrey_state.update_convs(3) surrey_state.update_convs(4) surrey_state.update_convs(5) tst_def value_def var_def visible_var visible_writes_def writes_on_def)\n    using a1 a2 a3 a4 a5 a6 apply auto\n     apply (simp add: tst_def value_def var_def p_obs_def is_releasing_def visible_writes_def  valid_fresh_ts_def ts_oride_def, auto)\n     apply(unfold wfs_def writes_on_def tst_def tst_def value_def var_def visible_var visible_writes_def writes_on_def)\n     apply clarsimp\n    by (smt Pair_inject fun_upd_other insert_iff surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(1) surrey_state.update_convs(2) surrey_state.update_convs(3) surrey_state.update_convs(4) surrey_state.update_convs(5))\nqed\n\ncorollary not_p_obs_RMW_pres:\n  \"wfs \\<sigma> \\<Longrightarrow> y \\<noteq> x \\<Longrightarrow> t \\<noteq> t' \n    \\<Longrightarrow> \\<not> [x \\<approx>\\<^sub>t u] \\<sigma> \\<Longrightarrow> \\<sigma> RMW[y, v, w]\\<^sub>t' \\<sigma>' \\<Longrightarrow> \\<not> [x \\<approx>\\<^sub>t u] \\<sigma>'\"\n  using not_p_obs_Up_pres by force\n\nlemma neg_pobs_val:\n  assumes \"isRd a\"\n     and \"\\<not> p_obs \\<sigma> t x u\"\n     and \"step t a \\<sigma> \\<sigma>''\"\n     and \"avar a = x\"\n   shows \"rd_val a \\<noteq> Some u\"\n  using assms \n  apply (simp add: step_def)\n  apply (elim exE conjE)\n  apply (cases rule: action.exhaust[where y = a], auto) \n  using p_obs_def by blast  \n\nlemma visible_writes_subset:\n  assumes \"wfs \\<sigma>\" \n     and \"isRd a\"\n     and \"step t a \\<sigma> \\<sigma>'\"\n     and \"avar a = x\"\n   shows \"visible_writes \\<sigma>' t x \\<subseteq> visible_writes \\<sigma> t x\"\n  using assms \n  apply (simp add: step_def)\n  apply (elim exE conjE)\n  apply (cases rule: action.exhaust[where y = a], auto) \n  apply (simp add: visible_writes_def)\n  apply (elim conjE)\n  apply (cases \"isRA a\", auto)\n  apply (unfold writes_on_def wfs_def read_trans_def ts_oride_def tst_def update_thrView_def rev_app_def, auto)\n  by (smt fun_upd_same order_trans snd_conv surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(2))\n\nlemma not_pobs_Rd_pres:\n  assumes \"isRd a\"\n     and \"\\<not> p_obs \\<sigma> t x u \"\n     and \"step t' a \\<sigma> \\<sigma>'\"\n   shows \"\\<not> p_obs \\<sigma>' t x u\"\n  using assms \n  apply (cases \"t = t'\", auto)\n  apply(rule step_cases[OF assms(3)]) \n  apply simp\n  apply (unfold p_obs_def read_trans_def update_thrView_def value_def visible_writes_def writes_on_def)\n  apply auto \n  apply (smt action.simps(10) dual_order.trans fun_upd_same fun_upd_triv fun_upd_twist mem_Collect_eq read_trans_def rev_app_def step_def surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(2) ts_oride_def update_thrView_def visible_writes_def writes_on_var)\n  by (smt action.simps(10) fun_upd_other isRd.elims(2) read_trans_def rev_app_def step_def surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(2) update_thrView_def)  \n\ncorollary not_pobs_RdX_pres:\n  \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma> \\<Longrightarrow> \\<sigma> [v \\<leftarrow> y]\\<^sub>t' \\<sigma>' \\<Longrightarrow> \\<not> [x \\<approx>\\<^sub>t u] \\<sigma>'\"\n  by (metis RdX_def not_pobs_Rd_pres isRd.simps(1))\n\ncorollary not_pobs_RdA_pres:\n  \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma> \\<Longrightarrow> \\<sigma> [v \\<leftarrow>\\<^sup>A y]\\<^sub>t' \\<sigma>' \\<Longrightarrow> \\<not> [x \\<approx>\\<^sub>t u] \\<sigma>'\"\n  by (metis RdA_def isRd.simps(1) not_pobs_Rd_pres)\n\n\n\nlemma not_p_obs_Wr_val_pres:\n  assumes \"isWr a\"\n     and \"\\<not> p_obs \\<sigma> t x u\"\n     and \"step t' a \\<sigma> \\<sigma>'\"\n     and \"wr_val a = Some v\"\n     and \"u \\<noteq> v\"\n   shows \"\\<not> p_obs \\<sigma>' t x u\"\n  using assms \n  apply (cases \"t = t'\", auto)\n  apply(rule step_cases[OF assms(3)]) \n  apply (simp, auto)\n  apply (unfold p_obs_def write_trans_def update_thrView_def step_def update_modView_def)\n  apply auto \n  apply (unfold rev_app_def tst_def update_mods_def add_cv_def valid_fresh_ts_def value_def writes_on_def visible_writes_def)\n  apply safe\n  apply (cases \"avar a = x\", safe, clarsimp)\n  apply (smt dual_order.strict_implies_order dual_order.trans write_record.select_convs(1))\n  apply clarsimp\n  apply blast\n  apply (cases \"a\", auto)\n  by (smt write_record.select_convs(1))\n\ncorollary not_p_obs_WrX_val_pres:\n  \"u \\<noteq> v \\<Longrightarrow> \\<not> [x \\<approx>\\<^sub>t u] \\<sigma> \\<Longrightarrow> \\<sigma> [y := v]\\<^sub>t' \\<sigma>' \\<Longrightarrow> \\<not> [x \\<approx>\\<^sub>t u] \\<sigma>'\"\n  by (metis WrX_def isWr.simps(2) not_p_obs_Wr_val_pres wr_val.simps(1))\n\ncorollary not_p_obs_WrR_val_pres:\n  \"u \\<noteq> v \\<Longrightarrow> \\<not> [x \\<approx>\\<^sub>t u] \\<sigma> \\<Longrightarrow> \\<sigma> [y :=\\<^sup>R v]\\<^sub>t' \\<sigma>' \\<Longrightarrow> \\<not> [x \\<approx>\\<^sub>t u] \\<sigma>'\"\n  by (metis WrR_def isWr.simps(2) not_p_obs_Wr_val_pres wr_val.simps(1))\n\n\nlemma not_p_obs_Wr_diff_var_pres:\n  assumes \"isWr a\"\n     and \"\\<not> p_obs \\<sigma> t x u\"\n     and \"step t' a \\<sigma> \\<sigma>'\"\n     and \"avar a = y\"\n     and \"x \\<noteq> y\"\n   shows \"\\<not> p_obs \\<sigma>' t x u\"\n  using assms \n  apply (cases \"t = t'\", auto)\n  apply(rule step_cases[OF assms(3)]) \n  apply (simp, auto)\n  apply (unfold p_obs_def write_trans_def update_thrView_def step_def update_modView_def)\n  apply auto \n  apply (unfold rev_app_def tst_def update_mods_def add_cv_def valid_fresh_ts_def value_def writes_on_def visible_writes_def)\n  apply safe\n  apply clarsimp\n  apply blast\n  by (cases \"a\", auto)\n\ncorollary not_p_obs_WrX_diff_var_pres:\n  \"x \\<noteq> y \\<Longrightarrow> \\<not> [x \\<approx>\\<^sub>t u] \\<sigma> \\<Longrightarrow> \\<sigma> [y := v]\\<^sub>t' \\<sigma>' \\<Longrightarrow> \\<not> [x \\<approx>\\<^sub>t u] \\<sigma>'\"\n  by (metis WrX_def avar.simps(2) isWr.simps(2) not_p_obs_Wr_diff_var_pres)\n\ncorollary not_p_obs_WrA_diff_var_pres:\n  \"x \\<noteq> y \\<Longrightarrow> \\<not> [x \\<approx>\\<^sub>t u] \\<sigma> \\<Longrightarrow> \\<sigma> [y :=\\<^sup>R v]\\<^sub>t' \\<sigma>' \\<Longrightarrow> \\<not> [x \\<approx>\\<^sub>t u] \\<sigma>'\"\n  by (metis WrR_def avar.simps(2) isWr.simps(2) not_p_obs_Wr_diff_var_pres)\n\n\nlemma not_p_obs_Up_val_pres:\n  assumes \"isUp a\"\n     and \"\\<not> p_obs \\<sigma> t x u\"\n     and \"step t' a \\<sigma> \\<sigma>'\"\n     and \"wr_val a = Some v\"\n     and \"u \\<noteq> v\"\n   shows \"\\<not> p_obs \\<sigma>' t x u\"\n  using assms \n  apply (cases \"t = t'\", auto)\n  apply(rule step_cases[OF assms(3)]) \n  apply (simp, auto)\n  apply (unfold p_obs_def update_trans_def update_thrView_def step_def update_modView_def)\n  apply auto \n  apply (unfold ts_oride_def Let_def tst_def rev_app_def tst_def update_mods_def add_cv_def valid_fresh_ts_def value_def writes_on_def visible_writes_def)\n  apply safe\n  apply (cases \"avar a = x\", safe, clarsimp)\n  apply (smt Pair_inject dual_order.trans  fun_upd_same fun_upd_triv fun_upd_twist insert_iff leD less_eq_rat_def not_le prod.collapse surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(1) surrey_state.update_convs(2) surrey_state.update_convs(3) surrey_state.update_convs(4) surrey_state.update_convs(5)  write_record.select_convs(1))\n   apply clarsimp\n   apply (case_tac \"releasing \\<sigma> (aa, ba)\", clarsimp) \n  apply (smt fun_upd_other order_trans)\n  apply auto[1]\n  apply(rule step_cases[OF assms(3)]) \n  apply (simp, auto)\n  apply (unfold p_obs_def update_trans_def update_thrView_def step_def update_modView_def)\n  apply auto \n  apply (unfold ts_oride_def Let_def tst_def rev_app_def tst_def update_mods_def add_cv_def valid_fresh_ts_def value_def writes_on_def visible_writes_def)\n  apply safe\n  apply (cases \"avar a = x\", safe, clarsimp)\n  apply (smt Pair_inject dual_order.trans  fun_upd_same fun_upd_triv fun_upd_twist insert_iff leD less_eq_rat_def not_le prod.collapse surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(1) surrey_state.update_convs(2) surrey_state.update_convs(3) surrey_state.update_convs(4) surrey_state.update_convs(5)  write_record.select_convs(1))\n   apply clarsimp\n  by (smt write_record.select_convs(1))\n\n\ncorollary not_p_obs_RMW_val_pres:\n  \"u \\<noteq> v \\<Longrightarrow> \\<not> [x \\<approx>\\<^sub>t u] \\<sigma> \\<Longrightarrow> \\<sigma> RMW[y, w, v]\\<^sub>t' \\<sigma>' \\<Longrightarrow> \\<not> [x \\<approx>\\<^sub>t u] \\<sigma>'\"\n    using isUp.simps(3) not_p_obs_Up_val_pres wr_val.simps(2) by blast\n\n\nlemma dobs_Rd_pres:\n  assumes \"isRd a\"\n     and \"d_obs_t \\<sigma> t x v\"\n     and \"step t' a \\<sigma> \\<sigma>'\"\n     and \"t \\<noteq> t'\"\n     shows \"d_obs_t \\<sigma>' t x v\"\n  apply(rule step_cases[OF assms(3)]) \n  apply (simp add: step_def d_obs_t_def d_obs_def)\n  apply (elim exE conjE)  \n  apply (smt Collect_cong assms(2) assms(4) d_obs_def d_obs_t_def fun_upd_other lastWr_def read_trans_def rev_app_def surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(2) update_thrView_def value_def writes_on_def)\n  using assms by auto\n\nlemma dobs_RdX_pres:\n  \"t \\<noteq> t' \\<Longrightarrow> [x =\\<^sub>t v] \\<sigma> \\<Longrightarrow> \\<sigma> [u \\<leftarrow> y]\\<^sub>t' \\<sigma>' \\<Longrightarrow> [x =\\<^sub>t v] \\<sigma>'\"\n  by (metis RdX_def dobs_Rd_pres isRd.simps(1))\n\nlemma dobs_RdA_pres:\n  \"t \\<noteq> t' \\<Longrightarrow> [x =\\<^sub>t v] \\<sigma> \\<Longrightarrow> \\<sigma> [u \\<leftarrow>\\<^sup>A y]\\<^sub>t' \\<sigma>' \\<Longrightarrow> [x =\\<^sub>t v] \\<sigma>'\"\n  by (metis RdA_def dobs_Rd_pres isRd.simps(1))\n\nlemma dobs_Wr_pres:\n  assumes \"isWr a\"\n     and \"d_obs_t \\<sigma> t x v\"\n     and \"avar a \\<noteq> x\" \n     and \"step t' a \\<sigma> \\<sigma>'\"\n     and \"t \\<noteq> t'\"\n     shows \"d_obs_t \\<sigma>' t x v\"\n  apply(rule step_cases[OF assms(4)]) \n  using assms(1) apply auto[1]\n  defer\n  using assms(1) apply auto[1]\n  apply(unfold d_obs_t_def d_obs_def)\n  using assms\n  apply simp\n   apply(case_tac \"var w = x\")\n  using visible_var apply fastforce\n  apply (rule conjI) \n   apply(unfold d_obs_def d_obs_t_def) apply simp\n  by clarsimp\n\nlemma dobs_WrX_pres:\n  \"t \\<noteq> t' \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow> [x =\\<^sub>t v] \\<sigma> \\<Longrightarrow> \\<sigma> [y:= u]\\<^sub>t' \\<sigma>' \\<Longrightarrow> [x =\\<^sub>t v] \\<sigma>'\"\n  by (metis WrX_def avar.simps(2) dobs_Wr_pres isWr.simps(2))\n\nlemma dobs_WrR_pres:\n  \"t \\<noteq> t' \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow> [x =\\<^sub>t v] \\<sigma> \\<Longrightarrow> \\<sigma> [y:=\\<^sup>R u]\\<^sub>t' \\<sigma>' \\<Longrightarrow> [x =\\<^sub>t v] \\<sigma>'\"\n  by (metis WrR_def avar.simps(2) dobs_Wr_pres isWr.simps(2))\n\n\nlemma dobs_Up_pres:\n  assumes \"isUp a\"\n     and \"d_obs_t \\<sigma> t x v\"\n     and \"avar a \\<noteq> x\" \n     and \"step t' a \\<sigma> \\<sigma>'\"\n     and \"t \\<noteq> t'\"\n     shows \"d_obs_t \\<sigma>' t x v\"\n  apply(rule step_cases[OF assms(4)]) \n  using assms(1) apply auto[2]\n  apply(unfold d_obs_t_def d_obs_def)\n  using assms\n  apply simp\n   apply(case_tac \"var w = x\")\n  using visible_var apply fastforce\n  apply (rule conjI) \n   apply(unfold d_obs_def d_obs_t_def) apply simp\n   apply(unfold Let_def step_def update_mods_def valid_fresh_ts_def tst_def lastWr_def add_cv_def update_trans_def update_thrView_def update_modView_def rev_app_def) \n   apply(case_tac \"releasing \\<sigma> w\") apply clarsimp\n   apply (case_tac \"releasing \\<sigma> (aaa, ba)\") apply auto \n     apply (simp_all add: value_def var_def  writes_on_def)\n  by (smt Collect_cong fst_conv var_def visible_var)+\n\n\nlemma dobs_RMW_pres:\n  \"t \\<noteq> t' \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow> [x =\\<^sub>t v] \\<sigma> \\<Longrightarrow> \\<sigma> RMW[y, w, u]\\<^sub>t' \\<sigma>' \\<Longrightarrow> [x =\\<^sub>t v] \\<sigma>'\"\n  using dobs_Up_pres by force\n  \n\nlemma cobs_pres:\n  assumes \"c_obs \\<sigma> x u t y v\"\n      and \"x \\<noteq> y\" \n      and \"wfs \\<sigma>\"\n      and \"v' \\<noteq> u\"\n      and \"step t (Read m x v') \\<sigma> \\<sigma>'\"\n    shows \"c_obs \\<sigma>' x u t y v\"\n  using assms apply (simp add: c_obs_def)\n  apply (cases \"m\")\n  apply (simp add: d_obs_def) apply safe[1]\n  apply (smt Collect_cong action.simps(10) avar.simps(1) in_mono isRd.simps(1) lastWr_def read_trans_def rev_app_def step_def surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(2) update_thrView_def value_def visible_writes_subset writes_on_def)\n  apply (smt Collect_cong action.simps(10) avar.simps(1) in_mono isRd.simps(1) lastWr_def read_trans_def rev_app_def step_def surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(2) update_thrView_def value_def visible_writes_subset writes_on_def)\n  apply (simp add:visible_writes_def releasing_def step_def, clarify)\n  apply (smt assms(5) avar.simps(1) in_mono isRd.simps(1) mem_Collect_eq read_trans_def rev_app_def snd_conv surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(2) tst_def update_thrView_def value_def visible_writes_def visible_writes_subset)\n  apply auto\n  apply (simp add:visible_writes_def releasing_def step_def d_obs_def lastWr_def, auto)\n  apply (smt dual_order.trans read_trans_def rev_app_def snd_conv surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(2) tst_def update_thrView_def value_def)\n  apply (smt dual_order.trans read_trans_def rev_app_def snd_conv surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(2) tst_def update_thrView_def value_def)\n  by (smt action.simps(10) avar.simps(1) in_mono isRd.simps(1) read_trans_def releasing_def rev_app_def step_def surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(2) update_thrView_def value_def visible_writes_subset)\n\n\nlemma cobs_Rd_pres:\n  assumes \"c_obs \\<sigma> x u t y v\"\n      and \"isRd a\"\n      and \"rd_val a = Some w\"\n      and \"x \\<noteq> y\" \n      and \"wfs \\<sigma>\"\n      and \"w \\<noteq> u\"\n      and \"step t a \\<sigma> \\<sigma>'\"\n    shows \"c_obs \\<sigma>' x u t y v\"\n  using assms apply (simp add: c_obs_def step_def)\n  apply (cases \"a\", auto)\n  apply (simp_all add: Let_def lastWr_def rev_app_def d_obs_def step_def read_trans_def) apply auto\n  apply (unfold writes_on_def tst_def value_def visible_writes_def update_thrView_def) \n  apply auto\n  apply (smt dual_order.trans fun_upd_other fun_upd_same snd_conv ts_oride_def tst_def)\n  apply (smt dual_order.trans fun_upd_other fun_upd_same snd_conv ts_oride_def tst_def)\n  using dual_order.trans apply fastforce\n  using dual_order.trans apply fastforce\n  apply (smt dual_order.trans fun_upd_other fun_upd_same releasing_def snd_conv surrey_state.select_convs(4) surrey_state.surjective surrey_state.update_convs(2) ts_oride_def tst_def)\n  by (smt dual_order.trans releasing_def snd_conv surrey_state.select_convs(4) surrey_state.surjective surrey_state.update_convs(2))\n\n\nlemma cobs_RdX_pres:\n  \"wfs \\<sigma> \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow> w \\<noteq> u \n    \\<Longrightarrow> [x = u]\\<^sub>t\\<lparr>y = v\\<rparr> \\<sigma> \\<Longrightarrow> \\<sigma> [w \\<leftarrow> z]\\<^sub>t \\<sigma>' \\<Longrightarrow> [x = u]\\<^sub>t\\<lparr>y = v\\<rparr> \\<sigma>'\"\n  by (metis RdX_def cobs_Rd_pres isRd.simps(1) rd_val.simps(1))\n\nlemma cobs_RdA_pres:\n  \"wfs \\<sigma> \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow> w \\<noteq> u \n    \\<Longrightarrow> [x = u]\\<^sub>t\\<lparr>y = v\\<rparr> \\<sigma> \\<Longrightarrow> \\<sigma> [w \\<leftarrow>\\<^sup>A z]\\<^sub>t \\<sigma>' \\<Longrightarrow> [x = u]\\<^sub>t\\<lparr>y = v\\<rparr> \\<sigma>'\"\n  by (metis RdA_def cobs_Rd_pres isRd.simps(1) rd_val.simps(1))\n\nlemma cobs_Rd_diff_var_pres:\n  assumes \"c_obs \\<sigma> x u t y v\"\n      and \"isRd a\"\n      and \"avar a \\<noteq> x\"\n      and \"x \\<noteq> y\" \n      and \"wfs \\<sigma>\"\n      and \"step t' a \\<sigma> \\<sigma>'\"\n    shows \"c_obs \\<sigma>' x u t y v\"\n  apply(rule step_cases[OF assms(6)]) \n  defer\n  using assms(2) apply auto[2]\n  using assms(1,2,3,4,5)\n  apply (simp add: c_obs_def)\n  apply (simp_all add: Let_def lastWr_def rev_app_def d_obs_def step_def read_trans_def)\n       apply (unfold writes_on_def tst_def value_def visible_writes_def update_thrView_def)\n  apply simp\n  by (smt fun_upd_other order.trans releasing_def surrey_state.select_convs(4) surrey_state.surjective surrey_state.update_convs(2) ts_oride_def tst_def)\n\nlemma cobs_RdX_diff_var_pres:\n  \"wfs \\<sigma> \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow> x \\<noteq> z\n    \\<Longrightarrow> [x = u]\\<^sub>t\\<lparr>y = v\\<rparr> \\<sigma> \\<Longrightarrow> \\<sigma> [w \\<leftarrow> z]\\<^sub>t' \\<sigma>' \\<Longrightarrow> [x = u]\\<^sub>t\\<lparr>y = v\\<rparr> \\<sigma>'\"\n  by (metis RdX_def avar.simps(1) cobs_Rd_diff_var_pres isRd.simps(1))\n\nlemma cobs_RdA_diff_var_pres:\n  \"wfs \\<sigma> \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow> x \\<noteq> z\n    \\<Longrightarrow> [x = u]\\<^sub>t\\<lparr>y = v\\<rparr> \\<sigma> \\<Longrightarrow> \\<sigma> [w \\<leftarrow>\\<^sup>A z]\\<^sub>t' \\<sigma>' \\<Longrightarrow> [x = u]\\<^sub>t\\<lparr>y = v\\<rparr> \\<sigma>'\"\n  by (metis RdA_def avar.simps(1) cobs_Rd_diff_var_pres isRd.simps(1))\n\n\n(*\n\n    y \\<noteq> x \\<Longrightarrow>\n    wfs (state s) \\<Longrightarrow>\n    [y = Suc 0]\\<^sub>t2\\<lparr>x = Suc 0 \\<rparr> state s \\<Longrightarrow>\n    state s [a s' \\<leftarrow> x]\\<^sub>t3 state s' \\<Longrightarrow>\n    [y = Suc 0]\\<^sub>t2\\<lparr>x = Suc 0 \\<rparr> state s'*)\n\n\nlemma p_obs_Rd_intro2:\n  assumes \"step t (Read m x v) \\<sigma> \\<sigma>'\"\n    shows \"p_obs \\<sigma> t x v\"\n  apply(rule step_cases[OF assms(1)])\n  defer\n  apply simp\n  apply blast\n  using p_obs_def by fastforce\n\n\n\n\n\nlemma init_d_obs:  \"wfs \\<sigma> \\<Longrightarrow> initial_state \\<sigma> I \\<Longrightarrow> I x = u \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma>\"\n  apply(simp add: initial_state_def d_obs_def d_obs_t_def)\n    apply(elim exE conjE, intro conjI)\n  defer\n  apply(simp add: value_def)\n  apply (simp add: lastWr_def)\n  using last_write_write_on\nproof -\n  fix F :: \"nat \\<Rightarrow> rat\"\n  assume a1: \"wfs \\<sigma>\"\n  assume a3: \"\\<forall>t x. thrView \\<sigma> t x = (x, F x)\"\n  assume a4: \"\\<forall>a b x. modView \\<sigma> (a, b) x = (x, F x)\"\n  have f5: \"\\<And>n. var (lastWr \\<sigma> n) = n \\<and> lastWr \\<sigma> n \\<in> surrey_state.writes \\<sigma>\"\n    using a1 writes_on_def by fastforce\n  then have \"\\<And>n. \\<exists>na. lastWr \\<sigma> n = (na, F na)\"\n    by (metis a1 a4 old.prod.exhaust own_ModView)\n    then show \"thrView \\<sigma> t x = lastWr \\<sigma> x\"\n    using f5 a4 a3 a1 by (metis (no_types) own_ModView)\nqed\n\n  \n  \n\ndefinition \"covered_v \\<sigma> x v \\<equiv> \\<forall> w .  w \\<in> writes_on \\<sigma> x \\<and> w \\<notin> covered \\<sigma> \\<longrightarrow> w = lastWr \\<sigma> x \\<and> value \\<sigma> w = v\"\n\nabbreviation covered_v_abbr:: \"L \\<Rightarrow> V  \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"cvd[_, _] _\" [100, 100,100])\n  where \"cvd[x, u] \\<sigma> \\<equiv> covered_v \\<sigma> x u\"\n\n\nlemma init_covered_v: \"initial_state \\<sigma> I \\<Longrightarrow> covered_v \\<sigma> x (I x)\"\n  apply(simp add:  covered_v_def)\n  apply clarsimp\n  using initially_write_unique\n  apply(intro conjI)\n   apply (simp add: initial_wfs initially_write_unique)\n  apply(unfold writes_on_def)\n  proof -\n  fix a :: nat and b :: rat\n  assume a1: \"initial_state \\<sigma> I\"\n    assume a2: \"(a, b) \\<in> {w. var w = x \\<and> w \\<in> surrey_state.writes \\<sigma>}\"\n    have \"\\<forall>p. I (var p) = value \\<sigma> p\"\n      using a1 by (metis (no_types) initial_state_def value_def write_record.select_convs(1))\n    then show \"value \\<sigma> (a, b) = I x\"\n      using a2 by auto\n  qed\n\nlemma covered_update_v_pres:\n  assumes \"covered_v \\<sigma> x u\"\n  and \"wfs \\<sigma>\"\n  and \"step t a \\<sigma> \\<sigma>'\"\n  and \"isUp a\"\n  and \"avar a = x\"\n  and \"wr_val a = Some v\"\nshows \"covered_v \\<sigma>' x v\"\n  apply(rule step_cases[OF assms(3)])\n  using assms(4) apply auto[1]\n    using assms(4) isUp.simps(2) apply blast\n    using assms(1,2,4,5)\n       apply(simp add: covered_v_def)\n    apply(intro allI impI, elim conjE)\n    apply(unfold writes_on_def)\n    apply simp\n    apply(elim  conjE)\n    apply clarsimp\n    apply(simp add: visible_writes_def)\n    apply(unfold writes_on_def)\n    apply clarsimp\n    apply(simp add: valid_fresh_ts_def)\n     apply(unfold writes_on_def)\n    apply(elim  conjE)\n    apply(case_tac \"ba = b\", simp)\n    apply(case_tac \"ba < b\", simp)\n     apply (metis dual_order.irrefl prod.inject)\n    apply clarsimp\n    apply(simp add: update_trans_def rev_app_def Let_def update_mods_def add_cv_def update_modView_def update_thrView_def)\n    apply (auto simp add: value_def)\n    using assms(6) apply auto[1]\n    apply (metis Pair_inject)\n    by (metis Pair_inject)\n\n\ncorollary cvd_RMW_new_cvd:\n  \"wfs \\<sigma> \\<Longrightarrow> cvd[x,u] \\<sigma> \\<Longrightarrow>  \\<sigma> RMW[x, z, v]\\<^sub>t \\<sigma>' \\<Longrightarrow> cvd[x,v] \\<sigma>' \"\n  by (simp add: covered_update_v_pres)\n\ncorollary cvd_SWAP_new_cvd:\n  \"wfs \\<sigma> \\<Longrightarrow> cvd[x,u] \\<sigma> \\<Longrightarrow>  \\<sigma> SWAP[x, v]\\<^sub>t \\<sigma>' \\<Longrightarrow> cvd[x,v] \\<sigma>' \"\n  using cvd_RMW_new_cvd by blast\n\n\nlemma covered_read_v_pres:\n  assumes \"covered_v \\<sigma> x u\"\n  and \"wfs \\<sigma>\"\n  and \"step t a \\<sigma> \\<sigma>'\"\n  and \"isRd a\"\nshows \"covered_v \\<sigma>' x u\"\n  apply(rule step_cases[OF assms(3)])\n  defer\n  using assms(4) apply auto[1]\n  using assms(4) apply auto[1]\n  using assms(1,2,4)\n       apply(simp add: covered_v_def)\n    apply(intro allI impI conjI, elim conjE)\n   apply(unfold writes_on_def, simp)\n    apply(simp add: read_trans_def rev_app_def Let_def  add_cv_def update_mods_def update_modView_def update_thrView_def)\n   apply(intro conjI impI, elim conjE)\n    apply(unfold wfs_def)\n    apply(case_tac \"syncing \\<sigma> w b\", clarsimp)\n  apply(simp add: visible_writes_def)\n    apply(unfold lastWr_def writes_on_def, clarsimp)\n  apply blast\n   apply auto[1]\n  apply(simp add: value_def)\n  apply(elim conjE)\n  apply clarsimp\n  done\n\nlemma covered_v_RMW_d_obs:\n  assumes \"covered_v \\<sigma> x v\"\n  and \"wfs \\<sigma>\"\n  and \"step t a \\<sigma> \\<sigma>'\"\n  and \"isUp a\"\n  and \"avar a = x\"\n  and \"wr_val a = Some u\"\nshows \"d_obs_t \\<sigma>' t x u\"\n  apply(rule step_cases[OF assms(3)])\n  using assms(4) isUp.simps(1) apply blast\n  using assms(4) isUp.simps(2) apply blast\n  using assms(1,2, 4, 5, 6)\n  apply(simp add: covered_v_def d_obs_t_def d_obs_def)\n  apply(intro conjI)\n   defer\n  apply(elim conjE)\n   apply(simp add: value_def)\n  apply(simp add: visible_writes_def)\n   apply(unfold  writes_on_def, clarsimp)\n  apply(unfold  visible_writes_def writes_on_def, clarsimp)\n  apply(simp add: update_trans_def Let_def rev_app_def update_thrView_def ts_oride_def)\n  apply(simp add: add_cv_def update_modView_def update_mods_def)\n  apply(case_tac \"releasing \\<sigma> (x, b)\", clarsimp)\n   defer\n   apply blast\n  apply(simp add: ts_oride_def valid_fresh_ts_def)\n  apply(intro impI)\n  apply(unfold  wfs_def lastWr_def writes_on_def, clarsimp)\n  done\n\ncorollary cvd_RMW_d_obs:\n  \"wfs \\<sigma> \\<Longrightarrow> cvd[x,v] \\<sigma> \\<Longrightarrow>  \\<sigma> RMW[x, w, u]\\<^sub>t \\<sigma>' \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma>' \"\n  by (simp add: covered_v_RMW_d_obs)\n\ncorollary cvd_SWAP_d_obs:\n  \"wfs \\<sigma> \\<Longrightarrow> cvd[x,v] \\<sigma> \\<Longrightarrow>  \\<sigma> SWAP[x, u]\\<^sub>t \\<sigma>' \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma>' \"\n  using cvd_RMW_d_obs by auto\n\n\nlemma covered_diff_var_pres:\n  assumes \"covered_v \\<sigma> x v\"\n  and \"wfs \\<sigma>\"\n  and \"step t a \\<sigma> \\<sigma>'\"\n  and \"avar a \\<noteq> x\"\nshows \"covered_v \\<sigma>' x v\"\n  apply(rule step_cases[OF assms(3)])\n   using assms(1,2,4)\n    apply(simp add: covered_v_def)\n    apply(unfold  writes_on_def, clarsimp)\n     apply (intro conjI)\n      apply(case_tac \"xa \\<noteq> aa\")\n       apply(simp add: visible_writes_def)\n       apply clarsimp\n       apply(unfold  wfs_def writes_on_def, simp)\n   apply clarsimp\n         apply(simp add: read_trans_def rev_app_def Let_def update_thrView_def)\n   apply(intro conjI impI)\n   apply(simp add: lastWr_def ts_oride_def)\n       apply(unfold   writes_on_def, simp)      \n   apply(simp add: lastWr_def ts_oride_def)\n       apply(unfold   writes_on_def, simp)      \n  apply (smt read_trans_def rev_app_def surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(2) update_thrView_def value_def)\n   using assms(1,2,4)\n    apply(simp add: covered_v_def)\n    apply(unfold  writes_on_def, clarsimp)\n    apply (intro conjI)  \n      apply(case_tac \"xa \\<noteq> aa\")\n       apply(simp add: visible_writes_def)\n       apply clarsimp\n       apply(unfold  wfs_def writes_on_def, simp)\n   apply clarsimp\n    apply(simp add: write_trans_def rev_app_def update_thrView_def value_def)\n    apply(simp add: update_mods_def update_thrView_def update_modView_def add_cv_def)\n   apply(intro conjI impI)\n     apply (metis assms(2) last_write_write_on subset_iff visible_var visible_writes_in_writes writes_on_var)\n    apply auto[1]\n   using assms(1,2,4)\n    apply(simp add: covered_v_def)\n   apply(intro allI impI conjI)\n    apply clarsimp\n    apply(unfold  writes_on_def, clarsimp)\n   apply(simp add: visible_writes_def)\n    apply(unfold  writes_on_def, clarsimp)\n    apply clarsimp\n   apply(simp add: visible_writes_def)\n   apply(unfold  writes_on_def value_def, clarsimp)\n   done\n\n\n\n\ncorollary cvd_WrX_other_var_pres:\n  \"wfs \\<sigma> \\<Longrightarrow> cvd[x,u] \\<sigma> \\<Longrightarrow> x\\<noteq>y \\<Longrightarrow> \\<sigma> [y := v]\\<^sub>t \\<sigma>' \\<Longrightarrow> cvd[x,u] \\<sigma>' \"\n  using WrX_def avar.simps(2) covered_diff_var_pres by auto\n\n\ncorollary cvd_WrR_other_var_pres:\n  \"wfs \\<sigma> \\<Longrightarrow> cvd[x,u] \\<sigma> \\<Longrightarrow> x\\<noteq>y \\<Longrightarrow> \\<sigma> [y :=\\<^sup>R v]\\<^sub>t \\<sigma>' \\<Longrightarrow> cvd[x,u] \\<sigma>' \"\n  using WrR_def avar.simps(2) covered_diff_var_pres by auto\n\n\ncorollary cvd_RMW_other_val_pres:\n  \"wfs \\<sigma> \\<Longrightarrow> cvd[x,u] \\<sigma> \\<Longrightarrow> x\\<noteq>y \\<Longrightarrow>  \\<sigma> RMW[y, u, v]\\<^sub>t \\<sigma>' \\<Longrightarrow> cvd[x,u] \\<sigma>' \"\n  using avar.simps(3) covered_diff_var_pres by blast\n\n\ncorollary cvd_RMW_pres:\n  \"wfs \\<sigma> \\<Longrightarrow> cvd[x,u] \\<sigma> \\<Longrightarrow> \\<sigma> RMW[x, z, v]\\<^sub>t \\<sigma>' \\<Longrightarrow> cvd[x,v] \\<sigma>' \"\n  using avar.simps(3) covered_update_v_pres isUp.simps(3) wr_val.simps(2) by blast\n\n\ncorollary cvd_Rdx_pres:\n  \"wfs \\<sigma> \\<Longrightarrow> cvd[x,u] \\<sigma> \\<Longrightarrow> \\<sigma> [a \\<leftarrow> y]\\<^sub>t \\<sigma>' \\<Longrightarrow> cvd[x,u] \\<sigma>' \"\n  by (simp add: RdX_def covered_read_v_pres)\n\ncorollary cvd_RdA_pres:\n  \"wfs \\<sigma> \\<Longrightarrow> cvd[x,u] \\<sigma> \\<Longrightarrow> \\<sigma> [a \\<leftarrow>\\<^sup>A y]\\<^sub>t \\<sigma>' \\<Longrightarrow> cvd[x,u] \\<sigma>' \"\n  by (simp add: RdA_def covered_read_v_pres)\n\n\n\nlemma backward_cvd:\n  assumes \"cvd[x, u] \\<sigma>'\"\n  and \"wfs \\<sigma>\"\n  and \"avar a \\<noteq> x\"\n  and \"step t a \\<sigma> \\<sigma>'\"\n  and \"\\<not>isUp a\"\nshows \"cvd[x, u] \\<sigma>\"\n  apply(rule step_cases[OF assms(4)])\n  using assms (1,2,3)\n    apply(simp add: covered_v_def read_trans_def visible_writes_def rev_app_def Let_def update_thrView_def)\n    apply(unfold writes_on_def)\n    apply clarsimp\n    apply(intro conjI)\n     apply(unfold lastWr_def writes_on_def)\n     apply simp\n    apply(simp add: value_def)\n  using assms(1,2,3)\n  apply(simp add: covered_v_def)\n  apply(case_tac \"lastWr (write_trans t b w v \\<sigma> ts') x \\<noteq> lastWr \\<sigma> x\")\n  apply (metis assms(3) visible_var write_to_different_var)\n   apply simp\n    apply(case_tac \"value (write_trans t b w v \\<sigma> ts') (lastWr \\<sigma> x) \\<noteq> value \\<sigma> (lastWr \\<sigma> x)\")\n  apply (metis avar.simps(2) lastWr_visible value_not_change_write_to_different_var visible_var)\n   apply simp\n   apply(intro allI impI conjI)\n  apply (unfold writes_on_def)\n  apply(elim conjE)\n    apply clarsimp\n  apply(simp add: visible_writes_def)\n  apply (unfold writes_on_def)\n   apply(elim conjE)\n   apply clarsimp\n  using assms(5) by auto\n\n\n\n\n\ncorollary cvd_backwards_WrX:  \n  \"wfs \\<sigma> \\<Longrightarrow> cvd[x, u] \\<sigma>' \\<Longrightarrow> y \\<noteq> x \\<Longrightarrow> \\<sigma> [y := v]\\<^sub>t \\<sigma>' \\<Longrightarrow> cvd[x, u] \\<sigma> \"\n  by (metis WrX_def avar.simps(2) backward_cvd isUp.simps(2))\n\ncorollary cvd_backwards_WrR:\n  \"wfs \\<sigma> \\<Longrightarrow> cvd[x, u] \\<sigma>' \\<Longrightarrow> y \\<noteq> x \\<Longrightarrow> \\<sigma> [y :=\\<^sup>R v]\\<^sub>t \\<sigma>' \\<Longrightarrow> cvd[x, u] \\<sigma> \"\n  by (metis WrR_def avar.simps(2) backward_cvd isUp.simps(2))\n\ncorollary cvd_backwards_RdX:\n  \"wfs \\<sigma> \\<Longrightarrow> cvd[x, u] \\<sigma>' \\<Longrightarrow> y \\<noteq> x \\<Longrightarrow> \\<sigma> [v \\<leftarrow> y]\\<^sub>t \\<sigma>' \\<Longrightarrow> cvd[x, u] \\<sigma> \"\n  by (metis RdX_def avar.simps(1) backward_cvd isUp.simps(1))\n\ncorollary cvd_backwards_RdA:\n  \"wfs \\<sigma> \\<Longrightarrow> cvd[x, u] \\<sigma>' \\<Longrightarrow> y \\<noteq> x \\<Longrightarrow> \\<sigma> [v \\<leftarrow>\\<^sup>A y]\\<^sub>t \\<sigma>' \\<Longrightarrow> cvd[x, u] \\<sigma> \"\n  by (metis RdA_def avar.simps(1) backward_cvd isUp.simps(1))\n\n\n\nlemma not_cvd_pres:\n  assumes \"\\<not>cvd[x, u] \\<sigma>\"\n  and \"wfs \\<sigma>\"\n  and \"step t a \\<sigma> \\<sigma>'\"\n  and \"\\<not>isUp a\"\nshows \"\\<not>cvd[x, u] \\<sigma>'\"\n  apply(rule step_cases[OF assms(3)])\n  using assms(1,2)\n    apply(simp add: covered_v_def visible_writes_def read_trans_def Let_def rev_app_def)\n    apply(simp add: add_cv_def update_mods_def update_modView_def update_thrView_def lastWr_def value_def)\n    apply(unfold wfs_def  writes_on_def)\n    apply simp\n  using assms(1,2)\n  apply(case_tac \"xa \\<noteq> x\")\n  using assms(3) backward_cvd apply force\n    apply(simp add: covered_v_def visible_writes_def write_trans_def Let_def rev_app_def valid_fresh_ts_def)\n    apply(simp add: add_cv_def update_mods_def update_modView_def update_thrView_def lastWr_def value_def)\n   apply(unfold wfs_def  writes_on_def, clarsimp)\n  apply(intro conjI)\n  using neq_iff apply blast\n  apply (metis less_irrefl subsetCE)\n  using assms(4) isUp.simps(3) by blast\n\ncorollary not_cvd_RdX_pres:\n  \"wfs \\<sigma> \\<Longrightarrow> \\<not>cvd[x, u] \\<sigma>  \\<Longrightarrow> \\<sigma> [v \\<leftarrow> y]\\<^sub>t \\<sigma>' \\<Longrightarrow> \\<not>cvd[x, u] \\<sigma>' \"\n  using RdX_def not_cvd_pres by auto\n\ncorollary not_cvd_RdA_pres:\n  \"wfs \\<sigma> \\<Longrightarrow> \\<not>cvd[x, u] \\<sigma>  \\<Longrightarrow> \\<sigma> [v \\<leftarrow>\\<^sup>A y]\\<^sub>t \\<sigma>' \\<Longrightarrow> \\<not>cvd[x, u] \\<sigma>' \"\n  using RdA_def not_cvd_pres by auto\n\n\ncorollary not_cvd_WrX_pres:\n  \"wfs \\<sigma> \\<Longrightarrow> \\<not>cvd[x, u] \\<sigma>  \\<Longrightarrow> \\<sigma> [y := v]\\<^sub>t \\<sigma>' \\<Longrightarrow> \\<not>cvd[x, u] \\<sigma>' \"\n  using WrX_def not_cvd_pres by auto\n\ncorollary not_cvd_WrR_pres:\n  \"wfs \\<sigma> \\<Longrightarrow> \\<not>cvd[x, u] \\<sigma>  \\<Longrightarrow>  \\<sigma> [y :=\\<^sup>R v]\\<^sub>t \\<sigma>' \\<Longrightarrow> \\<not>cvd[x, u] \\<sigma>' \"\n  using WrR_def not_cvd_pres by auto\n\n\n\nlemma cvd_u_not_cvd_v: \"w \\<in> writes_on \\<sigma> x \\<Longrightarrow> w \\<notin> covered \\<sigma> \\<Longrightarrow> value \\<sigma> w = u  \\<Longrightarrow> cvd[x, u] \\<sigma> \\<Longrightarrow> u \\<noteq> v \\<Longrightarrow> \\<not>cvd[x, v]\\<sigma>\"\n  apply(simp add: covered_v_def)\n  by (metis surj_pair)\n\n\nlemma new_update_not_covered:\n  assumes \"wfs \\<sigma>\"\n     and \"w \\<in> visible_writes \\<sigma> t x\"\n     and \"v = value \\<sigma> w\"\n     and \"w \\<notin> covered \\<sigma>\"\n     and \"valid_fresh_ts \\<sigma> w ts'\"\n   shows \"(var w, ts') \\<notin> covered (update_trans t w v' \\<sigma> ts')\"\n  apply(subgoal_tac \"(var w, ts') \\<notin> writes \\<sigma>\")\n  apply(subgoal_tac \"w \\<in> writes \\<sigma>\")\n  apply simp using assms(1)\n  using wfs_def apply fastforce\n  apply (meson assms(2) subsetCE visible_writes_in_writes)\n  by (metis assms(1) assms(5) fst_conv less_irrefl prod.sel(2) tst_def valid_fresh_ts_def var_def wfs_def)\n\nlemma RMW_exist_w_in_post: \"wfs \\<sigma> \\<Longrightarrow> \\<sigma> RMW[x, u, v]\\<^sub>t \\<sigma>' \\<Longrightarrow> \\<exists> w . w \\<in> writes_on \\<sigma>' x \\<and> value \\<sigma>' w = v  \\<and> w \\<notin> covered \\<sigma>'\"\n  apply(simp add:  step_def visible_writes_def valid_fresh_ts_def update_trans_def Let_def rev_app_def)\n  apply(simp add: add_cv_def update_mods_def update_thrView_def update_modView_def value_def)\n  apply(unfold writes_on_def)\n  apply clarsimp \n  by (metis less_irrefl subsetCE wfs_def)\n\n\nlemma update_reads_cvd_v:\n  assumes \"cvd[x, u] \\<sigma>\"\n  and \"isUp a\"\n  and \"avar a = x\"\n  and \"rd_val a = Some v\"\n  and \"wr_val a = Some z\"\n  and \"step t a \\<sigma> \\<sigma>'\"\nshows \"u = v\"\n  apply(rule step_cases[OF assms(6)])\n  using assms(2) isUp.simps(1) apply blast\n  using assms(2) isUp.simps(2) apply blast\n  using assms(1,2,3,4)\n  by (smt covered_v_def mem_Collect_eq option.inject rd_val.simps(2) visible_writes_def)\n\n\ncorollary Up_reads_cvd_v:\n  \"cvd[x, u] \\<sigma>  \\<Longrightarrow>  \\<sigma> RMW[x, v, z]\\<^sub>t \\<sigma>' \\<Longrightarrow> v = u \"\n  using avar.simps(3) isUp.simps(3) rd_val.simps(2) update_reads_cvd_v wr_val.simps(2) by blast\n\n(*****************************************************)\n\ndefinition \"mo w w'\\<equiv> var(w) = var(w') \\<and> tst(w) < tst(w')\" \n\ndefinition \"enc \\<sigma> view x u \\<equiv> \\<exists> w . w \\<in> writes_on \\<sigma> x \\<and> tst(w) \\<le> tst(view x) \\<and> value \\<sigma> w = u\"\n\ndefinition \"enc_t \\<sigma> t x u \\<equiv>  enc \\<sigma> (thrView \\<sigma> t) x u\"\n\ndefinition \"p_vorder \\<sigma> u x v \\<equiv> \\<exists> w w'.  w \\<in> writes_on \\<sigma> x  \\<and>  w' \\<in> writes_on \\<sigma> x \\<and>\n                                        value \\<sigma> w = u \\<and> value \\<sigma> w' = v \\<and>\n                                        mo w w' \"\n\ndefinition \"d_vorder \\<sigma> u x v \\<equiv> (\\<forall> w w'.  w \\<in> writes_on \\<sigma> x  \\<and>  w' \\<in> writes_on \\<sigma> x \\<and>\n                                        value \\<sigma> w = u \\<and> value \\<sigma> w' = v \\<longrightarrow>\n                                        mo w w') \\<and> p_vorder \\<sigma> u x v\"\n\ndefinition \"init_val \\<sigma> x v \\<equiv> \n  \\<exists> w . w \\<in> writes_on \\<sigma> x \\<and> \n        (\\<forall>w'\\<in> writes_on \\<sigma> x .  w \\<noteq> w' \\<longrightarrow>  mo w w') \\<and> \n        value \\<sigma> w = v\"\n\ndefinition \"amo \\<sigma> x u \\<equiv> \\<not> p_vorder \\<sigma> u x u\"\n\ndefinition \"no_val \\<sigma> x i u \\<equiv> init_val \\<sigma> x i \\<and> \\<not> p_vorder \\<sigma> i x u\"\n\ndefinition \"last_val \\<sigma> x u i \\<equiv> \n                init_val \\<sigma> x i \\<and> p_vorder \\<sigma> i x u \n                \\<and> (\\<forall> w. w \\<noteq> u \\<longrightarrow> \\<not> p_vorder \\<sigma> u x w)\"\n\n\n\nabbreviation p_vorder_abbr:: \"V  \\<Rightarrow> L \\<Rightarrow> V \\<Rightarrow>  surrey_state \\<Rightarrow> bool\" (\"[_ \\<leadsto>\\<^sub>_ _] _\" [100,100,100,100])\n  where \"[u \\<leadsto>\\<^sub>x v] \\<sigma> \\<equiv> p_vorder \\<sigma> u x v\"\n\nabbreviation d_vorder_abbr:: \"V  \\<Rightarrow> L \\<Rightarrow> V \\<Rightarrow>  surrey_state \\<Rightarrow> bool\" (\"[_ \\<hookrightarrow>\\<^sub>_ _] _\" [100,100,100,100])\n  where \"[u \\<hookrightarrow>\\<^sub>x v] \\<sigma> \\<equiv> d_vorder \\<sigma> u x v\"\n\nabbreviation amo_abbr:: \"L \\<Rightarrow> V \\<Rightarrow>  surrey_state \\<Rightarrow> bool\" (\"[\\<one>\\<^sub>_ _] _\" [100,100,100])\n  where \"[\\<one>\\<^sub>x u] \\<sigma> \\<equiv> amo \\<sigma> x u\"\n\nabbreviation no_abbr:: \"L \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"[\\<zero>\\<^sub>_ _]\\<^sub>_ _\" [100,100,100,100])\n  where \"[\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma> \\<equiv> no_val \\<sigma> x i u\"\n\nabbreviation enc_abbr:: \"L \\<Rightarrow> V \\<Rightarrow> T \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"[en _ _]\\<^sub>_ _\" [100,100,100,100])\n  where \"[en x u]\\<^sub>t \\<sigma> \\<equiv> enc_t \\<sigma> t x u\"\n\nabbreviation last_abbr:: \"L \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> T \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"[last _ _ _]\\<^sub>_ _\" [100, 100,100,100,100])\n  where \"[last x i u]\\<^sub>t \\<sigma> \\<equiv> last_val \\<sigma> x u i\"\n\nabbreviation init_abbr:: \"L \\<Rightarrow> V  \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"[init _ _] _\" [100, 100,100])\n  where \"[init x v] \\<sigma> \\<equiv> init_val \\<sigma> x v\"\n\nlemmas  opsem_def  =\n  amo_def \n  mo_def\n  d_vorder_def\n  p_vorder_def\n  enc_def\n  enc_t_def\n  no_val_def\n\n\n\n\nlemma pvord_to_dvord:\n  assumes \"p_vorder \\<sigma> u x v\"\n  and \"amo \\<sigma> x u\"\n  and \"amo \\<sigma> x v\"\n  shows \"d_vorder \\<sigma> u x v\"\n  using assms \n  apply(simp add: opsem_def)\n  by (metis fst_conv linorder_neqE_linordered_idom var_def writes_on_var)\n\n\nlemma enc_read_intro:\n  assumes \"isRd a\"\n  and \"avar a = x\"\n  and \"rd_val a = Some v\"\n  and \"step t a \\<sigma> \\<sigma>'\"\nshows \"enc_t \\<sigma>' t x v\"\n  apply(rule step_cases[OF assms(4)])\n  defer \n  using assms(1) apply auto[1]\n  using assms(1) isRd.simps(3) apply blast  apply(simp add: enc_t_def enc_def)\n  apply(case_tac \"va = v\")\n  defer\n  using assms(3) apply auto[1]\n  apply simp\n  apply(elim conjE)\n  apply clarsimp\n  apply(unfold read_trans_def Let_def rev_app_def)\n  apply simp\n  apply(case_tac \"syncing \\<sigma> (aa, b) ba\")\n   defer apply simp\n   apply(simp add: update_thrView_def)\n   apply (rule conjI)\n  apply (smt assms(2) avar.simps(1) mem_Collect_eq order_refl surrey_state.select_convs(4) surrey_state.surjective surrey_state.update_convs(2) value_def visible_writes_def)\n   apply (rule impI) \n   apply(unfold value_def writes_on_def visible_writes_def)\n  apply simp\n  using assms(2) avar.simps(1) apply blast\napply simp\n   apply(simp add: update_thrView_def ts_oride_def)\n   apply (rule conjI)\n  apply blast  \n  using assms(2) avar.simps(1) by blast\n\ncorollary enc_RdX_intro:\n  \"\\<sigma> [v \\<leftarrow> x]\\<^sub>t \\<sigma>' \\<Longrightarrow> [en x v]\\<^sub>t \\<sigma>'\"\n  by (metis RdX_def avar.simps(1) enc_read_intro isRd.simps(1) rd_val.simps(1))\n\ncorollary enc_RdA_intro:\n  \"\\<sigma> [v \\<leftarrow>\\<^sup>A x]\\<^sub>t \\<sigma>' \\<Longrightarrow> [en x v]\\<^sub>t \\<sigma>'\"\n  by (metis RdA_def avar.simps(1) enc_read_intro isRd.simps(1) rd_val.simps(1))\n\n\nlemma enc_write_intro:\n  assumes \"isWr a\"\n  and \"avar a = x\"\n  and \"wr_val a = Some v\"\n  and \"step t a \\<sigma> \\<sigma>'\"\nshows \"enc_t \\<sigma>' t x v\"\n  apply(rule step_cases[OF assms(4)])\n  using assms(1) isWr.simps(1) apply blast\n   defer\n  using assms(1) apply auto[1]\n  apply(simp add: enc_t_def enc_def)\n  apply (elim conjE impE)\n  apply (rule conjI)\n   defer\n  using assms(2) apply auto[1]\n  apply (rule impI)\n  apply simp\n  apply(simp add:  valid_fresh_ts_def)\n  apply (elim conjE)\n  apply clarsimp\n  apply(case_tac \"aa \\<noteq> x\")\n   apply(simp add: visible_writes_def)\n   apply(unfold writes_on_def)\n   apply simp\n  apply clarsimp\n  apply(simp add: write_trans_def rev_app_def value_def)\n  apply(unfold update_thrView_def  add_cv_def update_modView_def update_mods_def)\n  apply clarsimp\n  using assms(3) by auto\n\ncorollary enc_WrX_intro:\n  \"\\<sigma> [x := v]\\<^sub>t \\<sigma>' \\<Longrightarrow> [en x v]\\<^sub>t \\<sigma>'\"\n  by (metis WrX_def avar.simps(2) enc_write_intro isWr.simps(2) wr_val.simps(1))\n\ncorollary enc_WrR_intro:\n  \"\\<sigma> [x :=\\<^sup>R v]\\<^sub>t \\<sigma>' \\<Longrightarrow> [en x v]\\<^sub>t \\<sigma>'\"\n  by (metis WrR_def avar.simps(2) enc_write_intro isWr.simps(2) wr_val.simps(1))\n\n\nlemma enc_update_intro:\n  assumes \"isUp a\"\n  and \"avar a = x\"\n  and \"wr_val a = Some v\"\n  and \"step t a \\<sigma> \\<sigma>'\"\nshows \"enc_t \\<sigma>' t x v\"\n  using assms apply (simp add: enc_t_def step_def enc_def)\n  apply (case_tac \"a\", auto)\n  apply (simp add: update_simps)\n  apply (unfold writes_on_def)\n  apply (simp add: value_def ts_oride_def tst_def)\n  by blast\n\nlemma not_p_vorder_Write__pres:\n  assumes \"\\<not> p_vorder \\<sigma> v x v\"\nand \"isWr a\"\nand \"avar a  = x\"\nand \"wr_val a \\<noteq> Some v\"\nand \"step t a \\<sigma> \\<sigma>'\"\nshows \"\\<not> p_vorder \\<sigma>' v x v\"\n  apply(rule step_cases[OF assms(5)])\n  using assms(2) isWr.simps(1) apply blast\n  defer  \n  using assms(2) isWr.simps(3) apply blast\n  apply (elim conjE)\n  apply(case_tac \"xa = x\")\n   defer\n  using assms(3) apply auto[1]\n  using assms\n  apply(simp add:  valid_fresh_ts_def visible_writes_def opsem_def)\n  apply(unfold writes_on_def)\n  apply simp\n  apply(simp add: write_trans_def rev_app_def)\n  apply(unfold update_thrView_def  add_cv_def update_modView_def update_mods_def value_def)\n  by simp\n\n\n\nlemma amo_intro: \nassumes \"init_val \\<sigma> x u\" \nand \"\\<not> p_vorder \\<sigma> u x v\"\nshows \"amo \\<sigma> x v\"\n  using assms\n  apply (simp add: opsem_def) \n  by (metis assms(2) init_val_def p_vorder_def)\n\nlemma init_val_pres: \nassumes \"[init x u] \\<sigma>\" \nand \"step t action \\<sigma> \\<sigma>'\"\nshows \"init_val \\<sigma>' x u\"\n  using assms\n  apply (auto simp add: step_def)  \n  apply (cases action, auto)\n  apply (auto simp add: init_val_def)[1]  \n  apply (metis read_trans_def rev_app_def surrey_state.select_convs(4) surrey_state.surjective surrey_state.update_convs(2) update_thrView_def value_def)\n  apply (auto simp add: init_val_def)[1]  \n  apply (simp add: valid_fresh_ts_def update_thrView_def write_trans_def rev_app_def add_cv_def update_mods_def update_modView_def)  \n  apply (simp add: visible_writes_def tst_def value_def var_def writes_on_def)\n  apply (metis (no_types, lifting) fst_conv less_trans mo_def not_less_iff_gr_or_eq snd_conv tst_def var_def)\n  proof -\n  fix a b y v ts'\n  assume a1: \"init_val \\<sigma> x u\"  and\n         a2: \"(a, b) \\<in> visible_writes \\<sigma> t y\" and \n         a5: \"valid_fresh_ts \\<sigma> (a, b) ts'\" (*and *)\n  show \"init_val (update_trans t (a, b) v \\<sigma> ts') x u\"\n    using a1 a2 a5  \n  apply (simp add: update_trans_def)\n    apply (auto simp add: init_val_def value_def valid_fresh_ts_def  rev_app_def add_cv_def update_mods_def update_thrView_def update_modView_def)\n    by (smt fst_conv fun_upd_other insert_iff less_trans mem_Collect_eq mo_def not_less_iff_gr_or_eq snd_conv surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(1) surrey_state.update_convs(2) surrey_state.update_convs(3) surrey_state.update_convs(4) surrey_state.update_convs(5) tst_def var_def visible_writes_def writes_on_def)  \nqed\n\n\nlemma amo_intro_step: \n  assumes \"init_val \\<sigma> x u\" \n  and \"u \\<noteq> v\"\n  and \"\\<not> p_vorder \\<sigma> u x v\"\n  and \"step t action \\<sigma> \\<sigma>'\"\n  shows \"amo \\<sigma>' x v\"\n  using assms\n  apply (simp add: opsem_def step_def)\n  apply (intro impI allI conjI)\n  apply (elim conjE exE)\n  apply (cases action, auto)\n    apply (auto simp add: update_thrView_def value_def read_trans_def init_val_def rev_app_def)\n    apply (metis (no_types, lifting) fst_conv mo_def snd_conv surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(2) tst_def var_def)\n    apply (auto simp add:  write_trans_def rev_app_def add_cv_def update_mods_def)\n  apply (smt dual_order.irrefl fst_conv insert_compr mem_Collect_eq mo_def snd_conv surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(1) surrey_state.update_convs(2) surrey_state.update_convs(3) surrey_state.update_convs(4) surrey_state.update_convs(5) tst_def update_modView_def update_thrView_def var_def writes_on_def)\n    apply (auto simp add:  update_trans_def rev_app_def add_cv_def update_mods_def)\n    apply (auto simp add: valid_fresh_ts_def init_val_def write_trans_def rev_app_def update_thrView_def update_modView_def add_cv_def update_mods_def)\n  by (smt dual_order.irrefl fst_conv fun_upd_other insert_compr mem_Collect_eq mo_def snd_conv surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(1) surrey_state.update_convs(4) surrey_state.update_convs(5) tst_def var_def writes_on_def)\n\nlemma not_pvorder_pres_step_wr: \nassumes \"init_val \\<sigma> x u\" \nand \"\\<not> p_vorder \\<sigma> u x v\"\nand \"isWr action\"\nand \"wr_val action \\<noteq> Some v\"\nand \"wr_val action \\<noteq> Some u\"\nand \"step t action \\<sigma> \\<sigma>'\"\nshows \"\\<not> p_vorder \\<sigma>' u x v\"\n  using assms\n  apply (simp add: step_def opsem_def) \n  apply (intro allI impI)\n  apply (elim exE)\n  apply (cases \"action\", auto)\n  apply (auto simp add: update_thrView_def value_def fun_upd_other write_trans_def rev_app_def add_cv_def valid_fresh_ts_def init_val_def update_modView_def update_mods_def)\n  by (smt Pair_inject insert_iff mem_Collect_eq surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(1) surrey_state.update_convs(4) surrey_state.update_convs(5) write_record.ext_inject write_record.surjective writes_on_def)\n  \n\nlemma amo_pres_step_wr: \nassumes \"amo \\<sigma> x v\"\nand \"isWr action\" \nand \"wr_val action \\<noteq> Some v\"\nand \"step t action \\<sigma> \\<sigma>'\"\nshows \"amo \\<sigma>' x v\"\n  apply(rule step_cases[OF assms(4)])\n  using assms(2) apply auto[1]\n  using assms\n  apply(simp add: valid_fresh_ts_def visible_writes_def write_trans_def rev_app_def)\n   apply(simp add: add_cv_def update_mods_def update_thrView_def update_modView_def)\n   apply(elim conjE)\n   apply(simp add: opsem_def init_val_def value_def)\n   apply(unfold writes_on_def, simp)\n  using assms(2) isWr.simps(3) by blast\n\ncorollary amo_Wr_diff_val_pres:  \n  \"[\\<one>\\<^sub>x u] \\<sigma>  \\<Longrightarrow> u \\<noteq> v \\<Longrightarrow>  \\<sigma> [y := v]\\<^sub>t \\<sigma>' \\<Longrightarrow> [\\<one>\\<^sub>x u] \\<sigma>'\"\n  by (metis WrX_def amo_pres_step_wr isWr.simps(2) option.inject wr_val.simps(1))\n\ncorollary amo_WrR_diff_val_pres:  \n  \"[\\<one>\\<^sub>x u] \\<sigma>  \\<Longrightarrow> u \\<noteq> v \\<Longrightarrow>  \\<sigma> [y :=\\<^sup>R v]\\<^sub>t \\<sigma>' \\<Longrightarrow> [\\<one>\\<^sub>x u] \\<sigma>'\"\n  by (metis WrR_def amo_pres_step_wr isWr.simps(2) option.inject wr_val.simps(1))\n\n\n\nlemma amo_write_pres: \nassumes \"amo \\<sigma> x v\"\nand \"isWr action\" \nand \"avar action \\<noteq> x\"\nand \"step t action \\<sigma> \\<sigma>'\"\nshows \"amo \\<sigma>' x v\"\n  apply(rule step_cases[OF assms(4)])\n  using assms(2) apply auto[1] defer\n  using assms(2) apply auto[1]\n  using assms(1,2,3)\n  apply(simp add: valid_fresh_ts_def visible_writes_def write_trans_def rev_app_def)\n   apply(simp add: add_cv_def update_mods_def update_thrView_def update_modView_def)\n   apply(elim conjE)\n   apply(simp add: opsem_def init_val_def value_def)\n   by(unfold writes_on_def, simp)\n\ncorollary amo_WrX_pres:  \n  \"[\\<one>\\<^sub>x u] \\<sigma>  \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow>  \\<sigma> [y := v]\\<^sub>t \\<sigma>' \\<Longrightarrow> [\\<one>\\<^sub>x u] \\<sigma>'\"\n  by (metis WrX_def amo_write_pres avar.simps(2) isWr.simps(2))\n\ncorollary amo_WrR_pres:  \n  \"[\\<one>\\<^sub>x u] \\<sigma>  \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow>  \\<sigma> [y :=\\<^sup>R v]\\<^sub>t \\<sigma>' \\<Longrightarrow> [\\<one>\\<^sub>x u] \\<sigma>'\"\n  by (metis WrR_def amo_write_pres avar.simps(2) isWr.simps(2))\n\nlemma amo_update_pres: \nassumes \"amo \\<sigma> x v\"\nand \"isUp action\" \nand \"avar action \\<noteq> x\"\nand \"step t action \\<sigma> \\<sigma>'\"\nshows \"amo \\<sigma>' x v\"\n  apply(rule step_cases[OF assms(4)])\n  using assms(2) apply auto[2] \n  using assms(2) apply auto[1]\n  using assms(1,2,3)\n  apply(simp add: valid_fresh_ts_def visible_writes_def update_trans_def rev_app_def)\n   apply(elim conjE)\n   apply(simp add: Let_def opsem_def init_val_def value_def)\n   apply (case_tac \"releasing \\<sigma> (a, b)\", auto)\n  apply (simp add: tst_def var_def ts_oride_def add_cv_def update_mods_def update_modView_def update_thrView_def)\n    apply (unfold writes_on_def, simp)\n  apply blast\n  apply (simp add: tst_def var_def ts_oride_def add_cv_def update_mods_def update_modView_def update_thrView_def)\n  by blast\n\n\ncorollary amo_Up_pres:  \n  \"[\\<one>\\<^sub>x u] \\<sigma>  \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow>  \\<sigma> RMW[y, v, w]\\<^sub>t \\<sigma>' \\<Longrightarrow> [\\<one>\\<^sub>x u] \\<sigma>'\"\n  using amo_update_pres by force\n\n\nlemma amo_read_pres: \nassumes \"amo \\<sigma> x v\"\nand \"isRd action\" \nand \"step t action \\<sigma> \\<sigma>'\"\nshows \"amo \\<sigma>' x v\"\n  apply(rule step_cases[OF assms(3)])\n  defer \n  using assms(2) apply auto[1]\n  using assms(2) apply auto[1]\n  using assms\n  apply(unfold opsem_def read_trans_def Let_def rev_app_def writes_on_def update_thrView_def visible_writes_def value_def)\n  by clarsimp\n\ncorollary amo_RdX_pres:  \n  \"[\\<one>\\<^sub>x u] \\<sigma>  \\<Longrightarrow> \\<sigma> [v \\<leftarrow> y]\\<^sub>t \\<sigma>' \\<Longrightarrow> [\\<one>\\<^sub>x u] \\<sigma>'\"\n  by (metis RdX_def amo_read_pres isRd.simps(1))\n\ncorollary amo_RdA_pres:  \n  \"[\\<one>\\<^sub>x u] \\<sigma>  \\<Longrightarrow> \\<sigma> [v \\<leftarrow>\\<^sup>A y]\\<^sub>t \\<sigma>' \\<Longrightarrow> [\\<one>\\<^sub>x u] \\<sigma>'\"\n  by (metis RdA_def amo_read_pres isRd.simps(1))\n\nlemma d_vorder_intro:\n  assumes \"step t action \\<sigma> \\<sigma>'\"\n and \"p_vorder \\<sigma> u x v\" \n and \"[init x v'] \\<sigma>\"\n and np: \"\\<not> p_vorder \\<sigma> v' x v\" \nshows \"d_vorder \\<sigma>' u x v\"\n  using assms\n  apply (simp add: opsem_def)\n  apply (intro conjI allI impI)  \n  apply (metis fst_conv var_def writes_on_var)\n  apply (metis np init_val_def less_imp_not_less mo_def p_vorder_def snd_conv tst_def)\n  by (metis np init_val_def less_imp_not_less mo_def p_vorder_def snd_conv tst_def)\n\nlemma d_vorder_intro_w: \n  assumes \"enc_t \\<sigma> t xv u\"\nand \"init_val  \\<sigma> xv z\"\nand \"amo \\<sigma> xv u\"\nand \"\\<not> p_vorder  \\<sigma> z xv v\"\nand \"amo \\<sigma> xv v\"\nand \"v \\<noteq> u\"\nand \"v \\<noteq> z\"\nand \"u  \\<noteq> z\"\nand \"avar action = xv\"\nand \"wr_val action = Some v\"\nand \"step t action  \\<sigma> \\<sigma>'\"\nand \"isWr action\"\nshows \"d_vorder  \\<sigma>' u xv v\"\n  apply(rule step_cases[OF assms(11)])\n  using assms(10) apply auto[1]\n   defer\n  using assms(12) apply auto[1]\n  using assms(1, 2, 3,4,5,6,7,8,9,10,12)\n  apply clarsimp\n  apply(simp add: opsem_def write_trans_def rev_app_def init_val_def valid_fresh_ts_def visible_writes_def)\n  apply(simp add: add_cv_def update_modView_def update_thrView_def update_mods_def value_def)\n  apply(unfold writes_on_def)\n  apply clarsimp\n  apply(intro conjI)\n   apply clarsimp\n   apply(intro conjI impI)\n  apply clarsimp\n  apply(case_tac \"bb = bd\")\n  apply linarith\n  apply(case_tac \"bb = bc\")\n     apply blast\n    apply (metis linorder_cases)\n    apply metis\n    by (metis dual_order.strict_trans2)\n\n(*  assumes \"enc_t \\<sigma> t xv u\" enc_t \\<sigma> t x u\nand \"init_val  \\<sigma> xv z\" [\\<zero>\\<^sub>x u]\\<^sub>z \\<sigma>\nand \"amo \\<sigma> xv u\" [\\<one>\\<^sub>x u] \\<sigma>\nand \"\\<not> p_vorder  \\<sigma> z xv v\" [\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>\nand \"amo \\<sigma> xv v\" [\\<one>\\<^sub>x v] \\<sigma>\nand \"v \\<noteq> u\"\nand \"v \\<noteq> z\"\nand \"u  \\<noteq> z\"\nand \"avar action = xv\"\nand \"wr_val action = Some v\"\nand \"step t action  \\<sigma> \\<sigma>'\"\nand \"isWr action\"\nshows \"d_vorder  \\<sigma>' u xv v\"\n*)\n\ncorollary WrX_d_vorder:  \n  \"[\\<zero>\\<^sub>x v]\\<^sub>z \\<sigma> \\<Longrightarrow> [\\<one>\\<^sub>x u] \\<sigma> \\<Longrightarrow> [\\<one>\\<^sub>x v] \\<sigma> \\<Longrightarrow> [en x u]\\<^sub>t \\<sigma> \\<Longrightarrow> u \\<noteq> z \\<Longrightarrow> v \\<noteq> u \\<Longrightarrow> v \\<noteq> z  \\<Longrightarrow> \\<sigma> [x := v]\\<^sub>t \\<sigma>' \\<Longrightarrow>  [u \\<hookrightarrow>\\<^sub>x v] \\<sigma>'\"\n  by (metis WrX_def avar.simps(2) d_vorder_intro_w isWr.simps(2) no_val_def wr_val.simps(1))\n\ncorollary WrR_d_vorder:  \n  \"[\\<zero>\\<^sub>x v]\\<^sub>z \\<sigma> \\<Longrightarrow> [\\<one>\\<^sub>x u] \\<sigma> \\<Longrightarrow> [\\<one>\\<^sub>x v] \\<sigma> \\<Longrightarrow> [en x u]\\<^sub>t \\<sigma> \\<Longrightarrow> u \\<noteq> z \\<Longrightarrow> v \\<noteq> u \\<Longrightarrow> v \\<noteq> z  \\<Longrightarrow> \\<sigma> [x :=\\<^sup>R v]\\<^sub>t \\<sigma>' \\<Longrightarrow>  [u \\<hookrightarrow>\\<^sub>x v] \\<sigma>'\"\n  by (metis WrR_def avar.simps(2) d_vorder_intro_w isWr.simps(2) no_val_def wr_val.simps(1))\n\n\nlemma d_vorder_one_way:\n  assumes \"d_vorder \\<sigma> u x v\" \nshows \"\\<not> d_vorder \\<sigma> v x u\"\n  using assms\n  apply (unfold opsem_def, safe)\n  using not_less_iff_gr_or_eq by blast\n\n\nlemma enc_read_p_vorder1:\n  assumes \"enc_t \\<sigma> t xv v\"\nand \"isRd action\"\nand \"avar action = xv\"\nand \"rd_val action = Some u\"\nand \"step t action \\<sigma> \\<sigma>'\"\nshows \"v \\<noteq> u \\<longrightarrow> p_vorder \\<sigma> v xv u\"\n  apply(rule step_cases[OF assms(5)])\n  using assms\n  apply(unfold opsem_def read_trans_def Let_def rev_app_def writes_on_def update_thrView_def visible_writes_def)\n    apply simp\n    apply(case_tac \"syncing \\<sigma> w b\")\n     apply simp\n     apply (elim conjE)\n  apply(intro impI)\n     apply simp\n  apply(case_tac \"v = u\")\n      apply linarith\n     apply clarsimp\n  using le_neq_trans apply fastforce\n  apply (metis dual_order.trans order.not_eq_order_implies_strict prod.collapse tst_def var_def)\n  using isRd.simps(2) apply blast\n  using isRd.simps(3) by blast\n\n\nlemma enc_read_p_vorder:\n  assumes \"enc_t \\<sigma> t xv v\"\nand \"isRd action\"\nand \"avar action = xv\"\nand \"rd_val action = Some u\"\nand \"step t action \\<sigma> \\<sigma>'\"\nshows \"v \\<noteq> u \\<longrightarrow> p_vorder \\<sigma>' v xv u\"\n  apply(rule step_cases[OF assms(5)])\n    defer\n  using assms(2) apply auto[2]\n  using assms(1,2,3,4)\n  apply(unfold opsem_def read_trans_def Let_def rev_app_def writes_on_def update_thrView_def visible_writes_def)\n  apply simp\n    apply(case_tac \"syncing \\<sigma> w b\")\n     apply simp\n     apply (elim conjE)\n  apply(intro impI)\n     apply (simp_all add: value_def)\n  apply(case_tac \"v = u\")\n      apply linarith\n     apply clarsimp\n  using less_eq_rat_def apply fastforce\n  by (metis dual_order.trans order.not_eq_order_implies_strict prod.collapse tst_def var_def)\n  \n\ncorollary enc_RdA_p_vorder:  \n  \"[en x v]\\<^sub>t \\<sigma> \\<Longrightarrow> \\<sigma> [u \\<leftarrow>\\<^sup>A x]\\<^sub>t \\<sigma>' \\<Longrightarrow> v \\<noteq> u \\<longrightarrow> [v \\<leadsto>\\<^sub>x u] \\<sigma>'\"\n  by (metis RdA_def avar.simps(1) enc_read_p_vorder isRd.simps(1) rd_val.simps(1))\n\ncorollary enc_Rdx_p_vorder:  \n  \"[en x v]\\<^sub>t \\<sigma> \\<Longrightarrow> \\<sigma> [u \\<leftarrow> x]\\<^sub>t \\<sigma>' \\<Longrightarrow> v \\<noteq> u \\<longrightarrow> [v \\<leadsto>\\<^sub>x u] \\<sigma>'\"\n  by (metis RdX_def avar.simps(1) enc_read_p_vorder isRd.simps(1) rd_val.simps(1))\n\nlemma p_vorder_write_pres:\n  assumes \"p_vorder \\<sigma> v xv u\"\n    and \"isWr action\"\n    and \"step t action \\<sigma> \\<sigma>'\"\n  shows \"p_vorder \\<sigma>' v xv u\"\n  apply(rule step_cases[OF assms(3)])\n  using assms(2) isWr.simps(1) apply blast\n  using assms\n   apply(simp add: opsem_def value_def write_trans_def rev_app_def visible_writes_def update_thrView_def)\n   apply(simp add: update_modView_def update_mods_def add_cv_def)\n   apply(unfold writes_on_def valid_fresh_ts_def)\n   apply(elim conjE)\n   apply clarsimp\n  apply (metis (full_types) dual_order.irrefl)\n  using assms(2) isWr.simps(3) by blast\n\ncorollary p_vorder_WrX_p_vorder:  \n  \" [v \\<leadsto>\\<^sub>x u] \\<sigma> \\<Longrightarrow> \\<sigma> [y := z]\\<^sub>t \\<sigma>' \\<Longrightarrow> [v \\<leadsto>\\<^sub>x u] \\<sigma>'\"\n  by (metis WrX_def isWr.simps(2) p_vorder_write_pres)\n\n\ncorollary p_vorder_WrR_p_vorder:  \n  \" [v \\<leadsto>\\<^sub>x u] \\<sigma> \\<Longrightarrow> \\<sigma> [y :=\\<^sup>R z]\\<^sub>t \\<sigma>' \\<Longrightarrow> [v \\<leadsto>\\<^sub>x u] \\<sigma>'\"\n  by (metis WrR_def isWr.simps(2) p_vorder_write_pres)\n\n\nlemma read_pres_not_p_vorder:\n  assumes \"\\<not> p_vorder \\<sigma> v xv u\"\n  and \"isRd action\"\n  and \"step t action \\<sigma> \\<sigma>'\"\n  shows \"\\<not> p_vorder \\<sigma>' v xv u\"\n  apply(rule step_cases[OF assms(3)])\n    defer\n  using assms(2) apply auto[2]\n  using assms\n  by(simp add: opsem_def value_def)\n\nlemma read_pres_p_vorder:\n  assumes \"p_vorder \\<sigma> v xv u\"\n  and \"isRd action\"\n  and \"step t action \\<sigma> \\<sigma>'\"\n  shows \"p_vorder \\<sigma>' v xv u\"\n  apply(rule step_cases[OF assms(3)])\n    defer\n  using assms(2) apply auto[1]\n  using assms(2) apply auto[1]\n  using assms\n  by(simp add: opsem_def value_def)\n\n\ncorollary p_vorder_RdX_p_vorder:  \n  \" [v \\<leadsto>\\<^sub>x u] \\<sigma> \\<Longrightarrow> \\<sigma> [z \\<leftarrow> y]\\<^sub>t \\<sigma>' \\<Longrightarrow> [v \\<leadsto>\\<^sub>x u] \\<sigma>'\"\n  by (metis (full_types) RdX_def isRd.simps(1) read_pres_p_vorder)\n\n\ncorollary p_vorder_RdA_p_vorder:  \n  \" [v \\<leadsto>\\<^sub>x u] \\<sigma> \\<Longrightarrow> \\<sigma> [z \\<leftarrow>\\<^sup>A y]\\<^sub>t \\<sigma>' \\<Longrightarrow> [v \\<leadsto>\\<^sub>x u] \\<sigma>'\"\n  by (metis (full_types) RdA_def isRd.simps(1) read_pres_p_vorder)\n\n\n\nlemma d_vorder_Read_pres:\n  assumes \"d_vorder \\<sigma> v x u\"\n  and \"isRd action\"\n  and \"step t action \\<sigma> \\<sigma>'\"\n  shows \"d_vorder \\<sigma>' v x u\"\n  apply(rule step_cases[OF assms(3)])\n    defer\n  using assms(2) apply auto[1]\n  using assms(2) apply auto[1]\n  using assms\n  apply(simp add: d_vorder_def)\n  apply(simp add: value_def)\n  apply(unfold opsem_def read_trans_def writes_on_def rev_app_def Let_def, simp)\n  apply(elim conjE)\n  apply(case_tac \"syncing \\<sigma> w b\", simp)\n  apply (simp add: update_thrView_def value_def)\n  by (simp add: update_thrView_def value_def)\n\ncorollary d_vorder_RdX_pres:  \n  \" [v \\<hookrightarrow>\\<^sub>x u] \\<sigma> \\<Longrightarrow> \\<sigma> [z \\<leftarrow> y]\\<^sub>t \\<sigma>' \\<Longrightarrow> [v \\<hookrightarrow>\\<^sub>x u] \\<sigma>'\"  \n  by (metis RdX_def isRd.simps(1) d_vorder_Read_pres)\n\n\ncorollary d_vorder_RdA_pres:  \n  \" [v \\<hookrightarrow>\\<^sub>x u] \\<sigma> \\<Longrightarrow> \\<sigma> [z \\<leftarrow>\\<^sup>A y]\\<^sub>t \\<sigma>' \\<Longrightarrow> [v \\<hookrightarrow>\\<^sub>x u] \\<sigma>'\"\n  by (metis RdA_def isRd.simps(1) d_vorder_Read_pres)\n\n\nlemma d_vorder_Write_pres:\n  assumes \"d_vorder \\<sigma> v x u\"\n    and \"step t a \\<sigma> \\<sigma>'\"\n    and \"isWr a\"\n    and \"wr_val a \\<noteq> Some v\"\n    and \"wr_val a \\<noteq> Some u\"\n    and \"avar a = x\"\n shows \"d_vorder \\<sigma>' v x u\"\n  apply(rule step_cases[OF assms(2)])\n  using assms(3) apply auto[1] defer\n  using assms(3) isWr.simps(3) apply blast\n  using assms(1,3,4,5,6)\n  apply simp\n  apply(elim conjE)\n  apply clarsimp\n  apply(simp add: d_vorder_def)\n  apply(intro conjI)\n   apply clarsimp apply auto\n   apply (smt UnE fun_upd_def mem_Collect_eq rev_app_def singletonD surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(1) surrey_state.update_convs(2) surrey_state.update_convs(3) surrey_state.update_convs(4) surrey_state.update_convs(5) update_modView_def update_mods_def update_thrView_def add_cv_def value_def write_record.ext_inject write_record.surjective write_trans_def writes_on_def)\n  using assms(2) assms(3) p_vorder_write_pres by blast\n\n\ncorollary d_vorder_WrX_pres:  \n  \" [v \\<hookrightarrow>\\<^sub>x u] \\<sigma> \\<Longrightarrow> \\<sigma> [x := w]\\<^sub>t \\<sigma>' \\<Longrightarrow> w \\<noteq> u \\<Longrightarrow> w \\<noteq> v \\<Longrightarrow> [v \\<hookrightarrow>\\<^sub>x u] \\<sigma>'\"  \n  by (simp add: WrX_def d_vorder_Write_pres)\n\ncorollary d_vorder_WrR_pres:  \n  \" [v \\<hookrightarrow>\\<^sub>x u] \\<sigma> \\<Longrightarrow> \\<sigma> [x :=\\<^sup>R w]\\<^sub>t \\<sigma>' \\<Longrightarrow> w \\<noteq> u \\<Longrightarrow> w \\<noteq> v \\<Longrightarrow> [v \\<hookrightarrow>\\<^sub>x u] \\<sigma>'\"  \n  by (simp add: WrR_def d_vorder_Write_pres)\n\n\nlemma enc_pres:\n  assumes \"enc_t \\<sigma> t xv u\"\n  and \"step t' action \\<sigma> \\<sigma>'\"\n  shows \"enc_t \\<sigma>' t xv u\"\n  apply(rule step_cases[OF assms(2)])\n  using assms \n  apply simp\n  apply(simp add: enc_t_def enc_def visible_writes_def read_trans_def Let_def rev_app_def update_thrView_def ts_oride_def)\n  apply(case_tac \"syncing \\<sigma> w b\")\n  apply (unfold writes_on_def) \n  apply clarsimp \n  apply(auto simp add: tst_def value_def enc_t_def enc_def visible_writes_def read_trans_def Let_def rev_app_def update_thrView_def ts_oride_def)\n  using assms \n  apply(simp add: enc_t_def enc_def visible_writes_def write_trans_def Let_def rev_app_def update_thrView_def ts_oride_def)\n  apply (unfold writes_on_def) \n   apply clarsimp \n  apply(auto simp add: tst_def value_def enc_t_def enc_def visible_writes_def read_trans_def Let_def rev_app_def update_thrView_def ts_oride_def)[1]\n  apply(auto simp add: add_cv_def update_mods_def update_modView_def)\n  apply (metis dual_order.strict_implies_order dual_order.trans not_le snd_conv tst_def valid_fresh_ts_def)\n  apply (smt fst_conv mem_Collect_eq not_less_iff_gr_or_eq snd_conv tst_def valid_fresh_ts_def var_def writes_on_def)\n  using assms\n  apply(simp add: enc_t_def enc_def visible_writes_def update_trans_def Let_def rev_app_def update_thrView_def ts_oride_def)\n  apply(auto simp add: add_cv_def valid_fresh_ts_def update_mods_def  tst_def value_def enc_t_def enc_def visible_writes_def read_trans_def Let_def rev_app_def update_thrView_def ts_oride_def)\n  apply (unfold writes_on_def) \n  apply auto\n  apply (unfold update_modView_def, clarsimp) \n  apply (smt dual_order.irrefl dual_order.strict_implies_order dual_order.trans fun_upd_same fun_upd_triv fun_upd_twist snd_conv ts_oride_def tst_def)\n  apply auto\n  apply (metis leD less_imp_le order_trans)\n  by (metis leD order_refl)\n\n\nlemma enc_pvord_step:\n  \"enc_t \\<sigma> t xv u \\<Longrightarrow> \n   isRd action \\<Longrightarrow> \n   avar action = xv \\<Longrightarrow>\n   rd_val action = Some v \\<Longrightarrow>\n   step t action \\<sigma> \\<sigma>' \\<Longrightarrow> u \\<noteq> v\\<Longrightarrow> p_vorder \\<sigma>' u xv v\"\n  apply (frule enc_read_p_vorder[where action = action]) \n  by blast+ \n\n\n\nlemma no_val_read_pres:\n  assumes \"[\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>\"\n  and \"isRd a\"\n  and \"step t a \\<sigma> \\<sigma>'\"\n  shows \"[\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>'\"\n  by (meson assms(1) assms(2) assms(3) init_val_pres no_val_def read_pres_not_p_vorder)\n\ncorollary no_val_RdA_pres:  \n  \" [\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma> \\<Longrightarrow> \\<sigma> [r \\<leftarrow>\\<^sup>A y]\\<^sub>t \\<sigma>' \\<Longrightarrow> [\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>'\"\n  using  no_val_read_pres \n  by (metis RdA_def isRd.simps(1))\n\ncorollary no_val_Rdx_pres:  \n  \" [\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma> \\<Longrightarrow> \\<sigma> [r \\<leftarrow> y]\\<^sub>t \\<sigma>' \\<Longrightarrow> [\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>'\"\n  using  no_val_read_pres \n  by (metis RdX_def isRd.simps(1))\n\nlemma write_no_val:\n  assumes \"wr_val a = Some u\"\n   and \"[init x i] \\<sigma>\"\n  and \"avar a = x\"\n  and \"isWr a\"\n  and \"step t a \\<sigma> \\<sigma>'\"\nshows \"\\<not>[\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>'\"\n  apply(rule step_cases[OF assms(5)])\n  using assms(4) apply auto[1]\n  using assms(1,2,3,4)\n   apply(simp add:  opsem_def init_val_def visible_writes_def valid_fresh_ts_def value_def)\n   apply(simp add: write_trans_def rev_app_def add_cv_def update_mods_def update_modView_def update_thrView_def)\n   apply(unfold writes_on_def)\n   apply(elim conjE)\n   apply clarsimp\n  using order.asym apply blast\n    using assms(4) by auto\n\ncorollary WrX_no_val:  \n  \"[init x i] \\<sigma> \\<Longrightarrow> \\<sigma> [x := u]\\<^sub>t \\<sigma>' \\<Longrightarrow> \\<not>[\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>'\"\n  using  write_no_val \n  by (metis WrX_def avar.simps(2) isWr.simps(2) wr_val.simps(1))\n\nlemma no_val_write_diff_value_pres:\n  assumes \"[\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>\"\n  and \"isWr a\"\n  and \"wr_val a \\<noteq> Some u\"\n  and \"step t a \\<sigma> \\<sigma>'\"\nshows \"[\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>'\"\n  apply(rule step_cases[OF assms(4)])\n  using assms(2) apply auto[1]\n  using assms(1)\n   apply(elim conjE)\n   apply(simp add:  opsem_def init_val_def visible_writes_def valid_fresh_ts_def value_def)\n   apply(simp add: write_trans_def rev_app_def add_cv_def update_mods_def update_modView_def update_thrView_def)\n   apply(unfold writes_on_def)\n  apply(elim conjE, intro conjI)\n    apply simp\n    apply(elim conjE)\n    apply clarsimp\n    apply (smt less_trans order.asym)\n    apply clarsimp\n  using assms(3) apply auto[1]\n  using assms(2) by auto\n\n\ncorollary no_val_WrX_diff_val_pres:  \n  \" [\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma> \\<Longrightarrow> v \\<noteq> u \\<Longrightarrow> \\<sigma> [y := v]\\<^sub>t \\<sigma>' \\<Longrightarrow> [\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>'\"\n  by (metis WrX_def isWr.simps(2) no_val_write_diff_value_pres option.sel wr_val.simps(1))\n\ncorollary no_val_WrR_diff_val_pres:  \n  \" [\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma> \\<Longrightarrow> v \\<noteq> u \\<Longrightarrow> \\<sigma> [y :=\\<^sup>R v]\\<^sub>t \\<sigma>' \\<Longrightarrow> [\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>'\"\n  by (metis WrR_def isWr.simps(2) no_val_write_diff_value_pres option.sel wr_val.simps(1))\n\nlemma no_val_write_diff_var_pres:\n  assumes \"[\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>\"\n  and \"isWr a\"\n  and \"avar a \\<noteq> x\"\n  and \"step t a \\<sigma> \\<sigma>'\"\nshows \"[\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>'\"\n  apply(rule step_cases[OF assms(4)])\n  using assms(2) apply auto[1]\n  using assms(1)\n   apply(elim conjE)\n   apply(simp add:  opsem_def init_val_def visible_writes_def valid_fresh_ts_def value_def)\n   apply(simp add: write_trans_def rev_app_def add_cv_def update_mods_def update_modView_def update_thrView_def)\n   apply(unfold writes_on_def)\n  apply(elim conjE, intro conjI)\n    apply simp\n    apply(elim conjE)\n    apply clarsimp\n    apply (smt less_trans order.asym)\n    apply clarsimp\n  using assms(3) apply auto[1]\n  using assms(2) by auto\n\ncorollary no_val_Wr_diff_var_pres:  \n  \" [\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma> \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow> \\<sigma> [y := v]\\<^sub>t \\<sigma>' \\<Longrightarrow> [\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>'\"\n  by (metis WrX_def avar.simps(2) isWr.simps(2) no_val_write_diff_var_pres)\n\ncorollary no_val_WrR_diff_var_pres:  \n  \" [\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma> \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow> \\<sigma> [y :=\\<^sup>R v]\\<^sub>t \\<sigma>' \\<Longrightarrow> [\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>'\"\n  by (metis WrR_def avar.simps(2) isWr.simps(2) no_val_write_diff_var_pres)\n\n\nlemma d_obs_enc: \"wfs \\<sigma> \\<Longrightarrow> d_obs_t \\<sigma> t x v \\<Longrightarrow> enc_t \\<sigma> t x v\"\n    apply(simp add: opsem_def d_obs_t_def d_obs_def lastWr_def value_def)\n  apply(unfold wfs_def writes_on_def) apply simp\n  apply(elim conjE)\n  by (metis (no_types, lifting) less_eq_rat_def) \n\n\nlemma no_val_Update_diff_var_pres:\n  assumes \"[\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>\"\n  and \"isUp a\"\n  and \"avar a \\<noteq> x\"\n  and \"step t a \\<sigma> \\<sigma>'\"\nshows \"[\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>'\"\n  apply(rule step_cases[OF assms(4)])\n  using assms(2) apply auto[1]\n  using assms(2) apply auto[1]\n  using assms(1)\n   apply(elim conjE)\n   apply(simp add: update_simps opsem_def)\n  apply(unfold writes_on_def)\n  apply clarsimp\n  apply (intro conjI impI)\n   apply(simp add: releasing_def tst_def )\n  using assms(4) init_val_pres apply blast\n  apply clarsimp\n  apply (intro conjI impI)\n   apply(simp add: releasing_def tst_def )\n  using assms(3) avar.simps(3) apply blast\n  apply clarsimp\n  apply (intro conjI impI)\n   apply(simp add: releasing_def tst_def )\n  using assms(3) avar.simps(3) apply blast\n    apply(simp add: releasing_def ts_oride_def tst_def value_def)\n  apply auto\n  using assms(3) apply auto[1]\n  using assms(4) init_val_pres apply blast\n  using assms(3) avar.simps(3) apply blast\n  using assms(3) avar.simps(3) apply blast\n    apply(simp add: releasing_def ts_oride_def tst_def value_def)\n  using assms(3) by auto\n\ncorollary no_val_RMW_diff_var_pres:  \n  \" [\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma> \\<Longrightarrow> x \\<noteq> y \\<Longrightarrow> \\<sigma> RMW[y, v, w]\\<^sub>t \\<sigma>' \\<Longrightarrow> [\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>'\"\n  using no_val_Update_diff_var_pres by force\n\n\nend", "meta": {"author": "dalvandi", "repo": "dalvandi.github.io", "sha": "041547a91a9ecce033686db075e66ec9d5768a0b", "save_path": "github-repos/isabelle/dalvandi-dalvandi.github.io", "path": "github-repos/isabelle/dalvandi-dalvandi.github.io/dalvandi.github.io-041547a91a9ecce033686db075e66ec9d5768a0b/ECOOP2020/Isabelle/OpSem.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5506073655352404, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.28819909939536564}}
{"text": "theory Wasm_Type_Printing imports Wasm_Base_Defs begin\n(* Maps types to Andreas' Ocaml implementation - a thin wrapper over Ocaml ints/floats for the most part. *)\n\ncode_printing\n(*  type_constructor i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.t\" *)\n(*| type_constructor i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.t\" *)\n  type_constructor f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.t\"\n| type_constructor f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.t\"\n\n(* zero consts *)\ncode_printing\n(*  constant zero_i32_inst.zero_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.zero\"\n| constant zero_i64_inst.zero_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.zero\" *)\n  constant zero_f32_inst.zero_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.zero\"\n| constant zero_f64_inst.zero_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.zero\"\n\n(* intra-{int,float} conversions *)\ncode_printing\n(*  constant wasm_wrap \\<rightharpoonup> (OCaml) \"(I32Wrapper'_convert.wrap'_i64)\"\n| constant wasm_extend_u \\<rightharpoonup> (OCaml) \"(I64Wrapper'_convert.extend'_u'_i32)\"\n| constant wasm_extend_s \\<rightharpoonup> (OCaml) \"(I64Wrapper'_convert.extend'_s'_i32)\" *)\n  constant wasm_demote \\<rightharpoonup> (OCaml) \"(F32Wrapper'_convert.demote'_f64)\"\n| constant wasm_promote \\<rightharpoonup> (OCaml) \"(F64Wrapper'_convert.promote'_f32)\"\n\ntext\\<open>\nRepeat all code equations explicitly again because the ones like @{const I32.int_clz} do not work\nin export_code. Most of these are simply the original definitions, but we can also do some minor\noptimizations like in @{const int_shl} and others below.\n\\<close>\nlemma[code]: \"int_clz (Abs_i32 x) = Abs_i32 (of_nat (word_clz x))\"\n  by (simp add: I32.int_clz_def int_clz_i32.abs_eq)\nlemma[code]: \"int_ctz (Abs_i32 x) = Abs_i32 (of_nat (word_ctz x))\"\n  by (simp add: I32.int_ctz_def int_ctz_i32.abs_eq)\nlemma[code]: \"int_popcnt (Abs_i32 x) = Abs_i32 (of_nat (pop_count x))\"\n  by (simp add: I32.int_popcnt_def int_popcnt_i32.abs_eq)\nlemma[code]: \"int_add (Abs_i32 x) (Abs_i32 y) = Abs_i32 (x + y)\"\n  by (simp add: I32.int_add_def int_add_i32.abs_eq)\nlemma[code]: \"int_sub (Abs_i32 x) (Abs_i32 y) = Abs_i32 (x - y)\"\n  by (simp add: I32.int_sub_def int_sub_i32.abs_eq)\nlemma[code]: \"int_mul (Abs_i32 x) (Abs_i32 y) = Abs_i32 (x * y)\"\n  by (simp add: I32.int_mul_def int_mul_i32.abs_eq)\nlemma[code]: \"int_div_u (Abs_i32 x) (Abs_i32 y) =\n  (if y = 0 then None else Some (Abs_i32 (x div y)))\"\n  by (simp add: int_div_u_i32.abs_eq I32.int_div_u_def)\nlemma[code]: \"int_div_s (Abs_i32 x) (Abs_i32 y) =\n  (if y = 0 \\<or> (x = of_int (-(2^(LENGTH(i32) - 1))) \\<and> y = of_int (-1))\n  then None else Some (Abs_i32 (x sdiv y)))\"\n  by (simp add: int_div_s_i32.abs_eq I32.int_div_s_def)\nlemma[code]: \"int_rem_u (Abs_i32 x) (Abs_i32 y) =\n  (if y = 0 then None else Some (Abs_i32 (x mod y)))\"\n  by (simp add: int_rem_u_i32.abs_eq I32.int_rem_u_def)\nlemma[code]: \"int_rem_s (Abs_i32 x) (Abs_i32 y) =\n  (if y = 0 then None else Some (Abs_i32 (x smod y)))\"\n  by (simp add: int_rem_s_i32.abs_eq I32.int_rem_s_def)\nlemma[code]: \"int_and (Abs_i32 x) (Abs_i32 y) = Abs_i32 (x AND y)\"\n  by (simp add: I32.int_and_def int_and_i32.abs_eq)\nlemma[code]: \"int_or (Abs_i32 x) (Abs_i32 y) = Abs_i32 (x OR y)\"\n  by (simp add: I32.int_or_def int_or_i32.abs_eq)\nlemma[code]: \"int_xor (Abs_i32 x) (Abs_i32 y) = Abs_i32 (x XOR y)\"\n  by (simp add: I32.int_xor_def int_xor_i32.abs_eq)\nlemma mod_i32: \"x AND 31 = x mod LENGTH(i32)\"\nproof -\n  have int: \"int x mod (int LENGTH(i32)) = int x AND 31\" using AND_mod[of \"int x\" 5] by simp\n  thus ?thesis by (simp add: int int_ops(3) nat_int.Rep_eqD of_nat_and_eq zmod_int)\nqed\nlemma[code]: \"int_shl (Abs_i32 x) (Abs_i32 y) = Abs_i32 (x << (unat y AND 31))\"\n  by (simp add: I32.int_shl_def int_shl_i32.abs_eq mod_i32)\nlemma[code]: \"int_shr_u (Abs_i32 x) (Abs_i32 y) = Abs_i32 (x >> (unat y AND 31))\"\n  by (simp add: I32.int_shr_u_def int_shr_u_i32.abs_eq mod_i32)\nlemma[code]: \"int_shr_s (Abs_i32 x) (Abs_i32 y) = Abs_i32 (x >>> (unat y AND 31))\"\n  by (simp add: I32.int_shr_s_def int_shr_s_i32.abs_eq mod_i32)\nlemma[code]: \"int_rotl (Abs_i32 x) (Abs_i32 y) = Abs_i32 (word_rotl (unat y) x)\"\n  by (simp add: I32.int_rotl_def int_rotl_i32.abs_eq)\nlemma[code]: \"int_rotr (Abs_i32 x) (Abs_i32 y) = Abs_i32 (word_rotr (unat y) x)\"\n  by (simp add: I32.int_rotr_def int_rotr_i32.abs_eq)\nlemma[code]: \"int_eqz (Abs_i32 x) \\<longleftrightarrow> x = 0\"\nproof -\n  have \"x = 0 \\<longleftrightarrow> Abs_i32 x = 0\"\n    unfolding zero_i32_def\n    by (metis Abs_fnat_hom_0 I32.rep_abs)\n  thus ?thesis using I32.int_eqz_def int_eqz_i32.rep_eq by presburger\nqed\nlemma[code]: \"int_eq (Abs_i32 x) (Abs_i32 y) \\<longleftrightarrow> x = y\"\n  by (simp add: I32.int_eq_def int_eq_i32.abs_eq)\nlemma[code]: \"int_lt_u (Abs_i32 x) (Abs_i32 y) \\<longleftrightarrow> x < y\"\n  by (simp add: I32.int_lt_u_def int_lt_u_i32.abs_eq)\nlemma[code]: \"int_lt_s (Abs_i32 x) (Abs_i32 y) \\<longleftrightarrow> x <s y\"\n  by (simp add: I32.int_lt_s_def int_lt_s_i32.abs_eq)\nlemma[code]: \"int_gt_u (Abs_i32 x) (Abs_i32 y) \\<longleftrightarrow> x > y\"\n  by (simp add: I32.int_gt_u_def int_gt_u_i32.abs_eq)\nlemma[code]: \"int_gt_s (Abs_i32 x) (Abs_i32 y) \\<longleftrightarrow> signed.greater x y\"\n  by (simp add: I32.int_gt_s_def int_gt_s_i32.abs_eq)\nlemma[code]: \"int_le_u (Abs_i32 x) (Abs_i32 y) \\<longleftrightarrow> x \\<le> y\"\n  by (simp add: I32.int_le_u_def int_le_u_i32.abs_eq)\nlemma[code]: \"int_le_s (Abs_i32 x) (Abs_i32 y) \\<longleftrightarrow> x \\<le>s y\"\n  by (simp add: I32.int_le_s_def int_le_s_i32.abs_eq)\nlemma[code]: \"int_ge_u (Abs_i32 x) (Abs_i32 y) \\<longleftrightarrow> x \\<ge> y\"\n  by (simp add: I32.int_ge_u_def int_ge_u_i32.abs_eq)\nlemma[code]: \"int_ge_s (Abs_i32 x) (Abs_i32 y) \\<longleftrightarrow> signed.greater_eq x y\"\n  by (simp add: I32.int_ge_s_def int_ge_s_i32.abs_eq)\n\nlemma[code]: \"int_clz (Abs_i64 x) = Abs_i64 (of_nat (word_clz x))\"\n  by (simp add: I64.int_clz_def int_clz_i64.abs_eq)\nlemma[code]: \"int_ctz (Abs_i64 x) = Abs_i64 (of_nat (word_ctz x))\"\n  by (simp add: I64.int_ctz_def int_ctz_i64.abs_eq)\nlemma[code]: \"int_popcnt (Abs_i64 x) = Abs_i64 (of_nat (pop_count x))\"\n  by (simp add: I64.int_popcnt_def int_popcnt_i64.abs_eq)\nlemma[code]: \"int_add (Abs_i64 x) (Abs_i64 y) = Abs_i64 (x + y)\"\n  by (simp add: I64.int_add_def int_add_i64.abs_eq)\nlemma[code]: \"int_sub (Abs_i64 x) (Abs_i64 y) = Abs_i64 (x - y)\"\n  by (simp add: I64.int_sub_def int_sub_i64.abs_eq)\nlemma[code]: \"int_mul (Abs_i64 x) (Abs_i64 y) = Abs_i64 (x * y)\"\n  by (simp add: I64.int_mul_def int_mul_i64.abs_eq)\nlemma[code]: \"int_div_u (Abs_i64 x) (Abs_i64 y) =\n  (if y = 0 then None else Some (Abs_i64 (x div y)))\"\n  by (simp add: int_div_u_i64.abs_eq I64.int_div_u_def)\nlemma[code]: \"int_div_s (Abs_i64 x) (Abs_i64 y) =\n  (if y = 0 \\<or> (x = of_int (-(2^(LENGTH(i64) - 1))) \\<and> y = of_int (-1))\n  then None else Some (Abs_i64 (x sdiv y)))\"\n  by (simp add: int_div_s_i64.abs_eq I64.int_div_s_def)\nlemma[code]: \"int_rem_u (Abs_i64 x) (Abs_i64 y) =\n  (if y = 0 then None else Some (Abs_i64 (x mod y)))\"\n  by (simp add: int_rem_u_i64.abs_eq I64.int_rem_u_def)\nlemma[code]: \"int_rem_s (Abs_i64 x) (Abs_i64 y) =\n  (if y = 0 then None else Some (Abs_i64 (x smod y)))\"\n  by (simp add: int_rem_s_i64.abs_eq I64.int_rem_s_def)\nlemma[code]: \"int_and (Abs_i64 x) (Abs_i64 y) = Abs_i64 (x AND y)\"\n  by (simp add: I64.int_and_def int_and_i64.abs_eq)\nlemma[code]: \"int_or (Abs_i64 x) (Abs_i64 y) = Abs_i64 (x OR y)\"\n  by (simp add: I64.int_or_def int_or_i64.abs_eq)\nlemma[code]: \"int_xor (Abs_i64 x) (Abs_i64 y) = Abs_i64 (x XOR y)\"\n  by (simp add: I64.int_xor_def int_xor_i64.abs_eq)\nlemma mod_i64: \"x AND 63 = x mod LENGTH(i64)\"\nproof -\n  have int: \"int x mod (int LENGTH(i64)) = int x AND 63\" using AND_mod[of \"int x\" 6] by simp\n  thus ?thesis by (simp add: int int_ops(3) nat_int.Rep_eqD of_nat_and_eq zmod_int)\nqed\nlemma[code]: \"int_shl (Abs_i64 x) (Abs_i64 y) = Abs_i64 (x << (unat y AND 63))\"\n  by (simp add: I64.int_shl_def int_shl_i64.abs_eq mod_i64)\nlemma[code]: \"int_shr_u (Abs_i64 x) (Abs_i64 y) = Abs_i64 (x >> (unat y AND 63))\"\n  by (simp add: I64.int_shr_u_def int_shr_u_i64.abs_eq mod_i64)\nlemma[code]: \"int_shr_s (Abs_i64 x) (Abs_i64 y) = Abs_i64 (x >>> (unat y AND 63))\"\n  by (simp add: I64.int_shr_s_def int_shr_s_i64.abs_eq mod_i64)\nlemma[code]: \"int_rotl (Abs_i64 x) (Abs_i64 y) = Abs_i64 (word_rotl (unat y) x)\"\n  by (simp add: I64.int_rotl_def int_rotl_i64.abs_eq)\nlemma[code]: \"int_rotr (Abs_i64 x) (Abs_i64 y) = Abs_i64 (word_rotr (unat y) x)\"\n  by (simp add: I64.int_rotr_def int_rotr_i64.abs_eq)\nlemma[code]: \"int_eqz (Abs_i64 x) \\<longleftrightarrow> x = 0\"\nproof -\n  have \"x = 0 \\<longleftrightarrow> Abs_i64 x = 0\"\n    unfolding zero_i64_def\n    by (metis Abs_fnat_hom_0 I64.rep_abs)\n  thus ?thesis using I64.int_eqz_def int_eqz_i64.rep_eq by presburger\nqed\nlemma[code]: \"int_eq (Abs_i64 x) (Abs_i64 y) \\<longleftrightarrow> x = y\"\n  by (simp add: I64.int_eq_def int_eq_i64.abs_eq)\nlemma[code]: \"int_lt_u (Abs_i64 x) (Abs_i64 y) \\<longleftrightarrow> x < y\"\n  by (simp add: I64.int_lt_u_def int_lt_u_i64.abs_eq)\nlemma[code]: \"int_lt_s (Abs_i64 x) (Abs_i64 y) \\<longleftrightarrow> x <s y\"\n  by (simp add: I64.int_lt_s_def int_lt_s_i64.abs_eq)\nlemma[code]: \"int_gt_u (Abs_i64 x) (Abs_i64 y) \\<longleftrightarrow> x > y\"\n  by (simp add: I64.int_gt_u_def int_gt_u_i64.abs_eq)\nlemma[code]: \"int_gt_s (Abs_i64 x) (Abs_i64 y) \\<longleftrightarrow> signed.greater x y\"\n  by (simp add: I64.int_gt_s_def int_gt_s_i64.abs_eq)\nlemma[code]: \"int_le_u (Abs_i64 x) (Abs_i64 y) \\<longleftrightarrow> x \\<le> y\"\n  by (simp add: I64.int_le_u_def int_le_u_i64.abs_eq)\nlemma[code]: \"int_le_s (Abs_i64 x) (Abs_i64 y) \\<longleftrightarrow> x \\<le>s y\"\n  by (simp add: I64.int_le_s_def int_le_s_i64.abs_eq)\nlemma[code]: \"int_ge_u (Abs_i64 x) (Abs_i64 y) \\<longleftrightarrow> x \\<ge> y\"\n  by (simp add: I64.int_ge_u_def int_ge_u_i64.abs_eq)\nlemma[code]: \"int_ge_s (Abs_i64 x) (Abs_i64 y) \\<longleftrightarrow> signed.greater_eq x y\"\n  by (simp add: I64.int_ge_s_def int_ge_s_i64.abs_eq)\n\n(* Sometimes to implement conversions we need to indirect through OCaml int types *)\ntypedecl ocaml_i32\ntypedecl ocaml_i64\ntypedecl ocaml_char\n\ncode_printing\n  type_constructor ocaml_i32 \\<rightharpoonup> (OCaml) \"Int32.t\"\n| type_constructor ocaml_i64 \\<rightharpoonup> (OCaml) \"Int64.t\"\n| type_constructor ocaml_char \\<rightharpoonup> (OCaml) \"Char.t\"\n\naxiomatization\n  ocaml_i32_to_integer :: \"ocaml_i32 \\<Rightarrow> integer\" and\n  integer_to_ocaml_i32 :: \"integer \\<Rightarrow> ocaml_i32\" and\n  ocaml_i64_to_integer :: \"ocaml_i64 \\<Rightarrow> integer\" and\n  integer_to_ocaml_i64 :: \"integer \\<Rightarrow> ocaml_i64\" and\n  ocaml_char_to_integer :: \"ocaml_char \\<Rightarrow> integer\" and\n  integer_to_ocaml_char :: \"integer \\<Rightarrow> ocaml_char\"\n\ncode_printing\n  constant ocaml_i32_to_integer \\<rightharpoonup> (OCaml) \"LibAux.z'_of'_uint32\"\n| constant integer_to_ocaml_i32 \\<rightharpoonup> (OCaml) \"LibAux.uint32'_of'_z\"\n| constant ocaml_i64_to_integer \\<rightharpoonup> (OCaml) \"LibAux.z'_of'_uint64\"\n| constant integer_to_ocaml_i64 \\<rightharpoonup> (OCaml) \"LibAux.uint64'_of'_z\"\n| constant ocaml_char_to_integer \\<rightharpoonup> (OCaml) \"LibAux.z'_of'_char\"\n| constant integer_to_ocaml_char \\<rightharpoonup> (OCaml) \"LibAux.char'_of'_z\"\n\ndefinition ocaml_int32_to_isabelle_int32 :: \"ocaml_i32 \\<Rightarrow> i32\" where\n  \"ocaml_int32_to_isabelle_int32 n \\<equiv> wasm_int_ops_i32_inst.int_of_nat_i32 (nat_of_integer (ocaml_i32_to_integer n))\"\n\ndefinition isabelle_int32_to_ocaml_int32 :: \"i32 \\<Rightarrow> ocaml_i32\" where\n  \"isabelle_int32_to_ocaml_int32 n \\<equiv> integer_to_ocaml_i32 (integer_of_nat (wasm_int_ops_i32_inst.nat_of_int_i32 n))\"\n\ndefinition ocaml_int64_to_isabelle_int64 :: \"ocaml_i64 \\<Rightarrow> i64\" where\n  \"ocaml_int64_to_isabelle_int64 n \\<equiv> wasm_int_ops_i64_inst.int_of_nat_i64 (nat_of_integer (ocaml_i64_to_integer n))\"\n\ndefinition isabelle_int64_to_ocaml_int64 :: \"i64 \\<Rightarrow> ocaml_i64\" where\n  \"isabelle_int64_to_ocaml_int64 n \\<equiv> integer_to_ocaml_i64 (integer_of_nat (wasm_int_ops_i64_inst.nat_of_int_i64 n))\"\n\ndefinition ocaml_char_to_isabelle_byte :: \"ocaml_char \\<Rightarrow> byte\" where\n  \"ocaml_char_to_isabelle_byte n \\<equiv> byte_of_nat (nat_of_integer (ocaml_char_to_integer n))\"\n\ndefinition isabelle_byte_to_ocaml_char :: \"byte \\<Rightarrow> ocaml_char\" where\n  \"isabelle_byte_to_ocaml_char n \\<equiv> integer_to_ocaml_char (integer_of_nat (nat_of_byte n))\"\n\n(* axiomatise the existence of conversions between floats and OCaml ints/char lists *)\naxiomatization\n  f32_convert_u_ocaml_i32 :: \"ocaml_i32 \\<Rightarrow> f32\" and\n  f32_convert_s_ocaml_i32 :: \"ocaml_i32 \\<Rightarrow> f32\" and\n  f32_convert_u_ocaml_i64 :: \"ocaml_i64 \\<Rightarrow> f32\" and\n  f32_convert_s_ocaml_i64 :: \"ocaml_i64 \\<Rightarrow> f32\" and\n  f64_convert_u_ocaml_i32 :: \"ocaml_i32 \\<Rightarrow> f64\" and\n  f64_convert_s_ocaml_i32 :: \"ocaml_i32 \\<Rightarrow> f64\" and\n  f64_convert_u_ocaml_i64 :: \"ocaml_i64 \\<Rightarrow> f64\" and\n  f64_convert_s_ocaml_i64 :: \"ocaml_i64 \\<Rightarrow> f64\" and\n  ocaml_i32_trunc_u_f32 :: \"f32 \\<Rightarrow> ocaml_i32 option\" and\n  ocaml_i32_trunc_s_f32 :: \"f32 \\<Rightarrow> ocaml_i32 option\" and\n  ocaml_i32_trunc_u_f64 :: \"f64 \\<Rightarrow> ocaml_i32 option\" and\n  ocaml_i32_trunc_s_f64 :: \"f64 \\<Rightarrow> ocaml_i32 option\" and\n  ocaml_i64_trunc_u_f32 :: \"f32 \\<Rightarrow> ocaml_i64 option\" and\n  ocaml_i64_trunc_s_f32 :: \"f32 \\<Rightarrow> ocaml_i64 option\" and\n  ocaml_i64_trunc_u_f64 :: \"f64 \\<Rightarrow> ocaml_i64 option\" and\n  ocaml_i64_trunc_s_f64 :: \"f64 \\<Rightarrow> ocaml_i64 option\" and\n  f32_serialise_ocaml_char :: \"f32 \\<Rightarrow> ocaml_char list\" and\n  f64_serialise_ocaml_char :: \"f64 \\<Rightarrow> ocaml_char list\" and\n  f32_deserialise_ocaml_char :: \"ocaml_char list \\<Rightarrow> f32\" and\n  f64_deserialise_ocaml_char :: \"ocaml_char list \\<Rightarrow> f64\"\n\ncode_printing\n  constant f32_convert_u_ocaml_i32 \\<rightharpoonup> (OCaml) \"F32Wrapper'_convert.convert'_u'_i32\"\n| constant f32_convert_s_ocaml_i32 \\<rightharpoonup> (OCaml) \"F32Wrapper'_convert.convert'_s'_i32\"\n| constant f32_convert_u_ocaml_i64 \\<rightharpoonup> (OCaml) \"F32Wrapper'_convert.convert'_u'_i64\"\n| constant f32_convert_s_ocaml_i64 \\<rightharpoonup> (OCaml) \"F32Wrapper'_convert.convert'_s'_i64\"\n| constant f64_convert_u_ocaml_i32 \\<rightharpoonup> (OCaml) \"F64Wrapper'_convert.convert'_u'_i32\"\n| constant f64_convert_s_ocaml_i32 \\<rightharpoonup> (OCaml) \"F64Wrapper'_convert.convert'_s'_i32\"\n| constant f64_convert_u_ocaml_i64 \\<rightharpoonup> (OCaml) \"F64Wrapper'_convert.convert'_u'_i64\"\n| constant f64_convert_s_ocaml_i64 \\<rightharpoonup> (OCaml) \"F64Wrapper'_convert.convert'_s'_i64\"\n| constant ocaml_i32_trunc_u_f32 \\<rightharpoonup> (OCaml) \"I32Wrapper'_convert.trunc'_u'_f32\"\n| constant ocaml_i32_trunc_s_f32 \\<rightharpoonup> (OCaml) \"I32Wrapper'_convert.trunc'_s'_f32\"\n| constant ocaml_i32_trunc_u_f64 \\<rightharpoonup> (OCaml) \"I32Wrapper'_convert.trunc'_u'_f64\"\n| constant ocaml_i32_trunc_s_f64 \\<rightharpoonup> (OCaml) \"I32Wrapper'_convert.trunc'_s'_f64\"\n| constant ocaml_i64_trunc_u_f32 \\<rightharpoonup> (OCaml) \"I64Wrapper'_convert.trunc'_u'_f32\"\n| constant ocaml_i64_trunc_s_f32 \\<rightharpoonup> (OCaml) \"I64Wrapper'_convert.trunc'_s'_f32\"\n| constant ocaml_i64_trunc_u_f64 \\<rightharpoonup> (OCaml) \"I64Wrapper'_convert.trunc'_u'_f64\"\n| constant ocaml_i64_trunc_s_f64 \\<rightharpoonup> (OCaml) \"I64Wrapper'_convert.trunc'_s'_f64\"\n| constant f32_serialise_ocaml_char \\<rightharpoonup> (OCaml) \"ImplWrapper.serialise'_f32\"\n| constant f64_serialise_ocaml_char \\<rightharpoonup> (OCaml) \"ImplWrapper.serialise'_f64\"\n| constant f32_deserialise_ocaml_char \\<rightharpoonup> (OCaml) \"ImplWrapper.deserialise'_f32\"\n| constant f64_deserialise_ocaml_char \\<rightharpoonup> (OCaml) \"ImplWrapper.deserialise'_f64\"\n\ndefinition f32_convert_u_isabelle_i32 :: \"i32 \\<Rightarrow> f32\" where\n  \"f32_convert_u_isabelle_i32 i = f32_convert_u_ocaml_i32 (isabelle_int32_to_ocaml_int32 i)\"\n\ndefinition f32_convert_s_isabelle_i32 :: \"i32 \\<Rightarrow> f32\" where\n  \"f32_convert_s_isabelle_i32 i = f32_convert_s_ocaml_i32 (isabelle_int32_to_ocaml_int32 i)\"\n\ndefinition f32_convert_u_isabelle_i64 :: \"i64 \\<Rightarrow> f32\" where\n  \"f32_convert_u_isabelle_i64 i = f32_convert_u_ocaml_i64 (isabelle_int64_to_ocaml_int64 i)\"\n\ndefinition f32_convert_s_isabelle_i64 :: \"i64 \\<Rightarrow> f32\" where\n  \"f32_convert_s_isabelle_i64 i = f32_convert_s_ocaml_i64 (isabelle_int64_to_ocaml_int64 i)\"\n\ndefinition f64_convert_u_isabelle_i32 :: \"i32 \\<Rightarrow> f64\" where\n  \"f64_convert_u_isabelle_i32 i = f64_convert_u_ocaml_i32 (isabelle_int32_to_ocaml_int32 i)\"\n\ndefinition f64_convert_s_isabelle_i32 :: \"i32 \\<Rightarrow> f64\" where\n  \"f64_convert_s_isabelle_i32 i = f64_convert_s_ocaml_i32 (isabelle_int32_to_ocaml_int32 i)\"\n\ndefinition f64_convert_u_isabelle_i64 :: \"i64 \\<Rightarrow> f64\" where\n  \"f64_convert_u_isabelle_i64 i = f64_convert_u_ocaml_i64 (isabelle_int64_to_ocaml_int64 i)\"\n\ndefinition f64_convert_s_isabelle_i64 :: \"i64 \\<Rightarrow> f64\" where\n  \"f64_convert_s_isabelle_i64 i = f64_convert_s_ocaml_i64 (isabelle_int64_to_ocaml_int64 i)\"\n\ndefinition isabelle_i32_trunc_u_f32 :: \"f32 \\<Rightarrow>i32 option\" where\n  \"isabelle_i32_trunc_u_f32 f = map_option ocaml_int32_to_isabelle_int32 (ocaml_i32_trunc_u_f32 f)\"\n\ndefinition isabelle_i32_trunc_s_f32 :: \"f32 \\<Rightarrow>i32 option\" where\n  \"isabelle_i32_trunc_s_f32 f = map_option ocaml_int32_to_isabelle_int32 (ocaml_i32_trunc_s_f32 f)\"\n\ndefinition isabelle_i32_trunc_u_f64 :: \"f64 \\<Rightarrow>i32 option\" where\n  \"isabelle_i32_trunc_u_f64 f = map_option ocaml_int32_to_isabelle_int32 (ocaml_i32_trunc_u_f64 f)\"\n\ndefinition isabelle_i32_trunc_s_f64 :: \"f64 \\<Rightarrow>i32 option\" where\n  \"isabelle_i32_trunc_s_f64 f = map_option ocaml_int32_to_isabelle_int32 (ocaml_i32_trunc_s_f64 f)\"\n\ndefinition isabelle_i64_trunc_u_f32 :: \"f32 \\<Rightarrow>i64 option\" where\n  \"isabelle_i64_trunc_u_f32 f = map_option ocaml_int64_to_isabelle_int64 (ocaml_i64_trunc_u_f32 f)\"\n\ndefinition isabelle_i64_trunc_s_f32 :: \"f32 \\<Rightarrow>i64 option\" where\n  \"isabelle_i64_trunc_s_f32 f = map_option ocaml_int64_to_isabelle_int64 (ocaml_i64_trunc_s_f32 f)\"\n\ndefinition isabelle_i64_trunc_u_f64 :: \"f64 \\<Rightarrow>i64 option\" where\n  \"isabelle_i64_trunc_u_f64 f = map_option ocaml_int64_to_isabelle_int64 (ocaml_i64_trunc_u_f64 f)\"\n\ndefinition isabelle_i64_trunc_s_f64 :: \"f64 \\<Rightarrow>i64 option\" where\n  \"isabelle_i64_trunc_s_f64 f = map_option ocaml_int64_to_isabelle_int64 (ocaml_i64_trunc_s_f64 f)\"\n\ndefinition f32_serialise_isabelle_bytes :: \"f32 \\<Rightarrow> bytes\" where\n  \"f32_serialise_isabelle_bytes f = List.map ocaml_char_to_isabelle_byte (f32_serialise_ocaml_char f)\"\n\ndefinition f64_serialise_isabelle_bytes :: \"f64 \\<Rightarrow> bytes\" where\n  \"f64_serialise_isabelle_bytes f = List.map ocaml_char_to_isabelle_byte (f64_serialise_ocaml_char f)\"\n\ndefinition f32_deserialise_isabelle_bytes :: \"bytes \\<Rightarrow> f32\" where\n  \"f32_deserialise_isabelle_bytes bs = f32_deserialise_ocaml_char (List.map isabelle_byte_to_ocaml_char bs)\"\n\ndefinition f64_deserialise_isabelle_bytes :: \"bytes \\<Rightarrow> f64\" where\n  \"f64_deserialise_isabelle_bytes bs = f64_deserialise_ocaml_char (List.map isabelle_byte_to_ocaml_char bs)\"\n\naxiomatization where\n  f32_convert_ui32_is[code]: \"f32_convert_ui32 \\<equiv> f32_convert_u_isabelle_i32\" and\n  f32_convert_si32_is[code]: \"f32_convert_si32 \\<equiv> f32_convert_s_isabelle_i32\" and\n  f32_convert_ui64_is[code]: \"f32_convert_ui64 \\<equiv> f32_convert_u_isabelle_i64\" and\n  f32_convert_si64_is[code]: \"f32_convert_si64 \\<equiv> f32_convert_s_isabelle_i64\" and\n  f64_convert_ui32_is[code]: \"f64_convert_ui32 \\<equiv> f64_convert_u_isabelle_i32\" and\n  f64_convert_si32_is[code]: \"f64_convert_si32 \\<equiv> f64_convert_s_isabelle_i32\" and\n  f64_convert_ui64_is[code]: \"f64_convert_ui64 \\<equiv> f64_convert_u_isabelle_i64\" and\n  f64_convert_si64_is[code]: \"f64_convert_si64 \\<equiv> f64_convert_s_isabelle_i64\" and\n  ui32_trunc_f32_is[code]: \"ui32_trunc_f32 \\<equiv> isabelle_i32_trunc_u_f32\" and\n  si32_trunc_f32_is[code]: \"si32_trunc_f32 \\<equiv> isabelle_i32_trunc_u_f32\" and\n  ui32_trunc_f64_is[code]: \"ui32_trunc_f64 \\<equiv> isabelle_i32_trunc_u_f64\" and\n  si32_trunc_f64_is[code]: \"si32_trunc_f64 \\<equiv> isabelle_i32_trunc_u_f64\" and\n  ui64_trunc_f32_is[code]: \"ui64_trunc_f32 \\<equiv> isabelle_i64_trunc_u_f32\" and\n  si64_trunc_f32_is[code]: \"si64_trunc_f32 \\<equiv> isabelle_i64_trunc_u_f32\" and\n  ui64_trunc_f64_is[code]: \"ui64_trunc_f64 \\<equiv> isabelle_i64_trunc_u_f64\" and\n  si64_trunc_f64_is[code]: \"si64_trunc_f64 \\<equiv> isabelle_i64_trunc_u_f64\" and\n  serialise_f32_is[code]: \"serialise_f32 \\<equiv> f32_serialise_isabelle_bytes\" and\n  serialise_f64_is[code]: \"serialise_f64 \\<equiv> f64_serialise_isabelle_bytes\" and\n  deserialise_f32_is[code]: \"deserialise_f32 \\<equiv> f32_deserialise_isabelle_bytes\" and\n  deserialise_f64_is[code]: \"deserialise_f64 \\<equiv> f64_deserialise_isabelle_bytes\"\n\n(* arithmetic *)\ncode_printing\n(* INT32 *)\n  (* UNOPS *)\n(*  constant wasm_int_ops_i32_inst.int_clz_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.clz\"\n| constant wasm_int_ops_i32_inst.int_ctz_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.ctz\"\n| constant wasm_int_ops_i32_inst.int_popcnt_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.popcnt\"\n  (* BINOPS - wrap *)\n| constant wasm_int_ops_i32_inst.int_add_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.add\"\n| constant wasm_int_ops_i32_inst.int_sub_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.sub\"\n| constant wasm_int_ops_i32_inst.int_mul_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.mul\"\n| constant wasm_int_ops_i32_inst.int_div_u_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.div'_u\"\n| constant wasm_int_ops_i32_inst.int_div_s_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.div'_s\"\n| constant wasm_int_ops_i32_inst.int_rem_u_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.rem'_u\"\n| constant wasm_int_ops_i32_inst.int_rem_s_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.rem'_s\"\n| constant wasm_int_ops_i32_inst.int_and_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.and'_\"\n| constant wasm_int_ops_i32_inst.int_or_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.or'_\"\n| constant wasm_int_ops_i32_inst.int_xor_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.xor\"\n| constant wasm_int_ops_i32_inst.int_shl_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.shl\"\n| constant wasm_int_ops_i32_inst.int_shr_u_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.shr'_u\"\n| constant wasm_int_ops_i32_inst.int_shr_s_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.shr'_s\"\n| constant wasm_int_ops_i32_inst.int_rotl_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.rotl\"\n| constant wasm_int_ops_i32_inst.int_rotr_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.rotr\"\n  (* TESTOPS *)\n| constant wasm_int_ops_i32_inst.int_eqz_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.eqz\"\n  (* RELOPS *)\n| constant wasm_int_ops_i32_inst.int_eq_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.eq\"\n| constant wasm_int_ops_i32_inst.int_lt_u_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.lt'_u\"\n| constant wasm_int_ops_i32_inst.int_lt_s_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.lt'_s\"\n| constant wasm_int_ops_i32_inst.int_gt_u_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.gt'_u\"\n| constant wasm_int_ops_i32_inst.int_gt_s_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.gt'_s\"\n| constant wasm_int_ops_i32_inst.int_le_u_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.le'_u\"\n| constant wasm_int_ops_i32_inst.int_le_s_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.le'_s\"\n| constant wasm_int_ops_i32_inst.int_ge_u_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.ge'_u\"\n| constant wasm_int_ops_i32_inst.int_ge_s_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.ge'_s\" *)\n  (* CONVERSIONS *)\n(*\n  constant f32_convert_ui32 \\<rightharpoonup> (OCaml) \"F32Wrapper'_convert.convert'_u'_i32\"\n| constant f32_convert_si32 \\<rightharpoonup> (OCaml) \"F32Wrapper'_convert.convert'_s'_i32\"\n| constant f64_convert_ui32 \\<rightharpoonup> (OCaml) \"F64Wrapper'_convert.convert'_u'_i32\"\n| constant f64_convert_si32 \\<rightharpoonup> (OCaml) \"F64Wrapper'_convert.convert'_s'_i32\"\n*)\n  (* VALUE CONVERSIONS - wrap *)\n(* | constant wasm_int_ops_i32_inst.int_of_nat_i32 \\<rightharpoonup> (OCaml) \"I32Wrapper.int'_of'_z (integer'_of'_nat _)\"\n| constant wasm_int_ops_i32_inst.nat_of_int_i32 \\<rightharpoonup> (OCaml) \"Nat (I32Wrapper.z'_of'_int _)\" *)\n  (* SIGN EXTENDING DESERIALISATION TODO *)\n\n(* INT64 *)\n  (* UNOPS *)\n(*| constant wasm_int_ops_i64_inst.int_clz_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.clz\"\n| constant wasm_int_ops_i64_inst.int_ctz_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.ctz\"\n| constant wasm_int_ops_i64_inst.int_popcnt_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.popcnt\"\n  (* BINOPS - wrap *)\n| constant wasm_int_ops_i64_inst.int_add_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.add\"\n| constant wasm_int_ops_i64_inst.int_sub_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.sub\"\n| constant wasm_int_ops_i64_inst.int_mul_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.mul\"\n| constant wasm_int_ops_i64_inst.int_div_u_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.div'_u\"\n| constant wasm_int_ops_i64_inst.int_div_s_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.div'_s\"\n| constant wasm_int_ops_i64_inst.int_rem_u_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.rem'_u\"\n| constant wasm_int_ops_i64_inst.int_rem_s_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.rem'_s\"\n| constant wasm_int_ops_i64_inst.int_and_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.and'_\"\n| constant wasm_int_ops_i64_inst.int_or_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.or'_\"\n| constant wasm_int_ops_i64_inst.int_xor_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.xor\"\n| constant wasm_int_ops_i64_inst.int_shl_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.shl\"\n| constant wasm_int_ops_i64_inst.int_shr_u_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.shr'_u\"\n| constant wasm_int_ops_i64_inst.int_shr_s_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.shr'_s\"\n| constant wasm_int_ops_i64_inst.int_rotl_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.rotl\"\n| constant wasm_int_ops_i64_inst.int_rotr_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.rotr\"\n  (* TESTOPS *)\n| constant wasm_int_ops_i64_inst.int_eqz_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.eqz\"\n  (* RELOPS *)\n| constant wasm_int_ops_i64_inst.int_eq_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.eq\"\n| constant wasm_int_ops_i64_inst.int_lt_u_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.lt'_u\"\n| constant wasm_int_ops_i64_inst.int_lt_s_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.lt'_s\"\n| constant wasm_int_ops_i64_inst.int_gt_u_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.gt'_u\"\n| constant wasm_int_ops_i64_inst.int_gt_s_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.gt'_s\"\n| constant wasm_int_ops_i64_inst.int_le_u_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.le'_u\"\n| constant wasm_int_ops_i64_inst.int_le_s_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.le'_s\"\n| constant wasm_int_ops_i64_inst.int_ge_u_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.ge'_u\"\n| constant wasm_int_ops_i64_inst.int_ge_s_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.ge'_s\" *)\n  (* CONVERSIONS *)\n(*\n| constant f32_convert_ui64 \\<rightharpoonup> (OCaml) \"F32Wrapper'_convert.convert'_u'_i64\"\n| constant f32_convert_si64 \\<rightharpoonup> (OCaml) \"F32Wrapper'_convert.convert'_s'_i64\"\n| constant f64_convert_ui64 \\<rightharpoonup> (OCaml) \"F64Wrapper'_convert.convert'_u'_i64\"\n| constant f64_convert_si64 \\<rightharpoonup> (OCaml) \"F64Wrapper'_convert.convert'_s'_i64\"\n*)\n  (* VALUE CONVERSIONS - wrap *)\n(*| constant wasm_int_ops_i64_inst.int_of_nat_i64 \\<rightharpoonup> (OCaml) \"I64Wrapper.int'_of'_z (integer'_of'_nat _)\"\n| constant wasm_int_ops_i64_inst.nat_of_int_i64 \\<rightharpoonup> (OCaml) \"Nat (I64Wrapper.z'_of'_int _)\" *)\n(* FLOAT32 *)\n  (* UNOPS *)\n  constant wasm_float_f32_inst.float_neg_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.neg\"\n| constant wasm_float_f32_inst.float_abs_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.abs\"\n| constant wasm_float_f32_inst.float_ceil_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.ceil\"\n| constant wasm_float_f32_inst.float_floor_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.floor\"\n| constant wasm_float_f32_inst.float_trunc_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.trunc\"\n| constant wasm_float_f32_inst.float_nearest_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.nearest\"\n| constant wasm_float_f32_inst.float_sqrt_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.sqrt\"\n  (* BINOPS *)\n| constant wasm_float_f32_inst.float_add_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.add\"\n| constant wasm_float_f32_inst.float_sub_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.sub\"\n| constant wasm_float_f32_inst.float_mul_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.mul\"\n| constant wasm_float_f32_inst.float_div_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.div\"\n| constant wasm_float_f32_inst.float_min_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.min\"\n| constant wasm_float_f32_inst.float_max_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.max\"\n| constant wasm_float_f32_inst.float_copysign_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.copysign\"\n  (* RELOPS *)\n| constant wasm_float_f32_inst.float_eq_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.eq\"\n(* | constant wasm_float_f32_inst.float_ne_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.ne\" *)\n| constant wasm_float_f32_inst.float_lt_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.lt\"\n| constant wasm_float_f32_inst.float_gt_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.gt\"\n| constant wasm_float_f32_inst.float_le_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.le\"\n| constant wasm_float_f32_inst.float_ge_f32 \\<rightharpoonup> (OCaml) \"F32Wrapper.ge\"\n  (* CONVERSIONS *)\n(*\n| constant ui32_trunc_f32 \\<rightharpoonup> (OCaml) \"I32Wrapper'_convert.trunc'_u'_f32\"\n| constant si32_trunc_f32 \\<rightharpoonup> (OCaml) \"I32Wrapper'_convert.trunc'_s'_f32\"\n| constant ui64_trunc_f32 \\<rightharpoonup> (OCaml) \"I64Wrapper'_convert.trunc'_u'_f32\"\n| constant si64_trunc_f32 \\<rightharpoonup> (OCaml) \"I64Wrapper'_convert.trunc'_s'_f32\"\n*)\n(* FLOAT64 *)\n  (* UNOPS *)\n| constant wasm_float_f64_inst.float_neg_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.neg\"\n| constant wasm_float_f64_inst.float_abs_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.abs\"\n| constant wasm_float_f64_inst.float_ceil_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.ceil\"\n| constant wasm_float_f64_inst.float_floor_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.floor\"\n| constant wasm_float_f64_inst.float_trunc_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.trunc\"\n| constant wasm_float_f64_inst.float_nearest_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.nearest\"\n| constant wasm_float_f64_inst.float_sqrt_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.sqrt\"\n  (* BINOPS *)\n| constant wasm_float_f64_inst.float_add_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.add\"\n| constant wasm_float_f64_inst.float_sub_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.sub\"\n| constant wasm_float_f64_inst.float_mul_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.mul\"\n| constant wasm_float_f64_inst.float_div_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.div\"\n| constant wasm_float_f64_inst.float_min_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.min\"\n| constant wasm_float_f64_inst.float_max_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.max\"\n| constant wasm_float_f64_inst.float_copysign_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.copysign\"\n  (* RELOPS *)\n| constant wasm_float_f64_inst.float_eq_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.eq\"\n(* | constant wasm_float_f64_inst.float_ne_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.ne\" *)\n| constant wasm_float_f64_inst.float_lt_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.lt\"\n| constant wasm_float_f64_inst.float_gt_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.gt\"\n| constant wasm_float_f64_inst.float_le_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.le\"\n| constant wasm_float_f64_inst.float_ge_f64 \\<rightharpoonup> (OCaml) \"F64Wrapper.ge\"\n  (* CONVERSIONS *)\n(*\n| constant ui32_trunc_f64 \\<rightharpoonup> (OCaml) \"I32Wrapper'_convert.trunc'_u'_f64\"\n| constant si32_trunc_f64 \\<rightharpoonup> (OCaml) \"I32Wrapper'_convert.trunc'_s'_f64\"\n| constant ui64_trunc_f64 \\<rightharpoonup> (OCaml) \"I64Wrapper'_convert.trunc'_u'_f64\"\n| constant si64_trunc_f64 \\<rightharpoonup> (OCaml) \"I64Wrapper'_convert.trunc'_s'_f64\"\n*)\n(*\ncode_printing\n  constant serialise_i32 \\<rightharpoonup> (OCaml) \"ImplWrapper.serialise'_i32\"\n| constant serialise_i64 \\<rightharpoonup> (OCaml) \"ImplWrapper.serialise'_i64\"\n| constant serialise_f32 \\<rightharpoonup> (OCaml) \"ImplWrapper.serialise'_f32\"\n| constant serialise_f64 \\<rightharpoonup> (OCaml) \"ImplWrapper.serialise'_f64\"\n| constant deserialise_i32 \\<rightharpoonup> (OCaml) \"ImplWrapper.deserialise'_i32\"\n| constant deserialise_i64 \\<rightharpoonup> (OCaml) \"ImplWrapper.deserialise'_i64\"\n| constant deserialise_f32 \\<rightharpoonup> (OCaml) \"ImplWrapper.deserialise'_f32\"\n| constant deserialise_f64 \\<rightharpoonup> (OCaml) \"ImplWrapper.deserialise'_f64\"\n| constant wasm_bool \\<rightharpoonup> (OCaml) \"ImplWrapper.bool\"\n| constant int32_minus_one \\<rightharpoonup> (OCaml) \"I32Wrapper.minus'_one\" *)\n\nend", "meta": {"author": "WasmCert", "repo": "WasmCert-Isabelle", "sha": "f61ec8eab5d551347a268e858e83b7ac7da0d8b5", "save_path": "github-repos/isabelle/WasmCert-WasmCert-Isabelle", "path": "github-repos/isabelle/WasmCert-WasmCert-Isabelle/WasmCert-Isabelle-f61ec8eab5d551347a268e858e83b7ac7da0d8b5/WebAssembly/Wasm_Type_Printing.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.523420348936324, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.28819909939536564}}
{"text": "theory Termination imports \"Hybrid_Logic.Hybrid_Logic\" Trees begin\n\n(*\nInspired by:\nBolander, T., & Blackburn, P. (2007). Termination for Hybrid Tableaus.\nJournal of Logic and Computation, 17(3), 517-554. https://doi.org/10.1093/logcom/exm014\n\n*)\n\n(* TODO: Maybe do B \\<subseteq> nominals all labels? (still curious about this) *)\n\n(* TODO: is it nicer if we use sets for the introduced formulas? *)\n\nsection \\<open>Tableau\\<close>\n\ndatatype ('a, 'b) tag\n  = Close 'b \\<open>('a, 'b) fm\\<close>\n  | Open\n  | Block 'b\n  | Rule 'b \\<open>('a, 'b) fm list list\\<close>\n  | Fresh 'b \\<open>('a, 'b) fm\\<close> 'b\n\ndatatype ('a, 'b) step =\n  Step (getTag: \\<open>('a, 'b) tag\\<close>) (getPotential: nat) (getBranch: \\<open>('a, 'b) branch\\<close>)\n\ntype_synonym ('a, 'b) tableau = \\<open>('a, 'b) step tree\\<close>\n\ncoinductive wft :: \\<open>'b set \\<Rightarrow> ('a, 'b) tableau \\<Rightarrow> bool\\<close>\n  for A :: \\<open>'b set\\<close> where\n    WfClose:\n    \\<open>p at i in branch \\<Longrightarrow> (\\<^bold>\\<not> p) at i in branch \\<Longrightarrow>\n     wft A (Node (Step (Close i p) n branch) [])\\<close>\n  | WfOpen: (* TODO: Do I want to enforce that this is saturated? *)\n    \\<open>\\<nexists>p i. p at i in branch \\<and> (\\<^bold>\\<not> p) at i in branch \\<Longrightarrow>\n     wft A (Node (Step Open n branch) [])\\<close>\n  | WfNeg:\n    \\<open>(\\<^bold>\\<not> \\<^bold>\\<not> p) at a in (ps, a) # branch \\<Longrightarrow>\n    new p a ((ps, a) # branch) \\<Longrightarrow>\n    getBranch (getLabel s) = (p # ps, a) # branch \\<Longrightarrow>\n    getPotential (getLabel s) = Suc n \\<Longrightarrow>\n    wft A s \\<Longrightarrow>\n    wft A (Node (Step (Rule a [[p]]) n ((ps, a) # branch)) [s])\\<close>\n  | WfDisP:\n    \\<open>(p \\<^bold>\\<or> q) at a in (ps, a) # branch \\<Longrightarrow>\n     new p a ((ps, a) # branch) \\<Longrightarrow> new q a ((ps, a) # branch) \\<Longrightarrow>\n     getBranch (getLabel sl) = (p # ps, a) # branch \\<Longrightarrow> getPotential (getLabel sl) = Suc n \\<Longrightarrow>\n     getBranch (getLabel sr) = (q # ps, a) # branch \\<Longrightarrow> getPotential (getLabel sr) = Suc n \\<Longrightarrow>\n     wft A sl \\<Longrightarrow> wft A sr \\<Longrightarrow>\n     wft A (Node (Step (Rule a [[p], [q]]) n ((ps, a) # branch)) [sl, sr])\\<close>\n  | WfDisN:\n    \\<open>(\\<^bold>\\<not> (p \\<^bold>\\<or> q)) at a in (ps, a) # branch \\<Longrightarrow>\n     new (\\<^bold>\\<not> p) a ((ps, a) # branch) \\<or> new (\\<^bold>\\<not> q) a ((ps, a) # branch) \\<Longrightarrow>\n     getBranch (getLabel s) = ((\\<^bold>\\<not> q) # (\\<^bold>\\<not> p) # ps, a) # branch \\<Longrightarrow>\n     getPotential (getLabel s) = Suc n \\<Longrightarrow>\n     wft A s \\<Longrightarrow>\n     intro = filter (\\<lambda>p. new p a ((ps, a) # branch)) [\\<^bold>\\<not> q, \\<^bold>\\<not> p] \\<Longrightarrow>\n     wft A (Node (Step (Rule a [intro]) n ((ps, a) # branch)) [s])\\<close>\n  | WfDiaP:\n    \\<open>(\\<^bold>\\<diamond> p) at a in (ps, a) # branch \\<Longrightarrow>\n     i \\<notin> A \\<union> branch_nominals ((ps, a) # branch) \\<Longrightarrow>\n     \\<nexists>a. p = Nom a \\<Longrightarrow> \\<not> witnessed p a ((ps, a) # branch) \\<Longrightarrow>\n     getBranch (getLabel s) = ((\\<^bold>@ i p) # (\\<^bold>\\<diamond> Nom i) # ps, a) # branch \\<Longrightarrow>\n     getPotential (getLabel s) = Suc n \\<Longrightarrow>\n     wft A s \\<Longrightarrow>\n     wft A (Node (Step (Fresh a p i) n ((ps, a) # branch)) [s])\\<close>\n  | WfDiaN:\n    \\<open>(\\<^bold>\\<not> (\\<^bold>\\<diamond> p)) at a in (ps, a) # branch \\<Longrightarrow>\n     (\\<^bold>\\<diamond> Nom i) at a in (ps, a) # branch \\<Longrightarrow>\n     new (\\<^bold>\\<not> (\\<^bold>@ i p)) a ((ps, a) # branch) \\<Longrightarrow>\n     getBranch (getLabel s) = ((\\<^bold>\\<not> (\\<^bold>@ i p)) # ps, a) # branch \\<Longrightarrow>\n     getPotential (getLabel s) = Suc n \\<Longrightarrow>\n     wft A s \\<Longrightarrow>\n     wft A (Node (Step (Rule a [[\\<^bold>\\<not> (\\<^bold>@ i p)]]) n ((ps, a) # branch)) [s])\\<close>\n  | WfSatP:\n    \\<open>(\\<^bold>@ a p) at b in (ps, a) # branch \\<Longrightarrow>\n     new p a ((ps, a) # branch) \\<Longrightarrow>\n     getBranch (getLabel s) = (p # ps, a) # branch \\<Longrightarrow> getPotential (getLabel s) = Suc n \\<Longrightarrow>\n     wft A s \\<Longrightarrow>\n     wft A (Node (Step (Rule a [[p]]) n ((ps, a) # branch)) [s])\\<close>\n  | WfSatN:\n    \\<open>(\\<^bold>\\<not> (\\<^bold>@ a p)) at b in (ps, a) # branch \\<Longrightarrow>\n     new (\\<^bold>\\<not> p) a ((ps, a) # branch) \\<Longrightarrow>\n     getBranch (getLabel s) = ((\\<^bold>\\<not> p) # ps, a) # branch \\<Longrightarrow> getPotential (getLabel s) = Suc n \\<Longrightarrow>\n     wft A s \\<Longrightarrow>\n     wft A (Node (Step (Rule a [[\\<^bold>\\<not> p]]) n ((ps, a) # branch)) [s])\\<close>\n  | WfGoTo:\n    \\<open>i \\<in> branch_nominals branch \\<Longrightarrow>\n     getBranch (getLabel s) = ([], i) # branch \\<Longrightarrow> getPotential (getLabel s) = n \\<Longrightarrow>\n     wft A s \\<Longrightarrow>\n     wft A (Node (Step (Block i) (Suc n) branch) [s])\\<close>\n  | WfNom:\n    \\<open>p at b in (ps, a) # branch \\<Longrightarrow> Nom a at b in (ps, a) # branch \\<Longrightarrow>\n     \\<forall>i. p = Nom i \\<or> p = (\\<^bold>\\<diamond> Nom i) \\<longrightarrow> i \\<in> A \\<Longrightarrow>\n     new p a ((ps, a) # branch) \\<Longrightarrow>\n     getBranch (getLabel s) = (p # ps, a) # branch \\<Longrightarrow> getPotential (getLabel s) = Suc n \\<Longrightarrow>\n     wft A s \\<Longrightarrow>\n     wft A (Node (Step (Rule a [[p]]) n ((ps, a) # branch)) [s])\\<close>\n\nlemma example:\n  \\<open>wft A (Node (Step (Rule a [[Pro ''p'']]) 0 [([\\<^bold>\\<not> \\<^bold>\\<not> Pro ''p'', Pro ''q'', \\<^bold>\\<not> Pro ''p''], a)])\n  [Node (Step (Close a (Pro ''p'')) 1\n    [([Pro ''p'', \\<^bold>\\<not> \\<^bold>\\<not> Pro ''p'', Pro ''q'', \\<^bold>\\<not> Pro ''p''], a)]) []])\\<close>\nproof -\n  have \\<open>wft A (Node (Step (Close a (Pro ''p'')) 1\n      [([Pro ''p'', \\<^bold>\\<not> \\<^bold>\\<not> Pro ''p'', Pro ''q'', \\<^bold>\\<not> Pro ''p''], a)]) [])\\<close>\n    using WfClose[where p=\\<open>Pro ''p''\\<close> and i=a] by simp\n  then show ?thesis\n    using WfNeg[where p=\\<open>Pro ''p''\\<close> and a=a] unfolding new_def by simp\nqed\n\nsection \\<open>Soundness\\<close>\n\nlemma fin_no_open_sound:\n  assumes \\<open>fin tab\\<close> \\<open>wft A tab\\<close> \\<open>alwt (holdst (\\<lambda>step. getTag step \\<noteq> Open)) tab\\<close>\n  shows \\<open>A, getPotential (getLabel tab) \\<turnstile> getBranch (getLabel tab)\\<close>\n  using assms\nproof (induct tab rule: fin.induct)\n  case (Fin subs l)\n  from this(3) show ?case\n  proof cases\n    case AlwT\n    with Fin(2, 1) show ?thesis\n      by cases (simp_all add: STA.intros)\n  qed\nqed\n\nlemma fin_no_open_sound_labels:\n  assumes \\<open>fin tab\\<close> \\<open>wft A tab\\<close> \\<open>\\<forall>l \\<in> labels tab. getTag l \\<noteq> Open\\<close>\n  shows \\<open>A, getPotential (getLabel tab) \\<turnstile> getBranch (getLabel tab)\\<close>\n  using assms fin_no_open_sound labels_alwt_holdst by blast\n\nsection \\<open>LTL\\<close>\n\nlemma alwt_wft: \\<open>alwt (wft A impl nxtt (wft A)) tab\\<close>\n  by (coinduction arbitrary: tab) (auto elim: wft.cases)\n\nlemma wft_alwt:\n  assumes \\<open>wft A tab\\<close> \\<open>\\<And>t. wft A t \\<Longrightarrow> P t\\<close>\n  shows \\<open>alwt P tab\\<close>\n  using assms by (coinduction arbitrary: tab) (auto elim: wft.cases)\n\nlemma wft_alwt_impl:\n  assumes \\<open>wft A tab\\<close> \\<open>\\<And>t. wft A t \\<Longrightarrow> P t \\<Longrightarrow> Q t\\<close>\n  shows \\<open>alwt (P impl Q) tab\\<close>\n  using assms by (coinduction arbitrary: tab) (auto elim: wft.cases)\n\nlemma wft_ipath:\n  assumes \\<open>wft A t\\<close> \\<open>ipath t s\\<close>\n  shows \\<open>\\<exists>t. wft A t \\<and> ipath t (stl s)\\<close>\n  using assms\nproof cases\n  case (WfClose p i branch n)\n  then show ?thesis\n    using assms(2) by (auto elim: ipath.cases)\nnext\n  case (WfOpen branch n)\n  then show ?thesis\n    using assms(2) by (auto elim: ipath.cases)\nnext\n  case (WfNeg p a ps branch s n)\n  from this(1, 6) show ?thesis\n    using assms(2) ipath.cases by fastforce\nnext\n  case (WfDisP p q a ps branch sl n sr)\n  from this(1, 9-10) show ?thesis\n    using assms(2) ipath.cases by fastforce\nnext\n  case (WfDisN p q a ps branch s n intro)\n  from this(1, 6) show ?thesis\n    using assms(2) ipath.cases by fastforce\nnext\n  case (WfDiaP p a ps branch i s n)\n  from this(1, 8) show ?thesis\n    using assms(2) ipath.cases by fastforce\nnext\n  case (WfDiaN p a ps branch i s n)\n  from this(1, 7) show ?thesis\n    using assms(2) ipath.cases by fastforce\nnext\n  case (WfSatP a p b ps branch s n)\n  from this(1, 6) show ?thesis\n    using assms(2) ipath.cases by fastforce\nnext\n  case (WfSatN a p b ps branch s n)\n  from this(1, 6) show ?thesis\n    using assms(2) ipath.cases by fastforce\nnext\n  case (WfGoTo i branch s n)\n  from this(1, 5) show ?thesis\n    using assms(2) ipath.cases by fastforce\nnext\n  case (WfNom p b ps a branch s n)\n  from this(1, 8) show ?thesis\n    using assms(2) ipath.cases by fastforce\nqed\n\nlemma wft_alw:\n  assumes \\<open>wft A t\\<close>  \\<open>ipath t s\\<close> \\<open>\\<And>t. wft A t \\<Longrightarrow> relt r t\\<close>\n  shows \\<open>alw (rels r) s\\<close>\n  using assms\nproof (coinduction arbitrary: s t)\n  case alw\n  then have ?case if \\<open>rels r s\\<close> \\<open>\\<exists>t. wft A t \\<and> ipath t (stl s)\\<close>\n    using that by simp\n  moreover from alw have \\<open>rels r s\\<close>\n    using relt_ipath by fast\n  moreover have \\<open>\\<exists>t. wft A t \\<and> ipath t (stl s)\\<close>\n    using alw wft_ipath by fast\n  ultimately show ?case .\nqed\n\nlemma alwt_aand:\n  assumes \\<open>alwt P t\\<close> \\<open>alwt Q t\\<close>\n  shows \\<open>alwt (P aand Q) t\\<close>\n  using assms by (coinduction arbitrary: t) (auto elim: alwt.cases)\n\nlemma alwt_nxtt:\n  assumes \\<open>alwt P t\\<close> \\<open>\\<And>t. P t \\<Longrightarrow> Q t \\<Longrightarrow> nxtt Q t\\<close> \\<open>Q t\\<close>\n  shows \\<open>alwt Q t\\<close>\n  using assms by (coinduction arbitrary: t) (auto elim: alwt.cases)\n\nlemma holds_holdst:\n  assumes \\<open>ipath t s\\<close> \\<open>holdst P t\\<close>\n  shows \\<open>holds P s\\<close>\n  using assms by (auto elim: ipath.cases)\n\n(* TODO: unused *)\nlemma alw_impl:\n  assumes \\<open>alw (P impl Q) s\\<close> \\<open>P (sdrop k s)\\<close>\n  shows \\<open>Q (sdrop k s)\\<close>\n  using assms by (simp add: alw_iff_sdrop)\n\nlemma alwt_aand_E1: \\<open>alwt (P aand Q) t \\<Longrightarrow> alwt P t\\<close>\n  by (coinduction arbitrary: t) (auto elim: alwt.cases)\n\nlemma alwt_aand_E2: \\<open>alwt (P aand Q) t \\<Longrightarrow> alwt Q t\\<close>\n  by (coinduction arbitrary: t) (auto elim: alwt.cases)\n\nlemma wft_ipath_sdrop:\n  assumes \\<open>wft A tab\\<close> \\<open>ipath tab steps\\<close>\n  shows \\<open>\\<exists>tab. wft A tab \\<and> ipath tab (sdrop n steps)\\<close>\n  using assms\nproof (induct n)\n  case (Suc n)\n  then show ?case\n    using wft_ipath by fastforce\nqed auto\n\nsection \\<open>Preservation\\<close>\n\nlemma preservation_Next:\n  assumes \\<open>wft A tab\\<close>\n  shows \\<open>relt (Impl (\\<lambda>l. p at a in getBranch l) (Next (Here (\\<lambda>l. p at a in getBranch l)))) tab\\<close>\n  using assms\nproof cases\n  case (WfDisP p q a ps branch sl n sr)\n  from this(1, 5, 7) show ?thesis\n    by fastforce\nnext\n  case (WfDisN p q a ps branch s n intro)\n  from this(1, 4) show ?thesis\n    by fastforce\nnext\n  case (WfDiaN p a ps branch i s n)\n  from this(1, 5) show ?thesis\n    by fastforce\nnext\n  case (WfNom p b ps a branch s n)\n  from this(1, 6) show ?thesis\n    by fastforce\nqed fastforce+\n\nlemma preservation_alw:\n  assumes \\<open>wft A tab\\<close> \\<open>ipath tab steps\\<close>\n  shows \\<open>alw (holds (\\<lambda>l. p at a in getBranch l)\n   impl (nxt (holds (\\<lambda>l. p at a in getBranch l)))) steps\\<close>\nproof -\n  have \\<open>alw (rels (Impl (\\<lambda>l. p at a in getBranch l)\n      (Next (Here (\\<lambda>l. p at a in getBranch l))))) steps\\<close>\n    using wft_alw assms preservation_Next .\n  then show ?thesis\n    by simp\nqed\n\n(* TODO: is this nice to have on top? *)\nlemma preservation_invar:\n  assumes \\<open>wft A tab\\<close> \\<open>ipath tab steps\\<close> \\<open>holds (\\<lambda>l. p at a in getBranch l) steps\\<close>\n  shows \\<open>alw (holds (\\<lambda>l. p at a in getBranch l)) steps\\<close>\nproof -\n  have \\<open>alw (holds (\\<lambda>l. p at a in getBranch l)\n  impl (nxt (holds (\\<lambda>l. p at a in getBranch l)))) steps\\<close>\n    using assms preservation_alw by fast\n  then show ?thesis\n    using alw_invar assms(3) by blast\nqed\n\nsection \\<open>Nominals\\<close>\n\n(* TODO: think about this. It's not local since it uses labels *)\nsubsection \\<open>Generated\\<close>\n\nfun generates :: \\<open>('a, 'b) tag \\<Rightarrow> 'b set\\<close> where\n  \\<open>generates (Fresh _  _ b) = {b}\\<close>\n| \\<open>generates _ = {}\\<close>\n\ndefinition generated :: \\<open>('a, 'b) tableau \\<Rightarrow> 'b set\\<close> where\n  \\<open>generated tab \\<equiv> \\<Union>step \\<in> labels tab. generates (getTag step)\\<close>\n\ndefinition generated_ipath :: \\<open>('a, 'b) step stream \\<Rightarrow> 'b set\\<close> where\n  \\<open>generated_ipath steps \\<equiv> \\<Union>step \\<in> sset steps. generates (getTag step)\\<close>\n\nlemma nxtt_generated:\n  assumes \\<open>wft A tab\\<close> \\<open>generated tab \\<subseteq> B\\<close>\n  shows \\<open>nxtt (\\<lambda>t. generated t \\<subseteq> B) tab\\<close>\n  using assms unfolding generated_def\n  by (fastforce elim: wft.cases)\n\nlemma alwt_generated:\n  assumes \\<open>wft A tab\\<close>\n  shows \\<open>alwt ((\\<lambda>t. generated t \\<subseteq> B) impl nxtt (\\<lambda>t. generated t \\<subseteq> B)) tab\\<close>\n  using wft_alwt_impl assms nxtt_generated .\n\nlemma wft_generated_nxtt:\n  assumes \\<open>wft A tab\\<close> \\<open>generated tab \\<subseteq> B\\<close>\n    \\<open>holdst (\\<lambda>t. \\<forall>i \\<in> branch_nominals (getBranch t). i \\<in> orig \\<or> i \\<in> B) tab\\<close>\n  shows \\<open>nxtt (holdst (\\<lambda>s. \\<forall>i \\<in> branch_nominals (getBranch s). i \\<in> orig \\<or> i \\<in> B)) tab\\<close>\n  using assms\nproof cases\n  case (WfNeg p a ps branch s n)\n  moreover from this(2) have\n    \\<open>branch_nominals ((p # ps, a) # branch) \\<subseteq> branch_nominals ((ps, a) # branch)\\<close>\n    using WfNeg(2) unfolding branch_nominals_def by fastforce\n  ultimately show ?thesis\n    using assms(3) by auto\nnext\n  case (WfDisP p q a ps branch sl n sr)\n  moreover from this(2) have\n    \\<open>branch_nominals ((p # ps, a) # branch) \\<subseteq> branch_nominals ((ps, a) # branch)\\<close>\n    \\<open>branch_nominals ((q # ps, a) # branch) \\<subseteq> branch_nominals ((ps, a) # branch)\\<close>\n    unfolding branch_nominals_def by fastforce+\n  ultimately show ?thesis\n    using assms(3) by auto\nnext\n  case (WfDisN p q a ps branch s n intro)\n  moreover from this(2) have\n    \\<open>branch_nominals (((\\<^bold>\\<not> q) # (\\<^bold>\\<not> p) # ps, a) # branch) \\<subseteq> branch_nominals ((ps, a) # branch)\\<close>\n    unfolding branch_nominals_def by fastforce\n  ultimately show ?thesis\n    using assms(3) by auto\nnext\n  case (WfDiaP p a ps branch i s n)\n  have \\<open>branch_nominals (((\\<^bold>@ i p) # (\\<^bold>\\<diamond> Nom i) # ps, a) # branch) =\n          {i} \\<union> nominals p \\<union> branch_nominals ((ps, a) # branch)\\<close>\n    unfolding branch_nominals_def by auto\n  moreover have \\<open>nominals p \\<subseteq> branch_nominals ((ps, a) # branch)\\<close>\n    using WfDiaP(2) unfolding branch_nominals_def by fastforce\n  then have \\<open>\\<forall>i \\<in> nominals p. i \\<in> orig \\<or> i \\<in> B\\<close>\n    using WfDiaP(1) assms(3) by auto\n  ultimately have ?thesis if \\<open>i \\<in> B\\<close>\n    using that WfDiaP(1, 6) assms(3) by auto\n  moreover have \\<open>i \\<in> B\\<close>\n    using WfDiaP(1) assms(2) unfolding generated_def by simp\n  ultimately show ?thesis\n    using WfDiaP(1, 8) by fastforce\nnext\n  case (WfDiaN p a ps branch i s n)\n  moreover have \\<open>nominals (\\<^bold>\\<not> (\\<^bold>@ i p)) \\<subseteq> branch_nominals ((ps, a) # branch)\\<close>\n    using WfDiaN(2-3) unfolding branch_nominals_def by fastforce\n  then have\n    \\<open>branch_nominals (((\\<^bold>\\<not> (\\<^bold>@ i p)) # ps, a) # branch) \\<subseteq> branch_nominals ((ps, a) # branch)\\<close>\n    using WfDiaN(2) unfolding branch_nominals_def by auto\n  ultimately show ?thesis\n    using assms(3) unfolding generated_def by auto\nnext\n  case (WfSatP a p b ps branch s n)\n  moreover have \\<open>branch_nominals ((p # ps, a) # branch) \\<subseteq> branch_nominals ((ps, a) # branch)\\<close>\n    using WfSatP(2) unfolding branch_nominals_def by fastforce\n  ultimately show ?thesis\n    using assms(3) unfolding generated_def by auto\nnext\n  case (WfSatN a p b ps branch s n)\n  moreover have \\<open>branch_nominals (((\\<^bold>\\<not> p) # ps, a) # branch) \\<subseteq> branch_nominals ((ps, a) # branch)\\<close>\n    using WfSatN(2) unfolding branch_nominals_def by fastforce\n  ultimately show ?thesis\n    using assms(3) unfolding generated_def by auto\nnext\n  case (WfGoTo i branch s n)\n  moreover have \\<open>branch_nominals (([], i) # branch) \\<subseteq> branch_nominals branch\\<close>\n    using WfGoTo(2) unfolding branch_nominals_def by simp\n  ultimately show ?thesis\n    using assms(3) unfolding generated_def by auto\nnext\n  case (WfNom p b ps a branch s n)\n  moreover have \\<open>branch_nominals ((p # ps, a) # branch) \\<subseteq> branch_nominals ((ps, a) # branch)\\<close>\n    using WfNom(2) unfolding branch_nominals_def by fastforce\n  ultimately show ?thesis\n    using assms(3) unfolding generated_def by (simp add: in_mono)\nqed simp_all\n\nlemma wft_generated':\n  assumes \\<open>wft A tab\\<close> \\<open>generated tab \\<subseteq> B\\<close>\n    \\<open>holdst (\\<lambda>t. \\<forall>i \\<in> branch_nominals (getBranch t). i \\<in> orig \\<or> i \\<in> B) tab\\<close>\n  shows \\<open>alwt (holdst (\\<lambda>step. \\<forall>i \\<in> branch_nominals (getBranch step). i \\<in> orig \\<or> i \\<in> B)) tab\\<close>\nproof -\n  have \\<open>alwt (wft A) tab\\<close>\n    using assms(1) wft_alwt by blast\n  moreover have \\<open>alwt (\\<lambda>t. generated t \\<subseteq> B) tab\\<close>\n    using alwt_impl_nxtt alwt_generated assms(1-2) .\n  ultimately have \\<open>alwt (wft A aand (\\<lambda>t. generated t \\<subseteq> B)) tab\\<close>\n    using alwt_aand by blast\n  with alwt_nxtt[where Q=\\<open>holdst (\\<lambda>t. \\<forall>i \\<in> branch_nominals (getBranch t). i \\<in> orig \\<or> i \\<in> B)\\<close>]\n  show ?thesis\n    using wft_generated_nxtt assms(3) by blast\nqed\n\nlemma wft_generated:\n  assumes \\<open>wft A tab\\<close>\n  shows \\<open>alwt (holdst (\\<lambda>step. \\<forall>i \\<in> branch_nominals (getBranch step).\n    i \\<in> branch_nominals (getBranch (getLabel tab)) \\<or> i \\<in> generated tab)) tab\\<close>\n  using assms wft_generated' by blast\n\nlemma wft_generated_ipath':\n  assumes \\<open>ipath tab steps\\<close> \\<open>wft A tab\\<close> \\<open>generated_ipath steps \\<subseteq> B\\<close>\n    \\<open>holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> orig \\<union> B) steps\\<close>\n  shows \\<open>alw (holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> orig \\<union> B)) steps\\<close>\n  using assms\nproof (coinduction arbitrary: tab steps)\n  case alw\n  then show ?case\n  proof cases\n    case (IPath s' subs tail l)\n    then have wft: \\<open>wft A s'\\<close>\n      using alw(2) by (auto elim: wft.cases)\n\n    with alw(2) show ?thesis\n    proof cases\n      case (WfClose p i branch n)\n      then show ?thesis\n        using IPath by simp\n    next\n      case (WfOpen branch n)\n      then show ?thesis\n        using IPath by simp\n    next\n      case (WfNeg p a ps branch s n)\n      from this(1) have ?thesis if \\<open>branch_nominals (getBranch (getLabel s)) \\<subseteq> orig \\<union> B\\<close>\n        using that wft IPath alw(3-) holds_holdst unfolding generated_ipath_def by fastforce\n      moreover have \\<open>nominals p \\<subseteq> orig \\<union> B\\<close>\n        using WfNeg(1-2) IPath alw(4) unfolding branch_nominals_def by fastforce\n      then have \\<open>branch_nominals (getBranch (getLabel s)) \\<subseteq> orig \\<union> B\\<close>\n        using WfNeg(1, 4) IPath alw(4) unfolding branch_nominals_def by simp\n      ultimately show ?thesis\n        by simp\n    next\n      case (WfDisP p q a ps branch sl n sr)\n      have ?thesis if\n        \\<open>branch_nominals (getBranch (getLabel s')) \\<subseteq> orig \\<union> B\\<close>\n        using that wft IPath alw(3-) holds_holdst unfolding generated_ipath_def by fastforce\n      moreover have \\<open>s' = sl \\<or> s' = sr\\<close>\n        using WfDisP(1) IPath by simp\n      moreover have \\<open>nominals p \\<subseteq> orig \\<union> B\\<close> \\<open>nominals q \\<subseteq> orig \\<union> B\\<close>\n        using WfDisP(1-2) IPath alw(4) unfolding branch_nominals_def by fastforce+\n      then have\n        \\<open>branch_nominals (getBranch (getLabel sl)) \\<subseteq> orig \\<union> B\\<close>\n        \\<open>branch_nominals (getBranch (getLabel sr)) \\<subseteq> orig \\<union> B\\<close>\n        using WfDisP(1, 5, 7) IPath alw(4) unfolding branch_nominals_def by simp_all\n      ultimately show ?thesis\n        by blast\n    next\n      case (WfDisN p q a ps branch s n intro)\n      from this(1) have ?thesis if \\<open>branch_nominals (getBranch (getLabel s)) \\<subseteq> orig \\<union> B\\<close>\n        using that wft IPath alw(3-) holds_holdst unfolding generated_ipath_def by fastforce\n      moreover have \\<open>nominals p \\<subseteq> orig \\<union> B\\<close> \\<open>nominals q \\<subseteq> orig \\<union> B\\<close>\n        using WfDisN(1-2) IPath alw(4) unfolding branch_nominals_def by fastforce+\n      then have \\<open>branch_nominals (getBranch (getLabel s)) \\<subseteq> orig \\<union> B\\<close>\n        using WfDisN(1, 4) IPath alw(4) unfolding branch_nominals_def by simp\n      ultimately show ?thesis\n        by simp\n    next\n      case (WfDiaP p a ps branch i s n)\n      from this(1) have ?thesis if \\<open>branch_nominals (getBranch (getLabel s)) \\<subseteq> orig \\<union> B\\<close>\n        using that wft IPath alw(3-) holds_holdst unfolding generated_ipath_def by fastforce\n      moreover {\n        have \\<open>nominals p \\<subseteq> orig \\<union> B\\<close>\n          using WfDiaP(1-2) IPath alw(4) unfolding branch_nominals_def by fastforce\n        moreover have \\<open>i \\<in> B\\<close>\n          using WfDiaP(1) IPath alw(3) unfolding generated_ipath_def by simp\n        ultimately have \\<open>branch_nominals (getBranch (getLabel s)) \\<subseteq> orig \\<union> B\\<close>\n          using WfDiaP(1, 6) IPath alw(4) unfolding branch_nominals_def by simp\n      }\n      ultimately show ?thesis\n        by simp\n    next\n      case (WfDiaN p a ps branch i s n)\n      from this(1) have ?thesis if \\<open>branch_nominals (getBranch (getLabel s)) \\<subseteq> orig \\<union> B\\<close>\n        using that wft IPath alw(3-) holds_holdst unfolding generated_ipath_def by fastforce\n      moreover {\n        have \\<open>nominals p \\<subseteq> orig \\<union> B\\<close>\n          using WfDiaN(1-2) IPath alw(4) unfolding branch_nominals_def by fastforce\n        moreover have \\<open>i \\<in> orig \\<union> B\\<close>\n          using WfDiaN(1, 3) IPath alw(4) unfolding branch_nominals_def by fastforce\n        ultimately have \\<open>branch_nominals (getBranch (getLabel s)) \\<subseteq> orig \\<union> B\\<close>\n          using WfDiaN(1, 5) IPath alw(4) unfolding branch_nominals_def by simp\n      }\n      ultimately show ?thesis\n        by simp\n    next\n      case (WfSatP a p b ps branch s n)\n      from this(1) have ?thesis if \\<open>branch_nominals (getBranch (getLabel s)) \\<subseteq> orig \\<union> B\\<close>\n        using that wft IPath alw(3-) holds_holdst unfolding generated_ipath_def by fastforce\n      moreover have \\<open>nominals p \\<subseteq> orig \\<union> B\\<close>\n        using WfSatP(1-2) IPath alw(4) unfolding branch_nominals_def by force\n      then have \\<open>branch_nominals (getBranch (getLabel s)) \\<subseteq> orig \\<union> B\\<close>\n        using WfSatP(1, 4) IPath alw(4) unfolding branch_nominals_def by simp\n      ultimately show ?thesis\n        by simp\n    next\n      case (WfSatN a p b ps branch s n)\n      from this(1) have ?thesis if \\<open>branch_nominals (getBranch (getLabel s)) \\<subseteq> orig \\<union> B\\<close>\n        using that wft IPath alw(3-) holds_holdst unfolding generated_ipath_def by fastforce\n      moreover have \\<open>nominals p \\<subseteq> orig \\<union> B\\<close>\n        using WfSatN(1-2) IPath alw(4) unfolding branch_nominals_def by force\n      then have \\<open>branch_nominals (getBranch (getLabel s)) \\<subseteq> orig \\<union> B\\<close>\n        using WfSatN(1, 4) IPath alw(4) unfolding branch_nominals_def by simp\n      ultimately show ?thesis\n        by simp\n    next\n      case (WfGoTo i branch s n)\n      from this(1) have ?thesis if \\<open>branch_nominals (getBranch (getLabel s)) \\<subseteq> orig \\<union> B\\<close>\n        using that wft IPath alw(3-) holds_holdst unfolding generated_ipath_def by fastforce\n      moreover have \\<open>i \\<in> orig \\<union> B\\<close>\n        using WfGoTo(1-2) IPath alw(4) unfolding branch_nominals_def by auto\n      then have \\<open>branch_nominals (getBranch (getLabel s)) \\<subseteq> orig \\<union> B\\<close>\n        using WfGoTo(1, 3) IPath alw(4) unfolding branch_nominals_def by simp\n      ultimately show ?thesis\n        by simp\n    next\n      case (WfNom p b ps a branch s n)\n      from this(1) have ?thesis if \\<open>branch_nominals (getBranch (getLabel s)) \\<subseteq> orig \\<union> B\\<close>\n        using that wft IPath alw(3-) holds_holdst unfolding generated_ipath_def by fastforce\n      moreover have \\<open>nominals p \\<subseteq> orig \\<union> B\\<close>\n        using WfNom(1-2) IPath alw(4) unfolding branch_nominals_def by fastforce\n      then have \\<open>branch_nominals (getBranch (getLabel s)) \\<subseteq> orig \\<union> B\\<close>\n        using WfNom(1, 6) IPath alw(4) unfolding branch_nominals_def by simp\n      ultimately show ?thesis\n        by simp\n    qed\n  qed\nqed\n\nlemma wft_generated_ipath:\n  assumes \\<open>ipath tab steps\\<close> \\<open>wft A tab\\<close>\n  shows \\<open>alw (holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq>\n      branch_nominals (getBranch (shd steps)) \\<union> generated_ipath steps)) steps\\<close>\n  using assms wft_generated_ipath' by fastforce\n\nlemma wft_generated_labels:\n  assumes \\<open>wft A tab\\<close> \\<open>step \\<in> labels tab\\<close> \\<open>i \\<in> branch_nominals (getBranch step)\\<close>\n  shows \\<open>i \\<in> branch_nominals (getBranch (getLabel tab)) \\<or> i \\<in> generated tab\\<close>\n  using assms wft_generated alwt_holdst_labels by fast\n\nsection \\<open>Quasi subformulas\\<close>\n\nsubsection \\<open>Quasis\\<close>\n\nfun quasis :: \\<open>'b set \\<Rightarrow> ('a, 'b) fm \\<Rightarrow> ('a, 'b) fm set\\<close> where\n  \\<open>quasis A (\\<^bold>\\<not> \\<^bold>\\<not> p) = {p} \\<union> quasis A p\\<close>\n| \\<open>quasis A (p \\<^bold>\\<or> q) = {p, q} \\<union> quasis A p \\<union> quasis A q\\<close>\n| \\<open>quasis A (\\<^bold>\\<not> (p \\<^bold>\\<or> q)) = {\\<^bold>\\<not> p, \\<^bold>\\<not> q} \\<union> quasis A (\\<^bold>\\<not> p) \\<union> quasis A (\\<^bold>\\<not> q)\\<close>\n| \\<open>quasis A (\\<^bold>\\<diamond> p) = (if \\<exists>a. p = Nom a then {} else {\\<^bold>@ i p |i. i \\<in> A} \\<union> {p} \\<union> quasis A p)\\<close>\n| \\<open>quasis A (\\<^bold>\\<not> (\\<^bold>\\<diamond> p)) = {\\<^bold>\\<not> (\\<^bold>@ i p) |i. i \\<in> A} \\<union> {\\<^bold>\\<not> p} \\<union> quasis A (\\<^bold>\\<not> p)\\<close>\n| \\<open>quasis A (\\<^bold>@ i p) = {p} \\<union> quasis A p\\<close>\n| \\<open>quasis A (\\<^bold>\\<not> (\\<^bold>@ i p)) = {\\<^bold>\\<not> p} \\<union> quasis A (\\<^bold>\\<not> p)\\<close>\n| \\<open>quasis _ p = {p}\\<close>\n\nlemma quasis_subset_closed: \\<open>p' \\<in> quasis A p \\<Longrightarrow> quasis A p' \\<subseteq> quasis A p\\<close>\n  by (induct p rule: quasis.induct) (auto split: if_splits)\n\nlemma finite_quasis: \\<open>finite A \\<Longrightarrow> finite (quasis A p)\\<close>\n  by (induct p rule: quasis.induct) auto\n\ndefinition branch_formulas :: \\<open>('a, 'b) branch \\<Rightarrow> ('a, 'b) fm set\\<close> where\n  \\<open>branch_formulas branch \\<equiv> \\<Union>(ps, i) \\<in> set branch. {Nom i} \\<union> set ps\\<close>\n\nlemma finite_branch_formulas: \\<open>finite (branch_formulas branch)\\<close>\n  unfolding branch_formulas_def by auto\n\ndefinition formula_bound :: \\<open>'b set \\<Rightarrow> ('a, 'b) branch \\<Rightarrow> ('a, 'b) fm set\\<close> where\n  \\<open>formula_bound B branch \\<equiv>\n    branch_formulas branch \\<union>\n    (\\<Union>p \\<in> branch_formulas branch. quasis B p) \\<union>\n    (\\<Union>i \\<in> B. {Nom i, \\<^bold>\\<diamond> Nom i})\\<close>\n\nlemma finite_formula_bound: \\<open>finite B \\<Longrightarrow> finite (formula_bound B branch)\\<close>\n  unfolding formula_bound_def using finite_branch_formulas finite_quasis by auto\n\nlemma formula_bound_quasis: \\<open>\\<forall>p \\<in> formula_bound B branch. quasis B p \\<subseteq> formula_bound B branch\\<close>\n  unfolding formula_bound_def using quasis_subset_closed by fastforce\n\n(* TODO: may not need rest of section *)\n\nlemma branch_formulas_Cons [simp]:\n  \\<open>branch_formulas ((p # ps, a) # branch) = {p} \\<union> branch_formulas ((ps, a) # branch)\\<close>\n  unfolding branch_formulas_def by simp\n\nlemma at_in_branch_formulas: \\<open>p at a in branch \\<Longrightarrow> p \\<in> branch_formulas branch\\<close>\n  unfolding branch_formulas_def by auto\n\nlemma branch_nominals_there:\n  assumes \\<open>p' at b in ((ps, a) # branch)\\<close> \\<open>nominals p \\<subseteq> nominals p'\\<close>\n    \\<open>branch_nominals ((ps, a) # branch) \\<subseteq> B\\<close>\n  shows \\<open>branch_nominals ((p # ps, a) # branch) \\<subseteq> B\\<close>\nproof -\n  have \\<open>nominals p \\<subseteq> branch_nominals ((ps, a) # branch)\\<close>\n    using assms(1-2) unfolding branch_nominals_def by fastforce\n  then have \\<open>nominals p \\<subseteq> B\\<close>\n    using assms(3) by simp\n  then show ?thesis\n    using assms(3) unfolding branch_nominals_def by simp\nqed\n\nlemma branch_nominals_Cons [simp]:\n  \\<open>branch_nominals ((p # ps, a) # branch) = nominals p \\<union> branch_nominals ((ps, a) # branch)\\<close>\n  unfolding branch_nominals_def by auto\n\nsection \\<open>Finite Intro Rules\\<close>\n\nfun introduces :: \\<open>('a, 'b) tag \\<Rightarrow> (('a, 'b) fm list list \\<times> 'b) option\\<close> where\n  \\<open>introduces (Rule a ps) = Some (ps, a)\\<close>\n| \\<open>introduces (Fresh a p i) = Some ([[\\<^bold>@ i p, \\<^bold>\\<diamond> Nom i]], a)\\<close>\n| \\<open>introduces _ = None\\<close>\n\nsubsection \\<open>Distinct\\<close>\n\nlemma introduces_new:\n  assumes \\<open>wft A tab\\<close>\n  shows \\<open>relt (Here (\\<lambda>t. \\<forall>pps a. introduces (getTag t) = Some (pps, a) \\<longrightarrow>\n      (\\<forall>ps \\<in> set pps. \\<forall>p \\<in> set ps. new p a (getBranch t)))) tab\\<close>\n  using assms\nproof cases\n  case (WfDiaP p a ps branch i s n)\n  from this(1, 3) show ?thesis\n    unfolding branch_nominals_def new_def by fastforce\nqed auto\n\nlemma introduces_new_ipath:\n  assumes \\<open>wft A tab\\<close> \\<open>ipath tab steps\\<close>\n  shows \\<open>alw (holds (\\<lambda>t. \\<forall>pps a. introduces (getTag t) = Some (pps, a) \\<longrightarrow>\n      (\\<forall>ps \\<in> set pps. \\<forall>p \\<in> set ps. new p a (getBranch t)))) steps\\<close>\nproof -\n  have \\<open>alw (rels (Here (\\<lambda>t. \\<forall>pps a. introduces (getTag t) = Some (pps, a) \\<longrightarrow>\n      (\\<forall>ps \\<in> set pps. \\<forall>p \\<in> set ps. new p a (getBranch t))))) steps\\<close>\n  using wft_alw assms introduces_new .\n  then show ?thesis\n    by simp\nqed\n\nlemma introduces_Next:\n  assumes \\<open>wft A tab\\<close>\n  shows \\<open>relt (Impl (\\<lambda>t. introduces (getTag t) = Some (pps, a))\n      (Next (Here (\\<lambda>s. \\<exists>ps \\<in> set pps. ps \\<noteq> [] \\<and> (\\<forall>p \\<in> set ps. p at a in getBranch s))))) tab\\<close>\n  using assms\nproof cases\n  case (WfDisP p q a ps branch sl n sr)\n  then show ?thesis\n    by force\nnext\n  case (WfNom p b ps a branch s n)\n  from this(1, 6) show ?thesis\n    by fastforce\nqed fastforce+\n\nlemma introduces_alw_nxt:\n  assumes \\<open>wft A tab\\<close> \\<open>ipath tab steps\\<close>\n  shows \\<open>alw (holds (\\<lambda>t. introduces (getTag t) = Some (pps, a))\n   impl (nxt (holds (\\<lambda>s. \\<exists>ps \\<in> set pps. ps \\<noteq> [] \\<and> (\\<forall>p \\<in> set ps. p at a in getBranch s))))) steps\\<close>\nproof -\n  have \\<open>alw (rels (Impl (\\<lambda>t. introduces (getTag t) = Some (pps, a))\n      (Next (Here (\\<lambda>s. \\<exists>ps \\<in> set pps. ps \\<noteq> [] \\<and> (\\<forall>p \\<in> set ps. p at a in getBranch s)))))) steps\\<close>\n    using wft_alw assms introduces_Next .\n  then show ?thesis\n    by simp\nqed\n\n(* TODO: preservation-invar requires finding a tab in ipath tab (sdrop m steps)\n  [2021-06-10: I don't know what this means anymore]\n*)\n\nlemma distinct_introduces:\n  assumes \\<open>wft A tab\\<close> \\<open>ipath tab steps\\<close> \\<open>steps !! m = s\\<close> \\<open>steps !! n = s'\\<close> \\<open>m < n\\<close>\n    \\<open>introduces (getTag s) = Some (pps, a)\\<close> \\<open>introduces (getTag s') = Some (qqs, b)\\<close>\n  shows \\<open>(pps, a) \\<noteq> (qqs, b)\\<close>\nproof\n  assume \\<open>(pps, a) = (qqs, b)\\<close>\n\n  have \\<open>alw (holds (\\<lambda>t. introduces (getTag t) = Some (pps, a))\n   impl nxt (holds (\\<lambda>s. \\<exists>ps\\<in>set pps. ps \\<noteq> [] \\<and> (\\<forall>p \\<in> set ps. p at a in getBranch s)))) steps\\<close>\n    using introduces_alw_nxt assms(1-2) .\n  then have \\<open>holds (\\<lambda>s. \\<exists>ps\\<in>set pps. ps \\<noteq> [] \\<and>\n      (\\<forall>p \\<in> set ps. p at a in getBranch s)) (sdrop (Suc m) steps)\\<close>\n    using assms(3, 6) by (simp add: alw_iff_sdrop)\n  then obtain ps where\n    \\<open>ps \\<in>. pps\\<close>\n    \\<open>ps \\<noteq> []\\<close>\n    \\<open>\\<forall>p \\<in> set ps. holds (\\<lambda>s. p at a in getBranch s) (sdrop (Suc m) steps)\\<close>\n    by auto\n  moreover have \\<open>alw (holds (\\<lambda>l. p at a in getBranch l)\n            impl nxt (holds (\\<lambda>l. p at a in getBranch l))) steps\\<close> for p\n    using preservation_alw assms(1-2) .\n  then have \\<open>alw (holds (\\<lambda>l. p at a in getBranch l)\n        impl nxt (holds (\\<lambda>l. p at a in getBranch l))) (sdrop (Suc m) steps)\\<close> for p\n    using alw_sdrop by blast\n  ultimately have \\<open>\\<forall>p \\<in> set ps. alw (holds (\\<lambda>l. p at a in getBranch l)) (sdrop (Suc m) steps)\\<close>\n    using alw_invar by blast\n  then have \\<open>\\<forall>p \\<in> set ps. holds (\\<lambda>l. p at a in getBranch l) (sdrop n steps)\\<close>\n    using \\<open>m < n\\<close> by (auto simp: alw_iff_sdrop elim: less_natE)\n\n  moreover have \\<open>alw (holds (\\<lambda>l. \\<forall>pps a. introduces (getTag l) = Some (pps, a) \\<longrightarrow>\n    (\\<forall>ps \\<in> set pps. \\<forall>p\\<in>set ps. new p a (getBranch l)))) steps\\<close>\n    using introduces_new_ipath assms(1-2) .\n  then have \\<open>alw (holds (\\<lambda>l. \\<forall>pps a. introduces (getTag l) = Some (pps, a) \\<longrightarrow>\n    (\\<forall>ps \\<in> set pps. \\<forall>p\\<in>set ps. new p a (getBranch l)))) (sdrop n steps)\\<close>\n   by (simp add: alw_iff_sdrop)\n  then have \\<open>\\<forall>qs \\<in> set qqs. \\<forall>q\\<in>set qs. holds (\\<lambda>l. new q b (getBranch l)) (sdrop n steps)\\<close>\n    using assms(4, 7) by auto\n  then have \\<open>\\<forall>p\\<in>set ps. holds (\\<lambda>l. \\<not> p at a in (getBranch l)) (sdrop n steps)\\<close>\n    unfolding new_def using \\<open>ps \\<in>. pps\\<close> \\<open>(pps, a) = (qqs, b)\\<close> by simp\n  ultimately show False\n    by (cases ps) (auto simp: \\<open>ps \\<noteq> []\\<close>)    \nqed\n\nsubsection \\<open>Quasi\\<close>\n\nlemma wft_introduces_quasis_ipath':\n  assumes\n    \\<open>ipath tab steps\\<close> \\<open>wft A tab\\<close>\n    \\<open>generated_ipath steps \\<subseteq> B\\<close>\n    \\<open>holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) steps\\<close>\n    \\<open>holds (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) steps\\<close>\n    and X: \\<open>\\<forall>x \\<in> X. quasis B x \\<subseteq> X\\<close> and Xi: \\<open>\\<forall>i \\<in> B. {Nom i, \\<^bold>\\<diamond> Nom i} \\<subseteq> X\\<close>\n  shows \\<open>alw (holds (\\<lambda>step.\n      (\\<forall>pps a. introduces (getTag step) = Some (pps, a) \\<longrightarrow> set (concat pps) \\<subseteq> X) \\<and>\n      (\\<forall>a p i. getTag step = Fresh a p i \\<longrightarrow> (\\<nexists>a. p = Nom a) \\<and> (\\<^bold>\\<diamond> p) \\<in> X))) steps\\<close>\n  using assms(1-5)\nproof (coinduction arbitrary: tab steps)\n  case alw\n  then show ?case\n  proof cases\n    case (IPath s' subs tail l)\n    then have wft: \\<open>wft A s'\\<close>\n      using alw(2) wft_alwt by (auto elim: wft.cases)\n    from alw(2) show ?thesis\n    proof cases\n      case (WfClose p i branch n)\n      then show ?thesis\n        using IPath by simp\n    next\n      case (WfOpen branch n)\n      then show ?thesis\n        using IPath by simp\n    next\n      case (WfNeg p a ps branch s n)\n      from this(1) have s: \\<open>s' = s\\<close>\n        using IPath by simp\n\n      have ?thesis if\n        \\<open>p \\<in> X\\<close>\n        \\<open>holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) tail\\<close>\n        \\<open>holds (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) tail\\<close>\n        using that wft WfNeg(1) alw(3-) IPath unfolding generated_ipath_def by auto\n\n      moreover have \\<open>(\\<^bold>\\<not> \\<^bold>\\<not> p) \\<in> X\\<close>\n        using WfNeg(1, 2) IPath alw(5) at_in_branch_formulas\n        by (metis holds_Stream insert_subset mk_disjoint_insert step.sel(3) tree.inject)\n      then have \\<open>p \\<in> X\\<close>\n        using X by auto\n\n      moreover have \\<open>holdst (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) s\\<close>\n        using WfNeg(1-2, 4) IPath alw(4) branch_nominals_there[where p=p] by fastforce\n      then have \\<open>holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) tail\\<close>\n        using s IPath holds_holdst by fast\n\n      moreover have \\<open>holdst (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) s\\<close>\n        using WfNeg(1, 4) alw(5) \\<open>p \\<in> X\\<close> IPath(1-2) by auto\n      then have \\<open>holds (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) tail\\<close>\n        using s IPath holds_holdst by fast\n\n      ultimately show ?thesis\n        by simp\n    next\n      case (WfDisP p q a ps branch sl n sr)\n      from this(1) have s: \\<open>s' = sl \\<or> s' = sr\\<close>\n        using IPath by simp\n\n      have ?thesis if\n        \\<open>p \\<in> X\\<close> \\<open>q \\<in> X\\<close>\n        \\<open>holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) tail\\<close>\n        \\<open>holds (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) tail\\<close>\n        using that wft WfDisP(1) alw(3-) IPath unfolding generated_ipath_def by auto\n\n      moreover have \\<open>(p \\<^bold>\\<or> q) \\<in> X\\<close>\n        using WfDisP(1, 2) IPath alw(5) at_in_branch_formulas\n        by (metis holds_Stream insert_subset mk_disjoint_insert step.sel(3) tree.inject)\n      then have \\<open>p \\<in> X\\<close> \\<open>q \\<in> X\\<close>\n        using X by auto\n\n      moreover {\n        have \\<open>holdst (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) sl\\<close>\n          using WfDisP(1-2, 5) IPath alw(4) branch_nominals_there[where p=p] by fastforce\n        moreover have \\<open>holdst (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) sr\\<close>\n          using WfDisP(1-2, 7) IPath alw(4) branch_nominals_there[where p=q] by fastforce\n        ultimately have \\<open>holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) tail\\<close>\n          using s IPath holds_holdst by fast\n      }\n\n      moreover have\n        \\<open>holdst (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) sl\\<close>\n        \\<open>holdst (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) sr\\<close>\n        using WfDisP(1, 5, 7) alw(5) \\<open>p \\<in> X\\<close> \\<open>q \\<in> X\\<close> IPath(1-2) by auto\n      then have \\<open>holds (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) tail\\<close>\n        using s IPath holds_holdst by fast\n\n      ultimately show ?thesis\n        by simp\n    next\n      case (WfDisN p q a ps branch s n intro)\n      from this(1) have s: \\<open>s' = s\\<close>\n        using IPath by simp\n\n      have ?thesis if\n        \\<open>(\\<^bold>\\<not> p) \\<in> X\\<close> \\<open>(\\<^bold>\\<not> q) \\<in> X\\<close>\n        \\<open>holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) tail\\<close>\n        \\<open>holds (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) tail\\<close>\n        using that wft WfDisN(1, 7) alw(3-) IPath unfolding generated_ipath_def by auto\n\n      moreover have \\<open>(\\<^bold>\\<not> (p \\<^bold>\\<or> q)) \\<in> X\\<close>\n        using WfDisN(1, 2) IPath alw(5) at_in_branch_formulas\n        by (metis holds_Stream insert_subset mk_disjoint_insert step.sel(3) tree.inject)\n      then have \\<open>(\\<^bold>\\<not> p) \\<in> X\\<close> \\<open>(\\<^bold>\\<not> q) \\<in> X\\<close>\n        using X by auto\n\n      moreover {\n        have \\<open>branch_nominals (((\\<^bold>\\<not> q) # (\\<^bold>\\<not> p) # ps, a) # branch) \\<subseteq> nominals p \\<union> nominals q \\<union> B\\<close>\n          using WfDisN(1-2) IPath alw(4) by auto\n        moreover have \\<open>nominals p \\<subseteq> B\\<close> \\<open>nominals q \\<subseteq> B\\<close>\n          using WfDisN(1-2) IPath(1-2) alw(4) unfolding branch_nominals_def by force+\n        ultimately have \\<open>holdst (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) s\\<close>\n          using WfDisN(1, 4) IPath alw(4) by simp\n        then have \\<open>holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) tail\\<close>\n          using s IPath holds_holdst by fast\n      }\n\n      moreover have \\<open>holdst (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) s\\<close>\n        using WfDisN(1, 4) alw(5) \\<open>(\\<^bold>\\<not> p) \\<in> X\\<close> \\<open>(\\<^bold>\\<not> q) \\<in> X\\<close> IPath(1-2) by auto\n      then have \\<open>holds (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) tail\\<close>\n        using s IPath holds_holdst by fast\n\n      ultimately show ?thesis\n        by simp\n    next\n      case (WfDiaP p a ps branch i s n)\n      from this(1) have s: \\<open>s' = s\\<close>\n        using IPath by simp\n\n      have ?thesis if\n        \\<open>(\\<^bold>@ i p) \\<in> X\\<close> \\<open>(\\<^bold>\\<diamond> Nom i) \\<in> X\\<close> \\<open>(\\<^bold>\\<diamond> p) \\<in> X\\<close>\n        \\<open>holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) tail\\<close>\n        \\<open>holds (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) tail\\<close>\n        using that wft WfDiaP(1, 4) alw(3-) IPath unfolding generated_ipath_def by auto\n\n      moreover have \\<open>i \\<in> B\\<close>\n        using WfDiaP(1) alw(3) IPath unfolding generated_ipath_def by simp\n\n      moreover have \\<open>(\\<^bold>\\<diamond> p) \\<in> X\\<close>\n        using WfDiaP(1, 2) IPath alw(5) at_in_branch_formulas\n        by (metis holds_Stream insert_subset mk_disjoint_insert step.sel(3) tree.inject)\n      moreover from this have \\<open>(\\<^bold>@ i p) \\<in> X\\<close> \\<open>(\\<^bold>\\<diamond> Nom i) \\<in> X\\<close>\n        using \\<open>i \\<in> B\\<close> WfDiaP(4) X Xi by fastforce+\n\n      moreover {\n        have \\<open>branch_nominals (((\\<^bold>@ i p) # (\\<^bold>\\<diamond> Nom i) # ps, a) # branch) \\<subseteq> {i} \\<union> nominals p \\<union> B\\<close>\n          using WfDiaP(1-2) IPath alw(4) by auto\n        moreover have \\<open>nominals p \\<subseteq> B\\<close>\n          using WfDiaP(1-2) IPath(1-2) alw(4) unfolding branch_nominals_def by force\n        ultimately have \\<open>holdst (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) s\\<close>\n          using \\<open>i \\<in> B\\<close> WfDiaP(1, 6) IPath alw(4) by simp\n        then have \\<open>holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) tail\\<close>\n          using s IPath holds_holdst by fast\n      }\n\n      moreover have \\<open>holdst (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) s\\<close>\n        using WfDiaP(1, 6) alw(5) \\<open>(\\<^bold>@ i p) \\<in> X\\<close> \\<open>(\\<^bold>\\<diamond> Nom i) \\<in> X\\<close> IPath(1-2) by auto\n      then have \\<open>holds (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) tail\\<close>\n        using s IPath holds_holdst by fast\n\n      ultimately show ?thesis\n        by simp\n    next\n      case (WfDiaN p a ps branch i s n)\n      from this(1) have s: \\<open>s' = s\\<close>\n        using IPath by simp\n\n      have \\<open>i \\<in> B\\<close>\n        using WfDiaN(1, 3) alw(4) IPath unfolding branch_nominals_def by force\n\n      have ?thesis if\n        \\<open>(\\<^bold>\\<not> (\\<^bold>@ i p)) \\<in> X\\<close>\n        \\<open>holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) tail\\<close>\n        \\<open>holds (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) tail\\<close>\n        using that wft WfDiaN(1) alw(3-) IPath unfolding generated_ipath_def by auto\n\n      moreover have \\<open>(\\<^bold>\\<not> (\\<^bold>\\<diamond> p)) \\<in> X\\<close>\n        using WfDiaN(1, 2) IPath alw(5) at_in_branch_formulas\n        by (metis holds_Stream insert_subset mk_disjoint_insert step.sel(3) tree.inject)\n      then have \\<open>(\\<^bold>\\<not> (\\<^bold>@ i p)) \\<in> X\\<close>\n        using \\<open>i \\<in> B\\<close> X by fastforce\n\n      moreover {\n        have \\<open>branch_nominals (((\\<^bold>\\<not> (\\<^bold>@ i p)) # ps, a) # branch) \\<subseteq> {i} \\<union> nominals p \\<union> B\\<close>\n          using WfDiaN(1-3) IPath alw(4) by auto\n        moreover have \\<open>nominals p \\<subseteq> B\\<close>\n          using WfDiaN(1-2) IPath(1-2) alw(4) unfolding branch_nominals_def by force\n        ultimately have \\<open>holdst (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) s\\<close>\n          using \\<open>i \\<in> B\\<close> WfDiaN(1, 5) IPath alw(4) by simp\n        then have \\<open>holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) tail\\<close>\n          using s IPath holds_holdst by fast\n      }\n\n      moreover have \\<open>holdst (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) s\\<close>\n        using WfDiaN(1, 5) alw(5) \\<open>(\\<^bold>\\<not> (\\<^bold>@ i p)) \\<in> X\\<close> IPath(1-2) by auto\n      then have \\<open>holds (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) tail\\<close>\n        using s IPath holds_holdst by fast\n\n      ultimately show ?thesis\n        by simp\n    next\n      case (WfSatP a p b ps branch s n)\n      from this(1) have s: \\<open>s' = s\\<close>\n        using IPath by simp\n\n      have ?thesis if\n        \\<open>p \\<in> X\\<close>\n        \\<open>holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) tail\\<close>\n        \\<open>holds (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) tail\\<close>\n        using that wft WfSatP(1) alw(3-) IPath unfolding generated_ipath_def by auto\n\n      moreover have \\<open>(\\<^bold>@ a p) \\<in> X\\<close>\n        using WfSatP(1, 2) IPath alw(5) at_in_branch_formulas\n        by (metis holds_Stream insert_subset mk_disjoint_insert step.sel(3) tree.inject)\n      then have \\<open>p \\<in> X\\<close>\n        using X by auto\n\n      moreover have \\<open>holdst (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) s\\<close>\n        using WfSatP(1-2, 4) IPath alw(4) branch_nominals_there[where p=p] by fastforce\n      then have \\<open>holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) tail\\<close>\n        using s IPath holds_holdst by fast\n\n      moreover have \\<open>holdst (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) s\\<close>\n        using WfSatP(1, 4) alw(5) \\<open>p \\<in> X\\<close> IPath(1-2) by auto\n      then have \\<open>holds (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) tail\\<close>\n        using s IPath holds_holdst by fast\n\n      ultimately show ?thesis\n        by simp\n    next\n      case (WfSatN a p b ps branch s n)\n      from this(1) have s: \\<open>s' = s\\<close>\n        using IPath by simp\n\n      have ?thesis if\n        \\<open>(\\<^bold>\\<not> p) \\<in> X\\<close>\n        \\<open>holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) tail\\<close>\n        \\<open>holds (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) tail\\<close>\n        using that wft WfSatN(1) alw(3-) IPath unfolding generated_ipath_def by auto\n\n      moreover have \\<open>(\\<^bold>\\<not> (\\<^bold>@ a p)) \\<in> X\\<close>\n        using WfSatN(1, 2) IPath alw(5) at_in_branch_formulas\n        by (metis holds_Stream insert_subset mk_disjoint_insert step.sel(3) tree.inject)\n      then have \\<open>(\\<^bold>\\<not> p) \\<in> X\\<close>\n        using X by auto\n\n      moreover have \\<open>holdst (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) s\\<close>\n        using WfSatN(1-2, 4) IPath alw(4) branch_nominals_there[where p=\\<open>\\<^bold>\\<not> p\\<close>] by fastforce\n      then have \\<open>holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) tail\\<close>\n        using s IPath holds_holdst by fast\n\n      moreover have \\<open>holdst (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) s\\<close>\n        using WfSatN(1, 4) alw(5) \\<open>(\\<^bold>\\<not> p) \\<in> X\\<close> IPath(1-2) by auto\n      then have \\<open>holds (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) tail\\<close>\n        using s IPath holds_holdst by fast\n\n      ultimately show ?thesis\n        by simp\n    next\n      case (WfGoTo i branch s n)\n      from this(1) have s: \\<open>s' = s\\<close>\n        using IPath by simp\n\n      have ?thesis if\n        \\<open>holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) tail\\<close>\n        \\<open>holds (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) tail\\<close>\n        using that wft WfGoTo(1) alw(3-) IPath unfolding generated_ipath_def by auto\n\n      moreover have \\<open>i \\<in> B\\<close>\n        using WfGoTo(1-2) IPath alw(4) by auto\n      then have \\<open>holdst (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) s\\<close>\n        using WfGoTo(1, 3) IPath alw(4) unfolding branch_nominals_def by auto        \n      then have \\<open>holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) tail\\<close>\n        using s IPath holds_holdst by fast\n\n      moreover have \\<open>holdst (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) s\\<close>\n        using WfGoTo(1, 3) alw(5) \\<open>i \\<in> B\\<close> Xi IPath(1-2) unfolding branch_formulas_def by simp\n      then have \\<open>holds (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) tail\\<close>\n        using s IPath holds_holdst by fast\n\n      ultimately show ?thesis\n        by simp\n    next\n      case (WfNom p b ps a branch s n)\n           from this(1) have s: \\<open>s' = s\\<close>\n        using IPath by simp\n\n      have ?thesis if\n        \\<open>p \\<in> X\\<close>\n        \\<open>holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) tail\\<close>\n        \\<open>holds (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) tail\\<close>\n        using that wft WfNom(1) alw(3-) IPath unfolding generated_ipath_def by auto\n\n      moreover have \\<open>p \\<in> X\\<close>\n        using WfNom(1, 2) IPath alw(5) at_in_branch_formulas\n        by (metis holds_Stream insert_subset mk_disjoint_insert step.sel(3) tree.inject)\n\n      moreover have \\<open>holdst (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) s\\<close>\n        using WfNom(1-2, 6) IPath alw(4) branch_nominals_there[where p=p] by fastforce\n      then have \\<open>holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq> B) tail\\<close>\n        using s IPath holds_holdst by fast\n\n      moreover have \\<open>holdst (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) s\\<close>\n        using WfNom(1, 6) alw(5) \\<open>p \\<in> X\\<close> IPath(1-2) by auto\n      then have \\<open>holds (\\<lambda>l. branch_formulas (getBranch l) \\<subseteq> X) tail\\<close>\n        using s IPath holds_holdst by fast\n\n      ultimately show ?thesis\n        by simp\n    qed\n  qed\nqed\n\nlemma wft_introduces_quasis_ipath:\n  fixes tab steps\n  defines \\<open>B \\<equiv> generated_ipath steps \\<union> branch_nominals (getBranch (shd steps))\\<close>\n  defines \\<open>X \\<equiv> formula_bound B (getBranch (shd steps))\\<close>\n  assumes \\<open>ipath tab steps\\<close> \\<open>wft A tab\\<close>\n  shows\n    \\<open>alw (holds (\\<lambda>l. \\<forall>pps a. introduces (getTag l) = Some (pps, a) \\<longrightarrow> set (concat pps) \\<subseteq> X)) steps\\<close>\n    \\<open>alw (holds (\\<lambda>step. \\<forall>a p i. getTag step = Fresh a p i \\<longrightarrow> (\\<nexists>a. p = Nom a) \\<and>(\\<^bold>\\<diamond> p) \\<in> X)) steps\\<close>\nproof -\n  have \\<open>generated_ipath steps \\<subseteq> B\\<close> \\<open>branch_nominals (getBranch (shd steps)) \\<subseteq> B\\<close>\n    unfolding B_def by simp_all\n  moreover have \\<open>branch_formulas (getBranch (shd steps)) \\<subseteq> X\\<close> \\<open>\\<forall>i\\<in>B. {Nom i, \\<^bold>\\<diamond> Nom i} \\<subseteq> X\\<close>\n    unfolding B_def X_def formula_bound_def by blast+\n  moreover have \\<open>\\<forall>x\\<in>X. quasis B x \\<subseteq> X\\<close>\n    unfolding X_def using formula_bound_quasis by blast\n  ultimately have \\<open>alw\n      (holds (\\<lambda>step. (\\<forall>pps a. introduces (getTag step) = Some (pps, a) \\<longrightarrow> set (concat pps) \\<subseteq> X) \\<and>\n      (\\<forall>a p i. getTag step = Fresh a p i \\<longrightarrow> (\\<nexists>a. p = Nom a) \\<and> (\\<^bold>\\<diamond> p) \\<in> X))) steps\\<close>\n    using assms(3-4) wft_introduces_quasis_ipath' by fastforce\n  then show\n    \\<open>alw (holds (\\<lambda>l. \\<forall>pps a. introduces (getTag l) = Some (pps, a) \\<longrightarrow> set (concat pps) \\<subseteq> X)) steps\\<close>\n    \\<open>alw (holds (\\<lambda>step. \\<forall>a p i. getTag step = Fresh a p i \\<longrightarrow> (\\<nexists>a. p = Nom a) \\<and> (\\<^bold>\\<diamond> p) \\<in> X)) steps\\<close>\n    by (metis (no_types, lifting) alw_sset sset_alw)+\nqed\n\nsubsection \\<open>Finite\\<close>\n\nlemma finite_introduces_lists:\n  fixes X k\n  defines \\<open>Y \\<equiv> {ps. set ps \\<subseteq> X \\<and> length ps \\<le> k}\\<close>\n  assumes \\<open>finite X\\<close>\n  shows \\<open>finite {pps. set pps \\<subseteq> Y \\<and> length pps \\<le> m}\\<close>\nproof -\n  have \\<open>finite Y\\<close>\n    unfolding Y_def using finite_lists_length_le \\<open>finite X\\<close> .\n  then show ?thesis\n    using finite_lists_length_le \\<open>finite X\\<close> by blast\nqed\n\n(* TODO: maybe drop some inner universal quantifiers? *)\nlemma introduces_lengths:\n  assumes \\<open>wft A tab\\<close>\n  shows \\<open>alwt (holdst (\\<lambda>l. \\<forall>pps a.\n    (introduces (getTag l) = Some (pps, a) \\<longrightarrow>\n      length pps \\<le> 2 \\<and> (\\<forall>ps \\<in> set pps. length ps \\<le> 2)))) tab\\<close>\n  using assms by (coinduction arbitrary: tab) (fastforce elim: wft.cases)\n\nlemma wft_introduces_nominals:\n  assumes \\<open>wft A tab\\<close>\n  shows \\<open>relt (Here (\\<lambda>step. \\<forall>ps a. introduces (getTag step) = Some (ps, a) \\<longrightarrow>\n    a \\<in> branch_nominals (getBranch step))) tab\\<close>\n  using assms unfolding branch_nominals_def by (auto elim: wft.cases)\n\nlemma wft_introduces_nominals_ipath:\n  assumes \\<open>wft A tab\\<close> \\<open>ipath tab steps\\<close>\n  shows \\<open>alw (holds (\\<lambda>step. \\<forall>ps a. introduces (getTag step) = Some (ps, a) \\<longrightarrow>\n    a \\<in> branch_nominals (getBranch step))) steps\\<close>\nproof -\n  have \\<open>alw (rels (Here (\\<lambda>step. \\<forall>ps a. introduces (getTag step) = Some (ps, a) \\<longrightarrow>\n    a \\<in> branch_nominals (getBranch step)))) steps\\<close>\n    using wft_alw assms wft_introduces_nominals .\n  then show ?thesis\n    by simp\nqed\n\nlemma introduces_bound:\n  fixes steps\n  defines \\<open>B \\<equiv> generated_ipath steps \\<union> branch_nominals (getBranch (shd steps))\\<close>\n  assumes \\<open>wft A tab\\<close> \\<open>ipath tab steps\\<close> \\<open>finite B\\<close>\n  shows \\<open>\\<exists>n. \\<forall>k \\<ge> n. introduces (getTag (steps !! k)) = None\\<close>\nproof -\n  let ?X = \\<open>formula_bound B (getBranch (shd steps))\\<close>\n  let ?f = \\<open>introduces o getTag\\<close>\n  let ?D = \\<open>?f ` sset steps\\<close>\n\n  let ?Y = \\<open>{pps. set pps \\<subseteq> {ps. set ps \\<subseteq> ?X \\<and> length ps \\<le> 2} \\<and> length pps \\<le> 2}\\<close>\n\n  have \\<open>alw (holds (\\<lambda>l. \\<forall>pps a. ?f l = Some (pps, a) \\<longrightarrow> set (concat pps) \\<subseteq> ?X)) steps\\<close>\n    using assms wft_introduces_quasis_ipath by auto\n  then have \\<open>\\<forall>intro \\<in> ?D. \\<forall>pps a. intro = Some (pps, a) \\<longrightarrow> set (concat pps) \\<subseteq> ?X\\<close>\n    using alw_sset by (smt (verit, best) imageE)\n  then have \\<open>\\<forall>intro \\<in> ?D. \\<forall>pps a. intro = Some (pps, a) \\<longrightarrow> (\\<forall>ps \\<in> set pps. set ps \\<subseteq> ?X)\\<close>\n    by auto\n\n  moreover have \\<open>\\<forall>intro \\<in> ?D. \\<forall>pps a. intro = Some (pps, a) \\<longrightarrow>\n      length pps \\<le> 2 \\<and> (\\<forall>ps \\<in> set pps. length ps \\<le> 2)\\<close>\n    using assms(2-3) alw_sset introduces_lengths alwt_ipath by fastforce\n  ultimately have \\<open>\\<forall>intro \\<in> ?D. \\<forall>pps a. intro = Some (pps, a) \\<longrightarrow> pps \\<in> ?Y\\<close>\n    by auto\n\n  (* TODO: pps should be pss? *)\n  moreover {\n    have \\<open>alw (holds (\\<lambda>step. \\<forall>pps a. ?f step = Some (pps, a) \\<longrightarrow>\n        a \\<in> branch_nominals (getBranch step))) steps\\<close>\n      using assms wft_introduces_nominals_ipath by auto\n    then have \\<open>\\<forall>step \\<in> sset steps. \\<forall>pps a. ?f step = Some (pps, a) \\<longrightarrow>\n      a \\<in> branch_nominals (getBranch step)\\<close>\n      using alw_sset by (metis (mono_tags, lifting))\n    moreover have \\<open>alw (holds (\\<lambda>l. branch_nominals (getBranch l) \\<subseteq>\n         branch_nominals (getBranch (shd steps)) \\<union> generated_ipath steps)) steps\\<close>\n      using assms(2-3) wft_generated_ipath by fast\n    then have \\<open>\\<forall>step \\<in> sset steps. branch_nominals (getBranch step) \\<subseteq>\n         branch_nominals (getBranch (shd steps)) \\<union> generated_ipath steps\\<close>\n      using alw_sset by (metis (mono_tags, lifting))\n    ultimately have \\<open>\\<forall>intro \\<in> ?D. \\<forall>pps a. intro = Some (pps, a) \\<longrightarrow> a \\<in> B\\<close>\n      unfolding B_def comp_def by fast\n  }\n  ultimately have \\<open>\\<forall>intro \\<in> ?D. \\<forall>x. intro = Some x \\<longrightarrow> x \\<in> ?Y \\<times> B\\<close>\n    by simp\n  then have \\<open>?D \\<subseteq> {None} \\<union> Some ` (?Y \\<times> B)\\<close>\n    by blast\n\n  moreover have \\<open>finite ?X\\<close>\n    using assms(4) finite_formula_bound by blast\n  then have \\<open>finite ?Y\\<close>\n    using finite_introduces_lists by blast\n  then have \\<open>finite ({None} \\<union> Some ` (?Y \\<times> B))\\<close>\n    using \\<open>finite B\\<close> by blast\n  ultimately have \\<open>finite ?D\\<close>\n    by (simp add: finite_subset)\n\n  then obtain n where n: \\<open>?D \\<subseteq> ?f ` set (stake n steps)\\<close>\n    using stake_finite' by blast\n\n  have \\<open>\\<forall>k \\<ge> Suc n. ?f (steps !! k) = None\\<close>\n  proof (intro allI impI)\n    fix k\n    assume \\<open>Suc n \\<le> k\\<close>\n    show \\<open>?f (steps !! k) = None\\<close>\n    proof (rule ccontr)\n      assume \\<open>?f (steps !! k) \\<noteq> None\\<close>\n      then obtain ps a where ps: \\<open>?f (steps !! k) = Some (ps, a)\\<close>\n        by fast\n      then have \\<open>Some (ps, a) \\<in> ?D\\<close>\n        by (metis comp_apply imageI snth_sset)\n      then have \\<open>Some (ps, a) \\<in> ?f ` set (stake n steps)\\<close>\n        using n by blast\n      then obtain m where \\<open>m \\<le> n\\<close> \\<open>?f (steps !! m) = Some (ps, a)\\<close>\n        using stake_snth by force\n      moreover have \\<open>m < k\\<close>\n        using \\<open>m \\<le> n\\<close> \\<open>Suc n \\<le> k\\<close> by simp\n      ultimately show False\n        using ps assms(2-3) distinct_introduces by fastforce\n    qed\n  qed\n  then show ?thesis\n    by auto\nqed\n\nlemma Block_Next_potential:\n  assumes \\<open>wft A tab\\<close>\n  shows \\<open>relt (Impl (\\<lambda>l. (\\<exists>i. getTag l = Block i) \\<and> getPotential l = Suc n)\n    (Next (Here (\\<lambda>t. getPotential t = n)))) tab\\<close>\n  using assms by (auto elim: wft.cases)\n\nlemma Block_nxt_potential:\n  assumes \\<open>wft A tab\\<close> \\<open>ipath tab steps\\<close>\n  shows \\<open>alw (holds (\\<lambda>l. (\\<exists>i. getTag l = Block i) \\<and> getPotential l = Suc n)\n    impl (nxt (holds (\\<lambda>t. getPotential t = n)))) steps\\<close>\nproof -\n  have \\<open>alw (rels (Impl (\\<lambda>l. (\\<exists>i. getTag l = Block i) \\<and> getPotential l = Suc n)\n    (Next (Here (\\<lambda>t. getPotential t = n))))) steps\\<close>\n    using wft_alw assms Block_Next_potential .\n  then show ?thesis\n    by simp\nqed\n\nlemma Suc_potential:\n  assumes \\<open>wft A tab\\<close>\n  shows \\<open>relt (Here (\\<lambda>l. (\\<exists>i. getTag l = Block i) \\<longrightarrow> (\\<exists>n. getPotential l = Suc n))) tab\\<close>\n  using assms(1) by (auto elim: wft.cases)\n\nlemma Suc_potential_ipath:\n  assumes \\<open>wft A tab\\<close> \\<open>ipath tab steps\\<close>\n  shows \\<open>alw (holds (\\<lambda>l. (\\<exists>i. getTag l = Block i) \\<longrightarrow> (\\<exists>n. getPotential l = Suc n))) steps\\<close>\nproof -\n  have \\<open>alw (rels (Here (\\<lambda>l. (\\<exists>i. getTag l = Block i) \\<longrightarrow> (\\<exists>n. getPotential l = Suc n)))) steps\\<close>\n    using wft_alw assms Suc_potential .\n  then show ?thesis\n    by simp\nqed\n\nlemma ipath_ev_not_Block:\n  assumes \\<open>wft A tab\\<close> \\<open>ipath tab steps\\<close>\n  shows \\<open>\\<exists>k. \\<nexists>i. getTag (sdrop m steps !! k) = Block i\\<close>\nproof (rule ccontr)\n  assume \\<open>\\<not> ?thesis\\<close>\n  then have *: \\<open>\\<forall>k. \\<exists>i. getTag (sdrop m steps !! k) = Block i\\<close>\n    by blast\n  moreover have \\<open>alw (holds (\\<lambda>l. (\\<exists>i. getTag l = Block i) \\<longrightarrow> (\\<exists>n. getPotential l = Suc n))) steps\\<close>\n    using Suc_potential_ipath assms .\n  ultimately have suc: \\<open>\\<forall>k. \\<exists>n. getPotential (sdrop m steps !! k) = Suc n\\<close>\n    using alw_snth alw_sdrop by blast\n  then obtain n where n: \\<open>getPotential (shd (sdrop m steps)) = Suc n\\<close>\n    by (metis snth.simps(1))\n\n  have \\<open>alw (holds (\\<lambda>l. (\\<exists>i. getTag l = Block i) \\<and> getPotential l = Suc n)\n    impl (nxt (holds (\\<lambda>t. getPotential t = n)))) steps\\<close> for n\n    using Block_nxt_potential assms .\n  then have \\<open>alw (holds (\\<lambda>l. (\\<exists>i. getTag l = Block i) \\<and> getPotential l = Suc n)\n    impl (nxt (holds (\\<lambda>t. getPotential t = n)))) (sdrop m steps)\\<close> for n\n    by (simp add: alw_iff_sdrop)\n  then have \\<open>\\<forall>k. ((holds (\\<lambda>l. (\\<exists>i. getTag l = Block i) \\<and> getPotential l = Suc n))\n       impl (nxt (holds (\\<lambda>t. getPotential t = n)))) (sdrop (m + k) steps)\\<close> for n\n    by (simp add: alw_iff_sdrop)\n  then have \\<open>\\<forall>k. holds (\\<lambda>l. (\\<exists>i. getTag l = Block i) \\<and> getPotential l = Suc n) (sdrop (m + k) steps)\n       \\<longrightarrow> holds (\\<lambda>t. getPotential t = n) (sdrop (Suc m + k) steps)\\<close> for n\n    by simp\n  moreover from * have \\<open>\\<forall>k. holds (\\<lambda>l. (\\<exists>i. getTag l = Block i)) (sdrop (m + k) steps)\\<close>\n    by (metis (mono_tags, lifting) holds.elims(1) sdrop_add sdrop_simps(1))\n  ultimately have **: \\<open>\\<forall>k. (holds (\\<lambda>l. getPotential l = Suc n)) (sdrop (m + k) steps)\n       \\<longrightarrow> (holds (\\<lambda>t. getPotential t = n)) (sdrop (Suc (m + k)) steps)\\<close> for n\n    by (simp add: alw_iff_sdrop)\n\n  have \\<open>getPotential (sdrop m steps !! k) = Suc n - k\\<close> for k\n  proof (induct k)\n    case 0\n    then show ?case\n      using n by simp\n  next\n    case (Suc k)\n    moreover obtain x where x: \\<open>getPotential (sdrop m steps !! k) = Suc x\\<close>\n      using suc by metis\n    then have \\<open>getPotential (sdrop m steps !! Suc k) = x\\<close>\n      using ** by (simp add: sdrop_snth)\n    ultimately show ?case\n      using x by simp\n  qed\n  then have \\<open>getPotential (sdrop m steps !! Suc n) = 0\\<close>\n    by presburger\n  then show False\n    using suc by (metis Zero_not_Suc)\nqed\n\nlemma ipath_Open_Close:\n  assumes \\<open>ipath tab steps\\<close> \\<open>wft A tab\\<close> \n  shows \\<open>alw (holds (\\<lambda>l. getTag l \\<noteq> Open \\<and> (\\<nexists>p i. getTag l = Close p i))) steps\\<close>\n  using assms\nproof (coinduction arbitrary: tab steps)\n  case alw\n  then show ?case\n    by cases (fastforce elim: wft.cases)\nqed\n\nlemma introduces_None:\n  assumes \\<open>introduces t = None\\<close>\n  shows \\<open>t = Open \\<or> (\\<exists>p i. t = Close p i) \\<or> (\\<exists>i. t = Block i)\\<close>\n  using assms by (cases t) simp_all\n\ntheorem infinite_generated:\n  assumes \\<open>wft A tab\\<close> \\<open>ipath tab steps\\<close>\n  shows \\<open>infinite (generated_ipath steps)\\<close>\nproof\n  let ?B = \\<open>generated_ipath steps \\<union> branch_nominals (getBranch (shd steps))\\<close>\n  assume \\<open>finite (generated_ipath steps)\\<close>\n  then have \\<open>finite ?B\\<close>\n    using finite_branch_nominals by blast\n  then obtain k where k: \\<open>\\<forall>k' \\<ge> k. introduces (getTag (steps !! k')) = None\\<close>\n    using assms(1-2) introduces_bound by blast\n  then have \\<open>alw (holds (\\<lambda>l. introduces (getTag l) = None)) (sdrop k steps)\\<close>\n    by (simp add: alw_iff_sdrop)\n  moreover have \\<open>alw (holds (\\<lambda>l. getTag l \\<noteq> Open \\<and> (\\<nexists>p i. getTag l = Close p i))) steps\\<close>\n    using ipath_Open_Close assms(2, 1) .\n  then have \\<open>alw (holds (\\<lambda>l. getTag l \\<noteq> Open \\<and> (\\<nexists>p i. getTag l = Close p i))) (sdrop k steps)\\<close>\n    by (simp add: alw_iff_sdrop)\n  ultimately have *: \\<open>alw (holds (\\<lambda>l. \\<exists>i. getTag l = Block i)) (sdrop k steps)\\<close>\n    using introduces_None by (metis (mono_tags, lifting) alw_sset sset_alw)\n  moreover have \\<open>\\<exists>x. \\<nexists>i. getTag (sdrop k steps !! x) = Block i\\<close>\n    using ipath_ev_not_Block assms(1-2) .\n  ultimately show False\n    using alw_snth by blast\nqed\n\nsection \\<open>Infinite Path\\<close>\n\ndefinition propers :: \\<open>('a, 'b) fm set \\<Rightarrow> ('a, 'b) fm set\\<close> where\n  \\<open>propers X \\<equiv> {p. p \\<in> X \\<and> (\\<exists>p'. p = (\\<^bold>\\<diamond> p') \\<and> (\\<nexists>a. p' = Nom a))}\\<close>\n\nlemma finite_propers_quasis: \\<open>finite (propers (quasis A p))\\<close>\nproof (induct p rule: quasis.induct)\n  case (1 A p)\n  moreover have \\<open>propers (quasis A (\\<^bold>\\<not> \\<^bold>\\<not> p)) \\<subseteq> {p} \\<union> propers (quasis A p)\\<close>\n    unfolding propers_def by auto\n  ultimately show ?case\n    by (simp add: finite_subset)\nnext\n  case (2 A p q)\n  moreover have \\<open>propers (quasis A (p \\<^bold>\\<or> q)) \\<subseteq> {p, q} \\<union> propers (quasis A p) \\<union> propers (quasis A q)\\<close>\n    unfolding propers_def by auto\n  ultimately show ?case\n    by (simp add: finite_subset)\nnext\n  case (3 A p q)\n  moreover have \\<open>propers (quasis A (\\<^bold>\\<not> (p \\<^bold>\\<or> q))) \\<subseteq>\n      {\\<^bold>\\<not> p, \\<^bold>\\<not> q} \\<union> propers (quasis A (\\<^bold>\\<not> p)) \\<union> propers (quasis A (\\<^bold>\\<not> q))\\<close>\n    unfolding propers_def by auto\n  ultimately show ?case\n    by (simp add: finite_subset)\nnext\n  case (4 A p)\n  moreover have \\<open>propers (quasis A (\\<^bold>\\<diamond> p)) \\<subseteq> {p} \\<union> propers (quasis A p)\\<close>\n    unfolding propers_def by auto\n  ultimately show ?case\n    unfolding propers_def\n    by (cases \\<open>\\<exists>a. p = Nom a\\<close>) (simp_all add: finite_subset)\nnext\n  case (5 A p)\n  moreover have \\<open>propers (quasis A (\\<^bold>\\<not> (\\<^bold>\\<diamond> p))) \\<subseteq> {\\<^bold>\\<not> p} \\<union> propers (quasis A (\\<^bold>\\<not> p))\\<close>\n    unfolding propers_def by auto\n  ultimately show ?case\n    by (simp add: finite_subset)    \nnext\n  case (6 A i p)\n  moreover have \\<open>propers (quasis A (\\<^bold>@ i p)) \\<subseteq> {p} \\<union> propers (quasis A p)\\<close>\n    unfolding propers_def by auto\n  ultimately show ?case\n    by (simp add: finite_subset)    \nnext\n  case (7 A i p)\n  moreover have \\<open>propers (quasis A (\\<^bold>\\<not> (\\<^bold>@ i p))) \\<subseteq> {\\<^bold>\\<not> p} \\<union> propers (quasis A (\\<^bold>\\<not> p))\\<close>\n    unfolding propers_def by auto\n  ultimately show ?case\n    by (simp add: finite_subset)    \nqed (simp_all add: propers_def)\n\nlemma propers_Un: \\<open>propers (A \\<union> B) = propers A \\<union> propers B\\<close>\n  unfolding propers_def by blast\n\nlemma propers_subset: \\<open>propers X \\<subseteq> X\\<close>\n  unfolding propers_def by blast\n\nlemma finite_propers_formula_bound: \\<open>finite (propers (formula_bound B branch))\\<close>\nproof -\n  let ?b = \\<open>branch_formulas branch\\<close>\n  have b: \\<open>finite ?b\\<close>\n    using finite_branch_formulas by blast\n\n  let ?X = \\<open>formula_bound B branch\\<close>\n\n  have \\<open>propers (\\<Union>p \\<in> ?b. quasis B p) = (\\<Union>p \\<in> ?b. propers (quasis B p))\\<close>\n    unfolding propers_def by blast\n  moreover have \\<open>finite (propers (quasis B p))\\<close> for p :: \\<open>('a, 'b) fm\\<close>\n    using finite_propers_quasis by blast\n  ultimately have \\<open>finite (propers (\\<Union>p \\<in> ?b. quasis B p))\\<close>\n    using b by simp\n  moreover have \\<open>finite (propers ?b)\\<close>\n    using b finite_subset propers_subset by blast\n  moreover have \\<open>propers ?X = propers ?b \\<union> propers (\\<Union>p \\<in> ?b. quasis B p)\\<close>\n    unfolding formula_bound_def propers_def by blast\n  ultimately show ?thesis\n    by simp\nqed\n\nlemma Fresh_unwitnessed:\n  assumes \\<open>wft A tab\\<close>\n  shows \\<open>relt (Here (\\<lambda>t. \\<forall>a p i. getTag t = Fresh a p i \\<longrightarrow> \\<not> witnessed p a (getBranch t))) tab\\<close>\n  using assms by (auto elim: wft.cases)\n\nlemma Fresh_unwitnessed_ipath:\n  assumes \\<open>wft A tab\\<close> \\<open>ipath tab steps\\<close>\n  shows \\<open>alw (holds (\\<lambda>t. \\<forall>a p i. getTag t = Fresh a p i \\<longrightarrow> \\<not> witnessed p a (getBranch t))) steps\\<close>\nproof -\n  have \\<open>alw (rels (Here (\\<lambda>t. \\<forall>a p i. getTag t = Fresh a p i \\<longrightarrow>\n    \\<not> witnessed p a (getBranch t)))) steps\\<close>\n  using wft_alw assms Fresh_unwitnessed .\n  then show ?thesis\n    by simp\nqed\n\nlemma distinct_Fresh:\n  assumes \\<open>wft A tab\\<close> \\<open>ipath tab steps\\<close> \\<open>steps !! m = s\\<close> \\<open>steps !! n = s'\\<close> \\<open>m < n\\<close>\n    \\<open>getTag s = Fresh a p i\\<close> \\<open>getTag s' = Fresh a q j\\<close>\n  shows \\<open>p \\<noteq> q\\<close>\nproof -\n  let ?ps = \\<open>[\\<^bold>@ i p, \\<^bold>\\<diamond> Nom i]\\<close>\n  have \\<open>alw (holds (\\<lambda>t. introduces (getTag t) = Some ([?ps], a))\n   impl nxt (holds (\\<lambda>s. \\<exists>ps \\<in> set [?ps]. ps \\<noteq> [] \\<and> (\\<forall>p\\<in>set ps. p at a in getBranch s)))) steps\\<close>\n    using introduces_alw_nxt assms(1-2) .\n  then have \\<open>holds (\\<lambda>s. \\<forall>p\\<in>set ?ps. p at a in getBranch s) (sdrop (Suc m) steps)\\<close>\n    using assms(3, 6) by (simp add: alw_iff_sdrop)\n  then have\n    \\<open>holds (\\<lambda>s. (\\<^bold>@ i p) at a in getBranch s) (sdrop (Suc m) steps)\\<close>\n    \\<open>holds (\\<lambda>s. (\\<^bold>\\<diamond> Nom i) at a in getBranch s) (sdrop (Suc m) steps)\\<close>\n    by auto\n  moreover have \\<open>alw (holds (\\<lambda>l. p at a in getBranch l)\n            impl nxt (holds (\\<lambda>l. p at a in getBranch l))) steps\\<close> for p\n    using preservation_alw assms(1-2) .\n  then have \\<open>alw (holds (\\<lambda>l. p at a in getBranch l)\n        impl nxt (holds (\\<lambda>l. p at a in getBranch l))) (sdrop (Suc m) steps)\\<close> for p\n    using alw_sdrop by blast\n  ultimately have\n    \\<open>alw (holds (\\<lambda>l. (\\<^bold>@ i p) at a in getBranch l)) (sdrop (Suc m) steps)\\<close>\n    \\<open>alw (holds (\\<lambda>l. (\\<^bold>\\<diamond> Nom i) at a in getBranch l)) (sdrop (Suc m) steps)\\<close>\n    using alw_invar by blast+\n  then have\n    \\<open>holds (\\<lambda>l. (\\<^bold>@ i p) at a in getBranch l) (sdrop n steps)\\<close>\n    \\<open>holds (\\<lambda>l. (\\<^bold>\\<diamond> Nom i) at a in getBranch l) (sdrop n steps)\\<close>\n    using \\<open>m < n\\<close> by (auto simp: alw_iff_sdrop elim: less_natE)\n  then have \\<open>holds (\\<lambda>l. witnessed p a (getBranch l)) (sdrop n steps)\\<close>\n    unfolding witnessed_def by auto\n\n  moreover have \\<open>alw (holds (\\<lambda>t. \\<forall>a p i. getTag t = Fresh a p i \\<longrightarrow>\n    \\<not> witnessed p a (getBranch t))) steps\\<close>\n    using Fresh_unwitnessed_ipath assms(1-2) .\n  then have \\<open>alw (holds (\\<lambda>t. \\<forall>a p i. getTag t = Fresh a p i \\<longrightarrow>\n    \\<not> witnessed p a (getBranch t))) (sdrop n steps)\\<close>\n    by (simp add: alw_iff_sdrop)\n  then have \\<open>holds (\\<lambda>t. \\<not> witnessed q a (getBranch t)) (sdrop n steps)\\<close>\n    using assms(4, 7) by auto\n  ultimately show ?thesis\n    unfolding witnessed_def  by auto\nqed\n\nlemma labels_sset:\n  assumes \\<open>\\<forall>l \\<in> labels t. P l\\<close> \\<open>ipath t s\\<close>\n  shows \\<open>\\<forall>l \\<in> sset s. P l\\<close>\n  using assms by (meson alw_sset alwt_ipath labels_alwt_holdst)\n\nlemma finite_inj_preimage:\n  assumes \\<open>finite (f ` X)\\<close> \\<open>inj f\\<close>\n  shows \\<open>finite X\\<close>\n  using assms by (meson finite.emptyI finite.insertI finite_vimageI inf_img_fin_dom)\n\nlemma Fresh_determined_nominal:\n  assumes \\<open>wft A tab\\<close> \\<open>ipath tab steps\\<close>\n    \\<open>Fresh a p i \\<in> getTag ` sset steps\\<close> \\<open>Fresh a p i' \\<in> getTag ` sset steps\\<close>\n  shows \\<open>i = i'\\<close>\nproof -\n  obtain m where m: \\<open>getTag (steps !! m) = Fresh a p i\\<close>\n    using assms(3) sset_range by (metis image_iff)\n  obtain n where n: \\<open>getTag (steps !! n) = Fresh a p i'\\<close>\n    using assms(4) sset_range by (metis image_iff)\n\n  consider (lt) \\<open>m < n\\<close> | (eq) \\<open>m = n\\<close> | (gt) \\<open>n < m\\<close>\n    by linarith\n  then show ?thesis\n  proof cases\n    case lt\n    then show ?thesis\n      using assms(1-2) m n distinct_Fresh by fast\n  next\n    case eq\n    then show ?thesis\n      using m n by simp\n  next\n    case gt\n    then show ?thesis\n      using assms(1-2) m n distinct_Fresh by fast\n  qed\nqed\n\nlemma Fresh_determined_nominal_f:\n  assumes \\<open>wft A tab\\<close> \\<open>ipath tab steps\\<close>\n  shows \\<open>\\<exists>f. \\<forall>p i. Fresh a p i \\<in> getTag ` sset steps \\<longrightarrow> f p = i\\<close>\nproof (intro exI allI impI)\n  fix p i\n  let ?f = \\<open>\\<lambda>p. THE i. Fresh a p i \\<in> getTag ` sset steps\\<close>\n  assume \\<open>Fresh a p i \\<in> getTag ` sset steps\\<close>\n  then show \\<open>?f p = i\\<close>\n    using assms Fresh_determined_nominal by fast\nqed\n\nlemma finite_Fresh_nominal:\n  assumes \\<open>wft A tab\\<close> \\<open>ipath tab steps\\<close>\n    \\<open>finite {p |p i. Fresh a p i \\<in> getTag ` sset steps}\\<close>\n  shows \\<open>finite {i |p i. Fresh a p i \\<in> getTag ` sset steps}\\<close>\nproof -\n  obtain f where \\<open>\\<forall>p i. Fresh a p i \\<in> getTag ` sset steps \\<longrightarrow> f p = i\\<close>\n    using assms(1-2) Fresh_determined_nominal_f by metis\n  then have \\<open>{f p |p i. Fresh a p i \\<in> getTag ` sset steps} =\n      {i |p i. Fresh a p i \\<in> getTag ` sset steps}\\<close>\n    by blast\n  moreover have \\<open>finite {f p |p i. Fresh a p i \\<in> getTag ` sset steps}\\<close>\n    using assms(3) by simp\n  ultimately show ?thesis\n    by simp\nqed\n\ntext \\<open>The number of nominals generated by any fixed nominal is finite.\\<close>\n\ntheorem generated_bound:\n  assumes \\<open>wft A tab\\<close> \\<open>ipath tab steps\\<close>\n  shows \\<open>finite {(a, i) |p i. Fresh a p i \\<in> getTag ` sset steps}\\<close>\nproof -\n  let ?B = \\<open>generated_ipath steps \\<union> branch_nominals (getBranch (shd steps))\\<close>\n  let ?X = \\<open>formula_bound ?B (getBranch (shd steps))\\<close>\n  let ?Y = \\<open>propers ?X\\<close>\n\n  have \\<open>alw (holds (\\<lambda>step. \\<forall>a p i. getTag step = Fresh a p i \\<longrightarrow>\n      (\\<nexists>a. p = Nom a) \\<and> (\\<^bold>\\<diamond> p) \\<in> ?X)) steps\\<close>\n    using assms wft_introduces_quasis_ipath by blast\n  then have \\<open>\\<forall>l \\<in> sset steps. \\<forall>p i. getTag l = Fresh a p i \\<longrightarrow>\n      (\\<nexists>a. p = Nom a) \\<and> (\\<^bold>\\<diamond> p) \\<in> ?X\\<close>\n    by (smt alw_sset)\n  then have \\<open>\\<forall>l \\<in> sset steps. \\<forall>p i. getTag l = Fresh a p i \\<longrightarrow> (\\<^bold>\\<diamond> p) \\<in> ?Y\\<close>\n    unfolding propers_def by blast\n  moreover have \\<open>finite ?Y\\<close>\n    using finite_propers_formula_bound  by blast\n  ultimately have \\<open>finite {\\<^bold>\\<diamond> p |p i. Fresh a p i \\<in> getTag ` sset steps}\\<close>\n    by (smt finite_subset imageE mem_Collect_eq subsetI)\n  moreover have \\<open>Dia ` {p |p i. Fresh a p i \\<in> getTag ` sset steps} \\<subseteq>\n      {\\<^bold>\\<diamond> p |p i. Fresh a p i \\<in> getTag ` sset steps}\\<close>\n    by blast\n  ultimately have \\<open>finite (Dia ` {p |p i. Fresh a p i \\<in> getTag ` sset steps})\\<close>\n    by (simp add: finite_subset)    \n  moreover have \\<open>inj Dia\\<close>\n    unfolding inj_def by blast\n  ultimately have \\<open>finite {p |p i. Fresh a p i \\<in> getTag ` sset steps}\\<close>\n    using finite_inj_preimage by fast\n  then have \\<open>finite {i |p i. Fresh a p i \\<in> getTag ` sset steps}\\<close>\n    using assms finite_Fresh_nominal by fast\n  then have \\<open>finite ({a} \\<times> {i |p i. Fresh a p i \\<in> getTag ` sset steps})\\<close>\n    by blast\n  moreover have \\<open>({a} \\<times> {i |p i. Fresh a p i \\<in> getTag ` sset steps}) =\n      {(a, i) |p i. Fresh a p i \\<in> getTag ` sset steps}\\<close>\n    by fast\n  ultimately show ?thesis\n    by simp\nqed\n\n(**********************************************************************************)\n\nsection \\<open>CURRENT WORK\\<close>\n\n(* Ignoring Lemma 6.4 / 4.2 for a bit (finite set of well-founded, finitely branching trees) *)\n\n(* Ignoring Lemma 6.5 for a bit (must be an infinite chain) *)\n\n\n(* TODO: not currently used *)\ndefinition set_to_list :: \\<open>'a set \\<Rightarrow> 'a list\\<close> where\n  \\<open>set_to_list s = (SOME l. set l = s)\\<close>\n\nlemma set_set_to_list: \\<open>finite s \\<Longrightarrow> set (set_to_list s) = s\\<close>\n  unfolding set_to_list_def by (metis (mono_tags) finite_list some_eq_ex)\n\nprimcorec mkTree :: \\<open>('b \\<times> 'b) set \\<Rightarrow> 'b \\<Rightarrow> 'b tree\\<close> where\n  \\<open>getLabel (mkTree T a) = a\\<close>\n| \\<open>getSubs (mkTree T a) = map (mkTree T) (set_to_list {b. (a, b) \\<in> T})\\<close>\n\n(*\n    a      h    j\n  b   c    i\n  d  e f\n     g\n*)\n\n(* Major TODO\n  + We have that ipath \\<Longrightarrow> infinite nominals generated on that ipath\n  + We have that any root has a finite number of subtrees (generated_bound).\n  \n  - We need to show that infinite nominals on an ipath means an infinite chain\n  - We need to show the decreasing measure\n*)\n\nsubsection \\<open>Measure\\<close>\n\nlemma woop1:\n  assumes \\<open>ipath tab steps\\<close> \\<open>wft A tab\\<close>\n    \\<open>Fresh b t c \\<in> getTag ` sset steps\\<close> (* b < c *)\n    \\<open>(holds (\\<lambda>step. \\<forall>r'. r' at c in getBranch step \\<longrightarrow> size r' \\<le> size r) impl\n     (holds (\\<lambda>step. \\<exists>r'. r' at b in getBranch step \\<and> size r < size r'))) steps\\<close>\n  shows \\<open>alw\n    (holds (\\<lambda>step. \\<forall>r'. r' at c in getBranch step \\<longrightarrow> size r' \\<le> size r) impl\n    (holds (\\<lambda>step. \\<exists>r'. r' at b in getBranch step \\<and> size r < size r'))) steps\\<close>\n  using assms\nproof (coinduction arbitrary: tab steps)\n  case alw\n  then show ?case\n  proof cases\n    case (IPath s' subs tail l)\n    then have wft: \\<open>wft A s'\\<close>\n      using alw(2) wft_alwt by (auto elim: wft.cases)\n    from alw(2) show ?thesis\n    proof cases\n      case (WfClose p i branch n)\n      then show ?thesis\n        using IPath(1-2) alw(1-2) alw_holds ipath_Open_Close\n        by (metis (mono_tags, lifting) step.sel(1) tree.inject)\n    next\n      case (WfOpen branch n)\n      then show ?thesis\n        using IPath(1-2) alw(1-2) alw_holds ipath_Open_Close\n        by (metis (mono_tags, lifting) step.sel(1) tree.inject)\n    next\n      case (WfNeg p a ps branch s n)\n      then have the: ?thesis if\n        \\<open>(\\<forall>r'. r' at c in getBranch (shd tail) \\<longrightarrow> size r' \\<le> size r) \\<longrightarrow>\n         (\\<exists>r'. r' at b in getBranch (shd tail) \\<and> size r < size r')\\<close>\n        using that alw IPath by auto\n\n      have *:\n        \\<open>(\\<forall>r'. r' at c in getBranch l \\<longrightarrow> size r' \\<le> size r) \\<longrightarrow>\n         (\\<exists>r'. r' at b in getBranch l \\<and> size r < size r')\\<close>\n        using IPath(2) alw(4) by auto\n\n      have \\<open>getBranch (shd tail) = (p # ps, a) # branch\\<close>\n        using IPath(1, 3-4) WfNeg(1, 4) by (fastforce elim: ipath.cases)\n      moreover have \\<open>getBranch l = (ps, a) # branch\\<close>\n        using IPath(1) WfNeg(1) by auto\n      moreover note \\<open>(\\<^bold>\\<not> \\<^bold>\\<not> p) at a in (ps, a) # branch\\<close>\n      moreover have \\<open>size p \\<le> size (\\<^bold>\\<not> \\<^bold>\\<not> p)\\<close>\n        by simp\n      ultimately have **: \\<open>\\<forall>r'. r' at c in getBranch (shd tail) \\<longrightarrow>\n          (\\<exists>r''. r'' at c in getBranch l \\<and> size r' \\<le> size r'')\\<close>\n        \\<open>\\<forall>r'. r' at c in getBranch l \\<longrightarrow>\n          (\\<exists>r''. r'' at c in getBranch (shd tail) \\<and> size r' \\<le> size r'')\\<close>\n        by (metis (no_types, opaque_lifting) list.set_intros(1-2) on.simps order_refl prod.inject\n            set_ConsD)+\n\n      {\n        assume assm: \\<open>\\<forall>r'. r' at c in getBranch (shd tail) \\<longrightarrow> size r' \\<le> size r\\<close>\n        then have \\<open>\\<forall>r'. r' at c in getBranch (shd tail) \\<longrightarrow>\n            (\\<exists>r''. r'' at c in getBranch l \\<and> size r' \\<le> size r'')\\<close>\n          using **(1) by blast\n        then have \\<open>\\<forall>r'. r' at c in getBranch l \\<longrightarrow> size r' \\<le> size r\\<close>\n          using **(2) assm by (meson le_trans)\n        then have \\<open>\\<exists>r'. r' at b in getBranch l \\<and> size r < size r'\\<close>\n          using * by blast\n        then have \\<open>\\<exists>r'. r' at b in getBranch (shd tail) \\<and> size r < size r'\\<close>\n          using \\<open>getBranch (shd tail) = (p # ps, a) # branch\\<close> \\<open>getBranch l = (ps, a) # branch\\<close> \n          by (metis list.set_intros(1-2) on.simps prod.inject set_ConsD)\n      }\n      then show ?thesis\n        using the by blast\n    next\n      case (WfDisP p q a ps branch sl n sr)\n      then show ?thesis sorry\n    next\n      case (WfDisN p q a ps branch s n intro)\n      then show ?thesis sorry\n    next\n      case (WfDiaP p a ps branch i s n)\n      then show ?thesis sorry\n    next\n      case (WfDiaN p a ps branch i s n)\n      then show ?thesis sorry\n    next\n      case (WfSatP a p b ps branch s n)\n      then show ?thesis sorry\n    next\n      case (WfSatN a p b ps branch s n)\n      then show ?thesis sorry\n    next\n      case (WfGoTo i branch s n)\n      then show ?thesis sorry\n    next\n      case (WfNom p b ps a branch s n)\n      then show ?thesis sorry\n    qed\n  qed\nqed\n\n(* tricky to show this directly by coinduction since we lack the assumption\n   but it should hold and it's what we want *)\n(* c is generated, so there cannot be any c blocks initially *)\nlemma woop2:\n  assumes \\<open>ipath tab steps\\<close> \\<open>wft A tab\\<close>\n    \\<open>Fresh b t c \\<in> getTag ` sset steps\\<close> (* b < c *)\n  shows \\<open>alw (holds (\\<lambda>step. \\<exists>r. r at b in getBranch step \\<and>\n      (\\<forall>r'. r' at c in getBranch step \\<longrightarrow> size r' < size r))) steps\\<close>\n  using assms\nproof (coinduction arbitrary: tab steps)\n  case alw\n  then show ?case\n  proof cases\n    case (IPath s' subs tail l)\n    then have wft: \\<open>wft A s'\\<close>\n      using alw(2) wft_alwt by (auto elim: wft.cases)\n    from alw(2) show ?thesis\n    proof cases\n      case (WfClose p i branch n)\n      then show ?thesis\n        using IPath(1, 3) by simp\n    next\n      case (WfOpen branch n)\n      then show ?thesis\n        using IPath(1, 3) by simp\n    next\n      case (WfNeg p a ps branch s n)\n      then show ?thesis\n        sorry\n    next\n      case (WfDisP p q a ps branch sl n sr)\n      then show ?thesis sorry\n    next\n      case (WfDisN p q a ps branch s n intro)\n      then show ?thesis sorry\n    next\n      case (WfDiaP p a ps branch i s n)\n      then show ?thesis sorry\n    next\n      case (WfDiaN p a ps branch i s n)\n      then show ?thesis sorry\n    next\n      case (WfSatP a p b ps branch s n)\n      then show ?thesis sorry\n    next\n      case (WfSatN a p b ps branch s n)\n      then show ?thesis sorry\n    next\n      case (WfGoTo i branch s n)\n      then show ?thesis sorry\n    next\n      case (WfNom p b ps a branch s n)\n      then show ?thesis sorry\n    qed\n  qed\nqed\n\ntext \\<open>\n  There is an infinite chain of generated nominals starting with i if\n  within some prefix, i generates j and the remaining suffix has a chain from j.\n\\<close>\ncoinductive infgen :: \\<open>'b \\<Rightarrow> ('a, 'b) step stream \\<Rightarrow> bool\\<close> where\n  InfGen: \\<open>Fresh i p j \\<in> getTag ` set (stake n xs) \\<Longrightarrow>\n   infgen j (sdrop n xs) \\<Longrightarrow>\n   infgen i xs\\<close>\n\ntext \\<open>Version that gives us the stream of nominals.\\<close>\ncoinductive infgens :: \\<open>'b stream \\<Rightarrow> ('a, 'b) step stream \\<Rightarrow> bool\\<close> where\n  InfGens: \\<open>Fresh i p j \\<in> getTag ` set (stake n xs) \\<Longrightarrow>\n   infgens (j ## bs) (sdrop n xs) \\<Longrightarrow>\n   infgens (i ## j ## bs) xs\\<close>\n\n(*\n  Branch: step step step step\n  Some steps are the generation of a nominal\n  We know that an infinite branch must have an infinite number of nominals\n  We will also show that they must form a chain\n\n  Assume we have such a chain in our branch\n  We will show that each generated nominal has smaller formulas on it\n  This leads to an infinite descent in formula size\n  This is a contradiction\n*)\n\ndefinition fms_at :: \\<open>'b \\<Rightarrow> ('a, 'b) step stream \\<Rightarrow> ('a, 'b) fm set\\<close> where\n  \\<open>fms_at i steps \\<equiv> {p |p step. step \\<in> sset steps \\<and> p at i in getBranch step}\\<close>\n\n(* TODO: need quasi-root lemmas to show this, I guess *)\nlemma finite_size_fms_at:\n  assumes \\<open>ipath tab steps\\<close> \\<open>wft A tab\\<close>\n  shows \\<open>finite (size ` fms_at i steps)\\<close>\n  sorry\n\ndefinition M_branch :: \\<open>'b \\<Rightarrow> ('a, 'b) step stream \\<Rightarrow> nat\\<close> where\n  \\<open>M_branch i steps \\<equiv> Max (size ` fms_at i steps)\\<close>\n\nlemma M_branch_le:\n  assumes \\<open>p \\<in> fms_at i steps\\<close> \\<open>\\<forall>q. q \\<in> fms_at i steps \\<longrightarrow> size q \\<le> size p\\<close>\n  shows \\<open>M_branch i steps = size p\\<close>\n  using assms unfolding M_branch_def (* TODO: smt *)\n  by (smt (verit, del_insts) Max_eqI finite_nat_set_iff_bounded_le image_iff)\n\n(*\n  Imagine we have the whole branch in front of us.\n  Then we consider a maximal element at c.\n  We see what introduced it.\n  In each case, we show that there is a bigger element at b.\n  \n  What kind of principle is this?\n  \n  Assume it holds.\n  Show it keeps holding under extensions.\n  alw P steps?\n  But P references all of steps\n\n*)\n\n(*\n    \\<open>(holds (\\<lambda>step. \\<forall>r'. r' at c in getBranch step \\<longrightarrow> size r' \\<le> size r) impl\n     (holds (\\<lambda>step. \\<exists>r'. r' at b in getBranch step \\<and> size r < size r'))) steps\\<close>\n  shows \\<open>alw\n    (holds (\\<lambda>step. \\<forall>r'. r' at c in getBranch step \\<longrightarrow> size r' \\<le> size r) impl\n    (holds (\\<lambda>step. \\<exists>r'. r' at b in getBranch step \\<and> size r < size r'))) steps\\<close>\n\nthis isn't good for going to the global M_branch we need for the descent\n\nalw (\\<forall>r. r at c in getBranch step \\<longrightarrow> size r < M_branch b steps) steps\n*)\n\nlemma fms_at_SCons: \\<open>fms_at i xs \\<subseteq> fms_at i (x ## xs)\\<close>\n  unfolding fms_at_def by auto\n\nlemma M_branch_SCons: \\<open>M_branch i xs \\<le> M_branch i (x ## xs)\\<close>\n  unfolding M_branch_def using fms_at_SCons finite_size_fms_at sorry\n    (* TODO: ipath tab xs of wft tab *)\n\nlemma zoop1':\n  assumes \\<open>ipath tab steps\\<close> \\<open>wft A tab\\<close>\n    \\<open>M_branch c steps \\<le> x\\<close>\n  shows \\<open>alw (holds (\\<lambda>step. \\<forall>r. r at c in getBranch step \\<longrightarrow> size r \\<le> x)) steps\\<close>\n  using assms\nproof (coinduction arbitrary: tab steps)\n  case alw\n  then show ?case\n  proof cases\n    case (IPath s' subs tail l)\n    then have wft: \\<open>wft A s'\\<close>\n      using alw(2) wft_alwt by (auto elim: wft.cases)\n    from alw(2) show ?thesis\n    proof cases\n      case (WfClose p i branch n)\n      then show ?thesis\n        using IPath(1, 3) by simp\n    next\n      case (WfOpen branch n)\n      then show ?thesis\n        using IPath(1, 3) by simp\n    next\n      case (WfNeg p a ps branch s n)\n      then have ?thesis if\n        \\<open>\\<forall>r. r at c in (ps, a) # branch \\<longrightarrow> size r \\<le> x\\<close>\n        \\<open>M_branch c tail \\<le> x\\<close>\n        using that IPath(1-2, 4) wft by auto\n      \n      moreover have \\<open>M_branch c tail \\<le> x\\<close>\n        using alw(3) IPath(2) M_branch_SCons by (metis dual_order.trans)\n\n      moreover from alw(3) have \\<open>\\<forall>r \\<in> fms_at c steps. size r \\<le> x\\<close>\n        unfolding M_branch_def using alw(1-2) finite_size_fms_at\n        by (metis Max_ge dual_order.trans image_eqI)\n      then have \\<open>\\<forall>r. r at c in (ps, a) # branch \\<longrightarrow> size r \\<le> x\\<close>\n        unfolding fms_at_def using IPath(1-2) WfNeg(1) by fastforce\n\n      ultimately show ?thesis\n        by blast\n    next\n      case (WfDisP p q a ps branch sl n sr)\n      then show ?thesis sorry\n    next\n      case (WfDisN p q a ps branch s n intro)\n      then show ?thesis sorry\n    next\n      case (WfDiaP p a ps branch i s n)\n      then show ?thesis sorry\n    next\n      case (WfDiaN p a ps branch i s n)\n      then show ?thesis sorry\n    next\n      case (WfSatP a p b ps branch s n)\n      then show ?thesis sorry\n    next\n      case (WfSatN a p b ps branch s n)\n      then show ?thesis sorry\n    next\n      case (WfGoTo i branch s n)\n      then show ?thesis sorry\n    next\n      case (WfNom p b ps a branch s n)\n      then show ?thesis sorry\n    qed\n  qed\nqed\n\n(* Trying to work out how to formulate the a < b \\<longrightarrow> m b < m a lemma in a way we can prove *)\n\nlemma zoop1:\n  assumes \\<open>ipath tab steps\\<close> \\<open>wft A tab\\<close>\n  shows \\<open>alw (holds (\\<lambda>step. \\<forall>p. p at i in getBranch step \\<longrightarrow> size p \\<le> M_branch i steps)) steps\\<close>\n  using assms zoop1' by fast\n\nlemma zoop2:\n  assumes \\<open>ipath tab steps\\<close> \\<open>wft A tab\\<close>\n    \\<open>Fresh b t c \\<in> getTag ` sset steps\\<close> (* b < c *)\n    \\<open>M_branch b steps \\<le> bmax\\<close>\n  shows \\<open>alw (holds (\\<lambda>step. \\<forall>r. r at c in getBranch step \\<longrightarrow> size r < bmax)) steps\\<close>\n  (* idea, don't look at a max c-formula, just look at all of them, at all steps.\n    we can add that it holds initially if we need to (probably do)\n    This gives us something suitable for the coinduction principle\n\n    We need to then bound it by M_branch c steps afterwards\n    And the bound needs to be tight so it doesn't surpass bmax\n    But the bound is only tight in the limit, not at each step\n\n    \n    at each step, a local (varying) measure is smaller than a global (constant) measure\n    l c < m b\n    l c \\<le> m c\n    I need m c < m b\n  *)\n  sorry\n\n(* the induction principle is local but the measure is global\n\n  I need to look at a largest formula and see what rule introduced it.\n\n  No matter what largest c-formula you look at,\n  by looking at what introduced it,\n  you can point to a larger b-formula\n  when b < c\n\n\n  Let's say we show the local property:\n    at all steps, all c-formulas are smaller than bmax\n\n  Then we get a property about each step.\n  But the measure is defined across the steps.\n  So we need to show\n  - Each step is at most the measure (should be possible)\n  - There is a step equal to the measure\n  So we get a tight bound.\n*)\n\n\nlemma zoop1a:\n  assumes \\<open>ipath tab steps\\<close> \\<open>wft A tab\\<close>\n  shows \\<open>ev (holds (\\<lambda>step. \\<exists>p. p at i in getBranch step \\<and> M_branch i steps \\<le> size p)) steps\\<close>\n  sorry\n\n\n\nlemma zoop3:\n  assumes \\<open>ipath tab steps\\<close> \\<open>wft A tab\\<close>\n    \\<open>Fresh b t c \\<in> getTag ` sset steps\\<close> (* b < c *)\n    \\<open>M_branch b steps \\<le> bmax\\<close>\n  shows \\<open>alw (holds (\\<lambda>step. M_branch c steps < bmax)) steps\\<close>\nproof -\n  have \\<open>alw (holds (\\<lambda>step. \\<forall>r. r at c in getBranch step \\<longrightarrow> size r < bmax)) steps\\<close>\n    using assms zoop2 by fast\n  then have *: \\<open>\\<forall>step \\<in> sset steps. \\<forall>r. r at c in getBranch step \\<longrightarrow> size r < bmax\\<close>\n    using alw_sset by (metis (mono_tags, lifting))\n  \n  have\n    \\<open>alw (holds (\\<lambda>step. \\<forall>p. p at c in getBranch step \\<longrightarrow> size p \\<le> M_branch c steps)) steps\\<close>\n    using assms zoop1 by fast\n  then have **:\n    \\<open>\\<forall>step \\<in> sset steps. \\<forall>p. p at c in getBranch step \\<longrightarrow> size p \\<le> M_branch c steps\\<close>\n    using alw_sset by (metis (mono_tags, lifting))\n\n  have \\<open>\\<forall>step \\<in> sset steps. M_branch c steps \\<le> bmax\\<close>\n  proof\n    fix step\n    assume step: \\<open>step \\<in> sset steps\\<close>\n    then have \\<open>\\<forall>r. r at c in getBranch step \\<longrightarrow> size r < bmax\\<close>\n      using * by blast\n    moreover have \\<open>\\<forall>r. r at c in getBranch step \\<longrightarrow> size r \\<le> M_branch c steps\\<close>\n      using step ** by blast\n    ultimately show \\<open>M_branch c steps \\<le> bmax\\<close>\n      (* this makes no sense *)\n      sorry\n  qed\n  then show ?thesis\n    sorry\nqed\n\nlemma\n  assumes \\<open>ipath tab steps\\<close> \\<open>wft A tab\\<close>\n    \\<open>Fresh b t c \\<in> getTag ` sset steps\\<close> (* b < c *)\n    \\<open>pc \\<in> fms_at c steps\\<close> \\<open>\\<forall>q. q \\<in> fms_at c steps \\<longrightarrow> size q \\<le> size pc\\<close> (* pc max at c *)\n  shows \\<open>size pc < M_branch b steps\\<close>\n  using assms\nproof cases\n  case (IPath s' subs tail l)\n  then have wft: \\<open>wft A s'\\<close>\n    using assms(2) wft_alwt by (auto elim: wft.cases)\n  from assms(2) show ?thesis\n  proof cases\n    case (WfClose p i branch n)\n    then show ?thesis\n      using IPath(1, 3) by simp\n  next\n    case (WfOpen branch n)\n    then show ?thesis\n      using IPath(1, 3) by simp\n  next\n    case (WfNeg p a ps branch s n)\n    then show ?thesis\n      using IPath assms(3-) sorry\n        (* if p = pc then \\<not> \\<not> p is bigger. Contradiction *)\n        (* otherwise we need to know the thesis held before the extension *)\n  next\n    case (WfDisP p q a ps branch sl n sr)\n    then show ?thesis sorry\n  next\n    case (WfDisN p q a ps branch s n intro)\n    then show ?thesis sorry\n  next\n    case (WfDiaP p a ps branch i s n)\n    then show ?thesis sorry\n  next\n    case (WfDiaN p a ps branch i s n)\n    then show ?thesis sorry\n  next\n    case (WfSatP a p b ps branch s n)\n    then show ?thesis sorry\n  next\n    case (WfSatN a p b ps branch s n)\n    then show ?thesis sorry\n  next\n    case (WfGoTo i branch s n)\n    then show ?thesis sorry\n  next\n    case (WfNom p b ps a branch s n)\n    then show ?thesis sorry\n  qed\nqed\n\n\n(* TODO: this is what we want for the infinite descent, question is how easy it is to prove *)\nlemma woop4:\n  assumes \\<open>ipath tab steps\\<close> \\<open>wft A tab\\<close>\n    \\<open>Fresh b t c \\<in> getTag ` sset steps\\<close> (* b < c *)\n  shows \\<open>M_branch c steps < M_branch b steps\\<close>\n  using assms\nproof cases\n  case (IPath s' subs tail l)\n  then have wft: \\<open>wft A s'\\<close>\n    using assms(2) wft_alwt by (auto elim: wft.cases)\n  from assms(2) show ?thesis\n  proof cases\n    case (WfClose p i branch n)\n    then show ?thesis\n      using IPath(1, 3) by simp\n  next\n    case (WfOpen branch n)\n    then show ?thesis\n      using IPath(1, 3) by simp\n  next\n    case (WfNeg p a ps branch s n)\n    then show ?thesis\n      unfolding M_branch_def\n      using IPath (* we lack inductive knowledge to build on *)\n      sorry\n  next\n    case (WfDisP p q a ps branch sl n sr)\n    then show ?thesis sorry\n  next\n    case (WfDisN p q a ps branch s n intro)\n    then show ?thesis sorry\n  next\n    case (WfDiaP p a ps branch i s n)\n    then show ?thesis sorry\n  next\n    case (WfDiaN p a ps branch i s n)\n    then show ?thesis sorry\n  next\n    case (WfSatP a p b ps branch s n)\n    then show ?thesis sorry\n  next\n    case (WfSatN a p b ps branch s n)\n    then show ?thesis sorry\n  next\n    case (WfGoTo i branch s n)\n    then show ?thesis sorry\n  next\n    case (WfNom p b ps a branch s n)\n    then show ?thesis sorry\n  qed\nqed\n\nlemma ne_sset: \\<open>sset steps \\<noteq> {}\\<close>\n  by (cases steps) auto\n\nlemma fms_at_sdrop: \\<open>fms_at i (sdrop n steps) \\<subseteq> fms_at i steps\\<close>\n  unfolding fms_at_def (* TODO: smt *)\n  by (smt (verit) Collect_mono sdrop_add sdrop_simps(1) snth_sset sset_sdrop)\n\nlemma M_branch_sdrop: \\<open>M_branch i (sdrop n steps) \\<le> M_branch i steps\\<close>\n  unfolding M_branch_def using fms_at_sdrop sorry\n\nlemma ipath_infgens':\n  assumes \\<open>ipath tab steps\\<close> \\<open>wft A tab\\<close> \\<open>infgens bs steps\\<close>\n    (* TODO: derive some infgens from ipath *)\n    \\<open>M_branch (shd bs) steps < r\\<close> \\<comment> \\<open>to less-induct on a natural number (r)\\<close>\n  shows \\<open>False\\<close>\n  using assms\nproof (induct r arbitrary: tab bs steps rule: less_induct)\n  case (less x)\n  from less(4) show ?case\n  proof cases\n    case (InfGens i p j n bs')\n    then have \\<open>Fresh i p j \\<in> getTag ` sset steps\\<close>\n      using stake_snth by fastforce\n    then have \\<open>M_branch j steps < M_branch i steps\\<close>\n      using less(2-3) woop4 by fast\n    then have \\<open>M_branch j (sdrop n steps) < M_branch i steps\\<close>\n      using M_branch_sdrop by (metis le_less_trans)\n    then have \\<open>M_branch j (sdrop n steps) < M_branch (shd bs) steps\\<close>\n      using InfGens(1) by simp\n    moreover note \\<open>infgens (j ## bs') (sdrop n steps)\\<close> \\<open>M_branch (shd bs) steps < x\\<close>\n    moreover obtain t where \\<open>wft A t\\<close> \\<open>ipath t (sdrop n steps)\\<close>\n      using less(2-3) wft_ipath_sdrop by blast\n    ultimately show False\n      using less(1) by fastforce    \n  qed\nqed\n\ntheorem ipath_infgens:\n  assumes \\<open>ipath tab steps\\<close> \\<open>wft A tab\\<close>\n  shows \\<open>\\<not> infgens bs steps\\<close>\n  using assms ipath_infgens' by fast\n\n(*\n  m turns a branch and a nominal into a natural number\n  then we less_induct on that number\n*)\n\nsection \\<open>THINGS I MAY NOT NEED\\<close>\n\n(* TODO: I don't think we actually need the whole (q)subfm machinery, just quasis. *)\n\nprimrec subfm :: \\<open>('a, 'b) fm \\<Rightarrow> ('a, 'b) fm \\<Rightarrow> bool\\<close> where\n  \\<open>subfm p (Pro x) = (p = Pro x)\\<close>\n| \\<open>subfm p (Nom a) = (p = Nom a)\\<close>\n| \\<open>subfm p (\\<^bold>\\<not> q) = (p = (\\<^bold>\\<not> q) \\<or> subfm p q)\\<close>\n| \\<open>subfm p (q \\<^bold>\\<or> r) = (p = (q \\<^bold>\\<or> r) \\<or> subfm p q \\<or> subfm p r)\\<close>\n| \\<open>subfm p (\\<^bold>\\<diamond> q) = (p = (\\<^bold>\\<diamond> q) \\<or> subfm p q)\\<close>\n| \\<open>subfm p (\\<^bold>@ i q) = (p = (\\<^bold>@ i q) \\<or> p = Nom i \\<or> subfm p q)\\<close>\n\nlemma subfm_refl [simp]: \\<open>subfm p p\\<close>\n  by (cases p) simp_all\n\nlemma subfm_trans: \\<open>subfm p q \\<Longrightarrow> subfm q r \\<Longrightarrow> subfm p r\\<close>\n  by (induct r) auto\n\nlemma subfm_reflp: \\<open>reflp subfm\\<close>\n  unfolding reflp_def by simp\n\nlemma subfm_transp: \\<open>transp subfm\\<close>\n  unfolding transp_def using subfm_trans by blast\n\nlemma nominals_subfm [simp]: \\<open>i \\<in> nominals p \\<Longrightarrow> subfm (Nom i) p\\<close>\n  by (induct p) auto\n\ninductive qsubfm :: \\<open>('a, 'b) fm \\<Rightarrow> ('a, 'b) fm \\<Rightarrow> bool\\<close> where\n  (* q is fixed but to express that, I need to put it first which would be annoying *)\n  PureSub: \\<open>subfm p q \\<Longrightarrow> qsubfm p q\\<close>\n| NegPSub: \\<open>subfm p q \\<Longrightarrow> qsubfm (\\<^bold>\\<not> p) q\\<close>\n| SatPSub: \\<open>subfm p q \\<Longrightarrow> qsubfm (\\<^bold>@ i p) q\\<close>\n| SatNSub: \\<open>subfm p q \\<Longrightarrow> qsubfm (\\<^bold>\\<not> (\\<^bold>@ i p)) q\\<close>\n\nlemma qsubfm_reflp: \\<open>reflp qsubfm\\<close>\n  unfolding reflp_def by (simp add: PureSub)\n\nlemma quasis_qsubfm: \\<open>p' \\<in> quasis A p \\<Longrightarrow> qsubfm p' p \\<and> size p' \\<le> size p\\<close>\n  by (induct p arbitrary: p' rule: quasis.induct)\n    (fastforce simp: qsubfm.intros elim: qsubfm.cases split: if_splits)+\n\nsubsection \\<open>Distinct branches\\<close>\n\nlemma fin_finite_branches:\n  assumes \\<open>fin tab\\<close> \\<open>wft A tab\\<close>\n  shows \\<open>finite (getBranch ` labels tab)\\<close>\n  using assms by induct (fastforce simp: image_UN elim: wft.cases)\n\ncorollary infinite_branches_infin:\n  assumes \\<open>infinite (getBranch ` labels tab)\\<close> \\<open>wft A tab\\<close>\n  shows \\<open>infin tab\\<close>\n  using assms fin_finite_branches by blast\n\ndefinition nformulas :: \\<open>('a, 'b) branch \\<Rightarrow> nat\\<close> where\n  \\<open>nformulas branch \\<equiv> sum_list (map (Suc o length o fst) branch)\\<close>\n\nlemma alwt_nformulas:\n  assumes \\<open>wft A tab\\<close> \\<open>nformulas branch' < nformulas (getBranch (getLabel tab))\\<close>\n  shows \\<open>alwt (holdst (\\<lambda>step. nformulas branch' < nformulas (getBranch step))) tab\\<close>\n  using assms unfolding nformulas_def\n  by (coinduction arbitrary: tab) (fastforce elim: wft.cases)\n\nlemma nformulas_subs:\n  assumes \\<open>wft A (Node l subs)\\<close> \\<open>s \\<in> set subs\\<close>\n  shows \\<open>nformulas (getBranch l) < nformulas (getBranch (getLabel s))\\<close>\n  using assms unfolding nformulas_def by (fastforce elim: wft.cases)\n\n(* TODO: may not be useful *)\nlemma wft_potential_bound:\n  assumes\n    \\<open>wft A tab\\<close>\n    \\<open>getPotential (getLabel tab) \\<le> start + nformulas (getBranch (getLabel tab))\\<close>\n  shows \\<open>alwt (holdst (\\<lambda>step. getPotential step \\<le> start + nformulas (getBranch step))) tab\\<close>\n  using assms unfolding nformulas_def\n  by (coinduction arbitrary: tab) (fastforce elim: wft.cases)\n\nsubsection \\<open>Preservation\\<close>\n\nabbreviation preserved :: \\<open>('a, 'b) branch \\<Rightarrow> ('a, 'b) branch \\<Rightarrow> bool\\<close> where\n  \\<open>preserved branch branch' \\<equiv> \\<forall>p b. p at b in branch \\<longrightarrow> p at b in branch'\\<close>\n\nlemma alwt_preservation':\n  assumes \\<open>wft A tab\\<close> \\<open>preserved branch' (getBranch (getLabel tab))\\<close>\n  shows \\<open>alwt (holdst (\\<lambda>step. preserved branch' (getBranch step))) tab\\<close>\n  using assms\nproof (coinduction arbitrary: tab)\n  case alwt\n  then show ?case\n  proof cases\n    case (WfNeg p a ps branch s n)\n    from this(1, 4, 6) show ?thesis\n      using alwt(2) by fastforce\n  next\n    case (WfDisP p q a ps branch sl n sr)\n    from this(1, 5, 7, 9-10) show ?thesis\n      using alwt(2) by fastforce\n  next\n    case (WfDisN p q a ps branch s n)\n    from this(1, 4, 6) show ?thesis\n      using alwt(2) by fastforce\n  next\n    case (WfDiaP p a ps branch i s n)\n    from this(1, 6, 8) show ?thesis\n      using alwt(2) by fastforce\n  next\n    case (WfDiaN p a ps branch i s n)\n    from this(1, 5, 7) show ?thesis\n      using alwt(2) by fastforce\n  next\n    case (WfSatP a p b ps branch s n)\n    from this(1, 4, 6) show ?thesis\n      using alwt(2) by fastforce\n  next\n    case (WfSatN a p b ps branch s n)\n    from this(1, 4, 6) show ?thesis\n      using alwt(2) by fastforce\n  next\n    case (WfNom p b ps a branch s n)\n    from this(1, 6, 8) show ?thesis\n      using alwt(2) by fastforce\n  qed auto\nqed\n\nlemma alwt_preservation:\n  assumes \\<open>wft A tab\\<close>\n  shows \\<open>alwt (holdst (\\<lambda>step. preserved (getBranch (getLabel tab)) (getBranch step))) tab\\<close>\n  using assms alwt_preservation' by blast\n\ncorollary alwt_preservation_subs:\n  assumes \\<open>wft A tab\\<close> \\<open>s \\<in> set (getSubs tab)\\<close>\n  shows \\<open>alwt (holdst (\\<lambda>step. preserved (getBranch (getLabel tab)) (getBranch step))) s\\<close>\n  using assms alwt_preservation by (fastforce elim: alwt.cases)\n\nlemma reflp_preserved: \\<open>reflp preserved\\<close>\n  unfolding reflp_def by simp\n\nlemma transp_preserved: \\<open>transp preserved\\<close>\n  unfolding transp_def by simp\n\nend", "meta": {"author": "astahfrom", "repo": "hybrid_termination", "sha": "90e970d6cfaa7f0a6afa9debb890e5f808275fcb", "save_path": "github-repos/isabelle/astahfrom-hybrid_termination", "path": "github-repos/isabelle/astahfrom-hybrid_termination/hybrid_termination-90e970d6cfaa7f0a6afa9debb890e5f808275fcb/Termination.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.523420348936324, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.28819909939536564}}
{"text": "section \\<open>AsynchronousSystem\\<close>\n\ntext \\<open>\n  \\file{AsynchronousSystem} defines a message datatype and a transition system locale to\n  model asynchronous distributed computation. It establishes a diamond property for a\n  special reachability relation within such transition systems.\n\\<close>\n\ntheory AsynchronousSystem\nimports Multiset\nbegin\n\ntext\\<open>\n  The formalization is type-parameterized over\n  \\begin{description}\n    \\item[\\var{'p} process identifiers.] Corresponds to the set $P$ in Völzer.\n      Finiteness is not yet demanded, but will be in \\file{FLPSystem}.\n    \\item[\\var{'s} process states.] Corresponds to $S$, countability is not\n      imposed.\n    \\item[\\var{'v} message payloads.] Corresponds to the interprocess\n      communication part of $M$ from Völzer. The whole of $M$ is captured by\n      \\isb{messageValue}.\n  \\end{description}\n\\<close>\n\nsubsection\\<open>Messages\\<close>\n\ntext \\<open>\n  A \\isb{message} is either an initial input message telling a process\n  which value it should introduce to the consensus negotiation, a message\n  to the environment communicating the consensus outcome, or a message\n  passed from one process to some other.\n\\<close>\n\ndatatype ('p, 'v) message =\n  InMsg 'p bool  (\"<_, inM _>\")\n| OutMsg bool    (\"<\\<bottom>, outM _>\")\n| Msg 'p 'v      (\"<_, _>\")\n\ntext \\<open>\n  A message value is the content of a message, which a process may receive. \n\\<close>\n\ndatatype 'v messageValue = \n  Bool bool\n| Value 'v\n\nprimrec unpackMessage :: \"('p, 'v) message \\<Rightarrow> 'v messageValue\"\nwhere\n  \"unpackMessage <p, inM b>  = Bool b\"\n| \"unpackMessage <p, v>      = Value v\"\n| \"unpackMessage <\\<bottom>, outM v> = Bool False\"\n\nprimrec isReceiverOf :: \n  \"'p \\<Rightarrow> ('p, 'v) message \\<Rightarrow> bool\"\nwhere \n   \"isReceiverOf p1 (<p2, inM v>) = (p1 = p2)\"\n | \"isReceiverOf p1 (<p2, v>) =     (p1 = p2)\"\n | \"isReceiverOf p1 (<\\<bottom>,outM v>) =  False\"\n\nlemma UniqueReceiverOf:\nfixes \n  msg  :: \"('p, 'v) message\" and\n  p q :: 'p\nassumes\n  \"isReceiverOf q msg\"\n  \"p \\<noteq> q\"\nshows \n  \"\\<not> isReceiverOf p msg\"\nusing assms by (cases msg, auto)\n\nsubsection\\<open>Configurations\\<close>\n\ntext \\<open>\n  Here we formalize a configuration as detailed in section 2 of Völzer's paper.\n\n  Note that Völzer imposes the finiteness of the message multiset by\n  definition while we do not do so. In \\isb{FiniteMessages}\n  We prove the finiteness to follow from the assumption that only\n  finitely many messages can be sent at once.\n\\<close>\n\nrecord ('p, 'v, 's) configuration =\n  states :: \"'p \\<Rightarrow> 's\"\n  msgs :: \"(('p, 'v) message) multiset\"\n\ntext \\<open>\n  C.f. Völzer: \\textquote{A step is identified with a message $(p, m)$. A step $(p, m)$ is enabled\n  in a configuration c if $\\var{msgs}_c$ contains the message $(p, m)$.}\n\\<close>\n\ndefinition enabled ::\n  \"('p, 'v, 's) configuration \\<Rightarrow> ('p, 'v) message \\<Rightarrow> bool\"\nwhere \n  \"enabled cfg msg \\<equiv> (msg \\<in># msgs cfg)\"\n\nsubsection \\<open>The system locale\\<close>\n\ntext \\<open>\n  The locale describing a system is derived by slight refactoring from the\n  following passage of Völzer:\n  \\begin{displayquote}\n    A process $p$ consists of an initial state $s_p \\in S$ and a step transition\n    function, which assigns to each pair $(m, s)$ of a message value $m$ and\n    a process state $s$ a follower state and a finite set of messages (the\n    messages to be sent by $p$ in a step).\n  \\end{displayquote}\n\\<close>\n\nlocale asynchronousSystem =\nfixes \n  trans :: \"'p \\<Rightarrow> 's \\<Rightarrow> 'v messageValue \\<Rightarrow> 's\" and\n  sends :: \"'p \\<Rightarrow> 's \\<Rightarrow> 'v messageValue \\<Rightarrow> ('p, 'v) message multiset\" and\n  start :: \"'p \\<Rightarrow> 's\"\nbegin\n\nabbreviation Proc :: \"'p set\"\nwhere \"Proc \\<equiv> (UNIV :: 'p set)\"\n\nsubsection \\<open>The step relation\\<close>\n\ntext \\<open>\n  The step relation is defined analogously to Völzer:\n  \\begin{displayquote}\n    {[}If enabled, a step may{]} occur, resulting in a follower\n    configuration $c^\\prime$, where $c^\\prime$ is obtained from $c$ by removing\n    $(p, m)$ from $\\var{msgs}_c$, changing $p$'s state and adding the set of\n    messages to $\\var{msgs}_c$ according to the step transition function\n    associated with $p$. We denote this by $c \\xrightarrow{p,m} c^\\prime$.\n  \\end{displayquote}\n  There are no steps consuming output messages.\n\\<close>\n\nprimrec steps :: \n  \"('p, 'v, 's) configuration\n   \\<Rightarrow> ('p, 'v) message\n   \\<Rightarrow> ('p, 'v, 's) configuration\n   \\<Rightarrow> bool\"\n   (\"_ \\<turnstile> _ \\<mapsto> _\" [70,70,70])\nwhere \n  StepInMsg: \"cfg1 \\<turnstile> <p, inM v> \\<mapsto> cfg2 = (\n  (\\<forall> s. ((s = p) \\<longrightarrow> states cfg2 p = trans p (states cfg1 p) (Bool v))\n      \\<and> ((s \\<noteq> p) \\<longrightarrow> states cfg2 s = states cfg1 s))\n   \\<and> enabled cfg1 <p, inM v>\n   \\<and> msgs cfg2 = (sends p (states cfg1 p) (Bool v)\n                  \\<union># (msgs cfg1 -# <p, inM v>)))\"\n| StepMsg: \"cfg1 \\<turnstile> <p, v> \\<mapsto> cfg2 = (\n  (\\<forall> s. ((s = p) \\<longrightarrow> states cfg2 p = trans p (states cfg1 p) (Value v))\n      \\<and> ((s \\<noteq> p) \\<longrightarrow> states cfg2 s = states cfg1 s))\n   \\<and> enabled cfg1 <p, v>\n   \\<and> msgs cfg2 = (sends p (states cfg1 p) (Value v)\n                  \\<union># (msgs cfg1 -# <p, v>)))\"\n| StepOutMsg: \"cfg1 \\<turnstile> <\\<bottom>,outM v> \\<mapsto> cfg2 = \n    False\"\n\ntext \\<open>\n  The system is distributed and asynchronous in the sense that the processing\n  of messages only affects the process the message is directed to while the\n  rest stays unchanged.\n\\<close>\nlemma NoReceivingNoChange:\nfixes\n  cfg1 cfg2 :: \"('p,'v,'s) configuration\" and\n  m :: \"('p,'v) message\" and\n  p :: 'p\nassumes\n  Step: \"cfg1 \\<turnstile> m \\<mapsto> cfg2\" and\n  Rec: \"\\<not> isReceiverOf p m\"\nshows\n  \"states cfg1 p = states cfg2 p \"\nproof(cases m)\n  case (OutMsg b')\n  thus ?thesis using Step by auto\nnext\n  case (InMsg q b')\n  assume CaseM:  \"m = <q, inM b'>\"\n  with assms have \"p \\<noteq> q\" by simp\n  with Step CaseM show ?thesis by simp\nnext\n  case (Msg q v')\n  assume CaseM:  \"m = <q, v'>\"\n  with assms have \"p \\<noteq> q\" by simp\n  with Step CaseM show ?thesis by simp\nqed\n\nlemma ExistsMsg:\nfixes\n  cfg1 cfg2 :: \"('p,'v,'s) configuration\" and\n  m :: \"('p,'v) message\"\nassumes\n  Step: \"cfg1 \\<turnstile> m \\<mapsto> cfg2\"\nshows\n  \"m \\<in># (msgs cfg1)\"\nusing assms enabled_def by (cases m, auto)\n\nlemma NoMessageLossStep:\nfixes\n  cfg1 :: \"('p,'v,'s) configuration\" and\n  cfg2 :: \"('p,'v,'s) configuration\" and\n  p :: 'p and\n  m :: \"('p,'v) message\" and\n  m' :: \"('p,'v) message\"\nassumes\n  Step: \"cfg1 \\<turnstile> m \\<mapsto> cfg2\" and\n  Rec1: \"isReceiverOf p m\" and\n  Rec2: \"\\<not>isReceiverOf p m'\"\nshows \n  \"msgs cfg1 m' \\<le> msgs cfg2 m'\"\nusing assms by (induct m, simp_all, auto)\n\nlemma OutOnlyGrowing:\nfixes \n  cfg1 cfg2 :: \"('p,'v,'s) configuration\" and\n  b::bool and\n  m::\"('p, 'v) message\" and\n  p::'p\nassumes\n  \"cfg1 \\<turnstile> m \\<mapsto> cfg2\"\n  \"isReceiverOf p m\"\nshows \n  \"msgs cfg2 <\\<bottom>, outM b> \n  = (msgs cfg1 <\\<bottom>, outM b>) + \n    sends p (states cfg1 p) (unpackMessage m) <\\<bottom>, outM b>\" \nproof(-)\n  have \"m = <\\<bottom>, outM b> \\<Longrightarrow> False\" using assms proof(auto) qed\n  hence MNotOut: \"m \\<noteq> <\\<bottom>, outM b>\" by auto\n  have MsgFunction: \"msgs cfg2 \n                    = ((sends p (states cfg1 p) (unpackMessage m)) \n                      \\<union># ((msgs cfg1) -# m))\"\n  proof(cases m) \n    case (InMsg pa bool)\n    then have PaIsP: \"pa = p\" \"(unpackMessage m) = Bool bool\" \n      using isReceiverOf_def assms(2) by (auto simp add: UniqueReceiverOf)\n    hence \"cfg1 \\<turnstile> <p, inM bool> \\<mapsto> cfg2\" using assms(1) InMsg by simp\n    hence \"msgs cfg2 = (sends p (states cfg1 p) (Bool bool) \n                       \\<union># (msgs cfg1 -# <p, inM bool>))\" \n      by simp\n    hence \"msgs cfg2 = (sends p (states cfg1 p) (Bool bool) \n                       \\<union># (msgs cfg1 -# m))\" \n      using PaIsP(1) InMsg by simp\n    thus ?thesis using StepInMsg assms PaIsP by simp\n  next case (OutMsg b)\n    hence False using assms by auto\n    thus ?thesis by simp\n  next case (Msg pa va)\n    hence PaIsP: \"pa = p\" \"(unpackMessage m) = Value va\" \n      using isReceiverOf_def assms(2) by (auto simp add: UniqueReceiverOf)\n    hence \"cfg1 \\<turnstile> <p, va> \\<mapsto> cfg2\" using assms(1) Msg by simp\n    hence \"msgs cfg2 = (sends p (states cfg1 p) (Value va) \n                       \\<union># (msgs cfg1 -# <p, va>))\" by simp\n    hence \"msgs cfg2 = (sends p (states cfg1 p) (Value va) \n                       \\<union># (msgs cfg1 -# m))\" \n      using PaIsP(1) Msg by simp\n    thus ?thesis using StepInMsg assms PaIsP by simp\n  qed\n  have \"((sends p (states cfg1 p) (unpackMessage m)) \n         \\<union># ((msgs cfg1) -# m)) <\\<bottom>, outM b> \n       = ((sends p (states cfg1 p) (unpackMessage m)) \n         \\<union># (msgs cfg1)) <\\<bottom>, outM b>\"\n    using MNotOut by auto\n  thus \"msgs cfg2 <\\<bottom>, outM b> \n       = (msgs cfg1 <\\<bottom>, outM b>) + \n         sends p (states cfg1 p) (unpackMessage m) <\\<bottom>, outM b>\" \n    using MsgFunction by simp\nqed\n\nlemma OtherMessagesOnlyGrowing:\nfixes\n  cfg1 :: \"('p,'v,'s) configuration\" and\n  cfg2 :: \"('p,'v,'s) configuration\" and\n  p :: 'p and\n  m :: \"('p,'v) message\" and\n  m' :: \"('p,'v) message\"\nassumes\n  Step: \"cfg1 \\<turnstile> m \\<mapsto> cfg2\" and\n  \"m \\<noteq> m'\"\nshows\n  \"msgs cfg1 m' \\<le> msgs cfg2 m'\"\nusing assms by (cases m, auto)\n\ntext \\<open>\n  Völzer: \\textquote{Note that steps are enabled persistently, i.e., an\n  enabled step remains enabled as long as it does not occur.}\n\\<close>\nlemma OnlyOccurenceDisables:\nfixes\n  cfg1 :: \"('p,'v,'s) configuration\" and\n  cfg2 :: \"('p,'v,'s) configuration\" and\n  p :: 'p and\n  m :: \"('p,'v) message\" and\n  m' :: \"('p,'v) message\"\nassumes\n  Step: \"cfg1 \\<turnstile> m \\<mapsto> cfg2\" and\n  En: \"enabled cfg1 m'\" and\n  NotEn: \"\\<not> (enabled cfg2 m')\"\nshows\n  \"m = m'\"\nusing assms proof (cases m) print_cases\n  case (InMsg p bool)\n  with Step have \"msgs cfg2 = (sends p (states cfg1 p) (Bool bool) \n                              \\<union># (msgs cfg1 -# <p, inM bool>))\" by auto\n  thus \"m = m'\" using InMsg En NotEn \n    by (auto simp add: enabled_def, metis less_nat_zero_code)\nnext\n  case (OutMsg bool)\n  with Step show \"m = m'\" by auto\nnext\n  case (Msg p v)\n  with Step have \"msgs cfg2 = (sends p (states cfg1 p) (Value v) \n                              \\<union># (msgs cfg1 -# <p, v>))\" by auto\n  thus \"m = m'\" using Msg En NotEn \n    by (auto simp add: enabled_def, metis less_nat_zero_code)\nqed\n\nsubsection \\<open>Reachability\\<close>\n\ninductive reachable :: \n  \"  ('p, 'v, 's) configuration \n  \\<Rightarrow> ('p, 'v, 's) configuration\n  \\<Rightarrow> bool\"\nwhere \n  init: \"reachable cfg1 cfg1\"\n| step: \"\\<lbrakk> reachable cfg1 cfg2; (cfg2 \\<turnstile> msg \\<mapsto> cfg3) \\<rbrakk> \n          \\<Longrightarrow> reachable cfg1 cfg3\"\n\nlemma ReachableStepFirst: \nassumes\n  \"reachable cfg cfg'\"\nshows \n  \"cfg = cfg' \\<or> (\\<exists> cfg1 msg p . (cfg \\<turnstile> msg \\<mapsto> cfg1) \\<and> enabled cfg msg \n                    \\<and> isReceiverOf p msg  \n                    \\<and> reachable cfg1 cfg')\" \nusing assms \nby (induct rule: reachable.induct, auto, \n    metis StepOutMsg ExistsMsg init enabled_def isReceiverOf.simps(1) \n    isReceiverOf.simps(2) message.exhaust, metis asynchronousSystem.step)\n\nlemma ReachableTrans: \nfixes \n  cfg1 cfg2 cfg3 :: \"('p, 'v, 's ) configuration\" and \n  Q :: \" 'p set\"\nassumes \n  \"reachable cfg1 cfg2\" and \n  \"reachable cfg2 cfg3\"\nshows \"reachable cfg1 cfg3\"\nproof - \n  have \"reachable cfg2 cfg3 \\<Longrightarrow> reachable cfg1 cfg2 \\<Longrightarrow> reachable cfg1 cfg3\" \n  proof (induct rule: reachable.induct, auto)\n    fix cfg1' cfg2' msg cfg3'\n    assume \n      \"reachable cfg1 cfg2'\"\n      \"cfg2' \\<turnstile> msg \\<mapsto> cfg3'\"\n    thus \"reachable cfg1 cfg3'\" using reachable.simps by metis\n  qed\n  thus ?thesis using assms by simp\nqed\n\ndefinition stepReachable ::\n    \"('p, 'v, 's) configuration\n  \\<Rightarrow> ('p ,'v) message\n  \\<Rightarrow> ('p, 'v, 's) configuration\n  \\<Rightarrow> bool\" \nwhere\n  \"stepReachable c1 msg c2 \\<equiv> \n    \\<exists> c' c''. reachable c1 c' \\<and> (c' \\<turnstile> msg \\<mapsto> c'') \\<and> reachable c'' c2 \"\n\nlemma StepReachable:\nfixes\n  cfg cfg' :: \"('p,'v,'s) configuration\" and\n  msg :: \"('p, 'v) message\"\nassumes\n  \"reachable cfg cfg'\" and\n  \"enabled cfg msg\" and\n  \"\\<not> (enabled cfg' msg)\"\nshows \"stepReachable cfg msg cfg'\" \nusing assms\nproof(induct rule: reachable.induct, simp)\n  fix cfg1 cfg2 msga cfg3\n  assume Step: \"cfg2 \\<turnstile> msga \\<mapsto> cfg3\" and\n    ReachCfg1Cfg2: \"reachable cfg1 cfg2\" and\n    IV: \"(enabled cfg1 msg \\<Longrightarrow> \\<not> enabled cfg2 msg \n        \\<Longrightarrow> stepReachable cfg1 msg cfg2)\" and\n    AssumpInduct: \"enabled cfg1 msg\" \"\\<not> enabled cfg3 msg\"\n  have ReachCfg2Cfg3: \"reachable cfg2 cfg3\" using Step \n    by (metis reachable.init reachable.step)\n  show \"stepReachable cfg1 msg cfg3\" \n  proof (cases \"enabled cfg2 msg\")\n    assume AssumpEnabled: \"enabled cfg2 msg\"\n    hence \"msga = msg\" using OnlyOccurenceDisables Step AssumpInduct(2) by blast\n    thus \"stepReachable cfg1 msg cfg3\" using ReachCfg1Cfg2 Step \n      unfolding stepReachable_def by (metis init)\n  next\n    assume AssumpNotEnabled: \"\\<not> enabled cfg2 msg\"\n    hence \"stepReachable cfg1 msg cfg2\" using IV AssumpInduct(1) by simp\n    thus \"stepReachable cfg1 msg cfg3\"\n      using ReachCfg2Cfg3 ReachableTrans asynchronousSystem.stepReachable_def\n      by blast\n  qed\nqed\n\nsubsection \\<open>Reachability with special process activity\\<close>\n\ntext \\<open>\n  We say that \\isb{qReachable cfg1 Q cfg2} iff cfg2 is reachable from cfg1\n  only by activity of processes from Q.\n\\<close>\ninductive qReachable ::\n  \"('p,'v,'s) configuration \n  \\<Rightarrow> 'p set \n  \\<Rightarrow> ('p,'v,'s) configuration \n  \\<Rightarrow> bool\"\nwhere  \n  InitQ: \"qReachable cfg1 Q cfg1\"\n| StepQ: \"\\<lbrakk> qReachable cfg1 Q cfg2; (cfg2 \\<turnstile> msg \\<mapsto> cfg3) ;\n            \\<exists> p \\<in> Q . isReceiverOf p msg \\<rbrakk> \n          \\<Longrightarrow> qReachable cfg1 Q cfg3\"\n\ntext \\<open>\n  We say that \\isb{withoutQReachable cfg1 Q cfg2} iff cfg2 is reachable from cfg1\n  with no activity of processes from Q.\n\\<close>\nabbreviation withoutQReachable ::\n   \"('p,'v,'s) configuration \n  \\<Rightarrow> 'p set \n  \\<Rightarrow> ('p,'v,'s) configuration \n  \\<Rightarrow> bool\"\nwhere\n  \"withoutQReachable cfg1 Q cfg2 \\<equiv> \n    qReachable cfg1 ((UNIV :: 'p set ) - Q) cfg2\"\n\ntext\\<open>\n  Obviously q-reachability (and thus also without-q-reachability) implies \n  reachability.\n\\<close>\nlemma QReachImplReach:\nfixes\n  cfg1 cfg2::  \"('p, 'v, 's ) configuration\" and\n  Q :: \" 'p set\"\nassumes\n  \"qReachable cfg1 Q cfg2\"\nshows \n  \"reachable cfg1 cfg2\"\nusing assms \nproof (induct rule: qReachable.induct)\n  case InitQ thus ?case using reachable.simps by blast\nnext\n  case StepQ thus ?case using reachable.step by simp\nqed\n\nlemma QReachableTrans: \nfixes cfg1 cfg2 cfg3 :: \"('p, 'v, 's ) configuration\" and\n  Q :: \" 'p set\"\nassumes \"qReachable cfg2 Q cfg3\" and\n  \"qReachable cfg1 Q cfg2\"\nshows \"qReachable cfg1 Q cfg3\"\nusing assms\nproof (induct rule: qReachable.induct, simp)\n  case (StepQ)\n  thus ?case using qReachable.simps by metis\nqed\n\nlemma NotInQFrozenQReachability: \nfixes\n  cfg1 cfg2 :: \"('p,'v,'s) configuration\" and\n  p :: 'p and\n  Q :: \"'p set\"\nassumes\n  \"qReachable cfg1 Q cfg2\" and\n  \"p \\<notin> Q\"\nshows\n  \"states cfg1 p = states cfg2 p\"\nusing assms \nproof(induct rule: qReachable.induct, auto)\n  fix cfg1' Q' cfg2' msg cfg3 p'\n  assume \"qReachable cfg1' Q' cfg2'\"\n  assume Step: \"cfg2' \\<turnstile> msg \\<mapsto> cfg3\"\n  assume Rec: \"isReceiverOf p' msg\"\n  assume \"p' \\<in> Q'\"  \"p \\<notin> Q'\"\n  hence notEq: \"p \\<noteq> p'\" by blast\n  with Rec have \"\\<not> (isReceiverOf p msg)\" by (cases msg, simp_all)\n  thus \"states cfg2' p = states cfg3 p\"\n    using Step NoReceivingNoChange by simp\nqed\n\ncorollary WithoutQReachablFrozenQ:\nfixes\n  cfg1 cfg2 :: \"('p,'v,'s) configuration\" and\n  p :: 'p and\n  Q :: \"'p set\"\nassumes\n  Steps: \"withoutQReachable cfg1 Q cfg2\" and\n  P: \"p \\<in> Q\"\nshows\n  \"states cfg1 p = states cfg2 p\"\nusing assms NotInQFrozenQReachability by simp\n\nlemma NoActivityNoMessageLoss :\nfixes\n  cfg1 cfg2 :: \"('p,'v,'s) configuration\" and\n  p :: 'p and\n  Q :: \"'p set\" and\n  m' :: \"('p, 'v) message\"\nassumes\n  \"qReachable cfg1 Q cfg2\" and\n  \"p \\<notin> Q\" and\n  \"isReceiverOf p m'\"\nshows\n  \"(msgs cfg1 m') \\<le> (msgs cfg2 m')\"\nusing assms\nproof (induct rule: qReachable.induct, simp)\n  case (StepQ cfg1' Q' cfg2' msg cfg3)\n  then obtain p' where\n    P': \"p' \\<in> Q'\" \"isReceiverOf p' msg\" \"p \\<noteq> p'\" by blast\n  with assms(3) have \"\\<not>(isReceiverOf p' m')\" \n    by (cases m', simp_all)\n  with NoMessageLossStep StepQ(3) P'\n    have \"msgs cfg2' m' \\<le> msgs cfg3 m'\" \n    by simp\n  with StepQ\n    show \"msgs cfg1' m' \\<le> msgs cfg3 m'\" by simp\nqed\n\nlemma NoMessageLoss:\nfixes\n  cfg1 cfg2 :: \"('p,'v,'s) configuration\" and\n  p :: 'p and\n  Q :: \"'p set\" and\n  m' :: \"('p, 'v) message\"\nassumes\n  \"withoutQReachable cfg1 Q cfg2\" and\n  \"p \\<in> Q\" and\n  \"isReceiverOf p m'\"\nshows\n  \"(msgs cfg1 m') \\<le> (msgs cfg2 m')\" \nusing assms NoActivityNoMessageLoss by simp\n\nlemma NoOutMessageLoss:\nfixes\n  cfg1 cfg2 :: \"('p,'v,'s) configuration\" and\n  v :: bool\nassumes\n  \"reachable cfg1 cfg2\"\nshows\n  \"(msgs cfg1 <\\<bottom>, outM v>) \\<le> (msgs cfg2 <\\<bottom>, outM v>)\"\nusing assms \nproof(induct rule: reachable.induct, auto)\n  fix cfg1 cfg' msg cfg2\n  assume AssInduct:\n    \"reachable cfg1 cfg'\"\n    \"msgs cfg1 <\\<bottom>, outM v> \\<le> msgs cfg' <\\<bottom>, outM v>\" \n    \"cfg' \\<turnstile> msg \\<mapsto> cfg2\"\n  from AssInduct(3) have \"msgs cfg' <\\<bottom>, outM v> \\<le> msgs cfg2 <\\<bottom>, outM v>\"  \n    by (cases msg, auto)\n  with AssInduct(2) show \" msgs cfg1 <\\<bottom>, outM v> \\<le> msgs cfg2 <\\<bottom>, outM v>\"\n    using le_trans by blast\nqed \n\nlemma StillEnabled:\nfixes \n  cfg1 cfg2:: \"('p,'v,'s) configuration\" and\n  p :: 'p and\n  msg :: \"('p,'v) message\" and\n  Q :: \"'p set\"\nassumes \n  \"withoutQReachable cfg1 Q cfg2\" and\n  \"p \\<in> Q\" and\n  \"isReceiverOf p msg\" and\n  \"enabled cfg1 msg\"\nshows\n  \"enabled cfg2 msg\"\nusing assms enabled_def NoMessageLoss \n  by (metis le_0_eq neq0_conv)\n\nsubsection\\<open>Initial reachability\\<close>\n\ndefinition initial :: \n  \"('p, 'v, 's) configuration \\<Rightarrow> bool\"\nwhere\n  \"initial cfg \\<equiv>\n        (\\<forall> p::'p . (\\<exists> v::bool . ((msgs cfg (<p, inM v>)) = 1)))\n      \\<and> (\\<forall> p m1 m2 . ((m1 \\<in># (msgs cfg)) \\<and> (m2 \\<in># (msgs cfg)) \n         \\<and> isReceiverOf p m1 \\<and> isReceiverOf p m2) \\<longrightarrow> (m1 = m2))\n      \\<and> (\\<forall> v::bool . (msgs cfg) (<\\<bottom>, outM v>) = 0)\n      \\<and> (\\<forall> p v. (msgs cfg) (<p, v>) = 0)\n      \\<and> states cfg = start\"\n\ndefinition initReachable ::\n  \"('p, 'v, 's) configuration \\<Rightarrow> bool\"\nwhere\n  \"initReachable cfg \\<equiv> \\<exists>cfg0 . initial cfg0 \\<and> reachable cfg0 cfg\"\n\nlemma InitialIsInitReachable :\nassumes \"initial c\"\nshows \"initReachable c\"\n  using assms reachable.init\n  unfolding initReachable_def by blast\n\nsubsection \\<open>Diamond property of reachability\\<close>\n\nlemma DiamondOne:\nfixes\n  cfg cfg1 cfg2 :: \"('p,'v,'s) configuration\" and\n  p q :: 'p and\n  m m' :: \"('p,'v) message\"\nassumes\n  StepP: \"cfg \\<turnstile> m  \\<mapsto> cfg1\" and\n  PNotQ: \"p \\<noteq> q\" and\n  Rec: \"isReceiverOf p m\" \"\\<not> (isReceiverOf p m')\" and\n  Rec': \"isReceiverOf q m'\" \"\\<not> (isReceiverOf q m)\" and\n  StepWithoutP: \"cfg \\<turnstile> m' \\<mapsto> cfg2\"\nshows\n  \"\\<exists> cfg' :: ('p,'v,'s) configuration . (cfg1 \\<turnstile> m' \\<mapsto> cfg')\n        \\<and> (cfg2 \\<turnstile> m \\<mapsto> cfg')\"\nproof (cases m)\n  case (InMsg p b)\n  from StepWithoutP ExistsMsg have \" m' \\<in># (msgs cfg) \" by simp          \n  hence \"m' \\<in># (msgs cfg1)\" \n    using StepP Rec NoMessageLossStep le_neq_implies_less le_antisym \n    by (metis  gr_implies_not0 neq0_conv)\n  hence EnM': \"enabled cfg1 m'\" using enabled_def by auto\n  from StepP ExistsMsg have \"m \\<in># (msgs cfg) \" by simp\n  hence \"m \\<in># (msgs cfg2)\"\n    using StepWithoutP Rec' NoMessageLossStep\n    by (metis le_0_eq neq0_conv)\n  hence EnM: \"enabled cfg2 m\" using enabled_def by auto\n  assume CaseM:  \"m = <p, inM b>\"\n  \n  thus ?thesis \n  proof (cases m') \n    case (OutMsg b')\n    thus ?thesis using StepWithoutP by simp\n  next\n    case (InMsg q b')\n    define cfg' where \"cfg' = \\<lparr>states = \\<lambda>s. (\n      if s = q then\n        trans q (states cfg q) (Bool b')\n      else if s = p then\n        trans p (states cfg p) (Bool b)\n      else\n        states cfg s),\n      msgs = ((sends q (states cfg q) (Bool b')) \n        \\<union># (((sends p (states cfg p) (Bool b))\n            \\<union># ((msgs cfg)-# m)) -# m'))\\<rparr> \"\n    have StepP': \"(cfg1 \\<turnstile> m' \\<mapsto> cfg')\"\n      using StepP  EnM' Rec\n      unfolding cfg'_def InMsg CaseM by auto\n    moreover from EnM have \"(cfg2 \\<turnstile> m \\<mapsto> cfg')\"\n      using InMsg cfg'_def StepP StepP' StepWithoutP NoReceivingNoChange  \n            Rec' CaseM EnM'\n    proof (simp, clarify)\n      assume msgCfg:\n        \"msgs cfg1 = (sends p (states cfg p) (Bool b)  \n                     \\<union># (msgs cfg -# <p, inM b>))\"\n        \"msgs cfg2 = (sends q (states cfg q) (Bool b') \n                     \\<union># (msgs cfg -# <q, inM b'>))\"\n      have \"enabled cfg m\" \"enabled cfg m'\" \n        using StepP StepWithoutP CaseM InMsg \n        by auto\n      with msgCfg show \n        \"(sends q (states cfg q) (Bool b') \\<union># (msgs cfg1 -# <q, inM b'>)) =\n         (sends p (states cfg p) (Bool b) \\<union># (msgs cfg2 -# <p, inM b>))\"\n        using CaseM InMsg StepP StepWithoutP Rec' AXc[of \"m'\" \"m\" \"msgs cfg\"\n          \"sends q (states cfg q) (Bool b')\" \n          \"sends p (states cfg p) (Bool b)\"]         \n        unfolding enabled_def\n        by metis\n    qed\n    ultimately show ?thesis by blast\n  next\n    case (Msg q v')\n    define cfg' where \"cfg' = \\<lparr>states = \\<lambda>s. (\n      if s = q then\n        trans q (states cfg q) (Value v')\n      else if s = p then\n        trans p (states cfg p) (Bool b)\n      else\n        states cfg s),\n      msgs = ((sends q (states cfg q) (Value v')) \n        \\<union># (((sends p (states cfg p) (Bool b))\n            \\<union># ((msgs cfg)-# m))\n            -# m'))\\<rparr>\"\n    have StepP': \"(cfg1 \\<turnstile> m' \\<mapsto> cfg')\"\n      using StepP EnM' Rec\n      unfolding Msg CaseM cfg'_def by auto\n\n    moreover from EnM have \"(cfg2 \\<turnstile> m \\<mapsto> cfg')\"\n      using Msg cfg'_def StepP StepP' StepWithoutP NoReceivingNoChange Rec' CaseM EnM'\n    proof (simp,clarify) \n      assume msgCfg1:\n        \"msgs cfg1 = (sends p (states cfg p) (Bool b)   \n                      \\<union># (msgs cfg -# <p, inM b>))\"\n        \"msgs cfg2 = (sends q (states cfg q) (Value v') \n                      \\<union># (msgs cfg -# <q,  v'>))\" \n      have \"enabled cfg m\" \"enabled cfg m'\" \n        using StepP StepWithoutP CaseM Msg \n        by auto\n      with msgCfg1 show \n        \"(sends q (states cfg q) (Value v') \\<union># (msgs cfg1 -# <q, v'>)) =\n         (sends p (states cfg p) (Bool b) \\<union># (msgs cfg2 -# <p, inM b>))\"\n        using CaseM Msg StepP StepWithoutP Rec' AXc[of \"m'\" \"m\" \"msgs cfg\"\n          \"sends q (states cfg q) (Value v')\" \n          \"sends p (states cfg p) (Bool b)\"]\n        unfolding enabled_def by metis\n    qed\n    ultimately show ?thesis by blast\n  qed\nnext\n  case (OutMsg b)\n  thus ?thesis using StepP by simp\nnext\n  case (Msg p v)\n  from StepWithoutP ExistsMsg have \" m' \\<in># (msgs cfg) \" by simp\n  hence \"m' \\<in># (msgs cfg1)\" \n    using StepP Rec NoMessageLossStep le_neq_implies_less le_antisym \n    by (metis  gr_implies_not0 neq0_conv)\n  hence EnM': \"enabled cfg1 m'\" using enabled_def by auto\n  from StepP ExistsMsg have \"m \\<in># (msgs cfg) \" by simp\n  hence \"m \\<in># (msgs cfg2)\"\n    using StepWithoutP Rec' NoMessageLossStep\n    by (metis le_0_eq neq0_conv)\n  hence EnM: \"enabled cfg2 m\" using enabled_def by auto\n  assume CaseM:  \"m = <p, v>\" \n  thus ?thesis \n  proof (cases m')\n    case (OutMsg b')\n    thus ?thesis using StepWithoutP by simp\n  next\n    case (InMsg q b')\n    define cfg' where \"cfg' = \\<lparr>states = \\<lambda>s. (\n      if s = q then\n        trans q (states cfg q) (Bool b')\n      else if s = p then\n        trans p (states cfg p) (Value v)\n      else\n        states cfg s),\n      msgs = ((sends q (states cfg q) (Bool b')) \n        \\<union># (((sends p (states cfg p) (Value v))\n        \\<union># ((msgs cfg)-# m))\n        -# m'))\\<rparr> \"\n    hence StepP': \"(cfg1 \\<turnstile> m' \\<mapsto> cfg')\"\n      using StepP InMsg EnM' Rec CaseM\n      by auto\n    moreover from EnM have \"(cfg2 \\<turnstile> m \\<mapsto> cfg')\"\n      using InMsg cfg'_def StepP StepP' StepWithoutP NoReceivingNoChange Rec' \n            CaseM EnM'\n    proof (simp, clarify)\n      assume msgCfg:\n        \"msgs cfg1 = (sends p (states cfg p) (Value v)\n          \\<union># (msgs cfg -# <p, v>))\"\n        \"msgs cfg2 = (sends q (states cfg q) (Bool b')\n          \\<union># (msgs cfg -# <q, inM b'>))\"\n      have \"enabled cfg m\" \"enabled cfg m'\"\n        using StepP StepWithoutP CaseM InMsg by auto\n      with msgCfg show \" (sends q (states cfg q) (Bool b') \n                         \\<union># (msgs cfg1 -# <q, inM b'>)) \n                       = (sends p (states cfg p) (Value v) \n                         \\<union># (msgs cfg2 -# <p, v>))\"\n        using CaseM StepP StepWithoutP Rec' InMsg AXc[of \"m'\" \"m\" \"msgs cfg\"\n          \"sends q (states cfg q) (Bool b')\"\n          \"sends p (states cfg p) (Value v)\"]\n          unfolding enabled_def by metis\n    qed\n    ultimately show ?thesis by blast\n  next\n    case (Msg q v')\n    define cfg' where \"cfg' = \\<lparr>states = \\<lambda>s. (\n      if s = q then\n        trans q (states cfg q) (Value v')\n      else if s = p then\n        trans p (states cfg p) (Value v)\n      else\n        states cfg s),\n      msgs = ((sends q (states cfg q) (Value v')) \n        \\<union># (((sends p (states cfg p) (Value v))\n        \\<union># ((msgs cfg)-# m))\n        -# m'))\\<rparr> \"\n    hence StepP': \"(cfg1 \\<turnstile> m' \\<mapsto> cfg')\"\n      using StepP Msg EnM' Rec CaseM by auto\n    moreover from EnM have \"(cfg2 \\<turnstile> m \\<mapsto> cfg')\"\n      using Msg cfg'_def StepP StepP' StepWithoutP NoReceivingNoChange Rec' CaseM EnM'\n    proof (simp, clarify)\n      assume msgCfg:\n        \"msgs cfg1 = (sends p (states cfg p) (Value v)\n          \\<union># (msgs cfg -# <p, v>))\"\n        \"msgs cfg2 = (sends q (states cfg q) (Value v')\n          \\<union># (msgs cfg -# <q, v'>))\"\n      have \"enabled cfg m\" \"enabled cfg m'\"\n        using StepP StepWithoutP CaseM Msg by auto\n\n      with msgCfg show \" (sends q (states cfg q) (Value v') \n                         \\<union># (msgs cfg1 -# <q, v'>)) \n                       = (sends p (states cfg p) (Value v) \n                         \\<union># (msgs cfg2 -# <p, v>))\"\n        using CaseM StepP StepWithoutP Rec' Msg \n          AXc[of \"m'\" \"m\" \"msgs cfg\" \"sends q (states cfg q) (Value v')\"\n          \"sends p (states cfg p) (Value v)\"]\n        unfolding enabled_def by metis\n    qed\n    ultimately show ?thesis by blast          \n  qed\nqed\n\nlemma DiamondTwo:\nfixes\n  cfg cfg1 cfg2 :: \"('p,'v,'s) configuration\" and\n  Q :: \"'p set\" and\n  msg :: \"('p, 'v) message\"\nassumes\n  QReach: \"qReachable cfg Q cfg1\" and\n  Step: \"cfg  \\<turnstile> msg \\<mapsto> cfg2\"\n        \"\\<exists>p\\<in>Proc - Q. isReceiverOf p msg\"\nshows\n  \"\\<exists> (cfg' :: ('p,'v,'s) configuration) . (cfg1  \\<turnstile> msg \\<mapsto> cfg') \n  \\<and> qReachable cfg2 Q cfg'\"\nusing assms \nproof(induct rule: qReachable.induct)\n  fix cfg Q\n  have \"qReachable cfg2 Q cfg2\" using qReachable.simps(1) by blast\n  moreover assume \"cfg \\<turnstile> msg \\<mapsto> cfg2\" \"\\<exists>p\\<in>UNIV - Q. isReceiverOf p msg\"\n  ultimately have \"(cfg \\<turnstile> msg \\<mapsto> cfg2) \\<and> qReachable cfg2 Q cfg2\" by blast\n  thus \"\\<exists>cfg'.(cfg \\<turnstile> msg \\<mapsto> cfg') \\<and> qReachable cfg2 Q cfg'\" by blast\nnext\n  fix cfg Q cfg1' msga cfg1\n  assume   \"(cfg \\<turnstile> msg \\<mapsto> cfg2)\"\n    \"(\\<exists>p\\<in>UNIV - Q. isReceiverOf p msg)\"\n    \"((cfg \\<turnstile> msg \\<mapsto> cfg2) \\<Longrightarrow>\n     (\\<exists>p\\<in>UNIV - Q. isReceiverOf p msg) \\<Longrightarrow>\n     (\\<exists>cfg'. (cfg1' \\<turnstile> msg \\<mapsto> cfg') \\<and> qReachable cfg2 Q cfg'))\"\n  hence \"(\\<exists>cfg'. (cfg1' \\<turnstile> msg \\<mapsto> cfg') \\<and> (\\<exists>p\\<in>UNIV - Q. isReceiverOf p msg) \n        \\<and> qReachable cfg2 Q cfg')\" by blast\n  then obtain cfg' where Cfg': \"(cfg1' \\<turnstile> msg \\<mapsto> cfg')\" \n    \"(\\<exists>p\\<in>UNIV - Q. isReceiverOf p msg)\" \"qReachable cfg2 Q cfg'\" by blast\n  then obtain p where P: \"p\\<in>UNIV - Q\" \"isReceiverOf p msg\" by blast\n  assume Step2: \"(cfg1' \\<turnstile> msga \\<mapsto> cfg1)\"\n    \"(\\<exists>p\\<in>Q. isReceiverOf p msga)\"\n    \"(qReachable cfg Q cfg1')\"\n  then obtain p' where P': \"p'\\<in>Q\" \"isReceiverOf p' msga\" by blast\n  from P'(1) P(1) have notEq: \"p \\<noteq> p'\" by blast\n  with P(2) P'(2) have \"\\<not> isReceiverOf p' msg\" \"\\<not> isReceiverOf p msga\"\n    using UniqueReceiverOf[of p' msga p] UniqueReceiverOf[of p msg p']\n    by auto\n  with notEq P'(2) P(2) Cfg'(1) Step2(1) have \n    \"\\<exists>cfg''. (cfg' \\<turnstile> msga \\<mapsto> cfg'') \\<and> (cfg1 \\<turnstile> msg \\<mapsto> cfg'')\"\n    using DiamondOne by simp\n  then obtain cfg'' where Cfg'': \"cfg' \\<turnstile> msga \\<mapsto> cfg''\" \"cfg1 \\<turnstile> msg \\<mapsto> cfg''\" \n    by blast\n  from Cfg''(1) Step2(2) Cfg'(3) have \"qReachable cfg2 Q cfg''\" \n    using qReachable.simps[of cfg2 Q cfg''] by auto\n  with Cfg'(2) Cfg''(2) have \n    \"(cfg1 \\<turnstile> msg \\<mapsto> cfg'') \\<and> qReachable cfg2 Q cfg''\"  by simp\n  thus \"\\<exists>cfg'. (cfg1 \\<turnstile> msg \\<mapsto> cfg') \\<and> qReachable cfg2 Q cfg'\" by blast \nqed\n\ntext \\<open>Proposition 1 of Völzer.\\<close>\nlemma Diamond:\nfixes\n  cfg cfg1 cfg2 :: \"('p,'v,'s) configuration\" and\n  Q :: \"'p set\"\nassumes\n  QReach: \"qReachable cfg Q cfg1\" and\n  WithoutQReach: \"withoutQReachable cfg Q cfg2\"\nshows \n  \"\\<exists> cfg'. withoutQReachable cfg1 Q cfg' \n     \\<and> qReachable cfg2 Q cfg'\"\nproof -\n  define notQ where \"notQ \\<equiv> UNIV - Q\"\n  with WithoutQReach have \"qReachable cfg notQ cfg2\" by simp\n  thus ?thesis using QReach notQ_def\n  proof (induct rule: qReachable.induct)\n    fix cfg2\n    assume \"qReachable cfg2 Q cfg1\"\n    moreover have \"qReachable cfg1 (UNIV - Q) cfg1\"\n      using qReachable.simps by blast\n    ultimately show \n      \"\\<exists>cfg'. qReachable cfg1 (UNIV - Q) cfg' \n        \\<and> qReachable cfg2 Q cfg'\"  \n      by blast\n  next\n    fix cfg cfg2' cfg2 msg\n    assume Ass1: \" qReachable cfg Q cfg1\" \"qReachable cfg (UNIV - Q) cfg2' \" \n    assume Ass2:  \"cfg2' \\<turnstile> msg \\<mapsto> cfg2\" \"\\<exists>p\\<in>UNIV - Q. isReceiverOf p msg\"\n    assume \"qReachable cfg Q cfg1 \\<Longrightarrow> \\<exists>cfg'. qReachable cfg1 (UNIV - Q) cfg' \n      \\<and> qReachable cfg2' Q cfg'\"\n    with Ass1(1) have \"\\<exists>cfg'. qReachable cfg1 (UNIV - Q) cfg' \n      \\<and> qReachable cfg2' Q cfg'\" by blast\n    then obtain cfg' where \n      Cfg'1: \"qReachable cfg2' Q cfg'\" and \n      Cfg':  \"qReachable cfg1 (UNIV - Q) cfg'\" by blast\n    from Cfg'1 Ass2 have \n      \"\\<exists>cfg''.(cfg' \\<turnstile> msg \\<mapsto> cfg'') \\<and> qReachable cfg2 Q cfg''\" \n      using DiamondTwo by simp\n    then obtain cfg'' where\n      Cfg'': \"cfg' \\<turnstile> msg \\<mapsto> cfg''\" \"qReachable cfg2 Q cfg''\" by blast\n    from Cfg' Cfg''(1) Ass2(2) have \"qReachable cfg1 (UNIV - Q) cfg''\"  \n      using qReachable.simps[of cfg1 \"UNIV-Q\" cfg''] by auto\n    with Cfg'' show \n      \"\\<exists>cfg'. qReachable cfg1 (UNIV - Q) cfg' \n        \\<and> qReachable cfg2 Q cfg'\" by blast\n  qed\nqed\n\nsubsection \\<open>Invariant finite message count\\<close>\n\nlemma FiniteMessages:\nfixes \n  cfg  :: \"('p, 'v, 's) configuration\"\nassumes\n  FiniteProcs: \"finite Proc\" and\n  FiniteSends: \"\\<And> p s m. finite {v. v \\<in># (sends p s m)}\" and\n  InitReachable: \"initReachable cfg\"\nshows \"finite {msg . msg \\<in># msgs cfg}\"\nproof(-)\n  have \"\\<exists> init . initial init \\<and> reachable init cfg\" using assms \n    unfolding initReachable_def by simp\n  then obtain init where Init: \"initial init\" \"reachable init cfg\" \n    by blast\n  have InitMsgs:\"{msg . msg \\<in># msgs init} \n    = { msg . (msg \\<in># msgs init) \\<and> (\\<exists> p v. <p, v> = msg)} \n      \\<union> { msg . (msg \\<in># msgs init) \\<and> (\\<exists> v.  <\\<bottom>, outM v> = msg)}\n      \\<union> { msg . (msg \\<in># msgs init) \\<and> (\\<exists> p v.  <p, inM v> = msg)}\" \n       by (auto,metis message.exhaust)\n  have A:\"{ msg . (msg \\<in># msgs init) \\<and> (\\<exists> p v. <p, v> = msg)} = {}\" \n  using initial_def[of init] Init(1)by (auto, metis less_not_refl3)\n  have B:\"{ msg . (msg \\<in># msgs init) \\<and> (\\<exists> v.  <\\<bottom>, outM v> = msg)} = {}\" \n  using initial_def[of init] Init(1) by (auto, metis less_not_refl3)\n  have \"\\<forall> p . finite {<p, inM True>, <p, inM False>}\" by auto\n  moreover have SubsetMsg:\n    \"\\<forall> p. { msg . (msg \\<in># msgs init) \n      \\<and> (\\<exists> v::bool .  <p, inM v> = msg)} \n      \\<subseteq> {<p, inM True>, <p, inM False>}\" by auto\n  ultimately have AllFinite:\n    \"\\<forall> p. finite { msg . (msg \\<in># msgs init) \n      \\<and> (\\<exists> v::bool .  <p, inM v> = msg)}\"\n    using finite_subset by (clarify, auto)\n  have \" { msg . (msg \\<in># msgs init) \n    \\<and> (\\<exists> p\\<in>Proc . \\<exists> v::bool.  <p, inM v> = msg)} \n      = (\\<Union> p \\<in> Proc . { msg . (msg \\<in># msgs init) \n    \\<and> (\\<exists> v::bool .  <p, inM v> = msg)})\" by auto\n  hence \"finite  { msg . (msg \\<in># msgs init) \n    \\<and> (\\<exists> p\\<in>Proc . \\<exists> v::bool.  <p, inM v> = msg)}\" \n    using AllFinite FiniteProcs by auto\n  hence InitFinite:\"finite {msg . msg \\<in># msgs init}\" \n    by (auto simp add: A B InitMsgs) \n  show ?thesis using Init(2) InitFinite\n  proof(induct rule: reachable.induct, simp_all)\n    fix cfg1 cfg2 msg cfg3\n    assume assmsInduct:\"reachable cfg1 cfg2\" \n      \"finite {msg. msg \\<in># msgs cfg2}\" \"cfg2 \\<turnstile> msg \\<mapsto> cfg3\" \n      \"finite {msg. msg \\<in># msgs cfg1}\" \"reachable init cfg\" \n      \"finite {msg. msg \\<in># msgs init}\"\n    from assmsInduct(3) obtain p where \"isReceiverOf p msg \" \n      by (metis StepOutMsg isReceiverOf.simps(1) isReceiverOf.simps(2) \n       message.exhaust)\n    hence \"msgs cfg3 = ((msgs cfg2 -# msg) \\<union># (sends p (states cfg2 p) \n      (unpackMessage msg) ))\" \n      using assmsInduct(3) by (cases msg, auto simp add: add.commute)\n    hence MsgSet: \"{msg. msg \\<in>#  msgs cfg3 } \n      = {m. m \\<in># ((msgs cfg2 -# msg) \\<union># (sends p (states cfg2 p) \n        (unpackMessage msg) )) } \" by simp\n    have \"{v. v \\<in># (msgs cfg2 -# msg)} \\<subseteq> {msg. msg \\<in># msgs cfg2}\"\n      by auto\n    from finite_subset[OF this]\n      have \"finite {v. (v \\<in># sends p (states cfg2 p) (unpackMessage msg))\n        \\<or> (v \\<in># (msgs cfg2 -# msg))}\"\n      using FiniteSends assmsInduct(2) by auto\n    thus \"finite {msg. msg \\<in># msgs cfg3}\"\n       unfolding MsgSet by auto\n  qed\nqed\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/FLP/AsynchronousSystem.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.523420348936324, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.28819909939536564}}
{"text": "(*<*)\ntheory BTVSubstTypingL\n  imports  \"HOL-Eisbach.Eisbach_Tools\" ContextSubtypingL SubstMethods\nbegin\n  (*>*)\n\nchapter \\<open>Basic Type Variable Substitution Lemmas\\<close>\ntext \\<open>Lemmas that show that types are preserved, in some way, \nunder basic type variable substitution\\<close>\n\nlemma subst_vv_subst_bb_commute:\n  fixes bv::bv and b::b and x::x and v::v\n  assumes \"atom bv \\<sharp> v\"\n  shows \"(v'[x::=v]\\<^sub>v\\<^sub>v)[bv::=b]\\<^sub>v\\<^sub>b = (v'[bv::=b]\\<^sub>v\\<^sub>b)[x::=v]\\<^sub>v\\<^sub>v\" \n  using assms proof(nominal_induct v'  rule: v.strong_induct)\n  case (V_lit x)\n  then show ?case using subst_vb.simps subst_vv.simps by simp\nnext\n  case (V_var y)\n  hence \"v[bv::=b]\\<^sub>v\\<^sub>b=v\" using forget_subst subst_b_v_def by metis\n  then show ?case unfolding subst_vb.simps(2) subst_vv.simps(2) using V_var by auto\nnext\n  case (V_pair x1a x2a)\n  then show ?case using subst_vb.simps subst_vv.simps by simp\nnext\n  case (V_cons x1a x2a x3)\n  then show ?case using subst_vb.simps subst_vv.simps by simp\nnext\n  case (V_consp x1a x2a x3 x4)\n  then show ?case using subst_vb.simps subst_vv.simps by simp\nqed\n\nlemma subst_cev_subst_bb_commute:\n  fixes bv::bv and b::b and x::x and v::v\n  assumes \"atom bv \\<sharp> v\"\n  shows \"(ce[x::=v]\\<^sub>v)[bv::=b]\\<^sub>c\\<^sub>e\\<^sub>b = (ce[bv::=b]\\<^sub>c\\<^sub>e\\<^sub>b)[x::=v]\\<^sub>v\" \n  using assms apply (nominal_induct ce  rule: ce.strong_induct, (simp add: subst_vv_subst_bb_commute subst_ceb.simps subst_cv.simps))\n  using assms subst_vv_subst_bb_commute subst_ceb.simps subst_cv.simps \n  by (simp add: subst_v_ce_def)+\n\nlemma subst_cv_subst_bb_commute:\n  fixes bv::bv and b::b and x::x and v::v\n  assumes \"atom bv \\<sharp> v\"\n  shows \"c[x::=v]\\<^sub>c\\<^sub>v[bv::=b]\\<^sub>c\\<^sub>b = (c[bv::=b]\\<^sub>c\\<^sub>b)[x::=v]\\<^sub>c\\<^sub>v\" \n  using assms apply (nominal_induct c  rule: c.strong_induct )\n  using assms subst_vv_subst_bb_commute subst_ceb.simps subst_cv.simps \n    subst_v_c_def subst_b_c_def   apply auto\n  using subst_cev_subst_bb_commute subst_v_ce_def by auto+\n\nlemma subst_b_c_of:\n  \"(c_of \\<tau> z)[bv::=b]\\<^sub>c\\<^sub>b =  c_of (\\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b) z\"\nproof(nominal_induct \\<tau> avoiding: z rule:\\<tau>.strong_induct)\n  case (T_refined_type z' b' c')\n  moreover have \"atom bv \\<sharp> [ z ]\\<^sup>v \" using fresh_at_base v.fresh by auto\n  ultimately show ?case using subst_cv_subst_bb_commute[of bv \"V_var z\" c' z' b]  c_of.simps subst_tb.simps by metis\nqed\n\nlemma subst_b_b_of:\n  \"(b_of \\<tau>)[bv::=b]\\<^sub>b\\<^sub>b =  b_of (\\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b)\"\n  by(nominal_induct \\<tau> rule:\\<tau>.strong_induct, simp add: b_of.simps subst_tb.simps )\n\nlemma subst_b_if:\n  \"\\<lbrace> z : b_of \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b  | CE_val (v[bv::=b]\\<^sub>v\\<^sub>b)  ==  CE_val (V_lit ll)   IMP  c_of \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b z  \\<rbrace> = \\<lbrace> z : b_of \\<tau> | CE_val (v)  ==  CE_val (V_lit ll)   IMP  c_of \\<tau> z  \\<rbrace>[bv::=b]\\<^sub>\\<tau>\\<^sub>b \"\n  unfolding subst_tb.simps subst_cb.simps subst_ceb.simps subst_vb.simps using subst_b_b_of   subst_b_c_of by auto\n\nlemma subst_b_top_eq:\n  \"\\<lbrace> z : B_unit  | TRUE \\<rbrace>[bv::=b]\\<^sub>\\<tau>\\<^sub>b = \\<lbrace> z : B_unit  | TRUE \\<rbrace>\" and \"\\<lbrace> z : B_bool  | TRUE \\<rbrace>[bv::=b]\\<^sub>\\<tau>\\<^sub>b = \\<lbrace> z : B_bool  | TRUE \\<rbrace>\"  and \"\\<lbrace> z : B_id tid | TRUE \\<rbrace> = \\<lbrace> z : B_id tid | TRUE \\<rbrace>[bv::=b]\\<^sub>\\<tau>\\<^sub>b\"\n  unfolding  subst_tb.simps subst_bb.simps subst_cb.simps by auto\n\nlemmas subst_b_eq = subst_b_c_of subst_b_b_of subst_b_if subst_b_top_eq\n\nlemma subst_cx_subst_bb_commute[simp]:\n  fixes bv::bv and b::b and x::x and v'::c\n  shows \"(v'[x::=V_var y]\\<^sub>c\\<^sub>v)[bv::=b]\\<^sub>c\\<^sub>b = (v'[bv::=b]\\<^sub>c\\<^sub>b)[x::=V_var y]\\<^sub>c\\<^sub>v\" \n  using subst_cv_subst_bb_commute fresh_at_base  v.fresh by auto\n\nlemma subst_b_infer_b:\n  fixes l::l and b::b\n  assumes \" \\<turnstile> l \\<Rightarrow> \\<tau>\" and \"\\<Theta> ; {||} \\<turnstile>\\<^sub>w\\<^sub>f b\" and \"B = {|bv|}\"\n  shows  \"\\<turnstile> l \\<Rightarrow> (\\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b)\" \n  using assms infer_l_form3 infer_l_form4 wf_b_subst infer_l_wf subst_tb.simps base_for_lit.simps subst_tb.simps\n    subst_b_base_for_lit subst_cb.simps(6) subst_ceb.simps(1) subst_vb.simps(1) subst_vb.simps(2) type_l_eq\n  by metis\n\nlemma subst_b_subtype:\n  fixes s::s and b'::b\n  assumes  \"\\<Theta> ; {|bv|} ; \\<Gamma>  \\<turnstile> \\<tau>1 \\<lesssim> \\<tau>2\" and \"\\<Theta> ; {||} \\<turnstile>\\<^sub>w\\<^sub>f b'\"  and \"B = {|bv|}\" \n  shows \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b']\\<^sub>\\<Gamma>\\<^sub>b  \\<turnstile> \\<tau>1[bv::=b']\\<^sub>\\<tau>\\<^sub>b \\<lesssim> \\<tau>2[bv::=b']\\<^sub>\\<tau>\\<^sub>b\"\n  using assms proof(nominal_induct \"{|bv|}\"  \\<Gamma> \\<tau>1 \\<tau>2 rule:subtype.strong_induct)\n  case (subtype_baseI x \\<Theta> \\<Gamma> z c z' c' b)\n\n  hence **: \"\\<Theta> ; {|bv|} ; (x, b, c[z::=V_var x]\\<^sub>c\\<^sub>v) #\\<^sub>\\<Gamma> \\<Gamma>  \\<Turnstile> c'[z'::=V_var x]\\<^sub>c\\<^sub>v \" using validI subst_defs by metis\n\n  have \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b']\\<^sub>\\<Gamma>\\<^sub>b  \\<turnstile> \\<lbrace> z : b[bv::=b']\\<^sub>b\\<^sub>b | c[bv::=b']\\<^sub>c\\<^sub>b \\<rbrace>  \\<lesssim> \\<lbrace> z' : b[bv::=b']\\<^sub>b\\<^sub>b | c'[bv::=b']\\<^sub>c\\<^sub>b \\<rbrace>\" proof(rule Typing.subtype_baseI)\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b']\\<^sub>\\<Gamma>\\<^sub>b   \\<turnstile>\\<^sub>w\\<^sub>f \\<lbrace> z : b[bv::=b']\\<^sub>b\\<^sub>b  | c[bv::=b']\\<^sub>c\\<^sub>b \\<rbrace> \" \n      using subtype_baseI assms wf_b_subst(4) subst_tb.simps subst_defs  by metis\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b']\\<^sub>\\<Gamma>\\<^sub>b   \\<turnstile>\\<^sub>w\\<^sub>f \\<lbrace> z' : b[bv::=b']\\<^sub>b\\<^sub>b  | c'[bv::=b']\\<^sub>c\\<^sub>b \\<rbrace> \" \n      using subtype_baseI assms wf_b_subst(4) subst_tb.simps by metis\n    show \"atom x \\<sharp>(\\<Theta>, {||}::bv fset, \\<Gamma>[bv::=b']\\<^sub>\\<Gamma>\\<^sub>b,  z , c[bv::=b']\\<^sub>c\\<^sub>b ,  z'  , c'[bv::=b']\\<^sub>c\\<^sub>b )\" \n      apply(unfold fresh_prodN,auto simp add: * fresh_prodN fresh_empty_fset) \n      using subst_b_fresh_x * fresh_prodN  \\<open>atom x \\<sharp> c\\<close> \\<open>atom x \\<sharp> c'\\<close> subst_defs subtype_baseI by metis+\n    have \"\\<Theta> ; {||} ; (x, b[bv::=b']\\<^sub>b\\<^sub>b, c[z::=V_var x]\\<^sub>v[bv::=b']\\<^sub>c\\<^sub>b) #\\<^sub>\\<Gamma> \\<Gamma>[bv::=b']\\<^sub>\\<Gamma>\\<^sub>b  \\<Turnstile> c'[z'::=V_var x]\\<^sub>v[bv::=b']\\<^sub>c\\<^sub>b\" \n      using ** subst_b_valid subst_gb.simps assms  subtype_baseI  by metis\n    thus \"\\<Theta> ; {||} ; (x, b[bv::=b']\\<^sub>b\\<^sub>b, (c[bv::=b']\\<^sub>c\\<^sub>b)[z::=V_var x]\\<^sub>v) #\\<^sub>\\<Gamma> \\<Gamma>[bv::=b']\\<^sub>\\<Gamma>\\<^sub>b  \\<Turnstile> (c'[bv::=b']\\<^sub>c\\<^sub>b)[z'::=V_var x]\\<^sub>v\" \n      using subst_defs subst_cv_subst_bb_commute  by (metis subst_cx_subst_bb_commute)\n  qed\n  thus ?case using subtype_baseI subst_tb.simps subst_defs by metis\nqed\n\nlemma b_of_subst_bv:\n  \"(b_of \\<tau>)[x::=v]\\<^sub>b\\<^sub>b = b_of (\\<tau>[x::=v]\\<^sub>\\<tau>\\<^sub>b)\"\nproof -\n  obtain z b c where *:\"\\<tau> = \\<lbrace> z : b | c \\<rbrace> \\<and> atom z \\<sharp> (x,v)\" using obtain_fresh_z by metis\n  thus ?thesis  using subst_tv.simps * by auto \nqed\n\nlemma subst_b_infer_v:\n  fixes v::v and b::b\n  assumes \"\\<Theta> ; B ; G \\<turnstile> v \\<Rightarrow> \\<tau>\" and \"\\<Theta> ; {||} \\<turnstile>\\<^sub>w\\<^sub>f b\" and \"B = {|bv|}\"\n  shows  \"\\<Theta> ; {||} ; G[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> v[bv::=b]\\<^sub>v\\<^sub>b \\<Rightarrow> (\\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b)\" \n  using assms proof(nominal_induct avoiding: b bv rule: infer_v.strong_induct)\n  case (infer_v_varI \\<Theta> \\<B> \\<Gamma> b' c x z)\n  show ?case unfolding  subst_b_simps proof\n    show \"\\<Theta> ; {||}  \\<turnstile>\\<^sub>w\\<^sub>f \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \" using infer_v_varI wf_b_subst by metis\n    show \"Some (b'[bv::=b]\\<^sub>b\\<^sub>b, c[bv::=b]\\<^sub>c\\<^sub>b) = lookup \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b x\" using subst_b_lookup infer_v_varI by metis\n    show \"atom z \\<sharp> x\" using infer_v_varI by auto\n    show \"atom z \\<sharp>  (\\<Theta>, {||}, \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b) \" by(fresh_mth add: infer_v_varI subst_b_fresh_x subst_b_\\<Gamma>_def fresh_prodN fresh_empty_fset )\n  qed\nnext\n  case (infer_v_litI \\<Theta> \\<B> \\<Gamma> l \\<tau>)\n  then show ?case using Typing.infer_v_litI subst_b_infer_b \n    using wf_b_subst1(3) by auto\nnext\n  case (infer_v_pairI z v1 v2 \\<Theta> \\<B> \\<Gamma> t1 t2)\n  show ?case unfolding   subst_b_simps b_of_subst_bv proof\n    show \"atom z \\<sharp> (v1[bv::=b]\\<^sub>v\\<^sub>b, v2[bv::=b]\\<^sub>v\\<^sub>b)\" by(fresh_mth add: infer_v_pairI subst_b_fresh_x)\n    show \"atom z \\<sharp> (\\<Theta>, {||}, \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b)\" by(fresh_mth add: infer_v_pairI subst_b_fresh_x subst_b_\\<Gamma>_def fresh_empty_fset)\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> v1[bv::=b]\\<^sub>v\\<^sub>b \\<Rightarrow> t1[bv::=b]\\<^sub>\\<tau>\\<^sub>b\" using infer_v_pairI by auto\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> v2[bv::=b]\\<^sub>v\\<^sub>b \\<Rightarrow> t2[bv::=b]\\<^sub>\\<tau>\\<^sub>b\" using infer_v_pairI by auto\n  qed\nnext\n  case (infer_v_consI s dclist \\<Theta> dc tc \\<B> \\<Gamma> v tv z)\n  show ?case unfolding   subst_b_simps b_of_subst_bv proof\n    show \"AF_typedef s dclist \\<in> set \\<Theta>\" using infer_v_consI by auto\n    show \"(dc, tc) \\<in> set dclist\"  using infer_v_consI by auto\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> v[bv::=b]\\<^sub>v\\<^sub>b \\<Rightarrow> tv[bv::=b]\\<^sub>\\<tau>\\<^sub>b\" using infer_v_consI by auto\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b  \\<turnstile> tv[bv::=b]\\<^sub>\\<tau>\\<^sub>b \\<lesssim> tc\" proof -\n      have \"atom bv \\<sharp> tc\" using wfTh_lookup_supp_empty fresh_def infer_v_consI infer_v_wf by fast\n      moreover have  \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b  \\<turnstile> tv[bv::=b]\\<^sub>\\<tau>\\<^sub>b \\<lesssim> tc[bv::=b]\\<^sub>\\<tau>\\<^sub>b\"  \n        using subst_b_subtype infer_v_consI by simp     \n      ultimately show  ?thesis using forget_subst subst_b_\\<tau>_def by metis\n    qed\n    show \"atom z \\<sharp> v[bv::=b]\\<^sub>v\\<^sub>b\"  using infer_v_consI using  subst_b_fresh_x subst_b_v_def by metis\n    show \"atom z \\<sharp> (\\<Theta>, {||}, \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b)\"  by(fresh_mth add: infer_v_consI subst_b_fresh_x subst_b_\\<Gamma>_def fresh_empty_fset)\n  qed\nnext\n  case (infer_v_conspI s bv2 dclist2 \\<Theta> dc tc \\<B> \\<Gamma> v tv ba z)\n\n  have \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> V_consp s dc (ba[bv::=b]\\<^sub>b\\<^sub>b) (v[bv::=b]\\<^sub>v\\<^sub>b) \\<Rightarrow> \\<lbrace> z : B_app s (ba[bv::=b]\\<^sub>b\\<^sub>b)  | [ [ z ]\\<^sup>v ]\\<^sup>c\\<^sup>e  ==  [ V_consp s dc (ba[bv::=b]\\<^sub>b\\<^sub>b) (v[bv::=b]\\<^sub>v\\<^sub>b) ]\\<^sup>c\\<^sup>e  \\<rbrace>\"\n  proof(rule Typing.infer_v_conspI)\n    show \"AF_typedef_poly s bv2 dclist2 \\<in> set \\<Theta>\" using infer_v_conspI by auto\n    show \"(dc, tc) \\<in> set dclist2\"  using infer_v_conspI by auto\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> v[bv::=b]\\<^sub>v\\<^sub>b \\<Rightarrow> tv[bv::=b]\\<^sub>\\<tau>\\<^sub>b\" \n      using infer_v_conspI subst_tb.simps by metis\n\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b  \\<turnstile> tv[bv::=b]\\<^sub>\\<tau>\\<^sub>b \\<lesssim> tc[bv2::=ba[bv::=b]\\<^sub>b\\<^sub>b]\\<^sub>\\<tau>\\<^sub>b\" proof -\n      have \"supp tc \\<subseteq> { atom bv2 }\" using infer_v_conspI wfTh_poly_lookup_supp wfX_wfY by metis\n      moreover have \"bv2 \\<noteq> bv\"  using \\<open>atom bv2 \\<sharp> \\<B>\\<close> \\<open>\\<B> = {|bv|} \\<close> fresh_at_base fresh_def \n        using fresh_finsert by fastforce\n      ultimately have \"atom bv \\<sharp> tc\" unfolding fresh_def by auto\n      hence \"tc[bv2::=ba[bv::=b]\\<^sub>b\\<^sub>b]\\<^sub>\\<tau>\\<^sub>b = tc[bv2::=ba]\\<^sub>\\<tau>\\<^sub>b[bv::=b]\\<^sub>\\<tau>\\<^sub>b\" \n        using subst_tb_commute by metis\n      moreover  have \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b  \\<turnstile> tv[bv::=b]\\<^sub>\\<tau>\\<^sub>b \\<lesssim> tc[bv2::=ba]\\<^sub>\\<tau>\\<^sub>b[bv::=b]\\<^sub>\\<tau>\\<^sub>b\" \n        using infer_v_conspI(7) subst_b_subtype infer_v_conspI by metis\n      ultimately show ?thesis by auto\n    qed    \n    show \"atom z \\<sharp> (\\<Theta>, {||}, \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b, v[bv::=b]\\<^sub>v\\<^sub>b, ba[bv::=b]\\<^sub>b\\<^sub>b)\" \n      apply(unfold fresh_prodN, intro conjI, auto simp add: infer_v_conspI fresh_empty_fset)\n      using \\<open>atom z \\<sharp> \\<Gamma>\\<close>  fresh_subst_if   subst_b_\\<Gamma>_def x_fresh_b  apply metis\n      using \\<open>atom z \\<sharp> v\\<close>  fresh_subst_if   subst_b_v_def x_fresh_b  by metis\n    show \"atom bv2 \\<sharp> (\\<Theta>, {||}, \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b, v[bv::=b]\\<^sub>v\\<^sub>b, ba[bv::=b]\\<^sub>b\\<^sub>b)\" \n      apply(unfold fresh_prodN, intro conjI, auto simp add: infer_v_conspI fresh_empty_fset)\n      using \\<open>atom bv2 \\<sharp> b\\<close>  \\<open>atom bv2 \\<sharp> \\<Gamma>\\<close> fresh_subst_if   subst_b_\\<Gamma>_def apply metis\n      using \\<open>atom bv2 \\<sharp> b\\<close>  \\<open>atom bv2 \\<sharp> v\\<close> fresh_subst_if   subst_b_v_def apply metis\n      using \\<open>atom bv2 \\<sharp> b\\<close>  \\<open>atom bv2 \\<sharp> ba\\<close> fresh_subst_if   subst_b_b_def by metis\n    show \"\\<Theta> ; {||}  \\<turnstile>\\<^sub>w\\<^sub>f ba[bv::=b]\\<^sub>b\\<^sub>b \" \n      using infer_v_conspI  wf_b_subst by metis\n  qed\n  thus ?case using subst_vb.simps subst_tb.simps subst_bb.simps by simp\n\nqed\n\nlemma subst_b_check_v:\n  fixes v::v and b::b\n  assumes \"\\<Theta> ; B ; G \\<turnstile> v \\<Leftarrow> \\<tau>\" and \"\\<Theta> ; {||} \\<turnstile>\\<^sub>w\\<^sub>f b\" and \"B = {|bv|}\"\n  shows  \"\\<Theta> ; {||} ; G[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> v[bv::=b]\\<^sub>v\\<^sub>b \\<Leftarrow> (\\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b)\" \nproof -\n  obtain \\<tau>' where \"\\<Theta> ; B ; G \\<turnstile> v \\<Rightarrow> \\<tau>' \\<and>  \\<Theta> ; B ; G  \\<turnstile> \\<tau>' \\<lesssim> \\<tau>\" using check_v_elims[OF assms(1)] by metis\n  thus ?thesis using subst_b_subtype subst_b_infer_v assms \n    by (metis (no_types)  check_v_subtypeI subst_b_infer_v subst_b_subtype)\nqed\n\nlemma subst_vv_subst_vb_switch:\n  shows  \"(v'[bv::=b']\\<^sub>v\\<^sub>b)[x::=v[bv::=b']\\<^sub>v\\<^sub>b]\\<^sub>v\\<^sub>v = v'[x::=v]\\<^sub>v\\<^sub>v[bv::=b']\\<^sub>v\\<^sub>b\"\nproof(nominal_induct v' rule:v.strong_induct)\n  case (V_lit x)\n  then show ?case using subst_vv.simps subst_vb.simps by auto\nnext\n  case (V_var x)\n  then show ?case using subst_vv.simps subst_vb.simps by auto\nnext\n  case (V_pair x1a x2a)\n  then show ?case using subst_vv.simps subst_vb.simps v.fresh by auto\nnext\n  case (V_cons x1a x2a x3)\n  then show ?case using subst_vv.simps subst_vb.simps v.fresh by auto\nnext\n  case (V_consp x1a x2a x3 x4)\n  then show ?case using subst_vv.simps subst_vb.simps v.fresh pure_fresh \n    by (metis forget_subst subst_b_b_def)\nqed\n\nlemma subst_cev_subst_vb_switch:\n  shows  \"(ce[bv::=b']\\<^sub>c\\<^sub>e\\<^sub>b)[x::=v[bv::=b']\\<^sub>v\\<^sub>b]\\<^sub>c\\<^sub>e\\<^sub>v = (ce[x::=v]\\<^sub>c\\<^sub>e\\<^sub>v)[bv::=b']\\<^sub>c\\<^sub>e\\<^sub>b\"\n  by(nominal_induct ce rule:ce.strong_induct, auto simp add: subst_vv_subst_vb_switch ce.fresh)\n\nlemma subst_cv_subst_vb_switch:\n  shows  \"(c[bv::=b']\\<^sub>c\\<^sub>b)[x::=v[bv::=b']\\<^sub>v\\<^sub>b]\\<^sub>c\\<^sub>v = c[x::=v]\\<^sub>c\\<^sub>v[bv::=b']\\<^sub>c\\<^sub>b\"\n  by(nominal_induct c rule:c.strong_induct, auto simp add: subst_cev_subst_vb_switch c.fresh)\n\nlemma subst_tv_subst_vb_switch:\n  shows  \"(\\<tau>[bv::=b']\\<^sub>\\<tau>\\<^sub>b)[x::=v[bv::=b']\\<^sub>v\\<^sub>b]\\<^sub>\\<tau>\\<^sub>v = \\<tau>[x::=v]\\<^sub>\\<tau>\\<^sub>v[bv::=b']\\<^sub>\\<tau>\\<^sub>b\"\nproof(nominal_induct \\<tau> avoiding: x v rule:\\<tau>.strong_induct)\n  case (T_refined_type z b c )\n  hence ceq: \"(c[bv::=b']\\<^sub>c\\<^sub>b)[x::=v[bv::=b']\\<^sub>v\\<^sub>b]\\<^sub>c\\<^sub>v = c[x::=v]\\<^sub>c\\<^sub>v[bv::=b']\\<^sub>c\\<^sub>b\" using subst_cv_subst_vb_switch by auto\n\n  moreover have \"atom z \\<sharp> v[bv::=b']\\<^sub>v\\<^sub>b\" using x_fresh_b fresh_subst_if subst_b_v_def T_refined_type by metis\n\n  hence \"\\<lbrace> z : b  | c \\<rbrace>[bv::=b']\\<^sub>\\<tau>\\<^sub>b[x::=v[bv::=b']\\<^sub>v\\<^sub>b]\\<^sub>\\<tau>\\<^sub>v = \\<lbrace> z : b[bv::=b']\\<^sub>b\\<^sub>b  | (c[bv::=b']\\<^sub>c\\<^sub>b)[x::=v[bv::=b']\\<^sub>v\\<^sub>b]\\<^sub>c\\<^sub>v \\<rbrace>\"\n    using subst_tv.simps subst_tb.simps T_refined_type fresh_Pair by metis\n\n  moreover have \"\\<lbrace> z : b[bv::=b']\\<^sub>b\\<^sub>b  | (c[bv::=b']\\<^sub>c\\<^sub>b)[x::=v[bv::=b']\\<^sub>v\\<^sub>b]\\<^sub>c\\<^sub>v \\<rbrace>  =  \\<lbrace> z : b  | c[x::=v]\\<^sub>c\\<^sub>v \\<rbrace>[bv::=b']\\<^sub>\\<tau>\\<^sub>b\"\n    using subst_tv.simps subst_tb.simps ceq \\<tau>.fresh forget_subst[of \"bv\" b b'] subst_b_b_def T_refined_type by metis\n\n  ultimately show ?case using subst_tv.simps subst_tb.simps ceq T_refined_type by auto\nqed\n\nlemma subst_tb_triple:\n  assumes \"atom bv \\<sharp> \\<tau>'\" \n  shows  \"\\<tau>'[bv'::=b'[bv::=b]\\<^sub>b\\<^sub>b]\\<^sub>\\<tau>\\<^sub>b[x'::=v'[bv::=b]\\<^sub>v\\<^sub>b]\\<^sub>\\<tau>\\<^sub>v = \\<tau>'[bv'::=b']\\<^sub>\\<tau>\\<^sub>b[x'::=v']\\<^sub>\\<tau>\\<^sub>v[bv::=b]\\<^sub>\\<tau>\\<^sub>b\"  \nproof -\n  have \"\\<tau>'[bv'::=b'[bv::=b]\\<^sub>b\\<^sub>b]\\<^sub>\\<tau>\\<^sub>b[x'::=v'[bv::=b]\\<^sub>v\\<^sub>b]\\<^sub>\\<tau>\\<^sub>v = \\<tau>'[bv'::=b']\\<^sub>\\<tau>\\<^sub>b[bv::=b]\\<^sub>\\<tau>\\<^sub>b [x'::=v'[bv::=b]\\<^sub>v\\<^sub>b]\\<^sub>\\<tau>\\<^sub>v\"\n    using subst_tb_commute \\<open>atom bv \\<sharp> \\<tau>'\\<close> by auto\n  also have \"... = \\<tau>'[bv'::=b']\\<^sub>\\<tau>\\<^sub>b [x'::=v']\\<^sub>\\<tau>\\<^sub>v[bv::=b]\\<^sub>\\<tau>\\<^sub>b\" \n    using subst_tv_subst_vb_switch by auto\n  finally show ?thesis using fresh_subst_if forget_subst by auto\nqed\n\nlemma subst_b_infer_e:\n  fixes s::s and b::b\n  assumes \"\\<Theta> ; \\<Phi> ; B ; G; D \\<turnstile> e \\<Rightarrow> \\<tau>\" and \"\\<Theta> ; {||} \\<turnstile>\\<^sub>w\\<^sub>f b\"  and \"B = {|bv|}\" \n  shows  \"\\<Theta> ; \\<Phi> ; {||} ; G[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b; D[bv::=b]\\<^sub>\\<Delta>\\<^sub>b \\<turnstile> (e[bv::=b]\\<^sub>e\\<^sub>b) \\<Rightarrow> (\\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b)\" \n  using assms proof(nominal_induct avoiding: b rule: infer_e.strong_induct)\n  case (infer_e_valI \\<Theta> \\<B> \\<Gamma> \\<Delta> \\<Phi> v \\<tau>)\n  thus ?case using  subst_eb.simps infer_e.intros wf_b_subst subst_db.simps wf_b_subst infer_v_wf subst_b_infer_v \n    by (metis forget_subst ms_fresh_all(1) wfV_b_fresh)\nnext\n  case (infer_e_plusI \\<Theta> \\<B> \\<Gamma> \\<Delta> \\<Phi> v1 z1 c1 v2 z2 c2 z3)\n\n  show ?case unfolding subst_b_simps subst_eb.simps proof(rule Typing.infer_e_plusI)\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile>\\<^sub>w\\<^sub>f \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b \" using wf_b_subst(10) subst_db.simps infer_e_plusI wfX_wfY \n      by (metis wf_b_subst(15))\n    show \"\\<Theta>  \\<turnstile>\\<^sub>w\\<^sub>f \\<Phi> \" using infer_e_plusI by auto\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> v1[bv::=b]\\<^sub>v\\<^sub>b \\<Rightarrow> \\<lbrace> z1 : B_int  | c1[bv::=b]\\<^sub>c\\<^sub>b \\<rbrace>\" using subst_b_infer_v  infer_e_plusI subst_b_simps by force\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> v2[bv::=b]\\<^sub>v\\<^sub>b \\<Rightarrow> \\<lbrace> z2 : B_int  | c2[bv::=b]\\<^sub>c\\<^sub>b \\<rbrace>\" using subst_b_infer_v  infer_e_plusI subst_b_simps by force\n    show \"atom z3 \\<sharp> AE_op Plus (v1[bv::=b]\\<^sub>v\\<^sub>b) (v2[bv::=b]\\<^sub>v\\<^sub>b)\" using  subst_b_simps infer_e_plusI subst_b_fresh_x subst_b_e_def by metis\n    show \"atom z3 \\<sharp> \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b\" using subst_g_b_x_fresh infer_e_plusI by auto\n  qed\nnext\n  case (infer_e_leqI \\<Theta> \\<B> \\<Gamma> \\<Delta> \\<Phi> v1 z1 c1 v2 z2 c2 z3)\n  show ?case unfolding subst_b_simps proof(rule Typing.infer_e_leqI)\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile>\\<^sub>w\\<^sub>f \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b  \" using wf_b_subst(10) subst_db.simps infer_e_leqI wfX_wfY \n      by (metis wf_b_subst(15))\n    show \"\\<Theta>  \\<turnstile>\\<^sub>w\\<^sub>f \\<Phi> \" using infer_e_leqI by auto\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> v1[bv::=b]\\<^sub>v\\<^sub>b \\<Rightarrow> \\<lbrace> z1 : B_int  | c1[bv::=b]\\<^sub>c\\<^sub>b \\<rbrace>\" using subst_b_infer_v  infer_e_leqI subst_b_simps by force\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> v2[bv::=b]\\<^sub>v\\<^sub>b \\<Rightarrow> \\<lbrace> z2 : B_int  | c2[bv::=b]\\<^sub>c\\<^sub>b \\<rbrace>\" using subst_b_infer_v  infer_e_leqI subst_b_simps by force\n    show \"atom z3 \\<sharp> AE_op LEq (v1[bv::=b]\\<^sub>v\\<^sub>b) (v2[bv::=b]\\<^sub>v\\<^sub>b)\" using  subst_b_simps infer_e_leqI subst_b_fresh_x subst_b_e_def by metis\n    show \"atom z3 \\<sharp> \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b\" using subst_g_b_x_fresh infer_e_leqI by auto\n  qed\nnext\n  case (infer_e_eqI \\<Theta> \\<B> \\<Gamma> \\<Delta> \\<Phi> v1 z1 bb c1 v2 z2 c2 z3)\n  show ?case unfolding subst_b_simps proof(rule Typing.infer_e_eqI)\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile>\\<^sub>w\\<^sub>f \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b  \" using wf_b_subst(10) subst_db.simps infer_e_eqI wfX_wfY \n      by (metis wf_b_subst(15))\n    show \"\\<Theta>  \\<turnstile>\\<^sub>w\\<^sub>f \\<Phi> \" using infer_e_eqI by auto\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> v1[bv::=b]\\<^sub>v\\<^sub>b \\<Rightarrow> \\<lbrace> z1 : bb[bv::=b]\\<^sub>b\\<^sub>b  | c1[bv::=b]\\<^sub>c\\<^sub>b \\<rbrace>\" using subst_b_infer_v  infer_e_eqI subst_b_simps by force\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> v2[bv::=b]\\<^sub>v\\<^sub>b \\<Rightarrow> \\<lbrace> z2 : bb[bv::=b]\\<^sub>b\\<^sub>b  | c2[bv::=b]\\<^sub>c\\<^sub>b \\<rbrace>\" using subst_b_infer_v  infer_e_eqI subst_b_simps by force\n    show \"atom z3 \\<sharp> AE_op Eq (v1[bv::=b]\\<^sub>v\\<^sub>b) (v2[bv::=b]\\<^sub>v\\<^sub>b)\" using  subst_b_simps infer_e_eqI subst_b_fresh_x subst_b_e_def by metis\n    show \"atom z3 \\<sharp> \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b\" using subst_g_b_x_fresh infer_e_eqI by auto\n    show \"bb[bv::=b]\\<^sub>b\\<^sub>b  \\<in> {B_bool, B_int, B_unit}\" using infer_e_eqI by auto\n  qed\nnext\n  case (infer_e_appI \\<Theta> \\<B> \\<Gamma> \\<Delta> \\<Phi> f x b' c \\<tau>' s' v \\<tau>)\n  show ?case proof(subst subst_eb.simps, rule Typing.infer_e_appI)\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile>\\<^sub>w\\<^sub>f \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b\"  using wf_b_subst(10) subst_db.simps infer_e_appI wfX_wfY by (metis wf_b_subst(15))\n    show \"\\<Theta>  \\<turnstile>\\<^sub>w\\<^sub>f \\<Phi> \" using infer_e_appI by auto\n    show \"Some (AF_fundef f (AF_fun_typ_none (AF_fun_typ x b' c \\<tau>' s'))) = lookup_fun \\<Phi> f\" using infer_e_appI by auto\n        (*show  \"\\<Theta> ; {||} ; (x, b', c) #\\<^sub>\\<Gamma> GNil   \\<turnstile>\\<^sub>w\\<^sub>f \\<tau>'\" using infer_e_appI sory*)\n    have \"atom bv \\<sharp> b'\"  using \\<open>\\<Theta>  \\<turnstile>\\<^sub>w\\<^sub>f \\<Phi> \\<close> infer_e_appI wfPhi_f_supp  fresh_def[of \"atom bv\" b'] by simp\n    hence \"b' = b'[bv::=b]\\<^sub>b\\<^sub>b\" using subst_b_simps \n      using has_subst_b_class.forget_subst subst_b_b_def by force\n    moreover have  ceq:\"c = c[bv::=b]\\<^sub>c\\<^sub>b\" using subst_b_simps proof -\n      have \"supp c \\<subseteq> {atom x}\" using infer_e_appI wfPhi_f_simple_supp_c[OF  _  \\<open>\\<Theta>  \\<turnstile>\\<^sub>w\\<^sub>f \\<Phi> \\<close>]  by simp\n      hence \"atom bv \\<sharp> c\" using\n          fresh_def[of \"atom bv\" c] \n        using fresh_def fresh_finsert insert_absorb \n          insert_subset ms_fresh_all supp_at_base x_not_in_b_set fresh_prodN by metis\n      thus ?thesis \n        using forget_subst subst_b_c_def  fresh_def[of \"atom bv\" c] by metis    \n    qed \n    show   \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b  \\<turnstile> v[bv::=b]\\<^sub>v\\<^sub>b \\<Leftarrow> \\<lbrace> x : b'  | c \\<rbrace>\"  \n      using subst_b_check_v subst_tb.simps subst_vb.simps infer_e_appI \n    proof -\n      have \"\\<Theta> ; {|bv|} ; \\<Gamma> \\<turnstile> v \\<Leftarrow> \\<lbrace> x : b' | c \\<rbrace>\"\n        by (metis \\<open>\\<B> = {|bv|}\\<close> \\<open>\\<Theta> ; \\<B> ; \\<Gamma> \\<turnstile> v \\<Leftarrow> \\<lbrace> x : b' | c \\<rbrace>\\<close>) (* 0.0 ms *)\n      then show ?thesis \n        by (metis (no_types) \\<open>\\<Theta> ; {||} \\<turnstile>\\<^sub>w\\<^sub>f b\\<close> \\<open>b' = b'[bv::=b]\\<^sub>b\\<^sub>b\\<close> subst_b_check_v subst_tb.simps ceq) \n    qed\n    show \"atom x \\<sharp> (\\<Theta>, \\<Phi>, {||}::bv fset, \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b, \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b, v[bv::=b]\\<^sub>v\\<^sub>b, \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b)\"\n      apply (fresh_mth add:  fresh_prodN subst_g_b_x_fresh infer_e_appI )\n      using subst_b_fresh_x infer_e_appI apply metis+\n      done            \n    have \"supp \\<tau>' \\<subseteq> { atom x }\" using wfPhi_f_simple_supp_t  infer_e_appI by auto\n    hence \"atom bv \\<sharp> \\<tau>'\" using fresh_def fresh_at_base by force\n    then  show  \"\\<tau>'[x::=v[bv::=b]\\<^sub>v\\<^sub>b]\\<^sub>v = \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b\" using infer_e_appI \n        forget_subst subst_b_\\<tau>_def subst_tv_subst_vb_switch subst_defs by metis\n  qed\nnext\n  case (infer_e_appPI \\<Theta>' \\<B> \\<Gamma>' \\<Delta> \\<Phi>' b' f' bv' x' b1 c \\<tau>' s' v' \\<tau>1)\n\n  have beq: \"b1[bv'::=b']\\<^sub>b\\<^sub>b[bv::=b]\\<^sub>b\\<^sub>b =  b1[bv'::=b'[bv::=b]\\<^sub>b\\<^sub>b]\\<^sub>b\\<^sub>b\" \n  proof -\n    have \"supp b1 \\<subseteq> { atom bv' }\" using wfPhi_f_poly_supp_b infer_e_appPI \n      using supp_at_base by blast\n    moreover have \"bv \\<noteq> bv'\" using infer_e_appPI fresh_def supp_at_base \n      by (simp add: fresh_def supp_at_base)\n    ultimately have \"atom bv \\<sharp> b1\" using fresh_def fresh_at_base by force\n    thus ?thesis by simp\n  qed\n\n  have ceq: \"(c[bv'::=b']\\<^sub>c\\<^sub>b)[bv::=b]\\<^sub>c\\<^sub>b = c[bv'::=b'[bv::=b]\\<^sub>b\\<^sub>b]\\<^sub>c\\<^sub>b\" proof -\n    have \"supp c \\<subseteq> { atom bv', atom x' }\" using wfPhi_f_poly_supp_c infer_e_appPI \n      using supp_at_base by blast\n    moreover have \"bv \\<noteq> bv'\" using infer_e_appPI fresh_def supp_at_base \n      by (simp add: fresh_def supp_at_base)\n    moreover have \"atom x' \\<noteq> atom bv\" by auto\n    ultimately have \"atom bv \\<sharp> c\" using fresh_def[of \"atom bv\" c] fresh_at_base by auto\n    thus ?thesis by simp\n  qed\n\n  show ?case proof(subst subst_eb.simps, rule Typing.infer_e_appPI)\n    show \"\\<Theta>' ; {||} ; \\<Gamma>'[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile>\\<^sub>w\\<^sub>f \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b \" using wf_b_subst subst_db.simps infer_e_appPI wfX_wfY by metis\n    show \"\\<Theta>'  \\<turnstile>\\<^sub>w\\<^sub>f \\<Phi>' \" using infer_e_appPI by auto\n    show \"Some (AF_fundef f' (AF_fun_typ_some bv' (AF_fun_typ x' b1 c \\<tau>' s'))) = lookup_fun \\<Phi>' f'\" using infer_e_appPI by auto\n    thus  \"\\<Theta>' ; {||} ; \\<Gamma>'[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b  \\<turnstile> v'[bv::=b]\\<^sub>v\\<^sub>b \\<Leftarrow> \\<lbrace> x' : b1[bv'::=b'[bv::=b]\\<^sub>b\\<^sub>b]\\<^sub>b  | c[bv'::=b'[bv::=b]\\<^sub>b\\<^sub>b]\\<^sub>b \\<rbrace>\"  \n      using subst_b_check_v subst_tb.simps subst_b_simps infer_e_appPI \n    proof -\n      have \"\\<Theta>' ; {||} ; \\<Gamma>'[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b  \\<turnstile> v'[bv::=b]\\<^sub>v\\<^sub>b \\<Leftarrow> \\<lbrace> x' : b1[bv'::=b']\\<^sub>b[bv::=b]\\<^sub>b\\<^sub>b  | (c[bv'::=b']\\<^sub>b)[bv::=b]\\<^sub>c\\<^sub>b \\<rbrace>\" \n        using  infer_e_appPI subst_b_check_v subst_tb.simps by metis\n      thus  ?thesis using beq ceq  subst_defs by metis\n    qed\n    show \"atom x' \\<sharp> \\<Gamma>'[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b\" using subst_g_b_x_fresh infer_e_appPI by auto\n    show  \"\\<tau>'[bv'::=b'[bv::=b]\\<^sub>b\\<^sub>b]\\<^sub>b[x'::=v'[bv::=b]\\<^sub>v\\<^sub>b]\\<^sub>v = \\<tau>1[bv::=b]\\<^sub>\\<tau>\\<^sub>b\" proof - (* \\<tau>'[bv'::=b']\\<^sub>\\<tau>\\<^sub>b[x'::=v']\\<^sub>\\<tau>\\<^sub>v = \\<tau>1 *)\n\n      have \"supp \\<tau>' \\<subseteq> { atom x', atom bv' }\" using wfPhi_f_poly_supp_t  infer_e_appPI by auto\n      moreover hence \"bv \\<noteq> bv'\" using infer_e_appPI fresh_def supp_at_base \n        by (simp add: fresh_def supp_at_base)\n      ultimately have \"atom bv \\<sharp> \\<tau>'\" using fresh_def by force\n      hence \"\\<tau>'[bv'::=b'[bv::=b]\\<^sub>b\\<^sub>b]\\<^sub>b[x'::=v'[bv::=b]\\<^sub>v\\<^sub>b]\\<^sub>v = \\<tau>'[bv'::=b']\\<^sub>b[x'::=v']\\<^sub>v[bv::=b]\\<^sub>\\<tau>\\<^sub>b\"  using subst_tb_triple subst_defs by auto \n      thus ?thesis using infer_e_appPI by metis\n    qed\n    show \"atom bv' \\<sharp> (\\<Theta>', \\<Phi>', {||}, \\<Gamma>'[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b, \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b, b'[bv::=b]\\<^sub>b\\<^sub>b, v'[bv::=b]\\<^sub>v\\<^sub>b, \\<tau>1[bv::=b]\\<^sub>\\<tau>\\<^sub>b)\" \n      unfolding fresh_prodN apply( auto simp add: infer_e_appPI fresh_empty_fset)\n      using fresh_subst_if subst_b_\\<Gamma>_def  subst_b_\\<Delta>_def  subst_b_b_def subst_b_v_def subst_b_\\<tau>_def infer_e_appPI by metis+\n    show \"\\<Theta>' ; {||}  \\<turnstile>\\<^sub>w\\<^sub>f b'[bv::=b]\\<^sub>b\\<^sub>b \" using infer_e_appPI wf_b_subst by simp\n  qed\nnext\n  case (infer_e_fstI \\<Theta> \\<B> \\<Gamma> \\<Delta> \\<Phi> v z' b1 b2 c z)\n  show ?case unfolding subst_b_simps proof(rule Typing.infer_e_fstI)\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile>\\<^sub>w\\<^sub>f \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b \" using wf_b_subst(10) subst_db.simps infer_e_fstI wfX_wfY \n      by (metis wf_b_subst(15))\n    show \"\\<Theta>  \\<turnstile>\\<^sub>w\\<^sub>f \\<Phi> \" using infer_e_fstI by auto\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> v[bv::=b]\\<^sub>v\\<^sub>b \\<Rightarrow> \\<lbrace> z' : B_pair b1[bv::=b]\\<^sub>b\\<^sub>b b2[bv::=b]\\<^sub>b\\<^sub>b  | c[bv::=b]\\<^sub>c\\<^sub>b \\<rbrace>\" \n      using subst_b_infer_v subst_tb.simps subst_b_simps infer_e_fstI by force\n    show \"atom z \\<sharp> AE_fst (v[bv::=b]\\<^sub>v\\<^sub>b)\" using infer_e_fstI subst_b_fresh_x subst_b_v_def e.fresh by metis\n    show \"atom z \\<sharp> \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b\" using subst_g_b_x_fresh infer_e_fstI by auto\n  qed\nnext\n  case (infer_e_sndI \\<Theta> \\<B> \\<Gamma> \\<Delta> \\<Phi> v z' b1 b2 c z)\n  show ?case unfolding subst_b_simps proof(rule Typing.infer_e_sndI)\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile>\\<^sub>w\\<^sub>f \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b  \" using wf_b_subst(10) subst_db.simps infer_e_sndI wfX_wfY \n      by (metis wf_b_subst(15))\n    show \"\\<Theta>  \\<turnstile>\\<^sub>w\\<^sub>f \\<Phi> \" using infer_e_sndI by auto\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> v[bv::=b]\\<^sub>v\\<^sub>b \\<Rightarrow> \\<lbrace> z' : B_pair b1[bv::=b]\\<^sub>b\\<^sub>b b2[bv::=b]\\<^sub>b\\<^sub>b  | c[bv::=b]\\<^sub>c\\<^sub>b \\<rbrace>\" \n      using subst_b_infer_v subst_tb.simps subst_b_simps infer_e_sndI by force\n    show \"atom z \\<sharp> AE_snd (v[bv::=b]\\<^sub>v\\<^sub>b)\" using infer_e_sndI subst_b_fresh_x subst_b_v_def e.fresh by metis\n    show \"atom z \\<sharp> \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b\" using subst_g_b_x_fresh infer_e_sndI by auto\n  qed\nnext\n  case (infer_e_lenI \\<Theta> \\<B> \\<Gamma> \\<Delta> \\<Phi> v z' c z)\n  show ?case unfolding subst_b_simps proof(rule Typing.infer_e_lenI)\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile>\\<^sub>w\\<^sub>f \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b  \" using wf_b_subst(10) subst_db.simps infer_e_lenI wfX_wfY \n      by (metis wf_b_subst(15))\n    show \"\\<Theta>  \\<turnstile>\\<^sub>w\\<^sub>f \\<Phi> \" using infer_e_lenI by auto\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> v[bv::=b]\\<^sub>v\\<^sub>b \\<Rightarrow> \\<lbrace> z' : B_bitvec  | c[bv::=b]\\<^sub>c\\<^sub>b \\<rbrace>\" \n      using subst_b_infer_v subst_tb.simps subst_b_simps infer_e_lenI by force\n    show \"atom z \\<sharp> AE_len (v[bv::=b]\\<^sub>v\\<^sub>b)\" using infer_e_lenI subst_b_fresh_x subst_b_v_def e.fresh by metis\n    show \"atom z \\<sharp> \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b\" using subst_g_b_x_fresh infer_e_lenI by auto\n  qed\nnext\n  case (infer_e_mvarI \\<Theta> \\<B> \\<Gamma> \\<Phi> \\<Delta> u \\<tau>)\n  show ?case proof(subst  subst subst_eb.simps, rule Typing.infer_e_mvarI)\n    show \"\\<Theta> ; {||}  \\<turnstile>\\<^sub>w\\<^sub>f \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \" using infer_e_mvarI wf_b_subst by auto\n    show \"\\<Theta>  \\<turnstile>\\<^sub>w\\<^sub>f \\<Phi> \"  using infer_e_mvarI by auto\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile>\\<^sub>w\\<^sub>f \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b \"   using infer_e_mvarI  using wf_b_subst(10) subst_db.simps infer_e_sndI wfX_wfY \n      by (metis wf_b_subst(15))\n    show \"(u, \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b) \\<in> setD \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b\"  using infer_e_mvarI subst_db.simps set_insert \n        subst_d_b_member by simp\n  qed\nnext\n  case (infer_e_concatI \\<Theta> \\<B> \\<Gamma> \\<Delta> \\<Phi> v1 z1 c1 v2 z2 c2 z3)\n  show ?case unfolding subst_b_simps proof(rule Typing.infer_e_concatI)\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile>\\<^sub>w\\<^sub>f \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b \" using wf_b_subst(10) subst_db.simps infer_e_concatI wfX_wfY \n      by (metis wf_b_subst(15))\n    show \"\\<Theta>  \\<turnstile>\\<^sub>w\\<^sub>f \\<Phi> \" using infer_e_concatI by auto\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> v1[bv::=b]\\<^sub>v\\<^sub>b \\<Rightarrow> \\<lbrace> z1 : B_bitvec  | c1[bv::=b]\\<^sub>c\\<^sub>b \\<rbrace>\" \n      using subst_b_infer_v subst_tb.simps subst_b_simps infer_e_concatI by force\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> v2[bv::=b]\\<^sub>v\\<^sub>b \\<Rightarrow> \\<lbrace> z2 : B_bitvec  | c2[bv::=b]\\<^sub>c\\<^sub>b \\<rbrace>\" \n      using subst_b_infer_v subst_tb.simps subst_b_simps infer_e_concatI by force\n    show \"atom z3 \\<sharp> AE_concat (v1[bv::=b]\\<^sub>v\\<^sub>b) (v2[bv::=b]\\<^sub>v\\<^sub>b)\" using infer_e_concatI subst_b_fresh_x subst_b_v_def e.fresh by metis\n    show \"atom z3 \\<sharp> \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b\" using subst_g_b_x_fresh infer_e_concatI by auto\n  qed\nnext\n  case (infer_e_splitI \\<Theta> \\<B> \\<Gamma> \\<Delta> \\<Phi> v1 z1 c1 v2 z2 z3)\n  show ?case unfolding subst_b_simps proof(rule Typing.infer_e_splitI)\n    show \\<open> \\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile>\\<^sub>w\\<^sub>f \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b \\<close> using wf_b_subst(10) subst_db.simps infer_e_splitI wfX_wfY \n      by (metis wf_b_subst(15))\n    show \\<open> \\<Theta>  \\<turnstile>\\<^sub>w\\<^sub>f \\<Phi> \\<close>  using infer_e_splitI by auto\n    show \\<open> \\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> v1[bv::=b]\\<^sub>v\\<^sub>b \\<Rightarrow> \\<lbrace> z1 : B_bitvec  | c1[bv::=b]\\<^sub>c\\<^sub>b \\<rbrace>\\<close>  \n      using subst_b_infer_v subst_tb.simps subst_b_simps infer_e_splitI by force\n    show \\<open>\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b  \\<turnstile> v2[bv::=b]\\<^sub>v\\<^sub>b \\<Leftarrow> \\<lbrace> z2 : B_int  | [ leq [ [ L_num 0 ]\\<^sup>v ]\\<^sup>c\\<^sup>e [ [ z2 ]\\<^sup>v ]\\<^sup>c\\<^sup>e ]\\<^sup>c\\<^sup>e  ==  [ [ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e   AND\n                  [ leq [ [ z2 ]\\<^sup>v ]\\<^sup>c\\<^sup>e [| [ v1[bv::=b]\\<^sub>v\\<^sub>b ]\\<^sup>c\\<^sup>e |]\\<^sup>c\\<^sup>e ]\\<^sup>c\\<^sup>e  ==  [ [ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e   \\<rbrace>\\<close>  \n      using subst_b_check_v subst_tb.simps subst_b_simps infer_e_splitI \n    proof -\n      have \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile> v2[bv::=b]\\<^sub>v\\<^sub>b \\<Leftarrow> \\<lbrace> z2 : B_int | [ leq [ [ L_num 0 ]\\<^sup>v ]\\<^sup>c\\<^sup>e [ [ z2 ]\\<^sup>v ]\\<^sup>c\\<^sup>e ]\\<^sup>c\\<^sup>e == [ [ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e AND [ leq [ [ z2 ]\\<^sup>v ]\\<^sup>c\\<^sup>e [| [ v1 ]\\<^sup>c\\<^sup>e |]\\<^sup>c\\<^sup>e ]\\<^sup>c\\<^sup>e == [ [ L_true ]\\<^sup>v ]\\<^sup>c\\<^sup>e \\<rbrace>[bv::=b]\\<^sub>\\<tau>\\<^sub>b\"\n        using infer_e_splitI.hyps(7) infer_e_splitI.prems(1) infer_e_splitI.prems(2) subst_b_check_v by presburger (* 0.0 ms *)\n      then show ?thesis\n        by simp (* 0.0 ms *)\n    qed\n    show \\<open>atom z1 \\<sharp> AE_split (v1[bv::=b]\\<^sub>v\\<^sub>b) (v2[bv::=b]\\<^sub>v\\<^sub>b)\\<close> using infer_e_splitI subst_b_fresh_x subst_b_v_def e.fresh by metis\n    show \\<open>atom z1 \\<sharp> \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b\\<close> using subst_g_b_x_fresh infer_e_splitI by auto\n\n    show \\<open>atom z2 \\<sharp> AE_split (v1[bv::=b]\\<^sub>v\\<^sub>b) (v2[bv::=b]\\<^sub>v\\<^sub>b)\\<close>  using infer_e_splitI subst_b_fresh_x subst_b_v_def e.fresh by metis\n\n    show \\<open>atom z2 \\<sharp> \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b\\<close> using subst_g_b_x_fresh infer_e_splitI by auto\n    show \\<open>atom z3 \\<sharp> AE_split (v1[bv::=b]\\<^sub>v\\<^sub>b) (v2[bv::=b]\\<^sub>v\\<^sub>b)\\<close>  using infer_e_splitI subst_b_fresh_x subst_b_v_def e.fresh by metis\n    show \\<open>atom z3 \\<sharp> \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b\\<close> using subst_g_b_x_fresh infer_e_splitI by auto\n  qed\nqed\n\ntext \\<open>This is needed for preservation. When we apply a function \"f [b] v\" we need to \nsubstitute into the body of the function f replacing type-variable with b\\<close>\n\nlemma subst_b_c_of_forget:\n  assumes \"atom bv \\<sharp> const\"\n  shows \"(c_of const x)[bv::=b]\\<^sub>c\\<^sub>b = c_of const x\" \n  using assms proof(nominal_induct const avoiding: x rule:\\<tau>.strong_induct)\n  case (T_refined_type x' b' c')\n  hence \"c_of \\<lbrace> x' : b' | c' \\<rbrace> x = c'[x'::=V_var x]\\<^sub>c\\<^sub>v\" using c_of.simps by metis\n  moreover have \"atom bv \\<sharp> c'[x'::=V_var x]\\<^sub>c\\<^sub>v\" proof -\n    have \"atom bv \\<sharp> c'\" using T_refined_type \\<tau>.fresh by simp\n    moreover have \"atom bv \\<sharp> V_var x\" using v.fresh by simp\n    ultimately show ?thesis   \n      using T_refined_type \\<tau>.fresh subst_b_c_def fresh_subst_if\n        \\<tau>_fresh_c fresh_subst_cv_if has_subst_b_class.subst_b_fresh_x ms_fresh_all(37) ms_fresh_all assms by metis\n  qed\n  ultimately show ?case using forget_subst subst_b_c_def by metis\nqed\n\nlemma subst_b_check_s:\n  fixes s::s and b::b and cs::branch_s and css::branch_list and v::v and \\<tau>::\\<tau>\n  assumes \"\\<Theta> ; {||} \\<turnstile>\\<^sub>w\\<^sub>f b\"  and \"B = {|bv|}\" (*and \"D = []\"*)\n  shows  \"\\<Theta> ; \\<Phi> ; B ; G; D \\<turnstile> s \\<Leftarrow> \\<tau> \\<Longrightarrow> \\<Theta> ; \\<Phi> ; {||} ; G[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b; D[bv::=b]\\<^sub>\\<Delta>\\<^sub>b \\<turnstile> (s[bv::=b]\\<^sub>s\\<^sub>b) \\<Leftarrow> (\\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b)\" and\n    \"\\<Theta> ; \\<Phi> ; B ; G; D ; tid ; cons ; const ; v \\<turnstile> cs \\<Leftarrow> \\<tau> \\<Longrightarrow> \\<Theta> ; \\<Phi> ; {||} ; G[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b; D[bv::=b]\\<^sub>\\<Delta>\\<^sub>b ; tid ; cons ; const ; v[bv::=b]\\<^sub>v\\<^sub>b \\<turnstile> (subst_branchb cs bv b) \\<Leftarrow> (\\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b)\" and\n    \"\\<Theta> ; \\<Phi> ; B ; G; D ; tid ; dclist ; v \\<turnstile> css \\<Leftarrow> \\<tau> \\<Longrightarrow> \\<Theta> ; \\<Phi> ; {||} ; G[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b; D[bv::=b]\\<^sub>\\<Delta>\\<^sub>b ; tid ; dclist ; v[bv::=b]\\<^sub>v\\<^sub>b \\<turnstile> (subst_branchlb css bv b ) \\<Leftarrow> (\\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b)\" \n  using assms proof(induct  rule: check_s_check_branch_s_check_branch_list.inducts)\n  note facts = wfD_emptyI wfX_wfY wf_b_subst subst_b_subtype subst_b_infer_v\n  case (check_valI \\<Theta> \\<B> \\<Gamma> \\<Delta> \\<Phi> v \\<tau>' \\<tau>)\n  show ?case \n    apply(subst subst_sb.simps, rule Typing.check_valI) \n    using facts check_valI apply metis\n    using check_valI subst_b_infer_v wf_b_subst subst_b_subtype apply blast\n    using check_valI subst_b_infer_v wf_b_subst subst_b_subtype apply blast  \n    using check_valI subst_b_infer_v wf_b_subst subst_b_subtype by metis\nnext\n  case (check_letI x \\<Theta> \\<Phi> \\<B> \\<Gamma> \\<Delta> e \\<tau> z s b' c)\n  show ?case proof(subst subst_sb.simps, rule Typing.check_letI) \n\n    show \"atom x \\<sharp>(\\<Theta>, \\<Phi>, {||}, \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b, \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b, e[bv::=b]\\<^sub>e\\<^sub>b, \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b)\" (*using check_letI  subst_b_\\<tau>_def subst_b_\\<Gamma>_def subst_b_fresh_x fresh_prod4 subst_b_c_def sory*)\n      apply(unfold fresh_prodN,auto)\n      apply(simp add: check_letI fresh_empty_fset)+\n      apply(metis *   subst_b_fresh_x check_letI fresh_prodN)+ done\n    show \"atom z \\<sharp> (x, \\<Theta>, \\<Phi>, {||}, \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b, \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b, e[bv::=b]\\<^sub>e\\<^sub>b, \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b, s[bv::=b]\\<^sub>s\\<^sub>b)\"  \n      apply(unfold fresh_prodN,auto)\n      apply(simp add: check_letI fresh_empty_fset)+\n      apply(metis *   subst_b_fresh_x check_letI fresh_prodN)+ done\n    show \"\\<Theta> ; \\<Phi> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b ; \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b  \\<turnstile> e[bv::=b]\\<^sub>e\\<^sub>b \\<Rightarrow> \\<lbrace> z : b'[bv::=b]\\<^sub>b\\<^sub>b  | c[bv::=b]\\<^sub>c\\<^sub>b  \\<rbrace>\" \n      using check_letI subst_b_infer_e subst_tb.simps by metis\n    have \"c[z::=[ x ]\\<^sup>v]\\<^sub>c\\<^sub>v[bv::=b]\\<^sub>c\\<^sub>b =  (c[bv::=b]\\<^sub>c\\<^sub>b)[z::=V_var x]\\<^sub>c\\<^sub>v\" \n      using subst_cv_subst_bb_commute[of bv \"V_var x\" c z b] fresh_at_base by simp\n    thus \"\\<Theta> ; \\<Phi> ; {||} ; ((x, b'[bv::=b]\\<^sub>b\\<^sub>b , (c[bv::=b]\\<^sub>c\\<^sub>b)[z::=V_var x]\\<^sub>v) #\\<^sub>\\<Gamma> \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b) ; \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b  \\<turnstile> s[bv::=b]\\<^sub>s\\<^sub>b \\<Leftarrow> \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b\" \n      using check_letI subst_gb.simps subst_defs by metis\n  qed\nnext\n  case (check_assertI x \\<Theta> \\<Phi> \\<B> \\<Gamma> \\<Delta> c \\<tau> s)\n  show ?case proof(subst subst_sb.simps, rule Typing.check_assertI)\n    show \"atom x \\<sharp> (\\<Theta>, \\<Phi>, {||}, \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b, \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b,  c[bv::=b]\\<^sub>c\\<^sub>b, \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b, s[bv::=b]\\<^sub>s\\<^sub>b)\"   \n      apply(unfold fresh_prodN,auto)\n      apply(simp add: check_assertI fresh_empty_fset)+\n      apply(metis *   subst_b_fresh_x check_assertI fresh_prodN)+ done\n\n    have \"\\<Theta> ; \\<Phi> ; {||} ; ((x, B_bool, c) #\\<^sub>\\<Gamma> \\<Gamma>)[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b ; \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b  \\<turnstile> s[bv::=b]\\<^sub>s\\<^sub>b \\<Leftarrow> \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b\" using  check_assertI\n      by metis\n    thus \"\\<Theta> ; \\<Phi> ; {||} ; (x, B_bool, c[bv::=b]\\<^sub>c\\<^sub>b) #\\<^sub>\\<Gamma> \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b ; \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b  \\<turnstile> s[bv::=b]\\<^sub>s\\<^sub>b \\<Leftarrow> \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b\" using  subst_gb.simps by auto\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b  \\<Turnstile> c[bv::=b]\\<^sub>c\\<^sub>b \" using subst_b_valid  check_assertI by simp\n    show \" \\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile>\\<^sub>w\\<^sub>f \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b \" using wf_b_subst2(6) check_assertI by simp\n  qed\nnext\n  case (check_branch_list_consI \\<Theta> \\<Phi> \\<B> \\<Gamma> \\<Delta> tid dclist v cs \\<tau> css)\n  then show ?case unfolding subst_branchlb.simps using Typing.check_branch_list_consI by simp\nnext\n  case (check_branch_list_finalI \\<Theta> \\<Phi> \\<B> \\<Gamma> \\<Delta> tid dclist v cs \\<tau>)\n  then show ?case unfolding subst_branchlb.simps using Typing.check_branch_list_finalI by simp\nnext\n  case (check_branch_s_branchI \\<Theta> \\<B> \\<Gamma> \\<Delta> \\<tau> const x \\<Phi> tid cons v s)\n\n  show ?case unfolding subst_b_simps proof(rule Typing.check_branch_s_branchI) \n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile>\\<^sub>w\\<^sub>f \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b  \"  using check_branch_s_branchI wf_b_subst subst_db.simps by metis\n    show \"\\<turnstile>\\<^sub>w\\<^sub>f \\<Theta> \" using check_branch_s_branchI by auto\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b   \\<turnstile>\\<^sub>w\\<^sub>f \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b \"   using check_branch_s_branchI wf_b_subst by metis\n\n    show \"atom x \\<sharp>(\\<Theta>, \\<Phi>, {||}, \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b, \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b, tid, cons , const, v[bv::=b]\\<^sub>v\\<^sub>b, \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b)\"       \n      apply(unfold fresh_prodN,auto)\n      apply(simp add: check_branch_s_branchI fresh_empty_fset)+\n      apply(metis *   subst_b_fresh_x check_branch_s_branchI fresh_prodN)+\n      done\n    show wft:\"\\<Theta> ; {||} ; GNil \\<turnstile>\\<^sub>w\\<^sub>f  const\" using check_branch_s_branchI  by auto\n    hence \"(b_of const) = (b_of const)[bv::=b]\\<^sub>b\\<^sub>b\" \n      using wfT_nil_supp   fresh_def[of \"atom bv\" ] forget_subst subst_b_b_def \\<tau>.supp\n        bot.extremum_uniqueI ex_in_conv fresh_def supp_empty_fset \n      by (metis b_of_supp)\n    moreover have \"(c_of const x)[bv::=b]\\<^sub>c\\<^sub>b = c_of const x\" \n      using wft   wfT_nil_supp   fresh_def[of \"atom bv\" ] forget_subst subst_b_c_def \\<tau>.supp\n        bot.extremum_uniqueI ex_in_conv fresh_def supp_empty_fset  subst_b_c_of_forget by metis\n    ultimately show  \"\\<Theta> ; \\<Phi> ; {||} ; (x, b_of const, CE_val (v[bv::=b]\\<^sub>v\\<^sub>b)  ==  CE_val(V_cons tid cons (V_var x)) AND c_of const x) #\\<^sub>\\<Gamma> \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b ; \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b   \\<turnstile> s[bv::=b]\\<^sub>s\\<^sub>b \\<Leftarrow> \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b\"  \n      using check_branch_s_branchI subst_gb.simps by auto\n  qed\nnext\n  case (check_ifI z \\<Theta> \\<Phi> \\<B> \\<Gamma> \\<Delta> v s1 s2 \\<tau>)\n  show ?case unfolding subst_b_simps proof(rule  Typing.check_ifI) \n    show \\<open>atom z \\<sharp> (\\<Theta>, \\<Phi>, {||}, \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b, \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b, v[bv::=b]\\<^sub>v\\<^sub>b, s1[bv::=b]\\<^sub>s\\<^sub>b, s2[bv::=b]\\<^sub>s\\<^sub>b, \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b)\\<close> \n      by(unfold fresh_prodN,auto, auto simp add: check_ifI fresh_empty_fset subst_b_fresh_x )\n    have \"\\<lbrace> z : B_bool  | TRUE \\<rbrace>[bv::=b]\\<^sub>\\<tau>\\<^sub>b  = \\<lbrace> z : B_bool  | TRUE \\<rbrace>\"  by auto\n    thus \\<open>\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b  \\<turnstile> v[bv::=b]\\<^sub>v\\<^sub>b \\<Leftarrow> \\<lbrace> z : B_bool  | TRUE \\<rbrace>\\<close> using check_ifI subst_b_check_v by metis\n    show \\<open> \\<Theta> ; \\<Phi> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b ; \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b  \\<turnstile> s1[bv::=b]\\<^sub>s\\<^sub>b \\<Leftarrow> \\<lbrace> z : b_of \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b  | CE_val (v[bv::=b]\\<^sub>v\\<^sub>b)  ==  CE_val (V_lit L_true)   IMP  c_of \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b z  \\<rbrace>\\<close> \n      using subst_b_if check_ifI by metis\n    show \\<open> \\<Theta> ; \\<Phi> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b ; \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b  \\<turnstile> s2[bv::=b]\\<^sub>s\\<^sub>b \\<Leftarrow> \\<lbrace> z : b_of \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b  | CE_val (v[bv::=b]\\<^sub>v\\<^sub>b)  ==  CE_val (V_lit L_false)   IMP  c_of \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b z  \\<rbrace>\\<close> \n      using subst_b_if check_ifI by metis\n  qed\nnext\n  case (check_let2I x \\<Theta> \\<Phi> \\<B> G \\<Delta> t s1 \\<tau> s2 )\n  show ?case unfolding subst_b_simps proof (rule Typing.check_let2I)\n    have \"atom x \\<sharp> b\" using x_fresh_b by auto\n    show \\<open>atom x \\<sharp> (\\<Theta>, \\<Phi>, {||}, G[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b, \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b, t[bv::=b]\\<^sub>\\<tau>\\<^sub>b, s1[bv::=b]\\<^sub>s\\<^sub>b, \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b)\\<close>      \n      apply(unfold fresh_prodN, auto, auto simp add: check_let2I fresh_prodN fresh_empty_fset)\n      apply(metis  subst_b_fresh_x check_let2I fresh_prodN)+\n      done\n\n    show \\<open> \\<Theta> ; \\<Phi> ; {||} ; G[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b ; \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b  \\<turnstile> s1[bv::=b]\\<^sub>s\\<^sub>b \\<Leftarrow> t[bv::=b]\\<^sub>\\<tau>\\<^sub>b \\<close> using check_let2I subst_tb.simps  by auto\n    show \\<open> \\<Theta> ; \\<Phi> ; {||} ; (x, b_of t[bv::=b]\\<^sub>\\<tau>\\<^sub>b, c_of t[bv::=b]\\<^sub>\\<tau>\\<^sub>b x) #\\<^sub>\\<Gamma> G[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b ; \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b  \\<turnstile> s2[bv::=b]\\<^sub>s\\<^sub>b \\<Leftarrow> \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b\\<close> \n      using check_let2I subst_tb.simps  subst_gb.simps b_of.simps subst_b_c_of subst_b_b_of by auto\n  qed\nnext\n  case (check_varI u \\<Theta> \\<Phi> \\<B> \\<Gamma> \\<Delta> \\<tau>' v \\<tau> s)\n  show ?case unfolding subst_b_simps proof(rule Typing.check_varI) \n    show \"atom u \\<sharp>  (\\<Theta>, \\<Phi>, {||}, \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b, \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b, \\<tau>'[bv::=b]\\<^sub>\\<tau>\\<^sub>b, v[bv::=b]\\<^sub>v\\<^sub>b, \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b) \"\n      by(unfold fresh_prodN,auto simp add: check_varI fresh_empty_fset subst_b_fresh_u )\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b  \\<turnstile> v[bv::=b]\\<^sub>v\\<^sub>b \\<Leftarrow> \\<tau>'[bv::=b]\\<^sub>\\<tau>\\<^sub>b\" using check_varI subst_b_check_v by auto\n    show \"\\<Theta> ; \\<Phi> ; {||} ; (subst_gb  \\<Gamma> bv b) ; (u, (\\<tau>'[bv::=b]\\<^sub>\\<tau>\\<^sub>b)) #\\<^sub>\\<Delta> (subst_db  \\<Delta> bv b)   \\<turnstile> (s[bv::=b]\\<^sub>s\\<^sub>b) \\<Leftarrow> (\\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b)\" using check_varI by auto\n  qed\nnext\n  case (check_assignI \\<Theta> \\<Phi> \\<B> \\<Gamma> \\<Delta> u \\<tau> v z \\<tau>')\n  show ?case unfolding subst_b_simps proof( rule Typing.check_assignI) \n    show \"\\<Theta>  \\<turnstile>\\<^sub>w\\<^sub>f \\<Phi> \" using check_assignI by auto\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b \\<turnstile>\\<^sub>w\\<^sub>f \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b \" using wf_b_subst check_assignI by auto\n    show \"(u, \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b) \\<in> setD \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b\" using check_assignI subst_d_b_member  by simp\n    show \" \\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b  \\<turnstile> v[bv::=b]\\<^sub>v\\<^sub>b \\<Leftarrow> \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b\"  using check_assignI subst_b_check_v by auto\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b  \\<turnstile> \\<lbrace> z : B_unit  | TRUE \\<rbrace> \\<lesssim> \\<tau>'[bv::=b]\\<^sub>\\<tau>\\<^sub>b\" using check_assignI subst_b_subtype subst_b_simps subst_tb.simps by fastforce\n  qed\nnext\n  case (check_whileI \\<Theta> \\<Phi> \\<B> \\<Gamma> \\<Delta> s1 z s2 \\<tau>')\n  show ?case unfolding subst_b_simps proof(rule Typing.check_whileI) \n    show \"\\<Theta> ; \\<Phi> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b ; \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b  \\<turnstile> s1[bv::=b]\\<^sub>s\\<^sub>b \\<Leftarrow> \\<lbrace> z : B_bool  | TRUE \\<rbrace>\" using check_whileI by auto\n    show \"\\<Theta> ; \\<Phi> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b ; \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b  \\<turnstile> s2[bv::=b]\\<^sub>s\\<^sub>b \\<Leftarrow> \\<lbrace> z : B_unit  | TRUE \\<rbrace>\" using check_whileI by auto\n    show \"\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b  \\<turnstile> \\<lbrace> z : B_unit  | TRUE \\<rbrace> \\<lesssim> \\<tau>'[bv::=b]\\<^sub>\\<tau>\\<^sub>b\"  using subst_b_subtype check_whileI by fastforce\n  qed     \nnext\n  case (check_seqI \\<Theta> \\<Phi> \\<B> \\<Gamma> \\<Delta> s1 z s2 \\<tau>)\n  then show ?case unfolding subst_sb.simps using check_seqI Typing.check_seqI subst_b_eq by metis\nnext\n  case (check_caseI \\<Theta> \\<Phi> \\<B>  \\<Gamma> \\<Delta> tid dclist v cs \\<tau>  z)\n  show ?case unfolding subst_b_simps proof(rule Typing.check_caseI)\n    show \\<open> \\<Theta> ;  \\<Phi> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b ; \\<Delta>[bv::=b]\\<^sub>\\<Delta>\\<^sub>b ; tid ; dclist ; v[bv::=b]\\<^sub>v\\<^sub>b \\<turnstile> subst_branchlb cs bv b \\<Leftarrow> \\<tau>[bv::=b]\\<^sub>\\<tau>\\<^sub>b\\<close> using check_caseI by auto\n    show \\<open>AF_typedef tid dclist \\<in> set \\<Theta>\\<close> using check_caseI by auto\n    show \\<open>\\<Theta> ; {||} ; \\<Gamma>[bv::=b]\\<^sub>\\<Gamma>\\<^sub>b  \\<turnstile> v[bv::=b]\\<^sub>v\\<^sub>b \\<Leftarrow> \\<lbrace> z : B_id tid  | TRUE \\<rbrace>\\<close> using check_caseI subst_b_check_v subst_b_simps subst_tb.simps subst_b_simps       \n    proof -\n      have \"\\<lbrace> z : B_id tid | TRUE \\<rbrace> = \\<lbrace> z : B_id tid | TRUE \\<rbrace>[bv::=b]\\<^sub>\\<tau>\\<^sub>b\" using subst_b_eq by auto\n      then show ?thesis\n        by (metis (no_types) check_caseI.hyps(4) check_caseI.prems(1) check_caseI.prems(2) subst_b_check_v) (* 31 ms *)\n    qed\n    show \\<open>   \\<turnstile>\\<^sub>w\\<^sub>f \\<Theta> \\<close> using check_caseI by auto\n  qed\nqed\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/MiniSail/BTVSubstTypingL.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5544704796847396, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.28805923658922705}}
{"text": "theory Shifts\n  imports Frame Append\nbegin\n\n\nlemma shift_entails_prem: \"(As ** A) ** Bs \\<turnstile> Q \\<Longrightarrow> As ** A ** Bs \\<turnstile> Q\"\n  by simp\n\n\nlemma shift_entails_conc: \"P \\<turnstile> (As ** A) ** Bs \\<Longrightarrow> P  \\<turnstile> As ** A ** Bs\"\n  by simp\n\n\nlemma shift_frame_prem: \"((As ** A) ** Bs) -- PR \\<tturnstile> Q -- QR \\<Longrightarrow> (As ** A ** Bs) -- PR \\<tturnstile> Q -- QR\"\n  by simp\n\n\nlemma shift_frame_conc: \"P -- PR \\<tturnstile> ((As ** A) ** Bs) -- QR \\<Longrightarrow> P -- PR \\<tturnstile> (As ** A ** Bs) -- QR\"\n  by simp\n\nmethod_setup no_inst_rule = \n  \\<open>Attrib.thms >> (fn thms => fn ctxt => SIMPLE_METHOD' (match_tac ctxt thms THEN_ALL_NEW Goal.norm_hhf_tac ctxt))\\<close>\n\nmethod all_entails_prem_shifts methods M = append \\<open>M\\<close> \\<open>no_inst_rule shift_entails_prem, all_entails_prem_shifts M\\<close>\nmethod all_entails_conc_shifts methods M = append \\<open>M\\<close> \\<open>no_inst_rule shift_entails_conc, all_entails_conc_shifts M\\<close>\nmethod all_frame_prem_shifts methods M = append \\<open>M\\<close> \\<open>no_inst_rule shift_frame_prem, all_frame_prem_shifts M\\<close>\nmethod all_frame_conc_shifts methods M = append \\<open>M\\<close> \\<open>no_inst_rule shift_frame_conc, all_frame_conc_shifts M\\<close>\n\n\nend", "meta": {"author": "leanderBehr", "repo": "isabelle-llvm-RBT", "sha": "9456c7160d0d190bdb3ac358bc0058d22fb19926", "save_path": "github-repos/isabelle/leanderBehr-isabelle-llvm-RBT", "path": "github-repos/isabelle/leanderBehr-isabelle-llvm-RBT/isabelle-llvm-RBT-9456c7160d0d190bdb3ac358bc0058d22fb19926/LLVM_DS_RBT/Separation_Logic_Solver/Shifts.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.5195213219520929, "lm_q1q2_score": 0.28805922893963276}}
{"text": "theory Basic_Assn\n  imports\n    \"Refine_Imperative_HOL.Sepref_HOL_Bindings\"\n    \"Refine_Imperative_HOL.Sepref_Basic\"\nbegin\n\nsection \"Auxilary imperative assumptions\"\n\ntext \"The following auxiliary assertion types and lemmas were provided by Peter Lammich\"\n\nsubsection \\<open>List-Assn\\<close>\n\n\n\nlemma list_assn_cong[fundef_cong]:\n  \"\\<lbrakk> xs=xs'; ys=ys'; \\<And>x y. \\<lbrakk> x\\<in>set xs; y\\<in>set ys \\<rbrakk> \\<Longrightarrow> A x y = A' x y \\<rbrakk> \\<Longrightarrow> list_assn A xs ys = list_assn A' xs' ys'\"\n  by (induction xs ys arbitrary: xs' ys' rule: list_assn.induct) auto\n\n\nlemma list_assn_app_one: \"list_assn P (l1@[x]) (l1'@[y]) = list_assn P l1 l1' * P x y\"\n  by simp\n\n(* ------------------ ADDED by NM in course of btree_imp -------- *)\n\n\nlemma list_assn_len: \"h \\<Turnstile> list_assn A xs ys \\<Longrightarrow> length xs = length ys\"\n  using list_assn_aux_ineq_len by fastforce\n\n\nlemma list_assn_append_Cons_left: \"list_assn A (xs@x#ys) zs = (\\<exists>\\<^sub>A zs1 z zs2. list_assn A xs zs1 * A x z * list_assn A ys zs2 * \\<up>(zs1@z#zs2 = zs))\"\n  by (sep_auto simp add: list_assn_aux_cons_conv list_assn_aux_append_conv1 intro!: ent_iffI)\n\n\nlemma list_assn_aux_append_Cons: \n  shows \"length xs = length zsl \\<Longrightarrow> list_assn A (xs@x#ys) (zsl@z#zsr) = (list_assn A xs zsl * A x z * list_assn A ys zsr) \"\n  by (sep_auto simp add: mult.assoc)\n\nlemma list_assn_prod_split: \"list_assn (\\<lambda>x y. P x y * Q x y) as bs = list_assn P as bs * list_assn Q as bs\"\nproof(cases \"length as = length bs\")\n  case True\n  then show ?thesis\n  proof (induction rule: list_induct2)\n    case Nil\n    then show ?case by sep_auto\n  next\n    case (Cons x xs y ys)\n    show ?case\n    proof (rule ent_iffI, goal_cases)\n      case 1\n      then show ?case\n      using Cons by sep_auto\n    next\n      case 2\n      then show ?case\n      using Cons by sep_auto\n    qed\n  qed\nnext\n  case False\n  then show ?thesis\n    by (simp add: list_assn_aux_ineq_len)\nqed\n\n(* -------------------------------------------- *)\n\nsubsection \\<open>Prod-Assn\\<close>\n\n\nlemma prod_assn_cong[fundef_cong]:\n  \"\\<lbrakk> p=p'; pi=pi'; A (fst p) (fst pi) = A' (fst p) (fst pi); B (snd p) (snd pi) = B' (snd p) (snd pi) \\<rbrakk> \n    \\<Longrightarrow> (A\\<times>\\<^sub>aB) p pi = (A'\\<times>\\<^sub>aB') p' pi'\" \n  apply (cases p; cases pi)\n  by auto\n\nsubsection \\<open>Assertions and Magic Wand\\<close>\n\nlemma entails_preI: \"(\\<And>h. h \\<Turnstile> P \\<Longrightarrow> P \\<Longrightarrow>\\<^sub>A Q) \\<Longrightarrow> P \\<Longrightarrow>\\<^sub>A Q\"\n  unfolding entails_def\n  by auto\n\nlemma ent_true_drop_true: \n  \"P*true\\<Longrightarrow>\\<^sub>AQ*true \\<Longrightarrow> P*R*true\\<Longrightarrow>\\<^sub>AQ*true\"\n  using assn_aci(10) ent_true_drop(1) by presburger\n\n(* TODO *)\nlemma rem_true: \"P*true \\<Longrightarrow>\\<^sub>A Q*true \\<Longrightarrow> P \\<Longrightarrow>\\<^sub>AQ*true\"\n  using enttD enttI_true by blast\n\nlemma assn_eq_split:\n  assumes \"B = C\"\n  shows \"B \\<Longrightarrow>\\<^sub>A C\"\n  and \"C \\<Longrightarrow>\\<^sub>A B\"\n  by (simp_all add: assms)\n\nlemma ent_ex_inst: \"\\<exists>\\<^sub>Ax. P x \\<Longrightarrow>\\<^sub>A Q \\<Longrightarrow> P y \\<Longrightarrow>\\<^sub>A Q\"\n  using ent_trans by blast\n\nlemma ent_ex_inst2: \"\\<exists>\\<^sub>Ax y. P x y \\<Longrightarrow>\\<^sub>A Q \\<Longrightarrow> P x y \\<Longrightarrow>\\<^sub>A Q\"\n  using ent_trans by blast\n\nlemma ent_wandI2:\n  assumes IMP: \"P \\<Longrightarrow>\\<^sub>A (Q -* R)\"\n  shows \"Q*P \\<Longrightarrow>\\<^sub>A R\"\n  using assms\n  unfolding entails_def \n(*  by (meson assms ent_fwd ent_mp ent_refl fr_rot mod_frame_fwd)*)\nproof (clarsimp, goal_cases)\n  case (1 h as)\n  then obtain as1 as2 where \"as = as1 \\<union> as2\" \"as1 \\<inter> as2 = {}\" \"(h,as1) \\<Turnstile> Q\" \"(h,as2) \\<Turnstile> P\"\n    by (metis mod_star_conv prod.inject)\n  then have \"(h,as2) \\<Turnstile> (Q-*R)\"\n    by (simp add: \"1\"(1))\n  then have \"(h,as1\\<union>as2) \\<Turnstile> Q * (Q-*R)\"\n    by (simp add: \\<open>(h, as1) \\<Turnstile> Q\\<close> \\<open>as1 \\<inter> as2 = {}\\<close> star_assnI)\n  then show ?case \n    using \\<open>as = as1 \\<union> as2\\<close> ent_fwd ent_mp by blast\nqed\n\nlemma ent_wand: \"(P \\<Longrightarrow>\\<^sub>A (Q -* R)) = (Q*P \\<Longrightarrow>\\<^sub>A R)\"\n  using ent_wandI2 ent_wandI by blast\n\nlemma wand_ent_trans:\n  assumes \"P' \\<Longrightarrow>\\<^sub>A P\"\n      and \"Q \\<Longrightarrow>\\<^sub>A Q'\"\n    shows \"P -* Q \\<Longrightarrow>\\<^sub>A P' -* Q'\"\n  by (meson assms(1) assms(2) ent_wand ent_frame_fwd ent_refl ent_trans)\n\nlemma wand_elim: \"(P -* Q) * (Q -* R) \\<Longrightarrow>\\<^sub>A (P -* R)\"\n  by (metis ent_wand ent_frame_fwd ent_mp ent_refl star_assoc)\n\nlemma emp_wand_same: \"emp \\<Longrightarrow>\\<^sub>A (H -* H)\"\n  by (simp add: ent_wandI)\n\nlemma emp_wand_equal: \"(emp -* H) = H\"\n  apply(intro ent_iffI)\n  apply (metis ent_mp norm_assertion_simps(1))\n  by (simp add: ent_wandI)\n\nlemma pure_wand_equal: \"P \\<Longrightarrow> (\\<up>(P) -* H) = H\"\n  by (simp add: emp_wand_equal)\n\nlemma pure_wand_ent: \"(P \\<Longrightarrow> (H1 \\<Longrightarrow>\\<^sub>A H2)) \\<Longrightarrow> H1 \\<Longrightarrow>\\<^sub>A \\<up>(P) -* H2\"\n  by (simp add: ent_wand)\n\nlemma \"\\<up>(P \\<longrightarrow> Q) \\<Longrightarrow>\\<^sub>A (\\<up>(P) -* \\<up>(Q))\"\n  by (simp add: pure_wand_ent)\n\nlemma wand_uncurry: \"(P*Q) -* R \\<Longrightarrow>\\<^sub>A P -* (Q -* R)\"\n  by (simp add: assn_aci ent_mp ent_wandI fr_rot)\n\nlemma wand_absorb: \"(P -* Q) * R \\<Longrightarrow>\\<^sub>A (P -* (Q * R))\"\n  by (smt (z3) ent_mp ent_refl ent_star_mono ent_wandI star_aci(2) star_aci(3))\n\nlemma wand_ent_self: \"P \\<Longrightarrow>\\<^sub>A Q -* (Q * P)\"\n  by (simp add: ent_wandI)\n\nlemma wand_ent_cancel: \"P * ((P * Q) -* R) \\<Longrightarrow>\\<^sub>A Q -* R\"\n  by (simp add: ent_wandI2 wand_uncurry)\n\n\nlemma \"\\<exists>R. Q * R \\<Longrightarrow>\\<^sub>A P\"\n  using ent_mp by auto\n\nlemma \"P \\<Longrightarrow>\\<^sub>A Q * true \\<Longrightarrow> P = Q * (Q -* P)\"\n  apply(intro ent_iffI)\nproof(goal_cases)\n  case 2\n  then show ?case\n    by (simp add: ent_mp)\nnext\n  case test: 1\n  show ?case\n    unfolding entails_def\n    apply clarsimp\n  proof (goal_cases)\n    case (1 a b)\n    then have \"(a,b) \\<Turnstile> Q * true\"\n      using test entails_def\n      by blast\n    then obtain h as1 as2 where *:\n        \"(a,b) = (h, as1 \\<union> as2) \\<and> as1 \\<inter> as2 = {} \\<and> (h, as1) \\<Turnstile> Q \\<and> (h, as2) \\<Turnstile> true\"\n    using mod_star_conv by auto\n  then have \"(h, as1 \\<union> as2) \\<Turnstile> P\" \"(a,b) = (h, as1 \\<union> as2)\" \n    using \"1\" by blast+\n  then show ?case \n    apply simp\n    thm star_assnI\n    apply(intro star_assnI)\n    apply (simp_all add: *)\n    apply(intro wand_assnI)\n    apply (meson \"*\" models_in_range)\n    apply auto\n    oops\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/BTree/Basic_Assn.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5195213219520929, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.28805922893963276}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |               November 2004               |\n            |                   July 2005  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |                October 2005  (modified)   |\n            |                  April 2006  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2016         |\n            |                    May 2016  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory Trace_seq\nimports Prefix\nbegin\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite (notick | t = <>)                  *)\n(*                                                                     *)\n(*                  disj_not1: (~ P | Q) = (P --> Q)                   *)\n\ndeclare disj_not1 [simp del]\n\n(*****************************************************************\n\n         1. \n         2. \n         3. \n         4. \n\n *****************************************************************)\n\ndefinition\n  rmTick:: \"'a trace => 'a trace\"\n  where\n  rmTick_def : \n    \"rmTick s == if noTick s then s else butlastt s\"\n\n(***********************************************************\n                  nil and Tick\n ***********************************************************)\n\n(*** noTick s --> rmTick s ***)\n\nlemma rmTick_nochange[simp]: \"noTick s ==> rmTick s = s\"\nby (simp add: rmTick_def)\n\n(*** rmTick <> ***)\n\nlemma rmTick_nil[simp]: \"rmTick <> = <>\"\nby (simp add: rmTick_def)\n\n(*** rmTick <Tick> ***)\n\nlemma rmTick_Tick[simp]: \"rmTick <Tick> = <>\"\nby (simp add: rmTick_def)\n\n(*** noTick rmTick s ***)\n\nlemma noTick_rmTick[simp]: \"noTick (rmTick s)\"\napply (case_tac \"noTick s\")\napply (simp_all add: rmTick_def)\napply (simp add: noTick_butlast)\ndone\n\nlemma noTick_rmTickE: \"[| t = rmTick s ; noTick t ==> R |] ==> R\"\nby (simp)\n\n(***********************************************************\n                           appt\n ***********************************************************)\n\n(*-------------------------*\n |       rmTick last       |\n *-------------------------*)\n\nlemma rmTick_last_Tick[simp]:\n  \"noTick s ==> rmTick (s ^^^ <Tick>) = s\"\nby (simp add: rmTick_def)\n\n(*** noTick butlast ***)\n\nlemma rmTick_butlastt: \n  \"~ noTick s ==> rmTick s = butlastt s\"\nby (simp add: rmTick_def)\n\n(*-------------------------*\n |   rmTick distribution   |\n *-------------------------*)\n\nlemma rmTick_appt_dist[simp]:\n  \"noTick s ==> rmTick (s ^^^ t) = s ^^^ (rmTick t)\"\napply (insert trace_last_nil_or_unnil)\napply (drule_tac x=\"t\" in spec, simp)\napply (erule disjE, simp)\n\napply (elim conjE exE, simp)\napply (insert event_Tick_or_Ev)\napply (drule_tac x=\"a\" in spec)\n\napply (erule disjE)   (* Tick *)\napply (simp add: appt_assoc_sym)\n\napply (erule exE)     (* Ev *)\napply (simp add: appt_assoc_sym)\ndone\n\n(***********************************************************\n                        prefix\n ***********************************************************)\n\n(*** rmTick prefix ***)\n\n(* only if *)\n\nlemma rmTick_prefix_only_if:\n  \"prefix s (rmTick t) ==> (EX u. prefix u t & s = rmTick u)\"\napply (insert trace_last_nil_or_unnil)\napply (drule_tac x=\"t\" in spec, simp)\napply (erule disjE, simp)\n\napply (elim conjE exE, simp)\napply (insert event_Tick_or_Ev)\napply (drule_tac x=\"a\" in spec)\n\n apply (erule disjE)    (* Tick *)\n apply (rule_tac x=\"s\" in exI)\n apply (simp add: prefix_noTick)\n\n apply (erule exE)      (* Ev *)\n apply (simp)\n\n  apply (erule disjE)    (* same length *)\n  apply (rule_tac x=\"sa ^^^ <Ev aa>\" in exI, simp)\n\n  apply (rule_tac x=\"s\" in exI)\n  apply (simp add: prefix_noTick)\ndone\n\n(* if *)\n\nlemma rmTick_prefix_if:\n  \"(EX u. prefix u t & s = rmTick u) ==> prefix s (rmTick t)\"\napply (elim conjE exE)\napply (simp)\n\napply (insert trace_last_nil_or_unnil)\napply (drule_tac x=\"t\" in spec, simp)\napply (erule disjE, simp)\napply (elim conjE exE)\napply (simp)\n\n apply (erule disjE, simp)\n apply (case_tac \"~ noTick u\")\n apply (simp add: prefix_noTick)\n\n apply (insert event_Tick_or_Ev)\n apply (drule_tac x=\"a\" in spec)\n\n  apply (erule disjE)    (* Tick *)\n  apply (simp)\n\n  apply (elim exE)       (* Ev *)\n  apply (simp)\ndone\n\n(* iff *)\n\nlemma rmTick_prefix:\n  \"prefix s (rmTick t) = (EX u. prefix u t & s = rmTick u)\"\napply (rule iffI)\napply (simp add: rmTick_prefix_only_if)\napply (simp add: rmTick_prefix_if)\ndone\n\n(*--------------*\n |   reverse    |\n *--------------*)\n\nlemma rmTick_prefix_rev: \"prefix s t ==> prefix (rmTick s) t\"\napply (simp add: rmTick_def)\napply (intro impI)\napply (simp add: prefix_def)\n\napply (rule_tac x=\"<Tick>\" in exI)\napply (simp add: noTick_butlast)\napply (simp add: Tick_decompo)\ndone\n\nlemma rmTick_prefix_rev_simp[simp]: \"prefix (rmTick s) s\"\nby (simp add: rmTick_prefix_rev)\n\n(****************** to add it again ******************)\n\ndeclare disj_not1 [simp] \n\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/CSP/Trace_seq.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5851011542032313, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.28797984629537415}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2005         |\n            |               December 2005  (modified)   |\n            |                  April 2006  (modified)   |\n            |                  March 2007  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory CSP_F_law_step_ext\nimports CSP_F_law_basic CSP_T_law_step_ext\nbegin\n\n(*****************************************************************\n\n         1. step laws\n         2.\n         3. \n         4. \n\n *****************************************************************)\n\n(*********************************************************\n              (P1 [> P2) |[X]| (Q1 [> Q2)\n *********************************************************)\n\n(* The following law in p.288 does not hold.                               *)\n(*     (P1 [> P2) |[X]| (Q1 [> Q2)                                         *)\n(*  =F (P1 |[X]| Q1) [> ((P2 |[X]| (Q1 [> Q2)) |~| ((P1 [> P2) |[X]| Q2))  *)\n(*                                                                         *)\n(* a counter example:                                                      *)\n(*  P1 = a -> STOP, P2 = STOP, Q1 = STOP, Q2 = b -> STOP, X = {}           *)\n(*  where (a ~= b)                                                         *)\n(*                                                                         *)\n(*  check the following lemmas                                             *)\n\nlemma \"a ~= b ==>\n       (<Ev a>, {(Ev b)}) ~:f \n        failures ((a -> STOP [> STOP) |[{}]| (STOP [> (b -> STOP))) M\"\napply (simp add: in_failures in_traces)\napply (intro allI impI)\napply (simp add: par_tr_Ev)\napply (erule disjE)\napply (auto)\ndone\n\nlemma \"(<Ev a>, {(Ev b)}) :f\n       failures (((a -> STOP) |[{}]| STOP) [> \n                 ((STOP |[{}]| (STOP [> (b -> STOP))) |~| \n                  (((a -> STOP [> STOP) |[X]| (b -> STOP))))) M\"\napply (simp add: in_failures in_traces)\napply (rule disjI1)\napply (rule_tac x=\"{(Ev b)}\" in exI)\napply (rule_tac x=\"{(Ev b)}\" in exI)\napply (simp)\napply (rule_tac x=\"<Ev a>\" in exI)\napply (simp add: par_tr_nil_right)\ndone\n\n(*********************************************************\n              (P [> Q) |[X]| (? :Y -> Rf)\n *********************************************************)\n\n(* The following law in p.289 does not hold.                               *)\n(*                                                                         *)\n(*     (P [> Q) |[X]| (? :Y -> Rf) =F[M,M]                                      *)\n(*     (? x:(Y - X) -> ((P [> Q) |[X]| Rf x))                              *)\n(*     [+] ((P |[X]| (? :Y -> Rf)) [> (Q |[X]| (? :Y -> Rf)))              *)\n(*                                                                         *)\n(* a counter example:                                                      *)\n(*  P = STOP, Q = b -> STOP, Y = {a}, Rf = (%x. STOP), X = {}              *)\n(*  where (a ~= b)                                                         *)\n(*                                                                         *)\n(*  check the following lemmas                                             *)\n\nlemma \"a ~= b ==>\n      (<Ev a>, {(Ev b)}) ~:f  \n       failures ((STOP [> (b -> STOP)) |[{}]| (? x:{a} -> STOP)) M\"\napply (simp add: in_failures in_traces)\napply (intro allI impI)\napply (simp add: par_tr_Ev)\napply (erule disjE)\napply (auto)\ndone\n\nlemma \"a ~= b ==>\n       (<Ev a>, {(Ev b)}) :f \n        failures ((? x:({a} - {}) -> ((STOP [>  (b -> STOP)) |[{}]| STOP))\n                  [+] ((STOP |[{}]| (? x:{a} -> STOP)) \n                       [> ((b -> STOP) |[{}]| (? x:{a} -> STOP)))) M\"\napply (fold Timeout_def)\napply (simp add: in_failures in_failures_Timeout in_traces)\napply (rule disjI2)\napply (rule disjI2)\napply (rule_tac x=\"{(Ev b)}\" in exI)\napply (rule_tac x=\"{(Ev b)}\" in exI)\napply (simp)\napply (rule_tac x=\"<Ev a>\" in exI)\napply (simp add: par_tr_nil_left)\ndone\n\n(*********************************************************\n              Parallel expansion & distribbution\n *********************************************************)\n\nlemma cspF_Parallel_Timeout_split:\n  \"((? :Y -> Pf) [> P) |[X]| ((? :Z -> Qf) [> Q) =F[M,M]\n     (? x:((X Int Y Int Z) Un (Y - X) Un (Z - X))\n         -> IF (x : X) THEN (Pf x |[X]| Qf x)\n               ELSE IF (x : Y & x : Z) THEN ((Pf x |[X]| ((? x:Z -> Qf x) [> Q))\n                                        |~| (((? x:Y -> Pf x) [> P) |[X]| Qf x))\n               ELSE IF (x : Y) THEN (Pf x |[X]| ((? x:Z -> Qf x) [> Q))\n               ELSE (((? x:Y -> Pf x) [> P) |[X]| Qf x))\n     [> (((P |[X]| ((? :Z -> Qf) [> Q)) |~|\n         (((? :Y -> Pf) [> P) |[X]| Q)))\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Parallel_Timeout_split)\napply (fold Timeout_def)\napply (rule order_antisym)\n\n (* => *)\n apply (rule)\n apply (simp add: in_failures_Timeout in_failures)\n apply (elim disjE conjE exE)\n apply (simp_all)\n\n  apply (force)\n\n  apply (rule disjI1)\n  apply (rule_tac x=\"Y\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"sa\" in exI)\n  apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n  apply (simp)\n\n  apply (rule disjI1)\n  apply (rule_tac x=\"Y\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"sa\" in exI)\n  apply (rule_tac x=\"<>\" in exI)\n  apply (simp)\n\n  apply (rule disjI2)\n  apply (rule disjI1)\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Z\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n  apply (rule_tac x=\"t\" in exI)\n  apply (simp)\n\n  apply (rule disjI2)\n  apply (rule disjI1)\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Z\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"<>\" in exI)\n  apply (rule_tac x=\"t\" in exI)\n  apply (simp)\n\n  (* main part *)\n\n  apply (case_tac \"s = <>\", simp, simp)\n  apply (rule disjI2)\n  apply (rule disjI2)\n  apply (simp add: par_tr_head_Ev_Ev)\n  apply (elim exE disjE)\n  apply (rule_tac x=\"c\" in exI)\n  apply (rule_tac x=\"v\" in exI)\n  apply (elim conjE disjE)\n\n   (* sync *)\n   apply (simp)\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (force)\n\n   (* left *)\n   apply (simp)\n   apply (case_tac \"c:Z\")\n\n    apply (simp)\n    apply (rule disjI1)\n    apply (rule_tac x=\"Ya\" in exI)\n    apply (rule_tac x=\"Za\" in exI)\n    apply (force)\n\n    apply (simp)\n    apply (rule_tac x=\"Ya\" in exI)\n    apply (rule_tac x=\"Za\" in exI)\n    apply (force)\n\n   (* right *)\n   apply (simp)\n   apply (case_tac \"c:Y\")\n\n    apply (simp)\n    apply (rule disjI2)\n    apply (rule_tac x=\"Ya\" in exI)\n    apply (rule_tac x=\"Za\" in exI)\n    apply (force)\n\n    apply (simp)\n    apply (rule_tac x=\"Ya\" in exI)\n    apply (rule_tac x=\"Za\" in exI)\n    apply (force)\n\n  (* others *)\n\n  apply (simp add: in_traces)\n  apply (simp add: in_traces)\n  apply (simp add: in_traces)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_failures_Timeout in_failures)\n apply (elim conjE exE disjE)\n apply (simp_all)\n\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (force)\n\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (force)\n\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (force)\n\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (force)\n\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (force)\n\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (force)\n\n  (* main part *)\n\n  (* sync *)\n  apply (simp add: in_failures_Parallel)\n  apply (elim disjE conjE exE)\n  apply (simp)\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n  apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n  apply (simp add: par_tr_head)\n\n  (* no_sync *)\n  apply (simp add: in_failures_IF)\n  apply (case_tac \"a:Z\")\n\n  apply (simp add: in_failures_Timeout in_failures)\n  apply (elim disjE conjE exE)\n  apply (simp_all)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n  (* a ~: Z *)\n  apply (simp add: in_failures_Timeout in_failures)\n  apply (elim disjE conjE exE)\n  apply (simp_all)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n  apply (simp add: in_traces)\n\n  (* no_sync *)\n  apply (simp add: in_failures_IF)\n  apply (case_tac \"a:Y\")\n\n  apply (simp add: in_failures_Timeout in_failures)\n  apply (elim disjE conjE exE)\n  apply (simp_all)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n  (* a ~: Y *)\n  apply (simp add: in_failures_Timeout in_failures)\n  apply (elim disjE conjE exE)\n  apply (simp_all)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n (* others *)\n\n apply (simp add: in_traces)\ndone\n\n(*********************************************************\n            Parallel expansion & distribbution 2\n *********************************************************)\n\n(*** left ****)\n\nlemma cspF_Parallel_Timeout_input_l: \n  \"((? :Y -> Pf) [> P) |[X]| (? :Z -> Qf) =F[M,M]\n     (? x:((X Int Y Int Z) Un (Y - X) Un (Z - X))\n         -> IF (x : X) THEN (Pf x |[X]| Qf x)\n               ELSE IF (x : Y & x : Z) THEN ((Pf x |[X]| (? x:Z -> Qf x))\n                                        |~| (((? x:Y -> Pf x) [> P) |[X]| Qf x))\n               ELSE IF (x : Y) THEN (Pf x |[X]| (? x:Z -> Qf x))\n               ELSE (((? x:Y -> Pf x) [> P) |[X]| Qf x))\n     [> (((P |[X]| (? :Z -> Qf))))\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Parallel_Timeout_input)\napply (fold Timeout_def)\napply (rule order_antisym)\n\n (* => *)\n apply (rule)\n apply (simp add: in_failures_Timeout in_failures)\n apply (elim disjE conjE exE)\n apply (simp_all)\n\n  apply (force)\n\n  apply (rule disjI1)\n  apply (rule_tac x=\"Y\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"sa\" in exI)\n  apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n  apply (simp)\n\n  apply (simp add: par_tr_nil_right)\n  apply (rule disjI2)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"sb\" in exI)\n  apply (elim conjE)\n  apply (simp add: image_iff)\n  apply (case_tac \"a : Z\")\n   apply (simp)\n   apply (rule disjI1)\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<>\" in exI)\n   apply (simp add: par_tr_nil_right)\n\n   apply (simp)\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<>\" in exI)\n   apply (simp add: par_tr_nil_right)\n\n  apply (simp add: in_traces)\n\n  (* main part *)\n\n  apply (case_tac \"s = <>\", simp, simp)\n  apply (rule disjI2)\n  apply (simp add: par_tr_head_Ev_Ev)\n  apply (elim exE disjE)\n  apply (rule_tac x=\"c\" in exI)\n  apply (rule_tac x=\"v\" in exI)\n  apply (elim conjE disjE)\n\n   (* sync *)\n   apply (simp)\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (force)\n\n   (* left *)\n   apply (simp)\n   apply (case_tac \"c:Z\")\n\n    apply (simp)\n    apply (rule disjI1)\n    apply (rule_tac x=\"Ya\" in exI)\n    apply (rule_tac x=\"Za\" in exI)\n    apply (force)\n\n    apply (simp)\n    apply (rule_tac x=\"Ya\" in exI)\n    apply (rule_tac x=\"Za\" in exI)\n    apply (force)\n\n   (* right *)\n   apply (simp)\n   apply (case_tac \"c:Y\")\n\n    apply (simp)\n    apply (rule disjI2)\n    apply (rule_tac x=\"Ya\" in exI)\n    apply (rule_tac x=\"Za\" in exI)\n    apply (force)\n\n    apply (simp)\n    apply (rule_tac x=\"Ya\" in exI)\n    apply (rule_tac x=\"Za\" in exI)\n    apply (force)\n\n  (* others *)\n\n  apply (simp add: in_traces)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_failures_Timeout in_failures)\n apply (elim conjE exE disjE)\n apply (simp_all)\n\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"sa\" in exI)\n  apply (rule_tac x=\"<>\" in exI)\n  apply (simp)\n\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (force)\n\n  (* main part *)\n\n  (* sync *)\n  apply (simp add: in_failures_Parallel)\n  apply (elim disjE conjE exE)\n  apply (simp)\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n  apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n  apply (simp add: par_tr_head)\n\n  (* no_sync *)\n  apply (simp add: in_failures_IF)\n  apply (case_tac \"a:Z\")\n\n  apply (simp add: in_failures_Timeout in_failures)\n  apply (elim disjE conjE exE)\n  apply (simp_all)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev aa> ^^^ sc\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (simp add: in_traces)\n\n  (* a ~: Z *)\n  apply (simp add: in_failures_Timeout in_failures)\n  apply (elim disjE conjE exE)\n  apply (simp_all)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"<>\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n  apply (simp add: in_traces)\n\n  (* no_sync *)\n  apply (simp add: in_failures_IF)\n  apply (case_tac \"a:Y\")\n\n  apply (simp add: in_failures_Timeout in_failures)\n  apply (elim disjE conjE exE)\n  apply (simp_all)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"<Ev aa> ^^^ sc\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev aa> ^^^ sc\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (simp add: in_traces)\n\n  (* a ~: Y *)\n  apply (simp add: in_failures_Timeout in_failures)\n  apply (elim disjE conjE exE)\n  apply (simp_all)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev aa> ^^^ sc\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n\n   apply (simp add: in_traces)\n\n (* others *)\n\n apply (simp add: in_traces)\ndone\n\n(*** right ****)\n\nlemma cspF_Parallel_Timeout_input_r: \n  \"(? :Y -> Pf) |[X]| ((? :Z -> Qf) [> Q) =F[M,M]\n     (? x:((X Int Y Int Z) Un (Y - X) Un (Z - X))\n         -> IF (x : X) THEN (Pf x |[X]| Qf x)\n               ELSE IF (x : Y & x : Z) THEN ((Pf x |[X]| ((? x:Z -> Qf x) [> Q))\n                                        |~| ((? x:Y -> Pf x) |[X]| Qf x))\n               ELSE IF (x : Y) THEN (Pf x |[X]| ((? x:Z -> Qf x) [> Q))\n               ELSE ((? x:Y -> Pf x) |[X]| Qf x))\n     [> ((? :Y -> Pf) |[X]| Q)\"\napply (rule cspF_rw_left)\napply (rule cspF_commut)\napply (rule cspF_rw_left)\napply (rule cspF_Parallel_Timeout_input_l)\napply (rule cspF_decompo)\napply (rule cspF_decompo)\napply (rule cspF_decompo)\napply (force)\napply (rule cspF_decompo)\napply (simp)\napply (rule cspF_commut)\n\napply (case_tac \"a : Z & a : Y\")\napply (simp)\napply (rule cspF_rw_left)\napply (rule cspF_IF_True)\napply (rule cspF_rw_right)\napply (rule cspF_IF_True)\napply (rule cspF_rw_left)\napply (rule cspF_commut)\napply (rule cspF_decompo)\napply (rule cspF_commut)\napply (rule cspF_commut)\n\napply (simp (no_asm_simp))\napply (rule cspF_rw_left)\napply (rule cspF_IF_False)\napply (rule cspF_rw_right)\napply (subgoal_tac \"~ (a : Y & a : Z)\")\napply (simp (no_asm_simp))\napply (rule cspF_IF_False)\napply (force)\n\napply (case_tac \"a : Z\")\napply (simp)\napply (rule cspF_rw_left)\napply (rule cspF_IF_True)\napply (rule cspF_rw_right)\napply (rule cspF_IF_False)\napply (rule cspF_commut)\napply (simp)\napply (rule cspF_rw_left)\napply (rule cspF_IF_False)\napply (rule cspF_rw_right)\napply (rule cspF_IF_True)\napply (rule cspF_commut)\n\napply (rule cspF_reflex)\napply (rule cspF_commut)\ndone\n\nlemmas cspF_Parallel_Timeout_input\n     = cspF_Parallel_Timeout_input_l\n       cspF_Parallel_Timeout_input_r\n\n(*** cspF_step_ext ***)\n\nlemmas cspF_step_ext = cspF_Parallel_Timeout_split\n                       cspF_Parallel_Timeout_input\n\nend\n", "meta": {"author": "pefribeiro", "repo": "CSP-Prover", "sha": "8967cc482e5695fca4abb52d9dc2cf36b7b7a44e", "save_path": "github-repos/isabelle/pefribeiro-CSP-Prover", "path": "github-repos/isabelle/pefribeiro-CSP-Prover/CSP-Prover-8967cc482e5695fca4abb52d9dc2cf36b7b7a44e/CSP_F/CSP_F_law_step_ext.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5851011542032312, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.2879798462953741}}
{"text": "theory QuiescentResult\nimports Semantics PositiveAccounts\nbegin\n\nlemma reduceOne_onlyIfNonEmptyState : \"refundOne acc = Some c \\<Longrightarrow> acc \\<noteq> []\"\n  by auto\n\nlemma reduceContractStepPayIsQuiescent :\n      \"(let moneyToPay = evalValue env sta x23\n        in if moneyToPay \\<le> 0 then Reduced (ReduceNonPositivePay x21 x22 tok moneyToPay) ReduceNoPayment sta x24\n           else let balance = moneyInAccount x21 tok (accounts sta); paidMoney = min balance moneyToPay; newBalance = balance - paidMoney;\n                    newAccs = updateMoneyInAccount x21 tok newBalance (accounts sta);\n                    warning = if paidMoney < moneyToPay then ReducePartialPay x21 x22 tok paidMoney moneyToPay else ReduceNoWarning;\n                    (payment, finalAccs) = giveMoney x21 x22 tok paidMoney newAccs\n                in Reduced warning payment (sta\\<lparr>accounts := finalAccs\\<rparr>) x24) =\n       NotReduced \\<Longrightarrow>\n       cont = Pay x21 x22 tok x23 x24 \\<Longrightarrow> False\"\n  apply (cases \"evalValue env sta x23 \\<le> 0\")\n  apply simp\n  apply (cases \"min (moneyInAccount x21 tok (accounts sta)) (evalValue env sta x23) < (evalValue env sta x23)\")\n  apply (cases \"lookup (x21, tok) (accounts sta)\")\n  apply simp\n  apply (meson ReduceStepResult.distinct(1))\n  apply (cases \"evalValue env sta x23 \\<le> 0\")\n  apply simp\n  apply (cases \"min (moneyInAccount x21 tok (accounts sta)) (evalValue env sta x23) < evalValue env sta x23\")\n  apply simp\n  apply (meson ReduceStepResult.distinct(1))\n  apply simp\n  by (smt ReduceStepResult.distinct(1) case_prod_unfold)\n\nlemma reduceOneIsSomeIfNotEmptyAndPositive : \"accs \\<noteq> [] \\<Longrightarrow> allAccountsPositive accs \\<Longrightarrow> refundOne accs \\<noteq> None\"\n  by (metis allAccountsPositiveMeansFirstIsPositive option.distinct(1) refundOne.cases refundOne.simps(1))\n\nlemma reduceContractStepIsQuiescent : \"validAndPositive_state sta \\<Longrightarrow>\n                                       reduceContractStep env sta cont = NotReduced \\<Longrightarrow> isQuiescent cont sta\"\n  apply (cases cont)\n  apply (simp only:reduceContractStep.simps)\n  apply (cases \"accounts sta\")\n  using reduceContractStepPayIsQuiescent apply fastforce\n  apply (cases \"refundOne (accounts sta)\")\n  apply (simp add: reduceOneIsSomeIfNotEmptyAndPositive)\n  apply (simp add: case_prod_beta')\n  apply (metis reduceContractStep.simps(2) reduceContractStepPayIsQuiescent)\n  apply simp\n  using isQuiescent.simps(2) apply blast\n  apply (metis ReduceStepResult.distinct(1) reduceContractStep.simps(5))\n  by simp\n\nlemma reductionLoopIsQuiescent_aux :\n  \"(\\<And>x11 x12 x13 x14 x xa.\n     reduceContractStep env state contract = Reduced x11 x12 x13 x14 \\<Longrightarrow>\n     x = (if x11 = ReduceNoWarning then warnings else x11 # warnings) \\<Longrightarrow>\n     xa = (case x12 of ReduceNoPayment \\<Rightarrow> payments | ReduceWithPayment payment \\<Rightarrow> payment # payments) \\<Longrightarrow>\n     validAndPositive_state x13 \\<Longrightarrow> reductionLoop True env x13 x14 x xa = ContractQuiescent newReduced nwa nef nsta ncon \\<Longrightarrow> isQuiescent ncon nsta) \\<Longrightarrow>\n   validAndPositive_state state \\<Longrightarrow> reductionLoop reduced env state contract warnings payments = ContractQuiescent newReduced nwa nef nsta ncon \\<Longrightarrow> isQuiescent ncon nsta\"\n  apply (simp only:reductionLoop.simps [of reduced env state contract warnings payments])\n  apply (cases \"reduceContractStep env state contract\")\n  apply (metis (no_types, lifting) ReduceStepResult.simps(8) reduceContractStep_preserves_validAndPositive_state)\n  apply (simp add: reduceContractStepIsQuiescent)\n  by simp\n\nlemma reductionLoopIsQuiescent : \"validAndPositive_state sta \\<Longrightarrow>\n                                  reductionLoop reduced env sta c wa ef = ContractQuiescent newReduced nwa nef nsta ncon \\<Longrightarrow> isQuiescent ncon nsta\"\n  apply (induction reduced env sta c wa ef rule:reductionLoop.induct)\n  using reductionLoopIsQuiescent_aux by blast\n\ntheorem reduceContractUntilQuiecentIsQuiescent : \"validAndPositive_state sta \\<Longrightarrow>\n                                                  reduceContractUntilQuiescent env sta c = ContractQuiescent newReduced wa ef nsta ncon \\<Longrightarrow> isQuiescent ncon nsta\"\n  by (simp only:reduceContractUntilQuiescent.simps reductionLoopIsQuiescent)\n\nlemma applyAllInputsLoopIsQuiescent_base : \"validAndPositive_state fixSta \\<Longrightarrow>\n                                            applyAllLoop reduced env fixSta cont [] wa ef = ApplyAllSuccess newReduced nwa nef nsta ncon \\<Longrightarrow> isQuiescent ncon nsta\"\n  apply (cases \"reduceContractUntilQuiescent env fixSta cont\")\n  by (simp_all del:reduceContractUntilQuiescent.simps validAndPositive_state.simps add:reduceContractUntilQuiecentIsQuiescent)\n\nlemma applyAllInputsLoopIsQuiescent_loop : \"(\\<And>reduced env fixSta cont wa ef.\n           validAndPositive_state fixSta \\<Longrightarrow> applyAllLoop reduced env fixSta cont inps wa ef = ApplyAllSuccess newReduced nwa nef nsta ncon \\<Longrightarrow> isQuiescent ncon nsta) \\<Longrightarrow>\n       validAndPositive_state fixSta \\<Longrightarrow> applyAllLoop reduced env fixSta cont (a # inps) wa ef = ApplyAllSuccess newReduced nwa nef nsta ncon \\<Longrightarrow> isQuiescent ncon nsta\"\n  apply (cases \"reduceContractUntilQuiescent env fixSta cont\")\n  apply (unfold applyAllLoop.simps [of \"reduced\" \"env\" \"fixSta\"])\n  apply (simp only:ReduceResult.case list.case)\n  subgoal for x11 x12 x13 x14 x15\n    apply (cases \"applyInput env x14 a x15\")\n    apply (simp only:ApplyResult.case)\n    apply (meson applyInput_preserves_preserves_validAndPositive_state reduceContractUntilQuiescent_preserves_validAndPositive_state)\n    apply (simp only:ApplyResult.case)\n    by blast\n  by simp\n\nlemma applyAllInputsLoopIsQuiescent : \"validAndPositive_state fixSta \\<Longrightarrow>\n                                       applyAllLoop reduced env fixSta cont inps wa ef = ApplyAllSuccess newReduced nwa nef nsta ncon \\<Longrightarrow> isQuiescent ncon nsta\"\n  apply (induction inps arbitrary:reduced env fixSta cont wa ef)\n  apply (simp add: applyAllInputsLoopIsQuiescent_base)\n  using applyAllInputsLoopIsQuiescent_loop by blast\n\nlemma applyAllInputsIsQuiescent : \"validAndPositive_state fixSta \\<Longrightarrow>\n                                   applyAllInputs env fixSta cont inps = ApplyAllSuccess reduced warnings payments newState newCont \\<Longrightarrow> isQuiescent newCont newState\"\n  by (simp add: applyAllInputsLoopIsQuiescent)\n\nlemma computeTransactionIsQuiescent_aux : \"validAndPositive_state sta \\<Longrightarrow>\n                                           computeTransaction (Transaction \\<lparr>interval = interva, inputs = inps\\<rparr>) sta cont\n                                             = TransactionOutput \\<lparr> txOutWarnings = nwa,\n                                                                   txOutPayments = nef,\n                                                                   txOutState = nsta,\n                                                                   txOutContract = ncont\\<rparr> \\<Longrightarrow>\n       fixInterval (interval (Transaction \\<lparr>interval = interva, inputs = inps\\<rparr>)) sta = IntervalTrimmed x11 x12\n       \\<Longrightarrow> isQuiescent ncont nsta\"\n  apply (simp only:computeTransaction.simps)\n  by (smt ApplyAllResult.exhaust ApplyAllResult.simps(10) ApplyAllResult.simps(8) ApplyAllResult.simps(9) IntervalResult.simps(5) TransactionOutput.distinct(1) TransactionOutput.inject(1) TransactionOutputRecord.ext_inject applyAllInputs.simps applyAllInputsLoopIsQuiescent fixInterval_preserves_preserves_validAndPositive_state)\n\ntheorem computeTransactionIsQuiescent : \"validAndPositive_state sta \\<Longrightarrow>\n                                         computeTransaction traIn sta cont = TransactionOutput traOut \\<Longrightarrow>\n                                         isQuiescent (txOutContract traOut) (txOutState traOut)\"\n\n  apply (cases \"traIn\")\n  apply (cases \"traOut\")\n  by (smt IntervalResult.exhaust IntervalResult.simps(6) Transaction.update_convs(3) TransactionOutput.distinct(1) TransactionOutputRecord.surjective computeTransaction.simps computeTransactionIsQuiescent_aux old.unit.exhaust)\n\nlemma playTraceAuxIsQuiescent : \"validAndPositive_state (txOutState traIn) \\<Longrightarrow>\n                                 (l \\<noteq> Nil \\<or> isQuiescent (txOutContract traIn) (txOutState traIn)) \\<Longrightarrow>\n                                 playTraceAux traIn l = TransactionOutput traOut \\<Longrightarrow>\n                                 isQuiescent (txOutContract traOut) (txOutState traOut)\"\n  apply (induction traIn l arbitrary:traOut rule:playTraceAux.induct)\n  apply simp\n  apply (simp del:validAndPositive_state.simps isQuiescent.simps computeTransaction.simps)\n  subgoal for warnings payments state cont h t traOut\n    apply (cases \"computeTransaction h state cont\")\n    apply (simp del:validAndPositive_state.simps isQuiescent.simps computeTransaction.simps)\n    using computeTransactionIsQuiescent computeTransaction_preserves_validAndPositive_state by simp_all\n  done\n\ntheorem playTraceIsQuiescent : \"playTrace sl cont (Cons h t) = TransactionOutput traOut \\<Longrightarrow>\n                                isQuiescent (txOutContract traOut) (txOutState traOut)\"\n  by (metis TransactionOutputRecord.select_convs(3) list.discI playTrace.simps playTraceAuxIsQuiescent validAndPositive_initial_state)\n\n\nlemma reductionLoop_reduce_monotonic : \"reductionLoop True env sta cont wa ef = ContractQuiescent reduce nwa nef newState newCont \\<Longrightarrow> reduce\"\n  apply (induction True env sta cont wa ef arbitrary:reduce nwa nef newState newCont rule:reductionLoop.induct)\n  subgoal for env state contract warnings payments reduce nwa nef newState newCont\n    apply (cases \"reduceContractStep env state contract\")\n    apply (simp only:ReduceStepResult.case)\n    subgoal premises fact for x11 x12 x13 x14\n      apply (rule fact(1)[of x11 x12 x13 x14 \"(if x11 = ReduceNoWarning then warnings else x11 # warnings)\" \"(case x12 of ReduceNoPayment \\<Rightarrow> payments | ReduceWithPayment payment \\<Rightarrow> payment # payments)\" reduce nwa nef newState newCont])\n      apply simp\n      apply simp\n      apply simp\n      by (metis (lifting) ReduceStepResult.simps(8) fact(2) fact(3) reductionLoop.elims)\n     apply simp\n    by simp\n  done\n\nlemma reduceContractUntilQuiescent_ifDifferentReduced : \"reduceContractUntilQuiescent si sta cont = ContractQuiescent reduce wa ef sta newCont \\<Longrightarrow> cont \\<noteq> newCont \\<Longrightarrow> reduce\"\n  apply (simp only:reduceContractUntilQuiescent.simps)\n  apply (simp only:reductionLoop.simps)\n  apply (cases \"reduceContractStep si sta cont\")\n  apply (simp only:ReduceStepResult.case Let_def)\n  using reductionLoop_reduce_monotonic apply blast\n   apply simp\n  by auto\n\n\nend\n", "meta": {"author": "input-output-hk", "repo": "marlowe", "sha": "d2f7b3108894b7c3169c71214f1a2772716544bf", "save_path": "github-repos/isabelle/input-output-hk-marlowe", "path": "github-repos/isabelle/input-output-hk-marlowe/marlowe-d2f7b3108894b7c3169c71214f1a2772716544bf/isabelle/Core/QuiescentResult.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6406358548398982, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.28789703453908516}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |               December 2004               |\n            |                   July 2005 (modified)    |\n            |              September 2005 (modified)    |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |                October 2005  (modified)   |\n            |               November 2005  (modified)   |\n            |                  April 2006  (modified)   |\n            |                  March 2007  (modified)   |\n            |                 August 2007  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2008         |\n            |                   June 2008  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2009-2       |\n            |                October 2010  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2016         |\n            |                    May 2016  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory CSP_F_contraction\nimports CSP_F_domain CSP_T_contraction\nbegin\n\n(*****************************************************************\n\n         1. contraction failuresfun\n         2. contraction failuresFun\n         3. contraction [[ ]]Ffun\n         4. contraction [[ ]]FFun\n\n *****************************************************************)\n\n(*=============================================================*\n |                      traces fstF                            |\n *=============================================================*)\n\nlemma non_expanding_traces_fstF:\n   \"noHide P ==> non_expanding (%M. traces P (fstF o M))\"\napply (subgoal_tac \"(%M. traces P (fstF o M)) = (traces P) o (op o fstF)\")\napply (simp)\napply (rule compo_non_expand)\napply (simp add: non_expanding_traces)\napply (simp add: non_expanding_op_fstF)\napply (simp add: fun_eq_iff)\ndone\n\nlemma contraction_alpha_traces_fstF:\n   \"guarded P ==> contraction_alpha (%M. traces P (fstF o M)) (1/2)\"\napply (subgoal_tac \"(%M. traces P (fstF o M)) = (traces P) o (op o fstF)\")\napply (simp)\napply (rule compo_contra_alpha_non_expand)\napply (simp add: contraction_alpha_traces)\napply (simp add: non_expanding_op_fstF)\napply (simp add: fun_eq_iff)\ndone\n\n(*--------------------------------*\n |        STOP,SKIP,DIV           |\n *--------------------------------*)\n\n(*** STOP ***)\n\nlemma map_alpha_failures_STOP: \n  \"0 <= alpha ==> map_alpha (failures (STOP)) alpha\"\nby (simp add: failures_iff map_alpha_Constant)\n\nlemma non_expanding_failures_STOP: \n  \"non_expanding (failures (STOP))\"\nby (simp add: non_expanding_def map_alpha_failures_STOP)\n\nlemma contraction_alpha_failures_STOP: \n  \"[| 0 <= alpha ; 1 > alpha |] ==> contraction_alpha (failures (STOP)) alpha\"\nby (simp add: failures_iff contraction_alpha_Constant)\n\n(*** SKIP ***)\n\nlemma map_alpha_failures_SKIP: \n  \"0 <= alpha ==> map_alpha (failures (SKIP)) alpha\"\nby (simp add: failures_iff map_alpha_Constant)\n\nlemma non_expanding_failures_SKIP: \n  \"non_expanding (failures (SKIP))\"\nby (simp add: non_expanding_def map_alpha_failures_SKIP)\n\nlemma contraction_alpha_failures_SKIP: \n  \"[| 0 <= alpha ; 1 > alpha |] ==> contraction_alpha (failures (SKIP)) alpha\"\nby (simp add: failures_iff contraction_alpha_Constant)\n\n(*** DIV ***)\n\nlemma map_alpha_failures_DIV: \n  \"0 <= alpha ==> map_alpha (failures (DIV)) alpha\"\nby (simp add: failures_iff map_alpha_Constant)\n\nlemma non_expanding_failures_DIV: \n  \"non_expanding (failures (DIV))\"\nby (simp add: non_expanding_def map_alpha_failures_DIV)\n\nlemma contraction_alpha_failures_DIV: \n  \"[| 0 <= alpha ; 1 > alpha |] ==> contraction_alpha (failures (DIV)) alpha\"\nby (simp add: failures_iff contraction_alpha_Constant)\n\n(*--------------------------------*\n |          Act_prefix            |\n *--------------------------------*)\n\nlemma contraction_half_failures_Act_prefix_lm: \n   \"distance (failures (a -> P) M1, failures (a -> Q) M2) * 2\n    = distance (failures P M1, failures Q M2)\"\napply (rule sym)\napply (simp add: to_distance_rs)\napply (rule rest_Suc_dist_half[simplified])\napply (rule allI)\napply (simp add: rest_setF_eq_iff)\napply (rule iffI)\n\n (* => *)\n apply (intro allI)\n apply (simp add: in_failures)\n apply (rule iffI)\n\n  (* => *)\n  apply (elim conjE exE disjE)\n   apply (simp_all)\n   apply (drule_tac x=\"sa\" in spec)\n   apply (drule_tac x=\"X\" in spec)\n   apply (simp)\n\n   apply (drule_tac x=\"sa\" in spec)\n   apply (drule_tac x=\"X\" in spec)\n   apply (simp)\n   apply (erule iffE, simp)\n   apply (insert trace_last_nil_or_unnil)\n   apply (drule_tac x=\"sa\" in spec)\n   apply (erule disjE, simp)\n   apply (elim conjE exE)\n   apply (simp add: appt_assoc_sym)\n   apply (drule mp, fast)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (simp)\n\n  (* <= *)\n  apply (elim conjE exE disjE)\n   apply (simp_all)\n   apply (drule_tac x=\"sa\" in spec)\n   apply (drule_tac x=\"X\" in spec)\n   apply (simp)\n\n   apply (drule_tac x=\"sa\" in spec)\n   apply (drule_tac x=\"X\" in spec)\n   apply (simp)\n   apply (erule iffE, simp)\n   apply (drule_tac x=\"sa\" in spec)\n   apply (erule disjE, simp)\n   apply (elim conjE exE)\n   apply (simp add: appt_assoc_sym)\n   apply (drule mp, fast)\n   apply (simp)\n\n (* <= *)\n apply (intro allI)\n apply (drule_tac x=\"<Ev a> ^^^ s\" in spec)\n apply (drule_tac x=\"X\" in spec)\n apply (simp add: in_failures)\n apply (rule iffI)\n\n  (* => *)\n  apply (elim conjE exE disjE)\n   apply (simp)\n   apply (erule iffE, simp)\n   apply (simp add: appt_assoc_sym)\n   apply (drule mp, force)\n   apply (force)\n\n  (* <= *)\n  apply (elim conjE exE disjE)\n   apply (simp)\n   apply (erule iffE, simp)\n   apply (simp add: appt_assoc_sym)\n   apply (drule mp, force)\n   apply (force)\ndone\n\n(***  contraction_half ***)\n\nlemma contraction_half_failures_Act_prefix: \n \"non_expanding (failures P)\n  ==> contraction_alpha (failures (a -> P)) (1 / 2)\"\napply (simp add: contraction_alpha_def non_expanding_def map_alpha_def)\napply (intro allI)\napply (drule_tac x=\"x\" in spec)\napply (drule_tac x=\"y\" in spec)\napply (simp add: contraction_half_failures_Act_prefix_lm)\ndone\n\n(***  contraction ***)\n\nlemma contraction_failures_Act_prefix: \n \"non_expanding (failures P)\n  ==> contraction (failures (a -> P))\"\napply (simp add: contraction_def)\napply (rule_tac x=\"1/2\" in exI)\nby (simp add: contraction_half_failures_Act_prefix)\n\n(*** non_expanding ***)\n\nlemma non_expanding_failures_Act_prefix: \n \"non_expanding (failures P)\n  ==> non_expanding (failures (a -> P))\"\napply (rule contraction_non_expanding)\nby (simp add: contraction_failures_Act_prefix)\n\n(*--------------------------------*\n |        Ext_pre_choice          |\n *--------------------------------*)\n\n(*** rest_setF (subset) ***)\n\nlemma Ext_pre_choice_Act_prefix_rest_setF_sub:\n   \"[| ALL a : X.\n         failures (a -> Pf a) M1 .|. n <= failures (a -> Qf a) M2 .|. n |]\n    ==> failures (? a:X -> Pf a) M1 .|. n <=\n        failures (? a:X -> Qf a) M2 .|. n\"\napply (simp add: subsetF_iff)\napply (intro allI impI)\napply (simp add: in_rest_setF)\napply (simp add: in_failures)\napply (elim conjE exE disjE, simp_all)\n\n apply (drule_tac x=\"a\" in bspec, simp)\n apply (drule_tac x=\"<Ev a> ^^^ sa\" in spec)\n apply (drule_tac x=\"Xa\" in spec)\n apply (simp)\n\n apply (drule_tac x=\"a\" in bspec, simp)\n apply (drule_tac x=\"s' ^^^ <Tick>\" in spec)\n apply (drule_tac x=\"Xa\" in spec)\n apply (auto)\ndone\n\n(*** rest_setF (equal) ***)\n\nlemma Ext_pre_choice_Act_prefix_rest_setF:\n   \"[| ALL a : X.\n         failures (a -> Pf a) M1 .|. n = failures (a -> Qf a) M2 .|. n |]\n    ==> failures (? a:X -> Pf a) M1 .|. n =\n        failures (? a:X -> Qf a) M2 .|. n\"\napply (rule order_antisym)\nby (simp_all add: Ext_pre_choice_Act_prefix_rest_setF_sub)\n\n(*** distF lemma ***)\n\nlemma Ext_pre_choice_Act_prefix_distF_nonempty:\n\"[| X ~= {} ; PQs = {(failures (a -> Pf a) M1, failures (a -> Qf a) M2)|a. a : X} |]\n ==> (EX PQ. PQ:PQs & \n             distance(failures (? a:X -> Pf a) M1, failures (? a:X -> Qf a) M2)\n          <= distance(fst PQ, snd PQ))\"\napply (simp only: to_distance_rs)\napply (rule rest_to_dist_pair)\napply (force)\n\napply (intro allI impI)\napply (rule Ext_pre_choice_Act_prefix_rest_setF)\napply (rule ballI)\napply (simp)\napply (drule_tac x=\"failures (a -> Pf a) M1\" in spec)\napply (drule_tac x=\"failures (a -> Qf a) M2\" in spec)\nby (auto)\n\n(*** contraction lemma ***)\n\nlemma contraction_half_failures_Ext_pre_choice_lm:\n  \"[| X ~= {} ; ALL a. distance (failures (Pf a) M1, failures (Qf a) M2)\n                    <= distance (x1, x2) |]\n    ==> distance (failures (? a:X -> Pf a) M1, failures (? a:X -> Qf a) M2) * 2 \n     <= distance (x1, x2)\"\napply (insert Ext_pre_choice_Act_prefix_distF_nonempty\n       [of X \"{(failures (a -> Pf a) M1, failures (a -> Qf a) M2) |a. a : X}\" \n           Pf M1 Qf M2])\napply (simp)\napply (elim conjE exE)\napply (simp)\napply (subgoal_tac \n    \"distance (failures (aa -> Pf aa) M1, failures (aa -> Qf aa) M2) * 2\n   = distance (failures (Pf aa) M1, failures (Qf aa) M2)\")\napply (drule_tac x=\"aa\" in spec)\napply (force)\nby (simp add: contraction_half_failures_Act_prefix_lm)\n\n(*** contraction_half ***)\n\nlemma contraction_half_failures_Ext_pre_choice:\n \"ALL a. non_expanding (failures (Pf a))\n  ==> contraction_alpha (failures (? a:X -> (Pf a))) (1 / 2)\"\napply (simp add: contraction_alpha_def non_expanding_def map_alpha_def)\napply (case_tac \"X = {}\")\napply (simp add: failures_iff)\nby (simp add: contraction_half_failures_Ext_pre_choice_lm)\n\n(*** Ext_pre_choice_evalT_contraction ***)\n\nlemma contraction_failures_Ext_pre_choice:\n \"ALL a. non_expanding (failures (Pf a))\n  ==> contraction (failures (? a:X -> (Pf a)))\"\napply (simp add: contraction_def)\napply (rule_tac x=\"1/2\" in exI)\nby (simp add: contraction_half_failures_Ext_pre_choice)\n\n(*** Ext_pre_choice_evalT_non_expanding ***)\n\nlemma non_expanding_failures_Ext_pre_choice:\n \"ALL a. non_expanding (failures (Pf a))\n  ==> non_expanding (failures (? a:X -> (Pf a)))\"\napply (rule contraction_non_expanding)\nby (simp add: contraction_failures_Ext_pre_choice)\n\n(*--------------------------------*\n |          Ext_choice            |\n *--------------------------------*)\n\n(*** rest_domT (subset) ***)\n\nlemma Ext_choice_rest_setF_sub:\n   \"[| traces P1 (fstF o M1) .|. n <= traces P2 (fstF o M2) .|. n ;\n       traces Q1 (fstF o M1) .|. n <= traces Q2 (fstF o M2) .|. n ;\n       failures P1 M1 .|. n <= failures P2 M2 .|. n ;\n       failures Q1 M1 .|. n <= failures Q2 M2 .|. n  |]\n    ==> failures (P1 [+] Q1) M1 .|. n <= failures (P2 [+] Q2) M2 .|. n\"\napply (simp add: subdomT_iff subsetF_iff)\napply (intro allI impI)\napply (simp add: in_rest_domT)\napply (simp add: in_rest_setF)\napply (simp add: in_failures)\napply (elim conjE exE disjE, simp_all)\n\n apply (rotate_tac 2)\n apply (drule_tac x=\"s' ^^^ <Tick>\" in spec)\n apply (drule_tac x=\"X\" in spec)\n apply (drule mp, simp, fast)\n apply (simp)\n\n apply (rotate_tac 3)\n apply (drule_tac x=\"s' ^^^ <Tick>\" in spec)\n apply (drule_tac x=\"X\" in spec)\n apply (drule mp, simp, fast)\n apply (simp)\ndone\n\n(*** rest_setF (equal) ***)\n\nlemma Ext_choice_rest_setF:\n   \"[| traces P1 (fstF o M1) .|. n = traces P2 (fstF o M2) .|. n ;\n       traces Q1 (fstF o M1) .|. n = traces Q2 (fstF o M2) .|. n ;\n       failures P1 M1 .|. n = failures P2 M2 .|. n ;\n       failures Q1 M1 .|. n = failures Q2 M2 .|. n  |]\n    ==> failures (P1 [+] Q1) M1 .|. n = failures (P2 [+] Q2) M2 .|. n\"\napply (rule order_antisym)\nby (simp_all add: Ext_choice_rest_setF_sub)\n\n(*** distF lemma ***)\n\nlemma Ext_choice_distF:\n\"[| PQTs = {(traces P1 (fstF o M1), traces P2 (fstF o M2)), \n            (traces Q1 (fstF o M1), traces Q2 (fstF o M2))} ;\n    PQFs = {(failures P1 M1, failures P2 M2), (failures Q1 M1, failures Q2 M2)} |]\n ==> (EX PQ. PQ:PQTs & \n             distance(failures (P1 [+] Q1) M1, failures (P2 [+] Q2) M2)\n          <= distance((fst PQ), (snd PQ))) |\n     (EX PQ. PQ:PQFs & \n             distance(failures (P1 [+] Q1) M1, failures (P2 [+] Q2) M2)\n          <= distance((fst PQ), (snd PQ)))\"\napply (simp only: to_distance_rs)\napply (rule rest_to_dist_pair_two)\napply (simp_all)\nby (auto intro: Ext_choice_rest_setF)\n\n(*** map_alpha F lemma ***)\n\nlemma map_alpha_failures_Ext_choice_lm:\n  \"[| distance (traces P1 (fstF o M1), traces P2 (fstF o M2))\n       <= alpha * distance (x1, x2) ;\n      distance (traces Q1 (fstF o M1), traces Q2 (fstF o M2))\n       <= alpha * distance (x1, x2) ;\n      distance (failures P1 M1, failures P2 M2) <= alpha * distance (x1, x2) ;\n      distance (failures Q1 M1, failures Q2 M2) <= alpha * distance (x1, x2) |]\n    ==> distance (failures (P1 [+] Q1) M1, failures (P2 [+] Q2) M2)\n     <= alpha * distance (x1, x2)\"\napply (insert Ext_choice_distF\n       [of \"{(traces P1 (fstF o M1), traces P2 (fstF o M2)), \n             (traces Q1 (fstF o M1), traces Q2 (fstF o M2))}\"\n             P1 M1 P2 M2 Q1 Q2\n           \"{(failures P1 M1, failures P2 M2), (failures Q1 M1, failures Q2 M2)}\"])\nby (auto)\n\n(*** map_alpha ***)\n\nlemma map_alpha_failures_Ext_choice:\n \"[| map_alpha (%M. traces P (fstF o M)) alpha ; \n     map_alpha (%M. traces Q (fstF o M)) alpha ;\n     map_alpha (failures P) alpha ;\n     map_alpha (failures Q) alpha |]\n  ==> map_alpha (failures (P [+] Q)) alpha\"\napply (simp add: map_alpha_def)\napply (intro allI)\napply (erule conjE)\napply (drule_tac x=\"x\" in spec)\napply (drule_tac x=\"x\" in spec)\napply (drule_tac x=\"x\" in spec)\napply (drule_tac x=\"x\" in spec)\napply (drule_tac x=\"y\" in spec)\napply (drule_tac x=\"y\" in spec)\napply (drule_tac x=\"y\" in spec)\napply (drule_tac x=\"y\" in spec)\nby (simp add: map_alpha_failures_Ext_choice_lm)\n\n(*** non_expanding ***)\n\nlemma non_expanding_failures_Ext_choice:\n \"[| non_expanding (%M. traces P (fstF o M)) ;\n     non_expanding (%M. traces Q (fstF o M)) ;\n     non_expanding (failures P) ; non_expanding (failures Q) |]\n  ==> non_expanding (failures (P [+] Q))\"\nby (simp add: non_expanding_def map_alpha_failures_Ext_choice)\n\n(*** contraction ***)\n\nlemma contraction_alpha_failures_Ext_choice:\n \"[| contraction_alpha (%M. traces P (fstF o M)) alpha ;\n     contraction_alpha (%M. traces Q (fstF o M)) alpha ;\n     contraction_alpha (failures P) alpha ; \n     contraction_alpha (failures Q) alpha|]\n  ==> contraction_alpha (failures (P [+] Q)) alpha\"\nby (simp add: contraction_alpha_def map_alpha_failures_Ext_choice)\n\n(*--------------------------------*\n |          Int_choice            |\n *--------------------------------*)\n\n(*** rest_domT (subset) ***)\n\nlemma Int_choice_rest_setF_sub:\n   \"[| failures P1 M1 .|. n <= failures P2 M2 .|. n ;\n       failures Q1 M1 .|. n <= failures Q2 M2 .|. n  |]\n    ==> failures (P1 |~| Q1) M1 .|. n <= failures (P2 |~| Q2) M2 .|. n\"\napply (simp add: subsetF_iff)\napply (intro allI impI)\napply (simp add: in_rest_setF)\napply (simp add: in_failures)\napply (elim disjE conjE exE)\nby (force)+\n\n(*** rest_setF (equal) ***)\n\nlemma Int_choice_rest_setF:\n   \"[| failures P1 M1 .|. n = failures P2 M2 .|. n ;\n       failures Q1 M1 .|. n = failures Q2 M2 .|. n  |]\n    ==> failures (P1 |~| Q1) M1 .|. n = failures (P2 |~| Q2) M2 .|. n\"\napply (rule order_antisym)\nby (simp_all add: Int_choice_rest_setF_sub)\n\n(*** distF lemma ***)\n\nlemma Int_choice_distF:\n\"PQs = {(failures P1 M1, failures P2 M2), (failures Q1 M1, failures Q2 M2)}\n ==> (EX PQ. PQ:PQs & \n             distance(failures (P1 |~| Q1) M1, failures (P2 |~| Q2) M2)\n          <= distance((fst PQ), (snd PQ)))\"\napply (simp only: to_distance_rs)\napply (rule rest_to_dist_pair)\nby (auto intro: Int_choice_rest_setF)\n\n(*** map_alpha F lemma ***)\n\nlemma map_alpha_failures_Int_choice_lm:\n  \"[| distance (failures P1 M1, failures P2 M2) <= alpha * distance (x1, x2) ;\n      distance (failures Q1 M1, failures Q2 M2) <= alpha * distance (x1, x2) |]\n    ==> distance (failures (P1 |~| Q1) M1, failures (P2 |~| Q2) M2)\n     <= alpha * distance (x1, x2)\"\napply (insert Int_choice_distF\n       [of \"{(failures P1 M1, failures P2 M2), \n             (failures Q1 M1, failures Q2 M2)}\" P1 M1 P2 M2 Q1 Q2])\nby (auto)\n\n(*** map_alpha ***)\n\nlemma map_alpha_failures_Int_choice:\n \"[| map_alpha (failures P) alpha ; map_alpha (failures Q) alpha |]\n  ==> map_alpha (failures (P |~| Q)) alpha\"\napply (simp add: map_alpha_def)\napply (intro allI)\napply (erule conjE)\napply (drule_tac x=\"x\" in spec)\napply (drule_tac x=\"x\" in spec)\napply (drule_tac x=\"y\" in spec)\napply (drule_tac x=\"y\" in spec)\nby (simp add: map_alpha_failures_Int_choice_lm)\n\n(*** non_expanding ***)\n\nlemma non_expanding_failures_Int_choice:\n \"[| non_expanding (failures P) ; non_expanding (failures Q) |]\n  ==> non_expanding (failures (P |~| Q))\"\nby (simp add: non_expanding_def map_alpha_failures_Int_choice)\n\n(*** contraction ***)\n\nlemma contraction_alpha_failures_Int_choice:\n \"[| contraction_alpha (failures P) alpha ; \n     contraction_alpha (failures Q) alpha|]\n  ==> contraction_alpha (failures (P |~| Q)) alpha\"\nby (simp add: contraction_alpha_def map_alpha_failures_Int_choice)\n\n(*--------------------------------*\n |        Rep_int_choice          |\n *--------------------------------*)\n\n(*** rest_setF (subset) ***)\n\nlemma Rep_int_choice_rest_setF_sub:\n   \"[| ALL c : sumset C.\n         failures (Pf c) M1 .|. n <= failures (Qf c) M2 .|. n |]\n    ==> failures (!! :C .. Pf) M1 .|. n <=\n        failures (!! :C .. Qf) M2 .|. n\"\napply (simp add: subsetF_iff)\napply (intro allI impI)\napply (simp add: in_rest_setF)\napply (simp add: in_failures)\napply (elim conjE bexE)\napply (rule_tac x=\"c\" in bexI)\nby (auto)\n\n(*** rest_setF (equal) ***)\n\nlemma Rep_int_choice_rest_setF:\n   \"[| ALL c : sumset C.\n         failures (Pf c) M1 .|. n = failures (Qf c) M2 .|. n |]\n    ==> failures (!! :C .. Pf) M1 .|. n =\n        failures (!! :C .. Qf) M2 .|. n\"\napply (rule order_antisym)\nby (simp_all add: Rep_int_choice_rest_setF_sub)\n\n(*** distF lemma ***)\n\nlemma Rep_int_choice_distF_nonempty:\n\"[| sumset C ~= {} ; \n    PQs = {(failures (Pf c) M1, failures (Qf c) M2)|c. c : sumset C} |]\n ==> (EX PQ. PQ:PQs & \n             distance(failures (!! :C .. Pf) M1, failures (!! :C .. Qf) M2)\n          <= distance(fst PQ, snd PQ))\"\napply (simp only: to_distance_rs)\napply (rule rest_to_dist_pair)\napply (fast)\n\napply (intro allI impI)\napply (rule Rep_int_choice_rest_setF)\nby (auto)\n\n(*** map_alpha F lemma ***)\n\nlemma map_alpha_failures_Rep_int_choice_lm:\n\"[| sumset C ~= {} ; \n    ALL c. distance (failures (Pf c) M1, failures (Qf c) M2) \n                  <= alpha * distance (x1, x2) |]\n ==> distance(failures (!! :C .. Pf) M1, failures (!! :C .. Qf) M2)\n  <= alpha * distance(x1, x2)\"\napply (insert Rep_int_choice_distF_nonempty)\napply (insert Rep_int_choice_distF_nonempty\n       [of C \"{(failures (Pf c) M1, failures (Qf c) M2)|c. c : sumset C}\"\n           Pf M1 Qf M2])\napply (simp)\napply (elim conjE exE, simp)\napply (drule_tac x=\"c\" in spec)\nby (force)\n\n(*** map_alpha ***)\n\nlemma map_alpha_failures_Rep_int_choice:\n \"ALL c. map_alpha (failures (Pf c)) alpha\n  ==> map_alpha (failures (!! :C .. Pf)) alpha\"\napply (simp add: map_alpha_def)\napply (case_tac \"sumset C = {}\")\n apply (simp add: failures_iff)\n(* apply (simp add: real_mult_order_eq) *)\napply (simp add: map_alpha_failures_Rep_int_choice_lm)\ndone\n\n(*** non_expanding ***)\n\nlemma non_expanding_failures_Rep_int_choice:\n \"ALL c. non_expanding (failures (Pf c))\n  ==> non_expanding (failures (!! :C .. Pf))\"\nby (simp add: non_expanding_def map_alpha_failures_Rep_int_choice)\n\n(*** Rep_int_choice_evalT_contraction_alpha ***)\n\nlemma contraction_alpha_failures_Rep_int_choice:\n \"ALL c. contraction_alpha (failures (Pf c)) alpha \n     ==> contraction_alpha  (failures (!! :C .. Pf)) alpha\"\nby (simp add: contraction_alpha_def map_alpha_failures_Rep_int_choice)\n\n(*--------------------------------*\n |              IF                |\n *--------------------------------*)\n\n(*** rest_setF (subset) ***)\n\nlemma IF_rest_setF_sub:\n   \"[| failures P1 M1 .|. n <= failures P2 M2 .|. n ;\n       failures Q1 M1 .|. n <= failures Q2 M2 .|. n  |]\n    ==> failures (IF b THEN P1 ELSE Q1) M1 .|. n <= \n        failures (IF b THEN P2 ELSE Q2) M2 .|. n\"\napply (simp add: subsetF_iff)\napply (intro allI impI)\napply (simp add: in_rest_setF)\napply (simp add: in_failures)\ndone\n\n(*** rest_setF (equal) ***)\n\nlemma IF_rest_setF:\n   \"[| failures P1 M1 .|. n = failures P2 M2 .|. n ;\n       failures Q1 M1 .|. n = failures Q2 M2 .|. n  |]\n    ==> failures (IF b THEN P1 ELSE Q1) M1 .|. n = \n        failures (IF b THEN P2 ELSE Q2) M2 .|. n\"\napply (rule order_antisym)\nby (simp_all add: IF_rest_setF_sub)\n\n(*** distF lemma ***)\n\nlemma IF_distF:\n   \"PQs = {(failures P1 M1, failures P2 M2), (failures Q1 M1, failures Q2 M2)}\n    ==> (EX PQ. PQ:PQs & \n             distance(failures (IF b THEN P1 ELSE Q1) M1,\n                      failures (IF b THEN P2 ELSE Q2) M2)\n          <= distance((fst PQ), (snd PQ)))\"\napply (simp only: to_distance_rs)\napply (rule rest_to_dist_pair)\nby (auto intro: IF_rest_setF)\n\n(*** map_alpha F lemma ***)\n\nlemma map_alpha_failures_IF_lm:\n  \"[| distance (failures P1 M1, failures P2 M2) <= alpha * distance (x1, x2) ;\n      distance (failures Q1 M1, failures Q2 M2) <= alpha * distance (x1, x2) |]\n    ==> distance(failures (IF b THEN P1 ELSE Q1) M1,\n                 failures (IF b THEN P2 ELSE Q2) M2)\n     <= alpha * distance (x1, x2)\"\napply (insert IF_distF\n       [of \"{(failures P1 M1, failures P2 M2), \n             (failures Q1 M1, failures Q2 M2)}\"P1 M1 P2 M2 Q1 Q2 b])\nby (auto)\n\n(*** map_alpha ***)\n\nlemma map_alpha_failures_IF:\n \"[| map_alpha (failures P) alpha ; map_alpha (failures Q) alpha |]\n  ==> map_alpha (failures (IF b THEN P ELSE Q)) alpha\"\napply (simp add: map_alpha_def)\napply (intro allI)\napply (erule conjE)\napply (drule_tac x=\"x\" in spec)\napply (drule_tac x=\"x\" in spec)\napply (drule_tac x=\"y\" in spec)\napply (drule_tac x=\"y\" in spec)\nby (simp add: map_alpha_failures_IF_lm)\n\n(*** non_expanding ***)\n\nlemma non_expanding_failures_IF:\n \"[| non_expanding (failures P) ; non_expanding (failures Q) |]\n  ==> non_expanding (failures (IF b THEN P ELSE Q))\"\nby (simp add: non_expanding_def map_alpha_failures_IF)\n\n(*** contraction_alpha ***)\n\nlemma contraction_alpha_failures_IF:\n \"[| contraction_alpha (failures P) alpha ; contraction_alpha (failures Q) alpha|]\n  ==> contraction_alpha (failures (IF b THEN P ELSE Q)) alpha\"\nby (simp add: contraction_alpha_def map_alpha_failures_IF)\n\n(*--------------------------------*\n |           Parallel             |\n *--------------------------------*)\n\n(*** rest_setF (subset) ***)\n\nlemma Parallel_rest_setF_sub:\n   \"[| failures P1 M1 .|. n <= failures P2 M2 .|. n ;\n       failures Q1 M1 .|. n <= failures Q2 M2 .|. n  |]\n    ==> failures (P1 |[X]| Q1) M1 .|. n <= failures (P2 |[X]| Q2) M2 .|. n\"\napply (simp add: subsetF_iff)\napply (intro allI impI)\napply (simp add: in_rest_setF)\napply (simp add: in_failures)\napply (elim conjE exE)\n\napply (rule_tac x=\"Y\" in exI)\napply (rule_tac x=\"Z\" in exI)\napply (simp)\napply (rule_tac x=\"sa\" in exI)\napply (rule_tac x=\"t\" in exI)\napply (simp)\napply (drule_tac x=\"sa\" in spec)\napply (drule_tac x=\"t\" in spec)\napply (drule_tac x=\"Y\" in spec)\napply (drule_tac x=\"Z\" in spec)\n\napply (erule disjE, simp)    (* lengtht s < n *)\napply (erule par_tr_lengthtE)\napply (simp)\n\napply (elim conjE exE, simp) (* lengtht s = n *)\napply (simp add: par_tr_last)\napply (elim conjE exE, simp)\napply (erule par_tr_lengthtE)\napply (case_tac \"Suc (lengtht s'a) < n\", simp)\n apply (case_tac \"Suc (lengtht t') < n\", simp)\n apply (case_tac \"Suc (lengtht t') = n\", simp)\n apply (drule mp, force)\n apply (simp)\n apply (force)  (* contradict *)\n\n apply (case_tac \"Suc (lengtht t') < n\", simp)\n apply (drule mp)\n  apply (rule_tac x=\"s'a\" in exI, simp)\n apply (simp)\n\n apply (case_tac \"Suc (lengtht t') = n\", simp)\n apply (drule mp)\n  apply (rule_tac x=\"s'a\" in exI, simp)\n apply (drule mp)\n  apply (rule_tac x=\"t'\" in exI, simp)\n apply (simp)\n apply (force)  (* contradict *)\ndone\n\n(*** rest_setF (equal) ***)\n\nlemma Parallel_rest_setF:\n   \"[| failures P1 M1 .|. n = failures P2 M2 .|. n ;\n       failures Q1 M1 .|. n = failures Q2 M2 .|. n  |]\n    ==> failures (P1 |[X]| Q1) M1 .|. n = failures (P2 |[X]| Q2) M2 .|. n\"\napply (rule order_antisym)\nby (simp_all add: Parallel_rest_setF_sub)\n\n(*** distF lemma ***)\n\nlemma Parallel_distF:\n\"PQs = {(failures P1 M1, failures P2 M2), (failures Q1 M1, failures Q2 M2)}\n ==> (EX PQ. PQ:PQs & \n             distance(failures (P1 |[X]| Q1) M1, failures (P2 |[X]| Q2) M2)\n          <= distance((fst PQ), (snd PQ)))\"\napply (simp only: to_distance_rs)\napply (rule rest_to_dist_pair)\nby (auto intro: Parallel_rest_setF)\n\n(*** map_alpha F lemma ***)\n\nlemma map_alpha_failures_Parallel_lm:\n  \"[| distance (failures P1 M1, failures P2 M2) <= alpha * distance (x1, x2) ;\n      distance (failures Q1 M1, failures Q2 M2) <= alpha * distance (x1, x2) |]\n    ==> distance (failures (P1 |[X]| Q1) M1, failures (P2 |[X]| Q2) M2)\n     <= alpha * distance (x1, x2)\"\napply (insert Parallel_distF\n       [of \"{(failures P1 M1, failures P2 M2), \n             (failures Q1 M1, failures Q2 M2)}\" P1 M1 P2 M2 Q1 Q2 X])\nby (auto)\n\n(*** map_alpha ***)\n\nlemma map_alpha_failures_Parallel:\n \"[| map_alpha (failures P) alpha ; map_alpha (failures Q) alpha |]\n  ==> map_alpha (failures (P |[X]| Q)) alpha\"\napply (simp add: map_alpha_def)\napply (intro allI)\napply (erule conjE)\napply (drule_tac x=\"x\" in spec)\napply (drule_tac x=\"x\" in spec)\napply (drule_tac x=\"y\" in spec)\napply (drule_tac x=\"y\" in spec)\nby (simp add: map_alpha_failures_Parallel_lm)\n\n(*** non_expanding ***)\n\nlemma non_expanding_failures_Parallel:\n \"[| non_expanding (failures P) ; non_expanding (failures Q) |]\n  ==> non_expanding (failures (P|[X]| Q))\"\nby (simp add: non_expanding_def map_alpha_failures_Parallel)\n\n(*** contraction_alpha ***)\n\nlemma contraction_alpha_failures_Parallel:\n \"[| contraction_alpha (failures P) alpha ; \n     contraction_alpha (failures Q) alpha |]\n  ==> contraction_alpha (failures (P |[X]| Q)) alpha\"\nby (simp add: contraction_alpha_def map_alpha_failures_Parallel)\n\n(*--------------------------------*\n |            Hiding              |\n *--------------------------------*)\n\n(* cms rules for Hiding is not necessary \n   because processes are guarded. *)\n\n(*--------------------------------*\n |           Renaming             |\n *--------------------------------*)\n\n(*** rest_setF (subset) ***)\n\nlemma Renaming_rest_setF_sub:\n   \"failures P M1 .|. n <= failures Q M2 .|. n\n    ==> failures (P [[r]]) M1 .|. n <= failures (Q [[r]]) M2 .|. n\"\napply (simp add: subsetF_iff)\napply (intro allI impI)\napply (simp add: in_rest_setF)\napply (simp add: in_failures)\napply (elim conjE exE)\n\napply (rule_tac x=\"sa\" in exI)\napply (drule_tac x=\"sa\" in spec)\napply (drule_tac x=\"[[r]]inv X\" in spec)\napply (simp)\n\napply (erule disjE)\napply (simp add: ren_tr_lengtht)\n\napply (elim conjE exE)\napply (simp add: ren_tr_lengtht)\napply (simp add: ren_tr_appt_decompo_right)\napply (elim conjE exE, simp)\nby (fast)\n\n(*** rest_setF (equal) ***)\n\nlemma Renaming_rest_setF:\n   \"failures P M1 .|. n = failures Q M2 .|. n\n    ==> failures (P [[r]]) M1 .|. n = failures (Q [[r]]) M2 .|. n\"\napply (rule order_antisym)\nby (simp_all add: Renaming_rest_setF_sub)\n\n(*** distF lemma ***)\n\nlemma Renaming_distF:\n     \"distance(failures (P [[r]]) M1, failures (Q [[r]]) M2) <= \n      distance(failures P M1, failures Q M2)\"\napply (simp only: to_distance_rs)\napply (rule rest_distance_subset)\nby (auto intro: Renaming_rest_setF)\n\n(*** map_alphaT lemma ***)\n\nlemma map_alpha_failures_Renaming_lm:\n  \"distance(failures P M1, failures Q M2) <= alpha * distance (x1, x2)\n    ==> distance(failures (P [[r]]) M1, failures (Q [[r]]) M2)\n     <= alpha * distance(x1, x2)\"\napply (insert Renaming_distF[of P r M1 Q M2])\nby (simp)\n\n(*** map_alpha ***)\n\nlemma map_alpha_failures_Renaming:\n \"map_alpha (failures P) alpha\n  ==> map_alpha (failures (P [[r]])) alpha\"\napply (simp add: map_alpha_def)\napply (intro allI)\napply (erule conjE)\napply (drule_tac x=\"x\" in spec)\napply (drule_tac x=\"y\" in spec)\nby (simp add: map_alpha_failures_Renaming_lm)\n\n(*** non_expanding ***)\n\nlemma non_expanding_failures_Renaming:\n \"non_expanding (failures P)\n  ==> non_expanding (failures (P [[r]]))\"\nby (simp add: non_expanding_def map_alpha_failures_Renaming)\n\n(*** contraction_alpha ***)\n\nlemma contraction_alpha_failures_Renaming:\n \"contraction_alpha (failures P) alpha\n  ==> contraction_alpha (failures (P [[r]])) alpha\"\nby (simp add: contraction_alpha_def map_alpha_failures_Renaming)\n\n(*--------------------------------*\n |           Seq_compo            |\n *--------------------------------*)\n\n(*** rest_setF (subset) ***)\n\nlemma Seq_compo_rest_setF_sub:\n   \"[| traces P1 (fstF o M1) .|. n <= traces P2 (fstF o M2) .|. n ;\n       failures P1 M1 .|. n <= failures P2 M2 .|. n ;\n       failures Q1 M1 .|. n <= failures Q2 M2 .|. n  |]\n    ==> failures (P1 ;; Q1) M1 .|. n <= failures (P2 ;; Q2) M2 .|. n\"\napply (simp add: subsetF_iff)\napply (simp add: subdomT_iff)\napply (intro allI impI)\napply (simp add: in_rest_setF)\napply (simp add: in_rest_domT)\napply (simp add: in_failures)\napply (elim conjE exE disjE)\napply (simp_all)\n\n (* case 1 *)\n apply (rule disjI2)\n apply (rule_tac x=\"sa\" in exI)\n apply (rule_tac x=\"t\" in exI)\n apply (simp)\n\n (* case 2 *)\n apply (rule disjI2)\n apply (rule_tac x=\"sa\" in exI)\n apply (rule_tac x=\"t\" in exI)\n apply (simp)\n apply (drule_tac x=\" sa ^^^ <Tick>\" in spec)\n apply (simp)\n\n apply (insert trace_last_nil_or_unnil)\n apply (rotate_tac -1)\n apply (drule_tac x=\"t\" in spec)\n apply (erule disjE, simp)\n  apply (rotate_tac 2)\n  apply (drule sym)\n  apply (simp)\n\n  apply (elim conjE exE, simp)\n  apply (simp add: appt_assoc_sym)\n  apply (rotate_tac 1)\n  apply (drule_tac x=\"sb ^^^ <Tick>\" in spec)\n  apply (drule_tac x=\"X\" in spec, simp)\n  apply (elim conjE)\n\n  apply (case_tac \"Suc (lengtht sb) < n\", simp)\n  apply (case_tac \"Suc (lengtht sb) = n\", simp)\n  apply (drule mp, force)\n  apply (simp)\n  apply (force)\ndone\n\n(*** rest_setF (equal) ***)\n\nlemma Seq_compo_rest_setF:\n   \"[| traces P1 (fstF o M1) .|. n = traces P2 (fstF o M2) .|. n ;\n       failures P1 M1 .|. n = failures P2 M2 .|. n ;\n       failures Q1 M1 .|. n = failures Q2 M2 .|. n  |]\n    ==> failures (P1 ;; Q1) M1 .|. n = failures (P2 ;; Q2) M2 .|. n\"\napply (rule order_antisym)\nby (simp_all add: Seq_compo_rest_setF_sub)\n\n(*** distF lemma ***)\n\nlemma Seq_compo_distF:\n\"[| PQTs = {(traces P1 (fstF o M1), traces P2 (fstF o M2))} ;\n    PQFs = {(failures P1 M1, failures P2 M2), (failures Q1 M1, failures Q2 M2)} |]\n ==> (EX PQ. PQ:PQTs & \n             distance(failures (P1 ;; Q1) M1, failures (P2 ;; Q2) M2)\n          <= distance((fst PQ), (snd PQ))) |\n     (EX PQ. PQ:PQFs & \n             distance(failures (P1 ;; Q1) M1, failures (P2 ;; Q2) M2)\n          <= distance((fst PQ), (snd PQ)))\"\napply (simp only: to_distance_rs)\napply (rule rest_to_dist_pair_two)\nby (auto intro: Seq_compo_rest_setF)\n\n(*** map_alpha F lemma ***)\n\nlemma map_alpha_failures_Seq_compo_lm:\n  \"[| distance (traces P1 (fstF o M1), traces P2 (fstF o M2)) \n      <= alpha * distance (x1, x2) ;\n      distance (failures P1 M1, failures P2 M2) <= alpha * distance (x1, x2) ;\n      distance (failures Q1 M1, failures Q2 M2) <= alpha * distance (x1, x2) |]\n    ==> distance (failures (P1 ;; Q1) M1, failures (P2 ;; Q2) M2)\n     <= alpha * distance (x1, x2)\"\napply (insert Seq_compo_distF\n       [of \"{(traces P1 (fstF o M1), traces P2 (fstF o M2))}\" P1 M1 P2 M2\n           \"{(failures P1 M1, failures P2 M2), \n             (failures Q1 M1, failures Q2 M2)}\" Q1 Q2])\nby (auto)\n\n(*** map_alpha ***)\n\nlemma map_alpha_failures_Seq_compo:\n \"[| map_alpha (%M. traces P (fstF o M)) alpha ; \n     map_alpha (failures P) alpha ; map_alpha (failures Q) alpha |]\n  ==> map_alpha (failures (P ;; Q)) alpha\"\napply (simp add: map_alpha_def)\napply (intro allI)\napply (erule conjE)\napply (drule_tac x=\"x\" in spec)\napply (drule_tac x=\"x\" in spec)\napply (drule_tac x=\"x\" in spec)\napply (drule_tac x=\"y\" in spec)\napply (drule_tac x=\"y\" in spec)\napply (drule_tac x=\"y\" in spec)\nby (simp add: map_alpha_failures_Seq_compo_lm)\n\n(*** non_expanding ***)\n\nlemma non_expanding_failures_Seq_compo:\n \"[| non_expanding (%M. traces P (fstF o M)) ;\n     non_expanding (failures P) ; non_expanding (failures Q) |]\n  ==> non_expanding (failures (P ;; Q))\"\nby (simp add: non_expanding_def map_alpha_failures_Seq_compo)\n\n(*** contraction_alpha ***)\n\nlemma contraction_alpha_failures_Seq_compo:\n \"[| contraction_alpha (%M. traces P (fstF o M)) alpha ;\n     contraction_alpha (failures P) alpha ; \n     contraction_alpha (failures Q) alpha|]\n  ==> contraction_alpha (failures (P ;; Q)) alpha\"\nby (simp add: contraction_alpha_def map_alpha_failures_Seq_compo)\n\n(*--------------------------------*\n |       Seq_compo  (gSKIP)       |\n *--------------------------------*)\n\n(*** rest_setF (subset) ***)\n\nlemma gSKIP_Seq_compo_rest_setF_sub:\n   \"[| traces P1 (fstF o M1) .|. (Suc n) <= traces P2 (fstF o M2) .|. (Suc n) ;\n       failures P1 M1 .|. (Suc n) <= failures P2 M2 .|. (Suc n) ;\n       failures Q1 M1 .|. n <= failures Q2 M2 .|. n ;\n       <Tick> ~:t traces P1 (fstF o M1) ;\n       <Tick> ~:t traces P2 (fstF o M2) |]\n    ==> failures (P1 ;; Q1) M1 .|. (Suc n) <= failures (P2 ;; Q2) M2 .|. (Suc n)\"\napply (simp add: subsetF_iff)\napply (simp add: subdomT_iff)\napply (intro allI impI)\napply (simp add: in_rest_setF)\napply (simp add: in_rest_domT)\napply (simp add: in_failures)\napply (elim conjE exE disjE)\napply (simp_all)\n\n (* case 1 *)\n apply (insert trace_last_nil_or_unnil)\n apply (rotate_tac -1)\n apply (drule_tac x=\"sa\" in spec)\n apply (erule disjE)\n  apply (simp add: gSKIP_to_Tick_notin_traces)   (* sa = []t *)\n\n  apply (rule disjI2)                            (* sa ~= []t *)\n  apply (elim conjE exE, simp)\n  apply (rule_tac x=\"(sb ^^^ <a>)\" in exI)\n  apply (rule_tac x=\"t\" in exI)\n  apply (simp)\n\n (* case 2 *)\n apply (rotate_tac -1)\n apply (drule_tac x=\"t\" in spec)\n apply (erule disjE)   \n  apply (simp)           (* t = []t *)\n  apply (rotate_tac 5)\n  apply (drule sym)\n  apply (simp)           (* contradict noTick *)\n\n  apply (rule disjI2)    (* t ~= []t *)\n  apply (elim conjE exE, simp)\n  apply (simp add: appt_assoc_sym)\n  apply (rule_tac x=\"sa\" in exI)\n  apply (rule_tac x=\"sb ^^^ <Tick>\" in exI)\n  apply (simp add: appt_assoc)\n\n  apply (insert trace_last_nil_or_unnil)\n  apply (rotate_tac -1)\n  apply (drule_tac x=\"sa\" in spec)\n  apply (erule disjE)\n   apply (simp add: gSKIP_to_Tick_notin_traces)   (* sa = []t *)\n   apply (elim conjE exE, simp)\n                                                  (* i.e. lengtht sb < n *)\n   apply (rotate_tac 2)\n   apply (drule_tac x=\"sb ^^^ <Tick>\" in spec)\n   apply (drule_tac x=\"X\" in spec)\n   apply (drule mp)\n    apply (simp)\n    apply (case_tac \"Suc (lengtht sb) < n\", simp)\n    apply (case_tac \"Suc (lengtht sb) = n\", fast)\n    apply (force)\n   apply (simp)\ndone\n\n(*** rest_setF (equal) ***)\n\nlemma gSKIP_Seq_compo_rest_setF:\n   \"[| traces P1 (fstF o M1) .|. (Suc n) = traces P2 (fstF o M2) .|. (Suc n) ;\n       failures P1 M1 .|. (Suc n) = failures P2 M2 .|. (Suc n) ;\n       failures Q1 M1 .|. n = failures Q2 M2 .|. n ;\n       <Tick> ~:t traces P1 (fstF o M1) ;\n       <Tick> ~:t traces P2 (fstF o M2) |]\n    ==> failures (P1 ;; Q1) M1 .|. (Suc n) = failures (P2 ;; Q2) M2 .|. (Suc n)\"\napply (rule order_antisym)\nby (simp_all add: gSKIP_Seq_compo_rest_setF_sub)\n\n(*** map_alpha F lemma ***)\n\nlemma gSKIP_map_alpha_failures_Seq_compo_lm:\n  \"[| distance (traces P1 (fstF o M1), traces P2 (fstF o M2)) * 2 <= (1/2)^n ;\n      distance (failures P1 M1, failures P2 M2) * 2 <= (1/2)^n ;\n      distance (failures Q1 M1, failures Q2 M2) <= (1/2)^n ;\n       <Tick> ~:t traces P1 (fstF o M1);\n       <Tick> ~:t traces P2 (fstF o M2) |]\n    ==> distance (failures (P1 ;; Q1) M1, failures (P2 ;; Q2) M2) * 2\n     <= (1/2)^n\"\napply (insert gSKIP_Seq_compo_rest_setF[of P1 M1 n P2 M2 Q1 Q2])\napply (simp only: to_distance_rs)\napply (simp add: distance_rs_le_1)\ndone\n\n(*** map_alpha ***)\n\nlemma gSKIP_contraction_half_failures_Seq_compo:\n \"[| contraction_alpha (%M. traces P (fstF o M)) (1/2) ;\n     contraction_alpha (failures P) (1/2) ; non_expanding (failures Q) ;\n     gSKIP P |]\n  ==> contraction_alpha (failures (P ;; Q)) (1/2)\"\napply (simp add: contraction_alpha_def non_expanding_def map_alpha_def)\napply (intro allI)\napply (drule_tac x=\"x\" in spec)\napply (drule_tac x=\"x\" in spec)\napply (drule_tac x=\"x\" in spec)\napply (drule_tac x=\"y\" in spec)\napply (drule_tac x=\"y\" in spec)\napply (drule_tac x=\"y\" in spec)\n\napply (case_tac \"x = y\", simp)\napply (simp only: to_distance_rs)\napply (simp add: distance_iff)\napply (insert gSKIP_to_Tick_notin_traces)\napply (frule_tac x=\"P\" in spec)\napply (drule_tac x=\"P\" in spec)\napply (drule_tac x=\"fstF o x\" in spec)\napply (drule_tac x=\"fstF o y\" in spec)\napply (fold to_distance_rs)\napply (simp add: gSKIP_map_alpha_failures_Seq_compo_lm)\ndone\n\n(*--------------------------------*\n |          Depth_rest            |\n *--------------------------------*)\n\n(*** rest_setF (equal) ***)\n\nlemma Depth_rest_rest_setF:\n   \"failures P M1 .|. n = failures Q M2 .|. n\n    ==> failures (P |. m) M1 .|. n = failures (Q |. m) M2 .|. n\"\napply (simp add: failures.simps)\napply (simp add: min_rs)\napply (rule rest_equal_preserve)\napply (simp)\napply (simp add: min_def)\ndone\n\n(*** distF lemma ***)\n\nlemma Depth_rest_distF:\n     \"distance(failures (P |. m) M1, failures (Q |. m) M2) <= \n      distance(failures P M1, failures Q M2)\"\napply (simp add: to_distance_rs)\napply (rule rest_distance_subset)\nby (auto intro: Depth_rest_rest_setF)\n\n(*** map_alphaT lemma ***)\n\nlemma map_alpha_failures_Depth_rest_lm:\n  \"distance(failures P M1, failures Q M2) <= alpha * distance (x1, x2)\n    ==> distance(failures (P |. m) M1, failures (Q |. m) M2)\n     <= alpha * distance(x1, x2)\"\napply (insert Depth_rest_distF[of P m M1 Q M2])\nby (simp)\n\n(*** map_alpha ***)\n\nlemma map_alpha_failures_Depth_rest:\n \"map_alpha (failures P) alpha\n  ==> map_alpha (failures (P |. n)) alpha\"\napply (simp add: map_alpha_def)\napply (intro allI)\napply (erule conjE)\napply (drule_tac x=\"x\" in spec)\napply (drule_tac x=\"y\" in spec)\nby (simp add: map_alpha_failures_Depth_rest_lm)\n\n(*** non_expanding ***)\n\nlemma non_expanding_failures_Depth_rest:\n \"non_expanding (failures P)\n  ==> non_expanding (failures (P |. n))\"\nby (simp add: non_expanding_def map_alpha_failures_Depth_rest)\n\n(*** contraction_alpha ***)\n\nlemma contraction_alpha_failures_Depth_rest:\n \"contraction_alpha (failures P) alpha\n  ==> contraction_alpha (failures (P |. n)) alpha\"\nby (simp add: contraction_alpha_def map_alpha_failures_Depth_rest)\n\n(*--------------------------------*\n |            variable            |\n *--------------------------------*)\n\n(*** non_expanding ***)\n\nlemma continuous_failures_variable_lm:\n    \"non_expanding (sndF o (%M. M p))\"\napply (rule compo_non_expand)\napply (simp add: non_expanding_sndF)\napply (simp add: non_expanding_prod_variable)\ndone\n\nlemma non_expanding_failures_variable: \n   \"non_expanding (failures ($p))\"\napply (simp add: failures_iff)\napply (simp add: continuous_failures_variable_lm[simplified comp_def])\ndone\n\n(*--------------------------------*\n |            Procfun             |\n *--------------------------------*)\n\n(*****************************************************************\n |                         non_expanding                         |\n *****************************************************************)\n\nlemma non_expanding_failures_lm:\n  \"noHide P --> non_expanding (failures P)\"\napply (induct_tac P)\napply (simp add: non_expanding_failures_STOP)\napply (simp add: non_expanding_failures_SKIP)\napply (simp add: non_expanding_failures_DIV)\napply (simp add: non_expanding_failures_Act_prefix)\napply (simp add: non_expanding_failures_Ext_pre_choice)\napply (simp add: non_expanding_failures_Ext_choice non_expanding_traces_fstF)\napply (simp add: non_expanding_failures_Int_choice)\napply (simp add: non_expanding_failures_Rep_int_choice)\napply (simp add: non_expanding_failures_IF)\napply (simp add: non_expanding_failures_Parallel)\n\n(* hiding --> const *)\napply (intro impI)\napply (subgoal_tac \"EX F. (failures (x1 -- x2) = (%M. F))\")   (* 2012 *)\napply (erule exE)\napply (simp)\napply (simp add: non_expanding_Constant)\napply (rule failures_noPN_Constant)\napply (simp)\n\napply (simp add: non_expanding_failures_Renaming)\napply (simp add: non_expanding_failures_Seq_compo non_expanding_traces_fstF)\n\n(* Depth_res *)\napply (simp add: non_expanding_failures_Depth_rest)\napply (simp add: failures_iff)\napply (simp add: zero_rs_setF)\napply (simp add: non_expanding_Constant)\n\napply (simp add: non_expanding_failures_variable)\ndone\n\nlemma non_expanding_failures: \n  \"noHide P ==> non_expanding (failures P)\"\nby (simp add: non_expanding_failures_lm)\n\n(*=============================================================*\n |                          [[P]]Ff                            |\n *=============================================================*)\n\nlemma non_expanding_semFf:\n  \"noHide P ==> non_expanding ([[P]]Ff)\"\napply (simp add: semFf_def)\napply (simp add: non_expanding_domF_decompo)\napply (simp add: non_expanding_traces_fstF)\napply (simp add: non_expanding_failures)\ndone\n\n(*=============================================================*\n |                         [[P]]Ffun                           |\n *=============================================================*)\n\nlemma non_expanding_semFfun: \n  \"noHidefun Pf ==> non_expanding ([[Pf]]Ffun)\"\napply (simp add: semFfun_def)\napply (simp add: prod_non_expand)\napply (simp add: proj_fun_def comp_def)\napply (simp add: noHidefun_def)\napply (simp add: non_expanding_semFf)\ndone\n\n(*****************************************************************\n |                         contraction                           |\n *****************************************************************)\n\nlemma contraction_alpha_failures_lm: \n  \"guarded P --> contraction_alpha (failures P) (1/2)\"\napply (induct_tac P)\napply (simp add: contraction_alpha_failures_STOP)\napply (simp add: contraction_alpha_failures_SKIP)\napply (simp add: contraction_alpha_failures_DIV)\napply (simp add: contraction_half_failures_Act_prefix\n                 non_expanding_failures)\napply (simp add: contraction_half_failures_Ext_pre_choice\n                 non_expanding_failures)\napply (simp add: contraction_alpha_failures_Ext_choice\n                 contraction_alpha_traces_fstF)\napply (simp add: contraction_alpha_failures_Int_choice)\napply (simp add: contraction_alpha_failures_Rep_int_choice)\napply (simp add: contraction_alpha_failures_Rep_int_choice)\napply (simp add: contraction_alpha_failures_IF)\napply (simp add: contraction_alpha_failures_Parallel)\n\n(* hiding --> const *)\napply (intro impI)\napply (subgoal_tac \"EX F. (failures (x1 -- x2) = (%M. F))\")  (* 2012 *)\napply (erule exE)\napply (simp add: contraction_alpha_Constant)\napply (rule failures_noPN_Constant)\napply (simp)\n\napply (simp add: contraction_alpha_failures_Renaming)\n\n(* Seq_compo *)\napply (simp)\napply (intro conjI impI)\napply (simp add: gSKIP_contraction_half_failures_Seq_compo\n                 non_expanding_failures contraction_alpha_traces_fstF)\napply (simp add: contraction_alpha_failures_Seq_compo\n                 contraction_alpha_traces_fstF)\n\n(* Depth_res *)\napply (simp add: contraction_alpha_failures_Depth_rest)\napply (simp add: failures_iff)\napply (simp add: zero_rs_setF)\napply (simp add: contraction_alpha_Constant)\n\napply (simp add: non_expanding_failures_variable)\ndone\n\nlemma contraction_alpha_failures: \n  \"guarded P ==> contraction_alpha (failures P) (1/2)\"\napply (simp add: contraction_alpha_failures_lm)\ndone\n\n(*=============================================================*\n |                          [[P]]Ff                            |\n *=============================================================*)\n\nlemma contraction_alpha_semFf:\n  \"guarded P ==> contraction_alpha ([[P]]Ff) (1/2)\"\napply (simp add: semFf_def)\napply (simp add: contraction_alpha_domF_decompo)\napply (simp add: contraction_alpha_traces_fstF)\napply (simp add: contraction_alpha_failures)\ndone\n\n(*=============================================================*\n |                         [[P]]Ffun                           |\n *=============================================================*)\n\nlemma contraction_alpha_semFfun: \n  \"guardedfun Pf ==> contraction_alpha ([[Pf]]Ffun) (1/2)\"\napply (simp add: semFfun_def)\napply (simp add: prod_contra_alpha)\napply (simp add: proj_fun_def comp_def)\napply (simp add: guardedfun_def)\napply (simp add: contraction_alpha_semFf)\ndone\n\n(*=============================================================*\n |                        contraction                          |\n *=============================================================*)\n\nlemma contraction_semFfun: \n  \"guardedfun Pf ==> contraction ([[Pf]]Ffun)\"\napply (simp add: contraction_def)\napply (rule_tac x=\"1/2\" in exI)\napply (simp add:contraction_alpha_semFfun)\ndone\n\nend\n", "meta": {"author": "pefribeiro", "repo": "CSP-Prover", "sha": "8967cc482e5695fca4abb52d9dc2cf36b7b7a44e", "save_path": "github-repos/isabelle/pefribeiro-CSP-Prover", "path": "github-repos/isabelle/pefribeiro-CSP-Prover/CSP-Prover-8967cc482e5695fca4abb52d9dc2cf36b7b7a44e/CSP_F/CSP_F_contraction.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297746213017459, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.287893102723159}}
{"text": "(*\n * Copyright (c) 2020, CleanQ Project - Systems Group, ETH Zurich\n * All rights reserved.\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n *\n * See \"LICENSE\" for details.\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\n\n\n\n\ntheory CleanQ_SimpleQ\n  imports \n    \"AutoCorres.AutoCorres\"\n    CleanQ_RB\nbegin\n\n(* ==================================================================================== *)\nsubsection \\<open>Constants and Type Definitions\\<close>\n(* ==================================================================================== *)\n\ntext \\<open>\n  We define a few type synonyms and constants to reason about addresses\n\\<close>\ntype_synonym ulong_t = \"64 word\"\ntype_synonym uint_t = \"32 word\"\ntype_synonym ushort_t = \"16 word\"\n\nabbreviation \"addrlimit \\<equiv> (0xffffffffffffffff::ulong_t)\"\nabbreviation \"addrlimitnat \\<equiv> (0xffffffffffffffff::nat)\"\n\nlemma \"addrlimit = of_nat addrlimitnat\"\n  by(auto)\nlemma \"unat (addrlimit) = addrlimitnat\"\n  by(auto)\n\n\ndeclare[[show_types ]]\nsledgehammer_params[timeout = 120, provers = cvc4 z3 spass e vampire]\n  \n\n(* ==================================================================================== *)\nsubsection \\<open>Helper Lemmas\\<close>\n(* ==================================================================================== *)\n\nlemma unat_64word_eq_lt_lt:\n \"unat (C::ulong_t) = ULONG_MAX \\<Longrightarrow> (D::ulong_t) < C \\<Longrightarrow> unat (D) < ULONG_MAX\"\n  by(simp add: word_less_nat_alt)\n\nlemma unat_32word_eq_lt_lt:\n \"unat (C::uint_t) = UINT_MAX \\<Longrightarrow> (D::uint_t) < C \\<Longrightarrow> unat (D) < UINT_MAX\"\n  by(simp add: word_less_nat_alt)\n\nlemma unat_64word_lt_lt_lt:\n \"unat (C::ulong_t) < ULONG_MAX \\<Longrightarrow> (D::ulong_t) < C \\<Longrightarrow> unat (D) < ULONG_MAX\"\n  by(simp add: word_less_nat_alt)\n\nlemma unat_32word_lt_lt_lt:\n \"unat (C::uint_t) < UINT_MAX \\<Longrightarrow> (D::uint_t) < C \\<Longrightarrow> unat (D) < UINT_MAX\"\n  by(simp add: word_less_nat_alt)\n\nlemma unat_64word_leq_lt_lt: \n  \"unat (C::ulong_t) \\<le> ULONG_MAX \\<Longrightarrow> (D::ulong_t) < C \\<Longrightarrow> unat (D) < ULONG_MAX\"\n  using unat_64word_eq_lt_lt unat_64word_lt_lt_lt PackedTypes.order_leE \n  by blast\n\nlemma unat_32word_leq_lt_lt: \n  \"unat (C::uint_t) \\<le> UINT_MAX \\<Longrightarrow> (D::uint_t) < C \\<Longrightarrow> unat (D) < UINT_MAX\"\n  using unat_32word_eq_lt_lt unat_32word_lt_lt_lt PackedTypes.order_leE \n  by blast\n\nlemma unat_64word_lt_succ_leq:\n  \"unat (C::ulong_t) \\<le> ULONG_MAX \\<Longrightarrow> (D::ulong_t) < C \\<Longrightarrow> Suc (unat (D)) \\<le> ULONG_MAX\"\n  using unat_64word_leq_lt_lt  by (simp add: less_eq_Suc_le) \n\nlemma unat_32word_lt_succ_leq:\n  \"unat (C::uint_t) \\<le> ULONG_MAX \\<Longrightarrow> (D::uint_t) < C \\<Longrightarrow> Suc (unat (D)) \\<le> UINT_MAX\"\n  using unat_32word_leq_lt_lt  by (simp add: less_eq_Suc_le) \n\nlemma unat_64word_succ_mod:\n  assumes sz: \"1 < unat N\"  and hlt: \"H < N\"\n  shows\n  \"unat (((H::ulong_t) + 1) mod (N::ulong_t)) = Suc (unat (H)) mod unat (N)\"\n  using sz hlt  \n  by (metis add.commute less_is_non_zero_p1 unatSuc unat_mod)\n\nlemma unat_32word_succ_mod:\n  assumes sz: \"1 < unat N\"  and hlt: \"H < N\"\n  shows\n  \"unat (((H::uint_t) + 1) mod (N::uint_t)) = Suc (unat (H)) mod unat (N)\"\n  using sz hlt  \n  by (metis add.commute less_is_non_zero_p1 unatSuc unat_mod)\n\nlemma unat_word_lt: \n  \"a < b \\<Longrightarrow> unat a < unat b\"\n  by (simp add: unat_mono)\n\nlemma unat_word_leq: \n  \"a \\<le> b \\<Longrightarrow> unat a \\<le> unat b\"\n  by (simp add: word_le_nat_alt)\n\nlemma word64_mult_inequality:\n  assumes notzero: \"c \\<noteq> 0\" \n    and inrangex: \"x * unat(c) <  2 ^ 64\"\n    and inrangey: \"unat(y) * unat(c) <  2 ^ 64\"\n    and neq: \"x \\<noteq> unat y\"\n  shows \"((of_nat x)::ulong_t) * (c::ulong_t) \\<noteq> (y::ulong_t) * (c::ulong_t)\"\nproof -\n  from notzero inrangex have xlim:\n    \"x < 2 ^ 64\"\n    by (metis linorder_neqE_nat multi_lessD not_less0 unat_gt_0)\n\n  have xc_limit:\n    \"unat ((of_nat x)::ulong_t) * unat c < 2 ^ 64\"\n    using  xlim unat_of_nat64 word_bits_conv inrangex by(auto)\n\n  have xc_equiv:\n    \"unat (((of_nat x)::ulong_t) * c) = x * unat c\"\n    using xc_limit unat_mult_lem unat_of_nat64 word_bits_conv inrangex by fastforce\n  \n  have yc_equiv: \n    \"unat (y * c) = unat(y) * unat (c)\"\n    using inrangey  unat_mult_lem by fastforce\n\n  show ?thesis\n    using xc_equiv yc_equiv neq notzero unat_eq_zero\n    by force\nqed\n\nlemma word64_mult_inequality2:\n  assumes notzero: \"c \\<noteq> 0\" \n    and inrangex: \" x * unat(c) \\<le> unat addrlimit\"\n    and inrangey: \"unat (y) * unat (c) \\<le> unat  addrlimit\"\n    and neq: \"x \\<noteq> unat y\"\n  shows \"((of_nat x)::ulong_t) * (c::ulong_t) \\<noteq> (y::ulong_t) * (c::ulong_t)\"\nproof -\n  from notzero inrangex have xlim0:\n    \"x \\<le> unat addrlimit\"\n    using dual_order.trans unat_eq_zero by fastforce\n\n  from xlim0 have xlim:\n    \"x < 2 ^ 64\"\n    by (metis (mono_tags, hide_lams) le_unat_uoi  word_bits_conv unat_less_2p_word_bits)\n\n   from xlim have xc_limit:\n    \"unat ((of_nat x)::ulong_t) * unat c < 2 ^ 64\"\n     by (metis (no_types, hide_lams) le_unat_uoi unat_less_2p_word_bits\n                                     unat_of_nat64 word_bits_conv inrangex)\n\n    have xc_equiv:\n    \"unat (((of_nat x)::ulong_t) * c) = x * unat c\"\n    using inrangex le_unat_uoi by fastforce\n  have yc_equiv: \n    \"unat (y * c) = unat(y) * unat (c)\"\n    using inrangey le_unat_uoi by fastforce\n\n  show ?thesis\n    using xc_equiv yc_equiv neq notzero unat_eq_zero \n    by force\nqed\n\nlemma word64_multply_const_equaltiy:\nassumes notzero: \"c \\<noteq> (0::ulong_t)\"\n  and hclimit:  \"unat (h) * unat (c) < 2 ^ 64\"\n  and xclimit:  \"x * unat (c) < 2 ^ 64\"\nshows \"((of_nat x)::ulong_t) * (c::ulong_t) = (h::ulong_t) * (c::ulong_t) \\<longleftrightarrow> x = unat (h)\"\n  using hclimit notzero word64_mult_inequality xclimit by fastforce\n\n(* ==================================================================================== *)\nsubsection \\<open>SimpleQ C Implementation\\<close>\n(* ==================================================================================== *)\n\ntext \\<open>\n  Next we load the CleanQ_SimpleQ.c implementation of a shared-memory ring buffer, and\n  show that the C implementation refines the abstract ring buffer implementation.\n\\<close>\n\nexternal_file \"CleanQ_SimpleQ.c\"\ninstall_C_file \"CleanQ_SimpleQ.c\"\n\nautocorres [\n\n  (* Name compatibility options *)\n  lifted_globals_field_prefix=\"c_glbl_\",\n  lifted_globals_field_suffix=\"\",\n  function_name_prefix=\"\",\n  function_name_suffix=\"_c_fun\",\n\n\n  (* heap abstraction options *)\n    \n  (* no_heap_abs = FUNC_NAMES, *)\n  (* Disable _heap abstraction_ on the given list of functions. *)\n\n  (* force_heap_abs = FUNC_NAMES, *)\n  (* Attempt _heap abstraction_  on the given list of functions *)\n\n  (* heap_abs_syntax, *)\n  (* Enable experimental heap abstraction syntactic sugar. *)\n\n  (* skip_heap_abs *)\n  (* Completely disable _heap abstraction_ *)\n\n\n  (* word abstraction options *)\n\n  unsigned_word_abs =   rb_can_deq rb_can_enq rb_enq rb_deq rb_deq_unfolded rb_enq_unfolded ,\n  (* Use _word abstraction_  on unsigned integers in the given functions. *)\n\n  no_signed_word_abs =   rb_can_deq rb_can_enq rb_enq rb_deq rb_deq_unfolded rb_enq_unfolded,\n  (* Disable signed  _word abstraction_ on the given list of functions. *)\n\n  (* skip_word_abs, *)\n  (* Completely disable _word abstraction_. *)\n\n\n  (* type strengthening options *)\n  ts_rules =  pure option nondet, \n  (* Enable _type strengthening_ to the  following types. pure, option, gets nondet *)\n\n  ts_force nondet =   rb_can_deq rb_can_enq rb_enq rb_deq rb_deq_unfolded rb_enq_unfolded,\n  (* Force the given functions to be type-strengthened to the given type *)\n\n\n  (* translation scoping options *)\n  (* scope = FUNC_NAMES, *)\n  (* Only translate the given functions  and their callees, up to depth `scope_depth`. *)\n\n  (* scope_depth = N, *)\n  (* Call depth for `scope` *)\n\n\n  (* less common, debugging options *)\n\n  (*keep_going, *)\n  (* Attempt to ignore certain non-critical  errors. *)\n\n  (* trace_heap_lift = FUNC_NAMES`, *)\n  (* Trace the _heap abstraction_ process for each of the given functions.  *)\n\n  (* trace_word_abs = FUNC_NAMES`: *) \n  (* As above, but traces _word abstraction_. *)\n\n  (* trace_opt, *)\n  (* As above, but traces internal simplification phases (for all functions).*)\n\n  (* no_opt, *)\n  (* Disable some optimisation passes that simplify the AutoCorres output. *)\n\n  gen_word_heaps,\n  (* Force _heap abstraction_ to create  abstract heaps for standard `word` types *)\n\n\n  (* seL4 proof options *)\n\n  no_c_termination\n  (*  Generate SIMPL wrappers and correspondence proofs *)\n\n  (* c_locale = Name *)\n  (*  Run in this locale, rather than the default locale *)\n\n] \"CleanQ_SimpleQ.c\"\n(* skip_word_abs *)\n\ntext \\<open>\n We can now enter the defined context by autocorres. \n\\<close>\n\ncontext CleanQ_SimpleQ begin\n\n(* ==================================================================================== *)\nsubsection \\<open>C Definitions\\<close>\n(* ==================================================================================== *)\n\nabbreviation \"ERR_OK \\<equiv> (0)\"\nabbreviation \"ERR_QUEUE_FULL \\<equiv> (-1)\"\nabbreviation \"ERR_QUEUE_EMPTY  \\<equiv> (-2)\"\nabbreviation \"ERR_NO_BUFFERS \\<equiv> (-3)\"\n\n(* ==================================================================================== *)\nsubsection \\<open>Invariant\\<close>\n(* ==================================================================================== *)\n\ntext \\<open>\n  We now define the validity invariant for the ring buffer struct. We first define\n  abbrevations for each of the field\n\\<close>\n\nabbreviation \"c_rb_valid_is_valid s rb \\<equiv> is_valid_rb_C s rb\"\nabbreviation \"c_rb_valid_size s rb \\<equiv> 1 <  (size_C (heap_rb_C s rb))\"\nabbreviation \"c_rb_valid_head s rb \\<equiv> head_C (heap_rb_C s rb) < size_C (heap_rb_C s rb)\"\nabbreviation \"c_rb_valid_tail s rb \\<equiv> tail_C (heap_rb_C s rb) < size_C (heap_rb_C s rb)\"\nabbreviation \"c_rb_valid_ring s rb \\<equiv> (\\<forall>i \\<le> uint (size_C (heap_rb_C s rb)). \n                                    is_valid_buffer_C s (ring_C (heap_rb_C s rb) +\\<^sub>p i) \\<and>\n                                    ptr_val (ring_C (heap_rb_C s rb) +\\<^sub>p i) \\<le> addrlimit)\"\n\n(* this one should be the pre-condition for the operation *)\ndefinition c_rb_valid :: \"lifted_globals \\<Rightarrow> rb_C ptr \\<Rightarrow> bool\"\n  where \"c_rb_valid s rb \\<longleftrightarrow> c_rb_valid_is_valid s rb \n                            \\<and> c_rb_valid_size s rb  \\<and> c_rb_valid_head s rb\n                            \\<and> c_rb_valid_tail s rb  \\<and> c_rb_valid_ring s rb\"\n\n\ntext \"We can now define the set of valid entries in the ring buffer\"\n\ndefinition c_rb_valid_entries :: \"lifted_globals \\<Rightarrow> rb_C ptr \\<Rightarrow> nat list\"\n  where \"c_rb_valid_entries s rb = \n            (if (tail_C (heap_rb_C s rb)) \\<le> (head_C (heap_rb_C s rb))\n             then [unat (tail_C (heap_rb_C s rb)) ..< unat (head_C (heap_rb_C s rb))]\n             else [unat (tail_C (heap_rb_C s rb))..< unat (size_C (heap_rb_C s rb))]\n                     @ [0..<unat (head_C (heap_rb_C s rb))])\"\n\n\ndefinition c_rb_empty ::  \"lifted_globals \\<Rightarrow> rb_C ptr \\<Rightarrow> bool\"\n  where \"c_rb_empty s rb = (tail_C (heap_rb_C s rb) = head_C (heap_rb_C s rb))\"\n\n\n\nlemma c_rb_not_empty_valid_entries:\n  \"c_rb_valid s0 rb \\<Longrightarrow> \\<not> c_rb_empty s0 rb \\<Longrightarrow> c_rb_valid_entries s0 rb \\<noteq> []\"\n  unfolding c_rb_valid_entries_def c_rb_valid_def c_rb_empty_def\n  apply(auto simp add: word_le_nat_alt) \n  using dual_order.antisym apply fastforce\n  using unat_eq_zero apply force\n  using leD unat_word_lt by blast\n\n\nlemma c_rb_valid_entries_head_not_in_set:\n  \"unat (head_C (heap_rb_C s0 rb)) \\<notin> set (c_rb_valid_entries s0 rb)\"\n  unfolding c_rb_valid_entries_def \n  by (auto simp: word_le_nat_alt)\n\n\n\nlemma c_rb_valid_entries_tail_first1:\n  \"c_rb_valid s0 rb \\<Longrightarrow> \\<not> c_rb_empty s0 rb \\<Longrightarrow>\n       unat (tail_C (heap_rb_C s0 rb)) = hd (c_rb_valid_entries s0 rb)\"\nproof -\n  assume p1: \"c_rb_valid s0 rb\"\n  assume p2: \"\\<not> c_rb_empty s0 rb\"\n\n  from p1 have p3: \"  unat (tail_C (heap_rb_C s0 rb)) < unat (size_C (heap_rb_C s0 rb))\"\n    by(simp add:unat_mono c_rb_valid_def)\n\n  show \"unat (tail_C (heap_rb_C s0 rb)) = hd (c_rb_valid_entries s0 rb)\"\n    using p3  unfolding c_rb_valid_entries_def apply(auto simp:unat_word_lt)  \n    by (metis CleanQ_SimpleQ.c_rb_empty_def hd_upt order_leE p2 word_less_nat_alt)\nqed\n  \n\n\nlemma c_rb_valid_entries_tail_in_set:\n  \"c_rb_valid s0 rb \\<Longrightarrow> \\<not> c_rb_empty s0 rb \\<Longrightarrow>\n    unat (tail_C (heap_rb_C s0 rb)) \\<in> set (c_rb_valid_entries s0 rb)\"\n  using c_rb_valid_entries_tail_first1 c_rb_not_empty_valid_entries\n  by(auto)\n  \n\n\n\n(* ==================================================================================== *)\nsubsection \\<open>State Lifting\\<close>\n(* ==================================================================================== *)\n\n\ntext \\<open>\n  We now define the lifting function which converts the \\verb+rb_C+ object into a\n  \\verb+CleanQ_RB+ record. We use the \\verb+buffer_C+ representation for the buffer \n  descriptor type in the record.\n\\<close>\n\n(* \ndefinition\n  the_rb :: \"lifted_globals \\<Rightarrow> buffer_C ptr \\<Rightarrow> nat \\<Rightarrow> buffer\"\n  where\n  \"the_rb s b i =  \\<lparr> base = unat (offset_C (heap_buffer_C s (b  +\\<^sub>p i))),\n                     length = unat (length_C (heap_buffer_C s (b  +\\<^sub>p i))) \\<rparr>\"\n*)\n\n(* XXX: Should the ring here be taking the size of the ring buffer into account? \n      ring = \\<lambda>i. (if i <  size_C (heap_rb_C s rb) then heap_buffer_C s ((ring_C (heap_rb_C s rb))  +\\<^sub>p i)),\n*)\ndefinition rb_C_to_CleanQ_RB :: \"lifted_globals \\<Rightarrow> rb_C ptr \\<Rightarrow> buffer_C  CleanQ_RB\"\n  where \"rb_C_to_CleanQ_RB s rb = \\<lparr> \n                  ring = \\<lambda>i. (if i < unat (size_C (heap_rb_C s rb))\n                               then Some (heap_buffer_C s (ring_C (heap_rb_C s rb)  +\\<^sub>p i))\n                               else None),\n                  head =  unat (head_C (heap_rb_C s rb)), \n                  tail =  unat (tail_C (heap_rb_C s rb)),\n                  size =  unat (size_C (heap_rb_C s rb)) \\<rparr>\"\n\ntext \\<open>\n  We can now show that if the C ringbuffer is valid, then the lifted state is also\n  satisfying the validity predicate of the \\verb+CleanQ_RB+ model.\n\\<close>\n\n\nlemma \"c_rb_valid s rb \\<longrightarrow> rb_valid (rb_C_to_CleanQ_RB s rb)\"\n  unfolding c_rb_valid_def rb_valid_def rb_C_to_CleanQ_RB_def\n  using unat_word_lt\n  oops\n\n\n(* ==================================================================================== *)\nsubsection \\<open>Dequeue Operation\\<close>\n(* ==================================================================================== *)\n\ntext \\<open>\n  Whether or not the dequeue operation performs the update, depends on whether the\n  the ring buffer is empty or not. We first show that the \\verb+rb_can_deq+ function in \n  C produces the same result as the corresponding definition in the \\verb+CleanQ_RB+ \n  model.\n\\<close>\n\nlemma c_can_deq:\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb  \\<rbrace>\n   rb_can_deq_c_fun rb\n   \\<lbrace> \\<lambda> r s. to_bool r =  rb_can_deq (rb_C_to_CleanQ_RB s rb) \\<rbrace>!\"\n  apply(subst rb_can_deq_c_fun_def)\n  apply(wp)\n  apply (simp add:rb_can_deq_def rb_empty_def rb_C_to_CleanQ_RB_def c_rb_valid_def)\n  done\n\n\nlemma c_can_deq_return_values:\n  \"\\<lbrace> \\<lambda>s. is_valid_rb_C s rb  \\<rbrace>\n   rb_can_deq_c_fun rb \n   \\<lbrace> \\<lambda> r s. r =  0 \\<or> r = 1  \\<rbrace>!\"\n  unfolding rb_can_deq_c_fun_def\n  by(wp, auto)  \n\ntext \\<open>\n  For the dequeue operation, we can show that the operation preserves the size of the\n  ring buffer, and the head pointer.\n\\<close>\n\nlemma c_rb_deq_preserves_size :\n  fixes rb :: \"rb_C ptr\"\n  shows\n  \"\\<And>s0. \\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s \\<and> is_valid_buffer_C s b \\<rbrace>\n   rb_deq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. size_C (heap_rb_C s rb) = size_C (heap_rb_C s0 rb) \\<rbrace>!\"\n   apply(simp add:rb_deq_c_fun_def)\n  apply(wp_once)+\n  apply(auto simp:rb_can_deq_c_fun_def)\n  apply(wp_once)+\n  apply(simp add:c_rb_valid_def)\n  by (metis less_imp_le uint_0_iff uint_lt_0 unat_gt_0  word_less_def)\n  \n\n\nlemma c_rb_deq_preserves_size2 :\n  fixes rb :: \"rb_C ptr\"\n  shows\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> size_C (heap_rb_C s rb) = k  \\<and>  is_valid_buffer_C s b \\<rbrace>\n   rb_deq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. size_C (heap_rb_C s rb) = k  \\<rbrace>!\"\n   apply(simp add:rb_deq_c_fun_def)\n  apply(wp_once)+\n  apply(auto simp:rb_can_deq_c_fun_def)\n  apply(wp_once)+\n  apply(simp add:c_rb_valid_def)\n  by (metis less_imp_le uint_0_iff uint_lt_0 unat_gt_0  word_less_def)\n\n\nlemma c_rb_deq_preserves_head :\n  fixes rb :: \"rb_C ptr\"\n  shows\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s  \\<and>  is_valid_buffer_C s b \\<rbrace>\n   rb_deq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. head_C (heap_rb_C s rb) = head_C (heap_rb_C s0 rb)  \\<rbrace>!\"\n   apply(simp add:rb_deq_c_fun_def)\n  apply(wp_once)+\n  apply(auto simp:rb_can_deq_c_fun_def)\n  apply(wp_once)+\n  apply(simp add:c_rb_valid_def)\n  by (metis less_imp_le uint_0_iff uint_lt_0 unat_gt_0  word_less_def)\n\nlemma c_rb_deq_preserves_head2 :\n  fixes rb :: \"rb_C ptr\"\n  shows\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and>  head_C (heap_rb_C s rb) = k  \\<and> is_valid_buffer_C s b \\<rbrace>\n   rb_deq_c_fun rb b\n   \\<lbrace> \\<lambda> r s.  head_C (heap_rb_C s rb) = k  \\<rbrace>!\"\n  apply(simp add:rb_deq_c_fun_def)\n  apply(wp_once)+\n  apply(auto simp:rb_can_deq_c_fun_def)\n  apply(wp_once)+\n  apply(simp add:c_rb_valid_def)\n  by (metis less_imp_le uint_0_iff uint_lt_0 unat_gt_0  word_less_def)\n\n\ntext \\<open>\n  If the queue is empty, and the dequeue operation cannot pull another buffer from\n  the ring, then the ring buffer remains in the same state. .\n\\<close>\n\n\nlemma c_rb_deq_preserves_tail :\n  fixes rb :: \"rb_C ptr\"\n  shows\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s \\<and> rb_can_deq_c_fun rb = return (0)  \\<rbrace>\n   rb_deq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. tail_C (heap_rb_C s rb) = tail_C (heap_rb_C s0 rb)  \\<rbrace>!\"\n  apply(simp add:rb_deq_c_fun_def)\n  apply(wp_once)+\n  apply(smt hoare_assume_preNF validNF_chain validNF_return)\n  done\n\nlemma c_rb_deq_preserves_tail2 :\n  fixes rb :: \"rb_C ptr\"\n  shows\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> tail_C (heap_rb_C s rb) = k \\<and> rb_can_deq_c_fun rb = return (0) \\<rbrace>\n   rb_deq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. tail_C (heap_rb_C s rb) = k \\<rbrace>!\"\n  apply(simp add:rb_deq_c_fun_def)\n  apply(wp_once)+\n  apply(smt hoare_assume_preNF validNF_chain validNF_return)\n  done\n\ntext \\<open>\n  The dequeue operation does not change the ring at all\n\\<close>\n\nlemma c_rb_deq_preserves_ring :\n  fixes rb :: \"rb_C ptr\"\n  shows\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s \\<and> is_valid_buffer_C s0 b  \\<rbrace>\n   rb_deq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. ring_C (heap_rb_C s rb) = ring_C (heap_rb_C s0 rb)  \\<rbrace>!\"\n   apply(simp add:rb_deq_c_fun_def)\n  apply(wp_once)+\n  apply(simp add:rb_can_deq_c_fun_def)\n  apply(wp_once)+\n  apply(auto simp add:c_rb_valid_def)\n  using unat_word_lt apply fastforce\n  using word_le_def word_le_less_eq apply blast \n  done\n\nlemma c_rb_deq_preserves_ring2 :\n  fixes rb :: \"rb_C ptr\"\n  shows\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> ring_C (heap_rb_C s rb) = k \\<and> is_valid_buffer_C s b \\<rbrace>\n   rb_deq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. ring_C (heap_rb_C s rb) = k  \\<rbrace>!\"\n   apply(simp add:rb_deq_c_fun_def)\n  apply(wp_once)+\n  apply(simp add:rb_can_deq_c_fun_def)\n  apply(wp_once)+\n  apply(auto simp add:c_rb_valid_def)\n  using unat_word_lt apply fastforce\n  using word_le_def word_le_less_eq apply blast \n  done\n\ntext \\<open>\n  Also, the ring contents are not changed. \n\\<close>\n\nlemma c_rb_deq_preserves_ring_contents :\n  fixes rb :: \"rb_C ptr\"\n  shows\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s \\<and> is_valid_buffer_C s0 b \n    \\<and> (\\<forall>i < size_C (heap_rb_C s rb).  (ring_C (heap_rb_C s rb)  +\\<^sub>p uint i) \\<noteq> b)   \\<rbrace>\n   rb_deq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. \\<forall>i < size_C (heap_rb_C s rb). \n        heap_buffer_C s (ring_C (heap_rb_C s rb)  +\\<^sub>p uint i) = \n        heap_buffer_C s0 (ring_C (heap_rb_C s0 rb) +\\<^sub>p uint i)  \\<rbrace>!\"\n   apply(simp add:rb_deq_c_fun_def)\n  apply(wp_once)+\n  apply(simp add:rb_can_deq_c_fun_def)\n  apply(wp_once)+\n  apply(auto simp add:c_rb_valid_def)\n  using unat_word_lt apply fastforce\n  using word_le_def word_le_less_eq apply blast \n  using unat_word_lt apply fastforce\n  using less_imp_le word_le_def apply blast\n  done\n\n\ntext \\<open>\n  In fact, if the ring buffer is empty, then the state is not altered at all.\n\\<close>\n\nlemma c_rb_deq_empty_preserves_state:\n  fixes rb :: \"rb_C ptr\" and b :: buffer_C\n  shows \"\n   \\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s \\<and> rb_can_enq_c_fun rb =  return (0)  \\<rbrace>\n   rb_enq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. r \\<noteq> 0 \\<and> s = s0 \\<rbrace>!\"\n   apply(simp add:rb_enq_c_fun_def)\n  apply(wp_once)+\n  apply(simp)\n  apply (smt hoare_assume_preNF validNF_chain validNF_return)\n  done\n\ntext \\<open>\n  We can show that the dequeue function preserves the valid predicate.\n\\<close>\n\nlemma c_rb_deq_remains_valid:\n  fixes rb :: \"rb_C ptr\" \n  shows \"\n   \\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> is_valid_buffer_C s b  \\<rbrace>\n   rb_deq_c_fun rb b\n   \\<lbrace> \\<lambda> r s.  c_rb_valid s rb \\<rbrace>!\"\n  apply(simp add:rb_deq_c_fun_def)\n  apply(wp_once)+\n  apply(simp add:rb_can_deq_c_fun_def)\n  apply(wp_once)+\n  apply(simp add:c_rb_valid_def)\n  by (metis not_gr_zero not_less0 unat_0 word_le_def word_le_less_eq word_less_nat_alt \n            word_mod_less_divisor)\n\n\ntext \\<open>\n  Lastly, we can show that the C implementation of the dequeue operation produces the \n  same outcome as doing the abstraction operation.\n\\<close>\n\nlemma c_rb_deq_state_update_head:\n\"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s \\<and> rb0 = rb_C_to_CleanQ_RB s rb  \n        \\<and> is_valid_buffer_C s0 b  \\<rbrace>\n   rb_deq_c_fun rb b\n \\<lbrace> \\<lambda> r s. head (rb_C_to_CleanQ_RB s rb) = head (snd (rb_deq rb0)) \\<rbrace>!\"\n  unfolding rb_deq_c_fun_def\n  apply(wp_once)+\n  apply(simp add:rb_can_deq_c_fun_def)\n  apply(wp_once)+\n  apply(simp add:c_rb_valid_def rb_deq_equiv rb_deq_alt_def rb_C_to_CleanQ_RB_def)\n  using less_imp_le unat_1_0  word_le_def word_le_less_eq by blast\n\n  \nlemma c_rb_deq_state_update_tail:\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s \\<and> rb0 = rb_C_to_CleanQ_RB s rb   \\<and> is_valid_buffer_C s0 b  \\<rbrace>\n   rb_deq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. (r = ERR_OK \\<or> r = ERR_QUEUE_EMPTY) \\<and>\n      (if r = ERR_OK then tail (rb_C_to_CleanQ_RB s rb) = tail (snd (rb_deq rb0)) \n       else s = s0)  \\<rbrace>!\"\n  unfolding rb_deq_c_fun_def\n  apply(wp_once)+\n  apply(simp add:rb_can_deq_c_fun_def)\n  apply(wp_once)+\n  apply(auto simp add:c_rb_valid_def rb_deq_equiv rb_deq_alt_def rb_C_to_CleanQ_RB_def)\n  using unat_32word_succ_mod unat_word_lt apply fastforce\n  using unat_gt_0 apply fastforce\n  using word_le_def word_le_less_eq by blast\n\n\nlemma c_rb_deq_state_update_size:\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s \n                \\<and> rb0 = rb_C_to_CleanQ_RB s rb  \\<and> is_valid_buffer_C s0 b  \\<rbrace>\n   rb_deq_c_fun rb b\n   \\<lbrace> \\<lambda> r s.  (r = ERR_OK \\<or> r = ERR_QUEUE_EMPTY) \\<and>\n              size (rb_C_to_CleanQ_RB s rb) = size (snd (rb_deq rb0)) \\<rbrace>!\"\n  unfolding rb_deq_c_fun_def\n  apply(wp_once)+\n  apply(simp add:rb_can_deq_c_fun_def)\n  apply(wp_once)+\n  apply(simp add:c_rb_valid_def rb_deq_equiv rb_deq_alt_def rb_C_to_CleanQ_RB_def)\n  using less_imp_le unat_1_0  word_le_def word_le_less_eq by blast\n\n\nlemma c_rb_deq_state_update_ring:\n  assumes notinring: \"(\\<forall>i \\<le> uint (size_C (heap_rb_C s0 rb)). \n                                     (ring_C (heap_rb_C s0 rb) +\\<^sub>p i) \\<noteq> b)\"\n  shows \"\n   \\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s  \n                \\<and> rb0 = rb_C_to_CleanQ_RB s rb  \\<and> is_valid_buffer_C s b  \\<rbrace>\n   rb_deq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. (r = ERR_OK \\<or> r = ERR_QUEUE_EMPTY) \\<and> \n         (if r = ERR_OK then \\<forall> i < uint (size_C (heap_rb_C s rb)). ring (rb_C_to_CleanQ_RB s rb) i = ring (snd (rb_deq rb0)) i\n         else s = s0)  \\<rbrace>!\"\n  unfolding rb_deq_c_fun_def\n  apply(wp_once)+\n  apply(simp add:rb_can_deq_c_fun_def)\n  apply(wp_once)+ \n  apply(auto simp:c_rb_valid_def  rb_deq_equiv rb_deq_alt_def)\n  prefer 3 using word_le_def word_le_less_eq apply blast\n   prefer 2 using unat_word_lt apply fastforce\n  unfolding rb_C_to_CleanQ_RB_def using notinring by(auto)\n\nlemma c_rb_deq_buffer:\n  assumes notinring: \"(\\<forall>i \\<le> uint (size_C (heap_rb_C s0 rb)). \n                                     (ring_C (heap_rb_C s0 rb) +\\<^sub>p i) \\<noteq> b)\"\n  shows \"\n   \\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s  \\<and> rb0 = rb_C_to_CleanQ_RB s rb \\<and>  is_valid_buffer_C s0 b  \\<rbrace>\n   rb_deq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. (r = ERR_OK \\<or> r = ERR_QUEUE_EMPTY) \\<and> \n        (if r = ERR_OK then heap_buffer_C s b = fst (rb_deq rb0) else s = s0)\n    \\<rbrace>!\"\n  unfolding rb_deq_c_fun_def\n  apply(wp_once)+\n  apply(simp add:rb_can_deq_c_fun_def)\n  apply(wp_once)+ \n  apply(auto simp:c_rb_valid_def  rb_deq_equiv rb_deq_alt_def)\n  prefer 3 \n  using word_le_def word_le_less_eq apply blast\n   prefer 2  \n  using unat_word_lt apply fastforce\n  unfolding rb_C_to_CleanQ_RB_def rb_deq_def rb_read_tail_def\n  apply (simp add: int_unat)\n  using unat_word_lt by blast\n\n\nlemma ringhelper:\n  \"ring_C (heap_rb_C (heap_rb_C_update (\\<lambda>a::rb_C ptr \\<Rightarrow> rb_C. a(rb := tail_C_update (\\<lambda>a::32 word. (tail_C (heap_rb_C s0 rb) + (1::32 word)) mod size_C (heap_rb_C s0 rb)) (a rb)))\n                      (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(b := heap_buffer_C s0 (ring_C (heap_rb_C s0 rb) +\\<^sub>p uint (tail_C (heap_rb_C s0 rb))))) s0))\n                    rb) = ring_C (heap_rb_C s0 rb)\"\n  by(auto)\n\nlemma bufferhelper:\n  \" heap_buffer_C\n                (heap_rb_C_update (\\<lambda>a::rb_C ptr \\<Rightarrow> rb_C. a(rb := tail_C_update (\\<lambda>a::32 word. (tail_C (heap_rb_C s0 rb) + (1::32 word)) mod size_C (heap_rb_C s0 rb)) (a rb)))\n                  (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(b := heap_buffer_C s0 (ring_C (heap_rb_C s0 rb) +\\<^sub>p uint (tail_C (heap_rb_C s0 rb))))) s0)) = \n         heap_buffer_C\n                  (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(b := heap_buffer_C s0 (ring_C (heap_rb_C s0 rb) +\\<^sub>p uint (tail_C (heap_rb_C s0 rb))))) s0)\"\n  by(auto)\n\nlemma bufferhelper2:\n  \" (i::nat) < uint (size_C (heap_rb_C s0 rb)) \\<Longrightarrow> (ring_C (heap_rb_C s0 rb) +\\<^sub>p i) \\<noteq> b \\<Longrightarrow>\n  (heap_buffer_C (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(b := heap_buffer_C s0 (ring_C (heap_rb_C s0 rb) +\\<^sub>p uint (tail_C (heap_rb_C s0 rb))))) s0) (ring_C (heap_rb_C s0 rb) +\\<^sub>p int i)) \n  =  (heap_buffer_C (s0) (ring_C (heap_rb_C s0 rb) +\\<^sub>p int i))\"\n  by(auto)\n\nlemma c_rb_deq_correct:\n  assumes notinring: \"(\\<forall>i < uint (size_C (heap_rb_C s0 rb)). \n                                     (ring_C (heap_rb_C s0 rb) +\\<^sub>p i) \\<noteq> b)\"\n  shows \"\n   \\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s  \\<and> rb0 = rb_C_to_CleanQ_RB s rb \\<and>  is_valid_buffer_C s0 b  \\<rbrace>\n   rb_deq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. (r = ERR_OK \\<or> r = ERR_QUEUE_EMPTY) \\<and> \n        (if r = ERR_OK then rb_C_to_CleanQ_RB s rb = snd (rb_deq rb0) else s = s0)\n    \\<rbrace>!\"\n   unfolding rb_deq_c_fun_def\n  apply(wp_once)+\n  apply(simp add:rb_can_deq_c_fun_def)\n  apply(wp_once)+ \n  apply(auto simp:c_rb_valid_def  rb_deq_equiv rb_deq_alt_def)\n  prefer 3 \n  using word_le_def word_le_less_eq apply blast\n  prefer 2  \n  using unat_word_lt apply fastforce\n  unfolding rb_C_to_CleanQ_RB_def\n  apply(auto)\n  prefer 2 \n  using unat_32word_succ_mod unat_word_lt apply fastforce\n  apply(subst ringhelper)\n  apply(subst bufferhelper)\n(* WHOAH.... *)\nproof -\n  have \"\\<forall>n na. \\<not> n < unat (size_C (heap_rb_C s0 rb)) \\<or> \\<not> na < unat (size_C (heap_rb_C s0 rb)) \\<or> n < unat (size_C (heap_rb_C s0 rb)) \\<and> na < unat (size_C (heap_rb_C s0 rb)) \\<and> Some (heap_buffer_C (heap_buffer_C_update (\\<lambda>f. f (b := heap_buffer_C s0 (ring_C (heap_rb_C s0 rb) +\\<^sub>p uint (tail_C (heap_rb_C s0 rb))))) s0) (ring_C (heap_rb_C s0 rb) +\\<^sub>p int na)) = Some (heap_buffer_C s0 (ring_C (heap_rb_C s0 rb) +\\<^sub>p int na))\"\n    by (metis CleanQ_SimpleQ.bufferhelper2 int_unat notinring of_nat_less_iff)\n  then show \"(\\<lambda>n. if n < unat (size_C (heap_rb_C s0 rb)) then Some (heap_buffer_C (heap_buffer_C_update (\\<lambda>f. f (b := heap_buffer_C s0 (ring_C (heap_rb_C s0 rb) +\\<^sub>p uint (tail_C (heap_rb_C s0 rb))))) s0) (ring_C (heap_rb_C s0 rb) +\\<^sub>p int n)) else None) = (\\<lambda>n. if n < unat (size_C (heap_rb_C s0 rb)) then Some (heap_buffer_C s0 (ring_C (heap_rb_C s0 rb) +\\<^sub>p int n)) else None)\"\n    by meson\nqed\n\n \nthm rb_enq_c_fun_def\nthm rb_can_enq_c_fun_def\n\n\n(* ==================================================================================== *)\nsubsection \\<open>Enqueue Operation\\<close>\n(* ==================================================================================== *)\n\ntext \\<open>\n  Whether or not the enqueue operation performs the update, depends on whether the\n  the ring buffer is full or not. We first show that the \\verb+rb_can_enq+ function in \n  C produces the same result as the corresponding definition in the \\verb+CleanQ_RB+ \n  model.\n\\<close>\n\nlemma c_can_enq:\n  fixes rb :: \"rb_C ptr\"\n  shows \n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb  \\<rbrace>\n   rb_can_enq_c_fun rb\n   \\<lbrace> \\<lambda> r s. to_bool r =  rb_can_enq (rb_C_to_CleanQ_RB s rb) \\<rbrace>!\"\n  apply(subst rb_can_enq_c_fun_def)\n  apply(wp, simp add:rb_can_enq_def rb_full_def rb_C_to_CleanQ_RB_def c_rb_valid_def)\n  using Suc_le_eq unat_32word_leq_lt_lt unat_word_lt by fastforce\n\n\nlemma c_can_enq_return_values:\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb  \\<rbrace>\n   rb_can_enq_c_fun rb \n   \\<lbrace> \\<lambda> r s. r =  0 \\<or> r = 1  \\<rbrace>!\"\n  unfolding rb_can_enq_c_fun_def\n  apply(wp, simp)\n  using c_rb_valid_def unat_32word_leq_lt_lt unat_gt_0 by fastforce\n\n\ntext \\<open>\n  For the enqueue operation, we can show that the operation preserves the size of the\n  ring buffer, and the tail pointer.\n\\<close>\n\nlemma c_rb_enq_preserves_size :\n  fixes rb :: \"rb_C ptr\"\n  shows\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s \\<rbrace>\n   rb_enq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. size_C (heap_rb_C s rb) = size_C (heap_rb_C s0 rb)  \\<rbrace>!\"\n  apply(simp add:rb_enq_c_fun_def)\n  apply(wp_once)+\n  apply(auto simp:rb_can_enq_c_fun_def)\n  apply(wp_once)+\n  apply(simp add:c_rb_valid_def unat_word_leq word_less_nat_alt) \n  by (meson INT_MIN_MAX_lemmas(12) Suc_leI le_eq_less_or_eq less_le_trans un_ui_le)\n  \n\nlemma c_rb_enq_preserves_size2 :\n  fixes rb :: \"rb_C ptr\"\n  shows\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> size_C (heap_rb_C s rb) = k \\<rbrace>\n   rb_enq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. size_C (heap_rb_C s rb) = k  \\<rbrace>!\"\n   apply(simp add:rb_enq_c_fun_def)\n  apply(wp_once)+\n  apply(auto simp:rb_can_enq_c_fun_def)\n  apply(wp_once)+\n  apply(simp add:c_rb_valid_def unat_word_leq word_less_nat_alt) \n  by (meson INT_MIN_MAX_lemmas(12) Suc_le_eq less_imp_le_nat less_le_trans un_ui_le)\n\n\nlemma c_rb_enq_preserves_tail :\n  fixes rb :: \"rb_C ptr\"\n  shows\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s \\<rbrace>\n   rb_enq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. tail_C (heap_rb_C s rb) = tail_C (heap_rb_C s0 rb)  \\<rbrace>!\"\n   apply(simp add:rb_enq_c_fun_def)\n  apply(wp_once)+\n  apply(auto simp:rb_can_enq_c_fun_def)\n  apply(wp_once)+\n  apply(simp add:c_rb_valid_def word_less_nat_alt) \n  by (meson INT_MIN_MAX_lemmas(12) Suc_leI le_eq_less_or_eq less_le_trans un_ui_le)\n\nlemma c_rb_enq_preserves_tail2 :\n  fixes rb :: \"rb_C ptr\"\n  shows\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and>  tail_C (heap_rb_C s rb) = k \\<rbrace>\n   rb_enq_c_fun rb b\n   \\<lbrace> \\<lambda> r s.  tail_C (heap_rb_C s rb) = k  \\<rbrace>!\"\n   apply(simp add:rb_enq_c_fun_def)\n  apply(wp_once)+\n  apply(auto simp:rb_can_enq_c_fun_def)\n  apply(wp_once)+\n  apply(simp add:c_rb_valid_def word_less_nat_alt) \n  by (meson INT_MIN_MAX_lemmas(12) Suc_le_eq less_imp_le_nat less_le_trans un_ui_le)\n\n\ntext \\<open>\n  If the queue is full, and the enqueue operation cannot put another buffer into\n  the ring, then the ring buffer remains in the same state. .\n\\<close>\n\n\nlemma c_rb_enq_preserves_head :\n  fixes rb :: \"rb_C ptr\"\n  shows\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s \\<and> rb_can_enq_c_fun rb = return (0)  \\<rbrace>\n   rb_enq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. head_C (heap_rb_C s rb) = head_C (heap_rb_C s0 rb)  \\<rbrace>!\"\n   apply(simp add:rb_enq_c_fun_def)\n   apply(wp_once)+\n   apply(smt hoare_assume_preNF validNF_chain validNF_return)\n   done\n\nlemma c_rb_enq_preserves_head2 :\n  fixes rb :: \"rb_C ptr\"\n  shows\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> head_C (heap_rb_C s rb) = k \\<and> rb_can_enq_c_fun rb = return (0) \\<rbrace>\n   rb_enq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. head_C (heap_rb_C s rb) = k \\<rbrace>!\"\n   apply(simp add:rb_enq_c_fun_def)\n   apply(wp_once)+\n   apply(smt hoare_assume_preNF validNF_chain validNF_return)\n   done\n \nlemma c_rb_enq_preserves_ring :\n  fixes rb :: \"rb_C ptr\"\n  shows\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s \\<and> rb_can_enq_c_fun rb = return (0)  \\<rbrace>\n   rb_enq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. ring_C (heap_rb_C s rb) = ring_C (heap_rb_C s0 rb)  \\<rbrace>!\"\n   apply(simp add:rb_enq_c_fun_def)\n   apply(wp_once)+\n   apply(smt hoare_assume_preNF validNF_chain validNF_return)\n   done\n\n\nlemma c_rb_enq_preserves_ring2 :\n  fixes rb :: \"rb_C ptr\"\n  shows\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> ring_C (heap_rb_C s rb) = k \\<and> rb_can_enq_c_fun rb = return (0) \\<rbrace>\n   rb_enq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. ring_C (heap_rb_C s rb) = k  \\<rbrace>!\"\n   apply(simp add:rb_enq_c_fun_def)\n   apply(wp_once)+\n   apply(smt hoare_assume_preNF validNF_chain validNF_return)\n   done\n\ntext \\<open>\n  Also, the ring contents are not changed, if we're full\n\\<close>\n\nlemma c_rb_enq_full_preserves_ring_contents :\n  fixes rb :: \"rb_C ptr\"\n  shows\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s \\<and> rb_can_enq_c_fun rb = return (0) \\<rbrace>\n   rb_enq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. heap_buffer_C s (ring_C (heap_rb_C s rb)  +\\<^sub>p uint i) = \n            heap_buffer_C s0 (ring_C (heap_rb_C s0 rb) +\\<^sub>p uint i)  \\<rbrace>!\"\n  apply(simp add:rb_enq_c_fun_def)\n  apply(wp_once)+\n  by(smt hoare_assume_preNF validNF_chain validNF_return)\n\n\ntext \\<open>\n  In fact, if the ring buffer is full, then the state is not altered at all.\n\\<close>\n\nlemma c_rb_enq_full_preserves_state:\n  fixes rb :: \"rb_C ptr\" and b :: buffer_C\n  shows \"\n   \\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s \\<and> rb_can_enq_c_fun rb =  return (0)  \\<rbrace>\n   rb_enq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. r \\<noteq> 0 \\<and> s = s0 \\<rbrace>!\"\n   apply(simp add:rb_enq_c_fun_def)\n  apply(wp_once)+\n  apply(simp)\n  apply (smt hoare_assume_preNF validNF_chain validNF_return)\n  done\n\n\ntext \\<open>\n  We can show that the enqueue function preserves the valid predicate.\n\\<close>\n\nlemma c_rb_enq_remains_valid:\n  fixes rb :: \"rb_C ptr\" and b :: buffer_C\n  shows \"\n   \\<lbrace> \\<lambda>s. c_rb_valid s rb  \\<rbrace>\n   rb_enq_c_fun rb b\n   \\<lbrace> \\<lambda> r s.  c_rb_valid s rb \\<rbrace>!\"\n  apply(simp add:rb_enq_c_fun_def)\n  apply(wp_once)+\n  apply(simp add:rb_can_enq_c_fun_def)\n  apply(wp_once)+\n  apply(simp add:c_rb_valid_def )\n  by (meson INT_MIN_MAX_lemmas(12) less_eq_Suc_le less_trans not_less unat_1_0 \n            unat_32word_leq_lt_lt word_le_less_eq word_less_1 word_less_def \n            word_mod_less_divisor)\n\n  \ntext \\<open>\n  Lastly, we can show that the C implementation of the enqueue operation produces the \n  same outcome as doing the abstraction operation.\n\\<close>\n\nlemma c_rb_enq_state_update_head:\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s  \\<and> rb0 = rb_C_to_CleanQ_RB s rb   \\<rbrace>\n   rb_enq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. (r = ERR_OK \\<or> r = ERR_QUEUE_FULL) \\<and> \n         (if r = ERR_OK then head (rb_C_to_CleanQ_RB s rb) = head (rb_enq b rb0)\n         else s = s0) \\<rbrace>!\"\n  unfolding rb_enq_c_fun_def  rb_C_to_CleanQ_RB_def rb_enq_equiv rb_enq_alt_def\n  apply(wp_once)+\n  apply(simp add:rb_can_enq_c_fun_def)\n  apply(wp_once)+\n  apply(auto simp:c_rb_valid_def unat_32word_succ_mod Suc_leI unat_32word_leq_lt_lt \n                  word_less_nat_alt)\n  using word_le_def word_le_less_eq word_less_nat_alt by blast\n\nlemma c_rb_enq_state_update_tail:\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s  \\<and> rb0 = rb_C_to_CleanQ_RB s rb   \\<rbrace>\n   rb_enq_c_fun rb b\n   \\<lbrace> \\<lambda> r s.  (r = ERR_OK \\<or> r = ERR_QUEUE_FULL) \\<and> \n       tail (rb_C_to_CleanQ_RB s rb) = tail (rb_enq b rb0)  \\<rbrace>!\"\n  unfolding rb_enq_c_fun_def rb_C_to_CleanQ_RB_def\n  apply(wp_once)+\n  apply(auto simp:rb_can_enq_c_fun_def)\n  apply(wp_once)+\n  apply(auto simp: rb_enq_alt_def rb_enq_equiv c_rb_valid_def word_less_nat_alt Suc_leI \n                   unat_32word_leq_lt_lt)\n  by (meson le_eq_less_or_eq un_ui_le)\n\nlemma c_rb_enq_state_update_size:\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s  \\<and> rb0 = rb_C_to_CleanQ_RB s rb   \\<rbrace>\n   rb_enq_c_fun rb b\n   \\<lbrace> \\<lambda> r s.  (r = ERR_OK \\<or> r = ERR_QUEUE_FULL) \\<and> \n       size (rb_C_to_CleanQ_RB s rb) = size (rb_enq b rb0)  \\<rbrace>!\"\n  unfolding rb_enq_c_fun_def rb_C_to_CleanQ_RB_def\n  apply(wp_once)+\n  apply(auto simp:rb_can_enq_c_fun_def)\n  apply(wp_once)+\n  apply(auto simp: rb_enq_alt_def rb_enq_equiv c_rb_valid_def word_less_nat_alt Suc_leI \n                   unat_32word_leq_lt_lt)\n  by (meson le_eq_less_or_eq un_ui_le)\n  \n\n\nlemma c_ring_ptr_different:\nassumes neq: \"x \\<noteq> unat (head_C (heap_rb_C s0 rb)) \\<and> x < unat (size_C (heap_rb_C s0 rb))\" \n    and valid: \"c_rb_valid s0 rb\"\n  shows \"ring_C (heap_rb_C s0 rb) +\\<^sub>p int x \\<noteq> ring_C (heap_rb_C s0 rb) +\\<^sub>p uint (head_C (heap_rb_C s0 rb))\"\nproof-\n  have sizelimit:\n    \"(size_C (heap_rb_C s0 rb)) \\<le> 0xffffffff\"\n    by (metis word_and_le1 word_and_max_simps(3))\n\n  have unatsizelimit:\n    \"unat (size_C (heap_rb_C s0 rb)) \\<le> 0xffffffff\"\n    using sizelimit UINT_MAX_def by auto\n\n  have head_leq_size:\n     \"unat (head_C (heap_rb_C s0 rb)) < unat (size_C (heap_rb_C s0 rb))\"\n    using valid unfolding c_rb_valid_def\n    using unat_word_lt by blast\n\n  from head_leq_size unatsizelimit have headlim:\n     \"unat (head_C (heap_rb_C s0 rb)) \\<le> 0xffffffff\"\n    by linarith\n\n  have clim:\n    \"\\<And>(c::64 word). c \\<le> 0x40 \\<Longrightarrow> unat c \\<le> 0x40\"\n    using unat_word_leq by fastforce\n\n  have xlim:\n    \"x \\<le> 0xffffffff\"\n    using neq unatsizelimit by linarith\n\n  have inrangex: \n    \"\\<And>(c::64 word). (c::64 word)\\<le> 0x40 \\<Longrightarrow> x * unat(c::64 word) \\<le> unat addrlimit\"\n    using xlim clim mult_le_mono  by fastforce  \n\n  have inrangey: \n    \"\\<And>(c::64 word). c \\<le> 0x40 \\<Longrightarrow> unat (head_C (heap_rb_C s0 rb)) * unat (c) \\<le> unat addrlimit\"\n     using headlim clim unat_word_leq  mult_le_mono \n     by fastforce\n     \n  have ineq:\n    \"\\<And>c. 0 < c \\<Longrightarrow>  c \\<le> 0x40 \\<Longrightarrow> of_nat x * (c::ulong_t) \\<noteq> of_int (uint (head_C (heap_rb_C s0 rb))) * (c::ulong_t)\"\n    proof -\n      have f1: \"\\<forall>w n. of_int (int n) * (w::64 word) = of_int (int (n * unat w))\"\n        by simp\n      have \"\\<And>c. 0 < c \\<Longrightarrow> unat (head_C (heap_rb_C s0 rb)) * unat (c::64 word) \\<noteq> x * unat (c::64 word)\"\n      using neq clim headlim unat_word_lt by fastforce \n    then have \"\\<And>c.  0 < c \\<Longrightarrow> c \\<le> 0x40 \\<Longrightarrow> (of_int (int x)::64 word) * c \\<noteq> of_int (int (unat (head_C (heap_rb_C s0 rb)))) * c\"\n    using f1 by (metis (no_types) inrangex inrangey le_unat_uoi of_int_of_nat_eq)\n    then show \"\\<And>c. 0 < c \\<Longrightarrow> c \\<le> 0x40 \\<Longrightarrow> of_nat x * (c::ulong_t) \\<noteq> of_int (uint (head_C (heap_rb_C s0 rb))) * (c::ulong_t)\"\n    by (simp add: int_unat)\n    qed\n\n  thus ?thesis unfolding ptr_add_def\n    by(auto)\nqed\n\nlemma c_rb_enq_state_update_ring_other:\nassumes neq: \"x \\<noteq> unat (head_C (heap_rb_C s0 rb)) \\<and> x < unat (size_C (heap_rb_C s0 rb))\"\n    and valid: \"c_rb_valid s0 rb\"\n    and supd: \"s = heap_buffer_C_update \n                          (\\<lambda>a. a(ring_C (heap_rb_C s0 rb) \n                                +\\<^sub>p uint (head_C (heap_rb_C s0 rb)) := b)) s0\"\n  shows \"heap_buffer_C s (ring_C (heap_rb_C s rb) +\\<^sub>p int x)\n        = heap_buffer_C s0 (ring_C (heap_rb_C s0 rb) +\\<^sub>p int x)\"\n  apply(subst supd)+ \n  using neq valid unfolding c_rb_valid_def apply(simp)\n  using valid unfolding c_rb_valid_def \n  by (simp add: CleanQ_SimpleQ.c_ring_ptr_different valid)\n\n\nlemma c_rb_enq_state_update_ring_head:\n  assumes eq: \"x = unat (head_C (heap_rb_C s0 rb))\"\n     and supd: \"s = heap_buffer_C_update \n                        (\\<lambda>a. a(ring_C (heap_rb_C s0 rb)\n                               +\\<^sub>p uint (head_C (heap_rb_C s0 rb)) := b)) s0\"\n  shows \"heap_buffer_C s (ring_C (heap_rb_C s rb) +\\<^sub>p int x) = b\"\n  using eq  by (simp add: int_unat supd)\n\nlemma c_rb_enq_state_ring_lifted_head:\n  assumes eq:  \"x = unat (head_C (heap_rb_C s rb))\"\n    shows  \"ring (rb_enq b (rb_C_to_CleanQ_RB s rb)) x = Some b\"\n  unfolding rb_C_to_CleanQ_RB_def rb_enq_alt_def rb_enq_equiv\n  using eq by(auto)\n\nlemma c_rb_enq_state_ring_lifted_other:\n  assumes eq:  \"x \\<noteq> unat (head_C (heap_rb_C s rb))\"\n    shows  \"ring (rb_enq b (rb_C_to_CleanQ_RB s rb)) x = ring (rb_C_to_CleanQ_RB s rb) x\"\n  unfolding rb_C_to_CleanQ_RB_def rb_enq_alt_def rb_enq_equiv\n  using eq by(auto)\n\nlemma c_rb_enq_state_ring_head:\n  assumes eq:  \"x = unat (head_C (heap_rb_C s0 rb))\" \n     and supd: \"s = heap_buffer_C_update \n                        (\\<lambda>a. a(ring_C (heap_rb_C s0 rb)\n                                         +\\<^sub>p uint (head_C (heap_rb_C s0 rb)) := b)) s0\"\n     and hupd: \"s1 = heap_rb_C_update\n                        (\\<lambda>a. a(rb := head_C_update (\\<lambda>a. \n                              (a + (1)) mod size_C (heap_rb_C s0 rb)) (a rb))) s\"\n     and valid: \"c_rb_valid s0 rb\"\n   shows \"ring (rb_C_to_CleanQ_RB s1 rb) x = Some b\"\n   apply(auto simp:rb_C_to_CleanQ_RB_def)\n  unfolding rb_C_to_CleanQ_RB_def using eq valid  \n   apply(auto simp:supd hupd int_unat c_rb_valid_def)\n  using unat_word_lt by blast\n  \n\nlemma c_rb_enq_state_update_ring:\n  fixes rb :: \"rb_C ptr\" and b :: buffer_C\n  assumes notfull: \" rb_can_enq_c_fun rb = return (1) \"\n  shows \"\n   \\<lbrace> \\<lambda>s. rb_can_enq_c_fun rb = return (1) \\<and> (c_rb_valid s rb \\<and> s0 = s \n                \\<and> rb0 = rb_C_to_CleanQ_RB s rb)   \\<rbrace>\n   rb_enq_c_fun rb b\n   \\<lbrace> \\<lambda> r s. \\<forall>i < size rb0. ring (rb_C_to_CleanQ_RB s rb) i = ring (rb_enq b rb0) i \\<rbrace>!\"\n  unfolding rb_enq_c_fun_def  rb_C_to_CleanQ_RB_def rb_enq_equiv rb_enq_alt_def\n  apply(wp_once)+\n  apply(subst notfull)+\n  apply(wp_once)+\n  apply(auto simp:fun_upd_def)\n       prefer 6 using c_rb_valid_def apply blast\n      prefer 5 using c_rb_valid_def less_imp_le word_le_def apply blast\n     prefer 4 using c_rb_valid_def unat_gt_0 apply fastforce \n    prefer 3 apply (simp add: int_unat)\n   prefer 2 apply (simp add: int_unat)\n  using CleanQ_SimpleQ.c_ring_ptr_different by blast\n\n\nlemma c_rb_enq_state_update_ring2:\n  \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s  \\<and> rb0 = rb_C_to_CleanQ_RB s rb   \\<rbrace>\n   rb_enq_c_fun rb b\n   \\<lbrace> \\<lambda> r s.  (r = ERR_OK \\<or> r = ERR_QUEUE_FULL) \\<and> \n         (if r = ERR_OK then (\\<forall>i < size rb0. ring (rb_C_to_CleanQ_RB s rb) i = ring (rb_enq b rb0) i) \n         else s = s0) \\<rbrace>!\"\n  unfolding rb_enq_c_fun_def  rb_C_to_CleanQ_RB_def rb_enq_equiv rb_enq_alt_def\n  apply(wp_once)+\n  apply(simp add:rb_can_enq_c_fun_def)\n  apply(wp_once)+\n  apply(auto simp:fun_upd_def)\n  using CleanQ_SimpleQ.c_ring_ptr_different apply blast\n  unfolding c_rb_valid_def\n  apply (simp_all add: int_unat)\n  using unat_gt_0 apply fastforce\n  using less_imp_le word_le_def apply blast\n  using INT_MIN_MAX_lemmas(12) Suc_leI  unat_32word_leq_lt_lt apply blast\n  using unat_gt_0 by fastforce     \n  \n   lemma enq_bufferhelper :\n  \"   heap_buffer_C\n                (heap_rb_C_update\n                  (\\<lambda>a::rb_C ptr \\<Rightarrow> rb_C. a\n                      (rb :=\n                         head_C_update\n                          (\\<lambda>a::32 word.\n                              (head_C (heap_rb_C (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring_C (heap_rb_C s0 rb) +\\<^sub>p uint (head_C (heap_rb_C s0 rb)) := b)) s0) rb) + (1::32 word)) mod\n                              size_C (heap_rb_C (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring_C (heap_rb_C s0 rb) +\\<^sub>p uint (head_C (heap_rb_C s0 rb)) := b)) s0) rb))\n                          (a rb)))\n                  (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring_C (heap_rb_C s0 rb) +\\<^sub>p uint (head_C (heap_rb_C s0 rb)) := b)) s0)) = \n\n\n   heap_buffer_C\n                \n                  (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring_C (heap_rb_C s0 rb) +\\<^sub>p uint (head_C (heap_rb_C s0 rb)) := b)) s0)\"\n\n     by(auto)\n\nlemma enq_ringhelper:\n\"\n \n                (ring_C\n                  (heap_rb_C\n                    (heap_rb_C_update\n                      (\\<lambda>a::rb_C ptr \\<Rightarrow> rb_C. a\n                          (rb :=\n                             head_C_update\n                              (\\<lambda>a::32 word.\n                                  (head_C (heap_rb_C (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring_C (heap_rb_C s0 rb) +\\<^sub>p uint (head_C (heap_rb_C s0 rb)) := b)) s0) rb) + (1::32 word)) mod\n                                  size_C (heap_rb_C (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring_C (heap_rb_C s0 rb) +\\<^sub>p uint (head_C (heap_rb_C s0 rb)) := b)) s0) rb))\n                              (a rb)))\n                      (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring_C (heap_rb_C s0 rb) +\\<^sub>p uint (head_C (heap_rb_C s0 rb)) := b)) s0))\n                    rb) +\\<^sub>p\n                 int i)\n\n = \n                (ring_C\n                  (heap_rb_C s0 rb) +\\<^sub>p                int i)\n\n\"\n\n  by(auto)\n\nlemma \n ring_upd_helper:\n \"(heap_buffer_C (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring_C (heap_rb_C s0 rb) +\\<^sub>p uint (head_C (heap_rb_C s0 rb)) := b)) s0) (ring_C (heap_rb_C s0 rb) +\\<^sub>p int i))\n  = (if i = unat (head_C (heap_rb_C s0 rb)) then b else (heap_buffer_C (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring_C (heap_rb_C s0 rb) +\\<^sub>p uint (head_C (heap_rb_C s0 rb)) := b)) s0) (ring_C (heap_rb_C s0 rb) +\\<^sub>p int i)))\"\n  apply(simp add: int_unat)\n\n  done\n\nlemmas unat_of_nat32' = unat_of_nat_eq[where 'a=32]\nlemmas unat_of_nat32 = unat_of_nat32'[unfolded word_bits_len_of]\n\nlemma ring_upd_helper2:\n  assumes ii:\" j \\<noteq> unat (head_C (heap_rb_C s0 rb)) \\<and>  j <  unat (size_C (heap_rb_C s0 rb)) \"\nshows  \" (heap_buffer_C (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring_C (heap_rb_C s0 rb) +\\<^sub>p uint (head_C (heap_rb_C s0 rb)) := b)) s0) (ring_C (heap_rb_C s0 rb) +\\<^sub>p int j))\n =(heap_buffer_C s0 (ring_C (heap_rb_C s0 rb) +\\<^sub>p int j))\"\nproof -\n  from ii have ilimit:\n    \"j < UINT_MAX\"\n    using INT_MIN_MAX_lemmas(12) less_le_trans by blast\n\n  have is64: \n    \"unat((0x40::64 word)) = 64\"\n    by(auto)\n\n  have inrangex: \"j * unat((0x40::64 word)) < 2 ^ 64\"\n    using ii ilimit apply(subst is64) by(auto simp:UINT_MAX_def)\n\n  have hlim:\n    \"unat (of_int (uint (head_C (heap_rb_C s0 rb)))::64 word)  \\<le> UINT_MAX\"\n    by (metis (mono_tags, hide_lams) INT_MIN_MAX_lemmas(12) int_unat le_less le_trans of_int_of_nat_eq unat_le_helper)\n  \n  have inrangey: \"unat (of_int (uint (head_C (heap_rb_C s0 rb)))::64 word) * unat((0x40::64 word)) < 2 ^ 64\"\n    using hlim apply(subst is64) by(auto simp:UINT_MAX_def)   \n\n    have hlim2:\n    \"unat (head_C (heap_rb_C s0 rb)) < 2 ^ 32\"\n      using unat_lt2p \n      by (metis len32)\n\n  have \"unat (head_C (heap_rb_C s0 rb)) = unat ((of_int (uint (head_C (heap_rb_C s0 rb)))::64 word))\"\n    using hlim2 apply(subst of_int_uint_ucast)\n    by(simp add:unat_ucast)\n    \n\n  have newq: \"j \\<noteq> unat ((of_int (uint (head_C (heap_rb_C s0 rb)))::64 word))\"\n    using ii hlim2\n    apply(subst of_int_uint_ucast)\n    by(simp add:unat_ucast)\n\n\n  have  \"x < 2^ 32 \\<Longrightarrow> unat ((of_nat x)::64 word) = x\"\n    by (simp add: unat_of_nat64 word_bits_conv)\n\n  have  \"x < 2^ 32 \\<Longrightarrow> unat ((of_nat x)::32 word) = x\"\n    by (simp add: unat_of_nat32 word_bits_conv)\n \n  have  \"x < 2^ 32 \\<Longrightarrow> unat ((of_nat x)::64 word) = unat ((of_nat x)::32 word)\"\n    by (simp add: unat_of_nat64 unat_of_nat32 word_bits_conv)\n\n  show ?thesis      \n  using ii inrangex inrangey newq apply(auto simp add:ptr_add_def)\n    by(simp add:word64_mult_inequality2)\n    \nqed\n\n\n\nlemma c_rb_enq_correct:\n   \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and> s0 = s \\<and> rb0 = rb_C_to_CleanQ_RB s rb  \\<rbrace>\n           rb_enq_c_fun rb b\n    \\<lbrace> \\<lambda>r s.  (r = ERR_OK \\<or> r = ERR_QUEUE_FULL) \\<and> \n              (if r = ERR_OK then rb_C_to_CleanQ_RB s rb = rb_enq b rb0\n               else s = s0) \\<rbrace>!\"\n  unfolding rb_enq_c_fun_def  rb_C_to_CleanQ_RB_def rb_enq_equiv rb_enq_alt_def\n  apply(wp_once)+\n  apply(simp add:rb_can_enq_c_fun_def)\n  apply(wp_once)+\n  apply(auto)\n  prefer 8 using c_rb_valid_def apply blast\n  prefer 7 using c_rb_valid_def unat_gt_0 apply fastforce\n  prefer 6 using INT_MIN_MAX_lemmas(12) Suc_leI c_rb_valid_def unat_32word_leq_lt_lt apply blast\n  prefer 5 using c_rb_valid_def apply blast \n  prefer 4 using c_rb_valid_def word_le_def word_le_less_eq apply blast\n  prefer 3 using c_rb_valid_def unat_gt_0 apply fastforce\n  prefer 2 using c_rb_valid_def unat_32word_succ_mod unat_word_lt apply fastforce\n  apply(subst enq_bufferhelper)\n  apply(subst enq_ringhelper)\n  apply(simp add:fun_upd_def)\n  apply(subst ring_upd_helper)\n  using ring_upd_helper2 c_rb_valid_def unat_word_lt \n  by fastforce\n\n  \n(* ####################################################### *)\n\n\nlemma \"rb_enq_c_fun rb b = rb_enq_unfolded_c_fun rb b\"\n  unfolding  rb_enq_c_fun_def  rb_enq_unfolded_c_fun_def rb_can_enq_c_fun_def\n  apply(monad_eq)\n  apply(auto simp add: int_unat)\n  done\n\n\nlemma \"rb_deq_c_fun rb b = rb_deq_unfolded_c_fun rb b\"\n  unfolding rb_deq_c_fun_def rb_deq_unfolded_c_fun_def rb_can_deq_c_fun_def\n  apply(monad_eq)  (* seems to take a while... *)\n  apply(auto simp add: int_unat)   (* seems to take a while... *)\n  done\n\n\n\nabbreviation \"rbhead s rb \\<equiv> unat (head_C (heap_rb_C s rb))\"\nabbreviation \"rbtail s rb \\<equiv> unat (tail_C (heap_rb_C s rb))\"\nabbreviation \"rbsize s rb \\<equiv> unat (size_C (heap_rb_C s rb))\"\nabbreviation \"rbring s rb \\<equiv> (ring_C (heap_rb_C s rb))\"\n\n\nlemma c_rb_enq_unfolded_ring_size_invariant:\n\"\\<lbrace> \\<lambda>s. c_rb_valid s rb  \\<and>  sz = rbsize s rb  \\<and>  rg = rbring s rb   \\<rbrace>\n rb_enq_unfolded_c_fun rb b\n\\<lbrace> \\<lambda>r s. sz = rbsize s rb  \\<and> rg = rbring s rb   \\<rbrace>!\"\n  unfolding rb_enq_unfolded_c_fun_def\n  apply(wp_once)+\n  by(auto simp:c_rb_valid_def unat_gt_0 Suc_le_eq unat_32word_leq_lt_lt \n               int_unat word_less_def)\n\nlemma c_rb_deq_unfolded_ring_size_invariant:\n\"\\<lbrace> \\<lambda>s. c_rb_valid s rb  \\<and>  sz = rbsize s rb  \\<and>  rg = rbring s rb  \\<and>  is_valid_buffer_C s b  \\<rbrace>\n rb_deq_unfolded_c_fun rb b\n\\<lbrace> \\<lambda>r s. sz = rbsize s rb  \\<and> rg = rbring s rb \\<rbrace>!\"\n  unfolding rb_deq_unfolded_c_fun_def\n  apply(wp_once)+\n  by(auto simp:c_rb_valid_def unat_gt_0 Suc_le_eq unat_32word_leq_lt_lt \n               int_unat word_less_def)\n\n\n\n\n\n\n\nlemma c_rb_enq_unfolded_pre_post:\n\"\\<lbrace> \\<lambda>s. c_rb_valid s rb    \n      \\<and> h = rbhead s rb   \n      \\<and> t = rbtail s rb   \n      \\<and> sz = rbsize s rb  \n      \\<and> rg = rbring s rb   \\<rbrace>\n rb_enq_unfolded_c_fun rb b\n\\<lbrace> \\<lambda>r s. (r = ERR_OK \\<longrightarrow> (h + 1) mod sz = rbhead s rb) \n        \\<and>  (\\<exists>\\<delta>. (t + \\<delta>) mod sz = rbtail s rb)\n        \\<and> (r \\<noteq> ERR_OK \\<longrightarrow> h = rbhead s rb)\n        \\<and> sz = rbsize s rb \n        \\<and> rg = rbring s rb   \\<rbrace>!\"\n  unfolding rb_enq_unfolded_c_fun_def\n  apply(wp_once)+\n  apply(auto simp:c_rb_valid_def unat_gt_0 unat_32word_leq_lt_lt int_unat \n                  Suc_leI  word_less_def)\n  apply (metis mod_div_mult_eq)\n  prefer 2 \n  apply (metis Euclidean_Division.mod_less int_unat mod_add_self2 of_nat_less_iff)\n  by (metis (no_types, hide_lams) int_unat of_nat_less_iff uint_1 unat_1 unat_32word_succ_mod word_less_def)\n\n\ntext \\<open>\n  The following two proofs show, using guard annotations, that the size, the ring, \n  and the head/tail pointers are invariant after every step in the programm.\n  The only thing that is changed by the program is the tail/head pointer. \n  -> the other size can do the change!\n\\<close>\n\ndefinition rb_enq_unfolded_c_fun_size_ring_anotate  :: \"nat \\<Rightarrow> nat \\<Rightarrow> buffer_C ptr \\<Rightarrow> rb_C ptr \\<Rightarrow> buffer_C \\<Rightarrow> (lifted_globals, 32 signed word) nondet_monad\"\n  where \"rb_enq_unfolded_c_fun_size_ring_anotate sz t rg rb c = \n do guard (\\<lambda>s::lifted_globals. is_valid_rb_C s rb);\n    guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  t = rbtail s rb );\n    head::nat <- gets (\\<lambda>s::lifted_globals. unat (head_C (heap_rb_C s rb)));\n    guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  t = rbtail s rb);\n    tail::nat <- gets (\\<lambda>s::lifted_globals. unat (tail_C (heap_rb_C s rb)));\n    guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  t = rbtail s rb );\n    size::nat <- gets (\\<lambda>s::lifted_globals. unat (size_C (heap_rb_C s rb)));\n    guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  t = rbtail s rb );\n    guard (\\<lambda>s::lifted_globals. (0::nat) < size);\n    guard (\\<lambda>s::lifted_globals. Suc head \\<le> UINT_MAX);\n    condition (\\<lambda>s::lifted_globals. Suc head mod size = tail)\n      (do guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb  \\<and>  t = rbtail s rb ); \n         return (-1::32 signed word)\n      od)\n      (do guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  t = rbtail s rb );\n          head2::nat <- gets (\\<lambda>s::lifted_globals. unat (head_C (heap_rb_C s rb)));\n          guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  t = rbtail s rb );\n          ring::buffer_C ptr <- gets (\\<lambda>s::lifted_globals. ring_C (heap_rb_C s rb));\n          guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  t = rbtail s rb );\n          guard (\\<lambda>s::lifted_globals. is_valid_buffer_C s (ring +\\<^sub>p int head2));\n          modify (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring +\\<^sub>p int head2 := region_C_update (\\<lambda>a::64 word. region_C c) (a (ring +\\<^sub>p int head2)))));\n          guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  t = rbtail s rb );\n          modify (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring +\\<^sub>p int head2 := offset_C_update (\\<lambda>a::64 word. offset_C c) (a (ring +\\<^sub>p int head2)))));\n          guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  t = rbtail s rb );\n          modify (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring +\\<^sub>p int head2 := length_C_update (\\<lambda>a::64 word. length_C c) (a (ring +\\<^sub>p int head2)))));\n          guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  t = rbtail s rb );\n          modify (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring +\\<^sub>p int head2 := valid_offset_C_update (\\<lambda>a::64 word. valid_offset_C c) (a (ring +\\<^sub>p int head2)))));\n          guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  t = rbtail s rb );\n          modify (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring +\\<^sub>p int head2 := valid_length_C_update (\\<lambda>a::64 word. valid_length_C c) (a (ring +\\<^sub>p int head2)))));\n          guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  t = rbtail s rb );\n          modify (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring +\\<^sub>p int head2 := flags_C_update (\\<lambda>a::64 word. flags_C c) (a (ring +\\<^sub>p int head2)))));\n          guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  t = rbtail s rb );\n          head3::nat <- gets (\\<lambda>s::lifted_globals. unat (head_C (heap_rb_C s rb)));\n          guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  t = rbtail s rb );\n          size3::nat <- gets (\\<lambda>s::lifted_globals. unat (size_C (heap_rb_C s rb)));\n          guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  t = rbtail s rb );\n          modify (heap_rb_C_update (\\<lambda>a::rb_C ptr \\<Rightarrow> rb_C. a(rb := head_C_update (\\<lambda>a::32 word. (of_nat head3 + (1::32 word)) mod of_nat size3) (a rb))));\n          guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  t = rbtail s rb );\n          return (0::32 signed word)\n       od)\n od\n\"\n\nlemma c_rb_enq_unfolded_ring_size_invariant2:\n\"\\<lbrace> \\<lambda>s. c_rb_valid s rb  \\<and>  sz = rbsize s rb  \\<and>  rg = rbring s rb \\<and> t = rbtail s rb  \\<rbrace>\n rb_enq_unfolded_c_fun_size_ring_anotate sz t rg rb b\n\\<lbrace> \\<lambda>r s. sz = rbsize s rb  \\<and> rg = rbring s rb   \\<rbrace>!\"\n  unfolding rb_enq_unfolded_c_fun_size_ring_anotate_def\n  apply(wp_once)+\n  apply(auto simp:c_rb_valid_def unat_gt_0 Suc_le_eq unat_32word_leq_lt_lt \n               int_unat word_less_def)\n  done\n\n\ndefinition rb_deq_unfolded_c_fun_size_ring_anotate  :: \"nat \\<Rightarrow> nat \\<Rightarrow> buffer_C ptr \\<Rightarrow> rb_C ptr \\<Rightarrow> buffer_C ptr \\<Rightarrow> (lifted_globals, 32 signed word) nondet_monad\"\n  where \"rb_deq_unfolded_c_fun_size_ring_anotate sz h rg rb ret = \ndo guard (\\<lambda>s::lifted_globals. is_valid_rb_C s rb);\n   guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  h = rbhead s rb );\n   head::nat <- gets (\\<lambda>s::lifted_globals. unat (head_C (heap_rb_C s rb)));\n   guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  h = rbhead s rb );\n   tail::nat <- gets (\\<lambda>s::lifted_globals. unat (tail_C (heap_rb_C s rb)));\n   guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  h = rbhead s rb );\n   condition (\\<lambda>s::lifted_globals. head = tail)\n     (do guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  h = rbhead s rb ); \n         return (0xFFFFFFFE::32 signed word)\n      od)\n     (do guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  h = rbhead s rb );\n         tail1::nat <- gets (\\<lambda>s::lifted_globals. unat (tail_C (heap_rb_C s rb)));\n         guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb  \\<and>  h = rbhead s rb);\n         ring::buffer_C ptr <- gets (\\<lambda>s::lifted_globals. ring_C (heap_rb_C s rb));\n         guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  h = rbhead s rb );\n         guard (\\<lambda>s::lifted_globals. is_valid_buffer_C s ret);\n         guard (\\<lambda>s::lifted_globals. is_valid_buffer_C s (ring +\\<^sub>p int tail1));\n         modify (\\<lambda>s::lifted_globals. heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ret := region_C_update (\\<lambda>a::64 word. region_C (heap_buffer_C s (ring +\\<^sub>p int tail1))) (a ret))) s);\n         guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  h = rbhead s rb );\n         modify (\\<lambda>s::lifted_globals. heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ret := offset_C_update (\\<lambda>a::64 word. offset_C (heap_buffer_C s (ring +\\<^sub>p int tail1))) (a ret))) s);\n         guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  h = rbhead s rb );\n         modify (\\<lambda>s::lifted_globals. heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ret := length_C_update (\\<lambda>a::64 word. length_C (heap_buffer_C s (ring +\\<^sub>p int tail1))) (a ret))) s);\n         guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  h = rbhead s rb );\n         modify (\\<lambda>s::lifted_globals. heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ret := valid_offset_C_update (\\<lambda>a::64 word. valid_offset_C (heap_buffer_C s (ring +\\<^sub>p int tail1))) (a ret))) s);\n         guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  h = rbhead s rb );\n         modify (\\<lambda>s::lifted_globals. heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ret := valid_length_C_update (\\<lambda>a::64 word. valid_length_C (heap_buffer_C s (ring +\\<^sub>p int tail1))) (a ret))) s);\n         guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  h = rbhead s rb );\n         modify (\\<lambda>s::lifted_globals. heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ret := flags_C_update (\\<lambda>a::64 word. flags_C (heap_buffer_C s (ring +\\<^sub>p int tail1))) (a ret))) s);\n         guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  h = rbhead s rb );\n         size::nat <- gets (\\<lambda>s::lifted_globals. unat (size_C (heap_rb_C s rb)));\n         guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  h = rbhead s rb );\n         tail2::nat <- gets (\\<lambda>s::lifted_globals. unat (tail_C (heap_rb_C s rb)));\n         guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  h = rbhead s rb );\n         guard (\\<lambda>s::lifted_globals. (0::nat) < size);\n         guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb \\<and>  h = rbhead s rb );\n         modify (heap_rb_C_update (\\<lambda>a::rb_C ptr \\<Rightarrow> rb_C. a(rb := tail_C_update (\\<lambda>a::32 word. (of_nat tail2 + (1::32 word)) mod of_nat size) (a rb))));\n         guard (\\<lambda>s::lifted_globals. sz = rbsize s rb \\<and> rg = rbring s rb  \\<and>  h = rbhead s rb );\n         return (0::32 signed word)\n      od)\nod\"\n\n\nlemma c_rb_deq_unfolded_ring_size_invariant2:\n\"\\<lbrace> \\<lambda>s. c_rb_valid s rb  \\<and>  sz = rbsize s rb  \\<and>  rg = rbring s rb  \\<and>  h = rbhead s rb \\<and>\n       is_valid_buffer_C s b\n  \\<rbrace>\n rb_deq_unfolded_c_fun_size_ring_anotate sz h rg rb b\n\\<lbrace> \\<lambda>r s. sz = rbsize s rb  \\<and> rg = rbring s rb \\<and>  h = rbhead s rb \\<rbrace>!\"\n  unfolding rb_deq_unfolded_c_fun_size_ring_anotate_def\n  apply(wp_once)+\n  by(auto simp:c_rb_valid_def unat_gt_0 Suc_le_eq unat_32word_leq_lt_lt \n               int_unat word_less_def)\n\n\n\n\n\nthm rb_enq_unfolded_c_fun_def\nterm rb_enq_unfolded_c_fun\nthm rb_deq_unfolded_c_fun_def\n\n\ndefinition rb_enq_test :: \"rb_C ptr \\<Rightarrow> buffer_C \\<Rightarrow> (lifted_globals, 32 signed word) nondet_monad\"\n  where \n\"rb_enq_test rb slot \\<equiv>\n do guard (\\<lambda>s::lifted_globals. is_valid_rb_C s rb);\n  head::nat <- gets (\\<lambda>s::lifted_globals. unat (head_C (heap_rb_C s rb)));\n  guard (\\<lambda>s::lifted_globals. head \\<le> UINT_MAX);\n  tail::nat <- gets (\\<lambda>s::lifted_globals. unat (tail_C (heap_rb_C s rb)));\n  size::nat <- gets (\\<lambda>s::lifted_globals. unat (size_C (heap_rb_C s rb)));\n  guard (\\<lambda>s::lifted_globals. (0::nat) < size);\n  guard (\\<lambda>s::lifted_globals. Suc head \\<le> UINT_MAX);\n  condition (\\<lambda>s::lifted_globals. Suc head mod size = tail)\n  (return (- (1::32 signed word)))\n  (do head2::nat <- gets (\\<lambda>s::lifted_globals. unat (head_C (heap_rb_C s rb)));\n      ring::buffer_C ptr <- gets (\\<lambda>s::lifted_globals. ring_C (heap_rb_C s rb));\n      guard (\\<lambda>s::lifted_globals. is_valid_buffer_C s (ring +\\<^sub>p int head2));\n      modify (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring +\\<^sub>p int head2 := region_C_update (\\<lambda>a::64 word. region_C slot) (a (ring +\\<^sub>p int head2)))));\n      modify (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring +\\<^sub>p int head2 := offset_C_update (\\<lambda>a::64 word. offset_C slot) (a (ring +\\<^sub>p int head2)))));\n      modify (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring +\\<^sub>p int head2 := length_C_update (\\<lambda>a::64 word. length_C slot) (a (ring +\\<^sub>p int head2)))));\n      modify (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring +\\<^sub>p int head2 := valid_offset_C_update (\\<lambda>a::64 word. valid_offset_C slot) (a (ring +\\<^sub>p int head2)))));\n      modify (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring +\\<^sub>p int head2 := valid_length_C_update (\\<lambda>a::64 word. valid_length_C slot) (a (ring +\\<^sub>p int head2)))));\n      modify (heap_buffer_C_update (\\<lambda>a::buffer_C ptr \\<Rightarrow> buffer_C. a(ring +\\<^sub>p int head2 := flags_C_update (\\<lambda>a::64 word. flags_C slot) (a (ring +\\<^sub>p int head2)))));\n      head3::nat <- gets (\\<lambda>s::lifted_globals. unat (head_C (heap_rb_C s rb)));\n      size3::nat <- gets (\\<lambda>s::lifted_globals. unat (size_C (heap_rb_C s rb)));\n      modify (heap_rb_C_update (\\<lambda>a::rb_C ptr \\<Rightarrow> rb_C. a(rb := head_C_update (\\<lambda>a::32 word. (of_nat head3 + (1::32 word)) mod of_nat size3) (a rb))));\n      guard (\\<lambda>s::lifted_globals. unat (head_C (heap_rb_C s rb)) = ( head3 + 1) mod size3);\n      return (0::32 signed word)\n   od)\n  od\"\n\n\ndefinition rb_enq_e1 :: \"rb_C ptr \\<Rightarrow> buffer_C \\<Rightarrow> (lifted_globals, 32 signed word) nondet_monad\"\n  where \n\"rb_enq_e1 rb slot \\<equiv>\n do guard (\\<lambda>s::lifted_globals. is_valid_rb_C s rb);\n  head::nat <- gets (\\<lambda>s::lifted_globals. unat (head_C (heap_rb_C s rb)));\n  return (0::32 signed word)\n  od\"\n\n\nabbreviation \"rbhead s rb \\<equiv> unat (head_C (heap_rb_C s rb))\"\nabbreviation \"rbtail s rb \\<equiv> unat (tail_C (heap_rb_C s rb))\"\nabbreviation \"rbsize s rb \\<equiv> unat (size_C (heap_rb_C s rb))\"\nabbreviation \"rbring s rb \\<equiv> (ring_C (heap_rb_C s rb))\"\n\nlemma test:\n\"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and>  h = rbhead s rb  \\<rbrace>\n     do \n       head::nat <- gets (\\<lambda>s. rbhead s rb); return (0)\n     od\n \\<lbrace> \\<lambda>r s. h = rbhead s rb \\<rbrace>!\"\n  unfolding rb_enq_e1_def\n  apply(wp_once)+\n  by(auto simp:c_rb_valid_def)\n\n\nlemma \"rb_enq_test rb slot = rb_enq_unfolded_c_fun rb slot\"\n  unfolding rb_enq_test_def rb_enq_unfolded_c_fun_def\n  apply(monad_eq)  (* seems to take a while... *)\n  apply(auto)\n  sledgehammer\n   apply (simp add: unat_mod)\n  \n  apply (simp add: unat_mod)\n  done\n\n\nlemma test:\n   \"\\<lbrace> \\<lambda>s. c_rb_valid s rb \\<and>  h = unat (head_C (heap_rb_C s rb)) \\<and>  is_valid_buffer_C s b  \\<rbrace>\n           rb_deq_c_fun rb b\n    \\<lbrace> \\<lambda>r s. h = unat (head_C (heap_rb_C s rb)) \\<rbrace>!\"\n  unfolding rb_deq_c_fun_def  rb_can_deq_c_fun_def\n  apply(wp_once)+\n  apply(auto)\n  using c_rb_valid_def apply blast\n  using c_rb_valid_def unat_gt_0 apply fastforce\n  using c_rb_valid_def word_le_def word_le_less_eq apply blast \n  using c_rb_valid_def apply blast\n  done\n\nlemma \"(a::nat) \\<le> 64 \\<Longrightarrow> (b::nat) < 2^32 \\<Longrightarrow> a * b < 2^64\"\nproof -\n  assume p1 :\"(a::nat) \\<le> 64\"\n  assume p2: \"(b::nat) < 2^32\"\n\n  have x1: \"(64::nat) * 2^32  \\<le> 2^64\"\n    by(simp)\n\n  have x2: \"(a::nat) \\<le> 64 \\<Longrightarrow> (b::nat) < 2^32 \\<Longrightarrow>  a * b < 64 * 2^32\" \n    by (meson le_less_trans mult_less_cancel1 mult_right_mono zero_le zero_less_numeral)\n\n  show ?thesis using order_trans x2 x1 p1 p2 \n    by linarith\nqed\n  \n\nlemma \"(a::nat) < 2^32 \\<Longrightarrow> (b::nat) < 2^32 \\<Longrightarrow> a * b < 2^64\"\nproof -\n  assume p1 :\"(a::nat) < 2^32\"\n  assume p2: \"(b::nat) < 2^32\"\n  \n  have X1: \"(0xffffffff::nat) * 0xffffffff \\<le> 0xffffffffffffffff\"\n    by(auto)\n\n  have X2: \"(a::nat) \\<le> 0xffffffff \\<Longrightarrow> (b::nat) \\<le> 0xffffffff \\<Longrightarrow> a * b \\<le> 0xffffffffffffffff\"\n    using X1 mult_le_mono order_trans by blast\n\n  have X3: \"(a::nat) <  2^32 \\<Longrightarrow> (b::nat) < 2^32 \\<Longrightarrow>  a * b < (2^32 * 2^32)\"\n    using X2  by simp\n\n  show ?thesis\n    using p1 p2 X3 by auto\nqed\n\n\n(* SimpleQ C parser output. *)\n\nthm simpleq_enq_body_def\nthm simpleq_deq_body_def\nthm simpleq_enq_x_body_def\nthm simpleq_enq_y_body_def\nthm simpleq_deq_x_body_def\nthm simpleq_deq_y_body_def\n\n(* SimpleQ Init C parser output. *)\nthm init_x_body_def\nthm init_y_body_def\nthm init_queue_body_def\n\n\nend\nend\n", "meta": {"author": "CleanQ-Project", "repo": "cleanq-proofs", "sha": "5212fcd2aceba0028bd1474e0553578a6091ca63", "save_path": "github-repos/isabelle/CleanQ-Project-cleanq-proofs", "path": "github-repos/isabelle/CleanQ-Project-cleanq-proofs/cleanq-proofs-5212fcd2aceba0028bd1474e0553578a6091ca63/CleanQ/CleanQ_SimpleQ.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297745935070808, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.28789309001719704}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\n(* License: BSD, terms see file ./LICENSE *)\n\ntheory Addr_Type\nimports \"~~/src/HOL/Word/Word\"\nbegin\n\ntype_synonym addr_bitsize = \"32\"\ntype_synonym addr = \"addr_bitsize word\"\ndefinition addr_bitsize :: nat where \"addr_bitsize \\<equiv> 32\"\ndefinition addr_align :: nat where \"addr_align \\<equiv> 2\"\ndeclare addr_align_def[simp]\n\ndefinition addr_card :: nat where\n  \"addr_card \\<equiv> card (UNIV::addr set)\"\n  \n\n\ndeclare addr_bitsize_def[simp]\n\nlemma addr_card:\n  \"addr_card = 2^addr_bitsize\"\n  by (simp add: addr_card_def card_word)\n\nlemma len_of_addr_card:\n  \"2 ^ len_of TYPE(addr_bitsize) = addr_card\"\n  by (simp add: addr_card)\n\nlemma of_nat_addr_card [simp]:\n  \"of_nat addr_card = (0::addr)\"\n  by (simp add: addr_card)\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/l4v/tools/c-parser/umm_heap/ARM/Addr_Type.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318337259584, "lm_q2_score": 0.476579651063676, "lm_q1q2_score": 0.28782162258336325}}
{"text": "(* @TAG(OTHER_LGPL) *)\n\n(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      Generalise.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2005-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\ntheory Generalise imports \"~~/src/HOL/Statespace/DistinctTreeProver\"\nbegin\n\nlemma protectRefl: \"PROP Pure.prop (PROP C) \\<Longrightarrow> PROP Pure.prop (PROP C)\"\n  by (simp add: prop_def)\n\nlemma protectImp: \n assumes i: \"PROP Pure.prop (PROP P \\<Longrightarrow> PROP Q)\" \n shows \"PROP Pure.prop (PROP Pure.prop P \\<Longrightarrow> PROP Pure.prop Q)\"\nproof -\n  {\n    assume P: \"PROP Pure.prop P\"\n    from i [unfolded prop_def, OF P [unfolded prop_def]] \n    have \"PROP Pure.prop Q\"\n      by (simp add: prop_def)\n  }\n  note i' = this\n  show \"PROP ?thesis\" \n    apply (rule protectI)\n    apply (rule i')\n    apply assumption\n    done\nqed\n\n\nlemma generaliseConj: \n  assumes i1: \"PROP Pure.prop (PROP Pure.prop (Trueprop P) \\<Longrightarrow> PROP Pure.prop (Trueprop Q))\"\n  assumes i2: \"PROP Pure.prop (PROP Pure.prop (Trueprop P') \\<Longrightarrow> PROP Pure.prop (Trueprop Q'))\"\n  shows \"PROP Pure.prop (PROP Pure.prop (Trueprop (P \\<and> P')) \\<Longrightarrow> (PROP Pure.prop (Trueprop (Q \\<and> Q'))))\"\n  using i1 i2\n  by (auto simp add: prop_def)\n\nlemma generaliseAll: \n assumes i: \"PROP Pure.prop (\\<And>s. PROP Pure.prop (Trueprop (P s)) \\<Longrightarrow> PROP Pure.prop (Trueprop (Q s)))\" \n shows \"PROP Pure.prop (PROP Pure.prop (Trueprop (\\<forall>s. P s)) \\<Longrightarrow> PROP Pure.prop (Trueprop (\\<forall>s. Q s)))\"\n  using i\n  by (auto simp add: prop_def)\n\nlemma generalise_all: \n assumes i: \"PROP Pure.prop (\\<And>s. PROP Pure.prop (PROP P s) \\<Longrightarrow> PROP Pure.prop (PROP Q s))\" \n shows \"PROP Pure.prop ((PROP Pure.prop (\\<And>s. PROP P s)) \\<Longrightarrow> (PROP Pure.prop (\\<And>s. PROP Q s)))\"\n  using i\n  proof (unfold prop_def)\n    assume i1: \"\\<And>s. (PROP P s) \\<Longrightarrow> (PROP Q s)\"\n    assume i2: \"\\<And>s. PROP P s\"\n    show \"\\<And>s. PROP Q s\"\n      by (rule i1) (rule i2)\n  qed\n\nlemma generaliseTrans: \n  assumes i1: \"PROP Pure.prop (PROP P \\<Longrightarrow> PROP Q)\"\n  assumes i2: \"PROP Pure.prop (PROP Q \\<Longrightarrow> PROP R)\" \n  shows \"PROP Pure.prop (PROP P \\<Longrightarrow> PROP R)\"\n  using i1 i2\n  proof (unfold prop_def)\n    assume P_Q: \"PROP P \\<Longrightarrow> PROP Q\" \n    assume Q_R: \"PROP Q \\<Longrightarrow> PROP R\" \n    assume P: \"PROP P\"\n    show \"PROP R\"\n      by (rule Q_R [OF P_Q [OF P]])\n  qed\n\nlemma meta_spec:\n  assumes \"\\<And>x. PROP P x\"\n  shows \"PROP P x\" by fact\n\nlemma meta_spec_protect:\n  assumes g: \"\\<And>x. PROP P x\"\n  shows \"PROP Pure.prop (PROP P x)\"\nusing g\nby (auto simp add: prop_def)\n\nlemma generaliseImp: \n  assumes i: \"PROP Pure.prop (PROP Pure.prop (Trueprop P) \\<Longrightarrow> PROP Pure.prop (Trueprop Q))\"\n  shows \"PROP Pure.prop (PROP Pure.prop (Trueprop (X \\<longrightarrow> P)) \\<Longrightarrow> PROP Pure.prop (Trueprop (X \\<longrightarrow> Q)))\"\n  using i\n  by (auto simp add: prop_def)\n\nlemma generaliseEx: \n assumes i: \"PROP Pure.prop (\\<And>s. PROP Pure.prop (Trueprop (P s)) \\<Longrightarrow> PROP Pure.prop (Trueprop (Q s)))\" \n shows \"PROP Pure.prop (PROP Pure.prop (Trueprop (\\<exists>s. P s)) \\<Longrightarrow> PROP Pure.prop (Trueprop (\\<exists>s. Q s)))\"\n  using i\n  by (auto simp add: prop_def)\n\n\nlemma generaliseRefl: \"PROP Pure.prop (PROP Pure.prop (Trueprop P) \\<Longrightarrow> PROP Pure.prop (Trueprop P))\"\n  by (auto simp add: prop_def)\n\nlemma generaliseRefl': \"PROP Pure.prop (PROP P \\<Longrightarrow> PROP P)\"\n  by (auto simp add: prop_def)\n\nlemma generaliseAllShift:\n  assumes i: \"PROP Pure.prop (\\<And>s. P \\<Longrightarrow> Q s)\"\n  shows \"PROP Pure.prop (PROP Pure.prop (Trueprop P) \\<Longrightarrow> PROP Pure.prop (Trueprop (\\<forall>s. Q s)))\"\n  using i\n  by (auto simp add: prop_def)\n\nlemma generalise_allShift:\n  assumes i: \"PROP Pure.prop (\\<And>s. PROP P \\<Longrightarrow> PROP Q s)\"\n  shows \"PROP Pure.prop (PROP Pure.prop (PROP P) \\<Longrightarrow> PROP Pure.prop (\\<And>s. PROP Q s))\"\n  using i\n  proof (unfold prop_def)\n    assume P_Q: \"\\<And>s. PROP P \\<Longrightarrow> PROP Q s\" \n    assume P: \"PROP P\"\n    show \"\\<And>s. PROP Q s\"\n      by (rule P_Q [OF P])\n  qed\n\n\nlemma generaliseImpl:\n  assumes i: \"PROP Pure.prop (PROP Pure.prop P \\<Longrightarrow> PROP Pure.prop Q)\"\n  shows \"PROP Pure.prop ((PROP Pure.prop (PROP X \\<Longrightarrow> PROP P)) \\<Longrightarrow> (PROP Pure.prop (PROP X \\<Longrightarrow> PROP Q)))\"\n  using i\n  proof (unfold prop_def)\n    assume i1: \"PROP P \\<Longrightarrow> PROP Q\"\n    assume i2: \"PROP X \\<Longrightarrow> PROP P\"\n    assume X: \"PROP X\"\n    show \"PROP Q\"\n      by (rule i1 [OF i2 [OF X]])\n  qed\n\n\nML_file \"generalise_state.ML\"\n\nend\n\n", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/c-parser/Simpl/Generalise.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5117166047041654, "lm_q2_score": 0.5621765008857982, "lm_q1q2_score": 0.28767505027774887}}
{"text": "(*****************************************************************************\n * ESPL --- an embedded security protocol logic\n *          http://people.inf.ethz.ch/meiersi/espl/\n *\n *   Copyright (c) 2009-2011, Simon Meier, ETH Zurich, Switzerland\n *\n * All rights reserved. See file LICENCE for more information.\n ******************************************************************************)\n(* Extensions to the standard HOL library *)\ntheory HOL_ext\nimports\n  Main\nbegin\n\n\nsection{* Maps *}\n\nlemma dom_upd [simp]: \n  \"dom (\\<lambda> a. if a = x then Some y else m a) = insert x (dom m)\"\n  by(fastforce simp: dom_if)\n\nlemma map_leD: \"\\<lbrakk> m \\<subseteq>\\<^sub>m m'; m x = Some y \\<rbrakk> \\<Longrightarrow> m' x = Some y\"\n  by(force simp: map_le_def)\n\nlemma rev_map_leD: \"\\<lbrakk>  m x = Some y; m \\<subseteq>\\<^sub>m m' \\<rbrakk> \\<Longrightarrow> m' x = Some y\"\n  by(force simp: map_le_def)\n\nlemma map_leI: \n  \"\\<lbrakk> \\<And> x y. m x = Some y \\<Longrightarrow> m' x = Some y \\<rbrakk> \\<Longrightarrow>  m \\<subseteq>\\<^sub>m m'\"\n  by(force simp: map_le_def)\n\n\nsection{* Option *}\n\nfun opt_map2 :: \"('a \\<Rightarrow> 'b \\<Rightarrow> 'c) \\<Rightarrow> 'a option \\<Rightarrow> 'b option \\<Rightarrow> 'c option\"\nwhere\n  \"opt_map2 f (Some x) (Some y) = Some (f x y)\"\n| \"opt_map2 f _        _        = None\"\n\nlemma Some_opt_map2 [simp]:\n  \"(Some x = opt_map2 f a b) =\n   (\\<exists> y z. x = f y z \\<and> Some y = a \\<and> Some z = b)\"\n  \"(opt_map2 f a b = Some x) =\n   (\\<exists> y z. x = f y z \\<and> Some y = a \\<and> Some z = b)\"\n  by (cases a, simp, cases b, simp_all add: eq_commute)+\n\nlemma Some_if_pushL [simp]:\n  \"(Some x = (if b then Some y else None)) = (b \\<and> x = y)\"\n  \"((if b then Some y else None) = Some x) = (b \\<and> x = y)\"\n  by (auto split: if_splits)\n\nlemma Some_if_pushR [simp]:\n  \"(Some x = (if b then None else Some y)) = (\\<not>b \\<and> x = y)\"\n  \"((if b then None else Some y) = Some x) = (\\<not>b \\<and> x = y)\"\n  by (auto split: if_splits)\n\nlemma Some_Option_map [simp]:\n  \"(Some x = map_option f a) = (\\<exists>y. x = f y \\<and> Some y = a)\"\n  \"(map_option f a = Some x) = (\\<exists>y. x = f y \\<and> Some y = a)\"\n  by (cases a, auto)+\n\n\nsection{* Variadic Functions *}\n\ndatatype ('a, 'b) varfun = Val 'b | Fun \"'a \\<Rightarrow> ('a, 'b) varfun\"\n\nprimrec var_map :: \"('b \\<Rightarrow> 'c) \\<Rightarrow> ('a, 'b) varfun \\<Rightarrow> ('a, 'c) varfun\"\nwhere\n  \"var_map f (Val x) = Val (f x)\"\n| \"var_map f (Fun g) = Fun (\\<lambda>x. var_map f (g x))\"\n\nprimrec var_apply :: \"('a, 'b \\<Rightarrow> 'c) varfun \\<Rightarrow> ('a, 'b) varfun \\<Rightarrow> ('a, 'c) varfun\"\nwhere\n  \"var_apply (Val f) v = var_map f v\"\n| \"var_apply (Fun g) v = Fun (\\<lambda>x. var_apply (g x) v)\"\n\nabbreviation var_lift2 :: \"('b \\<Rightarrow> 'c \\<Rightarrow> 'd) \\<Rightarrow> ('a, 'b) varfun \\<Rightarrow> ('a, 'c) varfun \\<Rightarrow> ('a, 'd) varfun\"\nwhere \"var_lift2 f v1 v2 \\<equiv> var_apply (var_map f v1) v2\"\n\nprimrec var_fold :: \"(('a \\<Rightarrow> 'b) \\<Rightarrow> 'b) \\<Rightarrow> ('a, 'b) varfun \\<Rightarrow> 'b\"\nwhere\n  \"var_fold f (Val x) = x\"\n| \"var_fold f (Fun g) = f (\\<lambda>x. var_fold f (g x))\"\n\n\nlemma var_map_map [simp]: \"var_map f (var_map g v) = var_map (f o g) v\"\nby (induct v) (auto)\n\nlemma var_fold_not_all: \"(\\<not> var_fold All v) = var_fold Ex (var_map Not v)\"\nby (induct v) (auto)\n\nlemma var_fold_not_ex: \"(\\<not> var_fold Ex v) = var_fold All (var_map Not v)\"\nby (induct v) (auto)\n\n\nsection{* Finite Sets *}\n\ntext{* \n  Automating the simplification of differences of finite sets. \n*}\nlemma eq_conj_neq: \n  \"y \\<noteq> z \\<Longrightarrow> (x = y \\<and> x \\<noteq> z) = (x = y)\"\n  \"y \\<noteq> z \\<Longrightarrow> (x = y \\<and> (x \\<noteq> z \\<and> P)) = ((x = y) \\<and> P)\"\n  \"y \\<noteq> z \\<Longrightarrow> (x = y \\<and> (P \\<and> x \\<noteq> z)) = ((x = y) \\<and> P)\"\n  \"y \\<noteq> z \\<Longrightarrow> (x \\<noteq> z \\<and> x = y) = (x = y)\"\n  \"y \\<noteq> z \\<Longrightarrow> ((x \\<noteq> z \\<and> P) \\<and> x = y) = ((x = y) \\<and> P)\"\n  \"y \\<noteq> z \\<Longrightarrow> ((P \\<and> x \\<noteq> z) \\<and> x = y) = ((x = y) \\<and> P)\"\n  by(auto)\n\nlemmas finite_setdiff_compute =\n  conj_disj_distribL \n  conj_disj_distribR \n  ex_disj_distrib\n  eq_conj_neq\n  disj_ac\n\n\nsubsection{* Extensions to ML infrastructure for HOL *}\n\nlemma HOL_concl_revcut_rl:\n  \"\\<lbrakk> PROP V; PROP V \\<Longrightarrow> W \\<rbrakk> \\<Longrightarrow> W\"\n  by simp\n\n\nML{*\nsignature HOL_EXT =\nsig\n  (* Gather bound variables *)\n  val add_bound_list : term -> int list -> int list\n\n  (* Permutations of all quantifiers *)\n  val invert_perm : int list -> int list\n  val forall_permute : Proof.context -> int list -> cterm -> thm\n  val forall_permute_conv : Proof.context -> int list -> cterm -> thm\n\n  (* Theorem modifications *)\n  val beta_norm_thm : thm -> thm\n  val make_HOL_elim : thm -> thm\n  val protect_concl : thm -> thm\n  val lift_ground_thm_mod \n    : Proof.context -> (Proof.context -> thm -> thm) -> thm -> thm\n\n  (* Applying tactics to theorems *)\n  val rule_by_tactic \n    : Proof.context -> (Proof.context -> thm -> thm Seq.seq) -> thm -> thm\n  val refine_rule \n    : Proof.context -> (Proof.context -> thm -> thm Seq.seq) -> thm -> thm\n  val track_HOL_term \n    : Proof.context -> term -> (thm * (thm -> thm)) * Proof.context\nend;\n\n*}\n\nML{*\n\nstructure HOL_Ext: HOL_EXT =\nstruct\n\n(* gather a list of bound variables *)\nval add_bound_list =\n  (fn f => rev o f) o fold_aterms (fn Bound i => (fn is => i::is) | _ => I);\n\n\n(* invert a permutation *)\nfun invert_perm p =\n  p ~~ (0 upto (length p - 1))\n  |> sort (int_ord o pairself fst)\n  |> map snd\n\n\n(* Prove the permutation of the outermost all quantifiers:\n \n   !!x0 .. x(n-1). A |- !!x[p0] .. x[p(n-1)]. A\n\n   PRE: No meta-variables in the given cterm.\n*)\nfun forall_permute ctxt p ct =\n  let\n    val cert = Thm.cterm_of (Proof_Context.theory_of ctxt);\n    fun mk_cv (_, ty) n = cert (Free (n, ty));\n    val string_of_perm = commas o map string_of_int;\n    fun err msg = raise CTERM\n      ( \"forall_permute: \" ^ msg ^ \" [\" ^ string_of_perm p ^ \"]\"\n      , [ct] );\n\n    val t = Thm.term_of ct;\n    val n = length p;\n    val vs = t |> Term.strip_all_vars |> #1 o chop n;\n\n    val () = if n <> length vs\n             then err \"too many variables referenced\"\n             else ();\n\n    val (vns', _) = Variable.variant_fixes (map fst vs) ctxt;\n    val cvs'  = map2 mk_cv vs vns';\n    val cpvs' = \n      map (nth cvs') p\n      handle Subscript => err \"wrong subscript in permutation\";\n  in\n    ct\n    |> Thm.assume\n    |> forall_elim_list cvs'\n    |> forall_intr_list cpvs'\n  end\n\n(* Prove the conversion permuting the variables:\n\n   (!!x0 .. x(n-1). A) == (!!x[p0] .. x[p(n-1)]. A)\n*)\nfun forall_permute_conv ctxt p ct =\n  let\n    val lr  = forall_permute ctxt p ct;\n    val ct' = Thm.cprop_of lr;\n    val rl  = forall_permute ctxt (invert_perm p) ct';\n  in\n    Thm.equal_intr (Thm.implies_intr ct  lr) \n                   (Thm.implies_intr ct' rl)\n  end;\n\n\n(* Beta-normal form of a theorem *)\nfun beta_norm_thm th =\n  Thm.equal_elim (Thm.beta_conversion true (Thm.cprop_of th)) th\n\n(* make an elim rule with a \"Trueprop ?R\" concluion *)\nfun make_HOL_elim rl = \n  zero_var_indexes (rl RS @{thm HOL_concl_revcut_rl})\n\n\n(*\n  A ==> ... ==>  C\n  ---------------- (protect_concl)\n  A ==> ... ==> #C\n*)\nfun protect_concl th = \n  Drule.comp_no_flatten (th, Thm.nprems_of th) 1 Drule.protectI;\n\n\n(* Modify a theorem using a function thm -> thm that requires the theorem\n   to contain no schematic variables.\n*)\nfun lift_ground_thm_mod ctxt f th =\n  let\n    val ((_, [th']), ctxt') = Variable.import true [th] ctxt;\n  in\n    f ctxt' th'\n    |> singleton (Variable.export ctxt' ctxt)\n    |> zero_var_indexes\n  end;\n\n\n(*Makes a rule by applying a tactic to an existing rule.\n\n  Copied from 'tactic.ML' and fixed such that the current context\n  is taken as an argument to avoid clashes with free variables referenced \n  by facts used by the tactic.\n*)\nfun rule_by_tactic ctxt tac rl =\n  lift_ground_thm_mod ctxt \n    (fn ctxt' => fn st => \n       case Seq.pull (tac ctxt' st) of\n         NONE => raise THM (\"rule_by_tactic\", 0, [rl])\n       | SOME (st', _) => st')\n    rl;\n\n(* Apply a tactic to the premises of an elim rule *)\nfun refine_rule ctxt tac =\n  Goal.conclude o rule_by_tactic ctxt tac o protect_concl\n\n\n(* Returns a theorem of the for \"Q x |- Q x\" together with\n   a removal function that can be used to eliminate the \"Q x\"\n   assumption by replacing it with (\\y. x = y). The given\n   theorem can be used to track the conversions of \"x\" that\n   happen when using automatic tools. Just insert the given\n   theorem.\n*)\nfun track_HOL_term ctxt x_t =\n  let\n    val thy  = Proof_Context.theory_of ctxt;\n    val cert = Thm.cterm_of thy;\n\n    val x_ty = Term.fastype_of x_t; \n\n    val ([Q_n],ctxt') = Variable.variant_fixes [\"Q\"] ctxt;\n    val Q_ty = x_ty --> HOLogic.boolT;\n    val Q_t  = Free (Q_n, Q_ty);\n    \n    val Q_ct    = cert Q_t;\n    val Qx_ct   = cert (HOLogic.mk_Trueprop (Q_t $ x_t));\n    val eq_x_ct = cert \n      (Abs (\"y\", x_ty, \n            Const (@{const_name \"HOL.eq\"}, x_ty --> x_ty --> HOLogic.boolT)\n            $ x_t $ Bound 0));\n\n    fun remove_tracking th' =\n      th' \n      |> Thm.implies_intr Qx_ct \n      |> Thm.forall_intr Q_ct\n      |> Thm.forall_elim eq_x_ct\n      |> curry (op RS) @{thm refl}\n      |> beta_norm_thm\n  in\n    ((Thm.assume Qx_ct, remove_tracking), ctxt')\n  end;\n\n\nend;\n*}\n\n\nend\n", "meta": {"author": "meiersi", "repo": "scyther-proof", "sha": "84e42366a46f66f1b090651be3bfaa3497696280", "save_path": "github-repos/isabelle/meiersi-scyther-proof", "path": "github-repos/isabelle/meiersi-scyther-proof/scyther-proof-84e42366a46f66f1b090651be3bfaa3497696280/data/isabelle/src/ESPLogic/HOL_ext.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5621765008857982, "lm_q2_score": 0.5117166047041652, "lm_q1q2_score": 0.2876750502777488}}
{"text": "(* \n   Title: Psi-calculi   \n   Author/Maintainer: Jesper Bengtson (jebe@itu.dk), 2012\n*)\ntheory Weak_Bisim_Subst\n  imports Weak_Bisim_Struct_Cong Weak_Bisim_Pres Bisim_Subst\nbegin\n\ncontext env begin\n\nabbreviation\n  weakBisimSubstJudge (\"_ \\<rhd> _ \\<approx>\\<^sub>s _\" [70, 70, 70] 65) where \"\\<Psi> \\<rhd> P \\<approx>\\<^sub>s Q \\<equiv> (\\<Psi>, P, Q) \\<in> closeSubst weakBisim\"\nabbreviation\n  weakBisimSubstNilJudge (\"_ \\<approx>\\<^sub>s _\" [70, 70] 65) where \"P \\<approx>\\<^sub>s Q \\<equiv> \\<one> \\<rhd> P \\<approx>\\<^sub>s Q\"\n\nlemmas weakBisimSubstClosed[eqvt] = closeSubstClosed[OF weakBisimEqvt]\nlemmas weakBisimEqvt[simp] = closeSubstEqvt[OF weakBisimEqvt]\n\nlemma strongBisimSubstWeakBisimSubst:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<sim>\\<^sub>s Q\"\n\n  shows \"\\<Psi> \\<rhd> P \\<approx>\\<^sub>s Q\"\nusing assms\nby(metis closeSubstI closeSubstE strongBisimWeakBisim)\n\nlemma weakBisimSubstOutputPres:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   M :: 'a\n  and   N :: 'a\n  \n  assumes \"\\<Psi> \\<rhd> P \\<approx>\\<^sub>s Q\"\n\n  shows \"\\<Psi> \\<rhd> M\\<langle>N\\<rangle>.P \\<approx>\\<^sub>s M\\<langle>N\\<rangle>.Q\"\nusing assms\nby(fastforce intro: closeSubstI closeSubstE weakBisimOutputPres)\n\nlemma bisimSubstInputPres:\n  fixes \\<Psi>    :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   xvec :: \"name list\"\n  and   N    :: 'a\n\n  assumes \"\\<Psi> \\<rhd> P \\<approx>\\<^sub>s Q\"\n  and     \"xvec \\<sharp>* \\<Psi>\"\n  and     \"distinct xvec\"\n\n  shows \"\\<Psi> \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.P \\<approx>\\<^sub>s M\\<lparr>\\<lambda>*xvec N\\<rparr>.Q\"\nproof(rule_tac closeSubstI)\n  fix yvec Tvec\n  assume \"length(yvec::name list) = length (Tvec::'a list)\" and \"distinct yvec\"\n  obtain p where \"(p \\<bullet> xvec) \\<sharp>* yvec\" and \"(p \\<bullet> xvec) \\<sharp>* Tvec\"\n             and \"(p \\<bullet> xvec) \\<sharp>* P\" and \"(p \\<bullet> xvec) \\<sharp>* Q\" and \"(p \\<bullet> xvec) \\<sharp>* \\<Psi>\" and \"(p \\<bullet> xvec) \\<sharp>* N\"\n             and S: \"set p \\<subseteq> set xvec \\<times> set (p \\<bullet> xvec)\"\n      by(rule_tac c=\"(yvec, Tvec, P, Q, \\<Psi>, N)\" in name_list_avoiding) auto\n    \n  from `\\<Psi> \\<rhd> P \\<approx>\\<^sub>s Q` have \"(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P) \\<approx>\\<^sub>s (p \\<bullet> Q)\"\n    by(rule weakBisimSubstClosed)\n  with `xvec \\<sharp>* \\<Psi>` `(p \\<bullet> xvec) \\<sharp>* \\<Psi>` S have \"\\<Psi> \\<rhd> (p \\<bullet> P) \\<approx>\\<^sub>s (p \\<bullet> Q)\"\n    by simp\n\n  {\n    fix Tvec' :: \"'a list\"\n\n    note  `\\<Psi> \\<rhd> (p \\<bullet> P) \\<approx>\\<^sub>s (p \\<bullet> Q)`\n    moreover assume \"length xvec = length Tvec'\"\n    with `length yvec = length Tvec` have \"length(yvec@(p \\<bullet> xvec)) = length(Tvec@Tvec')\"\n      by auto\n    moreover from `distinct xvec` `distinct yvec` `(p \\<bullet> xvec) \\<sharp>* yvec` have \"distinct(yvec@(p \\<bullet> xvec))\"\n      by(auto simp add: fresh_star_def fresh_def name_list_supp)\n    ultimately have \"\\<Psi> \\<rhd> (p \\<bullet> P)[(yvec@(p \\<bullet> xvec))::=(Tvec@Tvec')] \\<approx> (p \\<bullet> Q)[(yvec@(p \\<bullet> xvec))::=(Tvec@Tvec')]\"\n      by(rule closeSubstE)\n    with `length yvec = length Tvec` `length xvec = length Tvec'` `distinct xvec` `distinct yvec` `(p \\<bullet> xvec) \\<sharp>* yvec` `(p \\<bullet> xvec) \\<sharp>* Tvec` have \"\\<Psi> \\<rhd> ((p \\<bullet> P)[yvec::=Tvec])[(p \\<bullet> xvec)::=Tvec'] \\<approx> ((p \\<bullet> Q)[yvec::=Tvec])[(p \\<bullet> xvec)::=Tvec']\"\n      by(subst subst5[symmetric], auto)+\n  }\n\n  with `(p \\<bullet> xvec) \\<sharp>* yvec` `(p \\<bullet> xvec) \\<sharp>* Tvec`\n  have \"\\<Psi> \\<rhd> (M\\<lparr>\\<lambda>*(p \\<bullet> xvec) (p \\<bullet> N)\\<rparr>.(p \\<bullet> P))[yvec::=Tvec] \\<approx> (M\\<lparr>\\<lambda>*(p \\<bullet> xvec) (p \\<bullet> N)\\<rparr>.(p \\<bullet> Q))[yvec::=Tvec]\"\n    by(force intro: weakBisimInputPres)\n  moreover from `(p \\<bullet> xvec) \\<sharp>* N` `(p \\<bullet> xvec) \\<sharp>* P` S have \"M\\<lparr>\\<lambda>*(p \\<bullet> xvec) (p \\<bullet> N)\\<rparr>.(p \\<bullet> P) = M\\<lparr>\\<lambda>*xvec N\\<rparr>.P\" \n    apply(simp add: psi.inject) by(rule inputChainAlpha[symmetric]) auto\n  moreover from `(p \\<bullet> xvec) \\<sharp>* N` `(p \\<bullet> xvec) \\<sharp>* Q` S have \"M\\<lparr>\\<lambda>*(p \\<bullet> xvec) (p \\<bullet> N)\\<rparr>.(p \\<bullet> Q) = M\\<lparr>\\<lambda>*xvec N\\<rparr>.Q\"\n    apply(simp add: psi.inject) by(rule inputChainAlpha[symmetric]) auto\n  ultimately show \"\\<Psi> \\<rhd> (M\\<lparr>\\<lambda>*xvec N\\<rparr>.P)[yvec::=Tvec] \\<approx> (M\\<lparr>\\<lambda>*xvec N\\<rparr>.Q)[yvec::=Tvec]\"\n    by force\nqed\n(*\nlemma bisimSubstCasePresAux:\n  fixes \\<Psi>   :: 'b\n  and   CsP :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n  and   CsQ :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n  \n  assumes C1: \"\\<And>\\<phi> P. (\\<phi>, P) mem CsP \\<Longrightarrow> \\<exists>Q. (\\<phi>, Q) mem CsQ \\<and> guarded Q \\<and> \\<Psi> \\<rhd> P \\<sim>\\<^sub>s Q\"\n  and     C2: \"\\<And>\\<phi> Q. (\\<phi>, Q) mem CsQ \\<Longrightarrow> \\<exists>P. (\\<phi>, P) mem CsP \\<and> guarded P \\<and> \\<Psi> \\<rhd> P \\<sim>\\<^sub>s Q\"\n\n  shows \"\\<Psi> \\<rhd> Cases CsP \\<sim>\\<^sub>s Cases CsQ\"\nproof -\n  {\n    fix xvec :: \"name list\"\n    and Tvec :: \"'a list\"\n\n    assume \"length xvec = length Tvec\"\n    and    \"distinct xvec\"\n\n    have \"\\<Psi> \\<rhd> Cases(caseListSubst CsP xvec Tvec) \\<sim> Cases(caseListSubst CsQ xvec Tvec)\"\n    proof(rule bisimCasePres)\n      fix \\<phi> P\n      assume \"(\\<phi>, P) mem (caseListSubst CsP xvec Tvec)\"\n      then obtain \\<phi>' P' where \"(\\<phi>', P') mem CsP\" and \"\\<phi> = substCond \\<phi>' xvec Tvec\" and PeqP': \"P = (P'[xvec::=Tvec])\"\n        by(induct CsP) force+\n      from `(\\<phi>', P') mem CsP` obtain Q' where \"(\\<phi>', Q') mem CsQ\" and \"guarded Q'\" and \"\\<Psi> \\<rhd> P' \\<sim>\\<^sub>s Q'\" by(blast dest: C1)\n      from `(\\<phi>', Q') mem CsQ` `\\<phi> = substCond \\<phi>' xvec Tvec` obtain Q where \"(\\<phi>, Q) mem (caseListSubst CsQ xvec Tvec)\" and \"Q = Q'[xvec::=Tvec]\"\n        by(induct CsQ) auto\n      with PeqP' `guarded Q'` `\\<Psi> \\<rhd> P' \\<sim>\\<^sub>s Q'` `length xvec = length Tvec` `distinct xvec` show \"\\<exists>Q. (\\<phi>, Q) mem (caseListSubst CsQ xvec Tvec) \\<and> guarded Q \\<and> \\<Psi> \\<rhd> P \\<sim> Q\"\n        by(blast dest: bisimSubstE guardedSubst)\n    next\n      fix \\<phi> Q\n      assume \"(\\<phi>, Q) mem (caseListSubst CsQ xvec Tvec)\"\n      then obtain \\<phi>' Q' where \"(\\<phi>', Q') mem CsQ\" and \"\\<phi> = substCond \\<phi>' xvec Tvec\" and QeqQ': \"Q = Q'[xvec::=Tvec]\"\n        by(induct CsQ) force+\n      from `(\\<phi>', Q') mem CsQ` obtain P' where \"(\\<phi>', P') mem CsP\" and \"guarded P'\" and \"\\<Psi> \\<rhd> P' \\<sim>\\<^sub>s Q'\" by(blast dest: C2)\n      from `(\\<phi>', P') mem CsP` `\\<phi> = substCond \\<phi>' xvec Tvec` obtain P where \"(\\<phi>, P) mem (caseListSubst CsP xvec Tvec)\" and \"P = P'[xvec::=Tvec]\"\n        by(induct CsP) auto\n      with QeqQ' `guarded P'` `\\<Psi> \\<rhd> P' \\<sim>\\<^sub>s Q'` `length xvec = length Tvec` `distinct xvec` show \"\\<exists>P. (\\<phi>, P) mem (caseListSubst CsP xvec Tvec) \\<and> guarded P \\<and> \\<Psi> \\<rhd> P \\<sim> Q\"\n        by(blast dest: bisimSubstE guardedSubst)\n    qed\n  }\n  thus ?thesis\n    by(rule_tac bisimSubstI) auto\nqed\n*)\nlemma weakBisimSubstReflexive:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n\n  shows \"\\<Psi> \\<rhd> P \\<approx>\\<^sub>s P\"\nby(auto intro: closeSubstI weakBisimReflexive)\n\nlemma bisimSubstTransitive:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   R :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<approx>\\<^sub>s Q\"\n  and     \"\\<Psi> \\<rhd> Q \\<approx>\\<^sub>s R\"\n\n  shows \"\\<Psi> \\<rhd> P \\<approx>\\<^sub>s R\"\nusing assms\nby(auto intro: closeSubstI closeSubstE weakBisimTransitive)\n\nlemma weakBisimSubstSymmetric:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<approx>\\<^sub>s Q\"\n\n  shows \"\\<Psi> \\<rhd> Q \\<approx>\\<^sub>s P\"\nusing assms\nby(auto intro: closeSubstI closeSubstE weakBisimE)\n(*\nlemma bisimSubstCasePres:\n  fixes \\<Psi>   :: 'b\n  and   CsP :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n  and   CsQ :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n  \n  assumes \"length CsP = length CsQ\"\n  and     C: \"\\<And>(i::nat) \\<phi> P \\<phi>' Q. \\<lbrakk>i <= length CsP; (\\<phi>, P) = nth CsP i; (\\<phi>', Q) = nth CsQ i\\<rbrakk> \\<Longrightarrow> \\<phi> = \\<phi>' \\<and> \\<Psi> \\<rhd> P \\<sim> Q\"\n\n  shows \"\\<Psi> \\<rhd> Cases CsP \\<sim>\\<^sub>s Cases CsQ\"\nproof -\n  {\n    fix \\<phi> \n    and P\n\n    assume \"(\\<phi>, P) mem CsP\"\n\n    with `length CsP = length CsQ` have \"\\<exists>Q. (\\<phi>, Q) mem CsQ \\<and> \\<Psi> \\<rhd> P \\<sim>\\<^sub>s Q\"\n      apply(induct n==\"length CsP\" arbitrary: CsP CsQ rule: nat.induct)\n      apply simp\n      apply simp\n      apply auto\n\n  }\nusing `length CsP = length CsQ`\nproof(induct n==\"length CsP\" rule: nat.induct)\n  case zero\n  thus ?case by(fastforce intro: bisimSubstReflexive)\nnext\n  case(Suc n)\nnext\napply auto\napply(blast intro: bisimSubstReflexive)\napply auto\napply(simp add: nth.simps)\napply(auto simp add: nth.simps)\napply blast\napply(rule_tac bisimSubstCasePresAux)\napply auto\n*)\nlemma weakBisimSubstParPres:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   R :: \"('a, 'b, 'c) psi\"\n  \n  assumes \"\\<Psi> \\<rhd> P \\<approx>\\<^sub>s Q\"\n\n  shows \"\\<Psi> \\<rhd> P \\<parallel> R \\<approx>\\<^sub>s Q \\<parallel> R\"\nusing assms\nby(fastforce intro: closeSubstI closeSubstE weakBisimParPres)\n\nlemma weakBisimSubstResPres:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   x :: name\n\n  assumes \"\\<Psi> \\<rhd> P \\<approx>\\<^sub>s Q\"\n  and     \"x \\<sharp> \\<Psi>\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<approx>\\<^sub>s \\<lparr>\\<nu>x\\<rparr>Q\"\nproof(rule_tac closeSubstI)\n  fix xvec Tvec\n  assume \"length(xvec::name list) = length(Tvec::'a list)\" and \"distinct xvec\"\n  obtain y::name where \"y \\<sharp> \\<Psi>\" and \"y \\<sharp> P\" and \"y \\<sharp> Q\" and \"y \\<sharp> xvec\" and \"y \\<sharp> Tvec\"\n    by(generate_fresh \"name\") (auto simp add: fresh_prod)\n\n  from `\\<Psi> \\<rhd> P \\<approx>\\<^sub>s Q` have \"([(x, y)] \\<bullet> \\<Psi>) \\<rhd> ([(x, y)] \\<bullet> P) \\<approx>\\<^sub>s ([(x, y)] \\<bullet> Q)\"\n    by(rule weakBisimSubstClosed)\n  with `x \\<sharp> \\<Psi>` `y \\<sharp> \\<Psi>` have \"\\<Psi> \\<rhd> ([(x, y)] \\<bullet> P) \\<approx>\\<^sub>s ([(x, y)] \\<bullet> Q)\"\n    by simp\n  hence \"\\<Psi> \\<rhd> ([(x, y)] \\<bullet> P)[xvec::=Tvec] \\<approx> ([(x, y)] \\<bullet> Q)[xvec::=Tvec]\" using `length xvec = length Tvec` `distinct xvec`\n    by(rule closeSubstE)\n  hence \"\\<Psi> \\<rhd> \\<lparr>\\<nu>y\\<rparr>(([(x, y)] \\<bullet> P)[xvec::=Tvec]) \\<approx> \\<lparr>\\<nu>y\\<rparr>(([(x, y)] \\<bullet> Q)[xvec::=Tvec])\" using `y \\<sharp> \\<Psi>`\n    by(rule weakBisimResPres)\n  with `y \\<sharp> P` `y \\<sharp> Q` `y \\<sharp> xvec` `y \\<sharp> Tvec` \n  show \"\\<Psi> \\<rhd> (\\<lparr>\\<nu>x\\<rparr>P)[xvec::=Tvec] \\<approx> (\\<lparr>\\<nu>x\\<rparr>Q)[xvec::=Tvec]\"\n    by(simp add: alphaRes)\nqed\n(*\nlemma bisimSubstBangPres:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n \n  assumes \"\\<Psi> \\<rhd> P \\<sim>\\<^sub>s Q\"\n  and     \"guarded P\"\n  and     \"guarded Q\"\n\n  shows \"\\<Psi> \\<rhd> !P \\<sim>\\<^sub>s !Q\"\nusing assms\nby(fastforce intro: bisimSubstI bisimSubstE bisimBangPres)\n*)\n\nlemma weakBisimSubstParNil:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n\n  shows \"\\<Psi> \\<rhd> P \\<parallel> \\<zero> \\<approx>\\<^sub>s P\"\nby(metis strongBisimSubstWeakBisimSubst bisimSubstParNil) \n\nlemma weakBisimSubstParComm:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  shows \"\\<Psi> \\<rhd> P \\<parallel> Q \\<approx>\\<^sub>s Q \\<parallel> P\"\nby(metis strongBisimSubstWeakBisimSubst bisimSubstParComm) \n\nlemma weakBisimSubstParAssoc:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   R :: \"('a, 'b, 'c) psi\"\n\n  shows \"\\<Psi> \\<rhd> (P \\<parallel> Q) \\<parallel> R \\<approx>\\<^sub>s P \\<parallel> (Q \\<parallel> R)\"\nby(metis strongBisimSubstWeakBisimSubst bisimSubstParAssoc) \n\nlemma weakBisimSubstResNil:\n  fixes \\<Psi> :: 'b\n  and   x :: name\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>\\<zero> \\<sim>\\<^sub>s \\<zero>\"\nby(metis strongBisimSubstWeakBisimSubst bisimSubstResNil) \n\nlemma weakBisimSubstScopeExt:\n  fixes \\<Psi> :: 'b\n  and   x :: name\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes \"x \\<sharp> P\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q) \\<approx>\\<^sub>s P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q\" \nusing assms\nby(metis strongBisimSubstWeakBisimSubst bisimSubstScopeExt) \n\nlemma weakBisimSubstCasePushRes:\n  fixes x  :: name\n  and   \\<Psi>  :: 'b\n  and   Cs :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n\n  assumes \"x \\<sharp> map fst Cs\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(Cases Cs) \\<approx>\\<^sub>s Cases map (\\<lambda>(\\<phi>, P). (\\<phi>, \\<lparr>\\<nu>x\\<rparr>P)) Cs\"\nusing assms\nby(metis strongBisimSubstWeakBisimSubst bisimSubstCasePushRes) \n\nlemma weakBisimSubstOutputPushRes:\n  fixes x :: name\n  and   \\<Psi> :: 'b\n  and   M :: 'a\n  and   N :: 'a\n  and   P :: \"('a, 'b, 'c) psi\"\n\n  assumes \"x \\<sharp> \\<Psi>\"\n  and     \"x \\<sharp> M\"\n  and     \"x \\<sharp> N\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(M\\<langle>N\\<rangle>.P) \\<approx>\\<^sub>s M\\<langle>N\\<rangle>.\\<lparr>\\<nu>x\\<rparr>P\"\nusing assms\nby(metis strongBisimSubstWeakBisimSubst bisimSubstOutputPushRes) \n\nlemma weakBisimSubstInputPushRes:\n  fixes x    :: name\n  and   \\<Psi>    :: 'b\n  and   M    :: 'a\n  and   xvec :: \"name list\"\n  and   N    :: 'a\n\n  assumes \"x \\<sharp> M\"\n  and     \"x \\<sharp> xvec\"\n  and     \"x \\<sharp> N\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(M\\<lparr>\\<lambda>*xvec N\\<rparr>.P) \\<approx>\\<^sub>s M\\<lparr>\\<lambda>*xvec N\\<rparr>.\\<lparr>\\<nu>x\\<rparr>P\"\nusing assms\nby(metis strongBisimSubstWeakBisimSubst bisimSubstInputPushRes) \n\nlemma weakBisimSubstResComm:\n  fixes x :: name\n  and   y :: name\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>y\\<rparr>P) \\<approx>\\<^sub>s \\<lparr>\\<nu>y\\<rparr>(\\<lparr>\\<nu>x\\<rparr>P)\"\nby(metis strongBisimSubstWeakBisimSubst bisimSubstResComm) \n\nlemma weakBisimSubstExtBang:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  \n  assumes \"guarded P\"\n\n  shows \"\\<Psi> \\<rhd> !P \\<approx>\\<^sub>s P \\<parallel> !P\"\nusing assms\nby(metis strongBisimSubstWeakBisimSubst bisimSubstExtBang) \n\nend\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Psi_Calculi/Weak_Bisim_Subst.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5117166047041652, "lm_q2_score": 0.5621765008857981, "lm_q1q2_score": 0.28767505027774876}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory Plus\nimports\n  \"AutoCorres.AutoCorres\"\nbegin\n\nexternal_file \"plus.c\"\ninstall_C_file \"plus.c\"\n\nautocorres [ ts_force nondet = plus2 ] \"plus.c\"\n\ncontext plus begin\n\n(* 3 + 2 should be 5 *)\nlemma \"plus' 3 2 = 5\"\n  unfolding plus'_def\n  by eval\n\n(* plus does what it says on the box *)\nlemma plus_correct: \"plus' a b = a + b\"\n  unfolding plus'_def\n  apply (rule refl)\n  done\n\n(* Compare pre-lifting to post-lifting *)\nthm plus_global_addresses.plus2_body_def\nthm plus2'_def\n\n(* plus2 does what it says on the box *)\nlemma plus2_correct: \"\\<lbrace>\\<lambda>s. True\\<rbrace> plus2' a b \\<lbrace> \\<lambda>r s. r = a + b\\<rbrace>\"\n  unfolding plus2'_def\n  apply (subst whileLoop_add_inv\n   [where I=\"\\<lambda>(a', b') s. a' + b' = a + b\"\n      and M=\"\\<lambda>((a', b'), s). b'\"])\n  apply (wp, auto simp: not_less)\n  done\n\n(* plus2 does what it says on plus's box *)\nlemma plus2_is_plus: \"\\<lbrace> \\<lambda>s. True \\<rbrace> plus2' a b \\<lbrace> \\<lambda>r s. r = plus' a b \\<rbrace>\"\n  unfolding plus'_def\n  apply (simp add:plus2_correct)\n  done\n\n(* Prove plus2 with no failure *)\nlemma plus2_valid:\"\\<lbrace> \\<lambda>s. True \\<rbrace> plus2' a b \\<lbrace> \\<lambda>r s. r = a + b \\<rbrace>!\"\n  unfolding plus2'_def\n  apply (subst whileLoop_add_inv\n   [where I=\"\\<lambda>(a', b') s. a' + b' = a + b\"\n      and M=\"\\<lambda>((a', b'), s). b'\"])\n  apply wp\n    apply clarsimp\n    apply unat_arith\n   apply clarsimp\n   apply unat_arith\n  apply clarsimp\n  done\n\nend\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/autocorres/tests/examples/Plus.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.28754478422412977}}
{"text": "(*  Title:      HOL/Auth/n_germanish_lemma_inv__2_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_germanish Protocol Case Study*} \n\ntheory n_germanish_lemma_inv__2_on_rules imports n_germanish_lemma_on_inv__2\nbegin\nsection{*All lemmas on causal relation between inv__2*}\nlemma lemma_inv__2_on_rules:\n  assumes b1: \"r \\<in> rules N\" and b2: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__2  p__Inv2)\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have c1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t1  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_t2  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_t3  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_t4  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_t5  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_t6 N i)\"\n  apply (cut_tac b1, auto) done\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t1  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_t1Vsinv__2) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t2  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_t2Vsinv__2) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t3  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_t3Vsinv__2) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t4  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_t4Vsinv__2) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t5  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_t5Vsinv__2) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t6 N i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_t6Vsinv__2) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "paraVerifier", "repo": "paraVerifier", "sha": "5de62b433a160bf8d714e0a5085a38b9dd8899f0", "save_path": "github-repos/isabelle/paraVerifier-paraVerifier", "path": "github-repos/isabelle/paraVerifier-paraVerifier/paraVerifier-5de62b433a160bf8d714e0a5085a38b9dd8899f0/proof_scripts/germanish/n_germanish_lemma_inv__2_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6992544210587585, "lm_q2_score": 0.41111086923216805, "lm_q1q2_score": 0.2874710928559026}}
{"text": "(* Author: Florian Haftmann, TU Muenchen *)\n\nsection {* Reflecting Pure types into HOL *}\n\ntheory Typerep\nimports String\nbegin\n\ndatatype typerep = Typerep String.literal \"typerep list\"\n\nclass typerep =\n  fixes typerep :: \"'a itself \\<Rightarrow> typerep\"\nbegin\n\ndefinition typerep_of :: \"'a \\<Rightarrow> typerep\" where\n  [simp]: \"typerep_of x = typerep TYPE('a)\"\n\nend\n\nsyntax\n  \"_TYPEREP\" :: \"type => logic\"  (\"(1TYPEREP/(1'(_')))\")\n\nparse_translation {*\n  let\n    fun typerep_tr (*\"_TYPEREP\"*) [ty] =\n          Syntax.const @{const_syntax typerep} $\n            (Syntax.const @{syntax_const \"_constrain\"} $ Syntax.const @{const_syntax Pure.type} $\n              (Syntax.const @{type_syntax itself} $ ty))\n      | typerep_tr (*\"_TYPEREP\"*) ts = raise TERM (\"typerep_tr\", ts);\n  in [(@{syntax_const \"_TYPEREP\"}, K typerep_tr)] end\n*}\n\ntyped_print_translation {*\n  let\n    fun typerep_tr' ctxt (*\"typerep\"*)\n            (Type (@{type_name fun}, [Type (@{type_name itself}, [T]), _]))\n            (Const (@{const_syntax Pure.type}, _) :: ts) =\n          Term.list_comb\n            (Syntax.const @{syntax_const \"_TYPEREP\"} $ Syntax_Phases.term_of_typ ctxt T, ts)\n      | typerep_tr' _ T ts = raise Match;\n  in [(@{const_syntax typerep}, typerep_tr')] end\n*}\n\nsetup {*\nlet\n\nfun add_typerep tyco thy =\n  let\n    val sorts = replicate (Sign.arity_number thy tyco) @{sort typerep};\n    val vs = Name.invent_names Name.context \"'a\" sorts;\n    val ty = Type (tyco, map TFree vs);\n    val lhs = Const (@{const_name typerep}, Term.itselfT ty --> @{typ typerep})\n      $ Free (\"T\", Term.itselfT ty);\n    val rhs = @{term Typerep} $ HOLogic.mk_literal tyco\n      $ HOLogic.mk_list @{typ typerep} (map (HOLogic.mk_typerep o TFree) vs);\n    val eq = HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs));\n  in\n    thy\n    |> Class.instantiation ([tyco], vs, @{sort typerep})\n    |> `(fn lthy => Syntax.check_term lthy eq)\n    |-> (fn eq => Specification.definition (NONE, (Attrib.empty_binding, eq)))\n    |> snd\n    |> Class.prove_instantiation_exit (K (Class.intro_classes_tac []))\n  end;\n\nfun ensure_typerep tyco thy =\n  if not (Sorts.has_instance (Sign.classes_of thy) tyco @{sort typerep})\n    andalso Sorts.has_instance (Sign.classes_of thy) tyco @{sort type}\n  then add_typerep tyco thy else thy;\n\nin\n\nadd_typerep @{type_name fun}\n#> Typedef.interpretation (Local_Theory.background_theory o ensure_typerep)\n#> Code.datatype_interpretation (ensure_typerep o fst)\n#> Code.abstype_interpretation (ensure_typerep o fst)\n\nend\n*}\n\n\n\nlemma [code nbe]:\n  \"HOL.equal (x :: typerep) x \\<longleftrightarrow> True\"\n  by (fact equal_refl)\n\ncode_printing\n  type_constructor typerep \\<rightharpoonup> (Eval) \"Term.typ\"\n| constant Typerep \\<rightharpoonup> (Eval) \"Term.Type/ (_, _)\"\n\ncode_reserved Eval Term\n\nhide_const (open) typerep Typerep\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/Typerep.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5660185205547239, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.28743092013945154}}
{"text": "(*  Title:      HOL/Auth/n_mutualEx_lemma_inv__1_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mutualEx Protocol Case Study*} \n\ntheory n_mutualEx_lemma_inv__1_on_rules imports n_mutualEx_lemma_on_inv__1\nbegin\nsection{*All lemmas on causal relation between inv__1*}\nlemma lemma_inv__1_on_rules:\n  assumes b1: \"r \\<in> rules N\" and b2: \"(\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__1  p__Inv0 p__Inv1)\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have c1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n  apply (cut_tac b1, auto) done\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_TryVsinv__1) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_CritVsinv__1) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_ExitVsinv__1) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_IdleVsinv__1) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "lyj238Gmail", "repo": "newParaVerifier", "sha": "5c2d49bf8e6c46c60efa53c98b0ba5c577d59618", "save_path": "github-repos/isabelle/lyj238Gmail-newParaVerifier", "path": "github-repos/isabelle/lyj238Gmail-newParaVerifier/newParaVerifier-5c2d49bf8e6c46c60efa53c98b0ba5c577d59618/examples/n_mutualEx/n_mutualEx_lemma_inv__1_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6926419831347361, "lm_q2_score": 0.4148988457967688, "lm_q1q2_score": 0.287376359352987}}
{"text": "(*<*)\n(*\n * Knowledge-based programs.\n * (C)opyright 2011, Peter Gammie, peteg42 at gmail.com.\n * License: BSD\n *)\n\ntheory ClockView\nimports\n  KBPsAlg\n  Eval\n  List_local\n  ODList\n  Trie2\n  \"Transitive-Closure.Transitive_Closure_List_Impl\"\n  \"HOL-Library.Mapping\"\nbegin\n(*>*)\n\nsubsection\\<open>The Clock View\\<close>\n\ntext\\<open>\n\n\\label{sec:kbps-theory-clock-view}\n\nThe \\emph{clock view} records the current time and the observation for\nthe most recent state:\n\n\\<close>\n\ndefinition (in Environment)\n  clock_jview :: \"('a, 's, nat \\<times> 'obs) JointView\"\nwhere\n  \"clock_jview \\<equiv> \\<lambda>a t. (tLength t, envObs a (tLast t))\"\n(*<*)\n\ncontext Environment\nbegin\n\nlemma clock_jview_tInit:\n  \"clock_jview a (tInit s) = (0, envObs a s)\"\n  unfolding clock_jview_def by simp\n\nlemma clock_jview_tStep:\n  \"clock_jview a (t \\<leadsto> s) = (Suc (tLength t), envObs a s)\"\n  unfolding clock_jview_def by simp\n\nlemma clock_jview_tStepI[intro]:\n  \"\\<lbrakk> tLength t = Suc n; envObs a (tLast t) = obs \\<rbrakk>\n     \\<Longrightarrow> clock_jview a t = (Suc n, obs)\"\n  unfolding clock_jview_def by (cases t) simp_all\n\nlemma clock_jview_inv:\n  \"clock_jview a t = (n, obs) \\<Longrightarrow> envObs a (tLast t) = obs\"\n  unfolding clock_jview_def by (cases t) simp_all\n\nlemmas clock_jview_simps =\n  clock_jview_tInit\n  clock_jview_tStep\n  clock_jview_inv\n\nlemma clock_jview_eq_inv[iff]:\n  \"clock_jview a t' = clock_jview a t\n    \\<longleftrightarrow> tLength t' = tLength t \\<and> envObs a (tLast t') = envObs a (tLast t)\"\n  by (fastforce simp: clock_jview_def)\n\nend(*>*)\n\ntext\\<open>\n\nThis is the least-information synchronous view, given the requirements\nof \\S\\ref{sec:kbps-views}. We show that finite-state implementations\nexist for all environments with respect to this view as per\n\\<^citet>\\<open>\"Ron:1996\"\\<close>.\n\nThe corresponding incremental view simply increments the counter\nrecords the new observation.\n\n\\<close>\n\ndefinition (in Environment)\n  clock_jviewInit :: \"'a \\<Rightarrow> 'obs \\<Rightarrow> nat \\<times> 'obs\"\nwhere\n  \"clock_jviewInit \\<equiv> \\<lambda>a obs. (0, obs)\"\n\ndefinition (in Environment)\n  clock_jviewIncr :: \"'a \\<Rightarrow> 'obs \\<Rightarrow> nat \\<times> 'obs \\<Rightarrow> nat \\<times> 'obs\"\nwhere\n  \"clock_jviewIncr \\<equiv> \\<lambda>a obs' (l, obs). (l + 1, obs')\"\n\ntext\\<open>\n\nIt is straightforward to demonstrate the assumptions of the\nincremental environment locale (\\S\\ref{sec:kbps-environments}) with\nrespect to an arbitrary environment.\n\n\\<close>\n\nsublocale Environment\n        < Clock: IncrEnvironment jkbp envInit envAction envTrans envVal\n                        clock_jview envObs clock_jviewInit clock_jviewIncr\n(*<*)\n  apply (unfold_locales)\n  apply (simp_all add: clock_jviewInit_def clock_jviewIncr_def clock_jview_def)\n  done\n\n(*>*)\ntext\\<open>\n\nAs we later show, satisfaction of a formula at a trace \\<open>t \\<in>\nClock.jkbpC\\<^bsub>n\\<^esub>\\<close> is determined by the set of final states of traces in\n\\<open>Clock.jkbpCn\\<close>:\n\n\\<close>\n\ncontext Environment\nbegin\n\nabbreviation clock_commonAbs :: \"'s Trace \\<Rightarrow> 's set\" where\n  \"clock_commonAbs t \\<equiv> tLast ` Clock.jkbpCn (tLength t)\"\n\ntext\\<open>\n\nIntuitively this set contains the states that the agents commonly\nconsider possible at time @{term \"n\"}, which is sufficient for\ndetermining knowledge as the clock view ignores paths. Therefore we\ncan simulate trace @{term \"t\"} by pairing this abstraction of @{term\n\"t\"} with its final state:\n\n\\<close>\n\ntype_synonym (in -) 's clock_simWorlds = \"'s set \\<times> 's\"\n\ndefinition clock_sim :: \"'s Trace \\<Rightarrow> 's clock_simWorlds\" where\n  \"clock_sim \\<equiv> \\<lambda>t. (clock_commonAbs t, tLast t)\"\n\ntext\\<open>\n\nIn the Kripke structure for our simulation, we relate worlds for\n@{term \"a\"} if the sets of commonly-held states coincide, and the\nobservation of the final states of the traces is the\nsame. Propositions are evaluated at the final state.\n\n\\<close>\n\ndefinition clock_simRels :: \"'a \\<Rightarrow> 's clock_simWorlds Relation\" where\n  \"clock_simRels \\<equiv> \\<lambda>a. { ((X, s), (X', s')) |X X' s s'.\n                          X = X' \\<and> {s, s'} \\<subseteq> X \\<and> envObs a s = envObs a s' }\"\n\ndefinition clock_simVal :: \"'s clock_simWorlds \\<Rightarrow> 'p \\<Rightarrow> bool\" where\n  \"clock_simVal \\<equiv> envVal \\<circ> snd\"\n\nabbreviation clock_simMC :: \"('a, 'p, 's clock_simWorlds) KripkeStructure\" where\n  \"clock_simMC \\<equiv> mkKripke (clock_sim ` Clock.jkbpC) clock_simRels clock_simVal\"\n(*<*)\n\nlemma clock_simVal_def2[iff]: \"clock_simVal (clock_sim t) = envVal (tLast t)\"\n  unfolding clock_sim_def clock_simVal_def by simp\n\nlemma clock_sim_range:\n  \"sim_range Clock.MC clock_simMC clock_sim\"\n  by (rule sim_rangeI) (simp_all add: clock_sim_def)\n\nlemma clock_simVal:\n  \"sim_val Clock.MC clock_simMC clock_sim\"\n  by (rule sim_valI) (simp add: clock_simVal_def clock_sim_def)\n\nlemma clock_sim_f:\n  \"sim_f Clock.MC clock_simMC clock_sim\"\napply (rule sim_fI)\napply (simp add: clock_simRels_def clock_sim_def)\napply (intro conjI)\n   apply (fastforce intro!: imageI)\n  apply (fastforce intro!: imageI)\n apply (fastforce dest: Clock.mkM_simps(2))\napply (rule_tac x=v in image_eqI)\n apply simp_all\ndone\n\nlemma clock_sim_r:\n  \"sim_r Clock.MC clock_simMC clock_sim\"\n  apply (rule sim_rI)\n  apply (clarsimp simp: clock_simRels_def clock_sim_def cong del: image_cong_simp)\n  apply (rule_tac x=xa in exI)\n  unfolding Clock.mkM_def\n  apply auto\n  done\n\n(*>*)\ntext\\<open>\n\nThat this is in fact a simulation\n(\\S\\ref{sec:kripke-theory-simulations}) is entirely straightforward.\n\n\\<close>\n\nlemma clock_sim:\n  \"sim Clock.MC clock_simMC clock_sim\"\n(*<*)\n  using clock_sim_range clock_simVal clock_sim_f clock_sim_r\n  unfolding sim_def\n  by blast\n(*>*)\n\nend (* context Environment *)\n\ntext\\<open>\n\nThe \\<open>SimIncrEnvironment\\<close> of\n\\S\\ref{sec:kbps-theory-automata-env-sims} only requires that we\nprovide it an @{term \"Environment\"} and a simulation.\n\n\\<close>\n\nsublocale Environment\n        < Clock: SimIncrEnvironment jkbp envInit envAction envTrans envVal\n                  clock_jview envObs clock_jviewInit clock_jviewIncr\n                  clock_sim clock_simRels clock_simVal\n(*<*)\n  by (unfold_locales, simp_all add: clock_sim)\n(*>*)\n\ntext\\<open>\n\nWe next consider algorithmic issues.\n\n\\<close>\n\n(* **************************************** *)\n\nsubsubsection\\<open>Representations\\<close>\n\ntext\\<open>\n\n\\label{sec:kbps-theory-clock-view-rep}\n\nWe now turn to the issue of how to represent equivalence classes of\nstates. As these are used as map keys, it is easiest to represent them\ncanonically. A simple approach is to use \\emph{ordered distinct lists}\nof type @{typ \"'a odlist\"} for the sets and \\emph{tries} for the\nmaps. Therefore we ask that environment states @{typ \"'s\"} belong to\nthe class \\<open>linorder\\<close> of linearly-ordered types, and moreover\nthat the set \\<open>agents\\<close> be effectively presented. We introduce a\nnew locale capturing these requirements:\n\n\\<close>\n\nlocale FiniteLinorderEnvironment =\n  Environment jkbp envInit envAction envTrans envVal envObs\n    for jkbp :: \"('a::{finite, linorder}, 'p, 'aAct) JKBP\"\n    and envInit :: \"('s::{finite, linorder}) list\"\n    and envAction :: \"'s \\<Rightarrow> 'eAct list\"\n    and envTrans :: \"'eAct \\<Rightarrow> ('a \\<Rightarrow> 'aAct) \\<Rightarrow> 's \\<Rightarrow> 's\"\n    and envVal :: \"'s \\<Rightarrow> 'p \\<Rightarrow> bool\"\n    and envObs :: \"'a \\<Rightarrow> 's \\<Rightarrow> 'obs\"\n+ fixes agents :: \"'a odlist\"\n  assumes agents: \"ODList.toSet agents = UNIV\"\n\ncontext FiniteLinorderEnvironment\nbegin\n\ntext\\<open>\n\n\\label{sec:kbps-theory-clock-view-algops}\n\nFor a fixed agent @{term \"a\"}, we can reduce the number of worlds in\n@{term \"clock_simMC\"} by taking its quotient with respect to the\nequivalence relation for @{term \"a\"}. In other words, we represent a\nsimulated equivalence class by a pair of the set of all states\nreachable at a particular time, and the subset of these that @{term\n\"a\"} considers possible. The worlds in our representational Kripke\nstructure are therefore a pair of ordered, distinct lists:\n\n\\<close>\n\ntype_synonym (in -) 's clock_simWorldsRep = \"'s odlist \\<times> 's odlist\"\n\ntext\\<open>\n\nWe can readily abstract a representation to a set of simulated\nequivalence classes:\n\n\\<close>\n\ndefinition (in -)\n  clock_simAbs :: \"'s::linorder clock_simWorldsRep \\<Rightarrow> 's clock_simWorlds set\"\nwhere\n  \"clock_simAbs X \\<equiv> { (ODList.toSet (fst X), s) |s. s \\<in> ODList.toSet (snd X) }\"\n\ntext\\<open>\n\nAssuming @{term \"X\"} represents a simulated equivalence class for\n@{term \"t \\<in> jkbpC\"}, @{term \"clock_simAbs X\"} decomposes into these\ntwo functions:\n\n\\<close>\n\ndefinition\n  agent_abs :: \"'a \\<Rightarrow> 's Trace \\<Rightarrow> 's set\"\nwhere\n  \"agent_abs a t \\<equiv>\n     { tLast t' |t'. t' \\<in> Clock.jkbpC \\<and> clock_jview a t' = clock_jview a t}\"\n\ndefinition\n  common_abs :: \"'s Trace \\<Rightarrow> 's set\"\nwhere\n  \"common_abs t \\<equiv> tLast ` Clock.jkbpCn (tLength t)\"\n(*<*)\n\nlemma aec_refl[intro, simp]:\n  \"t \\<in> Clock.jkbpC \\<Longrightarrow> tLast t \\<in> agent_abs a t\"\n  unfolding agent_abs_def by auto\n\nlemma aec_cec_subset:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and aec: \"ODList.toSet aec = agent_abs a t\"\n      and cec: \"ODList.toSet cec = common_abs t\"\n  shows \"x \\<in> ODList.toSet aec \\<Longrightarrow> x \\<in> ODList.toSet cec\"\n  using assms\n  unfolding agent_abs_def common_abs_def\n  by fastforce\n\nlemma clock_simAbs_refl:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and ec: \"clock_simAbs ec = Clock.sim_equiv_class a t\"\n  shows \"clock_sim t \\<in> clock_simAbs ec\"\n  using assms by simp\n\nlemma common_abs:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n  assumes ec: \"clock_simAbs ec = Clock.sim_equiv_class a t\"\n  shows \"ODList.toSet (fst ec) = common_abs t\"\n  using tC clock_simAbs_refl[OF tC ec]\n  unfolding clock_sim_def clock_simAbs_def common_abs_def\n  by (auto simp: ODList.toSet_def[symmetric])\n\nlemma agent_abs:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n  assumes ec: \"clock_simAbs ec = Clock.sim_equiv_class a t\"\n  shows \"ODList.toSet (snd ec) = agent_abs a t\"\n  using assms\n  unfolding clock_sim_def clock_simAbs_def agent_abs_def\n  apply auto\n  apply (subgoal_tac \"(ODList.toSet (fst ec), x) \\<in> {(ODList.toSet (fst ec), s) |s. s \\<in> ODList.toSet (snd ec)}\")\n  apply auto (* FIXME filthy *)\n  done\n\n(*>*)\ntext\\<open>\n\nThis representation is canonical on the domain of interest (though not\nin general):\n\n\\<close>\n\nlemma clock_simAbs_inj_on:\n  \"inj_on clock_simAbs { x . clock_simAbs x \\<in> Clock.jkbpSEC }\"\n(*<*)\nproof(rule inj_onI)\n  fix x y\n  assume x: \"x \\<in> { x . clock_simAbs x \\<in> Clock.jkbpSEC }\"\n     and y: \"y \\<in> { x . clock_simAbs x \\<in> Clock.jkbpSEC }\"\n     and xy: \"clock_simAbs x = clock_simAbs y\"\n  from x obtain a t\n    where tC: \"t \\<in> Clock.jkbpC\"\n      and ec: \"clock_simAbs x = Clock.sim_equiv_class a t\"\n    by auto\n  from common_abs[OF tC ec] common_abs[OF tC trans[OF xy[symmetric] ec], symmetric]\n  have \"fst x = fst y\" by (blast intro: injD[OF toSet_inj])\n  moreover\n  from agent_abs[OF tC ec] agent_abs[OF tC trans[OF xy[symmetric] ec], symmetric]\n  have \"snd x = snd y\" by (blast intro: injD[OF toSet_inj])\n  ultimately show \"x = y\" by (simp add: prod_eqI)\nqed\n(*>*)\ntext\\<open>\n\nWe could further compress this representation by labelling each\nelement of the set of states reachable at time $n$ with a bit to\nindicate whether the agent considers that state possible.  Note,\nhowever, that the representation would be non-canonical: if \\<open>(s, True)\\<close> is in the representation, indicating that the agent\nconsiders \\<open>s\\<close> possible, then \\<open>(s, False)\\<close> may or may\nnot be. The associated abstraction function is not injective and hence\nwould obfuscate the following. Repairing this would entail introducing\na new type, which would again complicate this development.\n\n\n\nThe following lemmas make use of this Kripke structure, constructed\nfrom the set of final states of a temporal slice @{term \"X\"}:\n\n\\<close>\n\ndefinition\n  clock_repRels :: \"'a \\<Rightarrow> ('s \\<times> 's) set\"\nwhere\n  \"clock_repRels \\<equiv> \\<lambda>a. { (s, s'). envObs a s = envObs a s' }\"\n\nabbreviation\n  clock_repMC :: \"'s set \\<Rightarrow> ('a, 'p, 's) KripkeStructure\"\nwhere\n  \"clock_repMC \\<equiv> \\<lambda>X. mkKripke X clock_repRels envVal\"\n(*<*)\n\nlemma clock_repMC_kripke[intro, simp]: \"kripke (clock_repMC X)\"\n  by (rule kripkeI) simp\n\nlemma clock_repMC_S5n[intro, simp]: \"S5n (clock_repMC X)\"\n  unfolding clock_repRels_def\n  by (intro S5nI equivI refl_onI symI transI) auto\n\n(*>*)\ntext\\<open>\n\nWe can show that this Kripke structure retains sufficient information\nfrom @{term \"Clock.MCS\"} by showing simulation. This is eased by\nintroducing an intermediary structure that focusses on a particular\ntrace:\n\n\\<close>\n\nabbreviation\n  clock_jkbpCSt :: \"'b Trace \\<Rightarrow> 's clock_simWorlds set\"\nwhere\n  \"clock_jkbpCSt t \\<equiv> clock_sim ` Clock.jkbpCn (tLength t)\"\n\nabbreviation\n  clock_simMCt :: \"'b Trace \\<Rightarrow> ('a, 'p, 's clock_simWorlds) KripkeStructure\"\nwhere\n  \"clock_simMCt t \\<equiv> mkKripke (clock_jkbpCSt t) clock_simRels clock_simVal\"\n\ndefinition clock_repSim :: \"'s clock_simWorlds \\<Rightarrow> 's\" where\n  \"clock_repSim \\<equiv> snd\"\n(*<*)\n\nlemma jkbpCSt_jkbpCS_subset:\n  \"clock_jkbpCSt t \\<subseteq> clock_sim ` Clock.jkbpC\"\n  by auto\n\nlemma jkbpCSt_refl[iff]:\n  \"t \\<in> Clock.jkbpC \\<Longrightarrow> clock_sim t \\<in> clock_jkbpCSt t\"\n  by blast\n\nlemma fst_clock_sim[iff]:\n  \"t \\<in> Clock.jkbpC \\<Longrightarrow> fst (clock_sim t) = tLast ` Clock.jkbpCn (tLength t)\"\n  by (simp add: clock_sim_def)\n\nlemma clock_repSim_simps[simp]:\n  \"clock_repSim ` clock_sim ` T = tLast ` T\"\n  \"clock_repSim (clock_sim t) = tLast t\"\n  unfolding clock_repSim_def clock_sim_def\n  by (auto intro!: image_eqI)\n\n(*>*)\ntext\\<open>\\<close>\n\nlemma clock_repSim:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n  shows \"sim (clock_simMCt t)\n             ((clock_repMC \\<circ> fst) (clock_sim t))\n             clock_repSim\"\n(*<*) (is \"sim ?M ?M' ?f\")\nproof\n  show \"sim_range ?M ?M' ?f\"\n  proof\n    show \"worlds ?M' = ?f ` worlds ?M\"\n      unfolding clock_sim_def clock_repSim_def by force\n  next\n    fix a\n    show \"relations ?M' a \\<subseteq> worlds ?M' \\<times> worlds ?M'\"\n      by (simp add: clock_sim_def clock_repSim_def)\n  qed\nnext\n  show \"sim_val ?M ?M' ?f\"\n    by (rule, simp add: clock_sim_def clock_simVal_def clock_repSim_def split: prod.split)\nnext\n  show \"sim_f ?M ?M' ?f\"\n    apply rule\n    unfolding clock_repRels_def clock_repSim_def clock_simRels_def\n    apply (auto iff: clock_sim_def)\n    done\nnext\n  show \"sim_r ?M ?M' ?f\"\n    apply rule\n    unfolding clock_repRels_def clock_repSim_def clock_simRels_def clock_sim_def\n    apply clarsimp\n    done\nqed\n\n(*>*)\ntext\\<open>\n\nThe following sections show how we satisfy the remaining requirements\nof the \\<open>Algorithm\\<close> locale of\nFigure~\\ref{fig:kbps-alg-alg-locale}. Where the proof is routine, we\nsimply present the lemma without proof or comment.\n\nDue to a limitation in the code generator in the present version of\nIsabelle (2011), we need to define the equations we wish to execute\noutside of a locale; the syntax \\<open>(in -)\\<close> achieves this by\nmaking definitons at the theory top-level. We then define (but elide)\nlocale-local abbreviations that supply the locale-bound variables to\nthese definitions.\n\n\\<close>\n\n(* **************************************** *)\n\nsubsubsection\\<open>Initial states\\<close>\n\ntext\\<open>\n\nThe initial states of the automaton for an agent is simply @{term\n\"envInit\"} paired with the partition of @{term \"envInit\"} under the\nagent's observation.\n\n\\<close>\n\ndefinition (in -)\n  clock_simInit :: \"('s::linorder) list \\<Rightarrow> ('a \\<Rightarrow> 's \\<Rightarrow> 'obs)\n                \\<Rightarrow> 'a \\<Rightarrow> 'obs \\<Rightarrow> 's clock_simWorldsRep\"\nwhere\n  \"clock_simInit envInit envObs \\<equiv> \\<lambda>a iobs.\n    let cec = ODList.fromList envInit\n     in (cec, ODList.filter (\\<lambda>s. envObs a s = iobs) cec)\"\n(*<*)\n\nabbreviation\n  clock_simInit :: \"'a \\<Rightarrow> 'obs \\<Rightarrow> 's clock_simWorldsRep\"\nwhere\n  \"clock_simInit \\<equiv> ClockView.clock_simInit envInit envObs\"\n\n(*>*)\ntext\\<open>\\<close>\n\nlemma clock_simInit:\n  assumes \"iobs \\<in> envObs a ` set envInit\"\n  shows \"clock_simAbs (clock_simInit a iobs)\n       = clock_sim ` { t' \\<in> Clock.jkbpC.\n                       clock_jview a t' = clock_jviewInit a iobs }\"\n(*<*)\n  using assms\n  unfolding clock_simInit_def clock_simAbs_def clock_sim_def [abs_def] Let_def\n  apply clarsimp\n  apply rule\n   apply clarsimp\n   apply (rule_tac x=\"tInit s\" in image_eqI)\n    apply (auto simp: Set.image_def Clock.jviewInit)[2]\n  apply clarsimp\n  apply (case_tac xa)\n   apply clarsimp\n   apply rule\n    apply rule\n     apply clarsimp\n    apply clarsimp\n    apply (rule_tac x=\"tInit xa\" in image_eqI)\n    apply (auto intro!: image_eqI simp: Clock.jviewInit)\n  done\n(*>*)\n\n(* **************************************** *)\n\nsubsubsection\\<open>Simulated observations\\<close>\n\ntext\\<open>\n\nAgent @{term \"a\"} will make the same observation at any of the worlds\nthat it considers possible, so we choose the first one in the list:\n\n\\<close>\n\ndefinition (in -)\n  clock_simObs :: \"('a \\<Rightarrow> ('s :: linorder) \\<Rightarrow> 'obs)\n                \\<Rightarrow> 'a \\<Rightarrow> 's clock_simWorldsRep \\<Rightarrow> 'obs\"\nwhere\n  \"clock_simObs envObs \\<equiv> \\<lambda>a. envObs a \\<circ> ODList.hd \\<circ> snd\"\n(*<*)\n\nabbreviation\n  clock_simObs :: \"'a \\<Rightarrow> 's clock_simWorldsRep \\<Rightarrow> 'obs\"\nwhere\n  \"clock_simObs \\<equiv> ClockView.clock_simObs envObs\"\n\n(*>*)\ntext\\<open>\\<close>\n\nlemma clock_simObs:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and ec: \"clock_simAbs ec = Clock.sim_equiv_class a t\"\n  shows \"clock_simObs a ec = envObs a (tLast t)\"\n(*<*)\nproof -\n  have A: \"\\<forall>s \\<in> set (toList (snd ec)). envObs a s = envObs a (tLast t)\"\n    using agent_abs[OF tC ec]\n    by (clarsimp simp: agent_abs_def toSet_def)\n  have B: \"tLast t \\<in> set (toList (snd ec))\"\n    using clock_simAbs_refl[OF assms]\n    unfolding clock_simAbs_def clock_sim_def\n    by (simp add: toSet_def snd_def)\n  show ?thesis\n    unfolding clock_simObs_def by (simp add: list_choose_hd[OF A B] ODList.hd_def)\nqed\n(*>*)\n\n(* **************************************** *)\n\nsubsubsection\\<open>Evaluation\\<close>\n\ntext\\<open>\n\n\\label{sec:kbps-theory-clock-view-eval}\n\nWe define our \\<open>eval\\<close> function in terms of @{term \"evalS\"},\nwhich implements boolean logic over @{typ \"'s odlist\"} in the usual\nway -- see \\S\\ref{sec:kbps-spr-single-agent-eval} for the relevant\nclauses. It requires three functions specific to the representation:\none each for propositions, knowledge and common knowledge.\n\nPropositions define subsets of the worlds considered possible:\n\n\\<close>\n\nabbreviation (in -)\n  clock_evalProp :: \"(('s::linorder) \\<Rightarrow> 'p \\<Rightarrow> bool)\n                  \\<Rightarrow> 's odlist \\<Rightarrow> 'p \\<Rightarrow> 's odlist\"\nwhere\n  \"clock_evalProp envVal \\<equiv> \\<lambda>X p. ODList.filter (\\<lambda>s. envVal s p) X\"\n\ntext\\<open>\n\nThe knowledge relation computes the subset of the\ncommonly-held-possible worlds \\<open>cec\\<close> that agent @{term \"a\"}\nconsiders possible at world @{term \"s\"}:\n\n\\<close>\n\ndefinition (in -)\n  clock_knowledge :: \"('a \\<Rightarrow> ('s :: linorder) \\<Rightarrow> 'obs) \\<Rightarrow> 's odlist\n                  \\<Rightarrow> 'a \\<Rightarrow> 's \\<Rightarrow> 's odlist\"\nwhere\n  \"clock_knowledge envObs cec \\<equiv> \\<lambda>a s.\n     ODList.filter (\\<lambda>s'. envObs a s = envObs a s') cec\"\n\ntext\\<open>\n\n\nSimilarly the common knowledge operation computes the transitive\nclosure of the union of the knowledge relations for the agents \\<open>as\\<close>:\n\n\\<close>\n\ndefinition (in -)\n  clock_commonKnowledge :: \"('a \\<Rightarrow> ('s :: linorder) \\<Rightarrow> 'obs) \\<Rightarrow> 's odlist\n           \\<Rightarrow> 'a list \\<Rightarrow> 's \\<Rightarrow> 's odlist\"\nwhere\n  \"clock_commonKnowledge envObs cec \\<equiv> \\<lambda>as s.\n     let r = \\<lambda>a. ODList.fromList [ (s', s'') . s' \\<leftarrow> toList cec, s'' \\<leftarrow> toList cec,\n                                   envObs a s' = envObs a s'' ];\n         R = toList (ODList.big_union r as)\n      in ODList.fromList (memo_list_trancl R s)\"\n\ntext\\<open>\n\nThe function \\<open>memo_list_trancl\\<close> comes from the executable\ntransitive closure theory of \\<^citep>\\<open>\"AFP:TRANCL\"\\<close>.\n\nThe evaluation function evaluates a subjective knowledge formula on\nthe representation of an equivalence class:\n\n\\<close>\n\ndefinition (in -)\n  eval :: \"(('s :: linorder) \\<Rightarrow> 'p \\<Rightarrow> bool)\n        \\<Rightarrow> ('a \\<Rightarrow> 's \\<Rightarrow> 'obs)\n        \\<Rightarrow> 's clock_simWorldsRep \\<Rightarrow> ('a, 'p) Kform \\<Rightarrow> bool\"\nwhere\n  \"eval envVal envObs \\<equiv> \\<lambda>(cec, aec). evalS (clock_evalProp envVal)\n                                      (clock_knowledge envObs cec)\n                                      (clock_commonKnowledge envObs cec)\n                                      aec\"\n\ntext\\<open>\n\nThis function corresponds with the standard semantics:\n\n\\<close>\n(*<*)\n\nlemma clock_coEC_relation_image:\n  \"s \\<in> ODList.toSet Y\n    \\<Longrightarrow> ODList.toSet (clock_knowledge envObs Y a s) = relations (clock_repMC (ODList.toSet Y)) a `` {s}\"\n  unfolding clock_knowledge_def clock_repRels_def Image_def\n  by auto\n\nlemma clock_commonKnowledge_relation_image_aux:\n  \"(\\<Union>x\\<in>set as. \\<Union>a\\<in>ODList.toSet Y. \\<Union>aa\\<in>ODList.toSet Y \\<inter> {s''. envObs x a = envObs x s''}. {(a, aa)})\n = ((\\<Union>a\\<in>set as. {(s, s'). envObs a s = envObs a s'}) \\<inter> ODList.toSet Y \\<times> ODList.toSet Y)\"\n  by auto\n\nlemma clock_commonKnowledge_relation_image:\n  \"s \\<in> ODList.toSet Y\n    \\<Longrightarrow> ODList.toSet (clock_commonKnowledge envObs Y as s) = (\\<Union>a \\<in> set as. relations (clock_repMC (ODList.toSet Y)) a)\\<^sup>+ `` {s}\"\n  unfolding clock_commonKnowledge_def clock_repRels_def Let_def\n  apply (simp add: memo_list_trancl toSet_def[symmetric] Image_def clock_commonKnowledge_relation_image_aux)\n  done\n\nlemma eval_rec_models:\n  assumes XY: \"ODList.toSet X \\<subseteq> ODList.toSet Y\"\n      and s: \"s \\<in> ODList.toSet X\"\n  shows \"s \\<in> ODList.toSet (eval_rec (clock_evalProp envVal) (clock_knowledge envObs Y) (clock_commonKnowledge envObs Y) X \\<phi>)\n     \\<longleftrightarrow> clock_repMC (ODList.toSet Y), s \\<Turnstile> \\<phi>\"\nusing XY s\nproof(induct \\<phi> arbitrary: X s)\n  case (Kknows a' \\<phi> X s)\n  from \\<open>s \\<in> ODList.toSet X\\<close> clock_coEC_relation_image[OF subsetD[OF Kknows(2) Kknows(3)], where a=a']\n  show ?case\n    apply simp\n    apply rule\n     apply (drule arg_cong[where f=\"ODList.toSet\"])\n     apply (clarsimp simp: odlist_all_iff)\n     apply (cut_tac s3=\"w'\" and X3=\"clock_knowledge envObs Y a' s\" in Kknows.hyps)\n      using Kknows(2) Kknows(3)\n      apply (auto simp add: S5n_rels_closed[OF clock_repMC_S5n])[3]\n\n    apply (clarsimp simp: toSet_eq_iff odlist_all_iff)\n    apply (subst Kknows.hyps)\n      using Kknows(2) Kknows(3)\n      apply (auto simp add: S5n_rels_closed[OF clock_repMC_S5n])\n    done\nnext\n  case (Kcknows as \\<phi> X s)\n  show ?case\n  proof(cases \"as = Nil\")\n    case True with \\<open>s \\<in> ODList.toSet X\\<close> show ?thesis by clarsimp\n  next\n    case False\n    with \\<open>s \\<in> ODList.toSet X\\<close> clock_commonKnowledge_relation_image[OF subsetD[OF Kcknows(2) Kcknows(3)], where as=as]\n    show ?thesis\n      apply simp\n      apply rule\n       apply (drule arg_cong[where f=\"ODList.toSet\"])\n       apply (clarsimp simp: odlist_all_iff)\n       apply (cut_tac s3=\"w'\" and X3=\"clock_commonKnowledge envObs Y as s\" in Kcknows.hyps)\n        using Kcknows(2) Kcknows(3)\n        apply (auto simp add: S5n_rels_closed[OF clock_repMC_S5n])[3]\n        apply (subst (asm) trancl_unfold) back back back\n        apply auto[1] (* FIXME disgusting *)\n\n      apply (clarsimp simp: toSet_eq_iff odlist_all_iff)\n      apply (subst Kcknows.hyps)\n       using Kcknows(2) Kcknows(3)\n       apply (auto simp add: S5n_rels_closed[OF clock_repMC_S5n])\n        apply (subst (asm) trancl_unfold) back back back\n        apply auto[1] (* FIXME disgusting *)\n\n      done\n  qed\nqed simp_all\n\nlemma trc_aux:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and aec: \"ODList.toSet aec = agent_abs a t\"\n      and cec: \"ODList.toSet cec = common_abs t\"\n  shows \"ODList.toSet (big_union (clock_commonKnowledge envObs cec as) (toList aec)) \\<subseteq> ODList.toSet cec\"\n  apply (clarsimp simp: toSet_def[symmetric])\n  apply (subst (asm) clock_commonKnowledge_relation_image)\n   apply (erule aec_cec_subset[OF tC aec cec])\n  apply (subst (asm) trancl_unfold)\n  using assms\n  apply (auto simp: agent_abs_def)\n  done\n\nlemma clock_repMC_aec:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and aec: \"ODList.toSet aec = agent_abs a t\"\n      and cec: \"ODList.toSet cec = common_abs t\"\n      and x: \"x \\<in> ODList.toSet aec\"\n      and xy: \"(x, y) \\<in> relations (clock_repMC (ODList.toSet cec)) a\"\n  shows \"y \\<in> ODList.toSet aec\"\n  using assms\n  unfolding clock_repRels_def agent_abs_def common_abs_def\n  by auto\n\nlemma clock_repMC_cec:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and aec: \"ODList.toSet aec = agent_abs a t\"\n      and cec: \"ODList.toSet cec = common_abs t\"\n      and x: \"x \\<in> ODList.toSet aec\"\n      and y: \"y \\<in> ODList.toSet aec\"\n  shows \"(x, y) \\<in> relations (clock_repMC (ODList.toSet cec)) a\"\n  using assms\n  unfolding clock_repRels_def agent_abs_def common_abs_def\n  by auto\n\nlemma evalS_models:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and aec: \"ODList.toSet aec = agent_abs a t\"\n      and cec: \"ODList.toSet cec = common_abs t\"\n      and subj_phi: \"subjective a \\<phi>\"\n      and s: \"s \\<in> ODList.toSet aec\"\n  shows \"evalS (clock_evalProp envVal) (clock_knowledge envObs cec) (clock_commonKnowledge envObs cec) aec \\<phi>\n     \\<longleftrightarrow> clock_repMC (ODList.toSet cec), s \\<Turnstile> \\<phi>\" (is \"?lhs \\<phi> = ?rhs \\<phi>\")\nusing subj_phi s aec cec\nproof(induct \\<phi> rule: subjective.induct[case_names Kprop Knot Kand Kknows Kcknows])\n  case (Kknows a a' \\<psi>) show ?case\n    apply (clarsimp simp: toSet_eq_iff)\n    apply rule\n     apply clarsimp\n     apply (subgoal_tac \"w' \\<in> ODList.toSet aec\")\n     apply (drule_tac c=\"w'\" in subsetD)\n       apply assumption\n      apply (simp add: eval_rec_models[OF subsetI[OF aec_cec_subset[OF tC aec cec]]])\n     apply (rule clock_repMC_aec[OF tC Kknows(3) Kknows(4), rotated, where x=s])\n       using Kknows\n       apply simp\n      using Kknows\n      apply simp\n\n    apply clarsimp\n    apply (simp add: eval_rec_models[OF subsetI[OF aec_cec_subset[OF tC aec cec]]])\n    using tC Kknows\n    apply (clarsimp simp: agent_abs_def)\n    apply (erule (1) ballE)\n    using Kknows\n    apply (cut_tac x=\"tLast t'\" and y=\"tLast t'a\" in clock_repMC_cec[OF tC Kknows(3) Kknows(4)])\n      unfolding clock_repRels_def\n      apply auto\n    done\nnext\n  case (Kcknows a as \\<psi>)\n  have \"?lhs (Kcknows as \\<psi>)\n      = (\\<forall>y\\<in>ODList.toSet aec.\n           \\<forall>x\\<in>(\\<Union>a\\<in>set as. relations (clock_repMC (ODList.toSet cec)) a)\\<^sup>+ `` {y}.\n              x \\<in> ODList.toSet (eval_rec (clock_evalProp envVal) (clock_knowledge envObs cec) (clock_commonKnowledge envObs cec)\n                       (big_union (clock_commonKnowledge envObs cec as) (toList aec)) \\<psi>))\"\n    (* FIXME dreaming of a cong rule here. *)\n    using toSet_def[symmetric]\n    apply (clarsimp simp: toSet_eq_iff toSet_def[symmetric] subset_eq)\n    apply (rule ball_cong[OF refl])\n    apply (rule ball_cong)\n    apply (subst clock_commonKnowledge_relation_image[OF aec_cec_subset[OF tC Kcknows(3) Kcknows(4)]])\n    apply simp_all\n    done\n  also have \"... = (\\<forall>s\\<in>ODList.toSet aec. clock_repMC (ODList.toSet cec), s \\<Turnstile> Kcknows as \\<psi>)\"\n    apply (rule ball_cong[OF refl])\n    apply simp\n    apply (rule ball_cong[OF refl])\n    apply (subst eval_rec_models[OF trc_aux[OF tC Kcknows(3) Kcknows(4), where as=as], symmetric])\n     apply (simp add: toSet_def[symmetric])\n     apply (rule_tac x=y in bexI)\n      apply (subst clock_commonKnowledge_relation_image[OF aec_cec_subset[OF tC Kcknows(3) Kcknows(4)]])\n       apply simp_all\n    done\n  also have \"... = clock_repMC (ODList.toSet cec), s \\<Turnstile> Kknows a (Kcknows as \\<psi>)\"\n    using clock_repMC_aec[OF tC Kcknows(3) Kcknows(4) Kcknows(2)]\n          clock_repMC_cec[OF tC Kcknows(3) Kcknows(4) Kcknows(2)]\n    by (auto cong: ball_cong)\n  also have \"... = clock_repMC (ODList.toSet cec), s \\<Turnstile> Kcknows as \\<psi>\"\n    apply (rule S5n_common_knowledge_fixed_point_simpler[symmetric])\n    using Kcknows\n    apply (auto intro: aec_cec_subset[OF tC Kcknows(3) Kcknows(4) Kcknows(2)])\n    done\n  finally show ?case .\nqed simp_all\n\n(*>*)\nlemma eval_models:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and aec: \"ODList.toSet aec = agent_abs a t\"\n      and cec: \"ODList.toSet cec = common_abs t\"\n      and subj_phi: \"subjective a \\<phi>\"\n      and s: \"s \\<in> ODList.toSet aec\"\n  shows \"eval envVal envObs (cec, aec) \\<phi>\n     \\<longleftrightarrow> clock_repMC (ODList.toSet cec), s \\<Turnstile> \\<phi>\"\n(*<*)\n  unfolding eval_def\n  using evalS_models[OF tC aec cec subj_phi s]\n  apply (simp add: Let_def)\n  done\n\n(*>*)\n\n(* **************************************** *)\n\nsubsubsection\\<open>Simulated actions\\<close>\n\ntext\\<open>\n\nFrom a common equivalence class and a subjective equivalence class for\nagent @{term \"a\"}, we can compute the actions enabled for @{term \"a\"}:\n\n\\<close>\n\ndefinition (in -)\n  clock_simAction :: \"('a, 'p, 'aAct) JKBP \\<Rightarrow> (('s :: linorder) \\<Rightarrow> 'p \\<Rightarrow> bool)\n                  \\<Rightarrow> ('a \\<Rightarrow> 's \\<Rightarrow> 'obs)\n                  \\<Rightarrow> 'a \\<Rightarrow> 's clock_simWorldsRep \\<Rightarrow> 'aAct list\"\nwhere\n  \"clock_simAction jkbp envVal envObs \\<equiv> \\<lambda>a (Y, X).\n     [ action gc. gc \\<leftarrow> jkbp a, eval envVal envObs (Y, X) (guard gc) ]\"\n(*<*)\n\nabbreviation\n  clock_simAction :: \"'a \\<Rightarrow> 's clock_simWorldsRep \\<Rightarrow> 'aAct list\"\nwhere\n  \"clock_simAction \\<equiv> ClockView.clock_simAction jkbp envVal envObs\"\n\n(*>*)\ntext\\<open>\n\nUsing the above result about evaluation, we can relate \\<open>clock_simAction\\<close> to @{term \"jAction\"}. Firstly, \\<open>clock_simAction\\<close> behaves the same as @{term \"jAction\"} using the\n@{term \"clock_repMC\"} structure:\n\n\\<close>\n\nlemma clock_simAction_jAction:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and aec: \"ODList.toSet aec = agent_abs a t\"\n      and cec: \"ODList.toSet cec = common_abs t\"\n  shows \"set (clock_simAction a (cec, aec))\n       = set (jAction (clock_repMC (ODList.toSet cec)) (tLast t) a)\"\n(*<*)\n  unfolding clock_simAction_def jAction_def\n  apply clarsimp\n  apply rule\n   apply clarsimp\n   apply (rule_tac x=xa in bexI)\n    apply simp\n   apply clarsimp\n   apply (subst eval_models[OF tC aec cec, symmetric])\n     using tC aec cec subj\n     apply simp_all\n  apply clarsimp\n  apply (rule_tac x=xa in bexI)\n   apply (rule refl)\n  apply clarsimp\n  apply (subst eval_models[OF tC aec cec])\n    using tC aec cec subj\n    apply simp_all\n  done\n\nlemma clock_submodel_aux:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and s: \"s \\<in> worlds (clock_simMCt t)\"\n  shows \"gen_model Clock.MCS s = gen_model (clock_simMCt t) s\"\nproof(rule gen_model_subset[where T=\"clock_jkbpCSt t\"])\n  fix a\n  let ?X = \"clock_sim ` Clock.jkbpCn (tLength t)\"\n  show \"relations Clock.MCS a \\<inter> ?X \\<times> ?X\n      = relations (clock_simMCt t) a \\<inter> ?X \\<times> ?X\"\n    by (simp add: Int_ac Int_absorb1\n                  relation_mono[OF jkbpCSt_jkbpCS_subset jkbpCSt_jkbpCS_subset])\nnext\n  let ?X = \"clock_sim ` Clock.jkbpCn (tLength t)\"\n  from s show \"(\\<Union>a. relations (clock_simMCt t) a)\\<^sup>* `` {s} \\<subseteq> ?X\"\n    apply (clarsimp simp del: mkKripke_simps)\n    apply (erule kripke_rels_trc_worlds)\n    apply auto\n    done\nnext\n  let ?Y = \"Clock.jkbpCn (tLength t)\"\n  let ?X = \"clock_sim ` ?Y\"\n  from s obtain t'\n    where st': \"s = clock_sim t'\"\n      and t'C: \"t' \\<in> Clock.jkbpC\"\n      and t'O: \"tLength t = tLength t'\"\n    by fastforce\n  { fix t''\n    assume tt': \"(t', t'') \\<in> (\\<Union>a. relations Clock.MC a)\\<^sup>*\"\n    from t'C tt' have t''C: \"t'' \\<in> Clock.jkbpC\"\n      by - (erule kripke_rels_trc_worlds, simp_all)\n    from t'O tt' have t''O: \"tLength t = tLength t''\"\n      by (simp add: Clock.sync_tLength_eq_trc)\n    from t''C t''O have \"t'' \\<in> ?Y\" by fastforce }\n  hence \"(\\<Union>a. relations Clock.MC a)\\<^sup>* `` {t'} \\<subseteq> ?Y\"\n    by clarsimp\n  hence \"clock_sim ` ((\\<Union>a. relations Clock.MC a)\\<^sup>* `` {t'}) \\<subseteq> ?X\"\n    by (rule image_mono)\n  with st' t'C\n  show \"(\\<Union>a. relations Clock.MCS a)\\<^sup>* `` {s} \\<subseteq> ?X\"\n    using sim_trc_commute[OF Clock.mkM_kripke clock_sim, where t=t'] by simp\nqed (insert s, auto)\n\n(*>*)\ntext\\<open>\n\nWe can connect the agent's choice of actions on the \\<open>clock_repMC\\<close> structure to those on the \\<open>Clock.MC\\<close>\nstructure using our earlier results about actions being preserved by\ngenerated models and simulations.\n\n\\<close>\n\nlemma clock_simAction':\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n  assumes aec: \"ODList.toSet aec = agent_abs a t\"\n  assumes cec: \"ODList.toSet cec = common_abs t\"\n  shows \"set (clock_simAction a (cec, aec)) = set (jAction Clock.MC t a)\"\n(*<*) (is \"?lhs = ?rhs\")\nproof -\n  from tC aec cec\n  have \"?lhs = set (jAction (clock_repMC (ODList.toSet cec)) (tLast t) a)\"\n    by (rule clock_simAction_jAction)\n  also from tC aec cec\n  have \"... = set (jAction (clock_simMCt t) (clock_sim t) a)\"\n    by (simp add: simulation_jAction_eq[OF _ clock_repSim] common_abs_def)\n  also from tC\n  have \"... = set (jAction Clock.MCS (clock_sim t) a)\"\n    using gen_model_jAction_eq[OF clock_submodel_aux[OF tC, where s=\"clock_sim t\"], where w'=\"clock_sim t\"]\n          gen_model_world_refl[where w=\"clock_sim t\" and M=\"clock_simMCt t\"]\n    by simp\n  also from tC have \"... = set (jAction Clock.MC t a)\"\n    by (simp add: simulation_jAction_eq[OF _ clock_sim])\n  finally show ?thesis .\nqed\n\n(*>*)\ntext\\<open>\n\nThe @{term \"Algorithm\"} locale requires a specialisation of this\nlemma:\n\n\\<close>\n\nlemma clock_simAction:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n  assumes ec: \"clock_simAbs ec = Clock.sim_equiv_class a t\"\n  shows \"set (clock_simAction a ec) = set (jAction Clock.MC t a)\"\n(*<*)\n  using assms clock_simAction'[OF tC, where cec=\"fst ec\" and aec=\"snd ec\"]\n  apply (simp add: common_abs agent_abs)\n  done\n(*>*)\n\n(* **************************************** *)\n\nsubsubsection\\<open>Simulated transitions\\<close>\n\ntext\\<open>\n\nWe need to determine the image of the set of commonly-held-possible\nstates under the transition function, and also for the agent's\nsubjective equivalence class. We do this with the \\<open>clock_trans\\<close> function:\n\n\\<close>\n\ndefinition (in -)\n  clock_trans :: \"('a :: linorder) odlist \\<Rightarrow> ('a, 'p, 'aAct) JKBP\n              \\<Rightarrow> (('s :: linorder) \\<Rightarrow> 'eAct list)\n              \\<Rightarrow> ('eAct \\<Rightarrow> ('a \\<Rightarrow> 'aAct) \\<Rightarrow> 's \\<Rightarrow> 's)\n              \\<Rightarrow> ('s \\<Rightarrow> 'p \\<Rightarrow> bool) \\<Rightarrow> ('a \\<Rightarrow> 's \\<Rightarrow> 'obs)\n              \\<Rightarrow> 's odlist \\<Rightarrow> 's odlist \\<Rightarrow> 's odlist\"\nwhere\n  \"clock_trans agents jkbp envAction envTrans envVal envObs \\<equiv> \\<lambda>cec X.\n     ODList.fromList (concat\n       [ [ envTrans eact aact s .\n                     eact \\<leftarrow> envAction s,\n                     aact \\<leftarrow> listToFuns (\\<lambda>a. clock_simAction jkbp envVal envObs a\n                                        (cec, clock_knowledge envObs cec a s))\n                                        (toList agents) ] .\n                   s \\<leftarrow> toList X ])\"\n(*<*)\n\nabbreviation\n  clock_trans :: \"'s odlist \\<Rightarrow> 's odlist \\<Rightarrow> 's odlist\"\nwhere\n  \"clock_trans \\<equiv> ClockView.clock_trans agents jkbp envAction envTrans envVal envObs\"\n\nlemma clock_trans_aux:\n  assumes t'C: \"t' \\<in> Clock.jkbpC\"\n      and ec: \"clock_simAbs ec = Clock.sim_equiv_class a' t'\"\n      and tC: \"t \\<in> Clock.jkbpCn (tLength t')\"\n      and eact: \"eact \\<in> set (envAction (tLast t))\"\n  shows \"(aact \\<in> set (listToFuns (\\<lambda>a. clock_simAction a (fst ec, clock_knowledge envObs (fst ec) a (tLast t)))\n                            (toList agents)))\n     \\<longleftrightarrow> (\\<forall>a. aact a \\<in> set (jAction (Clock.MCn (tLength t')) t a))\"\n  using assms\n  apply -\n  apply (frule Clock.jkbpCn_jkbpC_inc)\n  apply (clarsimp simp: listToFuns_ext[OF agents[unfolded toSet_def]])\n  apply (subst clock_simAction')\n     apply (erule Clock.jkbpCn_jkbpC_inc)\n    apply (subst clock_coEC_relation_image)\n     apply (simp add: common_abs common_abs_def toSet_def[symmetric])\n    apply (fastforce simp: common_abs agent_abs_def common_abs_def clock_repRels_def)\n   apply (simp add: common_abs common_abs_def)\n  apply (simp add: Clock.jkbpC_jkbpCn_jAction_eq)\n  done\n\n(*>*)\ntext\\<open>\n\nThe function @{term \"listToFuns\"} exhibits the isomorphism between @{typ\n\"('a \\<times> 'b list) list\"} and @{typ \"('a \\<Rightarrow> 'b) list\"} for finite types\n@{typ \"'a\"}.\n\nWe can show that the transition function works for both the\ncommonly-held set of states and the agent subjective one. The proofs\nare  straightforward.\n\n\\<close>\n\nlemma clock_trans_common:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n  assumes ec: \"clock_simAbs ec = Clock.sim_equiv_class a t\"\n  shows \"ODList.toSet (clock_trans (fst ec) (fst ec))\n       = { s |t' s. t' \\<leadsto> s \\<in> Clock.jkbpC \\<and> tLength t' = tLength t }\"\n(*<*) (is \"?lhs = ?rhs\")\nproof\n  show \"?lhs \\<subseteq> ?rhs\"\n    unfolding clock_trans_def\n    apply (clarsimp simp: toSet_def[symmetric] common_abs[OF assms] common_abs_def)\n    apply (rule_tac x=xa in exI)\n    apply clarsimp\n    apply (rule Clock.jkbpCn_jkbpC_inc[where n=\"Suc (tLength t)\"])\n    apply (auto simp: Let_def iff: clock_trans_aux[OF tC ec])\n    done\nnext\n  show \"?rhs \\<subseteq> ?lhs\"\n    unfolding clock_trans_def\n    apply (clarsimp simp: toSet_def[symmetric] common_abs[OF assms] common_abs_def)\n    apply (drule Clock.jkbpC_tLength_inv[where n=\"Suc (tLength t)\"])\n    apply (auto simp: Let_def iff: clock_trans_aux[OF tC ec])\n    done\nqed\n\n(*>*)\ntext\\<open>\\<close>\n\nlemma clock_trans_agent:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n  assumes ec: \"clock_simAbs ec = Clock.sim_equiv_class a t\"\n  shows \"ODList.toSet (clock_trans (fst ec) (snd ec))\n       = { s |t' s. t' \\<leadsto> s \\<in> Clock.jkbpC \\<and> clock_jview a t' = clock_jview a t }\"\n(*<*) (is \"?lhs = ?rhs\")\nproof\n  show \"?lhs \\<subseteq> ?rhs\"\n    unfolding clock_trans_def\n    apply (clarsimp simp: toSet_def[symmetric] common_abs[OF assms] agent_abs[OF assms] common_abs_def agent_abs_def)\n    apply (rule_tac x=t' in exI)\n    apply clarsimp\n    apply (rule Clock.jkbpCn_jkbpC_inc[where n=\"Suc (tLength t)\"])\n    apply (auto simp: Let_def iff: clock_trans_aux[OF tC ec])\n    done\nnext\n  show \"?rhs \\<subseteq> ?lhs\"\n    unfolding clock_trans_def\n    apply (clarsimp simp: toSet_def[symmetric] common_abs[OF assms] agent_abs[OF assms] common_abs_def agent_abs_def)\n    apply (drule Clock.jkbpC_tLength_inv[where n=\"Suc (tLength t)\"])\n    apply (auto simp: Let_def iff: clock_trans_aux[OF tC ec])\n    done\nqed\n\n(*>*)\ntext\\<open>\n\nNote that the clock semantics disregards paths, so we simply compute\nthe successors of the temporal slice and partition that. Similarly the\nsuccessors of the agent's subjective equivalence class tell us what\nthe set of possible observations are:\n\n\\<close>\n\ndefinition (in -)\n  clock_mkSuccs :: \"('s :: linorder \\<Rightarrow> 'obs) \\<Rightarrow> 'obs \\<Rightarrow> 's odlist\n                \\<Rightarrow> 's clock_simWorldsRep\"\nwhere\n  \"clock_mkSuccs envObs obs Y' \\<equiv> (Y', ODList.filter (\\<lambda>s. envObs s = obs) Y')\"\n\ntext\\<open>\n\nFinally we can define our transition function on simulated states:\n\n\\<close>\n\ndefinition (in -)\n  clock_simTrans :: \"('a :: linorder) odlist \\<Rightarrow> ('a, 'p, 'aAct) JKBP\n              \\<Rightarrow> (('s :: linorder) \\<Rightarrow> 'eAct list)\n              \\<Rightarrow> ('eAct \\<Rightarrow> ('a \\<Rightarrow> 'aAct) \\<Rightarrow> 's \\<Rightarrow> 's)\n              \\<Rightarrow> ('s \\<Rightarrow> 'p \\<Rightarrow> bool) \\<Rightarrow> ('a \\<Rightarrow> 's \\<Rightarrow> 'obs)\n              \\<Rightarrow> 'a \\<Rightarrow> 's clock_simWorldsRep \\<Rightarrow> 's clock_simWorldsRep list\"\nwhere\n  \"clock_simTrans agents jkbp envAction envTrans envVal envObs \\<equiv> \\<lambda>a (Y, X).\n     let X' = clock_trans agents jkbp envAction envTrans envVal envObs Y X;\n        Y' = clock_trans agents jkbp envAction envTrans envVal envObs Y Y\n      in [ clock_mkSuccs (envObs a) obs Y' .\n             obs \\<leftarrow> map (envObs a) (toList X') ]\"\n(*<*)\n\nabbreviation\n  clock_simTrans :: \"'a \\<Rightarrow> 's clock_simWorldsRep \\<Rightarrow> 's clock_simWorldsRep list\"\nwhere\n  \"clock_simTrans \\<equiv> ClockView.clock_simTrans agents jkbp envAction envTrans envVal envObs\"\n\n(*>*)\ntext\\<open>\n\nShowing that this respects the property asked of it by the @{term\n\"Algorithm\"} locale is straightforward:\n\n\\<close>\n\nlemma clock_simTrans:\n  assumes tC: \"t \\<in> Clock.jkbpC\"\n      and ec: \"clock_simAbs ec = Clock.sim_equiv_class a t\"\n  shows \"clock_simAbs ` set (clock_simTrans a ec)\n      = { Clock.sim_equiv_class a (t' \\<leadsto> s)\n          |t' s. t' \\<leadsto> s \\<in> Clock.jkbpC \\<and> clock_jview a t' = clock_jview a t }\"\n(*<*) (is \"?lhs = ?rhs\")\nproof\n  note image_cong_simp [cong del]\n  show \"?lhs \\<subseteq> ?rhs\"\n    unfolding clock_simTrans_def clock_mkSuccs_def\n    using clock_trans_common[OF tC ec] clock_trans_agent[OF tC ec]\n    apply (clarsimp simp: toSet_def[symmetric] clock_simAbs_def Let_def)\n\n    apply (rule_tac x=t' in exI)\n    apply (rule_tac x=xa in exI)\n\n    apply (clarsimp simp: clock_sim_def)\n    apply safe\n\n     apply clarsimp\n     apply (rule_tac x=\"t'a \\<leadsto> s\" in image_eqI)\n      apply (clarsimp simp: Let_def Set.image_def)\n      apply safe\n        apply (rule_tac x=\"t'b \\<leadsto> x\" in exI)\n        apply (clarsimp simp: Let_def Set.image_def)\n        apply (drule_tac t=\"t'b \\<leadsto> x\" in Clock.jkbpC_tLength_inv[OF _ refl])\n        apply (auto simp: Let_def)[1]\n       apply (rule_tac x=\"ta\" in exI)\n       apply simp\n       apply (rule Clock.jkbpCn_jkbpC_inc[where n=\"Suc (tLength t)\"])\n       apply (auto simp: Let_def)[3]\n\n    apply (rule_tac x=\"tLast ta\" in exI)\n    apply (clarsimp simp: Let_def Set.image_def)\n    apply safe\n      apply (rule_tac x=\"taa\" in exI)\n      apply simp\n      apply (rule Clock.jkbpCn_jkbpC_inc[where n=\"Suc (tLength t)\"])\n       apply (auto simp: Let_def)[1]\n     apply (drule_tac t=\"t'a \\<leadsto> x\" in Clock.jkbpC_tLength_inv[OF _ refl])\n     apply (rule_tac x=\"t'a \\<leadsto> x\" in exI)\n     apply (auto simp: Let_def)[1]\n    apply (drule_tac t=\"ta\" in Clock.jkbpC_tLength_inv)\n     apply blast\n    apply (clarsimp simp: Let_def)\n    apply (rule_tac x=\"ta\" in exI)\n    apply simp\n    apply (rule Clock.jkbpCn_jkbpC_inc[where n=\"Suc (tLength t)\"])\n    apply (auto simp: Let_def)\n    done\nnext\n  show \"?rhs \\<subseteq> ?lhs\"\n    unfolding clock_simTrans_def Let_def\n    apply (cases ec)\n    using clock_trans_common[OF tC ec] clock_trans_agent[OF tC ec]\n    apply (clarsimp simp: toSet_def[symmetric] Set.image_def clock_simAbs_def\n                simp del: split_paired_Ex)\n\n    apply (rule_tac x=\"clock_mkSuccs (envObs a) (envObs a s) (clock_trans aa aa)\" in exI)\n    apply safe\n      apply auto[1]\n     apply (rule_tac x=\"tLast x\" in exI)\n     apply (clarsimp simp: clock_trans_common[OF tC ec] clock_mkSuccs_def)\n     apply safe\n       apply (clarsimp simp: clock_sim_def simp del: Clock.jkbpCn.simps)\n       apply rule\n        apply (clarsimp simp: Let_def)\n        apply (rule_tac x=\"ta\" in exI)\n        apply (simp add: Let_def)\n        apply (rule Clock.jkbpCn_jkbpC_inc[where n=\"Suc (tLength t)\"])\n        apply (clarsimp simp: Let_def)\n        apply (rule_tac x=eact in exI)\n        apply (rule_tac x=aact in exI)\n        apply clarsimp\n       apply (clarsimp simp: Let_def Set.image_def)\n       apply (drule_tac t=\"t'a \\<leadsto> xa\" in Clock.jkbpC_tLength_inv[OF _ refl])\n       apply (rule_tac x=\"t'a \\<leadsto> xa\" in exI)\n       apply (auto simp: Let_def)[1]\n      apply (drule_tac t=\"x\" in Clock.jkbpC_tLength_inv[OF _ refl])\n      apply (simp only: Let_def Clock.jkbpCn.simps)\n      apply clarify\n      apply (rule_tac x=\"ta\" in exI)\n      apply simp\n      apply (rule Clock.jkbpCn_jkbpC_inc[where n=\"Suc (tLength t)\"])\n      apply (auto simp: Let_def)[1]\n     apply (clarsimp simp: clock_trans_common[OF tC ec] clock_mkSuccs_def)\n     apply (rule_tac x=\"t'a \\<leadsto> sa\" in exI)\n     apply (clarsimp simp: clock_sim_def Let_def)\n     (* FIXME similar to above *)\n     apply rule\n      apply (clarsimp simp: Set.image_def)\n      apply (rule_tac x=\"t'b \\<leadsto> x\" in exI)\n      apply (drule_tac t=\"t'b \\<leadsto> x\" in Clock.jkbpC_tLength_inv[OF _ refl])\n      apply (auto simp: Let_def)[1]\n    apply clarsimp\n    apply (rule_tac x=\"ta\" in exI)\n    apply auto\n    apply (rule Clock.jkbpCn_jkbpC_inc[where n=\"Suc (tLength t)\"])\n    apply (auto simp: Let_def)\n    done\nqed\n(*>*)\n\nend (* context FiniteLinorderEnvironment *)\n\n(* **************************************** *)\n\nsubsubsection\\<open>Maps\\<close>\n\ntext\\<open>\n\n\\label{sec:kbps-theory-clock-view-maps}\n\nAs mentioned above, the canonicity of our ordered, distinct list\nrepresentation of automaton states allows us to use them as keys in a\ndigital trie; a value of type @{typ \"('key, 'val) trie\"} maps keys of\ntype @{typ \"'key list\"} to values of type @{typ \"'val\"}.\n\nIn this specific case we track automaton transitions using a two-level\nstructure mapping sets of states to an association list mapping\nobservations to sets of states, and for actions automaton states map\ndirectly to agent actions.\n\n\\<close>\n\ntype_synonym ('s, 'obs) clock_trans_trie\n  = \"('s, ('s, ('obs, 's clock_simWorldsRep) mapping) trie) trie\"\ntype_synonym ('s, 'aAct) clock_acts_trie = \"('s, ('s, 'aAct) trie) trie\"\n(*<*)\n\ndefinition\n  trans_MapOps_lookup :: \"('s :: linorder, 'obs) clock_trans_trie\n                        \\<Rightarrow> 's clock_simWorldsRep \\<times> 'obs\n                        \\<rightharpoonup> 's clock_simWorldsRep\"\nwhere\n  \"trans_MapOps_lookup \\<equiv> \\<lambda>m k.\n     Option.bind (trie_odlist_lookup m (fst (fst k))) (\\<lambda>m.\n       (Option.bind (trie_odlist_lookup m (snd (fst k))) (\\<lambda>m.\n         Mapping.lookup m (snd k))))\"\n\ndefinition\n  trans_MapOps_update :: \"('s :: linorder) clock_simWorldsRep \\<times> 'obs \\<Rightarrow> 's clock_simWorldsRep\n                        \\<Rightarrow> ('s :: linorder, 'obs) clock_trans_trie\n                        \\<Rightarrow> ('s :: linorder, 'obs) clock_trans_trie\"\nwhere\n  \"trans_MapOps_update \\<equiv> \\<lambda>k v m.\n     trie_odlist_update_with (fst (fst k)) m empty_trie (\\<lambda>m.\n       trie_odlist_update_with (snd (fst k)) m Mapping.empty (\\<lambda>m.\n          Mapping.update (snd k) v m))\"\n\ndefinition\n  trans_MapOps :: \"(('s :: linorder, 'obs) clock_trans_trie,\n                    's clock_simWorldsRep \\<times> 'obs, 's clock_simWorldsRep) MapOps\"\nwhere\n  \"trans_MapOps \\<equiv>\n     \\<lparr> MapOps.empty = empty_trie,\n       lookup = trans_MapOps_lookup,\n       update = trans_MapOps_update \\<rparr>\"\n\nlemma (in FiniteLinorderEnvironment) trans_MapOps:\n  \"MapOps (\\<lambda>k. (clock_simAbs (fst k), snd k)) (Clock.jkbpSEC \\<times> UNIV) trans_MapOps\"\nproof\n  fix k show \"MapOps.lookup trans_MapOps (MapOps.empty trans_MapOps) k = None\"\n    unfolding trans_MapOps_def trans_MapOps_lookup_def trie_odlist_lookup_def\n    by (auto split: prod.split)\nnext\n  fix e k k' M\n  assume k: \"(clock_simAbs (fst k), snd k) \\<in> Clock.jkbpSEC \\<times> (UNIV :: 'z set)\"\n     and k': \"(clock_simAbs (fst k'), snd k') \\<in> Clock.jkbpSEC \\<times> (UNIV :: 'z set)\"\n  show \"MapOps.lookup trans_MapOps (MapOps.update trans_MapOps k e M) k'\n         = (if (clock_simAbs (fst k'), snd k') = (clock_simAbs (fst k), snd k)\n             then Some e else MapOps.lookup trans_MapOps M k')\"\n  proof(cases \"(clock_simAbs (fst k'), snd k') = (clock_simAbs (fst k), snd k)\")\n    case True hence \"k = k'\"\n      using inj_onD[OF clock_simAbs_inj_on] k k' by (auto iff: prod_eqI)\n    thus ?thesis\n      unfolding trans_MapOps_def trans_MapOps_lookup_def trans_MapOps_update_def trie_odlist_lookup_def trie_odlist_update_with_def\n        by (simp add: lookup_trie_update_with lookup_update split: option.split prod.split) \n  next\n    case False thus ?thesis\n      unfolding trans_MapOps_def trans_MapOps_lookup_def trans_MapOps_update_def trie_odlist_lookup_def trie_odlist_update_with_def\n      by (cases \"fst k = fst k'\")\n       (auto simp add: lookup_empty lookup_update_neq prod_eq_iff lookup_trie_update_with split: option.split prod.split)\n  qed\nqed\n\n(* A map for the agent actions. *)\n\ndefinition\n  acts_MapOps_lookup :: \"('s :: linorder, 'aAct) clock_acts_trie\n                      \\<Rightarrow> 's clock_simWorldsRep\n                      \\<rightharpoonup> 'aAct\"\nwhere\n  \"acts_MapOps_lookup \\<equiv> \\<lambda>m k.\n     Option.bind (trie_odlist_lookup m (fst k)) (\\<lambda>m.\n       (trie_odlist_lookup m (snd k)))\"\n\ndefinition\n  acts_MapOps_update :: \"('s :: linorder) clock_simWorldsRep \\<Rightarrow> 'aAct\n                      \\<Rightarrow> ('s :: linorder, 'aAct) clock_acts_trie\n                      \\<Rightarrow> ('s :: linorder, 'aAct) clock_acts_trie\"\nwhere\n  \"acts_MapOps_update \\<equiv> \\<lambda>k v m.\n     trie_odlist_update_with (fst k) m empty_trie (\\<lambda>m.\n       trie_odlist_update (snd k) v m)\"\n\ndefinition\n  acts_MapOps :: \"(('s :: linorder, 'aAct) clock_acts_trie, 's clock_simWorldsRep, 'aAct) MapOps\"\nwhere\n  \"acts_MapOps \\<equiv>\n     \\<lparr> MapOps.empty = empty_trie,\n       lookup = acts_MapOps_lookup,\n       update = acts_MapOps_update \\<rparr>\"\n\nlemma (in FiniteLinorderEnvironment) acts_MapOps:\n  \"MapOps clock_simAbs Clock.jkbpSEC acts_MapOps\"\nproof\n  fix k show \"MapOps.lookup acts_MapOps (MapOps.empty acts_MapOps) k = None\"\n    unfolding acts_MapOps_def acts_MapOps_lookup_def trie_odlist_lookup_def\n    by auto\nnext\n  fix e k k' M\n  assume k: \"clock_simAbs k \\<in> Clock.jkbpSEC\"\n     and k': \"clock_simAbs k' \\<in> Clock.jkbpSEC\"\n  show \"MapOps.lookup acts_MapOps (MapOps.update acts_MapOps k e M) k'\n         = (if clock_simAbs k' = clock_simAbs k\n             then Some e else MapOps.lookup acts_MapOps M k')\"\n  proof(cases \"clock_simAbs k' = clock_simAbs k\")\n    case True hence \"k = k'\"\n      using inj_onD[OF clock_simAbs_inj_on] k k' by (auto iff: prod_eqI)\n    thus ?thesis\n      unfolding acts_MapOps_def acts_MapOps_lookup_def acts_MapOps_update_def\n      by (auto simp: lookup_trie_update lookup_trie_update_with\n                     trie_odlist_update_with_def trie_odlist_update_def trie_odlist_lookup_def)\n  next\n    case False thus ?thesis\n      unfolding acts_MapOps_def acts_MapOps_lookup_def acts_MapOps_update_def\n      by (auto simp: lookup_trie_update lookup_trie_update_with\n                     trie_odlist_update_with_def trie_odlist_update_def trie_odlist_lookup_def\n               dest: prod_eqI\n              split: option.split)\n  qed\nqed\n\n(*>*)\ntext\\<open>\n\nWe define two records @{term \"acts_MapOps\"} and @{term \"trans_MapOps\"}\nsatisfying the @{term \"MapOps\"} predicate\n(\\S\\ref{sec:kbps-theory-map-ops}). Discharging the obligations in the\n@{term \"Algorithm\"} locale is routine, leaning on the work of\n\\<^citet>\\<open>\"DBLP:conf/itp/LammichL10\"\\<close>.\n\n\\<close>\n\nsubsubsection\\<open>Locale instantiation\\<close>\n\ntext\\<open>\n\nFinally we assemble the algorithm and discharge the proof obligations.\n\n\\<close>\n\nsublocale FiniteLinorderEnvironment\n        < Clock: Algorithm\n            jkbp envInit envAction envTrans envVal\n            clock_jview envObs clock_jviewInit clock_jviewIncr\n            clock_sim clock_simRels clock_simVal\n            clock_simAbs clock_simObs clock_simInit clock_simTrans clock_simAction\n            acts_MapOps trans_MapOps\n(*<*)\n  apply (unfold_locales)\n\n  apply clarify\n  apply (rule clock_simInit)\n  apply simp\n\n  apply clarify\n  apply (erule (1) clock_simObs)\n\n  apply clarify\n  apply (erule (1) clock_simAction)\n\n  apply clarify\n  apply (erule (1) clock_simTrans)\n\n  apply (rule acts_MapOps)\n  apply (rule trans_MapOps)\n\n  done\n\n(*>*)\ntext\\<open>\n\nExplicitly, the algorithm for this case is:\n\n\\<close>\n\ndefinition\n  \"mkClockAuto \\<equiv> \\<lambda>agents jkbp envInit envAction envTrans envVal envObs.\n    mkAlgAuto acts_MapOps\n              trans_MapOps\n              (clock_simObs envObs)\n              (clock_simInit envInit envObs)\n              (clock_simTrans agents jkbp envAction envTrans envVal envObs)\n              (clock_simAction jkbp envVal envObs)\n              (\\<lambda>a. map (clock_simInit envInit envObs a \\<circ> envObs a) envInit)\"\n\nlemma (in FiniteLinorderEnvironment) mkClockAuto_implements:\n  \"Clock.implements\n    (mkClockAuto agents jkbp envInit envAction envTrans envVal envObs)\"\n(*<*)\n  using Clock.k_mkAlgAuto_implements\n  unfolding mkClockAuto_def mkAlgAuto_def Clock.k_frontier_def\n  by simp\n\n(*\n\nWe actually run this unfolding of the algorithm. The lemma is keeping\nus honest.\n\n*)\n\ndefinition\n  \"ClockAutoDFS \\<equiv> \\<lambda>agents jkbp envInit envAction envTrans envVal envObs. \\<lambda>a.\n    alg_dfs acts_MapOps\n            trans_MapOps\n            (clock_simObs envObs a)\n            (clock_simTrans agents jkbp envAction envTrans envVal envObs a)\n            (clock_simAction jkbp envVal envObs a)\n            (map (clock_simInit envInit envObs a \\<circ> envObs a) envInit)\"\n\nlemma (in FiniteLinorderEnvironment)\n  \"mkClockAuto agents jkbp envInit envAction envTrans envVal envObs\n = (\\<lambda>a. alg_mk_auto acts_MapOps trans_MapOps (clock_simInit a) (ClockAutoDFS agents jkbp envInit envAction envTrans envVal envObs a))\"\n  unfolding mkClockAuto_def ClockAutoDFS_def mkAlgAuto_def alg_mk_auto_def by (simp add: Let_def)\n\n(*>*)\ntext\\<open>\n\nWe discuss the clock semantics further in \\S\\ref{sec:kbps-alg-clock}.\n\n\\<close>\n\n(*<*)\nend\n(*>*)\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/KBPs/ClockView.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631556226292, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.2872323330138475}}
{"text": "theory SINVAR_ACLnotCommunicateWith\nimports \"../TopoS_Helper\" SINVAR_ACLcommunicateWith\nbegin\n\nsubsection {* SecurityInvariant ACLnotCommunicateWith*}\ntext{*An access control list strategy that says that hosts must not transitively access each other.*}\n\ntext{* node properties: a set of hosts this host must not access *}\n\ndefinition default_node_properties :: \"'v set\"\n  where  \"default_node_properties \\<equiv> UNIV\"\n\n\nfun sinvar :: \"'v graph \\<Rightarrow> ('v \\<Rightarrow> 'v set) \\<Rightarrow> bool\" where\n  \"sinvar G nP = (\\<forall> v \\<in> nodes G. \\<forall> a \\<in> (succ_tran G v). a \\<notin> (nP v))\"\n\ndefinition receiver_violation :: \"bool\" where \n  \"receiver_violation \\<equiv> False\"\n\ntext{*It is the inverse of @{const SINVAR_ACLcommunicateWith.sinvar}*}\nlemma ACLcommunicateNotWith_inverse_ACLcommunicateWith:\n  \"\\<forall>v. UNIV - nP' v = set (nP v) \\<Longrightarrow> SINVAR_ACLcommunicateWith.sinvar G nP \\<longleftrightarrow> sinvar G nP'\"\n  by auto\n\n\n\n\n    from a3 have \"\\<And>v a. v \\<in> N \\<Longrightarrow>  a \\<in> (succ_tran \\<lparr>nodes = N, edges = E\\<rparr> v) \\<Longrightarrow> a \\<notin> (nP v)\" by fastforce\n    from this a2 have g1: \"\\<And>v a. v \\<in> N \\<Longrightarrow> a \\<in> (succ_tran \\<lparr>nodes = N, edges = E'\\<rparr> v) \\<Longrightarrow> a \\<notin> (nP v)\" \n      using succ_tran_mono[OF a1] by blast\n\n    thus \"sinvar \\<lparr>nodes = N, edges = E'\\<rparr> nP\"\n      by(clarsimp)\nqed\n  \n\nlemma succ_tran_empty: \"(succ_tran \\<lparr>nodes = nodes G, edges = {}\\<rparr> v) = {}\"\n  by(simp add: succ_tran_def)\n\ninterpretation SecurityInvariant_preliminaries\nwhere sinvar = sinvar\n  apply unfold_locales\n    apply(frule_tac finite_distinct_list[OF wf_graph.finiteE])\n    apply(erule_tac exE)\n    apply(rename_tac list_edges)\n    apply(rule_tac ff=\"list_edges\" in SecurityInvariant_withOffendingFlows.mono_imp_set_offending_flows_not_empty[OF sinvar_mono])\n        apply(auto)[4]\n    apply(auto simp add: SecurityInvariant_withOffendingFlows.is_offending_flows_def graph_ops succ_tran_empty)[1]\n   apply(fact SecurityInvariant_withOffendingFlows.sinvar_mono_imp_sinvar_mono[OF sinvar_mono])\n  apply(fact SecurityInvariant_withOffendingFlows.sinvar_mono_imp_is_offending_flows_mono[OF sinvar_mono])\n done\n\n\nlemma unique_default_example: \"succ_tran \\<lparr>nodes = {vertex_1, vertex_2}, edges = {(vertex_1, vertex_2)}\\<rparr> vertex_2 = {}\"\napply (simp add: succ_tran_def)\nby (metis Domain.DomainI Domain_empty Domain_insert distinct_vertices12 singleton_iff trancl_domain)\n\ninterpretation ACLnotCommunicateWith: SecurityInvariant_ACS\nwhere default_node_properties = SINVAR_ACLnotCommunicateWith.default_node_properties\nand sinvar = SINVAR_ACLnotCommunicateWith.sinvar\n  unfolding SINVAR_ACLnotCommunicateWith.default_node_properties_def\n  apply unfold_locales\n \n   apply simp\n   apply(subst(asm) SecurityInvariant_withOffendingFlows.set_offending_flows_simp, simp)\n   apply(clarsimp)\n   apply (metis)\n\n  apply(erule default_uniqueness_by_counterexample_ACS)\n  apply(simp)\n  apply (simp add: SecurityInvariant_withOffendingFlows.set_offending_flows_def\n      SecurityInvariant_withOffendingFlows.is_offending_flows_min_set_def\n      SecurityInvariant_withOffendingFlows.is_offending_flows_def)\n  apply (simp add:graph_ops)\n  apply (simp split: prod.split_asm prod.split)\n  apply(case_tac \"otherbot = {}\")\n\n   apply(rule_tac x=\"\\<lparr> nodes={vertex_1,vertex_2}, edges = {(vertex_1,vertex_2)} \\<rparr>\" in exI, simp)\n   apply(rule conjI)\n    apply(simp add: wf_graph_def)\n   apply(rule_tac x=\"(\\<lambda> x. UNIV)(vertex_1 := {vertex_2}, vertex_2 := {})\" in exI, simp)\n   apply(simp add: example_simps)\n   apply(rule_tac x=\"{(vertex_1,vertex_2)}\" in exI, simp)\n   apply(simp add: example_simps)\n\n  apply(subgoal_tac \"\\<exists>canAccess. canAccess \\<in> UNIV \\<and> canAccess \\<notin> otherbot\")\n   prefer 2\n   apply blast\n  apply(erule exE)\n  apply(rename_tac canAccessThis)\n  apply(case_tac \"vertex_1 \\<noteq> canAccessThis\")\n\n   apply(rule_tac x=\"\\<lparr> nodes={vertex_1,canAccessThis}, edges = {(vertex_1,canAccessThis)} \\<rparr>\" in exI, simp)\n   apply(rule conjI)\n    apply(simp add: wf_graph_def)\n   apply(rule_tac x=\"(\\<lambda> x. UNIV)(vertex_1 := UNIV, canAccessThis := {})\" in exI, simp)\n   apply(simp add: example_simps)\n   apply(rule_tac x=\"{(vertex_1,canAccessThis)}\" in exI, simp)\n   apply(simp add: example_simps)\n\n  apply(rule_tac x=\"\\<lparr> nodes={canAccessThis,vertex_2}, edges = {(vertex_2,canAccessThis)} \\<rparr>\" in exI, simp)\n  apply(rule conjI)\n   apply(simp add: wf_graph_def)\n  apply(rule_tac x=\"(\\<lambda> x. UNIV)(vertex_2 := UNIV, canAccessThis := {})\" in exI, simp)\n  apply(simp add: example_simps)\n  apply(rule_tac x=\"{(vertex_2,canAccessThis)}\" in exI, simp)\n  apply(simp add: example_simps)\n done\n\n  lemma TopoS_ACLnotCommunicateWith: \"SecurityInvariant sinvar default_node_properties receiver_violation\"\n  unfolding receiver_violation_def by unfold_locales  \n\nhide_const (open) sinvar receiver_violation default_node_properties\n\nend\n", "meta": {"author": "diekmann", "repo": "topoS", "sha": "4303ebd95a501283c02fd513c109e645a48ad080", "save_path": "github-repos/isabelle/diekmann-topoS", "path": "github-repos/isabelle/diekmann-topoS/topoS-4303ebd95a501283c02fd513c109e645a48ad080/thy/Network_Security_Policy_Verification/Security_Invariants/SINVAR_ACLnotCommunicateWith.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6859494550081926, "lm_q2_score": 0.4186969093556867, "lm_q1q2_score": 0.2872049167861479}}
{"text": "theory WelltypedSubst\nimports ExecMessage\nbegin\n\n\nsubsection{* Well-typed Ground Atomic Substitutions *}\n\ntext{* \n  TODO: Revamp proofs and tool setup, because the current setup is too ad-hoc.\n*}\n\ndefinition groundSubst :: \"(execlit \\<Rightarrow> execmsg) \\<Rightarrow> bool\"\nwhere \"groundSubst s \\<equiv> \\<forall> l. s l \\<noteq> Lit l \\<longrightarrow> ground (s l)\"\n\ndefinition welltyped :: \"(execlit \\<Rightarrow> execmsg) \\<Rightarrow> bool\"\nwhere \n\"welltyped s \\<equiv> \\<forall> l. s l \\<noteq> Lit l \\<longrightarrow>\n   (\\<exists> varid tid. l = EVar varid tid \\<and> \n     (\n       (\\<exists> a. varid = (AVar a) \\<and> \n             (s l = Lit Eve \\<or> (\\<exists> n. s l = Lit (EHonest n)))\n        ) \\<or>\n       (\\<exists> v. varid = (MVar v) \\<and> \n             ((\\<exists> n tid'. s l = Lit (ENonce n tid')) \\<or>\n              (\\<exists> n. s l = Lit (EveNonce n)))\n        )\n      )\n    )\"\n\ntypedef wt_subst = \"\\<lambda> s. s \\<in> welltyped \\<and> s \\<in> groundSubst\"\n  by(auto simp: mem_def welltyped_def groundSubst_def ran_def)\n\n\nfun subst :: \"wt_subst \\<Rightarrow> execmsg \\<Rightarrow> execmsg\"\nwhere\n  \"subst s (Lit l)   = Rep_wt_subst s l\"\n| \"subst s (Tup x y) = Tup  (subst s x) (subst s y)\"\n| \"subst s (Enc m k) = Enc  (subst s m) (subst s k)\"\n| \"subst s (Hash m)  = Hash (subst s m)\"\n| \"subst s (K a b)   = K    (subst s a) (subst s b)\"\n| \"subst s (PK a)    = PK   (subst s a)\"\n| \"subst s (SK a)    = SK   (subst s a)\"\n\n\ndefinition empty_wts :: \"wt_subst\"\nwhere \"empty_wts \\<equiv> Abs_wt_subst Lit\"\n\ndefinition extend_wts :: \"wt_subst \\<Rightarrow> wt_subst \\<Rightarrow> wt_subst\"\nwhere \"extend_wts s1 s2 \\<equiv> Abs_wt_subst (subst s2 o Rep_wt_subst s1)\"\n\ndefinition dom_wts :: \"wt_subst \\<Rightarrow> execlit set\"\nwhere \"dom_wts s \\<equiv> { l. Rep_wt_subst s l \\<noteq> Lit l }\"\n\ndefinition ran_wts :: \"wt_subst \\<Rightarrow> execmsg set\"\nwhere \"ran_wts s \\<equiv> { Rep_wt_subst s l | l. Rep_wt_subst s l \\<noteq> Lit l }\"\n\n\nsubsubsection{* Properties *}\n\nlemma Rep_wt_subst_welltyped: \"welltyped (Rep_wt_subst s)\"\n  by(insert Rep_wt_subst, simp add: wt_subst_def mem_def)\n\n\nlemma Rep_wt_subst_groundSubst: \"groundSubst (Rep_wt_subst s)\"\n  by(insert Rep_wt_subst, simp add: wt_subst_def mem_def)\n\nlemma Rep_wt_subst_ground [simp]: \n  \"l \\<in> dom_wts s \\<Longrightarrow> ground (Rep_wt_subst s l)\"\n  apply(insert Rep_wt_subst_groundSubst[of s])\n  by(auto simp: dom_wts_def groundSubst_def)\n\nlemma Rep_wt_subst_EVar_notin_dom [simp]: \n  \"EVar v tid \\<notin> dom_wts s \\<Longrightarrow> \n   Rep_wt_subst s (EVar v tid) = Lit (EVar v tid)\"\n  apply(insert Rep_wt_subst_groundSubst[of s])\n  by(auto simp: dom_wts_def groundSubst_def)\n\nlemma Rep_wt_subst_simps [simp]: \n  \"Rep_wt_subst s (EConst c)     = Lit (EConst c)\"\n  \"Rep_wt_subst s (EHonest a)    = Lit (EHonest a)\"\n  \"Rep_wt_subst s (ENonce n tid) = Lit (ENonce n tid)\"\n  \"Rep_wt_subst s (Eve)          = Lit (Eve)\"\n  \"Rep_wt_subst s (EveNonce n)   = Lit (EveNonce n)\"\n  by(insert Rep_wt_subst_welltyped[of s], auto simp: welltyped_def)\n\nlemma Rep_wt_subst_MVar_splits:\n  \"P (Rep_wt_subst s (EVar (MVar v) tid)) = (\n   (          Rep_wt_subst s (EVar (MVar v) tid) = (Lit (EVar (MVar v) tid)) \\<longrightarrow> P (Lit (EVar (MVar v) tid))) \\<and> \n   (\\<forall> n tid'. Rep_wt_subst s (EVar (MVar v) tid) = (Lit (ENonce n tid'))     \\<longrightarrow> P (Lit (ENonce n tid'))) \\<and>\n   (\\<forall> n.      Rep_wt_subst s (EVar (MVar v) tid) = (Lit (EveNonce n))        \\<longrightarrow> P (Lit (EveNonce n))))\"\n  apply(insert Rep_wt_subst_welltyped[of s])\n  apply(simp add: welltyped_def)\n  apply(drule_tac x=\"EVar (MVar v) tid\" in spec)\n  by(auto)\n\nlemma Rep_wt_subst_AVar_splits:\n  \"P (Rep_wt_subst s (EVar (AVar a) tid)) = (\n   (     Rep_wt_subst s (EVar (AVar a) tid) = (Lit (EVar (AVar a) tid)) \\<longrightarrow> P (Lit (EVar (AVar a) tid))) \\<and> \n   (\\<forall> n. Rep_wt_subst s (EVar (AVar a) tid) = (Lit (EHonest n))         \\<longrightarrow> P (Lit (EHonest n))) \\<and>\n   (\\<forall> n. Rep_wt_subst s (EVar (AVar a) tid) = (Lit Eve)                 \\<longrightarrow> P (Lit Eve)))\"\n  apply(insert Rep_wt_subst_welltyped[of s])\n  apply(simp add: welltyped_def)\n  apply(drule_tac x=\"EVar (AVar a) tid\" in spec)\n  by(auto)\n\nlemma Rep_wt_subst_AVar_cases:\n  \"(     Rep_wt_subst s (EVar (AVar a) tid) = (Lit (EVar (AVar a) tid))) \\<or>\n   (\\<exists> n. Rep_wt_subst s (EVar (AVar a) tid) = (Lit (EHonest n))) \\<or>\n   (Rep_wt_subst s (EVar (AVar a) tid) = (Lit Eve))\"\n  apply(insert Rep_wt_subst_welltyped[of s])\n  by(auto simp: welltyped_def)\n\nlemma subst_ground_msg [simp]: \"ground m \\<Longrightarrow> subst s m = m\"\n  by(induct m, case_tac lit, auto)\n\nlemma subst_idem [simp]: \"subst s (subst s m) = subst s m\"\n  apply(induct m, case_tac lit, simp_all)\n  apply(case_tac \"EVar varid nat \\<in> dom_wts s\", simp+)\n  done\n\nlemma subst_Rep_wt_subst_idem [simp]:\n  \"subst s (Rep_wt_subst s l) = Rep_wt_subst s l\"\n  apply(rule_tac s=\"subst s (Lit l)\" in subst)\n  apply(simp, rule subst_idem)\n  done\n\nlemma Abs_wt_subst_extend_wts_inverse [simp]:\n  \"Rep_wt_subst (Abs_wt_subst (subst s' o Rep_wt_subst s)) = subst s' o Rep_wt_subst s\"\n  apply(subst Abs_wt_subst_inverse)\n  apply(insert Rep_wt_subst_welltyped[of s])\n  apply(insert Rep_wt_subst_welltyped[of s'])\n  apply(simp add: welltyped_def groundSubst_def o_def wt_subst_def mem_def)\n  apply(safe)\n  apply(drule_tac x=l in spec)+\n  defer 1\n  apply(drule_tac x=l in spec)+\n  apply(auto)\n  done\n\nlemma extend_wts_conv_subst: \n  \"subst (extend_wts s s') m = subst s' (subst s m)\"\n  by(induct m, induct_tac lit, auto simp: extend_wts_def)\n\n\nlemma dom_wts_empty_wts [simp]: \"dom_wts empty_wts = {}\"\n  by(simp add: dom_wts_def empty_wts_def wt_subst_def\n               Abs_wt_subst_inverse welltyped_def groundSubst_def mem_def)\n\nlemma dom_wts_extend_wts [simp]: \"dom_wts (extend_wts s s') = dom_wts s \\<union> dom_wts s'\"\n  apply(auto simp: dom_wts_def extend_wts_def)\n  apply(insert Rep_wt_subst_welltyped[of s])\n  apply(insert Rep_wt_subst_welltyped[of s'])\n  apply(simp add: welltyped_def groundSubst_def o_def wt_subst_def mem_def)\n  apply(drule_tac x=x in spec)+\n  apply(auto)\n  done\n\n\nlemma Abs_wt_subst_empty_wts_inverse [simp]: \n  \"Rep_wt_subst (Abs_wt_subst Lit) = Lit\"\n  by(simp add: mem_def welltyped_def wt_subst_def \n               groundSubst_def Abs_wt_subst_inverse)\n\nlemma subst_empty_wts [simp]: \"subst empty_wts m = m\"\n  by(induct m, auto simp: empty_wts_def)\n\nlemma unpair_subst_distr: \"x \\<in> unpair m \\<Longrightarrow> subst s x \\<in> unpair (subst s m)\"\n  apply(induct m rule: subst.induct, auto)\n  apply(subgoal_tac \"welltyped (Rep_wt_subst s)\") defer 1\n  apply(rule Rep_wt_subst_welltyped)\n  apply(simp add: welltyped_def)\n  apply(drule_tac x=l in spec)\n  apply(auto)\n  done\n\nlemma inv_subst_comm [simp]: \n  \"subst s (inv m) = inv (subst s m)\"\n  apply(induct m rule: subst.induct, auto)\n  apply(subgoal_tac \"welltyped (Rep_wt_subst s)\")\n  apply(simp add: welltyped_def)\n  apply(drule_tac x=l in spec)\n  apply(auto simp: Rep_wt_subst_welltyped)\n  done\n\n\nlemma ground_subst_s2e_conv_FV: \n  \"ground (subst s (s2e msg tid)) = (\\<forall> v \\<in> FV msg. EVar v tid \\<in> dom_wts s)\"\n  apply(induct msg, induct_tac lit)\n  apply(simp_all)\n  apply(case_tac \"EVar varid tid \\<in> dom_wts s\")\n  apply(auto)\n  done\n\nlemma subst_subdomain: \n  \"dom_wts s' \\<subseteq> dom_wts s \\<Longrightarrow> subst s' (subst s m) = subst s m\"\n  apply(induct m rule: subst.induct, simp_all)\n  apply(case_tac \"l \\<in> dom_wts s\")\n  apply(auto simp: dom_wts_def)\n  done\n\nlemma Rep_wt_subst_atomic: \"\\<exists> l'. Rep_wt_subst s l = Lit l'\"\n  apply(insert Rep_wt_subst_welltyped[of s])\n  apply(simp add: welltyped_def)\n  apply(drule_tac x=l in spec, auto)\n  done\n\nlemma Rep_wt_subst_noteq_simps [simp]: \n  \"Rep_wt_subst s l \\<noteq> Hash m\"\n  \"Rep_wt_subst s l \\<noteq> Enc m k\"\n  \"Rep_wt_subst s l \\<noteq> Tup x y\"\n  \"Rep_wt_subst s l \\<noteq> PK a\"\n  \"Rep_wt_subst s l \\<noteq> SK a\"\n  \"Rep_wt_subst s l \\<noteq> K a b\"\n  by(insert Rep_wt_subst_atomic[of s l], auto)\n\nlemma Rep_wt_subst_AV_noteq [simp]:\n  \"Rep_wt_subst s (EVar (AVar a) tid) \\<noteq> Lit (EConst c)\"\n  \"Rep_wt_subst s (EVar (AVar a) tid) \\<noteq> Lit (ENonce n' tid')\"\n  apply(insert Rep_wt_subst_AVar_cases[of \"s\" a tid])\n  apply(auto)\n  done\n\nlemma subst_notin_dom_wts [iff]:\n  \"(Rep_wt_subst s x = Lit x) = (x \\<notin> dom_wts s)\"\n  by(auto simp: dom_wts_def)\n\n(* NOTE: makes unfolding dom_wts using simp loop *)\nlemma subst_in_dom_wts [iff]:\n  \"(Rep_wt_subst s x \\<noteq> Lit x) = (x \\<in> dom_wts s)\"\n by(simp)\n\nlemma Rep_wt_subst_AVar_in_IK0 [intro!, simp]:\n  \"EVar (AVar a) tid \\<in> dom_wts s \\<Longrightarrow>\n   Rep_wt_subst s (EVar (AVar a) tid) \\<in> IK0\"\n  by(insert Rep_wt_subst_AVar_cases[of s a tid], auto)\n\nlemma EVar_ground_imp_in_dom_wts [iff]:\n  \"(ground (Rep_wt_subst s (EVar v tid))) = (EVar v tid \\<in> dom_wts s)\"\n  apply(case_tac \"(Rep_wt_subst s (EVar v tid)) = Lit ( (EVar v tid))\")\n  apply(auto)\n  done\n\nlemma unpair_Rep_wt_subst_AVar [simp]:\n  \"unpair (Rep_wt_subst s (EVar (AVar a) tid))= \n   {Rep_wt_subst s (EVar (AVar a) tid)}\"\n  by(insert Rep_wt_subst_atomic[of s \"EVar (AVar a) tid\"], auto)\n\nlemma unpair_Rep_wt_subst_MVar [simp]:\n  \"unpair (Rep_wt_subst s (EVar (MVar n) tid))= \n   {Rep_wt_subst s (EVar (MVar n) tid)}\"\n  by(insert Rep_wt_subst_atomic[of s \"EVar (MVar n) tid\"], auto)\n\ndeclare Rep_wt_subst_noteq_simps[THEN neq_commute[THEN iffD1], iff]\n\n\nlemma Rep_wt_subst_reorient_Lit [iff]:\n  \"(Lit l = Rep_wt_subst s l') = (Rep_wt_subst s l' = Lit l)\"\n  by(auto)\n\nlemma pairParts_Rep_wt_subst_AVar [simp]:\n  \"pairParts (Rep_wt_subst s (EVar (AVar a) tid))= \n   {Rep_wt_subst s (EVar (AVar a) tid)}\"\n  by(insert Rep_wt_subst_atomic[of s \"EVar (AVar a) tid\"], auto)\n\nlemma pairParts_Rep_wt_subst_MVar [simp]:\n  \"pairParts (Rep_wt_subst s (EVar (MVar n) tid))= \n   {Rep_wt_subst s (EVar (MVar n) tid)}\"\n  by(insert Rep_wt_subst_atomic[of s \"EVar (MVar n) tid\"], auto)\n\n\nend", "meta": {"author": "meiersi", "repo": "scyther-proof", "sha": "84e42366a46f66f1b090651be3bfaa3497696280", "save_path": "github-repos/isabelle/meiersi-scyther-proof", "path": "github-repos/isabelle/meiersi-scyther-proof/scyther-proof-84e42366a46f66f1b090651be3bfaa3497696280/data/isabelle/src/experiments/WelltypedSubst.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5698526660244838, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.2871522747021847}}
{"text": "section {* Tagging of Terms *}\ntheory Autoref_Tagging\nimports \"../Lib/Refine_Lib\" \nbegin\ntext {*\n  We provide a mechanism to tag terms, that supports relator annotations,\n  and introduces tags to protect operations, function applications, and \n  abstractions from automatic beta and eta conversions.\n*}\n\n\nML {*\n  structure Autoref_Tag_Defs = Named_Thms (\n    val name = @{binding autoref_tag_defs}\n    val description = \"Autoref: Definitions of internal tags\"\n  )\n*}\nsetup Autoref_Tag_Defs.setup\n\n\ntext {* General protection tag *}\ndefinition PROTECT where [simp, autoref_tag_defs]: \"PROTECT x \\<equiv> x\"\n\ntext {* General annotation tag *}\ntypedecl annot\ndefinition ANNOT :: \"'a \\<Rightarrow> annot \\<Rightarrow> 'a\" \n  where [simp, autoref_tag_defs]: \"ANNOT x a \\<equiv> x\"\n\ntext {* Operation-tag, Autoref does not look beyond this *}\ndefinition OP where [simp, autoref_tag_defs]: \"OP x \\<equiv> x\"\n\ntext {* Protected function application *}\ndefinition APP (infixl \"$\" 900) where [simp, autoref_tag_defs]: \"f$a \\<equiv> f a\"\n\ntext {* Protected abstraction *}\nabbreviation ABS :: \"('a\\<Rightarrow>'b)\\<Rightarrow>'a\\<Rightarrow>'b\" (binder \"\\<lambda>''\" 10)\n  where \"ABS f \\<equiv> PROTECT (\\<lambda>x. PROTECT (f x))\"\n\n\nlemma ABS_beta: \"(\\<lambda>'x. f x)$x \\<equiv> f x\" by simp\nlemma ABS_eta: \"\\<lambda>'x. (f$x) \\<equiv> f\" by simp\n\ntext {* This tag is used to highlight failures during operation \n  identification *}\ndefinition \"ID_FAIL x \\<equiv> x\"\nnotation (output) ID_FAIL (\"FAIL *** _ ***\")\n\n\ntext {* Relator annotation *}\nconsts rel_annot :: \"('c\\<times>'a) set \\<Rightarrow> annot\"\nabbreviation rel_ANNOT :: \"'a \\<Rightarrow> ('c \\<times> 'a) set \\<Rightarrow> 'a\" (infix \":::\" 10)\n  where \"t:::R \\<equiv> ANNOT t (rel_annot R)\"\n\nlemma rel_ANNOT_eq: \"t \\<equiv> t:::R\" by simp\n\ntext {* Indirect annotation *}\ntypedecl rel_name\nconsts ind_annot :: \"rel_name \\<Rightarrow> annot\"\nabbreviation ind_ANNOT :: \"'a \\<Rightarrow> rel_name \\<Rightarrow> 'a\" (infix \"::#\" 10)\n  where \"t::#s \\<equiv> ANNOT t (ind_annot s)\"\n\n\n\n\n\nML {*\n  signature AUTOREF_TAGGING = sig\n    val term_of_tagged: term -> term\n    val is_valid_tagged: term -> bool\n\n    val mk_APP: term -> term -> term\n    val mk_OP: term -> term\n    val lambda': string * typ -> term -> term\n\n    val list_APP: term * term list -> term\n    val strip_app: term -> term * term list\n\n    val untag_conv: Proof.context -> conv\n\n    val mk_APP_conv: conv\n    val mk_OP_conv: conv\n    val mk_ABS_conv: Proof.context -> conv\n    val mk_ANNOT_conv: cterm -> conv\n    val mk_rel_ANNOT_conv: Proof.context -> cterm -> conv\n\n    val ABS_beta_conv: Proof.context -> conv\n\n    val rhs_conv: (Proof.context -> conv) -> Proof.context -> conv\n  end\n\n\n  structure Autoref_Tagging :AUTOREF_TAGGING = struct\n    fun term_of_tagged (Free v) = Free v\n      | term_of_tagged (Var v) = Var v\n      | term_of_tagged (Bound i) = Bound i\n      | term_of_tagged @{mpat \"OP ?t\"} = t\n      | term_of_tagged @{mpat \"ANNOT ?t _\"} = term_of_tagged t\n      | term_of_tagged @{mpat \"?f$?x\"} = term_of_tagged f $ term_of_tagged x\n      | term_of_tagged @{mpat \"PROTECT (\\<lambda>x. PROTECT ?t)\"} \n        = Abs (x,x_T,term_of_tagged t)\n      | term_of_tagged @{mpat (typs) \"PROTECT (PROTECT::?'v_T\\<Rightarrow>_)\"} \n        = Abs (\"x\",T,Bound 0)\n      | term_of_tagged t = raise TERM (\"term_of_tagged\",[t])\n\n    fun is_valid_tagged (Free _) = true\n      | is_valid_tagged (Var _) = true\n      | is_valid_tagged (Bound _) = true\n      | is_valid_tagged @{mpat \"OP _\"} = true\n      | is_valid_tagged @{mpat \"ANNOT ?t _\"} = is_valid_tagged t\n      | is_valid_tagged @{mpat \"?f$?x\"} \n        = is_valid_tagged f andalso is_valid_tagged x\n      | is_valid_tagged @{mpat \"PROTECT (\\<lambda>_. PROTECT ?t)\"} = is_valid_tagged t\n      | is_valid_tagged @{mpat \"PROTECT PROTECT\"} = true\n      | is_valid_tagged _ = false\n\n    fun mk_APP f x = let\n      val fT = fastype_of f\n      val xT = fastype_of x\n      val rT = range_type fT\n    in\n      Const (@{const_name APP},fT --> xT --> rT)$f$x\n    end;\n\n    fun mk_OP x = let \n      val T = fastype_of x \n    in \n      Const(@{const_name OP},T-->T)$x\n    end\n\n    fun lambda' (name,T) t = let\n      val tT = fastype_of t\n      val t' = Const (@{const_name PROTECT},tT --> tT)$\n        abstract_over (Free (name,T), t)\n      val t' = \n        Const (@{const_name PROTECT},(T --> tT) --> T --> tT)$Abs (name,T,t')\n    in\n      t'\n    end\n\n    val list_APP = Library.foldl (uncurry mk_APP)\n\n    (* f$x1$...$xn goes to (f,[x1,...,xn]*)\n    fun strip_app t = let\n      fun strip_app_aux @{mpat \"?f$?x\"} args = strip_app_aux f (x::args)\n        | strip_app_aux t args = (t,args)\n    in strip_app_aux t [] end\n      \n    fun untag_conv ctxt = Raw_Simplifier.rewrite ctxt\n      true (Autoref_Tag_Defs.get ctxt)\n\n    fun ABS_beta_conv ctxt = Raw_Simplifier.rewrite ctxt\n      true @{thms ABS_beta}\n  \n    val mk_PROTECT_conv = Conv.rewr_conv @{thm PROTECT_def[symmetric]}\n    val mk_APP_conv = Conv.rewr_conv @{thm APP_def[symmetric]}\n    val mk_OP_conv = Conv.rewr_conv @{thm OP_def[symmetric]}\n    fun mk_ABS_conv ctxt = Conv.abs_conv (K mk_PROTECT_conv) ctxt\n      then_conv mk_PROTECT_conv\n\n    fun mk_ANNOT_conv a ct = let\n      val Tt = Thm.ctyp_of_cterm ct\n\n      val thm = Thm.instantiate' [SOME Tt] [SOME ct,SOME a] \n        @{thm ANNOT_def[symmetric]}\n    in\n      thm\n    end\n\n    fun mk_rel_ANNOT_conv ctxt a ct = let\n      val T = Thm.typ_of_cterm a\n      val (Tc,Ta) = HOLogic.dest_setT T \n        |> HOLogic.dest_prodT \n        |> apply2 (Thm.ctyp_of ctxt)\n      val thm = Thm.instantiate' [SOME Ta, SOME Tc] [SOME ct,SOME a] \n        @{thm rel_ANNOT_eq}\n    in\n      thm\n    end\n\n    (* Convert right hand side of refinement statement *)\n    fun rhs_conv conv ctxt ct = let \n      open Conv Refine_Util \n    in\n      case Logic.strip_imp_concl (Thm.term_of ct) of\n        @{mpat \"Trueprop ((_,_)\\<in>_)\"} =>\n          HOL_concl_conv (fn ctxt => (arg1_conv (arg_conv (conv ctxt)))) ctxt ct\n      | _ => raise CTERM (\"rhs_conv\",[ct])\n    end\n  end\n\n*}\n\nML_val {*\n  Autoref_Tagging.mk_ANNOT_conv @{cterm \"bar::annot\"} @{cterm \"foo::'a::type\"};\n*}\n\nML_val {*\n  Autoref_Tagging.mk_rel_ANNOT_conv @{context}\n    @{cterm \"bar::('c\\<times>'a) set\"} @{cterm \"foo::'a::type\"}\n*}\n\nend\n", "meta": {"author": "diekmann", "repo": "Iptables_Semantics", "sha": "e0a2516bd885708fce875023b474ae341cbdee29", "save_path": "github-repos/isabelle/diekmann-Iptables_Semantics", "path": "github-repos/isabelle/diekmann-Iptables_Semantics/Iptables_Semantics-e0a2516bd885708fce875023b474ae341cbdee29/thy/Automatic_Refinement/Tool/Autoref_Tagging.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5698526368038304, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.2871522599777171}}
{"text": "theory RB_Relaxed imports RCU_Lems \nbegin\n\ndatatype F = B | W | Q | R\ndatatype Pointer = Head | Tail\n\nconsts n :: nat   (*size of buffer, input*)\nconsts N :: nat   (*number of Arr\\<^sub>W entries*)\n\n\nlemma pval_val_same:\n  assumes \"wfs \\<sigma>\"\n  and \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  and \"u \\<noteq> v\"\n  and \"var w = x\"\nshows \"\\<not> [x \\<approx>\\<^sub>t u] (Wr x v t b \\<sigma>)\"\n  using assms\n  apply (simp add: p_obs_def visible_writes_def value_def write_trans_def)\n  apply(simp add: rev_app_def update_modView_def update_mods_def update_thrView_def update_wa_def)\n  apply safe  \n  using w_in_writes_on_var apply blast\n  defer  \n  apply (simp add: getVWNC_var)\n   apply (simp add: getVWNC_var)\n  apply(case_tac \"(a, ba)\n       \\<in> writes_on \\<sigma> x\")\n  apply (smt dual_order.strict_trans getTS_w_greater_tst_w getVWNC_in_visible_writes le_neq_trans less_le_not_le mem_Collect_eq visible_writes_def)\nproof -\nfix a :: nat and ba :: rat\n  assume a1: \"(a, ba) \\<in> writes_on (\\<sigma> \\<lparr>thrView := (thrView \\<sigma>) (t := (thrView \\<sigma> t) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))))), modView := (modView \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))) := (thrView \\<sigma> t) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))))), mods := (mods \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))) := \\<lparr>val = v, is_releasing = b\\<rparr>), writes := insert (var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))) (surrey_state.writes \\<sigma>), write_available := (write_available \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))) := True)\\<rparr>) (var w)\"\n  assume a2: \"x = var w\"\n  assume a3: \"(a, ba) \\<notin> writes_on \\<sigma> x\"\n  assume a4: \"ba \\<noteq> getTS \\<sigma> (getVWNC \\<sigma> t (var w))\"\n  have f5: \"\\<forall>s n p. var p = n \\<and> p \\<in> surrey_state.writes (s::surrey_state) \\<or> p \\<notin> writes_on s n\"\n    using writes_on_def by force\n  have \"\\<forall>s n p. writes_on (write_available_update p (s::surrey_state)) n = writes_on s n\"\n    by (metis (no_types) surrey_state.select_convs(1) surrey_state.surjective surrey_state.update_convs(5) writes_on_def)\n  then have f6: \"(a, ba) \\<in> writes_on (\\<sigma> \\<lparr>thrView := (thrView \\<sigma>) (t := (thrView \\<sigma> t) (x := (x, getTS \\<sigma> (getVWNC \\<sigma> t x)))), modView := (modView \\<sigma>) ((x, getTS \\<sigma> (getVWNC \\<sigma> t x)) := (thrView \\<sigma> t) (x := (x, getTS \\<sigma> (getVWNC \\<sigma> t x)))), mods := (mods \\<sigma>) ((x, getTS \\<sigma> (getVWNC \\<sigma> t x)) := \\<lparr>val = v, is_releasing = b\\<rparr>), writes := insert (x, getTS \\<sigma> (getVWNC \\<sigma> t x)) (surrey_state.writes \\<sigma>)\\<rparr>) x\"\n    using a2 a1 by blast\n  have f7: \"\\<forall>s f. surrey_state.writes (writes_update f (s::surrey_state)) = f (surrey_state.writes s)\"\n    by auto\n  have f8: \"var (a, ba) = x\"\n    using f6 f5 by meson\n  have \"(a, ba) \\<in> surrey_state.writes \\<sigma>\"\n    using f7 f6 f5 a4 a2 by (metis insert_iff snd_conv)\n  then show False\n    using f8 a3 writes_on_def by force\nqed\n\n\n\nlemma pval_val_other:\n  assumes \"wfs \\<sigma>\"\n  and \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  and \"u \\<noteq> v\"\n  and \"var w = x\"\n  and \"t\\<noteq>s\"\nshows \"\\<not> [x \\<approx>\\<^sub>t u] (Wr x v s b \\<sigma>)\"\n  using assms apply simp\n  apply (simp add: p_obs_def visible_writes_def value_def write_trans_def)\n    apply(simp add: rev_app_def update_modView_def update_mods_def update_thrView_def update_wa_def)\n  apply safe  \n  using w_in_writes_on_var\n  apply (simp add: w_in_writes_on_var getVWNC_var) \n  apply (simp add: getVWNC_var)\n\n  apply(case_tac \"(a, ba)\n       \\<in> writes_on \\<sigma> x\")\n  apply (smt dual_order.strict_trans getTS_w_greater_tst_w getVWNC_in_visible_writes le_neq_trans less_le_not_le mem_Collect_eq visible_writes_def)\nproof -\n  fix a :: nat and ba :: rat\n  assume a1: \"ba \\<noteq> getTS \\<sigma> (getVWNC \\<sigma> s (var w))\"\n  assume a2: \"(a, ba) \\<in> writes_on (\\<sigma> \\<lparr>thrView := (thrView \\<sigma>) (s := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), modView := (modView \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), mods := (mods \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := \\<lparr>val = v, is_releasing = b\\<rparr>), writes := insert (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) (surrey_state.writes \\<sigma>), write_available := (write_available \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := True)\\<rparr>) (var w)\"\n  assume a3: \"(a, ba) \\<notin> writes_on \\<sigma> x\"\n  assume a4: \"x = var w\"\n  have \"(a, ba) \\<in> \\<lbrace>\\<acute>var = var w \\<and> \\<acute>(\\<in>) (surrey_state.writes (\\<sigma> \\<lparr>thrView := (thrView \\<sigma>) (s := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), modView := (modView \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), mods := (mods \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := \\<lparr>val = v, is_releasing = b\\<rparr>), writes := insert (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) (surrey_state.writes \\<sigma>), write_available := (write_available \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := True)\\<rparr>))\\<rbrace>\"\n    using a2 writes_on_def by blast\n  then have f5: \"var (a, ba) = var w \\<and> (a, ba) \\<in> surrey_state.writes (\\<sigma> \\<lparr>thrView := (thrView \\<sigma>) (s := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), modView := (modView \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), mods := (mods \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := \\<lparr>val = v, is_releasing = b\\<rparr>), writes := insert (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) (surrey_state.writes \\<sigma>), write_available := (write_available \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := True)\\<rparr>)\"\n    by blast\n  then have \"(a, ba) \\<notin> surrey_state.writes \\<sigma>\"\n    using a4 a3 writes_on_def by fastforce\n  then show False\n    using f5 a1 by simp\nqed\n\n\n\nlemma pval_val:\n  assumes \"wfs \\<sigma>\"\n  and \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  and \"u \\<noteq> v\"\n  and \"var w = x\"\nshows \"\\<not> [x \\<approx>\\<^sub>t u] (Wr x v t' b \\<sigma>)\"\n  using assms apply (cases \"t=t'\")\n  using pval_val_same apply blast\n  using pval_val_other by blast\n\n\n\n\nlemma pval_val_outside:\n  assumes \"wfs \\<sigma>\"\n  and \"N\\<in> \\<nat>\"\n  and \"\\<forall>j.[x \\<approx>\\<^sub>t j] \\<sigma> \\<longrightarrow> j<N\"\n  and \"\\<forall>k. k<N \\<longrightarrow> [x \\<approx>\\<^sub>t k] \\<sigma>\"\n  and \"u\\<in>\\<nat> \\<and> u<N\"\nshows \"\\<forall>z.(z>N\\<longrightarrow>\\<not>[x \\<approx>\\<^sub>t z] (Wr x u t' b \\<sigma>))\"\n  using assms apply (cases \"t=t'\")\n  apply (metis fst_conv not_less_iff_gr_or_eq pval_val)\n  by (metis fst_conv not_less_iff_gr_or_eq pval_val)\n\n\n(*Ex (d_obs_t (Wr T 0 2 False (\\<sigma> x)) 3 T)*)\n\n\n(*\n  assumes \"wfs \\<sigma>\"\n  and \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  and \"u \\<noteq> v\"\n  and \"var w = x\"\nshows \"\\<not> [x \\<approx>\\<^sub>t u] (Wr x v t b \\<sigma>)\"\n\n\nlemma pval_val_all: \n  assumes \"wfs \\<sigma>\"\n  and \"\\<forall>i. i > k \\<longrightarrow> \\<not> [x \\<approx>\\<^sub>t i] \\<sigma>\"\n  and \"k < j\" \n  and \"u \\<le> k\"\n  and \"var w = x\"\nshows \"\\<not> [x \\<approx>\\<^sub>t j] (Wr x v t b \\<sigma>) \"\n  using assms\n  \n  using pval_val sledgehammer\n*)\n\nconsts   \n  H :: L\n  T :: L\n\n\nrecord LB =\n  hW ::  V               (*local copy of W*)\n  tW ::  V               (*local copy of W*)\n  q :: \"(nat \\<times> nat) list\" (*for now assume well synchronised, need to think about weak memory *)\n  tempR :: \"(nat \\<times> nat)\"          (*local copy of word by R*)\n\n  Data:: \"nat  \\<Rightarrow> nat\"     (*returns a word Data_i*)\n  countW :: nat  (* the index of the next element of Data to be written  *)\n  countR :: nat  (* how many words from Data the read has read or reading (i.e., retrieved)  *)\n\n  ownD :: \"nat \\<Rightarrow> F\" (* ownership of data indices *)\n  ownB :: \"nat \\<Rightarrow> F\" (* ownership of bytes in buffer *)\n  (* tries :: nat *)\n  oom :: bool       (*signals W that it was OOM*)\n  \\<sigma> :: surrey_state\n\ndefinition \"global s \\<equiv> wfs s \\<and> H \\<noteq> T\"\n\n\n\n\nlemmas opsemsyntax [simp] =  global_def\nlemmas defs_del [simp del] =  Rd_def Let_def Wr_def Upd_def st_rd_def val_rd_def\n\n(* thread 2 is the writer *)\n(* thread 3 is the reader *)\n\n(* Omit tries *)\n(* Finish queueu + reader *)\n\n(* We need this one to hold at minimum *)\ndefinition \"arrayInv s \\<equiv> \\<forall>i. (i<countR s \\<longrightarrow> ownD s i = R)\\<and> (countR s \\<le> i \\<and> i < countW s \\<longrightarrow> ownD s i = B) \\<and> (countW s \\<le> i \\<and> i < n \\<longrightarrow> ownD s i = W) \"\n\n\ndefinition \"q_entries_bounded s \\<equiv> (\\<forall>i. i < length(q s) \\<longrightarrow> (fst(q s!i)+snd(q s!i)\\<le>N)\\<and>snd(q s!i)>0)\"\ndefinition \"tempR_bounded s \\<equiv> fst (tempR s) + snd (tempR s) \\<le> N\"\ndefinition \"counter_q_rel s \\<equiv> (countW s-countR s=length(q s))\"\ndefinition \"con_assms s  \\<equiv>   0 < N \\<and> 0<n \\<and> (countR s\\<le>countW s) \\<and> (countW s\\<le>n)\n                             \\<and> (\\<forall>i.(i<n)\\<longrightarrow>Data s i\\<le>N \\<and> Data s i>0)\"\n(*new\n(typically)\n\\forall x . P(x) \\<longrightarrow> Q(x)\n\\exists x . P(x) \\<and> Q(x)\n\n[H =\\<^sub>2 i] means thread 2 sees the last write to H and this has value i.\n[H \\<approx>\\<^sub>2 i] means that thread 2 can see the value i.\n*)\ndefinition \"bounded_pointers s \\<equiv> ((\\<forall>i. i > N \\<longrightarrow> \\<not>[H \\<approx>\\<^sub>2 i] (\\<sigma> s)))\\<and>\n                                 ((\\<forall>j. j > N \\<longrightarrow> \\<not>[T \\<approx>\\<^sub>2 j] (\\<sigma> s)))\"\n\ndefinition \"basic_pointer_movement s \\<equiv> 0\\<le>hW s\\<and> hW s\\<le>N \\<and> 0\\<le>tW s\\<and> tW s\\<le>N\"\n\n\n\ndefinition \"collection s \\<equiv> arrayInv s \\<and> q_entries_bounded s\n                          \\<and>tempR_bounded s \\<and>counter_q_rel s \\<and> con_assms s\n                          \\<and> bounded_pointers s \\<and> basic_pointer_movement s\n                          \"\n\n\ndefinition \"init s \\<equiv>\n                     [T =\\<^sub>2 0] (\\<sigma> s) \\<and> [H =\\<^sub>2 0] (\\<sigma> s) \\<and> (q s = []) \\<and> (hW s = 0) \\<and> (tW s = 0)\n                        \\<and> (\\<forall>l. (l<n) \\<longrightarrow>  ((Data s l > 0)\\<and>(Data s l \\<le> N)))\n                        \\<and> (\\<forall>i. (i<n) \\<longrightarrow>  ownD s i = W)\n                        \\<and> (\\<forall>i. (i\\<le>N) \\<longrightarrow>  ownB s i = B)\n                        \\<and> (countW s = 0) \\<and> (countR s = 0)\n                        \\<and> (tempR s = (0,0)) \\<and> \\<not> oom s \"\n\ndefinition \"grd1 s \\<equiv> (tW s = hW s) \\<and> (Data s (countW s) \\<le> N) \"\ndefinition \"grd2 s \\<equiv> (tW s > hW s) \\<and> (Data s (countW s) < (tW s - hW s)) \"\ndefinition \"grd3 s \\<equiv> tW s < hW s \"\ndefinition \"grd4 s \\<equiv> Data s (countW s) \\<le> N - hW s \"\ndefinition \"grd5 s \\<equiv> Data s (countW s) < tW s \"\ndefinition \"no_space_for_word s \\<equiv> (grd1 s \\<longrightarrow> \\<not>(Data s (countW s) \\<le> N))\\<and>\n                                  (grd2 s \\<longrightarrow> \\<not>(Data s (countW s) < (tW s - hW s)))\\<and>\n                                  (grd3 s \\<longrightarrow> \\<not>(Data s (countW s) \\<le> N - hW s \\<or> Data s (countW s) < tW s))\"\n\n\n\nlemmas main_invariant_lemmas = collection_def arrayInv_def q_entries_bounded_def \n                                      counter_q_rel_def tempR_bounded_def con_assms_def\n                                      init_def bounded_pointers_def basic_pointer_movement_def\n                                      pval_val_same pval_val_other pval_val \nlemmas guards = grd1_def grd2_def grd3_def grd4_def grd5_def no_space_for_word_def\n\n\nlemma LoadBuffering:\n \"\\<parallel>-   \\<lbrace> global \\<acute>\\<sigma>  \\<and> \\<acute>collection  \\<and> \\<acute>init \\<rbrace>\nCOBEGIN\n\\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection  \\<and> \\<not> \\<acute>oom \\<and> \\<acute>init\\<rbrace>\n  WHILE \\<acute>countW < n \n   INV \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> (\\<exists> i. [H =\\<^sub>2 i]\\<acute>\\<sigma>)\\<rbrace>\n   DO\n    \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> (\\<exists> i. [H =\\<^sub>2 i]\\<acute>\\<sigma>) \\<and> \\<acute>countW < n\\<rbrace> \\<comment> \\<open>A1\\<close>\n      <\\<acute>hW \\<leftarrow>\\<^sub>2 H\\<acute>\\<sigma>> ;;  \n    \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection  \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n\\<rbrace>\n      <\\<acute>tW \\<leftarrow>\\<^sub>2 T\\<acute>\\<sigma>> ;;\n    \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection  \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n\\<rbrace>\n      IF \\<acute>grd1 \\<comment> \\<open>A2\\<close>\n      THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd1 \\<rbrace> \\<comment> \\<open>A3\\<close>\n            <T :=\\<^sub>2 0 \\<acute>\\<sigma>> ;; \\<comment> \\<open>This might not need to be releasing\\<close>  \n            \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd1 \\<rbrace>\n            \\<langle><H :=\\<^sub>2 (\\<acute>Data \\<acute>countW) \\<acute>\\<sigma>> ,, \\<acute>hW := 0 ,, \\<acute>oom := False ,,\n              (\\<acute>ownB := ( \\<lambda> x. if 0\\<le> x \\<and> x < (\\<acute>Data \\<acute>countW) then W else \\<acute>ownB x ))\\<rangle>\n      ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<not>\\<acute>grd1 \\<rbrace> \n            IF \\<acute>grd2\n            THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd2\\<rbrace> \\<comment> \\<open>A4\\<close>\n                \\<langle><H :=\\<^sub>2 \\<acute>hW + (\\<acute>Data \\<acute>countW) \\<acute>\\<sigma>> ,, \\<acute>oom := False ,,\n                  (\\<acute>ownB := ( \\<lambda> x. if \\<acute>hW \\<le> x \\<and> x < (\\<acute>hW + (\\<acute>Data \\<acute>countW)) then W else \\<acute>ownB x ))\\<rangle>\n            ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<not>\\<acute>grd1 \\<and> \\<not>\\<acute>grd2\\<rbrace>\n                 IF \\<acute>grd3\n                 THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd3 \\<rbrace> \\<comment> \\<open>A5\\<close>\n                      IF \\<acute>grd4\n                      THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd3 \\<and> \\<acute>grd4 \\<rbrace> \\<comment> \\<open>A6\\<close>\n                      \\<langle><H :=\\<^sub>2 \\<acute>hW + (\\<acute>Data \\<acute>countW) \\<acute>\\<sigma>> ,, \\<acute>oom := False ,,\n                         (\\<acute>ownB := ( \\<lambda> x. if \\<acute>hW \\<le> x \\<and> x < (\\<acute>hW + (\\<acute>Data \\<acute>countW)) then W else \\<acute>ownB x ))\\<rangle>\n                      ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd3 \\<and> \\<not>\\<acute>grd4 \\<rbrace>\n                            IF \\<acute>grd5\n                            THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd3 \\<and> \\<acute>grd5 \\<rbrace> \\<comment> \\<open>A7\\<close>\n                              \\<langle><H :=\\<^sub>2 (\\<acute>Data \\<acute>countW) \\<acute>\\<sigma>> ,, \\<acute>hW := 0 ,, \\<acute>oom := False ,,\n                                (\\<acute>ownB := ( \\<lambda> x. if ((0 \\<le> x \\<and> x < (\\<acute>Data \\<acute>countW))\\<or> x\\<ge>\\<acute>tW)\\<and>x\\<noteq>N then W else \\<acute>ownB x ))\\<rangle>\n                            ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>no_space_for_word\\<rbrace> \\<comment> \\<open>A8\\<close>\n                                \\<langle>\\<acute>oom := True\\<rangle>\n                                  \\<comment> \\<open>OOM\\<close>\n                            FI\n                      FI\n                 ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>no_space_for_word\\<rbrace>\n                      \\<langle>\\<acute>oom := True\\<rangle>\n                      \\<comment> \\<open>OOM\\<close>\n                 FI\n           FI\n     FI;;\n     \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection  \n        \\<and> ((\\<acute>oom=False \\<and> [H =\\<^sub>2 (\\<acute>hW+(\\<acute>Data \\<acute>countW))]\\<acute>\\<sigma> ) \\<comment> \\<open>\\<and> \\<acute>hW  + \\<acute>Data (\\<acute>countW) \\<le> N\\<close> \n             \\<or> (\\<acute>oom=True \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>no_space_for_word)) \\<and> \\<acute>countW < n\\<rbrace>\n     IF \\<acute>oom=True\n     THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>no_space_for_word \\<and> \\<acute>countW < n\\<rbrace> \\<comment> \\<open>OK\\<close>\n          SKIP\n     ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection  \\<and> \\<acute>countW < n \\<and> [H =\\<^sub>2 (\\<acute>hW+(\\<acute>Data \\<acute>countW))]\\<acute>\\<sigma>\\<rbrace>\n          \\<langle>\\<acute>q := \\<acute>q @ [(\\<acute>hW, (\\<acute>Data \\<acute>countW))],,  \n           \\<acute>ownD := (\\<lambda> x. if x = \\<acute>countW then B else \\<acute>ownD x),, \n           \\<acute>ownB := (\\<lambda> x. if (\\<acute>ownB x = W) then Q else \\<acute>ownB x),,  \n           \\<acute>countW := (\\<acute>countW+1)\\<rangle> \n     FI\n   OD \n    \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>countW = n\\<rbrace>\n\n\\<parallel>\n \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>tempR = (0, 0)  \\<rbrace>\n  WHILE \\<acute>countR < n\n  INV \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>tempR=(0,0)  \\<rbrace>\n  DO  \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>countR < n \\<and> \\<acute>tempR=(0,0)  \\<rbrace>\n      IF \\<acute>countR < \\<acute>countW THEN\n                \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>countR < \\<acute>countW \\<and> \\<acute>tempR=(0,0)  \\<rbrace> \\<comment> \\<open>retrieve from Q, dequeue\\<close>\n\n                \\<langle> \\<acute>tempR  := (fst(hd \\<acute>q),(snd(hd \\<acute>q))) ,,\n                    \\<acute>ownD := (\\<lambda> x. if x = \\<acute>countR then R else \\<acute>ownD x),, \n                    \\<acute>countR := \\<acute>countR+1,, \n                    ( IF fst(hd \\<acute>q)\\<noteq>0 THEN (\\<acute>ownB := ( \\<lambda> x. if fst(hd \\<acute>q)  \\<le> x \\<and> x < (fst(hd \\<acute>q)+(snd(hd \\<acute>q))) then R else \\<acute>ownB x ))\n                      ELSE (\\<acute>ownB := ( \\<lambda> x. if (0 \\<le> x \\<and> x < (fst(hd \\<acute>q)+(snd(hd \\<acute>q)))) \\<or> (\\<forall>i.((x+i<N \\<and> i\\<ge>0)\\<longrightarrow>\\<acute>ownB (x+i) =Q)) then R else \\<acute>ownB x )) FI),, \n                     \\<acute>q := (tl \\<acute>q) \\<rangle>;;\n\n                    \\<lbrace> global \\<acute>\\<sigma> \\<and>\\<acute>collection \\<and> \\<acute>countR \\<le> \\<acute>countW  \\<and> \\<acute>tempR\\<noteq>(0,0)\\<rbrace> \\<comment> \\<open>Push T\\<close>\n\n                    \\<langle><T :=\\<^sub>3 (fst \\<acute>tempR + snd \\<acute>tempR) \\<acute>\\<sigma> >\n                    ,, \\<acute> tempR := (0,0),, \n                   \\<acute>ownB := (\\<lambda> x. if \\<acute>ownB x = R then B else \\<acute>ownD x) \\<rangle> \\<comment> \\<open>Broken\\<close>\n      ELSE\n      \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>tempR=(0,0) \\<and> \\<acute>countR < n \\<rbrace>\n      SKIP\n      FI\n  OD\n\\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>countR = n\\<rbrace>\n\n\n\nCOEND\n  \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>countW = n \\<and> \\<acute>countR = n\\<rbrace>\n  \n\n\"\n  apply (oghoare)\n  apply ((simp add: main_invariant_lemmas Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff; force)+)[4]\n  apply ((simp add: guards main_invariant_lemmas Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)[1]\n  apply (clarify)\n  apply (intro conjI impI)\n  apply (metis OpSem_ProofRules.d_obs_read_value d_obs_implies_p_obs le_less_linear)\n  apply (metis OpSem_ProofRules.d_obs_read_value OpSem_ProofRules.ext_d_obs_rd_pres)\n  apply auto[1]\n  apply ((simp add: guards main_invariant_lemmas Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)[1]\n  apply clarsimp\n  apply (meson not_less not_pobs_contradiction)\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  using pval_val apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply auto[3]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply auto[3]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply auto[1]\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply auto[1]\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis (no_types, lifting) Suc_diff_le d_obs_implies_p_obs fst_eqD le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply clarsimp\n  apply (simp_all add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)\n          (*129*)\n                      apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis (full_types) diff_is_0_eq hd_conv_nth length_0_conv length_greater_0_conv not_less)\n  apply linarith\n  apply auto[1]\n  apply (simp add: nth_tl)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth length_0_conv not_less0 zero_less_diff)\n  apply linarith\n  apply (metis (full_types) hd_conv_nth length_0_conv not_less0 snd_conv zero_less_diff)\n  using main_invariant_lemmas(12) apply auto[1]\n  using OpSem_ProofRules.ext_d_obs_d_obs apply blast\n  apply clarify\n  apply linarith\n  using OpSem_ProofRules.p_obs_contradiction apply blast\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply clarify\n  apply (intro conjI impI)\n  apply (metis One_nat_def Suc_eq_plus1 length_tl less_diff_conv nth_tl)\n  apply (metis One_nat_def Suc_eq_plus1 length_tl less_diff_conv nth_tl)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply clarify\n  apply (intro conjI impI)\n  apply (metis getVWNC_var leD pval_val)\n  apply (metis OpSem_ProofRules.ext_write_other_pres_d_obs)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (metis getVWNC_var leD pval_val)\n  apply (metis OpSem_ProofRules.ext_write_other_pres_d_obs)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply clarify                   \n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis getVWNC_var le_less_trans main_invariant_lemmas(12) nat_neq_iff)\n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply clarify\n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis getVWNC_var leD pval_val)    \n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (simp add: nth_tl)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth length_greater_0_conv zero_less_diff)\n  apply linarith\n  apply blast\n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply blast\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (simp add: nth_tl)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth length_greater_0_conv zero_less_diff)\n  apply linarith\n  apply blast\n  apply (metis getVWNC_var leD pval_val)\n  apply blast\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (simp add: nth_tl)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff) \n  apply linarith\n  apply blast\n  apply clarify\n  apply (metis getVWNC_var leD pval_val)\n  apply blast\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (simp add: nth_tl)    \n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)                \n  apply linarith\n  apply blast\n  apply clarify\n  apply (metis getVWNC_var leD pval_val)     \n  apply blast\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (simp add: nth_tl)    \n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)                \n  apply linarith\n  apply blast\n  apply clarify\n  apply (intro conjI impI)\n  apply (metis getVWNC_var leD pval_val)\n  apply (metis OpSem_ProofRules.ext_write_other_pres_d_obs)\n  apply clarify\n  apply (intro conjI impI)\n  apply blast\n  apply blast\n  apply blast\n  apply blast\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (simp add: nth_tl)    \n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)                \n  apply linarith\n  apply blast\n  apply clarify\n  apply (metis getVWNC_var leD pval_val)     \n  apply blast\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis (full_types) fst_conv not_less0 pval_val)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis (full_types) fst_conv not_less0 pval_val)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis (full_types) fst_conv not_less0 pval_val)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis (full_types) fst_conv not_less0 pval_val)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis (full_types) fst_conv not_less0 pval_val)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis (full_types) fst_conv not_less0 pval_val)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  by simp\n  \n\n\n\n\n\n(*(simp add: Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff )?)*)", "meta": {"author": "MSemenyuk", "repo": "PhD_Isabelle", "sha": "179f5d346a721b15940a271323e3487f4ea51338", "save_path": "github-repos/isabelle/MSemenyuk-PhD_Isabelle", "path": "github-repos/isabelle/MSemenyuk-PhD_Isabelle/PhD_Isabelle-179f5d346a721b15940a271323e3487f4ea51338/Amazon Ring Buffer/RB_Relaxed.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6334102636778401, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.28710070666653087}}
{"text": "(*\n * Copyright 2017, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory ArchArraysMemInstance\nimports \"../ArraysMemInstance\"\nbegin\n\n(* Showing arrays are in mem_type requires maximum sizes for objects,\n   and maximum counts for elements *)\nclass array_outer_max_size = mem_type +\n  assumes array_outer_max_size_ax: \"size_of TYPE('a::c_type) < 2 ^ 26\"\n\nclass array_max_count = finite +\n  assumes array_max_count_ax: \"CARD ('a) <= 2 ^ 20\"\n\ninstance array :: (array_outer_max_size, array_max_count) mem_type\napply intro_classes\napply simp\napply (subgoal_tac \"addr_card = 2 ^ (addr_bitsize - 26) * 2 ^ 26\")\n  apply (erule ssubst)\n  apply (rule less_le_trans[where y = \"card (UNIV::'b set) * 2 ^ 26\"])\n    apply (rule mult_less_mono2)\n      apply (rule array_outer_max_size_ax)\n    apply simp\n  apply (rule mult_le_mono1)\n    apply (rule le_trans[where j = \"2 ^ 20\"])\n      apply (rule array_max_count_ax)\n    apply simp\n  apply simp\napply (simp add: addr_card)\ndone\n\nclass array_inner_max_size = array_outer_max_size +\n  assumes array_inner_max_size_ax: \"size_of TYPE('a::c_type) < 2 ^ 6\"\n\ninstance array :: (array_inner_max_size, array_max_count) array_outer_max_size\napply intro_classes\napply simp\n  apply (rule order_less_le_trans)\n   apply (rule mult_le_less_imp_less)\n    apply (rule array_max_count_ax)\n   apply (rule array_inner_max_size_ax)\n  apply simp\n   apply simp\n  apply simp\n  done\n\ninstance word :: (len8) array_outer_max_size\napply intro_classes\napply(simp add: size_of_def)\napply(subgoal_tac \"len_of TYPE('a) \\<le> 128\")\n apply simp\napply(rule len8_width)\ndone\n\ninstance word :: (len8) array_inner_max_size\napply intro_classes\napply(simp add: size_of_def)\napply(subgoal_tac \"len_of TYPE('a) \\<le> 128\")\n apply simp\napply(rule len8_width)\ndone\n\ninstance ptr :: (c_type) array_outer_max_size\napply intro_classes\napply (simp add: size_of_def)\ndone\n\ninstance ptr :: (c_type) array_inner_max_size\napply intro_classes\napply (simp add: size_of_def)\ndone\n\nclass lt19 = finite +\n  assumes lt19_ax: \"CARD ('a) < 2 ^ 19\"\nclass lt18 = lt19 +\n  assumes lt18_ax: \"CARD ('a) < 2 ^ 18\"\nclass lt17 = lt18 +\n  assumes lt17_ax: \"CARD ('a) < 2 ^ 17\"\nclass lt16 = lt17 +\n  assumes lt16_ax: \"CARD ('a) < 2 ^ 16\"\nclass lt15 = lt16 +\n  assumes lt15_ax: \"CARD ('a) < 2 ^ 15\"\nclass lt14 = lt15 +\n  assumes lt14_ax: \"CARD ('a) < 2 ^ 14\"\nclass lt13 = lt14 +\n  assumes lt13_ax: \"CARD ('a) < 2 ^ 13\"\nclass lt12 = lt13 +\n  assumes lt12_ax: \"CARD ('a) < 2 ^ 12\"\nclass lt11 = lt12 +\n  assumes lt11_ax: \"CARD ('a) < 2 ^ 11\"\nclass lt10 = lt11 +\n  assumes lt10_ax: \"CARD ('a) < 2 ^ 10\"\nclass lt9 = lt10 +\n  assumes lt9_ax: \"CARD ('a) < 2 ^ 9\"\nclass lt8 = lt9 +\n  assumes lt8_ax: \"CARD ('a) < 2 ^ 8\"\nclass lt7 = lt8 +\n  assumes lt7_ax: \"CARD ('a) < 2 ^ 7\"\nclass lt6 = lt7 +\n  assumes lt6_ax: \"CARD ('a) < 2 ^ 6\"\nclass lt5 = lt6 +\n  assumes lt5_ax: \"CARD ('a) < 2 ^ 5\"\nclass lt4 = lt5 +\n  assumes lt4_ax: \"CARD ('a) < 2 ^ 4\"\nclass lt3 = lt4 +\n  assumes lt3_ax: \"CARD ('a) < 2 ^ 3\"\nclass lt2 = lt3 +\n  assumes lt2_ax: \"CARD ('a) < 2 ^ 2\"\nclass lt1 = lt2 +\n  assumes lt1_ax: \"CARD ('a) < 2 ^ 1\"\n\ninstance bit0 :: (lt19) array_max_count\n  using lt19_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt19) array_max_count\n  using lt19_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt18) lt19\n  using lt18_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt18) lt19\n  using lt18_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt17) lt18\n  using lt17_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt17) lt18\n  using lt17_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt16) lt17\n  using lt16_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt16) lt17\n  using lt16_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt15) lt16\n  using lt15_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt15) lt16\n  using lt15_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt14) lt15\n  using lt14_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt14) lt15\n  using lt14_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt13) lt14\n  using lt13_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt13) lt14\n  using lt13_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt12) lt13\n  using lt12_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt12) lt13\n  using lt12_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt11) lt12\n  using lt11_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt11) lt12\n  using lt11_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt10) lt11\n  using lt10_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt10) lt11\n  using lt10_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt9) lt10\n  using lt9_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt9) lt10\n  using lt9_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt8) lt9\n  using lt8_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt8) lt9\n  using lt8_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt7) lt8\n  using lt7_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt7) lt8\n  using lt7_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt6) lt7\n  using lt6_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt6) lt7\n  using lt6_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt5) lt6\n  using lt5_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt5) lt6\n  using lt5_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt4) lt5\n  using lt4_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt4) lt5\n  using lt4_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt3) lt4\n  using lt3_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt3) lt4\n  using lt3_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt2) lt3\n  using lt2_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt2) lt3\n  using lt2_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt1) lt2\n  using lt1_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt1) lt2\n  using lt1_ax[where 'a='a] by intro_classes simp\n\ninstance num1 :: lt1\n  by (intro_classes, simp_all)\n\n(* don't understand why this also seems to be necessary *)\ninstance num1 :: array_max_count\n  by (intro_classes, simp)\n\n(* introduce hackish handling of 8192 type by making a copy of the type\n   under a constructor, and then manually showing that it is an instance of\n   array_max_count *)\ndatatype array_max_count_ty = array_max_count_ty \"1048576\"\n\n(* ML c-parser code also needs to know at which array size to use this type *)\nML \\<open>\n  structure ArchArrayMaxCount = struct\n    val array_max_count = 1048576\n  end\n\\<close>\n\nlemma univ_array_max_count_ty:\n  \"(UNIV::array_max_count_ty set) = image array_max_count_ty (UNIV::1048576 set)\"\n  apply (simp add: set_eq_iff image_iff)\n  apply (rule_tac allI)\n  apply (rule_tac array_max_count_ty.induct)\n  apply simp\n  done\n\ninstance \"array_max_count_ty\" :: finite\n  apply intro_classes\n  apply (simp add: univ_array_max_count_ty)\n  done\n\nlemma card_array_max_count_ty[simp]: \"CARD(array_max_count_ty) = CARD(1048576)\"\n  apply (simp add: univ_array_max_count_ty card_image inj_on_def)\n  done\n\ninstance \"array_max_count_ty\" :: array_max_count\n  by intro_classes simp\n\nend\n", "meta": {"author": "CompSoftVer", "repo": "CSim2", "sha": "b09a4d77ea089168b1805db5204ac151df2b9eff", "save_path": "github-repos/isabelle/CompSoftVer-CSim2", "path": "github-repos/isabelle/CompSoftVer-CSim2/CSim2-b09a4d77ea089168b1805db5204ac151df2b9eff/CParser/tools/c-parser/umm_heap/X64/ArchArraysMemInstance.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6334102636778401, "lm_q2_score": 0.4532618480153861, "lm_q1q2_score": 0.2871007066665308}}
{"text": "(*  Title:      SSA_CFG.thy\n    Author:     Sebastian Ullrich, Denis Lohner\n*)\n\ntheory SSA_CFG\nimports Main Relation Graph_path \"~~/src/HOL/Library/Sublist\"\nbegin\n\nsubsection {* CFG *}\n\nlocale CFG_base = graph_Entry_base \\<alpha>n predecessors Entry\nfor\n  \\<alpha>n :: \"'node::linorder list\" and\n  predecessors :: \"'node \\<Rightarrow> 'node list\" and\n  Entry :: \"'node\" +\nfixes \"defs\" :: \"'node \\<Rightarrow> 'var::linorder set\"\nfixes \"uses\" :: \"'node \\<Rightarrow> 'var set\"\nbegin\n  definition \"vars \\<equiv> fold (op \\<union>) (map uses \\<alpha>n) {}\"\n  definition defAss' :: \"'node \\<Rightarrow> 'var \\<Rightarrow> bool\" where\n    \"defAss' m v \\<longleftrightarrow> (\\<forall>ns. Entry\\<comment>ns\\<rightarrow>m \\<longrightarrow> (\\<exists>n \\<in> set ns. v \\<in> defs n))\"\n  definition defAss'Uses :: bool where\n    \"defAss'Uses \\<equiv> \\<forall>m \\<in> set \\<alpha>n. \\<forall>v \\<in> uses m. defAss' m v\"\nend\n\nlocale CFG = CFG_base \\<alpha>n predecessors Entry \"defs\" \"uses\"\n+ graph_Entry \\<alpha>n predecessors Entry\nfor\n  \\<alpha>n :: \"'node::linorder list\" and\n  predecessors :: \"'node \\<Rightarrow> 'node list\" and\n  Entry :: \"'node\" and\n  \"defs\" :: \"'node \\<Rightarrow> 'var::linorder set\" and\n  \"uses\" :: \"'node \\<Rightarrow> 'var set\" +\nassumes defs_uses_disjoint: \"n \\<in> set \\<alpha>n \\<Longrightarrow> defs n \\<inter> uses n = {}\"\nassumes defs_finite[simp]: \"finite (defs n)\"\nassumes uses_in_\\<alpha>n: \"v \\<in> uses n \\<Longrightarrow> n \\<in> set \\<alpha>n\"\nassumes uses_finite[simp, intro!]: \"finite (uses n)\"\nbegin\n  lemma vars_finite[simp]: \"finite (vars)\"\n  by (auto simp:vars_def)\n\n  lemma uses_in_vars[elim, simp]: \"v \\<in> uses n \\<Longrightarrow>  v \\<in> vars\"\n  by (auto simp add:vars_def uses_in_\\<alpha>n intro!: fold_union_elemI)\n\n  lemma varsE:\n    assumes \"v \\<in> vars\"\n    obtains n where \"n \\<in> set \\<alpha>n\" \"v \\<in> uses n\"\n  using assms by (auto simp:vars_def elim!:fold_union_elem)\n\n  lemma defs_uses_disjoint'[simp]: \"n \\<in> set \\<alpha>n \\<Longrightarrow> v \\<in> defs n \\<Longrightarrow> v \\<in> uses n \\<Longrightarrow> False\"\n  using defs_uses_disjoint by auto\nend\n\ncontext CFG\nbegin\n  lemma defAss'E:\n    assumes \"defAss' m v\" \"Entry\\<comment>ns\\<rightarrow>m\"\n    obtains n where \"n \\<in> set ns\" \"v \\<in> defs n\"\n  using assms unfolding defAss'_def by auto\n\n  lemmas defAss'I = defAss'_def[THEN iffD2, rule_format]\n\n  lemma defAss'_extend:\n    assumes \"defAss' m v\"\n    assumes \"n\\<comment>ns\\<rightarrow>m\" \"\\<forall>n \\<in> set (tl ns). v \\<notin> defs n\"\n    shows \"defAss' n v\"\n  unfolding defAss'_def proof (rule allI, rule impI)\n    fix ns'\n    assume \"Entry\\<comment>ns'\\<rightarrow>n\"\n    with assms(2) have \"Entry\\<comment>ns'@tl ns\\<rightarrow>m\" by auto\n    with assms(1) obtain n' where n': \"n' \\<in> set (ns'@tl ns)\" \"v \\<in> defs n'\" by -(erule defAss'E)\n    with assms(3) have \"n' \\<notin> set (tl ns)\" by auto\n    with n' show \"\\<exists>n \\<in> set ns'. v \\<in> defs n\" by auto\n  qed\nend\n\ntext {* A CFG is well-formed if it satisfies definite assignment. *}\n\nlocale CFG_wf = CFG \\<alpha>n predecessors Entry \"defs\" \"uses\"\nfor\n  \\<alpha>n :: \"'node::linorder list\" and\n  predecessors :: \"'node \\<Rightarrow> 'node list\" and\n  Entry::\"'node\" and\n  \"defs\" :: \"'node \\<Rightarrow> 'var::linorder set\" and\n  \"uses\" :: \"'node \\<Rightarrow> 'var set\" +\nassumes def_ass_uses: \"\\<forall>m \\<in> set \\<alpha>n. \\<forall>v \\<in> uses m. defAss' m v\"\n\nsubsection {* SSA CFG *}\n\ntype_synonym ('node, 'val) phis = \"'node \\<times> 'val \\<rightharpoonup> 'val list\"\n\ndeclare in_set_zipE[elim]\ndeclare zip_same[simp]\n\nlocale CFG_SSA_base = CFG_base \\<alpha>n predecessors Entry \"defs\" \"uses\"\nfor\n  \\<alpha>n :: \"'node::linorder list\" and\n  predecessors :: \"'node \\<Rightarrow> 'node list\" and\n  Entry::\"'node\" and\n  \"defs\" :: \"'node \\<Rightarrow> 'val::linorder set\" and\n  \"uses\" :: \"'node \\<Rightarrow> 'val set\" +\nfixes phis :: \" ('node, 'val) phis\"\nbegin\n  definition \"phiDefs n \\<equiv> {v. (n,v) \\<in> dom phis}\"\n  definition[code]: \"allDefs n \\<equiv> defs n \\<union> phiDefs n\"\n\n  definition[code]: \"phiUses n \\<equiv>\n    \\<Union>n' \\<in> set (successors n). \\<Union>v' \\<in> phiDefs n'. snd ` Set.filter (\\<lambda>(n'',v). n'' = n) (set (zip (predecessors n') (the (phis (n',v')))))\"\n  definition[code]: \"allUses n \\<equiv> uses n \\<union> phiUses n\"\n  definition[code]: \"allVars \\<equiv> \\<Union>n \\<in> set \\<alpha>n. allDefs n \\<union> allUses n\"\n\n  definition defAss :: \"'node \\<Rightarrow> 'val \\<Rightarrow> bool\" where\n    \"defAss m v \\<longleftrightarrow> (\\<forall>ns. Entry\\<comment>ns\\<rightarrow>m \\<longrightarrow> (\\<exists>n \\<in> set ns. v \\<in> allDefs n))\"\n\n  lemmas CFG_SSA_defs = phiDefs_def allDefs_def phiUses_def allUses_def allVars_def defAss_def\nend\n\nlocale CFG_SSA = CFG \\<alpha>n predecessors Entry \"defs\" \"uses\" + CFG_SSA_base \\<alpha>n predecessors Entry \"defs\" \"uses\" phis\nfor\n  \\<alpha>n :: \"'node::linorder list\" and\n  predecessors :: \"'node \\<Rightarrow> 'node list\" and\n  Entry::\"'node\" and\n  \"defs\" :: \"'node \\<Rightarrow> 'val::linorder set\" and\n  \"uses\" :: \"'node \\<Rightarrow> 'val set\" and\n   phis :: \" ('node, 'val) phis\" +\nassumes phis_finite: \"finite (dom phis)\"\nassumes phis_in_\\<alpha>n: \"phis (n,v) = Some vs \\<Longrightarrow> n \\<in> set \\<alpha>n\"\nassumes phis_wf:\n  \"phis (n,v) = Some args \\<Longrightarrow> length (predecessors n) = length args\"\nassumes simpleDefs_phiDefs_disjoint:\n  \"n \\<in> set \\<alpha>n \\<Longrightarrow> defs n \\<inter> phiDefs n = {}\"\nassumes allDefs_disjoint:\n  \"\\<lbrakk>n \\<in> set \\<alpha>n; m \\<in> set \\<alpha>n; n \\<noteq> m\\<rbrakk> \\<Longrightarrow> allDefs n \\<inter> allDefs m = {}\"\nbegin\n  lemma phis_disj:\n    assumes \"phis (n,v) = Some vs\"\n    and \"phis (n',v) = Some vs'\"\n    shows \"n = n'\" and \"vs = vs'\"\n  proof -\n    from assms have \"n \\<in> set \\<alpha>n\" and \"n' \\<in> set \\<alpha>n\"\n      by (auto dest: phis_in_\\<alpha>n)\n    from allDefs_disjoint [OF this] assms show \"n = n'\"\n      by (auto simp: allDefs_def phiDefs_def)\n    with assms show \"vs = vs'\" by simp\n  qed\n\n  lemma allDefs_disjoint': \"\\<lbrakk>n \\<in> set \\<alpha>n; m \\<in> set \\<alpha>n; v \\<in> allDefs n; v \\<in> allDefs m\\<rbrakk> \\<Longrightarrow> n = m\"\n  using allDefs_disjoint by auto\n\n  lemma phiUsesI:\n    assumes \"n' \\<in> set \\<alpha>n\" \"phis (n',v') = Some vs\" \"(n,v) \\<in> set (zip (predecessors n') vs)\"\n    shows \"v \\<in> phiUses n\"\n  proof-\n    from assms(3) have \"n \\<in> set (predecessors n')\" by auto\n    hence 1: \"n' \\<in> set (successors n)\" using assms(1) by simp\n    from assms(2) have 2: \"v' \\<in> phiDefs n'\" by (auto simp add:phiDefs_def)\n    from assms(2) have 3: \"the (phis (n',v')) = vs\" by simp\n    show ?thesis unfolding phiUses_def by (rule UN_I[OF 1], rule UN_I[OF 2], auto simp:image_def Set.filter_def assms(3) 3)\n  qed\n\n  lemma phiUsesE:\n    assumes \"v \\<in> phiUses n\"\n    obtains  n' v' vs where \"n' \\<in> set (successors n)\" \"(n,v) \\<in> set (zip (predecessors n') vs)\" \"phis (n', v') = Some vs\"\n  proof-\n    from assms(1) obtain n' v' where \"n'\\<in>set (successors n)\" \"v'\\<in>phiDefs n'\"\n      \"v \\<in> snd ` Set.filter (\\<lambda>(n'', v). n'' = n) (set (zip (predecessors n') (the (phis (n', v')))))\" by (auto simp:phiUses_def)\n    thus ?thesis by - (rule that[of n' \"the (phis (n',v'))\" v'], auto simp:phiDefs_def)\n  qed\n\n  lemma defs_in_allDefs[intro]: \"v \\<in> defs n \\<Longrightarrow> v \\<in> allDefs n\" by (simp add:allDefs_def)\n  lemma phiDefs_in_allDefs[intro]: \"v \\<in> phiDefs n \\<Longrightarrow> v \\<in> allDefs n\" by (simp add:allDefs_def)\n  lemma uses_in_allUses[intro]: \"v \\<in> uses n \\<Longrightarrow> v \\<in> allUses n\" by (simp add:allUses_def)\n  lemma phiUses_in_allUses[simp]: \"v \\<in> phiUses n \\<Longrightarrow> v \\<in> allUses n\" by (simp add:allUses_def)\n  lemma allDefs_in_allVars[intro]: \"\\<lbrakk>v \\<in> allDefs n; n \\<in> set \\<alpha>n\\<rbrakk> \\<Longrightarrow> v \\<in> allVars\" by (auto simp:allVars_def)\n  lemma allUses_in_allVars[intro]: \"\\<lbrakk>v \\<in> allUses n; n \\<in> set \\<alpha>n\\<rbrakk> \\<Longrightarrow> v \\<in> allVars\" by (auto simp:allVars_def)\n\n  lemma phiDefs_finite[simp]: \"finite (phiDefs n)\"\n  unfolding phiDefs_def\n  proof (rule finite_surj[where f=snd], rule phis_finite)\n    have \"\\<And>x y. phis (n,x) = Some y \\<Longrightarrow> x \\<in> snd ` dom phis\" by (metis domI imageI snd_conv)\n    thus \"{v. (n, v) \\<in> dom phis} \\<subseteq> snd ` dom phis\" by auto\n  qed\n\n  lemma phiUses_finite[simp]:\n    assumes \"n \\<in> set \\<alpha>n\"\n    shows \"finite (phiUses n)\"\n  by (auto simp:phiUses_def Set.filter_def)\n\n  lemma allDefs_finite[intro!]: \"n \\<in> set \\<alpha>n \\<Longrightarrow> finite (allDefs n)\" by (auto simp add:allDefs_def)\n  lemma allUses_finite[intro!]: \"n \\<in> set \\<alpha>n \\<Longrightarrow> finite (allUses n)\" by (auto simp add:allUses_def)\n  lemma allVars_finite[simp]: \"finite (allVars)\" by (auto simp add:allVars_def)\n\n  lemmas defAssI = defAss_def[THEN iffD2, rule_format]\n  lemmas defAssD = defAss_def[THEN iffD1, rule_format]\n\n  lemma defAss_extend:\n    assumes \"defAss m v\"\n    assumes \"n\\<comment>ns\\<rightarrow>m\" \"\\<forall>n \\<in> set (tl ns). v \\<notin> allDefs n\"\n    shows \"defAss n v\"\n  unfolding defAss_def proof (rule allI, rule impI)\n    fix ns'\n    assume \"Entry\\<comment>ns'\\<rightarrow>n\"\n    with assms(2) have \"Entry\\<comment>ns'@tl ns\\<rightarrow>m\" by auto\n    with assms(1) obtain n' where n': \"n' \\<in> set (ns'@tl ns)\" \"v \\<in> allDefs n'\" by (auto dest:defAssD)\n    with assms(3) have \"n' \\<notin> set (tl ns)\" by auto\n    with n' show \"\\<exists>n \\<in> set ns'. v \\<in> allDefs n\" by auto\n  qed\n\n  lemma defAss_dominating:\n    assumes[simp]: \"n \\<in> set \\<alpha>n\"\n    shows \"defAss n v \\<longleftrightarrow> (\\<exists>m \\<in> set \\<alpha>n. dominates m n \\<and> v \\<in> allDefs m)\"\n  proof\n    assume asm: \"defAss n v\"\n    obtain ns where ns: \"Entry\\<comment>ns\\<rightarrow>n\" by (atomize, auto)\n    from defAssD[OF asm this] obtain m where m: \"m \\<in> set ns\" \"v \\<in> allDefs m\" by auto\n    have \"dominates m n\"\n    proof (rule dominatesI)\n      fix ns'\n      assume ns': \"Entry\\<comment>ns'\\<rightarrow>n\"\n      from defAssD[OF asm this] obtain m' where m': \"m' \\<in> set ns'\" \"v \\<in> allDefs m'\" by auto\n      with m ns ns' have \"m' = m\" by - (rule allDefs_disjoint', auto)\n      with m' show \"m \\<in> set ns'\" by simp\n    qed simp\n    with m ns show \"\\<exists>m\\<in>set \\<alpha>n. dominates m n \\<and> v \\<in> allDefs m\" by auto\n  next\n    assume \"\\<exists>m \\<in> set \\<alpha>n. dominates m n \\<and> v \\<in> allDefs m\"\n    then obtain m where[simp]: \"m \\<in> set \\<alpha>n\" and m: \"dominates m n\" \"v \\<in> allDefs m\" by auto\n    show \"defAss n v\"\n    proof (rule defAssI)\n      fix ns\n      assume \"Entry\\<comment>ns\\<rightarrow>n\"\n      with m(1) have \"m \\<in> set ns\" by - (rule dominates_mid, auto)\n      with m(2) show \"\\<exists>n\\<in>set ns. v \\<in> allDefs n\" by auto\n    qed\n  qed\nend\n\nlocale CFG_SSA_wf_base = CFG_SSA_base \\<alpha>n predecessors Entry \"defs\" \"uses\" phis\nfor\n  \\<alpha>n :: \"'node::linorder list\" and\n  predecessors :: \"'node \\<Rightarrow> 'node list\" and\n  Entry::\"'node\" and\n  \"defs\" :: \"'node \\<Rightarrow> 'val::linorder set\" and\n  \"uses\" :: \"'node \\<Rightarrow> 'val set\" and\n  phis :: \" ('node, 'val) phis\"\nbegin\n  text {* Using the SSA properties, we can map every value to its unique defining node and\n    remove the @{typ 'node} parameter of the @{term phis} map. *}\n\n  definition defNode :: \"'val \\<Rightarrow> 'node\" where\n    defNode_code [code]: \"defNode v \\<equiv> hd [n \\<leftarrow> \\<alpha>n. v \\<in> allDefs n]\"\n\n  abbreviation \"def_dominates v' v \\<equiv> dominates (defNode v') (defNode v)\"\n  abbreviation \"strict_def_dom v' v \\<equiv> defNode v' \\<noteq> defNode v \\<and> def_dominates v' v\"\n\n  definition \"phi v = phis (defNode v,v)\"\n  definition[simp]: \"phiArg v v' \\<equiv> \\<exists>vs. phi v = Some vs \\<and> v' \\<in> set vs\"\n\n  definition[code]: \"isTrivialPhi v v' \\<longleftrightarrow> v' \\<noteq> v \\<and>\n    (case phi v of\n      Some vs \\<Rightarrow> set vs = {v,v'} \\<or> set vs = {v'}\n    | None \\<Rightarrow> False)\"\n  definition[code]: \"trivial v \\<equiv> \\<exists>v' \\<in> allVars. isTrivialPhi v v'\"\n  definition[code]: \"redundant \\<equiv> \\<exists>v \\<in> allVars. trivial v\"\n\n  definition \"defAssUses \\<equiv> \\<forall>n \\<in> set \\<alpha>n. \\<forall>v \\<in> allUses n. defAss n v\"\n\n  declare [[inductive_internals]]\n  inductive liveVal :: \"'val \\<Rightarrow> bool\"\n  where\n    liveSimple: \"\\<lbrakk>n \\<in> set \\<alpha>n; val \\<in> uses n\\<rbrakk> \\<Longrightarrow> liveVal val\"\n  | livePhi: \"\\<lbrakk>liveVal v; phiArg v v'\\<rbrakk> \\<Longrightarrow> liveVal v'\"\n\n  definition \"pruned = (\\<forall>n \\<in> set \\<alpha>n. \\<forall>val. val \\<in> phiDefs n \\<longrightarrow> liveVal val)\"\n\n  lemmas \"CFG_SSA_wf_defs\" = CFG_SSA_defs defNode_code phi_def isTrivialPhi_def trivial_def redundant_def liveVal_def pruned_def\nend\n\nlocale CFG_SSA_wf = CFG_SSA \\<alpha>n predecessors Entry \"defs\" \"uses\" phis\n  + CFG_SSA_wf_base \\<alpha>n predecessors Entry \"defs\" \"uses\" phis\nfor\n  \\<alpha>n :: \"'node::linorder list\" and\n  predecessors :: \"'node \\<Rightarrow> 'node list\" and\n  Entry::\"'node\" and\n  \"defs\" :: \"'node \\<Rightarrow> 'val::linorder set\" and\n  \"uses\" :: \"'node \\<Rightarrow> 'val set\" and\n  phis :: \" ('node, 'val) phis\" +\n  assumes allUses_def_ass: \"\\<lbrakk>v \\<in> allUses n; n \\<in> set \\<alpha>n\\<rbrakk> \\<Longrightarrow> defAss n v\"\n  assumes Entry_no_phis[simp]: \"phis (Entry,v) = None\"\nbegin\n  lemma allVars_in_allDefs: \"v \\<in> allVars \\<Longrightarrow> \\<exists>n \\<in> set \\<alpha>n. v \\<in> allDefs n\"\n    unfolding allVars_def\n  apply auto\n  apply (drule(1) allUses_def_ass)\n  apply (clarsimp simp: defAss_def)\n  apply (drule Entry_reaches)\n   apply auto[1]\n  by fastforce\n\n  lemma phiDefs_Entry_empty[simp]: \"phiDefs (Entry) = {}\"\n  by (auto simp: phiDefs_def)\n\n  lemma phi_Entry_empty[simp]: \"defNode v = Entry \\<Longrightarrow> phi v = None\"\n    by (simp add:phi_def)\n\n  lemma defNode_ex1:\n    assumes \"v \\<in> allVars\"\n    shows \"\\<exists>!n. n \\<in> set \\<alpha>n \\<and> v \\<in> allDefs n\"\n  proof (rule ex_ex1I)\n    show \"\\<exists>n. n \\<in> set \\<alpha>n \\<and> v \\<in> allDefs n\"\n    proof-\n      from assms(1) obtain n where n: \"n \\<in> set \\<alpha>n\" \"v \\<in> allDefs n \\<or> v \\<in> allUses n\" by (auto simp:allVars_def)\n      thus ?thesis\n      proof (cases \"v \\<in> allUses n\")\n        case True\n        from n(1) obtain ns where ns: \"Entry\\<comment>ns\\<rightarrow>n\" by (atomize_elim, rule Entry_reaches)\n        with allUses_def_ass[OF True n(1)] obtain m where m: \"m \\<in> set ns\" \"v \\<in> allDefs m\" by - (drule defAssD, auto)\n        from ns this(1) have \"m \\<in> set \\<alpha>n\" by (rule path2_in_\\<alpha>n)\n        with n(1) m show ?thesis by auto\n      qed auto\n    qed\n    show \"\\<And>n m. n \\<in> set \\<alpha>n \\<and> v \\<in> allDefs n \\<Longrightarrow> m \\<in> set \\<alpha>n \\<and> v \\<in> allDefs m \\<Longrightarrow> n = m\" using allDefs_disjoint by auto\n  qed\n\n  lemma defNode_def: \"v \\<in> allVars \\<Longrightarrow> defNode v = (THE n. n \\<in> set \\<alpha>n \\<and> v \\<in> allDefs n)\"\n  unfolding defNode_code by (rule the1_list[symmetric], rule defNode_ex1)\n\n  lemma defNode[simp]:\n    assumes \"v \\<in> allVars\"\n    shows  \"(defNode v) \\<in> set \\<alpha>n\" \"v \\<in> allDefs (defNode v)\"\n  apply (atomize(full))\n  unfolding defNode_def[OF assms] using assms\n  by - (rule theI', rule defNode_ex1)\n\n  lemma defNode_eq[intro]:\n    assumes \"n \\<in> set \\<alpha>n\" \"v \\<in> allDefs n\"\n    shows \"defNode v = n\"\n  apply (subst defNode_def, rule allDefs_in_allVars[OF assms(2) assms(1)])\n  by (rule the1_equality, rule defNode_ex1, rule allDefs_in_allVars[where n=n], simp_all add:assms)\n\n  lemma defNode_cases[consumes 1]:\n    assumes \"v \\<in> allVars\"\n    obtains (simpleDef) \"v \\<in> defs (defNode v)\"\n          | (phi)       \"phi v \\<noteq> None\"\n  proof (cases \"v \\<in> defs (defNode v)\")\n    case True\n    thus thesis by (rule simpleDef)\n  next\n    case False\n    with assms[THEN defNode(2)] show thesis\n      by - (rule phi, auto simp: allDefs_def phiDefs_def phi_def)\n  qed\n\n  lemma phi_phiDefs[simp]: \"phi v = Some vs \\<Longrightarrow> v \\<in> phiDefs (defNode v)\" by (auto simp:phiDefs_def phi_def)\n\n  lemma simpleDef_not_phi:\n    assumes \"n \\<in> set \\<alpha>n\" \"v \\<in> defs n\"\n    shows \"phi v = None\"\n  proof-\n    from assms have \"defNode v = n\" by auto\n    with assms show ?thesis using simpleDefs_phiDefs_disjoint by (auto simp: phi_def phiDefs_def)\n  qed\n\n  lemma phi_wf: \"phi v = Some vs \\<Longrightarrow> length (predecessors (defNode v)) = length vs\"\n  by (rule phis_wf) (simp add:phi_def)\n\n  lemma phi_finite: \"finite (dom (phi))\"\n  proof-\n    let ?f = \"\\<lambda>v. (defNode v,v)\"\n    have \"phi = phis \\<circ> ?f\" by (auto simp add:phi_def)\n    moreover have \"inj ?f\" by (auto intro:injI)\n    hence \"finite (dom (phis \\<circ> ?f))\" by - (rule finite_dom_comp, auto simp add:phis_finite inj_on_def)\n    ultimately show ?thesis by simp\n  qed\n\n  lemma phiUses_exI:\n    assumes \"m \\<in> set (predecessors n)\" \"phis (n,v) = Some vs\" \"n \\<in> set \\<alpha>n\"\n    obtains v' where \"v' \\<in> phiUses m\" \"v' \\<in> set vs\"\n  proof-\n    from assms(1) obtain i where i: \"m = predecessors n ! i\" \"i < length (predecessors n)\" by (metis in_set_conv_nth)\n    with assms(2) phis_wf have[simp]: \"i < length vs\" by (auto simp add:phi_def)\n    from i assms(2,3) have \"vs ! i \\<in> phiUses m\" by - (rule phiUsesI, auto simp add:phiUses_def phi_def set_zip)\n    thus thesis by (rule that) (auto simp add:i(2) phis_wf)\n  qed\n\n  lemma phiArg_exI:\n    assumes \"m \\<in> set (predecessors (defNode v))\" \"phi v \\<noteq> None\" and[simp]: \"v \\<in> allVars\"\n    obtains v' where \"v' \\<in> phiUses m\" \"phiArg v v'\"\n  proof-\n    from assms(2) obtain vs where \"phi v = Some vs\" by auto\n    with assms(1) show thesis\n      by - (rule phiUses_exI, auto intro!:that simp: phi_def)\n  qed\n\n  lemma phiUses_exI':\n    assumes \"phiArg p q\" and[simp]: \"p \\<in> allVars\"\n    obtains m where \"q \\<in> phiUses m\" \"m \\<in> set (predecessors (defNode p))\"\n  proof-\n    let ?n = \"defNode p\"\n    from assms(1) obtain i vs where vs: \"phi p = Some vs\" and i: \"q = vs ! i\" \"i < length vs\" by (metis in_set_conv_nth phiArg_def)\n    with phis_wf have[simp]: \"i < length (predecessors ?n)\" by (auto simp add:phi_def)\n    from vs i have \"q \\<in> phiUses (predecessors ?n ! i)\" by - (rule phiUsesI, auto simp add:phiUses_def phi_def set_zip)\n    thus thesis by (rule that) (auto simp add:i(2) phis_wf)\n  qed\n\n  lemma phiArg_in_allVars[simp]:\n    assumes \"phiArg v v'\"\n    shows \"v' \\<in> allVars\"\n  proof-\n    let ?n = \"defNode v\"\n    from assms(1) obtain vs where vs: \"phi v = Some vs\" \"v' \\<in> set vs\" by auto\n    then obtain m where m: \"(m,v') \\<in> set (zip (predecessors ?n) vs)\" by - (rule set_zip_leftI, rule phi_wf)\n    from vs(1) have n: \"?n \\<in> set \\<alpha>n\" by (simp add: phi_def phis_in_\\<alpha>n)\n    with m have[simp]: \"m \\<in> set \\<alpha>n\" by auto\n    from n m vs have \"v' \\<in> phiUses m\" by - (rule phiUsesI, simp_all add:phi_def)\n    thus ?thesis by - (rule allUses_in_allVars, auto simp:allUses_def)\n  qed\n\n  lemma defAss_defNode:\n    assumes \"defAss m v\" \"v \\<in> allVars\" \"Entry\\<comment>ns\\<rightarrow>m\"\n    shows \"defNode v \\<in> set ns\"\n  proof-\n    from assms obtain n where n: \"n \\<in> set ns\" \"v \\<in> allDefs n\" by (auto simp:defAss_def)\n    with assms(3) have \"n = defNode v\" by - (rule defNode_eq[symmetric], auto)\n    with n show \"defNode v \\<in> set ns\" by (simp add:defAss_def)\n  qed\n\n  lemma defUse_path_ex:\n    assumes \"v \\<in> allUses m\" \"m \\<in> set \\<alpha>n\"\n    obtains ns where \"defNode v\\<comment>ns\\<rightarrow>m\" \"EntryPath ns\"\n  proof-\n    from assms have \"defAss m v\" by - (rule allUses_def_ass, auto)\n    moreover from assms obtain ns where ns: \"Entry\\<comment>ns\\<rightarrow>m\" \"EntryPath ns\"\n      by - (atomize_elim, rule Entry_reachesE, auto)\n    ultimately have \"defNode v \\<in> set ns\" using assms(1)\n      by - (rule defAss_defNode, auto)\n    with ns(1) obtain ns' where \"defNode v\\<comment>ns'\\<rightarrow>m\" \"suffixeq ns' ns\"\n      by (rule path2_split_ex', auto simp: suffixeq_def)\n    thus thesis using ns(2)\n      by - (rule that, assumption, rule EntryPath_suffixeq, auto)\n  qed\n\n  lemma defUse_path_dominated:\n    assumes \"defNode v\\<comment>ns\\<rightarrow>n\" \"defNode v \\<notin> set (tl ns)\" \"v \\<in> allUses n\" \"n' \\<in> set ns\"\n    shows \"dominates (defNode v) n'\"\n  proof (rule dominatesI)\n    fix es\n    assume asm: \"Entry\\<comment>es\\<rightarrow>n'\"\n    from assms(1,4) obtain ns' where ns': \"n'\\<comment>ns'\\<rightarrow>n\" \"suffixeq ns' ns\"\n      by - (rule path2_split_ex, auto simp: suffixeq_def)\n    from assms have \"defAss n v\" by - (rule allUses_def_ass, auto)\n    with asm ns'(1) assms(3) have \"defNode v \\<in> set (es@tl ns')\" by - (rule defAss_defNode, auto)\n    with suffixeq_tl_subset[OF ns'(2)] assms(2) show \"defNode v \\<in> set es\" by auto\n  next\n    show \"n' \\<in> set \\<alpha>n\" using assms(1,4) by auto\n  qed\n\n  lemma allUses_dominated:\n    assumes \"v \\<in> allUses n\" \"n \\<in> set \\<alpha>n\"\n    shows \"dominates (defNode v) n\"\n  proof-\n    from assms obtain ns where \"defNode v\\<comment>ns\\<rightarrow>n\" \"defNode v \\<notin> set (tl ns)\"\n      by - (rule defUse_path_ex, auto elim: simple_path2)\n    with assms(1) show ?thesis by - (rule defUse_path_dominated, auto)\n  qed\n\n  lemma phiArg_path_ex':\n    assumes \"phiArg p q\" and[simp]: \"p \\<in> allVars\"\n    obtains ns m where \"defNode q\\<comment>ns\\<rightarrow>m\" \"EntryPath ns\" \"q \\<in> phiUses m\" \"m \\<in> set (predecessors (defNode p))\"\n  proof-\n    from assms obtain m where m: \"q \\<in> phiUses m\" \"m \\<in> set (predecessors (defNode p))\"\n      by (rule phiUses_exI')\n    then obtain ns where \"defNode q\\<comment>ns\\<rightarrow>m\" \"EntryPath ns\" by - (rule defUse_path_ex[of q m], auto)\n    with m show thesis by - (rule that)\n  qed\n\n  lemma phiArg_path_ex:\n    assumes \"phiArg p q\" and[simp]: \"p \\<in> allVars\"\n    obtains ns where \"defNode q\\<comment>ns\\<rightarrow>defNode p\" \"length ns > 1\"\n    by (rule phiArg_path_ex'[OF assms], rule, auto)\n\n  lemma phiArg_tranclp_path_ex:\n    assumes \"r\\<^sup>+\\<^sup>+ p q\" \"p \\<in> allVars\" and[simp]: \"\\<And>p q. r p q \\<Longrightarrow> phiArg p q\"\n    obtains ns where \"defNode q\\<comment>ns\\<rightarrow>defNode p\" \"length ns > 1\"\n      \"\\<forall>n \\<in> set (butlast ns). \\<exists>p q m ns'. r p q \\<and> defNode q\\<comment>ns'\\<rightarrow>m \\<and> (defNode q) \\<notin> set (tl ns') \\<and> q \\<in> phiUses m \\<and> m \\<in> set (predecessors (defNode p)) \\<and> n \\<in> set ns' \\<and> set ns' \\<subseteq> set ns \\<and> defNode p \\<in> set ns\"\n  using assms(1,2) proof (induction rule: converse_tranclp_induct)\n    case (base p)\n    from base.hyps base.prems(2) obtain ns' m where ns': \"defNode q\\<comment>ns'\\<rightarrow>m\" \"defNode q \\<notin> set (tl ns')\" \"m \\<in> set (predecessors (defNode p))\" \"q \\<in> phiUses m\"\n      by - (rule phiArg_path_ex', rule assms(3), auto intro: simple_path2)\n    hence ns: \"defNode q\\<comment>ns'@[defNode p]\\<rightarrow>defNode p\" \"length (ns'@[defNode p]) > 1\" by auto\n\n    show ?case\n    proof (rule base.prems(1)[OF ns, rule_format], rule exI, rule exI, rule exI, rule exI)\n      fix n\n      assume \"n \\<in> set (butlast (ns' @ [defNode p]))\"\n      with base.hyps ns'\n      show \"r p q \\<and>\n          defNode q\\<comment>ns'\\<rightarrow>m \\<and>\n          defNode q \\<notin> set (tl ns') \\<and>\n          q \\<in> phiUses m \\<and>\n          m \\<in> set (predecessors (defNode p)) \\<and> n \\<in> set ns' \\<and> set ns' \\<subseteq> set (ns' @ [defNode p]) \\<and> defNode p \\<in> set (ns' @ [defNode p])\"\n        by auto\n    qed\n  next\n    case (step p p')\n    from step.prems(2) step.hyps(1) obtain ns'\\<^sub>2 m where ns'\\<^sub>2: \"defNode p'\\<comment>ns'\\<^sub>2\\<rightarrow>m\" \"m \\<in> set (predecessors (defNode p))\" \"defNode p' \\<notin> set (tl ns'\\<^sub>2)\" \"p' \\<in> phiUses m\"\n      by - (rule phiArg_path_ex', rule assms(3), auto intro: simple_path2)\n    then obtain ns\\<^sub>2 where ns\\<^sub>2: \"defNode p'\\<comment>ns\\<^sub>2\\<rightarrow>defNode p\" \"length ns\\<^sub>2 > 1\" \"ns\\<^sub>2 = ns'\\<^sub>2@[defNode p]\" by (atomize_elim, auto)\n\n    show thesis\n    proof (rule step.IH)\n      fix ns\n      assume ns: \"defNode q\\<comment>ns\\<rightarrow>defNode p'\" \"1 < length ns\"\n      assume IH: \"\\<forall>n\\<in>set (butlast ns).\n             \\<exists>p q m ns'.\n                r p q \\<and>\n                defNode q\\<comment>ns'\\<rightarrow>m \\<and>\n                defNode q \\<notin> set (tl ns') \\<and>\n                q \\<in> phiUses m \\<and> m \\<in> set (predecessors (defNode p)) \\<and> n \\<in> set ns' \\<and> set ns' \\<subseteq> set ns \\<and> defNode p \\<in> set ns\"\n\n      let ?path = \"ns@tl ns\\<^sub>2\"\n      have ns_ns\\<^sub>2: \"defNode q\\<comment>?path\\<rightarrow>defNode p\" \"1 < length ?path\" using ns ns\\<^sub>2(1,2) by auto\n      show thesis\n      proof (rule step.prems(1)[OF ns_ns\\<^sub>2, rule_format])\n        fix n\n        assume n: \"n \\<in> set (butlast ?path)\"\n        show \"\\<exists>p q m ns'a.\n          r p q \\<and>\n          defNode q\\<comment>ns'a\\<rightarrow>m \\<and>\n          defNode q \\<notin> set (tl ns'a) \\<and>\n          q \\<in> phiUses m \\<and> m \\<in> set (predecessors (defNode p)) \\<and> n \\<in> set ns'a \\<and> set ns'a \\<subseteq> set ?path \\<and> defNode p \\<in> set ?path\"\n        proof (cases \"n \\<in> set (butlast ns)\")\n          case True\n          with IH obtain p q m ns' where \"\n                r p q \\<and>\n                defNode q\\<comment>ns'\\<rightarrow>m \\<and>\n                defNode q \\<notin> set (tl ns') \\<and>\n                q \\<in> phiUses m \\<and> m \\<in> set (predecessors (defNode p)) \\<and> n \\<in> set ns' \\<and> set ns' \\<subseteq> set ns \\<and> defNode p \\<in> set ns\" by auto\n          thus ?thesis by - (rule exI, rule exI, rule exI, rule exI, auto)\n        next\n          case False\n          from ns ns\\<^sub>2 have 1: \"?path = butlast ns@ns\\<^sub>2\"\n            by - (rule concat_join[symmetric], auto simp: path2_def)\n          from ns\\<^sub>2(1) n False 1 have \"n \\<in> set (butlast ns\\<^sub>2)\" by (auto simp: butlast_append path2_not_Nil)\n          with step.hyps ns'\\<^sub>2 ns\\<^sub>2(3) show ?thesis\n            by - (subst 1, rule exI[where x=p], rule exI[where x=p'], rule exI, rule exI, auto simp: path2_not_Nil)\n        qed\n      qed\n    next\n      show \"p' \\<in> allVars\" using step.prems(2) step.hyps(1)[THEN assms(3)] by auto\n    qed\n  qed\n\n  lemma non_dominated_predecessor:\n    assumes \"n \\<in> set \\<alpha>n\" \"n \\<noteq> Entry\"\n    obtains m where \"m \\<in> set (predecessors n)\" \"\\<not>dominates n m\"\n  proof-\n    obtain ns where \"Entry\\<comment>ns\\<rightarrow>n\"\n      by (atomize_elim, rule Entry_reaches, auto simp add:assms(1))\n    then obtain ns' where ns': \"Entry\\<comment>ns'\\<rightarrow>n\" \"n \\<notin> set (butlast ns')\"\n      by (rule simple_path2)\n    let ?m = \"last (butlast ns')\"\n    from ns'(1) assms(2) obtain m: \"Entry\\<comment>butlast ns'\\<rightarrow>?m\" \"?m \\<in> set (predecessors n)\"\n      by - (rule path2_unsnoc, auto)\n    with m(1) ns'(2) show thesis\n      by - (rule that, auto elim:dominatesE)\n  qed\n\n  lemma liveVal_in_allVars[simp]: \"liveVal v \\<Longrightarrow> v \\<in> allVars\"\n  by (induction rule: liveVal.induct, auto intro!: allUses_in_allVars)\n\n  lemma phi_no_closed_loop:\n    assumes[simp]: \"p \\<in> allVars\" and \"phi p = Some vs\"\n    shows \"set vs \\<noteq> {p}\"\n  proof (cases \"defNode p = Entry\")\n    case True\n    with assms(2) show ?thesis by auto\n  next\n    case False\n    show ?thesis\n    proof\n      assume[simp]: \"set vs = {p}\"\n      let ?n = \"defNode p\"\n      obtain ns where ns: \"Entry\\<comment>ns\\<rightarrow>?n\" \"?n \\<notin> set (butlast ns)\" by (rule simple_Entry_path, auto)\n      let ?m = \"last (butlast ns)\"\n      from ns False obtain m: \"Entry\\<comment>butlast ns\\<rightarrow>?m\" \"?m \\<in> set (predecessors ?n)\"\n        by - (rule path2_unsnoc, auto)\n      hence \"p \\<in> phiUses ?m\" using assms(2) by - (rule phiUses_exI, auto simp:phi_def)\n      hence \"defAss ?m p\" using m by - (rule allUses_def_ass, auto)\n      then obtain l where l: \"l \\<in> set (butlast ns)\" \"p \\<in> allDefs l\" using m by - (drule defAssD, auto)\n      with assms(2) m have \"l = ?n\" by - (rule allDefs_disjoint', auto)\n      with ns l m show False by auto\n    qed\n  qed\n\n  lemma phis_phi: \"phis (n, v) = Some vs \\<Longrightarrow> phi v = Some vs\"\n  unfolding phi_def\n  apply (subst defNode_eq)\n  by (auto simp: allDefs_def phi_def phiDefs_def intro: phis_in_\\<alpha>n)\n\n  lemma trivial_phi: \"trivial v \\<Longrightarrow> phi v \\<noteq> None\"\n  by (auto simp: trivial_def isTrivialPhi_def split: option.splits)\n\n  lemma trivial_finite: \"finite {v. trivial v}\"\n  by (rule finite_subset[OF _ phi_finite]) (auto dest: trivial_phi)\n\n  lemma trivial_in_allVars: \"trivial v \\<Longrightarrow> v \\<in> allVars\"\n  by (drule trivial_phi, auto simp: allDefs_def phiDefs_def image_def phi_def intro: phis_in_\\<alpha>n intro!: allDefs_in_allVars)\n\n  declare phiArg_def [simp del]\nend\n\nsubsection {* Bundling of CFG and Equivalent SSA CFG *}\n\nlocale CFG_SSA_Transformed_base = CFG_SSA_wf_base \\<alpha>n predecessors Entry \"defs\" \"uses\" phis\n  + old: CFG_base \\<alpha>n predecessors Entry oldDefs oldUses\nfor\n  \\<alpha>n :: \"'node::linorder list\" and\n  predecessors :: \"'node \\<Rightarrow> 'node list\" and\n  Entry::\"'node\" and\n  oldDefs :: \"'node \\<Rightarrow> 'var::linorder set\" and\n  oldUses :: \"'node \\<Rightarrow> 'var set\" and\n  \"defs\" :: \"'node \\<Rightarrow> 'val::linorder set\" and\n  \"uses\" :: \"'node \\<Rightarrow> 'val set\" and\n  phis :: \" ('node, 'val) phis\" +\n  fixes var :: \"'val \\<Rightarrow> 'var\"\n\nlocale CFG_SSA_Transformed = CFG_SSA_Transformed_base \\<alpha>n predecessors Entry oldDefs oldUses \"defs\" \"uses\" phis var\n  + CFG_SSA_wf \\<alpha>n predecessors Entry \"defs\" \"uses\" phis\n  + old: CFG_wf \\<alpha>n predecessors Entry oldDefs oldUses\nfor\n  \\<alpha>n :: \"'node::linorder list\" and\n  predecessors :: \"'node \\<Rightarrow> 'node list\" and\n  Entry::\"'node\" and\n  oldDefs :: \"'node \\<Rightarrow> 'var::linorder set\" and\n  oldUses :: \"'node \\<Rightarrow> 'var set\" and\n  \"defs\" :: \"'node \\<Rightarrow> 'val::linorder set\" and\n  \"uses\" :: \"'node \\<Rightarrow> 'val set\" and\n  phis :: \" ('node, 'val) phis\" and\n  var :: \"'val \\<Rightarrow> 'var\" +\n  assumes oldDefs_def: \"oldDefs n = var ` defs n\"\n  assumes oldUses_def: \"n \\<in> set \\<alpha>n \\<Longrightarrow> oldUses n = var ` uses n\"\n  assumes conventional: \"\n\\<lbrakk>n\\<comment>ns\\<rightarrow>m; n \\<notin> set (tl ns); v \\<in> allDefs n; v \\<in> allUses m; x \\<in> set (tl ns); v' \\<in> allDefs x\\<rbrakk> \\<Longrightarrow> var v' \\<noteq> var v\"\n  assumes phis_same_var[elim]: \"phis (n,v) = Some vs \\<Longrightarrow> v' \\<in> set vs \\<Longrightarrow> var v' = var v\"\n  assumes allDefs_var_disjoint: \"\\<lbrakk>n \\<in> set \\<alpha>n; v \\<in> allDefs n; v' \\<in> allDefs n; v \\<noteq> v'\\<rbrakk> \\<Longrightarrow> var v' \\<noteq> var v\"\nbegin\n  lemma conventional': \"\\<lbrakk>n\\<comment>ns\\<rightarrow>m; n \\<notin> set (tl ns); v \\<in> allDefs n; v \\<in> allUses m; v' \\<in> allDefs x; var v' = var v\\<rbrakk> \\<Longrightarrow> x \\<notin> set (tl ns)\"\n    using conventional by auto\n\n  lemma conventional'': \"\\<lbrakk>defNode v\\<comment>ns\\<rightarrow>m; defNode v \\<notin> set (tl ns); v \\<in> allUses m; var v' = var v; v \\<in> allVars; v' \\<in> allVars\\<rbrakk> \\<Longrightarrow> defNode v' \\<notin> set (tl ns)\"\n    by (rule conventional'[where v=v and v'=v'], auto)\n\n  lemma phiArg_same_var: \"phiArg p q \\<Longrightarrow> var q = var p\"\n    by (metis phiArg_def phi_def phis_same_var)\n\n  lemma oldDef_defAss:\n    assumes \"v \\<in> allUses n\" \"Entry\\<comment>ns\\<rightarrow>n\"\n    obtains m where \"m \\<in> set ns\" \"var v \\<in> oldDefs m\"\n  using assms proof (induction ns arbitrary: v n rule: length_induct)\n    case (1 ns)\n    from \"1.prems\"(2-) have 2: \"defNode v \\<in> set ns\"\n      by - (rule defAss_defNode, rule allUses_def_ass, auto)\n    let ?V = \"defNode v\"\n    from \"1.prems\"(2,3) have[simp]: \"v \\<in> allVars\" by auto\n    thus ?case\n    proof (cases v rule: defNode_cases)\n      case simpleDef\n      with 2 show thesis by - (rule \"1.prems\"(1), auto simp: oldDefs_def)\n    next\n      case phi\n      then obtain vs where vs: \"phi v = Some vs\" by auto\n      from \"1.prems\"(3) 2 obtain ns' where ns': \"Entry\\<comment>ns'\\<rightarrow>?V\" \"prefixeq ns' ns\"\n        by (rule path2_split_ex, auto)\n      let ?V' = \"last (butlast ns')\"\n      from ns' phi have nontriv: \"length ns' \\<ge> 2\"\n        by - (rule path2_nontrivial, auto)\n      hence 3: \"Entry\\<comment>butlast ns'\\<rightarrow>?V'\" \"?V' \\<in> set (predecessors ?V)\"\n        using ns'(1) by (auto intro: path2_unsnoc)\n      with phi vs obtain v' where v': \"v' \\<in> phiUses ?V'\" \"var v' = var v\"\n        by - (rule phiArg_exI, auto simp: phi_def phis_same_var phiArg_def)\n      show thesis\n      proof (rule \"1.IH\"[rule_format])\n        show \"length (butlast ns') < length ns\" using ns' by (cases ns', auto simp: path2_not_Nil2 dest: prefixeq_length_le)\n        show \"v' \\<in> allUses ?V'\" using v'(1) by simp\n      next\n        fix n\n        assume \"n \\<in> set (butlast ns')\" \"var v' \\<in> oldDefs n\"\n        thus thesis\n          using ns'(2)[THEN set_mono_prefixeq] v'(2) by - (rule \"1.prems\"(1)[of n], auto dest: in_set_butlastD)\n      qed (rule 3(1))\n    qed\n  qed\n\n  lemma allDef_path_from_simpleDef:\n    assumes[simp]: \"v \\<in> allVars\"\n    obtains n ns where \"n\\<comment>ns\\<rightarrow>defNode v\" \"EntryPath ns\" \"var v \\<in> oldDefs n\"\n  proof-\n    let ?V = \"defNode v\"\n    from assms obtain ns where ns: \"Entry\\<comment>ns\\<rightarrow>?V\" \"EntryPath ns\"\n      by - (rule Entry_reachesE, auto)\n    from assms show thesis\n    proof (cases v rule: defNode_cases)\n      case simpleDef\n      thus thesis by - (rule that, auto simp: oldDefs_def)\n    next\n      case phi\n      then obtain vs where vs: \"phi v = Some vs\" by auto\n      let ?V' = \"last (butlast ns)\"\n      from ns phi have nontriv: \"length ns \\<ge> 2\"\n        by - (rule path2_nontrivial, auto)\n      hence 3: \"Entry\\<comment>butlast ns\\<rightarrow>?V'\" \"?V' \\<in> set (predecessors ?V)\"\n        using ns(1) by (auto intro: path2_unsnoc)\n      with phi vs obtain v' where v': \"v' \\<in> phiUses ?V'\" \"var v' = var v\"\n        by - (rule phiArg_exI, auto simp: phi_def phis_same_var phiArg_def)\n      with 3(1) obtain n where n: \"n \\<in> set (butlast ns)\" \"var v' \\<in> oldDefs n\"\n        by - (rule oldDef_defAss[of v'], auto)\n      with ns obtain ns' where \"n\\<comment>ns'\\<rightarrow>?V\" \"suffixeq ns' ns\"\n        by - (rule path2_split_ex'[OF ns(1)], auto intro: in_set_butlastD simp: suffixeq_def)\n      with n(2) v'(2) ns(2) show thesis\n        by - (rule that, assumption, erule EntryPath_suffixeq, auto)\n    qed\n  qed\n\n  lemma defNode_var_disjoint:\n    assumes \"p \\<in> allVars\" \"q \\<in> allVars\" \"p \\<noteq> q\" \"defNode p = defNode q\"\n    shows \"var p \\<noteq> var q\"\n  proof-\n    have \"q \\<in> allDefs (defNode p)\" using assms(2) assms(4) by (auto)\n    thus ?thesis using assms(1-3)\n      by - (rule allDefs_var_disjoint[of \"defNode p\"], auto)\n  qed\n\n  lemma phiArg_distinct_nodes:\n    assumes \"phiArg p q\" \"p \\<noteq> q\" and[simp]: \"p \\<in> allVars\"\n    shows \"defNode p \\<noteq> defNode q\"\n  proof\n    have \"p \\<in> allDefs (defNode p)\" by simp\n    moreover assume \"defNode p = defNode q\"\n    ultimately have \"var p \\<noteq> var q\" using assms\n      by - (rule defNode_var_disjoint, auto)\n    moreover\n    from assms(1) have \"var q = var p\" by (rule phiArg_same_var)\n    ultimately show False by simp\n  qed\n\n  lemma phiArgs_def_distinct:\n    assumes \"phiArg p q\" \"phiArg p r\" \"q \\<noteq> r\" \"p \\<in> allVars\"\n    shows \"defNode q \\<noteq> defNode r\"\n  proof (rule)\n    assume \"defNode q = defNode r\"\n    hence \"var q \\<noteq> var r\" using assms by - (rule defNode_var_disjoint, auto)\n    thus False using phiArg_same_var[OF assms(1)] phiArg_same_var[OF assms(2)] by simp\n  qed\n\n  lemma defNode_not_on_defUse_path:\n    assumes p: \"defNode p\\<comment>ns\\<rightarrow>n\" \"defNode p \\<notin> set (tl ns)\" \"p \\<in> allUses n\"\n    assumes[simp]: \"q \\<in> allVars\" \"p \\<noteq> q\" \"var p = var q\"\n    shows \"defNode q \\<notin> set ns\"\n  proof-\n    let ?P = \"defNode p\"\n    let ?Q = \"defNode q\"\n\n    have[simp]: \"p \\<in> allVars\" using p(1,3) by auto\n    have \"?P \\<noteq> ?Q\" using defNode_var_disjoint[of p q] by auto\n    moreover have \"?Q \\<notin> set (tl ns)\" using p(2,3)\n      by - (rule conventional'[OF p(1), of p q], auto)\n    ultimately show ?thesis using p(1) by (cases ns, auto simp: path2_def)\n  qed\n\n  lemma defUse_paths_disjoint:\n    assumes p: \"defNode p\\<comment>ns\\<rightarrow>n\" \"defNode p \\<notin> set (tl ns)\" \"p \\<in> allUses n\"\n    assumes q: \"defNode q\\<comment>ms\\<rightarrow>m\" \"defNode q \\<notin> set (tl ms)\" \"q \\<in> allUses m\"\n    assumes[simp]: \"p \\<noteq> q\" \"var p = var q\"\n    shows \"set ns \\<inter> set ms = {}\"\n  proof (rule equals0I)\n    fix y\n    assume y: \"y \\<in> set ns \\<inter> set ms\"\n\n    {\n      fix p ns n\n      assume p: \"defNode p\\<comment>ns\\<rightarrow>n\" \"defNode p \\<notin> set (tl ns)\" \"p \\<in> allUses n\"\n      assume y: \"y \\<in> set ns\"\n      from p(1,3) have dom: \"dominates (defNode p) n\" by - (rule allUses_dominated, auto)\n      moreover\n      obtain ns' where \"y\\<comment>ns'\\<rightarrow>n\" \"suffixeq ns' ns\"\n        by (rule path2_split_first_last[OF p(1) y], auto)\n      ultimately have \"dominates (defNode p) y\" using suffixeq_tl_subset[of ns' ns] p(2)\n        by - (rule dominates_extend[where ms=ns'], auto)\n    }\n    with assms y have dom: \"dominates (defNode p) y\" \"dominates (defNode q) y\" by auto\n\n    {\n      fix p ns n q ms m\n      let ?P = \"defNode p\"\n      let ?Q = \"defNode q\"\n\n      assume p: \"defNode p\\<comment>ns\\<rightarrow>n\" \"defNode p \\<notin> set (tl ns)\" \"p \\<in> allUses n\" \"dominates ?P y\" \"y \\<in> set ns\"\n      assume q: \"defNode q\\<comment>ms\\<rightarrow>m\" \"defNode q \\<notin> set (tl ms)\" \"q \\<in> allUses m\" \"dominates ?Q y\" \"y \\<in> set ms\"\n      assume[simp]: \"p \\<noteq> q\" \"var p = var q\"\n      assume dom: \"dominates ?P ?Q\"\n      then obtain pqs where pqs: \"?P\\<comment>pqs\\<rightarrow>?Q\" \"?P \\<notin> set (tl pqs)\" by (rule dominates_path, auto intro: simple_path2)\n      from p obtain ns\\<^sub>2 where ns\\<^sub>2: \"y\\<comment>ns\\<^sub>2\\<rightarrow>n\" \"suffixeq ns\\<^sub>2 ns\" by - (rule path2_split_first_last, auto)\n      from q obtain ms\\<^sub>1 where ms\\<^sub>1: \"?Q\\<comment>ms\\<^sub>1\\<rightarrow>y\" \"prefixeq ms\\<^sub>1 ms\" by - (rule path2_split_first_last, auto)\n      have \"var q \\<noteq> var p\"\n      proof (rule conventional[OF _ _ _ p(3)])\n        let ?path = \"(pqs@tl ms\\<^sub>1)@tl ns\\<^sub>2\"\n        show \"?P\\<comment>?path\\<rightarrow>n\" using pqs ms\\<^sub>1 ns\\<^sub>2\n          by (auto simp del:append_assoc intro:path2_app)\n        have \"?P \\<notin> set (tl ns\\<^sub>2)\" using p(2) ns\\<^sub>2(2)[THEN suffixeq_tl_subset, THEN subsetD] by auto\n        moreover\n        have[simp]: \"q \\<in> allVars\" \"p \\<in> allVars\" using p q by auto\n        have \"?P \\<notin> set (tl ms)\" using q\n          by - (rule conventional'[where v'=p and v=q], auto)\n        hence \"?P \\<notin> set (tl ms\\<^sub>1)\" using ms\\<^sub>1(2)[simplified, THEN prefixeq_tl_subset] by auto\n        ultimately\n        show \"?P \\<notin> set (tl ?path)\" using pqs(2)\n          by - (rule notI, auto dest: subsetD[OF set_tl_append'])\n        show \"p \\<in> allDefs (defNode p)\" by auto\n        have \"?P \\<noteq> ?Q\" using defNode_var_disjoint[of p q] by auto\n        hence 1: \"length pqs > 1\" using pqs by - (rule path2_nontriv)\n        hence \"?Q \\<in> set (tl pqs)\" using pqs unfolding path2_def by (auto intro:last_in_tl)\n        moreover from 1 have \"pqs \\<noteq> []\" by auto\n        ultimately show \"?Q \\<in> set (tl ?path)\" by simp\n        show \"q \\<in> allDefs ?Q\" by simp\n      qed\n      hence False by simp\n    }\n    from this[OF p _ _ q] this[OF q _ _ p] y dom show False\n      by - (rule dominates_antitrans[OF dom], auto)\n  qed\n\n  lemma oldDefsI: \"v \\<in> defs n \\<Longrightarrow> var v \\<in> oldDefs n\" by (simp add: oldDefs_def)\n\n  lemma simpleDefs_phiDefs_var_disjoint:\n    assumes \"v \\<in> phiDefs n\" \"n \\<in> set \\<alpha>n\"\n    shows \"var v \\<notin> oldDefs n\"\n  proof\n    from assms have[simp]: \"v \\<in> allVars\" by auto\n    assume \"var v \\<in> oldDefs n\"\n    then obtain v'' where v'': \"v'' \\<in> defs n\" \"var v'' = var v\"\n      by (auto simp: oldDefs_def)\n    from this(1) assms have \"v'' \\<noteq> v\"\n      using simpleDefs_phiDefs_disjoint[of n] by (auto simp: phiArg_def)\n    with v'' assms show False\n      using allDefs_var_disjoint[of n v'' v] by auto\n  qed\n\n  lemma liveVal_use_path:\n    assumes \"liveVal v\"\n    obtains ns m where \"defNode v\\<comment>ns\\<rightarrow>m\" \"var v \\<in> oldUses m\"\n      \"\\<And>x. x \\<in> set (tl ns) \\<Longrightarrow> var v \\<notin> oldDefs x\"\n  using assms proof (induction)\n    case (liveSimple m v)\n    from liveSimple.hyps have[simp]: \"v \\<in> allVars\"\n      by - (rule allUses_in_allVars, auto)\n    from liveSimple.hyps obtain ns where ns: \"defNode v\\<comment>ns\\<rightarrow>m\" \"defNode v \\<notin> set (tl ns)\"\n      by - (rule defUse_path_ex, auto intro!: uses_in_allUses elim: simple_path2)\n    from this(1) show thesis\n    proof (rule liveSimple.prems)\n      show \"var v \\<in> oldUses m\" using liveSimple.hyps by (auto simp: oldUses_def)\n      {\n        fix x\n        assume asm: \"x \\<in> set (tl ns)\" \"var v \\<in> oldDefs x\"\n        then obtain v' where \"v' \\<in> defs x\" \"var v' = var v\"\n          by (auto simp: oldDefs_def)\n        with asm liveSimple.hyps have False\n          by - (rule conventional[OF ns, of v x v', THEN notE], auto)\n      }\n      thus \"\\<And>x. x \\<in> set (tl ns) \\<Longrightarrow> var v \\<notin> oldDefs x\" by auto\n    qed\n  next\n    case (livePhi v v')\n    from livePhi.hyps have[simp]: \"v \\<in> allVars\" \"v' \\<in> allVars\" \"var v' = var v\"\n      by (auto intro: phiArg_same_var)\n    show thesis\n    proof (rule livePhi.IH)\n      fix ns m\n      assume asm: \"defNode v\\<comment>ns\\<rightarrow>m\" \"var v \\<in> oldUses m\"\n        \"\\<And>x. x \\<in> set (tl ns) \\<Longrightarrow> var v \\<notin> oldDefs x\"\n      from livePhi.hyps(2) obtain ns' m' where ns': \"defNode v'\\<comment>ns'\\<rightarrow>m'\" \"v' \\<in> phiUses m'\"\n        \"m' \\<in> set (predecessors (defNode v))\" \"defNode v' \\<notin> set (tl ns')\"\n        by (rule phiArg_path_ex', auto elim: simple_path2)\n      show thesis\n      proof (rule livePhi.prems)\n        show \"defNode v'\\<comment>(ns'@[defNode v])@tl ns\\<rightarrow>m\"\n        apply (rule path2_app)\n         apply (rule path2_snoc[OF ns'(1,3)])\n        by (rule asm(1))\n        show \"var v' \\<in> oldUses m\" using asm(2) by simp\n        {\n          fix x\n          assume asm: \"x \\<in> set (tl ns')\" \"var v \\<in> oldDefs x\"\n          then obtain v'' where \"v'' \\<in> defs x\" \"var v'' = var v\"\n            by (auto simp: oldDefs_def)\n          with asm ns'(2) have False\n            by - (rule conventional[OF ns'(1,4), of v' x v'', THEN notE], auto)\n        }\n        then show \"\\<And>x. x \\<in> set (tl ((ns'@[defNode v])@tl ns)) \\<Longrightarrow> var v' \\<notin> oldDefs x\"\n          using simpleDefs_phiDefs_var_disjoint[of v \"defNode v\"] livePhi.hyps(2)\n          by (auto dest!: set_tl_append'[THEN subsetD] asm(3) simp: phiArg_def)\n      qed\n    qed\n  qed\nend\n\nend\n", "meta": {"author": "lohner", "repo": "FormalSSA", "sha": "34253ae0ea0db6ef78b644f41ab5e9d0bde6c32e", "save_path": "github-repos/isabelle/lohner-FormalSSA", "path": "github-repos/isabelle/lohner-FormalSSA/FormalSSA-34253ae0ea0db6ef78b644f41ab5e9d0bde6c32e/SSA_CFG.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926665999540698, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.2870758976339061}}
{"text": "chapter \\<open>Dynamic Slicing\\<close>\n\nsection \\<open>Dynamic Program Dependence Graph\\<close>\n\ntheory DynPDG imports \n  \"../Basic/DynDataDependence\" \n  \"../Basic/CFGExit_wf\" \n  \"../Basic/DynStandardControlDependence\"\n  \"../Basic/DynWeakControlDependence\"\nbegin\n\nsubsection \\<open>The dynamic PDG\\<close>\n\nlocale DynPDG = \n  CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use state_val Exit\n  for sourcenode :: \"'edge \\<Rightarrow> 'node\" and targetnode :: \"'edge \\<Rightarrow> 'node\"\n  and kind :: \"'edge \\<Rightarrow> 'state edge_kind\" and valid_edge :: \"'edge \\<Rightarrow> bool\"\n  and Entry :: \"'node\" (\"'('_Entry'_')\") and Def :: \"'node \\<Rightarrow> 'var set\"\n  and Use :: \"'node \\<Rightarrow> 'var set\" and state_val :: \"'state \\<Rightarrow> 'var \\<Rightarrow> 'val\"\n  and Exit :: \"'node\" (\"'('_Exit'_')\") +\n  fixes dyn_control_dependence :: \"'node \\<Rightarrow> 'node \\<Rightarrow> 'edge list \\<Rightarrow> bool\" \n(\"_ controls _ via _\" [51,0,0])\n  assumes Exit_not_dyn_control_dependent:\"n controls n' via as \\<Longrightarrow> n' \\<noteq> (_Exit_)\"\n  assumes dyn_control_dependence_path:\n  \"n controls n' via as  \\<Longrightarrow> n -as\\<rightarrow>* n' \\<and> as \\<noteq> []\"\n\nbegin\n\ninductive cdep_edge :: \"'node \\<Rightarrow> 'edge list \\<Rightarrow> 'node \\<Rightarrow> bool\" \n    (\"_ -_\\<rightarrow>\\<^sub>c\\<^sub>d _\" [51,0,0] 80)\n  and ddep_edge :: \"'node \\<Rightarrow> 'var \\<Rightarrow> 'edge list \\<Rightarrow> 'node \\<Rightarrow> bool\"\n    (\"_ -'{_'}_\\<rightarrow>\\<^sub>d\\<^sub>d _\" [51,0,0,0] 80)\n  and DynPDG_edge :: \"'node \\<Rightarrow> 'var option \\<Rightarrow> 'edge list \\<Rightarrow> 'node \\<Rightarrow> bool\"\n\nwhere\n      \\<comment> \\<open>Syntax\\<close>\n  \"n -as\\<rightarrow>\\<^sub>c\\<^sub>d n' == DynPDG_edge n None as n'\"\n  | \"n -{V}as\\<rightarrow>\\<^sub>d\\<^sub>d n' == DynPDG_edge n (Some V) as n'\"\n\n      \\<comment> \\<open>Rules\\<close>\n  | DynPDG_cdep_edge:\n  \"n controls n' via as \\<Longrightarrow> n -as\\<rightarrow>\\<^sub>c\\<^sub>d n'\"\n\n  | DynPDG_ddep_edge:\n  \"n influences V in n' via as \\<Longrightarrow> n -{V}as\\<rightarrow>\\<^sub>d\\<^sub>d n'\"\n\n\ninductive DynPDG_path :: \"'node \\<Rightarrow> 'edge list \\<Rightarrow> 'node \\<Rightarrow> bool\"\n(\"_ -_\\<rightarrow>\\<^sub>d* _\" [51,0,0] 80) \n\nwhere DynPDG_path_Nil:\n  \"valid_node n \\<Longrightarrow> n -[]\\<rightarrow>\\<^sub>d* n\"\n\n  | DynPDG_path_Append_cdep:\n  \"\\<lbrakk>n -as\\<rightarrow>\\<^sub>d* n''; n'' -as'\\<rightarrow>\\<^sub>c\\<^sub>d n'\\<rbrakk> \\<Longrightarrow> n -as@as'\\<rightarrow>\\<^sub>d* n'\"\n\n  | DynPDG_path_Append_ddep:\n  \"\\<lbrakk>n -as\\<rightarrow>\\<^sub>d* n''; n'' -{V}as'\\<rightarrow>\\<^sub>d\\<^sub>d n'\\<rbrakk> \\<Longrightarrow> n -as@as'\\<rightarrow>\\<^sub>d* n'\"\n\n\nlemma DynPDG_empty_path_eq_nodes:\"n -[]\\<rightarrow>\\<^sub>d* n' \\<Longrightarrow> n = n'\"\napply - apply(erule DynPDG_path.cases) \n  apply simp\n apply(auto elim:DynPDG_edge.cases dest:dyn_control_dependence_path)\nby(auto elim:DynPDG_edge.cases simp:dyn_data_dependence_def)\n\n\nlemma DynPDG_path_cdep:\"n -as\\<rightarrow>\\<^sub>c\\<^sub>d n' \\<Longrightarrow> n -as\\<rightarrow>\\<^sub>d* n'\"\napply(subgoal_tac \"n -[]@as\\<rightarrow>\\<^sub>d* n'\")\n apply simp\napply(rule DynPDG_path_Append_cdep, rule DynPDG_path_Nil)\nby(auto elim!:DynPDG_edge.cases dest:dyn_control_dependence_path path_valid_node)\n\nlemma DynPDG_path_ddep:\"n -{V}as\\<rightarrow>\\<^sub>d\\<^sub>d n' \\<Longrightarrow> n -as\\<rightarrow>\\<^sub>d* n'\"\napply(subgoal_tac \"n -[]@as\\<rightarrow>\\<^sub>d* n'\")\n apply simp\napply(rule DynPDG_path_Append_ddep, rule DynPDG_path_Nil)\nby(auto elim!:DynPDG_edge.cases dest:path_valid_node simp:dyn_data_dependence_def)\n\nlemma DynPDG_path_Append:\n  \"\\<lbrakk>n'' -as'\\<rightarrow>\\<^sub>d* n'; n -as\\<rightarrow>\\<^sub>d* n''\\<rbrakk> \\<Longrightarrow> n -as@as'\\<rightarrow>\\<^sub>d* n'\"\napply(induct rule:DynPDG_path.induct)\n  apply(auto intro:DynPDG_path.intros)\n apply(rotate_tac 1,drule DynPDG_path_Append_cdep,simp+)\napply(rotate_tac 1,drule DynPDG_path_Append_ddep,simp+)\ndone\n\n\nlemma DynPDG_path_Exit:\"\\<lbrakk>n -as\\<rightarrow>\\<^sub>d* n'; n' = (_Exit_)\\<rbrakk> \\<Longrightarrow> n = (_Exit_)\"\napply(induct rule:DynPDG_path.induct)\nby(auto elim:DynPDG_edge.cases dest:Exit_not_dyn_control_dependent \n        simp:dyn_data_dependence_def)\n\n\nlemma DynPDG_path_not_inner:\n  \"\\<lbrakk>n -as\\<rightarrow>\\<^sub>d* n'; \\<not> inner_node n'\\<rbrakk> \\<Longrightarrow> n = n'\"\nproof(induct rule:DynPDG_path.induct)\n  case (DynPDG_path_Nil n)\n  thus ?case by simp\nnext\n  case (DynPDG_path_Append_cdep n as n'' as' n')\n  from \\<open>n'' -as'\\<rightarrow>\\<^sub>c\\<^sub>d n'\\<close> \\<open>\\<not> inner_node n'\\<close> have False\n    apply -\n    apply(erule DynPDG_edge.cases) apply(auto simp:inner_node_def)\n      apply(fastforce dest:dyn_control_dependence_path path_valid_node)\n     apply(fastforce dest:dyn_control_dependence_path path_valid_node)\n    by(fastforce dest:Exit_not_dyn_control_dependent)\n  thus ?case by simp\nnext\n  case (DynPDG_path_Append_ddep n as n'' V as' n')\n  from \\<open>n'' -{V}as'\\<rightarrow>\\<^sub>d\\<^sub>d n'\\<close> \\<open>\\<not> inner_node n'\\<close> have False\n    apply -\n    apply(erule DynPDG_edge.cases) \n    by(auto dest:path_valid_node simp:inner_node_def dyn_data_dependence_def)\n  thus ?case by simp\nqed\n\n\nlemma DynPDG_cdep_edge_CFG_path:\n  assumes \"n -as\\<rightarrow>\\<^sub>c\\<^sub>d n'\" shows \"n -as\\<rightarrow>* n'\" and \"as \\<noteq> []\"\n  using \\<open>n -as\\<rightarrow>\\<^sub>c\\<^sub>d n'\\<close>\n  by(auto elim:DynPDG_edge.cases dest:dyn_control_dependence_path)\n\nlemma DynPDG_ddep_edge_CFG_path:\n  assumes \"n -{V}as\\<rightarrow>\\<^sub>d\\<^sub>d n'\" shows \"n -as\\<rightarrow>* n'\" and \"as \\<noteq> []\"\n  using \\<open>n -{V}as\\<rightarrow>\\<^sub>d\\<^sub>d n'\\<close>\n  by(auto elim:DynPDG_edge.cases simp:dyn_data_dependence_def)\n\nlemma DynPDG_path_CFG_path:\n  \"n -as\\<rightarrow>\\<^sub>d* n' \\<Longrightarrow> n -as\\<rightarrow>* n'\"\nproof(induct rule:DynPDG_path.induct)\n  case DynPDG_path_Nil thus ?case by(rule empty_path)\nnext\n  case (DynPDG_path_Append_cdep n as n'' as' n')\n  from \\<open>n'' -as'\\<rightarrow>\\<^sub>c\\<^sub>d n'\\<close> have \"n'' -as'\\<rightarrow>* n'\"\n    by(rule DynPDG_cdep_edge_CFG_path(1))\n  with \\<open>n -as\\<rightarrow>* n''\\<close> show ?case by(rule path_Append)\nnext\n  case (DynPDG_path_Append_ddep n as n'' V as' n')\n  from \\<open>n'' -{V}as'\\<rightarrow>\\<^sub>d\\<^sub>d n'\\<close> have \"n'' -as'\\<rightarrow>* n'\"\n    by(rule DynPDG_ddep_edge_CFG_path(1))\n  with \\<open>n -as\\<rightarrow>* n''\\<close> show ?case by(rule path_Append)\nqed\n\n\nlemma DynPDG_path_split: \n  \"n -as\\<rightarrow>\\<^sub>d* n' \\<Longrightarrow>\n  (as = [] \\<and> n = n') \\<or> \n  (\\<exists>n'' asx asx'. (n -asx\\<rightarrow>\\<^sub>c\\<^sub>d n'') \\<and> (n'' -asx'\\<rightarrow>\\<^sub>d* n') \\<and> \n        (as = asx@asx')) \\<or>\n  (\\<exists>n'' V asx asx'. (n -{V}asx\\<rightarrow>\\<^sub>d\\<^sub>d n'') \\<and> (n'' -asx'\\<rightarrow>\\<^sub>d* n') \\<and> \n        (as = asx@asx'))\"\nproof(induct rule:DynPDG_path.induct)\n  case (DynPDG_path_Nil n) thus ?case by auto\nnext\n  case (DynPDG_path_Append_cdep n as n'' as' n')\n  note IH = \\<open>as = [] \\<and> n = n'' \\<or>\n    (\\<exists>nx asx asx'. n -asx\\<rightarrow>\\<^sub>c\\<^sub>d nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx') \\<or>\n    (\\<exists>nx V asx asx'. n -{V}asx\\<rightarrow>\\<^sub>d\\<^sub>d nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx')\\<close>\n  from IH show ?case\n  proof\n    assume \"as = [] \\<and> n = n''\"\n    with \\<open>n'' -as'\\<rightarrow>\\<^sub>c\\<^sub>d n'\\<close> have \"valid_node n'\"\n      by(fastforce intro:path_valid_node(2) DynPDG_path_CFG_path \n                        DynPDG_path_cdep)\n    with \\<open>as = [] \\<and> n = n''\\<close> \\<open>n'' -as'\\<rightarrow>\\<^sub>c\\<^sub>d n'\\<close>\n    have \"\\<exists>n'' asx asx'. n -asx\\<rightarrow>\\<^sub>c\\<^sub>d n'' \\<and> n'' -asx'\\<rightarrow>\\<^sub>d* n' \\<and> as@as' = asx@asx'\"\n      by(auto intro:DynPDG_path_Nil)\n    thus ?thesis by simp\n  next\n    assume \"(\\<exists>nx asx asx'. n -asx\\<rightarrow>\\<^sub>c\\<^sub>d nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx') \\<or>\n      (\\<exists>nx V asx asx'. n -{V}asx\\<rightarrow>\\<^sub>d\\<^sub>d nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx')\"\n    thus ?thesis\n    proof\n      assume \"\\<exists>nx asx asx'. n -asx\\<rightarrow>\\<^sub>c\\<^sub>d nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx'\"\n      then obtain nx asx asx' where \"n -asx\\<rightarrow>\\<^sub>c\\<^sub>d nx\" and \"nx -asx'\\<rightarrow>\\<^sub>d* n''\"\n        and \"as = asx@asx'\" by auto\n      from \\<open>n'' -as'\\<rightarrow>\\<^sub>c\\<^sub>d n'\\<close> have \"n'' -as'\\<rightarrow>\\<^sub>d* n'\" by(rule DynPDG_path_cdep)\n      with \\<open>nx -asx'\\<rightarrow>\\<^sub>d* n''\\<close> have \"nx -asx'@as'\\<rightarrow>\\<^sub>d* n'\"\n        by(fastforce intro:DynPDG_path_Append)\n      with \\<open>n -asx\\<rightarrow>\\<^sub>c\\<^sub>d nx\\<close> \\<open>as = asx@asx'\\<close>\n      have \"\\<exists>n'' asx asx'. n -asx\\<rightarrow>\\<^sub>c\\<^sub>d n'' \\<and> n'' -asx'\\<rightarrow>\\<^sub>d* n' \\<and> as@as' = asx@asx'\"\n        by auto\n      thus ?thesis by simp\n    next\n      assume \"\\<exists>nx V asx asx'. n -{V}asx\\<rightarrow>\\<^sub>d\\<^sub>d nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx'\"\n      then obtain nx V asx asx' where \"n -{V}asx\\<rightarrow>\\<^sub>d\\<^sub>d nx\" and \"nx -asx'\\<rightarrow>\\<^sub>d* n''\"\n        and \"as = asx@asx'\" by auto\n      from \\<open>n'' -as'\\<rightarrow>\\<^sub>c\\<^sub>d n'\\<close> have \"n'' -as'\\<rightarrow>\\<^sub>d* n'\" by(rule DynPDG_path_cdep)\n      with \\<open>nx -asx'\\<rightarrow>\\<^sub>d* n''\\<close> have \"nx -asx'@as'\\<rightarrow>\\<^sub>d* n'\"\n        by(fastforce intro:DynPDG_path_Append)\n      with \\<open>n -{V}asx\\<rightarrow>\\<^sub>d\\<^sub>d nx\\<close> \\<open>as = asx@asx'\\<close>\n      have \"\\<exists>n'' V asx asx'. n -{V}asx\\<rightarrow>\\<^sub>d\\<^sub>d n'' \\<and> n'' -asx'\\<rightarrow>\\<^sub>d* n' \\<and> as@as' = asx@asx'\"\n        by auto\n      thus ?thesis by simp\n    qed\n  qed\nnext\n  case (DynPDG_path_Append_ddep n as n'' V as' n')\n  note IH = \\<open>as = [] \\<and> n = n'' \\<or>\n    (\\<exists>nx asx asx'. n -asx\\<rightarrow>\\<^sub>c\\<^sub>d nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx') \\<or>\n    (\\<exists>nx V asx asx'. n -{V}asx\\<rightarrow>\\<^sub>d\\<^sub>d nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx')\\<close>\n  from IH show ?case\n  proof\n    assume \"as = [] \\<and> n = n''\"\n    with \\<open>n'' -{V}as'\\<rightarrow>\\<^sub>d\\<^sub>d n'\\<close> have \"valid_node n'\"\n      by(fastforce intro:path_valid_node(2) DynPDG_path_CFG_path \n                        DynPDG_path_ddep)\n    with \\<open>as = [] \\<and> n = n''\\<close> \\<open>n'' -{V}as'\\<rightarrow>\\<^sub>d\\<^sub>d n'\\<close>\n    have \"\\<exists>n'' V asx asx'. n -{V}asx\\<rightarrow>\\<^sub>d\\<^sub>d n'' \\<and> n'' -asx'\\<rightarrow>\\<^sub>d* n' \\<and> as@as' = asx@asx'\"\n      by(fastforce intro:DynPDG_path_Nil)\n    thus ?thesis by simp\n  next\n    assume \"(\\<exists>nx asx asx'. n -asx\\<rightarrow>\\<^sub>c\\<^sub>d nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx') \\<or>\n      (\\<exists>nx V asx asx'. n -{V}asx\\<rightarrow>\\<^sub>d\\<^sub>d nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx')\"\n    thus ?thesis\n    proof\n      assume \"\\<exists>nx asx asx'. n -asx\\<rightarrow>\\<^sub>c\\<^sub>d nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx'\"\n      then obtain nx asx asx' where \"n -asx\\<rightarrow>\\<^sub>c\\<^sub>d nx\" and \"nx -asx'\\<rightarrow>\\<^sub>d* n''\"\n        and \"as = asx@asx'\" by auto\n      from \\<open>n'' -{V}as'\\<rightarrow>\\<^sub>d\\<^sub>d n'\\<close> have \"n'' -as'\\<rightarrow>\\<^sub>d* n'\" by(rule DynPDG_path_ddep)\n      with \\<open>nx -asx'\\<rightarrow>\\<^sub>d* n''\\<close> have \"nx -asx'@as'\\<rightarrow>\\<^sub>d* n'\"\n        by(fastforce intro:DynPDG_path_Append)\n      with \\<open>n -asx\\<rightarrow>\\<^sub>c\\<^sub>d nx\\<close> \\<open>as = asx@asx'\\<close>\n      have \"\\<exists>n'' asx asx'. n -asx\\<rightarrow>\\<^sub>c\\<^sub>d n'' \\<and> n'' -asx'\\<rightarrow>\\<^sub>d* n' \\<and> as@as' = asx@asx'\"\n        by auto\n      thus ?thesis by simp\n    next\n      assume \"\\<exists>nx V asx asx'. n -{V}asx\\<rightarrow>\\<^sub>d\\<^sub>d nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx'\"\n      then obtain nx V' asx asx' where \"n -{V'}asx\\<rightarrow>\\<^sub>d\\<^sub>d nx\" and \"nx -asx'\\<rightarrow>\\<^sub>d* n''\"\n        and \"as = asx@asx'\" by auto\n      from \\<open>n'' -{V}as'\\<rightarrow>\\<^sub>d\\<^sub>d n'\\<close> have \"n'' -as'\\<rightarrow>\\<^sub>d* n'\" by(rule DynPDG_path_ddep)\n      with \\<open>nx -asx'\\<rightarrow>\\<^sub>d* n''\\<close> have \"nx -asx'@as'\\<rightarrow>\\<^sub>d* n'\"\n        by(fastforce intro:DynPDG_path_Append)\n      with \\<open>n -{V'}asx\\<rightarrow>\\<^sub>d\\<^sub>d nx\\<close> \\<open>as = asx@asx'\\<close>\n      have \"\\<exists>n'' V asx asx'. n -{V}asx\\<rightarrow>\\<^sub>d\\<^sub>d n'' \\<and> n'' -asx'\\<rightarrow>\\<^sub>d* n' \\<and> as@as' = asx@asx'\"\n        by auto\n      thus ?thesis by simp\n    qed\n  qed\nqed\n\n\nlemma DynPDG_path_rev_cases [consumes 1,\n  case_names DynPDG_path_Nil DynPDG_path_cdep_Append DynPDG_path_ddep_Append]:\n  \"\\<lbrakk>n -as\\<rightarrow>\\<^sub>d* n'; \\<lbrakk>as = []; n = n'\\<rbrakk> \\<Longrightarrow> Q;\n    \\<And>n'' asx asx'. \\<lbrakk>n -asx\\<rightarrow>\\<^sub>c\\<^sub>d n''; n'' -asx'\\<rightarrow>\\<^sub>d* n'; \n                       as = asx@asx'\\<rbrakk> \\<Longrightarrow> Q;\n    \\<And>V n'' asx asx'. \\<lbrakk>n -{V}asx\\<rightarrow>\\<^sub>d\\<^sub>d n''; n'' -asx'\\<rightarrow>\\<^sub>d* n'; \n                       as = asx@asx'\\<rbrakk> \\<Longrightarrow> Q\\<rbrakk>\n  \\<Longrightarrow> Q\"\nby(blast dest:DynPDG_path_split)\n\n\n\nlemma DynPDG_ddep_edge_no_shorter_ddep_edge:\n  assumes ddep:\"n -{V}as\\<rightarrow>\\<^sub>d\\<^sub>d n'\"\n  shows \"\\<forall>as' a as''. tl as = as'@a#as'' \\<longrightarrow> \\<not> sourcenode a -{V}a#as''\\<rightarrow>\\<^sub>d\\<^sub>d n'\"\nproof -\n  from ddep have influence:\"n influences V in n' via as\"\n    by(auto elim!:DynPDG_edge.cases)\n  then obtain  a asx where as:\"as = a#asx\"\n    and notin:\"n \\<notin> set (sourcenodes asx)\"\n    by(auto dest:dyn_influence_source_notin_tl_edges simp:dyn_data_dependence_def)\n  from influence as\n  have imp:\"\\<forall>nx \\<in> set (sourcenodes asx). V \\<notin> Def nx\"\n    by(auto simp:dyn_data_dependence_def)\n  { fix as' a' as'' \n    assume eq:\"tl as = as'@a'#as''\"\n      and ddep':\"sourcenode a' -{V}a'#as''\\<rightarrow>\\<^sub>d\\<^sub>d n'\"\n    from eq as notin have noteq:\"sourcenode a' \\<noteq> n\" by(auto simp:sourcenodes_def)\n    from ddep' have \"V \\<in> Def (sourcenode a')\"\n      by(auto elim!:DynPDG_edge.cases simp:dyn_data_dependence_def)\n    with eq as noteq imp have False by(auto simp:sourcenodes_def) }\n  thus ?thesis by blast\nqed\n\n\n\nlemma no_ddep_same_state:\n  assumes path:\"n -as\\<rightarrow>* n'\" and Uses:\"V \\<in> Use n'\" and preds:\"preds (kinds as) s\"\n  and no_dep:\"\\<forall>as' a as''. as = as'@a#as'' \\<longrightarrow> \\<not> sourcenode a -{V}a#as''\\<rightarrow>\\<^sub>d\\<^sub>d n'\"\n  shows \"state_val (transfers (kinds as) s) V = state_val s V\"\nproof -\n  { fix n''\n    assume inset:\"n'' \\<in> set (sourcenodes as)\" and Defs:\"V \\<in> Def n''\"\n    hence \"\\<exists>nx \\<in> set (sourcenodes as). V \\<in> Def nx\" by auto\n    then obtain nx ns' ns'' where nodes:\"sourcenodes as = ns'@nx#ns''\"\n        and Defs':\"V \\<in> Def nx\" and notDef:\"\\<forall>nx' \\<in> set ns''. V \\<notin> Def nx'\"\n      by(fastforce elim!:rightmost_element_property)\n    from nodes obtain as' a as''\n      where as'':\"sourcenodes as'' = ns''\" and as:\"as=as'@a#as''\"\n      and source:\"sourcenode a = nx\"\n      by(fastforce elim:map_append_append_maps simp:sourcenodes_def)\n    from as path have path':\"sourcenode a -a#as''\\<rightarrow>* n'\"\n      by(fastforce dest:path_split_second)\n    from notDef as'' source\n    have \"\\<forall>n'' \\<in> set (sourcenodes as''). V \\<notin> Def n''\"\n      by(auto simp:sourcenodes_def)\n    with path' Defs' Uses source\n    have influence:\"nx influences V in n' via (a#as'')\"\n      by(simp add:dyn_data_dependence_def)\n    hence \"nx \\<notin> set (sourcenodes as'')\" by(rule dyn_influence_source_notin_tl_edges)\n    with influence source\n    have \"\\<exists>asx a'. sourcenode a' -{V}a'#asx\\<rightarrow>\\<^sub>d\\<^sub>d n' \\<and> sourcenode a' = nx \\<and>\n          (\\<exists>asx'. a#as'' = asx'@a'#asx)\"\n      by(fastforce intro:DynPDG_ddep_edge)\n    with nodes no_dep as have False by(auto simp:sourcenodes_def) }\n  hence \"\\<forall>n \\<in> set (sourcenodes as). V \\<notin> Def n\" by auto\n  with wf path preds show ?thesis by(fastforce intro:CFG_path_no_Def_equal)\nqed\n\n\nlemma DynPDG_ddep_edge_only_first_edge:\n  \"\\<lbrakk>n -{V}a#as\\<rightarrow>\\<^sub>d\\<^sub>d n'; preds (kinds (a#as)) s\\<rbrakk> \\<Longrightarrow> \n    state_val (transfers (kinds (a#as)) s) V = state_val (transfer (kind a) s) V\"\n  apply -\n  apply(erule DynPDG_edge.cases)\n  apply auto\n  apply(frule dyn_influence_Cons_source)\n  apply(frule dyn_influence_source_notin_tl_edges)\n  by(erule dyn_influence_only_first_edge)\n\n\nlemma Use_value_change_implies_DynPDG_ddep_edge:\n  assumes \"n -as\\<rightarrow>* n'\" and \"V \\<in> Use n'\" and \"preds (kinds as) s\" \n  and \"preds (kinds as) s'\" and \"state_val s V = state_val s' V\"\n  and \"state_val (transfers (kinds as) s) V \\<noteq> \n             state_val (transfers (kinds as) s') V\"\n  obtains as' a as'' where \"as = as'@a#as''\"\n  and \"sourcenode a -{V}a#as''\\<rightarrow>\\<^sub>d\\<^sub>d n'\"\n  and \"state_val (transfers (kinds as) s) V = \n       state_val (transfers (kinds (as'@[a])) s) V\"\n  and \"state_val (transfers (kinds as) s') V = \n       state_val (transfers (kinds (as'@[a])) s') V\"\nproof(atomize_elim)\n  show \"\\<exists>as' a as''. as = as'@a#as'' \\<and>\n                     sourcenode a -{V}a#as''\\<rightarrow>\\<^sub>d\\<^sub>d n' \\<and>\n             state_val (transfers (kinds as) s) V = \n             state_val (transfers (kinds (as'@[a])) s) V \\<and>\n             state_val (transfers (kinds as) s') V = \n             state_val (transfers (kinds (as'@[a])) s') V\"\n  proof(cases \"\\<forall>as' a as''. as = as'@a#as'' \\<longrightarrow>\n                 \\<not> sourcenode a -{V}a#as''\\<rightarrow>\\<^sub>d\\<^sub>d n'\")\n    case True\n    with \\<open>n -as\\<rightarrow>* n'\\<close> \\<open>V \\<in> Use n'\\<close> \\<open>preds (kinds as) s\\<close> \\<open>preds (kinds as) s'\\<close>\n    have \"state_val (transfers (kinds as) s) V = state_val s V\"\n      and \"state_val (transfers (kinds as) s') V = state_val s' V\"\n      by(auto intro:no_ddep_same_state)\n    with \\<open>state_val s V = state_val s' V\\<close> \n      \\<open>state_val (transfers (kinds as) s) V \\<noteq> state_val (transfers (kinds as) s') V\\<close>\n    show ?thesis by simp\n  next\n    case False\n    then obtain as' a as'' where [simp]:\"as = as'@a#as''\"\n      and \"sourcenode a -{V}a#as''\\<rightarrow>\\<^sub>d\\<^sub>d n'\" by auto\n    from \\<open>preds (kinds as) s\\<close> have \"preds (kinds (a#as'')) (transfers (kinds as') s)\"\n      by(simp add:kinds_def preds_split)\n    with \\<open>sourcenode a -{V}a#as''\\<rightarrow>\\<^sub>d\\<^sub>d n'\\<close> have all:\n      \"state_val (transfers (kinds (a#as'')) (transfers (kinds as') s)) V = \n       state_val (transfer (kind a) (transfers (kinds as') s)) V\"\n      by(auto dest!:DynPDG_ddep_edge_only_first_edge)\n    from \\<open>preds (kinds as) s'\\<close> \n    have \"preds (kinds (a#as'')) (transfers (kinds as') s')\"\n      by(simp add:kinds_def preds_split)\n    with \\<open>sourcenode a -{V}a#as''\\<rightarrow>\\<^sub>d\\<^sub>d n'\\<close> have all':\n      \"state_val (transfers (kinds (a#as'')) (transfers (kinds as') s')) V = \n       state_val (transfer (kind a) (transfers (kinds as') s')) V\"\n      by(auto dest!:DynPDG_ddep_edge_only_first_edge)\n    hence eq:\"\\<And>s. transfers (kinds as) s =\n      transfers (kinds (a#as'')) (transfers (kinds as') s)\"\n      by(simp add:transfers_split[THEN sym] kinds_def)\n    with all have \"state_val (transfers (kinds as) s) V = \n                   state_val (transfers (kinds (as'@[a])) s) V\"\n      by(simp add:transfers_split kinds_def)\n    moreover\n    from eq all' have \"state_val (transfers (kinds as) s') V = \n                       state_val (transfers (kinds (as'@[a])) s') V\"\n      by(simp add:transfers_split kinds_def)\n    ultimately show ?thesis using \\<open>sourcenode a -{V}a#as''\\<rightarrow>\\<^sub>d\\<^sub>d n'\\<close> by simp blast\n  qed\nqed\n\n\nend\n\n\nsubsection \\<open>Instantiate dynamic PDG\\<close>\n\nsubsubsection \\<open>Standard control dependence\\<close>\n\nlocale DynStandardControlDependencePDG =\n  Postdomination sourcenode targetnode kind valid_edge Entry Exit +\n  CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use state_val Exit\n  for sourcenode :: \"'edge \\<Rightarrow> 'node\" and targetnode :: \"'edge \\<Rightarrow> 'node\"\n  and kind :: \"'edge \\<Rightarrow> 'state edge_kind\" and valid_edge :: \"'edge \\<Rightarrow> bool\"\n  and Entry :: \"'node\" (\"'('_Entry'_')\") and Def :: \"'node \\<Rightarrow> 'var set\"\n  and Use :: \"'node \\<Rightarrow> 'var set\" and state_val :: \"'state \\<Rightarrow> 'var \\<Rightarrow> 'val\"\n  and Exit :: \"'node\" (\"'('_Exit'_')\")\n\nbegin\n\nlemma DynPDG_scd:\n  \"DynPDG sourcenode targetnode kind valid_edge (_Entry_) \n          Def Use state_val (_Exit_) dyn_standard_control_dependence\"\nproof(unfold_locales)\n  fix n n' as assume \"n controls\\<^sub>s n' via as\"\n  show \"n' \\<noteq> (_Exit_)\"\n  proof\n    assume \"n' = (_Exit_)\"\n    with \\<open>n controls\\<^sub>s n' via as\\<close> show False\n      by(fastforce intro:Exit_not_dyn_standard_control_dependent)\n  qed\nnext\n  fix n n' as assume \"n controls\\<^sub>s n' via as\"\n  thus \"n -as\\<rightarrow>* n' \\<and> as \\<noteq> []\"\n    by(fastforce simp:dyn_standard_control_dependence_def)\nqed\n\n\nend\n\nsubsubsection \\<open>Weak control dependence\\<close>\n\nlocale DynWeakControlDependencePDG = \n  StrongPostdomination sourcenode targetnode kind valid_edge Entry Exit +\n  CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use state_val Exit\n  for sourcenode :: \"'edge \\<Rightarrow> 'node\" and targetnode :: \"'edge \\<Rightarrow> 'node\"\n  and kind :: \"'edge \\<Rightarrow> 'state edge_kind\" and valid_edge :: \"'edge \\<Rightarrow> bool\"\n  and Entry :: \"'node\" (\"'('_Entry'_')\") and Def :: \"'node \\<Rightarrow> 'var set\"\n  and Use :: \"'node \\<Rightarrow> 'var set\" and state_val :: \"'state \\<Rightarrow> 'var \\<Rightarrow> 'val\"\n  and Exit :: \"'node\" (\"'('_Exit'_')\")\n\nbegin\n\n\n\n\nend\n\n\nsubsection \\<open>Data slice\\<close>\n\ndefinition (in CFG) empty_control_dependence :: \"'node \\<Rightarrow> 'node \\<Rightarrow> 'edge list \\<Rightarrow> bool\"\nwhere \"empty_control_dependence n n' as \\<equiv> False\"\n\nlemma (in CFGExit_wf) DynPDG_scd:\n  \"DynPDG sourcenode targetnode kind valid_edge (_Entry_)\n          Def Use state_val  (_Exit_) empty_control_dependence\"\nproof(unfold_locales)\n  fix n n' as assume \"empty_control_dependence n n' as\"\n  thus \"n' \\<noteq> (_Exit_)\" by(simp add:empty_control_dependence_def)\nnext\n  fix n n' as assume \"empty_control_dependence n n' as\"\n  thus \"n -as\\<rightarrow>* n' \\<and> as \\<noteq> []\" by(simp add:empty_control_dependence_def)\nqed\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Slicing/Dynamic/DynPDG.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6442250928250375, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.28702130606716453}}
{"text": "theory Seq_Parametric\n  imports \"../Gensyn\" \"../Gensyn_Descend\" \"../Mergeable/Mergeable\" \"../Mergeable/MergeableInstances\"\n          \"../Lifting/LiftUtils\" \"../Lifting/LiftInstances\"\n          \"../Lifting/AutoLift\" \"../Semantics/Gensyn_Sem_Small\"\n          \"../Hoare/CPS_Hoare\"\n\nbegin\n\n(* Variant of sequencing language with extensible syntax instead of skeleton *)\n\ndatatype syn =\n  Sseq\n  | Sskip\n\n\ntype_synonym 'xext state' = \"gensyn_skel * 'xext gs_result * dir\"\n\nfun getlast :: \"'a list \\<Rightarrow> 'a option\" where\n\"getlast [] = None\"\n| \"getlast [h] = Some h\"\n| \"getlast (h1#h2#t) = getlast (h2#t)\"\n\n(* to be strict, we need to check if the returned CP is a suffix of us. *)\n(* TODO: factor out the part about deferring to parent *)\n(*\n(case gensyn_cp_parent sk cp of\n      None \\<Rightarrow> (sk, GRDone, Up cp)\n      | Some cp' \\<Rightarrow> (sk, GRPath cp', Up xcp))\n*)\n(*\n  Seq will always \"catch-and-rethrow\" exceptions from below\n  \n*)\ndefinition seq_sem :: \"syn \\<Rightarrow> 'xext state' \\<Rightarrow> 'xext state'\" where\n\"seq_sem x st =\n(case st of (sk, GRPath cp, d) \\<Rightarrow>\n  (case x of\n    Sskip \\<Rightarrow> (case cp_parent cp of\n                    None \\<Rightarrow> (sk, GRDone, Up cp)\n                    | Some cp' \\<Rightarrow> (sk, GRPath cp', Up cp))\n    | Sseq \\<Rightarrow>\n        (case d of\n          Down \\<Rightarrow>\n            (case gensyn_get sk (cp @ [0]) of\n             None \\<Rightarrow> (sk, GRPath cp, Up cp)\n             | Some _ \\<Rightarrow> (sk, GRPath (cp @ [0]), Down))\n          | Up xcp \\<Rightarrow> \n             (case get_suffix cp xcp of\n              Some (xcph#xcpt) \\<Rightarrow> \n                           (case gensyn_get sk (cp @ [1+xcph]) of\n                              None \\<Rightarrow> (case cp_parent cp of\n                                        None \\<Rightarrow> (sk, GRDone, Up cp)\n                                        | Some cp' \\<Rightarrow> (sk, GRPath cp', Up cp))\n                              | Some _ \\<Rightarrow> (sk, GRPath (cp @ [1+xcph]), Down))\n                | _ \\<Rightarrow> (if cp = xcp \n                        \\<comment> \\<open>if our signal is not coming from a child, it should come from us,\n                            otherwise this is an error\\<close>\n                        then (case cp_parent cp of\n                               None \\<Rightarrow> (sk, GRDone, Up cp)\n                               | Some cp' \\<Rightarrow> (sk, GRPath cp', Up cp))\n                        else (sk, GRCrash, Up cp)))))\n  | _ \\<Rightarrow> st)\"\n\n\ntype_synonym 'xext state = \"gensyn_skel md_triv option *\n                      'xext gs_result md_triv option md_prio *\n                      dir md_triv option md_prio\"\n\n\ninstantiation gensyn :: (Bogus) Bogus begin\ndefinition gensyn_bogus :\n\"bogus = G bogus []\"\ninstance proof qed\nend\n\ninstantiation gs_result :: (_) Bogus begin\ndefinition gsx_result_bogus :\n\"bogus = GRUnhandled\"\ninstance proof qed\nend\n\ninstantiation dir :: Bogus begin\ndefinition dir_bogus :\n\"bogus = Down\"\ninstance proof qed\nend\n\ndefinition seq_path :: \"'xext state \\<Rightarrow> childpath option\" where\n\"seq_path s =\n  (case s of\n    (_, (mdp _ (Some (mdt (GRPath p)))), _) \\<Rightarrow> Some p\n    | _ \\<Rightarrow> None)\"\n\n(*\ndefinition seq_sem_l :: \" syn \\<Rightarrow> state \\<Rightarrow> state\" where\n\"seq_sem_l  =\n  l_map_s id\n    (prod_l (option_l (triv_l (id_l)))\n             (prod_l \n              (prio_l_inc (option_l (triv_l (id_l))))\n              (prio_l_inc (option_l (triv_l (id_l)))))) (seq_sem)\"\n*)\n\n\nterm \"(schem_lift\n    (SP NA (SP NB NC)) (SP (SO NA) (SP (SPRI (SO NB)) (SPRI (SO NC)))))\"\n\ndefinition seq_sem_l :: \"syn \\<Rightarrow> ('xext :: Bogus) state \\<Rightarrow> ('xext :: Bogus) state\" where\n\"seq_sem_l =\n  lift_map_s id\n  (schem_lift\n    (SP NA (SP NB NC)) (SP (SO NA) (SP (SPRI (SO NB)) (SPRI (SO NC)))))\n  seq_sem\"\n\ndefinition seq_gsem :: \"(syn, ('xext :: Bogus) state) g_sem\" where\n\"seq_gsem \\<equiv>\n  \\<lparr> gs_sem = seq_sem_l\n  , gs_getpath = seq_path \\<rparr>\"\n\n(* we will need to generalize this however *)\nlemma seq_hoare :\n  assumes H : \"\n\nend", "meta": {"author": "mmalvarez", "repo": "Gazelle", "sha": "0a80144107b3ec7487725bd88d658843beb6cb82", "save_path": "github-repos/isabelle/mmalvarez-Gazelle", "path": "github-repos/isabelle/mmalvarez-Gazelle/Gazelle-0a80144107b3ec7487725bd88d658843beb6cb82/Attic/Old_Examples/Seq_Parametric.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6442250928250375, "lm_q2_score": 0.44552953503957277, "lm_q1q2_score": 0.28702130606716453}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\n(*\n * This file contains theorems for dealing with a \"simply\" lifted\n * heap, where each byte of memory can be accessed as one (and only)\n * type.\n *\n * This is a simpler model of Tuch's \"lift_t\" model, where nested\n * struct fields cannot be directly accessed as pointers.\n *)\n\ntheory TypHeapSimple\nimports\n  \"../../lib/TypHeapLib\"\nbegin\n\n(*\n * Each address in the heap can contain one of three things:\n *\n *   - A type tag, which inidicates that this address is the first\n *     byte of an object;\n *\n *   - A footprint, which indicates that this address is a latter byte\n *     of an object;\n *\n *   - Nothing, which indicates that this address does not fall inside\n *     an object.\n *)\ndatatype heap_typ_contents =\n    HeapType typ_uinfo\n  | HeapFootprint\n  | HeapEmpty\n\n(*\n * Given a Tuch-style heap representation (where each memory location\n * contains a set of different types, representing nested field types)\n * calculate a single top-level type of the heap.\n *\n * We just want to commit to a single type for this heap location,\n * and nothing more.\n *)\ndefinition\n  heap_type_tag :: \"heap_typ_desc \\<Rightarrow> word32 \\<Rightarrow> heap_typ_contents\"\nwhere\n  \"heap_type_tag d a \\<equiv>\n     (if fst (d a) = False \\<or> (\\<forall>x. (snd (d a)) x = None) \\<or> (\\<forall>x. (snd (d a)) x \\<noteq> None) then\n       HeapEmpty\n     else\n       case (snd (d a)) (GREATEST x. snd (d a) x \\<noteq> None) of\n         Some (_, False) \\<Rightarrow> HeapFootprint\n       | Some (x, True) \\<Rightarrow> HeapType x\n       | None \\<Rightarrow> HeapEmpty)\"\n\n(*\n * Determine if the heap has a valid footprint for the given type at\n * the given address.\n *\n * A valid footprint means that the user has committed that the given\n * memory location will only be used for the given type.\n *\n * A \"simple\" footprint differs from the Tuch-style because we only\n * commit to a single type, and have no support for accessing nested\n * structures.\n *)\ndefinition\n  valid_simple_footprint :: \"heap_typ_desc \\<Rightarrow> word32 \\<Rightarrow> typ_uinfo \\<Rightarrow> bool\"\nwhere\n  \"valid_simple_footprint d x t \\<equiv>\n    heap_type_tag d x = HeapType t \\<and>\n      (\\<forall>y. y \\<in> {x + 1..+  (size_td t)- Suc 0} \\<longrightarrow> heap_type_tag d y = HeapFootprint)\"\n\nlemma valid_simple_footprintI:\n  \"\\<lbrakk> heap_type_tag d x = HeapType t; \\<And>y. y \\<in> {x + 1..+(size_td t) - Suc 0} \\<Longrightarrow> heap_type_tag d y = HeapFootprint \\<rbrakk>\n      \\<Longrightarrow> valid_simple_footprint d x t\"\n  by (clarsimp simp: valid_simple_footprint_def)\n\nlemma valid_simple_footprintD:\n  \"valid_simple_footprint d x t \\<Longrightarrow> heap_type_tag d x = HeapType t\"\n  by (simp add: valid_simple_footprint_def)\n\nlemma valid_simple_footprintD2:\n  \"\\<lbrakk> valid_simple_footprint d x t; y \\<in> {x + 1..+(size_td t) - Suc 0} \\<rbrakk> \\<Longrightarrow> heap_type_tag d y = HeapFootprint\"\n  by (simp add: valid_simple_footprint_def)\n\nlemma typ_slices_not_empty:\n    \"typ_slices (x::('a::{mem_type} itself)) \\<noteq> []\"\n  apply (clarsimp simp: typ_slices_def)\n  done\n\nlemma last_typ_slice_t:\n    \"(last (typ_slice_t t 0)) = (t, True)\"\n  apply (case_tac t)\n  apply clarsimp\n  done\n\nlemma if_eqI:\n \"\\<lbrakk> a \\<Longrightarrow> x = z; \\<not> a \\<Longrightarrow> y = z \\<rbrakk> \\<Longrightarrow> (if a then x else y) = z\"\n  by simp\n\nlemma heap_type_tag_ptr_retyp:\n    \"snd (s (ptr_val t)) = empty \\<Longrightarrow>\n        heap_type_tag (ptr_retyp (t :: 'a::mem_type ptr) s) (ptr_val t) = HeapType (typ_uinfo_t TYPE('a))\"\n  apply (unfold ptr_retyp_def heap_type_tag_def)\n  apply (subst htd_update_list_index, fastforce, fastforce)+\n  apply (rule if_eqI)\n   apply clarsimp\n   apply (erule disjE)\n    apply (erule_tac x=0 in allE)\n    apply clarsimp\n   apply (erule_tac x=\"length (typ_slice_t (typ_uinfo_t TYPE('a)) 0)\" in allE)\n   apply (clarsimp simp: list_map_eq)\n  apply (clarsimp simp: list_map_eq last_conv_nth [simplified, symmetric] last_typ_slice_t\n            split: option.splits if_split_asm prod.splits)\n  done\n\nlemma not_snd_last_typ_slice_t:\n    \"k \\<noteq> 0 \\<Longrightarrow> \\<not> snd (last (typ_slice_t z k))\"\n  by (case_tac z, clarsimp)\n\nlemma heap_type_tag_ptr_retyp_rest:\n    \"\\<lbrakk> snd (s (ptr_val t + k)) = empty; 0 < k; unat k < size_td (typ_uinfo_t TYPE('a)) \\<rbrakk> \\<Longrightarrow>\n        heap_type_tag (ptr_retyp (t :: 'a::mem_type ptr) s) (ptr_val t + k) = HeapFootprint\"\n  apply (unfold ptr_retyp_def heap_type_tag_def)\n  apply (subst htd_update_list_index, simp, clarsimp,\n      metis intvlI size_of_def word_unat.Rep_inverse)+\n  apply (rule if_eqI)\n   apply clarsimp\n   apply (erule disjE)\n    apply (erule_tac x=0 in allE)\n    apply (clarsimp simp: typ_slices_index size_of_def)\n   apply (erule_tac x=\"length (typ_slice_t (typ_uinfo_t TYPE('a)) (unat k))\" in allE)\n   apply (clarsimp simp: typ_slices_index size_of_def list_map_eq)\n  apply (clarsimp simp: list_map_eq last_conv_nth [simplified, symmetric] size_of_def\n      split: option.splits if_split_asm prod.splits bool.splits)\n   apply (metis surj_pair)\n  apply (subst (asm) (2) surjective_pairing)\n  apply (subst (asm) not_snd_last_typ_slice_t)\n   apply clarsimp\n   apply unat_arith\n  apply simp\n  done\n\nlemma typ_slices_addr_card [simp]:\n    \"length (typ_slices (x::('a::{mem_type} itself))) < addr_card\"\n  apply (clarsimp simp: typ_slices_def)\n  done\n\nlemma htd_update_list_same':\n  \"\\<lbrakk>0 < unat k; unat k \\<le> addr_card - length v\\<rbrakk> \\<Longrightarrow> htd_update_list (p + k) v h p = h p\"\n  apply (insert htd_update_list_same [where v=v and p=p and h=h and k=\"unat k\"])\n  apply clarsimp\n  done\n\nlemma unat_less_impl_less:\n    \"unat a < unat b \\<Longrightarrow> a < b\"\n  by unat_arith\n\nlemma valid_simple_footprint_ptr_retyp:\n    \"\\<lbrakk> \\<forall>k < size_td (typ_uinfo_t TYPE('a)). snd (s (ptr_val t + of_nat k)) = Map.empty;\n        1 \\<le> size_td (typ_uinfo_t TYPE('a));\n        size_td (typ_uinfo_t TYPE('a)) < addr_card \\<rbrakk>\n        \\<Longrightarrow> valid_simple_footprint (ptr_retyp (t :: 'a::mem_type ptr) s) (ptr_val t) (typ_uinfo_t TYPE('a))\"\n  apply (clarsimp simp: valid_simple_footprint_def)\n  apply (rule conjI)\n   apply (subst heap_type_tag_ptr_retyp)\n    apply (erule allE [where x=\"0\"])\n    apply clarsimp\n   apply clarsimp\n  apply (clarsimp simp: intvl_def)\n  apply (erule_tac x=\"k + 1\" in allE)\n  apply (erule impE)\n   apply (metis One_nat_def less_diff_conv)\n  apply (subst add.assoc, subst heap_type_tag_ptr_retyp_rest)\n     apply clarsimp\n    apply (case_tac \"1 + of_nat k = (0 :: word32)\")\n     apply (metis add.left_neutral intvlI intvl_Suc_nmem size_of_def)\n    apply unat_arith\n   apply clarsimp\n   apply (metis lt_size_of_unat_simps size_of_def Suc_eq_plus1 One_nat_def less_diff_conv of_nat_Suc)\n  apply simp\n  done\n\n(* Determine if the given pointer is valid in the given heap. *)\ndefinition\n  heap_ptr_valid :: \"heap_typ_desc \\<Rightarrow> 'a::c_type ptr \\<Rightarrow> bool\"\nwhere\n  \"heap_ptr_valid d p \\<equiv>\n      valid_simple_footprint d (ptr_val (p::'a ptr)) (typ_uinfo_t TYPE('a))\n        \\<and> c_guard p\"\n\n(*\n * Lift a heap from raw bytes and a heap description into\n * higher-level objects.\n *\n * This differs from Tuch's \"lift_t\" because we only support\n * simple lifting; that is, each byte in the heap may only\n * be accessed as a single type. Accessing struct fields by\n * their pointers is not supported.\n *)\ndefinition\n  simple_lift :: \"heap_raw_state \\<Rightarrow> ('a::c_type) ptr \\<Rightarrow> 'a option\"\nwhere\n  \"simple_lift s p = (\n     if (heap_ptr_valid (hrs_htd s) p) then\n       (Some (h_val (hrs_mem s) p))\n     else\n       None)\"\n\nlemma simple_lift_heap_ptr_valid:\n  \"simple_lift s p = Some x \\<Longrightarrow> heap_ptr_valid (hrs_htd s) p\"\n  apply (clarsimp simp: simple_lift_def split: if_split_asm)\n  done\n\nlemma simple_lift_c_guard:\n  \"simple_lift s p = Some x \\<Longrightarrow> c_guard p\"\n  apply (clarsimp simp: simple_lift_def heap_ptr_valid_def split: if_split_asm)\n  done\n\n(* Two valid footprints will either overlap completely or not at all. *)\nlemma valid_simple_footprint_neq:\n  assumes valid_p: \"valid_simple_footprint d p s\"\n      and valid_q: \"valid_simple_footprint d q t\"\n      and neq: \"p \\<noteq> q\"\n  shows \"p \\<notin> {q..+ (size_td t)}\"\nproof -\n  have heap_type_p: \"heap_type_tag d p = HeapType s\"\n    apply (metis valid_p valid_simple_footprint_def)\n    done\n\n  have heap_type_q: \"heap_type_tag d q = HeapType t\"\n    apply (metis valid_q valid_simple_footprint_def)\n    done\n\n  have heap_type_q_footprint:\n    \"\\<And>x. x \\<in> {(q + 1)..+(size_td t - Suc 0)} \\<Longrightarrow> heap_type_tag d x = HeapFootprint\"\n    apply (insert valid_q)\n    apply (simp add: valid_simple_footprint_def)\n    done\n\n  show ?thesis\n    using heap_type_q_footprint heap_type_p neq\n         intvl_neq_start heap_type_q\n    by (metis heap_typ_contents.simps(2))\nqed\n\n(* Two valid footprints with different types will never overlap. *)\nlemma valid_simple_footprint_type_neq:\n  \"\\<lbrakk> valid_simple_footprint d p s;\n     valid_simple_footprint d q t;\n     s \\<noteq> t \\<rbrakk> \\<Longrightarrow>\n   p \\<notin> {q..+ (size_td t)}\"\n  apply (subgoal_tac \"p \\<noteq> q\")\n   apply (rule valid_simple_footprint_neq, simp_all)[1]\n  apply (clarsimp simp: valid_simple_footprint_def)\n  done\n\nlemma valid_simple_footprint_neq_disjoint:\n  \"\\<lbrakk> valid_simple_footprint d p s; valid_simple_footprint d q t; p \\<noteq> q \\<rbrakk> \\<Longrightarrow>\n      {p..+(size_td s)} \\<inter> {q..+ (size_td t)} = {}\"\n  apply (rule ccontr)\n  apply (fastforce simp: valid_simple_footprint_neq dest!: intvl_inter)\n  done\n\nlemma valid_simple_footprint_type_neq_disjoint:\n  \"\\<lbrakk> valid_simple_footprint d p s;\n     valid_simple_footprint d q t;\n     s \\<noteq> t \\<rbrakk> \\<Longrightarrow>\n   {p..+(size_td s)} \\<inter> {q..+ (size_td t)} = {}\"\n  apply (subgoal_tac \"p \\<noteq> q\")\n   apply (rule valid_simple_footprint_neq_disjoint, simp_all)[1]\n  apply (clarsimp simp: valid_simple_footprint_def)\n  done\n\nlemma heap_ptr_valid_neq_disjoint:\n  \"\\<lbrakk> heap_ptr_valid d (p::'a::c_type ptr);\n     heap_ptr_valid d (q::'b::c_type ptr);\n     ptr_val p \\<noteq> ptr_val q \\<rbrakk> \\<Longrightarrow>\n   {ptr_val p..+size_of TYPE('a)} \\<inter>\n          {ptr_val q..+size_of TYPE('b)} = {}\"\n  apply (clarsimp simp only: size_of_tag [symmetric])\n  apply (rule valid_simple_footprint_neq_disjoint [where d=\"d\"])\n    apply (clarsimp simp: heap_ptr_valid_def)\n   apply (clarsimp simp: heap_ptr_valid_def)\n  apply simp\n  done\n\nlemma heap_ptr_valid_type_neq_disjoint:\n  \"\\<lbrakk> heap_ptr_valid d (p::'a::c_type ptr);\n     heap_ptr_valid d (q::'b::c_type ptr);\n     typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('b) \\<rbrakk> \\<Longrightarrow>\n   {ptr_val p..+size_of TYPE('a)} \\<inter>\n          {ptr_val q..+size_of TYPE('b)} = {}\"\n  apply (subgoal_tac \"ptr_val p \\<noteq> ptr_val q\")\n   apply (rule heap_ptr_valid_neq_disjoint, auto)[1]\n  apply (clarsimp simp: heap_ptr_valid_def valid_simple_footprint_def)\n  done\n\n(* If we update one pointer in the heap, other valid pointers will be unaffected. *)\nlemma heap_ptr_valid_heap_update_other:\n  assumes val_p: \"heap_ptr_valid d (p::'a::mem_type ptr)\"\n      and val_q: \"heap_ptr_valid d (q::'b::c_type ptr)\"\n      and neq: \"ptr_val p \\<noteq> ptr_val q\"\n  shows \"h_val (heap_update p v h) q = h_val h q\"\n  apply (clarsimp simp: h_val_def heap_update_def)\n  apply (subst heap_list_update_disjoint_same)\n   apply simp\n   apply (rule heap_ptr_valid_neq_disjoint [OF val_p val_q neq])\n  apply simp\n  done\n\n(* If we update one type in the heap, other types will be unaffected. *)\nlemma heap_ptr_valid_heap_update_other_typ:\n  assumes val_p: \"heap_ptr_valid d (p::'a::mem_type ptr)\"\n      and val_q: \"heap_ptr_valid d (q::'b::c_type ptr)\"\n      and neq: \"typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('b)\"\n  shows \"h_val (heap_update p v h) q = h_val h q\"\n  apply (clarsimp simp: h_val_def heap_update_def)\n  apply (subst heap_list_update_disjoint_same)\n   apply simp\n   apply (rule heap_ptr_valid_type_neq_disjoint [OF val_p val_q neq])\n  apply simp\n  done\n\n(* Updating the raw heap is equivalent to updating the lifted heap. *)\nlemma simple_lift_heap_update:\n  \"\\<lbrakk> heap_ptr_valid (hrs_htd h) p \\<rbrakk> \\<Longrightarrow>\n      simple_lift (hrs_mem_update (heap_update p v) h)\n          = (simple_lift h)(p := Some (v::'a::mem_type))\"\n  apply (rule ext)\n  apply (clarsimp simp: simple_lift_def hrs_mem_update h_val_heap_update)\n  apply (fastforce simp: heap_ptr_valid_heap_update_other ptr_val_inj)\n  done\n\n(* Updating the raw heap of one type doesn't affect the lifted heap of other types. *)\nlemma simple_lift_heap_update_other:\n  \"\\<lbrakk> heap_ptr_valid (hrs_htd d) (p::'b::mem_type ptr);\n     typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('b) \\<rbrakk> \\<Longrightarrow>\n   simple_lift (hrs_mem_update (heap_update p v) d) = ((simple_lift d)::'a::c_type typ_heap)\"\n  apply (rule ext)+\n  apply (clarsimp simp: simple_lift_def h_val_heap_update hrs_mem_update)\n  apply (auto intro: heap_ptr_valid_heap_update_other_typ)\n  done\n\nlemma h_val_simple_lift:\n  \"simple_lift h p = Some v \\<Longrightarrow> h_val (hrs_mem h) p = v\"\n  apply (clarsimp simp: simple_lift_def split: if_split_asm)\n  done\n\nlemma h_val_field_simple_lift:\n  \"\\<lbrakk> simple_lift h (pa :: 'a ptr) = Some (v::'a::mem_type);\n     \\<exists>t. field_ti TYPE('a) f = Some t;\n     export_uinfo (the (field_ti TYPE('a) f)) = export_uinfo (typ_info_t TYPE('b :: mem_type)) \\<rbrakk> \\<Longrightarrow>\n   h_val (hrs_mem h) (Ptr &(pa\\<rightarrow>f) :: 'b :: mem_type ptr) = from_bytes (access_ti\\<^sub>0 (the (field_ti TYPE('a) f)) v)\"\n  apply (clarsimp simp: simple_lift_def split: if_split_asm)\n  apply (clarsimp simp: h_val_field_from_bytes)\n  done\n\nlemma simple_lift_heap_update':\n  \"simple_lift h p = Some v' \\<Longrightarrow>\n      simple_lift (hrs_mem_update (heap_update (p::('a::{mem_type}) ptr) v) h)\n          = (simple_lift h)(p := Some v)\"\n  apply (rule simple_lift_heap_update)\n  apply (erule simple_lift_heap_ptr_valid)\n  done\n\nlemma simple_lift_hrs_mem_update_None [simp]:\n    \"(simple_lift (hrs_mem_update a hp) x = None) = (simple_lift hp x = None)\"\n  apply (clarsimp simp: simple_lift_def)\n  done\n\nlemma simple_lift_data_eq:\n   \"\\<lbrakk> h_val (hrs_mem h) p = h_val (hrs_mem h') p';\n     heap_ptr_valid (hrs_htd h) p = heap_ptr_valid (hrs_htd h') p' \\<rbrakk> \\<Longrightarrow>\n    simple_lift h p = simple_lift h' p'\"\n  apply (clarsimp simp: simple_lift_def)\n  done\n\nlemma h_val_heap_update_disjoint:\n  \"\\<lbrakk> {ptr_val p ..+ size_of TYPE('a::c_type)}\n        \\<inter> {ptr_val q ..+ size_of TYPE('b::mem_type)} = {} \\<rbrakk> \\<Longrightarrow>\n      h_val (heap_update (q :: 'b ptr) r h) (p :: 'a ptr) = h_val h p\"\n  apply (clarsimp simp: h_val_def)\n  apply (clarsimp simp: heap_update_def)\n  apply (subst heap_list_update_disjoint_same)\n   apply clarsimp\n   apply blast\n   apply clarsimp\n  done\n\nlemma update_ti_t_valid_size:\n  \"size_of TYPE('b) = size_td t \\<Longrightarrow>\n   update_ti_t t (to_bytes_p (val::'b::mem_type)) obj = update_ti t (to_bytes_p val) obj\"\n  apply (clarsimp simp: update_ti_t_def to_bytes_p_def)\n  done\n\nlemma h_val_field_from_bytes':\n  \"\\<lbrakk> field_ti TYPE('a::{mem_type}) f = Some t;\n     export_uinfo t = export_uinfo (typ_info_t TYPE('b::{mem_type})) \\<rbrakk> \\<Longrightarrow>\n    h_val h (Ptr &(pa\\<rightarrow>f) :: 'b ptr) = from_bytes (access_ti\\<^sub>0 t (h_val h pa))\"\n  apply (insert h_val_field_from_bytes [where f=f and pa=pa and t=t and h=\"(h,x)\" and 'a='a and 'b='b])\n  apply (clarsimp simp: hrs_mem_def)\n  done\n\nlemma simple_lift_super_field_update_lookup:\n  fixes dummy :: \"'b :: mem_type\"\n  assumes \"field_lookup (typ_info_t TYPE('b::mem_type)) f 0 = Some (s,n)\"\n    and \"typ_uinfo_t TYPE('a) = export_uinfo s\"\n    and \"simple_lift h p = Some v'\"\n  shows \"(super_field_update_t (Ptr (&(p\\<rightarrow>f))) (v::'a::mem_type) ((simple_lift h)::'b ptr \\<Rightarrow> 'b option)) =\n          ((simple_lift h)(p \\<mapsto> field_update (field_desc s) (to_bytes_p v) v'))\"\nproof -\n  from assms have [simp]: \"unat (of_nat n :: 32 word) = n\"\n     apply (subst unat_of_nat)\n     apply (subst mod_less)\n      apply (drule td_set_field_lookupD)+\n      apply (drule td_set_offset_size)+\n      apply (subst len_of_addr_card)\n      apply (subst (asm) size_of_def [symmetric, where t=\"TYPE('b)\"])+\n      apply (subgoal_tac \"size_of TYPE('b) < addr_card\")\n       apply arith\n      apply simp\n     apply simp\n     done\n  from assms show ?thesis\n    apply (clarsimp simp: super_field_update_t_def)\n    apply (rule ext)\n    apply (clarsimp simp: field_lvalue_def split: option.splits)\n    apply (safe, simp_all)\n       apply (frule_tac v=v and v'=v' in update_field_update)\n       apply (clarsimp simp: field_of_t_def field_of_def typ_uinfo_t_def)\n       apply (frule_tac m=0 in field_names_SomeD2)\n        apply simp\n       apply clarsimp\n       apply (simp add: field_typ_def field_typ_untyped_def)\n       apply (frule field_lookup_export_uinfo_Some)\n       apply (frule_tac s=k in field_lookup_export_uinfo_Some)\n       apply simp\n       apply (drule (1) field_lookup_inject)\n        apply (subst typ_uinfo_t_def [symmetric, where t=\"TYPE('b)\"])\n        apply simp\n       apply simp\n      apply (drule field_of_t_mem)+\n      apply (case_tac h)\n      apply (clarsimp simp: simple_lift_def split: if_split_asm)\n      apply (drule (1) heap_ptr_valid_neq_disjoint)\n       apply simp\n      apply fast\n     apply (clarsimp simp: field_of_t_def field_of_def)\n     apply (subst (asm) td_set_field_lookup)\n      apply simp\n     apply simp\n     apply (frule field_lookup_export_uinfo_Some)\n     apply (simp add: typ_uinfo_t_def)\n    apply (clarsimp simp: field_of_t_def field_of_def)\n    apply (subst (asm) td_set_field_lookup)\n     apply simp\n    apply simp\n    apply (frule field_lookup_export_uinfo_Some)\n    apply (simp add: typ_uinfo_t_def)\n    done\nqed\n\nlemma field_offset_addr_card:\n    \"\\<exists>x. field_lookup (typ_info_t TYPE('a::mem_type)) f 0 = Some x \\<Longrightarrow> field_offset TYPE('a) f < addr_card\"\n  apply (clarsimp simp: field_offset_def field_offset_untyped_def typ_uinfo_t_def)\n  apply (subst field_lookup_export_uinfo_Some)\n   apply assumption\n  apply (frule td_set_field_lookupD)\n  apply (drule td_set_offset_size)\n  apply (insert max_size [where ?'a=\"'a\"])\n  apply (clarsimp simp: size_of_def)\n  done\n\nlemma unat_of_nat_field_offset:\n  \"\\<exists>x. field_lookup (typ_info_t TYPE('a::mem_type)) f 0 = Some x \\<Longrightarrow>\n      unat (of_nat (field_offset TYPE('a) f)  :: word32 ) = field_offset TYPE('a) f\"\n  apply (subst word_unat.Abs_inverse)\n   apply (clarsimp simp: unats_def)\n   apply (insert field_offset_addr_card [where f=f and ?'a=\"'a\"])[1]\n   apply (fastforce simp: addr_card)\n  apply simp\n  done\n\nlemma field_of_t_field_lookup:\n  assumes a: \"field_lookup (typ_info_t TYPE('a::mem_type)) f 0 = Some (s, n)\"\n  assumes b: \"export_uinfo s = typ_uinfo_t TYPE('b::mem_type)\"\n  assumes n: \"n = field_offset TYPE('a) f\"\n  shows \"field_of_t (Ptr &(ptr\\<rightarrow>f) :: ('b ptr)) (ptr :: 'a ptr)\"\n  apply (clarsimp simp del: field_lookup_offset_eq\n      simp: field_of_t_def field_of_def)\n  apply (subst td_set_field_lookup)\n   apply (rule wf_desc_typ_tag)\n  apply (rule exI [where x=f])\n  using a[simplified n] b\n  apply (clarsimp simp: typ_uinfo_t_def)\n  apply (subst field_lookup_export_uinfo_Some)\n   apply assumption\n  apply (clarsimp simp del: field_lookup_offset_eq\n      simp: field_lvalue_def unat_of_nat_field_offset)\n  done\n\nlemma simple_lift_field_update':\n  fixes val :: \"'b :: mem_type\" and ptr :: \"'a :: mem_type ptr\"\n  assumes   fl: \"field_lookup (typ_info_t TYPE('a)) f 0 =\n                     Some (adjust_ti (typ_info_t TYPE('b)) xf xfu, n)\"\n  and   xf_xfu: \"fg_cons xf xfu\"\n  and       cl: \"simple_lift hp ptr = Some z\"\n  shows \"(simple_lift (hrs_mem_update (heap_update (Ptr &(ptr\\<rightarrow>f)) val) hp)) =\n                simple_lift hp(ptr \\<mapsto> xfu val z)\"\n    (is \"?LHS = ?RHS\")\nproof (rule ext)\n  fix p\n\n  have eui: \"typ_uinfo_t TYPE('b) =\n       export_uinfo (adjust_ti (typ_info_t TYPE('b)) xf xfu)\"\n    using xf_xfu\n    apply (subst export_tag_adjust_ti2 [OF _ wf_lf wf_desc])\n    apply (simp add: fg_cons_def )\n    apply (rule meta_eq_to_obj_eq [OF typ_uinfo_t_def])\n    done\n\n  have n_is_field_offset: \"n = field_offset TYPE('a) f\"\n    apply (insert field_lookup_offset_eq [OF fl])\n    apply (clarsimp)\n    done\n\n  have equal_case: \"?LHS ptr = ?RHS ptr\"\n    apply (insert cl)\n    apply (clarsimp simp: simple_lift_def split: if_split_asm)\n    apply (clarsimp simp: hrs_mem_update)\n    apply (subst h_val_super_update_bs)\n     apply (rule field_of_t_field_lookup [OF fl])\n      apply (clarsimp simp: eui)\n     apply (clarsimp simp: n_is_field_offset)\n    apply clarsimp\n    apply (unfold from_bytes_def)\n    apply (subst fi_fu_consistentD [where f=f and s=\"adjust_ti (typ_info_t TYPE('b)) xf xfu\"])\n        apply (clarsimp simp: fl)\n        apply (clarsimp simp: n_is_field_offset field_lvalue_def)\n        apply (metis unat_of_nat_field_offset fl)\n       apply clarsimp\n      apply (clarsimp simp: size_of_def)\n     apply (clarsimp simp: size_of_def)\n    apply clarsimp\n    apply (subst update_ti_s_from_bytes)\n     apply clarsimp\n    apply (subst update_ti_adjust_ti)\n     apply (rule xf_xfu)\n    apply (subst update_ti_s_from_bytes)\n     apply clarsimp\n    apply clarsimp\n    apply (clarsimp simp: h_val_def)\n    done\n\n  show \"?LHS p = ?RHS p\"\n    apply (case_tac \"p = ptr\")\n     apply (erule ssubst)\n     apply (rule equal_case)\n    apply (insert cl)\n    apply (clarsimp simp: simple_lift_def hrs_mem_update split: if_split_asm)\n    apply (rule h_val_heap_update_disjoint)\n    apply (insert field_tag_sub [OF fl, where p=ptr])\n    apply (clarsimp simp: size_of_def)\n    apply (clarsimp simp: heap_ptr_valid_def)\n    apply (frule (1) valid_simple_footprint_neq_disjoint, fastforce)\n    apply clarsimp\n    apply blast\n    done\nqed\n\nlemma simple_lift_field_update:\n  fixes val :: \"'b :: mem_type\" and ptr :: \"'a :: mem_type ptr\"\n  assumes   fl: \"field_ti TYPE('a) f =\n                     Some (adjust_ti (typ_info_t TYPE('b)) xf (xfu o (\\<lambda>x _. x)))\"\n  and   xf_xfu: \"fg_cons xf (xfu o (\\<lambda>x _. x))\"\n  and       cl: \"simple_lift hp ptr = Some z\"\n  shows \"(simple_lift (hrs_mem_update (heap_update (Ptr &(ptr\\<rightarrow>f)) val) hp)) =\n                simple_lift hp(ptr \\<mapsto> xfu (\\<lambda>_. val) z)\"\n    (is \"?LHS = ?RHS\")\n  apply (insert fl [unfolded field_ti_def])\n  apply (clarsimp split: option.splits)\n  apply (subst simple_lift_field_update' [where xf=xf and xfu=\"xfu o (\\<lambda>x _. x)\" and z=z])\n     apply (clarsimp simp: o_def split: option.splits)\n     apply (rule refl)\n    apply (rule xf_xfu)\n   apply (rule cl)\n  apply clarsimp\n  done\n\nlemma simple_heap_diff_types_impl_diff_ptrs:\n  \"\\<lbrakk> heap_ptr_valid h (p::('a::c_type) ptr);\n     heap_ptr_valid h (q::('b::c_type) ptr);\n     typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('b) \\<rbrakk> \\<Longrightarrow>\n   ptr_val p \\<noteq> ptr_val q\"\n  apply (clarsimp simp: heap_ptr_valid_def)\n  apply (clarsimp simp: valid_simple_footprint_def)\n  done\n\nlemma h_val_update_regions_disjoint:\n  \"\\<lbrakk> { ptr_val p ..+ size_of TYPE('a) } \\<inter> { ptr_val x ..+ size_of TYPE('b)} = {} \\<rbrakk> \\<Longrightarrow>\n        h_val (heap_update p (v::('a::mem_type)) h) x = h_val h (x::('b::c_type) ptr)\"\n  apply (clarsimp simp: heap_update_def)\n  apply (clarsimp simp: h_val_def)\n  apply (subst heap_list_update_disjoint_same)\n   apply clarsimp\n  apply clarsimp\n  done\n\nlemma simple_lift_field_update_t:\n  fixes    val :: \"'b :: mem_type\" and ptr :: \"'a :: mem_type ptr\"\n  assumes  fl: \"field_ti TYPE('a) f = Some t\"\n  and      diff: \"typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('c :: c_type)\"\n  and      eu: \"export_uinfo t = export_uinfo (typ_info_t TYPE('b))\"\n  and      cl: \"simple_lift hp ptr = Some z\"\n  shows \"((simple_lift (hrs_mem_update (heap_update (Ptr &(ptr\\<rightarrow>f)) val) hp)) :: 'c ptr \\<Rightarrow> 'c option) =\n             simple_lift hp\"\n  apply (rule ext)\n  apply (case_tac \"simple_lift hp x\")\n   apply clarsimp\n  apply (case_tac \"ptr_val x = ptr_val ptr\")\n   apply clarsimp\n   apply (clarsimp simp: simple_lift_def hrs_mem_update split: if_split_asm)\n   apply (cut_tac simple_lift_heap_ptr_valid [OF cl])\n   apply (drule (1) simple_heap_diff_types_impl_diff_ptrs [OF _ _ diff])\n   apply simp\n  apply (clarsimp simp: simple_lift_def hrs_mem_update split: if_split_asm)\n  apply (rule field_ti_field_lookupE [OF fl])\n  apply (frule_tac p=ptr in field_tag_sub)\n  apply (clarsimp simp: h_val_def heap_update_def)\n  apply (subst heap_list_update_disjoint_same)\n   apply clarsimp\n   apply (cut_tac simple_lift_heap_ptr_valid [OF cl])\n   apply (drule (2) heap_ptr_valid_neq_disjoint)\n   apply (clarsimp simp: export_size_of [unfolded typ_uinfo_t_def, OF eu])\n   apply blast\n  apply simp\n  done\n\nlemma simple_lift_heap_update_other':\n  \"\\<lbrakk> simple_lift h (p::'b::mem_type ptr) = Some v';\n     typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('b) \\<rbrakk> \\<Longrightarrow>\n   simple_lift (hrs_mem_update (heap_update p v) h) = ((simple_lift h)::'a::c_type typ_heap)\"\n  apply (rule simple_lift_heap_update_other)\n   apply (erule simple_lift_heap_ptr_valid)\n  apply simp\n  done\n\n(* If you update bytes inside an object of one type, it won't affect\n * heaps of other types. *)\nlemma simple_lift_heap_update_bytes_in_other:\n  \"\\<lbrakk> simple_lift h (p::'b::mem_type ptr) = Some v';\n     typ_uinfo_t TYPE('b) \\<noteq> typ_uinfo_t TYPE('c);\n     { ptr_val q ..+ size_of TYPE('a)} \\<subseteq> {ptr_val p  ..+ size_of TYPE('b) }  \\<rbrakk> \\<Longrightarrow>\n   simple_lift (hrs_mem_update (heap_update (q::'a::mem_type ptr) v) h) = ((simple_lift h)::'c::mem_type typ_heap)\"\n  apply (rule ext)\n  apply (clarsimp simp: simple_lift_def split: if_split_asm)\n  apply (drule (1) heap_ptr_valid_type_neq_disjoint, simp)\n  apply (clarsimp simp: hrs_mem_update)\n  apply (rule h_val_heap_update_disjoint)\n  apply blast\n  done\n\nlemma typ_name_neq:\n    \"typ_name (export_uinfo (typ_info_t TYPE('a::c_type)))\n        \\<noteq> typ_name (export_uinfo (typ_info_t TYPE('b::c_type)))\n    \\<Longrightarrow> typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('b)\"\n  apply (metis typ_uinfo_t_def)\n  done\n\nlemma of_nat_mod_div_decomp:\n  \"of_nat k\n        = of_nat (k div size_of TYPE('b)) * of_nat (size_of TYPE('b::mem_type)) +\n              of_nat (k mod size_of TYPE('b))\"\n  by (metis mod_div_decomp of_nat_add of_nat_mult)\n\nlemma c_guard_array_c_guard:\n  \"\\<lbrakk> \\<And>x. x < CARD('a) \\<Longrightarrow> c_guard (ptr_coerce p +\\<^sub>p int x :: 'b ptr) \\<rbrakk> \\<Longrightarrow> c_guard ( p :: ('b :: mem_type, 'a :: finite) array ptr)\"\n  apply atomize\n  apply (clarsimp simp: c_guard_def)\n  apply (rule conjI)\n   apply (drule_tac x=0 in spec)\n   apply (clarsimp simp: ptr_aligned_def align_of_def align_td_array)\n  apply (simp add: c_null_guard_def)\n  apply (clarsimp simp: intvl_def)\n  apply (drule_tac x=\"k div size_of TYPE('b)\" in spec)\n  apply (erule impE)\n   apply (metis (full_types) less_nat_zero_code mult_is_0 neq0_conv td_gal_lt)\n  apply clarsimp\n  apply (drule_tac x=\"k mod size_of TYPE('b)\" in spec)\n  apply (clarsimp simp: CTypesDefs.ptr_add_def)\n  apply (subst (asm) add.assoc)\n  apply (subst (asm) of_nat_mod_div_decomp [symmetric])\n  apply clarsimp\n  done\n\nlemma heap_list_update_list':\n  \"\\<lbrakk> n + x \\<le> length v; length v < addr_card; q = (p + of_nat x) \\<rbrakk> \\<Longrightarrow>\n      heap_list (heap_update_list p v h) n q = take n (drop x v)\"\n  by (metis heap_list_update_list)\n\nlemma outside_intvl_range:\n    \"p \\<notin> {a ..+ b} \\<Longrightarrow> p < a \\<or> p \\<ge> a + of_nat b\"\n  apply (clarsimp simp: intvl_def not_le not_less)\n  apply (drule_tac x=\"unat (p-a)\" in spec)\n  apply clarsimp\n  apply (metis add_diff_cancel2 le_less_linear le_unat_uoi\n      mpl_lem not_add_less2 unat_mono word_less_minus_mono_left)\n  done\n\nlemma first_in_intvl:\n  \"b \\<noteq> 0 \\<Longrightarrow> a \\<in> {a ..+ b}\"\n  by (force simp: intvl_def)\n\nlemma zero_not_in_intvl_no_overflow:\n  \"0 \\<notin> {a :: 'a::len word ..+ b} \\<Longrightarrow> unat a + b \\<le> 2 ^ len_of TYPE('a)\"\n  apply (rule ccontr)\n  apply (simp add: intvl_def not_le)\n  apply (drule_tac x=\"2 ^ len_of TYPE('a) - unat a\" in spec)\n  apply (clarsimp simp: not_less)\n  apply (erule disjE)\n  apply (metis (erased, hide_lams) diff_add_inverse less_imp_add_positive of_nat_2p of_nat_add\n           unat_lt2p word_neq_0_conv word_unat.Rep_inverse)\n  apply (metis le_add_diff_inverse le_antisym le_diff_conv le_refl\n           less_imp_le_nat add.commute not_add_less1 unat_lt2p)\n  done\n\nlemma intvl_split:\n  \"\\<lbrakk> n \\<ge> a \\<rbrakk> \\<Longrightarrow> { p :: ('a :: len) word ..+ n } = { p ..+ a } \\<union> { p + of_nat a ..+ (n - a)}\"\n  apply (rule set_eqI, rule iffI)\n   apply (clarsimp simp: intvl_def not_less)\n   apply (rule_tac x=k in exI)\n   apply clarsimp\n   apply (rule classical)\n   apply (drule_tac x=\"k - a\" in spec)\n   apply (clarsimp simp: not_less)\n   apply (metis diff_less_mono not_less)\n  apply (clarsimp simp: intvl_def not_less)\n  apply (rule_tac x=\"unat (x - p)\" in exI)\n  apply clarsimp\n  apply (erule disjE)\n   apply clarsimp\n   apply (metis le_unat_uoi less_or_eq_imp_le not_less order_trans)\n  apply clarsimp\n  apply (metis le_def le_eq_less_or_eq le_unat_uoi less_diff_conv\n    add.commute of_nat_add)\n  done\n\nlemma heap_ptr_valid_range_not_NULL:\n  \"heap_ptr_valid htd (p :: ('a :: c_type) ptr)\n      \\<Longrightarrow> 0 \\<notin> {ptr_val p ..+ size_of TYPE('a)}\"\n  apply (clarsimp simp: heap_ptr_valid_def)\n  apply (metis c_guard_def c_null_guard_def)\n  done\n\nlemma heap_ptr_valid_last_byte_no_overflow:\n  \"heap_ptr_valid htd (p :: ('a :: c_type) ptr)\n      \\<Longrightarrow> unat (ptr_val p) + size_of TYPE('a) \\<le> 2 ^ len_of TYPE(32)\"\n  by (metis c_guard_def c_null_guard_def heap_ptr_valid_def\n        zero_not_in_intvl_no_overflow)\n\nlemma heap_ptr_valid_intersect_array:\n  \"\\<lbrakk> \\<forall>j < n. heap_ptr_valid htd (p +\\<^sub>p int j);\n        heap_ptr_valid htd (q :: ('a :: c_type) ptr) \\<rbrakk>\n         \\<Longrightarrow> (\\<exists>m < n. q = (p +\\<^sub>p int m))\n    \\<or> ({ptr_val p ..+ size_of TYPE ('a) * n} \\<inter> {ptr_val q ..+ size_of TYPE ('a :: c_type)} = {})\"\n  apply (induct n)\n   apply clarsimp\n  apply atomize\n  apply simp\n  apply (case_tac \"n = 0\")\n   apply clarsimp\n   apply (metis heap_ptr_valid_neq_disjoint ptr_val_inj)\n  apply (erule disjE)\n   apply (metis less_Suc_eq)\n  apply (case_tac \"q = p +\\<^sub>p int n\")\n   apply force\n  apply (frule_tac x=n in spec)\n  apply (erule impE, simp)\n  apply (drule (1) heap_ptr_valid_neq_disjoint)\n  apply simp\n  apply (simp add: CTypesDefs.ptr_add_def)\n  apply (rule disjI2)\n  apply (cut_tac a=\" of_nat n * of_nat (size_of TYPE('a))\"\n      and p=\"ptr_val p\" and n=\"n * size_of TYPE('a) + size_of TYPE('a)\" in intvl_split)\n   apply clarsimp\n  apply (clarsimp simp: field_simps Int_Un_distrib2)\n  apply (metis IntI emptyE intvl_empty intvl_inter intvl_self neq0_conv)\n  done\n\n(* Simplification rules for dealing with \"lift_simple\". *)\n\nlemmas simple_lift_simps =\n  typ_name_neq\n  simple_lift_c_guard\n  h_val_simple_lift\n  simple_lift_heap_update'\n  simple_lift_heap_update_other'\n  c_guard_field\n  h_val_field_simple_lift\n  simple_lift_field_update\n  simple_lift_field_update_t\n  c_guard_array_field\n  nat_to_bin_string_simps\n\n(* Old name for the above simpset. *)\nlemmas typ_simple_heap_simps = simple_lift_simps\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/l4v/tools/autocorres/TypHeapSimple.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6224593312018546, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.28696419612357715}}
{"text": "theory DYNAMIC_Post_ISSUER\n  imports\n    \"Post_Observation_Setup_ISSUER\"\n    DYNAMIC_Post_Value_Setup_ISSUER\n    \"Bounded_Deducibility_Security.Compositional_Reasoning\"\nbegin\n\n\nsubsubsection \\<open>Issuer declassification bound\\<close>\n\ntext \\<open>\\label{sec:dynamic-post-issuer}\nWe verify that a group of users of some node \\<open>i\\<close>,\nallowed to take normal actions to the system and observe their outputs\n\\emph{and additionally allowed to observe communication},\ncan learn nothing about the updates to a post located at node \\<open>i\\<close>\nand the sends of that post to other nodes beyond:\n\n(1) the updates that occur during the times when one of the following holds,\nand the \\<^emph>\\<open>last\\<close> update \\<^emph>\\<open>before\\<close> one of the following holds\n(because, for example, observers can see the current version of the post when it is made public):\n\\begin{itemize}\n\\item either a user in the group is the post's owner or the administrator\n\\item or a user in the group is a friend of the owner\n\\item or the group has at least one registered user and the post is marked \"public\"\n\\end{itemize}\n\n(2) the presence of the sends (i.e., the number of the sending actions)\n\n(3) the public knowledge that what is being sent is always the last version (modeled as\nthe correlation predicate)\n\nSee \\<^cite>\\<open>\\<open>Appendix C\\<close> in \"cosmedis-SandP2017\"\\<close> for more details. This is the dynamic-trigger\n(i.e., trigger-incorporating inductive bound) version of the property proved in\nSection~\\ref{sec:post-issuer}.\nFor a discussion of this ``while-or-last-before'' style of formalizing bounds,\nsee \\<^cite>\\<open>\\<open>Section 3.4\\<close> in \"cosmed-jar2018\"\\<close> about the the corresponding property of CoSMed.\n\\<close>\n\ncontext Post\nbegin\n\nfun T :: \"(state,act,out) trans \\<Rightarrow> bool\" where \"T _ = False\"\n\ninductive BC :: \"value list \\<Rightarrow> value list \\<Rightarrow> bool\"\nand BO :: \"value list \\<Rightarrow> value list \\<Rightarrow> bool\"\nwhere\n BC_PVal[simp,intro!]:\n  \"list_all (Not o isOVal) ul \\<Longrightarrow> list_all (Not o isOVal) ul1 \\<Longrightarrow>\n   map tgtAPI (filter isPValS ul) = map tgtAPI (filter isPValS ul1) \\<Longrightarrow>\n   (ul = [] \\<longrightarrow> ul1 = [])\n   \\<Longrightarrow> BC ul ul1\"\n|BC_BO[intro]:\n  \"BO vl vl1 \\<Longrightarrow>\n   list_all (Not o isOVal) ul \\<Longrightarrow> list_all (Not o isOVal) ul1 \\<Longrightarrow>\n   map tgtAPI (filter isPValS ul) = map tgtAPI (filter isPValS ul1) \\<Longrightarrow>\n   (ul = [] \\<longleftrightarrow> ul1 = []) \\<Longrightarrow>\n   (ul \\<noteq> [] \\<Longrightarrow> isPVal (last ul) \\<and> last ul = last ul1) \\<Longrightarrow>\n   list_all isPValS sul\n   \\<Longrightarrow>\n   BC (ul  @ sul @ OVal True # vl)\n      (ul1 @ sul @ OVal True # vl1)\"\n(*  *)\n|BO_PVal[simp,intro!]:\n  \"list_all (Not o isOVal) ul \\<Longrightarrow> BO ul ul\"\n|BO_BC[intro]:\n  \"BC vl vl1 \\<Longrightarrow>\n   list_all (Not o isOVal) ul\n   \\<Longrightarrow>\n   BO (ul @ OVal False # vl) (ul @ OVal False # vl1)\"\n\nlemma list_all_filter_Not_isOVal:\nassumes \"list_all (Not \\<circ> isOVal) ul\"\nand \"filter isPValS ul = []\" and \"filter isPVal ul = []\"\nshows \"ul = []\"\nusing assms value.exhaust_disc by (induct ul) auto\n\nlemma BC_not_Nil: \"BC vl vl1 \\<Longrightarrow> vl = [] \\<Longrightarrow> vl1 = []\"\nby(auto elim: BC.cases)\n\nlemma BC_OVal_True:\nassumes \"BC (OVal True # vl') vl1\"\nshows \"\\<exists> vl1'. BO vl' vl1' \\<and> vl1 = OVal True # vl1'\"\nproof-\n  define vl where vl: \"vl \\<equiv> OVal True # vl'\"\n  have \"BC vl vl1\" using assms unfolding vl by auto\n  thus ?thesis proof cases\n    case (BC_BO vll vll1 ul ul1 sul)\n    hence ul: \"ul = []\" unfolding vl apply simp\n    by (metis (no_types) Post.value.disc(9) append_eq_Cons_conv\n         list.map(2) list.pred_inject(2) list_all_map)\n    have sul: \"sul = []\" using BC_BO unfolding vl ul apply simp\n    by (metis Post.value.disc(6) append_eq_Cons_conv list.pred_inject(2))\n    show ?thesis\n    apply - apply(rule exI[of _ \"vll1\"])\n    using BC_BO using list_all_filter_Not_isOVal[of ul1]\n    unfolding ul sul vl by auto\n  qed(unfold vl, auto)\nqed\n\n(* Correlation is defined to mean: always send what was last uploaded, or emptyPost\nif nothing had been uploaded. This needs the auxiliary notion of \"correlation from\" *)\nfun corrFrom :: \"post \\<Rightarrow> value list \\<Rightarrow> bool\" where\n \"corrFrom pst [] = True\"\n|\"corrFrom pst (PVal pstt # vl) = corrFrom pstt vl\"\n|\"corrFrom pst (PValS aid pstt # vl) = (pst = pstt \\<and> corrFrom pst vl)\"\n|\"corrFrom pst (OVal b # vl) = (corrFrom pst vl)\"\n\n\nabbreviation corr :: \"value list \\<Rightarrow> bool\" where \"corr \\<equiv> corrFrom emptyPost\"\n\ndefinition B where\n\"B vl vl1 \\<equiv> BC vl vl1 \\<and> corr vl1\"\n\n(* lemma vl_Nil_filter_not:\nassumes \"filter (%v. isPVal v \\<or> isOVal v) Vl = [] \\<and> filter (Not o isPVal) Vl = []\"\nshows \"Vl = []\"\nusing assms by (induct Vl) auto *)\n\nlemma B_not_Nil:\nassumes B: \"B vl vl1\" and vl: \"vl = []\"\nshows \"vl1 = []\"\nusing B Post.BC_not_Nil Post.B_def vl by blast\n\n\nsublocale BD_Security_IO where\nistate = istate and step = step and\n\\<phi> = \\<phi> and f = f and \\<gamma> = \\<gamma> and g = g and T = T and B = B\ndone\n\nsubsubsection \\<open>Issuer unwinding proof\\<close>\n\nlemma reach_PublicV_imples_FriendV[simp]:\nassumes \"reach s\"\nand \"vis s pid \\<noteq> PublicV\"\nshows \"vis s pid = FriendV\"\nusing assms reach_vis by auto\n\n\n(* major *) lemma eqButPID_step_\\<gamma>_out:\nassumes ss1: \"eqButPID s s1\"\nand step: \"step s a = (ou,s')\" and step1: \"step s1 a = (ou1,s1')\"\nand op: \"\\<not> open s\"\nand sT: \"reachNT s\" and s1: \"reach s1\"\nand \\<gamma>: \"\\<gamma> (Trans s a ou s')\"\nshows \"(\\<exists> uid p aid pid. a = COMact (comSendPost uid p aid pid) \\<and> outPurge ou = outPurge ou1) \\<or>\n       ou = ou1\"\nproof-\n  note [simp] = all_defs\n                open_def\n  note s = reachNT_reach[OF sT]\n  note willUse =\n    step step1 \\<gamma>\n    not_open_eqButPID[OF op ss1]\n    reach_vis[OF s]\n    eqButPID_stateSelectors[OF ss1] (* eqButPID_postSelectors[OF ss1]  *)\n    eqButPID_actions[OF ss1]\n    eqButPID_update[OF ss1] (* eqButPID_setTextPost[OF ss1] *) eqButPID_not_PID[OF ss1]\n  (* added to cope with extra leak towards the admin, when moving from CoSMed to CosMeDis: *)\n    (* eqButPID_eqButT[OF ss1] *) eqButPID_eqButF[OF ss1]\n    eqButPID_setShared[OF ss1] eqButPID_updateShared[OF ss1]\n    eeqButPID_F_not_PID eqButPID_not_PID_sharedWith\n    eqButPID_insert2[OF ss1]\n  show ?thesis\n  proof (cases a)\n    case (Sact x1)\n    with willUse show ?thesis by (cases x1) auto\n  next\n    case (Cact x2)\n    with willUse show ?thesis by (cases x2) auto\n  next\n    case (Dact x3)\n    with willUse show ?thesis by (cases x3) auto\n  next\n    case (Uact x4)\n    with willUse show ?thesis by (cases x4) auto\n  next\n    case (Ract x5)\n    with willUse show ?thesis\n    proof (cases x5)\n      case (rPost uid p pid)\n      with Ract willUse show ?thesis by (cases \"pid = PID\") auto\n    qed auto\n  next\n    case (Lact x6)\n    with willUse show ?thesis\n    proof (cases x6)\n      case (lClientsPost uid p pid)\n      with Lact willUse show ?thesis by (cases \"pid = PID\") auto\n    qed auto\n  next\n    case (COMact x7)\n    with willUse show ?thesis by (cases x7) auto\n  qed\nqed\n\n(* major *) lemma eqButPID_step_eq:\nassumes ss1: \"eqButPID s s1\"\nand a: \"a = Uact (uPost uid p PID pst)\" \"ou = outOK\"\nand step: \"step s a = (ou, s')\" and step1: \"step s1 a = (ou', s1')\"\nshows \"s' = s1'\"\nusing ss1 step step1\nusing eqButPID_stateSelectors[OF ss1]\neqButPID_update[OF ss1] (* eqButPID_setTextPost[OF ss1] *) eqButPID_setShared[OF ss1]\nunfolding a by (auto simp: u_defs)\n\n\ndefinition \\<Delta>0 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>0 s vl s1 vl1 \\<equiv>\n \\<not> PID \\<in>\\<in> postIDs s \\<and>\n s = s1 \\<and> BC vl vl1 \\<and>\n corr vl1\"\n\ndefinition \\<Delta>1 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>1 s vl s1 vl1 \\<equiv>\n PID \\<in>\\<in> postIDs s \\<and>\n list_all (Not o isOVal) vl \\<and> list_all (Not o isOVal) vl1 \\<and>\n map tgtAPI (filter isPValS vl) = map tgtAPI (filter isPValS vl1) \\<and>\n (vl = [] \\<longrightarrow> vl1 = []) \\<and>\n eqButPID s s1 \\<and> \\<not> open s \\<and>\n corrFrom (post s1 PID) vl1\"\n\ndefinition \\<Delta>11 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>11 s vl s1 vl1 \\<equiv>\n PID \\<in>\\<in> postIDs s \\<and>\n vl = [] \\<and> list_all isPVal vl1 \\<and>\n eqButPID s s1 \\<and> \\<not> open s \\<and>\n corrFrom (post s1 PID) vl1\"\n\ndefinition \\<Delta>2 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>2 s vl s1 vl1 \\<equiv>\n PID \\<in>\\<in> postIDs s \\<and>\n list_all (Not o isOVal) vl \\<and>\n vl = vl1 \\<and>\n s = s1 \\<and> open s \\<and>\n corrFrom (post s1 PID) vl1\"\n\ndefinition \\<Delta>31 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>31 s vl s1 vl1 \\<equiv>\n PID \\<in>\\<in> postIDs s \\<and>\n (\\<exists> ul ul1 sul vll vll1.\n    BO vll vll1 \\<and>\n    list_all (Not o isOVal) ul \\<and> list_all (Not o isOVal) ul1 \\<and>\n    map tgtAPI (filter isPValS ul) = map tgtAPI (filter isPValS ul1) \\<and>\n    ul \\<noteq> [] \\<and> ul1 \\<noteq> [] \\<and>\n    isPVal (last ul) \\<and> last ul = last ul1 \\<and>\n    list_all isPValS sul \\<and>\n    vl = ul @ sul @ OVal True # vll \\<and> vl1 = ul1 @ sul @ OVal True # vll1) \\<and>\n eqButPID s s1 \\<and> \\<not> open s \\<and>\n corrFrom (post s1 PID) vl1\"\n\ndefinition \\<Delta>32 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>32 s vl s1 vl1 \\<equiv>\n PID \\<in>\\<in> postIDs s \\<and>\n (\\<exists> sul vll vll1.\n    BO vll vll1 \\<and>\n    list_all isPValS sul \\<and>\n    vl = sul @ OVal True # vll \\<and> vl1 = sul @ OVal True # vll1) \\<and>\n s = s1 \\<and> \\<not> open s \\<and>\n corrFrom (post s1 PID) vl1\"\n\ndefinition \\<Delta>4 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>4 s vl s1 vl1 \\<equiv>\n PID \\<in>\\<in> postIDs s \\<and>\n (\\<exists> ul vll vll1.\n    BC vll vll1 \\<and>\n    list_all (Not o isOVal) ul \\<and>\n    vl = ul @ OVal False # vll \\<and> vl1 = ul @ OVal False # vll1) \\<and>\n s = s1 \\<and> open s \\<and>\n corrFrom (post s1 PID) vl1\"\n\nlemma istate_\\<Delta>0:\nassumes B: \"B vl vl1\"\nshows \"\\<Delta>0 istate vl istate vl1\"\nusing assms unfolding \\<Delta>0_def istate_def B_def by auto\n(* by (auto simp: list_all_isOVal_filter_isPValS)\n(auto intro!: exI[of _ \"[]\"]) *)\n\nlemma list_all_filter[simp]:\nassumes \"list_all PP xs\"\nshows \"filter PP xs = xs\"\nusing assms by (induct xs) auto\n\nlemma unwind_cont_\\<Delta>0: \"unwind_cont \\<Delta>0 {\\<Delta>0,\\<Delta>1,\\<Delta>2,\\<Delta>31,\\<Delta>32,\\<Delta>4}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>0 s vl s1 vl1 \\<or>\n                           \\<Delta>1 s vl s1 vl1 \\<or> \\<Delta>2 s vl s1 vl1 \\<or>\n                           \\<Delta>31 s vl s1 vl1 \\<or> \\<Delta>32 s vl s1 vl1 \\<or> \\<Delta>4 s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \"\\<Delta>0 s vl s1 vl1\"\n  hence rs: \"reach s\" and ss1: \"s1 = s\" and BC: \"BC vl vl1\" and PID: \"\\<not> PID \\<in>\\<in> postIDs s\"\n  and cor1: \"corr vl1\" using reachNT_reach unfolding \\<Delta>0_def by auto\n  have vis: \"vis s PID = FriendV\" using reach_not_postIDs_friendV[OF rs PID] .\n  have pPID: \"post s1 PID = emptyPost\" by (simp add: PID reach_not_postIDs_emptyPost rs ss1)\n  have vlvl1: \"vl = [] \\<Longrightarrow> vl1 = []\" using BC_not_Nil BC by auto\n  have op: \"\\<not> open s\" using PID unfolding open_def by auto\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof-\n    have ?react proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\"  let ?trn1 = \"Trans s1 a ou s'\"\n      assume step: \"step s a = (ou, s')\" and T: \"\\<not> T ?trn\" and c: \"consume ?trn vl vl'\"\n      hence pPID': \"post s' PID = emptyPost\"\n        using step pPID ss1 PID\n        apply(cases a)\n        subgoal for x1 apply(cases x1) apply(fastforce simp: s_defs)+ .\n        subgoal for x2 apply(cases x2) apply(fastforce simp: c_defs)+ .\n        subgoal for x3 apply(cases x3) apply(fastforce simp: d_defs)+ .\n        subgoal for x4 apply(cases x4) apply(fastforce simp: u_defs)+ .\n        subgoal by (fastforce simp: d_defs)\n        subgoal by (fastforce simp: d_defs)\n        subgoal for x7 apply(cases x7) apply(fastforce simp: com_defs)+ .\n        done\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n      proof-\n        have ?match\n        proof(cases \"\\<exists> uid p. a = Cact (cPost uid p PID) \\<and> ou = outOK\")\n          case True\n          then obtain uid p where a: \"a = Cact (cPost uid p PID)\" and ou: \"ou = outOK\" by auto\n          have PID': \"PID \\<in>\\<in> postIDs s'\"\n          using step PID unfolding a ou by (auto simp: c_defs)\n          show ?thesis proof(cases\n             \"\\<exists> uid' \\<in> UIDs. uid' \\<in>\\<in> userIDs s \\<and>\n                             (uid' = admin s \\<or> uid' = uid \\<or> uid' \\<in>\\<in> friendIDs s uid)\")\n            case True note uid = True\n            have op': \"open s'\" using uid using step PID' unfolding a ou by (auto simp: c_defs open_def)\n            have \\<phi>: \"\\<phi> ?trn\" using op op' unfolding \\<phi>_def2[OF step] by simp\n            then obtain v where vl: \"vl = v # vl'\" and f: \"f ?trn = v\"\n            using c unfolding consume_def \\<phi>_def2 by(cases vl) auto\n            have v: \"v = OVal True\" using f op op' unfolding a by simp\n            then obtain ul1 vl1' where BO': \"BO vl' vl1'\" and vl1: \"vl1 = ul1 @ OVal True # vl1'\"\n            and ul1: \"list_all (Not \\<circ> isOVal) ul1\"\n            using BC_OVal_True[OF BC[unfolded vl v]] by auto\n            have ul1: \"ul1 = []\"\n              using BC BC_OVal_True list_all_Not_isOVal_OVal_True ul1 v vl vl1 by blast\n            hence vl1: \"vl1 = OVal True # vl1'\" using vl1 by simp\n            show ?thesis proof\n              show \"validTrans ?trn1\" unfolding ss1 using step by simp\n            next\n              show \"consume ?trn1 vl1 vl1'\" using \\<phi> f unfolding vl1 v consume_def ss1 by simp\n            next\n              show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n            next\n              assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\" unfolding ss1 by simp\n            next\n              show \"?\\<Delta> s' vl' s' vl1'\" using BO' proof(cases rule: BO.cases)\n                case (BO_PVal)\n                hence \"\\<Delta>2 s' vl' s' vl1'\" using PID' op' cor1 unfolding \\<Delta>2_def vl1 pPID' by auto\n                thus ?thesis by simp\n              next\n                case (BO_BC vll vll1 textl)\n                hence \"\\<Delta>4 s' vl' s' vl1'\" using PID' op' cor1 unfolding \\<Delta>4_def vl1 pPID' by auto\n                thus ?thesis by simp\n              qed\n            qed\n          next\n            case False note uid = False\n            have op': \"\\<not> open s'\" using step op uid vis unfolding open_def a by (auto simp: c_defs)\n            have \\<phi>: \"\\<not> \\<phi> ?trn\" using op op' a unfolding \\<phi>_def2[OF step] by auto\n            hence vl': \"vl' = vl\" using c unfolding consume_def by simp\n            show ?thesis proof\n              show \"validTrans ?trn1\" unfolding ss1 using step by simp\n            next\n              show \"consume ?trn1 vl1 vl1\" using \\<phi> unfolding consume_def ss1 by auto\n            next\n              show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n            next\n              assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\" unfolding ss1 by simp\n            next\n              show \"?\\<Delta> s' vl' s' vl1\" using BC proof(cases rule: BC.cases)\n                case (BC_PVal)\n                hence \"\\<Delta>1 s' vl' s' vl1\" using PID' op' cor1 unfolding \\<Delta>1_def vl' pPID' by auto\n                thus ?thesis by simp\n              next\n                case (BC_BO vll vll1 ul ul1 sul)\n                show ?thesis\n                proof(cases \"ul \\<noteq> [] \\<and> ul1 \\<noteq> []\")\n                  case True\n                  hence \"\\<Delta>31 s' vl' s' vl1\" using BC_BO PID' op' cor1\n                  unfolding \\<Delta>31_def vl' pPID' apply auto\n                  apply (rule exI[of _ \"ul\"]) apply (rule exI[of _ \"ul1\"])\n                  apply (rule exI[of _ \"sul\"])\n                  apply (rule exI[of _ \"vll\"]) apply (rule exI[of _ \"vll1\"])\n                  by auto\n                  thus ?thesis by simp\n                next\n                  case False\n                  hence 0: \"ul = [] \\<and> ul1 = []\" using BC_BO by simp\n                  hence 1: \"list_all isPValS ul \\<and> list_all isPValS ul1\"\n                  using \\<open>list_all (Not \\<circ> isOVal) ul\\<close> \\<open>list_all (Not \\<circ> isOVal) ul1\\<close>\n                  using filter_list_all_isPValS_isOVal by auto\n                  (* have \"map tgtAPI ul = map tgtAPI ul1\" using 1BC_BO by auto *)\n                  have \"\\<Delta>32 s' vl' s' vl1\" using BC_BO PID' op' cor1 0 1\n                  unfolding \\<Delta>32_def vl' pPID' apply simp\n                  apply(rule exI[of _ \"sul\"])\n                  apply(rule exI[of _ vll]) apply(rule exI[of _ vll1])\n                  by auto\n                  thus ?thesis by simp\n                qed\n              qed\n            qed\n          qed\n        next\n          case False note a = False\n          have op': \"\\<not> open s'\"\n            using a step PID op unfolding open_def\n            apply(cases a)\n            subgoal for x1 apply(cases x1) apply(fastforce simp: s_defs)+ .\n            subgoal for x2 apply(cases x2) apply(fastforce simp: c_defs)+ .\n            subgoal for x3 apply(cases x3) apply(fastforce simp: d_defs)+ .\n            subgoal for x4 apply(cases x4) apply(fastforce simp: u_defs)+ .\n            subgoal by (fastforce simp: u_defs)\n            subgoal by (fastforce simp: u_defs)\n            subgoal for x7 apply(cases x7) apply(fastforce simp: com_defs)+ .\n            done\n          have \\<phi>: \"\\<not> \\<phi> ?trn\" using PID step op op' unfolding \\<phi>_def2[OF step]\n          by (auto simp: u_defs com_defs)\n          hence vl': \"vl' = vl\" using c unfolding consume_def by simp\n          have PID': \"\\<not> PID \\<in>\\<in> postIDs s'\"\n            using step PID a\n            apply(cases a)\n            subgoal for x1 apply(cases x1) apply(fastforce simp: s_defs)+ .\n            subgoal for x2 apply(cases x2) apply(fastforce simp: c_defs)+ .\n            subgoal for x3 apply(cases x3) apply(fastforce simp: d_defs)+ .\n            subgoal for x4 apply(cases x4) apply(fastforce simp: u_defs)+ .\n            subgoal by (fastforce simp: u_defs)\n            subgoal by (fastforce simp: u_defs)\n            subgoal for x7 apply(cases x7) apply(fastforce simp: com_defs)+ .\n            done\n          show ?thesis proof\n            show \"validTrans ?trn1\" unfolding ss1 using step by simp\n          next\n            show \"consume ?trn1 vl1 vl1\" using \\<phi> unfolding consume_def ss1 by auto\n          next\n            show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n          next\n            assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\" unfolding ss1 by simp\n          next\n            have \"\\<Delta>0 s' vl' s' vl1\" using a BC PID' cor1 unfolding \\<Delta>0_def vl' by simp\n            thus \"?\\<Delta> s' vl' s' vl1\" by simp\n          qed\n        qed\n        thus ?thesis by simp\n      qed\n    qed\n  thus ?thesis using vlvl1 by simp\n  qed\nqed\n\nlemma unwind_cont_\\<Delta>1: \"unwind_cont \\<Delta>1 {\\<Delta>1,\\<Delta>11}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>1 s vl s1 vl1 \\<or> \\<Delta>11 s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \"\\<Delta>1 s vl s1 vl1\"\n  then obtain\n  lvl: \"list_all (Not \\<circ> isOVal) vl\" and lvl1: \"list_all (Not \\<circ> isOVal) vl1\"\n  and map: \"map tgtAPI (filter isPValS vl) = map tgtAPI (filter isPValS vl1)\"\n  and rs: \"reach s\" and ss1: \"eqButPID s s1\" and op: \"\\<not> open s\" and PID: \"PID \\<in>\\<in> postIDs s\"\n  and vlvl1: \"vl = [] \\<Longrightarrow> vl1 = []\" and cor1: \"corrFrom (post s1 PID) vl1\"\n  using reachNT_reach unfolding \\<Delta>1_def by auto\n  have PID1: \"PID \\<in>\\<in> postIDs s1\" using eqButPID_stateSelectors[OF ss1] PID by auto\n  have own: \"owner s PID \\<in> set (userIDs s)\" using reach_owner_userIDs[OF rs PID] .\n  hence own1: \"owner s1 PID \\<in> set (userIDs s1)\" using eqButPID_stateSelectors[OF ss1] by auto\n  have adm: \"admin s \\<in> set (userIDs s)\" using reach_admin_userIDs[OF rs own] .\n  hence adm1: \"admin s1 \\<in> set (userIDs s1)\" using eqButPID_stateSelectors[OF ss1] by auto\n  have op1: \"\\<not> open s1\" using op ss1 eqButPID_open by auto\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof(cases vl1)\n    case (Cons v1 vll1) note vl1 = Cons\n    show ?thesis proof(cases v1)\n      case (PVal pst1) note v1 = PVal\n      define uid where uid: \"uid \\<equiv> owner s PID\"  define p where p: \"p \\<equiv> pass s uid\"\n      define a1 where a1: \"a1 \\<equiv> Uact (uPost uid p PID pst1)\"\n      have uid1: \"uid = owner s1 PID\" and p1: \"p = pass s1 uid\" unfolding uid p\n      using eqButPID_stateSelectors[OF ss1] by auto\n      obtain ou1 s1' where step1: \"step s1 a1 = (ou1, s1')\" by(cases \"step s1 a1\") auto\n      have ou1: \"ou1 = outOK\" using step1 PID1 own1 unfolding a1 uid1 p1 by (auto simp: u_defs)\n      have op1': \"\\<not> open s1'\" using step1 op1 unfolding a1 ou1 open_def by (auto simp: u_defs)\n      have uid: \"uid \\<notin> UIDs\" unfolding uid using op PID own unfolding open_def by auto\n      have pPID1': \"post s1' PID = pst1\" using step1 unfolding a1 ou1 by (auto simp: u_defs)\n      let ?trn1 = \"Trans s1 a1 ou1 s1'\"\n      have ?iact proof\n        show \"step s1 a1 = (ou1, s1')\" using step1 .\n      next\n        show \\<phi>: \"\\<phi> ?trn1\" unfolding \\<phi>_def2[OF step1] a1 ou1 by simp\n        show \"consume ?trn1 vl1 vll1\"\n        using \\<phi> unfolding vl1 consume_def v1 a1 by auto\n      next\n        show \"\\<not> \\<gamma> ?trn1\" using uid unfolding a1 by auto\n      next\n        have \"eqButPID s1 s1'\" using Uact_uPaperC_step_eqButPID[OF _ step1] a1 by auto\n        hence ss1': \"eqButPID s s1'\" using eqButPID_trans ss1 by blast\n        show \"?\\<Delta> s vl s1' vll1\" using PID op ss1' lvl lvl1 map vlvl1 cor1\n        unfolding \\<Delta>1_def vl1 v1 pPID1' by auto\n      qed\n      thus ?thesis by simp\n    next\n      case (PValS aid1 pst1) note v1 = PValS\n      have pPID1: \"post s1 PID = pst1\" using cor1 unfolding vl1 v1 by auto\n      then obtain v vll where vl: \"vl = v # vll\"\n      using map unfolding vl1 v1 by (cases vl) auto\n      have ?react proof\n        fix a :: act and ou :: out and s' :: state and vl'\n        let ?trn = \"Trans s a ou s'\"\n        assume step: \"step s a = (ou, s')\" and c: \"consume ?trn vl vl'\"\n        have PID': \"PID \\<in>\\<in> postIDs s'\" using reach_postIDs_persist[OF PID step] .\n        obtain ou1 s1' where step1: \"step s1 a = (ou1, s1')\" by(cases \"step s1 a\") auto\n        let ?trn1 = \"Trans s1 a ou1 s1'\"\n        show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\"\n            (is \"?match \\<or> ?ignore\")\n        proof(cases \"\\<phi> ?trn\")\n          case True note \\<phi> = True\n          then obtain f: \"f ?trn = v\" and vl': \"vl' = vll\"\n          using c unfolding vl consume_def \\<phi>_def2 by auto\n          show ?thesis\n          proof(cases v)\n            case (PVal pst) note v = PVal\n            have vll: \"vll \\<noteq> []\" using map unfolding vl1 v1 vl v by auto\n            define uid where uid: \"uid \\<equiv> owner s PID\"  define p where p: \"p \\<equiv> pass s uid\"\n            have a: \"a = Uact (uPost uid p PID pst)\"\n            using f_eq_PVal[OF step \\<phi> f[unfolded v]] unfolding uid p .\n            have \"eqButPID s s'\" using Uact_uPaperC_step_eqButPID[OF a step] by auto\n            hence s's1: \"eqButPID s' s1\" using eqButPID_sym eqButPID_trans ss1 by blast\n            have op': \"\\<not> open s'\" using uPost_comSendPost_open_eq[OF step] a op by auto\n            have ?ignore proof\n              show \\<gamma>: \"\\<not> \\<gamma> ?trn\" using step_open_\\<phi>_f_PVal_\\<gamma>[OF rs step PID op \\<phi> f[unfolded v]] .\n              show \"?\\<Delta> s' vl' s1 vl1\"\n              using lvl1 lvl PID' map s's1 op' vll cor1 unfolding \\<Delta>1_def vl1 vl vl' v\n              by auto\n            qed\n            thus ?thesis by simp\n          next\n            case (PValS aid pst) note v = PValS\n            define uid where uid: \"uid \\<equiv> admin s\" define p where p: \"p \\<equiv> pass s uid\"\n            have a: \"a = COMact (comSendPost (admin s) p aid PID)\"\n            using f_eq_PValS[OF step \\<phi> f[unfolded v]] unfolding uid p .\n            have op': \"\\<not> open s'\" using uPost_comSendPost_open_eq[OF step] a op by auto\n            have aid1: \"aid1 = aid\" using map unfolding vl1 v1 vl v by simp\n            have uid1: \"uid = admin s1\" and p1: \"p = pass s1 uid\" unfolding uid p\n            using eqButPID_stateSelectors[OF ss1] by auto\n            obtain ou1 s1' where step1: \"step s1 a = (ou1, s1')\" by(cases \"step s1 a\") auto\n            have pPID1': \"post s1' PID = pst1\" using pPID1 step1 unfolding a\n            by (auto simp: com_defs)\n            have uid: \"uid \\<notin> UIDs\" unfolding uid using op PID adm unfolding open_def by auto\n            have op1': \"\\<not> open s1'\" using step1 op1 unfolding a open_def\n            by (auto simp: u_defs com_defs)\n            let ?trn1 = \"Trans s1 a ou1 s1'\"\n            have \\<phi>1: \"\\<phi> ?trn1\" using eqButPID_step_\\<phi>_imp[OF ss1 step step1 \\<phi>] .\n            have ou1: \"ou1 =\n                O_sendPost (aid, clientPass s1 aid, PID, post s1 PID, owner s1 PID, vis s1 PID)\"\n              using \\<phi>1 step1 adm1 PID1 unfolding a by (cases ou1, auto simp: com_defs)\n            have f1: \"f ?trn1 = v1\" using \\<phi>1 unfolding \\<phi>_def2[OF step1] v1 a ou1 aid1 pPID1 by auto\n            have s's1': \"eqButPID s' s1'\" using eqButPID_step[OF ss1 step step1] .\n            have ?match proof\n              show \"validTrans ?trn1\" using step1 by simp\n            next\n              show \"consume ?trn1 vl1 vll1\" using \\<phi>1 unfolding consume_def vl1 f1 by simp\n            next\n              show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n            next\n              assume \"\\<gamma> ?trn\" note \\<gamma> = this\n              have ou: \"(\\<exists> uid p aid pid.\n                       a = COMact (comSendPost uid p aid pid) \\<and> outPurge ou = outPurge ou1) \\<or>\n                                        ou = ou1\"\n              using eqButPID_step_\\<gamma>_out[OF ss1 step step1 op rsT rs1 \\<gamma>] .\n              thus \"g ?trn = g ?trn1\" by (cases a) auto\n            next\n              show \"?\\<Delta> s' vl' s1' vll1\"\n              proof(cases \"vll = []\")\n                case True note vll = True\n                hence \"filter isPValS vll1 = []\" using map lvl lvl1 unfolding vl vl1 v v1 by simp\n                hence lvl1: \"list_all isPVal vll1\"\n                using filter_list_all_isPVal_isOVal lvl1 unfolding vl1 v1 by auto\n                hence \"\\<Delta>11 s' vl' s1' vll1\" using s's1' op1' op' PID' lvl lvl1 map cor1 pPID1 pPID1'\n                unfolding \\<Delta>11_def vl vl' vl1 v v1 vll by auto\n                thus ?thesis by auto\n              next\n                case False note vll = False\n                hence \"\\<Delta>1 s' vl' s1' vll1\" using s's1' op1' op' PID' lvl lvl1 map cor1 pPID1 pPID1'\n                unfolding \\<Delta>1_def vl vl' vl1 v v1 by auto\n                thus ?thesis by auto\n              qed\n            qed\n          thus ?thesis using vl by simp\n        qed(insert lvl vl, auto)\n      next\n        case False note \\<phi> = False\n        hence vl': \"vl' = vl\" using c unfolding consume_def by auto\n        obtain ou1 s1' where step1: \"step s1 a = (ou1, s1')\" by(cases \"step s1 a\") auto\n        have s's1': \"eqButPID s' s1'\" using eqButPID_step[OF ss1 step step1] .\n        let ?trn1 = \"Trans s1 a ou1 s1'\"\n        have \\<phi>1: \"\\<not> \\<phi> ?trn1\" using \\<phi> ss1 by (simp add: eqButPID_step_\\<phi> step step1)\n        have pPID1': \"post s1' PID = pst1\" using PID1 pPID1 step1 \\<phi>1 (* unfolding \\<phi>_def2[OF step1] *)\n          apply(cases a)\n          subgoal for x1 apply(cases x1) apply(fastforce simp: s_defs)+ .\n          subgoal for x2 apply(cases x2) apply(fastforce simp: c_defs)+ .\n          subgoal for x3 apply(cases x3) apply(fastforce simp: d_defs)+ .\n          subgoal for x4 apply(cases x4) apply(fastforce simp: u_defs)+ .\n          subgoal by (fastforce simp: u_defs)\n          subgoal by (fastforce simp: u_defs)\n          subgoal for x7 apply(cases x7) apply(fastforce simp: com_defs)+ .\n          done\n        have op': \"\\<not> open s'\"\n        using PID step \\<phi> op unfolding \\<phi>_def2[OF step] by auto\n        have ?match proof\n          show \"validTrans ?trn1\" using step1 by simp\n        next\n          show \"consume ?trn1 vl1 vl1\" using \\<phi>1 unfolding consume_def by simp\n        next\n          show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n        next\n          assume \"\\<gamma> ?trn\" note \\<gamma> = this\n          have ou: \"(\\<exists> uid p aid pid.\n                   a = COMact (comSendPost uid p aid pid) \\<and> outPurge ou = outPurge ou1) \\<or>\n                   ou = ou1\"\n          using eqButPID_step_\\<gamma>_out[OF ss1 step step1 op rsT rs1 \\<gamma>] .\n          thus \"g ?trn = g ?trn1\" by (cases a) auto\n        next\n          have \"\\<Delta>1 s' vl' s1' vl1\" using s's1' PID' pPID1 pPID1' lvl lvl1 map cor1 op'\n          unfolding \\<Delta>1_def vl vl' by auto\n          thus \"?\\<Delta> s' vl' s1' vl1\" by simp\n        qed\n        thus ?thesis by simp\n      qed\n    qed\n    thus ?thesis using vlvl1 by simp\n  qed(insert lvl1 vl1, auto)\nnext\n  case Nil note vl1 = Nil\n  have ?react proof\n    fix a :: act and ou :: out and s' :: state and vl'\n    let ?trn = \"Trans s a ou s'\"\n      assume step: \"step s a = (ou, s')\" and T: \"\\<not> T ?trn\" and c: \"consume ?trn vl vl'\"\n      have PID': \"PID \\<in>\\<in> postIDs s'\" using reach_postIDs_persist[OF PID step] .\n      obtain ou1 s1' where step1: \"step s1 a = (ou1, s1')\" by(cases \"step s1 a\") auto\n      let ?trn1 = \"Trans s1 a ou1 s1'\"\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n      proof(cases \"\\<exists> uid p pstt. a = Uact (uPost uid p PID pstt) \\<and> ou = outOK\")\n        case True then obtain uid p pstt where\n        a: \"a = Uact (uPost uid p PID pstt)\" and ou: \"ou = outOK\" by auto\n        hence \\<phi>: \"\\<phi> ?trn\" unfolding \\<phi>_def2[OF step] by auto\n        then obtain v where vl: \"vl = v # vl'\" and f: \"f ?trn = v\"\n        using c unfolding consume_def \\<phi>_def2 by (cases vl) auto\n        obtain pst where v: \"v = PVal pst\" using map lvl unfolding vl vl1 by (cases v) auto\n        have pstt: \"pstt = pst\" using f unfolding a v by auto\n        have uid: \"uid \\<notin> UIDs\" using step op PID unfolding a ou open_def by (auto simp: u_defs)\n        have \"eqButPID s s'\" using Uact_uPaperC_step_eqButPID[OF a step] by auto\n        hence s's1: \"eqButPID s' s1\" using eqButPID_sym eqButPID_trans ss1 by blast\n        have op': \"\\<not> open s'\" using step PID' op unfolding a ou open_def by (auto simp: u_defs)\n        have ?ignore proof\n          show \"\\<not> \\<gamma> ?trn\" unfolding a using uid by auto\n        next\n          show \"?\\<Delta> s' vl' s1 vl1\" using PID' s's1 op' lvl map\n          unfolding \\<Delta>1_def vl1 vl by auto\n        qed\n        thus ?thesis by simp\n      next\n        case False note a = False\n        {assume \\<phi>: \"\\<phi> ?trn\"\n         then obtain v vl' where vl: \"vl = v # vl'\" and f: \"f ?trn = v\"\n         using c unfolding consume_def by (cases vl) auto\n         obtain pst where v: \"v = PVal pst\" using map lvl unfolding vl vl1 by (cases v) auto\n         have False using f f_eq_PVal[OF step \\<phi>, of pst] a \\<phi> v by auto\n        }\n        hence \\<phi>: \"\\<not> \\<phi> ?trn\" by auto\n        have \\<phi>1: \"\\<not> \\<phi> ?trn1\" by (metis \\<phi> eqButPID_step_\\<phi> step ss1 step1)\n        have op': \"\\<not> open s'\" using a op \\<phi> unfolding \\<phi>_def2[OF step] by auto\n        have vl': \"vl' = vl\" using c \\<phi> unfolding consume_def by auto\n        have s's1': \"eqButPID s' s1'\" using eqButPID_step[OF ss1 step step1] .\n        have op1': \"\\<not> open s1'\" using op' eqButPID_open[OF s's1'] by simp\n        have \"\\<And> uid p pst. e_updatePost s1 uid p PID pst \\<longleftrightarrow> e_updatePost s uid p PID pst\"\n        using eqButPID_stateSelectors[OF ss1] unfolding u_defs by auto\n        hence ou1: \"\\<And> uid p pst. a = Uact (uPost uid p PID pst) \\<Longrightarrow> ou1 = ou\"\n        using step step1 by auto\n        have ?match proof\n          show \"validTrans ?trn1\" using step1 by simp\n        next\n          show \"consume ?trn1 vl1 vl1\" using \\<phi>1 unfolding consume_def by simp\n        next\n          show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n        next\n          assume \"\\<gamma> ?trn\" note \\<gamma> = this\n          have ou: \"(\\<exists> uid p aid pid.\n                       a = COMact (comSendPost uid p aid pid) \\<and> outPurge ou = outPurge ou1) \\<or>\n                                        ou = ou1\"\n          using eqButPID_step_\\<gamma>_out[OF ss1 step step1 op rsT rs1 \\<gamma>] .\n          thus \"g ?trn = g ?trn1\" by (cases a) auto\n        next\n          show \"?\\<Delta> s' vl' s1' vl1\" using s's1' op' PID' lvl map\n          unfolding \\<Delta>1_def vl' vl1 by auto\n        qed\n      thus ?thesis by simp\n      qed\n    qed\n    thus ?thesis using vlvl1 by simp\n  qed\nqed\n\nlemma unwind_cont_\\<Delta>11: \"unwind_cont \\<Delta>11 {\\<Delta>11}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>11 s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \"\\<Delta>11 s vl s1 vl1\"\n  hence  vl: \"vl = []\" and lvl1: \"list_all isPVal vl1\"\n  and rs: \"reach s\" and ss1: \"eqButPID s s1\" and op: \"\\<not> open s\" and PID: \"PID \\<in>\\<in> postIDs s\"\n  and cor1: \"corrFrom (post s1 PID) vl1\"\n  using reachNT_reach unfolding \\<Delta>11_def by auto\n  have PID1: \"PID \\<in>\\<in> postIDs s1\" using eqButPID_stateSelectors[OF ss1] PID by auto\n  have own: \"owner s PID \\<in> set (userIDs s)\" using reach_owner_userIDs[OF rs PID] .\n  hence own1: \"owner s1 PID \\<in> set (userIDs s1)\" using eqButPID_stateSelectors[OF ss1] by auto\n  have adm: \"admin s \\<in> set (userIDs s)\" using reach_admin_userIDs[OF rs own] .\n  hence adm1: \"admin s1 \\<in> set (userIDs s1)\" using eqButPID_stateSelectors[OF ss1] by auto\n  have op1: \"\\<not> open s1\" using op ss1 eqButPID_open by auto\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof(cases vl1)\n    case (Cons v1 vll1) note vl1 = Cons\n    then obtain pst1 where v1: \"v1 = PVal pst1\" using lvl1 unfolding vl1 by (cases v1) auto\n    define uid where uid: \"uid \\<equiv> owner s PID\"  define p where p: \"p \\<equiv> pass s uid\"\n    define a1 where a1: \"a1 \\<equiv> Uact (uPost uid p PID pst1)\"\n    have uid1: \"uid = owner s1 PID\" and p1: \"p = pass s1 uid\" unfolding uid p\n    using eqButPID_stateSelectors[OF ss1] by auto\n    obtain ou1 s1' where step1: \"step s1 a1 = (ou1, s1')\" by(cases \"step s1 a1\") auto\n    have ou1: \"ou1 = outOK\" using step1 PID1 own1 unfolding a1 uid1 p1 by (auto simp: u_defs)\n    have op1': \"\\<not> open s1'\" using step1 op1 unfolding a1 ou1 open_def by (auto simp: u_defs)\n    have uid: \"uid \\<notin> UIDs\" unfolding uid using op PID own unfolding open_def by auto\n    have pPID1': \"post s1' PID = pst1\" using step1 unfolding a1 ou1 by (auto simp: u_defs)\n    let ?trn1 = \"Trans s1 a1 ou1 s1'\"\n    have ?iact proof\n      show \"step s1 a1 = (ou1, s1')\" using step1 .\n    next\n      show \\<phi>: \"\\<phi> ?trn1\" unfolding \\<phi>_def2[OF step1] a1 ou1 by simp\n      show \"consume ?trn1 vl1 vll1\"\n      using \\<phi> unfolding vl1 consume_def v1 a1 by auto\n    next\n      show \"\\<not> \\<gamma> ?trn1\" using uid unfolding a1 by auto\n    next\n      have \"eqButPID s1 s1'\" using Uact_uPaperC_step_eqButPID[OF _ step1] a1 by auto\n      hence ss1': \"eqButPID s s1'\" using eqButPID_trans ss1 by blast\n      show \"?\\<Delta> s vl s1' vll1\"\n      using PID op ss1' lvl1 cor1 unfolding \\<Delta>11_def vl1 v1 vl pPID1' by auto\n    qed\n    thus ?thesis by simp\n  next\n    case Nil note vl1 = Nil\n    have ?react proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\"\n      assume step: \"step s a = (ou, s')\" and c: \"consume ?trn vl vl'\"\n      have PID': \"PID \\<in>\\<in> postIDs s'\" using reach_postIDs_persist[OF PID step] .\n      obtain ou1 s1' where step1: \"step s1 a = (ou1, s1')\" by(cases \"step s1 a\") auto\n      let ?trn1 = \"Trans s1 a ou1 s1'\"\n      have \\<phi>: \"\\<not> \\<phi> ?trn\" using c unfolding consume_def vl by auto\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\"\n          (is \"?match \\<or> ?ignore\")\n      proof-\n        have vl': \"vl' = vl\" using c unfolding vl consume_def by auto\n        obtain ou1 s1' where step1: \"step s1 a = (ou1, s1')\" by(cases \"step s1 a\") auto\n        have s's1': \"eqButPID s' s1'\" using eqButPID_step[OF ss1 step step1] .\n        let ?trn1 = \"Trans s1 a ou1 s1'\"\n        have \\<phi>1: \"\\<not> \\<phi> ?trn1\" using \\<phi> ss1 by (simp add: eqButPID_step_\\<phi> step step1)\n        have pPID1': \"post s1' PID = post s1 PID\" using PID1 step1 \\<phi>1\n          apply(cases a)\n          subgoal for x1 apply(cases x1) apply(fastforce simp: s_defs)+ .\n          subgoal for x2 apply(cases x2) apply(fastforce simp: c_defs)+ .\n          subgoal for x3 apply(cases x3) apply(fastforce simp: d_defs)+ .\n          subgoal for x4 apply(cases x4) apply(fastforce simp: u_defs)+ .\n          subgoal by fastforce\n          subgoal by fastforce\n          subgoal for x7 apply(cases x7) apply(fastforce simp: com_defs)+ .\n          done\n        have op': \"\\<not> open s'\" using PID step \\<phi> op unfolding \\<phi>_def2[OF step] by auto\n        have ?match proof\n          show \"validTrans ?trn1\" using step1 by simp\n        next\n          show \"consume ?trn1 vl1 vl1\" using \\<phi>1 unfolding consume_def by simp\n        next\n          show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n        next\n          assume \"\\<gamma> ?trn\" note \\<gamma> = this\n          have ou: \"(\\<exists> uid p aid pid.\n                   a = COMact (comSendPost uid p aid pid) \\<and> outPurge ou = outPurge ou1) \\<or>\n                   ou = ou1\"\n          using eqButPID_step_\\<gamma>_out[OF ss1 step step1 op rsT rs1 \\<gamma>] .\n          thus \"g ?trn = g ?trn1\" by (cases a) auto\n        next\n          have \"?\\<Delta> s' vl' s1' vl1\" using s's1' PID' pPID1' lvl1 cor1 op'\n          unfolding \\<Delta>11_def vl vl' by auto\n          thus \"?\\<Delta> s' vl' s1' vl1\" by simp\n        qed\n        thus ?thesis by simp\n      qed\n    qed\n    thus ?thesis using vl1 by simp\n  qed\nqed\n\nlemma unwind_cont_\\<Delta>31: \"unwind_cont \\<Delta>31 {\\<Delta>31,\\<Delta>32}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>31 s vl s1 vl1 \\<or> \\<Delta>32 s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \"\\<Delta>31 s vl s1 vl1\"\n  then obtain ul ul1 sul vll vll1 where\n  lul: \"list_all (Not \\<circ> isOVal) ul\" and lul1: \"list_all (Not \\<circ> isOVal) ul1\"\n  and map: \"map tgtAPI (filter isPValS ul) = map tgtAPI (filter isPValS ul1)\"\n  and rs: \"reach s\" and ss1: \"eqButPID s s1\" and op: \"\\<not> open s\" and PID: \"PID \\<in>\\<in> postIDs s\"\n  and cor1: \"corrFrom (post s1 PID) vl1\"\n  and ful: \"ul \\<noteq> []\" and ful1: \"ul1 \\<noteq> []\"\n  and lastul: \"isPVal (last ul)\" and ulul1: \"last ul = last ul1\"\n  and lsul: \"list_all isPValS sul\"\n  and vl: \"vl = ul @ sul @ OVal True # vll\"\n  and vl1: \"vl1 = ul1 @ sul @ OVal True # vll1\"\n  and BO: \"BO vll vll1\"\n  using reachNT_reach unfolding \\<Delta>31_def by auto\n  have ulNE: \"ul \\<noteq> []\" and ul1NE: \"ul1 \\<noteq> []\" using ful ful1 by auto\n  have PID1: \"PID \\<in>\\<in> postIDs s1\" using eqButPID_stateSelectors[OF ss1] PID by auto\n  have own: \"owner s PID \\<in> set (userIDs s)\" using reach_owner_userIDs[OF rs PID] .\n  hence own1: \"owner s1 PID \\<in> set (userIDs s1)\" using eqButPID_stateSelectors[OF ss1] by auto\n  have adm: \"admin s \\<in> set (userIDs s)\" using reach_admin_userIDs[OF rs own] .\n  hence adm1: \"admin s1 \\<in> set (userIDs s1)\" using eqButPID_stateSelectors[OF ss1] by auto\n  have op1: \"\\<not> open s1\" using op ss1 eqButPID_open by auto\n  obtain v1 ull1 where ul1: \"ul1 = v1 # ull1\" using ful1 by (cases ul1) auto\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof(cases v1)\n    case (PVal pst1) note v1 = PVal\n    show ?thesis proof(cases \"list_ex isPVal ull1\")\n      case True note lull1 = True\n      hence full1: \"filter isPVal ull1 \\<noteq> []\" by (induct ull1) auto\n      hence ull1NE: \"ull1 \\<noteq> []\" by auto\n      define uid where uid: \"uid \\<equiv> owner s PID\"  define p where p: \"p \\<equiv> pass s uid\"\n      define a1 where a1: \"a1 \\<equiv> Uact (uPost uid p PID pst1)\"\n      have uid1: \"uid = owner s1 PID\" and p1: \"p = pass s1 uid\" unfolding uid p\n      using eqButPID_stateSelectors[OF ss1] by auto\n      obtain ou1 s1' where step1: \"step s1 a1 = (ou1, s1')\" by(cases \"step s1 a1\") auto\n      have ou1: \"ou1 = outOK\" using step1 PID1 own1 unfolding a1 uid1 p1 by (auto simp: u_defs)\n      have op1': \"\\<not> open s1'\" using step1 op1 unfolding a1 ou1 open_def by (auto simp: u_defs)\n      have uid: \"uid \\<notin> UIDs\" unfolding uid using op PID own unfolding open_def by auto\n      have pPID1': \"post s1' PID = pst1\" using step1 unfolding a1 ou1 by (auto simp: u_defs)\n      let ?trn1 = \"Trans s1 a1 ou1 s1'\"\n      let ?vl1' = \"ull1 @ sul @ OVal True # vll1\"\n      have ?iact proof\n        show \"step s1 a1 = (ou1, s1')\" using step1 .\n      next\n        show \\<phi>: \"\\<phi> ?trn1\" unfolding \\<phi>_def2[OF step1] a1 ou1 by simp\n        show \"consume ?trn1 vl1 ?vl1'\"\n        using \\<phi> unfolding vl1 ul1 consume_def v1 a1 by simp\n      next\n        show \"\\<not> \\<gamma> ?trn1\" using uid unfolding a1 by auto\n      next\n        have \"eqButPID s1 s1'\" using Uact_uPaperC_step_eqButPID[OF _ step1] a1 by auto\n        hence ss1': \"eqButPID s s1'\" using eqButPID_trans ss1 by blast\n        have \"\\<Delta>31 s vl s1' ?vl1'\"\n        using PID op ss1' lul lul1 map ulul1 cor1 BO ull1NE ful ful1 full1 lastul ulul1 lsul\n        unfolding \\<Delta>31_def vl vl1 ul1 v1 pPID1' apply auto\n        apply(rule exI[of _ \"ul\"]) apply(rule exI[of _ \"ull1\"]) apply(rule exI[of _ sul])\n        apply(rule exI[of _ \"vll\"]) apply(rule exI[of _ \"vll1\"]) by auto\n        thus \"?\\<Delta> s vl s1' ?vl1'\" by auto\n      qed\n      thus ?thesis by simp\n    next\n      case False note lull1 = False\n      hence ull1: \"ull1 = []\" using lastul unfolding ulul1 ul1 v1 by simp(meson Bex_set last_in_set)\n      hence ul1: \"ul1 = [PVal pst1]\" unfolding ul1 v1 by simp\n      obtain ulll where ul_ulll: \"ul = ulll ## PVal pst1\" using lastul ulul1 ulNE unfolding ul1 ull1 v1\n      by (cases ul rule: rev_cases) auto\n      hence ulNE: \"ul \\<noteq> []\" by simp\n      (* then obtain v ul' where ul: \"ul = v # ul'\" by (cases ul) auto *)\n      have \"filter isPValS ulll = []\" using map unfolding ul_ulll ul1 v1 ull1 by simp\n      hence lull: \"list_all isPVal ulll\" using lul filter_list_all_isPVal_isOVal\n      unfolding ul_ulll by auto\n      have ?react  proof\n        fix a :: act and ou :: out and s' :: state and vl'\n        let ?trn = \"Trans s a ou s'\"\n        assume step: \"step s a = (ou, s')\" and c: \"consume ?trn vl vl'\"\n        have PID': \"PID \\<in>\\<in> postIDs s'\" using reach_postIDs_persist[OF PID step] .\n        obtain ul' where cc: \"consume ?trn ul ul'\" and\n        vl': \"vl' = ul' @ sul @ OVal True # vll\" using c ulNE unfolding consume_def vl\n        by (cases \"\\<phi> ?trn\") auto\n        obtain ou1 s1' where step1: \"step s1 a = (ou1, s1')\" by(cases \"step s1 a\") auto\n        let ?trn1 = \"Trans s1 a ou1 s1'\"\n        show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\"\n             (is \"?match \\<or> ?ignore\")\n        proof(cases ulll)\n          case Nil\n          hence ul: \"ul = [PVal pst1]\" unfolding ul_ulll by simp\n          have ?match proof(cases \"\\<phi> ?trn\")\n            case True note \\<phi> = True\n            then obtain f: \"f ?trn = PVal pst1\" and ul': \"ul' = []\"\n            using cc unfolding ul consume_def \\<phi>_def2 by auto\n            define uid where uid: \"uid \\<equiv> owner s PID\"  define p where p: \"p \\<equiv> pass s uid\"\n            have a: \"a = Uact (uPost uid p PID pst1)\"\n            using f_eq_PVal[OF step \\<phi> f] unfolding uid p .\n            have uid1: \"uid = owner s1 PID\" and p1: \"p = pass s1 uid\" unfolding uid p\n            using eqButPID_stateSelectors[OF ss1] by auto\n            obtain ou1 s1' where step1: \"step s1 a = (ou1, s1')\" by(cases \"step s1 a\") auto\n            let ?trn1 = \"Trans s1 a ou1 s1'\"\n            have \\<phi>1: \"\\<phi> ?trn1\" using eqButPID_step_\\<phi>_imp[OF ss1 step step1 \\<phi>] .\n            have ou1: \"ou1 = outOK\"\n            using \\<phi>1 step1 PID1 unfolding a by (cases ou1, auto simp: com_defs)\n            have pPID': \"post s' PID = pst1\" using step \\<phi> unfolding a by (auto simp: u_defs)\n            have pPID1': \"post s1' PID = pst1\" using step1 \\<phi>1 unfolding a by (auto simp: u_defs)\n            have uid: \"uid \\<notin> UIDs\" unfolding uid using op PID own unfolding open_def by auto\n            have op1': \"\\<not> open s1'\" using step1 op1 unfolding a open_def\n            by (auto simp: u_defs com_defs)\n            have f1: \"f ?trn1 = PVal pst1\" using \\<phi>1 unfolding \\<phi>_def2[OF step1] v1 a ou1 by auto\n            have s's1': \"eqButPID s' s1'\" using eqButPID_step[OF ss1 step step1] .\n            have op': \"\\<not> open s'\" using uPost_comSendPost_open_eq[OF step] a op by auto\n            have ou: \"ou = outOK\" using \\<phi> op op' unfolding \\<phi>_def2[OF step] a by auto\n            let ?vl' = \"sul @ OVal True # vll\"\n            let ?vl1' = \"sul @ OVal True # vll1\"\n            show ?thesis proof\n              show \"validTrans ?trn1\" using step1 by simp\n            next\n              show \"consume ?trn1 vl1 ?vl1'\"\n              using \\<phi>1 unfolding consume_def ul1 f1 vl1 by simp\n            next\n              show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n            next\n              assume \"\\<gamma> ?trn\" note \\<gamma> = this\n              thus \"g ?trn = g ?trn1\" using ou ou1 by (cases a) auto\n            next\n              have s': \"s' = s1'\" using eqButPID_step_eq[OF ss1 a ou step step1] .\n              have corr1: \"corrFrom (post s1' PID) ?vl1'\"\n              using cor1 unfolding vl1 ul1 v1 pPID1' by auto\n              have \"\\<Delta>32 s' vl' s1' ?vl1'\"\n              using PID' op1 op' s's1' lul lul1 map ulul1 cor1 BO ful ful1 lastul ulul1 lsul corr1\n              unfolding \\<Delta>32_def vl vl1 v1 vl' ul' ul ul1 s' apply simp\n              apply(rule exI[of _ sul])\n              apply(rule exI[of _ \"vll\"]) apply(rule exI[of _ \"vll1\"]) by auto\n              thus \"?\\<Delta> s' vl' s1' ?vl1'\" by simp\n            qed\n          next\n            case False note \\<phi> = False\n            hence ul': \"ul' = ul\" using cc unfolding consume_def by auto\n            obtain ou1 s1' where step1: \"step s1 a = (ou1, s1')\" by(cases \"step s1 a\") auto\n            have s's1': \"eqButPID s' s1'\" using eqButPID_step[OF ss1 step step1] .\n            let ?trn1 = \"Trans s1 a ou1 s1'\"\n            have \\<phi>1: \"\\<not> \\<phi> ?trn1\" using \\<phi> ss1 by (simp add: eqButPID_step_\\<phi> step step1)\n            have pPID1': \"post s1' PID = post s1 PID\" using PID1 step1 \\<phi>1\n              apply(cases a)\n              subgoal for x1 apply(cases x1) apply(fastforce simp: s_defs)+ .\n              subgoal for x2 apply(cases x2) apply(fastforce simp: c_defs)+ .\n              subgoal for x3 apply(cases x3) apply(fastforce simp: d_defs)+ .\n              subgoal for x4 apply(cases x4) apply(fastforce simp: u_defs)+ .\n              subgoal by fastforce\n              subgoal by fastforce\n              subgoal for x7 apply(cases x7) apply(fastforce simp: com_defs)+ .\n              done\n            have op': \"\\<not> open s'\" using PID step \\<phi> op unfolding \\<phi>_def2[OF step] by auto\n            have ?match proof\n              show \"validTrans ?trn1\" using step1 by simp\n            next\n              show \"consume ?trn1 vl1 vl1\" using \\<phi>1 unfolding consume_def by simp\n            next\n              show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n            next\n              assume \"\\<gamma> ?trn\" note \\<gamma> = this\n              have ou: \"(\\<exists> uid p aid pid.\n                 a = COMact (comSendPost uid p aid pid) \\<and> outPurge ou = outPurge ou1) \\<or>\n                 ou = ou1\"\n              using eqButPID_step_\\<gamma>_out[OF ss1 step step1 op rsT rs1 \\<gamma>] .\n              thus \"g ?trn = g ?trn1\" by (cases a) auto\n            next\n              have \"\\<Delta>31 s' vl' s1' vl1\"\n              using PID' pPID1' op' s's1' lul lul1 map ulul1 cor1\n              BO ful ful1 lastul ulul1 lsul cor1\n              unfolding \\<Delta>31_def vl vl1 v1 vl' ul' apply simp\n              apply(rule exI[of _ \"ul\"]) apply(rule exI[of _ \"ul1\"]) apply(rule exI[of _ sul])\n              apply(rule exI[of _ \"vll\"]) apply(rule exI[of _ \"vll1\"]) by auto\n              thus \"?\\<Delta> s' vl' s1' vl1\" by simp\n            qed\n            thus ?thesis by simp\n          qed\n          thus ?thesis by simp\n        next\n          case (Cons v ullll) note ulll = Cons\n          then obtain pst where v: \"v = PVal pst\" using lull ul_ulll ulll lul by (cases v) auto\n          define ull where ull: \"ull \\<equiv> ullll ## PVal pst1\"\n          have ul: \"ul = v # ull\" unfolding ul_ulll ull ulll by simp\n          show ?thesis proof(cases \"\\<phi> ?trn\")\n            case True note \\<phi> = True\n            then obtain f: \"f ?trn = v\" and ul': \"ul' = ull\"\n            using cc unfolding ul consume_def \\<phi>_def2 by auto\n            define uid where uid: \"uid \\<equiv> owner s PID\"  define p where p: \"p \\<equiv> pass s uid\"\n            have a: \"a = Uact (uPost uid p PID pst)\"\n            using f_eq_PVal[OF step \\<phi> f[unfolded v]] unfolding uid p .\n            have \"eqButPID s s'\" using Uact_uPaperC_step_eqButPID[OF a step] by auto\n            hence s's1: \"eqButPID s' s1\" using eqButPID_sym eqButPID_trans ss1 by blast\n            have op': \"\\<not> open s'\" using uPost_comSendPost_open_eq[OF step] a op by auto\n            have ?ignore proof\n              show \\<gamma>: \"\\<not> \\<gamma> ?trn\" using step_open_\\<phi>_f_PVal_\\<gamma>[OF rs step PID op \\<phi> f[unfolded v]] .\n              have \"\\<Delta>31 s' vl' s1 vl1\"\n              using PID' op' s's1 lul lul1 map ulul1 cor1 BO ful ful1 lastul ulul1 lsul ull\n              unfolding \\<Delta>31_def vl vl1 v1 vl' ul' ul v apply simp\n              apply(rule exI[of _ \"ull\"]) apply(rule exI[of _ \"ul1\"]) apply(rule exI[of _ sul])\n              apply(rule exI[of _ \"vll\"]) apply(rule exI[of _ \"vll1\"]) by auto\n              thus \"?\\<Delta> s' vl' s1 vl1\" by auto\n            qed\n            thus ?thesis by simp\n          next\n            case False note \\<phi> = False\n            hence ul': \"ul' = ul\" using cc unfolding consume_def by auto\n            obtain ou1 s1' where step1: \"step s1 a = (ou1, s1')\" by(cases \"step s1 a\") auto\n            have s's1': \"eqButPID s' s1'\" using eqButPID_step[OF ss1 step step1] .\n            let ?trn1 = \"Trans s1 a ou1 s1'\"\n            have \\<phi>1: \"\\<not> \\<phi> ?trn1\" using \\<phi> ss1 by (simp add: eqButPID_step_\\<phi> step step1)\n            have pPID1': \"post s1' PID = post s1 PID\" using PID1 step1 \\<phi>1\n              apply(cases a)\n              subgoal for x1 apply(cases x1) apply(fastforce simp: s_defs)+ .\n              subgoal for x2 apply(cases x2) apply(fastforce simp: c_defs)+ .\n              subgoal for x3 apply(cases x3) apply(fastforce simp: d_defs)+ .\n              subgoal for x4 apply(cases x4) apply(fastforce simp: u_defs)+ .\n              subgoal by fastforce\n              subgoal by fastforce\n              subgoal for x7 apply(cases x7) apply(fastforce simp: com_defs)+ .\n              done\n            have op': \"\\<not> open s'\" using PID step \\<phi> op unfolding \\<phi>_def2[OF step] by auto\n            have ?match proof\n              show \"validTrans ?trn1\" using step1 by simp\n            next\n              show \"consume ?trn1 vl1 vl1\" using \\<phi>1 unfolding consume_def by simp\n            next\n              show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n            next\n              assume \"\\<gamma> ?trn\" note \\<gamma> = this\n              have ou: \"(\\<exists> uid p aid pid.\n                 a = COMact (comSendPost uid p aid pid) \\<and> outPurge ou = outPurge ou1) \\<or>\n                 ou = ou1\"\n              using eqButPID_step_\\<gamma>_out[OF ss1 step step1 op rsT rs1 \\<gamma>] .\n              thus \"g ?trn = g ?trn1\" by (cases a) auto\n            next\n              have \"\\<Delta>31 s' vl' s1' vl1\"\n              using PID' pPID1' op' s's1' lul lul1 map ulul1 cor1\n              BO ful ful1 lastul ulul1 lsul cor1\n              unfolding \\<Delta>31_def vl vl1 v1 vl' ul' apply simp\n              apply(rule exI[of _ \"ul\"]) apply(rule exI[of _ \"ul1\"]) apply(rule exI[of _ sul])\n              apply(rule exI[of _ \"vll\"]) apply(rule exI[of _ \"vll1\"]) by auto\n              thus \"?\\<Delta> s' vl' s1' vl1\" by simp\n            qed\n          thus ?thesis by simp\n          qed\n        qed\n      qed\n      thus ?thesis using vl by simp\n    qed\n  next\n    case (PValS aid1 pst1) note v1 = PValS\n    have pPID1: \"post s1 PID = pst1\" using cor1 unfolding vl1 ul1 v1 by auto\n    then obtain v ull where ul: \"ul = v # ull\"\n    using map unfolding ul1 v1 by (cases ul) auto\n    let ?vl1' = \"ull1 @ sul @ OVal True # vll1\"\n    have ?react proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\"\n      assume step: \"step s a = (ou, s')\" and c: \"consume ?trn vl vl'\"\n      have PID': \"PID \\<in>\\<in> postIDs s'\" using reach_postIDs_persist[OF PID step] .\n      obtain ul' where cc: \"consume ?trn ul ul'\" and\n      vl': \"vl' = ul' @ sul @ OVal True # vll\" using c ul unfolding consume_def vl\n      by (cases \"\\<phi> ?trn\") auto\n      obtain ou1 s1' where step1: \"step s1 a = (ou1, s1')\" by(cases \"step s1 a\") auto\n      let ?trn1 = \"Trans s1 a ou1 s1'\"\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\"\n          (is \"?match \\<or> ?ignore\")\n      proof(cases \"\\<phi> ?trn\")\n        case True note \\<phi> = True\n        then obtain f: \"f ?trn = v\" and ul': \"ul' = ull\"\n        using cc unfolding ul consume_def \\<phi>_def2 by auto\n        show ?thesis\n        proof(cases v)\n          case (PVal pst) note v = PVal\n          have full: \"ull \\<noteq> []\" using map unfolding ul1 v1 ul v by auto\n          define uid where uid: \"uid \\<equiv> owner s PID\"  define p where p: \"p \\<equiv> pass s uid\"\n          have a: \"a = Uact (uPost uid p PID pst)\"\n          using f_eq_PVal[OF step \\<phi> f[unfolded v]] unfolding uid p .\n          have \"eqButPID s s'\" using Uact_uPaperC_step_eqButPID[OF a step] by auto\n          hence s's1: \"eqButPID s' s1\" using eqButPID_sym eqButPID_trans ss1 by blast\n          have op': \"\\<not> open s'\" using uPost_comSendPost_open_eq[OF step] a op by auto\n          (* have \"list_ex isPVal ull1\" using lastul not_list_ex_filter\n          using ful1 not_list_ex_filter ul1 v1 unfolding ulul1 by auto\n          hence lull: \"list_ex isPVal ull\" using lastul ulul1 ull unfolding ul ul1 v v1\n          by (metis filter_empty_conv last_ConsR last_in_set not_list_ex_filter)\n          hence full: \"filter isPVal ull \\<noteq> []\" by (induct ull) auto *)\n          have ?ignore proof\n            show \\<gamma>: \"\\<not> \\<gamma> ?trn\" using step_open_\\<phi>_f_PVal_\\<gamma>[OF rs step PID op \\<phi> f[unfolded v]] .\n            have \"\\<Delta>31 s' vl' s1 vl1\"\n            using PID' op' s's1 lul lul1 map ulul1 cor1 BO ful ful1 lastul ulul1 lsul full\n            unfolding \\<Delta>31_def vl vl1 v1 vl' ul' ul v apply simp\n            apply(rule exI[of _ \"ull\"]) apply(rule exI[of _ \"ul1\"]) apply(rule exI[of _ sul])\n            apply(rule exI[of _ \"vll\"]) apply(rule exI[of _ \"vll1\"]) by auto\n            thus \"?\\<Delta> s' vl' s1 vl1\" by auto\n          qed\n          thus ?thesis by simp\n        next\n          case (PValS aid pst) note v = PValS\n          define uid where uid: \"uid \\<equiv> admin s\" define p where p: \"p \\<equiv> pass s uid\"\n          have a: \"a = COMact (comSendPost (admin s) p aid PID)\"\n          using f_eq_PValS[OF step \\<phi> f[unfolded v]] unfolding uid p .\n          have op': \"\\<not> open s'\" using uPost_comSendPost_open_eq[OF step] a op by auto\n          have aid1: \"aid1 = aid\" using map unfolding ul1 v1 ul v by simp\n          have uid1: \"uid = admin s1\" and p1: \"p = pass s1 uid\" unfolding uid p\n          using eqButPID_stateSelectors[OF ss1] by auto\n          obtain ou1 s1' where step1: \"step s1 a = (ou1, s1')\" by(cases \"step s1 a\") auto\n          have pPID1': \"post s1' PID = pst1\" using pPID1 step1 unfolding a\n          by (auto simp: com_defs)\n          have uid: \"uid \\<notin> UIDs\" unfolding uid using op PID adm unfolding open_def by auto\n          have op1': \"\\<not> open s1'\" using step1 op1 unfolding a open_def\n          by (auto simp: u_defs com_defs)\n          let ?trn1 = \"Trans s1 a ou1 s1'\"\n          have \\<phi>1: \"\\<phi> ?trn1\" using eqButPID_step_\\<phi>_imp[OF ss1 step step1 \\<phi>] .\n          have ou1: \"ou1 =\n            O_sendPost (aid, clientPass s1 aid, PID, post s1 PID, owner s1 PID, vis s1 PID)\"\n          using \\<phi>1 step1 adm1 PID1 unfolding a by (cases ou1, auto simp: com_defs)\n          have f1: \"f ?trn1 = v1\" using \\<phi>1 unfolding \\<phi>_def2[OF step1] v1 a ou1 aid1 pPID1 by auto\n          have s's1': \"eqButPID s' s1'\" using eqButPID_step[OF ss1 step step1] .\n          have ?match proof\n            show \"validTrans ?trn1\" using step1 by simp\n          next\n            show \"consume ?trn1 vl1 ?vl1'\" using \\<phi>1 unfolding consume_def ul1 f1 vl1 by simp\n          next\n            show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n          next\n            assume \"\\<gamma> ?trn\" note \\<gamma> = this\n            have ou: \"(\\<exists> uid p aid pid.\n               a = COMact (comSendPost uid p aid pid) \\<and> outPurge ou = outPurge ou1) \\<or>\n               ou = ou1\"\n            using eqButPID_step_\\<gamma>_out[OF ss1 step step1 op rsT rs1 \\<gamma>] .\n            thus \"g ?trn = g ?trn1\" by (cases a) auto\n          next\n            have corr1: \"corrFrom (post s1' PID) ?vl1'\"\n            using cor1 unfolding vl1 ul1 v1 pPID1' by auto\n            have ullull1: \"ull1 \\<noteq> [] \\<longrightarrow> ull \\<noteq> []\" using ul ul1 lastul ulul1 unfolding v v1\n            by fastforce\n            have \"\\<Delta>31 s' vl' s1' ?vl1'\"\n            using PID' op' s's1' lul lul1 map ulul1 cor1 BO ful ful1 lastul ulul1 lsul corr1 ullull1\n            unfolding \\<Delta>31_def vl vl1 v1 vl' ul' ul ul1 v apply auto\n            apply(rule exI[of _ \"ull\"]) apply(rule exI[of _ \"ull1\"]) apply(rule exI[of _ sul])\n            apply(rule exI[of _ \"vll\"]) apply(rule exI[of _ \"vll1\"]) by auto\n            thus \"?\\<Delta> s' vl' s1' ?vl1'\" by simp\n          qed\n          thus ?thesis using ul by simp\n        next\n        qed(insert lul ul, auto)\n      next\n        case False note \\<phi> = False\n        hence ul': \"ul' = ul\" using cc unfolding consume_def by auto\n        obtain ou1 s1' where step1: \"step s1 a = (ou1, s1')\" by(cases \"step s1 a\") auto\n        have s's1': \"eqButPID s' s1'\" using eqButPID_step[OF ss1 step step1] .\n        let ?trn1 = \"Trans s1 a ou1 s1'\"\n        have \\<phi>1: \"\\<not> \\<phi> ?trn1\" using \\<phi> ss1 by (simp add: eqButPID_step_\\<phi> step step1)\n        have pPID1': \"post s1' PID = pst1\" using PID1 pPID1 step1 \\<phi>1\n          apply(cases a)\n          subgoal for x1 apply(cases x1) apply(fastforce simp: s_defs)+ .\n          subgoal for x2 apply(cases x2) apply(fastforce simp: c_defs)+ .\n          subgoal for x3 apply(cases x3) apply(fastforce simp: d_defs)+ .\n          subgoal for x4 apply(cases x4) apply(fastforce simp: u_defs)+ .\n          subgoal by fastforce\n          subgoal by fastforce\n          subgoal for x7 apply(cases x7) apply(fastforce simp: com_defs)+ .\n          done\n        have op': \"\\<not> open s'\" using PID step \\<phi> op unfolding \\<phi>_def2[OF step] by auto\n        have ?match proof\n          show \"validTrans ?trn1\" using step1 by simp\n        next\n          show \"consume ?trn1 vl1 vl1\" using \\<phi>1 unfolding consume_def by simp\n        next\n          show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n        next\n          assume \"\\<gamma> ?trn\" note \\<gamma> = this\n          have ou: \"(\\<exists> uid p aid pid.\n                 a = COMact (comSendPost uid p aid pid) \\<and> outPurge ou = outPurge ou1) \\<or>\n                 ou = ou1\"\n          using eqButPID_step_\\<gamma>_out[OF ss1 step step1 op rsT rs1 \\<gamma>] .\n          thus \"g ?trn = g ?trn1\" by (cases a) auto\n        next\n          have \"\\<Delta>31 s' vl' s1' vl1\"\n          using PID' pPID1 pPID1' op' s's1' lul lul1 map ulul1 cor1\n            BO ful ful1 lastul ulul1 lsul cor1\n          unfolding \\<Delta>31_def vl vl1 v1 vl' ul' apply simp\n          apply(rule exI[of _ \"ul\"]) apply(rule exI[of _ \"ul1\"]) apply(rule exI[of _ sul])\n          apply(rule exI[of _ \"vll\"]) apply(rule exI[of _ \"vll1\"]) by auto\n          thus \"?\\<Delta> s' vl' s1' vl1\" by simp\n        qed\n        thus ?thesis by simp\n      qed\n    qed\n    thus ?thesis using vl by simp\n  qed(insert lul1 ul1, auto)\nqed\n\nlemma unwind_cont_\\<Delta>32: \"unwind_cont \\<Delta>32 {\\<Delta>2,\\<Delta>32,\\<Delta>4}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>2 s vl s1 vl1 \\<or> \\<Delta>32 s vl s1 vl1 \\<or> \\<Delta>4 s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \"\\<Delta>32 s vl s1 vl1\"\n  then obtain ul vll vll1 where\n  lul: \"list_all isPValS ul\"\n  and rs: \"reach s\" and ss1: \"s1 = s\" and op: \"\\<not> open s\" and PID: \"PID \\<in>\\<in> postIDs s\"\n  and cor1: \"corrFrom (post s1 PID) vl1\"\n  and vl: \"vl = ul @ OVal True # vll\"\n  and vl1: \"vl1 = ul @ OVal True # vll1\"\n  and BO: \"BO vll vll1\"\n  using reachNT_reach unfolding \\<Delta>32_def by blast\n  have own: \"owner s PID \\<in> set (userIDs s)\" using reach_owner_userIDs[OF rs PID] .\n  have adm: \"admin s \\<in> set (userIDs s)\" using reach_admin_userIDs[OF rs own] .\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof-\n    have ?react proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\" let ?trn1 = \"Trans s1 a ou s'\"\n      assume step: \"step s a = (ou, s')\" and c: \"consume ?trn vl vl'\"\n      have PID': \"PID \\<in>\\<in> postIDs s'\" using reach_postIDs_persist[OF PID step] .\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\"\n          (is \"?match \\<or> ?ignore\")\n      proof-\n        have ?match proof(cases \"ul = []\")\n          case False note ul = False\n          then obtain ul' where cc: \"consume ?trn ul ul'\"\n          and vl': \"vl' = ul' @ OVal True # vll\" using vl c unfolding consume_def\n          by (cases \"\\<phi> ?trn\") auto\n          let ?vl1' = \"ul' @ OVal True # vll1\"\n          show ?thesis proof\n            show \"validTrans ?trn1\" using step unfolding ss1 by simp\n          next\n            show \"consume ?trn1 vl1 ?vl1'\" using cc ul unfolding vl1 consume_def ss1\n            by (cases \"\\<phi> ?trn\") auto\n          next\n            show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n          next\n            assume \"\\<gamma> ?trn\" note \\<gamma> = this\n            thus \"g ?trn = g ?trn1\" unfolding ss1 by simp\n          next\n            have \"\\<Delta>32 s' vl' s' ?vl1'\"\n            proof(cases \"\\<phi> ?trn\")\n              case True note \\<phi> = True\n              then obtain v where f: \"f ?trn = v\" and  ul: \"ul = v # ul'\"\n              using cc unfolding consume_def by (cases ul) auto\n              define uid where uid: \"uid \\<equiv> admin s\" define p where p: \"p \\<equiv> pass s uid\"\n              obtain aid pst where v: \"v = PValS aid pst\" using lul unfolding ul by (cases v) auto\n              have a: \"a = COMact (comSendPost (admin s) p aid PID)\"\n              using f_eq_PValS[OF step \\<phi> f[unfolded v]] unfolding uid p .\n              have op': \"\\<not> open s'\" using uPost_comSendPost_open_eq[OF step] a op by auto\n              have pPID': \"post s' PID = post s PID\"\n              using step unfolding a by (auto simp: com_defs)\n              show ?thesis using PID' pPID' op' cor1 BO lul\n              unfolding \\<Delta>32_def vl1 ul ss1 v vl' by auto\n            next\n              case False note \\<phi> = False\n              hence ul: \"ul = ul'\" using cc unfolding consume_def by (cases ul) auto\n              have pPID': \"post s' PID = post s PID\"\n                using step \\<phi> PID op\n                apply(cases a)\n                subgoal for x1 apply(cases x1) apply(fastforce simp: s_defs)+ .\n                subgoal for x2 apply(cases x2) apply(fastforce simp: c_defs)+ .\n                subgoal for x3 apply(cases x3) apply(fastforce simp: d_defs)+ .\n                subgoal for x4 apply(cases x4) apply(fastforce simp: u_defs)+ .\n                subgoal by fastforce\n                subgoal by fastforce\n                subgoal for x7 apply(cases x7) apply(fastforce simp: com_defs)+ .\n                done\n              have op': \"\\<not> open s'\" using PID step \\<phi> op unfolding \\<phi>_def2[OF step] by auto\n              show ?thesis using PID' pPID' op' cor1 BO lul\n              unfolding \\<Delta>32_def vl1 ul ss1 vl' by auto\n            qed\n            thus \"?\\<Delta> s' vl' s' ?vl1'\" by simp\n          qed\n        next\n          case True note ul = True\n          show ?thesis proof(cases \"\\<phi> ?trn\")\n            case True note \\<phi> = True\n            hence f: \"f ?trn = OVal True\" and vl': \"vl' = vll\"\n            using vl c unfolding consume_def ul by auto\n            have op': \"open s'\" using f_eq_OVal[OF step \\<phi> f] op by simp\n            show ?thesis proof\n              show \"validTrans ?trn1\" using step unfolding ss1 by simp\n            next\n              show \"consume ?trn1 vl1 vll1\" using ul \\<phi> c\n              unfolding vl1 vl' vl ss1 consume_def by auto\n            next\n              show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n            next\n              assume \"\\<gamma> ?trn\" note \\<gamma> = this\n              thus \"g ?trn = g ?trn1\" unfolding ss1 by simp\n            next\n              have pPID': \"post s' PID = post s PID\"\n                using step \\<phi> PID op op' f\n                apply(cases a)\n                subgoal for x1 apply(cases x1) apply(fastforce simp: s_defs)+ .\n                subgoal for x2 apply(cases x2) apply(fastforce simp: c_defs)+ .\n                subgoal for x3 apply(cases x3) apply(fastforce simp: d_defs)+ .\n                subgoal for x4 apply(cases x4) apply(fastforce simp: u_defs)+ .\n                subgoal by fastforce\n                subgoal by fastforce\n                subgoal for x7 apply(cases x7) apply(fastforce simp: com_defs)+ .\n                done\n              show \"?\\<Delta> s' vl' s' vll1\" using BO proof cases\n                case BO_PVal\n                hence \"\\<Delta>2 s' vl' s' vll1\" using PID' pPID' op' cor1 BO lul\n                unfolding \\<Delta>2_def vl1 ul ss1 vl' by auto\n                thus ?thesis by simp\n              next\n                case BO_BC\n                hence \"\\<Delta>4 s' vl' s' vll1\" using PID' pPID' op' cor1 BO lul\n                unfolding \\<Delta>4_def vl1 ul ss1 vl' by auto\n                thus ?thesis by simp\n              qed\n            qed\n          next\n            case False note \\<phi> = False\n            hence vl': \"vl' = vl\" using c unfolding consume_def by auto\n            have pPID': \"post s' PID = post s PID\"\n              using step \\<phi> PID op\n              apply(cases a)\n              subgoal for x1 apply(cases x1) apply(fastforce simp: s_defs)+ .\n              subgoal for x2 apply(cases x2) apply(fastforce simp: c_defs)+ .\n              subgoal for x3 apply(cases x3) apply(fastforce simp: d_defs)+ .\n              subgoal for x4 apply(cases x4) apply(fastforce simp: u_defs)+ .\n              subgoal by fastforce\n              subgoal by fastforce\n              subgoal for x7 apply(cases x7) apply(fastforce simp: com_defs)+ .\n              done\n            have op': \"\\<not> open s'\" using PID step \\<phi> op unfolding \\<phi>_def2[OF step] by auto\n            show ?thesis proof\n              show \"validTrans ?trn1\" using step unfolding ss1 by simp\n            next\n              show \"consume ?trn1 vl1 vl1\" using ul \\<phi> unfolding vl1 consume_def ss1 by simp\n            next\n              show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n            next\n              assume \"\\<gamma> ?trn\" note \\<gamma> = this\n              thus \"g ?trn = g ?trn1\" unfolding ss1 by simp\n            next\n              have \"\\<Delta>32 s' vl' s' vl1\" using PID' pPID' op' cor1 BO lul\n              unfolding \\<Delta>32_def vl vl1 ul ss1 vl' apply simp\n              apply(rule exI[of _ \"[]\"])\n              apply(rule exI[of _ vll]) apply(rule exI[of _ vll1]) by auto\n              thus \"?\\<Delta> s' vl' s' vl1\" by simp\n            qed\n          qed\n        qed\n        thus ?thesis by simp\n      qed\n    qed\n  thus ?thesis using vl by simp\n  qed\nqed\n\nlemma unwind_cont_\\<Delta>2: \"unwind_cont \\<Delta>2 {\\<Delta>2}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>2 s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \"\\<Delta>2 s vl s1 vl1\"\n  hence vlvl1: \"vl = vl1\"\n  and rs: \"reach s\" and ss1: \"s1 = s\" and op: \"open s\" and PID: \"PID \\<in>\\<in> postIDs s\"\n  and cor1: \"corrFrom (post s1 PID) vl1\" and lvl: \"list_all (Not \\<circ> isOVal) vl\"\n  using reachNT_reach unfolding \\<Delta>2_def by auto\n  have own: \"owner s PID \\<in> set (userIDs s)\" using reach_owner_userIDs[OF rs PID] .\n  have adm: \"admin s \\<in> set (userIDs s)\" using reach_admin_userIDs[OF rs own] .\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof-\n    have ?react proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\"  let ?trn1 = \"Trans s1 a ou s'\"\n      assume step: \"step s a = (ou, s')\" and c: \"consume ?trn vl vl'\"\n      have PID': \"PID \\<in>\\<in> postIDs s'\" using reach_postIDs_persist[OF PID step] .\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n      proof-\n        have ?match proof(cases \"\\<phi> ?trn\")\n          case True note \\<phi> = True\n          then obtain v where vl: \"vl = v # vl'\" and f: \"f ?trn = v\"\n          using c unfolding consume_def \\<phi>_def2 by(cases vl) auto\n          show ?thesis proof(cases v)\n            case (PVal pst) note v = PVal\n            have a: \"a = Uact (uPost (owner s PID) (pass s (owner s PID)) PID pst)\"\n            using f_eq_PVal[OF step \\<phi> f[unfolded v]] .\n            have ou: \"ou = outOK\" using step own PID unfolding a by (auto simp: u_defs)\n            have op': \"open s'\" using step op PID PID' \\<phi>\n            unfolding open_def a by (auto simp: u_defs)\n            have pPID': \"post s' PID = pst\"\n            using step \\<phi> PID op f op' unfolding a by(auto simp: u_defs)\n            show ?thesis proof\n              show \"validTrans ?trn1\" unfolding ss1 using step by simp\n            next\n              show \"consume ?trn1 vl1 vl'\" using \\<phi> vlvl1 unfolding ss1 consume_def vl f by auto\n            next\n              show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n            next\n              assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\" unfolding ss1 by simp\n            next\n              show \"?\\<Delta> s' vl' s' vl'\" using cor1 PID' pPID' op' lvl vlvl1 ss1\n              unfolding \\<Delta>2_def vl v by auto\n            qed\n          next\n            case (PValS aid pid) note v = PValS\n            have a: \"a = COMact (comSendPost (admin s) (pass s (admin s)) aid PID)\"\n            using f_eq_PValS[OF step \\<phi> f[unfolded v]] .\n            have op': \"open s'\" using step op PID PID' \\<phi>\n            unfolding open_def a by (auto simp: com_defs)\n            have ou: \"ou \\<noteq> outErr\" using \\<phi> op op' unfolding \\<phi>_def2[OF step] unfolding a by auto\n            have pPID': \"post s' PID = post s PID\"\n            using step \\<phi> PID op f op' unfolding a by(auto simp: com_defs)\n            show ?thesis proof\n              show \"validTrans ?trn1\" unfolding ss1 using step by simp\n            next\n              show \"consume ?trn1 vl1 vl'\" using \\<phi> vlvl1 unfolding ss1 consume_def vl f by auto\n            next\n              show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n            next\n              assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\" unfolding ss1 by simp\n            next\n              show \"?\\<Delta> s' vl' s' vl'\" using cor1 PID' pPID' op' lvl vlvl1 ss1\n              unfolding \\<Delta>2_def vl v by auto\n            qed\n          qed(insert vl lvl, auto)\n        next\n          case False note \\<phi> = False\n          hence vl': \"vl' = vl\" using c unfolding consume_def by auto\n          have pPID': \"post s' PID = post s PID\"\n            using step \\<phi> PID op\n            apply(cases a)\n            subgoal for x1 apply(cases x1) apply(fastforce simp: s_defs)+ .\n            subgoal for x2 apply(cases x2) apply(fastforce simp: c_defs)+ .\n            subgoal for x3 apply(cases x3) apply(fastforce simp: d_defs)+ .\n            subgoal for x4 apply(cases x4) apply(fastforce simp: u_defs)+ .\n            subgoal by fastforce\n            subgoal by fastforce\n            subgoal for x7 apply(cases x7) apply(fastforce simp: com_defs)+ .\n            done\n          have op': \"open s'\" using PID step \\<phi> op unfolding \\<phi>_def2[OF step] by auto\n          show ?thesis proof\n            show \"validTrans ?trn1\" unfolding ss1 using step by simp\n          next\n            show \"consume ?trn1 vl1 vl\" using \\<phi> vlvl1 unfolding ss1 consume_def vl' by simp\n          next\n            show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n          next\n            assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\" unfolding ss1 by simp\n          next\n            show \"?\\<Delta> s' vl' s' vl\" using cor1 PID' op' lvl vlvl1 pPID'\n            unfolding \\<Delta>2_def vl' ss1 by auto\n          qed\n        qed\n      thus ?thesis by simp\n      qed\n    qed\n  thus ?thesis using vlvl1 by simp\n  qed\nqed\n\nlemma unwind_cont_\\<Delta>4: \"unwind_cont \\<Delta>4 {\\<Delta>1,\\<Delta>31,\\<Delta>32,\\<Delta>4}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>1 s vl s1 vl1 \\<or> \\<Delta>31 s vl s1 vl1 \\<or> \\<Delta>32 s vl s1 vl1 \\<or> \\<Delta>4 s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \"\\<Delta>4 s vl s1 vl1\"\n  then obtain ul vll vll1 where vl: \"vl = ul @ OVal False # vll\" and vl1: \"vl1 = ul @ OVal False # vll1\"\n  and rs: \"reach s\" and ss1: \"s1 = s\" and op: \"open s\" and PID: \"PID \\<in>\\<in> postIDs s\"\n  and cor1: \"corrFrom (post s1 PID) vl1\" and lul: \"list_all (Not \\<circ> isOVal) ul\"\n  and BC: \"BC vll vll1\"\n  using reachNT_reach unfolding \\<Delta>4_def by blast\n  have own: \"owner s PID \\<in> set (userIDs s)\" using reach_owner_userIDs[OF rs PID] .\n  have adm: \"admin s \\<in> set (userIDs s)\" using reach_admin_userIDs[OF rs own] .\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof-\n    have ?react proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\"  let ?trn1 = \"Trans s1 a ou s'\"\n      assume step: \"step s a = (ou, s')\" and c: \"consume ?trn vl vl'\"\n      have PID': \"PID \\<in>\\<in> postIDs s'\" using reach_postIDs_persist[OF PID step] .\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n      proof-\n        have ?match proof(cases \"\\<phi> ?trn\")\n          case True note \\<phi> = True\n          then obtain v where vl_vl': \"vl = v # vl'\" and f: \"f ?trn = v\"\n          using c unfolding consume_def \\<phi>_def2 by(cases vl) auto\n          show ?thesis proof(cases \"ul = []\")\n            case False note ul = False\n            then obtain ul' where ul: \"ul = v # ul'\" and vl': \"vl' = ul' @ OVal False # vll\"\n            using c \\<phi> f unfolding consume_def vl by (cases ul) auto\n            let ?vl1' = \"ul' @ OVal False # vll1\"\n            show ?thesis proof(cases v)\n              case (PVal pst) note v = PVal\n              have a: \"a = Uact (uPost (owner s PID) (pass s (owner s PID)) PID pst)\"\n              using f_eq_PVal[OF step \\<phi> f[unfolded v]] .\n              have ou: \"ou = outOK\" using step own PID unfolding a by (auto simp: u_defs)\n              have op': \"open s'\" using step op PID PID' \\<phi>\n              unfolding open_def a by (auto simp: u_defs)\n              have pPID': \"post s' PID = pst\"\n              using step \\<phi> PID op f op' unfolding a by(auto simp: u_defs)\n              show ?thesis proof\n                show \"validTrans ?trn1\" unfolding ss1 using step by simp\n              next\n                show \"consume ?trn1 vl1 ?vl1'\" using \\<phi>\n                unfolding ss1 consume_def vl f ul vl1 vl' by simp\n              next\n                show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n              next\n                assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\" unfolding ss1 by simp\n              next\n                have \"\\<Delta>4 s' vl' s' ?vl1'\" using cor1 PID' pPID' op' vl1 ss1 lul BC\n                unfolding \\<Delta>4_def vl v ul vl' apply simp\n                apply(rule exI[of _ ul'])\n                apply(rule exI[of _ vll]) apply(rule exI[of _ vll1])\n                by auto\n                thus \"?\\<Delta> s' vl' s' ?vl1'\" by simp\n              qed\n            next\n              case (PValS aid pid) note v = PValS\n              have a: \"a = COMact (comSendPost (admin s) (pass s (admin s)) aid PID)\"\n              using f_eq_PValS[OF step \\<phi> f[unfolded v]] .\n              have op': \"open s'\" using step op PID PID' \\<phi>\n              unfolding open_def a by (auto simp: com_defs)\n              have ou: \"ou \\<noteq> outErr\" using \\<phi> op op' unfolding \\<phi>_def2[OF step] unfolding a by auto\n              have pPID': \"post s' PID = post s PID\"\n              using step \\<phi> PID op f op' unfolding a by(auto simp: com_defs)\n              show ?thesis proof\n                show \"validTrans ?trn1\" unfolding ss1 using step by simp\n              next\n                show \"consume ?trn1 vl1 ?vl1'\" using \\<phi>\n                unfolding ss1 consume_def vl f ul vl1 vl' by simp\n              next\n                show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n              next\n                assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\" unfolding ss1 by simp\n              next\n                have \"\\<Delta>4 s' vl' s' ?vl1'\" using cor1 PID' pPID' op' vl1 ss1 lul BC\n                unfolding \\<Delta>4_def vl v ul vl' by auto\n                thus \"?\\<Delta> s' vl' s' ?vl1'\" by simp\n              qed\n            qed(insert vl lul ul, auto)\n          next\n            case True note ul = True\n            hence f: \"f ?trn = OVal False\" and vl': \"vl' = vll\"\n            using vl c f \\<phi> unfolding consume_def ul by auto\n            have op': \"\\<not> open s'\" using f_eq_OVal[OF step \\<phi> f] op by simp\n            show ?thesis proof\n              show \"validTrans ?trn1\" using step unfolding ss1 by simp\n            next\n              show \"consume ?trn1 vl1 vll1\" using ul \\<phi> c\n              unfolding vl1 vl' vl ss1 consume_def by auto\n            next\n              show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n            next\n              assume \"\\<gamma> ?trn\" note \\<gamma> = this\n              thus \"g ?trn = g ?trn1\" unfolding ss1 by simp\n            next\n              have pPID': \"post s' PID = post s PID\"\n                using step \\<phi> PID op op' f\n                apply(cases a)\n                subgoal for x1 apply(cases x1) apply(fastforce simp: s_defs)+ .\n                subgoal for x2 apply(cases x2) apply(fastforce simp: c_defs)+ .\n                subgoal for x3 apply(cases x3) apply(fastforce simp: d_defs)+ .\n                subgoal for x4 apply(cases x4) apply(fastforce simp: u_defs)+ .\n                subgoal by fastforce\n                subgoal by fastforce\n                subgoal for x7 apply(cases x7) apply(fastforce simp: com_defs)+ .\n                done\n              show \"?\\<Delta> s' vl' s' vll1\" using BC proof cases\n                case BC_PVal\n                hence \"\\<Delta>1 s' vl' s' vll1\" using PID' pPID' op' cor1 BC lul\n                unfolding \\<Delta>1_def vl1 ul ss1 vl' by auto\n                thus ?thesis by simp\n              next\n                case (BC_BO Vll Vll1 Ul Ul1 Sul)\n                show ?thesis proof(cases \"Ul \\<noteq> [] \\<and> Ul1 \\<noteq> []\")\n                  case True\n                  hence \"\\<Delta>31 s' vl' s' vll1\" using PID' pPID' op' cor1 BC BC_BO lul\n                  unfolding \\<Delta>31_def vl1 ul ss1 vl' apply simp\n                  apply(rule exI[of _ Ul]) apply(rule exI[of _ Ul1])\n                  apply(rule exI[of _ Sul])\n                  apply(rule exI[of _ Vll]) apply(rule exI[of _ Vll1])\n                  by auto\n                  thus ?thesis by simp\n                next\n                  case False\n                  hence 0: \"Ul = []\" \"Ul1 = []\" using BC_BO by auto\n                  hence \"\\<Delta>32 s' vl' s' vll1\" using PID' pPID' op' cor1 BC BC_BO lul\n                  unfolding \\<Delta>32_def vl1 ul ss1 vl' apply simp\n                  apply(rule exI[of _ Sul])\n                  apply(rule exI[of _ Vll]) apply(rule exI[of _ Vll1])\n                  by auto\n                  thus ?thesis by simp\n                qed\n              qed\n            qed\n          qed\n        next\n          case False note \\<phi> = False\n          hence vl': \"vl' = vl\" using c unfolding consume_def by auto\n          have pPID': \"post s' PID = post s PID\"\n            using step \\<phi> PID op\n            apply(cases a)\n            subgoal for x1 apply(cases x1) apply(fastforce simp: s_defs)+ .\n            subgoal for x2 apply(cases x2) apply(fastforce simp: c_defs)+ .\n            subgoal for x3 apply(cases x3) apply(fastforce simp: d_defs)+ .\n            subgoal for x4 apply(cases x4) apply(fastforce simp: u_defs)+ .\n            subgoal by fastforce\n            subgoal by fastforce\n            subgoal for x7 apply(cases x7) apply(fastforce simp: com_defs)+ .\n            done\n          have op': \"open s'\" using PID step \\<phi> op unfolding \\<phi>_def2[OF step] by auto\n          show ?thesis proof\n            show \"validTrans ?trn1\" unfolding ss1 using step by simp\n          next\n            show \"consume ?trn1 vl1 vl1\" using \\<phi> unfolding ss1 consume_def vl' vl vl1 by simp\n          next\n            show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n          next\n            assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\" unfolding ss1 by simp\n          next\n            have \"\\<Delta>4 s' vl' s' vl1\" using cor1 PID' pPID' op' vl1 ss1 lul BC\n            unfolding \\<Delta>4_def vl vl' by auto\n            thus \"?\\<Delta> s' vl' s' vl1\" by simp\n          qed\n        qed\n      thus ?thesis by simp\n      qed\n    qed\n  thus ?thesis using vl by simp\n  qed\nqed\n\ndefinition Gr where\n\"Gr =\n {\n (\\<Delta>0, {\\<Delta>0,\\<Delta>1,\\<Delta>2,\\<Delta>31,\\<Delta>32,\\<Delta>4}),\n (\\<Delta>1, {\\<Delta>1,\\<Delta>11}),\n (\\<Delta>11, {\\<Delta>11}),\n (\\<Delta>2, {\\<Delta>2}),\n (\\<Delta>31, {\\<Delta>31,\\<Delta>32}),\n (\\<Delta>32, {\\<Delta>2,\\<Delta>32,\\<Delta>4}),\n (\\<Delta>4, {\\<Delta>1,\\<Delta>31,\\<Delta>32,\\<Delta>4})\n }\"\n\n\ntheorem secure: secure\napply (rule unwind_decomp_secure_graph[of Gr \\<Delta>0])\nunfolding Gr_def\napply (simp, smt insert_subset order_refl)\nusing\nistate_\\<Delta>0 unwind_cont_\\<Delta>0 unwind_cont_\\<Delta>1 unwind_cont_\\<Delta>11\nunwind_cont_\\<Delta>31 unwind_cont_\\<Delta>32 unwind_cont_\\<Delta>2 unwind_cont_\\<Delta>4\nunfolding Gr_def by auto\n\n\n\n\nend\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/CoSMeDis/Post_Confidentiality/DYNAMIC_Post_ISSUER.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6113819732941511, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.28661013836855453}}
{"text": "(*  Title:      HOL/Auth/n_german.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\n(*header{*The n_german Protocol Case Study*}*) \n\ntheory n_german imports n_german_lemma_invs_on_rules n_german_on_inis\nbegin\nlemma main:\nassumes a1: \"s \\<in> reachableSet {andList (allInitSpecs N)} (rules N)\"\nand a2: \"0 < N\"\nshows \"\\<forall> f. f \\<in> (invariants N) --> formEval f s\"\nproof (rule consistentLemma)\nshow \"consistent (invariants N) {andList (allInitSpecs N)} (rules N)\"\nproof (cut_tac a1, unfold consistent_def, rule conjI)\nshow \"\\<forall> f ini s. f \\<in> (invariants N) --> ini \\<in> {andList (allInitSpecs N)} --> formEval ini s --> formEval f s\"\nproof ((rule allI)+, (rule impI)+)\n  fix f ini s\n  assume b1: \"f \\<in> (invariants N)\" and b2: \"ini \\<in> {andList (allInitSpecs N)}\" and b3: \"formEval ini s\"\n  have b4: \"formEval (andList (allInitSpecs N)) s\"\n  apply (cut_tac b2 b3, simp) done\n  show \"formEval f s\"\n  apply (rule on_inis, cut_tac b1, assumption, cut_tac b2, assumption, cut_tac b3, assumption) done\nqed\nnext show \"\\<forall> f r s. f \\<in> invariants N --> r \\<in> rules N --> invHoldForRule s f r (invariants N)\"\nproof ((rule allI)+, (rule impI)+)\n  fix f r s\n  assume b1: \"f \\<in> invariants N\" and b2: \"r \\<in> rules N\"\n  show \"invHoldForRule s f r (invariants N)\"\n  apply (rule invs_on_rules, cut_tac b1, assumption, cut_tac b2, assumption) done\nqed\nqed\nnext show \"s \\<in> reachableSet {andList (allInitSpecs N)} (rules N)\"\n  apply (metis a1) done\nqed\nend\n", "meta": {"author": "hongjianjiang", "repo": "paraverif_dafny", "sha": "083d86afb46a847783cb9319d975b3c2ad0afe93", "save_path": "github-repos/isabelle/hongjianjiang-paraverif_dafny", "path": "github-repos/isabelle/hongjianjiang-paraverif_dafny/paraverif_dafny-083d86afb46a847783cb9319d975b3c2ad0afe93/examples/n_german/n_german.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331319177487, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.28657340276781285}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      HoarePartialProps.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer\nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection \\<open>Properties of Partial Correctness Hoare Logic\\<close>\n\ntheory HoarePartialProps imports HoarePartialDef begin\n\nsubsection \\<open>Soundness\\<close>\n\nlemma hoare_cnvalid:\n assumes hoare: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n shows \"\\<And>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\nusing hoare\nproof (induct)\n  case (Skip \\<Theta> F P A)\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P Skip P,A\"\n  proof (rule cnvalidI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Skip,Normal s\\<rangle> =n\\<Rightarrow> t\" \"s \\<in> P\"\n    thus \"t \\<in> Normal ` P \\<union> Abrupt ` A\"\n      by cases auto\n  qed\nnext\n  case (Basic \\<Theta> F f P A)\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> {s. f s \\<in> P} (Basic f) P,A\"\n  proof (rule cnvalidI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Basic f,Normal s\\<rangle> =n\\<Rightarrow> t\" \"s \\<in> {s. f s \\<in> P}\"\n    thus \"t \\<in> Normal ` P \\<union> Abrupt ` A\"\n      by cases auto\n  qed\nnext\n  case (Spec \\<Theta> F r Q A)\n  show \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> {s. (\\<forall>t. (s, t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s, t) \\<in> r)} Spec r Q,A\"\n  proof (rule cnvalidI)\n    fix s t\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Spec r,Normal s\\<rangle> =n\\<Rightarrow> t\"\n    assume P: \"s \\<in> {s. (\\<forall>t. (s, t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s, t) \\<in> r)}\"\n    from exec P\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by cases auto\n  qed\nnext\n  case (Seq \\<Theta> F P c1 R A c2 Q)\n  have valid_c1: \"\\<And>n. \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P c1 R,A\" by fact\n  have valid_c2: \"\\<And>n. \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> R c2 Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P Seq c1 c2 Q,A\"\n  proof (rule cnvalidI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal s\\<rangle> =n\\<Rightarrow> t\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    assume P: \"s \\<in> P\"\n    from exec P obtain r where\n      exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> =n\\<Rightarrow> r\" and exec_c2:  \"\\<Gamma>\\<turnstile>\\<langle>c2,r\\<rangle> =n\\<Rightarrow> t\"\n      by cases auto\n    with t_notin_F have \"r \\<notin> Fault ` F\"\n      by (auto dest: execn_Fault_end)\n    with valid_c1 ctxt exec_c1 P\n    have r: \"r\\<in>Normal ` R \\<union> Abrupt ` A\"\n      by (rule cnvalidD)\n    show \"t\\<in>Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases r)\n      case (Normal r')\n      with exec_c2 r\n      show \"t\\<in>Normal ` Q \\<union> Abrupt ` A\"\n        apply -\n        apply (rule cnvalidD [OF valid_c2 ctxt _ _ t_notin_F])\n        apply auto\n        done\n    next\n      case (Abrupt r')\n      with exec_c2 have \"t=Abrupt r'\"\n        by (auto elim: execn_elim_cases)\n      with Abrupt r show ?thesis\n        by auto\n    next\n      case Fault with r show ?thesis by blast\n    next\n      case Stuck with r show ?thesis by blast\n    qed\n  qed\nnext\n  case (Cond \\<Theta> F P b c1 Q A c2)\n  have valid_c1: \"\\<And>n. \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> (P \\<inter> b) c1 Q,A\" by fact\n  have valid_c2: \"\\<And>n. \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> (P \\<inter> - b) c2 Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P Cond b c1 c2 Q,A\"\n  proof (rule cnvalidI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> =n\\<Rightarrow> t\"\n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases \"s\\<in>b\")\n      case True\n      with exec have \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> =n\\<Rightarrow> t\"\n        by cases auto\n      with P True\n      show ?thesis\n        by - (rule cnvalidD [OF valid_c1 ctxt _ _ t_notin_F],auto)\n    next\n      case False\n      with exec P have \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal s\\<rangle> =n\\<Rightarrow> t\"\n        by cases auto\n      with P False\n      show ?thesis\n        by - (rule cnvalidD [OF valid_c2 ctxt _ _ t_notin_F],auto)\n    qed\n  qed\nnext\n  case (While \\<Theta> F P b c A n)\n  have valid_c: \"\\<And>n. \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> (P \\<inter> b) c P,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P While b c (P \\<inter> - b),A\"\n  proof (rule cnvalidI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    show \"t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\"\n    proof (cases \"s \\<in> b\")\n      case True\n      {\n        fix d::\"('b,'a,'c) com\" fix s t\n        assume exec: \"\\<Gamma>\\<turnstile>\\<langle>d,s\\<rangle> =n\\<Rightarrow> t\"\n        assume d: \"d=While b c\"\n        assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n        from exec d ctxt\n        have \"\\<lbrakk>s \\<in> Normal ` P; t \\<notin> Fault ` F\\<rbrakk>\n               \\<Longrightarrow> t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt`A\"\n        proof (induct)\n          case (WhileTrue s b' c' n r t)\n          have t_notin_F: \"t \\<notin> Fault ` F\" by fact\n          have eqs: \"While b' c' = While b c\" by fact\n          note valid_c\n          moreover have ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\" by fact\n          moreover from WhileTrue\n          obtain \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> r\" and\n            \"\\<Gamma>\\<turnstile>\\<langle>While b c,r\\<rangle> =n\\<Rightarrow> t\" and\n            \"Normal s \\<in> Normal `(P \\<inter> b)\" by auto\n          moreover with t_notin_F have \"r \\<notin> Fault ` F\"\n            by (auto dest: execn_Fault_end)\n          ultimately\n          have r: \"r \\<in> Normal ` P \\<union> Abrupt ` A\"\n            by - (rule cnvalidD,auto)\n          from this _ ctxt\n          show \"t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A \"\n          proof (cases r)\n            case (Normal r')\n            with r ctxt eqs t_notin_F\n            show ?thesis\n              by - (rule WhileTrue.hyps,auto)\n          next\n            case (Abrupt r')\n            have \"\\<Gamma>\\<turnstile>\\<langle>While b' c',r\\<rangle> =n\\<Rightarrow> t\" by fact\n            with Abrupt have \"t=r\"\n              by (auto dest: execn_Abrupt_end)\n            with r Abrupt show ?thesis\n              by blast\n          next\n            case Fault with r show ?thesis by blast\n          next\n            case Stuck with r show ?thesis by blast\n          qed\n        qed auto\n      }\n      with exec ctxt P t_notin_F\n      show ?thesis\n        by auto\n    next\n      case False\n      with exec P have \"t=Normal s\"\n        by cases auto\n      with P False\n      show ?thesis\n        by auto\n    qed\n  qed\nnext\n  case (Guard \\<Theta> F g P c Q A f)\n  have valid_c: \"\\<And>n. \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> (g \\<inter> P) Guard f g c  Q,A\"\n  proof (rule cnvalidI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    assume P:\"s \\<in> (g \\<inter> P)\"\n    from exec P have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by cases auto\n    from valid_c ctxt this P t_notin_F\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by (rule cnvalidD)\n  qed\nnext\n  case (Guarantee f F \\<Theta> g P c Q A)\n  have valid_c: \"\\<And>n. \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\" by fact\n  have f_F: \"f \\<in> F\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P Guard f g c  Q,A\"\n  proof (rule cnvalidI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    assume P:\"s \\<in> P\"\n    from exec f_F t_notin_F have g: \"s \\<in> g\"\n      by cases auto\n    with P have P': \"s \\<in> g \\<inter> P\"\n      by blast\n    from exec P g have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by cases auto\n    from valid_c ctxt this P' t_notin_F\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by (rule cnvalidD)\n  qed\nnext\n  case (CallRec P p Q A Specs \\<Theta> F)\n  have p: \"(P,p,Q,A) \\<in> Specs\" by fact\n  have valid_body:\n    \"\\<forall>(P,p,Q,A) \\<in> Specs. p \\<in> dom \\<Gamma> \\<and> (\\<forall>n. \\<Gamma>,\\<Theta> \\<union> Specs \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (the (\\<Gamma> p)) Q,A)\"\n    using CallRec.hyps by blast\n  show \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P Call p Q,A\"\n  proof -\n    {\n      fix n\n      have \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\n        \\<Longrightarrow> \\<forall>(P,p,Q,A) \\<in>Specs. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n      proof (induct n)\n        case 0\n        show \"\\<forall>(P,p,Q,A) \\<in>Specs. \\<Gamma>\\<Turnstile>0:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n          by (fastforce elim!: execn_elim_cases simp add: nvalid_def)\n      next\n        case (Suc m)\n        have hyp: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>m:\\<^bsub>/F\\<^esub> P (Call p) Q,A\n              \\<Longrightarrow> \\<forall>(P,p,Q,A) \\<in>Specs. \\<Gamma>\\<Turnstile>m:\\<^bsub>/F\\<^esub> P (Call p) Q,A\" by fact\n        have \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>Suc m:\\<^bsub>/F\\<^esub> P (Call p) Q,A\" by fact\n        hence ctxt_m: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>m:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n          by (fastforce simp add: nvalid_def intro: execn_Suc)\n        hence valid_Proc:\n          \"\\<forall>(P,p,Q,A) \\<in>Specs. \\<Gamma>\\<Turnstile>m:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n          by (rule hyp)\n        let ?\\<Theta>'= \"\\<Theta> \\<union> Specs\"\n        from valid_Proc ctxt_m\n        have \"\\<forall>(P, p, Q, A)\\<in>?\\<Theta>'. \\<Gamma> \\<Turnstile>m:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n          by fastforce\n        with valid_body\n        have valid_body_m:\n          \"\\<forall>(P,p,Q,A) \\<in>Specs. \\<forall>n. \\<Gamma> \\<Turnstile>m:\\<^bsub>/F\\<^esub> P (the (\\<Gamma> p)) Q,A\"\n          by (fastforce simp add: cnvalid_def)\n        show \"\\<forall>(P,p,Q,A) \\<in>Specs. \\<Gamma> \\<Turnstile>Suc m:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n        proof (clarify)\n          fix P p Q A assume p: \"(P,p,Q,A) \\<in> Specs\"\n          show \"\\<Gamma> \\<Turnstile>Suc m:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n          proof (rule nvalidI)\n            fix s t\n            assume exec_call:\n              \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> =Suc m\\<Rightarrow> t\"\n            assume Pre: \"s \\<in> P\"\n            assume t_notin_F: \"t \\<notin> Fault ` F\"\n            from exec_call\n            show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n            proof (cases)\n              fix bdy m'\n              assume m: \"Suc m = Suc m'\"\n              assume bdy: \"\\<Gamma> p = Some bdy\"\n              assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal s\\<rangle> =m'\\<Rightarrow> t\"\n              from Pre valid_body_m exec_body bdy m p t_notin_F\n              show ?thesis\n                by (fastforce simp add: nvalid_def)\n            next\n              assume \"\\<Gamma> p = None\"\n              with valid_body p have False by auto\n              thus ?thesis ..\n            qed\n          qed\n        qed\n      qed\n    }\n    with p show ?thesis\n      by (fastforce simp add: cnvalid_def)\n  qed\nnext\n  case (DynCom P \\<Theta> F c Q A)\n  hence valid_c: \"\\<forall>s\\<in>P. (\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (c s) Q,A)\" by auto\n  show \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P DynCom c Q,A\"\n  proof (rule cnvalidI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n    assume P: \"s \\<in> P\"\n    assume t_notin_Fault: \"t \\<notin> Fault ` F\"\n    from exec show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases)\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c s,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      from cnvalidD [OF valid_c [rule_format, OF P] ctxt this P t_notin_Fault]\n      show ?thesis .\n    qed\n  qed\nnext\n  case (Throw \\<Theta> F A Q)\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> A Throw Q,A\"\n  proof (rule cnvalidI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Throw,Normal s\\<rangle> =n\\<Rightarrow> t\" \"s \\<in> A\"\n    then show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by cases simp\n  qed\nnext\n  case (Catch \\<Theta> F P c\\<^sub>1 Q R c\\<^sub>2 A)\n  have valid_c1: \"\\<And>n. \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,R\" by fact\n  have valid_c2: \"\\<And>n. \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P Catch c\\<^sub>1 c\\<^sub>2 Q,A\"\n  proof (rule cnvalidI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> =n\\<Rightarrow> t\"\n    assume P: \"s \\<in> P\"\n    assume t_notin_Fault: \"t \\<notin> Fault ` F\"\n    from exec show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases)\n      fix s'\n      assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> =n\\<Rightarrow> Abrupt s'\"\n      assume exec_c2: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s'\\<rangle> =n\\<Rightarrow> t\"\n      from cnvalidD [OF valid_c1 ctxt exec_c1 P ]\n      have \"Abrupt s' \\<in> Abrupt ` R\"\n        by auto\n      with cnvalidD [OF valid_c2 ctxt _ _ t_notin_Fault] exec_c2\n      show ?thesis\n        by fastforce\n    next\n      assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      assume notAbr: \"\\<not> isAbr t\"\n      from cnvalidD [OF valid_c1 ctxt exec_c1 P t_notin_Fault]\n      have \"t \\<in> Normal ` Q \\<union> Abrupt ` R\" .\n      with notAbr\n      show ?thesis\n        by auto\n    qed\n  qed\nnext\n  case (Conseq P \\<Theta> F c Q A)\n  hence adapt: \"\\<forall>s \\<in> P. (\\<exists>P' Q' A'. \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P' c Q',A'  \\<and>\n                          s \\<in> P' \\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A)\"\n    by blast\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\n  proof (rule cnvalidI)\n    fix s t\n    assume ctxt:\"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof -\n      from P adapt obtain P' Q' A' Z  where\n        spec: \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P' c Q',A'\" and\n        P': \"s \\<in> P'\"  and  strengthen: \"Q' \\<subseteq> Q \\<and> A' \\<subseteq> A\"\n        by auto\n      from spec [rule_format] ctxt exec P' t_notin_F\n      have \"t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n        by (rule cnvalidD)\n      with strengthen show ?thesis\n        by blast\n    qed\n  qed\nnext\n  case (Asm P p Q A \\<Theta> F)\n  have asm: \"(P, p, Q, A) \\<in> \\<Theta>\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  proof (rule cnvalidI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> =n\\<Rightarrow> t\"\n    from asm ctxt have \"\\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P Call p Q,A\" by auto\n    moreover\n    assume \"s \\<in> P\" \"t \\<notin> Fault ` F\"\n    ultimately\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      using exec\n      by (auto simp add: nvalid_def)\n  qed\nnext\n  case ExFalso thus ?case by iprover\nqed\n\n\n\nsubsection \\<open>Completeness\\<close>\n\nlemma MGT_valid:\n\"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union>  Fault ` (-F))} c\n   {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t}, {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\nproof (rule validI)\n  fix s t\n  assume \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n         \"s \\<in> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union>  Fault ` (-F))}\"\n         \"t \\<notin> Fault ` F\"\n  thus \"t \\<in> Normal ` {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t} \\<union>\n            Abrupt ` {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (cases t) (auto simp add: final_notin_def)\nqed\n\ntext \\<open>The consequence rule where the existential @{term Z} is instantiated\nto @{term s}. Usefull in proof of \\<open>MGT_lemma\\<close>.\\<close>\nlemma ConseqMGT:\n  assumes modif: \"\\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z)\"\n  assumes impl: \"\\<And>s. s \\<in> P \\<Longrightarrow> s \\<in> P' s \\<and> (\\<forall>t. t \\<in> Q' s \\<longrightarrow> t \\<in> Q) \\<and>\n                                            (\\<forall>t. t \\<in> A' s \\<longrightarrow> t \\<in> A)\"\n  shows \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\nusing impl\nby -  (rule conseq [OF modif],blast)\n\n\nlemma Seq_NoFaultStuckD1:\n  assumes noabort: \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault `  F)\"\n  shows \"\\<Gamma>\\<turnstile>\\<langle>c1,s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault `  F)\"\nproof (rule final_notinI)\n  fix t\n  assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,s\\<rangle> \\<Rightarrow> t\"\n  show \"t \\<notin> {Stuck} \\<union> Fault `  F\"\n  proof\n    assume \"t \\<in> {Stuck} \\<union> Fault `  F\"\n    moreover\n    {\n      assume \"t = Stuck\"\n      with exec_c1\n      have \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,s\\<rangle> \\<Rightarrow> Stuck\"\n        by (auto intro: exec_Seq')\n      with noabort have False\n        by (auto simp add: final_notin_def)\n      hence False ..\n    }\n    moreover\n    {\n      assume \"t \\<in> Fault ` F\"\n      then obtain f where\n      t: \"t=Fault f\" and f: \"f \\<in> F\"\n        by auto\n      from t exec_c1\n      have \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,s\\<rangle> \\<Rightarrow> Fault f\"\n        by (auto intro: exec_Seq')\n      with noabort f have False\n        by (auto simp add: final_notin_def)\n      hence False ..\n    }\n    ultimately show False by auto\n  qed\nqed\n\nlemma Seq_NoFaultStuckD2:\n  assumes noabort: \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault `  F)\"\n  shows \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>c1,s\\<rangle> \\<Rightarrow> t \\<longrightarrow> t\\<notin> ({Stuck} \\<union> Fault `  F) \\<longrightarrow>\n             \\<Gamma>\\<turnstile>\\<langle>c2,t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault `  F)\"\nusing noabort\nby (auto simp add: final_notin_def intro: exec_Seq')\n\n\nlemma MGT_implies_complete:\n  assumes MGT: \"\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union>  Fault ` (-F))} c\n                           {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                           {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  assumes valid: \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,{} \\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  using MGT\n  apply (rule ConseqMGT)\n  apply (insert valid)\n  apply (auto simp add: valid_def intro!: final_notinI)\n  done\n\ntext \\<open>Equipped only with the classic consequence rule @{thm \"conseqPrePost\"}\n        we can only derive this syntactically more involved version\n        of completeness. But semantically it is equivalent to the \"real\" one\n        (see below)\\<close>\nlemma MGT_implies_complete':\n  assumes MGT: \"\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub>\n                       {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union>  Fault ` (-F))} c\n                           {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                           {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  assumes valid: \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,{} \\<turnstile>\\<^bsub>/F\\<^esub> {s. s=Z \\<and> s \\<in> P} c {t. Z \\<in> P \\<longrightarrow> t \\<in> Q},{t. Z \\<in> P \\<longrightarrow> t \\<in> A}\"\n  using MGT [rule_format, of Z]\n  apply (rule conseqPrePost)\n  apply (insert valid)\n  apply   (fastforce simp add: valid_def final_notin_def)\n  apply  (fastforce simp add: valid_def)\n  apply (fastforce simp add: valid_def)\n  done\n\ntext \\<open>Semantic equivalence of both kind of formulations\\<close>\nlemma valid_involved_to_valid:\n  assumes valid:\n    \"\\<forall>Z. \\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> {s. s=Z \\<and> s \\<in> P} c {t. Z \\<in> P \\<longrightarrow> t \\<in> Q},{t. Z \\<in> P \\<longrightarrow> t \\<in> A}\"\n  shows \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  using valid\n  apply (simp add: valid_def)\n  apply clarsimp\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"Normal x\" in allE)\n  apply (erule_tac x=t in allE)\n  apply fastforce\n  done\n\ntext \\<open>The sophisticated consequence rule allow us to do this\n        semantical transformation on the hoare-level, too.\n        The magic is, that it allow us to\n        choose the instance of @{term Z} under the assumption of an state @{term \"s \\<in> P\"}\\<close>\nlemma\n  assumes deriv:\n    \"\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> {s. s=Z \\<and> s \\<in> P} c {t. Z \\<in> P \\<longrightarrow> t \\<in> Q},{t. Z \\<in> P \\<longrightarrow> t \\<in> A}\"\n  shows \"\\<Gamma>,{} \\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule ConseqMGT [OF deriv])\n  apply auto\n  done\n\nlemma valid_to_valid_involved:\n  \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow>\n   \\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> {s. s=Z \\<and> s \\<in> P} c {t. Z \\<in> P \\<longrightarrow> t \\<in> Q},{t. Z \\<in> P \\<longrightarrow> t \\<in> A}\"\nby (simp add: valid_def Collect_conv_if)\n\nlemma\n  assumes deriv: \"\\<Gamma>,{} \\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> {s. s=Z \\<and> s \\<in> P} c {t. Z \\<in> P \\<longrightarrow> t \\<in> Q},{t. Z \\<in> P \\<longrightarrow> t \\<in> A}\"\n  apply (rule conseqPrePost [OF deriv])\n  apply auto\n  done\n\nlemma conseq_extract_state_indep_prop:\n  assumes state_indep_prop:\"\\<forall>s \\<in> P. R\"\n  assumes to_show: \"R \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule Conseq)\n  apply (clarify)\n  apply (rule_tac x=\"P\" in exI)\n  apply (rule_tac x=\"Q\" in exI)\n  apply (rule_tac x=\"A\" in exI)\n  using state_indep_prop to_show\n  by blast\n\n\nlemma MGT_lemma:\n  assumes MGT_Calls:\n    \"\\<forall>p\\<in>dom \\<Gamma>. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub>\n       {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\n        (Call p)\n       {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n       {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  shows \"\\<And>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} c\n             {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\nproof (induct c)\n  case Skip\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Skip,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} Skip\n           {t. \\<Gamma>\\<turnstile>\\<langle>Skip,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>Skip,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoarep.Skip [THEN conseqPre])\n       (auto elim: exec_elim_cases simp add: final_notin_def intro: exec.intros)\nnext\n  case (Basic f)\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Basic f,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} Basic f\n           {t. \\<Gamma>\\<turnstile>\\<langle>Basic f,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n           {t. \\<Gamma>\\<turnstile>\\<langle>Basic f,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoarep.Basic [THEN conseqPre])\n       (auto elim: exec_elim_cases simp add: final_notin_def intro: exec.intros)\nnext\n  case (Spec r)\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Spec r,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} Spec r\n           {t. \\<Gamma>\\<turnstile>\\<langle>Spec r,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n           {t. \\<Gamma>\\<turnstile>\\<langle>Spec r,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    apply (rule hoarep.Spec [THEN conseqPre])\n    apply (clarsimp simp add: final_notin_def)\n    apply (case_tac \"\\<exists>t. (Z,t) \\<in> r\")\n    apply (auto elim: exec_elim_cases simp add: final_notin_def intro: exec.intros)\n    done\nnext\n  case (Seq c1 c2)\n  have hyp_c1: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} c1\n                           {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                           {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Seq.hyps by iprover\n  have hyp_c2: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} c2\n                          {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                          {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Seq.hyps by iprover\n  from hyp_c1\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} c1\n              {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t \\<and>\n                  \\<Gamma>\\<turnstile>\\<langle>c2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT)\n       (auto dest: Seq_NoFaultStuckD1 [simplified] Seq_NoFaultStuckD2 [simplified]\n             intro: exec.Seq)\n  thus \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\n                   Seq c1 c2\n              {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  proof (rule hoarep.Seq )\n    show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t \\<and>\n                      \\<Gamma>\\<turnstile>\\<langle>c2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\n                   c2\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    proof (rule ConseqMGT [OF hyp_c2],safe)\n      fix r t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal r\" \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal r\\<rangle> \\<Rightarrow> Normal t\"\n      then show \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n        by (iprover intro: exec.intros)\n    next\n      fix r t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal r\" \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal r\\<rangle> \\<Rightarrow> Abrupt t\"\n      then show \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n        by (iprover intro: exec.intros)\n    qed\n  qed\nnext\n  case (Cond b c1 c2)\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} c1\n                 {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                 {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Cond.hyps by iprover\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\\<inter>b)\n                   c1\n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT)\n       (fastforce intro: exec.CondTrue simp add: final_notin_def)\n  moreover\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} c2\n                    {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                    {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Cond.hyps by iprover\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>({s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\\<inter>-b)\n                  c2\n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT)\n       (fastforce intro: exec.CondFalse simp add: final_notin_def)\n  ultimately\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\n                 Cond b c1 c2\n              {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoarep.Cond)\nnext\n  case (While b c)\n  let ?unroll = \"({(s,t). s\\<in>b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t})\\<^sup>*\"\n  let ?P' = \"\\<lambda>Z. {t. (Z,t)\\<in>?unroll \\<and>\n                    (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                         \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                             (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow>\n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u))}\"\n  let ?A' = \"\\<lambda>Z. {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\n                While b c\n              {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  proof (rule ConseqMGT [where ?P'=\"?P'\"\n                         and ?Q'=\"\\<lambda>Z. ?P' Z \\<inter> - b\" and ?A'=\"?A'\"])\n    show \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (?P' Z) (While b c) (?P' Z \\<inter> - b),(?A' Z)\"\n    proof (rule allI, rule hoarep.While)\n      fix Z\n      from While\n      have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} c\n                        {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                        {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" by iprover\n      then show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (?P' Z  \\<inter> b) c (?P' Z),(?A' Z)\"\n      proof (rule ConseqMGT)\n        fix s\n        assume  \"s\\<in> {t. (Z, t) \\<in> ?unroll \\<and>\n                      (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                           \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                               (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow>\n                                    \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u))}\n                   \\<inter> b\"\n        then obtain\n          Z_s_unroll: \"(Z,s) \\<in> ?unroll\" and\n          noabort:\"\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                        \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                            (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow>\n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)\" and\n          s_in_b: \"s\\<in>b\"\n          by blast\n        show \"s \\<in> {t. t = s \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} \\<and>\n        (\\<forall>t. t \\<in> {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t} \\<longrightarrow>\n             t \\<in> {t. (Z, t) \\<in> ?unroll \\<and>\n                  (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow>  e\\<in>b\n                       \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                           (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow>\n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u))}) \\<and>\n         (\\<forall>t. t \\<in> {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Abrupt t} \\<longrightarrow>\n             t \\<in> {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})\"\n          (is \"?C1 \\<and> ?C2 \\<and> ?C3\")\n        proof (intro conjI)\n          from Z_s_unroll noabort s_in_b show ?C1 by blast\n        next\n          {\n            fix t\n            assume s_t: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t\"\n            moreover\n            from Z_s_unroll s_t s_in_b\n            have \"(Z, t) \\<in> ?unroll\"\n              by (blast intro: rtrancl_into_rtrancl)\n            moreover note noabort\n            ultimately\n            have \"(Z, t) \\<in> ?unroll \\<and>\n                  (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                        \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                            (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow>\n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u))\"\n              by iprover\n          }\n          then show ?C2 by blast\n        next\n          {\n            fix t\n            assume s_t:  \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Abrupt t\"\n            from Z_s_unroll noabort s_t s_in_b\n            have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n              by blast\n          } thus ?C3 by simp\n        qed\n      qed\n    qed\n  next\n    fix s\n    assume P: \"s \\<in> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\"\n    hence WhileNoFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n      by auto\n    show \"s \\<in> ?P' s \\<and>\n    (\\<forall>t. t\\<in>(?P' s \\<inter> - b)\\<longrightarrow>\n         t\\<in>{t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t})\\<and>\n    (\\<forall>t. t\\<in>?A' s \\<longrightarrow> t\\<in>?A' Z)\"\n    proof (intro conjI)\n      {\n        fix e\n        assume \"(Z,e) \\<in> ?unroll\" \"e \\<in> b\"\n        from this WhileNoFault\n        have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n               (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow>\n                    \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)\" (is \"?Prop Z e\")\n        proof (induct rule: converse_rtrancl_induct [consumes 1])\n          assume e_in_b: \"e \\<in> b\"\n          assume WhileNoFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n          with e_in_b WhileNoFault\n          have cNoFault: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n            by (auto simp add: final_notin_def intro: exec.intros)\n          moreover\n          {\n            fix u assume \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow> Abrupt u\"\n            with e_in_b have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal e\\<rangle> \\<Rightarrow> Abrupt u\"\n              by (blast intro: exec.intros)\n          }\n          ultimately\n          show \"?Prop e e\"\n            by iprover\n        next\n          fix Z r\n          assume e_in_b: \"e\\<in>b\"\n          assume WhileNoFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n          assume hyp: \"\\<lbrakk>e\\<in>b;\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\\<rbrakk>\n                       \\<Longrightarrow> ?Prop r e\"\n          assume Z_r:\n            \"(Z, r) \\<in> {(Z, r). Z \\<in> b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal r}\"\n          with WhileNoFault\n          have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n            by (auto simp add: final_notin_def intro: exec.intros)\n          from hyp [OF e_in_b this] obtain\n            cNoFault: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\" and\n            Abrupt_r: \"\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow> Abrupt u \\<longrightarrow>\n                            \\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow> Abrupt u\"\n            by simp\n\n           {\n            fix u assume \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow> Abrupt u\"\n            with Abrupt_r have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow> Abrupt u\" by simp\n            moreover from  Z_r obtain\n              \"Z \\<in> b\"  \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal r\"\n              by simp\n            ultimately have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u\"\n              by (blast intro: exec.intros)\n          }\n          with cNoFault show \"?Prop Z e\"\n            by iprover\n        qed\n      }\n      with P show \"s \\<in> ?P' s\"\n        by blast\n    next\n      {\n        fix t\n        assume \"termination\": \"t \\<notin> b\"\n        assume \"(Z, t) \\<in> ?unroll\"\n        hence \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n        proof (induct rule: converse_rtrancl_induct [consumes 1])\n          from \"termination\"\n          show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal t\\<rangle> \\<Rightarrow> Normal t\"\n            by (blast intro: exec.WhileFalse)\n        next\n          fix Z r\n          assume first_body:\n                 \"(Z, r) \\<in> {(s, t). s \\<in> b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t}\"\n          assume \"(r, t) \\<in> ?unroll\"\n          assume rest_loop: \"\\<Gamma>\\<turnstile>\\<langle>While b c, Normal r\\<rangle> \\<Rightarrow> Normal t\"\n          show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n          proof -\n            from first_body obtain\n              \"Z \\<in> b\" \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal r\"\n              by fast\n            moreover\n            from rest_loop have\n              \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow> Normal t\"\n              by fast\n            ultimately show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n              by (rule exec.WhileTrue)\n          qed\n        qed\n      }\n      with P\n      show \"(\\<forall>t. t\\<in>(?P' s \\<inter> - b)\n            \\<longrightarrow>t\\<in>{t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t})\"\n        by blast\n    next\n      from P show \"\\<forall>t. t\\<in>?A' s \\<longrightarrow> t\\<in>?A' Z\" by simp\n    qed\n  qed\nnext\n  case (Call p)\n  let ?P = \"{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\"\n  from noStuck_Call have \"\\<forall>s \\<in> ?P. p \\<in> dom \\<Gamma>\"\n    by (fastforce simp add: final_notin_def )\n  then show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ?P (Call p)\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  proof (rule conseq_extract_state_indep_prop)\n    assume p_definied: \"p \\<in> dom \\<Gamma>\"\n    with MGT_Calls show\n      \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>{s. s=Z \\<and>\n                 \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\n                  (Call p)\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Call  p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      by (auto)\n  qed\nnext\n  case (DynCom c)\n  have hyp:\n    \"\\<And>s'. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>{s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c s',Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} c s'\n      {t. \\<Gamma>\\<turnstile>\\<langle>c s',Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c s',Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using DynCom by simp\n  have hyp':\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>{s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} c Z\n        {t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT [OF hyp])\n       (fastforce simp add: final_notin_def intro: exec.intros)\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>{s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\n               DynCom c\n             {t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    apply (rule hoarep.DynCom)\n    apply (clarsimp)\n    apply (rule hyp' [simplified])\n    done\nnext\n  case (Guard f g c)\n  have hyp_c: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} c\n                    {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                    {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Guard by iprover\n  show ?case\n  proof (cases \"f \\<in> F\")\n    case True\n    from hyp_c\n    have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>(g \\<inter> {s. s = Z \\<and>\n                    \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (- F))})\n             c\n           {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n           {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      apply (rule ConseqMGT)\n      apply (insert True)\n      apply (auto simp add: final_notin_def intro: exec.intros)\n      done\n    from True this\n    show ?thesis\n      by (rule conseqPre [OF Guarantee]) auto\n  next\n    case False\n    from hyp_c\n    have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>\n           (g \\<inter> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))})\n           c\n           {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n           {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      apply (rule ConseqMGT)\n      apply clarify\n      apply (frule Guard_noFaultStuckD [OF _ False])\n      apply (auto simp add: final_notin_def intro: exec.intros)\n      done\n    then show ?thesis\n      apply (rule conseqPre [OF hoarep.Guard])\n      apply clarify\n      apply (frule Guard_noFaultStuckD [OF _ False])\n      apply auto\n      done\n  qed\nnext\n  case Throw\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Throw,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} Throw\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule conseqPre [OF hoarep.Throw]) (blast intro: exec.intros)\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} c\\<^sub>1\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} c\\<^sub>1\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t \\<and>\n                   \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\"\n    by (rule ConseqMGT)\n       (fastforce intro: exec.intros simp add: final_notin_def)\n  moreover\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} c\\<^sub>2\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>{s. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow>Abrupt s \\<and>\n                   \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\n               c\\<^sub>2\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT)\n       (fastforce intro: exec.intros  simp add: final_notin_def)\n  ultimately\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\n                   Catch c\\<^sub>1 c\\<^sub>2\n              {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoarep.Catch)\nqed\n\nlemma MGT_Calls:\n \"\\<forall>p\\<in>dom \\<Gamma>. \\<forall>Z.\n     \\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\n            (Call p)\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\nproof -\n  {\n    fix p Z\n    assume defined: \"p \\<in> dom \\<Gamma>\"\n    have\n      \"\\<Gamma>,(\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z.\n          {({s. s=Z \\<and>\n             \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))},\n             p,\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})})\n       \\<turnstile>\\<^bsub>/F\\<^esub>{s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\n          (the (\\<Gamma> p))\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      (is \"\\<Gamma>,?\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (?Pre p Z) (the (\\<Gamma> p)) (?Post p Z),(?Abr p Z)\")\n    proof -\n      have MGT_Calls:\n       \"\\<forall>p\\<in>dom \\<Gamma>. \\<forall>Z. \\<Gamma>,?\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub>\n        {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\n         (Call p)\n        {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n        {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n        by (intro ballI allI, rule HoarePartialDef.Asm,auto)\n      have \"\\<forall>Z. \\<Gamma>,?\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p) ,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault`(-F))}\n                        (the (\\<Gamma> p))\n                        {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                        {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n        by (iprover intro: MGT_lemma [OF MGT_Calls])\n      thus \"\\<Gamma>,?\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (?Pre p Z) (the (\\<Gamma> p)) (?Post p Z),(?Abr p Z)\"\n        apply (rule ConseqMGT)\n        apply (clarify,safe)\n      proof -\n        assume \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n        with defined show \"\\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n          by (fastforce simp add: final_notin_def\n                intro: exec.intros)\n      next\n        fix t\n        assume \"\\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n        with defined\n        show \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow>Normal t\"\n          by  (auto intro: exec.Call)\n      next\n        fix t\n        assume \"\\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n        with defined\n        show \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow>Abrupt t\"\n          by  (auto intro: exec.Call)\n      qed\n    qed\n  }\n  then show ?thesis\n    apply -\n    apply (intro ballI allI)\n    apply (rule CallRec' [where Procs=\"dom \\<Gamma>\"  and\n      P=\"\\<lambda>p Z. {s. s=Z \\<and>\n                  \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\"and\n      Q=\"\\<lambda>p Z.\n        {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t}\" and\n      A=\"\\<lambda>p Z.\n        {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"] )\n    apply simp+\n    done\nqed\n\ntheorem hoare_complete: \"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (iprover intro: MGT_implies_complete MGT_lemma [OF MGT_Calls])\n\nlemma hoare_complete':\n  assumes cvalid: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (cases \"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\")\n  case True\n  hence \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (rule hoare_complete)\n  thus \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P c Q,A\"\n    by (rule hoare_augment_context) simp\nnext\n  case False\n  with cvalid\n  show ?thesis\n    by (rule ExFalso)\nqed\n\n\nlemma hoare_strip_\\<Gamma>:\n  assumes deriv: \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> P p Q,A\"\n  assumes F': \"F' \\<subseteq> -F\"\n  shows \"strip F' \\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> P p Q,A\"\nproof (rule hoare_complete)\n  from hoare_sound [OF deriv] have \"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P p Q,A\"\n    by (simp add: cvalid_def)\n  from this F'\n  show \"strip F' \\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P p Q,A\"\n    by (rule valid_to_valid_strip)\nqed\n\n\nsubsection \\<open>And Now: Some Useful Rules\\<close>\n\nsubsubsection \\<open>Consequence\\<close>\n\n\nlemma LiberalConseq_sound:\nfixes F::\"'f set\"\nassumes cons: \"\\<forall>s \\<in> P. \\<forall>(t::('s,'f) xstate). \\<exists>P' Q' A'. (\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P' c Q',A') \\<and>\n                ((s \\<in> P' \\<longrightarrow> t \\<in> Normal ` Q' \\<union> Abrupt ` A')\n                              \\<longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A)\"\nshows \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A \"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt:\"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof -\n    from P cons obtain P' Q' A' where\n      spec: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P' c Q',A'\" and\n      adapt: \"(s \\<in> P' \\<longrightarrow> t \\<in> Normal ` Q' \\<union> Abrupt ` A')\n                              \\<longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      apply -\n      apply (drule (1) bspec)\n      apply (erule_tac x=t in allE)\n      apply (elim exE conjE)\n      apply iprover\n      done\n    from exec spec ctxt t_notin_F\n    have \"s \\<in> P' \\<longrightarrow> t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n      by (simp add: cnvalid_def nvalid_def)\n    with adapt show ?thesis\n      by simp\n  qed\nqed\n\nlemma LiberalConseq:\nfixes F:: \"'f set\"\nassumes cons: \"\\<forall>s \\<in> P.  \\<forall>(t::('s,'f) xstate). \\<exists>P' Q' A'. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' c Q',A' \\<and>\n                ((s \\<in> P' \\<longrightarrow> t \\<in> Normal ` Q' \\<union> Abrupt ` A')\n                              \\<longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A \"\napply (rule hoare_complete')\napply (rule allI)\napply (rule LiberalConseq_sound)\nusing cons\napply (clarify)\napply (drule (1) bspec)\napply (erule_tac x=t in allE)\napply clarify\napply (rule_tac x=P' in exI)\napply (rule_tac x=Q' in exI)\napply (rule_tac x=A' in exI)\napply (rule conjI)\napply (blast intro: hoare_cnvalid)\napply assumption\ndone\n\nlemma \"\\<forall>s \\<in> P. \\<exists>P' Q' A'. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' c Q',A' \\<and> s \\<in> P' \\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A\n           \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule LiberalConseq)\n  apply (rule ballI)\n  apply (drule (1) bspec)\n  apply clarify\n  apply (rule_tac x=P' in exI)\n  apply (rule_tac x=Q' in exI)\n  apply (rule_tac x=A' in exI)\n  apply auto\n  done\n\nlemma\nfixes F:: \"'f set\"\nassumes cons: \"\\<forall>s \\<in> P.  \\<exists>P' Q' A'. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' c Q',A' \\<and>\n                (\\<forall>(t::('s,'f) xstate). (s \\<in> P' \\<longrightarrow> t \\<in> Normal ` Q' \\<union> Abrupt ` A')\n                              \\<longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A \"\n  apply (rule Conseq)\n  apply (rule ballI)\n  apply (insert cons)\n  apply (drule (1) bspec)\n  apply clarify\n  apply (rule_tac x=P' in exI)\n  apply (rule_tac x=Q' in exI)\n  apply (rule_tac x=A' in exI)\n  apply (rule conjI)\n  apply  assumption\n  (* no way to get s \\<in> P' *)\n  oops\n\nlemma LiberalConseq':\nfixes F:: \"'f set\"\nassumes cons: \"\\<forall>s \\<in> P.  \\<exists>P' Q' A'. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' c Q',A' \\<and>\n                (\\<forall>(t::('s,'f) xstate). (s \\<in> P' \\<longrightarrow> t \\<in> Normal ` Q' \\<union> Abrupt ` A')\n                              \\<longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A \"\napply (rule LiberalConseq)\napply (rule ballI)\napply (rule allI)\napply (insert cons)\napply (drule (1) bspec)\napply clarify\napply (rule_tac x=P' in exI)\napply (rule_tac x=Q' in exI)\napply (rule_tac x=A' in exI)\napply iprover\ndone\n\nlemma LiberalConseq'':\nfixes F:: \"'f set\"\nassumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z)\"\nassumes cons: \"\\<forall>s (t::('s,'f) xstate).\n                 (\\<forall>Z. s \\<in> P' Z \\<longrightarrow> t \\<in> Normal ` Q' Z \\<union> Abrupt ` A' Z)\n                  \\<longrightarrow> (s \\<in> P \\<longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A \"\napply (rule LiberalConseq)\napply (rule ballI)\napply (rule allI)\napply (insert cons)\napply (erule_tac x=s in allE)\napply (erule_tac x=t in allE)\napply (case_tac \"t \\<in> Normal ` Q \\<union> Abrupt ` A\")\napply (insert spec)\napply  iprover\napply auto\ndone\n\nprimrec procs:: \"('s,'p,'f) com \\<Rightarrow> 'p set\"\nwhere\n\"procs Skip = {}\" |\n\"procs (Basic f) = {}\" |\n\"procs (Seq c\\<^sub>1 c\\<^sub>2)  = (procs c\\<^sub>1 \\<union> procs c\\<^sub>2)\" |\n\"procs (Cond b c\\<^sub>1 c\\<^sub>2) = (procs c\\<^sub>1 \\<union> procs c\\<^sub>2)\" |\n\"procs (While b c) = procs c\" |\n\"procs (Call p) = {p}\" |\n\"procs (DynCom c) = (\\<Union>s. procs (c s))\" |\n\"procs (Guard f g c) = procs c\" |\n\"procs Throw = {}\" |\n\"procs (Catch c\\<^sub>1 c\\<^sub>2) = (procs c\\<^sub>1 \\<union> procs c\\<^sub>2)\"\n\nprimrec noSpec:: \"('s,'p,'f) com \\<Rightarrow> bool\"\nwhere\n\"noSpec Skip = True\" |\n\"noSpec (Basic f) = True\" |\n\"noSpec (Spec r) = False\" |\n\"noSpec (Seq c\\<^sub>1 c\\<^sub>2)  = (noSpec c\\<^sub>1 \\<and> noSpec c\\<^sub>2)\" |\n\"noSpec (Cond b c\\<^sub>1 c\\<^sub>2) = (noSpec c\\<^sub>1 \\<and> noSpec c\\<^sub>2)\" |\n\"noSpec (While b c) = noSpec c\" |\n\"noSpec (Call p) = True\" |\n\"noSpec (DynCom c) = (\\<forall>s. noSpec (c s))\" |\n\"noSpec (Guard f g c) = noSpec c\" |\n\"noSpec Throw = True\" |\n\"noSpec (Catch c\\<^sub>1 c\\<^sub>2) = (noSpec c\\<^sub>1 \\<and> noSpec c\\<^sub>2)\"\n\nlemma exec_noSpec_no_Stuck:\n assumes exec: \"\\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t\"\n assumes noSpec_c: \"noSpec c\"\n assumes noSpec_\\<Gamma>: \"\\<forall>p \\<in> dom \\<Gamma>. noSpec (the (\\<Gamma> p))\"\n assumes procs_subset: \"procs c \\<subseteq> dom \\<Gamma>\"\n assumes procs_subset_\\<Gamma>: \"\\<forall>p \\<in> dom \\<Gamma>. procs (the (\\<Gamma> p)) \\<subseteq> dom \\<Gamma>\"\n assumes s_no_Stuck: \"s\\<noteq>Stuck\"\n shows \"t\\<noteq>Stuck\"\nusing exec noSpec_c procs_subset s_no_Stuck proof induct\n  case (Call p bdy s t) with noSpec_\\<Gamma> procs_subset_\\<Gamma> show ?case\n    by (auto dest!: bspec [of _ _ p])\nnext\n  case (DynCom c s t) then show ?case\n   by auto blast\nqed auto\n\nlemma execn_noSpec_no_Stuck:\n assumes exec: \"\\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> =n\\<Rightarrow> t\"\n assumes noSpec_c: \"noSpec c\"\n assumes noSpec_\\<Gamma>: \"\\<forall>p \\<in> dom \\<Gamma>. noSpec (the (\\<Gamma> p))\"\n assumes procs_subset: \"procs c \\<subseteq> dom \\<Gamma>\"\n assumes procs_subset_\\<Gamma>: \"\\<forall>p \\<in> dom \\<Gamma>. procs (the (\\<Gamma> p)) \\<subseteq> dom \\<Gamma>\"\n assumes s_no_Stuck: \"s\\<noteq>Stuck\"\n shows \"t\\<noteq>Stuck\"\nusing exec noSpec_c procs_subset s_no_Stuck proof induct\n  case (Call p bdy n s t) with noSpec_\\<Gamma> procs_subset_\\<Gamma> show ?case\n    by (auto dest!: bspec [of _ _ p])\nnext\n  case (DynCom c s t) then show ?case\n    by auto blast\nqed auto\n\nlemma LiberalConseq_noguards_nothrows_sound:\nassumes spec: \"\\<forall>Z. \\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z)\"\nassumes cons: \"\\<forall>s t. (\\<forall>Z. s \\<in> P' Z \\<longrightarrow> t \\<in>  Q' Z )\n                  \\<longrightarrow> (s \\<in> P \\<longrightarrow> t \\<in> Q )\"\nassumes noguards_c: \"noguards c\"\nassumes noguards_\\<Gamma>: \"\\<forall>p \\<in> dom \\<Gamma>. noguards (the (\\<Gamma> p))\"\nassumes nothrows_c: \"nothrows c\"\nassumes nothrows_\\<Gamma>: \"\\<forall>p \\<in> dom \\<Gamma>. nothrows (the (\\<Gamma> p))\"\nassumes noSpec_c: \"noSpec c\"\nassumes noSpec_\\<Gamma>: \"\\<forall>p \\<in> dom \\<Gamma>. noSpec (the (\\<Gamma> p))\"\nassumes procs_subset: \"procs c \\<subseteq> dom \\<Gamma>\"\nassumes procs_subset_\\<Gamma>: \"\\<forall>p \\<in> dom \\<Gamma>. procs (the (\\<Gamma> p)) \\<subseteq> dom \\<Gamma>\"\nshows \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A \"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt:\"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof -\n    from execn_noguards_no_Fault [OF exec noguards_c noguards_\\<Gamma>]\n     execn_nothrows_no_Abrupt [OF exec nothrows_c nothrows_\\<Gamma> ]\n     execn_noSpec_no_Stuck [OF exec\n              noSpec_c  noSpec_\\<Gamma> procs_subset\n      procs_subset_\\<Gamma>]\n    obtain t' where t: \"t=Normal t'\"\n      by (cases t) auto\n    with exec spec ctxt\n    have \"(\\<forall>Z. s \\<in> P' Z \\<longrightarrow> t' \\<in>  Q' Z)\"\n      by (unfold  cnvalid_def nvalid_def) blast\n    with cons P t show ?thesis\n      by simp\n  qed\nqed\n\n\nlemma LiberalConseq_noguards_nothrows:\nassumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z)\"\nassumes cons: \"\\<forall>s t. (\\<forall>Z. s \\<in> P' Z \\<longrightarrow> t \\<in>  Q' Z )\n                  \\<longrightarrow> (s \\<in> P \\<longrightarrow> t \\<in> Q )\"\nassumes noguards_c: \"noguards c\"\nassumes noguards_\\<Gamma>: \"\\<forall>p \\<in> dom \\<Gamma>. noguards (the (\\<Gamma> p))\"\nassumes nothrows_c: \"nothrows c\"\nassumes nothrows_\\<Gamma>: \"\\<forall>p \\<in> dom \\<Gamma>. nothrows (the (\\<Gamma> p))\"\nassumes noSpec_c: \"noSpec c\"\nassumes noSpec_\\<Gamma>: \"\\<forall>p \\<in> dom \\<Gamma>. noSpec (the (\\<Gamma> p))\"\nassumes procs_subset: \"procs c \\<subseteq> dom \\<Gamma>\"\nassumes procs_subset_\\<Gamma>: \"\\<forall>p \\<in> dom \\<Gamma>. procs (the (\\<Gamma> p)) \\<subseteq> dom \\<Gamma>\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A \"\napply (rule hoare_complete')\napply (rule allI)\napply (rule LiberalConseq_noguards_nothrows_sound\n             [OF _ cons noguards_c noguards_\\<Gamma> nothrows_c nothrows_\\<Gamma>\n                 noSpec_c noSpec_\\<Gamma>\n                 procs_subset procs_subset_\\<Gamma>])\napply (insert spec)\napply (intro allI)\napply (erule_tac x=Z in allE)\nby (rule hoare_cnvalid)\n\nlemma\nassumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>{s. s=fst Z \\<and> P s (snd Z)} c {t. Q (fst Z) (snd Z) t},{}\"\nassumes noguards_c: \"noguards c\"\nassumes noguards_\\<Gamma>: \"\\<forall>p \\<in> dom \\<Gamma>. noguards (the (\\<Gamma> p))\"\nassumes nothrows_c: \"nothrows c\"\nassumes nothrows_\\<Gamma>: \"\\<forall>p \\<in> dom \\<Gamma>. nothrows (the (\\<Gamma> p))\"\nassumes noSpec_c: \"noSpec c\"\nassumes noSpec_\\<Gamma>: \"\\<forall>p \\<in> dom \\<Gamma>. noSpec (the (\\<Gamma> p))\"\nassumes procs_subset: \"procs c \\<subseteq> dom \\<Gamma>\"\nassumes procs_subset_\\<Gamma>: \"\\<forall>p \\<in> dom \\<Gamma>. procs (the (\\<Gamma> p)) \\<subseteq> dom \\<Gamma>\"\nshows \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>{s. s=\\<sigma>} c {t. \\<forall>l. P \\<sigma> l \\<longrightarrow> Q \\<sigma> l t},{}\"\napply (rule allI)\napply (rule LiberalConseq_noguards_nothrows\n              [OF spec _ noguards_c noguards_\\<Gamma> nothrows_c nothrows_\\<Gamma>\n                  noSpec_c noSpec_\\<Gamma>\n                  procs_subset procs_subset_\\<Gamma>])\napply auto\ndone\n\nsubsubsection \\<open>Modify Return\\<close>\n\nlemma ProcModifyReturn_sound:\n  assumes valid_call: \"\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P call init p return' c Q,A\"\n  assumes valid_modif:\n    \"\\<forall>\\<sigma>. \\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/UNIV\\<^esub> {\\<sigma>} Call p (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  assumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s)\n           \\<longrightarrow> return' s t = return s t\"\n  assumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s)\n                             \\<longrightarrow> return' s t = return s t\"\n  shows \"\\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: nvalid_augment_Faults)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>call init p return c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from exec\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: execn_call_Normal_elim)\n    fix bdy m t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> =m\\<Rightarrow> Normal t'\"\n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> =Suc m\\<Rightarrow> t\"\n    assume n: \"n = Suc m\"\n    from exec_body n bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal (init s)\\<rangle> =n\\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: execn.Call)\n    from cnvalidD [OF valid_modif [rule_format, of n \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with ret_modif have \"Normal (return' s t') =\n      Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy n\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (auto intro: execn_call)\n    from cnvalidD [OF valid_call [rule_format] ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy m t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> =m\\<Rightarrow> Abrupt t'\"\n    assume n: \"n = Suc m\"\n    assume t: \"t = Abrupt (return s t')\"\n    also from exec_body n bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal (init s)\\<rangle> =n\\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: execn.intros)\n    from cnvalidD [OF valid_modif [rule_format, of n \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\"  .\n    with exec_body bdy n\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (auto intro: execn_callAbrupt)\n    from cnvalidD [OF valid_call [rule_format] ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy m f\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> =m\\<Rightarrow> Fault f\" \"n = Suc m\"\n      \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (auto intro: execn_callFault)\n    from valid_call [rule_format] ctxt this P t_notin_F\n    show ?thesis\n      by (rule cnvalidD)\n  next\n    fix bdy m\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> =m\\<Rightarrow> Stuck\" \"n = Suc m\"\n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (auto intro: execn_callStuck)\n    from valid_call [rule_format] ctxt this P t_notin_F\n    show ?thesis\n      by (rule cnvalidD)\n  next\n    fix m\n    assume \"\\<Gamma> p = None\"\n    and  \"n = Suc m\" \"t = Stuck\"\n    then have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (auto intro: execn_callUndefined)\n    from valid_call [rule_format] ctxt this P t_notin_F\n    show ?thesis\n      by (rule cnvalidD)\n  qed\nqed\n\n\nlemma ProcModifyReturn:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes result_conform:\n      \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes return_conform:\n      \"\\<forall>s t. t \\<in> ModifAbr (init s)\n             \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:\n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} Call p (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule hoare_complete')\napply (rule allI)\napply (rule ProcModifyReturn_sound\n          [where Modif=Modif and ModifAbr=ModifAbr,\n            OF _ _ result_conform return_conform] )\nusing spec\napply (blast intro: hoare_cnvalid)\nusing modifies_spec\napply (blast intro: hoare_cnvalid)\ndone\n\nlemma ProcModifyReturnSameFaults_sound:\n  assumes valid_call: \"\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P call init p return' c Q,A\"\n  assumes valid_modif:\n    \"\\<forall>\\<sigma>. \\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> {\\<sigma>} Call p (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  assumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s)\n           \\<longrightarrow> return' s t = return s t\"\n  assumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s)\n                             \\<longrightarrow> return' s t = return s t\"\n  shows \"\\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>call init p return c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from exec\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: execn_call_Normal_elim)\n    fix bdy m t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> =m\\<Rightarrow> Normal t'\"\n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> =Suc m\\<Rightarrow> t\"\n    assume n: \"n = Suc m\"\n    from exec_body n bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal (init s)\\<rangle> =n\\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: execn.intros)\n    from cnvalidD [OF valid_modif [rule_format, of n \"init s\"] ctxt this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with ret_modif have \"Normal (return' s t') =\n      Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy n\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (auto intro: execn_call)\n    from cnvalidD [OF valid_call [rule_format] ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy m t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> =m\\<Rightarrow> Abrupt t'\"\n    assume n: \"n = Suc m\"\n    assume t: \"t = Abrupt (return s t')\"\n    also\n    from exec_body n bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal (init s)\\<rangle> =n \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: execn.intros)\n    from cnvalidD [OF valid_modif [rule_format, of n \"init s\"] ctxt this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy n\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (auto intro: execn_callAbrupt)\n    from cnvalidD [OF valid_call [rule_format] ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy m f\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> =m\\<Rightarrow> Fault f\" \"n = Suc m\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (auto intro: execn_callFault)\n    from cnvalidD [OF valid_call [rule_format] ctxt this P] t t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy m\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> =m\\<Rightarrow> Stuck\" \"n = Suc m\"\n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (auto intro: execn_callStuck)\n    from valid_call [rule_format] ctxt this P t_notin_F\n    show ?thesis\n      by (rule cnvalidD)\n  next\n    fix m\n    assume \"\\<Gamma> p = None\"\n    and  \"n = Suc m\" \"t = Stuck\"\n    then have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (auto intro: execn_callUndefined)\n    from valid_call [rule_format] ctxt this P t_notin_F\n    show ?thesis\n      by (rule cnvalidD)\n  qed\nqed\n\n\nlemma ProcModifyReturnSameFaults:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes result_conform:\n      \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes return_conform:\n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:\n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call p (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule hoare_complete')\napply (rule allI)\napply (rule ProcModifyReturnSameFaults_sound\n          [where Modif=Modif and ModifAbr=ModifAbr,\n         OF _ _ result_conform return_conform])\nusing spec\napply (blast intro: hoare_cnvalid)\nusing modifies_spec\napply (blast intro: hoare_cnvalid)\ndone\n\nsubsubsection \\<open>DynCall\\<close>\n\nlemma dynProcModifyReturn_sound:\nassumes valid_call: \"\\<And>n. \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes valid_modif:\n    \"\\<forall>s \\<in> P. \\<forall>\\<sigma>. \\<forall>n.\n       \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/UNIV\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s)\n           \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s)\n                             \\<longrightarrow> return' s t = return s t\"\nshows \"\\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: nvalid_augment_Faults)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  assume P: \"s \\<in> P\"\n  with valid_modif\n  have valid_modif': \"\\<forall>\\<sigma>. \\<forall>n.\n       \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/UNIV\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n    by blast\n  from exec\n  have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n    by (cases rule: execn_dynCall_Normal_elim)\n  then show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: execn_call_Normal_elim)\n    fix bdy m t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> =m\\<Rightarrow> Normal t'\"\n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> =Suc m\\<Rightarrow> t\"\n    assume n: \"n = Suc m\"\n    from exec_body n bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s) ,Normal (init s)\\<rangle> =n\\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: execn.intros)\n    from cnvalidD [OF valid_modif' [rule_format, of n \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with ret_modif have \"Normal (return' s t') = Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy n\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (auto intro: execn_call)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (rule execn_dynCall)\n    from cnvalidD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy m t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> =m\\<Rightarrow> Abrupt t'\"\n    assume n: \"n = Suc m\"\n    assume t: \"t = Abrupt (return s t')\"\n    also from exec_body n bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s) ,Normal (init s)\\<rangle> =n\\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: execn.intros)\n    from cnvalidD [OF valid_modif' [rule_format, of n \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy n\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (auto intro: execn_callAbrupt)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (rule execn_dynCall)\n    from cnvalidD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy m f\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> =m\\<Rightarrow> Fault f\" \"n = Suc m\"\n      \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (auto intro: execn_callFault)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (rule execn_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cnvalidD)\n  next\n    fix bdy m\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> =m\\<Rightarrow> Stuck\" \"n = Suc m\"\n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (auto intro: execn_callStuck)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (rule execn_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cnvalidD)\n  next\n    fix m\n    assume \"\\<Gamma> (p s) = None\"\n    and  \"n = Suc m\" \"t = Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (auto intro: execn_callUndefined)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (rule execn_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cnvalidD)\n  qed\nqed\n\nlemma dynProcModifyReturn:\nassumes dyn_call: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s)\n           \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s)\n                             \\<longrightarrow> return' s t = return s t\"\nassumes modif:\n    \"\\<forall>s \\<in> P. \\<forall>\\<sigma>.\n       \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\napply (rule hoare_complete')\napply (rule allI)\napply (rule dynProcModifyReturn_sound [where Modif=Modif and ModifAbr=ModifAbr,\n          OF hoare_cnvalid [OF dyn_call] _ ret_modif ret_modifAbr])\napply (intro ballI allI)\napply (rule hoare_cnvalid [OF modif [rule_format]])\napply assumption\ndone\n\nlemma dynProcModifyReturnSameFaults_sound:\nassumes valid_call: \"\\<And>n. \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes valid_modif:\n    \"\\<forall>s \\<in> P. \\<forall>\\<sigma>. \\<forall>n.\n       \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\nshows \"\\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  assume P: \"s \\<in> P\"\n  with valid_modif\n  have valid_modif': \"\\<forall>\\<sigma>. \\<forall>n.\n    \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n    by blast\n  from exec\n  have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n    by (cases rule: execn_dynCall_Normal_elim)\n  then show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: execn_call_Normal_elim)\n    fix bdy m t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> =m\\<Rightarrow> Normal t'\"\n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> =Suc m\\<Rightarrow> t\"\n    assume n: \"n = Suc m\"\n    from exec_body n bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s) ,Normal (init s)\\<rangle> =n \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: execn.Call)\n    from cnvalidD [OF valid_modif' [rule_format, of n \"init s\"] ctxt this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with ret_modif have \"Normal (return' s t') = Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy n\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (auto intro: execn_call)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (rule execn_dynCall)\n    from cnvalidD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy m t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> =m\\<Rightarrow> Abrupt t'\"\n    assume n: \"n = Suc m\"\n    assume t: \"t = Abrupt (return s t')\"\n    also from exec_body n bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s) ,Normal (init s)\\<rangle> =n \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: execn.intros)\n    from cnvalidD [OF valid_modif' [rule_format, of n \"init s\"] ctxt this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy n\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (auto intro: execn_callAbrupt)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (rule execn_dynCall)\n    from cnvalidD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy m f\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> =m\\<Rightarrow> Fault f\" \"n = Suc m\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (auto intro: execn_callFault)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (rule execn_dynCall)\n    from cnvalidD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy m\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> =m\\<Rightarrow> Stuck\" \"n = Suc m\"\n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (auto intro: execn_callStuck)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (rule execn_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cnvalidD)\n  next\n    fix m\n    assume \"\\<Gamma> (p s) = None\"\n    and  \"n = Suc m\" \"t = Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (auto intro: execn_callUndefined)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by (rule execn_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cnvalidD)\n  qed\nqed\n\nlemma dynProcModifyReturnSameFaults:\nassumes dyn_call: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s)\n           \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s)\n                             \\<longrightarrow> return' s t = return s t\"\nassumes modif:\n    \"\\<forall>s \\<in> P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\napply (rule hoare_complete')\napply (rule allI)\napply (rule dynProcModifyReturnSameFaults_sound\n        [where Modif=Modif and ModifAbr=ModifAbr,\n           OF hoare_cnvalid [OF dyn_call] _ ret_modif ret_modifAbr])\napply (intro ballI allI)\napply (rule hoare_cnvalid [OF modif [rule_format]])\napply assumption\ndone\n\n\nsubsubsection \\<open>Conjunction of Postcondition\\<close>\n\nlemma PostConjI_sound:\nassumes valid_Q: \"\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\nassumes valid_R: \"\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P c R,B\"\nshows \"\\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from valid_Q [rule_format] ctxt exec P t_notin_F have \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    by (rule cnvalidD)\n  moreover\n  from valid_R [rule_format] ctxt exec P t_notin_F have \"t \\<in> Normal ` R \\<union> Abrupt ` B\"\n    by (rule cnvalidD)\n  ultimately show \"t \\<in> Normal ` (Q \\<inter> R) \\<union> Abrupt ` (A \\<inter> B)\"\n    by blast\nqed\n\nlemma PostConjI:\n  assumes deriv_Q: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes deriv_R: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c R,B\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\napply (rule hoare_complete')\napply (rule allI)\napply (rule PostConjI_sound)\nusing deriv_Q\napply (blast intro: hoare_cnvalid)\nusing deriv_R\napply (blast intro: hoare_cnvalid)\ndone\n\nlemma Merge_PostConj_sound:\n  assumes validF: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes validG: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/G\\<^esub> P' c R,X\"\n  assumes F_G: \"F \\<subseteq> G\"\n  assumes P_P': \"P \\<subseteq> P'\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> X)\"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  with F_G have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/G\\<^esub> P (Call p) Q,A\"\n    by (auto intro: nvalid_augment_Faults)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  with P_P' have P': \"s \\<in> P'\"\n    by auto\n  assume t_noFault: \"t \\<notin> Fault ` F\"\n  show \"t \\<in> Normal ` (Q \\<inter> R) \\<union> Abrupt ` (A \\<inter> X)\"\n  proof -\n    from cnvalidD [OF validF [rule_format] ctxt exec P t_noFault]\n    have *: \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\n    then have \"t \\<notin> Fault ` G\"\n      by auto\n    from cnvalidD [OF validG [rule_format] ctxt' exec P' this]\n    have \"t \\<in> Normal ` R \\<union> Abrupt ` X\" .\n    with * show ?thesis by auto\n  qed\nqed\n\nlemma Merge_PostConj:\n  assumes validF: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes validG: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/G\\<^esub> P' c R,X\"\n  assumes F_G: \"F \\<subseteq> G\"\n  assumes P_P': \"P \\<subseteq> P'\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> X)\"\napply (rule hoare_complete')\napply (rule allI)\napply (rule Merge_PostConj_sound [OF _ _ F_G P_P'])\nusing validF apply (blast intro:hoare_cnvalid)\nusing validG apply (blast intro:hoare_cnvalid)\ndone\n\nsubsubsection \\<open>Weaken Context\\<close>\n\n\nlemma WeakenContext_sound:\n  assumes valid_c: \"\\<forall>n. \\<Gamma>,\\<Theta>'\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes valid_ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>'. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  with valid_ctxt\n  have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>'. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (simp add: cnvalid_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from valid_c [rule_format] ctxt' exec P t_notin_F\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    by (rule cnvalidD)\nqed\n\nlemma WeakenContext:\n  assumes deriv_c: \"\\<Gamma>,\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes deriv_ctxt: \"\\<forall>(P,p,Q,A)\\<in>\\<Theta>'. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\napply (rule hoare_complete')\napply (rule allI)\napply (rule WeakenContext_sound)\nusing deriv_c\napply (blast intro: hoare_cnvalid)\nusing deriv_ctxt\napply (blast intro: hoare_cnvalid)\ndone\n\nsubsubsection \\<open>Guards and Guarantees\\<close>\n\nlemma SplitGuards_sound:\nassumes valid_c1: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,A\"\nassumes valid_c2: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c\\<^sub>2 UNIV,UNIV\"\nassumes c: \"(c\\<^sub>1 \\<inter>\\<^sub>g c\\<^sub>2) = Some c\"\nshows \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases t)\n    case Normal\n    with inter_guards_execn_noFault [OF c exec]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> =n\\<Rightarrow> t\" by simp\n    from valid_c1 [rule_format] ctxt this P t_notin_F\n    show ?thesis\n      by (rule cnvalidD)\n  next\n    case Abrupt\n    with inter_guards_execn_noFault [OF c exec]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> =n\\<Rightarrow> t\" by simp\n    from valid_c1 [rule_format] ctxt this P t_notin_F\n    show ?thesis\n      by (rule cnvalidD)\n  next\n    case (Fault f)\n    with exec inter_guards_execn_Fault [OF c]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> =n\\<Rightarrow> Fault f \\<or> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> =n\\<Rightarrow> Fault f\"\n      by auto\n    then show ?thesis\n    proof (cases rule: disjE [consumes 1])\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> =n\\<Rightarrow> Fault f\"\n      from Fault cnvalidD [OF valid_c1 [rule_format] ctxt this P] t_notin_F\n      show ?thesis\n        by blast\n    next\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> =n\\<Rightarrow> Fault f\"\n      from Fault cnvalidD [OF valid_c2 [rule_format] ctxt this P] t_notin_F\n      show ?thesis\n        by blast\n    qed\n  next\n    case Stuck\n    with inter_guards_execn_noFault [OF c exec]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> =n\\<Rightarrow> t\" by simp\n    from valid_c1 [rule_format] ctxt this P t_notin_F\n    show ?thesis\n      by (rule cnvalidD)\n  qed\nqed\n\nlemma SplitGuards:\n  assumes c: \"(c\\<^sub>1 \\<inter>\\<^sub>g c\\<^sub>2) = Some c\"\n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,A\"\n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>2 UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\napply (rule hoare_complete')\napply (rule allI)\napply (rule SplitGuards_sound [OF _ _ c])\nusing deriv_c1\napply (blast intro: hoare_cnvalid)\nusing deriv_c2\napply (blast intro: hoare_cnvalid)\ndone\n\nlemma CombineStrip_sound:\n  assumes valid: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes valid_strip: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/{}\\<^esub> P (strip_guards (-F) c) UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (auto intro: nvalid_augment_Faults)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases t)\n    case (Normal t')\n    from cnvalidD [OF valid [rule_format] ctxt' exec P] Normal\n    show ?thesis\n      by auto\n  next\n    case (Abrupt t')\n    from cnvalidD [OF valid [rule_format] ctxt' exec P] Abrupt\n    show ?thesis\n      by auto\n  next\n    case (Fault f)\n    show ?thesis\n    proof (cases \"f \\<in> F\")\n      case True\n      hence \"f \\<notin> -F\" by simp\n      with exec Fault\n      have \"\\<Gamma>\\<turnstile>\\<langle>strip_guards (-F) c,Normal s\\<rangle> =n\\<Rightarrow> Fault f\"\n        by (auto intro: execn_to_execn_strip_guards_Fault)\n      from cnvalidD [OF valid_strip [rule_format] ctxt this P] Fault\n      have False\n        by auto\n      thus ?thesis ..\n    next\n      case False\n      with cnvalidD [OF valid [rule_format] ctxt' exec P] Fault\n      show ?thesis\n        by auto\n    qed\n  next\n    case Stuck\n    from cnvalidD [OF valid [rule_format] ctxt' exec P] Stuck\n    show ?thesis\n      by auto\n  qed\nqed\n\nlemma CombineStrip:\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes deriv_strip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P (strip_guards (-F) c) UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoare_complete')\napply (rule allI)\napply (rule CombineStrip_sound)\napply  (iprover intro: hoare_cnvalid [OF deriv])\napply (iprover intro: hoare_cnvalid [OF deriv_strip])\ndone\n\nlemma GuardsFlip_sound:\n  assumes valid: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes validFlip: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/-F\\<^esub> P c UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (auto intro: nvalid_augment_Faults)\n  from ctxt have ctxtFlip: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/-F\\<^esub> P (Call p) Q,A\"\n    by (auto intro: nvalid_augment_Faults)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases t)\n    case (Normal t')\n    from cnvalidD [OF valid [rule_format] ctxt' exec P] Normal\n    show ?thesis\n      by auto\n  next\n    case (Abrupt t')\n    from cnvalidD [OF valid [rule_format] ctxt' exec P] Abrupt\n    show ?thesis\n      by auto\n  next\n    case (Fault f)\n    show ?thesis\n    proof (cases \"f \\<in> F\")\n      case True\n      hence \"f \\<notin> -F\" by simp\n      with cnvalidD [OF validFlip [rule_format] ctxtFlip exec P] Fault\n      have False\n        by auto\n      thus ?thesis ..\n    next\n      case False\n      with cnvalidD [OF valid [rule_format] ctxt' exec P] Fault\n      show ?thesis\n        by auto\n    qed\n  next\n    case Stuck\n    from cnvalidD [OF valid [rule_format] ctxt' exec P] Stuck\n    show ?thesis\n      by auto\n  qed\nqed\n\nlemma GuardsFlip:\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes derivFlip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/-F\\<^esub> P c UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoare_complete')\napply (rule allI)\napply (rule GuardsFlip_sound)\napply  (iprover intro: hoare_cnvalid [OF deriv])\napply (iprover intro: hoare_cnvalid [OF derivFlip])\ndone\n\nlemma MarkGuardsI_sound:\n  assumes valid: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/{}\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n  from execn_mark_guards_to_execn [OF exec] obtain t' where\n    exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> t'\" and\n    t'_noFault: \"\\<not> isFault t' \\<longrightarrow> t' = t\"\n    by blast\n  assume P: \"s \\<in> P\"\n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof -\n    from cnvalidD [OF valid [rule_format] ctxt exec_c P]\n    have \"t' \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by blast\n    with t'_noFault\n    show ?thesis\n      by auto\n  qed\nqed\n\nlemma MarkGuardsI:\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\"\napply (rule hoare_complete')\napply (rule allI)\napply (rule MarkGuardsI_sound)\napply (iprover intro: hoare_cnvalid [OF deriv])\ndone\n\nlemma MarkGuardsD_sound:\n  assumes valid: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases \"isFault t\")\n    case True\n    with execn_to_execn_mark_guards_Fault [OF exec ]\n    obtain f' where \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c,Normal s\\<rangle> =n\\<Rightarrow> Fault f'\"\n      by (fastforce elim: isFaultE)\n    from cnvalidD [OF valid [rule_format] ctxt this P]\n    have False\n      by auto\n    thus ?thesis ..\n  next\n    case False\n    from execn_to_execn_mark_guards [OF exec False]\n    obtain f' where \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n      by auto\n    from cnvalidD [OF valid [rule_format] ctxt this P]\n    show ?thesis\n      by auto\n  qed\nqed\n\nlemma MarkGuardsD:\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoare_complete')\napply (rule allI)\napply (rule MarkGuardsD_sound)\napply (iprover intro: hoare_cnvalid [OF deriv])\ndone\n\nlemma MergeGuardsI_sound:\n  assumes valid: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P merge_guards c Q,A\"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume exec_merge: \"\\<Gamma>\\<turnstile>\\<langle>merge_guards c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n  from execn_merge_guards_to_execn [OF exec_merge]\n  have exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> t\" .\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from cnvalidD [OF valid [rule_format] ctxt exec P t_notin_F]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nqed\n\nlemma MergeGuardsI:\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P merge_guards c Q,A\"\napply (rule hoare_complete')\napply (rule allI)\napply (rule MergeGuardsI_sound)\napply (iprover intro: hoare_cnvalid [OF deriv])\ndone\n\nlemma MergeGuardsD_sound:\n  assumes valid: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P merge_guards c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n  from execn_to_execn_merge_guards [OF exec]\n  have exec_merge: \"\\<Gamma>\\<turnstile>\\<langle>merge_guards c,Normal s\\<rangle> =n\\<Rightarrow> t\".\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from cnvalidD [OF valid [rule_format] ctxt exec_merge P t_notin_F]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nqed\n\n\n\n\nlemma SubsetGuards_sound:\n  assumes c_c': \"c \\<subseteq>\\<^sub>g c'\"\n  assumes valid: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/{}\\<^esub> P c' Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n  from execn_to_execn_subseteq_guards [OF c_c' exec] obtain t' where\n    exec_c': \"\\<Gamma>\\<turnstile>\\<langle>c',Normal s\\<rangle> =n\\<Rightarrow> t'\" and\n    t'_noFault: \"\\<not> isFault t' \\<longrightarrow> t' = t\"\n    by blast\n  assume P: \"s \\<in> P\"\n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  from cnvalidD [OF valid [rule_format] ctxt exec_c' P] t'_noFault t_noFault\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    by auto\nqed\n\nlemma SubsetGuards:\n  assumes c_c': \"c \\<subseteq>\\<^sub>g c'\"\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c' Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoare_complete')\napply (rule allI)\napply (rule SubsetGuards_sound [OF c_c'])\napply (iprover intro: hoare_cnvalid [OF deriv])\ndone\n\nlemma NormalizeD_sound:\n  assumes valid: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n  hence exec_norm: \"\\<Gamma>\\<turnstile>\\<langle>normalize c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n    by (rule execn_to_execn_normalize)\n  assume P: \"s \\<in> P\"\n  assume noFault: \"t \\<notin> Fault ` F\"\n  from cnvalidD [OF valid [rule_format] ctxt exec_norm P noFault]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nqed\n\nlemma NormalizeD:\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\napply (rule hoare_complete')\napply (rule allI)\napply (rule NormalizeD_sound)\napply (iprover intro: hoare_cnvalid [OF deriv])\ndone\n\nlemma NormalizeI_sound:\n  assumes valid: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\nproof (rule cnvalidI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume \"\\<Gamma>\\<turnstile>\\<langle>normalize c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n  hence exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n    by (rule execn_normalize_to_execn)\n  assume P: \"s \\<in> P\"\n  assume noFault: \"t \\<notin> Fault ` F\"\n  from cnvalidD [OF valid [rule_format] ctxt exec P noFault]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nqed\n\nlemma NormalizeI:\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\napply (rule hoare_complete')\napply (rule allI)\napply (rule NormalizeI_sound)\napply (iprover intro: hoare_cnvalid [OF deriv])\ndone\n\n\nsubsubsection \\<open>Restricting the Procedure Environment\\<close>\n\nlemma nvalid_restrict_to_nvalid:\nassumes valid_c: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\nshows \"\\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule nvalidI)\n  fix s t\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof -\n    from execn_to_execn_restrict [OF exec]\n    obtain t' where\n      exec_res: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>\\<langle>c,Normal s\\<rangle> =n\\<Rightarrow> t'\" and\n      t_Fault: \"\\<forall>f. t = Fault f \\<longrightarrow> t' \\<in> {Fault f, Stuck}\" and\n      t'_notStuck: \"t'\\<noteq>Stuck \\<longrightarrow> t'=t\"\n      by blast\n    from t_Fault t_notin_F t'_notStuck have \"t' \\<notin> Fault ` F\"\n      by (cases t') auto\n    with valid_c exec_res P\n    have \"t' \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by (auto simp add: nvalid_def)\n    with t'_notStuck\n    show ?thesis\n      by auto\n  qed\nqed\n\nlemma valid_restrict_to_valid:\nassumes valid_c: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\nshows \"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule validI)\n  fix s t\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof -\n    from exec_to_exec_restrict [OF exec]\n    obtain t' where\n      exec_res: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t'\" and\n      t_Fault: \"\\<forall>f. t = Fault f \\<longrightarrow> t' \\<in> {Fault f, Stuck}\" and\n      t'_notStuck: \"t'\\<noteq>Stuck \\<longrightarrow> t'=t\"\n      by blast\n    from t_Fault t_notin_F t'_notStuck have \"t' \\<notin> Fault ` F\"\n      by (cases t') auto\n    with valid_c exec_res P\n    have \"t' \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by (auto simp add: valid_def)\n    with t'_notStuck\n    show ?thesis\n      by auto\n  qed\nqed\n\nlemma augment_procs:\nassumes deriv_c: \"\\<Gamma>|\\<^bsub>M\\<^esub>,{}\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\nshows \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule hoare_complete)\n  apply (rule valid_restrict_to_valid)\n  apply (insert hoare_sound [OF deriv_c])\n  by (simp add: cvalid_def)\n\nlemma augment_Faults:\nassumes deriv_c: \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\nassumes F: \"F \\<subseteq> F'\"\nshows \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/F'\\<^esub> P c Q,A\"\n  apply (rule hoare_complete)\n  apply (rule valid_augment_Faults [OF _ F])\n  apply (insert hoare_sound [OF deriv_c])\n  by (simp add: cvalid_def)\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/c-parser/Simpl/HoarePartialProps.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953797290153, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.28649189443153006}}
{"text": "(*  File:       Maximum_Parallel_Composition.thy\n    Copyright   2021  Karlsruhe Institute of Technology (KIT)\n*)\n\\<^marker>\\<open>creator \"Karsten Diekhoff, Karlsruhe Institute of Technology (KIT)\"\\<close>\n\\<^marker>\\<open>contributor \"Jonas Kraemer, Karlsruhe Institute of Technology (KIT)\"\\<close>\n\\<^marker>\\<open>contributor \"Michael Kirsten, Karlsruhe Institute of Technology (KIT)\"\\<close>\n\nsection \\<open>Maximum Parallel Composition\\<close>\n\ntheory Maximum_Parallel_Composition\n  imports \"Basic_Modules/Component_Types/Maximum_Aggregator\"\n          Parallel_Composition\nbegin\n\ntext\n\\<open>This is a family of parallel compositions. It composes a new electoral module\nfrom two electoral modules combined with the maximum aggregator. Therein, the\ntwo modules each make a decision and then a partition is returned where every\nalternative receives the maximum result of the two input partitions. This means\nthat, if any alternative is elected by at least one of the modules, then it\ngets elected, if any non-elected alternative is deferred by at least one of the\nmodules, then it gets deferred, only alternatives rejected by both modules get\nrejected.\\<close>\n\nsubsection \\<open>Definition\\<close>\n\nfun maximum_parallel_composition :: \"'a Electoral_Module \\<Rightarrow>\n        'a Electoral_Module \\<Rightarrow> 'a Electoral_Module\" where\n  \"maximum_parallel_composition m n =\n    (let a = max_aggregator in (m \\<parallel>\\<^sub>a n))\"\n\nabbreviation max_parallel :: \"'a Electoral_Module \\<Rightarrow> 'a Electoral_Module \\<Rightarrow>\n        'a Electoral_Module\" (infix \"\\<parallel>\\<^sub>\\<up>\" 50) where\n  \"m \\<parallel>\\<^sub>\\<up> n == maximum_parallel_composition m n\"\n\nsubsection \\<open>Soundness\\<close>\n\ntheorem max_par_comp_sound:\n  assumes\n    mod_m: \"electoral_module m\" and\n    mod_n: \"electoral_module n\"\n  shows \"electoral_module (m \\<parallel>\\<^sub>\\<up> n)\"\n  using mod_m mod_n\n  by simp\n\nsubsection \\<open>Lemmata\\<close>\n\nlemma max_agg_eq_result:\n  assumes\n    module_m: \"electoral_module m\" and\n    module_n: \"electoral_module n\" and\n    f_prof: \"finite_profile A p\" and\n    in_A: \"x \\<in> A\"\n  shows\n    \"mod_contains_result (m \\<parallel>\\<^sub>\\<up> n) m A p x \\<or>\n      mod_contains_result (m \\<parallel>\\<^sub>\\<up> n) n A p x\"\nproof cases\n  assume a1: \"x \\<in> elect (m \\<parallel>\\<^sub>\\<up> n) A p\"\n    have mod_contains_inst:\n      \"\\<forall>p_mod q_mod a_set prof a.\n        mod_contains_result p_mod q_mod a_set prof (a::'a) =\n          (electoral_module p_mod \\<and> electoral_module q_mod \\<and>\n            finite a_set \\<and> profile a_set prof \\<and> a \\<in> a_set \\<and>\n            (a \\<notin> elect p_mod a_set prof \\<or> a \\<in> elect q_mod a_set prof) \\<and>\n            (a \\<notin> reject p_mod a_set prof \\<or> a \\<in> reject q_mod a_set prof) \\<and>\n            (a \\<notin> defer p_mod a_set prof \\<or> a \\<in> defer q_mod a_set prof))\"\n      by (simp add: mod_contains_result_def)\n  have module_mn: \"electoral_module (m \\<parallel>\\<^sub>\\<up> n)\"\n    by (simp add: module_m module_n)\n  have not_defer_mn: \"x \\<notin> defer (m \\<parallel>\\<^sub>\\<up> n) A p\"\n    using module_mn IntI a1 empty_iff f_prof result_disj\n    by (metis (no_types))\n  have not_reject_mn: \"x \\<notin> reject (m \\<parallel>\\<^sub>\\<up> n) A p\"\n    using module_mn IntI a1 empty_iff f_prof result_disj\n    by (metis (no_types))\n  from a1 have\n    \"let (e1, r1, d1) = m A p;\n        (e2, r2, d2) = n A p in\n      x \\<in> e1 \\<union> e2\"\n    by auto\n  hence union_mn: \"x \\<in> (elect m A p) \\<union> (elect n A p)\"\n    by auto\n  thus ?thesis\n    using f_prof in_A module_m module_mn module_n\n          not_defer_mn not_reject_mn union_mn\n          mod_contains_inst\n      by blast\nnext\n  assume not_a1: \"x \\<notin> elect (m \\<parallel>\\<^sub>\\<up> n) A p\"\n  thus ?thesis\n  proof cases\n    assume x_in_def: \"x \\<in> defer (m \\<parallel>\\<^sub>\\<up> n) A p\"\n    thus ?thesis\n    proof (safe)\n      assume not_mod_cont_mn:\n        \"\\<not> mod_contains_result (m \\<parallel>\\<^sub>\\<up> n) n A p x\"\n      have par_emod:\n        \"\\<forall>f g.\n          (electoral_module (f::'a set \\<Rightarrow> 'a Profile \\<Rightarrow> 'a Result) \\<and>\n            electoral_module g) \\<longrightarrow>\n              electoral_module (f \\<parallel>\\<^sub>\\<up> g)\"\n        using max_par_comp_sound\n        by blast\n      hence \"electoral_module (m \\<parallel>\\<^sub>\\<up> n)\"\n        using module_m module_n\n        by blast\n      hence max_par_emod:\n        \"electoral_module (m \\<parallel>\\<^sub>max_aggregator n)\"\n        by simp\n      have set_intersect:\n        \"\\<forall>(a::'a) A B. (a \\<in> A \\<inter> B) = (a \\<in> A \\<and> a \\<in> B)\"\n        by blast\n      obtain\n        s_func :: \"('a set \\<Rightarrow> 'a Profile \\<Rightarrow> 'a Result) \\<Rightarrow> 'a set\" and\n        p_func :: \"('a set \\<Rightarrow> 'a Profile \\<Rightarrow> 'a Result) \\<Rightarrow> 'a Profile\" where\n        well_f:\n        \"\\<forall>f.\n          (\\<not> electoral_module f \\<or>\n            (\\<forall>A prof. (finite A \\<and> profile A prof) \\<longrightarrow> well_formed A (f A prof))) \\<and>\n          (electoral_module f \\<or> finite (s_func f) \\<and> profile (s_func f) (p_func f) \\<and>\n            \\<not> well_formed (s_func f) (f (s_func f) (p_func f)))\"\n        using electoral_module_def\n        by moura\n      hence wf_n: \"well_formed A (n A p)\"\n        using f_prof module_n\n        by blast\n      have wf_m: \"well_formed A (m A p)\"\n        using well_f f_prof module_m\n        by blast\n      have a_exists: \"\\<forall>(a::'a). a \\<notin> {}\"\n        by blast\n      have e_mod_par:\n        \"electoral_module (m \\<parallel>\\<^sub>\\<up> n)\"\n        using par_emod module_m module_n\n        by blast\n      hence \"electoral_module (m \\<parallel>\\<^sub>max_aggregator n)\"\n        by simp\n      hence result_disj_max:\n        \"elect (m \\<parallel>\\<^sub>max_aggregator n) A p \\<inter> reject (m \\<parallel>\\<^sub>max_aggregator n) A p = {} \\<and>\n          elect (m \\<parallel>\\<^sub>max_aggregator n) A p \\<inter> defer (m \\<parallel>\\<^sub>max_aggregator n) A p = {} \\<and>\n          reject (m \\<parallel>\\<^sub>max_aggregator n) A p \\<inter> defer (m \\<parallel>\\<^sub>max_aggregator n) A p = {}\"\n        using f_prof result_disj\n        by metis\n      have x_not_elect:\n        \"x \\<notin> elect (m \\<parallel>\\<^sub>max_aggregator n) A p\"\n        using result_disj_max x_in_def\n        by force\n      have result_m:\n        \"(elect m A p, reject m A p, defer m A p) = m A p\"\n        by auto\n      have result_n:\n        \"(elect n A p, reject n A p, defer n A p) = n A p\"\n        by auto\n      have max_pq:\n        \"\\<forall>(A::'a set) p q.\n          elect_r (max_aggregator A p q) = elect_r p \\<union> elect_r q\"\n        by force\n      have\n        \"x \\<notin> elect (m \\<parallel>\\<^sub>max_aggregator n) A p\"\n        using x_not_elect\n        by blast\n      with max_pq\n      have \"x \\<notin> elect m A p \\<union> elect n A p\"\n        by (simp add: max_pq)\n      hence x_not_elect_mn:\n        \"x \\<notin> elect m A p \\<and> x \\<notin> elect n A p\"\n        by blast\n      have x_not_mpar_rej:\n        \"x \\<notin> reject (m \\<parallel>\\<^sub>max_aggregator n) A p\"\n        using result_disj_max x_in_def\n        by fastforce\n      hence x_not_par_rej:\n        \"x \\<notin> reject (m \\<parallel>\\<^sub>\\<up> n) A p\"\n        by auto\n      have mod_cont_res_fg:\n        \"\\<forall>f g A prof (a::'a).\n          mod_contains_result f g A prof a =\n            (electoral_module f \\<and> electoral_module g \\<and>\n              finite A \\<and> profile A prof \\<and> a \\<in> A \\<and>\n                (a \\<notin> elect f A prof \\<or> a \\<in> elect g A prof) \\<and>\n                (a \\<notin> reject f A prof \\<or> a \\<in> reject g A prof) \\<and>\n                (a \\<notin> defer f A prof \\<or> a \\<in> defer g A prof))\"\n        by (simp add: mod_contains_result_def)\n      have max_agg_res:\n        \"max_aggregator A (elect m A p, reject m A p, defer m A p)\n          (elect n A p, reject n A p, defer n A p) = (m \\<parallel>\\<^sub>max_aggregator n) A p\"\n        by simp\n      have well_f_max:\n        \"\\<forall>r2 r1 e2 e1 d2 d1 A.\n          well_formed A (e1, r1, d1) \\<and> well_formed A (e2, r2, d2) \\<longrightarrow>\n            reject_r (max_aggregator A (e1, r1, d1) (e2, r2, d2)) = r1 \\<inter> r2\"\n        using max_agg_rej_set\n        by metis\n      have e_mod_disj:\n        \"\\<forall>f (A::'a set) prof.\n          (electoral_module f \\<and> finite (A::'a set) \\<and> profile A prof) \\<longrightarrow>\n            elect f A prof \\<union> reject f A prof \\<union> defer f A prof = A\"\n        using result_presv_alts\n        by blast\n      hence e_mod_disj_n:\n        \"elect n A p \\<union> reject n A p \\<union> defer n A p = A\"\n        using f_prof module_n\n        by metis\n      have\n        \"\\<forall>f g A prof (a::'a).\n          mod_contains_result f g A prof a =\n            (electoral_module f \\<and> electoral_module g \\<and>\n              finite A \\<and> profile A prof \\<and> a \\<in> A \\<and>\n              (a \\<notin> elect f A prof \\<or> a \\<in> elect g A prof) \\<and>\n              (a \\<notin> reject f A prof \\<or> a \\<in> reject g A prof) \\<and>\n              (a \\<notin> defer f A prof \\<or> a \\<in> defer g A prof))\"\n        by (simp add: mod_contains_result_def)\n      with e_mod_disj_n\n      have \"x \\<in> reject n A p\"\n        using e_mod_par f_prof in_A module_n not_mod_cont_mn\n              x_not_elect x_not_elect_mn x_not_mpar_rej\n        by auto\n      hence \"x \\<notin> reject m A p\"\n        using well_f_max max_agg_res result_m result_n\n              set_intersect wf_m wf_n x_not_mpar_rej\n        by (metis (no_types))\n      with max_agg_res\n      have\n        \"x \\<notin> defer (m \\<parallel>\\<^sub>\\<up> n) A p \\<or> x \\<in> defer m A p\"\n          using e_mod_disj f_prof in_A module_m x_not_elect_mn\n          by blast\n      with x_not_mpar_rej\n      show \"mod_contains_result (m \\<parallel>\\<^sub>\\<up> n) m A p x\"\n        using mod_cont_res_fg x_not_par_rej e_mod_par f_prof\n              in_A module_m x_not_elect\n        by auto\n    qed\n  next\n    assume not_a2: \"x \\<notin> defer (m \\<parallel>\\<^sub>\\<up> n) A p\"\n    have el_rej_defer:\n      \"(elect m A p, reject m A p, defer m A p) = m A p\"\n      by auto\n    from not_a1 not_a2 have a3:\n      \"x \\<in> reject (m \\<parallel>\\<^sub>\\<up> n) A p\"\n      using electoral_mod_defer_elem in_A module_m module_n\n            f_prof max_par_comp_sound\n      by metis\n    hence\n      \"case snd (m A p) of (Aa, Ab) \\<Rightarrow>\n        case n A p of (Ac, Ad, Ae) \\<Rightarrow>\n          x \\<in> reject_r\n            (max_aggregator A\n              (elect m A p, Aa, Ab) (Ac, Ad, Ae))\"\n      using el_rej_defer\n      by force\n    hence\n      \"let (e1, r1, d1) = m A p;\n          (e2, r2, d2) = n A p in\n        x \\<in> fst (snd (max_aggregator A\n          (e1, r1, d1) (e2, r2, d2)))\"\n      by (simp add: case_prod_unfold)\n    hence\n      \"let (e1, r1, d1) = m A p;\n          (e2, r2, d2) = n A p in\n        x \\<in> A - (e1 \\<union> e2 \\<union> d1 \\<union> d2)\"\n      by simp\n    hence\n      \"x \\<notin> elect m A p \\<union> (defer n A p \\<union> defer m A p)\"\n      by force\n    thus ?thesis\n      using mod_contains_result_comm mod_contains_result_def Un_iff\n            a3 f_prof in_A module_m module_n max_par_comp_sound\n      by (metis (no_types))\n  qed\nqed\n\nlemma max_agg_rej_iff_both_reject:\n  assumes\n    f_prof: \"finite_profile A p\" and\n    module_m: \"electoral_module m\" and\n    module_n: \"electoral_module n\"\n  shows\n    \"x \\<in> reject (m \\<parallel>\\<^sub>\\<up> n) A p \\<longleftrightarrow>\n      (x \\<in> reject m A p \\<and> x \\<in> reject n A p)\"\nproof\n  assume a: \"x \\<in> reject (m \\<parallel>\\<^sub>\\<up> n) A p\"\n  hence\n    \"case n A p of (Aa, Ab, Ac) \\<Rightarrow>\n      x \\<in> reject_r (max_aggregator A\n        (elect m A p, reject m A p, defer m A p) (Aa, Ab, Ac))\"\n    by auto\n  hence\n    \"case snd (m A p) of (Aa, Ab) \\<Rightarrow>\n      case n A p of (Ac, Ad, Ae) \\<Rightarrow>\n        x \\<in> reject_r (max_aggregator A\n          (elect m A p, Aa, Ab) (Ac, Ad, Ae))\"\n    by force\n  with a have\n    \"let (e1, r1, d1) = m A p;\n          (e2, r2, d2) = n A p in\n      x \\<in> fst (snd (max_aggregator A (e1, r1, d1) (e2, r2, d2)))\"\n    by (simp add: prod.case_eq_if)\n  hence\n    \"let (e1, r1, d1) = m A p;\n        (e2, r2, d2) = n A p in\n      x \\<in> A - (e1 \\<union> e2 \\<union> d1 \\<union> d2)\"\n    by simp\n  hence\n    \"x \\<in> A - (elect m A p \\<union> elect n A p \\<union> defer m A p \\<union> defer n A p)\"\n    by auto\n  thus \"x \\<in> reject m A p \\<and> x \\<in> reject n A p\"\n    using Diff_iff Un_iff electoral_mod_defer_elem\n          f_prof module_m module_n\n    by metis\nnext\n  assume a: \"x \\<in> reject m A p \\<and> x \\<in> reject n A p\"\n  hence\n    \"x \\<notin> elect m A p \\<and> x \\<notin> defer m A p \\<and>\n      x \\<notin> elect n A p \\<and> x \\<notin> defer n A p\"\n    using IntI empty_iff module_m module_n f_prof result_disj\n    by metis\n  thus \"x \\<in> reject (m \\<parallel>\\<^sub>\\<up> n) A p\"\n    using DiffD1 a f_prof max_agg_eq_result module_m module_n\n          mod_contains_result_comm mod_contains_result_def\n          reject_not_elec_or_def\n      by (metis (no_types))\nqed\n\nlemma max_agg_rej1:\n  assumes\n    f_prof: \"finite_profile A p\" and\n    module_m: \"electoral_module m\" and\n    module_n: \"electoral_module n\" and\n    rejected: \"x \\<in> reject n A p\"\n  shows\n    \"mod_contains_result m (m \\<parallel>\\<^sub>\\<up> n) A p x\"\n  unfolding mod_contains_result_def\nproof (safe)\n  show \"electoral_module m\"\n    using module_m\n    by simp\nnext\n  show \"electoral_module (m \\<parallel>\\<^sub>\\<up> n)\"\n    using module_m module_n\n    by simp\nnext\n  show \"finite A\"\n    using f_prof\n    by simp\nnext\n  show \"profile A p\"\n    using f_prof\n    by simp\nnext\n  show \"x \\<in> A\"\n    using f_prof module_n reject_in_alts rejected\n    by auto\nnext\n  assume\n    x_in_elect: \"x \\<in> elect m A p\"\n  hence x_not_reject:\n    \"x \\<notin> reject m A p\"\n    using disjoint_iff_not_equal f_prof module_m result_disj\n    by metis\n  have rej_in_A:\n    \"reject n A p \\<subseteq> A\"\n    using f_prof module_n\n    by (simp add: reject_in_alts)\n  have x_in_A: \"x \\<in> A\"\n    using rej_in_A in_mono rejected\n    by metis\n  with x_in_elect x_not_reject\n  show \"x \\<in> elect (m \\<parallel>\\<^sub>\\<up> n) A p\"\n    using f_prof max_agg_eq_result module_m module_n rejected\n          max_agg_rej_iff_both_reject mod_contains_result_comm\n          mod_contains_result_def\n      by metis\nnext\n  assume \"x \\<in> reject m A p\"\n  hence\n    \"x \\<in> reject m A p \\<and> x \\<in> reject n A p\"\n    using rejected\n    by simp\n  thus \"x \\<in> reject (m \\<parallel>\\<^sub>\\<up> n) A p\"\n    using f_prof max_agg_rej_iff_both_reject module_m module_n\n    by (metis (no_types))\nnext\n  assume x_in_defer: \"x \\<in> defer m A p\"\n  hence defer_a:\n    \"\\<exists>a. a \\<in> defer m A p \\<and> x = a\"\n    by simp\n  then obtain x_inst :: 'a where\n    inst_x: \"x = x_inst \\<and> x_inst \\<in> defer m A p\"\n    by metis\n  hence x_not_rej:\n    \"x \\<notin> reject m A p\"\n    using disjoint_iff_not_equal f_prof inst_x module_m result_disj\n    by (metis (no_types))\n  have\n    \"\\<forall>f A prof.\n      (electoral_module f \\<and> finite (A::'a set) \\<and> profile A prof) \\<longrightarrow>\n        elect f A prof \\<union> reject f A prof \\<union> defer f A prof = A\"\n    using result_presv_alts\n    by metis\n  with x_in_defer\n  have \"x \\<in> A\"\n    using f_prof module_m\n    by blast\n  with inst_x x_not_rej\n  show \"x \\<in> defer (m \\<parallel>\\<^sub>\\<up> n) A p\"\n    using f_prof max_agg_eq_result\n          max_agg_rej_iff_both_reject\n          mod_contains_result_comm\n          mod_contains_result_def\n          module_m module_n rejected\n    by metis\nqed\n\nlemma max_agg_rej2:\n  assumes\n    f_prof: \"finite_profile A p\" and\n    module_m: \"electoral_module m\" and\n    module_n: \"electoral_module n\" and\n    rejected: \"x \\<in> reject n A p\"\n  shows\n    \"mod_contains_result (m \\<parallel>\\<^sub>\\<up> n) m A p x\"\n  using mod_contains_result_comm max_agg_rej1\n        module_m module_n f_prof rejected\n  by metis\n\nlemma max_agg_rej3:\n  assumes\n    f_prof:  \"finite_profile A p\" and\n    module_m: \"electoral_module m\" and\n    module_n: \"electoral_module n\" and\n    rejected: \"x \\<in> reject m A p\"\n  shows\n    \"mod_contains_result n (m \\<parallel>\\<^sub>\\<up> n) A p x\"\n  unfolding mod_contains_result_def\nproof (safe)\n  show \"electoral_module n\"\n    using module_n\n    by simp\nnext\n  show \"electoral_module (m \\<parallel>\\<^sub>\\<up> n)\"\n    using module_m module_n\n    by simp\nnext\n  show \"finite A\"\n    using f_prof\n    by simp\nnext\n  show \"profile A p\"\n    using f_prof\n    by simp\nnext\n  show \"x \\<in> A\"\n    using f_prof in_mono module_m reject_in_alts rejected\n    by (metis (no_types))\nnext\n  assume \"x \\<in> elect n A p\"\n  thus \"x \\<in> elect (m \\<parallel>\\<^sub>\\<up> n) A p\"\n    using Un_iff combine_ele_rej_def fst_conv\n          maximum_parallel_composition.simps\n          max_aggregator.simps\n          parallel_composition.simps\n    by (metis (mono_tags, lifting))\nnext\n  assume \"x \\<in> reject n A p\"\n  thus \"x \\<in> reject (m \\<parallel>\\<^sub>\\<up> n) A p\"\n    using f_prof max_agg_rej_iff_both_reject module_m module_n rejected\n    by metis\nnext\n  assume x_in_def: \"x \\<in> defer n A p\"\n  have \"x \\<in> A\"\n    using f_prof max_agg_rej1 mod_contains_result_def module_m rejected\n    by metis\n  thus \"x \\<in> defer (m \\<parallel>\\<^sub>\\<up> n) A p\"\n    using x_in_def disjoint_iff_not_equal f_prof\n          max_agg_eq_result max_agg_rej_iff_both_reject\n          mod_contains_result_comm mod_contains_result_def\n          module_m module_n rejected result_disj\n      by metis\nqed\n\nlemma max_agg_rej4:\n  assumes\n    f_prof: \"finite_profile A p\" and\n    module_m: \"electoral_module m\" and\n    module_n: \"electoral_module n\" and\n    rejected: \"x \\<in> reject m A p\"\n  shows\n    \"mod_contains_result (m \\<parallel>\\<^sub>\\<up> n) n A p x\"\n  using mod_contains_result_comm max_agg_rej3\n        module_m module_n f_prof rejected\n  by metis\n\nlemma max_agg_rej_intersect:\n  assumes\n    module_m: \"electoral_module m\" and\n    module_n: \"electoral_module n\" and\n    f_prof: \"finite_profile A p\"\n  shows\n    \"reject (m \\<parallel>\\<^sub>\\<up> n) A p =\n      (reject m A p) \\<inter> (reject n A p)\"\nproof -\n  have\n    \"A = (elect m A p) \\<union> (reject m A p) \\<union> (defer m A p) \\<and>\n      A = (elect n A p) \\<union> (reject n A p) \\<union> (defer n A p)\"\n    by (simp add: module_m module_n f_prof result_presv_alts)\n  hence\n    \"A - ((elect m A p) \\<union> (defer m A p)) = (reject m A p) \\<and>\n      A - ((elect n A p) \\<union> (defer n A p)) = (reject n A p)\"\n    using module_m module_n f_prof reject_not_elec_or_def\n    by auto\n  hence\n    \"A - ((elect m A p) \\<union> (elect n A p) \\<union> (defer m A p) \\<union> (defer n A p)) =\n      (reject m A p) \\<inter> (reject n A p)\"\n    by blast\n  hence\n    \"let (e1, r1, d1) = m A p;\n        (e2, r2, d2) = n A p in\n      A - (e1 \\<union> e2 \\<union> d1 \\<union> d2) = r1 \\<inter> r2\"\n    by fastforce\n  thus ?thesis\n    by auto\nqed\n\nlemma dcompat_dec_by_one_mod:\n  assumes\n    compatible: \"disjoint_compatibility m n\" and\n    in_A: \"x \\<in> A\"\n  shows\n    \"(\\<forall>p. finite_profile A p \\<longrightarrow>\n          mod_contains_result m (m \\<parallel>\\<^sub>\\<up> n) A p x) \\<or>\n        (\\<forall>p. finite_profile A p \\<longrightarrow>\n          mod_contains_result n (m \\<parallel>\\<^sub>\\<up> n) A p x)\"\n  using DiffI compatible disjoint_compatibility_def\n        in_A max_agg_rej1 max_agg_rej3\n  by metis\n\nsubsection \\<open>Composition Rules\\<close>\n\n(*\n   Using a conservative aggregator, the parallel composition\n   preserves the property non-electing.\n*)\ntheorem conserv_max_agg_presv_non_electing[simp]:\n  assumes\n    non_electing_m: \"non_electing m\" and\n    non_electing_n: \"non_electing n\"\n  shows \"non_electing (m \\<parallel>\\<^sub>\\<up> n)\"\n  using non_electing_m non_electing_n\n  by simp\n\n(*\n   Using the max aggregator, composing two compatible\n   electoral modules in parallel preserves defer-lift-invariance.\n*)\ntheorem par_comp_def_lift_inv[simp]:\n  assumes\n    compatible: \"disjoint_compatibility m n\" and\n    monotone_m: \"defer_lift_invariance m\" and\n    monotone_n: \"defer_lift_invariance n\"\n  shows \"defer_lift_invariance (m \\<parallel>\\<^sub>\\<up> n)\"\n  unfolding defer_lift_invariance_def\nproof (safe)\n  have electoral_mod_m: \"electoral_module m\"\n    using monotone_m\n    by (simp add: defer_lift_invariance_def)\n  have electoral_mod_n: \"electoral_module n\"\n    using monotone_n\n    by (simp add: defer_lift_invariance_def)\n  show \"electoral_module (m \\<parallel>\\<^sub>\\<up> n)\"\n    using electoral_mod_m electoral_mod_n\n    by simp\nnext\n  fix\n    S :: \"'a set\" and\n    p :: \"'a Profile\" and\n    q :: \"'a Profile\" and\n    x :: \"'a\"\n  assume\n    defer_x: \"x \\<in> defer (m \\<parallel>\\<^sub>\\<up> n) S p\" and\n    lifted_x: \"Profile.lifted S p q x\"\n  hence f_profs: \"finite_profile S p \\<and> finite_profile S q\"\n    by (simp add: lifted_def)\n  from compatible\n  obtain A::\"'a set\" where A:\n    \"A \\<subseteq> S \\<and> (\\<forall>x \\<in> A. indep_of_alt m S x \\<and>\n      (\\<forall>p. finite_profile S p \\<longrightarrow> x \\<in> reject m S p)) \\<and>\n        (\\<forall>x \\<in> S-A. indep_of_alt n S x \\<and>\n      (\\<forall>p. finite_profile S p \\<longrightarrow> x \\<in> reject n S p))\"\n    using disjoint_compatibility_def f_profs\n    by (metis (no_types, lifting))\n  have\n    \"\\<forall>x \\<in> S. prof_contains_result (m \\<parallel>\\<^sub>\\<up> n) S p q x\"\n  proof cases\n    assume a0: \"x \\<in> A\"\n    hence \"x \\<in> reject m S p\"\n      using A f_profs\n      by blast\n    with defer_x\n    have defer_n: \"x \\<in> defer n S p\"\n      using compatible disjoint_compatibility_def\n            mod_contains_result_def f_profs max_agg_rej4\n      by metis\n    have\n      \"\\<forall>x \\<in> A. mod_contains_result (m \\<parallel>\\<^sub>\\<up> n) n S p x\"\n      using A compatible disjoint_compatibility_def\n            max_agg_rej4 f_profs\n      by metis\n    moreover have \"\\<forall>x \\<in> S. prof_contains_result n S p q x\"\n      unfolding prof_contains_result_def\n    proof (clarify)\n      fix x :: \"'a\"\n      assume\n        x_in_S: \"x \\<in> S\"\n      show\n        \"electoral_module n \\<and>\n         finite_profile S p \\<and>\n         finite_profile S q \\<and>\n         x \\<in> S \\<and>\n         (x \\<in> elect n S p \\<longrightarrow> x \\<in> elect n S q) \\<and>\n         (x \\<in> reject n S p \\<longrightarrow> x \\<in> reject n S q) \\<and>\n         (x \\<in> defer n S p \\<longrightarrow> x \\<in> defer n S q)\"\n      proof (safe)\n        show \"electoral_module n\"\n          using monotone_n defer_lift_invariance_def\n          by metis\n      next\n        show \"finite S\"\n          using f_profs\n          by simp\n      next\n        show \"profile S p\"\n          using f_profs\n          by simp\n      next\n        show \"finite S\"\n          using f_profs\n          by simp\n      next\n        show \"profile S q\"\n          using f_profs\n          by simp\n      next\n        show \"x \\<in> S\"\n          using x_in_S\n          by simp\n      next\n        assume \"x \\<in> elect n S p\"\n        thus \"x \\<in> elect n S q\"\n          using defer_n lifted_x monotone_n\n                f_profs defer_lift_invariance_def\n          by metis\n      next\n        assume \"x \\<in> reject n S p\"\n        thus \"x \\<in> reject n S q\"\n          using defer_n lifted_x monotone_n\n                f_profs defer_lift_invariance_def\n          by metis\n      next\n        assume \"x \\<in> defer n S p\"\n        thus \"x \\<in> defer n S q\"\n          using defer_n lifted_x monotone_n\n                f_profs defer_lift_invariance_def\n          by metis\n      qed\n    qed\n    moreover have\n      \"\\<forall>x \\<in> A. mod_contains_result n (m \\<parallel>\\<^sub>\\<up> n) S q x\"\n      using A compatible disjoint_compatibility_def\n            max_agg_rej3 f_profs\n      by metis\n    ultimately have 00:\n      \"\\<forall>x \\<in> A. prof_contains_result (m \\<parallel>\\<^sub>\\<up> n) S p q x\"\n      by (simp add: mod_contains_result_def prof_contains_result_def)\n    have\n      \"\\<forall>x \\<in> S-A. mod_contains_result (m \\<parallel>\\<^sub>\\<up> n) m S p x\"\n      using A max_agg_rej2 monotone_m monotone_n f_profs\n            defer_lift_invariance_def\n      by metis\n    moreover have \"\\<forall>x \\<in> S. prof_contains_result m S p q x\"\n      unfolding prof_contains_result_def\n    proof (clarify)\n      fix x :: \"'a\"\n      assume\n        x_in_S: \"x \\<in> S\"\n      show\n        \"electoral_module m \\<and>\n         finite_profile S p \\<and>\n         finite_profile S q \\<and>\n         x \\<in> S \\<and>\n         (x \\<in> elect m S p \\<longrightarrow> x \\<in> elect m S q) \\<and>\n         (x \\<in> reject m S p \\<longrightarrow> x \\<in> reject m S q) \\<and>\n         (x \\<in> defer m S p \\<longrightarrow> x \\<in> defer m S q)\"\n      proof (safe)\n        show \"electoral_module m\"\n          using monotone_m defer_lift_invariance_def\n          by metis\n      next\n        show \"finite S\"\n          using f_profs\n          by simp\n      next\n        show \"profile S p\"\n          using f_profs\n          by simp\n      next\n        show \"finite S\"\n          using f_profs\n          by simp\n      next\n        show \"profile S q\"\n          using f_profs\n          by simp\n      next\n        show \"x \\<in> S\"\n          using x_in_S\n          by simp\n      next\n        assume \"x \\<in> elect m S p\"\n        thus \"x \\<in> elect m S q\"\n          using A a0 indep_of_alt_def lifted_x\n                lifted_imp_equiv_prof_except_a\n          by metis\n      next\n        assume \"x \\<in> reject m S p\"\n        thus \"x \\<in> reject m S q\"\n          using A a0 indep_of_alt_def lifted_x\n                lifted_imp_equiv_prof_except_a\n          by metis\n      next\n        assume \"x \\<in> defer m S p\"\n        thus \"x \\<in> defer m S q\"\n          using A a0 indep_of_alt_def lifted_x\n                lifted_imp_equiv_prof_except_a\n          by metis\n      qed\n    qed\n    moreover have\n      \"\\<forall>x \\<in> S-A. mod_contains_result m (m \\<parallel>\\<^sub>\\<up> n) S q x\"\n      using A max_agg_rej1 monotone_m monotone_n f_profs\n            defer_lift_invariance_def\n      by metis\n    ultimately have 01:\n      \"\\<forall>x \\<in> S-A. prof_contains_result (m \\<parallel>\\<^sub>\\<up> n) S p q x\"\n      by (simp add: mod_contains_result_def prof_contains_result_def)\n    from 00 01\n    show ?thesis\n      by blast\n  next\n    assume \"x \\<notin> A\"\n    hence a1: \"x \\<in> S-A\"\n      using DiffI lifted_x compatible f_profs\n            Profile.lifted_def\n      by (metis (no_types, lifting))\n    hence \"x \\<in> reject n S p\"\n      using A f_profs\n      by blast\n    with defer_x\n    have defer_m: \"x \\<in> defer m S p\"\n      using DiffD1 DiffD2 compatible dcompat_dec_by_one_mod\n            defer_not_elec_or_rej disjoint_compatibility_def\n            not_rej_imp_elec_or_def mod_contains_result_def\n            max_agg_sound par_comp_sound f_profs\n            maximum_parallel_composition.simps\n      by metis\n    have\n      \"\\<forall>x \\<in> A. mod_contains_result (m \\<parallel>\\<^sub>\\<up> n) n S p x\"\n      using A compatible disjoint_compatibility_def\n            max_agg_rej4 f_profs\n      by metis\n    moreover have \"\\<forall>x \\<in> S. prof_contains_result n S p q x\"\n      unfolding prof_contains_result_def\n    proof (clarify)\n      fix x :: \"'a\"\n        assume\n          x_in_S: \"x \\<in> S\"\n        show\n          \"electoral_module n \\<and>\n           finite_profile S p \\<and>\n           finite_profile S q \\<and>\n           x \\<in> S \\<and>\n           (x \\<in> elect n S p \\<longrightarrow> x \\<in> elect n S q) \\<and>\n           (x \\<in> reject n S p \\<longrightarrow> x \\<in> reject n S q) \\<and>\n           (x \\<in> defer n S p \\<longrightarrow> x \\<in> defer n S q)\"\n        proof (safe)\n          show \"electoral_module n\"\n            using monotone_n defer_lift_invariance_def\n            by metis\n        next\n          show \"finite S\"\n            using f_profs\n            by simp\n        next\n          show \"profile S p\"\n            using f_profs\n            by simp\n        next\n          show \"finite S\"\n            using f_profs\n            by simp\n        next\n          show \"profile S q\"\n            using f_profs\n            by simp\n        next\n          show \"x \\<in> S\"\n            using x_in_S\n            by simp\n        next\n          assume \"x \\<in> elect n S p\"\n          thus \"x \\<in> elect n S q\"\n            using A a1 indep_of_alt_def lifted_x\n                  lifted_imp_equiv_prof_except_a\n            by metis\n        next\n          assume \"x \\<in> reject n S p\"\n          thus \"x \\<in> reject n S q\"\n            using A a1 indep_of_alt_def lifted_x\n                  lifted_imp_equiv_prof_except_a\n            by metis\n        next\n          assume \"x \\<in> defer n S p\"\n          thus \"x \\<in> defer n S q\"\n            using A a1 indep_of_alt_def lifted_x\n                  lifted_imp_equiv_prof_except_a\n            by metis\n        qed\n    qed\n    moreover have\n      \"\\<forall>x \\<in> A. mod_contains_result n (m \\<parallel>\\<^sub>\\<up> n) S q x\"\n      using A compatible disjoint_compatibility_def\n            max_agg_rej3 f_profs\n      by metis\n    ultimately have 10:\n      \"\\<forall>x \\<in> A. prof_contains_result (m \\<parallel>\\<^sub>\\<up> n) S p q x\"\n      by (simp add: mod_contains_result_def prof_contains_result_def)\n    have\n      \"\\<forall>x \\<in> S-A. mod_contains_result (m \\<parallel>\\<^sub>\\<up> n) m S p x\"\n      using A max_agg_rej2 monotone_m monotone_n\n            f_profs defer_lift_invariance_def\n      by metis\n    moreover have \"\\<forall>x \\<in> S. prof_contains_result m S p q x\"\n      unfolding prof_contains_result_def\n    proof (clarify)\n      fix x :: \"'a\"\n        assume\n          x_in_S: \"x \\<in> S\"\n        show\n          \"electoral_module m \\<and>\n           finite_profile S p \\<and>\n           finite_profile S q \\<and>\n           x \\<in> S \\<and>\n           (x \\<in> elect m S p \\<longrightarrow> x \\<in> elect m S q) \\<and>\n           (x \\<in> reject m S p \\<longrightarrow> x \\<in> reject m S q) \\<and>\n           (x \\<in> defer m S p \\<longrightarrow> x \\<in> defer m S q)\"\n        proof (safe)\n          show \"electoral_module m\"\n            using monotone_m defer_lift_invariance_def\n            by metis\n        next\n          show \"finite S\"\n            using f_profs\n            by simp\n        next\n          show \"profile S p\"\n            using f_profs\n            by simp\n        next\n          show \"finite S\"\n            using f_profs\n            by simp\n        next\n          show \"profile S q\"\n            using f_profs\n            by simp\n        next\n          show \"x \\<in> S\"\n            using x_in_S\n            by simp\n        next\n          assume \"x \\<in> elect m S p\"\n          thus \"x \\<in> elect m S q\"\n            using defer_lift_invariance_def defer_m\n                  lifted_x monotone_m\n            by metis\n        next\n          assume \"x \\<in> reject m S p\"\n          thus \"x \\<in> reject m S q\"\n            using defer_lift_invariance_def defer_m\n                  lifted_x monotone_m\n            by metis\n        next\n          assume \"x \\<in> defer m S p\"\n          thus \"x \\<in> defer m S q\"\n            using defer_lift_invariance_def defer_m\n                  lifted_x monotone_m\n            by metis\n        qed\n    qed\n    moreover have\n      \"\\<forall>x \\<in> S-A. mod_contains_result m (m \\<parallel>\\<^sub>\\<up> n) S q x\"\n      using A max_agg_rej1 monotone_m monotone_n\n            f_profs defer_lift_invariance_def\n      by metis\n    ultimately have 11:\n      \"\\<forall>x \\<in> S-A. prof_contains_result (m \\<parallel>\\<^sub>\\<up> n) S p q x\"\n      using electoral_mod_defer_elem\n      by (simp add: mod_contains_result_def prof_contains_result_def)\n    from 10 11\n    show ?thesis\n      by blast\n  qed\n  thus \"(m \\<parallel>\\<^sub>\\<up> n) S p = (m \\<parallel>\\<^sub>\\<up> n) S q\"\n    using compatible disjoint_compatibility_def f_profs\n          eq_alts_in_profs_imp_eq_results max_par_comp_sound\n    by metis\nqed\n\nlemma par_comp_rej_card:\n  assumes\n    compatible: \"disjoint_compatibility x y\" and\n    f_prof: \"finite_profile S p\" and\n    reject_sum: \"card (reject x S p) + card (reject y S p) = card S + n\"\n  shows \"card (reject (x \\<parallel>\\<^sub>\\<up> y) S p) = n\"\nproof -\n  from compatible obtain A where A:\n    \"A \\<subseteq> S \\<and>\n      (\\<forall>a \\<in> A. indep_of_alt x S a \\<and>\n          (\\<forall>p. finite_profile S p \\<longrightarrow> a \\<in> reject x S p)) \\<and>\n      (\\<forall>a \\<in> S-A. indep_of_alt y S a \\<and>\n          (\\<forall>p. finite_profile S p \\<longrightarrow> a \\<in> reject y S p))\"\n    using disjoint_compatibility_def f_prof\n    by metis\n  from f_prof compatible\n  have reject_representation:\n    \"reject (x \\<parallel>\\<^sub>\\<up> y) S p = (reject x S p) \\<inter> (reject y S p)\"\n    using max_agg_rej_intersect disjoint_compatibility_def\n    by blast\n  have \"electoral_module x \\<and> electoral_module y\"\n    using compatible disjoint_compatibility_def\n    by auto\n  hence subsets: \"(reject x S p) \\<subseteq> S \\<and> (reject y S p) \\<subseteq> S\"\n    by (simp add: f_prof reject_in_alts)\n  hence \"finite (reject x S p) \\<and> finite (reject y S p)\"\n    using rev_finite_subset f_prof reject_in_alts\n    by auto\n  hence 0:\n    \"card (reject (x \\<parallel>\\<^sub>\\<up> y) S p) =\n        card S + n -\n          card ((reject x S p) \\<union> (reject y S p))\"\n    using card_Un_Int reject_representation reject_sum\n    by fastforce\n  have\n    \"\\<forall>a \\<in> S. a \\<in> (reject x S p) \\<or> a \\<in> (reject y S p)\"\n    using A f_prof\n    by blast\n  hence \"S = reject x S p \\<union> reject y S p\"\n    using subsets\n    by force\n  hence 1: \"card ((reject x S p) \\<union> (reject y S p)) = card S\"\n    by presburger\n  from 0 1\n  show \"card (reject (x \\<parallel>\\<^sub>\\<up> y) S p) = n\"\n    by simp\nqed\n\n(*\n   Using the max-aggregator for composing two compatible modules in parallel,\n   whereof the first one is non-electing and defers exactly one alternative,\n   and the second one rejects exactly two alternatives, the composition\n   results in an electoral module that eliminates exactly one alternative.\n*)\ntheorem par_comp_elim_one[simp]:\n  assumes\n    defers_m_1: \"defers 1 m\" and\n    non_elec_m: \"non_electing m\" and\n    rejec_n_2: \"rejects 2 n\" and\n    disj_comp: \"disjoint_compatibility m n\"\n  shows \"eliminates 1 (m \\<parallel>\\<^sub>\\<up> n)\"\n  unfolding eliminates_def\nproof (safe)\n  have electoral_mod_m: \"electoral_module m\"\n    using non_elec_m\n    by (simp add: non_electing_def)\n  have electoral_mod_n: \"electoral_module n\"\n    using rejec_n_2\n    by (simp add: rejects_def)\n  show \"electoral_module (m \\<parallel>\\<^sub>\\<up> n)\"\n    using electoral_mod_m electoral_mod_n\n    by simp\nnext\n  fix\n    A :: \"'a set\" and\n    p :: \"'a Profile\"\n  assume\n    min_2_card: \"1 < card A\" and\n    fin_A: \"finite A\" and\n    prof_A: \"profile A p\"\n  have card_geq_1: \"card A \\<ge> 1\"\n    using min_2_card dual_order.strict_trans2 less_imp_le_nat\n    by blast\n  have module: \"electoral_module m\"\n    using non_elec_m non_electing_def\n    by auto\n  have elec_card_0: \"card (elect m A p) = 0\"\n    using fin_A prof_A non_elec_m card_eq_0_iff non_electing_def\n    by metis\n  moreover\n  from card_geq_1 have def_card_1:\n    \"card (defer m A p) = 1\"\n    using defers_m_1 module fin_A prof_A\n    by (simp add: defers_def)\n  ultimately have card_reject_m:\n    \"card (reject m A p) = card A - 1\"\n  proof -\n    have \"finite A\"\n      by (simp add: fin_A)\n    moreover have\n      \"well_formed A\n        (elect m A p, reject m A p, defer m A p)\"\n      using fin_A prof_A electoral_module_def module\n      by auto\n    ultimately have\n      \"card A =\n        card (elect m A p) + card (reject m A p) +\n          card (defer m A p)\"\n      using result_count\n      by blast\n    thus ?thesis\n      using def_card_1 elec_card_0\n      by simp\n  qed\n  have case1: \"card A \\<ge> 2\"\n    using min_2_card\n    by auto\n  from case1 have card_reject_n:\n    \"card (reject n A p) = 2\"\n    using fin_A prof_A rejec_n_2 rejects_def\n    by blast\n  from card_reject_m card_reject_n\n  have\n    \"card (reject m A p) + card (reject n A p) =\n      card A + 1\"\n    using card_geq_1\n    by linarith\n  with disj_comp prof_A fin_A card_reject_m card_reject_n\n  show\n    \"card (reject (m \\<parallel>\\<^sub>\\<up> n) A p) = 1\"\n    using par_comp_rej_card\n    by blast\nqed\n\nend\n", "meta": {"author": "ChrisMackKit", "repo": "ba-scoring-rule-reinforcement-homogeneity", "sha": "d87febd04743389ac578b332349ae446b9c55e89", "save_path": "github-repos/isabelle/ChrisMackKit-ba-scoring-rule-reinforcement-homogeneity", "path": "github-repos/isabelle/ChrisMackKit-ba-scoring-rule-reinforcement-homogeneity/ba-scoring-rule-reinforcement-homogeneity-d87febd04743389ac578b332349ae446b9c55e89/verifiedVotingRuleConstruction-master - Bevor Range/theories/Compositional_Structures/Maximum_Parallel_Composition.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.28633032831866884}}
{"text": "(*\nTitle: SIFUM-Type-Systems\nAuthors: Sylvia Grewe, Heiko Mantel, Daniel Schoepe\n*)\nsection \\<open>Language for Instantiating the SIFUM-Security Property\\<close>\n\ntheory Language\nimports Main Preliminaries\nbegin\n\nsubsection \\<open>Syntax\\<close>\n\ndatatype 'var ModeUpd = Acq \"'var\" Mode (infix \"+=\\<^sub>m\" 75)\n  | Rel \"'var\" Mode (infix \"-=\\<^sub>m\" 75)\n\ndatatype ('var, 'aexp, 'bexp) Stmt = Assign \"'var\" \"'aexp\" (infix \"\\<leftarrow>\" 130)\n  | Skip\n  | ModeDecl \"('var, 'aexp, 'bexp) Stmt\" \"'var ModeUpd\" (\"_@[_]\" [0, 0] 150)\n  | Seq \"('var, 'aexp, 'bexp) Stmt\" \"('var, 'aexp, 'bexp) Stmt\" (infixr \";;\" 150)\n  | If \"'bexp\" \"('var, 'aexp, 'bexp) Stmt\" \"('var, 'aexp, 'bexp) Stmt\"\n  | While \"'bexp\" \"('var, 'aexp, 'bexp) Stmt\"\n  | Stop\n\ntype_synonym ('var, 'aexp, 'bexp) EvalCxt = \"('var, 'aexp, 'bexp) Stmt list\"\n\nlocale sifum_lang =\n  fixes eval\\<^sub>A :: \"('Var, 'Val) Mem \\<Rightarrow> 'AExp \\<Rightarrow> 'Val\"\n  fixes eval\\<^sub>B :: \"('Var, 'Val) Mem \\<Rightarrow> 'BExp \\<Rightarrow> bool\"\n  fixes aexp_vars :: \"'AExp \\<Rightarrow> 'Var set\"\n  fixes bexp_vars :: \"'BExp \\<Rightarrow> 'Var set\"\n  fixes dma :: \"'Var \\<Rightarrow> Sec\"\n  assumes Var_finite : \"finite {(x :: 'Var). True}\"\n  assumes eval_vars_det\\<^sub>A : \"\\<lbrakk> \\<forall> x \\<in> aexp_vars e. mem\\<^sub>1 x = mem\\<^sub>2 x \\<rbrakk> \\<Longrightarrow> eval\\<^sub>A mem\\<^sub>1 e = eval\\<^sub>A mem\\<^sub>2 e\"\n  assumes eval_vars_det\\<^sub>B : \"\\<lbrakk> \\<forall> x \\<in> bexp_vars b. mem\\<^sub>1 x = mem\\<^sub>2 x \\<rbrakk> \\<Longrightarrow> eval\\<^sub>B mem\\<^sub>1 b = eval\\<^sub>B mem\\<^sub>2 b\"\n\ncontext sifum_lang\nbegin\n\n(* To make the examples look a bit nicer in the PDF. *)\n\nnotation (latex output)\n  Seq (\"_; _\" 60)\n\nnotation (Rule output)\n  Seq (\"_ ; _\" 60)\n\nnotation (Rule output)\n  If (\"if _ then _ else _ fi\" 50)\n\nnotation (Rule output)\n  While (\"while _ do _ done\")\n\nabbreviation conf\\<^sub>w_abv :: \"('Var, 'AExp, 'BExp) Stmt \\<Rightarrow>\n  'Var Mds \\<Rightarrow> ('Var, 'Val) Mem \\<Rightarrow> (_,_,_) LocalConf\"\n  (\"\\<langle>_, _, _\\<rangle>\\<^sub>w\" [0, 120, 120] 100)\n  where\n  \"\\<langle> c, mds, mem \\<rangle>\\<^sub>w \\<equiv> ((c, mds), mem)\"\n\nsubsection \\<open>Semantics\\<close>\n\nprimrec update_modes :: \"'Var ModeUpd \\<Rightarrow> 'Var Mds \\<Rightarrow> 'Var Mds\"\n  where\n  \"update_modes (Acq x m) mds = mds (m := insert x (mds m))\" |\n  \"update_modes (Rel x m) mds = mds (m := {y. y \\<in> mds m \\<and> y \\<noteq> x})\"\n\nfun updated_var :: \"'Var ModeUpd \\<Rightarrow> 'Var\"\n  where\n  \"updated_var (Acq x _) = x\" |\n  \"updated_var (Rel x _) = x\"\n\nfun updated_mode :: \"'Var ModeUpd \\<Rightarrow> Mode\"\n  where\n  \"updated_mode (Acq _ m) = m\" |\n  \"updated_mode (Rel _ m) = m\"\n\ninductive_set eval\\<^sub>w_simple :: \"(('Var, 'AExp, 'BExp) Stmt \\<times> ('Var, 'Val) Mem) rel\"\nand eval\\<^sub>w_simple_abv :: \"(('Var, 'AExp, 'BExp) Stmt \\<times> ('Var, 'Val) Mem) \\<Rightarrow>\n  ('Var, 'AExp, 'BExp) Stmt \\<times> ('Var, 'Val) Mem \\<Rightarrow> bool\"\n  (infixr \"\\<leadsto>\\<^sub>s\" 60)\n  where\n  \"c \\<leadsto>\\<^sub>s c' \\<equiv> (c, c') \\<in> eval\\<^sub>w_simple\" |\n  assign: \"((x \\<leftarrow> e, mem), (Stop, mem (x := eval\\<^sub>A mem e))) \\<in> eval\\<^sub>w_simple\" |\n  skip: \"((Skip, mem), (Stop, mem)) \\<in> eval\\<^sub>w_simple\" |\n  seq_stop: \"((Seq Stop c, mem), (c, mem)) \\<in> eval\\<^sub>w_simple\" |\n  if_true: \"\\<lbrakk> eval\\<^sub>B mem b \\<rbrakk> \\<Longrightarrow> ((If b t e, mem), (t, mem)) \\<in> eval\\<^sub>w_simple\" |\n  if_false: \"\\<lbrakk> \\<not> eval\\<^sub>B mem b \\<rbrakk> \\<Longrightarrow> ((If b t e, mem), (e, mem)) \\<in> eval\\<^sub>w_simple\" |\n  while: \"((While b c, mem), (If b (c ;; While b c) Stop, mem)) \\<in> eval\\<^sub>w_simple\"\n\nprimrec cxt_to_stmt :: \"('Var, 'AExp, 'BExp) EvalCxt \\<Rightarrow> ('Var, 'AExp, 'BExp) Stmt\n  \\<Rightarrow> ('Var, 'AExp, 'BExp) Stmt\"\n  where\n  \"cxt_to_stmt [] c = c\" |\n  \"cxt_to_stmt (c # cs) c' = Seq c' (cxt_to_stmt cs c)\"\n\n(* Design decision: Add \"normal\" rule for sequential statements here as well.\n  Otherwise, one would have to take care of adding some sort of normalization\n  later, so that one doesn't get stuck on expressions of the form (c ;; c') ;; c''.\n*)\n(* Normalization turned out to be more difficult, as it made the proofs of several\n  helpful lemmas below quite difficult. *)\n\ninductive_set eval\\<^sub>w :: \"(('Var, 'AExp, 'BExp) Stmt, 'Var, 'Val) LocalConf rel\"\nand eval\\<^sub>w_abv :: \"(('Var, 'AExp, 'BExp) Stmt, 'Var, 'Val) LocalConf \\<Rightarrow>\n                  (('Var, 'AExp, 'BExp) Stmt, 'Var, 'Val) LocalConf \\<Rightarrow> bool\"\n  (infixr \"\\<leadsto>\\<^sub>w\" 60)\n  where\n  \"c \\<leadsto>\\<^sub>w c' \\<equiv> (c, c') \\<in> eval\\<^sub>w\" |\n  unannotated: \"\\<lbrakk> (c, mem) \\<leadsto>\\<^sub>s (c', mem') \\<rbrakk>\n    \\<Longrightarrow> (\\<langle>cxt_to_stmt E c, mds, mem\\<rangle>\\<^sub>w, \\<langle>cxt_to_stmt E c', mds, mem'\\<rangle>\\<^sub>w) \\<in> eval\\<^sub>w\" |\n  seq: \"\\<lbrakk> \\<langle>c\\<^sub>1, mds, mem\\<rangle>\\<^sub>w \\<leadsto>\\<^sub>w \\<langle>c\\<^sub>1', mds', mem'\\<rangle>\\<^sub>w \\<rbrakk> \\<Longrightarrow> (\\<langle>(c\\<^sub>1 ;; c\\<^sub>2), mds, mem\\<rangle>\\<^sub>w, \\<langle>(c\\<^sub>1' ;; c\\<^sub>2), mds', mem'\\<rangle>\\<^sub>w) \\<in> eval\\<^sub>w\" |\n  decl: \"\\<lbrakk> \\<langle>c, update_modes mu mds, mem\\<rangle>\\<^sub>w \\<leadsto>\\<^sub>w \\<langle>c', mds', mem'\\<rangle>\\<^sub>w \\<rbrakk> \\<Longrightarrow>\n         (\\<langle>cxt_to_stmt E (ModeDecl c mu), mds, mem\\<rangle>\\<^sub>w, \\<langle>cxt_to_stmt E c', mds', mem'\\<rangle>\\<^sub>w) \\<in> eval\\<^sub>w\"\n\nsubsection \\<open>Semantic Properties\\<close>\n\ntext \\<open>The following lemmas simplify working with evaluation contexts\n  in the soundness proofs for the type system(s).\\<close>\n\ninductive_cases eval_elim: \"(((c, mds), mem), ((c', mds'), mem')) \\<in> eval\\<^sub>w\"\ninductive_cases stop_no_eval' [elim]: \"((Stop, mem), (c', mem')) \\<in> eval\\<^sub>w_simple\"\ninductive_cases assign_elim' [elim]: \"((x \\<leftarrow> e, mem), (c', mem')) \\<in> eval\\<^sub>w_simple\"\ninductive_cases skip_elim' [elim]: \"(Skip, mem) \\<leadsto>\\<^sub>s (c', mem')\"\n\nlemma cxt_inv:\n  \"\\<lbrakk> cxt_to_stmt E c = c' ; \\<And> p q. c' \\<noteq> Seq p q \\<rbrakk> \\<Longrightarrow> E = [] \\<and> c' = c\"\n  by (metis cxt_to_stmt.simps(1) cxt_to_stmt.simps(2) neq_Nil_conv)\n\nlemma cxt_inv_assign:\n  \"\\<lbrakk> cxt_to_stmt E c = x \\<leftarrow> e \\<rbrakk> \\<Longrightarrow> c = x \\<leftarrow> e \\<and> E = []\"\n  by (metis Stmt.simps(11) cxt_inv)\n\nlemma cxt_inv_skip:\n  \"\\<lbrakk> cxt_to_stmt E c = Skip \\<rbrakk> \\<Longrightarrow> c = Skip \\<and> E = []\"\n  by (metis Stmt.simps(21) cxt_inv)\n\nlemma cxt_inv_stop:\n  \"cxt_to_stmt E c = Stop \\<Longrightarrow> c = Stop \\<and> E = []\"\n  by (metis Stmt.simps(40) cxt_inv)\n\nlemma cxt_inv_if:\n  \"cxt_to_stmt E c = If e p q \\<Longrightarrow> c = If e p q \\<and> E = []\"\n  by (metis Stmt.simps(37) cxt_inv)\n\nlemma cxt_inv_while:\n  \"cxt_to_stmt E c = While e p \\<Longrightarrow> c = While e p \\<and> E = []\"\n  by (metis Stmt.simps(39) cxt_inv)\n\nlemma skip_elim [elim]:\n  \"\\<langle>Skip, mds, mem\\<rangle>\\<^sub>w \\<leadsto>\\<^sub>w \\<langle>c', mds', mem'\\<rangle>\\<^sub>w \\<Longrightarrow> c' = Stop \\<and> mds = mds' \\<and> mem = mem'\"\n  apply (erule eval_elim)\n    apply (metis (lifting) cxt_inv_skip cxt_to_stmt.simps(1) skip_elim')\n   apply (metis Stmt.simps(20))\n  by (metis Stmt.simps(18) cxt_inv_skip)\n\nlemma assign_elim [elim]:\n  \"\\<langle>x \\<leftarrow> e, mds, mem\\<rangle>\\<^sub>w \\<leadsto>\\<^sub>w \\<langle>c', mds', mem'\\<rangle>\\<^sub>w \\<Longrightarrow> c' = Stop \\<and> mds = mds' \\<and> mem' = mem (x := eval\\<^sub>A mem e)\"\n  apply (erule eval_elim)\n    apply (rename_tac c c'a E)\n    apply (subgoal_tac \"c = x \\<leftarrow> e \\<and> E = []\")\n     apply auto\n      apply (metis cxt_inv_assign)\n     apply (metis cxt_inv_assign)\n    apply (metis Stmt.simps(8) cxt_inv_assign)\n   apply (metis Stmt.simps(8) cxt_inv_assign)\n  by (metis Stmt.simps(8) cxt_inv_assign)\n\ninductive_cases if_elim' [elim!]: \"(If b p q, mem) \\<leadsto>\\<^sub>s (c', mem')\"\n\nlemma if_elim [elim]:\n  \"\\<And> P.\n    \\<lbrakk> \\<langle>If b p q, mds, mem\\<rangle>\\<^sub>w \\<leadsto>\\<^sub>w \\<langle>c', mds', mem'\\<rangle>\\<^sub>w ;\n     \\<lbrakk> c' = p; mem' = mem ; mds' = mds ; eval\\<^sub>B mem b \\<rbrakk> \\<Longrightarrow> P ;\n     \\<lbrakk> c' = q; mem' = mem ; mds' = mds ; \\<not> eval\\<^sub>B mem b \\<rbrakk> \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P\"\n  apply (erule eval_elim)\n    apply (metis (no_types) cxt_inv_if cxt_to_stmt.simps(1) if_elim')\n   apply (metis Stmt.simps(36))\n  by (metis Stmt.simps(30) cxt_inv_if)\n\ninductive_cases while_elim' [elim!]: \"(While e c, mem) \\<leadsto>\\<^sub>s (c', mem')\"\n\nlemma while_elim [elim]:\n  \"\\<lbrakk> \\<langle>While e c, mds, mem\\<rangle>\\<^sub>w \\<leadsto>\\<^sub>w \\<langle>c', mds', mem'\\<rangle>\\<^sub>w \\<rbrakk> \\<Longrightarrow> c' = If e (c ;; While e c) Stop \\<and> mds' = mds \\<and> mem' = mem\"\n  apply (erule eval_elim)\n    apply (metis (no_types) cxt_inv_while cxt_to_stmt.simps(1) while_elim')\n   apply (metis Stmt.simps(38))\n  by (metis (lifting) Stmt.simps(33) cxt_inv_while)\n\ninductive_cases upd_elim' [elim]: \"(c@[upd], mem) \\<leadsto>\\<^sub>s (c', mem')\"\n\nlemma upd_elim [elim]:\n  \"\\<langle>c@[upd], mds, mem\\<rangle>\\<^sub>w \\<leadsto>\\<^sub>w \\<langle>c', mds', mem'\\<rangle>\\<^sub>w \\<Longrightarrow> \\<langle>c, update_modes upd mds, mem\\<rangle>\\<^sub>w \\<leadsto>\\<^sub>w \\<langle>c', mds', mem'\\<rangle>\\<^sub>w\"\n  apply (erule eval_elim)\n    apply (metis (lifting) Stmt.simps(28) cxt_inv upd_elim')\n   apply (metis Stmt.simps(29))\n  by (metis (lifting) Stmt.simps(2) Stmt.simps(29) cxt_inv cxt_to_stmt.simps(1))\n\nlemma cxt_seq_elim [elim]:\n  \"c\\<^sub>1 ;; c\\<^sub>2 = cxt_to_stmt E c \\<Longrightarrow> (E = [] \\<and> c = c\\<^sub>1 ;; c\\<^sub>2) \\<or> (\\<exists> c' cs. E = c' # cs \\<and> c = c\\<^sub>1 \\<and> c\\<^sub>2 = cxt_to_stmt cs c')\"\n  apply (cases E)\n   apply (metis cxt_to_stmt.simps(1))\n  by (metis Stmt.simps(3) cxt_to_stmt.simps(2))\n\ninductive_cases seq_elim' [elim]: \"(c\\<^sub>1 ;; c\\<^sub>2, mem) \\<leadsto>\\<^sub>s (c', mem')\"\n\nlemma stop_no_eval: \"\\<not> (\\<langle>Stop, mds, mem\\<rangle>\\<^sub>w \\<leadsto>\\<^sub>w \\<langle>c', mds', mem'\\<rangle>\\<^sub>w)\"\n  apply auto\n  apply (erule eval_elim)\n    apply (metis cxt_inv_stop stop_no_eval')\n   apply (metis Stmt.simps(41))\n  by (metis Stmt.simps(35) cxt_inv_stop)\n\nlemma seq_stop_elim [elim]:\n  \"\\<langle>Stop ;; c, mds, mem\\<rangle>\\<^sub>w \\<leadsto>\\<^sub>w \\<langle>c', mds', mem'\\<rangle>\\<^sub>w \\<Longrightarrow> c' = c \\<and> mds' = mds \\<and> mem' = mem\"\n  apply (erule eval_elim)\n    apply clarify\n    apply (metis (no_types) cxt_seq_elim cxt_to_stmt.simps(1) seq_elim' stop_no_eval')\n   apply (metis Stmt.inject(3) stop_no_eval)\n  by (metis Stmt.distinct(23) Stmt.distinct(29) cxt_seq_elim)\n\nlemma cxt_stmt_seq:\n  \"c ;; cxt_to_stmt E c' = cxt_to_stmt (c' # E) c\"\n  by (metis cxt_to_stmt.simps(2))\n\n\nlemma seq_elim [elim]:\n  \"\\<lbrakk> \\<langle>c\\<^sub>1 ;; c\\<^sub>2, mds, mem\\<rangle>\\<^sub>w \\<leadsto>\\<^sub>w \\<langle>c', mds', mem'\\<rangle>\\<^sub>w ; c\\<^sub>1 \\<noteq> Stop \\<rbrakk> \\<Longrightarrow>\n  (\\<exists> c\\<^sub>1'. \\<langle>c\\<^sub>1, mds, mem\\<rangle>\\<^sub>w \\<leadsto>\\<^sub>w \\<langle>c\\<^sub>1', mds', mem'\\<rangle>\\<^sub>w \\<and> c' = c\\<^sub>1' ;; c\\<^sub>2)\"\n  apply (erule eval_elim)\n    apply clarify\n    apply (drule cxt_seq_elim)\n    apply (erule disjE)\n     apply (metis seq_elim')\n    apply auto\n   apply (metis cxt_to_stmt.simps(1) eval\\<^sub>w.unannotated)\n  apply (subgoal_tac \"c\\<^sub>1 = (c@[mu])\")\n   apply simp\n   apply (drule cxt_seq_elim)\n   apply (metis Stmt.distinct(23) cxt_stmt_seq cxt_to_stmt.simps(1) eval\\<^sub>w.decl)\n  by (metis Stmt.distinct(23) cxt_seq_elim)\n\nlemma stop_cxt: \"Stop = cxt_to_stmt E c \\<Longrightarrow> c = Stop\"\n  by (metis Stmt.simps(41) cxt_to_stmt.simps(1) cxt_to_stmt.simps(2) neq_Nil_conv)\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/SIFUM_Type_Systems/Language.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5350984137988772, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.28633032038437156}}
{"text": "section {* UTP variables *}\n\ntheory utp_urel_laws\n  imports \"../../Isabelle-UTP-Extended/theories/Rel/utp_rel_more\"\nbegin\n\nsubsection {* Unrestriction Laws *}\nlemma unrest_iuvar [unrest]: \n  \"out\\<alpha> \\<sharp> $x\" \n  by ( rel_auto)\n \nlemma unrest_ouvar [unrest]: \n  \"in\\<alpha> \\<sharp> $x\\<acute>\" \n  by (rel_auto)\n\nlemma unrest_semir_undash [unrest]:\n  fixes x :: \"('a\\<Longrightarrow> '\\<alpha>)\"\n  assumes \"$x \\<sharp> P\"\n  shows \"$x \\<sharp> P ;; Q\"\n  using assms by (rel_auto) \n\nlemma unrest_semir_dash [unrest]:\n  fixes x :: \"('a \\<Longrightarrow> '\\<alpha>)\"\n  assumes \"$x\\<acute> \\<sharp> Q\"\n  shows \"$x\\<acute> \\<sharp> P ;; Q\"\n  using assms by (rel_auto)\n\n\nlemma unrest_in\\<alpha>_var [unrest]:\n  \"\\<lbrakk> mwb_lens x; in\\<alpha> \\<sharp> (P :: ('\\<alpha>, '\\<beta>) rel) \\<rbrakk> \\<Longrightarrow> $x \\<sharp> P\"\n  by (pred_auto)\n\nlemma unrest_out\\<alpha>_var [unrest]:\n  \"\\<lbrakk> mwb_lens x; out\\<alpha> \\<sharp> (P :: ('\\<alpha>, '\\<beta>) rel) \\<rbrakk> \\<Longrightarrow> $x\\<acute> \\<sharp> P\"\n  by (pred_auto)\n\nlemma in\\<alpha>_uvar [simp]: \"vwb_lens in\\<alpha>\"\n  by (unfold_locales, auto simp add: in\\<alpha>_def)\n\nlemma out\\<alpha>_uvar [simp]: \"vwb_lens out\\<alpha>\"\n  by (unfold_locales, auto simp add: out\\<alpha>_def)\n\nlemma unrest_pre_out\\<alpha> [unrest]: \"out\\<alpha> \\<sharp> \\<lceil>b\\<rceil>\\<^sub><\"\n  by (transfer, auto simp add: out\\<alpha>_def)\n\nlemma unrest_post_in\\<alpha> [unrest]: \"in\\<alpha> \\<sharp> \\<lceil>b\\<rceil>\\<^sub>>\"\n  by (transfer, auto simp add: in\\<alpha>_def)\n\nlemma unrest_pre_in_var [unrest]:\n  \"x \\<sharp> p1 \\<Longrightarrow> $x \\<sharp> \\<lceil>p1\\<rceil>\\<^sub><\"\n  by (transfer, simp)\n\nlemma unrest_post_out_var [unrest]:\n  \"x \\<sharp> p1 \\<Longrightarrow> $x\\<acute> \\<sharp> \\<lceil>p1\\<rceil>\\<^sub>>\"\n  by (transfer, simp)\n\nlemma unrest_convr_out\\<alpha> [unrest]:\n  \"in\\<alpha> \\<sharp> p \\<Longrightarrow> out\\<alpha> \\<sharp> p\\<^sup>-\"\n  by (pred_auto)\n\nlemma unrest_convr_in\\<alpha> [unrest]:\n  \"out\\<alpha> \\<sharp> p \\<Longrightarrow> in\\<alpha> \\<sharp> p\\<^sup>-\"\n  by (pred_auto)\n\nlemma unrest_in_rel_var_res [unrest]:\n  \"vwb_lens x \\<Longrightarrow> $x \\<sharp> (P \\<restriction>\\<^sub>\\<alpha> x)\"\n  by (simp add: rel_var_res_def unrest)\n \nlemma unrest_out_rel_var_res [unrest]:\n  \"vwb_lens x \\<Longrightarrow> $x\\<acute> \\<sharp> (P \\<restriction>\\<^sub>\\<alpha> x)\"\n  by (simp add: rel_var_res_def unrest)\n\nlemma unrest_in_rel_var_res_mwb [unrest]:\n  \"mwb_lens x \\<Longrightarrow> $x \\<sharp> (P \\<restriction>\\<^sub>\\<alpha> x)\"\n  by (simp add: rel_var_res_def unrest)\n \nlemma unrest_out_rel_var_res_mwb [unrest]:\n  \"mwb_lens x \\<Longrightarrow> $x\\<acute> \\<sharp> (P \\<restriction>\\<^sub>\\<alpha> x)\"\n  by (simp add: rel_var_res_def unrest)\n\nsubsection {* Substitution laws *}\n\nlemma subst_seq_left [usubst]:\n  \"out\\<alpha> \\<sharp> \\<sigma> \\<Longrightarrow> \\<sigma> \\<dagger> (P ;; Q) = (\\<sigma> \\<dagger> P) ;; Q\"\n  by transfer (rel_auto, (metis (no_types, lifting) Pair_inject surjective_pairing)+)\n\nlemma subst_seq_right [usubst]:\n  \"in\\<alpha> \\<sharp> \\<sigma> \\<Longrightarrow> \\<sigma> \\<dagger> (P ;; Q) = P ;; (\\<sigma> \\<dagger> Q)\"\n  by transfer (rel_auto, (metis (no_types, lifting) Pair_inject surjective_pairing)+)\n\ntext {* The following laws support substitution in heterogeneous relations for polymorphically\n  types literal expressions. These cannot be supported more generically due to limitations\n  in HOL's type system. The laws are presented in a slightly strange way so as to be as \n  general as possible. *}\n\nlemma bool_seqr_laws [usubst]:\n    \"\\<And> P Q \\<sigma>. \\<sigma>($x \\<mapsto>\\<^sub>s true) \\<dagger> (P ;; Q) = \\<sigma> \\<dagger> (P\\<lbrakk>true/$x\\<rbrakk> ;; Q)\"\n    \"\\<And> P Q \\<sigma>. \\<sigma>($x \\<mapsto>\\<^sub>s false) \\<dagger> (P ;; Q) = \\<sigma> \\<dagger> (P\\<lbrakk>false/$x\\<rbrakk> ;; Q)\"\n    \"\\<And> P Q \\<sigma>. \\<sigma>($x\\<acute> \\<mapsto>\\<^sub>s true) \\<dagger> (P ;; Q) = \\<sigma> \\<dagger> (P ;; Q\\<lbrakk>true/$x\\<acute>\\<rbrakk>)\"\n    \"\\<And> P Q \\<sigma>. \\<sigma>($x\\<acute> \\<mapsto>\\<^sub>s false) \\<dagger> (P ;; Q) = \\<sigma> \\<dagger> (P ;; Q\\<lbrakk>false/$x\\<acute>\\<rbrakk>)\"\n    by (transfer, rel_auto)+\n\nlemma zero_one_seqr_laws [usubst]:\n  fixes x :: \"(_ \\<Longrightarrow> '\\<alpha>)\"\n  shows \n    \"\\<And> P Q \\<sigma>. \\<sigma>($x \\<mapsto>\\<^sub>s 0) \\<dagger> (P ;; Q) = \\<sigma> \\<dagger> (P\\<lbrakk>0/$x\\<rbrakk> ;; Q)\"\n    \"\\<And> P Q \\<sigma>. \\<sigma>($x \\<mapsto>\\<^sub>s 1) \\<dagger> (P ;; Q) = \\<sigma> \\<dagger> (P\\<lbrakk>1/$x\\<rbrakk> ;; Q)\"\n    \"\\<And> P Q \\<sigma>. \\<sigma>($x\\<acute> \\<mapsto>\\<^sub>s 0) \\<dagger> (P ;; Q) = \\<sigma> \\<dagger> (P ;; Q\\<lbrakk>0/$x\\<acute>\\<rbrakk>)\"\n    \"\\<And> P Q \\<sigma>. \\<sigma>($x\\<acute> \\<mapsto>\\<^sub>s 1) \\<dagger> (P ;; Q) = \\<sigma> \\<dagger> (P ;; Q\\<lbrakk>1/$x\\<acute>\\<rbrakk>)\"\n    by (transfer, rel_auto)+\n\nlemma numeral_seqr_laws [usubst]:\n  fixes x :: \"(_ \\<Longrightarrow> '\\<alpha>)\"\n  shows \n    \"\\<And> P Q \\<sigma>. \\<sigma>($x \\<mapsto>\\<^sub>s numeral n) \\<dagger> (P ;; Q) = \\<sigma> \\<dagger> (P\\<lbrakk>numeral n/$x\\<rbrakk> ;; Q)\"\n    \"\\<And> P Q \\<sigma>. \\<sigma>($x\\<acute> \\<mapsto>\\<^sub>s numeral n) \\<dagger> (P ;; Q) = \\<sigma> \\<dagger> (P ;; Q\\<lbrakk>numeral n/$x\\<acute>\\<rbrakk>)\"\n  by (transfer, rel_auto)+    \n\nlemma usubst_condr [usubst]:\n  \"\\<sigma> \\<dagger> ( P \\<triangleleft> b \\<triangleright> Q) = (\\<sigma> \\<dagger> P \\<triangleleft> \\<sigma> \\<dagger> b \\<triangleright> \\<sigma> \\<dagger> Q)\"\n  unfolding cond_def\n  by rel_auto\n \nlemma subst_skip_r [usubst]:\n  \"out\\<alpha> \\<sharp> \\<sigma> \\<Longrightarrow> \\<sigma> \\<dagger> II = \\<langle>\\<lfloor>\\<sigma>\\<rfloor>\\<^sub>s\\<rangle>\\<^sub>a\"\n  by (rel_simp, (metis (mono_tags, lifting) prod.sel(1) sndI surjective_pairing)+)\n\nlemma usubst_upd_in_comp [usubst]:\n  \"\\<sigma>(&in\\<alpha>:x \\<mapsto>\\<^sub>s v) = \\<sigma>($x \\<mapsto>\\<^sub>s v)\"\n  by (pred_auto)\n\nlemma usubst_upd_out_comp [usubst]:\n  \"\\<sigma>(&out\\<alpha>:x \\<mapsto>\\<^sub>s v) = \\<sigma>($x\\<acute> \\<mapsto>\\<^sub>s v)\"\n  by (pred_auto)\n\nlemma subst_lift_upd [usubst]:\n  fixes x :: \"('a \\<Longrightarrow> '\\<alpha>)\"\n  shows \"\\<lceil>\\<sigma>(x \\<mapsto>\\<^sub>s v)\\<rceil>\\<^sub>s = \\<lceil>\\<sigma>\\<rceil>\\<^sub>s($x \\<mapsto>\\<^sub>s \\<lceil>v\\<rceil>\\<^sub><)\"\n  by pred_auto\n\nlemma subst_drop_upd [usubst]:\n  fixes x :: \"('a \\<Longrightarrow> '\\<alpha>)\"\n  shows \"\\<lfloor>\\<sigma>($x \\<mapsto>\\<^sub>s v)\\<rfloor>\\<^sub>s = \\<lfloor>\\<sigma>\\<rfloor>\\<^sub>s(x \\<mapsto>\\<^sub>s \\<lfloor>v\\<rfloor>\\<^sub><)\"\n  by  (pred_simp)\n\nlemma subst_lift_pre [usubst]: \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>s \\<dagger> \\<lceil>b\\<rceil>\\<^sub>< = \\<lceil>\\<sigma> \\<dagger> b\\<rceil>\\<^sub><\"\n  by (metis apply_subst_ext fst_vwb_lens in\\<alpha>_def)\n\nlemma unrest_usubst_lift_in [unrest]:\n  \"x \\<sharp> P \\<Longrightarrow> $x \\<sharp> \\<lceil>P\\<rceil>\\<^sub>s\"\n  by (pred_simp)\n\nlemma unrest_usubst_lift_out [unrest]:\n  fixes x :: \"('a \\<Longrightarrow> '\\<alpha>)\"\n  shows \"$x\\<acute> \\<sharp> \\<lceil>P\\<rceil>\\<^sub>s\"\n  by (pred_simp)\n\nsubsection {* Relation laws *}\n\nlemma drop_pre_inv [simp]: \"\\<lbrakk> out\\<alpha> \\<sharp> p \\<rbrakk> \\<Longrightarrow> \\<lceil>\\<lfloor>p\\<rfloor>\\<^sub><\\<rceil>\\<^sub>< = p\"\n  by (pred_simp)\n\nlemma seqr_true_lemma:\n  \"(P = (\\<not> ((\\<not> P) ;; true))) = (P = (P ;; true))\"\n  by (rel_auto)\n theorem precond_equiv:\n  \"P = (P ;; true) \\<longleftrightarrow> (out\\<alpha> \\<sharp> P)\"\n  by (rel_auto)\n\ntheorem postcond_equiv:\n  \"P = (true ;; P) \\<longleftrightarrow> (in\\<alpha> \\<sharp> P)\"\n  by (rel_auto)   \nlemma precond_right_unit: \"out\\<alpha> \\<sharp> p \\<Longrightarrow> (p ;; true) = p\"\n  by (metis precond_equiv)\n    \ntheorem seqr_post_transfer: \"out\\<alpha> \\<sharp> q \\<Longrightarrow> (P ;; (q \\<and> R)) = ((P \\<and> q\\<^sup>-) ;; R)\"\n  by (rel_auto)\n\nlemma seqr_pre_out: \"out\\<alpha> \\<sharp> p \\<Longrightarrow> ((p \\<and> Q) ;; R) = (p \\<and> (Q ;; R))\"\n  by (rel_blast)\n\nlemma postcond_left_unit: \"in\\<alpha> \\<sharp> p \\<Longrightarrow> (true ;; p) = p\"\n  by (metis postcond_equiv)\n    \nlemma seqr_to_conj: \"\\<lbrakk> out\\<alpha> \\<sharp> P; in\\<alpha> \\<sharp> Q \\<rbrakk> \\<Longrightarrow> (P ;; Q) = (P \\<and> Q)\"\n  by (metis postcond_left_unit seqr_pre_out utp_pred_laws.inf_top.right_neutral)\n\nlemma shEx_lift_seq_1 [uquant_lift]:\n  \"((\\<^bold>\\<exists> x \\<bullet> P x) ;; Q) = (\\<^bold>\\<exists> x \\<bullet> (P x ;; Q))\"\n  by pred_auto\n\nlemma shEx_lift_seq_2 [uquant_lift]:\n  \"(P ;; (\\<^bold>\\<exists> x \\<bullet> Q x)) = (\\<^bold>\\<exists> x \\<bullet> (P ;; Q x))\"\n  by pred_auto    \n \nsubsection {* Iterated Sequential Composition Laws *}\n  \nlemma iter_seqr_nil [simp]: \"(;; i : [] \\<bullet> P(i)) = II\"\n  by (simp add: seqr_iter_def)\n    \nlemma iter_seqr_cons [simp]: \"(;; i : (x # xs) \\<bullet> P(i)) = P(x) ;; (;; i : xs \\<bullet> P(i))\"\n  by (simp add: seqr_iter_def)\n    \ntext {* Quantale laws for relations *}\n\nlemma seq_Sup_distl: \"P ;; (\\<Sqinter> A) = (\\<Sqinter> Q\\<in>A. P ;; Q)\"\n  by (transfer, rel_auto)\n    \nlemma seq_Sup_distr: \"(\\<Sqinter> A) ;; Q = (\\<Sqinter> P\\<in>A. P ;; Q)\"\n  by (transfer, auto)\n    \nlemma seq_UINF_distl: \"P ;; (\\<Sqinter> Q\\<in>A \\<bullet> F(Q)) = (\\<Sqinter> Q\\<in>A \\<bullet> P ;; F(Q))\"\n  by (simp add: UINF_as_Sup_collect seq_Sup_distl)\n\nlemma seq_UINF_distl': \"P ;; (\\<Sqinter> Q \\<bullet> F(Q)) = (\\<Sqinter> Q \\<bullet> P ;; F(Q))\"\n  by (metis UINF_mem_UNIV seq_UINF_distl)\n    \nlemma seq_UINF_distr: \"(\\<Sqinter> P\\<in>A \\<bullet> F(P)) ;; Q = (\\<Sqinter> P\\<in>A \\<bullet> F(P) ;; Q)\"\n  by (simp add: UINF_as_Sup_collect seq_Sup_distr)\n\nlemma seq_UINF_distr': \"(\\<Sqinter> P \\<bullet> F(P)) ;; Q = (\\<Sqinter> P \\<bullet> F(P) ;; Q)\"\n  by (metis UINF_mem_UNIV seq_UINF_distr)\n\nlemma seq_SUP_distl: \"P ;; (\\<Sqinter>i\\<in>A. Q(i)) = (\\<Sqinter>i\\<in>A. P ;; Q(i))\"\n  by (metis image_image seq_Sup_distl)\n\nlemma seq_SUP_distr: \"(\\<Sqinter>i\\<in>A. P(i)) ;; Q = (\\<Sqinter>i\\<in>A. P(i) ;; Q)\"\n  by (simp add: seq_Sup_distr)\n    \nlemma impl_seqr_mono: \"\\<lbrakk> `P \\<Rightarrow> Q`; `R \\<Rightarrow> S` \\<rbrakk> \\<Longrightarrow> `(P ;; R) \\<Rightarrow> (Q ;; S)`\"\n  by transfer (pred_blast)\n\nlemma seqr_mono:\n  \"\\<lbrakk> P\\<^sub>1 \\<sqsubseteq> P\\<^sub>2; Q\\<^sub>1 \\<sqsubseteq> Q\\<^sub>2 \\<rbrakk> \\<Longrightarrow> (P\\<^sub>1 ;; Q\\<^sub>1) \\<sqsubseteq> (P\\<^sub>2 ;; Q\\<^sub>2)\"\n  by transfer (rel_blast)\n\nlemma seqr_monotonic: \n  \"\\<lbrakk> mono P; mono Q \\<rbrakk> \\<Longrightarrow> mono (\\<lambda> X. P X ;; Q X)\"\n  by (simp add: mono_def, transfer ,rel_blast)\n\nlemma cond_mono:\n  \"\\<lbrakk> P\\<^sub>1 \\<sqsubseteq> P\\<^sub>2; Q\\<^sub>1 \\<sqsubseteq> Q\\<^sub>2 \\<rbrakk> \\<Longrightarrow> (P\\<^sub>1 \\<triangleleft> b \\<triangleright> Q\\<^sub>1) \\<sqsubseteq> (P\\<^sub>2 \\<triangleleft> b \\<triangleright> Q\\<^sub>2)\"\n  unfolding cond_def\n  by transfer (rel_auto)\n\nlemma cond_monotonic:\n  \"\\<lbrakk> mono P; mono Q \\<rbrakk> \\<Longrightarrow> mono (\\<lambda> X. P X \\<triangleleft> b \\<triangleright> Q X)\"\n  unfolding cond_def\n  by (simp add: mono_def, rel_blast)\n\nlemma spec_refine:\n  \"Q \\<sqsubseteq> (P \\<and> R) \\<Longrightarrow> (P \\<Rightarrow> Q) \\<sqsubseteq> R\"\n  by (rel_auto)\n\nlemma cond_skip: \"out\\<alpha> \\<sharp> b \\<Longrightarrow> (b \\<and> II) = (II \\<and> b\\<^sup>-)\"\n  by (rel_auto)\n\n\nlemma assigns_subst [usubst]:\n  \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>s \\<dagger> \\<langle>\\<rho>\\<rangle>\\<^sub>a = \\<langle>\\<rho> \\<circ> \\<sigma>\\<rangle>\\<^sub>a\"\n  by transfer (rel_auto)\n\nlemma assigns_r_comp: \"(\\<langle>\\<sigma>\\<rangle>\\<^sub>a ;; P) = (\\<lceil>\\<sigma>\\<rceil>\\<^sub>s \\<dagger> P)\"\n  by transfer rel_auto\n\nlemma assigns_r_feasible:\n  \"(\\<langle>\\<sigma>\\<rangle>\\<^sub>a ;; true) = true\"\n  by (simp add: assigns_r_comp subst_true)\n\nlemma assign_subst [usubst]:\n  \"\\<lbrakk> mwb_lens x; mwb_lens y \\<rbrakk> \\<Longrightarrow> [$x \\<mapsto>\\<^sub>s \\<lceil>u\\<rceil>\\<^sub><] \\<dagger> (y :== v) = (x, y :== u, [x \\<mapsto>\\<^sub>s u] \\<dagger> v)\"\n  by rel_auto\n\nlemma assigns_idem: \"mwb_lens x \\<Longrightarrow> (x,x :== u,v) = (x :== v)\"\n  by (simp add: usubst)\n\nlemma assigns_comp: \"(\\<langle>f\\<rangle>\\<^sub>a ;; \\<langle>g\\<rangle>\\<^sub>a) = \\<langle>g \\<circ> f\\<rangle>\\<^sub>a\"\n  by (simp add: assigns_r_comp usubst)\n\nlemma assigns_r_conv:\n  \"bij f \\<Longrightarrow> \\<langle>f\\<rangle>\\<^sub>a\\<^sup>- = \\<langle>inv f\\<rangle>\\<^sub>a\"\n  by transfer (rel_auto, simp_all add: bij_is_inj bij_is_surj surj_f_inv_f)\n\nlemma assign_pred_transfer:\n  fixes x :: \"('a\\<Longrightarrow> '\\<alpha>)\"\n  assumes \"$x \\<sharp> b\" \"out\\<alpha> \\<sharp> b\"\n  shows \"(b \\<and> x :== v) = (x :== v \\<and> b\\<^sup>-)\"\n  using assms by rel_blast\n\nlemma assigns_r_ufunc: \"ufunctional \\<langle>f\\<rangle>\\<^sub>a\"\n  by (rel_auto)\n\nlemma assigns_r_uinj: \"inj f \\<Longrightarrow> uinj \\<langle>f\\<rangle>\\<^sub>a\"\n  by (rel_simp, simp add: inj_eq)\n\nlemma assigns_r_swap_uinj:\n  \"\\<lbrakk> vwb_lens x; vwb_lens y; x \\<bowtie> y \\<rbrakk> \\<Longrightarrow> uinj (x,y :== &y,&x)\"\n  using assigns_r_uinj swap_usubst_inj by rel_auto\n\nlemma skip_r_unfold:\n  \"vwb_lens x \\<Longrightarrow> II = ($x\\<acute> =\\<^sub>u $x \\<and> II\\<restriction>\\<^sub>\\<alpha>x)\"\n  by (rel_auto, metis mwb_lens.put_put vwb_lens_mwb vwb_lens_wb wb_lens.get_put)\n\nlemma skip_ra_unfold:\n  \"II\\<^bsub>x;y\\<^esub> = ($x\\<acute> =\\<^sub>u $x \\<and> II\\<^bsub>y\\<^esub>)\"\n  by (rel_auto)\n\nlemma skip_res_as_ra:\n  \"\\<lbrakk> vwb_lens y; x +\\<^sub>L y \\<approx>\\<^sub>L 1\\<^sub>L; x \\<bowtie> y \\<rbrakk> \\<Longrightarrow> II\\<restriction>\\<^sub>\\<alpha>x = II\\<^bsub>y\\<^esub>\"\n  apply (rel_auto)\n  apply (metis (no_types, lifting) lens_indep_def)\n  apply (metis vwb_lens.put_eq)\ndone\n\nlemma assign_unfold:\n  \"vwb_lens x \\<Longrightarrow> (x :== v) = ($x\\<acute> =\\<^sub>u \\<lceil>v\\<rceil>\\<^sub>< \\<and> II\\<restriction>\\<^sub>\\<alpha>x)\"\n  apply (rel_auto, auto simp add: comp_def)\n  using vwb_lens.put_eq by fastforce\n\nlemma seqr_and_distr_ufunc:\n  \"ufunctional P \\<Longrightarrow> (P ;; (Q \\<and> R)) = ((P ;; Q) \\<and> (P ;; R))\"\n  by rel_auto\n\nlemma seqr_and_distl_uinj:\n  \"uinj R \\<Longrightarrow> ((P \\<and> Q) ;; R) = ((P ;; R) \\<and> (Q ;; R))\"\n  by (rel_auto)\n\ntheorem precond_left_zero:\n  assumes \"out\\<alpha> \\<sharp> p\" \"p \\<noteq> false\"\n  shows \"(true ;; p) = true\"\n  using assms by pred_auto\n\nsubsection {* Converse laws *}\n\nlemma convr_invol [simp]: \"p\\<^sup>-\\<^sup>- = p\"\n  by pred_auto\n\nlemma lit_convr [simp]: \"\\<guillemotleft>v\\<guillemotright>\\<^sup>- = \\<guillemotleft>v\\<guillemotright>\"\n  by pred_auto\n\nlemma uivar_convr [simp]:\n  fixes x :: \"('a \\<Longrightarrow> '\\<alpha>)\"\n  shows \"($x)\\<^sup>- = $x\\<acute>\"\n  by pred_auto\n\nlemma uovar_convr [simp]:\n  fixes x :: \"('a \\<Longrightarrow> '\\<alpha>)\"\n  shows \"($x\\<acute>)\\<^sup>- = $x\"\n  by pred_auto\n\nlemma uop_convr [simp]: \"(uop f u)\\<^sup>- = uop f (u\\<^sup>-)\"\n  by (pred_auto)\n\nlemma bop_convr [simp]: \"(bop f u v)\\<^sup>- = bop f (u\\<^sup>-) (v\\<^sup>-)\"\n  by (pred_auto)\n\nlemma eq_convr [simp]: \"(p =\\<^sub>u q)\\<^sup>- = (p\\<^sup>- =\\<^sub>u q\\<^sup>-)\"\n  by (pred_auto)\n\nlemma not_convr [simp]: \"(\\<not> p)\\<^sup>- = (\\<not> p\\<^sup>-)\"\n  by (pred_auto)\n\nlemma disj_convr [simp]: \"(p \\<or> q)\\<^sup>- = (q\\<^sup>- \\<or> p\\<^sup>-)\"\n  by (pred_auto)\n\nlemma conj_convr [simp]: \"(p \\<and> q)\\<^sup>- = (q\\<^sup>- \\<and> p\\<^sup>-)\"\n  by (pred_auto)\n\nlemma seqr_convr [simp]: \"(p ;; q)\\<^sup>- = (q\\<^sup>- ;; p\\<^sup>-)\"\n  by rel_auto\n\nlemma pre_convr [simp]: \"\\<lceil>p\\<rceil>\\<^sub><\\<^sup>- = \\<lceil>p\\<rceil>\\<^sub>>\"\n  by (rel_auto)\n\nlemma post_convr [simp]: \"\\<lceil>p\\<rceil>\\<^sub>>\\<^sup>- = \\<lceil>p\\<rceil>\\<^sub><\"\n  by (rel_auto)\n\ntheorem seqr_pre_transfer: \"in\\<alpha> \\<sharp> q \\<Longrightarrow> ((P \\<and> q) ;; R) = (P ;; (q\\<^sup>- \\<and> R))\"\n  by (rel_auto)\n\ntheorem seqr_pre_transfer':\n  \"((P \\<and> \\<lceil>q\\<rceil>\\<^sub>>) ;; R) = (P ;; (\\<lceil>q\\<rceil>\\<^sub>< \\<and> R))\"\n  by (rel_auto)\n\ntheorem seqr_post_out: \"in\\<alpha> \\<sharp> r \\<Longrightarrow> (P ;; (Q \\<and> r)) = ((P ;; Q) \\<and> r)\"\n  by (rel_blast)\n\nlemma seqr_post_var_out:\n  fixes x :: \"(bool \\<Longrightarrow> '\\<alpha>)\"\n  shows \"(P ;; (Q \\<and> $x\\<acute>)) = ((P ;; Q) \\<and> $x\\<acute>)\"\n  by (rel_auto)\n\nlemma seqr_pre_var_out:\n  fixes x :: \"(bool \\<Longrightarrow> '\\<alpha>)\"\n  shows \"(($x \\<and> P) ;; Q) = ($x \\<and> (P ;; Q))\"\n  by (rel_auto)\n\n\nsubsection {* Relational unrestriction *}\n\ntext {* Relational unrestriction states that a variable is unchanged by a relation. Eventually\n  I'd also like to have it state that the relation also does not depend on the variable's\n  initial value, but I'm not sure how to state that yet. For now we represent this by\n  the parametric healthiness condition RID. *}\n\ndefinition RID :: \"('a \\<Longrightarrow> '\\<alpha>) \\<Rightarrow> '\\<alpha> hrel \\<Rightarrow> '\\<alpha> hrel\"\nwhere \"RID x P = ((\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> P) \\<and> $x\\<acute> =\\<^sub>u $x)\"\n\ndeclare RID_def [urel_defs]\n\nlemma RID_idem:\n  \"mwb_lens x \\<Longrightarrow> RID(x)(RID(x)(P)) = RID(x)(P)\"\n  by (rel_auto)\n\nlemma RID_mono:\n  \"P \\<sqsubseteq> Q \\<Longrightarrow> RID(x)(P) \\<sqsubseteq> RID(x)(Q)\"\n  by (rel_auto)\n\nlemma RID_skip_r:\n  \"vwb_lens x \\<Longrightarrow> RID(x)(II) = II\"\n  apply (rel_auto) using vwb_lens.put_eq by fastforce\n\nlemma RID_disj:\n  \"RID(x)(P \\<or> Q) = (RID(x)(P) \\<or> RID(x)(Q))\"\n  by (rel_auto)\n\nlemma RID_conj:\n  \"vwb_lens x \\<Longrightarrow> RID(x)(RID(x)(P) \\<and> RID(x)(Q)) = (RID(x)(P) \\<and> RID(x)(Q))\"\n  by (rel_auto)\n\nlemma RID_assigns_r_diff:\n  \"\\<lbrakk> vwb_lens x; x \\<sharp> \\<sigma> \\<rbrakk> \\<Longrightarrow> RID(x)(\\<langle>\\<sigma>\\<rangle>\\<^sub>a) = \\<langle>\\<sigma>\\<rangle>\\<^sub>a\"\n  apply (rel_auto)\n  apply (metis vwb_lens.put_eq)\n  apply (metis vwb_lens_wb wb_lens.get_put wb_lens_weak weak_lens.put_get)\ndone\n\nlemma RID_assign_r_same:\n  \"vwb_lens x \\<Longrightarrow> RID(x)(x :== v) = II\"\n  apply (rel_auto)\n  using vwb_lens.put_eq apply fastforce\ndone\n\nlemma RID_seq_left:\n  assumes \"vwb_lens x\"\n  shows \"RID(x)(RID(x)(P) ;; Q) = (RID(x)(P) ;; RID(x)(Q))\"\nproof -\n  have \"RID(x)(RID(x)(P) ;; Q) = ((\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> ((\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> P) \\<and> $x\\<acute> =\\<^sub>u $x) ;; Q) \\<and> $x\\<acute> =\\<^sub>u $x)\"\n    by (simp add: RID_def usubst)\n  also from assms have \"... = ((((\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> P) \\<and> (\\<exists> $x \\<bullet> $x\\<acute> =\\<^sub>u $x)) ;; (\\<exists> $x\\<acute> \\<bullet> Q)) \\<and> $x\\<acute> =\\<^sub>u $x)\"\n    by (rel_auto)\n  also from assms have \"... = (((\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> P) ;; (\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> Q)) \\<and> $x\\<acute> =\\<^sub>u $x)\"\n    apply (rel_auto)\n    apply (metis vwb_lens.put_eq)\n    apply (metis mwb_lens.put_put vwb_lens_mwb)\n  done\n  also from assms have \"... = ((((\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> P) \\<and> $x\\<acute> =\\<^sub>u $x) ;; (\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> Q)) \\<and> $x\\<acute> =\\<^sub>u $x)\"\n    by (rel_simp, metis (full_types) mwb_lens.put_put vwb_lens_def wb_lens_weak weak_lens.put_get)\n  also have \"... = ((((\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> P) \\<and> $x\\<acute> =\\<^sub>u $x) ;; ((\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> Q) \\<and> $x\\<acute> =\\<^sub>u $x)) \\<and> $x\\<acute> =\\<^sub>u $x)\"\n    by (rel_simp, fastforce)\n  also have \"... = ((((\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> P) \\<and> $x\\<acute> =\\<^sub>u $x) ;; ((\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> Q) \\<and> $x\\<acute> =\\<^sub>u $x)))\"\n    by (rel_auto)\n  also have \"... = (RID(x)(P) ;; RID(x)(Q))\"\n    by (rel_auto)\n  finally show ?thesis .\nqed\n\nlemma RID_seq_right:\n  assumes \"vwb_lens x\"\n  shows \"RID(x)(P ;; RID(x)(Q)) = (RID(x)(P) ;; RID(x)(Q))\"\nproof -\n  have \"RID(x)(P ;; RID(x)(Q)) = ((\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> P ;; ((\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> Q) \\<and> $x\\<acute> =\\<^sub>u $x)) \\<and> $x\\<acute> =\\<^sub>u $x)\"\n    by (simp add: RID_def usubst)\n  also from assms have \"... = (((\\<exists> $x \\<bullet>  P) ;; (\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> Q) \\<and> (\\<exists> $x\\<acute> \\<bullet> $x\\<acute> =\\<^sub>u $x)) \\<and> $x\\<acute> =\\<^sub>u $x)\"\n    by (rel_auto)\n  also from assms have \"... = (((\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> P) ;; (\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> Q)) \\<and> $x\\<acute> =\\<^sub>u $x)\"\n    apply (rel_auto)\n    apply (metis vwb_lens.put_eq)\n    apply (metis mwb_lens.put_put vwb_lens_mwb)\n  done\n  also from assms have \"... = ((((\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> P) \\<and> $x\\<acute> =\\<^sub>u $x) ;; (\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> Q)) \\<and> $x\\<acute> =\\<^sub>u $x)\"\n    by (rel_simp, metis (full_types) mwb_lens.put_put vwb_lens_def wb_lens_weak weak_lens.put_get)\n  also have \"... = ((((\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> P) \\<and> $x\\<acute> =\\<^sub>u $x) ;; ((\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> Q) \\<and> $x\\<acute> =\\<^sub>u $x)) \\<and> $x\\<acute> =\\<^sub>u $x)\"\n    by (rel_simp, fastforce)\n  also have \"... = ((((\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> P) \\<and> $x\\<acute> =\\<^sub>u $x) ;; ((\\<exists> $x \\<bullet> \\<exists> $x\\<acute> \\<bullet> Q) \\<and> $x\\<acute> =\\<^sub>u $x)))\"\n    by (rel_auto)\n  also have \"... = (RID(x)(P) ;; RID(x)(Q))\"\n    by (rel_auto)\n  finally show ?thesis .\nqed\n\ndefinition unrest_relation :: \"('a \\<Longrightarrow> '\\<alpha>) \\<Rightarrow> '\\<alpha> hrel \\<Rightarrow> bool\" (infix \"\\<sharp>\\<sharp>\" 20)\nwhere \"(x \\<sharp>\\<sharp> P) \\<longleftrightarrow> (P = RID(x)(P))\"\n\ndeclare unrest_relation_def [urel_defs]\n\nlemma skip_r_runrest [unrest]:\n  \"vwb_lens x \\<Longrightarrow> x \\<sharp>\\<sharp> II\"\n  by (simp add: RID_skip_r unrest_relation_def)\n\nlemma assigns_r_runrest:\n  \"\\<lbrakk> vwb_lens x; x \\<sharp> \\<sigma> \\<rbrakk> \\<Longrightarrow> x \\<sharp>\\<sharp> \\<langle>\\<sigma>\\<rangle>\\<^sub>a\"\n  by (simp add: RID_assigns_r_diff unrest_relation_def)\n\nlemma seq_r_runrest [unrest]:\n  assumes \"vwb_lens x\" \"x \\<sharp>\\<sharp> P\" \"x \\<sharp>\\<sharp> Q\"\n  shows \"x \\<sharp>\\<sharp> (P ;; Q)\"\n  by (metis RID_seq_left assms unrest_relation_def)\n\nlemma false_runrest [unrest]: \"x \\<sharp>\\<sharp> false\"\n  by (rel_auto)\n\nlemma and_runrest [unrest]: \"\\<lbrakk> vwb_lens x; x \\<sharp>\\<sharp> P; x \\<sharp>\\<sharp> Q \\<rbrakk> \\<Longrightarrow> x \\<sharp>\\<sharp> (P \\<and> Q)\"\n  by (metis RID_conj unrest_relation_def)\n\nlemma or_runrest [unrest]: \"\\<lbrakk> x \\<sharp>\\<sharp> P; x \\<sharp>\\<sharp> Q \\<rbrakk> \\<Longrightarrow> x \\<sharp>\\<sharp> (P \\<or> Q)\"\n  by (simp add: RID_disj unrest_relation_def)\n\nsubsection {* Alphabet laws *}\n\nlemma aext_cond [alpha]:\n  \"(P \\<triangleleft> b \\<triangleright> Q) \\<oplus>\\<^sub>p a = ((P \\<oplus>\\<^sub>p a) \\<triangleleft>(b \\<oplus>\\<^sub>p a)\\<triangleright>(Q \\<oplus>\\<^sub>p a))\"\n  by (rel_auto)\n\nlemma aext_seq [alpha]:\n  \"wb_lens a \\<Longrightarrow> ((P ;; Q) \\<oplus>\\<^sub>p (a \\<times>\\<^sub>L a)) = ((P \\<oplus>\\<^sub>p (a \\<times>\\<^sub>L a)) ;; (Q \\<oplus>\\<^sub>p (a \\<times>\\<^sub>L a)))\"\n  by (rel_simp, metis wb_lens_weak weak_lens.put_get)\ntext {* We introduce the power syntax derived from semirings *}\n  \nsubsection {* Algebraic Properties *}\n\ninterpretation upred_semiring: semiring_1\n  where times = seqr and one = skip_r and zero = false\\<^sub>h and plus = Lattices.sup\n  by (unfold_locales, (rel_auto)+)\n\n\nabbreviation upower :: \"'\\<alpha> hrel \\<Rightarrow> nat \\<Rightarrow> '\\<alpha> hrel\" (infixr \"\\<^bold>^\" 100) where\n\"upower P n \\<equiv> upred_semiring.power P n\"\n\ntranslations\n  \"P \\<^bold>^ i\" <= \"CONST power.power II op ;; P i\"\n  \"P \\<^bold>^ i\" <= \"(CONST power.power II op ;; P) i\"\n\ntext {* Set up transfer tactic for powers *}\n\nlemma upower_rep_eq:\n  \"\\<lbrakk>P \\<^bold>^ i\\<rbrakk>\\<^sub>e = (\\<lambda> b. b \\<in> ({p. \\<lbrakk>P\\<rbrakk>\\<^sub>e p} ^^ i))\"\nproof (induct i arbitrary: P)\n  case 0\n  then show ?case\n    by (auto, rel_auto)\nnext\n  case (Suc i)\n  show ?case\n    by (simp add: Suc seqr.rep_eq relpow_commute)\nqed\n\nlemma upower_rep_eq_alt:\n  \"\\<lbrakk>power.power \\<langle>id\\<rangle>\\<^sub>a op ;; P i\\<rbrakk>\\<^sub>e = (\\<lambda>b. b \\<in> ({p. \\<lbrakk>P\\<rbrakk>\\<^sub>e p} ^^ i))\"\n  by (metis skip_r_def upower_rep_eq)\n\nupdate_uexpr_rep_eq_thms\n  \nlemma Sup_power_expand:\n  fixes P :: \"nat \\<Rightarrow> 'a::complete_lattice\"\n  shows \"P(0) \\<sqinter> (\\<Sqinter>i. P(i+1)) = (\\<Sqinter>i. P(i))\"\nproof -\n  have \"UNIV = insert (0::nat) {1..}\"\n    by auto\n  moreover have \"(\\<Sqinter>i. P(i)) = \\<Sqinter> (P ` UNIV)\"\n    by (blast)\n  moreover have \"\\<Sqinter> (P ` insert 0 {1..}) = P(0) \\<sqinter> SUPREMUM {1..} P\"\n    by (simp)\n  moreover have \"SUPREMUM {1..} P = (\\<Sqinter>i. P(i+1))\"\n    by (simp add: atLeast_Suc_greaterThan)\n  ultimately show ?thesis\n    by (simp only:)\nqed\n\nlemma Sup_upto_Suc: \"(\\<Sqinter>i\\<in>{0..Suc n}. P \\<^bold>^ i) = (\\<Sqinter>i\\<in>{0..n}. P \\<^bold>^ i) \\<sqinter> P \\<^bold>^ Suc n\"\nproof -\n  have \"(\\<Sqinter>i\\<in>{0..Suc n}. P \\<^bold>^ i) = (\\<Sqinter>i\\<in>insert (Suc n) {0..n}. P \\<^bold>^ i)\"\n    by (simp add: atLeast0_atMost_Suc)\n  also have \"... = P \\<^bold>^ Suc n \\<sqinter> (\\<Sqinter>i\\<in>{0..n}. P \\<^bold>^ i)\"\n    by (simp)\n  finally show ?thesis\n    by (simp add: Lattices.sup_commute)\nqed\n\ntext {* The following two proofs are adapted from the AFP entry \n  \\href{https://www.isa-afp.org/entries/Kleene_Algebra.shtml}{Kleene Algebra}. \n  See also~\\cite{Armstrong2012,Armstrong2015}. *}\n\nlemma seqr_left_unit [simp]:\n  \"II ;; P = P\"\n  by rel_auto\n\nlemma seqr_right_unit [simp]:\n  \"P ;; II = P\"\n  by rel_auto\n    \nlemma seqr_assoc: \"P ;; (Q ;; R) = (P ;; Q) ;; R\"\n  by rel_auto\n\nlemma seqr_assoc': \"(P ;; Q) ;; R = P ;; (Q ;; R) \"\n  by rel_auto    \n    \nlemma upower_inductl: \"Q \\<sqsubseteq> (P ;; Q \\<sqinter> R) \\<Longrightarrow> Q \\<sqsubseteq> P \\<^bold>^ n ;; R\"\nproof (induct n)\n  case 0\n  then show ?case by (auto)\nnext\n  case (Suc n)\n  then show ?case\n    by (auto, metis (no_types, hide_lams) dual_order.trans order_refl seqr_assoc seqr_mono)\nqed\n\nlemma upower_inductr:\n  assumes \"Q \\<sqsubseteq> (R \\<sqinter> Q ;; P)\"\n  shows \"Q \\<sqsubseteq> R ;; (P \\<^bold>^ n)\"\nusing assms proof (induct n)\n  case 0\n  then show ?case by auto\nnext\n  case (Suc n)\n  have \"R ;; P \\<^bold>^ Suc n = (R ;; P \\<^bold>^ n) ;; P\"\n    by (metis seqr_assoc upred_semiring.power_Suc2)\n  also have \"Q ;; P \\<sqsubseteq> ...\"\n    using Suc.hyps assms seqr_mono by auto\n  also have \"Q \\<sqsubseteq> ...\"\n    using assms by auto\n  finally show ?case .\nqed\n\nlemma SUP_atLeastAtMost_first:\n  fixes P :: \"nat \\<Rightarrow> 'a::complete_lattice\"\n  assumes \"m \\<le> n\"\n  shows \"(\\<Sqinter>i\\<in>{m..n}. P(i)) = P(m) \\<sqinter> (\\<Sqinter>i\\<in>{Suc m..n}. P(i))\"\n  by (metis SUP_insert assms atLeastAtMost_insertL)\n    \nlemma upower_seqr_iter: \"P \\<^bold>^ n = (;; Q : replicate n P \\<bullet> Q)\"\n  by (induct n) simp_all\n    \nsubsubsection {* Kleene Star *}\n\ndefinition ustar :: \"'\\<alpha> hrel \\<Rightarrow> '\\<alpha> hrel\" (\"_\\<^sup>\\<star>\" [999] 999) where\n\"P\\<^sup>\\<star> = (\\<Sqinter>i\\<in>{0..} \\<bullet> P\\<^bold>^i)\"\n\nlemma ustar_rep_eq:\n  \"\\<lbrakk>P\\<^sup>\\<star>\\<rbrakk>\\<^sub>e = (\\<lambda>b. b \\<in> ({p. \\<lbrakk>P\\<rbrakk>\\<^sub>e p}\\<^sup>*))\"\n  by (simp add: ustar_def, rel_auto, simp_all add: relpow_imp_rtrancl rtrancl_imp_relpow)\n\nupdate_uexpr_rep_eq_thms\n  \nsubsubsection {* Omega *}\n\ndefinition uomega :: \"'\\<alpha> hrel \\<Rightarrow> '\\<alpha> hrel\" (\"_\\<^sup>\\<omega>\" [999] 999) where\n\"P\\<^sup>\\<omega> = (\\<mu> X \\<bullet> P ;; X)\"\n\nsubsection {* Relation Algebra Laws *}\n\ntheorem RA1: \"(P ;; (Q ;; R)) = ((P ;; Q) ;; R)\"\n  using seqr_assoc by auto\n\ntheorem RA2: \"(P ;; II) = P\" \"(II ;; P) = P\"\n  by simp_all\n\ntheorem RA3: \"P\\<^sup>-\\<^sup>- = P\"\n  by simp\n\ntheorem RA4: \"(P ;; Q)\\<^sup>- = (Q\\<^sup>- ;; P\\<^sup>-)\"\n  by simp\n\ntheorem RA5: \"(P \\<or> Q)\\<^sup>- = (P\\<^sup>- \\<or> Q\\<^sup>-)\"\n  by (rel_auto)\n    \nnamed_theorems urel_comp  \n  \nlemma seqr_or_distl[urel_comp]:\n  \"((P \\<or> Q) ;; R) = ((P ;; R) \\<or> (Q ;; R))\"\n  by rel_auto\n    \ntheorem RA6: \"((P \\<or> Q) ;; R) = (P;;R \\<or> Q;;R)\"\n  using seqr_or_distl by blast\n\n\n\nsubsection {* Kleene Algebra Laws *}\n\ntheorem ustar_unfoldl: \"P\\<^sup>\\<star> \\<sqsubseteq> II \\<sqinter> P;;P\\<^sup>\\<star>\"\n  by (rel_simp, simp add: rtrancl_into_trancl2 trancl_into_rtrancl)\n\ntheorem ustar_inductl:\n  assumes \"Q \\<sqsubseteq> R\" \"Q \\<sqsubseteq> P ;; Q\"\n  shows \"Q \\<sqsubseteq> P\\<^sup>\\<star> ;; R\"\nproof -\n  have \"P\\<^sup>\\<star> ;; R = (\\<Sqinter> i. P \\<^bold>^ i ;; R)\"\n    by (simp add: ustar_def UINF_as_Sup_collect' seq_SUP_distr)\n  also have \"Q \\<sqsubseteq> ...\"\n    by (simp add: SUP_least assms upower_inductl)\n  finally show ?thesis .\nqed\n\ntheorem ustar_inductr:\n  assumes \"Q \\<sqsubseteq> R\" \"Q \\<sqsubseteq> Q ;; P\"\n  shows \"Q \\<sqsubseteq> R ;; P\\<^sup>\\<star>\"\nproof -\n  have \"R ;; P\\<^sup>\\<star> = (\\<Sqinter> i. R ;; P \\<^bold>^ i)\"\n    by (simp add: ustar_def UINF_as_Sup_collect' seq_SUP_distl)\n  also have \"Q \\<sqsubseteq> ...\"\n    by (simp add: SUP_least assms upower_inductr)\n  finally show ?thesis .\nqed\n\nlemma ustar_refines_nu: \"(\\<nu> X \\<bullet> P ;; X \\<sqinter> II) \\<sqsubseteq> P\\<^sup>\\<star>\"\n  by (metis (no_types, lifting) lfp_greatest semilattice_sup_class.le_sup_iff \n      semilattice_sup_class.sup_idem upred_semiring.mult_2_right \n      upred_semiring.one_add_one ustar_inductl)\n\nlemma ustar_as_nu: \"P\\<^sup>\\<star> = (\\<nu> X \\<bullet> P ;; X \\<sqinter> II)\"\nproof (rule antisym)\n  show \"(\\<nu> X \\<bullet> P ;; X \\<sqinter> II) \\<sqsubseteq> P\\<^sup>\\<star>\"\n    by (simp add: ustar_refines_nu)\n  show \"P\\<^sup>\\<star> \\<sqsubseteq> (\\<nu> X \\<bullet> P ;; X \\<sqinter> II)\"\n    by (metis lfp_lowerbound upred_semiring.add_commute ustar_unfoldl)\nqed\n  \nsubsection {* Omega Algebra Laws *}\n\nlemma uomega_induct:\n  \"P ;; P\\<^sup>\\<omega> \\<sqsubseteq> P\\<^sup>\\<omega>\"\n  by (simp add: uomega_def, metis eq_refl gfp_unfold monoI seqr_mono)\n\n\nend\n", "meta": {"author": "git-vt", "repo": "orca", "sha": "92bda0f9cfe5cc680b9c405fc38f07a960087a36", "save_path": "github-repos/isabelle/git-vt-orca", "path": "github-repos/isabelle/git-vt-orca/orca-92bda0f9cfe5cc680b9c405fc38f07a960087a36/C-verifier/src/Midend-IVL/Isabelle-UTP/utp/utp_urel_laws.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5428632979641571, "lm_q2_score": 0.5273165233795672, "lm_q1q2_score": 0.2862607869528254}}
{"text": "theory Construction_Utility\n  imports\n    Fused_Resource\n    State_Isomorphism\nbegin\n\n\\<comment> \\<open>Dummy converters that return a constant value on their external interface\\<close>\n\nprimcorec \n  ldummy_converter :: \"('a \\<Rightarrow> 'b) \\<Rightarrow> ('i_cnv, 'o_cnv, 'i_res, 'o_res) converter \\<Rightarrow> \n    ('a + 'i_cnv, 'b + 'o_cnv, 'i_res, 'o_res) converter\"\n  where\n    \"run_converter (ldummy_converter f conv) = (\\<lambda>inp. case inp of\n      Inl x \\<Rightarrow> map_gpv (map_prod Inl (\\<lambda>_. ldummy_converter f conv)) id (Done (f x, ()))\n    | Inr x \\<Rightarrow> map_gpv (map_prod Inr (\\<lambda>c. ldummy_converter f c)) id (run_converter conv x))\"\n\nprimcorec \n  rdummy_converter :: \"('a \\<Rightarrow> 'b) \\<Rightarrow> ('i_cnv, 'o_cnv, 'i_res, 'o_res) converter \\<Rightarrow> \n    ('i_cnv + 'a, 'o_cnv + 'b, 'i_res, 'o_res) converter\"\n  where\n    \"run_converter (rdummy_converter f conv) = (\\<lambda>inp. case inp of\n      Inl x \\<Rightarrow> map_gpv (map_prod Inl (\\<lambda>c. rdummy_converter f c)) id (run_converter conv x)\n    | Inr x \\<Rightarrow> map_gpv (map_prod Inr (\\<lambda>_. rdummy_converter f conv)) id (Done (f x, ())))\"\n\nlemma ldummy_converter_of_callee: \n  \"ldummy_converter f (converter_of_callee callee state) = \n    converter_of_callee (\\<lambda>s q. case_sum (\\<lambda>ql. Done (Inl (f ql), s)) (\\<lambda>qr. map_gpv (map_prod Inr id) id (callee s qr))  q)  state\"\n  apply (coinduction arbitrary: callee state)\n  apply(clarsimp intro!:rel_funI split!:sum.splits)\n  subgoal by blast\n  apply (simp add: gpv.rel_map map_prod_def split_def)\n  by (rule gpv.rel_mono_strong0[of \"(=)\" \"(=)\"]) (auto simp add: gpv.rel_eq)\n\nlemma rdummy_converter_of_callee: \n  \"rdummy_converter f (converter_of_callee callee state) = \n    converter_of_callee (\\<lambda>s q. case_sum (\\<lambda>ql. map_gpv (map_prod Inl id) id (callee s ql)) (\\<lambda>qr. Done (Inr (f qr), s))  q) state\"\n  apply (coinduction arbitrary: callee state)\n  apply(clarsimp intro!:rel_funI split!:sum.splits)\n  defer\n  subgoal by blast\n  apply (simp add: gpv.rel_map map_prod_def split_def)\n  by (rule gpv.rel_mono_strong0[of \"(=)\" \"(=)\"]) (auto simp add: gpv.rel_eq)\n\n\n\n\\<comment> \\<open>Commonly used wirings\\<close>\n\ncontext\n  fixes\n    cnv1 :: \"('icnv_usr1, 'ocnv_usr1, 'iusr1_res1 + 'iusr1_res2, 'ousr1_res1 + 'ousr1_res2) converter\" and\n    cnv2 :: \"('icnv_usr2, 'ocnv_usr2, 'iusr2_res1 + 'iusr2_res2, 'ousr2_res1 + 'ousr2_res2) converter\" \nbegin\n\n\\<comment> \\<open>c1r22: a converter that has 1 interface and sends queries to two resources,\n   where the first and second resources have 2 and 2 interfaces respectively\\<close>\n  \ndefinition \n  wiring_c1r22_c1r22 :: \"('icnv_usr1 + 'icnv_usr2, 'ocnv_usr1 + 'ocnv_usr2, \n    ('iusr1_res1 + 'iusr2_res1) + 'iusr1_res2 + 'iusr2_res2, \n    ('ousr1_res1 + 'ousr2_res1) + 'ousr1_res2 + 'ousr2_res2) converter\"\n  where \n    \"wiring_c1r22_c1r22  \\<equiv> (cnv1 |\\<^sub>= cnv2) \\<odot> parallel_wiring\"\n\nend\n\n\n\\<comment> \\<open>Special wiring converters used for the parallel composition of Fused resources\\<close>\n\ndefinition \n  fused_wiring :: \"\n    ((('iadv_core1 + 'iadv_core2) + ('iadv_rest1 + 'iadv_rest2)) + \n      (('iusr_core1 + 'iusr_core2) + ('iusr_rest1 + 'iusr_rest2)), \n    (('oadv_core1 + 'oadv_core2) + ('oadv_rest1 + 'oadv_rest2)) +\n      (('ousr_core1 + 'ousr_core2) + ('ousr_rest1 + 'ousr_rest2)),\n    (('iadv_core1 + 'iadv_rest1) + ('iusr_core1 + 'iusr_rest1)) + \n      (('iadv_core2 + 'iadv_rest2) + ('iusr_core2 + 'iusr_rest2)),\n    (('oadv_core1 + 'oadv_rest1) + ('ousr_core1 + 'ousr_rest1)) + \n      (('oadv_core2 + 'oadv_rest2) + ('ousr_core2 + 'ousr_rest2))) converter\"\n  where\n    \"fused_wiring \\<equiv> (parallel_wiring |\\<^sub>= parallel_wiring) \\<odot> parallel_wiring\"\n\ndefinition \n  fused_wiring\\<^sub>w \n  where\n    \"fused_wiring\\<^sub>w \\<equiv> (parallel_wiring\\<^sub>w |\\<^sub>w parallel_wiring\\<^sub>w) \\<circ>\\<^sub>w parallel_wiring\\<^sub>w\"\n\nschematic_goal \n  wiring_fused_wiring[wiring_intro]: \"wiring ?\\<I>1 ?\\<I>2 fused_wiring fused_wiring\\<^sub>w\"\n  unfolding fused_wiring_def fused_wiring\\<^sub>w_def\n  by(rule wiring_intro)+\n\nschematic_goal WT_fused_wiring [WT_intro]: \"?\\<I>1, ?\\<I>2 \\<turnstile>\\<^sub>C fused_wiring \\<surd>\"\n  unfolding fused_wiring_def\n  by(rule WT_intro)+\n\n\n\n\\<comment> \\<open>Commonlu used attachments\\<close>\n\ncontext\n  fixes\n    cnv1 :: \"('icnv_usr1, 'ocnv_usr1, 'iusr1_core1 + 'iusr1_core2, 'ousr1_core1 + 'ousr1_core2) converter\" and\n    cnv2 :: \"('icnv_usr2, 'ocnv_usr2, 'iusr2_core1 + 'iusr2_core2, 'ousr2_core1 + 'ousr2_core2) converter\" and\n    res1 :: \"(('iadv_core1 + 'iadv_rest1) + ('iusr1_core1 + 'iusr2_core1) + 'iusr_rest1,\n      ('oadv_core1 + 'oadv_rest1) + ('ousr1_core1 + 'ousr2_core1) + 'ousr_rest1) resource\" and\n    res2 :: \"(('iadv_core2 + 'iadv_rest2) + ('iusr1_core2 + 'iusr2_core2) + 'iusr_rest2,\n      ('oadv_core2 + 'oadv_rest2) + ('ousr1_core2 + 'ousr2_core2) + 'ousr_rest2) resource\"\nbegin\n\n\\<comment> \\<open>Attachement of two c1f22 ('f' instead of 'r' to indicate Fused Resources) converters \n  to two 2-interface Fused Resources, the results will be a new 2-interface Fused Resource\\<close>\n\ndefinition \n  attach_c1f22_c1f22 :: \"((('iadv_core1 + 'iadv_core2) + 'iadv_rest1 + 'iadv_rest2) + ('icnv_usr1 + 'icnv_usr2) + 'iusr_rest1 + 'iusr_rest2,\n    (('oadv_core1 + 'oadv_core2) + 'oadv_rest1 + 'oadv_rest2) + ('ocnv_usr1 + 'ocnv_usr2) + 'ousr_rest1 + 'ousr_rest2) resource\"\n  where\n    \"attach_c1f22_c1f22 = (((1\\<^sub>C |\\<^sub>= 1\\<^sub>C) |\\<^sub>= ((wiring_c1r22_c1r22 cnv1 cnv2) |\\<^sub>= 1\\<^sub>C)) \\<odot> fused_wiring) \\<rhd> (res1 \\<parallel> res2)\"\nend\n\n\n\\<comment> \\<open>Properties of Converters attaching to Fused resources\\<close>\ncontext\n  fixes\n    core1 :: \"('s_core1, 'e1, 'iadv_core1, 'iusr_core1, 'oadv_core1, 'ousr_core1) core\" and\n    core2 :: \"('s_core2, 'e2, 'iadv_core2, 'iusr_core2, 'oadv_core2, 'ousr_core2) core\" and\n    rest1 :: \"('s_rest1, 'e1, 'iadv_rest1, 'iusr_rest1, 'oadv_rest1, 'ousr_rest1, 'm1) rest_scheme\" and\n    rest2 :: \"('s_rest2, 'e2, 'iadv_rest2, 'iusr_rest2, 'oadv_rest2, 'ousr_rest2, 'm2) rest_scheme\"\nbegin\n\nlemma parallel_oracle_fuse:\n  \"apply_wiring fused_wiring\\<^sub>w (parallel_oracle (fused_resource.fuse core1 rest1) (fused_resource.fuse core2 rest2)) =\n    apply_state_iso parallel_state_iso (fused_resource.fuse (parallel_core core1 core2) (parallel_rest rest1 rest2))\"\n  supply fused_resource.fuse.simps[simp]\n  apply(rule ext)+\n  apply(clarsimp simp add: fused_wiring\\<^sub>w_def apply_state_iso_def parallel_state_iso_def parallel_wiring\\<^sub>w_def)\n  apply(simp add: apply_wiring_def comp_wiring_def parallel2_wiring_def lassocr\\<^sub>w_def swap_lassocr\\<^sub>w_def rassocl\\<^sub>w_def swap\\<^sub>w_def)\n  subgoal for s_core1 s_rest1 s_core2 s_rest2 i\n    apply(cases \"(parallel_rest rest1 rest2, ((s_core1, s_core2), (s_rest1, s_rest2)), i)\" rule: fused_resource.fuse.cases)\n       apply(auto split!: sum.splits)\n    subgoal for iadv_core\n      by (cases iadv_core) (auto simp add: map_spmf_bind_spmf bind_map_spmf intro!: bind_spmf_cong split!: sum.splits)\n    subgoal for iadv_rest\n      by (cases iadv_rest) (auto simp add: parallel_handler_left parallel_handler_right foldl_spmf_pair_left \n        parallel_eoracle_def foldl_spmf_pair_right split_beta o_def map_spmf_bind_spmf bind_map_spmf)\n    subgoal for iusr_core\n      by (cases iusr_core) (auto simp add: map_spmf_bind_spmf bind_map_spmf intro!: bind_spmf_cong split!: sum.splits)\n    subgoal for iusr_rest\n      by (cases iusr_rest) (auto simp add: parallel_handler_left parallel_handler_right foldl_spmf_pair_left \n        parallel_eoracle_def foldl_spmf_pair_right split_beta o_def map_spmf_bind_spmf bind_map_spmf)\n    done\n  done\nend\n\nlemma attach_callee_fuse:\n  \"attach_callee ((cnv_adv_core \\<ddagger>\\<^sub>I cnv_adv_rest) \\<ddagger>\\<^sub>I cnv_usr_core \\<ddagger>\\<^sub>I cnv_usr_rest) (fused_resource.fuse core rest) =\n   apply_state_iso iso_trisplit (fused_resource.fuse (attach_core cnv_adv_core cnv_usr_core core) (attach_rest cnv_adv_rest cnv_usr_rest f_init rest))\"\n  (is \"?lhs = ?rhs\")\nproof(intro ext; clarify)\n  note fused_resource.fuse.simps [simp]\n  let ?tri = \"\\<lambda>(((s11, s12), s13), (s21, s22), s23). (((s11, s21), s12, s22), s13, s23)\"\n  fix q :: \"('g + 'h) + 'i + 'j\"\n  consider (ACore) qac where \"q = Inl (Inl qac)\"\n    | (ARest) qar where \"q = Inl (Inr qar)\"\n    | (UCore) quc where \"q = Inr (Inl quc)\"\n    | (URest) qur where \"q = Inr (Inr qur)\"\n    using fuse_callee.cases by blast\n  then show \"?lhs (((sac, sar), (suc, sur)), (sc, sr)) q = ?rhs (((sac, sar), (suc, sur)), (sc, sr)) q\"\n    for sac sar suc sur sc sr\n  proof cases\n    case ACore\n    have \"map_spmf rprodl (exec_gpv (fused_resource.fuse core rest)\n       (left_gpv (map_gpv (map_prod Inl (\\<lambda>s1'. (s1', suc, sur))) id (left_gpv (map_gpv (map_prod Inl (\\<lambda>s1'. (s1', sar))) id (cnv_adv_core sac qac)))))\n       (sc, sr)) =\n     (map_spmf (map_prod (Inl \\<circ> Inl) (?tri \\<circ> prod.swap \\<circ> Pair ((sar, sur), sr)))\n       (map_spmf (\\<lambda>((oadv, s_adv'), s_core'). (oadv, (s_adv', suc), s_core'))\n         (exec_gpv (cfunc_adv core) (cnv_adv_core sac qac) sc)))\" \n    proof(induction arbitrary: sc cnv_adv_core rule: exec_gpv_fixp_parallel_induct)\n      case adm show ?case by simp\n      case bottom show ?case by simp\n      case (step execl execr)\n      show ?case\n        apply(clarsimp simp add: gpv.map_sel map_bind_spmf bind_map_spmf intro!: bind_spmf_cong[OF refl] split!: generat.split)\n        apply(subst step.IH[unfolded id_def])\n        apply(simp add: spmf.map_comp o_def)\n        done\n    qed\n    then show ?thesis using ACore\n      by(simp add: apply_state_iso_def iso_trisplit_def map_spmf_conv_bind_spmf[symmetric] spmf.map_comp o_def split_def)\n  next\n    case ARest\n    have \"bind_spmf (foldl_spmf (cpoke core) (return_spmf sc) es) (\\<lambda>sc'.\n      map_spmf rprodl (exec_gpv (fused_resource.fuse core rest)\n        (left_gpv (map_gpv (map_prod Inl (\\<lambda>s1'. (s1', suc, sur))) id (right_gpv (map_gpv (map_prod Inr (Pair sac)) id (cnv_adv_rest sar qar)))))\n        (sc', sr))) =\n      bind_spmf\n        (exec_gpv (\\<lambda>(s, es) q. map_spmf (\\<lambda>((out, e), s'). (out, s', es @ e)) (rfunc_adv rest s q)) (cnv_adv_rest sar qar) (sr, es))\n        (map_spmf (map_prod id ?tri) \\<circ>\n          ((\\<lambda>((o_rfunc, e_lst), s_rfunc). map_spmf (\\<lambda>s_notify. (Inl (Inr o_rfunc), s_notify, s_rfunc))\n            (map_spmf (Pair (sac, suc)) (foldl_spmf (cpoke core) (return_spmf sc) e_lst))) \\<circ>\n          (\\<lambda>((oadv, s_adv'), s_rest', es). ((oadv, es), (s_adv', sur), s_rest'))))\"\n      for es\n    proof(induction arbitrary: sc sr es cnv_adv_rest rule: exec_gpv_fixp_parallel_induct)\n      case adm then show ?case by simp\n      case bottom then show ?case by simp\n      case (step execl execr)\n      show ?case \n        apply(clarsimp simp add: gpv.map_sel map_bind_spmf bind_map_spmf)\n        apply(subst bind_commute_spmf)\n        apply(clarsimp simp add: gpv.map_sel map_bind_spmf bind_map_spmf spmf.map_comp o_def map_spmf_conv_bind_spmf[symmetric] intro!: bind_spmf_cong[OF refl] split!: generat.split)\n        apply(subst bind_commute_spmf)\n        apply(clarsimp simp add: gpv.map_sel map_bind_spmf bind_map_spmf spmf.map_comp o_def map_spmf_conv_bind_spmf[symmetric] intro!: bind_spmf_cong[OF refl] split!: generat.split)\n        apply(simp add: bind_spmf_assoc[symmetric] bind_foldl_spmf_return foldl_spmf_append[symmetric] del: bind_spmf_assoc )\n        apply(subst step.IH[unfolded id_def])\n        apply(simp add: split_def o_def spmf.map_comp)\n        done\n    qed\n    from this[of \"[]\"]\n    show ?thesis using ARest\n      by(simp add: apply_state_iso_def iso_trisplit_def map_bind_spmf bind_map_spmf map_spmf_conv_bind_spmf[symmetric] foldl_spmf_pair_right)\n  next\n    case UCore\n    have \"map_spmf rprodl (exec_gpv (fused_resource.fuse core rest)\n       (right_gpv (map_gpv (map_prod Inr (Pair (sac, sar))) id (left_gpv (map_gpv (map_prod Inl (\\<lambda>s1'. (s1', sur))) id (cnv_usr_core suc quc)))))\n       (sc, sr)) =\n     (map_spmf (map_prod (Inr \\<circ> Inl) (?tri \\<circ> prod.swap \\<circ> Pair ((sar, sur), sr)))\n       (map_spmf (\\<lambda>((ousr, s_usr'), s_core'). (ousr, (sac, s_usr'), s_core'))\n         (exec_gpv (cfunc_usr core) (cnv_usr_core suc quc) sc)))\"\n    proof(induction arbitrary: sc cnv_usr_core rule: exec_gpv_fixp_parallel_induct)\n      case adm show ?case by simp\n      case bottom show ?case by simp\n      case (step execl execr)\n      show ?case\n        apply(clarsimp simp add: gpv.map_sel map_bind_spmf bind_map_spmf intro!: bind_spmf_cong[OF refl] split!: generat.split)\n        apply(subst step.IH[unfolded id_def])\n        apply(simp add: spmf.map_comp o_def)\n        done\n    qed\n    then show ?thesis using UCore\n      by(simp add: apply_state_iso_def iso_trisplit_def map_spmf_conv_bind_spmf[symmetric] spmf.map_comp o_def split_def)\n  next\n    case URest\n    have \"bind_spmf (foldl_spmf (cpoke core) (return_spmf sc) es) (\\<lambda>sc'.\n      map_spmf rprodl (exec_gpv (fused_resource.fuse core rest)\n        (right_gpv (map_gpv (map_prod Inr (Pair (sac, sar))) id (right_gpv (map_gpv (map_prod Inr (Pair suc)) id (cnv_usr_rest sur qur)))))\n        (sc', sr))) =\n      bind_spmf\n        (exec_gpv (\\<lambda>(s, es) q. map_spmf (\\<lambda>((out, e), s'). (out, s', es @ e)) (rfunc_usr rest s q)) (cnv_usr_rest sur qur) (sr, es))\n        (map_spmf (map_prod id ?tri) \\<circ>\n           ((\\<lambda>((o_rfunc, e_lst), s_rfunc). map_spmf (\\<lambda>s_notify. (Inr (Inr o_rfunc), s_notify, s_rfunc))\n              (map_spmf (Pair (sac, suc)) (foldl_spmf (cpoke core) (return_spmf sc) e_lst))) \\<circ>\n           (\\<lambda>((ousr, s_usr'), s_rest', es). ((ousr, es), (sar, s_usr'), s_rest'))))\"\n      for es\n    proof(induction arbitrary: sc sr es cnv_usr_rest rule: exec_gpv_fixp_parallel_induct)\n      case adm then show ?case by simp\n      case bottom then show ?case by simp\n      case (step execl execr)\n      show ?case \n        apply(clarsimp simp add: gpv.map_sel map_bind_spmf bind_map_spmf)\n        apply(subst bind_commute_spmf)\n        apply(clarsimp simp add: gpv.map_sel map_bind_spmf bind_map_spmf spmf.map_comp o_def map_spmf_conv_bind_spmf[symmetric] intro!: bind_spmf_cong[OF refl] split!: generat.split)\n        apply(subst bind_commute_spmf)\n        apply(clarsimp simp add: gpv.map_sel map_bind_spmf bind_map_spmf spmf.map_comp o_def map_spmf_conv_bind_spmf[symmetric] intro!: bind_spmf_cong[OF refl] split!: generat.split)\n        apply(simp add: bind_spmf_assoc[symmetric] bind_foldl_spmf_return foldl_spmf_append[symmetric] del: bind_spmf_assoc )\n        apply(subst step.IH[unfolded id_def])\n        apply(simp add: split_def o_def spmf.map_comp)\n        done\n    qed\n    from this[of \"[]\"] show ?thesis using URest\n      by(simp add: apply_state_iso_def iso_trisplit_def map_bind_spmf bind_map_spmf map_spmf_conv_bind_spmf[symmetric] foldl_spmf_pair_right)\n  qed\nqed\n\nlemma attach_parallel_fuse':\n  \"(CNV cnv_adv_core s_a_c |\\<^sub>= CNV cnv_adv_rest s_a_r) |\\<^sub>= (CNV cnv_usr_core s_u_c |\\<^sub>= CNV cnv_usr_rest s_u_r) \\<rhd> \n   RES (fused_resource.fuse core rest) (s_r_c, s_r_r) = \n   RES (fused_resource.fuse (attach_core cnv_adv_core cnv_usr_core core) (attach_rest cnv_adv_rest cnv_usr_rest f_init rest)) (((s_a_c, s_u_c), s_r_c), ((s_a_r, s_u_r), s_r_r))\"\n  apply(fold conv_callee_parallel)\n  apply(unfold attach_CNV_RES)\n  apply(subst attach_callee_fuse)\n  apply(subst resource_of_oracle_state_iso)\n   apply simp\n  apply(simp add: iso_trisplit_def)\n  done\n\n\n\\<comment> \\<open>Moving event translators from rest to the core\\<close>\n\ncontext\n  fixes\n    einit :: 's_event and\n    etran :: \"('s_event, 'ievent, 'oevent list) oracle'\" and\n    rest :: \"('s_rest, 'ievent, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest) rest_wstate\" and\n    core :: \"('s_core, 'oevent, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core\"\nbegin\n\nprimcorec\n  translate_rest :: \"('s_event \\<times> 's_rest, 'oevent, 'iadv_rest, 'iusr_rest, 'oadv_rest, 'ousr_rest) rest_wstate\"\n  where\n    \"rinit translate_rest = (einit, rinit rest)\"\n  | \"rfunc_adv translate_rest = translate_eoracle etran (extend_state_oracle (rfunc_adv rest))\"\n  | \"rfunc_usr translate_rest = translate_eoracle etran (extend_state_oracle (rfunc_usr rest))\"\n\nprimcorec\n  translate_core :: \"('s_event \\<times> 's_core, 'ievent, 'iadv_core, 'iusr_core, 'oadv_core, 'ousr_core) core\"\n  where\n    \"cpoke translate_core = (\\<lambda>(s_event, s_core) event. \n      bind_spmf (etran s_event event) (\\<lambda>(events, s_event'). \n        map_spmf (\\<lambda>s_core'. (s_event', s_core')) (foldl_spmf (cpoke core) (return_spmf s_core) events)))\"\n  | \"cfunc_adv translate_core = extend_state_oracle (cfunc_adv core)\"\n  | \"cfunc_usr translate_core = extend_state_oracle (cfunc_usr core)\"\n\n\nlemma WT_translate_rest [WT_intro]: \n  assumes \"WT_rest \\<I>_adv \\<I>_usr I_rest rest\"\n  shows \"WT_rest \\<I>_adv \\<I>_usr (pred_prod (\\<lambda>_. True) I_rest) translate_rest\"\n  by(rule WT_rest.intros)(auto simp add: translate_eoracle_def simp add: WT_restD_rinit[OF assms] dest!: WT_restD(1,2)[OF assms])\n\n\nlemma fused_resource_move_translate:\n  \"fused_resource.fuse core translate_rest = apply_state_iso iso_swapar (fused_resource.fuse translate_core rest)\"\nproof -\n  note [simp] = exec_gpv_bind spmf.map_comp o_def map_bind_spmf bind_map_spmf bind_spmf_const\n\n  show ?thesis\n    apply (rule ext)\n    apply (rule ext)\n    subgoal for s query\n      apply (cases s)\n      subgoal for s_core s_event s_rest\n        apply (cases query)\n        subgoal for q_adv\n          apply (cases q_adv)\n          subgoal for q_acore\n            by (simp add: apply_state_iso_def iso_swapar_def fused_resource.fuse.simps split_def map_prod_def)\n          subgoal for q_arest\n            apply (simp add: apply_state_iso_def iso_swapar_def fused_resource.fuse.simps)\n            apply (simp add: translate_eoracle_def split_def)\n            apply(rule bind_spmf_cong[OF refl])\n            apply(subst foldl_spmf_chain[simplified split_def])\n            by simp\n          done\n        subgoal for q_usr\n          apply (cases q_usr)\n          subgoal for q_ucore\n            by (simp add: apply_state_iso_def iso_swapar_def fused_resource.fuse.simps split_def map_prod_def)\n          subgoal for q_urest\n            apply (simp add: apply_state_iso_def iso_swapar_def fused_resource.fuse.simps)\n            apply (simp add: translate_eoracle_def split_def)\n            apply(rule bind_spmf_cong[OF refl])\n            apply(subst foldl_spmf_chain[simplified split_def])\n            by simp\n          done\n        done\n      done\n    done\nqed\n\n\n\nend\n\n\n\\<comment> \\<open>Moving interfaces between rest and core\\<close>\n\nlemma\n  fuse_ishift_core_to_rest:\n  assumes \"cpoke core' = (\\<lambda>s. case_sum (\\<lambda>q. fn s q) (cpoke core s))\"\n      and \"cfunc_adv core = cfunc_adv core'\"\n      and \"cfunc_usr core = cfunc_usr core' \\<oplus>\\<^sub>O (\\<lambda>s i. map_spmf (Pair (h_out i)) (fn s i))\"\n      and \"rfunc_adv rest' = (\\<lambda>s q. map_spmf (apfst (apsnd (map Inr))) (rfunc_adv rest s q))\"\n      and \"rfunc_usr rest' = plus_eoracle (\\<lambda>s i. return_spmf ((h_out i, [i]), s)) (rfunc_usr rest)\"\n    shows \"fused_resource.fuse core rest = apply_wiring (1\\<^sub>w |\\<^sub>w lassocr\\<^sub>w) (fused_resource.fuse core' rest')\" (is \"?L = ?R\")\nproof -\n  note [simp] = fused_resource.fuse.simps apply_wiring_def lassocr\\<^sub>w_def parallel2_wiring_def \n    plus_eoracle_def map_spmf_conv_bind_spmf map_prod_def map_fun_def split_def o_def\n\n  have \"?L s q = ?R s q\" for s q\n    apply (cases q; cases s)\n    subgoal for q_adv\n      by (cases q_adv) (simp_all add: assms(1, 2, 4))\n    subgoal for q_usr\n      apply (cases q_usr)\n      subgoal for q_usr_core\n        apply (cases q_usr_core)\n        subgoal for q_nrm\n          by (simp add: assms(3))\n        by (simp add: assms(1, 3, 5))\n      by (simp add: assms(1, 5))\n    done\n\n  then show ?thesis\n    by blast\nqed\n\n\nlemma move_simulator_interface:\n  defines \"x_ifunc \\<equiv> (\\<lambda>ifunc core (se, sc) q. do {\n      ((out, es), se') \\<leftarrow> ifunc se q;\n      sc' \\<leftarrow> foldl_spmf (cpoke core) (return_spmf sc) es;\n      return_spmf (out, se', sc')   })\"\n  assumes \"cpoke core' = cpoke (translate_core etran core)\"\n      and \"cfunc_adv core' = \\<dagger>(cfunc_adv core) \\<oplus>\\<^sub>O x_ifunc ifunc core\"\n      and \"cfunc_usr core' = cfunc_usr (translate_core etran core)\"\n      and \"rinit rest = (einit, rinit rest')\"\n      and \"rfunc_adv rest = (\\<lambda>s q. case q of \n        Inl ql \\<Rightarrow> map_spmf (apfst (map_prod Inl id)) ((ifunc\\<dagger>) s ql)\n      | Inr qr \\<Rightarrow> map_spmf (apfst (map_prod Inr id)) ((translate_eoracle etran (\\<dagger>(rfunc_adv rest'))) s qr))\"\n      and \"rfunc_usr rest = translate_eoracle etran (\\<dagger>(rfunc_usr rest'))\"\n  shows \"fused_resource.fuse core rest =  apply_wiring (rassocl\\<^sub>w |\\<^sub>w (id, id))\n       (apply_state_iso (rprodl o (apfst prod.swap), (apfst prod.swap) o lprodr)\n         (fused_resource.fuse core' rest'))\"\n    (is \"?L = ?R\")\nproof -\n  note [simp] = fused_resource.fuse.simps apply_wiring_def rassocl\\<^sub>w_def parallel2_wiring_def apply_state_iso_def\n    exec_gpv_bind spmf.map_comp map_bind_spmf bind_map_spmf bind_spmf_const o_def split_def\n\n  have \"?L (sc, st, sr) q = ?R (sc, st, sr) q\" for sc st sr q\n  apply (simp add: map_fun_def map_prod_def prod.swap_def apfst_def lprodr_def rprodl_def id_def)\n    using assms apply (cases q)\n    subgoal for q_adv\n      apply (cases q_adv)\n      subgoal for q_adv_core\n        by (simp add: map_prod_def)\n      subgoal for q_adv_rest\n        apply (cases q_adv_rest)\n        subgoal for q_adv_rest_ifunc\n          by simp\n        subgoal for q_adv_rest_etran\n          apply (simp add: translate_eoracle_def)\n          apply(rule bind_spmf_cong[OF refl])\n          apply(subst foldl_spmf_chain[simplified split_def])\n          by simp\n        done\n      done\n    subgoal for q_usr\n      apply (cases q_usr)\n      subgoal for q_usr_core\n        by (simp add: map_prod_def)\n      subgoal for q_usr_rest\n        apply (simp add: translate_eoracle_def extend_state_oracle_def)\n        apply(rule bind_spmf_cong[OF refl])\n            apply(subst foldl_spmf_chain[simplified split_def])\n          by simp\n      done\n    done\n\n  then show ?thesis\n    by force\nqed\n\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Constructive_Cryptography_CM/Construction_Utility.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.2862607791529429}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\n(*\n * Tactic for solving monadic equalities, such as:\n *\n * (liftE (return 3) = returnOk 3\n *\n * Theorems of the form:\n *\n *   ((a, s') \\<in> fst (A s)) = P a s s'\n *\n * and\n *\n *   snd (A s) = P s\n *\n * are added to the \"monad_eq\" set.\n *)\ntheory MonadEq\nimports \"wp/NonDetMonadVCG\"\nbegin\n\n(* Setup \"monad_eq\" attributes. *)\nML {*\nstructure MonadEqThms = Named_Thms (\n    val name = Binding.name \"monad_eq\"\n    val description = \"monad equality-prover theorems\"\n    )\n*}\nattribute_setup monad_eq = {*\n  Attrib.add_del\n    (Thm.declaration_attribute MonadEqThms.add_thm)\n    (Thm.declaration_attribute MonadEqThms.del_thm) *}\n  \"Monad equality-prover theorems\"\n\n(* Setup tactic. *)\n\nML {*\nfun monad_eq_tac ctxt =\nlet\n  (* Set a simpset as being hidden, so warnings are not printed from it. *)\n  val ctxt' = Context_Position.set_visible false ctxt\nin\n  CHANGED (clarsimp_tac (ctxt' addsimps (MonadEqThms.get ctxt')) 1)\nend\n*}\n\nmethod_setup monad_eq = {*\n    Method.sections Clasimp.clasimp_modifiers >> (K (SIMPLE_METHOD o monad_eq_tac)) *}\n  \"prove equality on monads\"\n\nlemma monad_eq_simp_state [monad_eq]:\n  \"((A :: ('s, 'a) nondet_monad) s = B s') =\n      ((\\<forall>r t. (r, t) \\<in> fst (A s) \\<longrightarrow> (r, t) \\<in> fst (B s'))\n         \\<and> (\\<forall>r t. (r, t) \\<in> fst (B s') \\<longrightarrow> (r, t) \\<in> fst (A s))\n         \\<and> (snd (A s) = snd (B s')))\"\n  apply (auto intro!: set_eqI prod_eqI)\n  done\n\nlemma monad_eq_simp [monad_eq]:\n  \"((A :: ('s, 'a) nondet_monad) = B) =\n      ((\\<forall>r t s. (r, t) \\<in> fst (A s) \\<longrightarrow> (r, t) \\<in> fst (B s))\n         \\<and> (\\<forall>r t s. (r, t) \\<in> fst (B s) \\<longrightarrow> (r, t) \\<in> fst (A s))\n         \\<and> (\\<forall>x. snd (A x) = snd (B x)))\"\n  apply (auto intro!: set_eqI prod_eqI)\n  done\n\ndeclare in_monad [monad_eq]\ndeclare in_bindE [monad_eq]\n\n(* Test *)\nlemma \"returnOk 3 = liftE (return 3)\"\n  apply monad_eq\n  oops\n\nend\n", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/lib/MonadEq.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5428632683808533, "lm_q2_score": 0.5273165233795672, "lm_q1q2_score": 0.2862607713530605}}
{"text": "(*  Title:       Jive Data and Store Model\n    Author:      Norbert Schirmer <schirmer at informatik.tu-muenchen.de>  and  \n                 Nicole Rauch <rauch at informatik.uni-kl.de>, 2005\n    Maintainer:  Nicole Rauch <rauch at informatik.uni-kl.de>\n    License:     LGPL\n*)\n\nsection \\<open>Program-Independent Lemmas on Attributes\\<close>\n\ntheory AttributesIndep\nimports \"../Isa_Counter_Store/Attributes\"\nbegin\n\ntext \\<open>The following lemmas validate the functions defined in the Attributes theory.\nThey also aid in subsequent proving tasks. Since they are\nprogram-independent, it is of no use to add them to the generation process of\nAttributes.thy. Therefore, they have been extracted to this theory.\n\\<close>\n\nlemma cls_catt [simp]: \n  \"CClassT c \\<le> dtype f \\<Longrightarrow> cls (catt c f) = c\"\n  apply (case_tac c)\n  apply (case_tac [!] f)\n  apply simp_all\n   \\<comment> \\<open>solves all goals where @{text \"CClassT c \\<le> dtype f\"}\\<close>\n  apply (fastforce elim: subtype_wrong_elims simp add: subtype_defs)+\n   \\<comment> \\<open>solves all the rest where @{text \"\\<not> CClassT c \\<le> dtype f\"} can be derived\\<close>\n  done\n\nlemma att_catt [simp]: \n  \"CClassT c \\<le> dtype f \\<Longrightarrow> att (catt c f) = f\"\n  apply (case_tac c)\n  apply (case_tac [!] f)\n  apply simp_all\n   \\<comment> \\<open>solves all goals where @{text \"CClassT c \\<le> dtype f\"}\\<close>\n  apply (fastforce elim: subtype_wrong_elims simp add: subtype_defs)+\n   \\<comment> \\<open>solves all the rest where @{text \"\\<not> CClassT c \\<le> dtype f\"} can be \n        derived\\<close>\n  done\n\ntext \\<open>The following lemmas are just a demonstration of simplification.\\<close>\n\nlemma rtype_att_catt: \n  \"CClassT c \\<le> dtype f \\<Longrightarrow> rtype (att (catt c f)) = rtype f\"\n  by simp\n\nlemma widen_cls_dtype_att [simp,intro]: \n  \"(CClassT (cls cf) \\<le> dtype (att cf)) \"\n  by (cases cf, simp_all)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/JiveDataStoreModel/Isabelle_Store/AttributesIndep.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5273165085228825, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.2862607710877943}}
{"text": "theory RCU\nimports RCU_model\nbegin \n\n(*the following must be included in the proof:\n\ncon_assms ps        --- concerns allocation/bounds of C and rcu_0+i for all i\nmain_inv ms             --- main invariant has 3 parts\n\nnts::\npsem_rules ps               --- how allocation works on the inside\n\ntedious - general_structure ms                      --- says how n \\<noteq> s \\<noteq> detaddrs\nallocated_addresses ms ps *********        --- allocation for above are defined here\nsimple - observation_inv_ms ms         --- how own\\<^sub>W affects loc status (own\\<^sub>W loc = t \\<longrightarrow> loc\\<in>{s,n,det} t)\nhard - observation_inv_sig ms ps \\<sigma>       --- limits which values can be WM_read from C\nsimple - own\\<^sub>W_n_by_t_imp ms\n\n\nt \\<le> T_max\nstep ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>'     --- defines a program step by t\nlast - preCond ms ps \\<sigma> (pc ms t) t             --- defines preconditions for t to proceed with stepping      \n\n\n\n\n*)\n\n\n\n(*the following describes originally reserved addresses*)\ndefinition \"default_locs \\<equiv> {i | i a. i=C \\<or> i = rcu_0+a \\<and> a\\<le>T_max }\"\n\ndefinition \"reserved_bydef ps \\<equiv> \\<forall>i. i\\<in>default_locs \\<longrightarrow> \\<not>isfree_addr i ps\"\n\ndefinition \"reservations_differ \\<equiv> \\<forall>i. i\\<le>T_max \\<longrightarrow> C\\<noteq>rcu_0+i\"\n\ndefinition \"con_assms ps \\<equiv> reserved_bydef ps \\<and> reservations_differ  \"\n\nlemmas con_lemmas [simp] = reserved_bydef_def reservations_differ_def default_locs_def\n\n\n\n(*----------------Main Invariant Shown--------------------*)\n\nlemma main_invariant_1_preservation:\n  \"main_inv ms ps \\<Longrightarrow> \n  t\\<le>T_max \\<Longrightarrow>\n  general_structure ms \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> \n  preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n  cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow>\n  psem_rules ps \\<Longrightarrow>\n  own\\<^sub>W_n_by_t_imp ms \\<Longrightarrow>\n    main_inv_1 ms'\"\n  apply simp \n  apply(simp add: step_def preCond_def general_structure_lemmas main_inv_lemmas)\n  apply(case_tac \"pc ms t\", simp_all add:abbr) apply clarsimp\n  apply (metis insert_not_empty option.sel) apply clarsimp\n  apply(case_tac \"repeat ms t\", simp_all) \n  apply (metis option.sel)\n  apply (metis option.sel)\n  (*FAAZ*) defer\n  apply clarsimp\n  apply (metis option.sel)\n  apply clarsimp\n  apply(case_tac \"snd (CAS t (a, b) ya y \\<sigma> ts')\", simp_all)\n  apply (metis option.sel)\n  apply (metis option.sel)\n  apply (metis Diff_empty Diff_insert0 insert_Diff singleton_insert_inj_eq)\n  apply(case_tac \"CAS_succ ms t\", simp_all add:abbr)\n  apply clarsimp\n  apply (metis option.sel)\n  apply(case_tac \"nondet_val ms t\", simp_all add:abbr)\n  apply(case_tac \"det ms t \\<noteq> []\", simp_all add:abbr)\n  apply (metis Diff_empty Diff_insert0 insert_absorb insert_iff)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all add:abbr)\n  apply clarsimp\n  apply (metis option.sel)\n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all add:abbr)\n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all add:abbr)\n  apply clarsimp\n  apply (metis option.sel)\n  apply(case_tac \"reg ms t = 1\", simp_all add:abbr)\n  apply(simp add: FAAZ_def get_C_val_def)\n  apply(clarsimp)  (*y \\<noteq> value \\<sigma> (a, b), where value \\<sigma> (a, b) is retrieved from reading C*)\n  apply(simp_all add: covered_v_def lastWr_def observation_inv_sig_def visible_writes_def)\n  by (metis option.sel own\\<^sub>W_n_by_t_imp_def)\n\n\nlemma main_invariant_2_preservation:\n  \"main_inv ms ps \\<Longrightarrow> \n  t\\<le>T_max \\<Longrightarrow>\n  general_structure ms \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> \n  preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow>\n  cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  psem_rules ps \\<Longrightarrow>\n  own\\<^sub>W_n_by_t_imp ms \\<Longrightarrow>\n    main_inv_2 ms' ps'\"\n  apply simp \n  apply(simp add: step_def preCond_def general_structure_lemmas main_inv_lemmas)\n  apply(case_tac \"pc ms t\", simp_all add:abbr)\n  apply clarsimp\n  apply clarsimp\n  apply(case_tac \"repeat ms t\", simp_all)  \n  apply (metis subset_singleton_iff) \n  (*FAAZ*) defer\n  apply clarsimp\n  apply clarsimp apply(case_tac \" snd (CAS t (a, b) ya y \\<sigma> ts')\", simp_all)\n  apply(case_tac \"CAS_succ ms t\", simp_all add:abbr)\n  apply clarsimp\n  apply(case_tac \"nondet_val ms t\", simp_all add:abbr)\n  apply(case_tac \"det ms t \\<noteq> []\", simp_all add:abbr) \n  (*detached rules*) defer\n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all add:abbr)\n  apply clarsimp\n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all add:abbr)\n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all add:abbr)\n  apply clarsimp\n  apply(case_tac \"reg ms t = 1\", simp_all add:abbr)\n  apply(simp add: FAAZ_def get_C_val_def)\n  apply(clarsimp)  (*y \\<noteq> value \\<sigma> (a, b), where value \\<sigma> (a, b) is retrieved from reading C*)\n  apply(simp add: covered_v_def observation_inv_sig_def visible_writes_def)\n  apply blast\n  (*the detached list property*)\n  apply clarify apply(intro conjI impI)\n  apply(subgoal_tac \"hd(det ms t) \\<in> detaddrs ms t\", simp_all) \n  apply(subgoal_tac \"det ms t \\<noteq> []\") prefer 2\n  apply blast\n  apply(subgoal_tac \"det ms t!0 = hd(det ms t)\") prefer 2\n  apply (metis hd_conv_nth)\n  by blast\n\n\n\nlemma main_invariant_3_preservation:\n  \"main_inv ms ps \\<Longrightarrow> \n  t\\<le>T_max \\<Longrightarrow>\n  general_structure ms \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> \n  preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow>\n  psem_rules ps \\<Longrightarrow>\n  cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  own\\<^sub>W_n_by_t_imp ms \\<Longrightarrow>\n    main_inv_3 ms' ps'\"\n  apply simp \n  apply(simp add: step_def preCond_def general_structure_lemmas main_inv_lemmas)\n  apply(case_tac \"pc ms t\", simp_all add:abbr Wcap_def Rcap_def)\n  apply clarsimp \n  apply (meson own\\<^sub>W_n_by_t_imp_def)\n  apply clarsimp\n  apply(case_tac \"repeat ms t\", simp_all add:own\\<^sub>W_n_by_t_imp_def) \n  apply clarsimp \n  apply(case_tac \"loc = ya\", simp_all) \n  apply (metis less_nat_zero_code list.size(3) option.sel) \n  (*FAAZ*) defer\n  apply clarsimp apply clarsimp\n  apply(case_tac \"snd (CAS t (a, b) ya y \\<sigma> ts')\", simp_all) \n  apply (meson option.distinct(1)) \n  apply (metis option.discI)\n  apply(case_tac \"CAS_succ ms t\", simp_all add:abbr)\n  apply clarsimp\n  apply(case_tac \"nondet_val ms t\", simp_all add:abbr)\n  apply(case_tac \"det ms t \\<noteq> []\", simp_all add:abbr)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all add:abbr)\n  apply clarsimp\n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all add:abbr)\n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all add:abbr)\n  apply clarsimp\n  apply(case_tac \"reg ms t = 1\", simp_all add:abbr)\n  apply(simp add: FAAZ_def get_C_val_def)\n  apply(clarsimp) (*y \\<noteq> value \\<sigma> (a, b), where value \\<sigma> (a, b) is retrieved from reading C*)\n  by(case_tac \"loc = value \\<sigma> (a, b)\", simp_all) \n\n\n\n\nlemma main_invariant_preservation:\n  \"main_inv ms ps \\<Longrightarrow> \n  t\\<le>T_max \\<Longrightarrow>\n  general_structure ms \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> \n  preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow>\n  cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  psem_rules ps \\<Longrightarrow>\n  own\\<^sub>W_n_by_t_imp ms  \\<Longrightarrow> \nmain_inv ms' ps'\"\n  unfolding main_inv_def\n  apply(intro conjI impI)\n  using main_invariant_1_preservation main_inv_def apply blast\n  using main_invariant_2_preservation main_inv_def apply blast\n  using main_invariant_3_preservation main_inv_def apply blast\n  done\n\n(*--------------------------------------------------------------------*)\n\n(*------------------------observation_inv_sig Correctness---------------------------*)\n\nlemma supp1:\n  \"cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  \\<sigma> [z \\<leftarrow> ya]\\<^sub>t \\<sigma>' \\<Longrightarrow>\n  cvd[C,vala] \\<sigma>'\"\n  apply(simp add:covered_v_def lastWr_def OpSem.step_def RdX_def visible_writes_def) unfolding writes_on_def\n  read_trans_def\n  by (smt (z3) Collect_cong rev_app_def surrey_state.ext_inject surrey_state.surjective surrey_state.update_convs(2) update_thrView_def value_def)\n\nlemma supp2:\n  \"cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  \\<sigma> [z := ya]\\<^sub>t \\<sigma>' \\<Longrightarrow>\n  z\\<noteq>C \\<Longrightarrow>\n  cvd[C,vala] \\<sigma>'\"\n  apply(simp add:covered_v_def lastWr_def OpSem.step_def WrX_def visible_writes_def value_def) unfolding writes_on_def\n  write_trans_def update_thrView_def update_mods_def \n  update_modView_def valid_fresh_ts_def \n  rev_app_def tst_def \n  apply auto\n  sledgehammer\n\n\nlemma Local_correctness:\n  \"main_inv ms ps \\<Longrightarrow> \n  t\\<le>T_max \\<Longrightarrow>\n  general_structure ms \\<Longrightarrow>\n  step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \\<Longrightarrow> \n  preCond ms ps \\<sigma> (pc ms t) t \\<Longrightarrow> \n  observation_inv_sig ms ps \\<sigma> \\<Longrightarrow>\n  cvd[C,vala] \\<sigma> \\<Longrightarrow>\n  psem_rules ps \\<Longrightarrow>\n  own\\<^sub>W_n_by_t_imp ms  \\<Longrightarrow> \nobservation_inv_sig ms' ps' \\<sigma>'\"\n  apply(simp add:step_def preCond_def)\n  apply(case_tac \"pc ms t\")\n  apply simp_all \n  apply (simp add:abbr)\n  apply(simp add:observation_inv_sig_def)\n  apply (simp add:abbr)\n  apply(simp add:observation_inv_sig_def)\n  apply (simp add:abbr)\n  apply(simp add:observation_inv_sig_def)\n  apply (simp add:abbr)\n  apply(simp add:observation_inv_sig_def)\n  apply clarsimp apply(simp add:covered_v_def)\n  apply metis\n  apply(simp add:abbr)  \n(*RCU_enter()*)defer\n  (*RCU_exit()*) defer\n  (*RCU_enter()*)defer\n  apply(simp add:abbr FAAZ_def get_C_val_def)\n  apply(simp add:covered_v_def visible_writes_def observation_inv_sig_def)\n  apply(simp add:lastWr_def) apply clarify\n                      defer\n  apply (simp add: observation_inv_sig_def) apply clarify\n  apply(simp add:abbr) apply clarsimp\n  apply(simp add:general_structure_lemmas main_inv_lemmas own\\<^sub>W_n_by_t_imp_def Wcap_def Rcap_def)\n  unfolding covered_v_def writes_on_def\n  apply clarify\n  sledgehammer\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n(*--------------------------------------------------------------------*)\n\n\nlemma preservation_of_variables_1_by_others:\n  assumes \"preCond ms ps \\<sigma> (pc ms t) t\"\n  and \"t \\<le> T_max\"\n  and \"ta \\<le> T_max\"\n  and \"step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>'\"    \n  and \"general_structure ms\"\n  and \"ta \\<noteq> t\"\nshows \"n ms ta = n ms' ta\"\n  using assms\n  apply(simp add:step_def)\n  apply(simp add:preCond_def)\n  apply(case_tac \"pc ms t\", simp_all)\n  apply(simp_all add:abbr)\n  apply clarify\n  apply(simp_all add:general_structure_lemmas) apply clarsimp  apply(simp add:get_C_val_def)\n  apply(simp add:FAAZ_def)\n  apply(simp add: visible_writes_def)\n  apply clarsimp\n  apply clarsimp \n  apply clarsimp\n  apply(case_tac \"snd (CAS t (a, b) (the (s ms t)) (the (n ms t)) \\<sigma> ts')\", simp_all)\n  apply(case_tac \"CAS_succ ms t\", simp_all add:abbr)\n  apply(clarsimp)\n  apply(case_tac \"nondet_val ms t\", simp_all add:abbr)\n  apply(case_tac \"det ms t \\<noteq> []\", simp_all add:abbr)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all add:abbr)\n  apply(clarsimp)\n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all add:abbr)\n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all add:abbr)\n  apply(clarsimp)\n  by(case_tac \"reg ms t = Suc 0\", simp_all add:abbr)\n\nlemma preservation_of_variables_2_by_others:\n  assumes \"preCond ms ps \\<sigma> (pc ms t) t\"\n  and \"t \\<le> T_max\"\n  and \"ta \\<le> T_max\"\n  and \"step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>'\"    \n  and \"general_structure ms\"\n  and \"ta \\<noteq> t\"\nshows \"s ms ta = s ms' ta\"\n  using assms \n  apply(simp add:step_def)\n  apply(simp add:preCond_def)\n  apply(case_tac \"pc ms t\", simp_all)\n  apply(simp_all add:abbr)\n  apply clarify\n  apply(simp_all add:general_structure_lemmas)apply(simp add:get_C_val_def)\n  apply(simp add:FAAZ_def)\n  apply(simp add: visible_writes_def) \n  apply clarsimp\n  apply clarsimp\n  apply clarsimp\n  apply(case_tac \"snd (CAS t (a, b) (the (s ms t)) (the (n ms t)) \\<sigma> ts')\", simp_all)\n  apply(case_tac \"CAS_succ ms t\", simp_all add:abbr)\n  apply(clarsimp)\n  apply(case_tac \"nondet_val ms t\", simp_all add:abbr)\n  apply(case_tac \"det ms t \\<noteq> []\", simp_all add:abbr)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all add:abbr)\n  apply(clarsimp)\n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all add:abbr)\n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all add:abbr)\n  apply(clarsimp)\n  by(case_tac \"reg ms t = Suc 0\", simp_all add:abbr)\n\nlemma preservation_of_variables_3_by_others:\n  assumes \"preCond ms ps \\<sigma> (pc ms t) t\"\n  and \"t \\<le> T_max\"\n  and \"ta \\<le> T_max\"\n  and \"step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>'\"    \n  and \"general_structure ms\"\n  and \"ta \\<noteq> t\"\nshows \"det ms ta = det ms' ta\"\n  using assms\n  apply(simp add:step_def)\n  apply(simp add:preCond_def)\n  apply(case_tac \"pc ms t\", simp_all)\n  apply(simp_all add:abbr)\n  apply clarify\n  apply(simp_all add:general_structure_lemmas)apply(simp add:get_C_val_def)\n  apply(simp add:FAAZ_def)\n  apply(simp add: visible_writes_def) \n  apply clarsimp\n  apply clarsimp\n  apply clarsimp\n  apply(case_tac \"snd (CAS t (a, b) (the (s ms t)) (the (n ms t)) \\<sigma> ts')\", simp_all)\n  apply(case_tac \"CAS_succ ms t\", simp_all add:abbr)\n  apply(clarsimp)\n  apply(case_tac \"nondet_val ms t\", simp_all add:abbr)\n  apply(case_tac \"det ms t \\<noteq> []\", simp_all add:abbr)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all add:abbr)\n  apply(clarsimp)\n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all add:abbr)\n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all add:abbr)\n  apply(clarsimp)\n  by(case_tac \"reg ms t = Suc 0\", simp_all add:abbr)\nlemma preservation_of_variables_inset_by_others:\n  assumes \"preCond ms ps \\<sigma> (pc ms t) t\"\n  and \"t \\<le> T_max\"\n  and \"ta \\<noteq> t\"\n  and \"ta \\<le> T_max\"\n  and \"step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>'\"    \n  and \"general_structure ms\"\n  and \"own\\<^sub>W ms loc = Some ta\"\n  and \"observation_inv_ms ms\"\nshows \"(loc \\<in> (detaddrs ms' ta) \\<or> Some loc = s ms' ta \\<or> Some loc = n ms' ta)\"\n  using assms \n  apply(subgoal_tac \"(det ms' ta) = (det ms ta)\") prefer 2 \n  using preservation_of_variables_3_by_others\n  apply force\n  apply(subgoal_tac \"the (s ms' ta) = the (s ms ta)\") prefer 2 \n  using preservation_of_variables_2_by_others\n  apply force\n  apply(subgoal_tac \"the (n ms' ta) = the (n ms ta)\") prefer 2 \n  using preservation_of_variables_1_by_others\n  apply force \n  apply(simp add:observation_inv_ms_def) \n  by (metis assms(5) preservation_of_variables_1_by_others preservation_of_variables_2_by_others)+\n  \n\n\n\n\nlemma preservation_of_variables_ninset_by_others:\n  assumes \"preCond ms ps \\<sigma> (pc ms t) t\"\n  and \"t \\<le> T_max\"\n  and \"ta \\<noteq> t\"\n  and \"ta \\<le> T_max\"\n  and \"step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>'\"    \n  and \"general_structure ms\"\n  and \"(loc \\<notin> (detaddrs ms ta) \\<and> Some loc \\<noteq> s ms ta \\<and> Some loc \\<noteq> n ms ta)\"\n  and \"observation_inv_ms ms\"\nshows \"(loc \\<notin> (detaddrs ms' ta) \\<and> Some loc \\<noteq> s ms' ta \\<and> Some loc \\<noteq> n ms' ta)\"\n  using assms apply simp\n  by (simp add: preservation_of_variables_1_by_others \n                preservation_of_variables_2_by_others \n                preservation_of_variables_3_by_others)\nlemma preservation_of_ownership_by_others:\n  \"preCond ms ps \\<sigma> (pc ms t) t\n\\<Longrightarrow> own\\<^sub>W ms loc = Some ta \n\\<Longrightarrow> ta\\<noteq>t \n\\<Longrightarrow> ta\\<le>T_max\n\\<Longrightarrow> t\\<le>T_max\n\\<Longrightarrow> main_inv_2 ms ps\n\\<Longrightarrow> main_inv_3 ms ps\n\\<Longrightarrow> observation_inv_ms ms\n\\<Longrightarrow> own\\<^sub>W_n_by_t_imp ms\n\\<Longrightarrow> general_structure ms\n\\<Longrightarrow> step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \n     \\<Longrightarrow> own\\<^sub>W ms' loc = Some ta\"\n  apply(simp add:step_def)\n  apply(case_tac \"pc ms t\", simp_all add:abbr)\n  (*n:=newint*) defer\n  (*FAAZ*) defer\n  apply force\n  (*cas_step_rcu*) defer\n  apply(case_tac \"CAS_succ ms t\", simp_all add:abbr)\n  apply force\n  apply(case_tac \"nondet_val ms t\", simp_all add:abbr)\n  apply(case_tac \"det ms t\", simp_all add:abbr)\n  (*kill*) defer\n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all add:abbr)\n  apply force\n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all add:abbr)\n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all add:abbr)\n  apply force\n  apply(case_tac \"reg ms t = Suc 0\", simp_all add:abbr)\n  apply clarsimp\n  apply(case_tac \"loc = loca\", simp_all)\n  using get_C_val_def mstate.simps(17) apply force apply clarify\n  apply(case_tac \"snd (CAS t (a, b) (the (s ms t)) (the (n ms t)) \\<sigma> ts')\", simp_all)\n  apply(simp add:observation_inv_ms_def)\n  apply(subgoal_tac \"loc \\<in> (detaddrs ms ta \\<union> s_and_n ms ta)\") prefer 2\n  apply(simp add:detaddrs_def s_and_n_def)\n  apply(simp add:general_structure_lemmas)\n  apply(simp add:preCond_def)\n  apply meson\n  apply(simp add:general_structure_lemmas)\n  apply(simp add:preCond_def observation_inv_ms_def own\\<^sub>W_n_by_t_imp_def)\n  apply(case_tac \"Some loc = (n ms ta)\") \n  apply (metis (no_types, lifting) hd_conv_nth length_greater_0_conv option.distinct(1) option.sel)\n  apply (metis (no_types, lifting) option.sel)\n  apply(simp add:preCond_def Wcap_def) \n  apply (metis option.sel)\n  apply(simp add:preCond_def Wcap_def) \n  apply(simp add:general_structure_lemmas)\n  (*ta cannot own\\<^sub>W ms LOC where LOC \\<in> det_addrs ms t*) \n  sorry\n  \n  \n\nlemma preservation_of_nownership_by_others:\n  \"preCond ms ps \\<sigma> (pc ms t) t\n\\<Longrightarrow> own\\<^sub>W ms loc \\<noteq> Some ta \n\\<Longrightarrow> ta\\<noteq>t \n\\<Longrightarrow> t\\<le>T_max \n\\<Longrightarrow> ta\\<le>T_max\n\\<Longrightarrow> step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>' \n     \\<Longrightarrow> own\\<^sub>W ms' loc \\<noteq> Some ta\"\n  apply (simp add:step_def)\n  apply(case_tac \"pc ms t\", simp_all add:abbr)\n  apply safe\n  apply (smt (z3) fun_upd_apply mstate.simps(17) mstate.surjective mstate.update_convs(1) mstate.update_convs(16) mstate.update_convs(17) option.sel)\n  apply(simp add:get_C_val_def FAAZ_def)\n  apply safe \n  apply simp+\n  apply(case_tac \"loc = the (n ms t)\", simp_all)\n  apply(case_tac \"CAS_succ ms t\", simp_all add:abbr)\n  apply(case_tac \"nondet_val ms t\", simp_all add:abbr)\n  apply(case_tac \"det ms t\", simp_all add:abbr)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all add:abbr)\n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all add:abbr)\n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all add:abbr)\n  by(case_tac \"reg ms t = Suc 0\", simp_all add:abbr)\n\n\nlemma preservation_of_observation_inv_ms:\n  assumes \"preCond ms ps \\<sigma> (pc ms t) t\"\n  and \"t \\<le> T_max\"\n  and \"step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>'\"    \n  and \"general_structure ms\"\n  and \"observation_inv_ms ms\"\n  and \"main_inv_2 ms ps\"\n  and \"main_inv_3 ms ps\"\n  and \"observation_inv_sig ms ps \\<sigma>\"\n  and \"own\\<^sub>W_n_by_t_imp ms\"\n  and \"general_structure ms\"\n  and \"psem_rules ps\"\nshows \"observation_inv_ms ms'\"\n  using assms unfolding observation_inv_ms_def apply simp apply clarify\n  apply(case_tac \"ta \\<noteq> t\")\n  (*ta\\<noteq>t*)\n  apply(simp add:step_def preCond_def)\n  apply(case_tac \"pc ms t\", simp_all add:abbr)\n  apply clarsimp \n  apply blast\n  apply blast\n  apply blast \n  apply clarsimp \n  apply (meson own\\<^sub>W_n_by_t_imp_def)\n  apply (meson own\\<^sub>W_n_by_t_imp_def)\n  apply (meson own\\<^sub>W_n_by_t_imp_def)\n  apply (meson own\\<^sub>W_n_by_t_imp_def)\n  (*FAAZ, ta\\<noteq>t*) defer\n  apply(simp add:Wcap_def own\\<^sub>W_n_by_t_imp_def general_structure_lemmas Rcap_def)\n  sledgehammer\n\n\n\n\n\n\n\n  sorry\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nlemma own\\<^sub>W_imp_not_free:\n  assumes \"main_inv ms ps\"\n  and \"own\\<^sub>W ms loc \\<noteq> None\"\nshows \"\\<not>isfree_addr loc ps\"\n  using assms apply (simp_all add:main_inv_def)\n  by blast\n\n\n\n\nlemma global_sig_invariant_preserved:\n  \"con_assms ps \\<Longrightarrow>\nmain_inv ms ps\\<Longrightarrow>\nobservation_inv_ms ms\\<Longrightarrow>\nmain_inv_2 ms ps\\<Longrightarrow> \nmain_inv_3 ms ps\\<Longrightarrow> \nobservation_inv_sig ms ps \\<sigma>\\<Longrightarrow> \nown\\<^sub>W_n_by_t_imp ms\\<Longrightarrow> \ngeneral_structure ms\\<Longrightarrow> \npsem_rules ps\\<Longrightarrow> \nt \\<le> T_max\\<Longrightarrow>\nstep ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>'\\<Longrightarrow>\npreCond ms ps \\<sigma> (pc ms t) t\\<Longrightarrow>\nobservation_inv_sig ms' ps' \\<sigma>'\n\"\n  unfolding observation_inv_sig_def step_def preCond_def\n  apply(case_tac \"pc ms t\", simp_all add:abbr covered_v_def con_assms_def main_inv_def observation_inv_ms_def)\n  apply(simp_all add:own\\<^sub>W_n_by_t_imp_def general_structure_lemmas)\n  apply meson\n  apply meson\n  apply meson\n  apply (metis domI domIff)  apply clarsimp sledgehammer\n  apply (metis domI domIff)\n  apply (metis domI domIff)\n  apply meson\n  apply meson\n  apply meson\n\n\n\n\n\n\n\n\n\n\n\n\nlemma ms_observation_lemma_Correctness_supp_4:\n  assumes \"preCond ms ps \\<sigma> (pc ms t) t\"\n  and \"t \\<le> T_max\"\n  and \"ta \\<le> T_max\"\n  and \"step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>'\"    \n  and \"general_structure ms\"\n  and \"ta \\<noteq> t\" \n  and \"own\\<^sub>W ms loc = Some ta\"\n  and \"main_inv ms\"\n  and \"main_inv_2 ms ps\"\n  and \"main_inv_3 ms ps\"\n  and \"observation_inv_ms ms\"\nshows \"own\\<^sub>W ms' loc = Some ta\"\n  using assms \n  apply(subgoal_tac \"\\<not>isfree_addr loc ps\") prefer 2\n  apply (metis option.distinct(1) own_imp_1) apply (simp_all)\n  apply(simp add:step_def)\n  apply(simp add:preCond_def)\n  apply(case_tac \"pc ms t\", simp_all)\n  apply(simp_all add:abbr)\n  apply clarify\n  apply(simp_all add:general_structure_lemmas)\n  apply(subgoal_tac \"loc\\<noteq>loca\", simp_all add:Rcap_def Wcap_def) \n  apply clarsimp apply(simp add:get_C_val_def)\n  apply(simp add:FAAZ_def)\n  apply(simp add: visible_writes_def)  apply clarsimp \n  apply clarsimp \n  apply(simp add: visible_writes_def)   apply clarsimp\n  apply(case_tac \"(snd (CAS t (a, b) (the (s ms t)) (the (n ms t)) \\<sigma> ts'))\", simp_all)\n  apply (metis option.sel)\n  apply(case_tac \"CAS_succ ms t\", simp_all add:abbr) apply clarsimp\n  apply(case_tac \"nondet_val ms t\", simp_all add:abbr) apply clarsimp\n  apply(case_tac \"det ms t\", simp_all add:abbr observation_inv_ms_def) apply clarify\n  apply clarsimp\n  sorry\n\n\n\n\n\nlemma FAAZ_wm_prelim1:\n  assumes \"ms \\<sigma> s:=\\<^sup>FC t ms' \\<sigma>'\"\n  and \"wfs \\<sigma>\"\n  and \"cvd[C,valaa] \\<sigma>\"\nshows \"cvd[C,valaa] \\<sigma>'\"\n  using assms apply (simp add:get_C_val_def FAAZ_def) apply(clarify) \n  apply(simp add:update_trans_def covered_v_def Let_def rev_app_def add_cv_def update_mods_def update_modView_def\n      update_thrView_def)\n  apply(unfold writes_on_def value_def lastWr_def) apply safe\n  apply (metis fst_conv var_def)\n  apply (metis fst_conv var_def visible_var)\n  apply (metis fst_conv var_def visible_var)\n  apply (metis fst_conv var_def)\n  apply(simp add:visible_writes_def tst_def var_def valid_fresh_ts_def)\n  apply(unfold writes_on_def value_def lastWr_def wfs_def var_def) apply safe\n  (*ts; is max, nempty \\<and> finite*) defer\n  apply auto[1]    \n  apply(simp) apply(intro conjI)\n  apply (meson subset_iff visible_writes_in_writes)\n  apply presburger\n  apply (metis fst_conv)\n  apply (metis fst_conv var_def visible_var)\n  apply (metis fst_conv var_def visible_var)\n  apply (metis fst_conv)\n  (*ts; is max*) defer    \n  apply(simp) apply(intro conjI)\n  apply (meson subset_iff visible_writes_in_writes)\n  apply presburger\n  sorry\n\nlemma FAAZ_wm_prelim2:\n  assumes \"ms \\<sigma> s:=\\<^sup>FC t ms' \\<sigma>'\"\n  and \"wfs \\<sigma>\"\n  and \"\\<exists>val. cvd[C,val] \\<sigma> \\<and> val\\<noteq> loca\"\nshows \"\\<exists>val. cvd[C,val] \\<sigma>' \\<and> val\\<noteq> loca\"\n  using assms\n  using FAAZ_wm_prelim1 by blast\n\nlemma FAAZ_wm_prelim3:\n  assumes \"ms \\<sigma> s:=\\<^sup>FC t ms' \\<sigma>'\"\n  and \"wfs \\<sigma>\"\n  and \"cvd[C,valaa] \\<sigma>\"\n  and \"valaa \\<noteq> loca\"\nshows \"\\<exists>val. cvd[C,val] \\<sigma>' \\<and> val\\<noteq> loca\"\n  using assms \n  using FAAZ_wm_prelim1 by blast\n\nlemma FAAZ_wm_prelim4:\n  assumes \"ms \\<sigma> s:=\\<^sup>FC t ms' \\<sigma>'\"\n  and \"wfs \\<sigma>\"\n  and \"observation_inv_sig ms ps \\<sigma>\"\n  and \"psem_rules ps \"\n  and \"general_structure ms\"\nshows \"observation_inv_sig ms' ps' \\<sigma>'\"\n  using assms \n  apply(simp add:observation_inv_sig_def general_structure_lemmas)\n  apply clarify\n  apply(intro conjI impI)\n  apply(case_tac \"ta = t\")\n  apply(subgoal_tac \"own\\<^sub>W ms loc = Some ta \\<longrightarrow> own\\<^sub>W ms' loc = Some ta\", simp_all)\n  apply(simp add:get_C_val_def)\n  sledgehammer\n\n\n\n\nlemma sigma_observation_lemma_Correctness:\n  assumes \"preCond ms ps \\<sigma> (pc ms t) t\"\n  and \"wfs \\<sigma>\"\n  and \"psem_rules ps\"\n  and \"t \\<le> T_max\"\n  and \"step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>'\"    \n  and \"general_structure ms\"\n  and \"observation_inv_ms ms\"\n  and \"observation_inv_sig ms ps \\<sigma>\"\n  and \"main_inv ms\"\n  and \"main_inv_2 ms ps\"\n  and \"main_inv_3 ms ps\"\nshows \"observation_inv_sig ms' ps' \\<sigma>'\"\n  using assms apply (simp_all)\n  apply(simp add:preCond_def RCU.step_def)\n  apply(case_tac \"pc ms t\", simp_all add:abbr)\n  apply(simp add:covered_v_def general_structure_lemmas )\n  apply clarify\n  apply(unfold observation_inv_sig_def observation_inv_ms_def)\n  apply clarify apply(simp_all)\n  apply(case_tac \"isfree_addr loc ps\", simp_all)\n  apply blast apply clarify\n  apply(case_tac \"isfree_addr loc ps\", simp_all)\n  apply clarify\n  apply(case_tac \"isfree_addr loc ps\", simp_all)\n  apply clarify apply(simp add:general_structure_lemmas)\n  apply(case_tac \"loc = loca\", simp_all) \n  apply metis \n  apply meson \n  defer (*rcu_enter*)\n  defer (*rcu_exit*)\n  defer (*rcu_enter*)\n  apply clarify\n  apply(intro conjI impI)\n  using FAAZ_wm_prelim2 [where ms = ms and ms' = ms' and \\<sigma> = \\<sigma> and \\<sigma>' = \\<sigma>' and t=t and loca=loc]\n  apply simp\n  apply(clarsimp)\n  apply(case_tac \"t \\<le> T_max \\<and> own\\<^sub>W ms loca = Some t\", simp_all)\n  apply (meson FAAZ_wm_prelim1)\n  apply(case_tac \"((\\<forall>x. (\\<forall>a. x = {a} \\<longrightarrow> (\\<forall>b. (a, b) \\<notin> ran (A ps))) \\<or> loca \\<notin> x))\")\n  apply (metis FAAZ_wm_prelim1)\n  apply clarify\n  sledgehammer\n\n\n  apply metis\n  apply(simp add:general_structure_lemmas)\n  sledgehammer\n\n\n  by (metis (full_types))+\n\n\n\nlemma ms_observation_lemma_Correctnesssss:\n  assumes \"preCond ms ps \\<sigma> (pc ms t) t\"\n  and \"wfs \\<sigma>\"\n  and \"psem_rules ps\"\n  and \"t \\<le> T_max\"\n  and \"step ms ps \\<sigma> (pc ms t) t ms' ps' \\<sigma>'\"    \n  and \"general_structure ms\"\n  and \"observation_inv_ms ms ps\"\n  and \"observation_inv_sig ms ps \\<sigma>\"\n  and \"main_inv ms\"\n  and \"main_inv_2 ms ps\"\n  and \"main_inv_3 ms ps\"\n  and \"cvd[C,vala] \\<sigma>\"\nshows \"observation_inv_ms ms' ps'\"\n  using assms apply (simp_all) \n  apply(simp add:preCond_def)\n  apply(case_tac \"pc ms t\", simp_all)\n  apply(simp add:covered_v_def general_structure_lemmas)\n  apply clarify\n  apply(unfold observation_inv_sig_def observation_inv_ms_def)\n  apply(subgoal_tac \"\\<forall>loc t. t\\<le>T_max \\<and> own\\<^sub>W ms' loc  = Some t\n  \\<longrightarrow> loc\\<in>(detaddrs ms' t \\<union> s_and_n ms' t) \") \n  apply clarify\n  apply(subgoal_tac \"loc \\<in> detaddrs ms ta\", simp add:detaddrs_def)\n  apply blast\n\n  sorry\n\n\n\n\n\n\n\n\n\n\n\nlemma main_invariant_Correctness:\n  assumes \"preCond ms ps \\<sigma> pcr t\"\n  and \"t \\<le> T_max\"\n  and \"main_inv ms\"\n  and \"main_inv_2 ms ps\"\n  and \"pcr = pc ms t\"\n  and \"step ms ps \\<sigma> pcr t ms' ps' \\<sigma>'\"    \n  and \"general_structure ms\"\n  and \"pcr' = pc ms' t\"\n  and \"observation_inv_ms ms ps\"\n  and \"observation_inv_sig ms ps \\<sigma>\"\nshows \"main_inv ms'\"\n  using assms apply (simp add:preCond_def step_def)\n  apply(case_tac[!] \"pc ms t\", simp_all add:abbr) \n  apply(intro allI)\n  apply(intro impI) apply(elim conjE exE) apply(simp add:isfree_addr_def) \n  apply (metis insert_not_empty option.sel) \n  apply(intro allI)\n  apply(simp add:general_structure_lemmas)\n  apply metis\n  defer (*I8*)\n  defer (*I9*)\n  defer (*I11*)\n  apply(simp add:general_structure_lemmas)\n  apply metis \n  apply(case_tac \"CAS_succ ms t\", simp_all)\n  apply(simp_all add:abbr)\n  defer (*R2*)\n  apply(simp add:general_structure_lemmas) apply(case_tac \"nondet_val ms t = True\", simp_all)\n  apply(simp_all add:abbr)\n  apply(case_tac \"det ms t \\<noteq> []\", simp_all) \n  apply(simp_all add:abbr)\n  apply(simp add:general_structure_lemmas)\n  apply (metis Diff_empty Diff_insert0 insert_absorb insert_iff)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all)\n  apply(simp_all add:abbr)\n  defer (*S3*)\n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all)\n  apply(simp_all add:abbr)\n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all)\n  apply(simp_all add:abbr)\n  defer (*S6*)\n  apply(case_tac \"reg ms t = Suc 0\", simp_all)\n  apply(simp add:abbr)\n  apply(simp add:abbr)\n  apply(clarify) \n  apply(simp add:get_C_val_def) \n  apply(subgoal_tac \"(snd (FAAZ t (a, b) \\<sigma> ts')) \\<noteq> the(n ms ta)\", simp add:FAAZ_def) (*need this as pre_cond*)\n  \n        apply (metis option.sel)\n  defer\n  apply clarify\n  apply(subgoal_tac \"own\\<^sub>R ms (the(n ms ta)) = {ta}\") prefer 2\n  apply(simp add:general_structure_lemmas) \n  apply (metis option.sel)\n  apply(simp add:general_structure_lemmas)  \n  apply clarify\n  apply(case_tac \"snd (CAS t (a, b) (the (s ms t)) (the (n ms t)) \\<sigma> ts') \")\n  apply(subgoal_tac \"n_dec ms' t = False\") prefer 2\n  apply(simp add:general_structure_lemmas)\n  apply(simp add:general_structure_lemmas)  \n  apply (metis option.sel)\n  apply(simp add:general_structure_lemmas)  \n  apply (metis option.sel)                      \n  apply(simp add:general_structure_lemmas)  \n  apply clarify\n  apply(case_tac \"b\", simp_all) prefer 2 \n  apply (metis option.sel) \n  apply (metis option.sel)                     \n  apply(simp add:general_structure_lemmas)\n  apply clarify apply(simp add:names_2)\n  apply (metis option.sel)                  \n  apply(simp add:general_structure_lemmas)\n  apply clarify\n  apply(case_tac \"v\", simp_all) prefer 2\n  apply (metis option.sel)\n  apply (metis option.sel)\n  apply(simp add: visible_writes_def) \n  apply(simp add:observation_lemma_def general_structure_lemmas covered_v_def FAAZ_def)  \n  apply(simp add:Wcap_def)\n  by (metis option.sel)\n  \n\n\n\n\nlemma main_invariant_2_Correctness:\n  assumes \"preCond ms ps \\<sigma> pcr t\"\n  and \"t \\<le> T_max\"\n  and \"main_inv ms\"\n  and \"main_inv_2 ms ps\"\n  and \"pcr = pc ms t\"\n  and \"step ms ps \\<sigma> pcr t ms' ps' \\<sigma>'\"       (*and \"allocated_n_addr ms ps \"     seems redundant*)\n  and \"general_structure ms\"\n  and \"pcr' = pc ms' t\"\n  and \"observation_lemma \\<sigma> ms\"\nshows \"main_inv_2 ms' ps'\"\n  using assms apply simp\n  apply(simp add:step_def) apply(case_tac \"pc ms t\", simp_all add:abbr)     \n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(elim conjE exE, intro allI impI)\n  apply(simp add:names_2)    \n  (*FAAZ*)\n  defer     \n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(elim conjE exE, intro allI impI)\n  apply(simp add:names_2)       \n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(elim conjE exE, intro allI impI)\n  apply(simp add:names_2)  \n  apply(case_tac \"snd (CAS t (a, b) (the (s ms t)) y \\<sigma> ts') \") prefer 2\n  apply simp\n  apply simp\n  apply(case_tac \"CAS_succ ms t\", simp_all)\n  apply(simp add:general_structure_lemmas preCond_def abbr)\n  apply(simp add:general_structure_lemmas preCond_def abbr)\n  apply(simp add:general_structure_lemmas preCond_def abbr)\n  apply(elim conjE exE, intro allI impI)\n  apply(simp add:names_2)       \n  apply(case_tac \"nondet_val ms t\", simp_all)\n  apply(simp add:general_structure_lemmas preCond_def abbr)\n  apply(simp add:general_structure_lemmas preCond_def abbr)\n  apply(case_tac \"det ms t \\<noteq> []\", simp_all)\n  apply(simp add:general_structure_lemmas preCond_def abbr)\n  apply(simp add:general_structure_lemmas preCond_def abbr)\n  apply(simp add:general_structure_lemmas preCond_def abbr)\n  apply(elim conjE exE, intro allI impI)\n  apply(simp add:names_2)       \n  (*show that own\\<^sub>R ms i \\<in> det ms t \\<longrightarrow> at some point is only held by {t}*)\n  defer\n  apply(simp add:general_structure_lemmas preCond_def abbr)\n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all)\n  apply(simp add:general_structure_lemmas preCond_def abbr)\n  apply(simp add:general_structure_lemmas preCond_def abbr)\n  apply(elim conjE exE, intro allI impI)\n  apply(simp add:names_2)     \n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all)\n  apply(simp add:general_structure_lemmas preCond_def abbr)\n  apply(simp add:general_structure_lemmas preCond_def abbr)\n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all)\n  apply(simp add:general_structure_lemmas preCond_def abbr)\n  apply(simp add:general_structure_lemmas preCond_def abbr)\n  apply(simp add:general_structure_lemmas preCond_def abbr)\n  apply(elim conjE exE, intro allI impI)\n  apply(simp add:names_2)         \n  apply(case_tac \"reg ms t = Suc 0\", simp_all)\n  apply(simp add:general_structure_lemmas preCond_def abbr)\n  apply(simp add:general_structure_lemmas preCond_def abbr)\n  (*FAAZ*)\n  apply(simp add:general_structure_lemmas preCond_def abbr)\n  apply(elim conjE exE, intro allI impI)\n  apply(simp add:names_2)   \n   defer\n  \n  sledgehammer\n  oops\n\n\n\nlemma General_Structure_Correctness:\n  assumes \"preCond ms ps \\<sigma> pcr t\"\n  and \"t \\<le> T_max\"\n  and \"main_inv ms\"\n  and \"main_inv_2 ms ps\"\n  and \"pcr = pc ms t\"\n  and \"step ms ps \\<sigma> pcr t ms' ps' \\<sigma>'\"       \n  and \"general_structure ms\"\n  and \"pcr' = pc ms' t\"\n  and \"observation_lemma \\<sigma> ms\"\n  and \"\\<exists>prov loc. prov \\<notin> dom(A ps) \\<and> isfree_addr loc ps\"\nshows \"general_structure ms'\"\n  using assms apply simp\n  apply(simp add:step_def) apply(case_tac \"pc ms t\", simp_all add:abbr)     \n  apply(simp_all add:general_structure_lemmas preCond_def names_2)\n  apply metis\n  apply metis \n  defer\n  apply metis \n  defer\n  defer\n  defer\n  apply metis\n  defer\n  defer\n  apply(elim conjE exE)\n  apply(case_tac \"b\", simp_all)\n  apply(case_tac \"nondet_val ms t\", simp_all add:abbr)\n  apply(case_tac \"det ms t = []\", simp_all add:abbr)\n  defer\n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all add:abbr)\n  defer\n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all add:abbr)\n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all add:abbr)\n  defer\n  apply(case_tac \"reg ms t = Suc 0\", simp_all add:abbr)\n  prefer 2\n  apply(simp add:FAAZ_def)\n  apply(simp add:allocated_addresses_def observation_lemma_def)\n  apply (metis option.sel)\n  apply(intro conjI impI) prefer 2\n  apply clarify\n  apply(case_tac \"ta = t\", simp_all) prefer 2\n  apply (metis option.sel) apply clarify\n  apply(intro conjI impI)\n  apply(subgoal_tac \"y \\<notin> alloc_addrs ps\") prefer 2\n  apply blast\n  apply(subgoal_tac \"the (s ms t) \\<in> alloc_addrs ps\") \n  apply blast\n  apply(subgoal_tac \"allocated_addresses ms ps\", simp_all add:allocation_lemmas)\n  oops\n\n\n\n\nlemma Global_Correctness:\n  assumes \"preCond ms ps \\<sigma> pcr\\<^sub>t t\"\n  and \"preCond ms ps \\<sigma> pcr\\<^sub>t\\<^sub>' t'\"  \n  and \"pcr\\<^sub>t = pc ms t\"\n  and \"pcr\\<^sub>t\\<^sub>' = pc ms t'\"\n  and \"t \\<noteq> t'\"\n  and \"main_inv ms\"\n  and \"main_inv_2 ms ps\"\n  and \"step ms ps \\<sigma> pcr\\<^sub>t t ms' ps' \\<sigma>'\"       (*and \"allocated_n_addr ms ps \"     seems redundant*)\n  and \"general_structure ms\"\n  and \"pcr' = pc ms' t\"\nshows \"preCond ms' ps' \\<sigma>' pcr\\<^sub>t\\<^sub>' t'\"\n  using assms apply simp\n  apply(simp add:step_def) apply(case_tac \"pc ms t\", simp_all add:abbr)     \n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2) \n  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis        \n \n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)  \n \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis        \n  \n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)\n \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis  \n\n  (*existential complication*) defer\n  apply(simp add:general_structure_lemmas preCond_def) \n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)  \n \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis        \n  \n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)\n \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis  \n  \n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)\n \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis  \n  \n  (*existential complication, FAAZ*) defer\n  (*weak memory read s*)defer\n  \n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)\n \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis\n  \n  (*existential complication, CAS*)defer\n   \n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)  \n \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis\n   \n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)  \n \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis\n   \n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)  \n \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis\n\n  apply(case_tac \"CAS_succ ms t\", simp_all)\n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)  \n \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis\n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis\n\n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)\n \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis \n  \n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(elim conjE impE exE)\n  apply(case_tac \"b\", simp_all)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2) \n \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis \n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2) \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis\n\n  apply(case_tac \"nondet_val ms t\", simp_all)\n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)\n  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis\n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis\n  \n  apply(case_tac \"det ms t \\<noteq> []\", simp_all)\n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)\n  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis\n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis\n  \n  (*existential complication, kill(x)*)defer\n  \n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)\n  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis\n  \n  apply(case_tac \"CTRsync\\<^sub>1 ms t < T_max\", simp_all)\n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)\n  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis\n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis\n  \n  (*existential complication, (rcu_0 + CTRsync\\<^sub>1) weak memory read*)defer\n  \n  apply(case_tac \"CTRsync\\<^sub>2 ms t < T_max\", simp_all)\n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)\n  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis\n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis\n  \n  apply(case_tac \"r ms t (CTRsync\\<^sub>2 ms t) = 0\", simp_all)\n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)\n  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis\n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis\n  \n  defer\n\n  apply(case_tac \"reg ms t = Suc 0\", simp_all) \n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)\n  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis\n  apply(simp add:general_structure_lemmas preCond_def)\n  apply(case_tac \"pc ms t'\", simp_all add:abbr names_2)\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis\n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis    apply metis  \n  apply metis   apply metis    apply metis    apply metis    apply metis\n\n(*weak memory guarantees needed, I think (maybe I'm wrong)*)\n  oops\n\n\n\n\n\n\n\n(*lemma test2:\n  assumes \"wfs \\<sigma>\"\n  and \"get_C_val ms \\<sigma> t ms' \\<sigma>'\"\n  and \"cvd[C,u] \\<sigma>\"\nshows \"cvd[C,u] \\<sigma>'\"\n  using assms apply (simp add:get_C_val_def FAAZ_def) apply(clarify) \n  apply(simp add:update_trans_def covered_v_def Let_def rev_app_def add_cv_def update_mods_def update_modView_def\n      update_thrView_def)\n  apply(unfold writes_on_def value_def lastWr_def) apply safe\n  apply (metis fst_conv var_def)\n  apply (metis fst_conv var_def visible_var)\n  apply (metis fst_conv var_def visible_var)\n  apply (metis fst_conv var_def)\n  apply(simp add:visible_writes_def tst_def var_def valid_fresh_ts_def)\n  apply(unfold writes_on_def value_def lastWr_def wfs_def var_def) apply safe\n  (*ts; is max, nempty \\<and> finite*) defer\n  apply auto[1]    \n  apply(simp) apply(intro conjI)\n  apply (meson subset_iff visible_writes_in_writes)\n  apply presburger\n  apply (metis fst_conv)\n  apply (metis fst_conv var_def visible_var)\n  apply (metis fst_conv var_def visible_var)\n  apply (metis fst_conv)\n  (*ts; is max*) defer    \n  apply(simp) apply(intro conjI)\n  apply (meson subset_iff visible_writes_in_writes)\n  apply presburger\n  sorry*)\n\n\n\n\n          \n(*\nOWNERSHIP IDEAS:\n\n\n\\<forall>i. (i\\<in>addrs) \\<longleftrightarrow> (the(own\\<^sub>W ms i)=t)\n\n\nWe have to get to this stage after sync():\n\\<forall>s i j. (s\\<in>det\\<^sub>i \\<and> i\\<noteq>j) \\<longrightarrow> T\\<^sub>j \\<notin> own\\<^sub>R(s)\n\nbecause:\n T\\<^sub>j \\<notin> own\\<^sub>R(s) \\<longrightarrow> T\\<^sub>j \\<noteq> own\\<^sub>W(s)\n\nThis allows for pop() operation to guarantee that no thread could allocate n:=newint as n:=s\nunless:\n\nown\\<^sub>W(s) = T\\<^sub>i \\<and> own\\<^sub>R(s) = { T\\<^sub>i }\npop()\nown\\<^sub>W(s) = None \\<and> own\\<^sub>R(s) = {}\n\n\n(Call threads t, t...)\n\nThis is absolutely guaranteed if sync() occurs deterministically:\n\\<forall>j. j<N \\<longrightarrow> |det\\<^sub>j| \\<le> 1\n\\<forall>s j i. (s\\<in>det\\<^sub>j \\<and> i\\<noteq>j \\<and> i<CTRsync\\<^sub>1(j) \\<and> r[i] = 0) \\<longrightarrow> T\\<^sub>i \\<notin> own\\<^sub>R(s)     (backward sync)\n\\<forall>s j i. (s\\<in>det\\<^sub>j \\<and> i\\<noteq>j \\<and> i<CTRsync\\<^sub>2(j)) \\<longrightarrow> T\\<^sub>i \\<notin> own\\<^sub>R(s)                (backward sync)\n\\<forall>s j i. (s\\<in>det\\<^sub>j \\<and> i\\<noteq>j \\<and> CTRsync\\<^sub>2(j) < N \\<and> i = CTRsync\\<^sub>2(j) \\<and> [rcu[i] \\<approx> 0]\\<^sub>j) \\<longrightarrow> T\\<^sub>i \\<notin> own\\<^sub>R(s)                (backward sync)\nNo thread i. (j\\<noteq>i) can allocate n:=newint to have address s, since own\\<^sub>W(s) = T\\<^sub>j\nIf a thread i attemps to read s=C while in rcu[i] (weak memory), this can only happen if:\nCTRsync\\<^sub>1 = N \\<and> r[i] = 1 \\<and> i\\<ge>CTRsync\\<^sub>2\nIn that case, it should be impossible for CAS\\<^sub>j to succeed, resulting in eventual rcu_exit() by j with no swap,\n(no matter how many times j performs rcu_enter()/rcu_exit()       ***careful in WM setting - fence*** )\nwhich should cause {while rcu[j]} to terminate and perform CTRsync\\<^sub>2++\n\nNondeterministically:\n\\<forall>j. j<N \\<longrightarrow> |det\\<^sub>j| \\<ge> 0\n\\<forall>s j i. (s\\<in>det\\<^sub>j \\<and> i\\<noteq>j \\<and> i<CTRsync\\<^sub>2) \\<longrightarrow> T\\<^sub>i \\<notin> own\\<^sub>R(s)                (backward sync)\n\\<forall>s j i. (s\\<in>det\\<^sub>j \\<and> i\\<noteq>j \\<and> i<CTRsync\\<^sub>1 \\<and> r[i] = 0) \\<longrightarrow> T\\<^sub>i \\<notin> own\\<^sub>R(s)     (backward sync)\n\nonly requirement is that own\\<^sub>W(s) = T\\<^sub>j to limit allocation of n:=newint to s by T\\<^sub>i\nT\\<^sub>j faces the same problem, since n:=newint, where newint=s, requires own\\<^sub>W(s) = Null.\n\n\n\nREASONS FOR OWNERSHIP OVER NO-OWNERSHIP:\nlimited in Deterministic setting.\nno requirement of insert(det\\<^sub>j) to track order of insertion.\nease of visualisation when n:=newint happens\n\n\npop of A\\<^sub>2 doesnt occur.\n*)\n\n(*definition \"FAAZ t w \\<sigma> ts' \\<equiv> \n        (update_trans t w (value \\<sigma> w) \\<sigma> ts', value \\<sigma> w)\"*)\n\n\n\n", "meta": {"author": "MSemenyuk", "repo": "PhD_Isabelle", "sha": "179f5d346a721b15940a271323e3487f4ea51338", "save_path": "github-repos/isabelle/MSemenyuk-PhD_Isabelle", "path": "github-repos/isabelle/MSemenyuk-PhD_Isabelle/PhD_Isabelle-179f5d346a721b15940a271323e3487f4ea51338/Treiber Stack C11/RCU (Brijesh Dongol's conflicted copy 2022-11-01).thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6261241772283035, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.2862243507044631}}
{"text": "(*  Title:       BDD\n    Author:      Veronika Ortner and Norbert Schirmer, 2004\n    Maintainer:  Norbert Schirmer,  norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*\nLevellistProof.thy\n\nCopyright (C) 2004-2008 Veronika Ortner and Norbert Schirmer\nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection \\<open>Proof of Procedure Levellist\\<close>\ntheory LevellistProof imports ProcedureSpecs Simpl.HeapList begin\n\nhide_const (open) DistinctTreeProver.set_of tree.Node tree.Tip\n\n\n\n(*a well formed levellist is a list that contains all nodes with variable\ni on position i\nbecause the elements of levellist can contain old elements before the call of Levellist,\nsubdag_eq t pt can not be postulated for all elements of the sublists. One has to make\nshure that the initial call of Levellist is parameterized with a levellist with empty sublists.\nOtherwise some problems could arise in the call of Reduce!\n(\\<exists> ptt. (Dag pt low high ptt \\<and> subdag_eq (Node lt p rt) ptt \\<and> pt\\<rightarrow>var = i))\nconsts wf_levellist :: \"dag \\<Rightarrow> ref list list \\<Rightarrow> ref list list \\<Rightarrow>\n                        (ref \\<Rightarrow> nat) \\<Rightarrow> (ref \\<Rightarrow> ref) \\<Rightarrow> (ref \\<Rightarrow> ref) \\<Rightarrow> bool\"\ndefs wf_levellist_def: \"wf_levellist t levellist_old levellist_new var low high \\<equiv>\ncase t of Tip \\<Rightarrow> levellist_old = levellist_new\n| (Node lt p rt) \\<Rightarrow>\n  (\\<forall> q. q \\<in> set_of t \\<longrightarrow> q \\<in> set (levellist_new ! (q\\<rightarrow>var))) \\<and>\n  (\\<forall> i \\<le> p\\<rightarrow>var. (\\<exists> prx. (levellist_new ! i) = prx@(levellist_old ! i)\n                       \\<and> (\\<forall> pt \\<in> set prx. pt \\<in> set_of t \\<and> pt\\<rightarrow>var = i))) \\<and>\n  (\\<forall> i. (p\\<rightarrow>var) < i \\<longrightarrow> (levellist_new ! i) = (levellist_old ! i)) \\<and>\n  (length levellist_new = length levellist_old)\"\n*)\n\n\nlemma all_stop_cong: \"(\\<forall>x. P x) = (\\<forall>x. P x)\"\n  by simp\n\nlemma Dag_RefD:\n  \"\\<lbrakk>Dag p l r t; p\\<noteq>Null\\<rbrakk> \\<Longrightarrow>\n    \\<exists>lt rt. t=Node lt p rt \\<and> Dag (l p) l r lt \\<and> Dag (r p) l r rt\"\n  by simp\n\nlemma Dag_unique_ex_conjI:\n  \"\\<lbrakk>Dag p l r t;   P t\\<rbrakk> \\<Longrightarrow> (\\<exists>t. Dag p l r t \\<and> P t)\"\n  by simp\n\n(* FIXME: To BinDag *)\nlemma dag_Null [simp]: \"dag Null l r = Tip\"\n  by (simp add: dag_def)\n\ndefinition first:: \"ref list \\<Rightarrow> ref\" where\n\"first ps = (case ps of [] \\<Rightarrow> Null | (p#rs) \\<Rightarrow> p)\"\n\nlemma first_simps [simp]:\n \"first [] = Null\"\n \"first (r#rs) = r\"\nby (simp_all add: first_def)\n\ndefinition Levellist:: \"ref list \\<Rightarrow> (ref \\<Rightarrow> ref) \\<Rightarrow> (ref list list) \\<Rightarrow> bool\" where\n\"Levellist hds next ll \\<longleftrightarrow> (map first ll = hds) \\<and>\n                         (\\<forall>i < length hds. List (hds ! i) next (ll!i))\"\n\nlemma Levellist_unique:\n  assumes ll: \"Levellist hds next ll\"\n  assumes ll': \"Levellist hds next ll'\"\n  shows \"ll=ll'\"\nproof -\n  from ll have \"length ll = length hds\"\n    by (clarsimp simp add: Levellist_def)\n  moreover\n  from ll' have \"length ll' = length hds\"\n    by (clarsimp simp add: Levellist_def)\n  ultimately have leq: \"length ll = length ll'\" by simp\n  show ?thesis\n  proof (rule nth_equalityI [OF leq, rule_format])\n    fix i\n    assume \"i < length ll\"\n    with ll ll'\n    show \"ll!i = ll'!i\"\n      apply (clarsimp simp add: Levellist_def)\n      apply (erule_tac x=i in allE)\n      apply (erule_tac x=i in allE)\n      apply simp\n      by (erule List_unique)\n  qed\nqed\n\nlemma Levellist_unique_ex_conj_simp [simp]:\n\"Levellist hds next ll \\<Longrightarrow> (\\<exists>ll. Levellist hds next ll \\<and> P ll) = P ll\"\nby (auto dest: Levellist_unique)\n\n\nlemma in_set_concat_idx:\n  \"x \\<in> set (concat xss) \\<Longrightarrow> \\<exists>i < length xss. x \\<in> set (xss!i)\"\napply (induct xss)\napply  simp\napply clarsimp\napply (erule disjE)\napply  (rule_tac x=0 in exI)\napply  simp\napply auto\ndone\n\ndefinition wf_levellist :: \"dag \\<Rightarrow> ref list list \\<Rightarrow> ref list list \\<Rightarrow>\n                       (ref \\<Rightarrow> nat) \\<Rightarrow> bool\" where\n\"wf_levellist t levellist_old levellist_new var =\n(case t of Tip \\<Rightarrow> levellist_old = levellist_new\n| (Node lt p rt) \\<Rightarrow>\n  (\\<forall> q. q \\<in> set_of t \\<longrightarrow> q \\<in> set (levellist_new ! (var q))) \\<and>\n  (\\<forall> i \\<le> var p. (\\<exists> prx. (levellist_new ! i) = prx@(levellist_old ! i)\n                       \\<and> (\\<forall> pt \\<in> set prx. pt \\<in> set_of t \\<and> var pt = i))) \\<and>\n  (\\<forall> i. (var p) < i \\<longrightarrow> (levellist_new ! i) = (levellist_old ! i)) \\<and>\n  (length levellist_new = length levellist_old))\"\n\nlemma wf_levellist_subset:\n  assumes wf_ll: \"wf_levellist t ll ll' var\"\n  shows \"set (concat ll') \\<subseteq>  set (concat ll) \\<union> set_of t\"\nproof (cases t)\n  case Tip with wf_ll show ?thesis by (simp add: wf_levellist_def)\nnext\n  case (Node lt p rt)\n  show ?thesis\n  proof -\n    {\n      fix n\n      assume \"n \\<in> set (concat ll')\"\n      from in_set_concat_idx [OF this]\n      obtain i where i_bound: \"i < length ll'\" and n_in: \"n \\<in> set (ll' ! i)\"\n        by blast\n      have \"n \\<in> set (concat ll) \\<union> set_of t\"\n      proof (cases \"i \\<le> var p\")\n        case True\n        with wf_ll obtain prx where\n          ll'_ll: \"ll' ! i = prx @ ll ! i\" and\n          prx: \"\\<forall>pt \\<in> set prx. pt \\<in> set_of t\"  and\n          leq: \"length ll' = length ll\"\n          apply (clarsimp simp add: wf_levellist_def Node)\n          apply (erule_tac x=\"i\" in allE)\n          apply clarsimp\n          done\n        show ?thesis\n        proof (cases \"n \\<in> set prx\")\n          case True\n          with prx have \"n \\<in> set_of t\"\n            by simp\n          thus ?thesis by simp\n        next\n          case False\n          with n_in ll'_ll\n          have \"n \\<in> set (ll ! i)\"\n            by simp\n          with i_bound leq\n          have \"n \\<in> set (concat ll)\"\n            by auto\n          thus ?thesis by simp\n        qed\n      next\n        case False\n        with wf_ll obtain \"ll'!i = ll!i\" \"length ll' = length ll\"\n          by (auto simp add: wf_levellist_def Node)\n        with n_in i_bound\n        have \"n \\<in> set (concat ll)\"\n          by auto\n        thus ?thesis by simp\n      qed\n    }\n    thus ?thesis by auto\n  qed\nqed\n(*\n  next\n    show \"set (concat ll) \\<union> set_of t \\<subseteq> set (concat ll')\"\n    proof -\n      {\n        fix n\n        assume \"n \\<in> set (concat ll)\"\n        from in_set_concat_idx [OF this]\n        obtain i where i_bound: \"i < length ll\" and n_in: \"n \\<in> set (ll ! i)\"\n          by blast\n        with wf_ll\n        obtain \"n \\<in> set (ll' ! i)\" \"length ll = length ll'\"\n          apply (clarsimp simp add: wf_levellist_def Node)\n          apply (case_tac \"i \\<le> var p\")\n          apply  fastforce\n          apply fastforce\n          done\n        with i_bound have \"n \\<in> set (concat ll')\"\n          by auto\n      }\n      moreover\n      {\n        fix n\n        assume \"n \\<in> set_of t\"\n        with wf_ll obtain \"n \\<in> set (ll' ! var n)\" \"length ll' = length ll\"\n          by (auto simp add: wf_levellist_def Node)\n        with root\n\n            next\n\n          proof (cases prx)\n            case Nil\n            with ll'_ll i_bound leq n_in\n            have \"n \\<in> set (concat ll)\"\n              by auto\n            thus ?thesis by simp\n          next\n            case (Cons p prx')\n            show ?thesis\n\n              apply auto\n        *)\n\n\n(*\nconsts wf_levellist :: \"dag \\<Rightarrow> ref list \\<Rightarrow> ref list \\<Rightarrow>\n                        (ref \\<Rightarrow> ref) \\<Rightarrow> (ref \\<Rightarrow> ref) \\<Rightarrow>\n                       (ref \\<Rightarrow> nat) \\<Rightarrow> bool\"\ndefs wf_levellist_def:\n\"wf_levellist t levellist_old levellist_new next_old next_new var  \\<equiv>\ncase t of Tip \\<Rightarrow> levellist_old = levellist_new\n| (Node lt p rt) \\<Rightarrow>\n  (\\<forall> q. q \\<in> set_of t \\<longrightarrow> (\\<exists>ns. List (levellist_new ! (var q)) next_new ns \\<and>\n                                q \\<in> set ns)) \\<and>\n  (\\<forall> i \\<le> var p. (\\<exists>ns_new ns_old.\n                  List (levellist_new ! i) next_new ns_new \\<and>\n                  List (levellist_old ! i) next_old ns_old \\<and>\n                 (\\<exists> prx. ns_new = prx@ns_old\n                       \\<and> (\\<forall> pt \\<in> set prx. pt \\<in> set_of t \\<and> var pt = i)))) \\<and>\n  (\\<forall> i. (var p) < i \\<longrightarrow> (\\<exists>ns_new ns_old.\n                          List (levellist_new ! i) next_new ns_new \\<and>\n                          List (levellist_old ! i) next_old ns_old \\<and>\n                          ns_new = ns_old)) \\<and>\n  (length levellist_new = length levellist_old)\"\n*)\n\nlemma Levellist_ext_to_all: \"((\\<exists>ll. Levellist hds next ll \\<and> P ll) \\<longrightarrow> Q)\n       =\n       (\\<forall>ll. Levellist hds next ll \\<and> P ll \\<longrightarrow> Q)\"\napply blast\ndone\n\nlemma Levellist_length: \"Levellist hds p ll \\<Longrightarrow> length ll = length hds\"\n  by (auto simp add: Levellist_def)\n\n\nlemma map_update:\n  \"\\<And>i. i < length xss \\<Longrightarrow> map f (xss[i := xs]) = (map f xss) [i := f xs]\"\napply (induct xss)\napply  simp\napply (case_tac i)\napply  simp\napply simp\ndone\n\n\nlemma (in Levellist_impl) Levellist_spec_total':\nshows \"\\<forall>ll \\<sigma> t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\n        \\<lbrace>\\<sigma>. Dag \\<acute>p \\<acute>low \\<acute>high t \\<and> (\\<acute>p \\<noteq> Null \\<longrightarrow> (\\<acute>p\\<rightarrow>\\<acute>var) < length \\<acute>levellist) \\<and>\n             ordered t \\<acute>var \\<and> Levellist \\<acute>levellist \\<acute>next ll \\<and>\n             (\\<forall>n \\<in> set_of t.\n              (if \\<acute>mark n = \\<acute>m\n               then n \\<in> set (ll ! \\<acute>var n) \\<and>\n                    (\\<forall>nt p. Dag n \\<acute>low \\<acute>high nt \\<and> p \\<in> set_of nt\n                     \\<longrightarrow> \\<acute>mark p = \\<acute>m)\n               else n \\<notin> set (concat ll)))\\<rbrace>\n          \\<acute>levellist :== PROC Levellist (\\<acute>p, \\<acute>m, \\<acute>levellist)\n       \\<lbrace>\\<exists>ll'. Levellist \\<acute>levellist \\<acute>next ll' \\<and> wf_levellist t ll ll' \\<^bsup>\\<sigma>\\<^esup>var \\<and>\n        wf_marking t  \\<^bsup>\\<sigma>\\<^esup>mark \\<acute>mark \\<^bsup>\\<sigma>\\<^esup>m \\<and>\n        (\\<forall>p. p \\<notin> set_of t \\<longrightarrow> \\<^bsup>\\<sigma>\\<^esup>next p = \\<acute>next p)\n        \\<rbrace>\"\napply (hoare_rule HoareTotal.ProcRec1\n           [where r=\"measure (\\<lambda>(s,p). size (dag \\<^bsup>s\\<^esup>p \\<^bsup>s\\<^esup>low \\<^bsup>s\\<^esup>high))\"])\napply vcg\napply (rule conjI)\napply  clarify\napply  (rule conjI)\napply   clarify\napply   (clarsimp simp del: BinDag.set_of.simps split del: if_split)\ndefer\napply   (rule impI)\napply   (clarsimp simp del: BinDag.set_of.simps split del: if_split)\ndefer\napply   (clarsimp simp add: wf_levellist_def wf_marking_def) (* p=Null*)\napply (simp only: Levellist_ext_to_all )\nproof -\n  fix ll var low high mark \"next\" nexta p levellist m lt rt\n  assume pnN: \"p \\<noteq> Null\"\n  assume mark_p: \"mark p = (\\<not> m)\"\n  assume lt: \"Dag (low p) low high lt\"\n  assume rt: \"Dag (high p) low high rt\"\n  from pnN lt rt have Dag_p: \"Dag p low high (Node lt p rt)\" by simp\n  from Dag_p rt\n  have size_rt_dec: \"size (dag (high p) low high) < size (dag p low high)\"\n    by (simp only: Dag_dag) simp\n  from Dag_p lt\n  have size_lt_dec: \"size (dag (low p) low high) < size (dag p low high)\"\n    by (simp only: Dag_dag) simp\n  assume ll: \"Levellist levellist next ll\"\n\n  assume marked_child_ll:\n    \"\\<forall>n \\<in> set_of (Node lt p rt).\n        if mark n = m\n        then n \\<in> set (ll ! var n) \\<and>\n             (\\<forall>nt p. Dag n low high nt \\<and> p \\<in> set_of nt \\<longrightarrow> mark p = m)\n        else n \\<notin> set (concat ll)\"\n  with mark_p have p_notin_ll: \"p \\<notin> set (concat ll)\"\n    by auto\n  assume varsll': \"var p < length levellist\"\n  with ll have varsll: \"var p < length ll\"\n    by (simp add: Levellist_length)\n  assume orderedt: \"ordered (Node lt p rt) var\"\n  show \"(low p \\<noteq> Null \\<longrightarrow> var (low p) < length levellist) \\<and>\n          ordered lt var \\<and>\n          (\\<forall>n \\<in> set_of lt.\n              if mark n = m\n              then n \\<in> set (ll ! var n) \\<and>\n                   (\\<forall>nt p. Dag n low high nt \\<and> p \\<in> set_of nt \\<longrightarrow> mark p = m)\n              else n \\<notin> set (concat ll)) \\<and>\n          size (dag (low p) low high) < size (dag p low high) \\<and>\n          (\\<forall>marka nexta levellist lla.\n              Levellist levellist nexta lla \\<and>\n              wf_levellist lt ll lla var \\<and> wf_marking lt mark marka m \\<and>\n              (\\<forall>p. p \\<notin> set_of lt \\<longrightarrow> next p = nexta p)\\<longrightarrow>\n              (high p \\<noteq> Null \\<longrightarrow> var (high p) < length levellist) \\<and>\n              ordered rt var \\<and>\n              (\\<exists>lla. Levellist levellist nexta lla \\<and>\n                     (\\<forall>n \\<in> set_of rt.\n                        if marka n = m\n                        then n \\<in> set (lla ! var n) \\<and>\n                             (\\<forall>nt p. Dag n low high nt \\<and> p \\<in> set_of nt \\<longrightarrow>\n                                    marka p = m)\n                        else n \\<notin> set (concat lla)) \\<and>\n                     size (dag (high p) low high) < size (dag p low high) \\<and>\n                     (\\<forall>markb nextb levellist llb.\n                         Levellist levellist nextb llb \\<and>\n                         wf_levellist rt lla llb var \\<and>\n                         wf_marking rt marka markb m \\<and>\n                         (\\<forall>p. p \\<notin> set_of rt \\<longrightarrow> nexta p = nextb p) \\<longrightarrow>\n                         (\\<exists>ll'. Levellist (levellist[var p := p])\n                                 (nextb(p := levellist ! var p)) ll' \\<and>\n                                wf_levellist (Node lt p rt) ll ll' var \\<and>\n                                wf_marking (Node lt p rt) mark (markb(p := m)) m \\<and>\n                                (\\<forall>pa. pa \\<notin> set_of (Node lt p rt) \\<longrightarrow>\n                                      next pa =\n                                      (if pa = p then levellist ! var p\n                                       else nextb pa))))))\"\n  proof (cases \"lt\")\n    case Tip\n    note lt_Tip = this\n    show ?thesis\n    proof (cases \"rt\")\n      case Tip\n      show ?thesis\n        using size_rt_dec Tip lt_Tip Tip lt rt\n        apply clarsimp\n        subgoal premises prems for marka nexta levellista lla markb nextb levellistb llb\n        proof -\n          have lla: \"Levellist levellista nexta lla\" by fact\n          have llb: \"Levellist levellistb nextb llb\" by fact\n          have wfll_lt: \"wf_levellist Tip ll lla var\"\n                        \"wf_marking Tip mark marka m\" by fact+\n\n          then have ll_lla: \"ll = lla\"\n            by (simp add: wf_levellist_def)\n\n          moreover\n          with wfll_lt lt_Tip lt have \"marka = mark\"\n            by (simp add: wf_marking_def)\n          moreover\n          have wfll_rt:\"wf_levellist Tip lla llb var\"\n                       \"wf_marking Tip marka markb m\" by fact+\n          then have lla_llb: \"lla = llb\"\n            by (simp add: wf_levellist_def)\n          moreover\n          with wfll_rt Tip rt have \"markb = marka\"\n            by (simp add: wf_marking_def)\n          moreover\n          from varsll llb ll_lla lla_llb\n          obtain \"var p < length levellistb\" \"var p < length llb\"\n            by (simp add: Levellist_length)\n          with llb pnN\n          have llc: \"Levellist (levellistb[var p := p]) (nextb(p := levellistb ! var p))\n                      (llb[var p := p # llb ! var p])\"\n            apply (clarsimp simp add: Levellist_def map_update)\n            apply (erule_tac x=i in allE)\n            apply clarsimp\n            apply (subgoal_tac \"p \\<notin> set (llb ! i) \")\n            prefer 2\n            using  p_notin_ll ll_lla lla_llb\n            apply  simp\n            apply (case_tac \"i=var p\")\n            apply  simp\n            apply simp\n            done\n          ultimately\n          show ?thesis\n            using lt_Tip Tip varsll\n            apply (clarsimp simp add: wf_levellist_def wf_marking_def)\n          proof -\n            fix i\n            assume varsllb: \"var p < length llb\"\n            assume \"i \\<le> var p\"\n            show \"\\<exists>prx. llb[var p := p#llb!var p]!i = prx @ llb!i \\<and>\n                      (\\<forall>pt\\<in>set prx. pt = p \\<and> var pt = i)\"\n            proof (cases \"i = var p\")\n              case True\n              with pnN lt rt varsllb lt_Tip Tip show ?thesis\n                apply -\n                apply (rule_tac x=\"[p]\" in exI)\n                apply (simp add: subdag_eq_def)\n                done\n            next\n              assume \"i \\<noteq> var p\"\n              with varsllb show ?thesis\n                apply -\n                apply (rule_tac x=\"[]\" in exI)\n                apply (simp add: subdag_eq_def)\n                done\n            qed\n          qed\n        qed\n      done\n    next\n      case (Node dag1 a dag2)\n      have rt_node: \"rt = Node dag1 a dag2\" by fact\n      with rt have high_p: \"high p = a\"\n        by simp\n      have s: \"\\<And>nexta. (\\<forall>p. next p = nexta p) = (next = nexta)\"\n        by auto\n      show ?thesis\n        using size_rt_dec size_lt_dec rt_node lt_Tip Tip lt rt\n        apply (clarsimp simp del: set_of_Node split del: if_split simp add: s)\n        subgoal premises prems for marka levellista lla\n        proof -\n          have lla: \"Levellist levellista next lla\" by fact\n          have wfll_lt:\"wf_levellist Tip ll lla var\"\n                       \"wf_marking Tip mark marka m\" by fact+\n          from this have ll_lla: \"ll = lla\"\n            by (simp add: wf_levellist_def)\n          moreover\n          from wfll_lt lt_Tip lt have marklrec: \"marka = mark\"\n            by (simp add: wf_marking_def)\n          from orderedt varsll lla ll_lla rt_node lt_Tip high_p\n          have var_highp_bound: \"var (high p) < length levellista\"\n            by (auto simp add: Levellist_length)\n          from orderedt high_p rt_node lt_Tip\n          have ordered_rt: \"ordered (Node dag1 (high p) dag2) var\"\n            by simp\n          from high_p marklrec marked_child_ll lt rt lt_Tip rt_node ll_lla\n          have mark_rt: \"(\\<forall>n\\<in>set_of (Node dag1 (high p) dag2).\n                if marka n = m\n                then n \\<in> set (lla ! var n) \\<and>\n                     (\\<forall>nt p. Dag n low high nt \\<and> p \\<in> set_of nt \\<longrightarrow> marka p = m)\n                else n \\<notin> set (concat lla))\"\n            apply (simp only: BinDag.set_of.simps)\n            apply clarify\n            apply (drule_tac x=n in bspec)\n            apply  blast\n            apply assumption\n            done\n          show ?thesis\n            apply (rule conjI)\n            apply  (rule var_highp_bound)\n            apply (rule conjI)\n            apply  (rule ordered_rt)\n            apply (rule conjI)\n            apply  (rule mark_rt)\n            apply clarify\n            apply clarsimp\n            subgoal premises prems for markb nextb levellistb llb\n            proof -\n              have llb: \"Levellist levellistb nextb llb\" by fact\n              have wfll_rt: \"wf_levellist (Node dag1 (high p) dag2) lla llb var\" by fact\n              have wfmarking_rt: \"wf_marking (Node dag1 (high p) dag2) marka markb m\" by fact\n              from wfll_rt varsll llb ll_lla\n              obtain var_p_bounds: \"var p < length levellistb\" \"var p < length llb\"\n                by (simp add: Levellist_length wf_levellist_def)\n              with p_notin_ll ll_lla wfll_rt\n              have p_notin_llb: \"\\<forall>i < length llb. p \\<notin> set (llb ! i)\"\n                apply -\n                apply (intro allI impI)\n                apply (clarsimp simp add: wf_levellist_def)\n                apply (case_tac \"i \\<le> var (high p)\")\n                apply  (drule_tac x=i in spec)\n                using  orderedt rt_node lt_Tip high_p\n                apply  clarsimp\n                apply (drule_tac x=i in spec)\n                apply (drule_tac x=i in spec)\n                apply clarsimp\n                done\n              with llb pnN var_p_bounds\n              have llc: \"Levellist (levellistb[var p := p])\n                            (nextb(p := levellistb ! var p))\n                            (llb[var p := p # llb ! var p])\"\n                apply (clarsimp simp add: Levellist_def map_update)\n                apply (erule_tac x=i in allE)\n                apply (erule_tac x=i in allE)\n                apply clarsimp\n                apply (case_tac \"i=var p\")\n                apply  simp\n                apply simp\n                done\n              then show ?thesis\n                apply simp\n                using wfll_rt wfmarking_rt\n                      lt_Tip rt_node varsll orderedt lt rt pnN ll_lla marklrec\n                apply (clarsimp simp add: wf_levellist_def wf_marking_def)\n                apply (intro conjI)\n                apply  (rule allI)\n                apply  (rule conjI)\n                apply   (erule_tac x=\"q\" in allE)\n                apply   (case_tac \"var p = var q\")\n                apply    fastforce\n                apply   fastforce\n                apply  (case_tac \"var p = var q\")\n                apply   hypsubst_thin\n                apply   fastforce\n                apply  fastforce\n                apply (rule allI)\n                apply (rotate_tac 4)\n                apply (erule_tac x=\"i\" in allE)\n                apply (case_tac \"i=var p\")\n                apply  simp\n                apply (case_tac \"var (high p) < i\")\n                apply  simp\n                apply simp\n                apply (erule exE)\n                apply (rule_tac x=\"prx\" in exI)\n                apply (intro conjI)\n                apply  simp\n                apply clarify\n                apply (rotate_tac 15)\n                apply (erule_tac x=\"pt\" in ballE)\n                apply  fastforce\n                apply fastforce\n                done\n            qed\n          done\n        qed\n      done\n    qed\n  next\n    case (Node llt l rlt)\n    have lt_Node: \"lt = Node llt l rlt\" by fact\n    from orderedt lt varsll' lt_Node\n    obtain ordered_lt:\n      \"ordered lt var\" \"(low p \\<noteq> Null \\<longrightarrow> var (low p) < length levellist)\"\n      by (cases rt) auto\n    from lt lt_Node marked_child_ll\n    have mark_lt: \"\\<forall>n\\<in>set_of lt.\n     if mark n = m\n     then n \\<in> set (ll ! var n) \\<and>\n          (\\<forall>nt p. Dag n low high nt \\<and> p \\<in> set_of nt \\<longrightarrow> mark p = m)\n     else n \\<notin> set (concat ll)\"\n      apply (simp only: BinDag.set_of.simps)\n      apply clarify\n      apply (drule_tac x=n in bspec)\n      apply  blast\n      apply assumption\n      done\n    show ?thesis\n      apply (intro conjI ordered_lt mark_lt size_lt_dec)\n      apply (clarify)\n      apply (simp add: size_rt_dec split del: if_split)\n      apply (simp only: Levellist_ext_to_all)\n      subgoal premises prems for marka nexta levellista lla\n      proof -\n        have lla: \"Levellist levellista nexta lla\" by fact\n        have wfll_lt: \"wf_levellist lt ll lla var\"  by fact\n        have wfmarking_lt:\"wf_marking lt mark marka m\" by fact\n        from wfll_lt lt_Node\n        have lla_eq_ll: \"length lla = length ll\"\n          by (simp add: wf_levellist_def)\n        with ll lla have lla_eq_ll': \"length levellista = length levellist\"\n          by (simp add: Levellist_length)\n        with orderedt rt lt_Node lt varsll'\n        obtain ordered_rt:\n          \"ordered rt var\" \"(high p \\<noteq> Null \\<longrightarrow> var (high p) < length levellista)\"\n          by (cases rt) auto\n        from wfll_lt lt_Node\n        have nodes_in_lla: \"\\<forall> q. q \\<in> set_of lt \\<longrightarrow> q \\<in> set (lla ! (q\\<rightarrow>var))\"\n          by (simp add: wf_levellist_def)\n        from wfll_lt lt_Node lt\n        have lla_st: \"(\\<forall>i \\<le> (low p)\\<rightarrow>var.\n                        (\\<exists>prx. (lla ! i) = prx@(ll ! i) \\<and>\n                               (\\<forall>pt \\<in> set prx. pt \\<in> set_of lt \\<and> pt\\<rightarrow>var = i)))\"\n          by (simp add: wf_levellist_def)\n        from wfll_lt lt_Node lt\n        have lla_nc: \"\\<forall>i. ((low p)\\<rightarrow>var) < i \\<longrightarrow> (lla ! i) = (ll ! i)\"\n          by (simp add: wf_levellist_def)\n        from wfmarking_lt lt_Node lt\n        have mot_nc: \"\\<forall> n. n \\<notin> set_of lt \\<longrightarrow> mark n = marka n\"\n          by (simp add: wf_marking_def)\n        from wfmarking_lt lt_Node lt\n        have mit_marked: \"\\<forall>n. n \\<in> set_of lt \\<longrightarrow> marka n = m\"\n          by (simp add: wf_marking_def)\n        from marked_child_ll nodes_in_lla mot_nc mit_marked lla_st\n        have mark_rt: \"\\<forall>n\\<in>set_of rt.\n               if marka n = m\n               then n \\<in> set (lla ! var n) \\<and>\n                   (\\<forall>nt p. Dag n low high nt \\<and> p \\<in> set_of nt \\<longrightarrow> marka p = m)\n               else n \\<notin> set (concat lla)\"\n          apply -\n          apply (rule ballI)\n          apply (drule_tac x=\"n\" in bspec)\n          apply (simp)\n        proof -\n          fix n\n\n          assume nodes_in_lla: \"\\<forall>q. q \\<in> set_of lt \\<longrightarrow> q \\<in> set (lla ! var q)\"\n          assume mot_nc: \"\\<forall>n. n \\<notin> set_of lt \\<longrightarrow> mark n = marka n\"\n          assume mit_marked: \"\\<forall>n. n \\<in> set_of lt \\<longrightarrow> marka n = m\"\n          assume marked_child_ll: \"if mark n = m\n           then n \\<in> set (ll ! var n) \\<and>\n                (\\<forall>nt p. Dag n low high nt \\<and> p \\<in> set_of nt \\<longrightarrow> mark p = m)\n           else n \\<notin> set (concat ll)\"\n\n          assume lla_st: \"\\<forall>i\\<le>var (low p).\n                               \\<exists>prx. lla ! i = prx @ ll ! i \\<and>\n                               (\\<forall>pt\\<in>set prx. pt \\<in> set_of lt \\<and> var pt = i)\"\n\n          assume n_in_rt: \" n \\<in> set_of rt\"\n          show n_in_lla_marked: \"if marka n = m\n             then n \\<in> set (lla ! var n) \\<and>\n                  (\\<forall>nt p. Dag n low high nt \\<and> p \\<in> set_of nt \\<longrightarrow> marka p = m)\n             else n \\<notin> set (concat lla)\"\n          proof (cases \"n \\<in> set_of lt\")\n            case True\n            from True nodes_in_lla have n_in_ll: \"n \\<in> set (lla ! var n)\"\n              by simp\n            moreover\n            from True wfmarking_lt\n            have \"marka n = m\"\n              apply (cases lt)\n              apply (auto simp add: wf_marking_def)\n              done\n            moreover\n            {\n              fix nt p\n              assume \"Dag n low high nt\"\n              with lt True have subset_nt_lt: \"set_of nt \\<subseteq> set_of lt\"\n                by (rule dag_setof_subsetD)\n              moreover assume \" p \\<in> set_of nt\"\n              ultimately have \"p \\<in> set_of lt\"\n                by blast\n              with mit_marked have \" marka p = m\"\n                by simp\n            }\n            ultimately show ?thesis\n              using n_in_rt\n              apply clarsimp\n              done\n          next\n            assume n_notin_lt: \"n \\<notin> set_of lt\"\n            show ?thesis\n            proof (cases \"marka n = m\")\n              case True\n              from n_notin_lt mot_nc have marka_eq_mark: \"mark n = marka n\"\n                by simp\n              from marka_eq_mark True have n_marked: \"mark n = m\"\n                by simp\n              from rt n_in_rt have nnN: \"n \\<noteq> Null\"\n                apply -\n                apply (rule set_of_nn [rule_format])\n                apply fastforce\n                apply assumption\n                done\n              from marked_child_ll n_in_rt marka_eq_mark nnN n_marked\n              have n_in_ll: \"n \\<in> set (ll ! var n)\"\n                by fastforce\n              from marked_child_ll n_in_rt marka_eq_mark nnN n_marked lt rt\n              have nt_mark: \"\\<forall>nt p. Dag n low high nt \\<and> p \\<in> set_of nt \\<longrightarrow> mark p = m\"\n                by simp\n              from nodes_in_lla n_in_ll lla_st\n              have n_in_lla: \"n \\<in> set (lla ! var n)\"\n              proof (cases \"var (low p) < (var n)\")\n                case True\n                with lla_nc have \"(lla ! var n) = (ll ! var n)\"\n                  by fastforce\n                with n_in_ll show ?thesis\n                  by fastforce\n              next\n                assume varnslp: \" \\<not> var (low p) < var n\"\n                with lla_st\n                have ll_in_lla: \"\\<exists>prx. lla ! (var n) = prx @ ll ! (var n)\"\n                  apply -\n                  apply (erule_tac x=\"var n\" in allE)\n                  apply fastforce\n                  done\n                with n_in_ll show ?thesis\n                  by fastforce\n              qed\n              {\n                fix nt pt\n                assume nt_Dag: \"Dag n low high nt\"\n                assume pt_in_nt: \"pt \\<in> set_of nt\"\n                have \" marka pt = m\"\n                proof (cases \"pt \\<in> set_of lt\")\n                  case True\n                  with mit_marked show ?thesis\n                    by fastforce\n                next\n                  assume pt_notin_lt: \" pt \\<notin> set_of lt\"\n                  with mot_nc have \"mark pt = marka pt\"\n                    by fastforce\n                  with nt_mark nt_Dag pt_in_nt show ?thesis\n                    by fastforce\n                qed\n              }\n              then have nt_marka:\n                \"\\<forall>nt pt. Dag n low high nt \\<and> pt \\<in> set_of nt \\<longrightarrow> marka pt = m\"\n                by fastforce\n              with n_in_lla nt_marka True show ?thesis\n                by fastforce\n            next\n              case False\n              note n_not_marka = this\n              with wfmarking_lt n_notin_lt\n              have \"mark n \\<noteq> m\"\n                by (simp add: wf_marking_def lt_Node)\n              with marked_child_ll\n              have n_notin_ll: \"n \\<notin> set (concat ll)\"\n                by simp\n              show ?thesis\n              proof (cases \"n \\<in> set (concat lla)\")\n                case False with n_not_marka show ?thesis by simp\n              next\n                case True\n                with wf_levellist_subset [OF wfll_lt] n_notin_ll\n                have \"n \\<in> set_of lt\"\n                  by blast\n                with n_notin_lt have False by simp\n                thus ?thesis ..\n              qed\n            qed\n          qed\n        qed\n        show ?thesis\n          apply (intro conjI ordered_rt mark_rt)\n          apply clarify\n          subgoal premises prems for markb nextb levellistb llb\n          proof -\n            have llb: \"Levellist levellistb nextb llb\" by fact\n            have wfll_rt: \"wf_levellist rt lla llb var\" by fact\n            have wfmarking_rt: \"wf_marking rt marka markb m\" by fact\n            show ?thesis\n            proof (cases rt)\n              case Tip\n              from wfll_rt Tip have lla_llb: \"lla = llb\"\n                by (simp add: wf_levellist_def)\n              moreover\n              from wfmarking_rt Tip rt have \"markb = marka\"\n                by (simp add: wf_marking_def)\n              moreover\n              from wfll_lt varsll llb lla_llb\n              obtain var_p_bounds: \"var p < length levellistb\" \"var p < length llb\"\n                by (simp add: Levellist_length wf_levellist_def lt_Node Tip)\n              with p_notin_ll lla_llb wfll_lt\n              have p_notin_llb: \"\\<forall>i < length llb. p \\<notin> set (llb ! i)\"\n                apply -\n                apply (intro allI impI)\n                apply (clarsimp simp add: wf_levellist_def lt_Node)\n                apply (case_tac \"i \\<le> var l\")\n                apply  (drule_tac x=i in spec)\n                using  orderedt Tip lt_Node\n                apply  clarsimp\n                apply (drule_tac x=i in spec)\n                apply (drule_tac x=i in spec)\n                apply clarsimp\n                done\n              with llb pnN var_p_bounds\n              have llc: \"Levellist (levellistb[var p := p])\n                            (nextb(p := levellistb ! var p))\n                            (llb[var p := p # llb ! var p])\"\n                apply (clarsimp simp add: Levellist_def map_update)\n                apply (erule_tac x=i in allE)\n                apply (erule_tac x=i in allE)\n                apply clarsimp\n                apply (case_tac \"i=var p\")\n                apply  simp\n                apply simp\n                done\n              ultimately show ?thesis\n                using Tip lt_Node varsll orderedt lt rt pnN wfll_lt wfmarking_lt\n                apply (clarsimp simp add: wf_levellist_def wf_marking_def)\n                apply (intro conjI)\n                apply  (rule allI)\n                apply  (rule conjI)\n                apply   (erule_tac x=\"q\" in allE)\n                apply   (case_tac \"var p = var q\")\n                apply    fastforce\n                apply   fastforce\n                apply  (case_tac \"var p = var q\")\n                apply   hypsubst_thin\n                apply   fastforce\n                apply  fastforce\n                apply (rule allI)\n                apply (rotate_tac 4)\n                apply (erule_tac x=\"i\" in allE)\n                apply (case_tac \"i=var p\")\n                apply  simp\n                apply (case_tac \"var (low p) < i\")\n                apply  simp\n                apply simp\n                apply (erule exE)\n                apply (rule_tac x=\"prx\" in exI)\n                apply (intro conjI)\n                apply  simp\n                apply clarify\n                apply (rotate_tac 15)\n                apply (erule_tac x=\"pt\" in ballE)\n                apply  fastforce\n                apply fastforce\n                done\n            next\n              case (Node lrt r rrt)\n              have rt_Node: \"rt = Node lrt r rrt\" by fact\n              from wfll_rt rt_Node\n              have llb_eq_lla: \"length llb = length lla\"\n                by (simp add: wf_levellist_def)\n              with llb lla\n              have llb_eq_lla': \"length levellistb = length levellista\"\n                by (simp add: Levellist_length)\n              from wfll_rt rt_Node\n              have nodes_in_llb: \"\\<forall>q. q \\<in> set_of rt \\<longrightarrow> q \\<in> set (llb ! (q\\<rightarrow>var))\"\n                by (simp add: wf_levellist_def)\n              from wfll_rt rt_Node rt\n              have llb_st: \"(\\<forall> i \\<le> (high p)\\<rightarrow>var.\n                             (\\<exists> prx. (llb ! i) = prx@(lla ! i) \\<and>\n                             (\\<forall>pt \\<in> set prx. pt \\<in> set_of rt \\<and> pt\\<rightarrow>var = i)))\"\n                by (simp add: wf_levellist_def)\n              from wfll_rt rt_Node rt\n              have llb_nc:\n                \"\\<forall>i. ((high p)\\<rightarrow>var) < i \\<longrightarrow> (llb ! i) = (lla ! i)\"\n                by (simp add: wf_levellist_def)\n              from wfmarking_rt rt_Node rt\n              have mort_nc: \"\\<forall>n. n \\<notin> set_of rt \\<longrightarrow> marka n = markb n\"\n                by (simp add: wf_marking_def)\n              from wfmarking_rt rt_Node rt\n              have mirt_marked: \"\\<forall>n. n \\<in> set_of rt \\<longrightarrow> markb n = m\"\n                by (simp add: wf_marking_def)\n              with p_notin_ll wfll_rt wfll_lt\n              have p_notin_llb: \"\\<forall>i < length llb. p \\<notin> set (llb ! i)\"\n                apply -\n                apply (intro allI impI)\n                apply (clarsimp simp add: wf_levellist_def lt_Node rt_Node)\n                apply (case_tac \"i \\<le> var r\")\n                apply  (drule_tac x=i in spec)\n                using  orderedt rt_Node lt_Node\n                apply  clarsimp\n                apply  (erule disjE)\n                apply   clarsimp\n                apply  (case_tac \"i \\<le> var l\")\n                apply   (drule_tac x=i in spec)\n                apply   clarsimp\n                apply  clarsimp\n                apply (subgoal_tac \"llb ! i = lla ! i\")\n                prefer 2\n                apply  clarsimp\n                apply (case_tac \"i \\<le> var l\")\n                apply  (drule_tac x=i in spec, erule impE, assumption)\n                apply  clarsimp\n                using  orderedt rt_Node lt_Node\n                apply  clarsimp\n                apply clarsimp\n                done\n              from wfll_lt wfll_rt varsll lla llb\n              obtain var_p_bounds: \"var p < length levellistb\" \"var p < length llb\"\n                by (simp add: Levellist_length wf_levellist_def lt_Node rt_Node)\n              with p_notin_llb llb pnN var_p_bounds\n              have llc: \"Levellist (levellistb[var p := p])\n                            (nextb(p := levellistb ! var p))\n                            (llb[var p := p # llb ! var p])\"\n                apply (clarsimp simp add: Levellist_def map_update)\n                apply (erule_tac x=i in allE)\n                apply (erule_tac x=i in allE)\n                apply clarsimp\n                apply (case_tac \"i=var p\")\n                apply  simp\n                apply simp\n                done\n              then show ?thesis\n              proof (clarsimp)\n                show \"wf_levellist (Node lt p rt) ll (llb[var p := p#llb ! var p]) var \\<and>\n                      wf_marking (Node lt p rt) mark (markb(p := m)) m\"\n                proof -\n                  have nodes_in_upllb: \"\\<forall> q. q \\<in> set_of (Node lt p rt)\n                    \\<longrightarrow> q \\<in> set (llb[var p :=p # llb ! var p] ! (var q))\"\n                    apply -\n                    apply (rule allI)\n                    apply (rule impI)\n                  proof -\n                    fix q\n                    assume q_in_t: \"q \\<in> set_of (Node lt p rt)\"\n                    show q_in_upllb:\n                      \"q \\<in> set (llb[var p :=p # llb ! var p] ! (var q))\"\n                    proof (cases \"q \\<in> set_of rt\")\n                      case True\n                      with nodes_in_llb have q_in_llb: \"q \\<in> set (llb ! (var q))\"\n                        by fastforce\n                      from orderedt rt_Node lt_Node lt rt\n                      have ordered_rt: \"ordered rt var\"\n                        by fastforce\n                      from True rt ordered_rt rt_Node lt lt_Node have \"var q \\<le> var r\"\n                        apply -\n                        apply (drule subnodes_ordered)\n                        apply fastforce\n                        apply fastforce\n                        apply fastforce\n                        done\n                      with orderedt rt lt rt_Node lt_Node have \"var q < var p\"\n                        by fastforce\n                      then have\n                        \"llb[var p :=p#llb ! var p] ! var q =\n                         llb ! var q\"\n                        by fastforce\n                      with q_in_llb show ?thesis\n                        by fastforce\n                    next\n                      assume q_notin_rt: \"q \\<notin> set_of rt\"\n                      show \"q \\<in> set (llb[var p :=p # llb ! var p] ! var q)\"\n                      proof (cases \"q \\<in> set_of lt\")\n                        case True\n                        assume q_in_lt: \"q \\<in> set_of lt\"\n                        with nodes_in_lla have q_in_lla: \"q \\<in> set (lla ! (var q))\"\n                          by fastforce\n                        from orderedt rt_Node lt_Node lt rt\n                        have ordered_lt: \"ordered lt var\"\n                          by fastforce\n                        from q_in_lt lt ordered_lt rt_Node rt lt_Node\n                        have \"var q \\<le> var l\"\n                          apply -\n                          apply (drule subnodes_ordered)\n                          apply fastforce\n                          apply fastforce\n                          apply fastforce\n                          done\n                        with orderedt rt lt rt_Node lt_Node have qsp: \"var q < var p\"\n                          by fastforce\n                        then show ?thesis\n                        proof (cases \"var q \\<le> var (high p)\")\n                          case True\n                          with llb_st\n                          have \"\\<exists>prx. (llb ! (var q)) = prx@(lla ! (var q))\"\n                            by fastforce\n                          with nodes_in_lla q_in_lla\n                          have q_in_llb: \"q \\<in> set (llb ! (var q))\"\n                            by fastforce\n                          from qsp\n                          have \"llb[var p :=p#llb ! var p]!var q =\n                                   llb ! (var q)\"\n                            by fastforce\n                          with q_in_llb show ?thesis\n                            by fastforce\n                        next\n                          assume \"\\<not> var q \\<le> var (high p)\"\n                          with llb_nc have \"llb ! (var q) = lla ! (var q)\"\n                            by fastforce\n                          with q_in_lla have q_in_llb: \"q \\<in> set (llb ! (var q))\"\n                            by fastforce\n                          from qsp have\n                            \"llb[var p :=p # llb ! var p] ! var q = llb ! (var q)\"\n                            by fastforce\n                          with q_in_llb show ?thesis\n                            by fastforce\n                        qed\n                      next\n                        assume q_notin_lt: \"q \\<notin> set_of lt\"\n                        with q_notin_rt rt lt rt_Node lt_Node q_in_t have qp: \"q = p\"\n                          by fastforce\n                        with varsll lla_eq_ll llb_eq_lla have \"var p < length llb\"\n                          by fastforce\n                        with qp show ?thesis\n                          by simp\n                      qed\n                    qed\n                  qed\n                  have prx_ll_st: \"\\<forall>i \\<le> var p.\n                   (\\<exists>prx. llb[var p :=p#llb!var p]!i = prx@(ll!i) \\<and>\n                         (\\<forall>pt \\<in> set prx. pt \\<in> set_of (Node lt p rt) \\<and> var pt = i))\"\n                    apply -\n                    apply (rule allI)\n                    apply (rule impI)\n                  proof -\n                    fix i\n                    assume isep: \"i \\<le> var p\"\n                    show \"\\<exists>prx. llb[var p :=p#llb!var p]!i = prx@ll!i \\<and>\n                      (\\<forall>pt\\<in>set prx. pt \\<in> set_of (Node lt p rt) \\<and> var pt = i)\"\n                    proof (cases \"i = var p\")\n                      case True\n                      with orderedt lt lt_Node rt rt_Node\n                      have lpsp: \"var (low p) < var p\"\n                        by fastforce\n                      with orderedt lt lt_Node rt rt_Node\n                      have hpsp: \"var (high p) < var p\"\n                        by fastforce\n                      with lpsp lla_nc\n                      have llall: \"lla ! var p = ll ! var p\"\n                        by fastforce\n                      with hpsp llb_nc have \"llb ! var p = ll ! var p\"\n                        by fastforce\n                      with llb_eq_lla lla_eq_ll isep True varsll lt rt show ?thesis\n                        apply -\n                        apply (rule_tac x=\"[p]\" in exI)\n                        apply (rule conjI)\n                        apply simp\n                        apply (rule ballI)\n                        apply fastforce\n                        done\n                    next\n                      assume inp: \" i \\<noteq> var p\"\n                      show ?thesis\n                      proof (cases \"var (low p) < i\")\n                        case True\n                        with lla_nc have llall: \"lla ! i = ll ! i\"\n                          by fastforce\n                        assume vpsi: \"var (low p) < i\"\n                        show ?thesis\n                        proof (cases \"var (high p) < i\")\n                          case True\n                          with llall llb_nc have \"llb ! i = ll ! i\"\n                            by fastforce\n                          with inp True vpsi varsll lt rt show ?thesis\n                            apply -\n                            apply (rule_tac x=\"[]\" in exI)\n                            apply (rule conjI)\n                            apply simp\n                            apply (rule ballI)\n                            apply fastforce\n                            done\n                        next\n                          assume isehp: \" \\<not> var (high p) < i\"\n                          with vpsi lla_nc have lla_ll: \"lla ! i = ll ! i\"\n                            by fastforce\n                          with isehp llb_st\n                          have prx_lla: \"\\<exists>prx. llb ! i = prx @ lla ! i \\<and>\n                            (\\<forall>pt\\<in>set prx. pt \\<in> set_of rt \\<and> var pt = i)\"\n                            apply -\n                            apply (erule_tac x=\"i\" in allE)\n                            apply simp\n                            done\n                          with lla_ll inp rt show ?thesis\n                            apply -\n                            apply (erule exE)\n                            apply (rule_tac x=\"prx\" in exI)\n                            apply simp\n                            done\n                        qed\n                      next\n                        assume iselp: \"\\<not> var (low p) < i\"\n                        show ?thesis\n                        proof (cases \"var (high p) < i\")\n                          case True\n                          with llb_nc have llb_ll: \"llb ! i = lla ! i\"\n                            by fastforce\n                          with iselp lla_st\n                          have prx_ll: \"\\<exists>prx. lla ! i = prx @ ll ! i \\<and>\n                            (\\<forall>pt\\<in>set prx. pt \\<in> set_of lt \\<and> var pt = i)\"\n                            apply -\n                            apply (erule_tac x=\"i\" in allE)\n                            apply simp\n                            done\n                          with llb_ll inp lt show ?thesis\n                            apply -\n                            apply (erule exE)\n                            apply (rule_tac x=\"prx\" in exI)\n                            apply simp\n                            done\n                        next\n                          assume isehp: \" \\<not> var (high p) < i\"\n                          from iselp lla_st\n                          have prxl: \"\\<exists>prx. lla ! i = prx @ ll ! i \\<and>\n                            (\\<forall>pt\\<in>set prx. pt \\<in> set_of lt \\<and> var pt = i)\"\n                            by fastforce\n                          from isehp llb_st\n                          have prxh: \"\\<exists>prx. llb ! i = prx @ lla ! i \\<and>\n                            (\\<forall>pt\\<in>set prx. pt \\<in> set_of rt \\<and> var pt = i)\"\n                            by fastforce\n                          with prxl inp lt pnN rt show ?thesis\n                            apply -\n                            apply (elim exE)\n                            apply (rule_tac x=\"prxa @ prx\" in exI)\n                            apply simp\n                            apply (elim conjE)\n                            apply fastforce\n                            done\n                        qed\n                      qed\n                    qed\n                  qed\n                  have big_Nodes_nc: \"\\<forall>i. (p->var) < i\n                    \\<longrightarrow> (llb[var p :=p # llb ! var p]) ! i = ll ! i\"\n                    apply -\n                    apply (rule allI)\n                    apply (rule impI)\n                  proof -\n                    fix i\n                    assume psi: \"var p < i\"\n                    with orderedt lt rt lt_Node rt_Node have lpsi: \"var (low p) < i\"\n                      by fastforce\n                    with lla_nc have lla_ll: \"lla ! i = ll ! i\"\n                      by fastforce\n                    from psi orderedt lt rt lt_Node rt_Node have hpsi: \"var (high p) < i\"\n                      by fastforce\n                    with llb_nc have llb_lla: \"llb ! i = lla ! i\"\n                      by fastforce\n                    from psi\n                    have upllb_llb: \"llb[var p :=p#llb!var p]!i = llb!i\"\n                      by fastforce\n                    from upllb_llb llb_lla lla_ll\n                    show \"llb[var p :=p # llb ! var p] ! i = ll ! i\"\n                      by fastforce\n                  qed\n                  from lla_eq_ll llb_eq_lla\n                  have length_eq: \"length (llb[var p :=p # llb ! var p]) = length ll\"\n                    by fastforce\n                  from length_eq big_Nodes_nc prx_ll_st nodes_in_upllb\n                  have wf_ll_upllb:\n                    \"wf_levellist (Node lt p rt) ll (llb[var p :=p # llb ! var p]) var\"\n                    by (simp add: wf_levellist_def)\n                  have mark_nc:\n                    \"\\<forall> n. n \\<notin> set_of (Node lt p rt) \\<longrightarrow> (markb(p:=m)) n = mark n\"\n                    apply -\n                    apply (rule allI)\n                    apply (rule impI)\n                  proof -\n                    fix n\n                    assume nnit: \"n \\<notin> set_of (Node lt p rt)\"\n                    with lt rt have nnilt: \" n \\<notin> set_of lt\"\n                      by fastforce\n                    from nnit lt rt have nnirt: \" n \\<notin> set_of rt\"\n                      by fastforce\n                    with nnilt mot_nc mort_nc have mb_eq_m: \"markb n = mark n\"\n                      by fastforce\n                    from nnit have \"n\\<noteq>p\"\n                      by fastforce\n                    then have upmarkb_markb: \"(markb(p :=m)) n = markb n\"\n                      by fastforce\n                    with mb_eq_m show \"(markb(p :=m)) n = mark n\"\n                      by fastforce\n                  qed\n                  have mark_c: \"\\<forall> n. n \\<in> set_of (Node lt p rt) \\<longrightarrow> (markb(p :=m)) n = m\"\n                    apply -\n                    apply (intro allI)\n                    apply (rule impI)\n                  proof -\n                    fix n\n                    assume nint: \" n \\<in> set_of (Node lt p rt)\"\n                    show \"(markb(p :=m)) n = m\"\n                    proof (cases \"n=p\")\n                      case True\n                      then show ?thesis\n                        by fastforce\n                    next\n                      assume nnp: \" n \\<noteq> p\"\n                      show ?thesis\n                      proof (cases \"n \\<in> set_of rt\")\n                        case True\n                        with mirt_marked have \"markb n = m\"\n                          by fastforce\n                        with nnp show ?thesis\n                          by fastforce\n                      next\n                        assume nninrt: \" n \\<notin> set_of rt\"\n                        with nint nnp have ninlt: \"n \\<in> set_of lt\"\n                          by fastforce\n                        with mit_marked have marka_m: \"marka n = m\"\n                          by fastforce\n                        from mort_nc nninrt have \"marka n = markb n\"\n                          by fastforce\n                        with marka_m have \"markb n = m\"\n                          by fastforce\n                        with nnp show ?thesis\n                          by fastforce\n                      qed\n                    qed\n                  qed\n                  from mark_c mark_nc\n                  have wf_mark: \"wf_marking (Node lt p rt) mark (markb(p :=m)) m\"\n                    by (simp add: wf_marking_def)\n                  with wf_ll_upllb show ?thesis\n                    by fastforce\n                qed\n              qed\n            qed\n          qed\n        done\n      qed\n    done\n  qed\nnext\n  fix var low high p lt rt and levellist and\n    ll::\"ref list list\" and mark::\"ref \\<Rightarrow> bool\" and \"next\"\n  assume pnN: \"p \\<noteq> Null\"\n  assume ll: \"Levellist levellist next ll\"\n  assume vpsll: \"var p < length levellist\"\n  assume orderedt: \"ordered (Node lt p rt) var\"\n  assume marked_child_ll: \"\\<forall>n\\<in>set_of (Node lt p rt).\n           if mark n = mark p\n           then n \\<in> set (ll ! var n) \\<and>\n                (\\<forall>nt pa. Dag n low high nt \\<and> pa \\<in> set_of nt \\<longrightarrow> mark pa = mark p)\n           else n \\<notin> set (concat ll)\"\n  assume lt: \"Dag (low p) low high lt\"\n  assume rt: \"Dag (high p) low high rt\"\n  show \"wf_levellist (Node lt p rt) ll ll var \\<and>\n        wf_marking (Node lt p rt) mark mark (mark p)\"\n  proof -\n    from marked_child_ll pnN lt rt have marked_st:\n      \"(\\<forall>pa. pa \\<in> set_of (Node lt p rt) \\<longrightarrow> mark pa = mark p)\"\n      apply -\n      apply (drule_tac x=\"p\" in bspec)\n      apply  simp\n      apply (clarsimp)\n      apply (erule_tac x=\"(Node lt p rt)\" in allE)\n      apply simp\n      done\n    have nodest_in_ll:\n      \"\\<forall>q. q \\<in> set_of (Node lt p rt) \\<longrightarrow> q \\<in> set (ll ! var q)\"\n    proof -\n      from marked_child_ll pnN have pinll: \"p \\<in> set (ll ! var p)\"\n        apply -\n        apply (drule_tac x=\"p\" in bspec)\n        apply  simp\n        apply fastforce\n        done\n      from marked_st marked_child_ll lt rt show ?thesis\n        apply -\n        apply (rule allI)\n        apply (erule_tac x=\"q\" in allE)\n        apply (rule impI)\n        apply (erule impE)\n        apply  assumption\n        apply (drule_tac x=\"q\" in bspec)\n        apply  simp\n        apply fastforce\n        done\n    qed\n    have levellist_nc: \"\\<forall> i \\<le> var p. (\\<exists> prx. ll ! i = prx@(ll ! i) \\<and>\n      (\\<forall> pt \\<in> set prx. pt \\<in> set_of (Node lt p rt) \\<and> var pt = i))\"\n      apply -\n      apply (rule allI)\n      apply (rule impI)\n      apply (rule_tac x=\"[]\" in exI)\n      apply fastforce\n      done\n    have ll_nc: \"\\<forall> i. (var p) < i \\<longrightarrow> ll ! i = ll ! i\"\n      by fastforce\n    have length_ll: \"length ll = length ll\"\n      by fastforce\n    with ll_nc levellist_nc nodest_in_ll\n    have wf: \"wf_levellist (Node lt p rt) ll ll var\"\n      by (simp add: wf_levellist_def)\n    have m_nc: \"\\<forall> n. n \\<notin> set_of (Node lt p rt) \\<longrightarrow> mark n = mark n\"\n      by fastforce\n    from marked_st have \"\\<forall> n. n \\<in> set_of (Node lt p rt) \\<longrightarrow> mark n = mark p\"\n      by fastforce\n    with m_nc have \" wf_marking (Node lt p rt) mark mark (mark p)\"\n      by (simp add: wf_marking_def)\n    with wf show ?thesis\n      by fastforce\n  qed\nqed\n\nlemma allD: \"\\<forall>ll. P ll \\<Longrightarrow> P ll\"\n  by blast\n\nlemma replicate_spec: \"\\<lbrakk>\\<forall>i < n. xs ! i = x; n=length xs\\<rbrakk>\n  \\<Longrightarrow> replicate (length xs) x = xs\"\napply hypsubst_thin\napply (induct xs)\napply  simp\napply force\ndone\n\nlemma (in Levellist_impl) Levellist_spec_total:\nshows \"\\<forall>\\<sigma> t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\n        \\<lbrace>\\<sigma>. Dag \\<acute>p \\<acute>low \\<acute>high t \\<and> (\\<forall>i < length \\<acute>levellist. \\<acute>levellist ! i = Null) \\<and>\n             length \\<acute>levellist  = \\<acute>p \\<rightarrow> \\<acute>var + 1 \\<and>\n             ordered t \\<acute>var \\<and> (\\<forall>n \\<in> set_of t. \\<acute>mark n = (\\<not> \\<acute>m) )\\<rbrace>\n          \\<acute>levellist :== PROC Levellist (\\<acute>p, \\<acute>m, \\<acute>levellist)\n       \\<lbrace>\\<exists>ll. Levellist \\<acute>levellist \\<acute>next ll \\<and> wf_ll t ll \\<^bsup>\\<sigma>\\<^esup>var  \\<and>\n         length \\<acute>levellist = \\<^bsup>\\<sigma>\\<^esup>p \\<rightarrow> \\<^bsup>\\<sigma>\\<^esup>var + 1 \\<and>\n         wf_marking t \\<^bsup>\\<sigma>\\<^esup>mark \\<acute>mark \\<^bsup>\\<sigma>\\<^esup>m \\<and>\n         (\\<forall>p. p \\<notin> set_of t \\<longrightarrow> \\<^bsup>\\<sigma>\\<^esup>next p = \\<acute>next p)\\<rbrace>\"\napply (hoare_rule HoareTotal.conseq)\napply  (rule_tac ll=\"replicate (\\<^bsup>\\<sigma>\\<^esup>p\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>var + 1) []\" in allD [OF Levellist_spec_total'])\napply (intro allI impI)\napply (rule_tac x=\\<sigma> in exI)\napply (rule_tac x=t in exI)\napply (rule conjI)\napply  (clarsimp split:if_split_asm simp del: concat_replicate_trivial)\napply  (frule replicate_spec [symmetric])\napply   (simp)\napply  (clarsimp simp add: Levellist_def )\napply  (case_tac i)\napply   simp\napply  simp\napply (simp add: Collect_conv_if split:if_split_asm)\napply vcg_step\napply (elim exE conjE)\napply (rule_tac x=ll' in exI)\napply simp\napply (thin_tac \"\\<forall>p. p \\<notin> set_of t \\<longrightarrow> next p = nexta p\")\napply (simp add: wf_levellist_def wf_ll_def)\napply (case_tac \"t = Tip\")\napply  simp\napply  (rule conjI)\napply   clarsimp\napply   (case_tac k)\napply    simp\napply   simp\napply  (subgoal_tac \"length ll'=Suc (var Null)\")\napply   (simp add: Levellist_length)\napply  fastforce\napply (split dag.splits)\napply  simp\napply (elim conjE)\napply (intro conjI)\napply   (rule allI)\napply   (erule_tac x=\"pa\" in allE)\napply   clarify\nprefer 2\napply  (simp add: Levellist_length)\napply (rule allI)\napply (rule impI)\napply (rule ballI)\napply (rotate_tac 11)\napply (erule_tac x=\"k\" in allE)\napply (rename_tac dag1 ref dag2 k pa)\napply (subgoal_tac \"k <= var ref\")\nprefer 2\napply  (subgoal_tac \"ref = p\")\napply   simp\napply  clarify\napply  (erule_tac ?P = \"Dag p low high (Node dag1 ref dag2)\" in rev_mp)\napply  (simp (no_asm))\napply (rotate_tac 14)\napply (erule_tac x=k in allE)\napply clarify\napply (erule_tac x=k in allE)\napply clarify\napply (case_tac k)\napply  simp\napply simp\ndone\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/BDD/LevellistProof.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.546738151984614, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.2861738742885876}}
{"text": "(* Title: CTR/CTR.thy\n   Author: Mihails Milehins\n   Copyright 2021 (C) Mihails Milehins\n\nInfrastructure for the synthesis of the transfer rules and relativized \nconstants.\n*)\n\n\nsection\\<open>\\<open>CTR\\<close>\\<close>\ntheory CTR\n  imports \n    \"../UD/UD\"\n    \"HOL-Library.Conditional_Parametricity\"\n  keywords \"ctr_relator\" :: thy_defn\n    and \"ctr\" :: thy_defn\n    and \"trp\"\n    and \"synthesis\"\n    and \"relativization\"\n    and \"hybrid\"\n    and \"parametricity\"\nbegin\n\n\n\nsubsection\\<open>Import\\<close>\n\nML_file \"CTR_Relators.ML\"\nML_file \"CTR_Foundations.ML\"\nML_file \"CTR_Algorithm.ML\"\nML_file \"CTR_Conversions.ML\"\nML_file \"CTR_Relativization.ML\"\nML_file \"CTR_Parametricity.ML\"\nML_file \"CTR_Postprocessing.ML\"\nML_file \"CTR.ML\"\n\n\n\nsubsection\\<open>Rewriting\\<close>\n\nnamed_theorems ctr_blank\nnamed_theorems ctr_simps\n\nlemma ctr_simps_pred_fun_top_eq_range[ctr_simps]: \n  \"pred_fun top (\\<lambda>x. x \\<in> R) f = (range f \\<subseteq> R)\"\n  by auto\nlemma ctr_simps_pred_prod_eq_cart[ctr_simps]: \n  \"pred_prod (\\<lambda>x. x \\<in> A) (\\<lambda>x. x \\<in> B) = (\\<lambda>x. x \\<in> A \\<times> B)\"\n  by auto\nlemma ctr_simps_pred_fun_eq_image[ctr_simps]: \n  \"pred_fun (\\<lambda>x. x \\<in> D) (\\<lambda>x. x \\<in> R) f \\<longleftrightarrow> (f ` D \\<subseteq> R)\"\n  by auto\nlemma ctr_simps_in_iff[ctr_simps]: \"(\\<forall>x\\<in>A. x \\<in> U) \\<longleftrightarrow> A \\<subseteq> U\" by auto\nlemma ctr_simps_subset_pow_iff[ctr_simps]: \"(\\<forall>A\\<in>S. A \\<subseteq> U) \\<longleftrightarrow> S \\<subseteq> Pow U\" \n  by auto\nlemma ctr_simps_subset_pow_iff'[ctr_simps]: \n  \"(\\<forall>A. A \\<in> S \\<longrightarrow> A \\<subseteq> U) \\<longleftrightarrow> S \\<subseteq> Pow U\" \n  by auto\nlemma ctr_simps_subset_pow_iff''[ctr_simps]: \"(S \\<subseteq> {S. S \\<subseteq> U}) \\<longleftrightarrow> S \\<subseteq> Pow U\" \n  by (simp add: subset_eq)\nlemma ctr_simps_range_ss_iff[ctr_simps]: \"(\\<forall>x. f x \\<in> U) \\<longleftrightarrow> range f \\<subseteq> U\" \n  by auto\nlemma ctr_simps_range_pow_ss_iff[ctr_simps]: \"(\\<forall>x. f x \\<subseteq> U) \\<longleftrightarrow> range f \\<subseteq> Pow U\" \n  by auto\nlemma ctr_simps_Ball_def'[ctr_simps]: \"(\\<forall>x. x \\<in> A \\<longrightarrow> P x) \\<longleftrightarrow> (\\<forall>x \\<in> A. P x)\" \n  by auto\nlemma ctr_simps_True_imp[ctr_simps]: \"(True \\<longrightarrow> A) \\<longleftrightarrow> A\" by simp\nlemma ctr_simps_True_conj[ctr_simps]: \"(True \\<and> A) \\<longleftrightarrow> A\" by simp\nlemma ctr_simps_conj_True[ctr_simps]: \"(A \\<and> True) \\<longleftrightarrow> A\" by simp\nlemma ctr_simps_top_True[ctr_simps]: \"top A \\<longleftrightarrow> True\" by auto\nlemma ctr_simps_Ball_True[ctr_simps]: \"(\\<forall>x\\<in>U. True) \\<longleftrightarrow> True\" by auto\nlemma ctr_simps_Ball_UNIV[ctr_simps]: \"(\\<forall>n\\<in>UNIV. A n) \\<longleftrightarrow> (\\<forall>n. A n)\" by simp\nlemma ctr_simps_Bex_UNIV[ctr_simps]: \"(\\<exists>n\\<in>UNIV. A n) \\<longleftrightarrow> (\\<exists>n. A n)\" by simp\nlemma ctr_simps_subset_Pow[ctr_simps]: \"{A. A \\<subseteq> U} = Pow U\" by blast\nlemma ctr_simps_mem_Collect_eq[ctr_simps]: \"(a \\<in> Collect P) = P a\"\n  by (rule mem_Collect_eq)\nlemma ctr_simps_relation_top_empty_eq[ctr_simps]: \"(\\<lambda>x. x \\<in> UNIV) = top\" \n  by auto\nlemma ctr_simps_pred_fun_eq[ctr_simps]: \n  \"pred_fun A B = (\\<lambda>f. \\<forall>x. A x \\<longrightarrow> B (f x))\" \n  by simp\nlemma ctr_simps_subset_eq_sym[ctr_simps]: \"(\\<forall>x\\<in>A. x \\<in> B) \\<longleftrightarrow> (A \\<subseteq> B)\" by auto\nlemma ctr_simps_UNIV_I[ctr_simps]: \"x \\<in> UNIV\" by simp\nlemma ctr_simps_UNIV_def[ctr_simps]: \"{x. True} = UNIV\" by simp\nlemma ctr_simps_conj_commute[ctr_simps]: \"(P \\<and> Q) \\<longleftrightarrow> (Q \\<and> P)\" by auto\nlemma ctr_simps_conj_absorb[ctr_simps]: \"(A \\<and> A) \\<longleftrightarrow> A\" by simp\nlemma ctr_simps_conj_left_absorb[ctr_simps]: \"(A \\<and> A \\<and> B) \\<longleftrightarrow> (A \\<and> B)\" by simp\nlemma ctr_simps_inf_idem[ctr_simps]: \"inf a a = (a::'a::semilattice_inf)\" \n  by simp\nlemma ctr_simps_sup_idem[ctr_simps]: \"sup a a = (a::'a::semilattice_sup)\" \n  by simp\nlemma ctr_simps_inf_assoc[ctr_simps]: \n  \"inf (inf a b) c = inf (a::'a::semilattice_inf) (inf b c)\"\n  by (auto simp: semilattice_inf_class.inf.assoc)\nlemma ctr_simps_sup_assoc[ctr_simps]:\n  \"sup (sup a b) c = sup (a::'a::semilattice_sup) (sup b c)\"\n  by (auto simp: semilattice_sup_class.sup.assoc)\nlemma ctr_simps_Collect_mem_eq[ctr_simps]: \"{x. x \\<in> U} = U\" by simp\n\n\n\nsubsection\\<open>tts relators\\<close>\n\nctr_relator rel_set\nctr_relator rel_filter\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Conditional_Transfer_Rule/CTR/CTR.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.28617387428858754}}
{"text": "theory ContractGeneration\nimports Contracts\nbegin\n\nfun map_of_eqs :: \"form \\<Rightarrow> (var \\<rightharpoonup> expr)\" where\n  \"map_of_eqs ((f_eq (VarE v) e)\\<^emph>f) = (map_of_eqs f)(v\\<mapsto>e)\"\n| \"map_of_eqs _ = Map.empty\"\n\nfun update_var_eq_after :: \"form \\<Rightarrow> (expr\\<rightharpoonup>expr) \\<Rightarrow> form\" where\n  \"update_var_eq_after (f_eq x y) arg_to_new_expr = \n    (case arg_to_new_expr x of Some a \\<Rightarrow> f_eq x a | None \\<Rightarrow> f_eq x y)\"\n| \"update_var_eq_after ((f_eq x y)\\<^emph>rest) arg_to_new_expr = \n    ((case arg_to_new_expr x of Some a \\<Rightarrow> f_eq x a | None \\<Rightarrow> f_eq x y)\n    \\<^emph>(update_var_eq_after rest arg_to_new_expr))\"\n| \"update_var_eq_after f _ = f\"\n\ndefinition (in sound_separation_logic) bap :: \"var set \\<Rightarrow> var set \\<Rightarrow> form \\<Rightarrow> form \\<Rightarrow> form \\<Rightarrow> form \\<Rightarrow> form \\<Rightarrow> bool\" where\n  \"bap args Uq Qfree Qeq C M F \\<equiv> entails (Qfree\\<^emph>M) (add_prenex (sorted_list_of_set ((free_vars C \\<union> free_vars F)\n    -(free_vars Qfree \\<union> free_vars Qeq \\<union> free_vars M))) (C\\<^emph>F))\n  \\<and> quantifree_symb_heap M \\<and> quantifree_symb_heap F\n  \\<and> free_vars M \\<subseteq> UNIV - args - Uq \\<and> free_vars F \\<inter> args = {}\"\n\nlocale generation_ctxt = program_logic +\n  fixes bap_solver :: \"var set \\<Rightarrow> var set \\<Rightarrow> form \\<Rightarrow> form \\<Rightarrow> form \\<Rightarrow> (form\\<times>form)\" and pvars :: \"var list\"\n  assumes bap_solution: \"\\<forall>Uq Qf Qeq C M F. bap_solver (set pvars) Uq Qf Qeq C = (M,F) \n    \\<longleftrightarrow> bap (set pvars) Uq Qf Qeq C M F\"\nbegin\n\ntext \\<open>This is what's called biabduct(P,Q,g(a1,...,an),C,D) but with slightly different argument order.\\<close>\ndefinition biabduction_step :: \"(contract\\<times>(var list)) \\<Rightarrow> (form\\<times>form) \\<Rightarrow> (form\\<times>form) option\" where\n  \"biabduction_step func_call PQ = (case PQ of (P,Q) \\<Rightarrow>\n    (case func_call of (contr, call_args) \\<Rightarrow>\n    (case raw_contract contr of ([(C,[D])],f) \\<Rightarrow>\n    (case strip_prenex Q of (Uq, Qf\\<^emph>Qeq) \\<Rightarrow> \n    \\<comment> \\<open>Rename logical variables\\<close>\n    (let (C1,vs) = rename_vars C (free_vars P - (set pvars)) VarE in\n    (let (D',_) = rename_vars D (free_vars P - (set (pvars))) vs in\n    (case strip_prenex D' of (_, Df\\<^emph>Deq) \\<Rightarrow> \n    \\<comment> \\<open>Substitute the arguments for the parameters\\<close>\n    (let (C2,_) = rename_vars_option C1 {} ((map_of_eqs Qeq) \\<circ>\\<^sub>m (map_of (zip (snd f) call_args))) in\n    \\<comment> \\<open>Do biabduction and construct the next intermediate contract\\<close>\n    (let (M,F) = bap_solver (set pvars) Uq Qf Qeq C2 in\n    (let P_after = M \\<^emph> P in\n    (let Qf' = F \\<^emph> Df in\n    (let Qeq' = update_var_eq_after Qeq ((map_of_eqs Deq) \\<circ>\\<^sub>m (map_of (zip (map VarE call_args) (snd f)))) in\n    (let Uq_after = (free_vars Qf' \\<union> free_vars Qeq') - (set pvars) - free_vars P_after in\n    (let Q_after = add_prenex (sorted_list_of_set Uq_after) (Qf'\\<^emph>Qeq') in\n    Some (P_after,Q_after))))))))\n  | _ \\<Rightarrow> None))) | _ \\<Rightarrow> None) | _ \\<Rightarrow> None)))\"\nend\n\ntext \\<open>As in 6.3.1 we assume a function body as a sequence of calls to functions for which we already \n  have the (conjunctive) contracts.\\<close>\nlocale sequential = generation_ctxt +\n  fixes func_body :: \"(contract\\<times>(var list)) list\"\n  assumes non_empty: \"func_body \\<noteq> []\" and conj: \"list_all (conjunctive \\<circ> fst) func_body\"\n  and simple: \"list_all (\\<lambda>c. (\\<exists>c'. fst (raw_contract (fst c)) = [c'])) func_body\"\n  and well_formed: \"list_all (\\<lambda>c. set (snd c) \\<subseteq> set (pvars) \\<and> distinct (snd c)) func_body\"\nbegin\nfun symbolic_execution :: \"(contract\\<times>(var list)) list \\<Rightarrow> (form\\<times>form) \\<Rightarrow> (form\\<times>form) option\" where\n  \"symbolic_execution [] (P,Q) = Some (P,Q)\"\n| \"symbolic_execution (func_call#rest) (P,Q) = (case biabduction_step func_call (P,Q) \n    of Some (P_after,Q_after) \\<Rightarrow> symbolic_execution rest (P_after,Q_after) | _ \\<Rightarrow> None)\"\n\nfun build_initial :: \"var list \\<Rightarrow> var set \\<Rightarrow> form\" where\n  \"build_initial [] _ = Emp\"\n| \"build_initial (x#vs) used = (let X = fresh used in (f_eq x X)\\<^emph>(build_initial vs (insert X used)))\"\n\ndefinition initialP :: form where\n  \"initialP \\<equiv> simplify_emp_sepconj (build_initial pvars (set pvars))\"\n\ntext \\<open>This is Theorem 3, but I won't prove it yet. This would be way to much work for now.\\<close>\nlemma \"symbolic_execution func_body (initialP, initialP) = Some (P,Q) \\<Longrightarrow>\n  sound (Contract ([(P,[Q])], (f,pvars)))\"\n  sorry\nend\n\ntype_synonym symb_map = \"CFG_node \\<Rightarrow> (form\\<times>form) list\"\naxiomatization P_init Q_init :: form\n\nabbreviation add_prenex_wo_pvars :: \"var set \\<Rightarrow> form \\<Rightarrow> form\" where\n  \"add_prenex_wo_pvars pvars P \\<equiv> add_prenex (sorted_list_of_set (free_vars P - pvars)) P\"\n\ndefinition (in sound_separation_logic) covers :: \"var set \\<Rightarrow> form \\<Rightarrow> form \\<Rightarrow> form \\<Rightarrow> form \\<Rightarrow> bool\" where\n  \"covers pvars P Q P' Q' \\<equiv> \n    entails (add_prenex_wo_pvars pvars P) (add_prenex_wo_pvars pvars P') \\<and>\n    entails (add_prenex_wo_pvars pvars Q') (add_prenex_wo_pvars pvars Q)\"\n\nlocale loops_allowed = generation_ctxt +\n  fixes func_body :: \"(CFG_node \\<times> string \\<times> var list \\<times> CFG_node) set\" and contracts :: \"string \\<Rightarrow> contract\"\n  and cut_points :: \"CFG_node set\" and widening :: \"form \\<Rightarrow> form\"\n  assumes sound_contracts: \"\\<forall>f. sound (contracts f)\"\nbegin\n\ndefinition init_symb :: symb_map where \"init_symb \\<equiv> (\\<lambda>_. [])(entry := [(P_init,Q_init)])\"\n\ntext \\<open>Given a worklist of nodes and the symb_maps, relate them to the next worklist and the updated\n  symb maps.\\<close>\ninductive symbolic_execution :: \"CFG_node set \\<Rightarrow> symb_map \\<Rightarrow> CFG_node set \\<Rightarrow> symb_map \\<Rightarrow> bool\" where\n  \"\\<lbrakk>v\\<in>worklist; sm v = (P,Q)#sm_v; \\<forall>f f_args v'. (v,f,f_args,v') \\<in> func_body \\<longrightarrow> \n    insert v' (ws-{v}) \\<subseteq> worklist_after \\<and>\n    (\\<forall>(C,Ds) \\<in> set (fst (raw_contract (contracts f))). \n    (\\<forall>D\\<in>set Ds.\n    (\\<forall>P_after Q_after. Some (P_after,Q_after) = \n      biabduction_step (Contract ([(C,[D])],snd (raw_contract (contracts f))), f_args) (P,Q) \\<longrightarrow>\n    (v'\\<notin>cut_points \\<longrightarrow> (sm_after v = sm_v \\<and> sm_after v' = (sm v')@[(P_after,Q_after)])) \\<and>\n    (v\\<in>cut_points \\<and> (\\<exists>P' Q'. ((P',Q')\\<in> set (sm v') \\<and> covers (set pvars) P_after Q_after P' Q') \n      \\<longrightarrow> (sm_after v = sm_v \\<and> sm_after v' = sm v')) \\<and> \n    (\\<nexists>P' Q'. ((P',Q')\\<in> set (sm v') \\<and> covers (set pvars) P_after Q_after P' Q') \n      \\<longrightarrow> (sm_after v = sm_v \\<and> sm_after v' = sm v'@[(widening P_after, widening Q_after)]))))))\\<rbrakk>\n    \\<Longrightarrow> symbolic_execution worklist sm worklist_after sm_after\"\nend\nend", "meta": {"author": "firefighterduck", "repo": "isabroom", "sha": "f260dfab2f1f6854986d3c337e3d00ab7728aa26", "save_path": "github-repos/isabelle/firefighterduck-isabroom", "path": "github-repos/isabelle/firefighterduck-isabroom/isabroom-f260dfab2f1f6854986d3c337e3d00ab7728aa26/ContractGeneration.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7025300449389326, "lm_q2_score": 0.40733340004593027, "lm_q1q2_score": 0.2861639518393956}}
{"text": "(*\n    Author:      David Sanan\n    Maintainer:  David Sanan, sanan at ntu edu sg\n    License:     LGPL\n*)\n\n(*  Title:      LocalRG_HoareDef.thy\n    Author:     David Sanan, NTU\n\nCopyright (C) 2015-2016 David Sanan \nSome rights reserved, NTU\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\ntheory LocalRG_HoareDefValidityN          \nimports \"SmallStepCon\" \"../EmbSimpl/HoarePartialProps\" \nbegin\nsection \\<open>Validity  of Correctness Formulas\\<close>\n\nsubsection \\<open>Aux\\<close>\nlemma tl_pair:\"Suc (Suc j) < length l \\<Longrightarrow>     \n       l1 = tl l \\<Longrightarrow>\n       P (l!(Suc j)) (l!(Suc (Suc j)))=\n       P  (l1!j) (l1!(Suc j))\"\nby (simp add: tl_zero_eq)\n\nlemma for_all_k_sublist:\nassumes a0:\"Suc (Suc j)<length l\" and\n      a1:\"(\\<forall>k < j. P ((tl l)!k) ((tl l)!(Suc k)))\" and\n      a2:\"P (l!0) (l!(Suc 0))\" \nshows \"(\\<forall>k < Suc j.  P (l!k) (l!(Suc k)))\"\nproof -\n  {fix k\n   assume aa0:\"k < Suc j\"\n   have \"P (l!k) (l!(Suc k))\"\n   proof (cases k)\n     case 0 thus ?thesis using a2 by auto\n   next\n     case (Suc k1) thus ?thesis using aa0 a0 a1 a2\n       by (metis SmallStepCon.nth_tl Suc_less_SucD dual_order.strict_trans length_greater_0_conv nth_Cons_Suc zero_less_Suc)\n   qed\n  } thus ?thesis by auto\nqed\n\n\nsubsection \\<open>Validity for Component Programs.\\<close>\n\ntype_synonym ('s,'f) tran = \"('s,'f) xstate \\<times> ('s,'f) xstate\"\ntype_synonym ('s,'p,'f) rgformula =  \n   \"(('s,'p,'f) com \\<times>      (* c *)\n    ('s set) \\<times>     (* P *)    \n    (('s,'f) tran) set \\<times> (* R *)\n    (('s,'f) tran) set \\<times> (* G *)\n    ('s set) \\<times> (* Q *)\n    ('s set))\" (* A *)\n    \ntype_synonym ('s,'p,'f) sextuple =  \n   \"('p \\<times>      (* c *)\n    ('s set) \\<times>     (* P *)    \n    (('s,'f) tran) set \\<times> (* R *)\n    (('s,'f) tran) set \\<times> (* G *)\n    ('s set) \\<times> (* Q *)\n    ('s set))\" (* A *)    \n\ndefinition Sta :: \"'s set \\<Rightarrow> (('s,'f) tran) set \\<Rightarrow> bool\" where\n  \"Sta \\<equiv> \\<lambda>f g. (\\<forall>x y x'. x' \\<in> f \\<and> x=Normal x' \\<longrightarrow>  (x,y)\\<in> g \\<longrightarrow> (\\<exists>y'. y=Normal y' \\<and> y' \\<in> f))\"\n\n\ndefinition Norm:: \"(('s,'f) tran) set \\<Rightarrow> bool\" where\n  \"Norm \\<equiv> \\<lambda>g. (\\<forall>x y. (x, y) \\<in> g \\<longrightarrow> (\\<exists>x' y'. x=Normal x' \\<and> y=Normal y'))\"\n\ndefinition env_tran::\n    \"('p \\<Rightarrow> ('s, 'p, 'f) LanguageCon.com option)\n     \\<Rightarrow> ('s set)\n        \\<Rightarrow> (('s, 'p, 'f) LanguageCon.com \\<times> ('s, 'f) xstate) list\n           \\<Rightarrow> ('s,'f) tran set \\<Rightarrow> bool\"\nwhere\n\"env_tran \\<Gamma> q l rely \\<equiv> snd(l!0) \\<in> Normal ` q \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                  \n                   (snd(l!i), snd(l!(Suc i))) \\<in> rely)\n\"\n\ndefinition env_tran_right::\n    \"('p \\<Rightarrow> ('s, 'p, 'f) LanguageCon.com option)     \n        \\<Rightarrow> (('s, 'p, 'f) LanguageCon.com \\<times> ('s, 'f) xstate) list\n           \\<Rightarrow> ('s,'f) tran set \\<Rightarrow> bool\"\nwhere\n\"env_tran_right \\<Gamma> l rely \\<equiv> \n   (\\<forall>i. Suc i<length l \\<longrightarrow> \n        \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                  \n        (snd(l!i), snd(l!(Suc i))) \\<in> rely)\n\"\n\nlemma env_tran_tail:\"env_tran_right \\<Gamma> (x#l) R \\<Longrightarrow> env_tran_right \\<Gamma> l R\"\nunfolding env_tran_right_def\nby fastforce\n\nlemma env_tran_subr:\nassumes a0:\"env_tran_right \\<Gamma> (l1@l2) R\"\nshows \"env_tran_right \\<Gamma> l1 R\"\nunfolding env_tran_right_def\nproof -\n  {fix i\n  assume a1:\"Suc i< length l1\"\n  assume a2:\"\\<Gamma>\\<turnstile>\\<^sub>c l1 ! i \\<rightarrow>\\<^sub>e l1 ! Suc i\"\n  then have \"Suc i < length (l1@l2)\" using a1 by fastforce\n  also then have \"\\<Gamma>\\<turnstile>\\<^sub>c (l1@l2) ! i \\<rightarrow>\\<^sub>e (l1@l2) ! Suc i\" \n  proof -\n    show ?thesis\n      by (simp add: Suc_lessD a1 a2 nth_append)\n  qed\n  ultimately have f1:\"(snd ((l1@l2)! i), snd ((l1@l2) ! Suc i)) \\<in> R\"\n  using a0 unfolding env_tran_right_def by auto\n  then have \"(snd (l1! i), snd (l1 ! Suc i)) \\<in>  R\"\n  using a1\nproof -\n  have \"\\<forall>ps psa n. if n < length ps then (ps @ psa) ! n = (ps ! n::('b, 'a, 'c) LanguageCon.com \\<times> ('b, 'c) xstate) else (ps @ psa) ! n = psa ! (n - length ps)\"\n    by (meson nth_append)\n  then show ?thesis\n    using f1 \\<open>Suc i < length l1\\<close> by force\nqed \n  } then show \n   \"\\<forall>i. Suc i < length l1 \\<longrightarrow>\n        \\<Gamma>\\<turnstile>\\<^sub>c l1 ! i \\<rightarrow>\\<^sub>e l1 ! Suc i \\<longrightarrow>\n        (snd (l1 ! i), snd (l1 ! Suc i)) \\<in> R\"\n   by blast\nqed\n  \n\nlemma env_tran_subl:\"env_tran_right \\<Gamma> (l1@l2) R \\<Longrightarrow> env_tran_right \\<Gamma> l2 R\"\nproof (induct \"l1\")\n  case Nil thus ?case by auto\nnext\n  case (Cons a l1) thus ?case by (fastforce intro:append_Cons env_tran_tail )\nqed\n\nlemma env_tran_R_R':\"env_tran_right \\<Gamma> l R \\<Longrightarrow>  \n                     (R  \\<subseteq> R') \\<Longrightarrow>\n                     env_tran_right \\<Gamma> l R'\"\nunfolding env_tran_right_def Satis_def sep_conj_def\napply clarify\napply (erule allE)\napply auto\ndone\n\n\n(* lemma skip_fault_tran_false:\nassumes a0:\"(\\<Gamma>,l) \\<in> cptn\" and\n        a1:\"Suc i<length l \\<and> l!i=(Skip, t) \\<and> (\\<forall>t'. \\<not>(t=Normal t'))\" and\n        a2: \"env_tran_right \\<Gamma> l rely \\<and> Norm rely\" and \n        a3: \"\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>c\\<^sub>e (l!(Suc i))\"\nshows \"P\"\nproof -\n  from a3 have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<or> \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i))\"\n  using step_ce_elim_cases by blast\n  thus ?thesis\n  proof\n    assume \"\\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow>\\<^sub>e (l ! Suc i)\"\n    thus ?thesis using a2 a1 unfolding env_tran_right_def Norm_def by fastforce\n  next\n    assume \"\\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow> (l ! Suc i)\"\n    thus ?thesis using a1 by (metis (full_types) stepc_elim_cases(1)) \n  qed \nqed *)\n\n(* lemma skip_fault_last:\nassumes a0:\"(\\<Gamma>,l) \\<in> cptn\" and\n        a1:\"(i< (length l)) \\<and> (l!i)=(Skip, t) \\<and> (\\<forall>t'. \\<not>(t=Normal t'))\" and\n        a2: \"env_tran_right \\<Gamma> l rely \\<and> Norm rely\" \nshows \"i=((length l)-1)\"\nproof (cases \"i = ((length l)-1)\")\n  case True thus ?thesis .\nnext\n  case False \n  have \"0 < length l\" using a1 by auto\n  then obtain x xs where l:\"l=x#xs\"\n    by (meson gr0_conv_Suc length_Suc_conv) \n  then have suci:\"Suc i < length l\" using False a1 by fastforce\n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>c\\<^sub>e (l!(Suc i))\" \n    using a0 a1 cptn_stepc_rtran l by blast\n  thus ?thesis using a0 a1 a2 skip_fault_tran_false suci by blast    \nqed *)\n\nlemma env_tran_normal:\nassumes a0:\"env_tran_right \\<Gamma> l rely \\<and> Sta q rely \\<and>  snd(l!i) = Normal s1 \\<and> s1\\<in>q\" and\n        a1:\"Suc i < length l \\<and>  \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i))\"\nshows \"\\<exists>s1 s2. snd(l!i) = Normal s1 \\<and> snd(l!(Suc i)) = Normal s2 \\<and> s2\\<in>q\"\nusing a0 a1 unfolding env_tran_right_def Sta_def by fastforce\n\nlemma no_env_tran_not_normal:\nassumes a0:\"env_tran_right \\<Gamma> l rely \\<and> Sta q rely \\<and>  snd(l!i) = Normal s1 \\<and> s1\\<in>q\" and\n        a1:\"Suc i < length l \\<and>  \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i))\" and\n        a2:\"(\\<forall>s1. \\<not> (snd(l!i) = Normal s1)) \\<or> (\\<forall>s2. \\<not> (snd (l!Suc i) = Normal s2))\"\nshows \"P\"\nusing a0 a1 a2 unfolding env_tran_right_def Sta_def by fastforce \n \ndefinition assum :: \n  \"('s set \\<times> ('s,'f) tran set) \\<Rightarrow>\n   'f set \\<Rightarrow>\n     (('s,'p,'f) confs) set\" where\n  \"assum \\<equiv> \\<lambda>(pre, rely) F. \n             {c. snd((snd c)!0) \\<in> Normal ` pre \\<and> \n                 (\\<forall>i. Suc i<length (snd c) \\<longrightarrow> \n                 (fst c)\\<turnstile>\\<^sub>c((snd c)!i)  \\<rightarrow>\\<^sub>e ((snd c)!(Suc i)) \\<longrightarrow>                  \n                   (snd((snd c)!i), snd((snd c)!(Suc i))) \\<in>  rely)}\"\n\ndefinition assum1 :: \n  \"('s set \\<times> ('s,'f) tran set) \\<Rightarrow>\n   'f set \\<Rightarrow>\n     (('s,'p,'f) confs) set\" where\n  \"assum1 \\<equiv> \\<lambda>(pre, rely) F. \n             {(\\<Gamma>,comp). snd(comp!0) \\<in> Normal ` pre \\<and> \n                 (\\<forall>i. Suc i<length comp \\<longrightarrow> \n                  \\<Gamma>\\<turnstile>\\<^sub>c(comp!i)  \\<rightarrow>\\<^sub>e (comp!(Suc i)) \\<longrightarrow>                  \n                   (snd(comp!i), snd(comp!(Suc i))) \\<in>  rely)}\"\n\n\nlemma assum_R_R': \n  \"(\\<Gamma>, l) \\<in> assum(p, R) F \\<Longrightarrow>\n    snd(l!0) \\<in> Normal `  p' \\<Longrightarrow>\n    R \\<subseteq> R'  \\<Longrightarrow> \n   (\\<Gamma>, l) \\<in> assum(p', R') F\"\nproof -\nassume a0:\"(\\<Gamma>, l) \\<in> assum(p, R) F\" and\n       a1:\"snd(l!0) \\<in> Normal `  p'\" and\n       a2: \" R \\<subseteq> R'\"\n  then have \"env_tran_right \\<Gamma> l R\" \n    unfolding assum_def using env_tran_right_def\n    by force\n  then have \"env_tran_right \\<Gamma> l R'\" \n    using  a2 env_tran_R_R' by blast\n  thus ?thesis using a1 unfolding assum_def unfolding env_tran_right_def\n    by fastforce\nqed\n\n\nlemma same_prog_p:\n  \"(\\<Gamma>,(P,s)#(P,t)#l)\\<in>cptn \\<Longrightarrow>\n   (\\<Gamma>,(P,s)#(P,t)#l) \\<in> assum (p,R) F \\<Longrightarrow>\n   Sta p R  \\<Longrightarrow>\n   \\<exists>t1. t=Normal t1 \\<and> t1 \\<in> p\n  \" \nproof -\nassume a0: \"(\\<Gamma>,(P,s)#(P,t)#l)\\<in>cptn\" and\n         a1: \"(\\<Gamma>,(P,s)#(P,t)#l) \\<in> assum (p,R) F\" and\n         a2: \"Sta p R\"\n  then have \"Suc 0 < length ((P,s)#(P,t)#l)\" \n    by fastforce\n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c(((P,s)#(P,t)#l)!0)  \\<rightarrow>\\<^sub>c\\<^sub>e (((P,s)#(P,t)#l)!(Suc 0))\" \n    using a0 cptn_stepc_rtran by fastforce \n  then have step_ce:\"\\<Gamma>\\<turnstile>\\<^sub>c(((P,s)#(P,t)#l)!0)  \\<rightarrow>\\<^sub>e (((P,s)#(P,t)#l)!(Suc 0)) \\<or>\n             \\<Gamma>\\<turnstile>\\<^sub>c(((P,s)#(P,t)#l)!0)  \\<rightarrow> (((P,s)#(P,t)#l)!(Suc 0))\"\n    using step_ce_elim_cases by blast  \n  then obtain s1 where s:\"s=Normal s1 \\<and> s1 \\<in> p\" \n    using a1 unfolding assum_def\n    by fastforce\n  have \"\\<exists>t1. t=Normal t1 \\<and> t1 \\<in> p \"\n  using step_ce\n  proof\n    {assume step_e:\"\\<Gamma>\\<turnstile>\\<^sub>c ((P, s) # (P, t) # l) ! 0 \\<rightarrow>\\<^sub>e\n          ((P, s) # (P, t) # l) ! Suc 0\"\n     have ?thesis \n     using a2 a1 s unfolding Sta_def assum_def \n     proof -\n       have \"(Suc 0 < length ((P, s) # (P, t) # l))\"\n         by fastforce\n       then have assm:\"(s, t) \\<in> R\"\n         using s a1 step_e\n         unfolding assum_def  by fastforce\n       then obtain t1 s2 where s_t:\"s= Normal s2 \\<and> t = Normal t1\" \n         using a2 s unfolding Sta_def by fastforce \n       then have R:\"(s,t)\\<in>R\" \n         using assm  unfolding Satis_def by fastforce\n       then have \"s2=s1\" using s s_t by fastforce\n       then have \"t1\\<in>p\" \n         using a2 s s_t R unfolding Sta_def Norm_def by blast\n       thus ?thesis using s_t by blast\n     qed thus ?thesis by auto\n    } \n    next\n    { \n      assume step:\"\\<Gamma>\\<turnstile>\\<^sub>c ((P, s) # (P, t) # l) ! 0 \\<rightarrow>\n          ((P, s) # (P, t) # l) ! Suc 0\"\n      then have \"P\\<noteq>P \\<or> s=t\"\n      proof -\n        have \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow> (P, t)\"\n          using local.step by force\n        then show ?thesis\n          using step_change_p_or_eq_s by blast\n      qed\n      then show ?thesis using s by fastforce\n    }\n  qed thus  ?thesis by auto\nqed\n\nlemma tl_of_assum_in_assum:\n  \"(\\<Gamma>,(P,s)#(P,t)#l)\\<in>cptn \\<Longrightarrow>\n   (\\<Gamma>,(P,s)#(P,t)#l) \\<in> assum (p,R) F \\<Longrightarrow>\n   Sta p R  \\<Longrightarrow>\n   (\\<Gamma>,(P,t)#l) \\<in> assum (p,R) F\n  \" \nproof -\n  assume a0: \"(\\<Gamma>,(P,s)#(P,t)#l)\\<in>cptn\" and\n         a1: \"(\\<Gamma>,(P,s)#(P,t)#l) \\<in> assum (p,R) F\" and\n         a2: \"Sta p R \"\n  \n  then obtain t1 where t1:\"t=Normal t1 \\<and> t1 \\<in>p\" \n   using same_prog_p by blast\n  then have \"env_tran_right \\<Gamma> ((P,s)#(P,t)#l) R\"\n    using env_tran_right_def a1 unfolding assum_def\n    by force\n  then have \"env_tran_right \\<Gamma> ((P,t)#l) R\"\n    using env_tran_tail by auto\n  thus ?thesis using t1 unfolding assum_def env_tran_right_def by auto\nqed\n\nlemma tl_of_assum_in_assum1:\n  \"(\\<Gamma>,(P,s)#(Q,t)#l)\\<in>cptn \\<Longrightarrow>\n   (\\<Gamma>,(P,s)#(Q,t)#l) \\<in> assum (p,R) F \\<Longrightarrow>\n   t \\<in> Normal ` q \\<Longrightarrow>\n   (\\<Gamma>,(Q,t)#l) \\<in> assum (q,R) F\n  \" \nproof -\n  assume a0: \"(\\<Gamma>,(P,s)#(Q,t)#l)\\<in>cptn\" and\n         a1: \"(\\<Gamma>,(P,s)#(Q,t)#l) \\<in> assum (p,R) F\" and\n         a2: \"t \\<in> Normal ` q\"  \n  then have \"env_tran_right \\<Gamma> ((P,s)#(Q,t)#l) R\"\n    using env_tran_right_def a1 unfolding assum_def\n    by force\n  then have \"env_tran_right \\<Gamma> ((Q,t)#l) R\"\n    using env_tran_tail by auto\n  thus ?thesis using a2 unfolding assum_def env_tran_right_def by auto\nqed\n            \nlemma sub_assum:\n  assumes a0: \"(\\<Gamma>,(x#l0)@l1) \\<in> assum (p,R) F\"\n  shows \"(\\<Gamma>,x#l0) \\<in> assum (p,R) F\"    \nproof -\n  {have p0:\"snd x \\<in> Normal ` p\" \n    using a0 unfolding assum_def by force\n  then have \"env_tran_right \\<Gamma> ((x#l0)@l1) R\"\n    using a0 unfolding assum_def \n    by (auto simp add: env_tran_right_def)\n  then have env:\"env_tran_right \\<Gamma> (x#l0) R\" \n    using env_tran_subr by blast \n  also have \"snd ((x#l0)!0)  \\<in> Normal ` p\" \n    using p0 by fastforce\n  ultimately have \"snd ((x#l0)!0)  \\<in> Normal ` p \\<and> \n                  (\\<forall>i. Suc i<length (x#l0) \\<longrightarrow> \n                       \\<Gamma>\\<turnstile>\\<^sub>c((x#l0)!i)  \\<rightarrow>\\<^sub>e ((x#l0)!(Suc i)) \\<longrightarrow>                  \n                       (snd((x#l0)!i), snd((x#l0)!(Suc i))) \\<in> R)\"\n   unfolding env_tran_right_def by auto\n  }    \n  then show ?thesis  unfolding assum_def by auto\nqed      \n\nlemma sub_assum_r:\n  assumes a0: \"(\\<Gamma>,l0@x1#l1) \\<in> assum (p,R) F\" and\n          a1: \"(snd x1) \\<in> Normal ` q\"\n  shows \"(\\<Gamma>,x1#l1) \\<in> assum (q,R) F\"\nproof -\n  have \"env_tran_right  \\<Gamma> (l0@x1#l1) R\"\n    using a0 unfolding assum_def env_tran_right_def\n    by fastforce\n  then have \"env_tran_right \\<Gamma> (x1#l1) R\"\n    using env_tran_subl by auto\n  thus ?thesis using a1 unfolding assum_def env_tran_right_def by fastforce\nqed\n\ndefinition comm :: \n  \"(('s,'f) tran) set \\<times> \n   ('s set \\<times> 's set) \\<Rightarrow>\n   'f set \\<Rightarrow> \n     (('s,'p,'f) confs) set\" where\n  \"comm \\<equiv> \\<lambda>(guar, (q,a)) F. \n            {c. snd (last (snd c)) \\<notin> Fault ` F  \\<longrightarrow> \n                (\\<forall>i. \n                 Suc i<length (snd c) \\<longrightarrow> \n                 (fst c)\\<turnstile>\\<^sub>c((snd c)!i)  \\<rightarrow> ((snd c)!(Suc i)) \\<longrightarrow>                                        \n                   (snd((snd c)!i), snd((snd c)!(Suc i))) \\<in> guar) \\<and> \n                 (final (last (snd c))  \\<longrightarrow>                   \n                    ((fst (last (snd c)) = Skip \\<and> \n                      snd (last (snd c)) \\<in> Normal ` q)) \\<or>\n                    (fst (last (snd c)) = Throw \\<and> \n                      snd (last (snd c)) \\<in> Normal ` a))}\"\n\ndefinition comm1 :: \n  \"(('s,'f) tran) set \\<times> \n   ('s set \\<times> 's set) \\<Rightarrow>\n   'f set \\<Rightarrow> \n     (('s,'p,'f) confs) set\" where\n  \"comm1 \\<equiv> \\<lambda>(guar, (q,a)) F. \n            {(\\<Gamma>,comp). snd (last comp) \\<notin> Fault ` F  \\<longrightarrow> \n                (\\<forall>i. \n                 Suc i<length comp \\<longrightarrow> \n                 \\<Gamma>\\<turnstile>\\<^sub>c(comp!i)  \\<rightarrow> (comp!(Suc i)) \\<longrightarrow>                                        \n                   (snd(comp!i), snd(comp!(Suc i))) \\<in> guar) \\<and> \n                 (final (last comp)  \\<longrightarrow>                   \n                    ((fst (last comp) = Skip \\<and> \n                      snd (last comp) \\<in> Normal ` q)) \\<or>\n                    (fst (last comp) = Throw \\<and> \n                      snd (last comp) \\<in> Normal ` a))}\"\n\nlemma comm_dest:\n\"(\\<Gamma>, l)\\<in> comm (G,(q,a)) F \\<Longrightarrow>\n snd (last l) \\<notin> Fault ` F \\<Longrightarrow>\n (\\<forall>i. Suc i<length l \\<longrightarrow>\n   \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow> \n    (snd(l!i), snd(l!(Suc i))) \\<in>  G)\"\nunfolding comm_def\napply clarify\napply (drule mp)\napply fastforce\napply (erule conjE)\napply (erule allE)\nby auto\n\nlemma comm_dest1:\n\"(\\<Gamma>, l)\\<in> comm (G,(q,a)) F \\<Longrightarrow>\n snd (last l) \\<notin> Fault ` F \\<Longrightarrow>\n Suc i<length l \\<Longrightarrow>\n \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<Longrightarrow>\n(snd(l!i), snd(l!(Suc i))) \\<in> G\"\nunfolding comm_def\napply clarify\napply (drule mp)\napply fastforce\napply (erule conjE)\napply (erule allE)\nby auto\n\nlemma comm_dest2:\n  assumes a0: \"(\\<Gamma>, l)\\<in> comm (G,(q,a)) F\" and\n          a1: \"final (last l)\" and\n          a2: \"snd (last l) \\<notin> Fault ` F\" \n  shows  \" ((fst (last l) = Skip \\<and> \n            snd (last l) \\<in> Normal ` q)) \\<or>\n            (fst (last l) = Throw \\<and> \n            snd (last l) \\<in> Normal ` a)\"\nproof -\n  show ?thesis using a0 a1 a2 unfolding comm_def by auto\nqed\n\nlemma comm_des3:\n  assumes a0: \"(\\<Gamma>, l)\\<in> comm (G,(q,a)) F\" and\n          a1: \"snd (last l) \\<notin> Fault ` F\"\n shows \"final (last l) \\<longrightarrow> ((fst (last l) = Skip \\<and> \n            snd (last l) \\<in> Normal ` q)) \\<or>\n            (fst (last l) = Throw \\<and> \n            snd (last l) \\<in> Normal ` a)\"\nusing a0 a1 unfolding comm_def by auto\n\nlemma commI:\n  assumes a0:\"snd (last l) \\<notin> Fault ` F \\<Longrightarrow>\n             (\\<forall>i. \n                 Suc i<length l \\<longrightarrow> \n                 \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                                               \n                   (snd(l!i), snd(l!(Suc i))) \\<in> G) \\<and> \n                 (final (last l)  \\<longrightarrow>                   \n                    ((fst (last l) = Skip \\<and> \n                      snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                      snd (last l) \\<in> Normal ` a))\"\nshows \"(\\<Gamma>,l)\\<in>comm (G, (q,a)) F\"\nusing a0  unfolding comm_def\napply clarify\nby simp\n\nlemma comm_conseq:\n  \"(\\<Gamma>,l) \\<in> comm(G', (q',a')) F \\<Longrightarrow>\n       G' \\<subseteq> G \\<and>\n       q' \\<subseteq> q \\<and>\n       a' \\<subseteq> a \\<Longrightarrow>\n      (\\<Gamma>,l) \\<in> comm (G,(q,a)) F\"\nproof -\n  assume a0:\"(\\<Gamma>,l) \\<in> comm(G', (q',a')) F\" and\n         a1:\" G' \\<subseteq> G  \\<and>\n        q' \\<subseteq> q \\<and>\n        a' \\<subseteq> a\"\n  {\n    assume a:\"snd (last l) \\<notin> Fault ` F \"\n    have l:\"(\\<forall>i. \n           Suc i<length l \\<longrightarrow> \n           \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                                          \n             (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n    proof -\n      {fix i ns ns'\n      assume a00:\"Suc i<length l\" and\n             a11:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i))\"             \n      have \"(snd(l!i), snd(l!(Suc i))) \\<in>  G\" \n      proof -\n        have \"(snd(l!i), snd(l!(Suc i))) \\<in>  G'\"\n        using comm_dest1 [OF a0 a a00 a11]  by auto\n        thus ?thesis using a1 unfolding Satis_def sep_conj_def by fastforce\n      qed\n      } thus ?thesis by auto\n    qed  \n    have \"(final (last l)  \\<longrightarrow>                   \n                    ((fst (last l) = Skip \\<and> \n                      snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                      snd (last l) \\<in> Normal ` a))\"\n    proof -\n      {assume a33:\"final (last l)\"\n      then have \"((fst (last l) = Skip \\<and> \n                      snd (last l) \\<in> Normal ` q')) \\<or>\n                    (fst (last l) = Throw \\<and> \n                      snd (last l) \\<in> Normal ` a')\"\n      using comm_dest2[OF a0 a33 a] by auto\n      then have \"((fst (last l) = Skip \\<and> \n                      snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                      snd (last l) \\<in> Normal ` a)\"\n      using a1 by fastforce\n     } thus ?thesis by auto\n    qed\n    note res1 = conjI[OF l this] \n  } thus ?thesis unfolding comm_def by simp\nqed   \n\ndefinition com_validity :: \n  \"('s,'p,'f) body \\<Rightarrow>  'f set \\<Rightarrow> ('s,'p,'f) com \\<Rightarrow> \n    's set \\<Rightarrow> (('s,'f) tran) set \\<Rightarrow>  (('s,'f) tran) set \\<Rightarrow>  \n    's set \\<Rightarrow>  's set \\<Rightarrow>  bool\" \n    (\"_ \\<Turnstile>\\<^bsub>'/_\\<^esub>/ _ sat [_,_, _, _,_]\"  [61,60,20,1000,1000,1000,1000,1000] 60) where\n  \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> Pr sat [p, R, G, q,a] \\<equiv> \n   \\<forall>s. cp \\<Gamma> Pr s \\<inter> assum(p, R) F \\<subseteq> comm(G, (q,a)) F\"\n\ndefinition com_validityn :: \n  \"('s,'p,'f) body \\<Rightarrow> nat \\<Rightarrow> 'f set \\<Rightarrow>  ('s,'p,'f) com \\<Rightarrow> \n    's set \\<Rightarrow> (('s,'f) tran) set \\<Rightarrow>  (('s,'f) tran) set \\<Rightarrow>  \n    's set \\<Rightarrow>  's set \\<Rightarrow>  bool\" \n    (\"_ \\<Turnstile>_:\\<^bsub>'/_\\<^esub>/ _ sat [_,_, _, _,_]\" [61,60,60,20,1000,1000,1000,1000,1000] 60) where\n  \"\\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> Pr sat [p, R, G, q,a] \\<equiv> \n   \\<forall>s. (cpn n \\<Gamma> Pr s) \\<inter> assum(p, R) F \\<subseteq> comm(G, (q,a)) F\"\n\ndefinition com_cvalidity::\n \"('s,'p,'f) body \\<Rightarrow>\n    ('s, 'p, 'f) sextuple set \\<Rightarrow>\n    'f set \\<Rightarrow>\n    ('s,'p,'f) com \\<Rightarrow> \n    's set \\<Rightarrow>          \n    (('s,'f) tran) set \\<Rightarrow> \n    (('s,'f) tran) set \\<Rightarrow>  \n    's set \\<Rightarrow> \n    's set \\<Rightarrow>\n      bool\" \n    (\"_,_ \\<Turnstile>\\<^bsub>'/_\\<^esub>/ _ sat [_,_, _, _,_]\" [61,60,60,20,1000,1000,1000,1000,1000] 60) where\n  \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> Pr sat [p, R, G, q,a] \\<equiv> \n   (\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]) \\<longrightarrow> \n     \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> Pr sat [p, R, G, q,a]\"\n\n\ndefinition com_cvalidityn::\n \"('s,'p,'f) body \\<Rightarrow>\n    ('s, 'p, 'f) sextuple set \\<Rightarrow> nat \\<Rightarrow> \n    'f set \\<Rightarrow>\n    ('s,'p,'f) com \\<Rightarrow> \n    's set \\<Rightarrow>          \n    (('s,'f) tran) set \\<Rightarrow> \n    (('s,'f) tran) set \\<Rightarrow>  \n    's set \\<Rightarrow> \n    's set \\<Rightarrow>\n      bool\" \n    (\"_,_ \\<Turnstile>_:\\<^bsub>'/_\\<^esub>/ _ sat [_,_, _, _,_]\" [61,60,60,60,20,1000,1000,1000,1000,1000] 60) where\n  \"\\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> Pr sat [p, R, G, q,a] \\<equiv> \n   (\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]) \\<longrightarrow> \n     \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> Pr sat [p, R, G, q,a]\"\n\nlemma cvalid_iff_cnvalid:\n\"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> Pr sat [p, R, G, q,a] = (\\<forall>n. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> Pr sat [p, R, G, q,a])\"\n  apply (simp only: com_validity_def com_validityn_def cp_def cpn_def Int_def subset_eq)\n  using cptn_mod_eq_cptn_mod_nest cptn_eq_cptn_mod_set\n  by fastforce\n\nlemma cvalid_to_cnvalid:\n\"(\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> Pr sat [p, R, G, q,a]) \\<Longrightarrow> \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> Pr sat [p, R, G, q,a] \"\n  apply (simp only: com_cvalidityn_def com_cvalidity_def cvalid_iff_cnvalid)\n  by fast\n  \n    \nlemma etran_in_comm:\n  \"(\\<Gamma>,(P, t) # xs) \\<in> comm(G, (q,a)) F  \\<Longrightarrow> \n    \\<not> (\\<Gamma>\\<turnstile>\\<^sub>c((P,s))  \\<rightarrow> ((P,t))) \\<Longrightarrow>\n    (\\<Gamma>,(P, s) # (P, t) # xs) \\<in> cptn \\<Longrightarrow>    \n   (\\<Gamma>,(P, s) # (P, t) # xs) \\<in> comm(G, (q,a)) F\" \nproof -\n  assume a1:\"(\\<Gamma>,(P, t) # xs) \\<in> comm(G, (q,a)) F\" and\n         a2:\"\\<not> \\<Gamma>\\<turnstile>\\<^sub>c((P,s))  \\<rightarrow> ((P,t))\" and\n         a3:\"(\\<Gamma>,(P, s) # (P, t) # xs) \\<in> cptn\"\n  show ?thesis using comm_def a1 a2 a3\n  proof -\n     {\n     let ?l1 = \"(P, t) # xs\"\n     let ?l = \"(P, s) # ?l1\"\n     assume a00:\"snd (last ?l) \\<notin> Fault ` F\"\n     have concl:\"(\\<forall>i ns ns'. Suc i<length ?l \\<longrightarrow> \n               \\<Gamma>\\<turnstile>\\<^sub>c(?l!i)  \\<rightarrow> (?l!(Suc i)) \\<longrightarrow>                          \n                 (snd(?l!i), snd(?l!(Suc i))) \\<in>  G)\"\n     proof -\n       {fix i ns ns'\n        assume a11:\"Suc i < length  ?l\" and\n               a12:\"\\<Gamma>\\<turnstile>\\<^sub>c (?l ! i) \\<rightarrow> ( ?l ! Suc i)\"               \n        have p1:\"(\\<forall>i ns ns'. Suc i<length ?l1 \\<longrightarrow> \n               \\<Gamma>\\<turnstile>\\<^sub>c(?l1!i)  \\<rightarrow> (?l1!(Suc i)) \\<longrightarrow>                             \n               (snd(?l1!i), snd(?l1!(Suc i))) \\<in>  G)\"\n        using a1 a3 a00 unfolding comm_def by auto\n        have \"(snd (?l ! i), snd (?l ! Suc i)) \\<in>  G\"         \n        proof (cases i)\n          case 0 \n          have  \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow> (P, t)\" using a12 0 by auto\n          thus ?thesis using a2 by auto             \n        next\n          case (Suc n) thus ?thesis\n          proof -\n            have f1: \"\\<Gamma>\\<turnstile>\\<^sub>c ((P, t) # xs) ! n \\<rightarrow> ((P, t) # xs) ! Suc n\"\n              using Suc a12 by fastforce\n            have f2: \"Suc n < length ((P, t) # xs)\"\n              using Suc a11 by fastforce                       \n            have \"snd (last ((P, t) # xs)) \\<notin> Fault ` F\"\n                by (metis (no_types) a00 last.simps list.distinct(1))\n            hence \"(snd (((P, t) # xs) ! n), snd (((P, t) # xs) ! Suc n)) \\<in> G\"\n              using f2 f1 a1 comm_dest1  by blast            \n            thus ?thesis\n              by (simp add: Suc)\n          qed  \n        qed\n       } thus ?thesis by auto\n     qed\n     have concr:\"(final (last ?l)  \\<longrightarrow>                   \n                    ((fst (last ?l) = Skip \\<and> \n                      snd (last ?l) \\<in> Normal ` q)) \\<or>\n                    (fst (last ?l) = Throw \\<and> \n                      snd (last ?l) \\<in> Normal ` a))\"\n     using a1 a00 unfolding comm_def by auto\n     note res1=conjI[OF concl concr] }   \n     thus ?thesis unfolding comm_def by auto qed\nqed\n\nlemma ctran_in_comm:   \n  \" (Normal s,Normal s) \\<in> G  \\<Longrightarrow>\n   (\\<Gamma>,(Q, Normal s) # xs) \\<in> comm(G, (q,a)) F  \\<Longrightarrow>        \n   (\\<Gamma>,(P, Normal s) # (Q, Normal s) # xs) \\<in> comm(G, (q,a)) F\"\nproof -\n  assume a1:\"(Normal s,Normal s) \\<in> G\" and\n         a2:\"(\\<Gamma>,(Q, Normal s) # xs) \\<in> comm(G, (q,a)) F\"          \n  show ?thesis using comm_def a1 a2\n  proof -\n     {\n     let ?l1 = \"(Q, Normal s) # xs\"\n     let ?l = \"(P, Normal s) # ?l1\"\n      assume a00:\"snd (last ?l) \\<notin> Fault ` F\"\n     have concl:\"(\\<forall>i. Suc i<length ?l \\<longrightarrow> \n               \\<Gamma>\\<turnstile>\\<^sub>c(?l!i)  \\<rightarrow> (?l!(Suc i)) \\<longrightarrow>                                              \n                 (snd(?l!i), snd(?l!(Suc i))) \\<in>  G)\"\n     proof -\n       {fix i ns ns'\n        assume a11:\"Suc i < length  ?l\" and\n               a12:\"\\<Gamma>\\<turnstile>\\<^sub>c (?l ! i) \\<rightarrow> ( ?l ! Suc i)\" \n        have p1:\"(\\<forall>i. Suc i<length ?l1 \\<longrightarrow> \n               \\<Gamma>\\<turnstile>\\<^sub>c(?l1!i)  \\<rightarrow> (?l1!(Suc i)) \\<longrightarrow>                              \n               (snd(?l1!i), snd(?l1!(Suc i))) \\<in>  G)\"\n        using a2 a00 unfolding comm_def by auto\n        have \"(snd (?l ! i), snd (?l ! Suc i)) \\<in> G\"   \n        proof (cases i)\n          case 0     \n          then have \"snd (((P, Normal s) # (Q, Normal s) # xs) ! i) = Normal s \\<and> \n                     snd (((P, Normal s) # (Q, Normal s) # xs) ! (Suc i)) = Normal s\"                \n            by fastforce\n          also have \"(Normal s, Normal s) \\<in> G\"\n             using Satis_def a1 by blast\n          ultimately show  ?thesis using a1 Satis_def by auto            \n        next\n          case (Suc n) thus ?thesis using p1 a2  a11 a12 \n          proof -\n            have f1: \"\\<Gamma>\\<turnstile>\\<^sub>c ((Q, Normal s) # xs) ! n \\<rightarrow> ((Q, Normal s) # xs) ! Suc n\"\n              using Suc a12 by fastforce\n            have f2: \"Suc n < length ((Q, Normal s) # xs)\"\n              using Suc a11 by fastforce\n            thus ?thesis using Suc f1 nth_Cons_Suc p1 by auto \n          qed  \n        qed\n       } thus ?thesis by auto\n     qed\n     have concr:\"(final (last ?l)  \\<longrightarrow> \n                  snd (last ?l) \\<notin> Fault ` F  \\<longrightarrow>\n                    ((fst (last ?l) = Skip \\<and> \n                      snd (last ?l) \\<in> Normal ` q)) \\<or>\n                    (fst (last ?l) = Throw \\<and> \n                      snd (last ?l) \\<in> Normal ` a))\"\n     using a2 unfolding comm_def by auto\n     note res=conjI[OF concl concr]}\n     thus ?thesis unfolding comm_def by auto qed\nqed\n\nlemma not_final_in_comm:\n \"(\\<Gamma>,(Q, Normal s) # xs) \\<in> comm(G, (q,a)) F \\<Longrightarrow>\n  \\<not> final (last ((Q, Normal s) # xs)) \\<Longrightarrow>\n  (\\<Gamma>,(Q, Normal s) # xs) \\<in> comm(G, (q',a')) F\"\nunfolding comm_def by force\n\nlemma comm_union:\n assumes \n   a0: \"(\\<Gamma>,xs) \\<in> comm(G, (q,a)) F\" and\n   a1: \"(\\<Gamma>,ys) \\<in> comm(G, (q',a')) F\" and\n   a2: \"xs\\<noteq>[] \\<and> ys\\<noteq>[]\" and\n   a3: \"( snd (last xs),snd (ys!0)) \\<in> G\" and\n   a4: \"(\\<Gamma>,xs@ys) \\<in> cptn\"\n shows \"(\\<Gamma>,xs@ys) \\<in> comm(G, (q',a')) F\" \nproof -\n{\n  let ?l=\"xs@ys\" \n  assume a00:\"snd (last (xs@ys)) \\<notin> Fault ` F\"\n  have last_ys:\"last (xs@ys) = last ys\" using a2 by fastforce\n  have concl:\"(\\<forall>i. Suc i<length ?l \\<longrightarrow> \n             \\<Gamma>\\<turnstile>\\<^sub>c(?l!i)  \\<rightarrow> (?l!(Suc i)) \\<longrightarrow>                                            \n               (snd(?l!i), snd(?l!(Suc i))) \\<in> G)\"\n   proof -\n     {fix i ns ns'\n      assume a11:\"Suc i < length  ?l\" and\n             a12:\"\\<Gamma>\\<turnstile>\\<^sub>c (?l ! i) \\<rightarrow> ( ?l ! Suc i)\" \n      have all_ys:\"\\<forall>i\\<ge>length xs. (xs@ys)!i = ys!(i-(length xs))\"\n          by (simp add: nth_append)   \n      have all_xs:\"\\<forall>i<length xs. (xs@ys)!i = xs!i\"\n            by (simp add: nth_append)\n      have \"(snd(?l!i), snd(?l!(Suc i))) \\<in>  G\"\n      proof (cases \"Suc i>length xs\")\n        case True                                 \n        have \"Suc (i - (length xs)) < length ys\" using a11 True by fastforce\n        moreover have \"\\<Gamma>\\<turnstile>\\<^sub>c (ys ! (i-(length xs))) \\<rightarrow> ( ys ! ((Suc i)-(length xs)))\" \n          using a12 all_ys True by fastforce          \n        moreover have \"snd (last ys) \\<notin> Fault ` F\" using last_ys a00 by fastforce   \n        ultimately have \"(snd(ys!(i-(length xs))), snd(ys!Suc (i-(length xs)))) \\<in> G\" \n        using a1 comm_dest1[of \\<Gamma> ys G q' a' F \"i-length xs\"] True Suc_diff_le by fastforce \n        thus ?thesis using True all_ys Suc_diff_le by fastforce\n      next\n        case False note F1=this  thus ?thesis \n        proof (cases \"Suc i < length xs\")\n          case True              \n          then have \"snd ((xs@ys)!(length xs -1)) \\<notin> Fault ` F\"\n            using a00 a2 a4 \n             by (simp add: last_not_F )         \n          then have \"snd (last xs) \\<notin> Fault ` F\" using all_xs a2 by (simp add: last_conv_nth )          \n          moreover have \"\\<Gamma>\\<turnstile>\\<^sub>c (xs ! i) \\<rightarrow> ( xs ! Suc i)\" \n            using True all_xs a12 by fastforce          \n          ultimately have\"(snd(xs!i), snd(xs!(Suc i))) \\<in> G\"\n            using a0 comm_dest1[of \\<Gamma> xs G q a F i] True by fastforce\n          thus ?thesis using True all_xs by fastforce\n        next\n          case False\n          then have suc_i:\"Suc i = length xs\" using F1 by fastforce\n          then have i:\"i=length xs -1\" using a2 by fastforce          \n          then show ?thesis using a3 \n            by (simp add: a2 all_xs all_ys  last_conv_nth ) \n        qed\n      qed\n     } thus ?thesis by auto          \n   qed\n   have concr:\"(final (last ?l)  \\<longrightarrow>                 \n                  ((fst (last ?l) = Skip \\<and> \n                    snd (last ?l) \\<in> Normal ` q')) \\<or>\n                  (fst (last ?l) = Throw \\<and> \n                    snd (last ?l) \\<in> Normal ` a'))\"\n   using a1 last_ys a00 a2 comm_des3 by fastforce\n   note res=conjI[OF concl concr]}\n   thus ?thesis unfolding comm_def by auto \nqed\n\n(* text{* \n@{text rel_safe} specifies that the relation leaves unmodifed any fragment out of the \nstate\n*}\ndefinition rel_safe:: \"(('l::sep_algebra,'g::sep_algebra) transition \\<Rightarrow> bool) \\<Rightarrow> bool\"\nwhere\n\"rel_safe R \\<equiv> \\<forall>h h1 h2 t. R (h1,t) \\<and> ((h1 \\<uplus>\\<^sub>p h2) h) \\<longrightarrow> R (h, t \\<uplus> h2)\"\n\ndefinition mem_safe::\n\"(('l::sep_algebra,'g::sep_algebra) state,'p,'f) body \\<Rightarrow> \n (('l,'g) state,'p,'f) com \\<Rightarrow> \n (('l,'g) transition \\<Rightarrow> bool) \\<Rightarrow> \n   bool\"\nwhere\n \"mem_safe \\<Gamma> f R \\<equiv> \\<forall>h h1 h2 t1. \n      ((\\<forall>c\\<in> cp \\<Gamma> f (Normal h1). \n        final_valid(last (snd c)) \\<and> (Normal t1 =  snd (last (snd c))) \\<and>\n        (\\<forall>i. Suc i<length (snd c) \\<longrightarrow> \n                 (fst c)\\<turnstile>\\<^sub>c((snd c)!i)  \\<rightarrow>\\<^sub>e ((snd c)!(Suc i)) \\<longrightarrow>                  \n                   (snd((snd c)!i), snd((snd c)!(Suc i))) \\<in> \n                     (case_prod (\\<lambda>x y. (Normal x, Normal y))) ` (R))) \\<and>      \n        (h1 \\<uplus>\\<^sub>p h2) h \\<longrightarrow>\n        (\\<forall>c\\<in> cp \\<Gamma> f (Normal h). \n          final_valid(last (snd c)) \\<and>\n          (\\<forall>i. Suc i<length (snd c) \\<longrightarrow> \n              (fst c)\\<turnstile>\\<^sub>c((snd c)!i)  \\<rightarrow>\\<^sub>e ((snd c)!(Suc i)) \\<longrightarrow>                  \n              (snd((snd c)!i), snd((snd c)!(Suc i))) \\<in> \n                (case_prod (\\<lambda>x y. (Normal x, Normal y))) ` (R)) \\<longrightarrow>\n              (Normal (t1 \\<uplus> h2) =  snd (last (snd c)))))     \n      \"                         \n *)\n\n     \nsubsection \\<open>Validity for Parallel Programs.\\<close>\ndefinition All_End :: \"('s,'p,'f) par_config \\<Rightarrow> bool\" where\n  \"All_End xs \\<equiv> fst xs \\<noteq>[] \\<and> (\\<forall>i<length (fst xs). final ((fst xs)!i,snd xs))\"\n\ndefinition par_assum :: \n  \"('s set \\<times>  \n   (('s,'f) tran) set) \\<Rightarrow>\n   'f set \\<Rightarrow>\n   (('s,'p,'f) par_confs) set\" where\n  \"par_assum \\<equiv> \n     \\<lambda>(pre, rely) F. {c. \n       snd((snd c)!0) \\<in> Normal ` pre \\<and> (\\<forall>i. Suc i<length (snd c) \\<longrightarrow> \n       (fst c)\\<turnstile>\\<^sub>p((snd c)!i)  \\<rightarrow>\\<^sub>e ((snd c)!(Suc i)) \\<longrightarrow>        \n         (snd((snd c)!i), snd((snd c)!(Suc i))) \\<in> rely)}\"\n           \ndefinition par_comm :: \n  \"((('s,'f) tran) set  \\<times> \n     ('s set \\<times> 's set))  \\<Rightarrow> \n    'f set \\<Rightarrow>\n   (('s,'p,'f) par_confs) set\" where\n  \"par_comm \\<equiv> \n     \\<lambda>(guar, (q,a)) F. \n     {c. snd (last (snd c)) \\<notin> Fault ` F \\<longrightarrow> \n         (\\<forall>i. \n            Suc i<length (snd c) \\<longrightarrow> \n            (fst c)\\<turnstile>\\<^sub>p((snd c)!i)  \\<rightarrow> ((snd c)!(Suc i)) \\<longrightarrow>                        \n              (snd((snd c)!i), snd((snd c)!(Suc i))) \\<in> guar) \\<and> \n                (All_End (last (snd c)) \\<longrightarrow> \n                   (\\<exists>j<length (fst (last (snd c))). fst (last (snd c))!j=Throw \\<and> \n                        snd (last (snd c)) \\<in> Normal ` a) \\<or>\n                   (\\<forall>j<length (fst (last (snd c))). fst (last (snd c))!j=Skip \\<and>\n                        snd (last (snd c)) \\<in> Normal ` q))}\"\n\ndefinition par_com_validity :: \n  \"('s,'p,'f) body \\<Rightarrow> \n   'f set \\<Rightarrow>\n   ('s,'p,'f) par_com \\<Rightarrow>  \n   ('s set) \\<Rightarrow> \n   ((('s,'f) tran) set) \\<Rightarrow> \n   ((('s,'f) tran) set) \\<Rightarrow> \n   ('s set) \\<Rightarrow>\n   ('s set) \\<Rightarrow> \n     bool\"  \n(\"_ \\<Turnstile>\\<^bsub>'/_\\<^esub>/ _ SAT [_, _, _, _,_]\" [61,60,0,0,0,0,0,0] 45) where\n  \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> Ps SAT [pre, R, G, q,a] \\<equiv> \n   \\<forall>s. par_cp \\<Gamma> Ps s \\<inter> par_assum(pre, R) F \\<subseteq> par_comm(G, (q,a)) F\"\n   \ndefinition par_com_cvalidity :: \n  \"('s,'p,'f) body \\<Rightarrow>\n    ('s,'p,'f) sextuple set \\<Rightarrow>\n   'f set \\<Rightarrow>\n  ('s,'p,'f) par_com \\<Rightarrow>   \n   ('s set) \\<Rightarrow> \n   ((('s,'f) tran) set) \\<Rightarrow> \n   ((('s,'f) tran) set) \\<Rightarrow> \n   ('s set) \\<Rightarrow>\n   ('s set) \\<Rightarrow> \n     bool\"  \n(\"_,_ \\<Turnstile>\\<^bsub>'/_\\<^esub>/ _ SAT [_, _, _, _,_]\" [61,60,0,0,0,0,0,0] 45) where\n  \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> Ps SAT [p,  R, G, q,a] \\<equiv> \n  (\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. (\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a])) \\<longrightarrow>\n   \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> Ps SAT [p, R, G, q,a]\"\n   \ndeclare Un_subset_iff [simp del] sup.bounded_iff [simp del]\n\ninductive\nlrghoare :: \"[('s,'p,'f) body,\n             ('s,'p,'f) sextuple set,\n              'f set,\n              ('s,'p,'f) com,  \n              ('s set),  \n              (('s,'f) tran) set, (('s,'f) tran) set,\n              's set,\n               's set] \\<Rightarrow> bool\"\n    (\"_,_ \\<turnstile>\\<^bsub>'/_\\<^esub> _ sat [_, _, _, _,_]\" [61,61,60,60,0,0,0,0] 45)\nwhere\n Skip: \"\\<lbrakk> Sta q R; (\\<forall>s. (Normal s, Normal s) \\<in> G) \\<rbrakk> \\<Longrightarrow>\n         \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> Skip sat [q, R, G, q,a] \"\n\n|Spec: \"\\<lbrakk>p \\<subseteq> {s. (\\<forall>t. (s,t)\\<in>r \\<longrightarrow> t \\<in> q) \\<and> (\\<exists>t. (s,t) \\<in> r)};        \n        (\\<forall>s t. s\\<in>p \\<and> (s,t)\\<in>r \\<longrightarrow> (Normal s,Normal t) \\<in> G);\n        Sta p R;Sta q R\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (Spec r) sat [p, R, G, q,a]\"\n\n| Basic: \"\\<lbrakk> p \\<subseteq> {s. f s \\<in> q};            \n           (\\<forall>s t. s\\<in>p \\<and> (t=f s) \\<longrightarrow> (Normal s,Normal t) \\<in> G);\n            Sta p R;Sta q R \\<rbrakk> \\<Longrightarrow>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (Basic f) sat [p, R, G, q,a]\"\n\n| If: \"\\<lbrakk> \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b, R, G, q,a]; \n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c2 sat [p \\<inter> (-b), R, G, q,a];         \n        Sta p R;  (\\<forall>s. (Normal s, Normal s) \\<in> G)\n        \\<rbrakk> \\<Longrightarrow>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (Cond b c1 c2) sat [p,  R, G, q,a]\"\n\n| While: \"\\<lbrakk> \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c sat [p \\<inter> b, R, G, p,a];            \n            Sta p R; Sta (p \\<inter> (-b)) R; Sta a R; (\\<forall>s. (Normal s,Normal s) \\<in> G)\\<rbrakk> \\<Longrightarrow>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (While b c) sat [p, R, G, p \\<inter> (-b),a]\"\n\n| Seq: \"\\<lbrakk> \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p, R, G, q,a]; \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c2 sat [q, R, G, r,a];         \n         Sta a R; Sta p R; (\\<forall>s. (Normal s,Normal s) \\<in> G)\\<rbrakk> \\<Longrightarrow>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (Seq c1 c2) sat [p, R, G, r,a]\"\n\n| Await: \"\\<lbrakk> \\<forall>V. \\<Gamma>\\<^sub>\\<not>\\<^sub>a,{}\\<turnstile>\\<^bsub>/F\\<^esub> \n                  (p \\<inter> b \\<inter> {V}) c \n                  ({s. (Normal V, Normal s) \\<in> G} \\<inter> q),\n                  ({s. (Normal V, Normal s) \\<in> G} \\<inter> a);                                        \n           Sta p R; Sta q R; Sta a R\\<rbrakk> \\<Longrightarrow>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (Await b c) sat [p, R, G, q,a]\"\n\n| Guard: \"\\<lbrakk> \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c sat [p \\<inter> g, R, G, q,a];           \n        Sta (p \\<inter> g) R; (\\<forall>s. (Normal s, Normal s) \\<in> G)\\<rbrakk> \\<Longrightarrow>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (Guard f g c) sat [p \\<inter> g, R, G, q,a]\"\n\n| Guarantee:  \"\\<lbrakk> \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c sat [p \\<inter> g, R, G, q,a];\n                Sta p R;f\\<in>F; (\\<forall>s. (Normal s, Normal s) \\<in> G) \\<rbrakk> \\<Longrightarrow>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (Guard f g c) sat [p, R, G, q,a]\"\n\n| CallRec: \"\\<lbrakk>(c,p,R,G,q,a) \\<in> Specs; \n             \\<forall>(c,p,R,G,q,a)\\<in> Specs. c \\<in> dom \\<Gamma> \\<and> \n              Sta p R \\<and>  (\\<forall>s. (Normal s,Normal s) \\<in> G) \\<and> \n             \\<Gamma>,\\<Theta> \\<union> Specs \\<turnstile>\\<^bsub>/F\\<^esub> (the (\\<Gamma> c)) sat [p,  R, G, q,a];\n            Sta p R; (\\<forall>s. (Normal s, Normal s) \\<in> G)\\<rbrakk> \\<Longrightarrow>\n            \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"\n\n| Asm: \"\\<lbrakk>(c,p,R,G,q,a) \\<in> \\<Theta>\\<rbrakk> \n        \\<Longrightarrow>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\" \n\n| Call: \"\\<lbrakk>c \\<in> dom \\<Gamma>; \n         \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (the (\\<Gamma> c)) sat [p, R, G, q,a];         \n         Sta p R; (\\<forall>s. (Normal s, Normal s) \\<in> G)\\<rbrakk> \n        \\<Longrightarrow>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"\n\n| DynCom: \"\\<lbrakk>(\\<forall>s \\<in> p. (\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (c s) sat [p, R, G, q,a]));\n          (Sta p R) \\<and> (Sta q R) \\<and> (Sta a R) \\<and>\n            (\\<forall>s. (Normal s,Normal s) \\<in> G)\\<rbrakk> \\<Longrightarrow>\n            \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (DynCom c) sat [p, R, G, q,a]\"\n\n| Throw: \"\\<lbrakk>Sta a R; (\\<forall>s. (Normal s, Normal s) \\<in> G) \\<rbrakk> \\<Longrightarrow>\n         \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> Throw sat [a,  R, G, q,a] \"\n\n| Catch: \"\\<lbrakk> \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p, R, G, q,r]; \n           \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c2 sat [r, R, G, q,a];           \n           Sta q R; (\\<forall>s. (Normal s, Normal s) \\<in> G)\\<rbrakk> \\<Longrightarrow>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (Catch c1 c2) sat [p, R, G, q,a]\"\n\n| Conseq: \"\\<forall>s \\<in> p. \n             (\\<exists>p' R' G' q' a'.  \n             (s\\<in> p') \\<and>\n              R \\<subseteq> R' \\<and>            \n             G' \\<subseteq> G \\<and>             \n             q' \\<subseteq> q \\<and>\n             a' \\<subseteq> a \\<and>                        \n            (\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p', R', G', q',a']) ) \n            \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q,a]\"\n\n| Conj_post: \" \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q,a] \\<Longrightarrow>\n                \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q',a'] \n            \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q \\<inter> q',a \\<inter> a']\" \n\ninductive_cases hoare_elim_cases [cases set]:\n \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> Skip sat [p, R, G, q,a]\"\n\nthm hoare_elim_cases\n(*\nlemma \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> Skip sat [p, R, G, q,a] \\<Longrightarrow> \n        \\<forall>s \\<in> p. \n          (\\<exists>p' R' G' q' a'.  \n           (s\\<in> p') \\<and>\n            R \\<subseteq> R' \\<and>            \n            G' \\<subseteq> G \\<and>             \n            q' \\<subseteq> q \\<and>\n            a' \\<subseteq> a \\<and>                        \n           (\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p', R', G', q',a']) \\<and> p'=q' \\<and> Sta q' R' \\<and> Norm R' \\<and> (\\<forall>s. (Normal s, Normal s) \\<in> G'))\"\nproof -\n  assume a0:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> Skip sat [p, R, G, q,a]\"  \n  {\n   fix s\n   assume a01:\"s\\<in>p\"\n   have \"(\\<exists>p' R' G' q' a'.  \n           (s\\<in> p') \\<and>\n            R \\<subseteq> R' \\<and>            \n            G' \\<subseteq> G \\<and>             \n            q' \\<subseteq> q \\<and>\n            a' \\<subseteq> a \\<and>                        \n           (\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p', R', G', q',a']) \\<and> p'=q' \\<and> Sta q' R' \\<and> Norm R' \\<and> (\\<forall>s. (Normal s, Normal s) \\<in> G'))\"\n   proof (cases \"p=q\")\n    case True thus ?thesis using hoare_elim_cases   sorry\n   next\n    case False thus ?thesis sorry\n   qed\n  } thus ?thesis by fastforce\nqed*)\n\n(* lemma \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c sat [p, R, G, q,r] \\<Longrightarrow>\n       c\\<noteq>Throw \\<Longrightarrow>\n       Sta p R\"\nsorry *)\n(*\n| Env:  \"\\<lbrakk>noawaits c; \\<Gamma>\\<^sub>\\<not>\\<^sub>a,{}\\<turnstile>\\<^bsub>/F\\<^esub> (p ) (sequential c) q,(a)\\<rbrakk> \\<Longrightarrow>\n         \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> c sat [p, sep_empty, Emp, Emp, q,a]\"\n        \n| Hide: \"\\<lbrakk>\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c sat [p, (I \\<and>* I'), (R \\<and>* R'), (G \\<and>* G'), q,a]; \n         (I  \\<triangleright> R); \n         (I  \\<triangleright> G)\n          \\<rbrakk> \\<Longrightarrow> \n         \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> c sat [p, I, R, G, q,a]\" \n\n|Frame: \"\\<lbrakk>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c sat [p, I, R, G , q,a]; \n        I'  \\<triangleright> R'; I'  \\<triangleright> G';\n        Sta r (R'\\<and>*tran_Id);\n        (\\<forall>s t. (r imp (I'\\<and>*sep_true))(s,t));\n        (rel_safe R); (rel_safe (G\\<and>*tran_True)) \\<rbrakk>  \\<Longrightarrow>\n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> c sat [p\\<and>*r, I \\<and>* I', R \\<and>* R', G \\<and>* G', q\\<and>*r,a\\<and>*r]\"\n*)\n\n\ndefinition Pre :: \" ('s,'p,'f)rgformula \\<Rightarrow> ('s set)\" where\n  \"Pre x \\<equiv> fst(snd x)\"\n\ndefinition Post :: \"('s,'p,'f) rgformula \\<Rightarrow> ('s set)\" where\n  \"Post x \\<equiv>  fst(snd(snd(snd(snd x))))\"\n\ndefinition Abr ::  \"('s,'p,'f) rgformula \\<Rightarrow> ('s set)\" where\n  \"Abr x \\<equiv> snd(snd(snd(snd(snd x))))\"\n\ndefinition Rely :: \"('s,'p,'f) rgformula \\<Rightarrow> (('s,'f) tran) set\" where\n  \"Rely x \\<equiv> fst(snd(snd x))\"\n\ndefinition Guar ::  \"('s,'p,'f) rgformula \\<Rightarrow> (('s,'f) tran) set\" where\n  \"Guar x \\<equiv> fst(snd(snd(snd x)))\"\n\ndefinition Com :: \"('s,'p,'f) rgformula \\<Rightarrow> ('s ,'p,'f) com\" where\n  \"Com x \\<equiv> fst  x\"\n\n\ninductive\n  par_rghoare ::  \"[('s,'p,'f) body,\n              ('s,'p,'f) sextuple set,\n              'f set,\n              ( ('s,'p,'f) rgformula) list,  \n              's set,              \n              (('s,'f) tran) set, (('s,'f) tran) set,\n              's set,\n               's set] \\<Rightarrow> bool\"\n    (\"_,_ \\<turnstile>\\<^bsub>'/_\\<^esub> _ SAT [_, _, _, _,_]\" [61,60,60,0,0,0,0] 45)\nwhere\n  Parallel:\n  \"\\<lbrakk> \\<forall>i<length xs. R \\<union> (\\<Union>j\\<in>{j. j<length xs \\<and> j\\<noteq>i}. (Guar(xs!j))) \\<subseteq> (Rely(xs!i));\n    (\\<Union>j<length xs. (Guar(xs!j))) \\<subseteq> G;\n     p \\<subseteq> (\\<Inter>i<length xs. (Pre(xs!i)));\n    (\\<Inter>i<length xs. (Post(xs!i))) \\<subseteq> q;\n    (\\<Union>i<length xs. (Abr(xs!i))) \\<subseteq> a;                 \n    \\<forall>i<length xs. \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> Com(xs!i) sat [Pre(xs!i),Rely(xs!i),Guar(xs!i),Post(xs!i),Abr(xs!i)] \\<rbrakk>\n   \\<Longrightarrow>  \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> xs SAT [p, R, G, q,a]\" \n \nsection {* Soundness *}\n\nlemma skip_suc_i:\n  assumes a1:\"(\\<Gamma>, l) \\<in> cptn \\<and> fst (l!i) = Skip\"   \n  assumes a2:\"i+1 < length l\"\n  shows \"fst (l!(i+1)) = Skip\"\nproof -\n  from a2 a1 obtain l1 ls where \"l=l1#ls\" \n    by (metis list.exhaust list.size(3) not_less0) \n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c (l!i) \\<rightarrow>\\<^sub>c\\<^sub>e (l!(Suc i))\" using cptn_stepc_rtran a1 a2\n    by fastforce \n  thus ?thesis using a1 a2 step_ce_elim_cases\n    by (metis (no_types) Suc_eq_plus1 not_eq_not_env prod.collapse stepc_elim_cases(1))\nqed \n\nlemma throw_suc_i:\n  assumes a1:\"(\\<Gamma>, l) \\<in> cptn \\<and> (fst(l!i) = Throw \\<and> snd(l!i) = Normal s1)\"   \n  assumes a2:\"Suc i < length l\"\n  assumes a3:\"env_tran_right \\<Gamma> l rely \\<and> Sta q rely \\<and> s1 \\<in> q\"\n  shows \"fst (l!(Suc i)) =  Throw \\<and> (\\<exists>s2. snd(l!(Suc i)) = Normal s2 \\<and> s2 \\<in>q)\"\nproof -\n  have fin:\"final (l!i)\" using a1 unfolding final_def by auto \n  from a2 a1 obtain l1 ls where \"l=l1#ls\" \n    by (metis list.exhaust list.size(3) not_less0) \n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c (l!i) \\<rightarrow>\\<^sub>c\\<^sub>e (l!(Suc i))\" using cptn_stepc_rtran a1 a2\n    by fastforce then have \"\\<Gamma>\\<turnstile>\\<^sub>c (l!i) \\<rightarrow> (l!(Suc i)) \\<or> \\<Gamma>\\<turnstile>\\<^sub>c (l!i) \\<rightarrow>\\<^sub>e (l!(Suc i))\"\n    using step_ce_elim_cases by blast\n  thus ?thesis proof                                          \n    assume \"\\<Gamma>\\<turnstile>\\<^sub>c (l!i) \\<rightarrow> (l!(Suc i))\" thus ?thesis using fin no_step_final' by blast\n  next\n    assume \"\\<Gamma>\\<turnstile>\\<^sub>c (l!i) \\<rightarrow>\\<^sub>e (l!(Suc i))\" thus ?thesis \n      using a1 a3 a2 env_tran_normal by (metis (no_types, lifting)  env_c_c' prod.collapse) \n  qed \nqed \n\nlemma i_skip_all_skip:assumes a1:\"(\\<Gamma>, l) \\<in> cptn \\<and> fst (l!i) = Skip\"\n      assumes a2: \"i\\<le>j \\<and> j < (length l)\"\n      assumes a3:\"n=j-i\"\n      (* assumes a4:\"env_tran_right \\<Gamma> l rely\" *)\n      shows \"fst (l!j) = Skip\"\nusing a1 a2 a3\nproof (induct n arbitrary: i j)\n  case 0\n  then have \"Suc i = Suc j\" by simp  \n  thus ?case using \"0.prems\" skip_suc_i by fastforce\nnext\n  case (Suc n)    \n  then have \"length l > Suc i\" by auto \n  then have \"i<j\" using Suc by fastforce\n  moreover then have \"j-1< length l\" using Suc by fastforce\n  moreover then have \"j  - i = Suc n\" using Suc by fastforce\n  ultimately have \"fst (l ! (j)) = LanguageCon.com.Skip\" using Suc  skip_suc_i\n    by (metis (no_types, lifting) Suc_diff_Suc Suc_eq_plus1 Suc_leI `Suc i < length l` diff_Suc_1)        \n  also have \"j=j\" using Cons using Suc.prems(2) by linarith  \n  ultimately show ?case using Suc by (metis (no_types))\nqed\n\nlemma i_throw_all_throw:assumes a1:\"(\\<Gamma>, l) \\<in> cptn \\<and> (fst (l!i) = Throw \\<and> snd (l!i) = Normal s1)\"\n      assumes a2: \"i\\<le>j \\<and> j < (length l)\"\n      assumes a3:\"n=j-i\"\n      assumes a4:\"env_tran_right \\<Gamma> l rely \\<and> Sta q rely \\<and> s1\\<in>q\" \n      shows \"fst (l!j) = Throw \\<and> (\\<exists>s2. snd(l!j) = Normal s2  \\<and> s2\\<in>q)\"\nusing a1 a2 a3 a4\nproof (induct n arbitrary: i j s1)\n  case 0\n  then have \"Suc i = Suc j\" by simp  \n  thus ?case using \"0.prems\" skip_suc_i by fastforce\nnext\n  case (Suc n)    \n  then have l_suc:\"length l > Suc i\" by linarith \n  then have \"i<j\" using Suc.prems(3) by linarith \n  moreover then have \"j-1< length l\" by (simp add: Suc.prems(2) less_imp_diff_less) \n  moreover then have \"j - Suc i = n\" by (metis Suc_diff_Suc Suc_inject \\<open>i < j\\<close> Suc(4))\n  ultimately obtain s2 where \"fst (l ! (j-1)) = LanguageCon.com.Throw \\<and> snd (l ! (j-1)) = Normal s2 \\<and> s2\\<in>q\"\n    using Suc(1)[of i s1 \"j-1\"] Suc(2) Suc(5)\n    by (metis (no_types, lifting) Suc_diff_Suc diff_Suc_eq_diff_pred diff_zero less_imp_Suc_add not_le not_less_eq_eq zero_less_Suc) \n  also have \"Suc (j - 1) < length l\" using Suc by arith\n  ultimately have \"fst (l ! (j)) = LanguageCon.com.Throw \\<and> (\\<exists>s2. snd(l!j) = Normal s2 \\<and> s2\\<in>q)\" \n    using Suc(2-5) throw_suc_i[of \\<Gamma> l \"j-1\" s2 rely q] a4\n    by fastforce\n  also have \"j=j\" using Cons using Suc.prems(2) by linarith  \n  ultimately show ?case using Suc by (metis (no_types))\nqed    \n\nlemma only_one_component_tran_j:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!i) = Skip  \\<or> fst (l!i) = Throw \" and \n         a1': \"snd (l!i) = Normal x \\<and> x \\<in> q\" and\n         a2: \"i\\<le>j \\<and> Suc j < length l\" and\n         a3: \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\" and \n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta q rely\"    \n   shows \"P\"\nproof -   \n   have \"fst (l!j) = Skip  \\<or> (fst (l!i) = Throw \\<and> snd(l!i) = Normal x)\" \n   using a0 a1 a1' a2 a3 a4 i_skip_all_skip by fastforce           \n   also have \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\" using a3 by fastforce \n   ultimately show ?thesis\nby (meson SmallStepCon.final_def SmallStepCon.no_step_final' Suc_lessD a0 a2  a4 i_throw_all_throw a1')  \nqed     \n\nlemma only_one_component_tran_all_j:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!i) = Skip  \\<or> (fst (l!i) = Throw \\<and> snd(l!i) = Normal s1)\" and \n         a1': \"snd (l!i) = Normal x \\<and> x \\<in> q\" and\n         a2: \"Suc i<length l\" and\n         a3: \"\\<forall>j. i\\<le>j \\<and> Suc j < length l \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"  and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta q rely\"              \n   shows \"P\" \nusing a0 a1 a2 a3 a4 a1' only_one_component_tran_j \nby (metis lessI less_Suc_eq_le) \n\n\nlemma zero_skip_all_skip: \n      assumes a1:\"(\\<Gamma>, l) \\<in> cptn \\<and> fst (l!0) = Skip \\<and>  i < length l\"\n      shows \"fst (l!i) = Skip\"\nusing a1 i_skip_all_skip by blast\n\nlemma all_skip:\n   assumes\n      a0:\"(\\<Gamma>,x)\\<in>cptn\" and\n      a1:\"x!0 = (Skip,s)\"\nshows \"(\\<forall>i<length x. fst(x!i) = Skip)\"\nusing a0 a1 zero_skip_all_skip by fastforce\n\nlemma zero_throw_all_throw:\n      assumes a1:\"(\\<Gamma>, l) \\<in> cptn \\<and> fst (l!0) = Throw \\<and> \n                  snd(l!0) = Normal s1 \\<and>  i < length l \\<and> s1\\<in>q\"\n      assumes a2: \"env_tran_right \\<Gamma> l rely \\<and> Sta q rely\" \n      shows \"fst (l!i) = Throw \\<and> (\\<exists>s2. snd (l!i) = Normal s2)\"\nusing a1 a2 i_throw_all_throw by (metis le0) \n\nlemma only_one_component_tran_0:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"(fst (l!0) = Skip) \\<or> (fst (l!0) = Throw)\" and                  \n         a1': \"snd (l!0) = Normal x \\<and> x \\<in> q\" and\n         a2: \"Suc j < length l\" and\n         a3: \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"  and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta q rely\"         \n   shows \"P\"      \n  proof-\n   have a2':\"0\\<le>j \\<and> Suc j<length l\" using a2 by arith\n   show ?thesis \n   using only_one_component_tran_j[OF a0 a1 a1' a2' a3 a4] by auto\nqed\n\n(* lemma only_one_component_tran_all_j_i:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!i) = Skip \\<or> (fst (l!0) = Throw \\<and> snd(l!0) = Normal s1)\" and \n         a2: \"Suc i<length l\" and\n         a3: \"\\<forall>j. j\\<ge>i \\<and> Suc j < length l \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\" and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Norm rely\"      \n   shows \"P\" \nusing a0 a1 a2 a3 a4\nproof (induct i)\n  case 0 \n  have \"(0::nat) \\<le> 0\" by fastforce  \n   thus ?thesis using only_one_component_tran_0 0 by metis\nnext\n  case (Suc n) thus ?thesis\n    by (metis Suc_leI lessI only_one_component_tran_0 prod.collapse stepc_elim_cases(1))\nqed  *)\n\nlemma not_step_comp_step_env:\n assumes a0:  \"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"(Suc j<length l)\" and \n         a2: \"(\\<forall>k < j. \\<not>((\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))))\"\n  shows \"(\\<forall>k < j. ((\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))))\"\nproof -\n  {fix k\n   assume asm: \"k<j\"\n   also then have \"Suc k<length l\" using a1 a2 by auto\n   ultimately have \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>c\\<^sub>e (l!(Suc k)))\" using a0 cptn_stepc_rtran\n  proof -\n    obtain nn :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat\" where\n      f1: \"\\<forall>x0 x1. (\\<exists>v2>x1. x0 = Suc v2) = (x1 < nn x0 x1 \\<and> x0 = Suc (nn x0 x1))\"\n      by moura\n    obtain pp :: \"nat \\<Rightarrow> (('b, 'a, 'c) LanguageCon.com \\<times> ('b, 'c) xstate) list \\<Rightarrow> ('b, 'a, 'c) LanguageCon.com \\<times> ('b, 'c) xstate\" and pps :: \"nat \\<Rightarrow> (('b, 'a, 'c) LanguageCon.com \\<times> ('b, 'c) xstate) list \\<Rightarrow> (('b, 'a, 'c) LanguageCon.com \\<times> ('b, 'c) xstate) list\" where\n      \"\\<forall>x0 x1. (\\<exists>v2 v3. x1 = v2 # v3 \\<and> length v3 = x0) = (x1 = pp x0 x1 # pps x0 x1 \\<and> length (pps x0 x1) = x0)\"\n      by moura\n    then have f2: \"l = pp (nn (length l) k) l # pps (nn (length l) k) l \\<and> length (pps (nn (length l) k) l) = nn (length l) k\"\n      using f1 by (meson Suc_lessE \\<open>Suc k < length l\\<close> length_Suc_conv)\n    then have f3: \"Suc k < length (pp (nn (length l) k) l # pps (nn (length l) k) l)\"\n      by (metis \\<open>Suc k < length l\\<close>)\n    have \"(\\<Gamma>, pp (nn (length l) k) l # pps (nn (length l) k) l) \\<in> cptn\"\n      using f2 a0 by presburger\n    then have \"\\<Gamma>\\<turnstile>\\<^sub>c (pp (nn (length l) k) l # pps (nn (length l) k) l) ! k \\<rightarrow>\\<^sub>c\\<^sub>e (pp (nn (length l) k) l # pps (nn (length l) k) l) ! Suc k\"\n      using f3 by (meson cptn_stepc_rtran)\n    then show ?thesis\n      using f2 by auto\n  qed \n   also have \"\\<not>((\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))))\" using a2 asm by auto\n   ultimately have \"((\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\" using step_ce_elim_cases by blast\n  } thus ?thesis by auto\nqed\n\nlemma cptn_i_env_same_prog:\nassumes a0: \"(\\<Gamma>, l) \\<in> cptn\" and\n        a1:  \"\\<forall>k < j. k\\<ge>i \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))\" and\n        a2: \"i\\<le>j \\<and> j < length l\"\nshows \"fst (l!j) =  fst (l!i)\"\nusing a0 a1 a2\nproof (induct \"j-i\" arbitrary: l j i)\n  case 0 thus ?case by auto    \nnext\n  case (Suc n)     \n    then have lenl:\"length l>Suc 0\" by fastforce    \n    have \"j>0\" using Suc by linarith\n    then obtain j1 where prev:\"j=Suc j1\" \n      using not0_implies_Suc by blast     \n    then obtain a0 a1 l1 where l:\"l=a0#l1@[a1]\" \n    using Suc lenl by (metis add.commute add.left_neutral length_Cons list.exhaust list.size(3) not_add_less1 rev_exhaust)     \n    then have al1_cptn:\"(\\<Gamma>,a0#l1)\\<in> cptn\"\n      using Suc.prems(1) Suc.prems(3) tl_in_cptn cptn_dest_2\n      by blast\n    have i_j:\"i\\<le>j1\" using Suc prev by auto\n    have \"\\<forall>k < j1. k\\<ge>i \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c((a0#l1)!k)  \\<rightarrow>\\<^sub>e ((a0#l1)!(Suc k)))\"\n    proof -\n       {fix k\n        assume a0:\"k<j1 \\<and> k\\<ge>i\"\n        then have \"(\\<Gamma>\\<turnstile>\\<^sub>c((a0#l1)!k)  \\<rightarrow>\\<^sub>e ((a0#l1)!(Suc k)))\" \n        using  l Suc(4) prev lenl Suc(5)\n        proof -   \n          have suc_k_j:\"Suc k < j\" using a0 prev by blast\n          have j1_l_l1:\"j1 < Suc (length l1)\" \n            using Suc.prems(3) l prev by auto\n          have \"k < Suc j1\"\n            using `k < j1 \\<and> i \\<le> k` less_Suc_eq by blast\n          hence f3: \"k < j\"\n            using prev by blast\n          hence ksuc:\"k < Suc (Suc j1)\"\n            using less_Suc_eq prev by blast\n          hence f4: \"k < Suc (length l1)\"\n            using  prev Suc.prems(3) l a0 j1_l_l1 less_trans \n            by blast            \n          have f6: \"\\<Gamma>\\<turnstile>\\<^sub>c l ! k \\<rightarrow>\\<^sub>e (l ! Suc k)\"\n            using f3 Suc(4) a0 by blast\n          have k_l1:\"k < length l1\"\n            using f3 Suc.prems(3) i_j l suc_k_j  by auto                            \n          thus ?thesis\n          proof (cases k)\n            case 0 thus ?thesis using f6 l  k_l1\n                by (simp add: nth_append)\n          next  \n            case (Suc k1) thus ?thesis \n              using f6  f4 l k_l1 \n              by (simp add: nth_append)\n          qed\n        qed\n       }thus ?thesis by auto\n    qed\n    then have fst:\"fst ((a0#l1)!i)=fst ((a0#l1)!j1)\"\n      using Suc(1)[of j1 i \"a0#l1\"] \n            Suc(2) Suc(3) Suc(4) Suc(5) prev al1_cptn i_j\n      by (metis (mono_tags, lifting) Suc_diff_le Suc_less_eq diff_Suc_1 l length_Cons length_append_singleton)\n    have len_l:\"length l = Suc (length (a0#l1))\" using l by auto\n    then have f1:\"i<length (a0#l1)\" using Suc.prems(3) i_j prev by linarith\n    then have f2:\"j1<length (a0#l1)\" using Suc.prems(3) len_l prev by auto\n    have i_l:\"fst (l!i) = fst ((a0#l1)!i)\" \n      using l prev f1 f2 fst \n      by (metis (no_types) append_Cons nth_append)\n    also have j1_l:\"fst (l!j1) = fst ((a0#l1)!j1)\"\n    using l prev f1 f2 fst \n      by (metis (no_types) append_Cons nth_append)\n    then have \"fst (l!i) = fst (l!j1)\" using\n      i_l j1_l fst by auto      \n    thus ?case using Suc prev by (metis env_c_c' i_j lessI prod.collapse)          \nqed  \n  \n\nlemma cptn_tran_ce_i: \n   assumes a1:\"(\\<Gamma>, l) \\<in> cptn  \\<and>  i + 1 < length l\"\n   shows \"\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>c\\<^sub>e (l!(Suc i))\"\nproof -\n  from a1\n  obtain a1 l1 where \"l=a1#l1\" using cptn.simps by blast\n  thus  ?thesis using a1 cptn_stepc_rtran by fastforce\nqed\n\nlemma zero_final_always_env_0: \n      assumes a1:\"(\\<Gamma>, l) \\<in> cptn\" and\n              a2: \"fst (l!0) = Skip \\<or> fst (l!0) = Throw\" and\n              a2': \"snd(l!0) = Normal s1 \\<and> s1\\<in>q\" and\n              a3: \"Suc i < length l\" and\n              a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta q rely\"\n      shows \"\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i))\"\nproof -\n   have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>c\\<^sub>e (l!(Suc i))\" using a1 a2 a3 cptn_tran_ce_i by auto   \n   also have \"\\<not> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" using a1 a2 a3 a4 a2'\n     using only_one_component_tran_0 by metis           \n   ultimately show ?thesis by (simp add: step_ce.simps) \nqed\n\nlemma final_always_env_i: \n      assumes a1:\"(\\<Gamma>, l) \\<in> cptn\" and\n              a2: \"fst (l!0) = Skip \\<or> fst (l!0) = Throw\" and\n              a2': \"snd(l!0) = Normal s1 \\<and> s1\\<in>q\" and\n              a3: \"j\\<ge>i \\<and> Suc j<length l\" and\n              a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta q rely\"\n      shows \"\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j))\"\nproof -\n   have ce_tran:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>c\\<^sub>e (l!(Suc j))\" using a1 a2 a3 a4 cptn_tran_ce_i by auto   \n   then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)) \\<or> \\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))\" \n     using step_ce_elim_cases by blast\n   thus ?thesis\n   proof\n     assume \"\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j))\" then show ?thesis by auto\n   next\n     assume a01:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))\"\n      then  have \"\\<not> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"   \n        using a1 a2 a3 a4 a2' only_one_component_tran_j [OF a1]  \n        by blast\n      then show ?thesis using a01 ce_tran by (simp add: step_ce.simps) \n   qed\nqed\n\n\nsubsection {*Skip Sound*}\n\nlemma stable_q_r_q: \n  assumes a0:\"Sta q R\"  and       \n          a1: \"snd(l!i) \\<in> Normal ` q\" and\n          a2:\"(snd(l!i), snd(l!(Suc i))) \\<in> R\"\n  shows \"snd(l!(Suc i)) \\<in> Normal ` q\"\nusing a0  a1  a2 \nunfolding Sta_def  by fastforce \n\nlemma stability:\nassumes   a0:\"Sta q R\"  and                 \n          a1: \"snd(l!j) \\<in> Normal ` q\" and\n          a2: \"j\\<le>k \\<and> k < (length l)\" and\n          a3: \"n=k-j\" and\n          a4: \"\\<forall>i. j\\<le>i \\<and> i < k \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i))\" and\n          a5:\"env_tran_right \\<Gamma> l R \"\n      shows \"snd (l!k) \\<in> Normal ` q \\<and> fst (l!j) = fst (l!k)\"\nusing a0 a1 a2 a3 a4 a5 \nproof (induct n arbitrary: j k)\n  case 0\n    thus ?case by auto\nnext\n  case (Suc n) \n    then have \"length l > j + 1\" by arith     \n    moreover then have \"k-1< length l\" using Suc by fastforce    \n    moreover then have \"(k - 1) - j = n\" using Suc by fastforce\n    moreover then have  \"j\\<le>k-1\" using Suc by arith \n    moreover have \"\\<forall>i. j \\<le> i \\<and> i < k-1 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c (l ! i) \\<rightarrow>\\<^sub>e (l ! Suc i)\"\n      using Suc by fastforce    \n    ultimately have induct:\"snd (l! (k-1)) \\<in> Normal ` q \\<and> fst (l!j) = fst (l!(k-1))\" using Suc\n      by blast      \n    also have j_1:\"k-1+1=k\" using Cons Suc.prems(4) by auto \n    have f1:\"\\<forall>i. j\\<le>i \\<and> i < k \\<longrightarrow> (snd((snd (\\<Gamma>,l))!i), snd((snd (\\<Gamma>,l))!(Suc i))) \\<in>  R\"\n    using Suc unfolding env_tran_right_def by fastforce\n    have  k1:\"k - 1 < k\"\n      by (metis (no_types) Suc_eq_plus1 j_1 lessI)    \n    then have \"(snd((snd (\\<Gamma>,l))!(k-1)), snd((snd (\\<Gamma>,l))!(Suc (k-1)))) \\<in>  R\"    \n    using `j \\<le> k - 1` f1 by blast                           \n    ultimately have \"snd (l!k) \\<in> Normal ` q\" using stable_q_r_q Suc(2)  Suc(5)  by fastforce\n    also have \"fst (l!j) = fst (l!k)\"\n    proof -\n      have \"\\<Gamma>\\<turnstile>\\<^sub>c (l ! (k-1)) \\<rightarrow>\\<^sub>e (l ! k)\" using Suc(6) k1 `j\\<le>k-1` by fastforce\n      thus ?thesis using k1 prod.collapse env_c_c' induct by metis\n    qed\n    ultimately show ?case by meson\nqed\n\nlemma stable_only_env_i_j: \n  assumes a0:\"Sta q R\"  and                 \n          a1: \"snd(l!i) \\<in> Normal ` q\" and\n          a2: \"i<j \\<and> j < (length l)\" and\n          a3: \"n=j-i-1\" and\n          a4: \"\\<forall>k\\<ge>i. k < j \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))\" and\n          a5: \"env_tran_right \\<Gamma> l R\"\n      shows \"snd (l!j) \\<in> Normal ` q\"\nusing a0 a1 a2 a3 a4 a5  by (meson less_imp_le_nat  stability)\n\n  \nlemma stable_only_env_1: \n  assumes a0:\"Sta q R\"  and                 \n          a1: \"snd(l!i) \\<in> Normal ` q\" and\n          a2: \"i<j \\<and> j < (length l)\" and\n          a3: \"n=j-i-1\" and\n          a4: \"\\<forall>i. Suc i < length l \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i))\" and\n          a5: \"env_tran_right \\<Gamma> l R\"\n      shows \"snd (l!j) \\<in> Normal ` q\"\nusing a0 a1 a2 a3 a4 a5 \nby (meson stable_only_env_i_j less_trans_Suc)\n\n\nlemma stable_only_env_q: \n  assumes a0:\"Sta q R\"  and                 \n          a1: \"\\<forall>i. Suc i < length l \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i))\" and\n          a2: \"env_tran \\<Gamma> q l R\"\n      shows \"\\<forall>i. i < length l \\<longrightarrow> snd (l!i) \\<in> Normal ` q\"\nproof (cases \"0 < length l\")\n  case False thus ?thesis using a2 unfolding env_tran_def by fastforce \nnext\n  case True \n  thus ?thesis \n  proof - {\n    fix i\n    assume aa1:\"i < length l\"\n    have post_0:\"snd (l ! 0) \\<in> Normal ` q \" \n      using a2 unfolding env_tran_def by auto\n    then have \"snd (l ! i) \\<in> Normal ` q\"     \n    proof (cases i) \n      case 0 thus ?thesis using post_0 by auto\n    next\n      case (Suc n) \n      \n      have \"env_tran_right \\<Gamma> l R\" \n        using a2 env_tran_right_def unfolding env_tran_def by auto\n      also have \"0<i\" using Suc by auto\n      ultimately show ?thesis \n        using post_0 stable_only_env_1  a0 a1 a2 aa1  by blast\n    qed\n  } then show ?thesis by auto qed\nqed\n\n\n\nlemma Skip_sound: \n  \"Sta q R \\<Longrightarrow>       \n   (\\<forall>s. (Normal s, Normal s) \\<in> G)  \\<Longrightarrow>\n   \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> Skip sat [q,R, G, q,a]\"\nproof -  \n assume\n    a0:\"Sta q R\" and    \n    a1:\"(\\<forall>s. (Normal s, Normal s) \\<in> G)\"\n  {\n    fix s\n    have ass:\"cpn n \\<Gamma> Skip s \\<inter> assum(q, R) F \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cpn n \\<Gamma> Skip s\" and a11:\"c \\<in> assum(q, R) F\"\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have \"c \\<in> comm(G, (q,a)) F\"      \n      proof - \n      {assume \"snd (last l) \\<notin> Fault ` F\"       \n       then have cp:\"l!0=(Skip,s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\"\n         using a10 cpn_def c_prod cptn_eq_cptn_mod_set  cptn_mod_same_n\n                cptn_mod_eq_cptn_mod_nest cptn_eq_cptn_mod by fastforce\n       have assum:\"snd(l!0) \\<in> Normal ` q \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n                   (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n       using a11 c_prod unfolding assum_def by simp\n       have concl:\"(\\<forall>i. Suc i<length l \\<longrightarrow> \n               \\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                             \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n       proof -\n       { fix i\n         assume asuc:\"Suc i<length l\"        \n         then have \"\\<not> (\\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\"\n           by (metis Suc_lessD cp prod.collapse prod.sel(1) stepc_elim_cases(1) zero_skip_all_skip)\n       } thus ?thesis by auto qed\n       have concr:\"(final (last l)  \\<longrightarrow>                    \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a)))\"\n       proof-\n       { \n         assume valid:\"final (last l)\"\n         have len_l:\"length l > 0\" using cp using cptn.simps by blast \n         then obtain a l1 where l:\"l=a#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n         have last_l:\"last l = l!(length l-1)\"\n            using last_length [of a l1] l by fastforce\n         then have fst_last_skip:\"fst (last l) = Skip\"             \n           by (metis `0 < length l` cp diff_less fst_conv zero_less_one zero_skip_all_skip)                           \n         have last_q: \"snd (last l) \\<in> Normal ` q\"    \n         proof -\n           have env: \"env_tran \\<Gamma> q l R\" using env_tran_def assum cp by blast\n           have env_right:\"env_tran_right \\<Gamma> l R \" using  a0 env_tran_right_def assum cp by metis\n           also obtain s1 where \"snd(l!0) = Normal s1 \\<and> s1\\<in>q\" \n             using assum by auto\n           ultimately have all_tran_env: \"\\<forall>i. Suc i < length l \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i))\"\n             using final_always_env_i cp zero_final_always_env_0 a0\n             by fastforce\n           then have \"\\<forall>i. i < length l \\<longrightarrow> snd (l!i) \\<in> Normal ` q\"\n           using stable_only_env_q  a0  env  by fastforce\n           thus ?thesis using last_l using len_l by fastforce    \n         qed                \n         note res = conjI [OF fst_last_skip last_q]\n       } thus ?thesis by auto qed\n       note res = conjI [OF concl concr]               \n      }              \n      thus ?thesis using c_prod unfolding comm_def by auto qed      \n    } thus ?thesis by auto qed \n  } thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def) \nqed\n\nlemma Throw_sound: \n  \"Sta a R  \\<Longrightarrow>\n   (\\<forall>s. (Normal s, Normal s) \\<in> G) \\<Longrightarrow>\n   \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> Throw sat [a, R, G, q,a]\"\nproof -  \n assume   \n    a1:\"Sta a R\" and\n    a2:\" (\\<forall>s. (Normal s, Normal s) \\<in> G)\" \n  {\n    fix s\n    have \"cpn n \\<Gamma> Throw s \\<inter> assum(a, R) F \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cpn n \\<Gamma> Throw s\" and a11:\"c \\<in> assum(a, R) F\"\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have \"c \\<in> comm(G, (q,a)) F\"      \n      proof - \n      {assume \"snd (last l) \\<notin> Fault ` F\"\n       have cp:\"l!0=(Throw,s) \\<and> (n,\\<Gamma>,l) \\<in> cptn_mod_nest_call \\<and> \\<Gamma>=\\<Gamma>1\" \n         using a10 cpn_def c_prod cptn_eq_cptn_mod_set  cptn_mod_same_n by fastforce\n       then have cp:\"l!0=(Throw,s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\"\n         using  cptn_mod_eq_cptn_mod_nest cptn_eq_cptn_mod by fastforce       \n       have assum:\"snd(l!0) \\<in> Normal ` (a) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n                   (snd(l!i), snd(l!(Suc i))) \\<in> (R))\" \n       using a11 c_prod unfolding assum_def by simp\n       then have env_tran:\"env_tran_right \\<Gamma> l R\" using cp env_tran_right_def by auto\n       obtain a1 where a_normal:\"snd(l!0) = Normal a1 \\<and> a1 \\<in> a\"\n         using assum by auto\n       have concl:\"(\\<forall>i ns ns'. Suc i<length l \\<longrightarrow> \n               \\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                                           \n                 (snd(l!i), snd(l!(Suc i))) \\<in>  (G))\"\n       proof -\n       { fix i\n         assume asuc:\"Suc i<length l\"\n         then have asuci:\"i<length l\" by fastforce\n         then have \"fst (l ! 0) = LanguageCon.com.Throw\" using cp by auto\n         moreover obtain s1 where \"snd (l ! 0) = Normal s1\" using assum by auto\n         ultimately have \"fst (l ! i) = Throw \\<and> (\\<exists>s2. snd (l ! i) = Normal s2)\"      \n           using cp a1 assum a_normal env_tran asuci zero_throw_all_throw\n           by fastforce\n         then have \"\\<not> (\\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\"\n           by (meson SmallStepCon.final_def SmallStepCon.no_step_final')           \n       } thus ?thesis by auto qed\n       have concr:\"(final (last l)  \\<longrightarrow>                    \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a)))\"\n       proof-\n       { \n         assume valid:\"final (last l)\"\n         have len_l:\"length l > 0\" using cp using cptn.simps by blast \n         then obtain a1 l1 where l:\"l=a1#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n         have last_l:\"last l = l!(length l-1)\"\n            using last_length [of a1 l1] l by fastforce\n         then have fst_last_skip:\"fst (last l) = Throw\"\n           by (metis a1 a_normal cp diff_less env_tran fst_conv len_l zero_less_one zero_throw_all_throw)                        \n         have last_q: \"snd (last l) \\<in> Normal ` (a)\"    \n         proof -\n           have env: \"env_tran \\<Gamma> a l R\" using env_tran_def assum cp by blast\n           have env_right:\"env_tran_right \\<Gamma> l R\" using env_tran_right_def assum cp by metis\n           then have all_tran_env: \"\\<forall>i. Suc i < length l \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i))\"\n           using final_always_env_i a1 assum cp zero_final_always_env_0 by fastforce            \n           then have \"\\<forall>i. i < length l \\<longrightarrow> snd (l!i) \\<in> Normal ` (a)\"\n           using stable_only_env_q  a1  env by fastforce\n           thus ?thesis using last_l using len_l by fastforce    \n         qed                \n         note res = conjI [OF fst_last_skip last_q]\n       } thus ?thesis by auto qed\n       note res = conjI [OF concl concr]               \n      }             \n      thus ?thesis using c_prod unfolding comm_def by auto qed      \n    } thus ?thesis by auto qed \n  } thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def) \nqed\n\nlemma no_comp_tran_before_i_0_g:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!0) = c \" and         \n         a2: \"Suc i<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"j < i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\" and\n         a4: \"\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))\" and\n         a5: \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(c, s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> \n                        (c1=Skip) \\<or> (c1=Throw \\<and> (\\<exists>s21. s2 = Normal s21))\" and        \n         a6: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc j) \\<in> Normal ` q\"\n   shows \"P\"\n  proof -\n   have \"Suc j < length l\" using a0 a1 a2 a3 a4 by fastforce\n   then have \"fst (l!j) = c\" \n     using a0 a1 a2 a3 a4 cptn_env_same_prog[of \\<Gamma> l j] by fastforce\n   then obtain s s1 c1 where l_0: \"l!j = (c, s) \\<and> l!(Suc j) = (c1,s1)\"  \n     by (metis (no_types) prod.collapse)    \n   moreover have \"snd (l!j) \\<in> Normal ` p\" using a4 stability[of p rely l 0 j j] a6 a3 a2\n    proof -\n      have \"\\<forall>B r ps n na nb f. \\<not> Sta B r \\<or> snd (ps ! n) \\<notin> Normal ` B \\<or> \\<not> n \\<le> na \\<or> \\<not> na < length ps \\<or> na - n \\<noteq> nb \\<or> (\\<exists>nb\\<ge>n. nb < na \\<and> \\<not> f\\<turnstile>\\<^sub>c ps ! nb \\<rightarrow>\\<^sub>e ps ! Suc nb) \\<or> \\<not> env_tran_right f ps r \\<or> snd (ps ! na) \\<in> Normal ` B \\<and> (fst (ps ! n)::('b, 'a, 'c) LanguageCon.com) = fst (ps ! na)\"\n        using stability by blast\n      then show ?thesis\n        using Suc_lessD \\<open>Suc j < length l\\<close> a4 a6 by blast\n    qed      \n   then have suc_0_skip: \"(fst (l!Suc j) = Skip \\<or> fst (l!Suc j) = Throw) \\<and> \n                           (\\<exists>s2. snd(l!Suc j) = Normal s2 ) \" \n      using a5 a6 a3 SmallStepCon.step_Stuck_prop using fst_conv imageE l_0 snd_conv by auto \n   thus ?thesis using only_one_component_tran_j\n    proof -\n      have \"\\<forall>n na. \\<not> n < na \\<or> Suc n \\<le> na\"\n        using Suc_leI by satx  \n      thus ?thesis using only_one_component_tran_j[OF a0] suc_0_skip a6 a0 a2 a3\n        using imageE by blast          \n    qed\nqed\n\nlemma no_comp_tran_before_i:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = c\" and        \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"k\\<le>j \\<and> j < i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\" and\n         a4: \"\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))\" and\n          a5: \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(c, s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> \n                        (c1=Skip) \\<or> (c1=Throw \\<and> (\\<exists>s21. s2 = Normal s21))\" and        \n         a6: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc j) \\<in> Normal ` q\"\n   shows \"P\"\nusing a0 a1 a2 a3 a4 a5 a6\nproof (induct k arbitrary: l i j)\n  case 0 thus ?thesis using no_comp_tran_before_i_0_g by blast\nnext\n  case (Suc n) \n  then obtain a1 l1 where l: \"l=a1#l1\"\n    by (metis less_nat_zero_code list.exhaust list.size(3))\n  then have l1notempty:\"l1\\<noteq>[]\" using Suc by force    \n  then obtain i' where i': \"i=Suc i'\" using Suc \n    using less_imp_Suc_add by blast\n  then obtain j' where j': \"j=Suc j'\" using Suc\n    using Suc_le_D by blast      \n  have \"(\\<Gamma>,l1)\\<in>cptn\" using Suc l\n    using tl_in_cptn l1notempty by blast\n  moreover have \"fst (l1 ! n) = c\"\n    using Suc l l1notempty by force  \n  moreover have \"Suc i' < length l1 \\<and> n \\<le> i' \\<and> \\<Gamma>\\<turnstile>\\<^sub>c l1 ! i' \\<rightarrow> (l1 ! Suc i')\"\n    using Suc l l1notempty i' by auto\n  moreover have \"n \\<le> j' \\<and> j' < i' \\<and> \\<Gamma>\\<turnstile>\\<^sub>c l1 ! j' \\<rightarrow> (l1 ! Suc j')\"\n    using Suc l l1notempty i' j' by auto\n  moreover have \"\\<forall>k<j'. \\<Gamma>\\<turnstile>\\<^sub>c l1 ! k \\<rightarrow>\\<^sub>e (l1 ! Suc k)\"\n    using Suc l l1notempty j' by auto     \n  moreover have \"env_tran_right \\<Gamma> l1 rely \\<and> Sta q rely \\<and> Sta p rely \\<and> snd (l1!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l1!Suc j') \\<in> Normal ` q\" \n  proof -\n    have suc0:\"Suc 0 < length l\" using Suc by auto\n    have \"j>0\" using j' by auto\n    then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!0)  \\<rightarrow>\\<^sub>e (l!(Suc 0))\" using Suc(6) by blast\n    then have \"(snd(l!Suc 0) \\<in> Normal ` p)\" \n      using Suc(8) suc0 unfolding Sta_def env_tran_right_def by blast\n    also have \"snd (l!Suc j) \\<in> Normal ` q\" using Suc(8) by auto\n    ultimately show ?thesis using Suc(8) l by (metis env_tran_tail j' nth_Cons_Suc) \n  qed\n  ultimately show ?case using Suc(1)[of l1 i' j' ]  Suc(7)  Suc(8) j' l by auto\nqed\n\nlemma exists_first_occ: \"P (n::nat) \\<Longrightarrow> \\<exists>m. P m \\<and> (\\<forall>i<m. \\<not> P i)\"\nproof (induct n)\n  case 0 thus ?case by auto\nnext\n  case (Suc n) thus ?case\n  by (metis ex_least_nat_le not_less0) \nqed\n\nlemma exist_first_comp_tran':\nassumes a1: \"Suc i<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\"      \nshows \"\\<exists>j. (Suc j<length l \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))) \\<and> (\\<forall>k < j. \\<not>\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\nproof -\n  let ?P =  \"(\\<lambda>n. Suc n<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!n)  \\<rightarrow> (l!(Suc n))))\"\n  show ?thesis using exists_first_occ[of ?P i] a1 by auto  \nqed\n\nlemma exist_first_comp_tran:\nassumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n        a1: \"Suc i<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\"      \nshows \"\\<exists>j. j\\<le>i \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\nproof -\n  obtain j where  pj:\"(Suc j<length l \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))) \\<and> \n                     (\\<forall>k < j. \\<not>(Suc k<length l \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))))\"\n    using a1 exist_first_comp_tran' by blast\n  then have \"j\\<le>i\" using a1 pj by (cases \"j\\<le>i\", auto)\n  moreover have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))\" using pj by auto\n  moreover have \"(\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\" \n  proof -\n    {fix k\n    assume kj:\"k<j\"\n    then have \"Suc k \\<ge> length l \\<or>  \\<not> ( (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))) \" using pj by auto\n    then have \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))\"\n    proof\n      {assume \"length l \\<le> Suc k\" \n       thus ?thesis using kj pj by auto\n      }\n      {assume \"\\<not> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n       also have \"k + 1 < length l\" using kj pj by auto\n       ultimately show ?thesis\n         using a0 cptn_tran_ce_i step_ce_elim_cases by blast\n      }\n    qed\n    } thus ?thesis by auto\n  qed\n  ultimately show ?thesis by auto\nqed\n\n\nlemma skip_com_all_skip:\nassumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n        a1:\"fst (l!i) = Skip\" and\n        a2:\"i<length l\" \n   shows \"\\<forall>j. j\\<ge>i \\<and> j <length l \\<longrightarrow> fst (l!j) = Skip\"\nusing a0 a1 a2\nproof (induct \"length l - (i + 1)\" arbitrary: i)\n  case 0  thus ?case by (metis Suc_eq_plus1 Suc_leI diff_is_0_eq nat_less_le zero_less_diff) \nnext \n  case (Suc n)\n  then have l:\"Suc i < length l\" by arith\n  have n:\"n = (length l) - (Suc i + 1)\" using Suc by arith\n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow>\\<^sub>c\\<^sub>e l ! Suc i\" using cptn_tran_ce_i Suc\n    by (metis (no_types) Suc.hyps(2) a0 cptn_tran_ce_i zero_less_Suc zero_less_diff)\n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow> l ! Suc i \\<or> \\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow>\\<^sub>e l ! Suc i\" \n    using step_ce_elim_cases by blast  \n  then have or:\"fst(l!Suc i) = Skip\" \n  proof\n    {assume \"\\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow>\\<^sub>e l ! Suc i\" \n     thus ?thesis using Suc(4) by (metis env_c_c' prod.collapse)\n    }\n  next\n   {assume step:\"\\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow> l ! Suc i\" \n     {assume \"fst(l!i) = Skip\" \n      then have ?thesis using step\n        using SmallStepCon.final_def SmallStepCon.no_step_final' by blast\n     }note left = this\n     {assume \"fst(l!i) = Throw\"\n      then have ?thesis using step stepc_elim_cases\n      proof -\n        have \"\\<exists>x. l ! Suc i = (LanguageCon.com.Skip, x)\"\n          by (metis (no_types) \\<open>fst (l ! i) = LanguageCon.com.Throw\\<close> local.step stepc_elim_cases(11) surjective_pairing)\n        then show ?thesis\n          by fastforce\n      qed      \n     } then show ?thesis using Suc(4) left by auto\n    }\n  qed\n  show ?case using Suc(1)[OF n a0 or l] Suc(4) Suc(5) by (metis le_less_Suc_eq not_le) \nqed\n\nlemma terminal_com_all_term:\nassumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n        a1:\"fst (l!i) = Skip \\<or> fst (l!i) = Throw\" and\n        a2:\"i<length l\" \n   shows \"\\<forall>j. j\\<ge>i \\<and> j <length l \\<longrightarrow> fst (l!j) = Skip \\<or> fst (l!j) = Throw\"\nusing a0 a1 a2\nproof (induct \"length l - (i + 1)\" arbitrary: i)\n  case 0  thus ?case by (metis Suc_eq_plus1 Suc_leI diff_is_0_eq nat_less_le zero_less_diff) \nnext \n  case (Suc n)\n  then have l:\"Suc i < length l\" by arith\n  have n:\"n = (length l) - (Suc i + 1)\" using Suc by arith\n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow>\\<^sub>c\\<^sub>e l ! Suc i\" using cptn_tran_ce_i Suc\n    by (metis (no_types) Suc.hyps(2) a0 cptn_tran_ce_i zero_less_Suc zero_less_diff)\n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow> l ! Suc i \\<or> \\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow>\\<^sub>e l ! Suc i\" \n    using step_ce_elim_cases by blast  \n  then have or:\"fst(l!Suc i) = Skip \\<or> fst(l!Suc i) = Throw\" \n  proof\n    {assume \"\\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow>\\<^sub>e l ! Suc i\" \n     thus ?thesis using Suc(4) by (metis env_c_c' prod.collapse)\n    }\n  next\n   {assume step:\"\\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow> l ! Suc i\" \n     {assume \"fst(l!i) = Skip\" \n      then have ?thesis using step\n        using SmallStepCon.final_def SmallStepCon.no_step_final' by blast\n     }note left = this\n     {assume \"fst(l!i) = Throw\"\n      then have ?thesis using step stepc_elim_cases\n      proof -\n        have \"\\<exists>x. l ! Suc i = (LanguageCon.com.Skip, x)\"\n          by (metis (no_types) \\<open>fst (l ! i) = LanguageCon.com.Throw\\<close> local.step stepc_elim_cases(11) surjective_pairing)\n        then show ?thesis\n          by fastforce\n      qed      \n     } then show ?thesis using Suc(4) left by auto\n    }\n  qed\n  show ?case using Suc(1)[OF n a0 or l] Suc(4) Suc(5) by (metis le_less_Suc_eq not_le) \nqed\n\nlemma only_one_c_comp_tran:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!0) = c\" and         \n         a2: \"Suc i<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"i < j \\<and> Suc j < length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> fst (l!j) = c\" and\n         a4: \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(c, s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> \n                        ((c1=Skip) \\<or> (c1=Throw)) \" and\n         a5: \"(\\<forall>k < i. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n   shows \"P\"\nproof - \n  have fst:\"fst (l!i) = c\" using a0 a1 a5\n    by (simp add: a2 cptn_env_same_prog)\n  then have suci:\"fst (l!Suc i) = Skip \\<or> fst (l!Suc i) = Throw\" \n    using a4 by (metis a2 surjective_pairing) \n  then have \"fst (l!j) = Skip \\<or> fst (l!j) = Throw\" \n  proof -\n    have \"Suc i \\<le> j\"\n      using Suc_leI a3 by presburger\n    then show ?thesis\n      using Suc_lessD  terminal_com_all_term[OF a0 suci] a2 a3 by blast\n  qed \n  thus ?thesis\n  proof \n    {assume \"fst (l ! j) = Skip\"\n     then show ?thesis using a3 SmallStepCon.final_def SmallStepCon.no_step_final' by blast\n    }\n  next\n    {assume asm:\"fst (l ! j) = Throw\"\n     then show ?thesis       \n       proof (cases \"snd (l!i)\")\n         case Normal \n         thus ?thesis using a3 a2 fst asm\n           by (metis SmallStepCon.final_def SmallStepCon.no_step_final') \n       next\n         case Abrupt thus ?thesis using a3 a2 fst asm skip_com_all_skip\n           by (metis Suc_leI Suc_lessD a0 \n                     prod.collapse step_change_p_or_eq_s_normal \n                     stepc_Normal_elim_cases(11) suci)\n       next \n         case Fault thus ?thesis using a3 a2 fst asm skip_com_all_skip \n           by (metis Suc_leI Suc_lessD a0 prod.collapse \n                     step_change_p_or_eq_s_normal stepc_Normal_elim_cases(11) suci)\n       next \n         case Stuck thus ?thesis using a3 a2 fst asm skip_com_all_skip \n            by (metis Suc_leI Suc_lessD a0 \n                      prod.collapse step_change_p_or_eq_s_normal \n                      stepc_Normal_elim_cases(11) suci)\n       qed\n    } \n  qed\nqed\n\nlemma only_one_component_tran1:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!0) = c\" and         \n         a2: \"Suc i<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"j \\<noteq> i \\<and> Suc j < length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> fst (l!j) = c\" and\n         a4: \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(c, s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> \n                        ((c1=Skip) \\<or> (c1=Throw)) \" and\n         a5: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc j) \\<in> Normal ` q \"\n   shows \"P\"\nproof (cases \"j=i\")\n  case True thus ?thesis using a3 by auto\nnext\n  case False note j_neq_i=this \n  thus ?thesis\n  proof (cases \"j<i\")\n    case True \n    thus ?thesis \n    proof -\n      obtain bb :: \"'b set \\<Rightarrow> ('b \\<Rightarrow> ('b, 'c) xstate) \\<Rightarrow> ('b, 'c) xstate \\<Rightarrow> 'b\" where\n        \"\\<forall>x0 x1 x2. (\\<exists>v3. x2 = x1 v3 \\<and> v3 \\<in> x0) = (x2 = x1 (bb x0 x1 x2) \\<and> bb x0 x1 x2 \\<in> x0)\"\n        by moura\n      then have f1: \"\\<forall>x f B. x \\<notin> f ` B \\<or> x = f (bb B f x) \\<and> bb B f x \\<in> B\"\n        by (meson imageE)\n      then have \"\\<Gamma>\\<turnstile>\\<^sub>c (c, snd (l ! j)) \\<rightarrow> (fst (l ! Suc j), Normal (bb q Normal (snd (l ! Suc j))))\"\n        by (metis (no_types) a3 a5 surjective_pairing)\n      then show ?thesis\n        using f1 by (meson Suc_leI a0 a2 a4 a5 True only_one_component_tran_j)\n    qed  \n  next\n    case False \n    obtain j1 \n    where all_ev:\"j1\\<le>i \\<and>  \n                 (\\<Gamma>\\<turnstile>\\<^sub>c(l!j1)  \\<rightarrow> (l!(Suc j1))) \\<and> \n                 (\\<forall>k < j1. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n      using a0 a2 a3 exist_first_comp_tran by blast\n    then have fst:\"fst (l!j1) = c\" \n      using a0 a1 a2 cptn_env_same_prog le_imp_less_Suc less_trans_Suc by blast\n    have suc:\"Suc j1 < length l \\<and> \\<Gamma>\\<turnstile>\\<^sub>c l ! j1 \\<rightarrow> l ! Suc j1\" using all_ev a2\n       using Suc_lessD le_eq_less_or_eq less_trans_Suc by linarith\n    have evs:\"(\\<forall>k < j1. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\" using all_ev by auto\n    have j:\"j1 < j \\<and> Suc j < length l \\<and> \\<Gamma>\\<turnstile>\\<^sub>c l ! j \\<rightarrow> l ! Suc j \\<and> fst (l ! j) = c\"\n      using a3 all_ev False by auto\n    then show ?thesis \n      using only_one_c_comp_tran[OF a0 a1 suc j a4 evs] by auto   \n  qed\nqed  \n \nlemma only_one_component_tran_i:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = c\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"k\\<le>j \\<and> j \\<noteq> i \\<and> Suc j < length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> fst (l!j) = c\" and\n         a4: \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(c, s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> \n                        ((c1=Skip) \\<or> (c1=Throw)) \" and\n         a5: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc j) \\<in> Normal ` q \"\n   shows \"P\"\nusing a0 a1 a2 a3 a4 a5\nproof (induct k arbitrary: l i j p q)\n  case 0 show ?thesis using only_one_component_tran1[OF 0(1) 0(2) ]  0 by blast\nnext\n  case (Suc n) \n   then obtain a1 l1 where l: \"l=a1#l1\"\n    by (metis less_nat_zero_code list.exhaust list.size(3))\n  then have l1notempty:\"l1\\<noteq>[]\" using Suc by force    \n  then obtain i' where i': \"i=Suc i'\" using Suc \n    using less_imp_Suc_add using Suc_le_D by meson \n  then obtain j' where j': \"j=Suc j'\" using Suc\n    using Suc_le_D by meson      \n  have a0:\"(\\<Gamma>,l1)\\<in>cptn\" using Suc l\n    using tl_in_cptn l1notempty by meson\n  moreover have a1:\"fst (l1 ! n) = c\"\n    using Suc l l1notempty by force  \n  moreover have a2:\"Suc i' < length l1 \\<and> n \\<le> i' \\<and> \\<Gamma>\\<turnstile>\\<^sub>c l1 ! i' \\<rightarrow> (l1 ! Suc i')\"\n    using Suc l l1notempty i' by auto\n  moreover have a3:\"n \\<le> j' \\<and> j' \\<noteq> i' \\<and> Suc j' < length l1 \\<and> \\<Gamma>\\<turnstile>\\<^sub>c l1 ! j' \\<rightarrow> (l1 ! Suc j') \\<and> fst (l1!j') = c\"\n    using Suc l l1notempty i' j' by auto\n  moreover have a4:\"env_tran_right \\<Gamma> l1 rely \\<and>\n                  Sta p rely \\<and> snd (l1!n) \\<in> Normal ` p \\<and> \n                  Sta q rely \\<and> snd (l1 ! Suc j') \\<in> Normal ` q \" \n     using Suc(7) l j' unfolding env_tran_right_def by fastforce\n  show ?case using Suc(1)[OF a0 a1 a2 a3 Suc(6) a4] by auto\nqed\n\nlemma only_one_component_tran:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = c\" and         \n         a2: \"k\\<le>i \\<and>  i \\<noteq> j \\<and> Suc i<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i))) \\<and>   fst (l!i) = c\" and\n         a3: \"k\\<le>j \\<and> Suc j < length l\" and\n         a4: \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(c,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> \n                        ((c1=Skip) \\<or> (c1=Throw))\" and\n         a5: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q \"\n   shows \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\nusing a0 a1 a2 a3 a4 a5 only_one_component_tran_i\nproof -\n  {assume \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<or> (\\<not> \\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"\n   then have  \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n   proof\n     assume \"\\<Gamma>\\<turnstile>\\<^sub>c l ! j \\<rightarrow> (l ! Suc j)\" \n       then have j:\"Suc j<length l \\<and> k\\<le>j \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\" using a3 by auto\n       show ?thesis using only_one_component_tran_i[OF a0 a1 j a2 a4 a5] \n        by blast \n   next\n      assume \"\\<not> \\<Gamma>\\<turnstile>\\<^sub>c l ! j \\<rightarrow> (l ! Suc j)\"\n        thus ?thesis\n          by (metis Suc_eq_plus1 a0 a3 cptn_tran_ce_i step_ce_elim_cases)\n   qed\n  } thus ?thesis by auto\nqed\n  \nlemma only_one_component_tran_all_env:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = c\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i))) \\<and> fst (l!i) = c\" and\n         a3: \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(c,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> \n                        ((c1=Skip) \\<or> (c1=Throw))\" and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q \"\n   shows \"\\<forall>j. k\\<le>j \\<and> j\\<noteq>i \\<and> Suc j < (length l) \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\nproof -\n  {fix j\n  assume ass:\"k\\<le>j \\<and> j\\<noteq>i \\<and> Suc j < (length l)\"\n  then have a2:\"k \\<le> i \\<and> i \\<noteq> j \\<and> Suc i < length l \\<and> \\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow> l ! Suc i \\<and> fst (l ! i) = c\"\n    using a2 by auto\n  then have \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\" \n    using only_one_component_tran[OF a0 a1 ] a2 a3 ass a4 by blast\n  } thus ?thesis by auto\nqed\n\nlemma only_one_component_tran_all_not_comp:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = c\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i))) \\<and> fst (l!i) = c\" and\n         a3: \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(c, s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> \n                        ((c1=Skip) \\<or> (c1=Throw))\" and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q \"\n   shows \"\\<forall>j. k\\<le>j \\<and> j\\<noteq>i \\<and> Suc j < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"\nproof -\n  {fix j\n  assume ass:\"k\\<le>j \\<and> j\\<noteq>i \\<and> Suc j < (length l)\"\n  then have \"\\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"    \n      using a0 a1 a2 a3 a4 only_one_component_tran_i ass by blast   \n  } thus ?thesis by auto\nqed\n\nlemma final_exist_component_tran1:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n          a1: \"fst (l!i) = c\" and               \n          a2: \"env_tran \\<Gamma> q l R \\<and> Sta q R\" and\n          a3: \"i\\<le>j \\<and> j < length l \\<and> final (l!j)\" and          \n          a5: \"c\\<noteq>Skip \\<and> c\\<noteq>Throw\"\n  shows \"\\<exists>k. k\\<ge>i \\<and> k<j \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\nproof -\n  {assume \"\\<forall>k. k\\<ge>i \\<and>  k<j \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\" \n   then have \"\\<forall>k. k\\<ge>i \\<and>  k<j \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))\"\n   by (metis (no_types, lifting) Suc_eq_plus1 a0 a3 cptn_tran_ce_i less_trans_Suc step_ce_elim_cases)\n   then have \"fst (l!j) =  fst (l!i)\" using cptn_i_env_same_prog a0 a3 by blast \n   then have False using a3 a1 a5 unfolding final_def by auto\n  }  \n  thus ?thesis by auto\nqed  \n\nlemma final_exist_component_tran:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n          a1: \"fst (l!i) = c\" and                         \n          a2: \"i\\<le>j \\<and> j < length l \\<and> final (l!j)\" and          \n          a3: \"c\\<noteq>Skip \\<and> c\\<noteq>Throw\"\n  shows \"\\<exists>k. k\\<ge>i \\<and> k<j \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\nproof -\n  {assume \"\\<forall>k. k\\<ge>i \\<and>  k<j \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\" \n   then have \"\\<forall>k. k\\<ge>i \\<and>  k<j \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))\"\n   by (metis (no_types, lifting) Suc_eq_plus1 a0 a2 cptn_tran_ce_i less_trans_Suc step_ce_elim_cases)\n   then have \"fst (l!j) =  fst (l!i)\" using cptn_i_env_same_prog a0 a2 by blast \n   then have False using a2 a1 a3 unfolding final_def by auto\n  }  \n  thus ?thesis by auto\nqed\n\nlemma suc_not_final_final_c_tran:\n assumes a0: \"(\\<Gamma>, l) \\<in> cptn \" and \n         a1: \"Suc j< length l \\<and> \\<not>final (l!j) \\<and> final (l!Suc j)\"\n shows \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"\nproof -\n   obtain x xs where l:\"l = x#xs\" using a0 cptn.simps by blast\n   obtain c1 s1 c2 s2 where l1:\"l!j = (c1,s1) \\<and> l!(Suc j) = (c2,s2)\" using a1 by fastforce\n   have \"\\<not> \\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j))\" \n   proof -\n      { assume a:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j))\"\n        then have eq_fst:\"fst (l!j) = fst (l!Suc j)\" by (metis env_c_c' prod.collapse)\n        { assume \"fst (l!Suc j) = Skip\"\n          then have \"False\" using a1 eq_fst unfolding final_def by fastforce\n        }note p1=this\n        { assume \"fst (l!Suc j) = Throw \\<and> (\\<exists>s. snd (l!Suc j) = Normal s)\" \n          then have \"False\" using a1 eq_fst unfolding final_def\n          by (metis a eenv_normal_s'_normal_s local.l1 snd_conv)\n        }\n        then have False using a1 p1 unfolding final_def by fastforce\n      } thus ?thesis by auto\n   qed\n   also have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>c\\<^sub>e (l!(Suc j))\" using l cptn_stepc_rtran a0 a1 by fastforce  \n   ultimately show ?thesis using step_ce_not_step_e_step_c local.l1 by fastforce \nqed\n \nlemma final_exist_component_tran_final:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and                                  \n          a2: \"i\\<le>j \\<and> j < length l \\<and> final (l!j)\" and                             \n          a3: \"\\<not>final(l!i)\" \n  shows \"\\<exists>k. k\\<ge>i \\<and> k<j \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final(l!(Suc k))\"\nproof -\n  let ?P = \"\\<lambda>j. i\\<le>j \\<and> j < length l \\<and> final (l!j)\"\n  obtain k where k:\"?P k \\<and> (\\<forall>i<k. \\<not> ?P i)\" using a2 exists_first_occ[of ?P j] by auto\n  then have i_k_not_final:\"\\<forall>i'<k. i'\\<ge>i \\<longrightarrow> \\<not>final (l!i')\" using a2 by fastforce\n  have i_eq_j:\"i<j\" using a2 a3 using le_imp_less_or_eq by auto \n  then obtain pre_k  where pre_k:\"Suc pre_k = k\" using a2 k\n    by (metis a3 eq_iff le0 lessE neq0_conv) \n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!pre_k)  \\<rightarrow> (l!k)\"\n  proof -\n    have \"pre_k \\<ge>i\" using pre_k i_eq_j using a3 k le_Suc_eq by blast  \n    then have \"\\<not>(final (l!pre_k))\" using i_k_not_final pre_k by auto \n    thus ?thesis using suc_not_final_final_c_tran a0 a2 pre_k k by fastforce\n  qed\n  thus ?thesis using pre_k by (metis a2 a3 i_k_not_final k le_Suc_eq not_less_eq)\nqed \n\n\nsubsection {* Basic Sound *}\n\nlemma basic_skip:\n   \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Basic f, s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> c1=Skip\"\nproof -\n  {fix s1 s2 c1\n   assume \"\\<Gamma>\\<turnstile>\\<^sub>c(Basic f,s1)  \\<rightarrow> ((c1,s2))\"     \n   then have \"c1=Skip\" using stepc_elim_cases(3) by blast    \n  } thus ?thesis by auto \nqed  \n\nlemma no_comp_tran_before_i_basic:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Basic f\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"k\\<le>j \\<and> j < i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\" and\n         a4: \"\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))\" and  \n         a5: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc j) \\<in> Normal ` q\"        \n   shows \"P\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Basic f,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  basic_skip by fastforce                  \n  thus ?thesis using  a0 a1 a2 a3 a4 a5 no_comp_tran_before_i by blast\nqed\n\nlemma only_one_component_tran_i_basic:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Basic f\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"k\\<le>j \\<and> j \\<noteq> i \\<and> Suc j < length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> fst (l!j) =  Basic f\" and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc j) \\<in> Normal ` q\"     \n   shows \"P\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Basic f,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  basic_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 a4 only_one_component_tran_i[OF a0 a1 a2 ] by blast\nqed   \n\nlemma only_one_component_tran_basic:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Basic f\" and         \n         a2: \" k\\<le>i \\<and> i \\<noteq> j \\<and>  Suc i<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i))) \\<and> fst (l!i) = Basic f\" and\n         a3: \"k\\<le>j  \\<and> Suc j < length l\" and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                       Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q\"       \n   shows \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Basic f,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  basic_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 a4 only_one_component_tran by blast\nqed   \n\nlemma only_one_component_tran_all_env_basic:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Basic f\" and         \n         a2: \"k\\<le>i \\<and> Suc i<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i))) \\<and> fst (l!i) = Basic f\" and        \n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                       Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q\"\n   shows \"\\<forall>j. k\\<le>j \\<and> j\\<noteq>i \\<and> Suc j < (length l) \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\nproof -\n  have b: \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Basic f,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  basic_skip by blast\n  show ?thesis \n    by (metis (no_types) a0 a1 a2 a3 only_one_component_tran_basic) \nqed   \n\nlemma only_one_component_tran_all_not_comp_basic:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Basic f\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))  \\<and> fst (l!i) = Basic f\" and         \n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                       Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q\"     \n   shows \"\\<forall>j. k\\<le>j \\<and> j\\<noteq>i \\<and> Suc j < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Basic f,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  basic_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 only_one_component_tran_all_not_comp by blast\nqed   \n\nlemma one_component_tran_basic:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!0) = Basic f\" and         \n         a2: \"Suc k<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\" and\n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely\" and\n         a4:\"p \\<subseteq> {s. f s \\<in> q}\"\n           \n  shows \"\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Basic f,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  basic_skip by blast\n  also obtain j where first:\"(Suc j<length l \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))) \\<and> \n                 (\\<forall>k < j. \\<not>((\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))))\"\n    by (metis (no_types) a2 exist_first_comp_tran')\n  moreover then have prg_j:\"fst (l!j) = Basic f\" using a1 a0\n   by (metis cptn_env_same_prog not_step_comp_step_env)\n  moreover have sta_j:\"snd (l!j) \\<in> Normal ` p\"\n  proof -\n    have a0':\"0\\<le>j \\<and> j<(length l)\" using first by auto\n    have a1':\"(\\<forall>k. 0\\<le>k \\<and> k < j \\<longrightarrow> ((\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))))\" \n      using first not_step_comp_step_env a0 by fastforce   \n    thus ?thesis using stability first a3 a1'  a0' by blast \n  qed \n  then have \"snd (l!Suc j) \\<in> Normal ` q\" using a4 first prg_j\n  proof -\n    obtain s where \"snd (l!j) = Normal s \\<and> s\\<in>p\" using sta_j by fastforce\n    moreover then have \"fst(l!Suc j) = Skip \\<and> snd(l!Suc j) = Normal (f s)\" using first\n      by (metis fst_conv prg_j snd_conv stepc_Normal_elim_cases(3) surjective_pairing)\n    ultimately show ?thesis using a4 by fastforce\n  qed\n  then have \"\\<forall>i. 0\\<le>i \\<and> i\\<noteq>j \\<and> Suc i < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\"\n    using only_one_component_tran_all_not_comp_basic[OF a0 a1] first a3 \n          a0 a1 calculation(1) only_one_component_tran1 prg_j by blast \n  moreover then have \"k=j\" using a2 by fastforce\n  ultimately show ?thesis by auto\nqed   \n\nlemma one_component_tran_basic_env:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!0) = Basic f\" and         \n         a2: \"Suc k<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\" and\n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely\" and\n         a4:\"p \\<subseteq> {s. f s \\<in> q}\"           \n  shows \"\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j))\"\nproof - \n  have \"\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> \\<not> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"\n  using one_component_tran_basic[OF a0 a1 a2 a3 a4] by auto\n  thus ?thesis using  a0 \n     by (metis Suc_eq_plus1 cptn_tran_ce_i step_ce_elim_cases)\nqed\n\nlemma final_exist_component_tran_basic:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n          a1: \"fst (l!i) = Basic f\" and               \n          a2: \"env_tran \\<Gamma> q l R\" and\n          a3: \"i\\<le>j \\<and> j < length l \\<and> final (l!j)\" \n  shows \"\\<exists>k. k\\<ge>i \\<and> k<j \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\nproof - \n  show ?thesis using  a0 a1 a2 a3 final_exist_component_tran by blast\nqed   \n\nlemma Basic_sound: \n       \"p \\<subseteq> {s. f s \\<in> q} \\<Longrightarrow>\n      (\\<forall>s t. s\\<in>p \\<and> (t=f s) \\<longrightarrow> (Normal s,Normal t) \\<in> G) \\<Longrightarrow>       \n       Sta p R \\<Longrightarrow>\n       Sta q R \\<Longrightarrow>       \n       \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub>  (Basic f) sat [p, R, G, q,a]\"\nproof -  \n assume\n    a0:\"p \\<subseteq> {s. f s \\<in> q}\" and\n    a1:\"(\\<forall>s t. s\\<in>p \\<and> (t=f s) \\<longrightarrow> (Normal s,Normal t) \\<in> G)\" and\n    a2:\"Sta p R \" and\n    a3:\"Sta q R\" \n{\n    fix s\n    have \"cpn n \\<Gamma> (Basic f) s \\<inter> assum(p, R) F \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cpn n \\<Gamma> (Basic f) s\" and a11:\"c \\<in> assum(p, R) F\"\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have \"c \\<in> comm(G, (q,a)) F\"      \n      proof - \n      {\n       have cp:\"l!0=(Basic f,s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\"\n         using a10 cpn_def c_prod cptn_eq_cptn_mod_set  cptn_mod_same_n\n                cptn_mod_eq_cptn_mod_nest cptn_eq_cptn_mod by fastforce\n       have assum:\"snd(l!0) \\<in> Normal ` (p) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n                   (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n       using a11 c_prod unfolding assum_def by simp\n       have concl:\"(\\<forall>i ns ns'. Suc i<length l \\<longrightarrow> \n               \\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                             \n               (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n       proof -\n       { fix k\n         assume a00:\"Suc k<length l\" and\n                a11:\"\\<Gamma>1\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"                \n         have len_l:\"length l > 0\" using cp using cptn.simps by blast \n         then obtain a l1 where l:\"l=a#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n         have last_l:\"last l = l!(length l-1)\"\n           using last_length [of a l1] l by fastforce\n         have env_tran:\"env_tran \\<Gamma> p l R\" using assum env_tran_def cp by blast\n         then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n           using env_tran env_tran_right_def a2 unfolding env_tran_def by auto\n         then have all_event:\"\\<forall>j. 0\\<le>j \\<and> j \\<noteq> k \\<and> Suc j < length l \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n           using one_component_tran_basic_env[of \\<Gamma> l f k R] a0 a00 a11 a2 a3 assum cp \n                 env_tran_right fst_conv\n           by metis\n         then have before_k_all_evn:\"\\<forall>j. 0\\<le>j \\<and> j < k  \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n               using a00 a11  by fastforce\n         then have k_basic:\"fst(l!k) = Basic f \\<and> snd (l!k) \\<in> Normal ` (p)\" \n           using  cp env_tran_right a2 assum a00 a11  stability[of p R l 0 k k \\<Gamma>]\n           by force\n         have suc_k_skip_q:\"fst(l!Suc k) = Skip \\<and> snd (l!(Suc k)) \\<in> Normal ` q\"\n         proof \n           show suc_skip: \"fst(l!Suc k) = Skip\"\n             using a0 a00 a11  k_basic by (metis basic_skip surjective_pairing) \n         next\n           obtain s' where k_s: \"snd (l!k)=Normal s' \\<and> s' \\<in> (p)\" \n             using a00 a11  k_basic by auto\n           then have \"snd (l!(Suc k)) = Normal (f s')\"          \n             using a00 a11  k_basic stepc_Normal_elim_cases(3)\n             by (metis prod.inject surjective_pairing)          \n           then show \"snd (l!(Suc k)) \\<in> Normal ` q\" using a0 k_s by blast\n         qed\n         obtain s' s'' where \n            ss:\"snd (l!k) = Normal s' \\<and> s' \\<in> (p) \\<and>  \n               snd (l!(Suc k)) = Normal s'' \\<and> s'' \\<in> q\"\n           using suc_k_skip_q k_basic by fastforce         \n         then have \"(snd(l!k), snd(l!(Suc k))) \\<in>  G\"\n           using a0 a1 a2\n           by (metis Pair_inject a11 k_basic prod.exhaust_sel stepc_Normal_elim_cases(3))\n       } thus ?thesis by auto qed\n       have concr:\"(final (last l)  \\<longrightarrow> \n                   snd (last l) \\<notin> Fault ` F  \\<longrightarrow>\n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a)))\"\n       proof-\n       { \n         assume valid:\"final (last l)\"\n         have len_l:\"length l > 0\" using cp using cptn.simps by blast \n         then obtain a l1 where l:\"l=a#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n         have last_l:\"last l = l!(length l-1)\"\n           using last_length [of a l1] l by fastforce\n         have env_tran:\"env_tran \\<Gamma> p l R\" using assum env_tran_def cp by blast\n         then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n           using env_tran env_tran_right_def a2 unfolding env_tran_def by auto\n         have \"\\<exists>k. k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n         proof -             \n           have \"0\\<le> (length l-1)\" using len_l last_l by auto\n           moreover have \"(length l-1) < length l\" using len_l by auto\n           moreover have \"final (l!(length l-1))\" using valid last_l by auto\n           moreover have \"fst (l!0) = Basic f\" using cp by auto\n           ultimately show ?thesis \n             using cp final_exist_component_tran_basic env_tran a2 by blast \n         qed\n         then obtain k where k_comp_tran: \"k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n           by auto\n         moreover then have \"Suc k < length l\" by auto\n         ultimately have all_event:\"\\<forall>j. 0\\<le>j \\<and> j \\<noteq> k \\<and> Suc j < length l \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n            using one_component_tran_basic_env[of \\<Gamma> l f k R] a0  a11 a2 a3 assum cp \n                 env_tran_right fst_conv by metis           \n         then have before_k_all_evn:\"\\<forall>j. 0\\<le>j \\<and> j < k  \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n               using k_comp_tran by fastforce\n         then have k_basic:\"fst(l!k) = Basic f \\<and> snd (l!k) \\<in> Normal ` (p)\" \n           using  cp env_tran_right a2 assum k_comp_tran stability[of p R l 0 k k \\<Gamma>]\n           by force\n         have suc_k_skip_q:\"fst(l!Suc k) = Skip \\<and> snd (l!(Suc k)) \\<in> Normal ` q\"\n         proof \n           show suc_skip: \"fst(l!Suc k) = Skip\"\n             using a0 k_comp_tran k_basic by (metis basic_skip surjective_pairing) \n         next\n           obtain s' where k_s: \"snd (l!k)=Normal s' \\<and> s' \\<in> (p)\" \n             using k_comp_tran k_basic by auto\n           then have \"snd (l!(Suc k)) = Normal (f s')\"          \n             using k_comp_tran k_basic stepc_Normal_elim_cases(3)\n             by (metis prod.inject surjective_pairing)          \n           then show \"snd (l!(Suc k)) \\<in> Normal ` q\" using a0 using k_s by blast\n         qed\n         have after_k_all_evn:\"\\<forall>j. (Suc k)\\<le>j \\<and> Suc j < (length l)  \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n               using all_event k_comp_tran by fastforce                            \n         then have fst_last_skip:\"fst (last l) = Skip \\<and> \n                             snd ((last l)) \\<in> Normal ` q\"\n         using  a2 last_l len_l cp env_tran_right a3 suc_k_skip_q assum k_comp_tran stability [of q R l \"Suc k\" \"((length l) - 1)\" _ \\<Gamma>] \n           by fastforce                 \n       } thus ?thesis by auto qed\n       note res = conjI [OF concl concr]               \n      }              \n      thus ?thesis using c_prod unfolding comm_def by auto qed      \n    } thus ?thesis by auto qed \n  } thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def)\nqed\n\nsubsection {* Spec Sound *}\n\nlemma spec_skip:\n   \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Spec r,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> c1=Skip\"\nproof -\n  {fix s1 s2 c1\n   assume \"\\<Gamma>\\<turnstile>\\<^sub>c(Spec r,s1)  \\<rightarrow> ((c1,s2))\"     \n   then have \"c1=Skip\" using stepc_elim_cases(4) by force    \n  } thus ?thesis by auto \nqed  \n\n\nlemma no_comp_tran_before_i_spec:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Spec r\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"k\\<le>j \\<and> j < i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\" and\n         a4: \"\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))\" and\n         a5: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc j) \\<in> Normal ` q\" \n   shows \"P\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Spec r,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  spec_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 a4 a5 no_comp_tran_before_i by blast\nqed\n\nlemma only_one_component_tran_i_spec:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Spec r\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"k\\<le>j \\<and> j \\<noteq> i \\<and> Suc j < length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> fst (l!j) =  Spec r\" and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc j) \\<in> Normal ` q\"     \n   shows \"P\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Spec r,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  spec_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 a4 only_one_component_tran_i[OF a0 a1 a2 ] by blast\nqed   \n\nlemma only_one_component_tran_spec:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Spec r\" and         \n         a2: \"k\\<le>i  \\<and> i \\<noteq> j \\<and> Suc i<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i))) \\<and> fst (l!i) =  Spec r\" and\n         a3: \"k\\<le>j  \\<and> Suc j < length l\" and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q\"       \n   shows \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Spec r,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  spec_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 a4 only_one_component_tran by blast\nqed   \n\nlemma only_one_component_tran_all_env_spec:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Spec r\" and         \n         a2: \"k\\<le>i \\<and> Suc i<length l \\<and>(\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))  \\<and> fst (l!i) =  Spec r\" and         \n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q\"       \n   shows \"\\<forall>j. k\\<le>j \\<and> j\\<noteq>i \\<and> Suc j < (length l) \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Spec r,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  spec_skip by blast\n  thus ?thesis by (metis (no_types) a0 a1 a2 a3 only_one_component_tran_spec) \nqed   \n\nlemma only_one_component_tran_all_not_comp_spec:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Spec r\" and         \n         a2: \"k\\<le>i \\<and> Suc i<length l \\<and>(\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))  \\<and> fst (l!i) =  Spec r\" and         \n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q\"       \n   shows \"\\<forall>j. k\\<le>j \\<and> j\\<noteq>i \\<and> Suc j < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Spec r,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  spec_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 only_one_component_tran_all_not_comp by blast\nqed   \n\nlemma one_component_tran_spec:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!0) = Spec r\" and         \n         a2: \"Suc k<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\" and\n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely\" and\n         a4:\"p \\<subseteq> {s. (\\<forall>t. (s,t)\\<in>r \\<longrightarrow> t \\<in> q) \\<and> (\\<exists>t. (s,t) \\<in> r)}\"\n           \n  shows \"\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Spec r,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  spec_skip by blast\n  also obtain j where first:\"(Suc j<length l \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!Suc j))) \\<and> \n                 (\\<forall>k < j. \\<not>((\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))))\"\n    by (metis (no_types) a2 exist_first_comp_tran')\n  moreover then have prg_j:\"fst (l!j) = Spec r\" using a1 a0\n   by (metis cptn_env_same_prog not_step_comp_step_env)\n  moreover have sta_j:\"snd (l!j) \\<in> Normal ` p\"\n  proof -\n    have a0':\"0\\<le>j \\<and> j<(length l)\" using first by auto\n    have a1':\"(\\<forall>k. 0\\<le>k \\<and> k < j \\<longrightarrow> ((\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))))\" \n      using first not_step_comp_step_env a0 by fastforce   \n    thus ?thesis using stability first a3 a1'  a0' by blast \n  qed \n  then have \"snd (l!Suc j) \\<in> Normal ` q\" using a4 first prg_j\n  proof -\n    obtain s where s:\"snd (l!j) = Normal s \\<and> s\\<in>p\" using sta_j by fastforce       \n    then have suc_skip: \"fst (l!Suc j) = Skip\"\n      using spec_skip first prg_j a4 by (metis (no_types, lifting) prod.collapse)\n    moreover obtain s' where  \"snd (l!Suc j) = Normal s' \\<and> (s,s')\\<in>r\" \n      proof -\n      { have f1:\"(\\<Gamma>\\<turnstile>\\<^sub>c(fst(l!j),snd(l!j))  \\<rightarrow> (fst(l!Suc j),snd(l!Suc j)))\" using first by auto\n        obtain t where \"snd (l!Suc j) = Normal t\"\n        using step_spec_skip_normal_normal[of \\<Gamma> \"fst(l!j)\" \"snd(l!j)\" \"fst(l!Suc j)\" \"snd(l!Suc j)\" r s] \n         suc_skip prg_j s a4 f1 by blast\n        moreover then have \"(s,t)\\<in>r\" using a4 s prg_j f1 suc_skip stepc_Normal_elim_cases(4)\n          by (metis (no_types, lifting)  stepc_Normal_elim_cases(4) prod.inject xstate.distinct(5) xstate.inject(1))\n        ultimately have \"\\<exists>t. snd (l!Suc j)= Normal t  \\<and> (s,t)\\<in>r\" by auto\n      }\n      then show \"(\\<And>s'. snd (l ! Suc j) = Normal s' \\<and> (s, s') \\<in> r \\<Longrightarrow> thesis) \\<Longrightarrow> thesis\" ..\n    qed             \n    then show ?thesis using a4 sta_j s by auto\n  qed\n  then have \"\\<forall>i. 0\\<le>i \\<and> i\\<noteq>j \\<and> Suc i < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\"\n    using only_one_component_tran_all_not_comp_spec[OF a0 a1] first a3 \n          a0 a1 calculation(1) only_one_component_tran1 prg_j by blast\n  moreover then have \"k=j\" using a2 by fastforce\n  ultimately show ?thesis by auto\nqed   \n\nlemma one_component_tran_spec_env:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!0) = Spec r\" and         \n         a2: \"Suc k<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\" and\n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely\" and\n         a4:\"p \\<subseteq> {s. (\\<forall>t. (s,t)\\<in>r \\<longrightarrow> t \\<in> q) \\<and> (\\<exists>t. (s,t) \\<in> r)}\"           \n  shows \"\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j))\"\nproof - \n  have \"\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> \\<not> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"\n  using one_component_tran_spec[OF a0 a1 a2 a3 a4] by auto\n  thus ?thesis using  a0 \n     by (metis Suc_eq_plus1 cptn_tran_ce_i step_ce_elim_cases)\nqed\n\nlemma final_exist_component_tran_spec:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n          a1: \"fst (l!i) = Spec r\" and               \n          a2: \"env_tran \\<Gamma> q l R \" and\n          a3: \"i\\<le>j \\<and> j < length l \\<and> final (l!j)\" \n  shows \"\\<exists>k. k\\<ge>i \\<and> k<j \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Spec r,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  spec_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 final_exist_component_tran by blast\nqed   \n\nlemma Spec_sound: \n       \"p \\<subseteq> {s. (\\<forall>t. (s,t)\\<in>r \\<longrightarrow> t \\<in> q) \\<and> (\\<exists>t. (s,t) \\<in> r)} \\<Longrightarrow>\n       (\\<forall>s t. s\\<in>p  \\<and> (s,t)\\<in>r \\<longrightarrow> (Normal s, Normal t) \\<in> G) \\<Longrightarrow>       \n       Sta p R \\<Longrightarrow>\n       Sta q R \\<Longrightarrow>    \n       \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub>  (Spec r) sat [p, R, G, q,a]\"\nproof -  \n assume\n    a0:\"p \\<subseteq> {s. (\\<forall>t. (s,t)\\<in>r \\<longrightarrow> t \\<in> q) \\<and> (\\<exists>t. (s,t) \\<in> r)}\" and\n    a1:\"(\\<forall>s t. s\\<in>p  \\<and> (s,t)\\<in>r \\<longrightarrow> (Normal s,Normal t) \\<in> G)\" and\n    a2:\"Sta p R\" and\n    a3:\"Sta q R\" \n{\n    fix s\n    have \"cpn n \\<Gamma> (Spec r) s \\<inter> assum(p, R) F \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cpn n \\<Gamma> (Spec r) s\" and a11:\"c \\<in> assum(p, R) F\"\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have \"c \\<in> comm(G, (q,a)) F\"      \n      proof - \n      {\n       have cp:\"l!0=(Spec r,s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\"\n         using a10 cpn_def c_prod cptn_eq_cptn_mod_set  cptn_mod_same_n\n                cptn_mod_eq_cptn_mod_nest cptn_eq_cptn_mod by fastforce\n       have assum:\"snd(l!0) \\<in> Normal ` (p) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n                   (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n       using a11 c_prod unfolding assum_def by simp\n       have concl:\"(\\<forall>i ns ns'. Suc i<length l \\<longrightarrow> \n               \\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                                       \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n       proof -\n       { fix k\n         assume a00:\"Suc k<length l\" and\n                a11:\"\\<Gamma>1\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"                \n         obtain ck sk csk ssk where tran_pair:\n           \"\\<Gamma>1\\<turnstile>\\<^sub>c (ck,sk)  \\<rightarrow> (csk, ssk) \\<and> (ck = fst (l!k)) \\<and> (sk = snd (l!k)) \\<and> (csk = fst (l!(Suc k))) \\<and> (ssk = snd (l!(Suc k)))\" \n           using a11 by fastforce\n         have len_l:\"length l > 0\" using cp using cptn.simps by blast \n         then obtain a l1 where l:\"l=a#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n         have last_l:\"last l = l!(length l-1)\"\n           using last_length [of a l1] l by fastforce\n         have env_tran:\"env_tran \\<Gamma> p l R\" using assum env_tran_def cp by blast\n         then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n           using env_tran env_tran_right_def unfolding env_tran_def by auto\n         then have all_event:\"\\<forall>j. 0\\<le>j \\<and> j \\<noteq> k \\<and> Suc j < length l \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n           using a00 a11   one_component_tran_spec_env[of \\<Gamma> l r k R] \n                 env_tran_right fst_conv a0 a2 a3 cp len_l assum\n           by fastforce\n         then have before_k_all_evn:\"\\<forall>j. 0\\<le>j \\<and> j < k  \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n               using a00 a11  by fastforce\n         then have k_basic:\"ck = Spec r \\<and> sk \\<in> Normal ` (p)\" \n           using  cp  env_tran_right a2 assum a00 a11 stability[of p R l 0 k k \\<Gamma>] tran_pair\n           by force\n         have suc_skip: \"csk = Skip\"\n            using a0 a00 k_basic tran_pair spec_skip by blast\n         obtain s' where ss:\"sk = Normal s' \\<and> s' \\<in> (p)\" \n           using k_basic by fastforce\n         obtain s'' where suc_k_skip_q:\"ssk = Normal s'' \\<and> (s',s'')\\<in>r \"           \n         proof -                    \n           {from ss  obtain t where \"ssk = Normal t\" \n             using step_spec_skip_normal_normal[of \\<Gamma>1 ck sk csk ssk r s'] \n                   k_basic tran_pair a0 suc_skip\n             by blast                      \n           moreover then have \"(s',t)\\<in>r\" using a0 k_basic ss a11 suc_skip \n             by (metis (no_types, lifting)  stepc_Normal_elim_cases(4) tran_pair prod.inject xstate.distinct(5) xstate.inject(1))            \n           ultimately have \"\\<exists>t. ssk= Normal t  \\<and> (s',t)\\<in>r\" by auto\n           } \n         then show \"(\\<And>s''. ssk = Normal s''  \\<and> (s',s'')\\<in>r\\<Longrightarrow> thesis) \\<Longrightarrow> thesis\" ..\n         qed                                                                        \n         then have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n           using ss a1 tran_pair   by force\n       } thus ?thesis by auto qed\n       have concr:\"(final (last l)  \\<longrightarrow> ((fst (last l) = Skip \\<and> \n                                                  snd (last l) \\<in> Normal ` q)) \\<or>\n                                                  (fst (last l) = Throw \\<and> \n                                                  snd (last l) \\<in> Normal ` (a)))\"\n       proof-\n       { \n         assume valid:\"final (last l)\"\n         have len_l:\"length l > 0\" using cp using cptn.simps by blast \n         then obtain a l1 where l:\"l=a#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n         have last_l:\"last l = l!(length l-1)\"\n           using last_length [of a l1] l by fastforce\n         have env_tran:\"env_tran \\<Gamma> p l R\" using assum env_tran_def cp by blast\n         then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n           using env_tran env_tran_right_def unfolding env_tran_def by auto\n         have \"\\<exists>k. k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n         proof -             \n           have \"0\\<le> (length l-1)\" using len_l last_l by auto\n           moreover have \"(length l-1) < length l\" using len_l by auto\n           moreover have \"final (l!(length l-1))\" using valid last_l by auto\n           moreover have \"fst (l!0) = Spec r\" using cp by auto\n           ultimately show ?thesis \n             using cp final_exist_component_tran_spec env_tran  by blast \n         qed\n         then obtain k  where k_comp_tran: \"k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n           by auto\n         then obtain ck sk csk ssk where tran_pair:\n           \"\\<Gamma>1\\<turnstile>\\<^sub>c (ck,sk)  \\<rightarrow> (csk, ssk) \\<and> (ck = fst (l!k)) \\<and> (sk = snd (l!k)) \\<and> (csk = fst (l!(Suc k))) \\<and> (ssk = snd (l!(Suc k)))\" \n           using cp by fastforce\n         moreover then have \"Suc k < length l\" using k_comp_tran by auto\n         ultimately have all_event:\"\\<forall>j. 0\\<le>j \\<and> j \\<noteq> k \\<and> Suc j < length l \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n           using one_component_tran_spec_env[of \\<Gamma> l r k R] a0  a11 a2 a3 assum cp \n                 env_tran_right fst_conv            \n           by fastforce\n         then have before_k_all_evn:\"\\<forall>j. 0\\<le>j \\<and> j < k  \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n               using k_comp_tran by fastforce\n         then have k_basic:\"ck = Spec r \\<and> sk \\<in> Normal ` (p)\" \n           using cp env_tran_right a2 assum tran_pair k_comp_tran stability[of p R l 0 k k \\<Gamma>] tran_pair\n           by force\n         have suc_skip: \"csk = Skip\"\n            using a0  k_basic tran_pair spec_skip by blast\n         have suc_k_skip_q:\"ssk \\<in> Normal ` q\"           \n         proof -         \n           obtain s' where k_s: \"sk =Normal s' \\<and> s' \\<in> (p)\" \n             using k_basic by auto\n           then obtain t where \"ssk = Normal t\" \n           using step_spec_skip_normal_normal[of \\<Gamma>1 ck sk csk ssk r s'] k_basic tran_pair a0 suc_skip\n           by blast           \n           then obtain t where \"ssk= Normal t\" by fastforce\n           then have \"(s',t)\\<in>r\" using  k_basic k_s a11 suc_skip \n             by (metis (no_types, lifting)  stepc_Normal_elim_cases(4) tran_pair prod.inject xstate.distinct(5) xstate.inject(1))\n           thus \"ssk \\<in> Normal ` q\"  using a0 k_s `ssk = Normal t` by blast \n         qed    \n         have after_k_all_evn:\"\\<forall>j. (Suc k)\\<le>j \\<and> Suc j < (length l)  \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n               using all_event k_comp_tran by fastforce                            \n         then have fst_last_skip:\"fst (last l) = Skip \\<and> \n                             snd ((last l)) \\<in> Normal ` q\"\n         using l tran_pair suc_skip last_l len_l cp \n               env_tran_right a3 suc_k_skip_q \n               assum k_comp_tran stability [of q R l \"Suc k\" \"((length l) - 1)\" _ \\<Gamma>] \n         by (metis One_nat_def Suc_eq_plus1 Suc_leI Suc_mono diff_Suc_1 lessI list.size(4))                  \n       } thus ?thesis by auto qed\n       note res = conjI [OF concl concr]               \n      }              \n      thus ?thesis using c_prod unfolding comm_def by auto qed      \n    } thus ?thesis by auto qed \n  } thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def)\nqed\n\nsubsection {* Await Sound *}\n\nlemma await_skip:\n   \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Await b c,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> c1=Skip \\<or> (c1 = Throw \\<and> (\\<exists>s21. s2 =Normal s21 ))\"\nproof -\n  {fix s1 s2 c1\n   assume \"\\<Gamma>\\<turnstile>\\<^sub>c(Await b c,s1)  \\<rightarrow> ((c1,s2))\"     \n   then have \"c1=Skip \\<or>  (c1 = Throw \\<and> (\\<exists>s21. s2 =Normal s21 ))\" using stepc_elim_cases(8) by blast    \n  } thus ?thesis by auto \nqed  \n\nlemma no_comp_tran_before_i_await:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Await b c\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"k\\<le>j \\<and> j < i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\" and\n         a4: \"\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))\" and\n         a5: \"env_tran_right \\<Gamma> l rely  \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                         Sta q rely \\<and> snd (l!Suc j) \\<in> Normal ` q\"\n   shows \"P\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Await b c,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow>  c1=Skip \\<or> (c1 = Throw \\<and> (\\<exists>s21. s2 =Normal s21 ))\" \n    using  await_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 a4 a5 no_comp_tran_before_i by blast\nqed\n\nlemma only_one_component_tran_i_await:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Await b c\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"k\\<le>j \\<and> j \\<noteq> i \\<and> Suc j < length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> fst (l!j) = Await b c\" and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc j) \\<in> Normal ` q\" \n   shows \"P\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Await b c,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\\<or>(c1 = Throw \\<and> (\\<exists>s21. s2 =Normal s21 ))\" \n    using  await_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 a4 only_one_component_tran_i by blast\nqed   \n\nlemma only_one_component_tran_await:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Await b c\" and         \n         a2: \" k\\<le>i \\<and> i \\<noteq> j \\<and>  Suc i<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i))) \\<and> fst (l!i) = Await b c\" and\n         a3: \"k\\<le>j  \\<and> Suc j < length l\" and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                       Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q\"     \n   shows \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Await b c,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\\<or>(c1 = Throw \\<and> (\\<exists>s21. s2 =Normal s21 ))\" \n    using  await_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 a4 only_one_component_tran by blast\nqed   \n\nlemma only_one_component_tran_all_env_await:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Await b c\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))  \\<and> fst (l!i) = Await b c\" and         \n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                       Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q\"       \n   shows \"\\<forall>j. k\\<le>j \\<and> j\\<noteq>i \\<and> Suc j < (length l) \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\nproof -\n  have  a:\"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Await b c,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\\<or>(c1 = Throw)\" \n    using  await_skip by blast\n  thus ?thesis by (metis (no_types) a0 a1 a2 a3 only_one_component_tran_await)\nqed\n   \n\nlemma only_one_component_tran_all_not_comp_await:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Await b  c\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))  \\<and> fst (l!i) = Await b c\" and         \n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                       Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q\" \n   shows \"\\<forall>j. k\\<le>j \\<and> j\\<noteq>i \\<and> Suc j < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Await b c,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\\<or>(c1 = Throw \\<and> (\\<exists>s21. s2 =Normal s21 ))\" \n    using  await_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 only_one_component_tran_all_not_comp by blast\nqed   \n\nlemma one_component_tran_await:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!0) = Await b c\" and         \n         a2: \"Suc k<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\" and\n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and>\n                                        Sta a rely\" and\n         a4:\"\\<forall>V. \\<Gamma>\\<^sub>\\<not>\\<^sub>a,{}\\<turnstile>\\<^bsub>/F\\<^esub> \n             (p \\<inter> b \\<inter> {V}) c\n             ({s. (Normal V, Normal s) \\<in> G} \\<inter> q),\n             ({s. (Normal V, Normal s) \\<in> G} \\<inter> a)\" and\n         a5:\"snd (last l) \\<notin> Fault ` F\"\n           \n  shows \"(\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))) \\<and>\n         (\\<exists>s s'. fst (l!k) = Await b c \\<and> snd (l!k) \\<in> Normal ` (p) \\<and> snd (l!k) = Normal s \\<and> snd (l!Suc k) = Normal s' \\<and> \n            (snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> q) \\<or> \n             snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> a)))\"\nproof -\n  have  suc_skip:\"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Await b c,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\\<or> (c1=Throw \\<and> (\\<exists>s21. s2 =Normal s21 ))\" \n    using  await_skip by blast\n  also obtain j where first:\"(Suc j<length l \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))) \\<and> \n                 (\\<forall>k < j. \\<not>((\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))))\"\n    by (metis (no_types) a2 exist_first_comp_tran')\n  moreover then have prg_j:\"fst (l!j) = Await b c\" using a1 a0\n   by (metis cptn_env_same_prog not_step_comp_step_env)\n  moreover have sta_j:\"snd (l!j) \\<in> Normal ` p\"\n  proof -\n    have a0':\"0\\<le>j \\<and> j<(length l)\" using first by auto\n    have a1':\"(\\<forall>k. 0\\<le>k \\<and> k < j \\<longrightarrow> ((\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))))\" \n      using first not_step_comp_step_env a0 by fastforce   \n    thus ?thesis using stability first a3 a1'  a0' by blast \n  qed \n  from sta_j obtain s where \n      k_basic:\"fst (l!j) = Await b c \\<and> snd (l!j) = Normal s \\<and>  s \\<in> p \\<and> snd(l!j) \\<in> Normal ` p\" \n      using sta_j prg_j by fastforce\n  then have conc:\"snd (l!Suc j) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> q) \\<or> \n             snd (l!Suc j) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> a)\" \n  proof -    \n    have \"\\<Gamma>\\<^sub>\\<not>\\<^sub>a,{}\\<Turnstile>\\<^bsub>/F\\<^esub> \n                     (p \\<inter> b \\<inter> {s}) c \n                     ({s'. (Normal s, Normal s') \\<in> G} \\<inter> q),\n                     ({s'. (Normal s, Normal s') \\<in> G} \\<inter> a)\"\n      using  a4 hoare_sound by fastforce\n    then have e_auto:\"\\<Gamma>\\<^sub>\\<not>\\<^sub>a\\<Turnstile>\\<^bsub>/F\\<^esub> (p \\<inter> b \\<inter> {s}) c \n                     ({s'. (Normal s, Normal s') \\<in> G} \\<inter> q),\n                     ({s'. (Normal s, Normal s') \\<in> G} \\<inter> a)\" \n      unfolding cvalid_def by auto    \n    have f': \"\\<Gamma>\\<turnstile>\\<^sub>c(fst (l!j), snd(l!j))  \\<rightarrow> (fst(l!(Suc j)), snd(l!(Suc j)))\"      \n      using first by auto\n    have step_await:\"Suc j<length l \\<and> \\<Gamma>\\<turnstile>\\<^sub>c (Await b c,snd(l!j))  \\<rightarrow> (fst(l!(Suc j)), snd(l!(Suc j)))\"\n             using f' k_basic first by fastforce           \n    then have s'_in_bp:\"s\\<in> b \\<and> s \\<in> p\"  using k_basic stepc_Normal_elim_cases(8) by metis\n    then have \"s \\<in> (p \\<inter> b)\"  by fastforce\n    moreover have test:\n      \"\\<exists>t. \\<Gamma>\\<^sub>\\<not>\\<^sub>a\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> t \\<and> \n       ((\\<exists>t'. t =Abrupt t' \\<and> snd(l!Suc j) = Normal t') \\<or>\n       (\\<forall>t'. t \\<noteq> Abrupt t' \\<and> snd(l!Suc j)=t))\"\n    proof -\n      fix t \n      { assume \"fst(l!Suc j) = Skip\"\n        then have step:\"\\<Gamma>\\<turnstile>\\<^sub>c (Await b c,Normal s)  \\<rightarrow> (Skip, snd(l!Suc j))\"\n          using step_await k_basic by fastforce\n        have s'_b:\"s\\<in>b\" using s'_in_bp by fastforce\n        note step = stepc_elim_cases_Await_skip[OF step]\n        have h:\"(s \\<in> b \\<Longrightarrow> \\<Gamma>\\<^sub>\\<not>\\<^sub>a\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> snd(l!Suc j) \\<Longrightarrow> \\<forall>t'. snd(l!Suc j) \\<noteq> Abrupt t' \\<Longrightarrow>\n              \\<Gamma>\\<^sub>\\<not>\\<^sub>a\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> snd(l!Suc j) \\<and> (\\<forall>t'. snd(l!Suc j) \\<noteq> Abrupt t'))\" by auto\n        have ?thesis \n          using step[OF h] by fastforce\n      } note left = this\n      { assume \"fst(l!Suc j)= Throw \\<and> (\\<exists>s1. snd(l!Suc j) = Normal s1)\"\n        then obtain s1 where step:\"fst(l!Suc j)= Throw \\<and> snd(l!Suc j) = Normal s1\"\n          by fastforce\n        then have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (Await b c,Normal s)  \\<rightarrow> (Throw, snd(l!Suc j))\"\n          using step_await k_basic by fastforce\n        have s'_b:\"s\\<in>b\" using s'_in_bp by fastforce\n        note step = stepc_elim_cases_Await_throw[OF step]\n        have h:\"(\\<And>t'. snd(l!Suc j) = Normal t' \\<Longrightarrow> s \\<in> b \\<Longrightarrow> \\<Gamma>\\<^sub>\\<not>\\<^sub>a\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> Abrupt t' \\<Longrightarrow> \n                \\<Gamma>\\<^sub>\\<not>\\<^sub>a\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> Abrupt t' \\<and>  snd(l!Suc j) = Normal t')\"\n        by auto                \n        have ?thesis using step[OF h] by blast \n      } thus ?thesis using suc_skip  left  step_await suc_skip by blast \n    qed\n    then obtain t where e_step:\"\\<Gamma>\\<^sub>\\<not>\\<^sub>a\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> t \\<and> \n             ((\\<exists>t'. t =Abrupt t' \\<and> snd(l!Suc j) = Normal t') \\<or>\n             (\\<forall>t'. t \\<noteq> Abrupt t' \\<and> snd(l!Suc j)=t)) \" by fastforce\n    moreover have \"t \\<notin> Fault ` F\" \n    proof -           \n       {assume a10:\"t \\<in> Fault ` F\"\n       then obtain tf where \"t=Fault tf \\<and> tf\\<in>F\" by fastforce\n       then have \"snd(l!Suc j) = Fault tf \\<and> tf\\<in>F\" using e_step by fastforce\n       also have \"snd(l!Suc j) \\<notin> Fault  ` F\" \n         using last_not_F[of \\<Gamma> l F] a5 a1 step_await a0 by blast\n       ultimately have False by auto\n       } thus ?thesis by auto\n    qed\n    ultimately have t_q_a:\"t \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter>q) \\<union> \n                              Abrupt ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> a)\" \n      using e_auto unfolding valid_def by fastforce\n    thus ?thesis using e_step t_q_a  by blast                                                                       \n  qed       \n  then have \"\\<forall>i. 0\\<le>i \\<and> i\\<noteq>j \\<and> Suc i < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\"\n    using only_one_component_tran_all_not_comp_await[OF a0 a1] first a3 \n          a0 a1 calculation(1) only_one_component_tran1 prg_j by blast \n  moreover then have k:\"k=j\" using a2 by fastforce\n  ultimately have \"(\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))))\" by auto \n  also from conc k k_basic have \n     \"(\\<exists>s s'. fst (l!k) = Await b c \\<and> snd (l!k) \\<in> Normal ` (p) \\<and> snd (l!k) = Normal s \\<and> snd (l!Suc k) = Normal s' \\<and> \n            (snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> q) \\<or> \n             snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> a)))\"\n     by fastforce\n  ultimately show ?thesis by auto\nqed \n\nlemma one_component_tran_await_env:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!0) = Await b c\" and         \n         a2: \"Suc k<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\" and\n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and>\n                                        Sta a rely\" and\n         a4:\"\\<forall>V. \\<Gamma>\\<^sub>\\<not>\\<^sub>a,{}\\<turnstile>\\<^bsub>/F\\<^esub> \n             (p \\<inter> b \\<inter> {V}) c\n             ({s. (Normal V, Normal s) \\<in> G} \\<inter> q),\n             ({s. (Normal V, Normal s) \\<in> G} \\<inter> a)\" and\n         a5:\"snd (last l) \\<notin> Fault ` F\"           \n  shows \"(\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))) \\<and> \n           (\\<exists>s s'. fst (l!k) = Await b c \\<and> snd (l!k) \\<in> Normal ` (p) \\<and> \n                 snd (l!k) = Normal s \\<and> snd (l!Suc k) = Normal s' \\<and> \n                  (snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> q) \\<or> \n                   snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> a)))\"  \nproof - \n  have \"(\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> \\<not> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))) \\<and> \n        (\\<exists>s s'. fst (l!k) = Await b c \\<and> snd (l!k) \\<in> Normal ` (p) \\<and> \n                snd (l!k) = Normal s \\<and> snd (l!Suc k) = Normal s' \\<and> \n                  (snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> q) \\<or> \n                   snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> a)))\"\n  using one_component_tran_await[OF a0 a1 a2 a3 a4 a5] by auto\n  thus ?thesis using  a0\n  by (metis Suc_eq_plus1 cptn_tran_ce_i step_ce_elim_cases)    \nqed\n\nlemma final_exist_component_tran_await:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n          a1: \"fst (l!i) = Await b c\" and               \n          a2: \"env_tran \\<Gamma> q l R \" and\n          a3: \"i\\<le>j \\<and> j < length l \\<and> final (l!j)\" \n  shows \"\\<exists>k. k\\<ge>i \\<and> k<j \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Await b c,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\\<or>(c1 = Throw \\<and> (\\<exists>s21. s2 =Normal s21 ))\" \n    using  await_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 final_exist_component_tran by blast\nqed   \n\ninductive_cases stepc_elim_cases_Await_Fault:\n\"\\<Gamma>\\<turnstile>\\<^sub>c (Await b c, Normal s) \\<rightarrow> (u,Fault f)\"\n\nlemma Await_sound: \n       \"\\<forall>V. \\<Gamma>\\<^sub>\\<not>\\<^sub>a,{}\\<turnstile>\\<^bsub>/F\\<^esub> \n          (p \\<inter> b \\<inter> {V}) e \n          ({s. (Normal V, Normal s) \\<in> G} \\<inter> q),\n          ({s. (Normal V, Normal s) \\<in> G} \\<inter> a) \\<Longrightarrow>     \n       Sta p R \\<Longrightarrow> Sta q R \\<Longrightarrow> Sta a R \\<Longrightarrow>      \n       \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> (Await b e) sat [p, R, G, q,a]\"\nproof -  \n assume\n    a0: \"\\<forall>V. \\<Gamma>\\<^sub>\\<not>\\<^sub>a,{}\\<turnstile>\\<^bsub>/F\\<^esub> \n          (p \\<inter> b \\<inter> {V}) e \n          ({s. (Normal V, Normal s) \\<in> G} \\<inter> q),\n          ({s. (Normal V, Normal s) \\<in> G} \\<inter> a)\" and\n    a2:\"Sta p R\" and\n    a3:\"Sta q R\" and\n    a4:\"Sta a R\" \n{\n    fix s\n    assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"\n    have \"cpn n \\<Gamma> (Await b e) s \\<inter> assum(p, R) F \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cpn n \\<Gamma> (Await b e) s\" and a11:\"c \\<in> assum(p, R) F\"\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have \"c \\<in> comm(G, (q,a)) F\"      \n      proof - \n      {assume last_fault:\"snd (last l) \\<notin> Fault ` F\"\n       have cp:\"l!0=(Await b e,s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\"\n         using a10 cpn_def c_prod cptn_eq_cptn_mod_set  cptn_mod_same_n\n                cptn_mod_eq_cptn_mod_nest cptn_eq_cptn_mod by fastforce\n       have assum:\"snd(l!0) \\<in> Normal ` (p) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n                   (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n       using a11 c_prod unfolding assum_def by simp\n       have concl:\"(\\<forall>i ns ns'. Suc i<length l \\<longrightarrow> \n               \\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                              \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n       proof -\n       { fix k ns ns'\n         assume a00:\"Suc k<length l\" and\n                a11:\"\\<Gamma>1\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"                \n         have len_l:\"length l > 0\" using cp using cptn.simps by blast \n         then obtain a1 l1 where l:\"l=a1#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n         have env_tran:\"env_tran \\<Gamma> p l R\" using assum env_tran_def cp by blast\n         then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n           using env_tran env_tran_right_def unfolding env_tran_def by auto\n         then have all_event:\n              \"(\\<exists>s s'. fst (l!k) = Await b e \\<and> snd (l!k) \\<in> Normal ` (p) \\<and> snd (l!k) = \n                       Normal s \\<and> snd (l!Suc k) = Normal s' \\<and> \n                      (snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> q) \\<or> \n                       snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> a)))\"\n           using a00 a11  one_component_tran_await_env[of \\<Gamma> l b e k R p q a F G] env_tran_right cp len_l\n           using a0 a2 a3 a4 assum fst_conv last_fault by auto                                                                          \n         then obtain s' s'' where ss:\n           \"snd (l!k) = Normal s' \\<and> s' \\<in> (p) \\<and>  snd (l!Suc k) = Normal s'' \n            \\<and> (s'' \\<in> (({s. (Normal s', Normal s) \\<in> G} \\<inter> q)) \\<or> \n               s''\\<in> (({s. (Normal s', Normal s) \\<in> G} \\<inter> a)))\"\n         by fastforce \n         then have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n           using a2  by force\n       } thus ?thesis using c_prod by auto qed  \n       have concr:\"(final (last l)  \\<longrightarrow>                    \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a)))\"\n       proof-\n       { \n         assume valid:\"final (last l)\"         \n         have len_l:\"length l > 0\" using cp using cptn.simps by blast \n         then obtain a1 l1 where l:\"l=a1#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n         have last_l:\"last l = l!(length l-1)\"\n           using last_length [of a1 l1] l by fastforce\n         have env_tran:\"env_tran \\<Gamma> p l R\" using assum env_tran_def cp by blast\n         then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n           using env_tran env_tran_right_def unfolding env_tran_def by auto\n         have \"\\<exists>k. k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n         proof -             \n           have \"0\\<le> (length l-1)\" using len_l last_l by auto\n           moreover have \"(length l-1) < length l\" using len_l by auto\n           moreover have \"final (l!(length l-1))\" using valid last_l by auto\n           moreover have \"fst (l!0) = Await b e\" using cp by auto\n           ultimately show ?thesis \n             using  cp final_exist_component_tran_await env_tran by blast \n         qed\n         then obtain k  where k_comp_tran: \"k\\<ge>0 \\<and> Suc k < length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n           by fastforce\n         then obtain ck sk csk ssk where tran_pair:\n           \"\\<Gamma>1\\<turnstile>\\<^sub>c (ck,sk)  \\<rightarrow> (csk, ssk) \\<and> (ck = fst (l!k)) \\<and> (sk = snd (l!k)) \\<and> (csk = fst (l!(Suc k))) \\<and> (ssk = snd (l!(Suc k)))\" \n           using cp by fastforce         \n         have all_event:\n              \"(\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))) \\<and>\n               (\\<exists>s s'. fst (l!k) = Await b e \\<and> snd (l!k) \\<in> Normal ` (p) \\<and> snd (l!k) = \n                       Normal s \\<and> snd (l!Suc k) = Normal s' \\<and> \n                      (snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> q) \\<or> \n                       snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> a)))\"\n           using  one_component_tran_await_env[of \\<Gamma> l b e k R p q a F G] a0 a11 a2 a3 a4 assum cp \n                  env_tran_right  len_l  fst_conv last_fault k_comp_tran  by fastforce\n         then have before_k_all_evn:\"\\<forall>j. 0\\<le>j \\<and> j < k  \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n               using k_comp_tran by fastforce\n         then obtain s' where k_basic:\"ck = Await b e \\<and> sk \\<in> Normal ` (p) \\<and> sk = Normal s'\" \n           using cp env_tran_right a2 assum tran_pair k_comp_tran stability[of p R l 0 k k \\<Gamma>] tran_pair\n           by force        \n         have \"\\<Gamma>\\<^sub>\\<not>\\<^sub>a,{}\\<Turnstile>\\<^bsub>/F\\<^esub> \n                     (p \\<inter> b \\<inter> {s'}) e \n                     ({s. (Normal s', Normal s) \\<in> G} \\<inter> q),\n                     ({s. (Normal s', Normal s) \\<in> G} \\<inter> a)\"\n           using  a0 hoare_sound k_basic\n             by fastforce\n           then have e_auto:\"\\<Gamma>\\<^sub>\\<not>\\<^sub>a\\<Turnstile>\\<^bsub>/F\\<^esub> (p \\<inter> b \\<inter> {s'}) e \n                     ({s. (Normal s', Normal s) \\<in> G} \\<inter> q),\n                     ({s. (Normal s', Normal s) \\<in> G} \\<inter> a)\" \n             unfolding cvalid_def by auto   \n         have after_k_all_evn:\"\\<forall>j. (Suc k)\\<le>j \\<and> Suc j < (length l)  \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n               using all_event k_comp_tran by fastforce          \n         have suc_skip: \"csk = Skip  \\<or> (csk = Throw \\<and> (\\<exists>s1. ssk = Normal s1))\"\n            using a0  k_basic tran_pair await_skip by blast\n         moreover {\n           assume at:\"csk = Skip\" \n           then have atom_tran:\"\\<Gamma>\\<^sub>\\<not>\\<^sub>a\\<turnstile>\\<langle>e,sk\\<rangle> \\<Rightarrow> ssk\"\n               using k_basic tran_pair k_basic cp stepc_elim_cases_Await_skip\n               by metis\n           have sk_in_normal_pb:\"sk \\<in> Normal ` (p \\<inter> b)\" \n             using k_basic tran_pair at cp stepc_elim_cases_Await_skip\n              by (metis (no_types, lifting) IntI image_iff)                                  \n           then have \"fst (last l) = Skip \\<and> \n                       snd ((last l)) \\<in> Normal ` q\" \n           proof (cases ssk)\n             case (Normal t)                                                  \n             then have \"ssk \\<in> Normal ` q\" \n               using sk_in_normal_pb k_basic e_auto Normal atom_tran unfolding valid_def\n               by blast\n             thus ?thesis\n               using at l tran_pair last_l len_l cp \n                 env_tran_right a3  after_k_all_evn \n                 assum k_comp_tran stability [of q R l \"Suc k\" \"((length l) - 1)\" _ \\<Gamma>]\n               by (metis (no_types, hide_lams) Suc_leI diff_Suc_eq_diff_pred diff_less less_one zero_less_diff)         \n           next\n              case (Abrupt t)\n              thus ?thesis \n               using at k_basic tran_pair k_basic cp stepc_elim_cases_Await_skip\n                 by metis                \n           next\n              case (Fault f1)              \n              then have \"ssk \\<in> Normal ` q \\<or> ssk \\<in> Fault ` F\" \n                using k_basic sk_in_normal_pb e_auto Fault atom_tran unfolding valid_def by auto                          \n              thus ?thesis\n              proof\n                assume \"ssk \\<in> Normal ` q\" thus ?thesis using Fault by auto\n              next\n                assume suck_fault:\"ssk \\<in> Fault ` F\"\n                have \"\\<forall>i<length l. snd (l ! i) \\<notin> Fault ` F\" \n                   using last_not_F[of \\<Gamma> l F] last_fault cp by auto\n                thus ?thesis \n                   using cp tran_pair a11 k_comp_tran suck_fault\n                   by (meson diff_less len_l less_imp_Suc_add less_one less_trans_Suc)                  \n              qed\n           next \n              case (Stuck)             \n              then have \"ssk \\<in> Normal ` q\" \n               using k_basic sk_in_normal_pb e_auto Stuck atom_tran unfolding valid_def\n               by blast\n              thus ?thesis using Stuck by auto                             \n           qed            \n         }\n         moreover {\n           assume at:\"(csk = Throw \\<and> (\\<exists>t. ssk = Normal t))\"\n           then obtain t where ssk_normal:\"ssk=Normal t\" by auto\n           then have atom_tran:\"\\<Gamma>\\<^sub>\\<not>\\<^sub>a\\<turnstile>\\<langle>e,sk\\<rangle> \\<Rightarrow> Abrupt t\"\n               using at k_basic tran_pair k_basic ssk_normal cp stepc_elim_cases_Await_throw xstate.inject(1)\n               by metis                        \n           also have \"sk \\<in> Normal ` (p \\<inter> b)\" \n               using k_basic tran_pair k_basic ssk_normal at cp stepc_elim_cases_Await_throw\n               by (metis (no_types, lifting) IntI imageE image_eqI stepc_elim_cases_Await_throw)               \n           then have \"ssk \\<in> Normal ` a\" \n             using e_auto k_basic ssk_normal atom_tran unfolding valid_def\n             by blast\n           then have \"(fst (last l) = Throw \\<and> snd (last l) \\<in> Normal ` (a))\"\n           using at l tran_pair last_l len_l cp \n               env_tran_right a4  after_k_all_evn\n               assum k_comp_tran stability [of a R l \"Suc k\" \"((length l) - 1)\" _ \\<Gamma>]        \n           by (metis (no_types, hide_lams) Suc_leI diff_Suc_eq_diff_pred diff_less less_one zero_less_diff)                    \n         }\n         ultimately have \"fst (last l) = Skip \\<and> \n                             snd ((last l)) \\<in> Normal ` q \\<or>\n                            (fst (last l) = Throw \\<and> snd (last l) \\<in> Normal ` (a))\"\n         by blast                     \n       } thus ?thesis by auto qed\n       note res = conjI [OF concl concr]               \n      }              \n      thus ?thesis using c_prod unfolding comm_def by auto qed      \n    } thus ?thesis by auto qed \n  } thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def)     \nqed\n\nsubsection {* If sound *}\n\nlemma cptn_assum_induct:\nassumes\n  a0: \"(\\<Gamma>,l) \\<in> (cp \\<Gamma> c s) \\<and> ((\\<Gamma>,l) \\<in> assum(p, R) F)\" and\n  a1: \"k < length l \\<and> l!k=(c1,Normal s') \\<and> s' \\<in> p1\"\nshows \"(\\<Gamma>,drop k l)\\<in> ((cp \\<Gamma> c1 (Normal s')) \\<inter> assum(p1, R) F)\"\nproof -\n  have drop_k_s:\"(drop k l)!0 = (c1,Normal s')\" using a1 by fastforce\n  have p1:\"s' \\<in> p1\" using a1 by auto\n  have k_l:\"k < length l\" using a1 by auto\n  show ?thesis\n  proof\n    show \"(\\<Gamma>, drop k l) \\<in> cp \\<Gamma> c1 (Normal s')\" \n    unfolding cp_def \n    using dropcptn_is_cptn a0 a1 drop_k_s cp_def \n    by fastforce\n  next\n    let ?c= \"(\\<Gamma>,drop k l)\"\n    have l:\"snd((snd ?c!0)) \\<in> Normal ` p1\"\n     using p1 drop_k_s by auto\n    {fix i\n     assume a00:\"Suc i<length (snd ?c)\" \n     assume a11:\"(fst ?c)\\<turnstile>\\<^sub>c((snd ?c)!i)  \\<rightarrow>\\<^sub>e ((snd ?c)!(Suc i))\"\n     have \"(snd((snd ?c)!i), snd((snd ?c)!(Suc i))) \\<in> R \"\n     using a0 unfolding assum_def using a00 a11 by auto\n    } thus \"(\\<Gamma>, drop k l) \\<in> assum (p1, R) F\" \n      using l unfolding assum_def by fastforce  \n  qed  \nqed\n\nlemma cptn_n_assum_induct:\nassumes\n  a0: \"(\\<Gamma>,l) \\<in> (cpn n \\<Gamma> c s) \\<and> ((\\<Gamma>,l) \\<in> assum(p, R) F)\" and\n  a1: \"k < length l \\<and> l!k=(c1,Normal s') \\<and> s' \\<in> p1\"\nshows \"(\\<Gamma>,drop k l)\\<in> ((cpn n \\<Gamma> c1 (Normal s')) \\<inter> assum(p1, R) F)\"\nproof -\n  have drop_k_s:\"(drop k l)!0 = (c1,Normal s')\" using a1 by fastforce\n  have p1:\"s' \\<in> p1\" using a1 by auto\n  have k_l:\"k < length l\" using a1 by auto\n  show ?thesis\n  proof\n    show \"(\\<Gamma>, drop k l) \\<in> cpn n \\<Gamma> c1 (Normal s')\" \n    unfolding cpn_def \n    using dropcptn_is_cptn a0 a1 drop_k_s cpn_def \n    by fastforce\n  next\n    let ?c= \"(\\<Gamma>,drop k l)\"\n    have l:\"snd((snd ?c!0)) \\<in> Normal ` p1\"\n     using p1 drop_k_s by auto\n    {fix i\n     assume a00:\"Suc i<length (snd ?c)\" \n     assume a11:\"(fst ?c)\\<turnstile>\\<^sub>c((snd ?c)!i)  \\<rightarrow>\\<^sub>e ((snd ?c)!(Suc i))\"\n     have \"(snd((snd ?c)!i), snd((snd ?c)!(Suc i))) \\<in> R \"\n     using a0 unfolding assum_def using a00 a11 by auto\n    } thus \"(\\<Gamma>, drop k l) \\<in> assum (p1, R) F\" \n      using l unfolding assum_def by fastforce  \n  qed  \nqed\n\n\n\nlemma cptn_comm_induct:\nassumes\n  a0: \"(\\<Gamma>,l) \\<in> (cp \\<Gamma> c s)\" and\n  a1: \"l1 = drop j l \\<and> (\\<Gamma>, l1)\\<in> comm(G, (q,a)) F\" and\n  a2: \"k \\<ge> j \\<and> j < length l\" \nshows \"snd (last (l)) \\<notin> Fault ` F  \\<longrightarrow> ((Suc k < length l \\<longrightarrow>\n       \\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)) \\<longrightarrow>        \n       (snd(l!k), snd(l!(Suc k))) \\<in> G) \n      \\<and> (final (last (l))  \\<longrightarrow>           \n            ((fst (last (l)) = Skip \\<and> \n              snd (last (l)) \\<in> Normal ` q)) \\<or>\n            (fst (last (l)) = Throw \\<and> \n              snd (last (l)) \\<in> Normal ` (a))))\"\nproof -  \n  have pair_\\<Gamma>l:\"fst (\\<Gamma>,l1) = \\<Gamma> \\<and> snd (\\<Gamma>,l1) = l1\" by fastforce  \n  have a03:\"snd (last (l1)) \\<notin> Fault ` F  \\<longrightarrow>(\\<forall>i.                 \n               Suc i<length (snd (\\<Gamma>, l1)) \\<longrightarrow> \n               fst (\\<Gamma>, l1)\\<turnstile>\\<^sub>c((snd (\\<Gamma>, l1))!i)  \\<rightarrow> ((snd (\\<Gamma>, l1))!(Suc i)) \\<longrightarrow>                                             \n                 (snd((snd (\\<Gamma>, l1))!i), snd((snd (\\<Gamma>, l1))!(Suc i))) \\<in> G) \\<and> \n               (final (last (snd (\\<Gamma>, l1)))  \\<longrightarrow> \n                snd (last (snd (\\<Gamma>, l1))) \\<notin> Fault ` F  \\<longrightarrow>\n                  ((fst (last (snd (\\<Gamma>, l1))) = Skip \\<and> \n                    snd (last (snd (\\<Gamma>, l1))) \\<in> Normal ` q)) \\<or>\n                  (fst (last (snd (\\<Gamma>, l1))) = Throw \\<and> \n                    snd (last (snd (\\<Gamma>, l1))) \\<in> Normal ` (a)))\"\n  using a1 unfolding comm_def by fastforce\n  have last_l:\"last l1 = last l\" using a1 a2 by fastforce\n  show ?thesis  \n  proof -\n  {\n    assume \" snd (last l) \\<notin> Fault ` F\" \n    then have l1_f:\"snd (last l1) \\<notin> Fault ` F\" \n     using a03 a1 a2 by force        \n      { assume \"Suc k < length l\"\n      then have a2: \"k \\<ge> j \\<and> Suc k < length l\" using a2 by auto\n      have \"k \\<le> length l\" using a2 by fastforce\n      then have l1_l:\"(l!k = l1! (k - j) ) \\<and> (l!Suc k = l1!Suc (k - j))\"\n        using a1 a2 by fastforce    \n      have a00:\"Suc (k - j) < length l1\" using a1 a2 by fastforce\n      have \"\\<Gamma>\\<turnstile>\\<^sub>c(l1!(k-j))  \\<rightarrow> (l1!(Suc (k-j))) \\<longrightarrow>         \n        (snd((snd (\\<Gamma>, l1))!(k-j)), snd((snd (\\<Gamma>, l1))!(Suc (k-j)))) \\<in> G\"\n      using  pair_\\<Gamma>l a00 l1_f a03 by presburger\n      then have \" \\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)) \\<longrightarrow> \n        (snd (l ! k), snd (l ! Suc k)) \\<in> G \" \n        using l1_l last_l by auto\n    } then have l_side:\"Suc k < length l \\<longrightarrow>\n    \\<Gamma>\\<turnstile>\\<^sub>c l ! k \\<rightarrow> l ! Suc k \\<longrightarrow>   \n    (snd (l ! k), snd (l ! Suc k)) \\<in> G\" by auto \n    { \n      assume a10:\"final (last (l))\"              \n      then have final_eq: \"final (last (l1))\"\n        using a10 a1 a2 by fastforce\n      also have \"snd (last (l1)) \\<notin> Fault ` F\"\n        using last_l l1_f by fastforce\n      ultimately have \"((fst (last (snd (\\<Gamma>, l1))) = Skip \\<and> \n                        snd (last (snd (\\<Gamma>, l1))) \\<in> Normal ` q)) \\<or>\n                      (fst (last (snd (\\<Gamma>, l1))) = Throw \\<and> \n                        snd (last (snd (\\<Gamma>, l1))) \\<in> Normal ` (a))\"\n        using pair_\\<Gamma>l a03 by presburger\n      then have \"((fst (last (snd (\\<Gamma>, l))) = Skip \\<and> \n              snd (last (snd (\\<Gamma>, l))) \\<in> Normal ` q)) \\<or>\n              (fst (last (snd (\\<Gamma>, l))) = Throw \\<and> \n             snd (last (snd (\\<Gamma>, l))) \\<in> Normal ` (a))\"\n        using final_eq a1 a2 by auto \n     } then have \n      r_side: \n      \"SmallStepCon.final (last l) \\<longrightarrow>     \n      fst (last l) = LanguageCon.com.Skip \\<and> snd (last l) \\<in> Normal ` q \\<or>\n       fst (last l) = LanguageCon.com.Throw \\<and> snd (last l) \\<in> Normal ` a\"\n       by fastforce\n     note res=conjI[OF l_side r_side] \n   } thus ?thesis by auto\n   qed\nqed\n\n\nlemma If_sound: \n      \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [(p \\<inter> b),  R, G, q,a] \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> c1 sat [(p \\<inter> b), R, G, q,a] \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c2 sat [(p \\<inter> (-b)),  R, G, q,a] \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> c2 sat [(p \\<inter> (-b)),  R, G, q,a] \\<Longrightarrow>      \n       Sta p R \\<Longrightarrow> (\\<forall>s. (Normal s, Normal s) \\<in> G)  \\<Longrightarrow> \n       \\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> (Cond b c1 c2) sat [p, R, G, q,a]\"\nproof -  \n assume\n    a0:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b,  R, G, q,a]\" and\n    a1:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c2 sat [p \\<inter> (-b), R, G, q,a]\" and    \n    a2: \"\\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> c1 sat [(p \\<inter> b), R, G, q,a]\" and\n    a3: \"\\<Gamma>,\\<Theta> \\<Turnstile>n:\\<^bsub>/F\\<^esub> c2 sat [(p \\<inter> (-b)), R, G, q,a]\" and\n    a4: \"Sta p R\" and\n    a5: \"(\\<forall>s. (Normal s, Normal s) \\<in> G)\"\n  { \n    fix s\n    assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"\n    then have a3:\"\\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> c2 sat [(p \\<inter> (-b)), R, G, q,a]\" \n      using a3 com_cvalidityn_def by fastforce \n    have a2:\"\\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> c1 sat [(p \\<inter> b), R, G, q,a]\"\n      using a2 all_call com_cvalidityn_def by fastforce \n    have \"cpn n \\<Gamma> (Cond b c1 c2)  s \\<inter> assum(p, R) F \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cpn n \\<Gamma> (Cond b c1 c2) s\" and a11:\"c \\<in> assum(p, R) F\"\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have \"c \\<in> comm(G, (q,a)) F\"      \n      proof - \n      {assume l_f:\"snd (last l) \\<notin> Fault ` F\"  \n       then have cp:\"l!0=((Cond b c1 c2),s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\"\n         using a10 cpn_def c_prod cptn_eq_cptn_mod_set  cptn_mod_same_n\n                cptn_mod_eq_cptn_mod_nest cptn_eq_cptn_mod by fastforce       \n       have \\<Gamma>1:\"(\\<Gamma>, l) = c\" using c_prod cp by blast\n       have assum:\"snd(l!0) \\<in> Normal ` (p) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n                   (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n       using a11 c_prod unfolding assum_def by simp\n       then have env_tran:\"env_tran \\<Gamma> p l R\" using env_tran_def cp by blast\n       then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n         using env_tran env_tran_right_def unfolding env_tran_def by auto\n       have concl:\"(\\<forall>i. Suc i<length l \\<longrightarrow> \n               \\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>               \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n       proof -\n       { fix k ns ns'\n         assume a00:\"Suc k<length l\" and\n                a21:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"                                                                           \n         obtain j where before_k_all_evnt:\"j\\<le>k \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n           using a00 a21 exist_first_comp_tran cp by blast\n         then obtain cj sj csj ssj where pair_j:\"(\\<Gamma>\\<turnstile>\\<^sub>c(cj,sj)  \\<rightarrow> (csj,ssj)) \\<and> cj = fst (l!j) \\<and> sj = snd (l!j) \\<and> csj = fst (l!(Suc j)) \\<and> ssj = snd(l!(Suc j))\"\n           by fastforce                                   \n         have k_basic:\"cj = (Cond b c1 c2) \\<and> sj \\<in> Normal ` (p)\" \n           using pair_j before_k_all_evnt cp env_tran_right a4 assum a00 stability[of p R l 0 j j \\<Gamma>]\n         by force\n         then obtain s' where ss:\"sj = Normal s' \\<and> s'\\<in> (p)\" by auto \n         then have ssj_normal_s:\"ssj = Normal s'\" using before_k_all_evnt k_basic pair_j\n           by (metis prod.collapse snd_conv stepc_Normal_elim_cases(6))          \n         have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n           using ss a2 unfolding Satis_def         \n         proof (cases \"k=j\")   \n           case True          \n             have \"(Normal s', Normal s') \\<in> G\" \n               using a5  by blast\n             thus \"(snd (l ! k), snd (l ! Suc k)) \\<in> G\"\n               using pair_j k_basic True ss ssj_normal_s by auto\n         next\n           case False\n           have j_length:\"Suc j < length l\" using a00 before_k_all_evnt by fastforce \n           have l_suc:\"l!(Suc j) = (csj, Normal s')\" \n             using before_k_all_evnt pair_j  ssj_normal_s\n             by fastforce\n           have l_k:\"j<k\" using  before_k_all_evnt False by fastforce\n           have \"s'\\<in>b \\<or> s'\\<notin>b\" by auto                         \n           thus \"(snd (l ! k), snd (l ! Suc k)) \\<in> G\"\n           proof\n             assume a000:\"s'\\<in>b\"\n             then have cj:\"csj=c1\" using k_basic pair_j ss \n                  by (metis (no_types) fst_conv stepc_Normal_elim_cases(6))\n             moreover have p1:\"s' \\<in> (p \\<inter> b)\" using a000 ss by blast \n             moreover then have \"cpn n \\<Gamma> csj ssj \\<inter> assum((p \\<inter> b), R) F \\<subseteq> comm(G, (q,a)) F\"\n               using a2 com_validityn_def cj by blast             \n             ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n               using l_suc j_length a10 a11 \\<Gamma>1  ssj_normal_s\n                     cptn_assum_induct[of \\<Gamma> l \"(LanguageCon.com.Cond b c1 c2)\" s p R F \"Suc j\" c1 s' \"(p \\<inter> b)\"]\n               by blast                         \n             show ?thesis \n               using l_k drop_comm a00 a21  a10 \\<Gamma>1 l_f  \n               cptn_comm_induct[of \\<Gamma> l \"(LanguageCon.com.Cond b c1 c2)\" s _ \"Suc j\" G q a F k]\n               by fastforce                       \n           next\n             assume a000:\"s'\\<notin>b\"\n              then have cj:\"csj=c2\" using k_basic pair_j ss \n                  by (metis (no_types) fst_conv stepc_Normal_elim_cases(6))\n             moreover have p1:\"s' \\<in> (p \\<inter> (-b))\" using a000 ss by fastforce\n             moreover then have \"cpn n \\<Gamma> csj ssj \\<inter> assum((p \\<inter> (-b)), R) F \\<subseteq> comm(G, (q,a)) F\"\n               using a3 com_validityn_def cj by blast             \n             ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n               using l_suc j_length a10 a11 \\<Gamma>1  ssj_normal_s\n                     cptn_assum_induct[of \\<Gamma> l \"(LanguageCon.com.Cond b c1 c2)\" s p R F \"Suc j\" c2 s' \"(p \\<inter> (-b))\"]\n               by fastforce             \n             show ?thesis \n             using l_k drop_comm a00 a21 a10 \\<Gamma>1 l_f\n             cptn_comm_induct[of \\<Gamma> l \"(LanguageCon.com.Cond b c1 c2)\" s _ \"Suc j\" G q a F k]\n             unfolding Satis_def by fastforce\n           qed\n         qed \n       } thus ?thesis by (simp add: c_prod cp) qed\n       have concr:\"(final (last l)  \\<longrightarrow>                    \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a)))\"\n       proof-\n       { \n         assume valid:\"final (last l)\" \n         assume not_fault:  \"snd (last l) \\<notin> Fault ` F\"                 \n         have \"\\<exists>k. k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final (l!(Suc k))\"\n         proof -             \n           have len_l:\"length l > 0\" using cp using cptn.simps by blast \n           then obtain a1 l1 where l:\"l=a1#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n           have last_l:\"last l = l!(length l-1)\"\n             using last_length [of a1 l1] l by fastforce\n           have final_0:\"\\<not>final(l!0)\" using cp unfolding final_def by auto\n           have \"0\\<le> (length l-1)\" using len_l last_l by auto\n           moreover have \"(length l-1) < length l\" using len_l by auto\n           moreover have \"final (l!(length l-1))\" using valid last_l by auto\n           moreover have \"fst (l!0) = LanguageCon.com.Cond b c1 c2\" using cp by auto\n           ultimately show ?thesis \n             using cp final_exist_component_tran_final env_tran_right final_0  \n             by blast \n         qed\n        then obtain k where a21: \"k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final (l!(Suc k))\"\n           by auto\n        then have a00:\"Suc k<length l\" by fastforce\n        then obtain j where before_k_all_evnt:\"j\\<le>k \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n           using a00 a21 exist_first_comp_tran cp by blast\n       then obtain cj sj csj ssj where pair_j:\"(\\<Gamma>\\<turnstile>\\<^sub>c(cj,sj)  \\<rightarrow> (csj,ssj)) \\<and> cj = fst (l!j) \\<and> sj = snd (l!j) \\<and> csj = fst (l!(Suc j)) \\<and> ssj = snd(l!(Suc j))\"\n         by fastforce\n       have j_length:\"Suc j < length l\" using a00 before_k_all_evnt by fastforce                                 \n       then have k_basic:\"cj = (Cond b c1 c2) \\<and> sj \\<in> Normal ` (p)\" \n         using  pair_j before_k_all_evnt cp env_tran_right a4 assum a00 stability[of p R l 0 j j \\<Gamma>]\n       by fastforce\n       then obtain s' where ss:\"sj = Normal s' \\<and> s'\\<in> (p)\" by auto \n       then have ssj_normal_s:\"ssj = Normal s'\" using before_k_all_evnt k_basic pair_j\n         by (metis prod.collapse snd_conv stepc_Normal_elim_cases(6))       \n       have l_suc:\"l!(Suc j) = (csj, Normal s')\" \n           using before_k_all_evnt pair_j  ssj_normal_s\n           by fastforce\n       have \"s'\\<in>b \\<or> s'\\<notin>b\" by auto \n       then have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a))\"\n       proof\n         assume a000:\"s'\\<in>b\"\n         then have cj:\"csj=c1\" using k_basic pair_j ss \n                  by (metis (no_types) fst_conv stepc_Normal_elim_cases(6))\n         moreover have p1:\"s' \\<in> (p \\<inter> b)\" using a000 ss by blast \n         moreover then have \"cpn n \\<Gamma> csj ssj \\<inter> assum((p \\<inter> b), R) F \\<subseteq> comm(G, (q,a)) F\"\n           using a2 com_validityn_def cj by blast         \n         ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n           using l_suc j_length a10 a11 \\<Gamma>1  ssj_normal_s\n                 cptn_assum_induct[of \\<Gamma> l \"(LanguageCon.com.Cond b c1 c2)\" s p R F \"Suc j\" c1 s' \"(p \\<inter> b)\"]\n           by blast                   \n         thus ?thesis       \n           using j_length drop_comm   a10 \\<Gamma>1  cptn_comm_induct[of \\<Gamma> l \"(LanguageCon.com.Cond b c1 c2)\" s _ \"Suc j\" G q a F \"Suc j\"] valid not_fault \n           by blast\n       next\n         assume a000:\"s'\\<notin>b\"\n         then have cj:\"csj=c2\" using k_basic pair_j ss \n                  by (metis (no_types) fst_conv stepc_Normal_elim_cases(6))\n         moreover have p1:\"s'\\<in>(p \\<inter> (-b))\" using a000 ss by blast \n         moreover then have \"cpn n \\<Gamma> csj ssj \\<inter> assum((p \\<inter> (-b)), R) F \\<subseteq> comm(G, (q,a)) F\"\n           using a3 com_validityn_def cj by blast         \n         ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n           using l_suc j_length a10 a11 \\<Gamma>1  ssj_normal_s\n                 cptn_assum_induct[of \\<Gamma> l \"(LanguageCon.com.Cond b c1 c2)\" s p R F \"Suc j\" c2 s' \"(p \\<inter> (-b))\"]\n           by blast                   \n         thus ?thesis       \n           using j_length drop_comm a10 \\<Gamma>1  cptn_comm_induct[of \\<Gamma> l \"(LanguageCon.com.Cond b c1 c2)\" s _ \"Suc j\" G q a F \"Suc j\"] valid not_fault \n           by blast\n       qed\n       } thus ?thesis using l_f by fastforce qed\n       note res = conjI [OF concl concr]              \n      }             \n      thus ?thesis using c_prod  unfolding comm_def by auto  qed      \n    } thus ?thesis by auto qed \n  } thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def) \nqed\n\n\nlemma Asm_sound:\n   \"(c, p, R, G, q, a) \\<in> \\<Theta> \\<Longrightarrow>    \n    \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\n   \"\nproof -\n  assume\n   a0:\"(c, p, R, G, q, a) \\<in> \\<Theta>\"    \n   { fix s\n     assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p,  R, G, q,a]\"\n     then have \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\" using a0 by auto\n   } thus ?thesis unfolding com_cvalidity_def by auto\nqed\n\nlemma Call_sound: \n      \"f \\<in> dom \\<Gamma> \\<Longrightarrow>      \n       \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> (the (\\<Gamma> f)) sat [p, R, G, q,a] \\<Longrightarrow>         \n       Sta p R \\<Longrightarrow> (\\<forall>s. (Normal s,Normal s) \\<in> G)  \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call f) sat [p, R, G, q,a]\"\nproof -  \n  assume\n    a0:\"f \\<in> dom \\<Gamma>\" and\n    a2:\"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> (the (\\<Gamma> f)) sat [p, R, G, q,a]\" and        \n    a3: \"Sta p R\" and\n    a4: \"(\\<forall>s. (Normal s, Normal s) \\<in> G)\"         \n  obtain bdy where a0:\"\\<Gamma> f = Some bdy\" using a0 by auto\n  { \n    fix s\n    assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p,  R, G, q,a]\"  \n    then have a2:\"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> bdy sat [p, R, G, q,a]\" \n      using a0 a2 com_cvalidity_def by fastforce\n    have \"cp \\<Gamma> (Call f)  s \\<inter> assum(p, R) F \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cp \\<Gamma> (Call f) s\" and a11:\"c \\<in> assum(p, R) F\"\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have \"c \\<in> comm(G, (q,a)) F\"      \n      proof - \n      {assume l_f:\"snd (last l) \\<notin> Fault ` F\"       \n        have cp:\"l!0=((Call f),s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\" using a10 cp_def c_prod by fastforce\n        have \\<Gamma>1:\"(\\<Gamma>, l) = c\" using c_prod cp by blast\n        have assum:\"snd(l!0) \\<in> Normal ` (p) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n                   (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n       using a11 c_prod unfolding assum_def by simp\n       then have env_tran:\"env_tran \\<Gamma> p l R\" using env_tran_def cp by blast\n       then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n         using env_tran env_tran_right_def unfolding env_tran_def by auto\n       have concl:\"(\\<forall>i. Suc i<length l \\<longrightarrow> \n               \\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                              \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n       proof -\n       { fix k ns ns'\n         assume a00:\"Suc k<length l\" and\n                a21:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"                                                      \n         obtain j where before_k_all_evnt:\"j\\<le>k \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n           using a00 a21 exist_first_comp_tran cp by blast\n         then obtain cj sj csj ssj where pair_j:\"(\\<Gamma>\\<turnstile>\\<^sub>c(cj,sj)  \\<rightarrow> (csj,ssj)) \\<and> cj = fst (l!j) \\<and> sj = snd (l!j) \\<and> csj = fst (l!(Suc j)) \\<and> ssj = snd(l!(Suc j))\"\n           by fastforce                                             \n         have k_basic:\"cj = (Call f) \\<and> sj \\<in> Normal ` (p)\" \n           using  pair_j before_k_all_evnt cp env_tran_right a3 assum a00 stability[of p R l 0 j j \\<Gamma>]\n           by force\n         then obtain s' where ss:\"sj = Normal s' \\<and> s'\\<in> (p)\" by auto \n         then have ssj_normal_s:\"ssj = Normal s'\" \n           using before_k_all_evnt k_basic pair_j a0 \n           by (metis not_None_eq snd_conv stepc_Normal_elim_cases(9))                     \n         have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n           using ss a2 \n         proof (cases \"k=j\")   \n           case True                                  \n           have \"(Normal s', Normal s') \\<in> G\" \n             using a4 by fastforce \n           thus \"(snd (l ! k), snd (l ! Suc k)) \\<in> G\"\n             using pair_j k_basic True ss ssj_normal_s by auto\n         next\n           case False   \n           have j_k:\"j<k\" using  before_k_all_evnt False by fastforce                      \n           thus \"(snd (l ! k), snd (l ! Suc k)) \\<in>  G\"\n           proof -\n             have j_length:\"Suc j < length l\" using a00 before_k_all_evnt by fastforce\n             have cj:\"csj=bdy\" using k_basic pair_j ss a0\n               by (metis fst_conv option.distinct(1) option.sel stepc_Normal_elim_cases(9))                \n             moreover have p1:\"s'\\<in>p\" using ss by blast \n             moreover then have \"cp \\<Gamma> csj ssj \\<inter> assum(p, R) F \\<subseteq> comm(G, (q,a)) F\"\n               using a2 com_validity_def cj by blast\n             moreover then have \"l!(Suc j) = (csj, Normal s')\" \n               using before_k_all_evnt pair_j cj ssj_normal_s\n               by fastforce\n             ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n               using  j_length a10 a11 \\<Gamma>1  ssj_normal_s\n                     cptn_assum_induct[of \\<Gamma> l \"Call f\" s p R F \"Suc j\" bdy s' p]\n               by blast                         \n             then show ?thesis \n             using a00 a21 a10 \\<Gamma>1  j_k j_length l_f\n             cptn_comm_induct[of \\<Gamma> l \"Call f\" s _ \"Suc j\" G q a F k ]\n             unfolding Satis_def by fastforce                         \n          qed            \n       qed \n       } thus ?thesis by (simp add: c_prod cp) qed\n       have concr:\"(final (last l)  \\<longrightarrow>                   \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a)))\"\n       proof-\n       { \n         assume valid:\"final (last l)\"                       \n         have \"\\<exists>k. k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final (l!(Suc k))\"\n         proof -             \n           have len_l:\"length l > 0\" using cp using cptn.simps by blast \n           then obtain a1 l1 where l:\"l=a1#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n           have last_l:\"last l = l!(length l-1)\"\n            using last_length [of a1 l1] l by fastforce         \n           have final_0:\"\\<not>final(l!0)\" using cp unfolding final_def by auto\n           have \"0\\<le> (length l-1)\" using len_l last_l by auto\n           moreover have \"(length l-1) < length l\" using len_l by auto\n           moreover have \"final (l!(length l-1))\" using valid last_l by auto\n           moreover have \"fst (l!0) = Call f\" using cp by auto\n           ultimately show ?thesis \n             using  cp final_exist_component_tran_final env_tran_right final_0 \n             by blast \n          qed\n          then obtain k where a21: \"k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final (l!(Suc k))\"\n            by auto\n          then have a00:\"Suc k<length l\" by fastforce\n          then obtain j where before_k_all_evnt:\"j\\<le>k \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n            using a00 a21 exist_first_comp_tran cp by blast\n          then obtain cj sj csj ssj where pair_j:\"(\\<Gamma>\\<turnstile>\\<^sub>c(cj,sj)  \\<rightarrow> (csj,ssj)) \\<and> cj = fst (l!j) \\<and> sj = snd (l!j) \\<and> csj = fst (l!(Suc j)) \\<and> ssj = snd(l!(Suc j))\"\n            by fastforce         \n          have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a))\"\n          proof -\n            have j_length:\"Suc j < length l\" using a00 before_k_all_evnt by fastforce                                 \n            then have k_basic:\"cj = (Call f) \\<and> sj \\<in> Normal ` (p)\" \n              using  pair_j before_k_all_evnt cp env_tran_right a3 assum a00 stability[of p R l 0 j j \\<Gamma>]\n              by force\n            then obtain s' where ss:\"sj = Normal s' \\<and> s'\\<in> (p)\" by auto \n            then have ssj_normal_s:\"ssj = Normal s'\" \n              using before_k_all_evnt k_basic pair_j a0 \n              by (metis not_None_eq snd_conv stepc_Normal_elim_cases(9))\n            have cj:\"csj=bdy\" using k_basic pair_j ss a0\n              by (metis fst_conv option.distinct(1) option.sel stepc_Normal_elim_cases(9))                \n            moreover have p1:\"s'\\<in>p\" using ss by blast \n            moreover then have \"cp \\<Gamma> csj ssj \\<inter> assum(p, R) F \\<subseteq> comm(G, (q,a)) F\"\n              using a2 com_validity_def cj by blast\n            moreover then have \"l!(Suc j) = (csj, Normal s')\" \n              using before_k_all_evnt pair_j cj ssj_normal_s\n              by fastforce\n            ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n              using  j_length a10 a11 \\<Gamma>1  ssj_normal_s\n              cptn_assum_induct[of \\<Gamma> l \"Call f\" s p R F \"Suc j\" bdy s' p]\n              by blast    \n            thus ?thesis       \n              using j_length l_f drop_comm a10 \\<Gamma>1 cptn_comm_induct[of \\<Gamma> l \"Call f\" s _ \"Suc j\" G q a F \"Suc j\"] valid  \n              by blast\n           qed\n         } thus ?thesis by auto \n         qed\n       note res = conjI [OF concl concr]}               \n       thus ?thesis using  c_prod unfolding comm_def by force qed      \n    } thus ?thesis by auto qed \n  } thus ?thesis by (simp add: com_validity_def[of \\<Gamma>] com_cvalidity_def) \nqed\n\n(* fun n_calls_cptn:: \"('s,'p,'f) confs \\<Rightarrow> nat\"\nwhere\n\"n_calls_cptn (\\<Gamma>,[]) = 0\"\n|\"n_calls_cptn (\\<Gamma>,[a0]) = 0\"\n|\"n_calls_cptn (\\<Gamma>,[a0,a1]) = 0\"\n|\"n_calls_cptn (\\<Gamma>,a0#a1#l) = (if (\\<exists>p. redex (fst a0) = Call p \\<and> \n                                      redex (fst a1) = the (\\<Gamma> p)) then\n                                (n_calls_cptn (\\<Gamma>,(a1#l))) + 1\n                              else n_calls_cptn (\\<Gamma>,(a1#l)))\"\n\ndefinition cptns_sat::\"('s,'p,'f) body \\<Rightarrow>  'f set \\<Rightarrow> ('s,'p,'f) com \\<Rightarrow> \n    's set \\<Rightarrow> (('s,'f) tran) set \\<Rightarrow>  (('s,'f) tran) set \\<Rightarrow>  \n    's set \\<Rightarrow>  's set \\<Rightarrow> (('s,'p,'f) confs) set\"\nwhere \n\"cptns_sat \\<Gamma> F Pr p R G q a \\<equiv> \n  {cf. \\<exists>s. cf \\<in> (cp \\<Gamma> Pr s \\<inter> assum(p, R) F) \\<and>\n       (cp \\<Gamma> Pr s \\<inter> assum(p, R) F \\<subseteq> comm(G, (q,a)) F) \n                               }\"\n\ndefinition max_calls_cptn_sat::\"('s,'p,'f) body \\<Rightarrow>  'f set \\<Rightarrow> ('s,'p,'f) com \\<Rightarrow> \n    's set \\<Rightarrow> (('s,'f) tran) set \\<Rightarrow>  (('s,'f) tran) set \\<Rightarrow>  \n    's set \\<Rightarrow>  's set \\<Rightarrow> nat\"\nwhere\n\"max_calls_cptn_sat \\<Gamma> F Pr p R G q a \\<equiv> \n  if (cptns_sat  \\<Gamma> F Pr p R G q a) = {} then 0\n  else\n      (SOME n.\n          (\\<forall>n1 \\<in> (n_calls_cptn ` (cptns_sat  \\<Gamma> F Pr p R G q a)). \n            n1\\<le>n))\n\"\n\ndefinition calls_cptn_spec::\n   \"('s,'p,'f) body \\<Rightarrow> 'f set \\<Rightarrow> ('s, 'p, 'f) sextuple set \\<Rightarrow> nat set\"\nwhere\n\"calls_cptn_spec \\<Gamma> F \\<Theta> \\<equiv> \n  {n. \\<forall>(Pr,p,R,G,q,a)\\<in>\\<Theta>. n \\<in> (n_calls_cptn ` (cptns_sat  \\<Gamma> F (Call Pr) p R G q a)) }\n\"\n\ndefinition max_calls_cptn_spec::\n  \"('s,'p,'f) body \\<Rightarrow>  'f set \\<Rightarrow> ('s, 'p, 'f) sextuple set \\<Rightarrow> nat \"\nwhere\n\"max_calls_cptn_spec \\<Gamma> F \\<Theta> \\<equiv> \n  if (calls_cptn_spec  \\<Gamma> F \\<Theta>) = {} then 0\n  else\n    (SOME n. \n      (\\<forall>n1 \\<in> (calls_cptn_spec  \\<Gamma> F \\<Theta>). \n        n1\\<le>n))\n\"\n\ndefinition max_calls_cptn_spec_sat::\n\"('s,'p,'f) body \\<Rightarrow>  'f set \\<Rightarrow> ('s, 'p, 'f) sextuple set \\<Rightarrow>\n ('s,'p,'f) com \\<Rightarrow> \n    's set \\<Rightarrow> (('s,'f) tran) set \\<Rightarrow>  (('s,'f) tran) set \\<Rightarrow>  \n    's set \\<Rightarrow>  's set \\<Rightarrow> nat\"\nwhere\n\"max_calls_cptn_spec_sat  \\<Gamma> F \\<Theta>  Pr p R G q a \\<equiv>\n    if (max_calls_cptn_sat \\<Gamma> F Pr p R G q a) \\<ge> (max_calls_cptn_spec \\<Gamma> F \\<Theta>) then\n       (max_calls_cptn_sat \\<Gamma> F Pr p R G q a)\n    else (max_calls_cptn_spec \\<Gamma> F \\<Theta>)\n\" *)\n\n\n(* lemma CallRec_sound1:\n    \"(c, p, R, G, q, a) \\<in> Specs \\<Longrightarrow>\n     \\<forall>(c, p, R, G, q, a)\\<in>Specs.\n       c \\<in> dom \\<Gamma> \\<and>\n       Sta p R \\<and>  (\\<forall>s. (Normal s,Normal s) \\<in> G) \\<and> Norm R \\<and>      \n       \\<Gamma>,\\<Theta> \\<union> Specs \\<turnstile>\\<^bsub>/F\\<^esub> the (\\<Gamma> c) sat [p, R, G, q,a] \\<and> \n       \\<Gamma>,\\<Theta> \\<union> Specs \\<Turnstile>\\<^bsub>/F\\<^esub> the (\\<Gamma> c) sat [p,R, G, q,a] \\<Longrightarrow>\n    Sta p R \\<Longrightarrow> (\\<forall>s. (Normal s,Normal s) \\<in> G) \\<Longrightarrow>\n     \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> Call c sat [p,R, G, q,a]\"\nproof -\n  assume a0: \"(c, p, R, G, q, a) \\<in> Specs\" and\n     a1: \n    \"\\<forall>(c, p, R, G, q, a)\\<in>Specs.\n       c \\<in> dom \\<Gamma> \\<and> Sta p R \\<and>  (\\<forall>s. (Normal s,Normal s) \\<in> G) \\<and> Norm R \\<and>  \n       \\<Gamma>,\\<Theta> \\<union> Specs \\<turnstile>\\<^bsub>/F\\<^esub> the (\\<Gamma> c) sat [p, R, G, q,a] \\<and> \n       \\<Gamma>,\\<Theta> \\<union> Specs \\<Turnstile>\\<^bsub>/F\\<^esub> the (\\<Gamma> c) sat [p,R, G, q,a]\"\n  then have a1': \"c \\<in> dom \\<Gamma>\"  and       \n       a1'': \"\\<Gamma>,\\<Theta> \\<union> Specs \\<Turnstile>\\<^bsub>/F\\<^esub> the (\\<Gamma> c) sat [p,R, G, q,a]\" using a0 by auto \n    from a1 have \n      valid_body:\n      \"\\<forall>(c, p, R, G, q, a)\\<in>Specs.\n       c \\<in> dom \\<Gamma> \\<and>  Sta p R \\<and>  (\\<forall>s. (Normal s,Normal s) \\<in> G) \\<and> Norm R \\<and>       \n       \\<Gamma>,\\<Theta> \\<union> Specs \\<Turnstile>\\<^bsub>/F\\<^esub> the (\\<Gamma> c) sat [p,R, G, q,a]\" by fastforce\n  assume a5: \"Sta p R\" and\n         a6: \"(\\<forall>s. (Normal s,Normal s) \\<in> G)\" and\n         a7: \"Norm R\"  \n  obtain bdy where \\<Gamma>bdy:\"\\<Gamma> c = Some bdy\" using a1' by auto\n  have theta_specs: \n         \"\\<forall>(c, p, R, G, q, a)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> Call c sat [p,R, G, q,a] \\<Longrightarrow>\n          \\<forall>(c, p, R, G, q, a)\\<in>Specs. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> Call c sat [p,R, G, q,a]\"\n  proof -\n    assume a00:\"\\<forall>(c, p, R, G, q, a)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> Call c sat [p,R, G, q,a]\"\n    { \n       fix c1 p1 R1 G1 q1 a1\n       assume a001:\"(c1, p1, R1, G1, q1, a1)\\<in>Specs\"       \n       then have \"c1 \\<in> dom \\<Gamma> \\<and> Sta p1 R1 \\<and>  (\\<forall>s. (Normal s,Normal s) \\<in> G1) \\<and> Norm R1 \\<and>  \n          \\<Gamma>,\\<Theta> \\<union> Specs \\<Turnstile>\\<^bsub>/F\\<^esub> the (\\<Gamma> c1) sat [p1,R1, G1, q1,a1]\" \n         using valid_body by fastforce\n       then have \"\\<Gamma>,\\<Theta> \\<union> Specs \\<Turnstile>\\<^bsub>/F\\<^esub> Call c1 sat [p1,R1, G1, q1,a1]\"\n         using Call_sound[of c1 \\<Gamma> \"\\<Theta> \\<union> Specs\" F p1 R1 G1 q1 a1] a5 a6 a7\n         by fastforce\n       {\n          fix s\n          have \"cp \\<Gamma> (LanguageCon.com.Call c1) s \\<inter> assum (p1, R1) F \\<subseteq> comm (G1, q1, a1) F\"\n          proof -\n          { \n            fix c\n            assume a10:\"c \\<in> cp \\<Gamma> (Call c1) s\" and a11:\"c\\<in> assum(p1,R1) F\"\n            obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n            obtain n where h:\"n_calls_cptn (\\<Gamma>1,l) = n\" by auto\n            then have \"c \\<in> comm(G1, (q1,a1)) F\" using a10 a11 \n            proof (induct n arbitrary: l s p1 c)\n              case 0 thus ?case sorry\n            next\n              case (Suc n) thus ?case sorry\n            qed\n          } thus ?thesis by auto qed\n       }  \n       then have \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> Call c1 sat [p1,R1, G1, q1,a1]\"\n         unfolding com_validity_def by auto\n          \n    } thus ?thesis by auto\n  qed\n  then show ?thesis using a0 unfolding com_cvalidity_def by auto     \nqed *)\n\n\n(* lemma CallRec_sound:\n    \"(c, p, R, G, q, a) \\<in> Specs \\<Longrightarrow>\n     \\<forall>(c, p, R, G, q, a)\\<in>Specs.\n       c \\<in> dom \\<Gamma> \\<and>\n       Sta p R \\<and>  (\\<forall>s. (Normal s,Normal s) \\<in> G) \\<and> Norm R \\<and>      \n       \\<Gamma>,\\<Theta> \\<union> Specs \\<turnstile>\\<^bsub>/F\\<^esub> the (\\<Gamma> c) sat [p, R, G, q,a] \\<and> \n       \\<Gamma>,\\<Theta> \\<union> Specs \\<Turnstile>\\<^bsub>/F\\<^esub> the (\\<Gamma> c) sat [p,R, G, q,a] \\<Longrightarrow>\n    Sta p R \\<Longrightarrow> (\\<forall>s. (Normal s,Normal s) \\<in> G)  \\<Longrightarrow>\n     \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> Call c sat [p,R, G, q,a]\"\nproof -\n  assume a0: \"(c, p, R, G, q, a) \\<in> Specs\" and\n     a1: \n    \"\\<forall>(c, p, R, G, q, a)\\<in>Specs.\n       c \\<in> dom \\<Gamma> \\<and> Sta p R \\<and>  (\\<forall>s. (Normal s,Normal s) \\<in> G) \\<and> Norm R \\<and>  \n       \\<Gamma>,\\<Theta> \\<union> Specs \\<turnstile>\\<^bsub>/F\\<^esub> the (\\<Gamma> c) sat [p, R, G, q,a] \\<and> \n       \\<Gamma>,\\<Theta> \\<union> Specs \\<Turnstile>\\<^bsub>/F\\<^esub> the (\\<Gamma> c) sat [p,R, G, q,a]\"\n  then have a1': \"c \\<in> dom \\<Gamma>\"  and       \n       a1'': \"\\<Gamma>,\\<Theta> \\<union> Specs \\<Turnstile>\\<^bsub>/F\\<^esub> the (\\<Gamma> c) sat [p,R, G, q,a]\" using a0 by auto \n    from a1 have \n      valid_body:\n      \"\\<forall>(c, p, R, G, q, a)\\<in>Specs.\n       c \\<in> dom \\<Gamma> \\<and>  Sta p R \\<and>  (\\<forall>s. (Normal s,Normal s) \\<in> G) \\<and> Norm R \\<and>       \n       \\<Gamma>,\\<Theta> \\<union> Specs \\<Turnstile>\\<^bsub>/F\\<^esub> the (\\<Gamma> c) sat [p,R, G, q,a]\" by fastforce\n  assume a5: \"Sta p R\" and\n         a6: \"(\\<forall>s. (Normal s,Normal s) \\<in> G)\"           \n  obtain bdy where \\<Gamma>bdy:\"\\<Gamma> c = Some bdy\" using a1' by auto\n  have theta_specs: \n         \"\\<forall>(c, p, R, G, q, a)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> Call c sat [p,R, G, q,a] \\<Longrightarrow>\n          \\<forall>(c, p, R, G, q, a)\\<in>Specs. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> Call c sat [p,R, G, q,a]\"\n  proof -\n    assume a00:\"\\<forall>(c, p, R, G, q, a)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> Call c sat [p,R, G, q,a]\"\n    { \n       fix c1 p1 R1 G1 q1 a1\n       assume \"(c1, p1, R1, G1, q1, a1)\\<in>Specs\"\n       then have \"c1 \\<in> dom \\<Gamma> \\<and> Sta p1 R1 \\<and>  (\\<forall>s. (Normal s,Normal s) \\<in> G1) \\<and> Norm R1 \\<and>  \n          \\<Gamma>,\\<Theta> \\<union> Specs \\<Turnstile>\\<^bsub>/F\\<^esub> the (\\<Gamma> c1) sat [p1,R1, G1, q1,a1]\" \n         using valid_body by fastforce\n       then have \"\\<Gamma>,\\<Theta> \\<union> Specs \\<Turnstile>\\<^bsub>/F\\<^esub> Call c1 sat [p1,R1, G1, q1,a1]\"\n         using Call_sound[of c1 \\<Gamma> \"\\<Theta> \\<union> Specs\" F p1 R1 G1 q1 a1] a5 a6 \n         by fastforce       \n       then have \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> Call c1 sat [p1,R1, G1, q1,a1]\" \n         unfolding com_cvalidity_def using a00\n            sorry\n    } thus ?thesis by auto\n  qed\n  then show ?thesis using a0 unfolding com_cvalidity_def by auto     \nqed*)\n\n\n\n\nlemma Seq_env_P:assumes a0:\"\\<Gamma>\\<turnstile>\\<^sub>c(Seq P Q,s) \\<rightarrow>\\<^sub>e (Seq P Q,t)\"\n      shows \"\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow>\\<^sub>e (P,t)\"\nusing a0\nby (metis env_not_normal_s snormal_enviroment)\n\nlemma map_eq_state:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Seq c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \" and\n  a2:\"l1=map (lift c2) l2\"\nshows\n  \"\\<forall>i<length l1. snd (l1!i) = snd (l2!i)\"\nusing a0 a1 a2 unfolding cp_def\nby (simp add: snd_lift) \n\nlemma map_eq_seq_c:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Seq c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \" and\n  a2:\"l1=map (lift c2) l2\"\nshows\n  \"\\<forall>i<length l1. fst (l1!i) = Seq (fst (l2!i)) c2\"\nproof -\n  {fix i\n  assume a3:\"i<length l1\"\n  have \"fst (l1!i) = Seq (fst (l2!i)) c2\"\n  using a0 a1 a2 a3 unfolding lift_def\n    by (simp add: case_prod_unfold) \n  }thus ?thesis by auto\nqed \n\nlemma same_env_seq_c:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Seq c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \" and\n  a2:\"l1=map (lift c2) l2\"\nshows\n\"\\<forall>i. Suc i<length l2 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow>\\<^sub>e (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow>\\<^sub>e (l1!(Suc i))\" \nproof -\n  have a0a:\"(\\<Gamma>,l1) \\<in>cptn \\<and> l1!0 = ((Seq c1 c2),s)\" \n    using a0 unfolding cp_def by blast\n  have a1a: \"(\\<Gamma>,l2) \\<in>cptn \\<and> l2!0 = (c1,s)\"\n    using a1 unfolding cp_def by blast\n  {\n    fix i\n    assume a3:\"Suc i< length l2\"\n    have \"\\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow>\\<^sub>e (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow>\\<^sub>e (l1!(Suc i))\"\n    proof\n    {\n      assume a4:\"\\<Gamma>\\<turnstile>\\<^sub>c l2 ! i \\<rightarrow>\\<^sub>e l2 ! Suc i\"\n      obtain c1i s1i c1si s1si where l1prod:\"l1 ! i=(c1i,s1i) \\<and> l1!Suc i = (c1si,s1si)\"\n        by fastforce\n      obtain c2i s2i c2si s2si where l2prod:\"l2 ! i=(c2i,s2i) \\<and> l2!Suc i = (c2si,s2si)\"\n        by fastforce\n      then have \"c1i = (Seq c2i c2) \\<and> c1si = (Seq c2si c2)\"\n        using  a0 a1 a2 a3 a4  map_eq_seq_c l1prod\n        by (metis Suc_lessD  fst_conv length_map)\n      also have \"s2i=s1i \\<and> s2si=s1si\"\n        using  a0 a1 a4  a2 a3 l2prod map_eq_state l1prod\n        by (metis Suc_lessD  nth_map snd_conv snd_lift)        \n      ultimately show \"\\<Gamma>\\<turnstile>\\<^sub>c l1 ! i \\<rightarrow>\\<^sub>e (l1 ! Suc i)\" \n        using a4 l1prod l2prod\n        by (metis Env_n env_c_c' env_not_normal_s step_e.Env)\n    } \n    {\n      assume a4:\"\\<Gamma>\\<turnstile>\\<^sub>c l1 ! i \\<rightarrow>\\<^sub>e l1 ! Suc i\"\n      obtain c1i s1i c1si s1si where l1prod:\"l1 ! i=(c1i,s1i) \\<and> l1!Suc i = (c1si,s1si)\"\n        by fastforce\n      obtain c2i s2i c2si s2si where l2prod:\"l2 ! i=(c2i,s2i) \\<and> l2!Suc i = (c2si,s2si)\"\n        by fastforce\n      then have \"c1i = (Seq c2i c2) \\<and> c1si = (Seq c2si c2)\"\n        using  a0 a1 a2 a3 a4  map_eq_seq_c l1prod\n        by (metis Suc_lessD  fst_conv length_map)\n      also have \"s2i=s1i \\<and> s2si=s1si\"\n        using  a0 a1 a4  a2 a3 l2prod map_eq_state l1prod\n        by (metis Suc_lessD  nth_map snd_conv snd_lift)        \n      ultimately show \"\\<Gamma>\\<turnstile>\\<^sub>c l2 ! i \\<rightarrow>\\<^sub>e (l2 ! Suc i)\" \n        using a4 l1prod l2prod        \n        by (metis Env_n LanguageCon.com.inject(3) env_c_c' env_not_normal_s step_e.Env)   \n    }\n    qed\n   } \n  thus ?thesis by auto\nqed\n\n\n\nlemma same_comp_seq_c:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Seq c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \" and\n  a2:\"l1=map (lift c2) l2\"\nshows\n\"\\<forall>i. Suc i<length l2 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow> (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow> (l1!(Suc i))\" \nproof -\n  have a0a:\"(\\<Gamma>,l1) \\<in>cptn \\<and> l1!0 = ((Seq c1 c2),s)\" \n    using a0 unfolding cp_def by blast\n  have a1a: \"(\\<Gamma>,l2) \\<in>cptn \\<and> l2!0 = (c1,s)\"\n    using a1 unfolding cp_def by blast\n  {\n    fix i\n    assume a3:\"Suc i< length l2\"\n    have \"\\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow> (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow> (l1!(Suc i))\"\n    proof\n    {\n      assume a4:\"\\<Gamma>\\<turnstile>\\<^sub>c l2 ! i \\<rightarrow> l2 ! Suc i\"\n      obtain c1i s1i c1si s1si where l1prod:\"l1 ! i=(c1i,s1i) \\<and> l1!Suc i = (c1si,s1si)\"\n        by fastforce\n      obtain c2i s2i c2si s2si where l2prod:\"l2 ! i=(c2i,s2i) \\<and> l2!Suc i = (c2si,s2si)\"\n        by fastforce\n      then have \"c1i = (Seq c2i c2) \\<and> c1si = (Seq c2si c2)\"\n        using  a0 a1 a2 a3 a4  map_eq_seq_c l1prod\n        by (metis Suc_lessD  fst_conv length_map)\n      also have \"s2i=s1i \\<and> s2si=s1si\"\n        using  a0 a1 a4  a2 a3 l2prod map_eq_state l1prod\n        by (metis Suc_lessD  nth_map snd_conv snd_lift)        \n      ultimately show \"\\<Gamma>\\<turnstile>\\<^sub>c l1 ! i \\<rightarrow> (l1 ! Suc i)\" \n        using a4 l1prod l2prod\n        by (simp add: Seqc)        \n    } \n    {\n      assume a4:\"\\<Gamma>\\<turnstile>\\<^sub>c l1 ! i \\<rightarrow> l1 ! Suc i\"\n      obtain c1i s1i c1si s1si where l1prod:\"l1 ! i=(c1i,s1i) \\<and> l1!Suc i = (c1si,s1si)\"\n        by fastforce\n      obtain c2i s2i c2si s2si where l2prod:\"l2 ! i=(c2i,s2i) \\<and> l2!Suc i = (c2si,s2si)\"\n        by fastforce\n      then have \"c1i = (Seq c2i c2) \\<and> c1si = (Seq c2si c2)\"\n        using  a0 a1 a2 a3 a4  map_eq_seq_c l1prod\n        by (metis Suc_lessD  fst_conv length_map)\n      also have \"s2i=s1i \\<and> s2si=s1si\"\n        using  a0 a1 a4  a2 a3 l2prod map_eq_state l1prod\n        by (metis Suc_lessD  nth_map snd_conv snd_lift)        \n      ultimately show \"\\<Gamma>\\<turnstile>\\<^sub>c l2 ! i \\<rightarrow> (l2 ! Suc i)\" \n        using a4 l1prod l2prod stepc_elim_cases_Seq_Seq\n      by auto           \n    }\n    qed\n   } \n  thus ?thesis by auto\nqed\n\nlemma assum_map:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Seq c1 c2) s) \\<and> ((\\<Gamma>,l1) \\<in> assum(p, R) F)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \" and\n  a2:\"l1=map (lift c2) l2\"  \nshows\n  \"((\\<Gamma>,l2) \\<in> assum(p, R) F)\"\nproof -\n  have a3: \"\\<forall>i. Suc i<length l2 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow>\\<^sub>e (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow>\\<^sub>e (l1!(Suc i))\" \n    using a0 a1 a2 same_env_seq_c by fastforce\n  have pair_\\<Gamma>l1:\"fst (\\<Gamma>,l1) = \\<Gamma> \\<and> snd (\\<Gamma>,l1) = l1\" by fastforce\n  have pair_\\<Gamma>l2:\"fst (\\<Gamma>,l2) = \\<Gamma> \\<and> snd (\\<Gamma>,l2) = l2\" by fastforce\n  have drop_k_s:\"l2!0 = (c1,s)\" using a1 cp_def by blast\n  have eq_length:\"length l1 = length l2\" using a2 by auto\n  obtain s' where normal_s:\"s = Normal s'\" \n    using  a0  unfolding cp_def   assum_def  by fastforce\n  then have p1:\"s'\\<in>p\" using a0 unfolding cp_def assum_def by fastforce  \n  show ?thesis \n  proof -    \n    let ?c= \"(\\<Gamma>,l2)\"\n    have l:\"snd((snd ?c!0)) \\<in> Normal ` (p)\"\n     using p1 drop_k_s a1 normal_s unfolding cp_def by auto\n    {fix i\n     assume a00:\"Suc i<length (snd ?c)\" \n     assume a11:\"(fst ?c)\\<turnstile>\\<^sub>c((snd ?c)!i)  \\<rightarrow>\\<^sub>e ((snd ?c)!(Suc i))\"\n     have \"(snd((snd ?c)!i), snd((snd ?c)!(Suc i))) \\<in> R\"\n     using a0 a1 a2 a3 map_eq_state unfolding assum_def \n     using a00 a11 eq_length by fastforce\n    } thus \"(\\<Gamma>, l2) \\<in> assum (p, R) F\" \n      using l unfolding assum_def by fastforce  \n  qed  \nqed\n\nlemma comm_map':\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Seq c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \\<and> (\\<Gamma>, l2)\\<in> comm(G, (q,a)) F\" and\n  a2:\"l1=map (lift c2) l2\" \nshows\n  \"snd (last l1) \\<notin> Fault ` F  \\<longrightarrow>(Suc k < length l1 \\<longrightarrow>\n       \\<Gamma>\\<turnstile>\\<^sub>c(l1!k)  \\<rightarrow> (l1!(Suc k)) \\<longrightarrow> \n       (snd(l1!k), snd(l1!(Suc k))) \\<in>  G) \\<and> \n   (fst (last l1) = (Seq c c2) \\<and> final (c, snd (last l1)) \\<longrightarrow>     \n      (fst (last l1) = (Seq Skip c2) \\<and> \n        (snd (last  l1) \\<in> Normal ` q) \\<or>\n      (fst (last l1) = (Seq Throw c2) \\<and> \n        snd (last l1) \\<in> Normal ` (a))))\n     \"\nproof -\n  have a3:\"\\<forall>i. Suc i<length l2 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow> (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow> (l1!(Suc i))\" \n    using a0 a1 a2 same_comp_seq_c\n    by fastforce\n  have pair_\\<Gamma>l1:\"fst (\\<Gamma>,l1) = \\<Gamma> \\<and> snd (\\<Gamma>,l1) = l1\" by fastforce\n  have pair_\\<Gamma>l2:\"fst (\\<Gamma>,l2) = \\<Gamma> \\<and> snd (\\<Gamma>,l2) = l2\" by fastforce\n  have drop_k_s:\"l2!0 = (c1,s)\" using a1 cp_def by blast\n  have eq_length:\"length l1 = length l2\" using a2 by auto \n  then have len0:\"length l1>0\" using a0 unfolding cp_def \n    using Collect_case_prodD drop_k_s eq_length by auto\n  then have l1_not_empty:\"l1\\<noteq>[]\" by auto\n  then have l2_not_empty:\"l2 \\<noteq> []\" using a2 by blast       \n   have last_lenl1:\"last l1 = l1!((length l1) -1)\" \n        using last_conv_nth l1_not_empty by auto\n  have last_lenl2:\"last l2 = l2!((length l2) -1)\" \n       using last_conv_nth l2_not_empty by auto \n  have a03:\"snd (last l2) \\<notin> Fault ` F  \\<longrightarrow>(\\<forall>i ns ns'.                 \n               Suc i<length (snd (\\<Gamma>, l2)) \\<longrightarrow> \n               fst (\\<Gamma>, l2)\\<turnstile>\\<^sub>c((snd (\\<Gamma>, l2))!i)  \\<rightarrow> ((snd (\\<Gamma>, l2))!(Suc i)) \\<longrightarrow>                               \n                 (snd((snd (\\<Gamma>, l2))!i), snd((snd (\\<Gamma>, l2))!(Suc i))) \\<in> G) \\<and> \n               (final (last (snd (\\<Gamma>, l2)))  \\<longrightarrow>                 \n                  ((fst (last (snd (\\<Gamma>, l2))) = Skip \\<and> \n                    snd (last (snd (\\<Gamma>, l2))) \\<in> Normal ` q)) \\<or>\n                  (fst (last (snd (\\<Gamma>, l2))) = Throw \\<and> \n                    snd (last (snd (\\<Gamma>, l2))) \\<in> Normal ` (a)))\"\n  using a1 unfolding comm_def by fastforce\n  show ?thesis unfolding comm_def \n  proof -\n  { fix k ns ns'\n    assume a00a:\"snd (last l1) \\<notin> Fault ` F\"\n    assume a00:\"Suc k < length l1\"    \n    then have \"k \\<le> length l1\" using a2 by fastforce    \n    have a00:\"Suc k < length l2\" using eq_length a00 by fastforce\n    then have a00a:\"snd (last l2) \\<notin> Fault ` F\"\n    proof-\n      have \"snd (l1!((length l1) -1)) = snd (l2!((length l2) -1))\"      \n        using a2 a1 a0  map_eq_state eq_length l2_not_empty last_snd \n        by fastforce \n      then have \"snd(last l2) = snd (last l1)\"\n        using last_lenl1 last_lenl2 by auto\n      thus ?thesis using a00a by auto\n    qed\n    then have \"snd (last l1) \\<notin> Fault ` F \\<longrightarrow>\\<Gamma>\\<turnstile>\\<^sub>c(l1!k)  \\<rightarrow> (l1!(Suc k)) \\<longrightarrow>       \n      (snd((snd (\\<Gamma>, l1))!k), snd((snd (\\<Gamma>, l1))!(Suc k))) \\<in>  G\"\n    using  pair_\\<Gamma>l1 pair_\\<Gamma>l2 a00  a03 a3  eq_length a00a\n     by (metis Suc_lessD a0 a1 a2 map_eq_state)\n  } note l=this\n  {\n    assume a00: \"fst (last l1) = (Seq c c2) \\<and> final (c, snd (last l1))\" and\n           a01:\"snd (last (l1)) \\<notin> Fault ` F\"\n    then have c:\"c=Skip \\<or> c = Throw\"\n     unfolding final_def by auto    \n    then have fst_last_l2:\"fst (last l2) = c\"                               \n      using  last_lenl1 a00 l1_not_empty eq_length len0 a2 last_conv_nth last_lift \n      by fastforce      \n    also have last_eq:\"snd (last l2) = snd (last l1)\"      \n      using l2_not_empty a2 last_conv_nth last_lenl1 last_snd \n      by fastforce\n    ultimately have \"final (fst (last l2),snd (last l2))\" \n     using a00 by auto\n    then have \"final (last l2)\" by auto\n    also have \"snd (last (l2)) \\<notin> Fault ` F\"\n       using  last_eq a01 by auto\n    ultimately have \"(fst (last  l2)) = Skip \\<and> \n                    snd (last  l2) \\<in> Normal ` q \\<or>\n                  (fst (last l2) = Throw \\<and> \n                    snd (last l2) \\<in> Normal ` (a))\"\n    using a03 by auto\n    then have \"(fst (last l1) = (Seq Skip c2) \\<and> \n                    snd (last  l1) \\<in> Normal ` q) \\<or>\n                  (fst (last l1) = (Seq Throw c2) \\<and> \n                    snd (last l1) \\<in> Normal ` (a))\"\n    using last_eq fst_last_l2 a00 by force\n  }\n  thus ?thesis using l by auto qed\nqed\n\nlemma comm_map'':\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Seq c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \\<and> (\\<Gamma>, l2)\\<in> comm(G, (q,a)) F\" and\n  a2:\"l1=map (lift c2) l2\" \nshows\n  \"snd (last l1) \\<notin> Fault ` F \\<longrightarrow> ((Suc k < length l1 \\<longrightarrow>\n       \\<Gamma>\\<turnstile>\\<^sub>c(l1!k)  \\<rightarrow> (l1!(Suc k)) \\<longrightarrow>        \n       (snd(l1!k), snd(l1!(Suc k))) \\<in> G) \\<and> \n   (final (last l1) \\<longrightarrow>     \n      (fst (last l1) = Skip \\<and> \n        (snd (last  l1) \\<in> Normal ` r) \\<or>\n      (fst (last l1) = Throw \\<and> \n        snd (last l1) \\<in> Normal ` (a)))))\n     \"\nproof -\n  have a3:\"\\<forall>i. Suc i<length l2 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow> (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow> (l1!(Suc i))\" \n    using a0 a1 a2 same_comp_seq_c\n    by fastforce\n  have pair_\\<Gamma>l1:\"fst (\\<Gamma>,l1) = \\<Gamma> \\<and> snd (\\<Gamma>,l1) = l1\" by fastforce\n  have pair_\\<Gamma>l2:\"fst (\\<Gamma>,l2) = \\<Gamma> \\<and> snd (\\<Gamma>,l2) = l2\" by fastforce\n  have drop_k_s:\"l2!0 = (c1,s)\" using a1 cp_def by blast\n  have eq_length:\"length l1 = length l2\" using a2 by auto \n  then have len0:\"length l1>0\" using a0 unfolding cp_def \n    using Collect_case_prodD drop_k_s eq_length by auto\n  then have l1_not_empty:\"l1\\<noteq>[]\" by auto\n  then have l2_not_empty:\"l2 \\<noteq> []\" using a2 by blast       \n  have last_lenl1:\"last l1 = l1!((length l1) -1)\" \n        using last_conv_nth l1_not_empty by auto\n  have last_lenl2:\"last l2 = l2!((length l2) -1)\" \n       using last_conv_nth l2_not_empty by auto \n  have a03:\"snd (last l2) \\<notin> Fault ` F \\<longrightarrow>(\\<forall>i ns ns'.                 \n               Suc i<length (snd (\\<Gamma>, l2)) \\<longrightarrow> \n               fst (\\<Gamma>, l2)\\<turnstile>\\<^sub>c((snd (\\<Gamma>, l2))!i)  \\<rightarrow> ((snd (\\<Gamma>, l2))!(Suc i)) \\<longrightarrow>                                            \n                 (snd((snd (\\<Gamma>, l2))!i), snd((snd (\\<Gamma>, l2))!(Suc i))) \\<in> G) \\<and> \n               (final (last (snd (\\<Gamma>, l2)))  \\<longrightarrow>                 \n                  ((fst (last (snd (\\<Gamma>, l2))) = Skip \\<and> \n                    snd (last (snd (\\<Gamma>, l2))) \\<in> Normal ` q)) \\<or>\n                  (fst (last (snd (\\<Gamma>, l2))) = Throw \\<and> \n                    snd (last (snd (\\<Gamma>, l2))) \\<in> Normal ` (a)))\"\n  using a1 unfolding comm_def by fastforce\n  show ?thesis unfolding comm_def \n  proof -\n  { fix k ns ns'\n    assume a00a:\"snd (last l1) \\<notin> Fault ` F\"\n    assume a00:\"Suc k < length l1\"    \n    then have \"k \\<le> length l1\" using a2 by fastforce    \n    have a00:\"Suc k < length l2\" using eq_length a00 by fastforce   \n    then have a00a:\"snd (last l2) \\<notin> Fault ` F\"\n    proof-\n      have \"snd (l1!((length l1) -1)) = snd (l2!((length l2) -1))\"      \n        using a2 a1 a0  map_eq_state eq_length l2_not_empty last_snd \n        by fastforce \n      then have \"snd(last l2) = snd (last l1)\"\n        using last_lenl1 last_lenl2 by auto\n      thus ?thesis using a00a by auto\n    qed \n    then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l1!k)  \\<rightarrow> (l1!(Suc k)) \\<longrightarrow>         \n        (snd((snd (\\<Gamma>, l1))!k), snd((snd (\\<Gamma>, l1))!(Suc k))) \\<in> G\"\n       using  pair_\\<Gamma>l1 pair_\\<Gamma>l2 a00  a03 a3  eq_length a00a\n      by (metis (no_types,lifting) a2 Suc_lessD nth_map snd_lift)\n    } note l= this\n    {\n     assume a00: \"final (last l1)\"           \n     then have c:\"fst (last l1)=Skip \\<or> fst (last l1) = Throw\"\n       unfolding final_def by auto \n     moreover have \"fst (last l1) = Seq (fst (last l2)) c2\" \n       using a2 last_lenl1 eq_length\n      proof -\n        have \"last l2 = l2 ! (length l2 - 1)\"\n          using l2_not_empty last_conv_nth by blast\n        then show ?thesis\n          by (metis One_nat_def a2 l2_not_empty last_lenl1 last_lift)\n      qed\n      ultimately have False by simp  \n    } thus ?thesis using l  by auto qed\nqed\n\nlemma comm_map:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Seq c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \\<and> (\\<Gamma>, l2)\\<in> comm(G, (q,a)) F\" and\n  a2:\"l1=map (lift c2) l2\" \nshows\n  \"(\\<Gamma>, l1)\\<in> comm(G, (r,a)) F\"\nproof - \n  {fix i \n   have \"snd (last l1) \\<notin> Fault ` F  \\<longrightarrow>(Suc i < length (l1) \\<longrightarrow>\n        \\<Gamma>\\<turnstile>\\<^sub>c (l1 ! i) \\<rightarrow> (l1 ! (Suc i)) \\<longrightarrow>       \n        (snd (l1 ! i), snd (l1 ! Suc i)) \\<in> G) \\<and>\n        (SmallStepCon.final (last l1) \\<longrightarrow>                  \n                   fst (last l1) = LanguageCon.com.Skip \\<and>\n                   snd (last l1) \\<in> Normal ` r \\<or>\n                   fst (last l1) = LanguageCon.com.Throw \\<and>\n                   snd (last l1) \\<in> Normal ` a) \"\n      using comm_map''[of \\<Gamma> l1 c1 c2 s l2 G q a F i r] a0 a1 a2 \n      by fastforce\n   }  then show ?thesis using comm_def unfolding comm_def by force       \nqed\n\nlemma Seq_sound1: \nassumes\n  a0:\"(\\<Gamma>,x)\\<in>cptn_mod\" and\n  a1:\"x!0 = ((Seq P Q),s)\" and\n  a2:\"\\<forall>i<length x. fst (x!i)\\<noteq> Q\" and\n  a3:\"\\<not> final (last x)\" and\n  a4:\"env_tran_right \\<Gamma> x rely\" and\n  a5:\"snd (x!0)\\<in> Normal ` p \\<and> Sta p rely \\<and> Sta a rely \" and \n  a6: \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P sat [p, rely, G, q,a]\" \nshows\n  \"\\<exists>xs. (\\<Gamma>,xs) \\<in> cp \\<Gamma> P s \\<and> x = map (lift Q) xs\"\nusing a0 a1 a2 a3 a4  a5 a6\nproof (induct arbitrary: P s p) \n  case (CptnModOne \\<Gamma> C s1)\n  then have \"(\\<Gamma>, [(P,s)]) \\<in> cp \\<Gamma> P s \\<and> [(C, s1)] = map (lift Q) [(P,s)]\"\n    unfolding cp_def lift_def  by (simp add: cptn.CptnOne) \n  thus ?case by fastforce\nnext\n  case (CptnModEnv \\<Gamma> C s1 t1 xsa)\n  then have C:\"C=Seq P Q\" unfolding lift_def by fastforce\n  have \"\\<exists>xs. (\\<Gamma>, xs) \\<in> cp \\<Gamma> P t1 \\<and> (C, t1) # xsa = map (lift Q) xs\"\n  proof -\n     have \"((C, t1) # xsa) ! 0 = (LanguageCon.com.Seq P Q, t1)\" using C by auto\n     moreover have \"\\<forall>i<length ((C, t1) # xsa). fst (((C, t1) # xsa) ! i) \\<noteq> Q\"\n       using CptnModEnv(5) by fastforce\n     moreover have \"\\<not> SmallStepCon.final (last ((C, t1) # xsa))\" using CptnModEnv(6) \n       by fastforce\n     moreover have \"snd (((C, t1) # xsa) ! 0) \\<in> Normal ` p\" \n       using CptnModEnv(8) CptnModEnv(1) CptnModEnv(7)\n       unfolding env_tran_right_def Sta_def by fastforce \n     ultimately show ?thesis\n       using CptnModEnv(3) CptnModEnv(7) CptnModEnv(8)  CptnModEnv(9) env_tran_tail by blast\n  qed \n  then obtain xs where hi:\"(\\<Gamma>, xs) \\<in> cp \\<Gamma> P t1 \\<and> (C, t1) # xsa = map (lift Q) xs\"\n    by fastforce\n  have s1_s:\"s1=s\" using  CptnModEnv unfolding cp_def by auto\n  obtain xsa' where xs:\"xs=((P,t1)#xsa') \\<and> (\\<Gamma>,((P,t1)#xsa'))\\<in>cptn \\<and> (C, t1) # xsa = map (lift Q) ((P,t1)#xsa')\" \n    using hi  unfolding cp_def by fastforce\n  \n  have env_tran:\"\\<Gamma>\\<turnstile>\\<^sub>c(P,s1) \\<rightarrow>\\<^sub>e (P,t1)\" using CptnModEnv Seq_env_P by (metis fst_conv nth_Cons_0)  \n  then have \"(\\<Gamma>,(P,s1)#(P,t1)#xsa')\\<in>cptn\" using xs env_tran CptnEnv by fastforce  \n  then have \"(\\<Gamma>,(P,s1)#(P,t1)#xsa') \\<in> cp \\<Gamma> P s\" \n    using cp_def s1_s by fastforce\n  moreover have \"(C,s1)#(C, t1) # xsa = map (lift Q) ((P,s1)#(P,t1)#xsa')\"\n    using xs C unfolding lift_def by fastforce\n  ultimately show ?case by auto\nnext\n  case (CptnModSkip)\n  thus ?case by (metis SmallStepCon.redex_not_Seq fst_conv nth_Cons_0)\nnext\n  case (CptnModThrow)\n  thus ?case by (metis SmallStepCon.redex_not_Seq fst_conv nth_Cons_0)\nnext\n  case (CptnModSeq1 \\<Gamma> P0 sa xsa zs P1)\n  then have a1:\"LanguageCon.com.Seq P Q = LanguageCon.com.Seq P0 P1\"\n    by fastforce  \n  have f1: \"sa = s\"\n    using CptnModSeq1.prems(1) by force\n  have f2: \"P = P0 \\<and> Q = P1\" using a1 by auto\n  have \"(\\<Gamma>, (P0, sa) # xsa) \\<in> cptn\"\n    by (metis CptnModSeq1.hyps(1) cptn_eq_cptn_mod_set)\n  hence \"(\\<Gamma>, (P0, sa) # xsa) \\<in> cp \\<Gamma> P s\"\n    using f2 f1 by (simp add: cp_def)\n  thus ?case\n    using Cons_lift CptnModSeq1.hyps(3) a1 by fastforce   \nnext\n  case (CptnModSeq2 \\<Gamma> P0 sa xsa P1 ys zs) \n  then have \"P0 = P \\<and> P1 = Q\" by auto\n  then obtain i where zs:\"fst (zs!i) = Q \\<and> (i< (length zs))\" using CptnModSeq2\n    by (metis (no_types, lifting) add_diff_cancel_left' fst_conv length_Cons length_append nth_append_length zero_less_Suc zero_less_diff)    \n  then have \"Suc i< length ((Seq P0 P1,sa)#zs)\" by fastforce\n  then have \"fst (((Seq P0 P1, sa) # zs)!Suc i) = Q\" using zs by fastforce    \n  thus ?case using CptnModSeq2(8) zs by auto\nnext\n  case (CptnModSeq3 \\<Gamma> P1 sa xsa s' ys zs Q1 )          \n  have s'_a:\"s' \\<in>  a\"   \n  proof -\n    have  cpP1:\"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> cp \\<Gamma> P1 (Normal sa)\" \n      using CptnModSeq3.hyps(1) cptn_eq_cptn_mod_set unfolding cp_def by fastforce\n    have map:\"((Seq P1 Q1), Normal sa)#(map (lift Q1) xsa) = map (lift Q1)  ((P1, Normal sa) # xsa) \"\n      using CptnModSeq3 by (simp add: Cons_lift) \n    then \n    have \"(\\<Gamma>,((LanguageCon.com.Seq P1 Q1, Normal sa) # (map (lift Q1) xsa))) \\<in> assum (p,rely) F\"\n    proof - \n      have \"env_tran_right \\<Gamma> ((LanguageCon.com.Seq P1 Q1, Normal sa) # (map (lift Q1) xsa)) rely\" \n        using  CptnModSeq3(11) CptnModSeq3(7) map\n        by (metis (no_types) Cons_lift_append CptnModSeq3.hyps(7) CptnModSeq3.prems(4) env_tran_subr) \n      thus ?thesis using CptnModSeq3(12) \n      unfolding assum_def env_tran_right_def by fastforce  \n    qed\n    moreover have \"(\\<Gamma>,((Seq P1 Q1), Normal sa)#(map (lift Q1) xsa)) \\<in> cp \\<Gamma> (Seq P1 Q1) (Normal sa)\"\n      using CptnModSeq3(7) CptnModSeq3.hyps(1) cptn_eq_cptn_mod_set cptn_mod.CptnModSeq1 \n      unfolding cp_def  by fastforce  \n    ultimately have  \"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> assum (p,rely) F\" \n      using assum_map map cpP1 by fastforce\n    then have \"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> comm (G,(q,a)) F\" \n      using cpP1 CptnModSeq3(13)  CptnModSeq3.prems(1) unfolding com_validity_def by auto\n    thus ?thesis   \n      using CptnModSeq3(3)  CptnModSeq3(4)\n      unfolding comm_def final_def by fastforce\n  qed\n  have \"final (last ((LanguageCon.com.Throw, Normal s')# ys))\"\n  proof -\n    have cptn:\"(\\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn\" \n      using CptnModSeq3(5) by (simp add: cptn_eq_cptn_mod_set)\n    moreover have throw_0:\"((LanguageCon.com.Throw, Normal s') # ys)!0 = (Throw, Normal s') \\<and> 0 < length((LanguageCon.com.Throw, Normal s') # ys)\"\n      by force         \n    moreover have last:\"last ((LanguageCon.com.Throw, Normal s') # ys) = ((LanguageCon.com.Throw, Normal s') # ys)!((length ((LanguageCon.com.Throw, Normal s') # ys)) - 1)\"\n      using last_conv_nth by auto\n    moreover have env_tran:\"env_tran_right \\<Gamma> ((LanguageCon.com.Throw, Normal s') # ys) rely\" \n      using  CptnModSeq3(11)  CptnModSeq3(7) env_tran_subl env_tran_tail by blast           \n    ultimately obtain st' where \"fst (last ((LanguageCon.com.Throw, Normal s') # ys)) = Throw \\<and>        \n                     snd (last ((LanguageCon.com.Throw, Normal s') # ys)) = Normal st'\" \n    using zero_throw_all_throw[of \\<Gamma> \"((Throw, Normal s') # ys)\" \"s'\" \"(length ((Throw, Normal s') # ys))-1\" a rely]\n          s'_a CptnModSeq3(11) CptnModSeq3(12) by fastforce      \n    thus ?thesis using CptnModSeq3(10) final_def by blast\n  qed\n  thus ?case using CptnModSeq3(10) CptnModSeq3(7)\n    by force\nqed (auto)\n\nlemma Seq_sound2: \nassumes\n  a0:\"(\\<Gamma>,x)\\<in>cptn_mod\" and\n  a1:\"x!0 = ((Seq P Q),s)\" and\n  a2:\"\\<forall>i<length x. fst (x!i)\\<noteq> Q\" and\n  a3:\"fst (last x) = Throw \\<and> snd (last x) = Normal s'\" and\n  a4:\"env_tran_right \\<Gamma> x rely\"\nshows\n  \"\\<exists>xs s' ys. (\\<Gamma>,xs) \\<in> cp \\<Gamma> P s \\<and> x = ((map (lift Q) xs)@((Throw, Normal s')#ys))\"\nusing a0 a1 a2 a3 a4\nproof (induct arbitrary: P s s')\n  case (CptnModOne \\<Gamma> C s1)\n  then have \"(\\<Gamma>, [(P,s)]) \\<in> cp \\<Gamma> P s \\<and> [(C, s1)] = map (lift Q) [(P,s)]@[(Throw, Normal s')]\"\n    unfolding cp_def lift_def  by (simp add: cptn.CptnOne) \n  thus ?case by fastforce\nnext\n  case (CptnModEnv \\<Gamma> C s1 t1 xsa)\n  then have C:\"C=Seq P Q\" unfolding lift_def by fastforce\n  have \"\\<exists>xs s' ys. (\\<Gamma>, xs) \\<in> cp \\<Gamma> P t1 \\<and> (C, t1) # xsa = map (lift Q) xs@((Throw, Normal s')#ys)\"\n  proof -\n     have \"((C, t1) # xsa) ! 0 = (LanguageCon.com.Seq P Q, t1)\" using C by auto\n     moreover have \"\\<forall>i<length ((C, t1) # xsa). fst (((C, t1) # xsa) ! i) \\<noteq> Q\"\n       using CptnModEnv(5) by fastforce\n     moreover have \"fst (last ((C, t1) # xsa)) = Throw \\<and> snd (last ((C, t1) # xsa)) = Normal s'\" using CptnModEnv(6) \n       by fastforce\n     ultimately show ?thesis\n       using CptnModEnv(3) CptnModEnv(7) env_tran_tail by blast     \n  qed \n  then obtain xs s'' ys where hi:\"(\\<Gamma>, xs) \\<in> cp \\<Gamma> P t1 \\<and> (C, t1) # xsa = map (lift Q) xs@((Throw, Normal s'')#ys)\"\n    by fastforce\n  have s1_s:\"s1=s\" using  CptnModEnv unfolding cp_def by auto\n  have \"\\<exists>xsa' s'' ys. xs=((P,t1)#xsa') \\<and> (\\<Gamma>,((P,t1)#xsa'))\\<in>cptn \\<and> (C, t1) # xsa = map (lift Q) ((P,t1)#xsa')@((Throw, Normal s'')#ys)\" \n    using hi  unfolding cp_def\n  proof -\n      have \"(\\<Gamma>,xs)\\<in>cptn \\<and> xs!0 = (P,t1)\" using hi unfolding cp_def by fastforce\n      moreover then have \"xs\\<noteq>[]\" using cptn.simps by fastforce  \n      ultimately obtain xsa' where \"xs=((P,t1)#xsa')\" using SmallStepCon.nth_tl by fastforce \n      thus ?thesis\n        using hi using \\<open>(\\<Gamma>, xs) \\<in> cptn \\<and> xs ! 0 = (P, t1)\\<close> by auto \n  qed\n  then obtain xsa' s'' ys where xs:\"xs=((P,t1)#xsa') \\<and> (\\<Gamma>,((P,t1)#xsa'))\\<in>cptn \\<and> (C, t1) # xsa = map (lift Q) ((P,t1)#xsa')@((Throw, Normal s'')#ys)\"\n    by fastforce\n  have env_tran:\"\\<Gamma>\\<turnstile>\\<^sub>c(P,s1) \\<rightarrow>\\<^sub>e (P,t1)\" using CptnModEnv Seq_env_P by (metis fst_conv nth_Cons_0)  \n  then have \"(\\<Gamma>,(P,s1)#(P,t1)#xsa')\\<in>cptn\" using xs env_tran CptnEnv by fastforce  \n  then have \"(\\<Gamma>,(P,s1)#(P,t1)#xsa') \\<in> cp \\<Gamma> P s\" \n    using cp_def s1_s by fastforce\n  moreover have \"(C,s1)#(C, t1) # xsa = map (lift Q) ((P,s1)#(P,t1)#xsa')@((Throw, Normal s'')#ys)\"\n    using xs C unfolding lift_def by fastforce\n  ultimately show ?case by auto\nnext\n  case (CptnModSkip)\n  thus ?case by (metis SmallStepCon.redex_not_Seq fst_conv nth_Cons_0)\nnext\n  case (CptnModThrow)\n  thus ?case by (metis SmallStepCon.redex_not_Seq fst_conv nth_Cons_0)\nnext\n  case (CptnModSeq1 \\<Gamma> P0 sa xsa zs P1)  \n  thus ?case    \n  proof -\n    have \"\\<forall>c p. fst (case p of (ca::('s, 'a, 'd) LanguageCon.com, x::('s, 'd) xstate) \\<Rightarrow> (LanguageCon.com.Seq ca c, x)) = LanguageCon.com.Seq (fst p) c\"\n      by simp\n    then have \"[] = xsa\"\n      using CptnModSeq1(6) CptnModSeq1(3)\n      by (metis (no_types) LanguageCon.com.distinct(71) fst_conv last.simps last_map lift_def)\n    then have \"\\<forall>c. Throw = c \\<or> [] = zs\"\n      using CptnModSeq1(3) by fastforce\n    then show ?thesis\n      using CptnModSeq1.prems(3) by force\n  qed   \nnext\n  case (CptnModSeq2 \\<Gamma> P0 sa xsa P1 ys zs) \n  then have \"P0 = P \\<and> P1 = Q\" by auto\n  then obtain i where zs:\"fst (zs!i) = Q \\<and> (i< (length zs))\" using CptnModSeq2\n    by (metis (no_types, lifting) add_diff_cancel_left' fst_conv length_Cons length_append nth_append_length zero_less_Suc zero_less_diff)    \n  then have \"Suc i< length ((Seq P0 P1,sa)#zs)\" by fastforce\n  then have \"fst (((Seq P0 P1, sa) # zs)!Suc i) = Q\" using zs by fastforce    \n  thus ?case using CptnModSeq2(8) zs by auto\nnext \n  case (CptnModSeq3 \\<Gamma> P0 sa xsa s'' ys zs P1)  \n  then have \"P0 = P \\<and> P1 = Q \\<and> s=Normal sa\" by auto  \n  moreover then have \"(\\<Gamma>, (P0, Normal sa) # xsa)\\<in> cp \\<Gamma> P s\" \n    using CptnModSeq3(1)\n    by (simp add: cp_def cptn_eq_cptn_mod_set)  \n  moreover have \"last zs=(Throw, Normal s')\" using CptnModSeq3(10) CptnModSeq3.hyps(7) \n    by (simp add: prod_eqI)    \n  ultimately show ?case using  CptnModSeq3(7)\n    using Cons_lift_append by blast      \nqed (auto)\n\nlemma Last_Skip_Exist_Final: \nassumes\n  a0:\"(\\<Gamma>,x)\\<in>cptn\" and\n  a1:\"x!0 = ((Seq P Q),s)\" and\n  a2:\"\\<forall>i<length x. fst (x!i)\\<noteq> Q\" and\n  a3:\"fst(last x) = Skip\"  \nshows \n  \"\\<exists>c s' i. i<length x \\<and> x!i = (Seq c Q,s') \\<and> final (c,s')\"\nusing a0 a1 a2 a3 \nproof (induct arbitrary: P s)\n  case (CptnOne \\<Gamma> c s1) thus ?case by fastforce \nnext\n  case (CptnEnv \\<Gamma> C st t xsa) \n  thus ?case \n  proof -         \n    have \"LanguageCon.com.Seq P Q = C\"\n      using CptnEnv.prems(1) by auto\n    then show ?thesis\n      using CptnEnv.hyps(3) CptnEnv.prems(2) CptnEnv.prems(3) by fastforce\n  qed\nnext\n  case (CptnComp \\<Gamma> C st C' st' xsa) \n  then have c_seq:\"C = (Seq P Q) \\<and> st = s\" by force\n  from CptnComp show ?case proof(cases)\n    case (Seqc P1 P1' P2) \n    then have \"\\<exists>c s' i. i < length ((C', st') # xsa) \\<and> \n                        ((C', st') # xsa) ! i = (LanguageCon.com.Seq c Q, s') \\<and> \n                        SmallStepCon.final (c, s')\"\n      using CptnComp last.simps  by fastforce\n    thus ?thesis by fastforce \n  next\n    case (SeqThrowc C2 s') \n    thus ?thesis \n    proof -\n      have \"LanguageCon.com.Seq LanguageCon.com.Throw Q = C\"\n        using \\<open>C = LanguageCon.com.Seq LanguageCon.com.Throw C2\\<close> c_seq by blast\n      then show ?thesis\n        using \\<open>st = Normal s'\\<close> unfolding final_def by force\n    qed\n  next\n    case (FaultPropc) thus ?thesis \n      using c_seq redex_not_Seq by blast\n  next\n    case (StuckPropc) thus ?thesis \n      using c_seq redex_not_Seq by blast\n  next \n    case (AbruptPropc) thus ?thesis\n     using c_seq redex_not_Seq by blast \n  qed (auto)\nqed\n\nlemma Seq_sound3: \nassumes\n  a0:\"(\\<Gamma>,x)\\<in>cptn_mod\" and\n  a1:\"x!0 = ((Seq P Q),s)\" and\n  a2:\"\\<forall>i<length x. fst (x!i)\\<noteq> Q\" and\n  a3:\"fst(last x) = Skip\" and\n  a4:\"env_tran_right \\<Gamma> x rely \" and\n  a5:\"snd (x!0)\\<in> Normal ` p \\<and> Sta p rely \\<and> Sta a rely\" and\n  a6: \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P sat [p, rely, G, q,a]\"\nshows\n  \"False\"\nusing a0 a1 a2 a3 a4 a5 a6\nproof (induct arbitrary: P s p) (* p) *)\n  case (CptnModOne \\<Gamma> C s1)  \n    thus ?case by fastforce\nnext\n  case (CptnModEnv \\<Gamma> C s1 t1 xsa)\n  then have C:\"C=Seq P Q\" unfolding lift_def by fastforce\n  thus ?case\n  proof -\n     have \"((C, t1) # xsa) ! 0 = (LanguageCon.com.Seq P Q, t1)\" using C by auto\n     moreover have \"\\<forall>i<length ((C, t1) # xsa). fst (((C, t1) # xsa) ! i) \\<noteq> Q\"\n       using CptnModEnv(5) by fastforce\n     moreover have \"fst (last ((C, t1) # xsa)) = LanguageCon.com.Skip\" using CptnModEnv(6)\n       by (simp add: SmallStepCon.final_def)        \n     moreover have \"snd (((C, t1) # xsa) ! 0) \\<in> Normal ` p\" \n       using CptnModEnv(8) CptnModEnv(1) CptnModEnv(7)\n       unfolding env_tran_right_def Sta_def by fastforce \n     ultimately show ?thesis\n       using CptnModEnv(3) CptnModEnv(7) CptnModEnv(8)  CptnModEnv(9) env_tran_tail\n       by blast\n  qed  \nnext\n  case (CptnModSkip)\n  thus ?case by (metis SmallStepCon.redex_not_Seq fst_conv nth_Cons_0)\nnext\n  case (CptnModThrow)\n  thus ?case by (metis SmallStepCon.redex_not_Seq fst_conv nth_Cons_0)\nnext\n  case (CptnModSeq1 \\<Gamma> P0 sa xsa zs P1)\n  obtain cl where \"fst (last ((LanguageCon.com.Seq P0 P1, sa) # zs)) = Seq cl P1\"\n    using CptnModSeq1(3) by (metis One_nat_def fst_conv last.simps last_conv_nth last_lift map_is_Nil_conv)\n  thus ?case using CptnModSeq1(6) by auto\nnext\n case (CptnModSeq2 \\<Gamma> P0 sa xsa P1 ys zs) \n  then have \"P0 = P \\<and> P1 = Q\" by auto\n  then obtain i where zs:\"fst (zs!i) = Q \\<and> (i< (length zs))\" using CptnModSeq2\n    by (metis (no_types, lifting) add_diff_cancel_left' fst_conv length_Cons length_append nth_append_length zero_less_Suc zero_less_diff)        \n  thus ?case using CptnModSeq2(8) zs by auto \nnext\n   case (CptnModSeq3 \\<Gamma> P1 sa xsa s' ys zs Q1 )          \n  have s'_a:\"s' \\<in>  a\"   \n  proof -\n    have  cpP1:\"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> cp \\<Gamma> P1 (Normal sa)\" \n      using CptnModSeq3.hyps(1) cptn_eq_cptn_mod_set unfolding cp_def by fastforce\n    have map:\"((Seq P1 Q1), Normal sa)#(map (lift Q1) xsa) = map (lift Q1)  ((P1, Normal sa) # xsa) \"\n      using CptnModSeq3 by (simp add: Cons_lift) \n    then \n    have \"(\\<Gamma>,((LanguageCon.com.Seq P1 Q1, Normal sa) # (map (lift Q1) xsa))) \\<in> assum (p,rely) F\"\n    proof - \n      have \"env_tran_right \\<Gamma> ((LanguageCon.com.Seq P1 Q1, Normal sa) # (map (lift Q1) xsa)) rely\" \n        using  CptnModSeq3(11) CptnModSeq3(7) map\n        by (metis (no_types) Cons_lift_append CptnModSeq3.hyps(7) CptnModSeq3.prems(4) env_tran_subr) \n      thus ?thesis using CptnModSeq3(12) \n      unfolding assum_def env_tran_right_def by fastforce  \n    qed\n    moreover have \"(\\<Gamma>,((Seq P1 Q1), Normal sa)#(map (lift Q1) xsa)) \\<in> cp \\<Gamma> (Seq P1 Q1) (Normal sa)\"\n      using CptnModSeq3(7) CptnModSeq3.hyps(1) cptn_eq_cptn_mod_set cptn_mod.CptnModSeq1 \n      unfolding cp_def  by fastforce  \n    ultimately have  \"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> assum (p,rely) F\" \n      using assum_map map cpP1 by fastforce\n    then have \"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> comm (G,(q,a)) F\" \n      using cpP1 CptnModSeq3(13)  CptnModSeq3.prems(1) unfolding com_validity_def by auto\n    thus ?thesis   \n      using CptnModSeq3(3)  CptnModSeq3(4)\n      unfolding comm_def final_def by fastforce\n  qed\n  have \"fst (last ((LanguageCon.com.Throw, Normal s') # ys)) = Throw\"\n  proof -\n    have cptn:\"(\\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn\" \n      using CptnModSeq3(5) by (simp add: cptn_eq_cptn_mod_set)\n    moreover have throw_0:\"((LanguageCon.com.Throw, Normal s') # ys)!0 = (Throw, Normal s') \\<and> 0 < length((LanguageCon.com.Throw, Normal s') # ys)\"\n      by force         \n    moreover have last:\"last ((LanguageCon.com.Throw, Normal s') # ys) = ((LanguageCon.com.Throw, Normal s') # ys)!((length ((LanguageCon.com.Throw, Normal s') # ys)) - 1)\"\n      using last_conv_nth by auto\n    moreover have env_tran:\"env_tran_right \\<Gamma> ((LanguageCon.com.Throw, Normal s') # ys) rely\" \n      using  CptnModSeq3(11)  CptnModSeq3(7) env_tran_subl env_tran_tail by blast           \n    ultimately obtain st' where \"fst (last ((LanguageCon.com.Throw, Normal s') # ys)) = Throw \\<and>        \n                     snd (last ((LanguageCon.com.Throw, Normal s') # ys)) = Normal st'\" \n    using zero_throw_all_throw[of \\<Gamma> \"((Throw, Normal s') # ys)\" \"s'\" \"(length ((Throw, Normal s') # ys))-1\" a rely]\n          s'_a CptnModSeq3(11) CptnModSeq3(12) by fastforce      \n    thus ?thesis using CptnModSeq3(10) final_def by blast\n  qed\n  thus ?case using CptnModSeq3(10) CptnModSeq3(7)\n    by force\nqed(auto)\n\nlemma map_xs_ys:\n  assumes\n  a0:\"(\\<Gamma>, (P0, sa) # xsa) \\<in> cptn_mod\" and    \n  a1:\"fst (last ((P0, sa) # xsa)) = C\" and\n  a2:\"(\\<Gamma>, (P1, snd (last ((P0, sa) # xsa))) # ys) \\<in> cptn_mod\" and\n  a3:\"zs = map (lift P1) xsa @ (P1, snd (last ((P0, sa) # xsa))) # ys\" and\n  a4:\"((LanguageCon.com.Seq P0 P1, sa) # zs) ! 0 = (LanguageCon.com.Seq P Q, s)\" and\n  a5:\"i < length ((LanguageCon.com.Seq P0 P1, sa) # zs) \\<and> ((LanguageCon.com.Seq P0 P1, sa) # zs) ! i = (Q, sj)\" and\n  a6:\"\\<forall>j<i. fst (((LanguageCon.com.Seq P0 P1, sa) # zs) ! j) \\<noteq> Q\"\nshows \n  \"\\<exists>xs ys. (\\<Gamma>, xs) \\<in> cp \\<Gamma> P s \\<and>\n            (\\<Gamma>, ys) \\<in> cp \\<Gamma> Q (snd (xs ! (i - 1))) \\<and> (LanguageCon.com.Seq P0 P1, sa) # zs = map (lift Q) xs @ ys\"\nproof -\n  let ?P0 = \"(P0, sa) # xsa\"\n  have P_Q:\"P=P0 \\<and> s=sa \\<and> Q = P1\" using a4 by force\n  have i:\"i=(length ((P0, sa) # xsa))\"   \n  proof (cases \"i=(length ((P0, sa) # xsa))\")\n    case True thus ?thesis by auto\n  next\n    case False     \n    then have i:\"i<(length ((P0, sa) # xsa)) \\<or> i > (length ((P0, sa) # xsa))\" by auto\n    {\n      assume i:\"i<(length ((P0, sa) # xsa))\"\n      then have eq_map:\"((LanguageCon.com.Seq P0 P1, sa) # zs) ! i = map (lift P1) ((P0, sa) # xsa) ! i\" \n        using a3 Cons_lift_append by (metis (no_types, lifting) length_map nth_append) \n      then have  \"\\<exists>ci si. map (lift P1) ((P0, sa) # xsa) ! i = (Seq ci P1,si)\" \n        using i unfolding lift_def\n        proof -\n          have \"map (\\<lambda>(c, y). (LanguageCon.com.Seq c P1, y)) ((P0, sa) # xsa) ! i = (case ((P0, sa) # xsa) ! i of (c, x) \\<Rightarrow> (LanguageCon.com.Seq c P1, x))\"\n            by (meson \\<open>i < length ((P0, sa) # xsa)\\<close> nth_map)\n          then show \"\\<exists>c x. map (\\<lambda>(c, x). (LanguageCon.com.Seq c P1, x)) ((P0, sa) # xsa) ! i = (LanguageCon.com.Seq c P1, x)\"\n            by (simp add: case_prod_beta)\n        qed \n      then have  \"((LanguageCon.com.Seq P0 P1, sa) # zs) ! i \\<noteq> (Q, sj)\" \n        using P_Q eq_map by fastforce\n      then have ?thesis using a5 by auto\n    }note l=this\n    {\n      assume i:\"i>(length ((P0, sa) # xsa))\"\n      have \"fst (((LanguageCon.com.Seq P0 P1, sa) # zs) ! (length ?P0)) = Q\"\n        using a3 P_Q Cons_lift_append by (metis fstI length_map nth_append_length) \n      then have ?thesis using a6 i by auto\n    }\n    thus ?thesis using l i by auto\n   qed\n   then have  \"(\\<Gamma>, (P0, sa) # xsa) \\<in> cp \\<Gamma> P s\" \n    using a0  cptn_eq_cptn_mod P_Q unfolding cp_def by fastforce\n  also have \"(\\<Gamma>, (P1, snd (last ((P0, sa) # xsa))) # ys) \\<in> cp \\<Gamma> Q (snd (?P0 ! ((length ?P0) -1)))\" \n    using a3 cptn_eq_cptn_mod P_Q unfolding cp_def\n  proof -\n    have \"(\\<Gamma>, (Q, snd (last ((P0, sa) # xsa))) # ys) \\<in> cptn_mod\"\n      using a2 P_Q by blast\n    then have \"(\\<Gamma>, (Q, snd (last ((P0, sa) # xsa))) # ys) \\<in> {(f, ps). ps ! 0 = (Q, snd (((P0, sa) # xsa) ! (Suc (length xsa) - 1))) \\<and> (\\<Gamma>, ps) \\<in> cptn \\<and> f = \\<Gamma>}\"\n      by (simp add: cptn_eq_cptn_mod last_length)\n    then show \"(\\<Gamma>, (P1, snd (last ((P0, sa) # xsa))) # ys) \\<in> {(f, ps). ps ! 0 = (Q, snd (((P0, sa) # xsa) ! (length ((P0, sa) # xsa) - 1))) \\<and> (\\<Gamma>, ps) \\<in> cptn \\<and> f = \\<Gamma>}\"\n      using P_Q by force\n  qed \n  ultimately show ?thesis using a3 P_Q i using Cons_lift_append by blast\nqed\n\nlemma Seq_sound4: \nassumes\n  a0:\"(\\<Gamma>,x)\\<in>cptn_mod\" and\n  a1:\"x!0 = ((Seq P Q),s)\" and\n  a2:\"i<length x \\<and> x!i=(Q,sj)\" and\n  a3:\"\\<forall>j<i. fst(x!j)\\<noteq>Q\" and \n  a4:\"env_tran_right \\<Gamma> x rely\" and\n  a5:\"snd (x!0)\\<in> Normal ` p \\<and> Sta p rely \\<and> Sta a rely\" and\n  a6: \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P sat [p, rely, G, q,a]\"\nshows\n  \"\\<exists>xs ys. (\\<Gamma>,xs) \\<in> (cp \\<Gamma> P s) \\<and> (\\<Gamma>,ys) \\<in> (cp \\<Gamma> Q (snd (xs!(i-1)))) \\<and> x = (map (lift Q) xs)@ys\"\nusing a0 a1 a2 a3 a4 a5 a6\nproof (induct arbitrary: i sj P s p) \n   case (CptnModOne \\<Gamma> C s1)  \n    thus ?case by fastforce\nnext\n  case (CptnModEnv \\<Gamma> C st t xsa)    \n  have a1:\"Seq P Q \\<noteq> Q\" by simp    \n  then have C_seq:\"C=(Seq P Q)\" using CptnModEnv by fastforce\n  then have \"fst(((C, st) # (C, t) # xsa)!0) \\<noteq>Q\" using CptnEnv a1 by auto\n  moreover have  \"fst(((C, st) # (C, t) # xsa)!1) \\<noteq>Q\" using CptnModEnv a1 by auto\n  moreover have \"fst(((C, st) # (C, t) # xsa)!i) =Q\" using CptnModEnv by auto\n  ultimately have i_suc: \"i> (Suc 0)\" \n    by (metis Suc_eq_plus1 Suc_lessI add.left_neutral neq0_conv) \n  then obtain i' where i':\"i=Suc i'\" by (meson lessE) \n  then have i_minus:\"i'=i-1\" by auto\n  have \"((C, t) # xsa) ! 0 = ((Seq P Q), t)\"\n    using CptnModEnv by auto \n  moreover have \"i'< length ((C,t)#xsa) \\<and> ((C,t)#xsa)!i' = (Q,sj)\"\n    using i' CptnModEnv(5) by force\n  moreover have \"\\<forall>j<i'. fst (((C, t) # xsa) ! j) \\<noteq> Q\"\n    using i' CptnModEnv(6) by force\n  moreover have \"snd (((C, t) # xsa) ! 0) \\<in> Normal ` p\" \n       using CptnModEnv(8) CptnModEnv(1) CptnModEnv(7)\n       unfolding env_tran_right_def Sta_def by fastforce \n  ultimately have hyp:\"\\<exists>xs ys.\n     (\\<Gamma>, xs) \\<in> cp \\<Gamma> P t \\<and>\n     (\\<Gamma>, ys) \\<in> cp \\<Gamma> Q (snd (xs ! (i'-1))) \\<and> (C, t) # xsa = map (lift Q) xs @ ys\"\n    using CptnModEnv(3) env_tran_tail  CptnModEnv(8) CptnModEnv(9) CptnModEnv.prems(4) by blast  \n  then obtain xs ys where xs_cp:\"(\\<Gamma>, xs) \\<in> cp \\<Gamma> P t \\<and>\n     (\\<Gamma>, ys) \\<in> cp \\<Gamma> Q (snd (xs ! (i'-1))) \\<and> (C, t) # xsa = map (lift Q) xs @ ys\"\n    by fast\n  have \"(\\<Gamma>, (P,s)#xs) \\<in> cp \\<Gamma> P s\"\n  proof -\n    have \"xs!0 = (P,t)\" \n      using xs_cp unfolding cp_def by blast\n    moreover have \"xs\\<noteq>[]\"\n      using cp_def cptn.simps xs_cp by blast \n    ultimately obtain xs' where xs':\"(\\<Gamma>, (P,t)#xs') \\<in> cptn \\<and> xs=(P,t)#xs'\" \n      using SmallStepCon.nth_tl xs_cp unfolding cp_def by force\n    thus ?thesis using cp_def  cptn.CptnEnv\n    proof -\n      have \"(LanguageCon.com.Seq P Q, s) = (C, st)\"\n        using CptnModEnv.prems(1) by auto\n      then have \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow>\\<^sub>e (P, t)\"\n        using Seq_env_P CptnModEnv(1) by blast\n      then show ?thesis\n        by (simp add:xs' cp_def cptn.CptnEnv)\n    qed\n  qed\n  thus  ?case \n    using i_suc Cons_lift_append CptnModEnv.prems(1) i' i_minus xs_cp\n    by fastforce   \nnext\n  case (CptnModSkip)\n  thus ?case by (metis SmallStepCon.redex_not_Seq fst_conv nth_Cons_0)\nnext\n  case (CptnModThrow)\n  thus ?case by (metis SmallStepCon.redex_not_Seq fst_conv nth_Cons_0)\nnext\n  case (CptnModSeq1 \\<Gamma> P0 sa xsa zs P1)  \n  then have P1_Q:\"P1 = Q\" by auto\n  let ?x = \"(LanguageCon.com.Seq P0 P1, sa) # zs\"\n  have \"\\<forall>j<length ?x. \\<exists>c s. ?x!j = (Seq c P1,s)\" using CptnModSeq1(3)\n  proof (induct xsa arbitrary: zs P0 P1 sa)\n    case Nil thus ?case by auto\n  next\n    case (Cons a xsa) \n    then obtain ac as where \"a=(ac,as)\" by fastforce\n    then have zs:\"zs = (Seq ac P1,as)#(map (lift P1)  xsa)\" \n      using Cons(2) \n      unfolding lift_def  by auto\n    have zs_eq:\"(map (lift P1)  xsa)=(map (lift P1)  xsa)\" by auto\n    note hyp=Cons(1)[OF zs_eq] \n    note hyp[of ac as]\n    thus ?case using zs Cons(2) by (metis One_nat_def diff_Suc_Suc diff_zero length_Cons less_Suc_eq_0_disj nth_Cons') \n  qed  \n  thus ?case using P1_Q CptnModSeq1(5) using fstI seq_not_eq2 by auto\nnext\n  case (CptnModSeq2 \\<Gamma> P0 sa xsa P1 ys zs) \n   show ?case using map_xs_ys[OF CptnModSeq2(1) CptnModSeq2(3) CptnModSeq2(4) CptnModSeq2(6)\n                              CptnModSeq2(7) CptnModSeq2(8) CptnModSeq2(9)] by blast\nnext \n  case (CptnModSeq3 \\<Gamma> P1 sa xsa s' ys zs Q1 ) \n  then have P_Q:\"P=P1 \\<and> Q = Q1\" by force\n  thus ?case\n  proof (cases \"Q1 = Throw\")\n    case True thus ?thesis using map_xs_ys[of \\<Gamma> P1 \"Normal sa\" xsa Throw Throw ys zs] \n      CptnModSeq3 by fastforce\n  next \n    case False note q_not_throw=this\n    have \"\\<forall>x. x< length ((LanguageCon.com.Seq P1 Q1, Normal sa) # zs) \\<longrightarrow>\n              ((LanguageCon.com.Seq P1 Q1, Normal sa) # zs) ! x \\<noteq> (Q, sj)\"\n    proof -\n    {\n      fix x\n      assume x_less:\"x< length ((LanguageCon.com.Seq P1 Q1, Normal sa) # zs)\"\n      have \"((LanguageCon.com.Seq P1 Q1, Normal sa) # zs) ! x \\<noteq> (Q, sj)\"\n      proof (cases \"x < length ((LanguageCon.com.Seq P1 Q1, Normal sa)#map (lift Q1) xsa)\")\n        case True \n        then have eq_map:\"((LanguageCon.com.Seq P1 Q1, Normal sa) # zs) ! x = map (lift Q1) ((P1, Normal sa) # xsa) ! x\"           \n          by (metis (no_types) Cons_lift Cons_lift_append CptnModSeq3.hyps(7) True nth_append)\n        then have  \"\\<exists>ci si. map (lift Q1) ((P1, Normal sa) # xsa) ! x = (Seq ci Q1,si)\" \n          using True unfolding lift_def\n        proof -\n          have \"x < length ((P1, Normal sa) # xsa)\"\n            using True by auto\n          then have \"map (\\<lambda>(c, y). (LanguageCon.com.Seq c Q1, y)) ((P1, Normal sa) # xsa) ! x = (case ((P1, Normal sa) # xsa) ! x of (c, x) \\<Rightarrow> (LanguageCon.com.Seq c Q1, x))\"\n            using nth_map by blast\n          then show \"\\<exists>c x1. map (\\<lambda>(c, x1). (LanguageCon.com.Seq c Q1, x1)) ((P1, Normal sa) # xsa) ! x = (LanguageCon.com.Seq c Q1, x1)\"\n            by (simp add: case_prod_beta')\n        qed            \n        then have  \"((LanguageCon.com.Seq P1 Q1, Normal sa) # zs) ! x \\<noteq> (Q, sj)\" \n          using P_Q eq_map by fastforce     \n        thus ?thesis using CptnModSeq3(10) by auto        \n      next\n        case False \n        have s'_a:\"s' \\<in>  a\"   \n        proof -\n        have  cpP1:\"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> cp \\<Gamma> P1 (Normal sa)\" \n          using CptnModSeq3.hyps(1) cptn_eq_cptn_mod_set unfolding cp_def by fastforce\n        have map:\"((Seq P1 Q1), Normal sa)#(map (lift Q1) xsa) = map (lift Q1)  ((P1, Normal sa) # xsa) \"\n          using CptnModSeq3 by (simp add: Cons_lift) \n        then \n        have \"(\\<Gamma>,((LanguageCon.com.Seq P1 Q1, Normal sa) # (map (lift Q1) xsa))) \\<in> assum (p,rely) F\"\n        proof - \n          have \"env_tran_right \\<Gamma> ((LanguageCon.com.Seq P1 Q1, Normal sa) # (map (lift Q1) xsa)) rely\" \n            using  CptnModSeq3(11) CptnModSeq3(7) map\n            by (metis (no_types) Cons_lift_append CptnModSeq3.hyps(7) CptnModSeq3.prems(4) env_tran_subr) \n          thus ?thesis using CptnModSeq3(12) \n          unfolding assum_def env_tran_right_def by fastforce  \n        qed\n        moreover have \"(\\<Gamma>,((Seq P1 Q1), Normal sa)#(map (lift Q1) xsa)) \\<in> cp \\<Gamma> (Seq P1 Q1) (Normal sa)\"\n          using CptnModSeq3(7) CptnModSeq3.hyps(1) cptn_eq_cptn_mod_set cptn_mod.CptnModSeq1 \n          unfolding cp_def  by fastforce  \n        ultimately have  \"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> assum (p,rely) F\" \n          using assum_map map cpP1 by fastforce\n        then have \"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> comm (G,(q,a)) F\" \n          using cpP1 CptnModSeq3(13)  CptnModSeq3.prems(1) unfolding com_validity_def by auto\n        thus ?thesis   \n          using CptnModSeq3(3)  CptnModSeq3(4)\n          unfolding comm_def final_def by fastforce\n      qed\n      have all_throw:\"\\<forall>i<length ((LanguageCon.com.Throw, Normal s')# ys). \n              fst (((LanguageCon.com.Throw, Normal s')# ys)!i) = Throw\"\n      proof -\n       {fix i\n        assume i:\"i< length ((LanguageCon.com.Throw, Normal s')# ys)\"\n        have cptn:\"(\\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn\" \n          using CptnModSeq3(5) by (simp add: cptn_eq_cptn_mod_set)\n        moreover have throw_0:\"((LanguageCon.com.Throw, Normal s') # ys)!0 = (Throw, Normal s') \\<and> 0 < length((LanguageCon.com.Throw, Normal s') # ys)\"\n          by force         \n        moreover have last:\"last ((LanguageCon.com.Throw, Normal s') # ys) = ((LanguageCon.com.Throw, Normal s') # ys)!((length ((LanguageCon.com.Throw, Normal s') # ys)) - 1)\"\n          using last_conv_nth by auto\n        moreover have env_tran:\"env_tran_right \\<Gamma> ((LanguageCon.com.Throw, Normal s') # ys) rely\" \n          using  CptnModSeq3(11)  CptnModSeq3(7) env_tran_subl env_tran_tail by blast           \n        ultimately have \n             \"fst (((LanguageCon.com.Throw, Normal s')# ys)!i) = Throw\"          \n        using zero_throw_all_throw[of \\<Gamma> \"((Throw, Normal s') # ys)\" \"s'\" \"i\" a rely]\n              s'_a  CptnModSeq3(12) i by fastforce\n        }     \n        thus ?thesis using CptnModSeq3(10) final_def by blast        \n      qed      \n      then have \n        \"\\<forall>x\\<ge> length ((LanguageCon.com.Seq P1 Q1, Normal sa) # map (lift Q1) xsa). \n           x<length (((LanguageCon.com.Seq P1 Q1, Normal sa) # zs)) \\<longrightarrow>\n              fst (((LanguageCon.com.Seq P1 Q1, Normal sa) # zs) ! x) = Throw\"  \n      proof-\n      {\n        fix x \n        assume a1:\"x\\<ge> length ((LanguageCon.com.Seq P1 Q1, Normal sa) # map (lift Q1) xsa)\" and\n               a2:\"x<length (((LanguageCon.com.Seq P1 Q1, Normal sa) # zs))\"\n        then have \"((LanguageCon.com.Seq P1 Q1, Normal sa) # zs) ! x = \n                   ((LanguageCon.com.Throw, Normal s')# ys) !(x - (length ((LanguageCon.com.Seq P1 Q1, Normal sa) # map (lift Q1) xsa)))\"\n        using CptnModSeq3(7) by (metis Cons_lift Cons_lift_append not_le nth_append)\n        then have\"fst (((LanguageCon.com.Seq P1 Q1, Normal sa) # zs) ! x) = Throw\" \n          using all_throw a1 a2 CptnModSeq3.hyps(7)  by auto \n      } thus ?thesis by auto\n      qed       \n      thus ?thesis using False CptnModSeq3(7) q_not_throw P_Q x_less \n        by (metis fst_conv not_le)  \n    qed\n    } thus ?thesis by auto\n    qed\n    thus ?thesis using CptnModSeq3(9) by fastforce    \n  qed\nqed(auto)\n\n\n\ninductive_cases stepc_elim_cases_Seq_throw:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Seq c1 c2,s) \\<rightarrow> (Throw, Normal s1)\" \n\ninductive_cases stepc_elim_cases_Seq_skip_c2:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Seq c1 c2,s) \\<rightarrow> (c2,s)\"\n\n\nlemma seq_skip_throw:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Seq c1 c2,s) \\<rightarrow> (c2,s)  \\<Longrightarrow> c1= Skip \\<or> (c1=Throw \\<and> (\\<exists>s2'. s=Normal s2'))\"\napply (rule stepc_elim_cases_Seq_skip_c2)\napply fastforce\napply (auto)+\napply (fastforce intro:redex_not_Seq)+\ndone\n\n\nlemma Seq_sound: \n      \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p, R, G, q,a] \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> c1 sat [p, R, G, q,a] \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c2 sat [q, R, G, r,a] \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> c2 sat [q, R, G, r,a] \\<Longrightarrow>        \n       Sta a R \\<and> Sta p R \\<Longrightarrow>  (\\<forall>s. (Normal s,Normal s) \\<in> G) \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> (Seq c1 c2) sat [p, R, G, r,a]\"\nproof -  \n  assume\n    a0:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p, R, G, q,a]\" and\n    a1:\"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> c1 sat [p, R, G, q,a]\" and\n    a2:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c2 sat [q, R, G, r,a]\" and    \n    a3: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> c2 sat [q, R, G, r,a]\" and     \n    a4: \"Sta a R \\<and> Sta p R\" and\n    a5: \"(\\<forall>s. (Normal s, Normal s) \\<in> G)\"\n  { \n    fix s\n    assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"\n    then have a1:\"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> c1 sat [p, R, G, q,a]\" \n      using a1 com_cvalidity_def by fastforce  \n    then have a3: \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> c2 sat [q, R, G, r,a]\"\n      using a3 com_cvalidity_def all_call by fastforce \n    have \"cp \\<Gamma> (Seq c1 c2)  s \\<inter> assum(p, R) F \\<subseteq> comm(G, (r,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cp \\<Gamma> (Seq c1 c2) s\" and a11:\"c \\<in> assum(p, R) F\"\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have cp:\"l!0=((Seq c1 c2),s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\" using a10 cp_def c_prod by fastforce\n      have \\<Gamma>1:\"(\\<Gamma>, l) = c\" using c_prod cp by blast\n      have \"c \\<in> comm(G, (r,a)) F\"         \n      proof - \n      {\n       assume l_f:\"snd (last l) \\<notin> Fault ` F\"       \n       have assum:\"snd(l!0) \\<in> Normal ` (p) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n                 (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n       using a11 c_prod unfolding assum_def by simp\n       then have env_tran:\"env_tran \\<Gamma> p l R\" using env_tran_def cp by blast\n       then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n         using env_tran env_tran_right_def unfolding env_tran_def by auto       \n       have \"(\\<forall>i. Suc i<length l \\<longrightarrow> \n               \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                                             \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\\<and>\n             (final (last l)  \\<longrightarrow>                    \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal `  r)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` a))\"\n       proof (cases \"\\<forall>i<length l. fst (l!i)\\<noteq> c2\")\n         case True \n         then have no_c2:\"\\<forall>i<length l. fst (l!i)\\<noteq> c2\" by assumption\n         show ?thesis\n         proof (cases \"final (last l)\")\n           case True\n           then obtain s' where \"fst (last l) = Skip \\<or> (fst (last l) = Throw \\<and> snd (last l) = Normal s')\"  \n             using final_def by fast           \n           thus ?thesis\n           proof\n             assume \"fst (last l) = LanguageCon.com.Skip\" \n             then have \"False\" \n               using  no_c2 env_tran_right cp cptn_eq_cptn_mod_set Seq_sound3 a4 a1 assum by blast\n             thus ?thesis by auto\n           next             \n             assume asm0:\"fst (last l) = LanguageCon.com.Throw \\<and> snd (last l) = Normal s'\"\n             then obtain lc1 s1' ys where cp_lc1:\"(\\<Gamma>,lc1) \\<in> cp \\<Gamma> c1 s \\<and> l = ((map (lift c2) lc1)@((Throw, Normal s1')#ys))\"\n               using Seq_sound2[of \\<Gamma> l c1 c2 s s']  cp cptn_eq_cptn_mod_set env_tran_right no_c2 by blast\n             let ?m_lc1 = \"map (lift c2) lc1\"\n             let ?lm_lc1 = \"(length ?m_lc1)\"\n             let ?last_m_lc1 = \"?m_lc1!(?lm_lc1-1)\"             \n             have lc1_not_empty:\"lc1 \\<noteq> []\"\n               using \\<Gamma>1 a10 cp_def cp_lc1 by force\n             then have map_cp:\"(\\<Gamma>,?m_lc1) \\<in> cp \\<Gamma> (Seq c1 c2) s\"               \n             proof -\n               have f1: \"lc1 ! 0 = (c1, s) \\<and> (\\<Gamma>, lc1) \\<in> cptn \\<and> \\<Gamma> = \\<Gamma>\"\n                 using cp_lc1 cp_def by blast\n               then have f2: \"(\\<Gamma>, ?m_lc1) \\<in> cptn\" using lc1_not_empty\n                 by (meson lift_is_cptn)                \n               then show ?thesis\n                 using f2 f1 lc1_not_empty by (simp add: cp_def lift_def)\n             qed\n             also have map_assum:\"(\\<Gamma>,?m_lc1) \\<in> assum (p,R) F\"\n               using sub_assum a10 a11 \\<Gamma>1 cp_lc1 lc1_not_empty \n               by (metis SmallStepCon.nth_tl map_is_Nil_conv)\n             ultimately have \"((\\<Gamma>,lc1) \\<in> assum(p, R) F)\"  \n               using \\<Gamma>1 assum_map cp_lc1 by blast                          \n             then have lc1_comm:\"(\\<Gamma>,lc1) \\<in> comm(G, (q,a)) F\"  \n               using a1 cp_lc1 by (meson IntI com_validity_def contra_subsetD)\n             then have m_lc1_comm:\"(\\<Gamma>,?m_lc1) \\<in> comm(G, (q,a)) F\"\n               using map_cp map_assum comm_map cp_lc1 by fastforce\n             then have last_m_lc1:\"last (?m_lc1) = (Seq (fst (last lc1)) c2,snd (last lc1))\"\n             proof -\n               have a000:\"\\<forall>p c. (LanguageCon.com.Seq (fst p) c, snd p) = lift c p\"\n                 using Cons_lift by force\n               then show ?thesis\n                 by (simp add: last_map a000 lc1_not_empty)\n             qed\n             then have last_length:\"last (?m_lc1) = ?last_m_lc1\"  \n               using lc1_not_empty last_conv_nth list.map_disc_iff by blast \n             then have l_map:\"l!(?lm_lc1-1)= ?last_m_lc1\" \n               using cp_lc1\n               by (simp add:lc1_not_empty nth_append)\n             then have lm_lc1:\"l!(?lm_lc1) = (Throw, Normal s1')\"\n               using cp_lc1 by (meson nth_append_length) \n             then have step:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!(?lm_lc1-1)) \\<rightarrow> (l!(?lm_lc1))\"\n             proof -\n               have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!(?lm_lc1-1)) \\<rightarrow>\\<^sub>c\\<^sub>e (l!(?lm_lc1))\"\n               proof -\n                 have f1: \"\\<forall>n na. \\<not> n < na \\<or> Suc (na - Suc n) = na - n\"\n                   by (meson Suc_diff_Suc)\n                 have \"map (lift c2) lc1 \\<noteq> []\"\n                   by (metis lc1_not_empty map_is_Nil_conv)\n                 then have f2: \"0 < length (map (lift c2) lc1)\"\n                   by (meson length_greater_0_conv)\n                 then have \"length (map (lift c2) lc1) - 1 + 1 < length (map (lift c2) lc1 @ (LanguageCon.com.Throw, Normal s1') # ys)\"\n                   by simp\n                 then show ?thesis\n                   using f2 f1 by (metis (no_types) One_nat_def cp cp_lc1 cptn_tran_ce_i diff_zero)\n               qed\n               moreover have \"\\<not>\\<Gamma>\\<turnstile>\\<^sub>c(l!(?lm_lc1-1)) \\<rightarrow>\\<^sub>e (l!(?lm_lc1))\"\n               using  last_m_lc1 last_length l_map\n               proof -\n                 have \"(LanguageCon.com.Seq (fst (last lc1)) c2, snd (last lc1)) = l ! (length (map (lift c2) lc1) - 1)\"\n                   using l_map last_m_lc1 local.last_length by presburger\n                 then show ?thesis\n                   by (metis (no_types) LanguageCon.com.distinct(71) \\<open>l ! length (map (lift c2) lc1) = (LanguageCon.com.Throw, Normal s1')\\<close> env_c_c')\n               qed\n               ultimately show ?thesis using step_ce_elim_cases by blast        \n             qed\n             then have last_lc1_suc:\"snd (l!(?lm_lc1-1)) = snd (l!?lm_lc1) \\<and> fst (l!(?lm_lc1-1)) = Seq Throw c2\"\n               using lm_lc1 stepc_elim_cases_Seq_throw\n               by (metis One_nat_def asm0 append_is_Nil_conv cp_lc1 diff_Suc_less fst_conv l_map last_conv_nth last_m_lc1 length_greater_0_conv list.simps(3) local.last_length no_c2 snd_conv)                            \n             then have a_normal:\"snd (l!?lm_lc1) \\<in> Normal ` (a)\" \n             proof\n               have last_lc1:\"fst (last lc1) = Throw \\<and> snd (last lc1) = Normal s1'\" \n               using last_length l_map lm_lc1 last_m_lc1 last_lc1_suc\n               by (metis LanguageCon.com.inject(3) fst_conv snd_conv)  \n               have \"final (last lc1)\" using last_lc1 final_def \n                 by blast\n               moreover have \"snd (last lc1)\\<notin> Fault ` F\" \n                 using last_lc1 by fastforce\n               ultimately have \"(fst (last lc1) = Throw \\<and> \n                      snd (last lc1) \\<in> Normal ` (a))\" \n                 using lc1_comm last_lc1 unfolding comm_def by force\n               thus ?thesis  using  l_map last_lc1_suc last_m_lc1 last_length by auto\n             qed                                         \n             have concl:\"(\\<forall>i. Suc i<length l \\<longrightarrow> \n               \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                                           \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n             proof-\n             { fix k ns ns'\n               assume a00:\"Suc k<length l\" and\n                a21:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"   \n                then have i_m_l:\"\\<forall>i <?lm_lc1  . l!i = ?m_lc1!i\" \n                  using cp_lc1\n                proof -\n                  have \"map (lift c2) lc1 \\<noteq> []\"\n                    by (meson lc1_not_empty list.map_disc_iff)\n                  then show ?thesis\n                    by (metis (no_types) cp_lc1  nth_append)\n                qed\n                have last_not_F:\"snd (last ?m_lc1) \\<notin> Fault ` F\" \n                   using l_map last_lc1_suc lm_lc1 last_length by auto \n                have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n                proof (cases \"Suc k< ?lm_lc1\")\n                  case True \n                  then have a11': \"\\<Gamma>\\<turnstile>\\<^sub>c(?m_lc1!k)  \\<rightarrow> (?m_lc1!(Suc k))\" \n                    using a11 i_m_l True\n                  proof -\n                    have \"\\<forall>n na. \\<not> 0 < n - Suc na \\<or> na < n \"\n                      using diff_Suc_eq_diff_pred zero_less_diff by presburger\n                    then show ?thesis\n                      by (metis (no_types) Suc_lessI True a21 i_m_l l_map zero_less_diff)\n                  qed                  \n                  then have \"(snd(?m_lc1!k), snd(?m_lc1!(Suc k))) \\<in> G\"\n                  using a11' m_lc1_comm True comm_dest1 l_f last_not_F by fastforce\n                  thus ?thesis using i_m_l using  True by fastforce\n                next\n                  case False \n                  then have \"(Suc k=?lm_lc1) \\<or> (Suc k>?lm_lc1)\" by auto\n                  thus ?thesis \n                  proof\n                    {assume suck:\"(Suc k=?lm_lc1)\"\n                     then have k:\"k=?lm_lc1-1\" by auto\n                     have G_s1':\"(Normal s1', Normal s1')\\<in>G\" \n                       using a5 by auto               \n                     then show \"(snd (l!k), snd (l!Suc k)) \\<in> G\"               \n                     proof -\n                       have \"snd (l!Suc k) = Normal s1'\" \n                         using lm_lc1 suck by fastforce                                \n                       then show ?thesis using suck k G_s1' last_lc1_suc by fastforce\n                     qed\n                    }\n                  next\n                  { \n                    assume a001:\"Suc k>?lm_lc1\"\n                    have \"\\<forall>i. i\\<ge>(length lc1) \\<and> (Suc i < length l) \\<longrightarrow> \n                            \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\"\n                    using lm_lc1 lc1_not_empty\n                    proof -\n                      have \"env_tran_right \\<Gamma> l R\"\n                        by (metis  env_tran_right)\n                      then show ?thesis \n                       using a_normal cp fst_conv length_map \n                             lm_lc1 only_one_component_tran_j[of \\<Gamma> l ?lm_lc1 s1' a k R] snd_conv a21 a001 a00\n                             a4 by auto\n                    qed\n                    then have \"\\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n                      using a00 a001  by auto                    \n                    then show ?thesis using a21 by fastforce                    \n                  }\n                  qed \n                qed\n              } thus ?thesis by auto \n             qed \n             have concr:\"(final (last l)  \\<longrightarrow>                    \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` r)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` a))\" \n             proof -\n               have l_t:\"fst (last l) = Throw\" \n                 using lm_lc1 by (simp add: asm0)\n               have \"?lm_lc1 \\<le> length l -1\" using cp_lc1 by fastforce\n               then have \"snd (l ! (length l - 1)) \\<in> Normal ` a\"\n                 using  cp a_normal a4  fst_conv  lm_lc1 snd_conv \n                         env_tran_right i_throw_all_throw[of \\<Gamma> l ?lm_lc1 s1' \"(length l -1)\" _ R a ]\n                       by (metis (no_types, lifting) One_nat_def diff_is_0_eq diff_less diff_less_Suc diff_zero image_iff length_greater_0_conv lessI less_antisym list.size(3) xstate.inject(1))                               \n               thus ?thesis using l_t \n                 by (simp add:  cp_lc1 last_conv_nth)\n             qed\n             note res = conjI [OF concl concr]\n             then show ?thesis using  \\<Gamma>1 c_prod unfolding comm_def by auto\n           qed                  \n         next\n           case False\n           then obtain lc1 where cp_lc1:\"(\\<Gamma>,lc1) \\<in> cp \\<Gamma> c1 s \\<and> l = map (lift c2) lc1\" \n             using Seq_sound1 assum False no_c2 env_tran_right cp cptn_eq_cptn_mod_set a4 a1 \n             by blast           \n           then have \"((\\<Gamma>,lc1) \\<in> assum(p, R) F)\"  \n              using \\<Gamma>1  a10 a11 assum_map by blast\n           then have \"(\\<Gamma>, lc1)\\<in> comm(G, (q,a)) F\" using cp_lc1 a1\n             by (meson IntI com_validity_def contra_subsetD)\n           then have \"(\\<Gamma>, l)\\<in> comm(G, (r,a)) F\"\n             using comm_map a10 \\<Gamma>1 cp_lc1 by fastforce\n           then show ?thesis using l_f\n             unfolding comm_def by auto\n         qed\n       next         \n         case False \n         then obtain k where k_len:\"k<length l \\<and> fst (l ! k) = c2\"\n           by blast         \n         then have \"\\<exists>m. (m < length l \\<and> fst (l ! m) = c2) \\<and>\n                   (\\<forall>i<m. \\<not> (i < length l \\<and> fst (l ! i) = c2))\"   \n           using a0 exists_first_occ[of \"(\\<lambda>i. i<length l  \\<and> fst (l ! i) = c2)\" k] \n           by blast\n         then obtain i where a0:\"i<length l \\<and> fst (l !i) = c2 \\<and>\n                                (\\<forall>j<i. (fst (l ! j) \\<noteq> c2))\"\n           by fastforce        \n         then obtain s2 where li:\"l!i =(c2,s2)\" by (meson eq_fst_iff)\n         then obtain lc1 lc2 where cp_lc1:\"(\\<Gamma>,lc1) \\<in> (cp \\<Gamma> c1 s) \\<and> \n                                 (\\<Gamma>,lc2) \\<in> (cp \\<Gamma> c2 (snd (lc1!(i-1)))) \\<and> \n                                 l = (map (lift c2) lc1)@lc2\"\n           using Seq_sound4[of \\<Gamma> l c1 c2 s] a0 cptn_eq_cptn_mod_set cp env_tran_right a4 a1 assum by blast  \n         have \"\\<forall>i < length l. snd (l!i) \\<notin> Fault ` F\"\n           using cp l_f last_not_F[of \\<Gamma> l F] by blast  \n         then have i_not_fault:\"snd (l!i) \\<notin> Fault ` F\" using a0 by blast\n         have length_c1_map:\"length lc1 = length (map (lift c2) lc1)\" \n           by fastforce      \n         then have i_map:\"i=length lc1\" \n           using cp_lc1 li a0 unfolding lift_def\n         proof -\n            assume a1: \"(\\<Gamma>, lc1) \\<in> cp \\<Gamma> c1 s \\<and> (\\<Gamma>, lc2) \\<in> cp \\<Gamma> c2 (snd (lc1 ! (i - 1))) \\<and> l = map (\\<lambda>(P, s). (LanguageCon.com.Seq P c2, s)) lc1 @ lc2\"\n            have f2: \"i < length l \\<and> fst (l ! i) = c2 \\<and> (\\<forall>n. \\<not> n < i \\<or> fst (l ! n) \\<noteq> c2)\"\n              using a0 by blast\n            have f3: \"(LanguageCon.com.Seq (fst (lc1 ! i)) c2, snd (lc1 ! i)) = lift c2 (lc1 ! i)\"\n              by (simp add: case_prod_unfold lift_def)            \n            then have \"fst (l ! length lc1) = c2\"\n              using a1 by (simp add: cp_def nth_append)\n            thus ?thesis\n              using f3 f2 by (metis (no_types) nth_append cp_lc1 fst_conv length_map lift_nth linorder_neqE_nat seq_and_if_not_eq(4))\n         qed                  \n         have lc2_l:\"\\<forall>j<length lc2. lc2!j=l!(i+j)\"\n           using cp_lc1 length_c1_map i_map a0\n           by (metis nth_append_length_plus)                                                             \n         have lc1_not_empty:\"lc1 \\<noteq> []\"\n           using cp cp_lc1 unfolding cp_def by fastforce      \n         have lc2_not_empty:\"lc2 \\<noteq> []\"\n           using cp_def cp_lc1 cptn.simps by blast             \n         have l_is:\"s2= snd (last lc1)\"\n         using cp_lc1 li a0 lc1_not_empty unfolding cp_def\n          proof -\n            assume a1: \"(\\<Gamma>, lc1) \\<in> {(\\<Gamma>1, l). l ! 0 = (c1, s) \\<and> (\\<Gamma>, l) \\<in> cptn \\<and> \\<Gamma>1 = \\<Gamma>} \\<and> (\\<Gamma>, lc2) \\<in> {(\\<Gamma>1, l). l ! 0 = (c2, snd (lc1 ! (i - 1))) \\<and> (\\<Gamma>, l) \\<in> cptn \\<and> \\<Gamma>1 = \\<Gamma>} \\<and> l = map (lift c2) lc1 @ lc2\"\n            then have \"(map (lift c2) lc1 @ lc2) ! length (map (lift c2) lc1) = l ! i\"\n              using i_map by force\n            have f2: \"(c2, s2) = lc2 ! 0\"\n              using li lc2_l lc2_not_empty by fastforce\n            have \"op - i = op - (length lc1)\"\n              using i_map by blast\n            then show ?thesis\n              using f2 a1 by (simp add: last_conv_nth lc1_not_empty)\n          qed \n         let ?m_lc1 = \"map (lift c2) lc1\"\n         (* let ?lm_lc1 = \"(length ?m_lc1)\"\n         let ?last_m_lc1 = \"?m_lc1!(?lm_lc1-1)\" *)                         \n         have last_m_lc1:\"l!(i-1) = (Seq (fst (last lc1)) c2,s2)\"\n         proof -\n           have a000:\"\\<forall>p c. (LanguageCon.com.Seq (fst p) c, snd p) = lift c p\"\n             using Cons_lift by force\n           then show ?thesis\n           proof -\n             have \"length (map (lift c2) lc1) = i\"\n               using i_map by fastforce\n             then show ?thesis\n               by (metis (no_types) One_nat_def l_is a000 cp_lc1 diff_less last_conv_nth last_map lc1_not_empty length_c1_map length_greater_0_conv less_Suc0 nth_append)\n           qed            \n         qed  \n         have last_mcl1_not_F:\"snd (last ?m_lc1) \\<notin> Fault ` F\"                 \n         proof -\n          have \"map (lift c2) lc1 \\<noteq> []\"\n            by (metis lc1_not_empty list.map_disc_iff)\n          then show ?thesis\n            by (metis (full_types) One_nat_def i_not_fault l_is last_conv_nth last_snd lc1_not_empty li snd_conv)\n         qed        \n         have map_cp:\"(\\<Gamma>,?m_lc1) \\<in> cp \\<Gamma> (Seq c1 c2) s\"               \n         proof -\n           have f1: \"lc1 ! 0 = (c1, s) \\<and> (\\<Gamma>, lc1) \\<in> cptn \\<and> \\<Gamma> = \\<Gamma>\"\n             using cp_lc1 cp_def by blast\n           then have f2: \"(\\<Gamma>, ?m_lc1) \\<in> cptn\" using lc1_not_empty\n             by (meson lift_is_cptn)                \n           then show ?thesis\n             using f2 f1 lc1_not_empty by (simp add: cp_def lift_def)\n         qed\n         also have map_assum:\"(\\<Gamma>,?m_lc1) \\<in> assum (p,R) F\" \n           using sub_assum a10 a11 \\<Gamma>1 cp_lc1 lc1_not_empty \n           by (metis SmallStepCon.nth_tl map_is_Nil_conv)\n         ultimately have \"((\\<Gamma>,lc1) \\<in> assum(p, R) F)\"  \n           using \\<Gamma>1 assum_map using assum_map cp_lc1 by blast                          \n         then have lc1_comm:\"(\\<Gamma>,lc1) \\<in> comm(G, (q,a)) F\"  \n           using a1 cp_lc1 by (meson IntI com_validity_def contra_subsetD)\n         then have m_lc1_comm:\"(\\<Gamma>,?m_lc1) \\<in> comm(G, (q,a)) F\"\n           using map_cp map_assum comm_map cp_lc1 by fastforce         \n         then have i_step:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!(i-1)) \\<rightarrow> (l!i)\"\n         proof -\n           have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!(i-1)) \\<rightarrow>\\<^sub>c\\<^sub>e (l!(i))\"\n           proof -\n             have f1: \"\\<forall>n na. \\<not> n < na \\<or> Suc (na - Suc n) = na - n\"\n               by (meson Suc_diff_Suc)\n             have \"map (lift c2) lc1 \\<noteq> []\"\n               by (metis lc1_not_empty map_is_Nil_conv)\n             then have f2: \"0 < length (map (lift c2) lc1)\"\n               by (meson length_greater_0_conv)             \n             then have \"length (map (lift c2) lc1) - 1 + 1 < length (map (lift c2) lc1 @ lc2)\"\n               using f2 lc2_not_empty by simp\n             then show ?thesis\n             using f2 f1\n              proof -\n                have \"0 < i\"\n                  using f2 i_map by blast\n                then show ?thesis\n                  by (metis (no_types) One_nat_def Suc_diff_1 a0 add.right_neutral add_Suc_right cp cptn_tran_ce_i)\n              qed \n           qed \n           moreover have \"\\<not>\\<Gamma>\\<turnstile>\\<^sub>c(l!(i-1)) \\<rightarrow>\\<^sub>e (l!i)\"           \n             using li last_m_lc1\n             by (metis (no_types, lifting) env_c_c' seq_and_if_not_eq(4))\n           ultimately show ?thesis using step_ce_elim_cases by blast\n         qed         \n         then have step:\"\\<Gamma>\\<turnstile>\\<^sub>c(Seq (fst (last lc1)) c2,s2) \\<rightarrow> (c2, s2)\"\n           using last_m_lc1  li by fastforce\n         then obtain s2' where \n           last_lc1:\"fst (last lc1) = Skip \\<or> \n            fst (last lc1) = Throw \\<and> (s2 = Normal s2')\" \n           using seq_skip_throw by blast    \n         have final:\"final (last lc1)\" \n           using last_lc1 l_is unfolding final_def by auto\n(* look here for the property *******************************************************************************)\n         have normal_last:\"fst (last lc1) = Skip \\<and> snd (last lc1) \\<in> Normal ` q \\<or>\n                        fst (last lc1) = Throw \\<and> snd (last lc1) \\<in> Normal ` (a)\" \n         proof -         \n           have \"snd (last lc1) \\<notin> Fault ` F\"\n             using i_not_fault l_is li by auto\n           then show ?thesis\n             using final comm_dest2 lc1_comm by blast\n         qed\n         obtain s2' where lastlc1_normal:\"snd (last lc1) = Normal s2'\" \n           using normal_last by blast\n         then have Normals2:\"s2 = Normal s2'\" by (simp add: l_is ) \n         have Gs2':\"(Normal s2', Normal s2')\\<in>G\" using a5 by auto                     \n         have concl:\n           \"(\\<forall>i. Suc i<length l \\<longrightarrow> \n           \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                                    \n             (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n         proof-\n         { fix k \n           assume a00:\"Suc k<length l\" and\n            a21:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\" \n            have i_m_l:\"\\<forall>j <i . l!j = ?m_lc1!j\"             \n            proof -\n              have \"map (lift c2) lc1 \\<noteq> []\"\n                by (meson lc1_not_empty list.map_disc_iff)\n              then show ?thesis \n                using cp_lc1 i_map length_c1_map by (fastforce simp:nth_append)              \n            qed \n            have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n            proof (cases \"Suc k< i\")\n              case True \n              then have a11': \"\\<Gamma>\\<turnstile>\\<^sub>c(?m_lc1!k)  \\<rightarrow> (?m_lc1!(Suc k))\" \n                using a11 i_m_l True\n              proof -\n                have \"\\<forall>n na. \\<not> 0 < n - Suc na \\<or> na < n \"\n                  using diff_Suc_eq_diff_pred zero_less_diff by presburger\n                then show ?thesis using True a21 i_m_l by force                  \n              qed                                                             \n              have \"Suc k < length ?m_lc1\" using True i_map length_c1_map by metis\n              then have \"(snd(?m_lc1!k), snd(?m_lc1!(Suc k))) \\<in> G\"\n              using a11' last_mcl1_not_F  m_lc1_comm True i_map length_c1_map \n                    comm_dest1[of \\<Gamma>]\n                by blast\n              thus ?thesis using i_m_l using True by fastforce \n            next\n              case False                                            \n              have \"(Suc k=i) \\<or> (Suc k>i)\" using False by auto\n              thus ?thesis \n              proof\n              { assume suck:\"(Suc k=i)\" \n                then have k:\"k=i-1\" by auto                                                            \n                then show \"(snd (l!k), snd (l!Suc k)) \\<in> G\"               \n                proof -\n                  have \"snd (l!Suc k) = Normal s2'\" \n                    using Normals2 suck li by auto     \n                  moreover have \"snd (l ! k) = Normal s2'\"   \n                    using Normals2 k last_m_lc1 by fastforce                 \n                  moreover have \"\\<exists>p. p \\<in> G \"\n                    by (meson  case_prod_conv mem_Collect_eq Gs2')\n                  ultimately show ?thesis using suck k Normals2\n                    using Gs2'  by force                       \n                qed\n              }\n              next\n              { \n                assume a001:\"Suc k>i\"\n                then have k:\"k\\<ge>i\" by fastforce\n                then obtain k' where k':\"k=i+k'\" \n                  using add.commute le_Suc_ex by blast\n                {assume throw:\"c2=Throw \\<and> fst (last lc1) = Throw\"\n                 then have s2_in:\"s2' \\<in> a\" \n                   using Normals2 i_map normal_last li lastlc1_normal \n                   using image_iff snd_conv xstate.inject(1) by auto\n                \n                 then have \"\\<forall>k. k\\<ge>i \\<and> (Suc k < length l) \\<longrightarrow> \n                            \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n                  using Normals2 li lastlc1_normal a21 a001 a00 a4\n                        a0 throw env_tran_right only_one_component_tran_j snd_conv \n                   by (metis  cp env_tran_right)\n                  then have ?thesis using a21 a001 k a00 by blast                                  \n                }  note left=this\n                {assume \"\\<not>(c2=Throw \\<and> fst (last lc1) = Throw)\"\n                 then have \"fst (last lc1) = Skip\"\n                   using last_m_lc1 last_lc1\n                   by (metis step a0 l_is li prod.collapse stepc_Normal_elim_cases(11) stepc_Normal_elim_cases(5))                 \n                 then have s2_normal:\"s2 \\<in> Normal ` q\" \n                   using normal_last lastlc1_normal Normals2\n                   by fastforce\n                 have length_lc2:\"length l=i+length lc2\" \n                       using i_map cp_lc1 by fastforce\n                 have \"(\\<Gamma>,lc2) \\<in>  assum (q,R) F\" \n                 proof -\n                   have left:\"snd (lc2!0) \\<in> Normal ` q\" \n                     using li lc2_l s2_normal lc2_not_empty by fastforce \n                   {\n                     fix j\n                     assume j_len:\"Suc j<length lc2\" and\n                            j_step:\"\\<Gamma>\\<turnstile>\\<^sub>c(lc2!j)  \\<rightarrow>\\<^sub>e (lc2!(Suc j))\"\n                     \n                     then have suc_len:\"Suc (i + j)<length l\" using j_len length_lc2\n                       by fastforce\n                     also then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!(i+j))  \\<rightarrow>\\<^sub>e (l! (Suc (i+ j)))\"\n                        using lc2_l j_step j_len by fastforce\n                     ultimately have \"(snd(lc2!j), snd(lc2!(Suc j))) \\<in> R\"\n                        using assum suc_len lc2_l j_len cp by fastforce \n                   }\n                   then show ?thesis using left \n                     unfolding assum_def by fastforce\n                 qed\n                 also have \"(\\<Gamma>,lc2) \\<in> cp \\<Gamma> c2 s2\"\n                   using cp_lc1 i_map l_is last_conv_nth lc1_not_empty by fastforce\n                 ultimately have comm_lc2:\"(\\<Gamma>,lc2) \\<in>  comm (G, (r,a)) F\"\n                   using a3 unfolding com_validity_def by auto\n                 have lc2_last_f:\"snd (last lc2)\\<notin> Fault ` F\" \n                   using lc2_l lc2_not_empty l_f cp_lc1 by fastforce\n                 have suck':\"Suc k' < length lc2\" \n                   using k' a00 length_lc2 by arith\n                 moreover then have \"\\<Gamma>\\<turnstile>\\<^sub>c(lc2!k')  \\<rightarrow> (lc2!(Suc k'))\"  \n                   using k' lc2_l a21 by fastforce\n                 ultimately have \"(snd (lc2! k'), snd (lc2 ! Suc k')) \\<in> G\"\n                   using comm_lc2 lc2_last_f comm_dest1[of \\<Gamma> lc2 G r a F k'] \n                   by blast\n                 then have ?thesis using suck' lc2_l k' by fastforce\n                }                    \n                then show ?thesis using left by auto                 \n              }\n              qed \n            qed\n          } thus ?thesis by auto \n         qed note left=this\n         have right:\"(final (last l)  \\<longrightarrow>                    \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal `  r)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` a))\"\n         proof -\n         { assume final_l:\"final (last l)\" \n           have eq_last_lc2_l:\"last l=last lc2\" by (simp add: cp_lc1 lc2_not_empty)\n           then have final_lc2:\"final (last lc2)\" using final_l by auto\n           {\n             assume lst_lc1_throw:\"fst (last lc1) = Throw\"                        \n             then have c2_throw:\"c2 = Throw\" \n               using lst_lc1_throw step lastlc1_normal stepc_elim_cases_Seq_skip_c2\n               by fastforce                                                                  \n             have s2_a:\"s2 \\<in> Normal ` (a)\"\n               using normal_last \n               by (simp add: lst_lc1_throw l_is)\n             have all_ev:\"\\<forall>k<length l - 1. k\\<ge>i \\<and> (Suc k < length l) \\<longrightarrow> \n                            \\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))\"\n             proof -\n               have s2_in:\"s2' \\<in> a\" \n                 using Normals2 i_map normal_last li lastlc1_normal \n                 using image_iff snd_conv xstate.inject(1) lst_lc1_throw by auto\n               then have \"\\<forall>k. k\\<ge>i \\<and> (Suc k < length l) \\<longrightarrow> \n                            \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n                 using Normals2 li lastlc1_normal   a4\n                     a0 c2_throw env_tran_right only_one_component_tran_j snd_conv \n                 by (metis  cp env_tran_right)  \n               thus ?thesis by (metis Suc_eq_plus1 cp cptn_tran_ce_i step_ce_elim_cases)      \n             qed    \n             then have Throw:\"fst (l!(length l - 1)) = Throw\"\n             using cp c2_throw a0 cptn_i_env_same_prog[of \\<Gamma> l \"((length l)-1)\" i] \n               by fastforce                            \n             then have \"snd (l!(length l - 1)) \\<in> Normal ` (a) \\<and> fst (l!(length l - 1)) = Throw\"\n               using  all_ev a0 s2_a li a4 env_tran_right stability[of a R l i \"(length l) -1\" _ \\<Gamma>] Throw \n               by (metis One_nat_def Suc_pred length_greater_0_conv \n                         lessI linorder_not_less list.size(3) \n                         not_less0 not_less_eq_eq snd_conv)                              \n             then have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal `  r)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a))\" \n              using a0 by (metis last_conv_nth list.size(3) not_less0)                           \n          }  note left = this\n          {  assume \"fst (last lc1) = Skip\"                 \n             then have s2_normal:\"s2 \\<in> Normal ` q\" \n               using normal_last lastlc1_normal Normals2\n               by fastforce\n             have length_lc2:\"length l=i+length lc2\" \n                   using i_map cp_lc1 by fastforce\n             have \"(\\<Gamma>,lc2) \\<in>  assum (q,R) F\" \n             proof -\n               have left:\"snd (lc2!0) \\<in> Normal ` q\" \n                 using li lc2_l s2_normal lc2_not_empty by fastforce \n               {\n                 fix j\n                 assume j_len:\"Suc j<length lc2\" and\n                        j_step:\"\\<Gamma>\\<turnstile>\\<^sub>c(lc2!j)  \\<rightarrow>\\<^sub>e (lc2!(Suc j))\"                 \n                 then have suc_len:\"Suc (i + j)<length l\" using j_len length_lc2\n                   by fastforce\n                 also then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!(i+j))  \\<rightarrow>\\<^sub>e (l! (Suc (i+ j)))\"\n                    using lc2_l j_step j_len by fastforce\n                 ultimately have \"(snd(lc2!j), snd(lc2!(Suc j))) \\<in> R\"\n                    using assum suc_len lc2_l j_len cp by fastforce \n               }\n               then show ?thesis using left \n                 unfolding assum_def by fastforce\n             qed\n             also have \"(\\<Gamma>,lc2) \\<in> cp \\<Gamma> c2 s2\"\n               using cp_lc1 i_map l_is last_conv_nth lc1_not_empty by fastforce\n             ultimately have comm_lc2:\"(\\<Gamma>,lc2) \\<in>  comm (G, (r,a)) F\"\n               using a3 unfolding com_validity_def by auto\n             have lc2_last_f:\"snd (last lc2)\\<notin> Fault ` F\" \n               using lc2_l lc2_not_empty l_f cp_lc1 by fastforce             \n             then have \"((fst (last lc2) = Skip \\<and> \n                    snd (last lc2) \\<in> Normal `  r)) \\<or>\n                    (fst (last lc2) = Throw \\<and> \n                    snd (last lc2) \\<in> Normal ` a)\" \n             using final_lc2 comm_lc2 unfolding comm_def by auto\n             then have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal `  r)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` a)\" \n             using eq_last_lc2_l by auto\n          }\n          then have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` r)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` a)\" \n            using left using last_lc1 by auto\n        } thus ?thesis by auto qed         \n     thus ?thesis using left l_f \\<Gamma>1 unfolding comm_def by force       \n       qed             \n     } thus ?thesis using \\<Gamma>1 unfolding comm_def by auto qed\n   } thus ?thesis by auto qed \n } thus ?thesis by (simp add: com_validity_def[of \\<Gamma>] com_cvalidity_def) \nqed\n\nlemma Catch_env_P:assumes a0:\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch P Q,s) \\<rightarrow>\\<^sub>e (Catch P Q,t)\"\n      shows \"\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow>\\<^sub>e (P,t)\"\nusing a0\nby (metis env_not_normal_s snormal_enviroment)\n\nlemma map_catch_eq_state:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Catch c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \" and\n  a2:\"l1=map (lift_catch c2) l2\"\nshows\n  \"\\<forall>i<length l1. snd (l1!i) = snd (l2!i)\"\nusing a0 a1 a2 unfolding cp_def\nby (simp add: snd_lift_catch) \n\nlemma map_eq_catch_c:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Catch c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \" and\n  a2:\"l1=map (lift_catch c2) l2\"\nshows\n  \"\\<forall>i<length l1. fst (l1!i) = Catch (fst (l2!i)) c2\"\nproof -\n  {fix i\n  assume a3:\"i<length l1\"\n  have \"fst (l1!i) = Catch (fst (l2!i)) c2\"\n  using a0 a1 a2 a3 unfolding lift_catch_def\n    by (simp add: case_prod_unfold) \n  }thus ?thesis by auto\nqed \n\nlemma same_env_catch_c:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Catch c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \" and\n  a2:\"l1=map (lift_catch c2) l2\"\nshows\n\"\\<forall>i. Suc i<length l2 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow>\\<^sub>e (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow>\\<^sub>e (l1!(Suc i))\" \nproof -\n  have a0a:\"(\\<Gamma>,l1) \\<in>cptn \\<and> l1!0 = ((Catch c1 c2),s)\" \n    using a0 unfolding cp_def by blast\n  have a1a: \"(\\<Gamma>,l2) \\<in>cptn \\<and> l2!0 = (c1,s)\"\n    using a1 unfolding cp_def by blast\n  {\n    fix i\n    assume a3:\"Suc i< length l2\"\n    have \"\\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow>\\<^sub>e (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow>\\<^sub>e (l1!(Suc i))\"\n    proof\n    {\n      assume a4:\"\\<Gamma>\\<turnstile>\\<^sub>c l2 ! i \\<rightarrow>\\<^sub>e l2 ! Suc i\"\n      obtain c1i s1i c1si s1si where l1prod:\"l1 ! i=(c1i,s1i) \\<and> l1!Suc i = (c1si,s1si)\"\n        by fastforce\n      obtain c2i s2i c2si s2si where l2prod:\"l2 ! i=(c2i,s2i) \\<and> l2!Suc i = (c2si,s2si)\"\n        by fastforce\n      then have \"c1i = (Catch c2i c2) \\<and> c1si = (Catch c2si c2)\"\n        using  a0 a1 a2 a3 a4  l1prod \n        by (simp add: lift_catch_def)         \n      also have \"s2i=s1i \\<and> s2si=s1si\"\n        using  a0 a1 a4  a2 a3 l2prod  l1prod\n        by (simp add: lift_catch_def)         \n      ultimately show \"\\<Gamma>\\<turnstile>\\<^sub>c l1 ! i \\<rightarrow>\\<^sub>e (l1 ! Suc i)\" \n        using a4 l1prod l2prod\n        by (metis Env_n env_c_c' env_not_normal_s step_e.Env)\n    } \n    {\n      assume a4:\"\\<Gamma>\\<turnstile>\\<^sub>c l1 ! i \\<rightarrow>\\<^sub>e l1 ! Suc i\"\n      obtain c1i s1i c1si s1si where l1prod:\"l1 ! i=(c1i,s1i) \\<and> l1!Suc i = (c1si,s1si)\"\n        by fastforce\n      obtain c2i s2i c2si s2si where l2prod:\"l2 ! i=(c2i,s2i) \\<and> l2!Suc i = (c2si,s2si)\"\n        by fastforce\n      then have \"c1i = (Catch c2i c2) \\<and> c1si = (Catch c2si c2)\"\n        using  a0 a1 a2 a3 a4  l1prod\n        by (simp add: lift_catch_def)\n      also have \"s2i=s1i \\<and> s2si=s1si\"\n        using  a0 a1 a4  a2 a3 l2prod l1prod\n        by (simp add: lift_catch_def)      \n      ultimately show \"\\<Gamma>\\<turnstile>\\<^sub>c l2 ! i \\<rightarrow>\\<^sub>e (l2 ! Suc i)\" \n        using a4 l1prod l2prod       \n        by (metis Env_n LanguageCon.com.inject(9) env_c_c' env_not_normal_s step_e.Env)   \n    }\n    qed\n   } \n  thus ?thesis by auto\nqed\n\n\nlemma same_comp_catch_c:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Catch c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \" and\n  a2:\"l1=map (lift_catch c2) l2\"\nshows\n\"\\<forall>i. Suc i<length l2 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow> (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow> (l1!(Suc i))\" \nproof -\n  have a0a:\"(\\<Gamma>,l1) \\<in>cptn \\<and> l1!0 = ((Catch c1 c2),s)\" \n    using a0 unfolding cp_def by blast\n  have a1a: \"(\\<Gamma>,l2) \\<in>cptn \\<and> l2!0 = (c1,s)\"\n    using a1 unfolding cp_def by blast\n  {\n    fix i\n    assume a3:\"Suc i< length l2\"\n    have \"\\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow> (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow> (l1!(Suc i))\"\n    proof\n    {\n      assume a4:\"\\<Gamma>\\<turnstile>\\<^sub>c l2 ! i \\<rightarrow> l2 ! Suc i\"\n      obtain c1i s1i c1si s1si where l1prod:\"l1 ! i=(c1i,s1i) \\<and> l1!Suc i = (c1si,s1si)\"\n        by fastforce\n      obtain c2i s2i c2si s2si where l2prod:\"l2 ! i=(c2i,s2i) \\<and> l2!Suc i = (c2si,s2si)\"\n        by fastforce\n      then have \"c1i = (Catch c2i c2) \\<and> c1si = (Catch c2si c2)\"\n        using  a0 a1 a2 a3 a4  map_eq_catch_c l1prod\n        by (simp add: lift_catch_def)\n      also have \"s2i=s1i \\<and> s2si=s1si\"\n        using  a0 a1 a4  a2 a3 l2prod map_eq_state l1prod\n        by (simp add: lift_catch_def)          \n      ultimately show \"\\<Gamma>\\<turnstile>\\<^sub>c l1 ! i \\<rightarrow> (l1 ! Suc i)\" \n        using a4 l1prod l2prod\n        by (simp add: Catchc)        \n    } \n    {\n      assume a4:\"\\<Gamma>\\<turnstile>\\<^sub>c l1 ! i \\<rightarrow> l1 ! Suc i\"\n      obtain c1i s1i c1si s1si where l1prod:\"l1 ! i=(c1i,s1i) \\<and> l1!Suc i = (c1si,s1si)\"\n        by fastforce\n      obtain c2i s2i c2si s2si where l2prod:\"l2 ! i=(c2i,s2i) \\<and> l2!Suc i = (c2si,s2si)\"\n        by fastforce\n      then have \"c1i = (Catch c2i c2) \\<and> c1si = (Catch c2si c2)\"\n        using  a0 a1 a2 a3 a4  l1prod\n       by (simp add: lift_catch_def)          \n      also have \"s2i=s1i \\<and> s2si=s1si\"\n        using  a0 a1 a4  a2 a3 l2prod  l1prod\n        by (simp add: lift_catch_def)          \n      ultimately show \"\\<Gamma>\\<turnstile>\\<^sub>c l2 ! i \\<rightarrow> (l2 ! Suc i)\" \n        using a4 l1prod l2prod stepc_elim_cases_Catch_Catch Catch_not_c\n        by (metis (no_types))\n    }\n    qed\n   } \n  thus ?thesis by auto\nqed\n\nlemma assum_map_catch:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Catch c1 c2) s) \\<and> ((\\<Gamma>,l1) \\<in> assum(p, R) F)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \" and\n  a2:\"l1=map (lift_catch c2) l2\"  \nshows\n  \"((\\<Gamma>,l2) \\<in> assum(p, R) F)\"\nproof -\n  have a3: \"\\<forall>i. Suc i<length l2 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow>\\<^sub>e (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow>\\<^sub>e (l1!(Suc i))\" \n    using a0 a1 a2 same_env_catch_c by fastforce\n  have pair_\\<Gamma>l1:\"fst (\\<Gamma>,l1) = \\<Gamma> \\<and> snd (\\<Gamma>,l1) = l1\" by fastforce\n  have pair_\\<Gamma>l2:\"fst (\\<Gamma>,l2) = \\<Gamma> \\<and> snd (\\<Gamma>,l2) = l2\" by fastforce\n  have drop_k_s:\"l2!0 = (c1,s)\" using a1 cp_def by blast\n  have eq_length:\"length l1 = length l2\" using a2 by auto\n  obtain s' where normal_s:\"s = Normal s'\" \n    using  a0  unfolding cp_def   assum_def  by fastforce\n  then have p1:\"s'\\<in>p\" using a0 unfolding cp_def assum_def by fastforce  \n  show ?thesis \n  proof -    \n    let ?c= \"(\\<Gamma>,l2)\"\n    have l:\"snd((snd ?c!0)) \\<in> Normal ` (p)\"\n     using p1 drop_k_s a1 normal_s unfolding cp_def by auto\n    {fix i\n     assume a00:\"Suc i<length (snd ?c)\" \n     assume a11:\"(fst ?c)\\<turnstile>\\<^sub>c((snd ?c)!i)  \\<rightarrow>\\<^sub>e ((snd ?c)!(Suc i))\"\n     have \"(snd((snd ?c)!i), snd((snd ?c)!(Suc i))) \\<in> R\"\n     using a0 a1 a2 a3 map_catch_eq_state unfolding assum_def \n     using a00 a11 eq_length by fastforce\n    } thus \"(\\<Gamma>, l2) \\<in> assum (p, R) F\" \n      using l unfolding assum_def by fastforce  \n  qed  \nqed\n\nlemma comm_map'_catch:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Catch c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \\<and> (\\<Gamma>, l2)\\<in> comm(G, (q,a)) F\" and\n  a2:\"l1=map (lift_catch c2) l2\" \nshows\n  \"snd (last l1) \\<notin> Fault ` F  \\<longrightarrow>(Suc k < length l1 \\<longrightarrow>\n       \\<Gamma>\\<turnstile>\\<^sub>c(l1!k)  \\<rightarrow> (l1!(Suc k)) \\<longrightarrow>        \n       (snd(l1!k), snd(l1!(Suc k))) \\<in> G) \\<and> \n   (fst (last l1) = (Catch c c2) \\<and> final (c, snd (last l1)) \\<longrightarrow>     \n      (fst (last l1) = (Catch Skip c2) \\<and> \n        (snd (last  l1) \\<in> Normal ` q) \\<or>\n      (fst (last l1) = (Catch Throw c2) \\<and> \n        snd (last l1) \\<in> Normal ` (a))))\n     \"\nproof -\n  have a3:\"\\<forall>i. Suc i<length l2 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow> (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow> (l1!(Suc i))\" \n    using a0 a1 a2 same_comp_catch_c\n    by fastforce\n  have pair_\\<Gamma>l1:\"fst (\\<Gamma>,l1) = \\<Gamma> \\<and> snd (\\<Gamma>,l1) = l1\" by fastforce\n  have pair_\\<Gamma>l2:\"fst (\\<Gamma>,l2) = \\<Gamma> \\<and> snd (\\<Gamma>,l2) = l2\" by fastforce\n  have drop_k_s:\"l2!0 = (c1,s)\" using a1 cp_def by blast\n  have eq_length:\"length l1 = length l2\" using a2 by auto\n  have len0:\"length l2>0\" using a1 unfolding cp_def \n      using cptn.simps  by fastforce   \n  then have len0:\"length l1>0\" using eq_length by auto\n  then have l1_not_empty:\"l1\\<noteq>[]\" by auto\n  then have l2_not_empty:\"l2 \\<noteq> []\" using a2 by blast       \n   have last_lenl1:\"last l1 = l1!((length l1) -1)\" \n        using last_conv_nth l1_not_empty by auto\n  have last_lenl2:\"last l2 = l2!((length l2) -1)\" \n       using last_conv_nth l2_not_empty by auto \n  have a03:\"snd (last l2) \\<notin> Fault ` F  \\<longrightarrow>(\\<forall>i ns ns'.                 \n               Suc i<length (snd (\\<Gamma>, l2)) \\<longrightarrow> \n               fst (\\<Gamma>, l2)\\<turnstile>\\<^sub>c((snd (\\<Gamma>, l2))!i)  \\<rightarrow> ((snd (\\<Gamma>, l2))!(Suc i)) \\<longrightarrow>                               \n                 (snd((snd (\\<Gamma>, l2))!i), snd((snd (\\<Gamma>, l2))!(Suc i))) \\<in> G) \\<and> \n               (final (last (snd (\\<Gamma>, l2)))  \\<longrightarrow>                 \n                  ((fst (last (snd (\\<Gamma>, l2))) = Skip \\<and> \n                    snd (last (snd (\\<Gamma>, l2))) \\<in> Normal ` q)) \\<or>\n                  (fst (last (snd (\\<Gamma>, l2))) = Throw \\<and> \n                    snd (last (snd (\\<Gamma>, l2))) \\<in> Normal ` (a)))\"\n  using a1 unfolding comm_def by fastforce\n  show ?thesis unfolding comm_def \n  proof -\n  { fix k ns ns'\n    assume a00a:\"snd (last l1) \\<notin> Fault ` F\"\n    assume a00:\"Suc k < length l1\"    \n    then have \"k \\<le> length l1\" using a2 by fastforce    \n    have a00:\"Suc k < length l2\" using eq_length a00 by fastforce\n    then have a00a:\"snd (last l2) \\<notin> Fault ` F\"\n    proof-\n      have \"snd (l1!((length l1) -1)) = snd (l2!((length l2) -1))\"      \n        using a2 a1 a0  map_catch_eq_state eq_length l2_not_empty last_snd \n        by fastforce \n      then have \"snd(last l2) = snd (last l1)\"\n        using last_lenl1 last_lenl2 by auto\n      thus ?thesis using a00a by auto\n    qed\n    then have \"snd (last l1) \\<notin> Fault ` F \\<longrightarrow>\\<Gamma>\\<turnstile>\\<^sub>c(l1!k)  \\<rightarrow> (l1!(Suc k)) \\<longrightarrow>       \n      (snd((snd (\\<Gamma>, l1))!k), snd((snd (\\<Gamma>, l1))!(Suc k))) \\<in> G\"\n    using  pair_\\<Gamma>l1 pair_\\<Gamma>l2 a00  a03 a3  eq_length a00a\n     by (metis Suc_lessD a0 a1 a2 map_catch_eq_state)\n  } note l=this\n  {\n    assume a00: \"fst (last l1) = (Catch c c2) \\<and> final (c, snd (last l1))\" and\n           a01:\"snd (last (l1)) \\<notin> Fault ` F\"\n    then have c:\"c=Skip \\<or> c = Throw\"\n     unfolding final_def by auto    \n    then have fst_last_l2:\"fst (last l2) = c\"                               \n      using  last_lenl1 a00 l1_not_empty eq_length len0 a2 last_conv_nth last_lift_catch \n      by fastforce      \n    also have last_eq:\"snd (last l2) = snd (last l1)\"      \n      using l2_not_empty a2 last_conv_nth last_lenl1 last_snd_catch\n      by fastforce\n    ultimately have \"final (fst (last l2),snd (last l2))\" \n     using a00 by auto\n    then have \"final (last l2)\" by auto\n    also have \"snd (last (l2)) \\<notin> Fault ` F\"\n       using  last_eq a01 by auto\n    ultimately have \"(fst (last  l2)) = Skip \\<and> \n                    snd (last  l2) \\<in> Normal ` q \\<or>\n                  (fst (last l2) = Throw \\<and> \n                    snd (last l2) \\<in> Normal ` (a))\"\n    using a03 by auto\n    then have \"(fst (last l1) = (Catch Skip c2) \\<and> \n                    snd (last  l1) \\<in> Normal ` q) \\<or>\n                  (fst (last l1) = (Catch Throw c2) \\<and> \n                    snd (last l1) \\<in> Normal ` (a))\"\n    using last_eq fst_last_l2 a00 by force\n  }\n  thus ?thesis using l by auto qed\nqed\n\nlemma comm_map''_catch:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Catch c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \\<and> (\\<Gamma>, l2)\\<in> comm(G, (q,a)) F\" and\n  a2:\"l1=map (lift_catch c2) l2\" \nshows\n  \"snd (last l1) \\<notin> Fault ` F \\<longrightarrow> ((Suc k < length l1 \\<longrightarrow>\n       \\<Gamma>\\<turnstile>\\<^sub>c(l1!k)  \\<rightarrow> (l1!(Suc k)) \\<longrightarrow>        \n       (snd(l1!k), snd(l1!(Suc k))) \\<in>  G) \\<and> \n   (final (last l1) \\<longrightarrow>     \n      (fst (last l1) = Skip \\<and> \n        (snd (last  l1) \\<in> Normal ` r) \\<or>\n      (fst (last l1) = Throw \\<and> \n        snd (last l1) \\<in> Normal ` a))))\n     \"\nproof -\n  have a3:\"\\<forall>i. Suc i<length l2 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow> (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow> (l1!(Suc i))\" \n    using a0 a1 a2 same_comp_catch_c\n    by fastforce\n  have pair_\\<Gamma>l1:\"fst (\\<Gamma>,l1) = \\<Gamma> \\<and> snd (\\<Gamma>,l1) = l1\" by fastforce\n  have pair_\\<Gamma>l2:\"fst (\\<Gamma>,l2) = \\<Gamma> \\<and> snd (\\<Gamma>,l2) = l2\" by fastforce\n  have drop_k_s:\"l2!0 = (c1,s)\" using a1 cp_def by blast\n   have eq_length:\"length l1 = length l2\" using a2 by auto\n  have len0:\"length l2>0\" using a1 unfolding cp_def \n      using cptn.simps  by fastforce   \n  then have len0:\"length l1>0\" using eq_length by auto\n  then have l1_not_empty:\"l1\\<noteq>[]\" by auto\n  then have l2_not_empty:\"l2 \\<noteq> []\" using a2 by blast       \n  have last_lenl1:\"last l1 = l1!((length l1) -1)\" \n        using last_conv_nth l1_not_empty by auto\n  have last_lenl2:\"last l2 = l2!((length l2) -1)\" \n       using last_conv_nth l2_not_empty by auto \n  have a03:\"snd (last l2) \\<notin> Fault ` F \\<longrightarrow>(\\<forall>i ns ns'.                 \n               Suc i<length (snd (\\<Gamma>, l2)) \\<longrightarrow> \n               fst (\\<Gamma>, l2)\\<turnstile>\\<^sub>c((snd (\\<Gamma>, l2))!i)  \\<rightarrow> ((snd (\\<Gamma>, l2))!(Suc i)) \\<longrightarrow>                                              \n                 (snd((snd (\\<Gamma>, l2))!i), snd((snd (\\<Gamma>, l2))!(Suc i))) \\<in> G) \\<and> \n               (final (last (snd (\\<Gamma>, l2)))  \\<longrightarrow>                 \n                  ((fst (last (snd (\\<Gamma>, l2))) = Skip \\<and> \n                    snd (last (snd (\\<Gamma>, l2))) \\<in> Normal ` q)) \\<or>\n                  (fst (last (snd (\\<Gamma>, l2))) = Throw \\<and> \n                    snd (last (snd (\\<Gamma>, l2))) \\<in> Normal ` (a)))\"\n  using a1 unfolding comm_def by fastforce\n  show ?thesis unfolding comm_def \n  proof -\n  { fix k ns ns'\n    assume a00a:\"snd (last l1) \\<notin> Fault ` F\"\n    assume a00:\"Suc k < length l1\"    \n    then have \"k \\<le> length l1\" using a2 by fastforce    \n    have a00:\"Suc k < length l2\" using eq_length a00 by fastforce   \n    then have a00a:\"snd (last l2) \\<notin> Fault ` F\"\n    proof-\n      have \"snd (l1!((length l1) -1)) = snd (l2!((length l2) -1))\"      \n        using a2 a1 a0  map_catch_eq_state eq_length l2_not_empty last_snd \n        by fastforce \n      then have \"snd(last l2) = snd (last l1)\"\n        using last_lenl1 last_lenl2 by auto\n      thus ?thesis using a00a by auto\n    qed \n    then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l1!k)  \\<rightarrow> (l1!(Suc k)) \\<longrightarrow>          \n        (snd((snd (\\<Gamma>, l1))!k), snd((snd (\\<Gamma>, l1))!(Suc k))) \\<in> G\"\n       using  pair_\\<Gamma>l1 pair_\\<Gamma>l2 a00  a03 a3  eq_length a00a\n      by (metis (no_types,lifting) a2 Suc_lessD nth_map snd_lift_catch)\n    } note l= this\n    {\n     assume a00: \"final (last l1)\"           \n     then have c:\"fst (last l1)=Skip \\<or> fst (last l1) = Throw\"\n       unfolding final_def by auto \n     moreover have \"fst (last l1) = Catch (fst (last l2)) c2\" \n       using a2 last_lenl1 eq_length\n      proof -\n        have \"last l2 = l2 ! (length l2 - 1)\"\n          using l2_not_empty last_conv_nth by blast\n        then show ?thesis\n          by (metis One_nat_def a2 l2_not_empty last_lenl1 last_lift_catch)\n      qed\n      ultimately have False by simp  \n    } thus ?thesis using l  by auto qed\nqed\n\nlemma comm_map_catch:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Catch c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \\<and> (\\<Gamma>, l2)\\<in> comm(G, (q,a)) F\" and\n  a2:\"l1=map (lift_catch c2) l2\" \nshows\n  \"(\\<Gamma>, l1)\\<in> comm(G, (r,a)) F\"\nproof - \n  {fix i ns ns'\n   have \"snd (last l1) \\<notin> Fault ` F  \\<longrightarrow>(Suc i < length (l1) \\<longrightarrow>\n        \\<Gamma>\\<turnstile>\\<^sub>c (l1 ! i) \\<rightarrow> (l1 ! (Suc i)) \\<longrightarrow>       \n        (snd (l1 ! i), snd (l1 ! Suc i)) \\<in> G) \\<and>\n        (SmallStepCon.final (last l1) \\<longrightarrow>                  \n                   fst (last l1) = LanguageCon.com.Skip \\<and>\n                   snd (last l1) \\<in> Normal ` r \\<or>\n                   fst (last l1) = LanguageCon.com.Throw \\<and>\n                   snd (last l1) \\<in> Normal ` a) \"\n      using comm_map''_catch[of \\<Gamma> l1 c1 c2 s l2 G q a F i r] a0 a1 a2 \n      by fastforce\n   }  then show ?thesis using comm_def unfolding comm_def by force       \nqed\n\nlemma Catch_sound1: \nassumes\n  a0:\"(\\<Gamma>,x)\\<in>cptn_mod\" and\n  a1:\"x!0 = ((Catch P Q),s)\" and\n  a2:\"\\<forall>i<length x. fst (x!i)\\<noteq> Q\" and\n  a3:\"\\<not> final (last x)\" and\n  a4:\"env_tran_right \\<Gamma> x rely\"\nshows\n  \"\\<exists>xs. (\\<Gamma>,xs) \\<in> cp \\<Gamma> P s \\<and> x = map (lift_catch Q) xs\"\nusing a0 a1 a2 a3 a4\nproof (induct arbitrary: P s)\n  case (CptnModOne \\<Gamma> C s1)\n  then have \"(\\<Gamma>, [(P,s)]) \\<in> cp \\<Gamma> P s \\<and> [(C, s1)] = map (lift_catch Q) [(P,s)]\"\n    unfolding cp_def lift_catch_def  by (simp add: cptn.CptnOne) \n  thus ?case by fastforce\nnext\n  case (CptnModEnv \\<Gamma> C s1 t1 xsa)\n  then have C:\"C=Catch P Q\" unfolding lift_catch_def by fastforce\n  have \"\\<exists>xs. (\\<Gamma>, xs) \\<in> cp \\<Gamma> P t1 \\<and> (C, t1) # xsa = map (lift_catch Q) xs\"\n  proof -\n     have \"((C, t1) # xsa) ! 0 = (Catch P Q, t1)\" using C by auto\n     moreover have \"\\<forall>i<length ((C, t1) # xsa). fst (((C, t1) # xsa) ! i) \\<noteq> Q\"\n       using CptnModEnv(5) by fastforce\n     moreover have \"\\<not> SmallStepCon.final (last ((C, t1) # xsa))\" using CptnModEnv(6) \n       by fastforce\n     ultimately show ?thesis\n       using CptnModEnv(3) CptnModEnv(7) env_tran_tail by blast     \n  qed \n  then obtain xs where hi:\"(\\<Gamma>, xs) \\<in> cp \\<Gamma> P t1 \\<and> (C, t1) # xsa = map (lift_catch Q) xs\"\n    by fastforce\n  have s1_s:\"s1=s\" using  CptnModEnv unfolding cp_def by auto\n  obtain xsa' where xs:\"xs=((P,t1)#xsa') \\<and> (\\<Gamma>,((P,t1)#xsa'))\\<in>cptn \\<and> (C, t1) # xsa = map (lift_catch Q) ((P,t1)#xsa')\" \n    using hi  unfolding cp_def by fastforce\n  \n  have env_tran:\"\\<Gamma>\\<turnstile>\\<^sub>c(P,s1) \\<rightarrow>\\<^sub>e (P,t1)\" using CptnModEnv Catch_env_P by (metis fst_conv nth_Cons_0)  \n  then have \"(\\<Gamma>,(P,s1)#(P,t1)#xsa')\\<in>cptn\" using xs env_tran CptnEnv by fastforce  \n  then have \"(\\<Gamma>,(P,s1)#(P,t1)#xsa') \\<in> cp \\<Gamma> P s\" \n    using cp_def s1_s by fastforce\n  moreover have \"(C,s1)#(C, t1) # xsa = map (lift_catch Q) ((P,s1)#(P,t1)#xsa')\"\n    using xs C unfolding lift_catch_def by fastforce\n  ultimately show ?case by auto\nnext\n  case (CptnModSkip)\n  thus ?case by (metis SmallStepCon.redex_not_Catch fst_conv nth_Cons_0)\nnext\n  case (CptnModThrow)\n  thus ?case by (metis SmallStepCon.redex_not_Catch fst_conv nth_Cons_0)\nnext\n  case (CptnModCatch1 \\<Gamma> P0 sa xsa zs P1)\n  then have a1:\"LanguageCon.com.Catch P Q = LanguageCon.com.Catch P0 P1\"\n    by fastforce  \n  have f1: \"sa = s\"\n    using CptnModCatch1.prems(1) by force\n  have f2: \"P = P0 \\<and> Q = P1\" using a1 by auto\n  have \"(\\<Gamma>, (P0, sa) # xsa) \\<in> cptn\"\n    by (metis CptnModCatch1.hyps(1) cptn_eq_cptn_mod_set)\n  hence \"(\\<Gamma>, (P0, sa) # xsa) \\<in> cp \\<Gamma> P s\"\n    using f2 f1 by (simp add: cp_def)\n  thus ?case\n    using Cons_lift_catch CptnModCatch1.hyps(3) a1 by blast   \nnext\n case (CptnModCatch2 \\<Gamma> P1 sa xsa  ys zs Q1)\n  have \"final (last ((Skip, sa)# ys))\"\n  proof -\n    have cptn:\"(\\<Gamma>, (Skip,snd (last ((P1, sa) # xsa))) # ys) \\<in> cptn\" \n      using CptnModCatch2(4) by (simp add: cptn_eq_cptn_mod_set)\n    moreover have throw_0:\"((Skip,snd (last ((P1, sa) # xsa))) # ys)!0 = (Skip, snd (last ((P1, sa) # xsa))) \\<and> 0 < length((Skip, snd (last ((P1, sa) # xsa))) # ys)\"\n      by force         \n    moreover have last:\"last ((Skip,snd (last ((P1, sa) # xsa))) # ys) = \n                      ((Skip,snd (last ((P1, sa) # xsa))) # ys)!((length ((Skip,snd (last ((P1, sa) # xsa))) # ys)) - 1)\"\n      using last_conv_nth by auto\n    moreover have env_tran:\"env_tran_right \\<Gamma> ((Skip,snd (last ((P1, sa) # xsa))) # ys) rely\" \n      using  CptnModCatch2.hyps(6) CptnModCatch2.prems(4) env_tran_subl env_tran_tail by blast          \n    ultimately obtain st' where \"fst (last ((Skip,snd (last ((P1, sa) # xsa))) # ys)) = Skip \\<and>        \n                     snd (last ((Skip,snd (last ((P1, sa) # xsa))) # ys)) = Normal st'\" \n    using  CptnModCatch2 zero_skip_all_skip[of \\<Gamma> \"((Skip,snd (last ((P1, sa) # xsa))) # ys)\" \"(length ((Skip,snd (last ((P1, sa) # xsa))) # ys))-1\"]\n    proof -\n      have False\n        by (metis (no_types) One_nat_def SmallStepCon.final_def \\<open>(\\<Gamma>, (LanguageCon.com.Skip, snd (last ((P1, sa) # xsa))) # ys) \\<in> cptn \\<and> fst (((LanguageCon.com.Skip, snd (last ((P1, sa) # xsa))) # ys) ! 0) = LanguageCon.com.Skip \\<and> length ((LanguageCon.com.Skip, snd (last ((P1, sa) # xsa))) # ys) - 1 < length ((LanguageCon.com.Skip, snd (last ((P1, sa) # xsa))) # ys) \\<Longrightarrow> fst (((LanguageCon.com.Skip, snd (last ((P1, sa) # xsa))) # ys) ! (length ((LanguageCon.com.Skip, snd (last ((P1, sa) # xsa))) # ys) - 1)) = LanguageCon.com.Skip\\<close> \\<open>\\<not> SmallStepCon.final (last ((LanguageCon.com.Catch P1 Q1, sa) # zs))\\<close> \\<open>zs = map (lift_catch Q1) xsa @ (LanguageCon.com.Skip, snd (last ((P1, sa) # xsa))) # ys\\<close> append_is_Nil_conv cptn diff_Suc_Suc diff_zero fst_conv last last.simps last_appendR length_Cons lessI list.simps(3) throw_0)\n      then show ?thesis\n        by metis\n    qed\n    thus ?thesis using final_def by (metis fst_conv last.simps)       \n  qed\n  thus ?case \n    by (metis (no_types, lifting) CptnModCatch2.hyps(3) CptnModCatch2.hyps(6) CptnModCatch2.prems(3) SmallStepCon.final_def append_is_Nil_conv last.simps last_appendR list.simps(3) prod.collapse)     \nnext\n  case (CptnModCatch3 \\<Gamma> P0 sa xsa sa' P1 ys zs)\n  then have \"P0 = P \\<and> P1 = Q\" by auto\n  then obtain i where zs:\"fst (zs!i) = Q \\<and> (i< (length zs))\" \n    using CptnModCatch3\n    by (metis (no_types, lifting) add_diff_cancel_left' fst_conv length_Cons length_append nth_append_length zero_less_Suc zero_less_diff)    \n  then have \"Suc i< length ((Catch P0 P1,Normal sa)#zs)\" by fastforce\n  then have \"fst (((Catch P0 P1, Normal sa) # zs)!Suc i) = Q\" using zs by fastforce    \n  thus ?case using CptnModCatch3(9) zs by auto\nqed (auto)\n\nlemma Catch_sound2: \nassumes\n  a0:\"(\\<Gamma>,x)\\<in>cptn_mod\" and\n  a1:\"x!0 = ((Catch P Q),s)\" and\n  a2:\"\\<forall>i<length x. fst (x!i)\\<noteq> Q\" and\n  a3:\"fst (last x) = Skip\" and\n  a4:\"env_tran_right \\<Gamma> x rely\"\nshows\n  \"\\<exists>xs ys. (\\<Gamma>,xs) \\<in> cp \\<Gamma> P s \\<and> x = ((map (lift_catch Q) xs)@((Skip,snd(last xs))#ys))\"\nusing a0 a1 a2 a3 a4\nproof (induct arbitrary: P s)\n  case (CptnModOne \\<Gamma> C s1)\n  then have \"(\\<Gamma>, [(P,s)]) \\<in> cp \\<Gamma> P s \\<and> [(C, s1)] = map (lift Q) [(P,s)]@[(Throw, Normal s')]\"\n    unfolding cp_def lift_def  by (simp add: cptn.CptnOne) \n  thus ?case by fastforce\nnext\n  case (CptnModEnv \\<Gamma> C s1 t1 xsa)\n  then have C:\"C=Catch P Q\" unfolding lift_catch_def by fastforce\n  have \"\\<exists>xs ys. (\\<Gamma>, xs) \\<in> cp \\<Gamma> P t1 \\<and> (C, t1) # xsa = \n                map (lift_catch Q) xs@((Skip, snd(last xs))#ys)\"\n  proof -\n     have \"((C, t1) # xsa) ! 0 = (LanguageCon.com.Catch P Q, t1)\" using C by auto\n     moreover have \"\\<forall>i<length ((C, t1) # xsa). fst (((C, t1) # xsa) ! i) \\<noteq> Q\"\n       using CptnModEnv(5) by fastforce\n     moreover have \"fst (last ((C, t1) # xsa)) = Skip\" using CptnModEnv(6) \n       by fastforce\n     ultimately show ?thesis\n       using CptnModEnv(3) CptnModEnv(7) env_tran_tail by blast    \n  qed \n  then obtain xs ys where hi:\"(\\<Gamma>, xs) \\<in> cp \\<Gamma> P t1 \\<and> (C, t1) # xsa = map (lift_catch Q) xs@((Skip,snd(last ((P, t1)#xs)))#ys)\"\n    by fastforce\n  have s1_s:\"s1=s\" using  CptnModEnv unfolding cp_def by auto\n  have \"\\<exists>xsa' ys. xs=((P,t1)#xsa') \\<and> (\\<Gamma>,((P,t1)#xsa'))\\<in>cptn \\<and> (C, t1) # xsa = map (lift_catch Q) ((P,t1)#xsa')@((Skip, snd(last xs))#ys)\" \n    using hi  unfolding cp_def\n  proof -\n      have \"(\\<Gamma>,xs)\\<in>cptn \\<and> xs!0 = (P,t1)\" using hi unfolding cp_def by fastforce\n      moreover then have \"xs\\<noteq>[]\" using cptn.simps by fastforce  \n      ultimately obtain xsa' where \"xs=((P,t1)#xsa')\" using SmallStepCon.nth_tl by fastforce \n      thus ?thesis\n        using hi using \\<open>(\\<Gamma>, xs) \\<in> cptn \\<and> xs ! 0 = (P, t1)\\<close> by auto \n  qed\n  then obtain xsa' ys where xs:\"xs=((P,t1)#xsa') \\<and> (\\<Gamma>,((P,t1)#xsa'))\\<in>cptn \\<and> (C, t1) # xsa = \n                                    map (lift_catch Q) ((P,t1)#xsa')@((Skip,snd(last ((P,s1)#(P,t1)#xsa')))#ys)\"\n    by fastforce\n  have env_tran:\"\\<Gamma>\\<turnstile>\\<^sub>c(P,s1) \\<rightarrow>\\<^sub>e (P,t1)\" using CptnModEnv Catch_env_P by (metis fst_conv nth_Cons_0)  \n  then have \"(\\<Gamma>,(P,s1)#(P,t1)#xsa')\\<in>cptn\" using xs env_tran CptnEnv by fastforce  \n  then have \"(\\<Gamma>,(P,s1)#(P,t1)#xsa') \\<in> cp \\<Gamma> P s\" \n    using cp_def s1_s by fastforce\n  moreover have \"(C,s1)#(C, t1) # xsa = map (lift_catch Q) ((P,s1)#(P,t1)#xsa')@((Skip,snd(last ((P,s1)#(P,t1)#xsa')))#ys)\"\n    using xs C unfolding lift_catch_def\n    by auto\n  ultimately show ?case by fastforce \nnext\n  case (CptnModSkip)\n  thus ?case by (metis SmallStepCon.redex_not_Catch fst_conv nth_Cons_0)\nnext\n  case (CptnModThrow)\n  thus ?case by (metis SmallStepCon.redex_not_Catch fst_conv nth_Cons_0)\nnext\n  case (CptnModCatch1 \\<Gamma> P0 sa xsa zs P1)  \n  thus ?case\n  proof -\n    have \"\\<forall>c x. (LanguageCon.com.Catch c P1, x) # zs = map (lift_catch P1) ((c, x) # xsa)\"\n      using Cons_lift_catch CptnModCatch1.hyps(3) by blast\n    then have \"(P0, sa) # xsa = []\"\n      by (metis (no_types) CptnModCatch1.prems(3) LanguageCon.com.distinct(19) One_nat_def last_conv_nth last_lift_catch map_is_Nil_conv)\n    then show ?thesis\n      by force\n  qed \nnext\n  case (CptnModCatch2 \\<Gamma> P1 sa xsa  ys zs Q1) \n  then have \"P1 = P \\<and> Q1 = Q \\<and> sa = s\" by auto  \n  moreover then have \"(\\<Gamma>, (P1,sa) # xsa)\\<in> cp \\<Gamma> P s\" \n    using CptnModCatch2(1)\n    by (simp add: cp_def cptn_eq_cptn_mod_set)  \n  moreover obtain s' where \"last zs=(Skip, s')\" \n  proof -\n    assume a1: \"\\<And>s'. last zs = (LanguageCon.com.Skip, s') \\<Longrightarrow> thesis\"\n    have \"\\<exists>x. last zs = (LanguageCon.com.Skip, x)\"\n      by (metis (no_types) CptnModCatch2.hyps(6) CptnModCatch2.prems(3) append_is_Nil_conv last_ConsR list.simps(3) prod.exhaust_sel)\n    then show ?thesis\n      using a1 by metis\n  qed        \n  ultimately show ?case \n    using Cons_lift_catch_append CptnModCatch2.hyps(6)  by fastforce  \nnext \n  case (CptnModCatch3 \\<Gamma> P0 sa xsa sa' P1 ys zs)   \n  then have \"P0 = P \\<and> P1 = Q \\<and> s=Normal sa\" by auto\n  then obtain i where zs:\"fst (zs!i) = Q \\<and> (i< (length zs))\" \n    using CptnModCatch3    \n    by (metis (no_types, lifting) add_diff_cancel_left' fst_conv length_Cons length_append nth_append_length zero_less_Suc zero_less_diff)    \n  then have si:\"Suc i< length ((Catch P0 P1,Normal sa)#zs)\" by fastforce\n  then have \"fst (((Seq P0 P1, Normal sa) # zs)!Suc i) = Q\" using zs by fastforce    \n  thus ?case using CptnModCatch3(9) zs\n     by (metis si nth_Cons_Suc)\nqed (auto)\n\nlemma Catch_sound3: \nassumes\n  a0:\"(\\<Gamma>,x)\\<in>cptn\" and\n  a1:\"x!0 = ((Catch P Q),s)\" and\n  a2:\"\\<forall>i<length x. fst (x!i)\\<noteq> Q\" and\n  a3:\"fst(last x) = Throw\" and\n  a4:\"env_tran_right \\<Gamma> x rely \"\nshows\n  \"False\"\nusing a0 a1 a2 a3 a4\nproof (induct arbitrary: P s)\n  case (CptnOne \\<Gamma> C s1) thus ?case by auto\nnext\n  case (CptnEnv \\<Gamma> C st t xsa) \n    thus ?case\n    proof -\n      have f1: \"env_tran_right \\<Gamma> ((C, t) # xsa) rely\"\n        using CptnEnv.prems(4) env_tran_tail by blast\n      have \"LanguageCon.com.Catch P Q = C\"\n        using CptnEnv.prems(1) by auto\n      then show ?thesis\n        using f1 CptnEnv.hyps(3) CptnEnv.prems(2) CptnEnv.prems(3) by moura\n    qed\nnext  \n  case (CptnComp \\<Gamma> C st C' st' xsa)\n  then have c_catch:\"C = (Catch P Q) \\<and> st = s\" by force\n  from CptnComp show ?case proof(cases)\n    case (Catchc P1 P1' P2) thus ?thesis\n    proof -\n      have f1: \"env_tran_right \\<Gamma> ((C', st') # xsa) rely\"\n        using CptnComp.prems(4) env_tran_tail by blast\n      have \"Q = P2\"\n        using c_catch Catchc(1)  by blast\n      then show ?thesis\n        using f1 CptnComp.hyps(3) CptnComp.prems(2) CptnComp.prems(3) Catchc(2) by moura\n    qed\n  next\n    case  (CatchSkipc) thus ?thesis\n    proof -\n      have \"fst (((C', st') # xsa) ! 0) = LanguageCon.com.Skip\"\n        by (simp add: local.CatchSkipc(2))\n      then show ?thesis\n        by (metis (no_types) CptnComp.hyps(2) CptnComp.prems(3) LanguageCon.com.distinct(17) \n            last_ConsR last_length length_Cons lessI list.simps(3) zero_skip_all_skip)\n    qed    \n  next\n    case (SeqThrowc C2 s') thus ?thesis\n     by (simp add: c_catch)    \n  next\n     case (FaultPropc) thus ?thesis \n      using c_catch redex_not_Catch by blast \n  next\n    case (StuckPropc) thus ?thesis \n      using c_catch redex_not_Catch by blast\n  next\n    case (AbruptPropc) thus ?thesis \n      using c_catch redex_not_Catch by blast\n  qed (auto)\nqed\n\n\nlemma Catch_sound4: \nassumes\n  a0:\"(\\<Gamma>,x)\\<in>cptn\" and\n  a1:\"x!0 = ((Catch P Q),s)\" and\n  a2:\"i<length x \\<and> x!i=(Q,sj)\" and\n  a3:\"\\<forall>j<i. fst(x!j)\\<noteq>Q\" and \n  a4:\"env_tran_right \\<Gamma> x rely \"\nshows\n  \"\\<exists>xs ys. (\\<Gamma>,xs) \\<in> (cp \\<Gamma> P s) \\<and> (\\<Gamma>,ys) \\<in> (cp \\<Gamma> Q (snd (xs!(i-1)))) \\<and> x = (map (lift_catch Q) xs)@ys\"\nusing a0 a1 a2 a3 a4\nproof (induct arbitrary: i sj P s) \n  case (CptnOne \\<Gamma>1 P1 s1) \n    thus ?case by auto    \nnext\n  case (CptnEnv \\<Gamma> C st t xsa)    \n  have a1:\"Catch P Q \\<noteq> Q\" by simp    \n  then have C_catch:\"C=(Catch P Q)\" using CptnEnv by fastforce\n  then have \"fst(((C, st) # (C, t) # xsa)!0) \\<noteq>Q\" using CptnEnv a1 by auto\n  moreover have  \"fst(((C, st) # (C, t) # xsa)!1) \\<noteq>Q\" using CptnEnv a1 by auto\n  moreover have \"fst(((C, st) # (C, t) # xsa)!i) =Q\" using CptnEnv by auto\n  ultimately have i_suc: \"i> (Suc 0)\" using CptnEnv \n    by (metis Suc_eq_plus1 Suc_lessI add.left_neutral neq0_conv) \n  then obtain i' where i':\"i=Suc i'\" by (meson lessE) \n  then have i_minus:\"i'=i-1\" by auto  \n  have \"((C, t) # xsa) ! 0 = ((Catch P Q), t)\"\n    using CptnEnv by auto \n  moreover have \"i'< length ((C,t)#xsa) \\<and> ((C,t)#xsa)!i' = (Q,sj)\"\n    using i' CptnEnv(5) by force\n  moreover have \"\\<forall>j<i'. fst (((C, t) # xsa) ! j) \\<noteq> Q\"\n    using i' CptnEnv(6) by force\n  ultimately have hyp:\"\\<exists>xs ys.\n     (\\<Gamma>, xs) \\<in> cp \\<Gamma> P t \\<and>\n     (\\<Gamma>, ys) \\<in> cp \\<Gamma> Q (snd (xs ! (i'-1))) \\<and> (C, t) # xsa = map (lift_catch Q) xs @ ys\"\n    using CptnEnv(3) env_tran_tail CptnEnv.prems(4)  by blast \n  then obtain xs ys where xs_cp:\"(\\<Gamma>, xs) \\<in> cp \\<Gamma> P t \\<and>\n     (\\<Gamma>, ys) \\<in> cp \\<Gamma> Q (snd (xs ! (i'-1))) \\<and> (C, t) # xsa = map (lift_catch Q) xs @ ys\"\n    by fast\n  have \"(\\<Gamma>, (P, s)#xs) \\<in> cp \\<Gamma> P s\"\n  proof -\n    have \"xs!0 = (P,t)\" \n      using xs_cp unfolding cp_def by blast\n    moreover have \"xs\\<noteq>[]\"\n      using cp_def cptn.simps xs_cp by blast \n    ultimately obtain xs' where xs':\"(\\<Gamma>, (P,t)#xs') \\<in> cptn \\<and> xs=(P,t)#xs'\" \n      using SmallStepCon.nth_tl xs_cp unfolding cp_def by force\n    thus ?thesis using cp_def  cptn.CptnEnv\n    proof -\n      have \"(Catch P Q, s) = (C, st)\"\n        using CptnEnv.prems(1) by auto\n      then have \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow>\\<^sub>e (P, t)\"\n        using Catch_env_P CptnEnv(1) by blast\n      then show ?thesis\n        by (simp add:xs' cp_def cptn.CptnEnv)\n    qed\n  qed\n  thus  ?case \n    using i_suc Cons_lift_catch_append CptnEnv.prems(1) i' i_minus xs_cp\n    by fastforce   \nnext\n  case (CptnComp \\<Gamma> C st C' st' xsa i)\n  then have c_catch:\"C = (Catch P Q) \\<and> st = s\" by fastforce  \n  from CptnComp show ?case proof(cases)\n    case (Catchc P1 P1' P2)      \n    then have C_seq:\"C=(Catch P Q)\" using CptnEnv CptnComp by fastforce    \n    then have \"fst(((C, st) # (C', st') # xsa)!0) \\<noteq>Q\" \n      using CptnComp by auto\n    moreover have  \"fst(((C, st) # (C', st') # xsa)!1) \\<noteq>Q\" \n      using  CptnComp Catchc by auto\n    moreover have \"fst(((C, st) # (C', st') # xsa)!i) =Q\" \n      using CptnComp by auto\n    ultimately have  i_gt0:\"i> (Suc 0)\" \n      by (metis Suc_eq_plus1 Suc_lessI add.left_neutral neq0_conv) \n    then obtain i' where i':\"i=Suc i'\" by (meson lessE) \n    then have i_minus:\"i'=i-1\" by auto       \n    have \"((C', st') # xsa) ! 0 = ((Catch P1' Q), st')\"\n      using CptnComp Catchc by auto \n    moreover have \"i'< length ((C',st')#xsa) \\<and> ((C',st')#xsa)!i' = (Q,sj)\"\n      using i' CptnComp(5) by force\n    moreover have \"\\<forall>j<i'. fst (((C', st') # xsa) ! j) \\<noteq> Q\"\n    using i' CptnComp(6) by force   \n    ultimately have \"\\<exists>xs ys.\n       (\\<Gamma>, xs) \\<in> cp \\<Gamma> P1' st' \\<and>\n       (\\<Gamma>, ys) \\<in> cp \\<Gamma> Q (snd (xs ! (i'-1))) \\<and> (C', st') # xsa = map (lift_catch Q) xs @ ys\"\n    using CptnComp Catchc env_tran_tail CptnComp.prems(4) by blast\n    then obtain xs ys where xs_cp:\n      \"(\\<Gamma>, xs) \\<in> cp \\<Gamma> P1' st' \\<and>\n       (\\<Gamma>, ys) \\<in> cp \\<Gamma> Q (snd (xs ! (i'-1))) \\<and> (C', st') # xsa = map (lift_catch Q) xs @ ys\"\n      by fastforce\n     have \"(\\<Gamma>, (P,s)#xs) \\<in> cp \\<Gamma> P s\"        \n     proof -\n        have \"xs!0 = (P1',st')\" \n          using xs_cp unfolding cp_def by blast\n        moreover have \"xs\\<noteq>[]\"\n          using cp_def cptn.simps xs_cp by blast \n        ultimately obtain xs' where xs':\"(\\<Gamma>, (P1',st')#xs') \\<in> cptn \\<and> xs=(P1',st')#xs'\" \n          using SmallStepCon.nth_tl xs_cp unfolding cp_def by force\n        thus ?thesis using cp_def  cptn.CptnEnv Catchc c_catch\n              xs' cp_def cptn.CptnComp          \n             by (simp add: cp_def cptn.CptnComp xs') \n     qed     \n     thus ?thesis using Cons_lift_catch c_catch i' xs_cp i_gt0 by fastforce\n  next\n    case (CatchSkipc) \n    with CptnComp have PC:\"P=Skip \\<and> C'=Skip \\<and> st=st' \\<and> s=st\" by fastforce   \n    then have all_skip:\"\\<forall>j\\<ge>0. j< (length ((C',st')#xsa)) \\<longrightarrow> fst(((C',st')#xsa)!j) = Skip\"       \n      by (metis (no_types) CptnComp.hyps(2) PC fst_conv i_skip_all_skip nth_Cons_0)\n    then have Q_skip:\"Q=Skip\" \n    proof - \n      have \"Catch Skip Q\\<noteq>Q\" by auto\n      then show \"Q=Skip\"         \n        using all_skip CptnComp(4,5,6)  PC less_Suc_eq_0_disj  \n        by auto\n    qed\n    then have \"(\\<Gamma>, [(Skip,st)]) \\<in> cp \\<Gamma> P s\" unfolding cp_def using cptn.simps PC\n      by fastforce    \n    moreover have \"(\\<Gamma>, (Q,st')#xsa) \\<in> cp \\<Gamma> Q st'\" \n       unfolding cp_def\n       using CptnComp PC Q_skip by fastforce\n    moreover have \"i=1\"\n    proof -\n      have f1: \"fst (((C, st) # (C', st') # xsa) ! 0) \\<noteq> Q\"\n        using CptnComp.prems(1) by force        \n      have \"fst (((C, st) # (C', st') # xsa) ! Suc 0) = LanguageCon.com.Skip\"\n        using PC by force\n      then have f3: \"\\<not> Suc 0 < i\"\n        using CptnComp.prems(3) Q_skip by blast\n      have \"((C, st) # (C', st') # xsa) ! i \\<noteq> (C, st)\"\n        using f1 CptnComp.prems(2) by force\n      then have \"0 \\<noteq> i\"\n         by force\n      then show ?thesis\n        using f3 by auto\n    qed      \n    moreover have \"[(Catch Skip Q, st)]  = map (lift_catch Q) [(Skip,st)]\" \n      unfolding lift_catch_def by auto\n    ultimately show ?thesis using PC CatchSkipc\n      using CptnComp.prems(2) PC  c_catch by force \n  next\n    case (CatchThrowc s')\n    with CptnComp have PC:\"P=Throw \\<and> C'=Q \\<and>  st=st' \\<and> st=s\" by fastforce        \n    then have \"(\\<Gamma>, [(Throw, Normal s')]) \\<in> cp \\<Gamma> P s\"\n      using PC cptn.simps unfolding cp_def \n      using cptn.CptnOne local.CatchThrowc(3) by force\n    moreover have \"(\\<Gamma>, (C', st') # xsa)\\<in>cp \\<Gamma> Q st' \"\n       using PC CptnComp unfolding cp_def  by fastforce\n     moreover have \"i=1\" using CptnComp (4-6) PC \n     proof -\n       have \"fst (((C, st) # (C', st') # xsa) ! Suc 0) = Q\"\n         using PC by force\n       then have \"\\<not> Suc 0 < i\"\n         using local.CptnComp(6) by blast \n       have \"(LanguageCon.com.Throw, sj) \\<noteq> (LanguageCon.com.Seq P Q, s)\"\n         by blast\n       then have \"i \\<noteq> 0\"\n         using c_catch local.CptnComp(5) by force\n       then have \"Suc 0 = i\"\n         using \\<open>\\<not> Suc 0 < i\\<close> by linarith\n       then show ?thesis by auto    \n     qed   \n     moreover have \"[(Catch Throw Q, st)]  = map (lift_catch Q) [(Throw,st)]\" \n      unfolding lift_catch_def by auto\n     ultimately show ?thesis  using PC CatchThrowc by fastforce     \n  next\n    case (FaultPropc) thus ?thesis \n      using c_catch redex_not_Catch by blast \n  next\n    case (StuckPropc) thus ?thesis \n      using c_catch redex_not_Catch by blast\n  next\n    case (AbruptPropc) thus ?thesis \n      using c_catch redex_not_Catch by blast\n  qed(auto)\nqed\n\ninductive_cases stepc_elim_cases_Catch_throw:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,s) \\<rightarrow> (Throw, Normal s1)\" \n\ninductive_cases stepc_elim_cases_Catch_skip_c2:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,s) \\<rightarrow> (c2,s)\"\n\ninductive_cases stepc_elim_cases_Catch_skip_2:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,s) \\<rightarrow> (Skip, s)\"\n\nlemma catch_skip_throw:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,s) \\<rightarrow> (c2,s)  \\<Longrightarrow> (c2= Skip \\<and> c1=Skip) \\<or> (c1=Throw \\<and> (\\<exists>s2'. s=Normal s2'))\"\napply (rule stepc_elim_cases_Catch_skip_c2)\napply fastforce\napply (auto)+\nusing redex_not_Catch apply auto\ndone\n\nlemma catch_skip_throw1:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,s) \\<rightarrow> (Skip,s)  \\<Longrightarrow> (c1=Skip) \\<or> (c1=Throw \\<and> (\\<exists>s2'. s=Normal s2') \\<and> c2 = Skip)\"\napply (rule stepc_elim_cases_Catch_skip_2)\nusing redex_not_Catch apply auto\nusing redex_not_Catch by auto\n\nlemma Catch_sound: \n      \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p,  R, G, q,r] \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> c1 sat [p,  R, G, q,r] \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c2 sat [r,  R, G, q,a] \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> c2 sat [r,  R, G, q,a] \\<Longrightarrow>        \n       Sta q R  \\<Longrightarrow>  (\\<forall>s. (Normal s,Normal s) \\<in> G) \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> (Catch c1 c2) sat [p, R, G, q,a]\"\nproof -  \n  assume\n    a0:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p, R, G, q,r]\" and\n    a1:\"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> c1 sat [p, R, G, q,r]\" and\n    a2:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c2 sat [r, R, G, q,a]\" and    \n    a3: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> c2 sat [r, R, G, q,a]\" and     \n    a4: \"Sta q R \" and\n    a5: \"(\\<forall>s. (Normal s, Normal s) \\<in> G)\"       \n  { \n    fix s\n    assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"\n    then have a1:\"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> c1 sat [p, R, G, q,r]\" \n      using a1 com_cvalidity_def by fastforce  \n    then have a3: \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> c2 sat [r, R, G, q,a]\"\n      using a3 com_cvalidity_def all_call by fastforce \n    have \"cp \\<Gamma> (Catch c1 c2)  s \\<inter> assum(p, R) F \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cp \\<Gamma> (Catch c1 c2) s\" and a11:\"c \\<in> assum(p, R) F\"\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have cp:\"l!0=((Catch c1 c2),s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\" using a10 cp_def c_prod by fastforce\n      have \\<Gamma>1:\"(\\<Gamma>, l) = c\" using c_prod cp by blast\n      have \"c \\<in> comm(G, (q,a)) F\"         \n      proof - \n      {\n       assume l_f:\"snd (last l) \\<notin> Fault ` F\"       \n       have assum:\"snd(l!0) \\<in> Normal ` (p) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n                 (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n       using a11 c_prod unfolding assum_def by simp\n       then have env_tran:\"env_tran \\<Gamma> p l R\" using env_tran_def cp by blast\n       then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n         using env_tran env_tran_right_def unfolding env_tran_def by auto       \n       have \"(\\<forall>i. Suc i<length l \\<longrightarrow> \n               \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i))  \\<longrightarrow>              \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\\<and>\n             (final (last l)  \\<longrightarrow>                    \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a)))\"\n       proof (cases \"\\<forall>i<length l. fst (l!i)\\<noteq> c2\")\n         case True \n         then have no_c2:\"\\<forall>i<length l. fst (l!i)\\<noteq> c2\" by assumption\n         show ?thesis\n         proof (cases \"final (last l)\")\n           case True\n           then obtain s' where \"fst (last l) = Skip \\<or> (fst (last l) = Throw \\<and> snd (last l) = Normal s')\"  \n             using final_def by fast           \n           thus ?thesis\n           proof\n             assume \"fst (last l)= LanguageCon.com.Throw \\<and> snd (last l) = Normal s'\" \n             then have \"False\" using  no_c2 env_tran_right cp cptn_eq_cptn_mod_set Catch_sound3\n               by blast\n             thus ?thesis by auto\n           next             \n             assume asm0:\"fst (last l) = Skip\"\n             then obtain lc1 ys where cp_lc1:\"(\\<Gamma>,lc1) \\<in> cp \\<Gamma> c1 s \\<and> l = ((map (lift_catch c2) lc1)@((Skip,snd(last lc1))#ys))\"\n               using Catch_sound2 cp cptn_eq_cptn_mod_set env_tran_right no_c2 by blast\n             let ?m_lc1 = \"map (lift_catch c2) lc1\"\n             let ?lm_lc1 = \"(length ?m_lc1)\"\n             let ?last_m_lc1 = \"?m_lc1!(?lm_lc1-1)\"              \n             have lc1_not_empty:\"lc1 \\<noteq> []\"\n               using \\<Gamma>1 a10 cp_def cp_lc1 by force             \n             then have map_cp:\"(\\<Gamma>,?m_lc1) \\<in> cp \\<Gamma> (Catch c1 c2) s\"               \n             proof -\n               have f1: \"lc1 ! 0 = (c1, s) \\<and> (\\<Gamma>, lc1) \\<in> cptn \\<and> \\<Gamma> = \\<Gamma>\"\n                 using cp_lc1 cp_def by blast\n               then have f2: \"(\\<Gamma>, ?m_lc1) \\<in> cptn\" using lc1_not_empty\n                 by (meson lift_catch_is_cptn)                \n               then show ?thesis\n                 using f2 f1 lc1_not_empty by (simp add: cp_def lift_catch_def)\n             qed\n             also have map_assum:\"(\\<Gamma>,?m_lc1) \\<in> assum (p,R) F\"\n               using sub_assum a10 a11 \\<Gamma>1 cp_lc1 lc1_not_empty \n               by (metis SmallStepCon.nth_tl map_is_Nil_conv)\n             ultimately have \"((\\<Gamma>,lc1) \\<in> assum(p, R) F)\"  \n               using \\<Gamma>1 assum_map_catch cp_lc1 by blast                          \n             then have lc1_comm:\"(\\<Gamma>,lc1) \\<in> comm(G, (q,r)) F\"  \n               using a1 cp_lc1 by (meson IntI com_validity_def contra_subsetD)\n             then have m_lc1_comm:\"(\\<Gamma>,?m_lc1) \\<in> comm(G, (q,r)) F\"\n               using map_cp map_assum comm_map_catch cp_lc1 by fastforce\n             then have last_m_lc1:\"last (?m_lc1) = (Catch (fst (last lc1)) c2,snd (last lc1))\"\n             proof -\n               have a000:\"\\<forall>p c. (LanguageCon.com.Catch (fst p) c, snd p) = lift_catch c p\"\n                 using Cons_lift_catch by force\n               then show ?thesis\n                 by (simp add: last_map a000 lc1_not_empty)\n             qed\n             then have last_length:\"last (?m_lc1) = ?last_m_lc1\"  \n               using lc1_not_empty last_conv_nth list.map_disc_iff by blast \n             then have l_map:\"l!(?lm_lc1-1)= ?last_m_lc1\" \n               using cp_lc1\n               by (simp add:lc1_not_empty nth_append)\n             then have lm_lc1:\"l!(?lm_lc1) = (Skip, snd (last lc1))\"\n               using cp_lc1 by (meson nth_append_length) \n             then have step:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!(?lm_lc1-1)) \\<rightarrow> (l!(?lm_lc1))\"\n             proof -\n               have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!(?lm_lc1-1)) \\<rightarrow>\\<^sub>c\\<^sub>e (l!(?lm_lc1))\"\n               proof -\n                 have f1: \"\\<forall>n na. \\<not> n < na \\<or> Suc (na - Suc n) = na - n\"\n                   by (meson Suc_diff_Suc)\n                 have \"map (lift_catch c2) lc1 \\<noteq> []\"\n                   by (metis lc1_not_empty map_is_Nil_conv)\n                 then have f2: \"0 < length (map (lift_catch c2) lc1)\"\n                   by (meson length_greater_0_conv)\n                 then have \"length (map (lift_catch c2) lc1) - 1 + 1 < length (map (lift_catch c2) lc1 @ (Skip,snd (last  lc1)) # ys)\"\n                   by simp\n                 then show ?thesis\n                   using f2 f1 by (metis (no_types) One_nat_def cp cp_lc1 cptn_tran_ce_i diff_zero)\n               qed\n               moreover have \"\\<not>\\<Gamma>\\<turnstile>\\<^sub>c(l!(?lm_lc1-1)) \\<rightarrow>\\<^sub>e (l!(?lm_lc1))\"\n               using  last_m_lc1 last_length l_map\n               proof -\n                 have \"(LanguageCon.com.Catch (fst (last lc1)) c2, snd (last lc1)) = l ! (length (map (lift_catch c2) lc1) - 1)\"\n                   using l_map last_m_lc1 local.last_length by presburger\n                 then show ?thesis\n                   by (metis LanguageCon.com.simps(30) env_c_c' lm_lc1)                   \n               qed\n               ultimately show ?thesis using step_ce_elim_cases by blast        \n             qed\n             have last_lc1_suc:\"snd (l!(?lm_lc1-1)) = snd (l!?lm_lc1)\"\n               using l_map  last_m_lc1 lm_lc1 local.last_length by force\n             then have step_catch:\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch (fst (last lc1)) c2,snd (last lc1)) \\<rightarrow> (Skip, snd (last lc1))\"               \n               using l_map last_m_lc1 lm_lc1 local.last_length local.step \n               by presburger \n             then obtain s2' where \n               last_lc1:\"fst (last lc1) = Skip  \\<or> \n               fst (last lc1) = Throw \\<and> (snd (last lc1) = Normal s2') \\<and> c2 = Skip\"\n             using catch_skip_throw1 by fastforce              \n             then have last_lc1_skip:\"fst (last lc1) = Skip\" \n             proof \n                assume \"fst (last lc1) = LanguageCon.com.Throw \\<and>\n                        snd (last lc1) = Normal s2' \\<and> c2 = LanguageCon.com.Skip\"\n                thus ?thesis using no_c2 asm0 \n                  by (simp add: cp_lc1 last_conv_nth ) \n             qed auto  \n             have last_not_F:\"snd (last ?m_lc1) \\<notin> Fault ` F\"\n             proof -\n               have \"snd ?last_m_lc1 = snd (l!(?lm_lc1-1))\"\n                 using l_map by auto \n               have \"(?lm_lc1-1)< length l\"using cp_lc1 by fastforce\n               also then have \"snd (l!(?lm_lc1-1))\\<notin> Fault ` F\"\n                 using cp cp_lc1  l_f  last_not_F[of \\<Gamma> l F]\n                 by fastforce\n               ultimately show ?thesis using l_map last_length by fastforce\n             qed\n             then have q_normal:\"snd (l!?lm_lc1) \\<in> Normal ` q \" \n             proof -\n               have last_lc1:\"fst (last lc1) = Skip\" \n               using last_lc1_skip by fastforce  \n               have \"final (last lc1)\" using last_lc1 final_def \n                 by blast              \n               then show ?thesis \n                 using lc1_comm last_lc1 last_not_F \n                 unfolding comm_def\n                 using  last_lc1_suc comm_dest2 l_map lm_lc1 local.last_length\n                 by force\n             qed                                             \n             then obtain s1' where normal_lm_lc1:\"snd (l!?lm_lc1) = Normal s1' \\<and> s1' \\<in>q\" \n               by auto\n             have concl:\"(\\<forall>i ns ns'. Suc i<length l \\<longrightarrow> \n               \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>              \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n             proof-\n             { fix k ns ns'\n               assume a00:\"Suc k<length l\" and\n                a21:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"   \n                then have i_m_l:\"\\<forall>i <?lm_lc1  . l!i = ?m_lc1!i\" \n                  using cp_lc1\n                proof -\n                  have \"map (lift c2) lc1 \\<noteq> []\"\n                    by (meson lc1_not_empty list.map_disc_iff)\n                  then show ?thesis\n                    by (metis (no_types) cp_lc1  nth_append)\n                qed                                                         \n                have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n                proof (cases \"Suc k< ?lm_lc1\")\n                  case True \n                  then have a11': \"\\<Gamma>\\<turnstile>\\<^sub>c(?m_lc1!k)  \\<rightarrow> (?m_lc1!(Suc k))\" \n                    using a11 i_m_l True\n                  proof -\n                    have \"\\<forall>n na. \\<not> 0 < n - Suc na \\<or> na < n \"\n                      using diff_Suc_eq_diff_pred zero_less_diff by presburger\n                    then show ?thesis\n                      by (metis (no_types) True a21 i_m_l zero_less_diff)\n                  qed                 \n                  then have \"(snd(?m_lc1!k), snd(?m_lc1!(Suc k))) \\<in> G\"\n                  using a11' m_lc1_comm True comm_dest1 l_f last_not_F by fastforce\n                  thus ?thesis using i_m_l True by auto  \n                next\n                  case False \n                  then have \"(Suc k=?lm_lc1) \\<or> (Suc k>?lm_lc1)\" by auto\n                  thus ?thesis \n                  proof\n                    {assume suck:\"(Suc k=?lm_lc1)\"\n                     then have k:\"k=?lm_lc1-1\" by auto\n                     then obtain s1' where s1'_normal:\"snd(l!?lm_lc1) = Normal s1'\"\n                       using q_normal by fastforce\n                     have G_s1':\"(Normal s1', Normal s1')\\<in> G\" using a5 by auto\n                     then show \"(snd (l!k), snd (l!Suc k)) \\<in> G\"\n                     proof -\n                       have \"snd (l ! k) = Normal s1'\"\n                         using k last_lc1_suc s1'_normal by presburger\n                       then show ?thesis\n                         using G_s1' s1'_normal suck by force\n                     qed                                   \n                    }\n                  next\n                  { \n                    assume a001:\"Suc k>?lm_lc1\"\n                    have \"\\<forall>i. i\\<ge>(length lc1) \\<and> (Suc i < length l) \\<longrightarrow> \n                            \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\"\n                    using lm_lc1 lc1_not_empty\n                    proof -\n                      have \"env_tran_right \\<Gamma>1 l R\"\n                        by (metis cp env_tran_right)\n                      then show ?thesis \n                        using  cp fst_conv length_map lm_lc1 a001 a21 a00 a4\n                              normal_lm_lc1 \n                        by (metis (no_types) only_one_component_tran_j)\n                    qed\n                    then have \"\\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n                      using a00 a001 by auto                    \n                    then show ?thesis using a21 by fastforce                    \n                  }\n                  qed \n                qed\n              } thus ?thesis by auto \n             qed \n             have concr:\"(final (last l)  \\<longrightarrow>                    \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a)))\" \n             proof -\n               have l_t:\"fst (last l) = Skip\" \n                 using lm_lc1 by (simp add: asm0)\n               have \"?lm_lc1 \\<le> length l -1\" using cp_lc1 by fastforce               \n               also have \"\\<forall>i. ?lm_lc1 \\<le>i \\<and> i<(length l -1) \\<longrightarrow>  \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i))\"        \n                 using cp fst_conv length_map lm_lc1 a4\n                      normal_lm_lc1 only_one_component_tran_j[of \\<Gamma> l ?lm_lc1 s1' q ]\n                 by (metis Suc_eq_plus1 cptn_tran_ce_i env_tran_right less_diff_conv  step_ce_elim_cases)                                                                       \n               ultimately have \"snd (l ! (length l - 1)) \\<in> Normal ` q\"\n                 using cp_lc1 q_normal a4 env_tran_right stability[of q R l ?lm_lc1 \"(length l) -1\" _ \\<Gamma>] \n                 by fastforce               \n               thus ?thesis using l_t \n                 by (simp add:  cp_lc1 last_conv_nth)\n             qed\n             note res = conjI [OF concl concr]\n             then show ?thesis using  \\<Gamma>1 c_prod unfolding comm_def by auto\n           qed                  \n         next\n           case False\n           then obtain lc1 where cp_lc1:\"(\\<Gamma>,lc1) \\<in> cp \\<Gamma> c1 s \\<and> l = map (lift_catch c2) lc1\" \n           using Catch_sound1 False no_c2 env_tran_right cp cptn_eq_cptn_mod_set \n           by blast \n           then have \"((\\<Gamma>,lc1) \\<in> assum(p, R) F)\"  \n              using \\<Gamma>1  a10 a11 assum_map_catch by blast\n           then have \"(\\<Gamma>, lc1)\\<in> comm(G, (q,r)) F\" using cp_lc1 a1\n             by (meson IntI com_validity_def contra_subsetD)\n           then have \"(\\<Gamma>, l)\\<in> comm(G, (q,r)) F\"\n             using comm_map_catch a10 \\<Gamma>1 cp_lc1 by fastforce\n           then show ?thesis using l_f False\n             unfolding comm_def by fastforce\n         qed\n       next         \n         case False \n         then obtain k where k_len:\"k<length l \\<and> fst (l ! k) = c2\"\n           by blast         \n         then have \"\\<exists>m. (m < length l \\<and> fst (l ! m) = c2) \\<and>\n                   (\\<forall>i<m. \\<not> (i < length l \\<and> fst (l ! i) = c2))\"   \n           using a0 exists_first_occ[of \"(\\<lambda>i. i<length l  \\<and> fst (l ! i) = c2)\" k] \n           by blast\n         then obtain i where a0:\"i<length l \\<and> fst (l !i) = c2 \\<and>\n                                (\\<forall>j<i. (fst (l ! j) \\<noteq> c2))\"\n           by fastforce        \n         then obtain s2 where li:\"l!i =(c2,s2)\" by (meson eq_fst_iff)\n         then obtain lc1 lc2 where cp_lc1:\"(\\<Gamma>,lc1) \\<in> (cp \\<Gamma> c1 s) \\<and> \n                                 (\\<Gamma>,lc2) \\<in> (cp \\<Gamma> c2 (snd (lc1!(i-1)))) \\<and> \n                                 l = (map (lift_catch c2) lc1)@lc2\"\n           using Catch_sound4 a0 cp env_tran_right by blast           \n         have i_not_fault:\"snd (l!i) \\<notin> Fault ` F\" using a0  cp l_f last_not_F[of \\<Gamma> l F] by blast\n         have length_c1_map:\"length lc1 = length (map (lift_catch c2) lc1)\" \n           by fastforce      \n         then have i_map:\"i=length lc1\" \n           using cp_lc1 li a0 unfolding lift_catch_def\n         proof -\n            assume a1: \"(\\<Gamma>, lc1) \\<in> cp \\<Gamma> c1 s \\<and> (\\<Gamma>, lc2) \\<in> cp \\<Gamma> c2 (snd (lc1 ! (i - 1))) \\<and> l = map (\\<lambda>(P, s). (Catch P c2, s)) lc1 @ lc2\"\n            have f2: \"i < length l \\<and> fst (l ! i) = c2 \\<and> (\\<forall>n. \\<not> n < i \\<or> fst (l ! n) \\<noteq> c2)\"\n              using a0 by blast\n            have f3: \"(Catch (fst (lc1 ! i)) c2, snd (lc1 ! i)) = lift_catch c2 (lc1 ! i)\"\n              by (simp add: case_prod_unfold lift_catch_def)            \n            then have \"fst (l ! length lc1) = c2\"\n              using a1 by (simp add: cp_def nth_append)\n            thus ?thesis\n              using f3 f2\n              by (metis (no_types, lifting) Pair_inject a0 cp_lc1 f3 length_c1_map li linorder_neqE_nat nth_append nth_map seq_and_if_not_eq(12))\n         qed                  \n         have lc2_l:\"\\<forall>j<length lc2. lc2!j=l!(i+j)\"\n           using cp_lc1 length_c1_map i_map a0\n           by (metis nth_append_length_plus)                                                             \n         have lc1_not_empty:\"lc1 \\<noteq> []\"\n           using cp cp_lc1 unfolding cp_def by fastforce      \n         have lc2_not_empty:\"lc2 \\<noteq> []\"\n           using cp_def cp_lc1 cptn.simps by blast             \n         have l_is:\"s2= snd (last lc1)\"\n         using cp_lc1 li a0 lc1_not_empty unfolding cp_def\n          proof -\n            assume a1: \"(\\<Gamma>, lc1) \\<in> {(\\<Gamma>1, l). l ! 0 = (c1, s) \\<and> (\\<Gamma>, l) \\<in> cptn \\<and> \\<Gamma>1 = \\<Gamma>} \\<and> (\\<Gamma>, lc2) \\<in> {(\\<Gamma>1, l). l ! 0 = (c2, snd (lc1 ! (i - 1))) \\<and> (\\<Gamma>, l) \\<in> cptn \\<and> \\<Gamma>1 = \\<Gamma>} \\<and> l = map (lift_catch c2) lc1 @ lc2\"\n            then have \"(map (lift_catch c2) lc1 @ lc2) ! length (map (lift_catch c2) lc1) = l ! i\"\n              using i_map by force\n            have f2: \"(c2, s2) = lc2 ! 0\"\n              using li lc2_l lc2_not_empty by fastforce\n            have \"op - i = op - (length lc1)\"\n              using i_map by blast\n            then show ?thesis\n              using f2 a1 by (simp add: last_conv_nth lc1_not_empty)\n          qed \n         let ?m_lc1 = \"map (lift_catch c2) lc1\"\n         (* let ?lm_lc1 = \"(length ?m_lc1)\"\n         let ?last_m_lc1 = \"?m_lc1!(?lm_lc1-1)\" *)                         \n         have last_m_lc1:\"l!(i-1) = (Catch (fst (last lc1)) c2,s2)\"\n         proof -\n           have a000:\"\\<forall>p c. (Catch (fst p) c, snd p) = lift_catch c p\"\n             using Cons_lift_catch by fastforce\n           then show ?thesis\n           proof -\n             have \"length (map (lift_catch c2) lc1) = i\"\n               using i_map by fastforce\n             then show ?thesis\n               by (metis (no_types) One_nat_def l_is a000 cp_lc1 diff_less last_conv_nth last_map lc1_not_empty length_c1_map length_greater_0_conv less_Suc0 nth_append)\n           qed            \n         qed  \n         have last_mcl1_not_F:\"snd (last ?m_lc1) \\<notin> Fault ` F\"                 \n         proof -\n          have \"map (lift_catch c2) lc1 \\<noteq> []\"\n            by (metis lc1_not_empty list.map_disc_iff)\n          then show ?thesis\n            by (metis One_nat_def i_not_fault l_is last_conv_nth last_snd_catch lc1_not_empty li snd_conv)             \n         qed        \n         have map_cp:\"(\\<Gamma>,?m_lc1) \\<in> cp \\<Gamma> (Catch c1 c2) s\"               \n         proof -\n           have f1: \"lc1 ! 0 = (c1, s) \\<and> (\\<Gamma>, lc1) \\<in> cptn \\<and> \\<Gamma> = \\<Gamma>\"\n             using cp_lc1 cp_def by blast\n           then have f2: \"(\\<Gamma>, ?m_lc1) \\<in> cptn\" using lc1_not_empty\n             by (meson lift_catch_is_cptn)                \n           then show ?thesis\n             using f2 f1 lc1_not_empty by (simp add: cp_def lift_catch_def)\n         qed\n         also have map_assum:\"(\\<Gamma>,?m_lc1) \\<in> assum (p,R) F\"\n           using sub_assum a10 a11 \\<Gamma>1 cp_lc1 lc1_not_empty \n           by (metis SmallStepCon.nth_tl map_is_Nil_conv)\n         ultimately have \"((\\<Gamma>,lc1) \\<in> assum(p, R) F)\"  \n           using \\<Gamma>1 assum_map_catch using assum_map cp_lc1 by blast                          \n         then have lc1_comm:\"(\\<Gamma>,lc1) \\<in> comm(G, (q,r)) F\"  \n           using a1 cp_lc1 by (meson IntI com_validity_def contra_subsetD)\n         then have m_lc1_comm:\"(\\<Gamma>,?m_lc1) \\<in> comm(G, (q,r)) F\"\n           using map_cp map_assum comm_map_catch cp_lc1 by fastforce         \n         then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!(i-1)) \\<rightarrow> (l!i)\"\n         proof -\n           have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!(i-1)) \\<rightarrow>\\<^sub>c\\<^sub>e (l!(i))\"\n           proof -\n             have f1: \"\\<forall>n na. \\<not> n < na \\<or> Suc (na - Suc n) = na - n\"\n               by (meson Suc_diff_Suc)\n             have \"map (lift_catch c2) lc1 \\<noteq> []\"\n               by (metis lc1_not_empty map_is_Nil_conv)\n             then have f2: \"0 < length (map (lift_catch c2) lc1)\"\n               by (meson length_greater_0_conv)             \n             then have \"length (map (lift_catch c2) lc1) - 1 + 1 < length (map (lift_catch c2) lc1 @ lc2)\"\n               using f2 lc2_not_empty by simp\n             then show ?thesis\n             using f2 f1\n              proof -\n                have \"0 < i\"\n                  using f2 i_map by blast\n                then show ?thesis\n                  by (metis (no_types) One_nat_def Suc_diff_1 a0 add.right_neutral add_Suc_right cp cptn_tran_ce_i)\n              qed \n           qed\n           moreover have \"\\<not>\\<Gamma>\\<turnstile>\\<^sub>c(l!(i-1)) \\<rightarrow>\\<^sub>e (l!i)\"           \n             using li last_m_lc1\n             by (metis (no_types, lifting) env_c_c' seq_and_if_not_eq(12))\n           ultimately show ?thesis using step_ce_elim_cases by blast\n         qed         \n         then have step:\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch (fst (last lc1)) c2,s2) \\<rightarrow> (c2, s2)\"\n           using last_m_lc1  li by fastforce\n         then obtain s2' where \n           last_lc1:\"(fst (last lc1) = Skip \\<and> c2 = Skip) \\<or> \n            fst (last lc1) = Throw \\<and> (s2 = Normal s2')\" \n           using catch_skip_throw by blast    \n         have final:\"final (last lc1)\" \n           using last_lc1 l_is unfolding final_def by auto\n         have normal_last:\"fst (last lc1) = Skip \\<and> snd (last lc1) \\<in> Normal ` q \\<or>\n                        fst (last lc1) = Throw \\<and> snd (last lc1) \\<in> Normal ` r\"\n         proof -         \n           have \"snd (last lc1) \\<notin> Fault ` F\"\n             using i_not_fault l_is li by auto\n           then show ?thesis\n             using final comm_dest2 lc1_comm by blast\n         qed\n         obtain s2' where lastlc1_normal:\"snd (last lc1) = Normal s2'\" \n           using normal_last by blast\n         then have Normals2:\"s2 = Normal s2'\" by (simp add: l_is) \n         have Gs2':\" (Normal s2', Normal s2')\\<in>G\" using a5 by auto              \n         have concl:\n           \"(\\<forall>i. Suc i<length l \\<longrightarrow> \n           \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                              \n             (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n         proof-\n         { fix k ns ns'\n           assume a00:\"Suc k<length l\" and\n            a21:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"   \n            have i_m_l:\"\\<forall>j <i . l!j = ?m_lc1!j\"             \n            proof -\n              have \"map (lift c2) lc1 \\<noteq> []\"\n                by (meson lc1_not_empty list.map_disc_iff)\n              then show ?thesis \n                using cp_lc1 i_map length_c1_map by (fastforce simp:nth_append)              \n            qed \n            have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n            proof (cases \"Suc k< i\")\n              case True \n              then have a11': \"\\<Gamma>\\<turnstile>\\<^sub>c(?m_lc1!k)  \\<rightarrow> (?m_lc1!(Suc k))\" \n                using a11 i_m_l True\n              proof -\n                have \"\\<forall>n na. \\<not> 0 < n - Suc na \\<or> na < n \"\n                  using diff_Suc_eq_diff_pred zero_less_diff by presburger\n                then show ?thesis using True a21 i_m_l by force                  \n              qed                                                             \n              have \"Suc k < length ?m_lc1\" using True i_map length_c1_map by metis\n              then have \"(snd(?m_lc1!k), snd(?m_lc1!(Suc k))) \\<in> G\"\n              using a11' last_mcl1_not_F m_lc1_comm True i_map length_c1_map comm_dest1[of \\<Gamma>] \n                by blast\n              thus ?thesis using i_m_l True by auto  \n            next\n              case False                                            \n              have \"(Suc k=i) \\<or> (Suc k>i)\" using False by auto\n              thus ?thesis \n              proof\n              { assume suck:\"(Suc k=i)\" \n                then have k:\"k=i-1\" by auto                                                            \n                then show \"(snd (l!k), snd (l!Suc k)) \\<in> G\"\n                  using Gs2' Normals2 last_m_lc1 li suck by auto               \n              }\n              next\n              { \n                assume a001:\"Suc k>i\"\n                then have k:\"k\\<ge>i\" by fastforce\n                then obtain k' where k':\"k=i+k'\" \n                  using add.commute le_Suc_ex by blast\n                {assume skip:\"c2=Skip\"\n                 then have \"\\<forall>k. k\\<ge>i \\<and> (Suc k < length l) \\<longrightarrow> \n                            \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n                  using Normals2 li lastlc1_normal a21 a001 a00 a4\n                        a0 skip env_tran_right cp\n                  by (metis SmallStepCon.final_def SmallStepCon.no_step_final' Suc_lessD skip_com_all_skip)                                      \n                 then have ?thesis using a21 a001 k a00 by blast\n                }  note left=this\n                {assume \"c2\\<noteq>Skip\"\n                 then have \"fst (last lc1) = Throw\"\n                   using last_m_lc1 last_lc1 by simp                                     \n                 then have s2_normal:\"s2 \\<in> Normal ` r\" \n                   using normal_last lastlc1_normal Normals2\n                   by fastforce\n                 have length_lc2:\"length l=i+length lc2\" \n                       using i_map cp_lc1 by fastforce\n                 have \"(\\<Gamma>,lc2) \\<in>  assum (r,R) F\" \n                 proof -\n                   have left:\"snd (lc2!0) \\<in> Normal ` r\" \n                     using li lc2_l s2_normal lc2_not_empty by fastforce \n                   {\n                     fix j\n                     assume j_len:\"Suc j<length lc2\" and\n                            j_step:\"\\<Gamma>\\<turnstile>\\<^sub>c(lc2!j)  \\<rightarrow>\\<^sub>e (lc2!(Suc j))\"                     \n                     then have suc_len:\"Suc (i + j)<length l\" using j_len length_lc2\n                       by fastforce\n                     also then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!(i+j))  \\<rightarrow>\\<^sub>e (l! (Suc (i+ j)))\"\n                        using lc2_l j_step j_len by fastforce\n                     ultimately have \"(snd(lc2!j), snd(lc2!(Suc j))) \\<in> R\"\n                        using assum suc_len lc2_l j_len cp by fastforce \n                   }\n                   then show ?thesis using left \n                     unfolding assum_def by fastforce\n                 qed\n                 also have \"(\\<Gamma>,lc2) \\<in> cp \\<Gamma> c2 s2\"\n                   using cp_lc1 i_map l_is last_conv_nth lc1_not_empty by fastforce\n                 ultimately have comm_lc2:\"(\\<Gamma>,lc2) \\<in>  comm (G, (q,a)) F\"\n                   using a3 unfolding com_validity_def by auto\n                 have lc2_last_f:\"snd (last lc2)\\<notin> Fault ` F\" \n                   using lc2_l lc2_not_empty l_f cp_lc1 by fastforce\n                 have suck':\"Suc k' < length lc2\" \n                   using k' a00 length_lc2 by arith\n                 moreover then have \"\\<Gamma>\\<turnstile>\\<^sub>c(lc2!k')  \\<rightarrow> (lc2!(Suc k'))\"  \n                   using k' lc2_l a21 by fastforce                 \n                 ultimately have \"(snd (lc2! k'), snd (lc2 ! Suc k')) \\<in> G\"\n                   using comm_lc2  lc2_last_f comm_dest1[of \\<Gamma> lc2 G q a F k'] \n                   by blast\n                 then have ?thesis using suck' lc2_l k' by fastforce\n                }                    \n                then show ?thesis using left by auto                 \n              }\n              qed \n            qed\n          } thus ?thesis by auto \n         qed note left=this\n         have right:\"(final (last l)  \\<longrightarrow>                    \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a)))\"\n         proof -\n         { assume final_l:\"final (last l)\" \n           have eq_last_lc2_l:\"last l=last lc2\" by (simp add: cp_lc1 lc2_not_empty)\n           then have final_lc2:\"final (last lc2)\" using final_l by auto\n           {\n             assume lst_lc1_skip:\"fst (last lc1) = Skip\"                        \n             then have c2_skip:\"c2 = Skip\" \n               using  step lastlc1_normal LanguageCon.com.distinct(17) last_lc1 \n               by auto                            \n             have Skip:\"fst (l!(length l - 1)) = Skip\"\n             using li Normals2  env_tran_right cp c2_skip a0\n                     i_skip_all_skip[of \\<Gamma> l i \"(length l) - 1\" _] \n                by fastforce                       \n             have s2_a:\"s2 \\<in> Normal ` q\"\n               using normal_last \n               by (simp add: lst_lc1_skip l_is)\n             then have \"\\<forall>ia. i \\<le> ia \\<and> ia < length l - 1 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c l ! ia \\<rightarrow>\\<^sub>e l ! Suc ia\"\n               using c2_skip li Normals2 a0 cp env_tran_right  final_def\n               by (metis (no_types, hide_lams) One_nat_def SmallStepCon.no_step_final' \n                   Suc_lessD add.right_neutral add_Suc_right \n                   cptn_tran_ce_i i_skip_all_skip less_diff_conv step_ce_elim_cases)                           \n             then have \"snd (l!(length l - 1)) \\<in> Normal ` q \\<and> fst (l!(length l - 1)) = Skip\"               \n               using a0 s2_a li a4 env_tran_right stability[of q R l i \"(length l) -1\" _ \\<Gamma>] Skip                \n               by (metis One_nat_def Suc_pred length_greater_0_conv lessI linorder_not_less list.size(3) \n                   not_less0 not_less_eq_eq snd_conv)\n             then have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a))\" \n              using a0 by (metis last_conv_nth list.size(3) not_less0)                           \n          }  note left = this\n          {  assume \"fst (last lc1) = Throw\"                 \n             then have s2_normal:\"s2 \\<in> Normal ` r\" \n               using normal_last lastlc1_normal Normals2\n               by fastforce\n             have length_lc2:\"length l=i+length lc2\" \n                   using i_map cp_lc1 by fastforce\n             have \"(\\<Gamma>,lc2) \\<in>  assum (r,R) F\" \n             proof -\n               have left:\"snd (lc2!0) \\<in> Normal ` r\" \n                 using li lc2_l s2_normal lc2_not_empty by fastforce \n               {\n                 fix j\n                 assume j_len:\"Suc j<length lc2\" and\n                        j_step:\"\\<Gamma>\\<turnstile>\\<^sub>c(lc2!j)  \\<rightarrow>\\<^sub>e (lc2!(Suc j))\"\n                 \n                 then have suc_len:\"Suc (i + j)<length l\" using j_len length_lc2\n                   by fastforce\n                 also then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!(i+j))  \\<rightarrow>\\<^sub>e (l! (Suc (i+ j)))\"\n                    using lc2_l j_step j_len by fastforce\n                 ultimately have \"(snd(lc2!j), snd(lc2!(Suc j))) \\<in> R\"\n                    using assum suc_len lc2_l j_len cp by fastforce \n               }\n               then show ?thesis using left \n                 unfolding assum_def by fastforce\n             qed\n             also have \"(\\<Gamma>,lc2) \\<in> cp \\<Gamma> c2 s2\"\n               using cp_lc1 i_map l_is last_conv_nth lc1_not_empty by fastforce\n             ultimately have comm_lc2:\"(\\<Gamma>,lc2) \\<in>  comm (G, (q,a)) F\"\n               using a3 unfolding com_validity_def by auto\n             have lc2_last_f:\"snd (last lc2)\\<notin> Fault ` F\" \n               using lc2_l lc2_not_empty l_f cp_lc1 by fastforce             \n             then have \"((fst (last lc2) = Skip \\<and> \n                    snd (last lc2) \\<in> Normal ` q)) \\<or>\n                    (fst (last lc2) = Throw \\<and> \n                    snd (last lc2) \\<in> Normal ` (a))\" \n             using final_lc2 comm_lc2 unfolding comm_def by auto\n             then have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a))\" \n             using eq_last_lc2_l by auto\n          }\n          then have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a))\" \n            using left using last_lc1 by auto\n        } thus ?thesis by auto qed         \n     thus ?thesis using left l_f \\<Gamma>1 unfolding comm_def by force       \n       qed             \n     } thus ?thesis using \\<Gamma>1 unfolding comm_def by auto qed\n   } thus ?thesis by auto qed \n } thus ?thesis by (simp add: com_validity_def[of \\<Gamma>] com_cvalidity_def) \nqed\nlemma \"\\<forall>s t. (q imp I)(s,t) \\<longrightarrow> (q imp (I \\<and>*sep_true))(s,t)\"\nby (simp add: sep_conj_sep_true)\n\n\nlemma DynCom_sound: \n      \"(\\<forall>s \\<in> p. ((\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (c1 s) sat [p, R, G, q,a]) \\<and> \n                 (\\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> (c1 s) sat [p,R, G, q,a]))) \\<Longrightarrow>\n        (\\<forall>s. (Normal s, Normal s) \\<in> G) \\<Longrightarrow>\n       (Sta p R) \\<and> (Sta q R) \\<and> (Sta a R) \\<Longrightarrow>        \n        \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> (DynCom c1) sat [p,  R, G, q,a]\"\nproof -  \n  assume\n    a0:\"(\\<forall>s \\<in> p. ((\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (c1 s) sat [p, R, G, q,a]) \\<and> \n                 (\\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> (c1 s) sat [p, R, G, q,a])))\" and    \n    a1:\"\\<forall>s. (Normal s, Normal s) \\<in> G\" and  \n    a2: \"(Sta p R) \\<and> (Sta q R) \\<and> (Sta a R)\"               \n  { \n    fix s\n    assume all_DynCom:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"     \n    then have a0:\"(\\<forall>s \\<in> p. (\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (c1 s) sat [p, R, G, q,a]))\"\n      using a0 unfolding com_cvalidity_def by fastforce     \n    have \"cp \\<Gamma>(DynCom c1) s \\<inter> assum(p, R) F \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cp \\<Gamma> (DynCom c1) s\" and a11:\"c \\<in> assum(p, R) F\"\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have \"c \\<in> comm(G, (q,a)) F\"      \n      proof - \n      {assume l_f:\"snd (last l) \\<notin> Fault ` F\"       \n        have cp:\"l!0=(DynCom c1,s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\" \n          using a10 cp_def c_prod by fastforce\n        have \\<Gamma>1:\"(\\<Gamma>, l) = c\" using c_prod cp by blast\n        have assum:\"snd(l!0) \\<in> Normal ` (p) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n                   (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n       using a11 c_prod unfolding assum_def by simp\n       then have env_tran:\"env_tran \\<Gamma> p l R\" using env_tran_def cp by blast\n       then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n         using env_tran env_tran_right_def unfolding env_tran_def by auto\n       obtain ns where s_normal:\"s=Normal ns \\<and> ns\\<in> p\" \n         using cp assum by fastforce       \n       have concl:\"(\\<forall>i. Suc i<length l \\<longrightarrow> \n               \\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>             \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n       proof -\n       { fix k ns ns'\n         assume a00:\"Suc k<length l\" and\n                a21:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"                                     \n         obtain j where before_k_all_evnt:\"j\\<le>k \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n           using a00 a21 exist_first_comp_tran cp by blast\n         then obtain cj sj csj ssj where pair_j:\"(\\<Gamma>\\<turnstile>\\<^sub>c(cj,sj)  \\<rightarrow> (csj,ssj)) \\<and> cj = fst (l!j) \\<and> sj = snd (l!j) \\<and> csj = fst (l!(Suc j)) \\<and> ssj = snd(l!(Suc j))\"\n           by fastforce                                             \n         have k_basic:\"cj = (DynCom c1) \\<and> sj \\<in> Normal ` (p)\" \n           using  pair_j before_k_all_evnt a2 cp env_tran_right  assum a00 stability[of p R l 0 j j \\<Gamma>]\n           by force\n         then obtain s' where ss:\"sj = Normal s' \\<and> s'\\<in> (p)\" by auto \n         then have ssj_normal_s:\"ssj = Normal s'\" \n           using before_k_all_evnt k_basic pair_j a0 \n           by (metis snd_conv stepc_Normal_elim_cases(10))                     \n         have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n           using ss a2 unfolding Satis_def\n         proof (cases \"k=j\")   \n           case True                                  \n           have \"(Normal s', Normal s')\\<in>G\" using a1 by fastforce\n           thus \"(snd (l ! k), snd (l ! Suc k)) \\<in>  G\"\n             using pair_j k_basic True ss ssj_normal_s by auto\n         next\n           case False   \n           have j_k:\"j<k\" using  before_k_all_evnt False by fastforce                      \n           thus \"(snd (l ! k), snd (l ! Suc k)) \\<in> G\"\n           proof -\n             have j_length:\"Suc j < length l\" using a00 before_k_all_evnt by fastforce\n             have p1:\"s'\\<in>p \\<and> ssj=Normal s'\" using ss ssj_normal_s by fastforce\n             then have c1_valid:\"(\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (c1 s') sat [p, R, G, q,a])\"\n               using a0 by fastforce\n             have cj:\"csj= (c1 s')\" using k_basic pair_j ss a0 s_normal\n             proof -\n               have \"\\<Gamma>\\<turnstile>\\<^sub>c (LanguageCon.com.DynCom c1, Normal s') \\<rightarrow> (csj, ssj)\"\n                 using k_basic pair_j ss by force\n               then have \"(csj, ssj) = (c1 s', Normal s')\"\n                 by (meson stepc_Normal_elim_cases(10))\n               then show ?thesis\n                 by blast\n             qed                                                       \n             moreover then have \"cp \\<Gamma> csj ssj \\<inter> assum(p, R) F \\<subseteq> comm(G, (q,a)) F\"\n               using a2 com_validity_def cj p1 c1_valid by blast\n             moreover then have \"l!(Suc j) = (csj, Normal s')\" \n               using before_k_all_evnt pair_j cj ssj_normal_s\n               by fastforce\n             ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n               using  p1 j_length a10 a11 \\<Gamma>1  ssj_normal_s\n                     cptn_assum_induct[of \\<Gamma> l \"DynCom c1\" s p R F \"Suc j\" \"c1 s'\" s' p]\n               by blast                         \n             then show ?thesis \n             using a00 a21  a10 \\<Gamma>1  j_k j_length l_f\n             cptn_comm_induct[of \\<Gamma> l \"DynCom c1\" s _ \"Suc j\" G q a F k ]\n             unfolding Satis_def by fastforce                         \n          qed            \n       qed \n       } thus ?thesis by (simp add: c_prod cp) qed\n       have concr:\"(final (last l)  \\<longrightarrow>                   \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a)))\"\n       proof-\n       { \n         assume valid:\"final (last l)\"                       \n         have \"\\<exists>k. k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final (l!(Suc k))\"\n         proof -             \n           have len_l:\"length l > 0\" using cp using cptn.simps by blast \n           then obtain a1 l1 where l:\"l=a1#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n           have last_l:\"last l = l!(length l-1)\"\n            using last_length [of a1 l1] l by fastforce         \n           have final_0:\"\\<not>final(l!0)\" using cp unfolding final_def by auto\n           have \"0\\<le> (length l-1)\" using len_l last_l by auto\n           moreover have \"(length l-1) < length l\" using len_l by auto\n           moreover have \"final (l!(length l-1))\" using valid last_l by auto\n           moreover have \"fst (l!0) = DynCom c1\" using cp by auto\n           ultimately show ?thesis \n             using a2 cp final_exist_component_tran_final env_tran_right final_0 \n             by blast \n          qed\n          then obtain k where a21: \"k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final (l!(Suc k))\"\n            by auto\n          then have a00:\"Suc k<length l\" by fastforce\n          then obtain j where before_k_all_evnt:\"j\\<le>k \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n            using a00 a21 exist_first_comp_tran cp by blast\n          then obtain cj sj csj ssj where pair_j:\"(\\<Gamma>\\<turnstile>\\<^sub>c(cj,sj)  \\<rightarrow> (csj,ssj)) \\<and> cj = fst (l!j) \\<and> sj = snd (l!j) \\<and> csj = fst (l!(Suc j)) \\<and> ssj = snd(l!(Suc j))\"\n            by fastforce         \n          have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a))\"\n          proof -\n            have j_length:\"Suc j < length l\" using a00 before_k_all_evnt by fastforce                                 \n            then have k_basic:\"cj = (DynCom c1) \\<and> sj \\<in> Normal ` (p)\" \n              using a2 pair_j before_k_all_evnt cp env_tran_right assum stability[of p R l 0 j j \\<Gamma>]\n              by force\n            then obtain s' where ss:\"sj = Normal s' \\<and> s'\\<in> (p)\" by auto \n            then have ssj_normal_s:\"ssj = Normal s'\" \n              using before_k_all_evnt k_basic pair_j a0 \n              by (metis snd_conv stepc_Normal_elim_cases(10))\n            have cj:\"csj=c1 s'\" using k_basic pair_j ss a0\n              by (metis fst_conv stepc_Normal_elim_cases(10))                \n            moreover have p1:\"s'\\<in>p\" using ss by blast \n            moreover then have \"cp \\<Gamma> csj ssj \\<inter> assum(p, R) F \\<subseteq> comm(G, (q,a)) F\"\n              using a0 com_validity_def cj by blast\n            moreover then have \"l!(Suc j) = (csj, Normal s')\" \n              using before_k_all_evnt pair_j cj ssj_normal_s\n              by fastforce\n            ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n              using  j_length a10 a11 \\<Gamma>1  ssj_normal_s\n              cptn_assum_induct[of \\<Gamma> l \"DynCom c1\" s p R F \"Suc j\" \"c1 s'\" s' p]\n              by blast    \n            thus ?thesis       \n              using j_length l_f drop_comm a10 \\<Gamma>1 cptn_comm_induct[of \\<Gamma> l \"DynCom c1\" s _ \"Suc j\" G q a F \"Suc j\"] valid  \n              by blast\n           qed\n         } thus ?thesis by auto \n         qed\n       note res = conjI [OF concl concr]}               \n       thus ?thesis using  c_prod unfolding comm_def by force qed      \n    } thus ?thesis by auto qed \n  } thus ?thesis by (auto simp add: com_validity_def[of \\<Gamma>] com_cvalidity_def) \nqed\n\nlemma Guard_sound:\n  \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> g, R, G, q,a] \\<Longrightarrow>\n   \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> g, R, G, q,a] \\<Longrightarrow>   \n   Sta (p \\<inter> g) R \\<Longrightarrow> (\\<forall>s. (Normal s, Normal s) \\<in> G) \\<Longrightarrow>\n    \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> (Guard f g c1) sat [p \\<inter> g, R, G, q,a]\"\nproof -  \n  assume\n    a0:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [(p \\<inter> g) , R, G, q,a]\" and\n    a1:\"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> g, R, G, q,a]\" and        \n    a2: \"Sta (p \\<inter> g) R\" and\n    a3: \"\\<forall>s. (Normal s, Normal s) \\<in> G\"\n  { \n    fix s\n    assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"  \n    then have a1:\"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> g, R, G, q,a]\" \n      using a1 com_cvalidity_def by fastforce\n    have \"cp \\<Gamma> (Guard f g c1)  s \\<inter> assum(p \\<inter> g, R) F \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cp \\<Gamma> (Guard f g c1) s\" and a11:\"c \\<in> assum(p \\<inter> g, R) F\"\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have \"c \\<in> comm(G, (q,a)) F\"      \n      proof - \n      {assume l_f:\"snd (last l) \\<notin> Fault ` F\"       \n        have cp:\"l!0=((Guard f g c1),s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\" using a10 cp_def c_prod by fastforce\n        have \\<Gamma>1:\"(\\<Gamma>, l) = c\" using c_prod cp by blast\n        have assum:\"snd(l!0) \\<in> Normal ` (p \\<inter> g) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n                   (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n       using a11 c_prod unfolding assum_def by simp\n       then have env_tran:\"env_tran \\<Gamma> (p \\<inter> g) l R\" using env_tran_def cp by blast\n       then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n         using env_tran env_tran_right_def unfolding env_tran_def by auto\n       have concl:\"(\\<forall>i. Suc i<length l \\<longrightarrow> \n               \\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                                            \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n       proof -\n       { fix k ns ns'\n         assume a00:\"Suc k<length l\" and\n                a21:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"                                                        \n         obtain j where before_k_all_evnt:\"j\\<le>k \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n           using a00 a21 exist_first_comp_tran cp by blast\n         then obtain cj sj csj ssj where pair_j:\"(\\<Gamma>\\<turnstile>\\<^sub>c(cj,sj)  \\<rightarrow> (csj,ssj)) \\<and> cj = fst (l!j) \\<and> sj = snd (l!j) \\<and> csj = fst (l!(Suc j)) \\<and> ssj = snd(l!(Suc j))\"\n           by fastforce                                             \n         have k_basic:\"cj =(Guard f g c1) \\<and> sj \\<in> Normal ` (p \\<inter> g)\" \n           using  pair_j before_k_all_evnt cp env_tran_right a2 assum a00 stability[of \"p \\<inter> g\" R l 0 j j \\<Gamma>]\n           by force\n         then obtain s' where ss:\"sj = Normal s' \\<and> s'\\<in> (p \\<inter> g)\" by auto \n         then have ssj_normal_s:\"ssj = Normal s'\" \n           using before_k_all_evnt k_basic pair_j a0 stepc_Normal_elim_cases(2)\n           by (metis (no_types, lifting)  IntD2 prod.inject)                                \n         have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n           using ss a2 unfolding Satis_def\n         proof (cases \"k=j\")   \n           case True                                  \n           have \" (Normal s', Normal s')\\<in>G\" using a3 by auto \n           thus \"(snd (l ! k), snd (l ! Suc k)) \\<in>  G\"\n             using pair_j k_basic True ss ssj_normal_s by auto\n         next\n           case False   \n           have j_k:\"j<k\" using  before_k_all_evnt False by fastforce                      \n           thus \"(snd (l ! k), snd (l ! Suc k)) \\<in>  G\"\n           proof -\n             have j_length:\"Suc j < length l\" using a00 before_k_all_evnt by fastforce\n             have cj:\"csj=c1\" using k_basic pair_j ss a0\n               by (metis (no_types, lifting) IntD2 fst_conv stepc_Normal_elim_cases(2))                             \n             moreover have p1:\"s' \\<in> (p \\<inter> g)\" using ss by blast \n             moreover then have \"cp \\<Gamma> csj ssj \\<inter> assum(p \\<inter> g, R) F \\<subseteq> comm(G, (q,a)) F\"\n               using a1 com_validity_def cj by blast\n             moreover then have \"l!(Suc j) = (csj, Normal s')\" \n               using before_k_all_evnt pair_j cj ssj_normal_s\n               by fastforce\n             ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n               using  j_length a10 a11 \\<Gamma>1  ssj_normal_s\n                     cptn_assum_induct[of \\<Gamma> l \" (Guard f g c1)\" s \"(p \\<inter> g)\" R F \"Suc j\" c1 s' \"p \\<inter> g\"]\n               by blast                         \n             then show ?thesis \n             using a00 a21  a10 \\<Gamma>1  j_k j_length l_f\n             cptn_comm_induct[of \\<Gamma> l \"(Guard f g c1)\" s _ \"Suc j\" G q a F k ]\n             unfolding Satis_def by fastforce                         \n          qed            \n       qed \n       } thus ?thesis by (simp add: c_prod cp) qed\n       have concr:\"(final (last l)  \\<longrightarrow>                   \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a)))\"\n       proof-\n       { \n         assume valid:\"final (last l)\"                       \n         have \"\\<exists>k. k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final (l!(Suc k))\"\n         proof -             \n           have len_l:\"length l > 0\" using cp using cptn.simps by blast \n           then obtain a1 l1 where l:\"l=a1#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n           have last_l:\"last l = l!(length l-1)\"\n            using last_length [of a1 l1] l by fastforce         \n           have final_0:\"\\<not>final(l!0)\" using cp unfolding final_def by auto\n           have \"0\\<le> (length l-1)\" using len_l last_l by auto\n           moreover have \"(length l-1) < length l\" using len_l by auto\n           moreover have \"final (l!(length l-1))\" using valid last_l by auto\n           moreover have \"fst (l!0) = (Guard f g c1)\" using cp by auto\n           ultimately show ?thesis \n             using  cp final_exist_component_tran_final env_tran_right final_0 \n             by blast \n          qed\n          then obtain k where a21: \"k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final (l!(Suc k))\"\n            by auto\n          then have a00:\"Suc k<length l\" by fastforce\n          then obtain j where before_k_all_evnt:\"j\\<le>k \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n            using a00 a21 exist_first_comp_tran cp by blast\n          then obtain cj sj csj ssj where pair_j:\"(\\<Gamma>\\<turnstile>\\<^sub>c(cj,sj)  \\<rightarrow> (csj,ssj)) \\<and> cj = fst (l!j) \\<and> sj = snd (l!j) \\<and> csj = fst (l!(Suc j)) \\<and> ssj = snd(l!(Suc j))\"\n            by fastforce         \n          have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a))\"\n          proof -\n            have j_length:\"Suc j < length l\" using a00 before_k_all_evnt by fastforce                                 \n            then have k_basic:\"cj = (Guard f g c1) \\<and> sj \\<in> Normal ` (p \\<inter> g)\" \n              using  pair_j before_k_all_evnt cp env_tran_right a2 assum a00 stability[of \"p \\<inter> g\" R l 0 j j \\<Gamma>]\n              by force\n            then obtain s' where ss:\"sj = Normal s' \\<and> s'\\<in> (p \\<inter> g)\" by auto \n            then have ssj_normal_s:\"ssj = Normal s'\" \n              using before_k_all_evnt k_basic pair_j a1\n              by (metis (no_types, lifting) IntD2 Pair_inject stepc_Normal_elim_cases(2))               \n            have cj:\"csj=c1\" using k_basic pair_j ss a0\n              by (metis (no_types, lifting) fst_conv IntD2 stepc_Normal_elim_cases(2))                              \n            moreover have p1:\"s' \\<in> (p \\<inter> g)\" using ss by blast \n            moreover then have \"cp \\<Gamma> csj ssj \\<inter> assum((p \\<inter> g), R) F \\<subseteq> comm(G, (q,a)) F\"\n              using a1 com_validity_def cj by blast\n            moreover then have \"l!(Suc j) = (csj, Normal s')\" \n              using before_k_all_evnt pair_j cj ssj_normal_s\n              by fastforce\n            ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n              using  j_length a10 a11 \\<Gamma>1  ssj_normal_s\n              cptn_assum_induct[of \\<Gamma> l \"(Guard f g c1)\" s \"(p \\<inter> g)\" R F \"Suc j\" c1 s' \"(p \\<inter> g)\"]\n              by blast    \n            thus ?thesis       \n              using j_length l_f drop_comm a10 \\<Gamma>1 cptn_comm_induct[of \\<Gamma> l \"(Guard f g c1)\" s _ \"Suc j\" G q a F \"Suc j\"] valid  \n              by blast\n           qed\n         } thus ?thesis by auto \n         qed\n       note res = conjI [OF concl concr]}               \n       thus ?thesis using  c_prod unfolding comm_def by force qed      \n    } thus ?thesis by auto qed \n  } thus ?thesis by (simp add: com_validity_def[of \\<Gamma>] com_cvalidity_def) \nqed\n\n\nlemma Guarantee_sound:\n  \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [(p \\<inter> g),  R, G, q,a] \\<Longrightarrow>\n   \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> c1 sat [(p \\<inter> g), R, G, q,a] \\<Longrightarrow>  \n   Sta p R \\<Longrightarrow> \n   f\\<in>F \\<Longrightarrow>\n   (\\<forall>s. (Normal s, Normal s) \\<in> G) \\<Longrightarrow> \n   \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> (Guard f g c1) sat [p, R, G, q,a]\"\nproof -  \n  assume\n    a0:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> g, R, G, q,a]\" and\n    a1:\"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> g, R, G, q,a]\" and      \n    a2: \"Sta p R\" and\n    a3: \"(\\<forall>s. (Normal s, Normal s) \\<in> G)\" and\n    a4: \"f\\<in>F\"    \n  { \n    fix s\n    assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"  \n    then have a1:\"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> g, R, G, q,a]\" \n      using a1 com_cvalidity_def by fastforce\n    have \"cp \\<Gamma> (Guard f g c1)  s \\<inter> assum(p, R) F \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cp \\<Gamma> (Guard f g c1) s\" and a11:\"c \\<in> assum(p, R) F\"\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have \"c \\<in> comm(G, (q,a)) F\"      \n      proof - \n      {assume l_f:\"snd (last l) \\<notin> Fault ` F\"       \n        have cp:\"l!0=((Guard f g c1),s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\" using a10 cp_def c_prod by fastforce\n        have \\<Gamma>1:\"(\\<Gamma>, l) = c\" using c_prod cp by blast\n        have assum:\"snd(l!0) \\<in> Normal ` (p) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n                   (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n       using a11 c_prod unfolding assum_def by simp\n       then have env_tran:\"env_tran \\<Gamma> p l R\" using env_tran_def cp by blast\n       then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n         using env_tran env_tran_right_def unfolding env_tran_def by auto                     \n       have concl:\"(\\<forall>i ns ns'. Suc i<length l \\<longrightarrow> \n               \\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                 \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n       proof -\n       { fix k ns ns'\n         assume a00:\"Suc k<length l\" and\n                a21:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"                                         \n         obtain j where before_k_all_evnt:\"j\\<le>k \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n           using a00 a21 exist_first_comp_tran cp by blast\n         then obtain cj sj csj ssj where pair_j:\"(\\<Gamma>\\<turnstile>\\<^sub>c(cj,sj)  \\<rightarrow> (csj,ssj)) \\<and> cj = fst (l!j) \\<and> sj = snd (l!j) \\<and> csj = fst (l!(Suc j)) \\<and> ssj = snd(l!(Suc j))\"\n           by fastforce                                                               \n         have k_basic:\"cj =(Guard f g c1) \\<and> sj \\<in> Normal ` (p)\" \n           using  pair_j before_k_all_evnt cp env_tran_right a2 assum a00 stability[of p R l 0 j j \\<Gamma>]\n           by force\n         then obtain s' where ss:\"sj = Normal s' \\<and> s'\\<in> (p)\" by auto          \n         have or:\"s'\\<in> (g \\<union> (-g))\" by fastforce\n         {assume \"s' \\<in> g\"\n          then have k_basic:\"cj =(Guard f g c1) \\<and> sj \\<in> Normal ` (p \\<inter> g)\" \n            using ss k_basic by fastforce\n          then have ss: \"sj = Normal s' \\<and> s'\\<in>  (p \\<inter> g)\"\n            using ss by fastforce\n          have ssj_normal_s:\"ssj = Normal s'\" \n           using ss before_k_all_evnt k_basic pair_j a0 stepc_Normal_elim_cases(2)\n           by (metis (no_types, lifting) IntD2 prod.inject)                                \n          have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n           using ss a2 unfolding Satis_def\n         proof (cases \"k=j\")   \n           case True                                  \n           have \"(Normal s', Normal s') \\<in> G\" using a3 by auto\n           thus \"(snd (l ! k), snd (l ! Suc k)) \\<in>  G\"\n             using pair_j k_basic True ss ssj_normal_s by auto\n         next\n           case False   \n           have j_k:\"j<k\" using  before_k_all_evnt False by fastforce                      \n           thus \"(snd (l ! k), snd (l ! Suc k)) \\<in>  G\"\n           proof -\n             have j_length:\"Suc j < length l\" using a00 before_k_all_evnt by fastforce\n             have cj:\"csj=c1\" using k_basic pair_j ss a0\n               by (metis (no_types, lifting) fst_conv IntD2 stepc_Normal_elim_cases(2))                             \n             moreover have p1:\"s' \\<in> (p \\<inter> g)\" using ss by blast \n             moreover then have \"cp \\<Gamma> csj ssj \\<inter> assum((p \\<inter> g), R) F \\<subseteq> comm(G, (q,a)) F\"\n               using a1 com_validity_def cj by blast\n             moreover then have \"l!(Suc j) = (csj, Normal s')\" \n               using before_k_all_evnt pair_j cj ssj_normal_s\n               by fastforce\n             ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n               using  j_length a10 a11 \\<Gamma>1  ssj_normal_s\n                     cptn_assum_induct[of \\<Gamma> l \" (Guard f g c1)\" s \"p\" R F \"Suc j\" c1 s' \"(p \\<inter> g)\"]\n               by blast                         \n              then show ?thesis \n              using a3 a00 a21  a10 \\<Gamma>1  j_k j_length l_f\n               cptn_comm_induct[of \\<Gamma> l \"(Guard f g c1)\" s _ \"Suc j\" G q a F k]\n              unfolding Satis_def by fastforce                         \n            qed            \n          qed\n         } note p1=this\n         {assume \"s' \\<in> (Collect (not (set_fun g)))\"\n          then have \"s'\\<notin>g\" by fastforce\n          then have csj_skip:\"csj= Skip \\<and> ssj=Fault f\" using k_basic ss pair_j \n            by (meson Pair_inject stepc_Normal_elim_cases(2))\n          then have \"snd (last l) = Fault f\" using pair_j\n          proof -\n            have \"j = k\" \n            proof -\n              have f1: \"k < length l\"\n                using a00 by linarith\n              have \"\\<not> SmallStepCon.final (l ! k)\"\n                by (metis SmallStepCon.no_step_final' a21)\n              then have \"\\<not> Suc j \\<le> k\"\n                using f1 SmallStepCon.final_def cp csj_skip i_skip_all_skip pair_j by blast\n              then show ?thesis\n                by (metis Suc_leI before_k_all_evnt le_eq_less_or_eq)\n            qed\n            then have False\n              using pair_j csj_skip by (metis a00 a4 cp image_eqI l_f last_not_F)\n            then show ?thesis\n              by metis\n          qed\n          then have False using a4 l_f by auto          \n         }\n         then have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n           using p1 or by fastforce\n       } thus ?thesis by (simp add: c_prod cp) qed\n       have concr:\"(final (last l)  \\<longrightarrow>                   \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a)))\"\n       proof-\n       { \n         assume valid:\"final (last l)\"                       \n         have \"\\<exists>k. k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final (l!(Suc k))\"\n         proof -             \n           have len_l:\"length l > 0\" using cp using cptn.simps by blast \n           then obtain a1 l1 where l:\"l=a1#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n           have last_l:\"last l = l!(length l-1)\"\n            using last_length [of a1 l1] l by fastforce         \n           have final_0:\"\\<not>final(l!0)\" using cp unfolding final_def by auto\n           have \"0\\<le> (length l-1)\" using len_l last_l by auto\n           moreover have \"(length l-1) < length l\" using len_l by auto\n           moreover have \"final (l!(length l-1))\" using valid last_l by auto\n           moreover have \"fst (l!0) = (Guard f g c1)\" using cp by auto\n           ultimately show ?thesis \n             using  cp final_exist_component_tran_final env_tran_right final_0 \n             by blast \n          qed\n          then obtain k where a21: \"k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final (l!(Suc k))\"\n            by auto\n          then have a00:\"Suc k<length l\" by fastforce\n          then obtain j where before_k_all_evnt:\"j\\<le>k \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n            using a00 a21 exist_first_comp_tran cp by blast\n          then obtain cj sj csj ssj where pair_j:\"(\\<Gamma>\\<turnstile>\\<^sub>c(cj,sj)  \\<rightarrow> (csj,ssj)) \\<and> cj = fst (l!j) \\<and> sj = snd (l!j) \\<and> csj = fst (l!(Suc j)) \\<and> ssj = snd(l!(Suc j))\"\n            by fastforce         \n          have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a))\"\n          proof -\n            have j_length:\"Suc j < length l\" using a00 before_k_all_evnt by fastforce                                 \n            have k_basic:\"cj =(Guard f g c1) \\<and> sj \\<in> Normal ` (p)\" \n             using  pair_j before_k_all_evnt cp env_tran_right a2 assum a00 stability[of p R l 0 j j \\<Gamma>]\n             by force\n            then obtain s' where ss:\"sj = Normal s' \\<and> s'\\<in> (p)\" by auto \n            have or:\"s'\\<in> (g \\<union> (-g))\" by fastforce\n            {assume \"s' \\<in> g\"\n             then have k_basic:\"cj =(Guard f g c1) \\<and> sj \\<in> Normal ` (p \\<inter> g)\" \n               using ss k_basic by fastforce\n             then have ss: \"sj = Normal s' \\<and> s'\\<in> (p \\<inter> g)\"\n               using ss by fastforce\n             then have ssj_normal_s:\"ssj = Normal s'\" \n              using before_k_all_evnt k_basic pair_j a1\n              by (metis (no_types, lifting) Pair_inject IntD2 stepc_Normal_elim_cases(2))               \n             have cj:\"csj=c1\" using k_basic pair_j ss a0\n              by (metis (no_types, lifting) fst_conv IntD2 stepc_Normal_elim_cases(2))                              \n             moreover have p1:\"s'\\<in>(p \\<inter> g)\" using ss by blast \n             moreover then have \"cp \\<Gamma> csj ssj \\<inter> assum((p \\<inter> g), R) F \\<subseteq> comm(G, (q,a)) F\"\n               using a1 com_validity_def cj by blast\n             moreover then have \"l!(Suc j) = (csj, Normal s')\" \n               using before_k_all_evnt pair_j cj ssj_normal_s\n               by fastforce\n             ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n               using  j_length a10 a11 \\<Gamma>1  ssj_normal_s\n               cptn_assum_induct[of \\<Gamma> l \"(Guard f g c1)\" s \"p\" R F \"Suc j\" c1 s' \"(p \\<inter> g)\"]\n               by blast                 \n            then have ?thesis       \n              using j_length l_f drop_comm a10 \\<Gamma>1 cptn_comm_induct[of \\<Gamma> l \"(Guard f g c1)\" s _ \"Suc j\" G q a F \"Suc j\"] valid  \n              by blast\n           }note left=this        \n           {\n            assume \"s' \\<in> (Collect (not (set_fun g)))\"\n            then have \"s'\\<notin>g\" by fastforce\n          then have \"csj= Skip \\<and> ssj=Fault f\" using k_basic ss pair_j \n            by (meson Pair_inject stepc_Normal_elim_cases(2))\n          then have \"snd (last l) = Fault f\" using pair_j\n            by (metis a4 cp imageI j_length l_f last_not_F)            \n          then have False using a4 l_f by auto           \n           }\n           thus ?thesis using or left by auto qed\n         } thus ?thesis by auto \n         qed\n       note res = conjI [OF concl concr]}               \n       thus ?thesis using  c_prod unfolding comm_def by force qed      \n    } thus ?thesis by auto qed \n  } thus ?thesis by (simp add: com_validity_def[of \\<Gamma>] com_cvalidity_def) \nqed\n\nlemma WhileNone:   \n   \"\\<Gamma>\\<turnstile>\\<^sub>c (While b c1, s1) \\<rightarrow> (LanguageCon.com.Skip, t1) \\<Longrightarrow>   \n    (\\<Gamma>, (Skip, t1) # xsa) \\<in> cptn \\<Longrightarrow>  \n    \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b,R, G, p,a] \\<Longrightarrow>\n    Sta p R \\<Longrightarrow>\n    Sta (p \\<inter> (-b)) R \\<Longrightarrow>\n    Sta a R \\<Longrightarrow>\n    (\\<forall>s. (Normal s, Normal s) \\<in> G) \\<Longrightarrow>            \n    (\\<Gamma>, (While b c1, s1) # (LanguageCon.com.Skip, t1) # xsa) \\<in> assum (p, R) F \\<Longrightarrow> \n    (\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p , R, G, q,a]) \\<Longrightarrow>     \n    (\\<Gamma>, (While b c1, s1) # (LanguageCon.com.Skip, t1) # xsa) \\<in> comm (G,(p \\<inter> (-b)),a) F\"\nproof -\n  assume a0:\"\\<Gamma>\\<turnstile>\\<^sub>c (While b c1, s1) \\<rightarrow> (LanguageCon.com.Skip, t1)\" and\n         a1:\"(\\<Gamma>, (Skip, t1) # xsa) \\<in> cptn\" and\n         a2:\" \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b,R, G, p,a]\" and\n         a3:\"Sta p R\" and\n         a4:\"Sta (p \\<inter> (-b)) R\" and\n         a5:\"Sta a R\" and\n         a6:\"\\<forall>s. (Normal s, Normal s) \\<in> G\" and\n         a7:\"(\\<Gamma>, (While b c1, s1) # (LanguageCon.com.Skip, t1) # xsa) \\<in> assum (p, R) F\" and\n         a8:\"(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p , R, G, q,a])\"\n  obtain s1' where s1N:\"s1=Normal s1' \\<and> s1'\\<in>p\" using a7 unfolding assum_def by fastforce\n  then have s1_t1:\"s1'\\<notin> b \\<and> t1=s1\" using a0\n    using LanguageCon.com.distinct(5) prod.inject \n    by (fastforce elim:stepc_Normal_elim_cases(7))\n  then have t1_Normal_post:\"t1\\<in> Normal ` (p \\<inter> (-b))\"\n    using s1N by fastforce\n  also have \"(\\<Gamma>, (While b c1, s1) # (LanguageCon.com.Skip, t1) # xsa)\\<in>cptn\"\n    using a1 a0 cptn.simps by fastforce\n  ultimately have assum_skip:\n    \"(\\<Gamma>,(LanguageCon.com.Skip, t1) # xsa) \\<in> assum (( p \\<inter> (-b)), R) F\"\n    using a1 a7 tl_of_assum_in_assum1 t1_Normal_post by fastforce\n  have skip_comm:\"(\\<Gamma>,(LanguageCon.com.Skip, t1) # xsa) \\<in> \n               comm (G,(( p \\<inter> (-b)),a)) F\" \n  proof- \n    have \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> Skip sat [( p \\<inter> (-b)), R, G, ( p \\<inter> (-b)),a]\"\n      using Skip_sound[of \"(p \\<inter> - b)\"]  a4 a6 by blast\n    thus ?thesis\n      using assum_skip cp_def a1 a8 unfolding com_cvalidity_def com_validity_def\n      by fastforce\n  qed    \n  have G_ref:\"(Normal s1', Normal s1')\\<in>G\" using a6 by fastforce\n  thus ?thesis using skip_comm ctran_in_comm[of s1'] s1N s1_t1 by blast\nqed \n\nlemma while1:\n   \"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> cptn_mod \\<Longrightarrow>    \n    s1 \\<in> b \\<Longrightarrow>\n    xsa = map (lift (While b c)) xs1 \\<Longrightarrow>\n    \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> c sat [p \\<inter> b,R, G, p,a] \\<Longrightarrow>    \n    (\\<Gamma>, (While b c, Normal s1) #\n        (Seq c (LanguageCon.com.While b c), Normal s1) # xsa)\n       \\<in> assum (p, R) F \\<Longrightarrow>               \n    \\<forall>s. (Normal s, Normal s) \\<in> G \\<Longrightarrow> \n     (\\<Gamma>, (LanguageCon.com.While b c, Normal s1) #\n         (LanguageCon.com.Seq c (LanguageCon.com.While b c), Normal s1) # xsa)\n    \\<in> comm (G, p\\<inter>(-b), a) F\"\nproof -\nassume   \n  a0:\"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> cptn_mod\" and\n  a1:\"s1 \\<in> b\" and\n  a2:\"xsa = map (lift (While b c)) xs1\" and\n  a3:\"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> c sat [p \\<inter> b,R, G, p,a]\" and\n  a4:\"(\\<Gamma>, (While b c, Normal s1) #\n        (Seq c (While b c), Normal s1) # xsa)\n       \\<in> assum (p, R) F\" and  \n  a5:\"\\<forall>s. (Normal s,Normal s) \\<in> G\" \n  have seq_map:\"(Seq c (While b c), Normal s1) # xsa=\n           map (lift (While b c)) ((c,Normal s1)#xs1)\"\n  using a2 unfolding lift_def by fastforce\n  have step:\"\\<Gamma>\\<turnstile>\\<^sub>c(While b c,Normal s1) \\<rightarrow> (Seq c (While b c),Normal s1)\" using a1\n    WhileTruec by fastforce\n  have s1_normal:\"s1 \\<in> p \\<and> s1 \\<in> b \" using a4 a1 unfolding assum_def by fastforce\n  then have G_ref:\"(Normal s1, Normal s1) \\<in> G\"  using a5 by fastforce \n  have s1_collect_p: \"Normal s1\\<in> Normal ` (p \\<inter> b)\" using s1_normal by fastforce\n  have \"(\\<Gamma>, map (lift (While b c)) ((c,Normal s1)#xs1))\\<in>cptn\" \n    using a2 cptn_eq_cptn_mod lift_is_cptn a0 by fastforce\n  then have cptn_seq:\"(\\<Gamma>,(Seq c (While b c), Normal s1) # xsa) \\<in>cptn\" \n    using seq_map by auto\n  then have \"(\\<Gamma>, (While b c, Normal s1) # (Seq c (While b c), Normal s1) # xsa) \\<in> cptn\"\n    using step by (simp add: cptn.CptnComp) \n  then have assum_seq:\"(\\<Gamma>,(Seq c (While b c), Normal s1) # xsa)\\<in>assum (p, R) F\"\n    using a4 tl_of_assum_in_assum1 s1_collect_p by fastforce\n  have cp_c:\"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> (cp \\<Gamma> c (Normal s1))\"\n    using a0[THEN cptn_if_cptn_mod] unfolding cp_def by fastforce\n  also have cp_seq:\"(\\<Gamma>, (Seq c (While b c), Normal s1) # xsa) \\<in> (cp \\<Gamma> (Seq c (While b c)) (Normal s1))\"\n    using cptn_seq unfolding cp_def by fastforce\n  ultimately have \"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> assum(p,R) F\"  \n    using assum_map assum_seq seq_map by fastforce  \n  then have \"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> assum((p \\<inter> b),R) F\"\n    unfolding assum_def using s1_collect_p by fastforce\n  then have \"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> comm(G,(p,a)) F\"\n    using a3 cp_c unfolding com_validity_def by fastforce\n  then have \"(\\<Gamma>, (Seq c (While b c), Normal s1) # xsa) \\<in> comm(G,(p,a)) F\"\n    using cp_seq cp_c comm_map seq_map by fastforce\n  then have \"(\\<Gamma>, (While b c, Normal s1) # (Seq c (While b c), Normal s1) # xsa) \\<in> comm(G,(p,a)) F\"\n    using G_ref ctran_in_comm by fastforce\n  also have \"\\<not> final (last ((While b c, Normal s1) # (Seq c (While b c), Normal s1) # xsa))\"\n    using seq_map unfolding final_def lift_def  by (simp add: case_prod_beta' last_map)  \n  ultimately show ?thesis using not_final_in_comm[of \\<Gamma>] by blast\nqed\n\nlemma while2:\n   \" (\\<Gamma>, (While b c, Normal s1) #\n         (Seq c (While b c), Normal s1) # xsa) \\<in>cptn \\<Longrightarrow>\n    (\\<Gamma>, (c, Normal s1) # xs1) \\<in> cptn_mod \\<Longrightarrow>\n    fst (last ((c, Normal s1) # xs1)) = LanguageCon.com.Skip \\<Longrightarrow>\n    s1 \\<in> b \\<Longrightarrow>\n    xsa = map (lift (While b c)) xs1 @\n    (While b c, snd (last ((c, Normal s1) # xs1))) # ys \\<Longrightarrow>\n    (\\<Gamma>, (While b c, snd (last ((c, Normal s1) # xs1))) # ys)\n      \\<in> cptn_mod \\<Longrightarrow>\n     (\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> c sat [p \\<inter> b, R, G, p,a] \\<Longrightarrow>    \n       (\\<Gamma>, (While b c, snd (last ((c, Normal s1) # xs1))) # ys)\n         \\<in> assum (p, R) F \\<Longrightarrow>\n       (\\<Gamma>, (While b c, snd (last ((c, Normal s1) # xs1))) # ys)\n          \\<in> comm (G, p \\<inter> (-b), a) F) \\<Longrightarrow>\n    \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> c sat [ p \\<inter> b, R, G, p,a] \\<Longrightarrow>\n    (\\<Gamma>, (While b c, Normal s1) #\n      (Seq c (While b c), Normal s1) # xsa)\n      \\<in> assum (p, R) F \\<Longrightarrow>\n     \\<forall>s. (Normal s,Normal s) \\<in> G  \\<Longrightarrow>     \n    (\\<Gamma>, (While b c, Normal s1) #\n         (Seq c (While b c), Normal s1) # xsa)\n      \\<in> comm (G,( p \\<inter> (-b), a)) F\"\nproof -\nassume a00:\"(\\<Gamma>, (While b c, Normal s1) #\n         (Seq c (While b c), Normal s1) # xsa) \\<in>cptn\" and\n       a0:\"(\\<Gamma>, (c, Normal s1) # xs1) \\<in> cptn_mod\" and\n       a1:\" fst (last ((c, Normal s1) # xs1)) = LanguageCon.com.Skip\" and\n       a2:\"s1 \\<in> b\" and\n       a3:\"xsa = map (lift (While b c)) xs1 @\n            (While b c, snd (last ((c, Normal s1) # xs1))) # ys\" and\n       a4:\"(\\<Gamma>, (While b c, snd (last ((c, Normal s1) # xs1))) # ys)\n            \\<in> cptn_mod\" and\n       a5:\"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> c sat [p \\<inter> b, R, G, p,a]\" and       \n       a6:\"(\\<Gamma>, (While b c, Normal s1) #\n               (Seq c (While b c), Normal s1) # xsa)\n             \\<in> assum (p, R) F\" and\n       a7:\"(\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> c sat [p \\<inter> b, R, G, p,a] \\<Longrightarrow>    \n           (\\<Gamma>, (While b c, snd (last ((c, Normal s1) # xs1))) # ys)\n             \\<in> assum (p, R) F \\<Longrightarrow>\n           (\\<Gamma>, (While b c, snd (last ((c, Normal s1) # xs1))) # ys)\n             \\<in> comm (G,p \\<inter> (-b), a) F)\" and\n       a8:\"\\<forall>s. (Normal s, Normal s) \\<in> G\" \n  let ?l= \"(While b c, Normal s1) #\n           (Seq c (While b c), Normal s1) # xsa\"\n  let ?sub_l=\"((While b c, Normal s1) # \n                 (Seq c (While b c), Normal s1) # \n                 map (lift (While b c)) xs1)\"\n  {\n  assume final_not_fault:\"snd (last ?l) \\<notin> Fault ` F\"\n  have a0:\"(\\<Gamma>, (c, Normal s1) # xs1) \\<in> cptn\"\n    using cptn_if_cptn_mod using a0 by auto\n  have a4:\"(\\<Gamma>, (While b c, snd (last ((c, Normal s1) # xs1))) # ys) \\<in> cptn\" \n    using cptn_if_cptn_mod using a4 by auto\n  have seq_map:\"(Seq c (While b c), Normal s1) # map (lift (While b c)) xs1=\n           map (lift (While b c)) ((c,Normal s1)#xs1)\"\n  using a2 unfolding lift_def by fastforce\n  have step:\"\\<Gamma>\\<turnstile>\\<^sub>c(While b c,Normal s1) \\<rightarrow> (Seq c (While b c),Normal s1)\" using a2\n    WhileTruec by fastforce\n  have s1_normal:\"s1\\<in>p \\<and> s1 \\<in> b \" using a6 a2 unfolding assum_def by fastforce\n  have G_ref:\"(Normal s1, Normal s1)\\<in>G \" \n    using a8 by blast\n  have s1_collect_p: \"Normal s1\\<in> Normal ` (p \\<inter> b)\" using s1_normal by fastforce\n  have \"(\\<Gamma>, map (lift (While b c)) ((c,Normal s1)#xs1))\\<in>cptn\" \n    using a2 cptn_eq_cptn_mod lift_is_cptn a0 by fastforce\n  then have cptn_seq:\"(\\<Gamma>,(Seq c (While b c), Normal s1) # map (lift (While b c)) xs1) \\<in>cptn\" \n    using seq_map by auto\n  then have \"(\\<Gamma>, (While b c, Normal s1) # \n                 (Seq c (While b c), Normal s1) # \n                  map (lift (While b c)) xs1) \\<in> cptn\"\n    using step by (simp add: cptn.CptnComp) \n  also have \"(\\<Gamma>, (While b c, Normal s1) #\n                 (Seq c (While b c), Normal s1) #\n                  map (lift (While b c)) xs1)\n          \\<in> assum (p, R) F\"\n    using a6 a3 sub_assum by force \n  ultimately have assum_seq:\"(\\<Gamma>,(Seq c (While b c), Normal s1)  # \n                       map (lift (While b c)) xs1) \\<in> assum (p, R) F\"\n    using a6 tl_of_assum_in_assum1 s1_collect_p \n          tl_of_assum_in_assum   by fastforce\n  have cp_c:\"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> (cp \\<Gamma> c (Normal s1))\"\n    using a0 unfolding cp_def by fastforce\n  also have cp_seq:\"(\\<Gamma>, (Seq c (While b c), Normal s1) # map (lift (While b c)) xs1) \\<in> (cp \\<Gamma> (Seq c (While b c)) (Normal s1))\"\n    using cptn_seq unfolding cp_def by fastforce\n  ultimately have \"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> assum(p,R) F\"  \n    using assum_map assum_seq seq_map by fastforce  \n  then have \"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> assum((p \\<inter> b),R) F\"\n    unfolding assum_def using s1_collect_p by fastforce\n  then have c_comm:\"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> comm(G,(p,a)) F\"\n    using a5 cp_c unfolding com_validity_def by fastforce\n  then have \"(\\<Gamma>, (Seq c (While b c), Normal s1) # map (lift (While b c)) xs1) \\<in> comm(G,(p,a)) F\"\n    using cp_seq cp_c comm_map seq_map by fastforce\n  then have comm_while:\"(\\<Gamma>, (While b c, Normal s1) # \n                            (Seq c (While b c), Normal s1) # \n                            map (lift (While b c)) xs1) \\<in> comm(G,(p,a)) F\"\n    using G_ref ctran_in_comm by fastforce\n  have final_last_c:\"final (last ((c,Normal s1)#xs1))\"\n    using a1 a3 unfolding final_def by fastforce\n  have last_while1:\"snd (last (map (lift (While b c)) ((c,Normal s1)#xs1))) = snd (last ((c, Normal s1) # xs1))\"\n    unfolding lift_def by (simp add: case_prod_beta' last_map)\n  have last_while2:\"(last (map (lift (While b c)) ((c,Normal s1)#xs1))) =\n           last ((While b c, Normal s1) # (Seq c (While b c), Normal s1) # map (lift (While b c)) xs1)\"\n    using seq_map by fastforce\n  have not_fault_final_last_c:\n    \"snd (last ( (c,Normal s1)#xs1)) \\<notin> Fault ` F\"\n  proof -    \n    have \"(length ?sub_l) - 1 < length ?l\" \n      using a3 by fastforce\n    then have \"snd (?l!((length ?sub_l) - 1))\\<notin> Fault ` F\"\n      using final_not_fault a3 a00 last_not_F[of \\<Gamma> ?l F]  by fast\n    thus ?thesis using last_while2 last_while1 seq_map\n      by (metis (no_types) Cons_lift_append  a3 diff_Suc_1 last_length length_Cons lessI nth_Cons_Suc nth_append)\n  qed\n  then have last_c_normal:\"snd (last ( (c,Normal s1)#xs1)) \\<in> Normal ` (p)\"\n    using c_comm a1 unfolding comm_def final_def by fastforce    \n  then obtain sl where sl:\"snd (last ( (c,Normal s1)#xs1)) = Normal sl\" by fastforce\n  have while_comm:\"(\\<Gamma>, (While b c, snd (last ((c, Normal s1) # xs1))) # ys) \\<in> comm(G,(p\\<inter>(-b),a)) F\"\n  proof -\n    have assum_while: \"(\\<Gamma>, (While b c, snd (last ((c, Normal s1) # xs1))) # ys)\n             \\<in> assum (p, R) F\"\n      using last_c_normal a3 a6 sub_assum_r[of \\<Gamma> ?sub_l \"(While b c, snd (last ((c, Normal s1) # xs1)))\"  ys p R F p] \n      by fastforce\n    thus ?thesis using a5 a7 by fastforce\n  qed      \n  have \"sl\\<in>p\" using last_c_normal sl by fastforce\n  then have G1_ref:\"(Normal sl, Normal sl)\\<in>G\" using a8 by auto\n  also have \"snd (last ?sub_l) = Normal sl\"\n    using last_while1 last_while2 sl by fastforce\n  ultimately have ?thesis \n    using  a00 a3 sl while_comm comm_union[OF comm_while]  \n    by fastforce    \n  } note p1 =this\n  {\n    assume final_not_fault:\"\\<not> (snd (last ?l) \\<notin> Fault ` F)\"\n    then have ?thesis unfolding comm_def by fastforce\n  } thus ?thesis using p1 by fastforce\nqed\n\nlemma while3:\n   \"(\\<Gamma>, (c, Normal s1) # xs1) \\<in> cptn_mod \\<Longrightarrow>    \n    fst (last ((c, Normal s1) # xs1)) = Throw \\<Longrightarrow>\n    s1 \\<in> b \\<Longrightarrow>\n    snd (last ((c, Normal s1) # xs1)) = Normal sl \\<Longrightarrow>\n    (\\<Gamma>, (Throw, Normal sl) # ys) \\<in> cptn_mod   \\<Longrightarrow>\n    \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> c sat [p \\<inter> b,R, G, p,a] \\<Longrightarrow>    \n    (\\<Gamma>, (While b c, Normal s1) #\n         (Seq c (While b c), Normal s1) #  \n         (map (lift (While b c)) xs1 @\n           (Throw, Normal sl) # ys))\n       \\<in> assum (p, R) F \\<Longrightarrow>    \n    (\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]) \\<Longrightarrow>      \n     Sta p R \\<Longrightarrow>\n     Sta a R \\<Longrightarrow> \\<forall>s. (Normal s, Normal s) \\<in> G \\<Longrightarrow> \n    (\\<Gamma>, (While b c, Normal s1) #\n         (Seq c (While b c), Normal s1) #          \n         ((map (lift (While b c)) xs1 @\n           (Throw, Normal sl) # ys))) \\<in> comm (G, p\\<inter> (-b), a) F\n\"\nproof -\nassume a0:\"(\\<Gamma>, (c, Normal s1) # xs1) \\<in> cptn_mod\" and\n       a1:\"fst (last ((c, Normal s1) # xs1)) = Throw\" and\n       a2:\"s1 \\<in> b\" and\n       a3:\"snd (last ((c, Normal s1) # xs1)) = Normal sl\" and\n       a4:\"(\\<Gamma>, (Throw, Normal sl) # ys) \\<in> cptn_mod\" and\n       a5:\"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> c sat [p \\<inter> b, R, G, p,a]\" and\n       a6:\"(\\<Gamma>, (While b c, Normal s1) #\n           (Seq c (While b c), Normal s1) #  \n           (map (lift (While b c)) xs1 @\n             (Throw, Normal sl) # ys))\n           \\<in> assum (p, R) F\" and      \n       a7: \"Sta p R\" and\n       a8: \"Sta a R\" and\n       a9: \"(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a])\" and\n       a10:\"\\<forall>s. (Normal s,Normal s) \\<in> G\" \n  have a0:\"(\\<Gamma>, (c, Normal s1) # xs1) \\<in> cptn\"\n    using cptn_if_cptn_mod using a0 by auto\n  have a4:\"(\\<Gamma>, (Throw, Normal sl) # ys) \\<in> cptn\" \n    using cptn_if_cptn_mod using a4 by auto\n  have seq_map:\"(Seq c (While b c), Normal s1) # map (lift (While b c)) xs1=\n           map (lift (While b c)) ((c,Normal s1)#xs1)\"\n  using a2 unfolding lift_def by fastforce\n  have step:\"\\<Gamma>\\<turnstile>\\<^sub>c(While b c,Normal s1) \\<rightarrow> (Seq c (While b c),Normal s1)\" using a2\n    WhileTruec by fastforce\n  have s1_normal:\"s1\\<in>p \\<and> s1 \\<in> b \" using a6 a2 unfolding assum_def by fastforce\n  then have G_ref:\"(Normal s1, Normal s1)\\<in>G\" using a10 by auto\n  have s1_collect_p: \"Normal s1\\<in> Normal ` (p \\<inter> b)\" using s1_normal by fastforce\n  have \"(\\<Gamma>, map (lift (While b c)) ((c,Normal s1)#xs1))\\<in>cptn\" \n    using a2 cptn_eq_cptn_mod lift_is_cptn a0 by fastforce\n  then have cptn_seq:\"(\\<Gamma>,(Seq c (While b c), Normal s1) # map (lift (While b c)) xs1) \\<in>cptn\" \n    using seq_map by auto\n  then have cptn:\"(\\<Gamma>, (While b c, Normal s1) # \n                 (Seq c (While b c), Normal s1) # \n                  map (lift (While b c)) xs1) \\<in> cptn\"\n    using step by (simp add: cptn.CptnComp) \n  also have \"(\\<Gamma>, (LanguageCon.com.While b c, Normal s1) #\n         (LanguageCon.com.Seq c (LanguageCon.com.While b c), Normal s1) #\n         map (lift (LanguageCon.com.While b c)) xs1)\n          \\<in> assum (p, R) F\"\n    using a6 sub_assum by force \n  ultimately have assum_seq:\"(\\<Gamma>,(Seq c (While b c), Normal s1)  # \n                       map (lift (While b c)) xs1) \\<in> assum (p, R) F\"\n    using a6 tl_of_assum_in_assum1 s1_collect_p \n          tl_of_assum_in_assum  by fastforce\n  have cp_c:\"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> (cp \\<Gamma> c (Normal s1))\"\n    using a0 unfolding cp_def by fastforce\n  also have cp_seq:\"(\\<Gamma>, (Seq c (While b c), Normal s1) # map (lift (While b c)) xs1) \\<in> (cp \\<Gamma> (Seq c (While b c)) (Normal s1))\"\n    using cptn_seq unfolding cp_def by fastforce\n  ultimately have \"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> assum(p,R) F\"  \n    using assum_map assum_seq seq_map by fastforce  \n  then have \"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> assum((p \\<inter> b),R) F\"\n    unfolding assum_def using s1_collect_p by fastforce\n  then have c_comm:\"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> comm(G,(p,a)) F\"\n    using a5 cp_c unfolding com_validity_def by fastforce\n  then have \"(\\<Gamma>, (Seq c (While b c), Normal s1) # map (lift (While b c)) xs1) \\<in> comm(G,(p,a)) F\"\n    using cp_seq cp_c comm_map seq_map by fastforce\n  then have comm_while:\"(\\<Gamma>, (While b c, Normal s1) # (Seq c (While b c), Normal s1) # map (lift (While b c)) xs1) \\<in> comm(G,(p,a)) F\"\n    using G_ref ctran_in_comm by fastforce\n  have final_last_c:\"final (last ((c,Normal s1)#xs1))\"\n    using a1 a3 unfolding final_def by fastforce\n  have not_fault_final_last_c:\n    \"snd (last ( (c,Normal s1)#xs1)) \\<notin> Fault ` F\"\n    using a3 by fastforce\n  then have sl_a:\"Normal sl \\<in> Normal ` (a)\"  \n    using final_last_c a1 c_comm unfolding comm_def\n    using  a3 comm_dest2   \n    by auto\n  have last_while1:\"snd (last (map (lift (While b c)) ((c,Normal s1)#xs1))) = snd (last ((c, Normal s1) # xs1))\"\n    unfolding lift_def by (simp add: case_prod_beta' last_map)\n  have last_while2:\"(last (map (lift (While b c)) ((c,Normal s1)#xs1))) =\n           last ((While b c, Normal s1) # (Seq c (While b c), Normal s1) # map (lift (While b c)) xs1)\"\n    using seq_map by fastforce\n  have throw_comm:\"(\\<Gamma>, (Throw, Normal sl) # ys) \\<in> comm(G,(p\\<inter>(-b),a)) F\"\n  proof -\n    have assum_throw: \"(\\<Gamma>, (Throw, Normal sl) # ys) \\<in> assum (a,R) F\"\n      using sl_a a6 sub_assum_r[of _ \"(LanguageCon.com.While b c, Normal s1) #\n         (LanguageCon.com.Seq c (LanguageCon.com.While b c), Normal s1) #\n         map (lift (LanguageCon.com.While b c)) xs1\" \"(Throw, Normal sl)\" ] \n      by fastforce\n    also have \"(\\<Gamma>,(Throw, Normal sl) # ys) \\<in> cp \\<Gamma> Throw (Normal sl)\" \n      unfolding cp_def using a4 by fastforce\n    ultimately show ?thesis using Throw_sound[of a R G \\<Gamma>] a10 a8 a9  \n      unfolding com_cvalidity_def com_validity_def by fast\n  qed  \n  have p1:\"(LanguageCon.com.While b c, Normal s1) #\n    (LanguageCon.com.Seq c (LanguageCon.com.While b c), Normal s1) #\n    map (lift (LanguageCon.com.While b c)) xs1 \\<noteq>\n    [] \\<and>\n    (LanguageCon.com.Throw, Normal sl) # ys \\<noteq> []\" by auto  \n  have \"sl \\<in> a\" using sl_a by fastforce\n  then have G1_ref:\"(Normal sl, Normal sl) \\<in> G\" using a10 by auto\n  moreover have \"snd (last ((While b c, Normal s1) # \n                  (Seq c (While b c), Normal s1) # \n                  map (lift (While b c)) xs1)) = Normal sl\"\n    using last_while1 last_while2 a3 by fastforce\n  moreover have \"snd (((LanguageCon.com.Throw, Normal sl) # ys) ! 0) = Normal sl\"\n    by (metis nth_Cons_0 snd_conv)\n  ultimately have G:\"(snd (last ((While b c, Normal s1) # \n                  (Seq c (While b c), Normal s1) # \n                  map (lift (While b c)) xs1)),\n                  snd (((LanguageCon.com.Throw, Normal sl) # ys) ! 0)) \\<in> G\" by auto\n  have cptn:\"(\\<Gamma>, ((LanguageCon.com.While b c, Normal s1) #\n          (LanguageCon.com.Seq c (LanguageCon.com.While b c), Normal s1) #\n          map (lift (LanguageCon.com.While b c)) xs1) @\n         (LanguageCon.com.Throw, Normal sl) # ys)\n    \\<in> cptn\" using cptn a4  a0 a1 a3 a4 cptn_eq_cptn_mod_set cptn_mod.CptnModWhile3 s1_normal by fastforce\n  show ?thesis using a0  comm_union[OF comm_while throw_comm p1 G cptn] by auto       \nqed\n\n\ninductive_cases stepc_elim_cases_while_throw [cases set]:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(While b c, s) \\<rightarrow> (Throw, t)\"\n\nlemma WhileSound_aux:\n \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b, R, G, p,a] \\<Longrightarrow>\n  Sta p R \\<Longrightarrow>\n  Sta  (p \\<inter> (-b)) R \\<Longrightarrow> \n  Sta a R \\<Longrightarrow>    \n  (\\<Gamma>,x)\\<in> cptn_mod \\<Longrightarrow> \n  \\<forall>s. (Normal s, Normal s) \\<in> G \\<Longrightarrow>\n  \\<forall>s xs. x = ((While b c1),s)#xs \\<longrightarrow> \n     (\\<Gamma>,x)\\<in>assum(p,R) F \\<longrightarrow> \n     (\\<Gamma>,x) \\<in> comm (G,(( p \\<inter> (-b)),a)) F\"\nproof -\n  assume a0: \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b, R, G, p,a] \" and\n         a1: \"Sta p R\" and\n         a2: \"Sta  (p \\<inter> (-b)) R\" and\n         a3: \"Sta a R\" and\n         a4: \"(\\<Gamma>,x)\\<in> cptn_mod\" and\n         a5: \"\\<forall>s. (Normal s, Normal s) \\<in> G\" \n   {fix xs s \n   assume while_xs:\"x=((While b c1),s)#xs\" and\n          x_assum:\"(\\<Gamma>,x)\\<in>assum(p,R) F\"\n   have \"(\\<Gamma>,x) \\<in> comm (G,(( p \\<inter> (-b)),a)) F\"\n   using a4 a0  while_xs x_assum\n   proof (induct arbitrary: xs s c1 rule:cptn_mod.induct)\n     case (CptnModOne  \\<Gamma> C s1) thus ?case \n       using CptnModOne unfolding comm_def final_def\n       by auto\n   next\n     case (CptnModEnv  \\<Gamma> C s1 t1 xsa) \n     then have c_while:\"C = While b c1\" by fastforce\n     have \"(\\<Gamma>, (C, t1) # xsa) \\<in> assum (p, R) F \\<longrightarrow>\n                (\\<Gamma>, (C, t1) # xsa) \\<in> comm (G, p \\<inter> (-b), a) F\"  \n     using CptnModEnv by fastforce  \n     moreover have\"(\\<Gamma>,(C, s1)#(C, t1) # xsa) \\<in> cptn_mod\"\n       using CptnModEnv(1,2)\n       by (simp add: CptnModEnv.hyps(1) CptnModEnv.hyps(2) cptn_mod.CptnModEnv)\n     then have  cptn_mod:\"(\\<Gamma>,(C, s1)#(C, t1) # xsa) \\<in> cptn\"\n       using cptn_eq_cptn_mod_set by blast      \n     then have \"(\\<Gamma>, (C, t1) # xsa) \\<in> assum (p, R) F\"   \n       using tl_of_assum_in_assum CptnModEnv(6) a1 a2 a3 a4 a5\n       by blast\n     ultimately have \"(\\<Gamma>, (C, t1) # xsa) \\<in> comm (G, p \\<inter> (-b), a) F\"\n       by auto\n     also have \" \\<not> (\\<Gamma>\\<turnstile>\\<^sub>c((C,s1))  \\<rightarrow> ((C,t1)))\" \n     proof \n       assume step:\"\\<Gamma>\\<turnstile>\\<^sub>c (C, s1) \\<rightarrow> (C, t1)\"\n       show False \n       proof (cases s1)\n         case (Normal s1') thus ?thesis \n           using step step_change_p_or_eq_Ns redex.simps(6) LanguageCon.com.distinct(91) c_while\n           by fastforce\n       next\n         case Abrupt thus ?thesis \n           using step c_while  prod.inject stepc_elim_cases(7) xstate.distinct(1) \n           by fastforce\n       next\n         case Fault thus ?thesis\n           using step c_while  prod.inject stepc_elim_cases(7) xstate.distinct(1) \n           by fastforce\n       next\n         case Stuck thus ?thesis\n           using step c_while  prod.inject stepc_elim_cases(7) xstate.distinct(1) \n           by fastforce\n       qed\n     qed\n     ultimately show ?case \n       using cptn_mod etran_in_comm by blast\n   next \n     case (CptnModSkip \\<Gamma> C s1 t1 xsa) \n     then have \"C=While b c1\" by auto\n     also have \"(\\<Gamma>, (LanguageCon.com.Skip, t1) # xsa) \\<in> cptn\"\n       using cptn_eq_cptn_mod_set CptnModSkip(3) by fastforce\n     thus ?case using WhileNone CptnModSkip a1 a2 a3 a4 a5  by blast\n   next\n     case (CptnModThrow  \\<Gamma> C s1 t1 xsa) \n     then have \"C = While b c1\" by auto \n       thus ?case using stepc_elim_cases_while_throw CptnModThrow(1) \n       by blast\n   next \n     case (CptnModWhile1  \\<Gamma> c s1 xs1 b1 xsa zs) \n     then have \"b=b1 \\<and> c=c1 \\<and> s=Normal s1\" by auto      \n     thus ?case\n     using a4 a5 CptnModWhile1 while1[of \\<Gamma>] by blast\n   next \n     case (CptnModWhile2 \\<Gamma> c s1 xs1 b1 xsa ys zs)\n     then have a00: \"(\\<Gamma>, (While b c, Normal s1) #\n         (Seq c (While b c), Normal s1) # xsa)\\<in>cptn_mod\" \n       using cptn_mod.CptnModWhile2 by fast note pp1 = this[THEN cptn_if_cptn_mod]  \n     then have eqs:\"b=b1 \\<and> c=c1 \\<and> s=Normal s1\"using CptnModWhile2 by auto\n     thus ?case using pp1 a4 a5 CptnModWhile2 while2[of \\<Gamma> b c s1 xsa xs1 ys F p R G a] \n         by fastforce\n   next\n     case (CptnModWhile3 \\<Gamma> c s1 xs1 b1 sl ys zs)  \n     then have eqs:\"b=b1 \\<and> c=c1 \\<and> s=Normal s1\" by auto \n     then have \"(\\<Gamma>, (While b c, Normal s1) #\n         (Seq c (While b c), Normal s1) #          \n         ((map (lift (While b c)) xs1 @\n           (Throw, Normal sl) # ys))) \\<in> comm (G, p\\<inter>(-b), a) F\"        \n       using a1 a3 a4 a5 CptnModWhile3 while3[of \\<Gamma> c s1 xs1 b sl ys F p R G a] \n       by fastforce   \n     thus ?case using eqs CptnModWhile3 by auto\n   qed (auto)\n  }\n  then show ?thesis by auto    \nqed\n\n\n\nlemma While_sound: \n      \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b, R, G, p,a] \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b, R, G, p,a] \\<Longrightarrow>       \n       Sta p R \\<Longrightarrow>     \n       Sta (p \\<inter> (-b)) R \\<Longrightarrow> Sta a R \\<Longrightarrow> \\<forall>s. (Normal s, Normal s) \\<in> G  \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> (While b c1) sat [p, R, G, p \\<inter> (-b),a]\"\nproof -  \n  assume\n    a0:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b, R, G, p,a]\" and\n    a1:\"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b, R, G, p,a]\" and    \n    a2: \"Sta p R\" and\n    a3: \"Sta (p \\<inter> (-b)) R\" and\n    a4: \"Sta a R\" and\n    a5: \"\\<forall>s. (Normal s, Normal s) \\<in> G\" \n  { \n    fix s\n    assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"  \n    then have a1:\"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b, R, G, p,a]\" \n      using a1 com_cvalidity_def by fastforce\n    have \"cp \\<Gamma> (While b c1)  s \\<inter> assum(p, R) F \\<subseteq> comm(G, (p \\<inter> (-b),a)) F\"\n    proof-\n      {fix c     \n      assume a10:\"c \\<in> cp \\<Gamma> (While b c1) s\" and a11:\"c \\<in> assum(p, R) F\"\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have cp:\"l!0=((While b c1),s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\" using a10 cp_def c_prod by fastforce      \n      have \\<Gamma>1:\"(\\<Gamma>, l) = c\" using c_prod cp by blast\n      obtain xs where \"l=((While b c1),s)#xs\" using cp\n      proof -\n        assume a1: \"\\<And>xs. l = (LanguageCon.com.While b c1, s) # xs \\<Longrightarrow> thesis\"\n        have \"[] \\<noteq> l\"\n          using cp cptn.simps by auto\n        then show ?thesis\n          using a1 by (metis (full_types) SmallStepCon.nth_tl cp)\n      qed \n      moreover have \"(\\<Gamma>,l)\\<in>cptn_mod\" using cp cptn_eq_cptn_mod_set by fastforce\n      ultimately have \"c \\<in> comm(G, (p \\<inter> (-b),a)) F\"\n      using a1 a2 a3 a4   WhileSound_aux a11 \\<Gamma>1 a5 \n        by blast\n      } thus ?thesis by auto qed\n  }\n  thus ?thesis by (simp add: com_validity_def[of \\<Gamma>] com_cvalidity_def)  \nqed\n\n\nlemma Conseq_sound:\n  \"(\\<forall>s\\<in> p.\n       \\<exists>p' R' G' q' a' I'.\n          s \\<in> p' \\<and>\n          R \\<subseteq> R' \\<and>            \n          G' \\<subseteq> G \\<and>             \n          q' \\<subseteq> q \\<and>\n          a' \\<subseteq> a \\<and>\n          \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> P sat [p',R', G', q',a'] \\<and> \n          \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> P sat [p', R', G', q',a']) \\<Longrightarrow>\n  \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> P sat [p,R, G, q,a]\" \nproof -\n  assume \n  a0: \"(\\<forall>s\\<in> p.\n       \\<exists>p' R' G' q' a' I'.\n          s \\<in> p' \\<and>\n          R \\<subseteq> R' \\<and>            \n          G' \\<subseteq> G \\<and>             \n          q' \\<subseteq> q \\<and>\n          a' \\<subseteq> a \\<and>\n          \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> P sat [p',R', G', q',a'] \\<and> \n          \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> P sat [p', R', G', q',a'])\"\n  {\n    fix s\n    assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"\n    have \"cp \\<Gamma> P  s \\<inter> assum(p, R) F \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {\n      fix c\n      assume a10:\"c \\<in> cp \\<Gamma> P s\" and a11:\"c \\<in> assum(p, R) F\"\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have cp:\"l!0=(P,s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\" using a10 cp_def c_prod by fastforce\n      have \\<Gamma>1:\"(\\<Gamma>, l) = c\" using c_prod cp by blast \n      obtain xs where \"l=(P,s)#xs\" using cp\n      proof -\n        assume a1: \"\\<And>xs. l = (P, s) # xs \\<Longrightarrow> thesis\"\n        have \"[] \\<noteq> l\"\n          using cp cptn.simps by auto\n        then show ?thesis\n          using a1 by (metis (full_types) SmallStepCon.nth_tl cp)\n      qed\n      obtain ns where s:\"(s = Normal ns)\" using a10 a11 unfolding assum_def cp_def by fastforce\n      then have \"ns \\<in> p\" using a10 a11 unfolding assum_def cp_def by fastforce\n      then have ns:\"ns\\<in>p\" by auto\n      then have\n      \"\\<forall>s. s \\<in> p \\<longrightarrow> (\\<exists>p' R' G' q' a' . (s\\<in>p') \\<and>\n        R \\<subseteq> R' \\<and>            \n        G' \\<subseteq> G \\<and>             \n        q' \\<subseteq> q \\<and>\n        a' \\<subseteq> a \\<and>\n        (\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> P sat [p',R', G', q',a']) \\<and> \n        \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> P sat [p', R', G', q',a'])\" using a0 by auto\n      then have \n       \"ns \\<in> p \\<longrightarrow> (\\<exists>p' R' G' q' a'. (ns \\<in> p' ) \\<and>\n        R \\<subseteq> R' \\<and>            \n        G' \\<subseteq> G \\<and>             \n        q' \\<subseteq> q \\<and>\n        a' \\<subseteq> a \\<and>\n        (\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> P sat [p',R', G', q',a']) \\<and> \n        \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> P sat [p', R', G', q',a'])\" apply (rule allE) by auto     \n     then obtain p' R' G' q' a' where\n     rels:\n       \"ns \\<in> p' \\<and>\n        R \\<subseteq> R' \\<and>            \n        G' \\<subseteq> G \\<and>             \n        q' \\<subseteq> q \\<and>\n        a' \\<subseteq> a \\<and>        \n        \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> P sat [p', R', G', q',a']\" using ns by auto\n      then have \"s \\<in>  Normal ` p'\" using s by fastforce\n      then have \"(\\<Gamma>,l) \\<in> assum(p', R') F\"\n        using a11 rels cp a11 c_prod assum_R_R'[of \\<Gamma> l p R F p' R'] \n        by fastforce\n      then have \"(\\<Gamma>,l) \\<in> comm(G',(q',a')) F\" \n        using rels all_call a10 c_prod cp unfolding com_cvalidity_def com_validity_def \n        by blast\n      then have \"(\\<Gamma>,l) \\<in> comm(G, (q,a)) F\" \n        using c_prod cp comm_conseq[of \\<Gamma> l G' q' a' F G q a] rels by fastforce\n      then have \"c \\<in> comm(G, (q,a)) F\" using c_prod cp by fastforce\n    }                 \n    thus ?thesis unfolding comm_def by force qed      \n  } thus ?thesis by (simp add: com_validity_def[of \\<Gamma>] com_cvalidity_def)  \nqed   \n\nlemma Conj_post_sound:\n  \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> P sat [p,R, G, q,a] \\<and> \n   \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q,a] \\<Longrightarrow> \n   \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> P sat [p,R, G, q',a'] \\<and> \n   \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q',a'] \\<Longrightarrow>\n  \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> P sat [p,R, G, q \\<inter> q' ,a \\<inter> a']\" \nproof -\nassume a0: \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> P sat [p,R, G, q,a] \\<and> \n            \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q,a]\" and\n       a1: \" \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> P sat [p,R, G, q',a'] \\<and> \n             \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q',a']\"\n{\n    fix s\n    assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"\n    with a0 have a0:\"cp \\<Gamma> P  s \\<inter> assum(p, R) F \\<subseteq> comm(G, (q,a)) F\"\n      unfolding com_cvalidity_def com_validity_def by auto\n    with a1 all_call have a1:\"cp \\<Gamma> P  s \\<inter> assum(p, R) F \\<subseteq> comm(G, (q',a')) F\"\n      unfolding com_cvalidity_def com_validity_def by auto\n    have \"cp \\<Gamma> P  s \\<inter> assum(p, R) F \\<subseteq> comm(G, (q\\<inter>q',a\\<inter>a')) F\"\n    proof -\n    {\n      fix c\n      assume a10:\"c \\<in> cp \\<Gamma> P s\" and a11:\"c \\<in> assum(p, R) F\"\n      then have \"c \\<in> comm(G,(q,a)) F \\<and> c \\<in> comm(G,(q',a')) F\"\n        using a0 a1 by auto\n      then have  \"c\\<in>comm(G, (q\\<inter>q',a\\<inter>a')) F\"\n        unfolding comm_def by fastforce\n    }               \n    thus ?thesis unfolding comm_def by force qed      \n  } thus ?thesis by (simp add: com_validity_def[of \\<Gamma>] com_cvalidity_def)  \nqed   \n\nlemma localRG_sound: \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c sat [p, R, G, q,a] \\<Longrightarrow> \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> c sat [p, R, G, q,a]\"\nproof (induct rule:lrghoare.induct)\n  case Skip \n    thus ?case  by (simp add: Skip_sound)\nnext\n  case Spec\n    thus ?case  by (simp add: Spec_sound)\nnext\n  case Basic\n    thus ?case by (simp add: Basic_sound)\nnext\n  case Await\n    thus ?case by (simp add: Await_sound)\nnext\n  case Throw thus ?case by (simp add: Throw_sound)\nnext \n  case If thus ?case by (simp add: If_sound)\nnext \n  case Call thus ?case by (simp add: Call_sound)\nnext\n  case Asm thus ?case by (simp add: Asm_sound)\nnext\n  case CallRec thus ?case using CallRec_sound by (simp add: CallRec_sound)\nnext\n  case Seq thus ?case by (simp add: Seq_sound)\nnext\n  case Catch thus ?case by (simp add: Catch_sound)\nnext\n  case DynCom thus ?case by (simp add: DynCom_sound)\nnext\n  case Guard thus ?case by (simp add: Guard_sound)\nnext\n  case Guarantee thus ?case by (simp add: Guarantee_sound)\nnext\n  case While thus ?case by (simp add: While_sound)\nnext\n  case (Conseq p R G q a \\<Gamma> \\<Theta> F P) thus ?case \n    using Conseq_sound by simp\nnext \n  case (Conj_post \\<Gamma> \\<Theta> F P p' R' G' q a q' a') thus ?case\n     using Conj_post_sound[of \\<Gamma> \\<Theta>] by simp\nqed   \n\n\ndefinition ParallelCom :: \"('s,'p,'f) rgformula list \\<Rightarrow> ('s,'p,'f) par_com\"\nwhere\n\"ParallelCom Ps \\<equiv> map fst Ps\"\n\nlemma ParallelCom_Com:\"i<length xs \\<Longrightarrow> (ParallelCom xs)!i = Com (xs!i)\"\nunfolding ParallelCom_def Com_def by fastforce\n\n\nlemma etran_ctran_eq_p_normal_s: \"\\<Gamma>\\<turnstile>\\<^sub>c s1  \\<rightarrow> s1' \\<Longrightarrow>\n             \\<Gamma>\\<turnstile>\\<^sub>c s1  \\<rightarrow>\\<^sub>e s1' \\<Longrightarrow>\n            fst s1 = fst s1' \\<and> snd s1 = snd s1' \\<and> (\\<exists>ns1. snd s1 = Normal ns1)\"\nproof -\n   assume a0: \"\\<Gamma>\\<turnstile>\\<^sub>c s1  \\<rightarrow> s1'\" and\n          a1: \"\\<Gamma>\\<turnstile>\\<^sub>c s1  \\<rightarrow>\\<^sub>e s1'\"\n   then obtain ps1 ss1 ps1' ss1' where prod:\"s1 = (ps1,ss1) \\<and> s1' = (ps1', ss1')\"\n     by fastforce\n   then have \"ps1=ps1'\" using a1 etranE by fastforce\n   thus ?thesis using prod step_change_p_or_eq_s_normal a0 by fastforce\nqed\n\nlemma step_e_step_c_eq:\"\\<lbrakk> \n  (\\<Gamma>,l) \\<propto> clist;\n  Suc m < length l;\n  i < length clist; \n  (fst (clist!i))\\<turnstile>\\<^sub>c((snd (clist!i))!m) \\<rightarrow>\\<^sub>e  ((snd (clist!i))!Suc m);          \n  (fst (clist!i))\\<turnstile>\\<^sub>c((snd (clist!i))!m) \\<rightarrow>  ((snd (clist!i))!Suc m);\n  (\\<forall>l<length clist. \n     l\\<noteq>i \\<longrightarrow>  (fst (clist!l))\\<turnstile>\\<^sub>c (snd (clist!l))!m  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc m)))\n  \\<rbrakk> \\<Longrightarrow> \n  l!m = l!(Suc m) \\<and> (\\<exists>ns. snd (l!m) = Normal ns )\"\nproof -\n  assume a0:\"(\\<Gamma>,l) \\<propto> clist\" and\n         a1:\"Suc m < length l\" and\n         a2:\"i < length clist\" and\n         a3:\"(fst (clist!i))\\<turnstile>\\<^sub>c((snd (clist!i))!m) \\<rightarrow>\\<^sub>e  ((snd (clist!i))!Suc m)\" and\n         a4:\"(fst (clist!i))\\<turnstile>\\<^sub>c((snd (clist!i))!m) \\<rightarrow>  ((snd (clist!i))!Suc m)\" and\n         a5:\"(\\<forall>l<length clist. \n                 l\\<noteq>i \\<longrightarrow> (fst (clist!l))\\<turnstile>\\<^sub>c (snd (clist!l))!m  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc m)))\"\n  obtain fp fs sp ss \n    where prod_step: \" \n               \\<Gamma>\\<turnstile>\\<^sub>c (fp, fs) \\<rightarrow> (sp,ss) \\<and> \n              fp = fst (((snd (clist!i))!m)) \\<and> fs = snd (((snd (clist!i))!m)) \\<and> \n              sp = fst ((snd (clist!i))!(Suc m)) \\<and> ss = snd((snd (clist!i))!(Suc m)) \\<and>\n              \\<Gamma> = fst (clist!i)\"\n    using a0 a2 a1 a4 unfolding conjoin_def same_functions_def by fastforce \n  have snd_lj:\"(snd (l!m)) = snd ((snd (clist!i))!m)\"\n            using a0 a1 a2  unfolding conjoin_def same_state_def\n            by fastforce \n  have fst_clist_\\<Gamma>:\"\\<forall>i<length clist. fst(clist!i) = \\<Gamma>\" \n    using a0 unfolding conjoin_def same_functions_def by fastforce\n  have all_env: \"\\<forall>l<length clist. \n                    (fst (clist!l))\\<turnstile>\\<^sub>c (snd (clist!l))!m  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc m))\"\n    using a3 a5 a2 fst_clist_\\<Gamma> by fastforce\n  then have allP:\"\\<forall>l< length clist. fst ((snd (clist!l))!m) = fst ((snd (clist!l))!(Suc m))\"\n    by (fastforce elim:etranE)         \n  then have \"fst (l!m) = (fst (l!(Suc m)))\"\n    using a0 conjoin_same_program_i_j [of \"(\\<Gamma>,l)\"] a1 by fastforce\n  also have snd_l_normal:\"snd (l!m) = snd (l!(Suc m)) \\<and> (\\<exists>ns. snd (l!m) = Normal ns )\"\n  proof -                        \n    have \"(snd (l!Suc m)) = snd ((snd (clist!i))!(Suc m))\"\n      using a0 a1 a2 unfolding conjoin_def same_state_def\n      by fastforce\n    also have \"fs = ss \\<and> \n               (\\<exists>ns.  (snd ((snd (clist!i))!m) = Normal ns ))\"\n      using a1 a2 step_change_p_or_eq_s_normal[of \\<Gamma> fp fs sp ss] all_env prod_step allP \n      by metis \n    ultimately show ?thesis using snd_lj prod_step a1  by fastforce\n  qed \n  ultimately show ?thesis using prod_eq_iff by blast      \nqed\n\nlemma two': \n  \"\\<lbrakk> \\<forall>i<length xs. R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n       \\<subseteq> (Rely (xs ! i));\n   p \\<subseteq> (\\<Inter>i<length xs. (Pre (xs ! i)));\n   \\<forall>i<length xs.\n    \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)];\n   length xs=length clist; (\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s; (\\<Gamma>,l)\\<in>par_assum (p, R) F;\n  \\<forall>i<length clist. clist!i\\<in>cp \\<Gamma> (Com(xs!i)) s; (\\<Gamma>,l) \\<propto> clist;(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]);\n  snd (last l) \\<notin> Fault ` F\\<rbrakk>\n  \\<Longrightarrow> \\<forall>j i ns ns'. i<length clist \\<and> Suc j<length l \\<longrightarrow> \n      \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>\\<^sub>e  ((snd (clist!i))!Suc j) \\<longrightarrow> \n      (snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in> Rely(xs!i)\"\nproof -\n  assume a0:\"\\<forall>i<length xs. R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n       \\<subseteq> (Rely (xs ! i))\" and\n         a1:\"p \\<subseteq> (\\<Inter>i<length xs. (Pre (xs ! i)))\" and\n         a2:\"\\<forall>i<length xs.\n    \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)]\" and\n         a3: \"length xs=length clist\" and\n         a4: \"(\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s\" and\n         a5: \"(\\<Gamma>,l)\\<in>par_assum (p, R) F\" and\n         a6: \"\\<forall>i<length clist. clist!i\\<in>cp \\<Gamma> (Com(xs!i)) s\" and\n         a7: \"(\\<Gamma>,l) \\<propto> clist\" and\n         a8: \"(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a])\" and \n         a9: \"snd (last l) \\<notin> Fault ` F\"\n{\n  assume a10:\"\\<exists>i j ns ns'. \n              i<length clist \\<and> Suc j<length l \\<and> \n              \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>\\<^sub>e  ((snd (clist!i))!Suc j) \\<and> \n              \\<not>(snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in> Rely(xs!i)\"\n  then obtain j where \n    a10:\"\\<exists>i ns ns'. \n       i<length clist \\<and> Suc j<length l \\<and> \n       \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>\\<^sub>e  ((snd (clist!i))!Suc j) \\<and>\n       \\<not>(snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in> Rely(xs!i)\" by fastforce\n   let ?P = \"\\<lambda>j. \\<exists>i. i<length clist \\<and> Suc j<length l \\<and>\n      \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>\\<^sub>e  ((snd (clist!i))!Suc j) \\<and>       \n      (\\<not> (snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in> Rely(xs!i))\"        \n   obtain m where fist_occ:\"(?P m) \\<and> (\\<forall>i<m. \\<not> ?P i)\" using exists_first_occ[of ?P j] a10 by blast\n     then have \"?P m\" by fastforce\n     then obtain i where\n      fst_occ:\"i<length clist \\<and> Suc m<length l \\<and>\n      \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!m) \\<rightarrow>\\<^sub>e  ((snd (clist!i))!Suc m) \\<and>       \n      (\\<not> (snd((snd (clist!i))!m), snd((snd (clist!i))!Suc m)) \\<in> Rely(xs!i))\"\n     by fastforce\n    have notP:\"(\\<forall>i<m. \\<not> ?P i)\" using fist_occ by blast     \n    have fst_clist_\\<Gamma>:\"\\<forall>i<length clist. fst(clist!i) = \\<Gamma>\" \n      using a7 unfolding conjoin_def same_functions_def by fastforce\n    have compat:\"(\\<Gamma>\\<turnstile>\\<^sub>p(l!m)  \\<rightarrow> (l!(Suc m))) \\<and> \n            (\\<exists>i<length clist. \n               ((fst (clist!i))\\<turnstile>\\<^sub>c ((snd (clist!i))!m)  \\<rightarrow> ((snd (clist!i))!(Suc m))) \\<and> \n            (\\<forall>l<length clist. \n               l\\<noteq>i \\<longrightarrow>  (fst (clist!l))\\<turnstile>\\<^sub>c (snd (clist!l))!m  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc m)))) \\<or> \n         (\\<Gamma>\\<turnstile>\\<^sub>p(l!m)  \\<rightarrow>\\<^sub>e (l!(Suc m)) \\<and> \n          (\\<forall>i<length clist.  (fst (clist!i))\\<turnstile>\\<^sub>c (snd (clist!i))!m  \\<rightarrow>\\<^sub>e ((snd (clist!i))!(Suc m))))\"\n     using a7 fst_occ unfolding conjoin_def compat_label_def by simp\n     {\n       assume a20: \"(\\<Gamma>\\<turnstile>\\<^sub>p(l!m)  \\<rightarrow>\\<^sub>e (l!(Suc m)) \\<and> \n          (\\<forall>i<length clist.  (fst (clist!i))\\<turnstile>\\<^sub>c (snd (clist!i))!m  \\<rightarrow>\\<^sub>e ((snd (clist!i))!(Suc m))))\"\n       then have \"(snd (l!m),snd (l!(Suc m))) \\<in> R\"       \n       using fst_occ a5  unfolding par_assum_def by fastforce\n       then have \"(snd(l!m), snd(l!(Suc m))) \\<in>  Rely(xs!i)\"\n       using fst_occ a3 a0 by fastforce\n       then have \"(snd ((snd (clist!i))!m), snd ((snd (clist!i))!(Suc m)) ) \\<in>  Rely(xs!i)\" \n       using a7 fst_occ unfolding conjoin_def same_state_def by fastforce        \n       then have False using fst_occ by auto\n     }note l = this\n     {\n      assume a20:\"(\\<Gamma>\\<turnstile>\\<^sub>p(l!m)  \\<rightarrow> (l!(Suc m))) \\<and> \n            (\\<exists>i<length clist. \n               ((fst (clist!i))\\<turnstile>\\<^sub>c ((snd (clist!i))!m)  \\<rightarrow> ((snd (clist!i))!(Suc m))) \\<and> \n            (\\<forall>l<length clist. \n               l\\<noteq>i \\<longrightarrow>  (fst (clist!l))\\<turnstile>\\<^sub>c (snd (clist!l))!m  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc m))))\"\n      then obtain i'  \n      where i':\"i'<length clist \\<and> \n               ((fst (clist!i'))\\<turnstile>\\<^sub>c ((snd (clist!i'))!m)  \\<rightarrow> ((snd (clist!i'))!(Suc m))) \\<and> \n               (\\<forall>l<length clist. \n                 l\\<noteq>i' \\<longrightarrow>  (fst (clist!l))\\<turnstile>\\<^sub>c (snd (clist!l))!m  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc m)))\"\n      by fastforce\n      then have eq_\\<Gamma>:\"\\<Gamma> = fst (clist!i')\" using a7 unfolding conjoin_def same_functions_def by fastforce\n      obtain fp fs sp ss \n      where prod_step: \" \n               \\<Gamma>\\<turnstile>\\<^sub>c (fp, fs) \\<rightarrow> (sp,ss) \\<and> \n              fp = fst (((snd (clist!i'))!m)) \\<and> fs = snd (((snd (clist!i'))!m)) \\<and> \n              sp = fst ((snd (clist!i'))!(Suc m)) \\<and> ss = snd((snd (clist!i'))!(Suc m)) \\<and>\n              \\<Gamma> = fst (clist!i') \"\n      using a7 i' unfolding conjoin_def same_functions_def by fastforce            \n      then have False\n      proof (cases \"i = i'\")\n        case True       \n        then have \"l!m = l!(Suc m) \\<and> (\\<exists>ns. snd (l!m) = Normal ns )\"\n          using step_e_step_c_eq[OF a7] i' fst_occ eq_\\<Gamma> by blast\n        then have \"\\<Gamma>\\<turnstile>\\<^sub>p(l!m)  \\<rightarrow>\\<^sub>e (l!(Suc m))\" \n          using step_pe.ParEnv  by (metis prod.collapse)           \n        then have \"(snd (l ! m), snd (l ! Suc m)) \\<in> R \"\n          using fst_occ  a5 unfolding par_assum_def by fastforce\n        then have \"(snd (l ! m), snd (l ! Suc m)) \\<in> Rely (xs ! i)\"\n          using a0 a3 fst_occ by fastforce\n        then show ?thesis using fst_occ a7\n          unfolding conjoin_def same_state_def  \n          by fastforce         \n      next\n        case False  note not_eq = this       \n        thus ?thesis \n        proof (cases \"fp = sp\")\n          case True \n          then have  \"fs = ss \\<and> (\\<exists>ns. fs=Normal ns)\" \n            using prod_step step_change_p_or_eq_s_normal[of \"\\<Gamma>\" fp fs sp ss] \n          by fastforce\n          then have \"\\<Gamma>\\<turnstile>\\<^sub>c (fp, fs) \\<rightarrow>\\<^sub>e (sp, ss)\" using True step_e.Env \n            by fastforce\n          then have \"l!m = l!(Suc m) \\<and> (\\<exists>ns. snd (l!m) = Normal ns )\"\n            using step_e_step_c_eq[OF a7] prod_step i' fst_occ prod.collapse by auto\n          then have \"\\<Gamma>\\<turnstile>\\<^sub>p(l!m)  \\<rightarrow>\\<^sub>e (l!(Suc m))\" \n            using step_pe.ParEnv  by (metis prod.collapse)           \n          then have \"(snd (l ! m), snd (l ! Suc m)) \\<in> R \"\n            using fst_occ  a5 unfolding par_assum_def by fastforce\n          then have \"(snd (l ! m), snd (l ! Suc m)) \\<in> Rely (xs ! i)\"\n            using a0 a3 fst_occ by fastforce\n          then show ?thesis using fst_occ a7\n            unfolding conjoin_def same_state_def  \n          by fastforce                   \n        next\n          case False                    \n          let ?l1 = \"take (Suc (Suc m)) (snd(clist!i'))\"\n          have clist_cptn:\"(\\<Gamma>,snd(clist!i')) \\<in> cptn\" using a6 i' unfolding cp_def by fastforce\n          have sucm_len:\"Suc m < length (snd (clist!i'))\" \n            using i' fst_occ a7 unfolding conjoin_def same_length_def by fastforce          \n          then have summ_lentake:\"Suc m < length ?l1\" by fastforce\n          have len_l: \"0<length l\" using fst_occ by fastforce\n          also then have \"snd (clist!i')\\<noteq>[]\" \n            using i' a7 unfolding conjoin_def same_length_def by fastforce\n          ultimately have \"snd (last (snd (clist ! i'))) = snd (last l)\"\n            using a7 i' conjoin_last_same_state by fastforce\n          then have last_i_notF:\"snd (last (snd(clist!i'))) \\<notin> Fault ` F\" \n            using a9 by auto  \n          have \"\\<forall>i<length (snd(clist!i')).  snd (snd(clist!i') ! i) \\<notin> Fault ` F \" \n            using  last_not_F[OF clist_cptn last_i_notF] by auto \n          also have suc_m_i':\"Suc m < length (snd (clist !i'))\"\n            using fst_occ i' a7 unfolding conjoin_def same_length_def by fastforce\n          ultimately have last_take_not_f:\"snd (last (take (Suc (Suc m)) (snd(clist!i')))) \\<notin> Fault ` F\"\n            by (simp add: take_Suc_conv_app_nth)           \n          have not_env_step:\"\\<not> \\<Gamma>\\<turnstile>\\<^sub>c snd (clist ! i') ! m \\<rightarrow>\\<^sub>e snd (clist ! i') ! Suc m\"\n            using False etran_ctran_eq_p_normal_s i' prod_step by blast           \n          then have \"snd ((snd(clist!i'))!0)\\<in> Normal ` p\" \n            using len_l a7 i' a5 unfolding conjoin_def same_state_def par_assum_def by fastforce\n          then have \"snd ((snd(clist!i'))!0)\\<in> Normal ` (Pre (xs ! i'))\"\n            using a1 i' a3 by fastforce\n          then have \"snd ((take (Suc (Suc m)) (snd(clist!i')))!0)\\<in> Normal `(Pre (xs ! i'))\" \n            by fastforce       \n          moreover have \n          \"\\<forall>j. Suc j < Suc (Suc m) \\<longrightarrow>\n                \\<Gamma>\\<turnstile>\\<^sub>c snd (clist ! i') ! j \\<rightarrow>\\<^sub>e snd (clist ! i') ! Suc j \\<longrightarrow>\n                (snd (snd (clist ! i') ! j), snd (snd (clist ! i') ! Suc j)) \\<in> Rely (xs ! i')\" \n            using not_env_step fst_occ Suc_less_eq fist_occ i' less_SucE less_trans_Suc by auto\n          then have \"\\<forall>j. Suc j < length (take (Suc (Suc m)) (snd(clist!i'))) \\<longrightarrow>\n                \\<Gamma>\\<turnstile>\\<^sub>c snd (clist ! i') ! j \\<rightarrow>\\<^sub>e snd (clist ! i') ! Suc j \\<longrightarrow>\n                (snd (snd (clist ! i') ! j), snd (snd (clist ! i') ! Suc j)) \\<in> Rely (xs ! i')\"\n            by fastforce \n          ultimately have \"(\\<Gamma>, (take (Suc (Suc m)) (snd(clist!i')))) \\<in> \n                             assum ((Pre (xs ! i')),Rely (xs ! i')) F\"\n            unfolding assum_def by fastforce         \n          moreover have \"(\\<Gamma>,snd(clist!i')) \\<in> cptn\" using a6 i' unfolding cp_def by fastforce\n          then have \"(\\<Gamma>,take (Suc (Suc m)) (snd(clist!i'))) \\<in> cptn\"\n            by (simp add: takecptn_is_cptn)              \n          then have \"(\\<Gamma>,take (Suc (Suc m)) (snd(clist!i'))) \\<in> cp \\<Gamma> (Com(xs!i')) s\"\n            using i' a3 a6 unfolding cp_def by fastforce          \n          ultimately have t:\"(\\<Gamma>,take (Suc (Suc m)) (snd(clist!i'))) \\<in> \n                              comm (Guar (xs ! i'), (Post (xs ! i'),Abr (xs ! i'))) F \"\n          using a8 a2 a3 i' unfolding com_cvalidity_def com_validity_def by fastforce               \n          have \"(snd(take (Suc (Suc m)) (snd(clist!i'))!m), \n                        snd(take (Suc (Suc m)) (snd(clist!i'))!(Suc m))) \\<in> Guar (xs ! i')\"\n            using eq_\\<Gamma>  i' comm_dest1[OF t last_take_not_f summ_lentake] by fastforce\n          \n          then have \"(snd( (snd(clist!i'))!m), \n                        snd((snd(clist!i'))!(Suc m))) \\<in> Guar (xs ! i')\"\n          by fastforce\n          then have \"(snd( (snd(clist!i))!m), \n                      snd((snd(clist!i))!(Suc m))) \\<in> Guar (xs ! i')\"\n           using a7 fst_occ unfolding conjoin_def same_state_def by (metis Suc_lessD i' snd_conv) \n          then have \"(snd( (snd(clist!i))!m), \n                      snd((snd(clist!i))!(Suc m))) \\<in> Rely (xs ! i)\"\n          using not_eq a0 i' a3 fst_occ by auto          \n          then have \"False\" using fst_occ by auto\n          then show ?thesis by auto\n        qed\n      qed\n     }  \n  then have False using compat l by auto\n} thus ?thesis by auto\nqed\n\nlemma two: \n  \"\\<lbrakk> \\<forall>i<length xs. R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n       \\<subseteq> (Rely (xs ! i));\n   p \\<subseteq> (\\<Inter>i<length xs. (Pre (xs ! i)));\n   \\<forall>i<length xs.\n    \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)];\n   length xs=length clist; (\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s; (\\<Gamma>,l)\\<in>par_assum (p, R) F;\n  \\<forall>i<length clist. clist!i\\<in>cp \\<Gamma> (Com(xs!i)) s; (\\<Gamma>,l) \\<propto> clist;(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]);\n  snd (last l) \\<notin> Fault ` F\\<rbrakk>\n  \\<Longrightarrow> \\<forall>j i ns ns'. i<length clist \\<and> Suc j<length l \\<longrightarrow> \n      \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>  ((snd (clist!i))!Suc j) \\<longrightarrow>       \n        (snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in> Guar(xs!i) \"\nproof -\n  assume a0:\"\\<forall>i<length xs. R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n       \\<subseteq> (Rely (xs ! i))\" and\n         a1:\"p \\<subseteq> (\\<Inter>i<length xs. (Pre (xs ! i)))\" and\n         a2:\"\\<forall>i<length xs.\n    \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)]\" and\n         a3: \"length xs=length clist\" and\n         a4: \"(\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s\" and\n         a5: \"(\\<Gamma>,l)\\<in>par_assum (p, R) F\" and\n         a6: \"\\<forall>i<length clist. clist!i\\<in>cp \\<Gamma> (Com(xs!i)) s\" and\n         a7: \"(\\<Gamma>,l) \\<propto> clist\" and\n         a8: \"(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a])\" and \n         a9: \"snd (last l) \\<notin> Fault ` F\"\n  {\n     assume a10:\"(\\<exists>i j. i<length clist \\<and> Suc j<length l \\<and>  \n      \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>  ((snd (clist!i))!Suc j) \\<and> \n       \\<not> (snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in> Guar(xs!i)) \"\n     then obtain j where a10: \"\\<exists>i. i<length clist \\<and> Suc j<length l \\<and>\n      \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>  ((snd (clist!i))!Suc j) \\<and>        \n      \\<not> (snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in> Guar(xs!i)\"\n     by fastforce\n     let ?P = \"\\<lambda>j. \\<exists>i. i<length clist \\<and> Suc j<length l \\<and>\n      \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>  ((snd (clist!i))!Suc j) \\<and>       \n      \\<not> (snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in> Guar(xs!i)\"     \n     obtain m where fist_occ:\"?P m \\<and> (\\<forall>i<m. \\<not> ?P i)\" using exists_first_occ[of ?P j] a10 by blast\n     then have P:\"?P m\" by fastforce\n     then have notP:\"(\\<forall>i<m. \\<not> ?P i)\" using fist_occ by blast\n     obtain i ns ns' where fst_occ:\"i<length clist \\<and> Suc m<length l \\<and> \n      \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!m) \\<rightarrow>  ((snd (clist!i))!Suc m) \\<and>      \n      (\\<not> (snd((snd (clist!i))!m), snd((snd (clist!i))!Suc m)) \\<in>  Guar(xs!i))\"\n       using P by fastforce\n     have fst_clist_i: \"fst (clist!i) = \\<Gamma>\" \n         using a7 fst_occ unfolding conjoin_def same_functions_def \n         by fastforce\n     have \"clist!i\\<in>cp \\<Gamma> (Com(xs!i)) s\" using a6 fst_occ by fastforce\n     then have clistcp:\"(\\<Gamma>, snd (clist!i))\\<in>cp \\<Gamma> (Com(xs!i)) s\" \n         using  fst_occ a7 unfolding conjoin_def same_functions_def by fastforce\n     let ?li=\"take (Suc (Suc m)) (snd (clist!i))\"     \n     have \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)]\"\n       using a8 a2 a3 fst_occ unfolding com_cvalidity_def by fastforce\n     moreover have take_in_ass:\"(\\<Gamma>, take (Suc (Suc m)) (snd (clist!i))) \\<in> assum (Pre(xs!i), Rely(xs!i)) F\"     \n     proof -\n       have length_take_length_l:\"length (take (Suc (Suc m)) (snd (clist!i))) \\<le> length l\"\n         using a7 fst_occ unfolding conjoin_def same_length_def by auto\n       have \"snd((?li!0)) \\<in> Normal ` Pre(xs!i)\" \n       proof -\n         have \"(take (Suc (Suc m)) (snd (clist!i)))!0 = (snd (clist!i))!0\" by fastforce\n         moreover have \"snd (snd(clist!i)!0) = snd (l!0)\" \n           using a7 fst_occ unfolding conjoin_def same_state_def by fastforce\n         moreover have \"snd (l!0) \\<in> Normal ` p\" \n           using a5 unfolding par_assum_def by fastforce\n         ultimately show ?thesis using a1 a3 fst_occ by fastforce \n       qed note left=this\n       thus ?thesis  \n         using two'[OF a0 a1 a2 a3 a4 a5 a6 a7 a8 a9] fst_occ unfolding assum_def by fastforce\n       qed     \n     moreover have \"(\\<Gamma>,take (Suc (Suc m)) (snd (clist!i))) \\<in> cp \\<Gamma> (Com(xs!i)) s\"\n       using takecptn_is_cptn clistcp unfolding cp_def by fastforce      \n     ultimately have comm:\"(\\<Gamma>, take (Suc (Suc m)) (snd (clist!i)))\\<in>comm(Guar(xs!i),(Post (xs ! i),Abr (xs ! i))) F\"       \n        unfolding com_validity_def by fastforce  \n     also have not_fault:\"snd (last (take (Suc (Suc m)) (snd (clist!i))))  \\<notin> Fault ` F\"\n     proof -      \n       have cptn:\"(\\<Gamma>, snd (clist!i)) \\<in> cptn\" \n         using fst_clist_i a6 fst_occ unfolding cp_def by fastforce   \n       then have \"(snd (clist!i))\\<noteq>[]\" \n        using cptn.simps list.simps(3) \n        by fastforce               \n       then have \"snd (last (snd (clist!i))) = snd (last l)\"\n         using conjoin_last_same_state fst_occ a7 by fastforce\n       then have \"snd (last (snd (clist!i))) \\<notin> Fault ` F\" using a9\n         by simp\n       also have sucm:\"Suc m < length (snd (clist!i))\" \n         using fst_occ a7 unfolding conjoin_def same_length_def by fastforce\n       ultimately have sucm_not_fault:\"snd ((snd (clist!i))!(Suc m)) \\<notin> Fault ` F\"\n         using last_not_F cptn by blast \n       have \"length (take (Suc (Suc m)) (snd (clist!i))) = Suc (Suc m)\" \n         using sucm by fastforce\n       then have \"last (take (Suc (Suc m)) (snd (clist!i))) =  (take (Suc (Suc m)) (snd (clist!i)))!(Suc m)\"\n         by (metis Suc_diff_1 Suc_inject last_conv_nth list.size(3) old.nat.distinct(2) zero_less_Suc)\n       moreover have \"(take (Suc (Suc m)) (snd (clist!i)))!(Suc m) = (snd (clist!i))!(Suc m)\" \n         by fastforce      \n       ultimately show ?thesis using sucm_not_fault by fastforce\n     qed\n     then have \" (Suc m < length (snd (clist ! i)) ) \\<longrightarrow>\n                 (\\<Gamma>\\<turnstile>\\<^sub>c (snd (clist ! i)) ! m \\<rightarrow> (snd (clist ! i)) ! Suc m) \\<longrightarrow>                      \n                    (snd ((snd (clist ! i)) ! m), snd ((snd (clist ! i)) ! Suc m)) \\<in> Guar(xs!i)\"\n       using comm_dest [OF comm not_fault] by auto     \n     then have \"False\" using fst_occ using a7 unfolding conjoin_def same_length_def by fastforce\n  } thus ?thesis by fastforce\nqed\n\nlemma par_cptn_env_comp:\n  \"(\\<Gamma>,l) \\<in> par_cptn \\<and> Suc i<length l \\<Longrightarrow> \n   \\<Gamma>\\<turnstile>\\<^sub>p l!i \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<or> \\<Gamma> \\<turnstile>\\<^sub>p l!i \\<rightarrow> (l!(Suc i))\"\nproof -\n  assume a0:\"(\\<Gamma>,l) \\<in> par_cptn \\<and> Suc i<length l\"         \n  then obtain c1 s1 c2 s2 where li:\"l!i=(c1,s1) \\<and> l!(Suc i) = (c2,s2)\"  by fastforce\n  obtain xs ys where l:\"l= xs@((l!i)#(l!(Suc i))#ys)\" using a0\n    by (metis Cons_nth_drop_Suc Suc_less_SucD id_take_nth_drop less_SucI)\n  moreover then have \"(drop (length xs) l) = ((l!i)#(l!(Suc i))#ys)\"\n    by (metis append_eq_conv_conj) \n  moreover then have \"length xs < length l\" using leI by fastforce \n  ultimately have \"(\\<Gamma>,((l!i)#(l!(Suc i))#ys))\\<in>par_cptn\" \n    using a0 droppar_cptn_is_par_cptn by fastforce\n  also then have \"(\\<Gamma>,(l!(Suc i))#ys)\\<in>par_cptn\" using par_cptn_dest li by fastforce\n  ultimately show ?thesis using li par_cptn_elim_cases(2)\n    by metis\nqed\n\n\nlemma three:\n  \"\\<lbrakk>xs\\<noteq>[]; \\<forall>i<length xs. R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n       \\<subseteq> (Rely (xs ! i));\n   p \\<subseteq> (\\<Inter>i<length xs. (Pre (xs ! i)));\n   \\<forall>i<length xs.\n     \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)];\n   length xs=length clist; (\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s; (\\<Gamma>,l) \\<in> par_assum(p, R) F;\n    \\<forall>i<length clist. clist!i\\<in>cp \\<Gamma> (Com(xs!i)) s; (\\<Gamma>,l) \\<propto> clist; (\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]);\n    snd (last l) \\<notin> Fault ` F\\<rbrakk>\n  \\<Longrightarrow> \\<forall>j i. i<length clist \\<and> Suc j<length l \\<longrightarrow>  \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>\\<^sub>e  ((snd (clist!i))!Suc j) \\<longrightarrow>\n      (snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in>            \n             (R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j))))\"\nproof -\n assume a0:\"xs\\<noteq>[]\" and\n        a1:\"\\<forall>i<length xs. R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n             \\<subseteq> (Rely (xs ! i))\" and\n        a2: \"p \\<subseteq> (\\<Inter>i<length xs.  (Pre (xs ! i)))\" and\n        a3: \"\\<forall>i<length xs.\n               \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)]\" and\n        a4: \"length xs=length clist\" and\n        a5: \"(\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s\" and\n        a6: \"(\\<Gamma>,l) \\<in> par_assum(p, R) F\" and\n        a7: \"\\<forall>i<length clist. clist!i\\<in>cp \\<Gamma> (Com(xs!i)) s\" and\n        a8: \"(\\<Gamma>,l) \\<propto> clist\" and\n        a9: \"(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a])\" and\n        10: \"snd (last l) \\<notin> Fault ` F\" \n  {\n  fix j i ns ns'\n  assume a00:\"i<length clist \\<and> Suc j<length l\" and\n         a11: \"\\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>\\<^sub>e  ((snd (clist!i))!Suc j)\"         \n  then have two:\"\\<forall>j i ns ns'. i<length clist \\<and> Suc j<length l \\<longrightarrow> \n      \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>  ((snd (clist!i))!Suc j) \\<longrightarrow>      \n        (snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in> (Guar(xs!i))\"\n     using two[OF a1 a2 a3 a4 a5 a6 a7 a8 a9 10] by auto\n  then have j_lenl:\"Suc j<length l\" using a00 by fastforce\n  have i_lj:\"i<length (fst (l!j)) \\<and> i<length (fst (l!(Suc j)))\" \n            using conjoin_same_length a00 a8 by fastforce \n  have fst_clist_\\<Gamma>:\"\\<forall>i<length clist. fst(clist!i) = \\<Gamma>\" using a8 unfolding conjoin_def same_functions_def by fastforce\n  have \"(\\<Gamma>\\<turnstile>\\<^sub>p(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> \n            (\\<exists>i<length clist. \n               ((fst (clist!i))\\<turnstile>\\<^sub>c ((snd (clist!i))!j)  \\<rightarrow> ((snd (clist!i))!(Suc j))) \\<and> \n            (\\<forall>l<length clist. \n               l\\<noteq>i \\<longrightarrow>  (fst (clist!l))\\<turnstile>\\<^sub>c (snd (clist!l))!j  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc j)))) \\<or> \n         (\\<Gamma>\\<turnstile>\\<^sub>p(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)) \\<and> \n          (\\<forall>i<length clist.  (fst (clist!i))\\<turnstile>\\<^sub>c (snd (clist!i))!j  \\<rightarrow>\\<^sub>e ((snd (clist!i))!(Suc j))))\"\n  using a8 a00 unfolding conjoin_def compat_label_def by simp\n  then have compat_label:\"(\\<Gamma>\\<turnstile>\\<^sub>p(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> \n            (\\<exists>i<length clist. \n               (\\<Gamma>\\<turnstile>\\<^sub>c ((snd (clist!i))!j)  \\<rightarrow> ((snd (clist!i))!(Suc j))) \\<and> \n            (\\<forall>l<length clist. \n               l\\<noteq>i \\<longrightarrow>  \\<Gamma>\\<turnstile>\\<^sub>c (snd (clist!l))!j  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc j)))) \\<or> \n         (\\<Gamma>\\<turnstile>\\<^sub>p(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)) \\<and> \n          (\\<forall>i<length clist.  \\<Gamma>\\<turnstile>\\<^sub>c (snd (clist!i))!j  \\<rightarrow>\\<^sub>e ((snd (clist!i))!(Suc j))))\"\n  using fst_clist_\\<Gamma> by blast\n  then have \"(snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in>            \n               (R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. Guar (xs ! j)))\" \n  proof        \n    assume a10:\"(\\<Gamma>\\<turnstile>\\<^sub>p(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> \n            (\\<exists>i<length clist. \n               (\\<Gamma>\\<turnstile>\\<^sub>c ((snd (clist!i))!j)  \\<rightarrow> ((snd (clist!i))!(Suc j))) \\<and> \n            (\\<forall>l<length clist. \n               l\\<noteq>i \\<longrightarrow>  \\<Gamma>\\<turnstile>\\<^sub>c (snd (clist!l))!j  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc j))))\" \n    then obtain i' where \n            a20:\"i'<length clist \\<and> \n             (\\<Gamma>\\<turnstile>\\<^sub>c ((snd (clist!i'))!j)  \\<rightarrow> ((snd (clist!i'))!(Suc j))) \\<and> \n             (\\<forall>l<length clist. \n                l\\<noteq>i' \\<longrightarrow>  \\<Gamma>\\<turnstile>\\<^sub>c (snd (clist!l))!j  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc j)))\" by blast    \n    thus ?thesis \n    proof (cases \"i'=i\")\n      case True note eq_i = this      \n      then obtain P S1 S2 where P:\"(snd (clist!i'))!j=(P,S1) \\<and> ((snd (clist!i'))!(Suc j)) = (P,S2)\"   \n        using a11 by (fastforce elim:etranE)       \n      thus ?thesis \n      proof (cases \"S1 = S2\")\n        case True \n        have snd_lj:\"(snd (l!j)) = snd ((snd (clist!i'))!j)\"\n            using a8 a20 a00 unfolding conjoin_def same_state_def\n            by fastforce     \n        have all_e:\"(\\<forall>l<length clist. \\<Gamma>\\<turnstile>\\<^sub>c (snd (clist!l))!j  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc j)))\"\n          using a11 a20 eq_i by fastforce\n        then have allP:\"\\<forall>l< length clist. fst ((snd (clist!l))!j) = fst ((snd (clist!l))!(Suc j))\"\n           by (fastforce elim:etranE)\n        then have \"fst (l!j) = (fst (l!(Suc j)))\"\n          using a8 conjoin_same_program_i_j [of \"(\\<Gamma>,l)\"] a00 by fastforce\n        also have \"snd (l!j) = snd (l!(Suc j))\"\n        proof -              \n          have \"(snd (l!Suc j)) = snd ((snd (clist!i'))!(Suc j))\"\n            using a8 a20 a00 unfolding conjoin_def same_state_def\n            by fastforce\n          then show ?thesis using snd_lj P True by auto\n        qed \n        ultimately have \"l!j = l!(Suc j)\" by (simp add: prod_eq_iff) \n        moreover have ns1:\"\\<exists>ns1. S1=Normal ns1\" \n          using P a20 step_change_p_or_eq_s_normal by fastforce                    \n        ultimately have \"\\<Gamma>\\<turnstile>\\<^sub>p(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j))\" \n          using P step_pe.ParEnv snd_lj by (metis prod.collapse snd_conv)          \n        then have \"(snd (l ! j), snd (l ! Suc j)) \\<in> R \"\n          using a00 a6 unfolding par_assum_def by fastforce\n        then show ?thesis using a8 a00 \n          unfolding conjoin_def same_state_def  \n         by fastforce\n      next\n        case False thus ?thesis \n          using a20 P a11 step_change_p_or_eq_s by fastforce\n      qed\n    next\n      case False \n      have i'_clist:\"i' < length clist\" using a20 by fastforce\n      then have clist_i'_Guardxs:\"(snd((snd (clist!i'))!j), snd((snd (clist!i'))!Suc j)) \\<in> Guar(xs!i')\"\n        using two a00 False a8 unfolding conjoin_def same_state_def\n        by (metis a20)\n      have \"snd((snd (clist!i))!j) = snd (l!j) \\<and> snd((snd (clist!i))!Suc j) = snd (l!Suc j)\" \n        using a00 a20 a8 unfolding conjoin_def same_state_def by fastforce\n      also have \"snd((snd (clist!i'))!j) = snd (l!j) \\<and> snd((snd (clist!i'))!Suc j) = snd (l!Suc j)\"\n        using j_lenl a20 a8 unfolding conjoin_def same_state_def by fastforce\n      ultimately have \"snd((snd (clist!i))!j) = snd((snd (clist!i'))!j) \\<and> \n                    snd((snd (clist!i))!Suc j) = snd((snd (clist!i'))!Suc j)\" \n      by fastforce\n      then have clist_i_Guardxs:\n        \"(snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in> \n            Guar(xs!i')\"  \n      using  clist_i'_Guardxs by fastforce      \n      thus ?thesis  \n        using False a20  a4 by fastforce        \n    qed\n  next\n    assume a10:\"(\\<Gamma>\\<turnstile>\\<^sub>p(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)) \\<and> \n          (\\<forall>i<length clist.  \\<Gamma>\\<turnstile>\\<^sub>c (snd (clist!i))!j  \\<rightarrow>\\<^sub>e ((snd (clist!i))!(Suc j))))\"      \n    then have \"(snd (l ! j), snd (l ! Suc j)) \\<in> R\"\n      using a00 a10 a6 unfolding par_assum_def by fastforce\n    then show ?thesis using a8 a00 \n      unfolding conjoin_def same_state_def\n      by fastforce\n  qed\n  }  thus ?thesis by blast\nqed\n\n                                                                                        \nlemma four:\n  \"\\<lbrakk>xs\\<noteq>[];  \\<forall>i<length xs.  R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n       \\<subseteq>  (Rely (xs ! i));\n   (\\<Union>j<length xs.  (Guar (xs ! j))) \\<subseteq> (G);\n   p \\<subseteq> (\\<Inter>i<length xs.  (Pre (xs ! i)));\n   \\<forall>i<length xs.\n     \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i),  Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)];\n    (\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s; (\\<Gamma>,l) \\<in> par_assum(p, R) F; Suc i < length l;\n   \\<Gamma>\\<turnstile>\\<^sub>p (l!i) \\<rightarrow> (l!(Suc i));\n   (\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]);\n   snd (last l) \\<notin> Fault ` F\\<rbrakk>\n  \\<Longrightarrow> (snd (l ! i), snd (l ! Suc i)) \\<in> G\"\nproof -\n  assume a0:\"xs\\<noteq>[]\" and\n         a1:\"\\<forall>i<length xs.  R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n             \\<subseteq>  (Rely (xs ! i))\" and\n         a2:\"(\\<Union>j<length xs.  (Guar (xs ! j))) \\<subseteq> (G)\" and\n         a3:\"p \\<subseteq> (\\<Inter>i<length xs.  (Pre (xs ! i)))\" and\n         a4:\"\\<forall>i<length xs.\n           \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i),  Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)]\" and\n         a5:\"(\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s\" and\n         a6:\"(\\<Gamma>,l) \\<in> par_assum(p, R) F\" and\n         a7: \"Suc i < length l\" and\n         a8:\"\\<Gamma>\\<turnstile>\\<^sub>p (l!i) \\<rightarrow> (l!(Suc i))\" and         \n         a10:\"(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a])\" and\n         a11:\"snd (last l) \\<notin> Fault ` F\"\n   have length_par_xs:\"length (ParallelCom xs) = length xs\" unfolding ParallelCom_def  by fastforce   \n   then have \"(ParallelCom xs)\\<noteq>[]\" using a0 by fastforce \n   then have \"(\\<Gamma>,l) \\<in>{(\\<Gamma>1,c). \\<exists>clist. (length clist)=(length (ParallelCom xs)) \\<and> \n               (\\<forall>i<length clist. (clist!i) \\<in> cp \\<Gamma> ((ParallelCom xs)!i) s) \\<and> (\\<Gamma>,c) \\<propto> clist \\<and> \\<Gamma>1=\\<Gamma>}\"\n     using one a5 by fastforce\n   then obtain clist where \"(length clist)=(length xs) \\<and> \n               (\\<forall>i<length clist. (clist!i) \\<in> cp \\<Gamma> ((ParallelCom xs)!i) s) \\<and> (\\<Gamma>,l) \\<propto> clist\"\n     using length_par_xs by auto\n   then have conjoin:\"(length clist)=(length xs) \\<and> \n               (\\<forall>i<length clist. (clist!i) \\<in> cp \\<Gamma>  (Com (xs ! i)) s) \\<and> (\\<Gamma>,l) \\<propto> clist\"\n     using ParallelCom_Com by fastforce\n   then have length_xs_clist:\"length xs = length clist\" by auto \n   have clist_cp:\"\\<forall>i<length clist. (clist!i) \\<in> cp \\<Gamma>  (Com (xs ! i)) s\" using conjoin by auto\n   have conjoin:\"(\\<Gamma>,l) \\<propto> clist\" using conjoin by auto     \n   have l_not_empty:\"l\\<noteq>[]\" using a5 par_cptn.simps unfolding par_cp_def by fastforce\n   then have l_g0:\"0<length l\" by fastforce  \n   then have last_l:\"last l = l!((length l) - 1)\" by (simp add: last_conv_nth)    \n   have \"\\<forall>i< length l. fst (l!i) = map (\\<lambda>x. fst ((snd x)!i)) clist\"\n     using conjoin unfolding conjoin_def same_program_def by fastforce\n   obtain Ps si Ps' ssi where li:\"l!i = (Ps,si) \\<and> l!(Suc i) = (Ps', ssi)\" by fastforce\n   then have \"\\<exists>j r. j<length Ps \\<and> Ps' = Ps[j:=r] \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c((Ps!j),si) \\<rightarrow> (r, ssi))\" \n     using a8 par_ctranE by fastforce\n   then obtain j r where step_c:\"j<length Ps \\<and> Ps' = Ps[j:=r] \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c((Ps!j),si) \\<rightarrow> (r, ssi))\"\n     by auto   \n   have length_Ps_clist:\n     \"length Ps = length clist \\<and> length Ps = length Ps'\" \n     using conjoin a7 conjoin_same_length li step_c by fastforce\n   have from_step:\"(snd (clist!j))!i = ((Ps!j),si) \\<and> (snd (clist!j))!(Suc i) = (Ps'!j,ssi)\"  \n   proof -     \n     have f2: \"Ps = fst (snd (\\<Gamma>, l) ! i)\" and f2':\"Ps' = fst (snd (\\<Gamma>, l) ! (Suc i))\"\n       using li by auto\n     have f3:\"si = snd (snd (\\<Gamma>, l) ! i) \\<and> ssi = snd (snd (\\<Gamma>, l) ! (Suc i))\"\n       by (simp add: li)\n     then have \"(snd (clist!j))!i = ((Ps!j),si)\"\n       using f2 conjoin a7 step_c unfolding conjoin_def same_program_def same_state_def by force     \n     moreover have \"(snd (clist!j))!(Suc i) = (Ps'!j,ssi)\"\n       using f2' f3 conjoin a7 step_c length_Ps_clist \n      unfolding conjoin_def same_program_def same_state_def \n       by auto\n     ultimately show ?thesis by auto\n   qed      \n   then have step_clist:\"\\<Gamma>\\<turnstile>\\<^sub>c(snd (clist!j))!i \\<rightarrow> (snd (clist!j))!(Suc i)\" \n     using from_step  step_c by fastforce\n   have j_xs:\"j<length xs\" using step_c length_Ps_clist length_xs_clist by auto\n   have \"j<length clist\" using j_xs length_xs_clist by auto    \n   also have \n     \"\\<forall>i j ns ns'. j < length clist \\<and> Suc i < length l \\<longrightarrow>\n            \\<Gamma>\\<turnstile>\\<^sub>c snd (clist ! j) ! i \\<rightarrow> snd (clist ! j) ! Suc i \\<longrightarrow>             \n              (snd (snd (clist ! j) ! i), snd (snd (clist ! j) ! Suc i)) \\<in> Guar (xs ! j)\"\n    using two[OF a1 a3 a4 length_xs_clist a5 a6 clist_cp conjoin a10 a11] by auto\n   ultimately have \"(snd (snd (clist ! j) ! i), snd (snd (clist ! j) ! Suc i)) \\<in> Guar (xs ! j)\"\n     using a7 step_c length_Ps_clist step_clist by metis     \n   then have \"(snd (l!i), snd (l!(Suc i)))\\<in> Guar (xs ! j)\"\n      using from_step a2 length_xs_clist step_c li by fastforce\n   then show ?thesis using a2 j_xs\n     unfolding sep_conj_def tran_True_def after_def Satis_def by fastforce\nqed\n\nlemma same_program_last:\"l\\<noteq>[] \\<Longrightarrow> (\\<Gamma>,l) \\<propto> clist  \\<Longrightarrow> i<length clist \\<Longrightarrow>fst (last (snd (clist!i))) = fst (last l) ! i\" \nproof -\n   assume l_not_empty:\"l\\<noteq>[]\" and\n          conjoin: \"(\\<Gamma>,l) \\<propto> clist\" and\n          i_clist: \"i<length clist\"\n   have last_clist_eq_l:\"\\<forall>i<length clist. last (snd (clist!i)) = (snd (clist!i))!((length l) - 1)\"\n          using conjoin  last_conv_nth l_not_empty \n          unfolding conjoin_def same_length_def\n          by (metis length_0_conv snd_eqD) \n   then have last_l:\"last l = l!((length l)-1)\" using l_not_empty by (simp add: last_conv_nth)\n   have \"fst (last l) = map (\\<lambda>x. fst (snd x ! ((length l)-1))) clist\"\n     using l_not_empty last_l conjoin unfolding conjoin_def same_program_def  by auto\n   also have \"(map (\\<lambda>x. fst (snd x ! ((length l)-1))) clist)!i = \n            fst ((snd (clist!i))! ((length l)-1))\" using i_clist by fastforce\n   also have  \"fst ((snd (clist!i))! ((length l)-1)) = \n             fst ((snd (clist!i))! ((length (snd (clist!i)))-1))\" \n     using conjoin i_clist unfolding conjoin_def same_length_def by fastforce\n   also then have \"fst ((snd (clist!i))! ((length (snd (clist!i)))-1)) = fst (last (snd (clist!i)))\"\n     using i_clist l_not_empty conjoin last_clist_eq_l last_conv_nth unfolding conjoin_def same_length_def\n     by presburger\n   finally show ?thesis by auto\nqed\n\n\n\nlemma five:\n  \"\\<lbrakk>xs\\<noteq>[];  \\<forall>i<length xs.  R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n       \\<subseteq> (Rely (xs ! i));\n   p \\<subseteq> (\\<Inter>i<length xs. (Pre (xs ! i)));\n   (\\<Inter>i<length xs. (Post (xs ! i))) \\<subseteq> q;\n   (\\<Union>i<length xs. (Abr (xs ! i))) \\<subseteq> a ;\n   \\<forall>i < length xs.\n    \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)];\n    (\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s; (\\<Gamma>,l) \\<in> par_assum(p, R) F;\n   All_End (last l); snd (last l) \\<notin> Fault ` F;(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]) \\<rbrakk> \\<Longrightarrow> \n                   (\\<exists>j<length (fst (last l)). fst (last l)!j=Throw \\<and> \n                        snd (last l) \\<in> Normal ` (a)) \\<or>\n                   (\\<forall>j<length (fst (last l)). fst (last l)!j=Skip \\<and>\n                        snd (last l) \\<in> Normal ` q)\"\nproof-\n  assume a0:\"xs\\<noteq>[]\" and \n         a1:\"\\<forall>i<length xs.  R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n                                                                     \\<subseteq>  (Rely (xs ! i))\" and\n         a2:\"p \\<subseteq> (\\<Inter>i<length xs. (Pre (xs ! i)))\" and\n         a3:\"(\\<Inter>i<length xs. (Post (xs ! i))) \\<subseteq> q\" and\n         a4:\"(\\<Union>i<length xs. (Abr (xs ! i))) \\<subseteq> a\" and\n         a5:\"\\<forall>i < length xs.\n               \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i), \n                                             Rely (xs ! i), Guar (xs ! i), \n                                             Post (xs ! i),Abr (xs ! i)]\" and\n         a6:\"(\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s\" and\n         a7:\"(\\<Gamma>,l) \\<in> par_assum(p, R) F\"and\n         a8:\"All_End (last l)\" and\n         a9:\"snd (last l) \\<notin> Fault ` F\" and\n         a10:\"(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a])\"\n   have length_par_xs:\"length (ParallelCom xs) = length xs\" unfolding ParallelCom_def  by fastforce   \n   then have \"(ParallelCom xs)\\<noteq>[]\" using a0 by fastforce\n   then have \"(\\<Gamma>,l) \\<in>{(\\<Gamma>1,c). \\<exists>clist. (length clist)=(length (ParallelCom xs)) \\<and> \n               (\\<forall>i<length clist. (clist!i) \\<in> cp \\<Gamma> ((ParallelCom xs)!i) s) \\<and> (\\<Gamma>,c) \\<propto> clist \\<and> \\<Gamma>1=\\<Gamma>}\"\n     using one a6 by fastforce\n   then obtain clist where \"(length clist)=(length xs) \\<and> \n               (\\<forall>i<length clist. (clist!i) \\<in> cp \\<Gamma> ((ParallelCom xs)!i) s) \\<and> (\\<Gamma>,l) \\<propto> clist\"\n     using length_par_xs by auto\n   then have conjoin:\"(length clist)=(length xs) \\<and> \n               (\\<forall>i<length clist. (clist!i) \\<in> cp \\<Gamma>  (Com (xs ! i)) s) \\<and> (\\<Gamma>,l) \\<propto> clist\"\n     using ParallelCom_Com by fastforce\n   then have length_xs_clist:\"length xs = length clist\" by auto\n   (*have length_l_clist: \"length l = length clist\" \n     using conjoin unfolding conjoin_def same_length_def *)\n   have clist_cp:\"\\<forall>i<length clist. (clist!i) \\<in> cp \\<Gamma>  (Com (xs ! i)) s\" using conjoin by auto\n   have conjoin:\"(\\<Gamma>,l) \\<propto> clist\" using conjoin by auto\n   have l_not_empty:\"l\\<noteq>[]\" using a6 par_cptn.simps unfolding par_cp_def by fastforce\n   then have l_g0:\"0<length l\" by fastforce  \n   then have last_l:\"last l = l!((length l) - 1)\" by (simp add: last_conv_nth) \n   have clist_assum:\"\\<forall>i<length clist. (clist!i) \\<in> assum (Pre (xs!i),Rely (xs!i)) F\"     \n   proof -\n   { fix i\n     assume i_length:\"i<length clist\"\n     obtain \\<Gamma>1 li where clist:\"clist!i=(\\<Gamma>1,li)\" by fastforce    \n     then have \\<Gamma>eq:\"\\<Gamma>1=\\<Gamma>\" \n       using conjoin i_length unfolding conjoin_def same_functions_def by fastforce\n     have \"(\\<Gamma>1,li) \\<in> assum (Pre (xs!i),Rely (xs!i)) F\"\n     proof-\n       have l:\"snd (li!0) \\<in> Normal ` ( (Pre (xs!i)))\"\n       proof -  \n         have snd_l:\"snd (\\<Gamma>,l) = l\" by fastforce       \n         have \"snd (l!0) \\<in> Normal ` (p)\" \n         using a7 unfolding par_assum_def by fastforce         \n         also have \"snd (l!0) = snd (li!0)\"           \n           using i_length conjoin l_g0 clist \n           unfolding conjoin_def same_state_def by fastforce\n         finally show ?thesis using a2 i_length length_xs_clist\n            by auto \n       qed              \n       have r:\"(\\<forall>j. Suc j < length li \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>\\<^sub>c(li!j)  \\<rightarrow>\\<^sub>e (li!(Suc j)) \\<longrightarrow>                 \n                    (snd(li!j), snd(li!(Suc j))) \\<in> Rely (xs!i))\"        \n         using three[OF a0 a1 a2 a5 length_xs_clist a6 a7 clist_cp conjoin a10 a9]  \n               i_length conjoin a1 length_xs_clist clist                     \n         unfolding assum_def conjoin_def same_length_def by fastforce                                   \n       show ?thesis using l r \\<Gamma>eq unfolding assum_def by fastforce\n     qed \n     then have \"clist!i \\<in> assum (Pre (xs!i),Rely (xs!i)) F\" using clist by auto            \n   } thus ?thesis by auto\n   qed\n   then have clist_com:\"\\<forall>i<length clist. (clist!i) \\<in> comm  (Guar (xs!i),(Post(xs!i),Abr (xs!i))) F\"\n     using a5 unfolding com_cvalidity_def \n     using a10 unfolding com_validity_def using clist_cp length_xs_clist\n     by force              \n   have last_clist_eq_l:\"\\<forall>i<length clist. last (snd (clist!i)) = (snd (clist!i))!((length l) - 1)\"\n     using conjoin  last_conv_nth l_not_empty \n     unfolding conjoin_def same_length_def\n     by (metis length_0_conv snd_eqD) \n   then have last_clist_l:\"\\<forall>i<length clist. snd (last (snd (clist!i))) = snd (last l)\"\n     using last_l conjoin l_not_empty unfolding conjoin_def same_state_def same_length_def \n     by simp\n   show ?thesis\n   proof(cases \"\\<forall>i<length (fst (last l)). fst (last l)!i = Skip\")\n     assume ac1:\"\\<forall>i<length (fst (last l)). fst (last l)!i = Skip\"\n     have \"(\\<forall>j<length (fst (last l)). fst (last l) ! j = LanguageCon.com.Skip \\<and> snd (last l) \\<in> Normal ` q)\"\n     proof -\n       {fix j\n        assume aj:\"j<length (fst (last l))\"         \n        have \"\\<forall>i<length clist. snd (last (snd (clist!i))) \\<in> Normal ` Post(xs!i)\"\n        proof-\n          {fix i \n           assume a20:\"i<length clist\"\n           then have snd_last:\"snd (last (snd (clist!i))) = snd (last l)\" \n             using last_clist_l by fastforce\n           have last_clist_not_F:\"snd (last (snd (clist!i)))\\<notin> Fault ` F\"\n              using a9 last_clist_l a20 by fastforce\n           have \"fst (last l) ! i = Skip\" \n             using a20 ac1 conjoin_same_length[OF conjoin]\n             by (simp add: l_not_empty last_l )                       \n           also have \"fst (last l) ! i=fst (last (snd (clist!i)))\"\n             using same_program_last[OF l_not_empty conjoin a20]  by auto\n           finally have \"fst (last (snd (clist!i))) = Skip\" .\n           then have \"snd (last (snd (clist!i))) \\<in> Normal ` Post(xs!i)\" \n             using clist_com last_clist_not_F a20\n             unfolding comm_def final_def by fastforce\n          }  thus ?thesis by auto \n        qed             \n        then have \"\\<forall>i<length xs. snd (last l) \\<in> Normal ` Post(xs!i)\" \n          using last_clist_l length_xs_clist by fastforce\n        then have \"\\<forall>i<length xs. \\<exists>x\\<in>( Post(xs!i)). snd (last l) = Normal x\"\n          by fastforce\n        moreover have \"\\<forall>t. (\\<forall>i<length xs. t\\<in> Post (xs ! i))\\<longrightarrow> t\\<in> q\" using a3\n          by fastforce        \n        ultimately have \"(\\<exists>x\\<in> q. snd (last l) = Normal x)\" using a0\n           by (metis (mono_tags, lifting) length_greater_0_conv xstate.inject(1)) \n        then have \"snd (last l) \\<in> Normal ` q\" by fastforce          \n        then have \"fst (last l) ! j = LanguageCon.com.Skip \\<and> snd (last l) \\<in> Normal ` q\"\n          using aj ac1 by fastforce\n        } thus ?thesis by auto\n     qed      \n     thus ?thesis by auto\n   next\n     assume \"\\<not> (\\<forall>i<length (fst (last l)). fst (last l)!i = Skip)\"    \n     then obtain i where a20:\"i< length (fst (last l)) \\<and>  fst (last l)!i \\<noteq> Skip\" \n       by fastforce\n     then have last_i_throw:\"fst (last l)!i = Throw \\<and> (\\<exists>n. snd (last l) = Normal n)\" \n       using a8 unfolding All_End_def final_def by fastforce     \n     have \"length (fst (last l)) =  length clist\" \n       using conjoin_same_length[OF conjoin] l_not_empty last_l\n       by simp\n     then have i_length:\"i<length clist\" using a20 by fastforce\n     then have snd_last:\"snd (last (snd (clist!i))) = snd (last l)\" \n       using last_clist_l by fastforce\n     have last_clist_not_F:\"snd (last (snd (clist!i)))\\<notin> Fault ` F\"\n       using a9 last_clist_l i_length by fastforce\n     then have \"fst (last (snd (clist!i))) = fst (last l) ! i\" \n       using i_length same_program_last [OF l_not_empty conjoin] by fastforce\n     then have \"fst (last (snd (clist!i))) = Throw\"\n       using last_i_throw by fastforce\n     then have \"snd (last (snd (clist!i))) \\<in> Normal `  Abr(xs!i)\" \n       using clist_com last_clist_not_F i_length last_i_throw snd_last\n       unfolding comm_def final_def by fastforce\n     then have \"snd (last l)\\<in> Normal ` Abr(xs!i)\" using last_clist_l i_length\n       by fastforce\n     then have \"snd (last l)\\<in> Normal ` (a)\" using a4 a0 i_length length_xs_clist by fastforce\n     then have \"\\<exists>j<length (fst (last l)).\n        fst (last l) ! j = LanguageCon.com.Throw \\<and> snd (last l) \\<in> Normal ` a\"\n     using last_i_throw a20 by fastforce\n     thus ?thesis by auto\n   qed \nqed\n\n\nlemma ParallelEmpty [rule_format]:\n  \"\\<forall>i s. (\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom []) s \\<longrightarrow>\n  Suc i < length l \\<longrightarrow> \\<not> (\\<Gamma> \\<turnstile>\\<^sub>p (l!i) \\<rightarrow> (l!Suc i))\"\napply(induct_tac l)\n apply simp\napply clarify\napply(case_tac list,simp,simp)\napply(case_tac i)\n apply(simp add:par_cp_def ParallelCom_def) \n apply(erule par_ctranE,simp)\napply(simp add:par_cp_def ParallelCom_def)\napply clarify\napply(erule par_cptn.cases,simp)\n apply simp\nby (metis list.inject list.size(3) not_less0 step_p_pair_elim_cases)\n\nlemma ParallelEmpty2:\n  assumes a0:\"(\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom []) s\" and\n         a1: \"i < length l\" \n  shows \"fst (l!i) = []\"\nproof -\n  have paremp:\"ParallelCom [] = []\" unfolding ParallelCom_def by auto\n  then have l0:\"l!0 =([],s)\" using a0 unfolding par_cp_def by auto\n  then have \"(\\<Gamma>,l) \\<in> par_cptn\" using a0 unfolding par_cp_def by fastforce\n  thus ?thesis using l0 a1\n  proof (induct arbitrary: i s) \n    case ParCptnOne thus ?case by auto\n  next\n    case (ParCptnEnv \\<Gamma> P s1 t xs i s)\n    thus ?case\n    proof -\n      have f1: \"i < Suc (Suc (length xs))\"\n        using ParCptnEnv.prems(2) by auto\n      have \"(P, s1) = ([], s)\"\n        using ParCptnEnv.prems(1) by auto\n      then show ?thesis\n        using f1 by (metis (no_types) ParCptnEnv.hyps(3) diff_Suc_1 fst_conv length_Cons less_Suc_eq_0_disj nth_Cons')\n    qed    \n  next\n    case (ParCptnComp \\<Gamma> P s1 Q t xs)   \n    have \"(\\<Gamma>, (P,s1)#(Q, t) # xs) \\<in> par_cp \\<Gamma> (ParallelCom []) s1\" \n        using ParCptnComp(4) ParCptnComp(1) step_p_elim_cases by fastforce\n    then have \"\\<not> \\<Gamma>\\<turnstile>\\<^sub>p (P, s1) \\<rightarrow> (Q, t)\" using ParallelEmpty ParCptnComp by fastforce\n    thus ?case using ParCptnComp by auto\n  qed\nqed  \n\nlemma parallel_sound: \n  \"\\<forall>i<length xs.\n       R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n       \\<subseteq> (Rely (xs ! i)) \\<Longrightarrow>\n    (\\<Union>j<length xs. (Guar (xs ! j))) \\<subseteq> G \\<Longrightarrow>\n    p \\<subseteq> (\\<Inter>i<length xs. (Pre (xs ! i))) \\<Longrightarrow>\n    (\\<Inter>i<length xs. (Post (xs ! i))) \\<subseteq> q \\<Longrightarrow>\n    (\\<Union>i<length xs. (Abr (xs ! i))) \\<subseteq> a \\<Longrightarrow>    \n    \\<forall>i<length xs.\n       \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> Com (xs !i) sat [Pre (xs !i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)] \\<Longrightarrow>\n  \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> ParallelCom xs SAT [p, R, G, q,a]\n  \"\nproof -\n  assume \n  a0:\"\\<forall>i<length xs.\n      R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n       \\<subseteq>  (Rely (xs ! i))\" and\n   a1:\"(\\<Union>j<length xs.  (Guar (xs ! j))) \\<subseteq> G\" and\n   a2:\"p \\<subseteq> (\\<Inter>i<length xs.  (Pre (xs ! i)))\" and\n   a3:\"(\\<Inter>i<length xs.  (Post (xs ! i))) \\<subseteq> q\" and\n   a4:\"(\\<Union>i<length xs.  (Abr (xs ! i))) \\<subseteq> a\" and\n   a5:\"\\<forall>i<length xs.\n            \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> Com (xs !i) sat [Pre (xs !i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)]\"\n  { \n     assume a00:\"(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a])\"\n     { fix s l\n       assume a10: \"(\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s \\<and> (\\<Gamma>,l) \\<in> par_assum(p, R) F\"       \n       then have c_par_cp:\"(\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s\" by auto\n       have c_par_assum: \"(\\<Gamma>,l) \\<in> par_assum(p, R) F\" using a10 by auto\n       { fix i ns ns'\n         assume a20:\"snd (last l) \\<notin> Fault ` F\"\n         {\n            assume a30:\"Suc i<length l\"  and\n                   a31: \"\\<Gamma>\\<turnstile>\\<^sub>p(l!i)  \\<rightarrow> (l!(Suc i))\"                   \n            have xs_not_empty:\"xs\\<noteq>[]\" \n            proof -\n            {\n              assume \"xs = []\"\n              then have \"\\<not> (\\<Gamma> \\<turnstile>\\<^sub>p (l!i) \\<rightarrow> (l!Suc i))\" \n                using a30 a10 ParallelEmpty by fastforce\n              then have False using a31 by auto\n            } thus ?thesis by auto\n            qed            \n            then have \"(snd(l!i), snd(l!(Suc i))) \\<in>  G\"\n            using four[OF xs_not_empty a0 a1 a2 a5 c_par_cp c_par_assum a30 a31 a00 a20] by blast\n            \n         } then have \"Suc i<length l \\<longrightarrow> \n                     \\<Gamma>\\<turnstile>\\<^sub>p(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                      \n                     (snd(l!i), snd(l!(Suc i))) \\<in> G \" by auto \n            note l = this\n         { assume a30:\"All_End (last l)\"\n           then have xs_not_empty:\"xs\\<noteq>[]\" \n           proof - \n           { assume xs_emp:\"xs=[]\"\n             have lenl:\"0<length l\" using a10 unfolding par_cp_def using par_cptn.simps by fastforce\n             then have \"(length l) - 1 < length l\" by fastforce\n             then have \"fst(l!((length l) - 1)) = []\" using ParallelEmpty2 a10 xs_emp by fastforce\n             then have False using a30 lenl unfolding All_End_def\n               by (simp add: last_conv_nth )              \n           } thus ?thesis by auto\n           qed\n           then have \"(\\<exists>j<length (fst (last l)). fst (last l)!j=Throw \\<and> \n                        snd (last l) \\<in> Normal ` (a)) \\<or>\n                      (\\<forall>j<length (fst (last l)). fst (last l)!j=Skip \\<and>\n                        snd (last l) \\<in> Normal ` q)\"\n           using five[OF xs_not_empty a0 a2 a3 a4 a5 c_par_cp c_par_assum a30 a20 a00] by blast\n         } then have \"All_End (last l) \\<longrightarrow> \n                      (\\<exists>j<length (fst (last l)). fst (last l)!j=Throw \\<and> \n                        snd (last l) \\<in> Normal ` (a)) \\<or>\n                   (\\<forall>j<length (fst (last l)). fst (last l)!j=Skip \\<and>\n                        snd (last l) \\<in> Normal ` q)\" by auto \n           note res1 = conjI[OF l this] \n       }\n       then have  \"(\\<Gamma>,l) \\<in> par_comm(G, (q,a)) F\" unfolding par_comm_def by auto       \n     } \n     then have \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (ParallelCom xs) SAT [p, R, G, q,a]\" \n       unfolding par_com_validity_def par_cp_def by fastforce\n  } thus ?thesis using par_com_cvalidity_def by fastforce\nqed\n\n\ntheorem  \n par_rgsound:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> Ps SAT [p, R, G, q,a] \\<Longrightarrow>\n  \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> (ParallelCom Ps) SAT [p, R, G, q,a]\"\nproof (induction rule:par_rghoare.induct)\n  case (Parallel xs R G p q a \\<Gamma> \\<Theta> F)\n    thus ?case using localRG_sound parallel_sound[of xs R G p q a \\<Gamma> \\<Theta> F] \n      by fast\nqed\nlemma Conseq':\"\\<forall>s. s\\<in>p \\<longrightarrow>\n              (\\<exists>p' q' a' R' G'. \n                (\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [(p' Z), (R' Z), (G' Z), (q' Z),(a' Z)]) \\<and>\n                   (\\<exists> Z. s\\<in>p' Z \\<and> (q' Z \\<subseteq> q) \\<and> (a' Z \\<subseteq> a) \\<and> (G' Z \\<subseteq> G) \\<and> (R \\<subseteq> R' Z)))\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q,a]\"\nby (rule Conseq) meson\n\nlemma conseq:\"\\<lbrakk>\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [(p' Z), (R' Z), (G' Z), (q' Z),(a' Z)];\n              \\<forall>s. s \\<in> p \\<longrightarrow> (\\<exists> Z. s\\<in>p' Z \\<and> (q' Z \\<subseteq> q) \\<and> (a' Z \\<subseteq> a) \\<and> (G' Z \\<subseteq> G) \\<and> (R \\<subseteq> R' Z))\\<rbrakk>\n              \\<Longrightarrow>\n               \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q,a]\"\nby (rule Conseq) meson\n\nlemma conseqPrePost[trans]:\n \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p', R', G', q',a'] \\<Longrightarrow>\n  p\\<subseteq>p' \\<Longrightarrow> q' \\<subseteq> q \\<Longrightarrow> a' \\<subseteq> a \\<Longrightarrow> G' \\<subseteq> G \\<Longrightarrow> R \\<subseteq> R' \\<Longrightarrow>\n  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q,a]\"\nby (rule conseq) auto\n\nlemma conseqPre[trans]:\n \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p', R, G, q,a] \\<Longrightarrow>\n  p\\<subseteq>p' \\<Longrightarrow>\n  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q,a]\"\nby (rule conseq) auto\n\nlemma conseqPost[trans]:\n \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q',a'] \\<Longrightarrow>\n  q'\\<subseteq>q \\<Longrightarrow>  a'\\<subseteq>a \\<Longrightarrow>\n  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q,a]\"\nby (rule conseq) auto\n\ninductive_cases hoare_elim_skip_cases [cases set]:\n\"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> Skip sat [p, R, G, q,a]\"\n\n\n\n(* abbreviation \n \"stepc_rtrancl\" :: \"[('s,'p,'f) body,('s,'p,'f) config,('s,'p,'f) config] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>c (_ \\<rightarrow>\\<^sup>*/ _)\" [81,81,81] 100)\n where                                \n  \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sup>* cf1 \\<equiv> ((CONST stepc \\<Gamma>))\\<^sup>*\\<^sup>* cf0 cf1\" *)\n\n\nend\n", "meta": {"author": "CompSoftVer", "repo": "CSim2", "sha": "b09a4d77ea089168b1805db5204ac151df2b9eff", "save_path": "github-repos/isabelle/CompSoftVer-CSim2", "path": "github-repos/isabelle/CompSoftVer-CSim2/CSim2-b09a4d77ea089168b1805db5204ac151df2b9eff/ConCSimpl/LocalRG_HoareDefValidityN.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982315512488, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.2861149919934692}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |                    May 2005               |\n            |                   June 2005  (modified)   |\n            |              September 2005  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |               November 2005  (modified)   |\n            |                  April 2006  (modified)   |\n            |                  March 2007  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2017         |\n            |                  April 2018  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory CSP_F_law_alpha_par\nimports CSP_F_op_alpha_par CSP_F_law_decompo \n        CSP_T.CSP_T_law_alpha_par\nbegin\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite UnionT and InterT.                 *)\n(*                  Union (B ` A) = (UN x:A. B x)                      *)\n(*                  Inter (B ` A) = (INT x:A. B x)                     *)\n\n(*\ndeclare Union_image_eq [simp del]\ndeclare Inter_image_eq [simp del]\n*)\n\n(* no simp rules in Isabelle 2017 \ndeclare Sup_image_eq [simp del]\ndeclare Inf_image_eq [simp del]\n*)\n\n(*****************************************************************\n\n         1. associativity of |[X,Y]|\n         2. commutativity of |[X,Y]|\n         3. monotonicity of |[X,Y]|\n         4. \n\n *****************************************************************)\n\n(*********************************************************\n                        P |[X,Y]| Q\n *********************************************************)\n\n(************************************\n |         SKIP and SKIP            |\n ************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspF_SKIP_Alpha_parallel:\n  \"(SKIP |[{}, {}]| SKIP) =F[M1,M2] SKIP\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_SKIP_Alpha_parallel)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_failures_Alpha_parallel)\n apply (elim conjE exE)\n\n apply (simp add: in_failures)\n apply (elim disjE)\n apply (simp_all)\n apply (simp add: Evset_def)\n apply (subgoal_tac \"(s = <> | s = <Tick>)\")\n apply (erule disjE)\n apply (simp)\n apply (fast)\n apply (simp)\n apply (simp add: sett_subset_Tick)\n\n apply (subgoal_tac \"(s = <> | s = <Tick>)\")\n apply (erule disjE)\n apply (simp)\n apply (simp)\n apply (simp add: sett_subset_Tick)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_failures_Alpha_parallel)\n apply (rule_tac x=\"X\" in exI)\n apply (rule_tac x=\"X\" in exI)\n apply (simp)\n\n apply (simp add: in_failures)\n apply (auto)\ndone\n\n(************************************\n |          associativity           |\n ************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspF_Alpha_parallel_ass_lm1:\n          \"Ya Int insert Tick (Ev ` X1) Un\n          (Za Int insert Tick (Ev ` X2) Un Z Int insert Tick (Ev ` X3)) =\n           Ya Int insert Tick (Ev ` X1) Un\n           (Za Int insert Tick (Ev ` X2) Un Z Int insert Tick (Ev ` X3)) Int\n           insert Tick (Ev ` (X2 Un X3))\"\nby (auto)\n\nlemma cspF_Alpha_parallel_assoc:\n  \"(P1 |[X1, X2]| P2) |[X1 Un X2, X3]| P3 =F[M,M]\n   P1 |[X1, X2 Un X3]| (P2 |[X2, X3]| P3)\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Alpha_parallel_assoc)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_failures_Alpha_parallel)\n apply (elim conjE exE)\n apply (simp add: Un_upper1 Un_upper2 rest_tr_of_rest_tr_subset)\n apply (rule_tac x=\"Ya\" in exI, simp)\n apply (rule_tac x=\"(Za Int insert Tick (Ev ` X2)) Un \n                     (Z Int insert Tick (Ev ` X3))\" in exI)\n apply (simp add: Un_assoc)\n apply (simp add: cspF_Alpha_parallel_ass_lm1)\n\n apply (rule_tac x=\"Za\" in exI, simp)\n apply (rule_tac x=\"Z\" in exI, simp)\n apply (force)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_failures_Alpha_parallel)\n apply (elim conjE exE)\n apply (simp add: Un_upper1 Un_upper2 rest_tr_of_rest_tr_subset)\n apply (rule_tac x=\"Y Int insert Tick (Ev ` X1) Un\n                  (Ya Int insert Tick (Ev ` X2))\" in exI)\n apply (rule_tac x=\"Za\" in exI)\n apply (simp add: Un_assoc)\n apply (rule conjI)\n apply (fast)\n\n apply (rule_tac x=\"Y\" in exI, simp)\n apply (rule_tac x=\"Ya\" in exI, simp)\n apply (force)\ndone\n\nlemma cspF_Alpha_parallel_assoc_sym:\n  \"P1 |[X1, X2 Un X3]| (P2 |[X2, X3]| P3) =F[M,M]\n   (P1 |[X1, X2]| P2) |[X1 Un X2, X3]| P3\"\napply (rule cspF_sym)\nby (simp add: cspF_Alpha_parallel_assoc)\n\n(************************************\n |          commutativity           |\n ************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspF_Alpha_parallel_commut:\n  \"(P1 |[X1, X2]| P2) =F[M,M] (P2 |[X2, X1]| P1)\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Alpha_parallel_commut)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_failures_Alpha_parallel)\n apply (elim conjE exE)\n apply (rule_tac x=\"Z\" in exI)\n apply (rule_tac x=\"Y\" in exI)\n apply (simp add: Un_sym)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_failures_Alpha_parallel)\n apply (elim conjE exE)\n apply (rule_tac x=\"Z\" in exI)\n apply (rule_tac x=\"Y\" in exI)\n apply (simp add: Un_sym)\ndone\n\n(************************************\n |          monotonicity            |\n ************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspF_Alpha_parallel_mono:\n  \"[| X1 = X2 ; Y1 = Y2 ;\n      P1 <=F[M1,M2] Q1 ; \n      P2 <=F[M1,M2] Q2 |]\n           ==> P1 |[X1,Y1]| P2 <=F[M1,M2] Q1 |[X2,Y2]| Q2\"\napply (simp add: Alpha_parallel_def)\napply (simp add: cspF_Parallel_mono)\ndone\n\nlemma cspF_Alpha_parallel_cong:\n  \"[| X1 = X2 ; Y1 = Y2 ;\n      P1 =F[M1,M2] Q1 ; \n      P2 =F[M1,M2] Q2 |]\n           ==> P1 |[X1,Y1]| P2 =F[M1,M2] Q1 |[X2,Y2]| Q2\"\nby (simp add: cspF_eq_ref_iff cspF_Alpha_parallel_mono)\n\nlemmas cspF_decompo_Alpha_parallel = cspF_Alpha_parallel_mono\n                                     cspF_Alpha_parallel_cong\n\n(****************** to add them again ******************)\n(*\ndeclare Union_image_eq [simp]\ndeclare Inter_image_eq [simp]\n*)\n(*\ndeclare Sup_image_eq [simp]\ndeclare Inf_image_eq [simp]\n*)\nend\n\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/CSP_F/CSP_F_law_alpha_par.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6477982043529715, "lm_q2_score": 0.44167300566462553, "lm_q1q2_score": 0.2861149799807242}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      HoarePartialDef.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection \\<open>Hoare Logic for Partial Correctness\\<close>\ntheory HoarePartialDef imports Semantic begin\n\ntype_synonym ('s,'p) quadruple = \"('s assn \\<times> 'p \\<times> 's assn \\<times> 's assn)\"\n\nsubsection \\<open>Validity of Hoare Tuples: \\<open>\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\\<close>\\<close>\n\ndefinition\n  valid :: \"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com,'s assn,'s assn] => bool\"\n                (\"_\\<Turnstile>\\<^bsub>'/_\\<^esub>/ _ _ _,_\"  [61,60,1000, 20, 1000,1000] 60)\nwhere\n \"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<equiv> \\<forall>s t. \\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t \\<longrightarrow> s \\<in> Normal ` P \\<longrightarrow> t \\<notin> Fault ` F  \n                      \\<longrightarrow>  t \\<in>  Normal ` Q \\<union> Abrupt ` A\"\n\ndefinition\n  cvalid::\n  \"[('s,'p,'f) body,('s,'p) quadruple set,'f set,\n      's assn,('s,'p,'f) com,'s assn,'s assn] =>bool\"\n                (\"_,_\\<Turnstile>\\<^bsub>'/_\\<^esub>/ _ _ _,_\"  [61,60,60,1000, 20, 1000,1000] 60)\nwhere\n \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<equiv> (\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A) \\<longrightarrow> \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n\n\ndefinition\n  nvalid :: \"[('s,'p,'f) body,nat,'f set, \n                's assn,('s,'p,'f) com,'s assn,'s assn] => bool\"\n                (\"_\\<Turnstile>_:\\<^bsub>'/_\\<^esub>/ _ _ _,_\"  [61,60,60,1000, 20, 1000,1000] 60)\nwhere\n \"\\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A \\<equiv> \\<forall>s t. \\<Gamma>\\<turnstile>\\<langle>c,s \\<rangle> =n\\<Rightarrow> t \\<longrightarrow> s \\<in> Normal ` P \\<longrightarrow> t \\<notin> Fault ` F \n                        \\<longrightarrow> t \\<in>  Normal ` Q \\<union> Abrupt ` A\"\n\n\ndefinition\n  cnvalid::\n  \"[('s,'p,'f) body,('s,'p) quadruple set,nat,'f set, \n     's assn,('s,'p,'f) com,'s assn,'s assn] \\<Rightarrow> bool\"\n                (\"_,_\\<Turnstile>_:\\<^bsub>'/_\\<^esub>/ _ _ _,_\"  [61,60,60,60,1000, 20, 1000,1000] 60)\nwhere\n \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A \\<equiv> (\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A) \\<longrightarrow> \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\n\n\nnotation (ASCII)\n  valid  (\"_|='/_/ _ _ _,_\"  [61,60,1000, 20, 1000,1000] 60) and\n  cvalid  (\"_,_|='/_/ _ _ _,_\"  [61,60,60,1000, 20, 1000,1000] 60) and\n  nvalid  (\"_|=_:'/_/ _ _ _,_\"  [61,60,60,1000, 20, 1000,1000] 60) and\n  cnvalid  (\"_,_|=_:'/_/ _ _ _,_\"  [61,60,60,60,1000, 20, 1000,1000] 60)\n\n\nsubsection \\<open>Properties of Validity\\<close>\n\nlemma valid_iff_nvalid: \"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A = (\\<forall>n. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A)\"\n  apply (simp only: valid_def nvalid_def exec_iff_execn )\n  apply (blast dest: exec_final_notin_to_execn)\n  done\n \nlemma cnvalid_to_cvalid: \"(\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (unfold cvalid_def cnvalid_def valid_iff_nvalid [THEN eq_reflection])\n  apply fast\n  done\n\nlemma nvalidI: \n \"\\<lbrakk>\\<And>s t. \\<lbrakk>\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> =n\\<Rightarrow> t;s \\<in> P; t\\<notin> Fault ` F\\<rbrakk> \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (auto simp add: nvalid_def)\n\nlemma validI: \n \"\\<lbrakk>\\<And>s t. \\<lbrakk>\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> t;s \\<in> P; t\\<notin>Fault ` F\\<rbrakk> \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (auto simp add: valid_def)\n\nlemma cvalidI: \n \"\\<lbrakk>\\<And>s t. \\<lbrakk>\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A;\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t;s \\<in> P;t\\<notin>Fault ` F\\<rbrakk> \n          \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (auto simp add: cvalid_def valid_def)\n\nlemma cvalidD: \n \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A;\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A;\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t;s \\<in> P;t\\<notin>Fault ` F\\<rbrakk> \n  \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  by (auto simp add: cvalid_def valid_def)\n\nlemma cnvalidI: \n \"\\<lbrakk>\\<And>s t. \\<lbrakk>\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A;\n   \\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> =n\\<Rightarrow> t;s \\<in> P;t\\<notin>Fault ` F\\<rbrakk> \n          \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (auto simp add: cnvalid_def nvalid_def)\n\n\nlemma cnvalidD: \n \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A;\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A;\n   \\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> =n\\<Rightarrow> t;s \\<in> P;\n   t\\<notin>Fault ` F\\<rbrakk> \n  \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  by (auto simp add: cnvalid_def nvalid_def)\n\nlemma nvalid_augment_Faults:\n  assumes validn:\"\\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes F': \"F \\<subseteq> F'\"\n  shows \"\\<Gamma>\\<Turnstile>n:\\<^bsub>/F'\\<^esub> P c Q,A\"\nproof (rule nvalidI)\n  fix s t\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> =n\\<Rightarrow> t\" \n  assume P: \"s \\<in> P\"\n  assume F: \"t \\<notin> Fault ` F'\"\n  with F' have \"t \\<notin> Fault ` F\"\n    by blast\n  with exec P validn\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    by (auto simp add: nvalid_def)\nqed\n\nlemma valid_augment_Faults:\n  assumes validn:\"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes F': \"F \\<subseteq> F'\"\n  shows \"\\<Gamma>\\<Turnstile>\\<^bsub>/F'\\<^esub> P c Q,A\"\nproof (rule validI)\n  fix s t\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\"\n  assume F: \"t \\<notin> Fault ` F'\"\n  with F' have \"t \\<notin> Fault ` F\"\n    by blast\n  with exec P validn\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    by (auto simp add: valid_def)\nqed\n\nlemma nvalid_to_nvalid_strip:\n  assumes validn:\"\\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes F': \"F' \\<subseteq> -F\"\n  shows \"strip F' \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule nvalidI)\n  fix s t\n  assume exec_strip: \"strip F' \\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> =n\\<Rightarrow> t\" \n  assume P: \"s \\<in> P\"\n  assume F: \"t \\<notin> Fault ` F\"\n  from exec_strip obtain t' where\n    exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> =n\\<Rightarrow> t'\" and\n    t': \"t' \\<in> Fault ` (-F') \\<longrightarrow> t'=t\" \"\\<not> isFault t' \\<longrightarrow> t'=t\"\n    by (blast dest: execn_strip_to_execn)\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases \"t' \\<in> Fault ` F\")\n    case True\n    with t' F F' have False\n      by blast\n    thus ?thesis ..\n  next\n    case False\n    with exec P validn\n    have *: \"t' \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by (auto simp add: nvalid_def)\n    with t' have \"t'=t\"\n      by auto\n    with * show ?thesis\n      by simp\n  qed\nqed\n\n\nlemma valid_to_valid_strip:\n  assumes valid:\"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes F': \"F' \\<subseteq> -F\"\n  shows \"strip F' \\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule validI)\n  fix s t\n  assume exec_strip: \"strip F' \\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\"\n  assume F: \"t \\<notin> Fault ` F\"\n  from exec_strip obtain t' where\n    exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> t'\" and\n    t': \"t' \\<in> Fault ` (-F') \\<longrightarrow> t'=t\" \"\\<not> isFault t' \\<longrightarrow> t'=t\"\n    by (blast dest: exec_strip_to_exec)\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases \"t' \\<in> Fault ` F\")\n    case True\n    with t' F F' have False\n      by blast\n    thus ?thesis ..\n  next\n    case False\n    with exec P valid\n    have *: \"t' \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by (auto simp add: valid_def)\n    with t' have \"t'=t\"\n      by auto\n    with * show ?thesis\n      by simp\n  qed\nqed\n\n\nsubsection \\<open>The Hoare Rules: \\<open>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\\<close>\\<close>\n\nlemma mono_WeakenContext: \"A \\<subseteq> B \\<Longrightarrow>\n        (\\<lambda>(P, c, Q, A'). (\\<Gamma>, \\<Theta>, F, P, c, Q, A') \\<in> A) x \\<longrightarrow>\n        (\\<lambda>(P, c, Q, A'). (\\<Gamma>, \\<Theta>, F, P, c, Q, A') \\<in> B) x\"\napply blast\ndone\n\n\ninductive \"hoarep\"::\"[('s,'p,'f) body,('s,'p) quadruple set,'f set,\n    's assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n    (\"(3_,_/\\<turnstile>\\<^bsub>'/_ \\<^esub>(_/ (_)/ _,/_))\" [60,60,60,1000,20,1000,1000]60)\n  for \\<Gamma>::\"('s,'p,'f) body\"\nwhere\n  Skip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> Q Skip Q,A\"\n\n| Basic: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. f s \\<in> Q} (Basic f) Q,A\"\n\n| Spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. (\\<forall>t. (s,t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s,t) \\<in> r)} (Spec r) Q,A\"\n\n| Seq: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>1 R,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk>\n        \\<Longrightarrow>\n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Seq c\\<^sub>1 c\\<^sub>2) Q,A\"\n  \n| Cond: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> b) c\\<^sub>1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> - b) c\\<^sub>2 Q,A\\<rbrakk>\n         \\<Longrightarrow> \n         \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) Q,A\"\n\n| While: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> b) c P,A\n          \\<Longrightarrow>\n          \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (While b c) (P \\<inter> - b),A\"\n\n| Guard: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\n          \\<Longrightarrow>\n          \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (g \\<inter> P) (Guard f g c) Q,A\"\n\n| Guarantee: \"\\<lbrakk>f \\<in> F; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\n\n| CallRec:\n  \"\\<lbrakk>(P,p,Q,A) \\<in> Specs;  \n    \\<forall>(P,p,Q,A) \\<in> Specs. p \\<in> dom \\<Gamma> \\<and> \\<Gamma>,\\<Theta>\\<union>Specs\\<turnstile>\\<^bsub>/F\\<^esub> P (the (\\<Gamma> p)) Q,A \\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n\n| DynCom:\n      \"\\<forall>s \\<in> P. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (c s) Q,A \n      \\<Longrightarrow> \n      \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (DynCom c) Q,A\"\n\n| Throw: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> A Throw Q,A\"\n\n| Catch: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk> \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Catch c\\<^sub>1 c\\<^sub>2 Q,A\"\n\n| Conseq: \"\\<forall>s \\<in> P. \\<exists>P' Q' A'. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' c Q',A' \\<and> s \\<in> P' \\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A \n           \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n\n\n| Asm: \"\\<lbrakk>(P,p,Q,A) \\<in> \\<Theta>\\<rbrakk>\n         \\<Longrightarrow> \n         \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n\n\n| ExFalso: \"\\<lbrakk>\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A; \\<not> \\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  \\<comment> \\<open>This is a hack rule that enables us to derive completeness for\n        an arbitrary context \\<open>\\<Theta>\\<close>, from completeness for an empty context.\\<close>  \n\n\n\ntext \\<open>Does not work, because of rule ExFalso, the context \\<open>\\<Theta>\\<close> is to blame.\n A weaker version with empty context can be derived from soundness \n and completeness later on.\\<close>\nlemma hoare_strip_\\<Gamma>: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P p Q,A\"\n  shows \"strip (-F) \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P p Q,A\"\nusing deriv \nproof induct\n  case Skip thus ?case by (iprover intro: hoarep.Skip)\nnext\n  case Basic thus ?case by (iprover intro: hoarep.Basic)\nnext\n  case Spec thus ?case by (iprover intro: hoarep.Spec)\nnext\n  case Seq thus ?case by (iprover intro: hoarep.Seq)\nnext\n  case Cond thus ?case by (iprover intro: hoarep.Cond)\nnext\n  case While thus ?case by (iprover intro: hoarep.While)\nnext\n  case Guard thus ?case by (iprover intro: hoarep.Guard)\n(*next\n  case CallSpec thus ?case by (iprover intro: hoarep.CallSpec)\nnext\n  case (CallRec A Abr Abr' Init P Post Pre Procs Q R Result Return Z \\<Gamma> \\<Theta> init p\n         result return )\n  from CallRec.hyps\n  have \"\\<forall>p\\<in>Procs. \\<forall>Z. (strip \\<Gamma>),\\<Theta> \\<union>\n             (\\<Union>\\<^bsub>p\\<in>Procs\\<^esub>\n                 \\<Union>\\<^bsub>Z\\<^esub> {(Pre p Z, Call (Init p) p (Return p) (Result p),\n                      Post p Z, Abr p Z)})\\<turnstile>\n            (Pre p Z) (the (\\<Gamma> p)) (R p Z),(Abr' p Z)\" by blast\n  hence \"\\<forall>p\\<in>Procs. \\<forall>Z. (strip \\<Gamma>),\\<Theta> \\<union>\n             (\\<Union>\\<^bsub>p\\<in>Procs\\<^esub>\n                 \\<Union>\\<^bsub>Z\\<^esub> {(Pre p Z, Call (Init p) p (Return p) (Result p),\n                      Post p Z, Abr p Z)})\\<turnstile>\n            (Pre p Z) (the ((strip \\<Gamma>) p)) (R p Z),(Abr' p Z)\"\n    by (auto intro: hoarep.StripI)\n  then show ?case\n    apply - \n    apply (rule hoarep.CallRec)\n    apply (assumption | simp only:dom_strip)+\n    done*)\nnext\n  case DynCom \n  thus ?case\n    by - (rule hoarep.DynCom,best  elim!: ballE exE)\nnext\n  case Throw thus ?case by (iprover intro: hoarep.Throw)\nnext\n  case Catch thus ?case by (iprover intro: hoarep.Catch)\n(*next \n  case CONSEQ thus ?case apply (auto intro: hoarep.CONSEQ)*)\nnext\n  case Asm thus ?case by (iprover intro: hoarep.Asm)\nnext\n  case ExFalso\n  thus ?case\n    oops\n\nlemma hoare_augment_context: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P p Q,A\"\n  shows \"\\<And>\\<Theta>'. \\<Theta> \\<subseteq> \\<Theta>' \\<Longrightarrow> \\<Gamma>,\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> P p Q,A\"\nusing deriv\nproof (induct)\n  case CallRec\n  case (CallRec P p Q A Specs \\<Theta> F \\<Theta>')\n  from CallRec.prems\n  have \"\\<Theta>\\<union>Specs\n       \\<subseteq> \\<Theta>'\\<union>Specs\"\n    by blast\n  with CallRec.hyps (2) \n  have \"\\<forall>(P,p,Q,A)\\<in>Specs.  p \\<in> dom \\<Gamma> \\<and> \\<Gamma>,\\<Theta>'\\<union>Specs \\<turnstile>\\<^bsub>/F\\<^esub> P  (the (\\<Gamma> p)) Q,A\"\n    by fastforce\n\n  with CallRec show ?case by - (rule hoarep.CallRec)\nnext\n  case DynCom thus ?case by (blast intro: hoarep.DynCom)\nnext\n  case (Conseq P \\<Theta> F c Q A \\<Theta>')\n  from Conseq\n  have \"\\<forall>s \\<in> P. \n         (\\<exists>P' Q' A'. \\<Gamma>,\\<Theta>' \\<turnstile>\\<^bsub>/F\\<^esub> P' c Q',A' \\<and> s \\<in> P' \\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A)\"\n    by blast\n  with Conseq show ?case by - (rule hoarep.Conseq)\nnext\n  case (ExFalso \\<Theta> F P c Q A \\<Theta>')\n  have valid_ctxt: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\" \"\\<Theta> \\<subseteq> \\<Theta>'\" by fact+\n  hence \"\\<forall>n. \\<Gamma>,\\<Theta>'\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (simp add: cnvalid_def) blast\n  moreover have invalid: \"\\<not> \\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"  by fact\n  ultimately show ?case\n    by (rule hoarep.ExFalso)\nqed (blast intro: hoarep.intros)+\n\n\nsubsection \\<open>Some Derived Rules\\<close>\n\nlemma  Conseq': \"\\<forall>s. s \\<in> P \\<longrightarrow> \n            (\\<exists>P' Q' A'. \n              (\\<forall> Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z)) \\<and>\n                    (\\<exists>Z. s \\<in> P' Z \\<and> (Q' Z \\<subseteq> Q) \\<and> (A' Z \\<subseteq> A)))\n           \\<Longrightarrow>\n           \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\napply (rule Conseq)\napply (rule ballI)\napply (erule_tac x=s in allE)\napply (clarify)\napply (rule_tac x=\"P' Z\" in exI)\napply (rule_tac x=\"Q' Z\" in exI)\napply (rule_tac x=\"A' Z\" in exI)\napply blast\ndone\n\nlemma conseq:\"\\<lbrakk>\\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z);\n              \\<forall>s. s \\<in> P \\<longrightarrow> (\\<exists> Z. s\\<in>P' Z \\<and> (Q' Z \\<subseteq> Q) \\<and> (A' Z \\<subseteq> A))\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule Conseq) blast\n\ntheorem conseqPrePost [trans]: \n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' c Q',A' \\<Longrightarrow> P \\<subseteq> P' \\<Longrightarrow>  Q' \\<subseteq> Q \\<Longrightarrow> A' \\<subseteq> A \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule conseq [where ?P'=\"\\<lambda>Z. P'\" and ?Q'=\"\\<lambda>Z. Q'\"]) auto\n\nlemma conseqPre [trans]: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' c Q,A \\<Longrightarrow> P \\<subseteq> P' \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\nby (rule conseq) auto\n\nlemma conseqPost [trans]: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q',A' \\<Longrightarrow> Q' \\<subseteq> Q \\<Longrightarrow> A' \\<subseteq> A \n \\<Longrightarrow>   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule conseq) auto\n\n\nlemma CallRec': \n  \"\\<lbrakk>p\\<in>Procs; Procs \\<subseteq> dom \\<Gamma>;\n   \\<forall>p\\<in>Procs. \n    \\<forall>Z. \\<Gamma>,\\<Theta> \\<union> (\\<Union>p\\<in>Procs. \\<Union>Z. {((P p Z),p,Q p Z,A p Z)})\n        \\<turnstile>\\<^bsub>/F\\<^esub> (P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\\<rbrakk>\n   \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P p Z) (Call p) (Q p Z),(A p Z)\"\napply (rule CallRec [where Specs=\"\\<Union>p\\<in>Procs. \\<Union>Z. {((P p Z),p,Q p Z,A p Z)}\"])\napply  blast\napply blast\ndone\n\nend \n", "meta": {"author": "LVPGroup", "repo": "TimSort", "sha": "16437b6b6e2df9f6d32b2a32be7d0d650d83f980", "save_path": "github-repos/isabelle/LVPGroup-TimSort", "path": "github-repos/isabelle/LVPGroup-TimSort/TimSort-16437b6b6e2df9f6d32b2a32be7d0d650d83f980/Simpl/HoarePartialDef.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5813030906443134, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.2861104844729612}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |               December 2004               |\n            |                 August 2005  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |                October 2005  (modified)   |\n            |                  April 2006  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2009-2       |\n            |                October 2010  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2016         |\n            |                    May 2016  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory Domain_F_cpo\nimports Domain_F Domain_T_cpo Set_F_cpo CPO_pair CSP_T_continuous\nbegin\n\n(*****************************************************************\n\n         1. \n         2. \n         3. \n         4. \n\n *****************************************************************)\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite UnionT and InterT.                 *)\n(*                  Union (B ` A) = (UN x:A. B x)                      *)\n(*                  Inter (B ` A) = (INT x:A. B x)                     *)\n(*\ndeclare Union_image_eq [simp del]\ndeclare Inter_image_eq [simp del]\n*)\ndeclare Sup_image_eq [simp del]\ndeclare Inf_image_eq [simp del]\n(*********************************************************\n                      Bottom in Dom_F\n *********************************************************)\n(*\ninstance domF :: (type) bot0\nby (intro_classes)\n*)\n\n\ninstantiation domF :: (type) bot0\nbegin\ndefinition\n  bottom_domF_def : \"Bot == ({<>}t ,, {}f)\"\ninstance ..\nend\n\n(*\ndefs (overloaded)\n  bottom_domF_def : \"Bot == ({<>}t ,, {}f)\"\n*)\n\nlemma bottom_domF: \"Bot <= (F::'a domF)\"\napply (simp add: bottom_domF_def pairF_def)\napply (simp add: subdomF_def Abs_domF_inverse)\ndone\n\ninstance domF :: (type) bot\napply (intro_classes)\nby (simp add: bottom_domF)\n\n(*** fstF and sndF ***)\n\nlemma fstF_bottom_domF[simp]: \"(fstF o Bot) = Bot\"\napply (simp add: prod_Bot_def)\napply (simp add: bottom_domF_def)\napply (simp add: bottom_domT_def)\napply (simp add: comp_def pairF)\ndone\n\nlemma sndF_bottom_domF[simp]: \"(sndF o Bot) = Bot\"\napply (simp add: prod_Bot_def)\napply (simp add: bottom_domF_def)\napply (simp add: bottom_setF_def)\napply (simp add: comp_def pairF)\ndone\n\n(********************************************************** \n      lemmas used in a proof that domain_F is a cpo.\n **********************************************************)\n\n(* LUB_TF TFs is an upper bound of TFs *)\n\ndefinition\n  LUB_TF :: \"'a domTsetF set => 'a domTsetF\"\n  where\n  LUB_TF_def : \"LUB_TF TFs == (UnionT (fst ` TFs), UnionF (snd ` TFs))\"\n  \ndefinition  \n  LUB_domF :: \"'a domF set => 'a domF\"\n  where\n  LUB_domF_def : \"LUB_domF Fs == Abs_domF (LUB_TF (Rep_domF ` Fs))\"\n\n(************* LUB_TF *************)\n\n(*** LUB_TF --> LUB ***)\n\nlemma LUB_TF_isLUB:\n  \"TFs ~= {} ==> LUB_TF TFs isLUB TFs\"\napply (simp add: pair_LUB_decompo)\napply (simp add: LUB_TF_def)\napply (simp add: isLUB_UnionT isLUB_UnionF)\ndone\n\n(*** LUB --> LUB_TF ***)\n\nlemma isLUB_LUB_TF_only_if:\n  \"[| TFs ~= {} ; TF isLUB TFs |] ==> TF = LUB_TF TFs\"\napply (insert LUB_TF_isLUB[of TFs])\nby (simp add: LUB_unique)\n\n(* iff *)\n\nlemma isLUB_LUB_TF : \"TFs ~= {} ==> TF isLUB TFs = (TF = LUB_TF TFs)\"\napply (rule iffI)\napply (simp add: isLUB_LUB_TF_only_if)\napply (simp add: LUB_TF_isLUB)\ndone\n\n(*** LUB TF = LUB_TF ***)\n\nlemma LUB_LUB_TF:\n  \"TFs ~= {} ==> LUB TFs = LUB_TF TFs\"\nby (simp add: isLUB_LUB LUB_TF_isLUB)\n\n(****** LUB_TF TFs in domF ******)\n\n(* T3_F4 *)\n\nlemma LUB_TF_in_T3_F4: \n  \"[| TFs ~= {} ; ALL TF:TFs. TF:domF |] ==> HC_T3_F4 (LUB_TF TFs)\"\napply (simp add: LUB_TF_def HC_T3_F4_def)\napply (intro allI impI)\napply (elim bexE conjE)\napply (drule_tac x=\"x\" in bspec, simp)\n\napply (simp add: domF_iff HC_T3_F4_def)\nby (auto)\n\n(* F3 *)\n\nlemma LUB_TF_in_F3: \n  \"[| TFs ~= {} ; ALL TF:TFs. TF:domF |] ==> HC_F3 (LUB_TF TFs)\"\napply (simp add: LUB_TF_def HC_F3_def)\napply (intro allI impI)\n\napply (elim bexE conjE)\napply (drule_tac x=\"x\" in bspec, simp)\n\napply (simp add: domF_def HC_F3_def)\napply (elim conjE)\napply (drule_tac x=\"s\" in spec)\napply (drule_tac x=\"X\" in spec)\napply (drule_tac x=\"Y\" in spec)\nby (auto)\n\n(* T2 *)\n\nlemma LUB_TF_in_T2: \n  \"[| TFs ~= {} ; ALL TF:TFs. TF:domF |] ==> HC_T2 (LUB_TF TFs)\"\napply (simp add: LUB_TF_def HC_T2_def)\napply (intro allI impI)\n\napply (elim exE bexE)\napply (drule_tac x=\"x\" in bspec, simp)\n\napply (simp add: domF_def HC_T2_def)\napply (elim conjE)\napply (drule_tac x=\"s\" in spec)\nby (auto)\n\n(*** LUB_TF TFs in domF ***)\n\nlemma LUB_TF_in: \n  \"[| TFs ~= {} ; ALL TF:TFs. TF:domF |] ==> (LUB_TF TFs): domF\"\napply (simp (no_asm) add: domF_iff)\napply (simp add: LUB_TF_in_T2)\napply (simp add: LUB_TF_in_F3)\napply (simp add: LUB_TF_in_T3_F4)\ndone\n\nlemma LUB_TF_in_Rep: \n  \"Fs ~= {} ==> (LUB_TF (Rep_domF ` Fs)): domF\"\napply (rule LUB_TF_in)\napply (auto)\ndone\n\n(************* LUB_domF *************)\n\n(* isLUB lemma *)\n\nlemma TF_isLUB_domFs:\n  \"[| TF:domF ; TF isLUB Rep_domF ` Fs |] ==> Abs_domF TF isLUB Fs\"\napply (simp add: isUB_def isLUB_def)\napply (rule conjI)\n\n(* ub *)\napply (intro allI impI)\napply (elim bexE conjE)\napply (drule_tac x=\"fst (Rep_domF y)\" in spec)\napply (drule_tac x=\"snd (Rep_domF y)\" in spec)\napply (simp add: subdomF_def Abs_domF_inverse)\n\n(* lub *)\napply (intro allI impI)\napply (elim bexE conjE)\napply (rotate_tac -1)\napply (drule_tac x=\"fst (Rep_domF y)\" in spec)\napply (rotate_tac -1)\napply (drule_tac x=\"snd (Rep_domF y)\" in spec)\napply (simp)\napply (drule mp)\n apply (intro allI impI)\n apply (simp add: image_def)\n apply (elim bexE conjE)\n apply (drule_tac x=\"x\" in spec)\n apply (simp)\n apply (simp add: subdomF_def)\napply (simp add: subdomF_def Abs_domF_inverse)\ndone\n\n(*** LUB_domF --> LUB ***)\n\nlemma LUB_domF_isLUB:\n  \"Fs ~= {} ==> LUB_domF Fs isLUB Fs\"\napply (simp add: LUB_domF_def)\napply (rule TF_isLUB_domFs)\napply (simp add: LUB_TF_in)\napply (simp add: LUB_TF_isLUB)\ndone\n\nlemma LUB_domF_isLUB_I:\n  \"[| Fs ~= {} ; F = LUB_domF Fs |] ==> F isLUB Fs\"\nby (simp add: LUB_domF_isLUB)\n\n(*** LUB --> LUB_domF ***)\n\nlemma isLUB_LUB_domF_only_if:\n  \"[| Fs ~= {} ; F isLUB Fs |] ==> F = LUB_domF Fs\"\napply (insert LUB_domF_isLUB[of Fs])\nby (simp add: LUB_unique)\n\n(* iff *)\n\nlemma isLUB_LUB_domF : \"Fs ~= {} ==> F isLUB Fs = (F = LUB_domF Fs)\"\napply (rule iffI)\napply (simp add: isLUB_LUB_domF_only_if)\napply (simp add: LUB_domF_isLUB)\ndone\n\n(********************************************************** \n                ( domF, <= ) is a CPO\n **********************************************************)\n\ninstance domF :: (type) cpo\napply (intro_classes)\napply (simp add: hasLUB_def)\napply (rule_tac x=\"LUB_domF X\" in exI)\nby (simp add: directed_def LUB_domF_isLUB)\n\n(********************************************************** \n             ( domF, <= ) is a pointed CPO\n **********************************************************)\n\ninstance domF :: (type) cpo_bot\nby (intro_classes)\n\n(********************************************************** \n                 continuity of Abs_domF\n **********************************************************)\n\n(*** Abs_domF ***)\n\nlemma continuous_Abs_domF:\n \"[| ALL x. f x: domF ; continuous f |] ==> continuous (Abs_domF o f)\"\napply (simp add: continuous_iff)\napply (intro allI impI)\napply (drule_tac x=\"X\" in spec, simp)\napply (elim conjE exE)\napply (rule_tac x=\"x\" in exI, simp)\napply (rule TF_isLUB_domFs)\napply (simp)\n\napply (subgoal_tac \"Rep_domF ` (Abs_domF o f) ` X = f ` X\")\nby (auto simp add: image_def Abs_domF_inverse)\n\n(*** Rep_domF ***)\n\nlemma cont_Rep_domF: \"continuous Rep_domF\"\napply (simp add: continuous_iff)\napply (intro allI impI)\napply (rule_tac x=\"LUB_domF X\" in exI)\n\napply (simp add: directed_def LUB_domF_isLUB)\napply (simp add: isLUB_LUB_TF)\napply (simp add: LUB_domF_def)\napply (simp add: LUB_TF_in Abs_domF_inverse)\ndone\n\n(*** fstF and sndF ***)\n\nlemma fstF_continuous: \"continuous fstF\"\napply (simp add: fstF_def)\napply (rule compo_continuous)\napply (simp add: cont_Rep_domF)\napply (simp add: fst_continuous)\ndone\n\nlemma sndF_continuous: \"continuous sndF\"\napply (simp add: sndF_def)\napply (rule compo_continuous)\napply (simp add: cont_Rep_domF)\napply (simp add: snd_continuous)\ndone\n\n(********************************************************** \n                continuity decomposition\n **********************************************************)\n\n(*** if ***)\n\nlemma continuous_domF:\n \"[| ALL x. (f x, g x): domF ; continuous f ; continuous g |]\n  ==> continuous (%x. (f x ,, g x))\"\napply (simp add: pairF_def)\napply (subgoal_tac \"(%x. Abs_domF (f x, g x)) = Abs_domF o (%x. (f x, g x))\")\napply (simp)\napply (rule continuous_Abs_domF)\napply (simp)\napply (simp add: pair_continuous)\napply (simp add: comp_def)\napply (simp add: fun_eq_iff)\ndone\n\nlemmas continuous_domF_decompo_if = continuous_domF\n\n(*** only if ***)\n\nlemma continuous_domF_decompo_only_if_lm:\n  \"[| ALL x. (f x, g x) : domF; continuous (%x. (f x , g x)) |]\n       ==> continuous f & continuous g\"\napply (simp add: pair_continuous)\napply (simp add: comp_def)\ndone\n\nlemma continuous_domF_decompo_only_if:\n  \"[| ALL x. (f x, g x) : domF; continuous (%x. (f x ,, g x)) |]\n   ==> continuous f & continuous g\"\napply (rule continuous_domF_decompo_only_if_lm)\napply (simp)\napply (simp add: pairF_def)\napply (insert compo_continuous\n       [of \"(%x. Abs_domF (f x, g x))\" \"Rep_domF\" ])\napply (simp add: comp_def)\napply (simp add: cont_Rep_domF)\napply (simp add: Abs_domF_inverse)\ndone\n\nlemma continuous_domF_decompo:\n  \"ALL x. (f x, g x) : domF\n   ==> continuous (%x. (f x ,, g x)) = (continuous f & continuous g)\"\napply (rule)\napply (simp add: continuous_domF_decompo_only_if)\napply (simp add: continuous_domF_decompo_if)\ndone\n\n(********************************************************** \n                continuity of (op o fstF)\n **********************************************************)\n\nlemma continuous_op_fstF: \"continuous (op o fstF)\"\napply (simp add: continuous_iff)\napply (intro allI impI)\napply (insert complete_cpo_lm)\napply (drule_tac x=\"X\" in spec)\napply (simp add: hasLUB_def)\n\napply (elim exE)\napply (rule_tac x=\"x\" in exI)\napply (simp)\napply (simp add: image_def)\napply (simp add: isLUB_def)\napply (simp add: isUB_def)\napply (rule)\n\n (* UB *)\n apply (intro allI impI)\n apply (elim conjE bexE) \n apply (simp)\n apply (drule_tac x=\"xa\" in spec)\n apply (simp add: order_prod_def)\n apply (simp add: mono_fstF[simplified mono_def])\n\n (* LUB *)\n apply (intro allI impI)\n apply (elim conjE)\n\n apply (rotate_tac -1)\n apply (drule_tac x=\"(%pn. (y pn ,, maxFof (y pn)))\" in spec)\n apply (drule mp)\n\n  apply (intro allI impI)\n  apply (drule_tac x=\"fstF o ya\" in spec)\n  apply (drule mp, fast)\n  apply (simp add: order_prod_def)\n  apply (intro allI impI)\n  apply (drule_tac x=\"xa\" in spec)\n  apply (simp add: subdomF_decompo)\n  apply (simp add: pairF maxFof_domF)\n  apply (rule)\n  apply (simp add: subdomT_iff)\n  apply (drule_tac x=\"s\" in spec)\n  apply (simp add: pairF_domF_T2)\n  apply (simp add: maxFof_max)\n\n apply (simp add: order_prod_def)\n apply (simp add: subdomF_decompo)\n apply (simp add: pairF maxFof_domF)\ndone\n\n(********************************************************** \n              fstF-distribution over LUB\n **********************************************************)\n\nlemma dist_fstF_LUB:\n  \"X ~= {} ==> fstF o LUB X = LUB ((op o fstF) ` X)\"\napply (subgoal_tac \"X hasLUB\")\napply (rule sym)\napply (rule isLUB_LUB)\napply (simp add: isLUB_def isUB_def)\napply (rule)\n\n(* UB *)\n apply (intro allI impI)\n apply (simp add: image_iff)\n apply (simp add: comp_def)\n apply (elim bexE)\n apply (simp add: order_prod_def)\n apply (intro allI)\n apply (subgoal_tac \"x <= LUB X\")\n\n  apply (simp add: order_prod_def)\n  apply (simp add: mono_fstF[simplified mono_def])\n  apply (subgoal_tac \"LUB X isLUB X\")\n  apply (simp add: isLUB_def isUB_def)\n  apply (simp add: LUB_is)\n\n(* LUB *)\n apply (intro allI impI)\n apply (simp add: order_prod_def)\n apply (intro allI impI)\n apply (subgoal_tac \"(LUB X) isLUB X\")\n\n  apply (simp add: prod_LUB_decompo)\n  apply (simp add: proj_fun_def)\n  apply (drule_tac x=\"x\" in spec)\n  apply (subgoal_tac \"(%xa. xa x) ` X ~= {}\")\n\n   apply (simp add: isLUB_LUB_domF)\n   apply (simp add: LUB_domF_def)\n   apply (simp add: fstF_def)\n   apply (simp add: LUB_TF_in_Rep Abs_domF_inverse)\n   apply (simp add: LUB_TF_def)\n   apply (rule subdomTI)\n   apply (simp)\n   apply (elim conjE bexE)\n   apply (drule_tac x=\"fstF o xa\" in spec)\n   apply (drule mp)\n    apply (simp add: image_iff)\n    apply (rule_tac x=\"xa\" in bexI)\n    apply (simp add: fstF_def)\n    apply (simp)\n   apply (drule_tac x=\"x\" in spec)\n   apply (simp add: subdomT_iff)\n   apply (drule_tac x=\"t\" in spec)\n   apply (simp add: fstF_def)\n\n  apply (force)\n apply (rule LUB_is)\n apply (simp)\n\napply (simp add: hasLUB_def)\napply (simp add: prod_LUB_decompo)\napply (simp add: proj_fun_def)\napply (rule_tac x=\"(%i. LUB_domF ((%x. x i) ` X))\" in exI)\napply (simp add: isLUB_LUB_domF)\ndone\n\n(****************** to add them again ******************)\n(*\ndeclare Union_image_eq [simp]\ndeclare Inter_image_eq [simp]\n*)\ndeclare Sup_image_eq [simp]\ndeclare Inf_image_eq [simp]\nend\n", "meta": {"author": "pefribeiro", "repo": "CSP-Prover", "sha": "8967cc482e5695fca4abb52d9dc2cf36b7b7a44e", "save_path": "github-repos/isabelle/pefribeiro-CSP-Prover", "path": "github-repos/isabelle/pefribeiro-CSP-Prover/CSP-Prover-8967cc482e5695fca4abb52d9dc2cf36b7b7a44e/CSP_F/Domain_F_cpo.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5813030761371503, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.28611047733270767}}
{"text": "section\\<open>Interface between set models and Constructibility\\<close>\n\ntext\\<open>This theory provides an interface between Paulson's\nrelativization results and set models of ZFC. In particular,\nit is used to prove that the locale \\<^term>\\<open>forcing_data\\<close> is\na sublocale of all relevant locales in ZF-Constructibility\n(\\<^term>\\<open>M_trivial\\<close>, \\<^term>\\<open>M_basic\\<close>, \\<^term>\\<open>M_eclose\\<close>, etc).\\<close>\n\ntheory Interface\n  imports\n    Nat_Miscellanea\n    Relative_Univ\n    Synthetic_Definition\nbegin\n\nsyntax\n  \"_sats\"  :: \"[i, i, i] \\<Rightarrow> o\"  (\"(_, _ \\<Turnstile> _)\" [36,36,36] 60)\ntranslations\n  \"(M,env \\<Turnstile> \\<phi>)\" \\<rightleftharpoons> \"CONST sats(M,\\<phi>,env)\"\n\nabbreviation\n  dec10  :: i   (\"10\") where \"10 \\<equiv> succ(9)\"\n\nabbreviation\n  dec11  :: i   (\"11\") where \"11 \\<equiv> succ(10)\"\n\nabbreviation\n  dec12  :: i   (\"12\") where \"12 \\<equiv> succ(11)\"\n\nabbreviation\n  dec13  :: i   (\"13\") where \"13 \\<equiv> succ(12)\"\n\nabbreviation\n  dec14  :: i   (\"14\") where \"14 \\<equiv> succ(13)\"\n\n\ndefinition\n  infinity_ax :: \"(i \\<Rightarrow> o) \\<Rightarrow> o\" where\n  \"infinity_ax(M) \\<equiv>\n      (\\<exists>I[M]. (\\<exists>z[M]. empty(M,z) \\<and> z\\<in>I) \\<and> (\\<forall>y[M]. y\\<in>I \\<longrightarrow> (\\<exists>sy[M]. successor(M,y,sy) \\<and> sy\\<in>I)))\"\n\ndefinition\n  choice_ax :: \"(i\\<Rightarrow>o) \\<Rightarrow> o\" where\n  \"choice_ax(M) \\<equiv> \\<forall>x[M]. \\<exists>a[M]. \\<exists>f[M]. ordinal(M,a) \\<and> surjection(M,a,x,f)\"\n\ncontext M_basic begin\n\nlemma choice_ax_abs :\n  \"choice_ax(M) \\<longleftrightarrow> (\\<forall>x[M]. \\<exists>a[M]. \\<exists>f[M]. Ord(a) \\<and> f \\<in> surj(a,x))\"\n  unfolding choice_ax_def\n  by (simp)\n\nend (* M_basic *)\n\ndefinition\n  wellfounded_trancl :: \"[i=>o,i,i,i] => o\" where\n  \"wellfounded_trancl(M,Z,r,p) \\<equiv>\n      \\<exists>w[M]. \\<exists>wx[M]. \\<exists>rp[M].\n               w \\<in> Z & pair(M,w,p,wx) & tran_closure(M,r,rp) & wx \\<in> rp\"\n\nlemma empty_intf :\n  \"infinity_ax(M) \\<Longrightarrow>\n  (\\<exists>z[M]. empty(M,z))\"\n  by (auto simp add: empty_def infinity_ax_def)\n\nlemma Transset_intf :\n  \"Transset(M) \\<Longrightarrow>  y\\<in>x \\<Longrightarrow> x \\<in> M \\<Longrightarrow> y \\<in> M\"\n  by (simp add: Transset_def,auto)\n\nlocale M_ZF_trans =\n  fixes M\n  assumes\n    upair_ax:         \"upair_ax(##M)\"\n    and Union_ax:         \"Union_ax(##M)\"\n    and power_ax:         \"power_ax(##M)\"\n    and extensionality:   \"extensionality(##M)\"\n    and foundation_ax:    \"foundation_ax(##M)\"\n    and infinity_ax:      \"infinity_ax(##M)\"\n    and separation_ax:    \"\\<phi>\\<in>formula \\<Longrightarrow> env\\<in>list(M) \\<Longrightarrow> arity(\\<phi>) \\<le> 1 #+ length(env) \\<Longrightarrow>\n                    separation(##M,\\<lambda>x. sats(M,\\<phi>,[x] @ env))\"\n    and replacement_ax:   \"\\<phi>\\<in>formula \\<Longrightarrow> env\\<in>list(M) \\<Longrightarrow> arity(\\<phi>) \\<le> 2 #+ length(env) \\<Longrightarrow>\n                    strong_replacement(##M,\\<lambda>x y. sats(M,\\<phi>,[x,y] @ env))\"\n    and trans_M:          \"Transset(M)\"\nbegin\n\n\nlemma TranssetI :\n  \"(\\<And>y x. y\\<in>x \\<Longrightarrow> x\\<in>M \\<Longrightarrow> y\\<in>M) \\<Longrightarrow> Transset(M)\"\n  by (auto simp add: Transset_def)\n\nlemma zero_in_M:  \"0 \\<in> M\"\nproof -\n  from infinity_ax have\n    \"(\\<exists>z[##M]. empty(##M,z))\"\n    by (rule empty_intf)\n  then obtain z where\n    zm: \"empty(##M,z)\"  \"z\\<in>M\"\n    by auto\n  with trans_M have \"z=0\"\n    by (simp  add: empty_def, blast intro: Transset_intf )\n  with zm show ?thesis\n    by simp\nqed\n\nsubsection\\<open>Interface with \\<^term>\\<open>M_trivial\\<close>\\<close>\nlemma mtrans :\n  \"M_trans(##M)\"\n  using Transset_intf[OF trans_M] zero_in_M exI[of \"\\<lambda>x. x\\<in>M\"]\n  by unfold_locales auto\n\n\nlemma mtriv :\n  \"M_trivial(##M)\"\n  using trans_M M_trivial.intro mtrans M_trivial_axioms.intro upair_ax Union_ax\n  by simp\n\nend\n\nsublocale M_ZF_trans \\<subseteq> M_trivial \"##M\"\n  by (rule mtriv)\n\ncontext M_ZF_trans\nbegin\n\nsubsection\\<open>Interface with \\<^term>\\<open>M_basic\\<close>\\<close>\n\n(* Inter_separation: \"M(A) \\<Longrightarrow> separation(M, \\<lambda>x. \\<forall> y[M]. y\\<in>A \\<Longrightarrow> x\\<in>y)\" *)\nschematic_goal inter_fm_auto:\n  assumes\n    \"nth(i,env) = x\" \"nth(j,env) = B\"\n    \"i \\<in> nat\" \"j \\<in> nat\" \"env \\<in> list(A)\"\n  shows\n    \"(\\<forall>y\\<in>A . y\\<in>B \\<longrightarrow> x\\<in>y) \\<longleftrightarrow> sats(A,?ifm(i,j),env)\"\n  by (insert assms ; (rule sep_rules | simp)+)\n\nlemma inter_sep_intf :\n  assumes\n    \"A\\<in>M\"\n  shows\n    \"separation(##M,\\<lambda>x . \\<forall>y\\<in>M . y\\<in>A \\<longrightarrow> x\\<in>y)\"\nproof -\n  obtain ifm where\n    fmsats:\"\\<And>env. env\\<in>list(M) \\<Longrightarrow> (\\<forall> y\\<in>M. y\\<in>(nth(1,env)) \\<longrightarrow> nth(0,env)\\<in>y)\n    \\<longleftrightarrow> sats(M,ifm(0,1),env)\"\n    and\n    \"ifm(0,1) \\<in> formula\"\n    and\n    \"arity(ifm(0,1)) = 2\"\n    using \\<open>A\\<in>M\\<close> inter_fm_auto\n    by (simp del:FOL_sats_iff add: nat_simp_union)\n  then\n  have \"\\<forall>a\\<in>M. separation(##M, \\<lambda>x. sats(M,ifm(0,1) , [x, a]))\"\n    using separation_ax by simp\n  moreover\n  have \"(\\<forall>y\\<in>M . y\\<in>a \\<longrightarrow> x\\<in>y) \\<longleftrightarrow> sats(M,ifm(0,1),[x,a])\"\n    if \"a\\<in>M\" \"x\\<in>M\" for a x\n    using that fmsats[of \"[x,a]\"] by simp\n  ultimately\n  have \"\\<forall>a\\<in>M. separation(##M, \\<lambda>x . \\<forall>y\\<in>M . y\\<in>a \\<longrightarrow> x\\<in>y)\"\n    unfolding separation_def by simp\n  with \\<open>A\\<in>M\\<close> show ?thesis by simp\nqed\n\n\n(* Diff_separation: \"M(B) \\<Longrightarrow> separation(M, \\<lambda>x. x \\<notin> B)\" *)\nschematic_goal diff_fm_auto:\n  assumes\n    \"nth(i,env) = x\" \"nth(j,env) = B\"\n    \"i \\<in> nat\" \"j \\<in> nat\" \"env \\<in> list(A)\"\n  shows\n    \"x\\<notin>B \\<longleftrightarrow> sats(A,?dfm(i,j),env)\"\n  by (insert assms ; (rule sep_rules | simp)+)\n\nlemma diff_sep_intf :\n  assumes\n    \"B\\<in>M\"\n  shows\n    \"separation(##M,\\<lambda>x . x\\<notin>B)\"\nproof -\n  obtain dfm where\n    fmsats:\"\\<And>env. env\\<in>list(M) \\<Longrightarrow> nth(0,env)\\<notin>nth(1,env)\n    \\<longleftrightarrow> sats(M,dfm(0,1),env)\"\n    and\n    \"dfm(0,1) \\<in> formula\"\n    and\n    \"arity(dfm(0,1)) = 2\"\n    using \\<open>B\\<in>M\\<close> diff_fm_auto\n    by (simp del:FOL_sats_iff add: nat_simp_union)\n  then\n  have \"\\<forall>b\\<in>M. separation(##M, \\<lambda>x. sats(M,dfm(0,1) , [x, b]))\"\n    using separation_ax by simp\n  moreover\n  have \"x\\<notin>b \\<longleftrightarrow> sats(M,dfm(0,1),[x,b])\"\n    if \"b\\<in>M\" \"x\\<in>M\" for b x\n    using that fmsats[of \"[x,b]\"] by simp\n  ultimately\n  have \"\\<forall>b\\<in>M. separation(##M, \\<lambda>x . x\\<notin>b)\"\n    unfolding separation_def by simp\n  with \\<open>B\\<in>M\\<close> show ?thesis by simp\nqed\n\nschematic_goal cprod_fm_auto:\n  assumes\n    \"nth(i,env) = z\" \"nth(j,env) = B\" \"nth(h,env) = C\"\n    \"i \\<in> nat\" \"j \\<in> nat\" \"h \\<in> nat\" \"env \\<in> list(A)\"\n  shows\n    \"(\\<exists>x\\<in>A. x\\<in>B \\<and> (\\<exists>y\\<in>A. y\\<in>C \\<and> pair(##A,x,y,z))) \\<longleftrightarrow> sats(A,?cpfm(i,j,h),env)\"\n  by (insert assms ; (rule sep_rules | simp)+)\n\n\nlemma cartprod_sep_intf :\n  assumes\n    \"A\\<in>M\"\n    and\n    \"B\\<in>M\"\n  shows\n    \"separation(##M,\\<lambda>z. \\<exists>x\\<in>M. x\\<in>A \\<and> (\\<exists>y\\<in>M. y\\<in>B \\<and> pair(##M,x,y,z)))\"\nproof -\n  obtain cpfm where\n    fmsats:\"\\<And>env. env\\<in>list(M) \\<Longrightarrow>\n    (\\<exists>x\\<in>M. x\\<in>nth(1,env) \\<and> (\\<exists>y\\<in>M. y\\<in>nth(2,env) \\<and> pair(##M,x,y,nth(0,env))))\n    \\<longleftrightarrow> sats(M,cpfm(0,1,2),env)\"\n    and\n    \"cpfm(0,1,2) \\<in> formula\"\n    and\n    \"arity(cpfm(0,1,2)) = 3\"\n    using cprod_fm_auto by (simp del:FOL_sats_iff add: fm_defs nat_simp_union)\n  then\n  have \"\\<forall>a\\<in>M. \\<forall>b\\<in>M. separation(##M, \\<lambda>z. sats(M,cpfm(0,1,2) , [z, a, b]))\"\n    using separation_ax by simp\n  moreover\n  have \"(\\<exists>x\\<in>M. x\\<in>a \\<and> (\\<exists>y\\<in>M. y\\<in>b \\<and> pair(##M,x,y,z))) \\<longleftrightarrow> sats(M,cpfm(0,1,2),[z,a,b])\"\n    if \"a\\<in>M\" \"b\\<in>M\" \"z\\<in>M\" for a b z\n    using that fmsats[of \"[z,a,b]\"] by simp\n  ultimately\n  have \"\\<forall>a\\<in>M. \\<forall>b\\<in>M. separation(##M, \\<lambda>z . (\\<exists>x\\<in>M. x\\<in>a \\<and> (\\<exists>y\\<in>M. y\\<in>b \\<and> pair(##M,x,y,z))))\"\n    unfolding separation_def by simp\n  with \\<open>A\\<in>M\\<close> \\<open>B\\<in>M\\<close> show ?thesis by simp\nqed\n\nschematic_goal im_fm_auto:\n  assumes\n    \"nth(i,env) = y\" \"nth(j,env) = r\" \"nth(h,env) = B\"\n    \"i \\<in> nat\" \"j \\<in> nat\" \"h \\<in> nat\" \"env \\<in> list(A)\"\n  shows\n    \"(\\<exists>p\\<in>A. p\\<in>r & (\\<exists>x\\<in>A. x\\<in>B & pair(##A,x,y,p))) \\<longleftrightarrow> sats(A,?imfm(i,j,h),env)\"\n  by (insert assms ; (rule sep_rules | simp)+)\n\nlemma image_sep_intf :\n  assumes\n    \"A\\<in>M\"\n    and\n    \"r\\<in>M\"\n  shows\n    \"separation(##M, \\<lambda>y. \\<exists>p\\<in>M. p\\<in>r & (\\<exists>x\\<in>M. x\\<in>A & pair(##M,x,y,p)))\"\nproof -\n  obtain imfm where\n    fmsats:\"\\<And>env. env\\<in>list(M) \\<Longrightarrow>\n    (\\<exists>p\\<in>M. p\\<in>nth(1,env) & (\\<exists>x\\<in>M. x\\<in>nth(2,env) & pair(##M,x,nth(0,env),p)))\n    \\<longleftrightarrow> sats(M,imfm(0,1,2),env)\"\n    and\n    \"imfm(0,1,2) \\<in> formula\"\n    and\n    \"arity(imfm(0,1,2)) = 3\"\n    using im_fm_auto by (simp del:FOL_sats_iff pair_abs add: fm_defs nat_simp_union)\n  then\n  have \"\\<forall>r\\<in>M. \\<forall>a\\<in>M. separation(##M, \\<lambda>y. sats(M,imfm(0,1,2) , [y,r,a]))\"\n    using separation_ax by simp\n  moreover\n  have \"(\\<exists>p\\<in>M. p\\<in>k & (\\<exists>x\\<in>M. x\\<in>a & pair(##M,x,y,p))) \\<longleftrightarrow> sats(M,imfm(0,1,2),[y,k,a])\"\n    if \"k\\<in>M\" \"a\\<in>M\" \"y\\<in>M\" for k a y\n    using that fmsats[of \"[y,k,a]\"] by simp\n  ultimately\n  have \"\\<forall>k\\<in>M. \\<forall>a\\<in>M. separation(##M, \\<lambda>y . \\<exists>p\\<in>M. p\\<in>k & (\\<exists>x\\<in>M. x\\<in>a & pair(##M,x,y,p)))\"\n    unfolding separation_def by simp\n  with \\<open>r\\<in>M\\<close> \\<open>A\\<in>M\\<close> show ?thesis by simp\nqed\n\nschematic_goal con_fm_auto:\n  assumes\n    \"nth(i,env) = z\" \"nth(j,env) = R\"\n    \"i \\<in> nat\" \"j \\<in> nat\" \"env \\<in> list(A)\"\n  shows\n    \"(\\<exists>p\\<in>A. p\\<in>R & (\\<exists>x\\<in>A.\\<exists>y\\<in>A. pair(##A,x,y,p) & pair(##A,y,x,z)))\n  \\<longleftrightarrow> sats(A,?cfm(i,j),env)\"\n  by (insert assms ; (rule sep_rules | simp)+)\n\n\nlemma converse_sep_intf :\n  assumes\n    \"R\\<in>M\"\n  shows\n    \"separation(##M,\\<lambda>z. \\<exists>p\\<in>M. p\\<in>R & (\\<exists>x\\<in>M.\\<exists>y\\<in>M. pair(##M,x,y,p) & pair(##M,y,x,z)))\"\nproof -\n  obtain cfm where\n    fmsats:\"\\<And>env. env\\<in>list(M) \\<Longrightarrow>\n    (\\<exists>p\\<in>M. p\\<in>nth(1,env) & (\\<exists>x\\<in>M.\\<exists>y\\<in>M. pair(##M,x,y,p) & pair(##M,y,x,nth(0,env))))\n    \\<longleftrightarrow> sats(M,cfm(0,1),env)\"\n    and\n    \"cfm(0,1) \\<in> formula\"\n    and\n    \"arity(cfm(0,1)) = 2\"\n    using con_fm_auto by (simp del:FOL_sats_iff pair_abs add: fm_defs nat_simp_union)\n  then\n  have \"\\<forall>r\\<in>M. separation(##M, \\<lambda>z. sats(M,cfm(0,1) , [z,r]))\"\n    using separation_ax by simp\n  moreover\n  have \"(\\<exists>p\\<in>M. p\\<in>r & (\\<exists>x\\<in>M.\\<exists>y\\<in>M. pair(##M,x,y,p) & pair(##M,y,x,z))) \\<longleftrightarrow>\n          sats(M,cfm(0,1),[z,r])\"\n    if \"z\\<in>M\" \"r\\<in>M\" for z r\n    using that fmsats[of \"[z,r]\"] by simp\n  ultimately\n  have \"\\<forall>r\\<in>M. separation(##M, \\<lambda>z . \\<exists>p\\<in>M. p\\<in>r & (\\<exists>x\\<in>M.\\<exists>y\\<in>M. pair(##M,x,y,p) & pair(##M,y,x,z)))\"\n    unfolding separation_def by simp\n  with \\<open>R\\<in>M\\<close> show ?thesis by simp\nqed\n\n\nschematic_goal rest_fm_auto:\n  assumes\n    \"nth(i,env) = z\" \"nth(j,env) = C\"\n    \"i \\<in> nat\" \"j \\<in> nat\" \"env \\<in> list(A)\"\n  shows\n    \"(\\<exists>x\\<in>A. x\\<in>C & (\\<exists>y\\<in>A. pair(##A,x,y,z)))\n  \\<longleftrightarrow> sats(A,?rfm(i,j),env)\"\n  by (insert assms ; (rule sep_rules | simp)+)\n\n\nlemma restrict_sep_intf :\n  assumes\n    \"A\\<in>M\"\n  shows\n    \"separation(##M,\\<lambda>z. \\<exists>x\\<in>M. x\\<in>A & (\\<exists>y\\<in>M. pair(##M,x,y,z)))\"\nproof -\n  obtain rfm where\n    fmsats:\"\\<And>env. env\\<in>list(M) \\<Longrightarrow>\n    (\\<exists>x\\<in>M. x\\<in>nth(1,env) & (\\<exists>y\\<in>M. pair(##M,x,y,nth(0,env))))\n    \\<longleftrightarrow> sats(M,rfm(0,1),env)\"\n    and\n    \"rfm(0,1) \\<in> formula\"\n    and\n    \"arity(rfm(0,1)) = 2\"\n    using rest_fm_auto by (simp del:FOL_sats_iff pair_abs add: fm_defs nat_simp_union)\n  then\n  have \"\\<forall>a\\<in>M. separation(##M, \\<lambda>z. sats(M,rfm(0,1) , [z,a]))\"\n    using separation_ax by simp\n  moreover\n  have \"(\\<exists>x\\<in>M. x\\<in>a & (\\<exists>y\\<in>M. pair(##M,x,y,z))) \\<longleftrightarrow>\n          sats(M,rfm(0,1),[z,a])\"\n    if \"z\\<in>M\" \"a\\<in>M\" for z a\n    using that fmsats[of \"[z,a]\"] by simp\n  ultimately\n  have \"\\<forall>a\\<in>M. separation(##M, \\<lambda>z . \\<exists>x\\<in>M. x\\<in>a & (\\<exists>y\\<in>M. pair(##M,x,y,z)))\"\n    unfolding separation_def by simp\n  with \\<open>A\\<in>M\\<close> show ?thesis by simp\nqed\n\nschematic_goal comp_fm_auto:\n  assumes\n    \"nth(i,env) = xz\" \"nth(j,env) = S\" \"nth(h,env) = R\"\n    \"i \\<in> nat\" \"j \\<in> nat\" \"h \\<in> nat\" \"env \\<in> list(A)\"\n  shows\n    \"(\\<exists>x\\<in>A. \\<exists>y\\<in>A. \\<exists>z\\<in>A. \\<exists>xy\\<in>A. \\<exists>yz\\<in>A.\n              pair(##A,x,z,xz) & pair(##A,x,y,xy) & pair(##A,y,z,yz) & xy\\<in>S & yz\\<in>R)\n  \\<longleftrightarrow> sats(A,?cfm(i,j,h),env)\"\n  by (insert assms ; (rule sep_rules | simp)+)\n\n\nlemma comp_sep_intf :\n  assumes\n    \"R\\<in>M\"\n    and\n    \"S\\<in>M\"\n  shows\n    \"separation(##M,\\<lambda>xz. \\<exists>x\\<in>M. \\<exists>y\\<in>M. \\<exists>z\\<in>M. \\<exists>xy\\<in>M. \\<exists>yz\\<in>M.\n              pair(##M,x,z,xz) & pair(##M,x,y,xy) & pair(##M,y,z,yz) & xy\\<in>S & yz\\<in>R)\"\nproof -\n  obtain cfm where\n    fmsats:\"\\<And>env. env\\<in>list(M) \\<Longrightarrow>\n    (\\<exists>x\\<in>M. \\<exists>y\\<in>M. \\<exists>z\\<in>M. \\<exists>xy\\<in>M. \\<exists>yz\\<in>M. pair(##M,x,z,nth(0,env)) &\n            pair(##M,x,y,xy) & pair(##M,y,z,yz) & xy\\<in>nth(1,env) & yz\\<in>nth(2,env))\n    \\<longleftrightarrow> sats(M,cfm(0,1,2),env)\"\n    and\n    \"cfm(0,1,2) \\<in> formula\"\n    and\n    \"arity(cfm(0,1,2)) = 3\"\n    using comp_fm_auto by (simp del:FOL_sats_iff pair_abs add: fm_defs nat_simp_union)\n  then\n  have \"\\<forall>r\\<in>M. \\<forall>s\\<in>M. separation(##M, \\<lambda>y. sats(M,cfm(0,1,2) , [y,s,r]))\"\n    using separation_ax by simp\n  moreover\n  have \"(\\<exists>x\\<in>M. \\<exists>y\\<in>M. \\<exists>z\\<in>M. \\<exists>xy\\<in>M. \\<exists>yz\\<in>M.\n              pair(##M,x,z,xz) & pair(##M,x,y,xy) & pair(##M,y,z,yz) & xy\\<in>s & yz\\<in>r)\n          \\<longleftrightarrow> sats(M,cfm(0,1,2) , [xz,s,r])\"\n    if \"xz\\<in>M\" \"s\\<in>M\" \"r\\<in>M\" for xz s r\n    using that fmsats[of \"[xz,s,r]\"] by simp\n  ultimately\n  have \"\\<forall>s\\<in>M. \\<forall>r\\<in>M. separation(##M, \\<lambda>xz . \\<exists>x\\<in>M. \\<exists>y\\<in>M. \\<exists>z\\<in>M. \\<exists>xy\\<in>M. \\<exists>yz\\<in>M.\n              pair(##M,x,z,xz) & pair(##M,x,y,xy) & pair(##M,y,z,yz) & xy\\<in>s & yz\\<in>r)\"\n    unfolding separation_def by simp\n  with \\<open>S\\<in>M\\<close> \\<open>R\\<in>M\\<close> show ?thesis by simp\nqed\n\n\nschematic_goal pred_fm_auto:\n  assumes\n    \"nth(i,env) = y\" \"nth(j,env) = R\" \"nth(h,env) = X\"\n    \"i \\<in> nat\" \"j \\<in> nat\" \"h \\<in> nat\" \"env \\<in> list(A)\"\n  shows\n    \"(\\<exists>p\\<in>A. p\\<in>R & pair(##A,y,X,p)) \\<longleftrightarrow> sats(A,?pfm(i,j,h),env)\"\n  by (insert assms ; (rule sep_rules | simp)+)\n\n\nlemma pred_sep_intf:\n  assumes\n    \"R\\<in>M\"\n    and\n    \"X\\<in>M\"\n  shows\n    \"separation(##M, \\<lambda>y. \\<exists>p\\<in>M. p\\<in>R & pair(##M,y,X,p))\"\nproof -\n  obtain pfm where\n    fmsats:\"\\<And>env. env\\<in>list(M) \\<Longrightarrow>\n    (\\<exists>p\\<in>M. p\\<in>nth(1,env) & pair(##M,nth(0,env),nth(2,env),p)) \\<longleftrightarrow> sats(M,pfm(0,1,2),env)\"\n    and\n    \"pfm(0,1,2) \\<in> formula\"\n    and\n    \"arity(pfm(0,1,2)) = 3\"\n    using pred_fm_auto by (simp del:FOL_sats_iff pair_abs add: fm_defs nat_simp_union)\n  then\n  have \"\\<forall>x\\<in>M. \\<forall>r\\<in>M. separation(##M, \\<lambda>y. sats(M,pfm(0,1,2) , [y,r,x]))\"\n    using separation_ax by simp\n  moreover\n  have \"(\\<exists>p\\<in>M. p\\<in>r & pair(##M,y,x,p))\n          \\<longleftrightarrow> sats(M,pfm(0,1,2) , [y,r,x])\"\n    if \"y\\<in>M\" \"r\\<in>M\" \"x\\<in>M\" for y x r\n    using that fmsats[of \"[y,r,x]\"] by simp\n  ultimately\n  have \"\\<forall>x\\<in>M. \\<forall>r\\<in>M. separation(##M, \\<lambda> y . \\<exists>p\\<in>M. p\\<in>r & pair(##M,y,x,p))\"\n    unfolding separation_def by simp\n  with \\<open>X\\<in>M\\<close> \\<open>R\\<in>M\\<close> show ?thesis by simp\nqed\n\n(* Memrel_separation:\n     \"separation(M, \\<lambda>z. \\<exists>x[M]. \\<exists>y[M]. pair(M,x,y,z) & x \\<in> y)\"\n*)\nschematic_goal mem_fm_auto:\n  assumes\n    \"nth(i,env) = z\" \"i \\<in> nat\" \"env \\<in> list(A)\"\n  shows\n    \"(\\<exists>x\\<in>A. \\<exists>y\\<in>A. pair(##A,x,y,z) & x \\<in> y) \\<longleftrightarrow> sats(A,?mfm(i),env)\"\n  by (insert assms ; (rule sep_rules | simp)+)\n\nlemma memrel_sep_intf:\n  \"separation(##M, \\<lambda>z. \\<exists>x\\<in>M. \\<exists>y\\<in>M. pair(##M,x,y,z) & x \\<in> y)\"\nproof -\n  obtain mfm where\n    fmsats:\"\\<And>env. env\\<in>list(M) \\<Longrightarrow>\n    (\\<exists>x\\<in>M. \\<exists>y\\<in>M. pair(##M,x,y,nth(0,env)) & x \\<in> y) \\<longleftrightarrow> sats(M,mfm(0),env)\"\n    and\n    \"mfm(0) \\<in> formula\"\n    and\n    \"arity(mfm(0)) = 1\"\n    using mem_fm_auto by (simp del:FOL_sats_iff pair_abs add: fm_defs nat_simp_union)\n  then\n  have \"separation(##M, \\<lambda>z. sats(M,mfm(0) , [z]))\"\n    using separation_ax by simp\n  moreover\n  have \"(\\<exists>x\\<in>M. \\<exists>y\\<in>M. pair(##M,x,y,z) & x \\<in> y) \\<longleftrightarrow> sats(M,mfm(0),[z])\"\n    if \"z\\<in>M\" for z\n    using that fmsats[of \"[z]\"] by simp\n  ultimately\n  have \"separation(##M, \\<lambda>z . \\<exists>x\\<in>M. \\<exists>y\\<in>M. pair(##M,x,y,z) & x \\<in> y)\"\n    unfolding separation_def by simp\n  then show ?thesis by simp\nqed\n\nschematic_goal recfun_fm_auto:\n  assumes\n    \"nth(i1,env) = x\" \"nth(i2,env) = r\" \"nth(i3,env) = f\" \"nth(i4,env) = g\" \"nth(i5,env) = a\"\n    \"nth(i6,env) = b\" \"i1\\<in>nat\" \"i2\\<in>nat\" \"i3\\<in>nat\" \"i4\\<in>nat\" \"i5\\<in>nat\" \"i6\\<in>nat\" \"env \\<in> list(A)\"\n  shows\n    \"(\\<exists>xa\\<in>A. \\<exists>xb\\<in>A. pair(##A,x,a,xa) & xa \\<in> r & pair(##A,x,b,xb) & xb \\<in> r &\n                  (\\<exists>fx\\<in>A. \\<exists>gx\\<in>A. fun_apply(##A,f,x,fx) & fun_apply(##A,g,x,gx) & fx \\<noteq> gx))\n    \\<longleftrightarrow> sats(A,?rffm(i1,i2,i3,i4,i5,i6),env)\"\n  by (insert assms ; (rule sep_rules | simp)+)\n\n\nlemma is_recfun_sep_intf :\n  assumes\n    \"r\\<in>M\" \"f\\<in>M\" \"g\\<in>M\" \"a\\<in>M\" \"b\\<in>M\"\n  shows\n    \"separation(##M,\\<lambda>x. \\<exists>xa\\<in>M. \\<exists>xb\\<in>M.\n                    pair(##M,x,a,xa) & xa \\<in> r & pair(##M,x,b,xb) & xb \\<in> r &\n                    (\\<exists>fx\\<in>M. \\<exists>gx\\<in>M. fun_apply(##M,f,x,fx) & fun_apply(##M,g,x,gx) &\n                                     fx \\<noteq> gx))\"\nproof -\n  obtain rffm where\n    fmsats:\"\\<And>env. env\\<in>list(M) \\<Longrightarrow>\n    (\\<exists>xa\\<in>M. \\<exists>xb\\<in>M. pair(##M,nth(0,env),nth(4,env),xa) & xa \\<in> nth(1,env) &\n    pair(##M,nth(0,env),nth(5,env),xb) & xb \\<in> nth(1,env) & (\\<exists>fx\\<in>M. \\<exists>gx\\<in>M.\n    fun_apply(##M,nth(2,env),nth(0,env),fx) & fun_apply(##M,nth(3,env),nth(0,env),gx) & fx \\<noteq> gx))\n    \\<longleftrightarrow> sats(M,rffm(0,1,2,3,4,5),env)\"\n    and\n    \"rffm(0,1,2,3,4,5) \\<in> formula\"\n    and\n    \"arity(rffm(0,1,2,3,4,5)) = 6\"\n    using recfun_fm_auto by (simp del:FOL_sats_iff pair_abs add: fm_defs nat_simp_union)\n  then\n  have \"\\<forall>a1\\<in>M. \\<forall>a2\\<in>M. \\<forall>a3\\<in>M. \\<forall>a4\\<in>M. \\<forall>a5\\<in>M.\n        separation(##M, \\<lambda>x. sats(M,rffm(0,1,2,3,4,5) , [x,a1,a2,a3,a4,a5]))\"\n    using separation_ax by simp\n  moreover\n  have \"(\\<exists>xa\\<in>M. \\<exists>xb\\<in>M. pair(##M,x,a4,xa) & xa \\<in> a1 & pair(##M,x,a5,xb) & xb \\<in> a1 &\n          (\\<exists>fx\\<in>M. \\<exists>gx\\<in>M. fun_apply(##M,a2,x,fx) & fun_apply(##M,a3,x,gx) & fx \\<noteq> gx))\n          \\<longleftrightarrow> sats(M,rffm(0,1,2,3,4,5) , [x,a1,a2,a3,a4,a5])\"\n    if \"x\\<in>M\" \"a1\\<in>M\" \"a2\\<in>M\" \"a3\\<in>M\" \"a4\\<in>M\" \"a5\\<in>M\"  for x a1 a2 a3 a4 a5\n    using that fmsats[of \"[x,a1,a2,a3,a4,a5]\"] by simp\n  ultimately\n  have \"\\<forall>a1\\<in>M. \\<forall>a2\\<in>M. \\<forall>a3\\<in>M. \\<forall>a4\\<in>M. \\<forall>a5\\<in>M. separation(##M, \\<lambda> x .\n          \\<exists>xa\\<in>M. \\<exists>xb\\<in>M. pair(##M,x,a4,xa) & xa \\<in> a1 & pair(##M,x,a5,xb) & xb \\<in> a1 &\n          (\\<exists>fx\\<in>M. \\<exists>gx\\<in>M. fun_apply(##M,a2,x,fx) & fun_apply(##M,a3,x,gx) & fx \\<noteq> gx))\"\n    unfolding separation_def by simp\n  with \\<open>r\\<in>M\\<close> \\<open>f\\<in>M\\<close> \\<open>g\\<in>M\\<close> \\<open>a\\<in>M\\<close> \\<open>b\\<in>M\\<close> show ?thesis by simp\nqed\n\n\n(* Instance of Replacement for M_basic *)\n\nschematic_goal funsp_fm_auto:\n  assumes\n    \"nth(i,env) = p\" \"nth(j,env) = z\" \"nth(h,env) = n\"\n    \"i \\<in> nat\" \"j \\<in> nat\" \"h \\<in> nat\" \"env \\<in> list(A)\"\n  shows\n    \"(\\<exists>f\\<in>A. \\<exists>b\\<in>A. \\<exists>nb\\<in>A. \\<exists>cnbf\\<in>A. pair(##A,f,b,p) & pair(##A,n,b,nb) & is_cons(##A,nb,f,cnbf) &\n    upair(##A,cnbf,cnbf,z)) \\<longleftrightarrow> sats(A,?fsfm(i,j,h),env)\"\n  by (insert assms ; (rule sep_rules | simp)+)\n\n\nlemma funspace_succ_rep_intf :\n  assumes\n    \"n\\<in>M\"\n  shows\n    \"strong_replacement(##M,\n          \\<lambda>p z. \\<exists>f\\<in>M. \\<exists>b\\<in>M. \\<exists>nb\\<in>M. \\<exists>cnbf\\<in>M.\n                pair(##M,f,b,p) & pair(##M,n,b,nb) & is_cons(##M,nb,f,cnbf) &\n                upair(##M,cnbf,cnbf,z))\"\nproof -\n  obtain fsfm where\n    fmsats:\"env\\<in>list(M) \\<Longrightarrow>\n    (\\<exists>f\\<in>M. \\<exists>b\\<in>M. \\<exists>nb\\<in>M. \\<exists>cnbf\\<in>M. pair(##M,f,b,nth(0,env)) & pair(##M,nth(2,env),b,nb)\n      & is_cons(##M,nb,f,cnbf) & upair(##M,cnbf,cnbf,nth(1,env)))\n    \\<longleftrightarrow> sats(M,fsfm(0,1,2),env)\"\n    and \"fsfm(0,1,2) \\<in> formula\" and \"arity(fsfm(0,1,2)) = 3\" for env\n    using funsp_fm_auto[of concl:M] by (simp del:FOL_sats_iff pair_abs add: fm_defs nat_simp_union)\n  then\n  have \"\\<forall>n0\\<in>M. strong_replacement(##M, \\<lambda>p z. sats(M,fsfm(0,1,2) , [p,z,n0]))\"\n    using replacement_ax by simp\n  moreover\n  have \"(\\<exists>f\\<in>M. \\<exists>b\\<in>M. \\<exists>nb\\<in>M. \\<exists>cnbf\\<in>M. pair(##M,f,b,p) & pair(##M,n0,b,nb) &\n          is_cons(##M,nb,f,cnbf) & upair(##M,cnbf,cnbf,z))\n          \\<longleftrightarrow> sats(M,fsfm(0,1,2) , [p,z,n0])\"\n    if \"p\\<in>M\" \"z\\<in>M\" \"n0\\<in>M\" for p z n0\n    using that fmsats[of \"[p,z,n0]\"] by simp\n  ultimately\n  have \"\\<forall>n0\\<in>M. strong_replacement(##M, \\<lambda> p z.\n          \\<exists>f\\<in>M. \\<exists>b\\<in>M. \\<exists>nb\\<in>M. \\<exists>cnbf\\<in>M. pair(##M,f,b,p) & pair(##M,n0,b,nb) &\n          is_cons(##M,nb,f,cnbf) & upair(##M,cnbf,cnbf,z))\"\n    unfolding strong_replacement_def univalent_def by simp\n  with \\<open>n\\<in>M\\<close> show ?thesis by simp\nqed\n\n\n(* Interface with M_basic *)\n\nlemmas M_basic_sep_instances =\n  inter_sep_intf diff_sep_intf cartprod_sep_intf\n  image_sep_intf converse_sep_intf restrict_sep_intf\n  pred_sep_intf memrel_sep_intf comp_sep_intf is_recfun_sep_intf\n\nlemma mbasic : \"M_basic(##M)\"\n  using trans_M zero_in_M power_ax M_basic_sep_instances funspace_succ_rep_intf mtriv\n  by unfold_locales auto\n\nend\n\nsublocale M_ZF_trans \\<subseteq> M_basic \"##M\"\n  by (rule mbasic)\n\nsubsection\\<open>Interface with \\<^term>\\<open>M_trancl\\<close>\\<close>\n\n(* rtran_closure_mem *)\nschematic_goal rtran_closure_mem_auto:\n  assumes\n    \"nth(i,env) = p\" \"nth(j,env) = r\"  \"nth(k,env) = B\"\n    \"i \\<in> nat\" \"j \\<in> nat\" \"k \\<in> nat\" \"env \\<in> list(A)\"\n  shows\n    \"rtran_closure_mem(##A,B,r,p) \\<longleftrightarrow> sats(A,?rcfm(i,j,k),env)\"\n  unfolding rtran_closure_mem_def\n  by (insert assms ; (rule sep_rules | simp)+)\n\n\nlemma (in M_ZF_trans) rtrancl_separation_intf:\n  assumes\n    \"r\\<in>M\"\n    and\n    \"A\\<in>M\"\n  shows\n    \"separation (##M, rtran_closure_mem(##M,A,r))\"\nproof -\n  obtain rcfm where\n    fmsats:\"\\<And>env. env\\<in>list(M) \\<Longrightarrow>\n    (rtran_closure_mem(##M,nth(2,env),nth(1,env),nth(0,env))) \\<longleftrightarrow> sats(M,rcfm(0,1,2),env)\"\n    and\n    \"rcfm(0,1,2) \\<in> formula\"\n    and\n    \"arity(rcfm(0,1,2)) = 3\"\n    using rtran_closure_mem_auto by (simp del:FOL_sats_iff pair_abs add: fm_defs nat_simp_union)\n  then\n  have \"\\<forall>x\\<in>M. \\<forall>a\\<in>M. separation(##M, \\<lambda>y. sats(M,rcfm(0,1,2) , [y,x,a]))\"\n    using separation_ax by simp\n  moreover\n  have \"(rtran_closure_mem(##M,a,x,y))\n          \\<longleftrightarrow> sats(M,rcfm(0,1,2) , [y,x,a])\"\n    if \"y\\<in>M\" \"x\\<in>M\" \"a\\<in>M\" for y x a\n    using that fmsats[of \"[y,x,a]\"] by simp\n  ultimately\n  have \"\\<forall>x\\<in>M. \\<forall>a\\<in>M. separation(##M, rtran_closure_mem(##M,a,x))\"\n    unfolding separation_def by simp\n  with \\<open>r\\<in>M\\<close> \\<open>A\\<in>M\\<close> show ?thesis by simp\nqed\n\nschematic_goal rtran_closure_fm_auto:\n  assumes\n    \"nth(i,env) = r\" \"nth(j,env) = rp\"\n    \"i \\<in> nat\" \"j \\<in> nat\" \"env \\<in> list(A)\"\n  shows\n    \"rtran_closure(##A,r,rp) \\<longleftrightarrow> sats(A,?rtc(i,j),env)\"\n  unfolding rtran_closure_def\n  by (insert assms ; (rule sep_rules rtran_closure_mem_auto | simp)+)\n\nschematic_goal trans_closure_fm_auto:\n  assumes\n    \"nth(i,env) = r\" \"nth(j,env) = rp\"\n    \"i \\<in> nat\" \"j \\<in> nat\" \"env \\<in> list(A)\"\n  shows\n    \"tran_closure(##A,r,rp) \\<longleftrightarrow> sats(A,?tc(i,j),env)\"\n  unfolding tran_closure_def\n  by (insert assms ; (rule sep_rules rtran_closure_fm_auto | simp))+\n\nsynthesize \"trans_closure_fm\" from_schematic trans_closure_fm_auto\n\nschematic_goal wellfounded_trancl_fm_auto:\n  assumes\n    \"nth(i,env) = p\" \"nth(j,env) = r\"  \"nth(k,env) = B\"\n    \"i \\<in> nat\" \"j \\<in> nat\" \"k \\<in> nat\" \"env \\<in> list(A)\"\n  shows\n    \"wellfounded_trancl(##A,B,r,p) \\<longleftrightarrow> sats(A,?wtf(i,j,k),env)\"\n  unfolding  wellfounded_trancl_def\n  by (insert assms ; (rule sep_rules trans_closure_fm_iff_sats | simp)+)\n\nlemma (in M_ZF_trans) wftrancl_separation_intf:\n  assumes\n    \"r\\<in>M\"\n    and\n    \"Z\\<in>M\"\n  shows\n    \"separation (##M, wellfounded_trancl(##M,Z,r))\"\nproof -\n  obtain rcfm where\n    fmsats:\"\\<And>env. env\\<in>list(M) \\<Longrightarrow>\n    (wellfounded_trancl(##M,nth(2,env),nth(1,env),nth(0,env))) \\<longleftrightarrow> sats(M,rcfm(0,1,2),env)\"\n    and\n    \"rcfm(0,1,2) \\<in> formula\"\n    and\n    \"arity(rcfm(0,1,2)) = 3\"\n    using wellfounded_trancl_fm_auto[of concl:M \"nth(2,_)\"] unfolding fm_defs trans_closure_fm_def\n    by (simp del:FOL_sats_iff pair_abs add: fm_defs nat_simp_union)\n  then\n  have \"\\<forall>x\\<in>M. \\<forall>z\\<in>M. separation(##M, \\<lambda>y. sats(M,rcfm(0,1,2) , [y,x,z]))\"\n    using separation_ax by simp\n  moreover\n  have \"(wellfounded_trancl(##M,z,x,y))\n          \\<longleftrightarrow> sats(M,rcfm(0,1,2) , [y,x,z])\"\n    if \"y\\<in>M\" \"x\\<in>M\" \"z\\<in>M\" for y x z\n    using that fmsats[of \"[y,x,z]\"] by simp\n  ultimately\n  have \"\\<forall>x\\<in>M. \\<forall>z\\<in>M. separation(##M, wellfounded_trancl(##M,z,x))\"\n    unfolding separation_def by simp\n  with \\<open>r\\<in>M\\<close> \\<open>Z\\<in>M\\<close> show ?thesis by simp\nqed\n\n(* nat \\<in> M *)\n\nlemma (in M_ZF_trans) finite_sep_intf:\n  \"separation(##M, \\<lambda>x. x\\<in>nat)\"\nproof -\n  have \"arity(finite_ordinal_fm(0)) = 1 \"\n    unfolding finite_ordinal_fm_def limit_ordinal_fm_def empty_fm_def succ_fm_def cons_fm_def\n      union_fm_def upair_fm_def\n    by (simp add: nat_union_abs1 Un_commute)\n  with separation_ax\n  have \"(\\<forall>v\\<in>M. separation(##M,\\<lambda>x. sats(M,finite_ordinal_fm(0),[x,v])))\"\n    by simp\n  then have \"(\\<forall>v\\<in>M. separation(##M,finite_ordinal(##M)))\"\n    unfolding separation_def by simp\n  then have \"separation(##M,finite_ordinal(##M))\"\n    using zero_in_M by auto\n  then show ?thesis unfolding separation_def by simp\nqed\n\n\nlemma (in M_ZF_trans) nat_subset_I' :\n  \"\\<lbrakk> I\\<in>M ; 0\\<in>I ; \\<And>x. x\\<in>I \\<Longrightarrow> succ(x)\\<in>I \\<rbrakk> \\<Longrightarrow> nat \\<subseteq> I\"\n  by (rule subsetI,induct_tac x,simp+)\n\n\nlemma (in M_ZF_trans) nat_subset_I :\n  \"\\<exists>I\\<in>M. nat \\<subseteq> I\"\nproof -\n  have \"\\<exists>I\\<in>M. 0\\<in>I \\<and> (\\<forall>x\\<in>M. x\\<in>I \\<longrightarrow> succ(x)\\<in>I)\"\n    using infinity_ax unfolding infinity_ax_def by auto\n  then obtain I where\n    \"I\\<in>M\" \"0\\<in>I\" \"(\\<forall>x\\<in>M. x\\<in>I \\<longrightarrow> succ(x)\\<in>I)\"\n    by auto\n  then have \"\\<And>x. x\\<in>I \\<Longrightarrow> succ(x)\\<in>I\"\n    using Transset_intf[OF trans_M]  by simp\n  then have \"nat\\<subseteq>I\"\n    using  \\<open>I\\<in>M\\<close> \\<open>0\\<in>I\\<close> nat_subset_I' by simp\n  then show ?thesis using \\<open>I\\<in>M\\<close> by auto\nqed\n\nlemma (in M_ZF_trans) nat_in_M :\n  \"nat \\<in> M\"\nproof -\n  have 1:\"{x\\<in>B . x\\<in>A}=A\" if \"A\\<subseteq>B\" for A B\n    using that by auto\n  obtain I where\n    \"I\\<in>M\" \"nat\\<subseteq>I\"\n    using nat_subset_I by auto\n  then have \"{x\\<in>I . x\\<in>nat} \\<in> M\"\n    using finite_sep_intf separation_closed[of \"\\<lambda>x . x\\<in>nat\"] by simp\n  then show ?thesis\n    using \\<open>nat\\<subseteq>I\\<close> 1 by simp\nqed\n  (* end nat \\<in> M *)\n\n\nlemma (in M_ZF_trans) mtrancl : \"M_trancl(##M)\"\n  using  mbasic rtrancl_separation_intf wftrancl_separation_intf nat_in_M\n    wellfounded_trancl_def\n  by unfold_locales auto\n\nsublocale M_ZF_trans \\<subseteq> M_trancl \"##M\"\n  by (rule mtrancl)\n\nsubsection\\<open>Interface with \\<^term>\\<open>M_eclose\\<close>\\<close>\n\nlemma repl_sats:\n  assumes\n    sat:\"\\<And>x z. x\\<in>M \\<Longrightarrow> z\\<in>M \\<Longrightarrow> sats(M,\\<phi>,Cons(x,Cons(z,env))) \\<longleftrightarrow> P(x,z)\"\n  shows\n    \"strong_replacement(##M,\\<lambda>x z. sats(M,\\<phi>,Cons(x,Cons(z,env)))) \\<longleftrightarrow>\n   strong_replacement(##M,P)\"\n  by (rule strong_replacement_cong,simp add:sat)\n\nlemma (in M_ZF_trans) nat_trans_M :\n  \"n\\<in>M\" if \"n\\<in>nat\" for n\n  using that nat_in_M Transset_intf[OF trans_M] by simp\n\nlemma (in M_ZF_trans) list_repl1_intf:\n  assumes\n    \"A\\<in>M\"\n  shows\n    \"iterates_replacement(##M, is_list_functor(##M,A), 0)\"\nproof -\n  {\n    fix n\n    assume \"n\\<in>nat\"\n    have \"succ(n)\\<in>M\"\n      using \\<open>n\\<in>nat\\<close> nat_trans_M by simp\n    then have 1:\"Memrel(succ(n))\\<in>M\"\n      using \\<open>n\\<in>nat\\<close> Memrel_closed by simp\n    have \"0\\<in>M\"\n      using  nat_0I nat_trans_M by simp\n    then have \"is_list_functor(##M, A, a, b)\n       \\<longleftrightarrow> sats(M, list_functor_fm(13,1,0), [b,a,c,d,a0,a1,a2,a3,a4,y,x,z,Memrel(succ(n)),A,0])\"\n      if \"a\\<in>M\" \"b\\<in>M\" \"c\\<in>M\" \"d\\<in>M\" \"a0\\<in>M\" \"a1\\<in>M\" \"a2\\<in>M\" \"a3\\<in>M\" \"a4\\<in>M\" \"y\\<in>M\" \"x\\<in>M\" \"z\\<in>M\"\n      for a b c d a0 a1 a2 a3 a4 y x z\n      using that 1 \\<open>A\\<in>M\\<close> list_functor_iff_sats by simp\n    then have \"sats(M, iterates_MH_fm(list_functor_fm(13,1,0),10,2,1,0), [a0,a1,a2,a3,a4,y,x,z,Memrel(succ(n)),A,0])\n        \\<longleftrightarrow> iterates_MH(##M,is_list_functor(##M,A),0,a2, a1, a0)\"\n      if \"a0\\<in>M\" \"a1\\<in>M\" \"a2\\<in>M\" \"a3\\<in>M\" \"a4\\<in>M\" \"y\\<in>M\" \"x\\<in>M\" \"z\\<in>M\"\n      for a0 a1 a2 a3 a4 y x z\n      using that sats_iterates_MH_fm[of M \"is_list_functor(##M,A)\" _] 1 \\<open>0\\<in>M\\<close> \\<open>A\\<in>M\\<close>  by simp\n    then have 2:\"sats(M, is_wfrec_fm(iterates_MH_fm(list_functor_fm(13,1,0),10,2,1,0),3,1,0),\n                            [y,x,z,Memrel(succ(n)),A,0])\n        \\<longleftrightarrow>\n        is_wfrec(##M, iterates_MH(##M,is_list_functor(##M,A),0) , Memrel(succ(n)), x, y)\"\n      if \"y\\<in>M\" \"x\\<in>M\" \"z\\<in>M\" for y x z\n      using  that sats_is_wfrec_fm 1 \\<open>0\\<in>M\\<close> \\<open>A\\<in>M\\<close> by simp\n    let\n      ?f=\"Exists(And(pair_fm(1,0,2),\n               is_wfrec_fm(iterates_MH_fm(list_functor_fm(13,1,0),10,2,1,0),3,1,0)))\"\n    have satsf:\"sats(M, ?f, [x,z,Memrel(succ(n)),A,0])\n        \\<longleftrightarrow>\n        (\\<exists>y\\<in>M. pair(##M,x,y,z) &\n        is_wfrec(##M, iterates_MH(##M,is_list_functor(##M,A),0) , Memrel(succ(n)), x, y))\"\n      if \"x\\<in>M\" \"z\\<in>M\" for x z\n      using that 2 1 \\<open>0\\<in>M\\<close> \\<open>A\\<in>M\\<close> by (simp del:pair_abs)\n    have \"arity(?f) = 5\"\n      unfolding iterates_MH_fm_def is_wfrec_fm_def is_recfun_fm_def is_nat_case_fm_def\n        restriction_fm_def list_functor_fm_def number1_fm_def cartprod_fm_def\n        sum_fm_def quasinat_fm_def pre_image_fm_def fm_defs\n      by (simp add:nat_simp_union)\n    then\n    have \"strong_replacement(##M,\\<lambda>x z. sats(M,?f,[x,z,Memrel(succ(n)),A,0]))\"\n      using replacement_ax 1 \\<open>A\\<in>M\\<close> \\<open>0\\<in>M\\<close> by simp\n    then\n    have \"strong_replacement(##M,\\<lambda>x z.\n          \\<exists>y\\<in>M. pair(##M,x,y,z) & is_wfrec(##M, iterates_MH(##M,is_list_functor(##M,A),0) ,\n                Memrel(succ(n)), x, y))\"\n      using repl_sats[of M ?f \"[Memrel(succ(n)),A,0]\"]  satsf by (simp del:pair_abs)\n  }\n  then\n  show ?thesis unfolding iterates_replacement_def wfrec_replacement_def by simp\nqed\n\n\n\n(* Iterates_replacement para predicados sin parámetros *)\nlemma (in M_ZF_trans) iterates_repl_intf :\n  assumes\n    \"v\\<in>M\" and\n    isfm:\"is_F_fm \\<in> formula\" and\n    arty:\"arity(is_F_fm)=2\" and\n    satsf: \"\\<And>a b env'. \\<lbrakk> a\\<in>M ; b\\<in>M ; env'\\<in>list(M) \\<rbrakk>\n              \\<Longrightarrow> is_F(a,b) \\<longleftrightarrow> sats(M, is_F_fm, [b,a]@env')\"\n  shows\n    \"iterates_replacement(##M,is_F,v)\"\nproof -\n  {\n    fix n\n    assume \"n\\<in>nat\"\n    have \"succ(n)\\<in>M\"\n      using \\<open>n\\<in>nat\\<close> nat_trans_M by simp\n    then have 1:\"Memrel(succ(n))\\<in>M\"\n      using \\<open>n\\<in>nat\\<close> Memrel_closed by simp\n    {\n      fix a0 a1 a2 a3 a4 y x z\n      assume as:\"a0\\<in>M\" \"a1\\<in>M\" \"a2\\<in>M\" \"a3\\<in>M\" \"a4\\<in>M\" \"y\\<in>M\" \"x\\<in>M\" \"z\\<in>M\"\n      have \"sats(M, is_F_fm, Cons(b,Cons(a,Cons(c,Cons(d,[a0,a1,a2,a3,a4,y,x,z,Memrel(succ(n)),v])))))\n          \\<longleftrightarrow> is_F(a,b)\"\n        if \"a\\<in>M\" \"b\\<in>M\" \"c\\<in>M\" \"d\\<in>M\" for a b c d\n        using as that 1 satsf[of a b \"[c,d,a0,a1,a2,a3,a4,y,x,z,Memrel(succ(n)),v]\"] \\<open>v\\<in>M\\<close> by simp\n      then\n      have \"sats(M, iterates_MH_fm(is_F_fm,9,2,1,0), [a0,a1,a2,a3,a4,y,x,z,Memrel(succ(n)),v])\n          \\<longleftrightarrow> iterates_MH(##M,is_F,v,a2, a1, a0)\"\n        using as\n          sats_iterates_MH_fm[of M \"is_F\" \"is_F_fm\"] 1 \\<open>v\\<in>M\\<close> by simp\n    }\n    then have 2:\"sats(M, is_wfrec_fm(iterates_MH_fm(is_F_fm,9,2,1,0),3,1,0),\n                            [y,x,z,Memrel(succ(n)),v])\n        \\<longleftrightarrow>\n        is_wfrec(##M, iterates_MH(##M,is_F,v),Memrel(succ(n)), x, y)\"\n      if \"y\\<in>M\" \"x\\<in>M\" \"z\\<in>M\" for y x z\n      using  that sats_is_wfrec_fm 1 \\<open>v\\<in>M\\<close> by simp\n    let\n      ?f=\"Exists(And(pair_fm(1,0,2),\n               is_wfrec_fm(iterates_MH_fm(is_F_fm,9,2,1,0),3,1,0)))\"\n    have satsf:\"sats(M, ?f, [x,z,Memrel(succ(n)),v])\n        \\<longleftrightarrow>\n        (\\<exists>y\\<in>M. pair(##M,x,y,z) &\n        is_wfrec(##M, iterates_MH(##M,is_F,v) , Memrel(succ(n)), x, y))\"\n      if \"x\\<in>M\" \"z\\<in>M\" for x z\n      using that 2 1 \\<open>v\\<in>M\\<close> by (simp del:pair_abs)\n    have \"arity(?f) = 4\"\n      unfolding iterates_MH_fm_def is_wfrec_fm_def is_recfun_fm_def is_nat_case_fm_def\n        restriction_fm_def pre_image_fm_def quasinat_fm_def fm_defs\n      using arty by (simp add:nat_simp_union)\n    then\n    have \"strong_replacement(##M,\\<lambda>x z. sats(M,?f,[x,z,Memrel(succ(n)),v]))\"\n      using replacement_ax 1 \\<open>v\\<in>M\\<close> \\<open>is_F_fm\\<in>formula\\<close> by simp\n    then\n    have \"strong_replacement(##M,\\<lambda>x z.\n          \\<exists>y\\<in>M. pair(##M,x,y,z) & is_wfrec(##M, iterates_MH(##M,is_F,v) ,\n                Memrel(succ(n)), x, y))\"\n      using repl_sats[of M ?f \"[Memrel(succ(n)),v]\"]  satsf by (simp del:pair_abs)\n  }\n  then\n  show ?thesis unfolding iterates_replacement_def wfrec_replacement_def by simp\nqed\n\nlemma (in M_ZF_trans) formula_repl1_intf :\n  \"iterates_replacement(##M, is_formula_functor(##M), 0)\"\nproof -\n  have \"0\\<in>M\"\n    using  nat_0I nat_trans_M by simp\n  have 1:\"arity(formula_functor_fm(1,0)) = 2\"\n    unfolding formula_functor_fm_def fm_defs sum_fm_def cartprod_fm_def number1_fm_def\n    by (simp add:nat_simp_union)\n  have 2:\"formula_functor_fm(1,0)\\<in>formula\" by simp\n  have \"is_formula_functor(##M,a,b) \\<longleftrightarrow>\n        sats(M, formula_functor_fm(1,0), [b,a])\"\n    if \"a\\<in>M\" \"b\\<in>M\"  for a b\n    using that by simp\n  then show ?thesis using \\<open>0\\<in>M\\<close> 1 2 iterates_repl_intf by simp\nqed\n\nlemma (in M_ZF_trans) nth_repl_intf:\n  assumes\n    \"l \\<in> M\"\n  shows\n    \"iterates_replacement(##M,\\<lambda>l' t. is_tl(##M,l',t),l)\"\nproof -\n  have 1:\"arity(tl_fm(1,0)) = 2\"\n    unfolding tl_fm_def fm_defs quasilist_fm_def Cons_fm_def Nil_fm_def Inr_fm_def number1_fm_def\n      Inl_fm_def by (simp add:nat_simp_union)\n  have 2:\"tl_fm(1,0)\\<in>formula\" by simp\n  have \"is_tl(##M,a,b) \\<longleftrightarrow> sats(M, tl_fm(1,0), [b,a])\"\n    if \"a\\<in>M\" \"b\\<in>M\" for a b\n    using that by simp\n  then show ?thesis using \\<open>l\\<in>M\\<close> 1 2 iterates_repl_intf by simp\nqed\n\n\nlemma (in M_ZF_trans) eclose_repl1_intf:\n  assumes\n    \"A\\<in>M\"\n  shows\n    \"iterates_replacement(##M, big_union(##M), A)\"\nproof -\n  have 1:\"arity(big_union_fm(1,0)) = 2\"\n    unfolding big_union_fm_def fm_defs by (simp add:nat_simp_union)\n  have 2:\"big_union_fm(1,0)\\<in>formula\" by simp\n  have \"big_union(##M,a,b) \\<longleftrightarrow> sats(M, big_union_fm(1,0), [b,a])\"\n    if \"a\\<in>M\" \"b\\<in>M\" for a b\n    using that by simp\n  then show ?thesis using \\<open>A\\<in>M\\<close> 1 2 iterates_repl_intf by simp\nqed\n\n(*\n    and list_replacement2:\n   \"M(A) \\<Longrightarrow> strong_replacement(M,\n         \\<lambda>n y. n\\<in>nat & is_iterates(M, is_list_functor(M,A), 0, n, y))\"\n\n*)\nlemma (in M_ZF_trans) list_repl2_intf:\n  assumes\n    \"A\\<in>M\"\n  shows\n    \"strong_replacement(##M,\\<lambda>n y. n\\<in>nat & is_iterates(##M, is_list_functor(##M,A), 0, n, y))\"\nproof -\n  have \"0\\<in>M\"\n    using  nat_0I nat_trans_M by simp\n  have \"is_list_functor(##M,A,a,b) \\<longleftrightarrow>\n        sats(M,list_functor_fm(13,1,0),[b,a,c,d,e,f,g,h,i,j,k,n,y,A,0,nat])\"\n    if \"a\\<in>M\" \"b\\<in>M\" \"c\\<in>M\" \"d\\<in>M\" \"e\\<in>M\" \"f\\<in>M\"\"g\\<in>M\"\"h\\<in>M\"\"i\\<in>M\"\"j\\<in>M\" \"k\\<in>M\" \"n\\<in>M\" \"y\\<in>M\"\n    for a b c d e f g h i j k n y\n    using that \\<open>0\\<in>M\\<close> nat_in_M \\<open>A\\<in>M\\<close> by simp\n  then\n  have 1:\"sats(M, is_iterates_fm(list_functor_fm(13,1,0),3,0,1),[n,y,A,0,nat] ) \\<longleftrightarrow>\n           is_iterates(##M, is_list_functor(##M,A), 0, n , y)\"\n    if \"n\\<in>M\" \"y\\<in>M\" for n y\n    using that \\<open>0\\<in>M\\<close> \\<open>A\\<in>M\\<close> nat_in_M\n      sats_is_iterates_fm[of M \"is_list_functor(##M,A)\"] by simp\n  let ?f = \"And(Member(0,4),is_iterates_fm(list_functor_fm(13,1,0),3,0,1))\"\n  have satsf:\"sats(M, ?f,[n,y,A,0,nat] ) \\<longleftrightarrow>\n        n\\<in>nat & is_iterates(##M, is_list_functor(##M,A), 0, n, y)\"\n    if \"n\\<in>M\" \"y\\<in>M\" for n y\n    using that \\<open>0\\<in>M\\<close> \\<open>A\\<in>M\\<close> nat_in_M 1 by simp\n  have \"arity(?f) = 5\"\n    unfolding is_iterates_fm_def restriction_fm_def list_functor_fm_def number1_fm_def Memrel_fm_def\n      cartprod_fm_def sum_fm_def quasinat_fm_def pre_image_fm_def fm_defs is_wfrec_fm_def\n      is_recfun_fm_def iterates_MH_fm_def is_nat_case_fm_def\n    by (simp add:nat_simp_union)\n  then\n  have \"strong_replacement(##M,\\<lambda>n y. sats(M,?f,[n,y,A,0,nat]))\"\n    using replacement_ax 1 nat_in_M \\<open>A\\<in>M\\<close> \\<open>0\\<in>M\\<close> by simp\n  then\n  show ?thesis using repl_sats[of M ?f \"[A,0,nat]\"]  satsf  by simp\nqed\n\nlemma (in M_ZF_trans) formula_repl2_intf:\n  \"strong_replacement(##M,\\<lambda>n y. n\\<in>nat & is_iterates(##M, is_formula_functor(##M), 0, n, y))\"\nproof -\n  have \"0\\<in>M\"\n    using  nat_0I nat_trans_M by simp\n  have \"is_formula_functor(##M,a,b) \\<longleftrightarrow>\n        sats(M,formula_functor_fm(1,0),[b,a,c,d,e,f,g,h,i,j,k,n,y,0,nat])\"\n    if \"a\\<in>M\" \"b\\<in>M\" \"c\\<in>M\" \"d\\<in>M\" \"e\\<in>M\" \"f\\<in>M\"\"g\\<in>M\"\"h\\<in>M\"\"i\\<in>M\"\"j\\<in>M\" \"k\\<in>M\" \"n\\<in>M\" \"y\\<in>M\"\n    for a b c d e f g h i j k n y\n    using that \\<open>0\\<in>M\\<close> nat_in_M by simp\n  then\n  have 1:\"sats(M, is_iterates_fm(formula_functor_fm(1,0),2,0,1),[n,y,0,nat] ) \\<longleftrightarrow>\n           is_iterates(##M, is_formula_functor(##M), 0, n , y)\"\n    if \"n\\<in>M\" \"y\\<in>M\" for n y\n    using that \\<open>0\\<in>M\\<close> nat_in_M\n      sats_is_iterates_fm[of M \"is_formula_functor(##M)\"] by simp\n  let ?f = \"And(Member(0,3),is_iterates_fm(formula_functor_fm(1,0),2,0,1))\"\n  have satsf:\"sats(M, ?f,[n,y,0,nat] ) \\<longleftrightarrow>\n        n\\<in>nat & is_iterates(##M, is_formula_functor(##M), 0, n, y)\"\n    if \"n\\<in>M\" \"y\\<in>M\" for n y\n    using that \\<open>0\\<in>M\\<close> nat_in_M 1 by simp\n  have artyf:\"arity(?f) = 4\"\n    unfolding is_iterates_fm_def formula_functor_fm_def fm_defs sum_fm_def quasinat_fm_def\n      cartprod_fm_def number1_fm_def Memrel_fm_def ordinal_fm_def transset_fm_def\n      is_wfrec_fm_def is_recfun_fm_def iterates_MH_fm_def is_nat_case_fm_def subset_fm_def\n      pre_image_fm_def restriction_fm_def\n    by (simp add:nat_simp_union)\n  then\n  have \"strong_replacement(##M,\\<lambda>n y. sats(M,?f,[n,y,0,nat]))\"\n    using replacement_ax 1 artyf \\<open>0\\<in>M\\<close> nat_in_M by simp\n  then\n  show ?thesis using repl_sats[of M ?f \"[0,nat]\"]  satsf  by simp\nqed\n\n\n(*\n   \"M(A) \\<Longrightarrow> strong_replacement(M,\n         \\<lambda>n y. n\\<in>nat & is_iterates(M, big_union(M), A, n, y))\"\n*)\n\nlemma (in M_ZF_trans) eclose_repl2_intf:\n  assumes\n    \"A\\<in>M\"\n  shows\n    \"strong_replacement(##M,\\<lambda>n y. n\\<in>nat & is_iterates(##M, big_union(##M), A, n, y))\"\nproof -\n  have \"big_union(##M,a,b) \\<longleftrightarrow>\n        sats(M,big_union_fm(1,0),[b,a,c,d,e,f,g,h,i,j,k,n,y,A,nat])\"\n    if \"a\\<in>M\" \"b\\<in>M\" \"c\\<in>M\" \"d\\<in>M\" \"e\\<in>M\" \"f\\<in>M\"\"g\\<in>M\"\"h\\<in>M\"\"i\\<in>M\"\"j\\<in>M\" \"k\\<in>M\" \"n\\<in>M\" \"y\\<in>M\"\n    for a b c d e f g h i j k n y\n    using that \\<open>A\\<in>M\\<close> nat_in_M by simp\n  then\n  have 1:\"sats(M, is_iterates_fm(big_union_fm(1,0),2,0,1),[n,y,A,nat] ) \\<longleftrightarrow>\n           is_iterates(##M, big_union(##M), A, n , y)\"\n    if \"n\\<in>M\" \"y\\<in>M\" for n y\n    using that \\<open>A\\<in>M\\<close> nat_in_M\n      sats_is_iterates_fm[of M \"big_union(##M)\"] by simp\n  let ?f = \"And(Member(0,3),is_iterates_fm(big_union_fm(1,0),2,0,1))\"\n  have satsf:\"sats(M, ?f,[n,y,A,nat] ) \\<longleftrightarrow>\n        n\\<in>nat & is_iterates(##M, big_union(##M), A, n, y)\"\n    if \"n\\<in>M\" \"y\\<in>M\" for n y\n    using that \\<open>A\\<in>M\\<close> nat_in_M 1 by simp\n  have artyf:\"arity(?f) = 4\"\n    unfolding is_iterates_fm_def formula_functor_fm_def fm_defs sum_fm_def quasinat_fm_def\n      cartprod_fm_def number1_fm_def Memrel_fm_def ordinal_fm_def transset_fm_def\n      is_wfrec_fm_def is_recfun_fm_def iterates_MH_fm_def is_nat_case_fm_def subset_fm_def\n      pre_image_fm_def restriction_fm_def\n    by (simp add:nat_simp_union)\n  then\n  have \"strong_replacement(##M,\\<lambda>n y. sats(M,?f,[n,y,A,nat]))\"\n    using replacement_ax 1 artyf \\<open>A\\<in>M\\<close> nat_in_M by simp\n  then\n  show ?thesis using repl_sats[of M ?f \"[A,nat]\"]  satsf  by simp\nqed\n\nlemma (in M_ZF_trans) mdatatypes : \"M_datatypes(##M)\"\n  using  mtrancl list_repl1_intf list_repl2_intf formula_repl1_intf\n    formula_repl2_intf nth_repl_intf\n  by unfold_locales auto\n\nsublocale M_ZF_trans \\<subseteq> M_datatypes \"##M\"\n  by (rule mdatatypes)\n\nlemma (in M_ZF_trans) meclose : \"M_eclose(##M)\"\n  using mdatatypes eclose_repl1_intf eclose_repl2_intf\n  by unfold_locales auto\n\nsublocale M_ZF_trans \\<subseteq> M_eclose \"##M\"\n  by (rule meclose)\n\n(* Interface with locale M_eclose_pow *)\n\n(* \"powerset(M,A,z) \\<equiv> \\<forall>x[M]. x \\<in> z \\<longleftrightarrow> subset(M,x,A)\" *)\ndefinition\n  powerset_fm :: \"[i,i] \\<Rightarrow> i\" where\n  \"powerset_fm(A,z) \\<equiv> Forall(Iff(Member(0,succ(z)),subset_fm(0,succ(A))))\"\n\nlemma powerset_type [TC]:\n  \"\\<lbrakk> x \\<in> nat; y \\<in> nat \\<rbrakk> \\<Longrightarrow> powerset_fm(x,y) \\<in> formula\"\n  by (simp add:powerset_fm_def)\n\ndefinition\n  is_powapply_fm :: \"[i,i,i] \\<Rightarrow> i\" where\n  \"is_powapply_fm(f,y,z) \\<equiv>\n      Exists(And(fun_apply_fm(succ(f), succ(y), 0),\n            Forall(Iff(Member(0, succ(succ(z))),\n            Forall(Implies(Member(0, 1), Member(0, 2)))))))\"\n\nlemma is_powapply_type [TC] :\n  \"\\<lbrakk>f\\<in>nat ; y\\<in>nat; z\\<in>nat\\<rbrakk> \\<Longrightarrow> is_powapply_fm(f,y,z)\\<in>formula\"\n  unfolding is_powapply_fm_def by simp\n\nlemma sats_is_powapply_fm :\n  assumes\n    \"f\\<in>nat\" \"y\\<in>nat\" \"z\\<in>nat\" \"env\\<in>list(A)\" \"0\\<in>A\"\n  shows\n    \"is_powapply(##A,nth(f, env),nth(y, env),nth(z, env))\n    \\<longleftrightarrow> sats(A,is_powapply_fm(f,y,z),env)\"\n  unfolding is_powapply_def is_powapply_fm_def is_Collect_def powerset_def subset_def\n  using nth_closed assms by simp\n\n\nlemma (in M_ZF_trans) powapply_repl :\n  assumes\n    \"f\\<in>M\"\n  shows\n    \"strong_replacement(##M,is_powapply(##M,f))\"\nproof -\n  have \"arity(is_powapply_fm(2,0,1)) = 3\"\n    unfolding is_powapply_fm_def\n    by (simp add: fm_defs nat_simp_union)\n  then\n  have \"\\<forall>f0\\<in>M. strong_replacement(##M, \\<lambda>p z. sats(M,is_powapply_fm(2,0,1) , [p,z,f0]))\"\n    using replacement_ax by simp\n  moreover\n  have \"is_powapply(##M,f0,p,z) \\<longleftrightarrow> sats(M,is_powapply_fm(2,0,1) , [p,z,f0])\"\n    if \"p\\<in>M\" \"z\\<in>M\" \"f0\\<in>M\" for p z f0\n    using that zero_in_M sats_is_powapply_fm[of 2 0 1 \"[p,z,f0]\" M] by simp\n  ultimately\n  have \"\\<forall>f0\\<in>M. strong_replacement(##M, is_powapply(##M,f0))\"\n    unfolding strong_replacement_def univalent_def by simp\n  with \\<open>f\\<in>M\\<close> show ?thesis by simp\nqed\n\n\n(*\"PHrank(M,f,y,z) \\<equiv> M(z) \\<and> (\\<exists>fy[M]. fun_apply(M,f,y,fy) \\<and> successor(M,fy,z))\"*)\ndefinition\n  PHrank_fm :: \"[i,i,i] \\<Rightarrow> i\" where\n  \"PHrank_fm(f,y,z) \\<equiv> Exists(And(fun_apply_fm(succ(f),succ(y),0)\n                                 ,succ_fm(0,succ(z))))\"\n\nlemma PHrank_type [TC]:\n  \"\\<lbrakk> x \\<in> nat; y \\<in> nat; z \\<in> nat \\<rbrakk> \\<Longrightarrow> PHrank_fm(x,y,z) \\<in> formula\"\n  by (simp add:PHrank_fm_def)\n\n\nlemma (in M_ZF_trans) sats_PHrank_fm [simp]:\n  \"\\<lbrakk> x \\<in> nat; y \\<in> nat; z \\<in> nat;  env \\<in> list(M) \\<rbrakk> \n    \\<Longrightarrow> sats(M,PHrank_fm(x,y,z),env) \\<longleftrightarrow>\n        PHrank(##M,nth(x,env),nth(y,env),nth(z,env))\"\n  using zero_in_M Internalizations.nth_closed by (simp add: PHrank_def PHrank_fm_def)\n\n\nlemma (in M_ZF_trans) phrank_repl :\n  assumes\n    \"f\\<in>M\"\n  shows\n    \"strong_replacement(##M,PHrank(##M,f))\"\nproof -\n  have \"arity(PHrank_fm(2,0,1)) = 3\"\n    unfolding PHrank_fm_def\n    by (simp add: fm_defs nat_simp_union)\n  then\n  have \"\\<forall>f0\\<in>M. strong_replacement(##M, \\<lambda>p z. sats(M,PHrank_fm(2,0,1) , [p,z,f0]))\"\n    using replacement_ax by simp\n  then\n  have \"\\<forall>f0\\<in>M. strong_replacement(##M, PHrank(##M,f0))\"\n    unfolding strong_replacement_def univalent_def by simp\n  with \\<open>f\\<in>M\\<close> show ?thesis by simp\nqed\n\n\n(*\"is_Hrank(M,x,f,hc) \\<equiv> (\\<exists>R[M]. big_union(M,R,hc) \\<and>is_Replace(M,x,PHrank(M,f),R)) \"*)\ndefinition\n  is_Hrank_fm :: \"[i,i,i] \\<Rightarrow> i\" where\n  \"is_Hrank_fm(x,f,hc) \\<equiv> Exists(And(big_union_fm(0,succ(hc)),\n                                Replace_fm(succ(x),PHrank_fm(succ(succ(succ(f))),0,1),0)))\"\n\nlemma is_Hrank_type [TC]:\n  \"\\<lbrakk> x \\<in> nat; y \\<in> nat; z \\<in> nat \\<rbrakk> \\<Longrightarrow> is_Hrank_fm(x,y,z) \\<in> formula\"\n  by (simp add:is_Hrank_fm_def)\n\nlemma (in M_ZF_trans) sats_is_Hrank_fm [simp]:\n  \"\\<lbrakk> x \\<in> nat; y \\<in> nat; z \\<in> nat; env \\<in> list(M)\\<rbrakk>\n    \\<Longrightarrow> sats(M,is_Hrank_fm(x,y,z),env) \\<longleftrightarrow>\n        is_Hrank(##M,nth(x,env),nth(y,env),nth(z,env))\"\n  using zero_in_M is_Hrank_def is_Hrank_fm_def sats_Replace_fm\n  by simp\n\n(* M(x) \\<Longrightarrow> wfrec_replacement(M,is_Hrank(M),rrank(x)) *)\nlemma (in M_ZF_trans) wfrec_rank :\n  assumes\n    \"X\\<in>M\"\n  shows\n    \"wfrec_replacement(##M,is_Hrank(##M),rrank(X))\"\nproof -\n  have\n    \"is_Hrank(##M,a2, a1, a0) \\<longleftrightarrow>\n             sats(M, is_Hrank_fm(2,1,0), [a0,a1,a2,a3,a4,y,x,z,rrank(X)])\"\n    if \"a4\\<in>M\" \"a3\\<in>M\" \"a2\\<in>M\" \"a1\\<in>M\" \"a0\\<in>M\" \"y\\<in>M\" \"x\\<in>M\" \"z\\<in>M\" for a4 a3 a2 a1 a0 y x z\n    using that rrank_in_M \\<open>X\\<in>M\\<close> by simp\n  then\n  have\n    1:\"sats(M, is_wfrec_fm(is_Hrank_fm(2,1,0),3,1,0),[y,x,z,rrank(X)])\n  \\<longleftrightarrow> is_wfrec(##M, is_Hrank(##M) ,rrank(X), x, y)\"\n    if \"y\\<in>M\" \"x\\<in>M\" \"z\\<in>M\" for y x z\n    using that \\<open>X\\<in>M\\<close> rrank_in_M sats_is_wfrec_fm by simp\n  let\n    ?f=\"Exists(And(pair_fm(1,0,2),is_wfrec_fm(is_Hrank_fm(2,1,0),3,1,0)))\"\n  have satsf:\"sats(M, ?f, [x,z,rrank(X)])\n              \\<longleftrightarrow> (\\<exists>y\\<in>M. pair(##M,x,y,z) & is_wfrec(##M, is_Hrank(##M) , rrank(X), x, y))\"\n    if \"x\\<in>M\" \"z\\<in>M\" for x z\n    using that 1 \\<open>X\\<in>M\\<close> rrank_in_M by (simp del:pair_abs)\n  have \"arity(?f) = 3\"\n    unfolding is_wfrec_fm_def is_recfun_fm_def is_nat_case_fm_def is_Hrank_fm_def PHrank_fm_def\n      restriction_fm_def list_functor_fm_def number1_fm_def cartprod_fm_def\n      sum_fm_def quasinat_fm_def pre_image_fm_def fm_defs\n    by (simp add:nat_simp_union)\n  then\n  have \"strong_replacement(##M,\\<lambda>x z. sats(M,?f,[x,z,rrank(X)]))\"\n    using replacement_ax 1 \\<open>X\\<in>M\\<close> rrank_in_M by simp\n  then\n  have \"strong_replacement(##M,\\<lambda>x z.\n          \\<exists>y\\<in>M. pair(##M,x,y,z) & is_wfrec(##M, is_Hrank(##M) , rrank(X), x, y))\"\n    using repl_sats[of M ?f \"[rrank(X)]\"]  satsf by (simp del:pair_abs)\n  then\n  show ?thesis unfolding wfrec_replacement_def  by simp\nqed\n\n(*\"is_HVfrom(M,A,x,f,h) \\<equiv> \\<exists>U[M]. \\<exists>R[M].  union(M,A,U,h)\n        \\<and> big_union(M,R,U) \\<and> is_Replace(M,x,is_powapply(M,f),R)\"*)\ndefinition\n  is_HVfrom_fm :: \"[i,i,i,i] \\<Rightarrow> i\" where\n  \"is_HVfrom_fm(A,x,f,h) \\<equiv> Exists(Exists(And(union_fm(A #+ 2,1,h #+ 2),\n                            And(big_union_fm(0,1),\n                            Replace_fm(x #+ 2,is_powapply_fm(f #+ 4,0,1),0)))))\"\n\nlemma is_HVfrom_type [TC]:\n  \"\\<lbrakk> A\\<in>nat; x \\<in> nat; f \\<in> nat; h \\<in> nat \\<rbrakk> \\<Longrightarrow> is_HVfrom_fm(A,x,f,h) \\<in> formula\"\n  by (simp add:is_HVfrom_fm_def)\n\nlemma sats_is_HVfrom_fm :\n  \"\\<lbrakk> a\\<in>nat; x \\<in> nat; f \\<in> nat; h \\<in> nat; env \\<in> list(A); 0\\<in>A\\<rbrakk>\n    \\<Longrightarrow> sats(A,is_HVfrom_fm(a,x,f,h),env) \\<longleftrightarrow>\n        is_HVfrom(##A,nth(a,env),nth(x,env),nth(f,env),nth(h,env))\"\n  using is_HVfrom_def is_HVfrom_fm_def sats_Replace_fm[OF sats_is_powapply_fm]\n  by simp\n\nlemma is_HVfrom_iff_sats:\n  assumes\n    \"nth(a,env) = aa\" \"nth(x,env) = xx\" \"nth(f,env) = ff\" \"nth(h,env) = hh\"\n    \"a\\<in>nat\" \"x\\<in>nat\" \"f\\<in>nat\" \"h\\<in>nat\" \"env\\<in>list(A)\" \"0\\<in>A\"\n  shows\n    \"is_HVfrom(##A,aa,xx,ff,hh) \\<longleftrightarrow> sats(A, is_HVfrom_fm(a,x,f,h), env)\"\n  using assms sats_is_HVfrom_fm by simp\n\n(* FIX US *)\nschematic_goal sats_is_Vset_fm_auto:\n  assumes\n    \"i\\<in>nat\" \"v\\<in>nat\" \"env\\<in>list(A)\" \"0\\<in>A\"\n    \"i < length(env)\" \"v < length(env)\"\n  shows\n    \"is_Vset(##A,nth(i, env),nth(v, env))\n    \\<longleftrightarrow> sats(A,?ivs_fm(i,v),env)\"\n  unfolding is_Vset_def is_Vfrom_def\n  by (insert assms; (rule sep_rules is_HVfrom_iff_sats is_transrec_iff_sats | simp)+)\n\nschematic_goal is_Vset_iff_sats:\n  assumes\n    \"nth(i,env) = ii\" \"nth(v,env) = vv\"\n    \"i\\<in>nat\" \"v\\<in>nat\" \"env\\<in>list(A)\" \"0\\<in>A\"\n    \"i < length(env)\" \"v < length(env)\"\n  shows\n    \"is_Vset(##A,ii,vv) \\<longleftrightarrow> sats(A, ?ivs_fm(i,v), env)\"\n  unfolding \\<open>nth(i,env) = ii\\<close>[symmetric] \\<open>nth(v,env) = vv\\<close>[symmetric]\n  by (rule sats_is_Vset_fm_auto(1); simp add:assms)\n\n\nlemma (in M_ZF_trans) memrel_eclose_sing :\n  \"a\\<in>M \\<Longrightarrow> \\<exists>sa\\<in>M. \\<exists>esa\\<in>M. \\<exists>mesa\\<in>M.\n       upair(##M,a,a,sa) & is_eclose(##M,sa,esa) & membership(##M,esa,mesa)\"\n  using upair_ax eclose_closed Memrel_closed unfolding upair_ax_def\n  by (simp del:upair_abs)\n\n\nlemma (in M_ZF_trans) trans_repl_HVFrom :\n  assumes\n    \"A\\<in>M\" \"i\\<in>M\"\n  shows\n    \"transrec_replacement(##M,is_HVfrom(##M,A),i)\"\nproof -\n  { fix mesa\n    assume \"mesa\\<in>M\"\n    have\n      0:\"is_HVfrom(##M,A,a2, a1, a0) \\<longleftrightarrow>\n      sats(M, is_HVfrom_fm(8,2,1,0), [a0,a1,a2,a3,a4,y,x,z,A,mesa])\"\n      if \"a4\\<in>M\" \"a3\\<in>M\" \"a2\\<in>M\" \"a1\\<in>M\" \"a0\\<in>M\" \"y\\<in>M\" \"x\\<in>M\" \"z\\<in>M\" for a4 a3 a2 a1 a0 y x z\n      using that zero_in_M sats_is_HVfrom_fm \\<open>mesa\\<in>M\\<close> \\<open>A\\<in>M\\<close> by simp\n    have\n      1:\"sats(M, is_wfrec_fm(is_HVfrom_fm(8,2,1,0),4,1,0),[y,x,z,A,mesa])\n        \\<longleftrightarrow> is_wfrec(##M, is_HVfrom(##M,A),mesa, x, y)\"\n      if \"y\\<in>M\" \"x\\<in>M\" \"z\\<in>M\" for y x z\n      using that \\<open>A\\<in>M\\<close> \\<open>mesa\\<in>M\\<close> sats_is_wfrec_fm[OF 0] by simp\n    let\n      ?f=\"Exists(And(pair_fm(1,0,2),is_wfrec_fm(is_HVfrom_fm(8,2,1,0),4,1,0)))\"\n    have satsf:\"sats(M, ?f, [x,z,A,mesa])\n              \\<longleftrightarrow> (\\<exists>y\\<in>M. pair(##M,x,y,z) & is_wfrec(##M, is_HVfrom(##M,A) , mesa, x, y))\"\n      if \"x\\<in>M\" \"z\\<in>M\" for x z\n      using that 1 \\<open>A\\<in>M\\<close> \\<open>mesa\\<in>M\\<close> by (simp del:pair_abs)\n    have \"arity(?f) = 4\"\n      unfolding is_HVfrom_fm_def is_wfrec_fm_def is_recfun_fm_def is_nat_case_fm_def\n        restriction_fm_def list_functor_fm_def number1_fm_def cartprod_fm_def\n        is_powapply_fm_def sum_fm_def quasinat_fm_def pre_image_fm_def fm_defs\n      by (simp add:nat_simp_union)\n    then\n    have \"strong_replacement(##M,\\<lambda>x z. sats(M,?f,[x,z,A,mesa]))\"\n      using replacement_ax 1 \\<open>A\\<in>M\\<close> \\<open>mesa\\<in>M\\<close> by simp\n    then\n    have \"strong_replacement(##M,\\<lambda>x z.\n          \\<exists>y\\<in>M. pair(##M,x,y,z) & is_wfrec(##M, is_HVfrom(##M,A) , mesa, x, y))\"\n      using repl_sats[of M ?f \"[A,mesa]\"]  satsf by (simp del:pair_abs)\n    then\n    have \"wfrec_replacement(##M,is_HVfrom(##M,A),mesa)\"\n      unfolding wfrec_replacement_def  by simp\n  }\n  then show ?thesis unfolding transrec_replacement_def\n    using \\<open>i\\<in>M\\<close> memrel_eclose_sing by simp\nqed\n\n\nlemma (in M_ZF_trans) meclose_pow : \"M_eclose_pow(##M)\"\n  using meclose power_ax powapply_repl phrank_repl trans_repl_HVFrom wfrec_rank\n  by unfold_locales auto\n\nsublocale M_ZF_trans \\<subseteq> M_eclose_pow \"##M\"\n  by (rule meclose_pow)\n\nlemma (in M_ZF_trans) repl_gen :\n  assumes\n    f_abs: \"\\<And>x y. \\<lbrakk> x\\<in>M; y\\<in>M \\<rbrakk> \\<Longrightarrow> is_F(##M,x,y) \\<longleftrightarrow> y = f(x)\"\n    and\n    f_sats: \"\\<And>x y. \\<lbrakk>x\\<in>M ; y\\<in>M \\<rbrakk> \\<Longrightarrow>\n             sats(M,f_fm,Cons(x,Cons(y,env))) \\<longleftrightarrow> is_F(##M,x,y)\"\n    and\n    f_form: \"f_fm \\<in> formula\"\n    and\n    f_arty: \"arity(f_fm) = 2\"\n    and\n    \"env\\<in>list(M)\"\n  shows\n    \"strong_replacement(##M, \\<lambda>x y. y = f(x))\"\nproof -\n  have \"sats(M,f_fm,[x,y]@env) \\<longleftrightarrow> is_F(##M,x,y)\" if \"x\\<in>M\" \"y\\<in>M\" for x y\n    using that f_sats[of x y] by simp\n  moreover\n  from f_form f_arty\n  have \"strong_replacement(##M, \\<lambda>x y. sats(M,f_fm,[x,y]@env))\"\n    using \\<open>env\\<in>list(M)\\<close> replacement_ax by simp\n  ultimately\n  have \"strong_replacement(##M, is_F(##M))\"\n    using strong_replacement_cong[of \"##M\" \"\\<lambda>x y. sats(M,f_fm,[x,y]@env)\" \"is_F(##M)\"] by simp\n  with f_abs show ?thesis\n    using strong_replacement_cong[of \"##M\" \"is_F(##M)\" \"\\<lambda>x y. y = f(x)\"] by simp\nqed\n\n(* Proof Scheme for instances of separation *)\nlemma (in M_ZF_trans) sep_in_M :\n  assumes\n    \"\\<phi> \\<in> formula\" \"env\\<in>list(M)\"\n    \"arity(\\<phi>) \\<le> 1 #+ length(env)\" \"A\\<in>M\" and\n    satsQ: \"\\<And>x. x\\<in>M \\<Longrightarrow> sats(M,\\<phi>,[x]@env) \\<longleftrightarrow> Q(x)\"\n  shows\n    \"{y\\<in>A . Q(y)}\\<in>M\"\nproof -\n  have \"separation(##M,\\<lambda>x. sats(M,\\<phi>,[x] @ env))\"\n    using assms separation_ax by simp\n  then show ?thesis using\n      \\<open>A\\<in>M\\<close> satsQ trans_M\n      separation_cong[of \"##M\" \"\\<lambda>y. sats(M,\\<phi>,[y]@env)\" \"Q\"]\n      separation_closed  by simp\nqed\n\nend", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Forcing/Interface.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5506073655352404, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.2860522664194274}}
{"text": "(*  Title:      Jinja/Compiler/Correctness2.thy\n    Author:     Tobias Nipkow\n    Copyright   TUM 2003\n*)\n\nsection \\<open>Correctness of Stage 2\\<close>\n\ntheory Correctness2\nimports \"HOL-Library.Sublist\" Compiler2\nbegin\n\n(*<*)hide_const (open) Throw(*>*)\n\nsubsection\\<open>Instruction sequences\\<close>\n\ntext\\<open>How to select individual instructions and subsequences of\ninstructions from a program given the class, method and program\ncounter.\\<close>\n\ndefinition before :: \"jvm_prog \\<Rightarrow> cname \\<Rightarrow> mname \\<Rightarrow> nat \\<Rightarrow> instr list \\<Rightarrow> bool\"\n   (\"(_,_,_,_/ \\<rhd> _)\" [51,0,0,0,51] 50) where\n \"P,C,M,pc \\<rhd> is \\<longleftrightarrow> prefix is (drop pc (instrs_of P C M))\"\n\ndefinition at :: \"jvm_prog \\<Rightarrow> cname \\<Rightarrow> mname \\<Rightarrow> nat \\<Rightarrow> instr \\<Rightarrow> bool\"\n   (\"(_,_,_,_/ \\<triangleright> _)\" [51,0,0,0,51] 50) where\n \"P,C,M,pc \\<triangleright> i \\<longleftrightarrow> (\\<exists>is. drop pc (instrs_of P C M) = i#is)\"\n\n\n\n\nlemma [simp]: \"P,C,M,pc \\<rhd> (i#is) = (P,C,M,pc \\<triangleright> i \\<and> P,C,M,pc + 1 \\<rhd> is)\"\n(*<*)by(fastforce simp add:before_def at_def prefix_def drop_Suc drop_tl)(*>*)\n\n(*<*)\ndeclare drop_drop[simp del]\n(*>*)\n\n\nlemma [simp]: \"P,C,M,pc \\<rhd> (is\\<^sub>1 @ is\\<^sub>2) = (P,C,M,pc \\<rhd> is\\<^sub>1 \\<and> P,C,M,pc + size is\\<^sub>1 \\<rhd> is\\<^sub>2)\"\n(*<*)\napply(simp add:before_def prefix_def)\napply(subst add.commute)\napply(simp add: drop_drop[symmetric])\napply fastforce\ndone\n(*>*)\n\n(*<*)\ndeclare drop_drop[simp]\n(*>*)\n\n\nlemma [simp]: \"P,C,M,pc \\<triangleright> i \\<Longrightarrow> instrs_of P C M ! pc = i\"\n(*<*)by(clarsimp simp add:at_def strict_prefix_def nth_via_drop)(*>*)\n\n\nlemma beforeM:\n  \"P \\<turnstile> C sees M: Ts\\<rightarrow>T = body in D \\<Longrightarrow>\n  compP\\<^sub>2 P,D,M,0 \\<rhd> compE\\<^sub>2 body @ [Return]\"\n(*<*)\napply(drule sees_method_idemp)\napply(simp add:before_def compP\\<^sub>2_def compMb\\<^sub>2_def)\ndone\n(*>*)\n\ntext\\<open>This lemma executes a single instruction by rewriting:\\<close>\n\nlemma [simp]:\n  \"P,C,M,pc \\<triangleright> instr \\<Longrightarrow>\n  (P \\<turnstile> (None, h, (vs,ls,C,M,pc) # frs) -jvm\\<rightarrow> \\<sigma>') =\n  ((None, h, (vs,ls,C,M,pc) # frs) = \\<sigma>' \\<or>\n   (\\<exists>\\<sigma>. exec(P,(None, h, (vs,ls,C,M,pc) # frs)) = Some \\<sigma> \\<and> P \\<turnstile> \\<sigma> -jvm\\<rightarrow> \\<sigma>'))\"\n(*<*)\napply(simp only: exec_all_def)\napply(blast intro: converse_rtranclE converse_rtrancl_into_rtrancl)\ndone\n(*>*)\n\n\nsubsection\\<open>Exception tables\\<close>\n\ndefinition pcs :: \"ex_table \\<Rightarrow> nat set\"\nwhere\n  \"pcs xt  \\<equiv>  \\<Union>(f,t,C,h,d) \\<in> set xt. {f ..< t}\"\n\nlemma pcs_subset:\nshows \"\\<And>pc d. pcs(compxE\\<^sub>2 e pc d) \\<subseteq> {pc..<pc+size(compE\\<^sub>2 e)}\"\nand \"\\<And>pc d. pcs(compxEs\\<^sub>2 es pc d) \\<subseteq> {pc..<pc+size(compEs\\<^sub>2 es)}\"\n(*<*)\napply(induct e and es rule: compxE\\<^sub>2.induct compxEs\\<^sub>2.induct)\napply (simp_all add:pcs_def)\napply (fastforce split:bop.splits)+\ndone\n(*>*)\n\n\nlemma [simp]: \"pcs [] = {}\"\n(*<*)by(simp add:pcs_def)(*>*)\n\n\nlemma [simp]: \"pcs (x#xt) = {fst x ..< fst(snd x)} \\<union> pcs xt\"\n(*<*)by(auto simp add: pcs_def)(*>*)\n\n\nlemma [simp]: \"pcs(xt\\<^sub>1 @ xt\\<^sub>2) = pcs xt\\<^sub>1 \\<union> pcs xt\\<^sub>2\"\n(*<*)by(simp add:pcs_def)(*>*)\n\n\nlemma [simp]: \"pc < pc\\<^sub>0 \\<or> pc\\<^sub>0+size(compE\\<^sub>2 e) \\<le> pc \\<Longrightarrow> pc \\<notin> pcs(compxE\\<^sub>2 e pc\\<^sub>0 d)\"\n(*<*)using pcs_subset by fastforce(*>*)\n\n\nlemma [simp]: \"pc < pc\\<^sub>0 \\<or> pc\\<^sub>0+size(compEs\\<^sub>2 es) \\<le> pc \\<Longrightarrow> pc \\<notin> pcs(compxEs\\<^sub>2 es pc\\<^sub>0 d)\"\n(*<*)using pcs_subset by fastforce(*>*)\n\n\nlemma [simp]: \"pc\\<^sub>1 + size(compE\\<^sub>2 e\\<^sub>1) \\<le> pc\\<^sub>2 \\<Longrightarrow> pcs(compxE\\<^sub>2 e\\<^sub>1 pc\\<^sub>1 d\\<^sub>1) \\<inter> pcs(compxE\\<^sub>2 e\\<^sub>2 pc\\<^sub>2 d\\<^sub>2) = {}\"\n(*<*)using pcs_subset by fastforce(*>*)\n\n\nlemma [simp]: \"pc\\<^sub>1 + size(compE\\<^sub>2 e) \\<le> pc\\<^sub>2 \\<Longrightarrow> pcs(compxE\\<^sub>2 e pc\\<^sub>1 d\\<^sub>1) \\<inter> pcs(compxEs\\<^sub>2 es pc\\<^sub>2 d\\<^sub>2) = {}\"\n(*<*)using pcs_subset by fastforce(*>*)\n\n\nlemma [simp]:\n \"pc \\<notin> pcs xt\\<^sub>0 \\<Longrightarrow> match_ex_table P C pc (xt\\<^sub>0 @ xt\\<^sub>1) = match_ex_table P C pc xt\\<^sub>1\"\n(*<*)by (induct xt\\<^sub>0) (auto simp: matches_ex_entry_def)(*>*)\n\n\nlemma [simp]: \"\\<lbrakk> x \\<in> set xt; pc \\<notin> pcs xt \\<rbrakk> \\<Longrightarrow> \\<not> matches_ex_entry P D pc x\"\n(*<*)by(auto simp:matches_ex_entry_def pcs_def)(*>*)\n\n\nlemma [simp]:\nassumes xe: \"xe \\<in> set(compxE\\<^sub>2 e pc d)\" and outside: \"pc' < pc \\<or> pc+size(compE\\<^sub>2 e) \\<le> pc'\"\nshows \"\\<not> matches_ex_entry P C pc' xe\"\n(*<*)\nproof\n  assume \"matches_ex_entry P C pc' xe\"\n  with xe have \"pc' \\<in> pcs(compxE\\<^sub>2 e pc d)\"\n    by(force simp add:matches_ex_entry_def pcs_def)\n  with outside show False by simp\nqed\n(*>*)\n\n\nlemma [simp]:\nassumes xe: \"xe \\<in> set(compxEs\\<^sub>2 es pc d)\" and outside: \"pc' < pc \\<or> pc+size(compEs\\<^sub>2 es) \\<le> pc'\"\nshows \"\\<not> matches_ex_entry P C pc' xe\"\n(*<*)\nproof\n  assume \"matches_ex_entry P C pc' xe\"\n  with xe have \"pc' \\<in> pcs(compxEs\\<^sub>2 es pc d)\"\n    by(force simp add:matches_ex_entry_def pcs_def)\n  with outside show False by simp\nqed\n(*>*)\n\n\nlemma match_ex_table_app[simp]:\n  \"\\<forall>xte \\<in> set xt\\<^sub>1. \\<not> matches_ex_entry P D pc xte \\<Longrightarrow>\n  match_ex_table P D pc (xt\\<^sub>1 @ xt) = match_ex_table P D pc xt\"\n(*<*)by(induct xt\\<^sub>1) simp_all(*>*)\n\n\nlemma [simp]:\n  \"\\<forall>x \\<in> set xtab. \\<not> matches_ex_entry P C pc x \\<Longrightarrow>\n  match_ex_table P C pc xtab = None\"\n(*<*)using match_ex_table_app[where ?xt = \"[]\"] by fastforce(*>*)\n\n\nlemma match_ex_entry:\n  \"matches_ex_entry P C pc (start, end, catch_type, handler) =\n  (start \\<le> pc \\<and> pc < end \\<and>  P \\<turnstile> C \\<preceq>\\<^sup>* catch_type)\"\n(*<*)by(simp add:matches_ex_entry_def)(*>*)\n\n\ndefinition caught :: \"jvm_prog \\<Rightarrow> pc \\<Rightarrow> heap \\<Rightarrow> addr \\<Rightarrow> ex_table \\<Rightarrow> bool\" where\n  \"caught P pc h a xt \\<longleftrightarrow>\n  (\\<exists>entry \\<in> set xt. matches_ex_entry P (cname_of h a) pc entry)\"\n\ndefinition beforex :: \"jvm_prog \\<Rightarrow> cname \\<Rightarrow> mname \\<Rightarrow> ex_table \\<Rightarrow> nat set \\<Rightarrow> nat \\<Rightarrow> bool\"\n              (\"(2_,/_,/_ \\<rhd>/ _ /'/ _,/_)\" [51,0,0,0,0,51] 50) where\n  \"P,C,M \\<rhd> xt / I,d \\<longleftrightarrow>\n  (\\<exists>xt\\<^sub>0 xt\\<^sub>1. ex_table_of P C M = xt\\<^sub>0 @ xt @ xt\\<^sub>1 \\<and> pcs xt\\<^sub>0 \\<inter> I = {} \\<and> pcs xt \\<subseteq> I \\<and>\n    (\\<forall>pc \\<in> I. \\<forall>C pc' d'. match_ex_table P C pc xt\\<^sub>1 = \\<lfloor>(pc',d')\\<rfloor> \\<longrightarrow> d' \\<le> d))\"\n\ndefinition dummyx :: \"jvm_prog \\<Rightarrow> cname \\<Rightarrow> mname \\<Rightarrow> ex_table \\<Rightarrow> nat set \\<Rightarrow> nat \\<Rightarrow> bool\"  (\"(2_,_,_ \\<triangleright>/ _ '/_,_)\" [51,0,0,0,0,51] 50) where\n  \"P,C,M \\<triangleright> xt/I,d \\<longleftrightarrow> P,C,M \\<rhd> xt/I,d\"\n\nlemma beforexD1: \"P,C,M \\<rhd> xt / I,d \\<Longrightarrow> pcs xt \\<subseteq> I\"\n(*<*)by(auto simp add:beforex_def)(*>*)\n\n\nlemma beforex_mono: \"\\<lbrakk> P,C,M \\<rhd> xt/I,d'; d' \\<le> d \\<rbrakk> \\<Longrightarrow> P,C,M \\<rhd> xt/I,d\"\n(*<*)by(fastforce simp:beforex_def)(*>*)\n\n\nlemma [simp]: \"P,C,M \\<rhd> xt/I,d \\<Longrightarrow> P,C,M \\<rhd> xt/I,Suc d\"\n(*<*)by(fastforce intro:beforex_mono)(*>*)\n\n\nlemma beforex_append[simp]:\n  \"pcs xt\\<^sub>1 \\<inter> pcs xt\\<^sub>2 = {} \\<Longrightarrow>\n  P,C,M \\<rhd> xt\\<^sub>1 @ xt\\<^sub>2/I,d =\n  (P,C,M \\<rhd> xt\\<^sub>1/I-pcs xt\\<^sub>2,d  \\<and>  P,C,M \\<rhd> xt\\<^sub>2/I-pcs xt\\<^sub>1,d \\<and> P,C,M \\<triangleright> xt\\<^sub>1@xt\\<^sub>2/I,d)\"\n(*<*)\napply(rule iffI)\n prefer 2\n apply(simp add:dummyx_def)\napply(auto simp add: beforex_def dummyx_def)\n apply(rule_tac x = xt\\<^sub>0 in exI)\n apply auto\napply(rule_tac x = \"xt\\<^sub>0@xt\\<^sub>1\" in exI)\napply auto\ndone\n(*>*)\n\n\nlemma beforex_appendD1:\n  \"\\<lbrakk> P,C,M \\<rhd> xt\\<^sub>1 @ xt\\<^sub>2 @ [(f,t,D,h,d)] / I,d;\n    pcs xt\\<^sub>1 \\<subseteq> J; J \\<subseteq> I; J \\<inter> pcs xt\\<^sub>2 = {} \\<rbrakk>\n  \\<Longrightarrow> P,C,M \\<rhd> xt\\<^sub>1 / J,d\"\n(*<*)\napply(auto simp:beforex_def)\napply(rule exI,rule exI,rule conjI, rule refl)\napply(rule conjI, blast)\napply(auto)\napply(subgoal_tac \"pc \\<notin> pcs xt\\<^sub>2\")\n prefer 2 apply blast\napply (auto split:if_split_asm)\ndone\n(*>*)\n\n\nlemma beforex_appendD2:\n  \"\\<lbrakk> P,C,M \\<rhd> xt\\<^sub>1 @ xt\\<^sub>2 @ [(f,t,D,h,d)] / I,d;\n    pcs xt\\<^sub>2 \\<subseteq> J; J \\<subseteq> I; J \\<inter> pcs xt\\<^sub>1 = {} \\<rbrakk>\n  \\<Longrightarrow> P,C,M \\<rhd> xt\\<^sub>2 / J,d\"\n(*<*)\napply(auto simp:beforex_def)\napply(rule_tac x = \"xt\\<^sub>0 @ xt\\<^sub>1\" in exI)\napply fastforce\ndone\n(*>*)\n\n\nlemma beforexM:\n  \"P \\<turnstile> C sees M: Ts\\<rightarrow>T = body in D \\<Longrightarrow>\n  compP\\<^sub>2 P,D,M \\<rhd> compxE\\<^sub>2 body 0 0/{..<size(compE\\<^sub>2 body)},0\"\n(*<*)\napply(drule sees_method_idemp)\napply(drule sees_method_compP[where f = compMb\\<^sub>2])\napply(simp add:beforex_def compP\\<^sub>2_def compMb\\<^sub>2_def)\napply(rule_tac x = \"[]\" in exI)\nusing pcs_subset apply fastforce\ndone\n(*>*)\n\n\nlemma match_ex_table_SomeD2:\n \"\\<lbrakk> match_ex_table P D pc (ex_table_of P C M) = \\<lfloor>(pc',d')\\<rfloor>;\n    P,C,M \\<rhd> xt/I,d; \\<forall>x \\<in> set xt. \\<not> matches_ex_entry P D pc x; pc \\<in> I \\<rbrakk>\n \\<Longrightarrow> d' \\<le> d\"\n(*<*)\napply(auto simp:beforex_def)\napply(subgoal_tac \"pc \\<notin> pcs xt\\<^sub>0\")\napply auto\ndone\n(*>*)\n\n\nlemma match_ex_table_SomeD1:\n  \"\\<lbrakk> match_ex_table P D pc (ex_table_of P C M) = \\<lfloor>(pc',d')\\<rfloor>;\n     P,C,M \\<rhd> xt / I,d; pc \\<in> I; pc \\<notin> pcs xt \\<rbrakk> \\<Longrightarrow> d' \\<le> d\"\n(*<*)by(auto elim: match_ex_table_SomeD2)(*>*)\n\n\nsubsection\\<open>The correctness proof\\<close>\n\n(*<*)\ndeclare nat_add_distrib[simp] caught_def[simp]\ndeclare fun_upd_apply[simp del]\n(*>*)\n\n\ndefinition\n  handle :: \"jvm_prog \\<Rightarrow> cname \\<Rightarrow> mname \\<Rightarrow> addr \\<Rightarrow> heap \\<Rightarrow> val list \\<Rightarrow> val list \\<Rightarrow> nat \\<Rightarrow> frame list\n                \\<Rightarrow> jvm_state\" where\n  \"handle P C M a h vs ls pc frs = find_handler P a h ((vs,ls,C,M,pc) # frs)\"\n\nlemma handle_Cons:\n \"\\<lbrakk> P,C,M \\<rhd> xt/I,d; d \\<le> size vs; pc \\<in> I;\n    \\<forall>x \\<in> set xt. \\<not> matches_ex_entry P (cname_of h xa) pc x \\<rbrakk> \\<Longrightarrow>\n  handle P C M xa h (v # vs) ls pc frs = handle P C M xa h vs ls pc frs\"\n(*<*)by(auto simp:handle_def Suc_diff_le dest: match_ex_table_SomeD2)(*>*)\n\nlemma handle_append:\n \"\\<lbrakk> P,C,M \\<rhd> xt/I,d; d \\<le> size vs; pc \\<in> I; pc \\<notin> pcs xt \\<rbrakk> \\<Longrightarrow>\n  handle P C M xa h (ws @ vs) ls pc frs = handle P C M xa h vs ls pc frs\"\n(*<*)\napply(auto simp:handle_def)\napply(rename_tac pc' d')\napply(subgoal_tac \"size ws \\<le> length ws + length vs - d'\")\napply(simp add:drop_all)\napply(fastforce dest:match_ex_table_SomeD2 split:nat_diff_split)\ndone\n(*>*)\n\n\nlemma aux_isin[simp]: \"\\<lbrakk> B \\<subseteq> A; a \\<in> B \\<rbrakk> \\<Longrightarrow> a \\<in> A\"\n(*<*)by blast(*>*)\n\n\nlemma fixes P\\<^sub>1 defines [simp]: \"P \\<equiv> compP\\<^sub>2 P\\<^sub>1\"\nshows Jcc:\n  \"P\\<^sub>1 \\<turnstile>\\<^sub>1 \\<langle>e,(h\\<^sub>0,ls\\<^sub>0)\\<rangle> \\<Rightarrow> \\<langle>ef,(h\\<^sub>1,ls\\<^sub>1)\\<rangle> \\<Longrightarrow>\n  (\\<And>C M pc v xa vs frs I.\n     \\<lbrakk> P,C,M,pc \\<rhd> compE\\<^sub>2 e; P,C,M \\<rhd> compxE\\<^sub>2 e pc (size vs)/I,size vs;\n       {pc..<pc+size(compE\\<^sub>2 e)} \\<subseteq> I \\<rbrakk> \\<Longrightarrow>\n     (ef = Val v \\<longrightarrow>\n      P \\<turnstile> (None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs) -jvm\\<rightarrow>\n            (None,h\\<^sub>1,(v#vs,ls\\<^sub>1,C,M,pc+size(compE\\<^sub>2 e))#frs))\n     \\<and>\n     (ef = Throw xa \\<longrightarrow>\n      (\\<exists>pc\\<^sub>1. pc \\<le> pc\\<^sub>1 \\<and> pc\\<^sub>1 < pc + size(compE\\<^sub>2 e) \\<and>\n               \\<not> caught P pc\\<^sub>1 h\\<^sub>1 xa (compxE\\<^sub>2 e pc (size vs)) \\<and>\n               P \\<turnstile> (None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs) -jvm\\<rightarrow> handle P C M xa h\\<^sub>1 vs ls\\<^sub>1 pc\\<^sub>1 frs)))\"\n(*<*)\n  (is \"_ \\<Longrightarrow> (\\<And>C M pc v xa vs frs I.\n                  PROP ?P e h\\<^sub>0 ls\\<^sub>0 ef h\\<^sub>1 ls\\<^sub>1 C M pc v xa vs frs I)\")\n(*>*)\n\nand \"P\\<^sub>1 \\<turnstile>\\<^sub>1 \\<langle>es,(h\\<^sub>0,ls\\<^sub>0)\\<rangle> [\\<Rightarrow>] \\<langle>fs,(h\\<^sub>1,ls\\<^sub>1)\\<rangle> \\<Longrightarrow>\n    (\\<And>C M pc ws xa es' vs frs I.\n      \\<lbrakk> P,C,M,pc \\<rhd> compEs\\<^sub>2 es; P,C,M \\<rhd> compxEs\\<^sub>2 es pc (size vs)/I,size vs;\n       {pc..<pc+size(compEs\\<^sub>2 es)} \\<subseteq> I \\<rbrakk> \\<Longrightarrow>\n      (fs = map Val ws \\<longrightarrow>\n       P \\<turnstile> (None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs) -jvm\\<rightarrow>\n             (None,h\\<^sub>1,(rev ws @ vs,ls\\<^sub>1,C,M,pc+size(compEs\\<^sub>2 es))#frs))\n      \\<and>\n      (fs = map Val ws @ Throw xa # es' \\<longrightarrow>\n       (\\<exists>pc\\<^sub>1. pc \\<le> pc\\<^sub>1 \\<and> pc\\<^sub>1 < pc + size(compEs\\<^sub>2 es) \\<and>\n                \\<not> caught P pc\\<^sub>1 h\\<^sub>1 xa (compxEs\\<^sub>2 es pc (size vs)) \\<and>\n                P \\<turnstile> (None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs) -jvm\\<rightarrow> handle P C M xa h\\<^sub>1 vs ls\\<^sub>1 pc\\<^sub>1 frs)))\"\n(*<*)\n  (is \"_ \\<Longrightarrow> (\\<And>C M pc ws xa es' vs frs I.\n                  PROP ?Ps es h\\<^sub>0 ls\\<^sub>0 fs h\\<^sub>1 ls\\<^sub>1 C M pc ws xa es' vs frs I)\")\nproof (induct rule:eval\\<^sub>1_evals\\<^sub>1_inducts)\n  case New\\<^sub>1 thus ?case by (clarsimp simp add:blank_def fun_eq_iff)\nnext\n  case NewFail\\<^sub>1 thus ?case by(auto simp: handle_def pcs_def)\nnext\n  case (Cast\\<^sub>1 e h\\<^sub>0 ls\\<^sub>0 a h\\<^sub>1 ls\\<^sub>1 D fs C')\n  let ?pc = \"pc + length(compE\\<^sub>2 e)\"\n  have \"P \\<turnstile> (None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs) -jvm\\<rightarrow>\n             (None,h\\<^sub>1,(Addr a#vs,ls\\<^sub>1,C,M,?pc)#frs)\" using Cast\\<^sub>1 by fastforce\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> (None,h\\<^sub>1,(Addr a#vs,ls\\<^sub>1,C,M,?pc+1)#frs)\"\n    using Cast\\<^sub>1 by (auto simp add:cast_ok_def)\n  finally show ?case by auto\nnext\n  case (CastNull\\<^sub>1 e h\\<^sub>0 ls\\<^sub>0 h\\<^sub>1 ls\\<^sub>1 C')\n  let ?pc = \"pc + length(compE\\<^sub>2 e)\"\n  have \"P \\<turnstile> (None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs) -jvm\\<rightarrow>\n            (None,h\\<^sub>1,(Null#vs,ls\\<^sub>1,C,M,?pc)#frs)\"\n    using CastNull\\<^sub>1 by fastforce\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> (None,h\\<^sub>1,(Null#vs,ls\\<^sub>1,C,M,?pc+1)#frs)\"\n    using CastNull\\<^sub>1 by (auto simp add:cast_ok_def)\n  finally show ?case by auto\nnext\n  case (CastFail\\<^sub>1 e h\\<^sub>0 ls\\<^sub>0 a h\\<^sub>1 ls\\<^sub>1 D fs C')\n  let ?pc = \"pc + length(compE\\<^sub>2 e)\"\n  let ?xa = \"addr_of_sys_xcpt ClassCast\"\n  have \"P \\<turnstile> (None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs) -jvm\\<rightarrow>\n             (None,h\\<^sub>1,(Addr a#vs,ls\\<^sub>1,C,M,?pc)#frs)\"\n    using CastFail\\<^sub>1 by fastforce\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> handle P C M ?xa h\\<^sub>1 (Addr a#vs) ls\\<^sub>1 ?pc frs\"\n    using CastFail\\<^sub>1 by (auto simp add:handle_def cast_ok_def)\n  also have \"handle P C M ?xa h\\<^sub>1 (Addr a#vs) ls\\<^sub>1 ?pc frs =\n             handle P C M ?xa h\\<^sub>1 vs ls\\<^sub>1 ?pc frs\"\n    using CastFail\\<^sub>1.prems by(auto simp:handle_Cons)\n  finally have exec: \"P \\<turnstile> (None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs) -jvm\\<rightarrow> \\<dots>\".\n  show ?case (is \"?N \\<and> (?eq \\<longrightarrow> (\\<exists>pc\\<^sub>1. ?H pc\\<^sub>1))\")\n  proof\n    show ?N by simp\n  next\n    have \"?eq \\<longrightarrow> ?H ?pc\" using exec by auto\n    thus \"?eq \\<longrightarrow> (\\<exists>pc\\<^sub>1. ?H pc\\<^sub>1)\" by blast\n  qed\nnext\n  case CastThrow\\<^sub>1 thus ?case by fastforce\nnext\n  case Val\\<^sub>1 thus ?case by simp\nnext\n  case Var\\<^sub>1 thus ?case by auto\nnext\n  case (BinOp\\<^sub>1 e\\<^sub>1 h\\<^sub>0 ls\\<^sub>0 v\\<^sub>1 h\\<^sub>1 ls\\<^sub>1 e\\<^sub>2 v\\<^sub>2 h\\<^sub>2 ls\\<^sub>2 bop w)\n  let ?pc\\<^sub>1 = \"pc + length(compE\\<^sub>2 e\\<^sub>1)\"\n  let ?pc\\<^sub>2 = \"?pc\\<^sub>1 + length(compE\\<^sub>2 e\\<^sub>2)\"\n  have IH\\<^sub>2: \"PROP ?P e\\<^sub>2 h\\<^sub>1 ls\\<^sub>1 (Val v\\<^sub>2) h\\<^sub>2 ls\\<^sub>2 C M ?pc\\<^sub>1 v\\<^sub>2 xa (v\\<^sub>1#vs) frs\n                     (I - pcs(compxE\\<^sub>2 e\\<^sub>1 pc (size vs)))\" by fact\n  have \"P \\<turnstile> (None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs) -jvm\\<rightarrow>\n             (None,h\\<^sub>1,(v\\<^sub>1#vs,ls\\<^sub>1,C,M,?pc\\<^sub>1)#frs)\" using BinOp\\<^sub>1 by fastforce\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> (None,h\\<^sub>2,(v\\<^sub>2#v\\<^sub>1#vs,ls\\<^sub>2,C,M,?pc\\<^sub>2)#frs)\"\n    using BinOp\\<^sub>1.prems IH\\<^sub>2 by fastforce\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> (None,h\\<^sub>2,(w#vs,ls\\<^sub>2,C,M,?pc\\<^sub>2+1)#frs)\"\n    using BinOp\\<^sub>1 by(cases bop) auto\n  finally show ?case by (auto split: bop.splits simp:add.assoc)\nnext\n  case BinOpThrow\\<^sub>1\\<^sub>1 thus ?case by(fastforce)\nnext\n  case (BinOpThrow\\<^sub>2\\<^sub>1 e\\<^sub>1 h\\<^sub>0 ls\\<^sub>0 v\\<^sub>1 h\\<^sub>1 ls\\<^sub>1 e\\<^sub>2 e h\\<^sub>2 ls\\<^sub>2 bop)\n  let ?pc = \"pc + length(compE\\<^sub>2 e\\<^sub>1)\"\n  let ?\\<sigma>\\<^sub>1 = \"(None,h\\<^sub>1,(v\\<^sub>1#vs,ls\\<^sub>1,C,M,?pc)#frs)\"\n  have 1: \"P \\<turnstile> (None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs) -jvm\\<rightarrow> ?\\<sigma>\\<^sub>1\"\n    using BinOpThrow\\<^sub>2\\<^sub>1 by fastforce\n  show ?case (is \"?N \\<and> (?eq \\<longrightarrow> (\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2))\")\n  proof\n    show ?N by simp\n  next\n    { assume ?eq\n      moreover\n      have \"PROP ?P e\\<^sub>2 h\\<^sub>1 ls\\<^sub>1 (throw e) h\\<^sub>2 ls\\<^sub>2 C M ?pc v xa (v\\<^sub>1#vs) frs\n                     (I - pcs(compxE\\<^sub>2 e\\<^sub>1 pc (size vs)))\" by fact\n      ultimately obtain pc\\<^sub>2 where\n        pc\\<^sub>2: \"?pc \\<le> pc\\<^sub>2 \\<and> pc\\<^sub>2 < ?pc + size(compE\\<^sub>2 e\\<^sub>2) \\<and>\n              \\<not> caught P pc\\<^sub>2 h\\<^sub>2 xa (compxE\\<^sub>2 e\\<^sub>2 ?pc (size vs + 1))\" and\n        2: \"P \\<turnstile> ?\\<sigma>\\<^sub>1 -jvm\\<rightarrow> handle P C M xa h\\<^sub>2 (v\\<^sub>1#vs) ls\\<^sub>2 pc\\<^sub>2 frs\"\n        using BinOpThrow\\<^sub>2\\<^sub>1.prems by fastforce\n      have 3: \"P \\<turnstile> ?\\<sigma>\\<^sub>1 -jvm\\<rightarrow> handle P C M xa h\\<^sub>2 vs ls\\<^sub>2 pc\\<^sub>2 frs\"\n        using 2 BinOpThrow\\<^sub>2\\<^sub>1.prems pc\\<^sub>2 by(auto simp:handle_Cons)\n      have \"?H pc\\<^sub>2\" using pc\\<^sub>2 jvm_trans[OF 1 3] by auto\n      hence \"\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2\" by iprover\n    }\n    thus \"?eq \\<longrightarrow> (\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2)\" by iprover\n  qed\nnext\n  case (FAcc\\<^sub>1 e h\\<^sub>0 ls\\<^sub>0 a h\\<^sub>1 ls\\<^sub>1 C fs F D w)\n  let ?pc = \"pc + length(compE\\<^sub>2 e)\"\n  have \"P \\<turnstile> (None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs) -jvm\\<rightarrow>\n             (None,h\\<^sub>1,(Addr a#vs,ls\\<^sub>1,C,M,?pc)#frs)\" using FAcc\\<^sub>1 by fastforce\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> (None,h\\<^sub>1,(w#vs,ls\\<^sub>1,C,M,?pc+1)#frs)\"\n    using FAcc\\<^sub>1 by auto\n  finally show ?case by auto\nnext\n  case (FAccNull\\<^sub>1 e h\\<^sub>0 ls\\<^sub>0 h\\<^sub>1 ls\\<^sub>1 F D)\n  let ?pc = \"pc + length(compE\\<^sub>2 e)\"\n  let ?xa = \"addr_of_sys_xcpt NullPointer\"\n  have \"P \\<turnstile> (None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs) -jvm\\<rightarrow>\n             (None,h\\<^sub>1,(Null#vs,ls\\<^sub>1,C,M,?pc)#frs)\" using FAccNull\\<^sub>1 by fastforce\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> handle P C M ?xa h\\<^sub>1 (Null#vs) ls\\<^sub>1 ?pc frs\"\n    using FAccNull\\<^sub>1.prems\n    by(fastforce simp:split_beta handle_def simp del: split_paired_Ex)\n  also have \"handle P C M ?xa h\\<^sub>1 (Null#vs) ls\\<^sub>1 ?pc frs =\n             handle P C M ?xa h\\<^sub>1 vs ls\\<^sub>1 ?pc frs\"\n    using FAccNull\\<^sub>1.prems by(auto simp add:handle_Cons)\n  finally show ?case by (auto intro: exI[where x = ?pc])\nnext\n  case FAccThrow\\<^sub>1 thus ?case by fastforce\nnext\n  case (LAss\\<^sub>1 e h\\<^sub>0 ls\\<^sub>0 w h\\<^sub>1 ls\\<^sub>1 i ls\\<^sub>2)\n  let ?pc = \"pc + length(compE\\<^sub>2 e)\"\n  have \"P \\<turnstile> (None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs) -jvm\\<rightarrow>\n             (None,h\\<^sub>1,(w#vs,ls\\<^sub>1,C,M,?pc)#frs)\" using LAss\\<^sub>1 by fastforce\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> (None,h\\<^sub>1,(Unit#vs,ls\\<^sub>2,C,M,?pc+2)#frs)\"\n    using LAss\\<^sub>1 by auto\n  finally show ?case using LAss\\<^sub>1 by auto\nnext\n  case LAssThrow\\<^sub>1 thus ?case by fastforce\nnext\n  case (FAss\\<^sub>1 e\\<^sub>1 h\\<^sub>0 ls\\<^sub>0 a h\\<^sub>1 ls\\<^sub>1 e\\<^sub>2 w h\\<^sub>2 ls\\<^sub>2 C fs fs' F D h\\<^sub>2')\n  let ?pc\\<^sub>1 = \"pc + length(compE\\<^sub>2 e\\<^sub>1)\"\n  let ?pc\\<^sub>2 = \"?pc\\<^sub>1 + length(compE\\<^sub>2 e\\<^sub>2)\"\n  have IH\\<^sub>2: \"PROP ?P e\\<^sub>2 h\\<^sub>1 ls\\<^sub>1 (Val w) h\\<^sub>2 ls\\<^sub>2 C M ?pc\\<^sub>1 w xa (Addr a#vs) frs\n                     (I - pcs(compxE\\<^sub>2 e\\<^sub>1 pc (size vs)))\" by fact\n  have \"P \\<turnstile> (None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs) -jvm\\<rightarrow>\n             (None,h\\<^sub>1,(Addr a#vs,ls\\<^sub>1,C,M,?pc\\<^sub>1)#frs)\" using FAss\\<^sub>1 by fastforce\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> (None,h\\<^sub>2,(w#Addr a#vs,ls\\<^sub>2,C,M,?pc\\<^sub>2)#frs)\"\n    using FAss\\<^sub>1.prems IH\\<^sub>2 by fastforce\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> (None,h\\<^sub>2',(Unit#vs,ls\\<^sub>2,C,M,?pc\\<^sub>2+2)#frs)\"\n    using FAss\\<^sub>1 by auto\n  finally show ?case using FAss\\<^sub>1 by (auto simp:add.assoc)\nnext\n  case (FAssNull\\<^sub>1 e\\<^sub>1 h\\<^sub>0 ls\\<^sub>0 h\\<^sub>1 ls\\<^sub>1 e\\<^sub>2 w h\\<^sub>2 ls\\<^sub>2 F D)\n  let ?pc\\<^sub>1 = \"pc + length(compE\\<^sub>2 e\\<^sub>1)\"\n  let ?pc\\<^sub>2 = \"?pc\\<^sub>1 + length(compE\\<^sub>2 e\\<^sub>2)\"\n  let ?xa = \"addr_of_sys_xcpt NullPointer\"\n  have IH\\<^sub>2: \"PROP ?P e\\<^sub>2 h\\<^sub>1 ls\\<^sub>1 (Val w) h\\<^sub>2 ls\\<^sub>2 C M ?pc\\<^sub>1 w xa (Null#vs) frs\n                     (I - pcs(compxE\\<^sub>2 e\\<^sub>1 pc (size vs)))\" by fact\n  have \"P \\<turnstile> (None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs) -jvm\\<rightarrow>\n             (None,h\\<^sub>1,(Null#vs,ls\\<^sub>1,C,M,?pc\\<^sub>1)#frs)\" using FAssNull\\<^sub>1 by fastforce\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> (None,h\\<^sub>2,(w#Null#vs,ls\\<^sub>2,C,M,?pc\\<^sub>2)#frs)\"\n    using FAssNull\\<^sub>1.prems IH\\<^sub>2 by fastforce\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> handle P C M ?xa h\\<^sub>2 (w#Null#vs) ls\\<^sub>2 ?pc\\<^sub>2 frs\"\n    using FAssNull\\<^sub>1.prems\n    by(fastforce simp:split_beta handle_def simp del: split_paired_Ex)\n  also have \"handle P C M ?xa h\\<^sub>2 (w#Null#vs) ls\\<^sub>2 ?pc\\<^sub>2 frs =\n             handle P C M ?xa h\\<^sub>2 vs ls\\<^sub>2 ?pc\\<^sub>2 frs\"\n    using FAssNull\\<^sub>1.prems by(auto simp add:handle_Cons)\n  finally show ?case by (auto intro: exI[where x = ?pc\\<^sub>2])\nnext\n  case (FAssThrow\\<^sub>2\\<^sub>1 e\\<^sub>1 h\\<^sub>0 ls\\<^sub>0 w h\\<^sub>1 ls\\<^sub>1 e\\<^sub>2 e' h\\<^sub>2 ls\\<^sub>2 F D)\n  let ?pc\\<^sub>1 = \"pc + length(compE\\<^sub>2 e\\<^sub>1)\"\n  let ?\\<sigma>\\<^sub>1 = \"(None,h\\<^sub>1,(w#vs,ls\\<^sub>1,C,M,?pc\\<^sub>1)#frs)\"\n  have 1: \"P \\<turnstile> (None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs) -jvm\\<rightarrow> ?\\<sigma>\\<^sub>1\"\n    using FAssThrow\\<^sub>2\\<^sub>1 by fastforce\n  show ?case (is \"?N \\<and> (?eq \\<longrightarrow> (\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2))\")\n  proof\n    show ?N by simp\n  next\n    { assume ?eq\n      moreover\n      have \"PROP ?P e\\<^sub>2 h\\<^sub>1 ls\\<^sub>1 (throw e') h\\<^sub>2 ls\\<^sub>2 C M ?pc\\<^sub>1 v xa (w#vs) frs\n                    (I - pcs (compxE\\<^sub>2 e\\<^sub>1 pc (length vs)))\" by fact\n      ultimately obtain pc\\<^sub>2 where\n        pc\\<^sub>2: \"?pc\\<^sub>1 \\<le> pc\\<^sub>2 \\<and> pc\\<^sub>2 < ?pc\\<^sub>1 + size(compE\\<^sub>2 e\\<^sub>2) \\<and>\n              \\<not> caught P pc\\<^sub>2 h\\<^sub>2 xa (compxE\\<^sub>2 e\\<^sub>2 ?pc\\<^sub>1 (size vs + 1))\" and\n        2: \"P \\<turnstile> ?\\<sigma>\\<^sub>1 -jvm\\<rightarrow> handle P C M xa h\\<^sub>2 (w#vs) ls\\<^sub>2 pc\\<^sub>2 frs\"\n        using FAssThrow\\<^sub>2\\<^sub>1.prems by fastforce\n      have 3: \"P \\<turnstile> ?\\<sigma>\\<^sub>1 -jvm\\<rightarrow> handle P C M xa h\\<^sub>2 vs ls\\<^sub>2 pc\\<^sub>2 frs\"\n        using 2 FAssThrow\\<^sub>2\\<^sub>1.prems pc\\<^sub>2 by(auto simp:handle_Cons)\n      have \"?H pc\\<^sub>2\" using pc\\<^sub>2 jvm_trans[OF 1 3] by auto\n      hence \"\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2\" by iprover\n    }\n    thus \"?eq \\<longrightarrow> (\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2)\" by iprover\n  qed\nnext\n  case FAssThrow\\<^sub>1\\<^sub>1 thus ?case by fastforce\nnext\n  case (Call\\<^sub>1 e h\\<^sub>0 ls\\<^sub>0 a h\\<^sub>1 ls\\<^sub>1 es pvs h\\<^sub>2 ls\\<^sub>2 Ca fs M' Ts T body D ls\\<^sub>2' f h\\<^sub>3 ls\\<^sub>3)\n  have \"P\\<^sub>1 \\<turnstile>\\<^sub>1 \\<langle>es,(h\\<^sub>1, ls\\<^sub>1)\\<rangle> [\\<Rightarrow>] \\<langle>map Val pvs,(h\\<^sub>2, ls\\<^sub>2)\\<rangle>\" by fact\n  hence [simp]: \"length es = length pvs\" by(auto dest:evals\\<^sub>1_preserves_elen)\n  let ?\\<sigma>\\<^sub>0 = \"(None,h\\<^sub>0,(vs, ls\\<^sub>0, C,M,pc)#frs)\"\n  let ?pc\\<^sub>1 = \"pc + length(compE\\<^sub>2 e)\"\n  let ?\\<sigma>\\<^sub>1 = \"(None,h\\<^sub>1,(Addr a # vs, ls\\<^sub>1, C,M,?pc\\<^sub>1)#frs)\"\n  let ?pc\\<^sub>2 = \"?pc\\<^sub>1 + length(compEs\\<^sub>2 es)\"\n  let ?frs\\<^sub>2 = \"(rev pvs @ Addr a # vs, ls\\<^sub>2, C,M,?pc\\<^sub>2)#frs\"\n  let ?\\<sigma>\\<^sub>2 = \"(None,h\\<^sub>2,?frs\\<^sub>2)\"\n  let ?frs\\<^sub>2' = \"([], ls\\<^sub>2', D,M',0) # ?frs\\<^sub>2\"\n  let ?\\<sigma>\\<^sub>2' = \"(None, h\\<^sub>2, ?frs\\<^sub>2')\"\n  have IH_es: \"PROP ?Ps es h\\<^sub>1 ls\\<^sub>1 (map Val pvs) h\\<^sub>2 ls\\<^sub>2 C M ?pc\\<^sub>1 pvs xa\n                    (map Val pvs) (Addr a # vs) frs (I - pcs(compxE\\<^sub>2 e pc (size vs)))\" by fact\n  have \"P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> ?\\<sigma>\\<^sub>1\" using Call\\<^sub>1 by fastforce\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> ?\\<sigma>\\<^sub>2\" using IH_es Call\\<^sub>1.prems by fastforce\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> ?\\<sigma>\\<^sub>2'\"\n    using Call\\<^sub>1 by(auto simp add: nth_append compMb\\<^sub>2_def)\n  finally have 1: \"P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> ?\\<sigma>\\<^sub>2'\".\n  have \"P\\<^sub>1 \\<turnstile> Ca sees M': Ts\\<rightarrow>T = body in D\" by fact\n  then have M'_in_D: \"P\\<^sub>1 \\<turnstile> D sees M': Ts\\<rightarrow>T = body in D\"\n    by(rule sees_method_idemp) \n  hence M'_code: \"compP\\<^sub>2 P\\<^sub>1,D,M',0 \\<rhd> compE\\<^sub>2 body @ [Return]\"\n    and M'_xtab: \"compP\\<^sub>2 P\\<^sub>1,D,M' \\<rhd> compxE\\<^sub>2 body 0 0/{..<size(compE\\<^sub>2 body)},0\"\n    by(rule beforeM, rule beforexM)\n  have IH_body: \"PROP ?P body h\\<^sub>2 ls\\<^sub>2' f h\\<^sub>3 ls\\<^sub>3 D M' 0 v xa [] ?frs\\<^sub>2 ({..<size(compE\\<^sub>2 body)})\" by fact\n  show ?case (is \"?Norm \\<and> ?Err\")\n  proof\n    show ?Norm (is \"?val \\<longrightarrow> ?trans\")\n    proof\n      assume val: ?val\n      note 1\n      also have \"P \\<turnstile> ?\\<sigma>\\<^sub>2' -jvm\\<rightarrow>\n                     (None,h\\<^sub>3,([v],ls\\<^sub>3,D,M',size(compE\\<^sub>2 body))#?frs\\<^sub>2)\"\n        using val IH_body Call\\<^sub>1.prems M'_code M'_xtab\n        by (fastforce simp del:split_paired_Ex)\n      also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> (None, h\\<^sub>3, (v # vs, ls\\<^sub>2, C,M,?pc\\<^sub>2+1)#frs)\"\n        using Call\\<^sub>1 M'_code M'_in_D by(auto simp: nth_append compMb\\<^sub>2_def)\n      finally show ?trans by(simp add:add.assoc)\n    qed\n  next\n    show ?Err (is \"?throw \\<longrightarrow> (\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2)\")\n    proof\n      assume throw: ?throw\n      with IH_body obtain pc\\<^sub>2 where\n        pc\\<^sub>2: \"0 \\<le> pc\\<^sub>2 \\<and> pc\\<^sub>2 < size(compE\\<^sub>2 body) \\<and>\n              \\<not> caught P pc\\<^sub>2 h\\<^sub>3 xa (compxE\\<^sub>2 body 0 0)\" and\n        2: \"P \\<turnstile> ?\\<sigma>\\<^sub>2' -jvm\\<rightarrow> handle P D M' xa h\\<^sub>3 [] ls\\<^sub>3 pc\\<^sub>2 ?frs\\<^sub>2\"\n        using Call\\<^sub>1.prems M'_code M'_xtab\n        by (fastforce simp del:split_paired_Ex)\n      have \"handle P D M' xa h\\<^sub>3 [] ls\\<^sub>3 pc\\<^sub>2 ?frs\\<^sub>2 =\n            handle P C M xa h\\<^sub>3 (rev pvs @ Addr a # vs) ls\\<^sub>2 ?pc\\<^sub>2 frs\"\n        using pc\\<^sub>2 M'_in_D by(auto simp add:handle_def)\n      also have \"\\<dots> = handle P C M xa h\\<^sub>3 vs ls\\<^sub>2 ?pc\\<^sub>2 frs\"\n        using Call\\<^sub>1.prems by(auto simp add:handle_append handle_Cons)\n      finally have \"?H ?pc\\<^sub>2\" using pc\\<^sub>2 jvm_trans[OF 1 2] by auto\n      thus \"\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2\" by iprover\n    qed\n  qed\nnext\n  case (CallParamsThrow\\<^sub>1 e h\\<^sub>0 ls\\<^sub>0 w h\\<^sub>1 ls\\<^sub>1 es es' h\\<^sub>2 ls\\<^sub>2 pvs ex es'' M')\n  let ?\\<sigma>\\<^sub>0 = \"(None,h\\<^sub>0,(vs, ls\\<^sub>0, C,M,pc)#frs)\"\n  let ?pc\\<^sub>1 = \"pc + length(compE\\<^sub>2 e)\"\n  let ?\\<sigma>\\<^sub>1 = \"(None,h\\<^sub>1,(w # vs, ls\\<^sub>1, C,M,?pc\\<^sub>1)#frs)\"\n  let ?pc\\<^sub>2 = \"?pc\\<^sub>1 + length(compEs\\<^sub>2 es)\"\n  have 1: \"P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> ?\\<sigma>\\<^sub>1\" using CallParamsThrow\\<^sub>1 by fastforce\n  show ?case (is \"?N \\<and> (?eq \\<longrightarrow> (\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2))\")\n  proof\n    show ?N by simp\n  next\n    { assume ?eq\n      moreover\n      have \"PROP ?Ps es h\\<^sub>1 ls\\<^sub>1 es' h\\<^sub>2 ls\\<^sub>2 C M ?pc\\<^sub>1 pvs xa es'' (w#vs) frs\n        (I - pcs (compxE\\<^sub>2 e pc (length vs)))\" by fact\n      ultimately have \"\\<exists>pc\\<^sub>2.\n        (?pc\\<^sub>1 \\<le> pc\\<^sub>2 \\<and> pc\\<^sub>2 < ?pc\\<^sub>1 + size(compEs\\<^sub>2 es) \\<and>\n         \\<not> caught P pc\\<^sub>2 h\\<^sub>2 xa (compxEs\\<^sub>2 es ?pc\\<^sub>1 (size vs + 1))) \\<and>\n        P \\<turnstile> ?\\<sigma>\\<^sub>1 -jvm\\<rightarrow> handle P C M xa h\\<^sub>2 (w#vs) ls\\<^sub>2 pc\\<^sub>2 frs\"\n        (is \"\\<exists>pc\\<^sub>2. ?PC pc\\<^sub>2 \\<and> ?Exec pc\\<^sub>2\")\n        using CallParamsThrow\\<^sub>1 by force\n      then obtain pc\\<^sub>2 where pc\\<^sub>2: \"?PC pc\\<^sub>2\" and 2: \"?Exec pc\\<^sub>2\" by iprover\n      have \"?H pc\\<^sub>2\" using pc\\<^sub>2 jvm_trans[OF 1 2] CallParamsThrow\\<^sub>1\n        by(auto simp:handle_Cons)\n      hence \"\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2\" by iprover\n    }\n    thus \"?eq \\<longrightarrow> (\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2)\" by iprover\n  qed\nnext\n  case (CallNull\\<^sub>1 e h\\<^sub>0 ls\\<^sub>0 h\\<^sub>1 ls\\<^sub>1 es pvs h\\<^sub>2 ls\\<^sub>2 M')\n  have \"P\\<^sub>1 \\<turnstile>\\<^sub>1 \\<langle>es,(h\\<^sub>1, ls\\<^sub>1)\\<rangle> [\\<Rightarrow>] \\<langle>map Val pvs,(h\\<^sub>2, ls\\<^sub>2)\\<rangle>\" by fact\n  hence [simp]: \"length es = length pvs\" by(auto dest:evals\\<^sub>1_preserves_elen)\n  let ?pc\\<^sub>1 = \"pc + length(compE\\<^sub>2 e)\"\n  let ?pc\\<^sub>2 = \"?pc\\<^sub>1 + length(compEs\\<^sub>2 es)\"\n  let ?xa = \"addr_of_sys_xcpt NullPointer\"\n  have IH_es: \"PROP ?Ps es h\\<^sub>1 ls\\<^sub>1 (map Val pvs) h\\<^sub>2 ls\\<^sub>2 C M ?pc\\<^sub>1 pvs xa\n                    (map Val pvs) (Null#vs) frs (I - pcs(compxE\\<^sub>2 e pc (size vs)))\" by fact\n  have \"P \\<turnstile> (None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs) -jvm\\<rightarrow>\n             (None,h\\<^sub>1,(Null#vs,ls\\<^sub>1,C,M,?pc\\<^sub>1)#frs)\" using CallNull\\<^sub>1 by fastforce\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> (None,h\\<^sub>2,(rev pvs@Null#vs,ls\\<^sub>2,C,M,?pc\\<^sub>2)#frs)\"\n    using CallNull\\<^sub>1 IH_es by fastforce\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> handle P C M ?xa h\\<^sub>2 (rev pvs@Null#vs) ls\\<^sub>2 ?pc\\<^sub>2 frs\"\n    using CallNull\\<^sub>1.prems\n    by(auto simp:split_beta handle_def nth_append simp del: split_paired_Ex)\n  also have \"handle P C M ?xa h\\<^sub>2 (rev pvs@Null#vs) ls\\<^sub>2 ?pc\\<^sub>2 frs =\n             handle P C M ?xa h\\<^sub>2 vs ls\\<^sub>2 ?pc\\<^sub>2 frs\"\n    using CallNull\\<^sub>1.prems by(auto simp:handle_Cons handle_append)\n  finally show ?case by (auto intro: exI[where x = ?pc\\<^sub>2])\nnext\n  case CallObjThrow\\<^sub>1 thus ?case by fastforce\nnext\n  case Block\\<^sub>1 thus ?case by auto\nnext\n  case (Seq\\<^sub>1 e\\<^sub>1 h\\<^sub>0 ls\\<^sub>0 w h\\<^sub>1 ls\\<^sub>1 e\\<^sub>2 e\\<^sub>2' h\\<^sub>2 ls\\<^sub>2)\n  let ?pc\\<^sub>1 = \"pc + length(compE\\<^sub>2 e\\<^sub>1)\"\n  let ?\\<sigma>\\<^sub>0 = \"(None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs)\"\n  let ?\\<sigma>\\<^sub>1 = \"(None,h\\<^sub>1,(vs,ls\\<^sub>1,C,M,?pc\\<^sub>1+1)#frs)\"\n  have \"P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> (None,h\\<^sub>1,(w#vs,ls\\<^sub>1,C,M,?pc\\<^sub>1)#frs)\"\n    using Seq\\<^sub>1 by fastforce\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> ?\\<sigma>\\<^sub>1\" using Seq\\<^sub>1 by auto\n  finally have eval\\<^sub>1: \"P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> ?\\<sigma>\\<^sub>1\".\n  let ?pc\\<^sub>2 = \"?pc\\<^sub>1 + 1 + length(compE\\<^sub>2 e\\<^sub>2)\"\n  have IH\\<^sub>2: \"PROP ?P e\\<^sub>2 h\\<^sub>1 ls\\<^sub>1 e\\<^sub>2' h\\<^sub>2 ls\\<^sub>2 C M (?pc\\<^sub>1+1) v xa vs frs\n                     (I - pcs(compxE\\<^sub>2 e\\<^sub>1 pc (size vs)))\" by fact\n  show ?case (is \"?Norm \\<and> ?Err\")\n  proof\n    show ?Norm (is \"?val \\<longrightarrow> ?trans\")\n    proof\n      assume val: ?val\n      note eval\\<^sub>1\n      also have \"P \\<turnstile> ?\\<sigma>\\<^sub>1 -jvm\\<rightarrow> (None,h\\<^sub>2,(v#vs,ls\\<^sub>2,C,M,?pc\\<^sub>2)#frs)\"\n        using val Seq\\<^sub>1.prems IH\\<^sub>2 by fastforce\n      finally show ?trans by(simp add:add.assoc)\n    qed\n  next\n    show ?Err (is \"?throw \\<longrightarrow> (\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2)\")\n    proof\n      assume throw: ?throw\n      then obtain pc\\<^sub>2 where\n        pc\\<^sub>2: \"?pc\\<^sub>1+1 \\<le> pc\\<^sub>2 \\<and> pc\\<^sub>2 < ?pc\\<^sub>2 \\<and>\n              \\<not> caught P pc\\<^sub>2 h\\<^sub>2 xa (compxE\\<^sub>2 e\\<^sub>2 (?pc\\<^sub>1+1) (size vs))\" and\n        eval\\<^sub>2: \"P \\<turnstile> ?\\<sigma>\\<^sub>1 -jvm\\<rightarrow> handle P C M xa h\\<^sub>2 vs ls\\<^sub>2 pc\\<^sub>2 frs\"\n        using IH\\<^sub>2 Seq\\<^sub>1.prems by fastforce\n      have \"?H pc\\<^sub>2\" using pc\\<^sub>2 jvm_trans[OF eval\\<^sub>1 eval\\<^sub>2] by auto\n      thus \"\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2\" by iprover\n    qed\n  qed\nnext\n  case SeqThrow\\<^sub>1 thus ?case by fastforce\nnext\n  case (CondT\\<^sub>1 e h\\<^sub>0 ls\\<^sub>0 h\\<^sub>1 ls\\<^sub>1 e\\<^sub>1 e' h\\<^sub>2 ls\\<^sub>2 e\\<^sub>2)\n  let ?pc\\<^sub>1 = \"pc + length(compE\\<^sub>2 e)\"\n  let ?\\<sigma>\\<^sub>0 = \"(None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs)\"\n  let ?\\<sigma>\\<^sub>1 = \"(None,h\\<^sub>1,(vs,ls\\<^sub>1,C,M,?pc\\<^sub>1+1)#frs)\"\n  have \"P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> (None,h\\<^sub>1,(Bool(True)#vs,ls\\<^sub>1,C,M,?pc\\<^sub>1)#frs)\"\n    using CondT\\<^sub>1 by (fastforce simp add: Int_Un_distrib)\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> ?\\<sigma>\\<^sub>1\" using CondT\\<^sub>1 by auto\n  finally have eval\\<^sub>1: \"P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> ?\\<sigma>\\<^sub>1\".\n  let ?pc\\<^sub>1' = \"?pc\\<^sub>1 + 1 + length(compE\\<^sub>2 e\\<^sub>1)\"\n  let ?pc\\<^sub>2' = \"?pc\\<^sub>1' + 1 + length(compE\\<^sub>2 e\\<^sub>2)\"\n  show ?case (is \"?Norm \\<and> ?Err\")\n  proof\n    show ?Norm (is \"?val \\<longrightarrow> ?trans\")\n    proof\n      assume val: ?val\n      note eval\\<^sub>1\n      also have \"P \\<turnstile> ?\\<sigma>\\<^sub>1 -jvm\\<rightarrow> (None,h\\<^sub>2,(v#vs,ls\\<^sub>2,C,M,?pc\\<^sub>1')#frs)\"\n        using val CondT\\<^sub>1 by(fastforce simp:Int_Un_distrib)\n      also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> (None,h\\<^sub>2,(v#vs,ls\\<^sub>2,C,M,?pc\\<^sub>2')#frs)\"\n        using CondT\\<^sub>1 by(auto simp:add.assoc)\n      finally show ?trans by(simp add:add.assoc)\n    qed\n  next\n    show ?Err (is \"?throw \\<longrightarrow> (\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2)\")\n    proof\n      let ?d = \"size vs\"\n      let ?I = \"I - pcs(compxE\\<^sub>2 e pc ?d) - pcs(compxE\\<^sub>2 e\\<^sub>2 (?pc\\<^sub>1'+1) ?d)\"\n      assume throw: ?throw\n      moreover\n      have \"PROP ?P e\\<^sub>1 h\\<^sub>1 ls\\<^sub>1 e' h\\<^sub>2 ls\\<^sub>2 C M (?pc\\<^sub>1+1) v xa vs frs ?I\" by fact\n      ultimately obtain pc\\<^sub>2 where\n        pc\\<^sub>2: \"?pc\\<^sub>1+1 \\<le> pc\\<^sub>2 \\<and> pc\\<^sub>2 < ?pc\\<^sub>1' \\<and>\n              \\<not> caught P pc\\<^sub>2 h\\<^sub>2 xa (compxE\\<^sub>2 e\\<^sub>1 (?pc\\<^sub>1+1) (size vs))\" and\n        eval\\<^sub>2: \"P \\<turnstile> ?\\<sigma>\\<^sub>1 -jvm\\<rightarrow> handle P C M xa h\\<^sub>2 vs ls\\<^sub>2 pc\\<^sub>2 frs\"\n        using CondT\\<^sub>1.prems by (fastforce simp:Int_Un_distrib)\n      have \"?H pc\\<^sub>2\" using pc\\<^sub>2 jvm_trans[OF eval\\<^sub>1 eval\\<^sub>2] by auto\n      thus \"\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2\" by iprover\n    qed\n  qed\nnext\n  case (CondF\\<^sub>1 e h\\<^sub>0 ls\\<^sub>0 h\\<^sub>1 ls\\<^sub>1 e\\<^sub>2 e' h\\<^sub>2 ls\\<^sub>2 e\\<^sub>1)\n  let ?pc\\<^sub>1 = \"pc + length(compE\\<^sub>2 e)\"\n  let ?pc\\<^sub>2 = \"?pc\\<^sub>1 + 1 + length(compE\\<^sub>2 e\\<^sub>1)+ 1\"\n  let ?pc\\<^sub>2' = \"?pc\\<^sub>2 + length(compE\\<^sub>2 e\\<^sub>2)\"\n  let ?\\<sigma>\\<^sub>0 = \"(None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs)\"\n  let ?\\<sigma>\\<^sub>1 = \"(None,h\\<^sub>1,(vs,ls\\<^sub>1,C,M,?pc\\<^sub>2)#frs)\"\n  have \"P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> (None,h\\<^sub>1,(Bool(False)#vs,ls\\<^sub>1,C,M,?pc\\<^sub>1)#frs)\"\n    using CondF\\<^sub>1 by (fastforce simp add: Int_Un_distrib)\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> ?\\<sigma>\\<^sub>1\" using CondF\\<^sub>1 by auto\n  finally have eval\\<^sub>1: \"P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> ?\\<sigma>\\<^sub>1\".\n  show ?case (is \"?Norm \\<and> ?Err\")\n  proof\n    show ?Norm (is \"?val \\<longrightarrow> ?trans\")\n    proof\n      assume val: ?val\n      note eval\\<^sub>1\n      also have \"P \\<turnstile> ?\\<sigma>\\<^sub>1 -jvm\\<rightarrow> (None,h\\<^sub>2,(v#vs,ls\\<^sub>2,C,M,?pc\\<^sub>2')#frs)\"\n        using val CondF\\<^sub>1 by(fastforce simp:Int_Un_distrib)\n      finally show ?trans by(simp add:add.assoc)\n    qed\n  next\n    show ?Err (is \"?throw \\<longrightarrow> (\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2)\")\n    proof\n      let ?d = \"size vs\"\n      let ?I = \"I - pcs(compxE\\<^sub>2 e pc ?d) - pcs(compxE\\<^sub>2 e\\<^sub>1 (?pc\\<^sub>1+1) ?d)\"\n      assume throw: ?throw\n      moreover\n      have \"PROP ?P e\\<^sub>2 h\\<^sub>1 ls\\<^sub>1 e' h\\<^sub>2 ls\\<^sub>2 C M ?pc\\<^sub>2 v xa vs frs ?I\" by fact\n      ultimately obtain pc\\<^sub>2 where\n        pc\\<^sub>2: \"?pc\\<^sub>2 \\<le> pc\\<^sub>2 \\<and> pc\\<^sub>2 < ?pc\\<^sub>2' \\<and>\n              \\<not> caught P pc\\<^sub>2 h\\<^sub>2 xa (compxE\\<^sub>2 e\\<^sub>2 ?pc\\<^sub>2 ?d)\" and\n        eval\\<^sub>2: \"P \\<turnstile> ?\\<sigma>\\<^sub>1 -jvm\\<rightarrow> handle P C M xa h\\<^sub>2 vs ls\\<^sub>2 pc\\<^sub>2 frs\"\n        using CondF\\<^sub>1.prems by(fastforce simp:Int_Un_distrib)\n      have \"?H pc\\<^sub>2\" using pc\\<^sub>2 jvm_trans[OF eval\\<^sub>1 eval\\<^sub>2] by auto\n      thus \"\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2\" by iprover\n    qed\n  qed\nnext\n  case (CondThrow\\<^sub>1 e h\\<^sub>0 ls\\<^sub>0 f h\\<^sub>1 ls\\<^sub>1 e\\<^sub>1 e\\<^sub>2)\n  let ?d = \"size vs\"\n  let ?xt\\<^sub>1 = \"compxE\\<^sub>2 e\\<^sub>1 (pc+size(compE\\<^sub>2 e)+1) ?d\"\n  let ?xt\\<^sub>2 = \"compxE\\<^sub>2 e\\<^sub>2 (pc+size(compE\\<^sub>2 e)+size(compE\\<^sub>2 e\\<^sub>1)+2) ?d\"\n  let ?I = \"I - (pcs ?xt\\<^sub>1 \\<union> pcs ?xt\\<^sub>2)\"\n  have \"pcs(compxE\\<^sub>2 e pc ?d) \\<inter> pcs(?xt\\<^sub>1 @ ?xt\\<^sub>2) = {}\"\n    using CondThrow\\<^sub>1.prems by (simp add:Int_Un_distrib)\n  moreover have \"PROP ?P e h\\<^sub>0 ls\\<^sub>0 (throw f) h\\<^sub>1 ls\\<^sub>1 C M pc v xa vs frs ?I\" by fact\n  ultimately show ?case using CondThrow\\<^sub>1.prems by fastforce\nnext\n  case (WhileF\\<^sub>1 e h\\<^sub>0 ls\\<^sub>0 h\\<^sub>1 ls\\<^sub>1 c)\n  let ?pc = \"pc + length(compE\\<^sub>2 e)\"\n  let ?pc' = \"?pc + length(compE\\<^sub>2 c) + 3\"\n  have \"P \\<turnstile> (None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs) -jvm\\<rightarrow>\n            (None,h\\<^sub>1,(Bool False#vs,ls\\<^sub>1,C,M,?pc)#frs)\"\n    using WhileF\\<^sub>1 by fastforce\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> (None,h\\<^sub>1,(vs,ls\\<^sub>1,C,M,?pc')#frs)\"\n    using WhileF\\<^sub>1 by (auto simp:add.assoc)\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> (None,h\\<^sub>1,(Unit#vs,ls\\<^sub>1,C,M,?pc'+1)#frs)\"\n    using WhileF\\<^sub>1.prems by (auto simp:eval_nat_numeral)\n  finally show ?case by (simp add:add.assoc eval_nat_numeral)\nnext\n  case (WhileT\\<^sub>1 e h\\<^sub>0 ls\\<^sub>0 h\\<^sub>1 ls\\<^sub>1 c v\\<^sub>1 h\\<^sub>2 ls\\<^sub>2 e\\<^sub>3 h\\<^sub>3 ls\\<^sub>3)\n  let ?pc = \"pc + length(compE\\<^sub>2 e)\"\n  let ?pc' = \"?pc + length(compE\\<^sub>2 c) + 1\"\n  let ?\\<sigma>\\<^sub>0 = \"(None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs)\"\n  let ?\\<sigma>\\<^sub>2 = \"(None,h\\<^sub>2,(vs,ls\\<^sub>2,C,M,pc)#frs)\"\n  have \"P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> (None,h\\<^sub>1,(Bool True#vs,ls\\<^sub>1,C,M,?pc)#frs)\"\n    using WhileT\\<^sub>1 by fastforce\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> (None,h\\<^sub>1,(vs,ls\\<^sub>1,C,M,?pc+1)#frs)\"\n    using WhileT\\<^sub>1.prems by auto\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> (None,h\\<^sub>2,(v\\<^sub>1#vs,ls\\<^sub>2,C,M,?pc')#frs)\"\n    using WhileT\\<^sub>1 by(fastforce)\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> ?\\<sigma>\\<^sub>2\" using WhileT\\<^sub>1.prems by auto\n  finally have 1: \"P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> ?\\<sigma>\\<^sub>2\".\n  show ?case (is \"?Norm \\<and> ?Err\")\n  proof\n    show ?Norm (is \"?val \\<longrightarrow> ?trans\")\n    proof\n      assume val: ?val\n      note 1\n      also have \"P \\<turnstile> ?\\<sigma>\\<^sub>2 -jvm\\<rightarrow> (None,h\\<^sub>3,(v#vs,ls\\<^sub>3,C,M,?pc'+3)#frs)\"\n        using val WhileT\\<^sub>1 by (auto simp add:add.assoc eval_nat_numeral)\n      finally show ?trans by(simp add:add.assoc eval_nat_numeral)\n    qed\n  next\n    show ?Err (is \"?throw \\<longrightarrow> (\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2)\")\n    proof\n      assume throw: ?throw\n      moreover\n      have \"PROP ?P (while (e) c) h\\<^sub>2 ls\\<^sub>2 e\\<^sub>3 h\\<^sub>3 ls\\<^sub>3 C M pc v xa vs frs I\" by fact\n      ultimately obtain pc\\<^sub>2 where\n        pc\\<^sub>2: \"pc \\<le> pc\\<^sub>2 \\<and> pc\\<^sub>2 < ?pc'+3 \\<and>\n              \\<not> caught P pc\\<^sub>2 h\\<^sub>3 xa (compxE\\<^sub>2 (while (e) c) pc (size vs))\" and\n        2: \"P \\<turnstile> ?\\<sigma>\\<^sub>2 -jvm\\<rightarrow> handle P C M xa h\\<^sub>3 vs ls\\<^sub>3 pc\\<^sub>2 frs\"\n        using WhileT\\<^sub>1.prems by (auto simp:add.assoc eval_nat_numeral)\n      have \"?H pc\\<^sub>2\" using pc\\<^sub>2 jvm_trans[OF 1 2] by auto\n      thus \"\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2\" by iprover\n    qed\n  qed\nnext\n  case WhileCondThrow\\<^sub>1 thus ?case by fastforce\nnext\n  case (WhileBodyThrow\\<^sub>1 e h\\<^sub>0 ls\\<^sub>0 h\\<^sub>1 ls\\<^sub>1 c e' h\\<^sub>2 ls\\<^sub>2)\n  let ?pc\\<^sub>1 = \"pc + length(compE\\<^sub>2 e)\"\n  let ?\\<sigma>\\<^sub>0 = \"(None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs)\"\n  let ?\\<sigma>\\<^sub>1 = \"(None,h\\<^sub>1,(vs,ls\\<^sub>1,C,M,?pc\\<^sub>1+1)#frs)\"\n  have \"P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> (None,h\\<^sub>1,(Bool(True)#vs,ls\\<^sub>1,C,M,?pc\\<^sub>1)#frs)\"\n    using WhileBodyThrow\\<^sub>1 by (fastforce simp add: Int_Un_distrib)\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> ?\\<sigma>\\<^sub>1\" using  WhileBodyThrow\\<^sub>1 by auto\n  finally have eval\\<^sub>1: \"P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> ?\\<sigma>\\<^sub>1\".\n  let ?pc\\<^sub>1' = \"?pc\\<^sub>1 + 1 + length(compE\\<^sub>2 c)\"\n  show ?case (is \"?Norm \\<and> ?Err\")\n  proof\n    show ?Norm by simp\n  next\n    show ?Err (is \"?throw \\<longrightarrow> (\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2)\")\n    proof\n      assume throw: ?throw\n      moreover\n      have \"PROP ?P c h\\<^sub>1 ls\\<^sub>1 (throw e') h\\<^sub>2 ls\\<^sub>2 C M (?pc\\<^sub>1+1) v xa vs frs\n                    (I - pcs (compxE\\<^sub>2 e pc (size vs)))\" by fact\n      ultimately obtain pc\\<^sub>2 where\n        pc\\<^sub>2: \"?pc\\<^sub>1+1 \\<le> pc\\<^sub>2 \\<and> pc\\<^sub>2 < ?pc\\<^sub>1' \\<and>\n              \\<not> caught P pc\\<^sub>2 h\\<^sub>2 xa (compxE\\<^sub>2 c (?pc\\<^sub>1+1) (size vs))\" and\n        eval\\<^sub>2: \"P \\<turnstile> ?\\<sigma>\\<^sub>1 -jvm\\<rightarrow> handle P C M xa h\\<^sub>2 vs ls\\<^sub>2 pc\\<^sub>2 frs\"\n        using WhileBodyThrow\\<^sub>1.prems by (fastforce simp:Int_Un_distrib)\n      have \"?H pc\\<^sub>2\" using pc\\<^sub>2 jvm_trans[OF eval\\<^sub>1 eval\\<^sub>2] by auto\n      thus \"\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2\" by iprover\n    qed\n  qed\nnext\n  case (Throw\\<^sub>1 e h\\<^sub>0 ls\\<^sub>0 a h\\<^sub>1 ls\\<^sub>1)\n  let ?pc = \"pc + size(compE\\<^sub>2 e)\"\n  show ?case (is \"?Norm \\<and> ?Err\")\n  proof\n    show ?Norm by simp\n  next\n    show ?Err (is \"?throw \\<longrightarrow> (\\<exists>pc\\<^sub>1. ?H pc\\<^sub>1)\")\n    proof\n      assume ?throw\n      hence \"P \\<turnstile> (None, h\\<^sub>0, (vs, ls\\<^sub>0, C, M, pc) # frs) -jvm\\<rightarrow>\n                 (None, h\\<^sub>1, (Addr xa#vs, ls\\<^sub>1, C, M, ?pc) # frs)\"\n        using Throw\\<^sub>1 by fastforce\n      also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> handle P C M xa h\\<^sub>1 (Addr xa#vs) ls\\<^sub>1 ?pc frs\"\n        using Throw\\<^sub>1.prems by(auto simp add:handle_def)\n      also have \"handle P C M xa h\\<^sub>1 (Addr xa#vs) ls\\<^sub>1 ?pc frs =\n                 handle P C M xa h\\<^sub>1 vs ls\\<^sub>1 ?pc frs\"\n        using Throw\\<^sub>1.prems by(auto simp add:handle_Cons)\n      finally have \"?H ?pc\" by simp\n      thus \"\\<exists>pc\\<^sub>1. ?H pc\\<^sub>1\" by iprover\n    qed\n  qed\nnext\n  case (ThrowNull\\<^sub>1 e h\\<^sub>0 ls\\<^sub>0 h\\<^sub>1 ls\\<^sub>1)\n  let ?pc = \"pc + size(compE\\<^sub>2 e)\"\n  let ?xa = \"addr_of_sys_xcpt NullPointer\"\n  show ?case (is \"?Norm \\<and> ?Err\")\n  proof\n    show ?Norm by simp\n  next\n    show ?Err (is \"?throw \\<longrightarrow> (\\<exists>pc\\<^sub>1. ?H pc\\<^sub>1)\")\n    proof\n      assume throw: ?throw\n      have \"P \\<turnstile> (None, h\\<^sub>0, (vs, ls\\<^sub>0, C, M, pc) # frs) -jvm\\<rightarrow>\n                 (None, h\\<^sub>1, (Null#vs, ls\\<^sub>1, C, M, ?pc) # frs)\"\n        using ThrowNull\\<^sub>1 by fastforce\n      also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow>  handle P C M ?xa h\\<^sub>1 (Null#vs) ls\\<^sub>1 ?pc frs\"\n        using ThrowNull\\<^sub>1.prems by(auto simp add:handle_def)\n      also have \"handle P C M ?xa h\\<^sub>1 (Null#vs) ls\\<^sub>1 ?pc frs =\n                 handle P C M ?xa h\\<^sub>1 vs ls\\<^sub>1 ?pc frs\"\n        using ThrowNull\\<^sub>1.prems by(auto simp add:handle_Cons)\n      finally have \"?H ?pc\" using throw by simp\n      thus \"\\<exists>pc\\<^sub>1. ?H pc\\<^sub>1\" by iprover\n    qed\n  qed\nnext\n  case ThrowThrow\\<^sub>1 thus ?case by fastforce\nnext\n  case (Try\\<^sub>1 e\\<^sub>1 h\\<^sub>0 ls\\<^sub>0 v\\<^sub>1 h\\<^sub>1 ls\\<^sub>1 Ci i e\\<^sub>2)\n  let ?pc\\<^sub>1 = \"pc + length(compE\\<^sub>2 e\\<^sub>1)\"\n  let ?pc\\<^sub>1' = \"?pc\\<^sub>1 + 2 + length(compE\\<^sub>2 e\\<^sub>2)\"\n  have \"P,C,M \\<rhd> compxE\\<^sub>2 (try e\\<^sub>1 catch(Ci i) e\\<^sub>2) pc (size vs) / I,size vs\" by fact\n  hence \"P,C,M \\<rhd> compxE\\<^sub>2 e\\<^sub>1 pc (size vs) /\n                 {pc..<pc + length (compE\\<^sub>2 e\\<^sub>1)},size vs\"\n    using Try\\<^sub>1.prems by (fastforce simp:beforex_def split:if_split_asm)\n  hence \"P \\<turnstile> (None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs) -jvm\\<rightarrow>\n             (None,h\\<^sub>1,(v\\<^sub>1#vs,ls\\<^sub>1,C,M,?pc\\<^sub>1)#frs)\" using Try\\<^sub>1 by auto\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> (None,h\\<^sub>1,(v\\<^sub>1#vs,ls\\<^sub>1,C,M,?pc\\<^sub>1')#frs)\"\n    using Try\\<^sub>1.prems by auto\n  finally show ?case by (auto simp:add.assoc)\nnext\n  case (TryCatch\\<^sub>1 e\\<^sub>1 h\\<^sub>0 ls\\<^sub>0 a h\\<^sub>1 ls\\<^sub>1 D fs Ci i e\\<^sub>2 e\\<^sub>2' h\\<^sub>2 ls\\<^sub>2)\n  let ?e = \"try e\\<^sub>1 catch(Ci i) e\\<^sub>2\"\n  let ?xt = \"compxE\\<^sub>2 ?e pc (size vs)\"\n  let ?\\<sigma>\\<^sub>0 = \"(None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs)\"\n  let ?ls\\<^sub>1 = \"ls\\<^sub>1[i := Addr a]\"\n  let ?pc\\<^sub>1 = \"pc + length(compE\\<^sub>2 e\\<^sub>1)\"\n  let ?pc\\<^sub>1' = \"?pc\\<^sub>1 + 2\"\n  let ?\\<sigma>\\<^sub>1 = \"(None,h\\<^sub>1,(vs,?ls\\<^sub>1,C,M, ?pc\\<^sub>1') # frs)\"\n  have I: \"{pc..<pc + length (compE\\<^sub>2 (try e\\<^sub>1 catch(Ci i) e\\<^sub>2))} \\<subseteq> I\"\n   and beforex: \"P,C,M \\<rhd> ?xt/I,size vs\" by fact+\n  have \"P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> (None,h\\<^sub>1,((Addr a)#vs,ls\\<^sub>1,C,M, ?pc\\<^sub>1+1) # frs)\"\n  proof -\n    have \"PROP ?P e\\<^sub>1 h\\<^sub>0 ls\\<^sub>0 (Throw a) h\\<^sub>1 ls\\<^sub>1 C M pc w a vs frs {pc..<pc + length (compE\\<^sub>2 e\\<^sub>1)}\"\n      by fact\n    moreover have \"P,C,M \\<rhd> compxE\\<^sub>2 e\\<^sub>1 pc (size vs)/{pc..<?pc\\<^sub>1},size vs\"\n      using beforex I pcs_subset by(force elim!: beforex_appendD1)\n    ultimately have\n      \"\\<exists>pc\\<^sub>1. pc \\<le> pc\\<^sub>1 \\<and> pc\\<^sub>1 < ?pc\\<^sub>1 \\<and>\n             \\<not> caught P pc\\<^sub>1 h\\<^sub>1 a (compxE\\<^sub>2 e\\<^sub>1 pc (size vs)) \\<and>\n             P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> handle P C M a h\\<^sub>1 vs ls\\<^sub>1 pc\\<^sub>1 frs\"\n      using  TryCatch\\<^sub>1.prems by auto\n    then obtain pc\\<^sub>1 where\n      pc\\<^sub>1_in_e\\<^sub>1: \"pc \\<le> pc\\<^sub>1\" \"pc\\<^sub>1 < ?pc\\<^sub>1\" and\n      pc\\<^sub>1_not_caught: \"\\<not> caught P pc\\<^sub>1 h\\<^sub>1 a (compxE\\<^sub>2 e\\<^sub>1 pc (size vs))\" and\n      0: \"P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> handle P C M a h\\<^sub>1 vs ls\\<^sub>1 pc\\<^sub>1 frs\" by iprover\n    from beforex obtain xt\\<^sub>0 xt\\<^sub>1\n      where ex_tab: \"ex_table_of P C M = xt\\<^sub>0 @ ?xt @ xt\\<^sub>1\"\n      and disj: \"pcs xt\\<^sub>0 \\<inter> I = {}\" by(auto simp:beforex_def)\n    have hp: \"h\\<^sub>1 a = Some (D, fs)\" \"P\\<^sub>1 \\<turnstile> D \\<preceq>\\<^sup>* Ci\" by fact+\n    have \"pc\\<^sub>1 \\<notin> pcs xt\\<^sub>0\" using pc\\<^sub>1_in_e\\<^sub>1 I disj by auto\n    with pc\\<^sub>1_in_e\\<^sub>1 pc\\<^sub>1_not_caught hp\n    show ?thesis using ex_tab 0 by(simp add:handle_def matches_ex_entry_def)\n  qed\n  also have \"P \\<turnstile> \\<dots> -jvm\\<rightarrow> ?\\<sigma>\\<^sub>1\" using TryCatch\\<^sub>1 by auto\n  finally have 1: \"P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> ?\\<sigma>\\<^sub>1\" .\n  let ?pc\\<^sub>2 = \"?pc\\<^sub>1' + length(compE\\<^sub>2 e\\<^sub>2)\"\n  let ?I\\<^sub>2 = \"{?pc\\<^sub>1' ..< ?pc\\<^sub>2}\"\n  have \"P,C,M \\<rhd> compxE\\<^sub>2 ?e pc (size vs) / I,size vs\" by fact\n  hence beforex\\<^sub>2: \"P,C,M \\<rhd> compxE\\<^sub>2 e\\<^sub>2 ?pc\\<^sub>1' (size vs) / ?I\\<^sub>2, size vs\"\n    using I pcs_subset[of _ ?pc\\<^sub>1'] by(auto elim!:beforex_appendD2)\n  have IH\\<^sub>2: \"PROP ?P e\\<^sub>2 h\\<^sub>1 ?ls\\<^sub>1 e\\<^sub>2' h\\<^sub>2 ls\\<^sub>2 C M ?pc\\<^sub>1' v xa vs frs ?I\\<^sub>2\" by fact\n  show ?case (is \"?Norm \\<and> ?Err\")\n  proof\n    show ?Norm (is \"?val \\<longrightarrow> ?trans\")\n    proof\n      assume val: ?val\n      note 1 also have \"P \\<turnstile> ?\\<sigma>\\<^sub>1 -jvm\\<rightarrow> (None,h\\<^sub>2,(v#vs,ls\\<^sub>2,C,M,?pc\\<^sub>2)#frs)\"\n        using val beforex\\<^sub>2 IH\\<^sub>2 TryCatch\\<^sub>1.prems by auto\n      finally show ?trans by(simp add:add.assoc)\n    qed\n  next\n    show ?Err (is \"?throw \\<longrightarrow> (\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2)\")\n    proof\n      assume throw: ?throw\n      then obtain pc\\<^sub>2 where\n        pc\\<^sub>2: \"?pc\\<^sub>1+2 \\<le> pc\\<^sub>2 \\<and> pc\\<^sub>2 < ?pc\\<^sub>2 \\<and>\n              \\<not> caught P pc\\<^sub>2 h\\<^sub>2 xa (compxE\\<^sub>2 e\\<^sub>2 ?pc\\<^sub>1' (size vs))\" and\n        2: \"P \\<turnstile> ?\\<sigma>\\<^sub>1 -jvm\\<rightarrow> handle P C M xa h\\<^sub>2 vs ls\\<^sub>2 pc\\<^sub>2 frs\"\n        using IH\\<^sub>2 beforex\\<^sub>2 TryCatch\\<^sub>1.prems by auto\n      have \"?H pc\\<^sub>2\" using pc\\<^sub>2 jvm_trans[OF 1 2]\n        by (simp add:match_ex_entry) (fastforce)\n      thus \"\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2\" by iprover\n    qed\n  qed\nnext\n  case (TryThrow\\<^sub>1 e\\<^sub>1 h\\<^sub>0 ls\\<^sub>0 a h\\<^sub>1 ls\\<^sub>1 D fs Ci i e\\<^sub>2)\n  let ?\\<sigma>\\<^sub>0 = \"(None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs)\"\n  let ?pc\\<^sub>1 = \"pc + length(compE\\<^sub>2 e\\<^sub>1)\"\n  let ?e = \"try e\\<^sub>1 catch(Ci i) e\\<^sub>2\"\n  let ?xt = \"compxE\\<^sub>2 ?e pc (size vs)\"\n  have I: \"{pc..<pc + length (compE\\<^sub>2 (try e\\<^sub>1 catch(Ci i) e\\<^sub>2))} \\<subseteq> I\"\n   and beforex: \"P,C,M \\<rhd> ?xt/I,size vs\" by fact+\n  have \"PROP ?P e\\<^sub>1 h\\<^sub>0 ls\\<^sub>0 (Throw a) h\\<^sub>1 ls\\<^sub>1 C M pc w a vs frs {pc..<pc + length (compE\\<^sub>2 e\\<^sub>1)}\" by fact\n  moreover have \"P,C,M \\<rhd> compxE\\<^sub>2 e\\<^sub>1 pc (size vs)/{pc..<?pc\\<^sub>1},size vs\"\n    using beforex I pcs_subset by(force elim!: beforex_appendD1)\n    ultimately have\n      \"\\<exists>pc\\<^sub>1. pc \\<le> pc\\<^sub>1 \\<and> pc\\<^sub>1 < ?pc\\<^sub>1 \\<and>\n             \\<not> caught P pc\\<^sub>1 h\\<^sub>1 a (compxE\\<^sub>2 e\\<^sub>1 pc (size vs)) \\<and>\n             P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> handle P C M a h\\<^sub>1 vs ls\\<^sub>1 pc\\<^sub>1 frs\"\n      using TryThrow\\<^sub>1.prems by auto\n    then obtain pc\\<^sub>1 where\n      pc\\<^sub>1_in_e\\<^sub>1: \"pc \\<le> pc\\<^sub>1\" \"pc\\<^sub>1 < ?pc\\<^sub>1\" and\n      pc\\<^sub>1_not_caught: \"\\<not> caught P pc\\<^sub>1 h\\<^sub>1 a (compxE\\<^sub>2 e\\<^sub>1 pc (size vs))\" and\n      0: \"P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> handle P C M a h\\<^sub>1 vs ls\\<^sub>1 pc\\<^sub>1 frs\" by iprover\n  show ?case (is \"?N \\<and> (?eq \\<longrightarrow> (\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2))\")\n  proof\n    show ?N by simp\n  next\n    { assume ?eq\n      with TryThrow\\<^sub>1 pc\\<^sub>1_in_e\\<^sub>1 pc\\<^sub>1_not_caught 0\n      have \"?H pc\\<^sub>1\" by (simp add:match_ex_entry) auto\n      hence \"\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2\" by iprover\n    }\n    thus \"?eq \\<longrightarrow> (\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2)\" by iprover\n  qed\nnext\n  case Nil\\<^sub>1 thus ?case by simp\nnext\n  case (Cons\\<^sub>1 e h\\<^sub>0 ls\\<^sub>0 v h\\<^sub>1 ls\\<^sub>1 es fs h\\<^sub>2 ls\\<^sub>2)\n  let ?pc\\<^sub>1 = \"pc + length(compE\\<^sub>2 e)\"\n  let ?\\<sigma>\\<^sub>0 = \"(None,h\\<^sub>0,(vs,ls\\<^sub>0,C,M,pc)#frs)\"\n  let ?\\<sigma>\\<^sub>1 = \"(None,h\\<^sub>1,(v#vs,ls\\<^sub>1,C,M,?pc\\<^sub>1)#frs)\"\n  have 1: \"P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> ?\\<sigma>\\<^sub>1\" using Cons\\<^sub>1 by fastforce\n  let ?pc\\<^sub>2 = \"?pc\\<^sub>1 + length(compEs\\<^sub>2 es)\"\n  have IHs: \"PROP ?Ps es h\\<^sub>1 ls\\<^sub>1 fs h\\<^sub>2 ls\\<^sub>2 C M ?pc\\<^sub>1 (tl ws) xa es' (v#vs) frs\n    (I - pcs (compxE\\<^sub>2 e pc (length vs)))\" by fact\n  show ?case (is \"?Norm \\<and> ?Err\")\n  proof\n    show ?Norm (is \"?val \\<longrightarrow> ?trans\")\n    proof\n      assume val: ?val\n      note 1\n      also have \"P \\<turnstile> ?\\<sigma>\\<^sub>1 -jvm\\<rightarrow> (None,h\\<^sub>2,(rev(ws) @ vs,ls\\<^sub>2,C,M,?pc\\<^sub>2)#frs)\"\n        using val IHs Cons\\<^sub>1.prems by fastforce\n      finally show ?trans by(simp add:add.assoc)\n    qed\n  next\n    show ?Err (is \"?throw \\<longrightarrow> (\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2)\")\n    proof\n      assume throw: ?throw\n      then obtain pc\\<^sub>2 where\n        pc\\<^sub>2: \"?pc\\<^sub>1 \\<le> pc\\<^sub>2 \\<and> pc\\<^sub>2 < ?pc\\<^sub>2 \\<and>\n              \\<not> caught P pc\\<^sub>2 h\\<^sub>2 xa (compxEs\\<^sub>2 es ?pc\\<^sub>1 (size vs + 1))\" and\n        2: \"P \\<turnstile> ?\\<sigma>\\<^sub>1 -jvm\\<rightarrow> handle P C M xa h\\<^sub>2 (v#vs) ls\\<^sub>2 pc\\<^sub>2 frs\"\n        using IHs Cons\\<^sub>1.prems\n        by(fastforce simp:Cons_eq_append_conv neq_Nil_conv)\n      have \"?H pc\\<^sub>2\" using Cons\\<^sub>1.prems pc\\<^sub>2 jvm_trans[OF 1 2]\n        by (auto simp add: handle_Cons)\n      thus \"\\<exists>pc\\<^sub>2. ?H pc\\<^sub>2\" by iprover\n    qed\n  qed\nnext\n  case ConsThrow\\<^sub>1 thus ?case by (fastforce simp:Cons_eq_append_conv)\nqed\n(*>*)\n\n\n(*FIXME move! *)\nlemma atLeast0AtMost[simp]: \"{0::nat..n} = {..n}\"\nby auto\n\nlemma atLeast0LessThan[simp]: \"{0::nat..<n} = {..<n}\"\nby auto\n\nfun exception :: \"'a exp \\<Rightarrow> addr option\" where\n  \"exception (Throw a) = Some a\"\n| \"exception e = None\"\n\n\nlemma comp\\<^sub>2_correct:\nassumes \"method\": \"P\\<^sub>1 \\<turnstile> C sees M:Ts\\<rightarrow>T = body in C\"\n    and eval:   \"P\\<^sub>1 \\<turnstile>\\<^sub>1 \\<langle>body,(h,ls)\\<rangle> \\<Rightarrow> \\<langle>e',(h',ls')\\<rangle>\"\nshows \"compP\\<^sub>2 P\\<^sub>1 \\<turnstile> (None,h,[([],ls,C,M,0)]) -jvm\\<rightarrow> (exception e',h',[])\"\n(*<*)\n      (is \"_ \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> ?\\<sigma>\\<^sub>1\")\nproof -\n  let ?P = \"compP\\<^sub>2 P\\<^sub>1\"\n  have code: \"?P,C,M,0 \\<rhd> compE\\<^sub>2 body\" using beforeM[OF \"method\"] by auto\n  have xtab: \"?P,C,M \\<rhd> compxE\\<^sub>2 body 0 (size[])/{..<size(compE\\<^sub>2 body)},size[]\"\n    using beforexM[OF \"method\"] by auto\n  \\<comment> \\<open>Distinguish if e' is a value or an exception\\<close>\n  { fix v assume [simp]: \"e' = Val v\"\n    have \"?P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> (None,h',[([v],ls',C,M,size(compE\\<^sub>2 body))])\"\n      using Jcc[OF eval code xtab] by auto\n    also have \"?P \\<turnstile> \\<dots> -jvm\\<rightarrow> ?\\<sigma>\\<^sub>1\" using beforeM[OF \"method\"] by auto\n    finally have ?thesis .\n  }\n  moreover\n  { fix a assume [simp]: \"e' = Throw a\"\n    obtain pc where pc: \"0 \\<le> pc \\<and> pc < size(compE\\<^sub>2 body) \\<and>\n          \\<not> caught ?P pc h' a (compxE\\<^sub>2 body 0 0)\"\n    and 1: \"?P \\<turnstile> ?\\<sigma>\\<^sub>0 -jvm\\<rightarrow> handle ?P C M a h' [] ls' pc []\"\n      using Jcc[OF eval code xtab] by fastforce\n    from pc have \"handle ?P C M a h' [] ls' pc [] = ?\\<sigma>\\<^sub>1\" using xtab \"method\"\n      by(auto simp:handle_def compMb\\<^sub>2_def)\n    with 1 have ?thesis by simp\n  } \n  ultimately show ?thesis using eval\\<^sub>1_final[OF eval] by(auto simp:final_def)\nqed\n(*>*)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Jinja/Compiler/Correctness2.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5506073655352404, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.2860522664194274}}
{"text": "theory v1_isar_new_original_K\n  imports Main \"../../QML\"\nbegin\n\n(* (T x y) \\<equiv> x made from y *)\nconsts makeTable ::  \"\\<mu> \\<Rightarrow> \\<mu> \\<Rightarrow> \\<sigma>\"  (\"T\") \n(* lemma necessity_of_distinctness: \"\\<lfloor>(\\<^bold>\\<box>(\\<^bold>\\<forall>x. \\<^bold>\\<box>(\\<^bold>\\<forall>y. \\<^bold>\\<box>(\\<^bold>\\<not>(x\\<^bold>=\\<^sup>Ly) \\<^bold>\\<rightarrow> \\<^bold>\\<box>(\\<^bold>\\<not>(x\\<^bold>=\\<^sup>Ly))))))\\<rfloor>\" by auto *)\n\nlemma \n  assumes compossibilty1: \"\\<lfloor>(\\<^bold>\\<box>(\\<^bold>\\<forall>x1. \\<^bold>\\<forall>y1. T x1 y1 \\<^bold>\\<rightarrow> \\<^bold>\\<box>(\\<^bold>\\<forall>x2. \\<^bold>\\<forall>y2. ((\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2)) \\<^bold>\\<and> T x2 y2) \\<^bold>\\<rightarrow> \\<^bold>\\<diamond>(T x1 y1 \\<^bold>\\<and> T x2 y2))))\\<rfloor>\"\n  assumes origin_uniqueness1: \"\\<lfloor>(\\<^bold>\\<box>(\\<^bold>\\<forall>x1. \\<^bold>\\<forall>y1. \\<^bold>\\<box>(\\<^bold>\\<forall>x2. \\<^bold>\\<forall>y2. \\<^bold>\\<box>((\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2) \\<^bold>\\<and> (T x1 y1) \\<^bold>\\<and> (T x2 y2)) \\<^bold>\\<rightarrow> (\\<^bold>\\<not>(x1\\<^bold>=\\<^sup>Lx2))))))\\<rfloor>\" \n  shows origin_essentialism1: \"\\<lfloor>(\\<^bold>\\<box>(\\<^bold>\\<forall>x1. \\<^bold>\\<forall>y1. T x1 y1 \\<^bold>\\<rightarrow> \\<^bold>\\<box>(\\<^bold>\\<forall>x2. \\<^bold>\\<forall>y2. (\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2) \\<^bold>\\<and> (T x2 y2)) \\<^bold>\\<rightarrow> \\<^bold>\\<not>(x1\\<^bold>=\\<^sup>Lx2))))\\<rfloor>\"\n\nproof(rule allI)\n  fix a\n  show \"(\\<^bold>\\<box>(\\<^bold>\\<forall>x1. \\<^bold>\\<forall>y1. T x1 y1 \\<^bold>\\<rightarrow> \\<^bold>\\<box>(\\<^bold>\\<forall>x2. \\<^bold>\\<forall>y2. (\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2) \\<^bold>\\<and> (T x2 y2)) \\<^bold>\\<rightarrow> \\<^bold>\\<not>(x1\\<^bold>=\\<^sup>Lx2)))) a\"\n  proof(rule allI)\n    fix b\n    show \"a r b \\<longrightarrow> ((\\<^bold>\\<forall>x1. \\<^bold>\\<forall>y1. T x1 y1 \\<^bold>\\<rightarrow> \\<^bold>\\<box>(\\<^bold>\\<forall>x2. \\<^bold>\\<forall>y2. (\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2) \\<^bold>\\<and> (T x2 y2)) \\<^bold>\\<rightarrow> \\<^bold>\\<not>(x1\\<^bold>=\\<^sup>Lx2))) b)\"\n    proof(rule impI)\n      assume \"a r b\"\n      show \"((\\<^bold>\\<forall>x1. \\<^bold>\\<forall>y1. T x1 y1 \\<^bold>\\<rightarrow> \\<^bold>\\<box>(\\<^bold>\\<forall>x2. \\<^bold>\\<forall>y2. (\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2) \\<^bold>\\<and> (T x2 y2)) \\<^bold>\\<rightarrow> \\<^bold>\\<not>(x1\\<^bold>=\\<^sup>Lx2))) b)\"\n      proof(rule allI)\n        fix x1\n        show \"((\\<^bold>\\<forall>y1. T x1 y1 \\<^bold>\\<rightarrow> \\<^bold>\\<box>(\\<^bold>\\<forall>x2. \\<^bold>\\<forall>y2. (\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2) \\<^bold>\\<and> (T x2 y2)) \\<^bold>\\<rightarrow> \\<^bold>\\<not>(x1\\<^bold>=\\<^sup>Lx2))) b)\"\n        proof(rule allI)\n          fix y1\n          show \"((T x1 y1 \\<^bold>\\<rightarrow> \\<^bold>\\<box>(\\<^bold>\\<forall>x2. \\<^bold>\\<forall>y2. (\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2) \\<^bold>\\<and> (T x2 y2)) \\<^bold>\\<rightarrow> \\<^bold>\\<not>(x1\\<^bold>=\\<^sup>Lx2))) b)\"\n          proof (rule impI)\n            assume table_x1_from_y1: \"T x1 y1 b\"          \n            show \"((\\<^bold>\\<box>(\\<^bold>\\<forall>x2. \\<^bold>\\<forall>y2. (\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2) \\<^bold>\\<and> (T x2 y2)) \\<^bold>\\<rightarrow> \\<^bold>\\<not>(x1\\<^bold>=\\<^sup>Lx2))) b)\"\n            proof(rule allI)\n              fix c            \n              show \"b r c \\<longrightarrow> (((\\<^bold>\\<forall>x2. \\<^bold>\\<forall>y2. (\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2) \\<^bold>\\<and> (T x2 y2)) \\<^bold>\\<rightarrow> \\<^bold>\\<not>(x1\\<^bold>=\\<^sup>Lx2))) c)\"\n              proof (rule impI)\n                assume \"b r c\"              \n                show \"(((\\<^bold>\\<forall>x2. \\<^bold>\\<forall>y2. (\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2) \\<^bold>\\<and> (T x2 y2)) \\<^bold>\\<rightarrow> \\<^bold>\\<not>(x1\\<^bold>=\\<^sup>Lx2))) c)\"\n                proof (rule allI)\n                  fix x2 \n                  show \"(((\\<^bold>\\<forall>y2. (\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2) \\<^bold>\\<and> (T x2 y2)) \\<^bold>\\<rightarrow> \\<^bold>\\<not>(x1\\<^bold>=\\<^sup>Lx2))) c)\"\n                  proof (rule allI)\n                    fix y2 \n                    show \"((((\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2) \\<^bold>\\<and> (T x2 y2)) \\<^bold>\\<rightarrow> \\<^bold>\\<not>(x1\\<^bold>=\\<^sup>Lx2))) c)\"\n                    proof (rule impI)\n                      assume antecedent: \"((\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2)) \\<^bold>\\<and> (T x2 y2)) c\"\n                      show \"(\\<^bold>\\<not>(x1\\<^bold>=\\<^sup>Lx2)) c\"\n                      proof (rule notI)\n                        assume \"(x1\\<^bold>=\\<^sup>Lx2) c\"\n                        from antecedent have table_x2_from_y2: \"T x2 y2 c\" by (rule conjE)\n                        from antecedent have non_overlapping: \"(\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2)) c\" by (rule conjE)\n\n                        from compossibilty1 have \"(\\<^bold>\\<box>(\\<^bold>\\<forall>x1. \\<^bold>\\<forall>y1. T x1 y1 \\<^bold>\\<rightarrow> \\<^bold>\\<box>(\\<^bold>\\<forall>x2. \\<^bold>\\<forall>y2. ((\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2)) \\<^bold>\\<and> T x2 y2) \\<^bold>\\<rightarrow> \\<^bold>\\<diamond>(T x1 y1 \\<^bold>\\<and> T x2 y2)))) a\"..\n                        then have \"((T x1 y1 \\<^bold>\\<rightarrow> \\<^bold>\\<box>(\\<^bold>\\<forall>x2. \\<^bold>\\<forall>y2. ((\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2)) \\<^bold>\\<and> T x2 y2) \\<^bold>\\<rightarrow> \\<^bold>\\<diamond>(T x1 y1 \\<^bold>\\<and> T x2 y2))) b)\" \n                          using `a r b` by auto\n                        then have \"((\\<^bold>\\<box>(\\<^bold>\\<forall>x2. \\<^bold>\\<forall>y2. ((\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2)) \\<^bold>\\<and> T x2 y2) \\<^bold>\\<rightarrow> \\<^bold>\\<diamond>(T x1 y1 \\<^bold>\\<and> T x2 y2))) b)\" \n                          using table_x1_from_y1 by auto\n                        then have \"((((\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2)) \\<^bold>\\<and> T x2 y2) \\<^bold>\\<rightarrow> \\<^bold>\\<diamond>(T x1 y1 \\<^bold>\\<and> T x2 y2)) c)\" \n                          using `b r c` by auto\n                        then have \"(\\<^bold>\\<diamond>(T x1 y1 \\<^bold>\\<and> T x2 y2)) c\" \n                          using antecedent by auto\n                        then obtain d where d: \"c r d \\<and> (((T x1 y1 \\<^bold>\\<and> T x2 y2)) d)\" by (rule exE)\n                        then have \"c r d\" by (rule conjE)\n                        have \"(T x1 y1 \\<^bold>\\<and> T x2 y2) d\" \n                          using `c r d \\<and> (((T x1 y1 \\<^bold>\\<and> T x2 y2)) d)` by (rule conjE) \n\n                        from  origin_uniqueness1 have \"(\\<^bold>\\<box>(\\<^bold>\\<forall>x1. \\<^bold>\\<forall>y1. \\<^bold>\\<box>(\\<^bold>\\<forall>x2. \\<^bold>\\<forall>y2. \\<^bold>\\<box>((\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2) \\<^bold>\\<and> (T x1 y1) \\<^bold>\\<and> (T x2 y2)) \\<^bold>\\<rightarrow> (\\<^bold>\\<not>(x1\\<^bold>=\\<^sup>Lx2)))))) a\"..\n                        then have \"((\\<^bold>\\<box>(\\<^bold>\\<forall>x2. \\<^bold>\\<forall>y2. \\<^bold>\\<box>((\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2) \\<^bold>\\<and> (T x1 y1) \\<^bold>\\<and> (T x2 y2)) \\<^bold>\\<rightarrow> (\\<^bold>\\<not>(x1\\<^bold>=\\<^sup>Lx2)))))) b\" \n                          using `a r b` by auto\n                        then have \"(((\\<^bold>\\<box>((\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2) \\<^bold>\\<and> (T x1 y1) \\<^bold>\\<and> (T x2 y2)) \\<^bold>\\<rightarrow> (\\<^bold>\\<not>(x1\\<^bold>=\\<^sup>Lx2)))))) c\"  \n                          using `b r c` by metis\n                        then have \"(((((\\<^bold>\\<not>(y1\\<^bold>=\\<^sup>Ly2) \\<^bold>\\<and> (T x1 y1) \\<^bold>\\<and> (T x2 y2)) \\<^bold>\\<rightarrow> (\\<^bold>\\<not>(x1\\<^bold>=\\<^sup>Lx2)))))) d\" \n                          using `c r d` by auto\n                        then have \"(\\<^bold>\\<not>(x1\\<^bold>=\\<^sup>Lx2)) d\" \n                          using `(T x1 y1 \\<^bold>\\<and> T x2 y2) d` and table_x1_from_y1 and `b r c` and `c r d` by (meson antecedent)\n                        then show False using `(x1\\<^bold>=\\<^sup>Lx2) c` and `c r d` by auto\n                      qed\n                    qed\n                  qed\n                qed\n              qed\n            qed\n          qed\n        qed\n      qed\n    qed\n  qed\nqed\n\n\nend\n", "meta": {"author": "hotessy", "repo": "origin_essen_public", "sha": "c91f54abfade669c30db34d2bbfcccbe1b97d23a", "save_path": "github-repos/isabelle/hotessy-origin_essen_public", "path": "github-repos/isabelle/hotessy-origin_essen_public/origin_essen_public-c91f54abfade669c30db34d2bbfcccbe1b97d23a/experiments/v1_isar_new_original_K.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.600188359260205, "lm_q2_score": 0.476579651063676, "lm_q1q2_score": 0.2860375588287087}}
{"text": "(*  Title:      Jinja/J/WellType.thy\n\n    Author:     Tobias Nipkow\n    Copyright   2003 Technische Universitaet Muenchen\n*)\n\nheader {* \\isaheader{Well-typedness of Jinja expressions} *}\n\ntheory WellType\nimports \"../Common/Objects\" Expr\nbegin\n\ntype_synonym\n  env  = \"vname \\<rightharpoonup> ty\"\n\ninductive\n  WT :: \"[J_prog,env, expr     , ty     ] \\<Rightarrow> bool\"\n         (\"_,_ \\<turnstile> _ :: _\"   [51,51,51]50)\n  and WTs :: \"[J_prog,env, expr list, ty list] \\<Rightarrow> bool\"\n         (\"_,_ \\<turnstile> _ [::] _\" [51,51,51]50)\n  for P :: J_prog\nwhere\n  \n  WTNew:\n  \"is_class P C  \\<Longrightarrow>\n  P,E \\<turnstile> new C :: Class C\"\n\n| WTCast:\n  \"\\<lbrakk> P,E \\<turnstile> e :: Class D;  is_class P C;  P \\<turnstile> C \\<preceq>\\<^sup>* D \\<or> P \\<turnstile> D \\<preceq>\\<^sup>* C \\<rbrakk>\n  \\<Longrightarrow> P,E \\<turnstile> Cast C e :: Class C\"\n\n| WTVal:\n  \"typeof v = Some T \\<Longrightarrow>\n  P,E \\<turnstile> Val v :: T\"\n\n| WTVar:\n  \"E V = Some T \\<Longrightarrow>\n  P,E \\<turnstile> Var V :: T\"\n(*\nWTBinOp:\n  \"\\<lbrakk> P,E \\<turnstile> e\\<^sub>1 :: T\\<^sub>1;  P,E \\<turnstile> e\\<^sub>2 :: T\\<^sub>2;\n     case bop of Eq \\<Rightarrow> (P \\<turnstile> T\\<^sub>1 \\<le> T\\<^sub>2 \\<or> P \\<turnstile> T\\<^sub>2 \\<le> T\\<^sub>1) \\<and> T = Boolean\n               | Add \\<Rightarrow> T\\<^sub>1 = Integer \\<and> T\\<^sub>2 = Integer \\<and> T = Integer \\<rbrakk>\n  \\<Longrightarrow> P,E \\<turnstile> e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2 :: T\"\n*)\n| WTBinOpEq:\n  \"\\<lbrakk> P,E \\<turnstile> e\\<^sub>1 :: T\\<^sub>1;  P,E \\<turnstile> e\\<^sub>2 :: T\\<^sub>2; P \\<turnstile> T\\<^sub>1 \\<le> T\\<^sub>2 \\<or> P \\<turnstile> T\\<^sub>2 \\<le> T\\<^sub>1 \\<rbrakk>\n  \\<Longrightarrow> P,E \\<turnstile> e\\<^sub>1 \\<guillemotleft>Eq\\<guillemotright> e\\<^sub>2 :: Boolean\"\n\n| WTBinOpAdd:\n  \"\\<lbrakk> P,E \\<turnstile> e\\<^sub>1 :: Integer;  P,E \\<turnstile> e\\<^sub>2 :: Integer \\<rbrakk>\n  \\<Longrightarrow> P,E \\<turnstile> e\\<^sub>1 \\<guillemotleft>Add\\<guillemotright> e\\<^sub>2 :: Integer\"\n\n| WTLAss:\n  \"\\<lbrakk> E V = Some T;  P,E \\<turnstile> e :: T';  P \\<turnstile> T' \\<le> T;  V \\<noteq> this \\<rbrakk>\n  \\<Longrightarrow> P,E \\<turnstile> V:=e :: Void\"\n\n| WTFAcc:\n  \"\\<lbrakk> P,E \\<turnstile> e :: Class C;  P \\<turnstile> C sees F:T in D \\<rbrakk>\n  \\<Longrightarrow> P,E \\<turnstile> e\\<bullet>F{D} :: T\"\n\n| WTFAss:\n  \"\\<lbrakk> P,E \\<turnstile> e\\<^sub>1 :: Class C;  P \\<turnstile> C sees F:T in D;  P,E \\<turnstile> e\\<^sub>2 :: T';  P \\<turnstile> T' \\<le> T \\<rbrakk>\n  \\<Longrightarrow> P,E \\<turnstile> e\\<^sub>1\\<bullet>F{D}:=e\\<^sub>2 :: Void\"\n\n| WTCall:\n  \"\\<lbrakk> P,E \\<turnstile> e :: Class C;  P \\<turnstile> C sees M:Ts \\<rightarrow> T = (pns,body) in D;\n     P,E \\<turnstile> es [::] Ts';  P \\<turnstile> Ts' [\\<le>] Ts \\<rbrakk>\n  \\<Longrightarrow> P,E \\<turnstile> e\\<bullet>M(es) :: T\"\n\n| WTBlock:\n  \"\\<lbrakk> is_type P T;  P,E(V \\<mapsto> T) \\<turnstile> e :: T' \\<rbrakk>\n  \\<Longrightarrow>  P,E \\<turnstile> {V:T; e} :: T'\"\n\n| WTSeq:\n  \"\\<lbrakk> P,E \\<turnstile> e\\<^sub>1::T\\<^sub>1;  P,E \\<turnstile> e\\<^sub>2::T\\<^sub>2 \\<rbrakk>\n  \\<Longrightarrow>  P,E \\<turnstile> e\\<^sub>1;;e\\<^sub>2 :: T\\<^sub>2\"\n| WTCond:\n  \"\\<lbrakk> P,E \\<turnstile> e :: Boolean;  P,E \\<turnstile> e\\<^sub>1::T\\<^sub>1;  P,E \\<turnstile> e\\<^sub>2::T\\<^sub>2;\n     P \\<turnstile> T\\<^sub>1 \\<le> T\\<^sub>2 \\<or> P \\<turnstile> T\\<^sub>2 \\<le> T\\<^sub>1;  P \\<turnstile> T\\<^sub>1 \\<le> T\\<^sub>2 \\<longrightarrow> T = T\\<^sub>2;  P \\<turnstile> T\\<^sub>2 \\<le> T\\<^sub>1 \\<longrightarrow> T = T\\<^sub>1 \\<rbrakk>\n  \\<Longrightarrow> P,E \\<turnstile> if (e) e\\<^sub>1 else e\\<^sub>2 :: T\"\n\n| WTWhile:\n  \"\\<lbrakk> P,E \\<turnstile> e :: Boolean;  P,E \\<turnstile> c::T \\<rbrakk>\n  \\<Longrightarrow> P,E \\<turnstile> while (e) c :: Void\"\n\n| WTThrow:\n  \"P,E \\<turnstile> e :: Class C  \\<Longrightarrow> \n  P,E \\<turnstile> throw e :: Void\"\n\n| WTTry:\n  \"\\<lbrakk> P,E \\<turnstile> e\\<^sub>1 :: T;  P,E(V \\<mapsto> Class C) \\<turnstile> e\\<^sub>2 :: T; is_class P C \\<rbrakk>\n  \\<Longrightarrow> P,E \\<turnstile> try e\\<^sub>1 catch(C V) e\\<^sub>2 :: T\"\n\n-- \"well-typed expression lists\"\n\n| WTNil:\n  \"P,E \\<turnstile> [] [::] []\"\n\n| WTCons:\n  \"\\<lbrakk> P,E \\<turnstile> e :: T;  P,E \\<turnstile> es [::] Ts \\<rbrakk>\n  \\<Longrightarrow>  P,E \\<turnstile> e#es [::] T#Ts\"\n\n(*<*)\n(*\nlemmas [intro!] = WTNew WTCast WTVal WTVar WTBinOp WTLAss WTFAcc WTFAss WTCall WTBlock WTSeq\n                  WTWhile WTThrow WTTry WTNil WTCons\nlemmas [intro]  = WTCond1 WTCond2\n*)\ndeclare WT_WTs.intros[intro!] (* WTNil[iff] *)\n\nlemmas WT_WTs_induct = WT_WTs.induct [split_format (complete)]\n  and WT_WTs_inducts = WT_WTs.inducts [split_format (complete)]\n(*>*)\n\n\n\nlemma [iff]: \"(P,E \\<turnstile> e#es [::] T#Ts) = (P,E \\<turnstile> e :: T \\<and> P,E \\<turnstile> es [::] Ts)\"\n(*<*)\napply(rule iffI)\napply (auto elim: WTs.cases)\ndone\n(*>*)\n\nlemma [iff]: \"(P,E \\<turnstile> (e#es) [::] Ts) =\n  (\\<exists>U Us. Ts = U#Us \\<and> P,E \\<turnstile> e :: U \\<and> P,E \\<turnstile> es [::] Us)\"\n(*<*)\napply(rule iffI)\napply (auto elim: WTs.cases)\ndone\n(*>*)\n\nlemma [iff]: \"\\<And>Ts. (P,E \\<turnstile> es\\<^sub>1 @ es\\<^sub>2 [::] Ts) =\n  (\\<exists>Ts\\<^sub>1 Ts\\<^sub>2. Ts = Ts\\<^sub>1 @ Ts\\<^sub>2 \\<and> P,E \\<turnstile> es\\<^sub>1 [::] Ts\\<^sub>1 \\<and> P,E \\<turnstile> es\\<^sub>2[::]Ts\\<^sub>2)\"\n(*<*)\napply(induct es\\<^sub>1 type:list)\n apply simp\napply clarsimp\napply(erule thin_rl)\napply (rule iffI)\n apply clarsimp\n apply(rule exI)+\n apply(rule conjI)\n  prefer 2 apply blast\n apply simp\napply fastforce\ndone\n(*>*)\n\nlemma [iff]: \"P,E \\<turnstile> Val v :: T = (typeof v = Some T)\"\n(*<*)\napply(rule iffI)\napply (auto elim: WT.cases)\ndone\n(*>*)\n\nlemma [iff]: \"P,E \\<turnstile> Var V :: T = (E V = Some T)\"\n(*<*)\napply(rule iffI)\napply (auto elim: WT.cases)\ndone\n(*>*)\n\nlemma [iff]: \"P,E \\<turnstile> e\\<^sub>1;;e\\<^sub>2 :: T\\<^sub>2 = (\\<exists>T\\<^sub>1. P,E \\<turnstile> e\\<^sub>1::T\\<^sub>1 \\<and> P,E \\<turnstile> e\\<^sub>2::T\\<^sub>2)\"\n(*<*)\napply(rule iffI)\napply (auto elim: WT.cases)\ndone\n(*>*)\n\nlemma [iff]: \"(P,E \\<turnstile> {V:T; e} :: T') = (is_type P T \\<and> P,E(V\\<mapsto>T) \\<turnstile> e :: T')\"\n(*<*)\napply(rule iffI)\napply (auto elim: WT.cases)\ndone\n(*>*)\n\n(*<*)\ninductive_cases WT_elim_cases[elim!]:\n  \"P,E \\<turnstile> V :=e :: T\"\n  \"P,E \\<turnstile> if (e) e\\<^sub>1 else e\\<^sub>2 :: T\"\n  \"P,E \\<turnstile> while (e) c :: T\"\n  \"P,E \\<turnstile> throw e :: T\"\n  \"P,E \\<turnstile> try e\\<^sub>1 catch(C V) e\\<^sub>2 :: T\"\n  \"P,E \\<turnstile> Cast D e :: T\"\n  \"P,E \\<turnstile> a\\<bullet>F{D} :: T\"\n  \"P,E \\<turnstile> a\\<bullet>F{D} := v :: T\"\n  \"P,E \\<turnstile> e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2 :: T\"\n  \"P,E \\<turnstile> new C :: T\"\n  \"P,E \\<turnstile> e\\<bullet>M(ps) :: T\"\n(*>*)\n\n\nlemma wt_env_mono:\n  \"P,E \\<turnstile> e :: T \\<Longrightarrow> (\\<And>E'. E \\<subseteq>\\<^sub>m E' \\<Longrightarrow> P,E' \\<turnstile> e :: T)\" and \n  \"P,E \\<turnstile> es [::] Ts \\<Longrightarrow> (\\<And>E'. E \\<subseteq>\\<^sub>m E' \\<Longrightarrow> P,E' \\<turnstile> es [::] Ts)\"\n(*<*)\napply(induct rule: WT_WTs_inducts)\napply(simp add: WTNew)\napply(fastforce simp: WTCast)\napply(fastforce simp: WTVal)\napply(simp add: WTVar map_le_def dom_def)\napply(fastforce simp: WTBinOpEq)\napply(fastforce simp: WTBinOpAdd)\napply(force simp:map_le_def)\napply(fastforce simp: WTFAcc)\napply(fastforce simp: WTFAss del:WT_WTs.intros WT_elim_cases)\napply(fastforce simp: WTCall)\napply(fastforce simp: map_le_def WTBlock)\napply(fastforce simp: WTSeq)\napply(fastforce simp: WTCond)\napply(fastforce simp: WTWhile)\napply(fastforce simp: WTThrow)\napply(fastforce simp: WTTry map_le_def dom_def)\napply(simp add: WTNil)\napply(simp add: WTCons)\ndone\n(*>*)\n\n\nlemma WT_fv: \"P,E \\<turnstile> e :: T \\<Longrightarrow> fv e \\<subseteq> dom E\"\nand \"P,E \\<turnstile> es [::] Ts \\<Longrightarrow> fvs es \\<subseteq> dom E\"\n(*<*)\napply(induct rule:WT_WTs.inducts)\napply(simp_all del: fun_upd_apply)\napply fast+\ndone\n\nend\n(*>*)\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Jinja/J/WellType.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6893056167854461, "lm_q2_score": 0.4148988457967688, "lm_q1q2_score": 0.2859921048055114}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory PackedTypes\nimports \"Word_Lib.WordSetup\" CProof\nbegin\n\nsection \\<open>Underlying definitions for the class axioms\\<close>\n\ntext \\<open>field_access / field_update is the identity for packed types\\<close>\n\ndefinition fa_fu_idem :: \"'a field_desc \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"fa_fu_idem fd n \\<equiv>\n     \\<forall>bs bs' v. length bs = n \\<longrightarrow> length bs' = n \\<longrightarrow> field_access fd (field_update fd bs v) bs' = bs\"\n\n(* Is it better to do this or to use a fold over td?  This seems easier to use *)\nprimrec\n  td_fafu_idem :: \"'a field_desc typ_desc \\<Rightarrow> bool\" and\n  td_fafu_idem_struct :: \"'a field_desc typ_struct \\<Rightarrow> bool\" and\n  td_fafu_idem_list :: \" ('a field_desc typ_desc, char list) dt_pair list \\<Rightarrow> bool\" and\n  td_fafu_idem_pair :: \"('a field_desc typ_desc, char list) dt_pair \\<Rightarrow> bool\"\nwhere\n  fai0: \"td_fafu_idem (TypDesc ts n) = td_fafu_idem_struct ts\"\n\n| fai1: \"td_fafu_idem_struct (TypScalar n algn d) = fa_fu_idem d n\"\n| fai2: \"td_fafu_idem_struct (TypAggregate ts) = td_fafu_idem_list ts\"\n\n| fai3: \"td_fafu_idem_list [] = True\"\n| fai4: \"td_fafu_idem_list (x#xs) = (td_fafu_idem_pair x \\<and> td_fafu_idem_list xs)\"\n\n| fai5: \"td_fafu_idem_pair (DTPair x n) = td_fafu_idem x\"\n\nlemmas td_fafu_idem_simps = fai0 fai1 fai2 fai3 fai4 fai5\n\ntext \\<open>field_access is independent of the underlying bytes\\<close>\n\ndefinition  fa_heap_indep :: \"'a field_desc \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"fa_heap_indep fd n \\<equiv>\n     \\<forall>bs bs' v. length bs = n \\<longrightarrow> length bs' = n \\<longrightarrow> field_access fd v bs = field_access fd v bs'\"\n\n\nprimrec\n  td_fa_hi :: \"'a field_desc typ_desc \\<Rightarrow> bool\" and\n  td_fa_hi_struct :: \"'a field_desc typ_struct \\<Rightarrow> bool\" and\n  td_fa_hi_list :: \"('a field_desc typ_desc, char list) dt_pair list \\<Rightarrow> bool\" and\n  td_fa_hi_pair :: \"('a field_desc typ_desc, char list) dt_pair \\<Rightarrow> bool\"\nwhere\n  fahi0: \"td_fa_hi (TypDesc ts n) = td_fa_hi_struct ts\"\n\n| fahi1: \"td_fa_hi_struct (TypScalar n algn d) = fa_heap_indep d n\"\n| fahi2: \"td_fa_hi_struct (TypAggregate ts) = td_fa_hi_list ts\"\n\n| fahi3: \"td_fa_hi_list [] = True\"\n| fahi4: \"td_fa_hi_list (x#xs) = (td_fa_hi_pair x \\<and> td_fa_hi_list xs)\"\n\n| fahi5: \"td_fa_hi_pair (DTPair x n) = td_fa_hi x\"\n\nlemmas td_fa_hi_simps = fahi0 fahi1 fahi2 fahi3 fahi4 fahi5\n\nsection \\<open>Lemmas about td_fafu_idem\\<close>\n\nlemma field_lookup_td_fafu_idem:\n  shows \"\\<And>(s :: 'a field_desc typ_desc) f m n.\n           \\<lbrakk> field_lookup t f m = Some (s, n); td_fafu_idem t \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  and   \"\\<And>(s :: 'a field_desc typ_desc) f m n.\n           \\<lbrakk> field_lookup_struct st f m = Some (s, n); td_fafu_idem_struct st \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  and   \"\\<And>(s :: 'a field_desc typ_desc) f m n.\n           \\<lbrakk> field_lookup_list ts f m = Some (s, n); td_fafu_idem_list ts \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  and   \"\\<And>(s :: 'a field_desc typ_desc) f m n.\n           \\<lbrakk> field_lookup_pair p f m = Some (s, n); td_fafu_idem_pair p \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  by (induct t and st and ts and p) (auto split: if_split_asm option.splits)\n\nlemma field_access_update_same:\n  fixes t :: \"'a :: mem_type field_desc typ_desc\" and st :: \"'a field_desc typ_struct\"\n  shows \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem t; wf_fd t; length bs = size_td t; length bs' = size_td t\\<rbrakk>\n  \\<Longrightarrow> access_ti t (update_ti t bs v) bs' = bs\"\n  and \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem_struct st; wf_fd_struct st; length bs = size_td_struct st; length bs' = size_td_struct st \\<rbrakk>\n  \\<Longrightarrow> access_ti_struct st (update_ti_struct st bs v) bs' = bs\"\n  and \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem_list ts; wf_fd_list ts; length bs = size_td_list ts; length bs' = size_td_list ts\\<rbrakk>\n  \\<Longrightarrow> access_ti_list ts (update_ti_list ts bs v) bs' = bs\"\n  and \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem_pair p; wf_fd_pair p; length bs = size_td_pair p; length bs' = size_td_pair p\\<rbrakk>\n  \\<Longrightarrow> access_ti_pair p (update_ti_pair p bs v) bs' = bs\"\nproof (induct t and st and ts and p)\n  case TypScalar thus ?case by (clarsimp simp: fa_fu_idem_def)\nnext\n  case (Cons_typ_desc p' ts' v bs bs')\n  hence \"fu_commutes (update_ti_pair_t p') (update_ti_list_t ts')\" by clarsimp\n  moreover\n  have \"update_ti_pair p' (take (size_td_pair p') bs) = update_ti_pair_t p' (take (size_td_pair p') bs)\"\n    using Cons_typ_desc.prems by (simp add: update_ti_pair_t_def min_ll)\n  moreover\n  have \"update_ti_list ts' (drop (size_td_pair p') bs) = update_ti_list_t ts' (drop (size_td_pair p') bs)\"\n    using Cons_typ_desc.prems by (simp add: update_ti_list_t_def)\n  ultimately have updeq:\n    \"(update_ti_pair p' (take (size_td_pair p') bs) (update_ti_list ts' (drop (size_td_pair p') bs) v))\n    = (update_ti_list ts' (drop (size_td_pair p') bs) (update_ti_pair p' (take (size_td_pair p') bs) v))\"\n    unfolding fu_commutes_def by simp\n\n  show ?case using Cons_typ_desc.prems\n    by (clarsimp simp add: Cons_typ_desc.hyps) (simp add: updeq  Cons_typ_desc.hyps)\nqed simp+\n\nlemma access_ti_pair_dt_fst:\n  \"access_ti_pair p v bs = access_ti (dt_fst p) v bs\"\n  by (cases p, simp)\n\nlemma size_td_pair_dt_fst:\n  \"size_td_pair p = size_td (dt_fst p)\"\n  by (cases p, simp)\n\nlemma wf_fd_pair_dt_fst:\n  \"wf_fd_pair p = wf_fd (dt_fst p)\"\n  by (cases p, simp)\n\nlemma field_lookup_offset2:\n  assumes fl: \"(field_lookup t f (m + n) = Some (s, q))\"\n  shows   \"field_lookup t f m = Some (s, q - n)\"\nproof -\n  from fl have le: \"m + n \\<le> q\"\n    by (rule field_lookup_offset_le)\n\n  hence \"q = (m + n) + (q - (m + n))\"\n    by simp\n\n  hence \"field_lookup t f (m + n) = Some (s, (m + n) + (q - (m + n)))\" using fl by simp\n\n  hence \"field_lookup t f m = Some (s, m + (q - (m + n)))\"\n    by (rule iffD1 [OF field_lookup_offset'(1)])\n\n  thus ?thesis using le by simp\nqed\n\nlemma field_lookup_offset2_list:\n  assumes fl: \"(field_lookup_list ts f (m + n) = Some (s, q))\"\n  shows   \"field_lookup_list ts f m = Some (s, q - n)\"\nproof -\n  from fl have le: \"m + n \\<le> q\"\n    by (rule field_lookup_offset_le)\n\n  hence \"q = (m + n) + (q - (m + n))\"\n    by simp\n\n  hence \"field_lookup_list ts f (m + n) = Some (s, (m + n) + (q - (m + n)))\" using fl by simp\n\n  hence \"field_lookup_list ts f m = Some (s, m + (q - (m + n)))\"\n    by (rule iffD1 [OF field_lookup_offset'(3)])\n\n  thus ?thesis using le by simp\nqed\n\nlemma field_lookup_offset2_pair:\n  assumes fl: \"(field_lookup_pair p f (m + n) = Some (s, q))\"\n  shows   \"field_lookup_pair p f m = Some (s, q - n)\"\nproof -\n  from fl have le: \"m + n \\<le> q\"\n    by (rule field_lookup_offset_le)\n\n  hence \"q = (m + n) + (q - (m + n))\"\n    by simp\n\n  hence \"field_lookup_pair p f (m + n) = Some (s, (m + n) + (q - (m + n)))\" using fl by simp\n\n  hence \"field_lookup_pair p f m = Some (s, m + (q - (m + n)))\"\n    by (rule iffD1 [OF field_lookup_offset'(4)])\n\n  thus ?thesis using le by simp\nqed\n\nlemma field_lookup_offset_size':\n  shows \"field_lookup t f 0 = Some (t',n) \\<Longrightarrow> size_td t' + n \\<le> size_td t\"\n  apply(drule td_set_field_lookupD)\n  apply(erule td_set_offset_size)\ndone\n\nlemma field_access_update_nth_inner:\n  shows \"\\<And>f (s :: 'a :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk> field_lookup t f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd t;\n  length bs = size_td s; length bs' = size_td t \\<rbrakk>\n  \\<Longrightarrow> access_ti t (update_ti s bs v) bs' ! x = bs ! (x - n)\"\n\n  and \"\\<And>f (s :: 'a  :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk>field_lookup_struct st f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd_struct st;\n  length bs = size_td s; length bs' = size_td_struct st \\<rbrakk>\n  \\<Longrightarrow> access_ti_struct st (update_ti s bs v) bs' ! x = bs ! (x - n)\"\n\n  and \"\\<And>f (s :: 'a  :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk>field_lookup_list ts f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd_list ts;\n  length bs = size_td s; length bs' = size_td_list ts\\<rbrakk>\n  \\<Longrightarrow> access_ti_list ts (update_ti s bs v) bs' ! x = bs ! (x - n)\"\n\n  and \"\\<And>f (s :: 'a  :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk>field_lookup_pair p f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd_pair p;\n  length bs = size_td s; length bs' = size_td_pair p\\<rbrakk>\n  \\<Longrightarrow> access_ti_pair p (update_ti s bs v) bs' ! x = bs ! (x - n)\"\nproof (induct t and st and ts and p)\n  case (TypDesc typ_struct ls f s n x v bs bs')\n\n  show ?case\n  proof (cases \"f = []\")\n    case False thus ?thesis using TypDesc by clarsimp\n  next\n    case True\n    thus ?thesis using TypDesc.prems\n      by (simp add: field_access_update_same)\n  qed\nnext\n  case (Cons_typ_desc p' ts' f s n x v bs bs')\n  have nlex: \"n \\<le> x\" and xln: \"x < n + size_td s\"\n    and lbs: \"length bs = size_td s\" and lbs': \"length bs' = size_td_list (p' # ts')\" by fact+\n  from Cons_typ_desc have wf: \"wf_fd (dt_fst p')\" and wfts: \"wf_fd_list ts'\" by (cases p', auto)\n\n  {\n    assume fl: \"field_lookup_list ts' f (size_td (dt_fst p')) = Some (s, n)\"\n\n    hence mlt: \"size_td (dt_fst p') \\<le> n\"\n      by (rule field_lookup_offset_le)\n\n    hence \"size_td (dt_fst p') \\<le> x\"\n      by (rule order_trans) fact\n\n    hence ?case using wf lbs lbs'\n    proof (simp add: nth_append length_fa_ti access_ti_pair_dt_fst size_td_pair_dt_fst)\n      from fl have fl': \"field_lookup_list ts' f 0 = Some (s, n - size_td (dt_fst p'))\"\n        by (rule field_lookup_offset2_list [where m = 0, simplified])\n\n      show \"access_ti_list ts' (update_ti s bs v) (drop (size_td (dt_fst p')) bs') ! (x - size_td (dt_fst p')) = bs ! (x - n)\"\n        using mlt nlex xln lbs lbs' wf wfts \\<open>td_fafu_idem s\\<close> \\<open>wf_fd s\\<close>\n        by (simp add: Cons_typ_desc.hyps(2) [OF fl'] size_td_pair_dt_fst)\n    qed\n  }\n  moreover\n  {\n    note ih = Cons_typ_desc.hyps(1)[simplified access_ti_pair_dt_fst wf_fd_pair_dt_fst]\n\n    assume fl: \"field_lookup_pair p' f 0 = Some (s, n)\"\n\n    hence \"x < size_td (dt_fst p')\"\n      apply (cases p')\n      apply (simp split: if_split_asm)\n      apply (drule field_lookup_offset_size')\n      apply (rule order_less_le_trans [OF xln])\n      apply simp\n      done\n\n    hence ?case using wf lbs lbs' nlex xln wf wfts \\<open>td_fafu_idem s\\<close> \\<open>wf_fd s\\<close>\n      by (simp add: nth_append length_fa_ti access_ti_pair_dt_fst size_td_pair_dt_fst ih[OF fl])\n  }\n  ultimately show ?case using \\<open>field_lookup_list (p' # ts') f 0 = Some (s, n)\\<close> by (simp split: option.splits)\nqed (clarsimp split: if_split_asm)+\n\nsubsection \\<open>td_fa_hi\\<close>\n\n(* \\<lbrakk> size_of TYPE('a::mem_type) \\<le> length h; size_of TYPE('a) \\<le> length h' \\<rbrakk> \\<Longrightarrow> *)\n\nlemma fa_heap_indepD:\n  \"\\<lbrakk> fa_heap_indep fd n; length bs = n; length bs' = n \\<rbrakk> \\<Longrightarrow>\n  field_access fd v bs = field_access fd v bs'\"\n  unfolding fa_heap_indep_def\n  apply (drule spec, drule spec, drule spec)\n  apply (drule (1) mp)\n  apply (erule (1) mp)\n  done\n\n(* The simplifier spins on the IHs here, hence the proofs for each case *)\nlemma td_fa_hi_heap_independence:\n  shows \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi t; length h = size_td t; length h' = size_td t \\<rbrakk>\n  \\<Longrightarrow> access_ti t v h = access_ti t v h'\"\n  and   \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi_struct st; length h = size_td_struct st; length h' = size_td_struct st\\<rbrakk>\n  \\<Longrightarrow> access_ti_struct st v h = access_ti_struct st v h'\"\n  and   \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi_list ts;  length h = size_td_list ts; length h' = size_td_list ts \\<rbrakk>\n  \\<Longrightarrow> access_ti_list ts v h = access_ti_list ts v h'\"\n  and   \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi_pair p;  length h = size_td_pair p; length h' = size_td_pair p \\<rbrakk>\n  \\<Longrightarrow> access_ti_pair p v h = access_ti_pair p v h'\"\nproof (induct t and st and ts and p)\n  case TypDesc\n  from TypDesc.prems show ?case\n    by (simp) (erule (2) TypDesc.hyps)\nnext\n  case TypScalar\n  from TypScalar.prems show ?case\n    by simp (erule (2) fa_heap_indepD)\nnext\n  case TypAggregate\n  from TypAggregate.prems show ?case\n    by (simp) (erule (2) TypAggregate.hyps)\nnext\n  case Nil_typ_desc thus ?case by simp\nnext\n  case Cons_typ_desc\n  from Cons_typ_desc.prems show ?case\n    apply simp\n    apply (erule conjE)\n    apply (rule arg_cong2 [where f = \"(@)\"])\n    apply (erule Cons_typ_desc.hyps; simp)\n    apply (erule Cons_typ_desc.hyps; simp)\n    done\nnext\n  case DTPair_typ_desc\n  from DTPair_typ_desc.prems show ?case\n    by simp (erule (2) DTPair_typ_desc.hyps)\nqed\n\nsection \\<open>Simp rules for deriving packed props from the type combinators\\<close>\n\nsubsection \\<open>td_fafu_idem\\<close>\n\nlemma td_fafu_idem_final_pad:\n  \"padup (2 ^ align_td t) (size_td t) = 0\n  \\<Longrightarrow> td_fafu_idem (final_pad t) = td_fafu_idem t\"\n  unfolding final_pad_def\n  by (clarsimp simp add: padup_def Let_def)\n\nlemma td_fafu_idem_ti_typ_pad_combine:\n  fixes t :: \"'a :: c_type itself\" and s :: \"'b :: c_type field_desc typ_desc\"\n  assumes pad: \"padup (align_of TYPE('a)) (size_td s) = 0\"\n  shows \"td_fafu_idem (ti_typ_pad_combine t xf xfu nm s) = td_fafu_idem (ti_typ_combine t xf xfu nm s)\"\n  unfolding ti_typ_pad_combine_def using pad\n  by (clarsimp simp: Let_def)\n\nlemma td_fafu_idem_list_append:\n  fixes xs :: \"'a :: c_type field_desc typ_pair list\"\n  shows \"td_fafu_idem_list (xs @ ys) = (td_fafu_idem_list xs \\<and> td_fafu_idem_list ys)\"\n  by (induct xs) simp+\n\nlemma td_fafu_idem_extend_ti:\n  fixes t :: \"'a :: c_type field_desc typ_desc\"\n  assumes as: \"td_fafu_idem s\"\n  and     at: \"td_fafu_idem t\"\n  shows \"td_fafu_idem (extend_ti s t nm)\" using as at\n  by (cases s, rename_tac typ_struct xs)\n     (case_tac typ_struct; simp add: td_fafu_idem_list_append)\n\nlemma fd_cons_access_updateD:\n  \"\\<lbrakk> fd_cons_access_update d n; length bs = n; length bs' = n\\<rbrakk> \\<Longrightarrow>\n   field_access d (field_update d bs v) bs' = field_access d (field_update d bs v') bs'\"\n  unfolding fd_cons_access_update_def by clarsimp\n\nlemma fa_fu_idem_update_desc:\n  fixes a :: \"'a field_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and     fd: \"fd_cons_struct (TypScalar n n' a)\"\n  shows   \"fa_fu_idem (update_desc xf xfu a) n = fa_fu_idem a n\"\nproof\n  assume asm: \"fa_fu_idem (update_desc xf xfu a) n\"\n\n  let ?fu = \"\\<lambda>bs. if length bs = n then field_update a bs else id\"\n  let ?a' = \"\\<lparr> field_access = field_access a, field_update = ?fu \\<rparr>\"\n\n  show \"fa_fu_idem a n\"\n    unfolding fa_fu_idem_def\n  proof (intro impI conjI allI)\n    fix bs :: \"byte list\" and bs' :: \"byte list\" and v\n    assume l: \"length bs = n\" and l': \"length bs' = n\"\n\n    hence \"(\\<forall>v. field_access a (field_update a bs (xf v)) bs' = bs)\n           = (\\<forall>v. field_access a (?fu bs (xf v)) bs' = bs)\" by simp\n\n    also have \"\\<dots> = (\\<forall>v. field_access a (field_update a bs v) bs' = bs)\" using fd\n      apply -\n      apply (rule iffI)\n       apply (rule allI)\n       apply (subst (asm) fd_cons_access_updateD [OF _ l l', where d = ?a', simplified])\n        apply (simp add: fd_cons_struct_def fd_cons_desc_def)\n       apply (fastforce simp: l l')\n      apply (fastforce simp: l l')\n      done\n\n    finally show \"field_access a (field_update a bs v) bs' = bs\" using asm fg l l'\n      by (clarsimp simp add: update_desc_def fa_fu_idem_def fg_cons_def)\n  qed\nnext\n  assume \"fa_fu_idem a n\"\n  thus \"fa_fu_idem (update_desc xf xfu a) n\"\n    unfolding fa_fu_idem_def update_desc_def using fg\n    by (clarsimp simp add: update_desc_def fa_fu_idem_def fg_cons_def)\nqed\n\nlemma td_fafu_idem_map_td_update_desc:\n  assumes fg: \"fg_cons xf xfu\"\n  shows  \"wf_fd t \\<Longrightarrow> td_fafu_idem (map_td (\\<lambda>_ _. update_desc xf xfu) t) = td_fafu_idem t\"\n  and    \"wf_fd_struct st \\<Longrightarrow> td_fafu_idem_struct (map_td_struct (\\<lambda>_ _. update_desc xf xfu) st) = td_fafu_idem_struct st\"\n  and    \"wf_fd_list ts \\<Longrightarrow> td_fafu_idem_list (map_td_list (\\<lambda>_ _. update_desc xf xfu) ts) = td_fafu_idem_list ts\"\n  and    \"wf_fd_pair p \\<Longrightarrow> td_fafu_idem_pair (map_td_pair (\\<lambda>_ _. update_desc xf xfu) p) = td_fafu_idem_pair p\"\n  by (induct t and st and ts and p) (auto elim!: fa_fu_idem_update_desc [OF fg])\n\nlemmas td_fafu_idem_adjust_ti = td_fafu_idem_map_td_update_desc(1)[folded adjust_ti_def]\n\nlemma td_fafu_idem_ti_typ_combine:\n  fixes s :: \"'b :: c_type field_desc typ_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and    tda: \"td_fafu_idem (typ_info_t TYPE('a :: mem_type))\"\n  and    tds: \"td_fafu_idem s\"\n  shows \"td_fafu_idem (ti_typ_combine TYPE('a :: mem_type) xf xfu nm s)\"\n  unfolding ti_typ_combine_def using tda tds\n  apply (clarsimp simp: Let_def)\n  apply (cases s)\n  apply (rename_tac typ_struct xs)\n  apply (case_tac typ_struct)\n   apply simp\n   apply (subst td_fafu_idem_adjust_ti [OF fg wf_fd], assumption)\n  apply (simp add: td_fafu_idem_list_append)\n  apply (subst td_fafu_idem_adjust_ti [OF fg wf_fd], assumption)\n  done\n\nlemma td_fafu_idem_ptr:\n   \"td_fafu_idem (typ_info_t TYPE('a :: c_type ptr))\"\n  apply (clarsimp simp add: fa_fu_idem_def)\n  apply (subst word_rsplit_rcat_size)\n   apply (clarsimp simp add: size_of_def word_size)\n  apply simp\n  done\n\nlemma td_fafu_idem_word:\n   \"td_fafu_idem (typ_info_t TYPE('a :: len8 word))\"\n  apply(clarsimp simp: fa_fu_idem_def)\n  apply (subst word_rsplit_rcat_size)\n   apply (insert len8_dv8)\n   apply (clarsimp simp add: size_of_def word_size)\n   apply (subst dvd_div_mult_self; simp)\n  apply simp\n  done\n\nlemma fg_cons_array [simp]:\n  \"n < card (UNIV :: 'b :: finite set) \\<Longrightarrow>\n   fg_cons (\\<lambda>x. index x n) (\\<lambda>x f. Arrays.update (f :: 'a['b]) n x)\"\n  unfolding fg_cons_def by simp\n\nlemma td_fafu_idem_array_n:\n  \"\\<lbrakk> td_fafu_idem (typ_info_t TYPE('a)); n \\<le> card (UNIV :: 'b set) \\<rbrakk> \\<Longrightarrow>\n   td_fafu_idem (array_tag_n n :: ('a :: mem_type ['b :: finite]) field_desc typ_desc)\"\n  by (induct n; simp add: array_tag_n.simps empty_typ_info_def)\n     (simp add: td_fafu_idem_ti_typ_combine)\n\nlemma td_fafu_idem_array:\n  \"td_fafu_idem (typ_info_t TYPE('a)) \\<Longrightarrow> td_fafu_idem (typ_info_t TYPE('a :: mem_type ['b :: finite]))\"\n  by (clarsimp simp: typ_info_array array_tag_def fa_fu_idem_def td_fafu_idem_array_n)\n\nlemma td_fafu_idem_empty_typ_info:\n  \"td_fafu_idem (empty_typ_info t)\"\n  unfolding empty_typ_info_def\n  by simp\n\nsubsection \\<open>td_fa_hi\\<close>\n\n(* These are mostly identical to the above --- surely there is something which implies both? *)\n\nlemma td_fa_hi_final_pad:\n  \"padup (2 ^ align_td t) (size_td t) = 0\n  \\<Longrightarrow> td_fa_hi (final_pad t) = td_fa_hi t\"\n  unfolding final_pad_def\n  by (clarsimp simp add: padup_def Let_def)\n\nlemma td_fa_hi_ti_typ_pad_combine:\n  fixes t :: \"'a :: c_type itself\" and s :: \"'b :: c_type field_desc typ_desc\"\n  assumes pad: \"padup (align_of TYPE('a)) (size_td s) = 0\"\n  shows \"td_fa_hi (ti_typ_pad_combine t xf xfu nm s) = td_fa_hi (ti_typ_combine t xf xfu nm s)\"\n  unfolding ti_typ_pad_combine_def using pad\n  by (clarsimp simp: Let_def)\n\nlemma td_fa_hi_list_append:\n  fixes xs :: \"'a :: c_type field_desc typ_pair list\"\n  shows \"td_fa_hi_list (xs @ ys) = (td_fa_hi_list xs \\<and> td_fa_hi_list ys)\"\n  by (induct xs) simp+\n\nlemma td_fa_hi_extend_ti:\n  fixes t :: \"'a :: c_type field_desc typ_desc\"\n  assumes as: \"td_fa_hi s\"\n  and     at: \"td_fa_hi t\"\n  shows \"td_fa_hi (extend_ti s t nm)\" using as at\n  by (cases s, rename_tac typ_struct xs)\n     (case_tac typ_struct; simp add: td_fa_hi_list_append)\n\nlemma fa_heap_indep_update_desc:\n  fixes a :: \"'a field_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and     fd: \"fd_cons_struct (TypScalar n n' a)\"\n  shows   \"fa_heap_indep (update_desc xf xfu a) n = fa_heap_indep a n\"\nproof\n  assume asm: \"fa_heap_indep (update_desc xf xfu a) n\"\n\n  have xf_xfu: \"\\<And>v v'. xf (xfu v v') = v\" using fg\n    unfolding fg_cons_def\n    by simp\n\n  show \"fa_heap_indep a n\"\n    unfolding fa_heap_indep_def\n  proof (intro impI conjI allI)\n    fix bs :: \"byte list\" and bs' :: \"byte list\" and v\n    assume l: \"length bs = n\" and l': \"length bs' = n\"\n    with asm\n    have \"field_access (update_desc xf xfu a) (xfu v undefined) bs =\n          field_access (update_desc xf xfu a) (xfu v undefined) bs'\"\n      by (rule fa_heap_indepD)\n\n    thus \"field_access a v bs = field_access a v bs'\"\n      unfolding update_desc_def\n      by (simp add: xf_xfu)\n  qed\nnext\n  assume asm: \"fa_heap_indep a n\"\n  show \"fa_heap_indep (update_desc xf xfu a) n\"\n    unfolding fa_heap_indep_def update_desc_def\n  proof (simp, intro impI conjI allI)\n    fix bs :: \"byte list\" and bs' :: \"byte list\" and v\n    assume l: \"length bs = n\" and l': \"length bs' = n\"\n\n    with asm show \"field_access a (xf v) bs = field_access a (xf v) bs'\"\n      by (rule fa_heap_indepD)\n  qed\nqed\n\nlemma td_fa_hi_map_td_update_desc:\n  assumes fg: \"fg_cons xf xfu\"\n  shows  \"wf_fd t \\<Longrightarrow> td_fa_hi (map_td (\\<lambda>_ _. update_desc xf xfu) t) = td_fa_hi t\"\n  and    \"wf_fd_struct st \\<Longrightarrow> td_fa_hi_struct (map_td_struct (\\<lambda>_ _. update_desc xf xfu) st) = td_fa_hi_struct st\"\n  and    \"wf_fd_list ts \\<Longrightarrow> td_fa_hi_list (map_td_list (\\<lambda>_ _. update_desc xf xfu) ts) = td_fa_hi_list ts\"\n  and    \"wf_fd_pair p \\<Longrightarrow> td_fa_hi_pair (map_td_pair (\\<lambda>_ _. update_desc xf xfu) p) = td_fa_hi_pair p\"\n  by (induct t and st and ts and p) (auto elim!: fa_heap_indep_update_desc [OF fg])\n\nlemmas td_fa_hi_adjust_ti = td_fa_hi_map_td_update_desc(1)[folded adjust_ti_def]\n\nlemma td_fa_hi_ti_typ_combine:\n  fixes s :: \"'b :: c_type field_desc typ_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and    tda: \"td_fa_hi (typ_info_t TYPE('a :: mem_type))\"\n  and    tds: \"td_fa_hi s\"\n  shows \"td_fa_hi (ti_typ_combine TYPE('a :: mem_type) xf xfu nm s)\"\n  unfolding ti_typ_combine_def Let_def using tda tds\n  by (cases s, rename_tac typ_struct xs)\n     (case_tac typ_struct; simp add: td_fa_hi_list_append td_fa_hi_adjust_ti[OF fg wf_fd])\n\nlemma td_fa_hi_ptr:\n   \"td_fa_hi (typ_info_t TYPE('a :: c_type ptr))\"\n  by (clarsimp simp add: fa_heap_indep_def)\n\nlemma td_fa_hi_word:\n   \"td_fa_hi (typ_info_t TYPE('a :: len8 word))\"\n  by (clarsimp simp add: fa_heap_indep_def)\n\nlemma td_fa_hi_array_n:\n  \"\\<lbrakk>td_fa_hi (typ_info_t TYPE('a)); n \\<le> card (UNIV :: 'b set) \\<rbrakk> \\<Longrightarrow> td_fa_hi (array_tag_n n :: ('a :: mem_type ['b :: finite]) field_desc typ_desc)\"\n  by (induct n; simp add: array_tag_n.simps empty_typ_info_def td_fa_hi_ti_typ_combine)\n\nlemma td_fa_hi_array:\n  \"td_fa_hi (typ_info_t TYPE('a)) \\<Longrightarrow> td_fa_hi (typ_info_t TYPE('a :: mem_type ['b :: finite]))\"\n  by (clarsimp simp add: typ_info_array array_tag_def fa_fu_idem_def td_fa_hi_array_n)\n\nlemma td_fa_hi_empty_typ_info:\n  \"td_fa_hi (empty_typ_info t)\"\n  unfolding empty_typ_info_def\n  by simp\n\nsection \\<open>The type class and simp sets\\<close>\n\ntext \\<open>Packed types, with no padding, have the defining property that\n        access is invariant under substitution of the underlying heap and\n        access/update is the identity\\<close>\n\nclass packed_type = mem_type +\n  assumes td_fafu_idem: \"td_fafu_idem (typ_info_t TYPE('a::c_type))\"\n  assumes td_fa_hi:     \"td_fa_hi (typ_info_t TYPE('a::c_type))\"\n\nlemmas td_fafu_idem_intro_simps =\n  \\<comment> \\<open>Axioms\\<close>\n  td_fafu_idem\n  \\<comment> \\<open>Combinators\\<close>\n  td_fafu_idem_final_pad td_fafu_idem_ti_typ_pad_combine td_fafu_idem_ti_typ_combine td_fafu_idem_empty_typ_info\n  \\<comment> \\<open>Constructors\\<close>\n  td_fafu_idem_ptr td_fafu_idem_word td_fafu_idem_array\n\nlemmas td_fa_hi_intro_simps =\n  \\<comment> \\<open>Axioms\\<close>\n  td_fa_hi\n  \\<comment> \\<open>Combinators\\<close>\n  td_fa_hi_final_pad td_fa_hi_ti_typ_pad_combine td_fa_hi_ti_typ_combine td_fa_hi_empty_typ_info\n  \\<comment> \\<open>Constructors\\<close>\n  td_fa_hi_ptr td_fa_hi_word td_fa_hi_array\n\nlemma align_td_array':\n  \"align_td (typ_info_t TYPE('a :: c_type['b :: finite])) = align_td (typ_info_t TYPE('a))\"\n  by (simp add: typ_info_array array_tag_def align_td_array_tag)\n\nlemmas packed_type_intro_simps =\n  td_fafu_idem_intro_simps td_fa_hi_intro_simps align_td_array' size_td_simps size_td_array\n\nlemma access_ti_append':\n  \"\\<And>list.\n   access_ti_list (xs @ ys) t list =\n     access_ti_list xs t (take (size_td_list xs) list) @\n     access_ti_list ys t (drop (size_td_list xs) list)\"\nproof(induct xs)\n  case Nil show ?case by simp\nnext\n  case (Cons x xs) thus ?case by (simp add: min_def ac_simps drop_take)\nqed\n\nsection \\<open>Instances\\<close>\n\ntext \\<open>Words (of multiple of 8 size) are packed\\<close>\n\ninstantiation word :: (len8) packed_type\nbegin\ninstance\n  by (intro_classes; rule td_fafu_idem_word td_fa_hi_word)\nend\n\ntext \\<open>Pointers are always packed\\<close>\n\ninstantiation ptr :: (c_type)packed_type\nbegin\ninstance\n  by (intro_classes; simp add: fa_fu_idem_def word_rsplit_rcat_size word_size fa_heap_indep_def)\nend\n\ntext \\<open>Arrays of packed types are in turn packed\\<close>\n\nclass array_outer_packed = packed_type + array_outer_max_size\nclass array_inner_packed = array_outer_packed + array_inner_max_size\n\ninstance word :: (len8)array_outer_packed ..\ninstance word :: (len8)array_inner_packed ..\n\ninstance array :: (array_outer_packed, array_max_count) packed_type\n  by (intro_classes; simp add: td_fafu_idem_intro_simps td_fa_hi_intro_simps)\n\ninstance array :: (array_inner_packed, array_max_count) array_outer_packed ..\n\nsection \\<open>Theorems about packed types\\<close>\n\nsubsection \\<open>td_fa_hi\\<close>\n\nlemma heap_independence:\n  \"\\<lbrakk>length h = size_of TYPE('a :: packed_type); length h' = size_of TYPE('a) \\<rbrakk>\n  \\<Longrightarrow> access_ti (typ_info_t TYPE('a)) v h = access_ti (typ_info_t TYPE('a)) v h'\"\n  by (rule td_fa_hi_heap_independence(1)[OF td_fa_hi], simp_all add: size_of_def)\n\ntheorem packed_heap_update_collapse:\n fixes u::\"'a::packed_type\"\n fixes v::\"'a\"\n shows \"heap_update p v (heap_update p u h) = heap_update p v h\"\n  unfolding heap_update_def\n  apply(rule ext)\n  apply(case_tac \"x \\<in> {ptr_val p..+size_of TYPE('a)}\")\n   apply(simp add: heap_update_mem_same_point)\n   apply(simp add:to_bytes_def)\n   apply(subst heap_independence, simp)\n    prefer 2\n    apply(rule refl)\n   apply(simp)\n  apply(simp add: heap_update_nmem_same)\n  done\n\nlemma packed_heap_update_collapse_hrs:\n  fixes p :: \"'a :: packed_type ptr\"\n  shows \"hrs_mem_update (heap_update p v) (hrs_mem_update (heap_update p v') hp) =\n         hrs_mem_update (heap_update p v) hp\"\n  unfolding hrs_mem_update_def\n  by (simp add: split_def packed_heap_update_collapse)\n\nsubsection \\<open>td_fafu_idem\\<close>\n\nlemma order_leE:\n  fixes x :: \"'a :: order\"\n  shows \"\\<lbrakk> x \\<le> y; x = y \\<Longrightarrow> P; x < y \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P\"\n  by (auto simp: order_le_less)\n\nlemma of_nat_mono_maybe_le:\n  shows \"\\<lbrakk>X < 2 ^ len_of TYPE('a); Y \\<le> X\\<rbrakk> \\<Longrightarrow> (of_nat Y :: 'a :: len word) \\<le> of_nat X\"\n  apply (erule order_leE)\n   apply simp\n  apply (rule order_less_imp_le)\n  apply (erule (1) of_nat_mono_maybe)\n  done\n\nlemma intvl_le_lower:\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk> x \\<in> {y..+n}; y \\<le> y + of_nat (n - 1); n < 2 ^ len_of TYPE('a) \\<rbrakk> \\<Longrightarrow> y \\<le> x\"\n  apply (drule intvlD)\n  apply (elim conjE exE)\n  apply (erule ssubst)\n  apply (erule word_plus_mono_right2)\n  apply (rule of_nat_mono_maybe_le)\n   apply simp\n  apply simp\n  done\n\nlemma intvl_less_upper:\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk> x \\<in> {y..+n}; y \\<le> y + of_nat (n - 1); n < 2 ^ len_of TYPE('a) \\<rbrakk> \\<Longrightarrow> x \\<le> y + of_nat (n - 1)\"\n  apply (drule intvlD)\n  apply (elim conjE exE)\n  apply (erule ssubst)\n  apply (rule word_plus_mono_right; assumption?)\n  apply (rule of_nat_mono_maybe_le; simp)\n  done\n\nlemma packed_type_access_ti:\n  fixes v :: \"'a :: packed_type\"\n  assumes lbs: \"length bs = size_of TYPE('a)\"\n  shows \"access_ti (typ_info_t TYPE('a)) v bs = access_ti\\<^sub>0 (typ_info_t TYPE('a)) v\"\n  unfolding access_ti\\<^sub>0_def\n  by (rule heap_independence; simp add: lbs size_of_def)\n\nlemma update_ti_update_ti_t:\n  \"length bs = size_td s \\<Longrightarrow> update_ti s bs v = update_ti_t s bs v\"\n  unfolding update_ti_t_def by simp\n\nlemma heap_list_nth:\n  \"m < n \\<Longrightarrow> heap_list hp n p ! m = hp (p + of_nat m)\"\nproof (induct m arbitrary: n p)\n  case (0 n' p')\n  thus ?case by (cases n', simp_all)\nnext\n  case (Suc m' n' p')\n  show ?case\n  proof (cases n')\n    case 0 thus ?thesis using \\<open>Suc m' < n'\\<close> by simp\n  next\n    case (Suc n'')\n    hence \"m' < n''\" using \\<open>Suc m' < n'\\<close> by simp\n    thus ?thesis using Suc\n      by (simp add: Suc.hyps ac_simps)\n  qed\nqed\n\nlemma c_guard_field_lvalue:\n  fixes p :: \"'a :: mem_type ptr\"\n  assumes cg: \"c_guard p\"\n  and     fl: \"field_lookup (typ_info_t TYPE('a)) f 0 = Some (t, n)\"\n  and     eu: \"export_uinfo t = typ_uinfo_t TYPE('b :: mem_type)\"\n  shows   \"c_guard (Ptr &(p\\<rightarrow>f) :: 'b :: mem_type ptr)\"\n  unfolding c_guard_def\nproof (rule conjI)\n  from cg fl eu show \"ptr_aligned (Ptr &(p\\<rightarrow>f) :: 'b ptr)\"\n    by (rule c_guard_ptr_aligned_fl)\nnext\n  from eu have std: \"size_td t = size_of TYPE('b)\" using fl\n    by (simp add: export_size_of)\n\n  from cg have \"c_null_guard p\" unfolding c_guard_def ..\n  thus \"c_null_guard (Ptr &(p\\<rightarrow>f)  :: 'b ptr)\" unfolding c_null_guard_def\n    apply (rule contrapos_nn)\n    apply (rule subsetD [OF field_tag_sub, OF fl])\n    apply (simp add: std)\n    done\nqed\n\n\nlemma c_guard_no_wrap:\n  fixes p :: \"'a :: mem_type ptr\"\n  assumes cgrd: \"c_guard p\"\n  shows   \"ptr_val p \\<le> ptr_val p + of_nat (size_of TYPE('a) - 1)\"\n  using cgrd unfolding c_guard_def c_null_guard_def\n  apply -\n  apply (erule conjE)\n  apply (erule contrapos_np)\n  apply (simp add: intvl_def)\n  apply (drule word_wrap_of_natD)\n  apply (erule exE)\n  apply (rule exI)\n  apply (simp add: nat_le_Suc_less)\n  done\n\ntheorem packed_heap_super_field_update:\n  fixes v :: \"'a :: packed_type\" and p :: \"'b :: packed_type ptr\"\n  assumes fl: \"field_lookup (typ_info_t TYPE('b)) f 0 = Some (t, n)\"\n  and   cgrd: \"c_guard p\"\n  and     eu: \"export_uinfo t = typ_uinfo_t TYPE('a)\"\n  shows   \"heap_update (Ptr &(p\\<rightarrow>f)) v hp = heap_update p (update_ti t (to_bytes_p v) (h_val hp p)) hp\"\n  unfolding heap_update_def to_bytes_def\nproof (simp add: packed_type_access_ti, rule ext)\n  fix x\n  let ?LHS = \"heap_update_list &(p\\<rightarrow>f) (to_bytes_p v) hp x\"\n  let ?RHS = \"heap_update_list (ptr_val p) (to_bytes_p (update_ti t (to_bytes_p v) (h_val hp p))) hp x\"\n\n  from cgrd have al: \"ptr_val p \\<le> ptr_val p + of_nat (size_of TYPE('b) - 1)\" by (rule c_guard_no_wrap)\n\n  have szb: \"size_of TYPE('b) < 2 ^ len_of TYPE(addr_bitsize)\"\n    apply (fold card_word)\n    apply (fold addr_card_def)\n    apply (rule max_size)\n    done\n\n  have szt: \"n + size_td t \\<le> size_of TYPE('b)\"\n    unfolding size_of_def\n    by (subst add.commute, rule field_lookup_offset_size [OF fl])\n  moreover have t0: \"0 < size_td t\" using fl wf_size_desc\n    by (rule field_lookup_wf_size_desc_gt)\n  ultimately have szn: \"n < size_of TYPE('b)\" by simp\n  from szt have szt1: \"n + (size_td t - 1) \\<le> size_of TYPE('b)\"\n    by simp\n\n  have b0: \"0 < size_of (TYPE ('b))\" using wf_size_desc\n    unfolding size_of_def\n    by (rule wf_size_desc_gt)\n\n  have uofn: \"unat (of_nat n :: addr_bitsize word) = n\" using szn szb\n    by (simp add: nat_less_le unat_of_nat_eq)\n\n  from eu have std: \"size_td t = size_of TYPE('a)\" using fl\n    by (simp add: export_size_of)\n\n  hence \"?LHS = (if x \\<in> {&(p\\<rightarrow>f)..+size_td t} then (to_bytes_p v) ! unat (x - &(p\\<rightarrow>f)) else hp x)\"\n    by (simp add: heap_update_mem_same_point heap_update_nmem_same)\n  also have \"... = ?RHS\"\n  proof (simp, intro impI conjI)\n    assume xin: \"x \\<in> {&(p\\<rightarrow>f)..+size_td t}\"\n    have \"to_bytes_p v ! unat (x - &(p\\<rightarrow>f)) = to_bytes_p (update_ti t (to_bytes_p v) (h_val hp p)) ! unat (x - ptr_val p)\"\n    proof (simp add: to_bytes_p_def to_bytes_def, subst field_access_update_nth_inner(1)[OF fl, simplified])\n\n      have \"c_guard (Ptr &(p\\<rightarrow>f) :: 'a ptr)\" using cgrd fl eu\n        by (rule c_guard_field_lvalue)\n      hence pft: \"&(p\\<rightarrow>f) \\<le> &(p\\<rightarrow>f) + of_nat (size_td t - 1)\"\n        apply -\n        apply (drule c_guard_no_wrap)\n        apply (simp add: std)\n        done\n\n      have szt': \"size_td t < 2 ^ len_of TYPE(addr_bitsize)\"\n        apply (subst std)\n        apply (fold card_word)\n        apply (fold addr_card_def)\n        apply (rule max_size)\n        done\n\n      have ofn: \"of_nat n \\<le> x - ptr_val p\"\n      proof (rule le_minus')\n        from xin show \"ptr_val p + of_nat n \\<le> x\" using pft szt'\n          unfolding field_lvalue_def field_lookup_offset_eq [OF fl]\n          by (rule intvl_le_lower)\n      next\n        from szb szn have \"of_nat n \\<le> (of_nat (size_of TYPE('b) - 1) :: addr_bitsize word)\"\n          apply -\n          apply (rule of_nat_mono_maybe_le)\n           apply simp_all\n          done\n        with al show \"ptr_val p \\<le> ptr_val p + of_nat n\"\n          by (rule word_plus_mono_right2)\n      qed\n\n      thus nlt: \"n \\<le> unat (x - ptr_val p)\"\n        by (simp add: word_le_nat_alt uofn)\n      have \"x \\<le> ptr_val p + (of_nat n + of_nat (size_td t - 1))\" using xin pft szt' t0\n        unfolding field_lvalue_def field_lookup_offset_eq [OF fl]\n        apply -\n        apply (drule (2) intvl_less_upper)\n        apply (simp add: add.assoc)\n        done\n      moreover have \"x \\<in> {ptr_val p..+size_of TYPE('b)}\" using fl xin\n        by (rule subsetD [OF field_tag_sub])\n      ultimately have \"x - ptr_val p \\<le> (of_nat n + of_nat (size_td t - 1))\" using al szb\n        apply -\n        apply (rule word_diff_ls(4)[where xa=x and x=x for x, simplified])\n         apply (metis (hide_lams, mono_tags) add.commute of_nat_add)\n        apply (erule (2) intvl_le_lower)\n        done\n      moreover have \"unat (of_nat n + of_nat (size_td t - 1) :: addr_bitsize word) = n + size_td t - 1\"\n        using t0 order_le_less_trans [OF szt1 szb]\n        apply (subst Abs_fnat_homs(1))\n        apply (subst unat_of_nat)\n        apply simp\n        done\n      ultimately have \"unat (x - ptr_val p) \\<le> n + size_td t - 1\"\n        by (simp add: word_le_nat_alt)\n      thus \"unat (x - ptr_val p) < n + size_td t\" using t0\n        by simp\n\n      show \"td_fafu_idem t\"\n        by (rule field_lookup_td_fafu_idem(1)[OF fl td_fafu_idem])\n\n      show \"wf_fd t\"\n        by (rule wf_fd_field_lookupD [OF fl wf_fd])\n\n      show \"length (access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0)) = size_td t\"\n        using wf_fd [where 'a = 'a]\n        by (simp add: length_fa_ti size_of_def std)\n\n      show \"length (replicate (size_of TYPE('b)) 0) = size_td (typ_info_t TYPE('b))\"\n        by (simp add: size_of_def)\n\n      have \"unat (x - &(p\\<rightarrow>f)) = unat ((x - ptr_val p) - of_nat n)\"\n        by (simp add: field_lvalue_def field_lookup_offset_eq [OF fl])\n      also have \"\\<dots> = unat (x - ptr_val p) - n\"\n        by (simp add: unat_sub [OF ofn] uofn)\n      finally have \"unat (x - &(p\\<rightarrow>f)) = unat (x - ptr_val p) - n\" .\n\n      thus \"access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0) ! unat (x - &(p\\<rightarrow>f)) =\n        access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0) ! (unat (x - ptr_val p) - n)\"\n        by simp\n    qed\n\n    thus \"to_bytes_p v ! unat (x - &(p\\<rightarrow>f)) = ?RHS\"\n    proof (subst heap_update_mem_same_point, simp_all)\n      show \"x \\<in> {ptr_val p..+size_of TYPE('b)}\" using fl xin\n        by (rule subsetD [OF field_tag_sub])\n    qed\n  next\n    assume xni: \"x \\<notin> {&(p\\<rightarrow>f)..+size_td t}\"\n    have \"?RHS = (if x \\<in> {ptr_val p..+size_of TYPE('b)}\n          then (to_bytes_p (update_ti t (to_bytes_p v) (h_val hp p))) ! unat (x - ptr_val p) else hp x)\"\n      by (simp add: heap_update_mem_same_point heap_update_nmem_same)\n\n    also\n    {\n      assume xin: \"x \\<in> {ptr_val p..+size_of TYPE('b)}\"\n\n      hence \"access_ti (typ_info_t TYPE('b))\n        (update_ti_t t (access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0)) (h_val hp p))\n        (replicate (size_of TYPE('b)) 0) ! unat (x - ptr_val p) = hp x\"\n      proof (subst field_access_update_nth_disjD [OF fl])\n        have \"x - ptr_val p \\<le> of_nat (size_of TYPE('b) - 1)\"\n        proof (rule word_diff_ls(4)[where xa=x and x=x for x, simplified])\n          from xin show \"x \\<le> of_nat (size_of TYPE('b) - 1) + ptr_val p\" using al szb\n            by (subst add.commute, rule intvl_less_upper)\n          show \"ptr_val p \\<le> x\" using xin al szb\n            by (rule intvl_le_lower)\n        qed\n        thus unx: \"unat (x - ptr_val p) < size_td (typ_info_t TYPE('b))\" using szb b0\n          by (simp add: word_le_nat_alt size_of_def unat_of_nat)\n\n        show \"unat (x - ptr_val p) < n - 0 \\<or> n - 0 + size_td t \\<le> unat (x - ptr_val p)\" using xin xni\n          unfolding field_lvalue_def field_lookup_offset_eq [OF fl]\n          apply -\n          apply (erule intvl_cut)\n           apply simp\n          apply (rule max_size)\n          done\n\n        show \"wf_fd (typ_info_t TYPE('b))\" by (rule wf_fd)\n            (* clag *)\n        show \"length (access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0)) = size_td t\"\n          using wf_fd [where 'a = 'a]\n          by (simp add: length_fa_ti size_of_def std)\n\n        show \"length (replicate (size_of TYPE('b)) 0) = size_td (typ_info_t TYPE('b))\"\n          by (simp add: size_of_def)\n\n        have \"heap_list hp (size_td (typ_info_t TYPE('b))) (ptr_val p) ! unat (x - ptr_val p) = hp x\"\n          apply (subst heap_list_nth)\n           apply (rule unx)\n          apply simp\n          done\n\n        thus \"access_ti (typ_info_t TYPE('b)) (h_val hp p) (replicate (size_of TYPE('b)) 0) ! unat (x - ptr_val p) = hp x\"\n          unfolding h_val_def\n          by (simp add: from_bytes_def update_ti_t_def size_of_def field_access_update_same(1)[OF td_fafu_idem wf_fd])\n      qed\n    }\n    hence \"\\<dots> = hp x\"\n      by (simp add: to_bytes_p_def to_bytes_def update_ti_update_ti_t length_fa_ti [OF wf_fd] std size_of_def)\n    finally show \"hp x = ?RHS\" by simp\n  qed\n  finally show \"?LHS = ?RHS\" .\nqed\n\nend\n", "meta": {"author": "CompSoftVer", "repo": "CSim2", "sha": "b09a4d77ea089168b1805db5204ac151df2b9eff", "save_path": "github-repos/isabelle/CompSoftVer-CSim2", "path": "github-repos/isabelle/CompSoftVer-CSim2/CSim2-b09a4d77ea089168b1805db5204ac151df2b9eff/CParser/tools/c-parser/PackedTypes.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6150878696277513, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.2859553171226515}}
{"text": "(*\n * @TAG(OTHER_LGPL)\n *)\n\n(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      XVcgEx.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2006-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nheader \"Examples for Parallel Assignments\"\n\ntheory XVcgEx \nimports \"../XVcg\"\n\nbegin\n\nrecord \"globals\" =\n  \"G_'\"::\"nat\"\n  \"H_'\"::\"nat\"\n\nrecord 'g vars = \"'g state\" +\n  A_' :: nat\n  B_' :: nat\n  C_' :: nat\n  I_' :: nat\n  M_' :: nat\n  N_' :: nat\n  R_' :: nat\n  S_' :: nat\n  Arr_' :: \"nat list\"\n  Abr_':: string\n\nterm \"BASIC\n         \\<acute>A :== x,\n         \\<acute>B :== y        \n      END\"\n\nterm \"BASIC\n         \\<acute>G :== \\<acute>H,\n         \\<acute>H :== \\<acute>G        \n      END\"\n\nterm \"BASIC\n        LET (x,y) = (\\<acute>A,b);\n            z = \\<acute>B\n        IN \\<acute>A :== x,\n           \\<acute>G :== \\<acute>A + y + z\n      END\"\n\n\nlemma \"\\<Gamma>\\<turnstile> \\<lbrace>\\<acute>A = 0\\<rbrace> \n      \\<lbrace>\\<acute>A < 0\\<rbrace> \\<longmapsto> BASIC\n       LET (a,b,c) = foo \\<acute>A\n       IN \n            \\<acute>A :== a,\n            \\<acute>B :== b,\n            \\<acute>C :== c\n      END\n      \\<lbrace>\\<acute>A = x \\<and> \\<acute>B = y \\<and> \\<acute>C = c\\<rbrace>\"\napply vcg\noops\n\nlemma \"\\<Gamma>\\<turnstile> \\<lbrace>\\<acute>A = 0\\<rbrace> \n      \\<lbrace>\\<acute>A < 0\\<rbrace> \\<longmapsto> BASIC\n       LET (a,b,c) = foo \\<acute>A\n       IN \n            \\<acute>A :== a,\n            \\<acute>G :== b + \\<acute>B,\n            \\<acute>H :== c\n      END\n      \\<lbrace>\\<acute>A = x \\<and> \\<acute>G = y \\<and> \\<acute>H = c\\<rbrace>\"\napply vcg\noops\n\ndefinition foo:: \"nat \\<Rightarrow> (nat \\<times> nat \\<times> nat)\"\n  where \"foo n = (n,n+1,n+2)\"\n\nlemma \"\\<Gamma>\\<turnstile> \\<lbrace>\\<acute>A = 0\\<rbrace> \n      \\<lbrace>\\<acute>A < 0\\<rbrace> \\<longmapsto> BASIC\n       LET (a,b,c) = foo \\<acute>A\n       IN \n            \\<acute>A :== a,\n            \\<acute>G :== b + \\<acute>B,\n            \\<acute>H :== c\n      END\n      \\<lbrace>\\<acute>A = x \\<and> \\<acute>G = y \\<and> \\<acute>H = c\\<rbrace>\"\napply (vcg add: foo_def snd_conv fst_conv)\noops\n\nend\n", "meta": {"author": "crizkallah", "repo": "checker-verification", "sha": "cd5101e57ef70dcdd1680db2de2f08521605bd7c", "save_path": "github-repos/isabelle/crizkallah-checker-verification", "path": "github-repos/isabelle/crizkallah-checker-verification/checker-verification-cd5101e57ef70dcdd1680db2de2f08521605bd7c/autocorres-1.0/c-parser/hoare-package/ex/XVcgEx.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6150878555160665, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.28595531056210705}}
{"text": "subsection \\<open>Link implementation to CISK: the specific separation kernel is an interpretation of the generic model.\\label{sect:link_to_CISK}\\<close>\n\ntheory Link_separation_kernel_model_to_CISK\n  imports Separation_kernel_model         \nbegin\n\ntext \\<open>We show that the separation kernel instantiation satisfies the \nspecification of CISK.\n\\<close>\n\ntheorem CISK_proof_obligations_satisfied:\n  shows\n    \"Controllable_Interruptible_Separation_Kernel\n      rstep\n      routput_f\n      (\\<up>s0)\n      rcurrent\n      rcswitch\n      rkinvolved\n      rifp\n      rvpeq\n      rAS_set\n      rinvariant\n      rprecondition\n      raborting\n      rwaiting\n      rset_error_code\"\nproof (unfold_locales)\n  \\<comment> \\<open>show that rvpeq is equivalence relation\\<close>\n  show \"\\<forall> a b c u. (rvpeq u a b \\<and> rvpeq u b c) \\<longrightarrow> rvpeq u a c\"\n   and \"\\<forall> a b u. rvpeq u a b \\<longrightarrow> rvpeq u b a\"\n   and \"\\<forall> a u. rvpeq u a a\"\n    using inst_vpeq_rel by metis+\n  \\<comment> \\<open>show output consistency\\<close>\n  show \"\\<forall> a s t. rvpeq (rcurrent s) s t \\<and> rcurrent s = rcurrent t \\<longrightarrow> routput_f s a = routput_f t a\"\n    using inst_output_consistency by metis\n  \\<comment> \\<open>show reflexivity of ifp\\<close>\n  show \"\\<forall> u . rifp u u\"\n    using inst_ifp_refl by metis\n  \\<comment> \\<open>show step consistency\\<close>\n  show \"\\<forall>s t u a. rvpeq u s t \\<and> rvpeq (rcurrent s) s t \\<and> True \\<and> rprecondition s (rcurrent s) a \\<and> True \\<and> rprecondition t (rcurrent t) a \\<and> rcurrent s = rcurrent t \\<longrightarrow>\n              rvpeq u (rstep s a) (rstep t a)\"\n    using inst_weakly_step_consistent by blast\n  \\<comment> \\<open>show step atomicity\\<close>\n  show \"\\<forall> s a . rcurrent (rstep s a) = rcurrent s\"\n    using inst_step_atomicity by metis\n  show \" \\<forall>a s u. \\<not> rifp (rcurrent s) u \\<and> True \\<and> rprecondition s (rcurrent s) a \\<longrightarrow> rvpeq u s (rstep s a)\"\n    using inst_local_respect by blast\n  \\<comment> \\<open>show cswitch is independent of state\\<close>\n  show \"\\<forall>n s t. rcurrent s = rcurrent t \\<longrightarrow> rcurrent (rcswitch n s) = rcurrent (rcswitch n t)\"\n    using inst_cswitch_independent_of_state by metis\n  \\<comment> \\<open>show cswitch consistency\\<close>\n  show \"\\<forall>u s t n. rvpeq u s t \\<longrightarrow> rvpeq u (rcswitch n s) (rcswitch n t)\"\n    using inst_cswitch_consistency by metis\n  \\<comment> \\<open>Show the empt action sequence is in @{term AS_set}\\<close>\n  show \"[] \\<in> rAS_set\"\n    unfolding rAS_set_def\n    by auto\n  \\<comment> \\<open>The invariant for the initial state, already encoded in @{term rstate_t}\\<close>\n  show \"True\"\n    by auto\n  \\<comment> \\<open>Step function of the invariant, already encoded in @{term rstate_t}\\<close>\n  show \"\\<forall>s n. True \\<longrightarrow> True\"\n    by auto\n  \\<comment> \\<open>The precondition does not change with a context switch\\<close>\n  show \"\\<forall>s d n a. rprecondition s d a \\<longrightarrow> rprecondition (rcswitch n s) d a\"\n    using precondition_after_cswitch by blast\n  \\<comment> \\<open>The precondition holds for the first action of each action sequence\\<close>\n  show \"\\<forall>s d aseq. True \\<and> aseq \\<in> rAS_set \\<and> aseq \\<noteq> [] \\<longrightarrow> rprecondition s d (hd aseq)\"\n    using prec_first_IPC_action prec_first_EV_WAIT_action prec_first_EV_SIGNAL_action\n    unfolding rAS_set_def is_sub_seq_def \n    by auto\n  \\<comment> \\<open>The precondition holds for the next action in an action sequence, assuming the sequence is not aborted or delayed\\<close>\n  show \"\\<forall>s a a'. (\\<exists>aseq\\<in>rAS_set. is_sub_seq a a' aseq) \\<and> True \\<and> rprecondition s (rcurrent s) a \\<and> \\<not> raborting s (rcurrent s) a \\<and> \\<not> rwaiting s (rcurrent s) a \\<longrightarrow>\n             rprecondition (rstep s a) (rcurrent s) a'\"\n    using prec_after_IPC_step prec_after_EV_SIGNAL_step prec_after_EV_WAIT_step\n    unfolding rAS_set_def is_sub_seq_def\n    by auto\n  \\<comment> \\<open>Steps of other domains do not influence the precondition\\<close>\n  show \"\\<forall>s d a a'. rcurrent s \\<noteq> d \\<and> rprecondition s d a \\<longrightarrow> rprecondition (rstep s a') d a\"\n    using prec_dom_independent by blast\n  \\<comment> \\<open>The invariant\\<close>\n  show \"\\<forall>s a. True \\<longrightarrow> True\"\n    by auto\n  \\<comment> \\<open>Aborting does not depend on a context switch\\<close>\n  show \"\\<forall>n s. raborting (rcswitch n s) = raborting s\"\n    using aborting_switch_independent by auto\n  \\<comment> \\<open>Aborting does not depend on actions of other domains\\<close>\n  show \"\\<forall>s a d. rcurrent s \\<noteq> d \\<longrightarrow> raborting (rstep s a) d = raborting s d\"\n    using aborting_dom_independent by auto\n  \\<comment> \\<open>Aborting is consistent\\<close>\n  show \"\\<forall>s t u. rvpeq u s t \\<longrightarrow> raborting s u = raborting t u\"\n    using raborting_consistent by auto\n  \\<comment> \\<open>Waiting does not depend on a context switch\\<close>\n  show \"\\<forall>n s. rwaiting (rcswitch n s) = rwaiting s\"\n    using waiting_switch_independent by auto\n  \\<comment> \\<open>Waiting is consistent\\<close>\n  show \"\\<forall>s t u a. rvpeq (rcurrent s) s t \\<and> (\\<forall> d \\<in> rkinvolved a . rvpeq d s t) \n         \\<and> rvpeq u s t  \n         \\<longrightarrow> rwaiting s u a = rwaiting t u a\"\n    unfolding Kernel.involved_def\n    using waiting_consistent by auto\n  \\<comment> \\<open>Domains that are involved in an action may influence the domain of the action\\<close>\n  show \"\\<forall>s a. \\<forall> d \\<in> rkinvolved a. rprecondition s (rcurrent s) a \\<longrightarrow> rifp d (rcurrent s)\"\n    using involved_ifp by blast\n  \\<comment> \\<open>An action that is waiting does not change the state\\<close>\n  show \"\\<forall>s a. rwaiting s (rcurrent s) a \\<longrightarrow> rstep s a = s\"\n    using spec_of_waiting by blast\n  \\<comment> \\<open>Proof obligations for @{term set_error_code}. Right now, they are all trivial\\<close>\n  show \"\\<forall>s d a' a. rcurrent s \\<noteq> d \\<and> raborting s d a \\<longrightarrow> raborting (rset_error_code s a') d a\"\n    unfolding rset_error_code_def\n    by auto\n  show \"\\<forall>s t u a. rvpeq u s t \\<longrightarrow> rvpeq u (rset_error_code s a) (rset_error_code t a)\"\n    unfolding rset_error_code_def\n    by auto\n  show \"\\<forall>s u a. \\<not> rifp (rcurrent s) u \\<longrightarrow> rvpeq u s (rset_error_code s a)\"\n    unfolding rset_error_code_def\n    by (metis \\<open>\\<forall>a u. rvpeq u a a\\<close>)\n  show \"\\<forall>s a. rcurrent (rset_error_code s a) = rcurrent s\"\n    unfolding rset_error_code_def\n    by auto\n  show \"\\<forall>s d a a'. rprecondition s d a \\<and> raborting s (rcurrent s) a' \\<longrightarrow> rprecondition (rset_error_code s a') d a\"\n    unfolding rset_error_code_def\n    by auto\n  show \"\\<forall>s d a' a. rcurrent s \\<noteq> d \\<and> rwaiting s d a \\<longrightarrow> rwaiting (rset_error_code s a') d a\"\n    unfolding rset_error_code_def\n    by auto\nqed\n\ntext \\<open>Now we can instantiate CISK with some initial state, interrupt function, etc.\\<close>\n\ninterpretation Inst:\n  Controllable_Interruptible_Separation_Kernel\n    rstep           \\<comment> \\<open>step function, without program stack\\<close>\n    routput_f       \\<comment> \\<open>output function\\<close>\n    \"\\<up>s0\"           \\<comment> \\<open>initial state\\<close>\n    rcurrent        \\<comment> \\<open>returns the currently active domain\\<close>\n    rcswitch        \\<comment> \\<open>switches the currently active domain\\<close>\n    \"(=) 42\"     \\<comment> \\<open>interrupt function (yet unspecified)\\<close>\n    rkinvolved      \\<comment> \\<open>returns a set of threads involved in the give action\\<close>\n    rifp            \\<comment> \\<open>information flow policy\\<close>\n    rvpeq           \\<comment> \\<open>view partitioning\\<close>\n    rAS_set         \\<comment> \\<open>the set of valid action sequences\\<close>\n    rinvariant      \\<comment> \\<open>the state invariant\\<close>\n    rprecondition   \\<comment> \\<open>the precondition for doing an action\\<close>\n    raborting       \\<comment> \\<open>condition under which an action is aborted\\<close>\n    rwaiting        \\<comment> \\<open>condition under which an action is delayed\\<close>\n    rset_error_code \\<comment> \\<open>updates the state. Has no meaning in the current model.\\<close>\nusing CISK_proof_obligations_satisfied by auto\n\ntext \\<open>The main theorem: the instantiation implements the information flow policy @{term ifp}.\\<close>\ntheorem risecure:\n  \"Inst.isecure\"\nusing Inst.unwinding_implies_isecure_CISK\nby blast\n      \nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/CISC-Kernel/trace/Rushby-with-Control/Link_separation_kernel_model_to_CISK.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6150878555160665, "lm_q2_score": 0.4649015713733885, "lm_q1q2_score": 0.28595531056210705}}
{"text": "theory SubstDropEnv\n  imports FlatLemma SubstExp\nbegin\n\n\n\n\n  \n    (* the issue we're having right now is that if we freely allow for r_s1 / r_s2, then in application, it's\n      possible that the reqs include ownerships that they dont need, which then get removed from the final reqs.\n       *)    \n    \n    (* the reasoning behind this lemma is that if tau is unlim, then we only require unlim reqs. *)(*\nlemma wt_sexp_drop_req: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx'; req_type tau \\<noteq> Aff; (*\\<not> aff_fun_ty tau;*) is_sexp e \\<rbrakk> \\<Longrightarrow>\n    well_typed env r_s1 e tau r_s2 (drop_use_env rx')\"      \n  apply (induction e arbitrary: env tau r_s1 r_s2 rx')\n        apply (auto)\n    (* const + op case *)\n       apply (rule_tac drop_leq_use_env)\n       apply (auto)\n      apply (rule_tac drop_leq_use_env)\n      apply (auto)\n    (* var case *)\n     apply (rule_tac x=\"r_ex\" in exI)\n     apply (auto)\n      apply (rule_tac drop_leq_use_env)\n      apply (simp)\n     apply (rule_tac rhs_drop_leq_use_env)\n      apply (rule_tac weak_diff_use_env)\n      apply (simp add: weak_use_env_def)\n      apply (simp add: ereq_use_env_def)\n      apply (simp add: end_req_perm_def)\n      apply (simp add: one_use_env_def)\n      apply (case_tac tau)\n            apply (auto)\n    (* pair case *)\n    apply (rule_tac x=\"rx\" in exI)\n    apply (rule_tac x=\"rx1\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"rx2\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"r_ex\" in exI)\n    apply (auto)\n     apply (rule_tac drop_leq_use_env)\n     apply (simp)\n    apply (rule_tac rhs_drop_leq_use_env)\n    apply (rule_tac weak_diff_use_env)\n    apply (simp add: aff_use_env_def)\n     apply (case_tac \"max_aff (req_type t1) (req_type t2)\")\n       apply (auto)\n     apply (simp add: weak_use_env_def)\n    apply (simp add: null_use_env_def)\n    (* lam case *)\n   apply (rule_tac x=\"rx\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_ex\" in exI)\n   apply (auto)\n    apply (rule_tac drop_leq_use_env)\n    apply (simp)\n   apply (rule_tac rhs_drop_leq_use_env)\n    apply (rule_tac weak_diff_use_env)\n    apply (auto)\n   apply (simp add: aff_use_env_def)\n   apply (case_tac a)\n     apply (auto)\n   apply (simp add: null_use_env_def)\n   apply (simp add: weak_use_env_def)\n    (* app case. e1 *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"drop_use_env rx1\" in exI)\n  apply (auto)\n   apply (case_tac e1)\n        apply (auto)\n   apply (rule_tac drop_leq_use_env)\n    apply (simp)\n    (* app case. e2, lambda unrolling *)\n  apply (rule_tac x=\"drop_use_env rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n   apply (cut_tac ?e1.0=\"e1\" and ?e2.0=\"e2\" in e2_sexp)\n    apply (auto)\n   apply (case_tac \"\\<not> unlim t1\")\n    apply (case_tac e1)\n         apply (auto)\n   apply (case_tac x1)\n               apply (auto)\n    apply (simp add: pure_fun_def)\n   apply (simp add: unlim_def)\n    (* - final manipulation *)\n  apply (rule_tac x=\"comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex\" in exI)\n  apply (auto)\n       apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n        apply (rule_tac dist_diff_leq_use_env_gen)\n         apply (rule_tac id_leq_use_env)\n         apply (rule_tac dist_comp_leq_use_env)\n          apply (rule_tac comp_leq_use_env1)\n          apply (rule_tac dist_comp_leq_use_env)\n           apply (rule_tac comp_leq_use_env1)\n           apply (rule_tac self_drop_leq_use_env)\n          apply (rule_tac comp_leq_use_env2)\n          apply (rule_tac dist_lift_leq_use_env)\n          apply (rule_tac self_drop_leq_use_env)\n         apply (rule_tac id_leq_use_env)\n        apply (simp)\n       apply (simp add: drop_use_env_def)\n       apply (case_tac r)\n         apply (auto)\n      apply (rule_tac r_sb=\"comp_use_env rx1 (lift_use_env rx2 r)\" in trans_leq_use_env)\n       apply (simp)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (rule_tac comp_leq_use_env1)\n       apply (rule_tac self_drop_leq_use_env)\n      apply (rule_tac comp_leq_use_env2)\n      apply (rule_tac dist_lift_leq_use_env)\n      apply (rule_tac self_drop_leq_use_env)\n     apply (rule_tac r_s=\"rx1\" in disj_leq_use_env1)\n      apply (rule_tac r_s=\"lift_use_env rx2 r\" in disj_leq_use_env2)\n       apply (simp)\n      apply (rule_tac dist_lift_leq_use_env)\n      apply (rule_tac self_drop_leq_use_env)\n     apply (rule_tac self_drop_leq_use_env)\n    apply (rule_tac drop_leq_use_env)\n    apply (simp)\n   apply (rule_tac dist_comp_leq_use_env)\n    apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n     apply (rule_tac r_sb=\"r_s2a\" in trans_leq_use_env)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n   apply (rule_tac well_typed_perm_leq)\n   apply (auto)\n  apply (simp add: app_req_def)\n  apply (case_tac \"req_type tau = Prim\")\n   apply (auto)\n   apply (rule_tac leq_empty_use_env)\n  apply (rule_tac r_sb=\"drop_use_env (diff_use_env (comp_use_env rx1 rx2) (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex))\" in trans_leq_use_env)\n   apply (rule_tac dist_drop_leq_use_env)\n   apply (simp)\n  apply (cut_tac r_s=\"comp_use_env rx1 rx2\" and r_ex=\"comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex\" in diff_drop_use_env)\n  apply (simp)\n  apply (rule_tac dist_diff_leq_use_env_gen)\n   apply (rule_tac dist_comp_leq_use_env)\n    apply (rule_tac dist_drop_leq_use_env)\n    apply (rule_tac self_comp_leq_use_env1)\n   apply (rule_tac dist_drop_leq_use_env)\n   apply (rule_tac self_comp_leq_use_env2)\n  apply (rule_tac self_comp_leq_use_env2)\n  done   *) \n\n(*\nlemma wt_sexp_drop_all: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; req_type tau \\<noteq> Aff; is_sexp e \\<rbrakk> \\<Longrightarrow> well_typed env (drop_use_env r_s1) e tau (drop_use_env r_s1) (drop_use_env rx)\"    \n  apply (induct e arbitrary: env r_s1 r_s2 tau rx)\n        apply (auto)\n    (* const + op cases *)\n          apply (rule_tac id_leq_use_env)\n         apply (rule_tac dist_drop_leq_use_env)\n         apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n          apply (simp_all)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac dist_drop_leq_use_env)\n       apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n        apply (simp_all)\n    (* var case p1. *)\n      apply (rule_tac ereq_leq_use_envx)\n      apply (cut_tac r_x=\"ereq_use_env x1a tau\" and r_s=\"r_s1\" and x=\"x1a\" in spec_leq_perm)\n       apply (simp)\n      apply (simp add: ereq_use_env_def)\n      apply (simp add: one_use_env_def)\n      apply (simp add: drop_use_env_def)\n      apply (simp add: end_req_perm_def)\n      apply (case_tac \"req_type tau\")\n        apply (auto)\n    (* var case p2. *)\n     apply (rule_tac x=\"empty_use_env\" in exI)\n     apply (auto)\n        apply (rule_tac rhs_weak_leq_use_env)\n         apply (rule_tac dist_weak_comp_use_env)\n          apply (simp add: weak_use_env_def)\n          apply (simp add: ereq_use_env_def)\n          apply (simp add: one_use_env_def)\n          apply (simp add: end_req_perm_def)\n          apply (case_tac \"req_type tau\")\n            apply (auto)\n         apply (simp add: weak_use_env_def)\n         apply (simp add: empty_use_env_def)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac dist_drop_leq_use_env)\n       apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n        apply (simp_all)\n       apply (rule_tac r_sb=\"diff_use_env r_s1 (comp_use_env (ereq_use_env x1a tau) r_ex)\" in trans_leq_use_env)\n        apply (rule_tac self_diff_leq_use_env)\n       apply (simp)\n      apply (rule_tac leq_empty_use_env)*)\n\n    \n    (*\nlemma wt_sexp_drop_all: \"\\<lbrakk> well_typed env rx e tau rx rx'; req_type tau \\<noteq> Aff; is_sexp e \\<rbrakk> \\<Longrightarrow> well_typed env (drop_use_env rx) e tau (drop_use_env rx) (drop_use_env rx')\"    \n  apply (induct e arbitrary: env tau rx rx')\n        apply (auto)\n    (* const + op cases *)\n          apply (rule_tac id_leq_use_env)\n         apply (rule_tac dist_drop_leq_use_env)\n         apply (simp)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac dist_drop_leq_use_env)\n       apply (simp)\n    (* var case p1 *)\n      apply (simp add: ereq_use_env_def)\n      apply (simp add: one_use_env_def)\n      apply (simp add: leq_use_env_def)\n      apply (simp add: drop_use_env_def)\n      apply (auto)\n       apply (simp add: end_req_perm_def)\n       apply (case_tac \"req_type tau\")\n         apply (auto)\n      apply (erule_tac x=\"x1a\" in allE)\n      apply (simp)\n    (* var case p2 *)\n     apply (cut_tac r_s=\"rx\" and r_x=\"comp_use_env (ereq_use_env x1a tau) r_ex\" in wtsdr_weak_use_env)\n       apply (simp)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (auto)\n     apply (rule_tac x=\"r_ex\" in exI)\n     apply (auto)\n        apply (rule_tac rhs_weak_leq_use_env)\n         apply (simp)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac dist_drop_leq_use_env)\n       apply (simp)\n      apply (rule_tac rhs_drop_leq_use_env)\n       apply (rule_tac r_sa=\"ereq_use_env x1a tau\" in weak_comp_use_env2)\n       apply (auto)\n     apply (rule_tac rhs_drop_leq_use_env)\n      apply (rule_tac weak_diff_use_env)\n      apply (rule_tac r_sb=\"r_ex\" in weak_comp_use_env1)\n      apply (auto)\n    (* pair case *)\n    apply (case_tac \"\\<not> (req_type t1 \\<noteq> Aff \\<and> req_type t2 \\<noteq> Aff)\")\n     apply (auto)\n     apply (case_tac \"req_type t1\")\n       apply (auto)\n    apply (cut_tac r_s=\"rx\" and r_x=\"r_ex\" in wtsdr_weak_use_env)\n      apply (auto)\n    apply (rule_tac x=\"drop_use_env rxa\" in exI)\n    apply (rule_tac x=\"drop_use_env rx1\" in exI)\n    apply (auto)\n     apply (rule_tac x=\"drop_use_env (comp_use_env r_xa (infl_use_env rx1 r_sa))\" in exI)\n     apply (rule_tac x=\"drop_use_env rx1\" in exI)\n     apply (cut_tac e=\"e1\" in value_is_sexp)\n      apply (auto)\n     apply (cut_tac env=\"env\" and ?r_s1.0=\"rx1\" and e=\"e1\" and ?r_s2.0=\"r_sa\" and rx=\"r_xa\" in infl_full_sexp_wp)\n       apply (auto)\n    apply (rule_tac x=\"drop_use_env rx2\" in exI)\n    apply (auto)\n         apply (rule_tac x=\"drop_use_env (comp_use_env r_xb (infl_use_env rx2 r_sb))\" in exI)\n         apply (rule_tac x=\"drop_use_env rx2\" in exI)\n         apply (cut_tac e=\"e2\" in value_is_sexp)\n          apply (auto)\n         apply (cut_tac env=\"env\" and ?r_s1.0=\"rx2\" and e=\"e2\" and ?r_s2.0=\"r_sb\" and rx=\"r_xb\" in infl_full_sexp_wp)\n           apply (auto)\n        apply (rule_tac dist_drop_leq_use_env)\n        apply (simp)\n       apply (rule_tac dist_drop_leq_use_env)\n       apply (simp)\n      apply (rule_tac dist_drop_leq_use_env)\n      apply (simp)\n     apply (rule_tac r_s=\"lift_use_env rx1 r\" in disj_leq_use_env1)\n      apply (rule_tac r_s=\"lift_use_env rx2 r\" in disj_leq_use_env2)\n       apply (simp)\n      apply (rule_tac dist_lift_leq_use_env)\n      apply (rule_tac self_drop_leq_use_env)\n     apply (rule_tac dist_lift_leq_use_env)\n     apply (rule_tac self_drop_leq_use_env)\n    apply (rule_tac x=\"empty_use_env\" in exI)\n    apply (auto)\n       apply (rule_tac rhs_weak_leq_use_env)\n        apply (simp add: weak_use_env_def)\n        apply (simp add: empty_use_env_def)\n       apply (rule_tac id_leq_use_env)\n      apply (rule_tac dist_drop_leq_use_env)\n      apply (simp)\n     apply (rule_tac leq_empty_use_env)\n    apply (rule_tac diff_leq_use_env)\n    apply (rule_tac r_sb=\"drop_use_env (diff_use_env rxa r_ex)\" in trans_leq_use_env)\n     apply (rule_tac dist_drop_leq_use_env)\n     apply (simp)\n    apply (rule_tac dist_drop_leq_use_env)\n    apply (rule_tac rhs_weak_leq_use_env)\n     apply (simp)\n    apply (rule_tac id_leq_use_env)\n    (* lam case *)\n   apply (simp add: aff_use_env_def)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n    apply (rule_tac rhs_drop_leq_use_env)\n     apply (auto)\n    apply (case_tac a)\n      apply (auto)\n    apply (simp add: weak_use_env_def)\n    apply (simp add: null_use_env_def)\n   apply (cut_tac r_s=\"rx\" and r_x=\"r_ex\" in wtsdr_weak_use_env)\n     apply (auto)\n   apply (rule_tac x=\"r_ex\" in exI)\n   apply (auto)\n      apply (rule_tac rhs_weak_leq_use_env)\n       apply (simp)\n      apply (rule_tac id_leq_use_env)\n     apply (rule_tac dist_drop_leq_use_env)\n     apply (simp)\n    apply (rule_tac rhs_drop_leq_use_env)\n     apply (auto)\n   apply (rule_tac rhs_drop_leq_use_env)\n    apply (rule_tac weak_diff_use_env)\n    apply (auto)\n   apply (case_tac a)\n     apply (auto)\n   apply (simp add: weak_use_env_def)\n   apply (simp add: null_use_env_def)\n    (* app case. e1 *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"drop_use_env rx\" in exI)\n  apply (rule_tac x=\"empty_use_env\" in exI)\n  (*apply (rule_tac x=\"drop_use_env rx1\" in exI)*)\n  apply (auto)\n   apply (case_tac e1)\n        apply (auto)\n    apply (rule_tac id_leq_use_env)(*\n    apply (rule_tac dist_drop_leq_use_env)\n    apply (simp)*)\n   apply (rule_tac leq_empty_use_env)(*\n   apply (rule_tac dist_drop_leq_use_env)\n   apply (simp)*)\n    (* app case. e2, lambda unrolling *)\n  apply (rule_tac x=\"drop_use_env rx2\" in exI)\n  apply (rule_tac x=\"drop_use_env rx\" in exI)\n  apply (auto)\n   apply (cut_tac env=\"env\" and r_c=\"rx\" and ?r_s1.0=\"r_s2\" and ?r_s2.0=\"rx\" and e=\"e2\" and tau=\"t1\" and rx=\"rx2\" in well_typed_incr_start_perm)\n     apply (rule_tac r_c=\"r_s3\" in well_typed_decr_end_perm)\n       apply (simp)\n      apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n       apply (rule_tac self_diff_leq_use_env)\n      apply (simp)\n     apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n      apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n     apply (rule_tac well_typed_perm_leqx)\n     apply (auto)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n    (* - prove that e2 is an s-expression *)\n   apply (case_tac \"\\<not> is_sexp e2\")\n    apply (cut_tac ?e1.0=\"e1\" and ?e2.0=\"e2\" in e2_sexp)\n     apply (simp_all)\n    (* - prove that t1 is unlim *)\n   apply (case_tac \"\\<not> req_type t1 \\<noteq> Aff\")\n    apply (case_tac e1)\n         apply (auto)\n   apply (case_tac x1)\n                apply (auto)\n   apply (simp add: pure_fun_def)\n    (* app case. tau primitive case (only happens for fixed point w/ primitive fun) *)\n  apply (simp add: app_req_def)\n  apply (case_tac \"req_type tau = Prim\")\n   apply (auto)\n   apply (case_tac e1)\n        apply (auto)\n   apply (case_tac x1)\n               apply (auto)\n   apply (simp add: pure_fun_def)\n   apply (auto)\n   apply (case_tac t)\n         apply (auto)\n   apply (case_tac \"\\<not> weak_use_env empty_use_env\")\n    apply (simp add: weak_use_env_def)\n    apply (simp add: empty_use_env_def)\n   apply (rule_tac x=\"empty_use_env\" in exI)\n   apply (auto)\n         apply (rule_tac rhs_weak_leq_use_env)\n          apply (rule_tac dist_weak_comp_use_env)\n           apply (rule_tac dist_weak_comp_use_env)\n            apply (auto)\n          apply (rule_tac drop_weak_use_env)\n         apply (rule_tac id_leq_use_env)\n        apply (simp add: drop_use_env_def)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac leq_empty_use_env)\n       apply (rule_tac dist_drop_leq_use_env)\n       apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n        apply (simp)\n       apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n        apply (rule_tac well_typed_perm_leq)\n        apply (auto)\n       apply (rule_tac well_typed_perm_leqx)\n       apply (auto)\n      apply (rule_tac disj_empty_use_env2)\n     apply (rule_tac dist_drop_leq_use_env)\n     apply (simp)\n    apply (rule_tac leq_empty_use_env)\n   apply (rule_tac leq_empty_use_env)\n    (* non prim case. *)\n    (* - prove weakness of rx1 + rx2 + r_ex *)\n  apply (cut_tac r_s=\"r_s3\" and r_x=\"comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex\" in wtsdr_weak_use_env)\n    apply (rule_tac r_sb=\"rx\" in trans_leq_use_env)\n     apply (simp)\n    apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n   apply (rule_tac dist_comp_leq_use_env)\n    apply (simp)\n   apply (rule_tac r_sb=\"rx\" in trans_leq_use_env)\n    apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n     apply (rule_tac self_diff_leq_use_env)\n    apply (simp_all)\n    (* - r not ownership *)\n  apply (case_tac \"r = OwnPerm\")\n   apply (case_tac e1)\n        apply (auto)\n   apply (case_tac x1)\n               apply (auto)\n   apply (simp add: pure_fun_def)\n    (* - final manipulation *)\n  apply (rule_tac x=\"r_ex\" in exI)\n  apply (auto)\n        apply (rule_tac rhs_weak_leq_use_env)\n         apply (rule_tac r_s=\"comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex\" in leq_weak_use_env)\n          apply (simp)\n         apply (rule_tac dist_comp_leq_use_env)\n          apply (rule_tac comp_leq_use_env1)\n          apply (rule_tac dist_comp_leq_use_env)\n           apply (rule_tac leq_empty_use_env)\n          apply (rule_tac comp_leq_use_env2)\n          apply (rule_tac dist_lift_leq_use_env)\n          apply (rule_tac self_drop_leq_use_env)\n         apply (rule_tac self_comp_leq_use_env2)\n        apply (rule_tac id_leq_use_env)\n       apply (simp add: drop_use_env_def)\n       apply (case_tac r)\n         apply (auto)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (rule_tac leq_empty_use_env)\n      apply (case_tac r)\n        apply (auto)\n      apply (rule_tac dist_drop_leq_use_env)\n      apply (rule_tac r_sb=\"comp_use_env rx1 rx2\" in trans_leq_use_env)\n       apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n        apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n         apply (rule_tac well_typed_perm_leq)\n         apply (auto)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n      apply (rule_tac self_comp_leq_use_env2)\n     apply (rule_tac disj_empty_use_env2)\n    apply (rule_tac dist_drop_leq_use_env)\n    apply (simp)\n   apply (rule_tac rhs_drop_leq_use_env)\n    apply (rule_tac r_sa=\"comp_use_env rx1 (lift_use_env rx2 r)\" in weak_comp_use_env2)\n    apply (auto)\n  apply (rule_tac r_sb=\"drop_use_env (diff_use_env (comp_use_env rx1 rx2) (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex))\" in trans_leq_use_env)\n   apply (rule_tac dist_drop_leq_use_env)\n   apply (auto)\n  apply (rule_tac rhs_drop_leq_use_env)\n   apply (rule_tac weak_diff_use_env)\n   apply (rule_tac dist_weak_comp_use_env)\n    apply (simp add: weak_use_env_def)\n    apply (simp add: empty_use_env_def)\n   apply (rule_tac drop_weak_use_env)\n  apply (rule_tac rhs_weak_leq_use_env)\n   apply (simp)\n  apply (rule_tac diff_leq_use_env)\n  apply (rule_tac dist_comp_leq_use_env)\n   apply (rule_tac leq_empty_use_env)\n  apply (rule_tac comp_leq_use_env2)\n  apply (rule_tac self_drop_leq_use_env)\n  done*)\n    \n    (*\nlemma wt_sexp_drop_req: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; req_type tau \\<noteq> Aff; (*\\<not> aff_fun_ty tau;*) is_sexp e \\<rbrakk> \\<Longrightarrow>\n    well_typed env r_s1 e tau r_s2 (drop_use_env rx)\"\n  apply (induct e arbitrary: env tau r_s1 r_s2 rx)\n        apply (auto)\n    (* const + op case *)\n       apply (rule_tac drop_leq_use_env)\n       apply (simp)\n      apply (rule_tac drop_leq_use_env)\n      apply (simp)\n    (* var case *)\n     apply (rule_tac x=\"r_ex\" in exI)\n     apply (auto)\n      apply (rule_tac drop_leq_use_env)\n      apply (simp)\n     apply (rule_tac rhs_drop_leq_use_env)\n      apply (rule_tac weak_diff_use_env)\n      apply (simp add: weak_use_env_def)\n      apply (simp add: ereq_use_env_def)\n      apply (simp add: one_use_env_def)\n      apply (simp add: end_req_perm_def)\n      apply (case_tac \"req_type tau\")\n        apply (auto)\n    (* pair case *)\n    apply (rule_tac x=\"drop_use_env rxa\" in exI)\n    (* - e1. the idea is that we should be able to drop the perms.  *)\n    apply (rule_tac x=\"drop_use_env rx1\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"drop_use_env rx2\" in exI)\n    apply (auto)\n    *)\n    \nlemma wt_sexp_drop_req: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; req_type tau \\<noteq> Aff; (*\\<not> aff_fun_ty tau;*) is_sexp e \\<rbrakk> \\<Longrightarrow>\n    well_typed env r_s1 e tau r_s2 (drop_use_env rx)\"\n  apply (rule_tac ?r_s2.0=\"diff_use_env r_s1 (infl_use_env r_s1 r_s2)\" and\n      rx=\"diff_use_env (drop_use_env (comp_use_env rx (infl_use_env r_s1 r_s2))) (infl_use_env r_s1 r_s2)\" in well_typed_simul_end_perm)\n     apply (rule_tac well_typed_diff_end_perm)\n      apply (rule_tac r_s=\"drop_use_env r_s1\" in well_typed_incr_simul_perm)\n       apply (rule_tac self_drop_leq_use_env)\n      apply (rule_tac wt_sexp_drop_all)\n        apply (rule_tac infl_full_sexp_wp)\n         apply (auto)\n     apply (rule_tac self_infl_leq_use_env)\n    apply (rule_tac disj_diff_leq_use_env)\n     apply (rule_tac comm_disj_use_env)\n     apply (rule_tac infl_disj_use_env)\n     apply (rule_tac id_leq_use_env)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n   apply (rule_tac drop_leq_use_env)\n   apply (rule_tac well_typed_perm_leqx)\n   apply (auto)\n  apply (cut_tac r_sa=\"rx\" and r_sb=\"infl_use_env r_s1 r_s2\" in dist_drop_comp_use_env)\n  apply (auto)\n  apply (rule_tac lhs_dist_dcl_use_env)\n  apply (rule_tac dist_comp_leq_use_env)\n   apply (rule_tac self_diff_leq_use_env)\n  apply (rule_tac r_sb=\"diff_use_env (infl_use_env r_s1 r_s2) (infl_use_env r_s1 r_s2)\" in trans_leq_use_env)\n   apply (rule_tac diff_infl_leq_use_env)\n  apply (rule_tac dist_diff_leq_use_env)\n  apply (rule_tac self_drop_leq_use_env)\n  done\n    \nfun drop_use_env_ex where\n  \"drop_use_env_ex r_s OwnPerm = r_s\"\n| \"drop_use_env_ex r_s r = drop_use_env r_s\"\n\ndefinition tau_drop_req where\n  \"tau_drop_req r tau = (if r = OwnPerm then True else req_type tau \\<noteq> Aff)\"\n    \nlemma wt_sexp_drop_all_ex: \"\\<lbrakk> well_typed env rx e tau rx rx; tau_drop_req r tau; is_sexp e \\<rbrakk> \\<Longrightarrow> well_typed env (drop_use_env_ex rx r) e tau (drop_use_env_ex rx r) (drop_use_env_ex rx r)\" \n  apply (simp add: tau_drop_req_def)\n  apply (case_tac r)\n    apply (auto)\n   apply (rule_tac wt_sexp_drop_all)\n     apply (auto)\n  apply (rule_tac wt_sexp_drop_all)\n    apply (auto)\n  done\n    \nend", "meta": {"author": "dcco", "repo": "perm_lang_ax1", "sha": "5742edc2c5db417002ed6b8acd159c522b3e6e38", "save_path": "github-repos/isabelle/dcco-perm_lang_ax1", "path": "github-repos/isabelle/dcco-perm_lang_ax1/perm_lang_ax1-5742edc2c5db417002ed6b8acd159c522b3e6e38/perm_unsafe_lift/SubstDropEnv.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6150878414043816, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.28595530400156255}}
{"text": "theory Legacy_Char\nimports Main\nbegin\n\ndatatype nibble =\n    Nibble0 | Nibble1 | Nibble2 | Nibble3 | Nibble4 | Nibble5 | Nibble6 | Nibble7\n  | Nibble8 | Nibble9 | NibbleA | NibbleB | NibbleC | NibbleD | NibbleE | NibbleF\n    \ndatatype legacy_char = LegacyChar nibble nibble\n\nfunction mk_legacy_nibble :: \"nat \\<Rightarrow> nibble\" where\n  \"mk_legacy_nibble 0 = Nibble0\"\n| \"mk_legacy_nibble (Suc 0) = Nibble1\"\n| \"mk_legacy_nibble 2 = Nibble2\"\n| \"mk_legacy_nibble 3 = Nibble3\"\n| \"mk_legacy_nibble 4 = Nibble4\"\n| \"mk_legacy_nibble 5 = Nibble5\"\n| \"mk_legacy_nibble 6 = Nibble6\"\n| \"mk_legacy_nibble 7 = Nibble7\"\n| \"mk_legacy_nibble 8 = Nibble8\"\n| \"mk_legacy_nibble 9 = Nibble9\"\n| \"mk_legacy_nibble 10 = NibbleA\"\n| \"mk_legacy_nibble 11 = NibbleB\"\n| \"mk_legacy_nibble 12 = NibbleC\"\n| \"mk_legacy_nibble 13 = NibbleD\"\n| \"mk_legacy_nibble 14 = NibbleE\"\n| \"mk_legacy_nibble 15 = NibbleF\"\n| \"x \\<ge> 16 \\<Longrightarrow> mk_legacy_nibble x = undefined\"\n                      apply auto apply atomize_elim by arith\ntermination apply (relation \"{}\") by auto\n  \nfun unmk_legacy_nibble where\n  \"unmk_legacy_nibble Nibble0 = 0\"\n| \"unmk_legacy_nibble Nibble1 = 1\"\n| \"unmk_legacy_nibble Nibble2 = 2\"\n| \"unmk_legacy_nibble Nibble3 = 3\"\n| \"unmk_legacy_nibble Nibble4 = 4\"\n| \"unmk_legacy_nibble Nibble5 = 5\"\n| \"unmk_legacy_nibble Nibble6 = 6\"\n| \"unmk_legacy_nibble Nibble7 = 7\"\n| \"unmk_legacy_nibble Nibble8 = 8\"\n| \"unmk_legacy_nibble Nibble9 = 9\"\n| \"unmk_legacy_nibble NibbleA = 10\"\n| \"unmk_legacy_nibble NibbleB = 11\"\n| \"unmk_legacy_nibble NibbleC = 12\"\n| \"unmk_legacy_nibble NibbleD = 13\"\n| \"unmk_legacy_nibble NibbleE = 14\"\n| \"unmk_legacy_nibble NibbleF = 15\"\n\n    \ndefinition mk_legacy_char :: \"char \\<Rightarrow> legacy_char\" where\n  \"mk_legacy_char c = LegacyChar (mk_legacy_nibble (nat_of_char c div 16))  (mk_legacy_nibble (nat_of_char c mod 16))\"\n  \nlemma legacy_char_000: \"mk_legacy_char CHR 000 = LegacyChar Nibble0 Nibble0\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_001: \"mk_legacy_char CHR 001 = LegacyChar Nibble0 Nibble1\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_002: \"mk_legacy_char CHR 002 = LegacyChar Nibble0 Nibble2\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_003: \"mk_legacy_char CHR 003 = LegacyChar Nibble0 Nibble3\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_004: \"mk_legacy_char CHR 004 = LegacyChar Nibble0 Nibble4\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_005: \"mk_legacy_char CHR 005 = LegacyChar Nibble0 Nibble5\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_006: \"mk_legacy_char CHR 006 = LegacyChar Nibble0 Nibble6\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_007: \"mk_legacy_char CHR 007 = LegacyChar Nibble0 Nibble7\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_008: \"mk_legacy_char CHR 008 = LegacyChar Nibble0 Nibble8\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_009: \"mk_legacy_char CHR 009 = LegacyChar Nibble0 Nibble9\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_010: \"mk_legacy_char CHR 010 = LegacyChar Nibble0 NibbleA\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_011: \"mk_legacy_char CHR 011 = LegacyChar Nibble0 NibbleB\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_012: \"mk_legacy_char CHR 012 = LegacyChar Nibble0 NibbleC\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_013: \"mk_legacy_char CHR 013 = LegacyChar Nibble0 NibbleD\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_014: \"mk_legacy_char CHR 014 = LegacyChar Nibble0 NibbleE\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_015: \"mk_legacy_char CHR 015 = LegacyChar Nibble0 NibbleF\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_016: \"mk_legacy_char CHR 016 = LegacyChar Nibble1 Nibble0\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_017: \"mk_legacy_char CHR 017 = LegacyChar Nibble1 Nibble1\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_018: \"mk_legacy_char CHR 018 = LegacyChar Nibble1 Nibble2\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_019: \"mk_legacy_char CHR 019 = LegacyChar Nibble1 Nibble3\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_020: \"mk_legacy_char CHR 020 = LegacyChar Nibble1 Nibble4\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_021: \"mk_legacy_char CHR 021 = LegacyChar Nibble1 Nibble5\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_022: \"mk_legacy_char CHR 022 = LegacyChar Nibble1 Nibble6\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_023: \"mk_legacy_char CHR 023 = LegacyChar Nibble1 Nibble7\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_024: \"mk_legacy_char CHR 024 = LegacyChar Nibble1 Nibble8\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_025: \"mk_legacy_char CHR 025 = LegacyChar Nibble1 Nibble9\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_026: \"mk_legacy_char CHR 026 = LegacyChar Nibble1 NibbleA\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_027: \"mk_legacy_char CHR 027 = LegacyChar Nibble1 NibbleB\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_028: \"mk_legacy_char CHR 028 = LegacyChar Nibble1 NibbleC\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_029: \"mk_legacy_char CHR 029 = LegacyChar Nibble1 NibbleD\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_030: \"mk_legacy_char CHR 030 = LegacyChar Nibble1 NibbleE\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_031: \"mk_legacy_char CHR 031 = LegacyChar Nibble1 NibbleF\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_032: \"mk_legacy_char CHR 032 = LegacyChar Nibble2 Nibble0\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_033: \"mk_legacy_char CHR 033 = LegacyChar Nibble2 Nibble1\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_034: \"mk_legacy_char CHR 034 = LegacyChar Nibble2 Nibble2\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_035: \"mk_legacy_char CHR 035 = LegacyChar Nibble2 Nibble3\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_036: \"mk_legacy_char CHR 036 = LegacyChar Nibble2 Nibble4\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_037: \"mk_legacy_char CHR 037 = LegacyChar Nibble2 Nibble5\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_038: \"mk_legacy_char CHR 038 = LegacyChar Nibble2 Nibble6\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_039: \"mk_legacy_char CHR 039 = LegacyChar Nibble2 Nibble7\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_040: \"mk_legacy_char CHR 040 = LegacyChar Nibble2 Nibble8\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_041: \"mk_legacy_char CHR 041 = LegacyChar Nibble2 Nibble9\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_042: \"mk_legacy_char CHR 042 = LegacyChar Nibble2 NibbleA\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_043: \"mk_legacy_char CHR 043 = LegacyChar Nibble2 NibbleB\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_044: \"mk_legacy_char CHR 044 = LegacyChar Nibble2 NibbleC\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_045: \"mk_legacy_char CHR 045 = LegacyChar Nibble2 NibbleD\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_046: \"mk_legacy_char CHR 046 = LegacyChar Nibble2 NibbleE\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_047: \"mk_legacy_char CHR 047 = LegacyChar Nibble2 NibbleF\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_048: \"mk_legacy_char CHR 048 = LegacyChar Nibble3 Nibble0\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_049: \"mk_legacy_char CHR 049 = LegacyChar Nibble3 Nibble1\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_050: \"mk_legacy_char CHR 050 = LegacyChar Nibble3 Nibble2\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_051: \"mk_legacy_char CHR 051 = LegacyChar Nibble3 Nibble3\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_052: \"mk_legacy_char CHR 052 = LegacyChar Nibble3 Nibble4\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_053: \"mk_legacy_char CHR 053 = LegacyChar Nibble3 Nibble5\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_054: \"mk_legacy_char CHR 054 = LegacyChar Nibble3 Nibble6\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_055: \"mk_legacy_char CHR 055 = LegacyChar Nibble3 Nibble7\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_056: \"mk_legacy_char CHR 056 = LegacyChar Nibble3 Nibble8\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_057: \"mk_legacy_char CHR 057 = LegacyChar Nibble3 Nibble9\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_058: \"mk_legacy_char CHR 058 = LegacyChar Nibble3 NibbleA\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_059: \"mk_legacy_char CHR 059 = LegacyChar Nibble3 NibbleB\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_060: \"mk_legacy_char CHR 060 = LegacyChar Nibble3 NibbleC\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_061: \"mk_legacy_char CHR 061 = LegacyChar Nibble3 NibbleD\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_062: \"mk_legacy_char CHR 062 = LegacyChar Nibble3 NibbleE\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_063: \"mk_legacy_char CHR 063 = LegacyChar Nibble3 NibbleF\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_064: \"mk_legacy_char CHR 064 = LegacyChar Nibble4 Nibble0\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_065: \"mk_legacy_char CHR 065 = LegacyChar Nibble4 Nibble1\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_066: \"mk_legacy_char CHR 066 = LegacyChar Nibble4 Nibble2\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_067: \"mk_legacy_char CHR 067 = LegacyChar Nibble4 Nibble3\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_068: \"mk_legacy_char CHR 068 = LegacyChar Nibble4 Nibble4\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_069: \"mk_legacy_char CHR 069 = LegacyChar Nibble4 Nibble5\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_070: \"mk_legacy_char CHR 070 = LegacyChar Nibble4 Nibble6\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_071: \"mk_legacy_char CHR 071 = LegacyChar Nibble4 Nibble7\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_072: \"mk_legacy_char CHR 072 = LegacyChar Nibble4 Nibble8\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_073: \"mk_legacy_char CHR 073 = LegacyChar Nibble4 Nibble9\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_074: \"mk_legacy_char CHR 074 = LegacyChar Nibble4 NibbleA\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_075: \"mk_legacy_char CHR 075 = LegacyChar Nibble4 NibbleB\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_076: \"mk_legacy_char CHR 076 = LegacyChar Nibble4 NibbleC\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_077: \"mk_legacy_char CHR 077 = LegacyChar Nibble4 NibbleD\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_078: \"mk_legacy_char CHR 078 = LegacyChar Nibble4 NibbleE\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_079: \"mk_legacy_char CHR 079 = LegacyChar Nibble4 NibbleF\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_080: \"mk_legacy_char CHR 080 = LegacyChar Nibble5 Nibble0\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_081: \"mk_legacy_char CHR 081 = LegacyChar Nibble5 Nibble1\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_082: \"mk_legacy_char CHR 082 = LegacyChar Nibble5 Nibble2\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_083: \"mk_legacy_char CHR 083 = LegacyChar Nibble5 Nibble3\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_084: \"mk_legacy_char CHR 084 = LegacyChar Nibble5 Nibble4\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_085: \"mk_legacy_char CHR 085 = LegacyChar Nibble5 Nibble5\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_086: \"mk_legacy_char CHR 086 = LegacyChar Nibble5 Nibble6\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_087: \"mk_legacy_char CHR 087 = LegacyChar Nibble5 Nibble7\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_088: \"mk_legacy_char CHR 088 = LegacyChar Nibble5 Nibble8\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_089: \"mk_legacy_char CHR 089 = LegacyChar Nibble5 Nibble9\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_090: \"mk_legacy_char CHR 090 = LegacyChar Nibble5 NibbleA\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_091: \"mk_legacy_char CHR 091 = LegacyChar Nibble5 NibbleB\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_092: \"mk_legacy_char CHR 092 = LegacyChar Nibble5 NibbleC\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_093: \"mk_legacy_char CHR 093 = LegacyChar Nibble5 NibbleD\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_094: \"mk_legacy_char CHR 094 = LegacyChar Nibble5 NibbleE\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_095: \"mk_legacy_char CHR 095 = LegacyChar Nibble5 NibbleF\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_096: \"mk_legacy_char CHR 096 = LegacyChar Nibble6 Nibble0\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_097: \"mk_legacy_char CHR 097 = LegacyChar Nibble6 Nibble1\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_098: \"mk_legacy_char CHR 098 = LegacyChar Nibble6 Nibble2\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_099: \"mk_legacy_char CHR 099 = LegacyChar Nibble6 Nibble3\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_100: \"mk_legacy_char CHR 100 = LegacyChar Nibble6 Nibble4\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_101: \"mk_legacy_char CHR 101 = LegacyChar Nibble6 Nibble5\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_102: \"mk_legacy_char CHR 102 = LegacyChar Nibble6 Nibble6\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_103: \"mk_legacy_char CHR 103 = LegacyChar Nibble6 Nibble7\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_104: \"mk_legacy_char CHR 104 = LegacyChar Nibble6 Nibble8\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_105: \"mk_legacy_char CHR 105 = LegacyChar Nibble6 Nibble9\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_106: \"mk_legacy_char CHR 106 = LegacyChar Nibble6 NibbleA\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_107: \"mk_legacy_char CHR 107 = LegacyChar Nibble6 NibbleB\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_108: \"mk_legacy_char CHR 108 = LegacyChar Nibble6 NibbleC\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_109: \"mk_legacy_char CHR 109 = LegacyChar Nibble6 NibbleD\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_110: \"mk_legacy_char CHR 110 = LegacyChar Nibble6 NibbleE\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_111: \"mk_legacy_char CHR 111 = LegacyChar Nibble6 NibbleF\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_112: \"mk_legacy_char CHR 112 = LegacyChar Nibble7 Nibble0\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_113: \"mk_legacy_char CHR 113 = LegacyChar Nibble7 Nibble1\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_114: \"mk_legacy_char CHR 114 = LegacyChar Nibble7 Nibble2\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_115: \"mk_legacy_char CHR 115 = LegacyChar Nibble7 Nibble3\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_116: \"mk_legacy_char CHR 116 = LegacyChar Nibble7 Nibble4\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_117: \"mk_legacy_char CHR 117 = LegacyChar Nibble7 Nibble5\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_118: \"mk_legacy_char CHR 118 = LegacyChar Nibble7 Nibble6\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_119: \"mk_legacy_char CHR 119 = LegacyChar Nibble7 Nibble7\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_120: \"mk_legacy_char CHR 120 = LegacyChar Nibble7 Nibble8\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_121: \"mk_legacy_char CHR 121 = LegacyChar Nibble7 Nibble9\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_122: \"mk_legacy_char CHR 122 = LegacyChar Nibble7 NibbleA\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_123: \"mk_legacy_char CHR 123 = LegacyChar Nibble7 NibbleB\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_124: \"mk_legacy_char CHR 124 = LegacyChar Nibble7 NibbleC\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_125: \"mk_legacy_char CHR 125 = LegacyChar Nibble7 NibbleD\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_126: \"mk_legacy_char CHR 126 = LegacyChar Nibble7 NibbleE\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_127: \"mk_legacy_char CHR 127 = LegacyChar Nibble7 NibbleF\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_128: \"mk_legacy_char CHR 128 = LegacyChar Nibble8 Nibble0\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_129: \"mk_legacy_char CHR 129 = LegacyChar Nibble8 Nibble1\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_130: \"mk_legacy_char CHR 130 = LegacyChar Nibble8 Nibble2\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_131: \"mk_legacy_char CHR 131 = LegacyChar Nibble8 Nibble3\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_132: \"mk_legacy_char CHR 132 = LegacyChar Nibble8 Nibble4\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_133: \"mk_legacy_char CHR 133 = LegacyChar Nibble8 Nibble5\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_134: \"mk_legacy_char CHR 134 = LegacyChar Nibble8 Nibble6\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_135: \"mk_legacy_char CHR 135 = LegacyChar Nibble8 Nibble7\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_136: \"mk_legacy_char CHR 136 = LegacyChar Nibble8 Nibble8\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_137: \"mk_legacy_char CHR 137 = LegacyChar Nibble8 Nibble9\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_138: \"mk_legacy_char CHR 138 = LegacyChar Nibble8 NibbleA\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_139: \"mk_legacy_char CHR 139 = LegacyChar Nibble8 NibbleB\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_140: \"mk_legacy_char CHR 140 = LegacyChar Nibble8 NibbleC\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_141: \"mk_legacy_char CHR 141 = LegacyChar Nibble8 NibbleD\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_142: \"mk_legacy_char CHR 142 = LegacyChar Nibble8 NibbleE\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_143: \"mk_legacy_char CHR 143 = LegacyChar Nibble8 NibbleF\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_144: \"mk_legacy_char CHR 144 = LegacyChar Nibble9 Nibble0\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_145: \"mk_legacy_char CHR 145 = LegacyChar Nibble9 Nibble1\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_146: \"mk_legacy_char CHR 146 = LegacyChar Nibble9 Nibble2\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_147: \"mk_legacy_char CHR 147 = LegacyChar Nibble9 Nibble3\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_148: \"mk_legacy_char CHR 148 = LegacyChar Nibble9 Nibble4\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_149: \"mk_legacy_char CHR 149 = LegacyChar Nibble9 Nibble5\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_150: \"mk_legacy_char CHR 150 = LegacyChar Nibble9 Nibble6\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_151: \"mk_legacy_char CHR 151 = LegacyChar Nibble9 Nibble7\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_152: \"mk_legacy_char CHR 152 = LegacyChar Nibble9 Nibble8\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_153: \"mk_legacy_char CHR 153 = LegacyChar Nibble9 Nibble9\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_154: \"mk_legacy_char CHR 154 = LegacyChar Nibble9 NibbleA\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_155: \"mk_legacy_char CHR 155 = LegacyChar Nibble9 NibbleB\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_156: \"mk_legacy_char CHR 156 = LegacyChar Nibble9 NibbleC\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_157: \"mk_legacy_char CHR 157 = LegacyChar Nibble9 NibbleD\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_158: \"mk_legacy_char CHR 158 = LegacyChar Nibble9 NibbleE\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_159: \"mk_legacy_char CHR 159 = LegacyChar Nibble9 NibbleF\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_160: \"mk_legacy_char CHR 160 = LegacyChar NibbleA Nibble0\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_161: \"mk_legacy_char CHR 161 = LegacyChar NibbleA Nibble1\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_162: \"mk_legacy_char CHR 162 = LegacyChar NibbleA Nibble2\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_163: \"mk_legacy_char CHR 163 = LegacyChar NibbleA Nibble3\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_164: \"mk_legacy_char CHR 164 = LegacyChar NibbleA Nibble4\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_165: \"mk_legacy_char CHR 165 = LegacyChar NibbleA Nibble5\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_166: \"mk_legacy_char CHR 166 = LegacyChar NibbleA Nibble6\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_167: \"mk_legacy_char CHR 167 = LegacyChar NibbleA Nibble7\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_168: \"mk_legacy_char CHR 168 = LegacyChar NibbleA Nibble8\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_169: \"mk_legacy_char CHR 169 = LegacyChar NibbleA Nibble9\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_170: \"mk_legacy_char CHR 170 = LegacyChar NibbleA NibbleA\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_171: \"mk_legacy_char CHR 171 = LegacyChar NibbleA NibbleB\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_172: \"mk_legacy_char CHR 172 = LegacyChar NibbleA NibbleC\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_173: \"mk_legacy_char CHR 173 = LegacyChar NibbleA NibbleD\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_174: \"mk_legacy_char CHR 174 = LegacyChar NibbleA NibbleE\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_175: \"mk_legacy_char CHR 175 = LegacyChar NibbleA NibbleF\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_176: \"mk_legacy_char CHR 176 = LegacyChar NibbleB Nibble0\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_177: \"mk_legacy_char CHR 177 = LegacyChar NibbleB Nibble1\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_178: \"mk_legacy_char CHR 178 = LegacyChar NibbleB Nibble2\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_179: \"mk_legacy_char CHR 179 = LegacyChar NibbleB Nibble3\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_180: \"mk_legacy_char CHR 180 = LegacyChar NibbleB Nibble4\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_181: \"mk_legacy_char CHR 181 = LegacyChar NibbleB Nibble5\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_182: \"mk_legacy_char CHR 182 = LegacyChar NibbleB Nibble6\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_183: \"mk_legacy_char CHR 183 = LegacyChar NibbleB Nibble7\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_184: \"mk_legacy_char CHR 184 = LegacyChar NibbleB Nibble8\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_185: \"mk_legacy_char CHR 185 = LegacyChar NibbleB Nibble9\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_186: \"mk_legacy_char CHR 186 = LegacyChar NibbleB NibbleA\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_187: \"mk_legacy_char CHR 187 = LegacyChar NibbleB NibbleB\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_188: \"mk_legacy_char CHR 188 = LegacyChar NibbleB NibbleC\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_189: \"mk_legacy_char CHR 189 = LegacyChar NibbleB NibbleD\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_190: \"mk_legacy_char CHR 190 = LegacyChar NibbleB NibbleE\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_191: \"mk_legacy_char CHR 191 = LegacyChar NibbleB NibbleF\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_192: \"mk_legacy_char CHR 192 = LegacyChar NibbleC Nibble0\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_193: \"mk_legacy_char CHR 193 = LegacyChar NibbleC Nibble1\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_194: \"mk_legacy_char CHR 194 = LegacyChar NibbleC Nibble2\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_195: \"mk_legacy_char CHR 195 = LegacyChar NibbleC Nibble3\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_196: \"mk_legacy_char CHR 196 = LegacyChar NibbleC Nibble4\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_197: \"mk_legacy_char CHR 197 = LegacyChar NibbleC Nibble5\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_198: \"mk_legacy_char CHR 198 = LegacyChar NibbleC Nibble6\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_199: \"mk_legacy_char CHR 199 = LegacyChar NibbleC Nibble7\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_200: \"mk_legacy_char CHR 200 = LegacyChar NibbleC Nibble8\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_201: \"mk_legacy_char CHR 201 = LegacyChar NibbleC Nibble9\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_202: \"mk_legacy_char CHR 202 = LegacyChar NibbleC NibbleA\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_203: \"mk_legacy_char CHR 203 = LegacyChar NibbleC NibbleB\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_204: \"mk_legacy_char CHR 204 = LegacyChar NibbleC NibbleC\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_205: \"mk_legacy_char CHR 205 = LegacyChar NibbleC NibbleD\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_206: \"mk_legacy_char CHR 206 = LegacyChar NibbleC NibbleE\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_207: \"mk_legacy_char CHR 207 = LegacyChar NibbleC NibbleF\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_208: \"mk_legacy_char CHR 208 = LegacyChar NibbleD Nibble0\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_209: \"mk_legacy_char CHR 209 = LegacyChar NibbleD Nibble1\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_210: \"mk_legacy_char CHR 210 = LegacyChar NibbleD Nibble2\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_211: \"mk_legacy_char CHR 211 = LegacyChar NibbleD Nibble3\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_212: \"mk_legacy_char CHR 212 = LegacyChar NibbleD Nibble4\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_213: \"mk_legacy_char CHR 213 = LegacyChar NibbleD Nibble5\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_214: \"mk_legacy_char CHR 214 = LegacyChar NibbleD Nibble6\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_215: \"mk_legacy_char CHR 215 = LegacyChar NibbleD Nibble7\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_216: \"mk_legacy_char CHR 216 = LegacyChar NibbleD Nibble8\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_217: \"mk_legacy_char CHR 217 = LegacyChar NibbleD Nibble9\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_218: \"mk_legacy_char CHR 218 = LegacyChar NibbleD NibbleA\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_219: \"mk_legacy_char CHR 219 = LegacyChar NibbleD NibbleB\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_220: \"mk_legacy_char CHR 220 = LegacyChar NibbleD NibbleC\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_221: \"mk_legacy_char CHR 221 = LegacyChar NibbleD NibbleD\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_222: \"mk_legacy_char CHR 222 = LegacyChar NibbleD NibbleE\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_223: \"mk_legacy_char CHR 223 = LegacyChar NibbleD NibbleF\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_224: \"mk_legacy_char CHR 224 = LegacyChar NibbleE Nibble0\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_225: \"mk_legacy_char CHR 225 = LegacyChar NibbleE Nibble1\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_226: \"mk_legacy_char CHR 226 = LegacyChar NibbleE Nibble2\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_227: \"mk_legacy_char CHR 227 = LegacyChar NibbleE Nibble3\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_228: \"mk_legacy_char CHR 228 = LegacyChar NibbleE Nibble4\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_229: \"mk_legacy_char CHR 229 = LegacyChar NibbleE Nibble5\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_230: \"mk_legacy_char CHR 230 = LegacyChar NibbleE Nibble6\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_231: \"mk_legacy_char CHR 231 = LegacyChar NibbleE Nibble7\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_232: \"mk_legacy_char CHR 232 = LegacyChar NibbleE Nibble8\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_233: \"mk_legacy_char CHR 233 = LegacyChar NibbleE Nibble9\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_234: \"mk_legacy_char CHR 234 = LegacyChar NibbleE NibbleA\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_235: \"mk_legacy_char CHR 235 = LegacyChar NibbleE NibbleB\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_236: \"mk_legacy_char CHR 236 = LegacyChar NibbleE NibbleC\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_237: \"mk_legacy_char CHR 237 = LegacyChar NibbleE NibbleD\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_238: \"mk_legacy_char CHR 238 = LegacyChar NibbleE NibbleE\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_239: \"mk_legacy_char CHR 239 = LegacyChar NibbleE NibbleF\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_240: \"mk_legacy_char CHR 240 = LegacyChar NibbleF Nibble0\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_241: \"mk_legacy_char CHR 241 = LegacyChar NibbleF Nibble1\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_242: \"mk_legacy_char CHR 242 = LegacyChar NibbleF Nibble2\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_243: \"mk_legacy_char CHR 243 = LegacyChar NibbleF Nibble3\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_244: \"mk_legacy_char CHR 244 = LegacyChar NibbleF Nibble4\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_245: \"mk_legacy_char CHR 245 = LegacyChar NibbleF Nibble5\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_246: \"mk_legacy_char CHR 246 = LegacyChar NibbleF Nibble6\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_247: \"mk_legacy_char CHR 247 = LegacyChar NibbleF Nibble7\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_248: \"mk_legacy_char CHR 248 = LegacyChar NibbleF Nibble8\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_249: \"mk_legacy_char CHR 249 = LegacyChar NibbleF Nibble9\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_250: \"mk_legacy_char CHR 250 = LegacyChar NibbleF NibbleA\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_251: \"mk_legacy_char CHR 251 = LegacyChar NibbleF NibbleB\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_252: \"mk_legacy_char CHR 252 = LegacyChar NibbleF NibbleC\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_253: \"mk_legacy_char CHR 253 = LegacyChar NibbleF NibbleD\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_254: \"mk_legacy_char CHR 254 = LegacyChar NibbleF NibbleE\" by (simp add: mk_legacy_char_def)\nlemma legacy_char_255: \"mk_legacy_char CHR 255 = LegacyChar NibbleF NibbleF\" by (simp add: mk_legacy_char_def)\n\nlemmas legacy_char_simps = legacy_char_000 legacy_char_001 legacy_char_002 legacy_char_003 legacy_char_004 legacy_char_005 legacy_char_006 legacy_char_007 legacy_char_008 legacy_char_009 legacy_char_010 legacy_char_011 legacy_char_012 legacy_char_013 legacy_char_014 legacy_char_015 legacy_char_016 legacy_char_017 legacy_char_018 legacy_char_019 legacy_char_020 legacy_char_021 legacy_char_022 legacy_char_023 legacy_char_024 legacy_char_025 legacy_char_026 legacy_char_027 legacy_char_028 legacy_char_029 legacy_char_030 legacy_char_031 legacy_char_032 legacy_char_033 legacy_char_034 legacy_char_035 legacy_char_036 legacy_char_037 legacy_char_038 legacy_char_039 legacy_char_040 legacy_char_041 legacy_char_042 legacy_char_043 legacy_char_044 legacy_char_045 legacy_char_046 legacy_char_047 legacy_char_048 legacy_char_049 legacy_char_050 legacy_char_051 legacy_char_052 legacy_char_053 legacy_char_054 legacy_char_055 legacy_char_056 legacy_char_057 legacy_char_058 legacy_char_059 legacy_char_060 legacy_char_061 legacy_char_062 legacy_char_063 legacy_char_064 legacy_char_065 legacy_char_066 legacy_char_067 legacy_char_068 legacy_char_069 legacy_char_070 legacy_char_071 legacy_char_072 legacy_char_073 legacy_char_074 legacy_char_075 legacy_char_076 legacy_char_077 legacy_char_078 legacy_char_079 legacy_char_080 legacy_char_081 legacy_char_082 legacy_char_083 legacy_char_084 legacy_char_085 legacy_char_086 legacy_char_087 legacy_char_088 legacy_char_089 legacy_char_090 legacy_char_091 legacy_char_092 legacy_char_093 legacy_char_094 legacy_char_095 legacy_char_096 legacy_char_097 legacy_char_098 legacy_char_099 legacy_char_100 legacy_char_101 legacy_char_102 legacy_char_103 legacy_char_104 legacy_char_105 legacy_char_106 legacy_char_107 legacy_char_108 legacy_char_109 legacy_char_110 legacy_char_111 legacy_char_112 legacy_char_113 legacy_char_114 legacy_char_115 legacy_char_116 legacy_char_117 legacy_char_118 legacy_char_119 legacy_char_120 legacy_char_121 legacy_char_122 legacy_char_123 legacy_char_124 legacy_char_125 legacy_char_126 legacy_char_127 legacy_char_128 legacy_char_129 legacy_char_130 legacy_char_131 legacy_char_132 legacy_char_133 legacy_char_134 legacy_char_135 legacy_char_136 legacy_char_137 legacy_char_138 legacy_char_139 legacy_char_140 legacy_char_141 legacy_char_142 legacy_char_143 legacy_char_144 legacy_char_145 legacy_char_146 legacy_char_147 legacy_char_148 legacy_char_149 legacy_char_150 legacy_char_151 legacy_char_152 legacy_char_153 legacy_char_154 legacy_char_155 legacy_char_156 legacy_char_157 legacy_char_158 legacy_char_159 legacy_char_160 legacy_char_161 legacy_char_162 legacy_char_163 legacy_char_164 legacy_char_165 legacy_char_166 legacy_char_167 legacy_char_168 legacy_char_169 legacy_char_170 legacy_char_171 legacy_char_172 legacy_char_173 legacy_char_174 legacy_char_175 legacy_char_176 legacy_char_177 legacy_char_178 legacy_char_179 legacy_char_180 legacy_char_181 legacy_char_182 legacy_char_183 legacy_char_184 legacy_char_185 legacy_char_186 legacy_char_187 legacy_char_188 legacy_char_189 legacy_char_190 legacy_char_191 legacy_char_192 legacy_char_193 legacy_char_194 legacy_char_195 legacy_char_196 legacy_char_197 legacy_char_198 legacy_char_199 legacy_char_200 legacy_char_201 legacy_char_202 legacy_char_203 legacy_char_204 legacy_char_205 legacy_char_206 legacy_char_207 legacy_char_208 legacy_char_209 legacy_char_210 legacy_char_211 legacy_char_212 legacy_char_213 legacy_char_214 legacy_char_215 legacy_char_216 legacy_char_217 legacy_char_218 legacy_char_219 legacy_char_220 legacy_char_221 legacy_char_222 legacy_char_223 legacy_char_224 legacy_char_225 legacy_char_226 legacy_char_227 legacy_char_228 legacy_char_229 legacy_char_230 legacy_char_231 legacy_char_232 legacy_char_233 legacy_char_234 legacy_char_235 legacy_char_236 legacy_char_237 legacy_char_238 legacy_char_239 legacy_char_240 legacy_char_241 legacy_char_242 legacy_char_243 legacy_char_244 legacy_char_245 legacy_char_246 legacy_char_247 legacy_char_248 legacy_char_249 legacy_char_250 legacy_char_251 legacy_char_252 legacy_char_253 legacy_char_254 legacy_char_255\n\nlemma unmk_legacy_nibble: \n  assumes \"x < 16\" \n  shows \"unmk_legacy_nibble (mk_legacy_nibble x) = x\" \nproof -\n  consider \"x=0\" | \"x=1\" | \"x=2\" | \"x=3\" | \"x=4\" | \"x=5\" | \"x=6\" | \"x=7\" | \"x=8\" | \"x=9\" | \"x=10\" | \"x=11\" | \"x=12\" | \"x=13\" | \"x=14\" | \"x=15\"\n    apply atomize_elim using `x<16` by arith\n  thus ?thesis apply cases by simp_all\nqed\n  \nlemma mk_legacy_nibble_inj:\n  assumes \"x < 16\" and \"y < 16\" \n  shows \"mk_legacy_nibble x = mk_legacy_nibble y \\<longleftrightarrow> x=y\"\n  apply rule\n   apply (subst unmk_legacy_nibble[OF `x<16`, symmetric])\n   apply (subst unmk_legacy_nibble[OF `y<16`, symmetric])\n  by auto\n\n  \nlemma mk_legacy_char_inj: \"x = y \\<longleftrightarrow> mk_legacy_char x = mk_legacy_char y\" \nproof -\n  define a b where \"a = nat_of_char x\" and \"b = nat_of_char y\"\n  have a: \"a<256\" by (simp add: a_def)\n  hence adiv16: \"a div 16 < 16\" by arith\n  have amod16: \"a mod 16 < 16\" by arith\n  have b: \"b<256\" by (simp add: b_def)\n  hence bdiv16: \"b div 16 < 16\" by arith \n  have bmod16: \"b mod 16 < 16\" by arith\n  have \"(a = b) =\n    (LegacyChar (mk_legacy_nibble (a div 16)) (mk_legacy_nibble (a mod 16)) =\n     LegacyChar (mk_legacy_nibble (b div 16)) (mk_legacy_nibble (b mod 16)))\"\n    apply simp\n    apply (subst mk_legacy_nibble_inj[OF adiv16 bdiv16])\n    apply (subst mk_legacy_nibble_inj[OF amod16 bmod16])\n    apply rule\n     apply simp\n    apply (subst mult_div_mod_eq[where a=a and b=16, symmetric])\n    apply (subst mult_div_mod_eq[where a=b and b=16, symmetric])\n    by arith\n  thus ?thesis\n    unfolding mk_legacy_char_def nat_of_char_eq_iff[symmetric] a_def[symmetric] b_def[symmetric] \n    by assumption\nqed\n  \nlemma \"CHR ''y'' \\<noteq> CHR ''z''\" \n  using[[simp_trace_new]]\n  by (simp only: List.list.inject mk_legacy_char_inj legacy_char.inject nibble.distinct legacy_char_simps HOL.simp_thms)\n    \n\nend\n", "meta": {"author": "dominique-unruh", "repo": "IsaCrypt", "sha": "1abc2041871af7b758adcc914b83f0d9135ec129", "save_path": "github-repos/isabelle/dominique-unruh-IsaCrypt", "path": "github-repos/isabelle/dominique-unruh-IsaCrypt/IsaCrypt-1abc2041871af7b758adcc914b83f0d9135ec129/Legacy_Char.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6825737214979745, "lm_q2_score": 0.4186969093556867, "lm_q1q2_score": 0.28579150759861116}}
{"text": "(*  Title:       Safe OCL\n    Author:      Denis Nikiforov, March 2019\n    Maintainer:  Denis Nikiforov <denis.nikif at gmail.com>\n    License:     LGPL\n*)\nsection \\<open>Object Model\\<close>\ntheory Object_Model\n  imports Finite_Map_Ext \"HOL-Library.Extended_Nat\"\n          \"HOL-Library.Phantom_Type\"\nbegin\n\ntext \\<open>\n  The section defines a generic object model.\\<close>\n\n(*** Type Synonyms **********************************************************)\n\nsubsection \\<open>Type Synonyms\\<close>\n\ntype_synonym attr = String.literal\ntype_synonym assoc = String.literal\ntype_synonym role = String.literal\ntype_synonym oper = String.literal\ntype_synonym param = String.literal\ntype_synonym elit = String.literal\n\ntype_synonym 'a enum_type = \"('a, String.literal) phantom\"\n\ndatatype param_dir = In | Out | InOut\n\ntype_synonym 'c assoc_end = \"'c \\<times> nat \\<times> enat \\<times> bool \\<times> bool\"\ntype_synonym 't param_spec = \"param \\<times> 't \\<times> param_dir\"\ntype_synonym ('t, 'e) oper_def = \"oper \\<times> 't param_spec list \\<times> 't \\<times> bool \\<times> 'e option\"\ntype_synonym ('t, 'e) oper_spec = \"'t \\<times> ('t, 'e) oper_def\"\n\ndefinition \"assoc_end_class :: 'c assoc_end \\<Rightarrow> 'c \\<equiv> fst\"\ndefinition \"assoc_end_min :: 'c assoc_end \\<Rightarrow> nat \\<equiv> fst \\<circ> snd\"\ndefinition \"assoc_end_max :: 'c assoc_end \\<Rightarrow> enat \\<equiv> fst \\<circ> snd \\<circ> snd\"\ndefinition \"assoc_end_ordered :: 'c assoc_end \\<Rightarrow> bool \\<equiv> fst \\<circ> snd \\<circ> snd \\<circ> snd\"\ndefinition \"assoc_end_unique :: 'c assoc_end \\<Rightarrow> bool \\<equiv> snd \\<circ> snd \\<circ> snd \\<circ> snd\"\n\ndefinition \"oper_context :: ('t, 'e) oper_spec \\<Rightarrow> 't \\<equiv> fst\"\ndefinition \"oper_name :: ('t, 'e) oper_spec \\<Rightarrow> oper \\<equiv> fst \\<circ> snd\"\ndefinition \"oper_params :: ('t, 'e) oper_spec \\<Rightarrow> 't param_spec list \\<equiv> fst \\<circ> snd \\<circ> snd\"\ndefinition \"oper_result :: ('t, 'e) oper_spec \\<Rightarrow> 't \\<equiv> fst \\<circ> snd \\<circ> snd \\<circ> snd\"\ndefinition \"oper_static :: ('t, 'e) oper_spec \\<Rightarrow> bool \\<equiv> fst \\<circ> snd \\<circ> snd \\<circ> snd \\<circ> snd\"\ndefinition \"oper_body :: ('t, 'e) oper_spec \\<Rightarrow> 'e option \\<equiv> snd \\<circ> snd \\<circ> snd \\<circ> snd \\<circ> snd\"\n\ndefinition \"param_name ::'t param_spec \\<Rightarrow> param \\<equiv> fst\"\ndefinition \"param_type ::'t param_spec \\<Rightarrow> 't \\<equiv> fst \\<circ> snd\"\ndefinition \"param_dir ::'t param_spec \\<Rightarrow> param_dir \\<equiv> snd \\<circ> snd\"\n\ndefinition \"oper_in_params op \\<equiv>\n  filter (\\<lambda>p. param_dir p = In \\<or> param_dir p = InOut) (oper_params op)\"\n\ndefinition \"oper_out_params op \\<equiv>\n  filter (\\<lambda>p. param_dir p = Out \\<or> param_dir p = InOut) (oper_params op)\"\n\nsubsection \\<open>Attributes\\<close>\n\ninductive owned_attribute' where\n  \"\\<C> |\\<in>| fmdom attributes \\<Longrightarrow>\n   fmlookup attributes \\<C> = Some attrs\\<^sub>\\<C> \\<Longrightarrow>\n   fmlookup attrs\\<^sub>\\<C> attr = Some \\<tau> \\<Longrightarrow>\n   owned_attribute' attributes \\<C> attr \\<tau>\"\n\ninductive attribute_not_closest where\n  \"owned_attribute' attributes \\<D>' attr \\<tau>' \\<Longrightarrow>\n   \\<C> \\<le> \\<D>' \\<Longrightarrow>\n   \\<D>' < \\<D> \\<Longrightarrow>\n   attribute_not_closest attributes \\<C> attr \\<D> \\<tau>\"\n\ninductive closest_attribute where\n  \"owned_attribute' attributes \\<D> attr \\<tau> \\<Longrightarrow>\n   \\<C> \\<le> \\<D> \\<Longrightarrow>\n   \\<not> attribute_not_closest attributes \\<C> attr \\<D> \\<tau> \\<Longrightarrow>\n   closest_attribute attributes \\<C> attr \\<D> \\<tau>\"\n\ninductive closest_attribute_not_unique where\n  \"closest_attribute attributes \\<C> attr \\<D>' \\<tau>' \\<Longrightarrow>\n   \\<D> \\<noteq> \\<D>' \\<or> \\<tau> \\<noteq> \\<tau>' \\<Longrightarrow>\n   closest_attribute_not_unique attributes \\<C> attr \\<D> \\<tau>\"\n\ninductive unique_closest_attribute where\n  \"closest_attribute attributes \\<C> attr \\<D> \\<tau> \\<Longrightarrow>\n   \\<not> closest_attribute_not_unique attributes \\<C> attr \\<D> \\<tau> \\<Longrightarrow>\n   unique_closest_attribute attributes \\<C> attr \\<D> \\<tau>\"\n\nsubsection \\<open>Association Ends\\<close>\n\ninductive role_refer_class where\n  \"role |\\<in>| fmdom ends \\<Longrightarrow>\n   fmlookup ends role = Some end \\<Longrightarrow>\n   assoc_end_class end = \\<C> \\<Longrightarrow>\n   role_refer_class ends \\<C> role\"\n\ninductive association_ends' where\n  \"\\<C> |\\<in>| classes \\<Longrightarrow>\n   assoc |\\<in>| fmdom associations \\<Longrightarrow>\n   fmlookup associations assoc = Some ends \\<Longrightarrow>\n   role_refer_class ends \\<C> from \\<Longrightarrow>\n   role |\\<in>| fmdom ends \\<Longrightarrow>\n   fmlookup ends role = Some end \\<Longrightarrow>\n   role \\<noteq> from \\<Longrightarrow>\n   association_ends' classes associations \\<C> from role end\"\n\ninductive association_ends_not_unique' where\n  \"association_ends' classes associations \\<C> from role end\\<^sub>1 \\<Longrightarrow>\n   association_ends' classes associations \\<C> from role end\\<^sub>2 \\<Longrightarrow>\n   end\\<^sub>1 \\<noteq> end\\<^sub>2 \\<Longrightarrow>\n   association_ends_not_unique' classes associations\"\n\ninductive owned_association_end' where\n  \"association_ends' classes associations \\<C> from role end \\<Longrightarrow>\n   owned_association_end' classes associations \\<C> None role end\"\n| \"association_ends' classes associations \\<C> from role end \\<Longrightarrow>\n   owned_association_end' classes associations \\<C> (Some from) role end\"\n\ninductive association_end_not_closest where\n  \"owned_association_end' classes associations \\<D>' from role end' \\<Longrightarrow>\n   \\<C> \\<le> \\<D>' \\<Longrightarrow>\n   \\<D>' < \\<D> \\<Longrightarrow>\n   association_end_not_closest classes associations \\<C> from role \\<D> end\"\n\ninductive closest_association_end where\n  \"owned_association_end' classes associations \\<D> from role end \\<Longrightarrow>\n   \\<C> \\<le> \\<D> \\<Longrightarrow>\n   \\<not> association_end_not_closest classes associations \\<C> from role \\<D> end \\<Longrightarrow>\n   closest_association_end classes associations \\<C> from role \\<D> end\"\n\ninductive closest_association_end_not_unique where\n  \"closest_association_end classes associations \\<C> from role \\<D>' end' \\<Longrightarrow>\n   \\<D> \\<noteq> \\<D>' \\<or> end \\<noteq> end' \\<Longrightarrow>\n   closest_association_end_not_unique classes associations \\<C> from role \\<D> end\"\n\ninductive unique_closest_association_end where\n  \"closest_association_end classes associations \\<C> from role \\<D> end \\<Longrightarrow>\n   \\<not> closest_association_end_not_unique classes associations \\<C> from role \\<D> end \\<Longrightarrow>\n   unique_closest_association_end classes associations \\<C> from role \\<D> end\"\n\nsubsection \\<open>Association Classes\\<close>\n\ninductive referred_by_association_class'' where\n  \"fmlookup association_classes \\<A> = Some assoc \\<Longrightarrow>\n   fmlookup associations assoc = Some ends \\<Longrightarrow>\n   role_refer_class ends \\<C> from \\<Longrightarrow>\n   referred_by_association_class'' association_classes associations \\<C> from \\<A>\"\n\ninductive referred_by_association_class' where\n  \"referred_by_association_class'' association_classes associations \\<C> from \\<A> \\<Longrightarrow>\n   referred_by_association_class' association_classes associations \\<C> None \\<A>\"\n| \"referred_by_association_class'' association_classes associations \\<C> from \\<A> \\<Longrightarrow>\n   referred_by_association_class' association_classes associations \\<C> (Some from) \\<A>\"\n\ninductive association_class_not_closest where\n  \"referred_by_association_class' association_classes associations \\<D>' from \\<A> \\<Longrightarrow>\n   \\<C> \\<le> \\<D>' \\<Longrightarrow>\n   \\<D>' < \\<D> \\<Longrightarrow>\n   association_class_not_closest association_classes associations \\<C> from \\<A> \\<D>\"\n\ninductive closest_association_class where\n  \"referred_by_association_class' association_classes associations \\<D> from \\<A> \\<Longrightarrow>\n   \\<C> \\<le> \\<D> \\<Longrightarrow>\n   \\<not> association_class_not_closest association_classes associations \\<C> from \\<A> \\<D> \\<Longrightarrow>\n   closest_association_class association_classes associations \\<C> from \\<A> \\<D>\"\n\ninductive closest_association_class_not_unique where\n  \"closest_association_class association_classes associations \\<C> from \\<A> \\<D>' \\<Longrightarrow>\n   \\<D> \\<noteq> \\<D>' \\<Longrightarrow>\n   closest_association_class_not_unique\n        association_classes associations \\<C> from \\<A> \\<D>\"\n\ninductive unique_closest_association_class where\n  \"closest_association_class association_classes associations \\<C> from \\<A> \\<D> \\<Longrightarrow>\n   \\<not> closest_association_class_not_unique\n        association_classes associations \\<C> from \\<A> \\<D> \\<Longrightarrow>\n   unique_closest_association_class association_classes associations \\<C> from \\<A> \\<D>\"\n\nsubsection \\<open>Association Class Ends\\<close>\n\ninductive association_class_end' where\n  \"fmlookup association_classes \\<A> = Some assoc \\<Longrightarrow>\n   fmlookup associations assoc = Some ends \\<Longrightarrow>\n   fmlookup ends role = Some end \\<Longrightarrow>\n   association_class_end' association_classes associations \\<A> role end\"\n\ninductive association_class_end_not_unique where\n  \"association_class_end' association_classes associations \\<A> role end' \\<Longrightarrow>\n   end \\<noteq> end' \\<Longrightarrow>\n   association_class_end_not_unique association_classes associations \\<A> role end\"\n\ninductive unique_association_class_end where\n  \"association_class_end' association_classes associations \\<A> role end \\<Longrightarrow>\n   \\<not> association_class_end_not_unique\n        association_classes associations \\<A> role end \\<Longrightarrow>\n   unique_association_class_end association_classes associations \\<A> role end\"\n\nsubsection \\<open>Operations\\<close>\n\ninductive any_operation' where\n  \"op |\\<in>| fset_of_list operations \\<Longrightarrow>\n   oper_name op = name \\<Longrightarrow>\n   \\<tau> \\<le> oper_context op \\<Longrightarrow>\n   list_all2 (\\<lambda>\\<sigma> param. \\<sigma> \\<le> param_type param) \\<pi> (oper_in_params op) \\<Longrightarrow>\n   any_operation' operations \\<tau> name \\<pi> op\"\n\ninductive operation' where\n  \"any_operation' operations \\<tau> name \\<pi> op \\<Longrightarrow>\n   \\<not> oper_static op \\<Longrightarrow>\n   operation' operations \\<tau> name \\<pi> op\"\n\ninductive operation_not_unique where\n  \"operation' operations \\<tau> name \\<pi> oper' \\<Longrightarrow>\n   oper \\<noteq> oper' \\<Longrightarrow>\n   operation_not_unique operations \\<tau> name \\<pi> oper\"\n\ninductive unique_operation where\n  \"operation' operations \\<tau> name \\<pi> oper \\<Longrightarrow>\n   \\<not> operation_not_unique operations \\<tau> name \\<pi> oper \\<Longrightarrow>\n   unique_operation operations \\<tau> name \\<pi> oper\"\n\ninductive operation_defined' where\n  \"unique_operation operations \\<tau> name \\<pi> oper \\<Longrightarrow>\n   operation_defined' operations \\<tau> name \\<pi>\"\n\ninductive static_operation' where\n  \"any_operation' operations \\<tau> name \\<pi> op \\<Longrightarrow>\n   oper_static op \\<Longrightarrow>\n   static_operation' operations \\<tau> name \\<pi> op\"\n\ninductive static_operation_not_unique where\n  \"static_operation' operations \\<tau> name \\<pi> oper' \\<Longrightarrow>\n   oper \\<noteq> oper' \\<Longrightarrow>\n   static_operation_not_unique operations \\<tau> name \\<pi> oper\"\n\ninductive unique_static_operation where\n  \"static_operation' operations \\<tau> name \\<pi> oper \\<Longrightarrow>\n   \\<not> static_operation_not_unique operations \\<tau> name \\<pi> oper \\<Longrightarrow>\n   unique_static_operation operations \\<tau> name \\<pi> oper\"\n\ninductive static_operation_defined' where\n  \"unique_static_operation operations \\<tau> name \\<pi> oper \\<Longrightarrow>\n   static_operation_defined' operations \\<tau> name \\<pi>\"\n\nsubsection \\<open>Literals\\<close>\n\ninductive has_literal' where\n  \"fmlookup literals e = Some lits \\<Longrightarrow>\n   lit |\\<in>| lits \\<Longrightarrow>\n   has_literal' literals e lit\"\n\n(*** Definition *************************************************************)\n\nsubsection \\<open>Definition\\<close>\n\nlocale object_model =\n  fixes classes :: \"'a :: semilattice_sup fset\"\n    and attributes :: \"'a \\<rightharpoonup>\\<^sub>f attr \\<rightharpoonup>\\<^sub>f 't :: order\"\n    and associations :: \"assoc \\<rightharpoonup>\\<^sub>f role \\<rightharpoonup>\\<^sub>f 'a assoc_end\"\n    and association_classes :: \"'a \\<rightharpoonup>\\<^sub>f assoc\"\n    and operations :: \"('t, 'e) oper_spec list\"\n    and literals :: \"'a enum_type \\<rightharpoonup>\\<^sub>f elit fset\"\n  assumes assoc_end_min_less_eq_max:\n    \"assoc |\\<in>| fmdom associations \\<Longrightarrow>\n     fmlookup associations assoc = Some ends \\<Longrightarrow>\n     role |\\<in>| fmdom ends  \\<Longrightarrow>\n     fmlookup ends role = Some end \\<Longrightarrow>\n     assoc_end_min end \\<le> assoc_end_max end\"\n  assumes association_ends_unique:\n    \"association_ends' classes associations \\<C> from role end\\<^sub>1 \\<Longrightarrow>\n     association_ends' classes associations \\<C> from role end\\<^sub>2 \\<Longrightarrow> end\\<^sub>1 = end\\<^sub>2\"\nbegin\n\nabbreviation \"owned_attribute \\<equiv>\n  owned_attribute' attributes\"\n\nabbreviation \"attribute \\<equiv>\n  unique_closest_attribute attributes\"\n\nabbreviation \"association_ends \\<equiv>\n  association_ends' classes associations\"\n\nabbreviation \"owned_association_end \\<equiv>\n  owned_association_end' classes associations\"\n\nabbreviation \"association_end \\<equiv>\n  unique_closest_association_end classes associations\"\n\nabbreviation \"referred_by_association_class \\<equiv>\n  unique_closest_association_class association_classes associations\"\n\nabbreviation \"association_class_end \\<equiv>\n  unique_association_class_end association_classes associations\"\n\nabbreviation \"operation \\<equiv>\n  unique_operation operations\"\n\nabbreviation \"operation_defined \\<equiv>\n  operation_defined' operations\"\n\nabbreviation \"static_operation \\<equiv>\n  unique_static_operation operations\"\n\nabbreviation \"static_operation_defined \\<equiv>\n  static_operation_defined' operations\"\n\nabbreviation \"has_literal \\<equiv>\n  has_literal' literals\"\n\nend\n\nlemmas object_model_simps =\n  assoc_end_class_def\n  assoc_end_min_def\n  assoc_end_max_def\n  assoc_end_ordered_def\n  assoc_end_unique_def\n  oper_name_def\n  oper_context_def\n  oper_params_def\n  oper_result_def\n  oper_static_def\n  oper_body_def\n  oper_in_params_def\n  oper_out_params_def\n  has_literal'.simps\n\n(*** Properties *************************************************************)\n\nsubsection \\<open>Properties\\<close>\n\nlemma (in object_model) attribute_det:\n  \"attribute \\<C> attr \\<D>\\<^sub>1 \\<tau>\\<^sub>1 \\<Longrightarrow>\n   attribute \\<C> attr \\<D>\\<^sub>2 \\<tau>\\<^sub>2 \\<Longrightarrow> \\<D>\\<^sub>1 = \\<D>\\<^sub>2 \\<and> \\<tau>\\<^sub>1 = \\<tau>\\<^sub>2\"\n  by (meson closest_attribute_not_unique.intros unique_closest_attribute.cases)\n\nlemma (in object_model) attribute_self_or_inherited:\n  \"attribute \\<C> attr \\<D> \\<tau> \\<Longrightarrow> \\<C> \\<le> \\<D>\"\n  by (meson closest_attribute.cases unique_closest_attribute.cases)\n\nlemma (in object_model) attribute_closest:\n  \"attribute \\<C> attr \\<D> \\<tau> \\<Longrightarrow>\n   owned_attribute \\<D>' attr \\<tau> \\<Longrightarrow>\n   \\<C> \\<le> \\<D>' \\<Longrightarrow> \\<not> \\<D>' < \\<D>\"\n  by (meson attribute_not_closest.intros closest_attribute.cases\n      unique_closest_attribute.cases)\n\n\nlemma (in object_model) association_end_det:\n  \"association_end \\<C> from role \\<D>\\<^sub>1 end\\<^sub>1 \\<Longrightarrow>\n   association_end \\<C> from role \\<D>\\<^sub>2 end\\<^sub>2 \\<Longrightarrow> \\<D>\\<^sub>1 = \\<D>\\<^sub>2 \\<and> end\\<^sub>1 = end\\<^sub>2\"\n  by (meson closest_association_end_not_unique.intros\n      unique_closest_association_end.cases)\n\nlemma (in object_model) association_end_self_or_inherited:\n  \"association_end \\<C> from role \\<D> end \\<Longrightarrow> \\<C> \\<le> \\<D>\"\n  by (meson closest_association_end.cases unique_closest_association_end.cases)\n\nlemma (in object_model) association_end_closest:\n  \"association_end \\<C> from role \\<D> end \\<Longrightarrow>\n   owned_association_end \\<D>' from role end \\<Longrightarrow>\n   \\<C> \\<le> \\<D>' \\<Longrightarrow> \\<not> \\<D>' < \\<D>\"\n  by (meson association_end_not_closest.intros closest_association_end.cases\n      unique_closest_association_end.cases)\n\n\nlemma (in object_model) association_class_end_det:\n  \"association_class_end \\<A> role end\\<^sub>1 \\<Longrightarrow>\n   association_class_end \\<A> role end\\<^sub>2 \\<Longrightarrow> end\\<^sub>1 = end\\<^sub>2\"\n  by (meson association_class_end_not_unique.intros unique_association_class_end.cases)\n\n\nlemma (in object_model) operation_det:\n  \"operation \\<tau> name \\<pi> oper\\<^sub>1 \\<Longrightarrow>\n   operation \\<tau> name \\<pi> oper\\<^sub>2 \\<Longrightarrow> oper\\<^sub>1 = oper\\<^sub>2\"\n  by (meson operation_not_unique.intros unique_operation.cases)\n\nlemma (in object_model) static_operation_det:\n  \"static_operation \\<tau> name \\<pi> oper\\<^sub>1 \\<Longrightarrow>\n   static_operation \\<tau> name \\<pi> oper\\<^sub>2 \\<Longrightarrow> oper\\<^sub>1 = oper\\<^sub>2\"\n  by (meson static_operation_not_unique.intros unique_static_operation.cases)\n\n(*** Notation ***************************************************************)\n\nsubsection \\<open>Notation\\<close>\n\ndatatype ('a, 't, 'e) model_element_spec =\n  EnumSpec \"'a enum_type\" \"elit list\"\n| ClassSpec 'a \"attr \\<rightharpoonup>\\<^sub>f 't\"\n| AssociationSpec assoc \"role \\<rightharpoonup>\\<^sub>f 'a assoc_end\"\n| ContextSpec 't \"('t, 'e) oper_def list\"\n\ndatatype ('a, 't, 'e) model_spec =\n  ModelSpec (model_spec_elements: \"('a, 't, 'e) model_element_spec list\")\n\nprimrec model_spec_classes where\n  \"model_spec_classes [] = []\"\n| \"model_spec_classes (x # xs) = (case x\n    of ClassSpec cls attrs \\<Rightarrow> (cls, attrs) # (model_spec_classes xs)\n     | _ \\<Rightarrow> (model_spec_classes xs))\"\n\nprimrec model_spec_assocs where\n  \"model_spec_assocs [] = []\"\n| \"model_spec_assocs (x # xs) = (case x\n    of AssociationSpec assoc ends \\<Rightarrow> (assoc, ends) # (model_spec_assocs xs)\n     | _ \\<Rightarrow> (model_spec_assocs xs))\"\n\nprimrec model_spec_contexts where\n  \"model_spec_contexts [] = []\"\n| \"model_spec_contexts (x # xs) = (case x\n    of ContextSpec ctx opers \\<Rightarrow> (ctx, opers) # (model_spec_contexts xs)\n     | _ \\<Rightarrow> (model_spec_contexts xs))\"\n\nprimrec model_spec_enums where\n  \"model_spec_enums [] = []\"\n| \"model_spec_enums (x # xs) = (case x\n    of EnumSpec enm lits \\<Rightarrow> (enm, fset_of_list lits) # (model_spec_enums xs)\n     | _ \\<Rightarrow> (model_spec_enums xs))\"\n\ndefinition \"model_spec_attributes m \\<equiv>\n  fmap_of_list (model_spec_classes (model_spec_elements m))\"\n\ndefinition \"model_spec_assoc_ens m \\<equiv>\n  fmap_of_list (model_spec_assocs (model_spec_elements m))\"\n\ndefinition \"model_spec_operations m \\<equiv>\n  concat (map (\\<lambda>ctx. map (\\<lambda>op. (fst ctx, op)) (snd ctx))\n      (model_spec_contexts (model_spec_elements m)))\"\n\ndefinition \"model_spec_enum_literals m \\<equiv>\n  fmap_of_list (model_spec_enums (model_spec_elements m))\"\n\nlemmas object_model_notation_simps =\n  model_spec_elements_def\n  model_spec_assocs_def\n  model_spec_assoc_ens_def\n  model_spec_enum_literals_def\n\nnonterminal model_elements and model_element\n\nnonterminal enum_def and enum_literal_defs and enum_literal_def\n\nsyntax\n  \"_enum_def\" :: \"'a \\<Rightarrow> enum_literal_defs \\<Rightarrow> model_element\" (\"enum _ {_}\" [1000,0] 0)\n  \"_enum_literal_defs_single\" :: \"elit \\<Rightarrow> enum_literal_defs\" (\"_\")\n  \"_enum_literal_defs_cons\" :: \"elit \\<Rightarrow> enum_literal_defs \\<Rightarrow> enum_literal_defs\" (\"_, _\")\n\ntranslations\n  \"_enum_def name literals\" \\<rightharpoonup> \"CONST EnumSpec name literals\"\n  \"_enum_literal_defs_cons x (y # xs)\" \\<rightharpoonup> \"x # y # xs\"\n  \"_enum_literal_defs_single x\" \\<rightharpoonup> \"[x]\"\n\nnonterminal class_defs and class_def\nnonterminal attr_defs and attr_def\n\nsyntax\n  \"_class_def\" :: \"'a \\<Rightarrow> attr_defs \\<Rightarrow> model_element\" (\"class _ _\" [1000,0] 0)\n  \"_class_def\" :: \"'a \\<Rightarrow> model_element\" (\"class _\" [1000] 0)\n  \"_attr_def\" :: \"'a \\<Rightarrow> 'b \\<Rightarrow> attr_def\" (\"_ : _\" [1000,1000] 0)\n  \"_attr_defs_single\" :: \"attr_def \\<Rightarrow> attr_defs\" (\"_\")\n  \"_attr_defs_cons\" :: \"attr_def \\<Rightarrow> attr_defs \\<Rightarrow> attr_defs\" (\"_ _\")\n\ntranslations\n  \"_class_def cls attrs\" \\<rightharpoonup> \"CONST ClassSpec cls (CONST fmap_of_list attrs)\"\n  \"_class_def cls\" \\<rightharpoonup> \"CONST ClassSpec cls (CONST fmap_of_list [])\"\n  \"_attr_def x y\" \\<rightharpoonup> \"(x, y)\"\n  \"_attr_defs_single x\" \\<rightharpoonup> \"[x]\"\n  \"_attr_defs_cons x (y # xs)\" \\<rightharpoonup> \"x # y # xs\"\n\nnonterminal assoc_defs and assoc_def\nnonterminal assoc_end_defs and assoc_end_def\nnonterminal assoc_end_mult\n\nsyntax\n  \"_assoc_def\" :: \"'a \\<Rightarrow> assoc_end_defs \\<Rightarrow> model_element\"\n      (\"association _ _\" [1000,100] 10)\n  \"_assoc_end_defs_single\" :: \"assoc_end_def \\<Rightarrow> assoc_end_defs\" (\"_\")\n  \"_assoc_end_defs_cons\" :: \"assoc_end_def \\<Rightarrow> assoc_end_defs \\<Rightarrow> assoc_end_defs\"\n      (\"_ _\")\n  \"_assoc_end_def\" :: \"'a \\<Rightarrow> 'b \\<Rightarrow> assoc_end_mult \\<Rightarrow> assoc_end_def\"\n      (\"_ : _ _\" [100,100,100] 100)\n  \"_assoc_end_def_o\" :: \"'a \\<Rightarrow> 'b \\<Rightarrow> assoc_end_mult \\<Rightarrow> assoc_end_def\"\n      (\"_ : _ _ {ordered}\" [100,100,100] 100)\n  \"_assoc_end_def_u\" :: \"'a \\<Rightarrow> 'b \\<Rightarrow> assoc_end_mult \\<Rightarrow> assoc_end_def\"\n      (\"_ : _ _ {unique}\" [100,100,100] 100)\n  \"_assoc_end_def_ou\" :: \"'a \\<Rightarrow> 'b \\<Rightarrow> assoc_end_mult \\<Rightarrow> assoc_end_def\"\n      (\"_ : _ _ {ordered,unique}\" [100,100,100] 100)\n\n  \"_assoc_end_mult_both\" :: \"nat \\<Rightarrow> assoc_end_mult\" (\"[_]\" [1000] 100)\n  \"_assoc_end_mult_lower\" :: \"nat \\<Rightarrow> assoc_end_mult\" (\"[_..(*)]\" [1000] 100)\n  \"_assoc_end_mult\" :: \"nat \\<Rightarrow> nat \\<Rightarrow> assoc_end_mult\" (\"[_.._]\" [1000,1000] 100)\n\ntranslations\n  \"_assoc_def assoc ends\" \\<rightharpoonup>\n      \"CONST AssociationSpec assoc (CONST fmap_of_list ends)\"\n  \"_assoc_end_defs_single x\" \\<rightharpoonup> \"[x]\"\n  \"_assoc_end_defs_cons x (y # xs)\" \\<rightharpoonup> \"x # y # xs\"\n  \"_assoc_end_def name cls (CONST Pair lower upper)\" \\<rightharpoonup>\n      \"(name, cls, lower, upper, CONST False, CONST False)\"\n  \"_assoc_end_def_o name cls (CONST Pair lower upper)\" \\<rightharpoonup>\n      \"(name, cls, lower, upper, CONST True, CONST False)\"\n  \"_assoc_end_def_u name cls (CONST Pair lower upper)\" \\<rightharpoonup>\n      \"(name, cls, lower, upper, CONST False, CONST True)\"\n  \"_assoc_end_def_ou name cls (CONST Pair lower upper)\" \\<rightharpoonup>\n      \"(name, cls, lower, upper, CONST True, CONST True)\"\n\n  \"_assoc_end_mult_both x\" \\<rightharpoonup> \"CONST Pair (x :: nat) (x :: enat)\"\n  \"_assoc_end_mult_lower x\" \\<rightharpoonup> \"CONST Pair (x :: nat) (\\<infinity> :: enat)\"\n  \"_assoc_end_mult x y\" \\<rightharpoonup> \"CONST Pair (x :: nat) (y :: enat)\"\n\nnonterminal context_defs and context_def\nnonterminal oper_defs and oper_def_const and oper_signature\nnonterminal oper_params and oper_param\n\nsyntax\n  \"_oper_param\" :: \"'a \\<Rightarrow> 'a \\<Rightarrow> oper_param\" (\"_ : _\")\n  \"_oper_param_in\" :: \"'a \\<Rightarrow> 'a \\<Rightarrow> oper_param\" (\"in _ : _\")\n  \"_oper_param_out\" :: \"'a \\<Rightarrow> 'a \\<Rightarrow> oper_param\" (\"out _ : _\")\n  \"_oper_param_inout\" :: \"'a \\<Rightarrow> 'a \\<Rightarrow> oper_param\" (\"inout _ : _\")\n  \"_oper_params_nil\" :: \"oper_params\" (\"\")\n  \"_oper_params_single\" :: \"oper_param \\<Rightarrow> oper_params\" (\"_\")\n  \"_oper_params_cons\" :: \"oper_param \\<Rightarrow> oper_params \\<Rightarrow> oper_params\" (\"_, _\")\n\ntranslations\n  \"_oper_param param ty\" \\<rightharpoonup> \"(param, ty, CONST In)\"\n  \"_oper_param_in param ty\" \\<rightharpoonup> \"(param, ty, CONST In)\"\n  \"_oper_param_out param ty\" \\<rightharpoonup> \"(param, ty, CONST Out)\"\n  \"_oper_param_inout param ty\" \\<rightharpoonup> \"(param, ty, CONST InOut)\"\n  \"_oper_params_nil\" \\<rightharpoonup> \"[]\"\n  \"_oper_params_single x\" \\<rightharpoonup> \"[x]\"\n  \"_oper_params_cons x xs\" \\<rightharpoonup> \"x # xs\"\n\nsyntax\n  \"_context_def\" :: \"'a \\<Rightarrow> oper_defs \\<Rightarrow> model_element\"\n      (\"context _ _\" [1000,100] 10)\n  \"_oper_def\" :: \"oper_signature \\<Rightarrow> 'a \\<Rightarrow> oper_def_const\"\n      (\"def : _ = _\" [100,100] 100)\n  \"_oper_def_no_body\" :: \"oper_signature \\<Rightarrow> oper_def_const\"\n      (\"def : _\" [100] 100)\n  \"_oper_def_static\" :: \"oper_signature \\<Rightarrow> 'a \\<Rightarrow> oper_def_const\"\n      (\"static def : _ = _\" [100,100] 100)\n  \"_oper_def_static_no_body\" :: \"oper_signature \\<Rightarrow> oper_def_const\"\n      (\"static def : _\" [100] 100)\n  \"_oper_defs_nil\" :: \"oper_defs\" (\"\")\n  \"_oper_defs_cons\" :: \"oper_def_const \\<Rightarrow> oper_defs \\<Rightarrow> oper_defs\" (\"_ _\")\n  \"_oper_signature\" :: \"'a \\<Rightarrow> oper_params \\<Rightarrow> 'b \\<Rightarrow> oper_signature\"\n      (\"_'(_') : _\" [1000,100,100] 100)\n  \"_oper_signature_no_params\" :: \"'a \\<Rightarrow> 'b \\<Rightarrow> oper_signature\"\n      (\"_'(') : _\" [1000,100] 100)\n\n(*definition \"mk_oper_spec op st body \\<equiv> (fst op, fst (snd op), snd (snd op), st, body)\"*)\n\ndatatype ('a, 'b, 'c) Triple = Triple 'a 'b 'c\n\ntranslations\n  \"_context_def ctx ops\" \\<rightharpoonup> \"CONST ContextSpec ctx ops\"\n  \"_oper_defs_nil\" \\<rightharpoonup> \"[]\"\n  \"_oper_defs_cons x xs\" \\<rightharpoonup> \"x # xs\"\n\n  \"_oper_def (CONST Triple op params ty) body\" \\<rightharpoonup>\n      \"(op, params, ty, CONST False, CONST Some body)\"\n  \"_oper_def_no_body (CONST Triple op params ty)\" \\<rightharpoonup>\n      \"(op, params, ty, CONST False, CONST None)\"\n  \"_oper_def_static (CONST Triple op params ty) body\" \\<rightharpoonup>\n      \"(op, params, ty, CONST True, CONST Some body)\"\n  \"_oper_def_static_no_body (CONST Triple op params ty)\" \\<rightharpoonup>\n      \"(op, params, ty, CONST True, CONST None)\"\n\n  \"_oper_signature op params ty\" \\<rightharpoonup> \"CONST Triple op params ty\"\n  \"_oper_signature_no_params op ty\" \\<rightharpoonup> \"CONST Triple op [] ty\"\n(*\n  \"_oper_def sign body\" \\<rightharpoonup>\n      \"CONST mk_oper_spec sign CONST False (CONST Some body)\"\n  \"_oper_def_no_body sign\" \\<rightharpoonup>\n      \"CONST mk_oper_spec sign CONST False CONST None\"\n  \"_oper_def_static sign body\" \\<rightharpoonup>\n      \"CONST mk_oper_spec sign CONST True (CONST Some body)\"\n  \"_oper_def_static_no_body sign\" \\<rightharpoonup>\n      \"CONST mk_oper_spec sign CONST True (CONST None)\"\n  \"_oper_signature op params ty\" \\<rightharpoonup> \"(op, params, ty)\"\n  \"_oper_signature_no_params op ty\" \\<rightharpoonup> \"(op, [], ty)\"\n*)\n\nsyntax\n  \"_model\" :: \"model_elements \\<Rightarrow> ('a, 't, 'e) model_spec\" (\"_\" 10)\n  \"_model_element_single\" :: \"model_element \\<Rightarrow> model_elements\" (\" _\")\n  \"_model_element_cons\" ::\n      \"model_element \\<Rightarrow> model_elements \\<Rightarrow> model_elements\" (\"_ _\")\n\ntranslations\n  \"_model xs\" \\<rightharpoonup> \"CONST ModelSpec xs\"\n  \"_model_element_single x\" \\<rightharpoonup> \"[x]\"\n  \"_model_element_cons x (y # xs)\" \\<rightharpoonup> \"x # y # xs\"\n\nterm \"\nassociation qwea\nz : x [1]\"\n\nterm \"\nassociation qwea\nz : x [1..2]\nz : x [1..2]\n\ncontext q\n  def: STR ''q''(qq : zz) : ff = ee\n  static def : zzz() : qq\"\n\nterm \"\nassociation qwea\nz : x [1 .. 2]\nz : x [1] {ordered}\nz : x [1]\nz : x [1 .. *]\"\n\n\n(*** Code Setup *************************************************************)\n\nsubsection \\<open>Code Setup\\<close>\n\nlemma fmember_code_predI [code_pred_intro]:\n  \"x |\\<in>| xs\" if \"Predicate_Compile.contains (fset xs) x\"\n  using that by (simp add: Predicate_Compile.contains_def fmember.rep_eq)\n\ncode_pred fmember\n  by (simp add: Predicate_Compile.contains_def fmember.rep_eq)\n\ncode_pred unique_closest_attribute .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool) association_ends' .\n\ncode_pred association_ends_not_unique' .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool) owned_association_end' .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool) closest_association_end .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool ) closest_association_end_not_unique .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool) unique_closest_association_end .\n\ncode_pred unique_closest_association_class .\n\ncode_pred association_class_end' .\n\ncode_pred association_class_end_not_unique .\n\ncode_pred unique_association_class_end .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool) any_operation' .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool) operation' .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool) operation_not_unique .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool) unique_operation .\n\ncode_pred operation_defined' .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool) static_operation' .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool) static_operation_not_unique .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool) unique_static_operation .\n\ncode_pred static_operation_defined' .\n\ncode_pred has_literal' .\n\nend\n", "meta": {"author": "AresEkb", "repo": "Safe_OCL", "sha": "61efbf1207b7a0e892190fe36fb60daf6dcf45a5", "save_path": "github-repos/isabelle/AresEkb-Safe_OCL", "path": "github-repos/isabelle/AresEkb-Safe_OCL/Safe_OCL-61efbf1207b7a0e892190fe36fb60daf6dcf45a5/Object_Model.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6584175139669997, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.28574099716393986}}
{"text": "(*  Title:      HOL/MicroJava/BV/Correct.thy\n    Author:     Cornelia Pusch, Gerwin Klein\n    Copyright   1999 Technische Universitaet Muenchen\n*)\n\nsection {* BV Type Safety Invariant *}\n\ntheory Correct\nimports BVSpec \"../JVM/JVMExec\"\nbegin\n\ndefinition approx_val :: \"[jvm_prog,aheap,val,ty err] \\<Rightarrow> bool\" where\n  \"approx_val G h v any == case any of Err \\<Rightarrow> True | OK T \\<Rightarrow> G,h\\<turnstile>v::\\<preceq>T\"\n\ndefinition approx_loc :: \"[jvm_prog,aheap,val list,locvars_type] \\<Rightarrow> bool\" where\n  \"approx_loc G hp loc LT == list_all2 (approx_val G hp) loc LT\"\n\ndefinition approx_stk :: \"[jvm_prog,aheap,opstack,opstack_type] \\<Rightarrow> bool\" where\n  \"approx_stk G hp stk ST == approx_loc G hp stk (map OK ST)\"\n\ndefinition correct_frame  :: \"[jvm_prog,aheap,state_type,nat,bytecode] \\<Rightarrow> frame \\<Rightarrow> bool\" where\n  \"correct_frame G hp == \\<lambda>(ST,LT) maxl ins (stk,loc,C,sig,pc).\n                         approx_stk G hp stk ST  \\<and> approx_loc G hp loc LT \\<and> \n                         pc < length ins \\<and> length loc=length(snd sig)+maxl+1\"\n\nprimrec correct_frames  :: \"[jvm_prog,aheap,prog_type,ty,sig,frame list] \\<Rightarrow> bool\" where\n  \"correct_frames G hp phi rT0 sig0 [] = True\"\n| \"correct_frames G hp phi rT0 sig0 (f#frs) =\n    (let (stk,loc,C,sig,pc) = f in\n    (\\<exists>ST LT rT maxs maxl ins et.\n      phi C sig ! pc = Some (ST,LT) \\<and> is_class G C \\<and> \n      method (G,C) sig = Some(C,rT,(maxs,maxl,ins,et)) \\<and>\n    (\\<exists>C' mn pTs. ins!pc = (Invoke C' mn pTs) \\<and> \n           (mn,pTs) = sig0 \\<and> \n           (\\<exists>apTs D ST' LT'.\n           (phi C sig)!pc = Some ((rev apTs) @ (Class D) # ST', LT') \\<and>\n           length apTs = length pTs \\<and>\n           (\\<exists>D' rT' maxs' maxl' ins' et'.\n             method (G,D) sig0 = Some(D',rT',(maxs',maxl',ins',et')) \\<and>\n             G \\<turnstile> rT0 \\<preceq> rT') \\<and>\n     correct_frame G hp (ST, LT) maxl ins f \\<and> \n     correct_frames G hp phi rT sig frs))))\"\n\ndefinition correct_state :: \"[jvm_prog,prog_type,jvm_state] \\<Rightarrow> bool\"\n                  (\"_,_ |-JVM _ [ok]\"  [51,51] 50) where\n\"correct_state G phi == \\<lambda>(xp,hp,frs).\n   case xp of\n     None \\<Rightarrow> (case frs of\n             [] \\<Rightarrow> True\n             | (f#fs) \\<Rightarrow> G\\<turnstile>h hp\\<surd> \\<and> preallocated hp \\<and> \n      (let (stk,loc,C,sig,pc) = f\n             in\n                         \\<exists>rT maxs maxl ins et s.\n                         is_class G C \\<and>\n                         method (G,C) sig = Some(C,rT,(maxs,maxl,ins,et)) \\<and>\n                         phi C sig ! pc = Some s \\<and>\n       correct_frame G hp s maxl ins f \\<and> \n             correct_frames G hp phi rT sig fs))\n   | Some x \\<Rightarrow> frs = []\" \n\n\nnotation (xsymbols)\n correct_state  (\"_,_ \\<turnstile>JVM _ \\<surd>\"  [51,51] 50)\n\n\nlemma sup_ty_opt_OK:\n  \"(G \\<turnstile> X <=o (OK T')) = (\\<exists>T. X = OK T \\<and> G \\<turnstile> T \\<preceq> T')\"\n  by (cases X) auto\n\n\nsubsection {* approx-val *}\n\nlemma approx_val_Err [simp,intro!]:\n  \"approx_val G hp x Err\"\n  by (simp add: approx_val_def)\n\nlemma approx_val_OK [iff]: \n  \"approx_val G hp x (OK T) = (G,hp \\<turnstile> x ::\\<preceq> T)\"\n  by (simp add: approx_val_def)\n\nlemma approx_val_Null [simp,intro!]:\n  \"approx_val G hp Null (OK (RefT x))\"\n  by (auto simp add: approx_val_def)\n\nlemma approx_val_sup_heap:\n  \"\\<lbrakk> approx_val G hp v T; hp \\<le>| hp' \\<rbrakk> \\<Longrightarrow> approx_val G hp' v T\"\n  by (cases T) (blast intro: conf_hext)+\n\nlemma approx_val_heap_update:\n  \"\\<lbrakk> hp a = Some obj'; G,hp\\<turnstile> v::\\<preceq>T; obj_ty obj = obj_ty obj'\\<rbrakk> \n  \\<Longrightarrow> G,hp(a\\<mapsto>obj)\\<turnstile> v::\\<preceq>T\"\n  by (cases v) (auto simp add: obj_ty_def conf_def)\n\nlemma approx_val_widen:\n  \"\\<lbrakk> approx_val G hp v T; G \\<turnstile> T <=o T'; wf_prog wt G \\<rbrakk>\n  \\<Longrightarrow> approx_val G hp v T'\"\n  by (cases T') (auto simp add: sup_ty_opt_OK intro: conf_widen)\n\nsubsection {* approx-loc *}\n\nlemma approx_loc_Nil [simp,intro!]:\n  \"approx_loc G hp [] []\"\n  by (simp add: approx_loc_def)\n\nlemma approx_loc_Cons [iff]:\n  \"approx_loc G hp (l#ls) (L#LT) = \n  (approx_val G hp l L \\<and> approx_loc G hp ls LT)\"\nby (simp add: approx_loc_def)\n\nlemma approx_loc_nth:\n  \"\\<lbrakk> approx_loc G hp loc LT; n < length LT \\<rbrakk>\n  \\<Longrightarrow> approx_val G hp (loc!n) (LT!n)\"\n  by (simp add: approx_loc_def list_all2_conv_all_nth)\n\nlemma approx_loc_imp_approx_val_sup:\n  \"\\<lbrakk>approx_loc G hp loc LT; n < length LT; LT ! n = OK T; G \\<turnstile> T \\<preceq> T'; wf_prog wt G\\<rbrakk> \n  \\<Longrightarrow> G,hp \\<turnstile> (loc!n) ::\\<preceq> T'\"\n  apply (drule approx_loc_nth, assumption) \n  apply simp\n  apply (erule conf_widen, assumption+)\n  done\n\nlemma approx_loc_conv_all_nth:\n  \"approx_loc G hp loc LT = \n  (length loc = length LT \\<and> (\\<forall>n < length loc. approx_val G hp (loc!n) (LT!n)))\"\n  by (simp add: approx_loc_def list_all2_conv_all_nth)\n\nlemma approx_loc_sup_heap:\n  \"\\<lbrakk> approx_loc G hp loc LT; hp \\<le>| hp' \\<rbrakk>\n  \\<Longrightarrow> approx_loc G hp' loc LT\"\n  apply (clarsimp simp add: approx_loc_conv_all_nth)\n  apply (blast intro: approx_val_sup_heap)\n  done\n\nlemma approx_loc_widen:\n  \"\\<lbrakk> approx_loc G hp loc LT; G \\<turnstile> LT <=l LT'; wf_prog wt G \\<rbrakk>\n  \\<Longrightarrow> approx_loc G hp loc LT'\"\napply (unfold Listn.le_def lesub_def sup_loc_def)\napply (simp (no_asm_use) only: list_all2_conv_all_nth approx_loc_conv_all_nth)\napply (simp (no_asm_simp))\napply clarify\napply (erule allE, erule impE) \n apply simp\napply (erule approx_val_widen)\n apply simp\napply assumption\ndone\n\nlemma loc_widen_Err [dest]:\n  \"\\<And>XT. G \\<turnstile> replicate n Err <=l XT \\<Longrightarrow> XT = replicate n Err\"\n  by (induct n) auto\n  \nlemma approx_loc_Err [iff]:\n  \"approx_loc G hp (replicate n v) (replicate n Err)\"\n  by (induct n) auto\n\nlemma approx_loc_subst:\n  \"\\<lbrakk> approx_loc G hp loc LT; approx_val G hp x X \\<rbrakk>\n  \\<Longrightarrow> approx_loc G hp (loc[idx:=x]) (LT[idx:=X])\"\napply (unfold approx_loc_def list_all2_iff)\napply (auto dest: subsetD [OF set_update_subset_insert] simp add: zip_update)\ndone\n\nlemma approx_loc_append:\n  \"length l1=length L1 \\<Longrightarrow>\n  approx_loc G hp (l1@l2) (L1@L2) = \n  (approx_loc G hp l1 L1 \\<and> approx_loc G hp l2 L2)\"\n  apply (unfold approx_loc_def list_all2_iff)\n  apply (simp cong: conj_cong)\n  apply blast\n  done\n\nsubsection {* approx-stk *}\n\nlemma approx_stk_rev_lem:\n  \"approx_stk G hp (rev s) (rev t) = approx_stk G hp s t\"\n  apply (unfold approx_stk_def approx_loc_def)\n  apply (simp add: rev_map [THEN sym])\n  done\n\nlemma approx_stk_rev:\n  \"approx_stk G hp (rev s) t = approx_stk G hp s (rev t)\"\n  by (auto intro: subst [OF approx_stk_rev_lem])\n\nlemma approx_stk_sup_heap:\n  \"\\<lbrakk> approx_stk G hp stk ST; hp \\<le>| hp' \\<rbrakk> \\<Longrightarrow> approx_stk G hp' stk ST\"\n  by (auto intro: approx_loc_sup_heap simp add: approx_stk_def)\n\nlemma approx_stk_widen:\n  \"\\<lbrakk> approx_stk G hp stk ST; G \\<turnstile> map OK ST <=l map OK ST'; wf_prog wt G \\<rbrakk>\n  \\<Longrightarrow> approx_stk G hp stk ST'\" \n  by (auto elim: approx_loc_widen simp add: approx_stk_def)\n\nlemma approx_stk_Nil [iff]:\n  \"approx_stk G hp [] []\"\n  by (simp add: approx_stk_def)\n\nlemma approx_stk_Cons [iff]:\n  \"approx_stk G hp (x#stk) (S#ST) = \n  (approx_val G hp x (OK S) \\<and> approx_stk G hp stk ST)\"\n  by (simp add: approx_stk_def)\n\nlemma approx_stk_Cons_\n\nlemma approx_stk_append:\n  \"approx_stk G hp stk (S@S') \\<Longrightarrow>\n  (\\<exists>s stk'. stk = s@stk' \\<and> length s = length S \\<and> length stk' = length S' \\<and> \n            approx_stk G hp s S \\<and> approx_stk G hp stk' S')\"\n  by (simp add: list_all2_append2 approx_stk_def approx_loc_def)\n\nlemma approx_stk_all_widen:\n  \"\\<lbrakk> approx_stk G hp stk ST; \\<forall>(x, y) \\<in> set (zip ST ST'). G \\<turnstile> x \\<preceq> y; length ST = length ST'; wf_prog wt G \\<rbrakk> \n  \\<Longrightarrow> approx_stk G hp stk ST'\"\napply (unfold approx_stk_def)\napply (clarsimp simp add: approx_loc_conv_all_nth all_set_conv_all_nth)\napply (erule allE, erule impE, assumption)\napply (erule allE, erule impE, assumption)\napply (erule conf_widen, assumption+)\ndone\n\nsubsection {* oconf *}\n\nlemma oconf_field_update:\n  \"\\<lbrakk>map_of (fields (G, oT)) FD = Some T; G,hp\\<turnstile>v::\\<preceq>T; G,hp\\<turnstile>(oT,fs)\\<surd> \\<rbrakk>\n  \\<Longrightarrow> G,hp\\<turnstile>(oT, fs(FD\\<mapsto>v))\\<surd>\"\n  by (simp add: oconf_def lconf_def)\n\nlemma oconf_newref:\n  \"\\<lbrakk>hp oref = None; G,hp \\<turnstile> obj \\<surd>; G,hp \\<turnstile> obj' \\<surd>\\<rbrakk> \\<Longrightarrow> G,hp(oref\\<mapsto>obj') \\<turnstile> obj \\<surd>\"\n  apply (unfold oconf_def lconf_def)\n  apply simp\n  apply (blast intro: conf_hext hext_new)\n  done\n\nlemma oconf_heap_update:\n  \"\\<lbrakk> hp a = Some obj'; obj_ty obj' = obj_ty obj''; G,hp\\<turnstile>obj\\<surd> \\<rbrakk>\n  \\<Longrightarrow> G,hp(a\\<mapsto>obj'')\\<turnstile>obj\\<surd>\"\n  apply (unfold oconf_def lconf_def)\n  apply (fastforce intro: approx_val_heap_update)\n  done\n\nsubsection {* hconf *}\n\nlemma hconf_newref:\n  \"\\<lbrakk> hp oref = None; G\\<turnstile>h hp\\<surd>; G,hp\\<turnstile>obj\\<surd> \\<rbrakk> \\<Longrightarrow> G\\<turnstile>h hp(oref\\<mapsto>obj)\\<surd>\"\n  apply (simp add: hconf_def)\n  apply (fast intro: oconf_newref)\n  done\n\nlemma hconf_field_update:\n  \"\\<lbrakk> map_of (fields (G, oT)) X = Some T; hp a = Some(oT,fs); \n     G,hp\\<turnstile>v::\\<preceq>T; G\\<turnstile>h hp\\<surd> \\<rbrakk> \n  \\<Longrightarrow> G\\<turnstile>h hp(a \\<mapsto> (oT, fs(X\\<mapsto>v)))\\<surd>\"\n  apply (simp add: hconf_def)\n  apply (fastforce intro: oconf_heap_update oconf_field_update \n                  simp add: obj_ty_def)\n  done\n\nsubsection {* preallocated *}\n\nlemma preallocated_field_update:\n  \"\\<lbrakk> map_of (fields (G, oT)) X = Some T; hp a = Some(oT,fs); \n     G\\<turnstile>h hp\\<surd>; preallocated hp \\<rbrakk> \n  \\<Longrightarrow> preallocated (hp(a \\<mapsto> (oT, fs(X\\<mapsto>v))))\"\n  apply (unfold preallocated_def)\n  apply (rule allI)\n  apply (erule_tac x=x in allE)\n  apply simp\n  apply (rule ccontr)  \n  apply (unfold hconf_def)\n  apply (erule allE, erule allE, erule impE, assumption)\n  apply (unfold oconf_def lconf_def)\n  apply (simp del: split_paired_All)\n  done  \n\n\nlemma \n  assumes none: \"hp oref = None\" and alloc: \"preallocated hp\"\n  shows preallocated_newref: \"preallocated (hp(oref\\<mapsto>obj))\"\nproof (cases oref)\n  case (XcptRef x) \n  with none alloc have False by (auto elim: preallocatedE [of _ x])\n  thus ?thesis ..\nnext\n  case (Loc l)\n  with alloc show ?thesis by (simp add: preallocated_def)\nqed\n  \nsubsection {* correct-frames *}\n\nlemmas [simp del] = fun_upd_apply\n\nlemma correct_frames_field_update [rule_format]:\n  \"\\<forall>rT C sig. \n  correct_frames G hp phi rT sig frs \\<longrightarrow> \n  hp a = Some (C,fs) \\<longrightarrow> \n  map_of (fields (G, C)) fl = Some fd \\<longrightarrow> \n  G,hp\\<turnstile>v::\\<preceq>fd \n  \\<longrightarrow> correct_frames G (hp(a \\<mapsto> (C, fs(fl\\<mapsto>v)))) phi rT sig frs\"\napply (induct frs)\n apply simp\napply clarify\napply (simp (no_asm_use))\napply clarify\napply (unfold correct_frame_def)\napply (simp (no_asm_use))\napply clarify\napply (intro exI conjI)\n    apply assumption+\n   apply (erule approx_stk_sup_heap)\n   apply (erule hext_upd_obj)\n  apply (erule approx_loc_sup_heap)\n  apply (erule hext_upd_obj)\n apply assumption+\napply blast\ndone\n\nlemma correct_frames_newref [rule_format]:\n  \"\\<forall>rT C sig. \n  hp x = None \\<longrightarrow> \n  correct_frames G hp phi rT sig frs \\<longrightarrow>\n  correct_frames G (hp(x \\<mapsto> obj)) phi rT sig frs\"\napply (induct frs)\n apply simp\napply clarify\napply (simp (no_asm_use))\napply clarify\napply (unfold correct_frame_def)\napply (simp (no_asm_use))\napply clarify\napply (intro exI conjI)\n    apply assumption+\n   apply (erule approx_stk_sup_heap)\n   apply (erule hext_new)\n  apply (erule approx_loc_sup_heap)\n  apply (erule hext_new)\n apply assumption+\napply blast\ndone\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/MicroJava/BV/Correct.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.658417487156366, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.2857409855286218}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\nsection \"Words of Length 8\"\n\ntheory Word_8\nimports\n  More_Word\n  Enumeration_Word\n  Even_More_List\n  Signed_Words\n  Word_Lemmas\nbegin\n\ncontext\n  includes bit_operations_syntax\nbegin\n\nlemma len8: \"len_of (x :: 8 itself) = 8\" by simp\n\nlemma word8_and_max_simp:\n  \\<open>x AND 0xFF = x\\<close> for x :: \\<open>8 word\\<close>\n  using word_and_full_mask_simp [of x]\n  by (simp add: numeral_eq_Suc mask_Suc_exp)\n\nlemma enum_word8_eq:\n  \\<open>enum = [0 :: 8 word, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,\n                            20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,\n                            37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,\n                            54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,\n                            71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,\n                            88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,\n                            104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117,\n                            118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131,\n                            132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145,\n                            146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,\n                            160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173,\n                            174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187,\n                            188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201,\n                            202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215,\n                            216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229,\n                            230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243,\n                            244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255]\\<close> (is \\<open>?lhs = ?rhs\\<close>)\nproof -\n  have \\<open>map unat ?lhs = [0..<256]\\<close>\n    by (simp add: enum_word_def comp_def take_bit_nat_eq_self map_idem_upt_eq unsigned_of_nat)\n  also have \\<open>\\<dots> = map unat ?rhs\\<close>\n    by (simp add: upt_zero_numeral_unfold)\n  finally show ?thesis\n    using unat_inj by (rule map_injective)\nqed\n\nlemma set_enum_word8_def:\n  \"(set enum :: 8 word set) = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,\n                            20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,\n                            37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,\n                            54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,\n                            71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,\n                            88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,\n                            104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117,\n                            118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131,\n                            132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145,\n                            146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,\n                            160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173,\n                            174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187,\n                            188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201,\n                            202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215,\n                            216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229,\n                            230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243,\n                            244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255}\"\n  by (simp add: enum_word8_eq)\n\nlemma set_strip_insert: \"\\<lbrakk> x \\<in> insert a S; x \\<noteq> a \\<rbrakk> \\<Longrightarrow> x \\<in> S\"\n  by simp\n\nlemma word8_exhaust:\n  fixes x :: \\<open>8 word\\<close>\n  shows \"\\<lbrakk>x \\<noteq> 0; x \\<noteq> 1; x \\<noteq> 2; x \\<noteq> 3; x \\<noteq> 4; x \\<noteq> 5; x \\<noteq> 6; x \\<noteq> 7; x \\<noteq> 8; x \\<noteq> 9; x \\<noteq> 10; x \\<noteq> 11; x \\<noteq>\n          12; x \\<noteq> 13; x \\<noteq> 14; x \\<noteq> 15; x \\<noteq> 16; x \\<noteq> 17; x \\<noteq> 18; x \\<noteq> 19; x \\<noteq> 20; x \\<noteq> 21; x \\<noteq> 22; x \\<noteq>\n          23; x \\<noteq> 24; x \\<noteq> 25; x \\<noteq> 26; x \\<noteq> 27; x \\<noteq> 28; x \\<noteq> 29; x \\<noteq> 30; x \\<noteq> 31; x \\<noteq> 32; x \\<noteq> 33; x \\<noteq>\n          34; x \\<noteq> 35; x \\<noteq> 36; x \\<noteq> 37; x \\<noteq> 38; x \\<noteq> 39; x \\<noteq> 40; x \\<noteq> 41; x \\<noteq> 42; x \\<noteq> 43; x \\<noteq> 44; x \\<noteq>\n          45; x \\<noteq> 46; x \\<noteq> 47; x \\<noteq> 48; x \\<noteq> 49; x \\<noteq> 50; x \\<noteq> 51; x \\<noteq> 52; x \\<noteq> 53; x \\<noteq> 54; x \\<noteq> 55; x \\<noteq>\n          56; x \\<noteq> 57; x \\<noteq> 58; x \\<noteq> 59; x \\<noteq> 60; x \\<noteq> 61; x \\<noteq> 62; x \\<noteq> 63; x \\<noteq> 64; x \\<noteq> 65; x \\<noteq> 66; x \\<noteq>\n          67; x \\<noteq> 68; x \\<noteq> 69; x \\<noteq> 70; x \\<noteq> 71; x \\<noteq> 72; x \\<noteq> 73; x \\<noteq> 74; x \\<noteq> 75; x \\<noteq> 76; x \\<noteq> 77; x \\<noteq>\n          78; x \\<noteq> 79; x \\<noteq> 80; x \\<noteq> 81; x \\<noteq> 82; x \\<noteq> 83; x \\<noteq> 84; x \\<noteq> 85; x \\<noteq> 86; x \\<noteq> 87; x \\<noteq> 88; x \\<noteq>\n          89; x \\<noteq> 90; x \\<noteq> 91; x \\<noteq> 92; x \\<noteq> 93; x \\<noteq> 94; x \\<noteq> 95; x \\<noteq> 96; x \\<noteq> 97; x \\<noteq> 98; x \\<noteq> 99; x \\<noteq>\n          100; x \\<noteq> 101; x \\<noteq> 102; x \\<noteq> 103; x \\<noteq> 104; x \\<noteq> 105; x \\<noteq> 106; x \\<noteq> 107; x \\<noteq> 108; x \\<noteq> 109; x \\<noteq>\n          110; x \\<noteq> 111; x \\<noteq> 112; x \\<noteq> 113; x \\<noteq> 114; x \\<noteq> 115; x \\<noteq> 116; x \\<noteq> 117; x \\<noteq> 118; x \\<noteq> 119; x \\<noteq>\n          120; x \\<noteq> 121; x \\<noteq> 122; x \\<noteq> 123; x \\<noteq> 124; x \\<noteq> 125; x \\<noteq> 126; x \\<noteq> 127; x \\<noteq> 128; x \\<noteq> 129; x \\<noteq>\n          130; x \\<noteq> 131; x \\<noteq> 132; x \\<noteq> 133; x \\<noteq> 134; x \\<noteq> 135; x \\<noteq> 136; x \\<noteq> 137; x \\<noteq> 138; x \\<noteq> 139; x \\<noteq>\n          140; x \\<noteq> 141; x \\<noteq> 142; x \\<noteq> 143; x \\<noteq> 144; x \\<noteq> 145; x \\<noteq> 146; x \\<noteq> 147; x \\<noteq> 148; x \\<noteq> 149; x \\<noteq>\n          150; x \\<noteq> 151; x \\<noteq> 152; x \\<noteq> 153; x \\<noteq> 154; x \\<noteq> 155; x \\<noteq> 156; x \\<noteq> 157; x \\<noteq> 158; x \\<noteq> 159; x \\<noteq>\n          160; x \\<noteq> 161; x \\<noteq> 162; x \\<noteq> 163; x \\<noteq> 164; x \\<noteq> 165; x \\<noteq> 166; x \\<noteq> 167; x \\<noteq> 168; x \\<noteq> 169; x \\<noteq>\n          170; x \\<noteq> 171; x \\<noteq> 172; x \\<noteq> 173; x \\<noteq> 174; x \\<noteq> 175; x \\<noteq> 176; x \\<noteq> 177; x \\<noteq> 178; x \\<noteq> 179; x \\<noteq>\n          180; x \\<noteq> 181; x \\<noteq> 182; x \\<noteq> 183; x \\<noteq> 184; x \\<noteq> 185; x \\<noteq> 186; x \\<noteq> 187; x \\<noteq> 188; x \\<noteq> 189; x \\<noteq>\n          190; x \\<noteq> 191; x \\<noteq> 192; x \\<noteq> 193; x \\<noteq> 194; x \\<noteq> 195; x \\<noteq> 196; x \\<noteq> 197; x \\<noteq> 198; x \\<noteq> 199; x \\<noteq>\n          200; x \\<noteq> 201; x \\<noteq> 202; x \\<noteq> 203; x \\<noteq> 204; x \\<noteq> 205; x \\<noteq> 206; x \\<noteq> 207; x \\<noteq> 208; x \\<noteq> 209; x \\<noteq>\n          210; x \\<noteq> 211; x \\<noteq> 212; x \\<noteq> 213; x \\<noteq> 214; x \\<noteq> 215; x \\<noteq> 216; x \\<noteq> 217; x \\<noteq> 218; x \\<noteq> 219; x \\<noteq>\n          220; x \\<noteq> 221; x \\<noteq> 222; x \\<noteq> 223; x \\<noteq> 224; x \\<noteq> 225; x \\<noteq> 226; x \\<noteq> 227; x \\<noteq> 228; x \\<noteq> 229; x \\<noteq>\n          230; x \\<noteq> 231; x \\<noteq> 232; x \\<noteq> 233; x \\<noteq> 234; x \\<noteq> 235; x \\<noteq> 236; x \\<noteq> 237; x \\<noteq> 238; x \\<noteq> 239; x \\<noteq>\n          240; x \\<noteq> 241; x \\<noteq> 242; x \\<noteq> 243; x \\<noteq> 244; x \\<noteq> 245; x \\<noteq> 246; x \\<noteq> 247; x \\<noteq> 248; x \\<noteq> 249; x \\<noteq>\n          250; x \\<noteq> 251; x \\<noteq> 252; x \\<noteq> 253; x \\<noteq> 254; x \\<noteq> 255\\<rbrakk> \\<Longrightarrow> P\"\n  apply (subgoal_tac \"x \\<in> set enum\", subst (asm) set_enum_word8_def)\n    apply (drule set_strip_insert, assumption)+\n   apply (erule emptyE)\n  apply (subst enum_UNIV, rule UNIV_I)\n  done\n\nend\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/lib/Word_Lib/Word_8.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5583269943353745, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.2857051938559796}}
{"text": "theory Sepref_Additional\nimports Sepref_Basic Sepref_Rules\nbegin\n\nlemma hoare_alt: \n  \"<P> c <\\<lambda>r. Q r > = (\\<forall>h as n.\n        pHeap h as n \\<Turnstile> P \\<longrightarrow> (\\<exists>h' t r. execute c h = Some (r, h', t) \\<and>\n        (pHeap h' (new_addrs h as h') (n - t) \\<Turnstile> Q r \\<and>\n        t \\<le> n \\<and> relH {a. a < heap.lim h \\<and> a \\<notin> as} h h' \\<and> heap.lim h \\<le> heap.lim h')))\" (is \"?L = (\\<forall>h as n. ?H h as n \\<longrightarrow> (\\<exists>h' t r. _ \\<and> ?P h as h' n t r))\")\nproof -\n  have \"?L = (\\<forall>h as n. pHeap h as n \\<Turnstile> P \\<longrightarrow> \n                  (\\<forall> \\<sigma> t r. run c (Some h) \\<sigma> r t \\<longrightarrow> \\<sigma> \\<noteq> None \\<and> (?P h as (the \\<sigma>) n t r)))\"\n    unfolding hoare_triple_def by auto  \n  also have \"\\<dots> =  (\\<forall>h as n. pHeap h as n \\<Turnstile> P \\<longrightarrow>\n              (\\<exists>h' t r. execute c h = Some (r, h', t) \\<and>\n                         ?P h as h' n t r))\" apply(subst run_and_execute) by simp\n  finally show ?thesis .\nqed\n\nlemma extract_cost_otherway:\n  assumes \n    \"\\<Gamma> * timeCredit_assn Cost_lb \\<Longrightarrow>\\<^sub>A G * F\"\n    \"<G> c <\\<lambda>r. Q r >\"\n    \"\\<And>r. Q r * F \\<Longrightarrow>\\<^sub>A \\<Gamma>' * (\\<exists>\\<^sub>Ara. R ra r * \\<up>(ra \\<in> dom M)) * true\"\n    \"(\\<And>c. c\\<in>ran M \\<Longrightarrow> Cost_lb \\<le> c)\"\n  shows \"hn_refine \\<Gamma> c \\<Gamma>' R (REST M)\" \nproof - \n  note pre_rule[OF assms(1) frame_rule[OF assms(2)]]\n  then have TR: \"\\<And>h as n. pHeap h as n \\<Turnstile> \\<Gamma> * timeCredit_assn Cost_lb \\<Longrightarrow>\n           (\\<exists>h' t r. execute c h = Some (r, h', t) \\<and>\n                     pHeap h' (new_addrs h as h') (n - t) \\<Turnstile> Q r * F \\<and> t \\<le> n \\<and> relH {a. a < heap.lim h \\<and> a \\<notin> as} h h' \\<and> heap.lim h \\<le> heap.lim h')\" \n    unfolding hoare_alt by simp\n\n  show ?thesis\n    unfolding hn_refine_def apply auto\n  proof -\n    fix h as n\n    assume \"pHeap h as n \\<Turnstile> \\<Gamma>\"\n    then have \"pHeap h as (n+Cost_lb) \\<Turnstile> \\<Gamma> * timeCredit_assn Cost_lb\"  \n      by (simp add: mod_timeCredit_dest)\n    from TR[OF this] obtain h' t r where \"execute c h = Some (r, h', t)\"\n           and h: \"pHeap h' (new_addrs h as h') (n + Cost_lb - t) \\<Turnstile> Q r * F\" \n           and 3: \"t \\<le> n + Cost_lb\" \"relH {a. a < heap.lim h \\<and> a \\<notin> as} h h'\" \"heap.lim h \\<le> heap.lim h'\"\n      by blast\n\n    from h assms(3) have h': \"pHeap h' (new_addrs h as h') (n + Cost_lb - t) \\<Turnstile>   \\<Gamma>' * (\\<exists>\\<^sub>Ara. R ra r * \\<up> (ra \\<in> dom M)) * true\"\n      by (simp add: entails_def)\n    then have \"\\<exists>ra. pHeap h' (new_addrs h as h') (n + Cost_lb - t) \\<Turnstile>   \\<Gamma>' *  R ra r * \\<up> (ra \\<in> dom M) * true\"\n      by simp\n    then obtain ra where h'': \"pHeap h' (new_addrs h as h') (n + Cost_lb - t) \\<Turnstile>   \\<Gamma>' *  R ra r * \\<up> (ra \\<in> dom M) * true\"\n        by blast\n    have \"pHeap h' (new_addrs h as h') (n + Cost_lb - t) \\<Turnstile>   (\\<Gamma>' *  R ra r * true) * \\<up> (ra \\<in> dom M)\"\n      apply(rule entailsD[OF _ h''])  by (simp add: entails_triv move_back_pure') \n    then have h'': \"pHeap h' (new_addrs h as h') (n + Cost_lb - t) \\<Turnstile>   \\<Gamma>' *  R ra r * true\" and radom: \"ra \\<in> dom M\"\n      using mod_pure_star_dist  by auto   \n\n    show \"\\<exists>h' t r. execute c h = Some (r, h', t) \\<and>\n                       (\\<exists>ra Ca. Some (enat Ca) \\<le> M ra \\<and> t \\<le> n + Ca \\<and> pHeap h' (new_addrs h as h') (n + Ca - t) \\<Turnstile> \\<Gamma>' * R ra r * true) \\<and>\n                       relH {a. a < heap.lim h \\<and> a \\<notin> as} h h' \\<and> heap.lim h \\<le> heap.lim h'\"\n      apply(rule exI[where x=h']) apply(rule exI[where x=t]) apply(rule exI[where x=r])\n      apply safe apply fact\n          apply(rule exI[where x=ra])\n        apply(rule exI[where x=Cost_lb])\n        apply safe \n      subgoal using assms(4) radom using ranI by force\n      subgoal by fact\n      subgoal using h'' mod_star_trueI by blast \n       apply fact apply fact done\n  qed\nqed\n\n\nlemma extract_cost_otherway':\n  fixes R\n  assumes \n    \"\\<Gamma> * timeCredit_assn Cost_lb \\<Longrightarrow>\\<^sub>A G * F\"\n    \"\\<And>h. h\\<Turnstile>\\<Gamma> \\<Longrightarrow> <G> c <\\<lambda>r. Q r >\"\n    \"\\<And>r h. h\\<Turnstile>\\<Gamma> \\<Longrightarrow> Q r * F \\<Longrightarrow>\\<^sub>A \\<Gamma>' * (\\<exists>\\<^sub>Ara. R ra r * \\<up>(ra \\<in> dom M)) * true\"\n    \"(\\<And>c h. h\\<Turnstile>\\<Gamma> \\<Longrightarrow> c\\<in>ran M \\<Longrightarrow> Cost_lb \\<le> c)\"\n  shows \"hn_refine \\<Gamma> c \\<Gamma>' R (REST M)\" \n  apply(rule hn_refine_preI)\n  apply(rule extract_cost_otherway)\n  using assms by auto\n\n\nlemmas extr = extract_cost_otherway[where F=emp, simplified, OF ent_refl _ ent_refl]\n\nlemma extr': \"(\\<And>M. m = SPECT M \\<Longrightarrow> <\\<Gamma> * timeCredit_assn Cost_lb> c <\\<lambda>r. \\<exists>\\<^sub>Ara. \\<Gamma>' * (R ra r * \\<up> (ra \\<in> dom M)) * true>) \\<Longrightarrow>\n(\\<And>c M. m = SPECT M \\<Longrightarrow> c \\<in> ran M \\<Longrightarrow> enat Cost_lb \\<le> c) \\<Longrightarrow> hn_refine \\<Gamma> c \\<Gamma>' R m\"\n  apply(cases m)\n    subgoal by simp\n  subgoal premises prems for M\n    using extr[OF prems(1)[OF prems(3)] prems(2)[OF prems(3)]]  prems(3) by simp\n  done\n\nlemma hfrefb_to_hoare_triple:\n   assumes\n  \"(\\<And>M h c a t. P a \\<Longrightarrow> D a \\<le> t a \\<Longrightarrow>  h\\<Turnstile>fst RS a c \\<Longrightarrow> g t a = SPECT M\n       \\<Longrightarrow> <fst RS a c * timeCredit_assn (D a)> f c <\\<lambda>r. \\<exists>\\<^sub>Ara. snd RS a c * (T ra r * \\<up> (ra \\<in> dom M)) * true>)\"\n  \"(\\<And>co M h c a t. P a \\<Longrightarrow> D a \\<le> t a \\<Longrightarrow> h\\<Turnstile>fst RS a c \\<Longrightarrow> g t a = SPECT M \\<Longrightarrow> co \\<in> ran M\n       \\<Longrightarrow> enat (D a) \\<le> co)\"\nshows \"(f,g)\\<in>hfrefb P D RS T\"\n  apply(rule hfrefbI)\n  apply(rule hn_refine_preI)\n  subgoal for c a t h\n    apply(rule extr'[where Cost_lb=\"D a\"])\n     apply (rule assms(1)) apply simp_all\n    apply (rule assms(2)) apply simp_all\n    done\n  done\n\n\n\nsubsection \"how to extract a hoare triple from hn_refine\"\n\nlemma extract_cost_ub:\n  assumes \"hn_refine \\<Gamma> c \\<Gamma>' R (REST M)\" \"(\\<And>c. c\\<in>ran M \\<Longrightarrow> c \\<le> Cost_ub)\"\n  shows \"<\\<Gamma> * timeCredit_assn Cost_ub> c <\\<lambda>r. \\<Gamma>' * (\\<exists>\\<^sub>Ara. R ra r * \\<up>(ra \\<in> dom M)) >\\<^sub>t\"\n  using assms(1)  unfolding hn_refine_def\n  unfolding hoare_triple_def \n  apply clarify\nproof (goal_cases)\n  case (1 h as \\<sigma> r n t)\n  from 1(2) have 2: \"pHeap h as (n-Cost_ub) \\<Turnstile> \\<Gamma>\" and  nf: \"n\\<ge>Cost_ub\"\n    using mod_timeCredit_dest by auto\n\n  from 1(1) have 3: \"\\<And>h as n Ma.\n       pHeap h as n \\<Turnstile> \\<Gamma> \\<Longrightarrow> \n      SPECT M = SPECT Ma \\<Longrightarrow> (\\<exists>h' t r. execute c h = Some (r, h', t) \\<and>      \n       (\\<exists>ra Ca. Ma ra \\<ge> Some (enat Ca) \\<and> t \\<le> n + Ca \\<and> pHeap h' (new_addrs h as h') ((n + Ca) - t) \\<Turnstile> \\<Gamma>' * R ra r * true) \\<and>\n      relH {a. a < heap.lim h \\<and> a \\<notin> as} h h' \\<and> heap.lim h \\<le> heap.lim h')\" \n    by auto\n\n  thm effect_deterministic\n\n  from 3[OF 2 ] obtain h' t' r' where E: \"execute c h = Some (r', h', t') \" and\n    R:  \"(\\<exists>ra Ca. M ra \\<ge> Some (enat Ca) \\<and>\n                    pHeap h' (new_addrs h as h') (n - Cost_ub + Ca - t') \\<Turnstile> \\<Gamma>' * R ra r' * true \\<and> t' \\<le> n - Cost_ub + Ca) \\<and>\n           relH {a. a < heap.lim h \\<and> a \\<notin> as} h h' \\<and> heap.lim h \\<le> heap.lim h'\" by blast\n\n  have F: \"\\<sigma> = Some h'\" and prime: \"r' = r\" \"t' = t\"  \n    using E 1(3) run.cases apply force\n    using E 1(3) run.cases apply force\n    using E 1(3) run.cases by force \n  then have sig: \"the \\<sigma> = h'\" by auto\n  from R  have\n    B: \"(\\<exists>ra Ca. M ra \\<ge> Some (enat Ca) \\<and>\n     pHeap (the \\<sigma>) (new_addrs h as (the \\<sigma>)) (n - Cost_ub + Ca - t) \\<Turnstile> \\<Gamma>' * R ra r * true \\<and>\n        t \\<le> n - Cost_ub + Ca )\" and C:\n    \"relH {a. a < heap.lim h \\<and> a \\<notin> as} h (the \\<sigma>)\" \"heap.lim h \\<le> heap.lim (the \\<sigma>) \" \n    unfolding prime sig by auto\n\n\n\n  from B obtain ra Ca where i: \"pHeap (the \\<sigma>) (new_addrs h as (the \\<sigma>)) (n - Cost_ub + Ca - t) \\<Turnstile> \\<Gamma>' * R ra r * true\"\n    and ii:  \"t \\<le> n - Cost_ub + Ca\"  and ineq: \"M ra \\<ge> Some (enat Ca)\"\n    using B by auto\n\n  from ineq have radom: \"ra \\<in> dom M\" using domIff by fastforce  \n  then obtain Mra where Mra: \"M ra = Some Mra\" by blast\n  with assms(2) have \"Mra \\<le> enat Cost_ub\" by (meson ranI)\n  with Mra ineq have \"Some (enat Ca) \\<le> Some (enat Cost_ub)\" \n    using dual_order.trans by fastforce \n  then have ie: \"Ca \\<le> Cost_ub\" by auto\n\n  have pr: \"(n - Cost_ub + Ca - t) = (n - t) - (Cost_ub - Ca)\" using ie ii nf by auto\n  have pl: \"(n - (t + (Cost_ub - Ca)) + (Cost_ub - Ca)) = n-t\" using ii nf by auto\n\n  have \"pHeap (the \\<sigma>) (new_addrs h as (the \\<sigma>) \\<union> {}) ((n - t) - (Cost_ub - Ca) + (Cost_ub - Ca)) \\<Turnstile> \\<Gamma>' * R ra r * true * true\"\n    apply(rule mod_star_convI)  apply simp\n     apply(rule i[unfolded pr])  by (simp add: top_assn_rule)\n\n  then have H: \"pHeap (the \\<sigma>) (new_addrs h as (the \\<sigma>)) (n - t) \\<Turnstile> \\<Gamma>' * R ra r * true * true\"\n    by (simp add: pl)   \n\n  have \"pHeap (the \\<sigma>) (new_addrs h as (the \\<sigma>)) (n - t) \\<Turnstile> \\<Gamma>' * R ra r * \\<up> (ra \\<in> dom M) * true\"\n    apply(rule entailsD[OF _ H]) using radom by auto2  \n  then have \"\\<exists>ra. pHeap (the \\<sigma>) (new_addrs h as (the \\<sigma>)) (n - t) \\<Turnstile> \\<Gamma>' * R ra r * \\<up> (ra \\<in> dom M) * true\"\n    by blast\n  then have H': \"pHeap (the \\<sigma>) (new_addrs h as (the \\<sigma>)) (n - t) \\<Turnstile> (\\<exists>\\<^sub>Ara. \\<Gamma>' *  R ra r * \\<up> (ra \\<in> dom M) * true)\"\n    using mod_ex_dist by blast\n  have H: \"pHeap (the \\<sigma>) (new_addrs h as (the \\<sigma>)) (n - t) \\<Turnstile> \\<Gamma>' * (\\<exists>\\<^sub>Ara. R ra r * \\<up> (ra \\<in> dom M)) * true\" \n    apply(rule entailsD[OF _ H']) by auto2\n\n  from ii ie nf have T: \"t \\<le> n \" by auto\n\n  show ?case\n    apply safe\n    subgoal using F by auto\n    subgoal using H by simp  \n    subgoal by fact\n     apply fact apply fact done\nqed \n\n\n\nlemma r: \"ran (\\<lambda>v. if M v then Some (t v) else None) = {t v |v. M v}\"\n  by (auto simp: ran_is_image domIff split: if_splits)  \n\nlemma d: \"ra \\<in> dom (\\<lambda>v. if M v then Some (t v) else None) \\<longleftrightarrow> M ra\" \n  unfolding domIff by (auto)  \n \nlemma extract_cost_ub_SPEC: \"hn_refine \\<Gamma> c \\<Gamma>' R (SPEC M t) \\<Longrightarrow> (\\<And>c. M c \\<Longrightarrow> t c \\<le> enat Cost_ub) \\<Longrightarrow> <\\<Gamma> * timeCredit_assn Cost_ub> c <\\<lambda>r. \\<Gamma>' * (\\<exists>\\<^sub>Ara. R ra r * \\<up> (M ra))>\\<^sub>t\"\n  unfolding SPEC_def\n  apply(drule extract_cost_ub[where Cost_ub=Cost_ub])\n  by (auto simp: r d)\n\n\nlemma hnr_hoare_triple_SPEC_conv: \"hn_refine \\<Gamma> c \\<Gamma>' R (SPEC P (\\<lambda>_. t)) =  <\\<Gamma> * timeCredit_assn t> c <\\<lambda>r. \\<Gamma>' * (\\<exists>\\<^sub>Ara. R ra r * \\<up> (P ra))>\\<^sub>t\"\n  apply(rule)\n  subgoal apply(rule extract_cost_ub_SPEC) by auto \n  subgoal unfolding SPEC_def apply(rule extract_cost_otherway[where Cost_lb=\"t\" and F=\"emp\"])\n       defer apply assumption apply (auto split:  if_splits simp: domIff)[]\n    apply solve_entails\napply (auto split:  if_splits simp: domIff)[]\n    by(auto split: if_splits simp: ran_def)    \n  done\n\n\n\n\nlemma post_rulet:\n  \"<P> f <Q>\\<^sub>t \\<Longrightarrow> \\<forall>x. Q x \\<Longrightarrow>\\<^sub>A R x * true \\<Longrightarrow> <P> f <R>\\<^sub>t\"\n  apply(rule post_rule[where Q=\"\\<lambda>x. Q x * true\"])\n  apply auto apply(rule ent_true_drop(1)) by simp\n\n lemma ht_cons_rule:\n  assumes CPRE: \"P \\<Longrightarrow>\\<^sub>A P'\"\n  assumes CPOST: \"\\<And>x. Q x \\<Longrightarrow>\\<^sub>A Q' x\"\n  assumes R: \"<P'> c <Q>\"\n  shows \"<P> c <Q'>\" apply(rule cons_post_rule[OF _ CPOST])\n   by(rule pre_rule[OF CPRE R]) \n\n\nlemma extract_cost_ub':\n  assumes \"hn_refine \\<Gamma> c \\<Gamma>' R (REST M)\" \"(\\<And>c. c\\<in>ran M \\<Longrightarrow> c \\<le> Cost_ub)\"\n   and pre: \"P \\<Longrightarrow>\\<^sub>A \\<Gamma> * timeCredit_assn Cost_ub\"\n   and post: \"\\<forall>r. \\<Gamma>' * (\\<exists>\\<^sub>Ara. R ra r * \\<up>(ra \\<in> dom M)) \\<Longrightarrow>\\<^sub>A Q r * true\"\n shows \"<P> c <Q>\\<^sub>t\"\n  apply(rule pre_rule[OF pre])\n  apply(rule post_rulet[OF _ post]) \n  apply(rule extract_cost_ub) by fact+\n \n\nlemma hn_refineI: \n  shows \"tt = enat ttt ==> <\\<Gamma> * timeCredit_assn ttt> C <\\<lambda>r. \\<Gamma>' *  RR ra r>\\<^sub>t \\<Longrightarrow> hn_refine \\<Gamma> C \\<Gamma>'  RR (SPECT [ra \\<mapsto> tt])\"\n    apply(rule extract_cost_otherway[where F=emp and Cost_lb=ttt and G=\" \\<Gamma> * timeCredit_assn ttt\"]) \n     apply solve_entails apply simp  apply simp apply solve_entails by simp\nlemma RETURNT_SPECT_conv: \"RETURNT r = SPECT [r \\<mapsto> 0]\" unfolding RETURNT_def by auto\nlemma hn_refineI0: \n  shows \"<\\<Gamma>> C <\\<lambda>r. \\<Gamma>' *  RR ra r>\\<^sub>t \\<Longrightarrow> hn_refine \\<Gamma> C \\<Gamma>'  RR (RETURNT ra)\"\n  unfolding RETURNT_SPECT_conv\n    apply(rule extract_cost_otherway[where F=emp and Cost_lb=0 and G=\" \\<Gamma> * timeCredit_assn 0\"]) \n     apply solve_entails apply (simp add: zero_time)  apply simp apply solve_entails by (simp add: zero_enat_def)\n\n        \nend", "meta": {"author": "maxhaslbeck", "repo": "Sepreftime", "sha": "c1c987b45ec886d289ba215768182ac87b82f20d", "save_path": "github-repos/isabelle/maxhaslbeck-Sepreftime", "path": "github-repos/isabelle/maxhaslbeck-Sepreftime/Sepreftime-c1c987b45ec886d289ba215768182ac87b82f20d/Refine_Imperative_HOL/Sepref_Additional.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5583269943353745, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.2857051938559796}}
{"text": "section \\<open>Implementation of Heaps with Arrays\\<close>\ntheory IICF_Impl_Heap\nimports \n  IICF_Abs_Heap \n  \"../IICF_Array\" \n  \"../IICF_Array_List\" \nbegin\n\n  (* TODO: Move *)\n  \n  term al_assn\n\n  (* TODO: Move *)      \n  lemma size_mset_param[param]: \"(size,size)\\<in>\\<langle>A\\<rangle>mset_rel \\<rightarrow> nat_rel\"  \n    by (auto simp: mset_rel_def p2rel_def rel_mset_size)\n    \n\n  (* TODO: Move *)\n  lemma rdomp_ref_mk_assn_iff[simp]: \"rdomp \\<upharpoonleft>(mk_assn A) = rdomp A\"\n    by (auto simp: rdomp_def)\n  \n  thm vcg_prep_ext_rules  \n    \n  find_theorems pure_part  \n    \n  lemma rdomp_arl_assn_len:\n    assumes \"rdomp \\<upharpoonleft>(arl_assn:: ('a::llvm_rep list, 'l::len2 word \\<times> 'l word \\<times> 'a ptr) dr_assn) xs\"\n    shows \"length xs < max_snat LENGTH('l)\"\n    using assms\n    by (auto \n      simp: rdomp_def arl_assn_def arl_assn'_def sep_algebra_simps pred_lift_extract_simps\n      simp: snat.assn_def\n      )\n\n  find_theorems vassn_tag hn_refine\n\n      \n  (* TODO: Very specialized workaround lemma, to work around invalid-recombination\n    problem for case that B is pure \n  *)    \n  lemma workaround_invalid_recombine_pure2: \"is_pure B \\<Longrightarrow> hn_ctxt (invalid_assn A \\<times>\\<^sub>a B) ax px \\<turnstile> hn_invalid (A \\<times>\\<^sub>a B) ax px\"\n    unfolding hn_ctxt_def invalid_assn_def prod_assn_def entails_def\n    by (auto split: prod.split elim!: is_pureE \n      simp: sep_algebra_simps pure_part_pure_conj_eq)\n    argo\n    \n  (* TODO: Move\n    TODO: Should be generic algorithm!\n  *)  \n  lemma mop_list_swap_unfold: \"mop_list_swap xs i j = do {\n    xi \\<leftarrow> mop_list_get xs i;\n    xj \\<leftarrow> mop_list_get xs j;\n    xs \\<leftarrow> mop_list_set xs i xj;\n    mop_list_set xs j xi\n  }\"\n  by (auto simp: pw_eq_iff refine_pw_simps swap_def)\n  \n    \n\n\n  text \\<open>We implement the heap data structure by an array.\n    The implementation is automatically synthesized by the Sepref-tool.\n    \\<close>\n  subsection \\<open>Setup of the Sepref-Tool\\<close>\n\n  (* TODO: Move *)\n  lemma mset_rel_id: \"\\<langle>Id\\<rangle>mset_rel = Id\"\n    unfolding mset_rel_def apply (simp add: rel2p multiset.rel_eq)\n    by (simp only: p2rel)\n  \n  \n  locale heap_impl = heapstruct prio for prio :: \"'e \\<Rightarrow> 'p::linorder\" +\n    fixes prio_assn :: \"'p \\<Rightarrow> 'pi::llvm_rep \\<Rightarrow> assn\"\n      and elem_assn :: \"'e \\<Rightarrow> 'ei::llvm_rep \\<Rightarrow> assn\"\n      and prio_impl le_prio_impl lt_prio_impl\n      and ltype :: \"'l::len2 itself\"\n    assumes prio_is_pure[safe_constraint_rules]: \"is_pure prio_assn\"\n    assumes elem_is_pure[safe_constraint_rules]: \"is_pure elem_assn\"  \n    assumes prio_impl_refine[sepref_fr_rules]: \"(prio_impl, RETURN o prio)\\<in>elem_assn\\<^sup>k \\<rightarrow>\\<^sub>a prio_assn\"\n    assumes le_prio_impl_refine[sepref_fr_rules]: \n      \"(uncurry le_prio_impl, uncurry (RETURN oo (\\<le>))) \\<in> prio_assn\\<^sup>k *\\<^sub>a prio_assn\\<^sup>k \\<rightarrow>\\<^sub>a bool1_assn\"\n    assumes lt_prio_impl_refine[sepref_fr_rules]: \n      \"(uncurry lt_prio_impl, uncurry (RETURN oo (<))) \\<in> prio_assn\\<^sup>k *\\<^sub>a prio_assn\\<^sup>k \\<rightarrow>\\<^sub>a bool1_assn\"\n      \n    fixes N defines \"N\\<equiv>LENGTH('l)\"\n    (*assumes l_len[simp,arith]: \"4 < LENGTH('l)\"*)\n  begin\n      \n    abbreviation \"assn \\<equiv> al_assn' TYPE('l) elem_assn\"\n    abbreviation \"idx_assn \\<equiv> snat_assn' TYPE('l)\"\n    definition \"heap_assn \\<equiv> hr_comp (al_assn elem_assn) heap_rel1\"\n\n    lemma mk_free_heap_assn[sepref_frame_free_rules]: \"MK_FREE heap_assn arl_free\"\n      unfolding heap_assn_def\n      by (rule sepref_frame_free_rules)+\n  \n    (*context\n      assumes l_len_pre: \"(4 < LENGTH('l))\"\n    begin  \n      private lemma l_len: \"4 < LENGTH('l)\" using l_len_pre unfolding vcg_tag_defs by auto\n    *)  \n  \n      sepref_register prio\n  \n      sepref_register \"(\\<le>) :: 'p \\<Rightarrow> 'p \\<Rightarrow> bool\"\n      sepref_register \"(<) :: 'p \\<Rightarrow> 'p \\<Rightarrow> bool\"\n      \n      lemmas [sepref_frame_free_rules] = \n        mk_free_is_pure[OF prio_is_pure]\n        mk_free_is_pure[OF elem_is_pure]\n          \n      sepref_register update_op\n      sepref_definition update_impl is \"uncurry2 update_op\" \n        :: \"assn\\<^sup>d *\\<^sub>a idx_assn\\<^sup>k *\\<^sub>a elem_assn\\<^sup>k \\<rightarrow>\\<^sub>a assn\"\n        unfolding update_op_def[abs_def]\n        apply (annot_snat_const \"TYPE('l)\")\n        by sepref\n      lemmas [sepref_fr_rules] = update_impl.refine\n          \n      sepref_register val_of_op\n      sepref_definition val_of_impl is \"uncurry val_of_op\" :: \"assn\\<^sup>k *\\<^sub>a idx_assn\\<^sup>k \\<rightarrow>\\<^sub>a elem_assn\"\n        unfolding val_of_op_def[abs_def]\n        apply (annot_snat_const \"TYPE('l)\")\n        by sepref\n      lemmas [sepref_fr_rules] = val_of_impl.refine\n    \n      sepref_register exch_op\n      sepref_definition exch_impl is \"uncurry2 exch_op\" :: \"assn\\<^sup>d *\\<^sub>a idx_assn\\<^sup>k *\\<^sub>a idx_assn\\<^sup>k \\<rightarrow>\\<^sub>a assn\"\n        unfolding exch_op_def[abs_def] mop_list_swap_unfold\n        apply (annot_snat_const \"TYPE('l)\")\n        by sepref\n        \n      lemmas [sepref_fr_rules] = exch_impl.refine\n    \n      sepref_register valid\n      sepref_definition valid_impl is \"uncurry (RETURN oo valid)\" :: \"assn\\<^sup>k *\\<^sub>a idx_assn\\<^sup>k \\<rightarrow>\\<^sub>a bool1_assn\"\n        unfolding valid_def[abs_def]\n        apply (annot_snat_const \"TYPE('l)\")\n        by sepref\n      lemmas [sepref_fr_rules] = valid_impl.refine\n          \n      sepref_register prio_of_op  \n      sepref_definition prio_of_impl is \"uncurry (PR_CONST prio_of_op)\" :: \"assn\\<^sup>k *\\<^sub>a idx_assn\\<^sup>k \\<rightarrow>\\<^sub>a prio_assn\"\n        unfolding prio_of_op_def[abs_def] PR_CONST_def\n        by sepref\n      lemmas [sepref_fr_rules] = prio_of_impl.refine\n      \n      sepref_definition append_impl is \"uncurry mop_list_append\" \n        :: \"[\\<lambda>(xs,_). length xs + 1 < max_snat LENGTH('l)]\\<^sub>a assn\\<^sup>d *\\<^sub>a elem_assn\\<^sup>k \\<rightarrow> assn\"\n        by sepref\n      lemmas [sepref_fr_rules] = append_impl.refine \n      \n      sepref_register swim_op\n      sepref_definition swim_impl is \n        \"uncurry (PR_CONST swim_op)\" :: \"[\\<lambda>_. 4<LENGTH('l)]\\<^sub>a assn\\<^sup>d *\\<^sub>a idx_assn\\<^sup>k \\<rightarrow> assn\"\n        unfolding swim_op_def[abs_def] parent_def PR_CONST_def\n        apply (annot_snat_const \"TYPE('l)\")\n        (* TODO: Workaround/Hack *)\n        supply [sepref_frame_match_rules] = workaround_invalid_recombine_pure2[where B=snat_assn, simplified]\n        by sepref_dbg_keep\n  \n      lemmas [sepref_fr_rules] = swim_impl.refine\n  \n      \n      lemma overflow_safe_hbound_check: \"2*k\\<le>n \\<longleftrightarrow> k\\<le>n div 2\" for k n :: nat by auto\n      \n      (*lemma bound_aux1: \"rdomp assn xs \\<Longrightarrow> j\\<le>length xs div 2 \\<Longrightarrow> 2*j < max_snat LENGTH('l)\"  \n        apply sepref_bounds*)\n\n      (*          \n      lemma bound_aux2: \"\\<lbrakk>rdomp assn a1'; 2 * a2' < length a1'\\<rbrakk> \n        \\<Longrightarrow> Suc (2 * a2') < max_snat LENGTH('l)\"  \n        apply sepref_bounds\n        apply (drule al_assn_len_bound)\n        by auto\n      *)\n        \n      sepref_register sink_op\n      sepref_definition sink_impl is \"uncurry (PR_CONST sink_op)\" :: \"[\\<lambda>_. 4<LENGTH('l)]\\<^sub>a assn\\<^sup>d *\\<^sub>a idx_assn\\<^sup>k \\<rightarrow> assn\"\n        unfolding sink_op_opt_def[abs_def] sink_op_opt_eq[symmetric,abs_def]  PR_CONST_def\n        unfolding overflow_safe_hbound_check Suc_eq_plus1\n        (* TODO: Workaround/Hack *)\n        supply [sepref_frame_match_rules] = workaround_invalid_recombine_pure2[where B=snat_assn, simplified]\n        apply (annot_snat_const \"TYPE('l)\")\n        by sepref\n        \n      lemmas [sepref_fr_rules] = sink_impl.refine\n  \n      \n      lemma prenorm_heaprel1_len: \"(h,m)\\<in>heap_rel1 \\<Longrightarrow> length h = size m\"\n        unfolding heap_rel1_def in_br_conv\n        by auto\n      lemma max_snat_param: \"(max_snat,max_snat)\\<in>nat_rel \\<rightarrow> nat_rel\" by simp\n\n      context\n        notes [fcomp_norm_unfold] = heap_assn_def[symmetric] list_rel_id_simp mset_rel_id\n        notes [fcomp_prenorm_simps] = prenorm_heaprel1_len\n        notes [param] = IdI[of N] max_snat_param\n      begin    \n      \n        sepref_definition empty_impl is \"uncurry0 empty_op\" :: \"[\\<lambda>_. 4<N]\\<^sub>a unit_assn\\<^sup>k \\<rightarrow> assn\"\n          unfolding empty_op_def N_def\n          apply (rewrite al_fold_custom_empty[where 'l='l])\n          by sepref\n        sepref_decl_impl (no_register) heap_empty: empty_impl.refine[FCOMP empty_op_refine] \n          uses op_mset_empty.fref[of Id] .\n    \n        sepref_definition is_empty_impl is \"is_empty_op\" :: \"assn\\<^sup>k \\<rightarrow>\\<^sub>a bool1_assn\"\n          unfolding is_empty_op_def[abs_def]\n          apply (annot_snat_const \"TYPE('l)\")\n          by sepref\n        sepref_decl_impl heap_is_empty: is_empty_impl.refine[FCOMP is_empty_op_refine] \n          uses op_mset_is_empty.fref[of Id] .  \n    \n        sepref_definition insert_impl\n          is \"uncurry insert_op\" :: \"[\\<lambda>(_,xs). 4<N \\<and> length xs+1 < max_snat N]\\<^sub>a elem_assn\\<^sup>k *\\<^sub>a assn\\<^sup>d \\<rightarrow> assn\"\n          unfolding insert_op_def[abs_def] append_op_def N_def\n          by sepref\n        sepref_decl_impl heap_insert: insert_impl.refine[FCOMP insert_op_refine] \n          uses op_mset_insert.fref[of Id] .\n          \n        sepref_definition pop_min_impl is \"pop_min_op\" :: \"[\\<lambda>_. 4<N]\\<^sub>a assn\\<^sup>d \\<rightarrow> elem_assn \\<times>\\<^sub>a assn\"\n          unfolding pop_min_op_def[abs_def] butlast_op_def N_def\n          apply (annot_snat_const \"TYPE('l)\")\n          by sepref\n        sepref_decl_impl (no_mop) heap_pop_min: pop_min_impl.refine[FCOMP pop_min_op_refine] \n          uses op_prio_pop_min.fref[of Id] .\n        \n        \n    \n        sepref_definition peek_min_impl is \"peek_min_op\" :: \"assn\\<^sup>k \\<rightarrow>\\<^sub>a elem_assn\"\n          unfolding peek_min_op_def[abs_def]\n          apply (annot_snat_const \"TYPE('l)\")\n          by sepref\n        sepref_decl_impl (no_mop) heap_peek_min: peek_min_impl.refine[FCOMP peek_min_op_refine] \n          uses op_prio_peek_min.fref[of Id] .\n                  \n      end\n    (*end        *)\n\n  end  \n    \n\n  global_interpretation heap_impl id snat_assn snat_assn return ll_icmp_sle ll_icmp_slt \"TYPE('l::len2)\" \"LENGTH('l)\"\n    defines h_update_impl = update_impl\n        and h_val_of_impl = val_of_impl\n        and h_exch_impl = exch_impl\n        and h_valid_impl = valid_impl\n        and h_prio_of_impl = prio_of_impl\n        and h_append_impl = append_impl\n        and h_swim_impl = swim_impl\n        and h_sink_impl = sink_impl\n        and h_empty_impl = empty_impl\n        and h_is_empty_impl = is_empty_impl\n        and h_insert_impl = insert_impl\n        and h_pop_min_impl = pop_min_impl\n        and h_peek_min_impl = peek_min_impl\n  \n    apply unfold_locales\n    apply (rule pure_pure)\n    apply sepref\n    apply sepref\n    apply sepref\n    apply simp\n    done\n\n   \n  lemmas heap_impl_inlines = \n    heap_impl.valid_impl_def[OF heap_impl_axioms]  \n    heap_impl.prio_of_impl_def[OF heap_impl_axioms]\n    heap_impl.val_of_impl_def[OF heap_impl_axioms]\n    heap_impl.append_impl_def[OF heap_impl_axioms]\n    heap_impl.exch_impl_def[OF heap_impl_axioms]\n    heap_impl.empty_impl_def[OF heap_impl_axioms]\n    heap_impl.is_empty_impl_def[OF heap_impl_axioms]\n    heap_impl.insert_impl_def[OF heap_impl_axioms]\n    heap_impl.pop_min_impl_def[OF heap_impl_axioms]\n    heap_impl.peek_min_impl_def[OF heap_impl_axioms]\n    \n    h_swim_impl_def[symmetric]\n    h_sink_impl_def[symmetric]\n    \n  lemmas [llvm_inline] = update_impl_def \n  lemmas [llvm_inline] = val_of_impl_def \n  lemmas [llvm_inline] = exch_impl_def    \n  lemmas [llvm_inline] = h_valid_impl_def[unfolded heap_impl_inlines]\n  lemmas [llvm_inline] = h_prio_of_impl_def[unfolded heap_impl_inlines]\n  lemmas [llvm_inline] = h_append_impl_def[unfolded heap_impl_inlines]\n  lemmas [llvm_code] = h_swim_impl_def[unfolded heap_impl.swim_impl_def[OF heap_impl_axioms], unfolded heap_impl_inlines]\n  lemmas [llvm_code] = h_sink_impl_def[unfolded heap_impl.sink_impl_def[OF heap_impl_axioms], unfolded heap_impl_inlines]\n  lemmas [llvm_inline] = h_empty_impl_def[unfolded heap_impl_inlines]\n  lemmas [llvm_inline] = h_is_empty_impl_def[unfolded heap_impl_inlines]\n  lemmas [llvm_inline] = h_insert_impl_def[unfolded heap_impl_inlines]\n  lemmas [llvm_inline] = h_pop_min_impl_def[unfolded heap_impl_inlines]\n  lemmas [llvm_inline] = h_peek_min_impl_def[unfolded heap_impl_inlines]\n  \n  definition [simp]: \"op_heap_custom_empty (_::'a::len2 itself) (_::'l::len2 itself) \\<equiv> op_mset_empty\"\n  context fixes Q T :: \"_::len2 itself\" begin sepref_register \"op_heap_custom_empty Q T\" end\n  \n  lemma op_heap_custom_empty_hnr[sepref_fr_rules]:\n    shows \"(\n      uncurry0 (empty_impl::('a::len2 word,'l)array_list llM ), \n      uncurry0 (RETURN (PR_CONST (op_heap_custom_empty TYPE('a) TYPE('l))))) \\<in> [\\<lambda>_. 4<LENGTH('l::len2)]\\<^sub>a unit_assn\\<^sup>k \\<rightarrow> heap_assn\"\n    unfolding op_heap_custom_empty_def PR_CONST_def\n    by (rule heap_empty_hnr[unfolded PRECOND_def])\n    \n  lemma heap_fold_custom_empty: \n    \"{#} = op_heap_custom_empty TYPE('a::len2) TYPE('l::len2)\"\n    \"op_mset_empty = op_heap_custom_empty TYPE('a::len2) TYPE('l::len2)\"\n    \"mop_mset_empty = RETURN (op_heap_custom_empty TYPE('a::len2) TYPE('l::len2))\"\n    by auto\n  \n    \n      \n  \n    \ndefinition \"sort_by_prio l\\<^sub>0 \\<equiv> do {\n  q \\<leftarrow> nfoldli l\\<^sub>0 (\\<lambda>_. True) (\\<lambda>x q. do { ASSERT (size q < length l\\<^sub>0); mop_mset_insert x q }) {#};\n  ASSERT (q = mset l\\<^sub>0);\n  (l,q) \\<leftarrow> WHILEIT (\\<lambda>(l,q). sorted l \\<and> (\\<forall>x\\<in>set l. \\<forall>y\\<in>#q. x\\<le>y) \\<and> mset l + q = mset l\\<^sub>0) \n    (\\<lambda>(l,q). \\<not>op_mset_is_empty q) (\\<lambda>(l,q). \n  do {\n    (x,q) \\<leftarrow> mop_prio_pop_min id q;\n    ASSERT (size l < length l\\<^sub>0);\n    RETURN (l@[x],q)\n  }) (op_list_empty,q);\n  RETURN l\n}\"\n\nlemma sort_by_prio_correct: \"sort_by_prio l \\<le> SPEC (\\<lambda>l'. sorted l' \\<and> mset l' = mset l)\"\n  unfolding sort_by_prio_def mop_prio_pop_min_def\n  \n  apply (refine_vcg \n    nfoldli_rule[where I=\"\\<lambda>ll _ q. q = mset ll\"]\n    WHILEIT_rule[where R=\"measure (\\<lambda>(l,q). size q)\"]\n    )\n  apply (auto 0 3 dest: in_diffD simp: size_Diff1_less sorted_append_bigger)\n  subgoal by (metis add_cancel_right_right le_add1 nat_less_le size_eq_0_iff_empty size_mset size_union) \n  subgoal by (metis insert_DiffM union_iff) \n  done\n  \n\n\n(* TODO: Move  *)\nfunction list_intv_induction where\n  \"list_intv_induction l u = (if l<u then list_intv_induction (Suc l) u else ())\"\n  by pat_completeness auto\n\ntermination\n  apply (relation \"measure (\\<lambda>(l,u). u-l)\")\n  by auto\n  \n  \n(*  \nlemma nfoldli_range_to_while: \"nfoldli [l..<u] c f \\<sigma> = do {\n    (_,\\<sigma>) \\<leftarrow> WHILET \n      (\\<lambda>(i,\\<sigma>). i<u \\<and> c \\<sigma>) \n      (\\<lambda>(i,\\<sigma>). do { \\<sigma> \\<leftarrow> f i \\<sigma>; ASSERT (i<u); RETURN (i+1,\\<sigma>) })\n      (l,\\<sigma>);\n    RETURN \\<sigma>\n  }\"\nproof (induction l u arbitrary: \\<sigma> rule: list_intv_induction.induct)\n  case (1 l u)\n  show ?case proof (cases \"l<u\")\n    case False thus ?thesis\n      by (rewrite WHILET_unfold) simp\n      \n  next\n    case True \n    thm \"1.IH\"[OF True, abs_def]\n    thus ?thesis \n      by (rewrite WHILET_unfold) (simp add: upt_conv_Cons \"1.IH\"[OF True, abs_def])\n  qed\nqed\n*)  \n\n\n\nsepref_definition sort_impl [llvm_code] is \n  \"sort_by_prio\" :: \"[\\<lambda>l. length l < max_snat LENGTH(64)]\\<^sub>a (al_assn' TYPE(64) (snat_assn' TYPE(64)))\\<^sup>k \\<rightarrow> al_assn' TYPE(64) (snat_assn' TYPE(64))\"\n  unfolding sort_by_prio_def[abs_def] \n  apply (rewrite nfoldli_by_idx)\n  apply (rewrite nfoldli_upt_by_while)\n  apply (rewrite heap_fold_custom_empty[where 'l=64 and 'a=\"64\"])\n  apply (rewrite at op_list_empty al_fold_custom_empty[where 'l=64])\n  apply (annot_snat_const \"TYPE(64)\")\n  by sepref\n\n  \n  \nexport_llvm (no_header)\n  sort_impl is \"sort\" \n  \"arl_new_raw :: (64 word,64) array_list llM\" is \"arl_new\"\n  \"arl_push_back :: _ \\<Rightarrow> _ \\<Rightarrow> (64 word,64) array_list llM\" is \"arl_push_back\"\n  file \"sort.ll\"\n  (* CAREFUL: The calling conventions generated by this LLVM code are hard/impossible to \n    interface from C !? *)\n  \nend\n", "meta": {"author": "lammich", "repo": "isabelle_llvm", "sha": "6be37a9c3cae74a1134dbef2979e312abb5f7f42", "save_path": "github-repos/isabelle/lammich-isabelle_llvm", "path": "github-repos/isabelle/lammich-isabelle_llvm/isabelle_llvm-6be37a9c3cae74a1134dbef2979e312abb5f7f42/thys/sepref/IICF/Impl/Heaps/IICF_Impl_Heap.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5851011686727231, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.28569518523107806}}
{"text": "theory ringBufFifoModi imports paraGste1\nbegin\nabbreviation rst::\"expType\" where\n\"rst \\<equiv> IVar (Ident ''rst'')\"\n\nabbreviation push::\"expType\" where\n\"push \\<equiv> IVar (Ident ''push'')\"\n\nabbreviation pop::\"expType\" where\n\"pop \\<equiv> IVar (Ident ''pop'')\"\n\nabbreviation dataIn::\"expType\" where\n\"dataIn \\<equiv> IVar (Ident ''dataIn'' )\"\n\n\n\nabbreviation LOW::\"expType\" where\n\"LOW \\<equiv> Const (boolV False)\"\nabbreviation HIGH::\"expType\" where\n\" HIGH \\<equiv> Const (boolV True)\"\n\nabbreviation emptyFifo::\"expType\" where\n\" emptyFifo \\<equiv> IVar (Ident ''empty'' ) \"\n\nabbreviation tail::\"expType\" where\n\" tail \\<equiv> IVar (Ident ''tail'' ) \"\n\nabbreviation head::\"expType\" where\n\" head \\<equiv> IVar (Ident ''head'' ) \"\n\n\nabbreviation full::\"expType\" where\n\" full \\<equiv> IVar (Ident ''full'' ) \"\n\ndefinition fullForm::\"formula\" where [simp]:\n\" fullForm \\<equiv> eqn full HIGH \"\n\nabbreviation mem::\"varType\" where\n\"mem \\<equiv>  ( (Ident ''mem'') )\"\n\ntype_synonym paraExpType=\"nat \\<Rightarrow>expType\"\n\n \n\nabbreviation dataOut::\"nat\\<Rightarrow>expType\" where\n\"dataOut DEPTH \\<equiv> read (Ident ''mem'') DEPTH (IVar (Ident ''head'' ))\"\n\n\nabbreviation rstForm::\"formula\" where\n\"rstForm  \\<equiv>  (eqn rst HIGH)\"\n\nabbreviation emptyForm::\"formula\" where\n\"emptyForm  \\<equiv>  (eqn emptyFifo HIGH)\"\n \nabbreviation pushForm::\"formula\" where\n\"pushForm \\<equiv> andForm (andForm (eqn rst LOW) (eqn push HIGH)) (eqn pop LOW)\"\n\nabbreviation popForm::\"formula\" where\n\"popForm \\<equiv> andForm (andForm (eqn rst LOW) (eqn push LOW)) (eqn pop HIGH)\"\n\nabbreviation nPushPopForm::\"formula\" where\n\"nPushPopForm \\<equiv> andForm (andForm (eqn rst LOW) (eqn push LOW)) (eqn pop LOW)\"\n\nabbreviation pushDataForm::\"nat \\<Rightarrow>formula\" where\n\" pushDataForm D \\<equiv>andForm pushForm  (eqn dataIn (Const (index D)))\"\n\nabbreviation popDataForm::\"nat\\<Rightarrow>nat \\<Rightarrow>formula\" where\n\" popDataForm DEPTH D \\<equiv>  (eqn (dataOut DEPTH) (Const (index D)))\"\n \nabbreviation nFullForm::\"formula\" where\n\"nFullForm \\<equiv>  neg (fullForm )\"\n\nabbreviation nEmptyForm::\"formula\" where\n\"nEmptyForm \\<equiv> neg emptyForm \"\n\n\n\ndefinition  vertexI::\"node\" where [simp]:\n\"vertexI \\<equiv>Vertex  0\"\n\n(*DEPTH=LAST + 1*)\ndefinition  vertexL::\"nat \\<Rightarrow> node list\" where [simp]:\n\"vertexL LAST  \\<equiv>  vertexI # (map (%i. Vertex  i) (down LAST))\"\n\ndefinition edgeL::\"nat \\<Rightarrow> edge list\" where [simp]:\n \"edgeL LAST \\<equiv> [Edge vertexI ( Vertex 1)]\n    @ [Edge  ( Vertex 1) ( Vertex 3)]\t\t\n    @ [Edge  ( Vertex 1) ( Vertex 4)]\t\n    \n\t\t@(map (%i.  ( Edge (Vertex ( 2*i+1 ))  (Vertex (  2*i+1 ))) ) (upt 0  (LAST+2) ))  (* self-loop*)  \n\t  @(map (%i.  ( Edge (Vertex ( 2*i+2 ))  (Vertex (  2*i+2 ))) ) (upt 1 (LAST+2) ))  (* self-loop*)   \n\t  \n\t\t@(map (%i.   ( Edge (Vertex (2 * i + 1))  (Vertex (2 * i + 3))) ) ( upt 1 (LAST+1)))\n\t\t@(map (%i.   ( Edge (Vertex (2 * i + 1))  (Vertex (2 * i + 4))) ) ( upt 1 (LAST+1)))\n\t\t\n\t\t@(map (%i.   ( Edge (Vertex (2 * i + 3))  (Vertex (2 * i + 1))) ) (  upt 0 (LAST+1) )) \n\t\t@(map (%i.   ( Edge (Vertex (2 * i + 4))  (Vertex (2 * i +2 ))) ) (  upt 1 (LAST+1) ))\n\t\t@[ Edge (Vertex 4) (Vertex 1)]\n\t \"\n\n\n(*\nedgeL LAST \\<equiv> [Edge vertexI ( Vertex 1)]\n    @ [Edge  ( Vertex 1) ( Vertex 3)]\t\t\n    @ [Edge  ( Vertex 1) ( Vertex 4)]\t\n    \n\t\t@(map (%i.  ( Edge (Vertex ( 2*i+1 ))  (Vertex (  2*i+1 ))) ) (upt 0  (LAST+2) ))  (* self-loop*)  \n\t  @(map (%i.  ( Edge (Vertex ( 2*i+2 ))  (Vertex (  2*i+2 ))) ) (upt 1  (LAST+2) ))  (* self-loop*)   \n\t  \n\t\t@(map (%i.   ( Edge (Vertex (2 * i + 1))  (Vertex (2 * i + 3))) ) ( upt 1 (LAST+1)))\n\t\t@(map (%i.   ( Edge (Vertex (2 * i + 1))  (Vertex (2 * i + 4))) ) ( upt 1 (LAST+1)))\n\t\t\n\t\t@(map (%i.   ( Edge (Vertex (2 * i + 3))  (Vertex (2 * i + 1))) ) (  upt 0 (LAST+1) )) \n\t\t@(map (%i.   ( Edge (Vertex (2 * i + 4))  (Vertex (2 * i + 2))) ) (  upt 1 (LAST+1) ))\n\t\t@[Edge  ( Vertex 4) ( Vertex 1)]\n;*)\nprimrec node2Nat::\"node \\<Rightarrow> nat\" where\n\"node2Nat (Vertex n) = n\"\n\n\ndefinition antOfRbFifo::\"nat\\<Rightarrow>edge\\<Rightarrow>formula\" where [simp]:\n\"antOfRbFifo  D  edge\\<equiv>\n  (let from=node2Nat (source edge) in\n   let to=node2Nat (sink edge) in\n  ( if (\tfrom = 0) then rstForm\telse\n     if (from=to) then nPushPopForm else\n   ( if ((from mod 2) =1) then\n     (\n       if ((from + 2)=to) then ( pushForm ) else\n       if (from=(to + 2)) then popForm else\n       pushDataForm D )   else \n     popForm)))\"\n\n\n(*definition antOfRbFifo::\"nat\\<Rightarrow>edge\\<Rightarrow>formula\" where [simp]:\n\"antOfRbFifo  D  edge\\<equiv>\n  (let from=node2Nat (source edge) in\n   let to=node2Nat (sink edge) in\n   if (from = 0) then rstForm\telse\n   if (from=to) then nPushPopForm else\n      (if ((from mod 2) =1) then\n        (\n          if ((from + 2)=to) then ( pushForm ) else\n          if (from=(to + 2)) then popForm else\n          pushDataForm D )   \n       else popForm))\"\n\n\n\ndefinition consOfRbFifo::\"nat\\<Rightarrow>nat\\<Rightarrow>edge \\<Rightarrow>formula\" where  [simp]:\n\"consOfRbFifo   D LAST edge \\<equiv>\n(let from=node2Nat (source edge) in\n let to=node2Nat (sink edge) in\n if \t(((from mod 2) = 1) \\<and> ((to mod 2) = 1)) then\n    (if  from =1 then (andForm  emptyForm (nFullForm LAST))\n     else if    (from = (2*LAST+3)) then (andForm nEmptyForm (fullForm LAST)) \n     else andForm nEmptyForm (nFullForm LAST))\n else if (from=4 \\<and> to = 1) then popDataForm LAST D\n else if (from = (2*LAST+4)) then (andForm nEmptyForm (fullForm LAST)) \n else if (from =1 )  then (andForm emptyForm (nFullForm LAST))\n else if (from \\<noteq>0)   then (andForm nEmptyForm (nFullForm LAST))\n else chaos)\"\n\nlet cons aEdge = \n\tval (Edge (Vertex from) (Vertex to)) = aEdge\nin\n\t((from%2) = 1) AND ((to%2) = 1) => \t\t\t\t\n\t\t(from = 1) => TAndList [empty,nFull]\t\t//FIFO is empty\n\t|\t(from = (2*DEPTH+1)) => TAndList [nEmpty,full]\t//FIFO is full\n\t|\tTAndList [nEmpty,nFull]\t\t\t\t\t//FIFO of other size\n|\t(to = 2) => popData vOfDataIn\t\t\t\t\t//read the write data\n| \tTAndList []\n;*)\n\ndefinition consOfRbFifo::\"nat\\<Rightarrow>nat\\<Rightarrow>edge \\<Rightarrow>formula\" where  [simp]:\n\"consOfRbFifo   D LAST edge \\<equiv>\nlet from=node2Nat (source edge) in\nlet to=node2Nat (sink edge) in\n (if \t(((from mod 2) = 1) \\<and> ((to mod 2) = 1)) then\n  (if  from =1 then (andForm  emptyForm (nFullForm))\n  else if    (from = (2*LAST+3)) then (andForm nEmptyForm (fullForm )) \n  else andForm nEmptyForm (nFullForm ))\n else if (from=4 \\<and> to = 1) then popDataForm LAST D\n else if (from = (2*LAST+4)) then (andForm nEmptyForm (fullForm)) \n else if (from =1 )  then (andForm emptyForm (nFullForm ))\n else if (from \\<noteq>0)   then (andForm nEmptyForm (nFullForm))\n else chaos)\"\n\ndefinition rbFifoGsteSpec::\" nat\\<Rightarrow>nat\\<Rightarrow>gsteSpec\" where  [simp]:\n\"rbFifoGsteSpec LAST  data\\<equiv>Graph  vertexI (edgeL  LAST ) (antOfRbFifo data )  (consOfRbFifo data  LAST)\"\n\nprimrec applyPlusN::\"expType\\<Rightarrow>nat \\<Rightarrow>expType\" where\n\"applyPlusN e 0=e\" |\n\"applyPlusN e (Suc N) = uif ''+'' [applyPlusN e N, Const (index 1)]\"\n\ndefinition tagFunOfRingBufFifo:: \" nat\\<Rightarrow>nat\\<Rightarrow>nodeTagFuncList\" where [simp]:\n\"tagFunOfRingBufFifo DATA LAST  n \\<equiv> \n  let x=node2Nat n in\n   let DataE=(Const (index DATA)) in\n   let LASTE=(Const (index LAST)) in\n   let TwiceLASTPlus3=(Const (index (2*LAST +3))) in\n   let tailPlus=uif ''+'' [tail, (Const (index 1))] in\n   let headPlus=uif ''+'' [head, (Const (index 1))] in\n   if (x = 0) then [] else\n    (if ((x mod 2) = 1) then \n      (if (x =1) then \n        [eqn tail head, eqn  emptyFifo HIGH,\n        eqn full LOW,uip ''le'' [head,LASTE]]\n       else \n       (if (x=2*LAST+3) then \n        [eqn tail (applyPlusN head (x div 2  )), \n        eqn  emptyFifo LOW,\n        (*eqn emptyFifo (iteForm (eqn tail  headPlus)  HIGH emptyFifo),\n        eqn full (iteForm (eqn tailPlus  head)  HIGH full),*)\n        eqn full  HIGH,\n        uip ''le'' [head,LASTE]\n        ] \n        else \n         [eqn tail (applyPlusN head (x div 2  )), \n         eqn  emptyFifo LOW,\n         eqn full LOW,uip ''le'' [head,LASTE]]\n         (* eqn emptyFifo (iteForm (eqn tail  headPlus)  HIGH emptyFifo),\n          eqn full (iteForm (eqn tailPlus  head)  HIGH full),*)\n        (* uip ''le'' [head,LASTE]]*) ) )\n    else \n    ((*if (x = 2) then [] \n     else *)\n        (if (x=2*LAST+4) then \n        [eqn tail (applyPlusN head (x div 2 - 1 ) ), \n        eqn emptyFifo LOW, \n        eqn full HIGH,uip ''le'' [head,LASTE],\n        eqn (read mem LAST (applyPlusN head (x div 2  - 2))) DataE ] \n        else \n         [eqn tail (applyPlusN head (x div 2  - 1)), eqn  emptyFifo LOW,\n         eqn full LOW, uip ''le'' [head,LASTE],\n         \n          eqn (read mem LAST (applyPlusN head (x div 2  - 2))) DataE ]))\n     )\n   \n \"\n \n abbreviation branch1::\"generalizeStatement\" where \n\"branch1 \\<equiv> \n  (let S1=assign (Ident ''head'',(Const (index 0))) in\n   let S2=assign (Ident ''tail'',(Const (index 0))) in\n   let S3=assign (Ident ''empty'',HIGH) in\n   let S4=assign (Ident ''full'',LOW) in \n   Parallel [S1,S2,S3,S4])\"\n   \nabbreviation branch2::\"nat\\<Rightarrow>generalizeStatement\" where \n\"branch2 LAST \\<equiv> \n  (let S1=map (\\<lambda>i. assign ((Para (Ident ''mem'') i), \n    iteForm (eqn tail (Const (index i)))  dataIn \n    (IVar (Para (Ident ''mem'')  i)))) (down LAST ) in\n   let tailPlus=uif ''+'' [tail, (Const (index 1))] in\n   let S2=assign (Ident ''tail'', tailPlus ) in\n   let S3=assign (Ident ''empty'',LOW) in\n   let S4=assign (Ident ''full'',iteForm (eqn tailPlus  head)  HIGH full) in\n   (* Parallel (S1@[S2,S3]))*)\n   Parallel ([S2,S3,S4]@S1))\"   \n   \nabbreviation branch3::\"generalizeStatement\" where \n\"branch3 \\<equiv> \n  (let headPlus=uif ''+'' [head, (Const (index 1))] in\n    Parallel [\n    assign (Ident ''empty'',iteForm (eqn tail  headPlus)  HIGH emptyFifo),\n    assign (Ident ''full'', LOW),\n    assign (Ident ''head'',  headPlus)] )\n    \" \n\n \nabbreviation ringBuffifo::\" nat\\<Rightarrow>generalizeStatement\" where\n\"ringBuffifo  LAST\\<equiv> \n  caseStatement \n     [(eqn rst HIGH, branch1),\n      (andForm (eqn push HIGH) (nFullForm), branch2 LAST),\n      (andForm (eqn pop HIGH) (eqn emptyFifo LOW), branch3)] \n   \"\n   \n\nconsts J::\"nat \\<Rightarrow> interpretFunType\"  \n  \naxiomatization where axiomOnIAdd [simp,intro]:\n\"  J LAST ''+'' [index m,   index (Suc 0)] = index ((m + 1) mod (Suc LAST  ))\"\n(* (if m=LAST  then (index 0) else (index (m +1 )))\"\nindex ((m + 1) mod (Suc LAST  )) \" *)\n\naxiomatization where axiomOnLe [simp,intro]:  \n\"  J LAST  ''le'' [index m, index n]  = boolV (m \\<le> n)\" \n\naxiomatization where headIsIndex[simp,intro]:\"\\<exists>i. ((s (Ident ''head'') ) = (index i)) \"\n\n\n\nlemma test0: \"formEval (J LAST) (eqn (Var tail) (applyPlusN head i) ) s  \\<longrightarrow>\nformEval (J LAST) (eqn (uif ''+''  [Var tail, Const (index 1)]) (applyPlusN head (i+1)) ) s\"\napply(auto) done\n\nlemma auxOnReadWrite[simp]:\n\"expEval I e s=expEval I e' s \\<and>expEval I e s=index i\\<and> i\\<le> LAST \\<longrightarrow>(\\<forall>j. Para mem j \\<notin>set (varOfExp e'))\\<longrightarrow> \n\n        expEval I  (substExp (caseExp (map (\\<lambda>i. (eqn e' (Const (index i)), IVar (Para mem i))) (down LAST)))\n            (map (\\<lambda>i. (Para mem i, iteForm (eqn e (Const (index i))) e'' (IVar (Para mem i))))\n              (down LAST)))\n          s = expEval I e'' s \"   (is \"?P LAST\")\nproof(induct_tac LAST) \n  show \"?P 0\"\n  proof(rule impI)+\n  assume a1:\" expEval I e s = expEval I e' s \\<and> expEval I e s = index i \\<and> i \\<le> 0\" and \n   a2:\" \\<forall>j. Para mem j \\<notin> set (varOfExp e')\"\n   have a3:\"(Para mem 0) \\<notin> set (varOfExp e')\"\n    by(cut_tac a2,auto)\n  show \" expEval I\n     (substExp (caseExp (map (\\<lambda>i. (eqn e' (Const (index i)), IVar (Para mem i))) (down 0)))\n       (map (\\<lambda>i. (Para mem i, iteForm (eqn e (Const (index i))) e'' (IVar (Para mem i)))) (down 0)))\n     s =\n    expEval I e'' s\"\n   using a1 a3 noEffectSubstExp proof(cut_tac a1,auto)qed\n   qed\n  next\n  fix n\n  assume a0:  \"?P n\"\n  show \"?P (Suc n)\"\n  proof(rule impI)+\n  assume a1:\" expEval I e s = expEval I e' s \\<and> expEval I e s = index i \\<and> i \\<le> Suc n\" and \n   a2:\" \\<forall>j. Para mem j \\<notin> set (varOfExp e')\"\n   have a3:\"(Para mem  (Suc n)) \\<notin> set (varOfExp e')\"\n    by(cut_tac a2,auto) \n   show \"expEval I\n     (substExp (caseExp (map (\\<lambda>i. (eqn e' (Const (index i)), IVar (Para mem i))) (down (Suc n))))\n       (map (\\<lambda>i. (Para mem i, iteForm (eqn e (Const (index i))) e'' (IVar (Para mem i)))) (down (Suc n))))\n     s =\n    expEval I e'' s\" (is \"?LHS (Suc n) =?RHS\")\n   proof(case_tac \"i \\<le> n\")\n     assume b1:\"i \\<le> n\"\n     have b2:\" (Para mem (Suc n)) \\<notin> set (varOfExp\n     (caseExp (map (\\<lambda>i. (eqn e' (Const (index i)), IVar (Para mem i))) (down n))))\" \n      apply(auto)\n      apply (simp add: SucnIsNotInDownn)\n      by (simp add: a3)\n      \n     have b3:\"?LHS (Suc n) =?LHS n\" \n     using a1 a2 a3 b1 b2 by auto\n     have b4:\"?LHS n =   expEval I e'' s\"\n     using a1 b1 a2 a0 apply auto  done\n     show \"?LHS (Suc n) =?RHS\"\n     using b4 b3 by auto\n   next\n    assume b1:\"\\<not>i \\<le> n\"\n    have b2:\"i=Suc n\" \n    using b1 a1 by auto\n    show \"?LHS (Suc n) =?RHS\"\n     using b1 b2 a1 a2 a3  apply auto done\n  qed\nqed  \nqed\n\nlemma caseExpCong:\n  assumes a:\"tautlogy (eqn e e') I\"\n  shows \"expEval I   (caseExp (map (\\<lambda>i. (eqn e (Const (index i)), IVar (Para mem i))) (down LAST))) s\n  =expEval I  (caseExp (map (\\<lambda>i. (eqn e' (Const (index i)), IVar (Para mem i))) (down LAST))) s\"\nproof(induct_tac LAST,(cut_tac a,simp)+)qed\n\nlemma caseExpCong1:\n  assumes a:\"formEval I (eqn e e') s \"\n  shows \"expEval I   (caseExp (map (\\<lambda>i. (eqn e (Const (index i)), IVar (Para mem i))) (down LAST))) s\n  =expEval I  (caseExp (map (\\<lambda>i. (eqn e' (Const (index i)), IVar (Para mem i))) (down LAST))) s\"\nproof(induct_tac LAST,(cut_tac a,simp)+)qed\n\nlemma readWrite[simp,intro!]:\nassumes a1:\"expEval I e s=expEval I e' s \" and a2:\"expEval I e s=index i\" and a3:\" i\\<le> LAST \" and\na2:\"(\\<forall>j. Para mem j \\<notin>set (varOfExp e'))\" \n\nshows \" expEval I  (substExp (caseExp (map (\\<lambda>i. (eqn e' (Const (index i)), IVar (Para mem i))) (down LAST)))\n            (map (\\<lambda>i. (Para mem i, iteForm (eqn e (Const (index i))) e'' (IVar (Para mem i))))\n              (down LAST)))\n          s = expEval I e'' s \"\nusing a2 a3 assms(2) auxOnReadWrite local.a1 by blast\n\n\n\nlemma varOfApplyPlus[simp]:\n  \"varOfExp (applyPlusN head i) = [(Ident ''head'' )]\"\n  apply(induct_tac i,auto) done\n  \nlemma onApplyPlusI[simp]:\"i \\<le> LAST \\<longrightarrow> \n  j \\<le> LAST \\<longrightarrow> s (Ident ''head'') = index j \\<longrightarrow> \n  expEval (J LAST) (applyPlusN head i) s = index ((j + i) mod (Suc LAST))  \"\n  proof(induct_tac i,auto,arith) qed\n  \nlemma onApplyPlusII[simp]:\"0<i\\<longrightarrow>i\\<le> LAST \\<longrightarrow> \n  j \\<le> LAST \\<longrightarrow> s (Ident ''head'') = index j \\<longrightarrow>  \nexpEval (J LAST) (applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) (i - Suc 0)) s = index ((j + i) mod (Suc LAST))\" (is \"?P i\")\n  proof(induct_tac i,simp,case_tac \"n=0\",simp) \n    fix n\n    assume a:\"?P n\" and b:\"~n=0\"\n    show \"?P (Suc n)\"\n    proof(rule impI)+\n      assume c1:\"0< Suc n\" and c2:\"Suc n \\<le> LAST\" and c3:\"j \\<le> LAST\" and c4:\"s (Ident ''head'') = index j\"\n      show \"\n      expEval (J LAST) (applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) (Suc n - Suc 0)) s = index ((j + Suc n) mod Suc LAST)\"\n      (is \"?LHS =?RHS\")\n      proof -\n      have d1:\"0<n\" by(cut_tac b,simp)\n      have d2:\"n <LAST\" by(cut_tac c2,simp)\n      have d3:\"(applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) (Suc n - Suc 0)) = \n      uif ''+'' [(applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) (n -Suc 0)), Const (index (Suc 0))]\"\n      by (metis One_nat_def Suc_pred applyPlusN.simps(2) d1 diff_Suc_1)\n      have d4:\"expEval (J LAST) (applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) (n - Suc 0)) s=index ((j + n) mod (Suc LAST))\"\n        apply(cut_tac a d1 d2 d3 c3 c4,simp) done\n\n      show \"?LHS=?RHS\"\n      apply(cut_tac d3 d4,simp)\n      using mod_Suc_eq_Suc_mod by auto\n    qed  \n   qed\nqed\n\n\n  \n \nlemma test1[simp]: \" (expEval (J LAST) (applyPlusN head (Suc i)) s) = J LAST ''+'' [expEval (J LAST) (applyPlusN head i) s, index (Suc 0)]\"  \n  apply simp done\n\n \n\nlemma test2[simp]:\"Suc j \\<le> LAST \\<longrightarrow> (Suc j + (Suc LAST)) mod (Suc LAST) =Suc ((j + (Suc LAST)) mod (Suc LAST))\" (is \"?P j\")\nby (metis Divides.mod_less le_less_trans lessI less_trans mod_add_self2)\n  \nlemma test3:\"j \\<le> LAST \\<longrightarrow> (j + (Suc LAST)) mod (Suc LAST) =j\" (is \"?P j\")\nby (metis Divides.mod_less le_imp_less_Suc mod_add_self2)\n\n\nlemma test4[simp]:\"0<LAST \\<longrightarrow>i < Suc LAST \\<longrightarrow> 0 < i \\<longrightarrow>\n  j \\<le> LAST \\<longrightarrow> ((j + i) mod (Suc LAST)) =\n  (if (j+i)< (Suc LAST) then j+i else (j+i -(Suc LAST)))\"  (is \"?P LAST\")\nusing le_mod_geq by force  \n\nlemma test5Aux[simp]:\"0<LAST \\<longrightarrow>i < Suc LAST \\<longrightarrow> 0 < i \\<longrightarrow>\n  j \\<le> LAST \\<longrightarrow> ((j + i) mod (Suc LAST)) \\<noteq> j\"\nusing nat_neq_iff not_less by auto \n\nlemma test5:\n  assumes a1:\" 0 < LAST \" and a2:\" i < Suc LAST\" and a3:\" 0 < i \" and \n  a4:\"j \\<le> LAST\"\n  shows \" ((j + i) mod (Suc LAST)) \\<noteq> j\"\n      using a1 a2 a3 a4 test5Aux by auto  \n  \n\n  \nlemma  iPlus1IsNotI:\n  assumes a1:\"0 < LAST\" and \n  a2:\"J LAST ''+'' [s (Ident ''head''), index (Suc 0)] = s (Ident ''head'')\" \n  (*and *a3:\" scalar2Bool (J LAST ''le'' [s (Ident ''head''), index LAST])\"*)\n  shows False\n  proof -\n    have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\"\n      using headIsIndex by auto\n    then obtain i where b1:\"((s (Ident ''head'') ) = (index i))\"\n      by blast\n   (* have b2:\"i\\<le> LAST\"\n     using a1 a3 b1 axiomOnLe  apply auto        done*)\n    show False\n       apply(cut_tac a1 a2 b1 ,case_tac \"i=LAST\",auto)\n       by (metis mod_Suc mod_mod_trivial n_not_Suc_n nat.inject)\n      \n  qed \n\nlemma iPlusSucLatIsi:  \n  assumes a:\" scalar2Bool (J LAST ''le'' [s (Ident ''head''), index LAST])\"\n  shows \"J LAST ''+'' [expEval (J LAST) (applyPlusN head LAST) s, index (Suc 0)]=  s (Ident ''head'')\"\n   proof -\n    have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\"\n      using headIsIndex by auto\n    then obtain i where b1:\"((s (Ident ''head'') ) = (index i))\"\n      by blast\n    have b2:\"i\\<le> LAST\"\n     using a b1 axiomOnLe  apply auto   done\n    show ?thesis\n    apply(cut_tac b1 b2,simp)\n    by (metis (full_types) Divides.mod_less add.commute add_Suc le_imp_less_Suc mod_Suc_eq_Suc_mod mod_add_self1)\nqed\n\nlemma  iPlusjPLUSIsNotj:\n  assumes a1:\"0 < LAST\"  and a4:\"i < LAST\" and\n  a3:\" scalar2Bool (J LAST ''le'' [s (Ident ''head''), index LAST])\"\n          \n  shows \"J LAST ''+'' [expEval (J LAST) (applyPlusN head i) s, index (Suc 0)]\\<noteq>s (Ident ''head'')\" \nproof -\n    have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\"\n      using headIsIndex by auto\n    then obtain j where b1:\"((s (Ident ''head'') ) = (index j))\"\n      by blast\n    have b2:\"j\\<le> LAST\"\n     using a1 a3 b1 axiomOnLe  apply auto        done\n    have b3: \"J LAST ''+'' [expEval (J LAST) (applyPlusN head i) s, index (Suc 0)]  =index ((j + Suc i) mod (Suc LAST))\"\n    by (metis Suc_eq_plus1 a4 b1 b2 discrete le_Suc_eq onApplyPlusI test1)\n \n    have b4:\"Suc i< Suc LAST\"\n    by (simp add: a4)  thm test5\n    have b5:\"((j + (Suc i)) mod (Suc LAST)) \\<noteq>j\"  \n    apply (cut_tac a1  b2 b4 ,rule test5,auto) \n    done\n    with b3 show \"J LAST ''+'' [expEval (J LAST) (applyPlusN head i) s, index (Suc 0)] \\<noteq> s (Ident ''head'')\"\n    by (simp add: b1)\n       \nqed\nlemma substApplyHead[simp]:\n  \"substExp (applyPlusN head n) [(Ident ''head'', uif ''+'' [head, Const (index (Suc 0))])] =\n         applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) n\"\nproof(induct_tac n,auto)qed         \n\nlemma applyIPlusIsPlusI:\n\"J LAST ''+'' [expEval (J LAST) (applyPlusN head i) s, index (Suc 0)] =\n         expEval (J LAST) (substExp (applyPlusN head i) \n         [(Ident ''head'', uif ''+'' [head, Const (index (Suc 0))])]) s\"\nproof(induct_tac i,auto)qed\n\nlemma substCaseExp:\n  \"substExp\n   (caseExp\n     (map (\\<lambda>i. (g i,e i)) (down LAST)))\n      subst0 =\n    caseExp\n      (map (\\<lambda>i. (substForm (g i) subst0, substExp (e i) subst0))\n      (down LAST))\"        (is \"?P LAST\")\nproof(induct_tac LAST,simp)\n  fix n\n  assume b:\"?P n\"\n  show \"?P (Suc n)\" (is \"substExp (?caseExp (Suc n)) subst0= caseExp (?list (Suc n))\")\n  proof -\n  have c1:\"substExp (?caseExp (Suc n)) subst0=\n          substExp (caseExp ((g (Suc n), e (Suc n))#(map (\\<lambda>i. (g i,e i)) (down n)))) subst0\" (is \"?LHS =?RHS1\")\n    apply (simp only:downSuc ,auto) done\n  have c2:\"?RHS1 =iteForm (substForm (g (Suc n)) subst0) (substExp (e (Suc n)) subst0) (caseExp (?list n))\"\n      (is \"?RHS1=?RHS2\")\n      by (simp add: b)\n  have c3:\"?RHS2=caseExp ((substForm (g (Suc n)) subst0,substExp (e (Suc n)) subst0)#(?list n))\"\n      (is \"?RHS2=?RHS3\")\n    by(simp )\n  have c4:\"?RHS3=caseExp (?list (Suc n))\"\n    by simp\n    with c1 c2 c3 show \"?P (Suc n)\" \n    by presburger\n  qed\nqed\n\n\n    \nlemma substCaseExp1:\n  \"substExp\n   (caseExp\n     (map (\\<lambda>i. (eqn (applyPlusN head (j - Suc 0)) (Const (index i)), IVar (Para mem i))) (down LAST)))\n      [(Ident ''head'', uif ''+'' [head, Const (index (Suc 0))])] =\n    caseExp\n      (map (\\<lambda>i. (eqn (applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) (j - Suc 0)) (Const (index i)), IVar (Para mem i)))\n      (down LAST))\"        (is \"?P LAST\")\nusing substCaseExp by auto\n \nlemma consistencyOfRbfifo0:\n  assumes a:\"LAST=0 \"\n  shows \"consistent' (ringBuffifo LAST ) (J LAST) (rbFifoGsteSpec LAST  data) \n  (tagFunOfRingBufFifo  data LAST)\"\n  proof(unfold consistent'_def,rule allI,rule impI)\n    fix e\n    let ?G=\" (rbFifoGsteSpec LAST  data)\"\n    let ?M=\"(ringBuffifo LAST )\"\n    let ?tag=\"(tagFunOfRingBufFifo  data LAST)\"\n    let ?P =\"\\<lambda>e.   \n    (let f=andListForm (?tag (sink e)) in\n    let f'=andListForm (?tag (source e)) in\n    tautlogy (implyForm (andForm f' (antOf ?G e)) (preCond1  f  ( ?M))) (J LAST))\"\n    \n    assume a1:\"e \\<in> edgesOf (rbFifoGsteSpec LAST  data)\"\n    \n    have \"e=Edge vertexI ( Vertex 1) | \n          e=Edge  ( Vertex 1) ( Vertex 3) |\n          e=Edge  ( Vertex 1) ( Vertex 4)|\n           (\\<exists>i. 0\\<le>i \\<and> i\\<le> LAST + 1 \\<and>  e=( Edge (Vertex ( 2*i+1 ))  (Vertex (  2*i+1 ))) )   |\n            (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST + 1 \\<and>  e=( Edge (Vertex ( 2*i+2 ))  (Vertex (  2*i+2 ))) ) |\n            \n           e=Edge  ( Vertex 3) ( Vertex 1) |\n           e=Edge (Vertex 4) (Vertex 1)\"\n      apply(cut_tac a a1,auto)  done\n   moreover\n    {assume b1:\"e=Edge vertexI ( Vertex 1)\"\n     have \"?P e\"\n     apply(cut_tac b1, simp add:antOfRbFifo_def)\n     done\n     }\n    moreover\n    {assume b1:\" (\\<exists>i. 0\\<le>i \\<and> i\\<le> LAST +1  \\<and>  e=( Edge (Vertex (2* i + 1))  (Vertex (  2*i + 1))) )  \" (is \"\\<exists>i. ?asm i\")\n     from b1 obtain i where b2:\"?asm i\" by auto\n      have \"?P e\"\n       apply(cut_tac b2, simp add:antOfRbFifo_def substNIl) done\n    }\n    moreover\n    {assume b1:\" (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST+1 \\<and>  e=( Edge (Vertex (2* i + 2))  (Vertex (  2*i + 2))) )  \" (is \"\\<exists>i. ?asm i\")\n     from b1 obtain i where b2:\"?asm i\" by auto\n      have \"?P e\"\n       apply(cut_tac b2, simp add:antOfRbFifo_def substNIl) done\n    }  \n     moreover\n    {assume b1:\" e=Edge  ( Vertex 1) ( Vertex 3) \"\n        \n       let ?P' =\"\\<lambda>e.   \n       (let f=andListForm (?tag (sink e)) in\n       let f'=andListForm (?tag (source e)) in\n       tautlogy (implyForm (andForm f' (antOf ?G e)) (preCond1  f  (branch2 LAST))) (J LAST))\"\n       \n        let ?P1=\"\\<lambda>e.   \n       (let f=andListForm (?tag (sink e)) in\n       let f'=andListForm (?tag (source e)) in\n       let tailPlus=uif ''+'' [tail, (Const (index 1))] in\n       let f1=andListForm [eqn tailPlus (applyPlusN head 1), eqn  LOW LOW,\n         eqn full LOW, uip ''le'' [head,LASTE]] in\n       tautlogy (implyForm (andForm f' (antOf ?G e)) f1) (J LAST))\" \n       have c1:\"?P e= ?P' e\"\n        by (simp add: a b1 del:tautlogy_def,auto)\n       \n      \n      (* have c2:\"?P' e=?P1 e\"  \n        apply (cut_tac a b1,simp del:tautlogy_def add:Let_def) \n        apply(rule onIfExpPos)\n        apply*)\n        have \"?P e \"\n       proof(cut_tac a b1,auto simp add:Let_def )  \n       fix s\n       assume c1:\"scalar2Bool (J 0 ''le'' [s (Ident ''head''), index 0]) \" and\n       c2:\" J 0 ''+'' [s (Ident ''head''), index (Suc 0)] \\<noteq> s (Ident ''head'')\"  \n       have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\" \n       using headIsIndex by auto\n       then obtain i where b1:\"((s (Ident ''head'') ) = (index i))\"\n          by blast\n       have b2:\"i=0\" \n       using a c1 b1 axiomOnLe  apply auto        done\n       show False\n       apply(cut_tac b1 b2 c2 , auto) done\n       \n       qed\n          \n    }\n    \n     moreover\n    {assume b1:\" e=Edge  ( Vertex 1) ( Vertex 4) \"\n      let ?f=\"andForm (neg (eqn rst HIGH)) (andForm (eqn push HIGH) nFullForm ) \" \n       have \"?P e \"\n       proof(cut_tac a b1,auto simp add:Let_def)\n          fix s::state\n          assume c1:\"s (Ident ''head'') \\<noteq> index 0 \" and\n          c2:\"scalar2Bool (J 0 ''le'' [s (Ident ''head''), index 0])\"\n          have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\" \n             using headIsIndex by auto\n          then obtain i where b1:\"((s (Ident ''head'') ) = (index i))\"\n             by blast\n          have b2:\"i=0\" \n            using a c2 b1 axiomOnLe  apply auto        done\n          show False\n          apply(cut_tac b1 b2 c1 , auto) done\n       qed\n    }\n    moreover\n    {assume b1:\"e=Edge  ( Vertex 3) ( Vertex 1)\"\n     \n     have b3:\"varOfExp (applyPlusN head i) =[Ident ''head'']\"\n        by simp \n     have \"?P e\"\n     proof(cut_tac a b1 b3,auto simp add:antOfRbFifo_def Let_def)\n     fix s\n     assume c1:\" scalar2Bool (J 0 ''le'' [s (Ident ''head''), index 0])\" \n     have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\" \n        using headIsIndex by auto\n     then obtain i where b1:\"((s (Ident ''head'') ) = (index i))\"\n        by blast\n     have b2:\"i=0\" \n        using a c1 b1 axiomOnLe  apply auto        done\n     show \"scalar2Bool (J 0 ''le'' [J 0 ''+'' [s (Ident ''head''), index (Suc 0)], index 0])\"\n      apply(cut_tac b1 b2,auto)\n     done\n     qed\n     }\n    moreover\n    {assume b1:\"e=Edge  ( Vertex 4) ( Vertex 1)\"\n     \n     have b3:\"varOfExp (applyPlusN head i) =[Ident ''head'']\"\n        by simp \n     have \"?P e\"\n     proof(cut_tac a b1 b3,auto simp add:antOfRbFifo_def Let_def)\n     qed\n     }\n    ultimately show \"?P e\" by satx\nqed\n\nlemma consistencyOfRbfifo:\n  assumes a:\"0 < LAST \"\n  shows \"consistent' (ringBuffifo LAST ) (J LAST) (rbFifoGsteSpec LAST  data) \n  (tagFunOfRingBufFifo  data LAST)\"\n  proof(unfold consistent'_def,rule allI,rule impI)\n    fix e\n    let ?G=\" (rbFifoGsteSpec LAST  data)\"\n    let ?M=\"(ringBuffifo LAST )\"\n    let ?tag=\"(tagFunOfRingBufFifo  data LAST)\"\n    let ?P =\"\\<lambda>e.   \n    (let f=andListForm (?tag (sink e)) in\n    let f'=andListForm (?tag (source e)) in\n    tautlogy (implyForm (andForm f' (antOf ?G e)) (preCond1  f  ( ?M))) (J LAST))\"\n    \n    assume a1:\"e \\<in> edgesOf (rbFifoGsteSpec LAST  data)\"\n    \n    have \"e=Edge vertexI ( Vertex 1) | \n          e=Edge  ( Vertex 1) ( Vertex 3) |\n          e=Edge  ( Vertex 1) ( Vertex 4)|\n           (\\<exists>i. 0\\<le>i \\<and> i\\<le> LAST+1 \\<and>  e=( Edge (Vertex ( 2*i+1 ))  (Vertex (  2*i+1 ))) )   |\n            (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST+1 \\<and>  e=( Edge (Vertex ( 2*i+2 ))  (Vertex (  2*i+2 ))) ) |\n            \n           (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST  \\<and> e=( Edge (Vertex (2 * i + 1))  (Vertex (2 * i + 3))) ) |\n           (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST  \\<and> e=( Edge (Vertex (2 * i + 1))  (Vertex (2 * i + 4))) )  |\n           \n           (\\<exists>i. 0\\<le>i \\<and> i\\<le> LAST  \\<and>  e= ( Edge (Vertex (2 * i + 3))  (Vertex (2 * i + 1))) ) |\n           (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST   \\<and> e=( Edge (Vertex(2 * i + 4))  (Vertex(2 *i+ 2))))|\n           e=Edge (Vertex 4) (Vertex 1)\"\n      apply(cut_tac a a1,auto)  done\n    moreover\n    {assume b1:\"e=Edge vertexI ( Vertex 1)\"\n     have \"?P e\"\n     apply(cut_tac b1, simp add:antOfRbFifo_def)\n     done\n     }\n    moreover\n    {assume b1:\" (\\<exists>i. 0\\<le>i \\<and> i\\<le> LAST+1  \\<and>  e=( Edge (Vertex (2* i + 1))  (Vertex (  2*i + 1))) )  \" (is \"\\<exists>i. ?asm i\")\n     from b1 obtain i where b2:\"?asm i\" by auto\n      have \"?P e\"\n       apply(cut_tac b2, simp add:antOfRbFifo_def substNIl) done\n    }\n    moreover\n    {assume b1:\" (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST+1  \\<and>  e=( Edge (Vertex (2* i + 2))  (Vertex (  2*i + 2))) )  \" (is \"\\<exists>i. ?asm i\")\n     from b1 obtain i where b2:\"?asm i\" by auto\n      have \"?P e\"\n       apply(cut_tac b2, simp add:antOfRbFifo_def substNIl) done\n    }  \n     moreover\n    {assume b1:\" e=Edge  ( Vertex 1) ( Vertex 3) \"\n        \n       let ?P' =\"\\<lambda>e.   \n       (let f=andListForm (?tag (sink e)) in\n       let f'=andListForm (?tag (source e)) in\n       tautlogy (implyForm (andForm f' (antOf ?G e)) (preCond1  f  (branch2 LAST))) (J LAST))\"\n       \n        let ?P1=\"\\<lambda>e.   \n       (let f=andListForm (?tag (sink e)) in\n       let f'=andListForm (?tag (source e)) in\n       let tailPlus=uif ''+'' [tail, (Const (index 1))] in\n       let f1=andListForm [eqn tailPlus (applyPlusN head 1), eqn  LOW LOW,\n         eqn full LOW, uip ''le'' [head,LASTE]] in\n       tautlogy (implyForm (andForm f' (antOf ?G e)) f1) (J LAST))\" \n       have c1:\"?P e= ?P' e\"\n        by (simp add: a b1 del:tautlogy_def,auto)\n       \n      \n      \n        have \"?P e \"\n       proof(cut_tac a b1,auto simp add:Let_def )  \n       fix s\n       assume c1:\"0 <LAST\" and\n       c2:\" J LAST ''+'' [s (Ident ''head''), index (Suc 0)] = s (Ident ''head'')\"  \n        \n       show False\n       apply(cut_tac c1 c2 , blast intro:  iPlus1IsNotI ) done\n       \n       qed\n          \n    }\n    \n     moreover\n    {assume b1:\" e=Edge  ( Vertex 1) ( Vertex 4) \"\n      let ?f=\"andForm (neg (eqn rst HIGH)) (andForm (eqn push HIGH) nFullForm ) \"\n      have b2:\"2*LAST +4 \\<noteq> 4\" apply(cut_tac a,arith) done\n       have \"?P e \"\n       proof(cut_tac a b1 b2,auto simp add:Let_def)\n          fix s::state\n          assume a1:\"0 <LAST\" and\n          a2:\"J LAST ''+'' [s (Ident ''head''), index (Suc 0)] = s (Ident ''head'')\"\n          \n          show False\n          apply(cut_tac a a2 , blast intro:  iPlus1IsNotI ) done\n        next\n          fix s\n          assume a1:\"s (Ident ''tail'') = s (Ident ''head'')\" and\n          a2:\" scalar2Bool (J LAST ''le'' [s (Ident ''head''), index LAST])\" and\n          a3:\"s (Ident ''dataIn'') = index data\" \n          have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\" \n          using headIsIndex by auto\n          then obtain i where b1:\"((s (Ident ''head'') ) = (index i))\"\n          by blast\n          have b2:\"i\\<le> LAST\" \n          using a1 a2 b1 axiomOnLe  apply auto        done\n          have b3:\"  \n          expEval (J LAST)\n          (substExp\n            (caseExp (map (\\<lambda>i. (eqn head (Const (index i)), IVar (Para mem i))) (down LAST)))\n            (map (\\<lambda>i. (Para mem i,\n                       iteForm (eqn tail (Const (index i))) dataIn (IVar (Para mem i))))\n              (down LAST)))\n          s =\n         expEval (J LAST) dataIn s\" thm auxOnReadWrite          \n          using a1 a2 b1 b2  by auto \n          show \"\n          expEval (J LAST)\n          (substExp\n            (caseExp (map (\\<lambda>i. (eqn head (Const (index i)), IVar (Para mem i))) (down LAST)))\n            (map (\\<lambda>i. (Para mem i,\n                       iteForm (eqn tail (Const (index i))) dataIn (IVar (Para mem i))))\n              (down LAST)))\n          s =\n         index data\"\n          using a3 b3  by auto\n     qed     \n    }\n    \n    moreover\n    {assume b1:\" \\<exists>i. 1\\<le>i \\<and> i \\<le>LAST \\<and> e=Edge  ( Vertex (2*i + 1)) ( Vertex (2*i + 3))\"     (is \"\\<exists>i. ?Q i\")\n      from b1 obtain i where b1:\"?Q i\" by blast\n      have b2:\"i - 1 < LAST\" by(cut_tac a b1,auto)\n      have b3:\"varOfExp (applyPlusN head i) =[Ident ''head'']\" by auto\n      have \"i=LAST \\<or> i <LAST\" by(cut_tac b1 ,auto)\n      moreover\n      {assume b4:\"i =LAST\"        \n      have \"?P e \"\n      proof(cut_tac  a b1  b3 b4,auto simp add: antOfRbFifo_def assms Let_def) \n        fix s\n        assume  a1:\"J LAST ''+'' [expEval (J LAST) (applyPlusN head LAST) s, index (Suc 0)] \\<noteq> s (Ident ''head'')\" and\n          a2:\" scalar2Bool (J LAST ''le'' [s (Ident ''head''), index LAST])\"  \n          \n          have b1:\"J LAST ''+'' [expEval (J LAST) (applyPlusN head LAST) s, index (Suc 0)]= s (Ident ''head'')\" \n          by (simp add: a2 iPlusSucLatIsi)\n          with a1 b1 show False by auto \n      qed\n      }\n      moreover\n      {assume b4:\" i <LAST\" \n      have \"?P e \"\n      proof(cut_tac  a b1 b3 b4,auto simp add: antOfRbFifo_def assms Let_def)\n        fix s\n        assume c1:\" Suc 0 \\<le> i \" and c2:\" i < LAST \" and c3:\"\n        J LAST ''+'' [expEval (J LAST) (applyPlusN head i) s, index (Suc 0)] = s (Ident ''head'')\"\n        and c4:\"scalar2Bool (J LAST ''le'' [s (Ident ''head''), index LAST]) \"\n        have c1:\"0< i\" by(cut_tac c1,simp)\n        have c5:\"J LAST ''+'' [expEval (J LAST) (applyPlusN head i) s, index (Suc 0)] \\<noteq> s (Ident ''head'')\"\n        using assms c1 c2 c4 iPlusjPLUSIsNotj by blast \n        \n        with c3 show False by simp\n        \n        \n      qed\n      }\n      ultimately have \"?P e \" by satx\n      \n          \n     }\n    \n    moreover\n    {assume b1:\" \\<exists>i. 1\\<le>i \\<and> i\\<le> LAST \\<and> e=Edge  ( Vertex (2*i + 1)) ( Vertex (2*i+4))    \"(is \"\\<exists>i. ?Q i\")\n     from b1 obtain i where b1:\"?Q i\" by blast\n      have b2:\"i - 1 < LAST\" by(cut_tac a b1,auto)\n      have b3:\"varOfExp (applyPlusN head i) =[Ident ''head'']\"\n        by simp \n      have \"i=LAST \\<or> i <LAST\" by(cut_tac b1 ,auto)\n      moreover\n      {assume b4:\"i =LAST\"        \n      have \"?P e \"\n      proof(cut_tac  a b1  b3 b4,auto simp add:  assms Let_def) \n        fix s\n        assume  a1:\"J LAST ''+'' [expEval (J LAST) (applyPlusN head LAST) s, index (Suc 0)] \\<noteq> s (Ident ''head'')\" and\n          a2:\" scalar2Bool (J LAST ''le'' [s (Ident ''head''), index LAST])\"  \n          \n          have b1:\"J LAST ''+'' [expEval (J LAST) (applyPlusN head LAST) s, index (Suc 0)]= s (Ident ''head'')\"\n          by (simp add: a2 iPlusSucLatIsi)\n          with a1 b1 show False by auto  \n      next\n         fix s\n          assume  \n          a4:\"s (Ident ''tail'') = expEval (J LAST) (applyPlusN head LAST) s\" and\n          a2:\" scalar2Bool (J LAST ''le'' [s (Ident ''head''), index LAST])\" and\n          a3:\"s (Ident ''dataIn'') = index data\" \n          \n            \n          have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\" \n          using headIsIndex by auto\n          then obtain j where b1:\"((s (Ident ''head'') ) = (index j))\"\n          by blast\n          have b2:\"j\\<le> LAST\" \n          using  a2 b1 axiomOnLe  apply auto        done\n          (*have a0:\"s (Ident ''tail'') = s (Ident ''head'')\"*)\n          have b3:\"  \n          expEval (J LAST)\n          (substExp\n            (caseExp (map (\\<lambda>i. (eqn (applyPlusN head LAST) (Const (index i)), IVar (Para mem i))) (down LAST)))\n            (map (\\<lambda>i. (Para mem i,\n                       iteForm (eqn tail (Const (index i))) dataIn (IVar (Para mem i))))\n              (down LAST)))\n          s =\n         expEval (J LAST) dataIn s\" thm auxOnReadWrite          \n          using a4 a2 b1 b2  by auto \n          show \"\n          expEval (J LAST)\n          (substExp\n            (caseExp (map (\\<lambda>i. (eqn (applyPlusN head LAST) (Const (index i)), IVar (Para mem i))) (down LAST)))\n            (map (\\<lambda>i. (Para mem i,\n                       iteForm (eqn tail (Const (index i))) dataIn (IVar (Para mem i))))\n              (down LAST)))\n          s =\n         index data\"\n          using a3 b3  by auto\n     qed     \n      \n      }\n      moreover\n      {assume b4:\" i <LAST\" \n      have \"?P e \"\n      proof(cut_tac  a b1 b3 b4,auto simp add: antOfRbFifo_def assms Let_def)\n        fix s\n        assume c1:\" Suc 0 \\<le> i \" and c2:\" i < LAST \" and c3:\"\n        J LAST ''+'' [expEval (J LAST) (applyPlusN head i) s, index (Suc 0)] = s (Ident ''head'')\"\n        and c4:\"scalar2Bool (J LAST ''le'' [s (Ident ''head''), index LAST]) \"\n        \n        have c1:\"0< i\" by(cut_tac c1,simp)\n        have c5:\"J LAST ''+'' [expEval (J LAST) (applyPlusN head i) s, index (Suc 0)] \\<noteq> s (Ident ''head'')\"\n        using assms c1 c2 c4 iPlusjPLUSIsNotj by blast \n        \n        with c3 show False by simp\n        \n      next\n        fix s\n        assume\n          a4:\"s (Ident ''tail'') = expEval (J LAST) (applyPlusN head i) s\" and\n          a2:\" scalar2Bool (J LAST ''le'' [s (Ident ''head''), index LAST])\" and\n          a3:\"s (Ident ''dataIn'') = index data\" \n          \n            \n          have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\" \n          using headIsIndex by auto\n          then obtain j where b1:\"((s (Ident ''head'') ) = (index j))\"\n          by blast\n          have b2:\"j\\<le> LAST\" \n          using  a2 b1 axiomOnLe  apply auto        done\n          have b3:\"expEval (J LAST) tail s = index ((j +i) mod (Suc LAST))\"\n            apply(cut_tac a4,simp)\n            by (simp add: b1 b2 b4 less_or_eq_imp_le)\n          have b4:\"(j +i) mod (Suc LAST) \\<le> LAST\"   by simp  \n          (*have a0:\"s (Ident ''tail'') = s (Ident ''head'')\"*)\n           \n          have b5:\"expEval (J LAST)\n          (substExp\n            (caseExp (map (\\<lambda>i'. (eqn (applyPlusN head i) (Const (index i')), IVar (Para mem i'))) (down LAST)))\n            (map (\\<lambda>i'. (Para mem i',\n                       iteForm (eqn tail (Const (index i'))) dataIn (IVar (Para mem i'))))\n              (down LAST)))\n          s =\n         expEval (J LAST) dataIn s\" thm readWrite          \n            apply(cut_tac b3 b4,  rule readWrite,auto)\n            by (simp add: a4) \n          show \"expEval (J LAST)\n          (substExp\n            (caseExp (map (\\<lambda>i'. (eqn (applyPlusN head i) (Const (index i')), IVar (Para mem i'))) (down LAST)))\n            (map (\\<lambda>i'. (Para mem i',\n                       iteForm (eqn tail (Const (index i'))) dataIn (IVar (Para mem i'))))\n              (down LAST)))\n          s =\n         index data\"\n          using a3 b5  by auto\n      qed\n      }\n      ultimately have \"?P e \" by satx\n       \n     } \n    \n     moreover\n    {assume b1:\"\\<exists>i. 0\\<le>i \\<and> i\\<le> LAST \\<and>  e=Edge  ( Vertex (2*i + 3)) ( Vertex (2*i + 1))   \" (is \"\\<exists>i. ?Q i\")\n       from b1 obtain i where b1:\"?Q i\" by blast\n      have b2:\"i - 1 < LAST\" by(cut_tac a b1,auto)\n      have b3:\"varOfExp (applyPlusN head i) =[Ident ''head'']\"\n        by simp \n      have \"i=LAST \\<or> i <LAST\" by(cut_tac b1 ,auto)\n      moreover\n      {assume b4:\"i =LAST\"        \n      have \"?P e \"\n      proof(cut_tac  a b1  b3 b4,auto simp add:  assms Let_def)\n        fix s\n        assume b5:\" LAST = 0\"\n        with a show \"scalar2Bool (J 0 ''le'' [J 0 ''+'' [s (Ident ''head''), index (Suc 0)], index 0])\" by simp\n      next\n        fix s\n        assume c1:\"J LAST ''+'' [expEval (J LAST) (applyPlusN head LAST) s, index (Suc 0)] \n          = J LAST ''+'' [s (Ident ''head''), index (Suc 0)]\" and\n        c2:\"scalar2Bool (J LAST ''le'' [s (Ident ''head''), index LAST])\"\n        have d1:\"J LAST ''+'' [expEval (J LAST) (applyPlusN head LAST) s, index (Suc 0)]= s (Ident ''head'')\" \n          by (simp add: c2 iPlusSucLatIsi)\n        \n        have d2:\"J LAST ''+'' [expEval (J LAST) (applyPlusN head 0) s, index (Suc 0)] =\n        J LAST ''+'' [s (Ident ''head''), index (Suc 0)] \" \n        apply(simp) done thm iPlusjPLUSIsNotj\n        have d3:\"J LAST ''+'' [expEval (J LAST) (applyPlusN head 0) s, index (Suc 0)]\\<noteq> s (Ident ''head'')\" \n        apply(cut_tac a c2,rule  iPlusjPLUSIsNotj,auto)  done\n        with d1 d2 c1 show False\n        by simp\n      next\n        fix s\n        show \"  J LAST ''+'' [expEval (J LAST) (applyPlusN head LAST) s, index (Suc 0)] =\n         expEval (J LAST) (applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) LAST) s\"\n         using applyIPlusIsPlusI by auto\n      next\n        fix s\n        \n          have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\"\n            using headIsIndex by auto\n          then obtain j where b1:\"((s (Ident ''head'') ) = (index j))\"\n            by blast  \n          show \"scalar2Bool (J LAST ''le'' [J LAST ''+'' [s (Ident ''head''), index (Suc 0)], index LAST])\"\n          apply(cut_tac b1,auto) done\n      qed    \n     }\n     moreover\n      {assume b4:\"i <LAST\"        \n      have \"?P e \"\n      proof(cut_tac  a b1  b3 b4,auto simp add:  assms Let_def) \n      fix s\n      have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\"\n            using headIsIndex by auto\n          then obtain j where b1:\"((s (Ident ''head'') ) = (index j))\"\n            by blast  \n      show \"scalar2Bool (J LAST ''le'' [J LAST ''+'' [s (Ident ''head''), index (Suc 0)], index LAST])\"\n        apply(cut_tac b1,auto) done\n     \n     next\n      fix s\n      assume c1:\" J LAST ''+'' [expEval (J LAST) (applyPlusN head i) s, index (Suc 0)] =\n      J LAST ''+'' [s (Ident ''head''), index (Suc 0)]\" and \n      c2:\" scalar2Bool (J LAST ''le'' [s (Ident ''head''), index LAST])\" and c3:\"0<i\"\n       have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\"\n            using headIsIndex by auto\n          then obtain j where e1:\"((s (Ident ''head'') ) = (index j))\"\n            by blast \n        have e2:\"j\\<le> LAST\" \n          using  c2 e1 axiomOnLe  apply auto        done thm  onApplyPlusI\n        have e3:\"expEval (J LAST) (applyPlusN head i) s= index ((j +i) mod Suc LAST)\"\n          by (simp add: e1 e2 b4 less_imp_le_nat)\n          \n        show False\n       apply(cut_tac a b1 e1 e2 e3 c1 c3, simp)\n       by (smt Divides.mod_less le_imp_less_Suc le_mod_geq mod_Suc nat.distinct(1) nat.inject neq0_conv not_less test5)\n     next\n      fix s\n      have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\"\n            using headIsIndex by auto\n          then obtain j where b1:\"((s (Ident ''head'') ) = (index j))\"\n            by blast  \n      show \" scalar2Bool (J LAST ''le'' [J LAST ''+'' [s (Ident ''head''), index (Suc 0)], index LAST])\"\n        apply(cut_tac b1,auto) done\n     next\n      fix s\n        show \"J LAST ''+'' [expEval (J LAST) (applyPlusN head i) s, index (Suc 0)] =\n         expEval (J LAST) (applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) i) s\"\n         by (simp add: applyIPlusIsPlusI)\n    qed\n    }\n   ultimately have \"?P e \" by satx\n   }\n  \n  \n     moreover\n    {assume b1:\"\\<exists>i.  1\\<le>i \\<and> i\\<le> LAST \\<and> e=Edge  ( Vertex (2*i + 4)) ( Vertex (2*i+2 ))   \" (is \"\\<exists>i. ?Q i\")\n      from b1 obtain i where b1:\"?Q i\" by blast\n      \n      have b3:\"varOfExp (applyPlusN head i) =[Ident ''head'']\"\n        by simp \n      have \"i=LAST \\<or> i <LAST\" by(cut_tac b1 ,auto)\n      moreover\n      {assume b4:\"i =LAST\"        \n      have \"?P e \"\n      proof(cut_tac  a b1  b3 b4,auto simp add:  assms Let_def)\n        fix s\n\n        assume c1:\" J LAST ''+'' [expEval (J LAST) (applyPlusN head LAST) s, index (Suc 0)] = \n        J LAST ''+'' [s (Ident ''head''), index (Suc 0)]\" and \n        c2:\" scalar2Bool (J LAST ''le'' [s (Ident ''head''), index LAST])\" \n        have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\"\n            using headIsIndex by auto\n        then obtain j where e1:\"((s (Ident ''head'') ) = (index j))\"\n            by blast \n        have e2:\"j\\<le> LAST\" \n          using  c2 e1 axiomOnLe  apply auto        done thm  onApplyPlusI\n        have e3:\"J LAST ''+'' [expEval (J LAST) (applyPlusN head LAST) s, index (Suc 0)]= index j\"\n          by (metis c2 e1 iPlusSucLatIsi)\n          \n        have e4:\"J LAST ''+'' [s (Ident ''head''), index (Suc 0)] = index ((j +1) mod Suc LAST) \"\n          by (simp add: e1)\n        show False\n          apply(cut_tac c1 e3 e4 a, simp)\n          by (metis e1 iPlus1IsNotI)\n      next\n        fix s\n        show \"  J LAST ''+'' [expEval (J LAST) (applyPlusN head LAST) s, index (Suc 0)] =\n          expEval (J LAST) (applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) LAST) s\"\n          using applyIPlusIsPlusI by auto\n      next\n        fix s\n        \n          have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\"\n            using headIsIndex by auto\n          then obtain j where b1:\"((s (Ident ''head'') ) = (index j))\"\n            by blast  \n          show \"scalar2Bool (J LAST ''le'' [J LAST ''+'' [s (Ident ''head''), index (Suc 0)], index LAST])\"\n          apply(cut_tac b1,auto) done\n      next\n        fix s\n        assume  \n          a2:\" scalar2Bool (J LAST ''le'' [s (Ident ''head''), index LAST])\" and \n          a4:\"expEval (J LAST) (caseExp (map (\\<lambda>i. (eqn (applyPlusN head LAST) (Const (index i)), IVar (Para mem i))) (down LAST))) s =\n         index data\"\n          have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\" \n          using headIsIndex by auto\n          then obtain j where b1:\"((s (Ident ''head'') ) = (index j))\"\n          by blast\n          have b2:\"j\\<le> LAST\" \n          using  a2 b1 axiomOnLe  apply auto        done\n          (*have a0:\"s (Ident ''tail'') = s (Ident ''head'')\"*)\n          have b20:\"tautlogy (eqn (applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) (LAST - Suc 0)) \n                              (applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) (LAST - Suc 0))) (J LAST)\"\n                  apply(induct_tac LAST, auto) done\n          have b3:\"  \n          expEval (J LAST)\n          (substExp\n            (caseExp\n              (map (\\<lambda>i. (eqn (applyPlusN head (LAST - Suc 0)) (Const (index i)), IVar (Para mem i))) (down LAST)))\n            [(Ident ''head'', uif ''+'' [head, Const (index (Suc 0))])])\n          s   =\n           expEval (J LAST)\n          (caseExp\n            (map (\\<lambda>i. (eqn (applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) (LAST - Suc 0)) (Const (index i)), IVar (Para mem i)))\n            (down LAST))) s\" \n            using substCaseExp1 by auto\n\n         have b4:\" expEval (J LAST)\n          ((caseExp (map (\\<lambda>i. (eqn (applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) (LAST - Suc 0)) (Const (index i)), \n          IVar (Para mem i))) (down LAST)))\n            )\n          s =\n         expEval (J LAST) (caseExp (map (\\<lambda>i. (eqn (applyPlusN head LAST) (Const (index i)), IVar (Para mem i))) (down LAST))) s\"\n         proof(rule caseExpCong1,simp)\n            \n            \n            have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\" \n            using headIsIndex by auto\n            then obtain j where b1:\"((s (Ident ''head'') ) = (index j))\"\n              by blast\n            have b2:\"j\\<le> LAST\" \n            using  a2 b1 axiomOnLe  apply auto        done\n            show \"expEval (J LAST) (applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) (LAST - Suc 0)) s\n            = expEval (J LAST) (applyPlusN head LAST) s\"\n            apply(cut_tac a b1 b2,auto) done\n          qed\n         \n          show \"expEval (J LAST)\n          (substExp (caseExp (map (\\<lambda>i. (eqn (applyPlusN head (LAST - Suc 0)) (Const (index i)), IVar (Para mem i))) (down LAST)))\n            [(Ident ''head'', uif ''+'' [head, Const (index (Suc 0))])])\n          s =\n         index data\"\n         by (simp add: a4 b3 b4)\n        \n      qed     \n     }\n    moreover\n    {assume b4:\"i <LAST\"        \n      have \"?P e \"\n      proof(cut_tac  a b1  b3 b4,auto simp add:  assms Let_def) \n      fix s\n      have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\"\n            using headIsIndex by auto\n          then obtain j where b1:\"((s (Ident ''head'') ) = (index j))\"\n            by blast  \n      show \"scalar2Bool (J LAST ''le'' [J LAST ''+'' [s (Ident ''head''), index (Suc 0)], index LAST])\"\n        apply(cut_tac b1,auto) done\n     \n     next\n      fix s\n      assume c1:\" J LAST ''+'' [expEval (J LAST) (applyPlusN head i) s, index (Suc 0)] =\n      J LAST ''+'' [s (Ident ''head''), index (Suc 0)]\" and \n      c2:\" scalar2Bool (J LAST ''le'' [s (Ident ''head''), index LAST])\" and c3:\"Suc 0 \\<le> i\"\n       have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\"\n            using headIsIndex by auto\n          then obtain j where e1:\"((s (Ident ''head'') ) = (index j))\"\n            by blast \n        have e2:\"j\\<le> LAST\" \n          using  c2 e1 axiomOnLe  apply auto        done thm  onApplyPlusI\n        have e3:\"expEval (J LAST) (applyPlusN head i) s= index ((j +i) mod Suc LAST)\"\n          by (simp add: e1 e2 b4 less_imp_le_nat)\n          \n        show False\n       apply(cut_tac a b1 e1 e2 e3 c1 c3, simp)\n       by (smt Divides.mod_less le_imp_less_Suc le_mod_geq mod_Suc nat.distinct(1) nat.inject neq0_conv not_less test5)\n     next\n      fix s\n      assume d1:\"i <LAST\" and d2:\"Suc 0 \\<le> i\"\n        show \"J LAST ''+'' [expEval (J LAST) (applyPlusN head i) s, index (Suc 0)] =\n         expEval (J LAST) (applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) i) s\"\n         by (simp add: applyIPlusIsPlusI)\n      next\n       fix s\n        assume  \n          a1:\"Suc 0 \\<le> i\" and\n          a2:\" scalar2Bool (J LAST ''le'' [s (Ident ''head''), index LAST])\" and \n          a4:\"expEval (J LAST) (caseExp (map (\\<lambda>ia. (eqn (applyPlusN head i) (Const (index ia)), IVar (Para mem ia))) (down LAST))) s =\n         index data\"\n          have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\" \n          using headIsIndex by auto\n          then obtain j where b1:\"((s (Ident ''head'') ) = (index j))\"\n          by blast\n          have b2:\"j\\<le> LAST\" \n          using  a2 b1 axiomOnLe  apply auto        done\n          (*have a0:\"s (Ident ''tail'') = s (Ident ''head'')\"*)\n          have b20:\"tautlogy (eqn (applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) (LAST - Suc 0)) \n                              (applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) (LAST - Suc 0))) (J LAST)\"\n                  apply(induct_tac LAST, auto) done\n          have b3:\"  \n          expEval (J LAST)\n          (substExp\n            (caseExp\n              (map (\\<lambda>ia. (eqn (applyPlusN head (i - Suc 0)) (Const (index ia)), IVar (Para mem ia))) (down LAST)))\n            [(Ident ''head'', uif ''+'' [head, Const (index (Suc 0))])])\n          s   =\n           expEval (J LAST)\n          (caseExp\n            (map (\\<lambda>ia. (eqn (applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) (i - Suc 0)) (Const (index ia)), IVar (Para mem ia)))\n            (down LAST))) s\" \n            using substCaseExp1 by auto\n\n         have c4:\" expEval (J LAST)\n          ((caseExp (map (\\<lambda>ia. (eqn (applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) (i - Suc 0)) (Const (index ia)), \n          IVar (Para mem ia))) (down LAST)))\n            )\n          s =\n         expEval (J LAST) (caseExp (map (\\<lambda>ia. (eqn (applyPlusN head i) (Const (index ia)), IVar (Para mem ia))) (down LAST))) s\"\n         proof(rule caseExpCong1,simp)\n            \n            \n            have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\" \n            using headIsIndex by auto\n            then obtain j where b1:\"((s (Ident ''head'') ) = (index j))\"\n              by blast\n            have b2:\"j\\<le> LAST\" \n            using  a2 b1 axiomOnLe  apply auto        done\n            show \"expEval (J LAST) (applyPlusN (uif ''+'' [head, Const (index (Suc 0))]) (i - Suc 0)) s\n            = expEval (J LAST) (applyPlusN head i) s\"\n            apply(cut_tac a b1 b2 b4 a1,auto)\n            done\n          qed\n         \n          show \"expEval (J LAST)\n          (substExp (caseExp (map (\\<lambda>ia. (eqn (applyPlusN head (i - Suc 0)) (Const (index ia)), IVar (Para mem ia))) (down LAST)))\n            [(Ident ''head'', uif ''+'' [head, Const (index (Suc 0))])])\n          s =\n         index data\"\n         by (simp add: a4 b3 c4)\n        \n      qed \n    }\n    ultimately have \"?P e\" by satx\n    }\n    moreover\n    {assume b1:\"e=Edge (Vertex 4) ( Vertex 1)\"\n     have \"?P e\"\n     proof(cut_tac a b1, simp add:antOfRbFifo_def Let_def,auto)\n     fix s\n     assume c2:\" scalar2Bool (J LAST ''le'' [s (Ident ''head''), index LAST])\"\n       have \"\\<exists>i. ((s (Ident ''head'') ) = (index i))\"\n            using headIsIndex by auto\n          then obtain j where e1:\"((s (Ident ''head'') ) = (index j))\"\n            by blast \n        have e2:\"j\\<le> LAST\"\n         using  c2 e1 axiomOnLe  apply auto        done \n        show \" scalar2Bool (J LAST ''le'' [J LAST ''+'' [s (Ident ''head''), index (Suc 0)], index LAST]) \"\n        apply(cut_tac e1 e2,auto) done\n     qed\n     }\nultimately show \"?P e\" by satx\nqed  \nlemma testAux[simp]:\n \nshows \"(expEval I e s =index i \\<longrightarrow>\ni \\<le> LAST\\<longrightarrow>expEval I (caseExp ((map (\\<lambda>i. (eqn e (Const (index i)), me i)) (down LAST)@S))) s \n=expEval  I  (me i) s) \\<and>\n(expEval I e s =index i \\<longrightarrow>\n LAST < i\\<longrightarrow>expEval I (caseExp ((map (\\<lambda>i. (eqn e (Const (index i)),me i)) (down LAST)@S))) s \n=expEval  I  (caseExp S) s)\"  (is \"?P LAST\")\nproof(induct_tac LAST,auto )qed \n\nlemma test[simp]:\nshows \"(expEval I e s =index i \\<longrightarrow>\ni \\<le> LAST\\<longrightarrow>expEval I (caseExp ((map (\\<lambda>i. (eqn e (Const (index i)), me i)) (down LAST)))) s \n=expEval  I  (me i) s)\"\nproof -\nhave a:\"(expEval I e s =index i \\<longrightarrow>\ni \\<le> LAST\\<longrightarrow>expEval I (caseExp ((map (\\<lambda>i. (eqn e (Const (index i)), me i)) (down LAST)@[]))) s \n=expEval  I  (me i) s)\"\napply(cut_tac testAux  [where I=\"I\" and S=\"[]\" and i=\"i\" and e=\"e\" and s=\"s\" and LAST=\"LAST\" and me=\"me\"]) \napply simp\ndone\nthen show ?thesis by auto\nqed\n\n \n\nlemma instImply:\nassumes a:\"G=(rbFifoGsteSpec LAST  data)\"   and c:\"tag=tagFunOfRingBufFifo  data LAST\"\nshows\n\"\\<forall> e. e \\<in>edgesOf G\\<longrightarrow> \ntautlogy (implyForm (andForm (antOf G e) (andListForm (tag (source e)))) (consOf G e)) I\"  \nproof(rule allI,rule impI,simp,rule allI,rule impI)\n  fix e s\n  assume a1:\"e \\<in> edgesOf G \" and a2:\"\n           formEval I (antOf G e) s \\<and> formEval I (andListForm (tag (source e))) s\" \n  let ?P =\"\\<lambda>e. formEval I (consOf G e) s\"           \n  have \"e=Edge vertexI ( Vertex 1) | \n          e=Edge  ( Vertex 1) ( Vertex 3) |\n          e=Edge  ( Vertex 1) ( Vertex 4)|\n           (\\<exists>i. 0\\<le>i \\<and> i\\<le> LAST+1 \\<and>  e=( Edge (Vertex ( 2*i+1 ))  (Vertex (  2*i+1 ))) )   |\n            (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST+1 \\<and>  e=( Edge (Vertex ( 2*i+2 ))  (Vertex (  2*i+2 ))) ) |\n            \n           (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST  \\<and> e=( Edge (Vertex (2 * i + 1))  (Vertex (2 * i + 3))) ) |\n           (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST  \\<and> e=( Edge (Vertex (2 * i + 1))  (Vertex (2 * i + 4))) )  |\n           \n           (\\<exists>i. 0\\<le>i \\<and> i\\<le> LAST  \\<and>  e= ( Edge (Vertex (2 * i + 3))  (Vertex (2 * i + 1))) ) |\n           (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST   \\<and> e=( Edge (Vertex(2 * i + 4))  (Vertex(2 *i+ 2))))|\n           e=Edge (Vertex 4) (Vertex 1)\"\n      apply(cut_tac a a1,auto)  done\n     \n   \n    moreover\n    {assume b1:\"e=Edge vertexI ( Vertex 1)\"\n     have \"?P e\"\n     apply(cut_tac a b1, simp add:antOfRbFifo_def) done\n     }\n    moreover\n    {assume b1:\" (\\<exists>i. 0\\<le>i \\<and> i\\<le> LAST +1  \\<and>  e=( Edge (Vertex (2* i + 1))  (Vertex (  2*i + 1))) )  \" (is \"\\<exists>i. ?asm i\")\n     from b1 obtain i where b2:\"?asm i\" by auto\n      have \"?P e\"\n       apply(cut_tac a  c a2 b2, auto) done\n    }\n    moreover\n    {assume b1:\" (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST+1  \\<and>  e=( Edge (Vertex (2* i + 2))  (Vertex (  2*i + 2))) )  \" (is \"\\<exists>i. ?asm i\")\n     from b1 obtain i where b2:\"?asm i\" by auto\n      have \"?P e\"\n       apply(cut_tac  a  c a2 b2,auto) done\n    }  \n     moreover\n    {assume b1:\" e=Edge  ( Vertex 1) ( Vertex 3) \"\n    \n       have \"?P e\"\n        apply(cut_tac a  c a2 b1,auto ) done\n    }\n    \n     moreover\n    {assume b1:\" e=Edge  ( Vertex 1) ( Vertex 4) \"\n      let ?f=\"andForm (neg (eqn rst HIGH)) (andForm (eqn push HIGH) (neg (eqn tail (Const (index LAST )))) ) \"\n     \n     \n       have \"?P e \"\n        apply(cut_tac a a1 a2 b1 ,auto simp add: antOfRbFifo_def assms) done\n    }\n    \n    moreover\n    {assume b1:\" \\<exists>i. 1\\<le>i \\<and> i\\<le> LAST \\<and> e=Edge  ( Vertex (2*i + 1)) ( Vertex (2*i + 3))\"     (is \"\\<exists>i. ?Q i\")\n      from b1 obtain i where b1:\"?Q i\" by blast\n      have \"?P e \"\n        by(cut_tac  a  c a2 b1 ,auto simp add: antOfRbFifo_def assms )\n     }\n    \n    moreover\n    {assume b1:\" \\<exists>i. 1\\<le>i \\<and> i\\<le> LAST \\<and> e=Edge  ( Vertex (2*i + 1)) ( Vertex (2*i+4))    \"(is \"\\<exists>i. ?Q i\")\n      from b1 obtain i where b1:\"?Q i\" by blast\n      have \"?P e \"\n        by(cut_tac a b1 a1 a2,auto simp add: antOfRbFifo_def assms)\n     } \n    \n     moreover\n    {assume b1:\"\\<exists>i. 0\\<le>i \\<and> i\\<le> LAST \\<and>  e=Edge  ( Vertex (2*i + 3)) ( Vertex (2*i + 1))   \" (is \"\\<exists>i. ?Q i\")\n       from b1 obtain i where b1:\"?Q i\" by blast\n       have \"?P e \"\n        by(cut_tac   a  c a2 b1 ,auto simp add:Let_def antOfRbFifo_def assms )\n     }\n    \n     moreover\n    {assume b1:\"\\<exists>i.  1\\<le>i \\<and> i\\<le> LAST \\<and> e=Edge  ( Vertex (2*i + 4)) ( Vertex (2*i +2))   \" (is \"\\<exists>i. ?Q i\")\n      from b1 obtain i where b1:\"?Q i\" by blast\n      have \"?P e \"\n         by(cut_tac  a   a2 b1 ,auto simp add: Let_def antOfRbFifo_def assms)\n       \n     }\n    moreover\n    {assume b1:\"e=Edge (Vertex 4) ( Vertex 1)\"\n     have \"?P e\"\n     apply(cut_tac  a  c a2 b1 ,case_tac \"LAST=0\",auto  simp add: Let_def antOfRbFifo_def assms) done\n     }\n    ultimately show \"?P e\" by satx\n  qed      \n\nlemma main: \nassumes a:\"G=(rbFifoGsteSpec LAST  data)\" \nand c:\"tag=tagFunOfRingBufFifo  data LAST\" and\nd:\"M=(ringBuffifo  LAST )\"\nshows \" circuitSatGsteSpec M G (J LAST) \"  \nproof(rule mainLemma)\nhave a1:\"consistent' (ringBuffifo LAST ) (J LAST) (rbFifoGsteSpec LAST  data) (tagFunOfRingBufFifo  data LAST)\" \n   apply (case_tac \"LAST=0\",rule consistencyOfRbfifo0,simp)\n   apply(rule   consistencyOfRbfifo,arith) done\nfrom a c d this show \"consistent' M   (J LAST) G tag\"\n  by simp   \nnext\nfrom a  c show \"\\<forall>e. e \\<in> edgesOf G \\<longrightarrow>\n        tautlogy (implyForm (andForm (antOf G e) (andListForm (tag (source e)))) (consOf G e)) (J LAST)\"\napply(rule instImply) done\nnext\nfrom a c show \"tag (initOf G) = []\"\napply auto done\nqed\nend\n", "meta": {"author": "lyj238Gmail", "repo": "gsteProof", "sha": "3070d08e1f31a93be6fde85ab6b65d489c05f99e", "save_path": "github-repos/isabelle/lyj238Gmail-gsteProof", "path": "github-repos/isabelle/lyj238Gmail-gsteProof/gsteProof-3070d08e1f31a93be6fde85ab6b65d489c05f99e/ringBufFifoModi.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5851011542032312, "lm_q2_score": 0.4882833952958347, "lm_q1q2_score": 0.2856951781658655}}
{"text": "section \\<open> RoboChart Meta-Model \\<close>\n\ntheory MetaModel\n  imports Actions\nbegin\n\nsubsection \\<open> State Machine Syntax \\<close>\n\ntext \\<open> All state machine statespace types extend the following type which provides a state control variable \\<close>\n\ntype_synonym ID = String.literal\n\nalphabet robochart_ctrl =\n  rc_ctrl :: ID \n\ntype_synonym 's rcst = \"'s robochart_ctrl_scheme\"\ntype_synonym ('s, 'e) RoboAction = \"('s robochart_ctrl_scheme, 'e) Actions.Action\"\ntype_synonym 's RoboPred = \"'s robochart_ctrl_scheme upred\"\n\ntranslations\n  (type) \"'s rcst\" <= (type) \"'s robochart_ctrl_scheme\"\n  (type) \"('s, 'e) RoboAction\" <= (type) \"('s rcst, 'e) Action\"\n  (type) \"'s RoboPred\" <= (type) \"'s rcst upred\"\n\nabbreviation \"rc_state \\<equiv> robochart_ctrl.more\\<^sub>L\"\n\nnotation rc_state (\"\\<^bold>r\")\n\nsyntax\n  \"_svid_rc_state\"  :: \"svid\" (\"\\<^bold>r\")\n\ntranslations\n  \"_svid_rc_state\" == \"CONST rc_state\"\n  \"_svid_dot \\<^bold>r x\" <= \"x ;\\<^sub>L \\<^bold>r\"\n\nrecord ('s, 'e) Transition = \n  tn_source    :: ID\n  tn_target    :: ID\n  tn_trigger   :: \"('s, 'e) Actions.Action option\"\n  tn_condition :: \"'s upred\"\n  tn_action    :: \"('s, 'e) Actions.Action\"\n\ndeclare Transition.defs [simp]\n\nrecord ('s, 'e) Node =\n  n_name   :: \"ID\"\n  n_entry  :: \"('s, 'e) Action\"\n  n_during :: \"('s, 'e) Action\"\n  n_exit   :: \"('s, 'e) Action\"\n\ndeclare Node.defs [simp]\n\nrecord ('s, 'e) StateMachine =\n  sm_initial     :: \"String.literal\" (\"init\\<index>\")\n  sm_finals      :: \"String.literal list\" (\"finals\\<index>\")\n  sm_nodes       :: \"('s, 'e) Node list\" (\"nodes\\<index>\")\n  sm_transitions :: \"('s, 'e) Transition list\" (\"\\<^bold>T\\<index>\")\n\ndeclare StateMachine.defs [simp]\n\nthm set_map\n\ndefinition sm_node_names :: \"('s, 'e) StateMachine \\<Rightarrow> String.literal set\" (\"nnames\\<index>\") where\n\"sm_node_names sm \\<equiv> n_name ` set(sm_nodes sm)\"\n\ndefinition sm_inters :: \"('s, 'e) StateMachine \\<Rightarrow> ('s, 'e) Node list\" where\n\"sm_inters sm = filter (\\<lambda> n. n_name n \\<notin> set(sm_finals sm)) (sm_nodes sm)\"\n\ndefinition sm_inter_names (\"inames\\<index>\") where\n\"sm_inter_names sm \\<equiv> n_name ` set (sm_inters sm)\"\n\nabbreviation sm_final_names (\"fnames\\<index>\") where\n\"sm_final_names M \\<equiv> set (finals\\<^bsub>M\\<^esub>)\"\n\ndefinition sm_node_map :: \"('s, 'e) StateMachine \\<Rightarrow> (ID \\<rightharpoonup> ('s, 'e) Node)\" (\"nmap\\<index>\") where\n\"sm_node_map M = map_of (map (\\<lambda> n. (n_name n, n)) (sm_nodes M))\"\n\ndefinition sm_trans_map :: \"('s, 'e) StateMachine \\<Rightarrow> (ID \\<rightharpoonup> ('s, 'e) Transition list)\" (\"tmap\\<index>\") where\n\"sm_trans_map M = map_of (map (\\<lambda> n. (n_name n, filter (\\<lambda> t. tn_source t = n_name n) (sm_transitions M))) (sm_nodes M))\"\n\nlemma dom_sm_node_map: \"dom(nmap\\<^bsub>M\\<^esub>) = nnames\\<^bsub>M\\<^esub>\"\n  using image_iff by (force simp add: sm_node_map_def sm_node_names_def dom_map_of_conv_image_fst)\n\nlemma dom_sm_trans_map: \"dom(tmap\\<^bsub>M\\<^esub>) = nnames\\<^bsub>M\\<^esub>\"\n  using image_iff by (force simp add: sm_trans_map_def sm_node_names_def dom_map_of_conv_image_fst)\n\nlemma nnames_finite: \"finite(nnames\\<^bsub>M\\<^esub>)\"\n  by (force simp add: sm_node_names_def)\n\nabbreviation sm_init_node :: \"('s, 'e) StateMachine \\<Rightarrow> ('s, 'e) Node\" (\"ninit\\<index>\") where\n\"sm_init_node M \\<equiv> the (sm_node_map M (sm_initial M))\"\n\nsubsection \\<open> Well-Formedness \\<close>\n\nlocale WfStateMachine =\n  fixes M :: \"('s, 'm) StateMachine\" (structure)\n  \\<comment> \\<open> The list of nnames is a set \\<close>\n  assumes nnames_distinct: \"distinct (map n_name (nodes\\<^bsub>M\\<^esub>))\"\n  and init_is_state: \"init \\<in> nnames\"\n  and init_not_final: \"init \\<notin> fnames\"\n  and trans_wf: \" \\<And> t. t \\<in> set(\\<^bold>T) \\<Longrightarrow> tn_source t \\<in> inames \\<and> tn_target t \\<in> nnames\"\nbegin\n  lemma init_is_inter: \"init \\<in> inames\"\n    using init_is_state init_not_final by (auto simp add: sm_inters_def sm_inter_names_def sm_node_names_def)\n\n  lemma nmap_init: \"nmap init = Some ninit\"\n    by (metis domIff dom_sm_node_map init_is_state option.exhaust_sel)\n\n  lemma n_name_init: \"n_name ninit = init\"\n  proof (simp add: sm_node_map_def)\n    have \"map_of (map (\\<lambda>n. (n_name n, n)) (sm_nodes M)) init = Some (the (map_of (map (\\<lambda>n. (n_name n, n)) (sm_nodes M)) init))\"\n      by (metis (no_types) nmap_init sm_node_map_def)\n    then show \"n_name (the (map_of (map (\\<lambda>n. (n_name n, n)) (sm_nodes M)) init)) = init\"\n      using map_of_SomeD by force\n  qed\n\n  lemma nmap_name:\n    assumes \"n \\<in> set(sm_nodes M)\"\n    shows \"nmap (n_name n) = Some n\"\n  proof -\n    have \"distinct (map fst (map (\\<lambda>n. (n_name n, n)) (sm_nodes M)))\"\n      by (simp add: comp_def nnames_distinct)\n    with assms show ?thesis\n      by (simp add: sm_node_map_def)\n  qed\n\n  lemma ninit_is_node: \"ninit \\<in> set(sm_nodes M)\"\n    using init_is_state nmap_name by (auto simp add: sm_node_names_def)\n\n  lemma tmap_node_in_trans: \n    assumes \"n \\<in> nnames\" \"ts \\<in> ran(tmap)\"\n    shows \"set(ts) \\<subseteq> set(\\<^bold>T)\"\n    using assms by (auto simp add: sm_trans_map_def ran_distinct nnames_distinct comp_def)\n\n  lemma node_tran_exists:\n    assumes \"n \\<in> nnames\" \"t \\<in> set(the(tmap n))\"\n    shows \"t \\<in> set(\\<^bold>T)\"\n    by (metis (mono_tags, hide_lams) assms(1) assms(2) domIff dom_sm_trans_map in_mono init_is_state option.collapse ranI tmap_node_in_trans)\n\nend\n\nmethod check_machine uses defs = \n  (unfold_locales, \n   simp_all add: defs sm_node_names_def sm_inter_names_def sm_inters_def, safe, simp_all)\n\nsubsection \\<open> State Machine Semantics \\<close>\n\nabbreviation \"trigger_semantics t null_event \\<equiv> \n  (case tn_trigger t of Some e \\<Rightarrow> if productive e then e else sync null_event | None \\<Rightarrow> sync null_event)\"\n\nno_utp_lift tn_condition\n\ndefinition tr_semantics :: \"('s, 'e) Transition \\<Rightarrow> (unit, 'e) chan \\<Rightarrow> ('s, 'e) RoboAction\" (\"\\<lbrakk>_\\<rbrakk>\\<^sub>T\") where\n\"tr_semantics t null_event \\<equiv> \n  tn_condition t \\<oplus>\\<^sub>p rc_state \\<^bold>& \n  rc_state:[trigger_semantics t null_event ; tn_action t]\\<^sub>A\\<^sup>+ ; rc_ctrl := \\<guillemotleft>tn_target t\\<guillemotright>\"\n\ndefinition node_semantics :: \n  \"('s, 'e) StateMachine \\<Rightarrow> (unit, 'e) chan \\<Rightarrow> ('s, 'e) Node \\<Rightarrow> ('s, 'e) RoboAction\" (\"_;_ \\<turnstile> \\<lbrakk>_\\<rbrakk>\\<^sub>N\" [10,0,0] 10) where\n  \"node_semantics M null_event node  = \n  (rc_state:[n_entry node]\\<^sub>A\\<^sup>+ ;\n   (foldr (\\<box>) (map (\\<lambda> t. \\<lbrakk>t\\<rbrakk>\\<^sub>T null_event) (the (tmap\\<^bsub>M\\<^esub> (n_name node)))) stop) ;\n   rc_state:[n_exit node]\\<^sub>A\\<^sup>+)\"\n\ndefinition sm_semantics :: \"('s, 'e) StateMachine \\<Rightarrow> (unit, 'e) chan \\<Rightarrow> ('s, 'e) RoboAction\" (\"\\<lbrakk>_\\<rbrakk>\\<^sub>M\") where\n\"sm_semantics M null_event = \n    (rc_ctrl := \\<guillemotleft>sm_initial M\\<guillemotright> ;\n    iteration (map (\\<lambda> n. (&rc_ctrl =\\<^sub>u \\<guillemotleft>n_name n\\<guillemotright>, M;null_event \\<turnstile> \\<lbrakk>n\\<rbrakk>\\<^sub>N)) (sm_inters M)))\"\n\nlemmas sm_sem_def = sm_semantics_def node_semantics_def sm_inters_def sm_inter_names_def\n\nlemma tr_semantics_subst_ctrl: \"[&rc_ctrl \\<mapsto>\\<^sub>s \\<guillemotleft>k\\<guillemotright>] \\<dagger> (\\<lbrakk>a\\<rbrakk>\\<^sub>T null_event) = \\<lbrakk>a\\<rbrakk>\\<^sub>T null_event\"\n  by (simp add: tr_semantics_def action_simp usubst unrest frame_asubst)\n\nlemma tr_choice_subst_ctrl:\n  \"[&rc_ctrl \\<mapsto>\\<^sub>s \\<guillemotleft>k\\<guillemotright>] \\<dagger> foldr (\\<box>) (map (\\<lambda>t. \\<lbrakk>t\\<rbrakk>\\<^sub>T null_event) ts) stop = foldr (\\<box>) (map (\\<lambda>t. \\<lbrakk>t\\<rbrakk>\\<^sub>T null_event) ts) stop\"\n  by (induct ts, simp_all add: action_simp usubst tr_semantics_subst_ctrl)\n\nlemma sm_semantics_subst_ctrl:\n  \"[&rc_ctrl \\<mapsto>\\<^sub>s \\<guillemotleft>k\\<guillemotright>] \\<dagger> node_semantics M null_event node = node_semantics M null_event node\"\n  by (simp add: node_semantics_def action_simp frame_asubst tr_choice_subst_ctrl unrest)\n\nsubsection \\<open> Theorems \\<close>\n\nlemma productive_tr_semantics [closure]: \"productive (\\<lbrakk>t\\<rbrakk>\\<^sub>T null_event)\"\n  by (cases \"tn_trigger t\", auto simp add: tr_semantics_def action_rep_eq closure unrest)\n\nlemma productive_node_semantics:\n  \"productive (M;null_event \\<turnstile> \\<lbrakk>node\\<rbrakk>\\<^sub>N)\"\nproof -\n  have \"\\<And> ts. productive (foldr (\\<box>) (map (\\<lambda> t. \\<lbrakk>t\\<rbrakk>\\<^sub>T null_event) ts) stop)\"\n    by (rename_tac ts, induct_tac ts, auto simp add: action_rep_eq closure, simp add: closure productive_Productive)\n  hence \"productive (foldr (\\<box>) (map (\\<lambda> t. \\<lbrakk>t\\<rbrakk>\\<^sub>T null_event) (the (tmap\\<^bsub>M\\<^esub> (n_name node)))) stop)\"\n    by blast\n  thus ?thesis\n    by (simp add: action_rep_eq closure node_semantics_def)\nqed\n\nlemma Sup_Collect_as_UINF:\n  \"\\<Sqinter> {P x | x. x \\<in> A} = (\\<Sqinter> x \\<in> A \\<bullet> P x)\"\n  apply (simp add: UINF_as_Sup[THEN sym], rel_simp)\n  apply (rule cong[of Sup Sup])\n   apply (auto)\n  done\n  \n\nlemma Sup_Collect_2_as_UINF:\n  \"\\<Sqinter> {P x y | x y. (x, y) \\<in> A} = (\\<Sqinter> (x, y) \\<in> A \\<bullet> P x y)\"\n  apply (simp add: UINF_as_Sup[THEN sym], rel_simp)\n  apply (rule cong[of Sup Sup])\n   apply (auto)\n  done\n\nlemma UINF_Collect: \"(\\<Sqinter> b \\<in> {F(x)| x . x \\<in> A} \\<bullet> b) = (\\<Sqinter> x \\<in> A \\<bullet> F(x))\"\n  by (simp add: Sup_Collect_as_UINF UINF_as_Sup)\n\nlemma ueq_literlise [lit_simps]: \n  \"(\\<guillemotleft>x = y\\<guillemotright>) = (\\<guillemotleft>x\\<guillemotright> =\\<^sub>u \\<guillemotleft>y\\<guillemotright>)\"\n  by (rel_auto)\n\nlemma seq_refine_mono:\n  fixes P\\<^sub>1 P\\<^sub>2 Q\\<^sub>1 Q\\<^sub>2 :: \"('s, 'e) Action\"\n  assumes \"P\\<^sub>1 \\<sqsubseteq> Q\\<^sub>1\" \"P\\<^sub>2 \\<sqsubseteq> Q\\<^sub>2\"\n  shows \"P\\<^sub>1 ; P\\<^sub>2 \\<sqsubseteq> Q\\<^sub>1 ; Q\\<^sub>2\"\n  using assms\n  by (simp add: action_rep_eq seqr_mono)\n\nlemma StateMachine_refine_intro:\n  fixes \n    S :: \"('s, 'e) RoboAction\" and\n    M :: \"('s, 'e) StateMachine\"\n  assumes \n    \"WfStateMachine M\"\n    \"S \\<sqsubseteq> (M;null_event \\<turnstile> \\<lbrakk>ninit\\<^bsub>M\\<^esub>\\<rbrakk>\\<^sub>N)\"\n    \"\\<And> n. n \\<in> inames\\<^bsub>M\\<^esub> \\<Longrightarrow> S \\<sqsubseteq> S ; (M;null_event \\<turnstile> \\<lbrakk>the(nmap\\<^bsub>M\\<^esub> n)\\<rbrakk>\\<^sub>N)\"\n  shows \"S \\<sqsubseteq> \\<lbrakk>M\\<rbrakk>\\<^sub>M null_event\"\nproof -\n  interpret wf: WfStateMachine M\n    by (simp add: assms)\n  have 1: \"\\<And>n. n \\<in> set(sm_inters M) \\<Longrightarrow> productive (M;null_event \\<turnstile> \\<lbrakk>n\\<rbrakk>\\<^sub>N)\"\n    by (simp add: productive_node_semantics)\n  have 2: \"S \\<sqsubseteq> rc_ctrl := \\<guillemotleft>init\\<^bsub>M\\<^esub>\\<guillemotright> ; [\\<not> (\\<Sqinter> (b, P) \\<in> (\\<lambda>n. (&rc_ctrl =\\<^sub>u \\<guillemotleft>n_name n\\<guillemotright>, M;null_event \\<turnstile> \\<lbrakk>n\\<rbrakk>\\<^sub>N)) ` set(sm_inters M) \\<bullet> b)]\\<^sub>A\"\n  proof -\n    have a:\"(\\<lambda> n. (&rc_ctrl =\\<^sub>u \\<guillemotleft>n_name n\\<guillemotright> :: 's RoboPred, M;null_event \\<turnstile> \\<lbrakk>n\\<rbrakk>\\<^sub>N)) ` set(sm_inters M) =\n             {(&rc_ctrl =\\<^sub>u \\<guillemotleft>n_name n\\<guillemotright>, M;null_event \\<turnstile> \\<lbrakk>n\\<rbrakk>\\<^sub>N)| n . n \\<in> set(sm_inters M)}\"\n      by (auto)\n    have b: \"(\\<guillemotleft>init\\<^bsub>M\\<^esub>\\<guillemotright> \\<notin>\\<^sub>u \\<guillemotleft>inames\\<^bsub>M\\<^esub>\\<guillemotright>) = false\"\n      by (literalise, metis (full_types) false_alt_def true_alt_def utp_pred_laws.compl_top_eq wf.init_is_inter)\n    have \"(\\<Sqinter> (b, P) \\<in> (\\<lambda>n. (&rc_ctrl =\\<^sub>u \\<guillemotleft>n_name n\\<guillemotright> :: 's RoboPred, M;null_event \\<turnstile> \\<lbrakk>n\\<rbrakk>\\<^sub>N)) ` set(sm_inters M) \\<bullet> b) =\n           (\\<Sqinter> (b, P) \\<in> {(&rc_ctrl =\\<^sub>u \\<guillemotleft>n_name n\\<guillemotright>, M;null_event \\<turnstile> \\<lbrakk>n\\<rbrakk>\\<^sub>N)| n . n \\<in> set(sm_inters M)} \\<bullet> b)\"\n      by (simp add: a)\n    also have \"...  = (\\<Sqinter> b \\<in> {&rc_ctrl =\\<^sub>u \\<guillemotleft>n_name n\\<guillemotright>| n . n \\<in> set(sm_inters M)} \\<bullet> b)\"\n      by (rel_auto)      \n    also have \"... = (&rc_ctrl \\<in>\\<^sub>u \\<guillemotleft>inames\\<^bsub>M\\<^esub>\\<guillemotright>)\"\n      apply (simp add: UINF_Collect, rel_auto)\n      apply (simp add: sm_inter_names_def sm_sem_def(3))\n      using sm_inter_names_def apply fastforce\n      done\n    finally show ?thesis\n      by (simp add: action_simp usubst b miracle_top)\n  qed\n  have 3: \"S \\<sqsubseteq> rc_ctrl := \\<guillemotleft>init\\<^bsub>M\\<^esub>\\<guillemotright> ; [\\<not> (&rc_ctrl \\<in>\\<^sub>u \\<guillemotleft>inames\\<^bsub>M\\<^esub>\\<guillemotright>)]\\<^sub>A\" (is \"?lhs \\<sqsubseteq> ?rhs\")\n  proof -\n    have \"?rhs = [\\<guillemotleft>init\\<^bsub>M\\<^esub>\\<guillemotright> \\<notin>\\<^sub>u \\<guillemotleft>inames\\<^bsub>M\\<^esub>\\<guillemotright>]\\<^sub>A ; rc_ctrl := \\<guillemotleft>init\\<^bsub>M\\<^esub>\\<guillemotright>\"\n      by (simp add: action_simp usubst)\n    also have \"... = [false]\\<^sub>A ; rc_ctrl := \\<guillemotleft>init\\<^bsub>M\\<^esub>\\<guillemotright>\"\n      by (literalise, simp add: wf.init_is_inter)\n    also have \"... = miracle\"\n      by (simp add: action_simp)\n    finally\n    show ?thesis by (simp add: miracle_top)\n  qed\n  have 4:\"\\<And>n. n \\<in> set(sm_inters M) \\<Longrightarrow> S \\<sqsubseteq> rc_ctrl := \\<guillemotleft>init\\<^bsub>M\\<^esub>\\<guillemotright> ; [&rc_ctrl =\\<^sub>u \\<guillemotleft>n_name n\\<guillemotright>]\\<^sub>A ; (M;null_event \\<turnstile> \\<lbrakk>n\\<rbrakk>\\<^sub>N)\"\n  proof -\n    fix n\n    assume a:\"n \\<in> set(sm_inters M)\"\n    show \"S \\<sqsubseteq> rc_ctrl := \\<guillemotleft>init\\<^bsub>M\\<^esub>\\<guillemotright> ; [&rc_ctrl =\\<^sub>u \\<guillemotleft>n_name n\\<guillemotright>]\\<^sub>A ; (M;null_event \\<turnstile> \\<lbrakk>n\\<rbrakk>\\<^sub>N)\"\n    proof (cases \"n=ninit\\<^bsub>M\\<^esub>\")\n      case True\n      hence \"[&rc_ctrl \\<mapsto>\\<^sub>s \\<guillemotleft>init\\<^bsub>M\\<^esub>\\<guillemotright>] \\<dagger> (M;null_event \\<turnstile> \\<lbrakk>ninit\\<^bsub>M\\<^esub>\\<rbrakk>\\<^sub>N) = (M;null_event \\<turnstile> \\<lbrakk>ninit\\<^bsub>M\\<^esub>\\<rbrakk>\\<^sub>N)\"\n        by (simp add: sm_semantics_subst_ctrl)\n      with True assms(2) show ?thesis\n        by (simp add: action_simp usubst wf.n_name_init)\n    next\n      case False\n      with a have \"(init\\<^bsub>M\\<^esub> = n_name n) = False\"\n      proof -\n        have \"n \\<in> {n. n \\<in> set(sm_nodes M) \\<and> \\<not> n_name n \\<in> set(finals\\<^bsub>M\\<^esub>)}\"\n          by (metis a set_filter sm_sem_def(3))\n        then have \"nmap\\<^bsub>M\\<^esub> (n_name n) = Some n\"\n          using WfStateMachine.nmap_name wf.WfStateMachine_axioms by blast\n        then show ?thesis\n          using False by fastforce\n      qed\n      hence \"((\\<guillemotleft>init\\<^bsub>M\\<^esub>\\<guillemotright> =\\<^sub>u \\<guillemotleft>n_name n\\<guillemotright>) :: 's RoboPred) = false\"\n        by (rel_auto)\n      thus ?thesis\n        by (simp add: action_simp usubst miracle_top)\n    qed\n  qed\n  have 5: \"\\<And>n. n \\<in> set(sm_inters M) \\<Longrightarrow> S \\<sqsubseteq> S ; [&rc_ctrl =\\<^sub>u \\<guillemotleft>n_name n\\<guillemotright>]\\<^sub>A ; (M;null_event \\<turnstile> \\<lbrakk>n\\<rbrakk>\\<^sub>N)\"\n  proof -\n    fix n\n    assume a:\"n \\<in> set(sm_inters M)\"\n    have \"S \\<sqsubseteq> S ; (M;null_event \\<turnstile> \\<lbrakk>n\\<rbrakk>\\<^sub>N)\"\n    proof -\n      have f1: \"{n. (n::('s, 'e) Node) \\<in> set(sm_nodes M) \\<and> \\<not> n_name n \\<in> set(finals\\<^bsub>M\\<^esub>)} = set(sm_inters M)\"\n        by (simp add: sm_sem_def(3))\n      then have \"n_name n \\<in> n_name ` {n. (n::('s, 'e) Node) \\<in> set(sm_nodes M) \\<and> \\<not> n_name n \\<in> set(finals\\<^bsub>M\\<^esub>)}\"\n        using a by force\n      then have \"n_name n \\<in> inames\\<^bsub>M\\<^esub>\"\n        by (simp add: sm_inter_names_def sm_sem_def(3))\n      then show ?thesis\n        using f1 a assms(3) wf.nmap_name by fastforce\n    qed\n    moreover have \"S ; (M;null_event \\<turnstile> \\<lbrakk>n\\<rbrakk>\\<^sub>N) \\<sqsubseteq> S ; [&rc_ctrl =\\<^sub>u \\<guillemotleft>n_name n\\<guillemotright>]\\<^sub>A ; (M;null_event \\<turnstile> \\<lbrakk>n\\<rbrakk>\\<^sub>N)\"\n      by (rule seq_refine_mono, simp_all add: asm_pre_refine)\n    ultimately show \"S \\<sqsubseteq> S ; [&rc_ctrl =\\<^sub>u \\<guillemotleft>n_name n\\<guillemotright>]\\<^sub>A ; (M;null_event \\<turnstile> \\<lbrakk>n\\<rbrakk>\\<^sub>N)\"\n      using dual_order.trans by blast\n  qed\n\n  show ?thesis\n    apply (simp add: sm_semantics_def)\n    apply (rule iterate_refine_intro)\n    apply (simp_all)\n    apply (auto simp add: 1 2 3 4 5)\n    done\nqed\n(*\nlemma StateMachine_sinv_refine_intro:\n  fixes \n    S :: \"('s, 'e) RoboAction\" and\n    M :: \"('s, 'e) StateMachine\"\n  assumes \n    \"WfStateMachine M\"\n    \"sinv\\<^sub>A(s) \\<sqsubseteq> (M;null_event \\<turnstile> \\<lbrakk>ninit\\<^bsub>M\\<^esub>\\<rbrakk>\\<^sub>N)\"\n    \"\\<And> n. n \\<in> inames\\<^bsub>M\\<^esub> \\<Longrightarrow> S \\<sqsubseteq> S ; (M;null_event \\<turnstile> \\<lbrakk>the(nmap\\<^bsub>M\\<^esub> n)\\<rbrakk>\\<^sub>N)\"\n  shows \"S \\<sqsubseteq> \\<lbrakk>M\\<rbrakk>\\<^sub>M null_event\"\n*)\n\n(*\nlemma \"sinv\\<^sub>A (&rc_ctrl \\<in>\\<^sub>u \\<guillemotleft>nnames\\<^bsub>M\\<^esub>\\<guillemotright>) \\<sqsubseteq> r:[P]\\<^sub>A\\<^sup>+\"\n  apply (simp add: action_rep_eq, safe)\n   apply (rdes_refine_split)\n  apply (rel_simp)\n\nlemma \n  assumes \"WfStateMachine M\"\n  shows \"sinv\\<^sub>A(&rc_ctrl \\<in>\\<^sub>u \\<guillemotleft>nnames\\<^bsub>M\\<^esub>\\<guillemotright>) \\<sqsubseteq> \\<lbrakk>M\\<rbrakk>\\<^sub>M null_event\"\nproof (rule StateMachine_refine_intro[OF assms])\n  show \"sinv\\<^sub>A(&rc_ctrl \\<in>\\<^sub>u \\<guillemotleft>nnames\\<^bsub>M\\<^esub>\\<guillemotright>) \\<sqsubseteq> (M;null_event \\<turnstile> \\<lbrakk>ninit\\<^bsub>M\\<^esub>\\<rbrakk>\\<^sub>N)\"\n    apply (simp add: node_semantics_def)\n*)\n\nsubsection \\<open> Divergence Freedom \\<close>\n\nlocale DivFreeSM = WfStateMachine +\n  assumes \n    n_entry_divf: \"\\<And> n. n \\<in> set(nodes) \\<Longrightarrow> divf \\<sqsubseteq> n_entry n\" and\n    n_during_divf: \"\\<And> n. n \\<in> set(nodes) \\<Longrightarrow> divf \\<sqsubseteq> n_exit n\" and\n    n_exit_divf: \"\\<And> n. n \\<in> set(nodes) \\<Longrightarrow> divf \\<sqsubseteq> n_exit n\" and\n    tn_trigger_divf: \"\\<And> t e. \\<lbrakk> t \\<in> set(\\<^bold>T); tn_trigger t = Some e \\<rbrakk> \\<Longrightarrow> divf \\<sqsubseteq> e\" and\n    tn_action_divf: \"\\<And> t. t \\<in> set(\\<^bold>T) \\<Longrightarrow> divf \\<sqsubseteq> tn_action t\"\n\nlemma DivFreeSM_divf:\n  assumes \"DivFreeSM M\"\n  shows \"divf \\<sqsubseteq> \\<lbrakk>M\\<rbrakk>\\<^sub>M \\<epsilon>\"\nproof (rule StateMachine_refine_intro)\n  interpret dvs: DivFreeSM M\n    by (simp add: assms)\n  show \"WfStateMachine M\"\n    by (simp add: dvs.WfStateMachine_axioms)\n  have \"\\<And> n t. \\<lbrakk> n \\<in> nnames\\<^bsub>M\\<^esub>; t \\<in> set(the (tmap\\<^bsub>M\\<^esub> n)) \\<rbrakk> \\<Longrightarrow> divf \\<sqsubseteq> \\<lbrakk>t\\<rbrakk>\\<^sub>T \\<epsilon>\"  \n  proof -\n    fix n t\n    assume a: \"n \\<in> nnames\\<^bsub>M\\<^esub>\" \"t \\<in> set(the (tmap\\<^bsub>M\\<^esub> n))\"\n    have \"divf \\<sqsubseteq> trigger_semantics t \\<epsilon>\"\n    proof (cases \"tn_trigger t\")\n      case None\n      then show ?thesis by (simp add: divf_sync)\n    next\n      case (Some a)\n      then show ?thesis\n        using a(1) a(2) divf_sync dvs.node_tran_exists dvs.tn_trigger_divf by fastforce\n    qed\n    thus \"divf \\<sqsubseteq> \\<lbrakk>t\\<rbrakk>\\<^sub>T \\<epsilon>\"\n      apply (simp add: tr_semantics_def)\n      apply (rule divf_guard)\n      apply (rule divf_seq_refine)\n       apply (rule divf_seq_refine)\n        apply (rule divf_frame_ext)\n        apply (simp)\n       apply (rule divf_frame_ext)\n      using a(1) a(2) dvs.node_tran_exists dvs.tn_action_divf apply blast\n      apply (simp add: divf_assigns)\n      done\n  qed\n  hence b:\"\\<And> n. n \\<in> inames\\<^bsub>M\\<^esub> \\<Longrightarrow> divf \\<sqsubseteq> (M;\\<epsilon> \\<turnstile> \\<lbrakk>the (nmap\\<^bsub>M\\<^esub> n)\\<rbrakk>\\<^sub>N)\"\n    apply (simp add: node_semantics_def)\n    apply (rule divf_seq_refine)\n    apply (rule divf_frame_ext)\n    apply (smt dvs.n_entry_divf dvs.nmap_name filter_is_subset imageE option.sel sm_inter_names_def sm_inters_def subset_eq)\n    apply (rule divf_seq_refine)\n     apply (rule divf_extchoice_fold_refine)\n    apply (auto)\n    apply (smt dvs.nmap_name filter_is_subset image_iff option.sel sm_inter_names_def sm_inters_def sm_node_names_def subset_code(1))\n    apply (rule divf_frame_ext)\n    apply (smt dvs.n_exit_divf dvs.nmap_name filter_is_subset imageE option.sel sm_inter_names_def sm_inters_def subset_eq)\n    done\n  show \"divf \\<sqsubseteq> (M;\\<epsilon> \\<turnstile> \\<lbrakk>ninit\\<^bsub>M\\<^esub>\\<rbrakk>\\<^sub>N)\"\n    by (simp add: b dvs.init_is_inter)\n  show \"\\<And>n. n \\<in> inames\\<^bsub>M\\<^esub> \\<Longrightarrow> divf \\<sqsubseteq> divf ; (M;\\<epsilon> \\<turnstile> \\<lbrakk>the (nmap\\<^bsub>M\\<^esub> n)\\<rbrakk>\\<^sub>N)\"\n    by (simp add: b divf_seq_refine)\nqed\n\nsubsection \\<open> Transition and State Parsers \\<close>\n\nsyntax\n  \"_transition\" :: \"id \\<Rightarrow> id \\<Rightarrow> raction \\<Rightarrow> logic \\<Rightarrow> raction \\<Rightarrow> logic\"\n  (\"from _ to _ trigger _ condition _ action _\" [0,0,0,0,10] 10)\n\n  \"_transition_action\" :: \"id \\<Rightarrow> id \\<Rightarrow> logic \\<Rightarrow> logic\"\n  (\"from _ to _ action _\" [0,0,10] 10)\n\n  \"_transition_condition\" :: \"id \\<Rightarrow> id \\<Rightarrow> logic \\<Rightarrow> logic\"\n  (\"from _ to _ condition _\" [0,0,10] 10)\n\n  \"_transition_condition_action\" :: \"id \\<Rightarrow> id \\<Rightarrow> logic \\<Rightarrow> raction \\<Rightarrow> logic\"\n  (\"from _ to _ condition _ action _\" [0,0,0,10] 10)\n\n  \"_transition_trigger\" :: \"id \\<Rightarrow> id \\<Rightarrow> raction \\<Rightarrow> logic\"\n  (\"from _ to _ trigger _\" [0,0,10] 10)\n\n  \"_transition_trigger_action\" :: \"id \\<Rightarrow> id \\<Rightarrow> raction \\<Rightarrow> raction \\<Rightarrow> logic\"\n  (\"from _ to _ trigger _ action _\" [0,0,0,10] 10)\n\n  \"_transition_trigger_condition\" :: \"id \\<Rightarrow> id \\<Rightarrow> raction \\<Rightarrow> logic \\<Rightarrow> logic\"\n  (\"from _ to _ trigger _ condition _\" [0,0,0,10] 10)\n\n  \"_state\" :: \"raction \\<Rightarrow> raction \\<Rightarrow> raction \\<Rightarrow> logic\"\n  (\"entry _ during _ exit _\" [0,0,10] 10)\n\n  \"_state_entry\" :: \"raction \\<Rightarrow> logic\"\n  (\"entry _\" [10] 10)\n\ntranslations\n  \"_transition s1 s2 e b a\" =>\n  \"CONST Transition.make IDLIT(s1) IDLIT(s2) (CONST Some e) b a\"\n\n  \"_transition_action s1 s2 a\" => \"CONST Transition.make IDLIT(s1) IDLIT(s2) (CONST None) true a\"\n\n  \"_transition_condition s1 s2 b\" => \"CONST Transition.make IDLIT(s1) IDLIT(s2) (CONST None) b (CONST Actions.skips)\"\n\n  \"_transition_condition_action s1 s2 b a\" => \"CONST Transition.make IDLIT(s1) IDLIT(s2) (CONST None) b a\"\n\n  \"_transition_trigger s1 s2 t\" => \"CONST Transition.make IDLIT(s1) IDLIT(s2) (CONST Some t) true (CONST Actions.skips)\"\n\n  \"_transition_trigger_action s1 s2 t a\" => \"CONST Transition.make IDLIT(s1) IDLIT(s2) (CONST Some t) true a\"\n\n  \"_transition_trigger_condition s1 s2 t b\" => \"CONST Transition.make IDLIT(s1) IDLIT(s2) (CONST Some t) b (CONST Actions.skips)\"\n\n\n  \"_state e d x\" => \"CONST Node.make (CONST undefined) e d x\"\n\n  \"_state_entry e\" => \"CONST Node.make (CONST undefined) e skip skip\"\n\nutp_lift_notation Transition.make (0 1 2 4)\n\nterm \"from s1 to s2 trigger y := 1 ; x?(y) ; z!(1) condition b action a\"\nterm \"from s1 to s2 action x := []\"\nterm \"from s1 to s2 trigger e\"\nterm \"entry e during d exit x\"\nterm \"entry e\"\n\nterm \"entry skip during skip exit skip\"\n\nsubsection \\<open> Proof Tactics \\<close>\n\nmethod sm_induct uses simps wf = auto intro!: StateMachine_refine_intro[OF wf] dlockf_refine_intro simp add: simps\nmethod sm_calc uses simps = simp_all add: simps sm_sem_def, simp_all add: action_simp usubst alpha\n\n\nend", "meta": {"author": "isabelle-utp", "repo": "utp-main", "sha": "27bdf3aee6d4fc00c8fe4d53283d0101857e0d41", "save_path": "github-repos/isabelle/isabelle-utp-utp-main", "path": "github-repos/isabelle/isabelle-utp-utp-main/utp-main-27bdf3aee6d4fc00c8fe4d53283d0101857e0d41/robochart/untimed/MetaModel.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5621765008857982, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.285479896968777}}
{"text": "theory Proofs5\n  imports Requirements VCTheoryLemmas\nbegin\n\ndefinition inv5 where \"inv5 s \\<equiv> R5 s \\<and> extraInv s\"\n\nthm extraInv_def\n\nlemma minimalOpened_R5: \"toEnvP s1 \\<and> toEnvP s2 \\<and> toEnvP s0 \\<and> substate s1 s2 \\<and> substate s2 s0 \\<and> substate s0 s \\<and>\ntoEnvNum s1 s2 = 1 \\<and> toEnvNum s2 s0 < 9 \\<and> getPstate s0 Controller' = Controller'minimalOpened' \\<and>\nltime s0 Controller' = 10  \\<and>\n(\\<forall>s1. toEnvP s1 \\<and> substate s1 s \\<and> getPstate s1 Init'init' = Controller'minimalOpened' \\<longrightarrow> ltime s1 Init'init' \\<le> 10) \\<and>\n(\\<forall>s2. toEnvP s2 \\<and> substate s2 s \\<and> getPstate s2 Init'init' = Controller'minimalOpened' \\<longrightarrow>\n      (\\<forall>s1. toEnvP s1 \\<and> substate s1 s2 \\<and> toEnvNum s1 s2 < ltime s2 Init'init' \\<longrightarrow>\n            getPstate s1 Init'init' = Controller'minimalOpened')) \\<and>\n(\\<forall>s1. toEnvP s1 \\<and>\n      substate s1 s \\<and> (getPstate s1 Init'init' = Controller'isOpened' \\<or> getPstate s1 Init'init' = Controller'minimalOpened') \\<longrightarrow>\n      getVarBool s1 Controller'minimalOpened') \n\\<longrightarrow> \\<not> (\\<not> getVarBool s1 open' \\<and> getVarBool s2 open')\"\n  using substate_trans\n  by (smt (verit, ccfv_SIG) BitM_inc_eq eval_nat_numeral(2) inc.simps(2) nat_add_left_cancel_less plus_1_eq_Suc toEnvNum3)\n\nlemma isOpened_timeout_R5: \"toEnvP s1 \\<and> toEnvP s2 \\<and> toEnvP s0 \\<and> substate s1 s2 \\<and> substate s2 s0 \\<and> substate s0 s \\<and>\ntoEnvNum s1 s2 = 1 \\<and> toEnvNum s2 s0 < 9 \\<and> getPstate s0 Controller' = Controller'isOpened' \\<and>\nltime s0 Controller' = 90  \\<and>\n(\\<forall>s1. toEnvP s1 \\<and> substate s1 s \\<and> getPstate s1 Init'init' = Controller'isOpened' \\<longrightarrow> ltime s1 Init'init' \\<le> 90) \\<and>\n(\\<forall>s3. toEnvP s3 \\<and> substate s3 s \\<and> getPstate s3 Init'init' = Controller'isOpened' \\<longrightarrow>\n      (\\<forall>s1. toEnvP s1 \\<and> substate s1 s3 \\<and> toEnvNum s1 s3 < ltime s3 Init'init' \\<longrightarrow> getPstate s1 Init'init' = Controller'isOpened') \\<and>\n      (\\<forall>s2. toEnvP s2 \\<and> substate s2 s3 \\<and> toEnvNum s2 s3 + 1 < ltime s3 Init'init' \\<longrightarrow> \\<not> getVarBool s2 Init')) \\<and>\n(\\<forall>s1. toEnvP s1 \\<and>\n      substate s1 s \\<and> (getPstate s1 Init'init' = Controller'isOpened' \\<or> getPstate s1 Init'init' = Controller'minimalOpened') \\<longrightarrow>\n      getVarBool s1 Controller'minimalOpened') \n\\<longrightarrow>  \\<not>(\\<not> getVarBool s1 open' \\<and> getVarBool s2 open')\"\n  apply(rule impI)\n  apply(rule cut_rl[of \"toEnvNum s1 s0 < ltime s0 Controller'\"])\n  using substate_trans\n   apply meson\n  using toEnvNum3 by auto\n\nlemma isOpened_R5: \"toEnvP s1 \\<and> toEnvP s2 \\<and> toEnvP s0 \\<and> substate s1 s2 \\<and> substate s2 s0 \\<and> substate s0 s \\<and>\ntoEnvNum s1 s2 = 1 \\<and> toEnvNum s2 s0 < 9 \\<and> getPstate s0 Controller' = Controller'isOpened' \\<and>\n(\\<forall>s1. toEnvP s1 \\<and> substate s1 s \\<and> getPstate s1 Init'init' = Controller'minimalOpened' \\<longrightarrow> ltime s1 Init'init' \\<le> 10) \\<and>\n(\\<forall>s2. toEnvP s2 \\<and> substate s2 s \\<and> getPstate s2 Init'init' = Controller'minimalOpened' \\<longrightarrow>\n      (\\<forall>s1. toEnvP s1 \\<and> substate s1 s2 \\<and> toEnvNum s1 s2 < ltime s2 Init'init' \\<longrightarrow>\n            getPstate s1 Init'init' = Controller'minimalOpened')) \\<and>\n(\\<forall>s1. toEnvP s1 \\<and>\n      substate s1 s \\<and> (getPstate s1 Init'init' = Controller'isOpened' \\<or> getPstate s1 Init'init' = Controller'minimalOpened') \\<longrightarrow>\n      getVarBool s1 Controller'minimalOpened') \\<and>\n(\\<forall>s1. toEnvP s1 \\<and> substate s1 s \\<and> getPstate s1 Init'init' = Controller'isOpened' \\<longrightarrow> ltime s1 Init'init' \\<le> 90) \\<and>\n(\\<forall>s1. toEnvP s1 \\<and> substate s1 s \\<and> getPstate s1 Init'init' = Controller'isOpened' \\<longrightarrow>\n      (\\<exists>s2 s3.\n          toEnvP s2 \\<and>\n          toEnvP s3 \\<and>\n          substate s2 s3 \\<and>\n          substate s3 s1 \\<and>\n          toEnvNum s2 s3 = 1 \\<and>\n          toEnvNum s2 s1 = ltime s1 Init'init' \\<and>\n          getPstate s2 Init'init' = Controller'minimalOpened' \\<and>\n          ltime s2 Init'init' = 10 \\<and> \\<not> getVarBool s3 EntranceController'isOpened')) \\<and>\n(\\<forall>s3. toEnvP s3 \\<and> substate s3 s \\<and> getPstate s3 Init'init' = Controller'isOpened' \\<longrightarrow>\n      (\\<forall>s1. toEnvP s1 \\<and> substate s1 s3 \\<and> toEnvNum s1 s3 < ltime s3 Init'init' \\<longrightarrow> getPstate s1 Init'init' = Controller'isOpened') \\<and>\n      (\\<forall>s2. toEnvP s2 \\<and> substate s2 s3 \\<and> toEnvNum s2 s3 + 1 < ltime s3 Init'init' \\<longrightarrow> \\<not> getVarBool s2 Init'))\n\\<longrightarrow> \\<not> (\\<not> getVarBool s1 open' \\<and> getVarBool s2 open')\"\n  apply(rule impI)\n  apply(cases \"toEnvNum s1 s0 < ltime s0 Controller'\")\n  using substate_trans\n   apply meson \n  apply(rule exE[of \" (\\<lambda> s2. \\<exists> s3.\n          toEnvP s2 \\<and>\n          toEnvP s3 \\<and>\n          substate s2 s3 \\<and>\n          substate s3 s0 \\<and>\n          toEnvNum s2 s3 = 1 \\<and>\n          toEnvNum s2 s0 = ltime s0 Init'init' \\<and>\n          getPstate s2 Init'init' = Controller'minimalOpened' \\<and> ltime s2 Init'init' = 10  \\<and> \\<not> getVarBool s3 EntranceController'isOpened')\"])\napply blast\n  apply(drule exE)\n   prefer 2\n   apply assumption\n  subgoal for s3 s4\n    apply(rule cut_rl[of \"substate s3 s0\"])\n    apply(cases \"substate s2 s3\")\n     apply(rule impE[OF minimalOpened_R5[of s1 s2 s3 s]])\n    using substate_trans toEnvNum3\n       apply (smt (verit) leD le_neq_implies_less le_trans less_or_eq_imp_le toEnvNum_substate1)\n      apply assumption\n     apply(rule cut_rl[of \"s1=s3\"])\n    using substate_trans\n      apply meson\n     apply(rule cut_rl[of \"toEnvNum s1 s0 = toEnvNum s3 s0\"])\n    using toEnvNum_eq_imp_eq2 substate_trans\n      apply meson\n     apply(rule le_antisym)\n      apply(rule cut_rl[of \"substate s3 s2 \\<and> s2 \\<noteq> s3\"])\n    using toEnvNum_substate2  toEnvNum_eq_imp_eq2 toEnvNum3[of s1 s2 s0]\n       apply (metis Suc_leI order.order_iff_strict plus_1_eq_Suc)\n    using substate_linear substate_refl\n      apply meson\n     apply arith\n    using substate_trans by meson\n  done\n\ntheorem proof_5_1: \"VC1 inv5 s0\"\n  apply(unfold VC1_def inv5_def R5_def extraInv_def)\n  by auto\n\ntheorem proof_5_2: \"VC2 R5 env s0 PdOut_value paid_value opened_value\"\n  apply(unfold VC2_def)\n  apply simp\n  apply(unfold R5_def)\n  apply(rule impI)\n  apply(rule conjI)\n   apply simp\n  subgoal premises vc_prems\n   apply((rule allI)+)\n    apply(rule impI)\n    apply(simp split: if_splits)\nusing vc_prems\n  by (metis One_nat_def) \n  done\n\ntheorem proof_5_500: \"VC500 R5 env s0 PdOut_value paid_value opened_value\"\n  apply(unfold VC500_def)\n  apply simp\n  apply(unfold R5_def)\n  apply(rule impI)\n  apply(rule conjI)\n   apply simp\n  subgoal premises vc_prems\n    apply((rule allI)+)\n    apply(rule impI)\n    apply(simp split: if_splits)\n    subgoal for s1 s2\n      apply(rule cut_rl[of \"toEnvNum s2 s0 <10\"])\n      using vc_prems substate_refl apply(metis One_nat_def) \n      by simp\n    using vc_prems by(metis One_nat_def) \n  done\n\nend\n", "meta": {"author": "ivchernenko", "repo": "post_vcgenerator", "sha": "fadfff131086870a027d6bd1c78b8d5a3baf183b", "save_path": "github-repos/isabelle/ivchernenko-post_vcgenerator", "path": "github-repos/isabelle/ivchernenko-post_vcgenerator/post_vcgenerator-fadfff131086870a027d6bd1c78b8d5a3baf183b/case-studies/turnstile/Proofs5.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6187804196836383, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.2852681561840741}}
{"text": "section \\<open>Generic Block Allocator\\<close>\ntheory Sep_Block_Allocator\nimports \"../../lib/Monad\"\nbegin\n\n  text \\<open>This theory specifies the concepts of memory allocation and deallocation.\n    It is parameterized over the actual type of blocks.\n  \\<close>\n\n  subsection \\<open>Memory and Addresses\\<close>\n\n  text \\<open>A memory is a list of allocated or already freed blocks.\n    Allocated blocks are modeled by @{term \\<open>Some blk\\<close>}, \n    freed blocks are modeled by @{term \\<open>None\\<close>}\n  \\<close>  \n  datatype 'blk memory = MEMORY (the_memory: \"'blk option list\")\n  define_lenses memory\n\n  text \\<open>An address indexes a block, and then addresses into the value of this block.\\<close>\n  datatype 'baddr addr = ADDR nat 'baddr\n\n  text \\<open>A pointer is either \\<open>null\\<close>, or an address\\<close>\n  datatype 'addr rptr = RP_NULL | RP_ADDR (the_addr: \"'addr\")\n  hide_const (open) the_addr\n\n  text \\<open>Type-class to model that there is a base address.\\<close>  \n  (* TODO: Remove from semantics, move to reasoning infrastructure? *)\n  class this_addr = fixes this_addr :: 'a  \n    \n  text \\<open>We immediately show that the typeclass is not empty. \n    This avoids confusion of the code generator with lemmas depending on this typeclass.\\<close>\n  typedecl this_addr_witness\n  instantiation this_addr_witness :: this_addr begin\n    instance ..\n  end\n  \n  \n  subsection \\<open>Memory Functions\\<close>\n    \n  text \\<open>\n    We specify the standard functions \\<open>alloc\\<close>, \\<open>free\\<close>, \\<open>load\\<close>, and \\<open>store\\<close>. \n    They are parameterized over load and store functions for blocks.\n    \n    Additionally, we specify a \\<open>check_ptr\\<close> function, that asserts that a pointer is valid,\n    i.e., is either \\<open>null\\<close>, or points to an allocated block, and its block address is valid \n    for this block.\n  \\<close>\n  \n  locale block_allocator1 =\n    fixes static_err :: 'err\n      and mem_err :: 'err\n      and bload :: \"'baddr::this_addr \\<Rightarrow> ('val,_,'block,'err) M\"\n      and bstore :: \"'val \\<Rightarrow> 'baddr \\<Rightarrow> (unit,_,'block,'err) M\"\n      and bcheck_addr :: \"'baddr \\<Rightarrow> (unit,_,'block,'err) M\"\n  begin\n\n    text \\<open>Allocate a new block, and a pointer to its start\\<close>\n    definition alloc :: \"'block \\<Rightarrow> ('baddr addr rptr,_,'block memory,'err) M\"\n    where \"alloc init \\<equiv> zoom (lift_lens static_err the_memory\\<^sub>L) (doM {\n      blocks \\<leftarrow> Monad.get;\n      let bi = length blocks;\n      let blocks = blocks @ [Some init];\n      Monad.set blocks;\n      return (RP_ADDR (ADDR bi this_addr))\n    })\"\n\n    text \\<open>Free a block, specified by a pointer to its start\\<close>    \n    definition free :: \"'baddr addr rptr \\<Rightarrow> (unit,_,'block memory,'err) M\"\n    where \"free \\<equiv> \n      \\<lambda>RP_ADDR (ADDR bi ba) \\<Rightarrow> doM {\n          fcheck mem_err (ba=this_addr);\n          \\<comment>\\<open> TODO: Use load here! \\<close>\n          let L = lift_lens static_err the_memory\\<^sub>L \\<bullet> (lift_lens mem_err (idx\\<^sub>L bi));\n          blk \\<leftarrow> use L;\n          fcheck mem_err (blk \\<noteq> None);\n          L ::= None\n        } \n      | _ \\<Rightarrow> fail mem_err\"\n      \n    text \\<open>We define a lens that focuses a block index. \\<close>  \n    (* TODO: Can we define lenses to focus addresses/pointers instead? *)\n    definition \"lens_of_bi bi \\<equiv> the_memory\\<^sub>L \\<bullet>\\<^sub>L idx\\<^sub>L bi \\<bullet>\\<^sub>L the\\<^sub>L\"\n    abbreviation \"elens_of_bi bi \\<equiv> lift_lens mem_err (lens_of_bi bi)\"\n    lemma lens_of_bi[simp, intro!]: \"hlens (lens_of_bi bi)\"\n      unfolding lens_of_bi_def by auto\n    \n    text \\<open>Load from an address\\<close>  \n    definition \"load \\<equiv> \\<lambda>RP_ADDR (ADDR bi ba) \\<Rightarrow> zoom (elens_of_bi bi) (bload ba) | _ \\<Rightarrow> fail mem_err\"\n    text \\<open>Store at an address\\<close>  \n    definition \"store \\<equiv> \\<lambda>x. \\<lambda>RP_ADDR (ADDR bi ba) \\<Rightarrow> zoom (elens_of_bi bi) (bstore x ba) | _ \\<Rightarrow> fail mem_err\"\n    \n    text \\<open>Check that pointer is valid\\<close>\n    definition \"check_ptr \\<equiv> \\<lambda>RP_NULL \\<Rightarrow> return () | RP_ADDR (ADDR bi ba) \\<Rightarrow> zoom (elens_of_bi bi) (bcheck_addr ba)\"\n    \n    text \\<open>The empty memory\\<close>\n    definition \"empty_memory \\<equiv> MEMORY []\"\n    \n  end    \n\n  subsection \\<open>Isabelle Code Generator Setup\\<close>\n  text \\<open>Setup to make the semantics executable inside Isabelle/HOL\\<close>\n  \n  lemmas block_allocator1_code[code] =\n    block_allocator1.alloc_def \n    block_allocator1.free_def\n    block_allocator1.lens_of_bi_def\n    block_allocator1.load_def\n    block_allocator1.store_def\n    block_allocator1.check_ptr_def\n    block_allocator1.empty_memory_def\n  \n  \nend\n", "meta": {"author": "lammich", "repo": "isabelle_llvm", "sha": "6be37a9c3cae74a1134dbef2979e312abb5f7f42", "save_path": "github-repos/isabelle/lammich-isabelle_llvm", "path": "github-repos/isabelle/lammich-isabelle_llvm/isabelle_llvm-6be37a9c3cae74a1134dbef2979e312abb5f7f42/thys/basic/kernel/Sep_Block_Allocator.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5888891451980404, "lm_q2_score": 0.4843800842769844, "lm_q1q2_score": 0.2852461737808281}}
{"text": "theory SpreadGetSet\n  imports Main\n \"build_spread/Spread_dargentfull_CorresProof\"\n\nbegin\ncontext spread_dargentfull begin\ndefinition find_position :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat \\<times> nat\"\n  where \"find_position si offset  = (offset div si, offset mod si)\"\n\ndefinition get_bit :: \"(('a::len0) word)['n::finite] \\<Rightarrow> nat \\<Rightarrow> bool\"\n  where \"get_bit arr pos = \n                (let (byte, off) = find_position LENGTH('a) pos in\n                 arr.[byte] !! off )\"\n\ndefinition raw_get_bit :: \"(('a::len0) word)['n::finite] \\<Rightarrow> nat \\<Rightarrow> 'a word\"\n  where \"raw_get_bit arr pos = \n                (let (byte, off) = find_position LENGTH('a) pos in\n                 arr.[byte] && 2^off )\"\n\n\n\ndefinition size_of_arr :: \"(('a::len0) word)['n::finite] \\<Rightarrow> nat\"\n  where \"size_of_arr _ = CARD('n)\"\n\ndefinition size_of_arr_bits :: \"(('a::len0) word)['n::finite] \\<Rightarrow> nat\"\n  where \"size_of_arr_bits _ = LENGTH('a)*CARD('n)\"\n\nML \\<open>\nfun getter_sanity_tac ctxt = \n let\n    val gets = Proof_Context.get_thms ctxt\n    val get  = Proof_Context.get_thm ctxt\n  in\n  K (print_tac ctxt \"debut_getter\")\nTHEN' \n (asm_full_simp_tac (ctxt addsimps [(get \"find_position_def\")])\nTHEN'\n (fn i => \nTRY (REPEAT_ALL_NEW (eresolve_tac ctxt @{thms exE conjE}) i))\n(* THEN' K (print_tac ctxt \"coucou\") *)\nTHEN' custom_get_set_different_field_tac ctxt\n) end\n\\<close>\n\nlemma wesh : \"x < LENGTH('a) \\<Longrightarrow> (((2 ^ x) :: ('a :: len0)  word) !! n) = (x = n)\"\n  by sorry\nML \\<open>\nfun setter_sanity_tac ctxt = \n let\n    val gets = Proof_Context.get_thms ctxt\n    val get  = Proof_Context.get_thm ctxt\n  in\n  K (print_tac ctxt \"debut\")\nTHEN' \n (asm_full_simp_tac (ctxt addsimps\n [get \"find_position_def\", get \"size_of_arr_bits_def\"]))\nTHEN'\n(asm_full_simp_tac ((clear_simpset ctxt) addsimps\n (gets \"numeral.simps\")))\nTHEN' asm_full_simp_tac ctxt\n(* THEN'  K (print_tac ctxt \"suite\") *)\nTHEN'\n (fn i => \nTRY (REPEAT_ALL_NEW (eresolve_tac ctxt @{thms exE conjE}) i))\n(* THEN'  K (print_tac ctxt \"resuite\") *)\n THEN'  (fn i => \nTRY (REPEAT_ALL_NEW (eresolve_tac ctxt @{thms less_zeroE less_SucE}) i)) \n\n (* THEN' K (print_tac ctxt \"coucou\")  *)\nTHEN_ALL_NEW custom_get_set_different_field_tac (ctxt addsimps @{thms wesh})\n end\n\\<close>\nML \\<open>\nfun prove_thm ctxt assms concl tactic = \nlet\nval clean = HOLogic.mk_Trueprop o strip_atype\nval thm0 = mk_meta_imps (map clean assms) (concl |> clean) ctxt\nval names =  Variable.add_free_names ctxt thm0 []\nin\nGoal.prove ctxt names [] thm0\n( fn {context, prems} => tactic context 1)\nend\n\\<close>\n\nML \\<open>\nval uvals = \nSymtab.lookup (UVals.get @{theory}) \"spread_dargentfull.c\"\n|> the\n(* Filter those with custom layouts*)\n |> get_uval_custom_layout_records\n\\<close>\nML \\<open>\n val uval0 = hd uvals\n\\<close>\n\nML \\<open>\nval (info0, lay0) = \ncase get_uval_layout uval0 of\nCustomLayout (info, \nConst (\"Option.option.Some\", _) $ \n( Const (\"Cogent.ptr_layout.LayRecord\", _) $ \nlayout)) => \n(info, \nlayout |> HOLogic.dest_list\n|> map HOLogic.dest_prod\n|> map (apfst HOLogic.dest_string)\n|> Symtab.make\n)\n\nval field0 = hd info0\nval layfield0 = Symtab.lookup lay0 (# name field0) |> the\n\\<close>\n\nML \\<open>\nval get_data =\nget_uval_name uval0 ^ \"_C.data_C\"\n\\<close>\n\nML \\<open>\nfun make_getter_sanity_thm ctxt layfield (field_info : field_layout) = \nlet\nval ass = \n  @{term \n  \"\\<lambda>  lay data. \n   (\\<forall> x\\<in> set(layout_taken_bit_list lay). \n  get_bit (data s) x = get_bit (data t) x)\n  \"\n  } $ layfield $ (Syntax.read_term ctxt get_data)\nval concl = @{term \"\\<lambda> getter . getter s = getter t\"  }\n        $ # isa_getter field_info\nin\nprove_thm ctxt [ass] concl getter_sanity_tac\nend\n\n\\<close>\nML \\<open>\nfun make_setter_sanity_thm ctxt layfield (field_info : field_layout) = \nlet\n\n val data = Syntax.read_term ctxt get_data\nval ass1 = \n  @{term \n  \"\\<lambda>  data .x < size_of_arr_bits (data s) \n  \"\n  } $ data\nval ass2 = \n  @{term \n  \"\\<lambda>  lay .x \\<notin> set (layout_taken_bit_list lay) \n  \"\n  } $ layfield\nval concl = @{term \"\\<lambda> data setter . \n   raw_get_bit (data (setter s b)) x = raw_get_bit (data s) x\"  }\n        $ data\n        $ # isa_setter field_info\nin\nprove_thm ctxt [ass1, ass2] concl (fn ctxt => fn _ => print_tac ctxt \"coucuo\" THEN cheat_tactic ctxt)(* setter_sanity_tac *)\nend\n\\<close>\n\nML \\<open>\nfun make_getset_sanity_thms ctxt (uval : field_layout uval) : (thm * thm) list =\nlet\nval (info, lays) = \ncase get_uval_layout uval of\nCustomLayout (info, \nConst (\"Option.option.Some\", _) $ \n( Const (\"Cogent.ptr_layout.LayRecord\", _) $ \nlayout)) => \n(info, \nlayout |> HOLogic.dest_list\n|> map HOLogic.dest_prod\n|> map (apfst HOLogic.dest_string)\n|> Symtab.make\n)\nin\nmap (\nfn field => \nlet val lay = Symtab.lookup lays (# name field) |> the in\n(make_getter_sanity_thm ctxt  lay field,\nmake_setter_sanity_thm ctxt lay field)\nend\n)\n \n info\n\nend\n\\<close>\n\nlemma raw_get_bit_eq : \"raw_get_bit x n = raw_get_bit y n \\<Longrightarrow> get_bit x n = get_bit y n\"\n  by sorry\n\nlemma find_pos_split : \" P (find_position q x)\n  = ((\\<forall> p r. find_position q x = (p, r) \\<longrightarrow>\nr < q \\<longrightarrow> p < n div q \\<longrightarrow>  P (p, r))\n\\<and> (\\<forall> r. find_position q x = (n div q, r) \\<longrightarrow> r < n mod q \\<longrightarrow> P ( (n div q), r) )\n\\<and> (\\<forall> p r. find_position q x = (p, r) \\<longrightarrow> (x \\<ge> n \\<or> q = 0) \\<longrightarrow> P ( p, r) )\n)\n\"\n  by sorry\n\nlemma \"x < size_of_arr_bits (data_C s) \\<Longrightarrow>\n    x \\<notin> set (layout_taken_bit_list (LayBitRange (64, 2))) \\<Longrightarrow>\n    get_bit (data_C (deref_d21_set_b s b)) x = get_bit (data_C s) x \"\n  apply(rule raw_get_bit_eq )\napply(simp add:raw_get_bit_def)\napply( split find_pos_split[of _ _ _  32])\n\nend\n\nlemma \"x < size_of_arr_bits (data_C s) \\<Longrightarrow>\n    x \\<notin> set (layout_taken_bit_list\n               (LayVariant (Suc 0, Suc 0) [(''A'', 0, LayBitRange (Suc 0, 0)), (''B'', Suc 0, LayBitRange (Suc 0, 67))])) \\<Longrightarrow>\n    raw_get_bit (data_C (deref_d14_set_a s b)) x = raw_get_bit (data_C s) x \"\n  apply(tactic \\<open>setter_sanity_tac @{context} 1\\<close> )\n(* ca ne marche pas ! *)\n\nlemma \"x < size_of_arr_bits (data_C s) \\<Longrightarrow>\n    x \\<notin> set (layout_taken_bit_list (LayBitRange (64, 2))) \\<Longrightarrow>\n    raw_get_bit (data_C (deref_d21_set_b s b)) x = raw_get_bit (data_C s) x \"\napply(tactic \\<open>setter_sanity_tac @{context} 1\\<close> )\n\nML \\<open>\nval thms = make_getset_sanity_thms @{context} uval0\n\\<close>\n\nend\n\n\nend\n", "meta": {"author": "amblafont", "repo": "dargent-examples", "sha": "dbcfdd6573c088f65d4dade1b351b3bb2bc073e7", "save_path": "github-repos/isabelle/amblafont-dargent-examples", "path": "github-repos/isabelle/amblafont-dargent-examples/dargent-examples-dbcfdd6573c088f65d4dade1b351b3bb2bc073e7/bucket/SpreadGetSet.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5888891451980403, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.285246173780828}}
{"text": "theory SNS_IAS_Eduroam_Spoofing\nimports \n  Iptables_Semantics.Parser\nbegin\n\n\nsection\\<open>Example: Eduroam and sns.ias Firewall Script\\<close>\n\ndefinition \"everything_but_my_ip = all_but_those_ips [(ipv4addr_of_dotdecimal (131,159,207,206), 32)]\"\n\n\ntext\\<open>Incoming: everything but my IP\\<close>\ndefinition \"ipassignment_incoming = [(Iface ''wlan0'', everything_but_my_ip), (Iface ''lo'', [(0,0)])]\"\n\nlemma \"ipassmt_sanity_nowildcards (map_of ipassignment_incoming)\" by eval\n\ntext\\<open>Outgoing: only my IP\\<close>\ndefinition \"ipassignment_outgoing = [(Iface ''wlan0'',  [(ipv4addr_of_dotdecimal (131,159,207,206), 32)]), (Iface ''lo'', [(0,0)])]\"\n\nlemma \"ipassmt_sanity_nowildcards (map_of ipassignment_outgoing)\" by eval\n\nparse_iptables_save eduroam_fw=\"eduroam_iptables-save\"\n\nthm eduroam_fw_def\nthm eduroam_fw_INPUT_default_policy_def\n\nvalue[code] \"debug_ipassmt_ipv4 ipassignment_incoming (unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw))\"\n\nvalue[code] \"unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw)\"\n\nvalue[code] \"collect_ifaces (unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw))\"\n\n\nlemma \"ipassmt_sanity_defined (unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw)) (map_of_ipassmt ipassignment_incoming)\" by eval\nlemma \"ipassmt_sanity_defined (unfold_ruleset_OUTPUT eduroam_fw_OUTPUT_default_policy (map_of_string_ipv4 eduroam_fw)) (map_of_ipassmt ipassignment_outgoing)\" by eval\n\n\nvalue[code] \"debug_ipassmt_ipv4 ipassignment_incoming (unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw))\"\nvalue[code] \"debug_ipassmt_ipv4 ipassignment_outgoing (unfold_ruleset_OUTPUT eduroam_fw_OUTPUT_default_policy (map_of_string_ipv4 eduroam_fw))\"\n\n\ntext\\<open>The ruleset\\<close>\nlemma \"check_simple_fw_preconditions (upper_closure (packet_assume_new (unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw))))\" by eval\nvalue[code] \"map simple_rule_ipv4_toString (to_simple_firewall (upper_closure (packet_assume_new (unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw)))))\"\nlemma \"simple_fw_valid (to_simple_firewall (upper_closure (packet_assume_new (unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw)))))\" by eval\nlemma \"simple_fw_valid (to_simple_firewall (lower_closure (packet_assume_new (unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw)))))\" by eval\n\n\ntext\\<open>We do not need to call things such as @{const transform_optimize_dnf_strict} because the\n     firewall already is in @{const normalized_nnf_match} (required for @{const no_spoofing_iface})\\<close>\nlemma \"transform_optimize_dnf_strict (unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw)) =\n          unfold_ruleset_INPUT action.Drop (map_of_string_ipv4 eduroam_fw)\" by eval\n\ntext\\<open>The ruleset prevents spoofed incoming packets\\<close>\nlemma \"no_spoofing_iface (Iface ''wlan0'')\n        (map_of_ipassmt ipassignment_incoming) (unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw))\" by eval\n\n\ntext\\<open>Ruleset does not prevent that I'm spoofing (which is not necessary anyways since I need root right to spoof, which \n      would also enable me to deactivate the firewall). This is only a one-user laptop!\\<close>\n\nlemma \"transform_optimize_dnf_strict (unfold_ruleset_OUTPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw)) =\n        unfold_ruleset_OUTPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw)\" by eval\n\nlemma \"\\<not> no_spoofing_iface (Iface ''wlan0'')\n        (map_of_ipassmt ipassignment_outgoing) (unfold_ruleset_OUTPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw))\" by eval\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Iptables_Semantics/Examples/sns.ias.edu/SNS_IAS_Eduroam_Spoofing.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.4843800842769844, "lm_q1q2_score": 0.2852461667911226}}
{"text": "(*\n * Copyright 2022, Proofcraft Pty Ltd\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory Named_Eta_Test\nimports Lib.Named_Eta\nbegin\n\nexperiment\nbegin\n\ndeclare [[eta_contract=false]] (* for display only, it does not affect terms *)\n\n(* tactical invocation example *)\nschematic_goal\n  \"\\<And>y. ?Q y False \\<Longrightarrow> ?P y (\\<lambda>x. f x)\"\n  apply (tactic \\<open>named_eta_tac \"x\" @{context}\\<close>)\n  apply assumption\n  done\n\n(* method invocation example *)\nschematic_goal\n  \"\\<And>y. ?Q y False \\<Longrightarrow> ?P y (\\<lambda>x. f x)\"\n  apply (named_eta x)\n  apply assumption\n  done\n\nlemma\n  \"P x (\\<lambda>z. g (\\<lambda>x. f x) z)\"\n  \"\\<And>P z. Q z \\<Longrightarrow> P (\\<lambda>x. f x)\"\n  apply -\n  (* only affects one subgoal *)\n  prefer 2\n  apply (named_eta x)\n  prefer 2\n  (* only contract \"z\" *)\n  apply (named_eta z)\n  (* now only contract \"x\" *)\n  apply (named_eta x)\n  oops\n\nlemma (* nested lambdas *)\n  \"\\<lbrakk> X; P (\\<lambda>x. (f (\\<lambda>x. g y x))) \\<rbrakk> \\<Longrightarrow> P (\\<lambda>x. (f (\\<lambda>x. g y x)))\"\n  apply (named_eta x)\n  apply assumption\n  done\n\nML \\<open>\n  (* nameless abstractions: *)\n  val t = Abs (\"\", @{typ bool}, @{term \"f (\\<lambda>x. g x) :: bool \\<Rightarrow> bool\"} $ Bound 0)\n  val ct = Thm.cterm_of @{context} t\n  (* contracts only the nameless \"a\" lambda: *)\n  val thm = Named_Eta.named_eta_conv \"\" @{context} ct\n\\<close>\n\nend\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/lib/test/Named_Eta_Test.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5660185351961015, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.285220232519147}}
{"text": "(*  Title:        Notions of Topology for C2KA\n    Author:       Maxime Buyse <maxime.buyse at polytechnique.edu>, 2019\n    Maintainers:  Maxime Buyse <maxime.buyse at polytechnique.edu> and Jason Jaskolka <jason.jaskolka at carleton.ca>\n*)\n\nsection \\<open>Notions of Topology for \\CCKAabbrv \\label{sec:topology}\\<close>\n\ntext \\<open>\nOrbits, stabilisers, and fixed points are notions that allow us to perceive a kind of topology of a system \nwith respect to the stimulus-response relationships among system agents. In this context, the term ``topology'' \nis used to capture the relationships (influence) and connectedness via stimuli of the agents in a distributed \nsystem. It intends to capture a kind of reachability in terms of the possible behaviours for a given agent.\n\nA \\CCKAabbrv consists of two semimodules~$\\ActSemimodule$ and~$\\OutSemimodule$ for which we have a \n\\leftAct{\\stim}~$\\lSact$ and a \\rightAct{\\cka}~$\\rKact$. Therefore, there are two complementary notions of orbits, \nstabilisers, and fixed points within the context of agent behaviours and stimuli, respectively. In this way, one \ncan use these notions to think about distributed systems from two different perspectives, namely the behavioural \nperspective provided by the action of stimuli on agent behaviours described by~$\\ActSemimodule$ and the external \nevent (stimulus) perspective provided by the action of agent behaviours on stimuli described by~$\\OutSemimodule$. \nIn this section, only the treatment of these notions with respect to the \\leftSemimodule{\\stim}~$\\ActSemimodule$ \nand agent behaviours is provided. The same notions for the \\rightSemimodule{\\cka}~$\\OutSemimodule$ and stimuli \ncan be provided in a very similar way.\n\nWhen discussing the interplay between \\CCKAabbrv and the notions of orbits, stabilisers, and fixed points, the \npartial order of sub-behaviours~$\\CKAle$ is extended to sets in order to express sets of agent behaviours \nencompassing one another. For two subsets of agent behaviours~$A,B \\STleq \\CKAset$, we say that~$A$ \n\\emph{is encompassed by}~$B$ (or~$B$ \\emph{encompasses}~$A$), written~$\\CKAencompass{A}{B}$, if and only \nif~$\\biglnotation{\\forall}{a}{a \\in A}{\\lnotation{\\exists}{b}{b \\in B}{a \\CKAle b}}$. In essence,~$A \\CKAenc B$ \nindicates that every behaviour contained within the set~$A$ is a sub-behaviour of at least one behaviour in the \nset~$B$. The encompassing relation~$\\STIMenc$ for stimuli can be defined similarly. \n\nThroughout this section, let~$\\ActSemimodule$ be the unitary and zero-preserving \\leftSemimodule{\\stim} of a \n\\CCKAabbrv and let~$a \\in \\CKAset$.\n\\<close>\n\ntheory Topology_C2KA\n  imports C2KA\nbegin\n\nno_notation\ncomp (infixl \"\\<circ>\" 55)\nand rtrancl (\"(_\\<^sup>*)\" [1000] 999)\n\ntext \\<open>\nThe locale \\emph{topology-c2ka} extends the axiomatisation of \\emph{c2ka} to support the notions of topology. \n\\<close>\n\nlocale topology_c2ka = c2ka +\n  fixes orbit :: \"'a::cka \\<Rightarrow> 'a::cka set\" (\"Orb\")\n  and strong_orbit :: \"'a::cka \\<Rightarrow> 'a::cka set\" (\"Orb\\<^sub>S\")\n  and stabiliser :: \"'a::cka \\<Rightarrow> 'b::stimuli set\" (\"Stab\")\n  and fixed :: \"'a::cka \\<Rightarrow> bool\"\n  and encompassing_relation_behaviours :: \"'a set \\<Rightarrow> 'a set \\<Rightarrow> bool\"  (infix \"\\<lless>\\<^sub>\\<K>\" 50)\n  and encompassing_relation_stimuli :: \"'b set \\<Rightarrow> 'b set \\<Rightarrow> bool\"  (infix \"\\<lless>\\<^sub>\\<S>\" 50)\n  and induced :: \"'a::cka \\<Rightarrow> 'a::cka \\<Rightarrow> bool\" (infix \"\\<lhd>\" 50)\n  and orbit_equivalent :: \"'a::cka \\<Rightarrow> 'a::cka \\<Rightarrow> bool\" (infix \"\\<sim>\\<^sub>\\<K>\" 50)\n  assumes orb_def: \"x \\<in> Orb(a) \\<longleftrightarrow> (\\<exists>s. (s \\<circ> a = x))\"\n  and orbs_def: \"b \\<in> Orb\\<^sub>S(a) \\<longleftrightarrow> Orb(b) = Orb(a)\"\n  and stab_def: \"s \\<in> Stab(a) \\<longleftrightarrow> s \\<circ> a = a\"\n  and fixed_def: \"fixed(a) \\<longleftrightarrow> (\\<forall>s::'b. s\\<noteq>\\<dd> \\<longrightarrow> s \\<circ> a = a)\"\n  and erb_def: \"A \\<lless>\\<^sub>\\<K> B \\<longleftrightarrow> (\\<forall>a::'a. a \\<in> A \\<longrightarrow> (\\<exists>b. b \\<in> B \\<and> a \\<le>\\<^sub>\\<K> b))\"\n  and ers_def: \"E \\<lless>\\<^sub>\\<S> F \\<longleftrightarrow> (\\<forall>a::'b. a \\<in> E \\<longrightarrow> (\\<exists>b. b \\<in> F \\<and> a \\<le>\\<^sub>\\<S> b))\"\n  and induced_def: \"a \\<lhd> b \\<longleftrightarrow> b \\<in> Orb(a)\"\n  and orbit_equivalent_def: \"a \\<sim>\\<^sub>\\<K> b \\<longleftrightarrow> Orb(a) = Orb(b)\"\nbegin\n\nsubsection \\<open>Orbits \\label{sub:orbits}\\<close>\n\ntext \\<open>\nThe \\emph{orbit} of~$a$ in~$\\stim$ is the set given by~$\\orb{a} = \\sets{\\lAct{a}{s}}{s \\in \\STIMset}$. The orbit of \nan agent~$a \\in \\CKAset$ represents the set of all possible behavioural responses from an agent behaving as~$a$ to \nany stimulus from~$\\stim$. In this way, the orbit of a given agent can be perceived as the set of all possible \nfuture behaviours for that agent. \n\\<close>\n\n\ntext \\<open>\nLemma \\emph{inf-K-enc-orb} provides an isotonicity law with respect to the orbits and the encompassing relation for agent behaviours.\n\\<close>\n\nlemma inf_K_enc_orb: \"a \\<le>\\<^sub>\\<K> b \\<Longrightarrow> Orb(a) \\<lless>\\<^sub>\\<K> Orb(b)\"\n  unfolding erb_def orb_def\n  using inf_K_next_behaviour by blast\n  \ntext \\<open>\nThe following lemmas provide a selection of properties regarding orbits and the encompassing relation for agent behaviours.\n\\<close>\n\nlemma enc_orb_add: \"Orb(a) \\<lless>\\<^sub>\\<K> Orb(a + b)\"\n  using  inf_K_enc_orb inf_add_K_right by auto\n\nlemma enc_orb_exchange: \"Orb((a*b) ; (c*d)) \\<lless>\\<^sub>\\<K> Orb((a;c) * (b;d))\"\n  using inf_K_enc_orb exchange_2 by blast\n\nlemma enc_orb_seq_par: \"Orb(a;b) \\<lless>\\<^sub>\\<K> Orb(a*b)\"\n  using inf_K_enc_orb seq_inf_par by auto\n\nlemma enc_orb_add_seq_par: \"Orb(a;b + b;a) \\<lless>\\<^sub>\\<K> Orb(a*b)\"\n  using inf_K_enc_orb add_seq_inf_par by auto\n\nlemma enc_orb_parseq: \"Orb((a*b);c) \\<lless>\\<^sub>\\<K> Orb(a*(b;c))\"\n  using inf_K_enc_orb exchange_3 by blast\n\nlemma enc_orb_seqpar: \"Orb(a;(b*c)) \\<lless>\\<^sub>\\<K> Orb((a;b)*c)\"\n  using inf_K_enc_orb exchange_4 by blast\n\nlemma enc_orb_seqstar_parstar: \"Orb(a\\<^sup>;) \\<lless>\\<^sub>\\<K> Orb(a\\<^sup>*)\"\n  using inf_K_enc_orb seqstar_inf_parstar by auto\n\nlemma enc_orb_union: \"Orb(a) \\<lless>\\<^sub>\\<K> Orb(c) \\<and> Orb(b) \\<lless>\\<^sub>\\<K> Orb(c) \n\\<longleftrightarrow> Orb(a) \\<union> Orb(b) \\<lless>\\<^sub>\\<K>  Orb(c)\"\n  unfolding erb_def \n  by auto\n   \nsubsection \\<open>Stabilisers \\label{sub:stabilisers}\\<close>\n\ntext \\<open>\nThe \\emph{stabiliser} of~$a$ in~$\\stim$ is the set given by~$\\stab{a} = \\sets{s \\in \\STIMset}{\\lAct{a}{s} = a}$. \nThe stabiliser of an agent~$a \\in \\CKAset$ represents the set of stimuli which have no observable influence \n(or act as neutral stimuli) on an agent behaving as~$a$.\n\\<close>  \n\ntext \\<open>\nLemma \\emph{enc-stab-inter-add} provides a property regarding stabilisers and the encompassing relation for stimuli.\n\\<close>\n\nlemma enc_stab_inter_add: \"Stab(a) \\<inter> Stab(b) \\<lless>\\<^sub>\\<S> Stab(a + b)\"\n  unfolding ers_def\n  by (auto simp add: stab_def, rename_tac s, rule_tac x=\"s\" in exI, simp)\n  \nsubsection \\<open>Fixed Points \\label{sub:fixed_points}\\<close>\n\ntext \\<open>\nAn element~$a \\in \\CKAset$ is called a \\emph{fixed point} if~$\\lnotation{\\forall}{s}{s \\in \\STIMset \\STdiff \\set{\\Dstim}}{\\lAct{a}{s} = a}$.\\linebreak \nWhen an agent behaviour is a fixed point, it is not influenced by any stimulus other than the deactivation stimulus~$\\Dstim$. \nIt is important to note that since~$\\ActSemimodule$ is zero-preserving, every agent behaviour becomes inactive when subjected to the \ndeactivation stimulus~$\\Dstim$. Because of this, we exclude this special case when discussing fixed point agent behaviours.\n\\<close>  \n\nlemma zerofix [simp]: \"s \\<circ> 0 = 0\"\nproof -\n  have \"0 = \\<dd> \\<circ> a\" by simp\n  hence \"s \\<circ> 0 = s \\<circ> (\\<dd> \\<circ> a)\" by simp\n  hence \"s \\<circ> 0 = (s \\<odot> \\<dd>) \\<circ> a\" by (simp only: lsemimodule3 [symmetric])\n  thus \"s \\<circ> 0 = 0\" by simp\nqed\n\ntext \\<open>\nThe following lemmas provide a selection of properties regarding fixed agent behaviours.\n\\<close>  \n\nlemma fixed_zero: \"fixed(0)\"\n  unfolding fixed_def\n  by simp\n\nlemma fixed_a_b_add: \"fixed(a) \\<and> fixed(b) \\<longrightarrow> fixed(a + b)\"\n  unfolding fixed_def\n  by simp\n\nlemma fix_not_deactivation: \"s \\<circ> a = a \\<and> \\<lambda>(s,a) = \\<dd> \\<Longrightarrow> a = 0\"\nproof -\n  assume E: \"s \\<circ> a = a \\<and> \\<lambda>(s,a) = \\<dd>\"\n  hence \"s \\<circ> (a;1) = a\" by simp\n  hence \"(s\\<circ>a) ; (\\<lambda>(s,a)\\<circ>1) = a\" by (simp only: cascadingaxiom)\n  hence \"0 = a\" by (simp add: E)\n  thus ?thesis by auto\nqed\n\nlemma fixed_a_b_seq: \"fixed(a) \\<and> fixed(b) \\<longrightarrow> fixed(a ; b)\"\n  unfolding fixed_def\nproof (rule impI)\n  assume hyp: \"(\\<forall>s. s \\<noteq> \\<dd> \\<longrightarrow> s \\<circ> a = a) \\<and> (\\<forall>s. s \\<noteq> \\<dd> \\<longrightarrow> s \\<circ> b = b)\"\n  have C1: \"(\\<forall>s. \\<lambda>(s,a) = \\<dd> \\<longrightarrow> s \\<noteq> \\<dd> \\<longrightarrow> s \\<circ> (a ; b) = a ; b)\"\n  proof -\n    have E: \"(\\<forall>s. s \\<noteq> \\<dd> \\<and> \\<lambda>(s,a) = \\<dd> \\<longrightarrow> s \\<circ> (a ; b) = 0)\" by simp\n    hence \"(\\<forall>s. s \\<noteq> \\<dd> \\<and> \\<lambda>(s,a) = \\<dd> \\<longrightarrow> s \\<circ> a = a \\<and> \\<lambda>(s,a) = \\<dd>)\" \n      by (simp add: hyp)\n    moreover have \"(\\<forall>s. s \\<circ> a = a \\<and> \\<lambda>(s,a) = \\<dd> \\<longrightarrow> a = 0)\" \n      by (simp add: fix_not_deactivation)\n    ultimately have \"(\\<forall>s. s \\<noteq> \\<dd> \\<and> \\<lambda>(s,a) = \\<dd> \\<longrightarrow> a = 0)\" by auto\n    thus ?thesis by (auto simp add: E)\n  qed\n  moreover have C2: \"(\\<forall>s. \\<lambda>(s,a) \\<noteq> \\<dd> \\<longrightarrow> s \\<noteq> \\<dd> \\<longrightarrow> s \\<circ> (a ; b) = a ; b)\" \n    by (simp add: hyp)\n  ultimately show \"(\\<forall>s. s \\<noteq> \\<dd> \\<longrightarrow> s \\<circ> (a ; b) = a ; b)\" by blast\nqed\n\nsubsection \\<open>Strong Orbits and Induced Behaviours \\label{sub:strong_orbits_and_induced_behaviours}\\<close>\n\ntext \\<open>\nThe \\emph{strong orbit} of~$a$ in~$\\stim$ is the set given by~$\\orbS{a} = \\sets{b \\in \\CKAset}{\\orb{b} = \\orb{a}}$. \nTwo agents are in the same strong orbit, denoted~$a \\CKAsim b$ for~$a,b \\in \\CKAset$, if and only if their orbits are \nidentical. This is to say when~$a \\CKAsim b$, if an agent behaving as~$a$ is influenced by a stimulus to behave as~$b$, \nthen there exists a stimulus which influences the agent, now behaving as~$b$, to revert back to its original behaviour~$a$. \n\nThe influence of stimuli on agent behaviours is called the \\emph{induced behaviours} via stimuli. Let~$a,b \\in \\CKAset$ \nbe agent behaviours with~$a \\neq b$. We say that~$b$ is \\emph{induced by~$a$ via stimuli} (denoted by~$\\induced{b}{a}$) \nif and only if~$\\lnotation{\\exists}{s}{s \\in \\STIMset}{\\lAct{a}{s} = b}$. The notion of induced behaviours allows us to make \nsome predictions about the evolution of agent behaviours in a given system by providing some insight into how different agents \ncan respond to any stimuli.\n\\<close>  \n\ntext \\<open>\nLemma \\emph{fixed-not-induce} states that if an agent has a fixed point behaviour, then it does not induce any agent behaviours via  stimuli besides the inactive behaviour~$0$.\n\\<close>  \n\nlemma fixed_not_induce: \"fixed(a) \\<longrightarrow> (\\<forall>b. b \\<noteq> 0 \\<and> b \\<noteq> a \\<longrightarrow> \\<not>(a \\<lhd> b))\"\nproof -\n  have \"\\<And>s. s = \\<dd> \\<or> s \\<noteq> \\<dd> \\<Longrightarrow> (\\<forall>t. t \\<noteq> \\<dd> \\<longrightarrow> t \\<circ> a = a) \\<Longrightarrow> s \\<circ> a \\<noteq> 0 \n\\<Longrightarrow> s \\<circ> a \\<noteq> a \\<Longrightarrow> False\"\n    by (erule disjE, simp_all)\n  hence \"\\<And>s. (\\<forall>t. t \\<noteq> \\<dd> \\<longrightarrow> t \\<circ> a = a) \\<Longrightarrow> s \\<circ> a \\<noteq> 0 \\<Longrightarrow> s \\<circ> a \\<noteq> a \\<Longrightarrow> False\"\n    by simp\n  thus ?thesis \n    unfolding fixed_def induced_def orb_def\n    by auto\nqed\n\ntext \\<open>\nLemma \\emph{strong-orbit-both-induced} states that all agent behaviours which belong to the same strong orbit are mutually induced via some (possibly different) stimuli.\nThis is to say that if two agent behaviours are in the same strong orbit, then there exists inverse stimuli for each agent behaviour in a \nstrong orbit allowing an agent to revert back to its previous behaviour.\n\\<close>  \n\nlemma in_own_orbit: \"a \\<in> Orb(a)\"\n  unfolding orb_def\n  by (rule_tac x=\"\\<nn>\" in exI, simp)\n\nlemma strong_orbit_both_induced: \"a \\<sim>\\<^sub>\\<K> b \\<longrightarrow> a \\<lhd> b \\<and> b \\<lhd> a\"\n  unfolding orbit_equivalent_def induced_def\n  by (blast intro: in_own_orbit)\n\ntext \\<open>\nLemma \\emph{strong-orbit-induce-same} states that if two agent behaviours are in the same strong orbit, then a third behaviour can be induced via  stimuli by either of \nthe behaviours within the strong orbit. This is to say that each behaviour in a strong orbit can induce the same set of behaviours\n(perhaps via different stimuli).\n\\<close>  \n\n\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/C2KA_DistributedSystems/Topology_C2KA.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.5660185351961015, "lm_q1q2_score": 0.285220232519147}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\n(* License: BSD, terms see file ./LICENSE *)\n\ntheory SepTactic\nimports SepInv\nbegin\n\nsection \"sep_point_tac\"\n\ndefinition sep_conj_extract :: \"heap_assert \\<Rightarrow> heap_assert\" where\n  \"sep_conj_extract \\<equiv> id\"\n\ndefinition sep_points :: \"heap_assert \\<Rightarrow> heap_assert\" where\n  \"sep_points P \\<equiv> P \\<and>\\<^sup>* sep_true\"\n\nlemma sep_conj_extract1D:\n  \"(P \\<and>\\<^sup>* Q) s \\<Longrightarrow> sep_conj_extract (P \\<and>\\<^sup>* Q) s\"\n  by (simp add: sep_conj_extract_def)\n\nlemma sep_conj_extract2D:\n  \"sep_conj_extract P s \\<Longrightarrow> P s \\<and> (sep_conj_extract P \\<and>\\<^sup>* sep_true) s\"\n  by (auto simp: sep_conj_extract_def elim: sep_conj_sep_true)\n\nlemma sep_conj_extract_assoc:\n  \"sep_conj_extract ((P \\<and>\\<^sup>* Q) \\<and>\\<^sup>* R) = sep_conj_extract (P \\<and>\\<^sup>* (Q \\<and>\\<^sup>* R))\"\n  by (simp add: sep_conj_ac)\n\nlemma sep_conj_extract_decomposeD:\n  \"(sep_conj_extract (P \\<and>\\<^sup>* Q) \\<and>\\<^sup>* sep_true) s \\<Longrightarrow> sep_points P s \\<and>\n      (sep_conj_extract Q \\<and>\\<^sup>* sep_true) s\"\n  apply (rule conjI)\n   apply(simp add: sep_conj_extract_def sep_points_def sep_conj_ac)\n   apply(erule (1) sep_conj_impl, simp)\n  apply(simp add: sep_conj_extract_def sep_conj_ac)\n  apply(subst (asm) sep_conj_assoc [symmetric])\n  apply(subst (asm) sep_conj_com)\n  apply(subst (asm) sep_conj_assoc)\n  apply(erule (1) sep_conj_impl)\n  apply simp\n  done\n\nlemma sep_conj_extract_decomposeD2:\n  \"(sep_conj_extract P \\<and>\\<^sup>* sep_true) s \\<Longrightarrow> sep_points P s\"\n  by (simp add: sep_conj_extract_def sep_points_def)\n\nlemma sep_point_mapD:\n  \"sep_points (p \\<mapsto>\\<^sup>i\\<^sub>g v) s \\<Longrightarrow> (p \\<hookrightarrow>\\<^sup>i\\<^sub>g v) s\"\n  by (simp add: sep_points_def sep_map_inv_def sep_map'_inv_def sep_map'_def\n                sep_conj_ac)\n\nlemma sep_point_map_excD:\n  \"sep_points (p \\<mapsto>\\<^sub>g v) s \\<Longrightarrow> (p \\<hookrightarrow>\\<^sub>g v) s\"\n  by (simp add: sep_points_def sep_map'_def)\n\nlemma sep_point_otherD:\n  \"sep_points P s \\<Longrightarrow> True\"\n  by (rule TrueI)\n\nML \\<open>\n\nval sep_point_ds = [@{thm sep_point_mapD}, @{thm sep_point_map_excD}]\n\nfun sep_point_tacs ds ctxt  = [\n    REPEAT1 (dresolve_tac ctxt [@{thm sep_conj_extract1D}] 1),\n    REPEAT1 (dresolve_tac ctxt [@{thm sep_conj_extract2D}] 1),\n    clarify_tac ctxt 1,\n    TRY (full_simp_tac (put_simpset HOL_ss ctxt addsimps\n        [@{thm sep_conj_extract_assoc}]) 1),\n    REPEAT (dresolve_tac ctxt [@{thm sep_conj_extract_decomposeD},\n        @{thm sep_conj_extract_decomposeD2}] 1 THEN\n        clarify_tac ctxt 1),\n    TRY (full_simp_tac ctxt 1),\n    REPEAT (dresolve_tac ctxt (sep_point_ds@ds) 1),\n    REPEAT (dresolve_tac ctxt [@{thm sep_point_otherD}] 1),\n    TRY (full_simp_tac ctxt 1)\n  ]\n\nfun sep_point_tac ds ctxt = EVERY (sep_point_tacs ds ctxt)\n\\<close>\n\nmethod_setup sep_point_tac =\n  \"Attrib.thms >> (fn thms => Method.SIMPLE_METHOD o sep_point_tac thms)\"\n  \"extract points-to facts from separation assertions in assumptions\"\n\nlemma \"(P \\<and>\\<^sup>* p \\<mapsto>\\<^sub>g v \\<and>\\<^sup>* Q) s \\<Longrightarrow> (p \\<hookrightarrow>\\<^bsub>g\\<^esub> v) s\"\n  by sep_point_tac\n\n\nsection \"sep_exists_tac\"\n\nML\\<open>\nfun sep_exists_tac ctxt = full_simp_tac\n    (put_simpset HOL_ss ctxt addsimps [@{thm \"sep_conj_exists1\"}, @{thm \"sep_conj_exists2\"}])\n\\<close>\n\nmethod_setup sep_exists_tac =\n  \"Scan.succeed (Method.SIMPLE_METHOD' o sep_exists_tac)\"\n  \"push existentials inside separation assertions to the outside\"\n\nlemma \"(P \\<and>\\<^sup>* (\\<lambda>s. (\\<exists>x. Q x s))) s \\<Longrightarrow> \\<exists>x. (P \\<and>\\<^sup>* Q x) s\"\n  by sep_exists_tac\n\nsection \"sep_select_tac\"\n\ndefinition sep_mark :: \"heap_assert \\<Rightarrow> heap_assert\" where\n  \"sep_mark \\<equiv> id\"\n\ndefinition sep_mark2 :: \"heap_assert \\<Rightarrow> heap_assert\" where\n  \"sep_mark2 \\<equiv> id\"\n\nlemma sep_mark2_id:\n  \"sep_mark2 P = P\"\n  by (simp add: sep_mark2_def)\n\nlemma sep_markI:\n  \"(\\<box> \\<and>\\<^sup>* sep_mark (P \\<and>\\<^sup>* Q)) s \\<Longrightarrow> (P \\<and>\\<^sup>* Q) s\"\n  by (simp add: sep_mark_def sep_conj_empty)\n\nlemma sep_mark_match:\n  \"(R \\<and>\\<^sup>* sep_mark2 P \\<and>\\<^sup>* Q) s \\<Longrightarrow> (R \\<and>\\<^sup>* sep_mark (P \\<and>\\<^sup>* Q)) s\"\n  by (simp add: sep_mark_def sep_mark2_def)\n\nlemma sep_mark_match2:\n  \"(R \\<and>\\<^sup>* sep_mark2 P) s \\<Longrightarrow> (R \\<and>\\<^sup>* sep_mark P) s\"\n  by (simp add: sep_mark_def sep_mark2_def)\n\nlemma sep_mark_mismatch:\n  \"((R \\<and>\\<^sup>* P) \\<and>\\<^sup>* sep_mark Q) s \\<Longrightarrow> (R \\<and>\\<^sup>* sep_mark (P \\<and>\\<^sup>* Q)) s\"\n  by (simp add: sep_mark_def sep_conj_ac)\n\nlemma sep_mark_mismatch2:\n  \"(R \\<and>\\<^sup>* P) s \\<Longrightarrow> (R \\<and>\\<^sup>* sep_mark P) s\"\n  by (simp add: sep_mark_def)\n\nlemma sep_emp_rem:\n  \"P s \\<Longrightarrow> (\\<box> \\<and>\\<^sup>* P) s\"\n  by (simp add: sep_conj_empty)\n\nlemma sep_mark2_left:\n  \"(P \\<and>\\<^sup>* (sep_mark2 Q \\<and>\\<^sup>* R)) = (sep_mark2 Q \\<and>\\<^sup>* (P \\<and>\\<^sup>* R))\"\n  by (rule sep_conj_left_com)\n\nlemma sep_mark2_left2:\n  \"(P \\<and>\\<^sup>* sep_mark2 Q) = (sep_mark2 Q \\<and>\\<^sup>* P)\"\n  by (rule sep_conj_com)\n\nML \\<open>\n\n(* Replace all occurrences of an underscore that does not have an alphanumeric\n   on either side of it *)\nlocal\n  val dummy_char = #\" \";\n  fun get_next (x::_) = x\n    | get_next [] = dummy_char;\n  fun nth_id n = \"SEPTAC\"^(Int.toString n);\n\n  fun ok_char c = not (Char.isAlphaNum c);\n\n  fun can_replace (prev,cur,last) =\n        (ok_char prev) andalso (cur = #\"_\") andalso (ok_char last);\n\n  fun replace_usc n prev_char (x::xs) =\n      let val (xs', ys) = replace_usc (n+1) x xs\n      in\n        if can_replace (prev_char,x,get_next xs)\n        then (nth_id n::xs', nth_id n::ys)\n        else (String.str x::xs', ys)\n      end\n    | replace_usc _ _ [] = ([],[])\nin\n  val rusc = apfst String.concat o replace_usc 0 dummy_char o String.explode\nend;\n\n(* some tests *)\nrusc \"(_ +\\<^sub>p _) \\<mapsto> _\";\nrusc \"_ \\<mapsto>\\<^sub>_ _\";\nrusc \"_\";\nrusc \"_ O_o _\"\n\\<close>\n\nML\\<open>\n\nfun sep_select_tacs s ctxt  =\n  let val (str, vars) = rusc s\n      val subst = [((Lexicon.read_indexname \"P\", Position.none), str)]\n      val fixes = map (fn v => (Binding.name v, NONE, Mixfix.NoSyn)) vars\n  in\n  [\n    TRY (simp_tac (put_simpset HOL_ss ctxt addsimps [@{thm sep_conj_assoc}]) 1),\n    resolve_tac ctxt [@{thm sep_markI}] 1,\n    REPEAT (Rule_Insts.res_inst_tac ctxt subst fixes @{thm sep_mark_match} 1 ORELSE\n      (Rule_Insts.res_inst_tac ctxt subst fixes @{thm sep_mark_match2} 1 ORELSE\n      resolve_tac ctxt [@{thm sep_mark_mismatch}] 1 ORELSE\n      resolve_tac ctxt [@{thm sep_mark_mismatch2}] 1)),\n    TRY (simp_tac (put_simpset HOL_ss ctxt addsimps [@{thm sep_conj_assoc}]) 1),\n    resolve_tac ctxt [@{thm sep_emp_rem}] 1,\n    TRY (simp_tac (put_simpset HOL_ss ctxt addsimps [@{thm sep_mark2_left},\n      @{thm sep_mark2_left2}]) 1),\n    TRY (simp_tac (put_simpset HOL_ss ctxt addsimps [@{thm sep_mark2_id}]) 1)\n  ]\n  end\n\nfun sep_select_tac s ctxt = SELECT_GOAL (EVERY (sep_select_tacs s ctxt))\n\nfun lift_parser p (ctxt,ts) =\n  let val (r, ts') = p ts\n  in (r, (ctxt,ts')) end\n\\<close>\n\nmethod_setup sep_select_tac =\n  \\<open>lift_parser Args.name >> (fn s => Method.SIMPLE_METHOD' o sep_select_tac s)\\<close>\n  \"takes a target conjunct in the goal and reorders it to the front\"\n\nlemma\n  \"\\<And>R x f n. ((P::heap_assert) \\<and>\\<^sup>* fac x n \\<and>\\<^sup>* R (f x)) s\"\n  apply(sep_select_tac \"fac _ _\")\n  apply(sep_select_tac \"R _\")\n  apply(sep_select_tac \"fac x _\")\n  apply(sep_select_tac \"R _\")\n  oops\n\nlemma\n  \"((P::heap_assert) \\<and>\\<^sup>* fac x n) s\"\n  apply(sep_select_tac \"fac _ _\")\n  oops\n\nlemma\n  \"((P::heap_assert) \\<and>\\<^sup>* long_name) s\"\n  apply(sep_select_tac \"long_name\")\n  oops\n\nconsts c_guard :: \"'a::c_type ptr_guard\"\n\nlemma sep_heap_update'_hrs:\n  \"(c_guard \\<turnstile>\\<^sub>s\\<^sup>i p \\<and>\\<^sup>* (p \\<mapsto>\\<^sup>i\\<^sub>c_guard v \\<longrightarrow>\\<^sup>* P)) (lift_state s) \\<Longrightarrow>\n      P (lift_state (hrs_mem_update (heap_update p (v::'a::mem_type)) s))\"\n  by (case_tac s)\n     (simp add: hrs_mem_update_def, erule sep_heap_update')\n\nlemma sep_map_lift_wp_hrs:\n  \"\\<lbrakk> \\<exists>v. (p \\<mapsto>\\<^sup>i\\<^sub>c_guard v \\<and>\\<^sup>* (p \\<mapsto>\\<^sup>i\\<^sub>c_guard v \\<longrightarrow>\\<^sup>* P v)) (lift_state s) \\<rbrakk>\n      \\<Longrightarrow> P (lift (hrs_mem s) (p::'a::mem_type ptr)) (lift_state s)\"\n  by (case_tac s)\n     (simp add: hrs_mem_def, erule sep_map_lift_wp)\n\nlemma ptr_retyp_sep_cut'_wp_hrs:\n  \"\\<lbrakk> (sep_cut' (ptr_val p) (size_of TYPE('a)) \\<and>\\<^sup>* (c_guard \\<turnstile>\\<^sub>s\\<^sup>i p \\<longrightarrow>\\<^sup>* P))\n      (lift_state s); c_guard (p::'a::mem_type ptr) \\<rbrakk>\n      \\<Longrightarrow> P (lift_state (hrs_htd_update (ptr_retyp p) s))\"\n  by (case_tac s)\n     (simp add: hrs_htd_update_def, erule (1) ptr_retyp_sep_cut'_wp)\n\nML \\<open>\n\nfun destruct bs (Bound n)      = Free (List.nth (bs,n))\n  | destruct bs (Abs (s,ty,t)) = destruct ((s,ty)::bs) t\n  | destruct bs (l$r)          = destruct bs l $ destruct bs r\n  | destruct _  x              = x\n\nfun schems (Abs (_,_,t)) = schems t\n  | schems (l$r)         = schems l + schems r\n  | schems (Var _)       = 1\n  | schems _             = 0\n\nfun hrs_mem_update (Const (@{const_name \"HeapRawState.hrs_mem_update\"},_)$_$s) = SOME s\n  | hrs_mem_update _                                             = NONE\n\nfun hrs_htd_update (Const (@{const_name \"HeapRawState.hrs_htd_update\"},_)$_$s) = SOME s\n  | hrs_htd_update _                                             = NONE\n\nfun lift_state_arg _   _  (Const (@{const_name \"TypHeap.lift_state\"},_)$s) = SOME s\n  | lift_state_arg thy nc (l$r)                              =\n        (case lift_state_arg thy nc r of\n          SOME s => if nc orelse hrs_mem_update s <> NONE orelse\n                        hrs_htd_update s <> NONE then SOME s\n                        else lift_state_arg thy nc l\n         | NONE   => lift_state_arg thy nc l)\n  | lift_state_arg thy nc (Abs (_,_,t))                      =\n        lift_state_arg thy nc t\n  | lift_state_arg _ _ _ =\n        NONE (*error (Sign.string_of_term thy s)*)\n\nfun term_of_thm thm = Thm.term_of (Thm.cprop_of thm)\n\nfun lift_tac ctxt s old_schems =\n  Rule_Insts.res_inst_tac ctxt [((Lexicon.read_indexname \"s\",Position.none),s)] [] @{thm sep_map_lift_wp_hrs} 1 THEN\n  (fn thm => if schems (term_of_thm thm) = old_schems then all_tac thm\n                 else no_tac thm)\n\nfun heap_update_tac ctxt s =\n  Rule_Insts.res_inst_tac ctxt [((Lexicon.read_indexname \"s\",Position.none),s)] [] @{thm sep_heap_update'_hrs} 1\n\nfun ptr_retyp_tac ctxt s =\n  Rule_Insts.res_inst_tac ctxt [((Lexicon.read_indexname \"s\",Position.none),s)] [] @{thm ptr_retyp_sep_cut'_wp_hrs} 1\n\nfun sep_wp_step_tac' ctxt lift_only s old_schems = let\n  fun prt s = (\n    case s of\n        Free (a, _) => a\n      | _ => raise TERM (\"Not a free variable\",[s]))\n  val state = prt s\n  val step = case hrs_mem_update s of\n               SOME s => heap_update_tac ctxt (prt s)\n             | NONE => case hrs_htd_update s of\n                         SOME s => ptr_retyp_tac ctxt (prt s)\n                       | NONE => no_tac\nin\n  TRY (lift_tac ctxt state old_schems) THEN (if lift_only then all_tac else step)\nend\n\nfun sep_wp_step_tac ctxt lift_only thm = let\n  val t = term_of_thm thm\n  val thy = Proof_Context.theory_of ctxt\n  val old_schems = schems t\n  val s = lift_state_arg thy lift_only (destruct [] t)\nin\n  (case s of\n    SOME state => sep_wp_step_tac' ctxt lift_only state old_schems\n   | NONE => no_tac) thm\nend\n\nfun sep_wp_tac ctxt = (REPEAT (sep_wp_step_tac ctxt false)) THEN sep_wp_step_tac ctxt true\n\n\\<close>\n\nmethod_setup sep_wp_tac =\n  \"Scan.succeed (Method.SIMPLE_METHOD o sep_wp_tac)\"\n  \"apply WP separation logic rules to goal\"\n\n\n(* see testfiles/sep_example_pre_list.thy for a more detailed example *)\nlemma\n  \"((\\<lambda>z. lift (hrs_mem s) (p::(32 word) ptr) + 1 = 2) \\<and>\\<^sup>* P) (lift_state s)\"\n  apply sep_wp_tac\n  oops\n\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/c-parser/umm_heap/SepTactic.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.5660185351961015, "lm_q1q2_score": 0.285220232519147}}
{"text": "(*******************************************************************************\n\n  Project: Development of Security Protocols by Refinement\n\n  Module:  Refinement/Runs.thy (Isabelle/HOL 2016-1)\n  ID:      $Id: Runs.thy 132773 2016-12-09 15:30:22Z csprenge $\n  Author:  Christoph Sprenger, ETH Zurich <sprenger@inf.ethz.ch>\n  \n  Protocol runs: local state of executing protocol roles\n\n  Copyright (c) 2010-2016 Christoph Sprenger \n  Licence: LGPL\n\n*******************************************************************************)\n\nsection \\<open>Protocol runs\\<close>\n\ntheory Runs imports Atoms\nbegin\n\n\n(******************************************************************************)\nsubsection \\<open>Runs\\<close>\n(******************************************************************************)\n\ntext \\<open>Define some typical roles.\\<close>\n\ndatatype role_t = Init | Resp | Serv\n\nfun \n  roleIdx :: \"role_t \\<Rightarrow> nat\"\nwhere\n  \"roleIdx Init = 0\"\n| \"roleIdx Resp = 1\"\n| \"roleIdx Serv = 2\"\n\n\ntext \\<open>The type of runs is a partial function from run identifiers to \na triple consisting of a role, a list of agents, and a list of atomic messages \nrecorded during the run's execution. \n\nThe type of roles could be made a parameter for more flexibility.\\<close>\n\ntype_synonym\n  rid_t = \"fid_t\"\n\ntype_synonym\n  runs_t = \"rid_t \\<rightharpoonup> role_t \\<times> agent list \\<times> atom list\"\n\n\nsubsection \\<open>Run abstraction\\<close>\n(******************************************************************************)\n\ntext \\<open>Define a function that lifts a function on roles and atom lists \nto a function on runs.\\<close>\n\ndefinition \n  map_runs :: \"([role_t, atom list] \\<Rightarrow> atom list) \\<Rightarrow> runs_t \\<Rightarrow> runs_t\"\nwhere\n  \"map_runs h runz rid \\<equiv> case runz rid of\n     None \\<Rightarrow> None\n   | Some (rol, agts, al) \\<Rightarrow> Some (rol, agts, h rol al)\"\n\nlemma map_runs_empty [simp]: \"map_runs h Map.empty = Map.empty\"\nby (rule ext) (auto simp add: map_runs_def)\n\nlemma map_runs_dom [simp]: \"dom (map_runs h runz) = dom runz\"\nby (auto simp add: map_runs_def split: option.split_asm)\n\nlemma map_runs_update [simp]:\n  \"map_runs h (runz(R \\<mapsto> (rol, agts, al))) \n   = (map_runs h runz)(R \\<mapsto> (rol, agts, h rol al))\"\nby (auto simp add: map_runs_def)\n\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Security_Protocol_Refinement/Refinement/Runs.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6513548782017745, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.2851784719394057}}
{"text": "theory ArityAnalysisImpl\nimports ArityAnalysisFix ArityAnalysisPreImpl\nbegin\n\ndefinition Real_Aexp where \"Real_Aexp = ArityAnalysisPreImpl.Aexp ArityAnalysis.Afix\"\n\nlemma heap_exp_are_smaller:  \"e \\<in> snd ` set \\<Gamma> \\<Longrightarrow> size e \\<le> size_list (\\<lambda>p. size (snd p)) \\<Gamma>\"\n  by (metis (mono_tags) imageE order_refl size_list_estimation')\n\ninterpretation ArityAnalysisPreImpl ArityAnalysis.Afix where \"Aexp = ArityAnalysisImpl.Real_Aexp\"\n  unfolding Real_Aexp_def atomize_conj\n  apply (rule conjI[OF _ refl])\n  apply default\n  apply (perm_simp, rule)\n  apply (rule ArityAnalysisFix.Afix_cong)\n  apply (metis heap_exp_are_smaller)\n  apply assumption\n  done\n\ninterpretation ArityAnalysis Aexp.\n\nlemma Aexp_edom': \"edom (Aexp e\\<cdot>a) \\<subseteq> fv e\"\n  by (nominal_induct arbitrary: a rule: exp_strong_induct) fastforce+\n\nend\n", "meta": {"author": "nomeata", "repo": "isa-launchbury", "sha": "2caa8d7d588e218aef1c49f2f327597af06d116e", "save_path": "github-repos/isabelle/nomeata-isa-launchbury", "path": "github-repos/isabelle/nomeata-isa-launchbury/isa-launchbury-2caa8d7d588e218aef1c49f2f327597af06d116e/Scratchpad/ArityAnalysisImpl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6513548646660542, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.2851784660131493}}
{"text": "section \\<open>Final Instantiation of Algorithms Related to Complementation\\<close>\n\ntheory Complementation_Final\nimports\n  \"Complementation_Implement\"\n  \"Formula\"\n  \"Transition_Systems_and_Automata.NBA_Translate\"\n  \"Transition_Systems_and_Automata.NGBA_Algorithms\"\n  \"HOL-Library.Multiset\"\nbegin\n\n  subsection \\<open>Syntax\\<close>\n\n  (* TODO: this syntax has unnecessarily high inner binding strength, requiring extra parentheses\n    the regular let syntax correctly uses inner binding strength 0: (\"(2_ =/ _)\" 10) *)\n  no_syntax \"_do_let\" :: \"[pttrn, 'a] \\<Rightarrow> do_bind\" (\"(2let _ =/ _)\" [1000, 13] 13)\n  syntax \"_do_let\" :: \"[pttrn, 'a] \\<Rightarrow> do_bind\" (\"(2let _ =/ _)\" 13)\n\n  subsection \\<open>Hashcodes on Complement States\\<close>\n\n  definition \"hci k \\<equiv> uint32_of_nat k * 1103515245 + 12345\"\n  definition \"hc \\<equiv> \\<lambda> (p, q, b). hci p + hci q * 31 + (if b then 1 else 0)\"\n  definition \"list_hash xs \\<equiv> fold (xor \\<circ> hc) xs 0\"\n\n  lemma list_hash_eq:\n    assumes \"distinct xs\" \"distinct ys\" \"set xs = set ys\"\n    shows \"list_hash xs = list_hash ys\"\n  proof -\n    have \"mset (remdups xs) = mset (remdups ys)\" using assms(3)\n      using set_eq_iff_mset_remdups_eq by blast \n    then have \"mset xs = mset ys\" using assms(1, 2) by (simp add: distinct_remdups_id)\n    have \"fold (xor \\<circ> hc) xs = fold (xor \\<circ> hc) ys\"\n      apply (rule fold_multiset_equiv)\n       apply (simp_all add: fun_eq_iff ac_simps)\n      using \\<open>mset xs = mset ys\\<close> .\n    then show ?thesis unfolding list_hash_def by simp\n  qed\n\n  definition state_hash :: \"nat \\<Rightarrow> Complementation_Implement.state \\<Rightarrow> nat\" where\n    \"state_hash n p \\<equiv> nat_of_hashcode (list_hash p) mod n\"\n\n  lemma state_hash_bounded_hashcode[autoref_ga_rules]: \"is_bounded_hashcode state_rel\n    (gen_equals (Gen_Map.gen_ball (foldli \\<circ> list_map_to_list)) (list_map_lookup (=))\n    (prod_eq (=) (\\<longleftrightarrow>))) state_hash\"\n  proof\n    show [param]: \"(gen_equals (Gen_Map.gen_ball (foldli \\<circ> list_map_to_list)) (list_map_lookup (=))\n      (prod_eq (=) (\\<longleftrightarrow>)), (=)) \\<in> state_rel \\<rightarrow> state_rel \\<rightarrow> bool_rel\" by autoref\n    show \"state_hash n xs = state_hash n ys\" if \"xs \\<in> Domain state_rel\" \"ys \\<in> Domain state_rel\"\n      \"gen_equals (Gen_Map.gen_ball (foldli \\<circ> list_map_to_list))\n      (list_map_lookup (=)) (prod_eq (=) (=)) xs ys\" for xs ys n\n    proof -\n      have 1: \"distinct (map fst xs)\" \"distinct (map fst ys)\"\n        using that(1, 2) unfolding list_map_rel_def list_map_invar_def by (auto simp: in_br_conv)\n      have 2: \"distinct xs\" \"distinct ys\" using 1 by (auto intro: distinct_mapI)\n      have 3: \"(xs, map_of xs) \\<in> state_rel\" \"(ys, map_of ys) \\<in> state_rel\"\n        using 1 unfolding list_map_rel_def list_map_invar_def by (auto simp: in_br_conv)\n      have 4: \"(gen_equals (Gen_Map.gen_ball (foldli \\<circ> list_map_to_list)) (list_map_lookup (=))\n        (prod_eq (=) (\\<longleftrightarrow>)) xs ys, map_of xs = map_of ys) \\<in> bool_rel\" using 3 by parametricity\n      have 5: \"map_to_set (map_of xs) = map_to_set (map_of ys)\" using that(3) 4 by simp\n      have 6: \"set xs = set ys\" using map_to_set_map_of 1 5 by blast\n      show \"state_hash n xs = state_hash n ys\" unfolding state_hash_def using list_hash_eq 2 6 by metis\n    qed\n    show \"state_hash n x < n\" if \"1 < n\" for n x using that unfolding state_hash_def by simp\n  qed\n\n  subsection \\<open>Complementation\\<close>\n\n  schematic_goal complement_impl:\n    assumes [simp]: \"finite (NBA.nodes A)\"\n    assumes [autoref_rules]: \"(Ai, A) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    shows \"(?f :: ?'c, op_translate (complement_4 A)) \\<in> ?R\"\n    by (autoref_monadic (plain))\n  concrete_definition complement_impl uses complement_impl\n\n  theorem complement_impl_correct:\n    assumes \"finite (NBA.nodes A)\"\n    assumes \"(Ai, A) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    shows \"NBA.language (nbae_nba (nbaei_nbae (complement_impl Ai))) =\n      streams (nba.alphabet A) - NBA.language A\"\n    using op_translate_language[OF complement_impl.refine[OF assms]]\n    using complement_4_correct[OF assms(1)]\n    by simp\n\n  subsection \\<open>Language Subset\\<close>\n\n  definition [simp]: \"op_language_subset A B \\<equiv> NBA.language A \\<subseteq> NBA.language B\"\n\n  lemmas [autoref_op_pat] = op_language_subset_def[symmetric]\n\n  schematic_goal language_subset_impl:\n    assumes [simp]: \"finite (NBA.nodes B)\"\n    assumes [autoref_rules]: \"(Ai, A) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    assumes [autoref_rules]: \"(Bi, B) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    shows \"(?f :: ?'c, do {\n      let AB' = intersect' A (complement_4 B);\n      ASSERT (finite (NGBA.nodes AB'));\n      RETURN (NGBA.language AB' = {})\n    }) \\<in> ?R\"\n\t\tby (autoref_monadic (plain))\n  concrete_definition language_subset_impl uses language_subset_impl\n  lemma language_subset_impl_refine[autoref_rules]:\n    assumes \"SIDE_PRECOND (finite (NBA.nodes A))\"\n    assumes \"SIDE_PRECOND (finite (NBA.nodes B))\"\n    assumes \"SIDE_PRECOND (nba.alphabet A \\<subseteq> nba.alphabet B)\"\n    assumes \"(Ai, A) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    assumes \"(Bi, B) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    shows \"(language_subset_impl Ai Bi, (OP op_language_subset :::\n      \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel \\<rightarrow> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel \\<rightarrow> bool_rel) $ A $ B) \\<in> bool_rel\"\n  proof -\n    have \"(RETURN (language_subset_impl Ai Bi), do {\n      let AB' = intersect' A (complement_4 B);\n      ASSERT (finite (NGBA.nodes AB'));\n      RETURN (NGBA.language AB' = {})\n    }) \\<in> \\<langle>bool_rel\\<rangle> nres_rel\"\n      using language_subset_impl.refine assms(2, 4, 5) unfolding autoref_tag_defs by this\n    also have \"(do {\n      let AB' = intersect' A (complement_4 B);\n      ASSERT (finite (NGBA.nodes AB'));\n      RETURN (NGBA.language AB' = {})\n    }, RETURN (NBA.language A \\<subseteq> NBA.language B)) \\<in> \\<langle>bool_rel\\<rangle> nres_rel\"\n    proof refine_vcg\n      show \"finite (NGBA.nodes (intersect' A (complement_4 B)))\" using assms(1, 2) by auto\n      have 1: \"NBA.language A \\<subseteq> streams (nba.alphabet B)\"\n        using nba.language_alphabet streams_mono2 assms(3) unfolding autoref_tag_defs by blast\n      have 2: \"NBA.language (complement_4 B) = streams (nba.alphabet B) - NBA.language B\"\n        using complement_4_correct assms(2) by auto\n      show \"(NGBA.language (intersect' A (complement_4 B)) = {},\n        NBA.language A \\<subseteq> NBA.language B) \\<in> bool_rel\" using 1 2 by auto\n    qed\n    finally show ?thesis using RETURN_nres_relD unfolding nres_rel_comp by force\n  qed\n\n  subsection \\<open>Language Equality\\<close>\n\n  definition [simp]: \"op_language_equal A B \\<equiv> NBA.language A = NBA.language B\"\n\n  lemmas [autoref_op_pat] = op_language_equal_def[symmetric]\n\n  schematic_goal language_equal_impl:\n    assumes [simp]: \"finite (NBA.nodes A)\"\n    assumes [simp]: \"finite (NBA.nodes B)\"\n    assumes [simp]: \"nba.alphabet A = nba.alphabet B\"\n    assumes [autoref_rules]: \"(Ai, A) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    assumes [autoref_rules]: \"(Bi, B) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    shows \"(?f :: ?'c, NBA.language A \\<subseteq> NBA.language B \\<and> NBA.language B \\<subseteq> NBA.language A) \\<in> ?R\"\n    by autoref\n  concrete_definition language_equal_impl uses language_equal_impl\n  lemma language_equal_impl_refine[autoref_rules]:\n    assumes \"SIDE_PRECOND (finite (NBA.nodes A))\"\n    assumes \"SIDE_PRECOND (finite (NBA.nodes B))\"\n    assumes \"SIDE_PRECOND (nba.alphabet A = nba.alphabet B)\"\n    assumes \"(Ai, A) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    assumes \"(Bi, B) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    shows \"(language_equal_impl Ai Bi, (OP op_language_equal :::\n      \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel \\<rightarrow> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel \\<rightarrow> bool_rel) $ A $ B) \\<in> bool_rel\"\n    using language_equal_impl.refine[OF assms[unfolded autoref_tag_defs]] by auto\n\n  schematic_goal product_impl:\n    assumes [simp]: \"finite (NBA.nodes B)\"\n    assumes [autoref_rules]: \"(Ai, A) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    assumes [autoref_rules]: \"(Bi, B) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    shows \"(?f :: ?'c, do {\n      let AB' = intersect A (complement_4 B);\n      ASSERT (finite (NBA.nodes AB'));\n      op_translate AB'\n    }) \\<in> ?R\"\n\t\tby (autoref_monadic (plain))\n  concrete_definition product_impl uses product_impl\n\n  (* TODO: possible optimizations:\n    - introduce op_map_map operation for maps instead of manually iterating via FOREACH\n    - consolidate various binds and maps in expand_map_get_7 *)\n  export_code\n    Set.empty Set.insert Set.member\n    \"Inf :: 'a set set \\<Rightarrow> 'a set\" \"Sup :: 'a set set \\<Rightarrow> 'a set\" image Pow set\n    nat_of_integer integer_of_nat\n    Variable Negation Conjunction Disjunction satisfies map_formula\n    nbaei alphabetei initialei transitionei acceptingei\n    nbae_nba_impl complement_impl language_equal_impl product_impl\n    in SML module_name Complementation file_prefix Complementation\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Buchi_Complementation/Complementation_Final.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526514141572, "lm_q2_score": 0.5, "lm_q1q2_score": 0.2849263257070786}}
{"text": "(*  Title:      HOL/HOLCF/IOA/meta_theory/CompoScheds.thy\n    Author:     Olaf Müller\n*)\n\nsection {* Compositionality on Schedule level *}\n\ntheory CompoScheds\nimports CompoExecs\nbegin\n\ndefinition\n  mkex2 :: \"('a,'s)ioa => ('a,'t)ioa => 'a Seq ->\n              ('a,'s)pairs -> ('a,'t)pairs ->\n              ('s => 't => ('a,'s*'t)pairs)\" where\n  \"mkex2 A B = (fix$(LAM h sch exA exB. (%s t. case sch of\n       nil => nil\n    | x##xs =>\n      (case x of\n        UU => UU\n      | Def y =>\n         (if y:act A then\n             (if y:act B then\n                (case HD$exA of\n                   UU => UU\n                 | Def a => (case HD$exB of\n                              UU => UU\n                            | Def b =>\n                   (y,(snd a,snd b))>>\n                     (h$xs$(TL$exA)$(TL$exB)) (snd a) (snd b)))\n              else\n                (case HD$exA of\n                   UU => UU\n                 | Def a =>\n                   (y,(snd a,t))>>(h$xs$(TL$exA)$exB) (snd a) t)\n              )\n          else\n             (if y:act B then\n                (case HD$exB of\n                   UU => UU\n                 | Def b =>\n                   (y,(s,snd b))>>(h$xs$exA$(TL$exB)) s (snd b))\n             else\n               UU\n             )\n         )\n       ))))\"\n\ndefinition\n  mkex :: \"('a,'s)ioa => ('a,'t)ioa => 'a Seq =>\n              ('a,'s)execution => ('a,'t)execution =>('a,'s*'t)execution\" where\n  \"mkex A B sch exA exB =\n       ((fst exA,fst exB),\n        (mkex2 A B$sch$(snd exA)$(snd exB)) (fst exA) (fst exB))\"\n\ndefinition\n  par_scheds ::\"['a schedule_module,'a schedule_module] => 'a schedule_module\" where\n  \"par_scheds SchedsA SchedsB =\n      (let schA = fst SchedsA; sigA = snd SchedsA;\n           schB = fst SchedsB; sigB = snd SchedsB\n       in\n       (    {sch. Filter (%a. a:actions sigA)$sch : schA}\n        Int {sch. Filter (%a. a:actions sigB)$sch : schB}\n        Int {sch. Forall (%x. x:(actions sigA Un actions sigB)) sch},\n        asig_comp sigA sigB))\"\n\n\nsubsection \"mkex rewrite rules\"\n\n\nlemma mkex2_unfold:\n\"mkex2 A B = (LAM sch exA exB. (%s t. case sch of\n      nil => nil\n   | x##xs =>\n     (case x of\n       UU => UU\n     | Def y =>\n        (if y:act A then\n            (if y:act B then\n               (case HD$exA of\n                  UU => UU\n                | Def a => (case HD$exB of\n                             UU => UU\n                           | Def b =>\n                  (y,(snd a,snd b))>>\n                    (mkex2 A B$xs$(TL$exA)$(TL$exB)) (snd a) (snd b)))\n             else\n               (case HD$exA of\n                  UU => UU\n                | Def a =>\n                  (y,(snd a,t))>>(mkex2 A B$xs$(TL$exA)$exB) (snd a) t)\n             )\n         else\n            (if y:act B then\n               (case HD$exB of\n                  UU => UU\n                | Def b =>\n                  (y,(s,snd b))>>(mkex2 A B$xs$exA$(TL$exB)) s (snd b))\n            else\n              UU\n            )\n        )\n      )))\"\napply (rule trans)\napply (rule fix_eq2)\napply (simp only: mkex2_def)\napply (rule beta_cfun)\napply simp\ndone\n\nlemma mkex2_UU: \"(mkex2 A B$UU$exA$exB) s t = UU\"\napply (subst mkex2_unfold)\napply simp\ndone\n\nlemma mkex2_nil: \"(mkex2 A B$nil$exA$exB) s t= nil\"\napply (subst mkex2_unfold)\napply simp\ndone\n\nlemma mkex2_cons_1: \"[| x:act A; x~:act B; HD$exA=Def a|]\n    ==> (mkex2 A B$(x>>sch)$exA$exB) s t =\n        (x,snd a,t) >> (mkex2 A B$sch$(TL$exA)$exB) (snd a) t\"\napply (rule trans)\napply (subst mkex2_unfold)\napply (simp add: Consq_def If_and_if)\napply (simp add: Consq_def)\ndone\n\nlemma mkex2_cons_2: \"[| x~:act A; x:act B; HD$exB=Def b|]\n    ==> (mkex2 A B$(x>>sch)$exA$exB) s t =\n        (x,s,snd b) >> (mkex2 A B$sch$exA$(TL$exB)) s (snd b)\"\napply (rule trans)\napply (subst mkex2_unfold)\napply (simp add: Consq_def If_and_if)\napply (simp add: Consq_def)\ndone\n\nlemma mkex2_cons_3: \"[| x:act A; x:act B; HD$exA=Def a;HD$exB=Def b|]\n    ==> (mkex2 A B$(x>>sch)$exA$exB) s t =\n         (x,snd a,snd b) >>\n            (mkex2 A B$sch$(TL$exA)$(TL$exB)) (snd a) (snd b)\"\napply (rule trans)\napply (subst mkex2_unfold)\napply (simp add: Consq_def If_and_if)\napply (simp add: Consq_def)\ndone\n\ndeclare mkex2_UU [simp] mkex2_nil [simp] mkex2_cons_1 [simp]\n  mkex2_cons_2 [simp] mkex2_cons_3 [simp]\n\n\nsubsection {* mkex *}\n\nlemma mkex_UU: \"mkex A B UU  (s,exA) (t,exB) = ((s,t),UU)\"\napply (simp add: mkex_def)\ndone\n\nlemma mkex_nil: \"mkex A B nil (s,exA) (t,exB) = ((s,t),nil)\"\napply (simp add: mkex_def)\ndone\n\nlemma mkex_cons_1: \"[| x:act A; x~:act B |]\n    ==> mkex A B (x>>sch) (s,a>>exA) (t,exB)  =\n        ((s,t), (x,snd a,t) >> snd (mkex A B sch (snd a,exA) (t,exB)))\"\napply (simp (no_asm) add: mkex_def)\napply (cut_tac exA = \"a>>exA\" in mkex2_cons_1)\napply auto\ndone\n\nlemma mkex_cons_2: \"[| x~:act A; x:act B |]\n    ==> mkex A B (x>>sch) (s,exA) (t,b>>exB) =\n        ((s,t), (x,s,snd b) >> snd (mkex A B sch (s,exA) (snd b,exB)))\"\napply (simp (no_asm) add: mkex_def)\napply (cut_tac exB = \"b>>exB\" in mkex2_cons_2)\napply auto\ndone\n\nlemma mkex_cons_3: \"[| x:act A; x:act B |]\n    ==>  mkex A B (x>>sch) (s,a>>exA) (t,b>>exB) =\n         ((s,t), (x,snd a,snd b) >> snd (mkex A B sch (snd a,exA) (snd b,exB)))\"\napply (simp (no_asm) add: mkex_def)\napply (cut_tac exB = \"b>>exB\" and exA = \"a>>exA\" in mkex2_cons_3)\napply auto\ndone\n\ndeclare mkex2_UU [simp del] mkex2_nil [simp del]\n  mkex2_cons_1 [simp del] mkex2_cons_2 [simp del] mkex2_cons_3 [simp del]\n\nlemmas composch_simps = mkex_UU mkex_nil mkex_cons_1 mkex_cons_2 mkex_cons_3\n\ndeclare composch_simps [simp]\n\n\nsubsection {* COMPOSITIONALITY on SCHEDULE Level *}\n\nsubsubsection \"Lemmas for ==>\"\n\n(* --------------------------------------------------------------------- *)\n(*    Lemma_2_1 :  tfilter(ex) and filter_act are commutative            *)\n(* --------------------------------------------------------------------- *)\n\nlemma lemma_2_1a:\n   \"filter_act$(Filter_ex2 (asig_of A)$xs)=\n    Filter (%a. a:act A)$(filter_act$xs)\"\n\napply (unfold filter_act_def Filter_ex2_def)\napply (simp (no_asm) add: MapFilter o_def)\ndone\n\n\n(* --------------------------------------------------------------------- *)\n(*    Lemma_2_2 : State-projections do not affect filter_act             *)\n(* --------------------------------------------------------------------- *)\n\nlemma lemma_2_1b:\n   \"filter_act$(ProjA2$xs) =filter_act$xs &\n    filter_act$(ProjB2$xs) =filter_act$xs\"\napply (tactic {* pair_induct_tac @{context} \"xs\" [] 1 *})\ndone\n\n\n(* --------------------------------------------------------------------- *)\n(*             Schedules of A||B have only  A- or B-actions              *)\n(* --------------------------------------------------------------------- *)\n\n(* very similar to lemma_1_1c, but it is not checking if every action element of\n   an ex is in A or B, but after projecting it onto the action schedule. Of course, this\n   is the same proposition, but we cannot change this one, when then rather lemma_1_1c  *)\n\nlemma sch_actions_in_AorB: \"!s. is_exec_frag (A||B) (s,xs)\n   --> Forall (%x. x:act (A||B)) (filter_act$xs)\"\n\napply (tactic {* pair_induct_tac @{context} \"xs\" [@{thm is_exec_frag_def}, @{thm Forall_def},\n  @{thm sforall_def}] 1 *})\n(* main case *)\napply auto\napply (simp add: trans_of_defs2 actions_asig_comp asig_of_par)\ndone\n\n\nsubsubsection \"Lemmas for <==\"\n\n(*---------------------------------------------------------------------------\n    Filtering actions out of mkex(sch,exA,exB) yields the oracle sch\n                             structural induction\n  --------------------------------------------------------------------------- *)\n\nlemma Mapfst_mkex_is_sch: \"! exA exB s t.\n  Forall (%x. x:act (A||B)) sch  &\n  Filter (%a. a:act A)$sch << filter_act$exA &\n  Filter (%a. a:act B)$sch << filter_act$exB\n  --> filter_act$(snd (mkex A B sch (s,exA) (t,exB))) = sch\"\n\napply (tactic {* Seq_induct_tac @{context} \"sch\" [@{thm Filter_def}, @{thm Forall_def},\n  @{thm sforall_def}, @{thm mkex_def}] 1 *})\n\n(* main case *)\n(* splitting into 4 cases according to a:A, a:B *)\napply auto\n\n(* Case y:A, y:B *)\napply (tactic {* Seq_case_simp_tac @{context} \"exA\" 1 *})\n(* Case exA=UU, Case exA=nil*)\n(* These UU and nil cases are the only places where the assumption filter A sch<<f_act exA\n   is used! --> to generate a contradiction using  ~a>>ss<< UU(nil), using theorems\n   Cons_not_less_UU and Cons_not_less_nil  *)\napply (tactic {* Seq_case_simp_tac @{context} \"exB\" 1 *})\n(* Case exA=a>>x, exB=b>>y *)\n(* here it is important that Seq_case_simp_tac uses no !full!_simp_tac for the cons case,\n   as otherwise mkex_cons_3 would  not be rewritten without use of rotate_tac: then tactic\n   would not be generally applicable *)\napply simp\n\n(* Case y:A, y~:B *)\napply (tactic {* Seq_case_simp_tac @{context} \"exA\" 1 *})\napply simp\n\n(* Case y~:A, y:B *)\napply (tactic {* Seq_case_simp_tac @{context} \"exB\" 1 *})\napply simp\n\n(* Case y~:A, y~:B *)\napply (simp add: asig_of_par actions_asig_comp)\ndone\n\n\n(* generalizing the proof above to a proof method *)\n\nML {*\n\nlocal\n  val defs = [@{thm Filter_def}, @{thm Forall_def}, @{thm sforall_def}, @{thm mkex_def},\n    @{thm stutter_def}]\n  val asigs = [@{thm asig_of_par}, @{thm actions_asig_comp}]\nin\n\nfun mkex_induct_tac ctxt sch exA exB =\n  EVERY'[Seq_induct_tac ctxt sch defs,\n         asm_full_simp_tac ctxt,\n         SELECT_GOAL\n          (safe_tac (Context.raw_transfer (Proof_Context.theory_of ctxt) @{theory_context Fun})),\n         Seq_case_simp_tac ctxt exA,\n         Seq_case_simp_tac ctxt exB,\n         asm_full_simp_tac ctxt,\n         Seq_case_simp_tac ctxt exA,\n         asm_full_simp_tac ctxt,\n         Seq_case_simp_tac ctxt exB,\n         asm_full_simp_tac ctxt,\n         asm_full_simp_tac (ctxt addsimps asigs)\n        ]\n\nend\n*}\n\nmethod_setup mkex_induct = {*\n  Scan.lift (Args.name -- Args.name -- Args.name)\n    >> (fn ((sch, exA), exB) => fn ctxt => SIMPLE_METHOD' (mkex_induct_tac ctxt sch exA exB))\n*}\n\n\n(*---------------------------------------------------------------------------\n               Projection of mkex(sch,exA,exB) onto A stutters on A\n                             structural induction\n  --------------------------------------------------------------------------- *)\n\nlemma stutterA_mkex: \"! exA exB s t.\n  Forall (%x. x:act (A||B)) sch &\n  Filter (%a. a:act A)$sch << filter_act$exA &\n  Filter (%a. a:act B)$sch << filter_act$exB\n  --> stutter (asig_of A) (s,ProjA2$(snd (mkex A B sch (s,exA) (t,exB))))\"\n  by (mkex_induct sch exA exB)\n\nlemma stutter_mkex_on_A: \"[|\n  Forall (%x. x:act (A||B)) sch ;\n  Filter (%a. a:act A)$sch << filter_act$(snd exA) ;\n  Filter (%a. a:act B)$sch << filter_act$(snd exB) |]\n  ==> stutter (asig_of A) (ProjA (mkex A B sch exA exB))\"\n\napply (cut_tac stutterA_mkex)\napply (simp add: stutter_def ProjA_def mkex_def)\napply (erule allE)+\napply (drule mp)\nprefer 2 apply (assumption)\napply simp\ndone\n\n\n(*---------------------------------------------------------------------------\n               Projection of mkex(sch,exA,exB) onto B stutters on B\n                             structural induction\n  --------------------------------------------------------------------------- *)\n\nlemma stutterB_mkex: \"! exA exB s t.\n  Forall (%x. x:act (A||B)) sch &\n  Filter (%a. a:act A)$sch << filter_act$exA &\n  Filter (%a. a:act B)$sch << filter_act$exB\n  --> stutter (asig_of B) (t,ProjB2$(snd (mkex A B sch (s,exA) (t,exB))))\"\n  by (mkex_induct sch exA exB)\n\n\nlemma stutter_mkex_on_B: \"[|\n  Forall (%x. x:act (A||B)) sch ;\n  Filter (%a. a:act A)$sch << filter_act$(snd exA) ;\n  Filter (%a. a:act B)$sch << filter_act$(snd exB) |]\n  ==> stutter (asig_of B) (ProjB (mkex A B sch exA exB))\"\napply (cut_tac stutterB_mkex)\napply (simp add: stutter_def ProjB_def mkex_def)\napply (erule allE)+\napply (drule mp)\nprefer 2 apply (assumption)\napply simp\ndone\n\n\n(*---------------------------------------------------------------------------\n     Filter of mkex(sch,exA,exB) to A after projection onto A is exA\n        --  using zip$(proj1$exA)$(proj2$exA) instead of exA    --\n        --           because of admissibility problems          --\n                             structural induction\n  --------------------------------------------------------------------------- *)\n\nlemma filter_mkex_is_exA_tmp: \"! exA exB s t.\n  Forall (%x. x:act (A||B)) sch &\n  Filter (%a. a:act A)$sch << filter_act$exA  &\n  Filter (%a. a:act B)$sch << filter_act$exB\n  --> Filter_ex2 (asig_of A)$(ProjA2$(snd (mkex A B sch (s,exA) (t,exB)))) =\n      Zip$(Filter (%a. a:act A)$sch)$(Map snd$exA)\"\n  by (mkex_induct sch exB exA)\n\n(*---------------------------------------------------------------------------\n                      zip$(proj1$y)$(proj2$y) = y   (using the lift operations)\n                    lemma for admissibility problems\n  --------------------------------------------------------------------------- *)\n\nlemma Zip_Map_fst_snd: \"Zip$(Map fst$y)$(Map snd$y) = y\"\napply (tactic {* Seq_induct_tac @{context} \"y\" [] 1 *})\ndone\n\n\n(*---------------------------------------------------------------------------\n      filter A$sch = proj1$ex   -->  zip$(filter A$sch)$(proj2$ex) = ex\n         lemma for eliminating non admissible equations in assumptions\n  --------------------------------------------------------------------------- *)\n\nlemma trick_against_eq_in_ass: \"!! sch ex.\n  Filter (%a. a:act AB)$sch = filter_act$ex\n  ==> ex = Zip$(Filter (%a. a:act AB)$sch)$(Map snd$ex)\"\napply (simp add: filter_act_def)\napply (rule Zip_Map_fst_snd [symmetric])\ndone\n\n(*---------------------------------------------------------------------------\n     Filter of mkex(sch,exA,exB) to A after projection onto A is exA\n                       using the above trick\n  --------------------------------------------------------------------------- *)\n\n\nlemma filter_mkex_is_exA: \"!!sch exA exB.\n  [| Forall (%a. a:act (A||B)) sch ;\n  Filter (%a. a:act A)$sch = filter_act$(snd exA)  ;\n  Filter (%a. a:act B)$sch = filter_act$(snd exB) |]\n  ==> Filter_ex (asig_of A) (ProjA (mkex A B sch exA exB)) = exA\"\napply (simp add: ProjA_def Filter_ex_def)\napply (tactic {* pair_tac @{context} \"exA\" 1 *})\napply (tactic {* pair_tac @{context} \"exB\" 1 *})\napply (rule conjI)\napply (simp (no_asm) add: mkex_def)\napply (simplesubst trick_against_eq_in_ass)\nback\napply assumption\napply (simp add: filter_mkex_is_exA_tmp)\ndone\n\n\n(*---------------------------------------------------------------------------\n     Filter of mkex(sch,exA,exB) to B after projection onto B is exB\n        --  using zip$(proj1$exB)$(proj2$exB) instead of exB    --\n        --           because of admissibility problems          --\n                             structural induction\n  --------------------------------------------------------------------------- *)\n\nlemma filter_mkex_is_exB_tmp: \"! exA exB s t.\n  Forall (%x. x:act (A||B)) sch &\n  Filter (%a. a:act A)$sch << filter_act$exA  &\n  Filter (%a. a:act B)$sch << filter_act$exB\n  --> Filter_ex2 (asig_of B)$(ProjB2$(snd (mkex A B sch (s,exA) (t,exB)))) =\n      Zip$(Filter (%a. a:act B)$sch)$(Map snd$exB)\"\n\n(* notice necessary change of arguments exA and exB *)\n  by (mkex_induct sch exA exB)\n\n\n(*---------------------------------------------------------------------------\n     Filter of mkex(sch,exA,exB) to A after projection onto B is exB\n                       using the above trick\n  --------------------------------------------------------------------------- *)\n\n\nlemma filter_mkex_is_exB: \"!!sch exA exB.\n  [| Forall (%a. a:act (A||B)) sch ;\n  Filter (%a. a:act A)$sch = filter_act$(snd exA)  ;\n  Filter (%a. a:act B)$sch = filter_act$(snd exB) |]\n  ==> Filter_ex (asig_of B) (ProjB (mkex A B sch exA exB)) = exB\"\napply (simp add: ProjB_def Filter_ex_def)\napply (tactic {* pair_tac @{context} \"exA\" 1 *})\napply (tactic {* pair_tac @{context} \"exB\" 1 *})\napply (rule conjI)\napply (simp (no_asm) add: mkex_def)\napply (simplesubst trick_against_eq_in_ass)\nback\napply assumption\napply (simp add: filter_mkex_is_exB_tmp)\ndone\n\n(* --------------------------------------------------------------------- *)\n(*                    mkex has only  A- or B-actions                    *)\n(* --------------------------------------------------------------------- *)\n\n\nlemma mkex_actions_in_AorB: \"!s t exA exB.\n  Forall (%x. x : act (A || B)) sch &\n  Filter (%a. a:act A)$sch << filter_act$exA  &\n  Filter (%a. a:act B)$sch << filter_act$exB\n   --> Forall (%x. fst x : act (A ||B))\n         (snd (mkex A B sch (s,exA) (t,exB)))\"\n  by (mkex_induct sch exA exB)\n\n\n(* ------------------------------------------------------------------ *)\n(*           COMPOSITIONALITY   on    SCHEDULE      Level             *)\n(*                          Main Theorem                              *)\n(* ------------------------------------------------------------------ *)\n\nlemma compositionality_sch:\n\"(sch : schedules (A||B)) =\n  (Filter (%a. a:act A)$sch : schedules A &\n   Filter (%a. a:act B)$sch : schedules B &\n   Forall (%x. x:act (A||B)) sch)\"\napply (simp (no_asm) add: schedules_def has_schedule_def)\napply auto\n(* ==> *)\napply (rule_tac x = \"Filter_ex (asig_of A) (ProjA ex) \" in bexI)\nprefer 2\napply (simp add: compositionality_ex)\napply (simp (no_asm) add: Filter_ex_def ProjA_def lemma_2_1a lemma_2_1b)\napply (rule_tac x = \"Filter_ex (asig_of B) (ProjB ex) \" in bexI)\nprefer 2\napply (simp add: compositionality_ex)\napply (simp (no_asm) add: Filter_ex_def ProjB_def lemma_2_1a lemma_2_1b)\napply (simp add: executions_def)\napply (tactic {* pair_tac @{context} \"ex\" 1 *})\napply (erule conjE)\napply (simp add: sch_actions_in_AorB)\n\n(* <== *)\n\n(* mkex is exactly the construction of exA||B out of exA, exB, and the oracle sch,\n   we need here *)\napply (rename_tac exA exB)\napply (rule_tac x = \"mkex A B sch exA exB\" in bexI)\n(* mkex actions are just the oracle *)\napply (tactic {* pair_tac @{context} \"exA\" 1 *})\napply (tactic {* pair_tac @{context} \"exB\" 1 *})\napply (simp add: Mapfst_mkex_is_sch)\n\n(* mkex is an execution -- use compositionality on ex-level *)\napply (simp add: compositionality_ex)\napply (simp add: stutter_mkex_on_A stutter_mkex_on_B filter_mkex_is_exB filter_mkex_is_exA)\napply (tactic {* pair_tac @{context} \"exA\" 1 *})\napply (tactic {* pair_tac @{context} \"exB\" 1 *})\napply (simp add: mkex_actions_in_AorB)\ndone\n\n\nsubsection {* COMPOSITIONALITY on SCHEDULE Level -- for Modules *}\n\nlemma compositionality_sch_modules:\n  \"Scheds (A||B) = par_scheds (Scheds A) (Scheds B)\"\n\napply (unfold Scheds_def par_scheds_def)\napply (simp add: asig_of_par)\napply (rule set_eqI)\napply (simp add: compositionality_sch actions_of_par)\ndone\n\n\ndeclare compoex_simps [simp del]\ndeclare composch_simps [simp del]\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/HOLCF/IOA/meta_theory/CompoScheds.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5698526368038304, "lm_q2_score": 0.5, "lm_q1q2_score": 0.2849263184019152}}
{"text": "(*\n * Copyright 2016, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the GNU General Public License version 2. Note that NO WARRANTY is provided.\n * See \"LICENSE_GPLv2.txt\" for details.\n *\n * @TAG(NICTA_GPL)\n *)\n\n(*\n * Primitive ops\n *   \n *)\n\ntheory Prim\nimports\n  \"../Deep_Embedding_Auto\"\n  \"../SpecialisedLemmaTactic\"\n  \"../Cogent_Corres\"\n  \"../Corres_Tac\"\n  \"../TypeProofGen\"\n  \"../Tidy\"\n  \"../Heap_Relation_Generation\" \"../Type_Relation_Generation\"\nbegin\n\n\n(* Cogent semantics generated by\n  cogent --fml-typing-tree --type-proof=Foo.thy pass_prim-ops.cogent\n*)\n\nlemmas abbreviated_type_defs =\n  TrueI\n\ndefinition\n  \"ops8_type \\<equiv> ([], (TPrim (Num U8), TPrim (Num U8)))\"\n\ndefinition\n  \"ops8 \\<equiv> Let (Var 0) (Let (Lit (LU8 1)) (Let (Prim (Plus U8) [Var 1, Var 0]) (Let (Prim (Times U8) [Var 0, Var 2]) (Let (Prim (Minus U8) [Var 0, Var 1]) (Let (Prim (BitOr U8) [Var 0, Var 1]) (Let (Prim (BitAnd U8) [Var 0, Var 1]) (Let (Prim (BitXor U8) [Var 1, Var 2]) (Let (Prim (Complement U8) [Var 0]) (Let (Prim (LShift U8) [Var 1, Var 0]) (Let (Prim (RShift U8) [Var 1, Var 0]) (Let (Prim (Divide U8) [Var 0, Var 1]) (Let (Prim (Mod U8) [Var 1, Var 0]) (Let (Prim (Lt U8) [Var 2, Var 1]) (Let (Prim (Le U8) [Var 2, Var 1]) (Let (Prim (Eq (Num U8)) [Var 4, Var 2]) (Let (Prim Cogent.And [Var 1, Var 0]) (Let (Prim Cogent.And [Var 3, Var 0]) (If (Var 0) (Lit (LU8 0)) (Lit (LU8 1))))))))))))))))))))\"\n\ndefinition\n  \"ops64_type \\<equiv> ([], (TPrim (Num U64), TPrim (Num U64)))\"\n\ndefinition\n  \"ops64 \\<equiv> Let (Var 0) (Let (Lit (LU8 1)) (Let (Cast U64 (Var 0)) (Let (Prim (Plus U64) [Var 2, Var 0]) (Let (Prim (Times U64) [Var 0, Var 3]) (Let (Prim (Minus U64) [Var 0, Var 1]) (Let (Prim (BitOr U64) [Var 0, Var 1]) (Let (Prim (BitAnd U64) [Var 0, Var 1]) (Let (Prim (BitXor U64) [Var 1, Var 0]) (Let (Prim (Complement U64) [Var 0]) (Let (Prim (LShift U64) [Var 1, Var 0]) (Let (Prim (RShift U64) [Var 1, Var 0]) (Let (Prim (Divide U64) [Var 0, Var 1]) (Let (Prim (Mod U64) [Var 1, Var 0]) (Let (Prim (Lt U64) [Var 2, Var 1]) (Let (Prim (Le U64) [Var 2, Var 1]) (Let (Prim (Eq (Num U64)) [Var 4, Var 2]) (Let (Prim Cogent.And [Var 1, Var 0]) (Let (Prim Cogent.And [Var 3, Var 0]) (If (Var 0) (Let (Lit (LU8 0)) (Cast U64 (Var 0))) (Let (Lit (LU8 1)) (Cast U64 (Var 0))))))))))))))))))))))\"\n\ndefinition\n  \"ops32_type \\<equiv> ([], (TPrim (Num U32), TPrim (Num U32)))\"\n\ndefinition\n  \"ops32 \\<equiv> Let (Var 0) (Let (Lit (LU8 1)) (Let (Cast U32 (Var 0)) (Let (Prim (Plus U32) [Var 2, Var 0]) (Let (Prim (Times U32) [Var 0, Var 3]) (Let (Prim (Minus U32) [Var 0, Var 1]) (Let (Prim (BitOr U32) [Var 0, Var 1]) (Let (Prim (BitAnd U32) [Var 0, Var 1]) (Let (Prim (BitXor U32) [Var 1, Var 2]) (Let (Prim (Complement U32) [Var 0]) (Let (Prim (LShift U32) [Var 1, Var 0]) (Let (Prim (RShift U32) [Var 1, Var 0]) (Let (Prim (Divide U32) [Var 0, Var 1]) (Let (Prim (Mod U32) [Var 1, Var 0]) (Let (Prim (Lt U32) [Var 2, Var 1]) (Let (Prim (Le U32) [Var 2, Var 1]) (Let (Prim (Eq (Num U32)) [Var 4, Var 2]) (Let (Prim Cogent.And [Var 1, Var 0]) (Let (Prim Cogent.And [Var 3, Var 0]) (If (Var 0) (Let (Lit (LU8 0)) (Cast U32 (Var 0))) (Let (Lit (LU8 1)) (Cast U32 (Var 0))))))))))))))))))))))\"\n\ndefinition\n  \"ops16_type \\<equiv> ([], (TPrim (Num U16), TPrim (Num U16)))\"\n\ndefinition\n  \"ops16 \\<equiv> Let (Var 0) (Let (Lit (LU8 1)) (Let (Cast U16 (Var 0)) (Let (Prim (Plus U16) [Var 2, Var 0]) (Let (Prim (Times U16) [Var 0, Var 3]) (Let (Prim (Minus U16) [Var 0, Var 1]) (Let (Prim (BitOr U16) [Var 0, Var 1]) (Let (Prim (BitAnd U16) [Var 0, Var 1]) (Let (Prim (BitXor U16) [Var 1, Var 2]) (Let (Prim (Complement U16) [Var 0]) (Let (Prim (LShift U16) [Var 1, Var 0]) (Let (Prim (RShift U16) [Var 1, Var 0]) (Let (Prim (Divide U16) [Var 0, Var 1]) (Let (Prim (Mod U16) [Var 1, Var 0]) (Let (Prim (Lt U16) [Var 2, Var 1]) (Let (Prim (Le U16) [Var 2, Var 1]) (Let (Prim (Eq (Num U16)) [Var 4, Var 2]) (Let (Prim Cogent.And [Var 1, Var 0]) (Let (Prim Cogent.And [Var 3, Var 0]) (If (Var 0) (Let (Lit (LU8 0)) (Cast U16 (Var 0))) (Let (Lit (LU8 1)) (Cast U16 (Var 0))))))))))))))))))))))\"\n\ndefinition\n  \"bool_ops_type \\<equiv> ([], (TPrim (Num U32), TPrim Bool))\"\n\ndefinition\n  \"bool_ops \\<equiv> Let (Var 0) (Let (Lit (LU8 1)) (Let (Cast U32 (Var 0)) (Let (Prim (Plus U32) [Var 2, Var 0]) (Let (Prim (Times U32) [Var 0, Var 3]) (Let (Prim (Lt U32) [Var 4, Var 1]) (Let (Prim (Le U32) [Var 2, Var 1]) (Let (Prim (Eq (Num U32)) [Var 2, Var 6]) (Let (Prim Cogent.And [Var 1, Var 0]) (Let (Prim Cogent.Or [Var 0, Var 1]) (Let (Prim Not [Var 0]) (Let (Lit (LBool True)) (Let (Prim Cogent.Or [Var 1, Var 0]) (Let (Prim Not [Var 0]) (Let (Lit (LBool False)) (Let (Prim Cogent.And [Var 1, Var 0]) (Var 0))))))))))))))))\"\n\nML {*\nval Cogent_functions = [\"ops8\",\"ops64\",\"ops32\",\"ops16\",\"bool_ops\"]\nval Cogent_abstract_functions = []\n*}\n\ndefinition\n  \"\\<Xi> func_name' \\<equiv> case func_name' of ''ops8'' \\<Rightarrow> ops8_type | ''ops64'' \\<Rightarrow> ops64_type | ''ops32'' \\<Rightarrow> ops32_type | ''ops16'' \\<Rightarrow> ops16_type | ''bool_ops'' \\<Rightarrow> bool_ops_type\"\n\ndefinition\n  \"ops8_typetree \\<equiv> TyTrSplit (Cons (Some TSK_L) []) [] TyTrLeaf [Some (TPrim (Num U8))] (TyTrSplit (append (replicate 2 None) []) [] TyTrLeaf [Some (TPrim (Num U8))] (TyTrSplit (Cons (Some TSK_L) (Cons (Some TSK_S) (Cons None []))) [] TyTrLeaf [Some (TPrim (Num U8))] (TyTrSplit (Cons (Some TSK_S) (Cons None (Cons (Some TSK_L) (Cons None [])))) [] TyTrLeaf [Some (TPrim (Num U8))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 3 None) []))) [] TyTrLeaf [Some (TPrim (Num U8))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 4 None) []))) [] TyTrLeaf [Some (TPrim (Num U8))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_S) (append (replicate 5 None) []))) [] TyTrLeaf [Some (TPrim (Num U8))] (TyTrSplit (Cons (Some TSK_L) (Cons (Some TSK_L) (Cons (Some TSK_L) (append (replicate 5 None) [])))) [] TyTrLeaf [Some (TPrim (Num U8))] (TyTrSplit (Cons (Some TSK_S) (append (replicate 8 None) [])) [] TyTrLeaf [Some (TPrim (Num U8))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 8 None) []))) [] TyTrLeaf [Some (TPrim (Num U8))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 9 None) []))) [] TyTrLeaf [Some (TPrim (Num U8))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 10 None) []))) [] TyTrLeaf [Some (TPrim (Num U8))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_S) (append (replicate 11 None) []))) [] TyTrLeaf [Some (TPrim (Num U8))] (TyTrSplit (Cons None (Cons (Some TSK_S) (Cons (Some TSK_S) (append (replicate 11 None) [])))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons None (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 12 None) [])))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (append (replicate 2 None) (Cons (Some TSK_L) (Cons None (Cons (Some TSK_L) (append (replicate 11 None) []))))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons (Some TSK_L) (Cons (Some TSK_L) (append (replicate 15 None) []))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons (Some TSK_L) (append (replicate 2 None) (Cons (Some TSK_L) (append (replicate 14 None) [])))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons (Some TSK_L) (append (replicate 18 None) [])) [] TyTrLeaf [] (TyTrSplit (append (replicate 19 None) []) [] TyTrLeaf [] TyTrLeaf)))))))))))))))))))\"\n\ndefinition\n  \"ops64_typetree \\<equiv> TyTrSplit (Cons (Some TSK_L) []) [] TyTrLeaf [Some (TPrim (Num U64))] (TyTrSplit (append (replicate 2 None) []) [] TyTrLeaf [Some (TPrim (Num U8))] (TyTrSplit (Cons (Some TSK_L) (append (replicate 2 None) [])) [] TyTrLeaf [Some (TPrim (Num U64))] (TyTrSplit (Cons (Some TSK_L) (Cons None (Cons (Some TSK_S) (Cons None [])))) [] TyTrLeaf [Some (TPrim (Num U64))] (TyTrSplit (Cons (Some TSK_S) (append (replicate 2 None) (Cons (Some TSK_L) (Cons None [])))) [] TyTrLeaf [Some (TPrim (Num U64))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 4 None) []))) [] TyTrLeaf [Some (TPrim (Num U64))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 5 None) []))) [] TyTrLeaf [Some (TPrim (Num U64))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 6 None) []))) [] TyTrLeaf [Some (TPrim (Num U64))] (TyTrSplit (Cons (Some TSK_L) (Cons (Some TSK_L) (append (replicate 7 None) []))) [] TyTrLeaf [Some (TPrim (Num U64))] (TyTrSplit (Cons (Some TSK_S) (append (replicate 9 None) [])) [] TyTrLeaf [Some (TPrim (Num U64))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 9 None) []))) [] TyTrLeaf [Some (TPrim (Num U64))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 10 None) []))) [] TyTrLeaf [Some (TPrim (Num U64))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 11 None) []))) [] TyTrLeaf [Some (TPrim (Num U64))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_S) (append (replicate 12 None) []))) [] TyTrLeaf [Some (TPrim (Num U64))] (TyTrSplit (Cons None (Cons (Some TSK_S) (Cons (Some TSK_S) (append (replicate 12 None) [])))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons None (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 13 None) [])))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (append (replicate 2 None) (Cons (Some TSK_L) (Cons None (Cons (Some TSK_L) (append (replicate 12 None) []))))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons (Some TSK_L) (Cons (Some TSK_L) (append (replicate 16 None) []))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons (Some TSK_L) (append (replicate 2 None) (Cons (Some TSK_L) (append (replicate 15 None) [])))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons (Some TSK_L) (append (replicate 19 None) [])) [] TyTrLeaf [] (TyTrSplit (append (replicate 20 None) []) [] (TyTrSplit (append (replicate 20 None) []) [] TyTrLeaf [Some (TPrim (Num U8))] TyTrLeaf) [] (TyTrSplit (append (replicate 20 None) []) [] TyTrLeaf [Some (TPrim (Num U8))] TyTrLeaf)))))))))))))))))))))\"\n\ndefinition\n  \"ops32_typetree \\<equiv> TyTrSplit (Cons (Some TSK_L) []) [] TyTrLeaf [Some (TPrim (Num U32))] (TyTrSplit (append (replicate 2 None) []) [] TyTrLeaf [Some (TPrim (Num U8))] (TyTrSplit (Cons (Some TSK_L) (append (replicate 2 None) [])) [] TyTrLeaf [Some (TPrim (Num U32))] (TyTrSplit (Cons (Some TSK_L) (Cons None (Cons (Some TSK_S) (Cons None [])))) [] TyTrLeaf [Some (TPrim (Num U32))] (TyTrSplit (Cons (Some TSK_S) (append (replicate 2 None) (Cons (Some TSK_L) (Cons None [])))) [] TyTrLeaf [Some (TPrim (Num U32))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 4 None) []))) [] TyTrLeaf [Some (TPrim (Num U32))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 5 None) []))) [] TyTrLeaf [Some (TPrim (Num U32))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_S) (append (replicate 6 None) []))) [] TyTrLeaf [Some (TPrim (Num U32))] (TyTrSplit (Cons (Some TSK_L) (Cons (Some TSK_L) (Cons (Some TSK_L) (append (replicate 6 None) [])))) [] TyTrLeaf [Some (TPrim (Num U32))] (TyTrSplit (Cons (Some TSK_S) (append (replicate 9 None) [])) [] TyTrLeaf [Some (TPrim (Num U32))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 9 None) []))) [] TyTrLeaf [Some (TPrim (Num U32))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 10 None) []))) [] TyTrLeaf [Some (TPrim (Num U32))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 11 None) []))) [] TyTrLeaf [Some (TPrim (Num U32))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_S) (append (replicate 12 None) []))) [] TyTrLeaf [Some (TPrim (Num U32))] (TyTrSplit (Cons None (Cons (Some TSK_S) (Cons (Some TSK_S) (append (replicate 12 None) [])))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons None (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 13 None) [])))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (append (replicate 2 None) (Cons (Some TSK_L) (Cons None (Cons (Some TSK_L) (append (replicate 12 None) []))))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons (Some TSK_L) (Cons (Some TSK_L) (append (replicate 16 None) []))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons (Some TSK_L) (append (replicate 2 None) (Cons (Some TSK_L) (append (replicate 15 None) [])))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons (Some TSK_L) (append (replicate 19 None) [])) [] TyTrLeaf [] (TyTrSplit (append (replicate 20 None) []) [] (TyTrSplit (append (replicate 20 None) []) [] TyTrLeaf [Some (TPrim (Num U8))] TyTrLeaf) [] (TyTrSplit (append (replicate 20 None) []) [] TyTrLeaf [Some (TPrim (Num U8))] TyTrLeaf)))))))))))))))))))))\"\n\ndefinition\n  \"ops16_typetree \\<equiv> TyTrSplit (Cons (Some TSK_L) []) [] TyTrLeaf [Some (TPrim (Num U16))] (TyTrSplit (append (replicate 2 None) []) [] TyTrLeaf [Some (TPrim (Num U8))] (TyTrSplit (Cons (Some TSK_L) (append (replicate 2 None) [])) [] TyTrLeaf [Some (TPrim (Num U16))] (TyTrSplit (Cons (Some TSK_L) (Cons None (Cons (Some TSK_S) (Cons None [])))) [] TyTrLeaf [Some (TPrim (Num U16))] (TyTrSplit (Cons (Some TSK_S) (append (replicate 2 None) (Cons (Some TSK_L) (Cons None [])))) [] TyTrLeaf [Some (TPrim (Num U16))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 4 None) []))) [] TyTrLeaf [Some (TPrim (Num U16))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 5 None) []))) [] TyTrLeaf [Some (TPrim (Num U16))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_S) (append (replicate 6 None) []))) [] TyTrLeaf [Some (TPrim (Num U16))] (TyTrSplit (Cons (Some TSK_L) (Cons (Some TSK_L) (Cons (Some TSK_L) (append (replicate 6 None) [])))) [] TyTrLeaf [Some (TPrim (Num U16))] (TyTrSplit (Cons (Some TSK_S) (append (replicate 9 None) [])) [] TyTrLeaf [Some (TPrim (Num U16))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 9 None) []))) [] TyTrLeaf [Some (TPrim (Num U16))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 10 None) []))) [] TyTrLeaf [Some (TPrim (Num U16))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 11 None) []))) [] TyTrLeaf [Some (TPrim (Num U16))] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_S) (append (replicate 12 None) []))) [] TyTrLeaf [Some (TPrim (Num U16))] (TyTrSplit (Cons None (Cons (Some TSK_S) (Cons (Some TSK_S) (append (replicate 12 None) [])))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons None (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 13 None) [])))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (append (replicate 2 None) (Cons (Some TSK_L) (Cons None (Cons (Some TSK_L) (append (replicate 12 None) []))))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons (Some TSK_L) (Cons (Some TSK_L) (append (replicate 16 None) []))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons (Some TSK_L) (append (replicate 2 None) (Cons (Some TSK_L) (append (replicate 15 None) [])))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons (Some TSK_L) (append (replicate 19 None) [])) [] TyTrLeaf [] (TyTrSplit (append (replicate 20 None) []) [] (TyTrSplit (append (replicate 20 None) []) [] TyTrLeaf [Some (TPrim (Num U8))] TyTrLeaf) [] (TyTrSplit (append (replicate 20 None) []) [] TyTrLeaf [Some (TPrim (Num U8))] TyTrLeaf)))))))))))))))))))))\"\n\ndefinition\n  \"bool_ops_typetree \\<equiv> TyTrSplit (Cons (Some TSK_L) []) [] TyTrLeaf [Some (TPrim (Num U32))] (TyTrSplit (append (replicate 2 None) []) [] TyTrLeaf [Some (TPrim (Num U8))] (TyTrSplit (Cons (Some TSK_L) (append (replicate 2 None) [])) [] TyTrLeaf [Some (TPrim (Num U32))] (TyTrSplit (Cons (Some TSK_L) (Cons None (Cons (Some TSK_S) (Cons None [])))) [] TyTrLeaf [Some (TPrim (Num U32))] (TyTrSplit (Cons (Some TSK_S) (append (replicate 2 None) (Cons (Some TSK_S) (Cons None [])))) [] TyTrLeaf [Some (TPrim (Num U32))] (TyTrSplit (Cons None (Cons (Some TSK_S) (append (replicate 2 None) (Cons (Some TSK_S) (Cons None []))))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons (Some TSK_L) (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 4 None) [])))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (append (replicate 2 None) (Cons (Some TSK_L) (append (replicate 3 None) (Cons (Some TSK_L) (Cons None []))))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons (Some TSK_S) (Cons (Some TSK_L) (append (replicate 7 None) []))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons (Some TSK_L) (Cons (Some TSK_L) (append (replicate 8 None) []))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons (Some TSK_L) (append (replicate 10 None) [])) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (append (replicate 12 None) []) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons (Some TSK_L) (Cons (Some TSK_L) (append (replicate 11 None) []))) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons (Some TSK_L) (append (replicate 13 None) [])) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (append (replicate 15 None) []) [] TyTrLeaf [Some (TPrim Bool)] (TyTrSplit (Cons (Some TSK_L) (Cons (Some TSK_L) (append (replicate 14 None) []))) [] TyTrLeaf [Some (TPrim Bool)] TyTrLeaf)))))))))))))))\"\n\nML {* open TTyping_Tactics *}\n\nML_quiet {*\nval typing_helper_1_script : tac list = [\n(RTac @{thm kind_tprim[where k = \"{E,S,D}\"]})\n] *}\n\n\nlemma typing_helper_1[unfolded abbreviated_type_defs] :\n  \"kinding [] (TPrim (Num U8)) {E, S, D}\"\n  apply (unfold abbreviated_type_defs)?\n  apply (tactic {* map (fn t => DETERM (interpret_tac t @{context} 1)) typing_helper_1_script |> EVERY *})\n  done\n\nML_quiet {*\nval typing_helper_2_script : tac list = [\n(RTac @{thm kind_tprim[where k = \"{E,S,D}\"]})\n] *}\n\n\nlemma typing_helper_2[unfolded abbreviated_type_defs] :\n  \"kinding [] (TPrim Bool) {E, S, D}\"\n  apply (unfold abbreviated_type_defs)?\n  apply (tactic {* map (fn t => DETERM (interpret_tac t @{context} 1)) typing_helper_2_script |> EVERY *})\n  done\n\nML_quiet {*\nval typing_helper_3_script : tac list = [\n(RTac @{thm kind_tprim[where k = \"{E,S,D}\"]})\n] *}\n\n\nlemma typing_helper_3[unfolded abbreviated_type_defs] :\n  \"kinding [] (TPrim (Num U64)) {E, S, D}\"\n  apply (unfold abbreviated_type_defs)?\n  apply (tactic {* map (fn t => DETERM (interpret_tac t @{context} 1)) typing_helper_3_script |> EVERY *})\n  done\n\nML_quiet {*\nval typing_helper_4_script : tac list = [\n(RTac @{thm kind_tprim[where k = \"{E,S,D}\"]})\n] *}\n\n\nlemma typing_helper_4[unfolded abbreviated_type_defs] :\n  \"kinding [] (TPrim (Num U32)) {E, S, D}\"\n  apply (unfold abbreviated_type_defs)?\n  apply (tactic {* map (fn t => DETERM (interpret_tac t @{context} 1)) typing_helper_4_script |> EVERY *})\n  done\n\nML_quiet {*\nval typing_helper_5_script : tac list = [\n(RTac @{thm kind_tprim[where k = \"{E,S,D}\"]})\n] *}\n\n\nlemma typing_helper_5[unfolded abbreviated_type_defs] :\n  \"kinding [] (TPrim (Num U16)) {E, S, D}\"\n  apply (unfold abbreviated_type_defs)?\n  apply (tactic {* map (fn t => DETERM (interpret_tac t @{context} 1)) typing_helper_5_script |> EVERY *})\n  done\n\nML_quiet {*\nval ops8_typecorrect_script : hints list = [\nKindingTacs [(RTac @{thm typing_helper_1})],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [(RTac @{thm typing_lit'}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac []),(SimpTac ([],[]))],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nTypingTacs [],\nTypingTacs [(RTac @{thm typing_lit'}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac []),(SimpTac ([],[]))],\nTypingTacs [(RTac @{thm typing_lit'}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac []),(SimpTac ([],[]))]\n] *}\n\n\nML_quiet {*\nval ops8_ttyping_details_future = get_all_typing_details_future @{context} \"ops8\"\n   ops8_typecorrect_script*}\n\n\nlemma ops8_typecorrect :\n  \"\\<Xi>, fst ops8_type, (ops8_typetree, [Some (fst (snd ops8_type))]) T\\<turnstile> ops8 : snd (snd ops8_type)\"\n  apply (tactic {* resolve_future_typecorrect @{context} ops8_ttyping_details_future *})\n  done\n\nML_quiet {*\nval ops64_typecorrect_script : hints list = [\nKindingTacs [(RTac @{thm typing_helper_3})],\nKindingTacs [(RTac @{thm typing_helper_3})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [(RTac @{thm typing_lit'}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac []),(SimpTac ([],[]))],\nKindingTacs [(RTac @{thm typing_helper_3})],\nTypingTacs [(RTac @{thm typing_cast}),(RTac @{thm typing_var}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac [@{thm typing_helper_1}]),(SimpTac ([],[])),(SimpTac ([],[]))],\nKindingTacs [(RTac @{thm typing_helper_3})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_3})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_3})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_3})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_3})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_3})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_3})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_3})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_3})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_3})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_3})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [(RTac @{thm typing_lit'}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac []),(SimpTac ([],[]))],\nTypingTacs [(RTac @{thm typing_cast}),(RTac @{thm typing_var}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac [@{thm typing_helper_1}]),(SimpTac ([],[])),(SimpTac ([],[]))],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [(RTac @{thm typing_lit'}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac []),(SimpTac ([],[]))],\nTypingTacs [(RTac @{thm typing_cast}),(RTac @{thm typing_var}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac [@{thm typing_helper_1}]),(SimpTac ([],[])),(SimpTac ([],[]))]\n] *}\n\n\nML_quiet {*\nval ops64_ttyping_details_future = get_all_typing_details_future @{context} \"ops64\"\n   ops64_typecorrect_script*}\n\n\nlemma ops64_typecorrect :\n  \"\\<Xi>, fst ops64_type, (ops64_typetree, [Some (fst (snd ops64_type))]) T\\<turnstile> ops64 : snd (snd ops64_type)\"\n  apply (tactic {* resolve_future_typecorrect @{context} ops64_ttyping_details_future *})\n  done\n\nML_quiet {*\nval ops32_typecorrect_script : hints list = [\nKindingTacs [(RTac @{thm typing_helper_4})],\nKindingTacs [(RTac @{thm typing_helper_4})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [(RTac @{thm typing_lit'}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac []),(SimpTac ([],[]))],\nKindingTacs [(RTac @{thm typing_helper_4})],\nTypingTacs [(RTac @{thm typing_cast}),(RTac @{thm typing_var}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac [@{thm typing_helper_1}]),(SimpTac ([],[])),(SimpTac ([],[]))],\nKindingTacs [(RTac @{thm typing_helper_4})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_4})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_4})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_4})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_4})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_4})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_4})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_4})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_4})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_4})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_4})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [(RTac @{thm typing_lit'}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac []),(SimpTac ([],[]))],\nTypingTacs [(RTac @{thm typing_cast}),(RTac @{thm typing_var}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac [@{thm typing_helper_1}]),(SimpTac ([],[])),(SimpTac ([],[]))],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [(RTac @{thm typing_lit'}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac []),(SimpTac ([],[]))],\nTypingTacs [(RTac @{thm typing_cast}),(RTac @{thm typing_var}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac [@{thm typing_helper_1}]),(SimpTac ([],[])),(SimpTac ([],[]))]\n] *}\n\n\nML_quiet {*\nval ops32_ttyping_details_future = get_all_typing_details_future @{context} \"ops32\"\n   ops32_typecorrect_script*}\n\n\nlemma ops32_typecorrect :\n  \"\\<Xi>, fst ops32_type, (ops32_typetree, [Some (fst (snd ops32_type))]) T\\<turnstile> ops32 : snd (snd ops32_type)\"\n  apply (tactic {* resolve_future_typecorrect @{context} ops32_ttyping_details_future *})\n  done\n\nML_quiet {*\nval ops16_typecorrect_script : hints list = [\nKindingTacs [(RTac @{thm typing_helper_5})],\nKindingTacs [(RTac @{thm typing_helper_5})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [(RTac @{thm typing_lit'}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac []),(SimpTac ([],[]))],\nKindingTacs [(RTac @{thm typing_helper_5})],\nTypingTacs [(RTac @{thm typing_cast}),(RTac @{thm typing_var}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac [@{thm typing_helper_1}]),(SimpTac ([],[])),(SimpTac ([],[]))],\nKindingTacs [(RTac @{thm typing_helper_5})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_5})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_5})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_5})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_5})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_5})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_5})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_5})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_5})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_5})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_5})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [(RTac @{thm typing_lit'}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac []),(SimpTac ([],[]))],\nTypingTacs [(RTac @{thm typing_cast}),(RTac @{thm typing_var}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac [@{thm typing_helper_1}]),(SimpTac ([],[])),(SimpTac ([],[]))],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [(RTac @{thm typing_lit'}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac []),(SimpTac ([],[]))],\nTypingTacs [(RTac @{thm typing_cast}),(RTac @{thm typing_var}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac [@{thm typing_helper_1}]),(SimpTac ([],[])),(SimpTac ([],[]))]\n] *}\n\n\nML_quiet {*\nval ops16_ttyping_details_future = get_all_typing_details_future @{context} \"ops16\"\n   ops16_typecorrect_script*}\n\n\nlemma ops16_typecorrect :\n  \"\\<Xi>, fst ops16_type, (ops16_typetree, [Some (fst (snd ops16_type))]) T\\<turnstile> ops16 : snd (snd ops16_type)\"\n  apply (tactic {* resolve_future_typecorrect @{context} ops16_ttyping_details_future *})\n  done\n\nML_quiet {*\nval bool_ops_typecorrect_script : hints list = [\nKindingTacs [(RTac @{thm typing_helper_4})],\nKindingTacs [(RTac @{thm typing_helper_4})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_1})],\nTypingTacs [(RTac @{thm typing_lit'}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac []),(SimpTac ([],[]))],\nKindingTacs [(RTac @{thm typing_helper_4})],\nTypingTacs [(RTac @{thm typing_cast}),(RTac @{thm typing_var}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac [@{thm typing_helper_1}]),(SimpTac ([],[])),(SimpTac ([],[]))],\nKindingTacs [(RTac @{thm typing_helper_4})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_4})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [(RTac @{thm typing_lit'}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac []),(SimpTac ([],[]))],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [(RTac @{thm typing_lit'}),(SimpTac ([@{thm empty_def}],[])),(WeakeningTac []),(SimpTac ([],[]))],\nKindingTacs [(RTac @{thm typing_helper_2})],\nTypingTacs [],\nTypingTacs []\n] *}\n\n\nML_quiet {*\nval bool_ops_ttyping_details_future = get_all_typing_details_future @{context} \"bool_ops\"\n   bool_ops_typecorrect_script*}\n\n\nlemma bool_ops_typecorrect :\n  \"\\<Xi>, fst bool_ops_type, (bool_ops_typetree, [Some (fst (snd bool_ops_type))]) T\\<turnstile> bool_ops : snd (snd bool_ops_type)\"\n  apply (tactic {* resolve_future_typecorrect @{context} bool_ops_ttyping_details_future *})\n  done\n\nML_quiet {*\nval (_, ops8_typing_tree, ops8_typing_bucket)\n= Future.join ops8_ttyping_details_future\n*}\n\n\nML_quiet {*\nval (_, ops64_typing_tree, ops64_typing_bucket)\n= Future.join ops64_ttyping_details_future\n*}\n\n\nML_quiet {*\nval (_, ops32_typing_tree, ops32_typing_bucket)\n= Future.join ops32_ttyping_details_future\n*}\n\n\nML_quiet {*\nval (_, ops16_typing_tree, ops16_typing_bucket)\n= Future.join ops16_ttyping_details_future\n*}\n\n\nML_quiet {*\nval (_, bool_ops_typing_tree, bool_ops_typing_bucket)\n= Future.join bool_ops_ttyping_details_future\n*}\n\n\n\n(* end Cogent semantics *)\n\n(* C semantics, generated by C parser *)\nnew_C_include_dir \"../../cogent/tests\"\ninstall_C_file \"pass_prim-ops.c\"\n\nautocorres [ts_rules=nondet, no_opt, gen_word_heaps, skip_word_abs] \"pass_prim-ops.c\"\n\ninstantiation bool_t_C :: cogent_C_val\nbegin\ndefinition type_rel_bool_t_C_def:\n  \"type_rel typ (_ :: bool_t_C itself) \\<equiv> (typ = RPrim Bool)\"\n\ndefinition val_rel_bool_t_C_def:\n  \"val_rel uv (x :: bool_t_C) \\<equiv> uv = UPrim (LBool (bool_t_C.boolean_C x \\<noteq> 0))\"\ninstance ..\nend\n\n(* Relation between Cogent and C data *)\nlocal_setup{* local_setup_val_rel_type_rel_put_them_in_buckets \"pass_prim-ops.c\" *}\n\n(* Lemma bucket.*)\nML{* TypeRelSimp.get @{context} *}\nML{* ValRelSimp.get @{context} *}\n\nlemmas val_rel_simps[ValRelSimp] = val_rel_word val_rel_ptr_def val_rel_bool_t_C_def\nlemmas type_rel_simps[TypeRelSimp] = type_rel_word type_rel_ptr_def type_rel_bool_t_C_def\n\nclass cogent_C_heap = cogent_C_val +\n  fixes is_valid    :: \"lifted_globals \\<Rightarrow> 'a ptr \\<Rightarrow> bool\"\n  fixes heap        :: \"lifted_globals \\<Rightarrow> 'a ptr \\<Rightarrow> 'a\"\n  fixes heap_update :: \"(('a ptr \\<Rightarrow> 'a) \\<Rightarrow> 'a ptr \\<Rightarrow> 'a) \\<Rightarrow> lifted_globals \\<Rightarrow> lifted_globals\"\n\nlocal_setup{* local_setup_instantiate_cogent_C_heaps_store_them_in_buckets \"pass_prim-ops.c\"*}\nML{* HeapSimp.get @{context}; IsValidSimp.get @{context} *}\n\nlocale take_cogent = \"pass_prim-ops\" + update_sem_init\nbegin\n\n(* Relation between program heaps *)\ndefinition\n  heap_rel_ptr ::\n  \"(funtyp, abstyp, ptrtyp) store \\<Rightarrow> lifted_globals \\<Rightarrow>\n   ('a :: cogent_C_heap) ptr \\<Rightarrow> bool\"\nwhere\n  \"heap_rel_ptr \\<sigma> h p \\<equiv>\n   (\\<forall>uv.\n     \\<sigma> (ptr_val p) = Some uv \\<longrightarrow>\n     type_rel (uval_repr uv) TYPE('a) \\<longrightarrow>\n     is_valid h p \\<and> val_rel uv (heap h p))\"\n\nlemma heap_rel_ptr_meta:\n  \"heap_rel_ptr = heap_rel_meta is_valid heap\"\n  by (simp add: heap_rel_ptr_def[abs_def] heap_rel_meta_def[abs_def])\n\nlemmas heap_rel_def = TrueI\n\ndefinition state_rel :: \"((funtyp, abstyp, ptrtyp) store \\<times> lifted_globals) set\"\nwhere\n  \"state_rel = {(\\<sigma>, h). True}\"\n\n\n(* Preprocess AutoCorres output *)\nlocal_setup {* fold tidy_C_fun_def' Cogent_functions *}\n\n(* Defined here because it relies on bool_t_C *)\n\nlemma corres_if_base:\n  assumes split\\<Gamma>: \"[] \\<turnstile> \\<Gamma>' \\<leadsto> \\<Gamma>1 | \\<Gamma>2\"\n  assumes typing_cond: \"\\<Xi>', [], \\<Gamma>1 \\<turnstile> Var c : TPrim Bool\"\n  assumes val_rel_cond: \"\\<gamma>!c = UPrim (LBool (bool_val' c' \\<noteq> (0::word8)))\"\n  assumes corres_true: \"corres srel a a' \\<xi> \\<gamma> \\<Xi>' \\<Gamma>2 \\<sigma> s\"\n  assumes corres_false: \"corres srel b b' \\<xi> \\<gamma> \\<Xi>' \\<Gamma>2 \\<sigma> s\"\n  shows \"corres srel (If (Var c) a b)\n           (do x \\<leftarrow> condition (\\<lambda>s. bool_val' c' \\<noteq> 0) a' b'; gets (\\<lambda>_. x) od)\n           \\<xi> \\<gamma> \\<Xi>' \\<Gamma>' \\<sigma> s\"\n  apply (clarsimp simp: corres_def snd_condition in_condition)\n  apply (rename_tac r w)\n  apply (insert typing_cond)\n  apply (erule typing_varE)\n  apply (frule matches_ptrs_split'[OF split\\<Gamma>])\n  apply clarsimp\n  apply (rename_tac r' w' r'' w'')\n  apply (frule_tac \\<Gamma>=\\<Gamma>1 in matches_ptrs_proj', simp+)\n  apply clarsimp\n  apply (rename_tac rr')\n  apply (insert val_rel_cond[unfolded val_rel_bool_t_C_def])\n  apply clarsimp\n  apply (cases \"bool_val' c'=0\")\n   apply (insert corres_false[unfolded corres_def])[1]\n   apply simp\n   apply (erule impE, fast)\n   apply clarsimp\n   apply (rename_tac v' s')\n   apply (erule_tac x=v' in allE)\n   apply (erule_tac x=s' in allE )\n   apply clarsimp\n   apply (rename_tac \\<sigma>' v)\n   apply (rule_tac x=\\<sigma>' in exI)\n   apply (rule_tac x=v in exI)\n   apply (fastforce intro!: u_sem_if u_sem_var elim: subst split: uval.splits lit.splits) \n  apply (insert corres_true[unfolded corres_def])[1]\n  apply simp\n  apply (erule impE, fast)\n  apply clarsimp\n  apply (rename_tac v' s')\n  apply (erule_tac x=v' in allE)\n  apply (erule_tac x=s' in allE )\n  apply clarsimp\n  apply (rename_tac \\<sigma>' v)\n  apply (rule_tac x=\\<sigma>' in exI)\n  apply (rule_tac x=v in exI)\n  apply (fastforce intro!: u_sem_if u_sem_var elim: subst split: uval.splits lit.splits)\n  done\n\nlemmas corres_if = corres_if_base[where bool_val' = boolean_C,\n                     OF _ _ val_rel_bool_t_C_def[THEN meta_eq_to_obj_eq, THEN iffD1]]\n\n(* dummy *)\nlemmas corres_nested_let = TrueI\n\nlemma ops32_corres:\n  \"val_rel a a' \\<Longrightarrow> corres state_rel ops32 (ops32' a') \\<xi> [a] \\<Xi> [Some (fst (snd ops32_type))] \\<sigma> s\"\n  apply (tactic {* corres_tac @{context}\n    (peel_two ops32_typing_tree)\n    @{thms ops32_def ops32'_def' ops32_type_def abbreviated_type_defs} [] []\n    @{thm corres_if} [] @{thms } @{thms } []\n    @{thm LETBANG_TRUE_def} @{thms } true *})\n  done\n\nlemma ops64_corres:\n  \"val_rel a a' \\<Longrightarrow> corres state_rel ops64 (ops64' a') \\<xi> [a] \\<Xi> [Some (fst (snd ops64_type))] \\<sigma> s\"\n  apply (tactic {* corres_tac @{context}\n    (peel_two ops64_typing_tree)\n    @{thms ops64_def ops64'_def' ops64_type_def abbreviated_type_defs} [] []\n    @{thm corres_if} [] @{thms } @{thms } []\n    @{thm LETBANG_TRUE_def} @{thms } true *})\n  done\n\nlemma ops8_corres:\n  \"val_rel a a' \\<Longrightarrow> corres state_rel ops8 (ops8' a') \\<xi> [a] \\<Xi> [Some (fst (snd ops8_type))] \\<sigma> s\"\n  apply (tactic {* corres_tac @{context}\n    (peel_two ops8_typing_tree)\n    @{thms ops8_def ops8'_def' ops8_type_def abbreviated_type_defs} [] []\n    @{thm corres_if} [] @{thms } @{thms } []\n    @{thm LETBANG_TRUE_def} @{thms } true *})\n  done\n\nlemma ops16_corres:\n  \"val_rel a a' \\<Longrightarrow> corres state_rel ops16 (ops16' a') \\<xi> [a] \\<Xi> [Some (fst (snd ops16_type))] \\<sigma> s\"\n  apply (tactic {* corres_tac @{context}\n    (peel_two ops16_typing_tree)\n    @{thms ops16_def ops16'_def' ops16_type_def abbreviated_type_defs} [] []\n    @{thm corres_if} [] @{thms } @{thms } []\n    @{thm LETBANG_TRUE_def} @{thms } true *})\n  done\n\nlemma bool_ops_corres:\n  \"val_rel a a' \\<Longrightarrow> corres state_rel bool_ops (bool_ops' a') \\<xi> [a] \\<Xi> [Some (fst (snd bool_ops_type))] \\<sigma> s\"\n  apply (tactic {* corres_tac @{context}\n    (peel_two bool_ops_typing_tree)\n    @{thms bool_ops_def bool_ops'_def' bool_ops_type_def abbreviated_type_defs} [] []\n    @{thm corres_if} [] @{thms } @{thms } []\n    @{thm LETBANG_TRUE_def} @{thms } true *})\n  done\n\nend\nend\n\n", "meta": {"author": "au-ts", "repo": "cogent", "sha": "a1464313bbd1bbfaa5c4e58ab14f669c6d2436a2", "save_path": "github-repos/isabelle/au-ts-cogent", "path": "github-repos/isabelle/au-ts-cogent/cogent-a1464313bbd1bbfaa5c4e58ab14f669c6d2436a2/c-refinement/tests/Prim.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631840431539, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.2848668048252886}}
{"text": "(*<*)\n(*\n * Copyright 2015, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory Proofs\nimports\n  TSO\n  Phases\n  MarkObject\n  StrongTricolour\n  Valid_Refs\n  Worklists\n  Global_Noninterference\n  Noninterference\n  Initial_Conditions\nbegin\n\n(*>*)\nsection\\<open>Top-level safety \\label{sec:top-level-correctness}\\<close>\n\nlemma (in gc) I:\n  \"\\<lbrace> I \\<rbrace> gc\"\napply (simp add: I_defs)\napply (rule valid_pre)\napply ( rule valid_conj_lift valid_all_lift | fastforce )+\ndone\n\nlemma (in sys) I:\n  \"\\<lbrace> I \\<rbrace> sys\"\napply (simp add: I_defs)\napply (rule valid_pre)\napply ( rule valid_conj_lift valid_all_lift | fastforce )+\ndone\n\ntext\\<open>\n\nWe need to separately treat the two cases of a single mutator and\nmultiple mutators. In the latter case we have the additional\nobligation of showing mutual non-interference amongst mutators.\n\n\\<close>\n\nlemma mut_invsL[intro]:\n  \"\\<lbrace>I\\<rbrace> mutator m \\<lbrace>mut_m.invsL m'\\<rbrace>\"\nproof(cases \"m = m'\")\n  case True\n  interpret mut_m m' by unfold_locales\n  from True show ?thesis\n    apply (simp add: I_defs)\n    apply (rule valid_pre)\n    apply ( rule valid_conj_lift | fastforce )+\n    done\nnext\n  case False\n  then interpret mut_m' m' m by unfold_locales blast\n  from False show ?thesis\n    apply (simp add: I_defs)\n    apply (rule valid_pre)\n    apply ( rule valid_conj_lift | fastforce )+\n    done\nqed\n\n(* FIXME split mutators_phase_inv from global invs to local invs. Move to StrongTricolour or similar. note dependence on I *)\nlemma mutators_phase_inv[intro]:\n  \"\\<lbrace> I \\<rbrace> mutator m  \\<lbrace> LSTP (mut_m.mutator_phase_inv m') \\<rbrace>\"\nproof(cases \"m = m'\")\n  case True\n  interpret mut_m m' by unfold_locales\n  from True show ?thesis\n    apply (simp add: I_defs)\n    apply (rule valid_pre)\n    apply ( rule valid_conj_lift valid_all_lift | fastforce )+\n    done\nnext\n  case False\n  then interpret mut_m' m' m by unfold_locales blast\n  from False show ?thesis\n    apply (simp add: I_defs)\n    apply (rule valid_pre)\n    apply ( rule valid_conj_lift valid_all_lift | fastforce )+\n    done\nqed\n\nlemma (in mut_m) I:\n  \"\\<lbrace> I \\<rbrace> mutator m\"\napply (simp add: I_def gc.invsL_def invs_def Local_Invariants.invsL_def)\napply (rule valid_pre)\napply ( rule valid_conj_lift valid_all_lift | fastforce )+\napply (simp add: I_defs)\ndone\n\ncontext gc_system\nbegin\n\ntheorem I: \"gc_system \\<Turnstile>\\<^bsub>pre\\<^esub> I\"\napply (rule VCG)\n apply (rule init_inv)\napply (rename_tac p)\napply (case_tac p, simp_all)\n  apply (rule mut_m.I[unfolded valid_proc_def, simplified])\n apply (rule gc.I[unfolded valid_proc_def, simplified])\napply (rule sys.I[unfolded valid_proc_def, simplified])\ndone\n\ntext\\<open>\n\n\\label{sec:proofs-headline-safety}\n\nOur headline safety result follows directly.\n\n\\<close>\n\ncorollary safety: \"gc_system \\<Turnstile>\\<^bsub>pre\\<^esub> LSTP valid_refs\"\nusing I unfolding I_def invs_def valid_refs_def prerun_valid_def\napply clarsimp\napply (drule_tac x=\\<sigma> in spec)\napply (drule (1) mp)\napply (rule alwaysI)\napply (erule_tac i=i in alwaysE)\napply (clarsimp simp: valid_refs_invD(1))\ndone\n\nend\n\ntext\\<open>\n\nThe GC is correct for the remaining fixed-but-arbitrary initial\nconditions.\n\n\\<close>\n\ninterpretation gc_system_interpretation: gc_system undefined .\n\n(* unused_thms Main Sublist CIMP - *)\n\n\nsection\\<open> A concrete system state \\label{sec:concrete-system-state} \\<close>\n\ntext\\<open>\n\nWe demonstrate that our definitions are not vacuous by exhibiting a\nconcrete initial state that satisfies the initial conditions. The heap\nis shown in Figure~\\ref{fig:concrete-heap}. We use Isabelle's notation\nfor types of a given size.\n\n\\begin{figure}\n  \\centering\n  \\includegraphics{heap.pdf}\n  \\caption{A concrete system state.}\n  \\label{fig:concrete-heap}\n\\end{figure}\n\n\\<close>\n(*<*)\n\nend\n(*>*)\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/ConcurrentGC/Proofs.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631698328917, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.2848667981636509}}
{"text": "(*  Title:      HOL/MicroJava/Comp/Index.thy\n    Author:     Martin Strecker\n*)\n\n(* Index of variable in list of parameter names and local variables *)\n\ntheory Index\nimports AuxLemmas DefsComp\nbegin\n\n(*indexing a variable name among all variable declarations in a method body*)\ndefinition index :: \"java_mb => vname => nat\" where\n \"index ==  \\<lambda> (pn,lv,blk,res) v.\n  if v = This\n  then 0 \n  else Suc (length (takeWhile (\\<lambda> z. z~=v) (pn @ map fst lv)))\"\n\n\nlemma index_length_pns: \"\n  \\<lbrakk> i = index (pns,lvars,blk,res) vn;\n  wf_java_mdecl G C ((mn,pTs),rT, (pns,lvars,blk,res));\n  vn \\<in> set pns\\<rbrakk>\n  \\<Longrightarrow> 0 < i \\<and> i < Suc (length pns)\"\n  apply (simp add: wf_java_mdecl_def index_def)\n  apply (subgoal_tac \"vn \\<noteq> This\")\n   apply (auto intro: length_takeWhile)\n  done\n\nlemma index_length_lvars: \"\n  \\<lbrakk> i = index (pns,lvars,blk,res) vn;\n  wf_java_mdecl G C ((mn,pTs),rT, (pns,lvars,blk,res));\n  vn \\<in> set (map fst lvars)\\<rbrakk>\n  \\<Longrightarrow> (length pns) < i \\<and> i < Suc((length pns) + (length lvars))\"\n  apply (simp add: wf_java_mdecl_def index_def)\n  apply (subgoal_tac \"vn \\<noteq> This\")\n   apply simp\n   apply (subgoal_tac \"\\<forall> x \\<in> set pns. (\\<lambda>z. z \\<noteq> vn) x\")\n    apply simp\n    apply (subgoal_tac \"length (takeWhile (\\<lambda>z. z \\<noteq> vn) (map fst lvars)) < length (map fst lvars)\")\n     apply simp\n    apply (rule length_takeWhile)\n    apply simp\n   apply (simp add: map_of_in_set)\n   apply (intro strip notI) \n   apply simp \n  apply blast\n  done\n\n\n(***  index  ***)\n\nlemma select_at_index : \n  \"x \\<in> set (gjmb_plns (gmb G C S)) \\<or> x = This\n  \\<Longrightarrow> (the (loc This) # glvs (gmb G C S) loc) ! (index (gmb G C S) x) = the (loc x)\"\n  apply (simp only: index_def gjmb_plns_def)\n  apply (case_tac \"gmb G C S\" rule: prod.exhaust)\n  apply (simp add: galldefs del: set_append map_append)\n  apply (rename_tac a b)\n  apply (case_tac b, simp add: gmb_def gjmb_lvs_def del: set_append map_append)\n  apply (intro strip)\n  apply (simp del: set_append map_append)\n  apply (frule length_takeWhile)\n  apply (frule_tac f = \"(the \\<circ> loc)\" in nth_map)\n  apply simp\n  done\n\nlemma lift_if: \"(f (if b then t else e)) = (if b then (f t) else (f e))\"\n  by auto\n\nlemma update_at_index: \"\n  \\<lbrakk> distinct (gjmb_plns (gmb G C S));\n  x \\<in> set (gjmb_plns (gmb G C S)); x \\<noteq> This \\<rbrakk> \\<Longrightarrow>\n  (locvars_xstate G C S (Norm (h, l)))[index (gmb G C S) x := val] =\n  locvars_xstate G C S (Norm (h, l(x\\<mapsto>val)))\"\n  apply (simp only: locvars_xstate_def locvars_locals_def index_def)\n  apply (case_tac \"gmb G C S\" rule: prod.exhaust, simp)\n  apply (rename_tac a b)\n  apply (case_tac b, simp)\n  apply (rule conjI)\n   apply (simp add: gl_def)\n  apply (simp add: galldefs del: set_append map_append)\n  done\n\n\n(* !!!! incomprehensible: why can't List.takeWhile_append2 be applied the same \n  way in the second case as in the first case ? *)\nlemma index_of_var: \"\\<lbrakk> xvar \\<notin> set pns; xvar \\<notin> set (map fst zs); xvar \\<noteq> This \\<rbrakk>\n  \\<Longrightarrow> index (pns, zs @ ((xvar, xval) # xys), blk, res) xvar = Suc (length pns + length zs)\"\n  apply (simp add: index_def)\n  apply (subgoal_tac \"(\\<And>x. ((x \\<in> (set pns)) \\<Longrightarrow> ((\\<lambda>z. (z \\<noteq> xvar))x)))\")\n   apply simp\n   apply (subgoal_tac \"(takeWhile (\\<lambda>z. z \\<noteq> xvar) (map fst zs @ xvar # map fst xys)) = map fst zs @ (takeWhile (\\<lambda>z. z \\<noteq> xvar) (xvar # map fst xys))\")\n    apply simp\n   apply (rule List.takeWhile_append2)\n   apply auto\n  done\n\n\n\n\n(* The following definition should replace the conditions in WellType.thy / wf_java_mdecl\n*)\ndefinition disjoint_varnames :: \"[vname list, (vname \\<times> ty) list] \\<Rightarrow> bool\" where\n  \"disjoint_varnames pns lvars \\<equiv> \n  distinct pns \\<and> unique lvars \\<and> This \\<notin> set pns \\<and> This \\<notin> set (map fst lvars) \\<and> \n  (\\<forall>pn\\<in>set pns. pn \\<notin> set (map fst lvars))\"\n\n\nlemma index_of_var2: \"\n  disjoint_varnames pns (lvars_pre @ (vn, ty) # lvars_post)\n  \\<Longrightarrow> index (pns, lvars_pre @ (vn, ty) # lvars_post, blk, res) vn =\n  Suc (length pns + length lvars_pre)\"\n  apply (simp add: disjoint_varnames_def index_def unique_def)\n  apply (subgoal_tac \"vn \\<noteq> This\", simp)\n   apply (subgoal_tac\n    \"takeWhile (\\<lambda>z. z \\<noteq> vn) (map fst lvars_pre @ vn # map fst lvars_post) =\n    map fst lvars_pre @ takeWhile (\\<lambda>z. z \\<noteq> vn) (vn # map fst lvars_post)\")\n    apply simp\n   apply (rule List.takeWhile_append2)\n   apply auto\n  done\n\nlemma wf_java_mdecl_disjoint_varnames: \n  \"wf_java_mdecl G C (S,rT,(pns,lvars,blk,res))\n  \\<Longrightarrow> disjoint_varnames pns lvars\"\n  apply (cases S)\n  apply (simp add: wf_java_mdecl_def disjoint_varnames_def  map_of_in_set)\n  done\n\nlemma wf_java_mdecl_length_pTs_pns: \n  \"wf_java_mdecl G C ((mn, pTs), rT, pns, lvars, blk, res)\n  \\<Longrightarrow> length pTs = length pns\"\n  by (simp add: wf_java_mdecl_def)\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/MicroJava/Comp/Index.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7057850278370112, "lm_q2_score": 0.40356685373537454, "lm_q1q2_score": 0.28483144309771635}}
{"text": "(*  Title:      HOL/Auth/n_mutualEx_lemma_inv__5_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mutualEx Protocol Case Study*} \n\ntheory n_mutualEx_lemma_inv__5_on_rules imports n_mutualEx_lemma_on_inv__5\nbegin\nsection{*All lemmas on causal relation between inv__5*}\nlemma lemma_inv__5_on_rules:\n  assumes b1: \"r \\<in> rules N\" and b2: \"(\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__5  p__Inv0 p__Inv1)\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have c1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n  apply (cut_tac b1, auto) done\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_TryVsinv__5) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_CritVsinv__5) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_ExitVsinv__5) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_IdleVsinv__5) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "lyj238Gmail", "repo": "newParaVerifier", "sha": "5c2d49bf8e6c46c60efa53c98b0ba5c577d59618", "save_path": "github-repos/isabelle/lyj238Gmail-newParaVerifier", "path": "github-repos/isabelle/lyj238Gmail-newParaVerifier/newParaVerifier-5c2d49bf8e6c46c60efa53c98b0ba5c577d59618/examples/n_mutualEx/n_mutualEx_lemma_inv__5_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6992544210587585, "lm_q2_score": 0.4073334000459302, "lm_q1q2_score": 0.2848296808270126}}
{"text": "theory Simple_Network_Language_Deadlock_Checking\n  imports Simple_Network_Language_Model_Checking Deadlock.Deadlock_Checking\nbegin\n\ncontext Simple_Network_Impl_nat_ceiling_start_state\nbegin\n\ncontext\n  fixes \\<phi>\n  assumes formula_is_false: \"formula = formula.EX (not sexp.true)\"\nbegin\n\nlemma F_is_FalseI:\n  shows \"PR_CONST F = (\\<lambda>_. False)\"\n  by (subst formula_is_false) auto\n\nlemma final_fun_is_False:\n  \"Fi a = False\"\n  by (subst formula_is_false) auto\n\nlemmas deadlock_checker_hoare = impl.deadlock_checker_hoare[\n    OF final_fun_is_False F_is_FalseI, folded deadlock_start_iff has_deadlock_def]\n\nend\n\nthm impl.is_start_in_states_impl_def\nschematic_goal deadlock_checker_alt_def:\n  \"impl.deadlock_checker \\<equiv> ?impl\"\n  unfolding impl.deadlock_checker_def\n  unfolding impl.succs_impl_def\n  unfolding impl.check_deadlock_neg_impl_def impl.check_deadlock_impl_def\n  apply (abstract_let impl.is_start_in_states_impl is_start)\n  unfolding impl.is_start_in_states_impl_def\n  apply (abstract_let impl.E_op''_impl E_op''_impl)\n  unfolding impl.E_op''_impl_def fw_impl'_int\n  apply (abstract_let trans_impl trans_impl)\n  unfolding trans_impl_def\n  apply (abstract_let int_trans_impl int_trans_impl)\n  apply (abstract_let bin_trans_from_impl bin_trans_impl)\n  apply (abstract_let broad_trans_from_impl broad_trans_impl)\n  unfolding int_trans_impl_def bin_trans_from_impl_def broad_trans_from_impl_def\n  apply (abstract_let trans_in_broad_grouped trans_in_broad_grouped)\n  apply (abstract_let trans_out_broad_grouped trans_out_broad_grouped)\n  apply (abstract_let trans_in_map trans_in_map)\n  apply (abstract_let trans_out_map trans_out_map)\n  apply (abstract_let int_trans_from_all_impl int_trans_from_all_impl)\n  unfolding int_trans_from_all_impl_def\n  apply (abstract_let int_trans_from_vec_impl int_trans_from_vec_impl)\n  unfolding int_trans_from_vec_impl_def\n  apply (abstract_let int_trans_from_loc_impl int_trans_from_loc_impl)\n  unfolding int_trans_from_loc_impl_def\n  apply (abstract_let trans_i_map trans_i_map)\n  unfolding trans_out_broad_grouped_def trans_out_broad_map_def\n  unfolding trans_in_broad_grouped_def trans_in_broad_map_def\n  unfolding trans_in_map_def trans_out_map_def\n  unfolding trans_i_map_def\n  apply (abstract_let trans_map trans_map)\n  apply (abstract_let \"inv_fun :: nat list \\<times> int list \\<Rightarrow> _\" inv_fun)\n  unfolding inv_fun_alt_def\n  apply (abstract_let invs2 invs)\n  unfolding invs2_def\n  unfolding k_impl_alt_def\n  apply (abstract_let k_i k_i) (* Could be killed *)\n  apply (abstract_let n_ps n_ps)\n  (* These would need to be moved to a defs locale *)\n  unfolding k_i_def impl.state_copy_impl_def impl.a\\<^sub>0_impl_def impl.abstr_repair_impl_def\n    impl.subsumes_impl_def impl.emptiness_check_impl_def impl.abstra_repair_impl_def\n    impl.init_dbm_impl_def\n  by (rule Pure.reflexive)\n\nend\n\nconcrete_definition deadlock_checker uses\n  Simple_Network_Impl_nat_ceiling_start_state.deadlock_checker_alt_def\n\ndefinition precond_dc where\n  \"precond_dc\n    show_clock show_state broadcast bounds' automata m num_states num_actions k L\\<^sub>0 s\\<^sub>0 formula \\<equiv>\n    if Simple_Network_Impl_nat_ceiling_start_state\n      broadcast bounds' automata m num_states num_actions k L\\<^sub>0 s\\<^sub>0 formula\n    then\n      deadlock_checker\n        broadcast bounds' automata m num_states num_actions k L\\<^sub>0 s\\<^sub>0 show_clock show_state\n      \\<bind> (\\<lambda> x. return (Some x))\n    else return None\"\n\ntheorem deadlock_check:\n  \"<emp> precond_dc\n    show_clock show_state broadcast bounds automata m num_states num_actions k L\\<^sub>0 s\\<^sub>0\n      (formula.EX (not sexp.true))\n    <\\<lambda> Some r \\<Rightarrow> \\<up>(\n        Simple_Network_Impl_nat_ceiling_start_state\n          broadcast bounds automata m num_states num_actions k L\\<^sub>0 s\\<^sub>0 (formula.EX (not sexp.true)) \\<and>\n          r = has_deadlock (N broadcast automata bounds) (L\\<^sub>0, map_of s\\<^sub>0, \\<lambda>_ . 0)\n        )\n     | None \\<Rightarrow> \\<up>(\\<not> Simple_Network_Impl_nat_ceiling_start_state\n        broadcast bounds automata m num_states num_actions k L\\<^sub>0 s\\<^sub>0 (formula.EX (not sexp.true)))\n    >\\<^sub>t\"\nproof -\n  define A where \"A \\<equiv> N broadcast automata bounds\"\n  define check where \"check \\<equiv> A,(L\\<^sub>0, map_of s\\<^sub>0, \\<lambda>_ . 0) \\<Turnstile> (formula.EX (not sexp.true))\"\n  note [sep_heap_rules] = Simple_Network_Impl_nat_ceiling_start_state.deadlock_checker_hoare[\n      OF _ HOL.refl,\n      of broadcast bounds automata m num_states num_actions k L\\<^sub>0 s\\<^sub>0 _,\n      unfolded UPPAAL_Reachability_Problem_precompiled_defs.init_def,\n      folded A_def\n      ]\n  show ?thesis\n    unfolding A_def[symmetric] precond_dc_def\n    by (sep_auto simp: deadlock_checker.refine[symmetric] pure_def has_deadlock_def)\nqed\n\nend", "meta": {"author": "wimmers", "repo": "munta", "sha": "62cb1a4a4dbcfcf62c365e90faba15b0012d5a12", "save_path": "github-repos/isabelle/wimmers-munta", "path": "github-repos/isabelle/wimmers-munta/munta-62cb1a4a4dbcfcf62c365e90faba15b0012d5a12/Simple_Networks/Simple_Network_Language_Deadlock_Checking.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.66192288918838, "lm_q2_score": 0.4301473485858429, "lm_q1q2_score": 0.2847243757526624}}
{"text": "theory ProcSendCase\n  imports ResMapValid ReduceWTS ProcDef ProcCVars\nbegin\n  \nlemma cancel_strong_leq_use_env: \"\\<lbrakk> strong_use_env r_x \\<rbrakk> \\<Longrightarrow> leq_use_env (diff_use_env r_x r_x) r_s\"  \n  apply (simp add: leq_use_env_def)\n  apply (simp add: diff_use_env_def)\n  apply (simp add: strong_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n  done\n  \nlemma sfl_diff_use_env: \"\\<lbrakk> strong_use_env r_ex; leq_use_env r_ex r_s; is_own r \\<rbrakk> \\<Longrightarrow> diff_use_env r_s (diff_use_env (lift_use_env r_s r) r_ex) = r_ex\"\n  apply (case_tac \"\\<forall> x. diff_use_env r_s (diff_use_env (lift_use_env r_s r) r_ex) x = r_ex x\")\n   apply (auto)\n  apply (simp add: strong_use_env_def)\n  apply (simp add: leq_use_env_def)\n  apply (simp add: diff_use_env_def)\n  apply (simp add: is_own_def)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_ex x\")\n    apply (auto)  \n   apply (case_tac \"r_s x\")\n    apply (auto)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n  done    \n    \n    (* the question right now is, how do we make these types line up? *)\n  \nlemma safe_val_exp: \"\\<lbrakk> well_typed env r_s1 (app_hole h (AppExp (AppExp (ConstExp SendConst) (VarExp (LocType a b))) v)) tau r_s2 rx;\n  env (Loc a) = Some (ChanTy t SEnd); is_value c; is_value v \\<rbrakk> \\<Longrightarrow>\n  well_typed env (np_dom_use_env env v) v t (np_dom_use_env env v) (np_dom_use_env env v)\"    \n  apply (induct h arbitrary: env r_s1 tau r_s2 rx)\n       apply (auto)\n    (* base case *)\n  apply (case_tac \"t \\<noteq> t1\")\n   apply (simp add: pure_fun_def)\n  apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s2a\" and e=\"v\" and tau=\"t\" and ?r_s2.0=\"r_s3\" and rx=\"rx2\" in infl_sexp_wp)\n    apply (simp)\n   apply (rule_tac value_is_sexp)\n   apply (auto)\n    (* r = rb *)\n  apply (case_tac \"rb \\<noteq> r\")\n   apply (simp add: pure_fun_def)\n    (* the idea is that the infl_sexp_wp requirements are strictly greater than np_dom. since np_dom is strong, there is an exact way of\n        subtracting to get to np_dom. (we do cheat a little by lifting rx2). *)\n  apply (rule_tac t=\"np_dom_use_env env v\" and s=\"diff_use_env (comp_use_env (lift_use_env rx2 r) (infl_use_env r_s2a r_s3))\n    (diff_use_env (lift_use_env (comp_use_env (lift_use_env rx2 r) (infl_use_env r_s2a r_s3)) rb) (np_dom_use_env env v))\" in subst)\n   apply (rule_tac sfl_diff_use_env)\n     apply (simp add: np_dom_use_env_def)\n     apply (rule_tac strong_dom_use_env)\n    (* to prove that the infl_sexp_wp reqs are greater than np_dom, we use the fact that any npv must have a permission *)\n    apply (simp add: np_dom_use_env_def)\n    apply (simp add: dom_use_env_def)\n    apply (auto)\n   apply (simp add: leq_use_env_def)\n   apply (auto)\n   apply (case_tac \"comp_use_env (lift_use_env rx2 r) (infl_use_env r_s2a r_s3) x \\<noteq> OwnPerm\")\n    apply (case_tac \"comp_use_env rx2 (infl_use_env r_s2a r_s3) x = NoPerm\")\n     apply (cut_tac x=\"x\" and env=\"env\" and e=\"v\" and ?r_s1.0=\"comp_use_env rx2 (infl_use_env r_s2a r_s3)\" in well_typed_no_npv_use)\n       apply (auto)\n   apply (cut_tac r_sa=\"lift_use_env rx2 r\" and r_sb=\"infl_use_env r_s2a r_s3\" and x=\"x\" in comp_use_no_own_both)\n    apply (auto)\n   apply (case_tac \"rx2 x \\<noteq> NoPerm\")\n    apply (simp add: is_own_def)\n   apply (auto)\n   apply (case_tac \"infl_use_env r_s2a r_s3 x \\<noteq> NoPerm\")\n    apply (simp add: infl_use_env_def)\n    apply (case_tac \"r_s2a x = OwnPerm \\<and> r_s3 x = NoPerm\")\n     apply (auto)\n   apply (cut_tac r_sa=\"rx2\" and r_sb=\"infl_use_env r_s2a r_s3\" and x=\"x\" in comp_use_none)\n     apply (auto)\n    (* with that in mind, we manipulate until we match the infl sexp lemma *)\n  apply (rule_tac well_typed_diff_perms)\n   apply (rule_tac rx=\"comp_use_env rx2 (infl_use_env r_s2a r_s3)\" in well_typed_incr_req)\n     apply (rule_tac r_s=\"comp_use_env rx2 (infl_use_env r_s2a r_s3)\" in well_typed_incr_simul_perm)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (rule_tac comp_leq_use_env1)\n       apply (rule_tac self_lift_leq_use_env)\n      apply (rule_tac self_comp_leq_use_env2)\n     apply (simp)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (rule_tac comp_leq_use_env1)\n     apply (rule_tac self_lift_leq_use_env)\n    apply (rule_tac self_comp_leq_use_env2)\n   apply (rule_tac id_leq_use_env)\n    (* next, we must show that the differential is actually subtractible, which is true since it removes all non-prim vars *)\n  apply (auto)\n  apply (case_tac \"np_dom_use_env env v x \\<noteq> OwnPerm\")\n   apply (simp add: np_dom_use_env_def)\n   apply (simp add: dom_use_env_def)\n   apply (cut_tac r_s=\"lift_use_env (comp_use_env (lift_use_env rx2 r) (infl_use_env r_s2a r_s3)) r\" and\n       r_ex=\"np_dom_use_env env v\" and x=\"x\" in diff_use_none_ex)\n    apply (simp)\n  apply (simp add: own_env_vars_def)\n  done\n    \n  \nlemma safe_recv_exp: \"\\<lbrakk> well_typed env r_s1 (app_hole h (AppExp (ConstExp RecvConst) (VarExp (LocType a b)))) tau r_s2 rx;\n  env (Loc a) = Some (ChanTy t REnd); well_typed env r_x v t r_x r_x; disj_use_env r_s1 r_x; \n  strong_use_env r_x; is_value c; is_value v; is_own r \\<rbrakk> \\<Longrightarrow>\n  well_typed env (comp_use_env r_s1 r_x) (app_hole h v) tau r_s2 rx\"  \n  apply (induct h arbitrary: env r_s1 tau r_s2 rx)\n       apply (auto)\n    (* base case *)\n       apply (cut_tac r_sc=\"r_s2\" and r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 ra)) r_exa)\" and\n          r_sa=\"r_s1\" in trans_leq_use_env)\n         apply (rule_tac diff_leq_use_env)\n         apply (rule_tac r_sb=\"diff_use_env r_s2a (comp_use_env (ereq_use_env (Loc b) tau_x) r_ex)\" in trans_leq_use_env)\n          apply (rule_tac diff_leq_use_env)\n          apply (auto)\n       apply (rule_tac ?r_s2.0=\"diff_use_env (comp_use_env r_s1 r_x) r_x\"\n        and rx=\"diff_use_env r_x r_x\" in well_typed_simul_end_perm)\n          apply (rule_tac well_typed_diff_end_perm)\n           apply (rule_tac well_typed_comp_perms2)\n            apply (simp add: pure_fun_def)\n           apply (auto)\n          apply (rule_tac comm_disj_use_env)\n          apply (simp)\n         apply (rule_tac self_comp_leq_use_env2)\n        apply (rule_tac disj_diff_leq_use_env)\n         apply (rule_tac r_s=\"r_s1\" in disj_leq_use_env2)\n          apply (rule_tac comm_disj_use_env)\n          apply (simp_all)\n        apply (rule_tac comp_leq_use_env1)\n        apply (simp)\n       apply (rule_tac cancel_strong_leq_use_env)\n       apply (simp)\n    (* lhs pair case. *)\n      apply (rule_tac x=\"t1\" in exI)\n      apply (rule_tac x=\"ra\" in exI)\n      apply (rule_tac x=\"aa\" in exI)\n      apply (rule_tac x=\"r_s2a\" in exI)\n      apply (rule_tac x=\"rx1\" in exI)\n      apply (auto)\n      apply (rule_tac x=\"rx2\" in exI)\n      apply (rule_tac x=\"r_s3\" in exI)\n      apply (auto)\n      apply (rule_tac x=\"r_ex\" in exI)\n      apply (auto)\n      apply (rule_tac comp_leq_use_env1)\n      apply (simp)\n    (* rhs pair case. *)\n     apply (rule_tac x=\"t1\" in exI)\n     apply (rule_tac x=\"ra\" in exI)\n     apply (rule_tac x=\"aa\" in exI)\n     apply (rule_tac x=\"comp_use_env r_s2a r_x\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n      apply (rule_tac well_typed_comp_perms)\n       apply (simp_all)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (rule_tac x=\"r_s3\" in exI)\n     apply (auto)\n      apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" and r_ex=\"r_x\" in disj_leq_use_env1)\n        apply (simp)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n     apply (rule_tac x=\"r_ex\" in exI)\n     apply (auto)\n     apply (rule_tac comp_leq_use_env1)\n     apply (simp)\n    (* if case. *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"r_s2a\" in exI)\n    apply (auto)\n    (* lhs pair case. *)\n   apply (rule_tac x=\"r_s2a\" in exI)\n   apply (rule_tac x=\"r_s3\" in exI)\n   apply (rule_tac x=\"rx1\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"rx2\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_ex\" in exI)\n   apply (auto)\n   apply (rule_tac comp_leq_use_env1)\n   apply (simp)\n    (* rhs pair case. *)\n  apply (rule_tac x=\"comp_use_env r_s2a r_x\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n   apply (auto)\n   apply (rule_tac well_typed_comp_perms)\n    apply (simp_all)\n  apply (rule_tac x=\"rx2\" in exI)\n   apply (auto)\n   apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" and r_ex=\"r_x\" in disj_leq_use_env1)\n     apply (simp)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n  apply (rule_tac x=\"r_ex\" in exI)\n  apply (auto)\n  apply (rule_tac comp_leq_use_env1)\n  apply (simp)\n  done\n    \nlemma safe_own_npv_use: \"\\<lbrakk> well_typed env r_s1 (app_hole h (AppExp f v)) tau r_s2 rx; is_value f; strong_fun f;\n  a \\<noteq> NoRef; is_value v; x \\<in> non_prim_vars env v \\<rbrakk> \\<Longrightarrow> r_s1 x = OwnPerm\"\n  apply (induct h arbitrary: env r_s1 r_s2 tau rx)\n       apply (auto)\n    (* base case *)\n    apply (cut_tac f=\"f\" and r=\"r\" in strong_fun_own)\n      apply (auto)\n    apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s2a\" and e=\"v\" and ?r_s2.0=\"r_s3\" and rx=\"rx2\" in infl_sexp_wp)\n      apply (auto)\n     apply (rule_tac value_is_sexp)\n     apply (simp)\n    apply (case_tac \"comp_use_env rx2 (infl_use_env r_s2a r_s3) x = NoPerm\")\n     apply (cut_tac env=\"env\" and x=\"x\" and e=\"v\" and ?r_s1.0=\"comp_use_env rx2 (infl_use_env r_s2a r_s3)\" in well_typed_no_npv_use)\n       apply (auto)\n    apply (case_tac \"rx2 x \\<noteq> NoPerm\")\n     apply (cut_tac r_x=\"lift_use_env rx2 r\" and r_s=\"r_s1\" and x=\"x\" in leq_use_own)\n      apply (simp add: is_own_def)\n     apply (rule_tac r_sb=\"comp_use_env rx1 (lift_use_env rx2 r)\" in trans_leq_use_env)\n      apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n       apply (rule_tac r_sb=\"r_s2a\" in trans_leq_use_env)\n        apply (auto)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n     apply (rule_tac self_comp_leq_use_env2)\n    apply (case_tac \"infl_use_env r_s2a r_s3 x \\<noteq> NoPerm\")\n     apply (simp add: infl_use_env_def)\n     apply (case_tac \"r_s2a x = OwnPerm \\<and> r_s3 x = NoPerm\")\n      apply (auto)\n     apply (rule_tac r_x=\"r_s2a\" in leq_use_own)\n      apply (auto)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n    apply (cut_tac r_sa=\"rx2\" and r_sb=\"infl_use_env r_s2a r_s3\" and x=\"x\" in comp_use_none)\n      apply (auto)\n    (* rhs induct *)\n   apply (rule_tac r_x=\"r_s2a\" in leq_use_own)\n    apply (simp)\n   apply (rule_tac well_typed_perm_leq)\n   apply (auto)\n    (* rhs pair *)\n  apply (rule_tac r_x=\"r_s2a\" in leq_use_own)\n   apply (simp)\n  apply (rule_tac well_typed_perm_leq)\n  apply (auto)\n  done    \n  \n    \nlemma safe_send_exp_ih: \"\\<lbrakk> well_typed env r_s1 (app_hole h (AppExp (AppExp (ConstExp SendConst) c) v)) tau r_s2 rx; is_value c; is_value v \\<rbrakk> \\<Longrightarrow>\n  well_typed env r_s1 (app_hole h (ConstExp UnitConst)) tau r_s2 rx\"  \n  apply (induct h arbitrary: env r_s1 tau r_s2 rx)\n       apply (auto)\n    (* base case *)\n        apply (simp add: pure_fun_def)\n       apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n        apply (rule_tac diff_leq_use_env)\n        apply (rule_tac r_sb=\"r_s2a\" in trans_leq_use_env)\n         apply (rule_tac r_sb=\"diff_use_env r_s3a (comp_use_env (comp_use_env rx1a (lift_use_env rx2a ra)) r_exa)\" in trans_leq_use_env)\n          apply (rule_tac diff_leq_use_env)\n          apply (rule_tac r_sb=\"r_s2b\" in trans_leq_use_env)\n           apply (simp_all)\n        apply (rule_tac well_typed_perm_leq)\n        apply (auto)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n    (* lhs app case *)\n      apply (rule_tac x=\"t1\" in exI)\n      apply (rule_tac x=\"r\" in exI)\n      apply (rule_tac x=\"a\" in exI)\n      apply (rule_tac x=\"r_s2a\" in exI)\n      apply (rule_tac x=\"rx1\" in exI)\n      apply (auto)\n    (* rhs app case *)\n     apply (rule_tac x=\"t1\" in exI)\n     apply (rule_tac x=\"r\" in exI)\n     apply (rule_tac x=\"a\" in exI)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (rule_tac x=\"r_s3\" in exI)\n     apply (auto) \n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"r_s2a\" in exI)\n    apply (auto)\n    (* lhs pair case *)\n   apply (rule_tac x=\"r_s2a\" in exI)\n   apply (rule_tac x=\"r_s3\" in exI)\n   apply (rule_tac x=\"rx1\" in exI)\n   apply (auto)\n    (* rhs pair case *)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (auto)\n  done\n    \n    \nlemma safe_send_exp: \"\\<lbrakk> well_typed env r_s1 (app_hole h (AppExp (AppExp (ConstExp SendConst) (VarExp (LocType a b))) v)) tau r_s2 rx;\n  valid_nres_map s rs_map; valid_exp_use_env s rs_map r_s1; wf_hole h; is_value v \\<rbrakk> \\<Longrightarrow>\n  well_typed env (diff_use_env r_s1 (full_dom_use_env env rs_map v)) (app_hole h (ConstExp UnitConst)) tau\n    (diff_use_env r_s2 (full_dom_use_env env rs_map v)) (diff_use_env rx (full_dom_use_env env rs_map v))\"  \n  apply (rule_tac well_typed_diff_perms)\n   apply (rule_tac c=\"VarExp (LocType a b)\" in safe_send_exp_ih)\n     apply (auto)\n    (* we want to show that if xa is in the dominator, it is not an np-var in h.\n        > if xa is an np-var itself, it cannot be in e by lemma *)\n  apply (case_tac \"x \\<in> non_prim_vars env v\")\n   apply (cut_tac h=\"h\" and x=\"x\" and e=\"ConstExp UnitConst\" in app_hole_res_vars_rev)\n    apply (auto)\n    apply (simp add: non_prim_vars_def)\n   apply (cut_tac h=\"h\" and x=\"x\" and env=\"env\" and ?r_s1.0=\"r_s1\" and v=\"VarExp (LocType a b)\" and e=\"v\" in safe_send_hole_npv_use)\n        apply (auto)\n    (* otherwise, xa is in the completion. we identify its ancestor z. *)\n  apply (simp add: own_env_vars_def)\n  apply (simp add: full_dom_use_env_def)\n  apply (simp add: dom_use_env_def)\n  apply (case_tac \"\\<exists>xa. x = Loc xa \\<and> (\\<exists>l z. Loc z \\<in> non_prim_vars env v \\<and> path_lookup rs_map z l xa)\")\n   apply (auto)\n    (* we note that z is a np-var of e therefore r_s1 z = Own *)\n  apply (cut_tac x=\"Loc z\" and env=\"env\" and f=\"AppExp (ConstExp SendConst) (VarExp (LocType a b))\" in safe_own_npv_use)\n        apply (auto)\n   apply (simp add: pure_fun_def)\n   apply (simp add: is_own_def)\n    (* xa then is in the lookup map of some parent y. *)\n  apply (cut_tac rs_map=\"rs_map\" and z=\"z\" and x=\"xa\" in path_lookup_parent)\n     apply (auto)\n    (* with that in mind, by separation, x is disjoint from r_s1. *)\n  apply (case_tac \"r_s1 (Loc xa) \\<noteq> NoPerm\")\n   apply (simp add: valid_exp_use_env_def)\n   apply (simp add: sep_nres_map_def)\n   apply (auto)\n   apply (erule_tac x=\"y\" in allE)\n   apply (simp add: nres_lookup_def)\n   apply (simp add: strong_disj_use_env_def)\n   apply (erule_tac x=\"Loc xa\" in allE)\n   apply (auto)\n    (* by extension, x is not in 'h (send c v)' *)\n  apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s1\" and x=\"Loc xa\" in well_typed_no_npv_use)\n    apply (auto)\n  apply (simp add: non_prim_vars_def)    \n    (* the very last part is showing that x not in 'h (send c v)' implies x not in 'h ()'. *)\n  apply (cut_tac x=\"Loc xa\" and h=\"h\" and e=\"ConstExp UnitConst\" in app_hole_res_vars_rev)\n   apply (auto)\n  apply (cut_tac x=\"Loc xa\" and h=\"h\" and e=\"AppExp (AppExp (ConstExp SendConst) (VarExp (LocType a b))) v\" in app_hole_res_vars2)\n   apply (auto)\n  done\n    \nlemma disj_lift_use_envr_rev: \"\\<lbrakk> strong_disj_use_env r_s r_x \\<rbrakk> \\<Longrightarrow> disj_use_env r_s (lift_use_env r_x r)\"    \n  apply (simp add: strong_disj_use_env_def)\n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (auto)\n   apply (erule_tac x=\"x\" in allE)\n   apply (auto)\n   apply (case_tac r)\n     apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (case_tac r)\n    apply (auto)\n  done\n    \nlemma lift_strong_disj_use_env1: \"\\<lbrakk> strong_disj_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> strong_disj_use_env (lift_use_env r_x r) r_s\"    \n  apply (simp add: strong_disj_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (case_tac r)\n    apply (auto)\n  done\n  \nlemma send_disj_nres_map: \"\\<lbrakk> disj_nres_map p_map; p_map u1 = Some r_sa; p_map u2 = Some r_sb; is_own r;\n  leq_use_env r_xa (lift_use_env r_sa r); leq_use_env r_xb (comp_use_env (lift_use_env r_sa r) (lift_use_env r_sb r));\n  strong_disj_use_env r_xa r_xb \\<rbrakk> \\<Longrightarrow> disj_nres_map (add_env (add_env p_map u1 r_xa) u2 r_xb)\"    \n  apply (rule_tac disj_add_nres_map)  \n   apply (rule_tac disj_add_nres_map)  \n    apply (simp)\n    (* proving disjointness for the send thread's material *)\n   apply (rule_tac r_s=\"lift_use_env r_sa r\" in leq_sep_nres_map)\n    apply (simp)\n   apply (simp add: disj_nres_map_def)\n   apply (simp add: sep_nres_map_def)\n   apply (auto)\n   apply (case_tac \"x = u1\")\n    apply (simp add: nres_lookup_def)\n    apply (simp add: rem_env_def)\n    apply (rule_tac empty_strong_disj_use_env2)\n   apply (rule_tac lift_strong_disj_use_env1)\n   apply (erule_tac x=\"u1\" in allE)\n   apply (erule_tac x=\"x\" in allE)\n   apply (simp add: nres_lookup_def)\n   apply (simp add: rem_env_def)\n    (* proving disjointness for the recv thread *)\n  apply (simp add: sep_nres_map_def)\n  apply (auto)\n  apply (case_tac \"u2 = x\")\n   apply (simp add: nres_lookup_def)\n   apply (simp add: rem_env_def)\n   apply (rule_tac empty_strong_disj_use_env2)\n  apply (case_tac \"u1 = x\")\n   apply (simp add: nres_lookup_def)\n   apply (simp add: rem_env_def)\n   apply (simp add: add_env_def)\n   apply (rule_tac comm_strong_disj_use_env)\n   apply (simp)\n  apply (simp add: nres_lookup_def)\n  apply (simp add: rem_env_def)\n  apply (simp add: add_env_def)\n  apply (simp add: disj_nres_map_def)\n  apply (rule_tac r_s=\"comp_use_env (lift_use_env r_sa r) (lift_use_env r_sb r)\" in strong_disj_leq_use_env1)\n   apply (rule_tac strong_disj_comp_use_env2)\n    apply (rule_tac lift_strong_disj_use_env1)\n    apply (erule_tac x=\"u1\" in allE)\n    apply (erule_tac x=\"x\" in allE)\n    apply (simp add: nres_lookup_def)\n   apply (rule_tac lift_strong_disj_use_env1)\n   apply (erule_tac x=\"u2\" in allE)\n   apply (erule_tac x=\"x\" in allE)\n   apply (simp add: nres_lookup_def)\n  apply (simp)\n  done\n  \nfun proper_hole where\n  \"proper_hole rs_map ExpHole = True\"\n| \"proper_hole rs_map (AppHole1 h e) = (proper_hole rs_map h \\<and> proper_exp rs_map e)\"    \n| \"proper_hole rs_map (AppHole2 v h) = (proper_exp rs_map v \\<and> proper_hole rs_map h)\"\n| \"proper_hole rs_map (IfHole h e1 e2) = (proper_hole rs_map h \\<and> proper_exp rs_map e1 \\<and> proper_exp rs_map e2)\"  \n| \"proper_hole rs_map (PairHole1 h e) = (proper_hole rs_map h \\<and> proper_exp rs_map e)\"    \n| \"proper_hole rs_map (PairHole2 v h) = (proper_exp rs_map v \\<and> proper_hole rs_map h)\"\n \nlemma proper_app_hole_split1: \"\\<lbrakk> proper_exp rs_map (app_hole h e) \\<rbrakk> \\<Longrightarrow> proper_hole rs_map h\" \n  apply (induct h)\n       apply (auto)\n            apply (simp_all add: proper_exp_def)\n  done\n\nlemma proper_app_hole_split2: \"\\<lbrakk> proper_exp rs_map (app_hole h e) \\<rbrakk> \\<Longrightarrow> proper_exp rs_map e\" \n  apply (induct h)\n       apply (auto)\n      apply (simp_all add: proper_exp_def)\n  done\n    \nlemma proper_app_hole_recon: \"\\<lbrakk> proper_hole rs_map h; proper_exp rs_map e \\<rbrakk> \\<Longrightarrow> proper_exp rs_map (app_hole h e)\"    \n  apply (induct h)\n       apply (auto)\n      apply (simp_all add: proper_exp_def)\n  done\n  \nlemma proper_app_hole: \"\\<lbrakk> proper_exp rs_map (app_hole h e1); proper_exp rs_map e2 \\<rbrakk> \\<Longrightarrow> proper_exp rs_map (app_hole h e2)\"    \n  apply (cut_tac rs_map=\"rs_map\" and h=\"h\" and e=\"e1\" in proper_app_hole_split1)\n   apply (auto)\n  apply (rule_tac proper_app_hole_recon)\n   apply (auto)\n  done\n  \nlemma srps_send_case: \"\\<lbrakk>well_typed_system env rs_map p_map s2 ps1; valid_reduct app_red_exp; r_ax = SendAct;\n        ps1 u1 = Some (app_hole h1 (AppExp (AppExp (ConstExp SendConst) (VarExp (LocType x_s a_s))) v));\n        ps1 u2 = Some (app_hole h2 (AppExp (ConstExp RecvConst) (VarExp (LocType x_r a_r)))); u1 \\<noteq> u2; wf_hole h1;\n        wf_hole h2; is_value v; s2 x_s = Some ChanSValue;\n        s2 x_r = Some (ChanRValue x_s); s1 = s2;\n        ps2 = add_env (add_env ps1 u1 (app_hole h1 (ConstExp UnitConst))) u2 (app_hole h2 v)\\<rbrakk>\n       \\<Longrightarrow> \\<exists>r_s g_ax.\n              (\\<exists>p_map'. well_typed_system (red_env env g_ax) (red_nres_map rs_map g_ax) p_map' s2\n                         (add_env (add_env ps1 u1 (app_hole h1 (ConstExp UnitConst))) u2 (app_hole h2 v))) \\<and>\n              safe_act s2 r_s g_ax\"\n      (* send case. no resources are generated in this step *)\n  apply (rule_tac x=\"empty_use_env\" in exI)\n  apply (rule_tac x=\"NoResAct\" in exI)\n  apply (auto)\n  apply (simp add: well_typed_system_def)\n  apply (auto)\n    (* we have to get the well-typedness statement for h1 [send c v] *)\n  apply (case_tac \"\\<not> (case ps1 u1 of None \\<Rightarrow> True | Some e \\<Rightarrow> (case p_map u1 of None \\<Rightarrow> False | Some r_s \\<Rightarrow> \\<exists>rx r_s2. well_typed env r_s e UnitTy r_s2 rx \\<and> proper_exp rs_map e))\")\n   apply (simp add: well_typed_proc_set_def)\n   apply (auto)\n   apply (erule_tac x=\"u1\" in allE)\n   apply (erule_tac x=\"u1\" in allE)\n   apply (auto)\n  apply (case_tac \"p_map u1\")\n   apply (auto)\n    (* we also get the well-typedness statement for h2 [recv c v] *)\n  apply (case_tac \"\\<not> (case ps1 u2 of None \\<Rightarrow> True | Some e \\<Rightarrow> (case p_map u2 of None \\<Rightarrow> False | Some r_s \\<Rightarrow> \\<exists>rx r_s2. well_typed env r_s e UnitTy r_s2 rx \\<and> proper_exp rs_map e))\")\n   apply (simp add: well_typed_proc_set_def)\n   apply (auto)\n   apply (erule_tac x=\"u2\" in allE)\n   apply (erule_tac x=\"u2\" in allE)\n   apply (auto)\n  apply (case_tac \"p_map u2\")\n   apply (auto)\n    (* next we get the send channel's type *)\n  apply (case_tac \"\\<not> (\\<exists> t. env (Loc x_s) = Some (ChanTy t SEnd))\")\n   apply (simp add: well_typed_state_def)\n   apply (auto)\n   apply (erule_tac x=\"x_s\" in allE)\n   apply (erule_tac x=\"x_s\" in allE)\n   apply (auto)\n   apply (case_tac \"env (Loc x_s)\")\n    apply (auto)\n    (* and the recv channel's type *)\n  apply (case_tac \"\\<not> env (Loc x_r) = Some (ChanTy t REnd)\")\n   apply (simp add: well_typed_state_def)\n   apply (auto)\n   apply (erule_tac x=\"x_r\" in allE)\n   apply (erule_tac x=\"x_r\" in allE)\n   apply (auto)\n   apply (case_tac \"env (Loc x_r)\")\n    apply (auto)\n    (* prelim: we prove the dominator of v \\<le> lift a r (the permission map of u1) *)\n  apply (cut_tac eq_own)\n  apply (auto)\n  apply (cut_tac r_sc=\"np_dom_use_env env v\" and r_sb=\"np_dom_use_env env (app_hole h1 (AppExp (AppExp (ConstExp SendConst) (VarExp (LocType x_s a_s))) v))\"\n      and r_sa=\"lift_use_env a r\" in trans_leq_use_env)\n    apply (rule_tac wt_np_leq_use_env)\n     apply (auto)\n   apply (simp add: np_dom_use_env_def)\n   apply (rule_tac dist_dom_leq_use_env)\n   apply (auto)\n   apply (simp add: non_prim_vars_def)\n   apply (rule_tac app_hole_res_vars)\n   apply (auto)\n    (* we can generate a type for h1 () *)\n  apply (cut_tac env=\"env\" and v=\"v\" and ?r_s1.0=\"a\" and tau=\"UnitTy\" and h=\"h1\" and ?r_s2.0=\"r_s2\" and rx=\"rx\" and s=\"s2\" and rs_map=\"rs_map\" in safe_send_exp)\n        apply (auto)\n    apply (simp add: well_typed_state_def)\n    (* - complete proof that a is still valid *)\n   apply (simp add: valid_exp_use_env_def)\n   apply (simp add: well_typed_proc_set_def)\n   apply (simp add: sub_nres_map_def)\n   apply (erule_tac x=\"u1\" in allE)\n   apply (erule_tac x=\"u1\" in allE)\n   apply (simp add: nres_lookup_def)\n    (* we can also generate a type for h2 v, first by getting a type for v, and then by putting it in the hole *)\n  apply (cut_tac env=\"env\" and v=\"v\" and h=\"h1\" and a=\"x_s\" and a=\"a_s\" and t=\"t\" in safe_val_exp)\n      apply (auto)\n  apply (cut_tac env=\"env\" and ?r_s1.0=\"aa\" and h=\"h2\" and r_x=\"np_dom_use_env env v\" in safe_recv_exp)\n          apply (auto)\n    (* - p_map disjointness proves that the permissions being added are disjoint *)\n    apply (rule_tac r_s=\"lift_use_env a r\" in disj_leq_use_env2)\n     apply (case_tac \"\\<forall>x y. x \\<noteq> y \\<longrightarrow> strong_disj_use_env (nres_lookup p_map x) (nres_lookup p_map y)\")\n      apply (erule_tac x=\"u1\" in allE)\n      apply (erule_tac x=\"u2\" in allE)\n      apply (erule_tac x=\"u1\" in allE)\n      apply (auto)\n     apply (simp add: nres_lookup_def)\n     apply (rule_tac disj_lift_use_envr_rev)\n     apply (simp)\n    apply (simp add: well_typed_proc_set_def)\n    apply (simp add: disj_nres_map_def)\n    (* - proving the dominator is strong *)\n   apply (simp add: np_dom_use_env_def)\n   apply (rule_tac strong_dom_use_env)\n    (* lastly it remains to prove the new process map is well-formed *)\n  apply (rule_tac x=\"add_env (add_env p_map u1 (diff_use_env a (full_dom_use_env env rs_map v)))\n    u2 (comp_use_env aa (np_dom_use_env env v))\" in exI)\n  apply (simp add: well_typed_proc_set_def)\n  apply (auto)\n    (* completeness *)\n      apply (rule_tac add_full_nres_map)\n      apply (rule_tac add_full_nres_map)\n      apply (simp)\n    (* disjointness, assisted by lemma *)\n     apply (rule_tac r_sa=\"a\" and r_sb=\"aa\" in send_disj_nres_map)\n           apply (simp_all)\n       apply (rule_tac diff_leq_use_env)\n       apply (rule_tac self_lift_leq_use_env)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (rule_tac comp_leq_use_env2)\n       apply (rule_tac self_lift_leq_use_env)\n      apply (rule_tac comp_leq_use_env1)\n      apply (simp)\n     apply (rule_tac strong_disj_comp_use_env1)\n      apply (rule_tac r_s=\"a\" in strong_disj_leq_use_env1)\n       apply (simp add: disj_nres_map_def)\n       apply (erule_tac x=\"u1\" in allE)\n       apply (erule_tac x=\"u1\" in allE)\n       apply (erule_tac x=\"u1\" in allE)\n       apply (erule_tac x=\"u2\" in allE)\n       apply (simp add: nres_lookup_def)\n      apply (rule_tac self_diff_leq_use_env)\n     apply (rule_tac r_s=\"full_dom_use_env env rs_map v\" in strong_disj_leq_use_env2)\n      apply (rule_tac diff_strong_disj_use_env)\n      apply (simp add: full_dom_use_env_def)\n      apply (rule_tac strong_dom_use_env)\n     apply (rule_tac full_dom_leq_use_env)\n    (* proving that the processes are well-typed *)\n    apply (case_tac \"u = u1\")\n     apply (simp add: add_env_def)\n     apply (auto)\n     apply (rule_tac proper_app_hole)\n      apply (simp)\n     apply (simp add: proper_exp_def)\n    apply (case_tac \"u = u2\")\n     apply (simp add: add_env_def)\n     apply (auto)\n     apply (rule_tac proper_app_hole)\n      apply (simp)\n     apply (cut_tac rs_map=\"rs_map\" and h=\"h1\" and e=\"AppExp (AppExp (ConstExp SendConst) (VarExp (LocType x_s a_s))) v\" in proper_app_hole_split2)\n      apply (simp)\n     apply (simp add: proper_exp_def)\n    apply (simp add: add_env_def)\n    apply (erule_tac x=\"u\" in allE)\n    apply (erule_tac x=\"u\" in allE)\n    apply (case_tac \"ps1 u\")\n     apply (auto)\n    apply (simp add: add_env_def)\n    (* proving res_map element containment *)\n   apply (rule_tac add_sub_nres_map1)\n    apply (rule_tac add_sub_nres_map1)\n     apply (simp)\n    apply (rule_tac r_s=\"a\" in trans_sub_use_env)\n     apply (simp add: sub_nres_map_def)\n     apply (erule_tac x=\"u1\" in allE)\n     apply (simp add: nres_lookup_def)\n    apply (rule_tac self_diff_leq_use_env)\n   apply (rule_tac comp_sub_use_env)\n    apply (simp add: sub_nres_map_def)\n    apply (erule_tac x=\"u2\" in allE)\n    apply (simp add: nres_lookup_def)\n   apply (rule_tac r_s=\"lift_use_env a r\" in trans_sub_use_env)\n    apply (rule_tac lift_sub_use_env)\n    apply (simp add: sub_nres_map_def)\n    apply (erule_tac x=\"u1\" in allE)\n    apply (simp add: nres_lookup_def)\n   apply (simp)\n    (* poriving the separation of the new maps *)\n  apply (case_tac \"u = u1\")\n   apply (simp add: add_env_def)\n   apply (rule_tac r_s=\"a\" in leq_sep_nres_map)\n    apply (rule_tac self_diff_leq_use_env)\n   apply (erule_tac x=\"u1\" in allE)\n   apply (auto)\n  apply (case_tac \"u = u2\")\n   apply (simp add: add_env_def)\n   apply (rule_tac comp_sep_nres_map)\n    apply (erule_tac x=\"u2\" in allE)\n    apply (auto)\n   apply (erule_tac x=\"u1\" in allE)\n   apply (auto)\n   apply (rule_tac r_s=\"lift_use_env a r\" in leq_sep_nres_map)\n    apply (simp)\n   apply (simp add: sep_nres_map_def)\n    apply (auto)\n   apply (rule_tac lift_strong_disj_use_env1)\n   apply (simp)\n  apply (simp add: add_env_def)\n  done\n    \n    \nend", "meta": {"author": "anon-ef", "repo": "perm_lang_ef2", "sha": "0fcb6e4c175193cc7b94f297a8aaa605f502d711", "save_path": "github-repos/isabelle/anon-ef-perm_lang_ef2", "path": "github-repos/isabelle/anon-ef-perm_lang_ef2/perm_lang_ef2-0fcb6e4c175193cc7b94f297a8aaa605f502d711/perm_ref/ProcSendCase.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6619228758499942, "lm_q2_score": 0.4301473485858429, "lm_q1q2_score": 0.2847243700151911}}
{"text": "(*  Title:       Lightweight Java, the equivalence functions\n    Authors:     Rok Strnisa <rok@strnisa.com>, 2006\n                 Matthew Parkinson <matt@matthewp.com>, 2006\n    Maintainer:  \n*)\n\ntheory Lightweight_Java_Equivalence imports Lightweight_Java_Definition begin\n\n(* BEGIN: HELPER FUNCTIONS *)\n\nlemma map_id[simp]: \"map id list = list\" by (induct list) auto\n\nlemma id_map_two[simp]: \"map (\\<lambda>(x,y). (x,y)) list = list\" by (induct list) auto\n\nlemma id_image_two[simp]: \"(\\<lambda>(x,y). (x,y)) ` set list = set list\" by (induct list) auto\n\nlemma map_fst[simp]: \"map (\\<lambda>(x, y). x) list = map fst list\" by (induct list) auto\n\nlemma map_snd[simp]: \"map (\\<lambda>(x, y). y) list = map snd list\" by (induct list) auto\n\nlemma zip_map_map_two [simp]: \"zip (map fst list) (map snd list) = list\"\nby (induct list) auto\n\nlemma concat_map_singlton [simp]: \"concat (map (\\<lambda>e. [e]) list) = list\"\nby (induct list) simp_all\n\nlemma list_all_map_P [simp]: \"list_all (\\<lambda>b. b) (map (\\<lambda>x. P x) list) = (\\<forall>x \\<in> set list. P x)\"\nby (induct list) simp_all\n\nlemma dom_single[simp]: \"a : dom (Map.empty(k \\<mapsto> v)) = (a = k)\"\nby (simp add: dom_def)\n\nlemma predicted_lu[rule_format, simp]:\n  \"x \\<in> set list \\<longrightarrow> map_of (map (\\<lambda>key. (key, value)) list) x = Some value\"\nby (induct list) auto\n\nlemma key_in_map1[simp]: \"k \\<notin> dom M' \\<Longrightarrow> (M ++ M') k = M k\"\napply (subgoal_tac \"M' k = None\")\napply (simp add: map_add_def, force simp add: domI)\ndone\n\nlemma forall_cons [rule_format]: \"(\\<forall>x \\<in> set (s#S). P x) \\<and> y \\<in> set S \\<longrightarrow> P y\"\nby (induct_tac S) simp_all\n\nlemma mem_cong[rule_format]:\n  \"x \\<in> set list \\<longrightarrow> (f x \\<in> set (map f list))\"\nby (induct list) auto\n\nlemma forall_union: \"\\<lbrakk>\\<forall>a \\<in> dom A. P (A a); \\<forall>b \\<in> dom B. P (B b)\\<rbrakk> \\<Longrightarrow> \\<forall>x \\<in> dom A \\<union> dom B. P ((B ++ A) x)\"\napply(safe)\n apply(force)\napply(drule_tac x = x in bspec, simp add: domI)\napply(case_tac \"A x = None\")\n apply(force simp add: map_add_def)\nby (force)\n\n(* END: HELPER FUNCTIONS *)\n\ndefinition\nclass_name_f :: \"cld \\<Rightarrow> dcl\"\nwhere\n\"class_name_f cld =\n  (case cld of cld_def dcl cl fds mds \\<Rightarrow> dcl)\"\n\n\ndefinition\nsuperclass_name_f :: \"cld \\<Rightarrow> cl\"\nwhere\n\"superclass_name_f cld =\n  (case cld of cld_def dcl cl fds mds \\<Rightarrow> cl)\"\nlemma [simp]: \"(superclass_name cld cl) = (superclass_name_f cld = cl)\"\nby (force simp add: superclass_name_f_def split: cld.splits\n          intro: superclass_nameI elim: superclass_name.cases)\n\ndefinition\nclass_fields_f :: \"cld \\<Rightarrow> fds\"\nwhere\n\"class_fields_f cld =\n  (case cld of cld_def dcl cl fds mds \\<Rightarrow> fds)\"\nlemma [simp]: \"(class_fields cld fds) = (class_fields_f cld = fds)\"\nby (force simp add: class_fields_f_def split: cld.splits\n          intro: class_fieldsI elim: class_fields.cases)\n\ndefinition\nclass_methods_f :: \"cld \\<Rightarrow> meth_defs\"\nwhere\n\"class_methods_f cld =\n  (case cld of cld_def dcl cl fds mds \\<Rightarrow> mds)\"\nlemma [simp]: \"(class_methods cld fds) = (class_methods_f cld = fds)\"\nby (force simp add: class_methods_f_def split: cld.splits\n          intro: class_methodsI elim: class_methods.cases)\n\ndefinition\nmethod_name_f :: \"meth_def \\<Rightarrow> meth\"\nwhere\n\"method_name_f md =\n  (case md of meth_def_def meth_sig meth_body \\<Rightarrow>\n  (case meth_sig of meth_sig_def cl meth vds \\<Rightarrow> meth))\"\nlemma [simp]: \"(method_name md m) = (method_name_f md = m)\"\nby (force simp add: method_name_f_def split: meth_def.splits meth_sig.splits\n          intro: method_nameI elim: method_name.cases)\n\ndefinition\ndistinct_names_f :: \"P \\<Rightarrow> bool\"\nwhere\n\"distinct_names_f P =\n  (distinct (map class_name_f P))\"\nlemma distinct_names_map[rule_format]:\n  \"(\\<forall>x\\<in>set cld_dcl_list. case_prod (\\<lambda>cld. (=) (class_name_f cld)) x) \\<and> distinct (map snd cld_dcl_list)\n      \\<longrightarrow> distinct_names_f (map fst cld_dcl_list)\"\napply(induct cld_dcl_list)\n apply(clarsimp simp add: distinct_names_f_def)+ apply(force)\ndone\nlemma [simp]: \"(distinct_names P) = (distinct_names_f P)\"\napply(rule)\n apply(erule distinct_names.cases) apply(clarsimp simp add: distinct_names_map)\napply(simp add: distinct_names_f_def)\napply(rule_tac cld_dcl_list = \"map (\\<lambda>cld. (cld, class_name_f cld)) P\" in dn_defI)\n  apply(simp) apply(induct P) apply(simp) apply(simp)\n apply(clarsimp)\napply(clarsimp) apply(induct P) apply(simp) apply(force)\ndone\n\nprimrec\nfind_cld_f :: \"P \\<Rightarrow> ctx \\<Rightarrow> fqn \\<Rightarrow> ctxcld_opt\"\nwhere\n\"find_cld_f []         ctx fqn = None\" |\n\"find_cld_f (cld#clds) ctx fqn =\n  (case cld of cld_def dcl cl fds mds \\<Rightarrow>\n  (case fqn of fqn_def dcl' \\<Rightarrow>\n  (if dcl = dcl' then Some (ctx, cld) else find_cld_f clds ctx fqn)))\"\nlemma [simp]: \"(find_cld P ctx fqn ctxcld_opt) = (find_cld_f P ctx fqn = ctxcld_opt)\"\napply(rule)\n apply(induct rule: find_cld.induct) apply(simp+)\n apply(clarsimp)\napply(induct P)\n apply(simp add: fc_emptyI)\napply(case_tac fqn) apply(rename_tac cld clds dcl) apply(case_tac cld)\napply(clarsimp) apply(rename_tac dcl' cl' vds' mds') apply(rule)\napply(clarsimp) apply(rule fc_cons_trueI) apply(simp) apply(force)\napply(force intro: fc_cons_falseI[simplified])\ndone\n\nlemma find_to_mem[rule_format]:\n  \"find_cld_f P ctx fqn = Some (ctx', cld) \\<longrightarrow> cld : set P\"\napply(induct P) by (clarsimp split: cld.splits fqn.splits)+\n\nlemma find_cld_name_eq[rule_format]:\n  \"\\<forall>ctxcld. find_cld_f P ctx (fqn_def dcl) = Some ctxcld \\<longrightarrow> (\\<exists>cl fds mds. (ctx, cld_def dcl cl fds mds) = ctxcld)\"\napply(induct P) apply(simp) apply(clarsimp split: cld.splits fqn.splits) done\n\nprimrec\nfind_type_f :: \"P \\<Rightarrow> ctx \\<Rightarrow> cl \\<Rightarrow> ty_opt\"\nwhere\n\"find_type_f P ctx cl_object = Some ty_top\" |\n\"find_type_f P ctx (cl_fqn fqn) =\n  (case fqn of fqn_def dcl \\<Rightarrow>\n  (case find_cld_f P ctx fqn of None \\<Rightarrow> None | Some (ctx', cld) \\<Rightarrow>\n     Some (ty_def ctx' dcl)))\"\nlemma [simp]: \"(find_type P ctx cl ty_opt) = (find_type_f P ctx cl = ty_opt)\"\napply(rule)\n apply(force elim: find_type.cases split: fqn.splits)\napply(case_tac cl) apply(force intro: ft_objI)\napply(rename_tac fqn)\napply(case_tac fqn) apply(clarsimp)\napply(split option.splits) apply(rule)\n apply(force intro: ft_nullI)\nby (force intro: ft_dclI)\n\nlemma mem_remove: \"cld : set P \\<Longrightarrow> length (remove1 cld P) < length P\"\napply(induct P) by(simp, force split: if_split_asm)\n\nlemma finite_program[rule_format, intro]:\n  \"\\<forall>P cld. (\\<exists>ctx ctx' fqn. find_cld_f P ctx fqn = Some (ctx', cld)) \\<longrightarrow>\n      length (remove1 cld P) < length P\"\napply(clarsimp) apply(drule find_to_mem) by (simp add: mem_remove)\n\nlemma path_length_eq[rule_format]:\n  \"path_length P ctx cl nn \\<Longrightarrow> \\<forall>nn'. path_length P ctx cl nn' \\<longrightarrow> nn = nn'\"\napply(erule path_length.induct)\n apply(clarsimp) apply(erule path_length.cases) apply(simp) apply(simp)\napply(rule) apply(rule)\napply(erule_tac ?a4.0 = nn' in path_length.cases) apply(clarify)\napply(clarsimp)\ndone\n\nlemma fpr_termination[iff]:\n  \"\\<forall>P cld ctx ctx' fqn. find_cld_f P ctx fqn = Some (ctx', cld) \\<and> acyclic_clds P\n       \\<longrightarrow> The (path_length P ctx' (superclass_name_f cld)) < The (path_length P ctx (cl_fqn fqn))\"\napply(clarsimp)\napply(erule acyclic_clds.cases) apply(clarsimp) apply(rename_tac P)\napply(erule_tac x = ctx in allE)\napply(erule_tac x = fqn in allE)\napply(clarsimp)\napply(rule theI2) apply(simp) apply(simp add: path_length_eq)\napply(erule path_length.cases) apply(simp) apply(clarsimp)\napply(rule theI2) apply(simp) apply(simp add: path_length_eq)\napply(drule_tac path_length_eq, simp)\napply(erule path_length.cases) apply(simp) apply(clarsimp)\napply(drule_tac path_length_eq, simp) apply(simp)\ndone\n\nfunction\nfind_path_rec_f :: \"P \\<Rightarrow> ctx \\<Rightarrow> cl \\<Rightarrow> ctxclds \\<Rightarrow> ctxclds_opt\"\nwhere\n\"find_path_rec_f P ctx  cl_object   path = Some path\" |\n\"find_path_rec_f P ctx (cl_fqn fqn) path =\n  (if ~(acyclic_clds P) then None else\n  (case find_cld_f P ctx fqn of None \\<Rightarrow> None | Some (ctx', cld) \\<Rightarrow>\n   find_path_rec_f P ctx'\n                    (superclass_name_f cld) (path @ [(ctx',cld)])))\"\nby pat_completeness auto\ntermination\nby (relation \"measure (\\<lambda>(P, ctx, cl, path). (THE nn. path_length P ctx cl nn))\") auto\n\nlemma [simp]: \"(find_path_rec P ctx cl path path_opt) = (find_path_rec_f P ctx cl path = path_opt)\"\napply(rule)\n apply(erule find_path_rec.induct) apply(simp)+\napply(induct rule: find_path_rec_f.induct)\n apply(clarsimp simp add: fpr_objI)\napply(clarsimp) apply(rule)\n apply(simp add: fpr_nullI)\napply(clarsimp split: option.splits)\napply(rule fpr_nullI)\n apply(simp add: fpr_nullI)\napply(rule fpr_fqnI) apply(force)+\ndone\n\ndefinition\nfind_path_f :: \"P \\<Rightarrow> ctx \\<Rightarrow> cl \\<Rightarrow> ctxclds_opt\"\nwhere\n\"find_path_f P ctx cl = find_path_rec_f P ctx cl []\"\nlemma [simp]: \"(find_path P ctx cl path_opt) = (find_path_f P ctx cl = path_opt)\"\napply(rule)\n apply(erule find_path.cases) apply(unfold find_path_f_def) apply(simp)\napply(simp add: fp_defI)\ndone\n\nprimrec\nfind_path_ty_f :: \"P \\<Rightarrow> ty \\<Rightarrow> ctxclds_opt\"\nwhere\n\"find_path_ty_f P  ty_top          = Some []\" |\n\"find_path_ty_f P (ty_def ctx dcl) =\n   find_path_f P ctx (cl_fqn (fqn_def dcl))\"\nlemma [simp]: \"(find_path_ty P ty ctxclds_opt) = (find_path_ty_f P ty = ctxclds_opt)\"\napply(rule)\n apply(force elim: find_path_ty.cases)\napply(case_tac ty)\n apply(clarsimp simp add: fpty_objI)\napply(clarsimp simp add: fpty_dclI)\ndone\n\nprimrec\nfields_in_path_f :: \"ctxclds \\<Rightarrow> fs\"\nwhere\n\"fields_in_path_f []               = []\" |\n\"fields_in_path_f (ctxcld#ctxclds) =\n  (map (\\<lambda>fd. case fd of fd_def cl f \\<Rightarrow> f) (class_fields_f (snd ctxcld)))\n     @ fields_in_path_f ctxclds\"\nlemma cl_f_list_map: \"map (case_fd (\\<lambda>cl f. f)) (map (\\<lambda>(x, y). fd_def x y) cl_f_list) = map (\\<lambda>(cl_XXX, f_XXX). f_XXX) cl_f_list\"\nby (induct cl_f_list, auto)\n\nlemma fip_ind_to_f: \"\\<forall>fs. fields_in_path clds fs \\<longrightarrow> fields_in_path_f clds = fs\"\napply(induct clds)\n apply(clarsimp, erule fields_in_path.cases) apply(simp) apply(clarsimp)\napply(clarsimp)\napply(erule fields_in_path.cases) apply(simp) by(clarsimp simp add: cl_f_list_map)\n\nlemma fd_map_split: \"map (case_fd (\\<lambda>cl f. f)) (map (\\<lambda>(x, y). fd_def x y) list) = map (\\<lambda>(cl, f). f) list\"\napply(induct list) apply(simp) apply(clarsimp) done\n\nlemma fd_map_split': \"map (\\<lambda>(x, y). fd_def x y) (map (case_fd Pair) list) = list\"\napply(induct list) apply(simp split: fd.splits)+ done\n\nlemma fd_map_split'': \"map ((\\<lambda>(x, y). fd_def x y) \\<circ> case_fd Pair) list = list\"\napply(induct list)  apply(simp split: fd.splits)+ done\n\nlemma [simp]: \"\\<forall>fs. (fields_in_path ctxclds fs) = (fields_in_path_f ctxclds = fs)\"\napply(induct ctxclds)\n apply(rule) apply(rule)\n  apply(force elim: fields_in_path.cases)\n apply(simp add: fip_emptyI)\napply(clarsimp)\napply(rule)\n apply(erule fields_in_path.cases)\n  apply(simp)\n apply(simp add: fip_ind_to_f fd_map_split)\napply(clarsimp)\napply(rule_tac cld = b and ctxcld_list = ctxclds\n           and cl_f_list = \"map (case_fd (\\<lambda>cl f. (cl, f))) (class_fields_f b)\" in fip_consI[simplified])\n  apply(simp add: fd_map_split'')\n apply(simp add: fd_map_split')\napply(clarsimp split: fd.splits)\ndone\n\ndefinition\nfields_f :: \"P \\<Rightarrow> ty \\<Rightarrow> fs option\"\nwhere\n\"fields_f P ty =\n  (case find_path_ty_f P ty of None \\<Rightarrow> None | Some ctxclds \\<Rightarrow>\n    Some (fields_in_path_f ctxclds))\"\nlemma [simp]: \"\\<forall>fs_opt. (fields P ty fs_opt) = (fields_f P ty = fs_opt)\"\napply(rule) apply(rule)\n apply(case_tac fs_opt)\n  apply(clarsimp) apply(erule fields.cases)\n   apply(clarsimp) apply(simp add: fields_f_def)\n  apply(clarsimp)\n apply(erule fields.cases)\n  apply(simp)\n apply(clarsimp) apply(simp add: fields_f_def)\n apply(simp add: fields_f_def) apply(case_tac \"find_path_ty_f P ty\") apply(simp) apply(simp add: fields_noneI[simplified])\napply(clarsimp) apply(case_tac \"find_path_ty_f P ty\") apply(simp) apply(simp) apply(clarsimp)\napply(rule fields_someI) apply(simp) apply(simp)\ndone\n\nprimrec\nmethods_in_path_f :: \"clds \\<Rightarrow> meths\"\nwhere\n\"methods_in_path_f []         = []\" |\n\"methods_in_path_f (cld#clds) =\n  map (\\<lambda>md. case md of meth_def_def meth_sig meth_body \\<Rightarrow>\n         case meth_sig of meth_sig_def cl meth vds \\<Rightarrow> meth)\n              (class_methods_f cld) @ methods_in_path_f clds\"\n\nlemma meth_def_map[THEN mp]:\n  \"(\\<forall>x \\<in> set list. (\\<lambda>(md, cl, m, vds, mb). md = meth_def_def (meth_sig_def cl m vds) mb) x)\n     \\<longrightarrow> map (case_meth_def (\\<lambda>ms mb. case ms of meth_sig_def cl m vds \\<Rightarrow> m)) (map (\\<lambda>(md, cl, m, vds, mb). md) list) = map (\\<lambda>(md, cl, m, vds, mb). m) list\"\nby (induct list, auto)\n\nlemma meth_def_map':\n  \"map ((\\<lambda>(md, cl, m, vds, mb). md) \\<circ> (\\<lambda>md. case md of meth_def_def (meth_sig_def cl m vds) mb \\<Rightarrow> (md, cl, m, vds, mb))) list = list\"\napply(induct list) by (auto split: meth_def.splits meth_sig.splits)\n\nlemma [simp]: \"\\<forall>meths. (methods_in_path clds meths) = (methods_in_path_f clds = meths)\"\napply(induct clds)\n apply(clarsimp) apply(rule)\n  apply(erule methods_in_path.cases) apply(simp) apply(clarsimp)\n apply(clarsimp) apply(rule mip_emptyI)\napply(clarsimp) apply(rule)\n apply(erule methods_in_path.cases) apply(simp)\n apply(force)\n\napply(rule_tac\n  meth_def_cl_meth_vds_meth_body_list =\n   \"(case a of cld_def dcl cl fds mds \\<Rightarrow>\n    (map (\\<lambda>md. (case md of meth_def_def ms mb \\<Rightarrow>\n               (case ms of meth_sig_def cl m vds \\<Rightarrow> (md, cl, m, vds, mb)))) mds))\" in\n  mip_consI[simplified])\n   apply(clarsimp) apply(case_tac a) apply(simp add: class_methods_f_def meth_def_map')\n  apply(clarsimp) apply(clarsimp split: meth_def.splits meth_sig.splits)\n apply(simp)\napply(clarsimp) apply(case_tac a) apply(clarsimp simp add: class_methods_f_def split: meth_def.splits meth_sig.splits)\ndone\n\ndefinition\nmethods_f :: \"P \\<Rightarrow> ty \\<Rightarrow> meths option\"\nwhere\n\"methods_f P ty =\n  (case find_path_ty_f P ty of None \\<Rightarrow> None | Some ctxclds \\<Rightarrow>\n    Some (methods_in_path_f (map (\\<lambda>(ctx, cld). cld) ctxclds)))\"\nlemma [simp]: \"(methods P ty meths) = (methods_f P ty = Some meths)\"\napply(rule)\n apply(erule methods.cases) apply(clarsimp simp add: methods_f_def)\napply(simp add: methods_f_def) apply(split option.splits) apply(simp)\napply(clarsimp) apply(rule methods_methodsI) apply(simp) apply(clarsimp)\ndone\n\nprimrec\nftype_in_fds_f :: \"P \\<Rightarrow> ctx \\<Rightarrow> fds \\<Rightarrow> f \\<Rightarrow> ty_opt_bot\"\nwhere\n\"ftype_in_fds_f P ctx []       f = ty_opt_bot_opt None\" |\n\"ftype_in_fds_f P ctx (fd#fds) f =\n  (case fd of fd_def cl f' \\<Rightarrow> (if f = f' then\n  (case find_type_f P ctx cl of None \\<Rightarrow> ty_opt_bot_bot | Some ty \\<Rightarrow>\n     ty_opt_bot_opt (Some ty)) else ftype_in_fds_f P ctx fds f))\"\nlemma [simp]: \"(ftype_in_fds P ctx fds f ty_opt) = (ftype_in_fds_f P ctx fds f = ty_opt)\"\napply(rule)\n apply(induct fds) apply(erule ftype_in_fds.cases) apply(simp) apply(simp) apply(simp) apply(simp)\n apply(erule ftype_in_fds.cases) apply(simp) apply(simp) apply(simp) apply(clarsimp)\napply(induct fds)\n apply(clarsimp) apply(rule ftif_emptyI)\napply(rename_tac fd fds) apply(case_tac fd, rename_tac cl f', clarsimp) apply(rule)\n apply(clarsimp) apply(case_tac \"find_type_f P ctx cl\")\n  apply(simp add: ftif_cons_botI[simplified])\n apply(simp add: ftif_cons_trueI[simplified])\napply(force intro: ftif_cons_falseI[simplified])\ndone\n\nprimrec\nftype_in_path_f :: \"P \\<Rightarrow> ctxclds \\<Rightarrow> f \\<Rightarrow> ty_opt\"\nwhere\n\"ftype_in_path_f P []               f = None\" |\n\"ftype_in_path_f P (ctxcld#ctxclds) f =\n  (case ctxcld of (ctx, cld) \\<Rightarrow>\n  (case ftype_in_fds_f P ctx (class_fields_f cld) f of\n     ty_opt_bot_bot \\<Rightarrow> None | ty_opt_bot_opt ty_opt \\<Rightarrow>\n  (case ty_opt of Some ty \\<Rightarrow> Some ty | None \\<Rightarrow>\n     ftype_in_path_f P ctxclds f)))\"\nlemma [simp]: \"(ftype_in_path P ctxclds f ty_opt) = (ftype_in_path_f P ctxclds f = ty_opt)\"\napply(rule)\n apply(induct rule: ftype_in_path.induct) apply(simp+)\napply(induct ctxclds) apply(simp) apply(rule ftip_emptyI)\napply(hypsubst_thin)\napply(clarsimp) apply(case_tac \"ftype_in_fds_f P a (class_fields_f b) f\")\n apply(rename_tac ty_opt) apply(case_tac ty_opt)\n  apply(simp add: ftip_cons_falseI[simplified])\n apply(simp add: ftip_cons_trueI[simplified])\napply(simp add: ftip_cons_botI[simplified])\ndone\n\ndefinition\nftype_f :: \"P \\<Rightarrow> ty \\<Rightarrow> f \\<Rightarrow> ty_opt\"\nwhere\n\"ftype_f P ty f =\n  (case find_path_ty_f P ty of None \\<Rightarrow> None | Some ctxclds \\<Rightarrow>\n     ftype_in_path_f P ctxclds f)\"\nlemma [simp]: \"(ftype P ty f ty') = (ftype_f P ty f = Some ty')\"\napply(rule)\n apply(induct rule: ftype.induct) apply(clarsimp simp add: ftype_f_def)\napply(clarsimp simp add: ftype_f_def split: option.splits) apply(rule ftypeI) apply(simp+)\ndone\n\nprimrec\nfind_meth_def_in_list_f :: \"meth_defs \\<Rightarrow> meth \\<Rightarrow> meth_def_opt\"\nwhere\n\"find_meth_def_in_list_f []       m = None\" |\n\"find_meth_def_in_list_f (md#mds) m =\n  (case md of meth_def_def ms mb \\<Rightarrow>\n  (case ms of meth_sig_def cl m' vds \\<Rightarrow>\n  (if m = m' then Some md else find_meth_def_in_list_f mds m)))\"\nlemma [simp]: \"(find_meth_def_in_list mds m md_opt) = (find_meth_def_in_list_f mds m = md_opt)\"\napply(rule)\n apply(induct rule: find_meth_def_in_list.induct) apply(simp+)\napply(induct mds) apply(simp) apply(rule fmdil_emptyI)\napply(clarsimp) apply(clarsimp split: meth_def.split meth_sig.split) apply(rule)\n apply(clarsimp) apply(rule fmdil_cons_trueI[simplified]) apply(force)\napply(clarsimp) apply(rule fmdil_cons_falseI[simplified]) apply(force+)\ndone\n\nprimrec\nfind_meth_def_in_path_f :: \"ctxclds \\<Rightarrow> meth \\<Rightarrow> ctxmeth_def_opt\"\nwhere\nfmdip_empty: \"find_meth_def_in_path_f []               m = None\" |\nfmdip_cons:  \"find_meth_def_in_path_f (ctxcld#ctxclds) m =\n  (case ctxcld of (ctx, cld) \\<Rightarrow>\n  (case find_meth_def_in_list_f (class_methods_f cld) m of\n    Some md \\<Rightarrow> Some (ctx, md) |\n    None \\<Rightarrow> find_meth_def_in_path_f ctxclds m))\"\nlemma [simp]: \"(find_meth_def_in_path ctxclds m ctxmeth_def_opt) = (find_meth_def_in_path_f ctxclds m = ctxmeth_def_opt)\"\napply(rule)\n apply(induct rule: find_meth_def_in_path.induct) apply(simp+)\napply(induct ctxclds) apply(simp) apply(rule fmdip_emptyI)\napply(clarsimp) apply(case_tac \"find_meth_def_in_list_f (class_methods_f b) m\") apply(clarsimp)\napply(simp add: fmdip_cons_falseI[simplified])\napply(simp add: fmdip_cons_trueI[simplified])\ndone\n\ndefinition\nfind_meth_def_f :: \"P \\<Rightarrow> ty \\<Rightarrow> meth \\<Rightarrow> ctxmeth_def_opt\"\nwhere\n\"find_meth_def_f P ty m =\n  (case find_path_ty_f P ty of None \\<Rightarrow> None | Some ctxclds \\<Rightarrow>\n    find_meth_def_in_path_f ctxclds m)\"\nlemma [simp]: \"(find_meth_def P ty m ctxmd_opt) = (find_meth_def_f P ty m = ctxmd_opt)\"\napply(rule)\n apply(induct rule: find_meth_def.induct) apply(simp add: find_meth_def_f_def)+\napply(clarsimp simp add: find_meth_def_f_def split: option.splits)\napply(simp add: fmd_nullI)\napply(simp add: fmd_optI)\ndone\n\nprimrec\nlift_opts :: \"'a option list \\<Rightarrow> 'a list option\"\nwhere\n\"lift_opts []         = Some []\" |\n\"lift_opts (opt#opts) =\n  (case opt of None \\<Rightarrow> None | Some v \\<Rightarrow>\n  (case lift_opts opts of None \\<Rightarrow> None | Some vs \\<Rightarrow> Some (v#vs)))\"\n\ndefinition\nmtype_f :: \"P \\<Rightarrow> ty \\<Rightarrow> meth \\<Rightarrow> mty option\"\nwhere\n\"mtype_f P ty m =\n  (case find_meth_def_f P ty m of None \\<Rightarrow> None | Some (ctx, md) \\<Rightarrow>\n  (case md of meth_def_def ms mb \\<Rightarrow>\n  (case ms of meth_sig_def cl m' vds \\<Rightarrow>\n  (case find_type_f P ctx cl of None \\<Rightarrow> None | Some ty' \\<Rightarrow>\n  (case lift_opts (map (\\<lambda>vd. case vd of vd_def clk vark \\<Rightarrow>\n    find_type_f P ctx clk) vds) of None \\<Rightarrow> None | Some tys \\<Rightarrow>\n      Some (mty_def tys ty'))))))\"\n\nlemma lift_opts_ind[rule_format]:\n  \"(\\<forall>x\\<in>set list. (\\<lambda>(cl, var, ty). find_type_f P ctx cl = Some ty) x)\n       \\<longrightarrow> lift_opts (map (case_vd (\\<lambda>clk vark. find_type_f P ctx clk) \\<circ> (\\<lambda>(cl, var, ty). vd_def cl var)) list) = Some (map (\\<lambda>(cl, var, ty). ty) list)\"\nby (induct list, auto)\n\nlemma find_md_m_match'[rule_format]:\n  \"find_meth_def_in_list_f mds m = Some (meth_def_def (meth_sig_def cl m' vds) mb) \\<longrightarrow> m' = m\"\napply(induct mds) apply(simp) apply(clarsimp split: meth_def.splits meth_sig.splits) done\n\nlemma find_md_m_match:\n  \"find_meth_def_in_path_f path m = Some (ctx, meth_def_def (meth_sig_def cl m' vds) mb) \\<longrightarrow> m' = m\"\napply(induct path) apply(simp) apply(clarsimp split: option.splits) by(rule find_md_m_match')\n\nlemma vds_map_length:\n  \"length (map (case_vd (\\<lambda>clk vark. find_type_f P ctx clk)) vds) = length vds\"\nby (induct vds, auto)\n\nlemma lift_opts_length[rule_format]:\n  \"\\<forall>tys. lift_opts ty_opts = Some tys \\<longrightarrow> length ty_opts = length tys\"\napply(induct ty_opts) apply(simp) by(clarsimp split: option.splits)\n\nlemma vds_tys_length_eq[rule_format]:\n  \"lift_opts (map (case_vd (\\<lambda>clk vark. find_type_f P ctx clk)) vds) = Some tys \\<longrightarrow> length vds = length tys\"\napply(rule) apply(drule lift_opts_length) apply(simp add: vds_map_length) done\n\nlemma vds_tys_length_eq'[rule_format]:\n  \"\\<forall>tys. length vds = length tys \\<longrightarrow> vds = map (\\<lambda>(cl, var, ty). vd_def cl var) (map (\\<lambda>(vd, ty). case vd of vd_def cl var \\<Rightarrow> (cl, var, ty)) (zip vds tys))\"\napply(induct vds) apply(simp) apply(clarsimp) apply(case_tac a) apply(clarsimp)\napply(case_tac tys) apply(simp) apply(clarsimp) done\n\nlemma vds_tys_length_eq''[rule_format]:\n  \"\\<forall>vds. length vds = length tys \\<longrightarrow> tys = map ((\\<lambda>(cl, var, ty). ty) \\<circ> (\\<lambda>(vd, ty). case vd of vd_def cl var \\<Rightarrow> (cl, var, ty))) (zip vds tys)\"\napply(induct tys) apply(simp) apply(clarsimp) apply(case_tac vds) apply(clarsimp) apply(clarsimp)\napply(split vd.splits) apply(simp) done\n\nlemma lift_opts_find_type[rule_format]:\n  \"\\<forall>tys. lift_opts (map (case_vd (\\<lambda>clk vark. find_type_f P ctx clk)) vds) = Some tys\n      \\<longrightarrow> (\\<forall>(vd, ty) \\<in> set (zip vds tys). case vd of vd_def cl var \\<Rightarrow> find_type_f P ctx cl = Some ty)\"\napply(induct vds) apply(simp) apply(clarsimp split: vd.splits option.splits) apply(rename_tac cl' var)\napply(drule_tac x = \"(vd_def cl' var, b)\" in bspec, simp) apply(force) done\n\nlemma [simp]: \"(mtype P ty m mty) = (mtype_f P ty m = Some mty)\"\napply(rule)\n apply(induct rule: mtype.induct) apply(clarsimp simp add: mtype_f_def)\n apply(split option.splits) apply(rule) apply(clarsimp)\n apply(rule_tac x = \"map (\\<lambda>(cl, var, ty). ty) cl_var_ty_list\" in exI)\n apply(simp add: lift_opts_ind) apply(clarsimp) apply(simp add: lift_opts_ind)\napply(clarsimp simp add: mtype_f_def split: option.splits meth_def.splits meth_sig.splits)\napply(rename_tac ctx mb cl m' vds ty' tys)\napply(rule_tac ctx = ctx and cl = cl and meth_body = mb and ty' = ty'\n           and cl_var_ty_list = \"map (\\<lambda>(vd, ty). case vd of vd_def cl var \\<Rightarrow> (cl, var, ty)) (zip vds tys)\"\n           and meth_def = \"meth_def_def (meth_sig_def cl m' vds) mb\" in mtypeI[simplified])\n apply(simp) apply(clarsimp) apply(rule) apply(clarsimp simp add: find_meth_def_f_def split: option.splits)\n apply(simp add: find_md_m_match) apply(drule vds_tys_length_eq) apply(frule vds_tys_length_eq') apply(clarsimp)\n apply(simp) apply(clarsimp) apply(split vd.splits) apply(clarsimp) apply(drule lift_opts_find_type) apply(simp)\n apply(clarsimp)\napply(clarsimp) apply(drule vds_tys_length_eq) apply(simp add: vds_tys_length_eq'')\ndone\n\ndefinition\nis_sty_one :: \"P \\<Rightarrow> ty \\<Rightarrow> ty \\<Rightarrow> bool option\"\nwhere\n\"is_sty_one P ty ty' =\n  (case find_path_ty_f P ty of None \\<Rightarrow> None | Some ctxclds \\<Rightarrow>\n  (case ty' of ty_top \\<Rightarrow> Some True | ty_def ctx' dcl' \\<Rightarrow>\n    Some ((ctx', dcl') : set (map (\\<lambda>(ctx, cld). (ctx, class_name_f cld)) ctxclds)) ))\"\n\nlemma class_name_mem_map[rule_format]:\n\"(ctx, cld, class_name_f cld) \\<in> set ctx_cld_dcl_list\n       \\<Longrightarrow> (ctx, class_name_f cld)\n          \\<in> ((\\<lambda>(ctx, cld). (ctx, class_name_f cld)) \\<circ> (\\<lambda>(ctx, cld, dcl). (ctx, cld))) `\n            set ctx_cld_dcl_list\"\nby (induct ctx_cld_dcl_list, auto)\n\nlemma map_map_three:\n  \" ctxclds = map ((\\<lambda>(ctx, cld, dcl). (ctx, cld)) \\<circ> (\\<lambda>(ctx, cld). (ctx, cld, class_name_f cld))) ctxclds\"\nby (induct ctxclds, auto)\n\nlemma mem_el_map[rule_format]:\n  \"(ctx, dcl) \\<in> set ctxclds\n       \\<Longrightarrow> (ctx, class_name_f dcl)\n          \\<in> (\\<lambda>(ctx_XXX, cld_XXX, y). (ctx_XXX, y)) `\n            set (map (\\<lambda>(ctx, cld). (ctx, cld, class_name_f cld)) ctxclds)\"\nby (induct ctxclds, auto)\n\nlemma [simp]: \"(sty_one P ty ty') = (is_sty_one P ty ty' = Some True)\"\napply(rule)\n apply(induct rule: sty_one.induct)\n  apply(simp add: is_sty_one_def)\n apply(clarsimp simp add: is_sty_one_def) apply(rename_tac ctx cld dcl)\n   apply(drule_tac x = \"(ctx, cld, dcl)\" in bspec, simp) apply(clarsimp)\n  using case_prod_conv image_iff apply fastforce\napply(clarsimp simp add: is_sty_one_def split: option.splits ty.splits)\n apply(simp add: sty_objI)\napply(rename_tac ctxclds ctx dcl)\napply(rule_tac ctx_cld_dcl_list = \"map (\\<lambda>(ctx, cld). (ctx, cld, class_name_f cld)) ctxclds\" in sty_dclI[simplified])\n  apply(clarsimp) apply(rule map_map_three)\n apply(force)\napply(rule mem_el_map, assumption)\ndone\n\nlemma path_append[rule_format]:\n  \"find_path_rec_f P ctx cl path' = Some path \\<Longrightarrow> \\<exists>path''. path = path' @ path''\"\napply(induct rule: find_path_rec_f.induct)\n apply(clarsimp)\napply(force split: if_split_asm option.splits)\ndone\n\nlemma all_in_path_found'[rule_format]:\n  \"find_path_rec_f P ctx cl path' = Some path \\<longrightarrow>\n      (\\<forall>ctxcld \\<in> set path. ctxcld \\<in> set path' \\<or> (\\<exists>ctx' fqn'. find_cld_f P ctx' fqn' = Some ctxcld))\"\napply(induct rule: find_path_rec_f.induct)\n apply(clarsimp)\napply(rule)\napply(force split: if_split_asm option.splits)\ndone\n\nlemma all_in_path_found:\n  \"\\<lbrakk>find_path_f P ctx cl = Some path; ctxcld \\<in> set path\\<rbrakk> \\<Longrightarrow> \\<exists>ctx' fqn'. find_cld_f P ctx' fqn' = Some ctxcld\"\nby (unfold find_path_f_def, simp only: all_in_path_found'[of _ _ _ \"[]\", simplified])\n\nlemma fpr_target_is_head':\n  \"find_path_rec_f P ctx cl path' = Some path \\<longrightarrow>\n     (\\<forall>fqn ctxcld. cl = cl_fqn fqn \\<and> find_cld_f P ctx fqn = Some ctxcld \\<longrightarrow>\n          (\\<exists>path''. path = path' @ ctxcld # path''))\"\napply(induct_tac P ctx cl path' rule: find_path_rec_f.induct)\n apply(simp)\napply(clarsimp split: if_split_asm option.splits)\napply(case_tac \"superclass_name_f b\") apply(clarsimp)\napply(clarsimp split: if_split_asm option.splits)\napply(force)\ndone\n\nlemma fpr_target_is_head:\n  \"find_path_f P ctx (cl_fqn fqn) = Some path \\<Longrightarrow> \\<exists>ctxcld. find_cld_f P ctx fqn = Some ctxcld \\<and> (\\<exists>path''. path = ctxcld # path'')\"\napply(unfold find_path_f_def) apply(frule fpr_target_is_head'[of _ _ _ \"[]\", THEN mp]) apply(clarsimp split: option.splits) done\n\nlemma fpr_sub_path':\n  \"find_path_rec_f P ctx cl path' = Some path \\<longrightarrow>\n     (\\<forall>fqn ctxcld path'' path_fqn.\n         cl = cl_fqn fqn \\<and> find_cld_f P ctx fqn = Some ctxcld \\<and>\n         find_path_rec_f P (fst ctxcld) (superclass_name_f (snd ctxcld)) path'' = Some path_fqn \\<longrightarrow>\n              (\\<exists>path'''. path_fqn = path'' @ path''' \\<and> path = path' @ ctxcld # path'''))\"\napply(induct_tac P ctx cl path' rule: find_path_rec_f.induct)\n apply(simp)\napply(clarsimp split: if_split_asm option.splits)\napply(case_tac \"superclass_name_f b\") apply(simp add: find_path_f_def)\napply(clarsimp split: if_split_asm option.splits)\napply(frule_tac path = path in path_append) apply(clarsimp) apply(force)\ndone\n\nlemma fpr_sub_path:\n  \"\\<lbrakk>find_path_f P ctx (cl_fqn fqn) = Some path; find_cld_f P ctx fqn = Some ctxcld;\n    find_path_f P (fst ctxcld) (superclass_name_f (snd ctxcld)) = Some path'\\<rbrakk>\n       \\<Longrightarrow> path = ctxcld # path'\"\nby (unfold find_path_f_def, force intro: fpr_sub_path'[rule_format, of _ _ _ \"[]\" _ _ _ \"[]\", simplified])\n\nlemma fpr_sub_path_simp:\n  \"\\<lbrakk>find_path_rec_f P ctx (superclass_name_f cld) path'' = Some path_fqn; find_cld_f P ctx fqn = Some (ctx, cld); acyclic_clds P;\n    find_path_rec_f P ctx (superclass_name_f cld) (path' @ [(ctx, cld)]) = Some path\\<rbrakk>\n       \\<Longrightarrow> \\<exists>path'''. path_fqn = path'' @ path''' \\<and> path = path' @ (ctx, cld) # path'''\"\napply(cut_tac P = P and ctx = ctx and cl = \"cl_fqn fqn\" and path' = path' and path = path in fpr_sub_path')\napply(clarsimp split: option.splits if_split_asm)\ndone\n\nlemma fpr_same_suffix'[rule_format]:\n  \"find_path_rec_f P ctx cl prefix = Some path \\<longrightarrow>\n     (\\<forall>suffix prefix'. path = prefix @ suffix \\<longrightarrow>\n          find_path_rec_f P ctx cl prefix' = Some (prefix' @ suffix))\"\napply(induct_tac P ctx cl prefix rule: find_path_rec_f.induct)\n apply(clarsimp)\napply(clarsimp split: option.splits)\napply(frule path_append) apply(force)\ndone\n\nlemma fpr_same_suffix:\n  \"find_path_rec_f P ctx cl prefix = Some path \\<longrightarrow>\n     (\\<forall>suffix prefix' suffix'. path = prefix @ suffix \\<and>\n          find_path_rec_f P ctx cl prefix' = Some (prefix' @ suffix')\n             \\<longrightarrow> suffix = suffix')\"\napply(induct_tac P ctx cl prefix rule: find_path_rec_f.induct)\n apply(clarsimp)\nby (metis fpr_same_suffix' option.inject same_append_eq)\n\nlemma fpr_mid_path'[rule_format]:\n  \"find_path_rec_f P ctx cl path' = Some path \\<longrightarrow>\n     (\\<forall>ctxcld \\<in> set path.\n         ctxcld \\<in> set path' \\<or>\n         (\\<forall>path_fqn. find_path_rec_f P (fst ctxcld) (cl_fqn (fqn_def (class_name_f (snd ctxcld)))) path'' = Some path_fqn \\<longrightarrow>\n              (\\<forall>path'''. path_fqn = path'' @ path''' \\<longrightarrow> (\\<exists>path_rest. path = path_rest @ path'''))))\"\napply(induct_tac P ctx cl path' rule: find_path_rec_f.induct)\n apply(simp)\napply(clarsimp split: option.splits)\napply(frule find_cld_name_eq) apply(clarsimp)\napply(rename_tac path' ctx' cld' cld'' ctx'' path''' cl fds mds)\napply(subgoal_tac \"find_path_rec_f P ctx' (superclass_name_f cld') (path' @ [(ctx', cld')]) = Some path \\<longrightarrow>\n              (\\<forall>ctxcld\\<in>set path.\n                  ctxcld = (ctx', cld') \\<or>\n                  ctxcld \\<in> set path' \\<or>\n                  (\\<forall>path_fqn. case_option None (case_prod (\\<lambda>ctx' cld. find_path_rec_f P ctx' (superclass_name_f cld) (path'' @ [(ctx', cld)])))\n                               (find_cld_f P (fst ctxcld) (fqn_def (class_name_f (snd ctxcld)))) =\n                              Some path_fqn \\<longrightarrow>\n                              (\\<forall>path'''. path_fqn = path'' @ path''' \\<longrightarrow> (\\<exists>path_rest. path = path_rest @ path'''))))\")\n apply(erule impE) apply simp\n apply(drule_tac x = \"(ctx'', cld'')\" in bspec, simp) apply(clarsimp)\n apply(simp add: superclass_name_f_def)\n apply(case_tac cld') apply(rename_tac dcl' cl' fds' mds') apply(clarsimp simp add: class_name_f_def)\n apply(case_tac fqn) apply(rename_tac dcl'') apply(clarsimp)\n apply(frule find_cld_name_eq) apply(clarsimp)\n apply(frule path_append) apply(frule_tac path = \"path'' @ path'''\" in path_append) apply(clarsimp)\n apply(rule_tac x = path' in exI) apply(clarsimp)\n apply(frule_tac suffix = path''a and prefix' = \"path'' @ [(ctx', cld_def dcl' cl' fds' mds')]\" and\n                suffix' = path''aa in fpr_same_suffix[rule_format]) apply(simp)\n apply(force)\napply(simp)\ndone\n\nlemma fpr_mid_path:\n  \"\\<lbrakk>find_path_f P ctx cl = Some path; (ctx', cld') \\<in> set path;\n    find_path_f P ctx' (cl_fqn (fqn_def (class_name_f cld'))) = Some path'\\<rbrakk>\n       \\<Longrightarrow> \\<exists>path''. path = path'' @ path'\"\napply(cut_tac  P = P and ctx = ctx and cl = cl and path' = \"[]\" and path = path and ctxcld = \"(ctx', cld')\" and path'' = \"[]\" in fpr_mid_path')\napply(unfold find_path_f_def, assumption) apply(assumption) apply(simp)\ndone\n\nlemma fpr_first_in_path'[rule_format]:\n  \"find_path_rec_f P ctx cl path' = Some path \\<longrightarrow>\n      (\\<forall>fqn ctxcld. cl = cl_fqn fqn \\<and> find_cld_f P ctx fqn = Some ctxcld \\<longrightarrow> ctxcld \\<in> set path)\"\napply(case_tac cl)\n apply(simp)\napply(clarsimp) apply(drule path_append) apply(force)\ndone\n\nlemma fpr_first_in_path:\n  \"\\<lbrakk>find_path_f P ctx (cl_fqn fqn) = Some path; find_cld_f P ctx fqn = Some ctxcld\\<rbrakk> \\<Longrightarrow> ctxcld \\<in> set path\"\nby (unfold find_path_f_def, force intro: fpr_first_in_path'[of _ _ _ \"[]\", simplified])\n\nlemma cld_for_path:\n  \"find_path_f P ctx (cl_fqn fqn) = Some path \\<Longrightarrow> \\<exists>ctxcld. find_cld_f P ctx fqn = Some ctxcld\"\napply(unfold find_path_f_def) apply(clarsimp split: if_split_asm option.splits) done\n\nlemma ctx_cld_ctx_dcl[rule_format]:\n  \"(ctx, cld_def dcl cl fds mds) \\<in> set path \\<longrightarrow> (ctx, dcl) \\<in> (\\<lambda>(ctx, cld). (ctx, class_name_f cld)) ` set path\"\nby (induct path, auto simp add: class_name_f_def)\n\nlemma ctx_dcl_ctx_cld[rule_format]:\n  \"(ctx, dcl) \\<in> (\\<lambda>(ctx, cld). (ctx, class_name_f cld)) ` set path \\<longrightarrow> (\\<exists>cl fds mds. (ctx, cld_def dcl cl fds mds) \\<in> set path)\"\napply(induct path) apply(simp)\napply(auto) apply(case_tac b) apply(force simp add: class_name_f_def)\ndone\n\nlemma ctx_dcl_mem_path:\n  \"find_path_f P ctx (cl_fqn (fqn_def dcl)) = Some path \\<Longrightarrow> (ctx, dcl) \\<in> (\\<lambda>(ctx, cld). (ctx, class_name_f cld)) ` set path\"\napply(frule cld_for_path) apply(erule exE)\napply(frule fpr_first_in_path) apply(assumption)\napply(frule find_cld_name_eq) apply(elim exE)\napply(clarsimp simp add: ctx_cld_ctx_dcl)\ndone\n\nlemma sty_reflexiveI:\n  \"is_sty_one P ty ty' = Some True \\<Longrightarrow> is_sty_one P ty ty = Some True\"\napply(simp add: is_sty_one_def split: option.splits) apply(case_tac ty) apply(simp) apply(clarsimp)\napply(drule ctx_dcl_mem_path) apply(force)\ndone\n\nlemma sty_transitiveI:\n  \"\\<lbrakk>is_sty_one P ty ty' = Some True; is_sty_one P ty' ty'' = Some True\\<rbrakk>\n       \\<Longrightarrow> is_sty_one P ty ty'' = Some True\"\napply(clarsimp simp add: is_sty_one_def split: ty.splits option.splits)\napply(rename_tac path ctx dcl path' ctx' dcl')\napply(case_tac ty) apply(simp) apply(clarsimp) apply(rename_tac ctx dcl ctx' cld' ctx'' cld'')\napply(frule fpr_mid_path) apply(simp) apply(simp) apply(force)\ndone\n\ndefinition\nis_sty_many :: \"P \\<Rightarrow> tys \\<Rightarrow> tys \\<Rightarrow> bool option\"\nwhere\n\"is_sty_many P tys tys' =\n  (if length tys \\<noteq> length tys' then None else\n  (case lift_opts (map (\\<lambda>(ty, ty'). is_sty_one P ty ty') (zip tys tys'))\n     of None \\<Rightarrow> None | Some bools \\<Rightarrow> Some (list_all id bools)))\"\n\nlemma lift_opts_exists:\n  \"\\<forall>x\\<in>set ty_ty'_list. (\\<lambda>(ty, ty'). is_sty_one P ty ty' = Some True) x \\<Longrightarrow> \\<exists>bools. lift_opts (map (\\<lambda>(ty, ty'). is_sty_one P ty ty') ty_ty'_list) = Some bools\"\nby (induct ty_ty'_list, auto)\n\nlemma lift_opts_all_true[rule_format]:\n  \"\\<forall>bools. (\\<forall>x\\<in>set ty_ty'_list. (\\<lambda>(ty, ty'). is_sty_one P ty ty' = Some True) x) \\<and>\n            lift_opts (map (\\<lambda>(ty, ty'). is_sty_one P ty ty') ty_ty'_list) = Some bools\n                  \\<longrightarrow> list_all id bools\"\nby (induct ty_ty'_list, auto split: option.splits)\n\nlemma tys_tys'_list: \"\\<And>bools ty ty'. \\<lbrakk>lift_opts (map (\\<lambda>(x, y). is_sty_one P x y) tys_tys'_list) = Some bools; length tys = length tys'; list_all id bools; (ty, ty') \\<in> set tys_tys'_list\\<rbrakk> \\<Longrightarrow> is_sty_one P ty ty' = Some True\"\napply(induct tys_tys'_list)\n apply(simp)\napply(clarsimp split: option.splits)\nby force\n\nlemma [simp]: \"(sty_many P tys tys') = (is_sty_many P tys tys' = Some True)\"\napply(rule)\n apply(erule sty_many.cases) apply(clarsimp simp add: is_sty_many_def split: option.splits) apply(rule)\n  apply(simp add: lift_opts_exists)\n apply(force intro: lift_opts_all_true)\napply(clarsimp simp add: is_sty_many_def split: option.splits if_split_asm)\napply(rule_tac ty_ty'_list = \"zip tys tys'\" in sty_manyI)\n  apply(simp add: map_fst_zip[THEN sym])\n apply(simp add: map_snd_zip[THEN sym])\napply(clarsimp)\napply(simp add: tys_tys'_list)\ndone\n\n(* TODO: here will go all the other definitions for functions equivalent to\n   relations concerning well-formedness *)\n\ndefinition\ntr_x :: \"T \\<Rightarrow> x \\<Rightarrow> x\"\nwhere\n\"tr_x T x = (case T x of None \\<Rightarrow> x | Some x' \\<Rightarrow> x')\"\n\ndefinition\ntr_var :: \"T \\<Rightarrow> var \\<Rightarrow> var\"\nwhere\n\"tr_var T var = (case tr_x T (x_var var) of x_this \\<Rightarrow> var | x_var var' \\<Rightarrow> var')\"\n\nprimrec\ntr_s_f  :: \"T \\<Rightarrow> s \\<Rightarrow> s\" and\ntr_ss_f :: \"T \\<Rightarrow> s list \\<Rightarrow> s list\"\nwhere\n\"tr_s_f T (s_block ss)        = s_block (tr_ss_f T ss)\" |\n\"tr_s_f T (s_ass var x)       = s_ass (tr_var T var) (tr_x T x)\" |\n\"tr_s_f T (s_read var x f)    = s_read (tr_var T var) (tr_x T x) f\" |\n\"tr_s_f T (s_write x f y)     = s_write (tr_x T x) f (tr_x T y)\" |\n\"tr_s_f T (s_if x y s1 s2)    = s_if (tr_x T x) (tr_x T y) (tr_s_f T s1) (tr_s_f T s2)\" |\n\"tr_s_f T (s_call var x m ys) = s_call (tr_var T var) (tr_x T x) m (map (tr_x T) ys)\" |\n\"tr_s_f T (s_new var ctx cl)  = s_new (tr_var T var) ctx cl\" |\n\n\"tr_ss_f T [] = []\" |\n\"tr_ss_f T (s#ss) = tr_s_f T s # tr_ss_f T ss\"\n\nlemma [simp]: \"(\\<forall>x\\<in>set s_s'_list. case x of (s_XXX, s_') \\<Rightarrow> tr_s T s_XXX s_' \\<and> tr_s_f T s_XXX = s_') \\<longrightarrow>\n       tr_ss_f T (map fst s_s'_list) = map snd s_s'_list\"\nby (induct s_s'_list, auto)\n\nlemma [simp]: \"(\\<forall>x\\<in>set y_y'_list. case_prod (\\<lambda>y_XXX. (=) (case T y_XXX of None \\<Rightarrow> y_XXX | Some x' \\<Rightarrow> x')) x) \\<longrightarrow> map (tr_x T) (map fst y_y'_list) = map snd y_y'_list\"\napply(induct y_y'_list) apply(simp) apply(clarsimp) apply(simp only: tr_x_def) done\n\nlemma set_zip_tr[simp]: \"(s, s') \\<in> set (zip ss (tr_ss_f T ss)) \\<longrightarrow> s' = tr_s_f T s\" by (induct ss, auto)\n\n\n\nlemma tr_ss_map:\n  \"tr_ss_f T (map fst s_s'_list) = map snd s_s'_list \\<and> (\\<forall>x\\<in>set s_s'_list. case_prod (tr_s T) x) \\<and>\n   (a, b) \\<in> set s_s'_list \\<longrightarrow> tr_s T a (tr_s_f T a)\"\napply(induct s_s'_list) by auto\n\nlemma tr_f_to_rel: \"\\<forall>s'. tr_s_f T s = s' \\<longrightarrow> tr_s T s s'\"\napply(induct s rule: tr_s_f.induct)\napply(simp)\napply(clarsimp) apply(rule tr_s_var_assignI)\napply(clarsimp simp add: tr_x_def tr_var_def split: option.splits)\napply(simp add: tr_x_def)\napply(clarsimp) apply(rule tr_s_field_readI)\napply(clarsimp simp add: tr_x_def tr_var_def split: option.splits)\napply(simp add: tr_x_def)\napply(clarsimp) apply(rule tr_s_field_writeI)\napply(simp add: tr_x_def) apply(simp add: tr_x_def)\napply(clarsimp simp only: tr_s_f.simps) apply(rule tr_s_ifI)\napply(simp only: tr_x_def) apply(simp only: tr_x_def) apply(simp) apply(simp)\napply(clarsimp) apply(rule tr_s_newI)\napply(clarsimp simp add: tr_x_def tr_var_def split: option.splits)\napply(clarsimp)\napply(rename_tac var x m ys)\napply(cut_tac T = T and var = var and var' = \"tr_var T var\" and x = x and\n              x' = \"tr_x T x\" and y_y'_list = \"zip ys (map (tr_x T) ys)\" and\n              meth = m in tr_s_mcallI)\napply(clarsimp simp add: tr_x_def tr_var_def split: option.splits)\napply(simp only: tr_x_def) apply(clarsimp simp add: set_zip tr_x_def) apply(simp)\napply(simp)\napply(cut_tac T = T and s_s'_list = \"[]\" in tr_s_blockI[simplified])\n apply(simp)\napply(clarsimp)\napply(clarsimp) apply(rename_tac s ss)\napply(cut_tac T = T and s_s'_list = \"zip (s # ss) (tr_s_f T s # tr_ss_f T ss)\" in tr_s_blockI[simplified])\n apply(clarsimp) apply(rename_tac x x')\n apply(frule set_zip_tr[THEN mp]) apply(clarsimp)\n apply(erule in_set_zipE)\n apply(erule_tac ?a1.0=\"T\" and ?a2.0=\"s_block ss\" and ?a3.0=\"s_block (tr_ss_f T ss)\" in tr_s.cases)\n apply(clarsimp)\n apply(rule tr_ss_map[THEN mp], force)\n apply(clarsimp)+\ndone\n\nlemma tr_rel_f_eq: \"((tr_s T s s') = (tr_s_f T s = s'))\"\napply(rule)\n apply(erule tr_s.induct)\n apply(force simp add: tr_x_def tr_var_def split: option.splits)+\napply(cut_tac T = T and s = s in tr_f_to_rel) apply(simp)\ndone\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/LightweightJava/Lightweight_Java_Equivalence.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6224593312018546, "lm_q2_score": 0.45713671682749474, "lm_q1q2_score": 0.28454901502425395}}
{"text": "section {*I\\_kparser\\_HF*}\ntheory\n  I_kparser_HF\n\nimports\n  I_kparser_base\n\nbegin\n\nrecord ('stack, 'event) parserHF_conf =\n  parserHF_conf_fixed :: \"'event list\"\n  parserHF_conf_history :: \"'event list\"\n  parserHF_conf_stack :: \"'stack list\"\n\ndefinition parserHF_configurations :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserHF_conf set\"\n  where\n    \"parserHF_configurations G \\<equiv>\n  {\\<lparr>parserHF_conf_fixed = f,\n    parserHF_conf_history=h,\n    parserHF_conf_stack = l\\<rparr>\n    | f h l.\n    set l \\<subseteq> parser_nonterms G\n    \\<and> set f \\<subseteq> parser_events G\n    \\<and> set h \\<subseteq> parser_events G\n    \\<and> parser_bottom G \\<notin> set h\n    \\<and> suffix h (butlast_if_match f (parser_bottom G))\n    \\<and> (parser_bottom G \\<notin> set f\n        \\<or> (\\<exists>w. f = w @ [parser_bottom G]\n                \\<and> parser_bottom G \\<notin> set w))}\"\n\ndefinition parserHF_configurations_ALT :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserHF_conf set\"\n  where\n    \"parserHF_configurations_ALT G \\<equiv>\n  {\\<lparr>parserHF_conf_fixed = f,\n    parserHF_conf_history=h,\n    parserHF_conf_stack = l\\<rparr>\n    | f h l.\n    set l \\<subseteq> parser_nonterms G\n    \\<and> set h \\<subseteq> parser_events G - {parser_bottom G}\n    \\<and> suffix h (butlast_if_match f (parser_bottom G))\n    \\<and> f \\<in> parser_fixed_schedulers G}\"\n\nlemma parserHF_configurations_ALT_vs_parserHF_configurations: \"\n  valid_parser G\n  \\<Longrightarrow> parserHF_configurations_ALT G = parserHF_configurations G\"\n  apply(simp add: parserHF_configurations_ALT_def parserHF_configurations_def)\n  apply(rule antisym)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac f h l)(*strict*)\n   apply(case_tac \"parser_bottom G \\<in> set f\")\n    apply(rename_tac f h l)(*strict*)\n    apply(simp add: parser_schedulers_def)\n    apply(clarsimp)\n    apply(rename_tac h l w)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac h l w)(*strict*)\n     apply(force)\n    apply(rename_tac h l w)(*strict*)\n    apply(simp add: parser_fixed_schedulers_def prefix_closure_def)\n    apply(rule_tac x=\"w @ [parser_bottom G]\" in exI)\n    apply(rule conjI)\n     apply(rename_tac h l w)(*strict*)\n     prefer 2\n     apply(simp add: prefix_def)\n    apply(rename_tac h l w)(*strict*)\n    apply(simp add: parser_schedulers_def)\n   apply(rename_tac f h l)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac f h l)(*strict*)\n    apply(force)\n   apply(rename_tac f h l)(*strict*)\n   apply(simp add: parser_fixed_schedulers_def)\n   apply(simp add: prefix_closure_def parser_schedulers_def)\n   apply(rule_tac\n      x=\"f@ [parser_bottom G]\"\n      in exI)\n   apply(simp add: prefix_def)\n  apply(clarsimp)\n  apply(rename_tac f h l)(*strict*)\n  apply(simp add: parser_fixed_schedulers_def)\n  apply(simp add: prefix_closure_def parser_schedulers_def)\n  apply(clarsimp)\n  apply(rename_tac f h l va)(*strict*)\n  apply(simp add: prefix_def)\n  apply(clarsimp)\n  apply(rename_tac f h l va c)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac f h l va c)(*strict*)\n   apply(simp add: valid_parser_def)\n   apply(clarsimp)\n   apply(rename_tac f h l va c x)(*strict*)\n   apply(subgoal_tac \"x\\<in> set(va @ [parser_bottom G])\")\n    apply(rename_tac f h l va c x)(*strict*)\n    prefer 2\n    apply(rule_tac\n      A=\"set f\"\n      in set_mp)\n     apply(rename_tac f h l va c x)(*strict*)\n     apply(rule_tac\n      t=\"va @ [parser_bottom G]\"\n      and s=\"f @ c\"\n      in ssubst)\n      apply(rename_tac f h l va c x)(*strict*)\n      apply(force)\n     apply(rename_tac f h l va c x)(*strict*)\n     apply(simp (no_asm))\n    apply(rename_tac f h l va c x)(*strict*)\n    apply(force)\n   apply(rename_tac f h l va c x)(*strict*)\n   apply(force)\n  apply(rename_tac f h l va c)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac f h l va c)(*strict*)\n   apply(force)\n  apply(rename_tac f h l va c)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac f h l va c)(*strict*)\n   apply(force)\n  apply(rename_tac f h l va c)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n      xs=\"c\"\n      in rev_cases)\n   apply(rename_tac f h l va c)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac f h l va c ys y)(*strict*)\n  apply(clarsimp)\n  done\n\ndefinition parserHF_step_relation :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\n  \\<Rightarrow> ('stack, 'event) parser_step_label\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\n  \\<Rightarrow> bool\"\n  where\n    \"parserHF_step_relation G c1 p c2 \\<equiv>\n  p \\<in> parser_rules G \\<and> ((\\<exists>x. parserHF_conf_stack c1=x@(rule_lpop p) \\<and> parserHF_conf_stack c2=x@(rule_lpush p)) \\<and> (parserHF_conf_history c2=parserHF_conf_history c1@(drop (length(parserHF_conf_fixed c1)) (butlast_if_match (rule_rpop p) (parser_bottom G))) \\<and> parserHF_conf_fixed c2 = (rule_rpush p) @ (drop (length (rule_rpop p)) (parserHF_conf_fixed c1)) \\<and> (prefix (rule_rpop p) (parserHF_conf_fixed c1) \\<or> prefix (parserHF_conf_fixed c1) (rule_rpop p))))\"\n\ndefinition parserHF_step_relation_ALT :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\n  \\<Rightarrow> ('stack, 'event) parser_step_label\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\n  \\<Rightarrow> bool\"\n  where\n    \"parserHF_step_relation_ALT G c1 e c2 \\<equiv>\n  e \\<in> parser_rules G\n  \\<and> (\\<exists>x. parserHF_conf_stack c1 = x @ rule_lpop e\n          \\<and> parserHF_conf_stack c2 = x @ rule_lpush e)\n  \\<and> parserHF_conf_history c2\n      = parserHF_conf_history c1\n        @ drop\n            (length(parserHF_conf_fixed c1))\n            (butlast_if_match (rule_rpop e) (parser_bottom G))\n  \\<and> parserHF_conf_fixed c2\n      = rule_rpush e\n        @ drop\n            (length (rule_rpop e))\n            (parserHF_conf_fixed c1)\n  \\<and> (prefix (rule_rpop e) (parserHF_conf_fixed c1)\n    \\<or> prefix (parserHF_conf_fixed c1) (rule_rpop e))\"\n\nlemma parserHF_step_relation_ALT_vs_parserHF_step_relation: \"\n  parserHF_step_relation_ALT M c1 p c2 = parserHF_step_relation M c1 p c2\"\n  apply(simp add: parserHF_step_relation_ALT_def parserHF_step_relation_def)\n  done\n\n(*1a 1b 1c not fixed before AND not fixed afterwards*)\ndefinition parserHF_step_relation_ALT2_1a :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\n  \\<Rightarrow> ('stack, 'event) parser_step_label\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\n  \\<Rightarrow> bool\"\n  where\n    \"parserHF_step_relation_ALT2_1a G c1 e c2 \\<equiv>\n    (\\<exists>v1 v2 v3 h s s1 q1 s2 q2.\n        c1 = \\<lparr>parserHF_conf_fixed = v1, parserHF_conf_history = h, parserHF_conf_stack = s @ s1 @ [q1]\\<rparr>\n      \\<and> e = \\<lparr>rule_lpop = s1 @ [q1], rule_rpop = v1 @ v2 @ v3, rule_lpush = s2 @ [q2], rule_rpush = v3\\<rparr>\n      \\<and> c2 = \\<lparr>parserHF_conf_fixed = v3, parserHF_conf_history = h @ v2 @ v3, parserHF_conf_stack = s @ s2 @ [q2]\\<rparr>\n      \\<and> parser_bottom G \\<notin> set (v1 @ v2 @ v3))\"\n\ndefinition parserHF_step_relation_ALT2_1b :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\n  \\<Rightarrow> ('stack, 'event) parser_step_label\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\n  \\<Rightarrow> bool\"\n  where\n    \"parserHF_step_relation_ALT2_1b G c1 e c2 \\<equiv>\n    (\\<exists>v1 v2 v3 h s s1 q1 s2 q2.\n        c1 = \\<lparr>parserHF_conf_fixed = v1 @ v2, parserHF_conf_history = h, parserHF_conf_stack = s @ s1 @ [q1]\\<rparr>\n      \\<and> e = \\<lparr>rule_lpop = s1 @ [q1], rule_rpop = v1 @ v2 @ v3, rule_lpush = s2 @ [q2], rule_rpush = v2 @ v3\\<rparr>\n      \\<and> c2 = \\<lparr>parserHF_conf_fixed = v2 @ v3, parserHF_conf_history = h @ v3, parserHF_conf_stack = s @ s2 @ [q2]\\<rparr>\n      \\<and> parser_bottom G \\<notin> set (v1 @ v2 @ v3))\"\n\ndefinition parserHF_step_relation_ALT2_1c :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\n  \\<Rightarrow> ('stack, 'event) parser_step_label\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\n  \\<Rightarrow> bool\"\n  where\n    \"parserHF_step_relation_ALT2_1c G c1 e c2 \\<equiv>\n    (\\<exists>v1 v2 v3 h s s1 q1 s2 q2.\n        c1 = \\<lparr>parserHF_conf_fixed = v1 @ v2 @ v3, parserHF_conf_history = h, parserHF_conf_stack = s @ s1 @ [q1]\\<rparr>\n      \\<and> e = \\<lparr>rule_lpop = s1 @ [q1], rule_rpop = v1 @ v2, rule_lpush = s2 @ [q2], rule_rpush = v2\\<rparr>\n      \\<and> c2 = \\<lparr>parserHF_conf_fixed = v2 @ v3, parserHF_conf_history = h, parserHF_conf_stack = s @ s2 @ [q2]\\<rparr>\n      \\<and> parser_bottom G \\<notin> set (v1 @ v2 @ v3))\"\n\n(*2a 2b not fixed before but fixed afterwards*)\ndefinition parserHF_step_relation_ALT2_2a :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\n  \\<Rightarrow> ('stack, 'event) parser_step_label\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\n  \\<Rightarrow> bool\"\n  where\n    \"parserHF_step_relation_ALT2_2a G c1 e c2 \\<equiv>\n    (\\<exists>v1 v2 v3 h s s1 q1 s2 q2.\n        c1 = \\<lparr>parserHF_conf_fixed = v1, parserHF_conf_history = h, parserHF_conf_stack = s @ s1 @ [q1]\\<rparr>\n      \\<and> e = \\<lparr>rule_lpop = s1 @ [q1], rule_rpop = v1 @ v2 @ v3 @ [parser_bottom G], rule_lpush = s2 @ [q2], rule_rpush = v3 @ [parser_bottom G]\\<rparr>\n      \\<and> c2 = \\<lparr>parserHF_conf_fixed = v3 @ [parser_bottom G], parserHF_conf_history = h @ v2 @ v3, parserHF_conf_stack = s @ s2 @ [q2]\\<rparr>\n      \\<and> parser_bottom G \\<notin> set (v1 @ v2 @ v3))\"\n\ndefinition parserHF_step_relation_ALT2_2b :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\n  \\<Rightarrow> ('stack, 'event) parser_step_label\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\n  \\<Rightarrow> bool\"\n  where\n    \"parserHF_step_relation_ALT2_2b G c1 e c2 \\<equiv>\n    (\\<exists>v1 v2 v3 h s s1 q1 s2 q2.\n        c1 = \\<lparr>parserHF_conf_fixed = v1 @ v2, parserHF_conf_history = h, parserHF_conf_stack = s @ s1 @ [q1]\\<rparr>\n      \\<and> e = \\<lparr>rule_lpop = s1 @ [q1], rule_rpop = v1 @ v2 @ v3 @ [parser_bottom G], rule_lpush = s2 @ [q2], rule_rpush = v2 @ v3 @ [parser_bottom G]\\<rparr>\n      \\<and> c2 = \\<lparr>parserHF_conf_fixed = v2 @ v3 @ [parser_bottom G], parserHF_conf_history = h @ v3, parserHF_conf_stack = s @ s2 @ [q2]\\<rparr>\n      \\<and> parser_bottom G \\<notin> set (v1 @ v2 @ v3))\"\n\n(*3a 3b fixed before*)\ndefinition parserHF_step_relation_ALT2_3a :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\n  \\<Rightarrow> ('stack, 'event) parser_step_label\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\n  \\<Rightarrow> bool\"\n  where\n    \"parserHF_step_relation_ALT2_3a G c1 e c2 \\<equiv>\n    (\\<exists>v1 v2 v3 h s s1 q1 s2 q2.\n        c1 = \\<lparr>parserHF_conf_fixed = v1 @ v2 @ v3 @ [parser_bottom G], parserHF_conf_history = h, parserHF_conf_stack = s @ s1 @ [q1]\\<rparr>\n      \\<and> e = \\<lparr>rule_lpop = s1 @ [q1], rule_rpop = v1 @ v2, rule_lpush = s2 @ [q2], rule_rpush = v2\\<rparr>\n      \\<and> c2 = \\<lparr>parserHF_conf_fixed = v2 @ v3 @ [parser_bottom G], parserHF_conf_history = h, parserHF_conf_stack = s @ s2 @ [q2]\\<rparr>\n      \\<and> parser_bottom G \\<notin> set (v1 @ v2 @ v3))\"\n\ndefinition parserHF_step_relation_ALT2_3b :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\n  \\<Rightarrow> ('stack, 'event) parser_step_label\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\n  \\<Rightarrow> bool\"\n  where\n    \"parserHF_step_relation_ALT2_3b G c1 e c2 \\<equiv>\n    (\\<exists>v1 v2 h s s1 q1 s2 q2.\n        c1 = \\<lparr>parserHF_conf_fixed = v1 @ v2 @ [parser_bottom G], parserHF_conf_history = h, parserHF_conf_stack = s @ s1 @ [q1]\\<rparr>\n      \\<and> e = \\<lparr>rule_lpop = s1 @ [q1], rule_rpop = v1 @ v2 @ [parser_bottom G], rule_lpush = s2 @ [q2], rule_rpush = v2 @ [parser_bottom G]\\<rparr>\n      \\<and> c2 = \\<lparr>parserHF_conf_fixed = v2 @ [parser_bottom G], parserHF_conf_history = h, parserHF_conf_stack = s @ s2 @ [q2]\\<rparr>\n      \\<and> parser_bottom G \\<notin> set (v1 @ v2))\"\n\ndefinition parserHF_step_relation_ALT2 :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\n  \\<Rightarrow> ('stack, 'event) parser_step_label\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\n  \\<Rightarrow> bool\"\n  where\n    \"parserHF_step_relation_ALT2 G c1 e c2 \\<equiv>\n  e \\<in> parser_rules G\n  \\<and> (\n      parserHF_step_relation_ALT2_1a G c1 e c2\n    \\<or> parserHF_step_relation_ALT2_1b G c1 e c2\n    \\<or> parserHF_step_relation_ALT2_1c G c1 e c2\n    \\<or> parserHF_step_relation_ALT2_2a G c1 e c2\n    \\<or> parserHF_step_relation_ALT2_2b G c1 e c2\n    \\<or> parserHF_step_relation_ALT2_3a G c1 e c2\n    \\<or> parserHF_step_relation_ALT2_3b G c1 e c2\n    )\"\n\nlemma parserHF_step_relation_ALT2_1a_intro: \"\n  e \\<in> parser_rules G \\<Longrightarrow> parserHF_step_relation_ALT2_1a G c1 e c2 \\<Longrightarrow> parserHF_step_relation_ALT2 G c1 e c2\"\n  apply(simp add: parserHF_step_relation_ALT2_def)\n  done\n\nlemma parserHF_step_relation_ALT2_2b_intro: \"\n  e \\<in> parser_rules G \\<Longrightarrow> parserHF_step_relation_ALT2_2b G c1 e c2 \\<Longrightarrow> parserHF_step_relation_ALT2 G c1 e c2\"\n  apply(simp add: parserHF_step_relation_ALT2_def)\n  done\n\nlemma parserHF_step_relation_ALT2_1b_intro: \"\n  e \\<in> parser_rules G \\<Longrightarrow> parserHF_step_relation_ALT2_1b G c1 e c2 \\<Longrightarrow> parserHF_step_relation_ALT2 G c1 e c2\"\n  apply(simp add: parserHF_step_relation_ALT2_def)\n  done\n\nlemma parserHF_step_relation_ALT2_1c_intro: \"\n  e \\<in> parser_rules G \\<Longrightarrow> parserHF_step_relation_ALT2_1c G c1 e c2 \\<Longrightarrow> parserHF_step_relation_ALT2 G c1 e c2\"\n  apply(simp add: parserHF_step_relation_ALT2_def)\n  done\n\nlemma parserHF_step_relation_ALT2_2a_intro: \"\n  e \\<in> parser_rules G \\<Longrightarrow> parserHF_step_relation_ALT2_2a G c1 e c2 \\<Longrightarrow> parserHF_step_relation_ALT2 G c1 e c2\"\n  apply(simp add: parserHF_step_relation_ALT2_def)\n  done\n\nlemma parserHF_step_relation_ALT2_3b_intro: \"\n  e \\<in> parser_rules G \\<Longrightarrow> parserHF_step_relation_ALT2_3b G c1 e c2 \\<Longrightarrow> parserHF_step_relation_ALT2 G c1 e c2\"\n  apply(simp add: parserHF_step_relation_ALT2_def)\n  done\n\nlemma parserHF_step_relation_ALT2_3a_intro: \"\n  e \\<in> parser_rules G \\<Longrightarrow> parserHF_step_relation_ALT2_3a G c1 e c2 \\<Longrightarrow> parserHF_step_relation_ALT2 G c1 e c2\"\n  apply(simp add: parserHF_step_relation_ALT2_def)\n  done\n\nlemma parserHF_step_relation_ALT2__vs__parserHF_step_relation_ALT: \"\n  valid_parser G\n  \\<Longrightarrow> c1 \\<in> parserHF_configurations G\n  \\<Longrightarrow> parserHF_step_relation_ALT2 G c1 e c2 = parserHF_step_relation_ALT G c1 e c2\"\n  apply(rule antisym)\n   apply(simp add: parserHF_step_relation_ALT2_def parserHF_step_relation_ALT_def)\n   apply(clarsimp)\n   apply(erule disjE) \n    apply(simp add: parserHF_step_relation_ALT2_1a_def)\n    apply(clarsimp)\n    apply (metis append_Nil2 butlast_if_match_direct2_prime butlast_if_match_pull_out drop_butlast_if_match_distrib prefix_append)\n   apply(erule disjE) \n    apply(simp add: parserHF_step_relation_ALT2_1b_def)\n    apply(clarsimp)\n    apply (metis append_assoc butlast_if_match_direct2_prime drop_butlast_if_match_distrib length_append prefix_append)\n   apply(erule disjE) \n    apply(simp add: parserHF_step_relation_ALT2_1c_def)\n    apply(clarsimp)\n    apply (metis append_assoc butlast_if_match_direct2_prime drop_length_append length_append not_set_append prefix_append)\n   apply(erule disjE) \n    apply(simp add: parserHF_step_relation_ALT2_2a_def)\n    apply(clarsimp)\n    apply (metis append_assoc butlast_if_match_direct drop_butlast_if_match_distrib length_append prefix_append)    \n   apply(erule disjE)\n    apply(simp add: parserHF_step_relation_ALT2_2b_def)\n    apply(clarsimp)\n    apply (metis append_assoc butlast_if_match_direct drop_butlast_if_match_distrib length_append prefix_append)    \n   apply(erule disjE)\n    apply(simp add: parserHF_step_relation_ALT2_3a_def)\n    apply(clarsimp)\n    apply(rule conjI)\n     apply (metis append_assoc append_self_conv butlast_if_match_direct2_prime butlast_if_match_pull_out drop_length_append le_SucI length_append)\n    apply (metis append_assoc prefix_def)\n   apply(simp add: parserHF_step_relation_ALT2_3b_def)\n   apply(clarsimp)\n   apply(rule conjI)\n    apply (metis add_Suc_right butlast_if_match_length_le length_Suc length_append)\n   apply(simp add: prefix_def)\n  apply(clarsimp)\n  apply(simp add: parserHF_step_relation_ALT_def)\n  apply(clarsimp)\n  apply(subgoal_tac \"valid_parser_step_label G e\")\n   prefer 2\n   apply (metis valid_parser_def)\n  apply(case_tac c1)\n  apply(rename_tac f1 h1 s1)\n  apply(case_tac c2)\n  apply(rename_tac f2 h2 s2)\n  apply(case_tac e)\n  apply(rename_tac lpop rpop lpush rpush)\n  apply(clarsimp)\n  apply(erule disjE)\n   apply(simp add: prefix_def)\n   apply(clarsimp)\n   apply(subgoal_tac \"drop (length rpop + length c) (butlast_if_match rpop (parser_bottom G)) = []\")\n    prefer 2\n    apply (metis drop_entire_butlast_if_match drop_length_append length_append)  \n   apply(clarsimp)\n   apply(thin_tac \"length (butlast_if_match rpop (parser_bottom G)) \\<le> length rpop + length c\")\n   apply(simp add: valid_parser_step_label_def)\n   apply(clarsimp)\n   apply(rule_tac xs=\"lpop\" in rev_cases)\n    apply(force)\n   apply(clarsimp)\n   apply(rule_tac xs=\"lpush\" in rev_cases)\n    apply(force)\n   apply(clarsimp)\n   apply(case_tac \"\\<exists>w'. kPrefix k (w @ [parser_bottom G]) @ c = w'@[parser_bottom G]\")\n    prefer 2\n    apply(clarsimp)\n    apply(case_tac \"k \\<le> length w\")\n     prefer 2\n     apply(simp add: parserHF_configurations_def)\n     apply(simp add: kPrefix_def)\n    apply(simp add: kPrefix_def)\n    apply(rule parserHF_step_relation_ALT2_1c_intro)\n     apply(force)\n    apply(simp add: parserHF_step_relation_ALT2_1c_def)\n    apply(rule_tac x=\"xb\" in exI)\n    apply(clarsimp)\n    apply(rule conjI)\n     apply (metis append_same_eq append_take_drop_id drop_prefix_closureise set_take_subset subsetD triv_compl)\n    apply(rule conjI)\n     apply (metis (no_types, hide_lams) Diff_iff Un_iff all_not_in_conv empty_subsetI insert_subset set_append set_take_subset subsetD)\n    apply(simp add: parserHF_configurations_def)\n   apply(clarsimp)\n   apply(rule_tac xs=\"c\" in rev_cases)\n    prefer 2\n    apply(clarsimp)\n    apply(rule parserHF_step_relation_ALT2_3a_intro)\n     apply(force)\n    apply(rule_tac t=\"kPrefix k (w @ [parser_bottom G])\" and s=\"xb @ rpush\" in ssubst)\n     apply(force)\n    apply(simp add: parserHF_step_relation_ALT2_3a_def)\n    apply(rule_tac x=\"xb\" in exI)\n    apply(clarsimp)\n    apply(case_tac \"k \\<le> length w\")\n     apply(simp add: parserHF_configurations_def)\n     apply(simp add: kPrefix_def)\n     apply (metis Un_iff set_append)\n    apply(simp add: kPrefix_def)\n    apply(clarsimp)\n    apply(simp add: parserHF_configurations_def)\n   apply(clarsimp)\n   apply(case_tac \"k \\<le> length w\")\n    apply(simp add: kPrefix_def)\n    apply (metis Un_iff insertCI set_append set_simps(2) set_take_subset subset_trans triv_compl)\n   apply(simp add: kPrefix_def)\n   apply(clarsimp)\n   apply(rule parserHF_step_relation_ALT2_3b_intro)\n    apply(force)  \n   apply(simp add: parserHF_step_relation_ALT2_3b_def)\n   apply (metis triv_compl)\n  apply(simp add: prefix_def)\n  apply(clarsimp)\n  apply(subgoal_tac \"drop (length f1) (butlast_if_match (f1 @ c) (parser_bottom G)) = butlast_if_match c (parser_bottom G)\")\n   prefer 2\n   apply (metis drop_butlast_if_match_distrib)\n  apply(clarsimp)\n  apply(thin_tac \"drop (length f1) (butlast_if_match (f1 @ c) (parser_bottom G)) =\n       butlast_if_match c (parser_bottom G)\")\n  apply(case_tac \"\\<exists>c'. c = c' @[parser_bottom G]\")\n   apply(clarsimp)\n   apply(subgoal_tac \"butlast_if_match (c' @ [parser_bottom G]) (parser_bottom G) = c'\")\n    prefer 2\n    apply (metis butlast_if_match_direct)\n   apply(clarsimp)\n   apply(thin_tac \"butlast_if_match (c' @ [parser_bottom G]) (parser_bottom G) = c'\")\n   apply(simp add: valid_parser_step_label_def)\n   apply(clarsimp)\n   apply(rule_tac xs=\"lpop\" in rev_cases)\n    apply(force)\n   apply(clarsimp)\n   apply(rule_tac xs=\"lpush\" in rev_cases)\n    apply(force)\n   apply(clarsimp)\n   apply(subgoal_tac \"f1@c'=xb@xc\") \n    prefer 2\n    apply (metis append1_eq_conv append_assoc)\n   apply(subgoal_tac \"prefix f1 xb \\<or> prefix xb f1\")\n    prefer 2\n    apply (metis mutual_prefix_prefix)\n   apply(erule disjE)\n    apply(simp add: prefix_def)\n    apply(clarsimp)\n    apply(case_tac \"k \\<le> length w\")\n     apply(simp add: kPrefix_def)\n     apply(subgoal_tac \"parser_bottom G \\<in> set w\")\n      apply(force)\n     apply(rule_tac A=\"set (take k w)\" in set_mp)\n      apply(rule set_take_subset)\n     apply(rule_tac A=\"set (f1 @ c @ xc @ [parser_bottom G])\" in set_mp)\n      apply(force)\n     apply(simp (no_asm))\n    apply(simp add: kPrefix_def)\n    apply(clarsimp)\n    apply(rule parserHF_step_relation_ALT2_2a_intro)\n     apply(force)\n    apply(rename_tac s v1 h k v3 s1 q1 s2 q2 v2)\n    apply(simp add: parserHF_step_relation_ALT2_2a_def)\n    apply(force)\n   apply(simp add: prefix_def)\n   apply(clarsimp)\n   apply(case_tac \"k \\<le> length w\")\n    apply(simp add: kPrefix_def)  \n    apply(subgoal_tac \"parser_bottom G \\<in> set w\")\n     apply(force)\n    apply(rule_tac A=\"set (take k w)\" in set_mp)\n     apply(rule set_take_subset)\n    apply(rule_tac A=\"set (xb @ c @ c' @ [parser_bottom G])\" in set_mp)\n     apply(force)\n    apply(simp (no_asm))\n   apply(simp add: kPrefix_def)\n   apply(clarsimp)\n   apply(rename_tac s h v3 k v1 s1 q1 s2 q2 v2)\n   apply(rule parserHF_step_relation_ALT2_2b_intro)\n    apply(force)\n   apply(simp add: parserHF_step_relation_ALT2_2b_def)\n   apply (metis triv_compl)\n  apply(clarsimp)\n  apply(rule_tac xs=\"c\" in rev_cases)\n   apply(clarsimp)\n   apply(simp add: valid_parser_step_label_def)\n   apply(clarsimp)\n   apply(rule_tac xs=\"lpop\" in rev_cases)\n    apply(force)\n   apply(clarsimp)\n   apply(rule_tac xs=\"lpush\" in rev_cases)\n    apply(force)\n   apply(clarsimp)\n   apply(simp add: butlast_if_match_def) \n   apply(case_tac \"k \\<le> length w\")\n    apply(simp add: kPrefix_def)\n    apply(subgoal_tac \"\\<exists>w'. w =xb@rpush @w' \\<and> length (xb@rpush) = k\")\n     prefer 2\n     apply(rule_tac x=\"drop k w\" in exI)\n     apply(rule conjI)\n      apply (metis append_assoc append_take_drop_id)\n     apply (metis take_all_length)\n    apply(rule_tac t=\"take k w\" and s=\"xb@rpush\" in ssubst)  \n     apply(force)\n    apply(thin_tac \"xb @ rpush = take k w\")\n    apply(clarsimp)\n    apply(rule parserHF_step_relation_ALT2_1c_intro)\n     apply(force)\n    apply(simp add: parserHF_step_relation_ALT2_1c_def)  \n    apply (metis triv_compl)  \n   apply(simp add: kPrefix_def)\n   apply(clarsimp)\n   apply(rename_tac s h k v1 s1 q1 s2 q2 v2)\n   apply(rule parserHF_step_relation_ALT2_3b_intro)\n    apply(force)\n   apply(simp add: parserHF_step_relation_ALT2_3b_def)\n   apply (metis triv_compl)\n  apply(clarsimp)\n  apply(subgoal_tac \"butlast_if_match (ys @ [y]) (parser_bottom G) =ys@[y]\")\n   prefer 2\n   apply (metis butlast_if_match_direct2)\n  apply(clarsimp)\n  apply(simp add: valid_parser_step_label_def)\n  apply(clarsimp)\n  apply(thin_tac \"butlast_if_match (ys @ [y]) (parser_bottom G) = ys @ [y]\")\n  apply(case_tac \"k \\<le> length w\")\n   prefer 2\n   apply(simp add: kPrefix_def)\n  apply(simp add: kPrefix_def)\n  apply(subgoal_tac \"\\<exists>w'. w =f1 @ ys @ [y] @w' \\<and> length (f1 @ ys @ [y]) = k\")\n   prefer 2\n   apply(rule_tac x=\"drop k w\" in exI)\n   apply(rule conjI)\n    apply (metis append_assoc append_take_drop_id)\n   apply (metis take_all_length)\n  apply(rule_tac t=\"take k w\" and s=\"f1 @ ys @ [y]\" in ssubst)  \n   apply(force)\n  apply(thin_tac \"f1 @ ys @ [y] = take k w\")\n  apply(clarsimp)\n  apply(rule_tac xs=\"lpop\" in rev_cases)\n   apply(force)\n  apply(clarsimp)\n  apply(rule_tac xs=\"lpush\" in rev_cases)\n   apply(force)\n  apply(clarsimp)\n  apply(subgoal_tac \"prefix f1 xb \\<or> prefix xb f1\")\n   prefer 2\n   apply (metis mutual_prefix_prefix)\n  apply(erule disjE)\n   apply(simp add: prefix_def)\n   apply(clarsimp)\n   apply(rule_tac xs=\"rpush\" in rev_cases)\n    apply(clarsimp)\n    apply(rule parserHF_step_relation_ALT2_1a_intro)\n     apply(force)\n    apply(simp add: parserHF_step_relation_ALT2_1a_def)\n    apply(force)\n   apply(clarsimp)\n   apply(rule parserHF_step_relation_ALT2_1a_intro)\n    apply(force)\n   apply(simp add: parserHF_step_relation_ALT2_1a_def)\n   apply(force)\n  apply(simp add: prefix_def)\n  apply(clarsimp)\n  apply(rename_tac s h v3a v3b v1 w' s1 q1 s2 q2 v2)\n  apply(rule parserHF_step_relation_ALT2_1b_intro)\n   apply(force)\n  apply(simp add: parserHF_step_relation_ALT2_1b_def)\n  apply(force)\n  done\n\n\ndefinition parserHF_initial_configurations :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserHF_conf set\"\n  where\n    \"parserHF_initial_configurations G \\<equiv>\n  {c. parserHF_conf_history c = []\n      \\<and> parserHF_conf_fixed c = []\n      \\<and> parserHF_conf_stack c = [parser_initial G]}\n  \\<inter> parserHF_configurations G\"\n\ndefinition parserHF_marking_configurations :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserHF_conf set\"\n  where\n    \"parserHF_marking_configurations G \\<equiv>\n  {c. \\<exists>f \\<in> parser_marking G. \\<exists>w.\n      parserHF_conf_stack c = w @ [f]\n      \\<and> parserHF_conf_fixed c \\<in> {[], [parser_bottom G]}}\n  \\<inter> parserHF_configurations G\"\n\ndefinition parserHF_marking_condition :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> (('stack, 'event) parser_step_label, ('stack, 'event) parserHF_conf)derivation\n  \\<Rightarrow> bool\"\n  where\n    \"parserHF_marking_condition G d \\<equiv>\n  \\<exists>i e c.\n    d i = Some (pair e c)\n    \\<and> c \\<in> parserHF_marking_configurations G\n    \\<and> (\\<forall>j e' c'.\n        j > i\n        \\<and> d j = Some(pair e' c')\n        \\<longrightarrow> parserHF_conf_history c = parserHF_conf_history c')\"\n\ndefinition parserHF_marked_effect :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> (('stack, 'event) parser_step_label, ('stack, 'event) parserHF_conf)derivation\n  \\<Rightarrow> 'event list set\"\n  where\n    \"parserHF_marked_effect G d \\<equiv>\n  {w. \\<exists>i e c.\n      d i = Some (pair e c)\n      \\<and> w = parserHF_conf_history c\n      \\<and> c \\<in> parserHF_marking_configurations G}\"\n\ndefinition parserHF_unmarked_effect :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> (('stack, 'event) parser_step_label, ('stack, 'event) parserHF_conf)derivation\n  \\<Rightarrow> 'event list set\"\n  where\n    \"parserHF_unmarked_effect G d \\<equiv>\n  {w. \\<exists>i e c.\n      d i = Some (pair e c)\n      \\<and> parserHF_conf_history c = w}\"\n\ndefinition parserHF_get_destinations :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> (('stack, 'event) parser_step_label, ('stack, 'event) parserHF_conf)derivation_configuration\n  \\<Rightarrow> ('stack, 'event) parser_destinations set\"\n  where\n    \"parserHF_get_destinations G der_conf \\<equiv>\n  case der_conf of pair e c \\<Rightarrow>\n    state ` set (parserHF_conf_stack c)\n    \\<union> (case e of None \\<Rightarrow> {} | Some e' \\<Rightarrow> {rule e'})\"\n\nlemma parserHF_inst_AX_initial_configuration_belongs: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> parserHF_initial_configurations G \\<subseteq> parserHF_configurations G)\"\n  apply(clarsimp)\n  apply(rename_tac G x)(*strict*)\n  apply(simp add: parserHF_initial_configurations_def)\n  done\n\nlemma parserHF_inst_AX_step_relation_preserves_belongs: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c1 e c2. parserHF_step_relation G c1 e c2 \\<longrightarrow> c1 \\<in> parserHF_configurations G \\<longrightarrow> e \\<in> parser_step_labels G \\<and> c2 \\<in> parserHF_configurations G))\"\n  apply(clarsimp)\n  apply(rename_tac G c1 e c2)(*strict*)\n  apply(rule context_conjI)\n   apply(rename_tac G c1 e c2)(*strict*)\n   apply(simp add: parser_step_labels_def parserHF_step_relation_def)\n  apply(rename_tac G c1 e c2)(*strict*)\n  apply(simp add: parserHF_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac G e c2 f h l)(*strict*)\n  apply(simp add: parserHF_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac G e c2 f h x)(*strict*)\n  apply(case_tac c2)\n  apply(rename_tac G e c2 f h x parserHF_conf_fixeda parserHF_conf_historya parserHF_conf_stacka)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G e f h x)(*strict*)\n  apply(simp add: parser_step_labels_def)\n  apply(subgoal_tac \"valid_parser_step_label G e\")\n   apply(rename_tac G e f h x)(*strict*)\n   prefer 2\n   apply(simp add: valid_parser_def)\n  apply(rename_tac G e f h x)(*strict*)\n  apply(rule context_conjI)\n   apply(rename_tac G e f h x)(*strict*)\n   apply(simp add: valid_parser_step_label_def)\n  apply(rename_tac G e f h x)(*strict*)\n  apply(subgoal_tac \"set (rule_rpush e) \\<subseteq> parser_events G\")\n   apply(rename_tac G e f h x)(*strict*)\n   prefer 2\n   apply(simp add: valid_parser_step_label_def)\n  apply(rename_tac G e f h x)(*strict*)\n  apply(clarsimp)\n  apply(rule context_conjI)\n   apply(rename_tac G e f h x)(*strict*)\n   apply(metis set_drop_subset subset_trans)\n  apply(rename_tac G e f h x)(*strict*)\n  apply(subgoal_tac \"set (rule_rpop e) \\<subseteq> parser_events G\")\n   apply(rename_tac G e f h x)(*strict*)\n   prefer 2\n   apply(simp add: valid_parser_step_label_def)\n   apply(clarsimp)\n   apply(rename_tac G e f h x xa k w xc)(*strict*)\n   apply(rule_tac\n      A=\"set (kPrefix k (w @ [parser_bottom G]))\"\n      in set_mp)\n    apply(rename_tac G e f h x xa k w xc)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G e f h x xa k w xc)(*strict*)\n   apply(rule set_kPrefix_subset)\n   apply(clarsimp)\n   apply(simp add: valid_parser_def)\n   apply(rule_tac\n      B=\"parser_events G - {parser_bottom G}\"\n      in subset_trans)\n    apply(rename_tac G e f h x xa k w xc)(*strict*)\n    apply(force)\n   apply(rename_tac G e f h x xa k w xc)(*strict*)\n   apply(force)\n  apply(rename_tac G e f h x)(*strict*)\n  apply(subgoal_tac \"set (drop (length f) (butlast_if_match (rule_rpop e) (parser_bottom G))) \\<subseteq> set (rule_rpop e)\")\n   apply(rename_tac G e f h x)(*strict*)\n   prefer 2\n   apply(rule_tac\n      B=\"set(butlast_if_match (rule_rpop e) (parser_bottom G))\"\n      in subset_trans)\n    apply(rename_tac G e f h x)(*strict*)\n    apply(rule set_drop_subset)\n   apply(rename_tac G e f h x)(*strict*)\n   apply(rule_tac\n      B=\"set(rule_rpop e)\"\n      in subset_trans)\n    apply(rename_tac G e f h x)(*strict*)\n    apply(rule set_butlast_if_match_is_subset)\n   apply(rename_tac G e f h x)(*strict*)\n   apply(force)\n  apply(rename_tac G e f h x)(*strict*)\n  apply(rule context_conjI)\n   apply(rename_tac G e f h x)(*strict*)\n   apply(force)\n  apply(rename_tac G e f h x)(*strict*)\n  apply(rule context_conjI)\n   apply(rename_tac G e f h x)(*strict*)\n   apply(simp add: valid_parser_step_label_def)\n   apply(case_tac \"(\\<exists>x. x @ rule_rpush e = rule_rpop e)\")\n    apply(rename_tac G e f h x)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G e f h x xa k w)(*strict*)\n    apply(simp add: kPrefix_def)\n    apply(clarsimp)\n    apply(case_tac \"k-length w\")\n     apply(rename_tac G e f h x xa k w)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"butlast_if_match (take k w) (parser_bottom G) = take k w\")\n      apply(rename_tac G e f h x xa k w)(*strict*)\n      apply(clarsimp)\n      apply(subgoal_tac \"parser_bottom G \\<notin> set (drop (length f) (take k w))\")\n       apply(rename_tac G e f h x xa k w)(*strict*)\n       apply(force)\n      apply(rename_tac G e f h x xa k w)(*strict*)\n      apply(rule_tac\n      B=\"set(take k w)\"\n      in nset_mp)\n       apply(rename_tac G e f h x xa k w)(*strict*)\n       apply(rule set_drop_subset)\n      apply(rename_tac G e f h x xa k w)(*strict*)\n      apply(rule_tac\n      B=\"set w\"\n      in nset_mp)\n       apply(rename_tac G e f h x xa k w)(*strict*)\n       apply(rule set_take_subset)\n      apply(rename_tac G e f h x xa k w)(*strict*)\n      apply(rule_tac\n      A=\"parser_events G\"\n      in not_in_diff)\n      apply(force)\n     apply(rename_tac G e f h x xa k w)(*strict*)\n     apply(rule butlast_if_match_direct2_prime)\n     apply(rule_tac\n      B=\"set w\"\n      in nset_mp)\n      apply(rename_tac G e f h x xa k w)(*strict*)\n      apply(rule set_take_subset)\n     apply(rename_tac G e f h x xa k w)(*strict*)\n     apply(rule_tac\n      A=\"parser_events G\"\n      in not_in_diff)\n     apply(force)\n    apply(rename_tac G e f h x xa k w nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G e f h x xa k w nat xb)(*strict*)\n    apply(subgoal_tac \"butlast_if_match (w @ [parser_bottom G]) (parser_bottom G) = w\")\n     apply(rename_tac G e f h x xa k w nat xb)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"parser_bottom G \\<notin> set (drop (length f) w)\")\n      apply(rename_tac G e f h x xa k w nat xb)(*strict*)\n      apply(force)\n     apply(rename_tac G e f h x xa k w nat xb)(*strict*)\n     apply(rule_tac\n      B=\"set w\"\n      in nset_mp)\n      apply(rename_tac G e f h x xa k w nat xb)(*strict*)\n      apply(rule set_drop_subset)\n     apply(rename_tac G e f h x xa k w nat xb)(*strict*)\n     apply(rule_tac\n      A=\"parser_events G\"\n      in not_in_diff)\n     apply(force)\n    apply(rename_tac G e f h x xa k w nat xb)(*strict*)\n    apply(rule butlast_if_match_direct)\n    apply(force)\n   apply(rename_tac G e f h x)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G e f h x)(*strict*)\n  apply(rule propSym)\n  apply(subgoal_tac \"\\<exists>w. rule_rpop e = w @ (rule_rpush e)\")\n   apply(rename_tac G e f h x)(*strict*)\n   prefer 2\n   apply(simp add: valid_parser_step_label_def)\n   apply(clarsimp)\n   apply(rename_tac G e f h x k w xb)(*strict*)\n   apply(simp add: kPrefix_def)\n   apply(rule_tac\n      x=\"xb\"\n      in exI)\n   apply(force)\n  apply(rename_tac G e f h x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G e f h x w)(*strict*)\n  apply(rule context_conjI)\n   apply(rename_tac G e f h x w)(*strict*)\n   apply(clarsimp)\n   apply(erule disjE)\n    apply(rename_tac G e f h x w)(*strict*)\n    apply(simp add: prefix_def)\n    apply(clarsimp)\n    apply(rename_tac G e h x w c wa)(*strict*)\n    apply(subgoal_tac \"prefix w wa \\<or> prefix wa w\")\n     apply(rename_tac G e h x w c wa)(*strict*)\n     apply(erule disjE)\n      apply(rename_tac G e h x w c wa)(*strict*)\n      apply(simp add: prefix_def)\n      apply(clarsimp)\n     apply(rename_tac G e h x w c wa)(*strict*)\n     apply(simp add: prefix_def)\n     apply(clarsimp)\n     apply(rename_tac G e h x c wa ca)(*strict*)\n     apply(case_tac ca)\n      apply(rename_tac G e h x c wa ca)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac G e h x c wa ca a list)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G e h x w c wa)(*strict*)\n    apply(rule mutual_prefix_prefix)\n    apply(force)\n   apply(rename_tac G e f h x w)(*strict*)\n   apply(simp add: prefix_def)\n   apply(clarsimp)\n   apply(rename_tac G e f h x w c)(*strict*)\n   apply(subgoal_tac \"drop (length w + length (rule_rpush e)) f = []\")\n    apply(rename_tac G e f h x w c)(*strict*)\n    apply(clarsimp)\n    apply(simp add: valid_parser_step_label_def)\n    apply(clarsimp)\n    apply(rename_tac G e f h x w c k wa)(*strict*)\n    apply(case_tac e)\n    apply(rename_tac G e f h x w c k wa rule_lpopa rule_rpopa rule_lpusha rule_rpusha)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G f h x w c k wa rule_lpop rule_lpush rule_rpush)(*strict*)\n    apply(simp add: kPrefix_def)\n    apply(case_tac \"k-length wa\")\n     apply(rename_tac G f h x w c k wa rule_lpop rule_lpush rule_rpush)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"parser_bottom G \\<notin> set rule_rpush\")\n      apply(rename_tac G f h x w c k wa rule_lpop rule_lpush rule_rpush)(*strict*)\n      apply(force)\n     apply(rename_tac G f h x w c k wa rule_lpop rule_lpush rule_rpush)(*strict*)\n     apply(rule_tac\n      B=\"set(w @ rule_rpush)\"\n      in nset_mp)\n      apply(rename_tac G f h x w c k wa rule_lpop rule_lpush rule_rpush)(*strict*)\n      apply(simp (no_asm))\n     apply(rename_tac G f h x w c k wa rule_lpop rule_lpush rule_rpush)(*strict*)\n     apply(rule_tac\n      B=\"set(take k wa)\"\n      in nset_mp)\n      apply(rename_tac G f h x w c k wa rule_lpop rule_lpush rule_rpush)(*strict*)\n      apply(simp (no_asm_simp))\n     apply(rename_tac G f h x w c k wa rule_lpop rule_lpush rule_rpush)(*strict*)\n     apply(rule_tac\n      B=\"set wa\"\n      in nset_mp)\n      apply(rename_tac G f h x w c k wa rule_lpop rule_lpush rule_rpush)(*strict*)\n      apply(rule set_take_subset)\n     apply(rename_tac G f h x w c k wa rule_lpop rule_lpush rule_rpush)(*strict*)\n     apply(rule_tac\n      A=\"parser_events G\"\n      in not_in_diff)\n     apply(force)\n    apply(rename_tac G f h x w c k wa rule_lpop rule_lpush rule_rpush nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G f h x w c k rule_lpop rule_lpush nat xa)(*strict*)\n    apply(case_tac c)\n     apply(rename_tac G f h x w c k rule_lpop rule_lpush nat xa)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G f h x w c k rule_lpop rule_lpush nat xa a list)(*strict*)\n    apply(subgoal_tac \"\\<exists>w' x'. c = w' @ [x']\")\n     apply(rename_tac G f h x w c k rule_lpop rule_lpush nat xa a list)(*strict*)\n     prefer 2\n     apply(rule NonEmptyListHasTailElem)\n     apply(force)\n    apply(rename_tac G f h x w c k rule_lpop rule_lpush nat xa a list)(*strict*)\n    apply(thin_tac \"c=a#list\")\n    apply(clarsimp)\n    apply(rename_tac G f h x w k rule_lpop rule_lpush nat xa w')(*strict*)\n    apply(subgoal_tac \"parser_bottom G \\<notin> set xa\")\n     apply(rename_tac G f h x w k rule_lpop rule_lpush nat xa w')(*strict*)\n     apply(force)\n    apply(rename_tac G f h x w k rule_lpop rule_lpush nat xa w')(*strict*)\n    apply(rule_tac\n      A=\"parser_events G\"\n      in not_in_diff)\n    apply(force)\n   apply(rename_tac G e f h x w c)(*strict*)\n   apply(rule drop_all)\n   apply(rule_tac\n      j=\"length(w@rule_rpush e)\"\n      in le_trans)\n    apply(rename_tac G e f h x w c)(*strict*)\n    apply(rule_tac\n      t=\"w@rule_rpush e\"\n      and s=\"f@c\"\n      in ssubst)\n     apply(rename_tac G e f h x w c)(*strict*)\n     apply(force)\n    apply(rename_tac G e f h x w c)(*strict*)\n    apply(simp (no_asm))\n   apply(rename_tac G e f h x w c)(*strict*)\n   apply(force)\n  apply(rename_tac G e f h x w)(*strict*)\n  apply(rule context_conjI)\n   apply(rename_tac G e f h x w)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"parser_bottom G \\<in> set f\")\n    apply(rename_tac G e f h x w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G e h x w wa)(*strict*)\n    apply(case_tac \"length w + length (rule_rpush e) - length wa\")\n     apply(rename_tac G e h x w wa)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"parser_bottom G \\<in> set wa\")\n      apply(rename_tac G e h x w wa)(*strict*)\n      apply(force)\n     apply(rename_tac G e h x w wa)(*strict*)\n     apply(rule_tac\n      A=\"set (drop (length w + length (rule_rpush e)) wa)\"\n      in set_mp)\n      apply(rename_tac G e h x w wa)(*strict*)\n      apply(rule set_drop_subset)\n     apply(rename_tac G e h x w wa)(*strict*)\n     apply(force)\n    apply(rename_tac G e h x w wa nat)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G e f h x w)(*strict*)\n   apply(rule_tac\n      A=\"set (drop (length w + length (rule_rpush e)) f)\"\n      in set_mp)\n    apply(rename_tac G e f h x w)(*strict*)\n    apply(rule set_drop_subset)\n   apply(rename_tac G e f h x w)(*strict*)\n   apply(force)\n  apply(rename_tac G e f h x w)(*strict*)\n  apply(simp add: suffix_def)\n  apply(clarsimp)\n  apply(rename_tac G e f x w c)(*strict*)\n  apply(case_tac \"parser_bottom G \\<in> set f\")\n   apply(rename_tac G e f x w c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G e x w c wa)(*strict*)\n   apply(rule_tac\n      t=\"butlast_if_match (wa @ [parser_bottom G]) (parser_bottom G)\"\n      and s=\"wa\"\n      in ssubst)\n    apply(rename_tac G e x w c wa)(*strict*)\n    apply(rule butlast_if_match_direct)\n    apply(force)\n   apply(rename_tac G e x w c wa)(*strict*)\n   apply(case_tac \"length w + length (rule_rpush e) - length wa\")\n    apply(rename_tac G e x w c wa)(*strict*)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"butlast_if_match (rule_rpush e @ drop (length w + length (rule_rpush e)) wa @ [parser_bottom G]) (parser_bottom G)\"\n      and s=\"rule_rpush e @ drop (length w + length (rule_rpush e)) wa\"\n      in ssubst)\n     apply(rename_tac G e x w c wa)(*strict*)\n     apply(rule butlast_if_match_direct)\n     apply(force)\n    apply(rename_tac G e x w c wa)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac G e x w c wa)(*strict*)\n     apply(simp add: prefix_def)\n     apply(clarsimp)\n     apply(rename_tac G e x w c wa ca)(*strict*)\n     apply(rule_tac\n      t=\"drop (Suc (length wa)) (butlast_if_match (w @ rule_rpush e) (parser_bottom G))\"\n      and s=\"[]\"\n      in ssubst)\n      apply(rename_tac G e x w c wa ca)(*strict*)\n      apply(rule drop_all)\n      apply(rule_tac\n      j=\"length(w@rule_rpush e)\"\n      in le_trans)\n       apply(rename_tac G e x w c wa ca)(*strict*)\n       apply(rule butlast_if_match_length_le)\n      apply(rename_tac G e x w c wa ca)(*strict*)\n      apply(force)\n     apply(rename_tac G e x w c wa ca)(*strict*)\n     apply(clarsimp)\n     apply(case_tac ca)\n      apply(rename_tac G e x w c wa ca)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac G e x w c wa)(*strict*)\n      apply(rule_tac\n      t=\"drop (length w + length (rule_rpush e)) wa\"\n      and s=\"[]\"\n      in ssubst)\n       apply(rename_tac G e x w c wa)(*strict*)\n       apply(rule drop_all)\n       apply(rule_tac\n      j=\"length(w@rule_rpush e)\"\n      in le_trans)\n        apply(rename_tac G e x w c wa)(*strict*)\n        apply(force)\n       apply(rename_tac G e x w c wa)(*strict*)\n       apply(simp (no_asm))\n      apply(rename_tac G e x w c wa)(*strict*)\n      apply(clarsimp)\n      apply(case_tac \"rule_rpush e\")\n       apply(rename_tac G e x w c wa)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac G e x w c wa a list)(*strict*)\n      apply(subgoal_tac \"\\<exists>w' x'. rule_rpush e = w' @ [x']\")\n       apply(rename_tac G e x w c wa a list)(*strict*)\n       prefer 2\n       apply(rule NonEmptyListHasTailElem)\n       apply(force)\n      apply(rename_tac G e x w c wa a list)(*strict*)\n      apply(thin_tac \"rule_rpush e=a#list\")\n      apply(clarsimp)\n     apply(rename_tac G e x w c wa ca a list)(*strict*)\n     apply(subgoal_tac \"\\<exists>w' x'. ca = w' @ [x']\")\n      apply(rename_tac G e x w c wa ca a list)(*strict*)\n      prefer 2\n      apply(rule NonEmptyListHasTailElem)\n      apply(force)\n     apply(rename_tac G e x w c wa ca a list)(*strict*)\n     apply(thin_tac \"ca=a#list\")\n     apply(clarsimp)\n    apply(rename_tac G e x w c wa)(*strict*)\n    apply(simp add: prefix_def)\n    apply(clarsimp)\n    apply(rename_tac G e x w c wa ca)(*strict*)\n    apply(subgoal_tac \"prefix (wa@[parser_bottom G]) w \\<or> prefix w (wa@[parser_bottom G])\")\n     apply(rename_tac G e x w c wa ca)(*strict*)\n     prefer 2\n     apply(rule mutual_prefix_prefix)\n     apply(force)\n    apply(rename_tac G e x w c wa ca)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac G e x w c wa ca)(*strict*)\n     apply(simp add: prefix_def)\n     apply(clarsimp)\n    apply(rename_tac G e x w c wa ca)(*strict*)\n    apply(simp add: prefix_def)\n    apply(clarsimp)\n    apply(rename_tac G e x w c wa ca cb)(*strict*)\n    apply(case_tac cb)\n     apply(rename_tac G e x w c wa ca cb)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G e x w c wa ca cb a list)(*strict*)\n    apply(subgoal_tac \"\\<exists>w' x'. cb = w' @ [x']\")\n     apply(rename_tac G e x w c wa ca cb a list)(*strict*)\n     prefer 2\n     apply(rule NonEmptyListHasTailElem)\n     apply(force)\n    apply(rename_tac G e x w c wa ca cb a list)(*strict*)\n    apply(thin_tac \"cb=a#list\")\n    apply(clarsimp)\n    apply(rename_tac G e x w c ca w')(*strict*)\n    apply(subgoal_tac \"parser_bottom G \\<in> set (rule_rpush e)\")\n     apply(rename_tac G e x w c ca w')(*strict*)\n     apply(force)\n    apply(rename_tac G e x w c ca w')(*strict*)\n    apply(rule_tac\n      t=\"rule_rpush e\"\n      and s=\"w' @ parser_bottom G # ca\"\n      in ssubst)\n     apply(rename_tac G e x w c ca w')(*strict*)\n     apply(force)\n    apply(rename_tac G e x w c ca w')(*strict*)\n    apply(simp (no_asm))\n   apply(rename_tac G e x w c wa nat)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"parser_bottom G \\<in> set (rule_rpush e)\")\n    apply(rename_tac G e x w c wa nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G e x w c wa nat wb)(*strict*)\n    apply(rule_tac\n      t=\"butlast_if_match (wb @ [parser_bottom G]) (parser_bottom G)\"\n      and s=\"wb\"\n      in ssubst)\n     apply(rename_tac G e x w c wa nat wb)(*strict*)\n     apply(rule butlast_if_match_direct)\n     apply(force)\n    apply(rename_tac G e x w c wa nat wb)(*strict*)\n    apply(rule_tac\n      t=\"butlast_if_match (w @ wb @ [parser_bottom G]) (parser_bottom G)\"\n      and s=\"w@wb\"\n      in ssubst)\n     apply(rename_tac G e x w c wa nat wb)(*strict*)\n     apply(rule butlast_if_match_direct)\n     apply(force)\n    apply(rename_tac G e x w c wa nat wb)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac G e x w c wa nat wb)(*strict*)\n     apply(simp add: prefix_def)\n     apply(clarsimp)\n     apply(rename_tac G e x w c wa nat wb ca)(*strict*)\n     apply(case_tac ca)\n      apply(rename_tac G e x w c wa nat wb ca)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac G e x w c wa nat wb ca a list)(*strict*)\n     apply(subgoal_tac \"\\<exists>w' x'. ca = w' @ [x']\")\n      apply(rename_tac G e x w c wa nat wb ca a list)(*strict*)\n      prefer 2\n      apply(rule NonEmptyListHasTailElem)\n      apply(force)\n     apply(rename_tac G e x w c wa nat wb ca a list)(*strict*)\n     apply(thin_tac \"ca=a#list\")\n     apply(clarsimp)\n    apply(rename_tac G e x w c wa nat wb)(*strict*)\n    apply(simp add: prefix_def)\n    apply(clarsimp)\n    apply(rename_tac G e x w c wa nat wb ca)(*strict*)\n    apply(case_tac ca)\n     apply(rename_tac G e x w c wa nat wb ca)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G e x w c wa nat wb ca a list)(*strict*)\n    apply(subgoal_tac \"\\<exists>w' x'. ca = w' @ [x']\")\n     apply(rename_tac G e x w c wa nat wb ca a list)(*strict*)\n     prefer 2\n     apply(rule NonEmptyListHasTailElem)\n     apply(force)\n    apply(rename_tac G e x w c wa nat wb ca a list)(*strict*)\n    apply(thin_tac \"ca=a#list\")\n    apply(clarsimp)\n    apply(rename_tac G e x w c wa nat wb w')(*strict*)\n    apply(subgoal_tac \"prefix (wa@[parser_bottom G]) w \\<or> prefix w (wa@[parser_bottom G])\")\n     apply(rename_tac G e x w c wa nat wb w')(*strict*)\n     prefer 2\n     apply(rule mutual_prefix_prefix)\n     apply(force)\n    apply(rename_tac G e x w c wa nat wb w')(*strict*)\n    apply(erule disjE)\n     apply(rename_tac G e x w c wa nat wb w')(*strict*)\n     apply(simp add: prefix_def)\n     apply(clarsimp)\n    apply(rename_tac G e x w c wa nat wb w')(*strict*)\n    apply(simp add: prefix_def)\n    apply(clarsimp)\n    apply(rename_tac G e x w c wa nat wb w' ca)(*strict*)\n    apply(case_tac ca)\n     apply(rename_tac G e x w c wa nat wb w' ca)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G e x w c wa nat wb w' ca a list)(*strict*)\n    apply(subgoal_tac \"\\<exists>w' x'. ca = w' @ [x']\")\n     apply(rename_tac G e x w c wa nat wb w' ca a list)(*strict*)\n     prefer 2\n     apply(rule NonEmptyListHasTailElem)\n     apply(force)\n    apply(rename_tac G e x w c wa nat wb w' ca a list)(*strict*)\n    apply(thin_tac \"ca=a#list\")\n    apply(clarsimp)\n   apply(rename_tac G e x w c wa nat)(*strict*)\n   apply(rule_tac\n      t=\"butlast_if_match (rule_rpush e) (parser_bottom G)\"\n      and s=\"rule_rpush e\"\n      in ssubst)\n    apply(rename_tac G e x w c wa nat)(*strict*)\n    apply(rule butlast_if_match_direct2_prime)\n    apply(force)\n   apply(rename_tac G e x w c wa nat)(*strict*)\n   apply(case_tac \"rule_rpush e\")\n    apply(rename_tac G e x w c wa nat)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G e x w c wa nat a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. rule_rpush e = w' @ [x']\")\n    apply(rename_tac G e x w c wa nat a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac G e x w c wa nat a list)(*strict*)\n   apply(thin_tac \"rule_rpush e=a#list\")\n   apply(clarsimp)\n   apply(rename_tac G e x w c wa nat w' x')(*strict*)\n   apply(rule_tac\n      t=\"butlast_if_match (w @ w' @ [x']) (parser_bottom G)\"\n      and s=\"w @ w' @ [x']\"\n      in ssubst)\n    apply(rename_tac G e x w c wa nat w' x')(*strict*)\n    apply(rule butlast_if_match_direct2)\n     apply(rename_tac G e x w c wa nat w' x')(*strict*)\n     apply(force)\n    apply(rename_tac G e x w c wa nat w' x')(*strict*)\n    apply(force)\n   apply(rename_tac G e x w c wa nat w' x')(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"nat+length wa=length w + length w'\")\n    apply(rename_tac G e x w c wa nat w' x')(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G e x w c wa nat w' x')(*strict*)\n   apply(erule disjE)\n    apply(rename_tac G e x w c wa nat w' x')(*strict*)\n    prefer 2\n    apply(simp add: prefix_def)\n    apply(clarsimp)\n    apply(rename_tac G e x w c wa nat w' x' ca)(*strict*)\n    apply(subgoal_tac \"prefix (wa@[parser_bottom G]) w \\<or> prefix w (wa@[parser_bottom G])\")\n     apply(rename_tac G e x w c wa nat w' x' ca)(*strict*)\n     prefer 2\n     apply(rule mutual_prefix_prefix)\n     apply(force)\n    apply(rename_tac G e x w c wa nat w' x' ca)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac G e x w c wa nat w' x' ca)(*strict*)\n     apply(simp add: prefix_def)\n     apply(clarsimp)\n    apply(rename_tac G e x w c wa nat w' x' ca)(*strict*)\n    apply(simp add: prefix_def)\n    apply(clarsimp)\n    apply(rename_tac G e x w c wa nat w' x' ca cb)(*strict*)\n    apply(case_tac cb)\n     apply(rename_tac G e x w c wa nat w' x' ca cb)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G e x w c wa nat w' x' ca cb a list)(*strict*)\n    apply(subgoal_tac \"\\<exists>w' x'. cb = w' @ [x']\")\n     apply(rename_tac G e x w c wa nat w' x' ca cb a list)(*strict*)\n     prefer 2\n     apply(rule NonEmptyListHasTailElem)\n     apply(force)\n    apply(rename_tac G e x w c wa nat w' x' ca cb a list)(*strict*)\n    apply(thin_tac \"cb=a#list\")\n    apply(clarsimp)\n    apply(rename_tac G e x w c nat w' x' ca w'a)(*strict*)\n    apply(case_tac ca)\n     apply(rename_tac G e x w c nat w' x' ca w'a)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G e x w c nat w' x' ca w'a a list)(*strict*)\n    apply(subgoal_tac \"\\<exists>w' x'. ca = w' @ [x']\")\n     apply(rename_tac G e x w c nat w' x' ca w'a a list)(*strict*)\n     prefer 2\n     apply(rule NonEmptyListHasTailElem)\n     apply(force)\n    apply(rename_tac G e x w c nat w' x' ca w'a a list)(*strict*)\n    apply(thin_tac \"ca=a#list\")\n    apply(clarsimp)\n   apply(rename_tac G e x w c wa nat w' x')(*strict*)\n   apply(simp add: prefix_def)\n   apply(clarsimp)\n   apply(rename_tac G e x w c wa nat w' x' ca)(*strict*)\n   apply(case_tac ca)\n    apply(rename_tac G e x w c wa nat w' x' ca)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G e x w c wa nat w' x' ca a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. ca = w' @ [x']\")\n    apply(rename_tac G e x w c wa nat w' x' ca a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac G e x w c wa nat w' x' ca a list)(*strict*)\n   apply(thin_tac \"ca=a#list\")\n   apply(clarsimp)\n  apply(rename_tac G e f x w c)(*strict*)\n  apply(rule_tac\n      t=\"butlast_if_match f (parser_bottom G)\"\n      and s=\"f\"\n      in ssubst)\n   apply(rename_tac G e f x w c)(*strict*)\n   apply(rule butlast_if_match_direct2_prime)\n   apply(force)\n  apply(rename_tac G e f x w c)(*strict*)\n  apply(clarsimp)\n  apply(erule disjE)\n   apply(rename_tac G e f x w c)(*strict*)\n   apply(simp add: prefix_def)\n   apply(clarsimp)\n   apply(rename_tac G e x w c ca)(*strict*)\n   apply(case_tac ca)\n    apply(rename_tac G e x w c ca)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G e x w c)(*strict*)\n    apply(case_tac \"rule_rpush e\")\n     apply(rename_tac G e x w c)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G e x c)(*strict*)\n     apply(rule_tac\n      t=\"butlast_if_match [] (parser_bottom G)\"\n      and s=\"[]\"\n      in ssubst)\n      apply(rename_tac G e x c)(*strict*)\n      apply(rule butlast_if_match_direct2_prime)\n      apply(force)\n     apply(rename_tac G e x c)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G e x w c a list)(*strict*)\n    apply(subgoal_tac \"\\<exists>w' x'. rule_rpush e = w' @ [x']\")\n     apply(rename_tac G e x w c a list)(*strict*)\n     prefer 2\n     apply(rule NonEmptyListHasTailElem)\n     apply(force)\n    apply(rename_tac G e x w c a list)(*strict*)\n    apply(thin_tac \"rule_rpush e=a#list\")\n    apply(clarsimp)\n    apply(rename_tac G e x w c w' x')(*strict*)\n    apply(rule_tac\n      t=\"butlast_if_match (w' @ [x']) (parser_bottom G)\"\n      and s=\"w'@[x']\"\n      in ssubst)\n     apply(rename_tac G e x w c w' x')(*strict*)\n     apply(rule butlast_if_match_direct2)\n      apply(rename_tac G e x w c w' x')(*strict*)\n      apply(force)\n     apply(rename_tac G e x w c w' x')(*strict*)\n     apply(force)\n    apply(rename_tac G e x w c w' x')(*strict*)\n    apply(rule_tac\n      t=\"butlast_if_match (w@w' @ [x']) (parser_bottom G)\"\n      and s=\"w@w'@[x']\"\n      in ssubst)\n     apply(rename_tac G e x w c w' x')(*strict*)\n     apply(rule butlast_if_match_direct2)\n      apply(rename_tac G e x w c w' x')(*strict*)\n      apply(force)\n     apply(rename_tac G e x w c w' x')(*strict*)\n     apply(force)\n    apply(rename_tac G e x w c w' x')(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G e x w c ca a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. ca = w' @ [x']\")\n    apply(rename_tac G e x w c ca a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac G e x w c ca a list)(*strict*)\n   apply(thin_tac \"ca=a#list\")\n   apply(clarsimp)\n   apply(rename_tac G e x w c w' x')(*strict*)\n   apply(rule_tac\n      t=\"butlast_if_match (rule_rpush e @ w' @ [x']) (parser_bottom G)\"\n      and s=\"(rule_rpush e @ w' @ [x'])\"\n      in ssubst)\n    apply(rename_tac G e x w c w' x')(*strict*)\n    apply(rule butlast_if_match_direct2)\n     apply(rename_tac G e x w c w' x')(*strict*)\n     apply(force)\n    apply(rename_tac G e x w c w' x')(*strict*)\n    apply(force)\n   apply(rename_tac G e x w c w' x')(*strict*)\n   apply(rule_tac\n      t=\"drop (Suc (length w + (length (rule_rpush e) + length w'))) (butlast_if_match (w @ rule_rpush e) (parser_bottom G))\"\n      and s=\"[]\"\n      in ssubst)\n    apply(rename_tac G e x w c w' x')(*strict*)\n    apply(rule drop_all)\n    apply(rule_tac\n      j=\"length ((w @ rule_rpush e))\"\n      in le_trans)\n     apply(rename_tac G e x w c w' x')(*strict*)\n     apply(rule butlast_if_match_length_le)\n    apply(rename_tac G e x w c w' x')(*strict*)\n    apply(force)\n   apply(rename_tac G e x w c w' x')(*strict*)\n   apply(force)\n  apply(rename_tac G e f x w c)(*strict*)\n  apply(simp add: prefix_def)\n  apply(clarsimp)\n  apply(rename_tac G e f x w c ca)(*strict*)\n  apply(rule_tac\n      t=\"drop (length w + length (rule_rpush e)) f\"\n      and s=\"[]\"\n      in ssubst)\n   apply(rename_tac G e f x w c ca)(*strict*)\n   apply(rule drop_all)\n   apply(rule_tac\n      t=\"length w + length (rule_rpush e)\"\n      and s=\"length (w @ rule_rpush e)\"\n      in ssubst)\n    apply(rename_tac G e f x w c ca)(*strict*)\n    apply(force)\n   apply(rename_tac G e f x w c ca)(*strict*)\n   apply(rule_tac\n      t=\"w @ rule_rpush e\"\n      and s=\"f@ca\"\n      in ssubst)\n    apply(rename_tac G e f x w c ca)(*strict*)\n    apply(force)\n   apply(rename_tac G e f x w c ca)(*strict*)\n   apply(simp (no_asm))\n  apply(rename_tac G e f x w c ca)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n      t=\"drop (length f) (butlast_if_match (w @ rule_rpush e) (parser_bottom G))\"\n      and s=\"butlast_if_match ca (parser_bottom G)\"\n      in ssubst)\n   apply(rename_tac G e f x w c ca)(*strict*)\n   apply(rule_tac\n      t=\"w @ rule_rpush e\"\n      and s=\"f@ca\"\n      in ssubst)\n    apply(rename_tac G e f x w c ca)(*strict*)\n    apply(force)\n   apply(rename_tac G e f x w c ca)(*strict*)\n   apply(rule drop_butlast_if_match_distrib)\n  apply(rename_tac G e f x w c ca)(*strict*)\n  apply(case_tac ca)\n   apply(rename_tac G e f x w c ca)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G e x w c)(*strict*)\n   apply(rule_tac\n      t=\"butlast_if_match [] (parser_bottom G)\"\n      and s=\"[]\"\n      in ssubst)\n    apply(rename_tac G e x w c)(*strict*)\n    apply(rule butlast_if_match_direct2_prime)\n    apply(force)\n   apply(rename_tac G e x w c)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"rule_rpush e\")\n    apply(rename_tac G e x w c)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G e x c)(*strict*)\n    apply(rule_tac\n      t=\"butlast_if_match [] (parser_bottom G)\"\n      and s=\"[]\"\n      in ssubst)\n     apply(rename_tac G e x c)(*strict*)\n     apply(rule butlast_if_match_direct2_prime)\n     apply(force)\n    apply(rename_tac G e x c)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G e x w c a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. rule_rpush e = w' @ [x']\")\n    apply(rename_tac G e x w c a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac G e x w c a list)(*strict*)\n   apply(thin_tac \"rule_rpush e=a#list\")\n   apply(clarsimp)\n   apply(rename_tac G e x w c w' x')(*strict*)\n   apply(rule_tac\n      t=\"butlast_if_match (w' @ [x']) (parser_bottom G)\"\n      and s=\"w'@[x']\"\n      in ssubst)\n    apply(rename_tac G e x w c w' x')(*strict*)\n    apply(rule butlast_if_match_direct2)\n     apply(rename_tac G e x w c w' x')(*strict*)\n     apply(force)\n    apply(rename_tac G e x w c w' x')(*strict*)\n    apply(force)\n   apply(rename_tac G e x w c w' x')(*strict*)\n   apply(force)\n  apply(rename_tac G e f x w c ca a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. ca = w' @ [x']\")\n   apply(rename_tac G e f x w c ca a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac G e f x w c ca a list)(*strict*)\n  apply(thin_tac \"ca=a#list\")\n  apply(clarsimp)\n  apply(rename_tac G e f x w c w' x')(*strict*)\n  apply(case_tac \"rule_rpush e\")\n   apply(rename_tac G e f x w c w' x')(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G e f x c w' x')(*strict*)\n   apply(rule_tac\n      t=\"butlast_if_match [] (parser_bottom G)\"\n      and s=\"[]\"\n      in ssubst)\n    apply(rename_tac G e f x c w' x')(*strict*)\n    apply(rule butlast_if_match_direct2_prime)\n    apply(force)\n   apply(rename_tac G e f x c w' x')(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G e f x w c w' x' a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. rule_rpush e = w' @ [x']\")\n   apply(rename_tac G e f x w c w' x' a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac G e f x w c w' x' a list)(*strict*)\n  apply(thin_tac \"rule_rpush e=a#list\")\n  apply(clarsimp)\n  apply(rename_tac G e f x w c w' w'a x'a)(*strict*)\n  apply(rule_tac\n      x=\"c@w\"\n      in exI)\n  apply(clarsimp)\n  apply(rule_tac\n      t=\"f @ butlast_if_match (w' @ [x'a]) (parser_bottom G)\"\n      and s=\"butlast_if_match (f @ w' @ [x'a]) (parser_bottom G)\"\n      in ssubst)\n   apply(rename_tac G e f x w c w' w'a x'a)(*strict*)\n   apply (metis butlast_if_match_pull_out_prime)\n  apply(rename_tac G e f x w c w' w'a x'a)(*strict*)\n  apply(rule_tac\n      t=\"w @ butlast_if_match (w'a @ [x'a]) (parser_bottom G)\"\n      and s=\"butlast_if_match (w @ w'a @ [x'a]) (parser_bottom G)\"\n      in ssubst)\n   apply(rename_tac G e f x w c w' w'a x'a)(*strict*)\n   apply (metis butlast_if_match_pull_out dropPrecise drop_Nil not_Cons_self)\n  apply(rename_tac G e f x w c w' w'a x'a)(*strict*)\n  apply(rule_tac\n      t=\"f @ w' @ [x'a]\"\n      and s=\"(f @ w')@ [x'a]\"\n      in ssubst)\n   apply(rename_tac G e f x w c w' w'a x'a)(*strict*)\n   apply(force)\n  apply(rename_tac G e f x w c w' w'a x'a)(*strict*)\n  apply(rule_tac\n      t=\"f @ w'\"\n      and s=\"w @ w'a\"\n      in ssubst)\n   apply(rename_tac G e f x w c w' w'a x'a)(*strict*)\n   apply(force)\n  apply(rename_tac G e f x w c w' w'a x'a)(*strict*)\n  apply(force)\n  done\n\ninterpretation \"parserHF\" : loc_autHF_0\n  (* TSstructure *)\n  \"valid_parser\"\n  (* configurations *)\n  \"parserHF_configurations\"\n  (* initial_configurations *)\n  \"parserHF_initial_configurations\"\n  (* step_labels *)\n  \"parser_step_labels\"\n  (* step_relation *)\n  \"parserHF_step_relation\"\n  (* effects *)\n  \"parser_markers\"\n  (* marking_condition *)\n  \"parserHF_marking_condition\"\n  (* marked_effect *)\n  \"parserHF_marked_effect\"\n  (* unmarked_effect *)\n  \"parserHF_unmarked_effect\"\n  (* destinations *)\n  \"parser_destinations\"\n  (* get_destinations *)\n  \"parserHF_get_destinations\"\n  apply(simp add: LOCALE_DEFS parser_interpretations)\n  apply(simp add: parserHF_inst_AX_initial_configuration_belongs parserHF_inst_AX_step_relation_preserves_belongs)\n  done\n\nlemma parserHF_inst_AX_effect_inclusion1: \"\n  (\\<forall>M f. parserHF_marking_condition M f \\<longrightarrow> parserHF_marked_effect M f \\<subseteq> parserHF_unmarked_effect M f)\"\n  apply(clarsimp)\n  apply(rename_tac M f x)(*strict*)\n  apply(simp add: parserHF_unmarked_effect_def parserHF_marked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac M f i e c)(*strict*)\n  apply(rule_tac\n      x=\"i\"\n      in exI)\n  apply(rule_tac\n      x=\"e\"\n      in exI)\n  apply(rule_tac\n      x=\"c\"\n      in exI)\n  apply(clarsimp)\n  done\n\nlemma parserHF_ins_lang_sound: \"\n  (\\<forall>M. valid_parser M \\<longrightarrow> parserHF.unmarked_language M \\<subseteq> parser_markers M)\"\n  apply(clarsimp)\n  apply(rename_tac M x)(*strict*)\n  apply(simp add: parserHF.unmarked_language_def parserHF_unmarked_effect_def parser_markers_def)\n  apply(clarsimp)\n  apply(rename_tac M xa d i e c)(*strict*)\n  apply(subgoal_tac \"c \\<in> parserHF_configurations M\")\n   apply(rename_tac M xa d i e c)(*strict*)\n   apply(simp add: parserHF_configurations_def)\n   apply(clarsimp)\n   apply(rename_tac M xa d i e f h l)(*strict*)\n   apply(force)\n  apply(rename_tac M xa d i e c)(*strict*)\n  apply(rule parserHF.belongs_configurations)\n   apply(rename_tac M xa d i e c)(*strict*)\n   apply(rule parserHF.derivation_initial_belongs)\n    apply(rename_tac M xa d i e c)(*strict*)\n    apply(force)\n   apply(rename_tac M xa d i e c)(*strict*)\n   apply(force)\n  apply(rename_tac M xa d i e c)(*strict*)\n  apply(force)\n  done\n\nlemma parserHF_inst_AX_marking_condition_implies_existence_of_effect: \"\n  (\\<forall>M. valid_parser M \\<longrightarrow> (\\<forall>f. parserHF.derivation_initial M f \\<longrightarrow> parserHF_marking_condition M f \\<longrightarrow> parserHF_marked_effect M f \\<noteq> {}))\"\n  apply(simp add: parserHF_marking_condition_def parserHF_marked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac M f i e c)(*strict*)\n  apply(force)\n  done\n\nlemma parserHF_inst_AX_unmarked_effect_persists: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow>\n         (\\<forall>d. ATS.derivation_initial parserHF_initial_configurations\n               parserHF_step_relation G d \\<longrightarrow>\n              (\\<forall>n. parserHF_unmarked_effect G (derivation_take d n)\n                   \\<subseteq> parserHF_unmarked_effect G d)))\"\n  apply(clarsimp)\n  apply(rename_tac G d n xa)(*strict*)\n  apply(simp add: parserHF_unmarked_effect_def derivation_take_def)\n  apply(clarsimp)\n  apply(rename_tac G d n i e c)(*strict*)\n  apply(rule_tac\n      x=\"i\"\n      in exI)\n  apply(rule_tac\n      x=\"e\"\n      in exI)\n  apply(rule_tac\n      x=\"c\"\n      in exI)\n  apply(clarsimp)\n  apply(case_tac \"i\\<le>n\")\n   apply(rename_tac G d n i e c)(*strict*)\n   apply(force)\n  apply(rename_tac G d n i e c)(*strict*)\n  apply(force)\n  done\n\nlemma parserHF_inst_ATS_axioms: \"\n  ATS_Language_axioms valid_parser parserHF_initial_configurations\n     parserHF_step_relation parser_markers parserHF_marking_condition\n     parserHF_marked_effect parserHF_unmarked_effect\"\n  apply(simp add: ATS_Language_axioms_def)\n  apply(simp add: parserHF_inst_AX_effect_inclusion1 parserHF_ins_lang_sound parserHF_inst_AX_marking_condition_implies_existence_of_effect parserHF_inst_AX_unmarked_effect_persists )\n  done\n\ninterpretation \"parserHF\" : loc_autHF_1\n  (* TSstructure *)\n  \"valid_parser\"\n  (* configurations *)\n  \"parserHF_configurations\"\n  (* initial_configurations *)\n  \"parserHF_initial_configurations\"\n  (* step_labels *)\n  \"parser_step_labels\"\n  (* step_relation *)\n  \"parserHF_step_relation\"\n  (* effects *)\n  \"parser_markers\"\n  (* marking_condition *)\n  \"parserHF_marking_condition\"\n  (* marked_effect *)\n  \"parserHF_marked_effect\"\n  (* unmarked_effect *)\n  \"parserHF_unmarked_effect\"\n  (* destinations *)\n  \"parser_destinations\"\n  (* get_destinations *)\n  \"parserHF_get_destinations\"\n  apply(simp add: LOCALE_DEFS parser_interpretations)\n  apply(simp add: parserHF_inst_AX_initial_configuration_belongs parserHF_inst_AX_step_relation_preserves_belongs )\n  apply(simp add: parserHF_inst_ATS_axioms )\n  done\n\ndefinition parserHF_set_history :: \"\n  ('stack, 'event) parserHF_conf\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> ('stack, 'event) parserHF_conf\"\n  where\n    \"parserHF_set_history c h \\<equiv>\n  c \\<lparr>parserHF_conf_history := h\\<rparr>\"\n\nlemma parserHF_inst_AX_initial_history_empty: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c. c \\<in> parserHF_initial_configurations G \\<longrightarrow> parserHF_conf_history c = []))\"\n  apply(simp add: parserHF_initial_configurations_def)\n  done\n\nlemma parserHF_inst_AX_steps_extend_history: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c. c \\<in> parserHF_configurations G \\<longrightarrow> (\\<forall>e c'. parserHF_step_relation G c e c' \\<longrightarrow> (\\<exists>hf\\<in> parser_markers G. parserHF_conf_history c' = parserHF_conf_history c @ hf))))\"\n  apply(clarsimp)\n  apply(rename_tac G c e c')(*strict*)\n  apply(subgoal_tac \"SSe \\<in> parser_step_labels SSG \\<and> SSc2 \\<in> parserHF_configurations SSG\" for SSe SSc2 SSG)\n   apply(rename_tac G c e c')(*strict*)\n   prefer 2\n   apply(rule parserHF.AX_step_relation_preserves_belongs)\n     apply(rename_tac G c e c')(*strict*)\n     apply(force)\n    apply(rename_tac G c e c')(*strict*)\n    apply(force)\n   apply(rename_tac G c e c')(*strict*)\n   apply(force)\n  apply(rename_tac G c e c')(*strict*)\n  apply(clarsimp)\n  apply(simp add: parserHF_step_relation_def parser_markers_def parser_step_labels_def)\n  apply(clarsimp)\n  apply(rename_tac G c e c' x xa)(*strict*)\n  apply(subgoal_tac \"valid_parser_step_label G e\")\n   apply(rename_tac G c e c' x xa)(*strict*)\n   prefer 2\n   apply(simp add: valid_parser_def)\n  apply(rename_tac G c e c' x xa)(*strict*)\n  apply(simp add: valid_parser_step_label_def)\n  apply(clarsimp)\n  apply(rename_tac G c e c' x xa k w xc)(*strict*)\n  apply(rule_tac\n      A=\"set (drop (length (parserHF_conf_fixed c)) (butlast_if_match (kPrefix k (w @ [parser_bottom G])) (parser_bottom G)))\"\n      in set_mp)\n   apply(rename_tac G c e c' x xa k w xc)(*strict*)\n   apply(rule_tac\n      B=\"set ((butlast_if_match (kPrefix k (w @ [parser_bottom G])) (parser_bottom G)))\"\n      in subset_trans)\n    apply(rename_tac G c e c' x xa k w xc)(*strict*)\n    apply(rule set_drop_subset)\n   apply(rename_tac G c e c' x xa k w xc)(*strict*)\n   apply(rule_tac\n      B=\"set (((kPrefix k (w @ [parser_bottom G]))))\"\n      in subset_trans)\n    apply(rename_tac G c e c' x xa k w xc)(*strict*)\n    apply(rule set_butlast_if_match_is_subset)\n   apply(rename_tac G c e c' x xa k w xc)(*strict*)\n   apply(rule set_kPrefix_subset)\n   apply(clarsimp)\n   apply(simp add: valid_parser_def)\n   apply(blast)\n  apply(rename_tac G c e c' x xa k w xc)(*strict*)\n  apply(force)\n  done\n\nlemma parserHF_inst_AX_empty_history_is_history: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> [] \\<in> parser_markers G)\"\n  apply(simp add: parser_markers_def)\n  done\n\nlemma parserHF_inst_AX_set_get_history: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c. c \\<in> parserHF_configurations G \\<longrightarrow> parserHF_set_history c (parserHF_conf_history c) = c))\"\n  apply(clarsimp)\n  apply(rename_tac G c)(*strict*)\n  apply(simp add: parserHF_set_history_def)\n  done\n\nlemma parserHF_inst_AX_get_set_history: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c. c \\<in> parserHF_configurations G \\<longrightarrow> (\\<forall>h. h \\<in> parser_markers G \\<longrightarrow> parserHF_conf_history (parserHF_set_history c h) = h)))\"\n  apply(clarsimp)\n  apply(rename_tac G c h)(*strict*)\n  apply(simp add: parserHF_set_history_def)\n  done\n\nlemma parserHF_inst_AX_join_history_fragments_closed: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>hf1. hf1 \\<in> parser_markers G \\<longrightarrow> (\\<forall>hf2. hf2 \\<in> parser_markers G \\<longrightarrow> hf1 @ hf2 \\<in> parser_markers G)))\"\n  apply(clarsimp)\n  apply(rename_tac G hf1 hf2)(*strict*)\n  apply(simp add: parser_markers_def)\n  done\n\nlemma parserHF_inst_AX_get_history_closed: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c. c \\<in> parserHF_configurations G \\<longrightarrow> parserHF_conf_history c \\<in> parser_markers G))\"\n  apply(clarsimp)\n  apply(rename_tac G c)(*strict*)\n  apply(simp add: parser_markers_def parserHF_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac G x f h l)(*strict*)\n  apply(force)\n  done\n\nlemma parserHF_inst_AX_mutual_prefix: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>hf1. hf1 \\<in> parser_markers G \\<longrightarrow> (\\<forall>hf2. hf2 \\<in> parser_markers G \\<longrightarrow> (\\<forall>hf3. hf3 \\<in> parser_markers G \\<longrightarrow> (\\<forall>hf4. hf4 \\<in> parser_markers G \\<longrightarrow> hf1 @ hf2 = hf3 @ hf4 \\<longrightarrow> (\\<exists>hf\\<in> parser_markers G. hf1 @ hf = hf3) \\<or> (\\<exists>hf\\<in> parser_markers G. hf3 @ hf = hf1))))))\"\n  apply(clarsimp)\n  apply(rename_tac G hf1 hf2 hf3 hf4)(*strict*)\n  apply(simp add: parser_markers_def parserHF_configurations_def)\n  apply(subgoal_tac \"prefix hf1 hf3 \\<or> prefix hf3 hf1\")\n   apply(rename_tac G hf1 hf2 hf3 hf4)(*strict*)\n   prefer 2\n   apply(rule mutual_prefix_prefix)\n   apply(force)\n  apply(rename_tac G hf1 hf2 hf3 hf4)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac G hf1 hf2 hf3 hf4)(*strict*)\n   apply(simp add: prefix_def)\n   apply(clarsimp)\n  apply(rename_tac G hf1 hf2 hf3 hf4)(*strict*)\n  apply(simp add: prefix_def)\n  apply(clarsimp)\n  apply(rename_tac G hf2 hf3 c)(*strict*)\n  apply(force)\n  done\n\nlemma parserHF_inst_ATS_History_axioms: \"\n  ATS_History_axioms valid_parser parserHF_configurations\n     parserHF_initial_configurations parserHF_step_relation parser_markers\n     parser_markers parser_empty_history parser_empty_history_fragment\n     parserHF_set_history (@) (@) parserHF_conf_history\"\n  apply(simp add: ATS_History_axioms_def)\n  apply(simp add: parserHF_inst_AX_initial_history_empty parserHF_inst_AX_steps_extend_history parserHF_inst_AX_empty_history_is_history parserHF_inst_AX_set_get_history parserHF_inst_AX_get_set_history parserHF_inst_AX_join_history_fragments_closed parserHF_inst_AX_get_history_closed parserHF_inst_AX_mutual_prefix )\n  done\n\ninterpretation \"parserHF\" : loc_autHF_2\n  (* TSstructure *)\n  \"valid_parser\"\n  (* configurations *)\n  \"parserHF_configurations\"\n  (* initial_configurations *)\n  \"parserHF_initial_configurations\"\n  (* step_labels *)\n  \"parser_step_labels\"\n  (* step_relation *)\n  \"parserHF_step_relation\"\n  (* effects *)\n  \"parser_markers\"\n  (* marking_condition *)\n  \"parserHF_marking_condition\"\n  (* marked_effect *)\n  \"parserHF_marked_effect\"\n  (* unmarked_effect *)\n  \"parserHF_unmarked_effect\"\n  (* destinations *)\n  \"parser_destinations\"\n  (* get_destinations *)\n  \"parserHF_get_destinations\"\n  (* histories *)\n  \"parser_markers\"\n  (* history_fragments *)\n  \"parser_markers\"\n  (* empty_history *)\n  \"parser_empty_history\"\n  (* empty_history_fragment *)\n  \"parser_empty_history_fragment\"\n  (* set_history *)\n  \"parserHF_set_history\"\n  (* extend_history *)\n  \"append\"\n  (* join_history_fragments *)\n  \"append\"\n  (* get_history *)\n  \"parserHF_conf_history\"\n  apply(simp add: LOCALE_DEFS parser_interpretations)\n  apply(simp add: parserHF_inst_AX_initial_configuration_belongs parserHF_inst_AX_step_relation_preserves_belongs )\n  apply(simp add: parserHF_inst_ATS_axioms parserHF_inst_ATS_History_axioms )\n  done\n\nlemma parserHF_inst_lang_finite: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> parserHF.finite_marked_language G = parserHF.marked_language G)\"\n  apply(clarsimp)\n  apply(rename_tac G)(*strict*)\n  apply(simp add: parserHF.finite_marked_language_def parserHF.marked_language_def)\n  apply(rule order_antisym)\n   apply(rename_tac G)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G x d n)(*strict*)\n   apply(rule_tac\n      x=\"d\"\n      in exI)\n   apply(clarsimp)\n   apply(simp add: parserHF.derivation_initial_def)\n  apply(rename_tac G)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G x d)(*strict*)\n  apply(simp add: parserHF_marked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G d i e c)(*strict*)\n  apply(rule_tac\n      x=\"derivation_take d i\"\n      in exI)\n  apply(rule context_conjI)\n   apply(rename_tac G d i e c)(*strict*)\n   apply(rule parserHF.derivation_take_preserves_derivation_initial)\n   apply(force)\n  apply(rename_tac G d i e c)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G d i e c)(*strict*)\n   apply(rule_tac\n      x=\"i\"\n      in exI)\n   apply(rule_tac\n      x=\"e\"\n      in exI)\n   apply(rule_tac\n      x=\"c\"\n      in exI)\n   apply(clarsimp)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac G d i e c)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G d i e c)(*strict*)\n   apply(simp add: parserHF_marking_condition_def)\n   apply(rule_tac\n      x=\"i\"\n      in exI)\n   apply(rule_tac\n      x=\"e\"\n      in exI)\n   apply(rule_tac\n      x=\"c\"\n      in exI)\n   apply(clarsimp)\n   apply(rename_tac G d i e c ia ea ca)(*strict*)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac G d i e c)(*strict*)\n  apply(rule_tac\n      x=\"i\"\n      in exI)\n  apply(rule maximum_of_domain_derivation_take)\n  apply(force)\n  done\n\nlemma parserHF_inst_AX_unmarked_language_finite: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> parserHF.finite_unmarked_language G = parserHF.unmarked_language G)\"\n  apply(clarsimp)\n  apply(rename_tac G)(*strict*)\n  apply(simp add: parserHF.finite_unmarked_language_def parserHF.unmarked_language_def)\n  apply(rule order_antisym)\n   apply(rename_tac G)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G x d n)(*strict*)\n   apply(rule_tac\n      x=\"d\"\n      in exI)\n   apply(clarsimp)\n   apply(simp add: parserHF.derivation_initial_def)\n  apply(rename_tac G)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G x d)(*strict*)\n  apply(simp add: parserHF_unmarked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G d i e c)(*strict*)\n  apply(rule_tac\n      x=\"derivation_take d i\"\n      in exI)\n  apply(rule context_conjI)\n   apply(rename_tac G d i e c)(*strict*)\n   apply(rule parserHF.derivation_take_preserves_derivation_initial)\n   apply(force)\n  apply(rename_tac G d i e c)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G d i e c)(*strict*)\n   apply(rule_tac\n      x=\"i\"\n      in exI)\n   apply(rule_tac\n      x=\"e\"\n      in exI)\n   apply(rule_tac\n      x=\"c\"\n      in exI)\n   apply(clarsimp)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac G d i e c)(*strict*)\n  apply(rule_tac\n      x=\"i\"\n      in exI)\n  apply(rule maximum_of_domain_derivation_take)\n  apply(force)\n  done\n\ndefinition parserHF_get_fixed_scheduler_DB :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> (('stack, 'event) parser_step_label, ('stack, 'event) parserHF_conf) derivation\n  \\<Rightarrow> nat\n  \\<Rightarrow> 'event list\"\n  where\n    \"parserHF_get_fixed_scheduler_DB G d n \\<equiv>\n  parserHF_conf_fixed (the (get_configuration (d n)))\"\n\nlemma parserHF_inst_AX_fixed_scheduler_extendable_translates_backwards: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c1. c1 \\<in> parserHF_configurations G \\<longrightarrow> (\\<forall>e c2. parserHF_step_relation G c1 e c2 \\<longrightarrow> \\<not> parserHF_conf_fixed c2 \\<sqsupseteq> [parser_bottom G] \\<longrightarrow> \\<not> parserHF_conf_fixed c1 \\<sqsupseteq> [parser_bottom G])))\"\n  apply(clarsimp)\n  apply(rename_tac G c1 e c2)(*strict*)\n  apply(subgoal_tac \"valid_parser_step_label G e\")\n   apply(rename_tac G c1 e c2)(*strict*)\n   prefer 2\n   apply(simp add: parserHF_step_relation_def valid_parser_def)\n  apply(rename_tac G c1 e c2)(*strict*)\n  apply(subgoal_tac \"c2 \\<in> parserHF_configurations G\")\n   apply(rename_tac G c1 e c2)(*strict*)\n   prefer 2\n   apply(rule parserHF.AX_step_relation_preserves_belongsC)\n     apply(rename_tac G c1 e c2)(*strict*)\n     apply(force)\n    apply(rename_tac G c1 e c2)(*strict*)\n    apply(force)\n   apply(rename_tac G c1 e c2)(*strict*)\n   apply(force)\n  apply(rename_tac G c1 e c2)(*strict*)\n  apply(simp add: valid_parser_step_label_def suffix_def parserHF_configurations_def parserHF_step_relation_def prefix_def)\n  apply(clarsimp)\n  apply(rename_tac G e c k w xa ca cb xb)(*strict*)\n  apply(case_tac \"length (kPrefix k (w @ [parser_bottom G])) - length c\")\n   apply(rename_tac G e c k w xa ca cb xb)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G e c k w xa ca cb xb nat)(*strict*)\n  apply(clarsimp)\n  apply(simp add: kPrefix_def)\n  apply(case_tac \"k-length w\")\n   apply(rename_tac G e c k w xa ca cb xb nat)(*strict*)\n   prefer 2\n   apply(rename_tac G e c k w xa ca cb xb nat nata)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G e c k w xa ca cb xb nat nata x)(*strict*)\n   apply(erule_tac\n      x=\"x\"\n      in allE)\n   apply(force)\n  apply(rename_tac G e c k w xa ca cb xb nat)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"min (length w) k = k\")\n   apply(rename_tac G e c k w xa ca cb xb nat)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G e c k w xa ca cb xb nat)(*strict*)\n  apply(clarsimp)\n  apply(thin_tac \"min (length w) k = k\")\n  apply(erule disjE)\n   apply(rename_tac G e c k w xa ca cb xb nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G e c k w xa ca cb xb nat cc)(*strict*)\n   apply(case_tac cc)\n    apply(rename_tac G e c k w xa ca cb xb nat cc)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G e c k w xa ca cb xb nat x)(*strict*)\n    apply(erule_tac\n      x=\"x\"\n      in allE)\n    apply(force)\n   apply(rename_tac G e c k w xa ca cb xb nat cc a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. cc = w' @ [x']\")\n    apply(rename_tac G e c k w xa ca cb xb nat cc a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac G e c k w xa ca cb xb nat cc a list)(*strict*)\n   apply(thin_tac \"cc = a # list\")\n   apply(clarsimp)\n  apply(rename_tac G e c k w xa ca cb xb nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G e c k w xa ca cb xb nat cc)(*strict*)\n  apply(subgoal_tac \"parser_bottom G \\<in> set w\")\n   apply(rename_tac G e c k w xa ca cb xb nat cc)(*strict*)\n   apply(subgoal_tac \"parser_bottom G \\<notin> set w\")\n    apply(rename_tac G e c k w xa ca cb xb nat cc)(*strict*)\n    apply(force)\n   apply(rename_tac G e c k w xa ca cb xb nat cc)(*strict*)\n   apply(rule_tac\n      A=\"parser_events G\"\n      in not_in_diff)\n   apply(force)\n  apply(rename_tac G e c k w xa ca cb xb nat cc)(*strict*)\n  apply(rule_tac\n      A=\"set(take k w)\"\n      in set_mp)\n   apply(rename_tac G e c k w xa ca cb xb nat cc)(*strict*)\n   apply(rule set_take_subset)\n  apply(rename_tac G e c k w xa ca cb xb nat cc)(*strict*)\n  apply(rule_tac\n      t=\"take k w\"\n      and s=\"c @ [parser_bottom G] @ cc\"\n      in ssubst)\n   apply(rename_tac G e c k w xa ca cb xb nat cc)(*strict*)\n   apply(force)\n  apply(rename_tac G e c k w xa ca cb xb nat cc)(*strict*)\n  apply(simp (no_asm))\n  done\n\nlemma parserHF_inst_AX_get_fixed_scheduler_DB_in_fixed_schedulers: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d. parserHF.derivation G d \\<longrightarrow> parserHF.belongs G d \\<longrightarrow> (\\<forall>n. (\\<exists>y. d n = Some y) \\<longrightarrow> parserHF_get_fixed_scheduler_DB G d n \\<in> parser_fixed_schedulers G)))\"\n  apply(clarsimp)\n  apply(rename_tac G d n y)(*strict*)\n  apply(simp add: parserHF_get_fixed_scheduler_DB_def)\n  apply(simp add: parser_fixed_schedulers_def)\n  apply(case_tac y)\n  apply(rename_tac G d n y option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G d n option b)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(subgoal_tac \"b \\<in> parserHF_configurations G\")\n   apply(rename_tac G d n option b)(*strict*)\n   prefer 2\n   apply (metis parserHF.belongs_configurations)\n  apply(rename_tac G d n option b)(*strict*)\n  apply(simp add: parserHF_configurations_def parser_schedulers_def prefix_closure_def prefix_def)\n  apply(clarsimp)\n  apply(rename_tac G d n option f h l)(*strict*)\n  apply(case_tac \"parser_bottom G \\<in> set f\")\n   apply(rename_tac G d n option f h l)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G d n option h l w)(*strict*)\n   apply(rule_tac\n      x=\"w @ [parser_bottom G]\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac G d n option f h l)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n      x=\"f @ [parser_bottom G]\"\n      in exI)\n  apply(clarsimp)\n  done\n\nlemma parserHF_inst_AX_get_fixed_scheduler_DB_restrict: \"\n  \\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>x n. x \\<le> n \\<longrightarrow> (\\<forall>d1. parserHF.derivation G d1 \\<longrightarrow> (\\<forall>d2. parserHF_get_fixed_scheduler_DB G (derivation_append d1 d2 n) x = parserHF_get_fixed_scheduler_DB G d1 x)))\"\n  apply(clarsimp)\n  apply(rename_tac G x n d1 d2)(*strict*)\n  apply(simp add: derivation_append_def parserHF_get_fixed_scheduler_DB_def)\n  done\n\nlemma parserHF_inst_ATS_SchedF_SB_axioms: \"\n  ATS_SchedF_SB_axioms valid_parser parserHF_configurations\n     parserHF_step_relation parser_fixed_scheduler_extendable\n     parserHF_conf_fixed\"\n  apply(simp add: ATS_SchedF_SB_axioms_def)\n  apply(simp add: parserHF_inst_AX_fixed_scheduler_extendable_translates_backwards )\n  done\n\ninterpretation \"parserHF\" : loc_autHF_3\n  (* TSstructure *)\n  \"valid_parser\"\n  (* configurations *)\n  \"parserHF_configurations\"\n  (* initial_configurations *)\n  \"parserHF_initial_configurations\"\n  (* step_labels *)\n  \"parser_step_labels\"\n  (* step_relation *)\n  \"parserHF_step_relation\"\n  (* effects *)\n  \"parser_markers\"\n  (* marking_condition *)\n  \"parserHF_marking_condition\"\n  (* marked_effect *)\n  \"parserHF_marked_effect\"\n  (* unmarked_effect *)\n  \"parserHF_unmarked_effect\"\n  (* destinations *)\n  \"parser_destinations\"\n  (* get_destinations *)\n  \"parserHF_get_destinations\"\n  (* histories *)\n  \"parser_markers\"\n  (* history_fragments *)\n  \"parser_markers\"\n  (* empty_history *)\n  \"parser_empty_history\"\n  (* empty_history_fragment *)\n  \"parser_empty_history_fragment\"\n  (* set_history *)\n  \"parserHF_set_history\"\n  (* extend_history *)\n  \"append\"\n  (* join_history_fragments *)\n  \"append\"\n  (* get_history *)\n  \"parserHF_conf_history\"\n  (* fixed_schedulers *)\n  \"parser_fixed_schedulers\"\n  (* empty_fixed_scheduler *)\n  \"parser_empty_fixed_scheduler\"\n  (* fixed_scheduler_extendable *)\n  \"parser_fixed_scheduler_extendable\"\n  (* get_fixed_scheduler *)\n  \"parserHF_conf_fixed\"\n  apply(simp add: LOCALE_DEFS parser_interpretations)\n  apply(simp add: parserHF_inst_AX_initial_configuration_belongs parserHF_inst_AX_step_relation_preserves_belongs )\n  apply(simp add: parserHF_inst_ATS_axioms parserHF_inst_ATS_History_axioms parserHF_inst_ATS_SchedF_SB_axioms )\n  done\n\nlemma parserHF_inst_AX_schedF_db_extendable_translates_backwards: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d1. parserHF.derivation G d1 \\<longrightarrow> parserHF.belongs G d1 \\<longrightarrow> (\\<forall>n x. (\\<exists>y. d1 (n + x) = Some y) \\<longrightarrow> \\<not> parserHF_get_fixed_scheduler_DB G d1 (n + x) \\<sqsupseteq> [parser_bottom G] \\<longrightarrow> \\<not> parserHF_get_fixed_scheduler_DB G d1 n \\<sqsupseteq> [parser_bottom G])))\"\n  apply(clarsimp)\n  apply(rename_tac G d1 n x y)(*strict*)\n  apply(simp add: parserHF_get_fixed_scheduler_DB_def)\n  apply(subgoal_tac \"\\<exists>e c. d1 n= Some (pair e c)\")\n   apply(rename_tac G d1 n x y)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G d1 n x y e c)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(case_tac y)\n   apply(rename_tac G d1 n x y e c option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G d1 n x e c option b)(*strict*)\n   apply(subgoal_tac \"\\<not> parserHF_conf_fixed c \\<sqsupseteq> [parser_bottom G]\")\n    apply(rename_tac G d1 n x e c option b)(*strict*)\n    prefer 2\n    apply(fold parser_fixed_scheduler_extendable_def)\n    apply(rule parserHF.fixed_scheduler_extendable_translates_backwards_lift)\n          apply(rename_tac G d1 n x e c option b)(*strict*)\n          apply(force)\n         apply(rename_tac G d1 n x e c option b)(*strict*)\n         apply(force)\n        apply(rename_tac G d1 n x e c option b)(*strict*)\n        apply (metis parserHF.belongs_configurations)\n       apply(rename_tac G d1 n x e c option b)(*strict*)\n       apply(force)\n      apply(rename_tac G d1 n x e c option b)(*strict*)\n      apply(force)\n     apply(rename_tac G d1 n x e c option b)(*strict*)\n     apply(force)\n    apply(rename_tac G d1 n x e c option b)(*strict*)\n    apply(force)\n   apply(rename_tac G d1 n x e c option b)(*strict*)\n   apply(force)\n  apply(rename_tac G d1 n x y)(*strict*)\n  apply(rule_tac\n      m=\"n+x\"\n      in parserHF.pre_some_position_is_some_position)\n    apply(rename_tac G d1 n x y)(*strict*)\n    apply(force)\n   apply(rename_tac G d1 n x y)(*strict*)\n   apply(force)\n  apply(rename_tac G d1 n x y)(*strict*)\n  apply(force)\n  done\n\nlemma parserHF_inst_AX_state_based_vs_derivation_based_get_fixed_scheduler: \"\n  \\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d. parserHF.derivation_initial G d \\<longrightarrow> (\\<forall>n e c. d n = Some (pair e c) \\<longrightarrow> parserHF_get_fixed_scheduler_DB G d n = parserHF_conf_fixed c))\"\n  apply(clarsimp)\n  apply(rename_tac G d n e c)(*strict*)\n  apply(simp add: parserHF_get_fixed_scheduler_DB_def)\n  apply(simp add: get_configuration_def)\n  done\n\nlemma parserHF_inst_AX_history_no_mod_after_nonextendable_fixed_sched: \"\n  \\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c. parserHF_conf_fixed c \\<sqsupseteq> [parser_bottom G] \\<longrightarrow> c \\<in> parserHF_configurations G \\<longrightarrow> (\\<forall>e c'. parserHF_step_relation G c e c' \\<longrightarrow> parserHF_conf_history c = parserHF_conf_history c'))\"\n  apply(clarsimp)\n  apply(rename_tac G c e c')(*strict*)\n  apply(simp add: parserHF_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac G c e c' x)(*strict*)\n  apply(simp add: prefix_def suffix_def)\n  apply(clarsimp)\n  apply(rename_tac G c e c' x ca)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac G c e c' x ca)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G c e c' x ca cb)(*strict*)\n   apply (metis append_length_inc drop_entire_butlast_if_match drop_eq_Nil length_Suc)\n  apply(rename_tac G c e c' x ca)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G c e c' x ca cb)(*strict*)\n  apply(subgoal_tac \"cb=[]\")\n   apply(rename_tac G c e c' x ca cb)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G c e c' x ca)(*strict*)\n   apply (metis butlast_if_match_length_le length_Suc)\n  apply(rename_tac G c e c' x ca cb)(*strict*)\n  apply(subgoal_tac \"valid_parser_step_label G e\")\n   apply(rename_tac G c e c' x ca cb)(*strict*)\n   prefer 2\n   apply(simp add: valid_parser_def)\n  apply(rename_tac G c e c' x ca cb)(*strict*)\n  apply(simp add: valid_parser_step_label_def)\n  apply(clarsimp)\n  apply(rename_tac G c e c' x ca cb k w xb)(*strict*)\n  apply(simp add: kPrefix_def)\n  apply(case_tac \"k-length w\")\n   apply(rename_tac G c e c' x ca cb k w xb)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"parser_bottom G \\<in> set w\")\n    apply(rename_tac G c e c' x ca cb k w xb)(*strict*)\n    apply(force)\n   apply(rename_tac G c e c' x ca cb k w xb)(*strict*)\n   apply (metis Cons_eq_appendI append_Nil append_eq_appendI append_self_conv butlast_if_match_direct butlast_if_match_direct2_prime in_set_takeD kPrefix_def list.simps(2) take_append_prime)\n  apply(rename_tac G c e c' x ca cb k w xb nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G c e c' x ca cb k w xb nat xa)(*strict*)\n  apply(case_tac cb)\n   apply(rename_tac G c e c' x ca cb k w xb nat xa)(*strict*)\n   apply(force)\n  apply(rename_tac G c e c' x ca cb k w xb nat xa a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. cb = w' @ [x']\")\n   apply(rename_tac G c e c' x ca cb k w xb nat xa a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac G c e c' x ca cb k w xb nat xa a list)(*strict*)\n  apply(thin_tac \"cb=a#list\")\n  apply(clarsimp)\n  done\n\nlemma parserHF_inst_ATS_SchedF_DB_axioms: \"\n  ATS_SchedF_DB_axioms valid_parser parserHF_configurations\n     parser_step_labels parserHF_step_relation parser_fixed_schedulers\n     parser_fixed_scheduler_extendable parserHF_get_fixed_scheduler_DB\"\n  apply(simp add: ATS_SchedF_DB_axioms_def)\n  apply(simp add: parserHF_inst_AX_get_fixed_scheduler_DB_in_fixed_schedulers parserHF_inst_AX_fixed_scheduler_extendable_translates_backwards parserHF_inst_AX_get_fixed_scheduler_DB_restrict parserHF_inst_AX_schedF_db_extendable_translates_backwards )\n  done\n\nlemma parserHF_inst_ATS_SchedF_SDB_axioms: \"\n  ATS_SchedF_SDB_axioms valid_parser parserHF_initial_configurations parserHF_step_relation parserHF_conf_fixed parserHF_get_fixed_scheduler_DB\"\n  apply(simp add: ATS_SchedF_SDB_axioms_def)\n  apply(simp add: parserHF_inst_AX_state_based_vs_derivation_based_get_fixed_scheduler )\n  done\n\nlemma parserHF_inst_ATS_determHIST_SB_axioms: \"\n  ATS_determHIST_SB_axioms valid_parser parserHF_configurations\n     parserHF_step_relation parserHF_conf_history\n     parser_fixed_scheduler_extendable parserHF_conf_fixed\"\n  apply(simp add: ATS_determHIST_SB_axioms_def)\n  apply(simp add: parserHF_inst_AX_history_no_mod_after_nonextendable_fixed_sched )\n  done\n\ninterpretation \"parserHF\" : loc_autHF_6\n  (* TSstructure *)\n  \"valid_parser\"\n  (* configurations *)\n  \"parserHF_configurations\"\n  (* initial_configurations *)\n  \"parserHF_initial_configurations\"\n  (* step_labels *)\n  \"parser_step_labels\"\n  (* step_relation *)\n  \"parserHF_step_relation\"\n  (* effects *)\n  \"parser_markers\"\n  (* marking_condition *)\n  \"parserHF_marking_condition\"\n  (* marked_effect *)\n  \"parserHF_marked_effect\"\n  (* unmarked_effect *)\n  \"parserHF_unmarked_effect\"\n  (* destinations *)\n  \"parser_destinations\"\n  (* get_destinations *)\n  \"parserHF_get_destinations\"\n  (* histories *)\n  \"parser_markers\"\n  (* history_fragments *)\n  \"parser_markers\"\n  (* empty_history *)\n  \"parser_empty_history\"\n  (* empty_history_fragment *)\n  \"parser_empty_history_fragment\"\n  (* set_history *)\n  \"parserHF_set_history\"\n  (* extend_history *)\n  \"append\"\n  (* join_history_fragments *)\n  \"append\"\n  (* get_history *)\n  \"parserHF_conf_history\"\n  (* fixed_schedulers *)\n  \"parser_fixed_schedulers\"\n  (* empty_fixed_scheduler *)\n  \"parser_empty_fixed_scheduler\"\n  (* fixed_scheduler_extendable *)\n  \"parser_fixed_scheduler_extendable\"\n  (* get_fixed_scheduler *)\n  \"parserHF_conf_fixed\"\n  (* get_fixed_scheduler_DB *)\n  \"parserHF_get_fixed_scheduler_DB\"\n  apply(simp add: LOCALE_DEFS parser_interpretations)\n  apply(simp add: parserHF_inst_AX_initial_configuration_belongs parserHF_inst_AX_step_relation_preserves_belongs )\n  apply(simp add: parserHF_inst_ATS_axioms parserHF_inst_ATS_History_axioms parserHF_inst_ATS_SchedF_SB_axioms parserHF_inst_ATS_SchedF_DB_axioms parserHF_inst_ATS_SchedF_SDB_axioms parserHF_inst_ATS_determHIST_SB_axioms )\n  done\n\nlemma parserHF_inst_ATS_Language_by_Finite_Derivations_axioms: \"\n  ATS_Language_by_Finite_Derivations_axioms valid_parser\n     parserHF_initial_configurations parserHF_step_relation\n     parserHF_marking_condition parserHF_marked_effect\n     parserHF_unmarked_effect\"\n  apply(simp add: ATS_Language_by_Finite_Derivations_axioms_def)\n  apply(simp add: parserHF_inst_lang_finite parserHF_inst_AX_unmarked_language_finite )\n  done\n\ninterpretation \"parserHF\" : loc_autHF_7\n  (* TSstructure *)\n  \"valid_parser\"\n  (* configurations *)\n  \"parserHF_configurations\"\n  (* initial_configurations *)\n  \"parserHF_initial_configurations\"\n  (* step_labels *)\n  \"parser_step_labels\"\n  (* step_relation *)\n  \"parserHF_step_relation\"\n  (* effects *)\n  \"parser_markers\"\n  (* marking_condition *)\n  \"parserHF_marking_condition\"\n  (* marked_effect *)\n  \"parserHF_marked_effect\"\n  (* unmarked_effect *)\n  \"parserHF_unmarked_effect\"\n  (* destinations *)\n  \"parser_destinations\"\n  (* get_destinations *)\n  \"parserHF_get_destinations\"\n  (* histories *)\n  \"parser_markers\"\n  (* history_fragments *)\n  \"parser_markers\"\n  (* empty_history *)\n  \"parser_empty_history\"\n  (* empty_history_fragment *)\n  \"parser_empty_history_fragment\"\n  (* set_history *)\n  \"parserHF_set_history\"\n  (* extend_history *)\n  \"append\"\n  (* join_history_fragments *)\n  \"append\"\n  (* get_history *)\n  \"parserHF_conf_history\"\n  (* fixed_schedulers *)\n  \"parser_fixed_schedulers\"\n  (* empty_fixed_scheduler *)\n  \"parser_empty_fixed_scheduler\"\n  (* fixed_scheduler_extendable *)\n  \"parser_fixed_scheduler_extendable\"\n  (* get_fixed_scheduler *)\n  \"parserHF_conf_fixed\"\n  (* get_fixed_scheduler_DB *)\n  \"parserHF_get_fixed_scheduler_DB\"\n  apply(simp add: LOCALE_DEFS parser_interpretations)\n  apply(simp add: parserHF_inst_AX_initial_configuration_belongs parserHF_inst_AX_step_relation_preserves_belongs )\n  apply(simp add: parserHF_inst_ATS_axioms parserHF_inst_ATS_History_axioms parserHF_inst_ATS_SchedF_SB_axioms parserHF_inst_ATS_SchedF_DB_axioms parserHF_inst_ATS_SchedF_SDB_axioms parserHF_inst_ATS_determHIST_SB_axioms parserHF_inst_ATS_Language_by_Finite_Derivations_axioms )\n  done\n\nlemma parserHF_inst_AX_is_forward_target_deterministic_correspond_SB: \"\n  \\<forall>G. valid_parser G \\<longrightarrow> parserHF.is_forward_target_deterministic_accessible G = ATS_determHIST_SB.is_forward_target_deterministicHist_SB_long parserHF_initial_configurations parserHF_step_relation parser_markers (@) (@) parserHF_conf_history parser_fixed_scheduler_extendable parserHF_conf_fixed G\"\n  apply(clarsimp)\n  apply(rename_tac G)(*strict*)\n  apply(rule order_antisym)\n   apply(rename_tac G)(*strict*)\n   apply(clarsimp)\n   apply(rule parserHF.is_forward_target_deterministic_accessible_implies_is_forward_target_deterministicHist_SB_long)\n    apply(rename_tac G)(*strict*)\n    apply(force)\n   apply(rename_tac G)(*strict*)\n   apply(force)\n  apply(rename_tac G)(*strict*)\n  apply(clarsimp)\n  apply(simp add: parserHF.is_forward_target_deterministic_accessible_def)\n  apply(simp add: parserHF.is_forward_target_deterministicHist_SB_long_def)\n  apply(clarsimp)\n  apply(rename_tac G c c1 c2 e)(*strict*)\n  apply(erule_tac\n      x=\"c\"\n      in ballE)\n   apply(rename_tac G c c1 c2 e)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G c c1 c2 e)(*strict*)\n  apply(erule_tac\n      x=\"c1\"\n      in allE)\n  apply(erule_tac\n      x=\"c2\"\n      in allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"e\"\n      in allE)\n  apply(clarsimp)\n  apply(simp add: parserHF_step_relation_def)\n  apply(clarsimp)\n  done\n\nlemma parserHF_inst_ATS_HistoryCT_SB_axioms: \"\n  ATS_HistoryCT_SB_axioms valid_parser parserHF_initial_configurations parserHF_step_relation parser_markers (@) (@) parserHF_conf_history parser_fixed_scheduler_extendable parserHF_conf_fixed\"\n  apply(simp add: ATS_HistoryCT_SB_axioms_def)\n  apply(simp add: parserHF_inst_AX_is_forward_target_deterministic_correspond_SB )\n  done\n\ninterpretation \"parserHF\" : loc_autHF_8\n  (* TSstructure *)\n  \"valid_parser\"\n  (* configurations *)\n  \"parserHF_configurations\"\n  (* initial_configurations *)\n  \"parserHF_initial_configurations\"\n  (* step_labels *)\n  \"parser_step_labels\"\n  (* step_relation *)\n  \"parserHF_step_relation\"\n  (* effects *)\n  \"parser_markers\"\n  (* marking_condition *)\n  \"parserHF_marking_condition\"\n  (* marked_effect *)\n  \"parserHF_marked_effect\"\n  (* unmarked_effect *)\n  \"parserHF_unmarked_effect\"\n  (* destinations *)\n  \"parser_destinations\"\n  (* get_destinations *)\n  \"parserHF_get_destinations\"\n  (* histories *)\n  \"parser_markers\"\n  (* history_fragments *)\n  \"parser_markers\"\n  (* empty_history *)\n  \"parser_empty_history\"\n  (* empty_history_fragment *)\n  \"parser_empty_history_fragment\"\n  (* set_history *)\n  \"parserHF_set_history\"\n  (* extend_history *)\n  \"append\"\n  (* join_history_fragments *)\n  \"append\"\n  (* get_history *)\n  \"parserHF_conf_history\"\n  (* fixed_schedulers *)\n  \"parser_fixed_schedulers\"\n  (* empty_fixed_scheduler *)\n  \"parser_empty_fixed_scheduler\"\n  (* fixed_scheduler_extendable *)\n  \"parser_fixed_scheduler_extendable\"\n  (* get_fixed_scheduler *)\n  \"parserHF_conf_fixed\"\n  (* get_fixed_scheduler_DB *)\n  \"parserHF_get_fixed_scheduler_DB\"\n  apply(simp add: LOCALE_DEFS parser_interpretations)\n  apply(simp add: parserHF_inst_AX_initial_configuration_belongs parserHF_inst_AX_step_relation_preserves_belongs )\n  apply(simp add: parserHF_inst_ATS_axioms parserHF_inst_ATS_History_axioms parserHF_inst_ATS_SchedF_SB_axioms parserHF_inst_ATS_SchedF_DB_axioms parserHF_inst_ATS_SchedF_SDB_axioms parserHF_inst_ATS_determHIST_SB_axioms parserHF_inst_ATS_Language_by_Finite_Derivations_axioms parserHF_inst_ATS_HistoryCT_SB_axioms )\n  done\n\nlemma parserHF_inst_AX_is_forward_target_deterministic_correspond_DB: \"\n  \\<forall>G. valid_parser G \\<longrightarrow> parserHF.is_forward_target_deterministic_accessible G = ATS_determHIST_DB.is_forward_target_deterministicHist_DB_long parserHF_initial_configurations parserHF_step_relation parser_markers (@) (@) parserHF_conf_history parser_fixed_scheduler_extendable parserHF_get_fixed_scheduler_DB G\"\n  apply(clarsimp)\n  apply(rename_tac G)(*strict*)\n  apply(rule order_antisym)\n   apply(rename_tac G)(*strict*)\n   apply(clarsimp)\n   apply(rule parserHF.is_forward_target_deterministic_accessible_implies_is_forward_target_deterministicHist_DB_long)\n    apply(rename_tac G)(*strict*)\n    apply(force)\n   apply(rename_tac G)(*strict*)\n   apply(force)\n  apply(rename_tac G)(*strict*)\n  apply(clarsimp)\n  apply(simp add: parserHF.is_forward_target_deterministic_accessible_def)\n  apply(simp add: parserHF.is_forward_target_deterministicHist_DB_long_def)\n  apply(clarsimp)\n  apply(rename_tac G c c1 c2 e)(*strict*)\n  apply(simp add: parserHF_step_relation_def)\n  apply(clarsimp)\n  done\n\nlemma parserHF_inst_ATS_HistoryCT_DB_axioms: \"\n  ATS_HistoryCT_DB_axioms valid_parser parserHF_initial_configurations parserHF_step_relation parser_markers (@) (@) parserHF_conf_history parser_fixed_scheduler_extendable parserHF_get_fixed_scheduler_DB\"\n  apply(simp add: ATS_HistoryCT_DB_axioms_def)\n  apply(simp add: parserHF_inst_AX_is_forward_target_deterministic_correspond_DB )\n  done\n\ninterpretation \"parserHF\" : loc_autHF_9\n  (* TSstructure *)\n  \"valid_parser\"\n  (* configurations *)\n  \"parserHF_configurations\"\n  (* initial_configurations *)\n  \"parserHF_initial_configurations\"\n  (* step_labels *)\n  \"parser_step_labels\"\n  (* step_relation *)\n  \"parserHF_step_relation\"\n  (* effects *)\n  \"parser_markers\"\n  (* marking_condition *)\n  \"parserHF_marking_condition\"\n  (* marked_effect *)\n  \"parserHF_marked_effect\"\n  (* unmarked_effect *)\n  \"parserHF_unmarked_effect\"\n  (* destinations *)\n  \"parser_destinations\"\n  (* get_destinations *)\n  \"parserHF_get_destinations\"\n  (* histories *)\n  \"parser_markers\"\n  (* history_fragments *)\n  \"parser_markers\"\n  (* empty_history *)\n  \"parser_empty_history\"\n  (* empty_history_fragment *)\n  \"parser_empty_history_fragment\"\n  (* set_history *)\n  \"parserHF_set_history\"\n  (* extend_history *)\n  \"append\"\n  (* join_history_fragments *)\n  \"append\"\n  (* get_history *)\n  \"parserHF_conf_history\"\n  (* fixed_schedulers *)\n  \"parser_fixed_schedulers\"\n  (* empty_fixed_scheduler *)\n  \"parser_empty_fixed_scheduler\"\n  (* fixed_scheduler_extendable *)\n  \"parser_fixed_scheduler_extendable\"\n  (* get_fixed_scheduler *)\n  \"parserHF_conf_fixed\"\n  (* get_fixed_scheduler_DB *)\n  \"parserHF_get_fixed_scheduler_DB\"\n  apply(simp add: LOCALE_DEFS parser_interpretations)\n  apply(simp add: parserHF_inst_AX_initial_configuration_belongs parserHF_inst_AX_step_relation_preserves_belongs )\n  apply(simp add: parserHF_inst_ATS_axioms parserHF_inst_ATS_History_axioms parserHF_inst_ATS_SchedF_SB_axioms parserHF_inst_ATS_SchedF_DB_axioms parserHF_inst_ATS_SchedF_SDB_axioms parserHF_inst_ATS_determHIST_SB_axioms parserHF_inst_ATS_Language_by_Finite_Derivations_axioms parserHF_inst_ATS_HistoryCT_SB_axioms parserHF_inst_ATS_HistoryCT_DB_axioms )\n  done\n\nlemma parserHF_inst_AX_BF_BraSBRest_DetHSB_LaOp: \"\n  \\<forall>M. valid_parser M \\<longrightarrow>\n        ATS_determHIST_SB.is_forward_deterministicHist_SB\n         parserHF_initial_configurations parserHF_step_relation\n         parser_markers (@) (@) parserHF_conf_history\n         parser_fixed_scheduler_extendable parserHF_conf_fixed M \\<longrightarrow>\n        nonblockingness_language\n         (ATS_Language0.unmarked_language parserHF_initial_configurations\n           parserHF_step_relation parserHF_unmarked_effect M)\n         (ATS_Language0.marked_language parserHF_initial_configurations\n           parserHF_step_relation parserHF_marking_condition\n           parserHF_marked_effect M) \\<longrightarrow>\n        ATS_SchedF_SB.Nonblockingness_branching_restricted parserHF_configurations\n         parserHF_initial_configurations parser_step_labels\n         parserHF_step_relation parserHF_marking_condition\n         parser_fixed_scheduler_extendable parserHF_conf_fixed M\"\n  apply(clarsimp)\n  apply(rename_tac M)(*strict*)\n  apply(simp add: parserHF.Nonblockingness_branching_restricted_def)\n  apply(clarsimp)\n  apply(rename_tac M dh n)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. dh n= Some (pair e c)\")\n   apply(rename_tac M dh n)(*strict*)\n   prefer 2\n   apply(rule_tac\n      M=\"M\"\n      in parserHF.some_position_has_details_before_max_dom)\n     apply(rename_tac M dh n)(*strict*)\n     apply (metis parserHF.derivation_initial_is_derivation)\n    apply(rename_tac M dh n)(*strict*)\n    apply(force)\n   apply(rename_tac M dh n)(*strict*)\n   apply(force)\n  apply(rename_tac M dh n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac M dh n e c)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(subgoal_tac \"parserHF_conf_history c \\<in> prefix_closure (parserHF.marked_language M)\")\n   apply(rename_tac M dh n e c)(*strict*)\n   prefer 2\n   apply(simp add: nonblockingness_language_def)\n   apply(rename_tac M dh n e c)(*strict*)\n   apply(rule_tac\n      A=\" parserHF.unmarked_language M\"\n      in set_mp)\n    apply(rename_tac M dh n e c)(*strict*)\n    apply(force)\n   apply(rename_tac M dh n e c)(*strict*)\n   apply(thin_tac \" parserHF.unmarked_language M \\<subseteq> (prefix_closure (parserHF.marked_language M))\")\n   apply(rename_tac M dh n e c)(*strict*)\n   apply(simp add: parserHF.unmarked_language_def)\n   apply(rule_tac\n      x=\"dh\"\n      in exI)\n   apply(clarsimp)\n   apply(simp add: parserHF.derivation_initial_def)\n   apply(simp add: parserHF_unmarked_effect_def)\n   apply(clarsimp)\n   apply(force)\n  apply(rename_tac M dh n e c)(*strict*)\n  apply(thin_tac \"nonblockingness_language (parserHF.unmarked_language M) (parserHF.marked_language M)\")\n  apply(rename_tac M dh n e c)(*strict*)\n  apply(simp add: prefix_closure_def parserHF.marked_language_def prefix_def)\n  apply(clarsimp)\n  apply(rename_tac M dh n e c d ca)(*strict*)\n  apply(simp add: parserHF_marked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac M dh n e c d ca i ea cb)(*strict*)\n  apply(subgoal_tac \"\\<exists>i e c. d i = Some (pair e c) \\<and> c \\<in> parserHF_marking_configurations M \\<and> (\\<forall>j e' c'. i < j \\<and> d j = Some (pair e' c') \\<longrightarrow> parserHF_conf_history c = parserHF_conf_history c' )\")\n   apply(rename_tac M dh n e c d ca i ea cb)(*strict*)\n   prefer 2\n   apply(simp add: parserHF_marking_condition_def)\n  apply(rename_tac M dh n e c d ca i ea cb)(*strict*)\n  apply(thin_tac \"parserHF_marking_condition M d\")\n  apply(clarsimp)\n  apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n  apply(subgoal_tac \"dh 0 = d 0\")\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n   prefer 2\n   apply(simp add: parserHF.derivation_initial_def)\n   apply(case_tac \"d 0\")\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc b)(*strict*)\n   apply(case_tac \"dh 0\")\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc b)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc b a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc b a option ba)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc b ba)(*strict*)\n   apply(simp add: parserHF_initial_configurations_def)\n    (*\n  what should dc be?\n  ia \\<le> i \\<le> n : d@i ~ d@ia; d@ia ~~ dh@ia \\<Longrightarrow> dh@n ~ dh@ia; dc = []\n  ia \\<le> n \\<le> i : d@i ~ d@ia; d@ia ~~ dh@ia \\<Longrightarrow> dh@n ~ dh@ia; dc = []\n  n \\<le> ia \\<le> i : d@ia ~ d@ia \\<Longrightarrow> dc = d (n\\<dots>ia)\n  i \\<le> ia \\<le> n : d@ia ~ dh@ia \\<Longrightarrow> dh@n ~ dh@ia; dc = []\n  i \\<le> n \\<le> ia : d@n ~ dh@n; dc = d (n\\<dots>ia)\n  n \\<le> i \\<le> ia : d@n ~ dh@n; dc = d (n\\<dots>ia)\n  ia \\<le> n \\<Longrightarrow> dc = []\n  n \\<le> ia \\<Longrightarrow> dc = d (n\\<dots>ia)\n*)\n  apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n  apply(case_tac \"ia\\<le>n\")\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n   apply(rule_tac\n      x=\"der1 c\"\n      in exI)\n   apply(rule_tac\n      t=\"derivation_append dh (der1 c) n\"\n      and s=\"dh\"\n      in ssubst)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n    apply(rule ext)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc x)(*strict*)\n    apply(simp add: derivation_append_def)\n    apply(clarsimp)\n    apply(simp add: der1_def)\n    apply(case_tac \"dh x\")\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc x)(*strict*)\n     apply(force)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc x a)(*strict*)\n    apply(rule_tac\n      m=\"x\"\n      and d=\"dh\"\n      in parserHF.no_some_beyond_maximum_of_domain)\n       apply(rename_tac M dh n e c d ca i ea cb ia eb cc x a)(*strict*)\n       apply(simp add: parserHF.derivation_initial_def)\n       apply(force)\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc x a)(*strict*)\n      apply(force)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc x a)(*strict*)\n     apply(force)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc x a)(*strict*)\n    apply(force)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n    apply(rule parserHF.der1_is_derivation)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n    apply(rule parserHF.der1_belongs)\n    apply(rule parserHF.belongs_configurations)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n     apply(rule parserHF.derivation_initial_belongs)\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n      apply (metis)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n     apply(force)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n    apply(force)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n    apply(rule_tac\n      x=\"0\"\n      in exI)\n    apply(rule der1_maximum_of_domain)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n    apply(simp add: derivation_append_fit_def der1_def)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n   apply(simp add: parserHF_marking_condition_def)\n    (*\n  where does it accept continuously?\n  ia \\<le> i \\<le> n : d@i ~ d@ia; d@ia ~~ dh@ia \\<Longrightarrow> d@ia=dh@ia; @ia @i\n  ia \\<le> n \\<le> i : d@i ~ d@ia; d@ia ~~ dh@ia \\<Longrightarrow> dh@n ~ dh@ia; @ia\n  i \\<le> ia \\<le> n : d@ia ~ dh@ia \\<Longrightarrow> dh@n ~ dh@ia; @ia\n  *)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n   apply(rule_tac\n      x=\"ia\"\n      in exI)\n   apply(subgoal_tac \"dh ia = d ia\")\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n    prefer 2\n    apply(subgoal_tac \"\\<exists>e c. dh ia = Some (pair e c)\")\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n     prefer 2\n     apply(rule parserHF.some_position_has_details_before_max_dom)\n       apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n       apply(simp add: parserHF.derivation_initial_def)\n       apply(force)\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n      apply(force)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n     apply(force)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n    apply(erule exE)+\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n    apply(subgoal_tac \"\\<exists>ca'. parserHF_conf_history c @ ca' = parserHF_conf_history cc\")\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n     prefer 2\n     apply(case_tac \"i\\<le>ia\")\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n      prefer 2\n      apply(erule_tac\n      x=\"i\"\n      in allE)\n      apply(clarsimp)\n      apply(force)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n     apply(subgoal_tac \"\\<exists>ca'. parserHF_conf_history cb @ ca' = parserHF_conf_history cc\")\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n      apply(clarsimp)\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n      apply(rule_tac\n      x=\"ca @ ca'\"\n      in exI)\n      apply(rule_tac\n      t=\"parserHF_conf_history cc\"\n      and s=\"parserHF_conf_history cb @ ca'\"\n      in ssubst)\n       apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n       apply(force)\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n      apply(rule_tac\n      t=\"parserHF_conf_history cb\"\n      and s=\"parserHF_conf_history c @ ca\"\n      in ssubst)\n       apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n       apply(force)\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n      apply(simp (no_asm))\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n     apply(subgoal_tac \"\\<exists>h\\<in> parser_markers M. parserHF_conf_history cc = parserHF_conf_history cb @ h\")\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n      prefer 2\n      apply(rule_tac\n      d=\"d\"\n      and n=\"i\"\n      and m=\"ia-i\"\n      in parserHF.steps_extend_history_derivation)\n          apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n          apply(simp add: valid_bounded_parser_def)\n         apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n         apply(simp add: parserHF.derivation_initial_def)\n        apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n        apply(simp add: parserHF_marking_configurations_def)\n       apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n       apply(simp add: get_configuration_def)\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n      apply(simp add: get_configuration_def)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n     apply(clarsimp)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n    apply(erule exE)+\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n    apply(rule_tac\n      ?d1.0=\"dh\"\n      and n=\"ia\"\n      and m=\"ia\"\n      and ?d2.0=\"d\"\n      and x=\"0\"\n      and y=\"0\"\n      in parserHF.is_forward_deterministicHist_derivations_coincide)\n               apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n               apply(force)\n              apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n              apply(simp add: parserHF.derivation_initial_def)\n             apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n             apply(force)\n            apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n            apply(force)\n           apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n           apply(force)\n          apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n          apply(force)\n         apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n         apply(force)\n        apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n        apply(force)\n       apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n       apply(force)\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n      apply(force)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n     apply(simp add: get_configuration_def)\n     apply(subgoal_tac \"\\<exists>h\\<in> parser_markers M. parserHF_conf_history c = parserHF_conf_history cd @ h\")\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n      prefer 2\n      apply(rule_tac\n      d=\"dh\"\n      and n=\"ia\"\n      and m=\"n-ia\"\n      in parserHF.steps_extend_history_derivation)\n          apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n          apply(force)\n         apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n         apply(simp add: parserHF.derivation_initial_def)\n        apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n        apply(simp add: parserHF_marking_configurations_def)\n        apply(rule parserHF.belongs_configurations)\n         apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n         apply(rule parserHF.derivation_initial_belongs)\n          apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n          apply(force)\n         apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n         apply(force)\n        apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n        apply(force)\n       apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n       apply(simp add: get_configuration_def)\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n      apply(simp add: get_configuration_def)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n     apply(erule bexE)+\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n     apply(subgoal_tac \"cb \\<in> parserHF_configurations M\")\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n      prefer 2\n      apply(rule_tac\n      d=\"d\"\n      in parserHF.belongs_configurations)\n       apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n       apply(rule parserHF.derivation_initial_belongs)\n        apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n        apply(force)\n       apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n       apply(force)\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n      apply(force)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n     apply(case_tac \"ia\\<le>i\")\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n      apply(subgoal_tac \"parserHF_conf_history cc = parserHF_conf_history cb\")\n       apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n       prefer 2\n       apply(case_tac \"ia<i\")\n        apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n        apply(erule_tac\n      x=\"i\"\n      in allE)\n        apply(clarsimp)\n       apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n      apply(clarsimp)\n      apply(rule_tac\n      x=\"h@ca\"\n      in bexI)\n       apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n      apply(simp add: parser_markers_def)\n      apply(simp add: parserHF_configurations_def)\n      apply(clarsimp)\n      apply(rename_tac M dh n e c d ca i ea ia eb cc ec \"cd\" h x f l)(*strict*)\n      apply(force)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n     apply(subgoal_tac \"\\<exists>h\\<in> parser_markers M. parserHF_conf_history cc = parserHF_conf_history cb @ h\")\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n      prefer 2\n      apply(rule_tac\n      d=\"d\"\n      and n=\"i\"\n      and m=\"ia-i\"\n      in parserHF.steps_extend_history_derivation)\n          apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n          apply(force)\n         apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n         apply(simp add: parserHF.derivation_initial_def)\n        apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n        apply(simp add: parserHF_marking_configurations_def)\n       apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n       apply(simp add: get_configuration_def)\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n      apply(simp add: get_configuration_def)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h ha)(*strict*)\n     apply(rule_tac\n      x=\"h @ ca @ ha\"\n      in bexI)\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h ha)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca' h ha)(*strict*)\n     apply(simp add: parser_markers_def)\n     apply(simp add: parserHF_configurations_def)\n     apply(clarsimp)\n     apply(rename_tac M dh n e c d ca i ea ia eb cc ec \"cd\" h ha x f l)(*strict*)\n     apply(force)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n    apply(simp add: get_configuration_def)\n    apply(fold parser_fixed_scheduler_extendable_def)\n    apply(rule_tac\n      ?d=\"dh\"\n      in parserHF.fixed_scheduler_extendable_translates_backwards_lift)\n          apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n          apply(force)\n         apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n         apply (metis parserHF.derivation_initial_is_derivation)\n        apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n        apply (metis parserHF.belongs_configurations parserHF.derivation_initial_belongs)\n       apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n       apply(force)\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n      apply(force)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n     apply(force)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" ca')(*strict*)\n    apply(force)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n   apply(subgoal_tac \"\\<exists>h\\<in> parser_markers M. parserHF_conf_history c = parserHF_conf_history cc @ h\")\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"dh\"\n      and n=\"ia\"\n      and m=\"n-ia\"\n      in parserHF.steps_extend_history_derivation)\n        apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n        apply(force)\n       apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n       apply(simp add: parserHF.derivation_initial_def)\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n      apply(simp add: parserHF_marking_configurations_def)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n   apply(erule bexE)+\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc h)(*strict*)\n   apply(subgoal_tac \"h@ca=[]\")\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc h)(*strict*)\n    prefer 2\n    apply(case_tac \"ia\\<le>i\")\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc h)(*strict*)\n     apply(case_tac \"ia<i\")\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc h)(*strict*)\n      apply(erule_tac\n      x=\"i\"\n      in allE)\n      apply(clarsimp)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc h)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc h)(*strict*)\n    apply(subgoal_tac \"\\<exists>h\\<in> parser_markers M. parserHF_conf_history cc = parserHF_conf_history cb @ h\")\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc h)(*strict*)\n     prefer 2\n     apply(rule_tac\n      d=\"d\"\n      and n=\"i\"\n      and m=\"ia-i\"\n      in parserHF.steps_extend_history_derivation)\n         apply(rename_tac M dh n e c d ca i ea cb ia eb cc h)(*strict*)\n         apply(force)\n        apply(rename_tac M dh n e c d ca i ea cb ia eb cc h)(*strict*)\n        apply(simp add: parserHF.derivation_initial_def)\n       apply(rename_tac M dh n e c d ca i ea cb ia eb cc h)(*strict*)\n       apply(simp add: parserHF_marking_configurations_def)\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc h)(*strict*)\n      apply(simp add: get_configuration_def)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc h)(*strict*)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc h)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc h)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n   apply(erule_tac\n      x=\"j\"\n      in allE)\n   apply(clarsimp)\n   apply(subgoal_tac \"j\\<le>n\")\n    apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"dh\"\n      in parserHF.allPreMaxDomSome_prime)\n      apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n      apply(simp add: parserHF.derivation_initial_def)\n      apply(force)\n     apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n     apply(force)\n    apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n    apply(force)\n   apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n   apply(subgoal_tac \"\\<exists>h\\<in> parser_markers M. parserHF_conf_history c = parserHF_conf_history c' @ h\")\n    apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"dh\"\n      and n=\"j\"\n      and m=\"n-j\"\n      in parserHF.steps_extend_history_derivation)\n        apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n        apply(force)\n       apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n       apply(simp add: parserHF.derivation_initial_def)\n      apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n      apply(simp add: parserHF_marking_configurations_def)\n      apply(rule parserHF.belongs_configurations)\n       apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n       apply(rule parserHF.derivation_initial_belongs)\n        apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n        apply(force)\n       apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n       apply(force)\n      apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n      apply(force)\n     apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n   apply(subgoal_tac \"\\<exists>h\\<in> parser_markers M. parserHF_conf_history c' = parserHF_conf_history cc @ h\")\n    apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"dh\"\n      and n=\"ia\"\n      and m=\"j-ia\"\n      in parserHF.steps_extend_history_derivation)\n        apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n        apply(force)\n       apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n       apply(simp add: parserHF.derivation_initial_def)\n      apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n      apply(simp add: parserHF_marking_configurations_def)\n     apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n   apply(case_tac \"d j\")\n    apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c')(*strict*)\n    apply(clarify)\n    apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c' h ha)(*strict*)\n    apply(force)\n   apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c' a)(*strict*)\n   apply(clarify)\n   apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c' a h ha)(*strict*)\n   apply(case_tac a)\n   apply(rename_tac M dh n e c d i ea cb ia eb cc j e' c' a h ha option b)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n  apply(subgoal_tac \"ia>n\")\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n  apply(thin_tac \"\\<not> ia \\<le> n\")\n  apply(subgoal_tac \"\\<exists>e c. d n = Some (pair e c)\")\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"ia\"\n      in parserHF.pre_some_position_is_some_position)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n     apply(force)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n    apply(force)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n   apply(force)\n  apply(rename_tac M dh n e c d ca i ea cb ia eb cc)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n  apply(subgoal_tac \"cd \\<in> parserHF_configurations M\")\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"d\"\n      in parserHF.belongs_configurations)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n    apply(rule parserHF.derivation_initial_belongs)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n     apply(force)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n    apply(force)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n   apply(force)\n  apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n  apply(subgoal_tac \"c \\<in> parserHF_configurations M\")\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"dh\"\n      in parserHF.belongs_configurations)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n    apply(rule parserHF.derivation_initial_belongs)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n     apply(force)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n    apply(force)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n   apply(force)\n  apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n  apply(subgoal_tac \"d n = dh n\")\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n   prefer 2\n   apply(rule sym)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n   apply(rule_tac\n      ?d1.0=\"dh\"\n      and n=\"n\"\n      and m=\"ia\"\n      and ?d2.0=\"d\"\n      and x=\"0\"\n      and y=\"0\"\n      in parserHF.is_forward_deterministicHist_derivations_coincide)\n              apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n              apply(force)\n             apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n             apply(simp add: parserHF.derivation_initial_def)\n            apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n            apply(force)\n           apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n           apply(force)\n          apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n          apply(force)\n         apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n         apply(simp add: parserHF.derivation_initial_def)\n        apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n        apply(case_tac \"d 0\")\n         apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n         apply(clarsimp)\n        apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" a)(*strict*)\n        apply(clarsimp)\n       apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n       apply(case_tac \"dh 0\")\n        apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n        apply(clarsimp)\n       apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" a)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n      apply(force)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n     apply(force)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n    prefer 2\n    apply(simp add: get_configuration_def)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(case_tac \"ia<i\")\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n    apply(erule_tac\n      x=\"i\"\n      in allE)\n    apply(clarsimp)\n    apply(rule_tac\n      x=\"ca\"\n      in bexI)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n     apply(force)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n    apply(subgoal_tac \"cb \\<in> parserHF_configurations M\")\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n     apply(subgoal_tac \"cc \\<in> parserHF_configurations M\")\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n      apply(simp add: parserHF_configurations_def parser_markers_def)\n      apply(clarsimp)\n      apply(rename_tac M dh n e d ca i ea ia eb ec x f fa fb fc h ha l la lb lc)(*strict*)\n      apply(rule_tac\n      A=\"set ca\"\n      in set_mp)\n       apply(rename_tac M dh n e d ca i ea ia eb ec x f fa fb fc h ha l la lb lc)(*strict*)\n       apply(force)\n      apply(rename_tac M dh n e d ca i ea ia eb ec x f fa fb fc h ha l la lb lc)(*strict*)\n      apply(force)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n     apply (metis parserHF.belongs_configurations parserHF.derivation_initial_belongs)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n    apply (metis parserHF.belongs_configurations parserHF.derivation_initial_belongs)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n   apply(subgoal_tac \"i\\<le>ia\")\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"\\<exists>hf\\<in> parser_markers M. parserHF_conf_history cc = parserHF_conf_history cb @ hf\")\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"d\"\n      and n=\"i\"\n      and m=\"ia-i\"\n      in parserHF.steps_extend_history_derivation)\n        apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n        apply(force)\n       apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n       apply(force)\n      apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n      apply (metis parserHF.belongs_configurations parserHF.derivation_initial_belongs)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n   apply(clarsimp)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" hf)(*strict*)\n   apply(rule_tac\n      x=\"ca@hf\"\n      in bexI)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" hf)(*strict*)\n    apply(force)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" hf)(*strict*)\n   apply(subgoal_tac \"cb \\<in> parserHF_configurations M\")\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" hf)(*strict*)\n    apply(subgoal_tac \"cc \\<in> parserHF_configurations M\")\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" hf)(*strict*)\n     apply(simp add: parserHF_configurations_def parser_markers_def)\n     apply(clarsimp)\n     apply(rename_tac M dh n e d ca i ea ia eb ec hf x f fa fb fc h ha l la lb lc)(*strict*)\n     apply(rule_tac\n      A=\"set ca\"\n      in set_mp)\n      apply(rename_tac M dh n e d ca i ea ia eb ec hf x f fa fb fc h ha l la lb lc)(*strict*)\n      apply(force)\n     apply(rename_tac M dh n e d ca i ea ia eb ec hf x f fa fb fc h ha l la lb lc)(*strict*)\n     apply(force)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" hf)(*strict*)\n    apply (metis parserHF.belongs_configurations parserHF.derivation_initial_belongs)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\" hf)(*strict*)\n   apply (metis parserHF.belongs_configurations parserHF.derivation_initial_belongs)\n  apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n  apply(rule_tac\n      x=\"derivation_drop (derivation_take d ia) n\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n   apply(rule_tac\n      m=\"ia-n\"\n      in parserHF.derivation_drop_preserves_derivation_prime)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n    apply(rule parserHF.derivation_take_preserves_derivation)\n    apply(force)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n  apply(rule conjI)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n   apply(rule parserHF.derivation_drop_preserves_belongs)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n     apply(rule parserHF.derivation_take_preserves_derivation)\n     apply(force)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n    apply(rule parserHF.derivation_take_preserves_belongs)\n    apply(rule parserHF.derivation_initial_belongs)\n     apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n     apply(force)\n    apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n    apply(force)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n  apply(rule conjI)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n   apply(rule_tac\n      x=\"ia-n\"\n      in exI)\n   apply(simp add: maximum_of_domain_def derivation_drop_def derivation_take_def)\n  apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n  apply(rule conjI)\n   apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n   apply(simp add: derivation_append_fit_def derivation_drop_def derivation_take_def)\n  apply(rename_tac M dh n e c d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n  apply(simp add: parserHF_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac M dh n d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n  apply(rule_tac\n      x=\"ia\"\n      in exI)\n  apply(rule_tac\n      x=\"eb\"\n      in exI)\n  apply(rule_tac\n      x=\"cc\"\n      in exI)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(rename_tac M dh n d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n   apply(simp add: derivation_append_def derivation_drop_def derivation_take_def)\n  apply(rename_tac M dh n d ca i ea cb ia eb cc ec \"cd\")(*strict*)\n  apply(clarsimp)\n  apply(rename_tac M dh n d ca i ea cb ia eb cc ec \"cd\" j e' c')(*strict*)\n  apply(simp add: derivation_append_def derivation_drop_def derivation_take_def)\n  done\n\nlemma parserHF_inst_BF_BraSBRest_DetHSB_LaOp_axioms: \"\n  BF_BraSBRest_DetHSB_LaOp_axioms valid_parser parserHF_configurations\n     parserHF_initial_configurations parser_step_labels\n     parserHF_step_relation parserHF_marking_condition\n     parserHF_marked_effect parserHF_unmarked_effect parser_markers (@)\n     (@) parserHF_conf_history parser_fixed_scheduler_extendable\n     parserHF_conf_fixed\"\n  apply(simp add: BF_BraSBRest_DetHSB_LaOp_axioms_def)\n  apply(rule parserHF_inst_AX_BF_BraSBRest_DetHSB_LaOp)\n  done\n\nlemma parserHF_inst_BF_BraSBRest_DetHDB_LaOp_axioms: \"\n  BF_BraSBRest_DetHDB_LaOp_axioms valid_parser parserHF_configurations\n     parserHF_initial_configurations parser_step_labels\n     parserHF_step_relation parserHF_marking_condition\n     parserHF_marked_effect parserHF_unmarked_effect parser_markers (@)\n     (@) parserHF_conf_history parser_fixed_scheduler_extendable\n     parserHF_get_fixed_scheduler_DB parserHF_conf_fixed\"\n  apply(simp add: BF_BraSBRest_DetHDB_LaOp_axioms_def)\n  apply(clarsimp)\n  apply(rename_tac M)(*strict*)\n  apply(subgoal_tac \"parserHF.is_forward_deterministicHist_SB M\")\n   apply(rename_tac M)(*strict*)\n   apply (metis parserHF_inst_AX_BF_BraSBRest_DetHSB_LaOp)\n  apply(rename_tac M)(*strict*)\n  apply(thin_tac \"nonblockingness_language (parserHF.unmarked_language M) (parserHF.marked_language M)\")\n  apply(rename_tac M)(*strict*)\n  apply (metis parserHF.is_forward_deterministic_correspond_DB_SB)\n  done\n\nlemma parserHF_inst_BF_BraDBRest_DetHSB_LaOp_axioms: \"\n  BF_BraDBRest_DetHSB_LaOp_axioms valid_parser parserHF_configurations\n     parserHF_initial_configurations parser_step_labels\n     parserHF_step_relation parserHF_marking_condition\n     parserHF_marked_effect parserHF_unmarked_effect parser_markers (@)\n     (@) parserHF_conf_history parser_fixed_scheduler_extendable\n     parserHF_conf_fixed parserHF_get_fixed_scheduler_DB\"\n  apply(simp add: BF_BraDBRest_DetHSB_LaOp_axioms_def)\n  apply(clarsimp)\n  apply(rename_tac M)(*strict*)\n  apply(rule_tac\n      t=\"ATS_SchedF_DB.Nonblockingness_branching_restricted_DB\n          parserHF_configurations parserHF_initial_configurations\n          parser_step_labels parserHF_step_relation\n          parserHF_marking_condition parser_fixed_scheduler_extendable\n          parserHF_get_fixed_scheduler_DB M\"\n      and s=\"parserHF.Nonblockingness_branching_restricted M\"\n      in subst)\n   apply(rename_tac M)(*strict*)\n   apply(rule parserHF.Nonblockingness_branching_SB_DB_restricted)\n   apply(force)\n  apply(rename_tac M)(*strict*)\n  apply(subgoal_tac \"BF_BraSBRest_DetHDB_LaOp_axioms valid_parser parserHF_configurations\n     parserHF_initial_configurations parser_step_labels\n     parserHF_step_relation parserHF_marking_condition\n     parserHF_marked_effect parserHF_unmarked_effect parser_markers (@)\n     (@) parserHF_conf_history parser_fixed_scheduler_extendable\n     parserHF_get_fixed_scheduler_DB parserHF_conf_fixed\")\n   apply(rename_tac M)(*strict*)\n   apply(simp add: BF_BraSBRest_DetHDB_LaOp_axioms_def)\n   apply(erule_tac\n      x=\"M\"\n      in allE)\n   apply(erule impE)\n    apply(rename_tac M)(*strict*)\n    apply(force)\n   apply(rename_tac M)(*strict*)\n   apply(erule impE)\n    apply(rename_tac M)(*strict*)\n    apply (metis parserHF.is_forward_deterministic_correspond_DB_SB)\n   apply(rename_tac M)(*strict*)\n   apply(erule impE)\n    apply(rename_tac M)(*strict*)\n    apply(force)\n   apply(rename_tac M)(*strict*)\n   apply(force)\n  apply(rename_tac M)(*strict*)\n  apply(rule parserHF_inst_BF_BraSBRest_DetHDB_LaOp_axioms)\n  done\n\nlemma parserHF_inst_BF_BraDBRest_DetHDB_LaOp_axioms: \"\n  BF_BraDBRest_DetHDB_LaOp_axioms valid_parser parserHF_configurations\n     parserHF_initial_configurations parser_step_labels\n     parserHF_step_relation parserHF_marking_condition\n     parserHF_marked_effect parserHF_unmarked_effect parser_markers (@)\n     (@) parserHF_conf_history parser_fixed_scheduler_extendable\n     parserHF_get_fixed_scheduler_DB\"\n  apply(simp add: BF_BraDBRest_DetHDB_LaOp_axioms_def)\n  apply(clarsimp)\n  apply(rename_tac M)(*strict*)\n  apply(subgoal_tac \"BF_BraDBRest_DetHSB_LaOp_axioms valid_parser parserHF_configurations\n     parserHF_initial_configurations parser_step_labels\n     parserHF_step_relation parserHF_marking_condition\n     parserHF_marked_effect parserHF_unmarked_effect parser_markers (@)\n     (@) parserHF_conf_history parser_fixed_scheduler_extendable\n     parserHF_conf_fixed parserHF_get_fixed_scheduler_DB\")\n   apply(rename_tac M)(*strict*)\n   apply(simp add: BF_BraDBRest_DetHSB_LaOp_axioms_def)\n   apply(erule_tac\n      x=\"M\"\n      in allE)\n   apply(erule impE)\n    apply(rename_tac M)(*strict*)\n    apply(force)\n   apply(rename_tac M)(*strict*)\n   apply(erule impE)\n    apply(rename_tac M)(*strict*)\n    apply (metis parserHF.is_forward_deterministic_correspond_DB_SB)\n   apply(rename_tac M)(*strict*)\n   apply(erule impE)\n    apply(rename_tac M)(*strict*)\n    apply(force)\n   apply(rename_tac M)(*strict*)\n   apply(force)\n  apply(rename_tac M)(*strict*)\n  apply(rule parserHF_inst_BF_BraDBRest_DetHSB_LaOp_axioms)\n  done\n\nlemma parserHF_inst_BF_Bra_OpLa_axioms: \"\n  BF_Bra_OpLa_axioms valid_parser parserHF_configurations\n     parserHF_initial_configurations parser_step_labels\n     parserHF_step_relation parserHF_marking_condition\n     parserHF_marked_effect parserHF_unmarked_effect\"\n  apply(simp add: BF_Bra_OpLa_axioms_def)\n  apply(clarsimp)\n  apply(rename_tac M)(*strict*)\n  apply(simp add: nonblockingness_language_def)\n  apply(clarsimp)\n  apply(rename_tac M xa)(*strict*)\n  apply(simp add: prefix_closure_def prefix_def)\n  apply(simp add: parserHF.unmarked_language_def)\n  apply(clarsimp)\n  apply(rename_tac M xa d)(*strict*)\n  apply(simp add: parserHF.Nonblockingness_branching_def)\n  apply(simp add: parserHF_unmarked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac M d i e c)(*strict*)\n  apply(erule_tac\n      x=\"derivation_take d i\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac M d i e c)(*strict*)\n   apply(rename_tac M d i e c)(*strict*)\n   apply(rule parserHF.derivation_take_preserves_derivation_initial)\n   apply(force)\n  apply(rename_tac M d i e c)(*strict*)\n  apply(erule_tac\n      x=\"i\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac M d i e c)(*strict*)\n   apply(rule maximum_of_domain_derivation_take)\n   apply(force)\n  apply(rename_tac M d i e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac M d i e c dc x)(*strict*)\n  apply(simp add: parserHF_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n  apply(rule_tac\n      x=\"parserHF_conf_history ca\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n   apply(simp add: parserHF.marked_language_def)\n   apply(rule_tac\n      x=\"derivation_append (derivation_take d i) dc i\"\n      in exI)\n   apply(rule context_conjI)\n    apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n    apply(rule parserHF.derivation_append_preserves_derivation_initial)\n      apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n      apply(force)\n     apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n     apply(rule parserHF.derivation_take_preserves_derivation_initial)\n     apply(force)\n    apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n    apply(rule parserHF.derivation_append_preserves_derivation)\n      apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n      apply(rule parserHF.derivation_take_preserves_derivation)\n      apply(force)\n     apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n     apply(force)\n    apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n    apply(simp add: derivation_take_def)\n    apply(simp add: derivation_append_fit_def)\n    apply(case_tac \"dc 0\")\n     apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n     apply(force)\n    apply(rename_tac M d i e c dc x ia ea ca a)(*strict*)\n    apply(clarsimp)\n    apply(case_tac a)\n    apply(rename_tac M d i e c dc x ia ea ca a option b)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac M d i e c dc x ia ea ca option b)(*strict*)\n    apply(case_tac option)\n     apply(rename_tac M d i e c dc x ia ea ca option b)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac M d i e c dc x ia ea ca option b a)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n    apply(simp add: parserHF_marked_effect_def)\n    apply(rule_tac\n      x=\"ia\"\n      in exI)\n    apply(rule_tac\n      x=\"ea\"\n      in exI)\n    apply(rule_tac\n      x=\"ca\"\n      in exI)\n    apply(clarsimp)\n   apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n   apply(simp add: parserHF.derivation_initial_def)\n   apply(simp add: parserHF_marking_condition_def)\n   apply(rule_tac\n      x=\"ia\"\n      in exI)\n   apply(rule_tac\n      x=\"ea\"\n      in exI)\n   apply(rule_tac\n      x=\"ca\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n  apply(case_tac \"ia<i\")\n   apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n   apply(rule_tac\n      x=\"[]\"\n      in exI)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"i\"\n      in allE)\n   apply(erule_tac\n      x=\"e\"\n      in allE)\n   apply(erule_tac\n      x=\"c\"\n      in allE)\n   apply(clarsimp)\n   apply(simp add: derivation_append_def derivation_take_def)\n  apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n  apply(subgoal_tac \"\\<exists>h\\<in> parser_markers M. parserHF_conf_history SSc' = parserHF_conf_history SSc @ h\" for SSc' SSc)\n   apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"derivation_append (derivation_take d i) dc i\"\n      and n=\"i\"\n      and m=\"ia-i\"\n      in parserHF.steps_extend_history_derivation)\n       apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n       apply(force)\n      apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n      apply(simp add: parserHF.derivation_initial_def)\n      apply(rule parserHF.derivation_append_preserves_derivation)\n        apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n        apply(rule parserHF.derivation_take_preserves_derivation)\n        apply(force)\n       apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n       apply(force)\n      apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n      apply(simp add: derivation_take_def derivation_append_fit_def)\n      apply(case_tac \"dc 0\")\n       apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n       apply(force)\n      apply(rename_tac M d i e c dc x ia ea ca a)(*strict*)\n      apply(clarsimp)\n      apply(case_tac a)\n      apply(rename_tac M d i e c dc x ia ea ca a option b)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac M d i e c dc x ia ea ca option b)(*strict*)\n      apply(case_tac option)\n       apply(rename_tac M d i e c dc x ia ea ca option b)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac M d i e c dc x ia ea ca option b a)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n     prefer 2\n     apply(simp add: get_configuration_def derivation_append_def derivation_take_def)\n    apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n    apply(rule parserHF.belongs_configurations)\n     apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n     apply(rule parserHF.derivation_initial_belongs)\n      apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n      apply(force)\n     apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n     apply(force)\n    apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n    apply(force)\n   apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n   apply(simp add: get_configuration_def derivation_append_def derivation_take_def)\n  apply(rename_tac M d i e c dc x ia ea ca)(*strict*)\n  apply(force)\n  done\n\ninterpretation \"parserHF\" : loc_autHF_10\n  (* TSstructure *)\n  \"valid_parser\"\n  (* configurations *)\n  \"parserHF_configurations\"\n  (* initial_configurations *)\n  \"parserHF_initial_configurations\"\n  (* step_labels *)\n  \"parser_step_labels\"\n  (* step_relation *)\n  \"parserHF_step_relation\"\n  (* effects *)\n  \"parser_markers\"\n  (* marking_condition *)\n  \"parserHF_marking_condition\"\n  (* marked_effect *)\n  \"parserHF_marked_effect\"\n  (* unmarked_effect *)\n  \"parserHF_unmarked_effect\"\n  (* destinations *)\n  \"parser_destinations\"\n  (* get_destinations *)\n  \"parserHF_get_destinations\"\n  (* histories *)\n  \"parser_markers\"\n  (* history_fragments *)\n  \"parser_markers\"\n  (* empty_history *)\n  \"parser_empty_history\"\n  (* empty_history_fragment *)\n  \"parser_empty_history_fragment\"\n  (* set_history *)\n  \"parserHF_set_history\"\n  (* extend_history *)\n  \"append\"\n  (* join_history_fragments *)\n  \"append\"\n  (* get_history *)\n  \"parserHF_conf_history\"\n  (* fixed_schedulers *)\n  \"parser_fixed_schedulers\"\n  (* empty_fixed_scheduler *)\n  \"parser_empty_fixed_scheduler\"\n  (* fixed_scheduler_extendable *)\n  \"parser_fixed_scheduler_extendable\"\n  (* get_fixed_scheduler *)\n  \"parserHF_conf_fixed\"\n  (* get_fixed_scheduler_DB *)\n  \"parserHF_get_fixed_scheduler_DB\"\n  apply(simp add: LOCALE_DEFS parser_interpretations)\n  apply(simp add: parserHF_inst_AX_initial_configuration_belongs parserHF_inst_AX_step_relation_preserves_belongs )\n  apply(simp add: parserHF_inst_ATS_axioms parserHF_inst_ATS_History_axioms parserHF_inst_ATS_SchedF_SB_axioms parserHF_inst_ATS_SchedF_DB_axioms parserHF_inst_ATS_SchedF_SDB_axioms parserHF_inst_ATS_determHIST_SB_axioms parserHF_inst_ATS_Language_by_Finite_Derivations_axioms parserHF_inst_ATS_HistoryCT_SB_axioms parserHF_inst_ATS_HistoryCT_DB_axioms parserHF_inst_BF_BraSBRest_DetHDB_LaOp_axioms parserHF_inst_BF_BraSBRest_DetHSB_LaOp_axioms parserHF_inst_BF_BraDBRest_DetHSB_LaOp_axioms parserHF_inst_BF_BraDBRest_DetHDB_LaOp_axioms parserHF_inst_BF_Bra_OpLa_axioms )\n  done\n\nlemma parserHF_history_prefix_makes_prefix: \"\n  w1 \\<in> parser_markers G\n  \\<Longrightarrow> ATS_History.history_fragment_prefixes parser_markers (@) G w1 \\<subseteq> ATS_History.history_fragment_prefixes parser_markers (@) G w2\n  \\<Longrightarrow> w1 \\<sqsubseteq> w2\"\n  apply(simp add: parserHF.history_fragment_prefixes_def)\n  apply(simp add: prefix_def)\n  apply(subgoal_tac \"w1 \\<in> {hf' \\<in> parser_markers G. \\<exists>hf''\\<in> parser_markers G. hf' @ hf'' = w1}\")\n   prefer 2\n   apply(clarsimp)\n   apply(simp add: parser_markers_def)\n  apply(subgoal_tac \"w1 \\<in> {hf' \\<in> parser_markers G. \\<exists>hf''\\<in> parser_markers G. hf' @ hf'' = w2}\")\n   prefer 2\n   apply(force)\n  apply(thin_tac \"{hf' \\<in> parser_markers G. \\<exists>hf''\\<in> parser_markers G. hf' @ hf'' = w1} \\<subseteq> {hf' \\<in> parser_markers G. \\<exists>hf''\\<in> parser_markers G. hf' @ hf'' = w2}\")\n  apply(thin_tac \"w1 \\<in> {hf' \\<in> parser_markers G. \\<exists>hf''\\<in> parser_markers G. hf' @ hf'' = w1}\")\n  apply(force)\n  done\n\nlemma parserHF_history_prefix_makes_prefix_mutual: \"\n  w1 \\<in> parser_markers G\n  \\<Longrightarrow> w2 \\<in> parser_markers G\n  \\<Longrightarrow> ATS_History.history_fragment_prefixes parser_markers (@) G w1 \\<subseteq> ATS_History.history_fragment_prefixes parser_markers (@) G w2 \\<or> ATS_History.history_fragment_prefixes parser_markers (@) G w2 \\<subseteq> ATS_History.history_fragment_prefixes parser_markers (@) G w1\n  \\<Longrightarrow> prefix w1 w2 \\<or> prefix w2 w1\"\n  apply(erule disjE)\n   apply(rule disjI1)\n   apply(rule parserHF_history_prefix_makes_prefix)\n    apply(force)\n   apply(force)\n  apply(rule disjI2)\n  apply(rule parserHF_history_prefix_makes_prefix)\n   apply(force)\n  apply(force)\n  done\n\nlemma parserHF_is_forward_target_deterministicHist_DB_long: \"\n  valid_parser G\n  \\<Longrightarrow> parserHF.is_forward_target_deterministicHist_DB_long G\"\n  apply(simp add: parserHF.is_forward_target_deterministicHist_DB_long_def)\n  apply(clarsimp)\n  apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n  apply(simp add: parserHF_step_relation_def)\n  apply(clarsimp)\n  done\n\nlemmas parserHF_interpretations =\n  parser_interpretations\n  parserHF_inst_AX_initial_configuration_belongs\n  parserHF_inst_AX_step_relation_preserves_belongs\n  parserHF_inst_ATS_axioms\n  parserHF_inst_ATS_History_axioms\n  parserHF_inst_ATS_SchedF_SB_axioms\n  parserHF_inst_ATS_SchedF_DB_axioms\n  parserHF_inst_ATS_SchedF_SDB_axioms\n  parserHF_inst_ATS_determHIST_SB_axioms\n  parserHF_inst_ATS_Language_by_Finite_Derivations_axioms\n  parserHF_inst_ATS_HistoryCT_SB_axioms\n  parserHF_inst_ATS_HistoryCT_DB_axioms\n  parserHF_inst_BF_BraSBRest_DetHDB_LaOp_axioms\n  parserHF_inst_BF_BraSBRest_DetHSB_LaOp_axioms\n  parserHF_inst_BF_BraDBRest_DetHSB_LaOp_axioms\n  parserHF_inst_BF_BraDBRest_DetHDB_LaOp_axioms\n  parserHF_inst_BF_Bra_OpLa_axioms\n\nend\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_08/I_kparser_HF.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6442251064863697, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.2845368391064484}}
{"text": "theory BeispielZahlenweltGesetz\nimports BeispielZahlenwelt Simulation Gesetze AllgemeinesGesetz\nbegin\n\nsection\\<open>Beispiel: BeispielZahlenwelt aber mit Gesetz (Experimental)\\<close>\n\n  (*<*)\n  fun delta_zahlenwelt :: \\<open>(zahlenwelt, person, int) delta\\<close> where\n    \\<open>delta_zahlenwelt (Handlung (Zahlenwelt vor_besitz) (Zahlenwelt nach_besitz)) =\n        Aenderung.delta_num_fun (Handlung vor_besitz nach_besitz)\\<close>\n  (*>*)\n\nsubsection\\<open>Setup\\<close>\n  text\\<open>Wir nehmen an unsere handelnde Person ist \\<^const>\\<open>Alice\\<close>.\\<close>\n  \n  definition \\<open>beispiel_case_law_absolut maxime handlungsabsicht \\<equiv>\n    simulateOne\n      (SimConsts\n        Alice\n        maxime\n        (printable_case_law_ableiten_absolut show_zahlenwelt))\n      5 handlungsabsicht initialwelt (Gesetz {})\\<close>\n  definition \\<open>beispiel_case_law_relativ maxime handlungsabsicht \\<equiv>\n    simulateOne\n      (SimConsts\n        Alice\n        maxime\n        (case_law_ableiten_relativ delta_zahlenwelt))\n      10 handlungsabsicht initialwelt (Gesetz {})\\<close>\n\n\nsubsection\\<open>Beispiele\\<close>\n  text\\<open>Alice kann beliebig oft 5 Wohlstand für sich selbst erschaffen.\n  Das entstehende Gesetz ist nicht sehr gut, da es einfach jedes Mal einen\n  Snapshot der Welt aufschreibt und nicht sehr generisch ist.\\<close>\n  (*check: ist auch eine moralische Handlung*)\n  lemma \\<open>beispiel_case_law_absolut maxime_zahlenfortschritt (Handlungsabsicht (erschaffen 5))\n  =\n  Gesetz\n  {(\\<section> 5,\n    Rechtsnorm\n     (Tatbestand ([(Alice, 25), (Bob, 10), (Carol, - 3)], [(Alice, 30), (Bob, 10), (Carol, - 3)]))\n     (Rechtsfolge Erlaubnis)),\n   (\\<section> 4,\n    Rechtsnorm\n     (Tatbestand ([(Alice, 20), (Bob, 10), (Carol, - 3)], [(Alice, 25), (Bob, 10), (Carol, - 3)]))\n     (Rechtsfolge Erlaubnis)),\n   (\\<section> 3,\n    Rechtsnorm\n     (Tatbestand ([(Alice, 15), (Bob, 10), (Carol, - 3)], [(Alice, 20), (Bob, 10), (Carol, - 3)]))\n     (Rechtsfolge Erlaubnis)),\n   (\\<section> 2,\n    Rechtsnorm\n     (Tatbestand ([(Alice, 10), (Bob, 10), (Carol, - 3)], [(Alice, 15), (Bob, 10), (Carol, - 3)]))\n     (Rechtsfolge Erlaubnis)),\n   (\\<section> 1,\n    Rechtsnorm\n     (Tatbestand ([(Alice, 5), (Bob, 10), (Carol, - 3)], [(Alice, 10), (Bob, 10), (Carol, - 3)]))\n     (Rechtsfolge Erlaubnis))}\n  \\<close> by eval\n  \n  \n  text\\<open>Die gleiche Handlung, wir schreiben aber nur die Änderung der Welt ins Gesetz:\\<close>\n  lemma \\<open>beispiel_case_law_relativ maxime_zahlenfortschritt (Handlungsabsicht (erschaffen 5)) =\n    Gesetz\n    {(\\<section> 1, Rechtsnorm (Tatbestand [Gewinnt Alice 5]) (Rechtsfolge Erlaubnis))}\\<close>\n    by eval\n\n  (*TODO: Beispiele mit der guten maxime!*)\n  lemma \\<open>beispiel_case_law_relativ\n    (Maxime (\\<lambda>(ich::person) h. (\\<forall>pX. individueller_fortschritt pX h))) (Handlungsabsicht (erschaffen 5)) =\n  Gesetz {(\\<section> 1, Rechtsnorm (Tatbestand [Gewinnt Alice 5]) (Rechtsfolge Erlaubnis))}\\<close>\n    by eval\n\n\n\n  text\\<open>Nun ist es \\<^const>\\<open>Alice\\<close> verboten Wohlstand für sich selbst zu erzeugen.\\<close>\n  (*check: ist auch keine moralische Handlung*)\n  lemma \\<open>beispiel_case_law_relativ\n          (Maxime (\\<lambda>ich. individueller_strikter_fortschritt ich))\n          (Handlungsabsicht (erschaffen 5)) =\n    Gesetz {(\\<section> 1, Rechtsnorm (Tatbestand [Gewinnt Alice 5]) (Rechtsfolge Verbot))}\\<close>\n    by eval\n\n\n\n  (*check: ist auch eine moralische Handlung*)\n  lemma \\<open>beispiel_case_law_relativ\n          (Maxime (\\<lambda>ich. globaler_strikter_fortschritt))\n          (Handlungsabsicht (erschaffen 5)) =\n    Gesetz {(\\<section> 1, Rechtsnorm (Tatbestand [Gewinnt Alice 5]) (Rechtsfolge Erlaubnis))}\\<close>\n    by eval\n\n    \n\n  (*check: ist auch keine moralische Handlung*)\n  lemma \\<open>beispiel_case_law_relativ\n          (Maxime (\\<lambda>ich. globaler_strikter_fortschritt))\n          (Handlungsabsicht (erschaffen 0)) =\n    Gesetz {(\\<section> 1, Rechtsnorm (Tatbestand []) (Rechtsfolge Verbot))}\\<close>\n    by eval\n\n\n  (*check: ist auch keine moralische Handlung*)\n  lemma \\<open>beispiel_case_law_relativ\n          maxime_zahlenfortschritt\n          (Handlungsabsicht (erschaffen 0)) =\n    Gesetz {(\\<section> 1, Rechtsnorm (Tatbestand []) (Rechtsfolge Erlaubnis))}\\<close>\n    by eval\n\n  (*check: ist auch eine moralische Handlung*)\n  lemma\\<open>beispiel_case_law_relativ\n            (Maxime (\\<lambda>ich. globaler_fortschritt))\n            (Handlungsabsicht (erschaffen 0))\n    =\n    Gesetz {(\\<section> 1, Rechtsnorm (Tatbestand []) (Rechtsfolge Erlaubnis))}\\<close>\n    by eval\n\n  \n\n  (*check: ist auch eine moralische Handlung*)\n  lemma\\<open>beispiel_case_law_relativ\n          (Maxime (\\<lambda>ich. globaler_fortschritt))\n          (Handlungsabsicht (stehlen_nichtwf 5 Bob))\n    =\n    Gesetz\n    {(\\<section> 1, Rechtsnorm (Tatbestand [Gewinnt Alice 5, Verliert Bob 5]) (Rechtsfolge Erlaubnis))}\\<close>\n    by eval\n\n\n\n\n  text\\<open>Stehlen ist verboten:\\<close>\n  (*check: ist auch keine moralische Handlung*)\n  lemma \\<open>beispiel_case_law_relativ maxime_zahlenfortschritt (Handlungsabsicht (stehlen_nichtwf 5 Bob)) =\n    Gesetz\n    {(\\<section> 1, Rechtsnorm (Tatbestand [Gewinnt Alice 5, Verliert Bob 5]) (Rechtsfolge Verbot))}\\<close>\n    by eval\n\n\n\n  text\\<open>Auch wenn \\<^const>\\<open>Alice\\<close> von sich selbst stehlen möchte ist dies verboten,\n  obwohl hier keiner etwas verliert:\\<close>\n  (*check: ist auch keine moralische Handlung*)\n  lemma \\<open>beispiel_case_law_relativ maxime_zahlenfortschritt (Handlungsabsicht (stehlen_nichtwf 5 Alice)) =\n    Gesetz {(\\<section> 1, Rechtsnorm (Tatbestand []) (Rechtsfolge Verbot))}\\<close>\n    by eval\n\n\n  text\\<open>Der Grund ist, dass \\<^const>\\<open>Alice\\<close> die abstrakte Handlung \"Alice wird bestohlen\" gar nicht gut\n  fände, wenn sie jemand anderes ausführt:\\<close>\n(*\n  lemma \\<open>debug_maxime show_zahlenwelt initialwelt\n          maxime_zahlenfortschritt (Handlungsabsicht (stehlen_nichtwf 5 Alice)) =\n   {VerletzteMaxime (Opfer Alice) (Taeter Bob)\n     (Handlung [(Alice, 5), (Bob, 10), (Carol, - 3)] [(Bob, 15), (Carol, - 3)]),\n    VerletzteMaxime (Opfer Alice) (Taeter Carol)\n     (Handlung [(Alice, 5), (Bob, 10), (Carol, - 3)] [(Bob, 10), (Carol, 2)]),\n    VerletzteMaxime (Opfer Alice) (Taeter Eve)\n     (Handlung [(Alice, 5), (Bob, 10), (Carol, - 3)] [(Bob, 10), (Carol, - 3), (Eve, 5)])\n   }\\<close>\n    by eval\n*)  \n  text\\<open>Leider ist das hier abgeleitete Gesetz sehr fragwürdig:\n  \\<^term>\\<open>Rechtsnorm (Tatbestand []) (Rechtsfolge Verbot)\\<close>\n  \n  Es besagt, dass Nichtstun verboten ist.\\<close>\n\n  text\\<open>Indem wir die beiden Handlungen Nichtstun und Selbstbestehlen betrachten,\n  können wir sogar ein widersprüchliches Gesetz ableiten:\\<close>\n  lemma \\<open>simulateOne\n      (SimConsts\n        Alice\n        maxime_zahlenfortschritt\n        (case_law_ableiten_relativ delta_zahlenwelt))\n      20 (Handlungsabsicht (stehlen_nichtwf 5 Alice)) initialwelt\n      (beispiel_case_law_relativ maxime_zahlenfortschritt (Handlungsabsicht (erschaffen 0)))\n    =\n    Gesetz\n  {(\\<section> 2, Rechtsnorm (Tatbestand []) (Rechtsfolge Verbot)),\n   (\\<section> 1, Rechtsnorm (Tatbestand []) (Rechtsfolge Erlaubnis))}\\<close>\n    by eval\n\n  text\\<open>Meine persönliche Conclusion: Wir müssen irgendwie die Absicht mit ins Gesetz schreiben.\\<close>\n\n\n\n  text\\<open>Es ist \\<^const>\\<open>Alice\\<close> verboten, etwas zu verschenken:\\<close>\n  (*Check*)\n  lemma\\<open>beispiel_case_law_relativ maxime_zahlenfortschritt (Handlungsabsicht (schenken 5 Bob))\n    =\n    Gesetz\n      {(\\<section> 1,\n        Rechtsnorm (Tatbestand [Verliert Alice 5, Gewinnt Bob 5]) (Rechtsfolge Verbot))}\\<close>\n    by eval\n  text\\<open>Der Grund ist, dass \\<^const>\\<open>Alice\\<close> dabei etwas verliert und\n  die \\<^const>\\<open>maxime_zahlenfortschritt\\<close> dies nicht Erlaubt.\n  Es fehlt eine Möglichkeit zu modellieren, dass \\<^const>\\<open>Alice\\<close> damit einverstanden ist,\n  etwas abzugeben.\n  Doch wir haben bereits in @{thm stehlen_ist_schenken} gesehen,\n  dass \\<^const>\\<open>stehlen\\<close> und \\<^const>\\<open>schenken\\<close> nicht unterscheidbar sind.\\<close>\n\n(*TODO: gesetz ableiten aendern, so dass allgemeines gesetz ableiten eine\nhandlungsabsicht anstatt einer handlung nimmt.\nEvtl in neue Datei, damit sich dieses Beipsiel noch gut liesst.*)\n\n\n  text\\<open>Folgende ungültige Maxime würde es erlauben, dass \\<^const>\\<open>Alice\\<close> Leute bestehlen darf:\\<close>\n  lemma\\<open>beispiel_case_law_relativ\n            (Maxime (\\<lambda>ich. individueller_fortschritt Alice))\n            (Handlungsabsicht (stehlen_nichtwf 5 Bob))\n    =\n    Gesetz\n    {(\\<section> 1, Rechtsnorm (Tatbestand [Gewinnt Alice 5, Verliert Bob 5]) (Rechtsfolge Erlaubnis))}\\<close>\n    by eval\nend", "meta": {"author": "diekmann", "repo": "kant", "sha": "fd8cd77b199114d0a8f6b5ad5e0c63a2c4a88902", "save_path": "github-repos/isabelle/diekmann-kant", "path": "github-repos/isabelle/diekmann-kant/kant-fd8cd77b199114d0a8f6b5ad5e0c63a2c4a88902/Formal/BeispielZahlenweltGesetz.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5312093733737563, "lm_q2_score": 0.5350984286266116, "lm_q1q2_score": 0.284249300964024}}
{"text": "theory Traceback_Properties\nimports Safety_Properties\nbegin\n\n\nsection \\<open>Traceback properties\\<close>\n\ntext \\<open>In this section, we prove various traceback properties,\nby essentially giving trace-based justifications of certain\noccurring situations that are relevant for access to information:\n%\n\\begin{description}\n\\item{\\bf Being an author. }\nIf a user is an author of a paper, then either the user has registered the paper in the first\nplace or, inductively, has been appointed as coauthor by another author.\n%\n\\item{\\bf Being a chair. }\nIf a user is a chair of a conference, then either that user has registered the conference\nwhich has been approved by the superuser or, inductively, that user has been appointed\nby an existing chair of that conference.\n%\n%\n\\item{\\bf Being a PC member. }\nIf a user is a PC member in a conference, then the user either must have been the original chair or must\nhave been appointed by a chair.\n%\n\\item{\\bf Being a reviewer. }\nIf a user is a paper's reviewer, then the user must have been appointed by a chair (from\namong the PC members who have not declared a conflict with the paper).\n%\n\\item{\\bf Having conflict. }\nIf a user has conflict with a paper, then the user is either an author of the paper or the\nconflict has been declared by that user or by a paper's author, in such a way that between\nthe moment when the conflict has been last declared and the current moment there is no\ntransition that successfully removes the conflict.\n%\n\\item{\\bf Conference reaching a phase. }\nIf a conference is in a given phase different from ``no phase'', then this has happened as\na consequence of either a conference approval action by the superuser (if the phase is\nSetup) or a phase change action by a chair (otherwise).\n\\end{description}\n\nMore details and explanations can be found in \\<^cite>\\<open>\\<open>Section 3.6\\<close> in \"cocon-JAR2021\"\\<close>.\n\\<close>\n\n\nsubsection \\<open>Preliminaries\\<close>\n\ninductive trace_between :: \"state \\<Rightarrow> (state,act,out) trans trace \\<Rightarrow> state \\<Rightarrow> bool\" where\n  empty[simp]: \"trace_between s [] s\"\n| step: \"\\<lbrakk>trace_between s tr sh; step sh a = (ou,s')\\<rbrakk> \\<Longrightarrow> trace_between s (tr@[Trans sh a ou s']) s'\"\n\ninductive_simps\n  trace_ft_empty[simp]: \"trace_between s [] s'\" and\n  trace_ft_snoc: \"trace_between s (tr@[trn]) s'\"\nthm trace_ft_empty trace_ft_snoc\n\nlemma trace_ft_append: \"trace_between s (tr1@tr2) s'\n  \\<longleftrightarrow> (\\<exists>sh. trace_between s tr1 sh \\<and> trace_between sh tr2 s')\"\n  apply (induction tr2 arbitrary: s' rule: rev_induct)\n   apply simp\n  apply (subst append_assoc[symmetric], subst trace_ft_snoc)\n  apply (auto simp: trace_ft_snoc)\n  done\n\nlemma trace_ft_Cons: \"trace_between s (trn#tr) s'\n  \\<longleftrightarrow> (\\<exists>sh ou a. trn = Trans s a ou sh \\<and> step s a = (ou,sh) \\<and> trace_between sh tr s')\"\n  apply (subst trace_ft_append[where ?tr1.0 = \"[trn]\", simplified])\n  apply (subst trace_ft_snoc[where tr = \"[]\", simplified])\n  by auto\n\nlemmas trace_ft_simps = trace_ft_empty trace_ft_snoc trace_ft_Cons trace_ft_append\n\ninductive trace_to :: \" (state,act,out) trans trace \\<Rightarrow> state \\<Rightarrow> bool\" where\n  empty: \"trace_to [] istate\"\n| step: \"\\<lbrakk>trace_to tr s; step s a = (ou,s')\\<rbrakk> \\<Longrightarrow> trace_to (tr@[Trans s a ou s']) s'\"\n\nlemma trace_to_ft: \"trace_to tr s \\<longleftrightarrow> trace_between istate tr s\"\nproof (rule,goal_cases)\n  case 1 thus ?case\n    by induction (auto intro: trace_between.intros)\nnext\n  case 2\n  moreover\n  {fix s' assume \"trace_between s' tr s\" hence \"s' = istate \\<longrightarrow> trace_to tr s\"\n   by induction (auto intro: trace_to.intros)\n  }\n  ultimately show ?case by auto\nqed\n\ninductive_simps trace_to_empty[simp]: \"trace_to [] s\"\n\nlemma trace_to_reach: assumes \"trace_to tr s\" shows \"reach s\"\n  using assms apply induction\n   apply (rule reach.intros)\n  by (metis reach_step snd_conv)\n\nlemma reach_to_trace: assumes \"reach s\" obtains tr where \"trace_to tr s\"\n  using assms apply (induction rule: reach_step_induct)\n   apply (auto intro: trace_to.intros) []\n  by (metis surjective_pairing trace_to.step)\n\nlemma reach_trace_to_conv: \"reach s \\<longleftrightarrow> (\\<exists>tr. trace_to tr s)\"\n  by (blast intro: trace_to_reach elim: reach_to_trace)\n\nthm trace_to.induct[no_vars]\n\nlemma trace_to_induct[case_names empty step, induct set]:\n  \"\\<lbrakk>trace_to x1 x2; P [] istate;\n  \\<And>tr s a ou s'.\n    \\<lbrakk>trace_to tr s; P tr s; reach s; reach s'; step s a = (ou, s')\\<rbrakk>\n    \\<Longrightarrow> P (tr ## Trans s a ou s') s'\\<rbrakk>\n  \\<Longrightarrow> P x1 x2\"\n  apply (erule trace_to.induct)\n   apply simp\n  apply (frule trace_to_reach)\n  using reach_PairI by blast\n\n\n\nsubsection \\<open>Authorship\\<close>\n\ntext \\<open>\n  Only the creator of a paper, and users explicitly added by other authors,\n  are authors of a paper.\n\\<close>\n\ninductive isAut' :: \"(state,act,out) trans trace \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> paperID \\<Rightarrow> bool\" where\n  creator: \"\\<lbrakk> trn = Trans _ (Cact (cPaper cid uid _ pid _ _)) outOK _ \\<rbrakk>\n    \\<Longrightarrow> isAut' (tr@[trn]) cid uid pid\"\n  (* \"The creator of a paper is an author\"  *)\n| co_author: \"\\<lbrakk>\n  isAut' tr cid uid' pid;\n  trn = Trans _ (Cact (cAuthor cid uid' _ pid uid)) outOK _ \\<rbrakk>\n  \\<Longrightarrow> isAut' (tr@[trn]) cid uid pid\"\n  (* \"An author can add any other user as a coauthor\" *)\n| irrelevant: \"isAut' tr cid uid' pid \\<Longrightarrow> isAut' (tr@[_]) cid uid' pid\"\n\nlemma justify_author:\n  assumes \"trace_to tr s\"\n  assumes \"isAut s cid uid pid\"\n  shows \"isAut' tr cid uid pid\"\n  using assms\nproof (induction arbitrary: uid)\n  case (empty s) thus ?case\n    by (auto simp add: istate_def)\nnext\n  case (step tr s a ou s')\n  show ?case\n  proof (cases \"isAut s cid uid pid\")\n    case True with step.IH show ?thesis by (blast intro: isAut'.intros)\n  next\n    case False\n    with step.hyps step.prems obtain\n      pass s1 s2 uid' where\n      \"a=Cact (cPaper cid uid pass pid s1 s2)\n      \\<or> (a=Cact (cAuthor cid uid' pass pid uid) \\<and> isAut s cid uid' pid)\"\n      and [simp]: \"ou=outOK\"\n      apply (cases a)\n        subgoal for x1 apply (cases x1, auto simp add: c_defs) [] .\n        subgoal for x2 apply (cases x2, auto simp add: u_defs) [] .\n        subgoal for x3 apply (cases x3, auto simp add: uu_defs) [] .\n        by simp_all\n    thus ?thesis using step.IH\n      apply (elim disjE)\n      apply (rule isAut'.creator, auto) []\n      apply (rule isAut'.co_author, auto) []\n      done\n  qed\nqed\n\n\nlemma author_justify:\n  assumes \"trace_to tr s\"\n  assumes \"isAut' tr cid uid pid\"\n  shows \"isAut s cid uid pid\"\n  using assms\nproof (induction arbitrary: uid)\n  case (empty s) thus ?case\n    by (auto simp add: istate_def elim: isAut'.cases)\nnext\n  case (step tr s a ou s')\n  from step.prems\n  show ?case\n  proof (cases)\n    case (creator _ _ pass s1 s2)\n    hence [simp]: \"a=Cact (cPaper cid uid pass pid s1 s2)\" \"ou=outOK\" by simp_all\n    from step.hyps show ?thesis\n      by (auto simp add: c_defs)\n  next\n    case (co_author _ uid' _ _ pass)\n    hence [simp]: \"a=Cact (cAuthor cid uid' pass pid uid)\" \"ou=outOK\" by simp_all\n    from step.hyps show ?thesis\n      by (auto simp add: c_defs)\n  next\n    case (irrelevant) with step.IH have AUT: \"isAut s cid uid pid\" by simp\n\n    note roles_confIDs[OF \\<open>reach s\\<close> AUT]\n    with AUT \\<open>step s a = (ou, s')\\<close> show ?thesis\n      apply (cases a)\n      subgoal for x1 apply (cases x1, auto simp: c_defs) [] .\n      subgoal for x2 apply (cases x2, auto simp: u_defs) [] .\n      subgoal for x3 apply (cases x3, auto simp: uu_defs) [] .\n      by simp_all\n  qed\nqed\n\ntheorem isAut_eq: \"trace_to tr s \\<Longrightarrow> isAut s cid uid pid \\<longleftrightarrow> isAut' tr cid uid pid\"\n  (* \"Trace-based equivalent of authorship\" *)\n  using justify_author author_justify\n  by (blast)\n\n\nsubsection \\<open>Becoming a Conference Chair\\<close>\n\ninductive isChair' :: \"(state,act,out) trans trace \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> bool\" where\n  creator: \"\\<lbrakk> trn=Trans _ (Cact (cConf cid uid _ _ _)) outOK _ \\<rbrakk>\n    \\<Longrightarrow> isChair' (tr@[trn]) cid uid\"\n| add_chair: \"\\<lbrakk> isChair' tr cid uid'; trn = Trans _ (Cact (cChair cid uid' _ uid)) outOK _ \\<rbrakk>\n  \\<Longrightarrow> isChair' (tr@[trn]) cid uid\"\n| irrelevant: \"\\<lbrakk>isChair' tr cid uid\\<rbrakk> \\<Longrightarrow> isChair' (tr@[_]) cid uid\"\n\nlemma justify_chair:\n  assumes \"trace_to tr s\"\n  assumes \"isChair s cid uid\"\n  shows \"isChair' tr cid uid\"\n  using assms\nproof (induction arbitrary: uid)\n  case (empty s) thus ?case\n    by (auto simp add: istate_def)\nnext\n  case (step tr s a ou s')\n  show ?case\n  proof (cases \"isChair s cid uid\")\n    case True with step.IH show ?thesis by (blast intro: isChair'.intros)\n  next\n    case False\n    term cConf\n    with step.hyps step.prems obtain\n      pass s1 s2 uid' where\n      \"a=Cact (cConf cid uid pass s1 s2)\n      \\<or> (a=Cact (cChair cid uid' pass uid) \\<and> isChair s cid uid')\"\n      and [simp]: \"ou=outOK\"\n      apply (cases a)\n      subgoal for x1 apply (cases x1, auto simp add: c_defs) [] .\n      subgoal for x2 apply (cases x2, auto simp add: u_defs) [] .\n      subgoal for x3 apply (cases x3, auto simp add: uu_defs) [] .\n      by simp_all\n    thus ?thesis using step.IH\n      apply (elim disjE)\n      apply (rule isChair'.creator, auto) []\n      apply (rule isChair'.add_chair, auto) []\n      done\n  qed\nqed\n\nlemma chair_justify:\n  assumes \"trace_to tr s\"\n  assumes \"isChair' tr cid uid\"\n  shows \"isChair s cid uid\"\n  using assms\nproof (induction arbitrary: uid)\n  case (empty s) thus ?case\n    by (auto simp add: istate_def elim: isChair'.cases)\nnext\n  case (step tr s a ou s')\n  from step.prems\n  show ?case\n  proof (cases)\n    case (creator _ _ pass s1 s2)\n    hence [simp]: \"a=Cact (cConf cid uid pass s1 s2)\" \"ou=outOK\" by simp_all\n    from step.hyps show ?thesis\n      by (auto simp add: c_defs)\n  next\n    case (add_chair _ uid' _ _ pass)\n    hence [simp]: \"a=Cact (cChair cid uid' pass uid)\" \"ou=outOK\" by simp_all\n    from step.hyps show ?thesis\n      by (auto simp add: c_defs)\n  next\n    case (irrelevant) with step.IH have CH: \"isChair s cid uid\" by simp\n\n    from CH \\<open>step s a = (ou, s')\\<close> show ?thesis\n      apply (cases a)\n      subgoal for x1 apply (cases x1, auto simp: c_defs) [] .\n      subgoal for x2 apply (cases x2, auto simp: u_defs) [] .\n      subgoal for x3 apply (cases x3, auto simp: uu_defs) [] .\n      by simp_all\n  qed\nqed\n\ntheorem isChair_eq: \"trace_to tr s \\<Longrightarrow> isChair s cid uid = isChair' tr cid uid\"\n  (* \"Trace-based equivalent of being a chair\" *)\n  using justify_chair chair_justify\n  by (blast)\n\n\nsubsection \\<open>Committee Membership\\<close>\n\ninductive isPC' :: \"(state,act,out) trans trace \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> bool\" where\n  chair: \"isChair' tr cid uid \\<Longrightarrow> isPC' tr cid uid\"\n| add_com: \"\\<lbrakk> isChair' tr cid uid'; trn = Trans _ (Cact (cPC cid uid' _ uid)) outOK _ \\<rbrakk>\n  \\<Longrightarrow> isPC' (tr@[trn]) cid uid\"\n| irrelevant: \"\\<lbrakk>isPC' tr cid uid\\<rbrakk> \\<Longrightarrow> isPC' (tr@[_]) cid uid\"\n\nlemma justify_com:\n  assumes \"trace_to tr s\"\n  assumes \"isPC s cid uid\"\n  shows \"isPC' tr cid uid\"\n  using assms\nproof (induction arbitrary: uid)\n  case (empty s) thus ?case\n    by (auto simp add: istate_def)\nnext\n  case (step tr s a ou s')\n\n  show ?case\n  proof (cases \"isPC s cid uid\")\n    case True with step.IH show ?thesis by (blast intro: isPC'.irrelevant)\n  next\n    case False note noPC = this\n    show ?thesis proof (cases \"isChair s' cid uid\")\n      case True thus ?thesis\n        by (metis chair justify_chair step.hyps(1) step.hyps(4) trace_to.step)\n    next\n      case False note noChair=this\n      from noPC noChair step.hyps step.prems obtain\n        pass uid' where \"(a=Cact (cPC cid uid' pass uid))\"\n        and \"isChair s cid uid'\"\n        and [simp]: \"ou=outOK\"\n        apply (cases a)\n        subgoal for x1 apply (cases x1, auto simp add: c_defs) [] .\n        subgoal for x2 apply (cases x2, auto simp add: u_defs) [] .\n        subgoal for x3 apply (cases x3, auto simp add: uu_defs) [] .\n        by simp_all\n      thus ?thesis\n        apply -\n        apply (rule isPC'.add_com, auto simp: isChair_eq[OF \\<open>trace_to tr s\\<close>]) []\n        done\n    qed\n  qed\nqed\n\nlemma com_justify:\n  assumes \"trace_to tr s\"\n  assumes \"isPC' tr cid uid\"\n  shows \"isPC s cid uid\"\n  using assms\nproof (induction arbitrary: uid)\n  case (empty s) thus ?case\n    by (auto simp add: istate_def elim!: isPC'.cases isChair'.cases)\nnext\n  case (step tr s a ou s')\n  from step.prems\n  show ?case\n  proof (cases)\n    case chair thus ?thesis\n      by (metis isChair_eq isChair_isPC step.hyps(1) step.hyps(3) step.hyps(4) trace_to.step)\n  next\n    case (add_com _ uid' _ _ pass)\n    hence [simp]: \"a=Cact (cPC cid uid' pass uid)\" \"ou=outOK\" by simp_all\n    from step.hyps show ?thesis\n      by (auto simp add: c_defs)\n  next\n    case (irrelevant) with step.IH have COM: \"isPC s cid uid\" by simp\n\n    from COM \\<open>step s a = (ou, s')\\<close> show ?thesis\n      apply (cases a)\n      subgoal for x1 apply (cases x1, auto simp: c_defs) [] .\n      subgoal for x2 apply (cases x2, auto simp: u_defs) [] .\n      subgoal for x3 apply (cases x3, auto simp: uu_defs) [] .\n      by simp_all\n  qed\nqed\n\ntheorem isPC_eq: \"trace_to tr s \\<Longrightarrow> isPC s cid uid = isPC' tr cid uid\"\n  (* \"Trace-based equivalent of committee membership\" *)\n  using justify_com com_justify\n  by (blast)\n\n\nsubsection \\<open>Being a Reviewer\\<close>\n\ninductive isRev' :: \"(state,act,out) trans trace \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> paperID \\<Rightarrow> bool\" where\n  add_rev: \"\\<lbrakk> isChair' tr cid uid'; trn = Trans _ (Cact (cReview cid uid' _ pid uid)) outOK _ \\<rbrakk>\n  \\<Longrightarrow> isRev' (tr@[trn]) cid uid pid\"\n| irrelevant: \"\\<lbrakk>isRev' tr cid uid pid\\<rbrakk> \\<Longrightarrow> isRev' (tr@[_]) cid uid pid\"\n\nlemma justify_rev:\n  assumes \"trace_to tr s\"\n  assumes \"isRev s cid uid pid\"\n  shows \"isRev' tr cid uid pid\"\n  using assms\nproof (induction)\n  case empty thus ?case\n    by (auto simp add: istate_def isRev_def)\nnext\n  case (step tr s a ou s')\n\n  show ?case\n  proof (cases \"isRev s cid uid pid\")\n    case True with step.IH show ?thesis by (blast intro: isRev'.irrelevant)\n  next\n    case False note noRev = this\n    with step.hyps step.prems obtain\n      pass uid' where \"(a=Cact (cReview cid uid' pass pid uid))\"\n      and \"isChair s cid uid'\"\n      and [simp]: \"ou=outOK\"\n      apply (cases a)\n      subgoal for x1 apply (cases x1, auto simp add: c_defs isRev_def) [] .\n      subgoal for x2 apply (cases x2, auto simp add: u_defs isRev_def) [] .\n      subgoal for x3 apply (cases x3, auto simp add: uu_defs isRev_def) [] .\n      by simp_all\n    thus ?thesis\n      apply -\n      apply (rule isRev'.add_rev, auto simp: isChair_eq[OF \\<open>trace_to tr s\\<close>]) []\n      done\n  qed\nqed\n\nlemma rev_justify:\n  assumes \"trace_to tr s\"\n  assumes \"isRev' tr cid uid pid\"\n  shows \"isRev s cid uid pid\"\n  using assms\nproof (induction arbitrary: uid)\n  case (empty s) thus ?case\n    by (auto simp add: istate_def elim!: isRev'.cases)\nnext\n  case (step tr s a ou s')\n  from step.prems\n  show ?case\n  proof (cases)\n    case (add_rev _ uid' _ _ pass)\n    hence [simp]: \"a=Cact (cReview cid uid' pass pid uid)\" \"ou=outOK\" by simp_all\n    from step.hyps show ?thesis\n      by (auto simp add: c_defs isRev_def)\n  next\n    case (irrelevant) with step.IH have REV: \"isRev s cid uid pid\" by simp\n\n    note roles_confIDs[OF step.hyps(2)]\n    with REV \\<open>step s a = (ou, s')\\<close> show ?thesis\n      apply (cases a)\n      subgoal for x1 apply (cases x1, auto simp: c_defs isRev_def) [] .\n      subgoal for x2 apply (cases x2, auto simp: u_defs isRev_def) [] .\n      subgoal for x3 apply (cases x3, auto simp: uu_defs isRev_def) [] .\n      by simp_all\n  qed\nqed\n\ntheorem isRev_eq: \"trace_to tr s \\<Longrightarrow> isRev s cid uid pid = isRev' tr cid uid pid\"\n  (* \"Trace-based equivalent of being a reviewer\" *)\n  using justify_rev rev_justify\n  by (blast)\n\n\n\nsubsection \"Conflicts\"\n\nfun irrev_conflict :: \"userID \\<Rightarrow> paperID \\<Rightarrow> (state,act,out) trans \\<Rightarrow> bool\"\n (* \"Transitions causing irrevokable conflicts\" *)\nwhere\n  \"irrev_conflict uid pid (Trans _ (Cact (cPaper _ uid' _ pid' _ _)) outOK _)\n    \\<longleftrightarrow> uid'=uid \\<and> pid'=pid\"\n| \"irrev_conflict uid pid (Trans _ (Cact (cAuthor _ _ _ pid' uid')) outOK _)\n    \\<longleftrightarrow> uid'=uid \\<and> pid'=pid\"\n| \"irrev_conflict uid pid _ \\<longleftrightarrow> False\"\n\nfun set_conflict :: \"userID \\<Rightarrow> paperID \\<Rightarrow> (state,act,out) trans \\<Rightarrow> bool\"\n  (* \"Transitions setting conflict state, can be revoked by later reset-actions\" *)\n  where\n  \"set_conflict uid pid (Trans _ (Cact (cConflict _ _ _ pid' uid')) outOK _)\n    \\<longleftrightarrow> uid'=uid \\<and> pid'=pid\"\n| \"set_conflict uid pid (Trans _ (Uact (uPref _ uid' _ pid' Conflict)) outOK _)\n    \\<longleftrightarrow> uid'=uid \\<and> pid'=pid\"\n| \"set_conflict _ _ _ \\<longleftrightarrow> False\"\n\nfun reset_conflict :: \"userID \\<Rightarrow> paperID \\<Rightarrow> (state,act,out)trans \\<Rightarrow> bool\"\n  (* \"Transitions re-setting conflict state, can be revoked by later set-actions\" *)\n  where\n  \"reset_conflict uid pid (Trans _ (Uact (uPref _ uid' _ pid' pr)) outOK _)\n    \\<longleftrightarrow> uid'=uid \\<and> pid'=pid \\<and> pr\\<noteq>Conflict\"\n| \"reset_conflict _ _ _ \\<longleftrightarrow> False\"\n\ndefinition conflict_trace :: \"userID \\<Rightarrow> paperID \\<Rightarrow> (state,act,out) trans trace \\<Rightarrow> bool\"\n  (* \"Trace that causes a conflict: It contains either an irrevokable conflict action,\n    or the last action concerning conflicts was set-conflict\" *)\n  where\n  \"conflict_trace uid pid tr \\<equiv>\n  (\\<exists>trn\\<in>set tr. irrev_conflict uid pid trn)\n\\<or> (\\<exists>tr1 trn tr2. tr=tr1@trn#tr2 \\<and>\n    set_conflict uid pid trn \\<and> (\\<forall>trn\\<in>set tr2. \\<not>reset_conflict uid pid trn))\"\n\nlemma irrev_conflict_impl_author:\n  assumes \"trace_to tr s\"\n  assumes \"\\<exists>trn\\<in>set tr. irrev_conflict uid pid trn\"\n  shows \"\\<exists>cid. isAut s cid uid pid\"\n  using assms\n  apply induction\n  apply (auto simp add: istate_def) []\n  subgoal for _ _ a apply (cases a)\n    subgoal for x1 apply (cases x1, auto simp: c_defs, (metis roles_confIDs)+) [] .\n    subgoal for x2 apply (cases x2, auto simp: u_defs) [] .\n    subgoal for x3 apply (cases x3, auto simp: uu_defs) [] .\n    by simp_all\n  done\n\nlemma irrev_conflict_impl_conflict:\n  assumes \"trace_to tr s\"\n  assumes \"\\<exists>trn\\<in>set tr. irrev_conflict uid pid trn\"\n  shows \"pref s uid pid = Conflict\"\n  by (metis assms(1) assms(2) irrev_conflict_impl_author\n    isAut_pref_Conflict reach_trace_to_conv)\n\nlemma conflict_justify:\n  assumes TR: \"trace_to tr s\"\n  assumes \"conflict_trace uid pid tr\"\n  shows \"pref s uid pid = Conflict\"\n  using assms(2)\n  unfolding conflict_trace_def\nproof (cases rule: disjE[consumes 1, case_names irrev set])\n  case irrev thus ?thesis by (simp add: irrev_conflict_impl_conflict[OF TR])\nnext\n  case set\n  then obtain tr1 trn tr2 where\n    [simp]: \"tr = tr1 @ trn # tr2\" and\n    SET: \"set_conflict uid pid trn\"\n    and NRESET: \"\\<forall>trn\\<in>set tr2. \\<not> reset_conflict uid pid trn\"\n    by blast\n\n  from TR obtain s1 s2 a ou where\n    [simp]: \"trn = Trans s1 a ou s2\" and\n    TR1: \"trace_to tr1 s1\" and\n    STEP: \"step s1 a = (ou,s2)\" and\n    TR2: \"trace_between s2 tr2 s\"\n    by (fastforce simp add: trace_to_ft trace_ft_simps)\n\n  from STEP SET have \"pref s2 uid pid = Conflict\"\n    apply (cases a)\n      subgoal for x1 apply (cases x1, auto simp: c_defs) [] .\n      subgoal for x2 apply (cases x2, auto simp: u_defs) []\n        subgoal for _ x65 apply (cases x65, auto) [] .\n        subgoal for _ _ _ x65 apply (cases x65, auto) [] .\n        subgoal for _ _ _ x65 apply (cases x65, auto) [] . .\n      by simp_all\n\n  with TR2 NRESET show ?thesis\n    apply induction\n    subgoal by simp\n    subgoal for _ _ _ a apply (cases a)\n      subgoal for x1 apply (cases x1, auto simp: c_defs) [] .\n      subgoal for x2 apply (cases x2, auto simp: u_defs) [] .\n      subgoal for x3 apply (cases x3, auto simp: uu_defs) [] .\n      by simp_all\n    done\nqed\n\nlemma justify_conflict:\n  assumes TR: \"trace_to tr s\"\n  assumes \"pref s uid pid = Conflict\"\n  shows \"conflict_trace uid pid tr\"\n  using assms\nproof induction\n  case empty thus ?case by (auto simp add: istate_def)\nnext\n  case (step tr s a ou s')\n\n  let ?trn = \"Trans s a ou s'\"\n\n  show ?case proof (cases \"pref s uid pid = Conflict\")\n    case False\n    with step.prems \\<open>step s a = (ou, s')\\<close>\n    have \"irrev_conflict uid pid ?trn \\<or> set_conflict uid pid ?trn\"\n      apply (cases a)\n      subgoal for x1 apply (cases x1, auto simp: c_defs) [] .\n      subgoal for x2 apply (cases x2, auto simp: u_defs) [] .\n      subgoal for x3 apply (cases x3, auto simp: uu_defs) [] .\n      by simp_all\n    thus ?thesis\n      unfolding conflict_trace_def by fastforce\n  next\n    case True with step.IH have CT: \"conflict_trace uid pid tr\" .\n\n    from step.prems \\<open>step s a = (ou, s')\\<close> have \"\\<not>reset_conflict uid pid ?trn\"\n      apply (cases a)\n      subgoal by simp\n      subgoal for x2 by (cases x2, auto simp: u_defs)\n      by simp_all\n\n    thus ?thesis using CT\n      unfolding conflict_trace_def\n      apply clarsimp\n      by (metis rotate1.simps(2) set_ConsD set_rotate1)\n\n  qed\nqed\n\ntheorem conflict_eq:\n  assumes \"trace_to tr s\"\n  shows \"pref s uid pid = Conflict \\<longleftrightarrow> conflict_trace uid pid tr\"\n  using assms conflict_justify justify_conflict by auto\n\n\nsubsection \\<open>Conference Phases\\<close>\n\nfun is_uPhase where\n  \"is_uPhase cid (Trans _ (Uact (uConfA cid' _ _)) outOK _) \\<longleftrightarrow> cid'=cid\"\n| \"is_uPhase cid (Trans _ (Uact (uPhase cid' _ _ _)) outOK _) \\<longleftrightarrow> cid'=cid\"\n| \"is_uPhase _ _ \\<longleftrightarrow> False\"\n\ninductive phase' :: \"(state,act,out) trans trace \\<Rightarrow> confID \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  initial: \"phase' [] cid noPH\"\n| approve: \"\\<lbrakk>phase' tr cid noPH; trn=Trans s (Uact (uConfA cid (voronkov s) _)) outOK _ \\<rbrakk>\n  \\<Longrightarrow> phase' (tr@[trn]) cid setPH\"\n| advance: \"\\<lbrakk>trn = (Trans _ (Uact (uPhase cid uid _ ph)) outOK _); isChair' tr cid uid\\<rbrakk>\n  \\<Longrightarrow> phase' (tr@[trn]) cid ph\"\n| irrelevant: \"\\<lbrakk>phase' tr cid ph; \\<not>is_uPhase cid trn \\<rbrakk> \\<Longrightarrow> phase' (tr@[trn]) cid ph\"\n\nlemma justify_phase:\n  assumes \"trace_to tr s\"\n  assumes \"phase s cid = ph\"\n  shows \"phase' tr cid ph\"\n  using assms\nproof (induction arbitrary: ph)\n  case (empty s) thus ?case\n    by (auto simp add: istate_def phase'.initial)\nnext\n  case (step tr s a ou s')\n  thus ?case\n    apply (cases a)\n    subgoal for x1 apply (cases x1, auto simp: c_defs intro: phase'.advance phase'.irrelevant) [] .\n    subgoal for x2 apply (cases x2,\n      auto\n        simp: u_defs isChair_eq\n        intro: phase'.advance phase'.irrelevant phase'.approve,\n      (fastforce intro: phase'.approve phase'.irrelevant phase'.advance)+\n    ) [] .\n\n    subgoal for x3 apply (cases x3, auto simp: uu_defs intro: phase'.irrelevant) [] .\n    by (auto intro: phase'.advance phase'.irrelevant)\nqed\n\nlemma phase_justify:\n  assumes \"trace_to tr s\"\n  assumes \"phase' tr cid ph\"\n  shows \"phase s cid = ph\"\n  using assms\nproof (induction arbitrary: ph)\n  case (empty s) thus ?case\n    by (auto simp add: istate_def elim: phase'.cases)\nnext\n  case (step tr s a ou s')\n  from step.prems\n  show ?case\n  proof (cases)\n    case (approve _ _ _ pass _)\n    hence [simp]: \"a=Uact (uConfA cid (voronkov s) pass)\" \"ou=outOK\" \"ph=setPH\" by simp_all\n    from step.hyps show ?thesis\n      by (auto simp add: u_defs)\n  next\n    case (advance _ _ uid pass _ _)\n    hence [simp]: \"a=Uact (uPhase cid uid pass ph)\" \"ou=outOK\" by simp_all\n    from step.hyps show ?thesis\n      by (auto simp add: u_defs)\n  next\n    case (irrelevant) with step.IH have PH: \"phase s cid = ph\" \"\\<not> is_uPhase cid (Trans s a ou s')\"\n      by simp_all\n\n    from PH \\<open>step s a = (ou, s')\\<close> show ?thesis\n    apply (cases a)\n    subgoal for x1 apply (cases x1, auto simp: c_defs) [] .\n    subgoal for x2 apply (cases x2, auto simp: u_defs) [] .\n    subgoal for x3 apply (cases x3, auto simp: uu_defs) [] .\n    by simp_all\n  qed auto\nqed\n\ntheorem phase_eq:\n  assumes \"trace_to tr s\"\n  shows \"phase s cid = ph \\<longleftrightarrow> phase' tr cid ph\"\n  using assms phase_justify justify_phase by blast\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/CoCon/Traceback_Properties.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.28424930096402395}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |               December 2004               |\n            |                   July 2005  (modified)   |\n            |              September 2005  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |                October 2005  (modified)   |\n            |                  April 2006  (modified)   |\n            |                  March 2007  (modified)   |\n            |                 August 2007  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2009         |\n            |                   June 2009  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory CSP_T_law_dist\nimports CSP_T_law_basic CSP_T_law_alpha_par\nbegin\n\n(*****************************************************************\n\n      distribution over internal choice\n\n         1. (P1 |~| P2) [+] Q\n         2. Q [+] (P1 |~| P2)\n         3. (P1 |~| P2) |[X]| Q\n         4. Q |[X]| (P1 |~| P2)\n         5. (P1 |~| P2) -- X\n         6. (P1 |~| P2) [[r]]\n         7. (P1 |~| P2) ;; Q\n         8. (P1 |~| P2) |. n\n         9. !! x:X .. (P1 |~| P2)\n\n *****************************************************************)\n\n(*********************************************************\n                dist law for Ext_choice (l)\n *********************************************************)\n\nlemma cspT_Ext_choice_dist_l: \n  \"(P1 |~| P2) [+] Q =T[M,M]\n   (P1 [+] Q) |~| (P2 [+] Q)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\napply (rule, simp add: in_traces, fast)+\ndone\n\n(*********************************************************\n                dist law for Ext_choice (r)\n *********************************************************)\n\nlemma cspT_Ext_choice_dist_r: \n  \"P [+] (Q1 |~| Q2) =T[M,M]\n   (P [+] Q1) |~| (P [+] Q2)\"\napply (rule cspT_rw_left)\napply (rule cspT_commut)\napply (rule cspT_rw_left)\napply (rule cspT_Ext_choice_dist_l)\napply (rule cspT_decompo)\napply (rule cspT_commut)+\ndone\n\n(*********************************************************\n                dist law for Parallel (l)\n *********************************************************)\n\nlemma cspT_Parallel_dist_l: \n  \"(P1 |~| P2) |[X]| Q =T[M,M]\n   (P1 |[X]| Q) |~| (P2 |[X]| Q)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\napply (rule, simp add: in_traces, fast)+\ndone\n\n(*********************************************************\n                dist law for Parallel (r)\n *********************************************************)\n\nlemma cspT_Parallel_dist_r: \n  \"P |[X]| (Q1 |~| Q2) =T[M,M]\n   (P |[X]| Q1) |~| (P |[X]| Q2)\"\napply (rule cspT_rw_left)\napply (rule cspT_commut)\napply (rule cspT_rw_left)\napply (rule cspT_Parallel_dist_l)\napply (rule cspT_decompo)\napply (rule cspT_commut)+\ndone\n\n(*********************************************************\n                dist law for Hiding\n *********************************************************)\n\nlemma cspT_Hiding_dist: \n  \"(P1 |~| P2) -- X =T[M,M]\n   (P1 -- X) |~| (P2 -- X)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\napply (rule, simp add: in_traces, fast)+\ndone\n\n(*********************************************************\n               dist law for Renaming\n *********************************************************)\n\nlemma cspT_Renaming_dist: \n  \"(P1 |~| P2) [[r]] =T[M,M]\n   (P1 [[r]]) |~| (P2 [[r]])\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\napply (rule, simp add: in_traces, fast)+\ndone\n\n(*********************************************************\n         dist law for Sequential composition\n *********************************************************)\n\nlemma cspT_Seq_compo_dist: \n  \"(P1 |~| P2) ;; Q =T[M,M]\n   (P1 ;; Q) |~| (P2 ;; Q)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\napply (rule, simp add: in_traces, fast)+\ndone\n\n(*********************************************************\n               dist law for Depth_rest\n *********************************************************)\n\nlemma cspT_Depth_rest_dist: \n  \"(P1 |~| P2) |. n =T[M,M]\n   (P1 |. n) |~| (P2 |. n)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\napply (rule, simp add: in_traces)\napply (rule, simp add: in_traces)\napply (force)\ndone\n\n(*********************************************************\n               dist law for Rep_int_choice\n *********************************************************)\n\nlemma cspT_Rep_int_choice_sum_dist:\n  \"!! c:C .. (Pf c |~| Qf c) =T[M,M] (!! c:C .. Pf c) |~| (!! c:C .. Qf c)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\napply (rule, simp add: in_traces, fast)+\ndone\n\nlemma cspT_Rep_int_choice_nat_dist:\n  \"!nat n:N .. (Pf n |~| Qf n) =T[M,M] (!nat n:N .. Pf n) |~| (!nat n:N .. Qf n)\"\nby (simp add: Rep_int_choice_ss_def cspT_Rep_int_choice_sum_dist)\n\nlemma cspT_Rep_int_choice_set_dist:\n  \"!set X:Xs .. (Pf X |~| Qf X) =T[M,M] (!set X:Xs .. Pf X) |~| (!set X:Xs .. Qf X)\"\nby (simp add: Rep_int_choice_ss_def cspT_Rep_int_choice_sum_dist)\n\nlemma cspT_Rep_int_choice_com_dist:\n  \"! a:X .. (Pf a |~| Qf a) =T[M,M] (! a:X .. Pf a) |~| (! a:X .. Qf a)\"\nby (simp add: Rep_int_choice_com_def cspT_Rep_int_choice_set_dist)\n\nlemma cspT_Rep_int_choice_f_dist:\n  \"inj f ==>\n   !<f> a:X .. (Pf a |~| Qf a) =T[M,M] (!<f> a:X .. Pf a) |~| (!<f> a:X .. Qf a)\"\nby (simp add: Rep_int_choice_f_def cspT_Rep_int_choice_com_dist)\n\nlemmas cspT_Rep_int_choice_dist =\n       cspT_Rep_int_choice_sum_dist\n       cspT_Rep_int_choice_nat_dist\n       cspT_Rep_int_choice_set_dist\n       cspT_Rep_int_choice_com_dist\n       cspT_Rep_int_choice_f_dist\n\n(*********************************************************\n                     dist laws\n *********************************************************)\n\nlemmas cspT_dist = cspT_Ext_choice_dist_l cspT_Ext_choice_dist_r\n                   cspT_Parallel_dist_l   cspT_Parallel_dist_r\n                   cspT_Hiding_dist       cspT_Renaming_dist\n                   cspT_Seq_compo_dist    cspT_Depth_rest_dist\n                   cspT_Rep_int_choice_dist\n\n(*****************************************************************\n\n      distribution over replicated internal choice\n\n         1. (!! :C .. Pf) [+] Q\n         2. Q [+] (!! :C .. Pf)\n         3. (!! :C .. Pf) |[X]| Q\n         4. Q |[X]| (!! :C .. Pf)\n         5. (!! :C .. Pf) -- X\n         6. (!! :C .. Pf) [[r]]\n         7. (!! :C .. Pf) |. n\n\n *****************************************************************)\n\n(*********************************************************\n                Rep_dist law for Ext_choice (l)\n *********************************************************)\n\nlemma cspT_Ext_choice_Dist_sum_l_nonempty: \n  \"sumset C ~= {} ==> (!! :C .. Pf) [+] Q =T[M,M]\n                      !! c:C .. (Pf c [+] Q)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\napply (rule, simp add: in_traces, fast)+\ndone\n\n(*** Dist ***)\n\nlemma cspT_Ext_choice_Dist_sum_l: \n  \"(!! :C .. Pf) [+] Q =T[M,M]\n   IF (sumset C={}) THEN (DIV [+] Q) ELSE (!! c:C .. (Pf c [+] Q))\"\napply (case_tac \"sumset C={}\")\napply (simp)\napply (rule cspT_rw_right)\napply (rule cspT_IF)\napply (rule cspT_decompo)\napply (rule cspT_Rep_int_choice_empty)\napply (simp_all)\n\napply (rule cspT_rw_right)\napply (rule cspT_IF)\napply (rule cspT_Ext_choice_Dist_sum_l_nonempty)\napply (simp)\ndone\n\n(*********************************************************\n                Dist_sum law for Ext_choice (r)\n *********************************************************)\n\nlemma cspT_Ext_choice_Dist_sum_r_nonempty: \n  \"sumset C ~= {} ==> P [+] (!! :C .. Qf) =T[M,M]\n               !! c:C .. (P [+] Qf c)\"\napply (rule cspT_rw_left)\napply (rule cspT_commut)\napply (rule cspT_rw_left)\napply (rule cspT_Ext_choice_Dist_sum_l_nonempty, simp)\napply (rule cspT_decompo, simp)\napply (rule cspT_commut)\ndone\n\n(*** Dist ***)\n\nlemma cspT_Ext_choice_Dist_sum_r: \n  \"P [+] (!! :C .. Qf) =T[M,M]\n   IF (sumset C={}) THEN (P [+] DIV) ELSE (!! c:C .. (P [+] Qf c))\"\napply (case_tac \"sumset C={}\")\napply (simp)\napply (rule cspT_rw_right)\napply (rule cspT_IF)\napply (rule cspT_decompo)\napply (simp)\napply (simp add: cspT_Rep_int_choice_empty)\n\napply (simp)\napply (rule cspT_rw_right)\napply (rule cspT_IF)\napply (rule cspT_Ext_choice_Dist_sum_r_nonempty)\napply (simp)\ndone\n\n(*********************************************************\n                Dist_sum law for Parallel (l)\n *********************************************************)\n\nlemma cspT_Parallel_Dist_sum_l_nonempty: \n  \"sumset C ~= {} ==>\n     (!! :C .. Pf) |[X]| Q =T[M,M]\n     !! c:C .. (Pf c |[X]| Q)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n apply (rule, simp add: in_traces)\n apply (elim disjE conjE exE bexE)\n  apply (subgoal_tac \"EX c. c: sumset C\")\n  apply (elim exE)\n  apply (rule disjI2)\n  apply (rule_tac x=\"c\" in bexI)\n  apply (simp)\n  apply (rule_tac x=\"<>\" in exI)\n  apply (rule_tac x=\"ta\" in exI)\n  apply (simp)\n  apply (simp)\n  apply (fast)\n  (* *)\n  apply (rule disjI2)\n  apply (rule_tac x=\"c\" in bexI)\n  apply (fast)\n  apply (simp)\n\n apply (rule, simp add: in_traces)\n apply (elim disjE conjE exE bexE)\n  apply (rule_tac x=\"<>\" in exI)\n  apply (rule_tac x=\"<>\" in exI)\n  apply (simp)\n  apply (fast)\ndone\n\n(*** Dist ***)\n\nlemma cspT_Parallel_Dist_sum_l: \n  \"(!! :C .. Pf) |[X]| Q =T[M,M]\n   IF (sumset C={}) THEN (DIV |[X]| Q) ELSE (!! c:C .. (Pf c |[X]| Q))\"\napply (case_tac \"sumset C={}\")\napply (simp)\napply (rule cspT_rw_right)\napply (rule cspT_IF)\napply (rule cspT_decompo)\napply (simp)\napply (simp add: cspT_Rep_int_choice_empty)\napply (simp)\n\napply (simp)\napply (rule cspT_rw_right)\napply (rule cspT_IF)\napply (rule cspT_Parallel_Dist_sum_l_nonempty)\napply (simp)\ndone\n\n(*********************************************************\n                Dist_sum law for Parallel (r)\n *********************************************************)\n\nlemma cspT_Parallel_Dist_sum_r_nonempty: \n  \"sumset C ~= {} ==>\n     P |[X]| (!! :C .. Qf) =T[M,M]\n     !! c:C .. (P |[X]| Qf c)\"\napply (rule cspT_rw_left)\napply (rule cspT_commut)\napply (rule cspT_rw_left)\napply (rule cspT_Parallel_Dist_sum_l_nonempty, simp)\napply (rule cspT_decompo, simp)\napply (rule cspT_commut)\ndone\n\n(*** Dist ***)\n\nlemma cspT_Parallel_Dist_sum_r: \n  \"P |[X]| (!! :C .. Qf) =T[M,M]\n   IF (sumset C={}) THEN (P |[X]| DIV) ELSE (!! c:C .. (P |[X]| Qf c))\"\napply (case_tac \"sumset C={}\")\napply (simp)\napply (rule cspT_rw_right)\napply (rule cspT_IF)\napply (rule cspT_decompo)\napply (simp)\napply (simp)\napply (simp add: cspT_Rep_int_choice_empty)\n\napply (simp)\napply (rule cspT_rw_right)\napply (rule cspT_IF)\napply (rule cspT_Parallel_Dist_sum_r_nonempty)\napply (simp)\ndone\n\n(*********************************************************\n                Dist_sum law for Hiding\n *********************************************************)\n\nlemma cspT_Hiding_Dist_sum: \n  \"(!! :C .. Pf) -- X =T[M,M]\n   !! c:C .. (Pf c -- X)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n apply (rule, simp add: in_traces)\n apply (elim disjE conjE exE, simp, fast)\n\n apply (rule, simp add: in_traces)\n apply (elim disjE conjE exE bexE)\n apply (rule_tac x=\"<>\" in exI, simp)\n apply (rule_tac x=\"s\" in exI, fast)\ndone\n\n(*********************************************************\n                Dist_sum law for Renaming\n *********************************************************)\n\nlemma cspT_Renaming_Dist_sum: \n  \"(!! :C .. Pf) [[r]] =T[M,M]\n   !! c:C .. (Pf c [[r]])\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n apply (rule, simp add: in_traces)\n apply (elim disjE conjE exE, simp, fast)\n apply (rule, simp add: in_traces)\n apply (elim disjE conjE exE, simp, fast)\ndone\n\n(*********************************************************\n          Dist_sum law for Sequential composition\n *********************************************************)\n\nlemma cspT_Seq_compo_Dist_sum: \n  \"(!! :C .. Pf) ;; Q =T[M,M]\n   !! c:C .. (Pf c ;; Q)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n apply (rule, simp add: in_traces)\n apply (elim disjE conjE exE bexE)\n apply (simp)\n apply (fast)\n apply (force)\n apply (rule disjI2)\n apply (rule_tac x=\"c\" in bexI)\n apply (force)\n apply (simp)\n\n apply (rule, simp add: in_traces)\n apply (elim disjE conjE exE bexE)\n apply (rule disjI1)\n apply (rule_tac x=\"<>\" in exI, simp)\n apply (fast)\n apply (fast)\ndone\n\n(*********************************************************\n                Dist_sum law for Depth_rest\n *********************************************************)\n\nlemma cspT_Depth_rest_Dist_sum: \n  \"(!! :C .. Pf) |. m =T[M,M]\n   !! c:C .. (Pf c |. m)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n apply (rule, simp add: in_traces)\n apply (rule, simp add: in_traces)\n apply (force)\ndone\n\n(*********************************************************\n                     Dist_sum laws\n *********************************************************)\n\nlemmas cspT_Dist_sum = cspT_Ext_choice_Dist_sum_l cspT_Ext_choice_Dist_sum_r\n                        cspT_Parallel_Dist_sum_l   cspT_Parallel_Dist_sum_r\n                        cspT_Hiding_Dist_sum       cspT_Renaming_Dist_sum\n                        cspT_Seq_compo_Dist_sum    cspT_Depth_rest_Dist_sum\n\nlemmas cspT_Dist_sum_nonempty = \n       cspT_Ext_choice_Dist_sum_l_nonempty cspT_Ext_choice_Dist_sum_r_nonempty\n       cspT_Parallel_Dist_sum_l_nonempty   cspT_Parallel_Dist_sum_r_nonempty\n       cspT_Hiding_Dist_sum       cspT_Renaming_Dist_sum\n       cspT_Seq_compo_Dist_sum    cspT_Depth_rest_Dist_sum\n\n(*****************************************************************\n\n      distribution over replicated internal choice\n\n         1. (!nat :C .. Pf) [+] Q\n         2. Q [+] (!nat :C .. Pf)\n         3. (!nat :C .. Pf) |[X]| Q\n         4. Q |[X]| (!nat :C .. Pf)\n         5. (!nat :C .. Pf) -- X\n         6. (!nat :C .. Pf) [[r]]\n         7. (!nat :C .. Pf) |. n\n\n *****************************************************************)\n\n(*********************************************************\n                Rep_dist law for Ext_choice (l)\n *********************************************************)\n\nlemma cspT_Ext_choice_Dist_nat_l_nonempty: \n  \"N ~= {} ==> (!nat :N .. Pf) [+] Q =T[M,M]\n               !nat n:N .. (Pf n [+] Q)\"\nby (simp add: Rep_int_choice_ss_def cspT_Dist_sum_nonempty)\n\n(*** Dist ***)\n\nlemma cspT_Ext_choice_Dist_nat_l: \n  \"(!nat :N .. Pf) [+] Q =T[M,M]\n   IF (N={}) THEN (DIV [+] Q) ELSE (!nat n:N .. (Pf n [+] Q))\"\napply (simp add: Rep_int_choice_ss_def)\napply (rule cspT_rw_left)\napply (rule cspT_Dist_sum)\napply (simp)\ndone\n\n(*********************************************************\n                Dist_nat law for Ext_choice (r)\n *********************************************************)\n\nlemma cspT_Ext_choice_Dist_nat_r_nonempty: \n  \"N ~= {} ==> P [+] (!nat :N .. Qf) =T[M,M]\n               !nat n:N .. (P [+] Qf n)\"\nby (simp add: Rep_int_choice_ss_def cspT_Dist_sum_nonempty)\n\n(*** Dist ***)\n\nlemma cspT_Ext_choice_Dist_nat_r: \n  \"P [+] (!nat :N .. Qf) =T[M,M]\n   IF (N={}) THEN (P [+] DIV) ELSE (!nat n:N .. (P [+] Qf n))\"\napply (simp add: Rep_int_choice_ss_def)\nby (rule cspT_rw_left, rule cspT_Dist_sum, simp)\n\n(*********************************************************\n                Dist_nat law for Parallel (l)\n *********************************************************)\n\nlemma cspT_Parallel_Dist_nat_l_nonempty: \n  \"N ~= {} ==>\n     (!nat :N .. Pf) |[X]| Q =T[M,M]\n     !nat n:N .. (Pf n |[X]| Q)\"\nby (simp add: Rep_int_choice_ss_def cspT_Dist_sum_nonempty)\n\n(*** Dist ***)\n\nlemma cspT_Parallel_Dist_nat_l: \n  \"(!nat :N .. Pf) |[X]| Q =T[M,M]\n   IF (N={}) THEN (DIV |[X]| Q) ELSE (!nat n:N .. (Pf n |[X]| Q))\"\napply (simp add: Rep_int_choice_ss_def)\nby (rule cspT_rw_left, rule cspT_Dist_sum, simp)\n\n(*********************************************************\n                Dist_nat law for Parallel (r)\n *********************************************************)\n\nlemma cspT_Parallel_Dist_nat_r_nonempty: \n  \"N ~= {} ==>\n     P |[X]| (!nat :N .. Qf) =T[M,M]\n     !nat n:N .. (P |[X]| Qf n)\"\nby (simp add: Rep_int_choice_ss_def cspT_Dist_sum_nonempty)\n\n(*** Dist ***)\n\nlemma cspT_Parallel_Dist_nat_r: \n  \"P |[X]| (!nat :N .. Qf) =T[M,M]\n   IF (N={}) THEN (P |[X]| DIV) ELSE (!nat n:N .. (P |[X]| Qf n))\"\napply (simp add: Rep_int_choice_ss_def)\nby (rule cspT_rw_left, rule cspT_Dist_sum, simp)\n\n(*********************************************************\n                Dist_nat law for Hiding\n *********************************************************)\n\nlemma cspT_Hiding_Dist_nat: \n  \"(!nat :N .. Pf) -- X =T[M,M]\n   !nat n:N .. (Pf n -- X)\"\nby (simp add: Rep_int_choice_ss_def cspT_Dist_sum)\n\n(*********************************************************\n                Dist_nat law for Renaming\n *********************************************************)\n\nlemma cspT_Renaming_Dist_nat: \n  \"(!nat :N .. Pf) [[r]] =T[M,M]\n   !nat n:N .. (Pf n [[r]])\"\nby (simp add: Rep_int_choice_ss_def cspT_Dist_sum)\n\n(*********************************************************\n          Dist_nat law for Sequential composition\n *********************************************************)\n\nlemma cspT_Seq_compo_Dist_nat: \n  \"(!nat :N .. Pf) ;; Q =T[M,M]\n   !nat n:N .. (Pf n ;; Q)\"\nby (simp add: Rep_int_choice_ss_def cspT_Dist_sum)\n\n(*********************************************************\n                Dist_nat law for Depth_rest\n *********************************************************)\n\nlemma cspT_Depth_rest_Dist_nat: \n  \"(!nat :N .. Pf) |. m =T[M,M]\n   !nat n:N .. (Pf n |. m)\"\nby (simp add: Rep_int_choice_ss_def cspT_Dist_sum)\n\n(*********************************************************\n                     Dist_nat laws\n *********************************************************)\n\nlemmas cspT_Dist_nat = cspT_Ext_choice_Dist_nat_l cspT_Ext_choice_Dist_nat_r\n                        cspT_Parallel_Dist_nat_l   cspT_Parallel_Dist_nat_r\n                        cspT_Hiding_Dist_nat       cspT_Renaming_Dist_nat\n                        cspT_Seq_compo_Dist_nat    cspT_Depth_rest_Dist_nat\n\nlemmas cspT_Dist_nat_nonempty = \n       cspT_Ext_choice_Dist_nat_l_nonempty cspT_Ext_choice_Dist_nat_r_nonempty\n       cspT_Parallel_Dist_nat_l_nonempty   cspT_Parallel_Dist_nat_r_nonempty\n       cspT_Hiding_Dist_nat       cspT_Renaming_Dist_nat\n       cspT_Seq_compo_Dist_nat    cspT_Depth_rest_Dist_nat\n\n(*****************************************************************\n\n      distribution over replicated internal choice\n\n         1. (!set :C .. Pf) [+] Q\n         2. Q [+] (!set :C .. Pf)\n         3. (!set :C .. Pf) |[X]| Q\n         4. Q |[X]| (!set :C .. Pf)\n         5. (!set :C .. Pf) -- X\n         6. (!set :C .. Pf) [[r]]\n         7. (!set :C .. Pf) |. n\n\n *****************************************************************)\n\n(*********************************************************\n                Rep_dist law for Ext_choice (l)\n *********************************************************)\n\nlemma cspT_Ext_choice_Dist_set_l_nonempty: \n  \"Xs ~= {} ==> (!set :Xs .. Pf) [+] Q =T[M,M]\n               !set X:Xs .. (Pf X [+] Q)\"\nby (simp add: Rep_int_choice_ss_def cspT_Dist_sum_nonempty)\n\n(*** Dist ***)\n\nlemma cspT_Ext_choice_Dist_set_l: \n  \"(!set :Xs .. Pf) [+] Q =T[M,M]\n   IF (Xs={}) THEN (DIV [+] Q) ELSE (!set X:Xs .. (Pf X [+] Q))\"\napply (simp add: Rep_int_choice_ss_def)\nby (rule cspT_rw_left, rule cspT_Dist_sum, simp)\n\n(*********************************************************\n                Dist_set law for Ext_choice (r)\n *********************************************************)\n\nlemma cspT_Ext_choice_Dist_set_r_nonempty: \n  \"Xs ~= {} ==> P [+] (!set :Xs .. Qf) =T[M,M]\n               !set X:Xs .. (P [+] Qf X)\"\nby (simp add: Rep_int_choice_ss_def cspT_Dist_sum_nonempty)\n\n(*** Dist ***)\n\nlemma cspT_Ext_choice_Dist_set_r: \n  \"P [+] (!set :Xs .. Qf) =T[M,M]\n   IF (Xs={}) THEN (P [+] DIV) ELSE (!set X:Xs .. (P [+] Qf X))\"\napply (simp add: Rep_int_choice_ss_def)\nby (rule cspT_rw_left, rule cspT_Dist_sum, simp)\n\n(*********************************************************\n                Dist_set law for Parallel (l)\n *********************************************************)\n\nlemma cspT_Parallel_Dist_set_l_nonempty: \n  \"Xs ~= {} ==>\n     (!set :Xs .. Pf) |[Y]| Q =T[M,M]\n     !set X:Xs .. (Pf X |[Y]| Q)\"\nby (simp add: Rep_int_choice_ss_def cspT_Dist_sum_nonempty)\n\n(*** Dist ***)\n\nlemma cspT_Parallel_Dist_set_l: \n  \"(!set :Xs .. Pf) |[Y]| Q =T[M,M]\n   IF (Xs={}) THEN (DIV |[Y]| Q) ELSE (!set X:Xs .. (Pf X |[Y]| Q))\"\napply (simp add: Rep_int_choice_ss_def)\nby (rule cspT_rw_left, rule cspT_Dist_sum, simp)\n\n(*********************************************************\n                Dist_set law for Parallel (r)\n *********************************************************)\n\nlemma cspT_Parallel_Dist_set_r_nonempty: \n  \"Xs ~= {} ==>\n     P |[Y]| (!set :Xs .. Qf) =T[M,M]\n     !set X:Xs .. (P |[Y]| Qf X)\"\nby (simp add: Rep_int_choice_ss_def cspT_Dist_sum_nonempty)\n\n(*** Dist ***)\n\nlemma cspT_Parallel_Dist_set_r: \n  \"P |[Y]| (!set :Xs .. Qf) =T[M,M]\n   IF (Xs={}) THEN (P |[Y]| DIV) ELSE (!set X:Xs .. (P |[Y]| Qf X))\"\napply (simp add: Rep_int_choice_ss_def)\nby (rule cspT_rw_left, rule cspT_Dist_sum, simp)\n\n(*********************************************************\n                Dist_set law for Hiding\n *********************************************************)\n\nlemma cspT_Hiding_Dist_set: \n  \"(!set :Xs .. Pf) -- Y =T[M,M]\n   !set X:Xs .. (Pf X -- Y)\"\nby (simp add: Rep_int_choice_ss_def cspT_Dist_sum)\n\n(*********************************************************\n                Dist_set law for Renaming\n *********************************************************)\n\nlemma cspT_Renaming_Dist_set: \n  \"(!set :Xs .. Pf) [[r]] =T[M,M]\n   !set X:Xs .. (Pf X [[r]])\"\nby (simp add: Rep_int_choice_ss_def cspT_Dist_sum)\n\n(*********************************************************\n          Dist_set law for Sequential composition\n *********************************************************)\n\nlemma cspT_Seq_compo_Dist_set: \n  \"(!set :Xs .. Pf) ;; Q =T[M,M]\n   !set X:Xs .. (Pf X ;; Q)\"\nby (simp add: Rep_int_choice_ss_def cspT_Dist_sum)\n\n(*********************************************************\n                Dist_set law for Depth_rest\n *********************************************************)\n\nlemma cspT_Depth_rest_Dist_set: \n  \"(!set :Xs .. Pf) |. m =T[M,M]\n   !set X:Xs .. (Pf X |. m)\"\nby (simp add: Rep_int_choice_ss_def cspT_Dist_sum)\n\n(*********************************************************\n                     Dist_set laws\n *********************************************************)\n\nlemmas cspT_Dist_set = cspT_Ext_choice_Dist_set_l cspT_Ext_choice_Dist_set_r\n                        cspT_Parallel_Dist_set_l   cspT_Parallel_Dist_set_r\n                        cspT_Hiding_Dist_set       cspT_Renaming_Dist_set\n                        cspT_Seq_compo_Dist_set    cspT_Depth_rest_Dist_set\n\nlemmas cspT_Dist_set_nonempty = \n       cspT_Ext_choice_Dist_set_l_nonempty cspT_Ext_choice_Dist_set_r_nonempty\n       cspT_Parallel_Dist_set_l_nonempty   cspT_Parallel_Dist_set_r_nonempty\n       cspT_Hiding_Dist_set       cspT_Renaming_Dist_set\n       cspT_Seq_compo_Dist_set    cspT_Depth_rest_Dist_set\n\n(*****************************************************************\n\n      for convenience\n\n         1. (! :X .. Pf) [+] Q\n         2. Q [+] (! :X .. Pf)\n         3. (! :X .. Pf) |[X]| Q\n         4. Q |[X]| (! :X .. Pf)\n         5. (! :X .. Pf) -- X\n         6. (! :X .. Pf) [[r]]\n         7. (! :X .. Pf) |. n\n\n *****************************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_Ext_choice_Dist_com_l_nonempty: \n  \"X ~= {}\n   ==> (! :X .. Pf) [+] Q =T[M,M] ! x:X .. (Pf x [+] Q)\"\nby (simp add: Rep_int_choice_com_def cspT_Dist_set_nonempty)\n\nlemma cspT_Ext_choice_Dist_com_r_nonempty: \n  \"X ~= {}\n   ==> P [+] (! :X .. Qf) =T[M,M] ! x:X .. (P [+] Qf x)\"\nby (simp add: Rep_int_choice_com_def cspT_Dist_set_nonempty)\n\nlemma cspT_Parallel_Dist_com_l_nonempty: \n  \"Y ~= {}\n   ==> (! :Y .. Pf) |[X]| Q =T[M,M] ! x:Y .. (Pf x |[X]| Q)\"\nby (simp add: Rep_int_choice_com_def cspT_Dist_set_nonempty)\n\nlemma cspT_Parallel_Dist_com_r_nonempty: \n  \"Y ~= {}\n   ==> P |[X]| (! :Y .. Qf) =T[M,M] ! x:Y .. (P |[X]| Qf x)\"\nby (simp add: Rep_int_choice_com_def cspT_Dist_set_nonempty)\n\nlemma cspT_Ext_choice_Dist_com_l: \n  \"(! :X .. Pf) [+] Q =T[M,M] \n   IF (X ={}) THEN (DIV [+] Q) ELSE (! x:X .. (Pf x [+] Q))\"\napply (simp add: Rep_int_choice_com_def)\nby (rule cspT_rw_left, rule cspT_Dist_set, simp)\n\nlemma cspT_Ext_choice_Dist_com_r: \n  \"P [+] (! :X .. Qf) =T[M,M]\n   IF (X ={}) THEN (P [+] DIV) ELSE (! x:X .. (P [+] Qf x))\"\napply (simp add: Rep_int_choice_com_def)\nby (rule cspT_rw_left, rule cspT_Dist_set, simp)\n\nlemma cspT_Parallel_Dist_com_l: \n  \"(! :Y .. Pf) |[X]| Q =T[M,M]\n   IF (Y ={}) THEN (DIV |[X]| Q) ELSE (! x:Y .. (Pf x |[X]| Q))\"\napply (simp add: Rep_int_choice_com_def)\nby (rule cspT_rw_left, rule cspT_Dist_set, simp)\n\nlemma cspT_Parallel_Dist_com_r: \n  \"P |[X]| (! :Y .. Qf) =T[M,M] \n   IF (Y ={}) THEN (P |[X]| DIV) ELSE (! x:Y .. (P |[X]| Qf x))\"\napply (simp add: Rep_int_choice_com_def)\nby (rule cspT_rw_left, rule cspT_Dist_set, simp)\n\nlemma cspT_Hiding_Dist_com: \n  \"(! :Y .. Pf) -- X =T[M,M] ! x:Y .. (Pf x -- X)\"\nby (simp add: Rep_int_choice_com_def cspT_Dist_set_nonempty)\n\nlemma cspT_Renaming_Dist_com: \n  \"(! :X .. Pf) [[r]] =T[M,M] ! x:X .. (Pf x [[r]])\"\nby (simp add: Rep_int_choice_com_def cspT_Dist_set_nonempty)\n\nlemma cspT_Seq_compo_Dist_com:\n  \"(! :X .. Pf) ;; Q =T[M,M] ! x:X .. (Pf x ;; Q)\"\nby (simp add: Rep_int_choice_com_def cspT_Dist_set_nonempty)\n\nlemma cspT_Depth_rest_Dist_com: \n  \"(! :X .. Pf) |. n =T[M,M] ! x:X .. (Pf x |. n)\"\nby (simp add: Rep_int_choice_com_def cspT_Dist_set_nonempty)\n\n(*********************************************************\n                     Dist laws\n *********************************************************)\n\nlemmas cspT_Dist_com = cspT_Ext_choice_Dist_com_l cspT_Ext_choice_Dist_com_r\n                           cspT_Parallel_Dist_com_l   cspT_Parallel_Dist_com_r\n                           cspT_Hiding_Dist_com       cspT_Renaming_Dist_com\n                           cspT_Seq_compo_Dist_com    cspT_Depth_rest_Dist_com\n\nlemmas cspT_Dist_com_nonempty = \n       cspT_Ext_choice_Dist_com_l_nonempty cspT_Ext_choice_Dist_com_r_nonempty\n       cspT_Parallel_Dist_com_l_nonempty   cspT_Parallel_Dist_com_r_nonempty\n       cspT_Hiding_Dist_com       cspT_Renaming_Dist_com\n       cspT_Seq_compo_Dist_com    cspT_Depth_rest_Dist_com\n\n(*****************************************************************\n\n      for convenience\n\n         1. (!<f> :X .. Pf) [+] Q\n         2. Q [+] (!<f> :X .. Pf)\n         3. (!<f> :X .. Pf) |[X]| Q\n         4. Q |[X]| (!<f> :X .. Pf)\n         5. (!<f> :X .. Pf) -- X\n         6. (!<f> :X .. Pf) [[r]]\n         7. (!<f> :X .. Pf) |. n\n\n *****************************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_Ext_choice_Dist_f_l_nonempty: \n  \"[| inj f ; X ~= {} |]\n   ==> (!<f> :X .. Pf) [+] Q =T[M,M] !<f> x:X .. (Pf x [+] Q)\"\nby (simp add: Rep_int_choice_f_def cspT_Dist_com_nonempty)\n\nlemma cspT_Ext_choice_Dist_f_r_nonempty: \n  \"[| inj f ; X ~= {} |]\n   ==> P [+] (!<f> :X .. Qf) =T[M,M] !<f> x:X .. (P [+] Qf x)\"\nby (simp add: Rep_int_choice_f_def cspT_Dist_com_nonempty)\n\nlemma cspT_Parallel_Dist_f_l_nonempty: \n  \"[| inj f ; Y ~= {} |]\n   ==> (!<f> :Y .. Pf) |[X]| Q =T[M,M] !<f> x:Y .. (Pf x |[X]| Q)\"\nby (simp add: Rep_int_choice_f_def cspT_Dist_com_nonempty)\n\nlemma cspT_Parallel_Dist_f_r_nonempty: \n  \"[| inj f ; Y ~= {} |]\n   ==> P |[X]| (!<f> :Y .. Qf) =T[M,M] !<f> x:Y .. (P |[X]| Qf x)\"\nby (simp add: Rep_int_choice_f_def cspT_Dist_com_nonempty)\n\nlemma cspT_Ext_choice_Dist_f_l: \n  \"(!<f> :X .. Pf) [+] Q =T[M,M] \n   IF (X ={}) THEN (DIV [+] Q) ELSE (!<f> x:X .. (Pf x [+] Q))\"\napply (simp add: Rep_int_choice_f_def)\nby (rule cspT_rw_left, rule cspT_Dist_com, simp)\n\nlemma cspT_Ext_choice_Dist_f_r: \n  \"P [+] (!<f> :X .. Qf) =T[M,M]\n   IF (X ={}) THEN (P [+] DIV) ELSE (!<f> x:X .. (P [+] Qf x))\"\napply (simp add: Rep_int_choice_f_def)\nby (rule cspT_rw_left, rule cspT_Dist_com, simp)\n\nlemma cspT_Parallel_Dist_f_l: \n  \"(!<f> :Y .. Pf) |[X]| Q =T[M,M]\n   IF (Y ={}) THEN (DIV |[X]| Q) ELSE (!<f> x:Y .. (Pf x |[X]| Q))\"\napply (simp add: Rep_int_choice_f_def)\nby (rule cspT_rw_left, rule cspT_Dist_com, simp)\n\nlemma cspT_Parallel_Dist_f_r: \n  \"P |[X]| (!<f> :Y .. Qf) =T[M,M] \n   IF (Y ={}) THEN (P |[X]| DIV) ELSE (!<f> x:Y .. (P |[X]| Qf x))\"\napply (simp add: Rep_int_choice_f_def)\nby (rule cspT_rw_left, rule cspT_Dist_com, simp)\n\nlemma cspT_Hiding_Dist_f: \n  \"(!<f> :Y .. Pf) -- X =T[M,M] !<f> x:Y .. (Pf x -- X)\"\nby (simp add: Rep_int_choice_f_def cspT_Dist_com)\n\nlemma cspT_Renaming_Dist_f: \n  \"(!<f> :X .. Pf) [[r]] =T[M,M] !<f> x:X .. (Pf x [[r]])\"\nby (simp add: Rep_int_choice_f_def cspT_Dist_com)\n\nlemma cspT_Seq_compo_Dist_f:\n  \"(!<f> :X .. Pf) ;; Q =T[M,M] !<f> x:X .. (Pf x ;; Q)\"\nby (simp add: Rep_int_choice_f_def cspT_Dist_com)\n\nlemma cspT_Depth_rest_Dist_f: \n  \"(!<f> :X .. Pf) |. n =T[M,M] !<f> x:X .. (Pf x |. n)\"\nby (simp add: Rep_int_choice_f_def cspT_Dist_com)\n\n(*********************************************************\n                     Dist laws\n *********************************************************)\n\nlemmas cspT_Dist_f = cspT_Ext_choice_Dist_f_l cspT_Ext_choice_Dist_f_r\n                           cspT_Parallel_Dist_f_l   cspT_Parallel_Dist_f_r\n                           cspT_Hiding_Dist_f       cspT_Renaming_Dist_f\n                           cspT_Seq_compo_Dist_f    cspT_Depth_rest_Dist_f\n\nlemmas cspT_Dist_f_nonempty = \n       cspT_Ext_choice_Dist_f_l_nonempty cspT_Ext_choice_Dist_f_r_nonempty\n       cspT_Parallel_Dist_f_l_nonempty   cspT_Parallel_Dist_f_r_nonempty\n       cspT_Hiding_Dist_f       cspT_Renaming_Dist_f\n       cspT_Seq_compo_Dist_f    cspT_Depth_rest_Dist_f\n\n(*** all rules ***)\n\nlemmas cspT_Dist = cspT_Dist_sum\n                   cspT_Dist_nat cspT_Dist_set cspT_Dist_com cspT_Dist_f\n\nlemmas cspT_Dist_nonempty = cspT_Dist_sum_nonempty\n                            cspT_Dist_nat_nonempty\n                            cspT_Dist_set_nonempty\n                            cspT_Dist_com_nonempty\n                            cspT_Dist_f_nonempty\n\n(*****************************************************************\n\n      additional distribution over replicated internal choice\n\n         1. (!! :X .. (a -> P))\n         2. (!! :Y .. (? :X -> P))\n\n *****************************************************************)\n\n(*********************************************************\n              Dist law for Act_prefix\n *********************************************************)\n\nlemma cspT_Act_prefix_Dist_sum:\n  \"sumset C ~= {} ==> \n   a -> (!! :C .. Pf) =T[M,M] !! c:C .. (a -> Pf c)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n(* <= *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim disjE conjE exE bexE)\n apply (simp_all)\n apply (force)\n apply (force)\n\n(* => *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim disjE conjE exE bexE)\n apply (simp_all)\n apply (force)\ndone\n\n(*********************************************************\n              Dist_nat law for Ext_pre_choice\n *********************************************************)\n\nlemma cspT_Ext_pre_choice_Dist_sum:\n  \"sumset C ~= {} ==> \n   ? x:X -> (!! c:C .. (Pf c) x) =T[M,M] !! c:C .. (? :X -> (Pf c))\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n(* <= *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim disjE conjE exE bexE)\n apply (simp_all)\n apply (force)\n apply (force)\n\n(* => *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim disjE conjE exE bexE)\n apply (simp_all)\n apply (force)\ndone\n\n(*****************************************************************\n                     for convenienve\n *****************************************************************)\n\n(* nat *)\n\nlemma cspT_Act_prefix_Dist_nat:\n  \"N ~= {} ==> \n   a -> (!nat :N .. Pf) =T[M,M] !nat n:N .. (a -> Pf n)\"\nby (simp add: Rep_int_choice_ss_def cspT_Act_prefix_Dist_sum)\n\nlemma cspT_Ext_pre_choice_Dist_nat:\n  \"N ~= {} ==> \n   ? x:X -> (!nat n:N .. (Pf n) x) =T[M,M] !nat n:N .. (? :X -> (Pf n))\"\nby (simp add: Rep_int_choice_ss_def cspT_Ext_pre_choice_Dist_sum)\n\n(* set *)\n\nlemma cspT_Act_prefix_Dist_set:\n  \"Xs ~= {} ==> \n   a -> (!set :Xs .. Pf) =T[M,M] !set X:Xs .. (a -> Pf X)\"\nby (simp add: Rep_int_choice_ss_def cspT_Act_prefix_Dist_sum)\n\nlemma cspT_Ext_pre_choice_Dist_set:\n  \"Ys ~= {} ==> \n   ? x:X -> (!set Y:Ys .. (Pf Y) x) =T[M,M] !set Y:Ys .. (? :X -> (Pf Y))\"\nby (simp add: Rep_int_choice_ss_def cspT_Ext_pre_choice_Dist_sum)\n\n(* com *)\n\nlemma cspT_Act_prefix_Dist_com:\n  \"X ~= {} ==> \n   a -> (! :X .. Pf) =T[M,M] ! x:X .. (a -> Pf x)\"\nby (simp add: Rep_int_choice_com_def cspT_Act_prefix_Dist_set)\n\nlemma cspT_Ext_pre_choice_Dist_com:\n  \"Y ~= {} ==> \n   ? x:X -> (! y:Y .. (Pf y) x) =T[M,M] ! y:Y .. (? :X -> (Pf y))\"\nby (simp add: Rep_int_choice_com_def cspT_Ext_pre_choice_Dist_set)\n\n(* f *)\n\nlemma cspT_Act_prefix_Dist_f:\n  \"X ~= {} ==> \n   a -> (!<f> :X .. Pf) =T[M,M] !<f> x:X .. (a -> Pf x)\"\nby (simp add: Rep_int_choice_f_def cspT_Act_prefix_Dist_com)\n\nlemma cspT_Ext_pre_choice_Dist_f:\n  \"Y ~= {} ==> \n   ? x:X -> (!<f> y:Y .. (Pf y) x) =T[M,M] !<f> y:Y .. (? :X -> (Pf y))\"\nby (simp add: Rep_int_choice_f_def cspT_Ext_pre_choice_Dist_com)\n\n(*** arias ***)\n\nlemmas cspT_Act_prefix_Dist \n     = cspT_Act_prefix_Dist_sum\n       cspT_Act_prefix_Dist_nat\n       cspT_Act_prefix_Dist_set\n       cspT_Act_prefix_Dist_com\n       cspT_Act_prefix_Dist_f\n\nlemmas cspT_Ext_pre_choice_Dist\n     = cspT_Ext_pre_choice_Dist_sum\n       cspT_Ext_pre_choice_Dist_nat\n       cspT_Ext_pre_choice_Dist_set\n       cspT_Ext_pre_choice_Dist_com\n       cspT_Ext_pre_choice_Dist_f\n\n(*****************************************************************\n      distribution over external choice\n         1. (P1 [+] P2) [[r]]\n         2. (P1 [+] P2) |. n\n *****************************************************************)\n\n(*********************\n     [[r]]-[+]-dist\n *********************)\n\nlemma cspT_Renaming_Ext_dist:\n  \"(P1 [+] P2) [[r]] =T[M,M]\n   (P1 [[r]]) [+] (P2 [[r]])\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_traces)\n apply (force)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_traces)\n apply (force)\ndone\n\n(*********************\n     |.-[+]-dist\n *********************)\n\nlemma cspT_Depth_rest_Ext_dist: \n  \"(P1 [+] P2) |. n =T[M,M]\n   (P1 |. n) [+] (P2 |. n)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_traces)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_traces)\n apply (force)\ndone\n\nlemmas cspT_Ext_dist = cspT_Renaming_Ext_dist cspT_Depth_rest_Ext_dist\n\n(*---------------------------------------------------------*\n |                   complex distribution                  |\n *---------------------------------------------------------*)\n\n(*********************\n     !!-input-!set\n *********************)\n\nlemma cspT_Rep_int_choice_sum_input_set:\n  \"(!! c:C .. (? :(Yf c) -> Rff c))\n   =T[M,M]\n   (!set Y : {(Yf c)|c. c: sumset C} .. \n      (? a : Y -> (!! c:{c:C. a : Yf c}s .. Rff c a)))\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n(* => *)\n apply (rule, simp add: in_traces)\n apply (elim disjE conjE exE bexE)\n apply (simp_all)\n  apply (force)\n\n(* <= *)\n apply (rule, simp add: in_traces)\n apply (elim disjE conjE exE)\n apply (simp_all)\n apply (fast)\n apply (force)\ndone\n\nlemma cspT_Rep_int_choice_nat_input_set:\n  \"(!nat n:N .. (? :(Yf n) -> Rff n))\n   =T[M,M]\n   (!set Y : {(Yf n)|n. n:N} .. (? a : Y -> (!nat n:{n:N. a : Yf n} .. Rff n a)))\"\napply (simp add: Rep_int_choice_ss_def)\napply (rule cspT_rw_left)\napply (rule cspT_Rep_int_choice_sum_input_set)\napply (simp add: Rep_int_choice_ss_def)\napply (rule cspT_decompo)\napply (auto)\napply (rule_tac x=\"type2 n\" in exI)\nby (auto)\n\nlemma cspT_Rep_int_choice_set_input_set:\n  \"(!set X:Xs .. (? :(Yf X) -> Rff X))\n   =T[M,M]\n   (!set Y : {(Yf X)|X. X:Xs} .. (? a : Y -> (!set X:{X:Xs. a : Yf X} .. Rff X a)))\"\napply (simp add: Rep_int_choice_ss_def)\napply (rule cspT_rw_left)\napply (rule cspT_Rep_int_choice_sum_input_set)\napply (simp add: Rep_int_choice_ss_def)\napply (rule cspT_decompo)\napply (auto)\napply (rule_tac x=\"type1 X\" in exI)\nby (auto)\n\nlemmas cspT_Rep_int_choice_input_set =\n       cspT_Rep_int_choice_sum_input_set\n       cspT_Rep_int_choice_nat_input_set\n       cspT_Rep_int_choice_set_input_set\n\n(*-------------------------------*\n          !!-[+]-Dist\n *-------------------------------*)\n\nlemma cspT_Rep_int_choice_Ext_Dist_sum:\n  \"ALL c:sumset C. (Qf c = SKIP | Qf c = DIV) ==>\n   (!! c:C .. (Pf c [+] Qf c)) =T[M,M]\n   ((!! :C .. Pf) [+] (!! :C .. Qf))\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim conjE exE bexE disjE)\n apply (simp_all)\n apply (force)\n apply (drule_tac x=\"c\" in bspec)\n apply (simp)\n apply (erule disjE)\n apply (simp_all add: in_traces)\n apply (erule disjE)\n apply (simp_all)\n apply (rule disjI2)\n apply (rule_tac x=\"c\" in bexI)\n apply (simp_all add: in_traces)\n\n(* => *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim conjE exE bexE disjE)\n apply (simp_all)\n apply (fast)\n apply (fast)\ndone\n\nlemma cspT_Rep_int_choice_Ext_Dist_nat:\n  \"ALL n:N. (Qf n = SKIP | Qf n = DIV) ==>\n   (!nat n:N .. (Pf n [+] Qf n)) =T[M,M]\n   ((!nat :N .. Pf) [+] (!nat :N .. Qf))\"\napply (simp add: Rep_int_choice_ss_def)\napply (rule cspT_Rep_int_choice_Ext_Dist_sum)\nby (auto)\n\nlemma cspT_Rep_int_choice_Ext_Dist_set:\n  \"ALL X:Xs. (Qf X = SKIP | Qf X = DIV) ==>\n   (!set X:Xs .. (Pf X [+] Qf X)) =T[M,M]\n   ((!set :Xs .. Pf) [+] (!set :Xs .. Qf))\"\napply (simp add: Rep_int_choice_ss_def)\napply (rule cspT_Rep_int_choice_Ext_Dist_sum)\nby (auto)\n\nlemma cspT_Rep_int_choice_Ext_Dist_com:\n  \"ALL a:X. (Qf a = SKIP | Qf a = DIV) ==>\n   (! a:X .. (Pf a [+] Qf a)) =T[M,M]\n   ((! :X .. Pf) [+] (! :X .. Qf))\"\napply (simp add: Rep_int_choice_com_def)\napply (rule cspT_Rep_int_choice_Ext_Dist_set)\nby (auto)\n\nlemma cspT_Rep_int_choice_Ext_Dist_f:\n  \"[| inj f ; ALL a:X. (Qf a = SKIP | Qf a = DIV) |] ==>\n   (!<f> a:X .. (Pf a [+] Qf a)) =T[M,M]\n   ((!<f> :X .. Pf) [+] (!<f> :X .. Qf))\"\napply (simp add: Rep_int_choice_f_def)\napply (rule cspT_Rep_int_choice_Ext_Dist_com)\nby (auto)\n\nlemmas cspT_Rep_int_choice_Ext_Dist =\n       cspT_Rep_int_choice_Ext_Dist_sum\n       cspT_Rep_int_choice_Ext_Dist_nat\n       cspT_Rep_int_choice_Ext_Dist_set\n       cspT_Rep_int_choice_Ext_Dist_com\n       cspT_Rep_int_choice_Ext_Dist_f\n\n(*-------------------------------*\n          !!-input-Dist\n *-------------------------------*)\n\nlemma cspT_Rep_int_choice_input:\n  \"!set X:Xs .. (? :X -> Pf) =T[M,M] (? :(Union Xs) -> Pf)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n(* => *)\n apply (rule, simp add: in_traces)\n apply (force)\n\n(* <= *)\n apply (rule, simp add: in_traces)\n apply (force)\ndone\n\nlemma cspT_Rep_int_choice_input_Dist:\n  \"(!set X:Xs .. (? :X -> Pf)) [+] Q =T[M,M] (? :(Union Xs) -> Pf) [+] Q\"\napply (rule cspT_decompo)\napply (rule cspT_Rep_int_choice_input)\napply (rule cspT_reflex)\ndone\n\n(* =================================================== *\n |             addition for CSP-Prover 5               |\n * =================================================== *)\n\n(* --------------------------------------------------- *\n     distribution hiding over sequential composition\n * --------------------------------------------------- *)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_Seq_compo_hide_dist: \n  \"(P ;; Q) -- X =T[M,M] (P -- X) ;; (Q -- X)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim conjE exE disjE)\n apply (simp_all)\n\n  (* 1 *)\n apply (rule disjI1)\n apply (rule_tac x=\"sa --tr X\" in exI)\n apply (simp add: rmTick_hide)\n apply (rule_tac x=\"sa\" in exI)\n apply (simp)\n\n  (* 2 *)\n apply (rule disjI2)\n apply (rule_tac x=\"sa --tr X\" in exI)\n apply (rule_tac x=\"ta --tr X\" in exI)\n apply (simp)\n apply (rule conjI)\n  apply (rule_tac x=\"sa ^^^ <Tick>\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"ta\" in exI)\n  apply (simp)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim disjE conjE exE)\n  (* 1 *)\n  apply (insert trace_last_noTick_or_Tick)\n  apply (drule_tac x=\"sa\" in spec)\n  apply (elim disjE conjE exE)\n   apply (simp)\n   apply (rule_tac x=\"sa\" in exI)\n   apply (simp)\n   apply (rule disjI1)\n   apply (rule_tac x=\"sa\" in exI)\n   apply (simp)\n\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (simp)\n   apply (rule disjI1)\n   apply (rule_tac x=\"sb ^^^ <Tick>\" in exI)\n   apply (simp)\n\n (* 2 *)\n  apply (drule_tac x=\"sa\" in spec)\n  apply (elim disjE conjE exE)\n   apply (simp)\n   apply (subgoal_tac \"noTick(sa --tr X)\")\n   apply (rotate_tac 2)\n   apply (drule sym)\n   apply (simp del: hide_tr_noTick)\n   apply (simp)\n\n   apply (simp)\n   apply (rule_tac x=\"sc ^^^ sb\" in exI)\n   apply (simp)\n   apply (rule disjI2)\n   apply (rule_tac x=\"sc\" in exI)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (simp)\ndone\n\n\n(* --------------------------------------------------- *\n         distribution hiding over interleaving\n * --------------------------------------------------- *)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_Interleave_hide_dist: \n  \"(P ||| Q) -- X =T[M,M] (P -- X) ||| (Q -- X)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim conjE exE disjE)\n apply (simp_all)\n apply (rule_tac x=\"sa --tr X\" in exI)\n apply (rule_tac x=\"ta --tr X\" in exI)\n apply (simp add: interleave_of_hide_tr_ex)\n apply (force)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim disjE conjE exE)\n\n apply (simp add: interleave_of_hide_tr_ex)\n apply (elim conjE exE)\n apply (simp)\n apply (rule_tac x=\"v\" in exI)\n apply (simp)\n apply (force)\ndone\n\n(* --------------------------------------------------- *\n    distribution renaming over sequential composition\n * --------------------------------------------------- *)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_Seq_compo_renaming_dist: \n  \"(P ;; Q) [[r]] =T[M,M] (P [[r]]) ;; (Q [[r]])\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim conjE exE disjE)\n apply (simp_all)\n\n  (* 1 *)\n  apply (rule disjI1)\n  apply (rule_tac x=\"t\" in exI)\n  apply (subgoal_tac \"noTick t\")\n  apply (simp)\n  apply (rule_tac x=\"rmTick sa\" in exI)\n  apply (simp)\n  apply (rule memT_prefix_closed)\n  apply (simp)\n  apply (simp)\n  apply (rule ren_tr_noTick_left)\n  apply (simp)\n  apply (simp)\n\n  (* 2 *)\n  apply (rule disjI2)\n  apply (simp add: ren_tr_appt_decompo_left)\n  apply (elim conjE exE)\n\n  apply (simp)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"t2\" in exI)\n  apply (simp)\n  apply (rule conjI)\n\n   apply (rule_tac x=\"sa ^^^ <Tick>\" in exI)\n   apply (simp add: ren_tr_noTick_left)\n\n   apply (simp add: ren_tr_noTick_left)\n   apply (rule_tac x=\"ta\" in exI)\n   apply (simp)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim disjE conjE exE)\n  (* 1 *)\n  apply (insert trace_last_noTick_or_Tick)\n  apply (drule_tac x=\"s\" in spec)\n  apply (elim disjE conjE exE)\n   apply (simp)\n   apply (rule_tac x=\"sa\" in exI)\n   apply (simp)\n   apply (rule disjI1)\n   apply (rule_tac x=\"sa\" in exI)\n   apply (simp)\n   apply (simp add: ren_tr_noTick_right)\n\n   apply (simp)\n   apply (simp add: ren_tr_appt_decompo_right)\n   apply (elim conjE exE)\n   apply (simp)\n   apply (rule_tac x=\"s1\" in exI)\n   apply (simp)\n   apply (rule disjI1)\n   apply (rule_tac x=\"s1 ^^^ <Tick>\" in exI)\n   apply (simp)\n\n (* 2 *)\n  apply (simp)\n  apply (simp add: ren_tr_appt_decompo_right)\n  apply (elim conjE exE)\n  apply (simp)\n  apply (rule_tac x=\"s1 ^^^ sb\" in exI)\n  apply (rule conjI)\n\n   apply (force)\n   apply (force)\ndone\n\n\n(* --------------------------------------------------- *\n         distribution renaming over interleaving\n * --------------------------------------------------- *)\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_Interleave_renaming_dist: \n  \"(P ||| Q) [[r]] =T[M,M] (P [[r]]) ||| (Q [[r]])\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim conjE exE disjE)\n apply (insert interleave_of_ren_tr_only_if_all)\n apply (drule_tac x=\"s\" in spec)\n apply (drule_tac x=\"r\" in spec)\n apply (drule_tac x=\"t\" in spec)\n apply (drule_tac x=\"sa\" in spec)\n apply (drule_tac x=\"ta\" in spec)\n apply (force)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim conjE exE disjE)\n apply (erule rem_asmE)\n apply (insert interleave_of_ren_tr_if_all)\n apply (drule_tac x=\"t\" in spec)\n apply (drule_tac x=\"r\" in spec)\n apply (drule_tac x=\"sa\" in spec)\n apply (drule_tac x=\"sb\" in spec)\n apply (drule_tac x=\"s\" in spec)\n apply (drule_tac x=\"ta\" in spec)\n apply (force)\ndone\n\n(* --------------------------------------------------- *\n     distribution internal choice over prefix\n * --------------------------------------------------- *)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_Act_prefix_dist:\n  \"a -> (P |~| Q) =T[M,M] (a -> P) |~| (a -> Q)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n(* <= *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim disjE conjE exE bexE)\n apply (simp_all)\n\n(* => *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim disjE conjE exE bexE)\n apply (simp_all)\ndone\n\n\nlemma cspT_Int_choice_Act_prefix_delay:\n  \"(a -> P) |~| (a -> Q) =T[M,M] a -> (P |~| Q)\"\napply (rule cspT_sym)\napply (simp add: cspT_Act_prefix_dist)\ndone\n\nlemma cspT_Int_choice_Act_prefix_delay_eq:\n  \"a = b ==> (a -> P) |~| (b -> Q) =T[M,M] a -> (P |~| Q)\"\napply (simp add: cspT_Int_choice_Act_prefix_delay)\ndone\n\n\n(* --------------------------------------------------- *\n     distribution internal choice over prefix choice\n * --------------------------------------------------- *)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_Ext_pre_choice_dist:\n  \"? x:X -> (Pf x |~| Qf x) =T[M,M] (? x:X -> Pf x) |~| (? x:X -> Qf x)\"\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n(* <= *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim disjE conjE exE bexE)\n apply (simp_all)\n\n(* => *)\n apply (rule)\n apply (simp add: in_traces)\n apply (elim disjE conjE exE bexE)\n apply (simp_all)\ndone\n\n\nlemma cspT_Int_choice_Ext_pre_choice_delay:\n  \"(? x:X -> Pf x) |~| (? x:X -> Qf x)  =T[M,M] ? x:X -> (Pf x |~| Qf x)\"\napply (rule cspT_sym)\napply (simp add: cspT_Ext_pre_choice_dist)\ndone\n\nlemma cspT_Int_choice_Ext_pre_choice_delay_eq:\n  \"X = Y ==>\n  (? x:X -> Pf x) |~| (? x:Y -> Qf x)\n  =T[M,M] ? x:X -> (Pf x |~| Qf x)\"\napply (simp add: cspT_Int_choice_Ext_pre_choice_delay)\ndone\n\n\n(*  replicated internal choice *)\n\nlemma cspT_Act_prefix_delay_sum:\n  \"!! c:C .. (a -> Pf c) =T[M,M] \n   IF (sumset C = {}) THEN DIV ELSE (a -> (!! c:C .. (Pf c)))\"\napply (rule cspT_rw_right)\napply (rule cspT_IF_split)\napply (case_tac \"sumset C = {}\")\napply (simp add: cspT_Rep_int_choice_DIV)\napply (simp)\napply (rule cspT_sym)\napply (simp add: cspT_Act_prefix_Dist)\ndone\n\nlemma cspT_Ext_pre_choice_delay_sum:\n  \"!! c:C .. (? :X -> (Pf c)) =T[M,M] \n   IF (sumset C = {}) THEN DIV ELSE (? x:X -> (!! c:C .. (Pf c) x))\"\napply (rule cspT_rw_right)\napply (rule cspT_IF_split)\napply (case_tac \"sumset C = {}\")\napply (simp add: cspT_Rep_int_choice_DIV)\napply (simp)\napply (rule cspT_sym)\napply (simp add: cspT_Ext_pre_choice_Dist)\ndone\n\nlemma cspT_Act_prefix_delay_nat:\n  \"!nat n:N .. (a -> Pf n) =T[M,M] \n   IF (N = {}) THEN DIV ELSE (a -> (!nat n:N .. (Pf n)))\"\napply (rule cspT_rw_right)\napply (rule cspT_IF_split)\napply (case_tac \"N = {}\")\napply (simp add: cspT_Rep_int_choice_DIV)\napply (simp)\napply (rule cspT_sym)\napply (simp add: cspT_Act_prefix_Dist)\ndone\n\nlemma cspT_Ext_pre_choice_delay_nat:\n  \"!nat n:N .. (? :X -> (Pf n)) =T[M,M] \n   IF (N = {}) THEN DIV ELSE (? x:X -> (!nat n:N .. (Pf n) x))\"\napply (rule cspT_rw_right)\napply (rule cspT_IF_split)\napply (case_tac \"N = {}\")\napply (simp add: cspT_Rep_int_choice_DIV)\napply (simp)\napply (rule cspT_sym)\napply (simp add: cspT_Ext_pre_choice_Dist)\ndone\n\nlemma cspT_Act_prefix_delay_set:\n  \"!set X:Xs .. (a -> Pf X) =T[M,M] \n   IF (Xs = {}) THEN DIV ELSE (a -> (!set X:Xs .. (Pf X)))\"\napply (rule cspT_rw_right)\napply (rule cspT_IF_split)\napply (case_tac \"Xs = {}\")\napply (simp add: cspT_Rep_int_choice_DIV)\napply (simp)\napply (rule cspT_sym)\napply (simp add: cspT_Act_prefix_Dist)\ndone\n\nlemma cspT_Ext_pre_choice_delay_set:\n  \"!set Y:Xs .. (? :X -> (Pf Y)) =T[M,M] \n   IF (Xs = {}) THEN DIV ELSE (? x:X -> (!set Y:Xs .. (Pf Y) x))\"\napply (rule cspT_rw_right)\napply (rule cspT_IF_split)\napply (case_tac \"Xs = {}\")\napply (simp add: cspT_Rep_int_choice_DIV)\napply (simp)\napply (rule cspT_sym)\napply (simp add: cspT_Ext_pre_choice_Dist)\ndone\n\nlemma cspT_Act_prefix_delay_com:\n  \"! x:X .. (a -> Pf x) =T[M,M] \n   IF (X = {}) THEN DIV ELSE (a -> (! :X .. Pf))\"\napply (rule cspT_rw_right)\napply (rule cspT_IF_split)\napply (case_tac \"X = {}\")\napply (simp add: cspT_Rep_int_choice_DIV)\napply (simp)\napply (rule cspT_sym)\napply (simp add: cspT_Act_prefix_Dist)\ndone\n\nlemma cspT_Ext_pre_choice_delay_com:\n  \"! y:Y .. (? :X -> (Pf y)) =T[M,M] \n   IF (Y = {}) THEN DIV ELSE (? x:X -> (! y:Y .. (Pf y) x))\"\napply (rule cspT_rw_right)\napply (rule cspT_IF_split)\napply (case_tac \"Y = {}\")\napply (simp add: cspT_Rep_int_choice_DIV)\napply (simp)\napply (rule cspT_sym)\napply (simp add: cspT_Ext_pre_choice_Dist)\ndone\n\nlemma cspT_Act_prefix_delay_f:\n  \"inj f ==> \n   !<f> x:X .. (a -> Pf x) =T[M,M] \n   IF (X = {}) THEN DIV ELSE (a -> (!<f> :X .. Pf))\"\napply (rule cspT_rw_right)\napply (rule cspT_IF_split)\napply (case_tac \"X = {}\")\napply (simp add: cspT_Rep_int_choice_DIV)\napply (simp)\napply (rule cspT_sym)\napply (simp add: cspT_Act_prefix_Dist)\ndone\n\nlemma cspT_Ext_pre_choice_delay_f:\n  \"inj f ==> \n   !<f> y:Y .. (? :X -> (Pf y)) =T[M,M] \n   IF (Y = {}) THEN DIV ELSE (? x:X -> (!<f> y:Y .. (Pf y) x))\"\napply (rule cspT_rw_right)\napply (rule cspT_IF_split)\napply (case_tac \"Y = {}\")\napply (simp add: cspT_Rep_int_choice_DIV)\napply (simp)\napply (rule cspT_sym)\napply (simp add: cspT_Ext_pre_choice_Dist)\ndone\n\nlemmas cspT_choice_delay =\n       cspT_Int_choice_Act_prefix_delay\n       cspT_Int_choice_Ext_pre_choice_delay\n       cspT_Act_prefix_delay_sum\n       cspT_Ext_pre_choice_delay_sum\n       cspT_Act_prefix_delay_nat\n       cspT_Ext_pre_choice_delay_nat\n       cspT_Act_prefix_delay_set\n       cspT_Ext_pre_choice_delay_set\n       cspT_Act_prefix_delay_com\n       cspT_Ext_pre_choice_delay_com\n       cspT_Act_prefix_delay_f\n       cspT_Ext_pre_choice_delay_f\n\nlemmas cspT_choice_delay_eq =\n       cspT_Int_choice_Act_prefix_delay_eq\n       cspT_Int_choice_Ext_pre_choice_delay_eq\n\n\n(*********************************************************\n                       P |[X,Y]| Q\n *********************************************************)\n\n(* ---------- *\n    |~| left\n * ---------- *)\n\nlemma cspT_Alpha_Parallel_dist_l: \n  \"(P1 |~| P2) |[X,Y]| Q =T[M,M]\n   (P1 |[X,Y]| Q) |~| (P2 |[X,Y]| Q)\"\napply (simp add: Alpha_parallel_def)\n\napply (rule cspT_rw_left)\napply (rule cspT_decompo)\napply (simp)\napply (rule cspT_dist)\napply (rule cspT_reflex)\napply (rule cspT_rw_left)\napply (rule cspT_dist)\napply (simp)\ndone\n\n(* ---------- *\n    |~| right\n * ---------- *)\nlemma cspT_Alpha_Parallel_dist_r: \n  \"P |[X,Y]| (Q1 |~| Q2) =T[M,M]\n   (P |[X,Y]| Q1) |~| (P |[X,Y]| Q2)\"\napply (simp add: Alpha_parallel_def)\n\napply (rule cspT_rw_left)\napply (rule cspT_decompo)\napply (simp)\napply (rule cspT_reflex)\napply (rule cspT_dist)\napply (rule cspT_rw_left)\napply (rule cspT_dist)\napply (simp)\ndone\n\n(* ---------- *\n    !! left\n * ---------- *)\n\nlemma cspT_Alpha_Parallel_Dist_sum_l_nonempty: \n  \"sumset C ~= {} ==>\n     (!! :C .. Pf) |[X,Y]| Q =T[M,M]\n     !! c:C .. (Pf c |[X,Y]| Q)\"\napply (simp add: Alpha_parallel_def)\n\napply (rule cspT_rw_left)\napply (rule cspT_decompo)\napply (simp)\napply (rule cspT_Parallel_Dist_sum_l_nonempty)\napply (simp)\napply (rule cspT_reflex)\napply (rule cspT_rw_left)\napply (rule cspT_Parallel_Dist_sum_l_nonempty)\napply (simp)\napply (simp)\ndone\n\nlemma cspT_Alpha_Parallel_Dist_sum_l: \n  \"(!! :C .. Pf) |[X,Y]| Q =T[M,M]\n   IF (sumset C={}) THEN (DIV |[X,Y]| Q) ELSE (!! c:C .. (Pf c |[X,Y]| Q))\"\napply (case_tac \"sumset C={}\")\napply (simp)\napply (rule cspT_rw_right)\napply (rule cspT_IF)\napply (rule cspT_decompo_Alpha_parallel)\napply (simp)+\napply (simp add: cspT_Rep_int_choice_empty)\napply (simp)\n\napply (simp)\napply (rule cspT_rw_right)\napply (rule cspT_IF)\napply (rule cspT_Alpha_Parallel_Dist_sum_l_nonempty)\napply (simp)\ndone\n\n(* ---------- *\n    !! right\n * ---------- *)\n\nlemma cspT_Alpha_Parallel_Dist_sum_r_nonempty: \n  \"sumset C ~= {} ==>\n     P |[X,Y]| (!! :C .. Qf) =T[M,M]\n     !! c:C .. (P |[X,Y]| Qf c)\"\napply (rule cspT_rw_left)\napply (rule cspT_Alpha_parallel_commut)\napply (rule cspT_rw_left)\napply (rule cspT_Alpha_Parallel_Dist_sum_l_nonempty, simp)\napply (rule cspT_decompo, simp)\napply (rule cspT_Alpha_parallel_commut)\ndone\n\nlemma cspT_Alpha_Parallel_Dist_sum_r: \n  \"P |[X,Y]| (!! :C .. Qf) =T[M,M]\n   IF (sumset C={}) THEN (P |[X,Y]| DIV) ELSE (!! c:C .. (P |[X,Y]| Qf c))\"\napply (case_tac \"sumset C={}\")\napply (simp)\napply (rule cspT_rw_right)\napply (rule cspT_IF)\napply (rule cspT_decompo_Alpha_parallel)\napply (simp)+\napply (simp add: cspT_Rep_int_choice_empty)\napply (simp)\n\napply (rule cspT_rw_right)\napply (rule cspT_IF)\napply (rule cspT_Alpha_Parallel_Dist_sum_r_nonempty)\napply (simp)\ndone\n\n(* ---------- *\n   !nat left\n * ---------- *)\n\nlemma cspT_Alpha_Parallel_Dist_nat_l_nonempty: \n  \"N ~= {} ==>\n     (!nat :N .. Pf) |[X,Y]| Q =T[M,M]\n     !nat n:N .. (Pf n |[X,Y]| Q)\"\nby (simp add: Rep_int_choice_ss_def cspT_Alpha_Parallel_Dist_sum_l_nonempty)\n\n(*** Dist ***)\n\nlemma cspT_Alpha_Parallel_Dist_nat_l: \n  \"(!nat :N .. Pf) |[X,Y]| Q =T[M,M]\n   IF (N={}) THEN (DIV |[X,Y]| Q) ELSE (!nat n:N .. (Pf n |[X,Y]| Q))\"\napply (simp add: Rep_int_choice_ss_def)\nby (rule cspT_rw_left, rule cspT_Alpha_Parallel_Dist_sum_l, simp)\n\n(* ---------- *\n   !nat right\n * ---------- *)\n\nlemma cspT_Alpha_Parallel_Dist_nat_r_nonempty: \n  \"N ~= {} ==>\n     P |[X,Y]| (!nat :N .. Qf) =T[M,M]\n     !nat n:N .. (P |[X,Y]| Qf n)\"\nby (simp add: Rep_int_choice_ss_def cspT_Alpha_Parallel_Dist_sum_r_nonempty)\n\n(*** Dist ***)\n\nlemma cspT_Alpha_Parallel_Dist_nat_r: \n  \"P |[X,Y]| (!nat :N .. Qf) =T[M,M]\n   IF (N={}) THEN (P |[X,Y]| DIV) ELSE (!nat n:N .. (P |[X,Y]| Qf n))\"\napply (simp add: Rep_int_choice_ss_def)\nby (rule cspT_rw_left, rule cspT_Alpha_Parallel_Dist_sum_r, simp)\n\n(* ---------- *\n   !set left\n * ---------- *)\n\nlemma cspT_Alpha_Parallel_Dist_set_l_nonempty: \n  \"Xs ~= {} ==>\n     (!set :Xs .. Pf) |[Y,Z]| Q =T[M,M]\n     !set X:Xs .. (Pf X |[Y,Z]| Q)\"\nby (simp add: Rep_int_choice_ss_def cspT_Alpha_Parallel_Dist_sum_l_nonempty)\n\n(*** Dist ***)\n\nlemma cspT_Alpha_Parallel_Dist_set_l: \n  \"(!set :Xs .. Pf) |[Y,Z]| Q =T[M,M]\n   IF (Xs={}) THEN (DIV |[Y,Z]| Q) ELSE (!set X:Xs .. (Pf X |[Y,Z]| Q))\"\napply (simp add: Rep_int_choice_ss_def)\nby (rule cspT_rw_left, rule cspT_Alpha_Parallel_Dist_sum_l, simp)\n\n(* ---------- *\n   !set right\n * ---------- *)\n\nlemma cspT_Alpha_Parallel_Dist_set_r_nonempty: \n  \"Xs ~= {} ==>\n     P |[Y,Z]| (!set :Xs .. Qf) =T[M,M]\n     !set X:Xs .. (P |[Y,Z]| Qf X)\"\nby (simp add: Rep_int_choice_ss_def cspT_Alpha_Parallel_Dist_sum_r_nonempty)\n\n(*** Dist ***)\n\nlemma cspT_Alpha_Parallel_Dist_set_r: \n  \"P |[Y,Z]| (!set :Xs .. Qf) =T[M,M]\n   IF (Xs={}) THEN (P |[Y,Z]| DIV) ELSE (!set X:Xs .. (P |[Y,Z]| Qf X))\"\napply (simp add: Rep_int_choice_ss_def)\nby (rule cspT_rw_left, rule cspT_Alpha_Parallel_Dist_sum_r, simp)\n\n(* ---------- *\n     ! left\n * ---------- *)\n\nlemma cspT_Alpha_Parallel_Dist_com_l_nonempty: \n  \"A ~= {}\n   ==> (! :A .. Pf) |[X,Y]| Q =T[M,M] ! x:A .. (Pf x |[X,Y]| Q)\"\nby (simp add: Rep_int_choice_com_def cspT_Alpha_Parallel_Dist_set_l_nonempty)\n\nlemma cspT_Alpha_Parallel_Dist_com_l: \n  \"(! :A .. Pf) |[X,Y]| Q =T[M,M]\n   IF (A ={}) THEN (DIV |[X,Y]| Q) ELSE (! x:A .. (Pf x |[X,Y]| Q))\"\napply (simp add: Rep_int_choice_com_def)\nby (rule cspT_rw_left, rule cspT_Alpha_Parallel_Dist_set_l, simp)\n\n(* ---------- *\n     ! right\n * ---------- *)\n\nlemma cspT_Alpha_Parallel_Dist_com_r_nonempty: \n  \"A ~= {}\n   ==> P |[X,Y]| (! :A .. Qf) =T[M,M] ! x:A .. (P |[X,Y]| Qf x)\"\nby (simp add: Rep_int_choice_com_def cspT_Alpha_Parallel_Dist_set_r_nonempty)\n\nlemma cspT_Alpha_Parallel_Dist_com_r: \n  \"P |[X,Y]| (! :A .. Qf) =T[M,M] \n   IF (A ={}) THEN (P |[X,Y]| DIV) ELSE (! x:A .. (P |[X,Y]| Qf x))\"\napply (simp add: Rep_int_choice_com_def)\nby (rule cspT_rw_left, rule cspT_Alpha_Parallel_Dist_set_r, simp)\n\n(* ---------- *\n   !<f> left\n * ---------- *)\n\nlemma cspT_Alpha_Parallel_Dist_f_l_nonempty: \n  \"[| inj f ; A ~= {} |]\n   ==> (!<f> :A .. Pf) |[X,Y]| Q =T[M,M] !<f> x:A .. (Pf x |[X,Y]| Q)\"\nby (simp add: Rep_int_choice_f_def cspT_Alpha_Parallel_Dist_com_l_nonempty)\n\nlemma cspT_Alpha_Parallel_Dist_f_l: \n  \"(!<f> :A .. Pf) |[X,Y]| Q =T[M,M]\n   IF (A ={}) THEN (DIV |[X,Y]| Q) ELSE (!<f> x:A .. (Pf x |[X,Y]| Q))\"\napply (simp add: Rep_int_choice_f_def)\nby (rule cspT_rw_left, rule cspT_Alpha_Parallel_Dist_com_l, simp)\n\nlemma cspT_Alpha_Parallel_Dist_f_r_nonempty: \n  \"[| inj f ; A ~= {} |]\n   ==> P |[X,Y]| (!<f> :A .. Qf) =T[M,M] !<f> x:A .. (P |[X,Y]| Qf x)\"\nby (simp add: Rep_int_choice_f_def cspT_Alpha_Parallel_Dist_com_r_nonempty)\n\nlemma cspT_Alpha_Parallel_Dist_f_r: \n  \"P |[X,Y]| (!<f> :A .. Qf) =T[M,M] \n   IF (A ={}) THEN (P |[X,Y]| DIV) ELSE (!<f> x:A .. (P |[X,Y]| Qf x))\"\napply (simp add: Rep_int_choice_f_def)\nby (rule cspT_rw_left, rule cspT_Alpha_Parallel_Dist_com_r, simp)\n\nlemmas cspT_dist_Alpha_Parallel =\n       cspT_Alpha_Parallel_dist_l\n       cspT_Alpha_Parallel_dist_r \n\nlemmas cspT_Dist_Alpha_Parallel =\n      cspT_Alpha_Parallel_Dist_sum_l \n      cspT_Alpha_Parallel_Dist_sum_r \n      cspT_Alpha_Parallel_Dist_nat_l \n      cspT_Alpha_Parallel_Dist_nat_r \n      cspT_Alpha_Parallel_Dist_set_l \n      cspT_Alpha_Parallel_Dist_set_r \n      cspT_Alpha_Parallel_Dist_com_l \n      cspT_Alpha_Parallel_Dist_com_r \n      cspT_Alpha_Parallel_Dist_f_l \n      cspT_Alpha_Parallel_Dist_f_r \n\nlemmas cspT_Dist_Alpha_Parallel_nonempty =\n      cspT_Alpha_Parallel_Dist_sum_l_nonempty \n      cspT_Alpha_Parallel_Dist_sum_r_nonempty \n      cspT_Alpha_Parallel_Dist_nat_l_nonempty \n      cspT_Alpha_Parallel_Dist_nat_r_nonempty \n      cspT_Alpha_Parallel_Dist_set_l_nonempty \n      cspT_Alpha_Parallel_Dist_set_r_nonempty \n      cspT_Alpha_Parallel_Dist_com_l_nonempty\n      cspT_Alpha_Parallel_Dist_com_r_nonempty \n      cspT_Alpha_Parallel_Dist_f_l_nonempty \n      cspT_Alpha_Parallel_Dist_f_r_nonempty \n\n(****************** to add them again ******************)\n\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/CSP_T/CSP_T_law_dist.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5774953651858117, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.28423636717820466}}
{"text": "(*\n    Author:     Gerwin Klein\n    Copyright   1999 Technische Universitaet Muenchen\n*)\n\nheader {* \\isaheader{Correctness of the LBV} *}\n\ntheory LBVCorrect\nimports LBVSpec Typing_Framework\nbegin\n\nlocale lbvs = lbv +\n  fixes s\\<^sub>0  :: 'a\n  fixes c   :: \"'a list\"\n  fixes ins :: \"'b list\"\n  fixes \\<tau>s  :: \"'a list\"\n  defines phi_def:\n  \"\\<tau>s \\<equiv> map (\\<lambda>pc. if c!pc = \\<bottom> then wtl (take pc ins) c 0 s\\<^sub>0 else c!pc) \n       [0..<size ins]\"\n\n  assumes bounded: \"bounded step (size ins)\"\n  assumes cert: \"cert_ok c (size ins) \\<top> \\<bottom> A\"\n  assumes pres: \"pres_type step (size ins) A\"\n\nlemma (in lbvs) phi_None [intro?]:\n  \"\\<lbrakk> pc < size ins; c!pc = \\<bottom> \\<rbrakk> \\<Longrightarrow> \\<tau>s!pc = wtl (take pc ins) c 0 s\\<^sub>0\"\n(*<*) by (simp add: phi_def) (*>*)\n\nlemma (in lbvs) phi_Some [intro?]:\n  \"\\<lbrakk> pc < size ins; c!pc \\<noteq> \\<bottom> \\<rbrakk> \\<Longrightarrow> \\<tau>s!pc = c!pc\"\n(*<*) by (simp add: phi_def) (*>*)\n\nlemma (in lbvs) phi_len [simp]: \"size \\<tau>s = size ins\"\n(*<*) by (simp add: phi_def) (*>*)\n\nlemma (in lbvs) wtl_suc_pc:\n  assumes all: \"wtl ins c 0 s\\<^sub>0 \\<noteq> \\<top>\" \n  assumes pc:  \"pc+1 < size ins\"\n  shows \"wtl (take (pc+1) ins) c 0 s\\<^sub>0 \\<sqsubseteq>\\<^sub>r \\<tau>s!(pc+1)\"\n(*<*)\nproof -\n  from all pc\n  have \"wtc c (pc+1) (wtl (take (pc+1) ins) c 0 s\\<^sub>0) \\<noteq> T\" by (rule wtl_all)\n  with pc show ?thesis by (simp add: phi_def wtc split: split_if_asm)\nqed\n(*>*)\n\nlemma (in lbvs) wtl_stable:\n  assumes wtl: \"wtl ins c 0 s\\<^sub>0 \\<noteq> \\<top>\" \n  assumes s\\<^sub>0:  \"s\\<^sub>0 \\<in> A\" and  pc:  \"pc < size ins\" \n  shows \"stable r step \\<tau>s pc\"\n(*<*)\nproof (unfold stable_def, clarify)\n  fix pc' s' assume step: \"(pc',s') \\<in> set (step pc (\\<tau>s ! pc))\" \n                      (is \"(pc',s') \\<in> set (?step pc)\")\n  \n  from bounded pc step have pc': \"pc' < size ins\" by (rule boundedD)\n\n  have tkpc: \"wtl (take pc ins) c 0 s\\<^sub>0 \\<noteq> \\<top>\" (is \"?s\\<^sub>1 \\<noteq> _\") using wtl by (rule wtl_take)\n  have s\\<^sub>2: \"wtl (take (pc+1) ins) c 0 s\\<^sub>0 \\<noteq> \\<top>\" (is \"?s\\<^sub>2 \\<noteq> _\") using wtl by (rule wtl_take)\n  \n  from wtl pc have wt_s\\<^sub>1: \"wtc c pc ?s\\<^sub>1 \\<noteq> \\<top>\" by (rule wtl_all)\n\n  have c_Some: \"\\<forall>pc t. pc < size ins \\<longrightarrow> c!pc \\<noteq> \\<bottom> \\<longrightarrow> \\<tau>s!pc = c!pc\" \n    by (simp add: phi_def)\n  have c_None: \"c!pc = \\<bottom> \\<Longrightarrow> \\<tau>s!pc = ?s\\<^sub>1\" using pc ..\n\n  from wt_s\\<^sub>1 pc c_None c_Some\n  have inst: \"wtc c pc ?s\\<^sub>1  = wti c pc (\\<tau>s!pc)\"\n    by (simp add: wtc split: split_if_asm)\n\n  have \"?s\\<^sub>1 \\<in> A\" using pres cert s\\<^sub>0 wtl pc by (rule wtl_pres)\n  with pc c_Some cert c_None\n  have \"\\<tau>s!pc \\<in> A\" by (cases \"c!pc = \\<bottom>\") (auto dest: cert_okD1)\n  with pc pres\n  have step_in_A: \"snd`set (?step pc) \\<subseteq> A\" by (auto dest: pres_typeD2)\n\n  show \"s' \\<sqsubseteq>\\<^sub>r \\<tau>s!pc'\" \n  proof (cases \"pc' = pc+1\")\n    case True\n    with pc' cert\n    have cert_in_A: \"c!(pc+1) \\<in> A\" by (auto dest: cert_okD1)\n    from True pc' have pc1: \"pc+1 < size ins\" by simp\n    with tkpc have \"?s\\<^sub>2 = wtc c pc ?s\\<^sub>1\" by - (rule wtl_Suc)\n    with inst \n    have merge: \"?s\\<^sub>2 = merge c pc (?step pc) (c!(pc+1))\" by (simp add: wti)\n    also from s\\<^sub>2 merge have \"\\<dots> \\<noteq> \\<top>\" (is \"?merge \\<noteq> _\") by simp\n    with cert_in_A step_in_A\n    have \"?merge = (map snd [(p',t') \\<leftarrow> ?step pc. p'=pc+1] \\<Squnion>\\<^bsub>f\\<^esub> c!(pc+1))\"\n      by (rule merge_not_top_s) \n    finally have \"s' \\<sqsubseteq>\\<^sub>r ?s\\<^sub>2\" using step_in_A cert_in_A True step \n      by (auto intro: pp_ub1')\n    also from wtl pc1 have \"?s\\<^sub>2 \\<sqsubseteq>\\<^sub>r \\<tau>s!(pc+1)\" by (rule wtl_suc_pc)\n    also note True [symmetric]\n    finally show ?thesis by simp    \n  next\n    case False\n    from wt_s\\<^sub>1 inst \n    have \"merge c pc (?step pc) (c!(pc+1)) \\<noteq> \\<top>\" by (simp add: wti)\n    with step_in_A have \"\\<forall>(pc', s')\\<in>set (?step pc). pc'\\<noteq>pc+1 \\<longrightarrow> s' \\<sqsubseteq>\\<^sub>r c!pc'\"\n      by - (rule merge_not_top)\n    with step False  have ok: \"s' \\<sqsubseteq>\\<^sub>r c!pc'\" by blast\n    moreover from ok have \"c!pc' = \\<bottom> \\<Longrightarrow> s' = \\<bottom>\" by simp\n    moreover from c_Some pc'  have \"c!pc' \\<noteq> \\<bottom> \\<Longrightarrow> \\<tau>s!pc' = c!pc'\" by auto\n    ultimately show ?thesis by (cases \"c!pc' = \\<bottom>\") auto \n  qed\nqed\n(*>*)\n  \nlemma (in lbvs) phi_not_top:\n  assumes wtl: \"wtl ins c 0 s\\<^sub>0 \\<noteq> \\<top>\" and pc:  \"pc < size ins\"\n  shows \"\\<tau>s!pc \\<noteq> \\<top>\"\n(*<*)\nproof (cases \"c!pc = \\<bottom>\")\n  case False with pc\n  have \"\\<tau>s!pc = c!pc\" ..\n  also from cert pc have \"\\<dots> \\<noteq> \\<top>\" by (rule cert_okD4)\n  finally show ?thesis .\nnext\n  case True with pc\n  have \"\\<tau>s!pc = wtl (take pc ins) c 0 s\\<^sub>0\" ..\n  also from wtl have \"\\<dots> \\<noteq> \\<top>\" by (rule wtl_take)\n  finally show ?thesis .\nqed\n(*>*)\n\nlemma (in lbvs) phi_in_A:\n  assumes wtl: \"wtl ins c 0 s\\<^sub>0 \\<noteq> \\<top>\" and s\\<^sub>0: \"s\\<^sub>0 \\<in> A\"\n  shows \"\\<tau>s \\<in> list (size ins) A\"\n(*<*)\nproof -\n  { fix x assume \"x \\<in> set \\<tau>s\"\n    then obtain xs ys where \"\\<tau>s = xs @ x # ys\" \n      by (auto simp add: in_set_conv_decomp)\n    then obtain pc where pc: \"pc < size \\<tau>s\" and x: \"\\<tau>s!pc = x\"\n      by (simp add: that [of \"size xs\"] nth_append)\n    \n    from pres cert wtl s\\<^sub>0 pc \n    have \"wtl (take pc ins) c 0 s\\<^sub>0 \\<in> A\" by (auto intro!: wtl_pres)\n    moreover\n    from pc have \"pc < size ins\" by simp\n    with cert have \"c!pc \\<in> A\" ..\n    ultimately\n    have \"\\<tau>s!pc \\<in> A\" using pc by (simp add: phi_def)\n    hence \"x \\<in> A\" using x by simp\n  } \n  hence \"set \\<tau>s \\<subseteq> A\" ..\n  thus ?thesis by (unfold list_def) simp\nqed\n(*>*)\n\nlemma (in lbvs) phi0:\n  assumes wtl: \"wtl ins c 0 s\\<^sub>0 \\<noteq> \\<top>\" and 0: \"0 < size ins\"\n  shows \"s\\<^sub>0 \\<sqsubseteq>\\<^sub>r \\<tau>s!0\"\n(*<*)\nproof (cases \"c!0 = \\<bottom>\")\n  case True\n  with 0 have \"\\<tau>s!0 = wtl (take 0 ins) c 0 s\\<^sub>0\" ..\n  moreover have \"wtl (take 0 ins) c 0 s\\<^sub>0 = s\\<^sub>0\" by simp\n  ultimately have \"\\<tau>s!0 = s\\<^sub>0\" by simp\n  thus ?thesis by simp\nnext\n  case False\n  with 0 have \"\\<tau>s!0 = c!0\" ..\n  moreover \n  have \"wtl (take 1 ins) c 0 s\\<^sub>0 \\<noteq> \\<top>\" using wtl by (rule wtl_take)\n  with 0 False \n  have \"s\\<^sub>0 \\<sqsubseteq>\\<^sub>r c!0\" by (auto simp add: neq_Nil_conv wtc split: split_if_asm)\n  ultimately\n  show ?thesis by simp\nqed\n(*>*)\n\n\n\n\n\ntheorem (in lbvs) wtl_sound_strong:\n  assumes wtl: \"wtl ins c 0 s\\<^sub>0 \\<noteq> \\<top>\" \n  assumes s\\<^sub>0: \"s\\<^sub>0 \\<in> A\" and ins: \"0 < size ins\"\n  shows \"\\<exists>\\<tau>s \\<in> list (size ins) A. wt_step r \\<top> step \\<tau>s \\<and> s\\<^sub>0 \\<sqsubseteq>\\<^sub>r \\<tau>s!0\"\n(*<*)\nproof -\n  have \"\\<tau>s \\<in> list (size ins) A\" using wtl s\\<^sub>0 by (rule phi_in_A)\n  moreover\n  have \"wt_step r \\<top> step \\<tau>s\"\n  proof (unfold wt_step_def, intro strip conjI)\n    fix pc assume \"pc < size \\<tau>s\"\n    then obtain pc: \"pc < size ins\" by simp\n    with wtl show \"\\<tau>s!pc \\<noteq> \\<top>\" by (rule phi_not_top)\n    from wtl s\\<^sub>0 and pc show \"stable r step \\<tau>s pc\" by (rule wtl_stable)\n  qed\n  moreover from wtl ins have \"s\\<^sub>0 \\<sqsubseteq>\\<^sub>r \\<tau>s!0\" by (rule phi0)\n  ultimately show ?thesis by fast\nqed\n(*>*)\n\nend", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/JinjaThreads/DFA/LBVCorrect.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.577495350642608, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.2842363600202124}}
{"text": "section \\<open>List Comprehension\\<close>\n\ntheory List_Comprehension\n  imports Data_List\nbegin\n\nno_notation\n  disj (infixr \"|\" 30)\n\nnonterminal llc_qual and llc_quals\n\nsyntax\n  \"_llc\" :: \"'a \\<Rightarrow> llc_qual \\<Rightarrow> llc_quals \\<Rightarrow> ['a]\" (\"[_ | __\")\n  \"_llc_gen\" :: \"'a \\<Rightarrow> ['a] \\<Rightarrow> llc_qual\" (\"_ <- _\")\n  \"_llc_guard\" :: \"tr \\<Rightarrow> llc_qual\" (\"_\")\n  \"_llc_let\" :: \"letbinds \\<Rightarrow> llc_qual\" (\"let _\")\n  \"_llc_quals\" :: \"llc_qual \\<Rightarrow> llc_quals \\<Rightarrow> llc_quals\" (\", __\")\n  \"_llc_end\" :: \"llc_quals\" (\"]\")\n  \"_llc_abs\" :: \"'a \\<Rightarrow> ['a] \\<Rightarrow> ['a]\"\n\ntranslations\n  \"[e | p <- xs]\" => \"CONST concatMap\\<cdot>(_llc_abs p [e])\\<cdot>xs\"\n  \"_llc e (_llc_gen p xs) (_llc_quals q qs)\"\n    => \"CONST concatMap\\<cdot>(_llc_abs p (_llc e q qs))\\<cdot>xs\"\n  \"[e | b]\" => \"If b then [e] else []\"\n  \"_llc e (_llc_guard b) (_llc_quals q qs)\"\n    => \"If b then (_llc e q qs) else []\"\n  \"_llc e (_llc_let b) (_llc_quals q qs)\"\n    => \"_Let b (_llc e q qs)\"\n\nparse_translation \\<open>\nlet open HOLCF_Library in\n  let\n    val NilC = Syntax.const @{const_syntax \"Nil\"};\n\n    fun Lam x = Syntax.const @{const_syntax \"Abs_cfun\"} $ x;\n\n    fun fresh_var ts ctxt =\n      let\n        val ctxt' = fold Variable.declare_term ts ctxt\n      in\n        singleton (Variable.variant_frees ctxt' []) (\"x\", dummyT)\n      end\n\n    fun pat_tr ctxt p e = (* %x. case x of p => e | _ => [] *)\n      let\n        val x = Free (fresh_var [p, e] ctxt);\n        val case1 = Syntax.const @{syntax_const \"_case1\"} $ p $ e;\n        val case2 =\n          Syntax.const @{syntax_const \"_case1\"} $\n            Syntax.const @{const_syntax Pure.dummy_pattern} $ NilC;\n        val cs = Syntax.const @{syntax_const \"_case2\"} $ case1 $ case2;\n      in\n        (* FIXME: handle HOLCF patterns correctly *)\n        Syntax_Trans.abs_tr [x, Case_Translation.case_tr false ctxt [x, cs]]\n        |> Lam\n      end\n\n    fun abs_tr ctxt [p, e] =\n      (case Term_Position.strip_positions p of\n        Free (s, T) => Lam (Syntax_Trans.abs_tr [p, e])\n      | _ => pat_tr ctxt p e)\n\n  in [(@{syntax_const \"_llc_abs\"}, abs_tr)] end\nend\n\\<close>\n\nlemma concatMap_singleton [simp]:\n  \"concatMap\\<cdot>(\\<Lambda> x. [f\\<cdot>x])\\<cdot>xs = map\\<cdot>f\\<cdot>xs\"\n  by (induct xs) simp_all\n\nlemma listcompr_filter [simp]:\n  \"[x | x <- xs, P\\<cdot>x] = filter\\<cdot>P\\<cdot>xs\"\nproof (induct xs)\n  case (Cons a xs)\n  then show ?case by (cases \"P\\<cdot>a\"; simp)\nqed simp_all\n\nlemma \"[y | let y = x*2; z = y, x <- xs] = A\"\n  apply simp\n  oops\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Evaluation/HOLCF-Prelude/List_Comprehension.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.577495350642608, "lm_q2_score": 0.4921881357207955, "lm_q1q2_score": 0.28423636002021235}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory PackedTypes\nimports \"../lib/$L4V_ARCH/WordSetup\" CProof\nbegin\n\nsection {* Underlying definitions for the class axioms *}\n\ntext {* field_access / field_update is the identity for packed types *}\n\ndefinition\n  \"fa_fu_idem fd n \\<equiv>\n  \\<forall>bs bs' v. length bs = n \\<longrightarrow> length bs' = n \\<longrightarrow> field_access fd (field_update fd bs v) bs' = bs\"\n\n(* Is it better to do this or to use a fold over td?  This seems easier to use *)\nprimrec\n  td_fafu_idem :: \"'a field_desc typ_desc \\<Rightarrow> bool\" and\n  td_fafu_idem_struct :: \"'a field_desc typ_struct \\<Rightarrow> bool\" and\n  td_fafu_idem_list :: \" ('a field_desc typ_desc, char list) dt_pair list \\<Rightarrow> bool\" and\n  td_fafu_idem_pair :: \"('a field_desc typ_desc, char list) dt_pair \\<Rightarrow> bool\"\nwhere\n  fai0: \"td_fafu_idem (TypDesc ts n) = td_fafu_idem_struct ts\"\n\n| fai1: \"td_fafu_idem_struct (TypScalar n algn d) = fa_fu_idem d n\"\n| fai2: \"td_fafu_idem_struct (TypAggregate ts) = td_fafu_idem_list ts\"\n\n| fai3: \"td_fafu_idem_list [] = True\"\n| fai4: \"td_fafu_idem_list (x#xs) = (td_fafu_idem_pair x \\<and> td_fafu_idem_list xs)\"\n\n| fai5: \"td_fafu_idem_pair (DTPair x n) = td_fafu_idem x\"\n\nlemmas td_fafu_idem_simps = fai0 fai1 fai2 fai3 fai4 fai5\n\ntext {* field_access is independent of the underlying bytes *}\n\ndefinition\n  \"fa_heap_indep fd n \\<equiv>\n  \\<forall>bs bs' v. length bs = n \\<longrightarrow> length bs' = n \\<longrightarrow> field_access fd v bs = field_access fd v bs'\"\n\n\nprimrec\n  td_fa_hi :: \"'a field_desc typ_desc \\<Rightarrow> bool\" and\n  td_fa_hi_struct :: \"'a field_desc typ_struct \\<Rightarrow> bool\" and\n  td_fa_hi_list :: \"('a field_desc typ_desc, char list) dt_pair list \\<Rightarrow> bool\" and\n  td_fa_hi_pair :: \"('a field_desc typ_desc, char list) dt_pair \\<Rightarrow> bool\"\nwhere\n  fahi0: \"td_fa_hi (TypDesc ts n) = td_fa_hi_struct ts\"\n\n| fahi1: \"td_fa_hi_struct (TypScalar n algn d) = fa_heap_indep d n\"\n| fahi2: \"td_fa_hi_struct (TypAggregate ts) = td_fa_hi_list ts\"\n\n| fahi3: \"td_fa_hi_list [] = True\"\n| fahi4: \"td_fa_hi_list (x#xs) = (td_fa_hi_pair x \\<and> td_fa_hi_list xs)\"\n\n| fahi5: \"td_fa_hi_pair (DTPair x n) = td_fa_hi x\"\n\nlemmas td_fa_hi_simps = fahi0 fahi1 fahi2 fahi3 fahi4 fahi5\n\nsection {* Lemmas about td_fafu_idem *}\n\nlemma field_lookup_td_fafu_idem:\n  shows \"\\<And>(s :: 'a field_desc typ_desc) f m n. \\<lbrakk> field_lookup t f m = Some (s, n); td_fafu_idem t \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  and   \"\\<And>(s :: 'a field_desc typ_desc) f m n. \\<lbrakk> field_lookup_struct st f m = Some (s, n); td_fafu_idem_struct st \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  and   \"\\<And>(s :: 'a field_desc typ_desc) f m n. \\<lbrakk> field_lookup_list ts f m = Some (s, n); td_fafu_idem_list ts \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  and   \"\\<And>(s :: 'a field_desc typ_desc) f m n. \\<lbrakk> field_lookup_pair p f m = Some (s, n); td_fafu_idem_pair p \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  by (induct t and st and ts and p) (auto split: if_split_asm option.splits)\n\nlemma field_access_update_same:\n  fixes t :: \"'a :: mem_type field_desc typ_desc\" and st :: \"'a field_desc typ_struct\"\n  shows \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem t; wf_fd t; length bs = size_td t; length bs' = size_td t\\<rbrakk>\n  \\<Longrightarrow> access_ti t (update_ti t bs v) bs' = bs\"\n  and \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem_struct st; wf_fd_struct st; length bs = size_td_struct st; length bs' = size_td_struct st \\<rbrakk>\n  \\<Longrightarrow> access_ti_struct st (update_ti_struct st bs v) bs' = bs\"\n  and \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem_list ts; wf_fd_list ts; length bs = size_td_list ts; length bs' = size_td_list ts\\<rbrakk>\n  \\<Longrightarrow> access_ti_list ts (update_ti_list ts bs v) bs' = bs\"\n  and \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem_pair p; wf_fd_pair p; length bs = size_td_pair p; length bs' = size_td_pair p\\<rbrakk>\n  \\<Longrightarrow> access_ti_pair p (update_ti_pair p bs v) bs' = bs\"\nproof (induct t and st and ts and p)\n  case TypScalar thus ?case by (clarsimp simp: fa_fu_idem_def)\nnext\n  case (Cons_typ_desc p' ts' v bs bs')\n  hence \"fu_commutes (update_ti_pair_t p') (update_ti_list_t ts')\" by clarsimp\n  moreover have \"update_ti_pair p' (take (size_td_pair p') bs) = update_ti_pair_t p' (take (size_td_pair p') bs)\"\n    using Cons_typ_desc.prems by (simp add: update_ti_pair_t_def min_ll)\n  moreover have \"update_ti_list ts' (drop (size_td_pair p') bs) = update_ti_list_t ts' (drop (size_td_pair p') bs)\"\n    using Cons_typ_desc.prems by (simp add: update_ti_list_t_def)\n  ultimately have\n    updeq: \"(update_ti_pair p' (take (size_td_pair p') bs) (update_ti_list ts' (drop (size_td_pair p') bs) v))\n    = (update_ti_list ts' (drop (size_td_pair p') bs) (update_ti_pair p' (take (size_td_pair p') bs) v))\"\n    unfolding fu_commutes_def by simp\n\n  show ?case using Cons_typ_desc.prems\n    by (clarsimp simp add: Cons_typ_desc.hyps) (simp add: updeq  Cons_typ_desc.hyps)\nqed simp+\n\nlemma access_ti_pair_dt_fst:\n  \"access_ti_pair p v bs = access_ti (dt_fst p) v bs\"\n  by (cases p, simp)\n\nlemma size_td_pair_dt_fst:\n  \"size_td_pair p = size_td (dt_fst p)\"\n  by (cases p, simp)\n\nlemma wf_fd_pair_dt_fst:\n  \"wf_fd_pair p = wf_fd (dt_fst p)\"\n  by (cases p, simp)\n\nlemma field_lookup_offset2:\n  assumes fl: \"(field_lookup t f (m + n) = Some (s, q))\"\n  shows   \"field_lookup t f m = Some (s, q - n)\"\nproof -\n  from fl have le: \"m + n \\<le> q\"\n    by (rule field_lookup_offset_le)\n\n  hence \"q = (m + n) + (q - (m + n))\"\n    by simp\n\n  hence \"field_lookup t f (m + n) = Some (s, (m + n) + (q - (m + n)))\" using fl by simp\n\n  hence \"field_lookup t f m = Some (s, m + (q - (m + n)))\"\n    by (rule iffD1 [OF field_lookup_offset'(1)])\n\n  thus ?thesis using le by simp\nqed\n\nlemma field_lookup_offset2_list:\n  assumes fl: \"(field_lookup_list ts f (m + n) = Some (s, q))\"\n  shows   \"field_lookup_list ts f m = Some (s, q - n)\"\nproof -\n  from fl have le: \"m + n \\<le> q\"\n    by (rule field_lookup_offset_le)\n\n  hence \"q = (m + n) + (q - (m + n))\"\n    by simp\n\n  hence \"field_lookup_list ts f (m + n) = Some (s, (m + n) + (q - (m + n)))\" using fl by simp\n\n  hence \"field_lookup_list ts f m = Some (s, m + (q - (m + n)))\"\n    by (rule iffD1 [OF field_lookup_offset'(3)])\n\n  thus ?thesis using le by simp\nqed\n\nlemma field_lookup_offset2_pair:\n  assumes fl: \"(field_lookup_pair p f (m + n) = Some (s, q))\"\n  shows   \"field_lookup_pair p f m = Some (s, q - n)\"\nproof -\n  from fl have le: \"m + n \\<le> q\"\n    by (rule field_lookup_offset_le)\n\n  hence \"q = (m + n) + (q - (m + n))\"\n    by simp\n\n  hence \"field_lookup_pair p f (m + n) = Some (s, (m + n) + (q - (m + n)))\" using fl by simp\n\n  hence \"field_lookup_pair p f m = Some (s, m + (q - (m + n)))\"\n    by (rule iffD1 [OF field_lookup_offset'(4)])\n\n  thus ?thesis using le by simp\nqed\n\nlemma field_lookup_offset_size':\n  shows \"field_lookup t f 0 = Some (t',n) \\<Longrightarrow> size_td t' + n \\<le> size_td t\"\n  apply(drule td_set_field_lookupD)\n  apply(erule td_set_offset_size)\ndone\n\nlemma field_access_update_nth_inner:\n  shows \"\\<And>f (s :: 'a :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk> field_lookup t f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd t;\n  length bs = size_td s; length bs' = size_td t \\<rbrakk>\n  \\<Longrightarrow> access_ti t (update_ti s bs v) bs' ! x = bs ! (x - n)\"\n\n  and \"\\<And>f (s :: 'a  :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk>field_lookup_struct st f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd_struct st;\n  length bs = size_td s; length bs' = size_td_struct st \\<rbrakk>\n  \\<Longrightarrow> access_ti_struct st (update_ti s bs v) bs' ! x = bs ! (x - n)\"\n\n  and \"\\<And>f (s :: 'a  :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk>field_lookup_list ts f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd_list ts;\n  length bs = size_td s; length bs' = size_td_list ts\\<rbrakk>\n  \\<Longrightarrow> access_ti_list ts (update_ti s bs v) bs' ! x = bs ! (x - n)\"\n\n  and \"\\<And>f (s :: 'a  :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk>field_lookup_pair p f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd_pair p;\n  length bs = size_td s; length bs' = size_td_pair p\\<rbrakk>\n  \\<Longrightarrow> access_ti_pair p (update_ti s bs v) bs' ! x = bs ! (x - n)\"\nproof (induct t and st and ts and p)\n  case (TypDesc typ_struct ls f s n x v bs bs')\n\n  show ?case\n  proof (cases \"f = []\")\n    case False thus ?thesis using TypDesc by clarsimp\n  next\n    case True\n    thus ?thesis using TypDesc.prems\n      by (simp add: field_access_update_same)\n  qed\nnext\n  case (Cons_typ_desc p' ts' f s n x v bs bs')\n  have nlex: \"n \\<le> x\" and xln: \"x < n + size_td s\"\n    and lbs: \"length bs = size_td s\" and lbs': \"length bs' = size_td_list (p' # ts')\" by fact+\n  from Cons_typ_desc have wf: \"wf_fd (dt_fst p')\" and wfts: \"wf_fd_list ts'\" by (cases p', auto)\n\n  {\n    assume fl: \"field_lookup_list ts' f (size_td (dt_fst p')) = Some (s, n)\"\n\n    hence mlt: \"size_td (dt_fst p') \\<le> n\"\n      by (rule field_lookup_offset_le)\n\n    hence \"size_td (dt_fst p') \\<le> x\"\n      by (rule order_trans) fact\n\n    hence ?case using wf lbs lbs'\n    proof (simp add: nth_append length_fa_ti access_ti_pair_dt_fst size_td_pair_dt_fst)\n      from fl have fl': \"field_lookup_list ts' f 0 = Some (s, n - size_td (dt_fst p'))\"\n        by (rule field_lookup_offset2_list [where m = 0, simplified])\n\n      show \"access_ti_list ts' (update_ti s bs v) (drop (size_td (dt_fst p')) bs') ! (x - size_td (dt_fst p')) = bs ! (x - n)\"\n        using mlt nlex xln lbs lbs' wf wfts `td_fafu_idem s` `wf_fd s`\n        by (simp add: Cons_typ_desc.hyps(2) [OF fl'] size_td_pair_dt_fst)\n    qed\n  }\n  moreover\n  {\n    note ih = Cons_typ_desc.hyps(1)[simplified access_ti_pair_dt_fst wf_fd_pair_dt_fst]\n\n    assume fl: \"field_lookup_pair p' f 0 = Some (s, n)\"\n\n    hence \"x < size_td (dt_fst p')\"\n      apply -\n      apply (cases p')\n      apply (simp split: if_split_asm)\n      apply (drule field_lookup_offset_size')\n      apply (rule order_less_le_trans [OF xln])\n      apply simp\n      done\n\n    hence ?case using wf lbs lbs' nlex xln wf wfts `td_fafu_idem s` `wf_fd s`\n      by (simp add: nth_append length_fa_ti access_ti_pair_dt_fst size_td_pair_dt_fst ih[OF fl])\n  }\n  ultimately show ?case using `field_lookup_list (p' # ts') f 0 = Some (s, n)` by (simp split: option.splits)\nqed (clarsimp split: if_split_asm)+\n\nsubsection {* td_fa_hi *}\n\n(* \\<lbrakk> size_of TYPE('a::mem_type) \\<le> length h; size_of TYPE('a) \\<le> length h' \\<rbrakk> \\<Longrightarrow> *)\n\nlemma fa_heap_indepD:\n  \"\\<lbrakk> fa_heap_indep fd n; length bs = n; length bs' = n \\<rbrakk> \\<Longrightarrow>\n  field_access fd v bs = field_access fd v bs'\"\n  unfolding fa_heap_indep_def\n  apply (drule spec, drule spec, drule spec)\n  apply (drule (1) mp)\n  apply (erule (1) mp)\n  done\n\n(* The simplifier spins on the IHs here, hence the proofs for each case *)\nlemma td_fa_hi_heap_independence:\n  shows \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi t; length h = size_td t; length h' = size_td t \\<rbrakk>\n  \\<Longrightarrow> access_ti t v h = access_ti t v h'\"\n  and   \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi_struct st; length h = size_td_struct st; length h' = size_td_struct st\\<rbrakk>\n  \\<Longrightarrow> access_ti_struct st v h = access_ti_struct st v h'\"\n  and   \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi_list ts;  length h = size_td_list ts; length h' = size_td_list ts \\<rbrakk>\n  \\<Longrightarrow> access_ti_list ts v h = access_ti_list ts v h'\"\n  and   \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi_pair p;  length h = size_td_pair p; length h' = size_td_pair p \\<rbrakk>\n  \\<Longrightarrow> access_ti_pair p v h = access_ti_pair p v h'\"\nproof (induct t and st and ts and p)\n  case TypDesc\n  from TypDesc.prems show ?case\n    by (simp) (erule (2) TypDesc.hyps)\nnext\n  case TypScalar\n  from TypScalar.prems show ?case\n    by simp (erule (2) fa_heap_indepD)\nnext\n  case TypAggregate\n  from TypAggregate.prems show ?case\n    by (simp) (erule (2) TypAggregate.hyps)\nnext\n  case Nil_typ_desc thus ?case by simp\nnext\n  case Cons_typ_desc\n  from Cons_typ_desc.prems show ?case\n    apply simp\n    apply (erule conjE)\n    apply (rule arg_cong2 [where f = \"op @\"])\n    apply (erule Cons_typ_desc.hyps, simp, simp)\n    apply (erule Cons_typ_desc.hyps, simp, simp)\n    done\nnext\n  case DTPair_typ_desc\n  from DTPair_typ_desc.prems show ?case\n    by simp (erule (2) DTPair_typ_desc.hyps)\nqed\n\nsection {* Simp rules for deriving packed props from the type combinators *}\n\nsubsection {* td_fafu_idem *}\n\nlemma td_fafu_idem_final_pad:\n  \"padup (2 ^ align_td t) (size_td t) = 0\n  \\<Longrightarrow> td_fafu_idem (final_pad t) = td_fafu_idem t\"\n  unfolding final_pad_def\n  by (clarsimp simp add: padup_def Let_def)\n\nlemma td_fafu_idem_ti_typ_pad_combine:\n  fixes t :: \"'a :: c_type itself\" and s :: \"'b :: c_type field_desc typ_desc\"\n  assumes pad: \"padup (align_of TYPE('a)) (size_td s) = 0\"\n  shows \"td_fafu_idem (ti_typ_pad_combine t xf xfu nm s) = td_fafu_idem (ti_typ_combine t xf xfu nm s)\"\n  unfolding ti_typ_pad_combine_def using pad\n  by (clarsimp simp: Let_def)\n\nlemma td_fafu_idem_list_append:\n  fixes xs :: \"'a :: c_type field_desc typ_pair list\"\n  shows \"td_fafu_idem_list (xs @ ys) = (td_fafu_idem_list xs \\<and> td_fafu_idem_list ys)\"\n  by (induct xs) simp+\n\nlemma td_fafu_idem_extend_ti:\n  fixes t :: \"'a :: c_type field_desc typ_desc\"\n  assumes as: \"td_fafu_idem s\"\n  and     at: \"td_fafu_idem t\"\n  shows \"td_fafu_idem (extend_ti s t nm)\" using as at\n  apply (cases s)\n  apply (rename_tac typ_struct xs)\n  apply (case_tac typ_struct)\n   apply simp\n  apply (simp add: td_fafu_idem_list_append)\n  done\n\nlemma fd_cons_access_updateD:\n  \"\\<lbrakk> fd_cons_access_update d n; length bs = n; length bs' = n\\<rbrakk> \\<Longrightarrow> field_access d (field_update d bs v) bs' = field_access d (field_update d bs v') bs'\"\n  unfolding fd_cons_access_update_def by clarsimp\n\n(* Beer crime? *)\nlemma fa_fu_idem_update_desc:\n  fixes a :: \"'a field_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and     fd: \"fd_cons_struct (TypScalar n n' a)\"\n  shows   \"fa_fu_idem (update_desc xf xfu a) n = fa_fu_idem a n\"\nproof\n  assume asm: \"fa_fu_idem (update_desc xf xfu a) n\"\n\n  let ?fu = \"\\<lambda>bs. if length bs = n then field_update a bs else id\"\n  let ?a' = \"\\<lparr> field_access = field_access a, field_update = ?fu \\<rparr>\"\n\n  show \"fa_fu_idem a n\"\n    unfolding fa_fu_idem_def\n  proof (intro impI conjI allI)\n    fix bs :: \"byte list\" and bs' :: \"byte list\" and v\n    assume l: \"length bs = n\" and l': \"length bs' = n\"\n\n    hence \"(\\<forall>v. field_access a (field_update a bs (xf v)) bs' = bs)\n      = (\\<forall>v. field_access a (?fu bs (xf v)) bs' = bs)\" by simp\n\n    also have \"\\<dots> = (\\<forall>v. field_access a (field_update a bs v) bs' = bs)\" using fd\n      apply -\n      apply rule\n      apply (rule allI)\n      apply (subst (asm) fd_cons_access_updateD [OF _ l l', where d = ?a', simplified])\n      apply (simp add: fd_cons_struct_def fd_cons_desc_def)\n      apply (fastforce simp: l l')\n      apply (fastforce simp: l l')\n      done\n\n    finally show \"field_access a (field_update a bs v) bs' = bs\" using asm fg l l'\n      by (clarsimp simp add: update_desc_def fa_fu_idem_def fg_cons_def)\n  qed\nnext\n  assume \"fa_fu_idem a n\"\n  thus \"fa_fu_idem (update_desc xf xfu a) n\"\n    unfolding fa_fu_idem_def update_desc_def using fg\n    by (clarsimp simp add: update_desc_def fa_fu_idem_def fg_cons_def)\nqed\n\nlemma td_fafu_idem_map_td_update_desc:\n  assumes fg: \"fg_cons xf xfu\"\n  shows  \"wf_fd t \\<Longrightarrow> td_fafu_idem (map_td (\\<lambda>_ _. update_desc xf xfu) t) = td_fafu_idem t\"\n  and    \"wf_fd_struct st \\<Longrightarrow> td_fafu_idem_struct (map_td_struct (\\<lambda>_ _. update_desc xf xfu) st) = td_fafu_idem_struct st\"\n  and    \"wf_fd_list ts \\<Longrightarrow> td_fafu_idem_list (map_td_list (\\<lambda>_ _. update_desc xf xfu) ts) = td_fafu_idem_list ts\"\n  and    \"wf_fd_pair p \\<Longrightarrow> td_fafu_idem_pair (map_td_pair (\\<lambda>_ _. update_desc xf xfu) p) = td_fafu_idem_pair p\"\n  by (induct t and st and ts and p) (auto elim!: fa_fu_idem_update_desc [OF fg])\n\nlemmas td_fafu_idem_adjust_ti = td_fafu_idem_map_td_update_desc(1)[folded adjust_ti_def]\n\nlemma td_fafu_idem_ti_typ_combine:\n  fixes s :: \"'b :: c_type field_desc typ_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and    tda: \"td_fafu_idem (typ_info_t TYPE('a :: mem_type))\"\n  and    tds: \"td_fafu_idem s\"\n  shows \"td_fafu_idem (ti_typ_combine TYPE('a :: mem_type) xf xfu nm s)\"\n  unfolding ti_typ_combine_def using tda tds\n  apply (clarsimp simp: Let_def)\n  apply (cases s)\n  apply (rename_tac typ_struct xs)\n  apply (case_tac typ_struct)\n   apply simp\n   apply (subst td_fafu_idem_adjust_ti [OF fg wf_fd], assumption)\n  apply (simp add: td_fafu_idem_list_append)\n  apply (subst td_fafu_idem_adjust_ti [OF fg wf_fd], assumption)\n  done\n\nlemma td_fafu_idem_ptr:\n   \"td_fafu_idem (typ_info_t TYPE('a :: c_type ptr))\"\n  apply (clarsimp simp add: fa_fu_idem_def)\n  apply (subst word_rsplit_rcat_size)\n   apply (clarsimp simp add: size_of_def word_size)\n  apply simp\n  done\n\nlemma td_fafu_idem_word:\n   \"td_fafu_idem (typ_info_t TYPE('a :: len8 word))\"\n  apply(clarsimp simp add: fa_fu_idem_def)\n  apply (subst word_rsplit_rcat_size)\n   apply (insert len8_dv8)\n   apply (clarsimp simp add: size_of_def word_size)\n   apply (subst dvd_div_mult_self)\n    apply simp\n   apply simp\n  apply simp\n  done\n\nlemma fg_cons_array [simp]:\n  \"n < card (UNIV :: 'b :: finite set) \\<Longrightarrow> fg_cons (\\<lambda>x. index x n) (\\<lambda>x f. Arrays.update (f :: 'a['b]) n x)\"\n  unfolding fg_cons_def by simp\n\nlemma td_fafu_idem_array_n:\n  \"\\<lbrakk>td_fafu_idem (typ_info_t TYPE('a)); n \\<le> card (UNIV :: 'b set) \\<rbrakk> \\<Longrightarrow> td_fafu_idem (array_tag_n n :: ('a :: mem_type ['b :: finite]) field_desc typ_desc)\"\n  apply (induct n)\n   apply (simp add: array_tag_n.simps empty_typ_info_def)\n  apply (simp add: array_tag_n.simps)\n  apply (rule td_fafu_idem_ti_typ_combine)\n    apply simp\n   apply simp\n  apply simp\n  done\n\nlemma td_fafu_idem_array:\n  \"td_fafu_idem (typ_info_t TYPE('a)) \\<Longrightarrow> td_fafu_idem (typ_info_t TYPE('a :: mem_type ['b :: finite]))\"\n  apply (clarsimp simp add: typ_info_array array_tag_def fa_fu_idem_def)\n  apply (erule td_fafu_idem_array_n)\n  apply simp\n  done\n\nlemma td_fafu_idem_empty_typ_info:\n  \"td_fafu_idem (empty_typ_info t)\"\n  unfolding empty_typ_info_def\n  by simp\n\nsubsection {* td_fa_hi *}\n\n(* These are mostly identical to the above --- surely there is something which implies both? *)\n\nlemma td_fa_hi_final_pad:\n  \"padup (2 ^ align_td t) (size_td t) = 0\n  \\<Longrightarrow> td_fa_hi (final_pad t) = td_fa_hi t\"\n  unfolding final_pad_def\n  by (clarsimp simp add: padup_def Let_def)\n\nlemma td_fa_hi_ti_typ_pad_combine:\n  fixes t :: \"'a :: c_type itself\" and s :: \"'b :: c_type field_desc typ_desc\"\n  assumes pad: \"padup (align_of TYPE('a)) (size_td s) = 0\"\n  shows \"td_fa_hi (ti_typ_pad_combine t xf xfu nm s) = td_fa_hi (ti_typ_combine t xf xfu nm s)\"\n  unfolding ti_typ_pad_combine_def using pad\n  by (clarsimp simp: Let_def)\n\nlemma td_fa_hi_list_append:\n  fixes xs :: \"'a :: c_type field_desc typ_pair list\"\n  shows \"td_fa_hi_list (xs @ ys) = (td_fa_hi_list xs \\<and> td_fa_hi_list ys)\"\n  by (induct xs) simp+\n\nlemma td_fa_hi_extend_ti:\n  fixes t :: \"'a :: c_type field_desc typ_desc\"\n  assumes as: \"td_fa_hi s\"\n  and     at: \"td_fa_hi t\"\n  shows \"td_fa_hi (extend_ti s t nm)\" using as at\n  apply (cases s)\n  apply (rename_tac typ_struct xs)\n  apply (case_tac typ_struct)\n   apply simp\n  apply (simp add: td_fa_hi_list_append)\n  done\n\n(* Beer crime? *)\nlemma fa_heap_indep_update_desc:\n  fixes a :: \"'a field_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and     fd: \"fd_cons_struct (TypScalar n n' a)\"\n  shows   \"fa_heap_indep (update_desc xf xfu a) n = fa_heap_indep a n\"\nproof\n  assume asm: \"fa_heap_indep (update_desc xf xfu a) n\"\n\n  have xf_xfu: \"\\<And>v v'. xf (xfu v v') = v\" using fg\n    unfolding fg_cons_def\n    by simp\n\n  show \"fa_heap_indep a n\"\n    unfolding fa_heap_indep_def\n  proof (intro impI conjI allI)\n    fix bs :: \"byte list\" and bs' :: \"byte list\" and v\n    assume l: \"length bs = n\" and l': \"length bs' = n\"\n    with asm have \"field_access (update_desc xf xfu a) (xfu v undefined) bs =\n      field_access (update_desc xf xfu a) (xfu v undefined) bs'\"\n      by (rule fa_heap_indepD)\n\n    thus \"field_access a v bs = field_access a v bs'\"\n      unfolding update_desc_def\n      by (simp add: xf_xfu)\n  qed\nnext\n  assume asm: \"fa_heap_indep a n\"\n  show \"fa_heap_indep (update_desc xf xfu a) n\"\n    unfolding fa_heap_indep_def update_desc_def\n  proof (simp, intro impI conjI allI)\n    fix bs :: \"byte list\" and bs' :: \"byte list\" and v\n    assume l: \"length bs = n\" and l': \"length bs' = n\"\n\n    with asm show \"field_access a (xf v) bs = field_access a (xf v) bs'\"\n      by (rule fa_heap_indepD)\n  qed\nqed\n\nlemma td_fa_hi_map_td_update_desc:\n  assumes fg: \"fg_cons xf xfu\"\n  shows  \"wf_fd t \\<Longrightarrow> td_fa_hi (map_td (\\<lambda>_ _. update_desc xf xfu) t) = td_fa_hi t\"\n  and    \"wf_fd_struct st \\<Longrightarrow> td_fa_hi_struct (map_td_struct (\\<lambda>_ _. update_desc xf xfu) st) = td_fa_hi_struct st\"\n  and    \"wf_fd_list ts \\<Longrightarrow> td_fa_hi_list (map_td_list (\\<lambda>_ _. update_desc xf xfu) ts) = td_fa_hi_list ts\"\n  and    \"wf_fd_pair p \\<Longrightarrow> td_fa_hi_pair (map_td_pair (\\<lambda>_ _. update_desc xf xfu) p) = td_fa_hi_pair p\"\n  by (induct t and st and ts and p) (auto elim!: fa_heap_indep_update_desc [OF fg])\n\nlemmas td_fa_hi_adjust_ti = td_fa_hi_map_td_update_desc(1)[folded adjust_ti_def]\n\nlemma td_fa_hi_ti_typ_combine:\n  fixes s :: \"'b :: c_type field_desc typ_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and    tda: \"td_fa_hi (typ_info_t TYPE('a :: mem_type))\"\n  and    tds: \"td_fa_hi s\"\n  shows \"td_fa_hi (ti_typ_combine TYPE('a :: mem_type) xf xfu nm s)\"\n  unfolding ti_typ_combine_def using tda tds\n  apply (clarsimp simp: Let_def)\n  apply (cases s)\n  apply (rename_tac typ_struct xs)\n  apply (case_tac typ_struct)\n   apply simp\n   apply (subst td_fa_hi_adjust_ti [OF fg wf_fd], assumption)\n  apply (simp add: td_fa_hi_list_append)\n  apply (subst td_fa_hi_adjust_ti [OF fg wf_fd], assumption)\n  done\n\nlemma td_fa_hi_ptr:\n   \"td_fa_hi (typ_info_t TYPE('a :: c_type ptr))\"\n  by (clarsimp simp add: fa_heap_indep_def)\n\nlemma td_fa_hi_word:\n   \"td_fa_hi (typ_info_t TYPE('a :: len8 word))\"\n  by (clarsimp simp add: fa_heap_indep_def)\n\nlemma td_fa_hi_array_n:\n  \"\\<lbrakk>td_fa_hi (typ_info_t TYPE('a)); n \\<le> card (UNIV :: 'b set) \\<rbrakk> \\<Longrightarrow> td_fa_hi (array_tag_n n :: ('a :: mem_type ['b :: finite]) field_desc typ_desc)\"\n  apply (induct n)\n   apply (simp add: array_tag_n.simps empty_typ_info_def)\n  apply (simp add: array_tag_n.simps)\n  apply (rule td_fa_hi_ti_typ_combine)\n    apply simp\n   apply simp\n  apply simp\n  done\n\nlemma td_fa_hi_array:\n  \"td_fa_hi (typ_info_t TYPE('a)) \\<Longrightarrow> td_fa_hi (typ_info_t TYPE('a :: mem_type ['b :: finite]))\"\n  apply (clarsimp simp add: typ_info_array array_tag_def fa_fu_idem_def)\n  apply (erule td_fa_hi_array_n)\n  apply simp\n  done\n\nlemma td_fa_hi_empty_typ_info:\n  \"td_fa_hi (empty_typ_info t)\"\n  unfolding empty_typ_info_def\n  by simp\n\nsection {* The type class and simp sets *}\n\ntext {* Packed types, with no padding, have the defining property that\n        access is invariant under substitution of the underlying heap and\n        access/update is the identity *}\n\nclass packed_type = mem_type +\n  assumes td_fafu_idem: \"td_fafu_idem (typ_info_t TYPE('a::c_type))\"\n  assumes td_fa_hi:     \"td_fa_hi (typ_info_t TYPE('a::c_type))\"\n\nlemmas td_fafu_idem_intro_simps =\n  -- \"Axioms\"\n  td_fafu_idem\n  -- \"Combinators\"\n  td_fafu_idem_final_pad td_fafu_idem_ti_typ_pad_combine td_fafu_idem_ti_typ_combine td_fafu_idem_empty_typ_info\n  -- \"Constructors\"\n  td_fafu_idem_ptr td_fafu_idem_word td_fafu_idem_array\n\nlemmas td_fa_hi_intro_simps =\n  -- \"Axioms\"\n  td_fa_hi\n  -- \"Combinators\"\n  td_fa_hi_final_pad td_fa_hi_ti_typ_pad_combine td_fa_hi_ti_typ_combine td_fa_hi_empty_typ_info\n  -- \"Constructors\"\n  td_fa_hi_ptr td_fa_hi_word td_fa_hi_array\n\nlemma align_td_array':\n  \"align_td (typ_info_t TYPE('a :: c_type['b :: finite])) = align_td (typ_info_t TYPE('a))\"\n  by (simp add: typ_info_array array_tag_def align_td_array_tag)\n\nlemmas packed_type_intro_simps =\n  td_fafu_idem_intro_simps td_fa_hi_intro_simps align_td_array' size_td_simps size_td_array\n\nlemma access_ti_append':\n  \"\\<And>list.\n   access_ti_list (xs @ ys) t list =\n     access_ti_list xs t (take (size_td_list xs) list) @\n     access_ti_list ys t (drop (size_td_list xs) list)\"\nproof(induct xs)\n  case Nil show ?case by simp\nnext\n  case (Cons x xs) thus ?case by (simp add: min_def ac_simps drop_take)\nqed\n\nsection {* Instances *}\n\ntext {* Words (of multiple of 8 size) are packed *}\n\ninstantiation word :: (len8) packed_type\nbegin\ninstance\n apply(intro_classes)\n   apply (rule td_fafu_idem_word)\n  apply (rule td_fa_hi_word)\n  done\nend\n\ntext {* Pointers are always packed *}\n\ninstantiation ptr :: (c_type)packed_type\nbegin\ninstance\n  apply intro_classes\n   apply (simp add: fa_fu_idem_def word_rsplit_rcat_size word_size)\n  apply (simp add: fa_heap_indep_def)\n  done\nend\n\ntext {* Arrays of packed types are in turn packed *}\n\nclass array_outer_packed = packed_type + array_outer_max_size\nclass array_inner_packed = array_outer_packed + array_inner_max_size\n\ninstance word :: (len8)array_outer_packed ..\ninstance word :: (len8)array_inner_packed ..\n\ninstance array :: (array_outer_packed, array_max_count) packed_type\n  apply(intro_classes)\n   apply (simp add: td_fafu_idem_intro_simps)\n  apply (simp add: td_fa_hi_intro_simps)\n  done\n\ninstance array :: (array_inner_packed, array_max_count) array_outer_packed ..\n\nsection {* Theorems about packed types *}\n\nsubsection {* td_fa_hi *}\n\nlemma heap_independence:\n  \"\\<lbrakk>length h = size_of TYPE('a :: packed_type); length h' = size_of TYPE('a) \\<rbrakk>\n  \\<Longrightarrow> access_ti (typ_info_t TYPE('a)) v h = access_ti (typ_info_t TYPE('a)) v h'\"\n  by (rule td_fa_hi_heap_independence(1)[OF td_fa_hi], simp_all add: size_of_def)\n\ntheorem packed_heap_update_collapse:\n fixes u::\"'a::packed_type\"\n fixes v::\"'a\"\n shows\n  \"heap_update p v (heap_update p u h) = heap_update p v h\"\n apply(simp add:heap_update_def)\n apply(rule ext)\n apply(case_tac \"x \\<in> {ptr_val p..+size_of TYPE('a)}\")\n  apply((subst heap_update_mem_same_point, simp, simp)+)\n  apply(simp add:to_bytes_def)\n  apply(subst heap_independence)\n    apply(simp)\n   prefer 2\n   apply(force)\n  apply(simp)\n apply((subst heap_update_nmem_same, simp)+)\n apply(rule refl)\ndone\n\nlemma packed_heap_update_collapse_hrs:\n  fixes p :: \"'a :: packed_type ptr\"\n  shows \"(hrs_mem_update (heap_update p v) (hrs_mem_update (heap_update p v') hp)) =\n  (hrs_mem_update (heap_update p v) hp)\"\n  unfolding hrs_mem_update_def\n  by (simp add: split_def packed_heap_update_collapse)\n\nsubsection {* td_fafu_idem *}\n\nlemma order_leE:\n  fixes x :: \"'a :: order\"\n  shows \"\\<lbrakk> x \\<le> y; x = y \\<Longrightarrow> P; x < y \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P\"\n  by (auto simp: order_le_less)\n\nlemma of_nat_mono_maybe_le:\n  shows \"\\<lbrakk>X < 2 ^ len_of TYPE('a); Y \\<le> X\\<rbrakk> \\<Longrightarrow> (of_nat Y :: 'a :: len word) \\<le> of_nat X\"\n  apply (erule order_leE)\n   apply simp\n  apply (rule order_less_imp_le)\n  apply (erule (1) of_nat_mono_maybe)\n  done\n\nlemma intvl_le_lower:\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk> x \\<in> {y..+n}; y \\<le> y + of_nat (n - 1); n < 2 ^ len_of TYPE('a) \\<rbrakk> \\<Longrightarrow> y \\<le> x\"\n  apply (drule intvlD)\n  apply (elim conjE exE)\n  apply (erule ssubst)\n  apply (erule word_plus_mono_right2)\n  apply (rule of_nat_mono_maybe_le)\n   apply simp\n  apply simp\n  done\n\nlemma intvl_less_upper:\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk> x \\<in> {y..+n}; y \\<le> y + of_nat (n - 1); n < 2 ^ len_of TYPE('a) \\<rbrakk> \\<Longrightarrow> x \\<le> y + of_nat (n - 1)\"\n  apply (drule intvlD)\n  apply (elim conjE exE)\n  apply (erule ssubst)\n  apply (rule word_plus_mono_right)\n   apply (rule of_nat_mono_maybe_le)\n    apply simp\n   apply simp\n  apply assumption\n  done\n\nlemma packed_type_access_ti:\n  fixes v :: \"'a :: packed_type\"\n  assumes lbs: \"length bs = size_of TYPE('a)\"\n  shows \"access_ti (typ_info_t TYPE('a)) v bs = access_ti\\<^sub>0 (typ_info_t TYPE('a)) v\"\n  unfolding access_ti\\<^sub>0_def using lbs\n  apply -\n  apply (rule heap_independence)\n   apply simp\n  apply (simp add: size_of_def)\n  done\n\nlemma update_ti_update_ti_t:\n  \"length bs = size_td s \\<Longrightarrow> update_ti s bs v = update_ti_t s bs v\"\n  unfolding update_ti_t_def by simp\n\nlemma heap_list_nth:\n  \"m < n \\<Longrightarrow> heap_list hp n p ! m = hp (p + of_nat m)\"\nproof (induct m arbitrary: n p)\n  case (0 n' p')\n\n  thus ?case by (cases n', simp_all)\nnext\n  case (Suc m' n' p')\n\n  show ?case\n  proof (cases n')\n    case 0 thus ?thesis using `Suc m' < n'` by simp\n  next\n    case (Suc n'')\n    hence \"m' < n''\" using `Suc m' < n'` by simp\n    thus ?thesis using Suc\n      by (simp add: Suc.hyps ac_simps)\n  qed\nqed\n\nlemma c_guard_field_lvalue:\n  fixes p :: \"'a :: mem_type ptr\"\n  assumes cg: \"c_guard p\"\n  and     fl: \"field_lookup (typ_info_t TYPE('a)) f 0 = Some (t, n)\"\n  and     eu: \"export_uinfo t = typ_uinfo_t TYPE('b :: mem_type)\"\n  shows   \"c_guard (Ptr &(p\\<rightarrow>f) :: 'b :: mem_type ptr)\"\n  unfolding c_guard_def\nproof (rule conjI)\n  from cg fl eu show \"ptr_aligned (Ptr &(p\\<rightarrow>f) :: 'b ptr)\"\n    by (rule c_guard_ptr_aligned_fl)\nnext\n  from eu have std: \"size_td t = size_of TYPE('b)\" using fl\n    by (simp add: export_size_of)\n\n  from cg have \"c_null_guard p\" unfolding c_guard_def ..\n  thus \"c_null_guard (Ptr &(p\\<rightarrow>f)  :: 'b ptr)\" unfolding c_null_guard_def\n    apply (rule contrapos_nn)\n    apply (rule subsetD [OF field_tag_sub, OF fl])\n    apply (simp add: std)\n    done\nqed\n\n(* Similar in TypHeap, but for w32 *)\nlemma unat_minus':\n  fixes x :: \"'a :: len word\"\n  shows \"x \\<noteq> 0 \\<Longrightarrow> unat (-x) = 2 ^ len_of TYPE('a) - unat x\"\n  apply (simp add: unat_def word_minus_def)\n  apply (simp add: int_word_uint zmod_zminus1_eq_if uint_0_iff)\n  apply (subst nat_diff_distrib)\n    apply simp\n   apply (rule order_less_imp_le [OF uint_lt2p])\n   apply (clarsimp simp: nat_power_eq)\n   done\n\nlemma word_wrap_of_natD:\n  fixes x :: \"'a :: len word\"\n  assumes wraps: \"\\<not> x \\<le> x + of_nat n\"\n  shows   \"\\<exists>k. x + of_nat k = 0 \\<and> k \\<le> n\"\nproof -\n  show ?thesis\n  proof (rule exI [where x = \"unat (- x)\"], intro conjI)\n    show \"x + of_nat (unat (-x)) = 0\"\n      by simp\n  next\n    show \"unat (-x) \\<le> n\"\n    proof (subst unat_minus')\n      from wraps show \"x \\<noteq> 0\"\n        by (rule contrapos_pn, simp add: not_le)\n    next\n      show \"2 ^ len_of TYPE('a) - unat x \\<le> n\" using wraps\n        apply (simp add: no_olen_add_nat le_diff_conv not_less)\n        apply (erule order_trans)\n        apply (simp add: unat_of_nat)\n        done\n    qed\n  qed\nqed\n\nlemma nat_le_Suc_less:\n  \"0 < y \\<Longrightarrow> (x \\<le> y - Suc 0) = (x < y)\"\n  by arith\n\nlemma c_guard_no_wrap:\n  fixes p :: \"'a :: mem_type ptr\"\n  assumes cgrd: \"c_guard p\"\n  shows   \"ptr_val p \\<le> ptr_val p + of_nat (size_of TYPE('a) - 1)\"\n  using cgrd unfolding c_guard_def c_null_guard_def\n  apply -\n  apply (erule conjE)\n  apply (erule contrapos_np)\n  apply (simp add: intvl_def)\n  apply (drule word_wrap_of_natD)\n  apply (erule exE)\n  apply (rule exI)\n  apply (simp add: nat_le_Suc_less)\n  done\n\ntheorem packed_heap_super_field_update:\n  fixes v :: \"'a :: packed_type\" and p :: \"'b :: packed_type ptr\"\n  assumes fl: \"field_lookup (typ_info_t TYPE('b)) f 0 = Some (t, n)\"\n  and   cgrd: \"c_guard p\"\n  and     eu: \"export_uinfo t = typ_uinfo_t TYPE('a)\"\n  shows   \"heap_update (Ptr &(p\\<rightarrow>f)) v hp = heap_update p (update_ti t (to_bytes_p v) (h_val hp p)) hp\"\n  unfolding heap_update_def to_bytes_def\nproof (simp add: packed_type_access_ti, rule ext)\n  fix x\n  let ?LHS = \"heap_update_list &(p\\<rightarrow>f) (to_bytes_p v) hp x\"\n  let ?RHS = \"heap_update_list (ptr_val p) (to_bytes_p (update_ti t (to_bytes_p v) (h_val hp p))) hp x\"\n\n  from cgrd have al: \"ptr_val p \\<le> ptr_val p + of_nat (size_of TYPE('b) - 1)\" by (rule c_guard_no_wrap)\n\n  have szb: \"size_of TYPE('b) < 2 ^ len_of TYPE(addr_bitsize)\"\n    apply (fold card_word)\n    apply (fold addr_card_def)\n    apply (rule max_size)\n    done\n\n  have szt: \"n + size_td t \\<le> size_of TYPE('b)\"\n    unfolding size_of_def\n    by (subst add.commute, rule field_lookup_offset_size [OF fl])\n  moreover have t0: \"0 < size_td t\" using fl wf_size_desc\n    by (rule field_lookup_wf_size_desc_gt)\n  ultimately have szn: \"n < size_of TYPE('b)\" by simp\n  from szt have szt1: \"n + (size_td t - 1) \\<le> size_of TYPE('b)\"\n    by simp\n\n  have b0: \"0 < size_of (TYPE ('b))\" using wf_size_desc\n    unfolding size_of_def\n    by (rule wf_size_desc_gt)\n\n  have uofn: \"unat (of_nat n :: addr_bitsize word) = n\" using szn szb\n    by (simp add: unat_simps)\n\n  from eu have std: \"size_td t = size_of TYPE('a)\" using fl\n    by (simp add: export_size_of)\n\n  hence \"?LHS = (if x \\<in> {&(p\\<rightarrow>f)..+size_td t} then (to_bytes_p v) ! unat (x - &(p\\<rightarrow>f)) else hp x)\"\n    by (simp add: heap_update_mem_same_point heap_update_nmem_same)\n  also have \"... = ?RHS\"\n  proof (simp, intro impI conjI)\n    assume xin: \"x \\<in> {&(p\\<rightarrow>f)..+size_td t}\"\n    have \"to_bytes_p v ! unat (x - &(p\\<rightarrow>f)) = to_bytes_p (update_ti t (to_bytes_p v) (h_val hp p)) ! unat (x - ptr_val p)\"\n    proof (simp add: to_bytes_p_def to_bytes_def, subst field_access_update_nth_inner(1)[OF fl, simplified])\n\n      have \"c_guard (Ptr &(p\\<rightarrow>f) :: 'a ptr)\" using cgrd fl eu\n        by (rule c_guard_field_lvalue)\n      hence pft: \"&(p\\<rightarrow>f) \\<le> &(p\\<rightarrow>f) + of_nat (size_td t - 1)\"\n        apply -\n        apply (drule c_guard_no_wrap)\n        apply (simp add: std)\n        done\n\n      have szt': \"size_td t < 2 ^ len_of TYPE(addr_bitsize)\"\n        apply (subst std)\n        apply (fold card_word)\n        apply (fold addr_card_def)\n        apply (rule max_size)\n        done\n\n      have ofn: \"of_nat n \\<le> x - ptr_val p\"\n      proof (rule le_minus')\n        from xin show \"ptr_val p + of_nat n \\<le> x\" using pft szt'\n          unfolding field_lvalue_def field_lookup_offset_eq [OF fl]\n          by (rule intvl_le_lower)\n      next\n        from szb szn have \"of_nat n \\<le> (of_nat (size_of TYPE('b) - 1) :: addr_bitsize word)\"\n          apply -\n          apply (rule of_nat_mono_maybe_le)\n          apply simp_all\n          done\n        with al show \"ptr_val p \\<le> ptr_val p + of_nat n\"\n          by (rule word_plus_mono_right2)\n      qed\n\n      thus nlt: \"n \\<le> unat (x - ptr_val p)\"\n        by (simp add: word_le_nat_alt uofn)\n      have \"x \\<le> ptr_val p + (of_nat n + of_nat (size_td t - 1))\" using xin pft szt' t0\n        unfolding field_lvalue_def field_lookup_offset_eq [OF fl]\n        apply -\n        apply (drule (2) intvl_less_upper)\n        apply (simp add: add.assoc)\n        done\n      moreover have \"x \\<in> {ptr_val p..+size_of TYPE('b)}\" using fl xin\n        by (rule subsetD [OF field_tag_sub])\n      ultimately have \"x - ptr_val p \\<le> (of_nat n + of_nat (size_td t - 1))\" using al szb\n        apply -\n        apply (rule word_diff_ls(4)[where xa=x and x=x for x, simplified])\n        apply (metis (hide_lams, mono_tags) add.commute of_nat_add)\n        apply (erule (2) intvl_le_lower)\n        done\n      moreover have \"unat (of_nat n + of_nat (size_td t - 1) :: addr_bitsize word) = n + size_td t - 1\"\n        using t0 order_le_less_trans [OF szt1 szb]\n        apply (subst Abs_fnat_homs(1))\n        apply (subst unat_of_nat)\n        apply simp\n        done\n      ultimately have \"unat (x - ptr_val p) \\<le> n + size_td t - 1\"\n        by (simp add: word_le_nat_alt)\n      thus \"unat (x - ptr_val p) < n + size_td t\" using t0\n        by simp\n\n      show \"td_fafu_idem t\"\n        by (rule field_lookup_td_fafu_idem(1)[OF fl td_fafu_idem])\n\n      show \"wf_fd t\"\n        by (rule wf_fd_field_lookupD [OF fl wf_fd])\n\n      show \"length (access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0)) = size_td t\"\n        using wf_fd [where 'a = 'a]\n        by (simp add: length_fa_ti size_of_def std)\n\n      show \"length (replicate (size_of TYPE('b)) 0) = size_td (typ_info_t TYPE('b))\"\n        by (simp add: size_of_def)\n\n      have \"unat (x - &(p\\<rightarrow>f)) = unat ((x - ptr_val p) - of_nat n)\"\n        by (simp add: field_lvalue_def field_lookup_offset_eq [OF fl])\n      also have \"\\<dots> = unat (x - ptr_val p) - n\"\n        by (simp add: unat_sub [OF ofn] uofn)\n      finally have \"unat (x - &(p\\<rightarrow>f)) = unat (x - ptr_val p) - n\" .\n\n      thus \"access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0) ! unat (x - &(p\\<rightarrow>f)) =\n        access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0) ! (unat (x - ptr_val p) - n)\"\n        by simp\n    qed\n\n    thus \"to_bytes_p v ! unat (x - &(p\\<rightarrow>f)) = ?RHS\"\n    proof (subst heap_update_mem_same_point, simp_all)\n      show \"x \\<in> {ptr_val p..+size_of TYPE('b)}\" using fl xin\n        by (rule subsetD [OF field_tag_sub])\n    qed\n  next\n    assume xni: \"x \\<notin> {&(p\\<rightarrow>f)..+size_td t}\"\n    have \"?RHS = (if x \\<in> {ptr_val p..+size_of TYPE('b)}\n          then (to_bytes_p (update_ti t (to_bytes_p v) (h_val hp p))) ! unat (x - ptr_val p) else hp x)\"\n      by (simp add: heap_update_mem_same_point heap_update_nmem_same)\n\n    also\n    {\n      assume xin: \"x \\<in> {ptr_val p..+size_of TYPE('b)}\"\n\n      hence \"access_ti (typ_info_t TYPE('b))\n        (update_ti_t t (access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0)) (h_val hp p))\n        (replicate (size_of TYPE('b)) 0) ! unat (x - ptr_val p) = hp x\"\n      proof (subst field_access_update_nth_disjD [OF fl])\n        have \"x - ptr_val p \\<le> of_nat (size_of TYPE('b) - 1)\"\n        proof (rule word_diff_ls(4)[where xa=x and x=x for x, simplified])\n          from xin show \"x \\<le> of_nat (size_of TYPE('b) - 1) + ptr_val p\" using al szb\n            by (subst add.commute, rule intvl_less_upper)\n          show \"ptr_val p \\<le> x\" using xin al szb\n            by (rule intvl_le_lower)\n        qed\n        thus unx: \"unat (x - ptr_val p) < size_td (typ_info_t TYPE('b))\" using szb b0\n          by (simp add: word_le_nat_alt size_of_def unat_of_nat)\n\n        show \"unat (x - ptr_val p) < n - 0 \\<or> n - 0 + size_td t \\<le> unat (x - ptr_val p)\" using xin xni\n            unfolding field_lvalue_def field_lookup_offset_eq [OF fl]\n          apply -\n          apply (erule intvl_cut)\n          apply simp\n          apply (rule max_size)\n          done\n\n        show \"wf_fd (typ_info_t TYPE('b))\" by (rule wf_fd)\n        (* clag *)\n        show \"length (access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0)) = size_td t\"\n          using wf_fd [where 'a = 'a]\n          by (simp add: length_fa_ti size_of_def std)\n\n        show \"length (replicate (size_of TYPE('b)) 0) = size_td (typ_info_t TYPE('b))\"\n          by (simp add: size_of_def)\n\n        have \"heap_list hp (size_td (typ_info_t TYPE('b))) (ptr_val p) ! unat (x - ptr_val p) = hp x\"\n          apply (subst heap_list_nth)\n          apply (rule unx)\n          apply simp\n          done\n\n        thus \"access_ti (typ_info_t TYPE('b)) (h_val hp p) (replicate (size_of TYPE('b)) 0) ! unat (x - ptr_val p) = hp x\"\n          unfolding h_val_def\n          by (simp add: from_bytes_def update_ti_t_def size_of_def field_access_update_same(1)[OF td_fafu_idem wf_fd])\n      qed\n     }\n    hence \"\\<dots> = hp x\"\n      by (simp add: to_bytes_p_def to_bytes_def update_ti_update_ti_t length_fa_ti [OF wf_fd] std size_of_def)\n    finally show \"hp x = ?RHS\" by simp\n  qed\n  finally show \"?LHS = ?RHS\" .\nqed\n\nend\n", "meta": {"author": "z5146542", "repo": "TOR", "sha": "9a82d491288a6d013e0764f68e602a63e48f92cf", "save_path": "github-repos/isabelle/z5146542-TOR", "path": "github-repos/isabelle/z5146542-TOR/TOR-9a82d491288a6d013e0764f68e602a63e48f92cf/checker-verification/autocorres-1.4/c-parser/PackedTypes.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6113819591324416, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.28423243351001287}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: GPL-2.0-only\n *)\n\ntheory ArchVSpaceLookup_AI\nimports \"../SubMonad_AI\"\n \"Lib.Crunch_Instances_NonDet\"\nbegin\n\ndefinition\n  \"lookup_walk cs m ref p \\<equiv> {(r, q). \\<exists>h. ref = h @ r \\<and> (r, q) \\<in> cs\\<^sup>* `` m \\<and> (([], q),h, p) \\<in> cs\\<^sup>*}\"\n\ndefinition\n  \"trans_depends kh cs f \\<equiv> \\<forall>q h p. (([],q),h,p) \\<in> cs = (\\<exists>obj. obj = kh q \\<and> f obj p h)\"\n\ndefinition\n  \"lookup_leaf ptr cs =  {(ref,p). (([],ptr),ref, p) \\<in> cs^*}\"\n\ndefinition\nlookup_refs ::\"'c \\<Rightarrow> ('c \\<Rightarrow> 'b \\<Rightarrow> 'a list \\<Rightarrow> bool) \\<Rightarrow> ('a list \\<times> 'b) set\"\nwhere \"lookup_refs obj f \\<equiv> {(h,p). f obj p h}\"\n\ndefinition\nlookupable_refs :: \"(('a list \\<times> 'b) \\<times> 'a list \\<times> 'b) set \\<Rightarrow> 'a list set \\<Rightarrow> ('a list \\<times> 'b) set \\<Rightarrow> ('a list \\<times> 'b) set\"\nwhere  \"lookupable_refs cs refs m \\<equiv> {(ref, p). \\<exists>tref href. href\\<in>refs \\<and> ref=tref@href \\<and> (tref,p)\\<in>cs^* `` m}\"\n\ndefinition\n  \"reachable vset \\<equiv> (\\<lambda>(ref, p). p) ` vset\"\n\nlocale wellformed_lookup =\n  fixes cs :: \"(('c list \\<times> 'a) \\<times> 'c list \\<times> 'a) set\" and kh and f\n  assumes trans_depends: \"trans_depends kh cs f\"\n  assumes lookup1_is_append:\n      \"((r , q), rs, p) \\<in> cs \\<Longrightarrow> \\<exists>ref. rs = ref # r\"\n  assumes lookup1_append:\n      \"((ra @ b, q), r @ b, p) \\<in> cs \\<Longrightarrow> ((ra, q), r, p) \\<in> cs\"\n  assumes lookup1_cut:\n      \"((ra, q), r, p) \\<in> cs \\<Longrightarrow> ((ra @ b, q), r @ b, p) \\<in> cs\"\n  assumes graph_inject:\n      \"\\<And>p q obj ref. \\<lbrakk>f obj p ref; f obj q ref\\<rbrakk> \\<Longrightarrow> p = q\"\n  assumes graph_single_step:\n      \"\\<And>p obj ref. \\<lbrakk>f obj p ref\\<rbrakk> \\<Longrightarrow> \\<exists>r. ref = [r]\"\n\ncontext wellformed_lookup\nbegin\n\nlemma lookup_refs_lookup1:\n  \"lookup_refs (kh ptr) f = {(h,p). (([],ptr),h,p) \\<in> cs}\"\n  apply (insert  trans_depends)\n  apply (clarsimp simp: trans_depends_def lookup_refs_def)\n  done\n\nlemma lookupable_refs_reach_self:\n  \"(rs, ptr) \\<in> lookupable_refs cs {ref. (ref, ptr) \\<in> cs\\<^sup>* `` rset} refs\n  \\<Longrightarrow> \\<exists>rs'. (rs', ptr) \\<in> cs^* `` rset\"\n  apply (clarsimp simp: lookupable_refs_def Image_def)\n  apply fastforce\n  done\n\nlemma lookup1_append_singleton:\n  \"((a, b), ref # a, q) \\<in> cs \\<Longrightarrow> (([], b), [ref], q) \\<in> cs\"\n  apply (rule lookup1_append)\n  apply fastforce\n  done\n\nlemma lookup1_cut_singleton:\n  \"(([], b), [ref], q) \\<in> cs \\<Longrightarrow> ((a, b), ref # a, q) \\<in> cs \"\n  apply (drule lookup1_cut)\n  apply fastforce\n  done\n\nlemma trans_dependsD:\n  \"(([],p), ref, q ) \\<in> cs \\<Longrightarrow> f (kh p) q ref\"\n  apply (insert trans_depends)\n  apply (simp add: trans_depends_def)\n  done\n\nlemma trans_depends_eq:\n  \"(([],q),h,p) \\<in> cs = f (kh q) p h\"\n  apply (insert trans_depends)\n  apply (clarsimp simp: trans_depends_def)\n  done\n\nlemma lookup_empty_refl:\n  \"((a, p), [], q) \\<in> cs\\<^sup>* \\<Longrightarrow> a = [] \\<and> p = q\"\n  apply (erule rtranclE)\n   apply simp\n  apply (case_tac y)\n  apply (clarsimp dest!: lookup1_is_append)\n  done\n\nlemma lookup_empty_refl_eq[simp]:\n  \"((a, p), [], q) \\<in> cs\\<^sup>* \\<longleftrightarrow> a = [] \\<and> p = q\"\n  using lookup_empty_refl by auto\n\nlemma lookup1_same_leaf:\n  \"\\<lbrakk>(a, refs, p) \\<in> cs; (a, refs, q) \\<in> cs\\<rbrakk> \\<Longrightarrow> p = q\"\n  apply (case_tac a)\n  apply clarsimp\n  apply (frule lookup1_is_append)\n  apply clarsimp\n  apply (drule lookup1_append_singleton)\n  apply (drule lookup1_append_singleton)\n  apply (clarsimp dest!: trans_dependsD)\n  apply (drule graph_inject)\n  apply simp+\n  done\n\nlemma lookup_ref_step:\n  \"((ref, ptr), ref', p) \\<in> cs\\<^sup>* \\<Longrightarrow> \\<exists>r. ref' = r @ ref\"\n  proof (induct \"length ref'\" arbitrary: ref' ref ptr p)\n  case 0\n    assume xs: \"0 = length ref'\"\n      and  \"((ref, ptr), ref', p) \\<in> cs\\<^sup>*\"\n  thus ?case\n    apply simp\n    done\n  next\n  case Suc\n  show ?case\n    apply (cut_tac Suc.prems Suc.hyps(2))\n    apply (erule rtranclE)\n     apply fastforce\n    apply (case_tac y)\n    apply (case_tac ref')\n     apply clarsimp\n    apply simp\n    apply (drule Suc.hyps(1)[rotated])\n     apply (clarsimp dest!: lookup1_is_append )+\n    done\n  qed\n\nlemma lookup_trancl_append_1: (* This is true because the lengh of the lookup is always increased by 1 *)\n  \"((ra @ [b], q), r @ [b], p) \\<in> cs\\<^sup>*\n  \\<Longrightarrow> ((ra, q), r, p) \\<in> cs\\<^sup>*\"\n  proof (induct \"length r - length ra\" arbitrary: ra r q p)\n  case 0\n    assume \"0 = length r - length ra\"\n    and \"((ra @ [b], q), r @ [b], p) \\<in> cs\\<^sup>*\"\n  thus ?case\n    apply simp\n    apply (erule rtranclE)\n     apply simp\n    apply (case_tac y)\n    apply simp\n    apply (frule lookup_ref_step)\n    apply (clarsimp dest!: lookup1_is_append)\n    done\n  next\n  case Suc\n  show ?case\n    apply (insert Suc.prems Suc.hyps(2))\n    apply (erule rtranclE)\n     apply simp\n    apply (case_tac y)\n    apply clarsimp\n    apply (frule lookup_ref_step)\n    apply clarsimp\n    apply (drule Suc.hyps(1)[where r = \"a @ b\" for a b, rotated,simplified])\n     apply (clarsimp dest!: lookup1_is_append)\n    apply (drule lookup1_append[where ra = \"a @ b\" for a b, simplified])\n    apply (erule rtrancl.intros)\n    apply simp\n    done\n  qed\n\n\nlemma lookup_trancl_append:\n  \"((ra @ ref, b), r @ ref, p) \\<in> cs^* \\<Longrightarrow> ((ra, b), r, p) \\<in> cs^*\"\n  proof (induct \"length ref\" arbitrary: ref ra r b p)\n  case 0\n  assume \"((ra @ ref, b), r @ ref, p) \\<in> cs ^*\"\n     and \" 0 = length ref\"\n  thus ?case\n    by simp\n  next\n  case Suc\n  have t: \"\\<And>a b c. a @ b # c = (a @ [b]) @ c\"\n    by auto\n  show ?case\n    apply (insert Suc.prems Suc.hyps(2))\n    apply (case_tac ref)\n     apply clarsimp+\n    apply (subst(asm) t)\n    apply (subst(asm) t[where a = r])\n    apply (frule(1) Suc.hyps(1)[rotated])\n    apply (drule lookup_trancl_append_1)\n    apply fastforce\n    done\n  qed\n\nlemma lookup_leaf_from_lookup:\n  assumes neq: \"ref' \\<noteq> ref\"\n  shows \"\\<lbrakk>((ref, p), ref', q) \\<in> cs\\<^sup>* \\<rbrakk>\n  \\<Longrightarrow> \\<exists>r ptr. ref' = r @ ref \\<and> (([],p),[last r],ptr) \\<in> cs \\<and> (r,q) \\<in> lookup_leaf p cs\"\n  apply (frule lookup_ref_step)\n  apply clarsimp\n  apply (erule converse_rtranclE)\n   apply (insert neq)\n   apply clarsimp\n  apply (case_tac y)\n  apply (rule conjI)\n   apply clarsimp\n   apply (rename_tac r mref ptr)\n   apply (rule_tac x = ptr in exI)\n   subgoal ex\n    apply (clarsimp dest!: lookup_ref_step)\n    apply (rule_tac ra = \"[]\" and b = ref in lookup1_append)\n    apply (frule lookup1_is_append)\n    apply clarsimp\n    done\n  apply (clarsimp simp: lookup_leaf_def)\n  apply (rule converse_rtrancl_into_rtrancl)\n  apply (rule ex)\n      apply simp+\n  apply (rule_tac ref = ref in lookup_trancl_append)\n  apply (frule lookup_ref_step)\n  apply (clarsimp dest!: lookup1_is_append)\n  done\n\nlemma lookupE:\n  assumes rcl: \"((ref, p), ref', q) \\<in> cs\\<^sup>*\"\n  assumes eq: \"\\<lbrakk>ref' = ref; p = q\\<rbrakk> \\<Longrightarrow> P ref' ref p q cs\"\n  and neq: \"\\<And>r ptr. \\<lbrakk>ref' \\<noteq> ref; ref' = r @ ref;  (([],p),[last r],ptr) \\<in> cs; (r,q) \\<in> lookup_leaf p cs\\<rbrakk> \\<Longrightarrow> P ref' ref p q cs\"\n  shows \"P ref' ref p q cs\"\n  apply (insert rcl)\n  apply (case_tac \"ref' = ref\")\n   apply (rule eq)\n    apply simp\n   apply (erule rtranclE)\n    apply simp\n   apply (clarsimp dest!: lookup1_is_append lookup_ref_step)\n  apply (frule(1) lookup_leaf_from_lookup)\n  apply (elim disjE conjE exE)\n  apply (rule neq)\n   apply simp+\n  done\n\nlemma lookup_forwardE:\n  assumes rcl: \"(([], p), ref, q) \\<in> cs\\<^sup>*\"\n  assumes eq: \"\\<lbrakk>ref = []; p = q\\<rbrakk> \\<Longrightarrow> P ref p q cs\"\n  and neq1: \"\\<And>r. \\<lbrakk>ref = [r]; (([], p), [r], q) \\<in> cs\\<rbrakk> \\<Longrightarrow> P ref p q cs\"\n  and neq: \"\\<And>r ptr ref'. \\<lbrakk>ref \\<noteq> []; ref = r @ [ref'];  (([],p),[ref'],ptr) \\<in> cs; (([], ptr), r, q) \\<in> cs\\<^sup>*\\<rbrakk> \\<Longrightarrow> P ref p q cs\"\n  shows \"P ref p q cs\"\n  apply (insert rcl)\n  apply (erule converse_rtranclE)\n   apply (rule eq)\n    apply (simp add: eq)\n   apply simp\n  apply clarsimp\n  apply (frule lookup_ref_step)\n  apply (frule lookup1_is_append)\n  apply (elim exE)+\n  apply (case_tac r)\n   apply (rule neq1)\n    apply simp\n   apply clarsimp\n   apply (erule rtranclE, simp)\n   apply (clarsimp dest!: lookup1_is_append)\n  apply clarsimp\n  apply (drule lookup_trancl_append[where ra = \"[]\" and r = \"h # g\" for h g,simplified])\n  apply (drule neq[rotated 2])\n    apply simp+\n  done\n\nlemma lookup_rtrancl_stepD:\n  \"(([],p), [r], q) \\<in> cs^* \\<Longrightarrow> (([],p),[r],q) \\<in> cs\"\n  apply (erule rtranclE)\n  apply simp\n  apply clarsimp\n  apply (frule lookup_ref_step)\n  apply clarsimp\n  apply (erule rtranclE)\n   apply simp\n  apply (clarsimp dest!: lookup_ref_step lookup1_is_append)\n  done\n\nlemma lookup_rtrancl_stepsD:\n  \"(([], p), r @ [ref'], q) \\<in> cs\\<^sup>* \\<Longrightarrow> \\<exists>ptr. (([],p),[ref'],ptr) \\<in> cs \\<and> (([], ptr), r, q) \\<in> cs\\<^sup>*\"\n  apply (erule lookup_forwardE)\n  apply clarsimp+\n  apply force+\n  done\n\nlemma lookup_trancl_cut_1:\n  (* This is true because the lengh of the lookup is always increased by 1 *)\n  \"((ra, q), r, p) \\<in> cs\\<^sup>* \\<Longrightarrow> ((ra @ [b], q), r @ [b], p) \\<in> cs\\<^sup>*\"\n    proof (induct \"length r - length ra\" arbitrary: ra r q p)\n  case 0\n    assume \" 0 = length r - length ra\"\n    and \"((ra , q), r , p) \\<in> cs\\<^sup>*\"\n  thus ?case\n    apply simp\n    apply (frule lookup_ref_step)\n    apply clarsimp\n    apply (erule rtranclE)\n     apply simp\n    apply (case_tac y)\n    apply simp\n    apply (frule lookup_ref_step)\n    apply (clarsimp dest!: lookup1_is_append)\n    done\n  next\n  case Suc\n  show ?case\n    apply (insert Suc.prems Suc.hyps(2))\n    apply (erule rtranclE)\n     apply simp\n    apply (case_tac y)\n    apply clarsimp\n    apply (frule lookup_ref_step)\n    apply clarsimp\n    apply (drule Suc.hyps(1)[where r = \"a @ b\" for a b, rotated,simplified])\n     apply (clarsimp dest!: lookup1_is_append)\n    apply (erule rtrancl.intros)\n    apply (frule lookup1_cut)\n    apply simp\n    done\n  qed\n\nlemma lookup_trancl_cut:\n  \"((ra, b), r, p) \\<in> cs\\<^sup>* \\<Longrightarrow> ((ra @ ref, b), r @ ref, p) \\<in> cs\\<^sup>*\"\n  proof (induct \"length ref\" arbitrary: ref ra r b p)\n  case 0\n  assume \"((ra, b), r, p) \\<in> cs\\<^sup>*\"\n     and \" 0 = length ref\"\n  thus ?case\n    by simp\n  next\n  case Suc\n  have t: \"\\<And>a b c. a @ b # c = (a @ [b]) @ c\"\n    by auto\n  show ?case\n    apply (insert Suc.prems Suc.hyps(2))\n    apply (case_tac ref rule: rev_cases)\n     apply clarsimp+\n    apply (frule(1) Suc.hyps(1)[rotated])\n    apply (drule lookup_trancl_cut_1)\n        apply (drule lookup_trancl_cut_1)\n    apply fastforce\n    done\n  qed\n\nlemma empty_lookup_walk:\n  \"lookup_walk cs m [] p = {ptr. ptr \\<in> m \\<and> fst ptr = [] \\<and> snd ptr = p }\"\n  by (fastforce simp: lookup_walk_def)\n\nlemma lookup_walk_stepI1:\n  \"\\<lbrakk>p \\<in> lookup_walk cs m ref ptr; (([], ptr), [q], ptr') \\<in> cs\\<rbrakk> \\<Longrightarrow> p \\<in> lookup_walk cs m (q # ref) ptr'\"\n  apply (clarsimp simp: lookup_walk_def)\n  apply (rule conjI, fastforce)\n  apply (erule rtrancl_into_rtrancl)\n  apply (erule lookup1_cut[where ra = \"[]\" and r = \"[q]\", simplified])\n  done\n\nlemma lookup_walk_stepsI1:\n  \"\\<lbrakk>p \\<in> lookup_walk cs m ref ptr; (([], ptr), refs, ptr') \\<in> cs^*\\<rbrakk> \\<Longrightarrow> p \\<in> lookup_walk cs m (refs @ ref) ptr'\"\n  apply (clarsimp simp: lookup_walk_def)\n  apply (rule conjI, fastforce)\n  apply (erule rtrancl_trans)\n  apply (erule lookup_trancl_cut[where ra = \"[]\" and r = \"refs\", simplified])\n  done\n\nlemma lookup_walk_stepI2:\n  \"\\<lbrakk>(ref, ptr) \\<in> lookup_walk cs m ref ptr; (([], ptr), [q], ptr') \\<in> cs\\<rbrakk>\n  \\<Longrightarrow> (q#ref,ptr') \\<in> lookup_walk cs m (q # ref) ptr'\"\n  apply (clarsimp simp: lookup_walk_def Image_def)\n  apply (erule bexI[rotated])\n  apply (erule rtrancl_into_rtrancl)\n  apply (drule lookup1_cut)\n  apply fastforce\n  done\n\nlemma lookup_walk_step_hdD:\n  \"(refs, p) \\<in> lookup_walk cs m refs p \\<Longrightarrow> (refs, p)\\<in> m \\<or> (\\<exists>y. (tl refs,y) \\<in> lookup_walk cs m (tl refs) y \\<and> (([],y), [hd refs], p) \\<in> cs)\"\n  apply (clarsimp simp: lookup_walk_def del: disjCI)\n  apply (erule rtranclE)\n   apply simp\n  apply (rule disjI2)\n  apply (case_tac y, clarsimp)\n  apply (frule lookup1_is_append)\n  apply clarsimp\n  apply (intro conjI exI)\n   apply fastforce\n  apply (erule lookup1_append_singleton)\n  done\n\nlemma lookup_walk_stepD:\n  \"p \\<in> lookup_walk cs m (ref # refs) q\n  \\<Longrightarrow> p = (ref # refs, q)\n      \\<or> (\\<exists>ptr r. r @ (fst p) = refs \\<and> p \\<in> lookup_walk cs m refs ptr \\<and> (([],ptr),[ref], q) \\<in> cs)\"\n  apply (clarsimp simp: lookup_walk_def del: disjCI)\n  apply (erule rtranclE)\n   apply clarsimp\n  apply (case_tac ya, clarsimp del: disjCI)\n  apply (frule lookup1_is_append)\n  apply (clarsimp del: disjCI)\n  apply (rule conjI)\n   apply force\n  apply (intro exI conjI)\n   apply force\n  apply (erule lookup1_append_singleton)\n  done\n\nlemma reachable_walk:\n  \"(ref, p) \\<in> (cs^* `` m) \\<Longrightarrow> (ref, p) \\<in> lookup_walk cs m ref p\"\n  by (clarsimp simp: lookup_walk_def)\n\nlemma lookup_trans_eq:\n  \"((refs, b), refs, p) \\<in> cs\\<^sup>* \\<Longrightarrow> b = p\"\n  by (erule lookup_trancl_append[where ra = \"[]\" and r = \"[]\" , simplified])\n\nlemma lookup1_same_parent:\n  \"\\<lbrakk>(a, refs, p) \\<in> cs; (b, refs, q) \\<in> cs\\<rbrakk> \\<Longrightarrow> fst a = fst b\"\n  apply (insert trans_depends)\n  apply (case_tac a,case_tac b)\n  apply (clarsimp dest!: lookup1_is_append)\n  done\n\nlemma lookupable_is_unique:\n \"\\<lbrakk>(sref, refs, p) \\<in> cs^*; (sref, refs, q) \\<in> cs^* \\<rbrakk>\n \\<Longrightarrow> p = q\"\n  proof (induct \"length refs - length (fst sref)\" arbitrary: p q sref refs)\n  case 0\n  thus ?case\n    apply (insert \"local.0.prems\" \"local.0.hyps\")\n    apply (cases sref, simp)\n    apply (case_tac \"fst sref = refs\")\n     apply (clarsimp dest!: lookup_trans_eq)\n    apply clarsimp\n    apply (drule lookup_leaf_from_lookup[rotated])\n     apply simp\n    apply clarsimp\n    done\n  next\n  case Suc\n  show ?case\n    apply (insert Suc.prems Suc.hyps(2))\n    apply (erule rtranclE, simp)\n    apply (erule rtranclE, simp)\n    apply (frule_tac a = y and b = ya in lookup1_same_parent)\n     apply simp\n    apply (case_tac y, clarsimp)\n    apply (drule(1) Suc.hyps(1)[rotated])\n     apply (fastforce dest!: lookup1_is_append)\n   apply clarsimp\n   apply (erule(1) lookup1_same_leaf)\n   done\n  qed\n\nlemma lookup_walk_reduce:\n  \"(ref, ptr) \\<in> lookup_walk cs m refs q\n  \\<Longrightarrow> (ref, ptr) \\<in> lookup_walk cs m ref ptr\"\n  by (clarsimp simp: lookup_walk_def)\n\nlemma lookup_walk_trivial:\n  \"a \\<in> lookup_walk cs m ref ptr\n  \\<Longrightarrow> (ref, ptr) \\<in> lookup_walk cs m ref ptr\"\n  apply (clarsimp simp: lookup_walk_def Image_def)\n  apply (erule bexI[rotated])\n  apply (erule rtrancl_trans)\n  apply clarsimp\n  apply (drule_tac ref = x in lookup_trancl_cut)\n  apply clarsimp\n  done\n\nlemma lookup_walk_imp_reachable:\n  \"p \\<in> lookup_walk cs m r ptr \\<Longrightarrow> (r, ptr) \\<in> cs^* `` m\"\n  apply (clarsimp simp: lookup_walk_def Image_def)\n  apply (erule bexI[rotated])\n  apply (erule rtrancl_trans)\n  apply (erule lookup_trancl_cut[where ra = \"[]\", simplified])\n  done\n\nlemma lookup_trancl_walk:\n  \"(([], pa), ref, rptr) \\<in> cs\\<^sup>* \\<Longrightarrow> (ref, rptr) \\<in> lookup_walk cs {([],pa)} ref rptr\"\n  by (clarsimp simp: lookup_walk_def)\n\nlemma lookup1_eq_ref:\n  \"(ref, ptr) \\<in> lookup_walk cs m ref p \\<Longrightarrow> p = ptr\"\n  by (clarsimp simp: lookup_walk_def)\n\nlemma lookup_walk_decomp:\n  \"(a, ptr) \\<in> lookup_walk cs rset r rptr \\<Longrightarrow>\n  \\<exists>h. r = h @ a \\<and> (h,rptr) \\<in> lookup_walk cs ({([], ptr)}) h rptr\"\n  apply (clarsimp simp: lookup_walk_def)\n  done\n\nlemma lookup_walk_decomp_more:\n  \"(h @ [b],rptr) \\<in> lookup_walk cs ({([], ptr)}) (h @ [b]) rptr \\<Longrightarrow>\n    \\<exists>p. (([], ptr), [b], p) \\<in> cs \\<and> (([], p), h, rptr) \\<in> cs\\<^sup>*\"\n  apply (clarsimp simp: lookup_walk_def)\n  apply (erule converse_rtranclE)\n   apply clarsimp\n  apply clarsimp\n  apply (frule lookup1_is_append)\n  apply clarsimp\n  apply (frule lookup_ref_step)\n  apply (intro exI conjI)\n   apply force\n  apply (rule lookup_trancl_append)\n  apply force\n  done\n\nlemma lookupable_refs_set:\n  shows \"lookupable_refs cs refs (lookup_refs a f)\n    \\<subseteq> lookupable_refs cs refs (lookup_refs a f - lookup_refs b f) \\<union> lookupable_refs cs refs (lookup_refs b f)\"\n  apply (fastforce simp: lookupable_refs_def Image_def)\n  done\n\nlemma in_lookupable_refsI:\n  \"\\<lbrakk>(ref, ptr) \\<in> cs\\<^sup>* `` rset; f obj b a ; ((a, b), refs, rptr) \\<in> cs\\<^sup>*\\<rbrakk> \\<Longrightarrow>\n  (refs @ ref, rptr) \\<in> lookupable_refs cs {ref. (ref, ptr) \\<in> cs\\<^sup>* `` rset} (lookup_refs obj f)\"\n  apply (clarsimp simp: lookupable_refs_def Image_def)\n  apply (intro exI conjI)\n    apply fastforce\n   apply fastforce\n  apply (clarsimp simp: lookup_refs_def)\n  apply fastforce\n  done\n\n(* The main result for this locale *)\ntheorem khupd_graph_subset:\n  assumes wlcs: \"wellformed_lookup cs' (kh(ptr := obj)) f\"\n  shows \"(refs, p) \\<in> cs'^* `` rset \\<Longrightarrow> \\<exists>sref. (sref, p) \\<in> cs^* `` rset \\<union> lookupable_refs cs\n      {ref. (ref, ptr) \\<in> cs^* `` rset} (lookup_refs obj f)\"\n  proof (induct \"length refs\" arbitrary: refs p)\n   case 0\n   note \"0.prems\" \"0.hyps\"\n   thus ?case\n    apply clarsimp\n    apply (erule rtranclE, fastforce)\n    apply (clarsimp dest!: wellformed_lookup.lookup1_is_append[OF wlcs])\n    done\n   next\n   case Suc\n   thus ?case\n    apply (insert Suc.hyps(2) Suc.prems)\n    apply (clarsimp del: disjCI)\n    apply (erule rtranclE)\n     apply fastforce\n    apply (case_tac y, clarsimp del: disjCI)\n    apply (rename_tac ref mptr)\n    apply (frule  wellformed_lookup.lookup1_is_append[OF wlcs])\n    apply (clarsimp del: disjCI)\n    apply (drule Suc.hyps(1))\n     apply (fastforce simp: Image_def)\n    apply clarsimp\n    apply (case_tac \"mptr = ptr\")\n     apply (elim disjE)\n      apply (rule_tac x = \"refa # sref\" in exI)\n      apply (rule disjI2)\n      apply (clarsimp simp: lookupable_refs_def lookup_refs_def)\n      apply (drule wellformed_lookup.lookup1_append_singleton[OF wlcs])\n      apply (clarsimp dest!:wellformed_lookup.trans_dependsD[OF wlcs])\n      apply ((rule exI | rule conjI | force)+)[1]\n     apply clarsimp\n     apply (clarsimp simp: lookupable_refs_def)\n     apply (intro disjI2 exI conjI | force)+\n      apply (drule wellformed_lookup.lookup1_append_singleton[OF wlcs])\n      apply (clarsimp dest!:wellformed_lookup.trans_dependsD[OF wlcs])\n      apply (fastforce simp: Image_def lookup_refs_def)\n    apply (clarsimp simp: Image_def)\n    apply (drule wellformed_lookup.lookup1_append_singleton[OF wlcs])\n    apply (clarsimp dest!:wellformed_lookup.trans_dependsD[OF wlcs])\n    apply (rule exI)\n    apply (elim disjE)\n     apply (rule disjI1)\n     apply (clarsimp simp: Image_def trans_depends_eq[symmetric])\n     apply ((intro conjI bexI\n              | simp add: obj_at_def\n              | erule lookup1_cut_singleton\n              | erule rtrancl_into_rtrancl)+)[1]\n    apply (rule disjI2)\n    apply (clarsimp simp: lookupable_refs_def Image_def trans_depends_eq[symmetric])\n    apply (intro conjI exI)\n      apply (rule_tac x = \"(aa,ba)\" in bexI)\n       apply simp+\n    apply (clarsimp simp: lookup_refs_def)\n    apply ((intro conjI exI bexI\n              | simp add: obj_at_def\n              | erule lookup1_cut_singleton\n              | erule rtrancl_into_rtrancl)+)[1]\n    done\n   qed\nend\n\nlemma lookup_bound_estimate:\n  assumes wlcs: \"wellformed_lookup cs kh f\"\n  and   wlcs': \"wellformed_lookup cs' kh' f\"\n  and bound: \"\\<And>p. lookup_refs (kh' p) f \\<subseteq> lookup_refs (kh p) f\"\n  shows \"(refs, p) \\<in> cs'^* `` rset \\<Longrightarrow> (refs, p) \\<in> cs^* `` rset\"\n  apply (clarsimp simp: Image_def)\n  apply (erule_tac x = \"(a,b)\" in bexI[rotated])\n  apply (induct refs arbitrary: p)\n   apply (erule rtranclE)\n   apply (clarsimp dest!: wellformed_lookup.lookup1_is_append[OF wlcs'])+\n  apply (erule rtranclE)\n   apply simp\n  apply (rule_tac b = y in rtrancl_into_rtrancl)\n   apply (clarsimp dest!: wellformed_lookup.lookup1_is_append[OF wlcs'])\n  apply (case_tac y,clarsimp)\n  apply (frule wellformed_lookup.lookup_ref_step[OF wlcs'])\n  apply clarsimp\n  apply (frule wellformed_lookup.lookup1_is_append[OF wlcs'])\n  apply clarsimp\n  apply (rule  wellformed_lookup.lookup1_cut[OF wlcs,where ra = \"[]\" and r = \"[a]\" for a,simplified])\n  apply (drule wellformed_lookup.lookup1_append[OF wlcs', where ra = \"[]\" and r = \"[a]\" for a, simplified])\n  apply (simp add: wellformed_lookup.trans_depends_eq[OF wlcs] wellformed_lookup.trans_depends_eq[OF wlcs'])\n  apply (insert bound)\n  apply (clarsimp simp: lookup_refs_def)\n  apply fastforce\n  done\n\nlemma trans_depends_vs_walk:\n  assumes wlcs: \"wellformed_lookup cs kh f\"\n    and   wlcs': \"wellformed_lookup cs' kh' f\"\n    and stick: \"\\<And>r q. (r, q) \\<in> lookup_walk cs m ref p \\<Longrightarrow> kh' q = kh q\"\n  shows \"lookup_walk cs m ref p \\<subseteq> lookup_walk cs' m ref p\"\n  apply (subgoal_tac \"\\<forall>r q. (r, q) \\<in> lookup_walk cs m ref p \\<longrightarrow> kh' q = kh q\")\n  prefer 2\n    apply (clarsimp simp: stick)\n  proof (induct ref arbitrary: p)\n  case Nil\n  show ?case\n    by (simp add: wellformed_lookup.empty_lookup_walk[OF wlcs]\n                  wellformed_lookup.empty_lookup_walk[OF wlcs'])\n  next\n  case Cons\n  show ?case\n    apply clarsimp\n    apply (frule wellformed_lookup.lookup_walk_stepD[OF wlcs])\n    apply (elim disjE)\n     apply clarsimp\n     apply (drule wellformed_lookup.lookup_walk_step_hdD[OF wlcs])\n     apply (erule disjE)\n      apply (fastforce simp: lookup_walk_def Image_def)\n     apply clarsimp\n     apply (rule wellformed_lookup.lookup_walk_stepI2[OF wlcs'])\n      apply (erule subsetD[OF Cons.hyps, rotated])\n      apply clarsimp\n      apply (drule(1) wellformed_lookup.lookup_walk_stepI1[OF wlcs])\n      apply (insert Cons.prems, fastforce)\n     apply (drule(1) wellformed_lookup.lookup_walk_stepI1[OF wlcs])\n     apply (clarsimp simp: wellformed_lookup.trans_depends_eq[OF wlcs] wellformed_lookup.trans_depends_eq[OF wlcs'])\n    apply (elim exE conjE)\n    apply (rule wellformed_lookup.lookup_walk_stepI1[OF wlcs'])\n     apply (erule subsetD[OF Cons.hyps,rotated])\n     apply clarsimp\n      apply (drule(1) wellformed_lookup.lookup_walk_stepI1[OF wlcs])\n      apply (insert Cons.prems, fastforce)\n    apply clarsimp\n    apply (drule_tac ptr = ptr in wellformed_lookup.lookup_walk_trivial[OF wlcs])\n    apply (drule(1) wellformed_lookup.lookup_walk_stepI1[OF wlcs])\n    apply (clarsimp simp: wellformed_lookup.trans_depends_eq[OF wlcs] wellformed_lookup.trans_depends_eq[OF wlcs'])\n    done\n  qed\n\n\nlocale wellformed_order_lookup = wellformed_lookup +\n  fixes ev :: \"'b\\<Rightarrow>nat\" and rset\n  assumes lookup1_increase: \"\\<And>p q r ref. \\<lbrakk>(ref,p) \\<in> cs^* `` rset; (([],p),[r],q) \\<in> cs \\<rbrakk> \\<Longrightarrow> ev (kh p) < ev (kh q)\"\n\ncontext wellformed_order_lookup\nbegin\nlemma lookup1_increaseD:\n  \"\\<lbrakk>(ref,p) \\<in> cs^* `` rset; (([],p),[r],q) \\<in> cs\\<rbrakk> \\<Longrightarrow> ev (kh p) < ev (kh q)\"\n  apply (insert lookup1_increase)\n  apply (fastforce)\n  done\n\nlemma lookup_walk_distinct_strong:\n  \"(ref, ptr) \\<in> lookup_walk cs rset (r @ ref) q \\<Longrightarrow> (ev (kh ptr)) < (ev (kh q)) \\<or> r = []\"\n  proof (induct \"length r\" arbitrary: ref ptr q r)\n  case 0\n  show ?case\n    apply (insert \"local.0\")\n    by clarsimp\n  next\n  case Suc\n  show ?case\n    apply (insert Suc.prems Suc.hyps(2))\n    apply (case_tac r, simp)\n    apply clarsimp\n    apply (drule lookup_walk_stepD)\n    apply (elim disjE, clarsimp)\n    apply clarsimp\n    apply (frule Suc.hyps(1)[rotated])\n     apply fastforce\n    apply (elim disjE)\n     apply (frule lookup_walk_imp_reachable)\n     apply (drule(1) lookup1_increaseD)\n     apply clarsimp\n    apply (frule lookup_walk_imp_reachable)\n    apply (drule(1) lookup1_increaseD)\n    apply (clarsimp dest!:lookup1_eq_ref)\n    done\n  qed\n\nlemma lookup1_trans_increase:\n  \"\\<lbrakk>(ref,p) \\<in> cs^* `` rset; ((a,p),b,q) \\<in> cs^+ \\<rbrakk> \\<Longrightarrow> ev (kh p) < ev (kh q)\"\n  apply (drule reachable_walk)\n  apply (frule lookup_ref_step[OF trancl_into_rtrancl])\n  apply clarsimp\n  apply (drule lookup_walk_stepsI1)\n   apply (rule lookup_trancl_append)\n   apply force\n  apply (drule lookup_walk_distinct_strong)\n  apply clarsimp\n  apply (erule tranclE)\n   apply (clarsimp dest!: lookup1_is_append lookup_ref_step trancl_into_rtrancl)+\n  done\n\nlemma lookup_walk_unique:\n  \"(ref', ptr) \\<in> lookup_walk cs rset ref ptr \\<Longrightarrow> ref = ref'\"\n  proof (induct \"length ref\" arbitrary: ref ptr ref')\n  case 0\n  show ?case\n    apply (insert \"local.0\")\n    by (clarsimp simp:empty_lookup_walk)\n  next\n  case Suc\n  show ?case\n    apply (insert Suc.prems Suc.hyps(2))\n    apply (case_tac ref)\n     apply simp\n    apply clarsimp\n    apply (drule lookup_walk_stepD)\n    apply (elim disjE, clarsimp)\n    apply clarsimp\n    apply (frule lookup_walk_distinct_strong)\n    apply (frule lookup_walk_imp_reachable)\n    apply (drule(1) lookup1_increaseD)\n    apply (clarsimp dest!: lookup1_eq_ref)\n    done\n  qed\n\nlemma lookup_walk_unique_from_root:\n  \"\\<lbrakk>(([], ptr), b, ptr) \\<in> cs^*; (ref,ptr) \\<in> cs^* `` rset\\<rbrakk> \\<Longrightarrow> b = []\"\n  apply (subgoal_tac \"b @ ref = ref\")\n   apply simp\n  apply (rule lookup_walk_unique)\n  apply (simp add: lookup_walk_def)\n  done\n\nlemma  lookup_walk_kh_upd:\n  \"\\<lbrakk>wellformed_order_lookup cs' (kh(ptr := obj)) f ev rset; (q, ptr) \\<in> lookup_walk cs rset q ptr \\<rbrakk>\n    \\<Longrightarrow> (q, ptr) \\<in> lookup_walk cs' rset q ptr\"\n  apply (case_tac q)\n   apply (clarsimp simp: empty_lookup_walk)\n   apply (fastforce simp: lookup_walk_def Image_def)\n  apply clarsimp\n  apply (frule lookup_walk_step_hdD)\n   apply (elim disjE)\n   apply (fastforce simp: lookup_walk_def Image_def)\n  apply (clarsimp simp: Image_def)\n  apply (cut_tac m = rset and ref = list and p = y\n          in trans_depends_vs_walk[OF local.wellformed_lookup_axioms])\n    apply (erule wellformed_order_lookup.axioms)\n   apply clarsimp\n   apply (drule_tac p = \"(r, ptr)\" in lookup_walk_stepI1[rotated])\n    apply simp\n   apply (clarsimp dest!: lookup_walk_unique)\n   apply (drule lookup_walk_decomp)\n   apply simp\n  apply (rule wellformed_lookup.lookup_walk_stepI2)\n    apply (erule wellformed_order_lookup.axioms)\n   apply fastforce\n  apply (subst wellformed_lookup.trans_depends_eq)\n   apply (erule wellformed_order_lookup.axioms)\n  apply (subgoal_tac \"y \\<noteq> ptr\")\n   apply (simp add: trans_depends_eq)\n  apply clarsimp\n   apply (drule_tac p = \"(list, ptr)\" in lookup_walk_stepI1[rotated])\n   apply simp\n  apply (clarsimp dest!: lookup_walk_unique)\n  done\n\nlemma lookup_walk_path_distinct:\n  \"h \\<noteq> [] \\<Longrightarrow> (q, ptr) \\<in> lookup_walk cs rset (h @ q) rptr \\<Longrightarrow> ptr \\<noteq> rptr\"\n  apply (rule ccontr)\n  apply clarsimp\n  apply (drule lookup_walk_unique)\n  apply simp\n  done\n\n(*\n   This lemma should not be used out side of this locale.\n   Please use kpupd_wellformed_order_lookup instead.\n*)\nlemma khupd_wellform_order_lookup_pref:\n  assumes wlos: \"wellformed_order_lookup cs' (kh(ptr := obj)) f ev rset\"\n  shows \"cs'^* `` rset \\<subseteq> cs^* `` rset \\<union> lookupable_refs cs\n      {ref. (ref, ptr) \\<in> cs^* `` rset} (lookup_refs obj f)\"\n  proof -\n  have wlcs: \"wellformed_lookup cs' (kh(ptr := obj)) f\"\n   by (intro wellformed_order_lookup.axioms[OF wlos])\n  have kh_upd_dummy[simp]:\n     \"(kh(ptr := obj, ptr := kh ptr)) = kh\"\n  by auto\n  have l: \"\\<And>ys y q.  ys @ y # q = (ys @ [y]) @ q\"\n  by auto\n  show ?thesis\n  apply (rule subsetI)\n  apply (clarsimp del: disjCI)\n  apply (rename_tac r rptr ref p)\n  apply (erule rtranclE)\n   apply (fastforce simp: wellformed_lookup.empty_lookup_walk[OF wlcs] Image_def)\n  apply (insert wlcs)\n  apply (drule wellformed_lookup.reachable_walk)\n   apply (simp add: Image_def)\n   apply fastforce\n  apply (case_tac \"\\<exists>q. (q, ptr) \\<in> lookup_walk cs' rset r rptr\")\n   apply (clarsimp del: disjCI)\n   apply (frule_tac ptr = ptr in wellformed_lookup.lookup_walk_reduce[OF wlcs])\n   apply (drule_tac obj = \"kh ptr\" and ptr = ptr and cs' = cs in wellformed_order_lookup.lookup_walk_kh_upd[rotated -1,OF _ wlos])\n    apply simp\n    apply (rule wellformed_order_lookup_axioms)\n   apply (frule_tac rptr = rptr in wellformed_lookup.lookup_walk_decomp[OF wlcs])\n   apply (clarsimp del: disjCI)\n   apply (rule_tac xs = h in rev_cases)\n    apply (clarsimp simp: wellformed_lookup.empty_lookup_walk[OF wlcs])\n    apply (simp add: lookup_walk_def)\n   apply (rule disjI2)\n   apply clarsimp\n   apply (drule wellformed_lookup.lookup_walk_decomp_more[OF wlcs])\n   apply clarsimp\n   apply (drule wellformed_lookup.lookup_trancl_walk[OF wlcs])\n   apply (drule_tac ref = q in wellformed_lookup.lookup_walk_reduce[OF wlcs])\n   apply (drule_tac c=\"(ys, rptr)\" in subsetD[OF trans_depends_vs_walk,rotated -1])\n      apply (rule wlcs)\n     apply (rule local.wellformed_lookup_axioms)\n    apply clarsimp\n    apply (drule_tac ref = r in wellformed_lookup.lookup_walk_reduce[OF wlcs])\n    apply (frule_tac ptr = ptr in wellformed_order_lookup.lookup_walk_unique_from_root\n                 [OF wlos _ wellformed_lookup.lookup_walk_imp_reachable[OF wlcs],rotated])\n     apply (erule converse_rtrancl_into_rtrancl)\n     apply (drule wellformed_lookup.lookup_walk_imp_reachable[OF wlcs])+\n     apply (clarsimp simp: Image_def)\n     apply (rule wellformed_lookup.lookup_trancl_cut[OF wlcs, where ra = \"[]\",simplified])\n     apply simp\n    apply simp\n   apply (subst l)\n   apply (rule in_lookupable_refsI)\n     apply (clarsimp dest!: lookup_walk_imp_reachable)\n    apply (drule wellformed_lookup.trans_dependsD[OF wlcs])\n    apply simp\n   apply (rule lookup_trancl_cut[where ra =\"[]\",simplified])\n   apply (clarsimp dest!: lookup_walk_imp_reachable)\n   apply simp\n  apply (cut_tac m = rset and ref=r and p = rptr\n          in trans_depends_vs_walk[OF wlcs local.wellformed_lookup_axioms])\n   apply clarsimp\n  apply (drule subsetD)\n   apply (rule wellformed_lookup.reachable_walk[OF wlcs])\n   apply (clarsimp simp: Image_def)\n   apply (erule bexI[rotated])\n   apply (erule(1) rtrancl_into_rtrancl)\n  apply (simp add: lookup_walk_imp_reachable)\n  done\n  qed\n\nlemma lookupable_refs_reachable:\n  \"lookupable_refs cs {ref. (ref, ptr) \\<in> cs\\<^sup>* `` rset} (lookup_refs (kh ptr) f)\n   \\<subseteq> cs\\<^sup>* `` rset\"\n   apply (clarsimp simp: lookupable_refs_def Image_def lookup_refs_lookup1)\n   apply (erule bexI[rotated])\n   apply (erule rtrancl_trans)\n   apply (frule lookup1_is_append)\n   apply clarsimp\n   apply (erule converse_rtrancl_into_rtrancl[OF lookup1_cut_singleton])\n   apply (drule lookup_trancl_cut)\n   apply force\n   done\n\nlemma khupd_wellformed_order_lookup_private:\n  assumes well_order:\n    \"\\<And>nref np stepref nq sref. \\<lbrakk>(nref,np) \\<in> cs^* `` (lookup_refs obj f); (([],np),[stepref],nq) \\<in> cs; (sref, ptr)\\<in> cs^* `` rset\\<rbrakk>\n    \\<Longrightarrow> ev (kh np) < ev (kh nq)\"\n  and well_order_as_parent:\n    \"\\<And>nref np sref. \\<lbrakk>(nref,np) \\<in> lookup_refs obj f; (sref, ptr)\\<in> cs^* `` rset\\<rbrakk> \\<Longrightarrow> ev (obj) < ev (kh np)\"\n  and well_order_as_leaf:\n    \"\\<And>p r sref. \\<lbrakk>((r, p), sref, ptr) \\<in> cs^+ ;(r, p) \\<in> cs^* `` rset\\<rbrakk> \\<Longrightarrow> ev (kh p) < ev (obj)\"\n  and wlcs: \"wellformed_lookup cs' (kh(ptr := obj)) f\"\n  shows \"ev (kh ptr) \\<le> ev obj \\<Longrightarrow> wellformed_order_lookup cs' (kh(ptr := obj)) f ev rset\"\n  apply (intro wellformed_order_lookup.intro[OF wlcs])\n  apply (intro wellformed_order_lookup_axioms.intro)\n  apply (drule khupd_graph_subset[OF wlcs])\n  apply (clarsimp simp: wellformed_lookup.trans_depends_eq[OF wlcs])\n  apply (elim disjE)\n   apply (clarsimp split: if_splits)\n    apply (cut_tac nref = \"[r]\" and np = q in well_order_as_parent)\n      apply (clarsimp simp: Image_def lookup_refs_def)\n     apply (fastforce simp: Image_def)\n    apply clarsimp\n   apply (clarsimp simp: trans_depends_eq[symmetric])\n   apply (intro conjI impI)\n    apply (rule well_order_as_leaf[rotated])\n     apply (fastforce simp: Image_def)\n    apply (rule r_into_trancl')\n    apply (rule lookup1_cut_singleton)\n    apply force\n   apply (rule lookup1_increase)\n    apply (clarsimp simp: Image_def)\n    apply (erule bexI[rotated])\n    apply simp\n   apply simp\n  apply (clarsimp simp: lookupable_refs_def split: if_splits)\n   apply (cut_tac nref = \"[r]\" and np = q in well_order_as_parent)\n     apply (clarsimp simp: Image_def lookup_refs_def)\n    apply (fastforce simp: Image_def)\n   apply clarsimp\n  apply (clarsimp simp: trans_depends_eq[symmetric])\n  apply (intro conjI impI)\n   apply clarsimp\n   apply (frule well_order_as_parent)\n    apply fastforce\n   apply (drule well_order[rotated])\n     apply fastforce+\n  apply (frule well_order[rotated])\n    apply (fastforce)+\n  done\n\nlemma khupd_wellformed_order_lookup:\n  assumes well_order:\n    \"\\<And>nref np stepref nq sref. \\<lbrakk>(nref,np) \\<in> cs^* `` (lookup_refs obj f - lookup_refs (kh ptr) f); (([],np),[stepref],nq) \\<in> cs; (sref, ptr)\\<in> cs^* `` rset\\<rbrakk>\n    \\<Longrightarrow> ev (kh np) < ev (kh nq)\"\n  and well_order_as_parent:\n    \"\\<And>nref np sref. \\<lbrakk>(nref,np) \\<in> (lookup_refs obj f - lookup_refs (kh ptr) f); (sref, ptr)\\<in> cs^* `` rset\\<rbrakk> \\<Longrightarrow> ev (obj) < ev (kh np)\"\n  and well_order_as_leaf:\n    \"\\<And>p r sref. \\<lbrakk>((r, p), sref, ptr) \\<in> cs^+ ;(r, p) \\<in> cs^* `` rset\\<rbrakk> \\<Longrightarrow> ev (kh p) < ev (obj)\"\n  and wlcs: \"wellformed_lookup cs' (kh(ptr := obj)) f\"\n  shows \"ev (kh ptr) = ev obj \\<Longrightarrow> wellformed_order_lookup cs' (kh(ptr := obj)) f ev rset\"\n  apply (rule khupd_wellformed_order_lookup_private[OF _ _ well_order_as_leaf wlcs])\n       apply clarsimp\n       apply (case_tac \"(a,b) \\<in> lookup_refs (kh ptr) f\")\n        apply (rule lookup1_increaseD)\n         apply (clarsimp simp: Image_def)\n         apply (erule bexI[rotated])\n         apply (erule rtrancl_trans)\n         apply (rule converse_rtrancl_into_rtrancl)\n          apply (simp add: lookup_refs_lookup1)\n          apply (drule_tac b = sref in lookup1_cut[where q = ptr])\n          apply fastforce\n         apply (erule lookup_trancl_cut)\n        apply simp\n       apply (rule well_order, fastforce+)\n     apply clarsimp\n     apply (case_tac \"(nref,np) \\<in> lookup_refs (kh ptr) f\")\n      apply (clarsimp simp: Image_def lookup_refs_lookup1)\n      apply (frule lookup1_is_append)\n      apply clarsimp\n      apply (erule subst)\n       apply (rule lookup1_trans_increase)\n       apply (clarsimp simp: Image_def)\n       apply (erule bexI[rotated])\n        apply (simp add: lookup_refs_lookup1)+\n       apply fastforce\n      apply (rule well_order_as_parent,fastforce+)\n   done\n\n(* The main result for this locale *)\ntheorem khupd_graph_subset:\n  assumes wlos: \"wellformed_order_lookup cs' (kh(ptr := obj)) f ev rset\"\n  shows \"cs'^* `` rset \\<subseteq> cs^* `` rset \\<union> lookupable_refs cs\n      {ref. (ref, ptr) \\<in> cs^* `` rset} (lookup_refs obj f - lookup_refs (kh ptr) f)\"\n  proof -\n  have set_plus_mono: \"\\<And>a b c d. \\<lbrakk>a \\<subseteq> b \\<union> c; c \\<subseteq> d\\<rbrakk> \\<Longrightarrow> a \\<subseteq> b \\<union> d\"\n    by auto\n  show ?thesis\n    apply (insert khupd_wellform_order_lookup_pref[OF wlos])\n    apply (drule set_plus_mono)\n     apply (rule_tac b = \"kh ptr\" in lookupable_refs_set)\n    apply (cut_tac ptr = ptr in lookupable_refs_reachable)\n    apply fastforce\n    done\n  qed\nend\n\ncontext Arch begin global_naming X64\n\nlocale_abbrev \"vs_lookup_leaf ptr s \\<equiv> lookup_leaf ptr (vs_lookup1 s)\"\n\nprimrec vsref_of :: \"vs_ref \\<Rightarrow> word64\"\nwhere\n  \"vsref_of (VSRef x _ ) = x\"\n\ndefinition\n  vs_ref_lvl_arch :: \"arch_kernel_obj \\<Rightarrow> nat\"\nwhere\n  \"vs_ref_lvl_arch atype \\<equiv> case aa_type atype of\n      AASIDPool \\<Rightarrow> 1\n    | APageMapL4 \\<Rightarrow> 2\n    | APDPointerTable \\<Rightarrow> 3\n    | APageDirectory \\<Rightarrow> 4\n    | APageTable \\<Rightarrow> 5\n    | _ \\<Rightarrow> 6\"\n\ndefinition\n  \"vs_ref_lvl obj_opt \\<equiv> case_option 7 (arch_obj_fun_lift vs_ref_lvl_arch 7) obj_opt\"\n\nlemma vs_ref_lvl_arch_obj [simp]:\n  \"vs_ref_lvl (Some (ArchObj aobj)) = vs_ref_lvl_arch aobj\"\n  by (simp add: vs_ref_lvl_def)\n\nlemma vs_ref_lvl_arch_simps [simp]:\n  \"vs_ref_lvl_arch (ASIDPool ap) = 1\"\n  \"vs_ref_lvl_arch (PageMapL4 pm) = 2\"\n  \"vs_ref_lvl_arch (PDPointerTable pdpt) = 3\"\n  \"vs_ref_lvl_arch (PageDirectory pd) = 4\"\n  \"vs_ref_lvl_arch (PageTable pt) = 5\"\n  \"vs_ref_lvl_arch (DataPage dev sz) = 6\"\n  by (auto simp: vs_ref_lvl_arch_def aa_type_def)\n\ndefinition\n  \"vs_lookup1_on_heap_obj \\<equiv> \\<lambda>obj q h. (\\<exists>ko. obj = Some ko \\<and> (\\<exists>r. h = [r] \\<and> (r, q) \\<in> vs_refs ko))\"\n\ndefinition\n  \"vs_lookup_pages1_on_heap_obj \\<equiv> \\<lambda>obj q h. (\\<exists>ko. obj = Some ko \\<and> (\\<exists>r. h = [r] \\<and> (r, q) \\<in> vs_refs_pages ko))\"\n\nsublocale vs_lookup1_wellformed:\n  wellformed_lookup \"vs_lookup1 s\" \"kheap s\" vs_lookup1_on_heap_obj\n  apply unfold_locales\n       apply (clarsimp simp: trans_depends_def vs_lookup1_def obj_at_def vs_lookup1_on_heap_obj_def)+\n   apply (clarsimp simp: vs_refs_def up_ucast_inj_eq graph_of_def\n                  split: kernel_object.splits arch_kernel_obj.splits)\n  apply (clarsimp simp: vs_lookup1_on_heap_obj_def)\n  done\n\nlemmas vs_lookup1_is_wellformed_lookup\n  = vs_lookup1_wellformed.wellformed_lookup_axioms\n\nsublocale vs_lookup_pages1_wellformed:\n  wellformed_lookup \"vs_lookup_pages1 s\" \"kheap s\" vs_lookup_pages1_on_heap_obj\n  apply unfold_locales\n       apply (clarsimp simp: trans_depends_def vs_lookup_pages1_def obj_at_def vs_lookup_pages1_on_heap_obj_def)+\n   apply (clarsimp simp: vs_refs_pages_def up_ucast_inj_eq graph_of_def\n                  split: kernel_object.splits arch_kernel_obj.splits)\n  apply (clarsimp simp: vs_lookup_pages1_on_heap_obj_def)\n  done\n\nlemmas vs_lookup_pages1_is_wellformed_lookup\n  = vs_lookup_pages1_wellformed.wellformed_lookup_axioms\n\nlemma vs_refs_pages_vs_ref_lvl:\n  \"\\<lbrakk> ko_at (ArchObj aobj) p s; (r, q) \\<in> vs_refs_pages (ArchObj aobj); valid_vspace_obj aobj s \\<rbrakk>\n     \\<Longrightarrow> vs_ref_lvl (kheap s p) < vs_ref_lvl (kheap s q)\"\n  apply (cases aobj;\n         clarsimp simp: vs_refs_pages_def graph_of_def ball_ran_eq obj_at_def\n                        pte_ref_pages_def pde_ref_pages_def pdpte_ref_pages_def pml4e_ref_pages_def\n                 split: if_splits pte.splits pde.splits pdpte.splits pml4e.splits;\n         match premises in H [thin]: \"\\<forall>i. P (t i)\" and J: \"t i = v\" for P t i v \\<Rightarrow>\n                              \\<open>insert spec[where x=i, OF H]\\<close>\n                         \\<bar> H [thin]: \"\\<forall>i \\<in> S. P (t i)\" and J: \"t i = v\" for P S t i v \\<Rightarrow>\n                              \\<open>insert bspec[where x=i, OF H]\\<close>)\n  by (auto simp: obj_at_def data_at_def)\n\nlemmas vs_refs_vs_ref_lvl = vs_refs_pages_vs_ref_lvl[OF _ vs_refs_vs_refs_pages]\n\nlemma vs_lookup1_wellformed_order:\n  \"valid_vspace_objs s\n    \\<Longrightarrow> wellformed_order_lookup (vs_lookup1 s) (kheap s) vs_lookup1_on_heap_obj\n                                vs_ref_lvl (vs_asid_refs (x64_asid_table (arch_state s)))\"\n  apply (intro wellformed_order_lookup.intro vs_lookup1_wellformed.wellformed_lookup_axioms\n               wellformed_order_lookup_axioms.intro)\n  apply (simp only: vs_lookup_def2[symmetric])\n  apply (clarsimp simp add: vs_lookup1_def)\n  apply (case_tac ko; (clarsimp simp: vs_refs_def; fail)?; rename_tac ako; clarsimp)\n  apply (frule (2) valid_vspace_objsD)\n  apply (case_tac ako; clarsimp simp: vs_refs_def)\n     apply (drule (1) graph_of_in_ranD; clarsimp simp: obj_at_def)\n    apply (match premises in \"(i,_) \\<in> graph_of _\" for i \\<Rightarrow>\n            \\<open>match premises in H[thin]: \"\\<forall>i. P i\" for P \\<Rightarrow> \\<open>insert spec[where x=i, OF H]\\<close>\n                             \\<bar> H[thin]: \"\\<forall>i\\<in>_. P i\" for P \\<Rightarrow> \\<open>insert bspec[where x=i, OF H]\\<close>\\<close>;\n           fastforce simp: graph_of_def obj_at_def\n                           pde_ref_def pdpte_ref_def pml4e_ref_def\n                    split: pde.splits pdpte.splits pml4e.splits if_splits)+\n  done\n\nlemma vs_lookup_pages1_wellformed_order:\n  \"\\<lbrakk> valid_vspace_objs s; valid_asid_table (x64_asid_table (arch_state s)) s \\<rbrakk>\n    \\<Longrightarrow> wellformed_order_lookup (vs_lookup_pages1 s) (kheap s) vs_lookup_pages1_on_heap_obj\n                                vs_ref_lvl (vs_asid_refs (x64_asid_table (arch_state s)))\"\n  apply (intro wellformed_order_lookup.intro vs_lookup_pages1_wellformed.wellformed_lookup_axioms\n               wellformed_order_lookup_axioms.intro)\n  apply (simp only: vs_lookup_pages_def2[symmetric])\n  apply (clarsimp simp add: vs_lookup_pages1_def)\n  apply (case_tac ko; (clarsimp simp: vs_refs_pages_def; fail)?; rename_tac ako; clarsimp)\n  apply (frule (3) valid_vspace_objsD')\n  apply (case_tac ako; clarsimp simp: vs_refs_pages_def)\n      apply (drule (1) graph_of_in_ranD; clarsimp simp: obj_at_def)\n     apply (match premises in \"(x,y) \\<in> graph_of f\" for f x y \\<Rightarrow>\n             \\<open>match premises in H[thin]: \"\\<forall>i. P i\" for P \\<Rightarrow> \\<open>insert spec[where x=x, OF H]\\<close>\n                              \\<bar> H[thin]: \"\\<forall>i\\<in>_. P i\" for P \\<Rightarrow> \\<open>insert bspec[where x=x, OF H]\\<close>\\<close>;\n            fastforce simp: graph_of_def obj_at_def data_at_def\n                            pte_ref_pages_def pde_ref_pages_def pdpte_ref_pages_def pml4e_ref_pages_def\n                     split: pte.splits pde.splits pdpte.splits pml4e.splits if_splits)+\n  done\n\ndefinition\n  refs_diff :: \"(kernel_object option \\<Rightarrow> 'b \\<Rightarrow> 'a list \\<Rightarrow> bool)\n                  \\<Rightarrow> arch_kernel_obj \\<Rightarrow> 64 word \\<Rightarrow> 'c abstract_state_scheme \\<Rightarrow> ('a list \\<times> 'b) set\"\nwhere\n  \"refs_diff lf obj ptr s = (lookup_refs (Some (ArchObj obj)) lf - lookup_refs (kheap s ptr) lf)\"\n\nend\n\nend\n", "meta": {"author": "NICTA", "repo": "l4v", "sha": "3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b", "save_path": "github-repos/isabelle/NICTA-l4v", "path": "github-repos/isabelle/NICTA-l4v/l4v-3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b/proof/invariant-abstract/X64/ArchVSpaceLookup_AI.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5428632831725053, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.28414568910287125}}
{"text": "(*  Title:      HOL/Proofs/ex/XML_Data.thy\n    Author:     Makarius\n    Author:     Stefan Berghofer\n\nXML data representation of proof terms.\n*)\n\ntheory XML_Data\nimports \"~~/src/HOL/Isar_Examples/Drinker\"\nbegin\n\nsubsection \\<open>Export and re-import of global proof terms\\<close>\n\nML \\<open>\n  fun export_proof ctxt thm =\n    let\n      val thy = Proof_Context.theory_of ctxt;\n      val (_, prop) =\n        Logic.unconstrainT (Thm.shyps_of thm)\n          (Logic.list_implies (Thm.hyps_of thm, Thm.prop_of thm));\n      val prf =\n        Proofterm.proof_of (Proofterm.strip_thm (Thm.proof_body_of thm)) |>\n        Reconstruct.reconstruct_proof ctxt prop |>\n        Reconstruct.expand_proof ctxt [(\"\", NONE)] |>\n        Proofterm.rew_proof thy |>\n        Proofterm.no_thm_proofs;\n    in Proofterm.encode prf end;\n\n  fun import_proof thy xml =\n    let\n      val prf = Proofterm.decode xml;\n      val (prf', _) = Proofterm.freeze_thaw_prf prf;\n    in Drule.export_without_context (Proof_Checker.thm_of_proof thy prf') end;\n\\<close>\n\n\nsubsection \\<open>Examples\\<close>\n\nML \\<open>val thy1 = @{theory}\\<close>\n\nlemma ex: \"A \\<longrightarrow> A\" ..\n\nML_val \\<open>\n  val xml = export_proof @{context} @{thm ex};\n  val thm = import_proof thy1 xml;\n\\<close>\n\nML_val \\<open>\n  val xml = export_proof @{context} @{thm de_Morgan};\n  val thm = import_proof thy1 xml;\n\\<close>\n\nML_val \\<open>\n  val xml = export_proof @{context} @{thm Drinker's_Principle};\n  val thm = import_proof thy1 xml;\n\\<close>\n\ntext \\<open>Some fairly large proof:\\<close>\n\nML_val \\<open>\n  val xml = export_proof @{context} @{thm abs_less_iff};\n  val thm = import_proof thy1 xml;\n  @{assert} (size (YXML.string_of_body xml) > 1000000);\n\\<close>\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/HOL/Proofs/ex/XML_Data.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.523420348936324, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.2841456891028712}}
{"text": "(*  Title:       Jive Data and Store Model\n    Author:      Norbert Schirmer <schirmer at informatik.tu-muenchen.de>  and  \n                 Nicole Rauch <rauch at informatik.uni-kl.de>, 2003\n    Maintainer:  Nicole Rauch <rauch at informatik.uni-kl.de>\n    License:     LGPL\n*)\n \nsection \\<open>Value\\<close>\n\ntheory Value imports Subtype begin\n\ntext \\<open>This theory contains our model of the values in the store. The store is untyped, therefore all\n  types that exist in Java are wrapped into one type \\<open>Value\\<close>.\n\n  In a first approach, the primitive Java types supported in this formalization are \n  mapped to similar Isabelle\n  types. Later, we will have\n  proper formalizations of the Java types in Isabelle, which will then be used here.\n\\<close>\n  \ntype_synonym JavaInt = int\ntype_synonym JavaShort = int\ntype_synonym JavaByte = int\ntype_synonym JavaBoolean = bool\n\ntext \\<open>The objects of each class are identified by a unique ID.\nWe use elements of type @{typ nat} here, but in general it is sufficient to use\nan infinite type with a successor function and a comparison predicate.\n\\<close>\n\ntype_synonym ObjectId = nat\n\ntext \\<open>The definition of the datatype \\<open>Value\\<close>. Values can be of the Java types \nboolean, int, short and byte. Additionally, they can be an object reference,\nan array reference or the value null.\\<close>\n\ndatatype Value = boolV  JavaBoolean\n               | intgV  JavaInt  \n               | shortV JavaShort\n               | byteV  JavaByte\n               | objV   CTypeId ObjectId   \\<comment> \\<open>typed object reference\\<close>\n               | arrV   Arraytype ObjectId \\<comment> \\<open>typed array reference\\<close>\n               | nullV\n               \n\ntext \\<open>Arrays are modeled as references just like objects. So they\ncan be viewed as special kinds of objects, like in Java.\\<close>\n\nsubsection \\<open>Discriminator Functions\\<close>\n\ntext \\<open>To test values, we define the following discriminator functions.\\<close>\n\ndefinition isBoolV  :: \"Value \\<Rightarrow> bool\" where\n\"isBoolV v = (case v of\n               boolV b  \\<Rightarrow> True \n             | intgV i  \\<Rightarrow> False\n             | shortV s \\<Rightarrow> False\n             | byteV  by \\<Rightarrow> False\n             | objV C a \\<Rightarrow> False\n             | arrV T a \\<Rightarrow> False\n             | nullV    \\<Rightarrow> False)\"\n\nlemma isBoolV_simps [simp]:\n\"isBoolV (boolV b)       = True\" \n\"isBoolV (intgV i)       = False\"\n\"isBoolV (shortV s)      = False\"\n\"isBoolV (byteV by)       = False\"\n\"isBoolV (objV C a)      = False\"\n\"isBoolV (arrV T a)      = False\"\n\"isBoolV (nullV)         = False\"\n  by (simp_all add: isBoolV_def)\n\n\ndefinition isIntgV  :: \"Value \\<Rightarrow> bool\" where\n\"isIntgV v = (case v of\n               boolV b  \\<Rightarrow> False \n             | intgV i  \\<Rightarrow> True\n             | shortV s \\<Rightarrow> False\n             | byteV by  \\<Rightarrow> False\n             | objV C a \\<Rightarrow> False\n             | arrV T a \\<Rightarrow> False\n             | nullV    \\<Rightarrow> False)\" \n\nlemma isIntgV_simps [simp]:\n\"isIntgV (boolV b)       = False\" \n\"isIntgV (intgV i)       = True\"\n\"isIntgV (shortV s)       = False\"\n\"isIntgV (byteV by)       = False\"\n\"isIntgV (objV C a)      = False\"\n\"isIntgV (arrV T a)      = False\"\n\"isIntgV (nullV)         = False\"\n  by (simp_all add: isIntgV_def)\n\n\ndefinition isShortV :: \"Value \\<Rightarrow> bool\" where\n\"isShortV v = (case v of\n               boolV b  \\<Rightarrow> False \n             | intgV i  \\<Rightarrow> False\n             | shortV s \\<Rightarrow> True\n             | byteV by  \\<Rightarrow> False\n             | objV C a \\<Rightarrow> False\n             | arrV T a \\<Rightarrow> False\n             | nullV    \\<Rightarrow> False)\" \n\nlemma isShortV_simps [simp]:\n\"isShortV (boolV b)     = False\" \n\"isShortV (intgV i)     = False\"\n\"isShortV (shortV s)    = True\"\n\"isShortV (byteV by)     = False\"\n\"isShortV (objV C a)    = False\"\n\"isShortV (arrV T a)    = False\"\n\"isShortV (nullV)       = False\"\n  by (simp_all add: isShortV_def)\n\n\ndefinition isByteV :: \"Value \\<Rightarrow> bool\" where\n\"isByteV v = (case v of\n               boolV b  \\<Rightarrow> False \n             | intgV i  \\<Rightarrow> False\n             | shortV s \\<Rightarrow> False\n             | byteV by  \\<Rightarrow> True\n             | objV C a \\<Rightarrow> False\n             | arrV T a \\<Rightarrow> False\n             | nullV    \\<Rightarrow> False)\" \n\n\n\n\ndefinition isRefV :: \"Value \\<Rightarrow> bool\" where\n\"isRefV v = (case v of\n               boolV b  \\<Rightarrow> False \n             | intgV i  \\<Rightarrow> False\n             | shortV s \\<Rightarrow> False\n             | byteV by \\<Rightarrow> False\n             | objV C a  \\<Rightarrow> True\n             | arrV T a  \\<Rightarrow> True\n             | nullV     \\<Rightarrow> True)\"\n\nlemma isRefV_simps [simp]:\n\"isRefV (boolV b)       = False\" \n\"isRefV (intgV i)       = False\"\n\"isRefV (shortV s)      = False\"\n\"isRefV (byteV by)      = False\"\n\"isRefV (objV C a)      = True\"\n\"isRefV (arrV T a)      = True\"\n\"isRefV (nullV)         = True\"\n  by (simp_all add: isRefV_def)\n\n\ndefinition isObjV :: \"Value \\<Rightarrow> bool\" where\n\"isObjV v = (case v of\n               boolV b  \\<Rightarrow> False \n             | intgV i  \\<Rightarrow> False\n             | shortV s  \\<Rightarrow> False\n             | byteV by  \\<Rightarrow> False\n             | objV C a \\<Rightarrow> True\n             | arrV T a \\<Rightarrow> False\n             | nullV    \\<Rightarrow> False)\"\n\nlemma isObjV_simps [simp]:\n\"isObjV (boolV b)  = False\" \n\"isObjV (intgV i)  = False\"\n\"isObjV (shortV s)  = False\"\n\"isObjV (byteV by)  = False\"\n\"isObjV (objV c a) = True\" \n\"isObjV (arrV T a) = False\"\n\"isObjV nullV      = False\"\n  by (simp_all add: isObjV_def)\n\n\ndefinition isArrV :: \"Value \\<Rightarrow> bool\" where\n\"isArrV v = (case v of\n               boolV b  \\<Rightarrow> False \n             | intgV i  \\<Rightarrow> False\n             | shortV s  \\<Rightarrow> False\n             | byteV by  \\<Rightarrow> False\n             | objV C a \\<Rightarrow> False\n             | arrV T a \\<Rightarrow> True\n             | nullV    \\<Rightarrow> False)\"\n\nlemma isArrV_simps [simp]:\n\"isArrV (boolV b)  = False\" \n\"isArrV (intgV i)  = False\"\n\"isArrV (shortV s)  = False\"\n\"isArrV (byteV by)  = False\"\n\"isArrV (objV c a) = False\" \n\"isArrV (arrV T a) = True\"\n\"isArrV nullV      = False\"\n  by (simp_all add: isArrV_def)\n\n\ndefinition isNullV  :: \"Value \\<Rightarrow> bool\" where\n\"isNullV v = (case v of\n               boolV b  \\<Rightarrow> False \n             | intgV i  \\<Rightarrow> False\n             | shortV s  \\<Rightarrow> False\n             | byteV by  \\<Rightarrow> False\n             | objV C a \\<Rightarrow> False\n             | arrV T a \\<Rightarrow> False\n             | nullV    \\<Rightarrow> True)\"\n\nlemma isNullV_simps [simp]:\n\"isNullV (boolV b)   = False\" \n\"isNullV (intgV i)   = False\"\n\"isNullV (shortV s)   = False\"\n\"isNullV (byteV by)   = False\"\n\"isNullV (objV c a) = False\" \n\"isNullV (arrV T a) = False\"\n\"isNullV nullV      = True\"\n  by (simp_all add: isNullV_def)\n\nsubsection \\<open>Selector Functions\\<close>\n\ndefinition aI :: \"Value \\<Rightarrow> JavaInt\" where\n\"aI v = (case v of  \n            boolV  b   \\<Rightarrow> undefined\n          | intgV  i   \\<Rightarrow> i\n          | shortV sh  \\<Rightarrow> undefined\n          | byteV  by  \\<Rightarrow> undefined\n          | objV   C a \\<Rightarrow> undefined\n          | arrV  T a  \\<Rightarrow> undefined\n          | nullV      \\<Rightarrow> undefined)\"\nlemma aI_simps [simp]:\n\"aI (intgV i) = i\"\nby (simp add: aI_def)\n\n\ndefinition aB :: \"Value \\<Rightarrow> JavaBoolean\" where\n\"aB v = (case v of  \n            boolV  b   \\<Rightarrow> b\n          | intgV  i   \\<Rightarrow> undefined\n          | shortV sh  \\<Rightarrow> undefined\n          | byteV  by  \\<Rightarrow> undefined\n          | objV   C a \\<Rightarrow> undefined\n          | arrV  T a  \\<Rightarrow> undefined\n          | nullV      \\<Rightarrow> undefined)\"\nlemma aB_simps [simp]:\n\"aB (boolV b) = b\"\nby (simp add: aB_def)\n\n\ndefinition aSh :: \"Value \\<Rightarrow> JavaShort\" where\n\"aSh v = (case v of  \n            boolV  b   \\<Rightarrow> undefined\n          | intgV  i   \\<Rightarrow> undefined\n          | shortV sh  \\<Rightarrow> sh\n          | byteV  by  \\<Rightarrow> undefined\n          | objV   C a \\<Rightarrow> undefined\n          | arrV  T a  \\<Rightarrow> undefined\n          | nullV      \\<Rightarrow> undefined)\"\nlemma aSh_simps [simp]:\n\"aSh (shortV sh) = sh\"\nby (simp add: aSh_def)\n\n\ndefinition aBy :: \"Value \\<Rightarrow> JavaByte\" where\n\"aBy v = (case v of  \n            boolV  b   \\<Rightarrow> undefined\n          | intgV  i   \\<Rightarrow> undefined\n          | shortV s   \\<Rightarrow> undefined\n          | byteV  by  \\<Rightarrow> by\n          | objV   C a \\<Rightarrow> undefined\n          | arrV  T a  \\<Rightarrow> undefined\n          | nullV      \\<Rightarrow> undefined)\"\nlemma aBy_simps [simp]:\n\"aBy (byteV by) = by\"\nby (simp add: aBy_def)\n\n\ndefinition tid :: \"Value \\<Rightarrow> CTypeId\" where\n\"tid v = (case v of\n            boolV  b   \\<Rightarrow> undefined\n          | intgV  i   \\<Rightarrow> undefined\n          | shortV s   \\<Rightarrow> undefined\n          | byteV  by  \\<Rightarrow> undefined\n          | objV   C a \\<Rightarrow> C\n          | arrV  T a  \\<Rightarrow> undefined\n          | nullV      \\<Rightarrow> undefined)\"\n\nlemma tid_simps [simp]:\n\"tid (objV C a) = C\"\nby (simp add: tid_def)\n\n\ndefinition oid :: \"Value \\<Rightarrow> ObjectId\" where\n\"oid v = (case v of\n            boolV  b   \\<Rightarrow> undefined\n          | intgV  i   \\<Rightarrow> undefined\n          | shortV s   \\<Rightarrow> undefined\n          | byteV  by  \\<Rightarrow> undefined\n          | objV   C a \\<Rightarrow> a\n          | arrV  T a  \\<Rightarrow> undefined\n          | nullV      \\<Rightarrow> undefined)\"\n\nlemma oid_simps [simp]:\n\"oid (objV C a) = a\"\nby (simp add: oid_def)\n\n\ndefinition jt :: \"Value \\<Rightarrow> Javatype\" where\n\"jt v = (case v of\n            boolV  b   \\<Rightarrow> undefined\n          | intgV  i   \\<Rightarrow> undefined\n          | shortV s   \\<Rightarrow> undefined\n          | byteV  by  \\<Rightarrow> undefined\n          | objV   C a \\<Rightarrow> undefined\n          | arrV  T a  \\<Rightarrow> at2jt T\n          | nullV      \\<Rightarrow> undefined)\"\n\nlemma jt_simps [simp]:\n\"jt (arrV T a) = at2jt T\"\nby (simp add: jt_def)\n\n\ndefinition aid :: \"Value \\<Rightarrow> ObjectId\" where\n\"aid v = (case v of\n            boolV  b   \\<Rightarrow> undefined\n          | intgV  i   \\<Rightarrow> undefined\n          | shortV s   \\<Rightarrow> undefined\n          | byteV  by  \\<Rightarrow> undefined\n          | objV   C a \\<Rightarrow> undefined\n          | arrV  T a  \\<Rightarrow> a\n          | nullV      \\<Rightarrow> undefined)\"\n\nlemma aid_simps [simp]:\n\"aid (arrV T a) = a\"\nby (simp add: aid_def)\n\nsubsection\\<open>Determining the Type of a Value\\<close>\n\ntext \\<open>To determine the type of a value, we define the function\n\\<open>typeof\\<close>. This function is\noften written as $\\tau$ in theoretical texts, therefore we add\nthe appropriate syntax support.\\<close>\n\ndefinition typeof :: \"Value \\<Rightarrow> Javatype\" where\n\"typeof v = (case v of\n               boolV b  \\<Rightarrow> BoolT \n             | intgV i  \\<Rightarrow> IntgT\n             | shortV sh  \\<Rightarrow> ShortT\n             | byteV by  \\<Rightarrow> ByteT\n             | objV C a \\<Rightarrow> CClassT C\n             | arrV T a \\<Rightarrow> ArrT T\n             | nullV    \\<Rightarrow> NullT)\"\n\nabbreviation tau_syntax :: \"Value \\<Rightarrow> Javatype\" (\"\\<tau> _\")\n  where \"\\<tau> v == typeof v\"\n\nlemma typeof_simps [simp]:\n\"(\\<tau> (boolV b)) = BoolT\"\n\"(\\<tau> (intgV i)) = IntgT\"\n\"(\\<tau> (shortV sh)) = ShortT\"\n\"(\\<tau> (byteV by)) = ByteT\"\n\"(\\<tau> (objV c a)) = CClassT c\"\n\"(\\<tau> (arrV t a)) = ArrT t\"\n\"(\\<tau> (nullV))   = NullT\"\n  by (simp_all add: typeof_def)\n\n\nsubsection \\<open>Default Initialization Values for Types\\<close>\n\ntext \\<open>The function \\<open>init\\<close> yields the default initialization values for each \ntype. For boolean, the\ndefault value is False, for the integral types, it is 0, and for the reference\ntypes, it is nullV.\n\\<close>\n\ndefinition init :: \"Javatype \\<Rightarrow> Value\" where\n\"init T = (case T of\n             BoolT        \\<Rightarrow> boolV  False\n           | IntgT        \\<Rightarrow> intgV  0\n           | ShortT        \\<Rightarrow> shortV 0\n           | ByteT        \\<Rightarrow> byteV  0\n           | NullT        \\<Rightarrow> nullV\n           | ArrT T       \\<Rightarrow> nullV\n           | CClassT C     \\<Rightarrow> nullV\n           | AClassT C     \\<Rightarrow> nullV\n           | InterfaceT I \\<Rightarrow> nullV)\" \n\nlemma init_simps [simp]:\n\"init BoolT          = boolV False\"\n\"init IntgT          = intgV 0\"\n\"init ShortT         = shortV 0\"\n\"init ByteT          = byteV 0\"\n\"init NullT          = nullV\"\n\"init (ArrT T)       = nullV\"\n\"init (CClassT c)     = nullV\"\n\"init (AClassT a)     = nullV\"\n\"init (InterfaceT i) = nullV\"\n  by (simp_all add: init_def)\n\nlemma typeof_init_widen [simp,intro]: \"typeof (init T) \\<le> T\"\nproof (cases T)\n  assume c: \"T = BoolT\"\n  show \"(\\<tau> (init T)) \\<le> T\"\n    using c by simp\nnext\n  assume c: \"T = IntgT\"\n  show \"(\\<tau> (init T)) \\<le> T\"\n    using c by simp\nnext\n  assume c: \"T = ShortT\"\n  show \"(\\<tau> (init T)) \\<le> T\"\n    using c by simp\nnext\n  assume c: \"T = ByteT\"\n  show \"(\\<tau> (init T)) \\<le> T\"\n    using c by simp\nnext\n  assume c: \"T = NullT\"\n  show \"(\\<tau> (init T)) \\<le> T\"\n    using c by simp\nnext\n  fix x\n  assume c: \"T = CClassT x\"\n  show \"(\\<tau> (init T)) \\<le> T\"\n    using c by (cases x, simp_all)\nnext\n  fix x\n  assume c: \"T = AClassT x\"\n  show \"(\\<tau> (init T)) \\<le> T\"\n    using c by (cases x, simp_all)\nnext\n  fix x\n  assume c: \"T = InterfaceT x\"\n  show \"(\\<tau> (init T)) \\<le> T\"\n    using c by (cases x, simp_all)\nnext\n  fix x\n  assume c: \"T = ArrT x\"\n  show \"(\\<tau> (init T)) \\<le> T\"\n    using c \n  proof (cases x)\n    fix y\n    assume c2: \"x = CClassAT y\"\n    show \"(\\<tau> (init T)) \\<le> T\"\n      using c c2 by (cases y, simp_all)\n  next\n    fix y\n    assume c2: \"x = AClassAT y\"\n    show \"(\\<tau> (init T)) \\<le> T\"\n      using c c2 by (cases y, simp_all)\n  next\n    fix y\n    assume c2: \"x = InterfaceAT y\"\n    show \"(\\<tau> (init T)) \\<le> T\"\n      using c c2 by (cases y, simp_all)\n  next\n    assume c2: \"x = BoolAT\"\n    show \"(\\<tau> (init T)) \\<le> T\"\n      using c c2 by simp\n  next\n    assume c2: \"x = IntgAT\"\n    show \"(\\<tau> (init T)) \\<le> T\"\n      using c c2 by simp\n  next\n    assume c2: \"x = ShortAT\"\n    show \"(\\<tau> (init T)) \\<le> T\"\n      using c c2 by simp\n  next\n    assume c2: \"x = ByteAT\"\n    show \"(\\<tau> (init T)) \\<le> T\"\n      using c c2 by simp\n  qed\nqed\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/JiveDataStoreModel/Isabelle/Value.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.523420348936324, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.2841456891028712}}
{"text": "chapter \\<open>Calculus of Programming\\<close>\n\ntheory Calculus_of_Programming\n  imports Spec_Framework IDE_CP_Reasoning1\n  abbrevs \"<state>\" = \"\\<s>\\<t>\\<a>\\<t>\\<e>\"\n      and \"<results>\" = \"\\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s>\"\n      and \"<in>\" = \"\\<i>\\<n>\"\n      and \"<is>\" = \"\\<i>\\<s>\"\nbegin\n\nsection \\<open>Implementing CoP Sequent\\<close>\n\ntext \\<open>CoP sequent \\<open>P | S |- Q\\<close> for \\<open>S = (C\\<^sub>1,v\\<^sub>1); \\<cdots> ; (C\\<^sub>n,v\\<^sub>n)\\<close> is implemented as\n\\begin{align*}\n& \\<open>\\<c>\\<u>\\<r>\\<r>\\<e>\\<n>\\<t> s\\<^sub>0 [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> P\\<close>, \\\\\n& \\<open>CodeBlock s\\<^sub>0 s\\<^sub>1 C\\<^sub>1 v\\<^sub>1,\\<close>         \\\\\n&     \\qquad \\<open>\\<cdots>\\<close>                 \\\\\n& \\<open>CodeBlock s\\<^sub>i\\<^sub>-\\<^sub>1 s\\<^sub>i C\\<^sub>i v\\<^sub>i,\\<close>       \\\\\n&     \\qquad \\<open>\\<cdots>\\<close>                 \\\\\n& \\<open>CodeBlock s\\<^sub>n\\<^sub>-\\<^sub>1 s\\<^sub>n C\\<^sub>n v\\<^sub>n\\<close>        \\\\\n\\<open>\\<turnstile>\\<close> \\;&\\; \\<open>\\<c>\\<u>\\<r>\\<r>\\<e>\\<n>\\<t> s\\<^sub>n [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> Q\\<close>\n\\end{align*}\nwhere \\<open>s\\<^sub>0\\<close> denotes the initial state before execution and \\<open>s\\<^sub>i, v\\<^sub>i\\<close> denote\nrespectively the intermediate state after executing procedure \\<open>C\\<^sub>i\\<close> and\nthe return value of \\<open>C\\<^sub>i\\<close>.\nSequence \\<open>{s\\<^sub>i}\\<^sub>n\\<close> therefore links execution of each procedure.\n\\<open>R\\<close> is the frame variable.\n\n[C]-modality \\<open>[C]{Q}{E}\\<close> is implemented by \\<open>\\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> C \\<o>\\<n> s\\<^sub>n [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> Q \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\\<close>.\n\n\\<close>\n\ntext \\<open>\nIn addition, besides programming of procedures,\nthe system is extended to deduce view shift and transformation of abstraction by programming.\n\nThe programming deduction of view shift is also realized using similar structures\n(\\<open>CurrentConstruction\\<close>). Thus we reuse the infrastructures and\ngive two modes \\<open>programming_mode\\<close> and \\<open>view_shift_mode\\<close> to differentiate the two modes.\n\\<close>\n\nconsts programming_mode :: mode\n       view_shift_mode  :: mode\n\ndefinition CurrentConstruction :: \" mode \\<Rightarrow> resource \\<Rightarrow> assn \\<Rightarrow> assn \\<Rightarrow> bool \"\n  where \"CurrentConstruction mode s R S \\<longleftrightarrow> s \\<in> (INTERP_SPEC (R * S))\"\n\nabbreviation Programming_CurrentConstruction (\"\\<c>\\<u>\\<r>\\<r>\\<e>\\<n>\\<t> _ [_]/ \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> _\" [1000,1000,11] 10)\n  where \\<open>Programming_CurrentConstruction \\<equiv> CurrentConstruction programming_mode\\<close>\n\nabbreviation View_Shift_CurrentConstruction (\"\\<v>\\<i>\\<e>\\<w> _ [_]/ \\<i>\\<s> _\" [1000,1000,11] 10)\n  where \\<open>View_Shift_CurrentConstruction \\<equiv> CurrentConstruction view_shift_mode\\<close>\n\nconsts Programming_CurrentConstruction_syntax :: \\<open>assn \\<Rightarrow> bool\\<close> (\"\\<c>\\<u>\\<r>\\<r>\\<e>\\<n>\\<t> \\<s>\\<t>\\<a>\\<t>\\<e>: _\" [11] 10)\nconsts View_Shift_CurrentConstruction_syntax :: \\<open>assn \\<Rightarrow> bool\\<close> (\"\\<c>\\<u>\\<r>\\<r>\\<e>\\<n>\\<t> \\<v>\\<i>\\<e>\\<w>: _\" [11] 10)\n\ndefinition PendingConstruction :: \" 'ret::VALs proc\n                                  \\<Rightarrow> resource\n                                  \\<Rightarrow> assn\n                                  \\<Rightarrow> ('ret \\<phi>arg \\<Rightarrow> assn)\n                                  \\<Rightarrow> (ABNM \\<Rightarrow> assn)\n                                  \\<Rightarrow> bool \"\n    (\"\\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> _ \\<o>\\<n> _ [_]/ \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> _/ \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> _\" [1000,1000,1000,11,11] 10)\n    where \"PendingConstruction f s R S E \\<longleftrightarrow> f s \\<subseteq> \\<S> (\\<lambda>ret. INTERP_SPEC (R * S ret)) (\\<lambda>ex. INTERP_SPEC (R * E ex))\"\n\nconsts PendingConstruction_syntax :: \\<open>'ret::VALs proc \\<Rightarrow> ('ret \\<phi>arg \\<Rightarrow> assn) \\<Rightarrow> (ABNM \\<Rightarrow> assn) \\<Rightarrow> bool\\<close>\n  (\"\\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> \\<p>\\<r>\\<o>\\<c> _/ \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> _/ \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> _\" [1000,11,11] 10)\n\ntranslations\n  \"\\<c>\\<u>\\<r>\\<r>\\<e>\\<n>\\<t> \\<s>\\<t>\\<a>\\<t>\\<e>: S\" <= \"CONST Programming_CurrentConstruction s R S\"\n  \"\\<c>\\<u>\\<r>\\<r>\\<e>\\<n>\\<t> \\<v>\\<i>\\<e>\\<w>: S\" <= \"CONST View_Shift_CurrentConstruction s R S\"\n  \"\\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> \\<p>\\<r>\\<o>\\<c> f \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> S \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\" <= \"CONST PendingConstruction f s R S E\"\n\ndefinition \\<open>CodeBlock s s' f ret \\<longleftrightarrow> Success ret s' \\<in> f s\\<close>\n\nlemma CurrentConstruction_D: \"CurrentConstruction mode s H T \\<Longrightarrow> Inhabited T\"\n  unfolding CurrentConstruction_def Inhabited_def by (clarsimp simp add: \\<phi>expns; blast)\n\ndefinition ToA_Construction :: \\<open>'a \\<Rightarrow> 'a set \\<Rightarrow> bool\\<close> (\"\\<a>\\<b>\\<s>\\<t>\\<r>\\<a>\\<c>\\<t>\\<i>\\<o>\\<n>'(_') \\<i>\\<s> _\" [11,11] 10)\n  where \\<open>ToA_Construction = (\\<in>)\\<close>\n\n\nsection \\<open>Rules for Constructing Programs\\<close>\n\nsubsection \\<open>Construct Procedure\\<close>\n\nlemma \\<phi>apply_proc:\n  \"(\\<c>\\<u>\\<r>\\<r>\\<e>\\<n>\\<t> blk [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> S)\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> f \\<lbrace> S \\<longmapsto> T \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\n\\<Longrightarrow>(\\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> f \\<o>\\<n> blk [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> T \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E)\"\n  unfolding \\<phi>Procedure_def CurrentConstruction_def PendingConstruction_def bind_def by (auto 0 5)\n\nlemma\n  \\<open> (\\<exists>s' x. CodeBlock s  s'  f x \\<and> CodeBlock s' s'' (g x) y)\n\\<longleftrightarrow> CodeBlock s  s'' (f \\<bind> g) y\\<close>\n  unfolding CodeBlock_def bind_def\n  apply (rule; clarsimp)\n  apply blast\n  by (case_tac x; clarsimp; blast)\n\n\n(*Hint: because\n\\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> f \\<o>\\<n> s [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> U \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E1 \\<longrightarrow>\n  Invalid \\<notin> f s \\<and> (\\<forall>v s'. Abnormality v s' \\<in> f s \\<longrightarrow> s' \\<in> INTERP_SPEC (R \\<heavy_comma> E v))*)\n\nlemma \\<phi>assemble_proc:\n  \\<open> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> f \\<o>\\<n> s [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> T \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E1\n\\<Longrightarrow> (\\<And>s' ret. CodeBlock s s' f ret \\<Longrightarrow> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> (g ret) \\<o>\\<n> s' [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> U \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E2)\n\\<Longrightarrow> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> (f \\<bind> g) \\<o>\\<n> s [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> U \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E1 + E2\\<close>\n  unfolding CurrentConstruction_def PendingConstruction_def bind_def subset_iff CodeBlock_def\n  apply clarsimp subgoal for s s'\n  by (cases s; simp; cases s'; simp add: split_comp_All ring_distribs plus_fun) .\n\n\n\n\nlemma \\<phi>accept_proc:\n  \\<open> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> f \\<o>\\<n> s [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> T \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\n\\<Longrightarrow> CodeBlock s s' f ret\n\\<Longrightarrow> \\<c>\\<u>\\<r>\\<r>\\<e>\\<n>\\<t> s' [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> T ret\\<close>\n  unfolding PendingConstruction_def bind_def subset_iff CurrentConstruction_def CodeBlock_def\n  by blast\n\nlemma \\<phi>accept_proc_optimize_return_v:\n  \\<open> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> (Return v) \\<o>\\<n> s [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> T \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\n\\<Longrightarrow> \\<c>\\<u>\\<r>\\<r>\\<e>\\<n>\\<t> s [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> T v\\<close>\n  unfolding PendingConstruction_def bind_def subset_iff CurrentConstruction_def Return_def\n            det_lift_def\n  by simp\n\n\n(* lemma \\<phi>accept_proc: \\<comment> \\<open>Depreciated!\\<close>\n  \" \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> f \\<o>\\<n> s [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> T \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E1\n\\<Longrightarrow> (\\<And>s' ret. \\<c>\\<u>\\<r>\\<r>\\<e>\\<n>\\<t> s' [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> T ret \\<Longrightarrow> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> (g ret) \\<o>\\<n> s' [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> U \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E2)\n\\<Longrightarrow> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> (f \\<bind> g) \\<o>\\<n> s [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> U \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E1 + E2\"\n  unfolding CurrentConstruction_def PendingConstruction_def bind_def subset_iff plus_fun_def\n  apply clarsimp subgoal for s' s'' by (cases s'; simp; cases s''; simp add: ring_distribs; blast) .*)\n\n(*\nlemma \\<phi>return_when_unreachable:\n  \\<open> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> f \\<o>\\<n> s [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> (\\<lambda>_. T) \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\n\\<Longrightarrow> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> (f \\<ggreater> Return (\\<phi>arg undefined)) \\<o>\\<n> s [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> (\\<lambda>_. T) \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\\<close>\n  for f :: \\<open>unreachable proc\\<close>\n  unfolding CurrentConstruction_def PendingConstruction_def bind_def Return_def det_lift_def subset_iff\n  apply clarsimp subgoal for s' s'' by (cases s'; simp; cases s''; simp add: ring_distribs; blast) .\n*)\nlemma \\<phi>return_additional_unit:\n  \\<open> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> f \\<o>\\<n> s [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> T \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\n\\<Longrightarrow> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> (f \\<bind> (\\<lambda>v. Return (\\<phi>V_pair v \\<phi>V_none))) \\<o>\\<n> s [R]\n        \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> (\\<lambda>ret. T (\\<phi>V_fst ret)) \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\\<close>\n  unfolding CurrentConstruction_def PendingConstruction_def bind_def Return_def \\<phi>V_pair_def\n    \\<phi>V_fst_def \\<phi>V_snd_def det_lift_def subset_iff\n  apply clarsimp subgoal for s' s'' by (cases s'; simp; cases s''; simp add: ring_distribs; blast) .\n\nlemma \\<phi>return:\n  \" \\<c>\\<u>\\<r>\\<r>\\<e>\\<n>\\<t> s [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> T'\n\\<Longrightarrow> T' = T ret\n\\<Longrightarrow> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> (Return ret) \\<o>\\<n> s [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> T \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> 0\"\n  unfolding CurrentConstruction_def PendingConstruction_def bind_def Return_def det_lift_def subset_iff\n  by simp+\n\nlemma \\<phi>reassemble_proc_final:\n  \"(\\<And>s H. \\<c>\\<u>\\<r>\\<r>\\<e>\\<n>\\<t> s [H] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> S \\<Longrightarrow> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> g \\<o>\\<n> s [H] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> T \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E)\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> g \\<lbrace> S \\<longmapsto> T \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\"\n  unfolding CurrentConstruction_def PendingConstruction_def \\<phi>Procedure_def bind_def split_paired_all\n  by blast\n\nlemma \"\\<phi>__Return_rule__\":\n  \\<open> X \\<s>\\<h>\\<i>\\<f>\\<t>\\<s> Y \\<a>\\<n>\\<d> Any\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> Return \\<phi>V_none \\<lbrace> X \\<longmapsto> \\<lambda>_::unit \\<phi>arg. Y \\<rbrace>\\<close>\n  unfolding \\<phi>Procedure_def Return_def View_Shift_def subset_iff det_lift_def\n  by clarsimp\n\nsubsection \\<open>Construct View Shift\\<close>\n\nlemma \\<phi>make_view_shift:\n  \\<open> (\\<And>s R. \\<v>\\<i>\\<e>\\<w> s [R] \\<i>\\<s> S \\<Longrightarrow> (\\<v>\\<i>\\<e>\\<w> s [R] \\<i>\\<s> S' \\<s>\\<u>\\<b>\\<j> P))\n\\<Longrightarrow> S \\<s>\\<h>\\<i>\\<f>\\<t>\\<s> S' \\<a>\\<n>\\<d> P\\<close>\n  unfolding CurrentConstruction_def View_Shift_def\n  by (simp add: INTERP_SPEC_subj Subjection_expn)\n\n\nsubsection \\<open>Construct Implication\\<close>\n\nlemma \"\\<phi>make_implication\":\n  \\<open>(\\<And>x. \\<a>\\<b>\\<s>\\<t>\\<r>\\<a>\\<c>\\<t>\\<i>\\<o>\\<n>(x) \\<i>\\<s> S \\<Longrightarrow> \\<a>\\<b>\\<s>\\<t>\\<r>\\<a>\\<c>\\<t>\\<i>\\<o>\\<n>(x) \\<i>\\<s> T \\<s>\\<u>\\<b>\\<j> P) \\<Longrightarrow> S \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> T \\<a>\\<n>\\<d> P\\<close>\n  unfolding Imply_def ToA_Construction_def\n  by (simp add: Subjection_expn)\n\nsubsection \\<open>Cast\\<close>\n\nlemma \\<phi>apply_view_shift:\n  \" CurrentConstruction mode blk R S\n\\<Longrightarrow> S \\<s>\\<h>\\<i>\\<f>\\<t>\\<s> S' \\<a>\\<n>\\<d> P\n\\<Longrightarrow> (CurrentConstruction mode blk R S') \\<and> P\"\n  unfolding CurrentConstruction_def View_Shift_def\n  by (simp_all add: split_paired_all \\<phi>expns)\n\nlemmas \\<phi>apply_implication = \\<phi>apply_view_shift[OF _ view_shift_by_implication]\n\nlemma \\<phi>apply_view_shift_pending:\n  \" PendingConstruction f blk H T E\n\\<Longrightarrow> (\\<And>x. T x \\<s>\\<h>\\<i>\\<f>\\<t>\\<s> T' x \\<a>\\<n>\\<d> P)\n\\<Longrightarrow> PendingConstruction f blk H T' E\"\n  unfolding PendingConstruction_def View_Shift_def\n  by (clarsimp simp add: \\<phi>expns LooseStateSpec_expn' subset_iff split_comp_All)\n\nlemma \\<phi>apply_view_shift_pending_E:\n  \" PendingConstruction f blk H T E\n\\<Longrightarrow> (\\<And>x. E x \\<s>\\<h>\\<i>\\<f>\\<t>\\<s> E' x \\<a>\\<n>\\<d> P)\n\\<Longrightarrow> PendingConstruction f blk H T E'\"\n  unfolding PendingConstruction_def View_Shift_def\n  by (clarsimp simp add: \\<phi>expns LooseStateSpec_expn' subset_iff split_comp_All)\n\nlemmas \\<phi>apply_implication_pending =\n  \\<phi>apply_view_shift_pending[OF _ view_shift_by_implication]\n\nlemmas \\<phi>apply_implication_pending_E =\n  \\<phi>apply_view_shift_pending_E[OF _ view_shift_by_implication]\n\nlemma \\<phi>ex_quantify_E:\n  \\<open> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> f \\<o>\\<n> blk [H] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> T \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> (E ret)\n\\<Longrightarrow> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> f \\<o>\\<n> blk [H] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> T \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> (\\<lambda>e. ExSet (\\<lambda>x. E x e))\\<close>\n  using \\<phi>apply_implication_pending_E[OF _ ExSet_imp_I[OF implies_refl]] .\n\nlemma \\<phi>apply_implication_impl:\n  \\<open> \\<a>\\<b>\\<s>\\<t>\\<r>\\<a>\\<c>\\<t>\\<i>\\<o>\\<n>(s) \\<i>\\<s> S\n\\<Longrightarrow> S \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> S' \\<a>\\<n>\\<d> P\n\\<Longrightarrow>(\\<a>\\<b>\\<s>\\<t>\\<r>\\<a>\\<c>\\<t>\\<i>\\<o>\\<n>(s) \\<i>\\<s> S') \\<and> P\\<close>\n  unfolding ToA_Construction_def Imply_def by blast\n\nlemma \"_\\<phi>cast_internal_rule_\":\n  \" CurrentConstruction mode blk H T\n\\<Longrightarrow> T \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> T' \\<a>\\<n>\\<d> Any @action ToSA\n\\<Longrightarrow> \\<r>Success\n\\<Longrightarrow> \\<o>\\<b>\\<l>\\<i>\\<g>\\<a>\\<t>\\<i>\\<o>\\<n> True\n\\<Longrightarrow> CurrentConstruction mode blk H T'\"\n  unfolding Action_Tag_def\n  using \\<phi>apply_implication by blast\n\n\nlemma \"_\\<phi>cast_internal_rule_'\":\n  \" \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> f \\<o>\\<n> blk [H] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> T \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\n\\<Longrightarrow> (\\<And>v. T v \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> T' v \\<a>\\<n>\\<d> Any @action ToSA)\n\\<Longrightarrow> \\<r>Success\n\\<Longrightarrow> \\<o>\\<b>\\<l>\\<i>\\<g>\\<a>\\<t>\\<i>\\<o>\\<n> True\n\\<Longrightarrow> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> f \\<o>\\<n> blk [H] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> T' \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\"\n  unfolding Action_Tag_def\n  using \\<phi>apply_implication_pending by blast\n\nlemma \"_\\<phi>cast_exception_\":\n  \" \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> f \\<o>\\<n> blk [H] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> T \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\n\\<Longrightarrow> (\\<And>v. E v \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> E' v @action ToSA)\n\\<Longrightarrow> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> f \\<o>\\<n> blk [H] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> T \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E'\"\n  unfolding Action_Tag_def\n  using \\<phi>apply_implication_pending_E by blast\n\nlemma \"_\\<phi>cast_exception_rule_\":\n  \" \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> f \\<o>\\<n> blk [H] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> T \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\n\\<Longrightarrow> (\\<And>v. E v \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> E' v @action ToSA)\n\\<Longrightarrow> \\<r>Success\n\\<Longrightarrow> \\<o>\\<b>\\<l>\\<i>\\<g>\\<a>\\<t>\\<i>\\<o>\\<n> True\n\\<Longrightarrow> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> f \\<o>\\<n> blk [H] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> T \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E'\"\n  using \"_\\<phi>cast_exception_\" .\n\nlemma \"_\\<phi>cast_implication_\":\n  \\<open> \\<a>\\<b>\\<s>\\<t>\\<r>\\<a>\\<c>\\<t>\\<i>\\<o>\\<n>(x) \\<i>\\<s> S\n\\<Longrightarrow> S \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> T \\<a>\\<n>\\<d> Any @action ToSA\n\\<Longrightarrow> \\<r>Success\n\\<Longrightarrow> \\<o>\\<b>\\<l>\\<i>\\<g>\\<a>\\<t>\\<i>\\<o>\\<n> True\n\\<Longrightarrow> \\<a>\\<b>\\<s>\\<t>\\<r>\\<a>\\<c>\\<t>\\<i>\\<o>\\<n>(x) \\<i>\\<s> T\\<close>\n  unfolding ToA_Construction_def Action_Tag_def Imply_def by blast\n\n\nsubsection \\<open>Finalization Rewrites\\<close>\n\ntext \\<open>Rules showing the obtained procedure is identical to the desired goal\n  in the end of the construction.\\<close>\n\nML \\<open>structure Proc_Monad_SS = Simpset(\n  val initial_ss = Simpset_Configure.Minimal_SS\n  val binding = \\<^binding>\\<open>procedure_simps\\<close>\n  val comment = \"declare the rules for simplifying procedure monad.\"\n)\\<close>\n\nconsts procedure_simplification :: mode\n\nlemmas [procedure_simps] =\n            proc_bind_SKIP proc_bind_SKIP'\n            proc_bind_assoc proc_bind_return_none \\<phi>V_simps\n\n\\<phi>reasoner_ML procedure_equivalence 1200 (\\<open>Premise procedure_simplification ?P\\<close>)\n  = \\<open>PLPR_Simplifier.simplifier_by_ss' NONE Proc_Monad_SS.get'\\<close>\n\n\\<phi>reasoner_ML procedure_simplification 1000 (\\<open>Simplify procedure_simplification ?x ?y\\<close>)\n  = \\<open>PLPR_Simplifier.simplifier_by_ss' NONE Proc_Monad_SS.get'\\<close>\n\nsubsection \\<open>Misc\\<close>\n\nparagraph \\<open>Inhabitance\\<close>\n\nlemma ToA_Construction_Inhabited_rule:\n  \\<open>\\<a>\\<b>\\<s>\\<t>\\<r>\\<a>\\<c>\\<t>\\<i>\\<o>\\<n>(x) \\<i>\\<s> S \\<Longrightarrow> (Inhabited S \\<Longrightarrow> C) \\<Longrightarrow> C\\<close>\n  unfolding ToA_Construction_def Inhabited_def by blast\n\nlemma CurrentConstruction_Inhabited_rule:\n  \"CurrentConstruction mode s H T \\<Longrightarrow> (Inhabited T \\<Longrightarrow> C) \\<Longrightarrow> C\"\n  using CurrentConstruction_D by blast\n\n\nparagraph \\<open>Fact Store\\<close>\n\nlemma [\\<phi>programming_simps]:\n  \"CurrentConstruction mode s H (T \\<s>\\<u>\\<b>\\<j> P) \\<longleftrightarrow> (CurrentConstruction mode s H T) \\<and> P\"\n  unfolding CurrentConstruction_def by (simp_all add: \\<phi>expns split_paired_all)\n\nlemma [\\<phi>programming_simps]:\n  \"(CurrentConstruction mode s H T \\<and> B) \\<and> C \\<longleftrightarrow> (CurrentConstruction mode s H T) \\<and> (B \\<and> C)\"\n  by simp\n\nlemma [\\<phi>programming_simps]:\n  \\<open>(\\<a>\\<b>\\<s>\\<t>\\<r>\\<a>\\<c>\\<t>\\<i>\\<o>\\<n>(x) \\<i>\\<s> T \\<s>\\<u>\\<b>\\<j> P) \\<longleftrightarrow> (\\<a>\\<b>\\<s>\\<t>\\<r>\\<a>\\<c>\\<t>\\<i>\\<o>\\<n>(x) \\<i>\\<s> T) \\<and> P\\<close>\n  unfolding ToA_Construction_def by (simp add: Subjection_expn)\n\nlemma [\\<phi>programming_simps]:\n  \\<open>((\\<a>\\<b>\\<s>\\<t>\\<r>\\<a>\\<c>\\<t>\\<i>\\<o>\\<n>(x) \\<i>\\<s> T) \\<and> B) \\<and> C \\<longleftrightarrow> (\\<a>\\<b>\\<s>\\<t>\\<r>\\<a>\\<c>\\<t>\\<i>\\<o>\\<n>(x) \\<i>\\<s> T) \\<and> (B \\<and> C)\\<close>\n  by simp\n\nparagraph \\<open>Fixing Existentially Quantified Variable\\<close>\n\nlemma \\<phi>ExTyp_strip:\n  \"(CurrentConstruction mode p H (ExSet T)) \\<equiv> (\\<exists>c. CurrentConstruction mode p H (T c))\"\n  unfolding CurrentConstruction_def atomize_eq by (simp_all add: \\<phi>expns split_paired_all)\n\nlemma \\<phi>ExTyp_strip_imp:\n  \\<open>ToA_Construction s (ExSet T) \\<equiv> (\\<exists>c. ToA_Construction s (T c))\\<close>\n  unfolding ToA_Construction_def by (simp add: \\<phi>expns)\n\nparagraph \\<open>Introducing Existential Quantification\\<close>\n\nlemma introduce_Ex:\n  \\<open>CurrentConstruction mode blk H (S x) \\<Longrightarrow> CurrentConstruction mode blk H (ExSet S)\\<close>\n  using \\<phi>apply_implication[OF _ ExSet_imp_I[OF implies_refl], THEN conjunct1] .\n\nlemma introduce_Ex_subj:\n  \\<open>CurrentConstruction mode blk H (S x \\<s>\\<u>\\<b>\\<j> Q) \\<Longrightarrow> CurrentConstruction mode blk H (ExSet S \\<s>\\<u>\\<b>\\<j> Q)\\<close>\n  by (metis Subjection_True Subjection_cong introduce_Ex)\n\nlemma introduce_Ex_pending:\n  \\<open> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> f \\<o>\\<n> blk [H] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> (\\<lambda>v. Q x v) \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\n\\<Longrightarrow> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> f \\<o>\\<n> blk [H] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> (\\<lambda>v. \\<exists>*x. Q x v) \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\\<close>\n  using \\<phi>apply_implication_pending[OF _ ExSet_imp_I[OF implies_refl]] .\n\nlemma introduce_Ex_pending_E:\n  \\<open> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> f \\<o>\\<n> blk [H] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> Q \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> (\\<lambda>v. E x v)\n\\<Longrightarrow> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> f \\<o>\\<n> blk [H] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> Q \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> (\\<lambda>v. \\<exists>*x. E x v)\\<close>\n  using \\<phi>apply_implication_pending_E[OF _ ExSet_imp_I[OF implies_refl]] .\n\nlemma introduce_Ex_ToA:\n  \\<open> ToA_Construction s (S x)\n\\<Longrightarrow> ToA_Construction s (ExSet S) \\<close>\n  using \\<phi>ExTyp_strip_imp by fastforce\n\nlemma introduce_Ex_ToA_subj:\n  \\<open> ToA_Construction s (S x \\<s>\\<u>\\<b>\\<j> Q)\n\\<Longrightarrow> ToA_Construction s (ExSet S \\<s>\\<u>\\<b>\\<j> Q) \\<close>\n  by (metis Subjection_Flase Subjection_True introduce_Ex_ToA)\n\n\nparagraph \\<open>Return\\<close>\n\n\nlemma \\<phi>M_Success[intro!]:\n  \\<open> v \\<in> (y \\<Ztypecolon> T)\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> Return (\\<phi>arg v) \\<lbrace> X \\<longmapsto> \\<lambda>u. X\\<heavy_comma> y \\<Ztypecolon> Val u T \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> Any \\<close>\n  unfolding \\<phi>Procedure_def det_lift_def Return_def\n  by (clarsimp simp add: \\<phi>expns)\n\ndeclare \\<phi>M_Success[where X=1, simplified, intro!]\n\nlemma \\<phi>M_Success'[intro!]:\n  \\<open> \\<p>\\<r>\\<o>\\<c> Return vs \\<lbrace> X vs \\<longmapsto> X \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> Any \\<close>\n  unfolding Return_def \\<phi>Procedure_def det_lift_def by (clarsimp simp add: \\<phi>expns)\n\n\nend", "meta": {"author": "xqyww123", "repo": "phi-system", "sha": "c8dca186bcc8ac2c9b38d813fc0f0dfec486ebab", "save_path": "github-repos/isabelle/xqyww123-phi-system", "path": "github-repos/isabelle/xqyww123-phi-system/phi-system-c8dca186bcc8ac2c9b38d813fc0f0dfec486ebab/Phi_System/Calculus_of_Programming.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.523420348936324, "lm_q2_score": 0.5428632831725051, "lm_q1q2_score": 0.28414568910287114}}
{"text": "theory LiarsStreet  (*Christoph Benzmüller, 2020*)\n  imports Main  \n\nabbrevs   \n Nilda=\"\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a\" and Nilda=\"\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a\" and And=\"( \\<^bold>a\\<^bold>n\\<^bold>d )\" and Or=\"( \\<^bold>o\\<^bold>r )\" and Not=\"(\\<^bold>n\\<^bold>o\\<^bold>t )\" and If_then=\"(\\<^bold>I\\<^bold>f \\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>n )\"\n and LiarsStreet=\"\\<^bold>L\\<^bold>i\\<^bold>a\\<^bold>r\\<^bold>s\\<^bold>S\\<^bold>t\\<^bold>r\\<^bold>e\\<^bold>e\\<^bold>t\" and TruthtellersRoad=\"\\<^bold>T\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h\\<^bold>t\\<^bold>e\\<^bold>l\\<^bold>l\\<^bold>e\\<^bold>r\\<^bold>s\\<^bold>R\\<^bold>o\\<^bold>a\\<^bold>d\" and Lies=\"\\<^bold>(l\\<^bold>i\\<^bold>e\\<^bold>s )\"\n and Says_the_truth=\"(\\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s\\<^bold>-\\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>-\\<^bold>t\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h )\" and Lives_not_in=\"( \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>n\\<^bold>o\\<^bold>t\\<^bold>-\\<^bold>i\\<^bold>n )\" \n and Neither_nor_live_in=\"\\<^bold>(n\\<^bold>e\\<^bold>i\\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>r  \\<^bold>n\\<^bold>o\\<^bold>r  \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>-\\<^bold>i\\<^bold>n )\" and Both_live_in=\"\\<^bold>(b\\<^bold>o\\<^bold>t\\<^bold>h  \\<^bold>a\\<^bold>n\\<^bold>d  \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>-\\<^bold>i\\<^bold>n )\" \n\nbegin          \n(*unimportant*) nitpick_params [user_axioms,format=2,show_all]\n(*unimportant*) declare [[show_abbrevs=false]]\n\n(***********************************************************************************\n ******************  Some Basic Types of our Ontology ******************************\n ***********************************************************************************)\n\n(* There are some kids, could be many more *)\ndatatype Entity = Nilda (\"\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a\") | Carla  (\"\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a\")\n\nlemma \"\\<not>(\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a = \\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a)\" sledgehammer by simp\n\n(* There are some roads, could be many more *)\ndatatype Street = LiarsStreet (\"\\<^bold>L\\<^bold>i\\<^bold>a\\<^bold>r\\<^bold>s\\<^bold>S\\<^bold>t\\<^bold>r\\<^bold>e\\<^bold>e\\<^bold>t\") | TruthtellersRoad (\"\\<^bold>T\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h\\<^bold>t\\<^bold>e\\<^bold>l\\<^bold>l\\<^bold>e\\<^bold>r\\<^bold>s\\<^bold>R\\<^bold>o\\<^bold>a\\<^bold>d\") \n\n(***********************************************************************************\n ******************  Controlled Natural Language Library ***************************\n ******************  Logic and Modalities ******************************************\n ***********************************************************************************)\n\ndefinition And (\"_ \\<^bold>a\\<^bold>n\\<^bold>d _\") where \"X \\<^bold>a\\<^bold>n\\<^bold>d Y \\<equiv> X \\<and> Y\"\nabbreviation Or (\"_ \\<^bold>o\\<^bold>r _\") where \"X \\<^bold>o\\<^bold>r Y \\<equiv> X \\<or> Y\"\ndefinition Not (\"\\<^bold>n\\<^bold>o\\<^bold>t _\") where \"\\<^bold>n\\<^bold>o\\<^bold>t X \\<equiv> \\<not>X\"\ndefinition If_then (\"\\<^bold>I\\<^bold>f _ \\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>n _\") where \"\\<^bold>I\\<^bold>f X \\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>n Y \\<equiv> X \\<longrightarrow> Y\"\n\n\n(* \"Says\" \"Knows\" \"Belief\" \"Obligation\", etc. as uninterpreted truth-functions\n   --- which, of course, will lead to known paradoxes *)\nconsts  Says::\"Entity\\<Rightarrow>bool\\<Rightarrow>bool\"  (\"_ \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s _\") \nconsts  Knows::\"Entity\\<Rightarrow>bool\\<Rightarrow>bool\"  (\"_ \\<^bold>k\\<^bold>n\\<^bold>o\\<^bold>w\\<^bold>s _\")  \nconsts  Believes::\"Entity\\<Rightarrow>bool\\<Rightarrow>bool\"  (\"_ \\<^bold>b\\<^bold>e\\<^bold>l\\<^bold>i\\<^bold>e\\<^bold>v\\<^bold>e\\<^bold>s _\")    \nconsts  Obligation::\"Entity\\<Rightarrow>bool\\<Rightarrow>bool\"  (\"_ \\<^bold>m\\<^bold>u\\<^bold>s\\<^bold>t\\<^bold>-\\<^bold>d\\<^bold>o _\") \n\n(* We can introduce some further derived modal NL phrases *)\ndefinition Lies (\"\\<^bold>l\\<^bold>i\\<^bold>e\\<^bold>s _\") where \"\\<^bold>l\\<^bold>i\\<^bold>e\\<^bold>s X \\<equiv> \\<forall>Y. \\<^bold>I\\<^bold>f (X \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s Y) \\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>n \\<^bold>n\\<^bold>o\\<^bold>t Y\"\ndefinition Says_the_truth (\"\\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s\\<^bold>-\\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>-\\<^bold>t\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h _\") \n  where \"\\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s\\<^bold>-\\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>-\\<^bold>t\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h X \\<equiv> \\<forall>Y. \\<^bold>I\\<^bold>f (X \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s Y) \\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>n Y\" \n\n(* We add the above defintions to our \"bag\" called \"Defs\" — Unimportant *)\nnamed_theorems Defs\ndeclare Lies_def [Defs] Says_the_truth_def [Defs] \n\n\n(***********************************************************************************\n ****************** Controlled Natural Language Library ****************************\n ****************** Domain specific concepts ***************************************\n ***********************************************************************************)\n\n(* Uninterpreted predicate: Lives_in *)\nconsts Lives_in::\"Entity\\<Rightarrow>Street\\<Rightarrow>bool\" (\"_ \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n _\") \n\n(* Further derived NL phrases that concern \"Lives_in\" *)\ndefinition Lives_not_in (\"_ \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>n\\<^bold>o\\<^bold>t\\<^bold>-\\<^bold>i\\<^bold>n _\")\n  where \"X \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>n\\<^bold>o\\<^bold>t\\<^bold>-\\<^bold>i\\<^bold>n G \\<equiv> \\<^bold>n\\<^bold>o\\<^bold>t (X \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n G)\"\ndefinition Neither_nor_live_in (\"\\<^bold>n\\<^bold>e\\<^bold>i\\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>r _ \\<^bold>n\\<^bold>o\\<^bold>r _ \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>-\\<^bold>i\\<^bold>n _\") \n  where \"\\<^bold>n\\<^bold>e\\<^bold>i\\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>r X \\<^bold>n\\<^bold>o\\<^bold>r Y \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>-\\<^bold>i\\<^bold>n G \\<equiv> (\\<^bold>n\\<^bold>o\\<^bold>t (X \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n G)) \\<^bold>a\\<^bold>n\\<^bold>d (\\<^bold>n\\<^bold>o\\<^bold>t (Y \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n G))\"\ndefinition Both_live_in (\"\\<^bold>b\\<^bold>o\\<^bold>t\\<^bold>h _ \\<^bold>a\\<^bold>n\\<^bold>d _ \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>-\\<^bold>i\\<^bold>n _\") \n  where \"\\<^bold>b\\<^bold>o\\<^bold>t\\<^bold>h X \\<^bold>a\\<^bold>n\\<^bold>d Y \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>-\\<^bold>i\\<^bold>n G \\<equiv> (X \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n G) \\<^bold>a\\<^bold>n\\<^bold>d (Y \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n G)\"\n\n(* We add the above defintions to our \"bag\" called \"Defs\" — Unimportant *)\ndeclare Lives_not_in_def [Defs] Neither_nor_live_in_def [Defs] Both_live_in_def [Defs] \n\n\n(***********************************************************************************\n ****************** Example Queries ************************************************\n ***********************************************************************************)\n\naxiomatization where\nA1:  \"\\<forall>X. \\<^bold>I\\<^bold>f (X \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>L\\<^bold>i\\<^bold>a\\<^bold>r\\<^bold>s\\<^bold>S\\<^bold>t\\<^bold>r\\<^bold>e\\<^bold>e\\<^bold>t) \\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>n (\\<^bold>l\\<^bold>i\\<^bold>e\\<^bold>s X)\"  and\nA2:  \"\\<forall>X. \\<^bold>I\\<^bold>f (X \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>T\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h\\<^bold>t\\<^bold>e\\<^bold>l\\<^bold>l\\<^bold>e\\<^bold>r\\<^bold>s\\<^bold>R\\<^bold>o\\<^bold>a\\<^bold>d) \\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>n (\\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s\\<^bold>-\\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>-\\<^bold>t\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h X)\" \n\n\nlemma Question1:\n  assumes\n   \"\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s (\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>T\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h\\<^bold>t\\<^bold>e\\<^bold>l\\<^bold>l\\<^bold>e\\<^bold>r\\<^bold>s\\<^bold>R\\<^bold>o\\<^bold>a\\<^bold>d)\" \n   \"\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s (\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>T\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h\\<^bold>t\\<^bold>e\\<^bold>l\\<^bold>l\\<^bold>e\\<^bold>r\\<^bold>s\\<^bold>R\\<^bold>o\\<^bold>a\\<^bold>d)\"\n  shows\n   \"((\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n S1) \\<^bold>a\\<^bold>n\\<^bold>d (\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n S2))\"         \n  nitpick[satisfy] oops  \n\n\n\nlemma Question1b:\n  assumes\n   \"\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s (\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>T\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h\\<^bold>t\\<^bold>e\\<^bold>l\\<^bold>l\\<^bold>e\\<^bold>r\\<^bold>s\\<^bold>R\\<^bold>o\\<^bold>a\\<^bold>d)\" \n   \"\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s (\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>T\\<^bold>r\\<^bold>u\\<^bold>t\\<^bold>h\\<^bold>t\\<^bold>e\\<^bold>l\\<^bold>l\\<^bold>e\\<^bold>r\\<^bold>s\\<^bold>R\\<^bold>o\\<^bold>a\\<^bold>d)\"\n  shows\n   \"((\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>L\\<^bold>i\\<^bold>a\\<^bold>r\\<^bold>s\\<^bold>S\\<^bold>t\\<^bold>r\\<^bold>e\\<^bold>e\\<^bold>t) \\<^bold>a\\<^bold>n\\<^bold>d (\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n S2))\"         \n  nitpick[satisfy] oops \n\nlemma Question2:\n  assumes\n   \"\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s (\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>L\\<^bold>i\\<^bold>a\\<^bold>r\\<^bold>s\\<^bold>S\\<^bold>t\\<^bold>r\\<^bold>e\\<^bold>e\\<^bold>t)\"  \n   \"\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s (\\<^bold>n\\<^bold>e\\<^bold>i\\<^bold>t\\<^bold>h\\<^bold>e\\<^bold>r \\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>n\\<^bold>o\\<^bold>r \\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>L\\<^bold>i\\<^bold>a\\<^bold>r\\<^bold>s\\<^bold>S\\<^bold>t\\<^bold>r\\<^bold>e\\<^bold>e\\<^bold>t)\"\n  shows\n   \"((\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n S1) \\<^bold>a\\<^bold>n\\<^bold>d (\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n S2))\"         \n  nitpick[satisfy] oops\n\nlemma Question3:\n  assumes\n   \"\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s (\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>L\\<^bold>i\\<^bold>a\\<^bold>r\\<^bold>s\\<^bold>S\\<^bold>t\\<^bold>r\\<^bold>e\\<^bold>e\\<^bold>t)\" \n   \"\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s (\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n \\<^bold>L\\<^bold>i\\<^bold>a\\<^bold>r\\<^bold>s\\<^bold>S\\<^bold>t\\<^bold>r\\<^bold>e\\<^bold>e\\<^bold>t)\" \n shows\n   \"((\\<^bold>N\\<^bold>i\\<^bold>l\\<^bold>d\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n S1) \\<^bold>a\\<^bold>n\\<^bold>d (\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>l\\<^bold>i\\<^bold>v\\<^bold>e\\<^bold>s\\<^bold>-\\<^bold>i\\<^bold>n S2))\"    \n  nitpick[satisfy] oops\n\n(*** Do we run into Paradoxes with the modelling of modalities? ***)\n\nconsts It_holds_that_One_plus_One_Equals_Two::bool\n       It_holds_that_Fermats_last_Theorem_is_True::bool\n\n\n\nlemma Question8:\n  assumes\n   \"It_holds_that_One_plus_One_Equals_Two\" \n   \"It_holds_that_Fermats_last_Theorem_is_True\" \n   \"\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s It_holds_that_One_plus_One_Equals_Two\"\n  shows\n   \"\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>s\\<^bold>a\\<^bold>y\\<^bold>s It_holds_that_Fermats_last_Theorem_is_True\"  \n  using assms(1) assms(2) assms(3) by auto\n\n\nlemma Question9:\n  assumes\n   \"It_holds_that_One_plus_One_Equals_Two\" \n   \"It_holds_that_Fermats_last_Theorem_is_True\" \n   \"\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>k\\<^bold>n\\<^bold>o\\<^bold>w\\<^bold>s It_holds_that_One_plus_One_Equals_Two\"\n  shows\n   \"\\<^bold>C\\<^bold>a\\<^bold>r\\<^bold>l\\<^bold>a \\<^bold>k\\<^bold>n\\<^bold>o\\<^bold>w\\<^bold>s It_holds_that_Fermats_last_Theorem_is_True\"  \n  sledgehammer [verbose](assms)\n  nitpick oops\n\nend", "meta": {"author": "cbenzmueller", "repo": "LogiKEy", "sha": "5c16bdeb68bf8131e24ba9c8d774d4af663cb2cf", "save_path": "github-repos/isabelle/cbenzmueller-LogiKEy", "path": "github-repos/isabelle/cbenzmueller-LogiKEy/LogiKEy-5c16bdeb68bf8131e24ba9c8d774d4af663cb2cf/CoursesAndTutorials/2020-ZhejiangUniversity/examples/LiarsStreet/LiarsStreet.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5428632683808533, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.2841456813606196}}
{"text": "theory Semantics\nimports Model\nbegin\ntypedecl binop\naxiomatization apply_binop :: \"binop \\<Rightarrow> val \\<Rightarrow> val \\<Rightarrow> val\"\n  and plus minus :: binop\ntypedecl unop\naxiomatization apply_unop :: \"unop \\<Rightarrow> val \\<Rightarrow> val\"\ndatatype condition = Eq | Neq | Leq | Le | Geq | Gr\n\nfun eval_cond_aux :: \"val \\<Rightarrow> val \\<Rightarrow> (byte \\<Rightarrow> byte \\<Rightarrow> bool) \\<Rightarrow> bool \\<Rightarrow> bool\" where\n  \"eval_cond_aux [] [] _ b = b\"\n| \"eval_cond_aux [] _ _ _ = undefined\"\n| \"eval_cond_aux _ [] _ _ = undefined\"\n| \"eval_cond_aux (v1#xs) (v2#ys) c b = (if v1=v2 then eval_cond_aux xs ys c b\n    else c v1 v2)\"\n\nfun eval_cond :: \"condition \\<Rightarrow> val \\<Rightarrow> val \\<Rightarrow> bool\" where\n  \"eval_cond Eq v1 v2 = (v1=v2)\"\n| \"eval_cond Neq v1 v2 = (v1\\<noteq>v2)\"\n| \"eval_cond Leq v1 v2 = eval_cond_aux v1 v2 (\\<le>) True\"\n| \"eval_cond Le v1 v2 = eval_cond_aux v1 v2 (<) False\"\n| \"eval_cond Geq v1 v2 = eval_cond_aux v1 v2 (\\<ge>) True\"\n| \"eval_cond Gr v1 v2 = eval_cond_aux v1 v2 (>) False\"\n\ntype_synonym func = \"string \\<times> var list\"\n\ndatatype command =\n  AssignConst var val \n| AssignVar var var\n| Load var var\n| Store var var\n| Malloc var var\n| Free var\n| BinOp binop var var var\n| UnOp unop var var\n| PtrPlus var var var\n| PtrSub var var var\n| Memcpy (dest: var) (source: var) (number: var)\n| Assume condition var var\n| Assert condition var var\n| Call \"func\" \"var list\"\n\nsubsection \\<open>CFG\\<close>\n\ntypedecl CFG_node\naxiomatization entry :: CFG_node and exit :: CFG_node\n\ntype_synonym edge = \"CFG_node \\<times> command \\<times> CFG_node\"\ntype_synonym cfg = \"func \\<times> edge set\"\ntype_synonym prog = \"string \\<rightharpoonup> cfg\"\n\nabbreviation can_allocate_from :: \"blocks \\<Rightarrow> loc \\<Rightarrow> blockname \\<Rightarrow> val \\<Rightarrow> bool\" where\n  \"can_allocate_from B l n z \\<equiv>\n    0<l \\<and> \\<comment> \\<open>The location is not at null.\\<close>\n    l < l + (loc64_ops.from_val z) \\<and> \\<comment> \\<open>The allocated block does not wrap around.\\<close>\n    \\<comment> \\<open>It doesn't overlap with any other block.\\<close>\n    (\\<forall>b\\<in>set (raw_blocks B). \\<not>(overlaps_with (n,l,l + (loc64_ops.from_val z)) b)) \\<and>\n    (\\<forall>b\\<in>set (raw_blocks B). (case b of (n',_,_) \\<Rightarrow> n'\\<noteq>n)) \\<comment> \\<open>The name is new and unique\\<close>\"\n\ntext \\<open>Given a control flow graph as a map from function names to their body graphs, \n  relate the semantics of the program. The program implicitly starts at ''main''.\\<close>\ncontext fixes funs :: \"string \\<Rightarrow> cfg option\" begin\ninductive semantics :: \"pre_config \\<Rightarrow> command \\<Rightarrow> pre_config option \\<Rightarrow> bool\"\n  and fun_semantics :: \"string \\<Rightarrow> pre_config \\<Rightarrow> pre_config \\<Rightarrow> bool\"\n  and cfg_reachable :: \"edge set \\<Rightarrow> CFG_node \\<Rightarrow> CFG_node \\<Rightarrow> pre_config \\<Rightarrow> pre_config \\<Rightarrow> bool\" where  SingleStep: \"\\<lbrakk>\\<exists>cmd. (from,cmd,to) \\<in> es; semantics pre cmd (Some post)\\<rbrakk> \\<Longrightarrow> cfg_reachable es from to pre post\"\n| MultiStep: \"\\<lbrakk>\\<exists>cmd. (from,cmd,to') \\<in> es; semantics pre cmd (Some interm); \n  cfg_reachable es to' to interm post\\<rbrakk> \\<Longrightarrow> cfg_reachable es from to pre post\"\n| \"\\<lbrakk>(funs f) = Some cfg; cfg_reachable (snd cfg) entry exit pre post\\<rbrakk> \\<Longrightarrow> fun_semantics f pre post\"\n|  \"fits k x \\<Longrightarrow> semantics (S,B,M) (AssignConst x k) (Some (update_stack S x k,B,M))\"\n| \"size x = size y \\<Longrightarrow> semantics (S,B,M) (AssignVar x y) (Some (update_stack S x (lookup S y),B,M))\"\n| LoadFail: \n  \"\\<comment> \\<open>y does not point into any block, i.e. is an invalid location\\<close>\n  base B (loc64_ops.from_val (lookup S y)) = 0 \\<or>\n  \\<comment> \\<open>This load would read past the end of the block.\\<close>\n  ((loc64_ops.from_val (lookup S y)) + (sizev x) > ende B (loc64_ops.from_val (lookup S y)) \\<or> \n  \\<comment> \\<open>This would read past the maximum location and wrap around.\\<close>\n  (loc64_ops.from_val (lookup S y)) + (sizev x) \\<le> (loc64_ops.from_val (lookup S y))) \\<Longrightarrow>\n     semantics (S,B,M) (Load x y) None\"\n| LoadSuccess: \"\\<lbrakk>\\<not>(base B (loc64_ops.from_val (lookup S y)) = 0 \\<or> \n  ((loc64_ops.from_val (lookup S y)) + (sizev x) > ende B (loc64_ops.from_val (lookup S y)) \\<or>\n  (loc64_ops.from_val (lookup S y)) + (sizev x) \\<le> (loc64_ops.from_val (lookup S y))));\n  \\<comment> \\<open>The addressed memory cells are actually allocated.\\<close>\n  access M (loc64_ops.from_val (lookup S y)) (size x) = Some v\\<rbrakk> \\<Longrightarrow> \n    semantics (S,B,M) (Load x y) (Some (update_stack S x v, B, M))\"\n| StoreFail:\n  \"\\<comment> \\<open>x does not point into any block, i.e. is an invalid location\\<close>\n  base B (loc64_ops.from_val (lookup S x)) = 0 \\<or>\n  \\<comment> \\<open>This store woudl write past the end of the block.\\<close>\n  ((loc64_ops.from_val (lookup S x)) + (sizev y) > ende B (loc64_ops.from_val (lookup S x)) \\<or> \n  \\<comment> \\<open>This would write past the maximum location and wrap around.\\<close>\n  (loc64_ops.from_val (lookup S x)) + (sizev y) \\<le> (loc64_ops.from_val (lookup S x))) \\<Longrightarrow>\n    semantics (S,B,M) (Store x y) None\"\n| StoreSuccess: \"\\<not>(base B (loc64_ops.from_val (lookup S x)) = 0 \\<or> \n  ((loc64_ops.from_val (lookup S x)) + (sizev y) > ende B (loc64_ops.from_val (lookup S x)) \\<or>\n  (loc64_ops.from_val (lookup S x)) + (sizev y) \\<le> (loc64_ops.from_val (lookup S x)))) \\<Longrightarrow> \n    semantics (S,B,M) (Store x y) (Some (S, B, update_memory M (loc64_ops.from_val (lookup S x)) (lookup S y)))\"\n| MallocError: \"\n  \\<comment> \\<open>If we would allocate 0 bytes or x can't hold a pointer.\\<close>\n  (\\<forall>v\\<in>set (lookup S z). v = 0) \\<or> (size x \\<noteq> loc_N_B) \\<Longrightarrow> \n  semantics (S,_,_) (Malloc x z) None\"\n| MallocSuccessNull: \"\\<lbrakk>\\<exists>v\\<in>set (lookup S z). v \\<noteq> 0; size x = loc_N_B\\<rbrakk> \\<Longrightarrow>\n  semantics (S,B,M) (Malloc x z) (Some (update_stack S x (null x),B,M))\"\n| MallocSuccess: \"\\<lbrakk>\\<exists>v\\<in>set (lookup S z). v \\<noteq> 0; size x = loc_N_B;\n  \\<comment> \\<open>l and n are new, k is arbitrary\\<close>\n  can_allocate_from B l n (lookup S z); length k = length (lookup S z)\\<rbrakk> \\<Longrightarrow>\n  semantics (S,B,M) (Malloc x z) \n    (Some (update_stack S  x (loc64_ops.to_val l), \n    Blocks ((n,l,l+(loc64_ops.from_val (lookup S z)))#raw_blocks B),\n    update_memory M l k))\"\n| FreeError: \"loc64_ops.from_val (lookup S x) \\<noteq> base B (loc64_ops.from_val (lookup S x))\n  \\<Longrightarrow> semantics (S,B,_) (Free x) None\"\n| FreeSuccess: \"\\<lbrakk>loc64_ops.from_val (lookup S x) = y; y = base B y\\<rbrakk>\n  \\<Longrightarrow> semantics (S,B,M) (Free x) (Some (S,free_block B y, free_memory M y (ende B y)))\"\n| \"semantics (S,B,M) (BinOp b x y z) \n  (Some (update_stack S x (apply_binop b (lookup S y) (lookup S z)),B,M))\"\n| \"semantics (S,B,M) (UnOp u x y) \n  (Some (update_stack S x (apply_unop u (lookup S y)),B,M))\"\n| PtrPlusError: \"\\<lbrakk>y'=loc64_ops.from_val (lookup S y); z'=loc64_ops.from_val (lookup S z);\n  (\\<forall>v\\<in>set (lookup S y). v = 0) \\<or> (y' + z' < base B y') \\<or> (y' + z' > ende B y')\\<rbrakk>\n  \\<Longrightarrow> semantics (S,B,M) (PtrPlus _ y z) None\"\n| PtrPlusSuccess: \"\\<lbrakk>y'=loc64_ops.from_val (lookup S y); z'=loc64_ops.from_val (lookup S z);\n  \\<exists>v\\<in>set (lookup S y). v \\<noteq> 0; y' + z' \\<ge> base B y'; y' + z' \\<le> ende B y'\\<rbrakk>\n  \\<Longrightarrow> semantics (S,B,M) (PtrPlus x y z) (Some (update_stack S x (loc64_ops.to_val (y'+z')),B,M))\"\n| PtrSubError: \"\\<lbrakk>y'=loc64_ops.from_val (lookup S y); z'=loc64_ops.from_val (lookup S z);\n  (\\<forall>v\\<in>set (lookup S y). v = 0) \\<or> (from_block y' B \\<noteq> from_block z' B)\\<rbrakk>\n  \\<Longrightarrow> semantics (S,B,M) (PtrSub _ y z) None\"\n| PtrSubSuccess: \"\\<lbrakk>y'=loc64_ops.from_val (lookup S y); z'=loc64_ops.from_val (lookup S z);\n  \\<exists>v\\<in>set (lookup S y). v \\<noteq> 0; from_block y' B = from_block z' B\\<rbrakk>\n  \\<Longrightarrow> semantics (S,B,M) (PtrSub x y z) (Some (update_stack S x (loc64_ops.to_val (y'-z')),B,M))\"\n| MemcpyError: \"\\<lbrakk>y'=loc64_ops.from_val (lookup S y); z'=loc64_ops.from_val (lookup S z);\n  x'=loc64_ops.from_val (lookup S x);\n  \\<comment> \\<open>x or y do not point into any block, i.e. is an invalid location\\<close>\n  from_block x' B = None \\<or> from_block y' B = None \\<or>\n  \\<comment> \\<open>The size is too big, i.e. we would read/write out of bounds\\<close>\n  x'+z' > ende B x' \\<or> y'+z' > ende B y' \\<or>\n  \\<comment> \\<open>The two memory portions (pointer+size) overlap\\<close>\n  intv (x'+z') (bounds (raw_blocks B) y') \\<or> intv (y'+z') (bounds (raw_blocks B) x')\\<rbrakk> \n  \\<Longrightarrow> semantics (S,B,M) (Memcpy x y z) None\"\n| MemcpySuccess: \"\\<lbrakk>y'=loc64_ops.from_val (lookup S y); z'=loc64_ops.from_val (lookup S z);\n  from_block x' B \\<noteq> None; from_block y' B \\<noteq> None; x'+z' \\<le> ende B x'; y'+z' \\<le> ende B y';\n  \\<not>(intv (x'+z') (bounds (raw_blocks B) y')); \\<not>(intv (y'+z') (bounds (raw_blocks B) x'));\n  access M y' (unat z') = Some v\\<rbrakk>\n  \\<Longrightarrow> semantics (S,B,M) (Memcpy x y z) (Some (S,B,update_memory M x' v))\"\n| \"eval_cond c (lookup S x) (lookup S y) \\<Longrightarrow> semantics (S,B,M) (Assume c x y) (Some (S,B,M))\"\n| AssertError: \"\\<not> eval_cond c (lookup S x) (lookup S y) \\<Longrightarrow> semantics (S,B,M) (Assert c x y) None\"\n| AssertSuccess: \"eval_cond c (lookup S x) (lookup S y) \\<Longrightarrow> semantics (S,B,M) (Assert c x y) (Some (S,B,M))\"\n| \"\\<lbrakk>distinct args; length args = length params; list_all2 (\\<lambda>a p. size a = size p) args params;\n  fun_semantics f (Stack (bind_args_to_params (lookup S) params args),B,M) (S',B',M')\\<rbrakk>\n  \\<Longrightarrow> semantics (S,B,M) (Call (f,params) args) \n    (Some (Stack (bind_args_to_params (lookup S') args params),B',M'))\"\nend\n\nabbreviation program_semantics :: \"prog \\<Rightarrow> pre_config \\<Rightarrow> bool\" where\n  \"program_semantics program post \\<equiv> fun_semantics program ''main'' initial post\"\n\nlift_definition program_semantics_config :: \"prog \\<Rightarrow> config \\<Rightarrow> bool\" is\n  \"program_semantics\" .\n\nabbreviation all_blocks_alloc :: \"block list \\<Rightarrow> memory \\<Rightarrow> bool\" where\n  \"all_blocks_alloc B M \\<equiv> list_all (\\<lambda>(n,l,u). \\<forall>x. intv x (l,u) \\<longrightarrow> M x \\<noteq> None) B\"\n\nlift_definition blocks_alloc :: \"blocks \\<Rightarrow> memory \\<Rightarrow> bool\" is all_blocks_alloc .\n\nabbreviation config_blocks_alloc :: \"pre_config \\<Rightarrow> bool\" where\n  \"config_blocks_alloc \\<equiv> \\<lambda>(_,B,M). blocks_alloc B M\"\n\nlemma assumes \"config_blocks_alloc pre\"\n  shows \"(semantics pr pre cmd (Some post) \\<longrightarrow> config_blocks_alloc post) \\<and>\n    (fun_semantics pr f pre post \\<longrightarrow> config_blocks_alloc post) \\<and>\n    (cfg_reachable pr es from to pre post \\<longrightarrow> config_blocks_alloc post)\"\nproof (induction rule: semantics_fun_semantics_cfg_reachable.induct)\n  case (SingleStep \"from\" to es pre cmd post)\n  then show ?case sorry\nnext\n  case (MultiStep \"from\" to' es pre cmd interm to post)\n  then show ?case sorry\nnext\n  case (LoadFail B S y x M)\n  then show ?case sorry\nnext\n  case (LoadSuccess B S y x M v)\n  then show ?case sorry\nnext\n  case (StoreFail B S x y M)\n  then show ?case sorry\nnext\n  case (StoreSuccess B S x y M)\n  then show ?case sorry\nnext\n  case (MallocError S z x uu uv)\n  then show ?case sorry\nnext\n  case (MallocSuccessNull S z x B M)\n  then show ?case sorry\nnext\n  case (MallocSuccess S z x B l n k M)\n  then show ?case sorry\nnext\n  case (FreeError S x B uw)\n  then show ?case sorry\nnext\n  case (FreeSuccess S x y B M)\n  then show ?case sorry\nnext\n  case (PtrPlusError y' S y z' z B M ux)\n  then show ?case sorry\nnext\n  case (PtrPlusSuccess y' S y z' z B M x)\n  then show ?case sorry\nnext\n  case (PtrSubError y' S y z' z B M uy)\n  then show ?case sorry\nnext\n  case (PtrSubSuccess y' S y z' z B M x)\n  then show ?case sorry\nnext\n  case (MemcpyError y' S y z' z x' x B M)\n  then show ?case sorry\nnext\n  case (MemcpySuccess y' S y z' z x' B M v x)\n  then show ?case sorry\nnext\n  case (AssertError c S x y B M)\n  then show ?case sorry\nnext\n  case (AssertSuccess c S x y B M)\n  then show ?case sorry\nqed oops\n\nlemma assumes \"config_def pre\"\n  shows \"(semantics pr pre cmd (Some post) \\<longrightarrow> config_def post) \\<and>\n    (fun_semantics pr f pre post \\<longrightarrow> config_def post) \\<and>\n    (cfg_reachable pr es from to pre post \\<longrightarrow> config_def post)\"\nproof (induction rule: semantics_fun_semantics_cfg_reachable.induct)\n  case (SingleStep \"from\" to es pre cmd post')\n  then show ?case sorry\nnext\n  case (MultiStep \"from\" to' es pre cmd interm to post)\n  then show ?case sorry\nnext\n  case (LoadFail B S y x M)\n  then show ?case sorry\nnext\n  case (LoadSuccess B S y x M v)\n  then show ?case sorry\nnext\n  case (StoreFail B S x y M)\n  then show ?case sorry\nnext\n  case (StoreSuccess B S x y M)\n  then show ?case sorry\nnext\n  case (MallocError S z x uu uv)\n  then show ?case sorry\nnext\n  case (MallocSuccessNull S z x B M)\n  then show ?case sorry\nnext\n  case (MallocSuccess S z x B l n k M)\n  then show ?case sorry\nnext\n  case (FreeError S x B uw)\n  then show ?case sorry\nnext\n  case (FreeSuccess S x y B M)\n  then show ?case sorry\nnext\n  case (PtrPlusError y' S y z' z B M ux)\n  then show ?case sorry\nnext\n  case (PtrPlusSuccess y' S y z' z B M x)\n  then show ?case sorry\nnext\n  case (PtrSubError y' S y z' z B M uy)\n  then show ?case sorry\nnext\n  case (PtrSubSuccess y' S y z' z B M x)\n  then show ?case sorry\nnext\n  case (MemcpyError y' S y z' z x' x B M)\n  then show ?case sorry\nnext\n  case (MemcpySuccess y' S y z' z x' B M v x)\n  then show ?case sorry\nnext\n  case (AssertError c S x y B M)\n  then show ?case sorry\nnext\n  case (AssertSuccess c S x y B M)\n  then show ?case sorry\nqed oops\n\nend", "meta": {"author": "firefighterduck", "repo": "isabroom", "sha": "f260dfab2f1f6854986d3c337e3d00ab7728aa26", "save_path": "github-repos/isabelle/firefighterduck-isabroom", "path": "github-repos/isabelle/firefighterduck-isabroom/isabroom-f260dfab2f1f6854986d3c337e3d00ab7728aa26/Semantics.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6723316991792861, "lm_q2_score": 0.4225046348141882, "lm_q1q2_score": 0.2840632590357469}}
{"text": "theory Leadsto_Map\n  imports Leadsto Unified_PW_Hashing Liveness_Subsumption_Map Heap_Hash_Map Next_Key\nbegin\n\ndefinition map_to_set :: \"('b \\<rightharpoonup> 'a set) \\<Rightarrow> 'a set\" where\n  \"map_to_set m = (\\<Union> (ran m))\"\n\nhide_const wait\n\ndefinition\n  \"map_list_set_rel =\n    {(ml, ms). dom ml = dom ms\n     \\<and> (\\<forall> k \\<in> dom ms. set (the (ml k)) = the (ms k) \\<and> distinct (the (ml k)))\n     \\<and> finite (dom ml)\n    }\"\n\ncontext Worklist_Map2_Defs\nbegin\n\ndefinition\n  \"add_pw'_map3 passed wait a \\<equiv>\n   nfoldli (succs a) (\\<lambda>(_, _, brk). \\<not>brk)\n    (\\<lambda>a (passed, wait, _).\n      do {\n      RETURN (\n        if empty a then\n            (passed, wait, False)\n        else if F' a then (passed, wait, True)\n        else\n          let k = key a; passed' = (case passed k of Some passed' \\<Rightarrow> passed' | None \\<Rightarrow> [])\n          in\n            if \\<exists> x \\<in> set passed'. a \\<unlhd> x then\n              (passed, wait, False)\n            else\n              (passed(k \\<mapsto> (a # passed')), a # wait, False)\n        )\n      }\n    )\n    (passed,wait,False)\"\n\ndefinition\n  \"pw_map_inv3 \\<equiv> \\<lambda> (passed, wait, brk).\n    \\<exists> passed'. (passed, passed') \\<in> map_list_set_rel \\<and> pw_map_inv (passed', wait, brk)\n  \"\n\ndefinition pw_algo_map3 where\n  \"pw_algo_map3 = do\n    {\n      if F a\\<^sub>0 then RETURN (True, Map.empty)\n      else if empty a\\<^sub>0 then RETURN (False, Map.empty)\n      else do {\n        (passed, wait) \\<leftarrow> RETURN ([key a\\<^sub>0 \\<mapsto> [a\\<^sub>0]], [a\\<^sub>0]);\n        (passed, wait, brk) \\<leftarrow> WHILEIT pw_map_inv3 (\\<lambda> (passed, wait, brk). \\<not> brk \\<and> wait \\<noteq> [])\n          (\\<lambda> (passed, wait, brk). do\n            {\n              (a, wait) \\<leftarrow> take_from_list wait;\n              ASSERT (reachable a);\n              if empty a then RETURN (passed, wait, brk) else add_pw'_map3 passed wait a\n            }\n          )\n          (passed, wait, False);\n          RETURN (brk, passed)\n      }\n    }\n  \"\n\nend \\<comment> \\<open>Worklist Map 2 Defs\\<close>\n\nlemma map_list_set_rel_empty[refine, simp, intro]:\n  \"(Map.empty, Map.empty) \\<in> map_list_set_rel\"\n  unfolding map_list_set_rel_def by auto\n\nlemma map_list_set_rel_single:\n  \"(ml(key a\\<^sub>0 \\<mapsto> [a\\<^sub>0]), ms(key a\\<^sub>0 \\<mapsto> {a\\<^sub>0})) \\<in> map_list_set_rel\" if \"(ml, ms) \\<in> map_list_set_rel\"\n  using that unfolding map_list_set_rel_def by auto\n\ncontext Worklist_Map2\nbegin\n\nlemma refine_start[refine]:\n  \"(([key a\\<^sub>0 \\<mapsto> [a\\<^sub>0]], [a\\<^sub>0]), [key a\\<^sub>0 \\<mapsto> {a\\<^sub>0}], [a\\<^sub>0]) \\<in> map_list_set_rel \\<times>\\<^sub>r Id\"\n  by (simp add: map_list_set_rel_single)\n\nlemma pw_map_inv_ref:\n  \"pw_map_inv (x1, x2, x3) \\<Longrightarrow> (x1a, x1) \\<in> map_list_set_rel \\<Longrightarrow> pw_map_inv3 (x1a, x2, x3)\"\n  unfolding pw_map_inv3_def by auto\n\nlemma refine_aux[refine]:\n  \"(x1, x) \\<in> map_list_set_rel \\<Longrightarrow> ((x1, x2, False), x, x2, False) \\<in> map_list_set_rel \\<times>\\<^sub>r Id \\<times>\\<^sub>r Id\"\n  by simp\n\nlemma map_list_set_relD:\n  \"ms k = Some (set xs)\" if \"(ml, ms) \\<in> map_list_set_rel\" \"ml k = Some xs\"\n  using that unfolding map_list_set_rel_def\n  by clarsimp (metis (mono_tags, lifting) domD domI option.sel)\n\nlemma map_list_set_rel_distinct:\n  \"distinct xs\" if \"(ml, ms) \\<in> map_list_set_rel\" \"ml k = Some xs\"\n  using that unfolding map_list_set_rel_def by clarsimp (metis domI option.sel)\n\nlemma map_list_set_rel_NoneD1[dest, intro]:\n  \"ms k = None\" if \"(ml, ms) \\<in> map_list_set_rel\" \"ml k = None\"\n  using that unfolding map_list_set_rel_def by auto\n\nlemma map_list_set_rel_NoneD2[dest, intro]:\n  \"ml k = None\" if \"(ml, ms) \\<in> map_list_set_rel\" \"ms k = None\"\n  using that unfolding map_list_set_rel_def by auto\n\nlemma map_list_set_rel_insert:\n  \"(ml, ms) \\<in> map_list_set_rel \\<Longrightarrow>\n   ml (key a) = Some xs \\<Longrightarrow>\n   ms (key a) = Some (set xs) \\<Longrightarrow>\n   a \\<notin> set xs \\<Longrightarrow>\n   (ml(key a \\<mapsto> a # xs), ms(key a \\<mapsto> insert a (set xs))) \\<in> map_list_set_rel\"\n  apply (frule map_list_set_rel_distinct) unfolding map_list_set_rel_def by auto\n\nlemma add_pw'_map3_ref:\n  \"add_pw'_map3 ml xs a \\<le> \\<Down> (map_list_set_rel \\<times>\\<^sub>r Id) (add_pw'_map2 ms xs a)\"\n  if \"(ml, ms) \\<in> map_list_set_rel\" \"\\<not> empty a\"\n  using that unfolding add_pw'_map3_def add_pw'_map2_def\n  apply refine_rcg\n     apply refine_dref_type\n     apply (simp; fail)\n    apply (simp; fail)\n   apply (simp; fail)\n  apply (clarsimp simp: Let_def)\n  apply safe\n  subgoal\n    by (auto dest: map_list_set_relD[OF _ sym])\n  subgoal\n    apply (auto split: option.split_asm)\n    by (metis (mono_tags, lifting)\n          map_list_set_relD map_list_set_rel_NoneD1 option.collapse option.sel option.simps(3)\n        )\n  subgoal premises prems for a ms x2a ml x2c\n  proof (cases \"ml (key a)\")\n    case None\n    with \\<open>(ml, ms) \\<in> map_list_set_rel\\<close> have \"ms (key a) = None\"\n      by auto\n    with None \\<open>(ml, ms) \\<in> map_list_set_rel\\<close> show ?thesis\n      by (auto intro: map_list_set_rel_single)\n  next\n    case (Some xs)\n    from map_list_set_relD[OF \\<open>(ml, ms) \\<in> map_list_set_rel\\<close> \\<open>ml _ = _\\<close>] have\n      \"ms (key a) = Some (set xs)\"\n      by auto\n    moreover from prems have \"a \\<notin> set xs\"\n      by (metis Some empty_subsumes' local.eq_refl)\n    ultimately show ?thesis\n      using Some \\<open>(ml, ms) \\<in> map_list_set_rel\\<close> by (auto intro: map_list_set_rel_insert)\n  qed\n  done\n\nlemma pw_algo_map3_ref[refine]:\n  \"pw_algo_map3 \\<le> \\<Down> (Id \\<times>\\<^sub>r map_list_set_rel) pw_algo_map2\"\n  unfolding pw_algo_map3_def pw_algo_map2_def\n  apply refine_rcg\n              apply refine_dref_type\n              apply (simp; fail)+\n          apply (clarsimp, rule refine_aux; assumption)\n  by (auto intro: add_pw'_map3_ref pw_map_inv_ref)\n\nlemma pw_algo_map2_ref':\n  \"pw_algo_map2 \\<le> \\<Down> (bool_rel \\<times>\\<^sub>r map_set_rel) pw_algo\"\nproof -\n  note pw_algo_map2_ref\n  also note pw_algo_map_ref\n  also note pw_algo_unified_ref\n  finally show ?thesis .\nqed\n\nlemma pw_algo_map3_ref'[refine]:\n  \"pw_algo_map3 \\<le> \\<Down> (bool_rel \\<times>\\<^sub>r (map_list_set_rel O map_set_rel)) pw_algo\"\nproof -\n  have [simp]:\n    \"((bool_rel \\<times>\\<^sub>r map_list_set_rel) O (bool_rel \\<times>\\<^sub>r map_set_rel))\n    = (bool_rel \\<times>\\<^sub>r (map_list_set_rel O map_set_rel))\"\n    unfolding relcomp_def prod_rel_def by auto\n  note pw_algo_map3_ref\n  also note pw_algo_map2_ref'\n  finally show ?thesis\n    by (simp add: conc_fun_chain)\nqed\n\nend \\<comment> \\<open>Worklist Map 2 Defs\\<close>\n\nlemma (in Worklist_Map2_finite) map_set_rel_finite_domI[intro]:\n  \"finite (dom m)\" if \"(m, S) \\<in> map_set_rel\"\n  using that unfolding map_set_rel_def by auto\n\nlemma (in Worklist_Map2_finite) map_set_rel_finiteI:\n  \"finite S\" if \"(m, S) \\<in> map_set_rel\"\n  using that unfolding map_set_rel_def\n  apply clarsimp\n  apply (rule finite_Union)\n   apply (auto intro: map_dom_ran_finite; fail)\n  apply (auto simp: ran_def; fail)\n  done\n\nlemma (in Worklist_Map2_finite) map_set_rel_finite_ranI[intro]:\n  \"finite S'\" if \"(m, S) \\<in> map_set_rel\" \"S' \\<in> ran m\"\n  using that unfolding map_set_rel_def ran_def by auto\n\nlocale Leadsto_Search_Space_Key =\n  A: Worklist_Map2 _ _ _ _ _ _ _ succs1 +\n  Leadsto_Search_Space for succs1\nbegin\n\nsublocale A': Worklist_Map2_finite a\\<^sub>0 \"\\<lambda> _. False\" \"(\\<preceq>)\" empty \"(\\<unlhd>)\" E key succs1 \"\\<lambda> _. False\"\n  by (standard; blast intro!: A.succs_correct)\n\ninterpretation B:\n  Liveness_Search_Space_Key\n  \"\\<lambda> x y. E x y \\<and> Q y \\<and> \\<not> empty y\" a\\<^sub>0 \"\\<lambda> _. False\" \"(\\<preceq>)\" \"\\<lambda> x. A.reachable x \\<and> \\<not> empty x\"\n  succs_Q key\n  by standard (auto intro!: A.empty_subsumes')\n\ncontext\n  fixes a\\<^sub>1 :: 'a\nbegin\n\ninterpretation B':\n  Liveness_Search_Space_Key_Defs\n  a\\<^sub>1 \"\\<lambda> _. False\" \"(\\<preceq>)\" \"\\<lambda> x. A.reachable x \\<and> \\<not> empty x\"\n  succs_Q \"\\<lambda> x y. E x y \\<and> Q y \\<and> \\<not> empty y\" key .\n\ndefinition has_cycle_map where\n  \"has_cycle_map = B'.dfs_map\"\n\ncontext\n  assumes \"A.reachable a\\<^sub>1\"\nbegin\n\ninterpretation B':\n  Liveness_Search_Space_Key\n  \"\\<lambda> x y. E x y \\<and> Q y \\<and> \\<not> empty y\" a\\<^sub>1 \"\\<lambda> _. False\" \"(\\<preceq>)\" \"\\<lambda> x. A.reachable x \\<and> \\<not> empty x\"\n  succs_Q key\n  by standard\n\nlemmas has_cycle_map_ref[refine] = B'.dfs_map_dfs_refine[folded has_cycle_map_def has_cycle_def]\n\nend (* Reachability assumption *)\n\nend (* Second start state *)\n\ndefinition outer_inv where\n  \"outer_inv passed done todo \\<equiv> \\<lambda> (r, passed').\n    (r \\<longrightarrow> (\\<exists> a. A.reachable a \\<and> \\<not> empty a \\<and> P a \\<and> Q a \\<and> reaches_cycle a))\n     \\<and> (\\<not> r \\<longrightarrow>\n          (\\<forall> a \\<in> \\<Union> done. P a \\<and> Q a \\<longrightarrow> \\<not> reaches_cycle a)\n         \\<and> B.liveness_compatible passed'\n         \\<and> passed' \\<subseteq> {x. A.reachable x \\<and> \\<not> empty x}\n       )\n  \"\n\ndefinition inner_inv where\n  \"inner_inv passed done todo \\<equiv> \\<lambda> (r, passed').\n    (r \\<longrightarrow> (\\<exists> a. A.reachable a \\<and> \\<not> empty a \\<and> P a \\<and> Q a \\<and> reaches_cycle a))\n     \\<and> (\\<not> r \\<longrightarrow>\n          (\\<forall> a \\<in> done. P a \\<and> Q a \\<longrightarrow> \\<not> reaches_cycle a)\n         \\<and> B.liveness_compatible passed'\n         \\<and> passed' \\<subseteq> {x. A.reachable x \\<and> \\<not> empty x}\n       )\n  \"\n\ndefinition leadsto' :: \"bool nres\" where\n  \"leadsto' = do {\n    (r, passed) \\<leftarrow> A'.pw_algo_map2;\n    let passed = ran passed;\n    (r, _) \\<leftarrow> FOREACHcdi (outer_inv passed) passed (\\<lambda>(b,_). \\<not>b)\n      (\\<lambda> passed' (_,acc).\n          FOREACHcdi (inner_inv acc) passed' (\\<lambda>(b,_). \\<not>b)\n            (\\<lambda>v' (_,passed).\n              do {\n                ASSERT(A.reachable v' \\<and> \\<not> empty v');\n                if P v' \\<and> Q v' then has_cycle v' passed else RETURN (False, passed)\n              }\n            )\n            (False, acc)\n      )\n      (False, {});\n    RETURN r\n  }\"\n\nlemma leadsto'_correct:\n  \"leadsto' \\<le> leadsto_spec\"\nproof -\n  define inv where\n    \"inv \\<equiv> \\<lambda> passed it (r, passed').\n       (r \\<longrightarrow> (\\<exists> a. A.reachable a \\<and> \\<not> empty a \\<and> P a \\<and> Q a \\<and> reaches_cycle a))\n     \\<and> (\\<not> r \\<longrightarrow>\n          (\\<forall> a \\<in> passed - it. \\<not> reaches_cycle a)\n         \\<and> B.liveness_compatible passed'\n         \\<and> passed' \\<subseteq> {x. A.reachable x \\<and> \\<not> empty x}\n       )\n    \"\n\n  have [simp, intro]:\n    \"\\<not> A'.F_reachable\"\n    unfolding A'.F_reachable_def by simp\n\n  have B_reaches_empty:\n    \"\\<not> empty b\" if \"\\<not> empty a\" \"B.reaches a b\" for a b\n    using that(2,1)by induction auto\n\n  interpret Subgraph_Start E a\\<^sub>0 \"\\<lambda> a x. E a x \\<and> Q x \\<and> \\<not> empty x\"\n    by standard auto\n\n  have B_A_reaches:\n    \"A.reaches a b\" if \"B.reaches a b\" for a b\n    using that by (rule reaches)\n\n  have reaches_iff: \"B.reaches a x \\<longleftrightarrow> B.G.G'.reaches a x\"\n    if \"A.reachable a\" \"\\<not> empty a\" for a x\n    unfolding reaches_cycle_def\n    apply standard\n    using that\n      apply (rotate_tac 3)\n     apply (induction rule: rtranclp.induct)\n      apply blast\n     apply rule\n      apply assumption\n     apply (subst B.G.E'_def)\n    subgoal for a b c\n      by (auto dest: B_reaches_empty)\n    subgoal\n      by (rule B.G.reaches)\n    done\n\n  have reaches1_iff: \"B.reaches1 a x \\<longleftrightarrow> B.G.G'.reaches1 a x\"\n    if \"A.reachable a\" \"\\<not> empty a\" for a x\n    unfolding reaches_cycle_def\n    apply standard\n    subgoal\n      using that\n        apply (rotate_tac 3)\n      apply (induction rule: tranclp.induct)\n       apply (rule tranclp.intros(1), auto simp: B.G.E'_def; fail)\n      apply (\n          rule tranclp.intros(2);\n          auto 4 3 simp: B.G.E'_def dest:B_reaches_empty tranclp_into_rtranclp\n          )\n      done\n    subgoal\n      by (rule B.G.reaches1)\n    done\n\n  have reaches_cycle_iff: \"reaches_cycle a \\<longleftrightarrow> (\\<exists>x. B.G.G'.reaches a x \\<and> B.G.G'.reaches1 x x)\"\n    if \"A.reachable a\" \"\\<not> empty a\" for a\n    unfolding reaches_cycle_def\n    apply (subst reaches_iff[OF that])\n    using reaches1_iff B.G.G'_reaches_V that by blast\n\n  have aux1:\n    \"\\<not> reaches_cycle x\"\n    if\n      \"\\<forall>a. A.reachable a \\<and> \\<not> empty a \\<longrightarrow> (\\<exists>x\\<in>passed. a \\<preceq> x)\"\n      \"passed \\<subseteq> {a. A.reachable a \\<and> \\<not> empty a}\"\n      \"\\<forall> y \\<in> ran passed'. \\<forall> x \\<in> y. P x \\<and> Q x \\<longrightarrow> \\<not> reaches_cycle x\"\n      \"A.reachable x\" \"\\<not> empty x\" \"P x\" \"Q x\"\n      \"(passed', passed) \\<in> A'.map_set_rel\"\n    for x passed passed'\n  proof (rule ccontr, simp)\n    assume \"reaches_cycle x\"\n    from that obtain x' where x':\"x' \\<in> passed\" \"x \\<preceq> x'\"\n      by auto\n    with \\<open>(_, _) \\<in> _\\<close> obtain y where y: \"y \\<in> ran passed'\" \"x' \\<in> y\"\n      unfolding A'.map_set_rel_def by auto\n    from x' that have \"P x'\" \"Q x'\"\n      by (auto intro: P_mono Q_mono)\n    with \\<open>x' \\<in> passed\\<close> that(3) y have \"\\<not> reaches_cycle x'\"\n      by auto\n    have \"A.reachable x'\" \"\\<not> empty x'\"\n      using \\<open>x' \\<in> passed\\<close> that(2) A.empty_mono \\<open>x \\<preceq> x'\\<close> that(5) by auto\n    note reaches_cycle_iff' = reaches_cycle_iff[OF this] reaches_iff[OF this] reaches1_iff[OF this]\n    from \\<open>reaches_cycle x\\<close> guess y unfolding reaches_cycle_def\n      by safe\n    interpret\n      Subsumption_Graph_Pre_Nodes\n        \"(\\<preceq>)\" A.subsumes_strictly \"\\<lambda> x y. E x y \\<and> Q y \\<and> \\<not> empty y\"\n        \"\\<lambda> x. A.reachable x \\<and> \\<not> empty x\"\n      by standard (rule B.mono[simplified]; assumption)\n    from \\<open>B.reaches x y\\<close> \\<open>x \\<preceq> x'\\<close> \\<open>B.reaches1 y y\\<close> reaches_cycle_mono[OF B.finite_V] obtain y' where\n      \"y \\<preceq> y'\" \"B.G.G'.reaches x' y'\" \"B.G.G'.reaches1 y' y'\"\n      apply atomize_elim\n      apply (subst (asm) reaches_iff[rotated 2])\n        defer\n        defer\n        apply (subst (asm) reaches1_iff)\n          defer\n          defer\n      using \\<open>A.reachable x\\<close> \\<open>\\<not> empty x\\<close> \\<open>A.reachable x'\\<close> \\<open>\\<not> empty x'\\<close> \\<open>B.reaches1 y y\\<close>\n      by (auto simp: B.reaches1_reaches_iff2 dest!: B.G.G'_reaches_V)\n    with \\<open>A.reachable x'\\<close> \\<open>\\<not> empty x'\\<close> have \"reaches_cycle x'\"\n      unfolding reaches_cycle_iff'\n      by auto\n    with \\<open>\\<not> reaches_cycle x'\\<close> show False ..\n  qed\n\n  note [refine_vcg] = A'.pw_algo_map2_correct[THEN order.trans]\n\n  show ?thesis\n    unfolding leadsto'_def leadsto_spec_def\n    apply (refine_rcg refine_vcg)\n\n      (* Input is finite 1 *)\n    subgoal\n      by (auto intro: map_dom_ran_finite)\n\n      (* Outer invariant holds initially *)\n      subgoal\n        unfolding outer_inv_def B.liveness_compatible_def by simp\n\n      (* Input is finite 2 *)\n      subgoal\n        by auto\n\n      (* Inner invariant holds initially *)\n      subgoal for x a b S1 S2 todo \\<sigma> aa passed\n        unfolding inner_inv_def outer_inv_def by simp\n\n      (* Assertion *)\n      subgoal\n        unfolding inner_inv_def outer_inv_def A'.map_set_rel_def by auto\n\n      (* Assertion *)\n      subgoal\n        unfolding inner_inv_def outer_inv_def A'.map_set_rel_def by auto\n\n      (* Inner invariant is preserved *)\n      subgoal for _ _ b S1 S2 xa \\<sigma> aa passed S1' S2' a\\<^sub>1 \\<sigma>' ab passed'\n        unfolding outer_inv_def\n        apply clarsimp\n        subgoal premises prems for p\n        proof -\n          from prems have \"a\\<^sub>1 \\<in> p\"\n            unfolding A'.map_set_rel_def by auto\n          with \\<open>passed \\<subseteq> _\\<close> \\<open>p \\<subseteq> _\\<close> have \"A.reachable a\\<^sub>1\"\n            by auto\n          interpret B':\n            Liveness_Search_Space\n            \"\\<lambda> x y. E x y \\<and> Q y \\<and> \\<not> empty y\" a\\<^sub>1 \"\\<lambda> _. False\" \"(\\<preceq>)\"\n            \"\\<lambda> x. A.reachable x \\<and> \\<not> empty x\" succs_Q\n            by standard\n          from \\<open>inner_inv _ _ _ _\\<close> have\n            \"B'.liveness_compatible passed'\" \"passed' \\<subseteq> {x. A.reachable x \\<and> \\<not> empty x}\"\n            unfolding inner_inv_def by auto\n          from B'.dfs_correct[OF _ this] \\<open>passed \\<subseteq> _\\<close> \\<open>a\\<^sub>1 \\<in> _\\<close> \\<open>p \\<subseteq> _\\<close> have\n            \"B'.dfs passed' \\<le> B'.dfs_spec\"\n            by auto\n          then show ?thesis\n            unfolding has_cycle_def\n            apply (rule order.trans)\n            unfolding B'.dfs_spec_def\n            apply clarsimp\n            subgoal for r passed1\n              apply (cases r)\n               apply simp\n              subgoal\n                unfolding inner_inv_def\n                using \\<open>passed \\<subseteq> _\\<close> \\<open>a\\<^sub>1 \\<in> _\\<close> \\<open>p \\<subseteq> _\\<close>\n                apply simp\n                apply (inst_existentials a\\<^sub>1)\n                by (auto 4 3 simp: reaches_cycle_iff intro: prems)\n              subgoal\n                using \\<open>inner_inv _ _ _ _\\<close> \\<open>passed \\<subseteq> _\\<close> \\<open>a\\<^sub>1 \\<in> _\\<close> \\<open>p \\<subseteq> _\\<close> reaches_cycle_iff\n                unfolding inner_inv_def by auto\n                done\n              done\n          qed\n          done\n\n          (* Current state filtered out *)\n          subgoal for x a b S1 S2 xa \\<sigma> aa ba S1a S2a xb \\<sigma>' ab bb\n            unfolding inner_inv_def by auto\n\n          (* Break \\<and> inner inv \\<longrightarrow> outer inv *)\n          subgoal for x a b S1 S2 xa \\<sigma> aa ba S1a S2a \\<sigma>'\n            unfolding inner_inv_def outer_inv_def by auto\n\n          (* \\<not> Break \\<and> inner inv \\<longrightarrow> outer inv *)\n          subgoal for x a b S1 S2 xa \\<sigma> aa ba \\<sigma>'\n            unfolding inner_inv_def outer_inv_def by auto\n\n          (* Break \\<and> outer inv \\<longrightarrow> cycle *)\n          subgoal for x a b S1 S2 \\<sigma> aa ba\n            unfolding outer_inv_def by auto\n\n          (* \\<not> Break \\<and> outer inv \\<longrightarrow> cycle *)\n          (* I \\<and> \\<not> b \\<longrightarrow> post *)\n          subgoal for x a b \\<sigma> aa ba\n            unfolding outer_inv_def by (auto dest!: aux1)\n\n          done\n      qed\n\nlemma init_ref[refine]:\n  \"((False, Map.empty), False, {}) \\<in> bool_rel \\<times>\\<^sub>r A'.map_set_rel\"\n  unfolding A'.map_set_rel_def by auto\n\nlemma map_set_rel_id:\n  \"Liveness_Search_Space_Key.map_set_rel key = A'.map_set_rel\"\n  unfolding A'.map_set_rel_def B.map_set_rel_def ..\n\nlemma has_cycle_map_ref'[refine]:\n  assumes \"(P1, P1') \\<in> A'.map_set_rel\" \"(a, a') \\<in> Id\" \"A.reachable a\" \"\\<not> empty a\"\n  shows \"has_cycle_map a P1 \\<le> \\<Down> (bool_rel \\<times>\\<^sub>r A'.map_set_rel) (has_cycle a' P1')\"\n  using has_cycle_map_ref assms by (auto simp: map_set_rel_id)\n\ndefinition leadsto_map3' :: \"bool nres\" where\n  \"leadsto_map3' = do {\n    (r, passed) \\<leftarrow> A'.pw_algo_map2;\n    let passed = ran passed;\n    (r, _) \\<leftarrow> FOREACHcd passed (\\<lambda>(b,_). \\<not>b)\n      (\\<lambda> passed' (_,acc).\n        do {\n          passed' \\<leftarrow> SPEC (\\<lambda>l. set l = passed');\n          nfoldli passed' (\\<lambda>(b,_). \\<not>b)\n            (\\<lambda>v' (_,passed).\n              if P v' \\<and> Q v' then has_cycle_map v' passed else RETURN (False, passed)\n            )\n            (False, acc)\n        }\n      )\n      (False, Map.empty);\n    RETURN r\n  }\"\n\ndefinition \"pw_algo_map2_copy = A'.pw_algo_map2\"\n\nlemma [refine]:\n  \"A'.pw_algo_map2 \\<le>\n    \\<Down> (br id (\\<lambda> (_, m). finite (dom m) \\<and> (\\<forall> k S. m k = Some S \\<longrightarrow> finite S))) pw_algo_map2_copy\"\nproof -\n  have [refine]:\n    \"(x, x') \\<in> Id \\<Longrightarrow>\n     x' = (x1, x2) \\<Longrightarrow>\n     x = (x1a, x2a) \\<Longrightarrow>\n     A'.pw_map_inv (x1, x2, False)\n    \\<Longrightarrow> ((x1a, x2a, False), x1, x2, False) \\<in>\n        (br id (\\<lambda> m. finite (dom m) \\<and> (\\<forall> k S. m k = Some S \\<longrightarrow> finite S))) \\<times>\\<^sub>r Id \\<times>\\<^sub>r Id\"\n    for x x' x1 x2 x1a x2a\n    by (auto simp: br_def A'.pw_map_inv_def A'.map_set_rel_def)\n  show ?thesis\n    unfolding pw_algo_map2_copy_def\n    unfolding A'.pw_algo_map2_def\n    apply refine_rcg\n                  apply refine_dref_type\n                  prefer 5\n                  apply assumption\n                 apply (assumption | (simp add: br_def; fail) | (auto simp: br_def; fail))+\n    subgoal\n      apply (clarsimp simp: br_def)\n      subgoal premises prems\n        using \\<open>finite _\\<close> \\<open>\\<forall>k S. _ \\<longrightarrow> finite _\\<close>\n        unfolding A'.add_pw'_map2_def\n        apply refine_rcg\n           apply refine_dref_type\n           apply (auto simp: Let_def split!: option.split)\n        done\n      done\n    by (simp add: br_def)\nqed\n\nlemma leadsto_map3'_ref[refine]:\n  \"leadsto_map3' \\<le> \\<Down> Id leadsto'\"\n  unfolding leadsto_map3'_def leadsto'_def\n  apply (subst (2) pw_algo_map2_copy_def[symmetric])\n  apply (subst (2) FOREACHcdi_def)\n  apply (subst (2) FOREACHcd_def)\n  apply refine_rcg\n               apply refine_dref_type\n  by (auto simp: br_def intro: map_dom_ran_finite)\n\ndefinition leadsto_map3 :: \"bool nres\" where\n  \"leadsto_map3 = do {\n    (r, passed) \\<leftarrow> A'.pw_algo_map3;\n    let passed = ran passed;\n    (r, _) \\<leftarrow> FOREACHcd passed (\\<lambda>(b,_). \\<not>b)\n      (\\<lambda> passed' (_,acc).\n          nfoldli passed' (\\<lambda>(b,_). \\<not>b)\n            (\\<lambda>v' (_,passed).\n              if P v' \\<and> Q v' then has_cycle_map v' passed else RETURN (False, passed)\n            )\n            (False, acc)\n      )\n      (False, Map.empty);\n    RETURN r\n  }\"\n\nlemma start_ref:\n  \"((False, Map.empty), False, Map.empty) \\<in> Id \\<times>\\<^sub>r map_list_set_rel\"\n  by simp\n\nlemma map_list_set_rel_ran_set_rel:\n  \"(ran ml, ran ms) \\<in> \\<langle>br set (\\<lambda>_. True)\\<rangle>set_rel\" if \"(ml, ms) \\<in> map_list_set_rel\"\n  using that unfolding map_list_set_rel_def set_rel_def\n  apply safe\n  subgoal for x\n    by (auto simp: ran_def dom_def in_br_conv dest: A.map_list_set_relD[OF that])\n  subgoal premises prems for x'\n  proof -\n    from prems(4) obtain a where \"ms a = Some x'\"\n      unfolding ran_def by clarsimp\n    with prems(1) obtain m' where\n      \"ml a = Some (m' a)\"\n      by (fastforce simp: dom_def ran_def)\n    with prems(2) \\<open>ms a = _\\<close> show ?thesis\n      by (fastforce simp: in_br_conv dom_def ran_def)\n  qed\n  done\n\nlemma Id_list_rel_ref:\n  \"(x'a, x'a) \\<in> \\<langle>Id\\<rangle>list_rel\"\n  by simp\n\nlemma map_list_set_rel_finite_ran:\n  \"finite (ran ml)\" if \"(ml, ms) \\<in> map_list_set_rel\"\n  using that unfolding map_list_set_rel_def by (auto intro: map_dom_ran_finite)\n\nlemma leadsto_map3_ref[refine]:\n  \"leadsto_map3 \\<le> \\<Down> Id leadsto'\"\n  unfolding leadsto_map3_def leadsto'_def\n  apply (subst (2) FOREACHcdi_def)\n  apply (subst (2) FOREACHcd_def)\n  apply (refine_rcg map_list_set_rel_ran_set_rel map_list_set_rel_finite_ran)\n      prefer 4\n    apply (rule rhs_step_bind_SPEC)\n    apply (clarsimp simp: br_def; rule HOL.refl; fail)\n   apply (refine_rcg Id_list_rel_ref; simp; fail)\n   by auto\n\ndefinition leadsto_map4 :: \"bool nres\" where\n  \"leadsto_map4 = do {\n    (r, passed) \\<leftarrow> A'.pw_algo_map3;\n    ASSERT (finite (dom passed));\n    passed \\<leftarrow> ran_of_map passed;\n    (r, _) \\<leftarrow> nfoldli passed (\\<lambda>(b,_). \\<not>b)\n      (\\<lambda> passed' (_,acc).\n          nfoldli passed' (\\<lambda>(b,_). \\<not>b)\n            (\\<lambda>v' (_,passed).\n              if P v' \\<and> Q v' then has_cycle_map v' passed else RETURN (False, passed)\n            )\n            (False, acc)\n      )\n      (False, Map.empty);\n    RETURN r\n  }\"\n\nlemma ran_of_map_ref:\n  \"ran_of_map m \\<le> SPEC (\\<lambda>c. (c, ran m') \\<in> br set (\\<lambda> _. True))\" if \"finite (dom m)\" \"(m, m') \\<in> Id\"\n  using ran_of_map_correct[OF that(1)] that(2) unfolding br_def by (simp add: pw_le_iff)\n\nlemma aux_ref:\n  \"(xa, x'a) \\<in> Id \\<Longrightarrow>\n       x'a = (x1b, x2b) \\<Longrightarrow> xa = (x1c, x2c) \\<Longrightarrow> (x1c, x1b) \\<in> bool_rel\"\n  by simp\n\ndefinition \"foo = A'.pw_algo_map3\"\n\nlemma [refine]:\n  \"A'.pw_algo_map3 \\<le> \\<Down> (br id (\\<lambda> (_, m). finite (dom m))) foo\"\nproof -\n  have [refine]:\n    \"(x, x') \\<in> Id \\<Longrightarrow>\n     x' = (x1, x2) \\<Longrightarrow>\n     x = (x1a, x2a) \\<Longrightarrow>\n     A'.pw_map_inv3 (x1, x2, False)\n    \\<Longrightarrow> ((x1a, x2a, False), x1, x2, False) \\<in> (br id (\\<lambda> m. finite (dom m))) \\<times>\\<^sub>r Id \\<times>\\<^sub>r Id\"\n    for x x' x1 x2 x1a x2a\n    by (auto simp: br_def A'.pw_map_inv3_def map_list_set_rel_def)\n  show ?thesis\n    unfolding foo_def\n    unfolding A'.pw_algo_map3_def\n    apply refine_rcg\n                  apply refine_dref_type\n                  prefer 5\n                  apply assumption\n                 apply (assumption | (simp add: br_def; fail) | (auto simp: br_def; fail))+\n    subgoal\n      apply (clarsimp simp: br_def)\n      subgoal premises prems\n        using \\<open>finite _\\<close>\n        unfolding A'.add_pw'_map3_def\n        apply refine_rcg\n           apply refine_dref_type\n           apply (auto simp: Let_def)\n        done\n      done\n    by (simp add: br_def)\nqed\n\nlemma leadsto_map4_ref[refine]:\n  \"leadsto_map4 \\<le> \\<Down> Id leadsto_map3\"\n  unfolding leadsto_map4_def leadsto_map3_def FOREACHcd_def\n  apply (subst (2) foo_def[symmetric])\n  apply (refine_rcg ran_of_map_ref)\n     apply refine_dref_type\n     apply (simp add: br_def; fail)\n    apply (simp add: br_def; fail)\n   apply (rule rhs_step_bind_SPEC)\n  by (auto simp: br_def)\n\ndefinition leadsto_map4' :: \"bool nres\" where\n  \"leadsto_map4' = do {\n    (r, passed) \\<leftarrow> A'.pw_algo_map2;\n    ASSERT (finite (dom passed));\n    passed \\<leftarrow> ran_of_map passed;\n    (r, _) \\<leftarrow> nfoldli passed (\\<lambda>(b,_). \\<not>b)\n      (\\<lambda> passed' (_,acc).\n        do {\n          passed' \\<leftarrow> SPEC (\\<lambda>l. set l = passed');\n          nfoldli passed' (\\<lambda>(b,_). \\<not>b)\n            (\\<lambda>v' (_,passed).\n              if P v' \\<and> Q v' then has_cycle_map v' passed else RETURN (False, passed)\n            )\n            (False, acc)\n        }\n      )\n      (False, Map.empty);\n    RETURN r\n  }\"\n\nlemma leadsto_map4'_ref:\n  \"leadsto_map4' \\<le> \\<Down> Id leadsto_map3'\"\n  unfolding leadsto_map4'_def leadsto_map3'_def FOREACHcd_def\n  apply (subst (2) pw_algo_map2_copy_def[symmetric])\n  apply (refine_rcg ran_of_map_ref)\n     apply refine_dref_type\n     apply (simp add: br_def; fail)\n    apply (simp add: br_def; fail)\n   apply (rule rhs_step_bind_SPEC)\n  by (auto simp: br_def)\n\nlemma leadsto_map4'_correct:\n  \"leadsto_map4' \\<le> leadsto_spec_alt\"\nproof -\n  note leadsto_map4'_ref\n  also note leadsto_map3'_ref\n  also note leadsto'_correct\n  also note leadsto_spec_leadsto_spec_alt\n  finally show ?thesis .\nqed\n\nend (* Leadsto Search Space Key *)\n\nend (* Theory *)\n", "meta": {"author": "wimmers", "repo": "munta", "sha": "62cb1a4a4dbcfcf62c365e90faba15b0012d5a12", "save_path": "github-repos/isabelle/wimmers-munta", "path": "github-repos/isabelle/wimmers-munta/munta-62cb1a4a4dbcfcf62c365e90faba15b0012d5a12/Worklist_Algorithms/Leadsto_Map.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.2840421274806909}}
{"text": "section\\<open>The Axiom of Replacement in $M[G]$\\<close>\ntheory Replacement_Axiom\n  imports\n    Separation_Axiom\nbegin\n\ncontext forcing_data1\nbegin\n\nbundle sharp_simps1 = snd_abs[simp] fst_abs[simp] fst_closed[simp del, simplified, simp]\n  snd_closed[simp del, simplified, simp] M_inhabited[simplified, simp]\n  pair_in_M_iff[simp del, simplified, simp]\n\nlemma sats_body_ground_repl_fm:\n  includes sharp_simps1\n  assumes\n    \"\\<exists>t p. x=\\<langle>t,p\\<rangle>\" \"[x,\\<alpha>,m,\\<bbbP>,leq,\\<one>] @ nenv \\<in>list(M)\"\n    \"\\<phi>\\<in>formula\"\n  shows\n    \"(\\<exists>\\<tau>\\<in>M. \\<exists>V\\<in>M. is_Vset(\\<lambda>a. (##M)(a),\\<alpha>,V) \\<and> \\<tau> \\<in> V \\<and> (snd(x) \\<tturnstile> \\<phi> ([fst(x),\\<tau>]@nenv)))\n    \\<longleftrightarrow> M, [\\<alpha>, x, m, \\<bbbP>, leq, \\<one>] @ nenv \\<Turnstile> body_ground_repl_fm(\\<phi>)\"\n  unfolding body_ground_repl_fm_def rename_split_fm_def\n  by ((insert assms,rule iff_sats | simp add:nonempty[simplified])+,\n      insert sats_incr_bv_iff[where bvs=\"[_,_,_,_,_,_]\", simplified],auto del: iffI)\n\nend \\<comment> \\<open>\\<^locale>\\<open>forcing_data1\\<close>\\<close>\n\ncontext G_generic1\nbegin\n\nlemma Replace_sats_in_MG:\n  assumes\n    \"c\\<in>M[G]\" \"env \\<in> list(M[G])\"\n    \"\\<phi> \\<in> formula\" \"arity(\\<phi>) \\<le> 2 +\\<^sub>\\<omega> length(env)\"\n    \"univalent(##M[G], c, \\<lambda>x v. (M[G] , [x,v]@env \\<Turnstile> \\<phi>) )\"\n    and\n    ground_replacement:\n    \"\\<And>nenv. ground_replacement_assm(M,[\\<bbbP>,leq,\\<one>] @ nenv, \\<phi>)\"\n  shows\n    \"{v. x\\<in>c, v\\<in>M[G] \\<and> (M[G] , [x,v]@env \\<Turnstile> \\<phi>)} \\<in> M[G]\"\nproof -\n  let ?R = \"\\<lambda> x v . v\\<in>M[G] \\<and> (M[G] , [x,v]@env \\<Turnstile> \\<phi>)\"\n  from \\<open>c\\<in>M[G]\\<close>\n  obtain \\<pi>' where \"val(G, \\<pi>') = c\" \"\\<pi>' \\<in> M\"\n    using GenExt_def by auto\n  then\n  have \"domain(\\<pi>')\\<times>\\<bbbP>\\<in>M\" (is \"?\\<pi>\\<in>M\")\n    using cartprod_closed domain_closed by simp\n  from \\<open>val(G, \\<pi>') = c\\<close>\n  have \"c \\<subseteq> val(G,?\\<pi>)\"\n    using def_val[of G ?\\<pi>] elem_of_val[of _ G \\<pi>'] one_in_G\n       domain_of_prod[OF one_in_P, of \"domain(\\<pi>')\"]\n    by (force del:M_genericD)\n  from \\<open>env \\<in> _\\<close>\n  obtain nenv where \"nenv\\<in>list(M)\" \"env = map(val(G),nenv)\"\n    using map_val by auto\n  then\n  have \"length(nenv) = length(env)\" by simp\n  with \\<open>arity(\\<phi>) \\<le> _\\<close>\n  have \"arity(\\<phi>) \\<le> 2 +\\<^sub>\\<omega> length(nenv)\" by simp\n  define f where \"f(\\<rho>p) \\<equiv> \\<mu> \\<alpha>. \\<alpha>\\<in>M \\<and> (\\<exists>\\<tau>\\<in>M. \\<tau> \\<in> Vset(\\<alpha>) \\<and>\n        (snd(\\<rho>p) \\<tturnstile> \\<phi> ([fst(\\<rho>p),\\<tau>] @ nenv)))\" (is \"_ \\<equiv> \\<mu> \\<alpha>. ?P(\\<rho>p,\\<alpha>)\") for \\<rho>p\n  have \"f(\\<rho>p) = (\\<mu> \\<alpha>. \\<alpha>\\<in>M \\<and> (\\<exists>\\<tau>\\<in>M. \\<exists>V\\<in>M. is_Vset(##M,\\<alpha>,V) \\<and> \\<tau>\\<in>V \\<and>\n        (snd(\\<rho>p) \\<tturnstile> \\<phi> ([fst(\\<rho>p),\\<tau>] @ nenv))))\" (is \"_ = (\\<mu> \\<alpha>. \\<alpha>\\<in>M \\<and> ?Q(\\<rho>p,\\<alpha>))\") for \\<rho>p\n    unfolding f_def using Vset_abs Vset_closed Ord_Least_cong[of \"?P(\\<rho>p)\" \"\\<lambda> \\<alpha>. \\<alpha>\\<in>M \\<and> ?Q(\\<rho>p,\\<alpha>)\"]\n    by (simp, simp del:setclass_iff)\n  moreover\n  note inM = \\<open>nenv\\<in>list(M)\\<close> \\<open>?\\<pi>\\<in>M\\<close>\n  moreover\n  have \"f(\\<rho>p) \\<in> M\" \"Ord(f(\\<rho>p))\" for \\<rho>p\n    unfolding f_def using Least_closed'[of \"?P(\\<rho>p)\"] by simp_all\n  ultimately\n  have 1:\"least(##M,\\<lambda>\\<alpha>. ?Q(\\<rho>p,\\<alpha>),f(\\<rho>p))\" for \\<rho>p\n    using least_abs'[of \"\\<lambda>\\<alpha>. \\<alpha>\\<in>M \\<and> ?Q(\\<rho>p,\\<alpha>)\" \"f(\\<rho>p)\"] least_conj\n    by (simp flip: setclass_iff)\n  define QQ where \"QQ\\<equiv>?Q\"\n  from 1\n  have \"least(##M,\\<lambda>\\<alpha>. QQ(\\<rho>p,\\<alpha>),f(\\<rho>p))\" for \\<rho>p\n    unfolding QQ_def .\n  have body:\"(M, [\\<rho>p,m,\\<bbbP>,leq,\\<one>] @ nenv \\<Turnstile> ground_repl_fm(\\<phi>)) \\<longleftrightarrow> least(##M, QQ(\\<rho>p), m)\"\n    if \"\\<rho>p\\<in>M\" \"\\<rho>p\\<in>?\\<pi>\" \"m\\<in>M\" for \\<rho>p m\n  proof -\n    note inM that\n    moreover from this assms 1\n    have \"(M , [\\<alpha>,\\<rho>p,m,\\<bbbP>,leq,\\<one>] @ nenv \\<Turnstile> body_ground_repl_fm(\\<phi>)) \\<longleftrightarrow> ?Q(\\<rho>p,\\<alpha>)\" if \"\\<alpha>\\<in>M\" for \\<alpha>\n      using that sats_body_ground_repl_fm[of \\<rho>p \\<alpha> m nenv \\<phi>]\n      by auto\n    moreover from calculation\n    have body:\"\\<And>\\<alpha>. \\<alpha> \\<in> M \\<Longrightarrow> (\\<exists>\\<tau>\\<in>M. \\<exists>V\\<in>M. is_Vset(\\<lambda>a. a\\<in>M, \\<alpha>, V) \\<and> \\<tau> \\<in> V \\<and>\n          (snd(\\<rho>p) \\<tturnstile> \\<phi> ([fst(\\<rho>p),\\<tau>] @ nenv))) \\<longleftrightarrow>\n          M, Cons(\\<alpha>, [\\<rho>p, m, \\<bbbP>, leq, \\<one>] @ nenv) \\<Turnstile> body_ground_repl_fm(\\<phi>)\"\n      by simp\n    ultimately\n    show \"(M , [\\<rho>p,m,\\<bbbP>,leq,\\<one>] @ nenv \\<Turnstile> ground_repl_fm(\\<phi>)) \\<longleftrightarrow> least(##M, QQ(\\<rho>p), m)\"\n      using sats_least_fm[OF body,of 1] unfolding QQ_def ground_repl_fm_def\n      by (simp, simp flip: setclass_iff)\n  qed\n  then\n  have \"univalent(##M, ?\\<pi>, \\<lambda>\\<rho>p m. M , [\\<rho>p,m] @ ([\\<bbbP>,leq,\\<one>] @ nenv) \\<Turnstile> ground_repl_fm(\\<phi>))\"\n    unfolding univalent_def by (auto intro:unique_least)\n  moreover from \\<open>length(_) = _\\<close> \\<open>env \\<in> _\\<close>\n  have \"length([\\<bbbP>,leq,\\<one>] @ nenv) = 3 +\\<^sub>\\<omega> length(env)\" by simp\n  moreover from \\<open>arity(\\<phi>) \\<le> 2 +\\<^sub>\\<omega> length(nenv)\\<close>\n    \\<open>length(_) = length(_)\\<close>[symmetric] \\<open>nenv\\<in>_\\<close> \\<open>\\<phi>\\<in>_\\<close>\n  have \"arity(ground_repl_fm(\\<phi>)) \\<le> 5 +\\<^sub>\\<omega> length(env)\"\n    using arity_ground_repl_fm[of \\<phi>] le_trans Un_le by auto\n  moreover from \\<open>\\<phi>\\<in>formula\\<close>\n  have \"ground_repl_fm(\\<phi>)\\<in>formula\" by simp\n  moreover\n  note \\<open>length(nenv) = length(env)\\<close> inM\n  ultimately\n  obtain Y where \"Y\\<in>M\"\n    \"\\<forall>m\\<in>M. m \\<in> Y \\<longleftrightarrow> (\\<exists>\\<rho>p\\<in>M. \\<rho>p \\<in> ?\\<pi> \\<and> (M, [\\<rho>p,m] @ ([\\<bbbP>,leq,\\<one>] @ nenv) \\<Turnstile> ground_repl_fm(\\<phi>)))\"\n    using ground_replacement[of nenv]\n    unfolding strong_replacement_def ground_replacement_assm_def replacement_assm_def by auto\n  with \\<open>least(_,QQ(_),f(_))\\<close> \\<open>f(_) \\<in> M\\<close> \\<open>?\\<pi>\\<in>M\\<close> body\n  have \"f(\\<rho>p)\\<in>Y\" if \"\\<rho>p\\<in>?\\<pi>\" for \\<rho>p\n    using that transitivity[OF _ \\<open>?\\<pi>\\<in>M\\<close>]\n    by (clarsimp,rename_tac \\<rho> p \\<rho>p, rule_tac x=\"\\<langle>\\<rho>,p\\<rangle>\" in bexI, auto)\n  from \\<open>Y\\<in>M\\<close>\n  have \"\\<Union> {y\\<in>Y. Ord(y)} \\<in> M\" (is \"?sup \\<in> M\")\n    using separation_Ord separation_closed Union_closed by simp\n  then\n  have \"{x\\<in>Vset(?sup). x \\<in> M} \\<times> {\\<one>} \\<in> M\" (is \"?big_name \\<in> M\")\n    using Vset_closed cartprod_closed singleton_closed by simp\n  then\n  have \"val(G,?big_name) \\<in> M[G]\"\n    by (blast intro:GenExtI)\n  have \"{v. x\\<in>c, ?R(x,v)} \\<subseteq> val(G,?big_name)\" (is \"?repl\\<subseteq>?big\")\n  proof(intro subsetI)\n    fix v\n    assume \"v\\<in>?repl\"\n    moreover from this\n    obtain x where \"x\\<in>c\" \"M[G], [x, v] @ env \\<Turnstile> \\<phi>\" \"v\\<in>M[G]\"\n      by auto\n    moreover\n    note \\<open>val(G,\\<pi>')=c\\<close> \\<open>\\<pi>'\\<in>M\\<close>\n    moreover\n    from calculation\n    obtain \\<rho> p where \"\\<langle>\\<rho>,p\\<rangle>\\<in>\\<pi>'\" \"val(G,\\<rho>) = x\" \"p\\<in>G\" \"\\<rho>\\<in>M\"\n      using elem_of_val_pair' by blast\n    moreover from this \\<open>v\\<in>M[G]\\<close>\n    obtain \\<sigma> where \"val(G,\\<sigma>) = v\" \"\\<sigma>\\<in>M\"\n      using GenExtD by (force del:M_genericD)\n    moreover\n    note \\<open>\\<phi>\\<in>_\\<close> \\<open>nenv\\<in>_\\<close> \\<open>env = _\\<close> \\<open>arity(\\<phi>)\\<le> 2 +\\<^sub>\\<omega> length(env)\\<close>\n    ultimately\n    obtain q where \"q\\<in>G\" \"q \\<tturnstile> \\<phi> ([\\<rho>,\\<sigma>]@nenv)\" \"q\\<in>\\<bbbP>\"\n      using truth_lemma[OF \\<open>\\<phi>\\<in>_\\<close>,of \"[\\<rho>,\\<sigma>] @ nenv\"]\n      by auto\n    with \\<open>\\<langle>\\<rho>,p\\<rangle>\\<in>\\<pi>'\\<close> \\<open>\\<langle>\\<rho>,q\\<rangle>\\<in>?\\<pi> \\<Longrightarrow> f(\\<langle>\\<rho>,q\\<rangle>)\\<in>Y\\<close>\n    have \"f(\\<langle>\\<rho>,q\\<rangle>)\\<in>Y\"\n      using generic by blast\n    let ?\\<alpha>=\"succ(rank(\\<sigma>))\"\n    note \\<open>\\<sigma>\\<in>M\\<close>\n    moreover from this\n    have \"?\\<alpha> \\<in> M\" \"\\<sigma> \\<in> Vset(?\\<alpha>)\"\n      using rank_closed cons_closed Vset_Ord_rank_iff\n      by (simp_all flip: setclass_iff)\n    moreover\n    note \\<open>q \\<tturnstile> \\<phi> ([\\<rho>,\\<sigma>] @ nenv)\\<close>\n    ultimately\n    have \"?P(\\<langle>\\<rho>,q\\<rangle>,?\\<alpha>)\" by (auto simp del: Vset_rank_iff)\n    moreover\n    have \"(\\<mu> \\<alpha>. ?P(\\<langle>\\<rho>,q\\<rangle>,\\<alpha>)) = f(\\<langle>\\<rho>,q\\<rangle>)\"\n      unfolding f_def by simp\n    ultimately\n    obtain \\<tau> where \"\\<tau>\\<in>M\" \"\\<tau> \\<in> Vset(f(\\<langle>\\<rho>,q\\<rangle>))\" \"q \\<tturnstile> \\<phi> ([\\<rho>,\\<tau>] @ nenv)\"\n      using LeastI[of \"\\<lambda> \\<alpha>. ?P(\\<langle>\\<rho>,q\\<rangle>,\\<alpha>)\" ?\\<alpha>] by auto\n    with \\<open>q\\<in>G\\<close> \\<open>\\<rho>\\<in>M\\<close> \\<open>nenv\\<in>_\\<close> \\<open>arity(\\<phi>)\\<le> 2 +\\<^sub>\\<omega> length(nenv)\\<close>\n    have \"M[G], map(val(G),[\\<rho>,\\<tau>] @ nenv) \\<Turnstile> \\<phi>\"\n      using truth_lemma[OF \\<open>\\<phi>\\<in>_\\<close>, of \"[\\<rho>,\\<tau>] @ nenv\"] by auto\n    moreover from \\<open>x\\<in>c\\<close> \\<open>c\\<in>M[G]\\<close>\n    have \"x\\<in>M[G]\" using transitivity_MG by simp\n    moreover\n    note \\<open>M[G],[x,v] @ env\\<Turnstile> \\<phi>\\<close> \\<open>env = map(val(G),nenv)\\<close> \\<open>\\<tau>\\<in>M\\<close> \\<open>val(G,\\<rho>)=x\\<close>\n      \\<open>univalent(##M[G],_,_)\\<close> \\<open>x\\<in>c\\<close> \\<open>v\\<in>M[G]\\<close>\n    ultimately\n    have \"v=val(G,\\<tau>)\"\n      using GenExtI[of \\<tau> G] unfolding univalent_def by (auto)\n    from \\<open>\\<tau> \\<in> Vset(f(\\<langle>\\<rho>,q\\<rangle>))\\<close> \\<open>Ord(f(_))\\<close>  \\<open>f(\\<langle>\\<rho>,q\\<rangle>)\\<in>Y\\<close>\n    have \"\\<tau> \\<in> Vset(?sup)\"\n      using Vset_Ord_rank_iff lt_Union_iff[of _ \"rank(\\<tau>)\"] by auto\n    with \\<open>\\<tau>\\<in>M\\<close>\n    have \"val(G,\\<tau>) \\<in> val(G,?big_name)\"\n      using domain_of_prod[of \\<one> \"{\\<one>}\" \"{x\\<in>Vset(?sup). x \\<in> M}\" ] def_val[of G ?big_name]\n        one_in_G one_in_P  by (auto simp del: Vset_rank_iff)\n    with \\<open>v=val(G,\\<tau>)\\<close>\n    show \"v \\<in> val(G,?big_name)\"\n      by simp\n  qed\n  from \\<open>?big_name\\<in>M\\<close>\n  have \"?repl = {v\\<in>?big. \\<exists>x\\<in>c. M[G], [x,v] @ env \\<Turnstile>  \\<phi>}\" (is \"_ = ?rhs\")\n  proof(intro equalityI subsetI)\n    fix v\n    assume \"v\\<in>?repl\"\n    with \\<open>?repl\\<subseteq>?big\\<close>\n    obtain x where \"x\\<in>c\" \"M[G], [x, v] @ env \\<Turnstile> \\<phi>\" \"v\\<in>?big\"\n      using subsetD by auto\n    with \\<open>univalent(##M[G],_,_)\\<close> \\<open>c\\<in>M[G]\\<close>\n    show \"v \\<in> ?rhs\"\n      unfolding univalent_def\n      using transitivity_MG ReplaceI[of \"\\<lambda> x v. \\<exists>x\\<in>c. M[G], [x, v] @ env \\<Turnstile> \\<phi>\"] by blast\n  next\n    fix v\n    assume \"v\\<in>?rhs\"\n    then\n    obtain x where\n      \"v\\<in>val(G, ?big_name)\" \"M[G], [x, v] @ env \\<Turnstile> \\<phi>\" \"x\\<in>c\"\n      by blast\n    moreover from this \\<open>c\\<in>M[G]\\<close>\n    have \"v\\<in>M[G]\" \"x\\<in>M[G]\"\n      using transitivity_MG GenExtI[OF \\<open>?big_name\\<in>_\\<close>,of G] by auto\n    moreover from calculation \\<open>univalent(##M[G],_,_)\\<close>\n    have \"?R(x,y) \\<Longrightarrow> y = v\" for y\n      unfolding univalent_def by auto\n    ultimately\n    show \"v\\<in>?repl\"\n      using ReplaceI[of ?R x v c]\n      by blast\n  qed\n  moreover\n  let ?\\<psi> = \"(\\<cdot>\\<exists>\\<cdot>\\<cdot>0 \\<in> 2 +\\<^sub>\\<omega> length(env) \\<cdot> \\<and> \\<phi>\\<cdot>\\<cdot>)\"\n  from \\<open>\\<phi>\\<in>_\\<close>\n  have \"?\\<psi>\\<in>formula\" \"arity(?\\<psi>) \\<le> 2 +\\<^sub>\\<omega> length(env)\"\n    using pred_mono[OF _ \\<open>arity(\\<phi>)\\<le>2+\\<^sub>\\<omega>length(env)\\<close>] lt_trans[OF _ le_refl]\n    by (auto simp add:ord_simp_union arity)\n  moreover\n  from \\<open>\\<phi>\\<in>_\\<close> \\<open>arity(\\<phi>)\\<le>2+\\<^sub>\\<omega>length(env)\\<close> \\<open>c\\<in>M[G]\\<close> \\<open>env\\<in>_\\<close>\n  have \"(\\<exists>x\\<in>c. M[G], [x,v] @ env \\<Turnstile> \\<phi>) \\<longleftrightarrow> M[G], [v] @ env @ [c] \\<Turnstile> ?\\<psi>\" if \"v\\<in>M[G]\" for v\n    using that nth_concat transitivity_MG[OF _ \\<open>c\\<in>M[G]\\<close>] arity_sats_iff[of \\<phi> \"[c]\" _ \"[_,v]@env\"]\n    by auto\n  moreover from this\n  have \"{v\\<in>?big. \\<exists>x\\<in>c. M[G], [x,v] @ env \\<Turnstile> \\<phi>} = {v\\<in>?big. M[G], [v] @ env @ [c] \\<Turnstile>  ?\\<psi>}\"\n    using transitivity_MG[OF _ GenExtI, OF _ \\<open>?big_name\\<in>M\\<close>]\n    by simp\n  moreover from calculation and \\<open>env\\<in>_\\<close> \\<open>c\\<in>_\\<close> \\<open>?big\\<in>M[G]\\<close>\n  have \"{v\\<in>?big. M[G] , [v] @ env @ [c] \\<Turnstile> ?\\<psi>} \\<in> M[G]\"\n    using Collect_sats_in_MG by auto\n  ultimately\n  show ?thesis by simp\nqed\n\ntheorem strong_replacement_in_MG:\n  assumes\n    \"\\<phi>\\<in>formula\" and \"arity(\\<phi>) \\<le> 2 +\\<^sub>\\<omega> length(env)\" \"env \\<in> list(M[G])\"\n    and\n    ground_replacement:\n    \"\\<And>nenv. ground_replacement_assm(M,[\\<bbbP>,leq,\\<one>] @ nenv, \\<phi>)\"\n  shows\n    \"strong_replacement(##M[G],\\<lambda>x v. M[G],[x,v] @ env \\<Turnstile> \\<phi>)\"\nproof -\n  let ?R=\"\\<lambda>x y . M[G], [x, y] @ env \\<Turnstile> \\<phi>\"\n  {\n    fix A\n    let ?Y=\"{v . x \\<in> A, v\\<in>M[G] \\<and> ?R(x,v)}\"\n    assume 1: \"(##M[G])(A)\" \"univalent(##M[G], A, ?R)\"\n    with assms\n    have \"(##M[G])(?Y)\"\n      using Replace_sats_in_MG ground_replacement 1\n      unfolding ground_replacement_assm_def by auto\n    have \"b \\<in> ?Y \\<longleftrightarrow> (\\<exists>x[##M[G]]. x \\<in> A \\<and> ?R(x,b))\" if \"(##M[G])(b)\" for b\n    proof(rule)\n      from \\<open>(##M[G])(A)\\<close>\n      show \"\\<exists>x[##M[G]]. x \\<in> A \\<and> ?R(x,b)\" if \"b \\<in> ?Y\"\n        using that transitivity_MG by auto\n    next\n      show \"b \\<in> ?Y\" if \"\\<exists>x[##M[G]]. x \\<in> A \\<and> ?R(x,b)\"\n      proof -\n        from \\<open>(##M[G])(b)\\<close>\n        have \"b\\<in>M[G]\" by simp\n        with that\n        obtain x where \"(##M[G])(x)\" \"x\\<in>A\" \"b\\<in>M[G] \\<and> ?R(x,b)\"\n          by blast\n        moreover from this 1 \\<open>(##M[G])(b)\\<close>\n        have \"x\\<in>M[G]\" \"z\\<in>M[G] \\<and> ?R(x,z) \\<Longrightarrow> b = z\" for z\n          unfolding univalent_def\n          by auto\n        ultimately\n        show ?thesis\n          using ReplaceI[of \"\\<lambda> x y. y\\<in>M[G] \\<and> ?R(x,y)\"] by blast\n      qed\n    qed\n    then\n    have \"\\<forall>b[##M[G]]. b \\<in> ?Y \\<longleftrightarrow> (\\<exists>x[##M[G]]. x \\<in> A \\<and> ?R(x,b))\"\n      by simp\n    with \\<open>(##M[G])(?Y)\\<close>\n    have \" (\\<exists>Y[##M[G]]. \\<forall>b[##M[G]]. b \\<in> Y \\<longleftrightarrow> (\\<exists>x[##M[G]]. x \\<in> A \\<and> ?R(x,b)))\"\n      by auto\n  }\n  then show ?thesis unfolding strong_replacement_def\n    by simp\nqed\n\nlemma replacement_assm_MG:\n  assumes\n    ground_replacement:\n    \"\\<And>nenv. ground_replacement_assm(M,[\\<bbbP>,leq,\\<one>] @ nenv, \\<phi>)\"\n  shows\n    \"replacement_assm(M[G],env,\\<phi>)\"\n  using assms strong_replacement_in_MG\n  unfolding replacement_assm_def by simp\n\nend \\<comment> \\<open>\\<^locale>\\<open>G_generic1\\<close>\\<close>\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Independence_CH/Replacement_Axiom.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5467381372136563, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.2840421198068635}}
{"text": "subsection \\<open>State Monad\\<close>\n\ntheory State_Monad_Ext\n  imports \"HOL-Library.State_Monad\"\nbegin\n\ndefinition fun_app_lifted :: \"('M,'a \\<Rightarrow> ('M, 'b) state) state \\<Rightarrow> ('M,'a) state \\<Rightarrow> ('M,'b) state\" where\n  \"fun_app_lifted f\\<^sub>T x\\<^sub>T \\<equiv> do { f \\<leftarrow> f\\<^sub>T; x \\<leftarrow> x\\<^sub>T; f x }\"\n\nbundle state_monad_syntax begin\n\nnotation fun_app_lifted (infixl \".\" 999)\ntype_synonym ('a,'M,'b) fun_lifted = \"'a \\<Rightarrow> ('M,'b) state\" (\"_ ==_\\<Longrightarrow> _\" [3,1000,2] 2)\ntype_synonym ('a,'b) dpfun = \"'a ==('a\\<rightharpoonup>'b)\\<Longrightarrow> 'b\" (infixr \"\\<Rightarrow>\\<^sub>T\" 2)\ntype_notation state (\"[_| _]\")\n\nnotation State_Monad.return (\"\\<langle>_\\<rangle>\")\nnotation (ASCII) State_Monad.return (\"(#_#)\")\nnotation Transfer.Rel (\"Rel\")\n\nend\n\ncontext includes state_monad_syntax begin\n\nqualified lemma return_app_return:\n  \"\\<langle>f\\<rangle> . \\<langle>x\\<rangle> = f x\"\n  unfolding fun_app_lifted_def bind_left_identity ..\n\nqualified lemma return_app_return_meta:\n  \"\\<langle>f\\<rangle> . \\<langle>x\\<rangle> \\<equiv> f x\"\n  unfolding return_app_return .\n\nqualified definition if\\<^sub>T :: \"('M, bool) state \\<Rightarrow> ('M, 'a) state \\<Rightarrow> ('M, 'a) state \\<Rightarrow> ('M, 'a) state\" where\n  \"if\\<^sub>T b\\<^sub>T x\\<^sub>T y\\<^sub>T \\<equiv> do {b \\<leftarrow> b\\<^sub>T; if b then x\\<^sub>T else y\\<^sub>T}\"\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Monad_Memo_DP/state_monad/State_Monad_Ext.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5506073655352404, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.2839041234137523}}
{"text": "theory Linearization\nimports \"../LinearAssembly/LinearAssemblyLanguage\" \"../Utilities/Iterate\"\nbegin\n\nfun state_convert :: \"assembly_state \\<Rightarrow> l_assembly_state\" where\n  \"state_convert (\\<mu>, a, d, \\<pi>, s, \\<omega>) = (\\<mu>, a, d, \\<pi> @ [JAssm {EQ, GT, LT} s], \\<omega>)\"\n\nfun linearize_step :: \"code_label\\<^sub>2 \\<times> assembly list \\<times> code_label\\<^sub>2 \\<Rightarrow> l_assembly_program \\<Rightarrow> \n    l_assembly_program\" where\n  \"linearize_step (s, \\<pi>, s') \\<Pi> = (s, \\<pi> @ [JAssm {EQ, GT, LT} s']) # \\<Pi>\"\n\ndefinition linearize :: \"assembly_program \\<Rightarrow> l_assembly_program\" where\n  \"linearize \\<Pi> = finite_map_fold linearize_step [] \\<Pi>\"\n\n(* linearization correct *)\n\n\n\nlemma [simp]: \"finite (dom \\<Pi>) \\<Longrightarrow> \\<Pi> x = None \\<Longrightarrow> \n    lookup (finite_map_fold linearize_step [] \\<Pi>) x = None\"\n  proof (induction linearize_step \"[]::code_label\\<^sub>2 \\<leadsto> assembly list\" \\<Pi> rule: finite_map_fold.induct)\n  case 1\n    thus ?case by metis\n  next case 2\n    thus ?case by simp\n  next case (3 \\<Pi>)\n    let ?x = \"SOME x. x \\<in> dom \\<Pi>\"\n    let ?ih = \"finite_map_fold linearize_step [] (\\<Pi>(?x := None))\"\n    from 3 have \"?x \\<in> dom \\<Pi>\" by (smt Collect_empty_eq card_0_eq dom_def mem_Collect_eq someI_ex)\n    with 3 have \"x \\<noteq> ?x\" by blast\n    with 3 show ?case by (cases \"the (\\<Pi> ?x)\") (simp add: Let_def)\n  qed\n\nlemma [simp]: \"finite (dom \\<Pi>) \\<Longrightarrow> \\<Pi> x = Some (\\<pi>, s) \\<Longrightarrow> \n    lookup (finite_map_fold linearize_step [] \\<Pi>) x = Some (\\<pi> @ [JAssm {EQ, GT, LT} s])\"\n  proof (induction linearize_step \"[]::code_label\\<^sub>2 \\<leadsto> assembly list\" \\<Pi> rule: finite_map_fold.induct)\n  case 1\n    thus ?case by metis\n  next case 2\n    thus ?case by (metis card_0_eq dom_eq_empty_conv option.distinct(1))\n  next case (3 \\<Pi>)\n    let ?x = \"SOME x. x \\<in> dom \\<Pi>\"\n    let ?ih = \"finite_map_fold linearize_step [] (\\<Pi>(?x := None))\"\n    show ?case\n      proof (cases \"x = ?x\")\n      case True\n        with 3 have \"\\<Pi> ?x = Some (\\<pi>, s)\" by blast\n        with True have \"lookup (linearize_step (?x, the (\\<Pi> ?x)) ?ih) x = \n          Some (\\<pi> @ [JAssm {EQ, GT, LT} s])\" by (cases \"the (\\<Pi> ?x)\") simp\n        with 3 show ?thesis by (simp add: Let_def)\n      next case False\n        with 3 show ?thesis by (cases \"the (\\<Pi> ?x)\") (simp add: Let_def)\n      qed\n  qed\n\nlemma [simp]: \"finite (dom \\<Pi>) \\<Longrightarrow> \\<Pi> x = Some (\\<pi>, s) \\<Longrightarrow> \n    lookup (linearize \\<Pi>) x = Some (\\<pi> @ [JAssm {EQ, GT, LT} s])\"\n  by (simp add: linearize_def)\n\nlemma [simp]: \"finite (dom \\<Pi>) \\<Longrightarrow> domain_distinct (finite_map_fold linearize_step [] \\<Pi>)\"\n  proof (induction linearize_step \"[]::code_label\\<^sub>2 \\<leadsto> assembly list\" \\<Pi> rule: finite_map_fold.induct)\n  case 1\n    thus ?case by metis\n  next case 2\n    thus ?case by simp\n  next case (3 \\<Pi>)\n    let ?x = \"SOME x. x \\<in> dom \\<Pi>\"\n    let ?ih = \"finite_map_fold linearize_step [] (\\<Pi>(?x := None))\"\n    show ?case\n      proof (cases \"the (\\<Pi> ?x)\")\n      case (Pair \\<pi> s)\n        from 3 have \"lookup ?ih ?x = None\" by simp\n        hence \"?x \\<notin> dom (lookup ?ih)\" by auto\n        with 3 Pair show ?thesis by (simp add: Let_def)\n      qed\n  qed\n\nlemma [simp]: \"finite (dom \\<Pi>) \\<Longrightarrow> domain_distinct (linearize \\<Pi>)\"\n  by (simp add: linearize_def)\n\nlemma [simp]: \"finite (dom \\<Pi>) \\<Longrightarrow> eval_assembly \\<Pi> \\<Sigma> = Some \\<Sigma>' \\<Longrightarrow> \n    eval_l_assembly (linearize \\<Pi>) (state_convert \\<Sigma>) = Some (state_convert \\<Sigma>')\"\n  proof (induction \\<Pi> \\<Sigma> rule: eval_assembly.induct)\n  case (1 \\<Pi> \\<mu> a d s \\<omega>)\n    thus ?case by (cases \"\\<Pi> s\") (auto split: prod.splits)\n  next case 2\n    thus ?case by auto\n  next case 3\n    thus ?case by (auto simp add: Let_def)\n  next case 4\n    thus ?case by simp\n  next case (5 \\<Pi> \\<mu> a d jmp s \\<pi> s' \\<omega>)\n    thus ?case by (cases \"\\<Pi> s\") auto\n  next case 6\n    thus ?case by auto\n  qed\n\ntheorem linearization_correct [simp]: \"iterate (eval_assembly \\<Pi>) \\<Sigma> \\<Sigma>' \\<Longrightarrow> finite (dom \\<Pi>) \\<Longrightarrow> \n    iterate (eval_l_assembly (linearize \\<Pi>)) (state_convert \\<Sigma>) (state_convert \\<Sigma>')\"\n  by (induction \"eval_assembly \\<Pi>\" \\<Sigma> \\<Sigma>' rule: iterate.induct) simp_all\n\nend", "meta": {"author": "xtreme-james-cooper", "repo": "Elements", "sha": "695d842d865d1524a9e638f778b0bad97485b969", "save_path": "github-repos/isabelle/xtreme-james-cooper-Elements", "path": "github-repos/isabelle/xtreme-james-cooper-Elements/Elements-695d842d865d1524a9e638f778b0bad97485b969/Assembly/Linearization.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5506073655352404, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.28390412341375226}}
{"text": "           (*-------------------------------------------*\n            |                                           |\n            |          Test on LW-CSP-Prover            |\n            |                                           |\n            *-------------------------------------------*)\n\ntheory Test\nimports CSP_semantics\nbegin\n\n(*************************************************************\n\n         1. Test\n         2. \n         3. \n         4. \n\n *************************************************************)\n\n(* test of transition *)\n\ndatatype K_Events = lock | unlock | finish\ndatatype K_PName = Key\n\nprimrec\n  Def :: \"K_PName => (K_PName, K_Events) proc\"\n  where\n  \"Def Key = (lock -> unlock -> $Key) [+] (finish -> STOP)\"\n\noverloading K_PNfun == \n  \"PNfun :: K_PName => (K_PName, K_Events) proc\"\n  begin definition \"PNfun = Def\" end\n  declare K_PNfun_def [simp]\n\nlemma trn_exists:\n  \"$Key ---(Ev lock)---> (unlock -> $Key)\"\n  apply (rule PName, simp)\n  apply (rule ExtCh1)\n  apply (rule Prefix)\n  done\n\nlemma if_trn_exists:\n  \"$Key ---e---> P' \n   \\<Longrightarrow>   (e = (Ev lock) \\<and> P' = unlock -> $Key)\n       \\<or> (e = (Ev finish) \\<and> P' = STOP)\"\n  apply (erule trn.cases, auto)+\n  done\n\n\n\n(* test of transition *)\n\ndatatype FW_Events = in1 | in2 | out1 | out2\ndatatype FW_PName = FW\n\nprimrec\n  FW_Def :: \"FW_PName => (FW_PName, FW_Events) proc\"\n  where\n  \"FW_Def FW = (in1 -> out1 -> $FW) [+] (in2 -> out2 -> $FW)\"\n\noverloading FW_PNfun == \n  \"PNfun :: FW_PName => (FW_PName, FW_Events) proc\"\n  begin definition \"PNfun = FW_Def\" end\n  declare FW_PNfun_def [simp]\n\nlemma fw_trn_exists:\n  \"$FW ---(Ev in1)---> (out1 -> $FW)\"\n  apply (rule PName, simp)\n  apply (rule ExtCh1)\n  apply (rule Prefix)\n  done\n\nlemma fw_if_trn_exists:\n  \"$FW ---e---> P' \n   ==>   (e = Ev in1 & P' = out1 -> $FW)\n       | (e = Ev in2 & P' = out2 -> $FW)\"\n  apply (erule trn.cases, auto)+\n  done\n\nlemma trn_exists_STOP:\n  \"(in1 -> out1 -> STOP) [+] (in2 -> out2 -> STOP)\n   ---(Ev in1)---> (out1 -> STOP)\"\n  apply (rule ExtCh1)\n  apply (rule Prefix)\n  done\n\nlemma if_trn_exists_STOP:\n  \"(in1 -> out1 -> STOP) [+] (in2 -> out2 -> STOP)\n   ---e---> P' \n   ==>   (e = Ev in1 & P' = out1 -> STOP)\n       | (e = Ev in2 & P' = out2 -> STOP)\"\n  apply (erule trn.cases, auto)+\n  done\n\ndatatype Events2 = put | pass | get\n\nlemma ex1_transition:\n  \"((get -> pass -> STOP) |[{pass}]| (pass -> put -> STOP)) ~~ {pass}\n   ---(Ev get)---> \n   ((pass -> STOP) |[{pass}]| (pass -> put -> STOP)) ~~ {pass}\"\n  apply (rule Hide1, auto)\n  apply (rule Para1, auto)\n  apply (rule Prefix)\n  done\n\nlemma ex2_transition:\n  \"((pass -> STOP) |[{pass}]| (pass -> put -> STOP)) ~~ {pass}\n   ---Tau---> \n   (STOP |[{pass}]| (put -> STOP)) ~~ {pass}\"\n  apply (intro Hide2 Para3 Prefix, auto?)+\n  done\n\nlemma ex3_transition:\n  \"(STOP |[{pass}]| (put -> STOP)) ~~ {pass}\n   ---(Ev put)---> \n   (STOP |[{pass}]| STOP) ~~ {pass}\"\n  apply (intro Hide1 Para2 Prefix, auto?)+\n  done\n\nlemma ex4_transition:\n  \"((get -> pass -> STOP) |[{pass}]| (pass -> put -> STOP)) ~~ {pass}\n   ---e---> P'\n   ==> e = Ev get & \n       P' = ((pass -> STOP) |[{pass}]| (pass -> put -> STOP)) ~~ {pass}\"\n  apply (erule trn.cases, auto?)+\n  done\n\n\n\n\n\nlemma ex1_transition_manual_proof:\n  \"((a -> STOP) [+] P) ||| Q ---(Ev a)---> STOP ||| Q\"\n  apply (rule Para1)\n  apply (rule conjI)\n  apply (rule ExtCh1)\n  apply (rule Prefix)\n  apply (simp)\n  done\n\nlemma ex2_transition_auto_proof:\n  \"((a -> STOP) [+] P) ||| Q ---(Ev a)---> STOP ||| Q\"\n  apply (auto intro: trn.intros)\n  done\n\nlemma ex3_decomposition_of_transition:\n  \"((a -> STOP) [+] (b -> STOP)) ||| Q ---(Ev c)---> STOP ||| Q\n   ==> a = c | b = c\"\n  apply (erule trn.cases)   (* all cases are checked for ||| *)\n  apply (auto)\n  apply (erule trn.cases)   (* all cases are checked for [+] *)\n  apply (auto)\n  apply (erule trn.cases)   (* all cases are checked for a -> *)\n  apply (auto)\n  apply (erule trn.cases)   (* all cases are checked for b -> *)\n  apply (auto)\n  done\n\n\n\n(* ----- loop test (process name) ------ *)\n\ndatatype Event = act1 | act2\ndatatype Name = Ptest\n\nprimrec\n  Def2 :: \"Name => (Name, Event) proc\"\n  where\n  \"Def2 Ptest = act1 -> $Ptest [+] act2 -> STOP\"\n\noverloading Test_PNfun == \n  \"PNfun :: Name => (Name, Event) proc\"\n  begin\n    definition \"PNfun == Def2\"\n  end\n\ndeclare Test_PNfun_def [simp]\n\nlemma ex4_loop_transition_manual_proof:\n  \"$Ptest ---(Ev act1)---> $Ptest\"\n  apply (rule PName)\n  apply (simp)\n  apply (rule ExtCh1)\n  apply (rule Prefix)\n  done\n\nlemma ex4_loop_transition_auto_proof:\n  \"$Ptest ---(Ev act1)---> $Ptest\"\n  apply (intro trn.intros)\n  apply (simp)\n  apply (intro trn.intros)\n  done\n\n\n(* test of sequential transition *)\n\nlemma ex5_seq_transition_manual_proof:\n  \"a ~= b ==> c ~= b\n   ==> (a -> b -> c -> STOP) ~~ {b} ---[Ev a, Tau, Ev c]--->> STOP ~~ {b}\"\n  apply (rule Step)\n  apply (rule_tac x=\"(b -> c -> STOP) ~~ {b}\" in exI)\n  apply (rule_tac x=\"Ev a\" in exI)\n  apply (rule_tac x=\"[Tau,Ev c]\" in exI)\n  apply (rule conjI)\n   apply (rule Hide1)\n   apply (rule conjI)\n    apply (rule Prefix)\n   apply (simp)\n  apply (rule conjI)\n   apply (rule Step)\n   apply (rule_tac x=\"(c -> STOP) ~~ {b}\" in exI)\n   apply (rule_tac x=\"Tau\" in exI)\n   apply (rule_tac x=\"[Ev c]\" in exI)\n   apply (rule conjI)\n    apply (rule Hide2)\n    apply (rule conjI)\n     apply (rule Prefix)\n    apply (simp)\n   apply (rule conjI)\n    apply (rule Base)\n    apply (rule Hide1)\n    apply (rule conjI)\n     apply (rule Prefix)\n    apply (simp)\n   apply (simp)\n  apply (simp)\n  done\n\n(* test of traces *)\n\nlemma ex6_traces_manual_proof:\n  \"[| a ~= b; c ~= b |]\n   ==> [a,c] : traces((a -> b -> c -> STOP) ~~ {b})\"\n  apply (simp add: traces_def)\n  apply (rule_tac x=\"[Ev a, Tau, Ev c]\" in exI)\n  apply (rule conjI)\n   apply (simp)\n  apply (rule_tac x=\"STOP ~~ {b}\" in exI)\n  apply (simp add: ex5_seq_transition_manual_proof)\n  done\n\n\n\nend\n", "meta": {"author": "nu-manycore", "repo": "public", "sha": "94b6a68b8183e6b756f6ece0fa483b93ad8cc833", "save_path": "github-repos/isabelle/nu-manycore-public", "path": "github-repos/isabelle/nu-manycore-public/public-94b6a68b8183e6b756f6ece0fa483b93ad8cc833/MBP-Prover/Test.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5156199157230156, "lm_q2_score": 0.5506073655352404, "lm_q1q2_score": 0.28390412341375226}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory IndirectCalls\n\nimports\n  \"PrettyProgs\"\n\nbegin\n\ndefinition\n  lookup_proc :: \"(string \\<Rightarrow> 'proc_addr) \\<Rightarrow> ('proc_id \\<rightharpoonup> string)\n    \\<Rightarrow> 'proc_addr \\<Rightarrow> 'proc_id\"\nwhere\n  \"lookup_proc symtab naming x\n    = (THE pid. naming pid \\<noteq> None \\<and> symtab (the (naming pid)) = x)\"\n\ndefinition\n  lookup_proc_safe :: \"(string \\<Rightarrow> 'proc_addr) \\<Rightarrow> ('proc_id \\<rightharpoonup> string)\n    \\<Rightarrow> 'proc_addr \\<Rightarrow> bool\"\nwhere\n  \"lookup_proc_safe symtab naming x\n    = (card {pid. naming pid \\<noteq> None \\<and> symtab (the (naming pid)) = x} = 1)\"\n\ndefinition\n  procs_consistent :: \"(string \\<Rightarrow> 'proc_addr) \\<Rightarrow> ('proc_nm \\<rightharpoonup> string)\n    \\<Rightarrow> bool\"\nwhere\n  \"procs_consistent symtab naming\n    = (finite (dom naming)\n        \\<and> (\\<forall>x y nm nm'. naming x = Some nm \\<and> naming y = Some nm'\n            \\<and> symtab nm = symtab nm'\n                \\<longrightarrow> x = y))\"\n\nlemma procs_consistent_eq:\n  \"\\<lbrakk> naming proc = Some nm; procs_consistent symtab naming; addr = symtab nm \\<rbrakk>\n    \\<Longrightarrow> lookup_proc symtab naming addr = proc\"\n  apply (clarsimp simp: procs_consistent_def lookup_proc_def)\n  apply (rule the_equality)\n   apply clarsimp\n  apply clarsimp\n  done\n\nlemma procs_consistent_safe:\n  \"\\<lbrakk> naming proc = Some nm; procs_consistent symtab naming; addr = symtab nm \\<rbrakk>\n    \\<Longrightarrow> lookup_proc_safe symtab naming addr\"\n  apply (clarsimp simp: procs_consistent_def lookup_proc_safe_def)\n  apply (rule trans, rule arg_cong[where f=card and y=\"{proc}\"])\n   apply auto\n  done\n\nlemma hoare_indirect_call_procs_consistent:\n  \"\\<lbrakk> naming proc = Some nm;\n        \\<Gamma> \\<turnstile> P (call initf proc ret c) Q, A \\<rbrakk>\n    \\<Longrightarrow> \\<Gamma> \\<turnstile> ({s. procs_consistent symtab naming \\<and> x_fn s = symtab nm} \\<inter> P)\n            (dynCall initf (\\<lambda>s. lookup_proc symtab naming (x_fn s))\n                    ret c) Q, A\"\n  apply (rule hoare_complete, drule hoare_sound)\n  apply (clarsimp simp: cvalid_def HoarePartialDef.valid_def)\n  apply (erule exec_dynCall_Normal_elim)\n  apply (simp add: procs_consistent_eq)\n  apply blast\n  done\n\nend\n\n", "meta": {"author": "amblafont", "repo": "AutoCorres", "sha": "a8e96bff9fb22d633ff473401947ca84235d3b73", "save_path": "github-repos/isabelle/amblafont-AutoCorres", "path": "github-repos/isabelle/amblafont-AutoCorres/AutoCorres-a8e96bff9fb22d633ff473401947ca84235d3b73/c-parser/IndirectCalls.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5813030906443133, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.28384064679576765}}
{"text": "theory ReduceRestr\n  imports GenSubEnv WTLemma ResMapDisj ReduceWTS\nbegin\n  \n    (* setup for an important lemma, which states that s + env restricted to part of an rs_map should remain well-typed. *)\n    \ndefinition restr_env where\n  \"restr_env s rs_map = (\\<lambda> x. if lookup_mem rs_map x = None then None else s x)\"  \n  \ndefinition np_restr_env where\n  \"np_restr_env env rs_map = (\\<lambda> x. if lookup_mem rs_map x = None \\<and> non_prim_entry env x then None else env x)\"    \n  \nlemma restr_sub_env: \"\\<lbrakk> sub_env s env; non_prim_env env \\<rbrakk> \\<Longrightarrow> sub_env (restr_env s rs_map) (np_restr_env env rs_map)\"  \n  apply (simp add: sub_env_def)\n  apply (auto)\n  apply (simp add: restr_env_def)\n  apply (simp add: np_restr_env_def)\n  apply (auto)\n  apply (case_tac \"lookup_mem rs_map x\")\n   apply (auto)\n  apply (simp add: non_prim_env_def)\n  apply (simp add: non_prim_entry_def)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"env x\")\n   apply (auto)\n  done\n  \nlemma restr_disj_res_map: \"\\<lbrakk> valid_res_map s rs_map; lookup_mem rs_map x = Some (r_s, rs_map');\n  lookup_res rs_map' x = empty_use_env \\<rbrakk> \\<Longrightarrow> disj_res_map rs_map'\"\n  apply (induct rs_map arbitrary: s)\n   apply (auto)\n  apply (case_tac \"x1 = x\")\n   apply (auto)\n   apply (rule_tac x=\"x\" and r_s=\"r_s\" in disj_add_res_map_rev)\n    apply (simp add: add_mem_def)\n    apply (simp add: valid_res_map_def)\n   apply (simp)\n  apply (simp add: valid_res_map_def)\n    (* - disjointness for induction *)\n  apply (cut_tac rs_map=\"rs_map\" and x=\"x1\" and r_s=\"x2\" in disj_add_res_map_rev)\n    apply (simp add: add_mem_def)\n   apply (simp add: scope_res_map_def)\n   apply (simp add: fresh_map_var_def)\n   apply (simp add: lookup_res_def)\n    (* - containment for induction *)\n  apply (cut_tac rs_map=\"rs_map\" and x=\"x1\" and r_s=\"x2\" and s=\"s\" in add_sub_res_map_rev)\n    apply (simp add: add_mem_def)\n   apply (simp add: scope_res_map_def)\n   apply (simp add: fresh_map_var_def)\n    (* - scope containment for induction *)\n  apply (cut_tac rs_map=\"rs_map\" and x=\"x1\" and r_s=\"x2\" in add_scope_res_map_rev)\n   apply (simp add: add_mem_def)\n  apply (auto)\n  done\n    \nlemma restr_sub_res_map: \"\\<lbrakk> sub_res_map s rs_map; scope_res_map rs_map;\n  lookup_mem rs_map x = Some (r_s, rs_map') \\<rbrakk> \\<Longrightarrow> sub_res_map (restr_env s rs_map') rs_map'\"\n  apply (cut_tac rs_map=\"rs_map\" and rs_map'=\"rs_map'\" and x=\"x\" and r_s=\"r_s\" in self_scope_use_env_ih2)\n    apply (auto)\n  apply (simp add: sub_res_map_def)\n  apply (auto)\n  apply (erule_tac x=\"xa\" in allE)\n   apply (simp add: sub_scope_use_env_def)\n   apply (erule_tac x=\"xa\" in allE)\n   apply (auto)\n   apply (simp add: restr_env_def)\n   apply (case_tac \"lookup_mem rs_map' xa\")\n  apply (auto)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (simp add: restr_env_def)\n  done\n    \nlemma restr_valid_res_map: \"\\<lbrakk> valid_res_map s rs_map; lookup_mem rs_map x = Some (r_s, rs_map') \\<rbrakk> \\<Longrightarrow> valid_res_map (restr_env s rs_map') rs_map'\"\n  apply (simp add: valid_res_map_def)\n  apply (auto)\n    apply (rule_tac restr_disj_res_map)\n      apply (simp add: valid_res_map_def)\n     apply (auto)\n    apply (cut_tac rs_map=\"rs_map\" and x=\"x\" in scope_res_map_fresh_lookup)\n      apply (auto)\n    apply (simp add: fresh_map_var_def)\n    apply (simp add: lookup_res_def)\n   apply (rule_tac restr_sub_res_map)\n     apply (auto)\n  apply (rule_tac self_scope_res_map)\n   apply (auto)\n  done\n  \nlemma dist_restr_contain_env: \"\\<lbrakk> sub_scope_use_env rs_map rs_map' \\<rbrakk> \\<Longrightarrow> contain_env (restr_env r_s rs_map) (restr_env r_s rs_map')\"    \n  apply (simp add: sub_scope_use_env_def)\n  apply (simp add: contain_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"restr_env r_s rs_map' x\")\n   apply (auto)\n   apply (simp add: restr_env_def)\n   apply (case_tac \"lookup_mem rs_map' x\")\n    apply (auto)\n  apply (simp add: restr_env_def)\n  done\n  \nlemma np_restr_add_contain_env: \"\\<lbrakk> contain_env r_s r_x \\<rbrakk> \\<Longrightarrow> contain_env (add_env (np_restr_env r_s rs_map) x t) (np_restr_env (add_env r_x x t) rs_map)\"    \n  apply (simp add: contain_env_def)\n  apply (auto)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (case_tac \"np_restr_env (add_env r_x x t) rs_map xa\")\n   apply (auto)\n    (* if x = xa, we know that rs_map has an entry, it's just a matter of showing that it's the same entry. *)\n  apply (case_tac \"x = xa\")\n   apply (case_tac \"np_restr_env (add_env r_x x t) rs_map xa \\<noteq> Some t\")\n    apply (simp add: add_env_def)\n    apply (simp add: np_restr_env_def)\n    apply (case_tac \"lookup_mem rs_map xa = None \\<and> non_prim_entry (\\<lambda>x'. if xa = x' then Some t else r_x x') xa\")\n     apply (auto)\n   apply (simp add: add_env_def)\n    (* otherwise, we know rs_map xa = None or r_x has a prim entry.  *)\n  apply (simp add: np_restr_env_def)\n  apply (case_tac \"lookup_mem rs_map xa = None \\<and> non_prim_entry (add_env r_x x t) xa\")\n   apply (auto)\n   apply (simp add: add_env_def)\n  apply (simp add: add_env_def)\n  apply (simp add: non_prim_entry_def)\n  done\n    \nlemma np_restr_add_contain_env2: \"\\<lbrakk> contain_env r_s r_x \\<rbrakk> \\<Longrightarrow> contain_env (add_env (np_restr_env r_s rs_map) x t) (np_restr_env (add_env r_x x t) (add_mem rs_map x r_c))\"     \n  apply (simp add: contain_env_def)\n  apply (auto)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (case_tac \"np_restr_env (add_env r_x x t) (add_mem rs_map x r_c) xa\")\n   apply (auto)\n    (* if x = xa, then since x wasn't restricted in the original, it wont be restricted here either *)\n  apply (case_tac \"x = xa\")\n   apply (simp add: add_env_def)\n   apply (simp add: np_restr_env_def)\n   apply (auto)\n   apply (case_tac \"lookup_mem (add_mem rs_map x r_c) x\")\n    apply (simp add: add_mem_def)\n   apply (auto)\n    (* for x \\<noteq> xa, since xa wasn't restricted in the original, either it has a lookup in rs_map or it is a prim entry *)\n  apply (simp add: np_restr_env_def)\n  apply (case_tac \"lookup_mem (add_mem rs_map x r_c) xa = None \\<and> non_prim_entry (add_env r_x x t) xa\")\n   apply (auto)\n    (* if you can find it in rs_map, you can find it here too *)\n   apply (simp add: add_env_def)\n   apply (simp add: add_mem_def)\n    (* if it is prim, it will be prim in the new result as well *)\n  apply (simp add: add_env_def)\n  apply (simp add: non_prim_entry_def)\n  done    \n    \nlemma restr_env_eq: \"\\<lbrakk> sub_res_map s rs_map; sub_env s env \\<rbrakk> \\<Longrightarrow> restr_env env rs_map = env\"    \n  apply (case_tac \"\\<forall> x. restr_env env rs_map x = env x\")  \n   apply (auto)\n  apply (simp add: restr_env_def)\n  apply (case_tac \"lookup_mem rs_map x = None\")\n   apply (auto)\n  apply (simp add: sub_env_def)\n  apply (simp add: sub_res_map_def)\n  done\n    \n    (* attempt to show restricting the env to rs_map is acceptable. *)(*\nlemma well_typed_restr_ih: \"\\<lbrakk> sub_res_map s rs_map; sub_env s env (*scope_res_map rs_map; scope_use_env rs_map r_s1;*)\n  well_typed env r_s1 v tau r_s2 rx; contain_env env' (np_restr_env env rs_map) \\<rbrakk> \\<Longrightarrow> well_typed env' r_s1 v tau r_s2 rx\"        \n  apply (induct v arbitrary: env env' tau r_s1 r_s2 rx rs_map)\n        apply (auto)\n    (* var case p1. we must show the de-referenced name will still exist. *)\n      apply (case_tac \"\\<not> non_prim_entry env (deref_name x1a x2a)\")\n       apply (simp add: np_restr_env_def)\n       apply (simp add: contain_env_def)\n       apply (erule_tac x=\"deref_name x1a x2a\" in allE)\n       apply (auto)\n      apply (case_tac \"r_s1 x1a = NoPerm\")\n       apply (cut_tac r_x=\"ereq_use_env x1a tau\" and r_s=\"r_s1\" and x=\"x1a\" in leq_use_none)\n         apply (auto)\n       apply (cut_tac x=\"x1a\" and tau=\"tau\" in ereq_use_none)\n        apply (simp add: non_prim_entry_def)\n       apply (auto)\n      apply (simp add: scope_use_env_def)\n      apply (erule_tac x=\"x1a\" in allE)\n      apply (auto)\n      apply (simp add: contain_env_def)\n      apply (erule_tac x=\"x1a\" in allE)\n      apply (case_tac \"env' x1a\")\n       apply (auto)\n       apply (simp add: np_restr_env_def)\n      apply (simp add: np_restr_env_def)\n    (* pair case *)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (rule_tac x=\"r_s3\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n     apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" and rs_map=\"rs_map\" in trans_scope_use_env2)\n       apply (simp)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"r_s2a\" in exI)\n    apply (auto)\n    apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" and rs_map=\"rs_map\" in trans_scope_use_env2)\n      apply (simp)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n    apply (rule_tac x=\"rx1\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"rx2\" in exI)\n    apply (auto)\n    (* lam case *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_end\" in exI)\n   apply (rule_tac x=\"r_s'\" in exI)\n    (* - split over x1a in rs_map *)\n  apply (case_tac \"fresh_map_var rs_map x1a\")\n    (* - containment for induction *)\n    apply (cut_tac env_c=\"np_restr_env (add_env env x1a t1) (add_mem rs_map x1a empty_use_env)\" and\n      env_b=\"add_env (np_restr_env env rs_map) x1a t1\" and env_a=\"add_env env' x1a t1\" in trans_contain_env)\n      apply (rule_tac dist_add_contain_env)\n      apply (simp)\n     apply (rule_tac np_restr_add_contain_env2)\n     apply (rule_tac id_contain_env)\n    (* - scoping for induction *)\n    apply (cut_tac rs_map=\"rs_map\" and r_s=\"rxa\" and x=\"x1a\" and r=\"r\" and r_c=\"empty_use_env\" in dist_add_scope_use_env)\n     apply (rule_tac r_s=\"r_s1\" in trans_scope_use_env2)\n      apply (simp_all)\n    (* - scoping for induction p2 *)\n    apply (cut_tac rs_map=\"rs_map\" and x=\"x1a\" and r_s=\"empty_use_env\" in add_scope_res_map)\n        apply (auto)\n     apply (simp add: strong_use_env_def)\n     apply (simp add: empty_use_env_def)\n    apply (rule_tac empty_scope_use_env)\n    (* if x1a is in rs_map, we have a simpler containment induction *)\n   apply (cut_tac env_c=\"np_restr_env (add_env env x1a t1) rs_map\" and\n      env_b=\"add_env (np_restr_env env rs_map) x1a t1\" and env_a=\"add_env env' x1a t1\" in trans_contain_env)\n     apply (rule_tac dist_add_contain_env)\n     apply (simp)\n    apply (rule_tac np_restr_add_contain_env)\n    apply (rule_tac id_contain_env)\n    (* - scoping for induction *)\n   apply (cut_tac rs_map=\"rs_map\" and r_s=\"rxa\" and x=\"x1a\" and r=\"r\" in add_scope_use_env)\n     apply (rule_tac r_s=\"r_s1\" in trans_scope_use_env2)\n      apply (simp_all)\n   apply (simp add: fresh_map_var_def)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" and rs_map=\"rs_map\" in trans_scope_use_env2)\n    apply (simp)\n   apply (rule_tac well_typed_perm_leq)\n   apply (auto)\n  done*)\n    \nlemma well_typed_restr: \"\\<lbrakk> (*scope_res_map rs_map; scope_use_env rs_map r_s1; non_prim_env env; *)\n  sub_res_map s rs_map; sub_env s env; well_typed env r_s1 v tau r_s2 rx \\<rbrakk> \\<Longrightarrow>\n  well_typed (restr_env env rs_map) r_s1 v tau r_s2 rx\"  \n  apply (simp add: restr_env_eq)\n  (*apply (rule_tac well_typed_restr_ih)\n     apply (auto)\n  apply (simp add: contain_env_def)\n  apply (auto)\n  apply (case_tac \"np_restr_env env rs_map x\")\n   apply (auto)\n  apply (simp add: np_restr_env_def)\n  apply (simp add: restr_env_def)\n  apply (auto)\n  apply (case_tac \"lookup_mem rs_map x = None \\<and> non_prim_entry env x\")\n   apply (auto)\n  apply (simp add: non_prim_env_def)\n  apply (simp add: non_prim_entry_def)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)  *)\n  done\n  \nlemma well_typed_list_restr: \"\\<lbrakk> (*scope_res_map rs_map; non_prim_env env;*) sub_res_map s rs_map;\n  sub_env s env; well_typed_list env rs_list el n tau \\<rbrakk> \\<Longrightarrow>\n  well_typed_list (restr_env env rs_map) rs_list el n tau\"\n  apply (induct el arbitrary: n)\n   apply (auto)\n  apply (rule_tac well_typed_restr)\n    apply (auto)(*\n  apply (rule_tac self_scope_use_env)\n  apply (simp)*)\n  done\n    \ndefinition rs_free_vars where\n  \"rs_free_vars rs_map e = (\\<forall> x. lookup_mem rs_map x = None \\<longrightarrow> x \\<notin> free_vars e)\"\n\nlemma rem_add_restr_env: \"rem_env (restr_env s rs_map) x = restr_env (rem_env s x) (add_mem rs_map x r_c)\"  \n  apply (case_tac \"\\<forall> y. rem_env (restr_env s rs_map) x y = restr_env (rem_env s x) (add_mem rs_map x r_c) y\")\n   apply (auto)\n  apply (simp add: rem_env_def)\n  apply (simp add: add_mem_def)\n  apply (simp add: restr_env_def)\n  apply (case_tac \"x = y\")\n   apply (auto)\n  apply (simp add: restr_env_def)\n  apply (case_tac \"lookup_mem rs_map y\")\n   apply (auto)\n  done\n    \n    (* a lemma that states that every free variable of e appears in rs_map *)\nlemma well_typed_rs_free_vars: \"\\<lbrakk> scope_use_env rs_map r_s1; well_typed env r_s1 e tau r_s2 rx; non_prim_env env \\<rbrakk> \\<Longrightarrow> rs_free_vars rs_map e\"\n  apply (simp add: rs_free_vars_def)\n  apply (auto)\n  apply (case_tac \"r_s1 x = NoPerm\")\n   apply (cut_tac ?r_s1.0=\"r_s1\" and x=\"x\" and e=\"e\" in well_typed_no_npv_use)\n     apply (auto)\n   apply (simp add: non_prim_vars_def)\n   apply (simp add: non_prim_env_def)\n   apply (erule_tac x=\"x\" in allE)\n   apply (cut_tac env=\"env\" and x=\"x\" and e=\"e\" in well_typed_fv_env_use)\n     apply (auto)\n   apply (simp add: non_prim_entry_def)\n  apply (simp add: scope_use_env_def)\n  done\n\n\n    (*\nlemma aff_value_restr: \"\\<lbrakk> aff_value s e; rs_free_vars (rs_map :: perm_use_env p_stack) e \\<rbrakk> \\<Longrightarrow> aff_value (restr_env s rs_map) e\"    \n  apply (induct e arbitrary: s rs_map)\n       apply (auto)\n    (* var case. *)\n        apply (simp add: restr_env_def)\n        apply (simp add: rs_free_vars_def)\n        apply (erule_tac x=\"x1a\" in allE)\n        apply (auto)\n    (* if cases 1 - 3. *)\n       apply (simp add: rs_free_vars_def)\n      apply (simp add: rs_free_vars_def)\n     apply (simp add: rs_free_vars_def)\n    (* lam case. *)\n    apply (case_tac \"\\<not> rs_free_vars (add_mem rs_map x1a empty_use_env) e\")\n     apply (simp add: rs_free_vars_def)\n     apply (auto)\n     apply (erule_tac x=\"x\" in allE)\n     apply (simp add: add_mem_def)\n     apply (case_tac \"x = x1a\")\n      apply (auto)\n    apply (cut_tac s=\"s\" and rs_map=\"rs_map\" and x=\"x1a\" and r_c=\"empty_use_env\" in rem_add_restr_env)\n    apply (auto)\n    (* app cases 1 + 2. *)\n   apply (simp add: rs_free_vars_def)\n  apply (simp add: rs_free_vars_def)\n  done\n    \nlemma neg_aff_value_restr: \"\\<lbrakk> \\<not> aff_value s e; rs_free_vars (rs_map :: perm_use_env p_stack) e \\<rbrakk> \\<Longrightarrow> \\<not> aff_value (restr_env s rs_map) e\"    \n  apply (induct e arbitrary: s rs_map)\n       apply (auto)\n    (* var case. *)\n        apply (simp add: restr_env_def)\n        apply (simp add: rs_free_vars_def)\n        apply (erule_tac x=\"x1a\" in allE)\n        apply (auto)\n    (* if cases 1 - 3. *)\n       apply (simp add: rs_free_vars_def)\n      apply (simp add: rs_free_vars_def)\n     apply (simp add: rs_free_vars_def)\n    (* lam case. *)\n    apply (case_tac \"\\<not> rs_free_vars (add_mem rs_map x1a empty_use_env) e\")\n     apply (simp add: rs_free_vars_def)\n     apply (auto)\n     apply (erule_tac x=\"x\" in allE)\n     apply (simp add: add_mem_def)\n     apply (case_tac \"x = x1a\")\n      apply (auto)\n    apply (cut_tac s=\"s\" and rs_map=\"rs_map\" and x=\"x1a\" and r_c=\"empty_use_env\" in rem_add_restr_env)\n    apply (auto)\n    (* app cases 1 + 2. *)\n   apply (simp add: rs_free_vars_def)\n  apply (simp add: rs_free_vars_def)\n  done\n    \nlemma aff_pair_restr: \"\\<lbrakk> aff_pair s v1 v2 a; rs_free_vars (rs_map :: perm_use_env p_stack) v1; rs_free_vars rs_map v2 \\<rbrakk> \\<Longrightarrow> aff_pair (restr_env s rs_map) v1 v2 a\"\n  apply (simp add: aff_pair_def)\n  apply (auto)\n     apply (cut_tac s=\"s\" and rs_map=\"rs_map\" and e=\"v1\" in neg_aff_value_restr)\n       apply (auto)\n    apply (cut_tac s=\"s\" and rs_map=\"rs_map\" and e=\"v2\" in neg_aff_value_restr)\n      apply (auto)\n   apply (cut_tac s=\"s\" and rs_map=\"rs_map\" and e=\"v1\" in aff_value_restr)\n     apply (auto)\n  apply (cut_tac s=\"s\" and rs_map=\"rs_map\" and e=\"v2\" in aff_value_restr)\n    apply (auto)\n  done\n    *)\nlemma well_typed_mv_restr: \"\\<lbrakk> (*scope_res_map rs_map; non_prim_env env;*)\n  sub_res_map s rs_map; sub_env s env;  well_typed_mem_value s env (lookup_res rs_map x) tau v \\<rbrakk> \\<Longrightarrow>\n  well_typed_mem_value (restr_env s rs_map) (restr_env env rs_map) (lookup_res rs_map x) tau v\"    \n  apply (case_tac v)\n  apply (auto)\n  apply (rule_tac x=\"rs_list\" in exI)\n  apply (auto)\n   apply (rule_tac well_typed_list_restr)\n    apply (auto)(*\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (auto)\n(*\n    apply (rule_tac aff_pair_restr)\n      apply (auto)\n     apply (rule_tac well_typed_rs_free_vars)\n      apply (auto)\n    apply (rule_tac well_typed_rs_free_vars)\n     apply (auto)*)\n   apply (rule_tac well_typed_restr)\n     apply (auto)\n   apply (rule_tac self_scope_use_env)\n   apply (simp)\n  apply (rule_tac well_typed_restr)\n    apply (auto)\n  apply (rule_tac self_scope_use_env)\n  apply (simp)*)\n  done\n\ndefinition spec_scope_use_env where\n  \"spec_scope_use_env rs_map rs_map' = (\\<forall> y. case lookup_mem rs_map' y of None \\<Rightarrow> True | Some (r_s, rs_map') \\<Rightarrow> lookup_mem rs_map y = Some (r_s, rs_map'))\"\n\nlemma add_spec_scope_use_env: \"\\<lbrakk> spec_scope_use_env rs_map rs_map'; fresh_map_var rs_map x \\<rbrakk> \\<Longrightarrow> spec_scope_use_env (add_mem rs_map x r_s) rs_map'\"\n  apply (simp add: spec_scope_use_env_def)\n  apply (auto)\n  apply (case_tac \"lookup_mem rs_map' y\")\n   apply (auto)\n  apply (erule_tac x=\"y\" in allE)\n  apply (auto)\n  apply (simp add: fresh_map_var_def)\n  apply (simp add: add_mem_def)\n  apply (auto)\n  done\n    \nlemma self_spec_scope_use_env: \"\\<lbrakk> scope_res_map rs_map; lookup_mem rs_map x = Some (r_s, rs_map') \\<rbrakk> \\<Longrightarrow> spec_scope_use_env rs_map rs_map'\"\n  apply (induct rs_map)\n   apply (auto)\n    (* if x1 = x, rs_map' is only one level down from rs_map. any y that can be sucessfully looked-up from rs_map' is distinct from x1 by freshness,\n      meaning we look it up from rs_map' *)\n  apply (case_tac \"x1 = x\")\n   apply (auto)\n   apply (simp add: spec_scope_use_env_def)\n   apply (auto)\n   apply (simp add: scope_res_map_def)\n   apply (simp add: fresh_map_var_def)\n   apply (case_tac \"lookup_mem rs_map' y\")\n    apply (auto)\n    (* otherwise we have to induct *)\n  apply (cut_tac rs_map=\"rs_map\" and x=\"x1\" and r_s=\"x2\" in add_scope_res_map_rev)\n   apply (simp add: add_mem_def)\n  apply (auto)\n  apply (cut_tac rs_map=\"rs_map\" and x=\"x1\" and rs_map'=\"rs_map'\" in add_spec_scope_use_env)\n    apply (simp)\n   apply (simp add: scope_res_map_def)\n  apply (simp add: add_mem_def)\n  done    \n    (*\nlemma well_typed_restr_state: \"\\<lbrakk> well_typed_state s env rs_map; lookup_mem rs_map x = Some (r_s, rs_map') \\<rbrakk> \\<Longrightarrow>\n  well_typed_state (restr_env s rs_map') (restr_env env rs_map') rs_map'\"\n  apply (simp add: well_typed_state_def)\n  apply (auto)\n    apply (rule_tac restr_sub_env)\n    apply (simp)\n   apply (rule_tac restr_valid_res_map)\n    apply (auto)\n  apply (case_tac \"restr_env s rs_map' xa\")\n   apply (auto)\n  apply (case_tac \"s xa = None\")\n   apply (simp add: restr_env_def)\n   apply (case_tac \"lookup_mem rs_map' xa\")\n    apply (auto)\n  apply (case_tac \"restr_env env rs_map' xa\")\n   apply (auto)\n   apply (erule_tac x=\"xa\" in allE)\n   apply (case_tac \"env xa \\<noteq> None\")\n    apply (simp add: restr_env_def)\n    apply (case_tac \"lookup_mem rs_map' xa\")\n     apply (auto)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (auto)\n  apply (case_tac \"env xa\")\n   apply (auto)\n  apply (case_tac \"aa \\<noteq> ab\")\n   apply (simp add: restr_env_def)\n   apply (case_tac \"lookup_mem rs_map' xa\")\n    apply (auto)\n  apply (rule_tac well_typed_mv_restr)\n   apply (simp add: valid_res_map_def)\n   apply (auto)\n   apply (rule_tac rs_map=\"rs_map\" and x=\"x\" in self_scope_res_map)\n    apply (auto)\n  apply (simp add: restr_env_def)\n  apply (case_tac \"lookup_mem rs_map' xa\")\n   apply (auto)\n  apply (simp add: lookup_res_def)\n  apply (cut_tac rs_map=\"rs_map\" and rs_map'=\"rs_map'\" in self_spec_scope_use_env)\n    apply (auto)\n   apply (simp add: valid_res_map_def)\n  apply (simp add: spec_scope_use_env_def)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (auto)\n  done    *)\n    \nend", "meta": {"author": "dcco", "repo": "perm_lang_ax1", "sha": "5742edc2c5db417002ed6b8acd159c522b3e6e38", "save_path": "github-repos/isabelle/dcco-perm_lang_ax1", "path": "github-repos/isabelle/dcco-perm_lang_ax1/perm_lang_ax1-5742edc2c5db417002ed6b8acd159c522b3e6e38/perm_unsafe_lift/ReduceRestr.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5813030761371503, "lm_q2_score": 0.4882833952958347, "lm_q1q2_score": 0.28384063971216084}}
{"text": "(*  Title:       BDD\n    Author:      Veronika Ortner and Norbert Schirmer, 2004\n    Maintainer:  Norbert Schirmer,  norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  \nNormalizeTotalProof.thy\n\nCopyright (C) 2004-2008 Veronika Ortner and Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection \\<open>Proof of Procedure Normalize\\<close>\ntheory NormalizeTotalProof imports LevellistProof ShareReduceRepListProof \n                        RepointProof begin\n\nhide_const (open) DistinctTreeProver.set_of tree.Node tree.Tip\n\nlemma  (in Normalize_impl) Normalize_modifies:\n  shows\n   \"\\<forall>\\<sigma>. \\<Gamma>\\<turnstile>{\\<sigma>} \\<acute>p :== PROC Normalize (\\<acute>p) \n     {t. t may_only_modify_globals \\<sigma> in [rep,mark,low,high,next]}\"\n  apply (hoare_rule HoarePartial.ProcRec1)\n  apply (vcg spec=modifies)\n  done\n\nlemma (in Normalize_impl) Normalize_spec: \n  shows \"\\<forall>\\<sigma> pret prebdt. \\<Gamma>\\<turnstile>\\<^sub>t\n  \\<lbrace>\\<sigma>. Dag \\<acute>p \\<acute>low \\<acute>high pret \\<and> ordered pret \\<acute>var \\<and> \n   \\<acute>p \\<noteq> Null \\<and> (\\<forall>n. n \\<in> set_of pret \\<longrightarrow> \\<acute>mark n = \\<acute>mark \\<acute>p) \\<and> \n   bdt pret \\<acute>var = Some prebdt\\<rbrace>  \n  \\<acute>p :== PROC Normalize(\\<acute>p)\n  \\<lbrace>(\\<forall>pt. pt \\<notin> set_of pret \n    \\<longrightarrow> \\<^bsup>\\<sigma>\\<^esup>rep pt = \\<acute>rep pt \\<and> \\<^bsup>\\<sigma>\\<^esup>low pt = \\<acute>low pt \\<and> \\<^bsup>\\<sigma>\\<^esup>high pt = \\<acute>high pt \\<and> \n        \\<^bsup>\\<sigma>\\<^esup>mark pt = \\<acute>mark pt \\<and> \\<^bsup>\\<sigma>\\<^esup>next pt = \\<acute>next pt) \\<and> \n  (\\<exists>postt. Dag \\<acute>p \\<acute>low \\<acute>high postt \\<and> reduced postt \\<and> \n  shared postt \\<^bsup>\\<sigma>\\<^esup>var \\<and> ordered postt \\<^bsup>\\<sigma>\\<^esup>var \\<and>\n  set_of postt \\<subseteq> set_of pret \\<and> \n  (\\<exists>postbdt.  bdt postt \\<^bsup>\\<sigma>\\<^esup>var = Some postbdt \\<and> prebdt \\<sim> postbdt)) \\<and> \n  (\\<forall> no. no \\<in> set_of pret \\<longrightarrow> \\<acute>mark no = (\\<not> \\<^bsup>\\<sigma>\\<^esup>mark \\<^bsup>\\<sigma>\\<^esup>p)) \\<rbrace>\"\n  apply (hoare_rule HoareTotal.ProcNoRec1)\n  apply (hoare_rule anno=\"\n    \\<acute>levellist :==replicate (\\<acute>p\\<rightarrow>\\<acute>var + 1) Null;;\n    \\<acute>levellist :== CALL Levellist (\\<acute>p, (\\<not> \\<acute>p\\<rightarrow>\\<acute>mark) , \\<acute>levellist);;\n    (ANNO (\\<tau>,ll). \\<lbrace>\\<tau>. Levellist \\<acute>levellist \\<acute>next ll \\<and>\n                   Dag \\<^bsup>\\<sigma>\\<^esup>p \\<^bsup>\\<sigma>\\<^esup>low \\<^bsup>\\<sigma>\\<^esup>high pret \\<and> ordered pret \\<^bsup>\\<sigma>\\<^esup>var \\<and> \\<^bsup>\\<sigma>\\<^esup>p \\<noteq> Null \\<and> \n                 (bdt pret \\<^bsup>\\<sigma>\\<^esup>var  = Some prebdt) \\<and> \n                 wf_ll pret ll \\<^bsup>\\<sigma>\\<^esup>var \\<and> \n                 length \\<acute>levellist = ((\\<^bsup>\\<sigma>\\<^esup>p \\<rightarrow> \\<^bsup>\\<sigma>\\<^esup>var) + 1) \\<and> \n                 wf_marking pret \\<^bsup>\\<sigma>\\<^esup>mark \\<acute>mark (\\<not> \\<^bsup>\\<sigma>\\<^esup>mark \\<^bsup>\\<sigma>\\<^esup>p) \\<and> \n                 (\\<forall>pt. pt \\<notin> set_of pret \\<longrightarrow> \\<^bsup>\\<sigma>\\<^esup>next pt = \\<acute>next pt) \\<and>\n                 \\<acute>low = \\<^bsup>\\<sigma>\\<^esup>low \\<and> \\<acute>high = \\<^bsup>\\<sigma>\\<^esup>high  \\<and>  \\<acute>p = \\<^bsup>\\<sigma>\\<^esup>p \\<and> \\<acute>rep = \\<^bsup>\\<sigma>\\<^esup>rep \\<and> \n                 \\<acute>var = \\<^bsup>\\<sigma>\\<^esup>var\\<rbrace> \n    \\<acute>n :==0;;\n    WHILE (\\<acute>n < length \\<acute>levellist) \n    INV \\<lbrace>Levellist \\<acute>levellist \\<acute>next ll \\<and>\n         Dag \\<^bsup>\\<sigma>\\<^esup>p \\<^bsup>\\<sigma>\\<^esup>low \\<^bsup>\\<sigma>\\<^esup>high pret \\<and> ordered pret \\<^bsup>\\<sigma>\\<^esup>var \\<and> \\<^bsup>\\<sigma>\\<^esup>p \\<noteq> Null \\<and> \n         (bdt pret \\<^bsup>\\<sigma>\\<^esup>var  = Some prebdt) \\<and> wf_ll pret ll \\<^bsup>\\<sigma>\\<^esup>var  \\<and> \n         length \\<^bsup>\\<tau>\\<^esup>levellist = ((\\<^bsup>\\<sigma>\\<^esup>p \\<rightarrow> \\<^bsup>\\<sigma>\\<^esup>var) + 1) \\<and> \n         wf_marking pret \\<^bsup>\\<sigma>\\<^esup>mark \\<^bsup>\\<tau>\\<^esup>mark (\\<not> \\<^bsup>\\<sigma>\\<^esup>mark \\<^bsup>\\<sigma>\\<^esup>p) \\<and>\n         \\<^bsup>\\<tau>\\<^esup>low = \\<^bsup>\\<sigma>\\<^esup>low \\<and> \\<^bsup>\\<tau>\\<^esup>high = \\<^bsup>\\<sigma>\\<^esup>high  \\<and>  \\<^bsup>\\<tau>\\<^esup>p = \\<^bsup>\\<sigma>\\<^esup>p \\<and> \\<^bsup>\\<tau>\\<^esup>rep = \\<^bsup>\\<sigma>\\<^esup>rep  \\<and> \\<^bsup>\\<tau>\\<^esup>var = \\<^bsup>\\<sigma>\\<^esup>var \\<and>\n         \\<acute>n \\<le> length  \\<^bsup>\\<tau>\\<^esup>levellist \\<and>\n         (\\<forall>pt i. (pt \\<notin> set_of pret \\<or> (\\<acute>n <= i \\<and> pt \\<in> set (ll ! i) \\<and>\n                  i <length \\<^bsup>\\<tau>\\<^esup>levellist ) \n                  \\<longrightarrow> \\<^bsup>\\<sigma>\\<^esup>rep pt = \\<acute>rep pt)) \\<and> \n         \\<acute>rep ` Nodes \\<acute>n ll \\<subseteq> Nodes \\<acute>n ll \\<and> \n         (\\<forall>no \\<in> Nodes \\<acute>n ll.\n            no\\<rightarrow>\\<acute>rep\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>var <= no\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>var \\<and> \n            (\\<exists>not nort. Dag (\\<acute>rep no) (\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>low ) (\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>high ) nort \\<and>\n               Dag no \\<^bsup>\\<sigma>\\<^esup>low \\<^bsup>\\<sigma>\\<^esup>high not \\<and> reduced nort \\<and> \n               ordered nort \\<^bsup>\\<sigma>\\<^esup>var \\<and> set_of nort \\<subseteq> \\<acute>rep ` Nodes \\<acute>n ll \\<and> \n               (\\<forall> no \\<in> set_of nort. \\<acute>rep no = no) \\<and> \n               (\\<exists>nobdt norbdt. bdt not \\<^bsup>\\<sigma>\\<^esup>var = Some nobdt \\<and> \n                  bdt nort \\<^bsup>\\<sigma>\\<^esup>var = Some norbdt \\<and> nobdt \\<sim> norbdt))) \\<and>\n         (\\<forall>t1 t2. \n             t1\\<in>Dags (\\<acute>rep `(Nodes \\<acute>n ll))(\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>low )(\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>high)\\<and>\n             t2\\<in>Dags (\\<acute>rep `(Nodes \\<acute>n ll))(\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>low )(\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>high)\n             \\<longrightarrow> \n             isomorphic_dags_eq t1 t2  \\<^bsup>\\<sigma>\\<^esup>var) \\<and>\n         \\<acute>levellist = \\<^bsup>\\<tau>\\<^esup>levellist \\<and> \\<acute>next = \\<^bsup>\\<tau>\\<^esup>next \\<and> \\<acute>mark = \\<^bsup>\\<tau>\\<^esup>mark \\<and> \\<acute>low = \\<^bsup>\\<sigma>\\<^esup>low \\<and> \n         \\<acute>high = \\<^bsup>\\<sigma>\\<^esup>high  \\<and> \\<acute>p = \\<^bsup>\\<sigma>\\<^esup>p \\<and>  \\<acute>var = \\<^bsup>\\<sigma>\\<^esup>var \\<rbrace>\n    VAR MEASURE (length \\<acute>levellist - \\<acute>n)\n    DO\n    CALL ShareReduceRepList(\\<acute>levellist ! \\<acute>n);;\n    \\<acute>n :==\\<acute>n + 1\n    OD\n    \\<lbrace>(\\<exists>postnormt. Dag (\\<acute>rep \\<^bsup>\\<sigma>\\<^esup>p) (\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>low ) (\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>high ) postnormt \\<and> \n      reduced postnormt \\<and> shared postnormt \\<^bsup>\\<sigma>\\<^esup>var \\<and> \n      ordered postnormt \\<^bsup>\\<sigma>\\<^esup>var \\<and> set_of postnormt \\<subseteq> set_of pret \\<and> \n      (\\<exists>postnormbdt. bdt postnormt \\<^bsup>\\<sigma>\\<^esup>var = Some postnormbdt \\<and> prebdt \\<sim> postnormbdt) \\<and>\n      (\\<forall> no \\<in> set_of postnormt. (\\<acute>rep no = no))) \\<and> \n      ordered pret \\<^bsup>\\<sigma>\\<^esup>var  \\<and> \\<^bsup>\\<sigma>\\<^esup>p \\<noteq> Null \\<and> \n      (\\<forall> pt. pt \\<notin> set_of pret \\<longrightarrow> \\<^bsup>\\<sigma>\\<^esup>rep pt = \\<acute>rep pt) \\<and> \n      \\<acute>levellist = \\<^bsup>\\<tau>\\<^esup>levellist \\<and> \\<acute>next = \\<^bsup>\\<tau>\\<^esup>next \\<and> \\<acute>mark = \\<^bsup>\\<tau>\\<^esup>mark \\<and> \\<acute>low = \\<^bsup>\\<sigma>\\<^esup>low \\<and> \\<acute>high = \\<^bsup>\\<sigma>\\<^esup>high \\<and>\n      \\<acute>p = \\<^bsup>\\<sigma>\\<^esup>p \\<and> (\\<forall> no. no \\<in> set_of pret \\<longrightarrow> \\<acute>mark no = (\\<not> \\<^bsup>\\<sigma>\\<^esup>mark \\<^bsup>\\<sigma>\\<^esup>p)) \\<rbrace>)\n    ;;\n    \\<acute>p :== CALL Repoint (\\<acute>p)\"\n    in HoareTotal.annotateI)\n  apply (vcg spec=spec_total)\n  prefer 2\n    (*from precondition of inner spec to invariant *)\n  apply    (simp add: Nodes_def null_comp_def)\n    (*from inner spec to postcondition *) \n  apply   (rule_tac x=pret in exI)\n  apply   clarify\n  apply   (rule conjI)\n  apply    clarsimp\n  apply    (case_tac i)\n  apply     simp\n  apply    simp\n  apply   (rule conjI)\n  apply    simp\n  apply   (rule conjI)\n  apply    simp\n  apply   (rule conjI)\n  apply    simp\n  apply   clarify\n  apply   (simp (no_asm_use) only: simp_thms) \n  apply   (rule_tac x=\"ll\" in exI)\n  apply   (rule conjI)\n  apply    assumption\n  apply   clarify\n  apply   (simp only: simp_thms triv_forall_equality True_implies_equals) \n  apply   (rule_tac x=postnormt in exI)\n  apply   (rule conjI)\n  apply    simp\n  apply   (rule conjI)\n  apply    simp\n  apply   clarify\n  apply   (simp (no_asm_simp))\n  prefer 2\n    (*while-while-Fall: while nb und Schleifenbdg gelten \\<longrightarrow> while (nb+1)*)\n  apply   clarify\n  apply   (simp only: simp_thms triv_forall_equality True_implies_equals)\n  apply   (rule_tac x=\"ll!n\" in exI)\n  apply   (rule conjI)\n  apply   (simp add: Levellist_def)\n  prefer 3\n    (*while-end-Fall: INV nb gilt und Schleifenbdg falsch \\<longrightarrow> Nachbdg while*)\n  apply   (clarify)\n  apply   (simp (no_asm_use) only: simp_thms triv_forall_equality True_implies_equals) \nproof -\n  \\<comment> \\<open>End of while (invariant + false condition) to end of inner SPEC\\<close>\n  fix var p rep mark vara lowa higha pa levellista repa marka nexta varb ll  \n    nb pret prebdt  and low :: \"ref \\<Rightarrow> ref\" and \n    high :: \"ref \\<Rightarrow> ref\" and repb :: \"ref \\<Rightarrow> ref\"\n  assume ll: \"Levellist levellista nexta ll\"\n  assume wf_lla: \"wf_ll pret ll var\"\n  assume length_lla: \"length levellista = var p + 1\"\n  assume ord_pret: \"ordered pret var\"\n  assume pnN: \" p \\<noteq> Null\"\n  assume rep_repb_nc: \n    \"\\<forall>pt i. pt \\<notin> set_of pret \\<or> nb \\<le> i \\<and> pt \\<in> set (ll ! i) \\<and> \n    i < length levellista \n    \\<longrightarrow> rep pt = repb pt\"\n\n  assume wf_marking_prop: \" wf_marking pret mark marka (\\<not> mark p)\"\n  assume pret_dag: \"Dag p low high pret\"\n  assume prebdt: \"bdt pret var = Some prebdt\"\n  assume not_nbslla: \"\\<not> nb < length levellista\"\n  assume nb_le_lla: \" nb \\<le> length levellista\"\n  \n  assume normalize_prop: \"\\<forall>no\\<in>Nodes nb ll.\n    var (repb no) \\<le> var no \\<and>\n    (\\<exists>not nort. Dag (repb no) (repb \\<propto> low) (repb \\<propto> high) nort \\<and>\n    Dag no low high not \\<and> reduced nort \\<and> ordered nort var \\<and> \n    set_of nort \\<subseteq> repb ` Nodes nb ll \\<and> \n    (\\<forall>no\\<in>set_of nort. repb no = no) \\<and> \n    (\\<exists>nobdt norbdt. bdt not var = Some nobdt \\<and> \n    bdt nort var = Some norbdt \\<and> nobdt \\<sim> norbdt))\"\n  assume repbNodes_in_Nodes: \" repb ` Nodes nb ll \\<subseteq> Nodes nb ll\"\n  assume shared_mult_dags: \n    \"\\<forall>t1 t2. t1 \\<in> Dags (repb ` Nodes nb ll) (repb \\<propto> low) (repb \\<propto> high) \\<and> \n    t2 \\<in> Dags (repb ` Nodes nb ll) (repb \\<propto> low) (repb \\<propto> high) \n    \\<longrightarrow> isomorphic_dags_eq t1 t2 var\"\n  show \"(\\<exists>postnormt. Dag (repb p) (repb \\<propto> low) (repb \\<propto> high) postnormt \\<and>\n    reduced postnormt \\<and> shared postnormt var \\<and>\n    ordered postnormt var \\<and> set_of postnormt \\<subseteq> set_of pret \\<and> \n    (\\<exists>postnormbdt. \n    bdt postnormt var = Some postnormbdt \\<and> prebdt \\<sim> postnormbdt) \\<and> \n    (\\<forall> no \\<in> set_of postnormt. repb no = no)) \\<and>\n    ordered pret var \\<and> p \\<noteq> Null \\<and> \n    (\\<forall>pt. pt \\<notin> set_of pret \\<longrightarrow> rep pt = repb pt) \\<and>  \n    (\\<forall>no. no \\<in> set_of pret \\<longrightarrow> marka no = (\\<not> mark p))\"\n\n  proof -\n    from ll have length_ll_eq: \"length levellista = length ll\"\n      by (simp add: Levellist_length)\n    from rep_repb_nc have rep_nc_post: \"\\<forall>pt. pt \\<notin> set_of pret \\<longrightarrow> rep pt = repb pt\"\n      by auto\n    from pnN pret_dag obtain lt rt where pret_def: \"pret = Node lt p rt\"\n      by auto\n    from wf_marking_prop pret_def \n    have marking_inverted: \"(\\<forall>no. no \\<in> set_of pret \\<longrightarrow> marka no = (\\<not> mark p))\"\n      by (simp add: wf_marking_def)\n    from not_nbslla nb_le_lla have nb_length_lla: \"nb = length levellista\"\n      by simp\n    with length_lla have varp_s_nb: \"var p < nb\"\n      by simp\n    from pret_def have p_in_pret: \"p \\<in> set_of pret\"\n      by simp\n    with wf_lla have \"p \\<in> set (ll ! (var p))\" \n      by (simp add: wf_ll_def)\n    with varp_s_nb have p_in_Nodes: \"p \\<in> Nodes nb ll\"\n      by (auto simp add: Nodes_def)\n    with normalize_prop obtain not nort where\n      varrepno_varno: \" var (repb p) \\<le> var p\" and\n      nort_dag: \"Dag (repb p) (repb \\<propto> low) (repb \\<propto> high) nort\" and\n      not_dag: \" Dag p low high not\" and\n      red_nort: \"reduced nort\" and\n      ord_nort: \"ordered nort var\" and\n      nort_in_repNodes: \" set_of nort \\<subseteq> repb ` Nodes nb ll\" and\n      nort_repb: \"(\\<forall>no\\<in>set_of nort. repb no = no)\" and\n      bdt_prop: \"\\<exists>nobdt norbdt. bdt not var = Some nobdt \\<and> bdt nort var = Some norbdt \\<and>\n      nobdt \\<sim> norbdt\"\n      by auto\n    \n    from wf_lla nb_length_lla have Nodes_in_pret: \"Nodes nb ll \\<subseteq> set_of pret\"\n      apply -\n      apply (rule Nodes_in_pret)\n      apply (auto simp add: length_ll_eq)\n      done\n    from pret_dag wf_lla nb_length_lla have \"Null \\<notin> Nodes nb ll\"\n      apply -\n      apply (rule Null_notin_Nodes)\n      apply (auto simp add: length_ll_eq)\n      done\n    with p_in_Nodes repbNodes_in_Nodes have rp_nNull: \"repb p \\<noteq> Null\"\n      by auto\n    with nort_dag have nort_nTip: \"nort\\<noteq> Tip\"\n      by auto\n    have \"\\<exists>postnormt. Dag (repb p) (repb \\<propto> low) (repb \\<propto> high) postnormt \\<and>\n      reduced postnormt \\<and> shared postnormt var \\<and>\n      ordered postnormt var \\<and> set_of postnormt \\<subseteq> set_of pret \\<and> \n      (\\<exists>postnormbdt.  \n      bdt postnormt var = Some postnormbdt \\<and> prebdt \\<sim> postnormbdt) \\<and> \n      (\\<forall>no \\<in> set_of postnormt. repb no = no)\"\n    proof (rule_tac x=nort in exI)\n      from nort_in_repNodes repbNodes_in_Nodes Nodes_in_pret \n      have nort_in_pret: \"set_of nort \\<subseteq> set_of pret\"\n        by blast\n      from not_dag pret_dag have not_pret: \"not = pret\"\n        by (simp add: Dag_unique)\n      with bdt_prop prebdt have pret_bdt_prop: \n        \"\\<exists>postnormbdt.\n        bdt nort var = Some postnormbdt \\<and> prebdt \\<sim> postnormbdt\"\n        by auto\n      from shared_mult_dags have \"shared nort var\"\n      proof (auto simp add: shared_def isomorphic_dags_eq_def)\n        fix st1 st2 bdt1\n        assume shared_imp: \n          \"\\<forall>t1 t2. t1\\<in>Dags (repb ` Nodes nb ll) (repb \\<propto> low) (repb \\<propto> high) \\<and> \n          t2 \\<in> Dags (repb ` Nodes nb ll) (repb \\<propto> low) (repb \\<propto> high)\n          \\<longrightarrow>\n          (\\<exists>bdt1. bdt t1 var = Some bdt1 \\<and> bdt t2 var = Some bdt1) \\<longrightarrow> t1 = t2\"\n        assume st1_nort: \" st1 \\<le> nort\"\n        assume st2_nort: \"st2 \\<le> nort\"\n        assume bdt_st1: \"bdt st1 var = Some bdt1\"\n        assume bdt_st2: \" bdt st2 var = Some bdt1\"\n        from nort_in_repNodes nort_dag nort_nTip \n        have nort_in_DagsrNodes: \n          \"nort \\<in> Dags (repb `(Nodes nb ll)) (repb \\<propto> low) (repb \\<propto> high)\"\n          apply -\n          apply (rule DagsI)\n          apply auto\n          done\n        show \"st1 = st2\"\n        proof (cases st1)\n          case Tip\n          note st1_Tip=this\n          with bdt_st1 bdt_st2 show ?thesis\n            by auto\n        next\n          case (Node lst1 st1p rst1)\n          note st1_Node=this\n          then have st1_nTip: \"st1 \\<noteq> Tip\"\n            by simp\n          show ?thesis\n          proof (cases st2)\n            case Tip\n            with bdt_st1 bdt_st2 show ?thesis\n              by auto\n          next\n            case (Node lst2 st2p rst2)\n            note st2_Node=this\n            then have st2_nTip: \"st2 \\<noteq> Tip\"\n              by simp \n            from nort_in_DagsrNodes st1_nort ord_nort wf_lla st1_nTip \n            have st1_in_Dags: \n              \"st1 \\<in> Dags (repb ` Nodes nb ll) (repb \\<propto> low) (repb \\<propto> high)\"\n              apply -\n              apply (rule Dags_subdags)\n              apply auto\n              done\n            from nort_in_DagsrNodes st2_nort ord_nort wf_lla  st2_nTip \n            have st2_in_Dags: \n              \"st2 \\<in> Dags (repb ` Nodes nb ll) (repb \\<propto> low) (repb \\<propto> high)\"\n              apply -\n              apply (rule Dags_subdags) \n              apply auto\n              done\n            from st1_in_Dags st2_in_Dags bdt_st1 bdt_st2 shared_imp show \"st1=st2\"\n              by simp\n          qed\n        qed\n      qed\n      with nort_dag red_nort ord_nort nort_in_pret pret_bdt_prop nort_repb \n      show \"Dag (repb p) (repb \\<propto> low) (repb \\<propto> high) nort \\<and>\n        reduced nort \\<and> shared nort var \\<and> ordered nort var \\<and> \n        set_of nort \\<subseteq> set_of pret \\<and> \n        (\\<exists>postnormbdt. \n        bdt nort var = Some postnormbdt \\<and> prebdt \\<sim> postnormbdt) \\<and> \n        (\\<forall>no \\<in> set_of nort.  repb no = no)\"\n        apply -\n        apply (intro conjI)\n        apply assumption+\n        done\n    qed\n    with wf_lla length_lla ord_pret pnN rep_nc_post marking_inverted\n    show ?thesis\n      by simp\n  qed\nnext\n  \\<comment> \\<open>From postcondition inner SPEC to final postcondition\\<close>\n  fix var low high p rep levellist marka \"next\" \n    nexta lowb highb pb levellista ll repa pret prebdt \n    and mark::\"ref\\<Rightarrow>bool\" and postnormt postnormbdt\n  assume ll: \"Levellist levellista nexta ll\"\n  assume repoint_spec: \n         \"Dag pb lowb highb postnormt\"\n         \"\\<forall>pt. pt \\<notin> set_of postnormt \\<longrightarrow> low pt = lowb pt \\<and> high pt = highb pt\"\n  assume pret_dag: \"Dag p low high pret\"\n  assume ord_pret: \"ordered pret var\"\n  assume pnN: \" p \\<noteq> Null\"\n  assume onemark_pret: \n    \"\\<forall>n. n \\<in> set_of pret \\<longrightarrow> mark n = mark p\" (is \"\\<forall>n. ?in_pret n \\<longrightarrow> ?eq_mark_p n\")\n  assume pret_bdt: \" bdt pret var = Some prebdt\"\n  \n  assume  wf_ll: \"wf_ll pret ll var\"  and\n    length_ll:\"length levellist =var p + 1\" and\n    wf_marking_ll: \"wf_marking pret mark marka (\\<not> mark p)\"\n  assume  \n    postnormt_dag: \"Dag (repa p) (repa \\<propto> low) (repa \\<propto> high) postnormt\" and\n    reduced_postnormt: \"reduced postnormt\" and\n    shared_postnormt: \"shared postnormt var\" and\n    ordered_postnormt: \"ordered postnormt var\" and\n    subset_pret: \"set_of postnormt \\<subseteq> set_of pret\"and\n    sim_bdt: \"bdt postnormt var = Some postnormbdt\" \"prebdt \\<sim> postnormbdt\"  and\n    postdag_repa: \"\\<forall>no \\<in> set_of postnormt. repa no = no\" and\n    rep_eq: \"\\<forall>pt. pt \\<notin> set_of pret \\<longrightarrow> rep pt = repa pt\"  and\n    pret_marked: \"\\<forall>no. no \\<in> set_of pret \\<longrightarrow> marka no = (\\<not> mark p)\"\n  assume unmodif_next: \"\\<forall>p. p \\<notin> set_of pret \\<longrightarrow> next p = nexta p\"\n  show \"(\\<forall>pt. pt \\<notin> set_of pret \n    \\<longrightarrow> low pt = lowb pt \\<and> high pt = highb pt \\<and> \n    mark pt = marka pt ) \"\n\n  proof -\n    from ll have length_ll_eq: \"length levellista = length ll\"\n      by (simp add: Levellist_length)\n    from repoint_spec  pnN subset_pret\n    have repoint_nc: \"(\\<forall>pt. pt \\<notin> set_of pret \n      \\<longrightarrow> low pt = lowb pt \\<and> high pt = highb pt) \\<and> Dag pb lowb highb postnormt\"\n      by auto\n    then have lowhigh_b_eq: \"\\<forall>pt. pt \\<notin> set_of pret \n      \\<longrightarrow> low pt = lowb pt \\<and> high pt = highb pt\"\n      by fastforce\n    from wf_marking_ll pret_dag pnN \n    have mark_b_eq: \"\\<forall>pt. pt \\<notin> set_of pret \\<longrightarrow> mark pt = marka pt\"\n      apply -\n      apply (simp add: wf_marking_def)\n      apply (split dag.splits)\n      apply  simp\n      apply (rule allI)\n      apply (rule impI)\n      apply (elim conjE)\n      apply (erule_tac x=pt in allE)\n      apply fastforce\n      done\n    with lowhigh_b_eq rep_eq unmodif_next\n    have pret_nc: \"\\<forall>pt. pt \\<notin> set_of pret \n      \\<longrightarrow> rep pt = repa pt \\<and> low pt = lowb pt \\<and> high pt = highb pt \\<and> \n      mark pt = marka pt \\<and> next pt = nexta pt\"\n      by blast\n(*    from repoint_nc have rept_dag: \"Dag pb lowb highb postnormt\"\n      by simp\n    with reduced_postnormt shared_postnormt ordered_postnormt subset_pret sim_bdt \n      pret_bdt \n    have post_same_prop: \n      \"\\<exists>postt. Dag pb lowb highb postt \\<and> reduced postt \\<and>\n      shared postt var \\<and> ordered postt var \\<and> set_of postt \\<subseteq> set_of pret \\<and>\n      (\\<exists>postbdt. bdt postt var = Some postbdt \\<and> prebdt \\<sim> postbdt)\" \n      apply -\n      apply (rule_tac x=postnormt in exI)\n      apply fastforce\n      done*)\n    from pret_nc  \n    show ?thesis\n      by fastforce\n  qed\nnext\n  \\<comment> \\<open>invariant to invariant\\<close>\n  fix var low high p rep mark pret prebdt levellist ll \"next\" marka n repc \n    and repb :: \"ref \\<Rightarrow> ref\"  \n  assume ll: \"Levellist levellist next ll\"\n  assume pret_dag: \"Dag p low high pret\"\n  assume ord_pret: \" ordered pret var\"\n  assume pnN: \"p \\<noteq> Null\"\n  assume prebdt_pret: \"bdt pret var = Some prebdt\"\n  assume wf_ll: \"wf_ll pret ll var\"\n  assume lll: \"length levellist = var p + 1\"\n  assume n_Suc_var_p: \"n < var p + 1\"\n  assume wf_marking_m_ma: \"wf_marking pret mark marka (\\<not> mark p)\"\n\n(*  assume rep_nc: \" \\<forall>pt. pt \\<notin> set_of pret \\<or> \n    (\\<exists>i. n \\<le> i \\<and> pt \\<in> set (ll ! i) \\<and> i < var p + 1) \n    \\<longrightarrow> rep pt = repb pt\" *)\n  assume rep_nc:      \"\\<forall>pt i.\n           pt \\<notin> set_of pret \\<or> n \\<le> i \\<and> pt \\<in> set (ll ! i) \\<and> i < var p + 1 \\<longrightarrow>\n           rep pt = repb pt\"\n  assume repbNodes_in_Nodes: \"repb ` Nodes n ll \\<subseteq> Nodes n ll\"\n  assume\n    normalize_prop: \"\\<forall>no\\<in>Nodes n ll.\n    var (repb no) \\<le> var no \\<and>\n    (\\<exists>not nort. Dag (repb no) (repb \\<propto> low) (repb \\<propto> high) nort \\<and>\n    Dag no low high not \\<and> reduced nort \\<and> ordered nort var \\<and>\n    set_of nort \\<subseteq> repb ` Nodes n ll \\<and>\n    (\\<forall>no\\<in>set_of nort. repb no = no) \\<and>\n    (\\<exists>nobdt. bdt not var = Some nobdt \\<and> \n    (\\<exists>norbdt. bdt nort var = Some norbdt \\<and> \n    nobdt \\<sim> norbdt)))\" \n  assume \n    isomorphic_dags_eq: \n    \"\\<forall>t1 t2. t1 \\<in> Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high)\\<and>\n    t2 \\<in> Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high) \n    \\<longrightarrow> isomorphic_dags_eq t1 t2 var\"\n  show \"(\\<forall>no\\<in>set (ll ! n).\n              no \\<noteq> Null \\<and>\n              (low no = Null) = (high no = Null) \\<and>\n              low no \\<notin> set (ll ! n) \\<and>\n              high no \\<notin> set (ll ! n) \\<and>\n              isLeaf_pt no low high = (var no \\<le> 1) \\<and>\n              (low no \\<noteq> Null \\<longrightarrow> repb (low no) \\<noteq> Null) \\<and> (repb \\<propto> low) no \\<notin> set (ll ! n)) \\<and>\n          (\\<forall>no1\\<in>set (ll ! n). \\<forall>no2\\<in>set (ll ! n). var no1 = var no2) \\<and>\n          (\\<forall>repa. (\\<forall>no. no \\<notin> set (ll ! n) \\<longrightarrow> repb no = repa no) \\<and>\n                  (\\<forall>no\\<in>set (ll ! n).\n                      repa no \\<noteq> Null \\<and>\n                      (if (repa \\<propto> low) no = (repa \\<propto> high) no \\<and> low no \\<noteq> Null\n                       then repa no = (repa \\<propto> low) no\n                       else repa no \\<in> set (ll ! n) \\<and>\n                            repa (repa no) = repa no \\<and>\n                            (\\<forall>no1\\<in>set (ll ! n).\n                                ((repa \\<propto> high) no1 = (repa \\<propto> high) no \\<and>\n                                 (repa \\<propto> low) no1 = (repa \\<propto> low) no) =\n                                (repa no = repa no1)))) \\<longrightarrow>\n                  var p + 1 - (n + 1) < var p + 1 - n \\<and>\n                  n + 1 \\<le> var p + 1 \\<and>\n                  (\\<forall>pt i. pt \\<notin> set_of pret \\<or> (n + 1 \\<le> i \\<and> pt \\<in> set (ll ! i) \\<and> i < var p + 1) \\<longrightarrow>\n                        rep pt = repa pt) \\<and>\n                  repa ` Nodes (n + 1) ll \\<subseteq> Nodes (n + 1) ll \\<and>\n                  (\\<forall>no\\<in>Nodes (n + 1) ll.\n                      var (repa no) \\<le> var no \\<and>\n                      (\\<exists>not nort.\n                          Dag (repa no) (repa \\<propto> low) (repa \\<propto> high) nort \\<and>\n                          Dag no low high not \\<and>\n                          reduced nort \\<and>\n                          ordered nort var \\<and>\n                          set_of nort \\<subseteq> repa ` Nodes (n + 1) ll \\<and>\n                          (\\<forall>no\\<in>set_of nort. repa no = no) \\<and>\n                          (\\<exists>nobdt.\n                              bdt not var = Some nobdt \\<and>\n                              (\\<exists>norbdt. bdt nort var = Some norbdt \\<and> nobdt \\<sim> norbdt)))) \\<and>\n                  (\\<forall>t1 t2.\n                      t1 \\<in> Dags (repa ` Nodes (n + 1) ll) (repa \\<propto> low) (repa \\<propto> high) \\<and>\n                      t2 \\<in> Dags (repa ` Nodes (n + 1) ll) (repa \\<propto> low) (repa \\<propto> high) \\<longrightarrow>\n                      isomorphic_dags_eq t1 t2 var))\"\n  proof -\n    from ll have length_ll_eq: \"length levellist = length ll\"\n      by (simp add: Levellist_length)\n    from n_Suc_var_p lll have nsll: \"n < length levellist\" by simp\n    hence nseqll: \"n \\<le> length levellist\" by simp\n    have srrl_precond: \"(\\<forall>no \\<in> set (ll ! n).\n      no \\<noteq> Null \\<and>\n      (low no = Null) = (high no = Null) \\<and>\n      low no \\<notin> set (ll ! n) \\<and>\n      high no \\<notin> set (ll ! n) \\<and> \n      isLeaf_pt no low high = (var no \\<le> 1) \\<and> \n      (low no \\<noteq> Null \\<longrightarrow> repb (low no) \\<noteq> Null) \\<and> \n      (repb \\<propto> low) no \\<notin> set (ll ! n))\"\n    proof (intro ballI)\n      fix no\n      assume no_in_lln: \"no \\<in> set (ll ! n)\"\n      with wf_ll nsll have no_in_pret_var: \"no \\<in> set_of pret \\<and> var no = n\"\n        by (simp add: wf_ll_def length_ll_eq)\n      with pret_dag have no_nNull: \"no \\<noteq> Null\"\n        apply -\n        apply (rule set_of_nn)\n        apply auto\n        done\n      from pret_dag prebdt_pret no_in_pret_var \n      have balanced_no: \"(low no = Null) = (high no = Null)\"\n        apply -\n        apply (erule conjE)\n        apply (rule_tac p=p and low=low in balanced_bdt)\n        apply auto\n        done\n      have low_no_notin_lln: \"low no \\<notin> set (ll ! n)\"\n      proof (cases \"low no = Null\")\n        case True\n        note lno_Null=this\n        with balanced_no have hno_Null: \"high no = Null\"\n          by simp\n        show ?thesis\n        proof (cases \"low no \\<in> set (ll ! n)\") \n          case True\n          with wf_ll nsll have \"low no \\<in> set_of pret \\<and> var (low no) = n\"\n            by (auto simp add: wf_ll_def length_ll_eq)\n          with pret_dag have \"low no \\<noteq> Null\"\n            apply -\n            apply (rule set_of_nn)\n            apply auto\n            done\n          with lno_Null show ?thesis\n            by simp\n        next\n          assume lno_notin_lln: \"low no \\<notin> set (ll ! n)\"\n          then show ?thesis\n            by simp\n        qed\n      next\n        assume lno_nNull: \"low no \\<noteq> Null\"\n        with balanced_no have hno_nNull: \"high no \\<noteq> Null\"\n          by simp\n        with lno_nNull pret_dag ord_pret no_in_pret_var \n        have var_children_smaller: \"var (low no) < var no \\<and> var (high no) < var no\" \n          apply -\n          apply (rule var_ordered_children)\n          apply auto\n          done\n        show ?thesis\n        proof (cases \"low no \\<in> set (ll ! n)\")\n          case True\n          with wf_ll nsll have \"low no \\<in> set_of pret \\<and> var (low no) = n\"\n            by (simp add: wf_ll_def length_ll_eq)\n          with var_children_smaller no_in_pret_var show ?thesis\n            by simp\n        next\n          assume \"low no \\<notin> set (ll ! n)\"\n          thus ?thesis\n            by simp\n        qed\n      qed\n      have high_no_notin_lln: \"high no \\<notin> set (ll ! n)\"\n      proof (cases \"high no = Null\")\n        case True\n        note hno_Null=this\n        with balanced_no have lno_Null: \"low no = Null\"\n          by simp\n        show ?thesis\n        proof (cases \"high no \\<in> set (ll ! n)\") \n          case True\n          with wf_ll nsll have \"high no \\<in> set_of pret \\<and> var (high no) = n\"\n            by (auto simp add: wf_ll_def length_ll_eq)\n          with pret_dag have \"high no \\<noteq> Null\"\n            apply -\n            apply (rule set_of_nn)\n            apply auto\n            done\n          with hno_Null show ?thesis\n            by simp\n        next\n          assume hno_notin_lln: \"high no \\<notin> set (ll ! n)\"\n          then show ?thesis\n            by simp\n        qed\n      next\n        assume hno_nNull: \"high no \\<noteq> Null\"\n        with balanced_no have lno_nNull: \"low no \\<noteq> Null\"\n          by simp\n        with hno_nNull pret_dag ord_pret no_in_pret_var \n        have var_children_smaller: \"var (low no) < var no \\<and> var (high no) < var no\" \n          apply -\n          apply (rule var_ordered_children)\n          apply auto\n          done\n        show ?thesis\n        proof (cases \"high no \\<in> set (ll ! n)\")\n          case True\n          with wf_ll nsll have \"high no \\<in> set_of pret \\<and> var (high no) = n\"\n            by (simp add: wf_ll_def length_ll_eq)\n          with var_children_smaller no_in_pret_var show ?thesis\n            by simp\n        next\n          assume \"high no \\<notin> set (ll ! n)\"\n          thus ?thesis\n            by simp\n        qed\n      qed \n      from no_in_pret_var pret_dag no_nNull obtain not where \n        no_dag_ex: \"Dag no low high not\"\n        apply -\n        apply (rotate_tac 2)\n        apply (drule subnode_dag_cons)\n        apply (auto simp del: Dag_Ref)\n        done\n      with pret_dag prebdt_pret no_in_pret_var obtain nobdt \n        where nobdt_ex: \n        \"bdt not var = Some nobdt\"\n        apply -\n        apply (drule subbdt_ex_dag_def)\n        apply auto\n        done\n      have isLeaf_var: \"isLeaf_pt no low high = (var no \\<le> 1)\"\n      proof\n        assume no_isLeaf: \"isLeaf_pt no low high\"\n        from nobdt_ex no_dag_ex no_isLeaf show \"var no \\<le> 1\"\n          apply -\n          apply (rule bdt_Some_Leaf_var_le_1)\n          apply auto\n          done\n      next\n        assume varno_le_1: \"var no \\<le> 1\"\n        show \"isLeaf_pt no low high\"\n        proof (cases \"var no = 0\")\n          case True\n          with nobdt_ex no_nNull no_dag_ex have \"not = Node Tip no Tip\" \n            apply -\n            apply (drule bdt_Some_var0_Zero)\n            apply auto\n            done\n          with no_dag_ex show \"isLeaf_pt no low high\"\n            by (simp add: isLeaf_pt_def)\n        next\n          assume \"var no \\<noteq> 0\"\n          with varno_le_1 have \"var no = 1\"\n            by simp\n          with nobdt_ex no_nNull no_dag_ex have \"not = Node Tip no Tip\"\n            apply -\n            apply (drule bdt_Some_var1_One)\n            apply auto\n            done\n          with no_dag_ex show \"isLeaf_pt no low high\"\n            by (simp add: isLeaf_pt_def)\n        qed\n      qed\n      have repb_low_nNull: \"(low no \\<noteq> Null \\<longrightarrow> repb (low no) \\<noteq> Null)\"\n      proof\n        assume lno_nNull: \"low no \\<noteq> Null\"\n        with no_nNull no_in_pret_var pret_dag have lno_in_pret: \"low no \\<in> set_of pret\"\n          apply -\n          apply (rule_tac low=low in subelem_set_of_low)\n          apply auto\n          done\n        from lno_nNull balanced_no have hno_nNull: \"high no \\<noteq> Null\"\n          by simp\n        with lno_nNull pret_dag ord_pret no_in_pret_var \n        have var_children_smaller: \"var (low no) < var no \\<and> var (high no) < var no\" \n          apply -\n          apply (rule var_ordered_children)\n          apply auto\n          done \n        with no_in_pret_var have var_lno_l_n: \"var (low no) <n\"\n          by simp\n        with wf_ll lno_in_pret nsll have \"low no \\<in> set (ll ! (var (low no)))\"\n          by (simp add: wf_ll_def length_ll_eq)\n        with lno_in_pret var_lno_l_n have \"low no \\<in> Nodes n ll\"\n          apply (simp add: Nodes_def)\n          apply (rule_tac x=\"var (low no)\" in exI)\n          apply simp\n          done\n        hence \"repb (low no) \\<in> repb ` Nodes n ll\"\n          by simp\n        with repbNodes_in_Nodes have repb_lno_in_Nodes: \n          \"repb (low no) \\<in> Nodes n ll\"\n          by blast\n        from pret_dag wf_ll nsll have \"Null \\<notin> Nodes n ll\"\n          apply -\n          apply (rule Null_notin_Nodes)\n          apply (auto simp add: length_ll_eq)\n          done \n        with repb_lno_in_Nodes show \"repb (low no) \\<noteq> Null\"\n          by auto\n      qed\n      have Null_notin_lln: \"Null \\<notin> set (ll ! n)\"\n      proof (cases \"Null \\<in> set (ll ! n)\")\n        case True\n        with wf_ll nsll have \"Null \\<in> set_of pret \\<and> var (Null) = n\" \n          by (simp add: wf_ll_def length_ll_eq)\n        with pret_dag have \"Null \\<noteq> Null\"\n          apply -\n          apply (rule set_of_nn)\n          apply auto\n          done\n        thus ?thesis\n          by auto\n      next\n        assume \"Null \\<notin> set (ll ! n)\"\n        thus ?thesis\n          by simp\n      qed\n      have \"(repb \\<propto> low) no \\<notin> set (ll ! n)\"\n      proof (cases \"low no = Null\")  \n        case True\n        with Null_notin_lln show ?thesis\n          by (simp add: null_comp_def)\n      next\n        assume lno_nNull: \"low no \\<noteq> Null\"\n        with no_nNull no_in_pret_var pret_dag have lno_in_pret: \"low no \\<in> set_of pret\"\n          apply -\n          apply (rule_tac low=low in subelem_set_of_low)\n          apply auto\n          done\n        from lno_nNull have propto_eq_comp: \"(repb \\<propto> low) no = repb (low no)\"\n          by (simp add: null_comp_def)\n        from lno_nNull balanced_no have hno_nNull: \"high no \\<noteq> Null\"\n          by simp\n        with lno_nNull pret_dag ord_pret no_in_pret_var \n        have var_children_smaller: \"var (low no) < var no \\<and> var (high no) < var no\" \n          apply -\n          apply (rule var_ordered_children)\n          apply auto\n          done \n        with no_in_pret_var have var_lno_l_n: \"var (low no) <n\"\n          by simp\n        with wf_ll lno_in_pret nsll have \"low no \\<in> set (ll ! (var (low no)))\"\n          by (simp add: wf_ll_def length_ll_eq)\n        with lno_in_pret var_lno_l_n have lno_in_Nodes_n: \"low no \\<in> Nodes n ll\"\n          apply (simp add: Nodes_def)\n          apply (rule_tac x=\"var (low no)\" in exI)\n          apply simp\n          done\n        hence \"repb (low no) \\<in> repb ` Nodes n ll\"\n          by simp\n        with  repbNodes_in_Nodes have repb_lno_in_Nodes: \n          \"repb (low no) \\<in> Nodes n ll\"\n          by blast\n        with lno_in_Nodes_n normalize_prop have \"var (repb (low no)) \\<le> var (low no)\" \n          by auto\n        with var_lno_l_n have var_rep_lno_l_n: \" var (repb (low no)) < n\"\n          by simp\n        with repb_lno_in_Nodes have \"\\<exists> k < n. repb (low no) \\<in> set (ll ! k)\"\n          by (auto simp add: Nodes_def)\n        with wf_ll propto_eq_comp nsll show \" (repb \\<propto> low) no \\<notin> set (ll ! n)\"\n          apply -\n          apply (erule exE)\n          apply (rule_tac i=k and j=n in no_in_one_ll)\n          apply (auto simp add: length_ll_eq)\n          done\n      qed\n      with no_nNull balanced_no low_no_notin_lln high_no_notin_lln isLeaf_var repb_low_nNull\n      show \" no \\<noteq> Null \\<and>\n        (low no = Null) = (high no = Null) \\<and>\n        low no \\<notin> set (ll ! n) \\<and> high no \\<notin> set (ll ! n) \\<and> \n        isLeaf_pt no low high = (var no \\<le> 1) \\<and> \n        (low no \\<noteq> Null \\<longrightarrow> repb (low no) \\<noteq> Null) \\<and> \n        (repb \\<propto> low) no \\<notin> set (ll ! n)\"\n        by auto\n    qed\n    have all_nodes_same_var: \"\\<forall>no1 \\<in> set (ll ! n). \\<forall>no2 \\<in> set (ll ! n). var no1 = var no2\"\n    proof (intro ballI impI)\n      fix no1 no2\n      assume \"no1 \\<in> set (ll ! n)\"\n      with wf_ll nsll have var_lln_i: \"var no1 = n\"\n        by (simp add: wf_ll_def length_ll_eq)\n      assume \"no2 \\<in> set (ll ! n)\"\n      with wf_ll nsll have \"var no2 = n\"\n        by (simp add: wf_ll_def length_ll_eq)\n      with var_lln_i show \" var no1 = var no2\"\n        by simp\n    qed\n    have  \"(\\<forall>repa. (\\<forall>no. no \\<notin> set (ll ! n) \\<longrightarrow> repb no = repa no) \\<and>\n                  (\\<forall>no\\<in>set (ll ! n).\n                      repa no \\<noteq> Null \\<and>\n                      (if (repa \\<propto> low) no = (repa \\<propto> high) no \\<and> low no \\<noteq> Null\n                       then repa no = (repa \\<propto> low) no\n                       else repa no \\<in> set (ll ! n) \\<and>\n                            repa (repa no) = repa no \\<and>\n                            (\\<forall>no1\\<in>set (ll ! n).\n                                ((repa \\<propto> high) no1 = (repa \\<propto> high) no \\<and>\n                                 (repa \\<propto> low) no1 = (repa \\<propto> low) no) =\n                                (repa no = repa no1)))) \\<longrightarrow>\n                  var p + 1 - (n + 1) < var p + 1 - n \\<and>\n                  n + 1 \\<le> var p + 1 \\<and>\n                  (\\<forall>pt i. pt \\<notin> set_of pret \\<or> (n + 1 \\<le> i \\<and> pt \\<in> set (ll ! i) \\<and> i < var p + 1) \\<longrightarrow>\n                        rep pt = repa pt) \\<and>\n                  repa ` Nodes (n + 1) ll \\<subseteq> Nodes (n + 1) ll \\<and>\n                  (\\<forall>no\\<in>Nodes (n + 1) ll.\n                      var (repa no) \\<le> var no \\<and>\n                      (\\<exists>not nort.\n                          Dag (repa no) (repa \\<propto> low) (repa \\<propto> high) nort \\<and>\n                          Dag no low high not \\<and>\n                          reduced nort \\<and>\n                          ordered nort var \\<and>\n                          set_of nort \\<subseteq> repa ` Nodes (n + 1) ll \\<and>\n                          (\\<forall>no\\<in>set_of nort. repa no = no) \\<and>\n                          (\\<exists>nobdt.\n                              bdt not var = Some nobdt \\<and>\n                              (\\<exists>norbdt. bdt nort var = Some norbdt \\<and> nobdt \\<sim> norbdt)))) \\<and>\n                  (\\<forall>t1 t2.\n                      t1 \\<in> Dags (repa ` Nodes (n + 1) ll) (repa \\<propto> low) (repa \\<propto> high) \\<and>\n                      t2 \\<in> Dags (repa ` Nodes (n + 1) ll) (repa \\<propto> low) (repa \\<propto> high) \\<longrightarrow>\n                      isomorphic_dags_eq t1 t2 var))\"\n      (is \"(\\<forall>repc. ?srrl_post repc \\<longrightarrow> ?norm_inv repc) \") \n    proof (intro allI impI, elim conjE)\n      fix repc\n      assume repbc_nc: \"\\<forall>no. no \\<notin> set (ll ! n) \\<longrightarrow> repb no = repc no\"\n      assume rep_prop: \" \\<forall>no\\<in>set (ll ! n).\n        repc no \\<noteq> Null \\<and>\n               (if (repc \\<propto> low) no = (repc \\<propto> high) no \\<and> low no \\<noteq> Null\n                then repc no = (repc \\<propto> low) no\n                else repc no \\<in> set (ll ! n) \\<and>\n                     repc (repc no) = repc no \\<and>\n                     (\\<forall>no1\\<in>set (ll ! n).\n                         ((repc \\<propto> high) no1 = (repc \\<propto> high) no \\<and>\n                          (repc \\<propto> low) no1 = (repc \\<propto> low) no) =\n                         (repc no = repc no1)))\"\n      show \"?norm_inv repc\"\n      proof -\n        from n_Suc_var_p have termi: \"var p + 1 - (n + 1) < var p + 1 - n\"\n          by arith\n        from wf_ll repbc_nc nsll \n        have Nodes_n_rep_nc: \"\\<forall>p. p \\<in> Nodes n ll \\<longrightarrow> repb p = repc p\"\n          apply -\n          apply (rule allI)\n          apply (rule impI)\n          apply (simp add: Nodes_def)\n          apply (erule exE)\n          apply (erule_tac x=p in allE)\n          apply (drule_tac i=x and j=n in no_in_one_ll)\n          apply (auto simp add: length_ll_eq)\n          done\n        from repbNodes_in_Nodes \n        have Nodes_n_rep_in_Nodesn: \n          \"\\<forall> p. p \\<in> Nodes n ll \\<longrightarrow> repb p \\<in> Nodes n ll\"\n          by auto\n        from wf_ll nsll have \"Nodes n ll \\<subseteq> set_of pret\"\n          apply -\n          apply (rule Nodes_in_pret)\n          apply (auto simp add: length_ll_eq)\n          done\n        with Nodes_n_rep_in_Nodesn  \n        have Nodes_n_rep_in_pret: \"\\<forall>p. p \\<in> Nodes n ll \\<longrightarrow> repb p \\<in> set_of pret\"\n          apply -\n          apply (intro allI impI)\n          apply blast\n          done\n        have Nodes_repbc_Dags_eq: \"\\<forall>p t. p \\<in> Nodes n ll \n          \\<longrightarrow> Dag (repb p) (repb \\<propto> low) (repb \\<propto> high) t = \n          Dag (repc p) (repc \\<propto> low) (repc \\<propto> high) t\"\n        proof (intro allI impI)\n          fix p t\n          assume p_in_Nodes: \" p \\<in> Nodes n ll\"\n          then have repp_nc: \"repb p = repc p\"\n            by (rule Nodes_n_rep_nc [rule_format])\n          from p_in_Nodes normalize_prop obtain nort where\n            nort_repb_dag: \"Dag (repb p) (repb \\<propto> low) (repb \\<propto> high) nort\" and\n            nort_in_repbNodes: \"set_of nort \\<subseteq> repb ` Nodes n ll\"\n            apply -\n            apply (erule_tac x=p in ballE)\n            prefer 2\n            apply auto\n            done\n          from nort_in_repbNodes repbNodes_in_Nodes \n          have nort_in_Nodesn: \"set_of nort \\<subseteq> Nodes n ll\"\n            by blast\n          from pret_dag wf_ll nsll have \"Null \\<notin> Nodes n ll\"\n            apply -\n            apply (rule Null_notin_Nodes)\n            apply (auto simp add: length_ll_eq)\n            done\n          with p_in_Nodes repbNodes_in_Nodes have repp_nNull: \"repb p \\<noteq> Null\"\n            by auto\n          from nort_repb_dag repp_nc \n          have nort_repbc_dag: \"Dag (repc p) (repb \\<propto> low) (repb \\<propto> high) nort\"\n            by simp\n          from nort_in_Nodesn have \"\\<forall>x \\<in> set_of nort. x \\<in> Nodes n ll\"\n            apply -\n            apply (rule ballI)\n            apply blast\n            done\n          with wf_ll nsll  have \"\\<forall>x \\<in> set_of nort. x \\<in> set_of pret \\<and> var x < n\"\n            apply -\n            apply (rule ballI)\n            apply (rule wf_ll_Nodes_pret)\n            apply (auto simp add: length_ll_eq)\n            done\n          with pret_dag prebdt_pret nort_repbc_dag ord_pret wf_ll  nsll repbc_nc \n          have \n            \"\\<forall> x \\<in> set_of nort. (repc \\<propto> low) x = (repb \\<propto> low) x \\<and> \n            (repc \\<propto> high) x = (repb \\<propto> high) x\"\n            apply -\n            apply (rule nort_null_comp)\n            apply (auto simp add: length_ll_eq)\n            done\n          with nort_repbc_dag repp_nc \n          have \"Dag (repc p) (repb \\<propto> low) (repb \\<propto> high) nort = \n            Dag (repc p) (repc \\<propto> low) (repc \\<propto> high) nort\"\n            apply -\n            apply (rule heaps_eq_Dag_eq)\n            apply (rule ballI)\n            apply (erule_tac x=x in ballE)\n            apply (elim conjE)\n            apply (rule conjI)\n            apply auto\n            done\n          with nort_repbc_dag repp_nc show \n            \"Dag (repb p) (repb \\<propto> low) (repb \\<propto> high) t = \n            Dag (repc p) (repc \\<propto> low) (repc \\<propto> high) t\"\n            apply auto\n            apply (rotate_tac 2)\n            apply (frule_tac Dag_unique)\n            apply (rotate_tac 1)\n            apply simp\n            apply simp\n            apply (frule Dag_unique)\n            apply (rotate_tac 3)\n            apply simp\n            apply simp\n            done\n        qed\n        from rep_prop have repbc_changes: \"\\<forall>no\\<in>set (ll ! n).\n          repc no \\<noteq> Null \\<and>\n          (if (repc \\<propto> low) no = (repc \\<propto> high) no \\<and> low no \\<noteq> Null \n          then repc no = (repc \\<propto> low) no\n          else repc no \\<in> set (ll ! n) \\<and> repc (repc no) = repc no \\<and> \n          (\\<forall>no1\\<in>set (ll ! n). ((repc \\<propto> high) no1 = (repc \\<propto> high) no \\<and> \n          (repc \\<propto> low) no1 = (repc \\<propto> low) no) = (repc no = repc no1)))\"\n          by blast\n        from nsll lll  have n_var_prop: \"n + 1 <= var p + 1\"\n          by simp\n        from rep_nc have Sucn_repb_nc: \"(\\<forall>pt. pt \\<notin> set_of pret \\<or> \n          (\\<exists>i. n + 1 \\<le> i \\<and> pt \\<in> set (ll ! i) \\<and> i < var p + 1)  \n          \\<longrightarrow> rep pt = repb pt)\" \n          apply -\n          apply (intro allI impI)\n          apply (erule_tac x=pt in allE)\n          apply auto\n          apply (rule_tac x=\"i\" in exI)\n          apply auto\n          done\n        have repc_nc: \n          \"(\\<forall>pt. pt \\<notin> set_of pret \\<or> \n          (\\<exists>i. n + 1 \\<le> i \\<and> pt \\<in> set (ll ! i) \\<and> i < var p + 1) \n          \\<longrightarrow> rep pt = repc pt)\" \n        proof (intro allI impI)\n          fix pt \n          assume pt_notin_lower_ll: \"pt \\<notin> set_of pret \\<or> \n            (\\<exists>i. n + 1 \\<le> i \\<and> pt \\<in> set (ll ! i) \\<and> i < var p + 1)\"\n          show \"rep pt = repc pt\"\n          proof (cases \"pt \\<notin> set_of pret\")\n            case True\n            with wf_ll nsll have \"pt \\<notin> set (ll ! n)\"\n              apply (simp add: wf_ll_def length_ll_eq)\n              apply (case_tac \"pt \\<in> set (ll ! n)\")\n              apply (subgoal_tac \"pt \\<in> set_of pret\")\n              apply (auto)\n              done\n            with repbc_nc have \"repb pt = repc pt\"\n              by auto\n            with Sucn_repb_nc True show ?thesis\n              by auto\n          next\n            assume pt_in_pret: \"\\<not> pt \\<notin> set_of pret\"\n            with pt_notin_lower_ll have pt_in_higher_ll: \n              \"\\<exists>i. n + 1 \\<le> i \\<and> pt \\<in> set (ll ! i) \\<and> i < var p + 1\"\n              by simp\n            with nsll wf_ll lll have pt_notin_lln: \"pt \\<notin> set (ll ! n)\"\n              apply -\n              apply (erule exE)\n              apply (rule_tac i=i and j=n in no_in_one_ll)\n              apply (auto simp add: length_ll_eq)\n              done\n            with repbc_nc have \"repb pt = repc pt\"\n              by auto\n            with Sucn_repb_nc pt_in_higher_ll show ?thesis\n              by auto \n          qed\n        qed\n        from wf_ll nsll  \n        have Nodesn_notin_lln: \"\\<forall>no \\<in> Nodes n ll. no \\<notin> set (ll ! n)\"\n          apply (simp add: Nodes_def)\n          apply clarify\n          apply (drule no_in_one_ll)\n          apply (auto simp add: length_ll_eq)\n          done\n        with repbc_nc  \n        have Nodesn_repnc: \"\\<forall>no \\<in> Nodes n ll. repb no = repc no\"\n          apply -\n          apply (rule ballI)\n          apply (erule_tac x=no in allE)\n          apply simp\n          done\n        then have repbNodes_repcNodes: \n          \"repb `(Nodes n ll) = repc `(Nodes n ll)\"\n          apply -\n          apply rule\n          apply blast\n          apply rule\n          apply (erule imageE)\n          apply (erule_tac x=xa in ballE)\n          prefer 2\n          apply simp\n          apply rule\n          apply auto\n          done\n        have repcNodes_in_Nodes: \n          \"repc ` Nodes (n + 1) ll \\<subseteq> Nodes (n + 1) ll\"\n        proof\n          fix x\n          assume x_in_repcNodesSucn: \" x \\<in> repc ` Nodes (n + 1) ll\"\n          show \"x \\<in> Nodes (n + 1) ll\"\n          proof (cases \"x \\<in> repc `Nodes n ll\")\n            case True\n            with repbNodes_repcNodes repbNodes_in_Nodes have \"x \\<in> Nodes n ll\" \n              by auto\n            with Nodes_subset show ?thesis \n              by auto\n          next\n            assume \" x \\<notin> repc `Nodes n ll\"\n            with x_in_repcNodesSucn have x_in_repclln: \"x \\<in> repc `set (ll ! n)\"\n              apply (auto simp add: Nodes_def)\n              apply (case_tac \"k<n\")\n              apply auto\n              apply (case_tac \"k = n\")\n              apply simp\n              apply arith\n              done\n            from x_in_repclln show ?thesis\n            proof (elim imageE)\n              fix y\n              assume x_repcy: \"x = repc y\"\n              assume y_in_repclln: \"y \\<in> set (ll ! n)\"\n              from rep_prop y_in_repclln  obtain\n                repcy_nNull: \"repc y \\<noteq> Null\" and\n                red_prop: \"(repc \\<propto> low) y = (repc \\<propto> high) y \\<and> \n                low y \\<noteq> Null \\<longrightarrow> repc y = (repc \\<propto> high) y\" and\n                share_prop: \"((repc \\<propto> low) y = (repc \\<propto> high) y \\<longrightarrow> low y = Null) \n                \\<longrightarrow> repc y \\<in> set (ll ! n) \\<and> repc (repc y) = repc y \\<and> \n                (\\<forall>no1\\<in>set (ll ! n). \n                ((repc \\<propto> high) no1 = (repc \\<propto> high) y \\<and> \n                (repc \\<propto> low) no1 = (repc \\<propto> low) y) = (repc y = repc no1))\"\n                using [[simp_depth_limit = 4]]\n                by auto\n              from wf_ll nsll  y_in_repclln obtain\n                y_in_pret: \"y \\<in> set_of pret\" and\n                vary_n: \"var y = n\"\n                by (auto simp add: wf_ll_def length_ll_eq)\n              from y_in_pret pret_dag have y_nNull: \"y \\<noteq> Null\"\n                apply -\n                apply (rule set_of_nn)\n                apply auto\n                done\n              show \"x \\<in> Nodes (n + 1) ll\"\n              proof (cases \"low y = Null\")\n                case True\n                from pret_dag prebdt_pret True y_in_pret \n                have highy_Null: \"high y = Null\"\n                  apply -\n                  apply (drule balanced_bdt)\n                  apply auto\n                  done\n                with share_prop True obtain \n                  repcy_in_llb: \"repc y \\<in> set (ll ! n)\" and\n                  rry_ry: \" repc (repc y) = repc y\" and\n                  y_other_node_prop: \"\\<forall>no1\\<in>set (ll ! n). \n                  ((repc \\<propto> high) no1 = (repc \\<propto> high) y \\<and> \n                  (repc \\<propto> low) no1 = (repc \\<propto> low) y) = (repc y = repc no1)\"\n                  by simp\n                from repcy_in_llb  x_repcy show ?thesis\n                  by (auto simp add: Nodes_def)\n              next\n                assume lowy_nNull: \"low y \\<noteq> Null\"\n                with pret_dag prebdt_pret y_in_pret \n                have highy_nNull: \"high y \\<noteq> Null\"\n                  apply -\n                  apply (drule balanced_bdt)\n                  apply auto\n                  done\n                show ?thesis\n                proof (cases \"(repc \\<propto> low) y = (repc \\<propto> high) y\")\n                  case True\n                  with red_prop lowy_nNull have \"repc y = (repc \\<propto> high) y\"\n                    by auto\n                  with highy_nNull have red_repc_y: \"repc y = repc (high y)\"\n                    by (simp add: null_comp_def)\n                  from pret_dag ord_pret y_in_pret lowy_nNull  highy_nNull \n                  \n                  have \"var (low y) < var y \\<and> var (high y) < var y\"\n                    apply -\n                    apply (rule var_ordered_children) \n                    apply auto\n                    done\n                  with  vary_n have varhighy: \"var (high y) < n\"\n                    by auto\n                  from y_in_pret y_nNull highy_nNull pret_dag  \n                  have \"high y \\<in> set_of pret\" \n                    apply -\n                    apply (drule subelem_set_of_high)\n                    apply auto\n                    done\n                  with wf_ll varhighy have \"high y \\<in> Nodes n ll\"\n                    by (auto simp add: wf_ll_def Nodes_def)\n                  with red_repc_y have \"repc y \\<in> repc `Nodes n ll\"\n                    by simp\n                  with x_repcy have \"x \\<in> repc `Nodes n ll\"\n                    by simp\n                  with repbNodes_repcNodes repbNodes_in_Nodes \n                  have \"x \\<in> Nodes n ll\" \n                    by auto\n                  with Nodes_subset show ?thesis \n                    by auto\n                next\n                  assume \"(repc \\<propto> low) y \\<noteq> (repc \\<propto> high) y\"\n                  with share_prop obtain \n                    repcy_in_llbn: \"repc y \\<in> set (ll ! n)\" and\n                    rry_ry: \"repc (repc y) = repc y\" and \n                    y_other_node_share: \"\\<forall>no1\\<in>set (ll ! n). \n                    ((repc \\<propto> high) no1 = (repc \\<propto> high) y \\<and> \n                    (repc \\<propto> low) no1 = (repc \\<propto> low) y) = (repc y = repc no1)\"\n                    by auto\n                  with repcy_in_llbn  x_repcy have \"x \\<in> set (ll ! n)\"\n                    by auto\n                  then show ?thesis\n                    by (auto simp add: Nodes_def)\n                qed\n              qed\n            qed\n          qed\n        qed\n        have \"(\\<forall>no\\<in>Nodes (n + 1) ll.\n          var (repc no) \\<le> var no \\<and> \n          (\\<exists>not nort. Dag (repc no) (repc \\<propto> low) (repc \\<propto> high) nort \\<and>\n          Dag no low high not \\<and>\n          reduced nort \\<and> ordered nort var \\<and> \n          set_of nort \\<subseteq> repc ` Nodes (n + 1) ll \\<and> \n          (\\<forall>no\\<in>set_of nort. repc no = no) \\<and>\n          (\\<exists>nobdt. bdt not var = Some nobdt \\<and> \n          (\\<exists>norbdt. bdt nort var = Some norbdt \\<and> nobdt \\<sim> norbdt))))\"\n          (is \"\\<forall>no\\<in>Nodes (n + 1) ll. ?Q i no\")\n        proof (intro ballI)\n          fix no\n          assume no_in_Nodes: \"no \\<in> Nodes (n + 1) ll\"\n          from wf_ll no_in_Nodes nsll  have no_in_pret: \"no \\<in> set_of pret\"\n            apply (simp add: wf_ll_def Nodes_def length_ll_eq)\n            apply (erule conjE)\n            apply (thin_tac \"\\<forall>q. q \\<in> set_of pret \\<longrightarrow> q \\<in> set (ll ! var q)\")\n            apply (erule exE)\n            apply (erule_tac x=x in allE)\n            apply (erule impE)\n            apply arith\n            apply (erule_tac x=no in ballE)\n            apply auto\n            done\n          from pret_dag no_in_pret have nonNull: \"no\\<noteq> Null\" \n            apply -\n            apply (rule set_of_nn [rule_format])\n            apply auto\n            done  \n          show \"?Q i no\"\n          proof (cases \"no \\<in> Nodes n ll\")\n            case True\n            note no_in_Nodesn=this\n            with wf_ll nsll  no_in_Nodes \n            have no_notin_llbn: \"no \\<notin> set (ll ! n)\"\n              apply -\n              apply (simp add: Nodes_def length_ll_eq)\n              apply (elim exE)\n              apply (drule_tac ?i=xa and ?j=n in no_in_one_ll)\n              apply arith\n              apply simp\n              apply auto\n              done\n            with repbc_nc have repb_no_eq_repc_no: \"repb no = repc no\" \n              by simp\n            from repbc_nc no_in_Nodes no_notin_llbn normalize_prop True \n            have varrep_eq_var: \"var (repc no) \\<le> var no\" \n              apply -\n              apply (erule_tac x=no in ballE)\n              prefer 2\n              apply simp\n              apply (erule_tac x=no in allE)\n              apply simp\n              done\n            moreover\n            from True normalize_prop no_in_Nodes obtain not nort where\n              nort_dag: \"Dag (repb no) (repb \\<propto> low) (repb \\<propto> high) nort\" and\n              ord_nort: \"ordered nort var\" and\n              subset_nort_not:  \"set_of nort \\<subseteq> repb `(Nodes n ll)\" and\n              not_dag:  \" Dag no low high not\" and\n              red_nort: \"reduced nort\" and \n              nort_repb: \"(\\<forall>no\\<in>set_of nort. repb no = no)\" and\n              bdt_prop: \"\\<exists>nobdt norbdt. bdt not var = Some nobdt \\<and> \n              bdt nort var = Some norbdt \\<and> nobdt \\<sim> norbdt\" \n              by blast\n            moreover\n            from Nodesn_notin_lln repbc_nc nort_repb subset_nort_not repbNodes_in_Nodes \n            have nort_repc: \n              \"(\\<forall>no\\<in>set_of nort. repc no = no)\"\n              apply auto\n              apply (subgoal_tac \"no \\<in> Nodes n ll\")\n              apply fastforce\n              apply blast\n              done\n            moreover\n            from nort_dag have nortnodesnN: \"(\\<forall>no. no \\<in> set_of nort \\<longrightarrow> no \\<noteq> Null)\"\n              apply -\n              apply (rule allI)\n              apply (rule impI)\n              apply (rule set_of_nn)\n              apply auto\n              done\n            moreover  \n            have \"Dag (repc no) (repc \\<propto> low) (repc \\<propto> high) nort\"\n            proof -\n              from no_notin_llbn repbc_nc have repbc_no: \"repc no = repb no\"\n                by fastforce\n              with nort_dag \n              have nortrepbc_dag: \"Dag (repc no) (repb \\<propto> low) (repb \\<propto> high) nort\"\n                by simp\n              from wf_ll nseqll have \"Nodes n ll \\<subseteq> set_of pret\"\n                apply -\n                apply (rule Nodes_levellist_subset_t)\n                apply assumption+\n                apply (simp add: length_ll_eq)\n                done\n              with repbNodes_in_Nodes subset_nort_not \n              have subset_nort_pret:  \"set_of nort \\<subseteq> set_of pret\"\n                by simp\n              have vxsn_in_pret: \"\\<forall> x \\<in> set_of nort. var x < n \\<and> x \\<in> set_of pret\"\n              proof (rule ballI)\n                fix x\n                assume x_in_nort: \"x \\<in> set_of nort\"\n                from x_in_nort subset_nort_not repbNodes_in_Nodes \n                have \"x \\<in> Nodes n ll\"\n                  by blast\n                with wf_ll nsll  have xsn: \"var x < n\"\n                  apply (simp add: wf_ll_def Nodes_def length_ll_eq)\n                  apply (erule conjE)\n                  apply (thin_tac \" \\<forall>q. q \\<in> set_of pret \\<longrightarrow> q \\<in> set (ll ! var q)\")\n                  apply (erule exE)\n                  apply (erule_tac x=xa in allE)\n                  apply (erule impE)\n                  apply arith\n                  apply (erule_tac x=x in ballE)\n                  apply auto\n                  done\n                from x_in_nort subset_nort_pret have x_in_pret: \"x \\<in> set_of pret\"\n                  by blast\n                with xsn show \"var x < n \\<and> x \\<in> set_of pret\" by simp\n              qed\n              with pret_dag prebdt_pret nortrepbc_dag ord_pret wf_ll  nsll \n                repbc_nc \n              have \"\\<forall> x \\<in> set_of nort. ((repc \\<propto> low) x = (repb \\<propto> low) x \\<and> \n                (repc \\<propto> high) x = (repb \\<propto> high) x)\"\n                apply -\n                apply (rule nort_null_comp)\n                apply (auto simp add: length_ll_eq)\n                done\n              with nort_dag \n              have \"Dag (repc no) (repc \\<propto> low) (repc \\<propto> high) nort = \n                Dag (repc no) (repb \\<propto> low) (repb \\<propto> high) nort\"\n                apply -\n                apply (rule heaps_eq_Dag_eq)\n                apply simp\n                done\n              with nortrepbc_dag show ?thesis\n                by simp\n            qed\n            moreover \n            have \"set_of nort \\<subseteq> repc `(Nodes (n + 1) ll)\"\n            proof -\n              have Nodesn_in_NodesSucn: \"Nodes n ll \\<subseteq> Nodes (n + 1) ll\"\n                by (simp add: Nodes_def set_split)\n              then have repbNodesn_in_repbNodesSucn: \n                \"repb `(Nodes n ll) \\<subseteq> repb `(Nodes (n + 1) ll)\"\n                by blast\n              from wf_ll nsll  \n              have Nodes_n_notin_lln: \"\\<forall>no \\<in> Nodes n ll. no \\<notin> set (ll ! n)\"\n                apply (simp add: Nodes_def length_ll_eq)\n                apply clarify\n                apply (drule no_in_one_ll)\n                apply auto\n                done\n              with repbc_nc  have \"\\<forall>no \\<in> Nodes n ll. repb no = repc no\"\n                apply -\n                apply (rule ballI)\n                apply (erule_tac x=no in allE)\n                apply simp\n                done\n              then have repbNodes_repcNodes: \n                \"repb `(Nodes n ll) = repc `(Nodes n ll)\"\n                apply -\n                apply rule\n                apply blast\n                apply rule\n                apply (erule imageE)\n                apply (erule_tac x=xa in ballE)\n                prefer 2\n                apply simp\n                apply rule\n                apply auto\n                done\n              from Nodesn_in_NodesSucn \n              have \"repc `(Nodes n ll) \\<subseteq> repc `(Nodes (n + 1) ll)\"\n                by blast\n              with repbNodes_repcNodes subset_nort_not repbNodesn_in_repbNodesSucn \n              show ?thesis by simp\n            qed\n            ultimately show ?thesis \n              by blast\n          next\n            assume \" no \\<notin> Nodes n ll\"\n            with no_in_Nodes  have no_in_llbn: \"no \\<in> set (ll ! n)\"\n              apply (simp add: Nodes_def)\n              apply (erule exE)\n              apply (erule_tac x=x in allE)\n              apply (case_tac \"x<n\")\n              apply simp\n              apply simp\n              apply (elim conjE)\n              apply (case_tac \"x=n\")\n              apply simp\n              apply arith\n              done\n            with wf_ll  nsll have varno: \"var no = n\"\n              by (simp add: wf_ll_def length_ll_eq)\n            from repbc_changes no_in_llbn \n            have repbcno_changes: \"repc no \\<noteq> Null \\<and>\n              ((repc \\<propto> low) no = (repc \\<propto> high) no \\<and> low no \\<noteq> Null \n              \\<longrightarrow> repc no = (repc \\<propto> high) no) \\<and>\n              (((repc \\<propto> low) no = (repc \\<propto> high) no \\<longrightarrow> low no = Null) \n              \\<longrightarrow> repc no \\<in> set (ll ! n)  \\<and> repc (repc no) = repc no \\<and> \n              (\\<forall>no1\\<in>set (ll ! n). ((repc \\<propto> high) no1 = (repc \\<propto> high) no \\<and>\n              (repc \\<propto> low) no1 = (repc \\<propto> low) no) = (repc no = repc no1)))\"\n              (is \"?rnonN \\<and> ?repreduce \\<and> ?repshare\")\n              using [[simp_depth_limit=4]]\n              by (simp split: if_split)\n            then obtain \n              rnonN: \"?rnonN\" and\n              repreduce: \"?repreduce\" and\n              repshare: \"?repshare\"\n              by blast\n            have repcn_normalize: \"var (repc no) \\<le> var no \\<and>\n              (\\<exists>not nort. Dag (repc no) (repc \\<propto> low) (repc \\<propto> high) nort \\<and>\n              Dag no low high not \\<and> reduced nort \\<and> ordered nort var \\<and>\n              set_of nort \\<subseteq> repc ` Nodes (n + 1) ll \\<and>\n              (\\<forall>no\\<in>set_of nort. repc no = no) \\<and>\n              (\\<exists>nobdt. bdt not var = Some nobdt \\<and> \n              (\\<exists>norbdt. bdt nort var = Some norbdt \\<and> nobdt \\<sim> norbdt)))\"\n              (is \"?varrep \\<and> ?repcn_prop\" \n                is \"?varrep \\<and> \n                (\\<exists>not nort. ?nort_dag nort \\<and> ?not_dag not \\<and> ?red nort \\<and> \n                ?ord nort \\<and> ?nort_in_Nodes nort \\<and> ?repcno_no_n nort \\<and> ?bdt_equ not nort)\")\n            proof (cases \"high no = Null\")\n              case True\n              note highnoNull=this\n              with pret_dag prebdt_pret no_in_pret   \n              have lownoNull: \"low no = Null\"\n                apply -\n                apply (drule balanced_bdt)\n                apply assumption+\n                apply simp\n                done\n              with repshare have repcnoinlln:\"repc no \\<in> set (ll ! n)\"\n                by simp\n              with wf_ll  nsll have varrno_n: \"var (repc no) = n\"\n                by (simp add: wf_ll_def length_ll_eq)\n              with varno have varrep: \"?varrep\"\n                by simp\n              from wf_ll  nsll no_in_llbn varrno_n \n              have varrno_varno: \"var (repc no) = var no\"\n                by (simp add: wf_ll_def length_ll_eq)\n              from wf_ll  nsll repcnoinlln \n              have rno_in_pret: \"repc no \\<in> set_of pret\" \n                by (simp add: wf_ll_def length_ll_eq)\n              from repcnoinlln repshare lownoNull \n              have reprep_eq_rep: \"repc (repc no) = repc no\" \n                by simp\n              with repcnoinlln repshare lownoNull \n              have repchildreneq: \n                \"((repc \\<propto> high) (repc no) = (repc \\<propto> high) no \\<and> \n                (repc \\<propto> low) (repc no) = (repc \\<propto> low) no)\"\n                by simp\n              have repcn_prop: \"?repcn_prop\"\n                apply -         \n                apply (rule_tac x=\"(Node Tip no Tip)\" in exI)\n                apply (rule_tac x=\"(Node Tip (repc no) Tip)\" in exI)\n                apply (intro conjI)\n                apply simp\n                prefer 3\n                apply simp\n                prefer 3\n                apply simp\n              proof -\n                from pret_dag pnN rno_in_pret have rnonN: \"repc no \\<noteq> Null\"\n                  apply (case_tac \"repc no = Null\")\n                  apply auto\n                  done\n                from highnoNull repchildreneq \n                have rhighNull: \"(repc \\<propto> high) (repc no) = Null\" \n                  by (simp add: null_comp_def)\n                from lownoNull repchildreneq \n                have rlowNull: \"(repc \\<propto> low) (repc no) = Null\" \n                  by (simp add: null_comp_def)\n                with rhighNull rnonN   \n                show \"repc no \\<noteq> Null \\<and> (repc \\<propto> low) (repc no) = Null \\<and> \n                  (repc \\<propto> high) (repc no) = Null\"\n                  by simp\n              next\n                from nonNull lownoNull highnoNull   \n                show \"?not_dag (Node Tip no Tip)\"\n                  by simp\n              next\n                from no_in_Nodes \n                show \"set_of (Node Tip (repc no) Tip) \\<subseteq>  repc ` Nodes (n + 1) ll\"\n                  by simp\n              next\n                show \"\\<forall>no\\<in>set_of (Node Tip (repc no) Tip). repc no = no\"\n                proof \n                  fix pt\n                  assume pt_in_repcLeaf: \"pt \\<in> set_of (Node Tip (repc no) Tip)\"\n                  with reprep_eq_rep show \"repc pt = pt\"\n                    by simp\n                qed\n              next\n                show \"?bdt_equ (Node Tip no Tip) (Node Tip (repc no) Tip)\"\n                proof (cases \"var no = 0\")\n                  case True \n                  note vno_Null=this\n                  then have nobdt: \"bdt (Node Tip no Tip) var = Some Zero\" by simp\n                  from varrep  vno_Null have varrno: \"var (repc no) = 0\" by simp\n                  then have norbdt: \"bdt (Node Tip (repc no) Tip) var = Some Zero\" by simp\n                  from nobdt norbdt vno_Null varrno show ?thesis\n                    by (simp add: cong_eval_def)\n                next\n                  assume vno_not_Null: \"var no \\<noteq> 0\"\n                  show ?thesis\n                  proof (cases \"var no = 1\")\n                    case True\n                    note vno_One=this\n                    then have nobdt: \"bdt (Node Tip no Tip) var = Some One\" by simp\n                    from varrno_varno vno_One \n                    have \"bdt (Node Tip (repc no) Tip) var = Some One\" by simp \n                    with nobdt show ?thesis by (auto simp add: cong_eval_def)\n                  next\n                    assume vno_nOne: \"var no \\<noteq> 1\"\n                    with vno_not_Null have onesvno: \"1 < var no\" by simp\n                    from nonNull lownoNull highnoNull   \n                    have no_dag: \"Dag no low high (Node Tip no Tip)\"\n                      by simp \n                    with pret_dag no_in_pret have not_in_pret: \"(Node Tip no Tip) \\<le> pret\"\n                      by (metis set_of_subdag)\n                    with prebdt_pret have \"\\<exists>bdt2. bdt (Node Tip no Tip) var = Some bdt2\"\n                      by (metis subbdt_ex)\n                    with onesvno show ?thesis \n                      by simp\n                  qed\n                qed\n              qed\n              with varrep reprep_eq_rep show ?thesis by simp\n            next\n              assume hno_nNull: \"high no \\<noteq> Null\"\n              with pret_dag prebdt_pret no_in_pret   have lno_nNull: \"low no \\<noteq> Null\"\n                by (metis balanced_bdt)\n                  (*-------------------normalize_prop fuer (high no)------------------------*)\n              \n              from no_in_pret nonNull hno_nNull pret_dag  \n              have hno_in_pret: \"high no \\<in> set_of pret\"\n                by (metis subelem_set_of_high)\n              with wf_ll \n              have hno_in_ll: \"high no \\<in> set (ll ! (var (high no)))\" \n                by (simp add: wf_ll_def)\n              from pret_dag ord_pret  no_in_pret lno_nNull hno_nNull \n              \n              have varhnos_varno: \"var (high no) < var no\"\n                by (metis var_ordered_children)\n              with varno have varhnos_n: \"var (high no) < n\" by simp\n              with hno_in_ll have hno_in_Nodesn: \"high no \\<in> Nodes n ll\"\n                apply (simp add: Nodes_def)\n                apply (rule_tac x=\"var (high no)\" in exI)\n                apply simp\n                done\n              from wf_ll nsll hno_in_ll   varhnos_n \n              have \"high no \\<notin> set (ll ! n)\"\n                apply -\n                apply (rule no_in_one_ll)\n                apply (auto simp add: length_ll_eq)\n                done\n              with repbc_nc have repb_repc_high: \"repb (high no) = repc (high no)\" by simp\n              with normalize_prop hno_in_Nodesn varhnos_varno varno \n              have high_normalize: \"var (repc (high no)) \\<le> var (high no) \\<and>\n                (\\<exists>not nort. Dag (repc (high no)) (repb \\<propto> low) (repb \\<propto> high) nort \\<and>\n                Dag (high no) low high not \\<and> reduced nort \\<and>\n                ordered nort var \\<and> set_of nort \\<subseteq> repb `(Nodes n ll) \\<and>\n                (\\<forall>no\\<in>set_of nort. repb no = no) \\<and>\n                (\\<exists>nobdt norbdt. bdt not var = Some nobdt \\<and> bdt nort var = \n                Some norbdt \\<and> nobdt \\<sim> norbdt))\"\n                (is \"?varrep_high \\<and> \n                  (\\<exists>not nort. ?repbchigh_dag nort \\<and> ?high_dag not \\<and> \n                  ?redhigh nort \\<and> ?ordhigh nort \\<and> ?rephigh_in_Nodes nort \\<and> \n                  ?repbno_no nort \\<and> ?highdd_prop not nort)\"\n                  is \"?varrep_high \\<and> ?not_nort_prop\")\n                apply simp\n                apply (erule_tac x=\"high no\" in ballE)\n                apply (simp del: Dag_Ref)\n                apply simp\n                done\n              then have varrep_high: \"?varrep_high\" by simp\n              from varhnos_n varrep_high have varrephno_s_n: \n                \"var (repc (high no)) < n\"\n                by simp\n              from Nodes_subset \n              have \"Nodes n ll \\<subseteq> Nodes (Suc n) ll\"\n                by auto\n              with hno_in_Nodesn repcNodes_in_Nodes \n              have \"repc (high no) \\<in> Nodes (Suc n) ll\"\n                apply simp\n                apply blast\n                done\n              with wf_ll nsll  have \"repc (high no) \\<in> set_of pret\"\n                apply (simp add: wf_ll_def Nodes_def length_ll_eq)\n                apply (elim conjE exE)\n                apply (thin_tac \" \\<forall>q. q \\<in> set_of pret \\<longrightarrow> q \\<in> set (ll ! var q)\")\n                apply (erule_tac x=x in allE)\n                apply (erule impE)\n                apply simp\n                apply (erule_tac x=\"repc (high no)\" in ballE)\n                apply auto\n                done\n              with wf_ll varrephno_s_n \n              have \"\\<exists> k<n. repc (high no) \\<in> set (ll ! k)\"\n                by (auto simp add: wf_ll_def)\n              with wf_ll nsll  have \"repc (high no) \\<notin> set (ll ! n)\"\n                apply -\n                apply (erule exE)\n                apply (rule_tac i=k and j=n in no_in_one_ll)\n                apply (auto simp add: length_ll_eq)\n                done\n              with repbc_nc \n              have repbchigh_idem: \"repb (repc (high no)) = repc (repc (high no))\"\n                by auto\n              from high_normalize \n              have not_nort_prop_high: \"?not_nort_prop\" by (simp del: Dag_Ref)\n              from not_nort_prop_high obtain hnot where high_dag: \"?high_dag hnot\"\n                by auto\n              from wf_ll nsll  \n              have \"\\<forall>no \\<in> Nodes n ll. no \\<notin> set (ll ! n)\"\n                apply (simp add: Nodes_def length_ll_eq)\n                apply clarify\n                apply (drule no_in_one_ll)\n                apply auto\n                done\n              with repbc_nc  have \"\\<forall>no \\<in> Nodes n ll. repb no = repc no\"\n                apply -\n                apply (rule ballI)\n                apply (erule_tac x=no in allE)\n                apply simp\n                done\n              then \n              have repbNodes_repcNodes: \n                \"repb `(Nodes n ll) = repc `(Nodes n ll)\"\n                apply -\n                apply rule\n                apply blast\n                apply rule\n                apply (erule imageE)\n                apply (erule_tac x=xa in ballE)\n                prefer 2\n                apply simp\n                apply rule\n                apply auto\n                done\n              then have repcNodes_repbNodes: \n                \"repc `(Nodes n ll) = repb `(Nodes n ll)\"\n                by simp\n              from pret_dag nsll  wf_ll \n              have null_notin_Nodesn: \"Null \\<notin> Nodes n ll\"\n                apply -\n                apply (rule Null_notin_Nodes)\n                apply (auto simp add: length_ll_eq)\n                done\n              from hno_in_Nodesn have \"repc (high no) \\<in> repc `(Nodes n ll)\"\n                by blast\n              with repbNodes_in_Nodes repcNodes_repbNodes \n              have \"repc (high no) \\<in> Nodes n ll\"\n                apply simp\n                apply blast\n                done\n              with null_notin_Nodesn have rhn_nNull: \"repc (high no) \\<noteq> Null\"\n                by auto\n\n                  (*-------------------normalize_prop fuer (low no)--------------------------*)\n\n              from no_in_pret nonNull lno_nNull pret_dag  \n              have lno_in_pret: \"low no \\<in> set_of pret\"\n                by (rule subelem_set_of_low)\n              with wf_ll \n              have lno_in_ll: \"low no \\<in> set (ll ! (var (low no)))\" \n                by (simp add: wf_ll_def)\n              from pret_dag ord_pret  no_in_pret lno_nNull hno_nNull  \n              have varlnos_varno: \"var (low no) < var no\"\n                apply -\n                apply (drule var_ordered_children)\n                apply assumption+\n                apply auto\n                done\n              with varno have varlnos_n: \"var (low no) < n\" by simp\n              with lno_in_ll have lno_in_Nodesn: \"low no \\<in> Nodes n ll\"\n                apply (simp add: Nodes_def)\n                apply (rule_tac x=\"var (low no)\" in exI)\n                apply simp\n                done\n              from varlnos_n wf_ll nsll lno_in_ll   \n              have \"low no \\<notin> set (ll ! n)\"\n                apply -\n                apply (rule no_in_one_ll)\n                apply (auto simp add: length_ll_eq)\n                done\n              with repbc_nc have repb_repc_low: \"repb (low no) = repc (low no)\" by simp\n              with normalize_prop lno_in_Nodesn varlnos_varno varno \n              have low_normalize: \"var (repc (low no)) \\<le> var (low no) \\<and>\n                (\\<exists>not nort. Dag (repc (low no)) (repb \\<propto> low) (repb \\<propto> high) nort \\<and>\n                Dag (low no) low high not \\<and> reduced nort \\<and> ordered nort var \\<and>\n                set_of nort \\<subseteq> repb `(Nodes n ll) \\<and>\n                (\\<forall>no\\<in>set_of nort. repb no = no) \\<and>\n                (\\<exists>nobdt norbdt. bdt not var = Some nobdt \\<and> bdt nort var = Some norbdt \\<and> \n                nobdt \\<sim> norbdt))\"\n                (is \"?varrep_low \\<and> \n                  (\\<exists>not nort. ?repbclow_dag nort \\<and> ?low_dag not \\<and> ?redhigh nort \\<and> \n                  ?ordhigh nort \\<and> ?replow_in_Nodes nort  \\<and> ?low_repno_no nort \n                  \\<and> ?lowdd_prop not nort)\"\n                  is \"?varrep_low \\<and> ?not_nort_prop_low\")\n                apply simp\n                apply (erule_tac x=\"low no\" in ballE)\n                apply (simp del: Dag_Ref)\n                apply simp\n                done\n              then have varrep_low: \"?varrep_low\" by simp\n              from low_normalize have not_nort_prop_low: \"?not_nort_prop_low\" \n                by (simp del: Dag_Ref)\n              from lno_in_Nodesn have \"repc (low no) \\<in> repc `(Nodes n ll)\"\n                by blast\n              with repbNodes_in_Nodes repcNodes_repbNodes \n              have \"repc (low no) \\<in> Nodes n ll\"\n                apply simp\n                apply blast\n                done\n              with null_notin_Nodesn have rln_nNull: \"repc (low no) \\<noteq> Null\"\n                by auto\n\n              \n              show ?thesis\n              proof (cases \"repc (low no) = repc (high no)\")\n                case True\n                note red_case=this\n                with repreduce lno_nNull hno_nNull \n                have rno_eq_hrno: \"repc no = repc (high no)\" \n                  by (simp add: null_comp_def)\n                from varhnos_varno rno_eq_hrno varrep_high have varrep: \"?varrep\" by simp\n                from not_nort_prop_high not_nort_prop_low have repcn_prop: \"?repcn_prop\"\n                  apply -\n                  apply (elim exE)\n                  apply (rename_tac rnot lnot rnort lnort )\n                  apply (rule_tac x=\"(Node lnot no rnot)\" in exI)\n                  apply (rule_tac x=rnort in exI)\n                  apply (elim conjE)\n                  apply (intro conjI)\n                  prefer 7\n                  apply (elim exE)\n                  apply (rename_tac rnot lnot rnort lnort rnobdt lnobdt rnorbdt lnorbdt)\n                  apply (elim conjE)\n                  apply (case_tac  \"Suc 0 < var no\")\n                  apply (rule_tac x=\"(Bdt_Node lnobdt (var no) rnobdt)\" in exI)\n                  apply (rule conjI)\n                  prefer 2\n                  apply (rule_tac x=rnorbdt in exI)\n                  apply (rule conjI)\n                proof -\n                  fix rnot lnot rnort lnort\n                  assume highnort_dag: \n                    \"Dag (repc (high no)) (repb \\<propto> low) (repb \\<propto> high) rnort\"\n                  assume ord_nort: \" ordered rnort var\"\n                  assume rnort_in_repNodes: \" set_of rnort \\<subseteq>  repb ` Nodes n ll\"\n                  from rnort_in_repNodes repbNodes_in_Nodes \n                  have nort_in_Nodes: \"set_of rnort \\<subseteq> Nodes n ll\"\n                    by blast\n                  from varhnos_n varrep_high \n                  have vrhnos_n: \"var (repc (high no)) < n\" by simp\n                  from rhn_nNull highnort_dag \n                  have \"\\<exists>lno rno. rnort = Node lno (repc (high no)) rno\" by fastforce\n                  with highnort_dag rhn_nNull have \"root rnort = repc (high no)\" by auto\n                  with ord_nort have \"\\<forall>x \\<in> set_of rnort. var x <= var (repc (high no))\"\n                    apply -\n                    apply (rule ballI)\n                    apply (drule ordered_set_of)\n                    apply auto\n                    done\n                  with vrhnos_n have vxsn: \"\\<forall>x \\<in> set_of rnort. var x < n\" \n                    by fastforce\n                  from nort_in_Nodes have \"\\<forall>x \\<in> set_of rnort. x \\<in> Nodes n ll\" \n                    by auto\n                  with wf_ll nsll  \n                  have x_in_pret: \"\\<forall>x \\<in> set_of rnort. x \\<in> set_of pret\"\n                    apply -\n                    apply (rule ballI)\n                    apply (drule wf_ll_Nodes_pret)\n                    apply (auto simp add: length_ll_eq)\n                    done\n                  from vxsn x_in_pret \n                  have vxsn_in_nort: \"\\<forall>x \\<in> set_of rnort. var x <n \\<and> x \\<in> set_of pret\"\n                    by auto\n                  with pret_dag prebdt_pret highnort_dag ord_pret wf_ll  nsll \n                    repbc_nc \n                  have \"\\<forall>x \\<in> set_of rnort. (repc \\<propto> low) x = (repb \\<propto> low) x \\<and> \n                    (repc \\<propto> high) x = (repb \\<propto> high) x\"\n                    apply -\n                    apply (rule nort_null_comp)\n                    apply (auto simp add: length_ll_eq)\n                    done\n                  with rno_eq_hrno \n                  have \"Dag (repc no) (repc \\<propto> low) (repc \\<propto> high) rnort = \n                    Dag (repc no) (repb \\<propto> low) (repb \\<propto> high) rnort\"\n                    apply -\n                    apply (rule heaps_eq_Dag_eq)\n                    apply simp\n                    done\n                  with highnort_dag rno_eq_hrno \n                  show \"Dag (repc no) (repc \\<propto> low) (repc \\<propto> high) rnort\" by simp\n                next\n                  fix rnot lnot rnort lnort\n                  assume lnot_dag: \"Dag (low no) low high lnot\"\n                  assume rnot_dag: \"Dag (high no) low high rnot\"\n                  with lnot_dag   nonNull \n                  show \"Dag no low high (Node lnot no rnot)\" by simp\n                next\n                  fix rnot lnot rnort lnort\n                  assume \" reduced rnort\"\n                  then show \"reduced rnort\" by simp\n                next\n                  fix rnort\n                  assume \"ordered rnort var\"\n                  then show \"ordered rnort var\" by simp\n                next\n                  fix rnort\n                  assume rnort_in_Nodes: \" set_of rnort \\<subseteq> repb ` Nodes n ll\"\n                  have \"Nodes n ll \\<subseteq> Nodes (n + 1) ll\" \n                    by (simp add: Nodes_def set_split) \n                  then have \"repc ` Nodes n ll \\<subseteq> repc ` Nodes (n + 1) ll\"\n                    by blast\n                  with rnort_in_Nodes repbNodes_repcNodes \n                  show \" set_of rnort \\<subseteq> repc ` Nodes (n + 1) ll\" \n                    by (simp add: Nodes_def)\n                next\n                  fix rnort rnorbdt\n                  assume \" bdt rnort var = Some rnorbdt\"\n                  then show \" bdt rnort var = Some rnorbdt\" by simp\n                next\n                  fix rnot lnot rnort lnort rnobdt lnobdt rnorbdt lnorbdt\n                  assume rcongeval: \"rnobdt \\<sim> rnorbdt\"\n                  assume lnort_dag: \n                    \"Dag (repc (low no)) (repb \\<propto> low) (repb \\<propto> high) lnort\"\n                  assume rnort_dag: \n                    \"Dag (repc (high no)) (repb \\<propto> low) (repb \\<propto> high) rnort\"\n                  assume lnorbdt_def: \" bdt lnort var = Some lnorbdt\"\n                  assume rnorbdt_def: \" bdt rnort var = Some rnorbdt\"\n                  assume lcongeval:\"lnobdt \\<sim> lnorbdt\"\n                  from red_case lnort_dag rnort_dag \n                  have lnort_rnort: \"lnort = rnort\" \n                    by (simp add: Dag_unique del: Dag_Ref)\n                  with lnorbdt_def lcongeval rnorbdt_def \n                  have lnobdt_rnorbdt: \"lnobdt \\<sim> rnorbdt\" by simp\n                  with rcongeval have \"lnobdt \\<sim> rnobdt\" \n                    apply -\n                    apply (rule cong_eval_trans)\n                    apply (auto simp add: cong_eval_sym)\n                    done\n                  then have \" Bdt_Node lnobdt (var no) rnobdt \\<sim> rnobdt\"\n                    apply -\n                    apply (simp add: cong_eval_sym [rule_format])\n                    apply (rule cong_eval_child_high)\n                    apply assumption\n                    done\n                  with rcongeval show \"Bdt_Node lnobdt (var no) rnobdt \\<sim> rnorbdt\"\n                    apply -\n                    apply (rotate_tac 1)\n                    apply (rule cong_eval_trans)\n                    apply auto\n                    done\n                next\n                  fix lnot rnot lnobdt rnobdt\n                  assume lnot_dag: \"Dag (low no) low high lnot\"\n                  assume rnot_dag: \" Dag (high no) low high rnot\"\n                  assume lnobdt_def: \" bdt lnot var = Some lnobdt\"\n                  assume rnobdt_def: \" bdt rnot var = Some rnobdt\"\n                  assume onesvarno: \" Suc 0 < var no\"\n                  with rnobdt_def lnot_dag rnot_dag lnobdt_def \n                  show \"bdt (Node lnot no rnot) var = \n                    Some (Bdt_Node lnobdt (var no) rnobdt)\" \n                    by simp\n                next\n                  fix rnot lnot rnort lnort rnobdt lnobdt rnorbdt lnorbdt\n                  assume lnobdt_def: \" bdt lnot var = Some lnobdt\"\n                  assume rnobdt_def: \" bdt rnot var = Some rnobdt\"\n                  assume rnorbdt_def: \" bdt rnort var = Some rnorbdt\"\n                  assume cong_rno_rnor: \" rnobdt \\<sim> rnorbdt\"\n                  assume lnot_dag: \"Dag (low no) low high lnot\"\n                  assume rnot_dag: \"Dag (high no) low high rnot\"\n                  assume \"\\<not> Suc 0 < var no\"\n                  then have varnoseq1: \"var no = 0 \\<or> var no = 1\" by auto\n                  show \"\\<exists>nobdt. bdt (Node lnot no rnot) var = Some nobdt \\<and> \n                    (\\<exists>norbdt. bdt rnort var = Some norbdt \\<and> nobdt \\<sim> norbdt)\"\n                  proof (cases \"var no = 0\")\n                    case True\n                    note vnoNull=this\n                    with pret_dag ord_pret no_in_pret lno_nNull hno_nNull  \n                    show ?thesis\n                      apply -\n                      apply (drule var_ordered_children)\n                      apply auto\n                      done\n                  next\n                    assume \"var no \\<noteq> 0\"\n                    with varnoseq1 have vnoOne: \"var no = 1\" by simp\n                    from pret_dag  ord_pret no_in_pret lno_nNull hno_nNull  \n                      vnoOne \n                    have vlvrNull: \"var (low no) = 0 \\<and> var (high no) = 0\"\n                      apply -\n                      apply (drule var_ordered_children)\n                      apply auto\n                      done\n                    then have vlNull: \"var (low no) = 0\" by simp\n                    from vlvrNull have vrNull: \"var (high no) = 0\" by simp\n                    from lnobdt_def lnot_dag vlNull  lno_nNull \n                    have lnobdt_Zero: \"lnobdt = Zero\"\n                      apply -\n                      apply (drule bdt_Some_var0_Zero)\n                      apply auto\n                      done\n                    from rnobdt_def rnot_dag vrNull  hno_nNull \n                    have rnobdt_Zero: \"rnobdt = Zero\"\n                      apply -\n                      apply (drule bdt_Some_var0_Zero)\n                      apply auto\n                      done\n                    from lnobdt_Zero lnobdt_def have \"bdt lnot var = Some Zero\" by simp\n                    with lnot_dag vlNull  \n                    have lnot_Node: \"lnot = (Node Tip (low no) Tip)\"\n                      by auto\n                    from rnobdt_Zero rnobdt_def rnot_dag vrNull  \n                    have rnot_Node: \"rnot = (Node Tip (high no) Tip)\" \n                      by auto\n                    from pret_dag no_in_pret obtain not where \n                      not_ex: \"Dag no low high not\"\n                      apply -\n                      apply (drule dag_setof_exD)\n                      apply auto\n                      done\n                    with pret_dag no_in_pret have not_ex_in_pret: \"not <= pret\" \n                      apply -\n                      apply (rule set_of_subdag)\n                      apply auto\n                      done\n                    from not_ex lnot_dag rnot_dag   nonNull \n                    have not_def: \"not = (Node lnot no rnot)\" \n                      by (simp add: Dag_unique del: Dag_Ref)\n                    with not_ex_in_pret prebdt_pret \n                    have nobdt_ex: \"\\<exists>nobdt. bdt (Node lnot no rnot) var = Some nobdt\"\n                      apply -\n                      apply (rule subbdt_ex)\n                      apply auto\n                      done\n                    then obtain nobdt where \n                      nobdt_def: \"bdt (Node lnot no rnot) var = Some nobdt\" by auto\n                    from not_def have \"root not = no\" by simp\n                    with nobdt_def vnoOne not_def have \"not = (Node Tip no Tip)\"\n                      apply -\n                      apply (drule bdt_Some_var1_One)\n                      apply auto\n                      done\n                    with not_def have \"rnot = Tip\" by simp\n                    with rnot_Node show ?thesis by simp\n                  qed\n                next\n                  fix rnot lnot rnort lnort\n                  assume rnort_in_repb_Nodesn: \"set_of rnort \\<subseteq> repb ` Nodes n ll\"\n                  assume rnort_repb_no: \"\\<forall>no\\<in>set_of rnort. repb no = no\"\n                  from repbNodes_in_Nodes rnort_in_repb_Nodesn \n                  have rnort_in_Nodesn: \"set_of rnort \\<subseteq> Nodes n ll\"\n                    by blast\n                  show \"\\<forall>no\\<in>set_of rnort. repc no = no\"\n                  proof\n                    fix pt\n                    assume pt_in_rnort: \" pt \\<in> set_of rnort\"\n                    with rnort_in_Nodesn have \"pt \\<in> Nodes n ll\" \n                      by blast\n                    with Nodesn_notin_lln have \"pt \\<notin> set (ll ! n)\"\n                      by auto\n                    with repbc_nc have \"repb pt = repc pt\"\n                      by auto\n                    with rnort_repb_no pt_in_rnort show \"repc pt = pt\"\n                      by auto\n                  qed\n                qed\n                with varrep show ?thesis by simp\n              next\n                assume share_case_cond: \"repc (low no) \\<noteq> repc (high no)\"\n                with lno_nNull hno_nNull \n                have share_case_cond_propto: \"(repc \\<propto> low) no \\<noteq> (repc \\<propto> high) no\"\n                  by (simp add: null_comp_def)\n                with repshare obtain \n                  rno_in_llbn: \"repc no \\<in> set (ll ! n)\" and\n                  rrno_eq_rno: \"repc (repc no) = repc no\" and\n                  twonodes_in_llbn_prop: \"(\\<forall>no1\\<in>set (ll ! n). \n                  ((repc \\<propto> high) no1 = (repc \\<propto> high) no \\<and> \n                  (repc \\<propto> low) no1 = (repc \\<propto> low) no) = (repc no = repc no1))\"\n                  by auto\n                from wf_ll rno_in_llbn  nsll \n                have varrepno_n: \"var (repc no) = n\" \n                  by (simp add: wf_ll_def length_ll_eq)\n                with varno have varrep: \"?varrep\" \n                  by simp\n                from not_nort_prop_high not_nort_prop_low have repcn_prop: \"?repcn_prop\"\n                  apply-\n                  apply (elim exE)\n                  apply (rename_tac rnot lnot rnort lnort)\n                  apply (rule_tac x=\"Node lnot no rnot\" in exI)\n                  apply (rule_tac x=\"Node lnort (repc no) rnort\" in exI)\n                  apply (elim conjE)\n                  apply (intro conjI)\n                  prefer 7\n                  apply (elim exE)\n                  apply (rename_tac rnot lnot rnort lnort rnobdt lnobdt rnorbdt lnorbdt)\n                  apply (elim conjE)\n                  apply (case_tac  \"Suc 0 < var no\")\n                  apply (rule_tac x=\"(Bdt_Node lnobdt (var no) rnobdt)\" in exI)\n                  apply (rule conjI)\n                  prefer 2\n                  apply (rule_tac x=\"(Bdt_Node lnorbdt (var (repc no)) rnorbdt)\" in exI)\n                  apply (rule conjI)\n                proof -\n                  fix rnot lnot rnort lnort\n                  assume rnort_dag: \n                    \"Dag (repc (high no)) (repb \\<propto> low) (repb \\<propto> high) rnort\"\n                  assume lnort_dag: \n                    \"Dag (repc (low no)) (repb \\<propto> low) (repb \\<propto> high) lnort\"\n                  assume rnort_in_repNodes: \"set_of rnort \\<subseteq> repb ` Nodes n ll\"\n                  assume lnort_in_repNodes: \"set_of lnort \\<subseteq> repb ` Nodes n ll\"\n                  from rnort_in_repNodes repbNodes_in_Nodes \n                  have rnort_in_Nodes: \"set_of rnort \\<subseteq> Nodes n ll\"\n                    by simp\n                  from lnort_in_repNodes repbNodes_in_Nodes \n                  have lnort_in_Nodes: \"set_of lnort \\<subseteq> Nodes n ll\"\n                    by simp\n                  from rnort_in_Nodes \n                  have rnortx_in_Nodes: \"\\<forall> x \\<in> set_of rnort. x \\<in> Nodes n ll\"\n                    by blast\n                  with wf_ll nsll  \n                  have \"\\<forall> x \\<in> set_of rnort. x \\<in> set_of pret \\<and> var x < n\"\n                    apply -\n                    apply (rule ballI)\n                    apply (rule wf_ll_Nodes_pret)\n                    apply (auto simp add: length_ll_eq)\n                    done\n                  with pret_dag prebdt_pret rnort_dag ord_pret wf_ll  nsll \n                    repbc_nc \n                  have \"\\<forall>x \\<in> set_of rnort. (repc \\<propto> low) x = (repb \\<propto> low) x \\<and> \n                    (repc \\<propto> high) x = (repb \\<propto> high) x\"\n                    apply -\n                    apply (rule nort_null_comp)\n                    apply (auto simp add: length_ll_eq)\n                    done\n                  then have \"Dag (repc (high no)) (repc \\<propto> low) (repc \\<propto> high) rnort = \n                    Dag (repc (high no)) (repb \\<propto> low) (repb \\<propto> high) rnort\" \n                    apply -\n                    apply (rule heaps_eq_Dag_eq)\n                    apply assumption\n                    done\n                  with rnort_dag \n                  have rnort_dag_repc: \n                    \"Dag (repc (high no)) (repc \\<propto> low) (repc \\<propto> high) rnort\" \n                    by simp\n                  from lnort_in_Nodes \n                  have lnortx_in_Nodes: \"\\<forall>x \\<in> set_of lnort. x \\<in> Nodes n ll\"\n                    by blast\n                  with wf_ll nsll  \n                  have \"\\<forall> x \\<in> set_of lnort. x \\<in> set_of pret \\<and> var x < n\"\n                    apply -\n                    apply (rule ballI)\n                    apply (rule wf_ll_Nodes_pret)\n                    apply (auto simp add: length_ll_eq)\n                    done\n                  with pret_dag prebdt_pret lnort_dag ord_pret wf_ll  nsll \n                    repbc_nc \n                  have \"\\<forall> x \\<in> set_of lnort. (repc \\<propto> low) x = (repb \\<propto> low) x \\<and> \n                    (repc \\<propto> high) x = (repb \\<propto> high) x\"\n                    apply -\n                    apply (rule nort_null_comp)\n                    apply (auto simp add: length_ll_eq)\n                    done\n                  then have \n                    \"Dag (repc (low no)) (repc \\<propto> low) (repc \\<propto> high) lnort = \n                    Dag (repc (low no)) (repb \\<propto> low) (repb \\<propto> high) lnort\" \n                    apply -\n                    apply (rule heaps_eq_Dag_eq)\n                    apply assumption\n                    done\n                  with lnort_dag \n                  have lnort_dag_repc: \n                    \"Dag (repc (low no)) (repc \\<propto> low) (repc \\<propto> high) lnort\" \n                    by simp\n                  from lno_nNull hno_nNull   \n                  have propto_comp: \"(repc \\<propto> low) no = repc (low no) \\<and> \n                    (repc \\<propto> high) no = repc (high no)\" \n                    by (simp add: null_comp_def)\n                  from rno_in_llbn twonodes_in_llbn_prop rrno_eq_rno \n                  have \"(repc \\<propto> high) (repc no) = (repc \\<propto> high) no \\<and> \n                    (repc \\<propto> low) (repc no) = (repc \\<propto> low) no\"\n                    by simp\n                  with propto_comp lnort_dag_repc rnort_dag_repc lno_nNull hno_nNull \n                    rnonN   \n                  show \"Dag(repc no)(repc \\<propto> low)(repc \\<propto> high)(Node lnort (repc no) rnort)\"\n                    by auto\n                next\n                  fix rnot lnot rnort lnort\n                  assume rnot_dag: \"Dag (high no) low high rnot\"\n                  assume lnot_dag: \"Dag (low no) low high lnot\"\n                  with rnot_dag nonNull   \n                  show \"Dag no low high (Node lnot no rnot)\" \n                    by simp\n                next\n                  fix rnort lnort\n                  assume rnort_dag: \n                    \"Dag (repc (high no)) (repb \\<propto> low) (repb \\<propto> high) rnort\"\n                  assume lnort_dag: \n                    \"Dag (repc (low no)) (repb \\<propto> low) (repb \\<propto> high) lnort\"\n                  assume red_rnort: \"reduced rnort\"\n                  assume red_lnort: \" reduced lnort\"\n                  from rhn_nNull rnort_dag obtain lrnort rrnort where \n                    rnort_Node: \"rnort = (Node lrnort (repc (high no)) rrnort)\"\n                    by auto\n                  from rln_nNull lnort_dag obtain llnort rlnort where \n                    lnort_Node: \"lnort = (Node llnort (repc (low no)) rlnort)\"\n                    by auto\n                  from twonodes_in_llbn_prop rrno_eq_rno rno_in_llbn hno_nNull lno_nNull \n                  have \"((repc \\<propto> high) (repc no)) = repc (high no) \\<and> \n                    ((repc \\<propto> low) (repc no)) = repc (low no)\"\n                    apply -\n                    apply (erule_tac x=\"repc no\" in ballE)\n                    apply (auto simp add: null_comp_def)\n                    done\n                  with share_case_cond \n                  have \"((repc \\<propto> high) (repc no)) \\<noteq> ((repc \\<propto> low) (repc no))\"\n                    by auto\n                  with red_lnort red_rnort rnort_Node lnort_Node share_case_cond \n                  show \"reduced (Node lnort (repc no) rnort)\"\n                    apply -\n                    apply (rule_tac lp=\"repc (low no)\" and rp=\"repc (high no)\" and \n                      llt=llnort and rlt = rlnort and lrt=lrnort and rrt=rrnort \n                      in reduced_children_parent)\n                    apply auto\n                    done\n                next\n                  fix lnort rnort\n                  assume lnort_dag: \n                    \"Dag (repc (low no)) (repb \\<propto> low) (repb \\<propto> high) lnort\"\n                  assume ord_lnort: \"ordered lnort var\"\n                  assume rnort_dag: \n                    \"Dag (repc (high no)) (repb \\<propto> low) (repb \\<propto> high) rnort\"\n                  assume ord_rnort: \" ordered rnort var\"\n                  assume lnort_in_repNodes: \"set_of lnort \\<subseteq> repb `Nodes n ll\"\n                  assume rnort_in_repNodes: \"set_of rnort \\<subseteq> repb `Nodes n ll\"\n                  from lnort_in_repNodes repbNodes_in_Nodes \n                  have lnort_in_Nodes: \"set_of lnort \\<subseteq> Nodes n ll\"\n                    by simp\n                  from rnort_in_repNodes repbNodes_in_Nodes \n                  have rnort_in_Nodes: \"set_of rnort \\<subseteq> Nodes n ll\"\n                    by simp\n\n                  from rhn_nNull rnort_dag obtain lrnort rrnort where \n                    rnort_Node: \"rnort = (Node lrnort (repc (high no)) rrnort)\"\n                    by auto\n                  from rln_nNull lnort_dag obtain llnort rlnort where \n                    lnort_Node: \"lnort = (Node llnort (repc (low no)) rlnort)\"\n                    by auto\n                  from lnort_dag rln_nNull lnort_in_Nodes \n                  have \"repc (low no) \\<in> set_of lnort\" \n                    by auto\n                  with lnort_in_Nodes \n                  have \"repc (low no) \\<in> Nodes n ll\"\n                    by blast\n                  with wf_ll nsll  \n                  have vrlno_sn: \"var (repc (low no)) < n\"\n                    apply -\n                    apply (drule wf_ll_Nodes_pret)\n                    apply (auto simp add: length_ll_eq)\n                    done\n                  from rnort_dag rhn_nNull rnort_in_Nodes \n                  have \"repc (high no) \\<in> set_of rnort\" \n                    by auto\n                  with rnort_in_Nodes \n                  have \"repc (high no) \\<in> Nodes n ll\"\n                    by blast\n                  with wf_ll nsll  have vrhno_sn: \"var (repc (high no)) < n\"\n                    apply -\n                    apply (drule wf_ll_Nodes_pret)\n                    apply (auto simp add: length_ll_eq)\n                    done\n                  with varrepno_n vrlno_sn lnort_dag ord_lnort rnort_dag rnort_Node \n                    lnort_Node ord_rnort \n                  show \"ordered (Node lnort (repc no) rnort) var\"\n                    by auto\n                next\n                  fix lnort rnort\n                  assume lnort_in_Nodes: \"set_of lnort \\<subseteq> repb `Nodes n ll\"\n                  assume rnort_in_Nodes: \"set_of rnort \\<subseteq> repb `Nodes n ll\"\n                  from lnort_in_Nodes repbNodes_repcNodes \n                  have lnort_in_repcNodes: \"set_of lnort \\<subseteq> repc `Nodes n ll\"\n                    by simp\n                  from rnort_in_Nodes repbNodes_repcNodes \n                  have rnort_in_repcNodes: \"set_of rnort \\<subseteq> repc `Nodes n ll\"\n                    by simp\n                  have nNodessubset: \"Nodes n ll \\<subseteq> Nodes (n+1) ll\"\n                    by (simp add: Nodes_subset)\n                  then have repc_Nodes_subset:\n                    \"repc `Nodes n ll \\<subseteq> repc `Nodes (n+1) ll\"\n                    by blast\n                  from no_in_Nodes have \"repc no \\<in> repc `Nodes (n+1) ll\"\n                    by blast\n                  with repc_Nodes_subset lnort_in_repcNodes rnort_in_repcNodes \n                  show \"set_of (Node lnort (repc no) rnort) \\<subseteq> \n                    repc `Nodes (n + 1) ll\"\n                    apply simp\n                    apply blast\n                    done\n                next\n                  fix rnot lnot rnort lnort rnobdt lnobdt rnorbdt lnorbdt\n                  assume lnobdt_def: \" bdt lnot var = Some lnobdt\"\n                  assume rnobdt_def: \" bdt rnot var = Some rnobdt\"\n                  assume rnorbdt_def: \" bdt rnort var = Some rnorbdt\"\n                  assume cong_rno_rnor: \" rnobdt \\<sim> rnorbdt\"\n                  assume lnot_dag: \"Dag (low no) low high lnot\"\n                  assume rnot_dag: \"Dag (high no) low high rnot\"\n                  assume \"\\<not> Suc 0 < var no\"\n                  then have varnoseq1: \"var no = 0 \\<or> var no = 1\" by auto\n                  show \"\\<exists>nobdt. bdt (Node lnot no rnot) var = Some nobdt \\<and> \n                    (\\<exists>norbdt. bdt (Node lnort (repc no) rnort) var = Some norbdt \\<and> \n                    nobdt \\<sim> norbdt)\"\n                  proof (cases \"var no = 0\")\n                    case True\n                    note vnoNull=this\n                    with pret_dag ord_pret no_in_pret lno_nNull hno_nNull  \n                    show ?thesis\n                      apply -\n                      apply (drule var_ordered_children)\n                      apply auto\n                      done\n                  next\n                    assume \"var no \\<noteq> 0\"\n                    with varnoseq1 have vnoOne: \"var no = 1\" by simp\n                    from pret_dag  ord_pret no_in_pret lno_nNull hno_nNull  \n                      vnoOne \n                    have vlvrNull: \"var (low no) = 0 \\<and> var (high no) = 0\"\n                      apply -\n                      apply (drule var_ordered_children)\n                      apply auto\n                      done\n                    then have vlNull: \"var (low no) = 0\" by simp\n                    from vlvrNull have vrNull: \"var (high no) = 0\" by simp\n                    from lnobdt_def lnot_dag vlNull  lno_nNull \n                    have lnobdt_Zero: \"lnobdt = Zero\"\n                      apply -\n                      apply (drule bdt_Some_var0_Zero)\n                      apply auto\n                      done\n                    from rnobdt_def rnot_dag vrNull  hno_nNull \n                    have rnobdt_Zero: \"rnobdt = Zero\"\n                      apply -\n                      apply (drule bdt_Some_var0_Zero)\n                      apply auto\n                      done\n                    from lnobdt_Zero lnobdt_def \n                    have \"bdt lnot var = Some Zero\" by simp\n                    with lnot_dag vlNull  \n                    have lnot_Node: \"lnot = (Node Tip (low no) Tip)\"\n                      by auto\n                    from rnobdt_Zero rnobdt_def rnot_dag vrNull  \n                    have rnot_Node: \"rnot = (Node Tip (high no) Tip)\" \n                      by auto\n                    from pret_dag no_in_pret obtain not \n                      where not_ex: \"Dag no low high not\"\n                      apply -\n                      apply (drule dag_setof_exD)\n                      apply auto\n                      done\n                    with pret_dag no_in_pret have not_ex_in_pret: \"not <= pret\" \n                      apply -\n                      apply (rule set_of_subdag)\n                      apply auto\n                      done\n                    from not_ex lnot_dag rnot_dag   nonNull \n                    have not_def: \"not = (Node lnot no rnot)\" \n                      by (simp add: Dag_unique del: Dag_Ref)\n                    with not_ex_in_pret prebdt_pret \n                    have nobdt_ex: \"\\<exists> nobdt. bdt (Node lnot no rnot) var = Some nobdt\"\n                      apply -\n                      apply (rule subbdt_ex)\n                      apply auto\n                      done\n                    then obtain nobdt where \n                      nobdt_def: \"bdt (Node lnot no rnot) var = Some nobdt\" by auto\n                    from not_def have \"root not = no\" by simp\n                    with nobdt_def vnoOne not_def \n                    have \"not = (Node Tip no Tip)\"\n                      apply -\n                      apply (drule bdt_Some_var1_One)\n                      apply auto\n                      done\n                    with not_def have \"rnot = Tip\" by simp\n                    with rnot_Node show ?thesis by simp\n                  qed\n                next\n                  fix lnot rnot lnobdt rnobdt\n                  assume lnot_dag: \"Dag (low no) low high lnot\"\n                  assume rnot_dag: \" Dag (high no) low high rnot\"\n                  assume lnobdt_def: \" bdt lnot var = Some lnobdt\"\n                  assume rnobdt_def: \" bdt rnot var = Some rnobdt\"\n                  assume onesvarno: \" Suc 0 < var no\"\n                  with rnobdt_def lnot_dag rnot_dag lnobdt_def \n                  show \"bdt (Node lnot no rnot) var = \n                    Some (Bdt_Node lnobdt (var no) rnobdt)\" by simp\n                next\n                  fix rnot lnot rnort lnort rnobdt lnobdt rnorbdt lnorbdt\n                  assume rnort_dag: \n                    \"Dag (repc (high no)) (repb \\<propto> low) (repb \\<propto> high) rnort\"\n                  assume lnort_dag: \n                    \"Dag (repc (low no)) (repb \\<propto> low) (repb \\<propto> high) lnort\"\n                  assume rnorbdt_def: \" bdt rnort var = Some rnorbdt\"\n                  assume lnorbdt_def: \"bdt lnort var = Some lnorbdt\"\n                  assume varno_bOne: \"Suc 0 < var no\"\n                  with varno have \"Suc 0 < n\" by simp\n                  with varrepno_n have \"Suc 0 < var (repc no)\" by simp\n                  with rnorbdt_def lnorbdt_def \n                  show \"bdt (Node lnort (repc no) rnort) var = \n                    Some (Bdt_Node lnorbdt (var (repc no)) rnorbdt)\"\n                    by simp\n                next\n                  fix rnobdt lnobdt rnorbdt lnorbdt \n                  assume lcong_eval: \"lnobdt \\<sim> lnorbdt\"\n                  assume rcong_eval: \" rnobdt \\<sim> rnorbdt\"\n                  from varno varrepno_n have \"var (repc no) = var no\" by simp\n                  with lcong_eval rcong_eval \n                  show \"Bdt_Node lnobdt (var no) rnobdt \\<sim> \n                    Bdt_Node lnorbdt (var (repc no)) rnorbdt\"\n                    apply (unfold cong_eval_def)\n                    apply (rule ext)\n                    by simp\n                next\n                  fix rnot lnot rnort lnort\n                  assume lnort_repb: \"\\<forall>no\\<in>set_of lnort. repb no = no\"\n                  assume rnort_repb: \"\\<forall>no\\<in>set_of rnort. repb no = no\"\n                  assume rnort_in_repb_Nodesn: \"set_of rnort \\<subseteq> repb ` Nodes n ll\"\n                  assume lnort_in_repb_Nodesn: \"set_of lnort \\<subseteq> repb ` Nodes n ll\"\n                  from repbNodes_in_Nodes rnort_in_repb_Nodesn \n                  have rnort_in_Nodesn: \"set_of rnort \\<subseteq> Nodes n ll\"\n                    by blast\n                  from repbNodes_in_Nodes lnort_in_repb_Nodesn \n                  have lnort_in_Nodesn: \"set_of lnort \\<subseteq> Nodes n ll\"\n                    by blast\n                  have rnort_repc: \"\\<forall>no\\<in>set_of rnort. repc no = no\"\n                  proof\n                    fix pt\n                    assume pt_in_rnort: \" pt \\<in> set_of rnort\"\n                    with rnort_in_Nodesn have \"pt \\<in> Nodes n ll\" \n                      by blast\n                    with Nodesn_notin_lln have \"pt \\<notin> set (ll ! n)\"\n                      by auto\n                    with repbc_nc have \"repb pt = repc pt\"\n                      by auto\n                    with rnort_repb pt_in_rnort show \"repc pt = pt\"\n                      by auto\n                  qed\n                  have lnort_repc: \"\\<forall>no\\<in>set_of lnort. repc no = no\"\n                  proof\n                    fix pt\n                    assume pt_in_lnort: \" pt \\<in> set_of lnort\"\n                    with lnort_in_Nodesn have \"pt \\<in> Nodes n ll\" \n                      by blast\n                    with Nodesn_notin_lln have \"pt \\<notin> set (ll ! n)\"\n                      by auto\n                    with repbc_nc have \"repb pt = repc pt\"\n                      by auto\n                    with lnort_repb pt_in_lnort show \"repc pt = pt\"\n                      by auto\n                  qed\n                  show \"\\<forall>no\\<in>set_of (Node lnort (repc no) rnort). repc no = no\"\n                  proof\n                    fix pt\n                    assume pt_in_rept: \"pt \\<in> set_of (Node lnort (repc no) rnort)\"\n                    show \"repc pt = pt\"\n                    proof (cases \"pt \\<in> set_of lnort\")\n                      case True\n                      with lnort_repc show ?thesis\n                        by auto\n                    next\n                      assume pt_notin_lnort: \"pt \\<notin> set_of lnort\"\n                      show ?thesis\n                      proof (cases \"pt \\<in> set_of rnort\")\n                        case True\n                        with rnort_repc show ?thesis\n                          by auto\n                      next \n                        assume pt_notin_rnort: \"pt \\<notin> set_of rnort\"\n                        with pt_notin_lnort pt_in_rept have \"pt = repc no\"\n                          by simp\n                        with rrno_eq_rno show \"repc pt = pt\"\n                          by simp\n                      qed\n                    qed\n                  qed\n                qed\n                \n                with varrep rrno_eq_rno show ?thesis by simp\n              qed\n            qed\n            with rnonN show ?thesis by simp\n          qed\n        qed\n        note while_while_prop=this\n        from wf_ll nsll  \n        have \"\\<forall>no \\<in> Nodes n ll. no \\<notin> set (ll ! n)\"\n          apply (simp add: Nodes_def length_ll_eq)\n          apply clarify\n          apply (drule no_in_one_ll)\n          apply auto\n          done\n        with repbc_nc  have \"\\<forall>no \\<in> Nodes n ll. repb no = repc no\"\n          apply -\n          apply (rule ballI)\n          apply (erule_tac x=no in allE)\n          apply simp\n          done\n        then have repbNodes_repcNodes: \n          \"repb `(Nodes n ll) = repc `(Nodes n ll)\"\n          apply -\n          apply rule\n          apply blast\n          apply rule\n          apply (erule imageE)\n          apply (erule_tac x=xa in ballE)\n          prefer 2\n          apply simp\n          apply rule\n          apply auto\n          done\n        then have repcNodes_repbNodes: \n          \"repc `(Nodes n ll) = repb `(Nodes n ll)\"\n          by simp\n        have repbc_dags_eq: \n          \"Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high) = \n          Dags (repb  ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high)\"\n          apply -\n          apply rule\n          apply rule\n          apply (erule Dags.cases)\n          apply (rule DagsI)\n          prefer 4\n          apply rule\n          apply (erule Dags.cases)\n          apply (rule DagsI)\n        proof -\n          fix x p t\n          assume t_in_repcNodes: \"set_of t \\<subseteq> repc ` Nodes n ll\"\n          assume x_t: \"x=t\"\n          with t_in_repcNodes repcNodes_repbNodes \n          show \"set_of x \\<subseteq> repb ` Nodes n ll\" \n            by simp\n        next\n          fix x p t\n          assume t_in_repcNodes: \"set_of t \\<subseteq> repc ` Nodes n ll\"\n          assume t_dag: \"Dag p (repc \\<propto> low) (repc \\<propto> high) t\"\n          assume t_nTip: \" t \\<noteq> Tip\"\n          assume x_t: \"x=t\"\n          from t_nTip t_dag have \"p \\<noteq> Null\"\n            apply -\n            apply (case_tac \"p=Null\")\n            apply auto\n            done\n          with t_nTip t_dag obtain lt rt where t_Node: \"t=Node lt p rt\"\n            by auto\n          from t_in_repcNodes t_dag t_nTip t_Node obtain q where \n            rq_p: \"repc q = p\" and q_in_Nodes: \"q \\<in> Nodes n ll\"\n            apply simp\n            apply (elim conjE)\n            apply (erule imageE)\n            apply auto\n            done\n          from q_in_Nodes have \"repb q = repc q\"\n            by (rule Nodes_n_rep_nc [rule_format])\n          with rq_p have repbq_p: \"repb q = p\" by simp\n          from q_in_Nodes \n          have \"Dag (repb q) (repb \\<propto> low) (repb \\<propto> high) t = \n            Dag (repc q) (repc \\<propto> low) (repc \\<propto> high) t\"\n            by (rule Nodes_repbc_Dags_eq [rule_format])\n          with t_dag rq_p have \"Dag (repb q) (repb \\<propto> low) (repb \\<propto> high) t\" by simp\n          with repbq_p x_t show \"Dag p (repb \\<propto> low) (repb \\<propto> high) x\"\n            by simp\n        next\n          fix x p t\n          assume t_in_repcNodes: \"set_of t \\<subseteq> repb ` Nodes n ll\"\n          assume x_t: \"x=t\"\n          with t_in_repcNodes repbNodes_repcNodes \n          show \"set_of x \\<subseteq> repc ` Nodes n ll\" \n            by simp\n        next\n          fix x p t\n          assume t_in_repcNodes: \"set_of t \\<subseteq> repb ` Nodes n ll\"\n          assume t_dag: \"Dag p (repb \\<propto> low) (repb \\<propto> high) t\"\n          assume t_nTip: \" t \\<noteq> Tip\"\n          assume x_t: \"x=t\"\n          from t_nTip t_dag have \"p \\<noteq> Null\"\n            apply -\n            apply (case_tac \"p=Null\")\n            apply auto\n            done\n          with t_nTip t_dag obtain lt rt where t_Node: \"t=Node lt p rt\"\n            by auto\n          from t_in_repcNodes t_dag t_nTip t_Node obtain q where \n            rq_p: \"repb q = p\" and q_in_Nodes: \"q \\<in> Nodes n ll\"\n            apply simp\n            apply (elim conjE)\n            apply (erule imageE)\n            apply auto\n            done\n          from q_in_Nodes have \"repb q = repc q\"\n            by (rule Nodes_n_rep_nc [rule_format])\n          with rq_p have repbq_p: \"repc q = p\" by simp\n          from q_in_Nodes \n          have \"Dag (repb q) (repb \\<propto> low) (repb \\<propto> high) t = \n            Dag (repc q) (repc \\<propto> low) (repc \\<propto> high) t\"\n            by (rule Nodes_repbc_Dags_eq [rule_format])\n          with t_dag rq_p have \"Dag (repc q) (repc \\<propto> low) (repc \\<propto> high) t\" by simp\n          with repbq_p x_t show \"Dag p (repc \\<propto> low) (repc \\<propto> high) x\"\n            by simp\n        next\n          fix x p and t :: \"dag\"\n          assume x_t: \"x = t\"\n          assume t_nTip: \" t \\<noteq> Tip\"\n          with x_t show \"x\\<noteq> Tip\" by simp\n        next\n          fix x p and t :: \"dag\"\n          assume x_t: \"x = t\"\n          assume t_nTip: \" t \\<noteq> Tip\"\n          with x_t show \"x\\<noteq> Tip\" by simp\n        qed\n        from pret_dag wf_ll nsll \n        have null_notin_Nodes_Suc_n: \"Null \\<notin> Nodes (Suc n) ll\"\n          by  - (rule Null_notin_Nodes,auto simp add: length_ll_eq)\n        { fix t1 t2\n          assume t1_in_DagsNodesn: \n            \"t1 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume t2_notin_DagsNodesn: \n            \"t2 \\<notin> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume t2_in_DagsNodesSucn: \n            \"t2 \\<in> Dags (repc ` Nodes (Suc n) ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume isomorphic_dags_eq_asm: \n            \"\\<forall>t1 t2. t1 \\<in> Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high) \n            \\<and> t2 \\<in> Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high) \n            \\<longrightarrow> isomorphic_dags_eq t1 t2 var\"\n          assume repbc_Dags: \n            \"Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high) = \n            Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high)\"\n          from t1_in_DagsNodesn repbc_Dags \n          have t1_repb_subnode: \n            \"t1 \\<in> Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high)\" \n            by simp\n          from t2_in_DagsNodesSucn \n          have t2_in_DagsNodesSucn: \n            \"t2 \\<in> Dags (repc ` Nodes (Suc n) ll) (repc \\<propto> low) (repc \\<propto> high)\" \n            by simp\n          from repbNodes_in_Nodes repbNodes_repcNodes \n          have repcNodesn_in_Nodesn: \"repc `Nodes n ll \\<subseteq> Nodes n ll\"\n            by simp\n          from t1_in_DagsNodesn obtain q where \n            Dag_q_Nodes_n: \n            \"Dag (repc q) (repc \\<propto> low) (repc \\<propto> high) t1 \\<and> q \\<in> Nodes n ll\"\n          proof (elim Dags.cases)\n            fix p t\n            assume t1_t: \"t1 = t\"\n            assume t_in_repcNodesn: \"set_of t \\<subseteq> repc ` Nodes n ll\"\n            assume t_dag: \"Dag p (repc \\<propto> low) (repc \\<propto> high) t\"\n            assume t_nTip: \" t \\<noteq> Tip\"\n            assume obtain_prop: \"\\<And>q. Dag (repc q) (repc \\<propto> low) (repc \\<propto> high) t1 \\<and> \n              q \\<in> Nodes n ll \\<Longrightarrow> ?thesis\"\n            from t_nTip t_dag have \"p \\<noteq> Null\"\n              apply -\n              apply (case_tac \"p=Null\")\n              apply auto\n              done\n            with t_nTip t_dag obtain lt rt where t_Node: \"t=Node lt p rt\"\n              by auto\n            from t_in_repcNodesn t_dag t_nTip t_Node obtain k where \n              rk_p: \"repc k = p\" and k_in_Nodes: \"k \\<in> Nodes n ll\"\n              apply simp\n              apply (elim conjE)\n              apply (erule imageE)\n              apply auto\n              done\n            with t1_t t_dag obtain_prop rk_p k_in_Nodes show ?thesis\n              by auto\n          qed\n          with wf_ll  nsll  have varq_sn: \"(var q < n)\"         \n            apply (simp add: Nodes_def)\n            apply (elim conjE)\n            apply (erule exE)\n            apply (simp add: wf_ll_def length_ll_eq)\n            apply (elim conjE)\n            apply (thin_tac \" \\<forall>q. q \\<in> set_of pret \\<longrightarrow> q \\<in> set (ll ! var q)\")\n            apply (erule_tac x=x in allE)\n            apply auto\n            done\n          from Dag_q_Nodes_n have q_in_Nodesn: \"q \\<in> Nodes n ll\"\n            by simp\n          then have \"\\<exists> k<n. q \\<in> set (ll ! k)\"\n            by (simp add: Nodes_def)\n          with wf_ll nsll  have \"q \\<notin> set (ll ! n)\"\n            apply -\n            apply (erule exE)\n            apply (rule_tac i=k and j=n in no_in_one_ll)\n            apply (auto simp add: length_ll_eq)\n            done\n          with repbc_nc  have repbc_q: \"repc q = repb q\"\n            apply -\n            apply (erule_tac x=q in allE)\n            apply auto\n            done\n          from normalize_prop q_in_Nodesn have \"var (repb q) <= var q\"\n            apply -\n            apply (erule_tac x=q in ballE)\n            apply auto\n            done\n          with repbc_q have var_repc_q: \"var (repc q) <= var q\"\n            by simp\n          with varq_sn have var_repc_q_n: \"var (repc q) < n\"\n            by simp\n          \n          from Nodes_subset Dag_q_Nodes_n while_while_prop \n          have ord_t1_var_rep: \"ordered t1 var \\<and> var (repc q) <= var q\" \n            apply (elim conjE)\n            apply (erule_tac x=q in ballE)\n            apply auto\n            done\n          then have ord_t1: \"ordered t1 var\" by simp\n          from ord_t1_var_rep have varrep_q: \"var (repc q) <= var q\" by simp\n          from t2_in_DagsNodesSucn have ord_t2: \"ordered t2 var\"\n          proof (elim Dags.cases)\n            fix p t\n            assume t_in_repcNodes: \"set_of t \\<subseteq> repc ` Nodes (Suc n) ll\"\n            assume t_nTip: \" t \\<noteq> Tip\"\n            assume t2t: \"t2 = t\"\n            assume t_dag: \"Dag p (repc \\<propto> low) (repc \\<propto> high) t\"\n            from t_in_repcNodes have x_in_repcNodesSucn:  \n              \"\\<forall>x. x \\<in> set_of t \\<longrightarrow> x \\<in> repc ` Nodes (Suc n) ll\" \n              apply -\n              apply auto\n              done\n            from t_nTip t_dag have \"p \\<noteq> Null\"\n              apply -\n              apply (case_tac \"p=Null\")\n              apply auto\n              done\n            with t_nTip t_dag obtain lt rt where t_Node: \"t=Node lt p rt\"\n              by auto\n            then have \"p \\<in> set_of t\"\n              by auto\n            with x_in_repcNodesSucn have \"p \\<in> repc ` Nodes (Suc n) ll\"\n              by simp\n            then obtain a where repca_p: \"p=repc a\" and \n              a_in_NodesSucn: \"a \\<in> Nodes (Suc n) ll\"\n              by auto\n            with repca_p while_while_prop t_dag t2t show ?thesis\n              apply -\n              apply (erule_tac x=a in ballE)\n              apply (elim conjE exE)\n              apply (subgoal_tac \"nort = t\") \n              prefer 2\n              apply (simp add: Dag_unique)\n              apply auto\n              done\n          qed\n          from while_while_prop have while_prop_part: \n            \"\\<forall>no \\<in> Nodes (Suc n) ll. \n            var (repc no) <= var no\"\n            by auto\n          from while_while_prop have rep_rep_nort: \n            \"\\<forall>no\\<in>Nodes (n + 1) ll. (\\<exists>nort. Dag (repc no) (repc \\<propto> low) (repc \\<propto> high) nort \\<and> \n            (\\<forall>no\\<in>set_of nort. repc no = no))\"\n            by auto\n          from repcNodes_in_Nodes null_notin_Nodes_Suc_n \n          have \"\\<forall>no \\<in> Nodes (n+1) ll. repc no \\<noteq> Null\"\n            by auto\n          with rep_rep_nort have \"\\<forall> no \\<in> Nodes (n+1) ll. repc (repc no) = (repc no)\"\n            apply -\n            apply (rule ballI)\n            apply (erule_tac x=no in ballE)\n            prefer 2\n            apply simp\n            apply (erule_tac x=no in ballE)\n            apply (erule exE)\n            apply (subgoal_tac \"repc no \\<in> set_of nort\")\n            apply (elim conjE)\n            apply (erule_tac x=\"repc no\" in ballE)\n            apply simp\n            apply simp\n            apply (simp)\n            apply (elim conjE)\n            apply (thin_tac \"\\<forall>no\\<in>set_of nort. repc no = no\")\n            apply auto\n            done\n          with t2_in_DagsNodesSucn t2_notin_DagsNodesn ord_t2 while_prop_part \n            wf_ll nsll  repcNodes_in_Nodes obtain a where\n            t2_repc_dag: \"Dag (repc a) (repc \\<propto> low) (repc \\<propto> high) t2\" and\n            a_in_lln: \"a \\<in> set (ll ! n)\"\n            apply -\n            apply (drule restrict_root_Node)\n            apply (auto simp add: length_ll_eq)\n            done\n          with wf_ll nsll  have a_in_pret: \"a \\<in> set_of pret\" \n            by (simp add: wf_ll_def length_ll_eq)\n          from wf_ll nsll  a_in_lln have vara_n: \"var a = n\" \n            by (simp add: wf_ll_def length_ll_eq)\n          from a_in_lln rep_prop  obtain\n            repp_nNull: \" repc a \\<noteq> Null\" and\n            repp_reduce: \"(repc \\<propto> low) a = (repc \\<propto> high) a \\<and> low a \\<noteq> Null \n            \\<longrightarrow> repc a = (repc \\<propto> high) a\" and\n            repp_share: \"((repc \\<propto> low) a = (repc \\<propto> high) a \\<longrightarrow> low a = Null) \n            \\<longrightarrow> repc a \\<in> set (ll ! n) \\<and>\n            repc (repc a) = repc a \\<and> \n            (\\<forall>no1\\<in>set (ll ! n). ((repc \\<propto> high) no1 = (repc \\<propto> high) a \\<and> \n            (repc \\<propto> low) no1 = (repc \\<propto> low) a) = (repc a = repc no1))\"\n            using [[simp_depth_limit=4]]\n            by auto\n          from t2_repc_dag a_in_lln repp_nNull obtain lt2 rt2 where \n            t2_Node: \"t2 = (Node lt2 (repc a) rt2)\"\n            by auto\n          have \"isomorphic_dags_eq t1 t2 var\"\n          proof (cases \"(repc \\<propto> low) a = (repc \\<propto> high) a \\<and> low a \\<noteq> Null\")\n            case True\n            note red=this\n            then have red_case: \"(repc \\<propto> low) a = (repc \\<propto> high) a\"\n              by simp\n            from red have low_nNull: \"low a \\<noteq> Null\"\n              by simp\n            with pret_dag prebdt_pret a_in_pret have highp_nNull: \"high a \\<noteq> Null\" \n              apply -\n              apply (drule balanced_bdt)\n              apply auto\n              done\n            from pret_dag ord_pret a_in_pret low_nNull highp_nNull \n            have var_children_smaller: \"var (low a) < var a \\<and> var (high a) < var a\"\n              apply -\n              apply (rule var_ordered_children)\n              apply auto\n              done\n            from pret_dag a_in_pret have a_nNull: \"a \\<noteq> Null\" \n              apply -\n              apply (rule set_of_nn [rule_format])\n              apply auto\n              done\n            with a_in_pret highp_nNull pret_dag have \"high a \\<in> set_of pret\" \n              apply -\n              apply (drule subelem_set_of_high)\n              apply auto\n              done\n            with wf_ll have \"high a \\<in> set (ll ! (var (high a)))\" \n              by (simp add: wf_ll_def)\n            with a_in_lln t2_repc_dag var_children_smaller vara_n \n            have \"\\<exists> k<n. (high a) \\<in> set (ll ! k)\"\n              by auto\n            then have higha_in_Nodesn: \"(high a) \\<in> Nodes n ll\"\n              by (simp add: Nodes_def)\n            then have rhigha_in_rNodesn: \"repc (high a) \\<in> repc ` Nodes n ll\"\n              by simp\n            from higha_in_Nodesn normalize_prop obtain rt where \n              rt_dag:  \"Dag (repb (high a)) (repb \\<propto> low) (repb \\<propto> high) rt\" and\n              rt_in_repbNort: \"set_of rt \\<subseteq> repb `Nodes n ll\"\n              apply -\n              apply (erule_tac x=\"high a\" in ballE)\n              apply auto\n              done\n            from rt_in_repbNort repbNodes_repcNodes \n            have rt_in_repcNodesn: \"set_of rt \\<subseteq> repc `Nodes n ll\"\n              by blast\n            from rt_dag higha_in_Nodesn \n            have repcrt_dag: \"Dag (repc (high a)) (repc \\<propto> low) (repc \\<propto> high) rt\"\n              apply -\n              apply (drule Nodes_repbc_Dags_eq [rule_format])\n              apply auto\n              done\n            have rt_nTip: \"rt \\<noteq> Tip\"\n            proof -\n              have \"repc (high a) \\<noteq> Null\"\n              proof -\n                note rhigha_in_rNodesn\n                also have \"repc `Nodes n ll \\<subseteq> repc `Nodes (Suc n) ll\"\n                  using Nodes_subset \n                  by blast\n                also have \"\\<dots> \\<subseteq> Nodes (Suc n) ll\"\n                  using repcNodes_in_Nodes\n                  by simp\n                finally show ?thesis\n                  using null_notin_Nodes_Suc_n\n                  by auto\n              qed\n              with repcrt_dag show ?thesis by auto\n            qed\n            from a_nNull a_in_pret low_nNull pret_dag have \"low a \\<in> set_of pret\" \n              apply -\n              apply (drule subelem_set_of_low)\n              apply auto\n              done\n            with wf_ll have \"low a \\<in> set (ll ! (var (low a)))\" \n              by (simp add: wf_ll_def)\n            with a_in_lln t2_repc_dag var_children_smaller vara_n \n            have \"\\<exists>k<n. (low a) \\<in> set (ll ! k)\"\n              by auto\n            then have \"(low a) \\<in> Nodes n ll\"\n              by (simp add: Nodes_def)\n            then have rlow_in_rNodesn: \"repc (low a) \\<in> repc ` Nodes n ll\"\n              by simp\n            show ?thesis\n            proof -\n              from repp_reduce low_nNull  highp_nNull  red_case \n              have repc_p_def: \"repc a = repc (high a)\" \n                by (simp add: null_comp_def)\n              with rt_in_repcNodesn repcrt_dag rhigha_in_rNodesn a_in_lln t2_repc_dag\n                repc_p_def  rt_nTip \n              have t2_in_Dags_Nodesn: \n                \"t2 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n                apply -\n                apply (rule DagsI)\n                apply simp\n                apply (subgoal_tac \"t2=rt\")\n                apply (auto simp add: Dag_unique)\n                done\n              from t1_in_DagsNodesn t2_in_Dags_Nodesn repbc_dags_eq isomorphic_dags_eq_asm \n              show shared_t1_t2: \"isomorphic_dags_eq t1 t2 var\"\n                apply -\n                apply (erule_tac x=t1 in allE)\n                apply (erule_tac x=t2 in allE)\n                apply simp\n                done\n            qed\n          next\n            assume share: \" \\<not> ((repc \\<propto> low) a = (repc \\<propto> high) a \\<and> low a \\<noteq> Null)\"\n            then\n            have share: \"(repc \\<propto> low) a \\<noteq> (repc \\<propto> high) a \\<or> low a = Null\"\n              using [[simp_depth_limit=1]]\n              by simp\n            with repp_share obtain \n              ra_in_llbn: \"repc a \\<in> set (ll ! n)\" and \n              rra_ra: \"repc (repc a) = repc a\" and\n              two_nodes_share: \"(\\<forall>no1\\<in>set (ll ! n). \n              ((repc \\<propto> high) no1 = (repc \\<propto> high) a \\<and> \n              (repc \\<propto> low) no1 = (repc \\<propto> low) a) = (repc a = repc no1))\"\n              using [[simp_depth_limit=3]]\n              by simp\n            from wf_ll ra_in_llbn  nsll have var_repc_a_n: \"var (repc a) = n\" \n              by (auto simp add: wf_ll_def length_ll_eq)\n            show ?thesis\n            proof (auto simp add: isomorphic_dags_eq_def)\n              fix bdt1\n              assume bdt_t1: \"bdt t1 var = Some bdt1\"\n              assume bdt_t2: \"bdt t2 var = Some bdt1\"\n              show \"t1 = t2\"\n              proof (cases t1)\n                case Tip\n                with bdt_t1 show ?thesis\n                  by simp\n              next\n                case (Node lt1 p1 rt1)\n                note t1_Node=this\n                with Dag_q_Nodes_n have \"p1=(repc q)\"\n                  by simp\n                with t2_Node bdt_t1 bdt_t2 t1_Node have \"var (repc q) = var (repc a)\"\n                  apply -\n                  apply (rule same_bdt_var)\n                  apply auto\n                  done\n                with var_repc_q_n var_repc_a_n show ?thesis\n                  by simp\n              qed\n            qed\n          qed }\n        note mixed_Dags_case = this\n        from repbc_dags_eq isomorphic_dags_eq \n        have dags_shared: \n          \"\\<forall>t1 t2. t1 \\<in> Dags (repc ` Nodes (Suc n) ll)(repc \\<propto> low)(repc \\<propto> high)\\<and>\n          t2 \\<in> Dags (repc ` Nodes (Suc n) ll) (repc \\<propto> low) (repc \\<propto> high) \n          \\<longrightarrow> isomorphic_dags_eq t1 t2 var\"\n          apply -\n          apply (rule Dags_Nodes_cases)\n          apply (rule isomorphic_dags_eq_sym)\n        proof -\n          fix t1 t2\n          assume t1_in_Dagsn: \n            \"t1 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume t2_in_Dagsn: \n            \"t2 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume isomorphic_dags_eq_asm: \n            \"\\<forall>t1 t2. t1 \\<in> Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high) \\<and>\n            t2 \\<in> Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high) \n            \\<longrightarrow> isomorphic_dags_eq t1 t2 var\"\n          assume repb_repc_Dags: \n            \"Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high) = \n            Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high)\"\n          with t1_in_Dagsn t2_in_Dagsn isomorphic_dags_eq_asm \n          show \"isomorphic_dags_eq t1 t2 var\" by simp\n        next\n          fix t1 t2\n          assume t1_in_DagsNodesn: \n            \"t1 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume t2_notin_DagsNodesn: \n            \"t2 \\<notin> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume t2_in_DagsNodesSucn: \n            \"t2 \\<in> Dags (repc ` Nodes (Suc n) ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume isomorphic_dags_eq_asm: \n            \"\\<forall>t1 t2. t1 \\<in> Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high) \\<and>\n            t2 \\<in> Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high) \n            \\<longrightarrow> isomorphic_dags_eq t1 t2 var\"\n          assume repbc_Dags: \n            \"Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high) = \n            Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high)\"\n          from t1_in_DagsNodesn t2_notin_DagsNodesn t2_in_DagsNodesSucn \n            isomorphic_dags_eq_asm repbc_Dags\n          show \"isomorphic_dags_eq t1 t2 var\"\n            apply -\n            apply (rule mixed_Dags_case)\n            apply auto\n            done\n        next\n          fix t1 t2\n          assume t1_in_DagsNodesSucn: \n            \"t1 \\<in> Dags (repc ` Nodes (Suc n) ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume t1_notin_DagsNodesn: \n            \"t1 \\<notin> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume t2_in_DagsNodesSucn: \n            \"t2 \\<in> Dags (repc ` Nodes (Suc n) ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume t2_notin_DagsNodesn: \n            \"t2 \\<notin> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          \n          \n            (* ab hier gehts um t1 *)\n          from t1_in_DagsNodesSucn have ord_t1: \"ordered t1 var\"\n          proof (elim Dags.cases)\n            fix p t\n            assume t_in_repcNodes: \"set_of t \\<subseteq> repc ` Nodes (Suc n) ll\"\n            assume t_nTip: \" t \\<noteq> Tip\"\n            assume t2t: \"t1 = t\"\n            assume t_dag: \"Dag p (repc \\<propto> low) (repc \\<propto> high) t\"\n            from t_in_repcNodes \n            have x_in_repcNodesSucn:  \n              \"\\<forall> x. x \\<in> set_of t \\<longrightarrow> x \\<in> repc ` Nodes (Suc n) ll\" \n              apply -\n              apply auto\n              done\n            from t_nTip t_dag have \"p \\<noteq> Null\"\n              apply -\n              apply (case_tac \"p=Null\")\n              apply auto\n              done\n            with t_nTip t_dag obtain lt rt where t_Node: \"t=Node lt p rt\"\n              by auto\n            then have \"p \\<in> set_of t\"\n              by auto\n            with x_in_repcNodesSucn have \"p \\<in> repc ` Nodes (Suc n) ll\"\n              by simp\n            then obtain a where \n              repca_p: \"p=repc a\" and a_in_NodesSucn: \"a \\<in> Nodes (Suc n) ll\"\n              by auto\n            with repca_p while_while_prop t_dag t2t show ?thesis\n              apply -\n              apply (erule_tac x=a in ballE)\n              apply (elim conjE exE)\n              apply (subgoal_tac \"nort = t\") \n              prefer 2\n              apply (simp add: Dag_unique)\n              apply auto\n              done\n          qed\n          from while_while_prop \n          have while_prop_part: \"\\<forall>no \\<in> Nodes (Suc n) ll. \n            var (repc no) <= var no\"\n            by auto\n          from while_while_prop have rep_rep_nort: \n            \"\\<forall>no\\<in>Nodes (n + 1) ll. \n               (\\<exists>nort. Dag (repc no) (repc \\<propto> low) (repc \\<propto> high) nort \\<and> \n               (\\<forall>no\\<in>set_of nort. repc no = no))\"\n            by auto\n          from repcNodes_in_Nodes null_notin_Nodes_Suc_n \n          have \"\\<forall> no \\<in> Nodes (n+1) ll. repc no \\<noteq> Null\"\n            by auto\n          with rep_rep_nort \n          have rep_rep_no:  \"\\<forall>no \\<in> Nodes (n+1) ll. repc (repc no) = (repc no)\"\n            apply -\n            apply (rule ballI)\n            apply (erule_tac x=no in ballE)\n            prefer 2\n            apply simp\n            apply (erule_tac x=no in ballE)\n            apply (erule exE)\n            apply (subgoal_tac \"repc no \\<in> set_of nort\")\n            apply (elim conjE)\n            apply (erule_tac x=\"repc no\" in ballE)\n            apply simp\n            apply simp\n            apply (simp)\n            apply (elim conjE)\n            apply (thin_tac \"\\<forall>no\\<in>set_of nort. repc no = no\")\n            apply auto\n            done\n          with t1_in_DagsNodesSucn t1_notin_DagsNodesn ord_t1 while_prop_part wf_ll \n            nsll  repcNodes_in_Nodes obtain a1 where\n            t1_repc_dag: \"Dag (repc a1) (repc \\<propto> low) (repc \\<propto> high) t1\" and\n            a1_in_lln: \"a1 \\<in> set (ll ! n)\"\n            apply -\n            apply (drule restrict_root_Node)\n            apply (auto simp add: length_ll_eq)\n            done\n          with wf_ll nsll  have a1_in_pret: \"a1 \\<in> set_of pret\" \n            by (simp add: wf_ll_def length_ll_eq)\n          from wf_ll nsll  a1_in_lln have vara1_n: \"var a1 = n\" \n            by (simp add: wf_ll_def length_ll_eq)\n          from a1_in_lln rep_prop  obtain\n            repa1_nNull: \" repc a1 \\<noteq> Null\" and\n            repa1_reduce: \"(repc \\<propto> low) a1 = (repc \\<propto> high) a1 \\<and> low a1 \\<noteq> Null \n            \\<longrightarrow> repc a1 = (repc \\<propto> high) a1\" and\n            repa1_share: \"((repc \\<propto> low) a1 = (repc \\<propto> high) a1 \\<longrightarrow> low a1 = Null) \n            \\<longrightarrow> repc a1 \\<in> set (ll ! n) \\<and> repc (repc a1) = repc a1 \\<and> \n            (\\<forall>no1\\<in>set (ll ! n). ((repc \\<propto> high) no1 = (repc \\<propto> high) a1 \\<and> \n            (repc \\<propto> low) no1 = (repc \\<propto> low) a1) = (repc a1 = repc no1))\"\n            using [[simp_depth_limit=4]]\n            by auto\n          from t1_repc_dag a1_in_lln repa1_nNull obtain lt1 rt1 where \n            t1_Node: \"t1 = (Node lt1 (repc a1) rt1)\"\n            by auto\n\n\n\n              (* ab hier gehts um t2 *)\n          from t2_in_DagsNodesSucn have ord_t2: \"ordered t2 var\"\n          proof (elim Dags.cases)\n            fix p t\n            assume t_in_repcNodes: \"set_of t \\<subseteq> repc ` Nodes (Suc n) ll\"\n            assume t_nTip: \" t \\<noteq> Tip\"\n            assume t2t: \"t2 = t\"\n            assume t_dag: \"Dag p (repc \\<propto> low) (repc \\<propto> high) t\"\n            from t_in_repcNodes \n            have x_in_repcNodesSucn:  \n              \"\\<forall> x. x \\<in> set_of t \\<longrightarrow> x \\<in> repc ` Nodes (Suc n) ll\" \n              apply -\n              apply auto\n              done\n            from t_nTip t_dag have \"p \\<noteq> Null\"\n              apply -\n              apply (case_tac \"p=Null\")\n              apply auto\n              done\n            with t_nTip t_dag obtain lt rt where t_Node: \"t=Node lt p rt\"\n              by auto\n            then have \"p \\<in> set_of t\"\n              by auto\n            with x_in_repcNodesSucn have \"p \\<in> repc ` Nodes (Suc n) ll\"\n              by simp\n            then obtain a where \n              repca_p: \"p=repc a\" and a_in_NodesSucn: \"a \\<in> Nodes (Suc n) ll\"\n              by auto\n            with repca_p while_while_prop t_dag t2t show ?thesis\n              apply -\n              apply (erule_tac x=a in ballE)\n              apply (elim conjE exE)\n              apply (subgoal_tac \"nort = t\") \n              prefer 2\n              apply (simp add: Dag_unique)\n              apply auto\n              done\n          qed\n          from rep_rep_no t2_in_DagsNodesSucn t2_notin_DagsNodesn ord_t2 while_prop_part wf_ll \n            nsll  repcNodes_in_Nodes obtain a2 where\n            t2_repc_dag: \"Dag (repc a2) (repc \\<propto> low) (repc \\<propto> high) t2\" and\n            a2_in_lln: \"a2 \\<in> set (ll ! n)\"\n            apply -\n            apply (drule restrict_root_Node)\n            apply (auto simp add: length_ll_eq)\n            done\n          with wf_ll nsll  have a2_in_pret: \"a2 \\<in> set_of pret\" \n            by (simp add: wf_ll_def length_ll_eq)\n          from wf_ll nsll  a2_in_lln have vara2_n: \"var a2 = n\" \n            by (simp add: wf_ll_def length_ll_eq)\n          from a2_in_lln rep_prop  obtain\n            repa2_nNull: \" repc a2 \\<noteq> Null\" and\n            repa2_reduce: \"(repc \\<propto> low) a2 = (repc \\<propto> high) a2 \\<and> low a2 \\<noteq> Null \n            \\<longrightarrow> repc a2 = (repc \\<propto> high) a2\" and\n            repa2_share: \"((repc \\<propto> low) a2 = (repc \\<propto> high) a2 \\<longrightarrow> low a2 = Null) \n            \\<longrightarrow> repc a2 \\<in> set (ll ! n) \\<and> repc (repc a2) = repc a2 \\<and> \n            (\\<forall>no1\\<in>set (ll ! n). ((repc \\<propto> high) no1 = (repc \\<propto> high) a2 \\<and> \n            (repc \\<propto> low) no1 = (repc \\<propto> low) a2) = (repc a2 = repc no1))\"\n            using [[simp_depth_limit = 4]]\n            by auto\n          from t2_repc_dag a2_in_lln repa2_nNull obtain lt2 rt2 where \n            t2_Node: \"t2 = (Node lt2 (repc a2) rt2)\"\n            by auto\n          show \"isomorphic_dags_eq t1 t2 var\"\n          proof (cases \"(repc \\<propto> low) a1 = (repc \\<propto> high) a1 \\<and> low a1 \\<noteq> Null\")\n            case True\n            note t1_red_cond=this              \n            with t1_red_cond have t1_red_case: \"(repc \\<propto> low) a1 = (repc \\<propto> high) a1\"\n              by simp\n            from t1_red_cond have lowa1_nNull: \"low a1 \\<noteq> Null\"\n              by simp\n            with pret_dag prebdt_pret a1_in_pret have higha1_nNull: \"high a1 \\<noteq> Null\" \n              apply -\n              apply (drule balanced_bdt)\n              apply auto\n              done\n            from pret_dag ord_pret a1_in_pret lowa1_nNull higha1_nNull \n            have var_children_smaller_a1: \"var (low a1) < var a1 \\<and> var (high a1) < var a1\"\n              apply -\n              apply (rule var_ordered_children)\n              apply auto\n              done\n            from pret_dag a1_in_pret have a1_nNull: \"a1 \\<noteq> Null\" \n              apply -\n              apply (rule set_of_nn [rule_format])\n              apply auto\n              done\n            with a1_in_pret higha1_nNull pret_dag have \"high a1 \\<in> set_of pret\" \n              apply -\n              apply (drule subelem_set_of_high)\n              apply auto\n              done\n            with wf_ll have \"high a1 \\<in> set (ll ! (var (high a1)))\" \n              by (simp add: wf_ll_def)\n            with a1_in_lln t1_repc_dag var_children_smaller_a1 vara1_n \n            have \"\\<exists>k<n. (high a1) \\<in> set (ll ! k)\"\n              by auto\n            then have higha1_in_Nodesn: \"(high a1) \\<in> Nodes n ll\"\n              by (simp add: Nodes_def)\n            then have rhigha1_in_rNodesn: \"repc (high a1) \\<in> repc ` Nodes n ll\"\n              by simp\n            from higha1_in_Nodesn normalize_prop obtain rt1 where \n              rt1_dag:  \"Dag (repb (high a1)) (repb \\<propto> low) (repb \\<propto> high) rt1\" and\n              rt1_in_repbNort: \"set_of rt1 \\<subseteq> repb `Nodes n ll\"\n              apply -\n              apply (erule_tac x=\"high a1\" in ballE)\n              apply auto\n              done\n            from rt1_in_repbNort repbNodes_repcNodes \n            have rt1_in_repcNodesn: \"set_of rt1 \\<subseteq> repc `Nodes n ll\"\n              by blast\n            from rt1_dag higha1_in_Nodesn \n            have repcrt1_dag: \"Dag (repc (high a1)) (repc \\<propto> low) (repc \\<propto> high) rt1\"\n              apply -\n              apply (drule Nodes_repbc_Dags_eq [rule_format])\n              apply auto\n              done\n            have rt1_nTip: \"rt1 \\<noteq> Tip\"\n            proof -\n              have \"repc (high a1) \\<noteq> Null\"\n              proof -\n                note rhigha1_in_rNodesn\n                also have \"repc `Nodes n ll \\<subseteq> repc `Nodes (Suc n) ll\"\n                  using Nodes_subset \n                  by blast\n                also have \"\\<dots> \\<subseteq> Nodes (Suc n) ll\"\n                  using repcNodes_in_Nodes\n                  by simp\n                finally show ?thesis\n                  using null_notin_Nodes_Suc_n\n                  by auto\n              qed\n              with repcrt1_dag show ?thesis by auto\n            qed\n            from repa1_reduce lowa1_nNull  higha1_nNull  t1_red_case \n            have repc_a1_def: \"repc a1 = repc (high a1)\" \n              by (simp add: null_comp_def)\n            with rt1_in_repcNodesn repcrt1_dag rhigha1_in_rNodesn a1_in_lln \n              t1_repc_dag repc_a1_def  rt1_nTip \n            have t1_in_Dags_Nodesn: \n              \"t1 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n              apply -\n              apply (rule DagsI)\n              apply simp\n              apply (subgoal_tac \"t1=rt1\")\n              apply (auto simp add: Dag_unique)\n              done\n            show ?thesis\n            proof (cases \"(repc \\<propto> low) a2 = (repc \\<propto> high) a2 \\<and> low a2 \\<noteq> Null\")\n              case True\n              note t2_red_cond=this              \n              with t2_red_cond have t2_red_case: \"(repc \\<propto> low) a2 = (repc \\<propto> high) a2\"\n                by simp\n              from t2_red_cond have lowa2_nNull: \"low a2 \\<noteq> Null\"\n                by simp\n              with pret_dag prebdt_pret a2_in_pret have higha2_nNull: \"high a2 \\<noteq> Null\" \n                apply -\n                apply (drule balanced_bdt)\n                apply auto\n                done\n              from pret_dag ord_pret a2_in_pret lowa2_nNull higha2_nNull \n              have var_children_smaller_a2: \n                \"var (low a2) < var a2 \\<and> var (high a2) < var a2\"\n                apply -\n                apply (rule var_ordered_children)\n                apply auto\n                done\n              from pret_dag a2_in_pret have a2_nNull: \"a2 \\<noteq> Null\" \n                apply -\n                apply (rule set_of_nn [rule_format])\n                apply auto\n                done\n              with a2_in_pret higha2_nNull pret_dag have \"high a2 \\<in> set_of pret\" \n                apply -\n                apply (drule subelem_set_of_high)\n                apply auto\n                done\n              with wf_ll have \"high a2 \\<in> set (ll ! (var (high a2)))\" \n                by (simp add: wf_ll_def)\n              with a2_in_lln t2_repc_dag var_children_smaller_a2 vara2_n \n              have \"\\<exists> k<n. (high a2) \\<in> set (ll ! k)\"\n                by auto\n              then have higha2_in_Nodesn: \"(high a2) \\<in> Nodes n ll\"\n                by (simp add: Nodes_def)\n              then have rhigha2_in_rNodesn: \"repc (high a2) \\<in> repc ` Nodes n ll\"\n                by simp\n              from higha2_in_Nodesn normalize_prop obtain rt2 where \n                rt2_dag:  \"Dag (repb (high a2)) (repb \\<propto> low) (repb \\<propto> high) rt2\" and\n                rt2_in_repbNort: \"set_of rt2 \\<subseteq> repb `Nodes n ll\"\n                apply -\n                apply (erule_tac x=\"high a2\" in ballE)\n                apply auto\n                done\n              from rt2_in_repbNort repbNodes_repcNodes \n              have rt2_in_repcNodesn: \"set_of rt2 \\<subseteq> repc `Nodes n ll\"\n                by blast\n              from rt2_dag higha2_in_Nodesn \n              have repcrt2_dag: \"Dag (repc (high a2)) (repc \\<propto> low) (repc \\<propto> high) rt2\"\n                apply -\n                apply (drule Nodes_repbc_Dags_eq [rule_format])\n                apply auto\n                done\n              have rt2_nTip: \"rt2 \\<noteq> Tip\"\n              proof -\n                have \"repc (high a2) \\<noteq> Null\"\n                proof -\n                  note rhigha2_in_rNodesn\n                  also have \"repc `Nodes n ll \\<subseteq> repc `Nodes (Suc n) ll\"\n                    using Nodes_subset \n                    by blast\n                  also have \"\\<dots> \\<subseteq> Nodes (Suc n) ll\"\n                    using repcNodes_in_Nodes\n                    by simp\n                  finally show ?thesis\n                    using null_notin_Nodes_Suc_n\n                    by auto\n                qed\n                with repcrt2_dag show ?thesis by auto\n              qed\n              from repa2_reduce lowa2_nNull  higha2_nNull  t2_red_case \n              have repc_a2_def: \"repc a2 = repc (high a2)\" \n                by (simp add: null_comp_def)\n              with rt2_in_repcNodesn repcrt2_dag rhigha2_in_rNodesn a2_in_lln \n                t2_repc_dag repc_a2_def  rt2_nTip \n              have t2_in_Dags_Nodesn: \n                \"t2 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n                apply -\n                apply (rule DagsI)\n                apply simp\n                apply (subgoal_tac \"t2=rt2\")\n                apply (auto simp add: Dag_unique)\n                done\n              from isomorphic_dags_eq t1_in_Dags_Nodesn t2_in_Dags_Nodesn repbc_dags_eq \n              show ?thesis\n                by auto\n            next\n              assume t2_share_cond: \n                \"\\<not> ((repc \\<propto> low) a2 = (repc \\<propto> high) a2 \\<and> low a2 \\<noteq> Null)\"\n              from t1_in_Dags_Nodesn t2_notin_DagsNodesn t2_in_DagsNodesSucn \n                isomorphic_dags_eq repbc_dags_eq\n              show ?thesis\n                apply -\n                apply (rule mixed_Dags_case)\n                apply auto\n                done\n            qed\n          next\n            assume t1_share_cond: \n              \"\\<not>((repc \\<propto> low) a1 = (repc \\<propto> high) a1 \\<and> low a1 \\<noteq> Null)\"\n            with repa1_share obtain\n              repca1_in_llbn: \"repc a1 \\<in> set (ll ! n)\" and \n              reprepa1: \"repc (repc a1) = repc a1\" and\n              twonodes_llbn_a1: \n              \"(\\<forall>no1\\<in>set (ll ! n). ((repc \\<propto> high) no1 = (repc \\<propto> high) a1 \\<and> \n              (repc \\<propto> low) no1 = (repc \\<propto> low) a1) = (repc a1 = repc no1))\"\n              using [[simp_depth_limit=2]]\n              by auto\n            show ?thesis\n            proof (cases \"(repc \\<propto> low) a2 = (repc \\<propto> high) a2 \\<and> low a2 \\<noteq> Null\")\n              case True\n              note t2_red_cond=this              \n              with t2_red_cond have t2_red_case: \"(repc \\<propto> low) a2 = (repc \\<propto> high) a2\"\n                by simp\n              from t2_red_cond have lowa2_nNull: \"low a2 \\<noteq> Null\"\n                by simp\n              with pret_dag prebdt_pret a2_in_pret have higha2_nNull: \"high a2 \\<noteq> Null\" \n                apply -\n                apply (drule balanced_bdt)\n                apply auto\n                done\n              from pret_dag ord_pret a2_in_pret lowa2_nNull higha2_nNull \n              have var_children_smaller_a2: \n                \"var (low a2) < var a2 \\<and> var (high a2) < var a2\"\n                apply -\n                apply (rule var_ordered_children)\n                apply auto\n                done\n              from pret_dag a2_in_pret have a2_nNull: \"a2 \\<noteq> Null\" \n                apply -\n                apply (rule set_of_nn [rule_format])\n                apply auto\n                done\n              with a2_in_pret higha2_nNull pret_dag have \"high a2 \\<in> set_of pret\" \n                apply -\n                apply (drule subelem_set_of_high)\n                apply auto\n                done\n              with wf_ll \n              have \"high a2 \\<in> set (ll ! (var (high a2)))\" \n                by (simp add: wf_ll_def)\n              with a2_in_lln t2_repc_dag var_children_smaller_a2 vara2_n \n              have \"\\<exists> k<n. (high a2) \\<in> set (ll ! k)\"\n                by auto\n              then have higha2_in_Nodesn: \"(high a2) \\<in> Nodes n ll\"\n                by (simp add: Nodes_def)\n              then have rhigha2_in_rNodesn: \"repc (high a2) \\<in> repc ` Nodes n ll\"\n                by simp\n              from higha2_in_Nodesn normalize_prop obtain rt2 where \n                rt2_dag:  \"Dag (repb (high a2)) (repb \\<propto> low) (repb \\<propto> high) rt2\" and\n                rt2_in_repbNort: \"set_of rt2 \\<subseteq> repb `Nodes n ll\"\n                apply -\n                apply (erule_tac x=\"high a2\" in ballE)\n                apply auto\n                done\n              from rt2_in_repbNort repbNodes_repcNodes \n              have rt2_in_repcNodesn: \"set_of rt2 \\<subseteq> repc `Nodes n ll\"\n                by blast\n              from rt2_dag higha2_in_Nodesn \n              have repcrt2_dag: \"Dag (repc (high a2)) (repc \\<propto> low) (repc \\<propto> high) rt2\"\n                apply -\n                apply (drule Nodes_repbc_Dags_eq [rule_format])\n                apply auto\n                done\n              have rt2_nTip: \"rt2 \\<noteq> Tip\"\n              proof -\n                have \"repc (high a2) \\<noteq> Null\"\n                proof -\n                  note rhigha2_in_rNodesn\n                  also have \"repc `Nodes n ll \\<subseteq> repc `Nodes (Suc n) ll\"\n                    using Nodes_subset \n                    by blast\n                  also have \"\\<dots> \\<subseteq> Nodes (Suc n) ll\"\n                    using repcNodes_in_Nodes\n                    by simp\n                  finally show ?thesis\n                    using null_notin_Nodes_Suc_n\n                    by auto\n                qed\n                with repcrt2_dag show ?thesis by auto\n              qed\n              from repa2_reduce lowa2_nNull  higha2_nNull  t2_red_case \n              have repc_a2_def: \"repc a2 = repc (high a2)\" \n                by (simp add: null_comp_def)\n              with rt2_in_repcNodesn repcrt2_dag rhigha2_in_rNodesn a2_in_lln \n                t2_repc_dag repc_a2_def  rt2_nTip \n              have t2_in_Dags_Nodesn: \n                \"t2 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n                apply -\n                apply (rule DagsI)\n                apply simp\n                apply (subgoal_tac \"t2=rt2\")\n                apply (auto simp add: Dag_unique)\n                done\n              from t2_in_Dags_Nodesn t1_notin_DagsNodesn t1_in_DagsNodesSucn \n                isomorphic_dags_eq repbc_dags_eq \n              have \"isomorphic_dags_eq t2 t1 var\"\n                apply -\n                apply (rule mixed_Dags_case)\n                apply auto\n                done\n              then show ?thesis\n                by (simp add: isomorphic_dags_eq_sym)\n            next\n              assume t2_shared_cond: \n                \"\\<not> ((repc \\<propto> low) a2 = (repc \\<propto> high) a2 \\<and> low a2 \\<noteq> Null)\"\n              with repa2_share obtain\n                repca2_in_llbn: \"repc a2 \\<in> set (ll ! n)\" and \n                reprepa2: \"repc (repc a2) = repc a2\" and\n                twonodes_llbn_a2: \"(\\<forall>no1\\<in>set (ll ! n). \n                ((repc \\<propto> high) no1 = (repc \\<propto> high) a2 \\<and> \n                (repc \\<propto> low) no1 = (repc \\<propto> low) a2) = (repc a2 = repc no1))\"\n                using [[simp_depth_limit=2]]\n                by auto \n              from twonodes_llbn_a2 a1_in_lln  \n              have share_a1_a2: \n                \"((repc \\<propto> high) a1 = (repc \\<propto> high) a2 \\<and> \n                (repc \\<propto> low) a1 = (repc \\<propto> low) a2) = (repc a2 = repc a1)\"\n                by auto\n              from twonodes_llbn_a1 repca1_in_llbn reprepa1   \n              have children_repc_eq_a1: \"(repc \\<propto> high) (repc a1) = (repc \\<propto> high) a1 \\<and> \n                (repc \\<propto> low) (repc a1) = (repc \\<propto> low) a1\"\n                by auto\n              from twonodes_llbn_a2 repca2_in_llbn reprepa2  \n              have children_repc_eq_a2: \"(repc \\<propto> high) (repc a2) = (repc \\<propto> high) a2 \\<and> \n                (repc \\<propto> low) (repc a2) = (repc \\<propto> low) a2\"\n                by auto\n              from  t1_Node t2_Node show ?thesis\n              proof (clarsimp simp add: isomorphic_dags_eq_def)\n                fix bdt1\n                assume t1_bdt: \"bdt (Node lt1 (repc a1) rt1) var = Some bdt1\"\n                assume t2_bdt: \"bdt (Node lt2 (repc a2) rt2) var = Some bdt1\"\n                show \"lt1 = lt2 \\<and> repc a1 = repc a2 \\<and> rt1 = rt2\"\n                proof (cases bdt1)\n                  case Zero\n                  with t1_bdt t1_Node obtain\n                    lt1_Tip: \"lt1 = Tip\" and\n                    rt1_Tip: \"rt1 = Tip\"\n                    by simp\n                  from Zero t2_bdt t2_Node obtain \n                    lt2_Tip: \"lt2 = Tip\" and\n                    rt2_Tip: \"rt2 = Tip\"\n                    by simp\n                  from t1_repc_dag t1_Node lt1_Tip have \"(repc \\<propto> low) (repc a1) = Null\" \n                    by simp\n                  with children_repc_eq_a1  \n                  have repc_low_a1_Null: \"(repc \\<propto> low) a1 = Null\"\n                    by simp\n                  from t1_repc_dag t1_Node rt1_Tip \n                  have \"(repc \\<propto> high) (repc a1) = Null\"\n                    by simp\n                  with children_repc_eq_a1  \n                  have repc_high_a1_Null: \"(repc \\<propto> high) a1 = Null\"\n                    by simp\n                  from t2_repc_dag t2_Node lt2_Tip have \"(repc \\<propto> low) (repc a2) = Null\" \n                    by simp\n                  with children_repc_eq_a2  \n                  have repc_low_a2_Null: \"(repc \\<propto> low) a2 = Null\"\n                    by simp\n                  from t2_repc_dag t2_Node rt2_Tip \n                  have \"(repc \\<propto> high) (repc a2) = Null\"\n                    by simp\n                  with children_repc_eq_a2  \n                  have repc_high_a2_Null: \"(repc \\<propto> high) a2 = Null\"\n                    by simp\n                  with share_a1_a2   repc_low_a1_Null repc_high_a1_Null \n                    repc_low_a2_Null repc_high_a2_Null\n                  have \"repc a2 = repc a1\"\n                    by auto\n                  with lt1_Tip rt1_Tip lt2_Tip rt2_Tip show ?thesis\n                    by auto\n                next\n                  case One\n                  with t1_bdt t1_Node obtain\n                    lt1_Tip: \"lt1 = Tip\" and\n                    rt1_Tip: \"rt1 = Tip\"\n                    by simp\n                  from One t2_bdt t2_Node obtain \n                    lt2_Tip: \"lt2 = Tip\" and\n                    rt2_Tip: \"rt2 = Tip\"\n                    by simp\n                  from t1_repc_dag t1_Node lt1_Tip have \"(repc \\<propto> low) (repc a1) = Null\" \n                    by simp\n                  with children_repc_eq_a1  \n                  have repc_low_a1_Null: \"(repc \\<propto> low) a1 = Null\"\n                    by simp\n                  from t1_repc_dag t1_Node rt1_Tip have \"(repc \\<propto> high) (repc a1) = Null\"\n                    by simp\n                  with children_repc_eq_a1  \n                  have repc_high_a1_Null: \"(repc \\<propto> high) a1 = Null\"\n                    by simp\n                  from t2_repc_dag t2_Node lt2_Tip have \"(repc \\<propto> low) (repc a2) = Null\" \n                    by simp\n                  with children_repc_eq_a2  \n                  have repc_low_a2_Null: \"(repc \\<propto> low) a2 = Null\"\n                    by simp\n                  from t2_repc_dag t2_Node rt2_Tip have \"(repc \\<propto> high) (repc a2) = Null\"\n                    by simp\n                  with children_repc_eq_a2  \n                  have repc_high_a2_Null: \"(repc \\<propto> high) a2 = Null\"\n                    by simp\n                  with share_a1_a2   repc_low_a1_Null repc_high_a1_Null \n                    repc_low_a2_Null repc_high_a2_Null\n                  have \"repc a2 = repc a1\"\n                    by auto\n                  with lt1_Tip rt1_Tip lt2_Tip rt2_Tip show ?thesis\n                    by auto\n                next\n                  case (Bdt_Node lbdt v rbdt)\n                  note bdt_Node_case=this\n                  with t1_bdt t1_Node obtain\n                    lbdt_def_lt1: \"bdt lt1 var = Some lbdt\" and\n                    rbdt_def_rt1: \"bdt rt1 var = Some rbdt\"\n                    by auto\n                  from t2_bdt bdt_Node_case t2_Node obtain\n                    lbdt_def_lt2: \"bdt lt2 var = Some lbdt\" and\n                    rbdt_def_rt2: \"bdt rt2 var = Some rbdt\"\n                    by auto\n                  from lbdt_def_lt1 t1_Node t1_repc_dag children_repc_eq_a1  \n                  have \"(repc \\<propto> low) a1 \\<noteq> Null\"\n                    by auto\n                  then have low_a1_nNull: \"(low a1) \\<noteq> Null\" \n                    by (auto simp: null_comp_def)\n                  from rbdt_def_rt1 t1_Node t1_repc_dag children_repc_eq_a1  \n                  have \"(repc \\<propto> high) a1 \\<noteq> Null\"\n                    by auto\n                  then have high_a1_nNull: \"(high a1) \\<noteq> Null\" \n                    by (auto simp: null_comp_def)\n                  from lbdt_def_lt2 t2_Node t2_repc_dag children_repc_eq_a2  \n                  have \"(repc \\<propto> low) a2 \\<noteq> Null\"\n                    by auto\n                  then have low_a2_nNull: \"(low a2) \\<noteq> Null\" \n                    by (auto simp: null_comp_def)\n                  from rbdt_def_rt2 t2_Node t2_repc_dag children_repc_eq_a2  \n                  have \"(repc \\<propto> high) a2 \\<noteq> Null\"\n                    by auto\n                  then have high_a2_nNull: \"(high a2) \\<noteq> Null\" \n                    by (auto simp: null_comp_def)\n\n                      (*hier gehts um t1*)\n                  from pret_dag ord_pret a1_in_pret low_a1_nNull high_a1_nNull \n                  have var_children_smaller_a1: \n                    \"var (low a1) < var a1 \\<and> var (high a1) < var a1\"\n                    apply -\n                    apply (rule var_ordered_children)\n                    apply auto\n                    done\n                  from pret_dag a1_in_pret have a1_nNull: \"a1 \\<noteq> Null\" \n                    apply -\n                    apply (rule set_of_nn [rule_format])\n                    apply auto\n                    done\n                  \n                      (*hier gehts um rt1 *)\n                  with a1_in_pret high_a1_nNull pret_dag have \"high a1 \\<in> set_of pret\" \n                    apply -\n                    apply (drule subelem_set_of_high)\n                    apply auto\n                    done\n                  with wf_ll \n                  have \"high a1 \\<in> set (ll ! (var (high a1)))\" \n                    by (simp add: wf_ll_def)\n                  with a1_in_lln t1_repc_dag var_children_smaller_a1 vara1_n \n                  have \"\\<exists> k<n. (high a1) \\<in> set (ll ! k)\"\n                    by auto\n                  then have higha1_in_Nodesn: \"(high a1) \\<in> Nodes n ll\"\n                    by (simp add: Nodes_def)\n                  then have rhigha1_in_rNodesn: \n                    \"repc (high a1) \\<in> repc ` Nodes n ll\"\n                    by simp\n                  from higha1_in_Nodesn normalize_prop obtain rt1h where\n                    rt1_dag:  \"Dag (repb (high a1)) (repb \\<propto> low) (repb \\<propto> high) rt1h\" and\n                    rt1_in_repbNort: \"set_of rt1h \\<subseteq> repb `Nodes n ll\"\n                    apply -\n                    apply (erule_tac x=\"high a1\" in ballE)\n                    apply auto\n                    done\n                  from rt1_in_repbNort repbNodes_repcNodes \n                  have rt1_in_repcNodesn: \"set_of rt1h \\<subseteq> repc `Nodes n ll\"\n                    by blast\n                  from rt1_dag higha1_in_Nodesn \n                  have repcrt1_dag: \n                    \"Dag (repc (high a1)) (repc \\<propto> low) (repc \\<propto> high) rt1h\"\n                    apply -\n                    apply (drule Nodes_repbc_Dags_eq [rule_format])\n                    apply auto\n                    done\n                  from t1_Node t1_repc_dag high_a1_nNull children_repc_eq_a1 \n                  have \"Dag (repc (high a1)) (repc \\<propto> low) (repc \\<propto> high) rt1\"\n                    by (auto simp add: null_comp_def)\n                  with repcrt1_dag have rt1h_rt1: \"rt1h = rt1\" by (simp add: Dag_unique)\n                  have rt1_nTip: \"rt1 \\<noteq> Tip\"\n                  proof -\n                    have \"repc (high a1) \\<noteq> Null\"\n                    proof -\n                      note rhigha1_in_rNodesn\n                      also have \n                        \"repc `Nodes n ll \\<subseteq> repc `Nodes (Suc n) ll\"\n                        using Nodes_subset \n                        by blast\n                      also have \"\\<dots> \\<subseteq> Nodes (Suc n) ll\"\n                        using repcNodes_in_Nodes\n                        by simp\n                      finally show ?thesis\n                        using null_notin_Nodes_Suc_n\n                        by auto\n                    qed\n                    with repcrt1_dag rt1h_rt1 show ?thesis by auto\n                  qed\n                  with rt1_in_repcNodesn repcrt1_dag rhigha1_in_rNodesn a1_in_lln \n                    t1_repc_dag  rt1h_rt1 \n                  have rt1_in_Dags_Nodesn: \n                    \"rt1 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n                    apply -\n                    apply (rule DagsI)\n                    apply auto\n                    done \n\n                  \n                      (*hier gehts um lt1 *)\n                  from a1_nNull a1_in_pret low_a1_nNull pret_dag \n                  have \"low a1 \\<in> set_of pret\"\n                    apply -\n                    apply (drule subelem_set_of_low)\n                    apply auto\n                    done\n                  with wf_ll have \n                    \"low a1 \\<in> set (ll ! (var (low a1)))\" by (simp add: wf_ll_def)\n                  with a1_in_lln t1_repc_dag var_children_smaller_a1 vara1_n \n                  have \"\\<exists> k<n. (low a1) \\<in> set (ll ! k)\"\n                    by auto\n                  then have lowa1_in_Nodesn: \"(low a1) \\<in> Nodes n ll\"\n                    by (simp add: Nodes_def)\n                  then have rlowa1_in_rNodesn: \"repc (low a1) \\<in> repc ` Nodes n ll\"\n                    by simp\n                  from lowa1_in_Nodesn normalize_prop obtain lt1h where\n                    lt1_dag:  \"Dag (repb (low a1)) (repb \\<propto> low) (repb \\<propto> high) lt1h\" and\n                    lt1_in_repbNort: \"set_of lt1h \\<subseteq> repb `Nodes n ll\"\n                    apply -\n                    apply (erule_tac x=\"low a1\" in ballE)\n                    apply auto\n                    done\n                  from lt1_in_repbNort repbNodes_repcNodes \n                  have lt1_in_repcNodesn: \"set_of lt1h \\<subseteq> repc `Nodes n ll\"\n                    by blast\n                  from lt1_dag lowa1_in_Nodesn \n                  have repclt1_dag: \"Dag (repc (low a1)) (repc \\<propto> low) (repc \\<propto> high) lt1h\"\n                    apply -\n                    apply (drule Nodes_repbc_Dags_eq [rule_format])\n                    apply auto\n                    done\n                  from t1_Node t1_repc_dag low_a1_nNull children_repc_eq_a1 \n                  have \"Dag (repc (low a1)) (repc \\<propto> low) (repc \\<propto> high) lt1\"\n                    by (auto simp add: null_comp_def)\n                  with repclt1_dag have lt1h_lt1: \"lt1h = lt1\" by (simp add: Dag_unique)\n                  have lt1_nTip: \"lt1 \\<noteq> Tip\"\n                  proof -\n                    have \"repc (low a1) \\<noteq> Null\"\n                    proof -\n                      note rlowa1_in_rNodesn\n                      also have \n                        \"repc `Nodes n ll \\<subseteq> repc `Nodes (Suc n) ll\"\n                        using Nodes_subset \n                        by blast\n                      also have \"\\<dots> \\<subseteq> Nodes (Suc n) ll\"\n                        using repcNodes_in_Nodes\n                        by simp\n                      finally show ?thesis\n                        using null_notin_Nodes_Suc_n\n                        by auto\n                    qed\n                    with repclt1_dag lt1h_lt1 show ?thesis by auto\n                  qed\n                  with lt1_in_repcNodesn repclt1_dag rlowa1_in_rNodesn a1_in_lln \n                    t1_repc_dag  lt1h_lt1 \n                  have lt1_in_Dags_Nodesn: \n                    \"lt1 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n                    apply -\n                    apply (rule DagsI)\n                    apply auto\n                    done \n                  \n                  \n                      (*hier gehts um t2*)\n                  from pret_dag ord_pret a2_in_pret low_a2_nNull high_a2_nNull \n                  have var_children_smaller_a2: \n                    \"var (low a2) < var a2 \\<and> var (high a2) < var a2\"\n                    apply -\n                    apply (rule var_ordered_children)\n                    apply auto\n                    done\n                  from pret_dag a2_in_pret have a2_nNull: \"a2 \\<noteq> Null\" \n                    apply -\n                    apply (rule set_of_nn [rule_format])\n                    apply auto\n                    done\n                  \n                      (*hier gehts um rt1 *)\n                  with a2_in_pret high_a2_nNull pret_dag have \"high a2 \\<in> set_of pret\" \n                    apply -\n                    apply (drule subelem_set_of_high)\n                    apply auto\n                    done\n                  with wf_ll have \"high a2 \\<in> set (ll ! (var (high a2)))\" \n                    by (simp add: wf_ll_def)\n                  with a2_in_lln t2_repc_dag var_children_smaller_a2 vara2_n \n                  have \"\\<exists> k<n. (high a2) \\<in> set (ll ! k)\"\n                    by auto\n                  then have higha2_in_Nodesn: \"(high a2) \\<in> Nodes n ll\"\n                    by (simp add: Nodes_def)\n                  then have rhigha2_in_rNodesn: \n                    \"repc (high a2) \\<in> repc ` Nodes n ll\"\n                    by simp\n                  from higha2_in_Nodesn normalize_prop obtain rt2h where\n                    rt2_dag:  \"Dag (repb (high a2)) (repb \\<propto> low) (repb \\<propto> high) rt2h\" and\n                    rt2_in_repbNort: \"set_of rt2h \\<subseteq> repb `Nodes n ll\"\n                    apply -\n                    apply (erule_tac x=\"high a2\" in ballE)\n                    apply auto\n                    done\n                  from rt2_in_repbNort repbNodes_repcNodes \n                  have rt2_in_repcNodesn: \"set_of rt2h \\<subseteq> repc `Nodes n ll\"\n                    by blast\n                  from rt2_dag higha2_in_Nodesn \n                  have repcrt2_dag: \n                    \"Dag (repc (high a2)) (repc \\<propto> low) (repc \\<propto> high) rt2h\"\n                    apply -\n                    apply (drule Nodes_repbc_Dags_eq [rule_format])\n                    apply auto\n                    done\n                  from t2_Node t2_repc_dag high_a2_nNull children_repc_eq_a2 \n                  have \"Dag (repc (high a2)) (repc \\<propto> low) (repc \\<propto> high) rt2\"\n                    by (auto simp add: null_comp_def)\n                  with repcrt2_dag have rt2h_rt2: \"rt2h = rt2\" by (simp add: Dag_unique)\n                  have rt2_nTip: \"rt2 \\<noteq> Tip\"\n                  proof -\n                    have \"repc (high a2) \\<noteq> Null\"\n                    proof -\n                      note rhigha2_in_rNodesn\n                      also have \n                        \"repc `Nodes n ll \\<subseteq> repc `Nodes (Suc n) ll\"\n                        using Nodes_subset \n                        by blast\n                      also have \"\\<dots> \\<subseteq> Nodes (Suc n) ll\"\n                        using repcNodes_in_Nodes\n                        by simp\n                      finally show ?thesis\n                        using null_notin_Nodes_Suc_n\n                        by auto\n                    qed\n                    with repcrt2_dag rt2h_rt2 show ?thesis by auto\n                  qed\n                  with rt2_in_repcNodesn repcrt2_dag rhigha2_in_rNodesn a2_in_lln \n                    t2_repc_dag  rt2h_rt2 \n                  have rt2_in_Dags_Nodesn: \n                    \"rt2 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n                    apply -\n                    apply (rule DagsI)\n                    apply auto\n                    done \n\n                  \n                      (*hier gehts um lt2 *)\n                  from a2_nNull a2_in_pret low_a2_nNull pret_dag \n                  have \"low a2 \\<in> set_of pret\"\n                    apply -\n                    apply (drule subelem_set_of_low)\n                    apply auto\n                    done\n                  with wf_ll have \"low a2 \\<in> set (ll ! (var (low a2)))\" \n                    by (simp add: wf_ll_def)\n                  with a2_in_lln t2_repc_dag var_children_smaller_a2 vara2_n \n                  have \"\\<exists> k<n. (low a2) \\<in> set (ll ! k)\"\n                    by auto\n                  then have lowa2_in_Nodesn: \"(low a2) \\<in> Nodes n ll\"\n                    by (simp add: Nodes_def)\n                  then have rlowa2_in_rNodesn: \"repc (low a2) \\<in> repc ` Nodes n ll\"\n                    by simp\n                  from lowa2_in_Nodesn normalize_prop obtain lt2h where\n                    lt2_dag:  \"Dag (repb (low a2)) (repb \\<propto> low) (repb \\<propto> high) lt2h\" and\n                    lt2_in_repbNort: \"set_of lt2h \\<subseteq> repb `Nodes n ll\"\n                    apply -\n                    apply (erule_tac x=\"low a2\" in ballE)\n                    apply auto\n                    done\n                  from lt2_in_repbNort repbNodes_repcNodes \n                  have lt2_in_repcNodesn: \"set_of lt2h \\<subseteq> repc `Nodes n ll\"\n                    by blast\n                  from lt2_dag lowa2_in_Nodesn \n                  have repclt2_dag: \"Dag (repc (low a2)) (repc \\<propto> low) (repc \\<propto> high) lt2h\"\n                    apply -\n                    apply (drule Nodes_repbc_Dags_eq [rule_format])\n                    apply auto\n                    done\n                  from t2_Node t2_repc_dag low_a2_nNull children_repc_eq_a2 \n                  have \"Dag (repc (low a2)) (repc \\<propto> low) (repc \\<propto> high) lt2\"\n                    by (auto simp add: null_comp_def)\n                  with repclt2_dag have lt2h_lt2: \"lt2h = lt2\" by (simp add: Dag_unique)\n                  have lt2_nTip: \"lt2 \\<noteq> Tip\"\n                  proof -\n                    have \"repc (low a2) \\<noteq> Null\"\n                    proof -\n                      note rlowa2_in_rNodesn\n                      also have \n                        \"repc `Nodes n ll \\<subseteq> repc `Nodes (Suc n) ll\"\n                        using Nodes_subset \n                        by blast\n                      also have \"\\<dots> \\<subseteq> Nodes (Suc n) ll\"\n                        using repcNodes_in_Nodes\n                        by simp\n                      finally show ?thesis\n                        using null_notin_Nodes_Suc_n\n                        by auto\n                    qed\n                    with repclt2_dag lt2h_lt2 show ?thesis by auto\n                  qed\n                  with lt2_in_repcNodesn repclt2_dag rlowa2_in_rNodesn a2_in_lln \n                    t2_repc_dag  lt2h_lt2 \n                  have lt2_in_Dags_Nodesn: \n                    \"lt2 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n                    apply -\n                    apply (rule DagsI)\n                    apply auto\n                    done \n                  \n                  \n                  from isomorphic_dags_eq lt1_in_Dags_Nodesn lt2_in_Dags_Nodesn repbc_dags_eq \n                  have shared_lt1_lt2: \"isomorphic_dags_eq lt1 lt2 var\"\n                    by auto\n                  from isomorphic_dags_eq rt1_in_Dags_Nodesn rt2_in_Dags_Nodesn repbc_dags_eq \n                  have shared_rt1_rt2: \"isomorphic_dags_eq rt1 rt2 var\"\n                    by auto\n                  \n                  from shared_lt1_lt2 lbdt_def_lt1 lbdt_def_lt2 have lt1_lt2: \"lt1 = lt2\"\n                    by (auto simp add: isomorphic_dags_eq_def)\n                  then have root_lt1_lt2: \"root lt1 = root lt2\"\n                    by auto\n                  from lt1_nTip t1_repc_dag t1_Node have \"(repc \\<propto> low) (repc a1) \\<noteq> Null\"\n                    by auto\n                  with lt1_nTip t1_repc_dag t1_Node obtain llt1 lt1p rlt1 where \n                    lt1_Node: \"lt1 = Node llt1 lt1p rlt1\"\n                    by auto\n                  with t1_repc_dag t1_Node children_repc_eq_a1 lt1_nTip \n                  have root_lt1: \"root lt1 = (repc \\<propto> low) a1\"\n                    by auto\n                  from lt2_nTip t2_repc_dag t2_Node have \"(repc \\<propto> low) (repc a2) \\<noteq> Null\"\n                    by auto\n                  with lt2_nTip t2_repc_dag t2_Node obtain llt2 lt2p rlt2 where \n                    lt2_Node: \"lt2 = Node llt2 lt2p rlt2\"\n                    by auto\n                  with t2_repc_dag t2_Node children_repc_eq_a2 lt2_nTip \n                  have root_lt2: \"root lt2 = (repc \\<propto> low) a2\"\n                    by auto\n                  from root_lt1_lt2 root_lt2 root_lt1 \n                  have low_a1_a2: \"(repc \\<propto> low) a1 = (repc \\<propto> low) a2\"\n                    by auto\n                  from shared_rt1_rt2 rbdt_def_rt1 rbdt_def_rt2 have rt1_rt2: \"rt1 = rt2\"\n                    by (auto simp add: isomorphic_dags_eq_def)\n                  then have root_rt1_rt2: \"root rt1 = root rt2\"\n                    by auto\n                  from rt1_nTip t1_repc_dag t1_Node have \"(repc \\<propto> high) (repc a1) \\<noteq> Null\"\n                    by auto\n                  with rt1_nTip t1_repc_dag t1_Node obtain lrt1 rt1p rrt1 where \n                    rt1_Node: \"rt1 = Node lrt1 rt1p rrt1\"\n                    by auto\n                  with t1_repc_dag t1_Node children_repc_eq_a1 rt1_nTip \n                  have root_rt1: \"root rt1 = (repc \\<propto> high) a1\"\n                    by auto\n                  from rt2_nTip t2_repc_dag t2_Node \n                  have \"(repc \\<propto> high) (repc a2) \\<noteq> Null\"\n                    by auto\n                  with rt2_nTip t2_repc_dag t2_Node obtain lrt2 rt2p rrt2 where \n                    rt2_Node: \"rt2 = Node lrt2 rt2p rrt2\"\n                    by auto\n                  with t2_repc_dag t2_Node children_repc_eq_a2 rt2_nTip \n                  have root_rt2: \"root rt2 = (repc \\<propto> high) a2\"\n                    by auto\n                  from root_rt1_rt2 root_rt2 root_rt1 \n                  have high_a1_a2: \"(repc \\<propto> high) a1 = (repc \\<propto> high) a2\"\n                    by auto\n                  from low_a1_a2 high_a1_a2 share_a1_a2   \n                  have \"repc a1 = repc a2\"\n                    by auto\n                  with lt1_lt2 rt1_rt2 show ?thesis\n                    by auto\n                qed\n              qed\n            qed\n          qed\n        qed\n        from termi dags_shared while_while_prop repcNodes_in_Nodes repc_nc n_var_prop \n          wf_marking_m_ma  \n        show ?thesis\n          by auto\n      qed\n    qed\n    with srrl_precond all_nodes_same_var \n    show ?thesis\n      apply -\n      apply (intro conjI)\n      apply assumption+\n      done\n  qed\nqed\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/BDD/NormalizeTotalProof.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5544704796847395, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.2837317512729648}}
{"text": "section \\<open>Error monad\\<close>\n\ntheory Error_Monad\nimports Monad_Plus\nbegin\n\nsubsection \\<open>Type definition\\<close>\n\ntycondef 'a\\<cdot>'e error = Err (lazy \"'e\") | Ok (lazy \"'a\")\n\nlemma coerce_error_abs [simp]: \"coerce\\<cdot>(error_abs\\<cdot>x) = error_abs\\<cdot>(coerce\\<cdot>x)\"\napply (simp add: error_abs_def coerce_def)\napply (simp add: emb_prj_emb prj_emb_prj DEFL_eq_error)\ndone\n\nlemma coerce_Err [simp]: \"coerce\\<cdot>(Err\\<cdot>x) = Err\\<cdot>(coerce\\<cdot>x)\"\nunfolding Err_def by simp\n\nlemma coerce_Ok [simp]: \"coerce\\<cdot>(Ok\\<cdot>m) = Ok\\<cdot>(coerce\\<cdot>m)\"\nunfolding Ok_def by simp\n\nlemma fmapU_error_simps [simp]:\n  \"fmapU\\<cdot>f\\<cdot>(\\<bottom>::udom\\<cdot>'a error) = \\<bottom>\"\n  \"fmapU\\<cdot>f\\<cdot>(Err\\<cdot>e) = Err\\<cdot>e\"\n  \"fmapU\\<cdot>f\\<cdot>(Ok\\<cdot>x) = Ok\\<cdot>(f\\<cdot>x)\"\nunfolding fmapU_error_def error_map_def fix_const\napply simp\napply (simp add: Err_def)\napply (simp add: Ok_def)\ndone\n\nsubsection \\<open>Monad class instance\\<close>\n\ninstantiation error :: (\"domain\") \"{monad, functor_plus}\"\nbegin\n\ndefinition\n  \"returnU = Ok\"\n\nfixrec bindU_error :: \"udom\\<cdot>'a error \\<rightarrow> (udom \\<rightarrow> udom\\<cdot>'a error) \\<rightarrow> udom\\<cdot>'a error\"\n  where \"bindU_error\\<cdot>(Err\\<cdot>e)\\<cdot>f = Err\\<cdot>e\"\n  | \"bindU_error\\<cdot>(Ok\\<cdot>x)\\<cdot>f = f\\<cdot>x\"\n\nlemma bindU_error_strict [simp]: \"bindU\\<cdot>\\<bottom>\\<cdot>k = (\\<bottom>::udom\\<cdot>'a error)\"\nby fixrec_simp\n\nfixrec plusU_error :: \"udom\\<cdot>'a error \\<rightarrow> udom\\<cdot>'a error \\<rightarrow> udom\\<cdot>'a error\"\n  where \"plusU_error\\<cdot>(Err\\<cdot>e)\\<cdot>f = f\"\n  | \"plusU_error\\<cdot>(Ok\\<cdot>x)\\<cdot>f = Ok\\<cdot>x\"\n\nlemma plusU_error_strict [simp]: \"plusU\\<cdot>(\\<bottom> :: udom\\<cdot>'a error) = \\<bottom>\"\nby fixrec_simp\n\ninstance proof\n  fix f g :: \"udom \\<rightarrow> udom\" and r :: \"udom\\<cdot>'a error\"\n  show \"fmapU\\<cdot>f\\<cdot>(fmapU\\<cdot>g\\<cdot>r) = fmapU\\<cdot>(\\<Lambda> x. f\\<cdot>(g\\<cdot>x))\\<cdot>r\"\n    by (induct r rule: error.induct) simp_all\nnext\n  fix f :: \"udom \\<rightarrow> udom\" and r :: \"udom\\<cdot>'a error\"\n  show \"fmapU\\<cdot>f\\<cdot>r = bindU\\<cdot>r\\<cdot>(\\<Lambda> x. returnU\\<cdot>(f\\<cdot>x))\"\n    by (induct r rule: error.induct)\n       (simp_all add: returnU_error_def)\nnext\n  fix f :: \"udom \\<rightarrow> udom\\<cdot>'a error\" and x :: \"udom\"\n  show \"bindU\\<cdot>(returnU\\<cdot>x)\\<cdot>f = f\\<cdot>x\"\n    by (simp add: returnU_error_def)\nnext\n  fix r :: \"udom\\<cdot>'a error\" and f g :: \"udom \\<rightarrow> udom\\<cdot>'a error\"\n  show \"bindU\\<cdot>(bindU\\<cdot>r\\<cdot>f)\\<cdot>g = bindU\\<cdot>r\\<cdot>(\\<Lambda> x. bindU\\<cdot>(f\\<cdot>x)\\<cdot>g)\"\n    by (induct r rule: error.induct)\n       simp_all\nnext\n  fix f :: \"udom \\<rightarrow> udom\" and a b :: \"udom\\<cdot>'a error\"\n  show \"fmapU\\<cdot>f\\<cdot>(plusU\\<cdot>a\\<cdot>b) = plusU\\<cdot>(fmapU\\<cdot>f\\<cdot>a)\\<cdot>(fmapU\\<cdot>f\\<cdot>b)\"\n    by (induct a rule: error.induct) simp_all\nnext\n  fix a b c :: \"udom\\<cdot>'a error\"\n  show \"plusU\\<cdot>(plusU\\<cdot>a\\<cdot>b)\\<cdot>c = plusU\\<cdot>a\\<cdot>(plusU\\<cdot>b\\<cdot>c)\"\n    by (induct a rule: error.induct) simp_all\nqed\n\nend\n\nsubsection \\<open>Transfer properties to polymorphic versions\\<close>\n\nlemma fmap_error_simps [simp]:\n  \"fmap\\<cdot>f\\<cdot>(\\<bottom>::'a\\<cdot>'e error) = \\<bottom>\"\n  \"fmap\\<cdot>f\\<cdot>(Err\\<cdot>e :: 'a\\<cdot>'e error) = Err\\<cdot>e\"\n  \"fmap\\<cdot>f\\<cdot>(Ok\\<cdot>x :: 'a\\<cdot>'e error) = Ok\\<cdot>(f\\<cdot>x)\"\nunfolding fmap_def [where 'f=\"'e error\"]\nby (simp_all add: coerce_simp)\n\nlemma return_error_def: \"return = Ok\"\nunfolding return_def returnU_error_def\nby (simp add: coerce_simp eta_cfun)\n\nlemma bind_error_simps [simp]:\n  \"bind\\<cdot>(\\<bottom> :: 'a\\<cdot>'e error)\\<cdot>f = \\<bottom>\"\n  \"bind\\<cdot>(Err\\<cdot>e :: 'a\\<cdot>'e error)\\<cdot>f = Err\\<cdot>e\"\n  \"bind\\<cdot>(Ok\\<cdot>x :: 'a\\<cdot>'e error)\\<cdot>f = f\\<cdot>x\"\nunfolding bind_def\nby (simp_all add: coerce_simp)\n\nlemma join_error_simps [simp]:\n  \"join\\<cdot>\\<bottom> = (\\<bottom> :: 'a\\<cdot>'e error)\"\n  \"join\\<cdot>(Err\\<cdot>e) = Err\\<cdot>e\"\n  \"join\\<cdot>(Ok\\<cdot>x) = x\"\nunfolding join_def by simp_all\n\nlemma fplus_error_simps [simp]:\n  \"fplus\\<cdot>\\<bottom>\\<cdot>r = (\\<bottom> :: 'a\\<cdot>'e error)\"\n  \"fplus\\<cdot>(Err\\<cdot>e)\\<cdot>r = r\"\n  \"fplus\\<cdot>(Ok\\<cdot>x)\\<cdot>r = Ok\\<cdot>x\"\nunfolding fplus_def\nby (simp_all add: coerce_simp)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Tycon/Error_Monad.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5117166047041654, "lm_q2_score": 0.5544704649604274, "lm_q1q2_score": 0.2837317437382898}}
{"text": "(*\n  File:         PAC_Checker_Relation.thy\n  Author:       Mathias Fleury, Daniela Kaufmann, JKU\n  Maintainer:   Mathias Fleury, JKU\n*)\ntheory PAC_Checker_Relation\n  imports PAC_Checker WB_Sort \"Native_Word.Uint64\"\nbegin\n\nsection \\<open>Various Refinement Relations\\<close>\n\ntext \\<open>When writing this, it was not possible to share the definition with the IsaSAT version.\\<close>\ndefinition uint64_nat_rel :: \"(uint64 \\<times> nat) set\" where\n \\<open>uint64_nat_rel = br nat_of_uint64 (\\<lambda>_. True)\\<close>\n\nabbreviation uint64_nat_assn where\n  \\<open>uint64_nat_assn \\<equiv> pure uint64_nat_rel\\<close>\n\ninstantiation uint32 :: hashable\nbegin\ndefinition hashcode_uint32 :: \\<open>uint32 \\<Rightarrow> uint32\\<close> where\n  \\<open>hashcode_uint32 n = n\\<close>\n\ndefinition def_hashmap_size_uint32 :: \\<open>uint32 itself \\<Rightarrow> nat\\<close> where\n  \\<open>def_hashmap_size_uint32 = (\\<lambda>_. 16)\\<close>\n  \\<comment> \\<open>same as @{typ nat}\\<close>\ninstance\n  by standard (simp add: def_hashmap_size_uint32_def)\nend\n\ninstantiation uint64 :: hashable\nbegin\ndefinition hashcode_uint64 :: \\<open>uint64 \\<Rightarrow> uint32\\<close> where\n  \\<open>hashcode_uint64 n = (uint32_of_nat (nat_of_uint64 ((n) AND ((2 :: uint64)^32 -1))))\\<close>\n\ndefinition def_hashmap_size_uint64 :: \\<open>uint64 itself \\<Rightarrow> nat\\<close> where\n  \\<open>def_hashmap_size_uint64 = (\\<lambda>_. 16)\\<close>\n  \\<comment> \\<open>same as @{typ nat}\\<close>\ninstance\n  by standard (simp add: def_hashmap_size_uint64_def)\nend\n\nlemma word_nat_of_uint64_Rep_inject[simp]: \\<open>nat_of_uint64 ai = nat_of_uint64 bi \\<longleftrightarrow> ai = bi\\<close>\n  by transfer (simp add: word_unat_eq_iff)\n\ninstance uint64 :: heap\n  by standard (auto simp: inj_def exI[of _ nat_of_uint64])\n\ninstance uint64 :: semiring_numeral\n  by standard\n\nlemma nat_of_uint64_012[simp]: \\<open>nat_of_uint64 0 = 0\\<close> \\<open>nat_of_uint64 2 = 2\\<close> \\<open>nat_of_uint64 1 = 1\\<close>\n  by (transfer, auto)+\n\ndefinition uint64_of_nat_conv where\n  [simp]: \\<open>uint64_of_nat_conv (x :: nat) = x\\<close>\n\nlemma less_upper_bintrunc_id: \\<open>n < 2 ^b \\<Longrightarrow> n \\<ge> 0 \\<Longrightarrow> take_bit b n = n\\<close> for n :: int\n  by (rule take_bit_int_eq_self)\n\nlemma nat_of_uint64_uint64_of_nat_id: \\<open>n < 2^64 \\<Longrightarrow> nat_of_uint64 (uint64_of_nat n) = n\\<close>\n  unfolding uint64_of_nat_def\n  apply simp\n  apply transfer\n  apply (subst unat_eq_nat_uint)\n  apply transfer\n  by (auto simp: less_upper_bintrunc_id)\n\nlemma [sepref_fr_rules]:\n  \\<open>(return o uint64_of_nat, RETURN o uint64_of_nat_conv) \\<in> [\\<lambda>a. a < 2 ^64]\\<^sub>a nat_assn\\<^sup>k \\<rightarrow> uint64_nat_assn\\<close>\n  by sepref_to_hoare\n   (sep_auto simp: uint64_nat_rel_def br_def nat_of_uint64_uint64_of_nat_id)\n\ndefinition string_rel :: \\<open>(String.literal \\<times> string) set\\<close> where\n  \\<open>string_rel = {(x, y). y = String.explode x}\\<close>\n\nabbreviation string_assn :: \\<open>string \\<Rightarrow> String.literal \\<Rightarrow> assn\\<close> where\n  \\<open>string_assn \\<equiv> pure string_rel\\<close>\n\nlemma eq_string_eq:\n  \\<open>((=), (=)) \\<in> string_rel \\<rightarrow> string_rel \\<rightarrow> bool_rel\\<close>\n by (auto intro!: frefI simp: string_rel_def String.less_literal_def\n    less_than_char_def rel2p_def literal.explode_inject)\n\nlemmas eq_string_eq_hnr =\n   eq_string_eq[sepref_import_param]\n\ndefinition string2_rel :: \\<open>(string \\<times> string) set\\<close> where\n  \\<open>string2_rel \\<equiv> \\<langle>Id\\<rangle>list_rel\\<close>\n\nabbreviation string2_assn :: \\<open>string \\<Rightarrow> string \\<Rightarrow> assn\\<close> where\n  \\<open>string2_assn \\<equiv> pure string2_rel\\<close>\n\nabbreviation monom_rel where\n  \\<open>monom_rel \\<equiv> \\<langle>string_rel\\<rangle>list_rel\\<close>\n\nabbreviation monom_assn where\n  \\<open>monom_assn \\<equiv> list_assn string_assn\\<close>\n\nabbreviation monomial_rel where\n  \\<open>monomial_rel \\<equiv> monom_rel \\<times>\\<^sub>r int_rel\\<close>\n\nabbreviation monomial_assn where\n  \\<open>monomial_assn \\<equiv> monom_assn \\<times>\\<^sub>a int_assn\\<close>\n\nabbreviation poly_rel where\n  \\<open>poly_rel \\<equiv> \\<langle>monomial_rel\\<rangle>list_rel\\<close>\n\n\nabbreviation poly_assn where\n  \\<open>poly_assn \\<equiv> list_assn monomial_assn\\<close>\n\nlemma poly_assn_alt_def:\n  \\<open>poly_assn = pure poly_rel\\<close>\n  by (simp add: list_assn_pure_conv)\n\nabbreviation polys_assn where\n  \\<open>polys_assn \\<equiv> hm_fmap_assn uint64_nat_assn poly_assn\\<close>\n\nlemma string_rel_string_assn:\n  \\<open>(\\<up> ((c, a) \\<in> string_rel)) = string_assn a c\\<close>\n  by (auto simp: pure_app_eq)\n\nlemma single_valued_string_rel:\n   \\<open>single_valued string_rel\\<close>\n   by (auto simp: single_valued_def string_rel_def)\n\nlemma IS_LEFT_UNIQUE_string_rel:\n   \\<open>IS_LEFT_UNIQUE string_rel\\<close>\n   by (auto simp: IS_LEFT_UNIQUE_def single_valued_def string_rel_def\n     literal.explode_inject)\n\nlemma IS_RIGHT_UNIQUE_string_rel:\n   \\<open>IS_RIGHT_UNIQUE string_rel\\<close>\n   by (auto simp: single_valued_def string_rel_def\n     literal.explode_inject)\n\nlemma single_valued_monom_rel: \\<open>single_valued monom_rel\\<close>\n  by (rule list_rel_sv)\n    (auto intro!: frefI simp: string_rel_def\n    rel2p_def single_valued_def p2rel_def)\n\nlemma single_valued_monomial_rel:\n  \\<open>single_valued monomial_rel\\<close>\n  using single_valued_monom_rel\n  by (auto intro!: frefI simp:\n    rel2p_def single_valued_def p2rel_def)\n\nlemma single_valued_monom_rel': \\<open>IS_LEFT_UNIQUE monom_rel\\<close>\n  unfolding IS_LEFT_UNIQUE_def inv_list_rel_eq string2_rel_def\n  by (rule list_rel_sv)+\n   (auto intro!: frefI simp: string_rel_def\n    rel2p_def single_valued_def p2rel_def literal.explode_inject)\n\n\nlemma single_valued_monomial_rel':\n  \\<open>IS_LEFT_UNIQUE monomial_rel\\<close>\n  using single_valued_monom_rel'\n  unfolding IS_LEFT_UNIQUE_def inv_list_rel_eq\n  by (auto intro!: frefI simp:\n    rel2p_def single_valued_def p2rel_def)\n\nlemma [safe_constraint_rules]:\n  \\<open>Sepref_Constraints.CONSTRAINT single_valued string_rel\\<close>\n  \\<open>Sepref_Constraints.CONSTRAINT IS_LEFT_UNIQUE string_rel\\<close>\n  by (auto simp: CONSTRAINT_def single_valued_def\n    string_rel_def IS_LEFT_UNIQUE_def literal.explode_inject)\n\nlemma eq_string_monom_hnr[sepref_fr_rules]:\n  \\<open>(uncurry (return oo (=)), uncurry (RETURN oo (=))) \\<in> monom_assn\\<^sup>k *\\<^sub>a monom_assn\\<^sup>k \\<rightarrow>\\<^sub>a bool_assn\\<close>\n  using single_valued_monom_rel' single_valued_monom_rel\n  unfolding list_assn_pure_conv\n  by sepref_to_hoare\n   (sep_auto simp: list_assn_pure_conv string_rel_string_assn\n       single_valued_def IS_LEFT_UNIQUE_def\n     dest!: mod_starD\n     simp flip: inv_list_rel_eq)\n\n\ndefinition term_order_rel' where\n  [simp]: \\<open>term_order_rel' x y = ((x, y) \\<in> term_order_rel)\\<close>\n\nlemma term_order_rel[def_pat_rules]:\n  \\<open>(\\<in>)$(x,y)$term_order_rel \\<equiv> term_order_rel'$x$y\\<close>\n  by auto\n\nlemma term_order_rel_alt_def:\n  \\<open>term_order_rel = lexord (p2rel char.lexordp)\\<close>\n  by (auto simp: p2rel_def char.lexordp_conv_lexord var_order_rel_def intro!: arg_cong[of _ _ lexord])\n\n\ninstantiation char :: linorder\nbegin\n  definition less_char where [symmetric, simp]: \"less_char = PAC_Polynomials_Term.less_char\"\n  definition less_eq_char where [symmetric, simp]: \"less_eq_char = PAC_Polynomials_Term.less_eq_char\"\ninstance\n  apply standard\n  using char.linorder_axioms\n  by (auto simp: class.linorder_def class.order_def class.preorder_def\n       less_eq_char_def less_than_char_def class.order_axioms_def\n       class.linorder_axioms_def p2rel_def less_char_def)\nend\n\n\ninstantiation list :: (linorder) linorder\nbegin\n  definition less_list where  \"less_list = lexordp (<)\"\n  definition less_eq_list where \"less_eq_list = lexordp_eq\"\n\ninstance\nproof standard\n  have [dest]: \\<open>\\<And>x y :: 'a :: linorder list. (x, y) \\<in> lexord {(x, y). x < y} \\<Longrightarrow>\n           lexordp_eq y x \\<Longrightarrow> False\\<close>\n    by (metis lexordp_antisym lexordp_conv_lexord lexordp_eq_conv_lexord)\n  have [simp]: \\<open>\\<And>x y :: 'a :: linorder list. lexordp_eq x y \\<Longrightarrow>\n           \\<not> lexordp_eq y x \\<Longrightarrow>\n           (x, y) \\<in> lexord {(x, y). x < y}\\<close>\n    using lexordp_conv_lexord lexordp_conv_lexordp_eq by blast\n  show\n   \\<open>(x < y) = Restricted_Predicates.strict (\\<le>) x y\\<close>\n   \\<open>x \\<le> x\\<close>\n   \\<open>x \\<le> y \\<Longrightarrow> y \\<le> z \\<Longrightarrow> x \\<le> z\\<close>\n   \\<open>x \\<le> y \\<Longrightarrow> y \\<le> x \\<Longrightarrow> x = y\\<close>\n   \\<open>x \\<le> y \\<or> y \\<le> x\\<close>\n   for x y z :: \\<open>'a :: linorder list\\<close>\n    by (auto simp: less_list_def less_eq_list_def List.lexordp_def\n    lexordp_conv_lexord lexordp_into_lexordp_eq lexordp_antisym\n    antisym_def lexordp_eq_refl lexordp_eq_linear intro: lexordp_eq_trans\n    dest: lexordp_eq_antisym)\nqed\n\nend\n\n\nlemma term_order_rel'_alt_def_lexord:\n    \\<open>term_order_rel' x y = ord_class.lexordp x y\\<close> and\n  term_order_rel'_alt_def:\n    \\<open>term_order_rel' x y \\<longleftrightarrow> x < y\\<close>\nproof -\n  show\n    \\<open>term_order_rel' x y = ord_class.lexordp x y\\<close>\n    \\<open>term_order_rel' x y \\<longleftrightarrow> x < y\\<close>\n    unfolding less_than_char_of_char[symmetric, abs_def]\n    by (auto simp: lexordp_conv_lexord less_eq_list_def\n         less_list_def lexordp_def var_order_rel_def\n         rel2p_def term_order_rel_alt_def p2rel_def)\nqed\n\nlemma list_rel_list_rel_order_iff:\n  assumes \\<open>(a, b) \\<in> \\<langle>string_rel\\<rangle>list_rel\\<close> \\<open>(a', b') \\<in> \\<langle>string_rel\\<rangle>list_rel\\<close>\n  shows \\<open>a < a' \\<longleftrightarrow> b < b'\\<close>\nproof\n  have H: \\<open>(a, b) \\<in> \\<langle>string_rel\\<rangle>list_rel \\<Longrightarrow>\n       (a, cs) \\<in> \\<langle>string_rel\\<rangle>list_rel \\<Longrightarrow> b = cs\\<close> for cs\n     using single_valued_monom_rel' IS_RIGHT_UNIQUE_string_rel\n     unfolding string2_rel_def\n     by (subst (asm)list_rel_sv_iff[symmetric])\n       (auto simp: single_valued_def)\n  assume \\<open>a < a'\\<close>\n  then consider\n    u u' where \\<open>a' = a @ u # u'\\<close> |\n    u aa v w aaa where \\<open>a = u @ aa # v\\<close> \\<open>a' = u @ aaa # w\\<close> \\<open>aa < aaa\\<close>\n    by (subst (asm) less_list_def)\n     (auto simp: lexord_def List.lexordp_def\n      list_rel_append1 list_rel_split_right_iff)\n  then show \\<open>b < b'\\<close>\n  proof cases\n    case 1\n    then show \\<open>b < b'\\<close>\n      using assms\n      by (subst less_list_def)\n        (auto simp: lexord_def List.lexordp_def\n        list_rel_append1 list_rel_split_right_iff dest: H)\n  next\n    case 2\n    then obtain u' aa' v' w' aaa' where\n       \\<open>b = u' @ aa' # v'\\<close> \\<open>b' = u' @ aaa' # w'\\<close>\n       \\<open>(aa, aa') \\<in> string_rel\\<close>\n       \\<open>(aaa, aaa') \\<in> string_rel\\<close>\n      using assms\n      by (smt list_rel_append1 list_rel_split_right_iff single_valued_def single_valued_monom_rel)\n    with \\<open>aa < aaa\\<close> have \\<open>aa' < aaa'\\<close>\n      by (auto simp: string_rel_def less_literal.rep_eq less_list_def\n        lexordp_conv_lexord lexordp_def char.lexordp_conv_lexord\n          simp flip: less_char_def PAC_Polynomials_Term.less_char_def)\n    then show \\<open>b < b'\\<close>\n      using \\<open>b = u' @ aa' # v'\\<close> \\<open>b' = u' @ aaa' # w'\\<close>\n      by (subst less_list_def)\n        (fastforce simp: lexord_def List.lexordp_def\n        list_rel_append1 list_rel_split_right_iff)\n  qed\nnext\n  have H: \\<open>(a, b) \\<in> \\<langle>string_rel\\<rangle>list_rel \\<Longrightarrow>\n       (a', b) \\<in> \\<langle>string_rel\\<rangle>list_rel \\<Longrightarrow> a = a'\\<close> for a a' b\n     using single_valued_monom_rel'\n     by (auto simp: single_valued_def IS_LEFT_UNIQUE_def\n       simp flip: inv_list_rel_eq)\n  assume \\<open>b < b'\\<close>\n  then consider\n    u u' where \\<open>b' = b @ u # u'\\<close> |\n    u aa v w aaa where \\<open>b = u @ aa # v\\<close> \\<open>b' = u @ aaa # w\\<close> \\<open>aa < aaa\\<close>\n    by (subst (asm) less_list_def)\n     (auto simp: lexord_def List.lexordp_def\n      list_rel_append1 list_rel_split_right_iff)\n  then show \\<open>a < a'\\<close>\n  proof cases\n    case 1\n    then show \\<open>a < a'\\<close>\n      using assms\n      by (subst less_list_def)\n        (auto simp: lexord_def List.lexordp_def\n        list_rel_append2 list_rel_split_left_iff dest: H)\n  next\n    case 2\n    then obtain u' aa' v' w' aaa' where\n       \\<open>a = u' @ aa' # v'\\<close> \\<open>a' = u' @ aaa' # w'\\<close>\n       \\<open>(aa', aa) \\<in> string_rel\\<close>\n       \\<open>(aaa', aaa) \\<in> string_rel\\<close>\n      using assms\n      by (auto simp: lexord_def List.lexordp_def\n        list_rel_append2 list_rel_split_left_iff dest: H)\n    with \\<open>aa < aaa\\<close> have \\<open>aa' < aaa'\\<close>\n      by (auto simp: string_rel_def less_literal.rep_eq less_list_def\n        lexordp_conv_lexord lexordp_def char.lexordp_conv_lexord\n          simp flip: less_char_def PAC_Polynomials_Term.less_char_def)\n    then show \\<open>a < a'\\<close>\n      using \\<open>a = u' @ aa' # v'\\<close> \\<open>a' = u' @ aaa' # w'\\<close>\n      by (subst less_list_def)\n        (fastforce simp: lexord_def List.lexordp_def\n        list_rel_append1 list_rel_split_right_iff)\n  qed\nqed\n\n\nlemma string_rel_le[sepref_import_param]:\n  shows \\<open>((<), (<)) \\<in> \\<langle>string_rel\\<rangle>list_rel \\<rightarrow>  \\<langle>string_rel\\<rangle>list_rel \\<rightarrow> bool_rel\\<close>\n  by (auto intro!: fun_relI simp: list_rel_list_rel_order_iff)\n\n(* TODO Move *)\nlemma [sepref_import_param]:\n  assumes \\<open>CONSTRAINT IS_LEFT_UNIQUE R\\<close>  \\<open>CONSTRAINT IS_RIGHT_UNIQUE R\\<close>\n  shows \\<open>(remove1, remove1) \\<in> R \\<rightarrow> \\<langle>R\\<rangle>list_rel \\<rightarrow> \\<langle>R\\<rangle>list_rel\\<close>\n  apply (intro fun_relI)\n  subgoal premises p for x y xs ys\n    using p(2) p(1) assms\n    by (induction xs ys rule: list_rel_induct)\n      (auto simp: IS_LEFT_UNIQUE_def single_valued_def)\n  done\n\ninstantiation pac_step :: (heap, heap, heap) heap\nbegin\n\ninstance\nproof standard\n  obtain f :: \\<open>'a \\<Rightarrow> nat\\<close> where\n    f: \\<open>inj f\\<close>\n    by blast\n  obtain g :: \\<open>nat \\<times> nat \\<times> nat \\<times> nat \\<times> nat \\<Rightarrow> nat\\<close> where\n    g: \\<open>inj g\\<close>\n    by blast\n  obtain h :: \\<open>'b \\<Rightarrow> nat\\<close> where\n    h: \\<open>inj h\\<close>\n    by blast\n  obtain i :: \\<open>'c \\<Rightarrow> nat\\<close> where\n    i: \\<open>inj i\\<close>\n    by blast\n  have [iff]: \\<open>g a = g b \\<longleftrightarrow> a = b\\<close>\\<open>h a'' = h b'' \\<longleftrightarrow> a'' = b''\\<close>  \\<open>f a' = f b' \\<longleftrightarrow> a' = b'\\<close>\n    \\<open>i a''' = i b''' \\<longleftrightarrow> a''' = b'''\\<close>  for a b a' b' a'' b'' a''' b'''\n    using f g h i unfolding inj_def by blast+\n  let ?f = \\<open>\\<lambda>x :: ('a, 'b, 'c) pac_step.\n     g (case x of\n        Add a b c d \\<Rightarrow>     (0, i a,  i b,  i c, f d)\n      | Del a  \\<Rightarrow>          (1, i a,    0,   0,   0)\n      | Mult a b c d \\<Rightarrow>    (2, i a, f b, i c, f d)\n      | Extension a b c \\<Rightarrow> (3, i a, f c, 0, h b))\\<close>\n   have \\<open>inj ?f\\<close>\n     apply (auto simp: inj_def)\n     apply (case_tac x; case_tac y)\n     apply auto\n     done\n   then show \\<open>\\<exists>f :: ('a, 'b, 'c) pac_step \\<Rightarrow> nat. inj f\\<close>\n     by blast\nqed\n\nend\n\nend", "meta": {"author": "zabihullah331", "repo": "barakzai", "sha": "793257c1d71ec75a299fc6b5843af756ead2afb0", "save_path": "github-repos/isabelle/zabihullah331-barakzai", "path": "github-repos/isabelle/zabihullah331-barakzai/barakzai-793257c1d71ec75a299fc6b5843af756ead2afb0/thys/PAC_Checker/PAC_Checker_Relation.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5117166047041654, "lm_q2_score": 0.5544704649604274, "lm_q1q2_score": 0.2837317437382898}}
{"text": "(* \n   Title: Psi-calculi   \n   Author/Maintainer: Jesper Bengtson (jebe@itu.dk), 2012\n*)\ntheory Weakening\n  imports Weak_Bisimulation\nbegin\n\nlocale weak = env + \n  assumes weaken: \"\\<Psi> \\<hookrightarrow> \\<Psi> \\<otimes> \\<Psi>'\"\nbegin\n\nlemma entWeaken:\n  fixes \\<Psi> :: 'b\n  and   \\<phi> :: 'c\n\n  assumes \"\\<Psi> \\<turnstile> \\<phi>\"\n\n  shows \"\\<Psi> \\<otimes> \\<Psi>' \\<turnstile> \\<phi>\"\nusing assms weaken\nby(auto simp add: AssertionStatImp_def)\n\nlemma assertWeaken:\n  fixes \\<Psi>  :: 'b\n  and   \\<Psi>' :: 'b\n\n  shows \"\\<Psi> \\<hookrightarrow> \\<Psi> \\<otimes> \\<Psi>'\"\nby(auto simp add: AssertionStatImp_def entWeaken)\n\nlemma frameWeaken:\n  fixes F :: \"'b frame\"\n  and   G :: \"'b frame\"\n\n  shows \"F \\<hookrightarrow>\\<^sub>F F \\<otimes>\\<^sub>F G\"\nproof -\n  obtain A\\<^sub>F \\<Psi>\\<^sub>F where FrF: \"F = \\<langle>A\\<^sub>F, \\<Psi>\\<^sub>F\\<rangle>\" and \"A\\<^sub>F \\<sharp>* F\" and  \"A\\<^sub>F \\<sharp>* G\"\n    by(rule_tac F=F and C=\"(F, G)\" in freshFrame) auto\n  obtain A\\<^sub>G \\<Psi>\\<^sub>G where FrG: \"G = \\<langle>A\\<^sub>G, \\<Psi>\\<^sub>G\\<rangle>\" and \"A\\<^sub>G \\<sharp>* F\" and  \"A\\<^sub>G \\<sharp>* G\" and \"A\\<^sub>G \\<sharp>* A\\<^sub>F\" and \"A\\<^sub>G \\<sharp>* \\<Psi>\\<^sub>F\"\n    by(rule_tac F=G and C=\"(F, G, A\\<^sub>F, \\<Psi>\\<^sub>F)\" in freshFrame) auto\n  from FrG `A\\<^sub>F \\<sharp>* G` `A\\<^sub>G \\<sharp>* A\\<^sub>F` have \"A\\<^sub>F \\<sharp>* \\<Psi>\\<^sub>G\" by auto\n  have \"\\<Psi>\\<^sub>F \\<hookrightarrow> \\<Psi>\\<^sub>F \\<otimes> \\<Psi>\\<^sub>G\" by(rule weaken)\n  hence \"\\<langle>A\\<^sub>G, \\<Psi>\\<^sub>F\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>G, \\<Psi>\\<^sub>F \\<otimes> \\<Psi>\\<^sub>G\\<rangle>\" by(rule_tac frameImpResChainPres) auto\n  with `A\\<^sub>G \\<sharp>* \\<Psi>\\<^sub>F` have \"\\<langle>\\<epsilon>, \\<Psi>\\<^sub>F\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>G, \\<Psi>\\<^sub>F \\<otimes> \\<Psi>\\<^sub>G\\<rangle>\" using frameResFreshChain\n    by(rule_tac FrameStatImpTrans) (auto simp add: FrameStatEq_def)\n  with FrF FrG `A\\<^sub>G \\<sharp>* A\\<^sub>F` `A\\<^sub>G \\<sharp>* \\<Psi>\\<^sub>F` `A\\<^sub>F \\<sharp>* \\<Psi>\\<^sub>G` show ?thesis\n    by(force simp add: frameChainAppend intro: frameImpResChainPres)\nqed\n\nlemma unitAssertWeaken:\n  fixes \\<Psi> :: 'b\n\n  shows \"\\<one> \\<hookrightarrow> \\<Psi>\"\nproof -\n  have \"\\<one> \\<hookrightarrow> \\<one> \\<otimes> \\<Psi>\" by(rule assertWeaken)\n  moreover have \"\\<one> \\<otimes> \\<Psi> \\<hookrightarrow> \\<Psi>\" by(metis Identity AssertionStatEq_def Commutativity AssertionStatEqTrans)\n  ultimately show ?thesis by(rule AssertionStatImpTrans)\nqed\n\nlemma unitFrameWeaken:\n  fixes F :: \"'b frame\"\n\n  shows \"\\<langle>\\<epsilon>, \\<one>\\<rangle> \\<hookrightarrow>\\<^sub>F F\"\nproof -\n  have \"\\<langle>\\<epsilon>, \\<one>\\<rangle> \\<hookrightarrow>\\<^sub>F ((\\<langle>\\<epsilon>, \\<one>\\<rangle>) \\<otimes>\\<^sub>F F)\" by(rule frameWeaken)\n  moreover obtain A\\<^sub>F \\<Psi>\\<^sub>F where FrF: \"F = \\<langle>A\\<^sub>F, \\<Psi>\\<^sub>F\\<rangle>\"\n    by(rule_tac F=F and C=\"()\" in freshFrame) auto\n  hence \"(\\<langle>\\<epsilon>, \\<one>\\<rangle>) \\<otimes>\\<^sub>F F \\<simeq>\\<^sub>F F\" \n    by simp (metis frameIntIdentity frameIntCommutativity FrameStatEqTrans FrameStatEqSym)\n  ultimately show ?thesis by(metis FrameStatImpTrans FrameStatEq_def)\nqed\n\nlemma insertAssertionWeaken:\n  fixes F :: \"'b frame\"\n  and   \\<Psi> :: 'b\n\n  shows \"\\<langle>\\<epsilon>, \\<Psi>\\<rangle> \\<hookrightarrow>\\<^sub>F insertAssertion F \\<Psi>\"\nproof -\n  have \"\\<langle>\\<epsilon>, \\<Psi>\\<rangle> \\<hookrightarrow>\\<^sub>F (\\<langle>\\<epsilon>, \\<Psi>\\<rangle>) \\<otimes>\\<^sub>F F\" by(rule frameWeaken)\n  thus ?thesis by simp\nqed\n\nlemma frameImpStatEq:\n  fixes A\\<^sub>F  :: \"name list\"\n  and   \\<Psi>  :: 'b\n  and   \\<Psi>' :: 'b\n  and   \\<phi>  :: 'c\n\n  assumes \"(\\<langle>A\\<^sub>F, \\<Psi>\\<rangle>) \\<turnstile>\\<^sub>F \\<phi>\"\n  and     \"\\<Psi> \\<simeq> \\<Psi>'\"\n\n  shows \"(\\<langle>A\\<^sub>F, \\<Psi>'\\<rangle>) \\<turnstile>\\<^sub>F \\<phi>\"\nproof -\n  obtain p::\"name prm\" where \"(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<phi>\" and \"(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<Psi>\" and \"(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<Psi>'\"\n                         and \"distinctPerm p\" and S: \"set p \\<subseteq> set A\\<^sub>F \\<times> set(p \\<bullet> A\\<^sub>F)\"\n    by(rule_tac c=\"(\\<phi>, \\<Psi>, \\<Psi>')\" in name_list_avoiding) auto\n  from `(\\<langle>A\\<^sub>F, \\<Psi>\\<rangle>) \\<turnstile>\\<^sub>F \\<phi>` `(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<Psi>` S have \"(\\<langle>(p \\<bullet> A\\<^sub>F), p \\<bullet> \\<Psi>\\<rangle>) \\<turnstile>\\<^sub>F \\<phi>\" by(simp add: frameChainAlpha)\n  hence \"(p \\<bullet> \\<Psi>) \\<turnstile> \\<phi>\" using `(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<phi>` by(rule frameImpE)\n  moreover from `\\<Psi> \\<simeq> \\<Psi>'` have \"(p \\<bullet> \\<Psi>) \\<simeq> (p \\<bullet> \\<Psi>')\" by(rule AssertionStatEqClosed)\n  ultimately have \"(p \\<bullet> \\<Psi>') \\<turnstile> \\<phi>\" by(simp add: AssertionStatEq_def AssertionStatImp_def)\n  hence \"(\\<langle>(p \\<bullet> A\\<^sub>F), p \\<bullet> \\<Psi>'\\<rangle>) \\<turnstile>\\<^sub>F \\<phi>\" using `(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<phi>` \n    by(rule_tac frameImpI) auto\n  with `(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<Psi>'` S show ?thesis by(simp add: frameChainAlpha)\nqed\n\n\n\n  assumes \"\\<Psi> \\<rhd> P \\<longmapsto>\\<tau> \\<prec> P'\"\n\n  shows \"insertAssertion (extractFrame P) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P') \\<Psi>\"\nproof(auto simp add: FrameStatImp_def)\n  fix \\<phi> :: 'c\n  obtain A\\<^sub>P \\<Psi>\\<^sub>P where FrP: \"extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" and \"A\\<^sub>P \\<sharp>* P\" and \"A\\<^sub>P \\<sharp>* \\<phi>\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\" and \"distinct A\\<^sub>P\" \n    by(rule_tac C=\"(P, \\<phi>, \\<Psi>)\" in freshFrame) auto\n  with `\\<Psi> \\<rhd> P \\<longmapsto>\\<tau> \\<prec> P'` obtain \\<Psi>' A\\<^sub>P' \\<Psi>\\<^sub>P' where FrP': \"extractFrame P' = \\<langle>A\\<^sub>P', \\<Psi>\\<^sub>P'\\<rangle>\" and \"\\<Psi>\\<^sub>P \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>P'\" \n                                              and \"A\\<^sub>P' \\<sharp>* P'\" and \"A\\<^sub>P' \\<sharp>* \\<phi>\"  and \"A\\<^sub>P' \\<sharp>* \\<Psi>\" \n    by(rule_tac C=\"(\\<Psi>, \\<phi>)\" in expandTauFrame) auto\n  assume \"insertAssertion (extractFrame P) \\<Psi> \\<turnstile>\\<^sub>F \\<phi>\"\n  with FrP `A\\<^sub>P \\<sharp>* \\<phi>` `A\\<^sub>P \\<sharp>* \\<Psi>` have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<turnstile> \\<phi>\" by(auto dest: frameImpE)\n  hence \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>' \\<turnstile> \\<phi>\" by(rule entWeaken)\n  hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P' \\<turnstile> \\<phi>\" using `\\<Psi>\\<^sub>P \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>P'`\n    by(rule_tac statEqEnt, auto) (metis Associativity compositionSym AssertionStatEqTrans AssertionStatEqSym Commutativity)\n  with `A\\<^sub>P' \\<sharp>* \\<phi>` `A\\<^sub>P' \\<sharp>* \\<Psi>` FrP' show \"insertAssertion (extractFrame P') \\<Psi> \\<turnstile>\\<^sub>F \\<phi>\"\n    by(force intro: frameImpI)\nqed\n\nlemma weakenTransition:\n  fixes \\<Psi>  :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   Rs :: \"('a, 'b, 'c) residual\"\n  and   \\<Psi>' :: 'b\n\n  assumes \"\\<Psi> \\<rhd> P \\<longmapsto> Rs\"\n\n  shows \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<longmapsto> Rs\"\nusing assms\nproof(nominal_induct avoiding: \\<Psi>' rule: semantics.strong_induct)\n  case(cInput \\<Psi> M K xvec N Tvec P \\<Psi>')\n  from `\\<Psi> \\<turnstile> M \\<leftrightarrow> K` have \"\\<Psi> \\<otimes> \\<Psi>' \\<turnstile> M \\<leftrightarrow> K\" by(rule entWeaken)\n  thus ?case using `distinct xvec` `set xvec \\<subseteq> (supp N)` `length xvec = length Tvec` \n    by(rule Input)\nnext\n  case(Output \\<Psi> M K N P \\<Psi>')\n  from `\\<Psi> \\<turnstile> M \\<leftrightarrow> K` have \"\\<Psi> \\<otimes> \\<Psi>' \\<turnstile> M \\<leftrightarrow> K\" by(rule entWeaken)\n  thus ?case by(rule semantics.Output)\nnext\n  case(Case \\<Psi> P Rs \\<phi> Cs \\<Psi>')\n  have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<longmapsto> Rs\" by(rule Case)\n  moreover note `(\\<phi>, P) mem Cs`\n  moreover from `\\<Psi> \\<turnstile> \\<phi>` have \"\\<Psi> \\<otimes> \\<Psi>' \\<turnstile> \\<phi>\" by(rule entWeaken)\n  ultimately show ?case using `guarded P`\n    by(rule semantics.Case)\nnext\n  case(cPar1 \\<Psi> \\<Psi>\\<^sub>Q P \\<alpha> P' Q A\\<^sub>Q \\<Psi>')\n  have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>' \\<rhd> P \\<longmapsto>\\<alpha> \\<prec> P'\" by(rule cPar1)\n  hence \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<longmapsto>\\<alpha> \\<prec> P'\"\n    by(metis statEqTransition Composition Associativity Commutativity AssertionStatEqTrans)\n  thus ?case using `extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>` `bn \\<alpha> \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>'` `A\\<^sub>Q \\<sharp>* P` `A\\<^sub>Q \\<sharp>* \\<alpha>`\n    by(rule_tac Par1) auto\nnext\n  case(cPar2 \\<Psi> \\<Psi>\\<^sub>P Q \\<alpha> Q' P A\\<^sub>P \\<Psi>')\n  have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>' \\<rhd> Q \\<longmapsto>\\<alpha> \\<prec> Q'\" by(rule cPar2)\n  hence \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<longmapsto>\\<alpha> \\<prec> Q'\"\n    by(metis statEqTransition Composition Associativity Commutativity AssertionStatEqTrans)\n  thus ?case using `extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>` `bn \\<alpha> \\<sharp>* P` `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* \\<Psi>'` `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>P \\<sharp>* \\<alpha>`\n    by(rule_tac Par2) auto\nnext\n  case(cComm1 \\<Psi> \\<Psi>\\<^sub>Q P M N P' A\\<^sub>P \\<Psi>\\<^sub>P Q K xvec Q' A\\<^sub>Q \\<Psi>')\n  have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>' \\<rhd> P \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> P'\" by(rule cComm1)\n  hence \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> P'\"\n    by(metis statEqTransition Composition Associativity Commutativity AssertionStatEqTrans)\n  moreover note `extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>`\n  moreover have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>' \\<rhd> Q \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'\" by(rule cComm1)\n  hence \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'\"\n    by(metis statEqTransition Composition Associativity Commutativity AssertionStatEqTrans)\n  moreover note `extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>`\n  moreover from `\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M \\<leftrightarrow> K` have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>' \\<turnstile> M \\<leftrightarrow> K\" by(rule entWeaken)\n  hence \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M \\<leftrightarrow> K\" by(metis statEqEnt Composition Associativity Commutativity AssertionStatEqTrans)\n  ultimately show ?case using `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* \\<Psi>'` `A\\<^sub>P \\<sharp>* P` `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>P \\<sharp>* M` `A\\<^sub>P \\<sharp>* A\\<^sub>Q`\n                              `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>'` `A\\<^sub>Q \\<sharp>* P` `A\\<^sub>Q \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* K` `xvec \\<sharp>* P`\n    by(rule_tac Comm1) (assumption | auto)+\nnext\n  case(cComm2 \\<Psi> \\<Psi>\\<^sub>Q P M xvec N P' A\\<^sub>P \\<Psi>\\<^sub>P Q K Q' A\\<^sub>Q \\<Psi>')\n  have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>' \\<rhd> P \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\" by(rule cComm2)\n  hence \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n    by(metis statEqTransition Composition Associativity Commutativity AssertionStatEqTrans)\n  moreover note `extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>`\n  moreover have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>' \\<rhd> Q \\<longmapsto>K\\<lparr>N\\<rparr> \\<prec> Q'\" by(rule cComm2)\n  hence \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<longmapsto>K\\<lparr>N\\<rparr> \\<prec> Q'\"\n    by(metis statEqTransition Composition Associativity Commutativity AssertionStatEqTrans)\n  moreover note `extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>`\n  moreover from `\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M \\<leftrightarrow> K` have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>' \\<turnstile> M \\<leftrightarrow> K\" by(rule entWeaken)\n  hence \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M \\<leftrightarrow> K\" by(metis statEqEnt Composition Associativity Commutativity AssertionStatEqTrans)\n  ultimately show ?case using `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* \\<Psi>'` `A\\<^sub>P \\<sharp>* P` `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>P \\<sharp>* M` `A\\<^sub>P \\<sharp>* A\\<^sub>Q`\n                              `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>'` `A\\<^sub>Q \\<sharp>* P` `A\\<^sub>Q \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* K` `xvec \\<sharp>* Q`\n    by(rule_tac Comm2) (assumption | auto)+\nnext\n  case(cOpen \\<Psi> P M xvec yvec N P' x \\<Psi>')\n  have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<longmapsto>M\\<lparr>\\<nu>*(xvec@yvec)\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\" by(rule cOpen)\n  thus ?case using `x \\<in> supp N` `x \\<sharp> \\<Psi>` `x \\<sharp> \\<Psi>'` `x \\<sharp> M` `x \\<sharp> xvec` `x \\<sharp> yvec`\n    by(rule_tac Open) auto\nnext  \n  case(cScope \\<Psi> P \\<alpha> P' x \\<Psi>')\n  have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<longmapsto>\\<alpha> \\<prec> P'\" by(rule cScope)\n  thus ?case using `x \\<sharp> \\<Psi>` `x \\<sharp> \\<Psi>'` `x \\<sharp> \\<alpha>` by(rule_tac Scope) auto\nnext\n  case(Bang \\<Psi> P Rs \\<Psi>')\n  have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<parallel> !P\\<longmapsto> Rs\" by(rule Bang)\n  thus ?case using `guarded P` by(rule semantics.Bang)\nqed\n\nend\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Psi_Calculi/Weakening.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5544704502361149, "lm_q2_score": 0.5117166047041652, "lm_q1q2_score": 0.2837317362036145}}
{"text": "theory TwoColouringEx\n  imports Rule FOLoG\nbegin\n\nabbreviation cast_ruleschema_rule :: \"ruleschema \\<Rightarrow> rule\" where\n\"cast_ruleschema_rule rs \\<equiv> (rs, cond.T)\"\n\ndeclare [[coercion_enabled]]\ndeclare [[coercion cast_ruleschema_rule]]\n\n\n\ndefinition init :: ruleschema where\n\"init = \\<lparr>rule_ty = Mapping [(0,Lty)],\n         rule_lhs = \\<lparr>nodes = Mapping [(1, \\<lparr>node_mark = RuleMarkNode_None, node_label= Var 0 # [], node_rooted=False\\<rparr>)]\n                   ,edges = Mapping.empty\\<rparr>,\n         rule_rhs = \\<lparr>nodes = Mapping [(1, \\<lparr>node_mark = RuleMarkNode_Red, node_label= Var 0 # [] , node_rooted=False\\<rparr>)]\n               ,edges = Mapping.empty\\<rparr>,\n         rule_interf = {1}\\<rparr>\"\n\ndefinition unmark :: rule where\n\"unmark = (\\<lparr>rule_ty = Mapping [(0, Lty)],\n           rule_lhs = \\<lparr>nodes = Mapping [(1, \\<lparr>node_mark = RuleMarkNode_Any, node_label= Var 0 # [] , node_rooted=False\\<rparr>)]\n                 ,edges = Mapping.empty\\<rparr>,\n           rule_rhs = \\<lparr>nodes = Mapping[(1, \\<lparr>node_mark = RuleMarkNode_None, node_label= Var 0 # [], node_rooted=False\\<rparr>)]\n                 ,edges = Mapping.empty\\<rparr>,\n           rule_interf = {1}\\<rparr>, cond.T)\"\n\ndefinition col_blue_1 :: ruleschema where\n\"col_blue_1 = \\<lparr>rule_ty = Mapping [(0, Lty), (1, Lty), (2, Lty)]\n            ,rule_lhs = \\<lparr>nodes = Mapping\n                                 [(1, \\<lparr>node_mark = RuleMarkNode_Red , node_label = [Var 0], node_rooted = False\\<rparr>)\n                                 ,(2, \\<lparr>node_mark = RuleMarkNode_None, node_label = [Var 1], node_rooted = False\\<rparr>)]\n                        ,edges = Mapping [(1, \\<lparr>edge_src = 1, edge_trg = 2, edge_mark = RuleMarkEdge_None, edge_label = [Var 2]\\<rparr>)]\\<rparr>\n            ,rule_rhs = \\<lparr>nodes = Mapping\n                                 [(1, \\<lparr>node_mark = RuleMarkNode_Red , node_label = [Var 0], node_rooted = False\\<rparr>)\n                                 ,(2, \\<lparr>node_mark = RuleMarkNode_Blue, node_label = [Var 1], node_rooted = False\\<rparr>)]\n                        ,edges = Mapping [(1, \\<lparr>edge_src = 1, edge_trg = 2, edge_mark = RuleMarkEdge_None, edge_label = [Var 2]\\<rparr>)]\\<rparr>\n            ,rule_interf = {1,2}\\<rparr>\"\n\ndefinition col_blue_2 :: ruleschema where\n\"col_blue_2 = \\<lparr>rule_ty = Mapping [(0, Lty), (1, Lty), (2, Lty)]\n            ,rule_lhs = \\<lparr>nodes = Mapping\n                                 [(1, \\<lparr>node_mark = RuleMarkNode_Red , node_label = [Var 0], node_rooted = False\\<rparr>)\n                                 ,(2, \\<lparr>node_mark = RuleMarkNode_None, node_label = [Var 1], node_rooted = False\\<rparr>)]\n                        ,edges = Mapping [(1, \\<lparr>edge_src = 2, edge_trg = 1, edge_mark = RuleMarkEdge_None, edge_label = [Var 2]\\<rparr>)]\\<rparr>\n            ,rule_rhs = \\<lparr>nodes = Mapping\n                                 [(1, \\<lparr>node_mark = RuleMarkNode_Red , node_label = [Var 0], node_rooted = False\\<rparr>)\n                                 ,(2, \\<lparr>node_mark = RuleMarkNode_Blue, node_label = [Var 1], node_rooted = False\\<rparr>)]\n                        ,edges = Mapping [(1, \\<lparr>edge_src = 2, edge_trg = 1, edge_mark = RuleMarkEdge_None, edge_label = [Var 2]\\<rparr>)]\\<rparr>\n            ,rule_interf = {1,2}\\<rparr>\"\n             \ndefinition col_red_1 :: ruleschema where\n\"col_red_1 = \\<lparr>rule_ty = Mapping [(0, Lty), (1, Lty), (2, Lty)]\n           ,rule_lhs = \\<lparr>nodes = Mapping\n                                [(1, \\<lparr>node_mark = RuleMarkNode_Blue , node_label = [Var 0], node_rooted = False\\<rparr>)\n                                ,(2, \\<lparr>node_mark = RuleMarkNode_None, node_label = [Var 1], node_rooted = False\\<rparr>)]\n                       ,edges = Mapping [(1, \\<lparr>edge_src = 1, edge_trg = 2, edge_mark = RuleMarkEdge_None, edge_label = [Var 2]\\<rparr>)]\\<rparr>\n           ,rule_rhs = \\<lparr>nodes = Mapping \n                                [(1, \\<lparr>node_mark = RuleMarkNode_Blue , node_label = [Var 0], node_rooted = False\\<rparr>)\n                                ,(2, \\<lparr>node_mark = RuleMarkNode_Red, node_label = [Var 1], node_rooted = False\\<rparr>)]\n                       ,edges = Mapping [(1, \\<lparr>edge_src = 1, edge_trg = 2, edge_mark = RuleMarkEdge_None, edge_label = [Var 2]\\<rparr>)]\\<rparr>\n           ,rule_interf = {1,2}\\<rparr>\"\n\n             \ndefinition col_red_2 :: ruleschema where\n\"col_red_2 = \\<lparr>rule_ty = Mapping [(0, Lty), (1, Lty), (2, Lty)]\n           ,rule_lhs = \\<lparr>nodes = Mapping\n                                [(1, \\<lparr>node_mark = RuleMarkNode_Blue , node_label = [Var 0], node_rooted = False\\<rparr>)\n                                ,(2, \\<lparr>node_mark = RuleMarkNode_None, node_label = [Var 1], node_rooted = False\\<rparr>)]\n                       ,edges = Mapping [(1, \\<lparr>edge_src = 2, edge_trg = 1, edge_mark = RuleMarkEdge_None, edge_label = [Var 2]\\<rparr>)]\\<rparr>\n           ,rule_rhs = \\<lparr>nodes = Mapping \n                                [(1, \\<lparr>node_mark = RuleMarkNode_Blue , node_label = [Var 0], node_rooted = False\\<rparr>)\n                                ,(2, \\<lparr>node_mark = RuleMarkNode_Red, node_label = [Var 1], node_rooted = False\\<rparr>)]\n                       ,edges = Mapping [(1, \\<lparr>edge_src = 2, edge_trg = 1, edge_mark = RuleMarkEdge_None, edge_label = [Var 2]\\<rparr>)]\\<rparr>\n           ,rule_interf = {1,2}\\<rparr>\"\n\ndefinition ill_blue :: ruleschema where\n\"ill_blue = \\<lparr>rule_ty = Mapping [(0, Lty), (1, Lty), (2, Lty)]\n            ,rule_lhs = \\<lparr>nodes = Mapping\n                                 [(1, \\<lparr>node_mark = RuleMarkNode_Blue, node_label = [Var 0], node_rooted = False\\<rparr>)\n                                 ,(2, \\<lparr>node_mark = RuleMarkNode_Blue, node_label = [Var 1], node_rooted = False\\<rparr>)]\n                        ,edges = Mapping [(1, \\<lparr>edge_src = 1, edge_trg = 2, edge_mark = RuleMarkEdge_None, edge_label = [Var 2]\\<rparr>)]\\<rparr>\n            ,rule_rhs = \\<lparr>nodes = Mapping\n                                 [(1, \\<lparr>node_mark = RuleMarkNode_Blue, node_label = [Var 0], node_rooted = False\\<rparr>)\n                                 ,(2, \\<lparr>node_mark = RuleMarkNode_Blue, node_label = [Var 1], node_rooted = False\\<rparr>)]\n                        ,edges = Mapping [(1, \\<lparr>edge_src = 1, edge_trg = 2, edge_mark = RuleMarkEdge_None, edge_label = [Var 2]\\<rparr>)]\\<rparr>\n            ,rule_interf = {1,2}\\<rparr>\"\n\ndefinition ill_red :: ruleschema where\n\"ill_red = \\<lparr>rule_ty = Mapping [(0, Lty), (1, Lty), (2, Lty)]\n           ,rule_lhs = \\<lparr>nodes = Mapping\n                                [(1, \\<lparr>node_mark = RuleMarkNode_Red, node_label = [Var 0], node_rooted = False\\<rparr>)\n                                ,(2, \\<lparr>node_mark = RuleMarkNode_Red, node_label = [Var 1], node_rooted = False\\<rparr>)]\n                       ,edges = Mapping [(1, \\<lparr>edge_src = 1, edge_trg = 2, edge_mark = RuleMarkEdge_None, edge_label = [Var 2]\\<rparr>)]\\<rparr>\n           ,rule_rhs = \\<lparr>nodes = Mapping\n                                [(1, \\<lparr>node_mark = RuleMarkNode_Red, node_label = [Var 0], node_rooted = False\\<rparr>)\n                                ,(2, \\<lparr>node_mark = RuleMarkNode_Red, node_label = [Var 1], node_rooted = False\\<rparr>)]\n                       ,edges = Mapping [(1, \\<lparr>edge_src = 1, edge_trg = 2, edge_mark = RuleMarkEdge_None, edge_label = [Var 2]\\<rparr>)]\\<rparr>\n           ,rule_interf = {1,2}\\<rparr>\"\n\nlemma \"wf_ruleschema ill_red\"\n  by (simp add: ill_red_def)\n\nlemma \"wf_ruleschema ill_blue\"\n  by (simp add: ill_blue_def)\n\nlemma \"wf_ruleschema col_red\"\n  by (simp add: col_red_def)\n\nlemma \"wf_ruleschema col_blue\"\n  by (simp add: col_blue_def)\n\ndefinition twocolouring :: com where\n\"twocolouring \\<equiv> (RuleApp init ;; RuleSet {col_blue :: rule, col_red:: rule}!)! ;; \n  IF RuleSet {ill_blue :: rule, ill_red :: rule} THEN RuleApp unmark! ELSE Skip\"\n\n\nabbreviation c :: \"form\" where\n\"c == (\\<lceil>\\<forall> 0 : Node\\<rceil> \\<lceil>mark \\<langle>0\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_None \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>0\\<rangle>\\<rceil>) \\<lceil>\\<and>\\<rceil>\n      (\\<lceil>\\<forall> 0 : Edge\\<rceil> \\<lceil>mark \\<langle>0\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>E RuleMarkEdge_None)\"\n\n\nabbreviation d :: form where\n\"d == (\\<lceil>\\<forall> 0 : Node\\<rceil> \\<lceil>mark \\<langle>0\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Red  \\<lceil>\\<or>\\<rceil>\\<lceil>mark \\<langle>0\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Blue) \\<lceil>\\<and>\\<rceil>\n      \\<lceil>\\<not>\\<rceil>(\\<lceil>\\<exists> 0 : Edge\\<rceil> (\\<lceil>src \\<langle>0\\<rangle>\\<rceil> \\<lceil>\\<noteq>\\<rceil> \\<lceil>trg \\<langle>0\\<rangle>\\<rceil>) \\<lceil>\\<and>\\<rceil>\n                     \\<lceil>mark \\<lceil>src \\<langle>0\\<rangle>\\<rceil>\\<rceil> \\<lceil>=\\<rceil> \\<lceil>mark \\<lceil>trg \\<langle>0\\<rangle>\\<rceil>\\<rceil>)\"\n\nabbreviation e :: form where\n\"e == (\\<lceil>\\<forall> 0 : Node\\<rceil> (\\<lceil>mark \\<langle>0\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Red \\<lceil>\\<or>\\<rceil> \\<lceil>mark \\<langle>0\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Blue) \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>0\\<rangle>\\<rceil>) \\<lceil>\\<and>\\<rceil>\n      (\\<lceil>\\<forall> 0 : Edge\\<rceil>  \\<lceil>mark \\<langle>0\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>E RuleMarkEdge_None)\"\n\nabbreviation f :: form where\n\"f == (\\<lceil>\\<forall> 0 : Node\\<rceil> (\\<lceil>mark \\<langle>0\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Red \\<lceil>\\<or>\\<rceil> \\<lceil>mark \\<langle>0\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Blue \\<lceil>\\<or>\\<rceil> \n        \\<lceil>mark \\<langle>0\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_None) \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>0\\<rangle>\\<rceil>) \\<lceil>\\<and>\\<rceil>\n      (\\<lceil>\\<forall> 0 : Edge\\<rceil>  \\<lceil>mark \\<langle>0\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>E RuleMarkEdge_None)\"\n\n\nsection \\<open>SLP proofs\\<close>\n\nlemma \"eval g undefined (Slp f (init:: rule)  \\<lceil>\\<longleftrightarrow>\\<rceil> \n  ((\\<lceil>\\<exists>0: Node\\<rceil> (\\<lceil>\\<forall>1: Node\\<rceil> (\\<langle>1\\<rangle> \\<lceil>=\\<rceil> \\<langle>0\\<rangle> \n    \\<lceil>\\<or>\\<rceil> ((\\<lceil>mark \\<langle>1\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Red \\<lceil>\\<or>\\<rceil> \\<lceil>mark \\<langle>1\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Blue \\<lceil>\\<or>\\<rceil> \\<lceil>mark \\<langle>1\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_None)\\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>1\\<rangle>\\<rceil>)) \n  \\<lceil>\\<and>\\<rceil> \\<lceil>mark \\<langle>0\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Red \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>0\\<rangle>\\<rceil>)) \\<lceil>\\<and>\\<rceil> (\\<lceil>\\<forall>1: Edge\\<rceil> (\\<lceil>mark \\<langle>1\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>E RuleMarkEdge_None))))\"\n  apply code_simp\n  by auto\n\n\nvalue \"Slp f (col_blue_1::rule)\"\nvalue \"Slp f (col_blue_2::rule)\"\nvalue \"Slp f (col_red_1::rule)\" \n(* \nlemma \"eval g undefined ((Slp f (col_blue_1:: rule) \\<lceil>\\<or>\\<rceil> Slp f (col_blue_2:: rule)) \\<lceil>\\<longleftrightarrow>\\<rceil> \n  (Slp f (col_red_1:: rule) \\<lceil>\\<or>\\<rceil>  Slp f (col_red_2:: rule)))\"\n  apply code_simp\n  apply auto\n     apply (smt (z3))\n  apply (smt (z3))\n   apply (smt (z3))\n  by (smt (z3)) *)\n\n\n\n(* \n\nlemma \"eval g undefined (Slp f (col_blue:: rule) \\<lceil>\\<longleftrightarrow>\\<rceil> Slp f (col_red:: rule))\"\n   apply code_simp\n   apply auto\n  oops\n  \n\n\n  oops\n\nlemma \"eval g undefined (((\\<lceil>\\<exists>0: Node\\<rceil> (\\<lceil>\\<exists>1: Node\\<rceil> ((\\<lceil>\\<forall>2: Node\\<rceil> (\\<langle>2\\<rangle> \\<lceil>=\\<rceil> \\<langle>0\\<rangle> \\<lceil>\\<or>\\<rceil> \\<langle>2\\<rangle> \\<lceil>=\\<rceil> \\<langle>1\\<rangle> \\<lceil>\\<or>\\<rceil>\n    ((\\<lceil>mark \\<langle>2\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Red \\<lceil>\\<or>\\<rceil> \\<lceil>mark \\<langle>2\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Blue \\<lceil>\\<or>\\<rceil> \\<lceil>mark \\<langle>2\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_None) \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>2\\<rangle>\\<rceil>)))\n  \\<lceil>\\<and>\\<rceil> \\<lceil>mark \\<langle>0\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Red \\<lceil>\\<and>\\<rceil> \\<lceil>mark \\<langle>1\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Blue \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>0\\<rangle>\\<rceil> \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>1\\<rangle>\\<rceil>\n  \\<lceil>\\<and>\\<rceil> (\\<lceil>\\<exists>3: Edge\\<rceil> ((\\<lceil>src \\<langle>3\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<langle>0\\<rangle> \\<lceil>\\<and>\\<rceil> \\<lceil>trg \\<langle>3\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<langle>1\\<rangle>) \\<lceil>\\<or>\\<rceil> (\\<lceil>src \\<langle>3\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<langle>1\\<rangle> \\<lceil>\\<and>\\<rceil> \\<lceil>trg \\<langle>3\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<langle>0\\<rangle>)) )))) \\<lceil>\\<and>\\<rceil> (\\<lceil>\\<forall>4:Edge\\<rceil> (\\<lceil>mark \\<langle>4\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>E RuleMarkEdge_None)))  \\<lceil>\\<longrightarrow>\\<rceil>  Slp f (col_blue:: rule))\"\n  apply code_simp\n  apply auto\n   apply (erule notE)\n   apply (smt (z3) conv_mark_node.elims mark_eq_node.simps(12) mark_eq_node.simps(15) mark_eq_node.simps(23) mark_eq_node.simps(24) mark_eq_node.simps(26) rulemark_node.distinct(13))\n  apply (erule notE)\n  apply (rule spec)\n  oops  \n\n\n  text \\<open>\n    Slp f col_blue implies rule\n  \\<close>\n*)\nlemma x[simp]:\"mark_eq_node (conv_mark_node HostMarkNode_Red) RuleMarkNode_Red\"\n  by simp\n\n\nlemma xxx: \"\\<And>e. \\<forall>e\\<in>Mapping.keys (edges g).\n            (\\<exists>y. Mapping.lookup (nodes g) (edge_trg (the (Mapping.lookup (edges g) e))) = Some y) \\<and>\n            (\\<exists>y. Mapping.lookup (nodes g) (edge_src (the (Mapping.lookup (edges g) e))) = Some y) \\<Longrightarrow>\n         edge_src (the (Mapping.lookup (edges g) e)) \\<in> Mapping.keys (nodes g) \\<Longrightarrow>\n         edge_trg (the (Mapping.lookup (edges g) e)) \\<in> Mapping.keys (nodes g) \\<Longrightarrow>\n         \\<forall>e\\<in>Mapping.keys (edges g). mark_eq_edge (conv_mark_edge (edge_mark (the (Mapping.lookup (edges g) e)))) RuleMarkEdge_None \\<Longrightarrow>\n         \\<forall>n\\<in>Mapping.keys (nodes g).\n            mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) n)))) RuleMarkNode_Blue \\<longrightarrow>\n            (\\<forall>na\\<in>Mapping.keys (nodes g).\n                mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) na)))) RuleMarkNode_Red \\<longrightarrow>\n                n = na \\<or>\n                na = n \\<or>\n                (\\<exists>nb\\<in>Mapping.keys (nodes g).\n                    nb \\<noteq> na \\<and>\n                    nb \\<noteq> n \\<and>\n                    (\\<not> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) nb)))) RuleMarkNode_Red \\<and>\n                     \\<not> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) nb)))) RuleMarkNode_Blue \\<and>\n                     \\<not> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) nb)))) RuleMarkNode_None \\<or>\n                     node_rooted (the (Mapping.lookup (nodes g) nb)))) \\<or>\n                node_rooted (the (Mapping.lookup (nodes g) na)) \\<or>\n                node_rooted (the (Mapping.lookup (nodes g) n)) \\<or>\n                (\\<forall>e\\<in>Mapping.keys (edges g). edge_src (the (Mapping.lookup (edges g) e)) = n \\<longrightarrow> edge_trg (the (Mapping.lookup (edges g) e)) \\<noteq> na)) \\<Longrightarrow>\n         \\<forall>n\\<in>Mapping.keys (nodes g).\n            \\<forall>na\\<in>Mapping.keys (nodes g).\n               mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) na)))) RuleMarkNode_Blue \\<longrightarrow>\n               mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) n)))) RuleMarkNode_Red \\<longrightarrow>\n               n = na \\<or>\n               na = n \\<or>\n               (\\<exists>nb\\<in>Mapping.keys (nodes g).\n                   nb \\<noteq> n \\<and>\n                   nb \\<noteq> na \\<and>\n                   (\\<not> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) nb)))) RuleMarkNode_Red \\<and>\n                    \\<not> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) nb)))) RuleMarkNode_Blue \\<and>\n                    \\<not> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) nb)))) RuleMarkNode_None \\<or>\n                    node_rooted (the (Mapping.lookup (nodes g) nb)))) \\<or>\n               node_rooted (the (Mapping.lookup (nodes g) n)) \\<or>\n               node_rooted (the (Mapping.lookup (nodes g) na)) \\<or>\n               (\\<forall>e\\<in>Mapping.keys (edges g). edge_src (the (Mapping.lookup (edges g) e)) = n \\<longrightarrow> edge_trg (the (Mapping.lookup (edges g) e)) \\<noteq> na) \\<Longrightarrow>\n         mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) (edge_trg (the (Mapping.lookup (edges g) e))))))) RuleMarkNode_Blue \\<Longrightarrow>\n         mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) (edge_src (the (Mapping.lookup (edges g) e))))))) RuleMarkNode_Red \\<Longrightarrow>\n         \\<forall>n\\<in>Mapping.keys (nodes g).\n            n = edge_src (the (Mapping.lookup (edges g) e)) \\<or>\n            n = edge_trg (the (Mapping.lookup (edges g) e)) \\<or>\n            (mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) n)))) RuleMarkNode_Red \\<or>\n             mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) n)))) RuleMarkNode_Blue \\<or>\n             mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) n)))) RuleMarkNode_None) \\<and>\n            \\<not> node_rooted (the (Mapping.lookup (nodes g) n)) \\<Longrightarrow>\n         \\<not> node_rooted (the (Mapping.lookup (nodes g) (edge_src (the (Mapping.lookup (edges g) e))))) \\<Longrightarrow>\n         \\<not> node_rooted (the (Mapping.lookup (nodes g) (edge_trg (the (Mapping.lookup (edges g) e))))) \\<Longrightarrow> e \\<in> Mapping.keys (edges g) \\<Longrightarrow> False\"\nproof -\n  fix e :: nat\n  assume a1: \"mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) (edge_trg (the (Mapping.lookup (edges g) e))))))) RuleMarkNode_Blue\"\n  assume a2: \"mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) (edge_src (the (Mapping.lookup (edges g) e))))))) RuleMarkNode_Red\"\n  assume a3: \"edge_trg (the (Mapping.lookup (edges g) e)) \\<in> Mapping.keys (nodes g)\"\n  assume a4: \"\\<not> node_rooted (the (Mapping.lookup (nodes g) (edge_src (the (Mapping.lookup (edges g) e)))))\"\n  assume a5: \"\\<not> node_rooted (the (Mapping.lookup (nodes g) (edge_trg (the (Mapping.lookup (edges g) e)))))\"\n  assume a6: \"edge_src (the (Mapping.lookup (edges g) e)) \\<in> Mapping.keys (nodes g)\"\n  assume a7: \"\\<forall>n\\<in>Mapping.keys (nodes g). \\<forall>na\\<in>Mapping.keys (nodes g). mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) na)))) RuleMarkNode_Blue \\<longrightarrow> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) n)))) RuleMarkNode_Red \\<longrightarrow> n = na \\<or> na = n \\<or> (\\<exists>nb\\<in>Mapping.keys (nodes g). nb \\<noteq> n \\<and> nb \\<noteq> na \\<and> (\\<not> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) nb)))) RuleMarkNode_Red \\<and> \\<not> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) nb)))) RuleMarkNode_Blue \\<and> \\<not> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) nb)))) RuleMarkNode_None \\<or> node_rooted (the (Mapping.lookup (nodes g) nb)))) \\<or> node_rooted (the (Mapping.lookup (nodes g) n)) \\<or> node_rooted (the (Mapping.lookup (nodes g) na)) \\<or> (\\<forall>e\\<in>Mapping.keys (edges g). edge_src (the (Mapping.lookup (edges g) e)) = n \\<longrightarrow> edge_trg (the (Mapping.lookup (edges g) e)) \\<noteq> na)\"\n  assume a8: \"\\<forall>n\\<in>Mapping.keys (nodes g). n = edge_src (the (Mapping.lookup (edges g) e)) \\<or> n = edge_trg (the (Mapping.lookup (edges g) e)) \\<or> (mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) n)))) RuleMarkNode_Red \\<or> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) n)))) RuleMarkNode_Blue \\<or> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) n)))) RuleMarkNode_None) \\<and> \\<not> node_rooted (the (Mapping.lookup (nodes g) n))\"\n  assume a9: \"e \\<in> Mapping.keys (edges g)\"\n  obtain nn :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat\" where\n\"\\<forall>x0 x1. (\\<exists>v2. v2 \\<in> Mapping.keys (nodes g) \\<and> v2 \\<noteq> x1 \\<and> v2 \\<noteq> x0 \\<and> (\\<not> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) v2)))) RuleMarkNode_Red \\<and> \\<not> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) v2)))) RuleMarkNode_Blue \\<and> \\<not> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) v2)))) RuleMarkNode_None \\<or> node_rooted (the (Mapping.lookup (nodes g) v2)))) = (nn x0 x1 \\<in> Mapping.keys (nodes g) \\<and> nn x0 x1 \\<noteq> x1 \\<and> nn x0 x1 \\<noteq> x0 \\<and> (\\<not> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) (nn x0 x1))))) RuleMarkNode_Red \\<and> \\<not> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) (nn x0 x1))))) RuleMarkNode_Blue \\<and> \\<not> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) (nn x0 x1))))) RuleMarkNode_None \\<or> node_rooted (the (Mapping.lookup (nodes g) (nn x0 x1)))))\"\n    by moura\n  then have f10: \"\\<forall>n. n \\<notin> Mapping.keys (nodes g) \\<or> (\\<forall>na. (na \\<notin> Mapping.keys (nodes g) \\<or> \\<not> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) na)))) RuleMarkNode_Blue \\<or> \\<not> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) n)))) RuleMarkNode_Red) \\<or> n = na \\<or> na = n \\<or> nn na n \\<in> Mapping.keys (nodes g) \\<and> nn na n \\<noteq> n \\<and> nn na n \\<noteq> na \\<and> (\\<not> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) (nn na n))))) RuleMarkNode_Red \\<and> \\<not> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) (nn na n))))) RuleMarkNode_Blue \\<and> \\<not> mark_eq_node (conv_mark_node (node_mark (the (Mapping.lookup (nodes g) (nn na n))))) RuleMarkNode_None \\<or> node_rooted (the (Mapping.lookup (nodes g) (nn na n)))) \\<or> node_rooted (the (Mapping.lookup (nodes g) n)) \\<or> node_rooted (the (Mapping.lookup (nodes g) na)) \\<or> (\\<forall>nb. (nb \\<notin> Mapping.keys (edges g) \\<or> edge_src (the (Mapping.lookup (edges g) nb)) \\<noteq> n) \\<or> edge_trg (the (Mapping.lookup (edges g) nb)) \\<noteq> na))\"\n    using a7 by (simp add: Ball_def_raw Bex_def_raw)\n  have \"conv_mark_node (node_mark (the (Mapping.lookup (nodes g) (edge_trg (the (Mapping.lookup (edges g) e)))))) \\<noteq> RuleMarkNode_Green\"\n    using a1 by force\n  then show False\n    using f10 a9 a8 a6 a5 a4 a3 a2 a1 by (smt (z3) conv_mark_node.elims mark_eq_node.simps(12) mark_eq_node.simps(15) mark_eq_node.simps(16) mark_eq_node.simps(23) rulemark_node.distinct(13))\nqed\n\nlemma \"\\<lbrakk>wf_ruleschema col_blue_1; wf_ruleschema col_blue_2; wf_graph g\\<rbrakk> \n  \\<Longrightarrow> eval g undefined ((Slp f (col_blue_1:: rule) \\<lceil>\\<or>\\<rceil> Slp f (col_blue_2:: rule))  \\<lceil>\\<longleftrightarrow>\\<rceil>   \n  (\\<lceil>\\<exists>0: Node\\<rceil> (\\<lceil>\\<exists>1: Node\\<rceil> ((\\<lceil>\\<forall>2: Node\\<rceil> (\\<langle>2\\<rangle> \\<lceil>=\\<rceil> \\<langle>0\\<rangle> \\<lceil>\\<or>\\<rceil> \\<langle>2\\<rangle> \\<lceil>=\\<rceil> \\<langle>1\\<rangle> \\<lceil>\\<or>\\<rceil>\n    ((\\<lceil>mark \\<langle>2\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Red \\<lceil>\\<or>\\<rceil> \\<lceil>mark \\<langle>2\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Blue \\<lceil>\\<or>\\<rceil> \\<lceil>mark \\<langle>2\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_None) \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>2\\<rangle>\\<rceil>)))\n  \\<lceil>\\<and>\\<rceil> \\<lceil>mark \\<langle>0\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Red \\<lceil>\\<and>\\<rceil> \\<lceil>mark \\<langle>1\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Blue \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>0\\<rangle>\\<rceil> \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>1\\<rangle>\\<rceil>\n  \\<lceil>\\<and>\\<rceil> (\\<lceil>\\<exists>3: Edge\\<rceil> ((\\<lceil>src \\<langle>3\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<langle>0\\<rangle> \\<lceil>\\<and>\\<rceil> \\<lceil>trg \\<langle>3\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<langle>1\\<rangle>) \\<lceil>\\<or>\\<rceil> (\\<lceil>src \\<langle>3\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<langle>1\\<rangle> \\<lceil>\\<and>\\<rceil> \\<lceil>trg \\<langle>3\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<langle>0\\<rangle>)) )))) \\<lceil>\\<and>\\<rceil> (\\<lceil>\\<forall>4:Edge\\<rceil> (\\<lceil>mark \\<langle>4\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>E RuleMarkEdge_None)))\"\n  apply code_simp\n  apply safe\n  apply auto\n     apply (metis (no_types, lifting))\n    apply (metis (no_types, hide_lams))\n   apply (rule xxx)\n              apply blast+\n  apply (rule xxx)\n             apply blast+\n  by (metis (no_types, hide_lams))+\n\n\n\n  \n  \n  \n(*\nlemma \"eval g undefined (Slp f (col_red:: rule)  \\<lceil>\\<longrightarrow>\\<rceil>  \n  (\\<lceil>\\<exists>0: Node\\<rceil> (\\<lceil>\\<exists>1: Node\\<rceil> ((\\<lceil>\\<forall>2: Node\\<rceil> (\\<langle>2\\<rangle> \\<lceil>=\\<rceil> \\<langle>0\\<rangle> \\<lceil>\\<or>\\<rceil> \\<langle>2\\<rangle> \\<lceil>=\\<rceil> \\<langle>1\\<rangle> \\<lceil>\\<or>\\<rceil>\n    ((\\<lceil>mark \\<langle>2\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Red \\<lceil>\\<or>\\<rceil> \\<lceil>mark \\<langle>2\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Blue \\<lceil>\\<or>\\<rceil> \\<lceil>mark \\<langle>2\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_None) \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>2\\<rangle>\\<rceil>)))\n  \\<lceil>\\<and>\\<rceil> \\<lceil>mark \\<langle>0\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Red \\<lceil>\\<and>\\<rceil> \\<lceil>mark \\<langle>1\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Blue \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>0\\<rangle>\\<rceil> \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>1\\<rangle>\\<rceil>\n  \\<lceil>\\<and>\\<rceil> (\\<lceil>\\<exists>3: Edge\\<rceil> ((\\<lceil>src \\<langle>3\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<langle>0\\<rangle> \\<lceil>\\<and>\\<rceil> \\<lceil>trg \\<langle>3\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<langle>1\\<rangle>) \\<lceil>\\<or>\\<rceil> (\\<lceil>src \\<langle>3\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<langle>1\\<rangle> \\<lceil>\\<and>\\<rceil> \\<lceil>trg \\<langle>3\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<langle>0\\<rangle>)) )))) \\<lceil>\\<and>\\<rceil> (\\<lceil>\\<forall>4:Edge\\<rceil> (\\<lceil>mark \\<langle>4\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>E RuleMarkEdge_None)))\"\n  apply code_simp\n  by auto  \n\nlemma \"eval g undefined (Slp f (col_red:: rule)  \\<lceil>\\<longleftrightarrow>\\<rceil>\n  ((\\<lceil>\\<exists>0: Node\\<rceil> \n    (\\<lceil>\\<exists>1: Node\\<rceil> \n      ((\\<lceil>\\<forall>2: Node\\<rceil> (\\<langle>2\\<rangle> \\<lceil>=\\<rceil> \\<langle>0\\<rangle> \\<lceil>\\<or>\\<rceil> \\<langle>2\\<rangle> \\<lceil>=\\<rceil> \\<langle>1\\<rangle> \\<lceil>\\<or>\\<rceil>\n        ((\\<lceil>mark \\<langle>2\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Red \\<lceil>\\<or>\\<rceil> \\<lceil>mark \\<langle>2\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Blue \\<lceil>\\<or>\\<rceil> \\<lceil>mark \\<langle>2\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_None) \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>2\\<rangle>\\<rceil>) ))\n  \\<lceil>\\<and>\\<rceil> \\<lceil>mark \\<langle>0\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Red \\<lceil>\\<and>\\<rceil> \\<lceil>mark \\<langle>1\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Blue \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>0\\<rangle>\\<rceil> \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>1\\<rangle>\\<rceil>\n  \\<lceil>\\<and>\\<rceil> (\\<lceil>\\<exists>3: Edge\\<rceil> ((\\<lceil>src \\<langle>3\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<langle>0\\<rangle> \\<lceil>\\<and>\\<rceil> \\<lceil>trg \\<langle>3\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<langle>1\\<rangle>) \\<lceil>\\<or>\\<rceil> (\\<lceil>src \\<langle>3\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<langle>1\\<rangle> \\<lceil>\\<and>\\<rceil> \\<lceil>trg \\<langle>3\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<langle>0\\<rangle>)) )))) \\<lceil>\\<and>\\<rceil> (\\<lceil>\\<forall>4:Edge\\<rceil> (\\<lceil>mark \\<langle>4\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>E RuleMarkEdge_None))))\"\n  apply code_simp\n  apply auto\n  oops\n *)\n  \n  \nlemma \"eval g undefined (Slp f (unmark :: rule)  \\<lceil>\\<longleftrightarrow>\\<rceil>  \n  (\\<lceil>\\<exists>1: Node\\<rceil> ((\\<lceil>\\<forall>0: Node\\<rceil> (\\<langle>0\\<rangle> \\<lceil>=\\<rceil> \\<langle>1\\<rangle> \\<lceil>\\<or>\\<rceil> \n    ((\\<lceil>mark \\<langle>0\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Red \\<lceil>\\<or>\\<rceil> \\<lceil>mark \\<langle>0\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Blue \\<lceil>\\<or>\\<rceil> \\<lceil>mark \\<langle>0\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_None) \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>0\\<rangle>\\<rceil>)))\n  \\<lceil>\\<and>\\<rceil> \\<lceil>mark \\<langle>1\\<rangle>\\<rceil> \\<lceil>=\\<rceil>\\<triangleright>\\<^sub>V RuleMarkNode_None \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>1\\<rangle>\\<rceil>)) \\<lceil>\\<and>\\<rceil> (\\<lceil>\\<forall>4:Edge\\<rceil> (\\<lceil>mark \\<langle>4\\<rangle>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>E RuleMarkEdge_None)))\"\n  apply code_simp\n  by auto\n\n\n\n\n\nlemma c_impl_f : \"eval g undefined (c \\<lceil>\\<longrightarrow>\\<rceil> f)\" \n  by clarsimp\n\n(* section \\<open>Proof of Fail output\\<close> *)\n(* \nlemma \"eval g undefined (Fail (RuleSet {col_blue::rule, col_red::rule}) \\<lceil>\\<longleftrightarrow>\\<rceil> \n  (\\<lceil>\\<not>\\<rceil>(\\<lceil>\\<exists> x: Edge\\<rceil> ((((\\<lceil>mark \\<lceil>src \\<langle>x\\<rangle>\\<rceil>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Red \\<lceil>\\<or>\\<rceil> \\<lceil>mark \\<lceil>src \\<langle>x\\<rangle>\\<rceil>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Blue) \\<lceil>\\<and>\\<rceil> \\<lceil>mark \\<lceil>src \\<langle>x\\<rangle>\\<rceil>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_None) \\<lceil>\\<or>\\<rceil>\n                     ((\\<lceil>mark \\<lceil>trg \\<langle>x\\<rangle>\\<rceil>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Red \\<lceil>\\<or>\\<rceil> \\<lceil>mark \\<lceil>trg \\<langle>x\\<rangle>\\<rceil>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_Blue) \\<lceil>\\<and>\\<rceil> \\<lceil>mark \\<lceil>src \\<langle>x\\<rangle>\\<rceil>\\<rceil> \\<lceil>=\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_None) ) \\<lceil>\\<and>\\<rceil>\n  \\<lceil>unrooted \\<lceil>src \\<langle>x\\<rangle>\\<rceil>\\<rceil> \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<lceil>trg \\<langle>x\\<rangle>\\<rceil>\\<rceil>) )))\"\n  apply auto\n  oops\n\nlemma \"eval g undefined (Fail (RuleApp init ;; RuleSet {col_blue::rule, col_red::rule}!) \\<lceil>\\<longleftrightarrow>\\<rceil> \n  (\\<lceil>\\<not>\\<rceil>(\\<lceil>\\<exists> x : Node\\<rceil> (\\<lceil>mark \\<langle>x\\<rangle>\\<rceil> \\<lceil>=\\<rceil>  \\<triangleright>\\<^sub>V RuleMarkNode_None \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>x\\<rangle>\\<rceil>))))\"\n  apply auto\n  sorry\n\n\nlemma \"eval g undefined (Fail (RuleApp unmark) \\<lceil>\\<longleftrightarrow>\\<rceil> (\\<lceil>\\<not>\\<rceil>(\\<lceil>\\<exists>x:Node\\<rceil> (\\<lceil>mark \\<langle>x\\<rangle>\\<rceil> \\<lceil>\\<noteq>\\<rceil> \\<triangleright>\\<^sub>V RuleMarkNode_None \\<lceil>\\<and>\\<rceil> \\<lceil>unrooted \\<langle>x\\<rangle>\\<rceil>))))\"\n  apply (simp add: unmark_def)\n  apply (rule conjI)\n   apply (rule disjI1)\n   apply (simp add: set_to_list_def)\n   apply (rule someI2_ex)\n  apply (metis empty_set list.simps(15))\n  apply (induct g rule: eval.induct)\n\n\nlemma \"\\<turnstile> {c} twocolouring {c \\<lceil>\\<or>\\<rceil> d}\"\n  apply (simp add: twocolouring_def)\n  apply (rule Cons [where ?c' = f and ?d' = \"c \\<lceil>\\<or>\\<rceil> d\"])\n    apply auto\n  apply (rule Comp [where ?e = e])\n\\<comment> \\<open>subtree I\\<close>\n   apply (rule Cons [where ?c' = f and d'=\"f \\<lceil>\\<and>\\<rceil> Fail (RuleApp init ;; RuleSet {col_blue::rule, col_red::rule}!)\"])\n     apply auto\n    prefer 2\n  oops\n *)\n\n(*     prefer 2\n    using c_impl_f apply blast\n     prefer 2\n    apply auto\n  apply (rule Comp [where ?e = e])\n     apply (rule Cons [where ?c' = f and ?d' = \"f \\<lceil>\\<and>\\<rceil> Fail (RuleApp init ;; RuleSet {col_blue::rule, col_red::rule}!)\"])\n       prefer 2\n       apply auto\n      prefer 2\n    apply (simp add: dom_def)\n    oops\n\n *)end", "meta": {"author": "rsoeldner", "repo": "gp2-isabelle", "sha": "bd6283c5ee5307231d9bfdfce409610f46ec0357", "save_path": "github-repos/isabelle/rsoeldner-gp2-isabelle", "path": "github-repos/isabelle/rsoeldner-gp2-isabelle/gp2-isabelle-bd6283c5ee5307231d9bfdfce409610f46ec0357/TwoColouringEx.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6001883449573376, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.283699113521498}}
{"text": "theory ResourcedDenotational\nimports \"Abstract-Denotational-Props\" \"CValue-Nominal\" \"C-restr\"\nbegin\n\ntype_synonym CEnv = \"var \\<Rightarrow> (C \\<rightarrow> CValue)\"\n\ninterpretation semantic_domain\n  \"\\<Lambda> f . \\<Lambda> r. CFn\\<cdot>(\\<Lambda> v. (f\\<cdot>(v))|\\<^bsub>r\\<^esub>)\"\n  \"\\<Lambda> x y. (\\<Lambda> r. (x\\<cdot>r \\<down>CFn y|\\<^bsub>r\\<^esub>)\\<cdot>r)\"\n  \"\\<Lambda> b r. CB\\<cdot>b\"\n  \"\\<Lambda> scrut v1 v2 r. CB_project\\<cdot>(scrut\\<cdot>r)\\<cdot>(v1\\<cdot>r)\\<cdot>(v2\\<cdot>r)\"\n  \"C_case\".\n\nnotation ESem_syn (\"\\<N>\\<lbrakk> _ \\<rbrakk>\\<^bsub>_\\<^esub>\"  [60,60] 60)\nnotation EvalHeapSem_syn  (\"\\<^bold>\\<N>\\<lbrakk> _ \\<^bold>\\<rbrakk>\\<^bsub>_\\<^esub>\"  [0,0] 110)\nnotation HSem_syn (\"\\<N>\\<lbrace>_\\<rbrace>_\"  [60,60] 60)\nnotation AHSem_bot (\"\\<N>\\<lbrace>_\\<rbrace>\"  [60] 60)\n\ntext \\<open>\nHere we re-state the simplification rules, cleaned up by beta-reducing the locale parameters.\n\\<close>\n\nlemma CESem_simps:\n  \"\\<N>\\<lbrakk> Lam [x]. e \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>  = (\\<Lambda> (C\\<cdot>r). CFn\\<cdot>(\\<Lambda> v. (\\<N>\\<lbrakk> e \\<rbrakk>\\<^bsub>\\<rho>(x := v)\\<^esub>)|\\<^bsub>r\\<^esub>))\"\n  \"\\<N>\\<lbrakk> App e x \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>     = (\\<Lambda> (C\\<cdot>r). ((\\<N>\\<lbrakk> e \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>)\\<cdot>r \\<down>CFn \\<rho> x|\\<^bsub>r\\<^esub>)\\<cdot>r)\"\n  \"\\<N>\\<lbrakk> Var x \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>       = (\\<Lambda> (C\\<cdot>r). (\\<rho>  x) \\<cdot> r)\"\n  \"\\<N>\\<lbrakk> Bool b \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>      = (\\<Lambda> (C\\<cdot>r). CB\\<cdot>(Discr b))\"\n  \"\\<N>\\<lbrakk> (scrut ? e\\<^sub>1 : e\\<^sub>2) \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>  = (\\<Lambda> (C\\<cdot>r). CB_project\\<cdot>((\\<N>\\<lbrakk> scrut \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>)\\<cdot>r)\\<cdot>((\\<N>\\<lbrakk> e\\<^sub>1 \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>)\\<cdot>r)\\<cdot>((\\<N>\\<lbrakk> e\\<^sub>2 \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>)\\<cdot>r))\"\n  \"\\<N>\\<lbrakk> Let as body \\<rbrakk>\\<^bsub>\\<rho>\\<^esub> = (\\<Lambda> (C \\<cdot> r). (\\<N>\\<lbrakk>body\\<rbrakk>\\<^bsub>\\<N>\\<lbrace>as\\<rbrace>\\<rho>\\<^esub>) \\<cdot> r)\"\n  by (auto simp add: eta_cfun)\n\nlemma CESem_bot[simp]:\"(\\<N>\\<lbrakk> e \\<rbrakk>\\<^bsub>\\<sigma>\\<^esub>)\\<cdot>\\<bottom> = \\<bottom>\"\n  by (nominal_induct e arbitrary: \\<sigma> rule: exp_strong_induct) auto\n\nlemma CHSem_bot[simp]:\"((\\<N>\\<lbrace> \\<Gamma> \\<rbrace>) x)\\<cdot>\\<bottom> = \\<bottom>\"\n  by (cases \"x \\<in> domA \\<Gamma>\") (auto simp add: lookup_HSem_heap lookup_HSem_other)\n\ntext \\<open>\nSometimes we do not care much about the resource usage and just want a simpler formula.\n\\<close>\n\nlemma CESem_simps_no_tick:\n  \"(\\<N>\\<lbrakk> Lam [x]. e \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>)\\<cdot>r \\<sqsubseteq> CFn\\<cdot>(\\<Lambda> v. (\\<N>\\<lbrakk> e \\<rbrakk>\\<^bsub>\\<rho>(x := v)\\<^esub>)|\\<^bsub>r\\<^esub>)\"\n  \"(\\<N>\\<lbrakk> App e x \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>)\\<cdot>r    \\<sqsubseteq> ((\\<N>\\<lbrakk> e \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>)\\<cdot>r \\<down>CFn \\<rho> x|\\<^bsub>r\\<^esub>)\\<cdot>r\"\n  \"\\<N>\\<lbrakk> Var x \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>         \\<sqsubseteq> \\<rho> x\"\n  \"(\\<N>\\<lbrakk> (scrut ? e\\<^sub>1 : e\\<^sub>2) \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>)\\<cdot>r \\<sqsubseteq> CB_project\\<cdot>((\\<N>\\<lbrakk> scrut \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>)\\<cdot>r)\\<cdot>((\\<N>\\<lbrakk> e\\<^sub>1 \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>)\\<cdot>r)\\<cdot>((\\<N>\\<lbrakk> e\\<^sub>2 \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>)\\<cdot>r)\"\n  \"\\<N>\\<lbrakk> Let as body \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>   \\<sqsubseteq>  \\<N>\\<lbrakk>body\\<rbrakk>\\<^bsub>\\<N>\\<lbrace>as\\<rbrace>\\<rho>\\<^esub>\"\n  apply -\n  apply (rule below_trans[OF monofun_cfun_arg[OF below_C]], simp)\n  apply (rule below_trans[OF monofun_cfun_arg[OF below_C]], simp)\n  apply (rule cfun_belowI, rule below_trans[OF monofun_cfun_arg[OF below_C]], simp)\n  apply (rule below_trans[OF monofun_cfun_arg[OF below_C]], simp)\n  apply (rule cfun_belowI, rule below_trans[OF monofun_cfun_arg[OF below_C]], simp)\n  done\n\nlemma CELam_no_restr: \"(\\<N>\\<lbrakk> Lam [x]. e \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>)\\<cdot>r \\<sqsubseteq> CFn\\<cdot>(\\<Lambda> v. (\\<N>\\<lbrakk> e \\<rbrakk>\\<^bsub>\\<rho>(x := v)\\<^esub>))\"\nproof-\n  have \"(\\<N>\\<lbrakk> Lam [x]. e \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>)\\<cdot>r \\<sqsubseteq> CFn\\<cdot>(\\<Lambda> v. (\\<N>\\<lbrakk> e \\<rbrakk>\\<^bsub>\\<rho>(x := v)\\<^esub>)|\\<^bsub>r\\<^esub>)\" by (rule CESem_simps_no_tick)\n  also have \"\\<dots> \\<sqsubseteq> CFn\\<cdot>(\\<Lambda> v. (\\<N>\\<lbrakk> e \\<rbrakk>\\<^bsub>\\<rho>(x := v)\\<^esub>))\"\n    by (intro cont2cont monofun_LAM below_trans[OF C_restr_below] monofun_cfun_arg below_refl fun_upd_mono)\n  finally show ?thesis by this (intro cont2cont)\nqed\n\nlemma CEApp_no_restr: \"(\\<N>\\<lbrakk> App e x \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>)\\<cdot>r    \\<sqsubseteq> ((\\<N>\\<lbrakk> e \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>)\\<cdot>r \\<down>CFn \\<rho> x)\\<cdot>r\"\nproof-\n  have \"(\\<N>\\<lbrakk> App e x \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>)\\<cdot>r  \\<sqsubseteq> ((\\<N>\\<lbrakk> e \\<rbrakk>\\<^bsub>\\<rho>\\<^esub>)\\<cdot>r \\<down>CFn \\<rho> x|\\<^bsub>r\\<^esub>)\\<cdot>r\" by (rule CESem_simps_no_tick)\n  also have \"\\<rho> x|\\<^bsub>r\\<^esub> \\<sqsubseteq> \\<rho> x\" by (rule C_restr_below)\n  finally show ?thesis by this (intro cont2cont)\nqed\n\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Launchbury/ResourcedDenotational.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982315512489, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.2836212884577598}}
{"text": "(*  File:       Parallel_Composition.thy\n    Copyright   2021  Karlsruhe Institute of Technology (KIT)\n*)\n\\<^marker>\\<open>creator \"Karsten Diekhoff, Karlsruhe Institute of Technology (KIT)\"\\<close>\n\\<^marker>\\<open>contributor \"Jonas Kraemer, Karlsruhe Institute of Technology (KIT)\"\\<close>\n\\<^marker>\\<open>contributor \"Michael Kirsten, Karlsruhe Institute of Technology (KIT)\"\\<close>\n\nsection \\<open>Parallel Composition\\<close>\n\ntheory Parallel_Composition\n  imports \"Basic_Modules/Component_Types/Aggregator\"\n          \"Basic_Modules/Component_Types/Electoral_Module\"\nbegin\n\ntext\n\\<open>The parallel composition composes a new electoral module from\ntwo electoral modules combined with an aggregator.\nTherein, the two modules each make a decision and the aggregator combines\nthem to a single (aggregated) result.\\<close>\n\nsubsection \\<open>Definition\\<close>\n\nfun parallel_composition :: \"'a Electoral_Module \\<Rightarrow> 'a Electoral_Module \\<Rightarrow>\n        'a Aggregator \\<Rightarrow> 'a Electoral_Module\" where\n  \"parallel_composition m n agg A p = agg A (m A p) (n A p)\"\n\nabbreviation parallel :: \"'a Electoral_Module \\<Rightarrow> 'a Aggregator \\<Rightarrow>\n        'a Electoral_Module \\<Rightarrow> 'a Electoral_Module\"\n      (\"_ \\<parallel>\\<^sub>_ _\" [50, 1000, 51] 50) where\n  \"m \\<parallel>\\<^sub>a n == parallel_composition m n a\"\n\nsubsection \\<open>Soundness\\<close>\n\ntheorem par_comp_sound[simp]:\n  assumes\n    mod_m: \"electoral_module m\" and\n    mod_n: \"electoral_module n\" and\n    agg_a: \"aggregator a\"\n  shows \"electoral_module (m \\<parallel>\\<^sub>a n)\"\n  unfolding electoral_module_def\nproof (safe)\n  fix\n    A :: \"'a set\" and\n    p :: \"'a Profile\"\n  assume\n    fin_A: \"finite A\" and\n    prof_A: \"profile A p\"\n  have wf_quant:\n    \"\\<forall>f. aggregator f =\n      (\\<forall>a_set elec1 rej1 def1 elec2 rej2 def2.\n        (\\<not> well_formed (a_set::'a set) (elec1, rej2, def1) \\<or>\n          \\<not> well_formed a_set (rej1, def2, elec2)) \\<or>\n        well_formed a_set\n          (f a_set (elec1, rej2, def1) (rej1, def2, elec2)))\"\n    unfolding aggregator_def\n    by blast\n  have wf_imp:\n    \"\\<forall>e_mod a_set prof.\n      (electoral_module e_mod \\<and> finite (a_set::'a set) \\<and>\n        profile a_set prof) \\<longrightarrow>\n        well_formed a_set (e_mod a_set prof)\"\n    using par_comp_result_sound\n    by (metis (no_types))\n  from mod_m mod_n fin_A prof_A agg_a\n  have \"well_formed A (a A (m A p) (n A p))\"\n    using agg_a combine_ele_rej_def fin_A\n          mod_m mod_n prof_A wf_imp wf_quant\n    by metis\n  thus \"well_formed A ((m \\<parallel>\\<^sub>a n) A p)\"\n    by simp\nqed\n\nsubsection \\<open>Composition Rule\\<close>\n\n(*\n   Using a conservative aggregator, the parallel composition\n   preserves the property non-electing.\n*)\ntheorem conserv_agg_presv_non_electing[simp]:\n  assumes\n    non_electing_m: \"non_electing m\" and\n    non_electing_n: \"non_electing n\" and\n    conservative: \"agg_conservative a\"\n  shows \"non_electing (m \\<parallel>\\<^sub>a n)\"\n  unfolding non_electing_def\nproof (safe)\n  have emod_m: \"electoral_module m\"\n    using non_electing_m\n    by (simp add: non_electing_def)\n  have emod_n: \"electoral_module n\"\n    using non_electing_n\n    by (simp add: non_electing_def)\n  have agg_a: \"aggregator a\"\n    using conservative\n    by (simp add: agg_conservative_def)\n  thus \"electoral_module (m \\<parallel>\\<^sub>a n)\"\n    using emod_m emod_n agg_a par_comp_sound\n    by simp\nnext\n  fix\n    A :: \"'a set\" and\n    p :: \"'a Profile\" and\n    x :: \"'a\"\n  assume\n    fin_A: \"finite A\" and\n    prof_A: \"profile A p\" and\n    x_wins: \"x \\<in> elect (m \\<parallel>\\<^sub>a n) A p\"\n  have emod_m: \"electoral_module m\"\n    using non_electing_m\n    by (simp add: non_electing_def)\n  have emod_n: \"electoral_module n\"\n    using non_electing_n\n    by (simp add: non_electing_def)\n  have\n    \"\\<forall>x0 x1 x2 x3 x4 x5 x6 x7.\n      (well_formed (x6::'a set) (x5, x1, x3) \\<and> well_formed x6 (x4, x0, x2) \\<longrightarrow>\n        elect_r (x7 x6 (x5, x1, x3) (x4, x0, x2)) \\<subseteq> x5 \\<union> x4 \\<and>\n          reject_r (x7 x6 (x5, x1, x3) (x4, x0, x2)) \\<subseteq> x1 \\<union> x0 \\<and>\n          defer_r (x7 x6 (x5, x1, x3) (x4, x0, x2)) \\<subseteq> x3 \\<union> x2) =\n            ((\\<not> well_formed x6 (x5, x1, x3) \\<or> \\<not> well_formed x6 (x4, x0, x2)) \\<or>\n              elect_r (x7 x6 (x5, x1, x3) (x4, x0, x2)) \\<subseteq> x5 \\<union> x4 \\<and>\n                reject_r (x7 x6 (x5, x1, x3) (x4, x0, x2)) \\<subseteq> x1 \\<union> x0 \\<and>\n                defer_r (x7 x6 (x5, x1, x3) (x4, x0, x2)) \\<subseteq> x3 \\<union> x2)\"\n    by linarith\n  hence\n    \"\\<forall>f. agg_conservative f =\n      (aggregator f \\<and>\n        (\\<forall>A Aa Ab Ac Ad Ae Af. (\\<not> well_formed (A::'a set) (Aa, Ae, Ac) \\<or>\n            \\<not> well_formed A (Ab, Af, Ad)) \\<or>\n          elect_r (f A (Aa, Ae, Ac) (Ab, Af, Ad)) \\<subseteq> Aa \\<union> Ab \\<and>\n            reject_r (f A (Aa, Ae, Ac) (Ab, Af, Ad)) \\<subseteq> Ae \\<union> Af \\<and>\n            defer_r (f A (Aa, Ae, Ac) (Ab, Af, Ad)) \\<subseteq> Ac \\<union> Ad))\"\n    by (simp add: agg_conservative_def)\n  hence\n    \"aggregator a \\<and>\n      (\\<forall>A Aa Ab Ac Ad Ae Af. \\<not> well_formed A (Aa, Ae, Ac) \\<or>\n          \\<not> well_formed A (Ab, Af, Ad) \\<or>\n          elect_r (a A (Aa, Ae, Ac) (Ab, Af, Ad)) \\<subseteq> Aa \\<union> Ab \\<and>\n            reject_r (a A (Aa, Ae, Ac) (Ab, Af, Ad)) \\<subseteq> Ae \\<union> Af \\<and>\n            defer_r (a A (Aa, Ae, Ac) (Ab, Af, Ad)) \\<subseteq> Ac \\<union> Ad)\"\n    using conservative\n    by presburger\n  hence\n    \"let c = (a A (m A p) (n A p)) in\n      (elect_r c \\<subseteq> ((elect m A p) \\<union> (elect n A p)))\"\n    using emod_m emod_n fin_A par_comp_result_sound\n          prod.collapse prof_A\n    by metis\n  hence \"x \\<in> ((elect m A p) \\<union> (elect n A p))\"\n    using x_wins\n    by auto\n  thus \"x \\<in> {}\"\n    using sup_bot_right non_electing_def fin_A\n          non_electing_m non_electing_n prof_A\n    by (metis (no_types, lifting))\nqed\n\nend\n", "meta": {"author": "ChrisMackKit", "repo": "ba-scoring-rule-reinforcement-homogeneity", "sha": "d87febd04743389ac578b332349ae446b9c55e89", "save_path": "github-repos/isabelle/ChrisMackKit-ba-scoring-rule-reinforcement-homogeneity", "path": "github-repos/isabelle/ChrisMackKit-ba-scoring-rule-reinforcement-homogeneity/ba-scoring-rule-reinforcement-homogeneity-d87febd04743389ac578b332349ae446b9c55e89/verifiedVotingRuleConstruction-master - Bevor Range/theories/Compositional_Structures/Parallel_Composition.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5583270090337582, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.283525079334865}}
{"text": "theory ETCS_Comparison\n  imports ETCS_Quantifier ETCS_Add \nbegin\n\ndefinition leq :: \"cfunc\" where\n  \"leq = EXISTS \\<nat>\\<^sub>c \\<circ>\\<^sub>c (eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c)\\<^sup>\\<sharp>\"\n\ndefinition leq_infix :: \"cfunc \\<Rightarrow> cfunc \\<Rightarrow> bool\" (infix \"\\<le>\\<^sub>\\<nat>\" 50) where\n  \"a \\<le>\\<^sub>\\<nat> b = (leq \\<circ>\\<^sub>c \\<langle>a, b\\<rangle> = \\<t>)\"\n\nlemma leq_type[type_rule]:\n  \"leq : \\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c \\<rightarrow> \\<Omega>\"\n  unfolding leq_def by typecheck_cfuncs\n\nlemma leq_true_implies_exists:\n  assumes m_type: \"m \\<in>\\<^sub>c \\<nat>\\<^sub>c\" and n_type: \"n \\<in>\\<^sub>c \\<nat>\\<^sub>c\"\n  assumes leq_true: \"leq \\<circ>\\<^sub>c \\<langle>m, n\\<rangle> = \\<t>\"\n  shows \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> k +\\<^sub>\\<nat> m = n\"\nproof -\n  have \"EXISTS \\<nat>\\<^sub>c \\<circ>\\<^sub>c (eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c)\\<^sup>\\<sharp> \\<circ>\\<^sub>c \\<langle>m, n\\<rangle> = \\<t>\"\n    using m_type n_type leq_true comp_associative2 unfolding leq_def by (typecheck_cfuncs, auto)\n  then have \"EXISTS \\<nat>\\<^sub>c \\<circ>\\<^sub>c \n      ((eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c) \\<circ>\\<^sub>c (id \\<nat>\\<^sub>c \\<times>\\<^sub>f \\<langle>m, n\\<rangle>))\\<^sup>\\<sharp> = \\<t>\"\n    using m_type n_type sharp_comp by (typecheck_cfuncs, auto)\n  then have \"EXISTS \\<nat>\\<^sub>c \\<circ>\\<^sub>c \n      ((eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c) \\<circ>\\<^sub>c\n          (id \\<nat>\\<^sub>c \\<times>\\<^sub>f \\<langle>m, n\\<rangle>) \\<circ>\\<^sub>c id (\\<nat>\\<^sub>c \\<times>\\<^sub>c one))\\<^sup>\\<sharp> = \\<t>\"\n    using m_type n_type by (typecheck_cfuncs, simp add: id_right_unit2)\n  then have \"EXISTS \\<nat>\\<^sub>c \\<circ>\\<^sub>c \n      ((eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c) \\<circ>\\<^sub>c\n          (id \\<nat>\\<^sub>c \\<times>\\<^sub>f \\<langle>m, n\\<rangle>) \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c one, \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c one\\<^esub>\\<rangle>)\\<^sup>\\<sharp> = \\<t>\"\n    using m_type n_type by (typecheck_cfuncs, metis cfunc_cross_prod_def id_cross_prod\n        id_domain id_left_unit2 right_cart_proj_type terminal_func_unique)\n  then have \"EXISTS \\<nat>\\<^sub>c \\<circ>\\<^sub>c \n      ((eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c) \\<circ>\\<^sub>c\n          (id \\<nat>\\<^sub>c \\<times>\\<^sub>f \\<langle>m, n\\<rangle>) \\<circ>\\<^sub>c \\<langle>id \\<nat>\\<^sub>c, \\<beta>\\<^bsub>\\<nat>\\<^sub>c\\<^esub>\\<rangle> \\<circ>\\<^sub>c left_cart_proj \\<nat>\\<^sub>c one)\\<^sup>\\<sharp> = \\<t>\"\n    using m_type n_type by (typecheck_cfuncs, simp add: cfunc_prod_comp id_left_unit2 terminal_func_comp)\n  then have \"EXISTS \\<nat>\\<^sub>c \\<circ>\\<^sub>c \n      ((eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c) \\<circ>\\<^sub>c\n          ((id \\<nat>\\<^sub>c \\<times>\\<^sub>f \\<langle>m, n\\<rangle>) \\<circ>\\<^sub>c \\<langle>id \\<nat>\\<^sub>c, \\<beta>\\<^bsub>\\<nat>\\<^sub>c\\<^esub>\\<rangle>) \\<circ>\\<^sub>c left_cart_proj \\<nat>\\<^sub>c one)\\<^sup>\\<sharp> = \\<t>\"\n    using m_type n_type comp_associative2 by (typecheck_cfuncs, auto)\n  then have \"EXISTS \\<nat>\\<^sub>c \\<circ>\\<^sub>c \n      ((eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c) \\<circ>\\<^sub>c\n          \\<langle>id \\<nat>\\<^sub>c, \\<langle>m, n\\<rangle> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c\\<^esub>\\<rangle> \\<circ>\\<^sub>c left_cart_proj \\<nat>\\<^sub>c one)\\<^sup>\\<sharp> = \\<t>\"\n    using m_type n_type cfunc_cross_prod_comp_cfunc_prod id_right_unit2 by (typecheck_cfuncs, auto)\n  then have \"EXISTS \\<nat>\\<^sub>c \\<circ>\\<^sub>c \n      ((eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>id \\<nat>\\<^sub>c, \\<langle>m, n\\<rangle> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c\\<^esub>\\<rangle>) \\<circ>\\<^sub>c\n          left_cart_proj \\<nat>\\<^sub>c one)\\<^sup>\\<sharp> = \\<t>\"\n    using m_type n_type by (typecheck_cfuncs, smt cfunc_type_def comp_associative domain_comp)\n  then have \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> \n      (eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>id \\<nat>\\<^sub>c, \\<langle>m, n\\<rangle> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c\\<^esub>\\<rangle>) \\<circ>\\<^sub>c k = \\<t>\"\n     using m_type n_type EXISTS_true_implies_exists_true by (typecheck_cfuncs, blast)\n  then have \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> \n      eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c ((add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>id \\<nat>\\<^sub>c, \\<langle>m, n\\<rangle> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c\\<^esub>\\<rangle>) \\<circ>\\<^sub>c k = \\<t>\"\n    using m_type n_type comp_associative2 by (typecheck_cfuncs, auto)\n  then have \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> \n      eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c (associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>id \\<nat>\\<^sub>c, \\<langle>m, n\\<rangle> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c\\<^esub>\\<rangle>) \\<circ>\\<^sub>c k = \\<t>\"\n    using m_type n_type comp_associative2 by (typecheck_cfuncs, auto)\n  then have \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> \n      eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>id \\<nat>\\<^sub>c, \\<langle>m, n\\<rangle> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c\\<^esub>\\<rangle> \\<circ>\\<^sub>c k = \\<t>\"\n    using m_type n_type comp_associative2 by (typecheck_cfuncs, auto)\n  then have \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> \n      eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>k, \\<langle>m, n\\<rangle>\\<rangle> = \\<t>\"\n    using m_type n_type cart_prod_extract_left by (typecheck_cfuncs, auto)\n  then have \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c \\<langle>\\<langle>k, m\\<rangle>, n\\<rangle> = \\<t>\"\n    using associate_left_ap m_type n_type by auto\n  then have \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>(add2  \\<circ>\\<^sub>c \\<langle>k, m\\<rangle>), (id \\<nat>\\<^sub>c \\<circ>\\<^sub>c n)\\<rangle> = \\<t>\"\n  proof (rule ex_forward, auto)\n    fix k\n    assume k_type: \"k \\<in>\\<^sub>c \\<nat>\\<^sub>c\"\n    assume \"eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id\\<^sub>c \\<nat>\\<^sub>c) \\<circ>\\<^sub>c \\<langle>\\<langle>k,m\\<rangle>,n\\<rangle> = \\<t>\"\n    then show \"eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>add2 \\<circ>\\<^sub>c \\<langle>k,m\\<rangle>,id\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c n\\<rangle> = \\<t>\"\n      using k_type assms by (typecheck_cfuncs, simp add: cfunc_cross_prod_comp_cfunc_prod)\n  qed\n  then have \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>add2 \\<circ>\\<^sub>c \\<langle>k, m\\<rangle>, n\\<rangle> = \\<t>\"\n    using id_left_unit2 n_type by auto\n  then have \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> add2 \\<circ>\\<^sub>c \\<langle>k, m\\<rangle> = n\"\n    by (metis add_def add_type eq_pred_iff_eq m_type n_type)\n  then show \"\\<exists>k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> k +\\<^sub>\\<nat> m = n\"\n    by (simp add: add_def)\nqed\n\nlemma exists_implies_leq_true:\n  assumes m_type: \"m \\<in>\\<^sub>c \\<nat>\\<^sub>c\" and n_type: \"n \\<in>\\<^sub>c \\<nat>\\<^sub>c\"\n  assumes leq_eqn: \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> k +\\<^sub>\\<nat> m = n\"\n  shows \"leq \\<circ>\\<^sub>c \\<langle>m, n\\<rangle> = \\<t>\"\nproof - \n  have \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> add2 \\<circ>\\<^sub>c \\<langle>k, m\\<rangle> = n\"\n    using add_def leq_eqn by auto\n  then have \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>add2 \\<circ>\\<^sub>c \\<langle>k, m\\<rangle>, n\\<rangle> = \\<t>\"\n    using eq_pred_iff_eq n_type by auto\n  then have \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>(add2  \\<circ>\\<^sub>c \\<langle>k, m\\<rangle>), (id \\<nat>\\<^sub>c \\<circ>\\<^sub>c n)\\<rangle> = \\<t>\"\n    using id_left_unit2 n_type by auto\n  then have \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c \\<langle>\\<langle>k, m\\<rangle>, n\\<rangle> = \\<t>\"\n     proof (rule ex_forward, auto)\n       fix k ka\n       assume k_type: \"k \\<in>\\<^sub>c \\<nat>\\<^sub>c\"\n       assume  \"eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>add2 \\<circ>\\<^sub>c \\<langle>k,m\\<rangle>,id\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c n\\<rangle> = \\<t>\"\n       then show \"eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id\\<^sub>c \\<nat>\\<^sub>c) \\<circ>\\<^sub>c \\<langle>\\<langle>k,m\\<rangle>,n\\<rangle> = \\<t>\"\n         using k_type assms by (typecheck_cfuncs, simp add:  cfunc_cross_prod_comp_cfunc_prod)\n     qed\n  then have \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> \n      eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>k, \\<langle>m, n\\<rangle>\\<rangle> = \\<t>\"\n    using associate_left_ap m_type n_type by auto\n  then have \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> \n      eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>id \\<nat>\\<^sub>c, \\<langle>m, n\\<rangle> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c\\<^esub>\\<rangle> \\<circ>\\<^sub>c k = \\<t>\"\n    using m_type n_type cart_prod_extract_left by (typecheck_cfuncs, auto)\n  then have \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> \n      eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c (associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>id \\<nat>\\<^sub>c, \\<langle>m, n\\<rangle> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c\\<^esub>\\<rangle>) \\<circ>\\<^sub>c k = \\<t>\"\n    using m_type n_type comp_associative2 by (typecheck_cfuncs, auto)\n  then have \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> \n      eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c ((add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>id \\<nat>\\<^sub>c, \\<langle>m, n\\<rangle> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c\\<^esub>\\<rangle>) \\<circ>\\<^sub>c k = \\<t>\"\n    using m_type n_type comp_associative2 by (typecheck_cfuncs, auto)\n  then have \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> \n      (eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>id \\<nat>\\<^sub>c, \\<langle>m, n\\<rangle> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c\\<^esub>\\<rangle>) \\<circ>\\<^sub>c k = \\<t>\"\n    using m_type n_type comp_associative2 by (typecheck_cfuncs, auto)\n  then have \"EXISTS \\<nat>\\<^sub>c \\<circ>\\<^sub>c \n      ((eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>id \\<nat>\\<^sub>c, \\<langle>m, n\\<rangle> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c\\<^esub>\\<rangle>) \\<circ>\\<^sub>c\n          left_cart_proj \\<nat>\\<^sub>c one)\\<^sup>\\<sharp> = \\<t>\"\n    using m_type n_type exists_true_implies_EXISTS_true by (typecheck_cfuncs, blast)\n  then have \"EXISTS \\<nat>\\<^sub>c \\<circ>\\<^sub>c \n      ((eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c) \\<circ>\\<^sub>c\n          \\<langle>id \\<nat>\\<^sub>c, \\<langle>m, n\\<rangle> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c\\<^esub>\\<rangle> \\<circ>\\<^sub>c left_cart_proj \\<nat>\\<^sub>c one)\\<^sup>\\<sharp> = \\<t>\"\n    using m_type n_type comp_associative2 by (typecheck_cfuncs, auto)\n  then have \"EXISTS \\<nat>\\<^sub>c \\<circ>\\<^sub>c \n      ((eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c) \\<circ>\\<^sub>c\n          (id \\<nat>\\<^sub>c \\<times>\\<^sub>f \\<langle>m, n\\<rangle>) \\<circ>\\<^sub>c \\<langle>id \\<nat>\\<^sub>c, \\<beta>\\<^bsub>\\<nat>\\<^sub>c\\<^esub>\\<rangle> \\<circ>\\<^sub>c left_cart_proj \\<nat>\\<^sub>c one)\\<^sup>\\<sharp> = \\<t>\"\n    using m_type n_type cfunc_cross_prod_comp_cfunc_prod comp_associative2 id_right_unit2 by (typecheck_cfuncs, auto)\n  then have \"EXISTS \\<nat>\\<^sub>c \\<circ>\\<^sub>c \n      ((eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c) \\<circ>\\<^sub>c\n          (id \\<nat>\\<^sub>c \\<times>\\<^sub>f \\<langle>m, n\\<rangle>) \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c one, \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c one\\<^esub>\\<rangle>)\\<^sup>\\<sharp> = \\<t>\"\n    using m_type n_type by (typecheck_cfuncs, smt  cfunc_prod_comp id_left_unit2 terminal_func_comp terminal_func_type)\n  then have \"EXISTS \\<nat>\\<^sub>c \\<circ>\\<^sub>c \n      ((eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c) \\<circ>\\<^sub>c\n          (id \\<nat>\\<^sub>c \\<times>\\<^sub>f \\<langle>m, n\\<rangle>) \\<circ>\\<^sub>c id (\\<nat>\\<^sub>c \\<times>\\<^sub>c one))\\<^sup>\\<sharp> = \\<t>\"\n    using m_type n_type by (typecheck_cfuncs, metis  cfunc_cross_prod_def id_cross_prod id_domain id_left_unit2 left_cart_proj_type right_cart_proj_type terminal_func_unique)\n  then have \"EXISTS \\<nat>\\<^sub>c \\<circ>\\<^sub>c \n      ((eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c) \\<circ>\\<^sub>c (id \\<nat>\\<^sub>c \\<times>\\<^sub>f \\<langle>m, n\\<rangle>))\\<^sup>\\<sharp> = \\<t>\"\n    using m_type n_type id_right_unit2 by (typecheck_cfuncs, force)\n  then have \"EXISTS \\<nat>\\<^sub>c \\<circ>\\<^sub>c (eq_pred \\<nat>\\<^sub>c \\<circ>\\<^sub>c (add2 \\<times>\\<^sub>f id \\<nat>\\<^sub>c) \\<circ>\\<^sub>c associate_left \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<nat>\\<^sub>c)\\<^sup>\\<sharp> \\<circ>\\<^sub>c \\<langle>m, n\\<rangle> = \\<t>\"\n    using m_type n_type by (typecheck_cfuncs, simp add:  sharp_comp)\n  then show \"leq \\<circ>\\<^sub>c \\<langle>m, n\\<rangle> = \\<t>\"\n    using m_type n_type comp_associative2 unfolding leq_def by (typecheck_cfuncs, auto)\nqed\n\nlemma add_monotonic:\n  assumes m_type: \"m \\<in>\\<^sub>c \\<nat>\\<^sub>c\" and n_type: \"n \\<in>\\<^sub>c \\<nat>\\<^sub>c\" and u_type: \"u \\<in>\\<^sub>c \\<nat>\\<^sub>c\" and v_type: \"v \\<in>\\<^sub>c \\<nat>\\<^sub>c\"\n  assumes m_leq_n: \"leq \\<circ>\\<^sub>c \\<langle>m, n\\<rangle> = \\<t>\" \n  assumes u_leq_v: \"leq \\<circ>\\<^sub>c \\<langle>u, v\\<rangle> = \\<t>\" \n  shows \"leq \\<circ>\\<^sub>c \\<langle>m +\\<^sub>\\<nat> u, n +\\<^sub>\\<nat> v\\<rangle> = \\<t>\" \nproof - \n  have m_leq_n_Eqn: \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> k +\\<^sub>\\<nat> m = n\"\n    by (simp add: leq_true_implies_exists m_leq_n m_type n_type)\n  have u_leq_v_Eqn: \"\\<exists> j. j \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> j +\\<^sub>\\<nat> u = v\"\n    by (simp add: leq_true_implies_exists u_leq_v u_type v_type)\n  have combined_Eqns: \"\\<exists> l. l \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> l +\\<^sub>\\<nat> (m +\\<^sub>\\<nat> u) = n +\\<^sub>\\<nat> v\"\n    by (smt add_associates add_commutes add_type m_leq_n_Eqn m_type u_leq_v_Eqn u_type)\n  show \"leq \\<circ>\\<^sub>c \\<langle>m +\\<^sub>\\<nat> u, n +\\<^sub>\\<nat> v\\<rangle> = \\<t>\"\n    by (metis add_type combined_Eqns exists_implies_leq_true m_type u_type)\nqed\n\nlemma leq_transitivity:\n  assumes m_type: \"m \\<in>\\<^sub>c \\<nat>\\<^sub>c\" and n_type: \"n \\<in>\\<^sub>c \\<nat>\\<^sub>c\" and p_type: \"p \\<in>\\<^sub>c \\<nat>\\<^sub>c\"\n  assumes m_leq_n: \"leq \\<circ>\\<^sub>c \\<langle>m, n\\<rangle> = \\<t>\" \n  assumes n_leq_p: \"leq \\<circ>\\<^sub>c \\<langle>n, p\\<rangle> = \\<t>\" \n  shows \"leq \\<circ>\\<^sub>c \\<langle>m, p\\<rangle> = \\<t>\" \nproof - \n   have m_leq_n_Eqn: \"\\<exists> k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> k +\\<^sub>\\<nat> m = n\"\n     by (simp add: leq_true_implies_exists m_leq_n m_type n_type)\n   obtain k where k_num: \"k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> k +\\<^sub>\\<nat> m = n\"\n     using m_leq_n_Eqn by blast\n   have n_leq_p_Eqn: \"\\<exists> j. j \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> j +\\<^sub>\\<nat> n = p\"\n     by (simp add: leq_true_implies_exists n_leq_p n_type p_type)\n   obtain j where j_num: \"j \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> j +\\<^sub>\\<nat> n = p\"\n     using n_leq_p_Eqn by blast\n   have combined_Eqn: \"(k +\\<^sub>\\<nat> j) +\\<^sub>\\<nat> m = p\"\n     using add_associates add_commutes j_num k_num m_type by auto\n   have combined_Exists: \"\\<exists> l. l \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> l +\\<^sub>\\<nat> m = p\"\n     using add_type combined_Eqn j_num k_num by blast\n   then show \"leq \\<circ>\\<^sub>c \\<langle>m, p\\<rangle> = \\<t>\"\n     by (simp add: exists_implies_leq_true m_type p_type)\n qed\n\n  \n\n\n\nlemma lqe_antisymmetry:\n  assumes m_type: \"m \\<in>\\<^sub>c \\<nat>\\<^sub>c\" and n_type: \"n \\<in>\\<^sub>c \\<nat>\\<^sub>c\"\n  assumes m_leq_n: \"leq \\<circ>\\<^sub>c \\<langle>m, n\\<rangle> = \\<t>\" \n  assumes n_leq_m: \"leq \\<circ>\\<^sub>c \\<langle>n, m\\<rangle> = \\<t>\" \n  shows \"m = n\"\nproof - \n  have k_exists: \"\\<exists>k. k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> k +\\<^sub>\\<nat> n = m\"\n    by (simp add: leq_true_implies_exists m_type n_leq_m n_type)\n  obtain k where k_def: \"k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> k +\\<^sub>\\<nat> n = m\"\n    using k_exists by blast\n  have j_exists: \"\\<exists>j. j \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> j +\\<^sub>\\<nat> m = n\"\n    by (simp add: leq_true_implies_exists m_leq_n m_type n_type)\n  obtain j where j_def: \"j \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> j +\\<^sub>\\<nat> m = n\"\n    using j_exists by blast\n  have \"zero +\\<^sub>\\<nat> m = k +\\<^sub>\\<nat> n\"\n    by (simp add: add_respects_zero_on_left k_def m_type)\n  also have \"... = (k +\\<^sub>\\<nat> j) +\\<^sub>\\<nat> m\"\n    using add_associates j_def k_def m_type by blast\n  then have zero_is_kplsj: \"zero = k +\\<^sub>\\<nat> j\"\n    by (metis  add_cancellative add_type calculation j_def k_def n_type zero_type)\n  have \"k = zero\"\n  proof(rule ccontr)\n    assume bwoc: \"k \\<noteq> zero\"\n    have k_is_succ: \"\\<exists>a. (a \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> k = successor \\<circ>\\<^sub>c a)\"\n      by (simp add: bwoc k_def nonzero_is_succ)\n    obtain a where a_def: \"a \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> k = successor \\<circ>\\<^sub>c a\"\n      using k_is_succ by blast\n    have \"zero = successor \\<circ>\\<^sub>c (a +\\<^sub>\\<nat> j)\"\n      by (simp add: a_def add_respects_succ3 j_def zero_is_kplsj)\n    then show False\n      using a_def add_type  j_def zero_is_not_successor by auto\n  qed\n  then show ?thesis\n    using add_respects_zero_on_left k_def n_type by blast\nqed\n\nlemma zero_is_smallest:\n  assumes \"n \\<in>\\<^sub>c \\<nat>\\<^sub>c\"\n  shows \"leq \\<circ>\\<^sub>c\\<langle>zero ,n\\<rangle> = \\<t>\"\n  using add_respects_zero_on_right assms exists_implies_leq_true zero_type by blast\n\nlemma lqe_connexity:\n  assumes m_type: \"m \\<in>\\<^sub>c \\<nat>\\<^sub>c\" and n_type: \"n \\<in>\\<^sub>c \\<nat>\\<^sub>c\"\n  shows \"(leq \\<circ>\\<^sub>c \\<langle>n, m\\<rangle> = \\<t>) \\<or> (leq \\<circ>\\<^sub>c \\<langle>m, n\\<rangle> = \\<t>)\"\nproof-\n\n  have main_result: \"(OR \\<circ>\\<^sub>c \\<langle>\nleq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c, right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\nleq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c, left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\n\\<rangle>)\\<^sup>\\<sharp> = (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c\\<times>\\<^sub>c\\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp>\"\n  proof(rule natural_number_object_func_unique[where X=\"\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>\", where f = \"id (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>)\" ])\n    show type_fact1: \"(OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c\\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> : \\<nat>\\<^sub>c \\<rightarrow> \\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>\"\n      by (meson OR_type cfunc_prod_type comp_type left_cart_proj_type leq_type right_cart_proj_type transpose_func_type)\n    show type_fact2: \"(\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp> : \\<nat>\\<^sub>c \\<rightarrow> \\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>\"\n      using comp_type terminal_func_type transpose_func_type true_func_type by blast\n    have type_fact3: \"id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c zero : \\<nat>\\<^sub>c\\<times>\\<^sub>c one \\<rightarrow> \\<nat>\\<^sub>c\\<times>\\<^sub>c\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>\"\n      using cfunc_cross_prod_type comp_type id_type type_fact2 zero_type by auto\n    show type_fact3: \"id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) : \\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup> \\<rightarrow> \\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>\"\n      by (simp add: id_type)\n    show eqn_1: \"(OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c zero =\n            (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c zero\"\n    proof(rule same_evals_equal[where Z = \"one\", where X=\\<Omega>, where A=\"\\<nat>\\<^sub>c\"])\n      show type_fact5: \"(OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                   leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c zero \\<in>\\<^sub>c \\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>\"\n        by (meson comp_type type_fact1 zero_type)\n      show type_fact6: \"(\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c zero \\<in>\\<^sub>c \\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>\"\n        by (meson comp_type type_fact2 zero_type)\n      show eqn_2: \"eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c zero =\n            eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c zero\"\n      proof(rule one_separator[where X=\"\\<nat>\\<^sub>c\\<times>\\<^sub>c one\", where Y = \\<Omega>])\n        show type_fact7: \"eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f \n          (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                 leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c\n            zero : \\<nat>\\<^sub>c \\<times>\\<^sub>c one \\<rightarrow> \\<Omega>\"\n          using flat_type inv_transpose_func_def2 type_fact5 by force\n        show type_fact8: \"eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c\n    id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c zero : \\<nat>\\<^sub>c \\<times>\\<^sub>c one \\<rightarrow> \\<Omega>\"\n          using flat_type inv_transpose_func_def2 type_fact6 by force\n        show \"\\<And>x. x \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>c one \\<Longrightarrow>\n             (eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f (OR \\<circ>\\<^sub>c\n             \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n              leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c zero) \\<circ>\\<^sub>c x =\n           (eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c zero) \\<circ>\\<^sub>c x\"\n        proof - \n          fix x \n          assume x_type: \"x \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>c one\"\n          have x_form: \"\\<exists>j. (j\\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> x = \\<langle>j,id one\\<rangle>)\"\n            by (metis (no_types) x_type cart_prod_decomp id_type one_unique_element)\n          obtain j where j_def: \"j\\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> x = \\<langle>j,id one\\<rangle>\"\n            using x_form by blast\n          have eqn_RHS: \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c zero) \\<circ>\\<^sub>c x = \\<t>\"\n          proof - \n            have \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c zero) \\<circ>\\<^sub>c x = \n                  (eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>c (id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f zero) \\<circ>\\<^sub>c x\"\n              by (typecheck_cfuncs, smt cfunc_type_def comp_associative inv_transpose_func_def2 inv_transpose_of_composition x_type)\n            also have \"... = (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>) \\<circ>\\<^sub>c (id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f zero) \\<circ>\\<^sub>c \\<langle>j,id one\\<rangle>\"\n              by (typecheck_cfuncs, simp add: j_def transpose_func_def)\n            also have \"... = (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>) \\<circ>\\<^sub>c \\<langle>id\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c j,zero \\<circ>\\<^sub>c id one\\<rangle>\"\n              using cfunc_cross_prod_comp_cfunc_prod j_def by (typecheck_cfuncs, force)\n            also have \"... = \\<t> \\<circ>\\<^sub>c (\\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub> \\<circ>\\<^sub>c \\<langle>id\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c j,zero \\<circ>\\<^sub>c id one\\<rangle>)\"\n              by (typecheck_cfuncs, metis comp_associative2 j_def)\n            also have \"... =  \\<t>\"\n              by (typecheck_cfuncs, metis id_right_unit2 j_def terminal_func_unique)\n            then show ?thesis\n              by (simp add: calculation)\n          qed\n          \n          have eqn_LHS: \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c  id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n            (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                    leq \\<circ>\\<^sub>c\\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c zero) \\<circ>\\<^sub>c x = \\<t>\"\n            proof - \n              have \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c  id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n            (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                    leq \\<circ>\\<^sub>c\\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c zero) \\<circ>\\<^sub>c x = \n                    (eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c  id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n            (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                    leq \\<circ>\\<^sub>c\\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>)  \\<circ>\\<^sub>c\n                 (id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f zero) \\<circ>\\<^sub>c x\"\n                by (typecheck_cfuncs, smt cfunc_type_def comp_associative inv_transpose_func_def2 inv_transpose_of_composition x_type)\n              also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                    leq \\<circ>\\<^sub>c\\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle> \\<circ>\\<^sub>c\n                 (id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f zero) \\<circ>\\<^sub>c x\"\n                by (typecheck_cfuncs, smt cfunc_type_def comp_associative transpose_func_def x_type)\n              also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                    leq \\<circ>\\<^sub>c\\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle> \\<circ>\\<^sub>c\n                 \\<langle>id\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c j,zero \\<circ>\\<^sub>c id one\\<rangle>\"\n                using cfunc_cross_prod_comp_cfunc_prod j_def by (typecheck_cfuncs, auto)\n              also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                    leq \\<circ>\\<^sub>c\\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle> \\<circ>\\<^sub>c\n                 \\<langle>j,zero\\<rangle>\"\n                using id_left_unit2 id_right_unit2 j_def zero_type by force\n              also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>j,zero\\<rangle>  ,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>j,zero\\<rangle> \\<rangle>,\n                    leq \\<circ>\\<^sub>c\\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>j,zero\\<rangle> ,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>j,zero\\<rangle> \\<rangle>\\<rangle>\"\n                by (typecheck_cfuncs, smt cfunc_prod_comp comp_associative2 j_def)\n              also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>j ,zero \\<rangle>, leq \\<circ>\\<^sub>c\\<langle>zero ,j \\<rangle>\\<rangle>\"\n                by (typecheck_cfuncs, metis j_def left_cart_proj_cfunc_prod right_cart_proj_cfunc_prod)\n              also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>j ,zero \\<rangle>, \\<t>\\<rangle>\"\n                by (simp add: j_def zero_is_smallest)\n              also have \"... = \\<t>\"\n                by (typecheck_cfuncs, simp add: OR_true_right_is_true j_def)\n              then show ?thesis\n                by (simp add: calculation)\n            qed\n            show \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c  id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n            (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                    leq \\<circ>\\<^sub>c\\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c zero) \\<circ>\\<^sub>c x =(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c zero) \\<circ>\\<^sub>c x\"\n              by (simp add: eqn_LHS eqn_RHS)\n          qed\n        qed\n      qed\n    show \"(\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c successor =\n    id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp>\"\n      proof(rule same_evals_equal[where Z = \"\\<nat>\\<^sub>c\", where X = \\<Omega>,where A = \"\\<nat>\\<^sub>c\"])\n        show type_fact9: \"(\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c successor : \\<nat>\\<^sub>c \\<rightarrow> \\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>\"\n          by (meson comp_type successor_type type_fact2)\n        show type_fact10: \"id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp> : \\<nat>\\<^sub>c \\<rightarrow> \\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>\"\n          by (meson comp_type type_fact2 type_fact3)\n        show \"eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c successor =\n    eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp>\"\n        proof(rule one_separator[where X=\"\\<nat>\\<^sub>c\\<times>\\<^sub>c\\<nat>\\<^sub>c\", where Y = \\<Omega>])\n          show type_fact11: \"eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c\n    id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c successor : \\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c \\<rightarrow> \\<Omega>\"\n            using type_fact9 flat_type inv_transpose_func_def2 by auto\n          show type_fact12: \"eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c\n    id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n    id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp> : \\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c \\<rightarrow> \\<Omega>\"\n            using flat_type inv_transpose_func_def2 type_fact10 by auto\n          show \"\\<And>x. x \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c \\<Longrightarrow>\n         (eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c successor) \\<circ>\\<^sub>c  x =\n         (eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>cx\"\n          proof -\n            fix x\n            assume x_def: \"x \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\"\n\n            \n            \n            \n            show \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c successor) \\<circ>\\<^sub>c  x =\n         (eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>cx\"\n            \n\n            proof - \n              have calc1: \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c successor) \\<circ>\\<^sub>c  x =\n                    (eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp>)\\<circ>\\<^sub>c (id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f successor) \\<circ>\\<^sub>c  x\"\n                by (typecheck_cfuncs, smt cfunc_type_def comp_associative inv_transpose_func_def2 inv_transpose_of_composition x_def)     \n              also have \"... = (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>) \\<circ>\\<^sub>c (id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f successor) \\<circ>\\<^sub>c  x\"\n                using transpose_func_def by (typecheck_cfuncs, auto)\n              also have \"... = \\<t> \\<circ>\\<^sub>c (\\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub> \\<circ>\\<^sub>c (id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f successor) \\<circ>\\<^sub>c  x)\"\n                by (typecheck_cfuncs, metis cfunc_type_def comp_associative x_def)\n              also have \"... = \\<t>\"\n                by (typecheck_cfuncs, metis id_right_unit2 id_type terminal_func_unique x_def)\n              then have eqsT1: \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c successor) \\<circ>\\<^sub>c  x =  \\<t>\"\n                by (simp add: calculation)\n              have calc2: \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>cx = \\<t>\"\n              proof -\n                have \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>cx = (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>) \\<circ>\\<^sub>cx\"\n                  by (typecheck_cfuncs, simp add: id_left_unit2 transpose_func_def)\n                also have \"... = \\<t> \\<circ>\\<^sub>c (\\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub> \\<circ>\\<^sub>c x)\"\n                  using comp_associative2 x_def by (typecheck_cfuncs, auto)\n                also have \"... = \\<t>\"\n                  by (metis id_right_unit2 id_type one_unique_element terminal_func_comp terminal_func_type true_func_type x_def)\n                then show ?thesis\n                  using calculation by auto\n              qed\n              then have eqsT2: \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\\<^esub>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>cx =  \\<t>\"\n                by (simp add:  calc2)\n              then show ?thesis\n                using eqsT1 by auto\n            qed\n          qed\n        qed\n      qed\n\n      \n\n      show \"(OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                   leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c\n    successor =\n    id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                          leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>\"\n        proof(rule same_evals_equal[where Z=\"\\<nat>\\<^sub>c\", where X=\\<Omega>, where A =\"\\<nat>\\<^sub>c\" ])\n          show type_fact13: \"(OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c\\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                                    leq \\<circ>\\<^sub>c\\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c\n    successor : \\<nat>\\<^sub>c \\<rightarrow> \\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>\"\n            using comp_type successor_type type_fact1 by blast\n\n          show type_fact14: \"id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c\n    (OR \\<circ>\\<^sub>c\n     \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n      leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> : \\<nat>\\<^sub>c \\<rightarrow> \\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>\"\n            using comp_type type_fact1 type_fact3 by auto\n\n          show \"eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c\n    id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n    (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n            leq \\<circ>\\<^sub>c\\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c\n    successor =\n    eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c\n    (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n           leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>\"\n          proof(rule one_separator[where X = \"\\<nat>\\<^sub>c\\<times>\\<^sub>c\\<nat>\\<^sub>c\", where Y = \\<Omega>])\n            show type_fact15: \"eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n    (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n            leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c\n    successor : \\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c \\<rightarrow> \\<Omega>\"\n              using flat_type inv_transpose_func_def2 type_fact13 by force\n            show \"eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c\n    (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n           leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> : \\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c \\<rightarrow> \\<Omega>\"\n              using flat_type inv_transpose_func_def2 type_fact14 by force\n            show \"\\<And>x. x \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c \\<Longrightarrow>\n         (eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n          (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                  leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c\n          successor) \\<circ>\\<^sub>c x =\n         (eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c\n          (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                  leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>c x\"\n            proof -\n              fix x \n              assume x_is: \"x \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\"\n              have x_cart: \"\\<exists>n m. n \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> m \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> x = \\<langle>n,m\\<rangle>\"\n                using cart_prod_decomp x_is by blast\n              obtain n where n_def: \"\\<exists>m. n \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> m \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> x = \\<langle>n,m\\<rangle>\"\n                using x_cart by blast\n              obtain m where m_def: \"n \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> m \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> x = \\<langle>n,m\\<rangle>\"\n                using n_def by blast\n\n              \n              \n\n\n\n              have nsm_type: \"\\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle> \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\"\n                by (simp add: cfunc_prod_type m_def succ_n_type)\n              have smn_type: \"\\<langle>successor \\<circ>\\<^sub>c m,n\\<rangle> \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>c \\<nat>\\<^sub>c\"\n                by (simp add: cfunc_prod_type m_def succ_n_type)\n\n              have \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n          (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                  leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c\n          successor) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> =\n         (eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c\n          (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                  leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\"\n              proof(cases \"leq \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> = \\<f> \\<and>  leq \\<circ>\\<^sub>c \\<langle>m,n\\<rangle> = \\<f>\", auto)  \n                assume \"leq \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> = \\<f>\"\n                assume \"leq \\<circ>\\<^sub>c \\<langle>m,n\\<rangle> = \\<f>\"\n\n                have \"(leq \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle> = \\<f>)  \\<and> (leq \\<circ>\\<^sub>c \\<langle>successor \\<circ>\\<^sub>c m,n\\<rangle> = \\<f>)\"\n                 proof(rule ccontr,auto)\n                   assume  \"leq \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle> \\<noteq> \\<f>\"\n                   then have \"leq \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle> = \\<t>\"\n                     using  comp_type leq_type nsm_type true_false_only_truth_values by blast\n                   then have j_exists: \"\\<exists> j. j \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> n +\\<^sub>\\<nat> j = successor \\<circ>\\<^sub>c m\"\n                     by (metis add_commutes leq_true_implies_exists m_def succ_n_type)\n                   obtain j where j_def: \"j \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> n +\\<^sub>\\<nat> j = successor \\<circ>\\<^sub>c m\"\n                     using j_exists by blast\n                   have \"n +\\<^sub>\\<nat> j =  m +\\<^sub>\\<nat> (successor \\<circ>\\<^sub>c zero)\"\n                     by (simp add: add_respects_succ1 add_respects_zero_on_right j_def m_def zero_type)\n                   have \"leq \\<circ>\\<^sub>c \\<langle>m,n\\<rangle> = \\<t>\"\n                   proof (cases \"j = zero\")\n                     assume \"j = zero\"  \n                     have \"n = m +\\<^sub>\\<nat> (successor \\<circ>\\<^sub>c zero)\"\n                       using \\<open>j = zero\\<close> \\<open>n +\\<^sub>\\<nat> j = m +\\<^sub>\\<nat> (successor \\<circ>\\<^sub>c zero)\\<close> add_respects_zero_on_right m_def by auto\n                     then have \"n = (successor \\<circ>\\<^sub>c zero) +\\<^sub>\\<nat> m\"\n                       using add_commutes m_def succ_n_type zero_type by blast\n                     then have \"\\<exists>p. p \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> n = p +\\<^sub>\\<nat> m\"\n                       using succ_n_type zero_type by blast\n                     then show ?thesis\n                       using exists_implies_leq_true m_def by blast\n                   next\n                     assume \"j \\<noteq> zero\"\n                     then have \"\\<exists> p. (p \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> j = successor \\<circ>\\<^sub>c p) \"\n                       using  j_def nonzero_is_succ by auto\n                     then obtain p where p_def: \"p \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> j = successor \\<circ>\\<^sub>c p\"\n                       by blast\n                     have \"successor \\<circ>\\<^sub>c m = n +\\<^sub>\\<nat> j\"\n                       by (simp add: j_def)\n                     also have \"... = n +\\<^sub>\\<nat> (successor \\<circ>\\<^sub>c p)\"\n                       by (simp add: p_def)\n                     also have \"... = successor \\<circ>\\<^sub>c (n +\\<^sub>\\<nat> p)\"\n                       by (simp add: add_respects_succ1 m_def p_def)\n                     then  have \"successor \\<circ>\\<^sub>c m = successor \\<circ>\\<^sub>c (n +\\<^sub>\\<nat> p)\"\n                       using calculation by auto\n                     then have \"m = n +\\<^sub>\\<nat> p\"\n                       by (simp add: add_type m_def p_def succ_inject)\n                     then have \"... = p +\\<^sub>\\<nat> n\"\n                       using add_commutes m_def p_def by blast\n                     then have \"\\<exists>p. (p \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> m = p +\\<^sub>\\<nat> n)\"\n                       using \\<open>m = n +\\<^sub>\\<nat> p\\<close> p_def by blast\n                     then show ?thesis\n                       using \\<open>leq \\<circ>\\<^sub>c \\<langle>m,n\\<rangle> = \\<f>\\<close> \\<open>leq \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> = \\<f>\\<close> exists_implies_leq_true m_def by force\n                   qed\n                   then show False\n                     using \\<open>leq \\<circ>\\<^sub>c \\<langle>m,n\\<rangle> = \\<f>\\<close> true_false_distinct by auto\n                 \n                 next\n                   assume \"leq \\<circ>\\<^sub>c \\<langle>successor \\<circ>\\<^sub>c m,n\\<rangle> \\<noteq> \\<f>\"\n                   then have \"leq \\<circ>\\<^sub>c \\<langle>successor \\<circ>\\<^sub>c m,n\\<rangle> = \\<t>\"\n                     using  comp_type leq_type smn_type true_false_only_truth_values by blast\n                   then show False\n                     by (metis \\<open>leq \\<circ>\\<^sub>c \\<langle>m,n\\<rangle> = \\<f>\\<close>  add_respects_succ2 exists_implies_leq_true leq_true_implies_exists m_def succ_n_type true_false_distinct)\n                 qed\n                 \n\n\n\n\n              have \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n          (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                  leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c\n          successor) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>= \n                  (eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n                            (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                                    leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>c\n                           (id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f successor) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\"\n                by (typecheck_cfuncs, smt cfunc_type_def comp_associative inv_transpose_func_def2 inv_transpose_of_composition m_def)\n                also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                                    leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>\\<circ>\\<^sub>c\n                           (id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f successor) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\" \n                by (typecheck_cfuncs, smt cfunc_type_def comp_associative m_def transpose_func_def)\n                also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                                    leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>\\<circ>\\<^sub>c\n                            \\<langle>id\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c n,successor \\<circ>\\<^sub>c m\\<rangle>\" \n                  using cfunc_cross_prod_comp_cfunc_prod m_def by (typecheck_cfuncs, auto)\n                also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                                    leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>\\<circ>\\<^sub>c\n                            \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>\"\n                  using id_left_unit2 m_def by auto \n                also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle> ,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>\\<rangle>  ,\n                                    leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>   ,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>  \\<rangle>  \\<rangle>\"\n                  using nsm_type by (typecheck_cfuncs, smt cfunc_prod_comp comp_associative2)\n               also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>n ,successor \\<circ>\\<^sub>c m\\<rangle>  ,  leq \\<circ>\\<^sub>c \\<langle>successor \\<circ>\\<^sub>c m  ,n  \\<rangle>\\<rangle>\"\n                 using left_cart_proj_cfunc_prod m_def right_cart_proj_cfunc_prod succ_n_type by auto     \n               also have \"... =  \\<f>\"\n                 by (simp add: OR_false_false_is_false \\<open>leq \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle> = \\<f> \\<and> leq \\<circ>\\<^sub>c \\<langle>successor \\<circ>\\<^sub>c m,n\\<rangle> = \\<f>\\<close>)\n\n               have \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c\n          (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                  leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> = \\<f>\"\n               proof -\n                 have \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c\n                  (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                      leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> = \n                    OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                      leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle> \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\"\n                   by (typecheck_cfuncs, smt comp_associative2 id_left_unit2 m_def transpose_func_def x_is)\n                 also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>  ,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> \\<rangle>,\n                    leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c  \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> ,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> \\<rangle>\\<rangle> \"\n                   by (typecheck_cfuncs , smt cfunc_prod_comp comp_associative2 m_def x_is)\n                 also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>n  ,m  \\<rangle>, leq \\<circ>\\<^sub>c \\<langle>m ,n \\<rangle>\\<rangle> \"\n                    by (typecheck_cfuncs, metis left_cart_proj_cfunc_prod m_def right_cart_proj_cfunc_prod)                             \n                 also have \"... =  \\<f>\"\n                    by (simp add: OR_false_false_is_false \\<open>leq \\<circ>\\<^sub>c \\<langle>m,n\\<rangle> = \\<f>\\<close> \\<open>leq \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> = \\<f>\\<close>)\n                 then show ?thesis\n                   using calculation by auto\n               qed\n\n               then show ?thesis\n                 using \\<open>OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>successor \\<circ>\\<^sub>c m,n\\<rangle>\\<rangle> = \\<f>\\<close> calculation by presburger\n              \n              next\n                assume \"leq \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> \\<noteq> \\<f>\"\n                then have \"leq \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> = \\<t>\"\n                  using  m_def true_false_only_truth_values by (typecheck_cfuncs, blast)\n\n                then have \"leq \\<circ>\\<^sub>c \\<langle>n ,successor \\<circ>\\<^sub>c m\\<rangle> = \\<t>\"\n                  by (metis add_respects_succ3 exists_implies_leq_true leq_true_implies_exists m_def succ_n_type)\n                \n                \n                have \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n          (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                  leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c\n          successor) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>= \n                  (eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n                            (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                                    leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>c\n                           (id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f successor) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\"\n                by (typecheck_cfuncs, smt cfunc_type_def comp_associative inv_transpose_func_def2 inv_transpose_of_composition m_def)\n                also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                                    leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>\\<circ>\\<^sub>c\n                           (id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f successor) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\" \n                by (typecheck_cfuncs, smt cfunc_type_def comp_associative m_def transpose_func_def)\n                also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                                    leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>\\<circ>\\<^sub>c\n                            \\<langle>id\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c n,successor \\<circ>\\<^sub>c m\\<rangle>\" \n                  using cfunc_cross_prod_comp_cfunc_prod m_def by (typecheck_cfuncs, auto)\n                also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                                    leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>\\<circ>\\<^sub>c\n                            \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>\"\n                  using id_left_unit2 m_def by auto \n                also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle> ,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>\\<rangle>  ,\n                                    leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>   ,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>  \\<rangle>  \\<rangle>\"\n                  using nsm_type by (typecheck_cfuncs, smt cfunc_prod_comp comp_associative2)\n               also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>n ,successor \\<circ>\\<^sub>c m\\<rangle>  ,  leq \\<circ>\\<^sub>c \\<langle>successor \\<circ>\\<^sub>c m  ,n  \\<rangle>\\<rangle>\"\n                 using left_cart_proj_cfunc_prod m_def right_cart_proj_cfunc_prod succ_n_type by auto     \n               also have \"... =  \\<t>\"\n                 using OR_true_left_is_true \\<open>leq \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle> = \\<t>\\<close> comp_type leq_type smn_type by auto\n\n              have \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c\n          (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                  leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> = \\<t>\"\n              proof -\n               have \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c\n          (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                  leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> = \n                OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                  leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle> \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\"\n                 by (typecheck_cfuncs, smt comp_associative2 id_left_unit2 m_def transpose_func_def x_is)\n               also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>  ,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> \\<rangle>,\n                  leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c  \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> ,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> \\<rangle>\\<rangle> \"\n                 by (typecheck_cfuncs , smt cfunc_prod_comp comp_associative2 m_def x_is)\n               also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>n  ,m  \\<rangle>, leq \\<circ>\\<^sub>c \\<langle>m ,n \\<rangle>\\<rangle> \"\n                 by (typecheck_cfuncs, metis left_cart_proj_cfunc_prod m_def right_cart_proj_cfunc_prod)                             \n               also have \"... =  \\<t>\"\n                 by (typecheck_cfuncs, simp add: OR_true_left_is_true \\<open>leq \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> = \\<t>\\<close> m_def)\n\n                then show ?thesis\n                  by (simp add: \\<open>(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle> \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\\<close> \\<open>OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\\<rangle>\\<rangle> = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>m,n\\<rangle>\\<rangle>\\<close> \\<open>OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle> \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\\<rangle>\\<rangle>\\<close> \\<open>OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>successor \\<circ>\\<^sub>c m,n\\<rangle>\\<rangle> = \\<t>\\<close> calculation)\n\n              next\n                assume \"leq \\<circ>\\<^sub>c \\<langle>m,n\\<rangle> \\<noteq> \\<f>\"\n                then have \"leq \\<circ>\\<^sub>c \\<langle>m,n\\<rangle> = \\<t>\"\n                  using  m_def true_false_only_truth_values by (typecheck_cfuncs, blast)\n\n   then have \"leq \\<circ>\\<^sub>c \\<langle>m ,successor \\<circ>\\<^sub>c n\\<rangle> = \\<t>\"\n                  by (metis add_respects_succ3 exists_implies_leq_true leq_true_implies_exists m_def succ_n_type)\n                \n                \n                have \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n          (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                  leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c\n          successor) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>= \n                  (eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n                            (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                                    leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>c\n                           (id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f successor) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\"\n                by (typecheck_cfuncs, smt cfunc_type_def comp_associative inv_transpose_func_def2 inv_transpose_of_composition m_def)\n                also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                                    leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>\\<circ>\\<^sub>c\n                           (id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f successor) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\" \n                by (typecheck_cfuncs, smt cfunc_type_def comp_associative m_def transpose_func_def)\n                also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                                    leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>\\<circ>\\<^sub>c\n                            \\<langle>id\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c n,successor \\<circ>\\<^sub>c m\\<rangle>\" \n                  using cfunc_cross_prod_comp_cfunc_prod m_def by (typecheck_cfuncs, auto)\n                also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                                    leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>\\<circ>\\<^sub>c\n                            \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>\"\n                  using id_left_unit2 m_def by auto \n                also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle> ,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>\\<rangle>  ,\n                                    leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>   ,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>  \\<rangle>  \\<rangle>\"\n                  using nsm_type by (typecheck_cfuncs, smt cfunc_prod_comp comp_associative2)\n               also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>n ,successor \\<circ>\\<^sub>c m\\<rangle>  ,  leq \\<circ>\\<^sub>c \\<langle>successor \\<circ>\\<^sub>c m  ,n  \\<rangle>\\<rangle>\"\n                 using left_cart_proj_cfunc_prod m_def right_cart_proj_cfunc_prod succ_n_type by auto     \n               also have \"... =  \\<t>\"\n                 using OR_true_left_is_true \\<open>leq \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle> = \\<t>\\<close> comp_type leq_type smn_type by auto\n\n              have \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c\n          (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                  leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> = \\<t>\"\n              proof -\n                have \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c\n          (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                  leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> = \n                OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                  leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle> \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\"\n                 by (typecheck_cfuncs, smt comp_associative2 id_left_unit2 m_def transpose_func_def x_is)\n                also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>  ,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> \\<rangle>,\n                  leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c  \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> ,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> \\<rangle>\\<rangle> \"\n                 by (typecheck_cfuncs , smt cfunc_prod_comp comp_associative2 m_def x_is)\n                also have \"... = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>n  ,m  \\<rangle>, leq \\<circ>\\<^sub>c \\<langle>m ,n \\<rangle>\\<rangle> \"\n                  by (typecheck_cfuncs, metis left_cart_proj_cfunc_prod m_def right_cart_proj_cfunc_prod)                             \n                also have \"... =  \\<t>\"\n                  using OR_true_right_is_true \\<open>leq \\<circ>\\<^sub>c \\<langle>m,n\\<rangle> = \\<t>\\<close> comp_type leq_type m_def x_is by auto\n                then show ?thesis\n                  using calculation by auto\n              qed\n            qed\n            then show \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c\n     id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n     (OR \\<circ>\\<^sub>c\n      \\<langle>leq \\<circ>\\<^sub>c\n       \\<langle>left_cart_proj \\<nat>\\<^sub>c\n         \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c\n     successor) \\<circ>\\<^sub>c\n    \\<langle>n,m\\<rangle> =\n    (eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c\n     id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n     id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c\n     (OR \\<circ>\\<^sub>c\n      \\<langle>leq \\<circ>\\<^sub>c\n       \\<langle>left_cart_proj \\<nat>\\<^sub>c\n         \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>c\n    \\<langle>n,m\\<rangle>\"\n              by (simp add: \\<open>OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>successor \\<circ>\\<^sub>c m,n\\<rangle>\\<rangle> = \\<t>\\<close> calculation)\n          next\n            assume \"leq \\<circ>\\<^sub>c \\<langle>m,n\\<rangle> \\<noteq> \\<f>\"\n            then have m_leq_n: \"leq \\<circ>\\<^sub>c \\<langle>m,n\\<rangle> = \\<t>\"\n              by (meson cfunc_prod_type comp_type leq_type m_def true_false_only_truth_values)\n            then have main_inequality: \"OR \\<circ>\\<^sub>c \\<langle>  leq \\<circ>\\<^sub>c \\<langle>n, successor \\<circ>\\<^sub>c m\\<rangle>, leq \\<circ>\\<^sub>c \\<langle> successor \\<circ>\\<^sub>c m, n\\<rangle>\\<rangle>= \\<t>\"\n            proof(cases \"m = n\")\n              assume \"m = n\"\n              then have \"leq \\<circ>\\<^sub>c \\<langle>n, successor \\<circ>\\<^sub>c m\\<rangle> = \\<t>\"\n                by (typecheck_cfuncs, metis add_respects_succ3 add_respects_zero_on_left exists_implies_leq_true m_def succ_n_type zero_type)\n              then show ?thesis\n                using OR_true_left_is_true comp_type leq_type smn_type by presburger\n            next \n              assume \"m \\<noteq> n\"\n              then obtain k where k_def: \"k \\<in>\\<^sub>c \\<nat>\\<^sub>c \\<and> n = m +\\<^sub>\\<nat> k \\<and> k \\<noteq> zero\"\n                by (metis m_leq_n add_commutes add_respects_zero_on_right leq_true_implies_exists m_def)\n              then have \"leq \\<circ>\\<^sub>c \\<langle> successor \\<circ>\\<^sub>c m, n\\<rangle> = \\<t>\"\n              proof - \n                have \"leq \\<circ>\\<^sub>c  \\<langle>m +\\<^sub>\\<nat> (successor \\<circ>\\<^sub>c zero), n \\<rangle> = \\<t>\"\n                  by (smt (verit, ccfv_SIG) add_commutes add_respects_succ3 add_respects_zero_on_left exists_implies_leq_true k_def m_def nonzero_is_succ succ_n_type zero_type)\n                then show ?thesis\n                  by (simp add: add_respects_succ1 add_respects_zero_on_right m_def zero_type)\n              qed\n              then show ?thesis\n                using OR_true_right_is_true comp_type leq_type nsm_type by presburger\n            qed\n            \n\n\n\n\n             show \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c\n     id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n     (OR \\<circ>\\<^sub>c\n      \\<langle>leq \\<circ>\\<^sub>c\n       \\<langle>left_cart_proj \\<nat>\\<^sub>c\n         \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c\n     successor) \\<circ>\\<^sub>c\n    \\<langle>n,m\\<rangle> = \n    (eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c\n     id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n     id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c\n     (OR \\<circ>\\<^sub>c\n      \\<langle>leq \\<circ>\\<^sub>c\n       \\<langle>left_cart_proj \\<nat>\\<^sub>c\n         \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>c\n    \\<langle>n,m\\<rangle>\"\n             \n          proof - \n                            have \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c\n                   id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n                   (OR \\<circ>\\<^sub>c\n                    \\<langle>leq \\<circ>\\<^sub>c\n                     \\<langle>left_cart_proj \\<nat>\\<^sub>c\n                       \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c\n                   successor) \\<circ>\\<^sub>c\n                  \\<langle>n,m\\<rangle> = ((eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c\n                   id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n                   (OR \\<circ>\\<^sub>c\n                    \\<langle>leq \\<circ>\\<^sub>c\n                     \\<langle>left_cart_proj \\<nat>\\<^sub>c\n                       \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>c\n                  id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f successor) \\<circ>\\<^sub>c\n                  \\<langle>n,m\\<rangle>\"\n                              using sharp_comp transpose_func_def by (typecheck_cfuncs,force)\n                            also have \"... = (OR \\<circ>\\<^sub>c\n                    \\<langle>leq \\<circ>\\<^sub>c\n                     \\<langle>left_cart_proj \\<nat>\\<^sub>c\n                       \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<circ>\\<^sub>c\n                  ((id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f successor) \\<circ>\\<^sub>c\n                  \\<langle>n,m\\<rangle>)\"\n                              by (typecheck_cfuncs, smt (verit, best) comp_associative2 m_def transpose_func_def)\n              also have \"... = (OR \\<circ>\\<^sub>c\n                    \\<langle>leq \\<circ>\\<^sub>c\n                     \\<langle>left_cart_proj \\<nat>\\<^sub>c\n                       \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<circ>\\<^sub>c\n                  \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>\"\n                using cfunc_cross_prod_comp_cfunc_prod id_left_unit2 m_def by (typecheck_cfuncs, force)\n                also have \"... = OR \\<circ>\\<^sub>c \\<langle>\n              leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle> \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>,\n              leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle> \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>\n              \\<rangle>\"\n                  by (typecheck_cfuncs, smt (verit, best) cfunc_prod_comp comp_associative2 nsm_type)\n              also have \"... = OR \\<circ>\\<^sub>c \\<langle>\n              leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle> ,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>\\<rangle> ,\n              leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>n,successor \\<circ>\\<^sub>c m\\<rangle>\\<rangle> \n              \\<rangle>\"\n                using cfunc_prod_comp nsm_type by (typecheck_cfuncs, force)\n              also have \"... =  OR \\<circ>\\<^sub>c \\<langle>  leq \\<circ>\\<^sub>c \\<langle>n, successor \\<circ>\\<^sub>c m\\<rangle>, leq \\<circ>\\<^sub>c \\<langle> successor \\<circ>\\<^sub>c m, n\\<rangle>\\<rangle>\"\n                using left_cart_proj_cfunc_prod m_def right_cart_proj_cfunc_prod by (typecheck_cfuncs, force)\n              also have \"... = OR \\<circ>\\<^sub>c \\<langle>  leq \\<circ>\\<^sub>c \\<langle>n,  m\\<rangle>, leq \\<circ>\\<^sub>c \\<langle>  m, n\\<rangle>\\<rangle>\"\n                using OR_true_right_is_true main_inequality comp_type leq_type m_def m_leq_n x_is by presburger\n               also have \"... = OR \\<circ>\\<^sub>c\n                    \\<langle>leq \\<circ>\\<^sub>c\n                     \\<langle>left_cart_proj \\<nat>\\<^sub>c\n                       \\<nat>\\<^sub>c  \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c  \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c  \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c  \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\\<rangle>\\<rangle>\"\n                 by (typecheck_cfuncs, metis left_cart_proj_cfunc_prod m_def right_cart_proj_cfunc_prod)\n               also have \"... = OR \\<circ>\\<^sub>c\n                    \\<langle>leq \\<circ>\\<^sub>c\n                     \\<langle>left_cart_proj \\<nat>\\<^sub>c\n                       \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle> \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\"\n                 by (typecheck_cfuncs, smt (z3) cfunc_prod_comp comp_associative2 m_def x_is)\n               also have \"... = (OR \\<circ>\\<^sub>c\n                    \\<langle>leq \\<circ>\\<^sub>c\n                     \\<langle>left_cart_proj \\<nat>\\<^sub>c\n                       \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\"\n                 by (typecheck_cfuncs, meson comp_associative2 m_def)\n              \n              \n               also have \"... = (eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c\n                   id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n                   (OR \\<circ>\\<^sub>c\n                    \\<langle>leq \\<circ>\\<^sub>c\n                     \\<langle>left_cart_proj \\<nat>\\<^sub>c\n                       \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>c\n                  \\<langle>n,m\\<rangle>\"\n                 using transpose_func_def by (typecheck_cfuncs, presburger)\n              \n               also have \"... = (eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c\n                   id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n                   id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c\n                   (OR \\<circ>\\<^sub>c\n                    \\<langle>leq \\<circ>\\<^sub>c\n                     \\<langle>left_cart_proj \\<nat>\\<^sub>c\n                       \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>c\n                  \\<langle>n,m\\<rangle>\"\n                 using id_left_unit2 by (typecheck_cfuncs, presburger)\n                then show ?thesis\n                  by (simp add: calculation)\n              qed\n            qed\n\n\n\n \n\n\n              show \"(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f\n          (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                  leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c\n          successor) \\<circ>\\<^sub>c x =\n         (eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c\n          (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\n                  leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>c x\"\n                using \\<open>(eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp> \\<circ>\\<^sub>c successor) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle> = (eval_func \\<Omega> \\<nat>\\<^sub>c \\<circ>\\<^sub>c id\\<^sub>c \\<nat>\\<^sub>c \\<times>\\<^sub>f id\\<^sub>c (\\<Omega>\\<^bsup>\\<nat>\\<^sub>c\\<^esup>) \\<circ>\\<^sub>c (OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>)\\<^sup>\\<sharp>) \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\\<close> m_def by force\n           \n            qed\n\n          qed\n\n        qed\n      qed\n\nhave flat_main_result: \"(OR \\<circ>\\<^sub>c \\<langle>\nleq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c, right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\nleq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c, left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\n\\<rangle>) = (\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c\\<times>\\<^sub>c\\<nat>\\<^sub>c\\<^esub>)\"\n  by (typecheck_cfuncs, metis main_result transpose_func_def)\n\n\n  have \"(\\<t> \\<circ>\\<^sub>c \\<beta>\\<^bsub>\\<nat>\\<^sub>c\\<times>\\<^sub>c\\<nat>\\<^sub>c\\<^esub>) \\<circ>\\<^sub>c \\<langle>m,n\\<rangle> = \\<t>\"  \n    using assms by (typecheck_cfuncs,  smt comp_associative2 id_right_unit2 id_type one_unique_element terminal_func_comp terminal_func_type)\n  then  have \"(OR \\<circ>\\<^sub>c \\<langle>\nleq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c, right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\nleq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c, left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\n\\<rangle>) \\<circ>\\<^sub>c \\<langle>m,n\\<rangle> = \\<t>\"\n    by (simp add: flat_main_result)  \n  have \"(OR \\<circ>\\<^sub>c \\<langle>\nleq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c, right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,\nleq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c, left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\n\\<rangle>) \\<circ>\\<^sub>c \\<langle>m,n\\<rangle> = \nOR \\<circ>\\<^sub>c \\<langle>\nleq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c  \\<circ>\\<^sub>c \\<langle>m,n\\<rangle> , right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c   \\<circ>\\<^sub>c \\<langle>m,n\\<rangle>\\<rangle>,\nleq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>m,n\\<rangle>, left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>m,n\\<rangle>\\<rangle>\n\\<rangle>\"\n    using assms by (typecheck_cfuncs , smt cfunc_prod_comp comp_associative2)\n  also have \"... = OR \\<circ>\\<^sub>c \\<langle> leq \\<circ>\\<^sub>c \\<langle>m , n\\<rangle>, leq \\<circ>\\<^sub>c \\<langle>n, m\\<rangle>\\<rangle>\"\n    using left_cart_proj_cfunc_prod m_type n_type right_cart_proj_cfunc_prod by auto\n\n  then  have \"OR \\<circ>\\<^sub>c \\<langle> leq \\<circ>\\<^sub>c \\<langle>m , n\\<rangle>, leq \\<circ>\\<^sub>c \\<langle>n, m\\<rangle>\\<rangle> = \\<t>\"\n    using \\<open>(OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c\\<rangle>\\<rangle>) \\<circ>\\<^sub>c \\<langle>m,n\\<rangle> = \\<t>\\<close> \\<open>OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>m,n\\<rangle>,right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>m,n\\<rangle>\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>right_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>m,n\\<rangle>,left_cart_proj \\<nat>\\<^sub>c \\<nat>\\<^sub>c \\<circ>\\<^sub>c \\<langle>m,n\\<rangle>\\<rangle>\\<rangle> = OR \\<circ>\\<^sub>c \\<langle>leq \\<circ>\\<^sub>c \\<langle>m,n\\<rangle>,leq \\<circ>\\<^sub>c \\<langle>n,m\\<rangle>\\<rangle>\\<close> calculation by presburger\n\n  then show ?thesis\n    using OR_true_implies_one_is_true cfunc_prod_type comp_type leq_type m_type n_type by blast\nqed\n\n\n\n\n\nend", "meta": {"author": "jameseb7", "repo": "Isabelle-ETCS", "sha": "ae81dc674faf7cca62b30ac53888b3d319160849", "save_path": "github-repos/isabelle/jameseb7-Isabelle-ETCS", "path": "github-repos/isabelle/jameseb7-Isabelle-ETCS/Isabelle-ETCS-ae81dc674faf7cca62b30ac53888b3d319160849/ETCS_Comparison.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6959583250334526, "lm_q2_score": 0.40733340004593027, "lm_q1q2_score": 0.2834870708261469}}
{"text": "theory Balance\n  imports \n    \"../Utilities\"\n    Balance_Adapted\nbegin\n\n\ncontext rbt_impl\nbegin\ninterpretation rbt_impl_deps .\n\n\nsubsection \\<open>Checks\\<close>\n\n\ndefinition \"check_1 lhs_p rhs_p \\<equiv> is_red lhs_p &&! is_red rhs_p\"\ndefinition \"check_2 lhs_p rhs_p \\<equiv> is_red lhs_p &&! (do {l \\<leftarrow> left lhs_p; is_red l})\"\ndefinition \"check_3 lhs_p rhs_p \\<equiv> is_red lhs_p &&! (do {r \\<leftarrow> right lhs_p; is_red r})\"\ndefinition \"check_4 lhs_p rhs_p \\<equiv> is_red rhs_p &&! (do {r \\<leftarrow> right rhs_p; is_red r})\"\ndefinition \"check_5 lhs_p rhs_p \\<equiv> is_red rhs_p &&! (do {l \\<leftarrow> left rhs_p; is_red l})\"\n\n\nlemma check_1_correct [vcg_rules]:\n  \"\n    llvm_htriple\n    (rbt_assn lhs lhsi ** rbt_assn rhs rhsi)\n    (check_1 lhsi rhsi)\n    (\\<lambda>r. rbt_assn lhs lhsi ** rbt_assn rhs rhsi ** \\<upharpoonleft>bool.assn(rbt_check_1 lhs rhs) r)\n  \"\n  unfolding rbt_check_1_def check_1_def sc_and_def\n  apply vcg \n  unfolding rbt_is_red_def\n   apply vcg\n  done\n\n\nlemma check_2_correct [vcg_rules]:\n  \"\n    llvm_htriple\n    (rbt_assn lhs lhsi ** rbt_assn rhs rhsi)\n    (check_2 lhsi rhsi)\n    (\\<lambda>r. rbt_assn lhs lhsi ** rbt_assn rhs rhsi ** \\<upharpoonleft>bool.assn (rbt_check_2 lhs rhs) r)\n  \"\n  unfolding rbt_check_2_def check_2_def sc_and_def\n  apply vcg\n  subgoal\n    unfolding rbt_is_red_def rbt_left_def\n    apply vcg_try_solve\n    done \n  subgoal by vcg\n  done\n\n\nlemma check_3_correct [vcg_rules]:\n  \"\n    llvm_htriple\n    (rbt_assn lhs lhsi ** rbt_assn rhs rhsi)\n    (check_3 lhsi rhsi)\n    (\\<lambda>r. rbt_assn lhs lhsi ** rbt_assn rhs rhsi ** \\<upharpoonleft>bool.assn(rbt_check_3 lhs rhs) r)\n  \"\n  unfolding rbt_check_3_def check_3_def sc_and_def\n  apply vcg\n  subgoal\n    unfolding rbt_is_red_def rbt_right_def\n    apply vcg_try_solve\n    done \n  subgoal by vcg\n  done\n\n\nlemma check_4_correct [vcg_rules]:\n  \"\n    llvm_htriple\n    (rbt_assn lhs lhsi ** rbt_assn rhs rhsi)\n    (check_4 lhsi rhsi)\n    (\\<lambda>r. rbt_assn lhs lhsi ** rbt_assn rhs rhsi ** \\<upharpoonleft>bool.assn(rbt_check_4 lhs rhs) r)\n  \"\n  unfolding rbt_check_4_def check_4_def sc_and_def\n  apply vcg\n  subgoal\n    unfolding rbt_is_red_def rbt_right_def\n    apply vcg_try_solve\n    done \n  subgoal by vcg\n  done\n\n\nlemma check_5_correct [vcg_rules]:\n  \"\n    llvm_htriple\n    (rbt_assn lhs lhsi ** rbt_assn rhs rhsi)\n    (check_5 lhsi rhsi)\n    (\\<lambda>r. rbt_assn lhs lhsi ** rbt_assn rhs rhsi ** \\<upharpoonleft>bool.assn(rbt_check_5 lhs rhs) r)\n  \"\n  unfolding rbt_check_5_def check_5_def sc_and_def\n  apply vcg\n  subgoal\n    unfolding rbt_is_red_def rbt_left_def\n    apply vcg_try_solve\n    done \n  subgoal by vcg\n  done\n\n\nlemmas [llvm_inline] = \n  check_1_def            \n  check_2_def\n  check_3_def\n  check_4_def\n  check_5_def\n\n\nsubsection \\<open>Balance Cases\\<close>\n\n\ndefinition \"balance_ad_case_1 lhs_p k v rhs_p \\<equiv> do {\n  set_color_p 1 lhs_p;\n  set_color_p 1 rhs_p;\n  new (RBT_NODE 0 lhs_p k v rhs_p)\n}\"\n\nthm set_color_p_def[simplified mod_ptr_def]\nschematic_goal \"set_color_p color node_ptr = X ?X\"\n  unfolding set_color_p_def mod_ptr_def\n  apply simp\n  oops\n\nlemma balance_ad_case_1_correct [vcg_rules]:\n  \"\n    llvm_htriple\n    (rbt_assn lhs lhsi ** rbt_assn rhs rhsi ** \\<upharpoonleft>key_assn k ki ** \\<upharpoonleft>value_assn v vi ** \\<up>(rbt_check_1 lhs rhs))\n    (balance_ad_case_1 lhsi ki vi rhsi)\n    (\\<lambda>r. rbt_assn (rbt_balance_ad_case_1 lhs k v rhs) r)\n  \"\n  unfolding balance_ad_case_1_def rbt_balance_ad_case_1_def new_def\n  apply vcg\n  apply (erule rbt_check_1_unfold)\n  apply vcg\n  done\n\n\ndefinition \"balance_ad_case_2 lhs_p k v rhs_p \\<equiv> do {\n  lhs \\<leftarrow> ll_load lhs_p;\n  case lhs of (RBT_NODE _ llhs_p s t c) \\<Rightarrow>\n  do {\n    llhs \\<leftarrow> ll_load llhs_p;\n    case llhs of (RBT_NODE _ a w x b) \\<Rightarrow>\n    let y = k; z = v; d = rhs_p in\n    do {\n      ll_free lhs_p;\n      ll_free llhs_p;\n      lhs_n \\<leftarrow> new (RBT_NODE 1 a w x b);\n      rhs_n \\<leftarrow> new (RBT_NODE 1 c y z d);\n      new (RBT_NODE 0 lhs_n s t rhs_n)\n    }\n  }\n}\"\n\n\nlemma balance_ad_case_2_correct [vcg_rules]: \n  \"\n    llvm_htriple\n    (rbt_assn lhs lhsi ** rbt_assn rhs rhsi ** \\<upharpoonleft>key_assn k ki ** \\<upharpoonleft>value_assn v vi ** \\<up>(rbt_check_2 lhs rhs))\n    (balance_ad_case_2 lhsi ki vi rhsi)\n    (\\<lambda>r. rbt_assn (rbt_balance_ad_case_2 lhs k v rhs) r)\n  \"\n  unfolding balance_ad_case_2_def rbt_balance_ad_case_2_def new_def\n  apply vcg\n  apply (erule rbt_check_2_unfold)\n  apply vcg\n  done\n\nfind_theorems rbt_assn is_rbt\n\n\ndefinition \"balance_ad_case_3 lhs_p k v rhs_p \\<equiv> do {\n  lhs \\<leftarrow> ll_load lhs_p;\n  case lhs of (RBT_NODE _ a w x rlhs_p) \\<Rightarrow>\n  do {\n    rlhs \\<leftarrow> ll_load rlhs_p;\n    case rlhs of (RBT_NODE _ b s t c) \\<Rightarrow>\n    let y = k; z = v; d = rhs_p in\n    do {\n      ll_free lhs_p;\n      ll_free rlhs_p;\n      lhs_n \\<leftarrow> new (RBT_NODE 1 a w x b);\n      rhs_n \\<leftarrow> new (RBT_NODE 1 c y z d);\n      new (RBT_NODE 0 lhs_n s t rhs_n)\n    }\n  }\n}\"\n\n\nlemma balance_ad_case_3_correct [vcg_rules]: \n  \"\n    llvm_htriple\n    (rbt_assn lhs lhsi ** rbt_assn rhs rhsi ** \\<upharpoonleft>key_assn k ki ** \\<upharpoonleft>value_assn v vi ** \\<up>(rbt_check_3 lhs rhs))\n    (balance_ad_case_3 lhsi ki vi rhsi)\n    (\\<lambda>r. rbt_assn (rbt_balance_ad_case_3 lhs k v rhs) r)\n  \"\n  unfolding balance_ad_case_3_def rbt_balance_ad_case_3_def new_def\n  apply vcg\n  apply (erule rbt_check_3_unfold)\n  apply vcg\n  done\n\n\ndefinition \"balance_ad_case_4 l_p k v r_p \\<equiv> do {\n  let a=l_p; w=k; x=v in\n  do {    \n    r \\<leftarrow> ll_load r_p;\n    case r of (RBT_NODE _ b s t rr_p) \\<Rightarrow> \n    do {\n      rr \\<leftarrow> ll_load rr_p;\n      case rr of (RBT_NODE _ c y z d) \\<Rightarrow> \n      do {\n        ll_free r_p;\n        ll_free rr_p;\n        lhs_n \\<leftarrow> new (RBT_NODE 1 a w x b);\n        rhs_n \\<leftarrow> new (RBT_NODE 1 c y z d);\n        new (RBT_NODE 0 lhs_n s t rhs_n)\n      }\n    }\n  }\n}\"\n\n\nlemma balance_ad_case_4_correct [vcg_rules]: \n  \"\n    llvm_htriple\n    (rbt_assn lhs lhsi ** rbt_assn rhs rhsi ** \\<upharpoonleft>key_assn k ki ** \\<upharpoonleft>value_assn v vi ** \\<up>(rbt_check_4 lhs rhs))\n    (balance_ad_case_4 lhsi ki vi rhsi)\n    (\\<lambda>r. rbt_assn (rbt_balance_ad_case_4 lhs k v rhs) r)\n  \"\n  unfolding balance_ad_case_4_def rbt_balance_ad_case_4_def new_def\n  apply vcg\n  apply (erule rbt_check_4_unfold)\n  apply vcg\n  done\n\n\ndefinition \"balance_ad_case_5 l_p k v r_p \\<equiv> do {\n  let a=l_p; w=k; x=v in\n  do {    \n    r \\<leftarrow> ll_load r_p;\n    case r of (RBT_NODE _ rl_p y z d) \\<Rightarrow> \n    do {\n      rl \\<leftarrow> ll_load rl_p;\n      case rl of (RBT_NODE _ b s t c) \\<Rightarrow> \n      do {\n        ll_free r_p;\n        ll_free rl_p;\n        lhs_n \\<leftarrow> new (RBT_NODE 1 a w x b);\n        rhs_n \\<leftarrow> new (RBT_NODE 1 c y z d);\n        new (RBT_NODE 0 lhs_n s t rhs_n)\n      }\n    }\n  }\n}\"\n\n\nlemma balance_ad_case_5_correct [vcg_rules]: \n  \"\n    llvm_htriple\n    (rbt_assn lhs lhsi ** rbt_assn rhs rhsi ** \\<upharpoonleft>key_assn k ki ** \\<upharpoonleft>value_assn v vi ** \\<up>(rbt_check_5 lhs rhs))\n    (balance_ad_case_5 lhsi ki vi rhsi)\n    (\\<lambda>r. rbt_assn (rbt_balance_ad_case_5 lhs k v rhs) r)\n  \"\n  unfolding balance_ad_case_5_def rbt_balance_ad_case_5_def new_def\n  apply vcg\n  apply (erule rbt_check_5_unfold)\n  apply vcg\n  done\n\n                                             \ndefinition \"balance_ad_case_6 l_p k v r_p \\<equiv> new (RBT_NODE 1 l_p k v r_p)\"\n\n\nlemma balance_ad_case_6_correct [vcg_rules]: \n  \"\n    llvm_htriple\n    (rbt_assn lhs lhsi ** rbt_assn rhs rhsi ** \\<upharpoonleft>key_assn k ki ** \\<upharpoonleft>value_assn v vi)\n    (balance_ad_case_6 lhsi ki vi rhsi)\n    (\\<lambda>r. rbt_assn (rbt_balance_ad_case_6 lhs k v rhs) r)\n  \"\n  unfolding balance_ad_case_6_def rbt_balance_ad_case_6_def\n  by vcg\n\n\nlemmas [llvm_code] = \n  balance_ad_case_1_def\n  balance_ad_case_2_def\n  balance_ad_case_3_def\n  balance_ad_case_4_def\n  balance_ad_case_5_def\n  balance_ad_case_6_def\n\n\nsubsection \\<open>Balance Function\\<close>\n\n\ndefinition balance ::\n  \"('ki, 'vi) rbti \\<Rightarrow> 'ki \\<Rightarrow> 'vi \\<Rightarrow> ('ki, 'vi) rbti \\<Rightarrow> ('ki, 'vi) rbti llM\" where\n  \"balance lhs_p k v rhs_p = do {\n      if! check_1 lhs_p rhs_p\n      then! balance_ad_case_1 lhs_p k v rhs_p\n      else! if! check_2 lhs_p rhs_p\n      then! balance_ad_case_2 lhs_p k v rhs_p\n      else! if! check_3 lhs_p rhs_p\n      then! balance_ad_case_3 lhs_p k v rhs_p\n      else! if! check_4 lhs_p rhs_p\n      then! balance_ad_case_4 lhs_p k v rhs_p\n      else! if! check_5 lhs_p rhs_p\n      then! balance_ad_case_5 lhs_p k v rhs_p\n      else! balance_ad_case_6 lhs_p k v rhs_p\n  }\"\n\n\nlemmas [llvm_code] = balance_def\n\n\nlemma balance_correct':\n  \"llvm_htriple\n  (\n    rbt_assn tree_l tree_li **\n    rbt_assn tree_r tree_ri **   \n    \\<upharpoonleft>key_assn k ki **\n    \\<upharpoonleft>value_assn v vi\n  )\n  (balance tree_li ki vi tree_ri)\n  (\\<lambda>ri. rbt_assn (rbt_balance_ad tree_l k v tree_r) ri) \n  \"\n  unfolding balance_def\n  by vcg\n\n\nlemma balance_correct [vcg_rules]:\n  \"llvm_htriple\n  (\n    rbt_assn l li **\n    rbt_assn r ri **   \n    \\<upharpoonleft>key_assn k ki **\n    \\<upharpoonleft>value_assn v vi\n  )\n  (balance li ki vi ri)\n  (\\<lambda>res. rbt_assn (rbt_balance l k v r) res) \n  \"\n  by (metis balance_correct' rbt_balance_ad_correct)\n\n\nend\n\n\nend", "meta": {"author": "leanderBehr", "repo": "isabelle-llvm-RBT", "sha": "9456c7160d0d190bdb3ac358bc0058d22fb19926", "save_path": "github-repos/isabelle/leanderBehr-isabelle-llvm-RBT", "path": "github-repos/isabelle/leanderBehr-isabelle-llvm-RBT/isabelle-llvm-RBT-9456c7160d0d190bdb3ac358bc0058d22fb19926/LLVM_DS_RBT/Insert/Balance.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5621765155565326, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.28328421511547436}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory Crunch_Test_NonDet\nimports\n  Lib.Crunch_Instances_NonDet\n  Crunch_Test_Qualified_NonDet\n  Lib.GenericLib\n  Lib.Defs\nbegin\n\ntext \\<open>Test cases for crunch\\<close>\n\ndefinition\n  \"crunch_foo1 (x :: nat) \\<equiv> do\n    modify ((+) x);\n    modify ((+) x)\n  od\"\n\ndefinition\n  \"crunch_foo2 \\<equiv> do\n    crunch_foo1 12;\n    crunch_foo1 13\n  od\"\n\ncrunch (empty_fail) empty_fail: crunch_foo2\n  (ignore: modify bind)\n\ncrunch_ignore (add: crunch_foo1)\n\ncrunch gt: crunch_foo2 \"\\<lambda>x. x > y\"\n  (ignore: modify bind ignore_del: crunch_foo1)\n\ncrunch_ignore (del: crunch_foo1)\n\ndefinition\n  \"crunch_always_true (x :: nat) \\<equiv> \\<lambda>y :: nat. True\"\n\nlemma crunch_foo1_at_2:\n  \"True \\<Longrightarrow> \\<lbrace>crunch_always_true 3 and crunch_always_true 2\\<rbrace>\n      crunch_foo1 x \\<lbrace>\\<lambda>rv. crunch_always_true 2 and K True\\<rbrace>\"\n  by (simp add: crunch_always_true_def, wp)\n\nlemma crunch_foo1_at_2':\n  \"True \\<Longrightarrow> \\<lbrace>crunch_always_true 3 and crunch_always_true 2\\<rbrace>\n      crunch_foo1 x \\<lbrace>\\<lambda>rv. crunch_always_true 3\\<rbrace>\"\n  by (simp add: crunch_always_true_def, wp)\n\nlemma crunch_foo1_at_3[wp]:\n  \"\\<lbrace>crunch_always_true 3\\<rbrace> crunch_foo1 x \\<lbrace>\\<lambda>rv. crunch_always_true 3\\<rbrace>\"\n  by (simp add: crunch_always_true_def, wp)\n\nlemma crunch_foo1_no_fail:\n  \"True \\<Longrightarrow> no_fail (crunch_always_true 2 and crunch_always_true 3) (crunch_foo1 x)\"\n  apply (simp add:crunch_always_true_def crunch_foo1_def)\n  apply (rule no_fail_pre)\n   apply (wp, simp)\n  done\n\ncrunch (no_fail) no_fail: crunch_foo2\n  (ignore: modify bind wp: crunch_foo1_at_2[simplified])\n\ncrunch (valid) at_2': crunch_foo2 \"crunch_always_true 2\"\n  (ignore: modify bind wp: crunch_foo1_at_2[simplified])\n\nfun crunch_foo3 :: \"nat => nat => 'a => (nat,unit) nondet_monad\" where\n  \"crunch_foo3 0 x _ = crunch_foo1 x\"\n| \"crunch_foo3 (Suc n) x y = crunch_foo3 n x y\"\n\ncrunch gt2: crunch_foo3 \"\\<lambda>x. x > y\"\n  (ignore: modify bind)\n\ncrunch (empty_fail) empty_fail2: crunch_foo3\n  (ignore: modify bind)\n\nclass foo_class =\n  fixes stuff :: 'a\nbegin\n\nfun crunch_foo4 :: \"nat => nat => 'a => (nat,unit) nondet_monad\" where\n  \"crunch_foo4 0 x _ s = crunch_foo1 x s\"\n| \"crunch_foo4 (Suc n) x y s = crunch_foo4 n x y s\"\n\ndefinition\n  \"crunch_foo5 x (y::'a) \\<equiv> crunch_foo1 x\"\n\nend\n\nlemma crunch_foo4_alt:\n  \"crunch_foo4 n x y \\<equiv> crunch_foo1 x\"\n  apply (induct n)\n   apply (simp add: fun_eq_iff)+\n  done\n\n(* prove rules about crunch_foo4 with and without the alternative definition *)\ncrunch gt3: crunch_foo4 \"\\<lambda>x. x > y\"\n  (ignore: modify bind)\n\ncrunch (no_fail) no_fail2: crunch_foo4\n  (rule: crunch_foo4_alt ignore: modify bind)\n\ncrunch gt3: crunch_foo4 \"\\<lambda>x. x > y\"\n  (rule: crunch_foo4_alt ignore: modify bind)\n\ncrunch gt4: crunch_foo5 \"\\<lambda>x. x > y\"\n  (ignore: modify bind)\n\n(* Test cases for crunch in locales *)\n\ndefinition\n  \"crunch_foo6 \\<equiv> return () >>= (\\<lambda>_. return ())\"\n\nlocale test_locale =\nfixes fixed_return_unit :: \"(unit, unit) nondet_monad\"\n\nbegin\n\ndefinition\n  \"crunch_foo7 \\<equiv> return () >>= (\\<lambda>_. return ())\"\n\n(* crunch works on a global constant within a locale *)\ncrunch test[wp]: crunch_foo6 P\n(ignore: bind)\n\n(* crunch works on a locale constant *)\ncrunch test[wp]: crunch_foo7 P\n(ignore: bind)\n\ndefinition\n  \"crunch_foo8 \\<equiv> fixed_return_unit >>= (\\<lambda>_. fixed_return_unit)\"\n\ndefinition\n  \"crunch_foo9 (x :: nat) \\<equiv> do\n    modify ((+) x);\n    modify ((+) x)\n  od\"\n\ncrunch test: crunch_foo9 \"\\<lambda>x. x > y\" (ignore: bind)\n\ndefinition\n  \"crunch_foo10 (x :: nat) \\<equiv> do\n    modify ((+) x);\n    modify ((+) x)\n  od\"\n\n(*crunch_def attribute overrides definition lookup *)\n\nlemma crunch_foo10_def2[crunch_def]:\n  \"crunch_foo10 = crunch_foo9\"\n  unfolding crunch_foo10_def[abs_def] crunch_foo9_def[abs_def]\n  by simp\n\ncrunch test[wp]: crunch_foo10 \"\\<lambda>x. x > y\"\n\n(* crunch_ignore works within a locale *)\ncrunch_ignore (add: bind)\n\ncrunch test': crunch_foo9 \"\\<lambda>x. x > y\"\n\nend\n\ninterpretation test_locale \"return ()\" .\n\n(* interpretation promotes the wp attribute from the locale *)\nlemma \"\\<lbrace>Q\\<rbrace> crunch_foo7 \\<lbrace>\\<lambda>_. Q\\<rbrace>\" by wp\n\n(* crunch still works on an interpreted locale constant *)\ncrunch test2: crunch_foo7 P\n  (wp_del: crunch_foo7_test)\n\nlocale test_sublocale\n\nsublocale test_sublocale < test_locale \"return ()\" .\n\ncontext test_sublocale begin\n\n(* crunch works on a locale constant with a fixed locale parameter *)\ncrunch test[wp]: crunch_foo8 P\n\nend\n\n(* check that qualified names are handled properly. *)\n\nconsts foo_const :: \"(unit, unit) nondet_monad\"\ndefs foo_const_def: \"foo_const \\<equiv> Crunch_Test_Qualified_NonDet.foo_const\"\n\ncrunch test: foo_const P\n\n(* check that the grid-style crunch is working *)\n\ncrunches crunch_foo3, crunch_foo4, crunch_foo5\n  for silly: \"\\<lambda>s. True \\<noteq> False\" and (no_fail)nf and (empty_fail)ef\n  (ignore: modify bind rule: crunch_foo4_alt wp_del: hoare_vcg_prop)\n\nend\n", "meta": {"author": "CompSoftVer", "repo": "CSim2", "sha": "b09a4d77ea089168b1805db5204ac151df2b9eff", "save_path": "github-repos/isabelle/CompSoftVer-CSim2", "path": "github-repos/isabelle/CompSoftVer-CSim2/CSim2-b09a4d77ea089168b1805db5204ac151df2b9eff/lib/Crunch_Test_NonDet.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5039061705290806, "lm_q2_score": 0.5621765008857982, "lm_q1q2_score": 0.28328420772280083}}
{"text": "(*  Title:      JinjaDCI/Compiler/Compiler1.thy\n    Author:     Tobias Nipkow, Susannah Mansky\n    Copyright   TUM 2003, UIUC 2019-20\n\n    Based on the Jinja theory Compiler/Compiler1.thy by Tobias Nipkow\n*)\n\nsection \\<open> Compilation Stage 1 \\<close>\n\ntheory Compiler1 imports PCompiler J1 Hidden begin\n\ntext\\<open> Replacing variable names by indices. \\<close>\n\nprimrec compE\\<^sub>1  :: \"vname list \\<Rightarrow> expr \\<Rightarrow> expr\\<^sub>1\"\n  and compEs\\<^sub>1 :: \"vname list \\<Rightarrow> expr list \\<Rightarrow> expr\\<^sub>1 list\" where\n  \"compE\\<^sub>1 Vs (new C) = new C\"\n| \"compE\\<^sub>1 Vs (Cast C e) = Cast C (compE\\<^sub>1 Vs e)\"\n| \"compE\\<^sub>1 Vs (Val v) = Val v\"\n| \"compE\\<^sub>1 Vs (e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2) = (compE\\<^sub>1 Vs e\\<^sub>1) \\<guillemotleft>bop\\<guillemotright> (compE\\<^sub>1 Vs e\\<^sub>2)\"\n| \"compE\\<^sub>1 Vs (Var V) = Var(last_index Vs V)\"\n| \"compE\\<^sub>1 Vs (V:=e) = (last_index Vs V):= (compE\\<^sub>1 Vs e)\"\n| \"compE\\<^sub>1 Vs (e\\<bullet>F{D}) = (compE\\<^sub>1 Vs e)\\<bullet>F{D}\"\n| \"compE\\<^sub>1 Vs (C\\<bullet>\\<^sub>sF{D}) = C\\<bullet>\\<^sub>sF{D}\"\n| \"compE\\<^sub>1 Vs (e\\<^sub>1\\<bullet>F{D}:=e\\<^sub>2) = (compE\\<^sub>1 Vs e\\<^sub>1)\\<bullet>F{D} := (compE\\<^sub>1 Vs e\\<^sub>2)\"\n| \"compE\\<^sub>1 Vs (C\\<bullet>\\<^sub>sF{D}:=e\\<^sub>2) = C\\<bullet>\\<^sub>sF{D} := (compE\\<^sub>1 Vs e\\<^sub>2)\"\n| \"compE\\<^sub>1 Vs (e\\<bullet>M(es)) = (compE\\<^sub>1 Vs e)\\<bullet>M(compEs\\<^sub>1 Vs es)\"\n| \"compE\\<^sub>1 Vs (C\\<bullet>\\<^sub>sM(es)) = C\\<bullet>\\<^sub>sM(compEs\\<^sub>1 Vs es)\"\n| \"compE\\<^sub>1 Vs {V:T; e} = {(size Vs):T; compE\\<^sub>1 (Vs@[V]) e}\"\n| \"compE\\<^sub>1 Vs (e\\<^sub>1;;e\\<^sub>2) = (compE\\<^sub>1 Vs e\\<^sub>1);;(compE\\<^sub>1 Vs e\\<^sub>2)\"\n| \"compE\\<^sub>1 Vs (if (e) e\\<^sub>1 else e\\<^sub>2) = if (compE\\<^sub>1 Vs e) (compE\\<^sub>1 Vs e\\<^sub>1) else (compE\\<^sub>1 Vs e\\<^sub>2)\"\n| \"compE\\<^sub>1 Vs (while (e) c) = while (compE\\<^sub>1 Vs e) (compE\\<^sub>1 Vs c)\"\n| \"compE\\<^sub>1 Vs (throw e) = throw (compE\\<^sub>1 Vs e)\"\n| \"compE\\<^sub>1 Vs (try e\\<^sub>1 catch(C V) e\\<^sub>2) =\n    try(compE\\<^sub>1 Vs e\\<^sub>1) catch(C (size Vs)) (compE\\<^sub>1 (Vs@[V]) e\\<^sub>2)\"\n| \"compE\\<^sub>1 Vs (INIT C (Cs,b) \\<leftarrow> e) = INIT C (Cs,b) \\<leftarrow> (compE\\<^sub>1 Vs e)\"\n| \"compE\\<^sub>1 Vs (RI(C,e);Cs \\<leftarrow> e') = RI(C,(compE\\<^sub>1 Vs e));Cs \\<leftarrow> (compE\\<^sub>1 Vs e')\"\n\n| \"compEs\\<^sub>1 Vs []     = []\"\n| \"compEs\\<^sub>1 Vs (e#es) = compE\\<^sub>1 Vs e # compEs\\<^sub>1 Vs es\"\n\n\n\nlemma [simp]: \"\\<And>Vs. sub_RI (compE\\<^sub>1 Vs e) = sub_RI e\"\n and [simp]: \"\\<And>Vs. sub_RIs (compEs\\<^sub>1 Vs es) = sub_RIs es\"\nproof(induct rule: sub_RI_sub_RIs_induct) qed(auto)\n\nprimrec fin\\<^sub>1:: \"expr \\<Rightarrow> expr\\<^sub>1\" where\n  \"fin\\<^sub>1(Val v) = Val v\"\n| \"fin\\<^sub>1(throw e) = throw(fin\\<^sub>1 e)\"\n\nlemma comp_final: \"final e \\<Longrightarrow> compE\\<^sub>1 Vs e = fin\\<^sub>1 e\"\n(*<*)by(erule finalE, simp_all)(*>*)\n\n\nlemma [simp]:\n      \"\\<And>Vs. max_vars (compE\\<^sub>1 Vs e) = max_vars e\"\nand \"\\<And>Vs. max_varss (compEs\\<^sub>1 Vs es) = max_varss es\"\n(*<*)by (induct e and es rule: max_vars.induct max_varss.induct) simp_all(*>*)\n\n\ntext\\<open> Compiling programs: \\<close>\n\ndefinition compP\\<^sub>1 :: \"J_prog \\<Rightarrow> J\\<^sub>1_prog\"\nwhere\n  \"compP\\<^sub>1  \\<equiv>  compP (\\<lambda>b (pns,body). compE\\<^sub>1 (case b of NonStatic \\<Rightarrow> this#pns | Static \\<Rightarrow> pns) body)\"\n\n(*<*)\ndeclare compP\\<^sub>1_def[simp]\n(*>*)\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/JinjaDCI/Compiler/Compiler1.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5621764862150636, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.2832842003301271}}
{"text": "section \\<open>Examples for infixl seq (;;)\\<close>\n\ntheory examples_infixl_seq\n  imports \"../../../hoare/HoareLogic/TotalCorrectness/Abrupt/utp_hoare_total\"\nbegin\n\ntext \\<open>Burkhart Wolff suggests infixl rather than infixr (like how seL4 does it)\\<close>\nno_notation useq (infixr \";;\" 51)\nnotation useq (infixl \";;\" 51)\n\ntext \\<open>Variable swapping\\<close>\n\nlemma swap_test1:\n  assumes \"weak_lens x\" and \"weak_lens y\" and \"weak_lens z\"\n  and \"x \\<bowtie> y\" and \"x \\<bowtie> z\" and \"y \\<bowtie> z\"\n  shows \"\\<lbrace>&x =\\<^sub>u \\<guillemotleft>a\\<guillemotright> \\<and> &y =\\<^sub>u \\<guillemotleft>b\\<guillemotright>\\<rbrace>\n  z \\<Midarrow> &x;;\n  x \\<Midarrow> &y;;\n  y \\<Midarrow> &z\n  \\<lbrace>&x =\\<^sub>u \\<guillemotleft>b\\<guillemotright> \\<and> &y =\\<^sub>u \\<guillemotleft>a\\<guillemotright>\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R\"\n  apply (insert assms)\n  apply (rule seq_hoare_r_t)\n   apply (rule seq_hoare_r_t)\n    defer\n    apply (rule assigns_abr_hoare_r'_t)\n   apply (rule assigns_abr_hoare_r'_t)\n  apply (rule assigns_abr_hoare_r_t)\n  apply pred_simp\n  apply (simp add: lens_indep_sym)\n  done\n\nlemma swap_test2:\n  assumes \"weak_lens x\" and \"weak_lens y\" and \"weak_lens z\"\n  and \"x \\<bowtie> y\" and \"x \\<bowtie> z\" and \"y \\<bowtie> z\"\n  shows \"\\<lbrace>&x =\\<^sub>u \\<guillemotleft>a\\<guillemotright> \\<and> &y =\\<^sub>u \\<guillemotleft>b\\<guillemotright>\\<rbrace>\n  z \\<Midarrow> &x;;\n  x \\<Midarrow> &y;;\n  y \\<Midarrow> &z\n  \\<lbrace>&x =\\<^sub>u \\<guillemotleft>b\\<guillemotright> \\<and> &y =\\<^sub>u \\<guillemotleft>a\\<guillemotright>\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R\"\n  apply (insert assms)\n  apply (rule seq_hoare_r_t)\n   defer\n   apply (rule assigns_abr_hoare_r'_t)\n  apply (rule seq_hoare_r_t)\n   defer\n   apply (rule assigns_abr_hoare_r'_t)\n  apply (rule assigns_abr_hoare_r_t)\n  apply pred_simp\n  apply (simp add: lens_indep_sym)\n  done\n\nsubsection \\<open>Adding in loops\\<close>\n\nlemma increment:\n  assumes \"vwb_lens x\" and \"x \\<bowtie> y\"\n  shows\n  \"\\<lbrace>&y =\\<^sub>u \\<guillemotleft>5::int\\<guillemotright>\\<rbrace>\n  x \\<Midarrow> 0;;\n  (&x =\\<^sub>u 0 \\<and> &y =\\<^sub>u 5)\\<^sup>\\<top>\\<^sup>C;;\n  while &x <\\<^sub>u &y\n  invr &x \\<le>\\<^sub>u &y \\<and> &y =\\<^sub>u 5\n  do x \\<Midarrow> &x + 1 od\n  \\<lbrace>&x =\\<^sub>u 5\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R\"\n  apply (insert assms)\n  apply (rule seq_hoare_r_t)\n   apply (rule seq_hoare_r_t[of _ _ true])\n    apply (rule assigns_abr_hoare_r_t)\n    apply pred_auto\n   apply (rule assume_hoare_r_t)\n    apply (rule skip_abr_hoare_r_t)\n   apply rel_auto\n  apply (rule while_invr_hoare_r_t)\n    apply (rule assigns_abr_hoare_r_t)\n    unfolding lens_indep_def\n    apply pred_auto\n   apply pred_auto\n  apply pred_auto\n  done\n\nlemma increment2:\n  assumes \"vwb_lens x\" and \"x \\<bowtie> y\"\n  shows\n  \"\\<lbrace>&y =\\<^sub>u \\<guillemotleft>5::int\\<guillemotright>\\<rbrace>\n  x \\<Midarrow> 0;;\n  (&x =\\<^sub>u 0 \\<and> &y =\\<^sub>u 5)\\<^sup>\\<top>\\<^sup>C;;\n  while &x <\\<^sub>u &y\n  invr &x \\<le>\\<^sub>u &y \\<and> &y =\\<^sub>u 5\n  do x \\<Midarrow> &x + 1 od\n  \\<lbrace>&x =\\<^sub>u 5\\<rbrace>\\<^sub>A\\<^sub>B\\<^sub>R\"\n  apply (insert assms)\n  apply (rule seq_hoare_r_t)\n   defer\n   apply (rule while_invr_hoare_r_t)\n     apply (rule assigns_abr_hoare_r_t)\n     unfolding lens_indep_def\n     apply pred_auto\n    defer\n    apply pred_auto\n   apply (rule seq_hoare_r_t)\n    defer\n    apply (rule assume_hoare_r_t)\n     apply (rule skip_abr_hoare_r_t)\n    apply rel_auto\n   apply pred_auto\n  apply (rule assigns_abr_hoare_r_t)\n  apply pred_auto\n  oops (*  (rule seq_hoare_r_t[of _ _ true]) is necessary to instantiate ?s27 *)\n\nend", "meta": {"author": "git-vt", "repo": "orca", "sha": "92bda0f9cfe5cc680b9c405fc38f07a960087a36", "save_path": "github-repos/isabelle/git-vt-orca", "path": "github-repos/isabelle/git-vt-orca/orca-92bda0f9cfe5cc680b9c405fc38f07a960087a36/Archive/Programming-Languages-Semantics/WP11-C-semantics/src/IMP-Lenses/examples/TotalCorrectness/Abrupt/examples_infixl_seq.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5621764862150634, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.283284200330127}}
{"text": "section \\<open> Events for Reactive Processes \\<close>\n\ntheory utp_rea_event\nimports \"UTP1.utp\"\nbegin\n\nsubsection \\<open> Events \\<close>\n\ntext \\<open> Events of some type @{typ \"'\\<theta>\"} are just the elements of that type. \\<close>\n\ntype_synonym '\\<theta> event = \"'\\<theta>\"\n\nsubsection \\<open> Channels \\<close>\n\ntext \\<open>\n  Typed channels are modelled as prisms. Below, @{typ \"'a\"} determines the\n  channel type and @{typ \"'\\<theta>\"} the underlying event alphabet type. As with values, it\n  is difficult to introduce channels as monomorphic types due to the fact that\n  they can have arbitrary parametrisations in term of @{typ \"'a\"}. Applying a\n  channel to an element of its type yields an event, as we may expect. Though\n  this is not formalised here, we may also sensibly assume that all channel-\n  representing functions are injective.\n\\<close>\n\ntype_synonym ('a, '\\<theta>) chan = \"'a \\<Longrightarrow>\\<^sub>\\<triangle> '\\<theta> event\"\n\ntext \\<open>\n  A downside of the approach is that the event type @{typ \"'\\<theta>\"} must be able\n  to encode \\emph{all} events of a process model, and hence cannot be fixed\n  upfront for a single channel or channel set. To do so, we actually require\n  a notion of `extensible' datatypes, in analogy to extensible record types.\n  Another solution is to encode a notion of channel scoping that namely uses\n  @{type sum} types to lift channel types into extensible ones, that is using\n  channel-set specific scoping operators. This is a current work in progress.\n\\<close>\n\nsubsubsection \\<open> Operators \\<close>\n\ntext \\<open>\n  The next lifted function creates an expression that yields a channel event,\n  from an expression on the channel type @{typ \"'a\"}.\n\\<close>\n\ndefinition chan_apply ::\n  \"('a, '\\<theta>) chan \\<Rightarrow> ('a, '\\<alpha>) uexpr \\<Rightarrow> ('\\<theta> event, '\\<alpha>) uexpr\" (\"'(_\\<cdot>/_')\\<^sub>u\") where\n[upred_defs]: \"(c\\<cdot>e)\\<^sub>u = uop (build\\<^bsub>c\\<^esub>) e\"\n\nno_utp_lift chan_apply (0)\n\nlemma unrest_chan_apply [unrest]: \"x \\<sharp> e \\<Longrightarrow> x \\<sharp> (c\\<cdot>e)\\<^sub>u\"\n  by (rel_auto)\n\nlemma usubst_chan_apply [usubst]: \"\\<sigma> \\<dagger> (c\\<cdot>v)\\<^sub>u = (c\\<cdot>\\<sigma> \\<dagger> v)\\<^sub>u\"\n  by (rel_auto)\n\nlemma msubst_event [usubst]:\n  \"(c\\<cdot>v x)\\<^sub>u\\<lbrakk>x\\<rightarrow>u\\<rbrakk> = (c\\<cdot>(v x)\\<lbrakk>x\\<rightarrow>u\\<rbrakk>)\\<^sub>u\"\n  by (pred_simp)\n\nlemma msubst_event_2 [usubst]:\n  \"(c\\<cdot>v x y)\\<^sub>u\\<lbrakk>(x,y)\\<rightarrow>u\\<rbrakk> = (c\\<cdot>(v x y)\\<lbrakk>(x,y)\\<rightarrow>u\\<rbrakk>)\\<^sub>u\"\n  by (pred_simp)+\n\nlemma aext_event [alpha]: \"(c\\<cdot>v)\\<^sub>u \\<oplus>\\<^sub>p a = (c\\<cdot>v \\<oplus>\\<^sub>p a)\\<^sub>u\"\n  by (pred_auto)\n\nend", "meta": {"author": "isabelle-utp", "repo": "utp-main", "sha": "27bdf3aee6d4fc00c8fe4d53283d0101857e0d41", "save_path": "github-repos/isabelle/isabelle-utp-utp-main", "path": "github-repos/isabelle/isabelle-utp-utp-main/utp-main-27bdf3aee6d4fc00c8fe4d53283d0101857e0d41/theories/reactive/utp_rea_event.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318337259583, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.2831175827719284}}
{"text": "theory dADemo\n\nimports dAutomaton_causal\n\nbegin\n\nsection \\<open> flasher port chans \\<close>\n\ntypedef botChan =\"{SOME c. c\\<in>cEmpty}\"\n  by simp\n\ntypedef flasherPortIn = \"{SOME c. c\\<notin>cEmpty}\"\n  apply auto\n  done\n\n\ntypedef flasherPortOut = \"{SOME c. c\\<notin>cEmpty \\<and> c\\<notin>range(Rep_flasherPortIn)}\"\n  apply auto\n  done\n\ninstantiation flasherPortIn::chan\nbegin\ndefinition \"Rep = Rep_flasherPortIn\"\ninstance\n  apply(standard)\n  apply (smt Int_lower1 Rep_flasherPortIn_def inf.orderI subset_singletonD type_definition.Rep_range type_definition_flasherPortIn)\n   by (simp add: Rep_flasherPortIn_def Rep_flasherPortIn_inject inj_on_def)\nend\n\ninstance flasherPortIn::finite\n  apply(intro_classes)\n  apply (subst UNIV_def)\n  by (metis (full_types) Abs_flasherPortIn_cases Collect_const ex_new_if_finite finite.emptyI finite_insert insert_iff singletonD)\n\ninstantiation flasherPortOut::chan\nbegin\ndefinition \"Rep = Rep_flasherPortOut\"\ninstance\n  apply(standard) \n  apply (smt Int_lower1 Rep_flasherPortOut_def inf_commute subset_singletonD type_definition.Rep_range type_definition_flasherPortOut)\n  by (smt Rep_flasherPortOut_def Rep_flasherPortOut_inject injI)\nend\n\ninstantiation botChan::chan\nbegin\ndefinition \"Rep = Rep_botChan\"\ninstance\n  apply(standard)\n  apply (smt Int_lower1 Rep_botChan_def inf_commute subset_singletonD type_definition.Rep_range type_definition_botChan)\n  by (simp add: Rep_botChan_def Rep_botChan_inject inj_on_def)\nend\n\nlift_definition Nonesbe::\"botChan sbElem\" is (*Does not work for undefined ctype*)\n\"None\"\n  apply(simp)\n  using Rep_botChan Rep_botChan_def sorry\n\nsection \\<open>flasher states\\<close>\n\ndatatype flasherState = S\n\nsection \\<open>flasher automaton definition\\<close>\n\ndefinition flasherAutomatonw::\"(flasherState,flasherPortIn,flasherPortOut,botChan) dAutomaton_weak\" where\n\"flasherAutomatonw =(| dawTransition =(\\<lambda>s sbe. (s,Abs_sbElem(Some (\\<lambda>c. sbegetch c sbe)))), \n                 dawInitState = S, dawInitOut = Nonesbe |)\"\n\ndefinition flasherAutomatons::\"(flasherState,flasherPortIn,flasherPortOut) dAutomaton_strong\" where\n\"flasherAutomatons =(| dawTransition =(\\<lambda>s sbe. (s,Abs_sbElem(Some (\\<lambda>c. sbegetch c sbe)))), \n                 dawInitState = S, dawInitOut = Abs_sbElem(Some (\\<lambda>c. SOME m. True)) |)\"\n\nsection \\<open> flasher automat to spf\\<close>\n\ndefinition flasherspfw::\"(flasherPortIn,flasherPortOut)spfw\"where\n\"flasherspfw = semantik_weak(flasherAutomatonw)\"\n\ndefinition flasherspfs::\"(flasherPortIn,flasherPortOut)spfs\"where\n\"flasherspfs = semantik_strong(flasherAutomatons)\"\n\nlemma dawinitout_genaut:\"daInitOut (daw2da auts) =  sbe2sb\\<cdot>(dawInitOut auts)\"\n  by(simp add: daw2da_def)\n\nlemma semantik_strong_head:\"\\<exists>sb. (Rep_spfw (Rep_spfs (semantik_strong auts)))\\<cdot>insb = sbe2sb\\<cdot>(dawInitOut auts) \\<bullet>\\<^sup>\\<Omega> sb\"\n  apply(simp add: semantik_strong_def daSem_def dawinitout_genaut)\n  sorry\n\ntheorem flasherhead:assumes \"B True \\<in> ctype c2\" shows\"shd (((Rep_spfw (Rep_spfs flasherspfs))\\<cdot>sb) \\<^enum> (Abs c2)) = B True\"\n  apply(simp add: flasherspfs_def)\n  apply(insert semantik_strong_head[of flasherAutomatons sb])\n  apply(simp add: flasherAutomatons_def)\n  apply auto\n  oops\n\nend", "meta": {"author": "yyisgladiator", "repo": "demo", "sha": "2a57300dfa7268721c78c233ee6b0a5454acce1f", "save_path": "github-repos/isabelle/yyisgladiator-demo", "path": "github-repos/isabelle/yyisgladiator-demo/demo-2a57300dfa7268721c78c233ee6b0a5454acce1f/src/automatons/dADemo.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297746074044134, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.28301606994047906}}
{"text": "theory ProcSendCase\n  imports ResMapValid ReduceWTS ProcDef ProcCVars\nbegin\n  \nlemma cancel_strong_leq_use_env: \"\\<lbrakk> strong_use_env r_x \\<rbrakk> \\<Longrightarrow> leq_use_env (diff_use_env r_x r_x) r_s\"  \n  apply (simp add: leq_use_env_def)\n  apply (simp add: diff_use_env_def)\n  apply (simp add: strong_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n  done\n  \nlemma sfl_diff_use_env: \"\\<lbrakk> strong_use_env r_ex; leq_use_env r_ex r_s; is_own r \\<rbrakk> \\<Longrightarrow> diff_use_env r_s (diff_use_env (lift_use_env r_s r) r_ex) = r_ex\"\n  apply (case_tac \"\\<forall> x. diff_use_env r_s (diff_use_env (lift_use_env r_s r) r_ex) x = r_ex x\")\n   apply (auto)\n  apply (simp add: strong_use_env_def)\n  apply (simp add: leq_use_env_def)\n  apply (simp add: diff_use_env_def)\n  apply (simp add: is_own_def)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_ex x\")\n    apply (auto)  \n   apply (case_tac \"r_s x\")\n    apply (auto)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n  done    \n    \n    (* the question right now is, how do we make these types line up? *)\n  \nlemma safe_val_exp: \"\\<lbrakk> well_typed env delta r_s1 (app_hole h (AppExp (AppExp (ConstExp SendConst) (VarExp (LocType a))) v)) tau r_s2 rx;\n  well_formed_delta env delta; env (Loc a) = Some (ChanTy t SEnd); is_value c; is_value v \\<rbrakk> \\<Longrightarrow>\n  well_typed env delta (np_dom_use_env env delta v) v t (np_dom_use_env env delta v) (np_dom_use_env env delta v)\"    \n  apply (induct h arbitrary: env r_s1 tau r_s2 rx)\n       apply (auto)\n    (* base case *)\n  apply (case_tac \"t \\<noteq> t1\")\n   apply (simp add: pure_fun_def)\n  apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s2a\" and e=\"v\" and tau=\"t\" and ?r_s2.0=\"r_s3\" and rx=\"rx2\" in infl_sexp_wp)\n     apply (simp_all)\n   apply (rule_tac value_is_sexp)\n   apply (auto)\n    (* r = rb *)\n  apply (case_tac \"rb \\<noteq> r\")\n   apply (simp add: pure_fun_def)\n    (* the idea is that the infl_sexp_wp requirements are strictly greater than np_dom. since np_dom is strong, there is an exact way of\n        subtracting to get to np_dom. (we do cheat a little by lifting rx2). *)\n  apply (rule_tac t=\"np_dom_use_env env delta v\" and s=\"diff_use_env (comp_use_env (lift_use_env rx2 r) (infl_use_env r_s2a r_s3))\n    (diff_use_env (lift_use_env (comp_use_env (lift_use_env rx2 r) (infl_use_env r_s2a r_s3)) rb) (np_dom_use_env env delta v))\" in subst)\n   apply (rule_tac sfl_diff_use_env)\n     apply (simp add: np_dom_use_env_def)\n     apply (rule_tac strong_dom_use_env)\n    (* to prove that the infl_sexp_wp reqs are greater than np_dom, we use the fact that any npv must have a permission *)\n    apply (simp add: np_dom_use_env_def)\n    apply (simp add: dom_use_env_def)\n    apply (auto)\n   apply (simp add: leq_use_env_def)\n   apply (auto)\n   apply (case_tac \"comp_use_env (lift_use_env rx2 r) (infl_use_env r_s2a r_s3) x \\<noteq> OwnPerm\")\n    apply (case_tac \"comp_use_env rx2 (infl_use_env r_s2a r_s3) x = NoPerm\")\n     apply (cut_tac x=\"x\" and env=\"env\" and e=\"v\" and ?r_s1.0=\"comp_use_env rx2 (infl_use_env r_s2a r_s3)\" in well_typed_no_npv_use)\n       apply (auto)\n   apply (cut_tac r_sa=\"lift_use_env rx2 r\" and r_sb=\"infl_use_env r_s2a r_s3\" and x=\"x\" in comp_use_no_own_both)\n    apply (auto)\n   apply (case_tac \"rx2 x \\<noteq> NoPerm\")\n    apply (simp add: is_own_def)\n   apply (auto)\n   apply (case_tac \"infl_use_env r_s2a r_s3 x \\<noteq> NoPerm\")\n    apply (simp add: infl_use_env_def)\n    apply (case_tac \"r_s2a x = OwnPerm \\<and> r_s3 x = NoPerm\")\n     apply (auto)\n   apply (cut_tac r_sa=\"rx2\" and r_sb=\"infl_use_env r_s2a r_s3\" and x=\"x\" in comp_use_none)\n     apply (auto)\n    (* with that in mind, we manipulate until we match the infl sexp lemma *)\n  apply (rule_tac well_typed_diff_perms)\n   apply (rule_tac rx=\"comp_use_env rx2 (infl_use_env r_s2a r_s3)\" in well_typed_incr_req)\n     apply (rule_tac r_s=\"comp_use_env rx2 (infl_use_env r_s2a r_s3)\" in well_typed_incr_simul_perm)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (rule_tac comp_leq_use_env1)\n       apply (rule_tac self_lift_leq_use_env)\n      apply (rule_tac self_comp_leq_use_env2)\n     apply (simp)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (rule_tac comp_leq_use_env1)\n     apply (rule_tac self_lift_leq_use_env)\n    apply (rule_tac self_comp_leq_use_env2)\n   apply (rule_tac id_leq_use_env)\n    (* next, we must show that the differential is actually subtractible, which is true since it removes all non-prim vars *)\n  apply (auto)\n  apply (case_tac \"np_dom_use_env env delta v x \\<noteq> OwnPerm\")\n   apply (simp add: np_dom_use_env_def)\n   apply (simp add: dom_use_env_def)\n   apply (cut_tac r_s=\"lift_use_env (comp_use_env (lift_use_env rx2 r) (infl_use_env r_s2a r_s3)) r\" and\n       r_ex=\"np_dom_use_env env delta v\" and x=\"x\" in diff_use_none_ex)\n    apply (simp)\n  apply (simp add: own_env_vars_def)\n  done\n    \n  \nlemma safe_recv_exp: \"\\<lbrakk> well_typed env delta r_s1 (app_hole h (AppExp (ConstExp RecvConst) (VarExp (LocType a)))) tau r_s2 rx;\n  well_formed_delta env delta; env (Loc a) = Some (ChanTy t REnd); well_typed env delta r_x v t r_x r_x; disj_use_env r_s1 r_x; \n  strong_use_env r_x; is_value c; is_value v; is_own r \\<rbrakk> \\<Longrightarrow>\n  well_typed env delta (comp_use_env r_s1 r_x) (app_hole h v) tau r_s2 rx\"  \n  apply (induct h arbitrary: env r_s1 tau r_s2 rx)\n       apply (auto)\n    (* base case *)\n       apply (cut_tac r_sc=\"r_s2\" and r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 ra)) r_exa)\" and\n          r_sa=\"r_s1\" in trans_leq_use_env)\n         apply (rule_tac diff_leq_use_env)\n         apply (rule_tac r_sb=\"diff_use_env r_s2a (comp_use_env (ereq_use_env (Loc (delta a)) tau_x) r_ex)\" in trans_leq_use_env)\n          apply (rule_tac diff_leq_use_env)\n          apply (auto)\n       apply (rule_tac ?r_s2.0=\"diff_use_env (comp_use_env r_s1 r_x) r_x\"\n        and rx=\"diff_use_env r_x r_x\" in well_typed_simul_end_perm)\n          apply (rule_tac well_typed_diff_end_perm)\n           apply (rule_tac well_typed_comp_perms2)\n            apply (simp add: pure_fun_def)\n           apply (auto)\n          apply (rule_tac comm_disj_use_env)\n          apply (simp)\n         apply (rule_tac self_comp_leq_use_env2)\n        apply (rule_tac disj_diff_leq_use_env)\n         apply (rule_tac r_s=\"r_s1\" in disj_leq_use_env2)\n          apply (rule_tac comm_disj_use_env)\n          apply (simp_all)\n        apply (rule_tac comp_leq_use_env1)\n        apply (simp)\n       apply (rule_tac cancel_strong_leq_use_env)\n       apply (simp)\n    (* lhs pair case. *)\n      apply (rule_tac x=\"t1\" in exI)\n      apply (rule_tac x=\"ra\" in exI)\n      apply (rule_tac x=\"aa\" in exI)\n      apply (rule_tac x=\"r_s2a\" in exI)\n      apply (rule_tac x=\"rx1\" in exI)\n      apply (auto)\n      apply (rule_tac x=\"rx2\" in exI)\n      apply (rule_tac x=\"r_s3\" in exI)\n      apply (auto)\n      apply (rule_tac x=\"r_ex\" in exI)\n      apply (auto)\n      apply (rule_tac comp_leq_use_env1)\n      apply (simp)\n    (* rhs pair case. *)\n     apply (rule_tac x=\"t1\" in exI)\n     apply (rule_tac x=\"ra\" in exI)\n     apply (rule_tac x=\"aa\" in exI)\n     apply (rule_tac x=\"comp_use_env r_s2a r_x\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n      apply (rule_tac well_typed_comp_perms)\n       apply (simp_all)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (rule_tac x=\"r_s3\" in exI)\n     apply (auto)\n      apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" and r_ex=\"r_x\" in disj_leq_use_env1)\n        apply (simp)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n     apply (rule_tac x=\"r_ex\" in exI)\n     apply (auto)\n     apply (rule_tac comp_leq_use_env1)\n     apply (simp)\n    (* if case. *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"r_s2a\" in exI)\n    apply (auto)\n    (* lhs pair case. *)\n   apply (rule_tac x=\"r_s2a\" in exI)\n   apply (rule_tac x=\"r_s3\" in exI)\n   apply (rule_tac x=\"rx1\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"rx2\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_ex\" in exI)\n   apply (auto)\n   apply (rule_tac comp_leq_use_env1)\n   apply (simp)\n    (* rhs pair case. *)\n  apply (rule_tac x=\"comp_use_env r_s2a r_x\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n   apply (auto)\n   apply (rule_tac well_typed_comp_perms)\n    apply (simp_all)\n  apply (rule_tac x=\"rx2\" in exI)\n   apply (auto)\n   apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" and r_ex=\"r_x\" in disj_leq_use_env1)\n     apply (simp)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n  apply (rule_tac x=\"r_ex\" in exI)\n  apply (auto)\n  apply (rule_tac comp_leq_use_env1)\n  apply (simp)\n  done\n    \nlemma safe_own_npv_use: \"\\<lbrakk> well_typed env delta r_s1 (app_hole h (AppExp f v)) tau r_s2 rx; well_formed_delta env delta;\n  is_value f; strong_fun f; a \\<noteq> NoRef; is_value v; x \\<in> non_prim_vars env delta v \\<rbrakk> \\<Longrightarrow> r_s1 x = OwnPerm\"\n  apply (induct h arbitrary: env r_s1 r_s2 tau rx)\n       apply (auto)\n    (* base case *)\n    apply (cut_tac f=\"f\" and r=\"r\" in strong_fun_own)\n      apply (auto)\n    apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s2a\" and e=\"v\" and ?r_s2.0=\"r_s3\" and rx=\"rx2\" in infl_sexp_wp)\n      apply (auto)\n     apply (rule_tac value_is_sexp)\n     apply (simp)\n    apply (case_tac \"comp_use_env rx2 (infl_use_env r_s2a r_s3) x = NoPerm\")\n     apply (cut_tac env=\"env\" and x=\"x\" and e=\"v\" and ?r_s1.0=\"comp_use_env rx2 (infl_use_env r_s2a r_s3)\" in well_typed_no_npv_use)\n       apply (auto)\n    apply (case_tac \"rx2 x \\<noteq> NoPerm\")\n     apply (cut_tac r_x=\"lift_use_env rx2 r\" and r_s=\"r_s1\" and x=\"x\" in leq_use_own)\n      apply (simp add: is_own_def)\n     apply (rule_tac r_sb=\"comp_use_env rx1 (lift_use_env rx2 r)\" in trans_leq_use_env)\n      apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n       apply (rule_tac r_sb=\"r_s2a\" in trans_leq_use_env)\n        apply (auto)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n     apply (rule_tac self_comp_leq_use_env2)\n    apply (case_tac \"infl_use_env r_s2a r_s3 x \\<noteq> NoPerm\")\n     apply (simp add: infl_use_env_def)\n     apply (case_tac \"r_s2a x = OwnPerm \\<and> r_s3 x = NoPerm\")\n      apply (auto)\n     apply (rule_tac r_x=\"r_s2a\" in leq_use_own)\n      apply (auto)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n    apply (cut_tac r_sa=\"rx2\" and r_sb=\"infl_use_env r_s2a r_s3\" and x=\"x\" in comp_use_none)\n      apply (auto)\n    (* rhs induct *)\n   apply (rule_tac r_x=\"r_s2a\" in leq_use_own)\n    apply (simp)\n   apply (rule_tac well_typed_perm_leq)\n   apply (auto)\n    (* rhs pair *)\n  apply (rule_tac r_x=\"r_s2a\" in leq_use_own)\n   apply (simp)\n  apply (rule_tac well_typed_perm_leq)\n  apply (auto)\n  done    \n  \n    \nlemma safe_send_exp_ih: \"\\<lbrakk> well_typed env delta r_s1 (app_hole h (AppExp (AppExp (ConstExp SendConst) c) v)) tau r_s2 rx;\n  well_formed_delta env delta; is_value c; is_value v \\<rbrakk> \\<Longrightarrow>\n  well_typed env delta r_s1 (app_hole h (ConstExp UnitConst)) tau r_s2 rx\"  \n  apply (induct h arbitrary: env r_s1 tau r_s2 rx)\n       apply (auto)\n    (* base case *)\n        apply (simp add: pure_fun_def)\n       apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n        apply (rule_tac diff_leq_use_env)\n        apply (rule_tac r_sb=\"r_s2a\" in trans_leq_use_env)\n         apply (rule_tac r_sb=\"diff_use_env r_s3a (comp_use_env (comp_use_env rx1a (lift_use_env rx2a ra)) r_exa)\" in trans_leq_use_env)\n          apply (rule_tac diff_leq_use_env)\n          apply (rule_tac r_sb=\"r_s2b\" in trans_leq_use_env)\n           apply (simp_all)\n        apply (rule_tac well_typed_perm_leq)\n        apply (auto)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n    (* lhs app case *)\n      apply (rule_tac x=\"t1\" in exI)\n      apply (rule_tac x=\"r\" in exI)\n      apply (rule_tac x=\"a\" in exI)\n      apply (rule_tac x=\"r_s2a\" in exI)\n      apply (rule_tac x=\"rx1\" in exI)\n      apply (auto)\n    (* rhs app case *)\n     apply (rule_tac x=\"t1\" in exI)\n     apply (rule_tac x=\"r\" in exI)\n     apply (rule_tac x=\"a\" in exI)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (rule_tac x=\"r_s3\" in exI)\n     apply (auto) \n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"r_s2a\" in exI)\n    apply (auto)\n    (* lhs pair case *)\n   apply (rule_tac x=\"r_s2a\" in exI)\n   apply (rule_tac x=\"r_s3\" in exI)\n   apply (rule_tac x=\"rx1\" in exI)\n   apply (auto)\n    (* rhs pair case *)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (auto)\n  done\n    \n    \nlemma safe_send_exp: \"\\<lbrakk> well_typed env delta r_s1 (app_hole h (AppExp (AppExp (ConstExp SendConst) (VarExp (LocType a))) v)) tau r_s2 rx;\n  well_formed_delta env delta; sub_use_env s r_s1; wf_hole h; is_value v \\<rbrakk> \\<Longrightarrow>\n  well_typed env delta (diff_use_env r_s1 (np_dom_use_env env delta v)) (app_hole h (ConstExp UnitConst)) tau\n    (diff_use_env r_s2 (np_dom_use_env env delta v)) (diff_use_env rx (np_dom_use_env env delta v))\"  \n  apply (rule_tac well_typed_diff_perms)\n   apply (rule_tac c=\"VarExp (LocType a)\" in safe_send_exp_ih)\n     apply (auto)\n    (* we want to show that if xa is in the dominator, it is not an np-var in h.\n        > if xa is an np-var itself, it cannot be in e by lemma *)\n  apply (case_tac \"x \\<in> non_prim_vars env delta v\")\n   apply (cut_tac h=\"h\" and x=\"x\" and e=\"ConstExp UnitConst\" and delta=\"delta\" in app_hole_res_vars_rev)\n    apply (auto)\n    apply (simp add: non_prim_vars_def)\n   apply (cut_tac h=\"h\" and x=\"x\" and env=\"env\" and ?r_s1.0=\"r_s1\" and v=\"VarExp (LocType a)\" and e=\"v\" in safe_send_hole_npv_use)\n         apply (auto)\n  apply (simp add: own_env_vars_def)\n  apply (simp add: np_dom_use_env_def)\n  apply (simp add: dom_use_env_def)(*\n    (* otherwise, xa is in the completion. we identify its ancestor z. *)\n  apply (simp add: own_env_vars_def)\n  apply (simp add: np_dom_use_env_def)\n  apply (simp add: dom_use_env_def)\n  apply (case_tac \"\\<exists>xa. x = Loc xa \\<and> (\\<exists>l z. Loc z \\<in> non_prim_vars env v \\<and> path_lookup rs_map z l xa)\")\n   apply (auto)\n    (* we note that z is a np-var of e therefore r_s1 z = Own *)\n  apply (cut_tac x=\"Loc z\" and env=\"env\" and f=\"AppExp (ConstExp SendConst) (VarExp (LocType a b))\" in safe_own_npv_use)\n        apply (auto)\n   apply (simp add: pure_fun_def)\n   apply (simp add: is_own_def)\n    (* xa then is in the lookup map of some parent y. *)\n  apply (cut_tac rs_map=\"rs_map\" and z=\"z\" and x=\"xa\" in path_lookup_parent)\n     apply (auto)\n    (* with that in mind, by separation, x is disjoint from r_s1. *)\n  apply (case_tac \"r_s1 (Loc xa) \\<noteq> NoPerm\")\n   apply (simp add: valid_exp_use_env_def)\n   apply (simp add: sep_nres_map_def)\n   apply (auto)\n   apply (erule_tac x=\"y\" in allE)\n   apply (simp add: nres_lookup_def)\n   apply (simp add: strong_disj_use_env_def)\n   apply (erule_tac x=\"Loc xa\" in allE)\n   apply (auto)\n    (* by extension, x is not in 'h (send c v)' *)\n  apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s1\" and x=\"Loc xa\" in well_typed_no_npv_use)\n    apply (auto)\n  apply (simp add: non_prim_vars_def)    \n    (* the very last part is showing that x not in 'h (send c v)' implies x not in 'h ()'. *)\n  apply (cut_tac x=\"Loc xa\" and h=\"h\" and e=\"ConstExp UnitConst\" in app_hole_res_vars_rev)\n   apply (auto)\n  apply (cut_tac x=\"Loc xa\" and h=\"h\" and e=\"AppExp (AppExp (ConstExp SendConst) (VarExp (LocType a b))) v\" in app_hole_res_vars2)\n   apply (auto)*)\n  done\n    \nlemma disj_lift_use_envr_rev: \"\\<lbrakk> strong_disj_use_env r_s r_x \\<rbrakk> \\<Longrightarrow> disj_use_env r_s (lift_use_env r_x r)\"    \n  apply (simp add: strong_disj_use_env_def)\n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (auto)\n   apply (erule_tac x=\"x\" in allE)\n   apply (auto)\n   apply (case_tac r)\n     apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (case_tac r)\n    apply (auto)\n  done\n    \nlemma lift_strong_disj_use_env1: \"\\<lbrakk> strong_disj_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> strong_disj_use_env (lift_use_env r_x r) r_s\"    \n  apply (simp add: strong_disj_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (case_tac r)\n    apply (auto)\n  done\n  \nlemma send_disj_nres_map: \"\\<lbrakk> disj_nres_map p_map; p_map u1 = Some r_sa; p_map u2 = Some r_sb; is_own r;\n  leq_use_env r_xa (lift_use_env r_sa r); leq_use_env r_xb (comp_use_env (lift_use_env r_sa r) (lift_use_env r_sb r));\n  strong_disj_use_env r_xa r_xb \\<rbrakk> \\<Longrightarrow> disj_nres_map (add_env (add_env p_map u1 r_xa) u2 r_xb)\"    \n  apply (rule_tac disj_add_nres_map)  \n   apply (rule_tac disj_add_nres_map)  \n    apply (simp)\n    (* proving disjointness for the send thread's material *)\n   apply (rule_tac r_s=\"lift_use_env r_sa r\" in leq_sep_nres_map)\n    apply (simp)\n   apply (simp add: disj_nres_map_def)\n   apply (simp add: sep_nres_map_def)\n   apply (auto)\n   apply (case_tac \"x = u1\")\n    apply (simp add: nres_lookup_def)\n    apply (simp add: rem_env_def)\n    apply (rule_tac empty_strong_disj_use_env2)\n   apply (rule_tac lift_strong_disj_use_env1)\n   apply (erule_tac x=\"u1\" in allE)\n   apply (erule_tac x=\"x\" in allE)\n   apply (simp add: nres_lookup_def)\n   apply (simp add: rem_env_def)\n    (* proving disjointness for the recv thread *)\n  apply (simp add: sep_nres_map_def)\n  apply (auto)\n  apply (case_tac \"u2 = x\")\n   apply (simp add: nres_lookup_def)\n   apply (simp add: rem_env_def)\n   apply (rule_tac empty_strong_disj_use_env2)\n  apply (case_tac \"u1 = x\")\n   apply (simp add: nres_lookup_def)\n   apply (simp add: rem_env_def)\n   apply (simp add: add_env_def)\n   apply (rule_tac comm_strong_disj_use_env)\n   apply (simp)\n  apply (simp add: nres_lookup_def)\n  apply (simp add: rem_env_def)\n  apply (simp add: add_env_def)\n  apply (simp add: disj_nres_map_def)\n  apply (rule_tac r_s=\"comp_use_env (lift_use_env r_sa r) (lift_use_env r_sb r)\" in strong_disj_leq_use_env1)\n   apply (rule_tac strong_disj_comp_use_env2)\n    apply (rule_tac lift_strong_disj_use_env1)\n    apply (erule_tac x=\"u1\" in allE)\n    apply (erule_tac x=\"x\" in allE)\n    apply (simp add: nres_lookup_def)\n   apply (rule_tac lift_strong_disj_use_env1)\n   apply (erule_tac x=\"u2\" in allE)\n   apply (erule_tac x=\"x\" in allE)\n   apply (simp add: nres_lookup_def)\n  apply (simp)\n  done\n  (*\nfun proper_hole where\n  \"proper_hole rs_map ExpHole = True\"\n| \"proper_hole rs_map (AppHole1 h e) = (proper_hole rs_map h \\<and> proper_exp rs_map e)\"    \n| \"proper_hole rs_map (AppHole2 v h) = (proper_exp rs_map v \\<and> proper_hole rs_map h)\"\n| \"proper_hole rs_map (IfHole h e1 e2) = (proper_hole rs_map h \\<and> proper_exp rs_map e1 \\<and> proper_exp rs_map e2)\"  \n| \"proper_hole rs_map (PairHole1 h e) = (proper_hole rs_map h \\<and> proper_exp rs_map e)\"    \n| \"proper_hole rs_map (PairHole2 v h) = (proper_exp rs_map v \\<and> proper_hole rs_map h)\"\n \nlemma proper_app_hole_split1: \"\\<lbrakk> proper_exp rs_map (app_hole h e) \\<rbrakk> \\<Longrightarrow> proper_hole rs_map h\" \n  apply (induct h)\n       apply (auto)\n            apply (simp_all add: proper_exp_def)\n  done\n\nlemma proper_app_hole_split2: \"\\<lbrakk> proper_exp rs_map (app_hole h e) \\<rbrakk> \\<Longrightarrow> proper_exp rs_map e\" \n  apply (induct h)\n       apply (auto)\n      apply (simp_all add: proper_exp_def)\n  done\n    \nlemma proper_app_hole_recon: \"\\<lbrakk> proper_hole rs_map h; proper_exp rs_map e \\<rbrakk> \\<Longrightarrow> proper_exp rs_map (app_hole h e)\"    \n  apply (induct h)\n       apply (auto)\n      apply (simp_all add: proper_exp_def)\n  done\n  \nlemma proper_app_hole: \"\\<lbrakk> proper_exp rs_map (app_hole h e1); proper_exp rs_map e2 \\<rbrakk> \\<Longrightarrow> proper_exp rs_map (app_hole h e2)\"    \n  apply (cut_tac rs_map=\"rs_map\" and h=\"h\" and e=\"e1\" in proper_app_hole_split1)\n   apply (auto)\n  apply (rule_tac proper_app_hole_recon)\n   apply (auto)\n  done*)\n  \nlemma srps_send_case: \"\\<lbrakk>well_typed_system env delta p_map s2 ps1; valid_reduct app_red_exp; r_ax = SendAct;\n        ps1 u1 = Some (app_hole h1 (AppExp (AppExp (ConstExp SendConst) (VarExp (LocType x_s))) v));\n        ps1 u2 = Some (app_hole h2 (AppExp (ConstExp RecvConst) (VarExp (LocType x_r)))); u1 \\<noteq> u2; wf_hole h1;\n        wf_hole h2; is_value v; s2 x_s = Some ChanSValue;\n        s2 x_r = Some (ChanRValue x_s); s1 = s2;\n        ps2 = add_env (add_env ps1 u1 (app_hole h1 (ConstExp UnitConst))) u2 (app_hole h2 v)\\<rbrakk>\n       \\<Longrightarrow> \\<exists>r_s g_ax.\n              (\\<exists>p_map'. well_typed_system (red_env env g_ax) (red_delta delta g_ax) p_map' s2\n                         (add_env (add_env ps1 u1 (app_hole h1 (ConstExp UnitConst))) u2 (app_hole h2 v))) \\<and>\n              safe_act s2 r_s g_ax\"\n      (* prelim: well-formed-delta *)\n  apply (cut_tac delta=\"delta\" in wts_well_formed_delta)\n   apply (simp add: well_typed_system_def)\n   apply (auto)\n      (* send case. no resources are generated in this step *)\n  apply (rule_tac x=\"empty_use_env\" in exI)\n  apply (rule_tac x=\"NoResAct\" in exI)\n  apply (auto)\n  apply (simp add: well_typed_system_def)\n  apply (auto)\n    (* we have to get the well-typedness statement for h1 [send c v] *)\n  apply (case_tac \"\\<not> (case ps1 u1 of None \\<Rightarrow> True | Some e \\<Rightarrow> (case p_map u1 of None \\<Rightarrow> False | Some r_s \\<Rightarrow> \\<exists>rx r_s2. well_typed env delta r_s e UnitTy r_s2 rx))\")\n   apply (simp add: well_typed_proc_set_def)\n   apply (auto)\n   apply (erule_tac x=\"u1\" in allE)\n   apply (auto)\n  apply (case_tac \"p_map u1\")\n   apply (auto)\n    (* we also get the well-typedness statement for h2 [recv c v] *)\n  apply (case_tac \"\\<not> (case ps1 u2 of None \\<Rightarrow> True | Some e \\<Rightarrow> (case p_map u2 of None \\<Rightarrow> False | Some r_s \\<Rightarrow> \\<exists>rx r_s2. well_typed env delta r_s e UnitTy r_s2 rx))\")\n   apply (simp add: well_typed_proc_set_def)\n   apply (auto)\n   apply (erule_tac x=\"u2\" in allE)\n   apply (auto)\n  apply (case_tac \"p_map u2\")\n   apply (auto)\n    (* next we get the send channel's type *)\n  apply (case_tac \"\\<not> (\\<exists> t. env (Loc x_s) = Some (ChanTy t SEnd))\")\n   apply (simp add: well_typed_state_def)\n   apply (auto)\n   apply (erule_tac x=\"x_s\" in allE)\n   apply (auto)\n   apply (case_tac \"env (Loc x_s)\")\n    apply (auto)\n    (* and the recv channel's type *)\n  apply (case_tac \"\\<not> env (Loc x_r) = Some (ChanTy t REnd)\")\n   apply (simp add: well_typed_state_def)\n   apply (auto)\n   apply (erule_tac x=\"x_r\" in allE)\n   apply (auto)\n   apply (case_tac \"env (Loc x_r)\")\n    apply (auto)\n    (* prelim: we prove the dominator of v \\<le> lift a r (the permission map of u1) *)\n  apply (cut_tac eq_own)\n  apply (auto)\n  apply (cut_tac r_sc=\"np_dom_use_env env delta v\" and r_sb=\"np_dom_use_env env delta (app_hole h1 (AppExp (AppExp (ConstExp SendConst) (VarExp (LocType x_s))) v))\"\n      and r_sa=\"lift_use_env a r\" in trans_leq_use_env)\n    apply (rule_tac wt_np_leq_use_env)\n     apply (auto)\n   apply (simp add: np_dom_use_env_def)\n   apply (rule_tac dist_dom_leq_use_env)\n   apply (auto)\n   apply (simp add: non_prim_vars_def)\n   apply (rule_tac app_hole_res_vars)\n   apply (auto)\n    (* we can generate a type for h1 () *)\n  apply (cut_tac env=\"env\" and v=\"v\" and ?r_s1.0=\"a\" and tau=\"UnitTy\" and h=\"h1\" and ?r_s2.0=\"r_s2\" and rx=\"rx\" and s=\"s2\" and delta=\"delta\" in safe_send_exp)\n        apply (auto)\n    apply (simp add: well_typed_state_def)\n    (* - complete proof that a is still valid *)\n   apply (simp add: well_typed_proc_set_def)\n   apply (simp add: sub_nres_map_def)\n   apply (erule_tac x=\"u1\" in allE)\n   apply (simp add: nres_lookup_def)\n    (* we can also generate a type for h2 v, first by getting a type for v, and then by putting it in the hole *)\n  apply (cut_tac env=\"env\" and v=\"v\" and h=\"h1\" and a=\"x_s\" and t=\"t\" in safe_val_exp)\n      apply (auto)\n  apply (cut_tac env=\"env\" and ?r_s1.0=\"aa\" and h=\"h2\" and r_x=\"np_dom_use_env env delta v\" in safe_recv_exp)\n          apply (auto)\n    (* - p_map disjointness proves that the permissions being added are disjoint *)\n    apply (rule_tac r_s=\"lift_use_env a r\" in disj_leq_use_env2)\n     apply (case_tac \"\\<forall>x y. x \\<noteq> y \\<longrightarrow> strong_disj_use_env (nres_lookup p_map x) (nres_lookup p_map y)\")\n      apply (erule_tac x=\"u2\" in allE)\n      apply (erule_tac x=\"u1\" in allE)\n      apply (auto)\n     apply (simp add: nres_lookup_def)\n     apply (rule_tac disj_lift_use_envr_rev)\n     apply (simp)\n    apply (simp add: well_typed_proc_set_def)\n    apply (simp add: disj_nres_map_def)\n    (* - proving the dominator is strong *)\n   apply (simp add: np_dom_use_env_def)\n   apply (rule_tac strong_dom_use_env)\n    (* lastly it remains to prove the new process map is well-formed *)\n  apply (rule_tac x=\"add_env (add_env p_map u1 (diff_use_env a (np_dom_use_env env delta v)))\n    u2 (comp_use_env aa (np_dom_use_env env delta v))\" in exI)\n  apply (simp add: well_typed_proc_set_def)\n  apply (auto)\n    (* completeness *)(*\n      apply (rule_tac add_full_nres_map)\n      apply (rule_tac add_full_nres_map)\n      apply (simp)*)\n    (* disjointness, assisted by lemma *)\n     apply (rule_tac r_sa=\"a\" and r_sb=\"aa\" in send_disj_nres_map)\n           apply (simp_all)\n       apply (rule_tac diff_leq_use_env)\n       apply (rule_tac self_lift_leq_use_env)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (rule_tac comp_leq_use_env2)\n       apply (rule_tac self_lift_leq_use_env)\n      apply (rule_tac comp_leq_use_env1)\n      apply (simp)\n     apply (rule_tac strong_disj_comp_use_env1)\n      apply (rule_tac r_s=\"a\" in strong_disj_leq_use_env1)\n       apply (simp add: disj_nres_map_def)\n       apply (erule_tac x=\"u1\" in allE)\n       apply (erule_tac x=\"u1\" in allE)\n       apply (erule_tac x=\"u2\" in allE)\n       apply (simp add: nres_lookup_def)\n      apply (rule_tac self_diff_leq_use_env)\n     apply (rule_tac r_s=\"np_dom_use_env env delta v\" in strong_disj_leq_use_env2)\n      apply (rule_tac diff_strong_disj_use_env)\n      apply (simp add: np_dom_use_env_def)\n     apply (rule_tac strong_dom_use_env)\n    apply (rule_tac id_leq_use_env)\n    (* proving that the processes are well-typed *)\n    apply (case_tac \"u = u1\")\n     apply (simp add: add_env_def)\n     apply (auto)(*\n     apply (rule_tac proper_app_hole)\n      apply (simp)\n     apply (simp add: proper_exp_def)*)\n    apply (case_tac \"u = u2\")\n     apply (simp add: add_env_def)\n     apply (auto)(*\n     apply (rule_tac proper_app_hole)\n      apply (simp)\n     apply (cut_tac rs_map=\"rs_map\" and h=\"h1\" and e=\"AppExp (AppExp (ConstExp SendConst) (VarExp (LocType x_s a_s))) v\" in proper_app_hole_split2)\n      apply (simp)\n     apply (simp add: proper_exp_def)*)\n    apply (simp add: add_env_def)\n    apply (erule_tac x=\"u\" in allE)\n    apply (case_tac \"ps1 u\")\n     apply (auto)\n    apply (simp add: add_env_def)\n    (* proving res_map element containment *)\n   apply (rule_tac add_sub_nres_map1)\n    apply (rule_tac add_sub_nres_map1)\n     apply (simp)\n    apply (rule_tac r_s=\"a\" in trans_sub_use_env)\n     apply (simp add: sub_nres_map_def)\n     apply (erule_tac x=\"u1\" in allE)\n     apply (simp add: nres_lookup_def)\n    apply (rule_tac self_diff_leq_use_env)\n   apply (rule_tac comp_sub_use_env)\n    apply (simp add: sub_nres_map_def)\n    apply (erule_tac x=\"u2\" in allE)\n    apply (simp add: nres_lookup_def)\n   apply (rule_tac r_s=\"lift_use_env a r\" in trans_sub_use_env)\n    apply (rule_tac lift_sub_use_env)\n    apply (simp add: sub_nres_map_def)\n    apply (erule_tac x=\"u1\" in allE)\n    apply (simp add: nres_lookup_def)\n   apply (simp)\n    (* proving the separation of the new maps *)(*\n  apply (case_tac \"u = u1\")\n   apply (simp add: add_env_def)\n   apply (rule_tac r_s=\"a\" in leq_sep_nres_map)\n    apply (rule_tac self_diff_leq_use_env)\n   apply (erule_tac x=\"u1\" in allE)\n   apply (auto)\n  apply (case_tac \"u = u2\")\n   apply (simp add: add_env_def)\n   apply (rule_tac comp_sep_nres_map)\n    apply (erule_tac x=\"u2\" in allE)\n    apply (auto)\n   apply (erule_tac x=\"u1\" in allE)\n   apply (auto)\n   apply (rule_tac r_s=\"lift_use_env a r\" in leq_sep_nres_map)\n    apply (simp)\n   apply (simp add: sep_nres_map_def)\n    apply (auto)\n   apply (rule_tac lift_strong_disj_use_env1)\n   apply (simp)\n  apply (simp add: add_env_def)*)\n  done\n    \n    \nend", "meta": {"author": "dcco", "repo": "perm_lang_thesis", "sha": "81661c97a0c43701c9ec0a75074d9553b2dd0263", "save_path": "github-repos/isabelle/dcco-perm_lang_thesis", "path": "github-repos/isabelle/dcco-perm_lang_thesis/perm_lang_thesis-81661c97a0c43701c9ec0a75074d9553b2dd0263/isa_code/ProcSendCase.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297746074044134, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.28301606994047906}}
{"text": "section\\<open>The Needham-Schroeder Public-Key Protocol against Dolev-Yao --- with Gets event, hence with Reception rule\\<close>\n\ntheory NS_Public_Bad imports Public begin\n\ninductive_set ns_public :: \"event list set\"\n  where\n         (*Initial trace is empty*)\n   Nil:  \"[] \\<in> ns_public\"\n\n         (*The spy MAY say anything he CAN say.  We do not expect him to\n           invent new nonces here, but he can also use NS1.  Common to\n           all similar protocols.*)\n | Fake: \"\\<lbrakk>evsf \\<in> ns_public;  X \\<in> synth (analz (knows Spy evsf))\\<rbrakk>\n          \\<Longrightarrow> Says Spy B X  # evsf \\<in> ns_public\"\n\n         (*A message that is sent may be received*)\n | Reception: \"\\<lbrakk>evsr \\<in> ns_public; Says A B X \\<in> set evsr\\<rbrakk>\n                \\<Longrightarrow> Gets B X # evsr \\<in> ns_public\"\n\n         (*Alice initiates a protocol run, sending a nonce to Bob*)\n | NS1:  \"\\<lbrakk>evs1 \\<in> ns_public;  Nonce NA \\<notin> used evs1\\<rbrakk>\n          \\<Longrightarrow> Says A B (Crypt (pubEK B) \\<lbrace>Nonce NA, Agent A\\<rbrace>)\n                # evs1  \\<in>  ns_public\"\n\n         (*Bob responds to Alice's message with a further nonce*)\n | NS2:  \"\\<lbrakk>evs2 \\<in> ns_public;  Nonce NB \\<notin> used evs2;\n           Gets B (Crypt (pubEK B) \\<lbrace>Nonce NA, Agent A\\<rbrace>) \\<in> set evs2\\<rbrakk>\n          \\<Longrightarrow> Says B A (Crypt (pubEK A) \\<lbrace>Nonce NA, Nonce NB\\<rbrace>)\n                # evs2  \\<in>  ns_public\"\n\n         (*Alice proves her existence by sending NB back to Bob.*)\n | NS3:  \"\\<lbrakk>evs3 \\<in> ns_public;\n           Says A  B (Crypt (pubEK B) \\<lbrace>Nonce NA, Agent A\\<rbrace>) \\<in> set evs3;\n           Gets A (Crypt (pubEK A) \\<lbrace>Nonce NA, Nonce NB\\<rbrace>) \\<in> set evs3\\<rbrakk>\n          \\<Longrightarrow> Says A B (Crypt (pubEK B) (Nonce NB)) # evs3 \\<in> ns_public\"\n\ndeclare knows_Spy_partsEs [elim] thm knows_Spy_partsEs\ndeclare analz_into_parts [dest]\ndeclare Fake_parts_insert_in_Un [dest]\n\n(*A \"possibility property\": there are traces that reach the end*)\nlemma \"\\<exists>NB. \\<exists>evs \\<in> ns_public. Says A B (Crypt (pubEK B) (Nonce NB)) \\<in> set evs\"\napply (intro exI bexI)\napply (rule_tac [2] ns_public.Nil [THEN ns_public.NS1, THEN ns_public.Reception, \n                                   THEN ns_public.NS2, THEN ns_public.Reception, \n                                   THEN ns_public.NS3])\nby possibility\n\n\ntext\\<open>Lemmas about reception invariant: if a message is received it certainly\nwas sent\\<close>\nlemma Gets_imp_Says :\n     \"\\<lbrakk> Gets B X \\<in> set evs; evs \\<in> ns_public \\<rbrakk> \\<Longrightarrow> \\<exists>A. Says A B X \\<in> set evs\"\napply (erule rev_mp)\napply (erule ns_public.induct)\napply auto\ndone\n\nlemma Gets_imp_knows_Spy: \n     \"\\<lbrakk> Gets B X \\<in> set evs; evs \\<in> ns_public \\<rbrakk>  \\<Longrightarrow> X \\<in> knows Spy evs\"\napply (blast dest!: Gets_imp_Says Says_imp_knows_Spy)\ndone\n\nlemma Gets_imp_knows_Spy_parts[dest]:\n    \"\\<lbrakk> Gets B X \\<in> set evs; evs \\<in> ns_public \\<rbrakk>  \\<Longrightarrow> X \\<in> parts (knows Spy evs)\"\napply (blast dest: Gets_imp_knows_Spy [THEN parts.Inj])\ndone\n\n(**** Inductive proofs about ns_public ****)\n\n(** Theorems of the form X \\<notin> parts (knows Spy evs) imply that NOBODY\n    sends messages containing X! **)\n\n(*Spy never sees another agent's private key! (unless it's bad at start)*)\nlemma Spy_see_priEK [simp]: \n      \"evs \\<in> ns_public \\<Longrightarrow> (Key (priEK A) \\<in> parts (knows Spy evs)) = (A \\<in> bad)\"\nby (erule ns_public.induct, auto)\n\nlemma Spy_analz_priEK [simp]: \n      \"evs \\<in> ns_public \\<Longrightarrow> (Key (priEK A) \\<in> analz (knows Spy evs)) = (A \\<in> bad)\"\nby auto\n\n\n(*** Authenticity properties obtained from NS2 ***)\n\n(*It is impossible to re-use a nonce in both NS1 and NS2, provided the nonce\n  is secret.  (Honest users generate fresh nonces.)*)\n\n\n\n(*Unicity for NS1: nonce NA identifies agents A and B*)\nlemma unique_NA: \n     \"\\<lbrakk>Crypt(pubEK B)  \\<lbrace>Nonce NA, Agent A \\<rbrace> \\<in> parts(knows Spy evs);  \n       Crypt(pubEK B') \\<lbrace>Nonce NA, Agent A'\\<rbrace> \\<in> parts(knows Spy evs);  \n       Nonce NA \\<notin> analz (knows Spy evs); evs \\<in> ns_public\\<rbrakk>\n      \\<Longrightarrow> A=A' \\<and> B=B'\"\napply (erule rev_mp, erule rev_mp, erule rev_mp)   \napply (erule ns_public.induct, simp_all)\n(*Fake, NS1*)\napply (blast intro!: analz_insertI)+\ndone\n\n\n(*Secrecy: Spy does not see the nonce sent in msg NS1 if A and B are secure\n  The major premise \"Says A B ...\" makes it a dest-rule, so we use\n  (erule rev_mp) rather than rule_format. *)\ntheorem Spy_not_see_NA: \n      \"\\<lbrakk>Says A B (Crypt(pubEK B) \\<lbrace>Nonce NA, Agent A\\<rbrace>) \\<in> set evs;\n        A \\<notin> bad;  B \\<notin> bad;  evs \\<in> ns_public\\<rbrakk>                     \n       \\<Longrightarrow> Nonce NA \\<notin> analz (knows Spy evs)\"\napply (erule rev_mp)   \napply (erule ns_public.induct, simp_all, spy_analz)\napply (blast dest: unique_NA intro: no_nonce_NS1_NS2)+\ndone\n\n\n(*Authentication for A: if she receives message 2 and has used NA\n  to start a run, then B has sent message 2.*)\nlemma A_trusts_NS2_lemma [rule_format]: \n   \"\\<lbrakk>A \\<notin> bad;  B \\<notin> bad;  evs \\<in> ns_public\\<rbrakk>                     \n    \\<Longrightarrow> Crypt (pubEK A) \\<lbrace>Nonce NA, Nonce NB\\<rbrace> \\<in> parts (knows Spy evs) \\<longrightarrow>\n        Says A B (Crypt(pubEK B) \\<lbrace>Nonce NA, Agent A\\<rbrace>) \\<in> set evs \\<longrightarrow>\n        Says B A (Crypt(pubEK A) \\<lbrace>Nonce NA, Nonce NB\\<rbrace>) \\<in> set evs\"\napply (erule ns_public.induct)\napply (auto dest: Spy_not_see_NA unique_NA)\ndone\n\ntheorem A_trusts_NS2: \n     \"\\<lbrakk>Says A  B (Crypt(pubEK B) \\<lbrace>Nonce NA, Agent A\\<rbrace>) \\<in> set evs;   \n       Gets A (Crypt(pubEK A) \\<lbrace>Nonce NA, Nonce NB\\<rbrace>) \\<in> set evs;\n       A \\<notin> bad;  B \\<notin> bad;  evs \\<in> ns_public\\<rbrakk>                     \n      \\<Longrightarrow> Says B A (Crypt(pubEK A) \\<lbrace>Nonce NA, Nonce NB\\<rbrace>) \\<in> set evs\"\nby (blast intro: A_trusts_NS2_lemma)\n\n\n(*If the encrypted message appears then it originated with Alice in NS1*)\nlemma B_trusts_NS1 [rule_format]:\n     \"evs \\<in> ns_public                                         \n      \\<Longrightarrow> Crypt (pubEK B) \\<lbrace>Nonce NA, Agent A\\<rbrace> \\<in> parts (knows Spy evs) \\<longrightarrow>\n          Nonce NA \\<notin> analz (knows Spy evs) \\<longrightarrow>\n          Says A B (Crypt (pubEK B) \\<lbrace>Nonce NA, Agent A\\<rbrace>) \\<in> set evs\"\napply (erule ns_public.induct, simp_all)\n(*Fake*)\napply (blast intro!: analz_insertI)\ndone\n\n\n\n(*** Authenticity properties obtained from NS2 ***)\n\n(*Unicity for NS2: nonce NB identifies nonce NA and agent A\n  [proof closely follows that for unique_NA] *)\nlemma unique_NB [dest]: \n     \"\\<lbrakk>Crypt(pubEK A)  \\<lbrace>Nonce NA, Nonce NB\\<rbrace> \\<in> parts(knows Spy evs);\n       Crypt(pubEK A') \\<lbrace>Nonce NA', Nonce NB\\<rbrace> \\<in> parts(knows Spy evs);\n       Nonce NB \\<notin> analz (knows Spy evs); evs \\<in> ns_public\\<rbrakk>\n     \\<Longrightarrow> A=A' \\<and> NA=NA'\"\napply (erule rev_mp, erule rev_mp, erule rev_mp)   \napply (erule ns_public.induct, simp_all)\n(*Fake, NS2*)\napply (blast intro!: analz_insertI)+\ndone\n\n\n(*NB remains secret PROVIDED Alice never responds with round 3*)\ntheorem Spy_not_see_NB [dest]:\n     \"\\<lbrakk>Says B A (Crypt (pubEK A) \\<lbrace>Nonce NA, Nonce NB\\<rbrace>) \\<in> set evs;   \n       \\<forall>C. Says A C (Crypt (pubEK C) (Nonce NB)) \\<notin> set evs;       \n       A \\<notin> bad;  B \\<notin> bad;  evs \\<in> ns_public\\<rbrakk>                      \n     \\<Longrightarrow> Nonce NB \\<notin> analz (knows Spy evs)\"\napply (erule rev_mp, erule rev_mp)\napply (erule ns_public.induct, simp_all, spy_analz)\napply (simp_all add: all_conj_distrib) (*speeds up the next step*)\napply (blast intro: no_nonce_NS1_NS2)+\ndone\n\n\n(*Authentication for B: if he receives message 3 and has used NB\n  in message 2, then A has sent message 3--to somebody....*)\n\nlemma B_trusts_NS3_lemma [rule_format]:\n     \"\\<lbrakk>A \\<notin> bad;  B \\<notin> bad;  evs \\<in> ns_public\\<rbrakk>                    \n      \\<Longrightarrow> Crypt (pubEK B) (Nonce NB) \\<in> parts (knows Spy evs) \\<longrightarrow>\n          Says B A  (Crypt (pubEK A) \\<lbrace>Nonce NA, Nonce NB\\<rbrace>) \\<in> set evs \\<longrightarrow>\n          (\\<exists>C. Says A C (Crypt (pubEK C) (Nonce NB)) \\<in> set evs)\"\napply (erule ns_public.induct, auto)\nby (blast intro: no_nonce_NS1_NS2)+\n\ntheorem B_trusts_NS3:\n     \"\\<lbrakk>Says B A  (Crypt (pubEK A) \\<lbrace>Nonce NA, Nonce NB\\<rbrace>) \\<in> set evs;\n       Gets B (Crypt (pubEK B) (Nonce NB)) \\<in> set evs;             \n       A \\<notin> bad;  B \\<notin> bad;  evs \\<in> ns_public\\<rbrakk>                    \n      \\<Longrightarrow> \\<exists>C. Says A C (Crypt (pubEK C) (Nonce NB)) \\<in> set evs\"\nby (blast intro: B_trusts_NS3_lemma)\n\n\n(*Can we strengthen the secrecy theorem Spy_not_see_NB?  NO*)\nlemma \"\\<lbrakk>A \\<notin> bad;  B \\<notin> bad;  evs \\<in> ns_public\\<rbrakk>            \n       \\<Longrightarrow> Says B A (Crypt (pubEK A) \\<lbrace>Nonce NA, Nonce NB\\<rbrace>) \\<in> set evs  \n           \\<longrightarrow> Nonce NB \\<notin> analz (knows Spy evs)\"\napply (erule ns_public.induct, simp_all, spy_analz)\n(*NS1: by freshness*)\napply blast\n(*NS2: by freshness and unicity of NB*)\napply (blast intro: no_nonce_NS1_NS2)\n(*NS3: unicity of NB identifies A and NA, but not B*)\napply clarify\napply (frule_tac A' = A in \n       Says_imp_knows_Spy [THEN parts.Inj, THEN unique_NB], auto)\napply (rename_tac evs3 B' C)\ntxt\\<open>This is the attack!\n@{subgoals[display,indent=0,margin=65]}\n\\<close>\noops\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Inductive_Confidentiality/DolevYao/NS_Public_Bad.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297745935070808, "lm_q2_score": 0.4493926344647596, "lm_q1q2_score": 0.2830160636951201}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory GraphLang\n\nimports\n  \"CParser.TypHeapLib\"\n  \"Lib.SplitRule\"\n  \"CommonOps\"\n\nbegin\n\ntext \\<open>Note that machine states here are assumed to be countable and\nare thus represented by naturals.\\<close>\n\ndatatype variable =\n    VarNone\n  | VarWord8 word8\n  | VarWord16 word16\n  | VarWord32 word32\n  | VarWord64 word64\n  | VarMem \"machine_word \\<Rightarrow> word8\"\n  | VarDom \"machine_word set\"\n  | VarGhostState \"ghost_assertions\"\n  | VarHTD \"heap_typ_desc\"\n  | VarMS \"unit \\<times> nat\"\n  | VarBool bool\n\ntext \\<open>States are a mapping from names to the variable type, which is\na union of the available names.\\<close>\n\ndatatype state = State \"string \\<Rightarrow> variable\"\n\ntext \\<open>Accessors for grabbing variables by name and expected type.\\<close>\n\ndefinition\n  \"var_acc nm st = (case st of State f \\<Rightarrow> f nm)\"\n\ndefinition\n  \"var_word8 nm st = (case var_acc nm st of\n    VarWord8 w \\<Rightarrow> w | _ \\<Rightarrow> 0)\"\n\ndefinition\n  \"var_word16 nm st = (case var_acc nm st of\n    VarWord16 w \\<Rightarrow> w | _ \\<Rightarrow> 0)\"\n\ndefinition\n  \"var_word32 nm st = (case var_acc nm st of\n    VarWord32 w \\<Rightarrow> w | _ \\<Rightarrow> 0)\"\n\ndefinition\n  \"var_word64 nm st = (case var_acc nm st of\n    VarWord64 w \\<Rightarrow> w | _ \\<Rightarrow> 0)\"\n\ndefinition\n  \"var_ghoststate nm st = (case var_acc nm st of\n    VarGhostState arr \\<Rightarrow> arr | _ \\<Rightarrow> (\\<lambda>_. 0))\"\n\ndefinition\n  \"var_mem nm st = (case var_acc nm st of\n    VarMem m \\<Rightarrow> m | _ \\<Rightarrow> \\<lambda>_. 0)\"\n\ndefinition\n  \"var_dom nm st = (case var_acc nm st of\n    VarDom d \\<Rightarrow> d | _ \\<Rightarrow> {})\"\n\ndefinition\n  \"var_htd nm st = (case var_acc nm st of\n    VarHTD htd \\<Rightarrow> htd | _ \\<Rightarrow> empty_htd)\"\n\ndefinition\n  \"var_ms nm st = (case var_acc nm st of\n    VarMS ms \\<Rightarrow> ms | _ \\<Rightarrow> ((), 0))\"\n\ndefinition\n  \"var_bool nm st = (case var_acc nm st of\n    VarBool bool \\<Rightarrow> bool | _ \\<Rightarrow> False)\"\n\ntext \\<open>The variable updator.\\<close>\n\ndefinition\n  \"var_upd nm v st = (case st of State f \\<Rightarrow> State (f (nm := v)))\"\n\ndefinition\n  \"default_state = State (\\<lambda>_. VarNone)\"\n\ntext \\<open>The type of nodes.\\<close>\n\ndatatype next_node =\n    NextNode nat | Ret | Err\n\ndatatype node =\n    Basic next_node \"(string \\<times> (state \\<Rightarrow> variable)) list\"\n  | Cond next_node next_node \"state \\<Rightarrow> bool\"\n  | Call next_node string \"(state \\<Rightarrow> variable) list\" \"string list\"\n\ndefinition Skip where\n  \"Skip nn = Cond nn nn (\\<lambda>x. True)\"\n\ntext \\<open>The type for a total graph function, including list of inputs,\n  list of outputs, graph, and entry point.\\<close>\n\ndatatype graph_function\n  = GraphFunction \"string list\" \"string list\" \"nat \\<Rightarrow> node option\" nat\n\nprimrec entry_point where\n  \"entry_point (GraphFunction inputs outputs graph ep) = ep\"\n\nprimrec function_graph where\n  \"function_graph (GraphFunction inputs outputs graph ep) = graph\"\n\nprimrec function_inputs where\n  \"function_inputs (GraphFunction inputs outputs graph ep) = inputs\"\n\nprimrec function_outputs where\n  \"function_outputs (GraphFunction inputs outputs graph ep) = outputs\"\n\ntext \\<open>The definition of execution, including a stack to allow function calls.\\<close>\n\ndefinition\n  save_vals :: \"string list \\<Rightarrow> variable list \\<Rightarrow> state \\<Rightarrow> state\"\nwhere\n \"save_vals vars vals st = fold (\\<lambda>(var, val). var_upd var val) (zip vars vals) st\"\n\ndefinition\n  init_vars :: \"string list \\<Rightarrow> (state \\<Rightarrow> variable) list \\<Rightarrow> state \\<Rightarrow> state\"\nwhere\n  \"init_vars vars accs st = save_vals vars (map (\\<lambda>i. i st) accs) default_state\"\n\ndefinition\n  acc_vars :: \"string list \\<Rightarrow> state \\<Rightarrow> variable list\"\nwhere\n  \"acc_vars vars st = map (\\<lambda>v. var_acc v st) vars\"\n\ndefinition\n  return_vars :: \"string list \\<Rightarrow> string list \\<Rightarrow> state \\<Rightarrow> state \\<Rightarrow> state\"\nwhere\n  \"return_vars inner outer inner_st = save_vals outer (acc_vars inner inner_st)\"\n\ndefinition\n  upd_vars :: \"(string \\<times> (state \\<Rightarrow> variable)) list \\<Rightarrow> state \\<Rightarrow> state\"\nwhere\n  \"upd_vars upds st = save_vals (map fst upds) (map (\\<lambda>(nm, vf). vf st) upds) st\"\n\ntype_synonym stack = \"(next_node \\<times> state \\<times> string) list\"\n\nprimrec\n  upd_stack :: \"next_node \\<Rightarrow> (state \\<Rightarrow> state) \\<Rightarrow> stack \\<Rightarrow> stack\"\nwhere\n    \"upd_stack nn stf (x # xs) = (nn, stf (fst (snd x)), snd (snd x)) # xs\"\n  | \"upd_stack nn stf [] = []\"\n\nprimrec\n  exec_node :: \"(string \\<Rightarrow> graph_function option)\n        \\<Rightarrow> state \\<Rightarrow> node \\<Rightarrow> stack \\<Rightarrow> stack set\"\nwhere\n    \"exec_node Gamma st (Basic cont upds) stack\n        = {upd_stack cont (K (upd_vars upds st)) stack}\"\n  | \"exec_node Gamma st (Cond left right cond) stack\n        = {upd_stack (if cond st then left else right) id stack}\"\n  | \"exec_node Gamma st (Call cont fname inputs outputs) stack\n        = (case Gamma fname of None \\<Rightarrow> {upd_stack Err id stack}\n            | Some (GraphFunction inps outps graph ep)\n                \\<Rightarrow> {(NextNode ep, init_vars inps inputs st, fname)\n                        # stack})\"\n\nprimrec\n  exec_node_return :: \"(string \\<Rightarrow> graph_function option)\n        \\<Rightarrow> state \\<Rightarrow> node \\<Rightarrow> stack \\<Rightarrow> stack set\"\nwhere\n    \"exec_node_return _ _ (Basic _ _) stack = {}\"\n  | \"exec_node_return _ _ (Cond _ _ _) stack = {}\"\n  | \"exec_node_return Gamma st (Call cont fname inputs outputs) stack\n        = (case Gamma fname of None \\<Rightarrow> {}\n            | Some (GraphFunction inps outps graph ep)\n                \\<Rightarrow> {upd_stack cont (return_vars outps outputs st) stack})\"\n\ntext \\<open>The single-step relation on graph states.\\<close>\n\ndefinition\n  exec_graph_step :: \"(string \\<Rightarrow> graph_function option)\n        \\<Rightarrow> (stack \\<times> stack) set\"\nwhere\n    \"exec_graph_step Gamma = {(stack, stack'). case stack of\n            (NextNode nn, st, fname) # _ \\<Rightarrow>\n                (case Gamma fname of None \\<Rightarrow> False\n                    | Some (GraphFunction _ _ graph _) \\<Rightarrow>\n                        (case graph nn of None \\<Rightarrow> stack' = upd_stack Err id stack\n                            | Some node \\<Rightarrow> stack' \\<in> exec_node Gamma st node stack))\n          | (Ret, st, _) # (NextNode nn, _, fname) # _ \\<Rightarrow>\n                (case Gamma fname of None \\<Rightarrow> False\n                    | Some (GraphFunction _ _ graph _) \\<Rightarrow>\n                        (case graph nn of None \\<Rightarrow> stack' = upd_stack Err id (tl stack)\n                            | Some node \\<Rightarrow> stack' \\<in> exec_node_return Gamma st node (tl stack)))\n          | [] \\<Rightarrow> False\n          | [_] \\<Rightarrow> False \\<comment> \\<open>note NextNode case is handled\\<close>\n          | _ \\<Rightarrow> stack' = upd_stack Err id (tl stack)\n      }\"\n\ntext \\<open>Multi-step relations.\\<close>\n\ndefinition exec_graph\nwhere \"exec_graph Gamma = rtrancl (exec_graph_step Gamma)\"\n\ndefinition exec_graph_n\nwhere \"exec_graph_n Gamma n = exec_graph_step Gamma ^^ n\"\n\nlemma relpow_Suc_simp2:\n  \"R ^^ Suc n = R O R ^^ n\"\n  apply safe\n   apply (erule relpow_Suc_E2, blast)\n  apply (blast intro: relpow_Suc_I2)\n  done\n\nlemma exec_graph_n_take_step:\n  \"\\<lbrakk> (stack, stack') \\<in> exec_graph_n GGamma n;\n    \\<lbrakk> n = 0; stack' = stack \\<rbrakk> \\<Longrightarrow> P;\n    \\<And>stack''. \\<lbrakk> n > 0; (stack, stack'') \\<in> exec_graph_step GGamma;\n            (stack'', stack') \\<in> exec_graph_n GGamma (n - 1) \\<rbrakk>\n        \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P\"\n  apply (cases n, simp_all only: exec_graph_n_def relpow_Suc_simp2)\n   apply simp\n  apply clarsimp\n  done\n\nlemma exec_graph_take_step:\n  \"\\<lbrakk> ((NextNode m, gst, fname) # stack, stack') \\<in> exec_graph_n GGamma n;\n            GGamma fname = Some gf; function_graph gf m = Some node \\<rbrakk>\n    \\<Longrightarrow> (n = 0 \\<and> stack' = (NextNode m, gst, fname) # stack)\n    \\<or> (\\<exists>stack''. n \\<ge> 1\n            \\<and> stack'' \\<in> exec_node GGamma gst node\n                    ((NextNode m, gst, fname) # stack)\n            \\<and> (stack'', stack') \\<in> exec_graph_n GGamma (n - 1))\"\n  apply (erule exec_graph_n_take_step)\n   apply simp\n  apply (clarsimp simp: exec_graph_step_def split: graph_function.split_asm)\n  apply blast\n  done\n\ndefinition\n  continuing :: \"stack \\<Rightarrow> bool\"\nwhere\n  \"continuing st = (case st of [] \\<Rightarrow> False\n    | [(NextNode _, _, _)] \\<Rightarrow> True | [_] \\<Rightarrow> False | _ \\<Rightarrow> True)\"\n\nlemma continuing_simps[simp]:\n  \"\\<not> continuing []\"\n  \"continuing [(unn, st, g)] = (unn \\<noteq> Ret \\<and> unn \\<noteq> Err)\"\n  \"continuing ((Ret, st, g) # stk) = (stk \\<noteq> [])\"\n  \"continuing (stf # stf' # stk)\"\n  \"continuing ((NextNode nn, st, g) # stk)\"\n  \"continuing ((Err, st, g) # stk) = (stk \\<noteq> [])\"\n  by (simp_all add: continuing_def split: next_node.split list.split)\n\nlemma consume_Not_eq:\n  \"(\\<not> P) = Q \\<Longrightarrow> P = (\\<not> Q)\"\n  by clarsimp\n\nlemma exec_node_case_helper:\n  \"(stk' \\<in> exec_node Gamma st node stk)\n    = (case node of Basic _ _ \\<Rightarrow> stk' \\<in> id (exec_node Gamma) st node stk\n        | _ \\<Rightarrow> stk' \\<in> id (exec_node Gamma) st node stk)\"\n  \"(stk' \\<in> exec_node_return Gamma st node stk)\n    = (case node of Basic _ _ \\<Rightarrow> stk' \\<in> id (exec_node_return Gamma) st node stk\n        | _ \\<Rightarrow> stk' \\<in> id (exec_node_return Gamma) st node stk)\"\n  by (simp_all split: node.split)\n\nlemmas splits_raw = prod.split list.split option.split\n    next_node.split graph_function.split node.split\nlemmas splits_cooked = splits_raw[where P=Not, THEN consume_Not_eq]\n    option.split[where P=\"\\<lambda>S. x \\<notin> S\", THEN consume_Not_eq]\n    graph_function.split[where P=\"\\<lambda>S. x \\<notin> S\", THEN consume_Not_eq] for x\n\nlemmas all_exec_graph_step_cases = exec_graph_step_def[THEN eqset_imp_iff,\n    simplified, unfolded exec_node_case_helper splits_cooked, simplified,\n    unfolded splits_cooked, simplified]\n\nlemma exec_node_stack_extend:\n  \"continuing stack \\<Longrightarrow>\n    (stack' \\<in> exec_node Gamma st node (stack @ xs))\n        = (\\<exists>stack''. stack' = stack'' @ xs\n                \\<and> stack'' \\<in> exec_node Gamma st node stack)\"\n  apply (cases node, simp_all)\n  apply (simp_all add: continuing_def\n                split: list.split_asm prod.split_asm next_node.split_asm)\n  apply (auto split: option.split graph_function.split)\n  done\n\nlemma exec_node_return_stack_extend:\n  \"continuing stack \\<Longrightarrow>\n    (stack' \\<in> exec_node_return Gamma st node (stack @ xs))\n        = (\\<exists>stack''. stack' = stack'' @ xs\n                \\<and> stack'' \\<in> exec_node_return Gamma st node stack)\"\n  apply (cases node, simp_all)\n  apply (simp_all add: continuing_def\n                split: list.split_asm prod.split_asm next_node.split_asm)\n  apply (auto split: option.split graph_function.split)\n  done\n\nlemma exec_graph_step_stack_extend:\n  \"continuing stack \\<Longrightarrow>\n    ((stack @ xs, stack') \\<in> exec_graph_step Gamma)\n    = (\\<exists>stack''. stack' = stack'' @ xs\n        \\<and> (stack, stack'') \\<in> exec_graph_step Gamma)\"\n  using exec_node_stack_extend[where stack'=stack' and stack=stack\n            and Gamma=Gamma and xs=xs]\n        exec_node_return_stack_extend[where stack'=stack' and stack=\"tl stack\"\n            and Gamma=Gamma and xs=xs]\n  apply (simp add: exec_graph_step_def)\n  apply (cases stack, simp_all)\n  apply clarsimp\n  apply (case_tac a, simp_all)\n    apply (clarsimp split: option.split graph_function.split)\n   apply (clarsimp simp: neq_Nil_conv split: list.split)\n   apply (clarsimp split: next_node.split option.split graph_function.split)\n  apply (clarsimp simp: neq_Nil_conv split: list.split)\n  done\n\nlemma exec_graph_n_stack_extend:\n  \"continuing stack \\<Longrightarrow>\n    ((stack @ xs, stack') \\<in> exec_graph_n Gamma n)\n    = (\\<exists>stack'' n'. (stack, stack'') \\<in> (exec_graph_step Gamma\n                \\<inter> {(st, _). continuing st}) ^^ n'\n        \\<and> ((n' < n \\<and> \\<not> continuing stack''\n                \\<and> (stack'' @ xs, stack') \\<in> exec_graph_n Gamma (n - n'))\n            \\<or> (stack' = stack'' @ xs \\<and> n' = n)))\"\n  unfolding exec_graph_n_def\nproof (induct n arbitrary: stack)\n  case 0\n  show ?case\n    by auto[1]\nnext\n  case (Suc n stack)\n  show ?case\n    apply (simp only: relpow_Suc_simp2)\n    apply (rule iffI)\n     apply (clarsimp simp: exec_graph_step_stack_extend Suc.prems)\n     apply (case_tac \"continuing stack''\")\n      apply (frule Suc.hyps, clarsimp)\n      apply (rule_tac x=\"stack''a\" in exI, rule_tac x=\"Suc n'\" in exI)\n      apply (simp only: relpow_Suc_simp2, clarsimp)\n      apply (blast intro: Suc.prems)\n     apply (rule_tac x=\"stack''\" in exI, rule_tac x=1 in exI)\n     apply (auto simp: Suc.prems)[1]\n    apply (clarsimp)\n    apply (case_tac n', simp_all only: minus_nat.diff_0 relpow_Suc_simp2)\n     apply auto[1]\n    apply clarsimp\n    apply (rule_tac b=\"y @ xs\" in relcompI)\n     apply (simp add: exec_graph_step_stack_extend Suc.prems)\n    apply (case_tac \"nat = 0\")\n     apply auto[1]\n    apply (subst Suc.hyps)\n     apply (case_tac nat, simp_all only: relpow_Suc_simp2, auto)[1]\n    apply auto[1]\n    done\nqed\n\ndefinition\n  \"init_state fname gfun xs =\n    (NextNode (entry_point gfun), save_vals (function_inputs gfun) xs default_state, fname)\"\n\nlemma exec_graph_step_nonempty:\n  \"\\<lbrakk> (stack, stack') \\<in> exec_graph_step Gamma ^^ n; stack \\<noteq> [] \\<rbrakk>\n    \\<Longrightarrow> stack' \\<noteq> []\"\n  by (cases n, auto simp: all_exec_graph_step_cases\n                   split: graph_function.split_asm)\n\nlemma relpow_mono:\n  \"\\<lbrakk> R \\<subseteq> (S :: ('a \\<times> 'a) set) \\<rbrakk> \\<Longrightarrow> R ^^ n \\<subseteq> S ^^ n\"\n  by (induct n, auto)\n\nlemma drop_eq_Cons:\n  \"(drop n xs = x # ys) = (\\<exists>zs. length zs = n \\<and> xs = zs @ x # ys)\"\n  apply (induct n arbitrary: xs)\n   apply simp\n  apply (case_tac xs, auto simp add: length_Suc_conv)\n  done\n\nlemma exec_graph_step_n_Err:\n  \"(((Err, st, graph) # stack, stack') \\<in> exec_graph_n Gamma n)\n    \\<Longrightarrow> stack' = upd_stack Err id (drop n ((Err, st, graph) # stack))\n        \\<and> drop n ((Err, st, graph) # stack) \\<noteq> []\"\nproof (induct n arbitrary: stack')\n  case 0\n  show ?case using 0\n    by (auto simp add: exec_graph_n_def)\nnext\n  case (Suc n)\n  show ?case using Suc.prems\n    apply (clarsimp simp: exec_graph_n_def relcomp_unfold linorder_not_le)\n    apply (drule exec_graph_step_def[THEN eqset_imp_iff, THEN iffD1])\n    apply (case_tac y, simp_all)\n    apply (drule Suc.hyps[rotated, unfolded exec_graph_n_def])\n    apply (simp only: neq_Nil_conv)\n    apply (clarsimp simp: linorder_not_le drop_eq_Cons)\n    apply (clarsimp split: list.split_asm)\n    apply (case_tac zs, simp_all)\n    done\nqed\n\ntext \\<open>Possibly infinite traces.\\<close>\n\ndefinition nat_trace_rel\n  where \"nat_trace_rel cont r = {tr. (\\<forall>n. (tr n = None \\<longrightarrow> tr (Suc n) = None)\n    \\<and> (tr (Suc n) \\<noteq> None \\<longrightarrow> (the (tr n), the (tr (Suc n))) \\<in> r)\n    \\<and> (tr n \\<noteq> None \\<and> cont (the (tr n)) \\<longrightarrow> tr (Suc n) \\<noteq> None))}\"\n\ntype_synonym trace = \"(nat \\<Rightarrow> stack option)\"\n\ndefinition\n  trace_end :: \"(nat \\<Rightarrow> 'a option) \\<Rightarrow> 'a option\"\nwhere\n  \"trace_end tr = (if \\<exists>n. tr n = None then tr (Max (dom tr)) else None)\"\n\nlemma nat_trace_rel_Some_range:\n  \"tr \\<in> nat_trace_rel cont r \\<Longrightarrow> tr n = Some v\n    \\<Longrightarrow> \\<forall>i \\<le> n. \\<exists>v'. tr i = Some v'\"\n  apply (induct n arbitrary: v, simp_all)\n  apply (simp add: nat_trace_rel_def le_Suc_eq)\n  apply (drule_tac x=n in spec, clarsimp)\n  done\n\nlemma trace_None_dom_subset:\n  \"tr n = None \\<Longrightarrow> tr \\<in> nat_trace_rel cont R\n    \\<Longrightarrow> dom tr \\<subseteq> {..< n}\"\n  apply clarsimp\n  apply (drule_tac n=x in nat_trace_rel_Some_range, simp+)\n  apply (drule_tac x=\"n\" in spec)\n  apply simp\n  done\n\nlemma nat_trace_Max_dom_None:\n  \"tr \\<in> nat_trace_rel cont R \\<Longrightarrow> tr n \\<noteq> None \\<Longrightarrow> (tr (Max (dom tr)) \\<noteq> None)\"\n  apply (rule notI)\n  apply (frule(1) trace_None_dom_subset)\n  apply (cases \"dom tr = {}\")\n   apply clarsimp\n  apply (drule Max_in[rotated])\n   apply (simp add: finite_subset)\n  apply clarsimp\n  done\n\nlemma trace_end_NoneD:\n  \"trace_end tr = None \\<Longrightarrow> tr \\<in> nat_trace_rel cont r\n    \\<Longrightarrow> tr = (\\<lambda>_. None) \\<or> (\\<exists>f. tr = Some o f)\"\n  apply (subst disj_commute, rule disjCI)\n  apply (clarsimp simp: fun_eq_iff)\n  apply (simp add: trace_end_def split: if_split_asm)\n   apply (metis nat_trace_Max_dom_None not_None_eq)\n  apply (rule_tac x=\"the o tr\" in exI, simp)\n  done\n\nlemma trace_end_SomeD:\n  \"trace_end tr = Some v \\<Longrightarrow> tr \\<in> nat_trace_rel cont r\n    \\<Longrightarrow> \\<exists>n. tr n = Some v \\<and> tr (Suc n) = None \\<and> \\<not> cont v\"\n  apply (clarsimp simp: trace_end_def split: if_split_asm)\n  apply (rule exI, rule conjI, assumption)\n  apply (case_tac \"tr (Suc (Max (dom tr)))\")\n   apply (simp add: nat_trace_rel_def)\n   apply (metis option.sel option.simps(3))\n  apply (cut_tac x=\"Suc y\" for y in Max_ge[OF finite_subset domI])\n     apply (erule(1) trace_None_dom_subset[rotated])\n    apply simp+\n  done\n\ndefinition\n  exec_trace :: \"(string \\<Rightarrow> graph_function option) \\<Rightarrow> string \\<Rightarrow> trace set\"\nwhere\n  \"exec_trace Gamma fname\n    = {trace. \\<exists>gf. Gamma fname = Some gf\n        \\<and> (\\<exists>st. trace 0 = Some [(NextNode (entry_point gf), st, fname)])\n        \\<and> trace \\<in> nat_trace_rel continuing (exec_graph_step Gamma)}\"\n\nlemma relpow_nat_trace:\n  \"((s, s') \\<in> r ^^ n) = (\\<exists>tr \\<in> nat_trace_rel (\\<lambda>x. False) r. tr 0 = Some s\n    \\<and> tr n = Some s' \\<and> tr (Suc n) = None)\"\n  apply (simp add: relpow_fun_conv, safe)\n   apply (rule_tac x=\"\\<lambda>x. if x < Suc n then Some (f x) else None\" in bexI)\n    apply simp\n   apply (simp add: nat_trace_rel_def)\n  apply (rule_tac x=\"the o tr\" in exI)\n  apply (frule(1) nat_trace_rel_Some_range[where n=n])\n  apply (clarsimp simp: nat_trace_rel_def)\n  done\n\ntext \\<open>Parsing code for the graph language.\\<close>\n\nML \\<open>\n\nstructure ParseGraph = struct\n\nexception PARSEGRAPH of string list\n\nval debug = ref false\n\nfun trace s = if (! debug) then writeln s else ()\n\nfun parse_int str = if String.isPrefix \"-\" str\n  then ~ (parse_int (unprefix \"-\" str))\n  else case read_int (raw_explode str)\n  of (n, []) => n\n    | _ => raise PARSEGRAPH [\"read_int:\", str]\n\nval s = @{term \"s :: state\"}\n\nfun parse_n p (n :: ss) = let\n    val n = parse_int n\n  in funpow_yield n p ss end\n  | parse_n _ [] = raise PARSEGRAPH [\"parse_n: empty\"]\n\nfun mk_binT sz = Word_Lib.mk_wordT sz |> dest_Type |> snd |> hd\n\nval ptr_size_str =\n    case @{typ machine_word} of\n      @{typ word32} => \"32\"\n    | @{typ word64} => \"64\"\n\nfun parse_typ (\"Word\" :: n :: ss) = let\n    val n = parse_int n\n  in (Word_Lib.mk_wordT n, ss) end\n  | parse_typ (\"Bool\" :: ss) = (@{typ bool}, ss)\n  | parse_typ (\"Mem\" :: ss) = (@{typ \"machine_word \\<Rightarrow> word8\"}, ss)\n  | parse_typ (\"Dom\" :: ss) = (@{typ \"machine_word set\"}, ss)\n  | parse_typ (\"HTD\" :: ss) = (@{typ heap_typ_desc}, ss)\n  | parse_typ (\"PMS\" :: ss) = (@{typ nat}, ss)\n  | parse_typ (\"UNIT\" :: ss) = (@{typ unit}, ss)\n  | parse_typ (\"Array\" :: ss) = let\n    val (el_typ, ss) = parse_typ ss\n    val (n, ss) = case ss of (n :: ss) => (parse_int n, ss)\n        | [] => raise PARSEGRAPH [\"parse_typ: array index\"]\n  in (Type (@{type_name array}, [el_typ, mk_binT n]), ss) end\n  | parse_typ (bad as (\"WordArray\" :: \"50\" :: element_size :: ss)) =\n      (if element_size = ptr_size_str\n      then (@{typ \"ghost_assertions\"}, ss)\n      else raise PARSEGRAPH (\"parse_typ: bad ghost assertion codomain\" :: bad))\n  | parse_typ (\"Struct\" :: nm :: ss) = (Type (nm, []), ss)\n  | parse_typ (\"Ptr\" :: ss) = let\n    val (obj_typ, ss) = parse_typ ss\n  in (Type (@{type_name ptr}, [obj_typ]), ss) end\n  | parse_typ ss = raise PARSEGRAPH (\"parse_typ: malformed\" :: ss)\n\nfun parse_lval (\"VarUpdate\" :: nm :: ss) = let\n    val (_, ss) = parse_typ ss (* FIXME: check typ? *)\n  in (nm, ss) end\n  | parse_lval ss = raise PARSEGRAPH (\"parse_lval\" :: ss)\n\nfun parse_var ss = parse_lval (\"VarUpdate\" :: ss)\n\nval opers = Symtab.make [\n      (\"Plus\", @{const_name \"plus\"}),\n      (\"Minus\", @{const_name \"minus\"}),\n      (\"Times\", @{const_name \"times\"}),\n      (\"Modulus\", @{const_name \"modulo_class.modulo\"}),\n      (\"DividedBy\", @{const_name \"divide_class.divide\"}),\n      (\"BWAnd\", @{const_name \"and\"}),\n      (\"BWOr\", @{const_name \"or\"}),\n      (\"BWXOR\", @{const_name \"xor\"}),\n      (\"And\", @{const_name \"conj\"}),\n      (\"Or\", @{const_name \"disj\"}),\n      (\"Implies\", @{const_name \"implies\"}),\n      (\"Equals\", @{const_name \"HOL.eq\"}),\n      (\"Less\", @{const_name \"less\"}),\n      (\"LessEquals\", @{const_name \"less_eq\"}),\n      (\"SignedLess\", @{const_name \"word_sless\"}),\n      (\"SignedLessEquals\", @{const_name \"word_sle\"}),\n      (\"Not\", @{const_name \"Not\"}),\n      (\"BWNot\", @{const_name \"not\"}),\n      (\"WordCast\", @{const_name \"unsigned\"}),\n      (\"WordCastSigned\", @{const_name \"signed\"}),\n      (\"WordArrayAccess\", @{const_name \"fun_app\"}),\n      (\"WordArrayUpdate\", @{const_name \"fun_upd\"}),\n      (\"CountLeadingZeroes\", @{const_name \"bv_clz\"}),\n      (\"CountTrailingZeroes\", @{const_name \"bv_ctz\"}),\n      (\"True\", @{const_name \"True\"}),\n      (\"False\", @{const_name \"False\"}),\n      (\"IfThenElse\", @{const_name \"If\"}),\n      (\"MemAcc\", @{const_name \"mem_acc\"}),\n      (\"MemUpdate\", @{const_name \"mem_upd\"}),\n      (\"MemDom\", @{const_name \"Set.member\"}),\n      (\"ShiftLeft\", @{const_name \"bvshl\"}),\n      (\"ShiftRight\", @{const_name \"bvlshr\"}),\n      (\"SignedShiftRight\", @{const_name \"bvashr\"}),\n      (\"PValid\", @{const_name pvalid}),\n      (\"PArrayValid\", @{const_name parray_valid}),\n      (\"PAlignValid\", @{const_name palign_valid}),\n      (\"PGlobalValid\", @{const_name pglobal_valid}),\n      (\"PWeakValid\", @{const_name pweak_valid}),\n      (\"HTDUpdate\", @{const_name all_htd_updates})\n  ]\n\nfun mk_acc nm typ st = (case typ of\n        @{typ word8} => @{term var_word8}\n      | @{typ word16} => @{term var_word16}\n      | @{typ word32} => @{term var_word32}\n      | @{typ word64} => @{term var_word64}\n      | @{typ \"machine_word \\<Rightarrow> word8\"} => @{term var_mem}\n      | @{typ \"machine_word set\"} => @{term var_dom}\n      | @{typ \"ghost_assertions\"} => @{term var_ghoststate}\n      | @{typ \"heap_typ_desc\"} => @{term var_htd}\n      | @{typ \"nat\"} => @{term var_ms}\n      | @{typ bool} => @{term var_bool}\n      | Type (@{type_name ptr}, [_]) =>\n          (case @{typ \"machine_word\"} of\n            @{typ word32} => @{term var_word32}\n          | @{typ word64} => @{term var_word64})\n      | _ => raise PARSEGRAPH [\"mk_acc\", nm, fst (dest_Type typ)])\n    $ HOLogic.mk_string nm $ st\n\nfun parse_val (\"Num\" :: ss) = let\n    val (n, ss) = case ss of n :: ss => (n, ss)\n        | [] => raise PARSEGRAPH [\"parse_val: parsing num, no numeral\"]\n    val (typ, ss) = parse_typ ss\n    val n = parse_int n\n  in (HOLogic.mk_number typ n, ss) end\n  | parse_val (\"Op\" :: nm :: ss) = let\n    val const = case Symtab.lookup opers nm\n      of SOME c => c\n      | NONE => raise PARSEGRAPH [\"parse_val: unexpected op\", nm]\n    val (typ, ss) = parse_typ ss\n    val (args, ss) = parse_n parse_val ss\n    val oper = Const (const, map fastype_of args ---> typ)\n  in trace (\"parsed oper \" ^ nm ^ \" and args\");\n    (list_comb (oper, args), ss) end\n  | parse_val (\"Var\" :: nm :: ss) = let\n    val (typ, ss) = parse_typ ss\n  in (mk_acc nm typ s, ss) end\n  | parse_val (\"Type\" :: ss) = let\n    val (typ, ss) = parse_typ ss\n  in (Logic.mk_type typ, ss) end\n  | parse_val (\"Symbol\" :: nm :: ss) = let\n    val (_, ss) = parse_typ ss\n  in (TermsTypes.symbol_table $ HOLogic.mk_string nm, ss) end\n  | parse_val ss = raise PARSEGRAPH (\"parse_val: malformed\" :: ss)\n\nval parse_lvals = parse_n parse_lval\n\nval parse_vars = parse_n parse_var\n\nfun mk_var_typ T = (case T of\n        @{typ word8} => @{term VarWord8}\n      | @{typ word16} => @{term VarWord16}\n      | @{typ word32} => @{term VarWord32}\n      | @{typ word64} => @{term VarWord64}\n      | Type (@{type_name word}, [Type (@{type_name signed}, [T2])])\n        => let val uT = Type (@{type_name word}, [T2])\n        in Abs (\"t\", T, mk_var_typ uT $ (Const (@{const_name unsigned}, T --> uT) $ Bound 0)) end\n      | @{typ \"machine_word \\<Rightarrow> word8\"} => @{term VarMem}\n      | @{typ \"ghost_assertions\"} => @{term VarGhostState}\n      | @{typ \"machine_word set\"} => @{term VarDom}\n      | @{typ \"heap_typ_desc\"} => @{term VarHTD}\n      | @{typ \"unit \\<times> nat\"} => @{term VarMS}\n      | @{typ bool} => @{term VarBool}\n      | _ => raise TYPE (\"mk_var_typ: unexpected var typ\", [T], []))\n\nfun mk_var_term t = betapply (mk_var_typ (fastype_of t), t)\n\nfun parse_val_acc ss = let\n    val (t, ss) = parse_val ss\n  in (Term.lambda_name (\"s\", s) (mk_var_term t), ss) end\n\nfun parse_cond ss = let\n    val (t, ss) = parse_val ss\n  in (Term.lambda_name (\"s\", s) t, ss) end\n\nval parse_vals = parse_n parse_val_acc\n\nfun mk_NextNode n = @{term NextNode} $ HOLogic.mk_number @{typ nat} n\n\nfun parse_nn \"Err\" = @{term Err}\n  | parse_nn \"Ret\" = @{term Ret}\n  | parse_nn n = mk_NextNode (parse_int n)\n\nfun parse_fun_decl (\"Function\" :: nm :: ss) = let\n    val (xs, ss) = parse_vars ss\n    val (ys, ss) = parse_vars ss\n  in\n    ss = [] orelse raise PARSEGRAPH (\"parse_fun_decl: trailing\" :: ss);\n    (nm, xs, ys)\n  end\n  | parse_fun_decl ss = raise PARSEGRAPH (\"parse_fun_decl: malformed\" :: ss)\n\nfun parse_var_and_val_acc ss = let\n    val (var, ss) = parse_var ss\n    val (v, ss) = parse_val_acc ss\n  in (HOLogic.mk_prod (HOLogic.mk_string var, v), ss) end\n\nval mk_stringlist = map HOLogic.mk_string #> HOLogic.mk_list @{typ string}\n\nfun parse_node (n :: ss) = let\n    val n = parse_int n\n    val (t, ss) = case ss of\n      \"Cond\" :: l :: r :: ss => let\n        val l = parse_nn l\n        val r = parse_nn r\n        val (c, ss) = parse_cond ss\n      in (@{term Cond} $ l $ r $ c, ss) end\n      | \"Basic\" :: c :: ss => let\n        val c = parse_nn c\n        val (upds, ss) = parse_n parse_var_and_val_acc ss\n      in (@{term Basic} $ c $ HOLogic.mk_list\n            @{typ \"string \\<times> (state \\<Rightarrow> variable)\"} upds, ss) end\n      | \"Call\" :: c :: fname :: ss => let\n        val c = parse_nn c\n        val (args, ss) = parse_vals ss\n        val (rets, ss) = parse_vars ss\n      in (@{term Call} $ c $ HOLogic.mk_string fname\n            $ HOLogic.mk_list @{typ \"state \\<Rightarrow> variable\"} args\n            $ mk_stringlist rets, ss) end\n      | _ => raise PARSEGRAPH (\"parse_node: malformed\" :: ss)\n  in\n    ss = [] orelse raise PARSEGRAPH (\"parse_node: trailing\" :: ss);\n    (n, t)\n  end\n  | parse_node [] = raise PARSEGRAPH ([\"parse_node: empty\"])\n\nfun parse_fun ([\"Function\" :: ss]) = let\n    val (nm, xs, ys) = parse_fun_decl (\"Function\" :: ss)\n  in SOME (nm, (xs, ys, NONE)) end\n  | parse_fun ((\"Function\" :: ss) :: sss) = let\n    val (nm, xs, ys) = parse_fun_decl (\"Function\" :: ss)\n    val _ = tracing (\"Parsing \" ^ nm)\n    val (node_sss, sss) = chop_prefix\n        (fn ss => not (is_prefix (op =) [\"EntryPoint\"] ss)) sss\n    val (ep, _) = case sss of (ep :: sss) => (ep, sss)\n        | [] => raise PARSEGRAPH [\n        \"parse_fun: EntryPoint not found\"]\n    val ep = case ep of [_, n] => parse_int n\n        | _ => raise PARSEGRAPH (\n        \"parse_fun: EntryPoint line malformed\" :: ep)\n  in\n    SOME (nm, (xs, ys, SOME (ep, map parse_node node_sss,\n        Abs (\"g\", @{typ \"nat \\<Rightarrow> node option\"}, @{term GraphFunction}\n            $ mk_stringlist xs $ mk_stringlist ys\n            $ Bound 0 $ HOLogic.mk_number @{typ nat} ep))))\n  end\n  | parse_fun [] = raise PARSEGRAPH [\"parse_fun: empty\"]\n  | parse_fun (ss :: _) = (warning (\"parse_fun: ignoring: \"\n    ^ space_implode \" \" ss); NONE)\n\nfun fun_groups gp ((fs as (\"Function\" :: _)) :: sss) =\n    (if null gp then [] else [rev gp]) @ fun_groups [fs] sss\n  | fun_groups gp ([] :: sss) = fun_groups gp sss\n  | fun_groups gp (ss :: sss) = fun_groups (ss :: gp) sss\n  | fun_groups gp [] = [rev gp]\n\nfun filename_relative thy name =\n    Path.append (Resources.master_directory thy) (Path.explode name)\n    |> File.standard_path\n\nfun mkdir_relative thy name =\n    Path.append (Resources.master_directory thy) (Path.explode name)\n    |> Isabelle_System.make_directory\n\nfun openIn_relative thy = filename_relative thy #> TextIO.openIn\n\nfun get_funs thy file = let\n    val f = openIn_relative thy file\n    fun get () = case TextIO.inputLine f\n      of NONE => []\n      | SOME s => unsuffix \"\\n\" s :: get ()\n    val lines = get ()\n      |> map (Library.space_explode \" \" #> filter (fn s => s <> \"\"))\n      |> filter_out null\n      |> filter_out (fn (s :: _) => String.isPrefix \"#\" s | _ => false)\n  in fun_groups [] lines end\n\ntype funs = (string list * string list * (int * (int * term) list * term) option) Symtab.table\n\nfun funs thy file : funs = get_funs thy file\n  |> map_filter parse_fun\n  |> Symtab.make\n\nfun define_graph s nodes = let\n    val nodes = sort (int_ord o apply2 fst) nodes\n  in StaticFun.define_tree_and_save_thms (Binding.name s)\n    (map (fst #> Int.toString #> prefix (s ^ \"_\")) nodes)\n    (map (apfst (HOLogic.mk_number @{typ nat})) nodes)\n    @{term \"id :: nat => nat\"} []\n  end\n\nfun define_graph_fun (funs : funs) b1 b2 nm ctxt =\n        case (Symtab.lookup funs nm) of\n    SOME (_, _, SOME (_, g, gf))\n    => let\n    val (graph_term, ctxt) = define_graph b1 g ctxt\n    val (_, ctxt) = Local_Theory.define ((b2, NoSyn), ((Thm.def_binding b2, []),\n        betapply (gf, graph_term))) ctxt\n  in ctxt end\n  | _ => error (\"define_graph_fun: \" ^ nm ^ \" not in funs\")\n\nend\n\n\\<close>\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/asmrefine/GraphLang.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297745935070806, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.28301606369512006}}
{"text": "(* \n   Title: Psi-calculi   \n   Author/Maintainer: Jesper Bengtson (jebe@itu.dk), 2012\n*)\ntheory Tau_Stat_Imp\n  imports Tau_Sim Weaken_Stat_Imp\nbegin\n\nlocale weakTauLaws = weak + tau\nbegin\n\nlemma tauLaw1StatImpLeft:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<lessapprox>\\<^sub>w<Rel> Q\"\n  and     \"(\\<Psi>, \\<tau>.(P), Q) \\<in> Rel\"\n \n  shows \"\\<Psi> \\<rhd> \\<tau>.(P) \\<lessapprox>\\<^sub>w<Rel> Q\"\nproof -\n  have \"\\<Psi> \\<rhd> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q\" by simp\n  moreover have \"insertAssertion (extractFrame(\\<tau>.(P))) \\<Psi> \\<simeq>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi>\\<rangle>\" by(rule insertTauAssertion)\n  hence \"insertAssertion (extractFrame(\\<tau>.(P))) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame Q) \\<Psi>\"\n    by(metis FrameStatImpTrans FrameStatEq_def insertAssertionWeaken)\n  ultimately show ?thesis using \\<open>(\\<Psi>, \\<tau>.(P), Q) \\<in> Rel\\<close>\n    by(rule weakenStatImpI)\nqed\n\nlemma tauLaw1StatImpRight:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<lessapprox><Rel> Q\"\n  and     C1: \"\\<And>\\<Psi> P Q R. \\<lbrakk>(\\<Psi>, P, Q) \\<in> Rel; \\<Psi> \\<rhd> Q \\<sim> R\\<rbrakk> \\<Longrightarrow> (\\<Psi>, P, R) \\<in> Rel'\"\n\n  shows \"\\<Psi> \\<rhd> P \\<lessapprox><Rel'> \\<tau>.(Q)\"\nproof(induct rule: weakStatImpI)\n  case(cStatImp \\<Psi>')\n  from \\<open>\\<Psi> \\<rhd> P \\<lessapprox><Rel> Q\\<close> obtain Q' Q'' \n    where QChain: \"\\<Psi> \\<rhd> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q'\" and PImpQ': \"insertAssertion (extractFrame P) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame Q') \\<Psi>\" \n      and Q'Chain: \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> Q' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q''\" and PRelQ'': \"(\\<Psi> \\<otimes> \\<Psi>', P, Q'') \\<in> Rel\"\n    by(rule weakStatImpE)\n    \n  obtain Q''' where QTrans: \"\\<Psi> \\<rhd> \\<tau>.(Q) \\<longmapsto>\\<tau> \\<prec> Q'''\" and \"\\<Psi> \\<rhd> Q \\<sim> Q'''\" using tauActionI by auto\n  \n  from \\<open>\\<Psi> \\<rhd> Q \\<sim> Q'''\\<close> QChain bisimE(2) obtain Q'''' where Q'''Chain: \"\\<Psi> \\<rhd> Q''' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q''''\" and \"\\<Psi> \\<rhd> Q' \\<sim> Q''''\"\n    by(metis bisimE(4) simTauChain)\n  \n  from QTrans Q'''Chain have \"\\<Psi> \\<rhd> \\<tau>.(Q) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q''''\" by(drule_tac tauActTauChain) auto\n  moreover from \\<open>\\<Psi> \\<rhd> Q' \\<sim> Q''''\\<close> have \"insertAssertion (extractFrame Q') \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame Q'''') \\<Psi>\"\n    by(metis bisimE FrameStatEq_def)\n  with PImpQ'  have \"insertAssertion (extractFrame P) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame Q'''') \\<Psi>\"\n    by(rule FrameStatImpTrans)\n  moreover from \\<open>\\<Psi> \\<rhd> Q' \\<sim> Q''''\\<close> have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> Q' \\<sim> Q''''\" by(rule bisimE) \n  then obtain Q''''' where Q''''Chain: \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> Q'''' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q'''''\" and \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> Q'' \\<sim> Q'''''\" using Q'Chain bisimE(2) \n    by(metis bisimE(4) simTauChain)\n  note Q''''Chain\n  moreover from \\<open>(\\<Psi> \\<otimes> \\<Psi>', P, Q'') \\<in> Rel\\<close> \\<open>\\<Psi> \\<otimes> \\<Psi>' \\<rhd> Q'' \\<sim> Q'''''\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>', P, Q''''') \\<in> Rel'\"\n    by(rule C1)\n  ultimately show ?case by blast\nqed\n\nend\n\ncontext tau begin\n\nlemma tauLaw3StatImpLeft:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha> :: \"'a prefix\"\n\n  assumes C1: \"\\<And>\\<Psi>'. (\\<Psi> \\<otimes> \\<Psi>', \\<alpha>\\<cdot>(\\<tau>.(P)), \\<alpha>\\<cdot>Q) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(P)) \\<lessapprox><Rel> \\<alpha>\\<cdot>Q\"\nproof(induct rule: weakStatImpI)\n  case(cStatImp \\<Psi>')\n  have \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<alpha>\\<cdot>Q\" by auto\n  moreover have \"insertAssertion (extractFrame(\\<alpha>\\<cdot>(\\<tau>.(P)))) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame(\\<alpha>\\<cdot>Q)) \\<Psi>\" using insertTauAssertion\n    by(nominal_induct \\<alpha> rule: prefix.strong_inducts) (auto simp add: FrameStatEq_def intro: FrameStatImpTrans)\n  moreover have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> \\<alpha>\\<cdot>Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<alpha>\\<cdot>Q\" by auto\n  moreover have \"(\\<Psi> \\<otimes> \\<Psi>', \\<alpha>\\<cdot>(\\<tau>.(P)), \\<alpha>\\<cdot>Q) \\<in> Rel\" by(rule C1)\n  ultimately show ?case by blast\nqed\n\nlemma tauLaw3StatImpRight:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes C1: \"\\<And>\\<Psi>'. (\\<Psi> \\<otimes> \\<Psi>', \\<alpha>\\<cdot>P, \\<alpha>\\<cdot>(\\<tau>.(Q))) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<lessapprox><Rel> \\<alpha>\\<cdot>(\\<tau>.(Q))\"\nproof(induct rule: weakStatImpI)\n  case(cStatImp \\<Psi>')\n  have \"\\<Psi> \\<rhd>  \\<alpha>\\<cdot>(\\<tau>.(Q)) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau>  \\<alpha>\\<cdot>(\\<tau>.(Q))\" by auto\n  moreover have \"insertAssertion (extractFrame(\\<alpha>\\<cdot>P)) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame(\\<alpha>\\<cdot>(\\<tau>.(Q)))) \\<Psi>\" using insertTauAssertion\n    by(nominal_induct \\<alpha> rule: prefix.strong_inducts) (auto simp add: FrameStatEq_def intro: FrameStatImpTrans)\n  moreover have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd>  \\<alpha>\\<cdot>(\\<tau>.(Q)) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau>  \\<alpha>\\<cdot>(\\<tau>.(Q))\" by auto\n  moreover have \"(\\<Psi> \\<otimes> \\<Psi>', \\<alpha>\\<cdot>P, \\<alpha>\\<cdot>(\\<tau>.(Q))) \\<in> Rel\" by(rule C1)\n  ultimately show ?case by blast\nqed\n\nend\n\ncontext tauSum begin\n\nlemma tauLaw2StatImpLeft:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n\n  assumes C1: \"\\<And>\\<Psi>'. (\\<Psi> \\<otimes> \\<Psi>', P \\<oplus> \\<tau>.(P), \\<tau>.(P)) \\<in> Rel\" \n\n  shows \"\\<Psi> \\<rhd> P \\<oplus> \\<tau>.(P) \\<lessapprox><Rel> \\<tau>.(P)\"\nproof(induct rule: weakStatImpI)\n  case(cStatImp \\<Psi>')\n  have \"\\<Psi> \\<rhd> \\<tau>.(P) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<tau>.(P)\" by auto\n  moreover have \"insertAssertion (extractFrame(\\<tau>.(P))) \\<Psi> \\<simeq>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi>\\<rangle>\" by(rule insertTauAssertion)\n  hence \"insertAssertion (extractFrame(P \\<oplus> \\<tau>.(P))) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame(\\<tau>.(P))) \\<Psi>\" using Identity\n    by(rule_tac FrameStatImpTrans) (auto simp add: FrameStatEq_def AssertionStatEq_def)\n  moreover have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> \\<tau>.(P) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<tau>.(P)\" by auto\n  moreover have \"(\\<Psi> \\<otimes> \\<Psi>', P \\<oplus> \\<tau>.(P), \\<tau>.(P)) \\<in> Rel\" by(rule C1)\n  ultimately show ?case by blast\nqed  \n\nlemma tauLaw2StatImpRight:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n\n  assumes C1: \"\\<And>\\<Psi>'. (\\<Psi> \\<otimes> \\<Psi>', \\<tau>.(P), P \\<oplus> \\<tau>.(P)) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> \\<tau>.(P) \\<lessapprox><Rel> P \\<oplus> \\<tau>.(P)\"\nproof(induct rule: weakStatImpI)\n  case(cStatImp \\<Psi>')\n  have \"\\<Psi> \\<rhd> P \\<oplus> \\<tau>.(P) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P \\<oplus> \\<tau>.(P)\" by auto\n  moreover have \"insertAssertion (extractFrame(\\<tau>.(P))) \\<Psi> \\<simeq>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi>\\<rangle>\" by(rule insertTauAssertion)\n  hence \"insertAssertion (extractFrame(\\<tau>.(P))) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame(P \\<oplus> \\<tau>.(P))) \\<Psi>\" using Identity\n    by(rule_tac FrameStatImpTrans) (auto simp add: FrameStatEq_def AssertionStatEq_def)\n  moreover have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<oplus> \\<tau>.(P) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P \\<oplus> \\<tau>.(P)\" by auto\n  moreover have \"(\\<Psi> \\<otimes> \\<Psi>', \\<tau>.(P), P \\<oplus> \\<tau>.(P)) \\<in> Rel\" by(rule C1)\n  ultimately show ?case by blast\nqed\n\nlemma tauLaw4StatImpLeft:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   M :: 'a\n  and   N :: 'a\n\n  assumes C1: \"\\<And>\\<Psi>'. (\\<Psi> \\<otimes> \\<Psi>', \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q), \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q)) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q) \\<lessapprox><Rel> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q)\"\nproof(induct rule: weakStatImpI)\n  case(cStatImp \\<Psi>')\n  have \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q)\" by auto\n  hence \"insertAssertion (extractFrame(\\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q))) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame(\\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q))) \\<Psi>\" \n    using insertTauAssertion Identity\n    by(nominal_induct \\<alpha> rule: prefix.strong_inducts, auto) \n  (rule FrameStatImpTrans[where G=\"\\<langle>\\<epsilon>, \\<Psi>\\<rangle>\"], auto simp add: FrameStatEq_def AssertionStatEq_def)\n  moreover have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q)\" by auto\n  moreover have \"(\\<Psi> \\<otimes> \\<Psi>', \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q), \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q)) \\<in> Rel\" by(rule C1)\n  ultimately show ?case by blast\nqed\n\nlemma tauLaw4StatImpRight:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha> :: \"'a prefix\"\n\n  assumes C1: \"\\<And>\\<Psi>'. (\\<Psi> \\<otimes> \\<Psi>', \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q), \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q)) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q) \\<lessapprox><Rel> \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q)\"\nproof(induct rule: weakStatImpI)\n  case(cStatImp \\<Psi>')\n  have \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q)\" by auto\n  hence \"insertAssertion (extractFrame(\\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q))) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame(\\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q))) \\<Psi>\"\n    using insertTauAssertion Identity\n    by(nominal_induct \\<alpha> rule: prefix.strong_inducts, auto) \n  (rule FrameStatImpTrans[where G=\"\\<langle>\\<epsilon>, \\<Psi>\\<rangle>\"], auto simp add: FrameStatEq_def AssertionStatEq_def)\n  moreover have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q)\" by auto\n  moreover have \"(\\<Psi> \\<otimes> \\<Psi>', \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q), \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q)) \\<in> Rel\" by(rule C1)\n  ultimately show ?case by blast\nqed\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Psi_Calculi/Tau_Stat_Imp.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185498374789, "lm_q2_score": 0.5, "lm_q1q2_score": 0.28300927491873945}}
{"text": "           (*-------------------------------------------*\n            |                DFP package                |\n            |                    May 2005               |\n            |               December 2005  (modified)   |\n            |                                           |\n            |   DFP on CSP-Prover ver.3.0               |\n            |              September 2006  (modified)   |\n            |                  April 2007  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2016         |\n            |                    May 2016  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2017         |\n            |                  April 2018  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory DFP_Block\nimports DFP_Deadlock\nbegin\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite UnionT and InterT.                 *)\n(*                  Union (B ` A) = (UN x:A. B x)                      *)\n(*                  Inter (B ` A) = (INT x:A. B x)                     *)\n(*\ndeclare Union_image_eq [simp del]\ndeclare Inter_image_eq [simp del]\n*)\n\n(* no simp rules in Isabelle 2017 \ndeclare Sup_image_eq [simp del]\ndeclare Inf_image_eq [simp del]\n*)\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite (notick | t = []t)                 *)\n(*                                                                     *)\n(*                  disj_not1: (~ P | Q) = (P --> Q)                   *)\n\ndeclare disj_not1 [simp del]\n\n(*****************************************************************\n\n         1. \n         2. \n         3. \n         4. \n\n *****************************************************************)\n\n(*********************************************************\n                    definitions\n *********************************************************)\n\ndefinition\n  triple_disjoint :: \"('i,'a) NetworkF => bool\"\n  where\n  triple_disjoint_def :\n    \"triple_disjoint VF == \n       (ALL i: fst VF. ALL j: fst VF. ALL k: fst VF. i ~= j & j ~= k & k ~= i\n          --> (snd ((snd VF) i) Int snd ((snd VF) j) Int snd ((snd VF) k) = {}))\"\n\ndefinition\n  VocabularyOf :: \"('i,'a) NetworkF => 'a set\"\n  where\n  VocabularyOf_def : \n    \"VocabularyOf VF == \n     Union {X. EX i: fst VF. EX j: fst VF. i ~= j &\n               X = snd((snd VF) i) Int snd((snd VF) j)}\"\n    (* internal communication *)\n\ndefinition  \n  BusyNetworkP :: \"('i,'p,'a) Network => bool\"\n  where\n  BusyNetworkP_def : \n    \"BusyNetworkP V == \n     ALL i: fst V. DeadlockFreeNetwork ({i}, snd V)\"\n  \ndefinition  \n  BusyNetwork  :: \"('i,'a) NetworkF => bool\"\n  where\n  BusyNetwork_def : \n    \"BusyNetwork VF == \n     ALL i: fst VF. (ALL sigma. ~(sigma isDeadlockStateOf ({i}, snd VF)))\"\n\ndefinition\n  isRequestOf :: \"('i,'a) NetworkF => 'i => ('i,'a) net_state => 'i => bool\"\n     (\"(1_ >> /(0_ (1/--[_]-->) /_))\" [800, 800,100,800] 900)\n  where\n  isRequestOf_def :\n    \"VF >> i --[sigma]--> j == \n        sigma isStateOf VF & \n        i ~= j & i : fst VF & j : fst VF &\n        (Ev ` (snd (snd VF i)) - (snd sigma) i) Int \n         Ev ` (snd (snd VF j)) ~= {}\"\n\ndefinition\n  isStrongRequestOf :: \"('i,'a) NetworkF => 'i => ('i,'a) net_state => 'i => bool\"\n     (\"(1_ >> /(0_ (1/==[_]==>) /_))\" [800, 800,100,800] 900)\n  where\n  isStrongRequestOf_def :\n    \"VF >> i ==[sigma]==> j == \n        sigma isStateOf VF & \n        i ~= j & i : fst VF & j : fst VF &\n        Ev ` (snd (snd VF i)) - (snd sigma) i ~= {} &\n        Ev ` (snd (snd VF i)) - (snd sigma) i <= Ev ` (snd (snd VF j))\"\n\ndefinition\n  isUngrantedRequestOf ::\n      \"('i,'a) NetworkF => 'i => ('i,'a) net_state => 'i => bool\"\n      (\"(1_ >> /(0_ (1/--[_]-->o) /_))\" [800, 800,0,800] 900)\n  where\n  isUngrantedRequestOf_def :\n    \"VF >> i --[sigma]-->o j == VF >> i --[sigma]--> j &\n        Ev ` (snd (snd VF i)) Int Ev ` (snd (snd VF j))\n        <= (snd sigma) i Un (snd sigma) j\"\n  \ndefinition\n  isUngrantedStrongRequestOf ::\n      \"('i,'a) NetworkF => 'i => ('i,'a) net_state => 'i => bool\"\n      (\"(1_ >> /(0_ (1/==[_]==>o) /_))\" [800, 800,0,800] 900)\n  where\n  isUngrantedStrongRequestOf_def :\n    \"VF >> i ==[sigma]==>o j == VF >> i ==[sigma]==> j &\n        Ev ` (snd (snd VF i)) Int Ev ` (snd (snd VF j))\n        <= (snd sigma) i Un (snd sigma) j\"\n\ndefinition\n  isUngrantedRequestOfwrt ::\n      \"('i,'a) NetworkF => 'i => ('i,'a) net_state => 'a set => 'i => bool\"\n      (\"(1_ >> /(0_ (1/--[(0_,/_)]-->o) /_))\" [800, 800,0,0,800] 900)\n  where\n  isUngrantedRequestOfwrt_def :\n    \"VF >> i --[sigma,Lambda]-->o j == VF >> i --[sigma]-->o j &\n        ((Ev ` (snd (snd VF i))) - (snd sigma) i) Un\n        ((Ev ` (snd (snd VF j))) - (snd sigma) j) <= Ev ` Lambda\"\n\n(*** Block ***)\n\ndefinition\n  isBlockedIn ::\n      \"('i,'a) NetworkF => 'i => ('i,'a) net_state => bool\"\n      (\"(_ >> _ isBlockedIn _)\" [800, 800, 800] 900)\n  where\n  isBlockedIn_def :\n    \"VF >> i isBlockedIn sigma == \n          triple_disjoint VF &\n          (EX j. VF >> i --[sigma]--> j) &\n          (ALL j. VF >> i --[sigma]--> j\n          --> (VF >> i --[sigma, (VocabularyOf VF)]-->o j))\"\n\n(*********************************************************\n                  BusyNetwork lemmas\n *********************************************************)\n\nlemma BusyNetwork_BusyNetworkP :\n    \"[| I ~= {} ; finite I ; (I,FXf) isFailureOf (I,PXf) |]\n     ==> BusyNetwork (I,FXf) = BusyNetworkP (I,PXf)\"\napply (simp add: BusyNetwork_def)\napply (simp add: BusyNetworkP_def)\napply (rule)\n\n apply (rule ballI)\n apply (drule_tac x=\"i\" in bspec, simp)\n apply (subgoal_tac \"({i}, FXf) isFailureOf ({i}, PXf)\")\n apply (simp add: DeadlockFree_notDeadlockState)\n apply (rule isFailureOf_subset_index)\n apply (simp)\n apply (simp)\n\n apply (rule ballI)\n apply (drule_tac x=\"i\" in bspec, simp)\n apply (subgoal_tac \"({i}, FXf) isFailureOf ({i}, PXf)\")\n apply (simp add: DeadlockFree_notDeadlockState)\n apply (rule isFailureOf_subset_index)\n apply (simp)\n apply (simp)\ndone\n\n(*-----------------------------------*\n |     How to check BusyNetworkF     |\n *-----------------------------------*)\n\nlemma check_BusyNetwork:\n   \"[| ALL i:I. ALL s Y. (s, Y) : fst (FXf i) --> Y ~= Ev ` (snd (FXf i)) |]\n    ==> BusyNetwork (I,FXf)\"\napply (simp add: BusyNetwork_def)\napply (intro allI ballI)\napply (rename_tac s Yf)\napply (drule_tac x=\"i\" in bspec, simp)\n\napply (simp add: isDeadlockStateOf_def)\napply (simp add: disj_not1)\napply (intro impI)\napply (simp add: isStateOf_def)\napply (drule_tac x=\"s rest-tr (snd (FXf i))\" in spec)\napply (drule_tac x=\"Yf i\" in spec)\napply (simp)\napply (simp add: ALP_def)\ndone\n\n(*********************************************************\n                     in index I\n *********************************************************)\n\nlemma in_index_I1:\n  \"(I, FXf) >> i --[sigma]--> j ==> i : I & j : I & i ~= j\"\nby (simp add: isRequestOf_def)\n\nlemma in_index_I2:\n  \"(I, FXf) >> i ==[sigma]==> j ==> i : I & j : I & i ~= j\"\nby (simp add: isStrongRequestOf_def)\n\nlemma in_index_I3:\n  \"(I, FXf) >> i --[sigma]-->o j ==> i : I & j : I & i ~= j\"\napply (simp add: isUngrantedRequestOf_def)\napply (elim conjE)\nby (simp add: in_index_I1)\n\nlemma in_index_I4:\n  \"(I, FXf) >> i ==[sigma]==>o j ==> i : I & j : I & i ~= j\"\napply (simp add: isUngrantedStrongRequestOf_def)\napply (elim conjE)\nby (simp add: in_index_I2)\n\nlemma in_index_I5:\n  \"(I, FXf) >> i --[sigma,Lambda]-->o j ==> i : I & j : I & i ~= j\"\napply (simp add: isUngrantedRequestOfwrt_def)\napply (elim conjE)\nby (simp add: in_index_I3)\n\nlemmas in_index_I = in_index_I1 in_index_I2 in_index_I3 in_index_I4 in_index_I5\n\n(*********************************************************\n                       note (P.7)\n *********************************************************)\n\nlemma isUngrantedRequestOfwrt_note1:\n  \"[| Lambda1 <= Lambda2 ; VF >> i --[sigma,Lambda1]-->o j |]\n   ==> VF >> i --[sigma,Lambda2]-->o j\"\napply (simp add: isUngrantedRequestOfwrt_def)\nby (blast)\n\nlemma isUngrantedRequestOfwrt_note2:\n  \"(snd (snd VF i)) Un (snd (snd VF j)) <= Lambda\n   ==> (VF >> i --[sigma,Lambda]-->o j) = (VF >> i --[sigma]-->o j)\"\nby (auto simp add: isUngrantedRequestOfwrt_def)\n\n(*********************************************************\n                     sub request\n *********************************************************)\n\nlemma isRequestOf_subsetI:\n  \"[| (I, FXf) >> i --[(t,Yf)]--> j; J <= I; i:J ; j:J ; \n      X = Union {snd (FXf i)|i. i:J} |]\n   ==> (J, FXf) >> i --[(t rest-tr X,Yf)]--> j\"\napply (simp add: isRequestOf_def)\napply (rule isStateOf_subsetI)\napply (simp_all)\ndone\n\nlemma isStrongRequestOf_subsetI:\n  \"[| (I, FXf) >> i ==[(t,Yf)]==> j; J <= I; i:J ; j:J ; \n      X = Union {snd (FXf i)|i. i:J} |]\n   ==> (J, FXf) >> i ==[(t rest-tr X,Yf)]==> j\"\napply (simp add: isStrongRequestOf_def)\napply (rule isStateOf_subsetI)\napply (simp_all)\ndone\n\nlemma isUngrantedRequestOf_subsetI:\n  \"[| (I, FXf) >> i --[(t,Yf)]-->o j; J <= I; i:J ; j:J ; \n      X = Union {snd (FXf i)|i. i:J} |]\n   ==> (J, FXf) >> i --[(t rest-tr X,Yf)]-->o j\"\napply (simp add: isUngrantedRequestOf_def)\napply (rule isRequestOf_subsetI)\napply (simp_all)\ndone\n\nlemma isUngrantedStrongRequestOf_subsetI:\n  \"[| (I, FXf) >> i ==[(t,Yf)]==>o j; J <= I; i:J ; j:J ; \n      X = Union {snd (FXf i)|i. i:J} |]\n   ==> (J, FXf) >> i ==[(t rest-tr X,Yf)]==>o j\"\napply (simp add: isUngrantedStrongRequestOf_def)\napply (rule isStrongRequestOf_subsetI)\napply (simp_all)\ndone\n\nlemma isUngrantedRequestOfwrt_subsetI:\n  \"[| (I, FXf) >> i --[(t,Yf), Lambda1]-->o j; J <= I; i:J ; j:J ; \n      Lambda1 <= Lambda2 ; X = Union {snd (FXf i)|i. i:J} |]\n   ==> (J, FXf) >> i --[(t rest-tr X,Yf), Lambda2]-->o j\"\napply (simp add: isUngrantedRequestOfwrt_def)\napply (rule conjI)\napply (rule isUngrantedRequestOf_subsetI)\napply (simp_all)\napply (blast)\ndone\n\n(*********************************************************\n                      blocked\n *********************************************************)\n\n(*---------------------------------*\n | lemma 1 [Roscoe_Dathi_1987 P.7] |\n *---------------------------------*)\n\n(*** only if ***)\n\nlemma Lemma1_Roscoe_Dathi_1987_only_if:\n  \"[| triple_disjoint (I,FXf) ; BusyNetwork (I,FXf) ; \n      (t,Yf) isDeadlockStateOf (I,FXf) |]\n   ==> ALL i:I. (I,FXf) >> i isBlockedIn (t,Yf)\"\napply (intro ballI)\napply (subgoal_tac \"ALL i:I. Yf i <= (Ev ` (snd (FXf i)))\")\n apply (simp only: isBlockedIn_def)\n  apply (rule conjI)\n  apply (simp)\n  apply (rule conjI)\n\n (* 1 *)\n\n (* busy --> i is deadlock-free *)\n  apply (simp add: isRequestOf_def)\n  apply (simp add: BusyNetwork_def)\n  apply (drule_tac x=\"i\" in bspec, simp)\n\n  (* i is deadlock-free --> EX j *)\n  apply (rule conjI)\n  apply (simp add: isDeadlockStateOf_def)\n\n  apply (simp add: isDeadlockStateOf_def)\n  apply (simp add: disj_not1)\n  apply (elim conjE)\n  apply (drule_tac x=\"t rest-tr (snd (FXf i))\" in spec)\n  apply (drule_tac x=\"Yf\" in spec)\n  apply (simp add: isStateOf_each_element)\n  apply (simp add: ALP_def)\n\n  apply (subgoal_tac \"EX a: Ev ` snd (FXf i). a ~: Yf i\")\n                                                  (* ... sub 1 *)\n   apply (elim bexE)\n   apply (subgoal_tac \"a : Ev ` {a. EX i:I. a : snd (FXf i)}\")\n                                                  (* ... sub 2 *)\n    apply (rotate_tac 4)\n    apply (drule sym)\n    apply (simp)\n    apply (elim conjE exE)\n    apply (simp)\n    apply (rule_tac x=\"ia\" in exI)\n    apply (case_tac \"i = ia\", simp)\n    apply (simp)\n    apply (drule_tac x=\"ia\" in bspec, simp)\n    apply (blast)\n   (* sub 2 *)\n   apply (blast)\n  (* sub 1 *)\n  apply (blast)\n\n(* 2 *) \n apply (intro allI impI)\n apply (unfold isUngrantedRequestOfwrt_def)\n apply (rule conjI)\n\n (* 2-1 *)\n  apply (simp add: isUngrantedRequestOf_def)\n  apply (rule)\n\n  apply (subgoal_tac \"x : Union {Yf i |i. i : I}\")\n   apply (simp)\n   apply (elim conjE bexE exE)\n   apply (case_tac \"ia = i\", simp)\n   apply (case_tac \"ia = j\", simp)\n   (* ia ~= i & ia ~= j ==> contradict with triple_dijoint *)\n   apply (drule_tac x=\"ia\" in bspec, simp)\n   apply (simp add: isDeadlockStateOf_def isStateOf_def)\n   apply (simp add: triple_disjoint_def)\n   apply (drule_tac x=\"i\" in bspec, simp)\n   apply (drule_tac x=\"j\" in bspec, simp add: isRequestOf_def)\n   apply (drule_tac x=\"ia\" in bspec, simp)\n    apply (drule mp)\n    apply (simp add: isRequestOf_def)\n   apply (rotate_tac -1)\n   apply (erule contrapos_pp)\n   apply (blast)\n\n  apply (simp add: isDeadlockStateOf_def)\n  apply (simp add: ALP_def)\n  apply (simp add: image_iff)\n  apply (elim conjE bexE, simp)\n  apply (rule_tac x=\"i\" in bexI)\n  apply (simp)\n  apply (simp)\n\n (* 2-2 *)\n  apply (rule)\n  apply (simp add: VocabularyOf_def)\n  apply (subgoal_tac \"x : Union {Yf i |i. i : I}\")\n\n   apply (simp)\n   apply (elim conjE bexE exE)\n   apply (simp add: image_iff)\n   apply (elim disjE conjE bexE)\n\n    apply (case_tac \"i = ia\", simp)\n    apply (drule_tac x=\"ia\" in bspec, simp)\n    apply (simp add: isDeadlockStateOf_def isStateOf_def)\n    apply (rule_tac x=\"snd (FXf i) Int snd (FXf ia)\" in exI)\n    apply (rule conjI)\n     apply (rule_tac x=\"i\" in bexI)\n     apply (rule_tac x=\"ia\" in bexI)\n     apply (simp)\n     apply (simp)\n     apply (simp)\n     apply (blast)\n\n    apply (case_tac \"j = ia\", simp)\n    apply (drule_tac x=\"ia\" in bspec, simp)\n    apply (simp add: isDeadlockStateOf_def isStateOf_def)\n    apply (rule_tac x=\"snd (FXf j) Int snd (FXf ia)\" in exI)\n    apply (rule conjI)\n     apply (rule_tac x=\"j\" in bexI)\n     apply (rule_tac x=\"ia\" in bexI)\n     apply (simp)\n     apply (simp)\n     apply (simp add: isRequestOf_def)\n     apply (blast)\n\n  apply (simp add: isDeadlockStateOf_def)\n  apply (simp add: ALP_def)\n  apply (simp add: image_iff)\n  apply (elim disjE conjE bexE)\n\n   apply (rule_tac x=\"xa\" in exI)\n   apply (simp)\n   apply (fast)\n\n   apply (rule_tac x=\"xa\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"j\" in bexI)\n   apply (simp)\n   apply (simp add: isRequestOf_def)\n\napply (simp add: isDeadlockStateOf_def)\napply (simp add: isStateOf_def)\ndone\n\n(*** if ***)\n\nlemma Lemma1_Roscoe_Dathi_1987_if:\n  \"[| triple_disjoint (I,FXf) ; BusyNetwork (I,FXf) ; \n      (t,Yf) isStateOf (I,FXf) ;\n      ALL i:I. (I,FXf) >> i isBlockedIn (t,Yf) |]\n   ==> (t,Yf) isDeadlockStateOf (I,FXf)\"\napply (simp add: isDeadlockStateOf_def)\napply (simp add: ALP_def)\napply (rule)\n\n (* <= *)\n apply (rule)\n apply (simp)\n apply (elim exE conjE)\n apply (simp)\n apply (drule_tac x=\"i\" in bspec, simp)\n apply (simp add: isStateOf_def)\n apply (elim conjE)\n apply (drule_tac x=\"i\" in bspec, simp)\n apply (simp add: ALP_def)\n apply (force)\n\n (* => *)\n apply (rule)\n apply (simp)\n apply (simp only: isBlockedIn_def)\n apply (simp add: image_iff)\n apply (elim conjE exE bexE)\n apply (simp)\n\n apply (case_tac \"Ev xa : Yf i\")\n  apply (rule_tac x=\"Yf i\" in exI)\n  apply (fast)\n\n (* Ev xa ~: Yf i *)\n  apply (subgoal_tac \"xa : VocabularyOf (I,FXf)\")\n   apply (simp add: VocabularyOf_def)\n   apply (elim conjE exE bexE)\n   apply (simp)\n\n   apply (case_tac \"ia = i\")\n    apply (simp)\n    apply (drule_tac x=\"i\" in bspec, simp)\n    apply (elim conjE exE)\n\n    apply (drule_tac x=\"j\" in spec)\n    apply (drule mp)\n    apply (simp add: isRequestOf_def)\n    apply (blast)\n\n    apply (simp add: isUngrantedRequestOfwrt_def)\n    apply (simp add: isUngrantedRequestOf_def)\n    apply (rule_tac x=\"Yf j\" in exI)\n    apply (fast)\n\n   apply (case_tac \"j = i\")\n    apply (simp)\n    apply (drule_tac x=\"i\" in bspec, simp)\n    apply (elim conjE exE)\n     apply (drule_tac x=\"ia\" in spec)\n     apply (drule mp)\n     apply (simp add: isRequestOf_def)\n     apply (blast)\n\n     apply (simp add: isUngrantedRequestOfwrt_def)\n     apply (simp add: isUngrantedRequestOf_def)\n     apply (rule_tac x=\"Yf ia\" in exI)\n     apply (fast)\n\n   (* ia ~= i; j ~= i; ia ~= j, but xa : snd (PXf i), ... *)\n   apply (simp add: triple_disjoint_def)\n   apply (drule_tac x=\"i\" in bspec, simp)\n   apply (rotate_tac -1)\n   apply (drule_tac x=\"ia\" in bspec, simp)\n   apply (rotate_tac -1)\n   apply (drule_tac x=\"j\" in bspec, simp)\n   apply (fast)\n\n  (* xa : VocabularyOf VF *)\n   apply (drule_tac x=\"i\" in bspec, simp)\n   apply (elim exE conjE)\n   apply (drule_tac x=\"xb\" in spec)\n   apply (simp add: isUngrantedRequestOfwrt_def)\n   apply (fast)\ndone\n\nlemma Lemma1_Roscoe_Dathi_1987:\n  \"[| triple_disjoint (I,FXf) ; BusyNetwork (I,FXf) ; \n      (t,Yf) isStateOf (I,FXf) |]\n   ==> (t,Yf) isDeadlockStateOf (I,FXf)\n       = (ALL i:I. (I,FXf) >> i isBlockedIn (t,Yf))\"\napply (rule)\napply (simp add: Lemma1_Roscoe_Dathi_1987_only_if)\napply (simp add: Lemma1_Roscoe_Dathi_1987_if)\ndone\n\n(****************** to add it again ******************)\n\ndeclare disj_not1   [simp]\n(*\ndeclare Union_image_eq [simp]\ndeclare Inter_image_eq [simp]\n*)\n(*\ndeclare Sup_image_eq [simp]\ndeclare Inf_image_eq [simp]\n*)\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/DFP/DFP_Block.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.282948671068109}}
{"text": "section \\<open> Modelica Core \\<close>\n\ntheory Modelica_Core\nimports \"UTP1-Hybrid.utp_hrd\"\nbegin\n  \nnamed_theorems mo_defs\n  \nalphabet 'l mst =\n  mtime   :: real\n  mintern :: \"'l\" \\<comment> \\<open> Internal continuous variables \\<close>\n  \nsetup_lifting type_definition_mst_ext\n\ntext \\<open> Syntax for internal variables \\<close>\n  \nnotation mintern (\"\\<^bold>i\")\n  \nsyntax\n  \"_svid_mintern\"  :: \"svid\" (\"\\<^bold>i\")\n  \ntranslations\n  \"_svid_mintern\" => \"CONST mintern\"\n  \ninstantiation mst_ext :: (t2_space,t2_space) t2_space\nbegin\n  lift_definition open_mst_ext :: \"('a, 'b) mst_scheme set \\<Rightarrow> bool\" is \"open\" .\n  instance by (intro_classes, (transfer, auto simp add: separation_t2)+)\nend\n  \ndefinition map_mst ::\n  \"('\\<sigma> \\<Rightarrow> '\\<tau>) \\<Rightarrow>\n   ('\\<sigma>, 'c) mst_scheme \\<Rightarrow> ('\\<tau>, 'c) mst_scheme\" where\n[lens_defs]: \"map_mst f = (\\<lambda>r. \\<lparr>mtime\\<^sub>v = mtime\\<^sub>v r, mintern\\<^sub>v = f (mintern\\<^sub>v r), \\<dots> = more r\\<rparr>)\"\n\ndefinition map_mst_lens ::\n  \"('\\<sigma> \\<Longrightarrow> '\\<tau>) \\<Rightarrow> \n   (('\\<sigma>, 'b) mst_scheme, 't::trace, 'c) rsp \\<Longrightarrow> (('\\<tau>, 'b) mst_scheme, 't, 'c) rsp\" (\"map'_mst\\<^sub>L\") where\n[lens_defs]:\n\"map_mst_lens l = map_st\\<^sub>L \\<lparr>\n  lens_get = map_mst (get\\<^bsub>l\\<^esub>),\n  lens_put = map_mst o (put\\<^bsub>l\\<^esub>) o mintern\\<^sub>v\\<rparr>\"\n\n\nlemma map_mst_vwb [simp]: \"vwb_lens X \\<Longrightarrow> vwb_lens (map_mst\\<^sub>L X)\"\n  by (unfold_locales, simp_all add: lens_defs des_vars.defs rp_vars.defs rsp_vars.defs)\n\nabbreviation \"abs_mst\\<^sub>L \\<equiv> (map_mst\\<^sub>L 0\\<^sub>L) \\<times>\\<^sub>L (map_mst\\<^sub>L 0\\<^sub>L)\"\n\ntype_synonym ('l, 'c) mrel = \"(('l, 'c) mst_ext, ('l, 'c) mst_ext) hyrel\"\ntype_synonym ('d, 'l, 'c) mpred = \"('d, ('l, 'c) mst_ext) hybs upred\"\ntype_synonym ('a, 'l, 'c) mexpr = \"('a, ('l, 'c) mst_ext) uexpr\"  \n  \ntranslations\n  (type) \"('l,'c) mrel\" <= (type) \"(('l, 'c) mst_scheme, ('l', 'c') mst_scheme) hyrel\"\n  (type) \"('d,'l,'c) mpred\" <= (type) \"('d, ('l, 'c) mst_scheme) hybs upred\"\n  (type) \"('a,'l,'c) mexpr\" <= (type) \"('a, ('l, 'c) mst_scheme) uexpr\"\n  \ntext \\<open> Preconditions are captured by negating the continuous divergences, that is the set of\n  trajectories that eventually violate the precondition. Every divergence can be extended\n  aribtrarily. The precondition effectively states that no trace must violate the precondition\n  at the limit. \\<close>\n  \ndefinition ModelicaPre (\"\\<lceil>_\\<rceil>\\<^sub>M\") where\n[upred_defs]: \"\\<lceil>P\\<rceil>\\<^sub>M = (\\<not>\\<^sub>r (\\<lceil>\\<not> P\\<rceil>\\<^sup>\\<rightarrow> ;; true\\<^sub>r))\"\n  \nlemma true_ModelicaPre [rpred]: \"\\<lceil>true\\<rceil>\\<^sub>M = true\\<^sub>r\"\n  by (rel_auto)\n\nlemma ModelicaPre_RC [closure]: \"\\<lceil>P\\<rceil>\\<^sub>M is RC\"\n  apply (rel_auto)\n  apply (meson less_iff minus_gr_zero_iff order_refl)\n  apply (metis (no_types, lifting) diff_add_cancel_left' minus_gr_zero_iff order.trans trace_class.add_diff_cancel_left trace_class.add_left_mono)\ndone\n\ndefinition ModelicaBlock (\"[_ | _]\\<^sub>M\") where\n\"[P | Q]\\<^sub>M = \\<^bold>R\\<^sub>s(\\<lceil>P\\<rceil>\\<^sub>M \\<turnstile> Q \\<diamondop> false)\"\n\nlemma preR_simple_block [rdes]: \"pre\\<^sub>R([P\\<^sub>1 | \\<lceil>Q\\<^sub>1\\<rceil>\\<^sub>h]\\<^sub>M) = \\<lceil>P\\<^sub>1\\<rceil>\\<^sub>M\"\n  by (simp add: ModelicaBlock_def preR_srdes closure)\n\nlemma periR_simple_block [rdes]: \"peri\\<^sub>R([P\\<^sub>1 | \\<lceil>Q\\<^sub>1\\<rceil>\\<^sub>h]\\<^sub>M) = (\\<lceil>P\\<^sub>1\\<rceil>\\<^sub>M \\<Rightarrow>\\<^sub>r \\<lceil>Q\\<^sub>1\\<rceil>\\<^sub>h)\"\n  by (simp add: ModelicaBlock_def rdes closure)\n  \nlemma postR_simple_block [rdes]: \"post\\<^sub>R([P | \\<lceil>Q\\<rceil>\\<^sub>h]\\<^sub>M) = (\\<not>\\<^sub>r \\<lceil>P\\<rceil>\\<^sub>M)\"\n  by (simp add: ModelicaBlock_def rdes closure)\n    \nlemma NSRD_simple_block [closure]: \"[P\\<^sub>1 | \\<lceil>Q\\<^sub>1\\<rceil>\\<^sub>h]\\<^sub>M is NSRD\"\n  apply (rule NSRD_intro)\n  apply (simp add: ModelicaBlock_def)\n  apply (rule RHS_tri_design_is_SRD)\n  apply (simp_all add: unrest rdes closure RC1_prop RC_implies_RC1)\ndone\n    \nend\n", "meta": {"author": "isabelle-utp", "repo": "utp-main", "sha": "27bdf3aee6d4fc00c8fe4d53283d0101857e0d41", "save_path": "github-repos/isabelle/isabelle-utp-utp-main", "path": "github-repos/isabelle/isabelle-utp-utp-main/utp-main-27bdf3aee6d4fc00c8fe4d53283d0101857e0d41/modelica/Modelica_Core.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526514141572, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.2827003840742062}}
{"text": "           (*-------------------------------------------------*\n            |                 (a part of) ep2                 |\n            |                  September 2004                 |\n            |                   December 2004 (modified)      |\n            |                   November 2005 (modified)      |\n            |                      April 2006 (modified)      |\n            |                      March 2007  (modified)     |\n            |                                                 |\n            |        CSP-Prover on Isabelle2009               |\n            |                       June 2009  (modified)     |\n            |                                                 |\n            |        CSP-Prover on Isabelle2016               |\n            |                        May 2016  (modified)     |\n            |                                                 |\n            |  Markus Roggenbach (Univ of Wales Swansea, UK)  |\n            |  Yoshinao Isobe    (AIST, Japan)                |\n            *-------------------------------------------------*)\n\ntheory ep2_nucleus\nimports CSP_F\nbegin\n\n(*** To automatically unfold syntactic sugar ***)\n\ndeclare csp_prefix_ss_def [simp]\ndeclare inj_on_def        [simp]\n\n(*********************************************************\n              data type passed on channels\n *********************************************************)\n\ntypedecl init_d typedecl request_d typedecl response_d typedecl exit_d\n\ndatatype Data = Init    init_d    | Exit     exit_d\n              | Request request_d | Response response_d\n\n(*********************************************************\n                     event (channel)\n *********************************************************)\n\ndatatype Event = c Data\n\n(*********************************************************\n         abstract component description level\n *********************************************************)\n\ndatatype ACName = Acquirer | AcConfigManagement \n                | Terminal | TerminalConfigManagement\n\nprimrec\n  ACfun :: \"ACName => (ACName, Event) proc\"\nwhere\n  \"ACfun Acquirer\n         = c ? x:(range Init) -> $AcConfigManagement\"\n\n |\"ACfun AcConfigManagement\n         = c !? exit:(range Exit) -> SKIP\n           |~| \n           c !? request:(range Request)\n             -> c ? response:(range Response)\n             -> $AcConfigManagement\"\n\n |\"ACfun Terminal\n         = c !? init:(range Init) -> $TerminalConfigManagement\"\n\n |\"ACfun TerminalConfigManagement\n         = c ? x -> IF (x:range Request) \n                    THEN (c !? response:(range Response)\n                          -> $TerminalConfigManagement)\n                    ELSE IF (x:range Exit)\n                         THEN SKIP\n                         ELSE STOP\"\n(*\ndefs (overloaded)\nSet_ACfun_def [simp]: \"PNfun == ACfun\"\n*)\n\noverloading Set_ACfun == \n  \"PNfun :: (ACName, Event) pnfun\"\nbegin\n  definition \"PNfun == ACfun\"\nend\n\ndeclare Set_ACfun_def [simp]\n\ndefinition\n  AC :: \"(ACName, Event) proc\"\n  where\n  AC_def: \"AC == ($Acquirer |[range c]| $Terminal)\"\n\n(*---------------------------------------------------------------*\n |                          NOTE                                 |\n |                                                               |\n | c ! v -> P       : sends a value v to c, then behaves like P. |\n |                                                               |\n | c ? x:X -> P(x)  : receives a value v from c if c in X,       |\n |                    then behaves like P(v).                    |\n |                                                               |\n | c !? x:X -> P(x) : sends a value v selected from X to c,      |\n |                    then behaves like P(v).                    |\n |                                                               |\n *---------------------------------------------------------------*)\n\n(*********************************************************\n              equivalent sequential behavior\n *********************************************************)\n\ndatatype SeqName = SeqInit | Loop\n\nprimrec\n  Seqfun :: \"SeqName => (SeqName, Event) proc\"\nwhere\n  \"Seqfun SeqInit\n          = c !? init:(range Init) -> $Loop\"\n\n |\"Seqfun Loop\n          = c !? exit:(range Exit) -> SKIP\n            |~| \n            c !? request:(range Request)\n              -> c !? response:(range Response)\n              -> $Loop\"\n(*\ndefs (overloaded)\nSet_Seqfun_def [simp]: \"PNfun == Seqfun\"\n*)\n\noverloading Set_Seqfun == \n  \"PNfun :: (SeqName, Event) pnfun\"\nbegin\n  definition \"PNfun == Seqfun\"\nend\n  \ndeclare Set_Seqfun_def [simp]\n\ndefinition\n  Seq :: \"(SeqName, Event) proc\"\n  where\n  Seq_def: \"Seq == $SeqInit\"\n\n(*********************************************************\n        relating function between ACName and SeqName\n *********************************************************)\n\nprimrec\n  Seq_to_AC :: \"SeqName => (ACName, Event) proc\"\nwhere\n  \"Seq_to_AC (SeqInit)\n          = ($Acquirer |[range c]| $Terminal)\"\n\n |\"Seq_to_AC (Loop)\n          = ($AcConfigManagement |[range c]| $TerminalConfigManagement)\"\n\n(*********************************************************\n               gProc lemmas (routine work)\n *********************************************************)\n\nlemma guardedfun_AC_Seq[simp]:\n      \"guardedfun ACfun\"\n      \"guardedfun Seqfun\"\nby (simp add: guardedfun_def, rule allI, induct_tac p, simp_all)+\n\n(*********************************************************\n           a theorem for verifying Seq <=F AC\n *********************************************************)\n(*\ndefs FPmode_def [simp]: \"FPmode == CMSmode\"\n*)\n\noverloading FPmode == \n  \"FPmode :: fpmode\"\nbegin\n  definition \"FPmode == CMSmode\"\nend\n\ndeclare FPmode_def [simp]\n\n\ntheorem ep2: \"Seq =F AC\"\napply (unfold Seq_def AC_def)\napply (rule cspF_fp_induct_left[of _ \"Seq_to_AC\"])\napply (simp_all)\napply (simp)\napply (induct_tac p)\napply (simp_all)\n\n(* 1st subgoal *)\napply (cspF_unwind)\napply (cspF_hsf)+\napply (rule cspF_decompo, auto)\napply (cspF_hsf)+\napply (rule cspF_decompo, auto)\napply (cspF_hsf)+\n\n(* 2nd subgoal *)\napply (cspF_auto | rule cspF_decompo | rule cspF_decompo_ref | \n       auto simp add: image_iff)+\ndone\n\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/ep2/ep2_nucleus.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6513548511303338, "lm_q2_score": 0.4339814648038986, "lm_q1q2_score": 0.2826759324006676}}
{"text": "(*  Title:      JinjaDCI/BV/TF_JVM.thy\n\n    Author:     Tobias Nipkow, Gerwin Klein, Susannah Mansky\n    Copyright   2000 TUM, 2019-20 UIUC\n\n    Based on the Jinja theory BV/TF_JVM.thy by Tobias Nipkow and Gerwin Klein\n*)\n\nsection \\<open> The Typing Framework for the JVM \\label{sec:JVM} \\<close>\n\ntheory TF_JVM\nimports Jinja.Typing_Framework_err EffectMono BVSpec\nbegin\n\ndefinition exec :: \"jvm_prog \\<Rightarrow> nat \\<Rightarrow> ty \\<Rightarrow> ex_table \\<Rightarrow> instr list \\<Rightarrow> ty\\<^sub>i' err step_type\"\nwhere \n  \"exec G maxs rT et bs \\<equiv>\n  err_step (size bs) (\\<lambda>pc. app (bs!pc) G maxs rT pc (size bs) et) \n                     (\\<lambda>pc. eff (bs!pc) G pc et)\"\n\nlocale JVM_sl =\n  fixes P :: jvm_prog and mxs and mxl\\<^sub>0 and n\n  fixes b and Ts :: \"ty list\" and \"is\" and xt and T\\<^sub>r\n\n  fixes mxl and A and r and f and app and eff and step\n  defines [simp]: \"mxl \\<equiv> (case b of Static \\<Rightarrow> 0 | NonStatic \\<Rightarrow> 1)+size Ts+mxl\\<^sub>0\"\n  defines [simp]: \"A   \\<equiv> states P mxs mxl\"\n  defines [simp]: \"r   \\<equiv> JVM_SemiType.le P mxs mxl\"\n  defines [simp]: \"f   \\<equiv> JVM_SemiType.sup P mxs mxl\"\n\n  defines [simp]: \"app \\<equiv> \\<lambda>pc. Effect.app (is!pc) P mxs T\\<^sub>r pc (size is) xt\"\n  defines [simp]: \"eff \\<equiv> \\<lambda>pc. Effect.eff (is!pc) P pc xt\"\n  defines [simp]: \"step \\<equiv> err_step (size is) app eff\"\n\n  defines [simp]: \"n \\<equiv> size is\"\n  assumes staticb: \"b = Static \\<or> b = NonStatic\" \n\nlocale start_context = JVM_sl +\n  fixes p and C\n\n  assumes wf: \"wf_prog p P\"\n  assumes C:  \"is_class P C\"\n  assumes Ts: \"set Ts \\<subseteq> types P\"\n\n \n  fixes first :: ty\\<^sub>i' and start\n  defines [simp]: \n  \"first \\<equiv> Some ([],(case b of Static \\<Rightarrow> [] | NonStatic \\<Rightarrow> [OK (Class C)]) @ map OK Ts @ replicate mxl\\<^sub>0 Err)\"\n  defines [simp]:\n  \"start \\<equiv> (OK first) #  replicate (size is - 1) (OK None)\"\nthm start_context.intro\n\nlemma start_context_intro_auxi: \n  fixes  P b Ts p C\n  assumes \"b = Static \\<or> b = NonStatic \" \n      and \"wf_prog p P\"\n      and \"is_class P C\"\n      and \"set Ts \\<subseteq> types P\"\n    shows \" start_context P b Ts p C\"\n  using start_context.intro[OF JVM_sl.intro] start_context_axioms_def assms  by auto\n\nsubsection \\<open> Connecting JVM and Framework \\<close>\n\nlemma (in start_context) semi: \"semilat (A, r, f)\"\n  apply (insert semilat_JVM[OF wf])\n  apply (unfold A_def r_def f_def JVM_SemiType.le_def JVM_SemiType.sup_def states_def)\n  apply auto\n  done\n\n\nlemma (in JVM_sl) step_def_exec: \"step \\<equiv> exec P mxs T\\<^sub>r xt is\" \n  by (simp add: exec_def)  \n\nlemma special_ex_swap_\n\nlemma ex_in_list [iff]:\n  \"(\\<exists>n. ST \\<in> nlists n A \\<and> n \\<le> mxs) = (set ST \\<subseteq> A \\<and> size ST \\<le> mxs)\"\n  by (unfold nlists_def) auto\n\nlemma singleton_nlists: \n  \"(\\<exists>n. [Class C] \\<in> nlists n (types P) \\<and> n \\<le> mxs) = (is_class P C \\<and> 0 < mxs)\"\n  by auto\n\nlemma set_drop_subset:\n  \"set xs \\<subseteq> A \\<Longrightarrow> set (drop n xs) \\<subseteq> A\"\n  by (auto dest: in_set_dropD)\n\nlemma Suc_minus_minus_le:\n  \"n < mxs \\<Longrightarrow> Suc (n - (n - b)) \\<le> mxs\"\n  by arith\n\nlemma in_nlistsE:\n  \"\\<lbrakk> xs \\<in> nlists n A; \\<lbrakk>size xs = n; set xs \\<subseteq> A\\<rbrakk> \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P\"\n  by (unfold nlists_def) blast\n\ndeclare is_relevant_entry_def [simp]\ndeclare set_drop_subset [simp]\n\ntheorem (in start_context) exec_pres_type:\n  \"pres_type step (size is) A\"\n(*<*)\nproof -\n  let ?n = \"size is\" and ?app = app and ?step = eff\n  let ?mxl = \"(case b of Static \\<Rightarrow> 0 | NonStatic \\<Rightarrow> 1) + length Ts + mxl\\<^sub>0\"\n  let ?A = \"opt((Union {nlists n (types P) |n. n <= mxs}) \\<times>\n                                 nlists ?mxl (err(types P)))\"\n  have \"pres_type (err_step ?n ?app ?step) ?n (err ?A)\"\n  proof(rule pres_type_lift)\n    have \"\\<And>s pc pc' s'. s\\<in>?A \\<Longrightarrow> pc < ?n \\<Longrightarrow> ?app pc s\n             \\<Longrightarrow> (pc', s')\\<in>set (?step pc s) \\<Longrightarrow> s' \\<in> ?A\"\n    proof -\n      fix s pc pc' s'\n      assume asms: \"s\\<in>?A\" \"pc < ?n\" \"?app pc s\" \"(pc', s')\\<in>set (?step pc s)\"\n      show \"s' \\<in> ?A\"\n      proof(cases s)\n        case None\n        then show ?thesis using asms by (fastforce dest: effNone)\n      next\n        case (Some ab)\n        then show ?thesis using asms proof(cases \"is!pc\")\n          case Load\n          then show ?thesis using asms\n            by (fastforce simp: Effect.app_def xcpt_app_def Effect.eff_def  \n                                xcpt_eff_def norm_eff_def\n                          dest: nlistsE_nth_in)\n        next\n          case Push\n          then show ?thesis using asms Some\n            by (fastforce simp: Effect.app_def xcpt_app_def Effect.eff_def\n                                xcpt_eff_def norm_eff_def typeof_lit_is_type)\n        next\n          case Getfield\n          then show ?thesis using asms wf\n            by (fastforce simp: Effect.app_def xcpt_app_def Effect.eff_def\n                                xcpt_eff_def norm_eff_def\n                          dest: sees_field_is_type)\n        next\n          case Getstatic\n          then show ?thesis using asms wf\n            by (fastforce simp: Effect.app_def xcpt_app_def Effect.eff_def\n                                xcpt_eff_def norm_eff_def\n                          dest: sees_field_is_type)\n        next\n          case (Invoke M n)\n          obtain a b where [simp]: \"s = \\<lfloor>(a,b)\\<rfloor>\" using Some asms(1) by blast\n          show ?thesis\n          proof(cases \"a!n = NT\")\n            case True\n            then show ?thesis using Invoke asms wf\n              by (fastforce simp: Effect.app_def xcpt_app_def Effect.eff_def  \n                                  xcpt_eff_def norm_eff_def)\n          next\n            case False\n            have \"(pc', s') \\<in> set (norm_eff (Invoke M n) P pc (a, b)) \\<or>\n              (pc', s') \\<in> set (xcpt_eff (Invoke M n) P pc (a, b) xt)\"\n              using Invoke asms(4) by (simp add: Effect.eff_def)\n            then show ?thesis proof(rule disjE)\n              assume \"(pc', s') \\<in> set (xcpt_eff (Invoke M n) P pc (a, b) xt)\"\n              then show ?thesis using Invoke asms(1-3)\n                by (fastforce simp: Effect.app_def xcpt_app_def xcpt_eff_def)\n            next\n              assume norm: \"(pc', s') \\<in> set (norm_eff (Invoke M n) P pc (a, b))\"\n              also have \"Suc (length a - Suc n) \\<le> mxs\" using Invoke asms(1,3)\n                by (simp add: Effect.app_def xcpt_app_def) arith\n              ultimately show ?thesis using False Invoke asms(1-3) wf\n                by (auto simp: Effect.app_def xcpt_app_def norm_eff_def wf_mdecl_def\n                         dest!: sees_wf_mdecl)\n            qed\n          qed\n        next\n          case (Invokestatic C M n)\n          obtain a b where [simp]: \"s = \\<lfloor>(a,b)\\<rfloor>\" using Some asms(1) by blast\n          have \"(pc', s') \\<in> set (norm_eff (Invokestatic C M n) P pc (a, b)) \\<or>\n            (pc', s') \\<in> set (xcpt_eff (Invokestatic C M n) P pc (a, b) xt)\"\n            using Invokestatic asms(4) by (simp add: Effect.eff_def)\n          then show ?thesis proof(rule disjE)\n            assume \"(pc', s') \\<in> set (xcpt_eff (Invokestatic C M n) P pc (a, b) xt)\"\n            then show ?thesis using Invokestatic asms(1-3)\n              by (fastforce simp: Effect.app_def xcpt_app_def xcpt_eff_def)\n          next\n            assume norm: \"(pc', s') \\<in> set (norm_eff (Invokestatic C M n) P pc (a, b))\"\n            also have \"Suc (length a - Suc n) \\<le> mxs\" using Invokestatic asms(1,3)\n              by (simp add: Effect.app_def xcpt_app_def) arith\n            ultimately show ?thesis using Invokestatic asms(1-3) wf\n              by (auto simp: Effect.app_def xcpt_app_def norm_eff_def wf_mdecl_def\n                       dest!: sees_wf_mdecl)\n          qed\n        qed (fastforce simp: Effect.app_def xcpt_app_def Effect.eff_def  \n                             xcpt_eff_def norm_eff_def)+\n      qed\n    qed\n    then show \"\\<forall>s\\<in>?A. \\<forall>p. p < ?n \\<longrightarrow> ?app p s \\<longrightarrow> (\\<forall>(q, s')\\<in>set (?step p s). s' \\<in> ?A)\"\n      by clarsimp\n  qed\n  then show ?thesis by (simp add: JVM_states_unfold)\nqed\n(*>*)\n\ndeclare is_relevant_entry_def [simp del]\ndeclare set_drop_subset [simp del]\n\nlemma lesubstep_type_simple:\n  \"xs [\\<sqsubseteq>\\<^bsub>Product.le (=) r\\<^esub>] ys \\<Longrightarrow> set xs {\\<sqsubseteq>\\<^bsub>r\\<^esub>} set ys\"\n(*<*)\nproof -\n  assume assm: \"xs [\\<sqsubseteq>\\<^bsub>Product.le (=) r\\<^esub>] ys\"\n  have \"\\<And>a b i y. (a, b) = xs ! i \\<Longrightarrow> i < length xs\n     \\<Longrightarrow> \\<exists>\\<tau>'. (\\<exists>i. (a, \\<tau>') = ys ! i \\<and> i < length xs) \\<and> b \\<sqsubseteq>\\<^bsub>r\\<^esub> \\<tau>'\"\n  proof -\n    fix a b i assume ith: \"(a, b) = xs ! i\" and len: \"i < length xs\"\n    obtain \\<tau> where \"ys ! i = (a, \\<tau>) \\<and> r b \\<tau>\"\n      using le_listD[OF assm len] ith\n      by (clarsimp simp: lesub_def Product.le_def)\n    then have \"(a, \\<tau>) = ys ! i \\<and> b \\<sqsubseteq>\\<^bsub>r\\<^esub> \\<tau>\"\n      by (clarsimp simp: lesub_def)\n    with len show \"\\<exists>\\<tau>'. (\\<exists>i. (a, \\<tau>') = ys ! i \\<and> i < length xs) \\<and> b \\<sqsubseteq>\\<^bsub>r\\<^esub> \\<tau>'\"\n      by fastforce\n  qed\n  then show \"set xs {\\<sqsubseteq>\\<^bsub>r\\<^esub>} set ys\" using assm\n    by (clarsimp simp: lesubstep_type_def set_conv_nth)\nqed\n(*>*)\n\ndeclare is_relevant_entry_def [simp del]\n\n\nlemma conjI2: \"\\<lbrakk> A; A \\<Longrightarrow> B \\<rbrakk> \\<Longrightarrow> A \\<and> B\" by blast\n  \nlemma (in JVM_sl) eff_mono:\nassumes wf: \"wf_prog p P\" and \"pc < length is\" and\n  lesub: \"s \\<sqsubseteq>\\<^bsub>sup_state_opt P\\<^esub> t\" and app: \"app pc t\"\nshows \"set (eff pc s) {\\<sqsubseteq>\\<^bsub>sup_state_opt P\\<^esub>} set (eff pc t)\"\n(*<*)\nproof(cases t)\n  case None then show ?thesis using lesub\n   by (simp add: Effect.eff_def lesub_def)\nnext\n  case tSome: (Some a)\n  show ?thesis proof(cases s)\n    case None then show ?thesis using lesub\n     by (simp add: Effect.eff_def lesub_def)\n  next\n    case (Some b)\n    let ?norm = \"\\<lambda>x. norm_eff (is ! pc) P pc x\"\n    let ?xcpt = \"\\<lambda>x. xcpt_eff (is ! pc) P pc x xt\"\n    let ?r = \"Product.le (=) (sup_state_opt P)\"\n    let ?\\<tau>' = \"\\<lfloor>eff\\<^sub>i (is ! pc, P, a)\\<rfloor>\"\n    {\n      fix x assume xb: \"x \\<in> set (succs (is ! pc) b pc)\"\n      then have appi: \"app\\<^sub>i (is ! pc, P, pc, mxs, T\\<^sub>r, a)\" and\n                bia: \"P \\<turnstile> b \\<le>\\<^sub>i a\" and appa: \"app pc \\<lfloor>a\\<rfloor>\"\n        using lesub app tSome Some by (auto simp add: lesub_def Effect.app_def)\n      have xa: \"x \\<in> set (succs (is ! pc) a pc)\"\n        using xb succs_mono[OF wf appi bia] by auto\n      then have \"(x, ?\\<tau>') \\<in> (\\<lambda>pc'. (pc', ?\\<tau>')) ` set (succs (is ! pc) a pc)\"\n        by (rule imageI)\n      moreover have \"P \\<turnstile> \\<lfloor>eff\\<^sub>i (is ! pc, P, b)\\<rfloor> \\<le>' ?\\<tau>'\"\n        using xb xa eff\\<^sub>i_mono[OF wf bia] appa by fastforce\n      ultimately have \"\\<exists>\\<tau>'. (x, \\<tau>') \\<in> (\\<lambda>pc'. (pc', \\<lfloor>eff\\<^sub>i (is ! pc, P, a)\\<rfloor>)) ` set (succs (is ! pc) a pc) \\<and>\n              P \\<turnstile> \\<lfloor>eff\\<^sub>i (is ! pc, P, b)\\<rfloor> \\<le>' \\<tau>'\" by blast\n    }\n    then have norm: \"set (?norm b) {\\<sqsubseteq>\\<^bsub>sup_state_opt P\\<^esub>} set (?norm a)\"\n      using tSome Some by (clarsimp simp: norm_eff_def lesubstep_type_def lesub_def)\n    obtain a1 b1 a2 b2 where a: \"a = (a1, b1)\" and b: \"b = (a2, b2)\"\n      using tSome Some by fastforce\n    then have a12: \"size a2 = size a1\" using lesub tSome Some\n      by (clarsimp simp: lesub_def list_all2_lengthD)\n    have \"length (?xcpt b) = length (?xcpt a)\"\n      by (simp add: xcpt_eff_def split_beta)\n    moreover have \"\\<And>n. n < length (?xcpt b) \\<Longrightarrow> (?xcpt b) ! n \\<sqsubseteq>\\<^bsub>?r\\<^esub> (?xcpt a) ! n\"\n      using lesub tSome Some a b a12\n      by (simp add: xcpt_eff_def split_beta fun_of_def) (simp add: lesub_def)\n    ultimately have \"?xcpt b [\\<sqsubseteq>\\<^bsub>?r\\<^esub>] ?xcpt a\"\n      by(rule le_listI)\n    then have \"set (?xcpt b) {\\<sqsubseteq>\\<^bsub>sup_state_opt P\\<^esub>} set (?xcpt a)\"\n      by (rule lesubstep_type_simple)\n    moreover note norm\n    ultimately have\n     \"set (?norm b) \\<union> set (?xcpt b) {\\<sqsubseteq>\\<^bsub>sup_state_opt P\\<^esub>} set (?norm a) \\<union> set (?xcpt a)\"\n      by(intro lesubstep_union)\n    then show ?thesis using tSome Some by(simp add: Effect.eff_def)\n  qed\nqed\n(*>*)\n\nlemma (in JVM_sl) bounded_step: \"bounded step (size is)\"\n(*<*)\n  by (auto simp: bounded_def err_step_def Effect.app_def Effect.eff_def\n                 error_def map_snd_def\n          split: err.splits option.splits)\n(*>*)\n\ntheorem (in JVM_sl) step_mono:\n  \"wf_prog wf_mb P \\<Longrightarrow> mono r step (size is) A\"\n(*<*)\n apply (simp add: JVM_le_Err_conv)  \n  apply (insert bounded_step)\n  apply (unfold JVM_states_unfold)\n  apply (rule mono_lift)    \n  apply (subgoal_tac \"b = Static \\<or> b = NonStatic\") \n      apply (fastforce split:if_splits)\\<comment>\\<open> order_sup_state_opt' order_sup_state_opt'' \\<close>\n     apply (simp only:staticb)\n     apply (unfold app_mono_def lesub_def)\n    apply clarsimp\n    apply (erule (2) app_mono)\n   apply simp\n  apply clarify\n  apply (drule eff_mono)\n      apply (auto simp add: lesub_def)\n  done\n(*\nproof -\n  assume wf: \"wf_prog wf_mb P\"\n  let ?r = \"sup_state_opt P\" and ?n = \"length is\" and ?app = app and ?step = eff\n  let ?A = \"opt (\\<Union> {list n (types P) |n. n \\<le> mxs} \\<times>\n                list ((case b of Static \\<Rightarrow> 0 | NonStatic \\<Rightarrow> 1) + length Ts + mxl\\<^sub>0)\n                 (err (types P)))\"\n  have \"order ?r ?A\" using wf by simp\n  moreover have \"app_mono ?r ?app ?n ?A\" using app_mono[OF wf]\n    by (clarsimp simp: app_mono_def lesub_def)\n  moreover have \"bounded (err_step ?n ?app ?step) ?n\" using bounded_step\n    by simp\n  moreover have \"\\<forall>s p t. s \\<in> ?A \\<and> p < ?n \\<and> s \\<sqsubseteq>\\<^bsub>?r\\<^esub> t \\<longrightarrow>\n   ?app p t \\<longrightarrow> set (?step p s) {\\<sqsubseteq>\\<^bsub>?r\\<^esub>} set (?step p t)\"\n     using eff_mono[OF wf] by simp\n  ultimately have \"mono (Err.le ?r) (err_step ?n ?app ?step) ?n (err ?A)\"\n    by(rule mono_lift)\n  then show \"mono r step (size is) A\" using bounded_step\n    by (simp add: JVM_le_Err_conv JVM_states_unfold)\nqed\n*)\n(*>*)\n\n\nlemma (in start_context) first_in_A [iff]: \"OK first \\<in> A\"\n  using Ts C by (cases b; force intro!: nlists_appendI simp add: JVM_states_unfold)\n\n\nlemma (in JVM_sl) wt_method_def2:\n  \"wt_method P C' b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt \\<tau>s =\n  (is \\<noteq> [] \\<and> \n   (b = Static \\<or> b = NonStatic) \\<and>\n   size \\<tau>s = size is \\<and>\n   OK ` set \\<tau>s \\<subseteq> states P mxs mxl \\<and>\n   wt_start P C' b Ts mxl\\<^sub>0 \\<tau>s \\<and> \n   wt_app_eff (sup_state_opt P) app eff \\<tau>s)\"\n(*<*)using staticb\n  by (unfold wt_method_def wt_app_eff_def wt_instr_def lesub_def\n             check_types_def) auto\n(*>*)\n\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/JinjaDCI/BV/TF_JVM.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631698328917, "lm_q2_score": 0.4649015713733885, "lm_q1q2_score": 0.2825035625210456}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |               December 2004               |\n            |                   June 2005  (modified)   |\n            |              September 2005  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |               November 2005  (modified)   |\n            |                  March 2007  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory CSP_F_law_ref\nimports CSP_F_law_basic CSP_T_law_ref\nbegin\n\n(*****************************************************************\n\n         1. rules for refinement\n\n *****************************************************************)\n\n(*-------------------------------------------------------*\n |            refinement and equality                    |\n *-------------------------------------------------------*)\n\nlemma cspF_ref_eq_iff: \"(P <=F[M,M] Q) = (P =F[M,M] Q |~| P)\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_ref_eq_iff)\napply (rule)\n\n(* <= *)\n apply (simp)\n apply (rule order_antisym)\n apply (simp add: subsetF_iff)\n apply (simp add: in_failures)\n apply (simp add: subsetF_iff)\n apply (simp add: in_failures)\n\n(* => *)\n apply (simp)\n apply (erule conjE)\n apply (erule order_antisymE)\n apply (rule)\n apply (rotate_tac 2)\n apply (erule subsetFE_ALL)\n apply (drule_tac x=\"s\" in spec)\n apply (drule_tac x=\"X\" in spec)\n apply (simp add: in_failures)\ndone\n\n(*-------------------------------------------------------*\n |              decompose Internal choice                |\n *-------------------------------------------------------*)\n\n(*** or <= ***)                                         (* unsafe *)\n\nlemma cspF_Int_choice_left1:\n  \"P1 <=F[M1,M2] Q ==> P1 |~| P2 <=F[M1,M2] Q\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Int_choice_left1)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Int_choice_left2:\n  \"P2 <=F[M1,M2] Q ==> P1 |~| P2 <=F[M1,M2] Q\"\napply (rule cspF_rw_left)\napply (rule cspF_commut)\nby (simp add: cspF_Int_choice_left1)\n\n(*** <= and ***)                                          (* safe *)\n\nlemma cspF_Int_choice_right:\n  \"[| P <=F[M1,M2] Q1 ; P <=F[M1,M2] Q2 |]\n      ==> P <=F[M1,M2] Q1 |~| Q2\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Int_choice_right)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\n(*-------------------------------------------------------*\n |        decompose Replicated internal choice           |\n *-------------------------------------------------------*)\n\n(*** EX <= ***)                                           (* unsafe *)\n\nlemma cspF_Rep_int_choice_nat_left:\n  \"(EX n. n:N & Pf n <=F[M1,M2] Q)\n      ==> !nat :N .. Pf <=F[M1,M2] Q\"\napply (simp add: cspF_cspT_semantics)\napply (rule conjI)\n\napply (rule cspT_Rep_int_choice_left)\napply (fast)\n\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_nat_left_x:\n  \"[| n:N ; Pf n <=F[M1,M2] Q |]\n  ==> !nat :N .. Pf <=F[M1,M2] Q\"\napply (rule cspF_Rep_int_choice_nat_left)\nby (fast)\n\nlemma cspF_Rep_int_choice_set_left:\n  \"(EX X. X:Xs & Pf X <=F[M1,M2] Q)\n      ==> !set :Xs .. Pf <=F[M1,M2] Q\"\napply (simp add: cspF_cspT_semantics)\napply (rule conjI)\n\napply (rule cspT_Rep_int_choice_left)\napply (fast)\n\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_set_left_x:\n  \"[| X:Xs ; Pf X <=F[M1,M2] Q |]\n  ==> !set :Xs .. Pf <=F[M1,M2] Q\"\napply (rule cspF_Rep_int_choice_set_left)\nby (fast)\n\nlemma cspF_Rep_int_choice_com_left:\n  \"(EX a. a:X & Pf a <=F[M1,M2] Q)\n      ==> ! :X .. Pf <=F[M1,M2] Q\"\napply (simp add: Rep_int_choice_com_def)\napply (rule cspF_Rep_int_choice_set_left)\napply (erule exE)\napply (rule_tac x=\"{a}\" in exI)\napply (auto)\ndone\n\nlemma cspF_Rep_int_choice_com_left_x:\n  \"[| a:X ; Pf a <=F[M1,M2] Q |]\n  ==> ! :X .. Pf <=F[M1,M2] Q\"\napply (rule cspF_Rep_int_choice_com_left)\nby (fast)\n\nlemma cspF_Rep_int_choice_f_left:\n  \"[| inj f ; (EX a. a:X & Pf a <=F[M1,M2] Q) |]\n      ==> !<f> :X .. Pf <=F[M1,M2] Q\"\napply (simp add: Rep_int_choice_f_def)\napply (rule cspF_Rep_int_choice_com_left)\napply (erule exE)\napply (rule_tac x=\"f a\" in exI)\napply (auto)\ndone\n\nlemma cspF_Rep_int_choice_f_left_x:\n  \"[| inj f ; a:X ; Pf a <=F[M1,M2] Q |]\n  ==> !<f> :X .. Pf <=F[M1,M2] Q\"\napply (rule cspF_Rep_int_choice_f_left)\napply (simp)\nby (fast)\n\nlemmas cspF_Rep_int_choice_left = cspF_Rep_int_choice_nat_left\n                                  cspF_Rep_int_choice_set_left\n                                  cspF_Rep_int_choice_com_left\n                                  cspF_Rep_int_choice_f_left\n\nlemmas cspF_Rep_int_choice_left_x = cspF_Rep_int_choice_nat_left_x\n                                  cspF_Rep_int_choice_set_left_x\n                                  cspF_Rep_int_choice_com_left_x\n                                  cspF_Rep_int_choice_f_left_x\n\n(*** <= ALL ***)                                         (* safe *)\n\nlemma cspF_Rep_int_choice_nat_right:\n  \"[| !!n. n:N ==> P <=F[M1,M2] Qf n |]\n               ==> P <=F[M1,M2] !nat :N .. Qf\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Rep_int_choice_right)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_set_right:\n  \"[| !!X. X:Xs ==> P <=F[M1,M2] Qf X |]\n               ==> P <=F[M1,M2] !set :Xs .. Qf\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Rep_int_choice_right)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_com_right:\n  \"[| !!a. a:X ==> P <=F[M1,M2] Qf a |]\n               ==> P <=F[M1,M2] ! :X .. Qf\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Rep_int_choice_right)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_f_right:\n  \"[| inj f ; !!a. a:X ==> P <=F[M1,M2] Qf a |]\n               ==> P <=F[M1,M2] !<f> :X .. Qf\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Rep_int_choice_right)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemmas cspF_Rep_int_choice_right \n     = cspF_Rep_int_choice_nat_right\n       cspF_Rep_int_choice_set_right\n       cspF_Rep_int_choice_com_right\n       cspF_Rep_int_choice_f_right\n\n(* 1,2,3,f E *)\n\nlemma cspF_Rep_int_choice_nat_rightE:\n  \"[| P <=F[M1,M2] !nat :N .. Qf ;\n      ALL n:N. P <=F[M1,M2] Qf n ==> R\n   |] ==> R\"\napply (simp add: cspF_cspT_semantics)\napply (elim conjE exE)\napply (erule cspT_Rep_int_choice_rightE)\n\napply (simp add: subsetF_iff)\napply (simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_set_rightE:\n  \"[| P <=F[M1,M2] !set :Xs .. Qf ;\n      ALL X:Xs. P <=F[M1,M2] Qf X ==> R\n   |] ==> R\"\napply (simp add: cspF_cspT_semantics)\napply (elim conjE exE)\napply (erule cspT_Rep_int_choice_rightE)\n\napply (simp add: subsetF_iff)\napply (simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_com_rightE:\n  \"[| P <=F[M1,M2] ! :X .. Qf ;\n      ALL a:X. P <=F[M1,M2] Qf a ==> R\n   |] ==> R\"\napply (simp add: cspF_cspT_semantics)\napply (elim conjE exE)\napply (erule cspT_Rep_int_choice_rightE)\n\napply (simp add: subsetF_iff)\napply (simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_f_rightE:\n  \"[| P <=F[M1,M2] !<f> :X .. Qf ; inj f ;\n      [| ALL a:X. P <=F[M1,M2] Qf a |] ==> R\n   |] ==> R\"\napply (simp add: cspF_cspT_semantics)\napply (elim conjE exE)\napply (erule cspT_Rep_int_choice_rightE)\napply (simp)\n\napply (simp add: subsetF_iff)\napply (simp add: in_failures)\napply (force)\ndone\n\nlemmas cspF_Rep_int_choice_rightE =\n       cspF_Rep_int_choice_nat_rightE\n       cspF_Rep_int_choice_set_rightE\n       cspF_Rep_int_choice_com_rightE\n       cspF_Rep_int_choice_f_rightE\n\n(*-------------------------------------------------------*\n |             decomposition with subset                 |\n *-------------------------------------------------------*)\n\nlemma cspF_Rep_int_choice_nat_subset:\n  \"[| N2 <= N1  ; !!n. n:N2 ==> Pf n <=F[M1,M2] Qf n |]\n                    ==> !nat :N1 .. Pf <=F[M1,M2] !nat :N2 .. Qf\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Rep_int_choice_subset)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_set_subset:\n  \"[| Ys <= Xs  ; !!X. X:Ys ==> Pf X <=F[M1,M2] Qf X |]\n                    ==> !set :Xs .. Pf <=F[M1,M2] !set :Ys .. Qf\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Rep_int_choice_subset)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_com_subset:\n  \"[| Y <= X  ; !!a. a:Y ==> Pf a <=F[M1,M2] Qf a |]\n                    ==> ! :X .. Pf <=F[M1,M2] ! :Y .. Qf\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Rep_int_choice_subset)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemma cspF_Rep_int_choice_f_subset:\n  \"[| inj f ; Y <= X  ; !!a. a:Y ==> Pf a <=F[M1,M2] Qf a |]\n                    ==> !<f> :X .. Pf <=F[M1,M2] !<f> :Y .. Qf\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Rep_int_choice_subset)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemmas cspF_Rep_int_choice_subset \n     = cspF_Rep_int_choice_nat_subset\n       cspF_Rep_int_choice_set_subset\n       cspF_Rep_int_choice_com_subset\n       cspF_Rep_int_choice_f_subset\n\n(*** ! x:X .. and ? -> ***)\n\nlemma cspF_Int_Ext_pre_choice_subset:\n  \"[| Y ~={} ; Y <= X ; !!a. a:Y ==> Pf a <=F[M1,M2] Qf a |]\n        ==> ! x:X .. (x -> Pf x) <=F[M1,M2]\n            ? :Y -> Qf\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Int_Ext_pre_choice_subset)\napply (rule, simp add: in_failures)\napply (force)\ndone\n\nlemmas cspF_decompo_subset = cspF_Rep_int_choice_subset\n                             cspF_Int_Ext_pre_choice_subset\n\n(*-------------------------------------------------------*\n |               decompose external choice               |\n *-------------------------------------------------------*)\n\nlemma cspF_Ext_choice_right:\n  \"[| P <=F[M1,M2] Q1 ;\n      P <=F[M1,M2] Q2 |]\n      ==> P <=F[M1,M2] Q1 [+] Q2\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Ext_choice_right)\napply (rule)\n\n apply (simp add: in_failures)\n apply (elim disjE conjE exE, simp)\n apply (force, force, force)\n apply (simp_all)\n\n apply (subgoal_tac \"(<>, X) :f failures(Q1) M2\")\n apply (force)\n apply (rule proc_F2_F4)\n apply (simp_all)\n apply (rule proc_F2_F4)\n apply (simp_all)\n apply (simp add: cspT_semantics)\n apply (auto)\ndone\n\nend\n", "meta": {"author": "pefribeiro", "repo": "CSP-Prover", "sha": "8967cc482e5695fca4abb52d9dc2cf36b7b7a44e", "save_path": "github-repos/isabelle/pefribeiro-CSP-Prover", "path": "github-repos/isabelle/pefribeiro-CSP-Prover/CSP-Prover-8967cc482e5695fca4abb52d9dc2cf36b7b7a44e/CSP_F/CSP_F_law_ref.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6076631698328917, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.2825035625210456}}
{"text": "theory InstanceFsetalt\nimports NonFreeAnimation\nbegin \n\n(*\ndatatype 'a fset2 = Emp | Ins 'a ('a fset2) \nwhere \n  Ins a (Ins a s) = Ins a s\n  Ins a1 (Ins a2 s) = Ins a2 (Ins a1 s)\n*)\n\nlocale results =\n  fixes alpha :: tyvar\n    and finset_name :: tyco\n    and ins_name :: oper\n    and emp_name :: oper\n    and dummy :: 'a\nbegin\n\nlemma [ffact]: \"decl_tyvars () [alpha]\" ..\nlemma [ffact]: \"alpha tyinterpr TYPE('a)\" ..\n\nlemma [ffact]: \"finset_name tycohaskind (ExtType =K=> IntType)\" ..\n\nlemma [ffact]: \"ins_name operhasty (alpha =T=> finset_name ** alpha =T=> finset_name ** alpha)\" ..\nlemma [ffact]: \"emp_name operhasty (finset_name ** alpha)\" ..\n\ndefinition \"ins_clause1_name = (0::nat)\"\ndefinition \"ins_clause2_name = (0::nat)\"\n\nlemma [ffact]: \"decl_hcl ins_clause1_name (QUANT a:alpha. QUANT S: finset_name**alpha.\n  ins_name $ a $ (ins_name $ a $ S) === ins_name $ a $ S)\" ..\nlemma [ffact]: \"decl_hcl ins_clause2_name (QUANT a:alpha. QUANT a2:alpha. QUANT S: finset_name**alpha.\n  ins_name $ a $ (ins_name $ a2 $ S) === ins_name $ a2 $ (ins_name $ a $ S))\" ..\n\nlocal_setup {* MetaRec.run_expl_frules *}\n\nend\n\n\nthm results.ins_clause1\nthm results.ins_clause2\n\n\n\n\nlocale algebra_results = results  alpha finset_name ins_name emp_name dummy\n    for alpha :: tyvar\n    and finset_name :: tyco\n    and emp_name :: oper\n    and ins_name :: oper\n    and dummy :: 'a\nbegin\n\n\nlemma [ffact]: \"(finset_name ** alpha) alginterpr TYPE('a set)\" ..\nlemma [ffact]: \"ins_name operalginterpr (% (x::'a) (xs :: 'a set). {x} Un xs)\" ..\nlemma [ffact]: \"emp_name operalginterpr ({} :: 'a set)\" ..\n\nlemma [ffact]: \"proven_hcl (ALL (x::'a) (S::'a set). {x} Un ({x} Un S) = {x} Un S)\"\n  unfolding proven_hcl_def by blast\nlemma [ffact]: \"proven_hcl (ALL (x::'a) (x2::'a) (S::'a set). {x} Un ({x2} Un S) = {x2} Un ({x} Un S))\"\n  unfolding proven_hcl_def by blast\n\nlocal_setup {* MetaRec.run_expl_frules *}\n\nend\n\nthm algebra_results.iter_op_clauses0\n\n\n\nend\n", "meta": {"author": "metaforcy", "repo": "nonfree-data", "sha": "f3ce28278a88fdd240faa2e51f893fee5c15f2f2", "save_path": "github-repos/isabelle/metaforcy-nonfree-data", "path": "github-repos/isabelle/metaforcy-nonfree-data/nonfree-data-f3ce28278a88fdd240faa2e51f893fee5c15f2f2/manual-instantiations/InstanceFsetalt.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6076631698328916, "lm_q2_score": 0.4649015713733885, "lm_q1q2_score": 0.2825035625210455}}
{"text": "(*\n * Copyright 2014, General Dynamics C4 Systems\n *\n * SPDX-License-Identifier: GPL-2.0-only\n *)\n\n(* Title:   Confinement_S\n * Description: Rephrasing of the confinement proof using the concept of islands.\n *)\n\ntheory Islands_S\nimports Confine_S\nbegin\n\ndefinition\n  island :: \"state \\<Rightarrow> entity_id \\<Rightarrow> entity_id set\" where\n  \"island s x \\<equiv> {e\\<^sub>i. s \\<turnstile> x \\<leftrightarrow>* e\\<^sub>i}\"\n\ndefinition\n  island_caps :: \"state \\<Rightarrow> entity_id \\<Rightarrow> cap set\" where\n  \"island_caps s x \\<equiv> \\<Union>(caps_of s ` island s x)\"\n\nlemma island_caps_def2:\n  \"island_caps s x \\<equiv> \\<Union> e \\<in> island s x. caps_of s e\"\n  by(simp add: island_caps_def)\n\nlemma island_caps_def3:\n  \"island_caps s x =  \\<Union>(direct_caps_of s ` island s x)\"\n  apply (clarsimp simp: island_caps_def)\n  apply rule\n   apply (clarsimp simp: island_def caps_of_def)\n   apply (drule store_connected_directly_tgs_connected)\n   apply (metis directly_tgs_connected_rtrancl_into_rtrancl)\n  apply (fastforce simp: caps_of_def store_connected_def)\n  done\n\nlemma island_caps_dom:\n  \"island_caps s e\\<^sub>x \\<le>cap c =\n  (\\<forall>e\\<^sub>i. (e\\<^sub>x, e\\<^sub>i) \\<in> tgs_connected s \\<longrightarrow> caps_of s e\\<^sub>i \\<le>cap c)\"\n  by (auto simp add: island_caps_def caps_dominated_by_def island_def)\n\nlemma authority_confinement_islands:\n  \"\\<lbrakk>s' \\<in> execute cmds s;\n    island_caps s x \\<le>cap c\\<rbrakk>\n  \\<Longrightarrow> island_caps s' x \\<le>cap c\"\n  apply (simp add: island_caps_dom)\n  apply clarsimp\n  apply (frule (1) tgs_connected_preserved)\n  apply (subst (asm) tgs_connected_comm_eq)\n  apply (erule authority_confinement)\n  apply clarsimp\n  apply (erule_tac x=e\\<^sub>i' in allE)\n  apply (erule impE)\n  apply (metis (opaque_lifting, no_types) tgs_connected_comm_eq tgs_connected_def rtrancl_trans)\n  apply clarsimp\n  done\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/spec/take-grant/Islands_S.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926666143433998, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.2824528482608677}}
{"text": "(*  Title:      HOL/HOLCF/Powerdomains.thy\n    Author:     Brian Huffman\n*)\n\nsection {* Powerdomains *}\n\ntheory Powerdomains\nimports ConvexPD Domain\nbegin\n\nsubsection {* Universal domain embeddings *}\n\ndefinition \"upper_emb = udom_emb (\\<lambda>i. upper_map\\<cdot>(udom_approx i))\"\ndefinition \"upper_prj = udom_prj (\\<lambda>i. upper_map\\<cdot>(udom_approx i))\"\n\ndefinition \"lower_emb = udom_emb (\\<lambda>i. lower_map\\<cdot>(udom_approx i))\"\ndefinition \"lower_prj = udom_prj (\\<lambda>i. lower_map\\<cdot>(udom_approx i))\"\n\ndefinition \"convex_emb = udom_emb (\\<lambda>i. convex_map\\<cdot>(udom_approx i))\"\ndefinition \"convex_prj = udom_prj (\\<lambda>i. convex_map\\<cdot>(udom_approx i))\"\n\nlemma ep_pair_upper: \"ep_pair upper_emb upper_prj\"\n  unfolding upper_emb_def upper_prj_def\n  by (simp add: ep_pair_udom approx_chain_upper_map)\n\nlemma ep_pair_lower: \"ep_pair lower_emb lower_prj\"\n  unfolding lower_emb_def lower_prj_def\n  by (simp add: ep_pair_udom approx_chain_lower_map)\n\nlemma ep_pair_convex: \"ep_pair convex_emb convex_prj\"\n  unfolding convex_emb_def convex_prj_def\n  by (simp add: ep_pair_udom approx_chain_convex_map)\n\nsubsection {* Deflation combinators *}\n\ndefinition upper_defl :: \"udom defl \\<rightarrow> udom defl\"\n  where \"upper_defl = defl_fun1 upper_emb upper_prj upper_map\"\n\ndefinition lower_defl :: \"udom defl \\<rightarrow> udom defl\"\n  where \"lower_defl = defl_fun1 lower_emb lower_prj lower_map\"\n\ndefinition convex_defl :: \"udom defl \\<rightarrow> udom defl\"\n  where \"convex_defl = defl_fun1 convex_emb convex_prj convex_map\"\n\nlemma cast_upper_defl:\n  \"cast\\<cdot>(upper_defl\\<cdot>A) = upper_emb oo upper_map\\<cdot>(cast\\<cdot>A) oo upper_prj\"\nusing ep_pair_upper finite_deflation_upper_map\nunfolding upper_defl_def by (rule cast_defl_fun1)\n\nlemma cast_lower_defl:\n  \"cast\\<cdot>(lower_defl\\<cdot>A) = lower_emb oo lower_map\\<cdot>(cast\\<cdot>A) oo lower_prj\"\nusing ep_pair_lower finite_deflation_lower_map\nunfolding lower_defl_def by (rule cast_defl_fun1)\n\nlemma cast_convex_defl:\n  \"cast\\<cdot>(convex_defl\\<cdot>A) = convex_emb oo convex_map\\<cdot>(cast\\<cdot>A) oo convex_prj\"\nusing ep_pair_convex finite_deflation_convex_map\nunfolding convex_defl_def by (rule cast_defl_fun1)\n\nsubsection {* Domain class instances *}\n\ninstantiation upper_pd :: (\"domain\") \"domain\"\nbegin\n\ndefinition\n  \"emb = upper_emb oo upper_map\\<cdot>emb\"\n\ndefinition\n  \"prj = upper_map\\<cdot>prj oo upper_prj\"\n\ndefinition\n  \"defl (t::'a upper_pd itself) = upper_defl\\<cdot>DEFL('a)\"\n\ndefinition\n  \"(liftemb :: 'a upper_pd u \\<rightarrow> udom u) = u_map\\<cdot>emb\"\n\ndefinition\n  \"(liftprj :: udom u \\<rightarrow> 'a upper_pd u) = u_map\\<cdot>prj\"\n\ndefinition\n  \"liftdefl (t::'a upper_pd itself) = liftdefl_of\\<cdot>DEFL('a upper_pd)\"\n\ninstance proof\n  show \"ep_pair emb (prj :: udom \\<rightarrow> 'a upper_pd)\"\n    unfolding emb_upper_pd_def prj_upper_pd_def\n    by (intro ep_pair_comp ep_pair_upper ep_pair_upper_map ep_pair_emb_prj)\nnext\n  show \"cast\\<cdot>DEFL('a upper_pd) = emb oo (prj :: udom \\<rightarrow> 'a upper_pd)\"\n    unfolding emb_upper_pd_def prj_upper_pd_def defl_upper_pd_def cast_upper_defl\n    by (simp add: cast_DEFL oo_def cfun_eq_iff upper_map_map)\nqed (fact liftemb_upper_pd_def liftprj_upper_pd_def liftdefl_upper_pd_def)+\n\nend\n\ninstantiation lower_pd :: (\"domain\") \"domain\"\nbegin\n\ndefinition\n  \"emb = lower_emb oo lower_map\\<cdot>emb\"\n\ndefinition\n  \"prj = lower_map\\<cdot>prj oo lower_prj\"\n\ndefinition\n  \"defl (t::'a lower_pd itself) = lower_defl\\<cdot>DEFL('a)\"\n\ndefinition\n  \"(liftemb :: 'a lower_pd u \\<rightarrow> udom u) = u_map\\<cdot>emb\"\n\ndefinition\n  \"(liftprj :: udom u \\<rightarrow> 'a lower_pd u) = u_map\\<cdot>prj\"\n\ndefinition\n  \"liftdefl (t::'a lower_pd itself) = liftdefl_of\\<cdot>DEFL('a lower_pd)\"\n\ninstance proof\n  show \"ep_pair emb (prj :: udom \\<rightarrow> 'a lower_pd)\"\n    unfolding emb_lower_pd_def prj_lower_pd_def\n    by (intro ep_pair_comp ep_pair_lower ep_pair_lower_map ep_pair_emb_prj)\nnext\n  show \"cast\\<cdot>DEFL('a lower_pd) = emb oo (prj :: udom \\<rightarrow> 'a lower_pd)\"\n    unfolding emb_lower_pd_def prj_lower_pd_def defl_lower_pd_def cast_lower_defl\n    by (simp add: cast_DEFL oo_def cfun_eq_iff lower_map_map)\nqed (fact liftemb_lower_pd_def liftprj_lower_pd_def liftdefl_lower_pd_def)+\n\nend\n\ninstantiation convex_pd :: (\"domain\") \"domain\"\nbegin\n\ndefinition\n  \"emb = convex_emb oo convex_map\\<cdot>emb\"\n\ndefinition\n  \"prj = convex_map\\<cdot>prj oo convex_prj\"\n\ndefinition\n  \"defl (t::'a convex_pd itself) = convex_defl\\<cdot>DEFL('a)\"\n\ndefinition\n  \"(liftemb :: 'a convex_pd u \\<rightarrow> udom u) = u_map\\<cdot>emb\"\n\ndefinition\n  \"(liftprj :: udom u \\<rightarrow> 'a convex_pd u) = u_map\\<cdot>prj\"\n\ndefinition\n  \"liftdefl (t::'a convex_pd itself) = liftdefl_of\\<cdot>DEFL('a convex_pd)\"\n\ninstance proof\n  show \"ep_pair emb (prj :: udom \\<rightarrow> 'a convex_pd)\"\n    unfolding emb_convex_pd_def prj_convex_pd_def\n    by (intro ep_pair_comp ep_pair_convex ep_pair_convex_map ep_pair_emb_prj)\nnext\n  show \"cast\\<cdot>DEFL('a convex_pd) = emb oo (prj :: udom \\<rightarrow> 'a convex_pd)\"\n    unfolding emb_convex_pd_def prj_convex_pd_def defl_convex_pd_def cast_convex_defl\n    by (simp add: cast_DEFL oo_def cfun_eq_iff convex_map_map)\nqed (fact liftemb_convex_pd_def liftprj_convex_pd_def liftdefl_convex_pd_def)+\n\nend\n\nlemma DEFL_upper: \"DEFL('a::domain upper_pd) = upper_defl\\<cdot>DEFL('a)\"\nby (rule defl_upper_pd_def)\n\nlemma DEFL_lower: \"DEFL('a::domain lower_pd) = lower_defl\\<cdot>DEFL('a)\"\nby (rule defl_lower_pd_def)\n\nlemma DEFL_convex: \"DEFL('a::domain convex_pd) = convex_defl\\<cdot>DEFL('a)\"\nby (rule defl_convex_pd_def)\n\nsubsection {* Isomorphic deflations *}\n\nlemma isodefl_upper:\n  \"isodefl d t \\<Longrightarrow> isodefl (upper_map\\<cdot>d) (upper_defl\\<cdot>t)\"\napply (rule isodeflI)\napply (simp add: cast_upper_defl cast_isodefl)\napply (simp add: emb_upper_pd_def prj_upper_pd_def)\napply (simp add: upper_map_map)\ndone\n\nlemma isodefl_lower:\n  \"isodefl d t \\<Longrightarrow> isodefl (lower_map\\<cdot>d) (lower_defl\\<cdot>t)\"\napply (rule isodeflI)\napply (simp add: cast_lower_defl cast_isodefl)\napply (simp add: emb_lower_pd_def prj_lower_pd_def)\napply (simp add: lower_map_map)\ndone\n\nlemma isodefl_convex:\n  \"isodefl d t \\<Longrightarrow> isodefl (convex_map\\<cdot>d) (convex_defl\\<cdot>t)\"\napply (rule isodeflI)\napply (simp add: cast_convex_defl cast_isodefl)\napply (simp add: emb_convex_pd_def prj_convex_pd_def)\napply (simp add: convex_map_map)\ndone\n\nsubsection {* Domain package setup for powerdomains *}\n\nlemmas [domain_defl_simps] = DEFL_upper DEFL_lower DEFL_convex\nlemmas [domain_map_ID] = upper_map_ID lower_map_ID convex_map_ID\nlemmas [domain_isodefl] = isodefl_upper isodefl_lower isodefl_convex\n\nlemmas [domain_deflation] =\n  deflation_upper_map deflation_lower_map deflation_convex_map\n\nsetup {*\n  fold Domain_Take_Proofs.add_rec_type\n    [(@{type_name \"upper_pd\"}, [true]),\n     (@{type_name \"lower_pd\"}, [true]),\n     (@{type_name \"convex_pd\"}, [true])]\n*}\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/HOLCF/Powerdomains.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926665999540698, "lm_q2_score": 0.476579651063676, "lm_q1q2_score": 0.2824528414032058}}
{"text": "(*  Title:      HOL/Bali/Decl.thy\n    Author:     David von Oheimb and Norbert Schirmer\n*)\nsubsection {* Field, method, interface, and class declarations, whole Java programs\n*}\n\ntheory Decl\nimports Term Table\n  (** order is significant, because of clash for \"var\" **)\nbegin\n\ntext {*\nimprovements:\n\\begin{itemize}\n\\item clarification and correction of some aspects of the package/access concept\n  (Also submitted as bug report to the Java Bug Database:\n   Bug Id: 4485402 and Bug Id: 4493343 \n   @{url \"http://developer.java.sun.com/developer/bugParade/index.jshtml\"}\n  )\n\\end{itemize}\nsimplifications:\n\\begin{itemize}\n\\item the only field and method modifiers are static and the access modifiers\n\\item no constructors, which may be simulated by new + suitable methods\n\\item there is just one global initializer per class, which can simulate all \n      others\n\n\\item no throws clause\n\\item a void method is replaced by one that returns Unit (of dummy type Void)\n\n\\item no interface fields\n\n\\item every class has an explicit superclass (unused for Object)\n\\item the (standard) methods of Object and of standard exceptions are not \n      specified\n\n\\item no main method\n\\end{itemize}\n*}\n\nsubsection {* Modifier*}\n\nsubsubsection {* Access modifier *}\n\ndatatype acc_modi (* access modifier *)\n         = Private | Package | Protected | Public \n\ntext {* \nWe can define a linear order for the access modifiers. With Private yielding the\nmost restrictive access and public the most liberal access policy:\n  Private < Package < Protected < Public\n*}\n \ninstantiation acc_modi :: linorder\nbegin\n\ndefinition\n  less_acc_def: \"a < b\n      \\<longleftrightarrow> (case a of\n             Private    \\<Rightarrow> (b=Package \\<or> b=Protected \\<or> b=Public)\n           | Package    \\<Rightarrow> (b=Protected \\<or> b=Public)\n           | Protected  \\<Rightarrow> (b=Public)\n           | Public     \\<Rightarrow> False)\"\n\ndefinition\n  le_acc_def: \"(a :: acc_modi) \\<le> b \\<longleftrightarrow> a < b \\<or> a = b\"\n\ninstance\nproof\n  fix x y z::acc_modi\n  show \"(x < y) = (x \\<le> y \\<and> \\<not> y \\<le> x)\"\n    by (auto simp add: le_acc_def less_acc_def split add: acc_modi.split) \n  show \"x \\<le> x\"                       -- reflexivity\n    by (auto simp add: le_acc_def)\n  {\n    assume \"x \\<le> y\" \"y \\<le> z\"           -- transitivity \n    then show \"x \\<le> z\"\n      by (auto simp add: le_acc_def less_acc_def split add: acc_modi.split)\n  next\n    assume \"x \\<le> y\" \"y \\<le> x\"           -- antisymmetry\n    moreover have \"\\<forall> x y. x < (y::acc_modi) \\<and> y < x \\<longrightarrow> False\"\n      by (auto simp add: less_acc_def split add: acc_modi.split)\n    ultimately show \"x = y\" by (unfold le_acc_def) iprover\n  next\n    fix x y:: acc_modi\n    show \"x \\<le> y \\<or> y \\<le> x\"   \n      by (auto simp add: less_acc_def le_acc_def split add: acc_modi.split)\n  }\nqed\n  \nend\n\nlemma acc_modi_top [simp]: \"Public \\<le> a \\<Longrightarrow> a = Public\"\nby (auto simp add: le_acc_def less_acc_def split: acc_modi.splits)\n\nlemma acc_modi_top1 [simp, intro!]: \"a \\<le> Public\"\nby (auto simp add: le_acc_def less_acc_def split: acc_modi.splits)\n\nlemma acc_modi_le_Public: \n\"a \\<le> Public \\<Longrightarrow> a=Private \\<or> a = Package \\<or> a=Protected \\<or> a=Public\"\nby (auto simp add: le_acc_def less_acc_def split: acc_modi.splits)\n\nlemma acc_modi_bottom: \"a \\<le> Private \\<Longrightarrow> a = Private\"\nby (auto simp add: le_acc_def less_acc_def split: acc_modi.splits)\n\nlemma acc_modi_Private_le: \n\"Private \\<le> a \\<Longrightarrow> a=Private \\<or> a = Package \\<or> a=Protected \\<or> a=Public\"\nby (auto simp add: le_acc_def less_acc_def split: acc_modi.splits)\n\nlemma acc_modi_Package_le: \n  \"Package \\<le> a \\<Longrightarrow> a = Package \\<or> a=Protected \\<or> a=Public\"\nby (auto simp add: le_acc_def less_acc_def split: acc_modi.split)\n\nlemma acc_modi_le_Package: \n  \"a \\<le> Package \\<Longrightarrow> a=Private \\<or> a = Package\"\nby (auto simp add: le_acc_def less_acc_def split: acc_modi.splits)\n\nlemma acc_modi_Protected_le: \n  \"Protected \\<le> a \\<Longrightarrow> a=Protected \\<or> a=Public\"\nby (auto simp add: le_acc_def less_acc_def split: acc_modi.splits)\n\nlemma acc_modi_le_Protected: \n  \"a \\<le> Protected  \\<Longrightarrow> a=Private \\<or> a = Package \\<or> a = Protected\"\nby (auto simp add: le_acc_def less_acc_def split: acc_modi.splits)\n\n\nlemmas acc_modi_le_Dests = acc_modi_top           acc_modi_le_Public\n                           acc_modi_Private_le    acc_modi_bottom\n                           acc_modi_Package_le    acc_modi_le_Package\n                           acc_modi_Protected_le  acc_modi_le_Protected\n\nlemma acc_modi_Package_le_cases:\n  assumes \"Package \\<le> m\"\n  obtains (Package) \"m = Package\"\n    | (Protected) \"m = Protected\"\n    | (Public) \"m = Public\"\nusing assms by (auto dest: acc_modi_Package_le)\n\n\nsubsubsection {* Static Modifier *}\ntype_synonym stat_modi = bool (* modifier: static *)\n\nsubsection {* Declaration (base \"class\" for member,interface and class\n declarations *}\n\nrecord decl =\n        access :: acc_modi\n\ntranslations\n  (type) \"decl\" <= (type) \"\\<lparr>access::acc_modi\\<rparr>\"\n  (type) \"decl\" <= (type) \"\\<lparr>access::acc_modi,\\<dots>::'a\\<rparr>\"\n\nsubsection {* Member (field or method)*}\nrecord  member = decl +\n         static :: stat_modi\n\ntranslations\n  (type) \"member\" <= (type) \"\\<lparr>access::acc_modi,static::bool\\<rparr>\"\n  (type) \"member\" <= (type) \"\\<lparr>access::acc_modi,static::bool,\\<dots>::'a\\<rparr>\"\n\nsubsection {* Field *}\n\nrecord field = member +\n        type :: ty\ntranslations\n  (type) \"field\" <= (type) \"\\<lparr>access::acc_modi, static::bool, type::ty\\<rparr>\"\n  (type) \"field\" <= (type) \"\\<lparr>access::acc_modi, static::bool, type::ty,\\<dots>::'a\\<rparr>\"\n\ntype_synonym fdecl          (* field declaration, cf. 8.3 *)\n        = \"vname \\<times> field\"\n\n\ntranslations\n  (type) \"fdecl\" <= (type) \"vname \\<times> field\"\n\nsubsection  {* Method *}\n\nrecord mhead = member +     (* method head (excluding signature) *)\n        pars ::\"vname list\" (* parameter names *)\n        resT ::ty           (* result type *)\n\nrecord mbody =                      (* method body *)\n        lcls::  \"(vname \\<times> ty) list\" (* local variables *)\n        stmt:: stmt                 (* the body statement *)\n\nrecord methd = mhead + (* method in a class *)\n        mbody::mbody\n\ntype_synonym mdecl = \"sig \\<times> methd\"  (* method declaration in a class *)\n\n\ntranslations\n  (type) \"mhead\" <= (type) \"\\<lparr>access::acc_modi, static::bool, \n                      pars::vname list, resT::ty\\<rparr>\"\n  (type) \"mhead\" <= (type) \"\\<lparr>access::acc_modi, static::bool, \n                      pars::vname list, resT::ty,\\<dots>::'a\\<rparr>\"\n  (type) \"mbody\" <= (type) \"\\<lparr>lcls::(vname \\<times> ty) list,stmt::stmt\\<rparr>\"\n  (type) \"mbody\" <= (type) \"\\<lparr>lcls::(vname \\<times> ty) list,stmt::stmt,\\<dots>::'a\\<rparr>\"      \n  (type) \"methd\" <= (type) \"\\<lparr>access::acc_modi, static::bool, \n                      pars::vname list, resT::ty,mbody::mbody\\<rparr>\"\n  (type) \"methd\" <= (type) \"\\<lparr>access::acc_modi, static::bool, \n                      pars::vname list, resT::ty,mbody::mbody,\\<dots>::'a\\<rparr>\"\n  (type) \"mdecl\" <= (type) \"sig \\<times> methd\"\n\n\ndefinition\n  mhead :: \"methd \\<Rightarrow> mhead\"\n  where \"mhead m = \\<lparr>access=access m, static=static m, pars=pars m, resT=resT m\\<rparr>\"\n\nlemma access_mhead [simp]:\"access (mhead m) = access m\"\nby (simp add: mhead_def)\n\nlemma static_mhead [simp]:\"static (mhead m) = static m\"\nby (simp add: mhead_def)\n\nlemma pars_mhead [simp]:\"pars (mhead m) = pars m\"\nby (simp add: mhead_def)\n\nlemma resT_mhead [simp]:\"resT (mhead m) = resT m\"\nby (simp add: mhead_def)\n\ntext {* To be able to talk uniformaly about field and method declarations we\nintroduce the notion of a member declaration (e.g. useful to define \naccessiblity ) *}\n\ndatatype memberdecl = fdecl fdecl | mdecl mdecl\n\ndatatype memberid = fid vname | mid sig\n\nclass has_memberid =\n  fixes memberid :: \"'a \\<Rightarrow> memberid\"\n\ninstantiation memberdecl :: has_memberid\nbegin\n\ndefinition\nmemberdecl_memberid_def:\n  \"memberid m = (case m of\n                    fdecl (vn,f)  \\<Rightarrow> fid vn\n                  | mdecl (sig,m) \\<Rightarrow> mid sig)\"\n\ninstance ..\n\nend\n\nlemma memberid_fdecl_simp[simp]: \"memberid (fdecl (vn,f)) = fid vn\"\nby (simp add: memberdecl_memberid_def)\n\nlemma memberid_fdecl_simp1: \"memberid (fdecl f) = fid (fst f)\"\nby (cases f) (simp add: memberdecl_memberid_def)\n\nlemma memberid_mdecl_simp[simp]: \"memberid (mdecl (sig,m)) = mid sig\"\nby (simp add: memberdecl_memberid_def)\n\nlemma memberid_mdecl_simp1: \"memberid (mdecl m) = mid (fst m)\"\nby (cases m) (simp add: memberdecl_memberid_def)\n\ninstantiation prod :: (type, has_memberid) has_memberid\nbegin\n\ndefinition\npair_memberid_def:\n  \"memberid p = memberid (snd p)\"\n\ninstance ..\n\nend\n\nlemma memberid_pair_simp[simp]: \"memberid (c,m) = memberid m\"\nby (simp add: pair_memberid_def)\n\nlemma memberid_pair_simp1: \"memberid p  = memberid (snd p)\"\nby (simp add: pair_memberid_def)\n\ndefinition\n  is_field :: \"qtname \\<times> memberdecl \\<Rightarrow> bool\"\n  where \"is_field m = (\\<exists> declC f. m=(declC,fdecl f))\"\n  \nlemma is_fieldD: \"is_field m \\<Longrightarrow> \\<exists> declC f. m=(declC,fdecl f)\"\nby (simp add: is_field_def)\n\nlemma is_fieldI: \"is_field (C,fdecl f)\"\nby (simp add: is_field_def)\n\ndefinition\n  is_method :: \"qtname \\<times> memberdecl \\<Rightarrow> bool\"\n  where \"is_method membr = (\\<exists>declC m. membr=(declC,mdecl m))\"\n  \nlemma is_methodD: \"is_method membr \\<Longrightarrow> \\<exists> declC m. membr=(declC,mdecl m)\"\nby (simp add: is_method_def)\n\nlemma is_methodI: \"is_method (C,mdecl m)\"\nby (simp add: is_method_def)\n\n\nsubsection {* Interface *}\n\n\nrecord  ibody = decl +  --{* interface body *}\n          imethods :: \"(sig \\<times> mhead) list\" --{* method heads *}\n\nrecord  iface = ibody + --{* interface *}\n         isuperIfs:: \"qtname list\" --{* superinterface list *}\ntype_synonym\n        idecl           --{* interface declaration, cf. 9.1 *}\n        = \"qtname \\<times> iface\"\n\ntranslations\n  (type) \"ibody\" <= (type) \"\\<lparr>access::acc_modi,imethods::(sig \\<times> mhead) list\\<rparr>\"\n  (type) \"ibody\" <= (type) \"\\<lparr>access::acc_modi,imethods::(sig \\<times> mhead) list,\\<dots>::'a\\<rparr>\"\n  (type) \"iface\" <= (type) \"\\<lparr>access::acc_modi,imethods::(sig \\<times> mhead) list,\n                      isuperIfs::qtname list\\<rparr>\"\n  (type) \"iface\" <= (type) \"\\<lparr>access::acc_modi,imethods::(sig \\<times> mhead) list,\n                      isuperIfs::qtname list,\\<dots>::'a\\<rparr>\"\n  (type) \"idecl\" <= (type) \"qtname \\<times> iface\"\n\ndefinition\n  ibody :: \"iface \\<Rightarrow> ibody\"\n  where \"ibody i = \\<lparr>access=access i,imethods=imethods i\\<rparr>\"\n\nlemma access_ibody [simp]: \"(access (ibody i)) = access i\"\nby (simp add: ibody_def)\n\nlemma imethods_ibody [simp]: \"(imethods (ibody i)) = imethods i\"\nby (simp add: ibody_def)\n\nsubsection  {* Class *}\nrecord cbody = decl +          --{* class body *}\n         cfields:: \"fdecl list\" \n         methods:: \"mdecl list\"\n         init   :: \"stmt\"       --{* initializer *}\n\nrecord \"class\" = cbody +           --{* class *}\n        super   :: \"qtname\"      --{* superclass *}\n        superIfs:: \"qtname list\" --{* implemented interfaces *}\ntype_synonym\n        cdecl           --{* class declaration, cf. 8.1 *}\n        = \"qtname \\<times> class\"\n\ntranslations\n  (type) \"cbody\" <= (type) \"\\<lparr>access::acc_modi,cfields::fdecl list,\n                      methods::mdecl list,init::stmt\\<rparr>\"\n  (type) \"cbody\" <= (type) \"\\<lparr>access::acc_modi,cfields::fdecl list,\n                      methods::mdecl list,init::stmt,\\<dots>::'a\\<rparr>\"\n  (type) \"class\" <= (type) \"\\<lparr>access::acc_modi,cfields::fdecl list,\n                      methods::mdecl list,init::stmt,\n                      super::qtname,superIfs::qtname list\\<rparr>\"\n  (type) \"class\" <= (type) \"\\<lparr>access::acc_modi,cfields::fdecl list,\n                      methods::mdecl list,init::stmt,\n                      super::qtname,superIfs::qtname list,\\<dots>::'a\\<rparr>\"\n  (type) \"cdecl\" <= (type) \"qtname \\<times> class\"\n\ndefinition\n  cbody :: \"class \\<Rightarrow> cbody\"\n  where \"cbody c = \\<lparr>access=access c, cfields=cfields c,methods=methods c,init=init c\\<rparr>\"\n\nlemma access_cbody [simp]:\"access (cbody c) = access c\"\nby (simp add: cbody_def)\n\nlemma cfields_cbody [simp]:\"cfields (cbody c) = cfields c\"\nby (simp add: cbody_def)\n\nlemma methods_cbody [simp]:\"methods (cbody c) = methods c\"\nby (simp add: cbody_def)\n\nlemma init_cbody [simp]:\"init (cbody c) = init c\"\nby (simp add: cbody_def)\n\n\nsubsubsection \"standard classes\"\n\nconsts\n  Object_mdecls  ::  \"mdecl list\" --{* methods of Object *}\n  SXcpt_mdecls   ::  \"mdecl list\" --{* methods of SXcpts *}\n\ndefinition\n  ObjectC ::         \"cdecl\"      --{* declaration  of root      class   *} where\n  \"ObjectC = (Object,\\<lparr>access=Public,cfields=[],methods=Object_mdecls,\n                                  init=Skip,super=undefined,superIfs=[]\\<rparr>)\"\n\ndefinition\n  SXcptC  ::\"xname \\<Rightarrow> cdecl\"      --{* declarations of throwable classes *} where\n  \"SXcptC xn = (SXcpt xn,\\<lparr>access=Public,cfields=[],methods=SXcpt_mdecls,\n                                   init=Skip,\n                                   super=if xn = Throwable then Object \n                                                           else SXcpt Throwable,\n                                   superIfs=[]\\<rparr>)\"\n\nlemma ObjectC_neq_SXcptC [simp]: \"ObjectC \\<noteq> SXcptC xn\"\nby (simp add: ObjectC_def SXcptC_def Object_def SXcpt_def)\n\nlemma SXcptC_inject [simp]: \"(SXcptC xn = SXcptC xm) = (xn = xm)\"\nby (simp add: SXcptC_def)\n\ndefinition\n  standard_classes :: \"cdecl list\" where\n  \"standard_classes = [ObjectC, SXcptC Throwable,\n                SXcptC NullPointer, SXcptC OutOfMemory, SXcptC ClassCast,\n                SXcptC NegArrSize , SXcptC IndOutBound, SXcptC ArrStore]\"\n\n\nsubsubsection \"programs\"\n\nrecord prog =\n        ifaces ::\"idecl list\"\n        \"classes\"::\"cdecl list\"\n\ntranslations\n     (type) \"prog\" <= (type) \"\\<lparr>ifaces::idecl list,classes::cdecl list\\<rparr>\"\n     (type) \"prog\" <= (type) \"\\<lparr>ifaces::idecl list,classes::cdecl list,\\<dots>::'a\\<rparr>\"\n\nabbreviation\n  iface :: \"prog  \\<Rightarrow> (qtname, iface) table\"\n  where \"iface G I == table_of (ifaces G) I\"\n\nabbreviation\n  \"class\" :: \"prog  \\<Rightarrow> (qtname, class) table\"\n  where \"class G C == table_of (classes G) C\"\n\nabbreviation\n  is_iface :: \"prog  \\<Rightarrow> qtname  \\<Rightarrow> bool\"\n  where \"is_iface G I == iface G I \\<noteq> None\"\n\nabbreviation\n  is_class :: \"prog  \\<Rightarrow> qtname  \\<Rightarrow> bool\"\n  where \"is_class G C == class G C \\<noteq> None\"\n\n\nsubsubsection \"is type\"\n\nprimrec is_type :: \"prog \\<Rightarrow> ty \\<Rightarrow> bool\"\n  and isrtype :: \"prog \\<Rightarrow> ref_ty \\<Rightarrow> bool\"\nwhere\n  \"is_type G (PrimT pt)  = True\"\n| \"is_type G (RefT  rt)  = isrtype G rt\"\n| \"isrtype G (NullT) = True\"\n| \"isrtype G (IfaceT tn) = is_iface G tn\"\n| \"isrtype G (ClassT tn) = is_class G tn\"\n| \"isrtype G (ArrayT T ) = is_type  G T\"\n\nlemma type_is_iface: \"is_type G (Iface I) \\<Longrightarrow> is_iface G I\"\nby auto\n\nlemma type_is_class: \"is_type G (Class C) \\<Longrightarrow>  is_class G C\"\nby auto\n\n\nsubsubsection \"subinterface and subclass relation, in anticipation of TypeRel.thy\"\n\ndefinition\n  subint1  :: \"prog \\<Rightarrow> (qtname \\<times> qtname) set\" --{* direct subinterface *}\n  where \"subint1 G = {(I,J). \\<exists>i\\<in>iface G I: J\\<in>set (isuperIfs i)}\"\n\ndefinition\n  subcls1  :: \"prog \\<Rightarrow> (qtname \\<times> qtname) set\" --{* direct subclass *}\n  where \"subcls1 G = {(C,D). C\\<noteq>Object \\<and> (\\<exists>c\\<in>class G C: super c = D)}\"\n\nabbreviation\n  subcls1_syntax :: \"prog => [qtname, qtname] => bool\" (\"_|-_<:C1_\" [71,71,71] 70)\n  where \"G|-C <:C1 D == (C,D) \\<in> subcls1 G\"\n\nabbreviation\n  subclseq_syntax :: \"prog => [qtname, qtname] => bool\" (\"_|-_<=:C _\"[71,71,71] 70)\n  where \"G|-C <=:C D == (C,D) \\<in>(subcls1 G)^*\" (* cf. 8.1.3 *)\n\nabbreviation\n  subcls_syntax :: \"prog => [qtname, qtname] => bool\" (\"_|-_<:C _\"[71,71,71] 70)\n  where \"G|-C <:C D == (C,D) \\<in>(subcls1 G)^+\"\n\nnotation (xsymbols)\n  subcls1_syntax  (\"_\\<turnstile>_\\<prec>\\<^sub>C1_\"  [71,71,71] 70) and\n  subclseq_syntax  (\"_\\<turnstile>_\\<preceq>\\<^sub>C _\"  [71,71,71] 70) and\n  subcls_syntax  (\"_\\<turnstile>_\\<prec>\\<^sub>C _\"  [71,71,71] 70)\n\nlemma subint1I: \"\\<lbrakk>iface G I = Some i; J \\<in> set (isuperIfs i)\\<rbrakk> \n                 \\<Longrightarrow> (I,J) \\<in> subint1 G\" \napply (simp add: subint1_def)\ndone\n\nlemma subcls1I:\"\\<lbrakk>class G C = Some c; C \\<noteq> Object\\<rbrakk> \\<Longrightarrow> (C,(super c)) \\<in> subcls1 G\"\napply (simp add: subcls1_def)\ndone\n\n\nlemma subint1D: \"(I,J)\\<in>subint1 G\\<Longrightarrow> \\<exists>i\\<in>iface G I: J\\<in>set (isuperIfs i)\"\nby (simp add: subint1_def)\n\nlemma subcls1D: \n  \"(C,D)\\<in>subcls1 G \\<Longrightarrow> C\\<noteq>Object \\<and> (\\<exists>c. class G C = Some c \\<and> (super c = D))\"\napply (simp add: subcls1_def)\napply auto\ndone\n\nlemma subint1_def2:  \n  \"subint1 G = (SIGMA I: {I. is_iface G I}. set (isuperIfs (the (iface G I))))\"\napply (unfold subint1_def)\napply auto\ndone\n\nlemma subcls1_def2: \n  \"subcls1 G = \n     (SIGMA C: {C. is_class G C}. {D. C\\<noteq>Object \\<and> super (the(class G C))=D})\"\napply (unfold subcls1_def)\napply auto\ndone\n\nlemma subcls_is_class:\n\"\\<lbrakk>G\\<turnstile>C \\<prec>\\<^sub>C D\\<rbrakk> \\<Longrightarrow> \\<exists> c. class G C = Some c\"\nby (auto simp add: subcls1_def dest: tranclD)\n\nlemma no_subcls1_Object:\"G\\<turnstile>Object\\<prec>\\<^sub>C1 D \\<Longrightarrow> P\"\nby (auto simp add: subcls1_def)\n\nlemma no_subcls_Object: \"G\\<turnstile>Object\\<prec>\\<^sub>C D \\<Longrightarrow> P\"\napply (erule trancl_induct)\napply (auto intro: no_subcls1_Object)\ndone\n\nsubsubsection \"well-structured programs\"\n\ndefinition\n  ws_idecl :: \"prog \\<Rightarrow> qtname \\<Rightarrow> qtname list \\<Rightarrow> bool\"\n  where \"ws_idecl G I si = (\\<forall>J\\<in>set si.  is_iface G J   \\<and> (J,I)\\<notin>(subint1 G)^+)\"\n  \ndefinition\n  ws_cdecl :: \"prog \\<Rightarrow> qtname \\<Rightarrow> qtname \\<Rightarrow> bool\"\n  where \"ws_cdecl G C sc = (C\\<noteq>Object \\<longrightarrow> is_class G sc \\<and> (sc,C)\\<notin>(subcls1 G)^+)\"\n  \ndefinition\n  ws_prog  :: \"prog \\<Rightarrow> bool\" where\n  \"ws_prog G = ((\\<forall>(I,i)\\<in>set (ifaces  G). ws_idecl G I (isuperIfs i)) \\<and> \n                 (\\<forall>(C,c)\\<in>set (classes G). ws_cdecl G C (super c)))\"\n\n\nlemma ws_progI: \n\"\\<lbrakk>\\<forall>(I,i)\\<in>set (ifaces G). \\<forall>J\\<in>set (isuperIfs i). is_iface G J \\<and> \n                                                (J,I) \\<notin> (subint1 G)^+; \n  \\<forall>(C,c)\\<in>set (classes G). C\\<noteq>Object \\<longrightarrow> is_class G (super c) \\<and> \n                                        ((super c),C) \\<notin> (subcls1 G)^+  \n \\<rbrakk> \\<Longrightarrow> ws_prog G\"\napply (unfold ws_prog_def ws_idecl_def ws_cdecl_def)\napply (erule_tac conjI)\napply blast\ndone\n\nlemma ws_prog_ideclD: \n\"\\<lbrakk>iface G I = Some i; J\\<in>set (isuperIfs i); ws_prog G\\<rbrakk> \\<Longrightarrow>  \n  is_iface G J \\<and> (J,I)\\<notin>(subint1 G)^+\"\napply (unfold ws_prog_def ws_idecl_def)\napply clarify\napply (drule_tac map_of_SomeD)\napply auto\ndone\n\nlemma ws_prog_cdeclD: \n\"\\<lbrakk>class G C = Some c; C\\<noteq>Object; ws_prog G\\<rbrakk> \\<Longrightarrow>  \n  is_class G (super c) \\<and> (super c,C)\\<notin>(subcls1 G)^+\"\napply (unfold ws_prog_def ws_cdecl_def)\napply clarify\napply (drule_tac map_of_SomeD)\napply auto\ndone\n\n\nsubsubsection \"well-foundedness\"\n\nlemma finite_is_iface: \"finite {I. is_iface G I}\"\napply (fold dom_def)\napply (rule_tac finite_dom_map_of)\ndone\n\nlemma finite_is_class: \"finite {C. is_class G C}\"\napply (fold dom_def)\napply (rule_tac finite_dom_map_of)\ndone\n\nlemma finite_subint1: \"finite (subint1 G)\"\napply (subst subint1_def2)\napply (rule finite_SigmaI)\napply (rule finite_is_iface)\napply (simp (no_asm))\ndone\n\nlemma finite_subcls1: \"finite (subcls1 G)\"\napply (subst subcls1_def2)\napply (rule finite_SigmaI)\napply (rule finite_is_class)\napply (rule_tac B = \"{super (the (class G C))}\" in finite_subset)\napply  auto\ndone\n\nlemma subint1_irrefl_lemma1: \n  \"ws_prog G \\<Longrightarrow> (subint1 G)^-1 \\<inter> (subint1 G)^+ = {}\"\napply (force dest: subint1D ws_prog_ideclD conjunct2)\ndone\n\nlemma subcls1_irrefl_lemma1: \n  \"ws_prog G \\<Longrightarrow> (subcls1 G)^-1 \\<inter> (subcls1 G)^+ = {}\"\napply (force dest: subcls1D ws_prog_cdeclD conjunct2)\ndone\n\nlemmas subint1_irrefl_lemma2 = subint1_irrefl_lemma1 [THEN irrefl_tranclI']\nlemmas subcls1_irrefl_lemma2 = subcls1_irrefl_lemma1 [THEN irrefl_tranclI']\n\nlemma subint1_irrefl: \"\\<lbrakk>(x, y) \\<in> subint1 G; ws_prog G\\<rbrakk> \\<Longrightarrow> x \\<noteq> y\"\napply (rule irrefl_trancl_rD)\napply (rule subint1_irrefl_lemma2)\napply auto\ndone\n\nlemma subcls1_irrefl: \"\\<lbrakk>(x, y) \\<in> subcls1 G; ws_prog G\\<rbrakk> \\<Longrightarrow> x \\<noteq> y\"\napply (rule irrefl_trancl_rD)\napply (rule subcls1_irrefl_lemma2)\napply auto\ndone\n\nlemmas subint1_acyclic = subint1_irrefl_lemma2 [THEN acyclicI]\nlemmas subcls1_acyclic = subcls1_irrefl_lemma2 [THEN acyclicI]\n\n\nlemma wf_subint1: \"ws_prog G \\<Longrightarrow> wf ((subint1 G)\\<inverse>)\"\nby (auto intro: finite_acyclic_wf_converse finite_subint1 subint1_acyclic)\n\nlemma wf_subcls1: \"ws_prog G \\<Longrightarrow> wf ((subcls1 G)\\<inverse>)\"\nby (auto intro: finite_acyclic_wf_converse finite_subcls1 subcls1_acyclic)\n\n\nlemma subint1_induct: \n  \"\\<lbrakk>ws_prog G; \\<And>x. \\<forall>y. (x, y) \\<in> subint1 G \\<longrightarrow> P y \\<Longrightarrow> P x\\<rbrakk> \\<Longrightarrow> P a\"\napply (frule wf_subint1)\napply (erule wf_induct)\napply (simp (no_asm_use) only: converse_iff)\napply blast\ndone\n\nlemma subcls1_induct [consumes 1]:\n  \"\\<lbrakk>ws_prog G; \\<And>x. \\<forall>y. (x, y) \\<in> subcls1 G \\<longrightarrow> P y \\<Longrightarrow> P x\\<rbrakk> \\<Longrightarrow> P a\"\napply (frule wf_subcls1)\napply (erule wf_induct)\napply (simp (no_asm_use) only: converse_iff)\napply blast\ndone\n\nlemma ws_subint1_induct: \n \"\\<lbrakk>is_iface G I; ws_prog G; \\<And>I i. \\<lbrakk>iface G I = Some i \\<and> \n   (\\<forall>J \\<in> set (isuperIfs i). (I,J)\\<in>subint1 G \\<and> P J \\<and> is_iface G J)\\<rbrakk> \\<Longrightarrow> P I\n  \\<rbrakk> \\<Longrightarrow> P I\"\napply (erule rev_mp)\napply (rule subint1_induct)\napply  assumption\napply (simp (no_asm)) \napply safe\napply (blast dest: subint1I ws_prog_ideclD)\ndone\n\n\nlemma ws_subcls1_induct: \"\\<lbrakk>is_class G C; ws_prog G;  \n  \\<And>C c. \\<lbrakk>class G C = Some c;  \n (C \\<noteq> Object \\<longrightarrow> (C,(super c))\\<in>subcls1 G \\<and> \n                  P (super c) \\<and> is_class G (super c))\\<rbrakk> \\<Longrightarrow> P C\n \\<rbrakk> \\<Longrightarrow> P C\"\napply (erule rev_mp)\napply (rule subcls1_induct)\napply  assumption\napply (simp (no_asm)) \napply safe\napply (fast dest: subcls1I ws_prog_cdeclD)\ndone\n\nlemma ws_class_induct [consumes 2, case_names Object Subcls]:\n\"\\<lbrakk>class G C = Some c; ws_prog G; \n  \\<And> co. class G Object = Some co \\<Longrightarrow> P Object; \n  \\<And>  C c. \\<lbrakk>class G C = Some c; C \\<noteq> Object; P (super c)\\<rbrakk> \\<Longrightarrow> P C\n \\<rbrakk> \\<Longrightarrow> P C\"\nproof -\n  assume clsC: \"class G C = Some c\"\n  and    init: \"\\<And> co. class G Object = Some co \\<Longrightarrow> P Object\"\n  and    step: \"\\<And>   C c. \\<lbrakk>class G C = Some c; C \\<noteq> Object; P (super c)\\<rbrakk> \\<Longrightarrow> P C\"\n  assume ws: \"ws_prog G\"\n  then have \"is_class G C \\<Longrightarrow> P C\"  \n  proof (induct rule: subcls1_induct)\n    fix C\n    assume   hyp:\"\\<forall> S. G\\<turnstile>C \\<prec>\\<^sub>C1 S \\<longrightarrow> is_class G S \\<longrightarrow> P S\"\n       and iscls:\"is_class G C\"\n    show \"P C\"\n    proof (cases \"C=Object\")\n      case True with iscls init show \"P C\" by auto\n    next\n      case False with ws step hyp iscls \n      show \"P C\" by (auto dest: subcls1I ws_prog_cdeclD)\n    qed\n  qed\n  with clsC show ?thesis by simp\nqed\n\nlemma ws_class_induct' [consumes 2, case_names Object Subcls]:\n\"\\<lbrakk>is_class G C; ws_prog G; \n  \\<And> co. class G Object = Some co \\<Longrightarrow> P Object; \n  \\<And> C c. \\<lbrakk>class G C = Some c; C \\<noteq> Object; P (super c)\\<rbrakk> \\<Longrightarrow> P C\n \\<rbrakk> \\<Longrightarrow> P C\"\nby (auto intro: ws_class_induct)\n\nlemma ws_class_induct'' [consumes 2, case_names Object Subcls]:\n\"\\<lbrakk>class G C = Some c; ws_prog G; \n  \\<And> co. class G Object = Some co \\<Longrightarrow> P Object co; \n  \\<And>  C c sc. \\<lbrakk>class G C = Some c; class G (super c) = Some sc;\n            C \\<noteq> Object; P (super c) sc\\<rbrakk> \\<Longrightarrow> P C c\n \\<rbrakk> \\<Longrightarrow> P C c\"\nproof -\n  assume clsC: \"class G C = Some c\"\n  and    init: \"\\<And> co. class G Object = Some co \\<Longrightarrow> P Object co\"\n  and    step: \"\\<And> C c sc . \\<lbrakk>class G C = Some c; class G (super c) = Some sc;\n                             C \\<noteq> Object; P (super c) sc\\<rbrakk> \\<Longrightarrow> P C c\"\n  assume ws: \"ws_prog G\"\n  then have \"\\<And> c. class G C = Some c\\<Longrightarrow> P C c\"  \n  proof (induct rule: subcls1_induct)\n    fix C c\n    assume   hyp:\"\\<forall> S. G\\<turnstile>C \\<prec>\\<^sub>C1 S \\<longrightarrow> (\\<forall> s. class G S = Some s \\<longrightarrow> P S s)\"\n       and iscls:\"class G C = Some c\"\n    show \"P C c\"\n    proof (cases \"C=Object\")\n      case True with iscls init show \"P C c\" by auto\n    next\n      case False\n      with ws iscls obtain sc where\n        sc: \"class G (super c) = Some sc\"\n        by (auto dest: ws_prog_cdeclD)\n      from iscls False have \"G\\<turnstile>C \\<prec>\\<^sub>C1 (super c)\" by (rule subcls1I)\n      with False ws step hyp iscls sc\n      show \"P C c\" \n        by (auto)  \n    qed\n  qed\n  with clsC show \"P C c\" by auto\nqed\n\nlemma ws_interface_induct [consumes 2, case_names Step]:\n  assumes is_if_I: \"is_iface G I\" and \n               ws: \"ws_prog G\" and\n          hyp_sub: \"\\<And>I i. \\<lbrakk>iface G I = Some i; \n                            \\<forall> J \\<in> set (isuperIfs i).\n                                 (I,J)\\<in>subint1 G \\<and> P J \\<and> is_iface G J\\<rbrakk> \\<Longrightarrow> P I\"\n  shows \"P I\"\nproof -\n  from is_if_I ws \n  show \"P I\"\n  proof (rule ws_subint1_induct)\n    fix I i\n    assume hyp: \"iface G I = Some i \\<and>\n                (\\<forall>J\\<in>set (isuperIfs i). (I,J) \\<in>subint1 G \\<and> P J \\<and> is_iface G J)\"\n    then have if_I: \"iface G I = Some i\"\n      by blast\n    show \"P I\"\n    proof (cases \"isuperIfs i\")\n      case Nil\n      with if_I hyp_sub \n      show \"P I\" \n        by auto\n    next\n      case (Cons hd tl)\n      with hyp if_I hyp_sub \n      show \"P I\" \n        by auto\n    qed\n  qed\nqed\n\nsubsubsection \"general recursion operators for the interface and class hiearchies\"\n\nfunction iface_rec  :: \"prog \\<Rightarrow> qtname \\<Rightarrow> (qtname \\<Rightarrow> iface \\<Rightarrow> 'a set \\<Rightarrow> 'a) \\<Rightarrow> 'a\"\nwhere\n[simp del]: \"iface_rec G I f = \n  (case iface G I of \n         None \\<Rightarrow> undefined \n       | Some i \\<Rightarrow> if ws_prog G \n                      then f I i \n                               ((\\<lambda>J. iface_rec G J f)`set (isuperIfs i))\n                      else undefined)\"\nby auto\ntermination\nby (relation \"inv_image (same_fst ws_prog (\\<lambda>G. (subint1 G)^-1)) (%(x,y,z). (x,y))\")\n (auto simp: wf_subint1 subint1I wf_same_fst)\n\nlemma iface_rec: \n\"\\<lbrakk>iface G I = Some i; ws_prog G\\<rbrakk> \\<Longrightarrow> \n iface_rec G I f = f I i ((\\<lambda>J. iface_rec G J f)`set (isuperIfs i))\"\napply (subst iface_rec.simps)\napply simp\ndone\n\n\nfunction\n  class_rec  :: \"prog \\<Rightarrow> qtname \\<Rightarrow> 'a \\<Rightarrow> (qtname \\<Rightarrow> class \\<Rightarrow> 'a     \\<Rightarrow> 'a) \\<Rightarrow> 'a\"\nwhere\n[simp del]: \"class_rec G C t f = \n  (case class G C of \n           None \\<Rightarrow> undefined \n         | Some c \\<Rightarrow> if ws_prog G \n                        then f C c \n                                 (if C = Object then t \n                                                else class_rec G (super c) t f)\n                        else undefined)\"\n\nby auto\ntermination\nby (relation \"inv_image (same_fst ws_prog (\\<lambda>G. (subcls1 G)^-1)) (%(x,y,z,w). (x,y))\")\n (auto simp: wf_subcls1 subcls1I wf_same_fst)\n\nlemma class_rec: \"\\<lbrakk>class G C = Some c; ws_prog G\\<rbrakk> \\<Longrightarrow>  \n class_rec G C t f = \n   f C c (if C = Object then t else class_rec G (super c) t f)\"\napply (subst class_rec.simps)\napply simp\ndone\n\ndefinition\n  imethds :: \"prog \\<Rightarrow> qtname \\<Rightarrow> (sig,qtname \\<times> mhead) tables\" where\n  --{* methods of an interface, with overriding and inheritance, cf. 9.2 *}\n  \"imethds G I = iface_rec G I\n              (\\<lambda>I i ts. (Un_tables ts) \\<oplus>\\<oplus> \n                        (set_option \\<circ> table_of (map (\\<lambda>(s,m). (s,I,m)) (imethods i))))\"\n        \n\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/Bali/Decl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926665999540698, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.2824528414032058}}
{"text": "(*\n * Copyright 2016, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the GNU General Public License version 2. Note that NO WARRANTY is provided.\n * See \"LICENSE_GPLv2.txt\" for details.\n *\n * @TAG(NICTA_GPL)\n *)\n\ntheory Corres_Tac\nimports \n  \"Cogent_Corres\"\n  \"../cogent/isa/ProofTrace\"\n  \"../cogent/isa/CogentHelper\"\n  Value_Relation_Generation\n\nbegin    \n\n(*\n * Fix Cogent/C mismatch caused by unused return values of C blocks.\n * Cogent code can bind a value without using it. This commonly appears in code like\n *\n *   -- first, a message from our sponsors\n *   let debug_output = stuff\n *   and _ = _debug_print debug_output\n *   -- now back to our regularly scheduled programming\n *   ...\n *\n * where debug_output becomes unused because the call to _debug_print is stripped for verification.\n *\n * When AutoCorres comes across this code, it figures that debug_output is unused,\n * so its generated code for \"stuff\" appends \"gets (\\<lambda>_. ())\".\n * This breaks Corres_Tac's expectation that the C code for \"stuff\" returns a value that\n * corresponds to the Cogent code.\n *\n * We fix that up by walking the AutoCorres output and removing the extra \"gets (\\<lambda>_. ())\",\n * allowing the original return value of \"stuff\" to be propagated.\n * The most annoying bit is that the last statement of a monad block is the most deeply nested.\n * So our rules need to iterate through pairs of consecutive statements in the same manner\n * as @{term simp_last_bind}. The other annoying bit is that we need to change the return type\n * from unit to the corresponding type (e.g. of debug_output).\n * We use a stack of schematic variables to remember where to apply the type changes.\n *\n * This could also be fixed directly in AutoCorres, assuming someone remembers how l2 works...\n *)\n\ndefinition \"cogent_C_unused_return__internal X Y \\<equiv> X = (do Y; return () od)\"\n\nlemma cogent_C_unused_return_step:\n  \"\\<And>A A' B B'. A = A' \\<Longrightarrow> B = B' \\<Longrightarrow> A >>= K_bind B = A' >>= K_bind B'\"\n  \"\\<And>A A' B B'. A = A' \\<Longrightarrow> (\\<And>v. B v = B' v) \\<Longrightarrow> A >>= B = A' >>= B'\"\n  by meson+\n\n(* This should be the only interesting statement block.\n * For Let and LetBang codegen, C always returns true and R is unused,\n * so we don't care what the rules do to it. *)\nlemma cogent_C_unused_return_L:\n  \"\\<lbrakk> L = L';\n     cogent_C_unused_return__internal (L' :: ('s, unit) nondet_monad) (L'' :: ('s, 'a) nondet_monad);\n     X = X' \\<rbrakk> \\<Longrightarrow>\n   (do (_ :: unit) \\<leftarrow> condition C L R; X od)\n    =\n   (do (_ :: 'a) \\<leftarrow> condition C L'' (do R; return undefined od); X' od)\"\n  apply (simp add: cogent_C_unused_return__internal_def)\n  (* goal assumptions cause normal monad_eq to loop *)\n  apply (tactic {* simp_tac (@{context} addsimps (MonadEqThms.get @{context})) 1 *})\n  apply blast\n  done\n\nlemma cogent_C_unused_return__internal:\n  \"\\<And>A. cogent_C_unused_return__internal (do v \\<leftarrow> A; gets (\\<lambda>_. ()) od) A\"\n  \"\\<And>A A' B B'. \\<lbrakk> A = A'; (\\<And>v. cogent_C_unused_return__internal (B v) (B' v)) \\<rbrakk> \\<Longrightarrow>\n                cogent_C_unused_return__internal (A >>= B) (A' >>= B')\"\n  \"\\<And>A A'. A = A' \\<Longrightarrow> cogent_C_unused_return__internal A A'\"\n  by (monad_eq simp: cogent_C_unused_return__internal_def | blast)+\n\n(* Test: *)\nschematic_lemma\n  (* input *)\n  \"(do stuff1;\n       stuff2;\n       _ \\<leftarrow>\n         condition C1\n           (do _ \\<leftarrow>\n                 condition C2\n                   (do _ \\<leftarrow> gets (\\<lambda>_. r1);\n                       gets (\\<lambda>_. ()) od) (* <-- *)\n                   bla1;\n               gets (\\<lambda>_. ()) od)         (* <-- *)\n           bla2;\n       _ \\<leftarrow>\n         condition C3 stuff3 stuff4;     (* no change *)\n       stuff5 od)\n    = ?A\"\n  (* expected output *)\n  \"?A =\n   (do stuff1;\n       stuff2;\n       _ \\<leftarrow>\n         condition C1\n           (condition C2\n              (gets (\\<lambda>_. r1))\n              (do bla1; return undefined od))\n           (do bla2; return undefined od);\n       _ \\<leftarrow>\n         condition C3 stuff3 stuff4;\n       stuff5 od)\"\n  (* do it *)\n  apply ((rule cogent_C_unused_return_L cogent_C_unused_return_step cogent_C_unused_return__internal refl)+)[1]\n  (* check *)\n  by (rule refl)\n\n(* Apply the rewrite to a corres proof state.\n * In corres_tac, we apply this tactic blindly and it rewrites all unit-returning blocks\n * in the C code. This should be safe because no genuine Cogent code ever returns unit\n * (the unit type in Cogent is currently compiled to unit_t in C, instead of void). *)\n(* FIXME: maybe make this part of Tidy *)\n\ncontext update_sem_init begin\nlemma cogent_corres_unused_return:\n  \"m = m' \\<Longrightarrow>\n   corres srel c m' \\<xi> \\<gamma> \\<Xi> \\<Gamma> \\<sigma> s \\<Longrightarrow>\n   corres srel c m \\<xi> \\<gamma> \\<Xi> \\<Gamma> \\<sigma> s\"\n  by simp\n\nML {*\nfun cogent_C_unused_return_tac ctxt = let\n  (* import into ctxt's locale *)\n  val corres_rule = Proof_Context.get_thm ctxt \"cogent_corres_unused_return\"\n  in fn n =>\n      rtac corres_rule n\n      THEN SOLVES (REPEAT_DETERM\n             (resolve_tac ctxt @{thms cogent_C_unused_return_L cogent_C_unused_return_step\n                                      cogent_C_unused_return__internal refl} n)) end\n*}\nend\n\n\nML {*\n(* Create derivative equations that only apply in a given context.\n *\n *   make_contextual_eq_thms \"f\" [\"a = b\", \"c = d\"] ctxt\n *    = [\"f a = f b\", \"f c = f d\"]\n *)\nfun make_contextual_eq_thms (context : term) (eq_thms : thm list) ctxt : thm list =\n  let fun dest_eq (Const (@{const_name \"Trueprop\"}, _) $ eq) = dest_eq eq\n        | dest_eq (Const (@{const_name \"Pure.eq\"}, _) $ l $ r) = (l, r)\n        | dest_eq (Const (@{const_name \"HOL.eq\"}, _) $ l $ r) = (l, r)\n        | dest_eq t = raise (TERM (\"ContextThms.dest_eq\", [t]))\n      fun make_eq_thm thm0 =\n        let val ((_, [thm]), _) = Variable.import true [thm0] (Variable.set_body false ctxt);\n            val (lhs, rhs) = dest_eq (Thm.prop_of thm)\n                             handle TERM _ => raise THM (\"make_contextual_eq_thms: not an equation\", 0, [thm0])\n            val prop = @{term Trueprop} $ (@{term \"op =\"} $ (context $ lhs) $ (context $ rhs))\n            val prop' = map_types (K dummyT) prop |> Syntax.check_term ctxt\n                        handle ERROR _ => raise TERM (\"make_contextual_eq_thms: equality term is invalid\", [prop])\n            fun free_var v = case Syntax.check_term ctxt (Free (v, dummyT)) of\n                                Free (_, TFree _) => true\n                              | _ => false\n        in Goal.prove ctxt (filter free_var (Term.add_free_names prop' [])) [] prop'\n                      (K (simp_tac (ctxt addsimps [thm]) 1))\n           handle ERROR msg => raise TERM (\"make_contextual_eq_thms proof failed:\\n\" ^ msg, [prop']) end\n  in map make_eq_thm eq_thms end\n*}\n\nlemma simp_trivial_gets:\n  \"do x \\<leftarrow> gets (\\<lambda>_. v); B x od = B v\"\n  by simp\n(* Limit simp_trivial_gets to the top level *)\nlocal_setup {*\nfn ctxt =>\nLocal_Theory.note\n  ((Binding.name \"corres_simp_gets\", []),\n   (make_contextual_eq_thms @{term \"\\<lambda>m. update_sem_init.corres abs_typing abs_repr srel c m \\<xi>' \\<gamma> \\<Xi>' \\<Gamma>' \\<sigma> s\"} @{thms simp_trivial_gets} ctxt))\n  ctxt |> snd\n*}\n\nlemma simp_condition_bind:\n  \"do retval \\<leftarrow> condition b x y; gets (\\<lambda>s. retval) od = condition b x y\" by simp\n\nlocal_setup {*\nfn ctxt =>\nLocal_Theory.note\n  ((Binding.name \"corres_simp_cond_gets\", []),\n   (make_contextual_eq_thms @{term \"\\<lambda>m. update_sem_init.corres abs_typing abs_repr srel c m \\<xi>' \\<gamma> \\<Xi>' \\<Gamma>' \\<sigma> s\"} @{thms simp_condition_bind} ctxt))\n  ctxt |> snd\n*}\n\nlemma ucast_up_lesseq[OF refl]:\n  \"upcast = ucast\n    \\<Longrightarrow> is_up (upcast :: ('a :: len) word \\<Rightarrow> ('b :: len) word)\n    \\<Longrightarrow> (upcast x \\<le> upcast y) = (x \\<le> y)\"\n  by (simp add: word_le_nat_alt unat_ucast_upcast)\n\nlemma ucast_up_less[OF refl]:\n  \"upcast = ucast\n    \\<Longrightarrow> is_up (upcast :: ('a :: len) word \\<Rightarrow> ('b :: len) word)\n    \\<Longrightarrow> (upcast x < upcast y) = (x < y)\"\n  by (simp add: word_less_nat_alt unat_ucast_upcast)\n\nlemma ucast_up_mod[OF refl]:\n  \"upcast = ucast\n    \\<Longrightarrow> is_up (upcast :: ('c :: len) word \\<Rightarrow> ('d :: len) word)\n    \\<Longrightarrow> (upcast x mod upcast y) = upcast (x mod y)\"\n  apply (rule word_unat.Rep_eqD)\n  apply (simp only: unat_mod unat_ucast_upcast)\n  done\n\nlemma ucast_up_div[OF refl]:\n  \"upcast = ucast\n    \\<Longrightarrow> is_up (upcast :: ('c :: len) word \\<Rightarrow> ('d :: len) word)\n    \\<Longrightarrow> (upcast x div upcast y) = upcast (x div y)\"\n  apply (rule word_unat.Rep_eqD)\n  apply (simp only: unat_div unat_ucast_upcast)\n  done\n\nlemma ucast_up_eq_0[OF refl]:\n  \"upcast = ucast\n    \\<Longrightarrow> is_up (upcast :: ('c :: len) word \\<Rightarrow> ('d :: len) word)\n    \\<Longrightarrow> (upcast x = 0) = (x = 0)\"\n  by (metis word_unat.Rep_inject unat_ucast_upcast ucast_0)\n\nlemma ucast_down_bitwise[OF refl]:\n  \"dcast = ucast\n    \\<Longrightarrow> (bitOR (dcast x) (dcast y)) = dcast (bitOR x y)\"\n  \"dcast = ucast\n    \\<Longrightarrow> (bitAND (dcast x) (dcast y)) = dcast (bitAND x y)\"\n  \"dcast = ucast\n    \\<Longrightarrow> (bitXOR (dcast x) (dcast y)) = dcast (bitXOR x y)\"\n  \"dcast = ucast\n    \\<Longrightarrow> is_down (dcast :: ('a :: len) word \\<Rightarrow> ('b :: len) word)\n    \\<Longrightarrow> (bitNOT (dcast x)) = dcast (bitNOT x)\"\n  by (auto intro!: word_eqI simp add: word_size nth_ucast word_ops_nth_size\n      is_down_def target_size_def source_size_def)\n\nlemma ucast_down_shiftl[OF refl]:\n  \"dcast = ucast\n    \\<Longrightarrow> is_down (dcast :: ('a :: len) word \\<Rightarrow> ('b :: len) word)\n    \\<Longrightarrow> dcast (x << n) = dcast x << n\"\n  apply clarsimp\n  apply (rule word_eqI)\n  apply (simp add: word_size nth_shiftl nth_ucast)\n  apply (simp add: is_down_def source_size_def target_size_def word_size)\n  apply auto\n  done\n\nlemma ucast_up_down_shiftr[OF refl]:\n  \"dcast = ucast\n    \\<Longrightarrow> is_down (dcast :: ('a :: len) word \\<Rightarrow> ('b :: len) word)\n    \\<Longrightarrow> dcast (ucast x >> n) = x >> n\"\n  apply clarsimp\n  apply (rule word_eqI)\n  apply (simp add: word_size nth_shiftr nth_ucast)\n  apply (simp add: is_down_def source_size_def target_size_def word_size)\n  apply (auto dest: test_bit_size simp: word_size)\n  done\n\nlemma ucast_up_sless_disgusting[OF refl]:\n  \"(upcast :: ('c :: len) word \\<Rightarrow> ('d :: len) word) = ucast\n    \\<Longrightarrow> len_of TYPE('c) < len_of TYPE('d)\n    \\<Longrightarrow> (upcast x <s upcast y) = (x < y)\"\n  apply (clarsimp simp: word_sless_msb_less msb_nth nth_ucast\n                        word_less_nat_alt unat_ucast_upcast\n                        is_up_def source_size_def target_size_def word_size)\n  apply (auto dest: test_bit_size simp: word_size)\n  done\n\nlemma ucast_up_sle_disgusting[OF refl]:\n  \"(upcast :: ('c :: len) word \\<Rightarrow> ('d :: len) word) = ucast\n    \\<Longrightarrow> len_of TYPE('c) < len_of TYPE('d)\n    \\<Longrightarrow> (upcast x <=s upcast y) = (x \\<le> y)\"\n  apply (clarsimp simp: word_sle_msb_le msb_nth nth_ucast\n                        word_le_nat_alt unat_ucast_upcast\n                        is_up_def source_size_def target_size_def word_size)\n  apply (auto dest: test_bit_size simp: word_size)\n  done\n\n(* Corres tactic *)\n\nML {*\n(* Used to decode Cogent Var indices *)\nfun decode_isa_nat @{term \"0 :: nat\"} = 0\n  | decode_isa_nat (@{term Suc} $ n) = decode_isa_nat n + 1\n  | decode_isa_nat n = HOLogic.dest_number n |> snd\n\nfun TRY_FST tac1 tac2 st = (tac2 ORELSE ((DETERM tac1) THEN tac2)) st\nfun TRY_FST_N tac1 tac2 st = (tac2 ORELSE (tac1 THEN tac2)) st\nfun TRY_MORE_FST tac1 tac2 st = (tac2 ORELSE ((DETERM tac1) THEN (TRY_MORE_FST tac1 tac2))) st\n\n(* Determine whether a Cogent type contains a TFun anywhere.\n * This is used as a crude heuristic for applying corres_let_gets_propagate. *)\nfun Cogent_type_contains_TFun (Const (@{const_name TFun}, _)) = true\n  | Cogent_type_contains_TFun (Abs (_, _, t)) = Cogent_type_contains_TFun t\n  | Cogent_type_contains_TFun (f $ x) = Cogent_type_contains_TFun f orelse Cogent_type_contains_TFun x\n  | Cogent_type_contains_TFun _ = false\n\n(* Matches within a typing judgement. *)\nfun Cogent_typing_returns_TFun (@{term Trueprop} $\n                                (Const (@{const_name typing}, _) $ tenv $ kind $ env $ expr $ typ)) =\n      Cogent_type_contains_TFun typ\n  | Cogent_typing_returns_TFun t = raise TERM (\"Cogent_typing_returns_TFun: not a typing rule\", [t])\n\n(* Number of expected nondet_monad statements for each Cogent atom in a Let. *)\nfun atom_stmts @{const_name Var}     = SOME 1\n  | atom_stmts @{const_name Prim}    = NONE\n  | atom_stmts @{const_name App}     = SOME 2\n  | atom_stmts @{const_name Con}     = SOME 1\n  | atom_stmts @{const_name Promote} = SOME 1\n  | atom_stmts @{const_name Struct}  = SOME 1\n  | atom_stmts @{const_name Unit}    = SOME 1\n  | atom_stmts @{const_name Lit}     = SOME 1\n  | atom_stmts @{const_name Cast}    = SOME 1\n  | atom_stmts @{const_name Tuple}   = SOME 1\n  | atom_stmts @{const_name Esac}    = SOME 1\n  | atom_stmts @{const_name Fun}     = SOME 1\n  | atom_stmts @{const_name AFun}    = SOME 1\n  (* Let (Put...) is handled outside of corres_let_tac. *)\n  | atom_stmts _ = NONE\nfun sigil_atom_stmts @{const_name Member} Unboxed = SOME 1\n  | sigil_atom_stmts @{const_name Member} _       = SOME 2\n  | sigil_atom_stmts _ _ = NONE\nfun rec_sigil (Const (@{const_name TRecord}, _) $ _ $ @{term Unboxed}) = SOME Unboxed\n  | rec_sigil (Const (@{const_name TRecord}, _) $ _ $ @{term ReadOnly}) = SOME ReadOnly\n  | rec_sigil (Const (@{const_name TRecord}, _) $ _ $ @{term Writable}) = SOME Writable\n  | rec_sigil _ = NONE\n\n(* Guess the number of statements for this atom.\n * \"Member (Var 0) 0\" is passed as {head = Member, args = [Var 0, 0]}.\n * The type env is used to distinguish unboxed and boxed member accesses. *)\nfun atom_stmts' (head : string) (args : term list) (env : term) =\n  case atom_stmts head of SOME n => SOME n | NONE => (case (head, args)\n    of (@{const_name Member}, Const (@{const_name Var}, _) $ n :: _) => let\n    val ty = case nth (HOLogic.dest_list env) (decode_isa_nat n) of\n      (Const (@{const_name Some}, _) $ ty) => ty | t => raise TERM (\"atom_stmts': Gamma none\", [t])\n    val sg = case rec_sigil ty of SOME s => s | _ => raise TERM (\"atom_stmts': no sig\", [ty])\n  in sigil_atom_stmts head sg end\n    | (@{const_name Prim}, primop :: _) => let\n    val is_guarded = case head_of primop of @{const \"LShift\"} => true\n        | @{const \"RShift\"} => true | @{const \"Divide\"} => true\n        | @{const \"Mod\"} => true | _ => false\n  in if is_guarded then SOME 2 else SOME 1 end\n    | _ => NONE)\n\n(* Inspect a \"corres ...\" subgoal. *)\nfun dest_corres_prop prop =\n    case prop of\n         @{term Trueprop} $ (Const (@{const_name \"update_sem_init.corres\"}, _) $\n                               _ $ _ $ (* locale parameters *)\n                               srel $ cogent $ m $ xi $ gam $ Xi $ Gam $ si $ s) =>\n           SOME (srel, cogent, m, xi, gam, Xi, Gam, si, s)\n       | _ => NONE\nfun dest_corres_goal goal_num st =\n  if Thm.nprems_of st < goal_num then NONE else\n  Logic.concl_of_goal (Thm.prop_of st) goal_num |> dest_corres_prop\n\n(* Guess the C types mentioned in a rule. This can reduce the amount of\n * val_rel and type_rels that we need to unfold.\n * Ideally, this should be tracked in the lemma buckets. *)\n\nfun scrape_C_types thm = let\n    fun filter_Const P (Const (c_name, _)) = if P c_name then [c_name] else []\n      | filter_Const P (f $ x) = filter_Const P f @ filter_Const P x\n      | filter_Const P (Abs (_, _, t)) = filter_Const P t\n      | filter_Const _ _ = []\n    fun c_type_name str = String.tokens (fn x => x = #\".\") str\n                          |> filter (String.isSuffix \"_C\") |> take 1\n  in Thm.prop_of thm\n     |> filter_Const (c_type_name #> null #> not)\n     |> map c_type_name |> List.concat\n     |> distinct (op =)\n  end\n\n(* Apply a conversion to the n'th arg in the concl of the chosen subgoal. *)\nfun nth_arg_conv_tac n ngoal ctxt conv st = if Thm.nprems_of st < ngoal then no_tac st else\n  let val subgoal = Logic.get_goal (Thm.prop_of st) ngoal\n      val all_vars = length (strip_all_vars subgoal)\n      val imps = length (Logic.strip_imp_prems (strip_all_body subgoal))\n      val goal_concl = Logic.concl_of_goal (Thm.prop_of st) ngoal\n  in\n  Conv.gconv_rule\n    (Utils.nth_arg_conv n conv\n     |> (if fst (strip_comb goal_concl) = @{term Trueprop} then Conv.arg_conv else I)\n     |> Conv.concl_conv imps\n     |> (fn conv => Conv.params_conv all_vars (K conv) ctxt)) ngoal st\n  |> Seq.succeed\n  end\n  handle CTERM _ => no_tac st\n\n(* Remove \"val_rel a a'\" assumptions if a' does not appear anywhere else in the subgoal.\n   Special case for appearance within corres propositions - ignore elements of \\<gamma>\n   that are not given types in \\<Gamma>. *)\nval val_rel_thin_tac = SUBGOAL (fn (goal, n) => let\n  val hyps = Logic.strip_assums_hyp goal\n  val concl = Logic.strip_assums_concl goal\n  fun match_xi_bvars (Const (@{const_name Cons}, _) $ _ $ xs)\n          (Const (@{const_name Cons}, _) $ Const (@{const_name None}, _) $ ys) = match_xi_bvars xs ys\n    | match_xi_bvars (Const (@{const_name Cons}, _) $ x $ xs)\n          (Const (@{const_name Cons}, _) $ y $ ys) = maps spot_bvars [x, y] @ match_xi_bvars xs ys\n    | match_xi_bvars xs ys = maps spot_bvars [xs, ys]\n  and spot_bvars t = case (dest_corres_prop t, t) of\n    (SOME (srel, cogent, m, xi, gam, Xi, Gam, si, s), _)\n        => maps spot_bvars [srel, cogent, m, xi, Xi, si, s] @ match_xi_bvars gam Gam\n  | (NONE, f $ x) => spot_bvars f @ spot_bvars x\n  | (NONE, Abs (_, _, bd)) => map (fn x => x - 1) (filter (fn x => x > 0) (spot_bvars bd))\n  | (NONE, Bound n) => [n]\n  | _ => []\n  val used_bvars = (maps spot_bvars (concl :: hyps))\n    |> map (fn x => (x, ())) |> Inttab.make_list\n  fun keep (@{term Trueprop} $ (Const (@{const_name val_rel}, _) $ _ $ Bound n))\n        = (Inttab.lookup used_bvars n <> SOME [()])\n    | keep _ = true\n  val drops = filter_out (keep o fst) (hyps ~~ (0 upto length hyps - 1))\n    |> map snd |> rev\n  fun thin i = (rotate_tac i n THEN etac thin_rl n THEN rotate_tac (~ i) n)\n  in EVERY (map thin drops) end)\n\nfun corres_tac ctxt\n               (typing_tree : thm Tree)\n               (fun_defs : thm list)\n               (absfun_corres : thm list)\n               (fun_corres : thm list)\n               (corres_if: thm)\n               (corres_esac: thm list)\n               (val_rel_simps : thm list)\n               (type_rel_simps : thm list)\n               (tag_enum_defs : thm list)\n               (LETBANG_TRUE_def: thm)\n               (list_to_map_simps: thm list)\n               (verbose : bool)\n               : tactic =\nlet\n\n  fun corres_Cogent_head goal_num st =\n    Option.map (#2 #> strip_comb #> fst #> dest_Const #> fst) (dest_corres_goal goal_num st)\n\n  fun get_thm nm = Proof_Context.get_thm ctxt nm;\n  fun get_thms nm = Proof_Context.get_thms ctxt nm;\n\n  (* Basic rules. *)\n  val corres_let = get_thm \"corres_let\";\n  val corres_nested_let = get_thm \"corres_nested_let\";\n  val corres_let_propagate = get_thm \"corres_let_gets_propagate\";\n  val corres_letbang = get_thm \"corres_letbang\";\n  val corres_app_concrete = get_thm \"corres_app_concrete\";\n  val corres_var = get_thm \"corres_var\";\n  val corres_con = get_thm \"corres_con\";\n  val corres_lit = get_thm \"corres_lit\";\n  val corres_prim1 = get_thm \"corres_prim1\";\n  val corres_prim2 = get_thm \"corres_prim2\";\n  val corres_prim2_partial_right = get_thm \"corres_prim2_partial_right\";\n  val corres_prim2_partial_left = get_thm \"corres_prim2_partial_left\";\n  val eval_prim_simps = @{thms eval_prim_u_def\n    ucast_down_add ucast_down_mult up_ucast_inj_eq\n    ucast_down_minus ucast_up_less ucast_up_lesseq\n    ucast_down_bitwise[symmetric] ucast_down_shiftl unat_ucast_upcast\n    ucast_up_down_shiftr ucast_id\n    ucast_up_div ucast_up_mod ucast_up_eq_0 checked_div_def\n    ucast_up_sle_disgusting ucast_up_sless_disgusting\n    is_up_def is_down_def source_size_def \n    target_size_def word_size ucast_down_ucast_id\n    };\n  val eval_prim_ineq_guard_simps = @{thms word_less_nat_alt word_le_nat_alt}\n  val corres_unit = get_thm \"corres_unit\";\n  val corres_fun = get_thm \"corres_fun\";\n  val corres_afun = get_thm \"corres_afun\";\n  val corres_cast = get_thms \"corres_cast\";\n  val corres_struct = get_thm \"corres_struct\";\n  val corres_promote = get_thm \"corres_promote\";\n  val corres_let_put_unboxed = get_thm \"corres_let_put_unboxed'\";\n  val corres_no_let_put_unboxed = get_thm \"corres_no_let_put_unboxed'\";\n\n  (* Type-specialised rule buckets. *)\n  val net_resolve_tac = Tactic.build_net #> resolve_from_net_tac ctxt\n  val corres_case_rule = Case.get ctxt |> net_resolve_tac;\n  val corres_member_boxed_rule = MemberReadOnly.get ctxt |> net_resolve_tac;\n  val corres_take_boxed_rule = TakeBoxed.get ctxt |> net_resolve_tac;\n  val corres_take_unboxed_rule = TakeUnboxed.get ctxt |> net_resolve_tac;\n  val corres_put_boxed_rule = PutBoxed.get ctxt |> net_resolve_tac;\n  val corres_let_put_boxed_rule = LetPutBoxed.get ctxt |> net_resolve_tac;\n\n  (* Miscellaneous rules. *)\n  val bind_assoc_sym = @{thm bind_assoc[symmetric]};\n  val recguard_true_rule = get_thm \"condition_true_pure\";\n\n  val type_rel_simps = type_rel_simps @ TypeRelSimp.get ctxt;\n  val val_rel_simps_prim = @{thms val_rel_word}\n    @ [get_thm \"val_rel_bool_t_C_def\"]\n  val val_rel_simps = val_rel_simps @ ValRelSimp.get ctxt;\n  fun make_thm_index guess thms = let\n      val nmths = map swap (maps (fn t => map (pair t) (guess t)) thms)\n    in Symtab.make_list nmths end\n  fun lookup_thm_index table = List.mapPartial (Symtab.lookup table) #> List.concat #> distinct Thm.eq_thm\n  val type_rel_index = make_thm_index scrape_C_types type_rel_simps\n  val val_rel_index = make_thm_index guess_val_rel_type val_rel_simps\n\n  (* Basic tactics. *)\n  fun SOLVES' tac = fn n => SOLVES (tac n);\n  fun TRY' tac = fn n => TRY (tac n);\n  val simp = asm_full_simp_tac ctxt;\n  val subgoal_simp = TRY' (SOLVES' simp);\n  fun simp_add thms = asm_full_simp_tac (add_simps thms ctxt);\n  fun subgoal_simp_add thms = TRY' (SOLVES' (simp_add thms));\n  fun fastforce_add thms = Clasimp.fast_force_tac (add_simps thms ctxt);\n  fun clarsimp_add thms = Clasimp.clarsimp_tac (add_simps thms ctxt);\n  fun subst thms = EqSubst.eqsubst_tac ctxt [0] thms;\n  val rule = rtac;\n  val rules = resolve_tac ctxt;\n\n  (* Common simpsets. *)\n  val val_rel_simp_ctxt = ctxt addsimps val_rel_simps\n  val type_rel_simp_ctxt = ctxt addsimps type_rel_simps\n  fun subgoal_val_rel_simp_add thms = TRY' (val_rel_thin_tac\n      THEN' SOLVES' (asm_full_simp_tac (val_rel_simp_ctxt addsimps thms))) \n  fun subgoal_type_rel_simp_add thms = TRY' (SOLVES' (asm_full_simp_tac (type_rel_simp_ctxt addsimps thms)))\n  fun subgoal_val_rel_clarsimp_add thms = TRY' (val_rel_thin_tac\n      THEN' SOLVES' (Clasimp.clarsimp_tac (val_rel_simp_ctxt addsimps thms)))\n\n  fun real_goal_of (@{term Pure.imp} $ _ $ t) = real_goal_of t\n    | real_goal_of (@{term Trueprop} $ t) = real_goal_of t\n    | real_goal_of (Const (@{const_name Pure.all}, _) $ Abs (x, ty, t)) = betapply (real_goal_of t, Free (x, ty))\n    | real_goal_of t = t\n\n  (* Apply an abstract function corres rule.\n   * These rules may come in all shapes and sizes; try to solve their assumptions by simp. *)\n  fun apply_absfun absfun_thm st =\n    if exists_subterm (fn t => is_const @{const_name measure_call} t) (Thm.prop_of st)\n    then (* resolve AutoCorres' \"measure_call\" construct *)\n         st |>\n         (rule (get_thm \"corres_measure_call_subst\") 1\n          THEN\n          (fn st => (case Logic.concl_of_goal (Thm.prop_of st) 1 |> real_goal_of of\n                       Const (@{const_name \"monad_mono\"}, _) $ Abs (_ (* measure var *), _, call) =>\n                         case fst (strip_comb call) of\n                           Const (f, _) => rule (get_thm (Long_Name.base_name f ^ \"_mono\")) 1 st)\n                    handle Match => raise TERM (\"Corres_Tac: failed to resolve measure_call\",\n                                                [Logic.concl_of_goal (Thm.prop_of st) 1]))\n          THEN\n          (rule absfun_thm\n           THEN_ALL_NEW\n           (SOLVES' (val_rel_thin_tac THEN'\n                      (rule @{thm order_refl} ORELSE'\n                       simp_add (type_rel_simps @ val_rel_simps @ @{thms recguard_dec_def}))))) 1\n         )\n    else\n         st |>\n         (rule absfun_thm\n          THEN_ALL_NEW\n          (SOLVES' (val_rel_thin_tac THEN' simp_add (type_rel_simps @ val_rel_simps @ @{thms recguard_dec_def})))) 1\n\n  (* Strip the recursion guard from recursive function bodies.\n   * We try to simp away the guard condition. *)\n  fun simp_recguard_tac n st =\n    case dest_corres_goal n st of\n       NONE => raise THM (\"corres_tac/simp_recguard_tac: expected a corres subgoal here\", 0, [st])\n     | SOME (_, _, c_def, _, _, _, _, _, _) =>\n         (case strip_comb c_def of\n             (Const (@{const_name condition}, _), _) =>\n               (case (if verbose then tracing \"Proving: recursion guard\\n\" else ();\n                      subst [recguard_true_rule] n THEN SOLVES (simp n)) st |> Seq.pull of\n                   SOME (st', _) => Seq.succeed st'\n                 | NONE => raise THM (\"corres_tac/simp_recguard_tac: failed to discharge recursion guard\\n\", 0, [st]))\n           | _ => all_tac st);\n\n  (* Prove corres recursively. *)\n  fun corres_tac_rec typing_tree depth = let\n     fun print msg st = ((if verbose then tracing (String.implode (replicate (depth*2) #\" \") ^ msg ^ \"\\n\") else ()); Seq.single st);\n     fun tree_nth nth = List.nth (tree_rest typing_tree, nth);\n     fun rule_tree nth n st = TRY (TRY_FST (simp n) (rule (tree_hd (tree_nth nth)) n) |> SOLVES) st\n             handle Subscript => (print \"Warning: rule_tree failed\" THEN no_tac) st;\n     fun corres_tac_nth nth st = corres_tac_rec (tree_nth nth) (depth+1) st;\n\n     fun tree_nth' tree nth = List.nth (tree_rest tree, nth);\n     fun rule_tree' tree nth n st = rule (tree_hd (tree_nth' tree nth)) n st\n             handle Subscript => (print \"Warning: rule_tree' failed\" THEN no_tac) st;\n\n     (* For Let (Fun...) and similar constructs, we need to remember the value of the Fun\n      * so that we can apply the corres lemma for that function. *)\n     fun apply_corres_let n st =\n       (if Cogent_typing_returns_TFun (Thm.prop_of (tree_hd (tree_nth 1))) (* check the type of the bound-expr *)\n        then (print \"Debug: using corres_let_propagate\" THEN rule corres_let_propagate n) st\n        else rule corres_let n st\n       ) handle Subscript => (print \"Warning: tree_nth failed in apply_corres_let\" THEN no_tac) st\n\n     (* Process a program of the form (Let x y...).\n      * While x is guaranteed to be an atomic expression, atoms may translate\n      * to more than one statement in the C monad.\n      * For two-statement atoms, we use bind_assoc to pull out the statement pair\n      * before continuing.\n      *)\n     fun corres_let_tac n st =\n      (case dest_corres_goal n st of\n          SOME (_, Const (@{const_name Cogent.Let}, _) $ lhs $ rhs, _, _, _, _, env, _, _) =>\n          (case strip_comb lhs of\n            (Const (lhs_head, _), args) =>\n              (case atom_stmts' lhs_head args env of\n                  SOME 1 => apply_corres_let n\n                                THEN print (\"corres_let: \" ^ lhs_head)\n                               THEN rule_tree 0 n\n                              THEN rule_tree 1 n\n                             THEN TRY (corres_tac_nth 1)\n                            THEN TRY (corres_tac_nth 2)\n                | SOME 2 => subst [bind_assoc_sym] n\n                            THEN apply_corres_let n\n                                THEN print (\"corres_let: \" ^ lhs_head)\n                               THEN rule_tree 0 n\n                              THEN rule_tree 1 n\n                             THEN TRY (corres_tac_nth 1)\n                            THEN TRY (corres_tac_nth 2)\n                | _ => no_tac)\n            | _ => no_tac)\n        | _ => no_tac) st;\n\n      (* Check the head of the Cogent program before applying a tactic.\n       * This is useful when the tactic doesn't fail quickly (eg. for type-specialised rule buckets). *)\n      fun check_Cogent_head head tac st =\n        case corres_Cogent_head 1 st of\n           NONE => tac st (* not sure if we'd expect this to work *)\n         | SOME head' => if head = head' then tac st else no_tac st;\n    in\n      (fn t => case corres_Cogent_head 1 t of SOME h => print (\"Proving: \" ^ h) t | _ => all_tac t)\n      THEN\n      (* Evaluate Cogent environment lookups (ie. list lookups) eagerly *)\n      ((nth_arg_conv_tac 7 (* \\<gamma> *) 1 ctxt (Simplifier.rewrite ctxt)\n       THEN nth_arg_conv_tac 9 (* \\<Gamma> *) 1 ctxt (Simplifier.rewrite ctxt))\n       THEN\n       (* Prune val_rel assumptions and variables. *)\n       val_rel_thin_tac 1 THEN prune_params_tac ctxt\n       THEN\n       ((rule corres_var 1\n         THEN print \"corres_var\"\n         THEN subgoal_simp 1)\n\n        ORELSE\n        (rule corres_unit 1\n         THEN print \"corres_unit\"\n         THEN subgoal_val_rel_simp_add [] 1)\n\n        ORELSE\n        (rule corres_con 1\n         THEN print \"corres_con\"\n         THEN subgoal_val_rel_simp_add [] 1)\n\n        ORELSE\n        (rule corres_lit 1\n         THEN print \"corres_lit\"\n         THEN subgoal_val_rel_simp_add [] 1)\n\n        ORELSE\n        (rule corres_prim1 1\n         THEN print \"corres_prim (unary)\"\n         THEN val_rel_thin_tac 1 THEN fastforce_add (val_rel_simps_prim @ eval_prim_simps) 1)\n\n        ORELSE\n        (rule corres_prim2 1\n         THEN print \"corres_prim (binary)\"\n         THEN val_rel_thin_tac 1 THEN fastforce_add (val_rel_simps_prim @ eval_prim_simps) 1)\n\n        ORELSE\n        (rule corres_prim2_partial_right 1\n         THEN print \"corres_prim (binary, partial, right)\"\n         THEN (val_rel_thin_tac THEN' simp_add (eval_prim_simps @ val_rel_simps)\n             THEN_ALL_NEW simp_add (eval_prim_simps @ eval_prim_ineq_guard_simps)) 1\n         THEN subgoal_val_rel_simp_add (eval_prim_simps @ eval_prim_ineq_guard_simps) 1\n        )\n\n        ORELSE\n        (rule corres_prim2_partial_left 1\n         THEN print \"corres_prim (binary, partial, left)\"\n         THEN (val_rel_thin_tac THEN' simp_add (eval_prim_simps @ val_rel_simps)\n             THEN_ALL_NEW simp_add (eval_prim_simps @ eval_prim_ineq_guard_simps)) 1\n         THEN subgoal_val_rel_simp_add (eval_prim_simps @ eval_prim_ineq_guard_simps) 1\n        )\n\n        ORELSE\n        (rule corres_fun 1\n         THEN print \"corres_fun\"\n         THEN subgoal_val_rel_simp_add [] 1)\n\n        ORELSE\n        (rule corres_afun 1\n         THEN print \"corres_afun\"\n         THEN subgoal_val_rel_simp_add [] 1)\n\n        ORELSE\n        ((simp_tac (put_simpset HOL_basic_ss ctxt addsimps list_to_map_simps) 1)\n         THEN rule corres_struct 1\n         THEN print \"corres_struct\"\n         THEN subgoal_val_rel_simp_add [] 1)\n\n        ORELSE\n        (rules corres_cast 1\n         THEN print \"corres_cast\"\n         THEN rule_tree 0 1\n         THEN subgoal_simp 1)\n\n        ORELSE check_Cogent_head @{const_name App}\n        (((fn n => rule corres_app_concrete n\n                   THEN print \"corres_app_concrete\"\n                   THEN simp n THEN simp n\n                   THEN rules fun_corres n)\n          THEN_ALL_NEW subgoal_simp_add (@{thm recguard_dec_def} :: fun_corres)) 1)\n\n        ORELSE check_Cogent_head @{const_name App}\n        (APPEND_LIST (map apply_absfun absfun_corres)\n         THEN print \"corres_app_abstract\")\n\n        ORELSE\n        (rule corres_promote 1\n         THEN print \"corres_promote\"\n         THEN TRY (TRY_FST (simp 1) (rule_tree' (tree_nth 0) 0 1) |> SOLVES)\n         THEN subgoal_val_rel_clarsimp_add [] 1)\n\n        ORELSE\n        (rules corres_esac 1\n         THEN print \"corres_esac\"\n            THEN subgoal_simp 1\n           THEN subgoal_simp 1\n          THEN subgoal_simp 1\n         THEN subgoal_val_rel_simp_add [] 1\n\n        ORELSE check_Cogent_head @{const_name Member}\n        (corres_member_boxed_rule 1\n         THEN print \"corres_member_boxed\"\n               THEN rule_tree 0 1\n              THEN subgoal_simp 1\n             THEN subgoal_simp 1\n            THEN subgoal_type_rel_simp_add [] 1\n           THEN subgoal_type_rel_simp_add [] 1\n          THEN rule_tree 0 1\n         THEN TRY (TRY_FST (simp 1) (rule_tree' (tree_nth 0) 0 1) |> SOLVES))\n\n        ORELSE\n        (rule (Proof_Context.get_thm ctxt \"corres_member_unboxed\") 1\n         THEN subgoal_val_rel_clarsimp_add [] 1)\n\n        ORELSE check_Cogent_head @{const_name Take}\n        (corres_take_unboxed_rule 1\n         THEN print \"corres_take_unboxed\"\n                    THEN subgoal_simp 1\n                   THEN rule_tree 0 1\n                  THEN subgoal_val_rel_simp_add [] 1\n                 THEN subgoal_type_rel_simp_add [] 1\n                THEN subgoal_type_rel_simp_add [] 1\n               THEN TRY (TRY (simp 1) THEN SOLVES (rule (tree_hd typing_tree) 1))\n              THEN rule_tree 1 1\n             THEN rule_tree 3 1\n            THEN rule_tree 2 1\n           THEN subgoal_simp 1\n          THEN TRY (corres_tac_nth 3))\n\n        ORELSE check_Cogent_head @{const_name Take}\n        (corres_take_boxed_rule 1\n         THEN print \"corres_take_boxed\"\n                    THEN subgoal_simp 1\n                   THEN rule_tree 0 1\n                  THEN subgoal_val_rel_simp_add [] 1\n                 THEN subgoal_type_rel_simp_add [] 1\n                THEN subgoal_type_rel_simp_add [] 1\n               THEN TRY (TRY_FST (simp 1) (SOLVES (rule (tree_hd typing_tree) 1)))\n              THEN rule_tree 1 1\n             THEN rule_tree 3 1\n            THEN rule_tree 2 1\n           THEN subgoal_simp 1\n          THEN TRY (corres_tac_nth 3))\n\n        ORELSE\n        (rule corres_if 1\n         THEN print \"corres_if\"\n             THEN rule_tree 0 1\n            THEN rule_tree 1 1\n           THEN subgoal_val_rel_simp_add [] 1\n          THEN TRY (corres_tac_nth 2)\n         THEN TRY (corres_tac_nth 3))\n\n        ORELSE check_Cogent_head @{const_name Let}\n        (rule corres_let_put_unboxed 1\n         THEN print \"corres_put_unboxed\"\n               THEN subgoal_simp 1\n              THEN subgoal_simp 1\n             THEN rule_tree 0 1\n            THEN rule_tree 1 1\n           THEN subgoal_val_rel_clarsimp_add [] 1\n          THEN TRY (corres_tac_nth 2))\n\n        ORELSE check_Cogent_head @{const_name Put}\n        (rule corres_no_let_put_unboxed 1\n         THEN print \"corres_put_unboxed (no let)\"\n             THEN subgoal_simp 1\n            THEN subgoal_simp 1\n           THEN TRY (TRY (simp 1) THEN SOLVES (rule (tree_hd typing_tree) 1))\n          THEN subgoal_val_rel_clarsimp_add [] 1)\n\n        ORELSE check_Cogent_head @{const_name Let}\n        (corres_let_put_boxed_rule 1\n         THEN print \"corres_let_put_boxed\"\n                  THEN rule_tree 0 1\n                 THEN subgoal_simp 1\n                THEN subgoal_type_rel_simp_add [] 1\n               THEN subgoal_simp 1\n              THEN subgoal_simp 1\n             THEN TRY (TRY_FST (simp 1) (SOLVES (rule (tree_hd typing_tree) 1)))\n            THEN rule_tree 1 1\n           THEN subgoal_simp 1\n          THEN TRY (corres_tac_nth 2))\n\n        ORELSE check_Cogent_head @{const_name Put}\n        (corres_put_boxed_rule 1\n         THEN print \"corres_put_boxed\"\n                THEN rule_tree' (tree_nth 0 handle Subscript => error \"tree_nth failed\") 0 1\n               THEN subgoal_simp 1\n              THEN subgoal_type_rel_simp_add [] 1\n             THEN subgoal_simp 1\n            THEN subgoal_simp 1\n           THEN TRY (TRY_FST (simp 1) (SOLVES (rule (tree_hd typing_tree) 1)))\n          THEN subgoal_simp 1)\n\n        ORELSE check_Cogent_head @{const_name Case}\n        (rtac (get_thm \"corres_simp_cond_gets\" RS @{thm iffD2}) 1 THEN\n         (corres_case_rule 1\n            THEN print \"corres_case\"\n                    THEN subgoal_simp 1\n                   THEN subgoal_simp 1\n                  THEN rule_tree 0 1\n                 THEN subgoal_simp 1\n                THEN rule_tree 1 1\n               THEN rule_tree 2 1\n              THEN rule_tree 3 1\n             THEN TRY (corres_tac_nth 2)\n            THEN TRY (corres_tac_nth 3)))\n\n        ORELSE check_Cogent_head @{const_name Let}\n        (rtac corres_nested_let 1\n         THEN print \"corres_let (nested)\"\n             THEN rule_tree 0 1\n            THEN rule_tree 1 1\n           THEN TRY (corres_tac_nth 1)\n          THEN TRY (corres_tac_nth 2))\n\n        ORELSE corres_let_tac 1\n\n        ORELSE check_Cogent_head @{const_name LetBang}\n        ((simp_tac (put_simpset HOL_basic_ss ctxt addsimps [LETBANG_TRUE_def]) 1)\n         THEN\n         rule corres_letbang 1\n         THEN print \"corres_letbang\"\n               THEN rule_tree 0 1\n              THEN rule_tree 1 1\n             THEN rule_tree 3 1\n            THEN subgoal_simp 1\n           THEN TRY (corres_tac_nth 1)\n          THEN TRY (corres_tac_nth 2))\n\n        ORELSE check_Cogent_head @{const_name Split}\n        (rtac (get_thm \"corres_split\") 1\n         THEN print \"corres_split\"\n                 THEN rule_tree 0 1\n                THEN subgoal_val_rel_simp_add [] 1\n               THEN subgoal_simp 1\n              THEN rule_tree 1 1\n             THEN rule_tree 2 1\n            THEN subgoal_val_rel_simp_add [] 1\n           THEN subgoal_val_rel_simp_add [] 1\n          THEN TRY (corres_tac_nth 1))\n      )))\n   end\nin\n  (simp_tac (put_simpset HOL_basic_ss ctxt addsimps fun_defs) 1)\n  THEN simp_recguard_tac 1\n  THEN (fn st => (if verbose then tracing \"Fixing unused variables\\n\" else ();\n                  cogent_C_unused_return_tac ctxt 1 st))\n  THEN corres_tac_rec typing_tree 0\nend\n*}\n\nML{*\nfun peel_two tree =  hd (tree_rest (hd (tree_rest (hd tree))));\n*}\n\n\n\n(* Analyse the program and generate proofs based on its call tree. *)\nML {*\nfun partition _ [] = ([], [])\n  | partition P (x::xs) = let val (ps, ns) = partition P xs in\n                          if P x then (x::ps, ns) else (ps, x::ns) end\n\nfun max a b = if a < b then b else a\nfun maximum [] = error \"maximum: empty list\"\n  | maximum [x] = x\n  | maximum (x::xs) = max x (maximum xs)\n\nfun get_Cogent_funtype ctxt fname = let\n  val simps = Proof_Context.get_thms ctxt \"abbreviated_type_defs\"\n  in\n    Proof_Context.get_thm ctxt (fname ^ \"_type_def\")\n    |> simplify (ctxt addsimps simps)\n  end\n\n(* check whether the function argument type contains a TFun *)\nfun funtype_is_first_order (funtype:term) =\n  case funtype of (Const (@{const_name Pair}, _) $ _ $\n                    (Const (@{const_name Pair}, _) $ arg $ _)) =>\n                  not (Cogent_type_contains_TFun arg)\n                | _ => raise TERM (\"Expected a Cogent type signature\", [funtype])\n\n(* scrape all direct function calls *)\nval get_simple_function_calls = let\n  fun search (Const (@{const_name App}, _) $\n        (Const (@{const_name Fun}, _) $ Const (callee, _) $ _) $ _) = [Long_Name.base_name callee]\n    | search (Const (@{const_name App}, _) $\n        (Const (@{const_name AFun}, _) $ callee $ _) $ _) = [Utils.decode_isa_string callee]\n    | search (f $ x) = search f @ search x\n    | search _ = []\n  in search end\n\n(*\n * Infer a call graph. We assume that the program only has:\n *  - first-order Cogent functions,\n *  - first-order abstract functions, and\n *  - second-order abstract functions with first-order Cogent function arguments.\n *)\ndatatype FunType = AbsFun | CogentFun;\n\n(* Warning: CogentCallTree inlines a full subtree at each call site.\n * If this doesn't scale, we will need more indirection. *)\ndatatype 'a CogentCallOrder = FirstOrderCall of 'a CogentCallTree\n                          | SecondOrderCall of ('a CogentCallTree * (term * 'a CogentCallTree) list)\n     and 'a CogentCallTree = CogentCallTree of ('a * FunType * string * 'a CogentCallOrder list);\n\nfun CogentCallTree_name    (CogentCallTree (_, _, name, _))  = name\nfun CogentCallTree_funtype (CogentCallTree (_, typ, _, _))   = typ\nfun CogentCallTree_data    (CogentCallTree (a, _, _, _))     = a\nfun CogentCallTree_calls   (CogentCallTree (_, _, _, calls)) = calls\n\n(* We need a stack of environments \\<xi> to verify with higher-order absfuns later on.\n * Each such function call increments \\<xi>.\n * Get the stack height and the position of each function in the call tree.\n * Note that a function may appear in multiple environments. *)\nfun calc_call_depth tr = maximum (0 :: map calc_call_order_depth (CogentCallTree_calls tr))\nand calc_call_order_depth (FirstOrderCall f) = calc_call_depth f\n  | calc_call_order_depth (SecondOrderCall (f, args)) =\n       maximum (map calc_call_depth (f::map snd args)) + (if CogentCallTree_funtype f = AbsFun then 1 else 0)\n\n(*\n * FIXME: this only deals with one function (call tree) at a time.\n * If there are multiple entry points, we'd want to handle them simultaneously\n * to avoid redundant \\<xi>'s and subproofs.\n *)\nfun annotate_depth tr = let\n  fun annotate' d (CogentCallTree ((), ty, name, calls)) = let\n    in CogentCallTree (d, ty, name, map (annotate_call' d) calls) end\n  and annotate_call' d (FirstOrderCall f) = FirstOrderCall (annotate' d f)\n    | annotate_call' d (SecondOrderCall (f, args)) = let\n        val d' = if CogentCallTree_funtype f = AbsFun then d-1 else 0\n        in SecondOrderCall (annotate' d f, map (apsnd (annotate' d')) args) end\n  in annotate' (calc_call_depth tr) tr end\n\nfun make_call_tree (Cogent_functions, Cogent_abstract_functions) HO_hints ctxt = let\n  val Cogent_abstract_functions_HO =\n      filter_out (get_Cogent_funtype ctxt #> Thm.prop_of #> Utils.rhs_of_eq #> funtype_is_first_order)\n                 Cogent_abstract_functions\n  val FO_call_graph =\n      Cogent_functions\n      |> map (fn n => (n, Proof_Context.get_thm ctxt (n ^ \"_def\") |> Thm.prop_of |> Utils.rhs_of_eq\n                          |> get_simple_function_calls |> distinct (op =)))\n      |> map (apsnd (filter (fn f => not (exists (fn af => f = af) Cogent_abstract_functions_HO))))\n  val absfun_decls = map (fn name => (name, CogentCallTree ((), AbsFun, name, []))) Cogent_abstract_functions\n  fun func_name (Left f) = f\n    | func_name (Right f) = f\n  fun add_fun (name, FO_callees) table = let\n        fun subtree f = case Symtab.lookup table f of\n                SOME tr => tr\n              | (* assume that we get Cogent_functions in topological order *)\n                NONE => error (\"make_call_tree: \" ^ quote name ^ \" calls \" ^ quote f ^\n                               \" but we don't know anything about it (yet)\")\n        val FO_callees' = FO_callees\n                          |> map (fn f => FirstOrderCall (subtree f))\n        val HO_callees = Symtab.lookup_list HO_hints name\n                         |> map (fn (f, args) => SecondOrderCall (subtree (func_name f), map (apsnd (subtree o func_name)) args))\n      in Symtab.update_new (name, CogentCallTree ((), CogentFun, name, FO_callees' @ HO_callees)) table end\n  in\n    fold add_fun FO_call_graph (Symtab.make absfun_decls)\n  end\n\n(* Obtain the absfuns included in each \\<xi>_n, up to the call tree depth. *)\nfun make_uabsfuns_defs (tr as CogentCallTree (depth, _, _, _)) = let\n      fun collect_absfuns d (CogentCallTree (d', ty, name, calls)) callees =\n            (if d = d' andalso ty = AbsFun then [(AbsFun, name, map CogentCallTree_name callees)] else []) @\n            maps (fn c => case c of\n                  FirstOrderCall t => collect_absfuns d t []\n                | SecondOrderCall (f, args) => collect_absfuns d f (map snd args) @\n                                               maps (fn arg => collect_absfuns d (snd arg) []) args) calls\n    in map (fn d => collect_absfuns d tr []) (0 upto depth) end\n\n(* Define each of the \\<xi>_n. *)\nfun define_uabsfuns (defs : string list list) ctxt : ((term * (string * thm)) list * Proof.context) = let\n  fun define _ [] ctxt = ([], ctxt)\n    | define n (absfuns::defs') ctxt = let\n        val name = \"\\<xi>_\" ^ string_of_int n\n        val typ = @{typ \"(funtyp, abstyp, ptrtyp) uabsfuns\"}\n        val rhs = Const (@{const_name undefined}, typ) (* FIXME *)\n        val (thm, ctxt) = Specification.definition\n              (NONE, ((Binding.name (name ^ \"_def\"), []),\n                      @{mk_term \"?name \\<equiv> ?def\" (name, def)} (Free (name, typ), rhs))) ctxt\n        val (thms, ctxt) = define (n+1) defs' ctxt\n        in (thm::thms, ctxt) end\n  in define 0 defs ctxt end\n\n(* Convenience wrapper. *)\nfun define_uabsfuns' tr ctxt =\n  make_uabsfuns_defs tr\n  |> map (map #2 o filter (fn (funtyp, _, _) => funtyp = AbsFun))\n  |> (fn defs => define_uabsfuns defs ctxt)\n  |> snd\n\nfun isAutoCorresFunRec ctxt f =\n  (Proof_Context.get_thms ctxt (f ^ \"'.simps\"); true)\n  handle ERROR _ => false\n\n(* Manufacture fake corres rules for first-order absfuns. *)\nfun generate_FO_absfun_corres (xi:term) ctxt (fname:string) = let\n  val abs_rel = Syntax.read_term ctxt \"abs_rel\"\n  val state_rel = Syntax.read_term ctxt \"state_rel\"\n  val Xi = Syntax.read_term ctxt \"\\<Xi> :: string \\<Rightarrow> poly_type\"\n  val _ = if isAutoCorresFunRec ctxt fname then\n            error (\"Corres_Tac: expected first-order function call for \" ^ quote fname ^ \" but it is recursive\")\n          else ()\n  val cfun = Syntax.read_term ctxt (fname ^ \"'\")\n  val prop = @{mk_term \"Trueprop (?abs_rel ?Xi ?state_rel ?fname ?xi ?cfun)\"\n               (abs_rel, Xi, state_rel, fname, xi, cfun)}\n              (abs_rel, Xi, state_rel, Utils.encode_isa_string fname, xi, cfun)\n             |> strip_type |> Syntax.check_term ctxt\n  in\n    Goal.prove ctxt [] [] prop (K (Skip_Proof.cheat_tac ctxt 1)) RS Proof_Context.get_thm ctxt \"afun_corres\"\n  end\n\n(* The same, but for (higher-order absfun, callees) pairs. *)\nfun generate_HO_absfun_corres (xi:term) ctxt (fname:string) (callees:(term * string) list) min_measure = let\n  val corres = Syntax.read_term ctxt \"corres\"\n  val state_rel = Syntax.read_term ctxt \"state_rel\"\n  val Xi = Syntax.read_term ctxt \"\\<Xi> :: string \\<Rightarrow> poly_type\"\n  val cfun = Syntax.read_term ctxt (fname ^ \"'\")\n  val prop = if isAutoCorresFunRec ctxt fname\n    then @{mk_term \"\\<lbrakk> i < length \\<gamma>; val_rel (\\<gamma> ! i) v'; \\<Gamma> ! i = Some (fst (snd (?Xi ?fname))); m \\<ge> ?min_m \\<rbrakk> \\<Longrightarrow>\n                    ?corres ?state_rel (App (AFun ?fname []) (Var i))\n                            (do x \\<leftarrow> ?cfun m v'; gets (\\<lambda>s. x) od) ?xi \\<gamma> ?Xi \\<Gamma> \\<sigma> s\"\n               (corres, Xi, state_rel, fname, xi, cfun, min_m)}\n               (corres, Xi, state_rel, Utils.encode_isa_string fname, xi, cfun,\n                Int.toString min_measure |> Syntax.read_term ctxt)\n    else @{mk_term \"\\<lbrakk> i < length \\<gamma>; val_rel (\\<gamma> ! i) v'; \\<Gamma> ! i = Some (fst (snd (?Xi ?fname))) \\<rbrakk> \\<Longrightarrow>\n                    ?corres ?state_rel (App (AFun ?fname []) (Var i))\n                            (do x \\<leftarrow> ?cfun v'; gets (\\<lambda>s. x) od) ?xi \\<gamma> ?Xi \\<Gamma> \\<sigma> s\"\n               (corres, Xi, state_rel, fname, xi, cfun)}\n               (corres, Xi, state_rel, Utils.encode_isa_string fname, xi, cfun)\n  fun callee_assm (getter, callee) = @{mk_term \"Trueprop (?getter v' = ?callee_tag)\" (getter, callee_tag)}\n                                     (getter, Syntax.read_term ctxt (\"FUN_ENUM_\" ^ callee))\n  fun give_xi_type (t as Const (nm, T)) = (if nm = fst (dest_Const Xi) then Xi else t)\n    | give_xi_type t = t\n  val prop' = map callee_assm callees |> foldr Logic.mk_implies prop\n              |> strip_type |> map_aterms give_xi_type |> Syntax.check_term ctxt\n  in\n    Goal.prove ctxt [\"i\", \"\\<gamma>\", \"\\<Gamma>\", \"v\", \"v'\", \"\\<sigma>\", \"s\", \"m\"] [] prop' (K (Skip_Proof.cheat_tac ctxt 1))\n  end\n\nfun unfold_abbreviatedType_term ctxt (Const (nm, @{typ \"Cogent.type\"}))\n    = if String.isPrefix \"abbreviatedType\" (Long_Name.base_name nm)\n        then Proof_Context.get_thm ctxt (nm ^ \"_def\")\n            |> safe_mk_meta_eq |> Thm.concl_of |> Logic.dest_equals |> snd |> SOME\n        else NONE\n  | unfold_abbreviatedType_term _ _ = NONE\n\n(* Generate and prove corres rules for Cogent functions. *)\nfun make_FO_fun_corres_prop xi_index ctxt fname min_measure = let\n  val read = Syntax.read_term ctxt\n  val Xi = read \"\\<Xi> :: string \\<Rightarrow> poly_type\"\n  fun give_xi_type (t as Const (nm, T)) = (if nm = fst (dest_Const Xi) then Xi else t)\n    | give_xi_type t = t\n  val cfun = read (fname ^ \"'\")\n  val prop = if isAutoCorresFunRec ctxt fname\n    then @{mk_term \"\\<And>a a' \\<sigma> s m. val_rel a a' \\<Longrightarrow> m \\<ge> ?min_m \\<Longrightarrow>\n                   ?corres ?state_rel ?cogent (?cfun m a') ?\\<xi> [a] ?\\<Xi> [Some (fst (snd ?cogent_type))] \\<sigma> s\"\n               (corres, state_rel, cogent, cfun, \\<xi>, \\<Xi>, cogent_type, min_m)}\n               (read \"corres\", read \"state_rel\", read fname, cfun,\n                read (\"\\<xi>_\" ^ Int.toString xi_index), Xi, read (fname ^ \"_type\"),\n                Int.toString min_measure |> Syntax.read_term ctxt)\n    else @{mk_term \"\\<And>a a' \\<sigma> s. val_rel a a' \\<Longrightarrow>\n                   ?corres ?state_rel ?cogent (?cfun a') ?\\<xi> [a] ?\\<Xi> [Some (fst (snd ?cogent_type))] \\<sigma> s\"\n               (corres, state_rel, cogent, cfun, \\<xi>, \\<Xi>, cogent_type)}\n               (read \"corres\", read \"state_rel\", read fname, cfun,\n                read (\"\\<xi>_\" ^ Int.toString xi_index), Xi, read (fname ^ \"_type\"))\n  in prop |> strip_type |> map_aterms give_xi_type |> Syntax.check_term ctxt end\n\n(* Unfold types in corres rules. *)\nfun unfold_Cogent_simps ctxt =\n  Proof_Context.get_thms ctxt \"fst_conv\" @\n  Proof_Context.get_thms ctxt \"snd_conv\" @\n  Proof_Context.get_thms ctxt \"abbreviated_type_defs\"\nfun unfold_Cogent_types ctxt simps fname thm =\n  Local_Defs.unfold ctxt (Proof_Context.get_thms ctxt (fname ^ \"_type_def\") @ simps) thm\n\nfun mapAccumL _ [] acc = ([], acc)\n  | mapAccumL f (x::xs) acc = let val (x', acc') = f x acc\n                                   val (xs', acc'') = mapAccumL f xs acc'\n                              in (x'::xs', acc'') end\n\ntype obligations = (string * FunType * string list * cterm) Symtab.table\n\nfun corres_tree_obligations trs ctxt : obligations = let\n  fun descend (CogentCallTree ((xi_index, _), AbsFun, name, [])) tab = let\n      val thm_name = name ^ \"_corres_\" ^ string_of_int xi_index in\n      if Symtab.defined tab thm_name then (thm_name, tab) else let\n      (* generate a fake corres rule and for interesting reasons throw it away *)\n        val x = generate_FO_absfun_corres (Syntax.read_term ctxt (\"\\<xi>_\" ^ string_of_int xi_index)) ctxt name\n                |> forall_intr_vars\n        in tracing (\"  adding thm \" ^ thm_name);\n          (thm_name, Symtab.update (thm_name, (name, AbsFun, [], Thm.cprop_of x)) tab) end end\n    | descend (CogentCallTree ((xi_index, min_measure), CogentFun, name, callees)) tab = let\n      (* Calls to CogentFuns, which we should prove. *)\n        val thm_name = name ^ \"_corres_\" ^ string_of_int xi_index\n      in if Symtab.defined tab thm_name then (thm_name, tab) else let\n        val (callee_nms, tab) = mapAccumL (fn c => fn tab => case c of\n                FirstOrderCall f => descend f tab\n              | SecondOrderCall (f as CogentCallTree ((fxi_index, fmin_measure), AbsFun, fname, []), args) => let\n                  (* Second-order AbsFun calls are specialised to their callees. *)\n                  val nm = (space_implode \"_\" (fname::map (CogentCallTree_name o snd) args)\n                      ^ \"_corres_\" ^ string_of_int fxi_index)\n                  in if Symtab.defined tab nm then (nm, tab) else let\n                    val tab = fold (snd oo descend) (map snd args) tab\n                    val f_thm = generate_HO_absfun_corres (Syntax.read_term ctxt (\"\\<xi>_\" ^ string_of_int fxi_index))\n                                                   ctxt fname (map (apsnd CogentCallTree_name) args) fmin_measure\n                                |> forall_intr_vars\n                    in tracing (\"  adding thm \" ^ nm);\n                       (nm, Symtab.update (nm, (fname, AbsFun, [], Thm.cprop_of f_thm)) tab) end end\n              | tr' => raise TERM (\"descend: callees: tr': \" ^ @{make_string} tr', [])\n              ) callees tab\n        val prop = make_FO_fun_corres_prop xi_index ctxt name min_measure\n        val _ = tracing (\"  adding thm \" ^ thm_name)\n        in (thm_name, Symtab.update (thm_name, (name, CogentFun, callee_nms, Thm.cterm_of ctxt prop)) tab) end end\n      | descend tr' _ = raise TERM (\"descend: tr': \" ^ @{make_string} tr', [])\n\n  val tab = fold (snd oo descend o snd) (Symtab.dest trs) Symtab.empty\n  in tab end\n\nfun corres_tac_driver corres_tac typing_tree_of ctxt (tab : obligations) thm_name\n  = case Symtab.lookup tab thm_name of SOME (fname, CogentFun, assums, prop) => let\n    val lookup_assums = map (Symtab.lookup tab #> the) assums\n    val (callee_info, callee_abs_info) = lookup_assums\n        |> partition (fn v => #2 v = CogentFun)\n    val (callee_names, callee_abs_names) = (callee_info, callee_abs_info) |> apply2 (map #1)\n    val (callee_thm_props, callee_abs_thm_props) = (callee_info, callee_abs_info) |> apply2 (map #4)\n\n    val type_unfold_simps = unfold_Cogent_simps ctxt\n\n    val fun_defs = Proof_Context.get_thms ctxt (fname ^ \"_def\") @\n                   Proof_Context.get_thms ctxt (fname ^ \"'_def'\") @\n                   Proof_Context.get_thms ctxt (fname ^ \"_type_def\") @\n                   type_unfold_simps\n    val _ = @{trace} (\"corres_tac_driver: Proving \" ^ thm_name,\n        { prop = prop, callee_props = callee_thm_props,\n            callee_abs_props = callee_abs_thm_props })\n\n  in Goal.prove ctxt []\n        (map Thm.term_of (callee_thm_props @ callee_abs_thm_props))\n            (Thm.term_of prop)\n    (fn args => let\n        val callee_thms = take (length callee_thm_props) (#prems args) ~~ callee_names\n                          |> map (fn (assum, name) => unfold_Cogent_types ctxt type_unfold_simps name assum)\n        val callee_abs_thms = drop (length callee_thm_props) (#prems args) ~~ callee_abs_names\n                          |> map (fn (assum, name) => simp_xi ctxt assum |> unfold_Cogent_types ctxt type_unfold_simps name)\n        val _ = @{trace} (\"Assumptions for \" ^ thm_name, callee_thms, callee_abs_thms)\n      in corres_tac (#context args) (peel_two (typing_tree_of fname))\n          fun_defs callee_abs_thms callee_thms end)\n  end\n  | SOME (_, AbsFun, [], _) => @{thm TrueI}\n  | v => error (\"corres_tac_driver: tab contents: \" ^ thm_name ^ \": \" ^ @{make_string} v)\n\nfun finalise (tab : obligations) ctxt thm_tab = let\n    fun to_rsn NONE = Thm.trivial @{cpat \"?P :: prop\"}\n      | to_rsn (SOME thm) = thm\n\n    fun cleanup thm = thm\n        |> (ALLGOALS val_rel_thin_tac\n            THEN prune_params_tac ctxt\n            THEN distinct_subgoals_tac)\n        |> Seq.hd\n\n    fun inner nm ftab =\n     case Symtab.lookup ftab nm of SOME thm => (thm, ftab)\n      | NONE => let\n        val _ = tracing (\"finalise: \" ^ nm)\n        val assum_nms = Symtab.lookup tab nm |> the |> #3\n        val (concr_assums, abs_assums) = partition (fn n => CogentFun = (Symtab.lookup tab n |> the |> #2)) assum_nms\n        val assum_nms = concr_assums @ abs_assums\n        val thm = Symtab.lookup thm_tab nm |> the\n        val (assums, ftab) = mapAccumL inner assum_nms ftab\n        val rthm = case thm of NONE => NONE\n          | SOME t => if Thm.eq_thm (t, @{thm TrueI}) then NONE\n            else SOME ((map to_rsn assums MRS gen_all (Variable.maxidx_of ctxt) t) |> cleanup)\n      in (rthm, Symtab.update (nm, rthm) ftab) end\n\n  in fold (snd oo inner) (Symtab.keys tab) Symtab.empty end\n\nfun all_corres_goals corres_tac typing_tree_of time_limit ctxt (tab : obligations) =\n  let\n    val tl = Time.fromSeconds time_limit\n    fun driver nm = Timing.timing (try (TimeLimit.timeLimit tl\n            (corres_tac_driver corres_tac typing_tree_of ctxt tab))) nm\n        |> (fn (dur, res) => (tracing (\"Time for \" ^ nm ^ \": \" ^ Timing.message dur); res))\n        |> (fn NONE => (tracing (\"Failed: \" ^ nm); (nm, NONE))\n             | SOME thm => (tracing (\"Succeeded: \" ^ nm); (nm, SOME thm)))\n    val res = Par_List.map driver (Symtab.keys tab)\n    val thm_tab = Symtab.make res\n  in thm_tab end\n\n(* Top-level driver that attempts to prove a CogentCallTree.\n * For each function in the tree, it proves a corres theorem and assigns a standard name.\n * If a theorem by that name already exists, that is used instead.\n *\n * The naming scheme is: <fun>_[<funarg1>_<funarg2>_...]_corres_<xi_index>\n * Eg. for f called with function arguments g and h: f_g_h_corres_1\n * These names can be obtained using callee_corres_thms.\n *\n * Known issues:\n *  - Does not handle C recursion guards.\n *  - Does not handle higher-order CogentFuns.\n *  - Should be parallelised.\n *)\nfun corres_tree tr typing_tree_of corres_tac run_proofs skip_initial time_limit ctxt = let\n  fun cache_proof ctxt thm_name (make_thms : unit -> thm list) =\n    (Proof_Context.get_thms ctxt thm_name, ctxt)\n    handle ERROR _ =>\n      Utils.define_lemmas thm_name (make_thms ()) ctxt\n\n  fun mapAccumL _ [] acc = ([], acc)\n    | mapAccumL f (x::xs) acc = let val (x', acc') = f x acc\n                                    val (xs', acc'') = mapAccumL f xs acc'\n                                in (x'::xs', acc'') end\n\n  val type_unfold_simps = unfold_Cogent_simps ctxt\n\n  val skip_ctr = Unsynchronized.ref skip_initial\n  val failed_proofs = Unsynchronized.ref []\n\n  fun descend (CogentCallTree (xi_index, AbsFun, name, [])) ctxt = let\n      (* Simple AbsFun calls. Higher-order calls are handled elsewhere. *)\n        val (thm, ctxt) =\n          cache_proof ctxt (name ^ \"_corres_\" ^ string_of_int xi_index) (fn () =>\n            [generate_FO_absfun_corres (Syntax.read_term ctxt (\"\\<xi>_\" ^ string_of_int xi_index)) ctxt name\n             |> unfold_Cogent_types ctxt type_unfold_simps name])\n        in (CogentCallTree ((xi_index, thm), AbsFun, name, []), ctxt) end\n    | descend (CogentCallTree (xi_index, CogentFun, name, callees)) ctxt = let\n      (* Calls to CogentFuns, which we should prove. *)\n        val (callees', ctxt) = mapAccumL (fn c => fn ctxt => case c of\n                FirstOrderCall f => descend f ctxt |> apfst FirstOrderCall\n              | SecondOrderCall (f as CogentCallTree (fxi_index, AbsFun, fname, []), args) => let\n                  (* Second-order AbsFun calls are specialised to their callees. *)\n                  val (args', ctxt) = mapAccumL descend (map snd args) ctxt\n                  val (f_thm, ctxt) = cache_proof ctxt\n                        (space_implode \"_\" (fname::map (CogentCallTree_name o snd) args) ^ \"_corres_\" ^ string_of_int fxi_index)\n                        (fn () => [generate_HO_absfun_corres (Syntax.read_term ctxt (\"\\<xi>_\" ^ string_of_int fxi_index))\n                                                             ctxt fname (map (apsnd CogentCallTree_name) args) 42\n                                   |> unfold_Cogent_types ctxt type_unfold_simps fname])\n                  in (SecondOrderCall (CogentCallTree ((fxi_index, f_thm), AbsFun, fname, []), map fst args ~~ args'), ctxt) end)\n              callees ctxt\n        val thm_name = name ^ \"_corres_\" ^ string_of_int xi_index\n        val _ = if !skip_ctr > 0 then @{trace} (\"skipping \" ^ string_of_int (!skip_ctr) ^ \" more\") else ()\n        val run_proofs = run_proofs andalso !skip_ctr <= 0\n        val _ = (skip_ctr := !skip_ctr-1)\n        val (thm, ctxt) =\n          cache_proof ctxt thm_name (fn () => let\n            (* Warning: actual proofs ahead. *)\n            val corres = Syntax.read_term ctxt \"corres\"\n            val fun_term = Syntax.read_term ctxt name\n            val fun_type = Syntax.read_term ctxt (name ^ \"_type\")\n            val fun_c = Syntax.read_term ctxt (name ^ \"'\")\n            val state_rel = Syntax.read_term ctxt \"state_rel\"\n            val xi = Syntax.read_term ctxt (\"\\<xi>_\" ^ string_of_int xi_index)\n            val Xi = Syntax.read_term ctxt \"\\<Xi> :: string \\<Rightarrow> poly_type\"\n            val prop = @{mk_term \"\\<And>a a' \\<sigma> s. val_rel a a' \\<Longrightarrow> ?corres ?state_rel ?fun_term (?fun_c a') ?xi [a] ?Xi\n                                                                       [Some (fst (snd ?fun_type))] \\<sigma> s\"\n                         (corres, state_rel, fun_term, fun_c, xi, Xi, fun_type)}\n                         (corres, state_rel, fun_term, fun_c, xi, Xi, fun_type)\n                       |> strip_type |> Syntax.check_term ctxt\n            val (callee_thms, callee_abs_thms) = callees'\n                  |> map (fn call => case call of FirstOrderCall f => f\n                                                | SecondOrderCall (f, _) => f)\n                  |> partition (fn tr => CogentCallTree_funtype tr = CogentFun)\n                  |> apply2 (map (CogentCallTree_data #> snd))\n            val (callee_thms, callee_abs_thms) = (List.concat callee_thms, List.concat callee_abs_thms)\n\n            val fun_defs = Proof_Context.get_thms ctxt (name ^ \"_def\") @\n                           Proof_Context.get_thms ctxt (name ^ \"'_def'\") @\n                           Proof_Context.get_thms ctxt (name ^ \"_type_def\") @\n                           type_unfold_simps\n            val _ = @{trace} (\"cogent_corres_tree: \" ^ (if run_proofs then \"Proving \" else \"Skipping \") ^ thm_name,\n                              { prop = Thm.cterm_of ctxt prop,\n                                callees = callees\n                                          |> map (fn call => case call of FirstOrderCall f => f\n                                                                        | SecondOrderCall (f, _) => f)\n                                          |> map CogentCallTree_name |> commas })\n            fun fallback_thm msg = (warning (\"Failed to prove \" ^ thm_name ^ \"; error: \" ^ msg);\n                                    failed_proofs := thm_name :: !failed_proofs;\n                                    Goal.prove ctxt [] [] prop (K (Skip_Proof.cheat_tac ctxt 1)))\n            val (time, thms) = (fn f => Timing.timing f ()) (fn () =>\n                 [(TimeLimit.timeLimit (Time.fromSeconds time_limit) (fn () =>\n                   (((((Goal.prove ctxt [] [] prop (fn {context, prems} =>\n                     if not run_proofs then Skip_Proof.cheat_tac ctxt 1 else\n                        (corres_tac context (peel_two (typing_tree_of name)) fun_defs\n                                    callee_abs_thms callee_thms))\n                 handle Bind => fallback_thm (@{make_string} Bind))\n                 handle Match => fallback_thm (@{make_string} Match))\n                 handle Option => fallback_thm (@{make_string} Option))\n                 handle THM t => fallback_thm (@{make_string} (THM t)))\n                 handle TERM t => fallback_thm (@{make_string} (TERM t)))\n                 handle ERROR e => fallback_thm (@{make_string} (ERROR e))) ()\n                handle TimeLimit.TimeOut => fallback_thm (@{make_string} TimeLimit.TimeOut))\n                |> unfold_Cogent_types ctxt type_unfold_simps name])\n            val _ = tracing (\"Time for \" ^ thm_name ^ \": \" ^ Timing.message time)\n          in thms end)\n        in (CogentCallTree ((xi_index, thm), CogentFun, name, callees'), ctxt) end\n\n  val (tr', ctxt) = descend tr ctxt\n  val _ = if null (!failed_proofs) then () else warning (\"Failed proofs: \" ^ commas_quote (!failed_proofs))\n  in (tr', ctxt) end\n\n(* Convenience function for getting the expected corres thm names. *)\nfun callee_corres_thms (CogentCallTree (_, _, _, callees)) = callees\n      |> map (fn call => case call of\n                 FirstOrderCall f => (f, CogentCallTree_name f ^ \"_corres_\" ^ string_of_int (CogentCallTree_data f))\n               | SecondOrderCall (f, args) => (f, space_implode \"_\" (map CogentCallTree_name (f :: map snd args)) ^\n                                                  \"_corres_\" ^ string_of_int (CogentCallTree_data f)))\n                  |> partition (fn (tr, _) => CogentCallTree_funtype tr = CogentFun)\n                  |> apply2 (map snd)\n\n(* Assign AutoCorres recursion measures.\n * Each second-order function call involves a trip to the dispatcher,\n * meaning that the measure decreases by 2 instead of 1. *)\nfun calc_call_measure tr = maximum (1 :: map calc_call_order_measure (CogentCallTree_calls tr))\nand calc_call_order_measure (FirstOrderCall f) = 1 + calc_call_measure f\n  | calc_call_order_measure (SecondOrderCall (f, args)) =\n       1 + max (maximum (map (calc_call_measure o snd) args) + 2) (calc_call_measure f)\n\nfun annotate_measure tr = let\n  fun annotate' d (CogentCallTree (x, ty, name, calls)) = let\n    in CogentCallTree ((x, d), ty, name, map (annotate_call' d) calls) end\n  and annotate_call' d (FirstOrderCall f) = FirstOrderCall (annotate' (d-1) f)\n    | annotate_call' d (SecondOrderCall (f, args)) =\n        SecondOrderCall (annotate' (d-1) f, map (apsnd (annotate' (d-3))) args)\n  in annotate' (calc_call_measure tr) tr end\n\nfun map_annotations f (CogentCallTree (a, ty, name, calls)) =\n      CogentCallTree (f a, ty, name, calls |>\n        map (fn c => case c of FirstOrderCall a => FirstOrderCall (map_annotations f a)\n                             | SecondOrderCall (a, bs) =>\n                                 SecondOrderCall (map_annotations f a, map (apsnd (map_annotations f)) bs)))\n*}\n\nend\n", "meta": {"author": "crizkallah", "repo": "cogent", "sha": "cb16e8169d4389e32dc4aecf4eb9f57173264006", "save_path": "github-repos/isabelle/crizkallah-cogent", "path": "github-repos/isabelle/crizkallah-cogent/cogent-cb16e8169d4389e32dc4aecf4eb9f57173264006/c-refinement/Corres_Tac.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6334102636778401, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.28220298026568125}}
{"text": "chapter \\<open>A Control Flow Graph for Jinja Byte Code\\<close>\n\nsection \\<open>Formalizing the CFG\\<close>\n\ntheory JVMCFG imports \"../StaticInter/BasicDefs\" Jinja.BVExample begin\n\ndeclare lesub_list_impl_same_size [simp del]\ndeclare listE_length [simp del]\n\nsubsection \\<open>Type definitions\\<close>\n\nsubsubsection \\<open>Wellformed Programs\\<close>\n\ndefinition \"wf_jvmprog = {(P, Phi). wf_jvm_prog\\<^bsub>Phi\\<^esub> P}\"\n\ntypedef wf_jvmprog = \"wf_jvmprog\"\nproof\n  show \"(E, Phi) \\<in> wf_jvmprog\"\n    unfolding wf_jvmprog_def by (auto intro: wf_prog)\nqed\n\nhide_const Phi E\n\nabbreviation PROG :: \"wf_jvmprog \\<Rightarrow> jvm_prog\"\n  where \"PROG P \\<equiv> fst(Rep_wf_jvmprog(P))\"\n\nabbreviation TYPING :: \"wf_jvmprog \\<Rightarrow> ty\\<^sub>P\"\n  where \"TYPING P \\<equiv> snd(Rep_wf_jvmprog(P))\"\n\nlemma wf_jvmprog_is_wf_typ: \"wf_jvm_prog\\<^bsub>TYPING P\\<^esub> (PROG P)\"\nusing Rep_wf_jvmprog [of P]\n  by (auto simp: wf_jvmprog_def split_beta)\n\nlemma wf_jvmprog_is_wf: \"wf_jvm_prog (PROG P)\"\n  using wf_jvmprog_is_wf_typ unfolding wf_jvm_prog_def\n  by blast\n\nsubsubsection \\<open>Interprocedural CFG\\<close>\n\ntype_synonym jvm_method = \"wf_jvmprog \\<times> cname \\<times> mname\"\ndatatype var = Heap | Local \"nat\" | Stack \"nat\" | Exception\ndatatype val = Hp \"heap\" | Value \"Value.val\"\n\ntype_synonym state = \"var \\<rightharpoonup> val\"\n\ndefinition valid_state :: \"state \\<Rightarrow> bool\"\n  where \"valid_state s \\<equiv> (\\<forall>val. s Heap \\<noteq> Some (Value val))\n  \\<and> (s Exception = None \\<or> (\\<exists>addr. s Exception = Some (Value (Addr addr))))\n  \\<and> (\\<forall>var. var \\<noteq> Heap \\<and> var \\<noteq> Exception \\<longrightarrow> (\\<forall>h. s var \\<noteq> Some (Hp h)))\"\n\nfun the_Heap :: \"val \\<Rightarrow> heap\"\n  where \"the_Heap (Hp h) = h\"\n\nfun the_Value :: \"val \\<Rightarrow> Value.val\"\n  where \"the_Value (Value v) = v\"\n\nabbreviation heap_of :: \"state \\<Rightarrow> heap\"\n  where \"heap_of s \\<equiv> the_Heap (the (s Heap))\"\n\nabbreviation exc_flag :: \"state \\<Rightarrow> addr option\"\n  where \"exc_flag s \\<equiv> case (s Exception) of None \\<Rightarrow> None\n  | Some v \\<Rightarrow> Some (THE a. v = Value (Addr a))\"\n\nabbreviation stkAt :: \"state \\<Rightarrow> nat \\<Rightarrow> Value.val\"\n  where \"stkAt s n \\<equiv> the_Value (the (s (Stack n)))\"\n\nabbreviation locAt :: \"state \\<Rightarrow> nat \\<Rightarrow> Value.val\"\n  where \"locAt s n \\<equiv> the_Value (the (s (Local n)))\"\n\ndatatype nodeType = Enter | Normal | Return | Exceptional \"pc option\" \"nodeType\"\ntype_synonym cfg_node = \"cname \\<times> mname \\<times> pc option \\<times> nodeType\"\n\ntype_synonym\n  cfg_edge = \"cfg_node \\<times> (var, val, cname \\<times> mname \\<times> pc, cname \\<times> mname) edge_kind \\<times> cfg_node\"\n\ndefinition ClassMain :: \"wf_jvmprog \\<Rightarrow> cname\"\n  where \"ClassMain P \\<equiv> SOME Name. \\<not> is_class (PROG P) Name\"\n\ndefinition MethodMain :: \"wf_jvmprog \\<Rightarrow> mname\"\n  where \"MethodMain P \\<equiv> SOME Name.\n  \\<forall>C D fs ms. class (PROG P) C = \\<lfloor>(D, fs, ms)\\<rfloor> \\<longrightarrow> (\\<forall>m \\<in> set ms. Name \\<noteq> fst m)\"\n\ndefinition stkLength :: \"jvm_method \\<Rightarrow> pc \\<Rightarrow> nat\"\n  where\n  \"stkLength m pc \\<equiv> let (P, C, M) = m in (\n  if (C = ClassMain P) then 1 else (\n    length (fst(the(((TYPING P) C M) ! pc)))\n  ))\"\n\ndefinition locLength :: \"jvm_method \\<Rightarrow> pc \\<Rightarrow> nat\"\n  where\n  \"locLength m pc \\<equiv> let (P, C, M) = m in (\n  if (C = ClassMain P) then 1 else (\n    length (snd(the(((TYPING P) C M) ! pc)))\n  ))\"\n\nlemma ex_new_class_name: \"\\<exists>C. \\<not> is_class P C\"\nproof -\n  have \"\\<not> finite (UNIV :: cname set)\"\n    by (rule infinite_UNIV_listI)\n  hence \"\\<exists>C. C \\<notin> set (map fst P)\"\n    by -(rule ex_new_if_finite, auto)\n  then obtain C where \"C \\<notin> set (map fst P)\"\n    by blast\n  have \"\\<not> is_class P C\"\n  proof\n    assume \"is_class P C\"\n    then obtain D fs ms where \"class P C = \\<lfloor>(D, fs, ms)\\<rfloor>\"\n      by auto\n    with \\<open>C \\<notin> set (map fst P)\\<close> show False\n      by (auto dest: map_of_SomeD intro!: image_eqI simp: class_def)\n  qed\n  thus ?thesis\n    by blast\nqed\n\nlemma ClassMain_unique_in_P:\n  assumes \"is_class (PROG P) C\"\n  shows \"ClassMain P \\<noteq> C\"\nproof -\n  from ex_new_class_name [of \"PROG P\"] obtain D where \"\\<not> is_class (PROG P) D\"\n    by blast\n  with \\<open>is_class (PROG P) C\\<close> show ?thesis\n    unfolding ClassMain_def\n    by -(rule someI2, fastforce+)\nqed\n\nlemma map_of_fstD: \"\\<lbrakk> map_of xs a = \\<lfloor>b\\<rfloor>; \\<forall>x \\<in> set xs. fst x \\<noteq> a \\<rbrakk> \\<Longrightarrow> False\"\n  by (induct xs, auto)\n\nlemma map_of_fstE: \"\\<lbrakk> map_of xs a = \\<lfloor>b\\<rfloor>; \\<exists>x \\<in> set xs. fst x = a \\<Longrightarrow> thesis \\<rbrakk> \\<Longrightarrow> thesis\"\n  by (induct xs) (auto split: if_split_asm)\n\nlemma ex_unique_method_name:\n  \"\\<exists>Name. \\<forall>C D fs ms. class (PROG P) C = \\<lfloor>(D, fs, ms)\\<rfloor> \\<longrightarrow> (\\<forall>m\\<in>set ms. Name \\<noteq> fst m)\"\nproof -\n  from wf_jvmprog_is_wf [of P]\n  have \"distinct_fst (PROG P)\"\n    by (simp add: wf_jvm_prog_def wf_jvm_prog_phi_def wf_prog_def)\n  hence \"{C. \\<exists>D fs ms. class (PROG P) C = \\<lfloor>(D, fs, ms)\\<rfloor>} = fst ` set (PROG P)\"\n    by (fastforce elim: map_of_fstE simp: class_def intro: map_of_SomeI)\n  hence \"finite {C. \\<exists>D fs ms. class (PROG P) C = \\<lfloor>(D, fs, ms)\\<rfloor>}\"\n    by auto\n  moreover have \"{ms. \\<exists>C D fs. class (PROG P) C = \\<lfloor>(D, fs, ms)\\<rfloor>}\n    = snd ` snd ` the ` (\\<lambda>C. class (PROG P) C) ` {C. \\<exists>D fs ms. class (PROG P) C = \\<lfloor>(D, fs, ms)\\<rfloor>}\"\n    by (fastforce intro: rev_image_eqI map_of_SomeI simp: class_def)\n  ultimately have \"finite {ms. \\<exists>C D fs. class (PROG P) C = \\<lfloor>(D, fs, ms)\\<rfloor>}\"\n    by auto\n  moreover have \"\\<not> finite (UNIV :: mname set)\"\n    by (rule infinite_UNIV_listI)\n  ultimately\n  have \"\\<exists>Name. Name \\<notin> fst ` (\\<Union>ms \\<in> {ms. \\<exists>C D fs. class (PROG P) C = \\<lfloor>(D, fs, ms)\\<rfloor>}. set ms)\"\n    by -(rule ex_new_if_finite, auto)\n  thus ?thesis\n    by fastforce\nqed\n\nlemma MethodMain_unique_in_P:\n  assumes \"PROG P \\<turnstile> D sees M:Ts\\<rightarrow>T = mb in C\"\n  shows \"MethodMain P \\<noteq> M\"\nproof -\n  from ex_unique_method_name [of P] obtain M'\n    where \"\\<And>C D fs ms. class (PROG P) C = \\<lfloor>(D, fs, ms)\\<rfloor> \\<Longrightarrow> (\\<forall>m \\<in> set ms. M' \\<noteq> fst m)\"\n    by blast\n  with \\<open>PROG P \\<turnstile> D sees M:Ts\\<rightarrow>T = mb in C\\<close>\n  show ?thesis\n    unfolding MethodMain_def\n    by -(rule someI2_ex, fastforce, fastforce dest!: visible_method_exists elim: map_of_fstE)\nqed\n\nlemma ClassMain_is_no_class [dest!]: \"is_class (PROG P) (ClassMain P) \\<Longrightarrow> False\"\nproof (erule rev_notE)\n  from ex_new_class_name [of \"PROG P\"] obtain C where \"\\<not> is_class (PROG P) C\"\n    by blast\n  thus \"\\<not> is_class (PROG P) (ClassMain P)\" unfolding ClassMain_def\n    by (rule someI)\nqed\n\nlemma MethodMain_not_seen [dest!]: \"PROG P \\<turnstile> C sees (MethodMain P):Ts\\<rightarrow>T = mb in D \\<Longrightarrow> False\"\n  by (fastforce dest: MethodMain_unique_in_P)\n\nlemma no_Call_from_ClassMain [dest!]: \"PROG P \\<turnstile> ClassMain P sees M:Ts\\<rightarrow>T = mb in C \\<Longrightarrow> False\"\n  by (fastforce dest: sees_method_is_class)\n\nlemma no_Call_in_ClassMain [dest!]: \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = mb in ClassMain P \\<Longrightarrow> False\"\n  by (fastforce dest: sees_method_idemp)\n\ninductive JVMCFG :: \"jvm_method \\<Rightarrow> cfg_node \\<Rightarrow> (var, val, cname \\<times> mname \\<times> pc, cname \\<times> mname) edge_kind \\<Rightarrow> cfg_node \\<Rightarrow> bool\" (\" _ \\<turnstile> _ -_\\<rightarrow> _\")\n  and reachable :: \"jvm_method \\<Rightarrow> cfg_node \\<Rightarrow> bool\" (\" _ \\<turnstile> \\<Rightarrow>_\")\n  where\n    Entry_reachable: \"(P, C0, Main) \\<turnstile> \\<Rightarrow>(ClassMain P, MethodMain P, None, Enter)\"\n  | reachable_step: \"\\<lbrakk> P \\<turnstile> \\<Rightarrow>n; P \\<turnstile> n -(e)\\<rightarrow> n' \\<rbrakk> \\<Longrightarrow> P \\<turnstile> \\<Rightarrow>n'\"\n  | Main_to_Call: \"(P, C0, Main) \\<turnstile> \\<Rightarrow>(ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Enter)\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Enter) -\\<Up>id\\<rightarrow> (ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Normal)\"\n  | Main_Call_LFalse: \"(P, C0, Main) \\<turnstile> \\<Rightarrow>(ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Normal)\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Normal) -(\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow> (ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Return)\"\n  | Main_Call: \"\\<lbrakk> (P, C0, Main) \\<turnstile> \\<Rightarrow>(ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Normal);\n     PROG P \\<turnstile> C0 sees Main:[]\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in D;\n     initParams = [(\\<lambda>s. s Heap),(\\<lambda>s. \\<lfloor>Value Null\\<rfloor>)];\n     ek = (\\<lambda>(s, ret). True):(ClassMain P, MethodMain P, 0)\\<hookrightarrow>\\<^bsub>(D, Main)\\<^esub>initParams \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Normal) -(ek)\\<rightarrow> (D, Main, None, Enter)\"\n  | Main_Return_to_Exit: \"(P, C0, Main) \\<turnstile> \\<Rightarrow>(ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Return)\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Return) -(\\<Up>id)\\<rightarrow> (ClassMain P, MethodMain P, None, Return)\"\n  | Method_LFalse: \"(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, None, Enter)\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, None, Enter) -(\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow> (C, M, None, Return)\"\n  | Method_LTrue: \"(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, None, Enter)\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, None, Enter) -(\\<lambda>s. True)\\<^sub>\\<surd>\\<rightarrow> (C, M, \\<lfloor>0\\<rfloor>, Enter)\"\n  | CFG_Load: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter); instrs_of (PROG P) C M ! pc = Load n;\n    ek = \\<Up>(\\<lambda>s. s(Stack (stkLength (P, C, M) pc) := s (Local n))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_Store: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter); instrs_of (PROG P) C M ! pc = Store n;\n    ek = \\<Up>(\\<lambda>s. s(Local n := s (Stack (stkLength (P, C, M) pc - 1)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_Push: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter); instrs_of (PROG P) C M ! pc = Push v;\n    ek = \\<Up>(\\<lambda>s. s(Stack (stkLength (P, C, M) pc) \\<mapsto> Value v)) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_Pop: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter); instrs_of (PROG P) C M ! pc = Pop;\n    ek = \\<Up>id \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_IAdd: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter); instrs_of (PROG P) C M ! pc = IAdd;\n    ek = \\<Up>(\\<lambda>s. let i1 = the_Intg (stkAt s (stkLength (P, C, M) pc - 1));\n                   i2 = the_Intg (stkAt s (stkLength (P, C, M) pc - 2))\n                in s(Stack (stkLength (P, C, M) pc - 2) \\<mapsto> Value (Intg (i1 + i2)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_Goto: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter); instrs_of (PROG P) C M ! pc = Goto i \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -((\\<lambda>s. True)\\<^sub>\\<surd>)\\<rightarrow> (C, M, \\<lfloor>nat (int pc + i)\\<rfloor>, Enter)\"\n  | CFG_CmpEq: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter); instrs_of (PROG P) C M ! pc = CmpEq;\n    ek = \\<Up>(\\<lambda>s. let e1 = stkAt s (stkLength (P, C, M) pc - 1);\n                   e2 = stkAt s (stkLength (P, C, M) pc - 2)\n                in s(Stack (stkLength (P, C, M) pc - 2) \\<mapsto> Value (Bool (e1 = e2)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_IfFalse_False: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = IfFalse i;\n    i \\<noteq> 1;\n    ek = (\\<lambda>s. stkAt s (stkLength(P, C, M) pc - 1) = Bool False)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>nat (int pc + i)\\<rfloor>, Enter)\"\n  | CFG_IfFalse_True: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = IfFalse i;\n    ek = (\\<lambda>s. stkAt s (stkLength(P, C, M) pc - 1) \\<noteq> Bool False \\<or> i = 1)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_New_Check_Normal: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = New Cl;\n    ek = (\\<lambda>s. new_Addr (heap_of s) \\<noteq> None)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Normal)\"\n  | CFG_New_Check_Exceptional: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = New Cl;\n    pc' = (case (match_ex_table (PROG P) OutOfMemory pc (ex_table_of (PROG P) C M)) of\n             None \\<Rightarrow> None\n           | Some (pc'', d) \\<Rightarrow> \\<lfloor>pc''\\<rfloor>);\n    ek = (\\<lambda>s. new_Addr (heap_of s) = None)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional pc' Enter)\"\n  | CFG_New_Update: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Normal);\n    instrs_of (PROG P) C M ! pc = New Cl;\n    ek = \\<Up>(\\<lambda>s. let a = the (new_Addr (heap_of s))\n                in s(Heap \\<mapsto> Hp ((heap_of s)(a \\<mapsto> blank (PROG P) Cl)))\n                    (Stack (stkLength(P, C, M) pc) \\<mapsto> Value (Addr a))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Normal) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_New_Exceptional_prop: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter);\n    instrs_of (PROG P) C M ! pc = New Cl;\n    ek = \\<Up>(\\<lambda>s. s(Exception \\<mapsto> Value (Addr (addr_of_sys_xcpt OutOfMemory)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter) -(ek)\\<rightarrow> (C, M, None, Return)\"\n  | CFG_New_Exceptional_handle: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter);\n    instrs_of (PROG P) C M ! pc = New Cl;\n    ek = \\<Up>(\\<lambda>s. s(Exception := None)\n                (Stack (stkLength (P, C, M) pc' - 1) \\<mapsto> Value (Addr (addr_of_sys_xcpt OutOfMemory)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc'\\<rfloor>, Enter)\"\n  | CFG_Getfield_Check_Normal: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = Getfield F Cl;\n    ek = (\\<lambda>s. stkAt s (stkLength (P, C, M) pc - 1) \\<noteq> Null)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Normal)\"\n  | CFG_Getfield_Check_Exceptional: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = Getfield F Cl;\n    pc' = (case (match_ex_table (PROG P) NullPointer pc (ex_table_of (PROG P) C M)) of\n             None \\<Rightarrow> None\n           | Some (pc'', d) \\<Rightarrow> \\<lfloor>pc''\\<rfloor>);\n    ek = (\\<lambda>s. stkAt s (stkLength (P, C, M) pc - 1) = Null)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional pc' Enter)\"\n  | CFG_Getfield_Update: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Normal);\n    instrs_of (PROG P) C M ! pc = Getfield F Cl;\n    ek = \\<Up>(\\<lambda>s. let (D, fs) = the (heap_of s (the_Addr (stkAt s (stkLength (P, C, M) pc - 1))))\n                 in s(Stack (stkLength(P, C, M) pc - 1) \\<mapsto> Value (the (fs (F, Cl))))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Normal) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_Getfield_Exceptional_prop: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter);\n    instrs_of (PROG P) C M ! pc = Getfield F Cl;\n    ek = \\<Up>(\\<lambda>s. s(Exception \\<mapsto> Value (Addr (addr_of_sys_xcpt NullPointer)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter) -(ek)\\<rightarrow> (C, M, None, Return)\"\n  | CFG_Getfield_Exceptional_handle: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter);\n    instrs_of (PROG P) C M ! pc = Getfield F Cl;\n    ek = \\<Up>(\\<lambda>s. s(Exception := None)\n                (Stack (stkLength (P, C, M) pc' - 1) \\<mapsto> Value (Addr (addr_of_sys_xcpt NullPointer)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc'\\<rfloor>, Enter)\"\n  | CFG_Putfield_Check_Normal: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = Putfield F Cl;\n    ek = (\\<lambda>s. stkAt s (stkLength (P, C, M) pc - 2) \\<noteq> Null)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Normal)\"\n  | CFG_Putfield_Check_Exceptional: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = Putfield F Cl;\n    pc' = (case (match_ex_table (PROG P) NullPointer pc (ex_table_of (PROG P) C M)) of\n             None \\<Rightarrow> None\n           | Some (pc'', d) \\<Rightarrow> \\<lfloor>pc''\\<rfloor>);\n    ek = (\\<lambda>s. stkAt s (stkLength (P, C, M) pc - 2) = Null)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional pc' Enter)\"\n  | CFG_Putfield_Update: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Normal);\n    instrs_of (PROG P) C M ! pc = Putfield F Cl;\n    ek = \\<Up>(\\<lambda>s. let v = stkAt s (stkLength (P, C, M) pc - 1);\n                   r = stkAt s (stkLength (P, C, M) pc - 2);\n                   a = the_Addr r;\n                   (D, fs) = the (heap_of s a);\n                   h' = (heap_of s)(a \\<mapsto> (D, fs((F, Cl) \\<mapsto> v)))\n                 in s(Heap \\<mapsto> Hp h')) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Normal) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_Putfield_Exceptional_prop: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter);\n    instrs_of (PROG P) C M ! pc = Putfield F Cl;\n    ek = \\<Up>(\\<lambda>s. s(Exception \\<mapsto> Value (Addr (addr_of_sys_xcpt NullPointer)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter) -(ek)\\<rightarrow> (C, M, None, Return)\"\n  | CFG_Putfield_Exceptional_handle: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter);\n    instrs_of (PROG P) C M ! pc = Putfield F Cl;\n    ek = \\<Up>(\\<lambda>s. s(Exception := None)\n                (Stack (stkLength (P, C, M) pc' - 1) \\<mapsto> Value (Addr (addr_of_sys_xcpt NullPointer)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc'\\<rfloor>, Enter)\"\n  | CFG_Checkcast_Check_Normal: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = Checkcast Cl;\n    ek = (\\<lambda>s. cast_ok (PROG P) Cl (heap_of s) (stkAt s (stkLength (P, C, M) pc - 1)))\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_Checkcast_Check_Exceptional: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = Checkcast Cl;\n    pc' = (case (match_ex_table (PROG P) ClassCast pc (ex_table_of (PROG P) C M)) of\n             None \\<Rightarrow> None\n           | Some (pc'', d) \\<Rightarrow> \\<lfloor>pc''\\<rfloor>);\n    ek = (\\<lambda>s. \\<not> cast_ok (PROG P) Cl (heap_of s) (stkAt s (stkLength (P, C, M) pc - 1)))\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional pc' Enter)\"\n  | CFG_Checkcast_Exceptional_prop: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter);\n    instrs_of (PROG P) C M ! pc = Checkcast Cl;\n    ek = \\<Up>(\\<lambda>s. s(Exception \\<mapsto> Value (Addr (addr_of_sys_xcpt ClassCast)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter) -(ek)\\<rightarrow> (C, M, None, Return)\"\n  | CFG_Checkcast_Exceptional_handle: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter);\n    instrs_of (PROG P) C M ! pc = Checkcast Cl;\n    ek = \\<Up>(\\<lambda>s. s(Exception := None)\n                (Stack (stkLength (P, C, M) pc' - 1) \\<mapsto> Value (Addr (addr_of_sys_xcpt ClassCast)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc'\\<rfloor>, Enter)\"\n  | CFG_Throw_Check: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = Throw;\n    pc' = None \\<or> match_ex_table (PROG P) Exc pc (ex_table_of (PROG P) C M) = \\<lfloor>(the pc', d)\\<rfloor>;\n    ek = (\\<lambda>s. let v = stkAt s (stkLength (P, C, M) pc - 1);\n                  Cl = if (v = Null) then NullPointer else (cname_of (heap_of s) (the_Addr v))\n               in case pc' of\n                  None \\<Rightarrow> match_ex_table (PROG P) Cl pc (ex_table_of (PROG P) C M) = None\n                | Some pc'' \\<Rightarrow> \\<exists>d. match_ex_table (PROG P) Cl pc (ex_table_of (PROG P) C M)\n                                  = \\<lfloor>(pc'', d)\\<rfloor>\n    )\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional pc' Enter)\"\n\n  | CFG_Throw_prop: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter);\n    instrs_of (PROG P) C M ! pc = Throw;\n    ek = \\<Up>(\\<lambda>s. s(Exception \\<mapsto> Value (stkAt s (stkLength (P, C, M) pc - 1)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter) -(ek)\\<rightarrow> (C, M, None, Return)\"\n  | CFG_Throw_handle: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter);\n    pc' \\<noteq> length (instrs_of (PROG P) C M);\n    instrs_of (PROG P) C M ! pc = Throw;\n    ek = \\<Up>(\\<lambda>s. s(Exception := None)\n                (Stack (stkLength (P, C, M) pc' - 1) \\<mapsto> Value (stkAt s (stkLength (P, C, M) pc - 1)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc'\\<rfloor>, Enter)\"\n  | CFG_Invoke_Check_NP_Normal: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = Invoke M' n;\n    ek = (\\<lambda>s. stkAt s (stkLength (P, C, M) pc - Suc n) \\<noteq> Null)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Normal)\"\n  | CFG_Invoke_Check_NP_Exceptional: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = Invoke M' n;\n    pc' = (case (match_ex_table (PROG P) NullPointer pc (ex_table_of (PROG P) C M)) of\n             None \\<Rightarrow> None\n           | Some (pc'', d) \\<Rightarrow> \\<lfloor>pc''\\<rfloor>);\n    ek = (\\<lambda>s. stkAt s (stkLength (P, C, M) pc - Suc n) = Null)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional pc' Enter)\"\n  | CFG_Invoke_NP_prop: \"\\<lbrakk> C \\<noteq> ClassMain P;\n    (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter);\n    instrs_of (PROG P) C M ! pc = Invoke M' n;\n    ek = \\<Up>(\\<lambda>s. s(Exception \\<mapsto> Value (Addr (addr_of_sys_xcpt NullPointer)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter) -(ek)\\<rightarrow> (C, M, None, Return)\"\n  | CFG_Invoke_NP_handle: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter);\n    instrs_of (PROG P) C M ! pc = Invoke M' n;\n    ek = \\<Up>(\\<lambda>s. s(Exception := None)\n                (Stack (stkLength (P, C, M) pc' - 1) \\<mapsto> Value (Addr (addr_of_sys_xcpt NullPointer)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc'\\<rfloor>, Enter)\"\n  | CFG_Invoke_Call: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Normal);\n    instrs_of (PROG P) C M ! pc = Invoke M' n;\n    TYPING P C M ! pc = \\<lfloor>(ST, LT)\\<rfloor>;\n    ST ! n = Class D';\n    PROG P \\<turnstile> D' sees M':Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in D;\n    Q = (\\<lambda>(s, ret). let r = stkAt s (stkLength (P, C, M) pc - Suc n);\n                        C' = fst (the (heap_of s (the_Addr r)))\n                     in D = fst (method (PROG P) C' M'));\n    paramDefs = (\\<lambda>s. s Heap)\n                # (\\<lambda>s. s (Stack (stkLength (P, C, M) pc - Suc n)))\n                # (rev (map (\\<lambda>i. (\\<lambda>s. s (Stack (stkLength (P, C, M) pc - Suc i)))) [0..<n]));\n    ek = Q:(C, M, pc)\\<hookrightarrow>\\<^bsub>(D,M')\\<^esub>paramDefs\n  \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Normal) -(ek)\\<rightarrow> (D, M', None, Enter)\"\n  | CFG_Invoke_False: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Normal);\n    instrs_of (PROG P) C M ! pc = Invoke M' n;\n    ek = (\\<lambda>s. False)\\<^sub>\\<surd>\n  \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Normal) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Return)\"\n  | CFG_Invoke_Return_Check_Normal: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Return);\n    instrs_of (PROG P) C M ! pc = Invoke M' n;\n    (TYPING P) C M ! pc = \\<lfloor>(ST, LT)\\<rfloor>;\n    ST ! n \\<noteq> NT;\n    ek = (\\<lambda>s. s Exception = None)\\<^sub>\\<surd>\n  \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Return) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_Invoke_Return_Check_Exceptional: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Return);\n    instrs_of (PROG P) C M ! pc = Invoke M' n;\n    match_ex_table (PROG P) Exc pc (ex_table_of (PROG P) C M) = \\<lfloor>(pc', diff)\\<rfloor>;\n    pc' \\<noteq> length (instrs_of (PROG P) C M);\n    ek = (\\<lambda>s. \\<exists>v d. s Exception = \\<lfloor>v\\<rfloor> \\<and>\n                  match_ex_table (PROG P) (cname_of (heap_of s) (the_Addr (the_Value v))) pc (ex_table_of (PROG P) C M) = \\<lfloor>(pc', d)\\<rfloor>)\\<^sub>\\<surd>\n  \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Return) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Return)\"\n  | CFG_Invoke_Return_Exceptional_handle: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Return);\n    instrs_of (PROG P) C M ! pc = Invoke M' n;\n    ek = \\<Up>(\\<lambda>s. s(Exception := None,\n                 Stack (stkLength (P, C, M) pc' - 1) := s Exception)) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Return) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc'\\<rfloor>, Enter)\"\n  | CFG_Invoke_Return_Exceptional_prop: \"\\<lbrakk> C \\<noteq> ClassMain P;\n    (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Return);\n    instrs_of (PROG P) C M ! pc = Invoke M' n;\n    ek = (\\<lambda>s. \\<exists>v. s Exception = \\<lfloor>v\\<rfloor> \\<and>\n              match_ex_table (PROG P) (cname_of (heap_of s) (the_Addr (the_Value v))) pc (ex_table_of (PROG P) C M) = None)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Return) -(ek)\\<rightarrow> (C, M, None, Return)\"\n  | CFG_Return: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = instr.Return;\n    ek = \\<Up>(\\<lambda>s. s(Stack 0 := s (Stack (stkLength (P, C, M) pc - 1))))\n  \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, None, Return)\"\n  | CFG_Return_from_Method: \"\\<lbrakk> (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, None, Return);\n    (P, C0, Main) \\<turnstile> (C', M', \\<lfloor>pc'\\<rfloor>, Normal) -(Q':(C', M', pc')\\<hookrightarrow>\\<^bsub>(C,M)\\<^esub>ps)\\<rightarrow> (C, M, None, Enter);\n    Q = (\\<lambda>(s, ret). ret = (C', M', pc'));\n    stateUpdate = (\\<lambda>s s'. s'(Heap := s Heap,\n                            Exception := s Exception,\n                            Stack (stkLength (P, C', M') (Suc pc') - 1) := s (Stack 0))\n                  );\n    ek = Q\\<hookleftarrow>\\<^bsub>(C, M)\\<^esub>stateUpdate\n  \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, None, Return) -(ek)\\<rightarrow> (C', M', \\<lfloor>pc'\\<rfloor>, Return)\"\n\n\n(* This takes veeeery long *)\nlemma JVMCFG_edge_det: \"\\<lbrakk> P \\<turnstile> n -(et)\\<rightarrow> n'; P \\<turnstile> n -(et')\\<rightarrow> n' \\<rbrakk> \\<Longrightarrow> et = et'\"\n  by (erule JVMCFG.cases) (erule JVMCFG.cases, (fastforce dest: sees_method_fun)+)+\n\nlemma sourcenode_reachable: \"P \\<turnstile> n -(ek)\\<rightarrow> n' \\<Longrightarrow> P \\<turnstile> \\<Rightarrow>n\"\n  by (erule JVMCFG.cases, auto)\n\nlemma targetnode_reachable:\n  assumes edge: \"P \\<turnstile> n -(ek)\\<rightarrow> n'\"\n  shows \"P \\<turnstile> \\<Rightarrow>n'\"\nproof -\n  from edge have \"P \\<turnstile> \\<Rightarrow>n\"\n    by -(drule sourcenode_reachable)\n  with edge show ?thesis\n    by -(rule JVMCFG_reachable.intros)\nqed\n\nlemmas JVMCFG_reachable_inducts = JVMCFG_reachable.inducts[split_format (complete)]\n\nlemma ClassMain_imp_MethodMain:\n  \"(P, C0, Main) \\<turnstile> (C', M', pc', nt') -ek\\<rightarrow> (ClassMain P, M, pc, nt) \\<Longrightarrow> M = MethodMain P\"\n  \"(P, C0, Main) \\<turnstile> \\<Rightarrow>(ClassMain P, M, pc, nt) \\<Longrightarrow> M = MethodMain P\"\nproof (induct P==\"P\" C0\\<equiv>\"C0\" Main\\<equiv>Main C' M' pc' nt' ek C''==\"ClassMain P\" M pc nt and\n              P==\"P\" C0\\<equiv>\"C0\" Main\\<equiv>Main C'==\"ClassMain P\" M pc nt\n       rule: JVMCFG_reachable_inducts)\n  case CFG_Return_from_Method\n  thus ?case\n    by (fastforce elim: JVMCFG.cases)\nqed auto\n\nlemma ClassMain_no_Call_target [dest!]:\n  \"(P, C0, Main) \\<turnstile> (C, M, pc, nt) -Q:(C', M', pc')\\<hookrightarrow>\\<^bsub>(D,M'')\\<^esub>paramDefs\\<rightarrow> (ClassMain P, M''', pc'', nt')\n  \\<Longrightarrow> False\"\n  and\n  \"(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, pc, nt) \\<Longrightarrow> True\"\n  by (induct  P C0 Main C M pc nt ek==\"Q:(C', M', pc')\\<hookrightarrow>\\<^bsub>(D,M'')\\<^esub>paramDefs\"\n                         C''==\"ClassMain P\" M''' pc'' nt' and\n               P C0 Main C M pc nt\n    rule: JVMCFG_reachable_inducts) auto\n\nlemma method_of_src_and_trg_exists:\n  \"\\<lbrakk> (P, C0, Main) \\<turnstile> (C', M', pc', nt') -ek\\<rightarrow> (C, M, pc, nt); C \\<noteq> ClassMain P; C' \\<noteq> ClassMain P \\<rbrakk>\n  \\<Longrightarrow> (\\<exists>Ts T mb. (PROG P) \\<turnstile> C sees M:Ts\\<rightarrow>T = mb in C) \\<and>\n     (\\<exists>Ts T mb. (PROG P) \\<turnstile> C' sees M':Ts\\<rightarrow>T = mb in C')\"\n  and method_of_reachable_node_exists:\n  \"\\<lbrakk> (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, pc, nt); C \\<noteq> ClassMain P \\<rbrakk>\n  \\<Longrightarrow> \\<exists>Ts T mb. (PROG P) \\<turnstile> C sees M:Ts\\<rightarrow>T = mb in C\"\nproof (induct rule: JVMCFG_reachable_inducts)\n  case CFG_Invoke_Call\n  thus ?case\n    by (blast dest: sees_method_idemp)\nnext\n  case (reachable_step P C0 Main C M pc nt ek C' M' pc' nt')\n  show ?case\n  proof (cases \"C = ClassMain P\")\n    case True\n    with \\<open>(P, C0, Main) \\<turnstile> (C, M, pc, nt) -ek\\<rightarrow> (C', M', pc', nt')\\<close> \\<open>C' \\<noteq> ClassMain P\\<close>\n    show ?thesis\n    proof cases\n      case Main_Call\n      thus ?thesis\n        by (blast dest: sees_method_idemp)\n    qed auto\n  next\n    case False\n    with reachable_step show ?thesis\n      by simp\n  qed\nqed simp_all\n\nlemma \"\\<lbrakk> (P, C0, Main) \\<turnstile> (C', M', pc', nt') -ek\\<rightarrow> (C, M, pc, nt); C \\<noteq> ClassMain P; C' \\<noteq> ClassMain P \\<rbrakk>\n  \\<Longrightarrow> (case pc of None \\<Rightarrow> True |\n    \\<lfloor>pc''\\<rfloor> \\<Rightarrow> (TYPING P) C M ! pc'' \\<noteq> None \\<and> pc'' < length (instrs_of (PROG P) C M)) \\<and>\n  (case pc' of None \\<Rightarrow> True |\n    \\<lfloor>pc''\\<rfloor> \\<Rightarrow> (TYPING P) C' M' ! pc'' \\<noteq> None \\<and> pc'' < length (instrs_of (PROG P) C' M'))\"\n  and instr_of_reachable_node_typable: \"\\<lbrakk> (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, pc, nt); C \\<noteq> ClassMain P \\<rbrakk>\n  \\<Longrightarrow> case pc of None \\<Rightarrow> True |\n  \\<lfloor>pc''\\<rfloor> \\<Rightarrow> (TYPING P) C M ! pc'' \\<noteq> None \\<and> pc'' < length (instrs_of (PROG P) C M)\"\nproof (induct rule: JVMCFG_reachable_inducts)\n  case (CFG_Load C P C0 Main M pc n ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_Load show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_Store C P C0 Main M pc n ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_Store show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_Push C P C0 Main M pc v ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_Push show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_Pop C P C0 Main M pc ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_Pop show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_IAdd C P C0 Main M pc ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_IAdd show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_Goto C P C0 Main M pc i)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_Goto show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_CmpEq C P C0 Main M pc ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_CmpEq show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_IfFalse_False C P C0 Main M pc i ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_IfFalse_False show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_IfFalse_True C P C0 Main M pc i ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_IfFalse_True show ?case\n    using [[simproc del: list_to_set_comprehension]] by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_New_Update C P C0 Main M pc Cl ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Normal)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_New_Update show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_New_Exceptional_handle C P C0 Main M pc pc' Cl ek)\n  hence \"TYPING P C M ! pc \\<noteq> None\" and \"pc < length (instrs_of (PROG P) C M)\"\n    by simp_all\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 where\n    \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, instrs_of (PROG P) C M, ex_table_of (PROG P) C M) in C\"\n    by (fastforce dest: method_of_reachable_node_exists)\n  with \\<open>pc < length (instrs_of (PROG P) C M)\\<close> \\<open>instrs_of (PROG P) C M ! pc = New Cl\\<close>\n  have \"PROG P,T,mxs,length (instrs_of (PROG P) C M),ex_table_of (PROG P) C M\n    \\<turnstile> New Cl,pc :: TYPING P C M\"\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n    \\<open>instrs_of (PROG P) C M ! pc = New Cl\\<close> obtain d'\n    where \"match_ex_table (PROG P) OutOfMemory pc (ex_table_of (PROG P) C M) = \\<lfloor>(pc', d')\\<rfloor>\"\n    by cases (fastforce elim: JVMCFG.cases)\n  hence \"\\<exists>(f, t, D, h, d)\\<in>set (ex_table_of (PROG P) C M).\n    matches_ex_entry (PROG P) OutOfMemory pc (f, t, D, h, d) \\<and> h = pc' \\<and> d = d'\"\n    by -(drule match_ex_table_SomeD)\n  ultimately show ?case using \\<open>instrs_of (PROG P) C M ! pc = New Cl\\<close>\n    by (fastforce simp: relevant_entries_def is_relevant_entry_def matches_ex_entry_def)\nnext\n  case (CFG_Getfield_Update C P C0 Main M pc F Cl ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Normal)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_Getfield_Update show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_Getfield_Exceptional_handle C P C0 Main M pc pc' F Cl ek)\n  hence \"TYPING P C M ! pc \\<noteq> None\" and \"pc < length (instrs_of (PROG P) C M)\"\n    by simp_all\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 where\n    \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, instrs_of (PROG P) C M, ex_table_of (PROG P) C M) in C\"\n    by (fastforce dest: method_of_reachable_node_exists)\n  with \\<open>pc < length (instrs_of (PROG P) C M)\\<close> \\<open>instrs_of (PROG P) C M ! pc = Getfield F Cl\\<close>\n  have \"PROG P,T,mxs,length (instrs_of (PROG P) C M),ex_table_of (PROG P) C M\n    \\<turnstile> Getfield F Cl,pc :: TYPING P C M\"\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n    \\<open>instrs_of (PROG P) C M ! pc = Getfield F Cl\\<close> obtain d'\n    where \"match_ex_table (PROG P) NullPointer pc (ex_table_of (PROG P) C M) = \\<lfloor>(pc', d')\\<rfloor>\"\n    by cases (fastforce elim: JVMCFG.cases)\n  hence \"\\<exists>(f, t, D, h, d)\\<in>set (ex_table_of (PROG P) C M).\n    matches_ex_entry (PROG P) NullPointer pc (f, t, D, h, d) \\<and> h = pc' \\<and> d = d'\"\n    by -(drule match_ex_table_SomeD)\n  ultimately show ?case using \\<open>instrs_of (PROG P) C M ! pc = Getfield F Cl\\<close>\n    by (fastforce simp: relevant_entries_def is_relevant_entry_def matches_ex_entry_def)\nnext\n  case (CFG_Putfield_Update C P C0 Main M pc F Cl ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Normal)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_Putfield_Update show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_Putfield_Exceptional_handle C P C0 Main M pc pc' F Cl ek)\n  hence \"TYPING P C M ! pc \\<noteq> None\" and \"pc < length (instrs_of (PROG P) C M)\"\n    by simp_all\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 where\n    \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, instrs_of (PROG P) C M, ex_table_of (PROG P) C M) in C\"\n    by (fastforce dest: method_of_reachable_node_exists)\n  with \\<open>pc < length (instrs_of (PROG P) C M)\\<close> \\<open>instrs_of (PROG P) C M ! pc = Putfield F Cl\\<close>\n  have \"PROG P,T,mxs,length (instrs_of (PROG P) C M),ex_table_of (PROG P) C M\n    \\<turnstile> Putfield F Cl,pc :: TYPING P C M\"\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n    \\<open>instrs_of (PROG P) C M ! pc = Putfield F Cl\\<close> obtain d'\n    where \"match_ex_table (PROG P) NullPointer pc (ex_table_of (PROG P) C M) = \\<lfloor>(pc', d')\\<rfloor>\"\n    by cases (fastforce elim: JVMCFG.cases)\n  hence \"\\<exists>(f, t, D, h, d)\\<in>set (ex_table_of (PROG P) C M).\n    matches_ex_entry (PROG P) NullPointer pc (f, t, D, h, d) \\<and> h = pc' \\<and> d = d'\"\n    by -(drule match_ex_table_SomeD)\n  ultimately show ?case using \\<open>instrs_of (PROG P) C M ! pc = Putfield F Cl\\<close>\n    by (fastforce simp: relevant_entries_def is_relevant_entry_def matches_ex_entry_def)\nnext\n  case (CFG_Checkcast_Check_Normal C P C0 Main M pc Cl ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_Checkcast_Check_Normal show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_Checkcast_Exceptional_handle C P C0 Main M pc pc' Cl ek)\n  hence \"TYPING P C M ! pc \\<noteq> None\" and \"pc < length (instrs_of (PROG P) C M)\"\n    by simp_all\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 where\n    \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, instrs_of (PROG P) C M, ex_table_of (PROG P) C M) in C\"\n    by (fastforce dest: method_of_reachable_node_exists)\n  with \\<open>pc < length (instrs_of (PROG P) C M)\\<close> \\<open>instrs_of (PROG P) C M ! pc = Checkcast Cl\\<close>\n  have \"PROG P,T,mxs,length (instrs_of (PROG P) C M),ex_table_of (PROG P) C M\n    \\<turnstile> Checkcast Cl,pc :: TYPING P C M\"\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n    \\<open>instrs_of (PROG P) C M ! pc = Checkcast Cl\\<close> obtain d'\n    where \"match_ex_table (PROG P) ClassCast pc (ex_table_of (PROG P) C M) = \\<lfloor>(pc', d')\\<rfloor>\"\n    by cases (fastforce elim: JVMCFG.cases)\n  hence \"\\<exists>(f, t, D, h, d)\\<in>set (ex_table_of (PROG P) C M).\n    matches_ex_entry (PROG P) ClassCast pc (f, t, D, h, d) \\<and> h = pc' \\<and> d = d'\"\n    by -(drule match_ex_table_SomeD)\n  ultimately show ?case using \\<open>instrs_of (PROG P) C M ! pc = Checkcast Cl\\<close>\n    by (fastforce simp: relevant_entries_def is_relevant_entry_def matches_ex_entry_def)\nnext\n  case (CFG_Throw_handle C P C0 Main M pc pc' ek)\n  hence \"TYPING P C M ! pc \\<noteq> None\" and \"pc < length (instrs_of (PROG P) C M)\"\n    by simp_all\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 where\n    \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, instrs_of (PROG P) C M, ex_table_of (PROG P) C M) in C\"\n    by (fastforce dest: method_of_reachable_node_exists)\n  with \\<open>pc < length (instrs_of (PROG P) C M)\\<close> \\<open>instrs_of (PROG P) C M ! pc = Throw\\<close>\n  have \"PROG P,T,mxs,length (instrs_of (PROG P) C M),ex_table_of (PROG P) C M\n    \\<turnstile> Throw,pc :: TYPING P C M\"\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n    \\<open>instrs_of (PROG P) C M ! pc = Throw\\<close> obtain d' Exc\n    where \"match_ex_table (PROG P) Exc pc (ex_table_of (PROG P) C M) = \\<lfloor>(pc', d')\\<rfloor>\"\n    by cases (fastforce elim: JVMCFG.cases)\n  hence \"\\<exists>(f, t, D, h, d)\\<in>set (ex_table_of (PROG P) C M).\n    matches_ex_entry (PROG P) Exc pc (f, t, D, h, d) \\<and> h = pc' \\<and> d = d'\"\n    by -(drule match_ex_table_SomeD)\n  ultimately show ?case using \\<open>instrs_of (PROG P) C M ! pc = Throw\\<close>\n    by (fastforce simp: relevant_entries_def is_relevant_entry_def matches_ex_entry_def)\nnext\n  case (CFG_Invoke_NP_handle C P C0 Main M pc pc' M' n ek)\n  hence \"TYPING P C M ! pc \\<noteq> None\" and \"pc < length (instrs_of (PROG P) C M)\"\n    by simp_all\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 where\n    \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, instrs_of (PROG P) C M, ex_table_of (PROG P) C M) in C\"\n    by (fastforce dest: method_of_reachable_node_exists)\n  with \\<open>pc < length (instrs_of (PROG P) C M)\\<close> \\<open>instrs_of (PROG P) C M ! pc = Invoke M' n\\<close>\n  have \"PROG P,T,mxs,length (instrs_of (PROG P) C M),ex_table_of (PROG P) C M\n    \\<turnstile> Invoke M' n,pc :: TYPING P C M\"\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n    \\<open>instrs_of (PROG P) C M ! pc = Invoke M' n\\<close> obtain d'\n    where \"match_ex_table (PROG P) NullPointer pc (ex_table_of (PROG P) C M) = \\<lfloor>(pc', d')\\<rfloor>\"\n    by cases (fastforce elim: JVMCFG.cases)\n  hence \"\\<exists>(f, t, D, h, d)\\<in>set (ex_table_of (PROG P) C M).\n    matches_ex_entry (PROG P) NullPointer pc (f, t, D, h, d) \\<and> h = pc' \\<and> d = d'\"\n    by -(drule match_ex_table_SomeD)\n  ultimately show ?case using \\<open>instrs_of (PROG P) C M ! pc = Invoke M' n\\<close>\n    by (fastforce simp: relevant_entries_def is_relevant_entry_def matches_ex_entry_def)\nnext\n  case (CFG_Invoke_Return_Exceptional_handle C P C0 Main M pc pc' M' n ek)\n  hence \"TYPING P C M ! pc \\<noteq> None\" and \"pc < length (instrs_of (PROG P) C M)\"\n    by simp_all\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Return)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 where\n    \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, instrs_of (PROG P) C M, ex_table_of (PROG P) C M) in C\"\n    by (fastforce dest: method_of_reachable_node_exists)\n  with \\<open>pc < length (instrs_of (PROG P) C M)\\<close> \\<open>instrs_of (PROG P) C M ! pc = Invoke M' n\\<close>\n  have \"PROG P,T,mxs,length (instrs_of (PROG P) C M),ex_table_of (PROG P) C M\n    \\<turnstile> Invoke M' n,pc :: TYPING P C M\"\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Return)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n    \\<open>instrs_of (PROG P) C M ! pc = Invoke M' n\\<close> obtain d' Exc\n    where \"match_ex_table (PROG P) Exc pc (ex_table_of (PROG P) C M) = \\<lfloor>(pc', d')\\<rfloor>\"\n    by cases (fastforce elim: JVMCFG.cases)\n  hence \"\\<exists>(f, t, D, h, d)\\<in>set (ex_table_of (PROG P) C M).\n    matches_ex_entry (PROG P) Exc pc (f, t, D, h, d) \\<and> h = pc' \\<and> d = d'\"\n    by -(drule match_ex_table_SomeD)\n  ultimately show ?case using \\<open>instrs_of (PROG P) C M ! pc = Invoke M' n\\<close>\n    by (fastforce simp: relevant_entries_def is_relevant_entry_def matches_ex_entry_def)\nnext\n  case (CFG_Invoke_Return_Check_Normal C P C0 Main M pc M' n ST LT ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Return)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_Invoke_Return_Check_Normal show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext \n  case (Method_LTrue P C0 Main C M)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, None, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with Method_LTrue show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_start [OF wf_jvmprog_is_wf_typ] simp: wt_start_def)\nnext\n  case (reachable_step P C0 Main C M opc nt ek C' M' opc' nt')\n  thus ?case\n    by (cases \"C = ClassMain P\") (fastforce elim: JVMCFG.cases, simp)\nqed simp_all\n\nlemma reachable_node_impl_wt_instr:\n  assumes \"(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, nt)\"\n  and \"C \\<noteq> ClassMain P\"\n  shows \"\\<exists>T mxs mpc xt. PROG P,T,mxs,mpc,xt \\<turnstile> (instrs_of (PROG P) C M ! pc),pc :: TYPING P C M\"\nproof -\n  from \\<open>C \\<noteq> ClassMain P\\<close> \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, nt)\\<close>\n    method_of_reachable_node_exists [of P C0 Main C M \"\\<lfloor>pc\\<rfloor>\" nt]\n    instr_of_reachable_node_typable [of P C0 Main C M \"\\<lfloor>pc\\<rfloor>\" nt]\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt\n    where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"TYPING P C M ! pc \\<noteq> None\"\n    and \"pc < length (instrs_of (PROG P) C M)\"\n    by fastforce+\n  with wf_jvmprog_is_wf_typ [of P]\n  have \"PROG P,T,mxs,length is,xt \\<turnstile> instrs_of (PROG P) C M ! pc,pc :: TYPING P C M\"\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr)\n  thus ?thesis\n    by blast\nqed\n\nlemma\n  \"\\<lbrakk> (P, C0, Main) \\<turnstile> (C, M, pc, nt) -ek\\<rightarrow> (C', M', pc', nt'); C \\<noteq> ClassMain P \\<or> C' \\<noteq> ClassMain P \\<rbrakk>\n  \\<Longrightarrow> \\<exists>T mb D. PROG P \\<turnstile> C0 sees Main:[]\\<rightarrow>T = mb in D\"\n  and reachable_node_impl_Main_ex:\n  \"\\<lbrakk> (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, pc, nt); C \\<noteq> ClassMain P\\<rbrakk>\n  \\<Longrightarrow> \\<exists>T mb D. PROG P \\<turnstile> C0 sees Main:[]\\<rightarrow>T = mb in D\"\n  by (induct rule: JVMCFG_reachable_inducts) fastforce+\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/HRB-Slicing/JinjaVM_Inter/JVMCFG.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6334102498375401, "lm_q2_score": 0.44552953503957266, "lm_q1q2_score": 0.2822029740994188}}
{"text": "(*  Title:      ZF/UNITY/AllocImpl.thy\n    Author:     Sidi O Ehmety, Cambridge University Computer Laboratory\n    Copyright   2002  University of Cambridge\n\nSingle-client allocator implementation.\nCharpentier and Chandy, section 7 (page 17).\n*)\n\ntheory AllocImpl imports ClientImpl begin\n\nabbreviation\n  NbR :: i            (*number of consumed messages*)  where\n  \"NbR \\<equiv> Var([succ(2)])\"\n\nabbreviation\n  available_tok :: i  (*number of free tokens (T in paper)*)  where\n  \"available_tok \\<equiv> Var([succ(succ(2))])\"\n\naxiomatization where\n  alloc_type_assumes [simp]:\n  \"type_of(NbR) = nat \\<and> type_of(available_tok)=nat\" and\n\n  alloc_default_val_assumes [simp]:\n  \"default_val(NbR)  = 0 \\<and> default_val(available_tok)=0\"\n\ndefinition\n  \"alloc_giv_act \\<equiv>\n       {\\<langle>s, t\\<rangle> \\<in> state*state.\n        \\<exists>k. k = length(s`giv) \\<and>\n            t = s(giv := s`giv @ [nth(k, s`ask)],\n                  available_tok := s`available_tok #- nth(k, s`ask)) \\<and>\n            k < length(s`ask) \\<and> nth(k, s`ask) \\<le> s`available_tok}\"\n\ndefinition\n  \"alloc_rel_act \\<equiv>\n       {\\<langle>s, t\\<rangle> \\<in> state*state.\n        t = s(available_tok := s`available_tok #+ nth(s`NbR, s`rel),\n              NbR := succ(s`NbR)) \\<and>\n        s`NbR < length(s`rel)}\"\n\ndefinition\n  (*The initial condition s`giv=[] is missing from the\n    original definition: S. O. Ehmety *)\n  \"alloc_prog \\<equiv>\n       mk_program({s:state. s`available_tok=NbT \\<and> s`NbR=0 \\<and> s`giv=Nil},\n                  {alloc_giv_act, alloc_rel_act},\n                  \\<Union>G \\<in> preserves(lift(available_tok)) \\<inter>\n                        preserves(lift(NbR)) \\<inter>\n                        preserves(lift(giv)). Acts(G))\"\n\n\nlemma available_tok_value_type [simp,TC]: \"s\\<in>state \\<Longrightarrow> s`available_tok \\<in> nat\"\n  unfolding state_def\napply (drule_tac a = available_tok in apply_type, auto)\ndone\n\nlemma NbR_value_type [simp,TC]: \"s\\<in>state \\<Longrightarrow> s`NbR \\<in> nat\"\n  unfolding state_def\napply (drule_tac a = NbR in apply_type, auto)\ndone\n\n(** The Alloc Program **)\n\nlemma alloc_prog_type [simp,TC]: \"alloc_prog \\<in> program\"\nby (simp add: alloc_prog_def)\n\ndeclare alloc_prog_def [THEN def_prg_Init, simp]\ndeclare alloc_prog_def [THEN def_prg_AllowedActs, simp]\ndeclare alloc_prog_def [program]\n\ndeclare  alloc_giv_act_def [THEN def_act_simp, simp]\ndeclare  alloc_rel_act_def [THEN def_act_simp, simp]\n\n\nlemma alloc_prog_ok_iff:\n\"\\<forall>G \\<in> program. (alloc_prog ok G) \\<longleftrightarrow>\n     (G \\<in> preserves(lift(giv)) \\<and> G \\<in> preserves(lift(available_tok)) \\<and>\n       G \\<in> preserves(lift(NbR)) \\<and>  alloc_prog \\<in> Allowed(G))\"\nby (auto simp add: ok_iff_Allowed alloc_prog_def [THEN def_prg_Allowed])\n\n\nlemma alloc_prog_preserves:\n    \"alloc_prog \\<in> (\\<Inter>x \\<in> var-{giv, available_tok, NbR}. preserves(lift(x)))\"\napply (rule Inter_var_DiffI, force)\napply (rule ballI)\napply (rule preservesI, safety)\ndone\n\n(* As a special case of the rule above *)\n\nlemma alloc_prog_preserves_rel_ask_tok:\n    \"alloc_prog \\<in>\n       preserves(lift(rel)) \\<inter> preserves(lift(ask)) \\<inter> preserves(lift(tok))\"\napply auto\napply (insert alloc_prog_preserves)\napply (drule_tac [3] x = tok in Inter_var_DiffD)\napply (drule_tac [2] x = ask in Inter_var_DiffD)\napply (drule_tac x = rel in Inter_var_DiffD, auto)\ndone\n\nlemma alloc_prog_Allowed:\n\"Allowed(alloc_prog) =\n  preserves(lift(giv)) \\<inter> preserves(lift(available_tok)) \\<inter> preserves(lift(NbR))\"\napply (cut_tac v=\"lift(giv)\" in preserves_type)\napply (auto simp add: Allowed_def client_prog_def [THEN def_prg_Allowed]\n                      cons_Int_distrib safety_prop_Acts_iff)\ndone\n\n(* In particular we have *)\nlemma alloc_prog_ok_client_prog: \"alloc_prog ok client_prog\"\napply (auto simp add: ok_iff_Allowed)\napply (cut_tac alloc_prog_preserves)\napply (cut_tac [2] client_prog_preserves)\napply (auto simp add: alloc_prog_Allowed client_prog_Allowed)\napply (drule_tac [6] B = \"preserves (lift (NbR))\" in InterD)\napply (drule_tac [5] B = \"preserves (lift (available_tok))\" in InterD)\napply (drule_tac [4] B = \"preserves (lift (giv))\" in InterD)\napply (drule_tac [3] B = \"preserves (lift (tok))\" in InterD)\napply (drule_tac [2] B = \"preserves (lift (ask))\" in InterD)\napply (drule_tac B = \"preserves (lift (rel))\" in InterD)\napply auto\ndone\n\n(** Safety property: (28) **)\nlemma alloc_prog_Increasing_giv: \"alloc_prog \\<in> program guarantees Incr(lift(giv))\"\napply (auto intro!: increasing_imp_Increasing simp add: guar_def\n  Increasing.increasing_def alloc_prog_ok_iff alloc_prog_Allowed, safety+)\napply (auto dest: ActsD)\napply (drule_tac f = \"lift (giv) \" in preserves_imp_eq)\napply auto\ndone\n\nlemma giv_Bounded_lamma1:\n\"alloc_prog \\<in> stable({s\\<in>state. s`NbR \\<le> length(s`rel)} \\<inter>\n                     {s\\<in>state. s`available_tok #+ tokens(s`giv) =\n                                 NbT #+ tokens(take(s`NbR, s`rel))})\"\napply safety\napply auto\napply (simp add: diff_add_0 add_commute diff_add_inverse add_assoc add_diff_inverse)\napply (simp (no_asm_simp) add: take_succ)\ndone\n\nlemma giv_Bounded_lemma2:\n\"\\<lbrakk>G \\<in> program; alloc_prog ok G; alloc_prog \\<squnion> G \\<in> Incr(lift(rel))\\<rbrakk>\n  \\<Longrightarrow> alloc_prog \\<squnion> G \\<in> Stable({s\\<in>state. s`NbR \\<le> length(s`rel)} \\<inter>\n   {s\\<in>state. s`available_tok #+ tokens(s`giv) =\n    NbT #+ tokens(take(s`NbR, s`rel))})\"\napply (cut_tac giv_Bounded_lamma1)\napply (cut_tac alloc_prog_preserves_rel_ask_tok)\napply (auto simp add: Collect_conj_eq [symmetric] alloc_prog_ok_iff)\napply (subgoal_tac \"G \\<in> preserves (fun_pair (lift (available_tok), fun_pair (lift (NbR), lift (giv))))\")\napply (rotate_tac -1)\napply (cut_tac A = \"nat * nat * list(nat)\"\n             and P = \"%<m,n,l> y. n \\<le> length(y) \\<and>\n                                  m #+ tokens(l) = NbT #+ tokens(take(n,y))\"\n             and g = \"lift(rel)\" and F = alloc_prog\n       in stable_Join_Stable)\nprefer 3 apply assumption\napply (auto simp add: Collect_conj_eq)\napply (frule_tac g = length in imp_Increasing_comp)\napply (blast intro: mono_length)\napply (auto simp add: refl_prefix)\napply (drule_tac a=xa and f = \"length comp lift(rel)\" in Increasing_imp_Stable)\napply assumption\napply (auto simp add: Le_def length_type)\napply (auto dest: ActsD simp add: Stable_def Constrains_def constrains_def)\napply (drule_tac f = \"lift (rel) \" in preserves_imp_eq)\napply assumption+\napply (force dest: ActsD)\napply (erule_tac V = \"\\<forall>x \\<in> Acts (alloc_prog) \\<union> Acts (G). P(x)\" for P in thin_rl)\napply (erule_tac V = \"alloc_prog \\<in> stable (u)\" for u in thin_rl)\napply (drule_tac a = \"xc`rel\" and f = \"lift (rel)\" in Increasing_imp_Stable)\napply (auto simp add: Stable_def Constrains_def constrains_def)\napply (drule bspec, force)\napply (drule subsetD)\napply (rule imageI, assumption)\napply (auto simp add: prefix_take_iff)\napply (rotate_tac -1)\napply (erule ssubst)\napply (auto simp add: take_take min_def)\ndone\n\n(*Property (29), page 18:\n  the number of tokens in circulation never exceeds NbT*)\nlemma alloc_prog_giv_Bounded: \"alloc_prog \\<in> Incr(lift(rel))\n      guarantees Always({s\\<in>state. tokens(s`giv) \\<le> NbT #+ tokens(s`rel)})\"\napply (cut_tac NbT_pos)\napply (auto simp add: guar_def)\napply (rule Always_weaken)\napply (rule AlwaysI)\napply (rule_tac [2] giv_Bounded_lemma2, auto)\napply (rule_tac j = \"NbT #+ tokens(take (x` NbR, x`rel))\" in le_trans)\napply (erule subst)\napply (auto intro!: tokens_mono simp add: prefix_take_iff min_def length_take)\ndone\n\n(*Property (30), page 18: the number of tokens given never exceeds the number\n  asked for*)\nlemma alloc_prog_ask_prefix_giv:\n     \"alloc_prog \\<in> Incr(lift(ask)) guarantees\n                   Always({s\\<in>state. <s`giv, s`ask> \\<in> prefix(tokbag)})\"\napply (auto intro!: AlwaysI simp add: guar_def)\napply (subgoal_tac \"G \\<in> preserves (lift (giv))\")\n prefer 2 apply (simp add: alloc_prog_ok_iff)\napply (rule_tac P = \"\\<lambda>x y. \\<langle>x,y\\<rangle> \\<in> prefix(tokbag)\" and A = \"list(nat)\"\n       in stable_Join_Stable)\napply safety\n prefer 2 apply (simp add: lift_def, clarify)\napply (drule_tac a = k in Increasing_imp_Stable, auto)\ndone\n\nsubsection\\<open>Towards proving the liveness property, (31)\\<close>\n\nsubsubsection\\<open>First, we lead up to a proof of Lemma 49, page 28.\\<close>\n\nlemma alloc_prog_transient_lemma:\n     \"\\<lbrakk>G \\<in> program; k\\<in>nat\\<rbrakk>\n      \\<Longrightarrow> alloc_prog \\<squnion> G \\<in>\n             transient({s\\<in>state. k \\<le> length(s`rel)} \\<inter>\n             {s\\<in>state. succ(s`NbR) = k})\"\napply auto\napply (erule_tac V = \"G\\<notin>u\" for u in thin_rl)\napply (rule_tac act = alloc_rel_act in transientI)\napply (simp (no_asm) add: alloc_prog_def [THEN def_prg_Acts])\napply (simp (no_asm) add: alloc_rel_act_def [THEN def_act_eq, THEN act_subset])\napply (auto simp add: alloc_prog_def [THEN def_prg_Acts] domain_def)\napply (rule ReplaceI)\napply (rule_tac x = \"x (available_tok:= x`available_tok #+ nth (x`NbR, x`rel),\n                        NbR:=succ (x`NbR))\"\n       in exI)\napply (auto intro!: state_update_type)\ndone\n\nlemma alloc_prog_rel_Stable_NbR_lemma:\n    \"\\<lbrakk>G \\<in> program; alloc_prog ok G; k\\<in>nat\\<rbrakk>\n     \\<Longrightarrow> alloc_prog \\<squnion> G \\<in> Stable({s\\<in>state . k \\<le> succ(s ` NbR)})\"\napply (auto intro!: stable_imp_Stable simp add: alloc_prog_ok_iff, safety, auto)\napply (blast intro: le_trans leI)\napply (drule_tac f = \"lift (NbR)\" and A = nat in preserves_imp_increasing)\napply (drule_tac [2] g = succ in imp_increasing_comp)\napply (rule_tac [2] mono_succ)\napply (drule_tac [4] x = k in increasing_imp_stable)\n    prefer 5 apply (simp add: Le_def comp_def, auto)\ndone\n\nlemma alloc_prog_NbR_LeadsTo_lemma:\n     \"\\<lbrakk>G \\<in> program; alloc_prog ok G;\n         alloc_prog \\<squnion> G \\<in> Incr(lift(rel)); k\\<in>nat\\<rbrakk>\n      \\<Longrightarrow> alloc_prog \\<squnion> G \\<in>\n            {s\\<in>state. k \\<le> length(s`rel)} \\<inter> {s\\<in>state. succ(s`NbR) = k}\n            \\<longmapsto>w {s\\<in>state. k \\<le> s`NbR}\"\napply (subgoal_tac \"alloc_prog \\<squnion> G \\<in> Stable ({s\\<in>state. k \\<le> length (s`rel)})\")\napply (drule_tac [2] a = k and g1 = length in imp_Increasing_comp [THEN Increasing_imp_Stable])\napply (rule_tac [2] mono_length)\n    prefer 3 apply simp\napply (simp_all add: refl_prefix Le_def comp_def length_type)\napply (rule LeadsTo_weaken)\napply (rule PSP_Stable)\nprefer 2 apply assumption\napply (rule PSP_Stable)\napply (rule_tac [2] alloc_prog_rel_Stable_NbR_lemma)\napply (rule alloc_prog_transient_lemma [THEN transient_imp_leadsTo, THEN leadsTo_imp_LeadsTo], assumption+)\napply (auto dest: not_lt_imp_le elim: lt_asym simp add: le_iff)\ndone\n\nlemma alloc_prog_NbR_LeadsTo_lemma2 [rule_format]:\n    \"\\<lbrakk>G \\<in> program; alloc_prog ok G; alloc_prog \\<squnion> G \\<in> Incr(lift(rel));\n        k\\<in>nat; n \\<in> nat; n < k\\<rbrakk>\n      \\<Longrightarrow> alloc_prog \\<squnion> G \\<in>\n            {s\\<in>state . k \\<le> length(s ` rel)} \\<inter> {s\\<in>state . s ` NbR = n}\n               \\<longmapsto>w {x \\<in> state. k \\<le> length(x`rel)} \\<inter>\n                 (\\<Union>m \\<in> greater_than(n). {x \\<in> state. x ` NbR=m})\"\n  unfolding greater_than_def\napply (rule_tac A' = \"{x \\<in> state. k \\<le> length(x`rel)} \\<inter> {x \\<in> state. n < x`NbR}\"\n       in LeadsTo_weaken_R)\napply safe\napply (subgoal_tac \"alloc_prog \\<squnion> G \\<in> Stable ({s\\<in>state. k \\<le> length (s`rel) }) \")\napply (drule_tac [2] a = k and g1 = length in imp_Increasing_comp [THEN Increasing_imp_Stable])\napply (rule_tac [2] mono_length)\n    prefer 3 apply simp\napply (simp_all add: refl_prefix Le_def comp_def length_type)\napply (subst Int_commute [of _ \"{x \\<in> state . n < x ` NbR}\"])\napply (rule_tac A = \"({s \\<in> state . k \\<le> length (s ` rel) } \\<inter>\n                      {s\\<in>state . s ` NbR = n}) \\<inter> {s\\<in>state. k \\<le> length(s`rel)}\"\n       in LeadsTo_weaken_L)\napply (rule PSP_Stable, safe)\napply (rule_tac B = \"{x \\<in> state . n < length (x ` rel) } \\<inter> {s\\<in>state . s ` NbR = n}\" in LeadsTo_Trans)\napply (rule_tac [2] LeadsTo_weaken)\napply (rule_tac [2] k = \"succ (n)\" in alloc_prog_NbR_LeadsTo_lemma)\napply simp_all\napply (rule subset_imp_LeadsTo, auto)\napply (blast intro: lt_trans2)\ndone\n\nlemma Collect_vimage_eq: \"u\\<in>nat \\<Longrightarrow> {<s,f(s)>. s \\<in> A} -`` u = {s\\<in>A. f(s) < u}\"\nby (force simp add: lt_def)\n\n(* Lemma 49, page 28 *)\n\nlemma alloc_prog_NbR_LeadsTo_lemma3:\n  \"\\<lbrakk>G \\<in> program; alloc_prog ok G; alloc_prog \\<squnion> G \\<in> Incr(lift(rel));\n     k\\<in>nat\\<rbrakk>\n   \\<Longrightarrow> alloc_prog \\<squnion> G \\<in>\n           {s\\<in>state. k \\<le> length(s`rel)} \\<longmapsto>w {s\\<in>state. k \\<le> s`NbR}\"\n(* Proof by induction over the difference between k and n *)\napply (rule_tac f = \"\\<lambda>s\\<in>state. k #- s`NbR\" in LessThan_induct)\napply (simp_all add: lam_def, auto)\napply (rule single_LeadsTo_I, auto)\napply (simp (no_asm_simp) add: Collect_vimage_eq)\napply (rename_tac \"s0\")\napply (case_tac \"s0`NbR < k\")\napply (rule_tac [2] subset_imp_LeadsTo, safe)\napply (auto dest!: not_lt_imp_le)\napply (rule LeadsTo_weaken)\napply (rule_tac n = \"s0`NbR\" in alloc_prog_NbR_LeadsTo_lemma2, safe)\nprefer 3 apply assumption\napply (auto split: nat_diff_split simp add: greater_than_def not_lt_imp_le not_le_iff_lt)\napply (blast dest: lt_asym)\napply (force dest: add_lt_elim2)\ndone\n\nsubsubsection\\<open>Towards proving lemma 50, page 29\\<close>\n\nlemma alloc_prog_giv_Ensures_lemma:\n\"\\<lbrakk>G \\<in> program; k\\<in>nat; alloc_prog ok G;\n  alloc_prog \\<squnion> G \\<in> Incr(lift(ask))\\<rbrakk> \\<Longrightarrow>\n  alloc_prog \\<squnion> G \\<in>\n  {s\\<in>state. nth(length(s`giv), s`ask) \\<le> s`available_tok} \\<inter>\n  {s\\<in>state.  k < length(s`ask)} \\<inter> {s\\<in>state. length(s`giv)=k}\n  Ensures {s\\<in>state. \\<not> k <length(s`ask)} \\<union> {s\\<in>state. length(s`giv) \\<noteq> k}\"\napply (rule EnsuresI, auto)\napply (erule_tac [2] V = \"G\\<notin>u\" for u in thin_rl)\napply (rule_tac [2] act = alloc_giv_act in transientI)\n prefer 2\n apply (simp add: alloc_prog_def [THEN def_prg_Acts])\n apply (simp add: alloc_giv_act_def [THEN def_act_eq, THEN act_subset])\napply (auto simp add: alloc_prog_def [THEN def_prg_Acts] domain_def)\napply (erule_tac [2] swap)\napply (rule_tac [2] ReplaceI)\napply (rule_tac [2] x = \"x (giv := x ` giv @ [nth (length(x`giv), x ` ask) ], available_tok := x ` available_tok #- nth (length(x`giv), x ` ask))\" in exI)\napply (auto intro!: state_update_type simp add: app_type)\napply (rule_tac A = \"{s\\<in>state . nth (length(s ` giv), s ` ask) \\<le> s ` available_tok} \\<inter> {s\\<in>state . k < length(s ` ask) } \\<inter> {s\\<in>state. length(s`giv) =k}\" and A' = \"{s\\<in>state . nth (length(s ` giv), s ` ask) \\<le> s ` available_tok} \\<union> {s\\<in>state. \\<not> k < length(s`ask) } \\<union> {s\\<in>state . length(s ` giv) \\<noteq> k}\" in Constrains_weaken)\napply (auto dest: ActsD simp add: Constrains_def constrains_def alloc_prog_def [THEN def_prg_Acts] alloc_prog_ok_iff)\napply (subgoal_tac \"length(xa ` giv @ [nth (length(xa ` giv), xa ` ask) ]) = length(xa ` giv) #+ 1\")\napply (rule_tac [2] trans)\napply (rule_tac [2] length_app, auto)\napply (rule_tac j = \"xa ` available_tok\" in le_trans, auto)\napply (drule_tac f = \"lift (available_tok)\" in preserves_imp_eq)\napply assumption+\napply auto\napply (drule_tac a = \"xa ` ask\" and r = \"prefix(tokbag)\" and A = \"list(tokbag)\"\n       in Increasing_imp_Stable)\napply (auto simp add: prefix_iff)\napply (drule StableD)\napply (auto simp add: Constrains_def constrains_def, force)\ndone\n\nlemma alloc_prog_giv_Stable_lemma:\n\"\\<lbrakk>G \\<in> program; alloc_prog ok G; k\\<in>nat\\<rbrakk>\n  \\<Longrightarrow> alloc_prog \\<squnion> G \\<in> Stable({s\\<in>state . k \\<le> length(s`giv)})\"\napply (auto intro!: stable_imp_Stable simp add: alloc_prog_ok_iff, safety)\napply (auto intro: leI)\napply (drule_tac f = \"lift (giv)\" and g = length in imp_preserves_comp)\napply (drule_tac f = \"length comp lift (giv)\" and A = nat and r = Le in preserves_imp_increasing)\napply (drule_tac [2] x = k in increasing_imp_stable)\n prefer 3 apply (simp add: Le_def comp_def)\napply (auto simp add: length_type)\ndone\n\n(* Lemma 50, page 29 *)\n\nlemma alloc_prog_giv_LeadsTo_lemma:\n\"\\<lbrakk>G \\<in> program; alloc_prog ok G;\n    alloc_prog \\<squnion> G \\<in> Incr(lift(ask)); k\\<in>nat\\<rbrakk>\n \\<Longrightarrow> alloc_prog \\<squnion> G \\<in>\n        {s\\<in>state. nth(length(s`giv), s`ask) \\<le> s`available_tok} \\<inter>\n        {s\\<in>state.  k < length(s`ask)} \\<inter>\n        {s\\<in>state. length(s`giv) = k}\n        \\<longmapsto>w {s\\<in>state. k < length(s`giv)}\"\napply (subgoal_tac \"alloc_prog \\<squnion> G \\<in> {s\\<in>state. nth (length(s`giv), s`ask) \\<le> s`available_tok} \\<inter> {s\\<in>state. k < length(s`ask) } \\<inter> {s\\<in>state. length(s`giv) = k} \\<longmapsto>w {s\\<in>state. \\<not> k <length(s`ask) } \\<union> {s\\<in>state. length(s`giv) \\<noteq> k}\")\nprefer 2 apply (blast intro: alloc_prog_giv_Ensures_lemma [THEN LeadsTo_Basis])\napply (subgoal_tac \"alloc_prog \\<squnion> G \\<in> Stable ({s\\<in>state. k < length(s`ask) }) \")\napply (drule PSP_Stable, assumption)\napply (rule LeadsTo_weaken)\napply (rule PSP_Stable)\napply (rule_tac [2] k = k in alloc_prog_giv_Stable_lemma)\napply (auto simp add: le_iff)\napply (drule_tac a = \"succ (k)\" and g1 = length in imp_Increasing_comp [THEN Increasing_imp_Stable])\napply (rule mono_length)\n prefer 2 apply simp\napply (simp_all add: refl_prefix Le_def comp_def length_type)\ndone\n\n\ntext\\<open>Lemma 51, page 29.\n  This theorem states as invariant that if the number of\n  tokens given does not exceed the number returned, then the upper limit\n  (\\<^term>\\<open>NbT\\<close>) does not exceed the number currently available.\\<close>\nlemma alloc_prog_Always_lemma:\n\"\\<lbrakk>G \\<in> program; alloc_prog ok G;\n    alloc_prog \\<squnion> G \\<in> Incr(lift(ask));\n    alloc_prog \\<squnion> G \\<in> Incr(lift(rel))\\<rbrakk>\n  \\<Longrightarrow> alloc_prog \\<squnion> G \\<in>\n        Always({s\\<in>state. tokens(s`giv) \\<le> tokens(take(s`NbR, s`rel)) \\<longrightarrow>\n                NbT \\<le> s`available_tok})\"\napply (subgoal_tac\n       \"alloc_prog \\<squnion> G\n          \\<in> Always ({s\\<in>state. s`NbR \\<le> length(s`rel) } \\<inter>\n                    {s\\<in>state. s`available_tok #+ tokens(s`giv) = \n                              NbT #+ tokens(take (s`NbR, s`rel))})\")\napply (rule_tac [2] AlwaysI)\napply (rule_tac [3] giv_Bounded_lemma2, auto)\napply (rule Always_weaken, assumption, auto)\napply (subgoal_tac \"0 \\<le> tokens(take (x ` NbR, x ` rel)) #- tokens(x`giv) \")\n prefer 2 apply (force)\napply (subgoal_tac \"x`available_tok =\n                    NbT #+ (tokens(take(x`NbR,x`rel)) #- tokens(x`giv))\")\napply (simp add: )\napply (auto split: nat_diff_split dest: lt_trans2)\ndone\n\n\n\nsubsubsection\\<open>Main lemmas towards proving property (31)\\<close>\n\nlemma LeadsTo_strength_R:\n    \"\\<lbrakk>F \\<in> C \\<longmapsto>w B'; F \\<in> A-C \\<longmapsto>w B; B'<=B\\<rbrakk> \\<Longrightarrow> F \\<in> A \\<longmapsto>w  B\"\nby (blast intro: LeadsTo_weaken LeadsTo_Un_Un)\n\nlemma PSP_StableI:\n\"\\<lbrakk>F \\<in> Stable(C); F \\<in> A - C \\<longmapsto>w B;\n   F \\<in> A \\<inter> C \\<longmapsto>w B \\<union> (state - C)\\<rbrakk> \\<Longrightarrow> F \\<in> A \\<longmapsto>w  B\"\napply (rule_tac A = \" (A-C) \\<union> (A \\<inter> C)\" in LeadsTo_weaken_L)\n prefer 2 apply blast\napply (rule LeadsTo_Un, assumption)\napply (blast intro: LeadsTo_weaken dest: PSP_Stable)\ndone\n\nlemma state_compl_eq [simp]: \"state - {s\\<in>state. P(s)} = {s\\<in>state. \\<not>P(s)}\"\nby auto\n\n(*needed?*)\nlemma single_state_Diff_eq [simp]: \"{s}-{x \\<in> state. P(x)} = (if s\\<in>state \\<and> P(s) then 0 else {s})\"\nby auto\n\n\nlocale alloc_progress =\n fixes G\n assumes Gprog [intro,simp]: \"G \\<in> program\"\n     and okG [iff]:          \"alloc_prog ok G\"\n     and Incr_rel [intro]:   \"alloc_prog \\<squnion> G \\<in> Incr(lift(rel))\"\n     and Incr_ask [intro]:   \"alloc_prog \\<squnion> G \\<in> Incr(lift(ask))\"\n     and safety:   \"alloc_prog \\<squnion> G\n                      \\<in> Always(\\<Inter>k \\<in> nat. {s\\<in>state. nth(k, s`ask) \\<le> NbT})\"\n     and progress: \"alloc_prog \\<squnion> G\n                      \\<in> (\\<Inter>k\\<in>nat. {s\\<in>state. k \\<le> tokens(s`giv)} \\<longmapsto>w\n                        {s\\<in>state. k \\<le> tokens(s`rel)})\"\n\n(*First step in proof of (31) -- the corrected version from Charpentier.\n  This lemma implies that if a client releases some tokens then the Allocator\n  will eventually recognize that they've been released.*)\nlemma (in alloc_progress) tokens_take_NbR_lemma:\n \"k \\<in> tokbag\n  \\<Longrightarrow> alloc_prog \\<squnion> G \\<in>\n        {s\\<in>state. k \\<le> tokens(s`rel)}\n        \\<longmapsto>w {s\\<in>state. k \\<le> tokens(take(s`NbR, s`rel))}\"\napply (rule single_LeadsTo_I, safe)\napply (rule_tac a1 = \"s`rel\" in Increasing_imp_Stable [THEN PSP_StableI])\napply (rule_tac [4] k1 = \"length(s`rel)\" in alloc_prog_NbR_LeadsTo_lemma3 [THEN LeadsTo_strength_R])\napply (rule_tac [8] subset_imp_LeadsTo)\napply (auto intro!: Incr_rel)\napply (rule_tac j = \"tokens(take (length(s`rel), x`rel))\" in le_trans)\napply (rule_tac j = \"tokens(take (length(s`rel), s`rel))\" in le_trans)\napply (auto intro!: tokens_mono take_mono simp add: prefix_iff)\ndone\n\n(*** Rest of proofs done by lcp ***)\n\n(*Second step in proof of (31): by LHS of the guarantee and transivity of\n  \\<longmapsto>w *)\nlemma (in alloc_progress) tokens_take_NbR_lemma2:\n     \"k \\<in> tokbag\n      \\<Longrightarrow> alloc_prog \\<squnion> G \\<in>\n            {s\\<in>state. tokens(s`giv) = k}\n            \\<longmapsto>w {s\\<in>state. k \\<le> tokens(take(s`NbR, s`rel))}\"\napply (rule LeadsTo_Trans)\n apply (rule_tac [2] tokens_take_NbR_lemma)\n prefer 2 apply assumption\napply (insert progress) \napply (blast intro: LeadsTo_weaken_L progress nat_into_Ord)\ndone\n\n(*Third step in proof of (31): by PSP with the fact that giv increases *)\nlemma (in alloc_progress) length_giv_disj:\n     \"\\<lbrakk>k \\<in> tokbag; n \\<in> nat\\<rbrakk>\n      \\<Longrightarrow> alloc_prog \\<squnion> G \\<in>\n            {s\\<in>state. length(s`giv) = n \\<and> tokens(s`giv) = k}\n            \\<longmapsto>w\n              {s\\<in>state. (length(s`giv) = n \\<and> tokens(s`giv) = k \\<and>\n                         k \\<le> tokens(take(s`NbR, s`rel))) | n < length(s`giv)}\"\napply (rule single_LeadsTo_I, safe)\napply (rule_tac a1 = \"s`giv\" in Increasing_imp_Stable [THEN PSP_StableI])\napply (rule alloc_prog_Increasing_giv [THEN guaranteesD])\napply (simp_all add: Int_cons_left)\napply (rule LeadsTo_weaken)\napply (rule_tac k = \"tokens(s`giv)\" in tokens_take_NbR_lemma2)\napply auto\napply (force dest: prefix_length_le [THEN le_iff [THEN iffD1]]) \napply (simp add: not_lt_iff_le)\napply (force dest: prefix_length_le_equal) \ndone\n\n(*Fourth step in proof of (31): we apply lemma (51) *)\nlemma (in alloc_progress) length_giv_disj2:\n     \"\\<lbrakk>k \\<in> tokbag; n \\<in> nat\\<rbrakk>\n      \\<Longrightarrow> alloc_prog \\<squnion> G \\<in>\n            {s\\<in>state. length(s`giv) = n \\<and> tokens(s`giv) = k}\n            \\<longmapsto>w\n              {s\\<in>state. (length(s`giv) = n \\<and> NbT \\<le> s`available_tok) |\n                        n < length(s`giv)}\"\napply (rule LeadsTo_weaken_R)\napply (rule Always_LeadsToD [OF alloc_prog_Always_lemma length_giv_disj], auto)\ndone\n\n(*Fifth step in proof of (31): from the fourth step, taking the union over all\n  k\\<in>nat *)\nlemma (in alloc_progress) length_giv_disj3:\n     \"n \\<in> nat\n      \\<Longrightarrow> alloc_prog \\<squnion> G \\<in>\n            {s\\<in>state. length(s`giv) = n}\n            \\<longmapsto>w\n              {s\\<in>state. (length(s`giv) = n \\<and> NbT \\<le> s`available_tok) |\n                        n < length(s`giv)}\"\napply (rule LeadsTo_weaken_L)\napply (rule_tac I = nat in LeadsTo_UN)\napply (rule_tac k = i in length_giv_disj2)\napply (simp_all add: UN_conj_eq)\ndone\n\n(*Sixth step in proof of (31): from the fifth step, by PSP with the\n  assumption that ask increases *)\nlemma (in alloc_progress) length_ask_giv:\n \"\\<lbrakk>k \\<in> nat;  n < k\\<rbrakk>\n  \\<Longrightarrow> alloc_prog \\<squnion> G \\<in>\n        {s\\<in>state. length(s`ask) = k \\<and> length(s`giv) = n}\n        \\<longmapsto>w\n          {s\\<in>state. (NbT \\<le> s`available_tok \\<and> length(s`giv) < length(s`ask) \\<and>\n                     length(s`giv) = n) |\n                    n < length(s`giv)}\"\napply (rule single_LeadsTo_I, safe)\napply (rule_tac a1 = \"s`ask\" and f1 = \"lift(ask)\" \n       in Increasing_imp_Stable [THEN PSP_StableI])\napply (rule Incr_ask, simp_all)\napply (rule LeadsTo_weaken)\napply (rule_tac n = \"length(s ` giv)\" in length_giv_disj3)\napply simp_all\napply blast\napply clarify\napply simp\napply (blast dest!: prefix_length_le intro: lt_trans2)\ndone\n\n\n(*Seventh step in proof of (31): no request (ask[k]) exceeds NbT *)\nlemma (in alloc_progress) length_ask_giv2:\n     \"\\<lbrakk>k \\<in> nat;  n < k\\<rbrakk>\n      \\<Longrightarrow> alloc_prog \\<squnion> G \\<in>\n            {s\\<in>state. length(s`ask) = k \\<and> length(s`giv) = n}\n            \\<longmapsto>w\n              {s\\<in>state. (nth(length(s`giv), s`ask) \\<le> s`available_tok \\<and>\n                         length(s`giv) < length(s`ask) \\<and> length(s`giv) = n) |\n                        n < length(s`giv)}\"\napply (rule LeadsTo_weaken_R)\napply (rule Always_LeadsToD [OF safety length_ask_giv], assumption+, clarify)\napply (simp add: INT_iff)\napply (drule_tac x = \"length(x ` giv)\" and P = \"\\<lambda>x. f (x) \\<le> NbT\" for f in bspec)\napply simp\napply (blast intro: le_trans)\ndone\n\n(*Eighth step in proof of (31): by 50, we get |giv| > n. *)\nlemma (in alloc_progress) extend_giv:\n     \"\\<lbrakk>k \\<in> nat;  n < k\\<rbrakk>\n      \\<Longrightarrow> alloc_prog \\<squnion> G \\<in>\n            {s\\<in>state. length(s`ask) = k \\<and> length(s`giv) = n}\n            \\<longmapsto>w {s\\<in>state. n < length(s`giv)}\"\napply (rule LeadsTo_Un_duplicate)\napply (rule LeadsTo_cancel1)\napply (rule_tac [2] alloc_prog_giv_LeadsTo_lemma)\napply (simp_all add: Incr_ask lt_nat_in_nat)\napply (rule LeadsTo_weaken_R)\napply (rule length_ask_giv2, auto)\ndone\n\n(*Ninth and tenth steps in proof of (31): by 50, we get |giv| > n.\n  The report has an error: putting |ask|=k for the precondition fails because\n  we can't expect |ask| to remain fixed until |giv| increases.*)\nlemma (in alloc_progress) alloc_prog_ask_LeadsTo_giv:\n \"k \\<in> nat\n  \\<Longrightarrow> alloc_prog \\<squnion> G \\<in>\n        {s\\<in>state. k \\<le> length(s`ask)} \\<longmapsto>w {s\\<in>state. k \\<le> length(s`giv)}\"\n(* Proof by induction over the difference between k and n *)\napply (rule_tac f = \"\\<lambda>s\\<in>state. k #- length(s`giv)\" in LessThan_induct)\napply (auto simp add: lam_def Collect_vimage_eq)\napply (rule single_LeadsTo_I, auto)\napply (rename_tac \"s0\")\napply (case_tac \"length(s0 ` giv) < length(s0 ` ask) \")\n apply (rule_tac [2] subset_imp_LeadsTo)\n  apply (auto simp add: not_lt_iff_le)\n prefer 2 apply (blast dest: le_imp_not_lt intro: lt_trans2)\napply (rule_tac a1 = \"s0`ask\" and f1 = \"lift (ask)\"\n       in Increasing_imp_Stable [THEN PSP_StableI])\napply (rule Incr_ask, simp)\napply (force)\napply (rule LeadsTo_weaken)\napply (rule_tac n = \"length(s0 ` giv)\" and k = \"length(s0 ` ask)\"\n       in extend_giv) \napply (auto dest: not_lt_imp_le simp add: leI diff_lt_iff_lt) \napply (blast dest!: prefix_length_le intro: lt_trans2)\ndone\n\n(*Final lemma: combine previous result with lemma (30)*)\nlemma (in alloc_progress) final:\n     \"h \\<in> list(tokbag)\n      \\<Longrightarrow> alloc_prog \\<squnion> G\n            \\<in> {s\\<in>state. <h, s`ask> \\<in> prefix(tokbag)} \\<longmapsto>w\n              {s\\<in>state. <h, s`giv> \\<in> prefix(tokbag)}\"\napply (rule single_LeadsTo_I)\n prefer 2 apply simp\napply (rename_tac s0)\napply (rule_tac a1 = \"s0`ask\" and f1 = \"lift (ask)\"\n       in Increasing_imp_Stable [THEN PSP_StableI])\n   apply (rule Incr_ask)\n  apply (simp_all add: Int_cons_left)\napply (rule LeadsTo_weaken)\napply (rule_tac k1 = \"length(s0 ` ask)\"\n       in Always_LeadsToD [OF alloc_prog_ask_prefix_giv [THEN guaranteesD]\n                              alloc_prog_ask_LeadsTo_giv])\napply (auto simp add: Incr_ask)\napply (blast intro: length_le_prefix_imp_prefix prefix_trans prefix_length_le \n                    lt_trans2)\ndone\n\n(** alloc_prog liveness property (31), page 18 **)\n\ntheorem alloc_prog_progress:\n\"alloc_prog \\<in>\n    Incr(lift(ask)) \\<inter> Incr(lift(rel)) \\<inter>\n    Always(\\<Inter>k \\<in> nat. {s\\<in>state. nth(k, s`ask) \\<le> NbT}) \\<inter>\n    (\\<Inter>k\\<in>nat. {s\\<in>state. k \\<le> tokens(s`giv)} \\<longmapsto>w\n              {s\\<in>state. k \\<le> tokens(s`rel)})\n  guarantees (\\<Inter>h \\<in> list(tokbag).\n              {s\\<in>state. <h, s`ask> \\<in> prefix(tokbag)} \\<longmapsto>w\n              {s\\<in>state. <h, s`giv> \\<in> prefix(tokbag)})\"\napply (rule guaranteesI)\napply (rule INT_I)\napply (rule alloc_progress.final)\napply (auto simp add: alloc_progress_def)\ndone\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/ZF/UNITY/AllocImpl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.66192288918838, "lm_q2_score": 0.4263215925474903, "lm_q1q2_score": 0.2821920202624261}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory Memcpy\nimports\n  \"CParser.CTranslation\"\n  \"AutoCorres.AutoCorres\"\nbegin\n\nabbreviation \"ADDR_MAX \\<equiv> UWORD_MAX TYPE(addr_bitsize)\"\n\n(* Helper for noticing when you accidentally haven't constrained an of_nat *)\nabbreviation \"of_nat_addr \\<equiv> of_nat::(nat \\<Rightarrow> addr)\"\n\nlemma byte_ptr_guarded:\n    \"ptr_val (x::8 word ptr) \\<noteq> 0 \\<Longrightarrow> c_guard x\"\n  unfolding c_guard_def c_null_guard_def ptr_aligned_def\n  by (clarsimp simp: intvl_Suc)\n\n(* FIXME: MOVE *)\nlemma ptr_add_coerce: \"ptr_val (((ptr_coerce x)::('a::{c_type}) ptr) +\\<^sub>p a) = (ptr_val x) + (of_int a * of_nat (size_of TYPE('a)))\"\n  apply (case_tac x)\n  apply (clarsimp simp: CTypesDefs.ptr_add_def)\n  done\n\n(* FIXME: MOVE *)\n(* Casting a valid pointer to char* and incrementing it by a value less than\n * the size of the underlying type does not give us NULL.\n *)\nlemma ptr_contained:\"\\<lbrakk> c_guard (x::('a::c_type) ptr); size_of TYPE('a) = sz;\n                       0 \\<le> i; i < int sz; (y::8 word ptr) = ptr_coerce x\\<rbrakk> \\<Longrightarrow> c_guard (y +\\<^sub>p i)\"\n  apply (rule byte_ptr_guarded)\n  unfolding c_guard_def c_null_guard_def ptr_add_def\n  apply simp\n  apply (clarsimp simp: CTypesDefs.ptr_add_def intvl_def)\n  apply (erule allE [where x=\"nat i\"])\n  apply (clarsimp simp: nat_less_iff)\n  done\n\nexternal_file \"memcpy.c\"\ninstall_C_file \"memcpy.c\"\n\n(* FIXME: MOVE *)\nlemma squash_auxupd_id[polish]:\n  \"modify (t_hrs_'_update (hrs_htd_update id)) = skip\"\n  by (monad_eq simp: skip_def id_def hrs_htd_update_def)\n\nautocorres [no_heap_abs=memcpy memcpy_int] \"memcpy.c\"\n\n(* Dereference a pointer *)\nabbreviation \"deref s x \\<equiv> h_val (hrs_mem (t_hrs_' s)) x\"\n\n(* char* cast *)\nabbreviation \"byte_cast x \\<equiv> ((ptr_coerce x)::8 word ptr)\"\n\ncontext memcpy begin\n\nlemma memcpy_char:\n  \"\\<lbrace> \\<lambda>s. c_guard (x::8 word ptr) \\<and>\n         c_guard (y::8 word ptr) \\<and>\n         unat sz = size_of TYPE(8 word) \\<and>\n         P (deref s x) \\<and>\n         x \\<noteq> y\\<rbrace>\n      memcpy' (ptr_coerce y) (ptr_coerce x) sz\n   \\<lbrace>\\<lambda> _ s. P (deref s y) \\<rbrace>!\"\n  (* Evaluate sz *)\n  apply clarsimp\n\n  unfolding memcpy'_def\n  apply (clarsimp simp:skip_def)\n  apply wp\n\n  (* Unroll the loop twice *)\n  apply (subst whileLoop_unroll, wp)\n     apply (subst whileLoop_unroll, wp)\n\n  (* The remaining loop is never encountered *)\n       apply (rule validNF_false_pre)\n      apply wp+\n\n  (* Finally we're left with the single assignment *)\n  apply (clarsimp simp:hrs_mem_update h_val_heap_update)\n  apply unat_arith\n done\n\nlemma of_nat_prop_exp: \"n < 32 \\<Longrightarrow> of_nat (2 ^ n) = 2 ^ (of_nat n)\"\n  by clarsimp\n\nlemma memcpy_word:\n  \"\\<lbrace> \\<lambda>s. c_guard (x::32 word ptr) \\<and>\n         c_guard (y::32 word ptr) \\<and>\n         unat sz = size_of TYPE(32 word) \\<and>\n         P (deref s x) \\<and>\n         x \\<noteq> y \\<rbrace>\n      memcpy' (ptr_coerce y) (ptr_coerce x) sz\n   \\<lbrace> \\<lambda>_ s. P (deref s y) \\<rbrace>!\"\n  apply clarsimp\n  unfolding memcpy'_def apply (clarsimp simp:skip_def)\n  apply (rule validNF_assume_pre)\n  apply (subgoal_tac \"{ptr_val x ..+ unat sz} \\<inter> {ptr_val y ..+ unat sz} = {}\")\n   apply (subst whileLoop_add_inv [where\n     I=\"\\<lambda>i s.  unat i \\<le> unat sz \\<and>\n                (\\<forall>a < i. deref s (byte_cast x +\\<^sub>p uint a) = deref s (byte_cast y +\\<^sub>p uint a)) \\<and>\n                P (deref s x)\" and\n     M=\"\\<lambda>(i, s). unat sz - unat i\"])\n   apply (wp validNF_whileLoop_inv_measure_twosteps)\n      apply clarsimp\n      apply (rule conjI, unat_arith)\n      apply (rule conjI, clarsimp)\n       apply (case_tac \"a = i\")\n        apply (clarsimp)\n        apply (erule_tac x=i in allE)\n        apply (clarsimp simp:hrs_mem_update h_val_heap_update)\n        apply (subst h_val_heap_same)\n            apply (rule ptr_retyp_h_t_valid)\n            apply simp\n           apply (rule ptr_retyp_disjoint)\n            apply (rule ptr_retyp_h_t_valid)\n            apply simp\n           apply (clarsimp simp:ptr_add_def intvl_def)\n          apply simp\n         apply (clarsimp simp: CTypesDefs.ptr_add_def field_of_t_simple)\n         apply (drule field_of_t_simple)\n         apply clarsimp\n        apply simp\n       apply (subgoal_tac \"a < i\")\n        apply (clarsimp simp:hrs_mem_update)\n        apply (subst h_val_heap_update_disjoint)\n\n         (* The current goal should be obvious to unat_arith, but for some reason isn't *)\n         apply (clarsimp simp:ptr_add_def intvl_def disjoint_iff_not_equal)\n         apply (erule_tac x=\"ptr_val x + a\" in allE, clarsimp)\n         apply (erule impE)\n          apply (rule_tac x=\"unat a\" in exI, clarsimp)\n          apply unat_arith\n\n         apply (erule_tac x=\"ptr_val y + i\" and\n                          P=\"\\<lambda>ya. (\\<exists>k. ya = ptr_val y + of_nat k \\<and> k < 4) \\<longrightarrow> ptr_val y + i \\<noteq> ya\" in allE, clarsimp)\n         apply (erule_tac x=\"unat i\" in allE, clarsimp)\n          apply unat_arith\n         apply (clarsimp simp:CTypesDefs.ptr_add_def)\n        apply (subst h_val_heap_update_disjoint)\n         (* Similar goal to the previous irritation, but this time Isabelle decides to play ball *)\n         apply (clarsimp simp:ptr_add_def intvl_def disjoint_iff_not_equal)\n        apply (clarsimp simp:CTypesDefs.ptr_add_def)\n       apply (clarsimp simp:CTypesDefs.ptr_add_def)\n      apply unat_arith\n\n      apply (rule conjI)\n       apply (subst hrs_mem_update)+\n       apply (subst h_val_heap_update_disjoint)\n        apply (clarsimp simp: disjoint_iff_not_equal)\n        apply (clarsimp simp:CTypesDefs.ptr_add_def intvl_def)\n        apply (erule_tac x=\"ptr_val x + of_nat k\" in allE)\n        apply (erule impE)\n         apply (rule_tac x=\"k\" in exI)\n         apply simp\n        apply (erule_tac x=\"ptr_val y + i\" and\n                         P=\"\\<lambda>ya. (\\<exists>k. ya = ptr_val y + of_nat k \\<and> k < 4) \\<longrightarrow> ptr_val x + of_nat k \\<noteq> ya\" in allE)\n        apply (erule impE)\n         apply (rule_tac x=\"unat i\" in exI)\n         apply simp\n         apply unat_arith\n        apply simp\n       apply simp\n\n      (* Yet more tedium that unat_arith doesn't like *)\n      apply (rule conjI)\n       apply (rule byte_ptr_guarded,\n              clarsimp simp:CTypesDefs.ptr_add_def c_guard_def c_null_guard_def intvl_def,\n              (erule_tac x=\"unat i\" in allE)+,\n              clarsimp,\n              unat_arith)+\n\n     apply wp\n     apply unat_arith\n    apply clarsimp\n    apply (subgoal_tac \"deref sa x = deref sa y\")\n     apply clarsimp\n    apply (clarsimp simp: h_val_def)[1]\n    apply (rule arg_cong[where f=from_bytes])\n    apply (simp add: numeral_nat)\n    apply (rule_tac x=0 in allE, assumption, erule impE, unat_arith)\n    apply (rule_tac x=1 in allE, assumption, erule impE, unat_arith)\n    apply (rule_tac x=2 in allE, assumption, erule impE, unat_arith)\n    apply (rule_tac x=3 in allE, assumption, erule impE, unat_arith)\n    apply (simp add:CTypesDefs.ptr_add_def)\n    apply (simp add: add.commute from_bytes_eq)\n   apply clarsimp\n  apply (clarsimp simp:intvl_def disjoint_iff_not_equal)\n  apply (drule_tac x=x and y=y and j=\"of_nat k\" and i=\"of_nat ka\" and n=2 in neq_imp_bytes_disjoint)\n        apply assumption\n       apply (case_tac \"k = 0\", clarsimp) (* insert \"k > 0\" *)\n       apply (clarsimp simp:unat_of_nat_len)\n      apply (case_tac \"ka = 0\", clarsimp)\n      apply (clarsimp simp:unat_of_nat_len)\n     apply assumption\n    apply clarsimp+\n  done\n\ntext \\<open>The bytes at the pointer @{term p} are @{term bs}.\\<close>\ndefinition\n  bytes_at :: \"'a globals_scheme \\<Rightarrow> 'b::c_type ptr \\<Rightarrow> word8 list \\<Rightarrow> bool\"\nwhere\n  \"bytes_at s p bs \\<equiv> length bs = 0 \\<or>\n                      (length bs \\<le> ADDR_MAX \\<and> (\\<forall>i \\<in> {0..(length bs - 1)}. deref s (byte_cast p +\\<^sub>p (of_nat i)) = bs ! i))\"\n\nlemma bytes_at_none[simp]: \"bytes_at s p []\"\n  by (clarsimp simp:bytes_at_def)\n\ntext \\<open>The bytes of typed pointer @{term p} are @{term bs}.\\<close>\ndefinition\n  bytes_of :: \"'a globals_scheme \\<Rightarrow> 'b::c_type ptr \\<Rightarrow> word8 list \\<Rightarrow> bool\"\nwhere\n  \"bytes_of s p bs \\<equiv> length bs = size_of TYPE('b) \\<and> bytes_at s p bs\"\n\ntext \\<open>The bytes at a char pointer are just it dereferenced.\\<close>\nlemma bytes_of_char[simp]: \"bytes_of s (p::8word ptr) bs = (length bs = 1 \\<and> deref s p = hd bs)\"\n  apply (clarsimp simp:bytes_of_def bytes_at_def)\n  apply (rule iffI)\n   apply clarsimp\n   apply (erule disjE)\n    apply clarsimp+\n   apply (rule hd_conv_nth[symmetric])\n   apply clarsimp+\n  apply (subgoal_tac \"hd bs = bs ! 0\")\n   apply simp\n  apply (rule hd_conv_nth)\n  apply clarsimp\n  done\n\ntext \\<open>A pointer does not wrap around memory.\\<close>\ndefinition\n  no_wrap :: \"'a::c_type ptr \\<Rightarrow> nat \\<Rightarrow> bool\"\nwhere\n  \"no_wrap p sz \\<equiv> 0 \\<notin> {ptr_val p ..+ sz}\"\n\ntext \\<open>Two pointers do not overlap.\\<close>\ndefinition\n  no_overlap :: \"'a::c_type ptr \\<Rightarrow> 'b::c_type ptr \\<Rightarrow> nat \\<Rightarrow> bool\"\nwhere\n  \"no_overlap p q sz \\<equiv> {ptr_val p ..+ sz} \\<inter> {ptr_val q ..+ sz} = {}\"\n\nlemma no_overlap_sym: \"no_overlap x y = no_overlap y x\"\n  apply (rule ext)\n  apply (clarsimp simp:no_overlap_def)\n  by blast\n\n(* FIXME: MOVE *)\nlemma h_val_not_id:\n  fixes x :: \"'a::mem_type ptr\"\n    and y :: \"'b::mem_type ptr\"\n  shows \"{ptr_val x..+size_of TYPE('a)} \\<inter> {ptr_val y..+size_of TYPE('b)} = {}\n     \\<Longrightarrow> h_val (hrs_mem (hrs_mem_update (heap_update x v) s)) y = h_val (hrs_mem s) y\"\n  apply (subst hrs_mem_heap_update[symmetric])\n  apply (subst h_val_heap_update_disjoint)\n   apply blast\n  apply clarsimp\n  done\n\ndefinition\n  update_bytes :: \"'a globals_scheme \\<Rightarrow> 'b::mem_type ptr \\<Rightarrow> word8 list \\<Rightarrow> 'a globals_scheme\"\nwhere\n  \"update_bytes s p bs \\<equiv> s\\<lparr>t_hrs_' := hrs_mem_update (heap_update_list (ptr_val p) bs) (t_hrs_' s)\\<rparr>\"\n\nlemma the_horse_says_neigh: \"(s\\<lparr>t_hrs_' := x\\<rparr> = s\\<lparr>t_hrs_' := y\\<rparr>) = (x = y)\"\n by (metis (erased, lifting) globals.cases_scheme globals.select_convs(1) globals.update_convs(1))\n\nlemma upto_singleton[simp]:\"[x..x] = [x]\"\n  by (simp add: upto_rec1)\n\nlemma update_bytes_ignore_ptr_coerce[simp]: \"update_bytes s (ptr_coerce p) = update_bytes s p\"\n  by (auto simp:update_bytes_def)\n\nlemma hrs_mem_update_commute:\n  \"f \\<circ> g = g \\<circ> f \\<Longrightarrow> hrs_mem_update f (hrs_mem_update g s) = hrs_mem_update g (hrs_mem_update f s)\"\n  by (metis (no_types, lifting) comp_eq_elim hrs_htd_def hrs_htd_mem_update hrs_mem_def hrs_mem_f prod.collapse)\n\nlemma hrs_mem_update_collapse:\n  \"hrs_mem_update f (hrs_mem_update g s) = hrs_mem_update (f \\<circ> g) s\"\n  by (metis comp_eq_dest_lhs hrs_htd_def hrs_htd_mem_update hrs_mem_def hrs_mem_f prod.collapse)\n\nlemma update_bytes_reorder:\n  \"{ptr_val p..+length cs} \\<inter> {ptr_val q..+length bs} = {} \\<Longrightarrow>\n      update_bytes (update_bytes s q bs) p cs = update_bytes (update_bytes s p cs) q bs\"\n  apply (clarsimp simp:update_bytes_def)\n  apply (subst the_horse_says_neigh)\n  apply (subst hrs_mem_update_commute)\n   apply (rule ext)\n   apply clarsimp\n   apply (subst heap_update_list_commute)\n    apply clarsimp+\n  done\n\nlemma lt_step_down: \"\\<lbrakk>(x::nat) < y; x = y - 1 \\<longrightarrow> P; x < y - 1 \\<longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  by force\n\n(* XXX: This proof makes me sad. *)\nlemma under_uint_imp_no_overflow: \"x < ADDR_MAX \\<Longrightarrow> ((of_nat x)::addr) + 1 \\<noteq> 0\"\n  apply (induct x)\n   apply (clarsimp simp:UWORD_MAX_def)+\n  apply unat_arith\n  apply (clarsimp simp:UWORD_MAX_def)\n  apply (cut_tac y=x and z=\"(of_nat (ADDR_MAX - 1))::addr\" in le_unat_uoi)\n   apply (clarsimp simp:UWORD_MAX_def)+\n  done\n\nlemma heap_update_list_append3:\n  \"1 + length ys < 2 ^ word_bits \\<Longrightarrow>\n    heap_update_list s (y # ys) hp = heap_update_list s [y] (heap_update_list (s + 1) ys hp)\"\n  apply clarsimp\n  apply (subst heap_update_list_append2[where xs=\"[y]\", simplified])\n   apply clarsimp+\n  done\n\nlemma hrs_mem_update_cong': \"f = g \\<Longrightarrow> hrs_mem_update f s = hrs_mem_update g s\"\n  by presburger\n\nlemma update_bytes_append: \"length bs \\<le> ADDR_MAX \\<Longrightarrow>\n  update_bytes s p (b # bs) = update_bytes (update_bytes s p [b]) (byte_cast p +\\<^sub>p 1) bs\"\n  apply (clarsimp simp:update_bytes_def)\n  apply (subst the_horse_says_neigh)\n  apply (subst hrs_mem_update_commute)\n   apply (rule ext)+\n   apply simp\n   apply (case_tac \"xa = ptr_val p\")\n    apply (clarsimp simp:fun_upd_def)\n    apply (subst heap_update_nmem_same)\n     apply (clarsimp simp:intvl_def ptr_add_def)\n     apply (subgoal_tac \"k < ADDR_MAX\")\n      prefer 2\n      apply unat_arith\n     apply (drule under_uint_imp_no_overflow)\n     apply unat_arith\n    apply clarsimp\n   apply (subst heap_update_list_update)\n    apply simp\n   apply (clarsimp simp:fun_upd_def)\n  apply (subst hrs_mem_update_collapse)\n  apply (rule hrs_mem_update_cong')\n  apply (clarsimp simp:ptr_add_def)\n  apply (rule ext)\n  apply (cut_tac xs=\"[b]\" and ys=bs and s=\"ptr_val p\" and hp=x in heap_update_list_append)\n  apply (rule ext)\n  apply (clarsimp simp:fun_upd_def)\n  apply (rule conjI)\n   apply clarsimp\n   apply (subst heap_update_nmem_same)\n    apply (clarsimp simp:ptr_add_def intvl_def)\n    apply (subgoal_tac \"k < ADDR_MAX\")\n     prefer 2\n     apply unat_arith\n    apply (drule under_uint_imp_no_overflow)\n    apply unat_arith\n   apply clarsimp\n  apply clarsimp\n  apply (case_tac \"xa \\<in> {ptr_val p + 1..+length bs}\")\n  apply (subst heap_update_mem_same_point)\n    apply simp\n   apply (subgoal_tac \"addr_card = ADDR_MAX + 1\")\n    apply clarsimp\n   apply (clarsimp simp:addr_card UWORD_MAX_def)\n  apply (subst heap_update_mem_same_point)\n    apply simp\n   apply (subgoal_tac \"addr_card = ADDR_MAX + 1\")\n    apply clarsimp\n   apply (clarsimp simp:addr_card UWORD_MAX_def)\n  apply clarsimp\n  apply (subst heap_update_nmem_same)\n   apply clarsimp\n  apply (subst heap_update_nmem_same)\n   apply clarsimp+\n  done\n\nlemma update_bytes_postpend: \"length bs = x + 1 \\<Longrightarrow>\n  update_bytes s p bs = update_bytes (update_bytes s p (take x bs)) (byte_cast p +\\<^sub>p (of_nat x)) [bs ! x]\"\n  apply (clarsimp simp:update_bytes_def)\n  apply (subst the_horse_says_neigh)\n  apply (clarsimp simp:ptr_add_def)\n  apply (subst heap_update_list_concat_fold_hrs_mem)\n   apply clarsimp+\n  apply (metis append.right_neutral append_eq_conv_conj lessI take_Suc_conv_app_nth)\n  done\n\nlemma h_val_not_id_general:\n  fixes y :: \"'a::mem_type ptr\"\n  shows \"\\<forall>i \\<in> {0..+size_of TYPE('a)}. \\<forall>g. f g (ptr_val y + i) = g (ptr_val y + i)\n     \\<Longrightarrow> h_val (hrs_mem (hrs_mem_update f s)) y = h_val (hrs_mem s) y\"\n  apply (subst hrs_mem_update)\n  apply (clarsimp simp:h_val_def)\n  apply (subgoal_tac \"heap_list (f (hrs_mem s)) (size_of TYPE('a)) (ptr_val y) =\n                      heap_list (hrs_mem s) (size_of TYPE('a)) (ptr_val y)\")\n   apply clarsimp\n  apply (cut_tac h=\"f (hrs_mem s)\" and p=\"ptr_val y\" and n=\"size_of TYPE('a)\"\n                 and h'=\"hrs_mem s\" in heap_list_h_eq2)\n   apply (erule_tac x=\"x - ptr_val y\" in  ballE)\n    apply clarsimp\n   apply (clarsimp simp:intvl_def)+\n  done\n\nlemma h_val_not_id_list:\n  fixes y :: \"'a::mem_type ptr\"\n  shows \"{x..+length vs} \\<inter> {ptr_val y..+size_of TYPE('a)} = {}\n     \\<Longrightarrow> h_val (hrs_mem (hrs_mem_update (heap_update_list x vs) s)) y = h_val (hrs_mem s) y\"\n  apply (subst h_val_not_id_general)\n   apply clarsimp\n   apply (metis (erased, opaque_lifting) disjoint_iff_not_equal heap_update_nmem_same intvlD intvlI\n          monoid_add_class.add.left_neutral)\n  apply clarsimp\n  done\n\nlemma h_val_id_update_bytes:\n  fixes q :: \"'a::mem_type ptr\"\n  shows \"{ptr_val q..+size_of TYPE('a)} \\<inter> {ptr_val p..+length bs} = {}\n          \\<Longrightarrow> deref (update_bytes s p bs) q = deref s q\"\n  apply (clarsimp simp:update_bytes_def)\n  apply (subst h_val_not_id_list)\n   apply blast\n  by simp\n\nlemma bytes_at_len: \"bytes_at s p bs \\<Longrightarrow> length bs \\<le> ADDR_MAX\"\n  by (clarsimp simp:bytes_at_def, fastforce)\n\n(* Another sad proof. *)\nlemma le_uint_max_imp_id: \"x \\<le> ADDR_MAX \\<Longrightarrow> unat ((of_nat x)::addr) = x\"\n  apply (induct x)\n   apply (clarsimp simp: UWORD_MAX_def)+\n  apply unat_arith\n  apply clarsimp\n  done\n\nlemma update_bytes_id: \"update_bytes s p [] = s\"\n  apply (clarsimp simp:update_bytes_def)\n  apply (subst heap_update_list_base')\n  by (simp add: hrs_mem_update_id3)\n\nlemma a_horse_by_any_other_name: \"t_hrs_'_update f s = s\\<lparr>t_hrs_' := f (t_hrs_' s)\\<rparr>\"\n  by auto\n\nlemma heap_update_list_singleton: \"heap_update_list p [x] = heap_update (Ptr p) x\"\n  apply (rule ext)\n  by (metis heap_update_def ptr_val.simps to_bytes_word8)\n\nlemma update_bytes_eq: \"\\<lbrakk>s = s'; p = p'; bs = bs'\\<rbrakk> \\<Longrightarrow> update_bytes s p bs = update_bytes s' p' bs'\"\n  by clarsimp\n\ntext \\<open>\n  Memcpy does what it says on the box.\n\\<close>\nlemma memcpy_wp':\n  fixes src :: \"'a::mem_type ptr\"\n    and dst :: \"'b::mem_type ptr\"\n  shows \"\\<forall>s0 bs.\n  \\<lbrace>\\<lambda>s. s = s0 \\<and> c_guard src \\<and> c_guard dst \\<and> sz = of_nat (length bs) \\<and> bytes_at s src bs \\<and>\n       no_wrap src (unat sz) \\<and> no_wrap dst (unat sz) \\<and> no_overlap src dst (unat sz)\\<rbrace>\n    memcpy' (ptr_coerce dst) (ptr_coerce src) sz\n  \\<lbrace>\\<lambda>r s. r = ptr_coerce dst \\<and> bytes_at s dst bs \\<and> s = update_bytes s0 dst bs\\<rbrace>!\"\n  apply (rule allI)+\n  apply (rule validNF_assume_pre)\n  unfolding memcpy'_def\n  apply clarsimp\n  apply (subst whileLoop_add_inv[where\n    I=\"\\<lambda>i s. unat i \\<le> unat sz \\<and>\n             bytes_at s dst (take (unat i) bs) \\<and>\n             bytes_at s src bs \\<and>\n             s = update_bytes s0 dst (take (unat i) bs)\" and\n    M=\"\\<lambda>(i, s). unat sz - unat i\"])\n  apply wp\n    apply clarsimp\n    apply (rule conjI)\n     apply unat_arith\n    apply (rule conjI)\n     apply (simp add:bytes_at_def)\n     apply (case_tac \"bs = []\")\n      apply (rule disjI1)\n      apply clarsimp\n     apply (rule disjI2)\n     apply clarsimp\n     apply (rule conjI)\n      apply unat_arith\n     apply clarsimp\n     apply (case_tac \"unat i = ia\")\n      apply clarsimp\n      apply (subgoal_tac \"int (unat i) = uint i\")\n       prefer 2\n       apply (subst uint_nat)\n       apply simp\n      apply simp\n      apply (subst h_val_id)\n      apply (subst h_val_id_update_bytes)\n       apply (clarsimp simp:no_overlap_def ptr_add_def)\n       apply (subgoal_tac \"{ptr_val src + i..+Suc 0} \\<subseteq> {ptr_val src..+unat (of_nat_addr (length bs))}\")\n        prefer 2\n        apply (clarsimp simp:intvl_def)\n        apply (rule_tac x=\"unat i\" in exI)\n        apply unat_arith\n       apply (subgoal_tac \"{ptr_val dst..+unat i} \\<subseteq> {ptr_val dst..+unat (of_nat_addr (length bs))}\")\n        prefer 2\n        apply (clarsimp simp:intvl_def)\n        apply (rule exI, rule conjI, rule refl)\n        apply (simp add: unat_of_nat)\n       apply blast\n      apply (erule_tac x=\"unat i\" and P=\"\\<lambda>x. deref s0 (byte_cast src +\\<^sub>p int x) = bs ! x\" in ballE)\n       apply clarsimp\n       apply (subst nth_take)\n        apply unat_arith\n       apply simp\n      apply (erule disjE)\n       apply clarsimp+\n     apply (erule disjE)\n      apply (subgoal_tac \"length bs \\<noteq> 0\")\n       prefer 2\n       apply clarsimp\n      apply (case_tac \"unat i = 0\")\n       apply unat_arith\n      apply linarith\n     apply (subst h_val_not_id)\n      apply (clarsimp simp:ptr_add_def intvl_def)\n      (* Isabelle, why do you have to make it so hard? *)\n      apply (erule_tac P=\"unat (of_nat ia) = ia\" in notE)\n      apply (cut_tac y=ia and z=\"(of_nat ADDR_MAX)::addr\" in le_unat_uoi)\n       apply (subgoal_tac \"unat ((of_nat ADDR_MAX)::addr) = ADDR_MAX\")\n        prefer 2\n        apply (simp add: unat_of_nat)\n       apply (simp add: unat_of_nat)\n      apply clarsimp\n     apply clarsimp\n     apply (erule_tac x=ia and A=\"{0..min (length bs) (unat i) - Suc 0}\" in ballE)\n      apply clarsimp\n      apply (subst nth_take, unat_arith)+\n      apply simp\n     apply clarsimp\n     apply unat_arith\n    apply (rule conjI)\n     apply (clarsimp simp:bytes_at_def)\n     apply (subst h_val_not_id)\n      apply (clarsimp simp:no_overlap_def)\n      apply (subgoal_tac \"ptr_val (byte_cast dst +\\<^sub>p uint i) \\<in> {ptr_val dst..+unat (of_nat (length bs))}\")\n       prefer 2\n       apply (clarsimp simp:ptr_add_def intvl_def)\n       apply (rule_tac x=\"unat i\" in exI)\n       apply clarsimp\n       apply unat_arith\n      (* More or less symmetric subgoal *)\n      apply (subgoal_tac \"ptr_val (byte_cast src +\\<^sub>p int ia) \\<in> {ptr_val src..+unat ((of_nat (length bs))::addr)}\")\n       prefer 2\n       apply (clarsimp simp:ptr_add_def intvl_def)\n       apply (rule_tac x=ia in exI)\n       apply clarsimp\n       apply (subgoal_tac \"unat ((of_nat (length bs))::addr) = length bs\")\n        apply clarsimp\n        apply arith\n       apply (cut_tac y=\"length bs\" and z=\"(of_nat ADDR_MAX)::addr\" in le_unat_uoi)\n        apply (simp add: unat_of_nat)\n       apply arith\n      apply (clarsimp simp:intvl_def ptr_add_def)\n      apply blast\n     apply clarsimp\n    apply (rule conjI)\n     apply (subst h_val_id_update_bytes)\n      apply (clarsimp simp:no_overlap_def ptr_add_def)\n      apply (subgoal_tac \"{ptr_val src + i..+Suc 0} \\<subseteq> {ptr_val src..+unat (of_nat_addr (length bs))}\")\n       prefer 2\n       apply (clarsimp simp:intvl_def)\n       apply (rule_tac x=\"unat i\" in exI)\n       apply unat_arith\n      apply (subgoal_tac \"{ptr_val dst..+min (length bs) (unat i)} \\<subseteq> {ptr_val dst..+unat (of_nat_addr (length bs))}\")\n       prefer 2\n       apply (clarsimp simp:intvl_def)\n       apply (rule_tac x=ka in exI)\n       apply unat_arith\n      apply blast\n     apply (subgoal_tac \"deref s0 (byte_cast src +\\<^sub>p uint i) = bs ! (unat i)\")\n      apply clarsimp\n      apply (subgoal_tac \"update_bytes s0 dst (take (unat (i + 1)) bs) =\n                          update_bytes (update_bytes s0 dst (take (unat i) bs)) (byte_cast dst +\\<^sub>p uint i) [bs ! unat i]\")\n       apply clarsimp\n       apply (subgoal_tac\n               \"\\<forall>s'. t_hrs_'_update (hrs_mem_update (heap_update (byte_cast dst +\\<^sub>p uint i) (bs ! unat i))) s' =\n                     update_bytes s' (byte_cast dst +\\<^sub>p uint i) [bs ! unat i]\")\n        apply fast\n       apply (clarsimp simp:update_bytes_def)\n       apply (subst a_horse_by_any_other_name)\n       apply (subst the_horse_says_neigh)\n       apply (clarsimp simp:ptr_add_def)\n       apply (subst heap_update_list_singleton)\n       apply simp\n      apply (cut_tac s=s0 and p=dst and bs=\"take (unat (i + 1)) bs\" and x=\"unat i\"\n                     in update_bytes_postpend)\n       apply (subgoal_tac \"unat (i + 1) \\<le> length bs\")\n        apply clarsimp\n        apply unat_arith\n       apply (subgoal_tac \"unat i < length bs\")\n        apply unat_arith\n       apply (rule unat_less_helper)\n       apply simp\n      apply clarsimp\n      apply (rule update_bytes_eq)\n        apply (subgoal_tac \"min (unat i) (unat (i + 1)) = unat i\")\n         apply presburger\n        apply unat_arith\n       apply (clarsimp simp:ptr_add_def)\n      apply clarsimp\n      apply (rule nth_take)\n      apply unat_arith\n     apply (clarsimp simp:bytes_at_def)\n     apply (erule disjE)\n      apply clarsimp\n     apply clarsimp\n     apply (erule_tac x=\"unat i\" in ballE)\n      apply (subst (asm) uint_nat[symmetric])\n      apply simp\n     apply clarsimp\n     apply (subgoal_tac \"unat i < length bs\")\n      prefer 2\n      apply (rule unat_less_helper)\n      apply simp\n     apply unat_arith\n    apply (rule conjI)\n     apply unat_arith\n    apply (rule conjI)\n     apply (rule byte_ptr_guarded)\n     apply (clarsimp simp:no_wrap_def intvl_def ptr_add_def)\n     apply (erule_tac x=\"unat i\" in allE)\n     apply clarsimp\n    apply (rule byte_ptr_guarded)\n    apply (clarsimp simp:no_wrap_def intvl_def ptr_add_def)\n    apply (erule_tac x=\"unat i\" and\n                     P=\"\\<lambda>x. ptr_val dst + ((of_nat x)::addr) = 0 \\<longrightarrow> \\<not> x < unat ((of_nat_addr (length bs))::addr)\"\n                    in allE)\n    apply clarsimp\n   apply clarsimp\n   apply (rule conjI)\n    apply (subgoal_tac \"unat i = length bs\")\n     apply clarsimp\n    apply (case_tac \"length bs = 0\")\n     apply clarsimp\n    apply (subgoal_tac \"length bs \\<le> ADDR_MAX\")\n     prefer 2\n     apply (clarsimp simp:bytes_at_def)\n    (* XXX: We keep introducing this subgoal; we should do it once and for all up top. *)\n    apply (subgoal_tac \"unat ((of_nat (length bs))::addr) = length bs\")\n     prefer 2\n     apply (cut_tac y=\"length bs\" and z=\"(of_nat ADDR_MAX)::addr\" in le_unat_uoi)\n      apply (clarsimp simp:UWORD_MAX_def)\n     apply clarsimp+\n    apply unat_arith\n   (* insert a bunch a tedium... *)\n   apply (subgoal_tac \"unat i = length bs\")\n    prefer 2\n    apply (drule bytes_at_len)\n    apply (subgoal_tac \"unat (of_nat_addr (length bs)) = length bs\")\n     prefer 2\n     apply (rule le_uint_max_imp_id)\n     apply simp\n    apply unat_arith\n   apply clarsimp\n  apply (simp add:update_bytes_id)\n  done\n\nlemma validNF_make_schematic_post':\n  \"(\\<forall>s0 x. \\<lbrace> \\<lambda>s. P s0 x s \\<rbrace> f \\<lbrace> \\<lambda>rv s. Q s0 x rv s \\<rbrace>!) \\<Longrightarrow>\n   \\<lbrace> \\<lambda>s. \\<exists>s0 x. P s0 x s \\<and> (\\<forall>rv s'. Q s0 x rv s' \\<longrightarrow> Q' rv s') \\<rbrace> f \\<lbrace> Q'\\<rbrace>!\"\n  by (auto simp add: valid_def validNF_def no_fail_def split: prod.splits)\n\nlemmas memcpy_wp = memcpy_wp'[THEN validNF_make_schematic_post', simplified]\n\nlemma h_val_not_id_update_bytes:\n  fixes q :: \"'a::mem_type ptr\"\n  shows \"\\<lbrakk>ptr_val p = ptr_val q; length bs = size_of TYPE('a)\\<rbrakk> \\<Longrightarrow>\n            deref (update_bytes s p bs) q = from_bytes bs\"\n  apply (clarsimp simp:update_bytes_def h_val_def)\n  apply (subst hrs_mem_update)\n  apply (cut_tac p=\"ptr_val q\" and v=bs and h=\"hrs_mem (t_hrs_' s)\" in heap_list_update)\n   apply clarsimp\n   apply (metis less_imp_le max_size)\n  by clarsimp\n\ntext \\<open>\n  Test that we can use memcpy in a compositional proof. The following proof can be done much more\n  pleasantly, but we're just trying to check that the memcpy WP lemma is usable.\n  TODO: This relies on disabling heap abstraction for the calling function as well. We should be\n  able to phrase an exec_concrete WP lemma over memcpy that lets us prove properties about\n  heap-abstracted callers. This will need AutoCorres support to connect is_valid_* with\n  c_guard/no_overlap/no_wrap.\n\\<close>\n\ndefinition\n  memcpy_int_spec :: \"sword32 ptr \\<Rightarrow> sword32 ptr \\<Rightarrow> bool\"\nwhere\n  \"memcpy_int_spec dst src \\<equiv>\n    \\<forall>x. \\<lbrace>\\<lambda>s. deref s src = x \\<and>\n             {ptr_val src..+4} \\<inter> {ptr_val dst..+4} = {} \\<and>\n             c_guard src \\<and> c_guard dst \\<and>\n             no_wrap src 4 \\<and> no_wrap dst 4\\<rbrace>\n          memcpy_int' dst src\n        \\<lbrace>\\<lambda>_ s. deref s dst = x\\<rbrace>!\"\n\nlemma memcpy_int_wp'[unfolded memcpy_int_spec_def]: \"memcpy_int_spec dst src\"\n  unfolding memcpy_int_spec_def\n  apply (rule allI)\n  unfolding memcpy_int'_def\n  apply (wp memcpy_wp)\n  apply clarsimp\n  apply (rule_tac x=\"[deref s (byte_cast src),\n                      deref s (byte_cast src +\\<^sub>p 1),\n                      deref s (byte_cast src +\\<^sub>p 2),\n                      deref s (byte_cast src +\\<^sub>p 3)]\" in exI)\n  apply (clarsimp simp:bytes_at_def no_overlap_def UINT_MAX_def)\n  apply (rule conjI)\n   apply clarsimp\n   apply (case_tac \"i = 0\", clarsimp)\n   apply (case_tac \"i = 1\", clarsimp)\n   apply (case_tac \"i = 2\", clarsimp)\n   apply (case_tac \"i = 3\", clarsimp)\n   apply clarsimp\n  apply clarsimp\n  apply (subst h_val_not_id_update_bytes)\n    apply clarsimp+\n  apply (clarsimp simp:h_val_def)\n  apply (subgoal_tac \"heap_list (hrs_mem (t_hrs_' s)) 4 (ptr_val src) =\n                      deref s (byte_cast src) # (heap_list (hrs_mem (t_hrs_' s)) 3 (ptr_val src + 1))\")\n   prefer 2\n   apply (clarsimp simp:h_val_def)\n   apply (metis Suc_numeral from_bytes_eq heap_list_rec semiring_norm(2) semiring_norm(8))\n  apply (subgoal_tac \"heap_list (hrs_mem (t_hrs_' s)) 3 (ptr_val src + 1) =\n                      deref s (byte_cast src +\\<^sub>p 1) # (heap_list (hrs_mem (t_hrs_' s)) 2 (ptr_val src + 2))\")\n   prefer 2\n   apply (clarsimp simp:h_val_def ptr_add_def)\n   apply (cut_tac h=\"hrs_mem (t_hrs_' s)\" and p=\"ptr_val src + 1\" and n=2 in heap_list_rec)\n   apply clarsimp\n   apply (simp add: add.commute from_bytes_eq)\n  apply clarsimp\n  apply (subgoal_tac \"heap_list (hrs_mem (t_hrs_' s)) 2 (ptr_val src + 2) =\n                      deref s (byte_cast src +\\<^sub>p 2) # (heap_list (hrs_mem (t_hrs_' s)) 1 (ptr_val src + 3))\")\n   prefer 2\n   apply (cut_tac h=\"hrs_mem (t_hrs_' s)\" and p=\"ptr_val src + 2\" and n=3 in heap_list_rec)\n   apply (clarsimp simp:h_val_def ptr_add_def from_bytes_eq)\n   apply (metis (no_types) Suc_eq_plus1 heap_list_base heap_list_rec is_num_normalize(1)\n                monoid_add_class.add.left_neutral one_add_one one_plus_numeral semiring_norm(3))\n  apply (clarsimp simp:h_val_def ptr_add_def from_bytes_eq)\n  done\n\ntext \\<open>memcpying a typed variable is equivalent to assignment.\\<close>\nlemma memcpy_type_wp':\n  fixes dst :: \"'a::mem_type ptr\"\n    and src :: \"'a::mem_type ptr\"\n  shows \"\\<forall>s0 bs.\n   \\<lbrace>\\<lambda>s. s = s0 \\<and> c_guard dst \\<and> c_guard src \\<and> sz = of_nat (size_of TYPE('a)) \\<and>\n        no_overlap dst src (unat sz) \\<and> no_wrap dst (unat sz) \\<and> no_wrap src (unat sz) \\<and>\n        bytes_of s src bs\\<rbrace>\n     memcpy' (ptr_coerce dst) (ptr_coerce src) sz\n   \\<lbrace>\\<lambda>r s. r = ptr_coerce dst \\<and> bytes_of s dst bs \\<and> s = update_bytes s0 dst bs\\<rbrace>!\"\n  apply (rule allI)+\n  apply (wp memcpy_wp)\n  apply clarsimp\n  apply (rule_tac x=bs in exI)\n  apply clarsimp\n  apply (subst no_overlap_sym)\n  apply (clarsimp simp:bytes_of_def)\n  done\n\nlemmas memcpy_type_wp = memcpy_type_wp'[THEN validNF_make_schematic_post', simplified]\n\ntext \\<open>Confirm that we can also prove memcpy_int using the previous generic lemma.\\<close>\nlemma memcpy_int_wp''[unfolded memcpy_int_spec_def]: \"memcpy_int_spec dst src\"\n  unfolding memcpy_int_spec_def memcpy_int'_def\n  apply (rule allI)\n  apply (wp memcpy_type_wp)\n  (* Remainder mostly clagged from the original proof above. *)\n  apply clarsimp\n  apply (rule conjI, clarsimp simp:no_overlap_def, blast)\n  apply (rule_tac x=\"[deref s (byte_cast src),\n                      deref s (byte_cast src +\\<^sub>p 1),\n                      deref s (byte_cast src +\\<^sub>p 2),\n                      deref s (byte_cast src +\\<^sub>p 3)]\" in exI)\n  apply (rule conjI)\n   apply (clarsimp simp:bytes_of_def bytes_at_def UINT_MAX_def)\n   apply (case_tac \"i = 0\", clarsimp)\n   apply (case_tac \"i = 1\", clarsimp)\n   apply (case_tac \"i = 2\", clarsimp)\n   apply (case_tac \"i = 3\", clarsimp)\n   apply clarsimp\n  apply clarsimp\n  apply (subst h_val_not_id_update_bytes, clarsimp+)\n  apply (clarsimp simp:h_val_def)\n  apply (subgoal_tac \"heap_list (hrs_mem (t_hrs_' s)) 4 (ptr_val src) =\n                      deref s (byte_cast src) # (heap_list (hrs_mem (t_hrs_' s)) 3 (ptr_val src + 1))\")\n   prefer 2\n   apply (clarsimp simp:h_val_def from_bytes_eq)\n   apply (subst heap_list_rec[symmetric])\n   apply simp\n  apply (subgoal_tac \"heap_list (hrs_mem (t_hrs_' s)) 3 (ptr_val src + 1) =\n                      deref s (byte_cast src +\\<^sub>p 1) # (heap_list (hrs_mem (t_hrs_' s)) 2 (ptr_val src + 2))\")\n   prefer 2\n   apply (clarsimp simp:h_val_def ptr_add_def)\n   apply (cut_tac h=\"hrs_mem (t_hrs_' s)\" and p=\"ptr_val src + 1\" and n=2 in heap_list_rec)\n   apply (clarsimp simp: from_bytes_eq)\n   apply (metis add.commute)\n  apply clarsimp\n  apply (subgoal_tac \"heap_list (hrs_mem (t_hrs_' s)) 2 (ptr_val src + 2) =\n                      deref s (byte_cast src +\\<^sub>p 2) # (heap_list (hrs_mem (t_hrs_' s)) 1 (ptr_val src + 3))\")\n   prefer 2\n   apply (cut_tac h=\"hrs_mem (t_hrs_' s)\" and p=\"ptr_val src + 2\" and n=3 in heap_list_rec)\n   apply (clarsimp simp:h_val_def ptr_add_def from_bytes_eq)\n   apply (metis (no_types) Suc_eq_plus1 heap_list_base heap_list_rec is_num_normalize(1)\n                monoid_add_class.add.left_neutral one_add_one one_plus_numeral semiring_norm(3))\n  apply (clarsimp simp:h_val_def ptr_add_def from_bytes_eq)\n  done\n\nlemma bytes_of_imp_at[simp]: \"bytes_of s x bs \\<Longrightarrow> bytes_at s x bs\"\n  by (clarsimp simp:bytes_of_def bytes_at_def)\n\nlemma bytes_at_imp_of:\n  fixes x :: \"'a::mem_type ptr\"\n  shows \"\\<lbrakk>bytes_at s x bs; length bs = size_of TYPE('a)\\<rbrakk> \\<Longrightarrow> bytes_of s x bs\"\n  by (clarsimp simp:bytes_of_def bytes_at_def)\n\ntext \\<open>\n  Memcpying from a source to a destination via an intermediary does what it should. This is close to\n  the desirable property we want for CAmkES systems; i.e. that copying into your IPC buffer on one\n  side and then out on the other gives you back what you put in. Note that the type of the\n  intermediate pointer is irrelevant and we don't need to assume that the source and final\n  destination do not overlap.\n\\<close>\nlemma memcpy_seq:\n  fixes x :: \"'a::mem_type ptr\"\n    and y :: \"'b::mem_type ptr\"\n    and z :: \"'a::mem_type ptr\"\n  shows \"\\<forall>s0 bs.\n   \\<lbrace>\\<lambda>s. s = s0 \\<and> sz = of_nat (size_of TYPE('a)) \\<and>\n        c_guard x \\<and> c_guard y \\<and> c_guard z \\<and>\n        no_wrap x (unat sz) \\<and> no_wrap y (unat sz) \\<and> no_wrap z (unat sz) \\<and>\n        no_overlap x y (unat sz) \\<and> no_overlap y z (unat sz) \\<and>\n        bytes_of s x bs\\<rbrace>\n    do memcpy' (ptr_coerce y) (ptr_coerce x) sz;\n       memcpy' (ptr_coerce z) (ptr_coerce y) sz\n    od\n   \\<lbrace>\\<lambda>r s. r = ptr_coerce z \\<and> bytes_of s z bs\\<rbrace>!\"\n  apply (rule allI)+\n  apply (wp memcpy_wp)\n  apply clarsimp\n  apply (rule_tac x=bs in exI)\n  apply clarsimp\n  apply (rule conjI, clarsimp simp:bytes_of_def)\n  apply clarsimp\n  apply (rule_tac x=bs in exI)\n  apply (rule conjI, clarsimp simp:bytes_of_def)\n  apply clarsimp\n  apply (rule bytes_at_imp_of)\n   apply (clarsimp simp:bytes_of_def)+\n  done\n\nlemma update_ti_eq:\n  fixes x :: \"'a::mem_type\"\n    and y :: 'a\n  shows \"\\<lbrakk>length bs = size_of TYPE('a); bs = bs'\\<rbrakk>\n          \\<Longrightarrow> update_ti_t (typ_info_t TYPE('a)) bs x = update_ti_t (typ_info_t TYPE('a)) bs' y\"\n  by (clarsimp simp:upd)\n\nlemma from_bytes_cong: \"x = y \\<Longrightarrow> from_bytes x = from_bytes y\"\n  by simp\n\ndeclare from_bytes_eq [simp]\n\ntext \\<open>\n  If you dereference a pointer, the value you get is the same as the underlying bytes backing that\n  memory.\n\\<close>\nlemma val_eq_bytes:\n  fixes x :: \"'a::mem_type ptr\"\n  shows \"deref s x = from_bytes (map (\\<lambda>off. deref s (byte_cast x +\\<^sub>p of_nat off)) [0..<size_of TYPE('a)])\"\n  apply (clarsimp simp:h_val_def ptr_add_def)\n  apply (rule from_bytes_cong)\n  apply (rule nth_equalityI)\n   apply clarsimp+\n  apply (subst heap_list_nth)\n   apply clarsimp+\n  done\n\nlemma extract_list_elem: \"i < n \\<Longrightarrow> f i = (map f [0..<n]) ! i\"\n  apply (induct i)\n   apply clarsimp+\n  done\n\nlemma update_deref:\n  fixes x :: \"'a::mem_type ptr\"\n  shows \"size_of TYPE('a) = length bs \\<Longrightarrow> deref (update_bytes s x bs) x = from_bytes bs\"\n  apply (clarsimp simp:update_bytes_def)\n  apply (subst hrs_mem_update)\n  apply (clarsimp simp:h_val_def)\n  apply (subst heap_list_update)\n   apply (metis less_imp_le max_size)\n  apply clarsimp\n  done\n\ntext \\<open>\n  The memcpy_int proof can now be completed more elegantly. Note that the body of this proof is more\n  generic than the previous attempts and doesn't involve manually reasoning about each byte.\n\\<close>\nlemma memcpy_int_wp'''[unfolded memcpy_int_spec_def]: \"memcpy_int_spec dst src\"\n  unfolding memcpy_int_spec_def memcpy_int'_def\n  apply (rule allI)\n  apply (wp memcpy_type_wp)\n  apply clarsimp\n  apply (rule conjI, clarsimp simp:no_overlap_def, blast)\n  apply (rule_tac x=\"map (\\<lambda>i. deref s (byte_cast src +\\<^sub>p of_nat i)) [0..<size_of TYPE(32sword)]\" in exI)\n  apply (rule conjI)\n   apply (clarsimp simp:bytes_of_def bytes_at_def UINT_MAX_def)+\n  apply (subst update_deref)\n   apply clarsimp\n  apply (cut_tac s=s and x=src in val_eq_bytes)\n  apply clarsimp\n  done\n\nlemma bytes_at_heap_list:\n  fixes x :: \"'a::mem_type ptr\"\n  shows \"\\<lbrakk>n \\<le> ADDR_MAX; no_wrap x n\\<rbrakk>\n          \\<Longrightarrow> bytes_at s x (heap_list (hrs_mem (t_hrs_' s)) n (ptr_val x))\"\n  apply (clarsimp simp:bytes_at_def ptr_add_def h_val_def)\n  apply (subst heap_list_nth)\n   apply unat_arith\n  apply clarsimp\n  done\n\ntext \\<open>\n  A collection of useful type-generic implications for moving from the abstract heap to the concrete\n  heap.\n\\<close>\ndefinition\n  is_valid_imp_c_guard :: \"(lifted_globals \\<Rightarrow> 'b::mem_type ptr \\<Rightarrow> bool) \\<Rightarrow> bool\"\nwhere\n  \"is_valid_imp_c_guard is_valid \\<equiv> \\<forall>s p. is_valid (lift_global_heap s) p \\<longrightarrow> c_guard p\"\ndefinition\n  is_valid_imp_no_null :: \"(lifted_globals \\<Rightarrow> 'b::mem_type ptr \\<Rightarrow> bool) \\<Rightarrow> bool\"\nwhere\n  \"is_valid_imp_no_null is_valid \\<equiv>\n     \\<forall>s p. is_valid (lift_global_heap s) p \\<longrightarrow> 0 \\<notin> {ptr_val p..of_nat (size_of TYPE('b))}\"\ndefinition\n  is_valid_imp_no_wrap :: \"(lifted_globals \\<Rightarrow> 'b::mem_type ptr \\<Rightarrow> bool) \\<Rightarrow> bool\"\nwhere\n  \"is_valid_imp_no_wrap is_valid \\<equiv>\n     \\<forall>s p. is_valid (lift_global_heap s) p \\<longrightarrow> no_wrap p (size_of TYPE('b))\"\ndefinition\n  is_valid_imp_no_overlap :: \"(lifted_globals \\<Rightarrow> 'b::mem_type ptr \\<Rightarrow> bool) \\<Rightarrow> bool\"\nwhere\n  \"is_valid_imp_no_overlap is_valid \\<equiv>\n     \\<forall>s p q. is_valid (lift_global_heap s) p \\<and> is_valid (lift_global_heap s) q \\<and> p \\<noteq> q\n               \\<longrightarrow> no_overlap p q (size_of TYPE('b))\"\ndefinition\n  is_valid_imp_heap_ptr_valid :: \"(lifted_globals \\<Rightarrow> 'b::mem_type ptr \\<Rightarrow> bool) \\<Rightarrow> bool\"\nwhere\n  \"is_valid_imp_heap_ptr_valid is_valid \\<equiv>\n     \\<forall>s p. is_valid (lift_global_heap s) p \\<longrightarrow> heap_ptr_valid (hrs_htd (t_hrs_' s)) p\"\n\ntext \\<open>We can easily discharge these for a given type.\\<close>\nlemma is_valid_w32_imp_c_guard[unfolded is_valid_imp_c_guard_def, simplified]:\n    \"is_valid_imp_c_guard is_valid_w32\"\n  unfolding is_valid_imp_c_guard_def\n  apply clarsimp\n  apply (subst (asm) lifted_globals_ext_simps)\n  apply clarsimp\n  apply (rule simple_lift_c_guard, force)\n  done\n\nlemma is_valid_w32_imp_no_null[unfolded is_valid_imp_no_null_def, simplified]:\n    \"is_valid_imp_no_null is_valid_w32\"\n  unfolding is_valid_imp_no_null_def\n  apply clarsimp\n  apply (subst (asm) lifted_globals_ext_simps)\n  apply clarsimp\n  apply (drule simple_lift_c_guard)\n  apply (clarsimp simp:c_guard_def c_null_guard_def intvl_def)\n  by force\n\nlemma is_valid_w32_imp_no_wrap[unfolded is_valid_imp_no_wrap_def, simplified]:\n    \"is_valid_imp_no_wrap is_valid_w32\"\n  unfolding is_valid_imp_no_wrap_def no_wrap_def\n  apply clarsimp\n  apply (subst (asm) lifted_globals_ext_simps)\n  apply clarsimp\n  apply (drule simple_lift_c_guard)\n  apply (clarsimp simp:c_guard_def c_null_guard_def intvl_def)\n  done\n\nlemma is_valid_w32_imp_no_overlap[unfolded is_valid_imp_no_overlap_def, simplified]:\n    \"is_valid_imp_no_overlap is_valid_w32\"\n  unfolding is_valid_imp_no_overlap_def no_wrap_def\n  apply clarsimp\n  apply (subst (asm) lifted_globals_ext_simps)+\n  apply clarsimp\n  apply (drule simple_lift_heap_ptr_valid)+\n  apply (clarsimp simp:no_overlap_def)\n  apply (cut_tac p=p and q=q and d=\"hrs_htd (t_hrs_' s)\" in heap_ptr_valid_neq_disjoint)\n     apply clarsimp+\n  done\n\nlemma is_valid_w32_imp_heap_ptr_valid[unfolded is_valid_imp_heap_ptr_valid_def, simplified]:\n    \"is_valid_imp_heap_ptr_valid is_valid_w32\"\n  unfolding is_valid_imp_heap_ptr_valid_def\n  apply clarsimp\n  apply (subst (asm) lifted_globals_ext_simps)\n  apply clarsimp\n  by (rule simple_lift_heap_ptr_valid, force)\n\ntext \\<open>\n  With that support in place, we can now prove a heap-abstracted call to memcpy of a type in a\n  reasonably generic way. Note that we leverage the relationship between\n  is_valid_*/lift_global_heap/simple_lift to transfer assumptions across the boundary between the\n  abstract and concrete heaps.\n\\<close>\nlemma\n  fixes dst :: \"32word ptr\"\n    and src :: \"32word ptr\"\n  shows \"\\<forall>s0 x.\n   \\<lbrace>\\<lambda>s. s = s0 \\<and> is_valid_w32 s dst \\<and> is_valid_w32 s src \\<and> sz = of_nat (size_of TYPE(32word)) \\<and>\n        heap_w32 s src = x \\<and> dst \\<noteq> src\\<rbrace>\n     exec_concrete lift_global_heap (memcpy' (ptr_coerce dst) (ptr_coerce src) sz)\n   \\<lbrace>\\<lambda>r s. r = ptr_coerce dst \\<and> heap_w32 s dst = x\\<rbrace>!\"\n  including nf_no_pre\n  apply (rule allI)+\n  apply (wp memcpy_wp)\n  apply (clarsimp simp:is_valid_w32_imp_c_guard\n                       is_valid_w32_imp_no_wrap\n                       is_valid_w32_imp_no_overlap)\n  apply (rule_tac x=\"map (\\<lambda>i. deref s (byte_cast src +\\<^sub>p of_nat i)) [0..<size_of TYPE(32word)]\" in exI)\n  apply clarsimp\n  apply (rule conjI)\n   apply (clarsimp simp:bytes_at_def UINT_MAX_def)\n  apply clarsimp\n  apply (subst lifted_globals_ext_simps(3))+\n  apply (clarsimp simp:simple_lift_def is_valid_w32_imp_heap_ptr_valid)\n  apply (rule conjI)\n   apply clarsimp\n   apply (subst update_deref)\n    apply clarsimp+\n   apply (cut_tac s=s and x=src in val_eq_bytes)\n   apply clarsimp\n  apply (clarsimp simp:update_bytes_def is_valid_w32_imp_heap_ptr_valid)\n  done\n\ntext \\<open>\n  Let's do the same instantiation for a structure. Note that the proof text for the following lemmas\n  is identical to the word 32 instantiation above. These could be straightforwardly abstracted into\n  a locale which could be automatically interpreted with the use of generated proofs.\n\\<close>\nlemma is_valid_my_structure_imp_c_guard[unfolded is_valid_imp_c_guard_def, simplified]:\n    \"is_valid_imp_c_guard is_valid_my_structure_C\"\n  unfolding is_valid_imp_c_guard_def\n  apply clarsimp\n  apply (subst (asm) lifted_globals_ext_simps)\n  apply clarsimp\n  apply (rule simple_lift_c_guard, force)\n  done\n\nlemma is_valid_my_structure_imp_no_null[unfolded is_valid_imp_no_null_def, simplified]:\n    \"is_valid_imp_no_null is_valid_my_structure_C\"\n  unfolding is_valid_imp_no_null_def\n  apply clarsimp\n  apply (subst (asm) lifted_globals_ext_simps)\n  apply clarsimp\n  apply (drule simple_lift_c_guard)\n  apply (clarsimp simp:c_guard_def c_null_guard_def intvl_def)\n  by force\n\nlemma is_valid_my_structure_imp_no_wrap[unfolded is_valid_imp_no_wrap_def, simplified]:\n    \"is_valid_imp_no_wrap is_valid_my_structure_C\"\n  unfolding is_valid_imp_no_wrap_def no_wrap_def\n  apply clarsimp\n  apply (subst (asm) lifted_globals_ext_simps)\n  apply clarsimp\n  apply (drule simple_lift_c_guard)\n  apply (clarsimp simp:c_guard_def c_null_guard_def intvl_def)\n  done\n\nlemma is_valid_my_structure_imp_no_overlap[unfolded is_valid_imp_no_overlap_def, simplified]:\n    \"is_valid_imp_no_overlap is_valid_my_structure_C\"\n  unfolding is_valid_imp_no_overlap_def no_wrap_def\n  apply clarsimp\n  apply (subst (asm) lifted_globals_ext_simps)+\n  apply clarsimp\n  apply (drule simple_lift_heap_ptr_valid)+\n  apply (clarsimp simp:no_overlap_def)\n  apply (cut_tac p=p and q=q and d=\"hrs_htd (t_hrs_' s)\" in heap_ptr_valid_neq_disjoint)\n     apply clarsimp+\n  done\n\nlemma is_valid_my_structure_imp_heap_ptr_valid[unfolded is_valid_imp_heap_ptr_valid_def, simplified]:\n    \"is_valid_imp_heap_ptr_valid is_valid_my_structure_C\"\n  unfolding is_valid_imp_heap_ptr_valid_def\n  apply clarsimp\n  apply (subst (asm) lifted_globals_ext_simps)\n  apply clarsimp\n  by (rule simple_lift_heap_ptr_valid, force)\n\ntext \\<open>\n  Again, we can now trivially transfer Hoare triple properties.\n\\<close>\nlemma\n  fixes dst :: \"my_structure_C ptr\"\n    and src :: \"my_structure_C ptr\"\n  shows \"\\<forall>s0 x.\n   \\<lbrace>\\<lambda>s. s = s0 \\<and> is_valid_my_structure_C s dst \\<and> is_valid_my_structure_C s src \\<and>\n        heap_my_structure_C s src = x \\<and> dst \\<noteq> src\\<rbrace>\n     memcpy_struct' dst src\n   \\<lbrace>\\<lambda>r s. r = dst \\<and> heap_my_structure_C s dst = x\\<rbrace>!\"\n  including nf_no_pre\n  apply (rule allI)+\n  unfolding memcpy_struct'_def\n  apply (wp memcpy_wp)\n  apply (clarsimp simp:is_valid_my_structure_imp_c_guard)\n  apply (rule_tac x=\"map (\\<lambda>i. deref s (byte_cast src +\\<^sub>p of_nat i)) [0..<size_of TYPE(my_structure_C)]\" in exI)\n  apply (clarsimp simp:is_valid_my_structure_imp_no_wrap is_valid_my_structure_imp_no_overlap)\n  apply (rule conjI)\n   apply (clarsimp simp:bytes_at_def UINT_MAX_def)\n  apply clarsimp\n  apply (subst lifted_globals_ext_simps)+\n  apply (clarsimp simp:simple_lift_def is_valid_my_structure_imp_heap_ptr_valid)\n  apply (rule conjI)\n   apply clarsimp\n   apply (subst update_deref)\n    apply clarsimp\n   apply (cut_tac s=s and x=src in val_eq_bytes)\n   apply clarsimp\n  apply (clarsimp simp:update_bytes_def is_valid_my_structure_imp_heap_ptr_valid)\n  done\n\nend\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/autocorres/tests/examples/Memcpy.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6619228758499942, "lm_q2_score": 0.42632159254749036, "lm_q1q2_score": 0.28219201457598425}}
{"text": "subsection \\<open>Heap Monad\\<close>\n\ntheory Heap_Monad_Ext\n  imports \"HOL-Imperative_HOL.Imperative_HOL\"\nbegin\n\ndefinition fun_app_lifted :: \"('a \\<Rightarrow> 'b Heap) Heap \\<Rightarrow> 'a Heap \\<Rightarrow> 'b Heap\" where\n  \"fun_app_lifted f\\<^sub>T x\\<^sub>T \\<equiv> do { f \\<leftarrow> f\\<^sub>T; x \\<leftarrow> x\\<^sub>T; f x }\"\n\nbundle heap_monad_syntax begin\n\nnotation fun_app_lifted (infixl \".\" 999)\ntype_synonym ('a, 'b) fun_lifted = \"'a \\<Rightarrow> 'b Heap\" (\"_ ==H\\<Longrightarrow> _\" [3,2] 2)\ntype_notation Heap (\"[_]\")\n\nnotation Heap_Monad.return (\"\\<langle>_\\<rangle>\")\nnotation (ASCII) Heap_Monad.return (\"(#_#)\")\nnotation Transfer.Rel (\"Rel\")\n\nend\n\ncontext includes heap_monad_syntax begin\n\nqualified lemma return_app_return:\n  \"\\<langle>f\\<rangle> . \\<langle>x\\<rangle> = f x\"\n  unfolding fun_app_lifted_def return_bind ..\n\nqualified lemma return_app_return_meta:\n  \"\\<langle>f\\<rangle> . \\<langle>x\\<rangle> \\<equiv> f x\"\n  unfolding return_app_return .\n\nqualified definition if\\<^sub>T :: \"bool Heap \\<Rightarrow> 'a Heap \\<Rightarrow> 'a Heap \\<Rightarrow> 'a Heap\" where\n  \"if\\<^sub>T b\\<^sub>T x\\<^sub>T y\\<^sub>T \\<equiv> do {b \\<leftarrow> b\\<^sub>T; if b then x\\<^sub>T else y\\<^sub>T}\"\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Monad_Memo_DP/heap_monad/Heap_Monad_Ext.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5312093733737563, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.28218339836013884}}
{"text": "theory Presimplified_Semantics\n  imports \"Presimplified_Semantics_Manual\"\nbegin\n\nnamed_theorems get_semantics_rewriting\n\ncontext presimplified_semantics\nbegin\n\nabbreviation \"write_mem \\<alpha>  \\<sigma> a v s \\<equiv> bv_put \\<alpha>  (Memory s a) (ucast v,0) \\<sigma>\"\n\nabbreviation \"read_mem64 \\<alpha> \\<sigma> s a \\<equiv> fst (read_memory \\<alpha> \\<sigma> s a)\"\n\nabbreviation \"write_mem32 \\<alpha>  \\<sigma> a (v::32 word) \\<equiv>\n                \\<sigma>\\<lparr>mem := write_block ((resolve_address \\<alpha> \\<sigma> a) \\<rhd> rev (\\<lbrace>3,0\\<rbrace> v)) (mem \\<sigma>)\\<rparr>\"\n\nabbreviation \"write_mem64 \\<alpha>  \\<sigma> a (v::64 word) \\<equiv>\n                \\<sigma>\\<lparr>mem := write_block ((resolve_address \\<alpha> \\<sigma> a) \\<rhd> rev (\\<lbrace>7,0\\<rbrace> v)) (mem \\<sigma>)\\<rparr>\"\n\nlemma state_eqI:\n  fixes \\<sigma> \\<sigma>' :: state\n  assumes \"regs \\<sigma> = regs \\<sigma>'\"\n      and \"mem \\<sigma> = mem \\<sigma>'\"\n      and \"flags \\<sigma> = flags \\<sigma>'\"\n    shows \"\\<sigma> = \\<sigma>'\"\n  using assms\n  by (cases \\<sigma>,cases \\<sigma>',auto)\n\nlemma flags_eqI:\n  assumes \"f flag_zf = f' flag_zf\"\n      and \"f flag_cf = f' flag_cf\"\n      and \"f flag_pf = f' flag_pf\"\n      and \"f flag_af = f' flag_af\"\n      and \"f flag_sf = f' flag_sf\"\n      and \"f flag_of = f' flag_of\"\n    shows \"f = f'\"\n  apply (rule ext)\n  subgoal for flg\n    using assms\n    by (cases flg,auto)\n  done\n\n\nlemma parity_ucast[get_semantics_rewriting]:\n  fixes a :: \"'b::len0 word\"\n  assumes \"LENGTH('a) > LENGTH('b)\"\n      and \"LENGTH('b) \\<ge> 8\"\n  shows \"parity (ucast a :: 'a::len0 word) = parity a\"\n  using assms\n  unfolding parity_def\n  by (auto simp add: to_bl_ucast)  \n\nlemma test_bit_of_argument_of_take_bits[get_semantics_rewriting]:\n fixes a :: \"'a::len0 word\"\n   and x :: \"'b::len0 word\"\n assumes \"\\<langle>h,0\\<rangle>a = x\"\n     and \"n \\<le> h\"\n     and \"h < LENGTH('a)\"\n     and \"n < LENGTH('b)\"\n   shows \"a !! n = x !! n\"\nproof-\n have \"a !! n = (\\<langle>h,0\\<rangle>a :: 'b::len0 word) !! n\"\n   apply (subst test_bit_of_take_bits)\n   using assms\n   by (auto)\n also have \"... = x !! n\"\n   apply (subst assms(1))\n   by simp\n finally\n show ?thesis\n   by simp\nqed\n\n\n\n\n\n\n(*---------------------------------------------------proofs on nop ---------------------------------------*)\n\nlemma is_manual_nop[is_manual]:\n  shows \"is_manual assembly semantics (Nullary (IS_8088 Nop)) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_nop[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Nullary (IS_8088 Nop)) si = id\"\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (subst unfold_semantics)\n  apply (rewrite_one_let')+\n  apply simp\n  done\n\nlemma unat_take_bits_remove_32bits[get_semantics_rewriting]:\n  fixes a :: \"32 word\"\n  assumes \"LENGTH('a) \\<ge> 32\"\n  shows \"unat (\\<langle>31,0\\<rangle>a :: 'a::len0 word) = unat a\"\nproof-\n  have 1: \"(\\<langle>31,0\\<rangle>a :: 'a::len0 word) = (ucast a :: 'a::len0 word)\"\n    by (auto simp add:take_bits_remove)\n  show ?thesis\n  using assms\n  by (auto simp add:1 is_up unat_ucast)\nqed\n\n\nlemma test_bit_of_take_bits_for_diff_size[get_semantics_rewriting]:\n  fixes a b:: \"64 word\"\n  assumes \"LENGTH('a) > 64\"\n  shows \"((\\<langle>63,0\\<rangle>a + \\<langle>63,0\\<rangle>b) ::'a::len0 word ) !! 63 = (a + b) !! 63\"\nproof-\n  {\n    let ?x = \"((\\<langle>63,0\\<rangle>a + \\<langle>63,0\\<rangle>b) ::'a::len0 word )\"\n    have 1:\"(\\<langle>63,0\\<rangle>?x :: 64 word) = a + b\"\n      using assms\n      apply (subst take_bits_plus_64bit(1))\n      by auto\n    show ?thesis\n      apply (subst test_bit_of_argument_of_take_bits[where ?h=63 and ?x=\"a+b\"])\n      using assms\n      by auto\n  }\nqed\n\nlemma stupid[get_semantics_rewriting]:\n fixes a :: \"'a::len0 word\"\n assumes \"LENGTH('a) = x\"\n shows \"a = a\"\n by auto\n\n\nlemma unat_take_bits_32word[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"unat (\\<langle>31,0\\<rangle>a :: 33 word) = unat (\\<langle>31,0\\<rangle>a :: 32 word)\"\nproof -\n    have 1:\"(\\<langle>31,0\\<rangle>a :: 33 word) = (ucast (\\<langle>31,0\\<rangle>a :: 32 word))\"\n      by (auto simp add:simp_rules)\n    show ?thesis\n      apply (subst 1)\n      apply (subst unat_ucast)\n      by (auto simp add: is_up)\n  qed\n\nlemma test_bit_of_different_word_size_32[get_semantics_rewriting]:\n  fixes a b:: \"64 word\"\n  assumes \"LENGTH('a) = 33\"\n  shows \"((\\<langle>31,0\\<rangle>a + \\<langle>31,0\\<rangle>b) ::'a::len0 word ) !! 31 = ((\\<langle>31,0\\<rangle>a + \\<langle>31,0\\<rangle>b) :: 32 word ) !! 31\"\nproof-\n  {\n    let ?x = \"((\\<langle>31,0\\<rangle>a + \\<langle>31,0\\<rangle>b) ::'a::len0 word )\"\n    have 1:\"(\\<langle>31,0\\<rangle>?x :: 32 word) = ((\\<langle>31,0\\<rangle>a + \\<langle>31,0\\<rangle>b) :: 32 word)\"\n      using assms\n      apply (subst take_bits_plus)\n      by auto\n    show ?thesis\n      using assms\n      apply (subst test_bit_of_argument_of_take_bits[where ?h=31 and ?x=\"(\\<langle>31,0\\<rangle>a + \\<langle>31,0\\<rangle>b) :: 32 word\"])\n      by (auto simp add:ucast_id)\n  }\nqed\n\nlemma test_bit_2p_minus_1[get_semantics_rewriting]:\n  shows \"((2 ^ LENGTH('a) - 1) :: 'a::len word) !! n = (n < LENGTH('a))\"\nproof-\n  show ?thesis\n    apply (subst max_word_eq[symmetric])\n    by (auto simp add:word_size)\nqed\n\nlemma or_mask_all_0[get_semantics_rewriting]:\n  fixes a :: \"'a :: len word\"\n  shows \"a OR NOT mask LENGTH('a) = a\"\nproof-\n  have 1:\"NOT (2 ^ LENGTH('a) - 1) = (0 :: 'a::len word)\"\n  proof-\n    {\n      fix i\n      assume \"i < LENGTH('a)\" \n      have \"(NOT ((2 ^ LENGTH('a) - 1) :: 'a::len word)) !! i = (0 :: 'a::len word) !! i\"\n        apply (subst max_word_eq[symmetric])\n        by (auto simp add:test_bit_of_take_bits test_bit_2p_minus_1)\n    }\n    thus ?thesis\n    apply (intro word_eqI)\n      by (auto simp add: word_size)\n  qed\n  show ?thesis\n    by (auto simp add:mask_def 1)\nqed\n\nlemma useless_and[get_semantics_rewriting]:\n  fixes a::\"'a::len word\"\n  shows \"a AND ((2^LENGTH('a) - 1) :: 'a:: len word) = (a)\"\nproof-\n  show ?thesis\n    using max_word_eq\n    apply (subst max_word_eq[symmetric])\n    by auto\nqed\n\nlemma p2_ge_one:\n  shows \" Suc 0 \\<le> nat (2 ^ x)\"\n  by(induct x,auto)\n\nlemma nat_remove_2pxminusOne[get_semantics_rewriting]:\n  shows \"nat (2 ^ x - 1) = 2 ^ x - Suc 0\"\nproof(induct x)\n  case 0\n  thus ?case \n    by auto\nnext\n  case (Suc x)\n  have 1: \"2 * nat (2 ^ x) - Suc 0 = nat (2 ^ x) - Suc 0 + nat (2^x)\"\n    by (auto simp add: field_simps)\n  show ?case\n    using Suc \n    apply (auto simp add: nat_diff_distrib' nat_mult_distrib)\n    apply (subst 1)\n    apply auto\n    apply (subst diff_add_assoc)\n    by (auto simp add: p2_ge_one)\nqed\n\nlemma unat_max_word[get_semantics_rewriting]:\n  shows \"unat (max_word :: 'a::len word) = 2^LENGTH('a) - 1\"\n  apply (subst max_word_def)\n  apply auto\n  apply (subst unat_def)\n  apply (subst int_word_uint)\n  apply (auto simp add: m1mod2k)\n  apply (subst nat_remove_2pxminusOne)\n  by simp\n\nlemma unat_2px[get_semantics_rewriting]:\n  assumes \"x < LENGTH('a)\"\n  shows \"unat (2 ^ x :: 'a::len word) = 2 ^ x\"\n  using assms\nproof (induct x)\n  case 0\n  thus ?case\n    by auto\nnext\n  case (Suc x)\n  have 1: \"2 * 2 ^ x = (2 ^ x + 2 ^ x :: 'a word)\"\n    by (auto simp add: field_simps)\n  show ?case\n    using Suc\n    apply (auto simp add: )\n    apply (subst 1)\n    apply (subst unat_word_ariths)\n    apply (auto simp add: field_simps)\n    apply (subst mod_less)\n    using power_strict_increasing_iff[of 2 \"x+1\" \"LENGTH('a)\"]\n    by (auto simp add: field_simps mult_2)\nqed\n\n\nlemma test_bit_2p_of_diff_length[get_semantics_rewriting]:\n  assumes \"h < LENGTH('a)\"\n      and \"LENGTH('h::len) = h\"\n    shows \"((2 ^ h - 1) :: 'a::len word) = ucast (max_word :: 'h word)\"\n    using assms\n    apply (auto)\n    apply unat_arith\n    by (auto simp add: unat_ucast is_up unat_max_word unat_2px)\n\n\nlemma useless_sextend_hardocded_65_word:\n  fixes a :: \"64 word\"\n  shows \"\\<langle>63,0\\<rangle>((sextend (\\<langle>63,0\\<rangle>a :: 1000 word) 64 64) :: 1000 word) = (\\<langle>63,0\\<rangle>a ::65 word)\"\nproof-\n  show ?thesis\n      unfolding sextend.simps\n      apply (auto simp add: simp_rules mask_def)\n      apply (subst take_bits_bitOR)\n       apply (auto simp add:take_bits_remove ucast_id)\n      apply (subst useless_and[where ?a=\"a :: 64 word\", simplified])\n      by auto\n  qed\n\nlemma useless_sextend_hardocded[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"\\<langle>63,0\\<rangle>((sextend (\\<langle>63,0\\<rangle>a :: 1000 word) 64 64) :: 1000 word) = (a ::64 word)\"\nproof-\n  show ?thesis\n      unfolding sextend.simps\n      apply (auto simp add: simp_rules mask_def)\n      apply (subst Word.word_bool_alg.conj_disj_distrib2)\n       apply (auto)\n       apply (subst take_bits_remove[where ?w=\"a\" and ?h=\"63\", simplified])\n       apply (subst take_bits_bitAND)\n       apply auto\n      apply (auto simp add:ucast_id)\n      apply (subst useless_and[where ?a=\"a :: 64 word\", simplified])\n      by auto\n  qed\n\n\nlemma and_2p_minus_1_extend[get_semantics_rewriting]:\n  fixes a:: \"64 word\"\n  shows \"(\\<langle>63,0\\<rangle>a :: 1000 word) AND 2^(LENGTH(64)) - 1 = (\\<langle>63,0\\<rangle>a :: 1000 word)\"\nproof-\n  {\n    fix i n :: nat\n    assume a:\"n < 1000\"\n    have 1: \"(( 2^(LENGTH(64)) - 1) :: 1000 word) = \\<langle>63,0\\<rangle>(( 2^(LENGTH(64)) - 1) :: 64 word)\"\n      by auto\n    hence \"((\\<langle>63,0\\<rangle>a :: 1000 word) AND (2^(LENGTH(64)) - 1 :: 1000 word)) !! n = (\\<langle>63,0\\<rangle>a :: 1000 word)  !! n\"\n      apply (subst 1)\n      apply (subst max_word_eq[symmetric])\n      apply (subst take_bits_bitAND[symmetric]) \n      by (auto simp add:take_bits_remove)\n  }\n  thus ?thesis\n    apply (intro word_eqI)\n    by (auto simp add: word_size)\nqed\n\n\nlemma useless_sextend_hardocded_ucast[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"((sextend (\\<langle>63,0\\<rangle>a :: 1000 word) 64 64) :: 1000 word) = (ucast a ::1000 word)\"\nproof-\n  show ?thesis\n      unfolding sextend.simps\n      apply (auto simp add: simp_rules mask_def)\n      apply (subst Word.word_bool_alg.conj_disj_distrib2)\n       apply (auto)\n      subgoal\n        apply (subst and_2p_minus_1_extend[simplified])\n        apply (subst take_bits_remove[where ?w=\"a\" and ?h=\"63\", simplified])\n        by auto\n      subgoal\n        apply (subst take_bits_remove[where ?w=\"a\" and ?h=\"63\", simplified])\n        by auto\n      done\n qed\n\nlemma take_bits_lt_bit64[get_semantics_rewriting]:\n  fixes a b :: \"'b::len0 word\"\n  assumes \"64 \\<le> LENGTH('a)\"\n      and \"64 \\<le> LENGTH('b)\"\n  shows \"(((\\<langle>63,0\\<rangle>a)::'a::len0 word) < ((\\<langle>63,0\\<rangle>b)::'a::len0 word)) = (((\\<langle>63,0\\<rangle>a)::64 word) < ((\\<langle>63,0\\<rangle>b)::64 word))\"\nproof-\n  have 1: \"\\<forall>i\\<ge>64. i < length (rev (to_bl ((\\<langle>63,0\\<rangle>a)::'a::len0 word))) \\<longrightarrow> \\<not>rev (to_bl ((\\<langle>63,0\\<rangle>a)::'a::len0 word)) ! i\"\n    using assms\n    by (auto simp add: rev_nth test_bit_of_take_bits to_bl_nth word_size)\n  have 2: \"\\<forall>i\\<ge>64. i < length (rev (to_bl ((\\<langle>63,0\\<rangle>b)::'a::len0 word))) \\<longrightarrow> \\<not>rev (to_bl ((\\<langle>63,0\\<rangle>b)::'a::len0 word)) ! i\"\n    using assms\n    by (auto simp add: rev_nth test_bit_of_take_bits to_bl_nth word_size)\n  have 3: \"\\<And> a ::'b::len0 word . take 64 (rev (to_bl ((\\<langle>63,0\\<rangle>a)::'a::len0 word))) = rev (to_bl ((\\<langle>63,0\\<rangle>a)::64 word))\"\n  proof-\n    fix a :: \"'b::len0 word\"\n    {\n      fix i :: nat\n      assume \"i < 64\"\n      hence \"take 64 (rev (to_bl ((\\<langle>63,0\\<rangle>a)::'a::len0 word))) ! i = rev (to_bl ((\\<langle>63,0\\<rangle>a)::64 word)) ! i\"\n        using assms\n        by (auto simp add: rev_nth to_bl_nth word_size test_bit_of_take_bits)\n    }\n    thus \"?thesis a\"\n      using assms\n      apply (intro nth_equalityI)\n      by (auto)\n  qed\n\n  show ?thesis\n    apply (auto simp add: word_less_rbl)\n    apply (subst (asm) rev_bl_order_take[of 64])\n    using 1 2 3\n    apply auto\n    apply (subst rev_bl_order_take[of 64])\n    using 1 2 3\n    by auto\nqed\n\nlemma take_bits_le_bit64[get_semantics_rewriting]:\n  fixes a b :: \"'b::len0 word\"\n  assumes \"64 \\<le> LENGTH('a)\"\n      and \"64 \\<le> LENGTH('b)\"\n  shows \"(((\\<langle>63,0\\<rangle>a)::'a::len0 word) \\<le> ((\\<langle>63,0\\<rangle>b)::'a::len0 word)) = (((\\<langle>63,0\\<rangle>a)::64 word) \\<le> ((\\<langle>63,0\\<rangle>b)::64 word))\"\nproof-\n  have \"(((\\<langle>63,0\\<rangle>a)::'a::len0 word) = ((\\<langle>63,0\\<rangle>b)::'a::len0 word)) = (((\\<langle>63,0\\<rangle>a)::64 word) = ((\\<langle>63,0\\<rangle>b)::64 word))\"\n  proof-\n    { fix i :: nat\n      assume \"(((\\<langle>63,0\\<rangle>a)::'a::len0 word) = ((\\<langle>63,0\\<rangle>b)::'a::len0 word))\"\n      hence \"\\<forall> i < 64 . (((\\<langle>63,0\\<rangle>a)::'a::len0 word) !! i = (((\\<langle>63,0\\<rangle>b)::'a::len0 word)) !! i)\"\n        using assms\n        by (auto simp add: test_bit_of_take_bits)\n   \n      hence \"\\<forall> i < 64 . (((\\<langle>63,0\\<rangle>a)::64 word) !! i = (((\\<langle>63,0\\<rangle>b)::64 word)) !! i)\"\n        using assms\n        by (auto simp add: test_bit_of_take_bits)\n      hence \"(((\\<langle>63,0\\<rangle>a)::64 word) = ((\\<langle>63,0\\<rangle>b)::64 word))\"\n        apply (intro word_eqI)\n        by (auto simp add: word_size)\n    }\n    moreover\n    {\n      assume \"(((\\<langle>63,0\\<rangle>a)::64 word) = ((\\<langle>63,0\\<rangle>b)::64 word))\"\n      hence \"\\<forall> i < 64 . (((\\<langle>63,0\\<rangle>a)::64 word) !! i = (((\\<langle>63,0\\<rangle>b)::64 word)) !! i)\"\n        using assms\n        by (auto simp add: test_bit_of_take_bits)\n      hence \"\\<forall> i < LENGTH('a) . (((\\<langle>63,0\\<rangle>a)::'a::len0 word) !! i = (((\\<langle>63,0\\<rangle>b)::'a::len0 word)) !! i)\"\n        using assms\n        by (auto simp add: test_bit_of_take_bits)\n      hence \"(((\\<langle>63,0\\<rangle>a)::'a::len0 word) = ((\\<langle>63,0\\<rangle>b)::'a::len0 word))\"\n        using assms\n        apply (intro word_eqI)\n        by (auto simp add: word_size)\n    }\n    ultimately\n    show ?thesis\n      by auto\n  qed\n  thus ?thesis\n    using assms\n    apply (cases \"(((\\<langle>63,0\\<rangle>a)::'a::len0 word) = ((\\<langle>63,0\\<rangle>b)::'a::len0 word))\"; cases \"(((\\<langle>63,0\\<rangle>a)::64 word) = ((\\<langle>63,0\\<rangle>b)::64 word))\";auto)\n    by (meson less_imp_le_nat linorder_not_le take_bits_lt_bit64)+\nqed\n\n\n\nlemma overflow_sub_bit64[get_semantics_rewriting]:\n  fixes a b:: \"'a :: len0 word\"\n  assumes \"64 \\<le> LENGTH('a)\"\n  shows \"((1::65 word) + (((\\<langle>63,0\\<rangle>a)::65 word) + ucast (NOT ((\\<langle>63,0\\<rangle>b):: 64 word)))) !! 64 = (((\\<langle>63,0\\<rangle>a)::64 word) \\<ge> \\<langle>63,0\\<rangle>b)\"\nproof-\n  have 3: \"(((\\<langle>63,0\\<rangle>a)::65 word) \\<ge> \\<langle>63,0\\<rangle>b) = (((\\<langle>63,0\\<rangle>a)::64 word) \\<ge> \\<langle>63,0\\<rangle>b)\"\n    using assms\n    by (subst take_bits_le_bit64,simp,simp,simp)\n  have 1: \"\\<not> ((\\<langle>63,0\\<rangle>a)::65 word) !! 64\"\n   and 2: \"\\<not> ((\\<langle>63,0\\<rangle>b)::65 word) !! 64\"\n    using assms\n    by (auto simp add: test_bit_of_take_bits)\n  have \"uint ((\\<langle>63,0\\<rangle>a)::65 word) < 18446744073709551616\"\n   and \"uint ((\\<langle>63,0\\<rangle>b)::65 word) < 18446744073709551616\"\n    using msb_is_gt_2p[unfolded msb_nth,where 'a=65,simplified] 1\n    apply (uint_arith)\n    using msb_is_gt_2p[unfolded msb_nth,where 'a=65,simplified] 2\n    by (uint_arith)\n  hence \"((1::65 word) + (((\\<langle>63,0\\<rangle>a)::65 word) + ucast (NOT ((\\<langle>63,0\\<rangle>b):: 64 word)))) !! 64 = (((\\<langle>63,0\\<rangle>a)::65 word) \\<ge> \\<langle>63,0\\<rangle>b)\"\n    apply (subst ucast_bitNOT)\n    apply simp\n    apply (subst twos_complement_subtraction)\n    apply simp\n    apply (subst msb_is_gt_2p[unfolded msb_nth,where 'a=65,simplified])\n    apply auto\n    apply uint_arith\n    using assms\n    apply (auto simp add: is_up)\n    apply uint_arith\n    using assms\n    by (auto simp add: is_up)\n  thus ?thesis\n    using 3\n    by auto\nqed\n\n\n\nlemma sign_sub_bit64[get_semantics_rewriting]:\n  fixes a b:: \"'a :: len0 word\"\n  assumes \"63 < LENGTH('a)\"\n  shows \"((1::65 word) + (((\\<langle>63,0\\<rangle>a)::65 word) + ucast (NOT ((\\<langle>63,0\\<rangle>b):: 64 word)))) !! 63 \\<longleftrightarrow> sint (((\\<langle>63,0\\<rangle>a):: 64 word) - \\<langle>63,0\\<rangle>b) < 0\"\nproof-\n  have 1: \"\\<And> a :: 65 word . a !! 63 = ((\\<langle>63,0\\<rangle>a):: 64 word) !! 63\"\n    using assms\n    by (auto simp add: test_bit_of_take_bits nth_ucast)\n  have 2: \"\\<langle>63,0\\<rangle>((1::65 word) + (((\\<langle>63,0\\<rangle>a)::65 word) + ucast (NOT ((\\<langle>63,0\\<rangle>b):: 64 word)))) = (((\\<langle>63,0\\<rangle>a)::64 word) - \\<langle>63,0\\<rangle>b)\"\n    using assms\n    apply (subst ucast_bitNOT)\n    apply simp\n    apply (subst twos_complement_subtraction)\n    apply (subst take_bits_minus)\n    apply (simp)\n    apply (simp)\n    by (simp)\n  have 3: \"... !! 63 \\<longleftrightarrow> sint (((\\<langle>63,0\\<rangle>a):: 64 word) - \\<langle>63,0\\<rangle>b) < 0\"\n    using msb_nth[symmetric, where 'a=64]\n    by (simp add: word_msb_sint)\n  show ?thesis\n    apply (subst 1)\n    apply (subst 2)\n    apply (subst 3)\n    by simp\nqed\n\nlemma sub_overflow_flag64_bit[get_semantics_rewriting]:\n  fixes a b :: \"'a::len0 word\"\n  assumes \"LENGTH('a) \\<ge> 64\"\n  shows \"((\\<not> b !! 63) = a !! 63 \\<and> b !! 63 = (sint (\\<langle>63,0\\<rangle>a - \\<langle>63,0\\<rangle>b::64 word) < 0)) \\<longleftrightarrow>\n            ((9223372036854775808::64 word) > \\<langle>63,0\\<rangle>b \\<and> sint (\\<langle>63,0\\<rangle>a - \\<langle>63,0\\<rangle>b::64 word) \\<ge> 0 \\<and> (9223372036854775808::64 word) \\<le> \\<langle>63,0\\<rangle>a)\n             \\<or>\n             ((9223372036854775808::64 word) \\<le> \\<langle>63,0\\<rangle>b \\<and> sint (\\<langle>63,0\\<rangle>a - \\<langle>63,0\\<rangle>b::64 word) < 0 \\<and> (9223372036854775808::64 word) > \\<langle>63,0\\<rangle>a)\"\nproof-\n  have 1: \"a !! 63 = msb (\\<langle>63,0\\<rangle> a :: 64 word)\"\n   and 2: \"b !! 63 = msb (\\<langle>63,0\\<rangle> b :: 64 word)\"\n    using assms\n    by (auto simp add: msb_nth test_bit_of_take_bits)\n  show ?thesis\n    using assms\n    apply (subst 1)\n    apply (subst 2)+\n    apply (subst msb_is_gt_2p)+\n    apply simp\n    by (auto)\nqed\n\nfind_theorems \"(ucast ?x) !! ?v = ?m\"\n\n\nlemma test_32b_of_32AND64_word[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"(\\<langle>63,0\\<rangle>a :: 1000 word) !! 31 = (\\<langle>31,0\\<rangle>a :: 32 word) !! 31\"\n  by (simp add: test_bit_of_take_bits)\n\n\n(*---------------------------------------------------proofs on add ---------------------------------------*)\n\nlemma unat_take_bits_64word[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"unat (\\<langle>63,0\\<rangle>a :: 65 word) = unat (a)\"\nproof -\n    have 1:\"(\\<langle>63,0\\<rangle>a :: 65 word) = (ucast (a))\"\n      by (auto simp add:simp_rules take_bits_remove)\n    show ?thesis\n      apply (subst 1)\n      apply (subst unat_ucast)\n      by (auto simp add: is_up)\n  qed\n\n\n\nlemma is_manual_add_r64_r64[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Add) (Reg (General SixtyFour r64_1)) (Storage (Reg (General SixtyFour r64_2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_add_r64_r64[presimplify]:\n  shows \"get_semantics assembly semantics (Binary (IS_8088 Add) (Reg (General SixtyFour r64_1)) (Storage (Reg (General SixtyFour r64_2)))) si =\n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r64_1 :: 64 word;\n                   op2 = regs \\<sigma> r64_2 :: 64 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r64_1 := (op1 + op2)),\n               flags := (flags \\<sigma>)\n        (flag_zf := ucast(op1 + op2) = (0 :: 64 word),\n         flag_cf := (unat(op1 :: 64 word) + unat(op2 :: 64 word) \\<ge> 2^64),\n         flag_of := (sint(op1) \\<ge> 0  \\<and> sint(op2) \\<ge> 0 \\<and> (sint(op1 + op2) <0))\n                    \\<or>\n                    (sint(op1) < 0 \\<and> sint(op2)<0 \\<and> (sint(op1 + op2) \\<ge>0)),\n\n         flag_sf := sint(op1 + op2) < 0,\n         flag_pf := parity(op1 + op2))  \\<rparr>)\"\nproof-\n show ?thesis\n   apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n   apply (rewrite_one_let' add: semantics_def)\n   apply (rewrite_one_let')+\n   apply (simp add: simp_rules )\n   apply (intro state_eqI,simp_all)\n   subgoal for \\<sigma>\n     apply (intro flags_eqI,simp_all)\n   subgoal\n       unfolding bv_slice.simps[simplified]\n       apply (auto simp add:simp_rules)\n   done\n   subgoal \n     apply (subst msb_is_gt_2p[where ?a =\"(\\<langle>63,0\\<rangle>regs \\<sigma> r64_1 + \\<langle>63,0\\<rangle>regs \\<sigma> r64_2) :: 65 word\", unfolded msb_nth, simplified])\n     apply unat_arith\n     apply (auto simp add:simp_rules)\n     using unat_take_bits_64word[where ?a=\"regs \\<sigma> r64_1\"]\n     using unat_take_bits_64word[where ?a=\"regs \\<sigma> r64_2\"]\n     apply auto\n     done\n   subgoal \n    unfolding bv_slice.simps[simplified]\n    apply (auto simp add:parity_ucast)\n    done\n   subgoal \n     apply (subst word_msb_sint[where ?w=\"regs \\<sigma> r64_1 + regs \\<sigma> r64_2 :: 64 word\", unfolded msb_nth, symmetric])\n     apply (auto simp add:test_bit_of_take_bits simp_rules get_semantics_rewriting)\n     done\n   subgoal \n     apply (subst test_bit_of_take_bits_for_diff_size)\n     using word_msb_sint[where ?w=\"regs \\<sigma> r64_1\", unfolded msb_nth, simplified]\n     using word_msb_sint[where ?w=\"regs \\<sigma> r64_2\", unfolded msb_nth, simplified]\n     using word_msb_sint[where ?w=\"regs \\<sigma> r64_1 + regs \\<sigma> r64_2\",  unfolded msb_nth, simplified]\n     by (auto simp add: simp_rules msb_nth test_bit_of_take_bits )\n   done\n  done\n qed\n\n\n\nlemma test_64b_of_AND1000_word[get_semantics_rewriting]:\n  fixes w :: \"64 word\"\n  shows \"w !! 63 = (\\<langle>63,0\\<rangle>w :: 1000 word) !! 63\"\n  by (simp add: test_bit_of_take_bits)\n\nlemma is_manual_add_r32_r32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Add) (Reg (General ThirtyTwo r32_1)) (Storage (Reg (General ThirtyTwo r32_2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_add_r32_r32[presimplify]:\n  shows \"get_semantics assembly semantics (Binary (IS_8088 Add) (Reg (General ThirtyTwo r32_1)) (Storage (Reg (General ThirtyTwo r32_2)))) si =\n        (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r32_1 :: 32 word;\n                   op2 = \\<langle>31,0\\<rangle>regs \\<sigma> r32_2 :: 32 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r32_1 := ucast(op1 + op2)),\n               flags := (flags \\<sigma>)\n        (flag_zf := ucast(op1 + op2) = (0 :: 32 word),\n         flag_cf := (unat(op1 :: 32 word) + unat(op2 :: 32 word) \\<ge> 2^32),\n         flag_of := (sint(op1) \\<ge> 0  \\<and> sint(op2) \\<ge> 0 \\<and> (sint(op1 + op2) <0))\n                    \\<or>\n                    (sint(op1) < 0 \\<and> sint(op2)<0 \\<and> (sint(op1 + op2) \\<ge>0)),\n\n         flag_sf := sint(op1 + op2) < 0,\n         flag_pf := parity(op1 + op2))  \\<rparr>)\"\nproof-\n show ?thesis\n   apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n   apply (rewrite_one_let' add: semantics_def)\n   apply (rewrite_one_let')+\n   apply (simp add: simp_rules)\n   apply (intro state_eqI,simp_all)\n   subgoal for \\<sigma>\n   apply (intro flags_eqI,simp_all)\n   subgoal \n     apply (subst msb_is_gt_2p[where ?a =\"(\\<langle>31,0\\<rangle>regs \\<sigma> r32_1 + \\<langle>31,0\\<rangle>regs \\<sigma> r32_2) :: 33 word\", unfolded msb_nth, simplified])\n     apply unat_arith\n     apply auto\n     using unat_take_bits_32word[where ?a=\"regs \\<sigma> r32_1\"]\n     using unat_take_bits_32word[where ?a=\"regs \\<sigma> r32_2\"]\n     apply auto\n     done\n   subgoal \n     apply (auto simp add:parity_ucast)\n     done\n   subgoal \n     using word_msb_sint[where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32_1 + \\<langle>31,0\\<rangle>regs \\<sigma> r32_2 :: 32 word\", unfolded msb_nth]\n     apply (auto simp add:simp_rules msb_nth test_bit_of_take_bits test_bit_of_different_word_size_32)\n     done\n   subgoal \n     apply (subst test_bit_of_different_word_size_32)\n     using word_msb_sint[where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32_1 :: 32 word\", unfolded msb_nth, simplified]\n     using word_msb_sint[where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32_2 :: 32 word\", unfolded msb_nth, simplified]\n     using word_msb_sint[where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32_1 + \\<langle>31,0\\<rangle>regs \\<sigma> r32_2 :: 32 word\",  unfolded msb_nth, simplified]\n     by (auto simp add: simp_rules msb_nth test_bit_of_take_bits )\n   done\n  done\n qed\n\n\nlemma is_manual_add_r64_Imm32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Add) (Reg (General SixtyFour r64)) (Immediate (ImmSixtyFour Imm32))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_add_r64_Imm32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Add) (Reg (General SixtyFour r64)) (Immediate (ImmSixtyFour Imm32))) si =\n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r64 :: 64 word;\n                   op2 = (word_of_int Imm32) :: 64 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r64 := (op1 + op2)),\n               flags := (flags \\<sigma>)\n        (flag_zf := (op1 + op2) = (0 :: 64 word),\n         flag_cf := (unat(op1) + unat(op2) \\<ge> 2^64),\n         flag_of := (sint(op1) \\<ge> 0  \\<and> sint(op2) \\<ge> 0 \\<and> (sint(op1 + op2) <0))\n                    \\<or>\n                    (sint(op1) < 0 \\<and> sint(op2)<0 \\<and> (sint(op1 + op2) \\<ge>0)),\n\n         flag_sf := sint(op1 + op2) < 0,\n         flag_pf := parity(op1 + op2))  \\<rparr>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n   apply (rewrite_one_let')+\n    apply (intro state_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:simp_rules useless_sextend_hardocded)\n      done\n   apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n      unfolding bv_slice.simps[simplified]\n      apply (auto simp add:take_bits_remove ucast_id)\n      done\n    subgoal for \\<sigma>\n      apply (subst msb_is_gt_2p[where ?a=\"( \\<langle>63,0\\<rangle>word_of_int Imm32 + \\<langle>63,0\\<rangle>regs \\<sigma> r64 ) :: 65 word\", unfolded msb_nth, simplified])\n      apply unat_arith\n      apply (auto simp add:take_bits_remove)\n      apply (auto simp add:unat_ucast is_up)\n      done\n    subgoal for \\<sigma>\n      unfolding bv_slice.simps[simplified]\n      apply (auto simp add:parity_ucast)\n      done\n    subgoal for \\<sigma>\n      using word_msb_sint[where ?w=\"word_of_int Imm32 + regs \\<sigma> r64 :: 64 word\", unfolded msb_nth]\n      apply (auto simp add:simp_rules msb_nth test_bit_of_take_bits test_bit_of_take_bits_for_diff_size)\n      done\n    subgoal for \\<sigma>\n      using word_msb_sint[where ?w=\"word_of_int Imm32 + regs \\<sigma> r64 :: 64 word\", unfolded msb_nth]\n      using word_msb_sint[where ?w=\"regs \\<sigma> r64 :: 64 word\", unfolded msb_nth]\n      using word_msb_sint[where ?w=\"word_of_int Imm32 :: 64 word\", unfolded msb_nth]\n      by (auto simp add:simp_rules msb_nth test_bit_of_take_bits test_bit_of_take_bits_for_diff_size)\n    done\nqed\n\nlemma is_manual_add_r32_Imm32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Add) (Reg (General ThirtyTwo r32)) (Immediate (ImmSixtyFour Imm32))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_add_r32_Imm32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Add) (Reg (General ThirtyTwo r32)) (Immediate (ImmSixtyFour Imm32))) si =\n        (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r32 :: 32 word;\n                   op2 = \\<langle>31,0\\<rangle>(word_of_int Imm32 :: 64 word) :: 32 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r32 := ucast(op1 + op2)),\n               flags := (flags \\<sigma>)\n        (flag_zf := (op1 + op2) = (0 :: 32 word),\n         flag_cf := (unat(op1) + unat(op2) \\<ge> 2^32),\n         flag_of := (sint(op1) \\<ge> 0  \\<and> sint(op2) \\<ge> 0 \\<and> (sint(op1 + op2) <0))\n                    \\<or>\n                    (sint(op1) < 0 \\<and> sint(op2)<0 \\<and> (sint(op1 + op2) \\<ge>0)),\n\n         flag_sf := sint(op1 + op2) < 0,\n         flag_pf := parity(op1 + op2))  \\<rparr>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n   apply (rewrite_one_let')+\n    apply (intro state_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:simp_rules)\n      done\n   apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n     apply (subst msb_is_gt_2p[where ?a =\"(\\<langle>31,0\\<rangle>word_of_int Imm32 + \\<langle>31,0\\<rangle>regs \\<sigma> r32) :: 33 word\", unfolded msb_nth, simplified])\n     apply unat_arith\n     apply auto\n     using unat_take_bits_32word[where ?a=\"word_of_int Imm32\"]\n     using unat_take_bits_32word[where ?a=\"regs \\<sigma> r32\"]\n     apply auto\n     done\n    subgoal for \\<sigma>\n      apply (auto simp add:parity_ucast)\n      done\n    subgoal for \\<sigma>\n     using word_msb_sint[where ?w=\"\\<langle>31,0\\<rangle>word_of_int Imm32 + \\<langle>31,0\\<rangle>regs \\<sigma> r32 :: 32 word\", unfolded msb_nth]\n     apply (auto simp add:simp_rules msb_nth test_bit_of_take_bits test_bit_of_different_word_size_32)\n     done\n    subgoal for \\<sigma>\n     apply (subst test_bit_of_different_word_size_32)\n     using word_msb_sint[where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32 :: 32 word\", unfolded msb_nth, simplified]\n     using word_msb_sint[where ?w=\"\\<langle>31,0\\<rangle>word_of_int Imm32 :: 32 word\", unfolded msb_nth, simplified]\n     using word_msb_sint[where ?w=\"\\<langle>31,0\\<rangle>word_of_int Imm32 + \\<langle>31,0\\<rangle>regs \\<sigma> r32 :: 32 word\",  unfolded msb_nth, simplified]\n     by (auto simp add: simp_rules msb_nth test_bit_of_take_bits )\n    done\nqed\n\nlemma read_reg_after_update_flag[get_semantics_rewriting]: \"read_reg (\\<sigma>\\<lparr>flags := x\\<rparr>) r = read_reg \\<sigma> r\"\n  by (induct \\<sigma> r rule: read_reg.induct,auto)\n\nlemma resolve_address_after_update_flag[get_semantics_rewriting]: \"resolve_address \\<alpha> (\\<sigma>\\<lparr>flags := x\\<rparr>) Mem = resolve_address \\<alpha> \\<sigma> Mem\"\n by (induct \\<alpha> \\<sigma> Mem rule: resolve_address.induct, auto simp add:read_reg_after_update_flag)\n\nlemma sextend_useless_64_64:\n  fixes a :: \"64 word\"\n  shows \"sextend a 64 64 = a\"\n  unfolding sextend.simps\n  apply (auto simp add: simp_rules mask_def)\n  apply (subst useless_and[where ?a=\"a OR - 18446744073709551616 :: 64 word\", simplified])\n  using or_mask_all_0[of a]\n  by auto\n\nlemma is_manual_add_m64_Imm32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Add) (Memory 64 Mem) (Immediate (ImmSixtyFour Imm32))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_add_m64_Imm32[presimplify]:\n shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Add) (Memory 64 Mem) (Immediate (ImmSixtyFour Imm32))) si =\n         (\\<lambda> \\<sigma> . let a = resolve_address \\<alpha> \\<sigma> Mem;\n                    op1 = read_mem64 \\<alpha> \\<sigma> 64 Mem;\n                    op2 = (word_of_int Imm32) :: 64 word in\n      \\<sigma>\\<lparr>mem := write_blocks [a \\<rhd> rev (\\<lbrace>7,0\\<rbrace> (op1 + op2))] (mem \\<sigma>),\n      flags := (flags \\<sigma>)\n      (flag_zf := (op1 + op2) = (0 :: 64 word),\n       flag_cf := (unat(op1) + unat(op2) \\<ge> 2^64),\n       flag_of := (sint(op1) \\<ge> 0 \\<and> sint(op2) \\<ge> 0 \\<and> sint(op1 + op2) < 0)\n                  \\<or>\n                  (sint(op1) < 0 \\<and> sint(op2) < 0 \\<and> sint(op1 + op2) \\<ge> 0),\n       flag_sf := sint(op1 + op2) < 0,\n       flag_pf := parity(op1 + op2))  \\<rparr>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')\n    apply (rewrite_one_let')+\n    apply (intro state_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:simp_rules sextend_useless_64_64 useless_sextend_hardocded_ucast useless_sextend_hardocded useless_sextend_hardocded_65_word resolve_address_after_update_flag)\n      done\n   apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:take_bits_remove ucast_id )\n      unfolding bv_slice.simps\n       apply (auto simp add: sextend_useless_64_64 ucast_id)\n      done\n    subgoal for \\<sigma>\n      apply (subst useless_sextend_hardocded_65_word[simplified])\n      apply (subst msb_is_gt_2p[where ?a=\"( \\<langle>63,0\\<rangle>word_of_int Imm32 + \\<langle>63,0\\<rangle>read_mem64 \\<alpha> \\<sigma> 64 Mem) :: 65 word\", unfolded msb_nth, simplified])\n      apply unat_arith\n      apply (auto simp add:take_bits_remove)\n      apply (auto simp add:unat_ucast is_up)\n      done\n    subgoal for \\<sigma>\n      unfolding bv_slice.simps\n      apply (subst useless_sextend_hardocded_65_word[simplified])\n      apply (auto simp add:parity_ucast)\n      done\n    subgoal for \\<sigma>\n      apply (subst useless_sextend_hardocded_65_word[simplified])\n      using word_msb_sint[where ?w=\"word_of_int Imm32 + read_mem64 \\<alpha> \\<sigma> 64 Mem :: 64 word\", unfolded msb_nth]\n      apply (auto simp add:simp_rules msb_nth test_bit_of_take_bits test_bit_of_take_bits_for_diff_size)\n      done\n    subgoal for \\<sigma>\n      apply (subst  useless_sextend_hardocded_ucast[where ?a=\"word_of_int Imm32\"])\n      apply (subst useless_sextend_hardocded_65_word[simplified])\n      apply (subst  useless_sextend_hardocded_ucast[where ?a=\"word_of_int Imm32\"])\n      using word_msb_sint[where ?w=\"word_of_int Imm32 +read_mem64 \\<alpha> \\<sigma> 64 Mem :: 64 word\", unfolded msb_nth]\n      using word_msb_sint[where ?w=\"read_mem64 \\<alpha> \\<sigma> 64 Mem :: 64 word\", unfolded msb_nth]\n      using word_msb_sint[where ?w=\"word_of_int Imm32 :: 64 word\", unfolded msb_nth]\n      by (auto simp add:simp_rules msb_nth test_bit_of_take_bits test_bit_of_take_bits_for_diff_size)\n    done\nqed\n\nlemma is_manual_add_m32_Imm32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Add) (Memory 32 Mem) (Immediate (ImmSixtyFour Imm32))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_add_m32_imm32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Add) (Memory 32 Mem) (Immediate (ImmSixtyFour Imm32))) si =\n        (\\<lambda> \\<sigma> . let a = resolve_address \\<alpha> \\<sigma> Mem;\n                   op1 = \\<langle>31,0\\<rangle>read_mem64 \\<alpha> \\<sigma> 32 Mem;\n                   op2 = \\<langle>31,0\\<rangle>(word_of_int Imm32 :: 64 word) :: 32 word\n               in\n        \\<sigma>\\<lparr>mem :=  write_blocks [a \\<rhd> rev (\\<lbrace>3,0\\<rbrace> (op1 + op2))] (mem \\<sigma>),\n               flags := (flags \\<sigma>)\n        (flag_zf := ucast(op1 + op2) = (0 :: 32 word),\n         flag_cf := (unat(op1 :: 32 word) + unat(op2 :: 32 word) \\<ge> 2^32),\n         flag_of := (sint(op1) \\<ge> 0  \\<and> sint(op2) \\<ge> 0 \\<and> (sint(op1 + op2) <0))\n                    \\<or>\n                    (sint(op1) < 0 \\<and> sint(op2)<0 \\<and> (sint(op1 + op2) \\<ge>0)),\n\n         flag_sf := sint(op1 + op2) < 0,\n         flag_pf := parity(op1 + op2))  \\<rparr>)\"\nproof-\n show ?thesis\n   apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n   apply (rewrite_one_let' add: semantics_def)\n   apply (rewrite_one_let')+\n   apply (simp add: simp_rules resolve_address_after_update_flag)\n   apply (intro state_eqI,simp_all)\n   subgoal for \\<sigma>\n   apply (intro flags_eqI,simp_all)\n   subgoal \n     apply (subst msb_is_gt_2p[where ?a =\"(\\<langle>31,0\\<rangle>word_of_int Imm32 + \\<langle>31,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 32 Mem)) :: 33 word\", unfolded msb_nth, simplified])\n     apply unat_arith\n     apply auto\n     using unat_take_bits_32word[where ?a=\"word_of_int Imm32\"]\n     using unat_take_bits_32word[where ?a=\"fst (read_memory \\<alpha> \\<sigma> 32 Mem)\"]\n     apply auto\n     done\n   subgoal \n     apply (auto simp add:parity_ucast)\n     done\n   subgoal \n     using word_msb_sint[where ?w=\"\\<langle>31,0\\<rangle>word_of_int Imm32 + \\<langle>31,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 32 Mem) :: 32 word\", unfolded msb_nth]\n     apply (auto simp add:simp_rules msb_nth test_bit_of_take_bits test_bit_of_different_word_size_32)\n     done\n   subgoal \n     apply (subst test_bit_of_different_word_size_32)\n     using word_msb_sint[where ?w=\"\\<langle>31,0\\<rangle>word_of_int Imm32 :: 32 word\", unfolded msb_nth, simplified]\n     using word_msb_sint[where ?w=\"\\<langle>31,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 32 Mem) :: 32 word\", unfolded msb_nth, simplified]\n     using word_msb_sint[where ?w=\"\\<langle>31,0\\<rangle>word_of_int Imm32 + \\<langle>31,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 32 Mem) :: 32 word\",  unfolded msb_nth, simplified]\n     by (auto simp add: simp_rules msb_nth test_bit_of_take_bits )\n   done\n  done\n qed\n\nlemma is_manual_add_m64_r64[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Add) (Memory 64 Mem) (Storage (Reg (General SixtyFour reg)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_add_m64_imm64[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Add) (Memory 64 Mem) (Storage (Reg (General SixtyFour reg)))) si =\n        (\\<lambda> \\<sigma> . let a = resolve_address \\<alpha> \\<sigma> Mem;\n                   op1 = read_mem64 \\<alpha> \\<sigma> 64 Mem;\n                   op2 = regs \\<sigma> reg\n               in\n        \\<sigma>\\<lparr>mem :=  write_blocks [a \\<rhd> rev (\\<lbrace>7,0\\<rbrace> (op1 + op2))] (mem \\<sigma>),\n               flags := (flags \\<sigma>)\n        (flag_zf := ucast(op1 + op2) = (0 :: 64 word),\n         flag_cf := (unat(op1 :: 64 word) + unat(op2 :: 64 word) \\<ge> 2^64),\n         flag_of := (sint(op1) \\<ge> 0  \\<and> sint(op2) \\<ge> 0 \\<and> (sint(op1 + op2) <0))\n                    \\<or>\n                    (sint(op1) < 0 \\<and> sint(op2)<0 \\<and> (sint(op1 + op2) \\<ge>0)),\n\n         flag_sf := sint(op1 + op2) < 0,\n         flag_pf := parity(op1 + op2))  \\<rparr>)\"\nproof-\n show ?thesis\n   apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n   apply (rewrite_one_let' add: semantics_def)\n   apply (rewrite_one_let')+\n   apply (simp add: simp_rules resolve_address_after_update_flag)\n   apply (intro state_eqI,simp_all)\n   subgoal for \\<sigma>\n     apply (intro flags_eqI,simp_all)\n   subgoal\n       unfolding bv_slice.simps[simplified]\n       apply (auto simp add:simp_rules)\n   done\n   subgoal \n     apply (subst msb_is_gt_2p[where ?a =\"(\\<langle>63,0\\<rangle>regs \\<sigma> reg + \\<langle>63,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 64 Mem)) :: 65 word\", unfolded msb_nth, simplified])\n     apply unat_arith\n     apply (auto simp add:simp_rules)\n     using unat_take_bits_64word[where ?a=\"regs \\<sigma> reg\"]\n     using unat_take_bits_64word[where ?a=\"fst (read_memory \\<alpha> \\<sigma> 64 Mem)\"]\n     apply auto\n     done\n   subgoal \n    unfolding bv_slice.simps[simplified]\n    apply (auto simp add:parity_ucast)\n    done\n   subgoal \n     apply (subst word_msb_sint[where ?w=\"regs \\<sigma> reg + fst (read_memory \\<alpha> \\<sigma> 64 Mem) :: 64 word\", unfolded msb_nth, symmetric])\n     apply (auto simp add:test_bit_of_take_bits simp_rules test_bit_of_take_bits_for_diff_size)\n     done\n   subgoal \n     apply (subst test_bit_of_take_bits_for_diff_size)\n     using word_msb_sint[where ?w=\"regs \\<sigma> reg\", unfolded msb_nth, simplified]\n     using word_msb_sint[where ?w=\"fst (read_memory \\<alpha> \\<sigma> 64 Mem)\", unfolded msb_nth, simplified]\n     using word_msb_sint[where ?w=\"regs \\<sigma> reg + fst (read_memory \\<alpha> \\<sigma> 64 Mem)\",  unfolded msb_nth, simplified]\n     by (auto simp add: simp_rules msb_nth test_bit_of_take_bits )\n   done\n  done\n qed\n\n\n\n\nlemma sub_overflow_flag[get_semantics_rewriting]:\n  fixes a b :: \"'a::len0 word\"\n  assumes \"LENGTH('a) \\<ge> 32\"\n  shows \"((\\<not> b !! 31) = a !! 31 \\<and> b !! 31 = (sint (\\<langle>31,0\\<rangle>a - \\<langle>31,0\\<rangle>b::32 word) < 0)) \\<longleftrightarrow>\n            ((2147483648::32 word) > \\<langle>31,0\\<rangle>b \\<and> sint (\\<langle>31,0\\<rangle>a - \\<langle>31,0\\<rangle>b::32 word) \\<ge> 0 \\<and> (2147483648::32 word) \\<le> \\<langle>31,0\\<rangle>a)\n             \\<or>\n             ((2147483648::32 word) \\<le> \\<langle>31,0\\<rangle>b \\<and> sint (\\<langle>31,0\\<rangle>a - \\<langle>31,0\\<rangle>b::32 word) < 0 \\<and> (2147483648::32 word) > \\<langle>31,0\\<rangle>a)\"\nproof-\n  have 1: \"a !! 31 = msb (\\<langle>31,0\\<rangle> a :: 32 word)\"\n   and 2: \"b !! 31 = msb (\\<langle>31,0\\<rangle> b :: 32 word)\"\n    using assms\n    by (auto simp add: msb_nth test_bit_of_take_bits)\n  show ?thesis\n    using assms\n    apply (subst 1)\n    apply (subst 2)+\n    apply (subst msb_is_gt_2p)+\n    apply simp\n    by (auto)\nqed\n\n\n\n(*---------------------------------------------------proofs on seta ---------------------------------------*)\n\nlemma is_manual_seta_r8[is_manual]:\n  shows \"is_manual assembly semantics (Unary (IS_80386 Seta) (Storage (Reg (General EightLow r1)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_seta_r8[presimplify]:\n  shows \"get_semantics assembly semantics (Unary (IS_80386 Seta) (Storage (Reg (General EightLow r1)))) si =\n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r1 :: 64 word\n            in\n             \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r1 := \\<langle>63,0\\<rangle>((\\<langle>63,8\\<rangle>regs \\<sigma> r1 << 8 :: 64 word) OR (if flags \\<sigma> flag_zf \\<or> flags \\<sigma> flag_cf then 0 else 1))) \\<rparr>)\"\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n   apply (auto simp add:simp_rules Let'_def)\n  apply (subst bv_cat'_def)\n   apply (auto simp add:  bv_cat.simps)\n   apply (intro state_eqI)\n  apply (rule ext)\n       apply (auto)\n   apply (rule word_eqI)\n   apply (auto simp add: word_size word_ao_nth test_bit_of_take_bits nth_shiftl)\n  apply (subst bv_cat'_def)\n   apply (auto simp add:  bv_cat.simps)\n   apply (intro state_eqI)\n  apply (rule ext)\n       apply (auto)\n   apply (rule word_eqI)\n   apply (auto simp add: word_size word_ao_nth test_bit_of_take_bits nth_shiftl)\n  apply (subst bv_cat'_def)\n   apply (auto simp add:  bv_cat.simps)\n   apply (intro state_eqI)\n  apply (rule ext)\n       apply (auto)\n   apply (rule word_eqI)\n   apply (auto simp add: word_size word_ao_nth test_bit_of_take_bits nth_shiftl)\n  apply (subst bv_cat'_def)\n   apply (auto simp add:  bv_cat.simps)\n   apply (intro state_eqI)\n  apply (rule ext)\n       apply (auto)\n   apply (rule word_eqI)\n   apply (auto simp add: word_size word_ao_nth test_bit_of_take_bits nth_shiftl)\n    apply(auto simp add:semantics_def simp_rules Let'_def)[1]\n    apply(auto simp add:semantics_def simp_rules Let'_def)[1]\n    apply(auto simp add:semantics_def simp_rules Let'_def)[1]\n    apply(auto simp add:semantics_def simp_rules Let'_def)[1]\n  apply (subst bv_cat'_def)\n   apply (auto simp add:  bv_cat.simps)\n   apply (intro state_eqI)\n  apply (rule ext)\n       apply (auto)\n   apply (rule word_eqI)\n  apply (auto simp add: word_size word_ao_nth test_bit_of_take_bits nth_shiftl)\n   apply (intro state_eqI)\n  apply (rule ext)\n       apply (auto)\n   apply (rule word_eqI)\n  by (auto simp add: word_size word_ao_nth test_bit_of_take_bits nth_shiftl bv_to_bool_def word_lsb_alt)\n\nlemma is_manual_seta_m8[is_manual]:\n  shows \"is_manual assembly semantics (Unary (IS_80386 Seta) (Storage (Memory 8 Mem))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_seta_m8[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Unary (IS_80386 Seta) (Storage (Memory 8 Mem))) si =\n        (\\<lambda> \\<sigma> . let a = resolve_address \\<alpha> \\<sigma> Mem;\n                   op1 = (read_mem64 \\<alpha> \\<sigma> 8 Mem) :: 64 word\n            in\n             \\<sigma>\\<lparr>mem := write_blocks [a \\<rhd> (if flags \\<sigma> flag_zf \\<or> flags \\<sigma> flag_cf then [0] else [1])] (mem \\<sigma>)\\<rparr>)\"\nproof-\n  {\n    fix x :: \"64 word\"\n    have \"rev (\\<lbrace>0,0\\<rbrace>(\\<langle>63,0\\<rangle>(\\<langle>63,8\\<rangle>x << 8 :: 1000 word) :: 64 word)) = [0]\"\n      apply auto\n      apply (intro nth_equalityI)\n      apply (auto simp add: nth_bytes_of)\n      apply (intro word_eqI)\n      by (auto simp add: word_size nth_shiftl test_bit_of_take_bits)\n  }\n  note 1 = this\n  {\n    fix x :: \"64 word\"\n    have \"rev (\\<lbrace>0,0\\<rbrace>(\\<langle>63,0\\<rangle>((\\<langle>63,8\\<rangle>x << 8 :: 1000 word) OR 1)::64 word)) = [1]\"\n      apply auto\n      apply (intro nth_equalityI)\n      apply (auto simp add: nth_bytes_of)\n      apply (intro word_eqI)\n      by (auto simp add: word_size nth_shiftl test_bit_of_take_bits word_ao_nth)\n  }\n  note 2 = this\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n      apply (auto simp add:simp_rules Let'_def)\n  apply (subst bv_cat'_def)\n   apply (auto simp add:  bv_cat.simps)\n   apply (intro state_eqI)\n  apply (rule ext)\n       apply (auto simp add: 1)\n  apply (subst bv_cat'_def)\n   apply (auto simp add:  bv_cat.simps)\n   apply (intro state_eqI)\n  apply (rule ext)\n       apply (auto simp add: 1 2)\n  apply (subst bv_cat'_def)\n   apply (auto simp add:  bv_cat.simps)\n   apply (intro state_eqI)\n  apply (rule ext)\n       apply (auto simp add: 1 2)\n  apply (subst bv_cat'_def)\n   apply (auto simp add:  bv_cat.simps)\n   apply (intro state_eqI)\n  apply (rule ext)\n    apply (auto simp add: 1 2)\n    apply(auto simp add:semantics_def simp_rules Let'_def)[1]\n    apply(auto simp add:semantics_def simp_rules Let'_def)[1]\n    apply(auto simp add:semantics_def simp_rules Let'_def)[1]\n    apply(auto simp add:semantics_def simp_rules Let'_def)[1]\n   apply (intro state_eqI)\n  apply (rule ext)\n    apply (auto simp add: word_size word_ao_nth test_bit_of_take_bits nth_shiftl bv_to_bool_def word_lsb_alt)\n  apply (subst bv_cat'_def)\n   apply (auto simp add:  bv_cat.simps 2)\n    done\nqed\n\n\n(*---------------------------------------------------proofs on setb ---------------------------------------*)\n\nlemma is_manual_setb_r8[is_manual]:\n  shows \"is_manual assembly semantics (Unary (IS_80386 Setb) (Storage (Reg (General EightLow r)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_setb_r8[presimplify]:\n  shows \"get_semantics assembly semantics (Unary (IS_80386 Setb) (Storage (Reg (General EightLow r)))) si =\n        (\\<lambda>\\<sigma>. let op = regs \\<sigma> r\n            in\n          \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r := \\<langle>63,0\\<rangle>((\\<langle>63,8\\<rangle>op << 8 :: 64 word) OR (if flags \\<sigma> flag_cf then 1 else 0)))\\<rparr>)\"\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply rewrite_one_let'\n   apply rewrite_one_let'\n   apply rewrite_one_let'\n   apply (rewrite_one_let' add: semantics_def)\n   apply rewrite_one_let'+\n   apply (auto simp add:simp_rules)\n   apply (subst bv_cat'_def)\n   apply (auto simp add: bv_cat.simps)\n   apply (intro state_eqI)\n     apply (rule ext)\n     apply auto\n   apply (rule word_eqI)\n   apply (auto simp add: word_size word_ao_nth test_bit_of_take_bits nth_shiftl)\n  apply rewrite_one_let'\n  apply rewrite_one_let'\n  apply rewrite_one_let'\n  apply (rewrite_one_let' add: semantics_def)\n  apply rewrite_one_let'+\n  apply (auto simp add: simp_rules)\n  apply (subst bv_cat'_def)\n  apply (auto simp add: bv_cat.simps)\n  apply (intro state_eqI)\n    apply (rule ext)\n    apply auto\n  apply (rule word_eqI)\n  apply (auto simp add: word_size word_ao_nth test_bit_of_take_bits nth_shiftl)\n  done\n\n\n(*---------------------------------------------------proofs on setne ---------------------------------------*)\n\nlemma is_manual_setne_r8[is_manual]:\n  shows \"is_manual assembly semantics (Unary (IS_80386 Setne) (Storage (Reg (General EightLow r1)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_setne_r8[presimplify]:\n  shows \"get_semantics assembly semantics (Unary (IS_80386 Setne) (Storage (Reg (General EightLow r1)))) si =\n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r1 :: 64 word\n            in\n             \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r1 := \\<langle>63,0\\<rangle>((\\<langle>63,8\\<rangle>regs \\<sigma> r1 << 8 :: 64 word) OR (if flags \\<sigma> flag_zf then 0 else 1))) \\<rparr>)\"\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n   apply (auto simp add:simp_rules )\n  apply (subst bv_cat'_def)\n   apply (auto simp add:  bv_cat.simps)\n   apply (intro state_eqI)\n  apply (rule ext)\n       apply (auto)\n   apply (rule word_eqI)\n   apply (auto simp add: word_size word_ao_nth test_bit_of_take_bits nth_shiftl)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n  apply(rewrite_one_let')+\n   apply (auto simp add:simp_rules )\n  apply (subst bv_cat'_def)\n   apply (auto simp add:  bv_cat.simps)\n   apply (intro state_eqI)\n  apply (rule ext)\n       apply (auto)\n   apply (rule word_eqI)\n  apply (auto simp add: word_size word_ao_nth test_bit_of_take_bits nth_shiftl)\n  apply(rewrite_one_let')+\n   apply (auto simp add:simp_rules )\n  apply (subst bv_cat'_def)\n   apply (auto simp add:  bv_cat.simps)\n   apply (intro state_eqI)\n  apply (rule ext)\n       apply (auto)\n   apply (rule word_eqI)\n  by (auto simp add: word_size word_ao_nth test_bit_of_take_bits nth_shiftl bv_to_bool_def word_lsb_alt)\n\nlemma is_manual_setne_m8[is_manual]:\n  shows \"is_manual assembly semantics (Unary (IS_80386 Setne) (Storage (Memory 8 Mem))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_setne_m8[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Unary (IS_80386 Setne) (Storage (Memory 8 Mem))) si =\n        (\\<lambda> \\<sigma> . let a = resolve_address \\<alpha> \\<sigma> Mem;\n                   op1 = (read_mem64 \\<alpha> \\<sigma> 8 Mem) :: 64 word\n            in\n             \\<sigma>\\<lparr>mem := write_blocks [a \\<rhd> (if flags \\<sigma> flag_zf then [0] else [1])] (mem \\<sigma>)\\<rparr>)\"\nproof-\n  {\n    fix x :: \"64 word\"\n    have \"rev (\\<lbrace>0,0\\<rbrace>(\\<langle>63,0\\<rangle>(\\<langle>63,8\\<rangle>x << 8 :: 1000 word) :: 64 word)) = [0]\"\n      apply auto\n      apply (intro nth_equalityI)\n      apply (auto simp add: nth_bytes_of)\n      apply (intro word_eqI)\n      by (auto simp add: word_size nth_shiftl test_bit_of_take_bits)\n  }\n  note 1 = this\n  {\n    fix x :: \"64 word\"\n    have \"rev (\\<lbrace>0,0\\<rbrace>(\\<langle>63,0\\<rangle>((\\<langle>63,8\\<rangle>x << 8 :: 1000 word) OR 1)::64 word)) = [1]\"\n      apply auto\n      apply (intro nth_equalityI)\n      apply (auto simp add: nth_bytes_of)\n      apply (intro word_eqI)\n      by (auto simp add: word_size nth_shiftl test_bit_of_take_bits word_ao_nth)\n  }\n  note 2 = this\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n   apply (auto simp add:simp_rules )\n  apply (subst bv_cat'_def)\n   apply (auto simp add:  bv_cat.simps)\n   apply (intro state_eqI)\n  apply (rule ext)\n       apply (auto simp add: 1)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n  apply(rewrite_one_let')+\n   apply (auto simp add:simp_rules )\n  apply (subst bv_cat'_def)\n   apply (auto simp add:  bv_cat.simps)\n   apply (intro state_eqI)\n  apply (rule ext)\n       apply (auto simp add: 2)\n  apply(rewrite_one_let')+\n   apply (auto simp add:simp_rules )\n  apply (subst bv_cat'_def)\n   apply (auto simp add:  bv_cat.simps)\n   apply (intro state_eqI)\n  apply (rule ext)\n       apply (auto simp add: )\n    by (auto simp add: word_size word_ao_nth test_bit_of_take_bits nth_shiftl bv_to_bool_def word_lsb_alt)\nqed\n\n(*---------------------------------------------------proofs on sete ---------------------------------------*)\nlemma is_manual_sete_r8[is_manual]:\n  shows \\<open>is_manual assembly semantics (Unary (IS_80386 Sete) (Storage (Reg (General EightLow r)))) = False\\<close>\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_sete_r8[presimplify]:\n  \\<open>get_semantics assembly semantics (Unary (IS_80386 Sete) (Storage (Reg (General EightLow r)))) si =\n    (\\<lambda>\\<sigma>. let op1 = regs \\<sigma> r in\n      \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r := \\<langle>63,0\\<rangle>((\\<langle>63,8\\<rangle>regs \\<sigma> r << 8::64 word) OR (if flags \\<sigma> flag_zf then 1 else 0)))\\<rparr>)\\<close>\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply rewrite_one_let'\n   apply rewrite_one_let'\n   apply rewrite_one_let'\n   apply (rewrite_one_let' add: semantics_def)\n   apply rewrite_one_let'+\n   apply (auto simp add: simp_rules)\n   apply (subst bv_cat'_def)\n   apply (auto simp add: bv_cat.simps)\n   apply (intro state_eqI)\n     apply (rule ext)\n     apply auto\n   apply (rule word_eqI)\n   apply (auto simp add: word_size word_ao_nth test_bit_of_take_bits nth_shiftl)\n  apply rewrite_one_let'\n  apply rewrite_one_let'\n  apply rewrite_one_let'\n  apply (rewrite_one_let' add: semantics_def)\n  apply rewrite_one_let'+\n  apply (auto simp add: simp_rules)\n  apply (subst bv_cat'_def)\n  apply (auto simp add: bv_cat.simps)\n  apply (intro state_eqI)\n    apply (rule ext)\n    apply auto\n  apply (rule word_eqI)\n  by (auto simp add: word_size word_ao_nth test_bit_of_take_bits nth_shiftl)\n\n(*---------------------------------------------------proofs on cmp ---------------------------------------*)\nlemma is_manual_cmp_r32_r32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Cmp) (Reg (General ThirtyTwo r32_1)) (Storage (Reg (General ThirtyTwo r32_2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_cmp_r32_r32[presimplify]:\n  shows \"get_semantics assembly semantics (Binary (IS_8088 Cmp) (Reg (General ThirtyTwo r32_1)) (Storage (Reg (General ThirtyTwo r32_2)))) si = \n         (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r32_1 :: 32 word;\n                   op2 = \\<langle>31,0\\<rangle>regs \\<sigma> r32_2 :: 32 word\n               in\n        \\<sigma>\\<lparr>flags := (flags \\<sigma>)\n          (flag_pf := undefined,\n           flag_cf := op2 > op1,\n           flag_zf := op1 = op2,\n           flag_sf := sint (op1 - op2) < 0,\n           flag_of := (sint(op2) \\<ge> 0 \\<and> 0 \\<le> sint (op1 - op2) \\<and> sint(op1) < 0)\n                      \\<or>\n                      (sint(op2) < 0 \\<and> sint (op1  - op2) < 0 \\<and> sint(op1) \\<ge> 0))\\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let' add: semantics_def)\n    apply (rewrite_one_let')+\n  apply (intro state_eqI,simp_all)\n    apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32_2 :: 32 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32_1 :: 32 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"(\\<langle>31,0\\<rangle>regs \\<sigma> r32_1 - \\<langle>31,0\\<rangle>regs \\<sigma> r32_2) :: 32 word\"]\n    by (auto simp add: simp_rules test_bit_of_take_bits )\n  done\nqed\n\nlemma is_manual_cmp_r32_m32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Cmp) (Reg (General ThirtyTwo r32)) (Storage (Memory 32 a))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_cmp_r32_m32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Cmp) (Reg (General ThirtyTwo r32)) (Storage (Memory 32 a))) si = \n             (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r32 :: 32 word;\n                   op2 = \\<langle>31,0\\<rangle>(read_mem64 \\<alpha> \\<sigma> 32 a) :: 32 word\n               in\n        \\<sigma>\\<lparr>flags := (flags \\<sigma>)\n          (flag_pf := undefined,\n           flag_cf := op2 > op1,\n           flag_zf := op1 = op2,\n           flag_sf := sint (op1 - op2) < 0,\n           flag_of :=(sint(op2) \\<ge> 0 \\<and> 0 \\<le> sint (op1 - op2) \\<and> sint(op1) < 0)\n                      \\<or>\n                      (sint(op2) < 0 \\<and> sint (op1  - op2) < 0 \\<and> sint(op1) \\<ge> 0))\\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n    apply (rewrite_one_let')+\n  apply (intro state_eqI,simp_all)\n    apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32 :: 32 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"(\\<langle>31,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 32 a)) :: 32 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"(\\<langle>31,0\\<rangle>regs \\<sigma> r32 - \\<langle>31,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 32 a)) :: 32 word\"]\n    by (auto simp add: simp_rules test_bit_of_take_bits )\n  done\nqed\n\n\nlemma is_manual_cmp_r32_Imm32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Cmp) (Reg (General ThirtyTwo r1)) (Immediate (ImmSixtyFour Imm32))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_cmp_r32_Imm32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Cmp) (Reg (General ThirtyTwo r1)) (Immediate (ImmSixtyFour Imm32))) si = \n         (\\<lambda> \\<sigma> . let op1 = (\\<langle>31,0\\<rangle>regs \\<sigma> r1 :: 32 word);\n                   op2 = \\<langle>31,0\\<rangle>(word_of_int Imm32 :: 64 word)\n               in\n        \\<sigma>\\<lparr>flags := (flags \\<sigma>)\n          (flag_pf := undefined,\n           flag_cf := op2 > op1,\n           flag_zf := op1 = op2,\n           flag_sf := sint (op1 - op2) < 0,\n           flag_of := (sint(op2) \\<ge> 0 \\<and> 0 \\<le> sint (op1 - op2) \\<and> sint(op1) < 0)\n                      \\<or>\n                      (sint(op2) < 0 \\<and> sint (op1  - op2) < 0 \\<and> sint(op1) \\<ge> 0))\\<rparr>)\"\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')+\n  apply (intro state_eqI,simp_all)\n  apply (intro flags_eqI,simp_all)\n  subgoal for \\<sigma>\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r1 :: 32 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"(\\<langle>31,0\\<rangle>(word_of_int Imm32 :: 64 word) :: 32 word)\"]\n    by (auto simp add: simp_rules test_bit_of_take_bits )\n  done\n\n\n\n\nlemma is_manual_cmp_m32_r32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Cmp) (Memory 32 a) (Storage (Reg (General ThirtyTwo r32)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_cmp_m32_r32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Cmp) (Memory 32 a) (Storage (Reg (General ThirtyTwo r32))))  si = \n             (\\<lambda> \\<sigma> . let op2 = \\<langle>31,0\\<rangle>regs \\<sigma> r32 :: 32 word;\n                   op1 = \\<langle>31,0\\<rangle>(read_mem64 \\<alpha> \\<sigma> 32 a) :: 32 word\n               in\n        \\<sigma>\\<lparr>flags := (flags \\<sigma>)\n          (flag_pf := undefined,\n           flag_cf := op2 > op1,\n           flag_zf := op1 = op2,\n           flag_sf := sint (op1 - op2) < 0,\n           flag_of :=(sint(op2) \\<ge> 0 \\<and> 0 \\<le> sint (op1 - op2) \\<and> sint(op1) < 0)\n                      \\<or>\n                      (sint(op2) < 0 \\<and> sint (op1  - op2) < 0 \\<and> sint(op1) \\<ge> 0))\\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n    apply (rewrite_one_let')+\n  apply (intro state_eqI,simp_all)\n    apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (subst add.commute[of \"ucast (NOT \\<langle>31,0\\<rangle>regs \\<sigma> r32)\"])\n      by auto\n    subgoal for \\<sigma>\n      apply (subst add.commute[of \"ucast (NOT \\<langle>31,0\\<rangle>regs \\<sigma> r32)\"])\n      apply (subst sign_sub_bit32)\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32 :: 32 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"(\\<langle>31,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 32 a)) :: 32 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"(\\<langle>31,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 32 a)) - \\<langle>31,0\\<rangle>regs \\<sigma> r32 :: 32 word\"]\n    by (auto simp add: simp_rules test_bit_of_take_bits)\n  done\nqed\n\n\nlemma is_manual_cmp_r64_Imm32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Cmp) (Reg (General SixtyFour r64_1)) (Immediate (ImmSixtyFour Imm32))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_cmp_r64_Imm32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Cmp) (Reg (General SixtyFour r64_1)) (Immediate (ImmSixtyFour Imm32))) si = \n         (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r64_1 :: 64 word;\n                   op2 = (word_of_int Imm32 :: 64 word)\n               in\n        \\<sigma>\\<lparr>flags := (flags \\<sigma>)\n          (flag_pf := undefined,\n           flag_cf := op2 > op1,\n           flag_zf := op1 = op2,\n           flag_sf := sint (op1 - op2) < 0,\n           flag_of := (sint(op2) \\<ge> 0 \\<and> 0 \\<le> sint (op1 - op2) \\<and> sint(op1) < 0)\n                      \\<or>\n                      (sint(op2) < 0 \\<and> sint (op1  - op2) < 0 \\<and> sint(op1) \\<ge> 0))\\<rparr>)\"\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')+\n  apply (intro state_eqI,simp_all)\n  apply (intro flags_eqI,simp_all)\n  subgoal for \\<sigma>\n    apply (subst sextend_useless_64_64)\n    unfolding bv_slice.simps\n    apply (auto simp add:ucast_bitNOT ucast_id)\n    done\n  subgoal for \\<sigma>\n    apply (subst sextend_useless_64_64)\n    using overflow_sub_bit64[where ?a=\"regs \\<sigma> r64_1\" and ?b=\"word_of_int Imm32\"]\n    apply (auto simp add:simp_rules )\n    done\n  subgoal for \\<sigma>\n    apply (subst sextend_useless_64_64)\n    using sign_sub_bit64[where ?a=\"regs \\<sigma> r64_1\" and ?b=\"word_of_int Imm32\", simplified]\n    apply (auto simp add:simp_rules)\n    done\n  subgoal for \\<sigma>\n    apply (subst useless_sextend_hardocded_ucast)\n    apply (subst useless_sextend_hardocded_ucast)\n    apply (subst sextend_useless_64_64)\n    apply(subst test_64b_of_AND1000_word[symmetric, where ?w=\"regs \\<sigma> r64_1\"])\n    using sign_sub_bit64[where ?a=\"regs \\<sigma> r64_1\" and ?b=\"word_of_int Imm32\", simplified]\n    apply (auto simp add:simp_rules)\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"word_of_int Imm32 :: 64 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"regs \\<sigma> r64_1 :: 64 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"(regs \\<sigma> r64_1 - word_of_int Imm32) :: 64 word\"]\n    using sub_overflow_flag64_bit[where ?b=\"word_of_int Imm32 :: 64 word\" and ?a=\"regs \\<sigma> r64_1\"]\n    apply (auto simp add: word_msb_sint msb_nth test_bit_of_take_bits)\n    done\n  done\n\n\n\nlemma is_manual_cmp_m64_Imm64[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Cmp) (Memory 64 Mem) (Immediate (ImmSixtyFour Imm32))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_cmp_m64_Imm64[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Cmp) (Memory 64 Mem) (Immediate (ImmSixtyFour Imm32))) si = \n         (\\<lambda> \\<sigma> .let  op1 = read_mem64 \\<alpha> \\<sigma> 64 Mem;\n                   op2 = (word_of_int Imm32 :: 64 word)\n               in\n        \\<sigma>\\<lparr>flags := (flags \\<sigma>)\n          (flag_pf := undefined,\n           flag_cf := op2 > op1,\n           flag_zf := op1 = op2,\n           flag_sf := sint (op1 - op2) < 0,\n           flag_of := (sint(op2) \\<ge> 0 \\<and> 0 \\<le> sint (op1 - op2) \\<and> sint(op1) < 0)\n                      \\<or>\n                      (sint(op2) < 0 \\<and> sint (op1  - op2) < 0 \\<and> sint(op1) \\<ge> 0))\\<rparr>)\"\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')+\n  apply (intro state_eqI,simp_all)\n  apply (intro flags_eqI,simp_all)\n  subgoal for \\<sigma>\n    apply (subst sextend_useless_64_64)\n    unfolding bv_slice.simps\n    apply (auto simp add:ucast_bitNOT ucast_id)\n    done\n  subgoal for \\<sigma>\n    apply (subst sextend_useless_64_64)\n\n    using overflow_sub_bit64[where ?a=\"fst (read_memory \\<alpha> \\<sigma> 64 Mem)\" and ?b=\"word_of_int Imm32\"]\n    apply (auto simp add:simp_rules )\n    done\n  subgoal for \\<sigma>\n    apply (subst sextend_useless_64_64)\n    using sign_sub_bit64[where ?a=\"fst (read_memory \\<alpha> \\<sigma> 64 Mem)\" and ?b=\"word_of_int Imm32\", simplified]\n    apply (auto simp add:simp_rules)\n    done\n  subgoal for \\<sigma>\n    apply (subst useless_sextend_hardocded_ucast)\n    apply (subst useless_sextend_hardocded_ucast)\n    apply (subst sextend_useless_64_64)\n    apply(subst test_64b_of_AND1000_word[symmetric, where ?w=\"fst (read_memory \\<alpha> \\<sigma> 64 Mem)\"])\n    using sign_sub_bit64[where ?a=\"fst (read_memory \\<alpha> \\<sigma> 64 Mem)\" and ?b=\"word_of_int Imm32\", simplified]\n    apply (auto simp add:simp_rules)\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"word_of_int Imm32 :: 64 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"fst (read_memory \\<alpha> \\<sigma> 64 Mem) :: 64 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"(fst (read_memory \\<alpha> \\<sigma> 64 Mem) - word_of_int Imm32) :: 64 word\"]\n    using sub_overflow_flag64_bit[where ?b=\"word_of_int Imm32 :: 64 word\" and ?a=\"fst (read_memory \\<alpha> \\<sigma> 64 Mem)\"]\n    apply (auto simp add: word_msb_sint msb_nth test_bit_of_take_bits)\n    done\n  done\n\n\n\nlemma is_manual_cmp_m8_Imm8[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Cmp) (Memory 8 Mem) (Immediate (ImmSixtyFour Imm8))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma take_bits_remove_NOT:\n  fixes a :: \"64 word\"\n  shows \"\\<langle>7,0\\<rangle>(NOT (\\<langle>7,0\\<rangle>a :: 1000 word)) = ((NOT \\<langle>7,0\\<rangle>a) :: 8 word)\"\n  apply (intro word_eqI)\n  by (auto simp add:simp_rules test_bit_of_take_bits word_size bitNOT_nth)\n\nlemma take_bits_lt_bit8[get_semantics_rewriting]:\n  fixes a b :: \"'b::len0 word\"\n  assumes \"8 \\<le> LENGTH('a)\"\n      and \"8 \\<le> LENGTH('b)\"\n  shows \"(((\\<langle>7,0\\<rangle>a)::'a::len0 word) < ((\\<langle>7,0\\<rangle>b)::'a::len0 word)) = (((\\<langle>7,0\\<rangle>a)::8 word) < ((\\<langle>7,0\\<rangle>b)::8 word))\"\nproof-\n  have 1: \"\\<forall>i\\<ge>8. i < length (rev (to_bl ((\\<langle>7,0\\<rangle>a)::'a::len0 word))) \\<longrightarrow> \\<not>rev (to_bl ((\\<langle>7,0\\<rangle>a)::'a::len0 word)) ! i\"\n    using assms\n    by (auto simp add: rev_nth test_bit_of_take_bits to_bl_nth word_size)\n  have 2: \"\\<forall>i\\<ge>8. i < length (rev (to_bl ((\\<langle>7,0\\<rangle>b)::'a::len0 word))) \\<longrightarrow> \\<not>rev (to_bl ((\\<langle>7,0\\<rangle>b)::'a::len0 word)) ! i\"\n    using assms\n    by (auto simp add: rev_nth test_bit_of_take_bits to_bl_nth word_size)\n  have 3: \"\\<And> a ::'b::len0 word . take 8 (rev (to_bl ((\\<langle>7,0\\<rangle>a)::'a::len0 word))) = rev (to_bl ((\\<langle>7,0\\<rangle>a)::8 word))\"\n  proof-\n    fix a :: \"'b::len0 word\"\n    {\n      fix i :: nat\n      assume \"i < 8\"\n      hence \"take 8 (rev (to_bl ((\\<langle>7,0\\<rangle>a)::'a::len0 word))) ! i = rev (to_bl ((\\<langle>7,0\\<rangle>a)::8 word)) ! i\"\n        using assms\n        by (auto simp add: rev_nth to_bl_nth word_size test_bit_of_take_bits)\n    }\n    thus \"?thesis a\"\n      using assms\n      apply (intro nth_equalityI)\n      by (auto)\n  qed\n\n  show ?thesis\n    apply (auto simp add: word_less_rbl)\n    apply (subst (asm) rev_bl_order_take[of 8])\n    using 1 2 3\n    apply auto\n    apply (subst rev_bl_order_take[of 8])\n    using 1 2 3\n    by auto\nqed\n\nlemma take_bits_le_bit8[get_semantics_rewriting]:\n  fixes a b :: \"'b::len0 word\"\n  assumes \"8 \\<le> LENGTH('a)\"\n      and \"8 \\<le> LENGTH('b)\"\n  shows \"(((\\<langle>7,0\\<rangle>a)::'a::len0 word) \\<le> ((\\<langle>7,0\\<rangle>b)::'a::len0 word)) = (((\\<langle>7,0\\<rangle>a)::8 word) \\<le> ((\\<langle>7,0\\<rangle>b)::8 word))\"\nproof-\n  have \"(((\\<langle>7,0\\<rangle>a)::'a::len0 word) = ((\\<langle>7,0\\<rangle>b)::'a::len0 word)) = (((\\<langle>7,0\\<rangle>a)::8 word) = ((\\<langle>7,0\\<rangle>b)::8 word))\"\n  proof-\n    { fix i :: nat\n      assume \"(((\\<langle>7,0\\<rangle>a)::'a::len0 word) = ((\\<langle>7,0\\<rangle>b)::'a::len0 word))\"\n      hence \"\\<forall> i <8 . (((\\<langle>7,0\\<rangle>a)::'a::len0 word) !! i = (((\\<langle>7,0\\<rangle>b)::'a::len0 word)) !! i)\"\n        using assms\n        by (auto simp add: test_bit_of_take_bits)\n   \n      hence \"\\<forall> i < 8 . (((\\<langle>7,0\\<rangle>a)::8 word) !! i = (((\\<langle>7,0\\<rangle>b):: 8 word)) !! i)\"\n        using assms\n        by (simp add: simp_rules test_bit_of_take_bits)\n      hence \"(((\\<langle>7,0\\<rangle>a)::8 word) = ((\\<langle>7,0\\<rangle>b)::8 word))\"\n        apply (intro word_eqI)\n        by (auto simp add: word_size)\n    }\n    moreover\n    {\n      assume \"(((\\<langle>7,0\\<rangle>a)::8 word) = ((\\<langle>7,0\\<rangle>b)::8 word))\"\n      hence \"\\<forall> i < 8 . (((\\<langle>7,0\\<rangle>a)::8 word) !! i = (((\\<langle>7,0\\<rangle>b)::8 word)) !! i)\"\n        using assms\n        by (auto simp add: test_bit_of_take_bits)\n      hence \"\\<forall> i < LENGTH('a) . (((\\<langle>7,0\\<rangle>a)::'a::len0 word) !! i = (((\\<langle>7,0\\<rangle>b)::'a::len0 word)) !! i)\"\n        using assms\n        by (auto simp add: simp_rules test_bit_of_take_bits)\n      hence \"(((\\<langle>7,0\\<rangle>a)::'a::len0 word) = ((\\<langle>7,0\\<rangle>b)::'a::len0 word))\"\n        using assms\n        apply (intro word_eqI)\n        by (auto simp add: word_size)\n    }\n    ultimately\n    show ?thesis\n      by auto\n  qed\n  thus ?thesis\n    using assms\n    apply (cases \"(((\\<langle>7,0\\<rangle>a)::'a::len0 word) = ((\\<langle>7,0\\<rangle>b)::'a::len0 word))\"; cases \"(((\\<langle>7,0\\<rangle>a)::8 word) = ((\\<langle>7,0\\<rangle>b)::8 word))\";auto)\n    by (meson less_imp_le_nat linorder_not_le take_bits_lt_bit8)+\nqed\n\nvalue \"2 ^ 8 :: 65 word\"\n\n\nlemma overflow_sub_bit8[get_semantics_rewriting]:\n  fixes a b:: \"'a :: len0 word\"\n  assumes \"64\\<le> LENGTH('a)\"\n  shows \"((1::9 word) + (((\\<langle>7,0\\<rangle>a)::9 word) + ucast (NOT ((\\<langle>7,0\\<rangle>b):: 8 word)))) !! 8 = (((\\<langle>7,0\\<rangle>a)::8 word) \\<ge> \\<langle>7,0\\<rangle>b)\"\nproof-\n  have 3: \"(((\\<langle>7,0\\<rangle>a)::9 word) \\<ge> \\<langle>7,0\\<rangle>b) = (((\\<langle>7,0\\<rangle>a)::8 word) \\<ge> \\<langle>7,0\\<rangle>b)\"\n    using assms\n    by (subst take_bits_le_bit8,simp,simp,simp)\n  have 1: \"\\<not> ((\\<langle>7,0\\<rangle>a)::9 word) !! 8\"\n   and 2: \"\\<not> ((\\<langle>7,0\\<rangle>b)::9 word) !! 8\"\n    using assms\n    by (auto simp add: test_bit_of_take_bits)\n  have \"uint ((\\<langle>7,0\\<rangle>a)::9 word) < 256\"\n   and \"uint ((\\<langle>7,0\\<rangle>b)::9 word) < 256\"\n    using msb_is_gt_2p[unfolded msb_nth,where 'a=9,simplified] 1\n    apply (uint_arith)\n    using msb_is_gt_2p[unfolded msb_nth,where 'a=9,simplified] 2\n    by (uint_arith)\n  hence \"((1::9 word) + (((\\<langle>7,0\\<rangle>a)::9 word) + ucast (NOT ((\\<langle>7,0\\<rangle>b):: 8 word)))) !! 8 = (((\\<langle>7,0\\<rangle>a)::9 word) \\<ge> \\<langle>7,0\\<rangle>b)\"\n    apply (subst ucast_bitNOT)\n    apply simp\n    apply (subst twos_complement_subtraction)\n    apply simp\n    apply (subst msb_is_gt_2p[unfolded msb_nth,where 'a=9,simplified])\n    apply auto\n    apply uint_arith\n    using assms\n    apply (auto simp add: is_up)\n    apply uint_arith\n    using assms\n    by (auto simp add: is_up)\n  thus ?thesis\n    using 3\n    by auto\nqed\n\n\nlemma sign_sub_bit8[get_semantics_rewriting]:\n  fixes a b:: \"'a :: len0 word\"\n  assumes \"63 < LENGTH('a)\"\n  shows \"((1::9 word) + (((\\<langle>7,0\\<rangle>a)::9 word) + ucast (NOT ((\\<langle>7,0\\<rangle>b):: 8 word)))) !! 7 \\<longleftrightarrow> sint (((\\<langle>7,0\\<rangle>a):: 8 word) - \\<langle>7,0\\<rangle>b) < 0\"\nproof-\n  have 1: \"\\<And> a :: 9 word . a !! 7 = ((\\<langle>7,0\\<rangle>a):: 8 word) !! 7\"\n    using assms\n    by (auto simp add: test_bit_of_take_bits nth_ucast)\n  have 2: \"\\<langle>7,0\\<rangle>((1::9 word) + (((\\<langle>7,0\\<rangle>a)::9 word) + ucast (NOT ((\\<langle>7,0\\<rangle>b):: 8 word)))) = (((\\<langle>7,0\\<rangle>a)::8 word) - \\<langle>7,0\\<rangle>b)\"\n    using assms\n    apply (subst ucast_bitNOT)\n    apply simp\n    apply (subst twos_complement_subtraction)\n    apply (subst take_bits_minus)\n    apply (simp)\n    apply (simp)\n    by (simp)\n  have 3: \"... !! 7 \\<longleftrightarrow> sint (((\\<langle>7,0\\<rangle>a):: 8 word) - \\<langle>7,0\\<rangle>b) < 0\"\n    using msb_nth[symmetric, where 'a=8]\n    by (simp add: word_msb_sint)\n  show ?thesis\n    apply (subst 1)\n    apply (subst 2)\n    apply (subst 3)\n    by simp\nqed\n\n\nlemma test_8b_of_8AND1000_word[get_semantics_rewriting]:\n  fixes a :: \"1000 word\"\n  shows \"a !! 8 = (\\<langle>8,0\\<rangle>a :: 9 word) !! 8\"\n  by (auto simp add:simp_rules test_bit_of_take_bits)\n\nlemma take_bits_remove_NOT_1000word[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"\\<langle>7,0\\<rangle>(NOT (\\<langle>7,0\\<rangle>a :: 1000 word)) = (\\<langle>7,0\\<rangle>(NOT a) :: 1000 word)\"\n  apply (intro word_eqI)\n  by (auto simp add:simp_rules test_bit_of_take_bits word_size bitNOT_nth)\n\nlemma take_bits_remove_NOT_9word[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"\\<langle>7,0\\<rangle>(NOT (\\<langle>7,0\\<rangle>a :: 9 word)) = (\\<langle>7,0\\<rangle>(NOT a) :: 9 word)\"\n  apply (intro word_eqI)\n  by (auto simp add:simp_rules test_bit_of_take_bits word_size bitNOT_nth)\n\n\nlemma take_bits_remove_UCAST_NOT_9word[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"(\\<langle>7,0\\<rangle>(NOT a) :: 9 word) = (ucast (NOT (\\<langle>7,0\\<rangle>a :: 8 word)) :: 9 word)\"\n  apply (intro word_eqI)\n  by (auto simp add:simp_rules test_bit_of_take_bits word_size bitNOT_nth)\n\nlemma take_bits_remove_UCAST_NOT_1000word[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"\\<langle>7,0\\<rangle>(NOT (\\<langle>7,0\\<rangle>a :: 1000 word)) = (ucast (NOT (\\<langle>7,0\\<rangle>a :: 8 word)) :: 9 word)\"\n  apply (intro word_eqI)\n  by (auto simp add:simp_rules test_bit_of_take_bits word_size bitNOT_nth)\n\nlemma take_bits_remove_UCAST_NOT_9word_2[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"\\<langle>7,0\\<rangle>(NOT (\\<langle>7,0\\<rangle>a :: 9 word)) = (ucast (NOT (\\<langle>7,0\\<rangle>a :: 8 word)) :: 9 word)\"\n  apply (intro word_eqI)\n  by (auto simp add:simp_rules test_bit_of_take_bits word_size bitNOT_nth)\n\nlemma test_bit7_of_64_and_1000word[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"(\\<langle>63,0\\<rangle>a :: 1000 word) !! 7 = (\\<langle>7,0\\<rangle>a :: 8 word) !! 7\"\n  by (auto simp add:test_bit_of_take_bits)\n\n\nlemma sub_overflow_flag8_bit[get_semantics_rewriting]:\n  fixes a b :: \"'a::len0 word\"\n  assumes \"LENGTH('a) \\<ge> 64\"\n  shows \"((\\<not> b !! 7) = a !! 7 \\<and> b !! 7 = (sint (\\<langle>7,0\\<rangle>a - \\<langle>7,0\\<rangle>b::8 word) < 0)) \\<longleftrightarrow>\n            ((128::8 word) > \\<langle>7,0\\<rangle>b \\<and> sint (\\<langle>7,0\\<rangle>a - \\<langle>7,0\\<rangle>b::8 word) \\<ge> 0 \\<and> (128::8 word) \\<le> \\<langle>7,0\\<rangle>a)\n             \\<or>\n             ((128::8 word) \\<le> \\<langle>7,0\\<rangle>b \\<and> sint (\\<langle>7,0\\<rangle>a - \\<langle>7,0\\<rangle>b::8 word) < 0 \\<and> (128::8 word) > \\<langle>7,0\\<rangle>a)\"\nproof-\n  have 1: \"a !! 7 = msb (\\<langle>7,0\\<rangle> a :: 8 word)\"\n   and 2: \"b !! 7 = msb (\\<langle>7,0\\<rangle> b :: 8 word)\"\n    using assms\n    by (auto simp add: msb_nth test_bit_of_take_bits)\n  show ?thesis\n    using assms\n    apply (subst 1)\n    apply (subst 2)+\n    apply (subst msb_is_gt_2p)+\n    apply simp\n    by (auto)\nqed\n\n\n\nlemma BV_Add_bit9:\n fixes a b :: longword\n   shows \"(a,9) +\\<^sup>b\\<^sup>v (b,9) = (ucast (((\\<langle>8,0\\<rangle>a)::9 word) + \\<langle>8,0\\<rangle>b), 9)\"\nproof-\n have \"(a,9) +\\<^sup>b\\<^sup>v (b,9) = (\\<langle>8,0\\<rangle>(a + b), 9)\"\n   by (cases a;cases b;auto simp add: exec_BV_Plus_def case_prod_unfold)\n also have \"... = (ucast ((\\<langle>8,0\\<rangle>(a + b))::9 word), 9)\"\n   by (subst ucast_take_bits,simp,simp,simp)\n also have \"... = (ucast (((\\<langle>8,0\\<rangle>a)::9 word) + \\<langle>8,0\\<rangle>b), 9)\"\n   by (subst take_bits_plus,simp,simp,simp)\n finally\n show ?thesis\n   by auto\nqed\n\nlemma get_semantics_cmp_m8_Imm8[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Cmp) (Memory 8 Mem) (Immediate (ImmSixtyFour Imm32))) si = \n         (\\<lambda> \\<sigma> .let  op1 = \\<langle>7,0\\<rangle>read_mem64 \\<alpha> \\<sigma> 8 Mem :: 8 word;\n                   op2 = \\<langle>7,0\\<rangle>(word_of_int Imm32 :: 64 word) :: 8 word\n               in\n        \\<sigma>\\<lparr>flags := (flags \\<sigma>)\n          (flag_pf := undefined,\n           flag_cf := op2 > op1,\n           flag_zf := op1 = op2,\n           flag_sf := sint (op1 - op2) < 0,\n           flag_of :=  (sint(op2) \\<ge> 0 \\<and> 0 \\<le> sint (op1 - op2) \\<and> sint(op1) < 0)\n                      \\<or>\n                      (sint(op2) < 0 \\<and> sint (op1  - op2) < 0 \\<and> sint(op1) \\<ge> 0))\\<rparr>)\"\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let' add:BV_Add_bit9)+\n  apply (intro state_eqI,simp_all)\n  apply (intro flags_eqI,simp_all)\n  subgoal for \\<sigma>\n    unfolding bv_slice.simps\n    apply (auto simp add:simp_rules exec_BV_Plus_def take_bits_remove_NOT)\n    done\n  subgoal for \\<sigma>\n    apply (subst take_bits_remove_UCAST_NOT_1000word)\n    using overflow_sub_bit8[where ?a=\"fst (read_memory \\<alpha> \\<sigma> 8 Mem)\" and ?b=\"word_of_int Imm32\", simplified]\n    apply (auto simp add:simp_rules take_bits_remove_UCAST_NOT_9word)\n    done\n  subgoal for \\<sigma>\n    apply (subst take_bits_remove_UCAST_NOT_1000word)\n    using sign_sub_bit8[where ?a=\"fst (read_memory \\<alpha> \\<sigma> 8 Mem)\" and ?b=\"word_of_int Imm32\"]\n    apply (auto simp add:simp_rules )\n    done\n  subgoal for \\<sigma>\n    apply(subst test_bit7_of_64_and_1000word[where ?a=\"fst (read_memory \\<alpha> \\<sigma> 8 Mem)\"])\n    apply(subst test_bit7_of_64_and_1000word[where ?a=\"word_of_int Imm32\"])\n    apply(subst test_bit7_of_64_and_1000word[where ?a=\"word_of_int Imm32\"])\n    apply (subst take_bits_remove_UCAST_NOT_1000word)\n    using sign_sub_bit8[where ?a=\"fst (read_memory \\<alpha> \\<sigma> 8 Mem)\" and ?b=\"word_of_int Imm32\", simplified]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"\\<langle>7,0\\<rangle>word_of_int Imm32 :: 8 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"\\<langle>7,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 8 Mem) :: 8 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"(\\<langle>7,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 8 Mem) - \\<langle>7,0\\<rangle>word_of_int Imm32) :: 8 word\"]\n    apply (auto simp add:simp_rules test_bit_of_take_bits)\n    done\n  done\n\n\n\nlemma is_manual_cmp_r8_m8[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Cmp) (Reg (General EightLow r1)) (Storage (Memory 8 a))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_cmp_r8_m8[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Cmp) (Reg (General EightLow r1)) (Storage (Memory 8 a))) si = \n             (\\<lambda> \\<sigma> . let op1 = \\<langle>7,0\\<rangle>regs \\<sigma> r1 :: 8 word;\n                   op2 = \\<langle>7,0\\<rangle>(read_mem64 \\<alpha> \\<sigma> 8 a) :: 8 word\n               in\n        \\<sigma>\\<lparr>flags := (flags \\<sigma>)\n          (flag_pf := undefined,\n           flag_cf := op2 > op1,\n           flag_zf := op1 = op2,\n           flag_sf := sint (op1 - op2) < 0,\n           flag_of := (sint(op2) \\<ge> 0 \\<and> 0 \\<le> sint (op1 - op2) \\<and> sint(op1) < 0)\n                      \\<or>\n                      (sint(op2) < 0 \\<and> sint (op1  - op2) < 0 \\<and> sint(op1) \\<ge> 0))\\<rparr>)\"\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let' add:BV_Add_bit9)+\n  apply (intro state_eqI,simp_all)\n  apply (intro flags_eqI,simp_all)\n  subgoal for \\<sigma>\n    unfolding bv_slice.simps\n    apply (auto simp add:simp_rules exec_BV_Plus_def take_bits_remove_NOT)\n    done\n  subgoal for \\<sigma>\n    apply (subst take_bits_remove_UCAST_NOT_1000word)\n    using overflow_sub_bit8[where ?a=\"regs \\<sigma> r1\" and ?b=\"fst (read_memory \\<alpha> \\<sigma> 8 a)\", simplified]\n    apply (auto simp add:simp_rules take_bits_remove_UCAST_NOT_9word)\n    done\n  subgoal for \\<sigma>\n    apply (subst take_bits_remove_UCAST_NOT_1000word)\n    using sign_sub_bit8[where ?a=\"regs \\<sigma> r1\" and ?b=\"fst (read_memory \\<alpha> \\<sigma> 8 a)\"]\n    apply (auto simp add:simp_rules )\n    done\n  subgoal for \\<sigma>\n    apply(subst test_bit7_of_64_and_1000word[where ?a=\"regs \\<sigma> r1\"])\n    apply(subst test_bit7_of_64_and_1000word[where ?a=\"fst (read_memory \\<alpha> \\<sigma> 8 a)\"])\n    apply(subst test_bit7_of_64_and_1000word[where ?a=\"fst (read_memory \\<alpha> \\<sigma> 8 a)\"])\n    apply (subst take_bits_remove_UCAST_NOT_1000word)\n    using sign_sub_bit8[where ?a=\"regs \\<sigma> r1\" and ?b=\"fst (read_memory \\<alpha> \\<sigma> 8 a)\", simplified]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"\\<langle>7,0\\<rangle>regs \\<sigma> r1 :: 8 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"\\<langle>7,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 8 a) :: 8 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"(\\<langle>7,0\\<rangle>regs \\<sigma> r1 - \\<langle>7,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 8 a)) :: 8 word\"]\n    apply (auto simp add:simp_rules)\n    done\n  done\n\n\n\nlemma is_manual_cmp_m32_Imm32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Cmp) (Memory 32 Mem) (Immediate (ImmSixtyFour Imm32))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_cmp_m32_Imm32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Cmp) (Memory 32 Mem) (Immediate (ImmSixtyFour Imm32))) si = \n         (\\<lambda> \\<sigma> . let a = resolve_address \\<alpha> \\<sigma> Mem;\n                  op1 = \\<langle>31,0\\<rangle>(read_mem64 \\<alpha> \\<sigma> 32 Mem :: 64 word) :: 32 word;\n                   op2 = \\<langle>31,0\\<rangle>(word_of_int Imm32 :: 64 word) :: 32 word\n               in\n        \\<sigma>\\<lparr>flags := (flags \\<sigma>)\n          (flag_pf := undefined,\n           flag_cf := op2 > op1,\n           flag_zf := op1 = op2,\n           flag_sf := sint (op1 - op2) < 0,\n           flag_of := (sint(op2) \\<ge> 0 \\<and> 0 \\<le> sint (op1 - op2) \\<and> sint(op1) < 0)\n                      \\<or>\n                      (sint(op2) < 0 \\<and> sint (op1  - op2) < 0 \\<and> sint(op1) \\<ge> 0))\\<rparr>)\"\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')+\n  apply (intro state_eqI,simp_all)\n  apply (intro flags_eqI,simp_all)\n  subgoal for \\<sigma>\n    using sign_sub_bit32[where ?a=\"fst (read_memory \\<alpha> \\<sigma> 32 Mem)\" and ?b=\"word_of_int Imm32\"]\n    apply (auto simp add: simp_rules)\n    done\n  subgoal for \\<sigma>\n    apply (subst test_32b_of_32AND64_word[where ?a=\"fst (read_memory \\<alpha> \\<sigma> 32 Mem)\"])\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"\\<langle>31,0\\<rangle>word_of_int Imm32 :: 32 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"\\<langle>31,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 32 Mem) :: 32 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"(\\<langle>31,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 32 Mem) - \\<langle>31,0\\<rangle>word_of_int Imm32) :: 32 word\"]\n \n    using sign_sub_bit32[where ?a=\"fst (read_memory \\<alpha> \\<sigma> 32 Mem)\" and ?b=\"word_of_int Imm32\"]\n    apply (auto simp add: simp_rules test_bit_of_take_bits)\n    done\n  done\n\n\n(*---------------------------------------------------proofs on test ---------------------------------------*)\n\nlemma take_bits_AND_zero_64_word[get_semantics_rewriting]:\n  fixes a b :: \"64 word\"\n  shows \"(\\<langle>63,0\\<rangle>a AND \\<langle>63,0\\<rangle>b = (0::1000 word)) \\<longleftrightarrow> (a AND b = (0 :: 64 word))\"\nproof-\n  {\n    assume 1: \"(\\<langle>63,0\\<rangle>a AND \\<langle>63,0\\<rangle>b = (0::1000 word))\"\n    hence 2: \"\\<forall> i < 1000 . (\\<langle>63,0\\<rangle>a AND \\<langle>63,0\\<rangle>b :: 1000 word) !! i = False\"\n      apply (subst 1)\n      by auto\n    have \"(a AND b = (0 :: 64 word))\"\n    proof-\n      {\n        fix i :: nat\n        assume \"i < 64\"\n        hence \"(a AND b :: 64 word) !! i = (0 :: 64 word) !! i\"\n          using 2[THEN spec, of i]\n          by (auto simp add: word_ao_nth test_bit_of_take_bits)\n      }\n      thus ?thesis\n        apply (intro word_eqI)\n        by (auto simp add: word_size)\n    qed\n  }\n  moreover\n  {\n    assume 1: \"(a AND b = (0::64 word))\"\n    hence 2: \"\\<forall> i < 64 . (a AND b :: 64 word) !! i = False\"\n      apply (subst 1)\n      by auto\n    have \"(\\<langle>63,0\\<rangle>a AND \\<langle>63,0\\<rangle>b = (0 :: 1000 word))\"\n    proof-\n      {\n        fix i :: nat\n        assume \"i < 1000\"\n        hence \"(\\<langle>63,0\\<rangle>a AND \\<langle>63,0\\<rangle>b :: 1000 word) !! i = (0 :: 1000 word) !! i\"\n          using 2[THEN spec, of i]\n          by (auto simp add: word_ao_nth test_bit_of_take_bits)\n      }\n      thus ?thesis\n        apply (intro word_eqI)\n        by (auto simp add: word_size)\n    qed\n  }\n  ultimately\n  show ?thesis\n    by auto\nqed\n\n\n\nlemma take_bits_AND_zero_32_word[get_semantics_rewriting]:\n  fixes a b :: \"64 word\"\n  shows \"(\\<langle>31,0\\<rangle>a AND \\<langle>31,0\\<rangle>b = (0::1000 word)) \\<longleftrightarrow> (\\<langle>31,0\\<rangle>a AND \\<langle>31,0\\<rangle>b = (0 :: 32 word))\"\nproof-\n  {\n    assume 1: \"(\\<langle>31,0\\<rangle>a AND \\<langle>31,0\\<rangle>b = (0::1000 word))\"\n    hence 2: \"\\<forall> i < 1000 . (\\<langle>31,0\\<rangle>a AND \\<langle>31,0\\<rangle>b :: 1000 word) !! i = False\"\n      apply (subst 1)\n      by auto\n    have \"(\\<langle>31,0\\<rangle>a AND \\<langle>31,0\\<rangle>b = (0 :: 32 word))\"\n    proof-\n      {\n        fix i :: nat\n        assume \"i < 32\"\n        hence \"(\\<langle>31,0\\<rangle>a AND \\<langle>31,0\\<rangle>b :: 32 word) !! i = (0 :: 32 word) !! i\"\n          using 2[THEN spec, of i]\n          by (auto simp add: word_ao_nth test_bit_of_take_bits)\n      }\n      thus ?thesis\n        apply (intro word_eqI)\n        by (auto simp add: word_size)\n    qed\n  }\n  moreover\n  {\n    assume 1: \"(\\<langle>31,0\\<rangle>a AND \\<langle>31,0\\<rangle>b = (0::32 word))\"\n    hence 2: \"\\<forall> i < 32 . (\\<langle>31,0\\<rangle>a AND \\<langle>31,0\\<rangle>b :: 32 word) !! i = False\"\n      apply (subst 1)\n      by auto\n    have \"(\\<langle>31,0\\<rangle>a AND \\<langle>31,0\\<rangle>b = (0 :: 1000 word))\"\n    proof-\n      {\n        fix i :: nat\n        assume \"i < 1000\"\n        hence \"(\\<langle>31,0\\<rangle>a AND \\<langle>31,0\\<rangle>b :: 1000 word) !! i = (0 :: 1000 word) !! i\"\n          using 2[THEN spec, of i]\n          by (auto simp add: word_ao_nth test_bit_of_take_bits)\n      }\n      thus ?thesis\n        apply (intro word_eqI)\n        by (auto simp add: word_size)\n    qed\n  }\n  ultimately\n  show ?thesis\n    by auto\nqed\n\n\nlemma take_bits_AND_zero_16_word[get_semantics_rewriting]:\n  fixes a b :: \"64 word\"\n  shows \"(\\<langle>15,0\\<rangle>a AND \\<langle>15,0\\<rangle>b = (0::1000 word)) \\<longleftrightarrow> (\\<langle>15,0\\<rangle>a AND \\<langle>15,0\\<rangle>b = (0 :: 16 word))\"\nproof-\n  {\n    assume 1: \"(\\<langle>15,0\\<rangle>a AND \\<langle>15,0\\<rangle>b = (0::1000 word))\"\n    hence 2: \"\\<forall> i < 1000 . (\\<langle>15,0\\<rangle>a AND \\<langle>15,0\\<rangle>b :: 1000 word) !! i = False\"\n      apply (subst 1)\n      by auto\n    have \"(\\<langle>15,0\\<rangle>a AND \\<langle>15,0\\<rangle>b = (0 :: 16 word))\"\n    proof-\n      {\n        fix i :: nat\n        assume \"i < 16\"\n        hence \"(\\<langle>15,0\\<rangle>a AND \\<langle>15,0\\<rangle>b :: 16 word) !! i = (0 :: 16 word) !! i\"\n          using 2[THEN spec, of i]\n          by (auto simp add: word_ao_nth test_bit_of_take_bits)\n      }\n      thus ?thesis\n        apply (intro word_eqI)\n        by (auto simp add: word_size)\n    qed\n  }\n  moreover\n  {\n    assume 1: \"(\\<langle>15,0\\<rangle>a AND \\<langle>15,0\\<rangle>b = (0::16 word))\"\n    hence 2: \"\\<forall> i < 16 . (\\<langle>15,0\\<rangle>a AND \\<langle>15,0\\<rangle>b :: 16 word) !! i = False\"\n      apply (subst 1)\n      by auto\n    have \"(\\<langle>15,0\\<rangle>a AND \\<langle>15,0\\<rangle>b = (0 :: 1000 word))\"\n    proof-\n      {\n        fix i :: nat\n        assume \"i < 1000\"\n        hence \"(\\<langle>15,0\\<rangle>a AND \\<langle>15,0\\<rangle>b :: 1000 word) !! i = (0 :: 1000 word) !! i\"\n          using 2[THEN spec, of i]\n          by (auto simp add: word_ao_nth test_bit_of_take_bits)\n      }\n      thus ?thesis\n        apply (intro word_eqI)\n        by (auto simp add: word_size)\n    qed\n  }\n  ultimately\n  show ?thesis\n    by auto\nqed\n\n\n\nlemma bool_to_bv_eq_fst[get_semantics_rewriting]:\n shows \"fst (bool_to_bv b) = x \\<longleftrightarrow> (x \\<in> {0,1} \\<and> ((x = 1) \\<longleftrightarrow> b))\"\n  by (cases b,auto)\n\nlemma fst_bool_to_bv_AND_def[get_semantics_rewriting]:\n shows \"(fst (bool_to_bv a) AND fst (bool_to_bv b)) = (if a \\<and> b then 1 else 0)\"\n by (auto simp add:bool_to_bv_eq_fst )\n\nlemma is_manual_test_r32_r32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Test) (Reg (General ThirtyTwo r32_1)) (Storage (Reg (General ThirtyTwo r32_2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_test_r32_r32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Test) (Reg (General ThirtyTwo r32_1)) (Storage (Reg (General ThirtyTwo r32_2)))) si =\n        (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r32_1 :: 32 word;\n                   op2 = \\<langle>31,0\\<rangle>regs \\<sigma> r32_2 :: 32 word\n               in\n        \\<sigma>\\<lparr>flags := (flags \\<sigma>)\n        (flag_zf := (op1 AND op2) = (0 :: 32 word),\n         flag_cf := False,\n         flag_of := False,\n         flag_sf := (sint op1 < 0) \\<and> (sint op2 < 0),\n         flag_pf := undefined)  \n\\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n  apply (rewrite_one_let' add: semantics_def)\n    apply (rewrite_one_let')+\n    subgoal for \\<sigma> \n      apply(subst word_msb_sint[where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32_1 :: 32 word\", symmetric, unfolded msb_nth])\n      apply(subst word_msb_sint[where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32_2 :: 32 word\", symmetric, unfolded msb_nth])\n      by (auto simp add:simp_rules take_bits_AND_zero_32_word msb_nth flags_eqI test_bit_of_take_bits fst_bool_to_bv_AND_def)\n    done\n  qed\n\n\nlemma is_manual_test_r64_r64[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Test) (Reg (General SixtyFour r64_1)) (Storage (Reg (General SixtyFour r64_2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_test_r64_r64[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Test) (Reg (General SixtyFour r64_1)) (Storage (Reg (General SixtyFour r64_2)))) si =\n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r64_1 :: 64 word;\n                   op2 = regs \\<sigma> r64_2 :: 64 word\n               in\n        \\<sigma>\\<lparr>flags := (flags \\<sigma>)\n        (flag_zf := (op1 AND op2) = (0 :: 64 word),\n         flag_cf := False,\n         flag_of := False,\n         flag_sf := (sint op1 < 0) \\<and> (sint op2 < 0),\n         flag_pf := undefined)  \n\\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n  apply (rewrite_one_let' add: semantics_def)\n    apply (rewrite_one_let')+\n    subgoal for \\<sigma> \n      apply(subst word_msb_sint[where ?w=\"regs \\<sigma> r64_1\", symmetric, unfolded msb_nth])\n      apply(subst word_msb_sint[where ?w=\"regs \\<sigma> r64_2\", symmetric, unfolded msb_nth])\n      find_theorems \"\\<langle>?h,?l\\<rangle>?a AND \\<langle>?h,?l\\<rangle>?b = 0\"\n      by (auto simp add:simp_rules take_bits_AND_zero_64_word msb_nth flags_eqI test_bit_of_take_bits fst_bool_to_bv_AND_def)\n    done\n  qed\n\n\nlemma is_manual_test_r16_r16[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Test) (Reg (General Sixteen r16_1)) (Storage (Reg (General Sixteen r16_2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_test_r16_r16[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Test) (Reg (General Sixteen r16_1)) (Storage (Reg (General Sixteen r16_2)))) si =\n        (\\<lambda> \\<sigma> . let op1 = \\<langle>15,0\\<rangle>regs \\<sigma> r16_1 :: 16 word;\n                   op2 = \\<langle>15,0\\<rangle>regs \\<sigma> r16_2 :: 16 word\n               in\n        \\<sigma>\\<lparr>flags := (flags \\<sigma>)\n        (flag_zf := (op1 AND op2) = (0 :: 16 word),\n         flag_cf := False,\n         flag_of := False,\n         flag_sf := (sint op1 < 0) \\<and> (sint op2 < 0),\n         flag_pf := undefined)  \n\\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')+\n  subgoal for \\<sigma> \n    apply(subst word_msb_sint[where ?w=\"\\<langle>15,0\\<rangle>regs \\<sigma> r16_1 :: 16 word\", symmetric, unfolded msb_nth])\n    apply(subst word_msb_sint[where ?w=\"\\<langle>15,0\\<rangle>regs \\<sigma> r16_2 :: 16 word\", symmetric, unfolded msb_nth])\n    by (auto simp add:simp_rules take_bits_AND_zero_16_word msb_nth flags_eqI test_bit_of_take_bits fst_bool_to_bv_AND_def)\n    done\nqed \n\n\n(*---------------------------------------------------proofs on xor ---------------------------------------*)\n\nlemma take_bits_bitXOR[get_semantics_rewriting]:\n  fixes a b :: \"64 word\"\n  shows \"((\\<langle>63,0\\<rangle>(a XOR b)) :: 1000 word) = ((\\<langle>63,0\\<rangle>a) :: 1000 word) XOR ((\\<langle>63,0\\<rangle>b))\"\nproof-\n  {\nfix n :: nat\n    assume 1: \"n < 64\"\n    hence \"((\\<langle>63,0\\<rangle>(a XOR b)) :: 1000 word) !! n = (((\\<langle>63,0\\<rangle>a) :: 1000 word) XOR \\<langle>63,0\\<rangle>b) !! n  \"\n      using 1\n        apply (subst test_bit_of_take_bits)\n      by (auto simp add: simp_rules test_bit_of_take_bits word_ao_nth bitXOR_nth)\n  }\n  thus ?thesis\n    apply (intro word_eqI)\n    by (auto simp add:simp_rules test_bit_of_take_bits word_size word_ao_nth bitXOR_nth)\nqed\n\nlemma take_bits_bitXOR2:\n  fixes a b :: \"64 word\"\n    shows \" ((\\<langle>63,0\\<rangle>a) :: 1000 word) XOR ((\\<langle>63,0\\<rangle>b)) = ((\\<langle>63,0\\<rangle>(a XOR b)) :: 1000 word)\"\nproof-\n  {\nfix n :: nat\n    assume 1: \"n < 64\"\n    hence \"(((\\<langle>63,0\\<rangle>a) :: 1000 word) XOR \\<langle>63,0\\<rangle>b) !! n = ((\\<langle>63,0\\<rangle>(a XOR b)) :: 1000 word) !! n \"\n      using 1\n        apply (subst test_bit_of_take_bits)\n      by (auto simp add: simp_rules test_bit_of_take_bits word_ao_nth bitXOR_nth)\n  }\n  thus ?thesis\n    apply (intro word_eqI)\n    by (auto simp add:simp_rules test_bit_of_take_bits word_size word_ao_nth bitXOR_nth)\nqed\n\n\n\nlemma take_bits_XOR_eq_zero_64word[get_semantics_rewriting]:\n  fixes a b :: \"64 word\"\n  shows \"((\\<langle>63,0\\<rangle>a XOR \\<langle>63,0\\<rangle>b) = (0::1000 word)) \\<longleftrightarrow>  ((a XOR  b) = (0::64 word))\"\nproof-\n  {\n    assume 1: \"((\\<langle>63,0\\<rangle>a XOR \\<langle>63,0\\<rangle>b) = (0::1000 word))\"\n    hence 2: \"\\<forall> i<1000. (((\\<langle>63,0\\<rangle>a XOR \\<langle>63,0\\<rangle>b) :: 1000 word) !! i = False)\"\n      apply (subst 1)+\n      by auto\n    have \"((a XOR b) = (0::64 word))\"\n    proof-\n      {\n        fix i :: nat\n        assume \"i < 64\"\n        hence \"((a XOR b) !! i = (0 :: 64 word) !! i)\"\n          using 2[THEN spec, of i]\n          by (auto simp add: word_ao_nth test_bit_of_take_bits bitXOR_nth)\n      }\n      thus ?thesis\n        by (auto simp add: word_size word_eqI )\n    qed\n  }\n moreover\n  {\n    assume 1: \"((a XOR b) = (0::64 word))\"\n    hence 2: \"\\<forall> i < 64 . ((a XOR b) !! i = False)\"\n      apply (subst 1)\n      by auto\n    have \"((\\<langle>63,0\\<rangle>a XOR \\<langle>63,0\\<rangle>b) = (0::1000 word))\"\n    proof-\n      {\n        fix i :: nat\n        assume \"i < 1000\"\n        hence \" (((\\<langle>63,0\\<rangle>a XOR \\<langle>63,0\\<rangle>b):: 1000 word) !! i = (0 :: 1000 word) !! i)\"\n          using 2[THEN spec, of i]\n          by (auto simp add: word_ao_nth test_bit_of_take_bits bitXOR_nth)\n      }\n      thus ?thesis\n        by (auto simp add: word_size word_eqI)\n    qed\n  }\n  ultimately\n  show ?thesis\n    by auto\nqed\n\nlemma take_bits_XOR_eq_zero_32word[get_semantics_rewriting]:\n  fixes a b :: \"64 word\"\n  shows \"((\\<langle>31,0\\<rangle>a XOR \\<langle>31,0\\<rangle>b) = (0::1000 word)) \\<longleftrightarrow>  ((\\<langle>31,0\\<rangle>a XOR \\<langle>31,0\\<rangle>b) = (0::32 word))\"\nproof-\n  {\n    assume 1: \"((\\<langle>31,0\\<rangle>a XOR \\<langle>31,0\\<rangle>b) = (0::1000 word))\"\n    hence 2: \"\\<forall> i<1000. (((\\<langle>31,0\\<rangle>a XOR \\<langle>31,0\\<rangle>b) :: 1000 word) !! i = False)\"\n      apply (subst 1)+\n      by auto\n    have \"(((\\<langle>31,0\\<rangle>a XOR \\<langle>31,0\\<rangle>b) :: 32 word) = (0::32 word))\"\n    proof-\n      {\n        fix i :: nat\n        assume \"i < 32\"\n        hence \"(((\\<langle>31,0\\<rangle>a XOR \\<langle>31,0\\<rangle>b) :: 32 word) !! i = (0 :: 32 word) !! i)\"\n          using 2[THEN spec, of i]\n          by (auto simp add: word_ao_nth test_bit_of_take_bits bitXOR_nth)\n      }\n      thus ?thesis\n        by (auto simp add: word_size word_eqI )\n    qed\n  }\n moreover\n  {\n    assume 1: \"(((\\<langle>31,0\\<rangle>a XOR \\<langle>31,0\\<rangle>b) :: 32 word) = (0::32 word))\"\n    hence 2: \"\\<forall> i < 32 . (((\\<langle>31,0\\<rangle>a XOR \\<langle>31,0\\<rangle>b) :: 32 word) !! i = False)\"\n      apply (subst 1)\n      by auto\n    have \"(((\\<langle>31,0\\<rangle>a XOR \\<langle>31,0\\<rangle>b) :: 1000 word) = (0::1000 word))\"\n    proof-\n      {\n        fix i :: nat\n        assume \"i < 1000\"\n        hence \" (((\\<langle>31,0\\<rangle>a XOR \\<langle>31,0\\<rangle>b):: 1000 word) !! i = (0 :: 1000 word) !! i)\"\n          using 2[THEN spec, of i]\n          by (auto simp add: word_ao_nth test_bit_of_take_bits bitXOR_nth)\n      }\n      thus ?thesis\n        by (auto simp add: word_size word_eqI)\n    qed\n  }\n  ultimately\n  show ?thesis\n    by auto\nqed\n\nlemma parity_bit64[simp]:\n fixes a :: \"'b::len0 word\"\n assumes \"LENGTH('a) > 64\"\n     and \"LENGTH('b) \\<ge> 64\"\n shows \"parity (\\<langle>63,0\\<rangle> a :: 'a::len0 word) = parity (\\<langle>63,0\\<rangle> a :: 64 word)\"\nproof-\n {\n   fix i\n   assume \"i < LENGTH('a)\"\n   hence \"(\\<langle>63,0\\<rangle> a :: 'a::len0 word) !! i = (ucast (\\<langle>63,0\\<rangle> a :: 64 word) :: 'a::len0 word) !! i\"\n     using assms\n     by (auto simp add: test_bit_of_take_bits nth_ucast)\n }\n hence 1: \"(\\<langle>63,0\\<rangle> a :: 'a::len0 word) = (ucast (\\<langle>63,0\\<rangle> a :: 64 word) :: 'a::len0 word)\"\n   apply (intro word_eqI)\n   by (auto simp add: word_size)\n show ?thesis\n   apply (subst 1)\n   apply (subst parity_ucast)\n   using assms 1\n   by auto\nqed\n\n\nlemma fst_bool_to_bv_XOR_def[get_semantics_rewriting]:\n shows \"(fst (bool_to_bv a) XOR fst (bool_to_bv b)) = (if (a\\<noteq>b) then 1 else 0)\"\n  by (auto simp add:bool_to_bv_eq_fst )\n\n(* Proofs on Xor  *)\nlemma is_manual_test_xor_r64_r64[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Xor) (Reg (General SixtyFour r64_1)) (Storage (Reg (General SixtyFour r64_2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_xor_r64_r64[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Xor) (Reg (General SixtyFour r64_1)) (Storage (Reg (General SixtyFour r64_2)))) si =\n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r64_1 :: 64 word;\n                   op2 = regs \\<sigma> r64_2 :: 64 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r64_1 := op1 XOR op2),\n               flags := (flags \\<sigma>)\n        (flag_zf := (op1 XOR op2) = (0 :: 64 word),\n         flag_cf := False,\n         flag_of := False,\n\n         flag_sf := (sint(op1 XOR op2) < 0 ),\n         flag_pf := parity(op1 XOR op2))  \n\\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')+\n    apply (intro state_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:simp_rules take_bits_bitXOR2)\n      done\n    apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:simp_rules take_bits_XOR_eq_zero_64word)\n      done\n    subgoal for \\<sigma>\n      apply (auto simp add:simp_rules take_bits_bitXOR2 )\n      done\n    subgoal for \\<sigma>\n      using word_msb_sint[where ?w=\"regs \\<sigma> r64_1 XOR regs \\<sigma> r64_2\"]\n      by (auto simp add:msb_nth fst_bool_to_bv_XOR_def bitXOR_nth test_bit_of_take_bits)\n      done\nqed\n\nlemma is_manual_test_xor_r32_r32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Xor) (Reg (General ThirtyTwo r32_1)) (Storage (Reg (General ThirtyTwo r32_2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_xor_r32_r32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Xor) (Reg (General ThirtyTwo r32_1)) (Storage (Reg (General ThirtyTwo r32_2)))) si =\n        (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r32_1 :: 32 word;\n                   op2 = \\<langle>31,0\\<rangle>regs \\<sigma> r32_2 :: 32 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r32_1 := ucast(op1 XOR op2)),\n               flags := (flags \\<sigma>)\n        (flag_zf := (op1 XOR op2) = (0 :: 32 word),\n         flag_cf := False,\n         flag_of := False,\n         flag_sf := (sint (op1 XOR op2) < 0),\n         flag_pf := parity(op1 XOR op2))  \n\\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n    apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')+\n    apply (intro state_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:simp_rules take_bits_bitXOR2)\n      done\n    apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:simp_rules take_bits_XOR_eq_zero_32word)\n      done\n    subgoal for \\<sigma>\n      apply (auto simp add:simp_rules parity_ucast)\n      done\n    subgoal for \\<sigma>\n      using word_msb_sint[where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32_1 XOR \\<langle>31,0\\<rangle>regs \\<sigma> r32_2\"]\n      by (auto simp add:msb_nth fst_bool_to_bv_XOR_def bitXOR_nth test_bit_of_take_bits)\n      done\nqed\n\nlemma is_manual_test_xor_r64_m64[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Xor) (Reg (General SixtyFour r64_1)) (Storage (Memory 64 Mem))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\n\n\nlemma get_semantics_xor_r64_m64[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Xor) (Reg (General SixtyFour r64_1)) (Storage (Memory 64 Mem))) si =\n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r64_1 :: 64 word;\n                   op2 = read_mem64 \\<alpha> \\<sigma> 64 Mem :: 64 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r64_1 := op1 XOR op2),\n               flags := (flags \\<sigma>)\n        (flag_zf := (op1 XOR op2) = (0 :: 64 word),\n         flag_cf := False,\n         flag_of := False,\n\n         flag_sf := (sint(op1 XOR op2) < 0 ),\n         flag_pf := parity(op1 XOR op2))  \n\\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')+\n    apply (intro state_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:simp_rules take_bits_bitXOR2)\n      done\n    apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:simp_rules take_bits_XOR_eq_zero_64word)\n      done\n    subgoal for \\<sigma>\n      apply (auto simp add:simp_rules take_bits_bitXOR2 )\n      done\n    subgoal for \\<sigma>\n      using word_msb_sint[where ?w=\"regs \\<sigma> r64_1 XOR read_mem64 \\<alpha> \\<sigma> 64 Mem\"]\n      by (auto simp add:msb_nth fst_bool_to_bv_XOR_def bitXOR_nth test_bit_of_take_bits)\n      done\nqed\n\nlemma is_manual_test_xor_m32_r32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Xor) (Memory 32 Mem) (Storage (Reg (General ThirtyTwo r32_2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_xor_m32_r32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Xor) (Memory 32 Mem) (Storage (Reg (General ThirtyTwo r32_2)))) si =\n        (\\<lambda> \\<sigma> . let a = resolve_address \\<alpha> \\<sigma> Mem;\n                   op1 = \\<langle>31,0\\<rangle>read_mem64 \\<alpha> \\<sigma> 32 Mem;\n\n                   op2 = \\<langle>31,0\\<rangle>regs \\<sigma> r32_2 :: 32 word\n               in\n       \\<sigma>\\<lparr>mem := write_blocks [a \\<rhd> rev (\\<lbrace>3,0\\<rbrace> (op1 XOR op2))] (mem \\<sigma>),\n               flags := (flags \\<sigma>)\n        (flag_zf := (op1 XOR op2) = (0 :: 32 word),\n         flag_cf := False,\n         flag_of := False,\n         flag_sf := (sint (op1 XOR op2) < 0),\n         flag_pf := parity(op1 XOR op2))  \n\\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n    apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')+\n    apply (intro state_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:simp_rules take_bits_bitXOR2 resolve_address_after_update_flag)\n      done\n    apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:simp_rules take_bits_XOR_eq_zero_32word)\n      done\n    subgoal for \\<sigma>\n      apply (auto simp add:simp_rules parity_ucast)\n      done\n    subgoal for \\<sigma>\n      using word_msb_sint[where ?w=\"\\<langle>31,0\\<rangle>read_mem64 \\<alpha> \\<sigma> 32 Mem XOR \\<langle>31,0\\<rangle>regs \\<sigma> r32_2\"]\n      by (auto simp add:msb_nth fst_bool_to_bv_XOR_def bitXOR_nth test_bit_of_take_bits)\n      done\nqed\n\n\n(*---------------------------------------------------proofs on or ---------------------------------------*)\n\n\nlemma test_bit_of_extended_word_64[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"(\\<langle>63,0\\<rangle>a :: 1000 word) !! 63 = a !! 63\"\n  using test_bit_of_take_bits[of 63 63 0 \"\\<langle>63,0\\<rangle>a::1000 word\",where  ?'a=64]\n  by auto\n\n\n\n(* Proofs on or  *)\n\n\nlemma extended_AND_iff_orig_AND[get_semantics_rewriting]:\n  fixes a b :: \"64 word\"\n  shows \"(\\<langle>63,0\\<rangle>a = (0::1000 word) \\<and> \\<langle>63,0\\<rangle>b = (0::1000 word)) \\<longleftrightarrow>  (a = (0::64 word) \\<and> b = (0::64 word))\"\nproof-\n  {\n    assume 1: \"(\\<langle>63,0\\<rangle>a = (0::1000 word) \\<and> \\<langle>63,0\\<rangle>b = (0::1000 word))\"\n    hence 2: \"\\<forall> i<1000. ((\\<langle>63,0\\<rangle>a :: 1000 word) !! i = False) \\<and> ((\\<langle>63,0\\<rangle>b :: 1000 word) !! i = False)\"\n      apply (subst 1)+\n      by auto\n    have \"(a = (0::64 word) \\<and> b = (0::64 word))\"\n    proof-\n      {\n        fix i :: nat\n        assume \"i < 64\"\n        hence \"((a !! i = (0 :: 64 word) !! i) \\<and> (b !! i = (0 :: 64 word) !! i))\"\n          using 2[THEN spec, of i]\n          by (auto simp add: word_ao_nth test_bit_of_take_bits)\n      }\n      thus ?thesis\n        by (auto simp add: word_size word_eqI)\n    qed\n  }\n moreover\n  {\n    assume 1: \"(a = (0::64 word) \\<and> b = (0::64 word))\"\n    hence 2: \"\\<forall> i < 64 . ((a !! i = False) \\<and> (b !! i = False))\"\n      apply (subst 1)\n      by auto\n    have \"(\\<langle>63,0\\<rangle>a = (0::1000 word) \\<and> \\<langle>63,0\\<rangle>b = (0::1000 word))\"\n    proof-\n      {\n        fix i :: nat\n        assume \"i < 1000\"\n        hence \"( ((\\<langle>63,0\\<rangle>a :: 1000 word) !! i = (0 :: 1000 word) !! i) \\<and> ((\\<langle>63,0\\<rangle>b :: 1000 word) !! i = (0 :: 1000 word) !! i))\"\n          using 2[THEN spec, of i]\n          by (auto simp add: word_ao_nth test_bit_of_take_bits)\n      }\n      thus ?thesis\n        by (auto simp add: word_size word_eqI)\n    qed\n  }\n  ultimately\n  show ?thesis\n    by auto\nqed\n\nlemma extended_AND_iff_orig_AND_32[get_semantics_rewriting]:\n  fixes a b :: \"64 word\"\n  shows \"(\\<langle>31,0\\<rangle>a = (0::1000 word) \\<and> \\<langle>31,0\\<rangle>b = (0::1000 word)) \\<longleftrightarrow>  (\\<langle>31,0\\<rangle>a = (0::32 word) \\<and> \\<langle>31,0\\<rangle>b = (0::32 word))\"\nproof-\n  {\n    assume 1: \"(\\<langle>31,0\\<rangle>a = (0::1000 word) \\<and> \\<langle>31,0\\<rangle>b = (0::1000 word))\"\n    hence 2: \"\\<forall> i<1000. ((\\<langle>31,0\\<rangle>a :: 1000 word) !! i = False) \\<and> ((\\<langle>31,0\\<rangle>b :: 1000 word) !! i = False)\"\n      apply (subst 1)+\n      by auto\n    have \"(\\<langle>31,0\\<rangle>a = (0::32 word) \\<and> \\<langle>31,0\\<rangle>b = (0::32 word))\"\n    proof-\n      {\n        fix i :: nat\n        assume \"i < 32\"\n        hence \"(((\\<langle>31,0\\<rangle>a::32 word) !! i = (0 :: 32 word) !! i) \\<and> ((\\<langle>31,0\\<rangle>b::32 word) !! i = (0 :: 32 word) !! i))\"\n          using 2[THEN spec, of i]\n          by (auto simp add: word_ao_nth test_bit_of_take_bits)\n      }\n      thus ?thesis\n        by (auto simp add: word_size word_eqI)\n    qed\n  }\n moreover\n  {\n    assume 1: \"((\\<langle>31,0\\<rangle>a :: 32 word) = (0::32 word) \\<and> (\\<langle>31,0\\<rangle>b :: 32 word) = (0::32 word))\"\n    hence 2: \"\\<forall> i < 32 . (((\\<langle>31,0\\<rangle>a ::32 word) !! i = False) \\<and> ((\\<langle>31,0\\<rangle>b :: 32 word) !! i = False))\"\n      apply (subst 1)\n      by auto\n    have \"((\\<langle>31,0\\<rangle>a :: 1000 word) = (0::1000 word) \\<and> (\\<langle>31,0\\<rangle>b :: 1000 word) = (0::1000 word))\"\n    proof-\n      {\n        fix i :: nat\n        assume \"i < 1000\"\n        hence \"( ((\\<langle>31,0\\<rangle>a :: 1000 word) !! i = (0 :: 1000 word) !! i) \\<and> ((\\<langle>31,0\\<rangle>b :: 1000 word) !! i = (0 :: 1000 word) !! i))\"\n          using 2[THEN spec, of i]\n          by (auto simp add: word_ao_nth test_bit_of_take_bits)\n      }\n      thus ?thesis\n        by (auto simp add: word_size word_eqI)\n    qed\n  }\n  ultimately\n  show ?thesis\n    by blast\nqed\n\nlemma take_bits_bitOR_64[get_semantics_rewriting]:\n  fixes a b::\"64 word\"\n  shows \"((\\<langle>63,0\\<rangle>a OR \\<langle>63,0\\<rangle>b) :: 1000 word) = (\\<langle>63,0\\<rangle>(a OR b) :: 1000 word) \"\n  apply (subst take_bits_bitOR[symmetric, where ?h=63 and ?l=0 and ?a=a and ?b=b])\n  apply simp\n  by simp\n\n\nlemma fst_bool_to_bv_OR_def[get_semantics_rewriting]:\n shows \"(fst (bool_to_bv a) OR fst (bool_to_bv b)) = (if a then 1 else if b then 1 else 0)\"\n  by (auto simp add:bool_to_bv_eq_fst )\n\nlemma is_manual_or_r64_r64[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Or) (Reg (General SixtyFour r64_1)) (Storage (Reg (General SixtyFour r64_2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_or_r64_r64[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Or) (Reg (General SixtyFour r64_1)) (Storage (Reg (General SixtyFour r64_2)))) si =\n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r64_1 :: 64 word;\n                   op2 = regs \\<sigma> r64_2 :: 64 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r64_1 := op1 OR op2),\n               flags := (flags \\<sigma>)\n        (flag_zf := (op1 OR op2) = (0 :: 64 word),\n         flag_cf := False,\n         flag_of := False,\n\n         flag_sf := ((sint(op1)<0) \\<or> (sint(op2)<0)),\n         flag_pf := parity(op1 OR op2))  \n\\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')+\n    apply (intro state_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add: simp_rules take_bits_bitOR)\n      done\n    apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:extended_AND_iff_orig_AND)\n      done\n    subgoal for \\<sigma>\n      apply (auto simp add:take_bits_bitOR_64)\n      done\n    subgoal for \\<sigma>\n      using fst_bool_to_bv_OR_def\n      using word_msb_sint[where ?w=\"regs \\<sigma> r64_1\"]\n      using word_msb_sint[where ?w=\"regs \\<sigma> r64_2\"]\n      by (auto simp add: msb_nth test_bit_of_take_bits simp_rules)\n      done\n  qed\n\n\nlemma is_manual_or_r32_r32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Or) (Reg (General ThirtyTwo r64_1)) (Storage (Reg (General ThirtyTwo r64_2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_or_r32_r32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Or) (Reg (General ThirtyTwo r64_1)) (Storage (Reg (General ThirtyTwo r64_2)))) si =\n        (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r64_1 :: 32 word;\n                   op2 = \\<langle>31,0\\<rangle> regs \\<sigma> r64_2 :: 32 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r64_1 :=  \\<langle>31,0\\<rangle>(op1 OR op2)),\n               flags := (flags \\<sigma>)\n        (flag_zf := (op1 OR op2) = (0 :: 32 word),\n         flag_cf := False,\n         flag_of := False,\n\n         flag_sf := (((op1 !! 31) \\<or> (op2 !! 31)) = True),\n         flag_pf := parity(op1 OR op2))  \n\\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')+\n    apply (intro state_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add: simp_rules take_bits_bitOR)\n      done\n    apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:extended_AND_iff_orig_AND_32)\n      done\n    subgoal for \\<sigma>\n      apply (simp add: simp_rules parity_ucast take_bits_bitOR)\n      done\n    subgoal for \\<sigma>\n      using fst_bool_to_bv_OR_def\n      by (auto simp add:test_bit_of_take_bits simp_rules)\n      done\n  qed\n\n\nlemma is_manual_or_r32_m32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Or) (Reg (General ThirtyTwo r64_1)) (Storage (Memory 32 Mem))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_or_r32_m32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Or) (Reg (General ThirtyTwo r64_1)) (Storage (Memory 32 Mem))) si =\n        (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r64_1 :: 32 word;\n                   op2 = \\<langle>31,0\\<rangle>(read_mem64 \\<alpha> \\<sigma> 32 Mem) :: 32 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r64_1 :=  ucast(op1 OR op2)),\n               flags := (flags \\<sigma>)\n        (flag_zf := (op1 OR op2) = (0 :: 32 word),\n         flag_cf := False,\n         flag_of := False,\n\n         flag_sf := (((op1 !! 31) \\<or> (op2 !! 31)) = True),\n         flag_pf := parity(op1 OR op2))  \n\\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')+\n    apply (intro state_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (simp add: simp_rules)\n      done\n    apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:extended_AND_iff_orig_AND_32)\n      done\n    subgoal for \\<sigma>\n      apply (simp add: simp_rules parity_ucast take_bits_bitOR)\n      done\n    subgoal for \\<sigma>\n      using fst_bool_to_bv_OR_def\n      by (auto simp add:test_bit_of_take_bits simp_rules)\n      done\n  qed\n\n\nlemma useless_take_bits_ucast[get_semantics_rewriting]:\n  shows \"(\\<langle>31,0\\<rangle>(a :: 1000 word) :: 1000 word) = ucast (\\<langle>31,0\\<rangle>a :: 32 word) \"\n  by auto\n\n\nlemma useless_and_generic[get_semantics_rewriting]:\n  fixes a::\"'a::len word\"\n  assumes \"LENGTH('b :: len) < LENGTH('a)\" \n    and   \"h = LENGTH('b) - 1\"\n  shows \"\\<langle>h,0\\<rangle>a AND ((2^LENGTH('b) - 1) :: 'b:: len word) = (\\<langle>h,0\\<rangle>a  :: 'b:: len word)\"\nproof-\n  show ?thesis\n    using max_word_eq\n    apply (subst max_word_eq[symmetric])\n    by auto\nqed\n\nlemma useless_sextend_hardocded_32_word[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"\\<langle>31,0\\<rangle>((sextend (\\<langle>63,0\\<rangle>a :: 1000 word) 64 32) :: 1000 word) = (\\<langle>31,0\\<rangle>a ::32 word)\"\nproof-\n  show ?thesis\n      unfolding sextend.simps\n      apply (auto simp add: simp_rules mask_def)\n      apply (subst Word.word_bool_alg.conj_disj_distrib2)\n       apply (auto)\n       apply (subst take_bits_remove[where ?w=\"a\" and ?h=\"63\", simplified])\n       apply (subst take_bits_bitAND)\n       apply auto\n      apply (subst useless_and_generic[where ?a=a and ?h=31 and ?'b=32, simplified])\n      by auto\n  qed\n\nlemma is_manual_or_r32_Imm32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Or) (Reg (General ThirtyTwo r32_1)) (Immediate (ImmSixtyFour Imm32))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_or_r32_Imm32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Or) (Reg (General ThirtyTwo r32_1)) (Immediate (ImmSixtyFour Imm32))) si =\n        (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r32_1 :: 32 word;\n                    op2 = (word_of_int Imm32) :: 64 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r32_1 :=  ucast(op1 OR \\<langle>31,0\\<rangle>op2)),\n               flags := (flags \\<sigma>)\n        (flag_zf := (op1 OR \\<langle>31,0\\<rangle>op2) = (0 :: 32 word),\n         flag_cf := False,\n         flag_of := False,\n\n       flag_sf := sint(op1 OR \\<langle>31,0\\<rangle>op2) < 0,\n         flag_pf := parity(op1 OR \\<langle>31,0\\<rangle>op2))  \n\\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')+\n    apply (intro state_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (simp add: simp_rules useless_sextend_hardocded_32_word)\n      done\n    apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:useless_sextend_hardocded_32_word extended_AND_iff_orig_AND_32)\n      done\n    subgoal for \\<sigma>\n      apply (simp add: simp_rules parity_ucast take_bits_bitOR)\n      done\n    subgoal for \\<sigma>\n      apply (subst word_msb_sint[where ?w=\"(\\<langle>31,0\\<rangle>regs \\<sigma> r32_1 OR \\<langle>31,0\\<rangle>word_of_int Imm32) :: 32 word\", unfolded msb_nth, symmetric])\n      apply (subst word_ao_nth[where ?x=\"(\\<langle>31,0\\<rangle>regs \\<sigma> r32_1) :: 32 word\" and ?y=\"(\\<langle>31,0\\<rangle>word_of_int Imm32) :: 32 word\" and ?n=\"(LENGTH(32) - 1)\"])\n      using fst_bool_to_bv_OR_def\n      by (auto simp add:test_bit_of_take_bits simp_rules)\n      done\n  qed\n\n\nlemma is_manual_or_r64_m64[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Or) (Reg (General SixtyFour r64_1)) (Storage (Memory 64 Mem))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_or_r64_m64[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Or) (Reg (General SixtyFour r64_1)) (Storage (Memory 64 Mem))) si =\n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r64_1 :: 64 word;\n                   op2 = read_mem64 \\<alpha> \\<sigma> 64 Mem :: 64 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r64_1 := op1 OR op2),\n               flags := (flags \\<sigma>)\n        (flag_zf := (op1 OR op2) = (0 :: 64 word),\n         flag_cf := False,\n         flag_of := False,\n\n         flag_sf := ((sint(op1)<0) \\<or> (sint(op2)<0)),\n         flag_pf := parity(op1 OR op2))  \n\\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')+\n    apply (intro state_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add: simp_rules take_bits_bitOR)\n      done\n    apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:extended_AND_iff_orig_AND)\n      done\n    subgoal for \\<sigma>\n      apply (auto simp add:take_bits_bitOR_64)\n      done\n    subgoal for \\<sigma>\n      apply (subst  test_bit_of_extended_word_64[where ?a=\"regs \\<sigma> r64_1\"])\n      apply (subst  test_bit_of_extended_word_64[where ?a=\"read_mem64 \\<alpha> \\<sigma> 64 Mem\"])\n      apply (subst word_msb_sint[where ?w=\"regs \\<sigma> r64_1\", symmetric, unfolded msb_nth, simplified])\n      apply (subst word_msb_sint[where ?w=\"read_mem64 \\<alpha> \\<sigma> 64 Mem\", symmetric, unfolded msb_nth, simplified])\n      using fst_bool_to_bv_OR_def\n      by (auto simp add: msb_nth test_bit_of_take_bits simp_rules)\n      done\n  qed\n\n\n(*---------------------------------------------------proofs on and ---------------------------------------*)\nlemma is_manual_and_r64_r64[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 And) (Reg (General SixtyFour r64_1)) (Storage (Reg (General SixtyFour r64_2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_and_r64_r64[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 And) (Reg (General SixtyFour r64_1)) (Storage (Reg (General SixtyFour r64_2)))) si =\n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r64_1 :: 64 word;\n                   op2 = regs \\<sigma> r64_2 :: 64 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r64_1 := op1 AND op2),\n               flags := (flags \\<sigma>)\n        (flag_zf := (op1 AND op2) = (0 :: 64 word),\n         flag_cf := False,\n         flag_of := False,\n\n         flag_sf := (((op1 !! 63) \\<and> (op2 !! 63)) = True),\n         flag_pf := parity(op1 AND op2))  \n\\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')+\n    apply (intro state_eqI,simp_all)\n     apply (simp add:simp_rules take_bits_bitAND)\n    apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n      using take_bits_bitAND[where ?h=63 and ?l=0 and ?a=\"regs \\<sigma> r64_1\" and ?b=\"regs \\<sigma> r64_2\"  ]\n      apply auto\n      done\n    subgoal for \\<sigma>\n      apply (subst take_bits_bitAND[symmetric, where ?h=63 and ?l=0 and ?a=\"regs \\<sigma> r64_1\" and ?b=\"regs \\<sigma> r64_2\", simplified])\n      apply (simp add:parity_ucast)\n      done\n    subgoal for \\<sigma>\n      by (auto simp add:test_bit_of_take_bits fst_bool_to_bv_AND_def)\n    done\nqed\n\nlemma is_manual_and_r32_r32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 And) (Reg (General ThirtyTwo r32_1)) (Storage (Reg (General ThirtyTwo r32_2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_and_r32_r32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 And) (Reg (General ThirtyTwo r32_1)) (Storage (Reg (General ThirtyTwo r32_2)))) si =\n        (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r32_1 :: 32 word;\n                   op2 = \\<langle>31,0\\<rangle>regs \\<sigma> r32_2 :: 32 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r32_1 := ucast(op1 AND op2)),\n               flags := (flags \\<sigma>)\n        (flag_zf := (op1 AND op2) = (0 :: 32 word),\n         flag_cf := False,\n         flag_of := False,\n         flag_sf := (sint op1 < 0) \\<and> (sint op2 < 0),\n         flag_pf := parity(op1 AND op2))  \n\\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')+\n    apply (intro state_eqI,simp_all)\n      apply (simp add:simp_rules take_bits_bitAND)\n    apply (intro flags_eqI,simp_all)\n      apply (simp add:take_bits_AND_zero_32_word)\n     apply (simp add: parity_ucast)\n    apply (auto simp add: fst_bool_to_bv_AND_def test_bit_of_take_bits)\n    subgoal for \\<sigma>\n      using word_msb_sint[where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32_1\"]\n      apply (auto)\n      done\n    subgoal for \\<sigma>\n      using word_msb_sint[where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32_2\"]\n      apply (auto)\n      done\n    subgoal for \\<sigma>\n      using word_msb_sint[where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32_1\"]\n      apply (auto)\n      done\n    subgoal for \\<sigma>\n      using word_msb_sint[where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32_2\"]\n      by (auto)\n      done\n  qed\n\nlemma and_2p_minus_1_32_extended[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"\\<langle>63,0\\<rangle>a AND (2^(LENGTH(32)) - 1 :: 1000 word) = (\\<langle>31,0\\<rangle>a :: 1000 word)\"\nproof-\n  {\n    fix n :: nat\n    assume 1:\"n < 1000\"\n    have a: \"(2^(LENGTH(32)) - 1 :: 1000 word) = ucast (2^(LENGTH(32)) - 1 :: 32 word)\"\n      apply (subst max_word_eq[symmetric])\n      by (auto simp add:simp_rules max_word_eq)\n    have b: \"(mask 32 :: 1000 word) = ucast (mask 32 :: 32 word)\"\n      by simp\n    have c: \" (mask 32 :: 32 word) = (2^(LENGTH(32)) - 1 :: 32 word)\"\n      apply (subst max_word_eq[symmetric])\n      by (simp add: max_word_def)\n    have d: \"ucast (2^(LENGTH(32)) - 1 :: 32 word) = (mask 32 :: 1000 word)\"\n      apply (subst c[symmetric])\n      apply (subst b[symmetric])\n      by simp\n    have e :\"(mask 32 :: 1000 word) !! n = (n < 32)\"\n      apply (subst b)\n      apply (subst c)\n      apply(subst max_word_eq[symmetric])\n      by (auto simp add:simp_rules)\n    hence \"(\\<langle>63,0\\<rangle>a AND (2^(LENGTH(32)) - 1 :: 1000 word)) !! n = (\\<langle>31,0\\<rangle>a :: 1000 word) !! n\"\n      using 1\n      apply (subst a)\n      apply (subst d)\n      by (auto simp add: mask_def word_ao_nth test_bit_of_take_bits e)\n  }\n  thus ?thesis\n    apply (intro word_eqI)\n    by (auto simp add: word_size)\nqed\n\nlemma test_nth_32_bit[get_semantics_rewriting]:\n  fixes a:: \"64 word\"\n  assumes \"i<32\"\n  shows \"(\\<langle>63,0\\<rangle>a :: 1000 word) !! i = (\\<langle>31,0\\<rangle>a :: 32 word) !! i\"\nproof-\n  show ?thesis\n    using assms\n    by(auto simp add:simp_rules test_bit_of_take_bits)\nqed\n\nlemma test_bit_msb_sextend[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"(sextend (\\<langle>63,0\\<rangle>a :: 1000 word) 64 32 :: 1000 word) !! 31 = (\\<langle>31,0\\<rangle>sextend (\\<langle>63,0\\<rangle>a :: 1000 word) 64 32 :: 32 word) !! 31\"\nproof-\n  show ?thesis\n    by (auto simp add:test_bit_of_take_bits)\nqed\n\nlemma is_manual_and_m32_Imm32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 And) (Memory 32 Mem) (Immediate (ImmSixtyFour Imm32))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_and_m32_Imm32[presimplify]:\n shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 And) (Memory 32 Mem) (Immediate (ImmSixtyFour Imm32))) si =\n         (\\<lambda> \\<sigma> . let a = resolve_address \\<alpha> \\<sigma> Mem;\n                    op1 = read_mem64 \\<alpha> \\<sigma> 32 Mem;\n                    op2 = (word_of_int Imm32) :: 64 word in\n      \\<sigma>\\<lparr>mem := write_blocks [a \\<rhd> rev (\\<lbrace>3,0\\<rbrace> (\\<langle>31,0\\<rangle>(op1 AND op2) :: 32 word))] (mem \\<sigma>),\n      flags := (flags \\<sigma>)\n      (flag_zf :=  (\\<langle>31,0\\<rangle>(op1 AND op2)) = (0 :: 32 word),\n       flag_cf := False,\n       flag_of := False,\n       flag_sf := sint((\\<langle>31,0\\<rangle>op1 :: 32 word) AND (\\<langle>31,0\\<rangle>op2)) < 0,\n       flag_pf := parity(\\<langle>31,0\\<rangle>(op1 AND op2) :: 32 word))  \\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')+\n  apply (intro state_eqI,simp_all)\n  subgoal for \\<sigma>\n    apply (auto simp add:resolve_address_after_update_flag useless_sextend_hardocded_32_word)\n    apply (subst take_bits_bitAND[symmetric, where ?h=31 and ?l=0 and ?a=\"fst (read_memory \\<alpha> \\<sigma> 32 Mem)\" and ?b=\"word_of_int Imm32\"])\n    apply auto\n    done\n  apply (intro flags_eqI,simp_all)\n  subgoal for \\<sigma>\n    apply (auto simp add:take_bits_remove take_bits_bitAND take_bits_AND_zero_32_word)\n    done\n  subgoal for \\<sigma>\n    apply (auto simp add: parity_ucast take_bits_bitAND)\n    done\n  subgoal for \\<sigma>\n    apply (subst word_msb_sint[where ?w=\"(\\<langle>31,0\\<rangle>read_mem64 \\<alpha> \\<sigma> 32 Mem AND \\<langle>31,0\\<rangle>word_of_int Imm32) :: 32 word\", unfolded msb_nth, symmetric])\n    apply (subst word_ao_nth[where ?x=\"(\\<langle>31,0\\<rangle>read_mem64 \\<alpha> \\<sigma> 32 Mem) :: 32 word\" and ?y=\"(\\<langle>31,0\\<rangle>word_of_int Imm32) :: 32 word\" and ?n=\"(LENGTH(32) - 1)\"])\n    apply (subst test_nth_32_bit[where ?a=\"read_mem64 \\<alpha> \\<sigma> 32 Mem\" and i=31])\n    by (auto simp add:simp_rules  test_bit_of_take_bits fst_bool_to_bv_AND_def)\n  done\nqed\n\nlemma is_manual_and_r32_Imm32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 And) (Reg (General ThirtyTwo r32_1)) (Immediate (ImmSixtyFour Imm32))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_and_r32_Imm32[presimplify]:\n shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 And) (Reg (General ThirtyTwo r32_1)) (Immediate (ImmSixtyFour Imm32))) si =\n         (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r32_1 :: 32 word;\n                    op2 = (word_of_int Imm32) :: 64 word\n                 in\n       \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r32_1 := (ucast(op1 AND \\<langle>31,0\\<rangle>op2) :: 64 word)),\n      flags := (flags \\<sigma>)\n      (flag_zf :=  ((op1 AND \\<langle>31,0\\<rangle>op2)) = (0 :: 32 word),\n       flag_cf := False,\n       flag_of := False,\n       flag_sf := sint(op1 AND (\\<langle>31,0\\<rangle>op2)) < 0,\n       flag_pf := parity(op1 AND \\<langle>31,0\\<rangle>op2))  \\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')+\n  apply (intro state_eqI,simp_all)\n  subgoal for \\<sigma>\n    apply (auto simp add: simp_rules)\n    done\n  apply (intro flags_eqI,simp_all)\n  subgoal for \\<sigma>\n    apply (auto simp add:take_bits_remove take_bits_bitAND take_bits_AND_zero_32_word)\n    done\n  subgoal for \\<sigma>\n    apply (auto simp add: parity_ucast take_bits_bitAND)\n    done\n  subgoal for \\<sigma>\n    apply (subst word_msb_sint[where ?w=\"(\\<langle>31,0\\<rangle>regs \\<sigma> r32_1 AND \\<langle>31,0\\<rangle>word_of_int Imm32) :: 32 word\", unfolded msb_nth, symmetric])\n    apply (subst word_ao_nth[where ?x=\"(\\<langle>31,0\\<rangle>regs \\<sigma> r32_1) :: 32 word\" and ?y=\"(\\<langle>31,0\\<rangle>word_of_int Imm32) :: 32 word\" and ?n=\"(LENGTH(32) - 1)\"])\n    by (auto simp add:simp_rules  test_bit_of_take_bits fst_bool_to_bv_AND_def)\n  done\nqed\n\n(*---------------------------------------------------proofs on not ---------------------------------------*)\nlemma is_manual_not_r64_r64[is_manual]:\n  shows \"is_manual assembly semantics (Unary (IS_8088 Not) (Storage (Reg (General SixtyFour r64_2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_not_r64_r64[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Unary (IS_8088 Not) (Storage (Reg (General SixtyFour r64_2)))) si =\n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r64_2 :: 64 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r64_2 := NOT op1)\\<rparr>)\"\nproof -\n show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')+\n     by (simp add:simp_rules)\n qed\n\nlemma is_manual_not_r32[is_manual]:\n  shows \"is_manual assembly semantics (Unary (IS_8088 Not) (Storage (Reg (General ThirtyTwo r32)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_not_r32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Unary (IS_8088 Not) (Storage (Reg (General ThirtyTwo r32)))) si =\n        (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r32 :: 32 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r32 := \\<langle>31,0\\<rangle>(NOT op1))\\<rparr>)\"\nproof -\n show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')+\n   by (simp add:simp_rules)\n qed\n\n\n(*---------------------------------------------------proofs on neg ---------------------------------------*)\n\nlemma zero_le_2p[get_semantics_rewriting]:\n  assumes \"n < LENGTH('a)\"\n  shows \"(0::'a::len word) < 2 ^ n\"\n  using assms\nproof (induct n)\n  case 0\n  thus ?case\n    by auto\nnext\n  case (Suc n)\n  thus ?case\n    using shiftl_1[symmetric,of \"n+1\",where 'a='a]\n    using is_zero_shiftl[of \"1::'a word\" \"n+1\"]\n    apply (auto simp del: shiftl_1)\n    by fastforce\nqed\n\n\nlemma take_bits_neg[get_semantics_rewriting]:\n  fixes w :: \"1000 word\"\n  shows \"\\<langle>63,0\\<rangle> (- w) = (ucast (NOT w) + 1 :: 64 word)\"\n  apply (subst twos_complement)\n  apply (subst word_succ_p1)\n  apply (subst take_bits_plus[of 63 \"NOT w\" 1])\n  apply simp\n  apply simp\n  apply simp\n  apply (intro word_eqI)\n  by (auto simp add: word_size nth_ucast word_ao_nth bitNOT_nth test_bit_of_take_bits)\n\nlemma take_bits_drop_minus_64bit[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"\\<langle>63,0\\<rangle> (- (\\<langle>63,0\\<rangle>a :: 1000 word)) = -a\"\n  using take_bits_minus_64bit(1)[where ?'a=1000,of 0 \"\\<langle>63,0\\<rangle>a\"]\n  by auto\n\nlemma test_bit_of_take_bits_extended_64_neg_word[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"(- (\\<langle>63,0\\<rangle>a :: 1000 word)) !! 63 = (-a) !! 63\"\n  using take_bits_drop_minus_64bit[of a]\n  using test_bit_of_take_bits[of 63 63 0 \"- (\\<langle>63,0\\<rangle>a::1000 word)\",where  ?'a=64]\n  by auto\n\nlemma test_bit_of_take_bits_extended_64_word[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"((\\<langle>63,0\\<rangle>a :: 1000 word)) !! 63 = (a) !! 63\"\n  using take_bits_drop_minus_64bit[of a]\n  using test_bit_of_take_bits[of 63 63 0 \"(\\<langle>63,0\\<rangle>a::1000 word)\",where  ?'a=64]\n  by auto\n\n\nlemma diff_len_word_eq_0_64[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"((\\<langle>63,0\\<rangle>a :: 1000 word) = 0) = (a = 0)\"\nproof-\n  {\n    assume 1: \"\\<langle>63,0\\<rangle>a = (0::1000 word)\"\n    hence 2: \"\\<forall> i<1000. (\\<langle>63,0\\<rangle>a :: 1000 word) !! i = False\"\n      apply (subst 1)+\n      by auto\n    have \"(a = (0::64 word))\"\n    proof-\n      {\n        fix i :: nat\n        assume \"i < 64\"\n        hence \"a !! i = (0 :: 64 word) !! i\"\n          using 2[THEN spec, of i]\n          by (auto simp add: word_ao_nth test_bit_of_take_bits bitXOR_nth)\n      }\n      thus ?thesis\n        by (auto simp add: word_size word_eqI )\n    qed\n  }\n moreover\n  {\n    assume 1: \"a = (0::64 word)\"\n    hence 2: \"\\<forall> i < 64 . a !! i = False\"\n      apply (subst 1)\n      by auto\n    have \"\\<langle>63,0\\<rangle>a = (0::1000 word)\"\n    proof-\n      {\n        fix i :: nat\n        assume \"i < 1000\"\n        hence \" (\\<langle>63,0\\<rangle>a:: 1000 word) !! i = (0 :: 1000 word) !! i\"\n          using 2[THEN spec, of i]\n          by (auto simp add: word_ao_nth test_bit_of_take_bits bitXOR_nth)\n      }\n      thus ?thesis\n        by (auto simp add: word_size word_eqI)\n    qed\n  }\n  ultimately\n  show ?thesis\n    by auto\nqed\n\n\nlemma parity_equality[get_semantics_rewriting]:\n  fixes a :: \"1000 word\"\n    and b :: \"64 word\"\n  assumes \"\\<langle>63,0\\<rangle>a = b\"\n  shows \"parity a = parity b\"\nproof-\n  have a:\"parity(a) = parity(\\<langle>63,0\\<rangle>a :: 64 word)\"\n    unfolding parity_def\n    unfolding take_bits_def\n    by (auto simp add:simp_rules word_rep_drop)\n  thus ?thesis\n    apply (subst assms(1)[symmetric]) \n    by (auto simp add:simp_rules)\nqed\n\n\nlemma is_manual_neg_r64_r64[is_manual]:\n  shows \"is_manual assembly semantics (Unary (IS_8088 Neg) (Storage (Reg (General SixtyFour r64_2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_neg_r64_r64[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Unary (IS_8088 Neg) (Storage (Reg (General SixtyFour r64_2)))) si =\n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r64_2 :: 64 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r64_2 := (0:: 64 word) - op1),\n        flags := (flags \\<sigma>)\n        (flag_zf := op1 = (0 :: 64 word),\n         flag_cf := op1 \\<noteq> (0 :: 64 word),\n         flag_sf := (2^63 \\<le> - op1),\n         flag_of := (op1 \\<ge> 2^63 \\<and> 2^63 \\<le> - op1),\n         flag_pf := parity((0:: 64 word) - op1)  )\n                \n  \\<rparr>)\"\nproof-\n\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')\n  apply rewrite_one_let'\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')+\n  apply (intro state_eqI,simp_all)\n    subgoal for \\<sigma>\n     apply (auto simp add: simp_rules take_bits_drop_minus_64bit)\n      done\n  apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:diff_len_word_eq_0_64)\n      done\n    subgoal for \\<sigma>\n      apply (auto simp add:diff_len_word_eq_0_64)\n      done\n    subgoal for \\<sigma>\n      using parity_equality[where ?a=\"- (\\<langle>63,0\\<rangle>regs \\<sigma> r64_2)\" and ?b=\"- regs \\<sigma> r64_2\"]\n      apply (auto simp add:take_bits_drop_minus_64bit)\n      done\n    subgoal for \\<sigma>\n      using msb_is_gt_2p[of \"- regs \\<sigma> r64_2\", unfolded msb_nth]\n      using msb_is_gt_2p[of \"regs \\<sigma> r64_2\", unfolded msb_nth]\n      apply (simp add: test_bit_of_take_bits_extended_64_neg_word test_bit_of_take_bits)\n    done\n  subgoal for \\<sigma>\n    apply (subst test_bit_of_take_bits_extended_64_neg_word[where ?a=\"regs \\<sigma> r64_2\"])\n    apply (subst test_bit_of_take_bits_extended_64_word[where ?a=\"regs \\<sigma> r64_2\"])\n    apply( subst msb_is_gt_2p[of \"- regs \\<sigma> r64_2\", unfolded msb_nth, simplified])\n    apply( subst msb_is_gt_2p[of \"regs \\<sigma> r64_2\", unfolded msb_nth, simplified])\n    by simp\n  done\nqed\n\nlemma diff_len_word_eq_0_32[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"((\\<langle>31,0\\<rangle>a :: 1000 word) = 0) \\<longleftrightarrow> ((\\<langle>31,0\\<rangle>a :: 32 word) = (0 :: 32 word))\"\nproof-\n  {\n    assume 1: \"\\<langle>31,0\\<rangle>a = (0::1000 word)\"\n    hence 2: \"\\<forall> i<1000. (\\<langle>31,0\\<rangle>a :: 1000 word) !! i = False\"\n      apply (subst 1)+\n      by auto\n    have \"((\\<langle>31,0\\<rangle>a :: 32 word) = (0::32 word))\"\n    proof-\n      {\n        fix i :: nat\n        assume \"i < 32\"\n        hence \"(\\<langle>31,0\\<rangle>a :: 32 word) !! i = (0 :: 32 word) !! i\"\n          using 2[THEN spec, of i]\n          by (auto simp add: word_ao_nth test_bit_of_take_bits)\n      }\n      thus ?thesis\n        by (auto simp add: word_size word_eqI )\n    qed\n  }\n moreover\n  {\n    assume 1: \"\\<langle>31,0\\<rangle>a = (0::32 word)\"\n    hence 2: \"\\<forall> i < 32 . (\\<langle>31,0\\<rangle>a :: 32 word) !! i = False\"\n      apply (subst 1)\n      by auto\n    have \"\\<langle>31,0\\<rangle>a = (0::1000 word)\"\n    proof-\n      {\n        fix i :: nat\n        assume \"i < 1000\"\n        hence \" (\\<langle>31,0\\<rangle>a:: 1000 word) !! i = (0 :: 1000 word) !! i\"\n          using 2[THEN spec, of i]\n          by (auto simp add: word_ao_nth test_bit_of_take_bits )\n      }\n      thus ?thesis\n        by (auto simp add: word_size word_eqI)\n    qed\n  }\n  ultimately\n  show ?thesis\n    by auto\nqed\n\n\nlemma take_bits_minus_extend_32_to_64bits[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"(\\<langle>31,0\\<rangle>(- (\\<langle>31,0\\<rangle>a :: 1000 word)) :: 64 word) = (ucast (-(\\<langle>31,0\\<rangle>a :: 32 word)) :: 64 word)\"\n  apply (subst take_bits_minus_bit32_generic[where ?a=\"0 :: 1000 word\" and ?b=\"(\\<langle>31,0\\<rangle>a :: 1000 word)\" and ?'b=64, simplified])\n  by (auto simp add:simp_rules)\n\nlemma take_bits_minus_extend_32_to_32bits[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"(\\<langle>31,0\\<rangle>(- (\\<langle>31,0\\<rangle>a :: 1000 word)) :: 32 word) = ((-(\\<langle>31,0\\<rangle>a :: 32 word)))\"\n  apply (subst take_bits_minus_bit32_generic[where ?a=\"0 :: 1000 word\" and ?b=\"(\\<langle>31,0\\<rangle>a :: 1000 word)\" and ?'b=32, simplified])\n  by (auto simp add:simp_rules)\n\nlemma parity_equality_32[get_semantics_rewriting]:\n  fixes a :: \"1000 word\"\n    and b :: \"32 word\"\n  assumes \"\\<langle>31,0\\<rangle>a = b\"\n  shows \"parity a = parity b\"\nproof-\n  have a:\"parity(a) = parity(\\<langle>31,0\\<rangle>a :: 32 word)\"\n    unfolding parity_def\n    unfolding take_bits_def\n    by (auto simp add:simp_rules word_rep_drop)\n  thus ?thesis\n    apply (subst assms(1)[symmetric]) \n    by (auto simp add:simp_rules)\nqed\n\nlemma test_32b_neg_wordextended[get_semantics_rewriting]:\n  fixes a :: \"64 word\"\n  shows \"(- (\\<langle>31,0\\<rangle>a :: 1000 word)) !! 31 = (-(\\<langle>31,0\\<rangle>a :: 32 word)) !! 31\"\n  using take_bits_minus_extend_32_to_32bits[of a]\n  using test_bit_of_take_bits[of 31 31 0 \"- (\\<langle>31,0\\<rangle>a::1000 word)\",where  ?'a=32]\n  by auto\n\nlemma is_manual_neg_r32[is_manual]:\n  shows \"is_manual assembly semantics (Unary (IS_8088 Neg) (Storage (Reg (General ThirtyTwo r32)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_neg_r32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Unary (IS_8088 Neg) (Storage (Reg (General ThirtyTwo r32)))) si =\n        (\\<lambda> \\<sigma> . let opx = \\<langle>31,0\\<rangle>regs \\<sigma> r32 :: 32 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r32 := ucast ((0:: 32 word) - opx) ),\n        flags := (flags \\<sigma>)\n        (flag_zf := opx = (0 :: 32 word),\n         flag_cf := opx \\<noteq> (0 :: 32 word),\n         flag_sf := sint(0 - opx) < 0,\n         flag_of := (opx \\<ge> 2^31 \\<and> 2^31 \\<le> - opx),\n         flag_pf := parity((0:: 32 word) - opx)  )\n                \n  \\<rparr>)\"\nproof-\n\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')\n  apply rewrite_one_let'\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')+\n  apply (intro state_eqI,simp_all)\n    subgoal for \\<sigma>\n     apply (auto simp add: simp_rules take_bits_minus_extend_32_to_64bits)\n      done\n  apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:diff_len_word_eq_0_32)\n      done\n    subgoal for \\<sigma>\n      apply (auto simp add:diff_len_word_eq_0_32)\n      done\n    subgoal for \\<sigma>\n      apply (subst stupid[where a=\"(\\<langle>31,0\\<rangle>- (\\<langle>31,0\\<rangle>regs \\<sigma> r32))\"])\n      using parity_equality_32[where ?a=\"- (\\<langle>31,0\\<rangle>regs \\<sigma> r32)\" and ?b=\"- (\\<langle>31,0\\<rangle>regs \\<sigma> r32)\"]\n      apply (auto simp add:take_bits_minus_extend_32_to_32bits parity_equality_32 ucast_id)\n      done\n    subgoal for \\<sigma>\n      apply (subst word_msb_sint[where ?w=\"(- (\\<langle>31,0\\<rangle>regs \\<sigma> r32)) :: 32 word\", symmetric, unfolded msb_nth, simplified])\n      apply (simp add: test_32b_neg_wordextended test_bit_of_take_bits)\n    done\n  subgoal for \\<sigma>\n    apply (subst test_32b_of_32AND64_word[where ?a=\"regs \\<sigma> r32\"])\n    apply (subst test_32b_neg_wordextended[where a=\"regs \\<sigma> r32\"]) \n    apply( subst msb_is_gt_2p[of \"(- (\\<langle>31,0\\<rangle>regs \\<sigma> r32)) :: 32 word\", unfolded msb_nth, simplified])\n    apply( subst msb_is_gt_2p[of \"\\<langle>31,0\\<rangle>regs \\<sigma> r32 :: 32 word\", unfolded msb_nth, simplified])\n    by simp\n  done\nqed\n\n\n(*---------------------------------------------------proofs on mov ---------------------------------------*)\nabbreviation \"write_mem16 \\<alpha>  \\<sigma> a (v::64 word) \\<equiv>\n                \\<sigma>\\<lparr>mem := write_block ((resolve_address \\<alpha> \\<sigma> a) \\<rhd> rev (\\<lbrace>1,0\\<rbrace> v)) (mem \\<sigma>)\\<rparr>\"\n\nabbreviation \"write_mem8 \\<alpha>  \\<sigma> a (v::64 word) \\<equiv>\n                \\<sigma>\\<lparr>mem := write_block ((resolve_address \\<alpha> \\<sigma> a) \\<rhd> rev (\\<lbrace>0,0\\<rbrace> v)) (mem \\<sigma>)\\<rparr>\"\n\n\nlemma is_manual_mov_r64_r64[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Mov) (Reg (General SixtyFour r64_1)) (Storage (Reg (General SixtyFour r64_2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mov_r64_r64[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Mov) (Reg (General SixtyFour r64_1)) (Storage (Reg (General SixtyFour r64_2)))) si =\n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r64_1 :: 64 word;\n                   op2 = regs \\<sigma> r64_2 :: 64 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r64_1 := op2)\\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  by (simp add: simp_rules)\nqed\n\nlemma is_manual_mov_m64_r64[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Mov) (Memory 64 Mem) (Storage (Reg (General SixtyFour r64)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mov_m64_r64[presimplify]:\n  shows  \"get_semantics \\<alpha> semantics (Binary (IS_8088 Mov) (Memory 64 Mem) (Storage (Reg (General SixtyFour r64)))) si =\n        (\\<lambda> \\<sigma>.  let op2 = regs \\<sigma> r64 :: 64 word\n          in \n          write_mem64 \\<alpha> \\<sigma> Mem op2)\"\n    apply (rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add: semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    by(rewrite_one_let')+\n\nlemma is_manual_mov_m32_r32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Mov) (Memory 32 Mem) (Storage (Reg (General ThirtyTwo r32)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mov_m32_r32[presimplify]:\n  shows  \"get_semantics \\<alpha> semantics (Binary (IS_8088 Mov) (Memory 32 Mem) (Storage (Reg (General ThirtyTwo r32))) ) si =\n        (\\<lambda> \\<sigma>.  let op2 = \\<langle>31,0\\<rangle>regs \\<sigma> r32 :: 32 word\n          in \n          write_mem32 \\<alpha> \\<sigma> Mem op2)\"\n    apply (rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add: semantics_def)\n    by(rewrite_one_let')+\n\n\n\nlemma is_manual_mov_m16_r16[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Mov) (Memory 16 Mem) (Storage (Reg (General Sixteen r16)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mov_m16_r16[presimplify]:\n  shows  \"get_semantics \\<alpha> semantics (Binary (IS_8088 Mov) (Memory 16 Mem) (Storage (Reg (General Sixteen r16))) ) si =\n        (\\<lambda> \\<sigma>.  let op2 = \\<langle>15,0\\<rangle>regs \\<sigma> r16 :: 64 word;\n                op1 = \\<langle>63,16\\<rangle>read_mem64 \\<alpha> \\<sigma> 16 Mem :: 64 word;\n                op3 = fst (bv_cat (op1, 48) (op2, 16)) :: 64 word\n\n          in \n          write_mem16 \\<alpha> \\<sigma> Mem op3)\"\n    apply (rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add: semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    unfolding bv_cat.simps\n    apply (auto simp add:simp_rules)\n    apply (subst take_bits_bitOR[where ?h=63 and ?l=0 and ?a=\"(\\<langle>63,16\\<rangle>fst (read_memory \\<alpha> \\<sigma> 16 Mem) << 16) :: 1000 word\" and ?b=\"\\<langle>15,0\\<rangle>regs \\<sigma> r16\"])\n    by (auto simp add:simp_rules take_bits_def word_rep_drop shiftl_of_bl)\n\nlemma is_manual_mov_m8_r8[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Mov) (Memory 8 Mem) (Storage (Reg (General EightLow r8_1)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mov_m8_r8[presimplify]:\n  shows  \"get_semantics \\<alpha> semantics (Binary (IS_8088 Mov) (Memory 8 Mem) (Storage (Reg (General EightLow r8_1))) ) si =\n        (\\<lambda> \\<sigma>.  let op2 = \\<langle>7,0\\<rangle>regs \\<sigma> r8_1 :: 64 word;\n                op1 = \\<langle>63,8\\<rangle>read_mem64 \\<alpha> \\<sigma> 8 Mem :: 64 word;\n                op3 = fst (bv_cat (op1, 56) (op2, 8)) :: 64 word\n\n          in \n          write_mem8 \\<alpha> \\<sigma> Mem op3)\"\n    apply (rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add: semantics_def)\n    apply(rewrite_one_let')+\n    unfolding bv_cat.simps\n    apply (auto simp add:simp_rules)\n    apply (subst take_bits_bitOR[where ?h=63 and ?l=0 and ?a=\"(\\<langle>63,8\\<rangle>fst (read_memory \\<alpha> \\<sigma> 8 Mem) << 8) :: 1000 word\" and ?b=\"\\<langle>7,0\\<rangle>regs \\<sigma> r8_1\"])\n    by (auto simp add:simp_rules take_bits_def word_rep_drop shiftl_of_bl)\n\nlemma is_manual_mov_m16_imm16[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Mov) (Memory 16 Mem) (Immediate (ImmSixtyFour imm))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mov_m16_imm16[presimplify]:\n  shows  \"get_semantics \\<alpha> semantics (Binary (IS_8088 Mov) (Memory 16 Mem) (Immediate (ImmSixtyFour imm)) ) si =\n        (\\<lambda> \\<sigma>.  let op2 = word_of_int imm :: 64 word;\n                op1 = \\<langle>63,16\\<rangle>read_mem64 \\<alpha> \\<sigma> 16 Mem :: 64 word;\n                op3 = fst (bv_cat (op1, 48) (op2, 16)) :: 64 word\n\n          in \n          write_mem16 \\<alpha> \\<sigma> Mem op3)\"\n    apply (rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add: semantics_def)\n    apply(rewrite_one_let')+\n    unfolding bv_cat.simps\n    apply (auto simp add:simp_rules)\n    apply (subst take_bits_bitOR[where ?h=63 and ?l=0 and ?a=\"(\\<langle>63,16\\<rangle>fst (read_memory \\<alpha> \\<sigma> 16 Mem) << 16) :: 1000 word\" and ?b=\"\\<langle>15,0\\<rangle>word_of_int imm \"])\n    by (auto simp add:simp_rules take_bits_def word_rep_drop shiftl_of_bl)\n\nlemma is_manual_mov_m8_imm8[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Mov) (Memory 8 Mem) (Immediate (ImmSixtyFour imm))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mov_m8_imm8[presimplify]:\n  shows  \"get_semantics \\<alpha> semantics (Binary (IS_8088 Mov) (Memory 8 Mem) (Immediate (ImmSixtyFour imm)) ) si =\n        (\\<lambda> \\<sigma>.  let op2 = word_of_int imm :: 64 word;\n                op1 = \\<langle>63,8\\<rangle>read_mem64 \\<alpha> \\<sigma> 8 Mem :: 64 word;\n                op3 = fst (bv_cat (op1, 56) (op2, 8)) :: 64 word\n\n          in \n          write_mem8 \\<alpha> \\<sigma> Mem op3)\"\n    apply (rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add: semantics_def)\n    apply(rewrite_one_let')+\n    unfolding bv_cat.simps\n    apply (auto simp add:simp_rules)\n    apply (subst take_bits_bitOR[where ?h=63 and ?l=0 and ?a=\"(\\<langle>63,8\\<rangle>fst (read_memory \\<alpha> \\<sigma> 8 Mem) << 8) :: 1000 word\" and ?b=\"\\<langle>7,0\\<rangle>word_of_int imm \"])\n    by (auto simp add:simp_rules take_bits_def word_rep_drop shiftl_of_bl)\n\n\n\nlemma is_manual_mov_r16_imm16[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Mov) (Reg (General Sixteen r16))  (Immediate (ImmSixtyFour imm))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mov_r16_imm16[presimplify]:\n  shows  \"get_semantics \\<alpha> semantics (Binary (IS_8088 Mov) (Reg (General Sixteen r16)) (Immediate (ImmSixtyFour imm)) ) si =\n        (\\<lambda> \\<sigma>.  let op2 = word_of_int imm :: 64 word;\n                op1 = \\<langle>63,16\\<rangle>regs \\<sigma> r16 :: 64 word;\n                op3 = fst (bv_cat (op1, 48) (op2, 16)) :: 64 word\n          in \n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r16 := op3)\\<rparr>)\" \n    apply (rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add: semantics_def)\n    apply(rewrite_one_let')+\n    unfolding bv_cat.simps\n    apply (auto simp add:simp_rules)\n    apply (subst take_bits_bitOR[where ?h=63 and ?l=0 and ?a=\"(\\<langle>63,16\\<rangle>regs \\<sigma> r16 << 16) :: 1000 word\" and ?b=\"\\<langle>15,0\\<rangle>word_of_int imm\"])\n    by (auto simp add:simp_rules take_bits_def word_rep_drop shiftl_of_bl)\n\nlemma is_manual_mov_r8_imm8[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Mov) (Reg (General EightLow r16))  (Immediate (ImmSixtyFour imm))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mov_r8_imm8[presimplify]:\n  shows  \"get_semantics \\<alpha> semantics (Binary (IS_8088 Mov) (Reg (General EightLow r8_1)) (Immediate (ImmSixtyFour imm)) ) si =\n        (\\<lambda> \\<sigma>.  let op2 = word_of_int imm :: 64 word;\n                op1 = \\<langle>63,8\\<rangle>regs \\<sigma> r8_1 :: 64 word;\n                op3 = fst (bv_cat (op1, 56) (op2, 8)) :: 64 word\n          in \n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r8_1 := op3)\\<rparr>)\" \n    apply (rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add: semantics_def)\n    apply(rewrite_one_let')+\n    unfolding bv_cat.simps\n    apply (auto simp add:simp_rules)\n    apply (subst take_bits_bitOR[where ?h=63 and ?l=0 and ?a=\"(\\<langle>63,8\\<rangle>regs \\<sigma> r8_1 << 8) :: 1000 word\" and ?b=\"\\<langle>7,0\\<rangle>word_of_int imm\"])\n    by (auto simp add:simp_rules take_bits_def word_rep_drop shiftl_of_bl)\n\n\n\nlemma is_manual_mov_r16_r16[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Mov) (Reg (General Sixteen r16_1))  (Storage (Reg (General Sixteen r16_2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mov_r16_r16[presimplify]:\n  shows  \"get_semantics \\<alpha> semantics (Binary (IS_8088 Mov)  (Reg (General Sixteen r16_1))  (Storage (Reg (General Sixteen r16_2))) ) si =\n        (\\<lambda> \\<sigma>.  let op2 =regs \\<sigma> r16_2 :: 64 word;\n                op1 = \\<langle>63,16\\<rangle>regs \\<sigma> r16_1 :: 64 word;\n                op3 = fst (bv_cat (op1, 48) (op2, 16)) :: 64 word\n          in \n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r16_1 := op3)\\<rparr>)\" \n    apply (rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add: semantics_def)\n    apply(rewrite_one_let')+\n    unfolding bv_cat.simps\n    apply (auto simp add:simp_rules)\n    apply (subst take_bits_bitOR[where ?h=63 and ?l=0 and ?a=\"(\\<langle>63,16\\<rangle>regs \\<sigma> r16_1 << 16) :: 1000 word\" and ?b=\"\\<langle>15,0\\<rangle>regs \\<sigma> r16_2\"])\n    by (auto simp add:simp_rules take_bits_def word_rep_drop shiftl_of_bl)\n\nlemma is_manual_mov_r8_r8[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Mov) (Reg (General EightLow r8_1))  (Storage (Reg (General EightLow r8_2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mov_r8_r8[presimplify]:\n  shows  \"get_semantics \\<alpha> semantics (Binary (IS_8088 Mov)  (Reg (General EightLow r8_1))  (Storage (Reg (General EightLow r8_2))) ) si =\n        (\\<lambda> \\<sigma>.  let op2 =regs \\<sigma> r8_2 :: 64 word;\n                op1 = \\<langle>63,8\\<rangle>regs \\<sigma> r8_1 :: 64 word;\n                op3 = fst (bv_cat (op1, 56) (op2, 8)) :: 64 word\n          in \n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r8_1 := op3)\\<rparr>)\" \n    apply (rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add: semantics_def)\n    apply(rewrite_one_let')+\n    unfolding bv_cat.simps\n    apply (auto simp add:simp_rules)\n    apply (subst take_bits_bitOR[where ?h=63 and ?l=0 and ?a=\"(\\<langle>63,8\\<rangle>regs \\<sigma> r8_1 << 8) :: 1000 word\" and ?b=\"\\<langle>7,0\\<rangle>regs \\<sigma> r8_2\"])\n    by (auto simp add:simp_rules take_bits_def word_rep_drop shiftl_of_bl)\n\nlemma is_manual_mov_r16_m16[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Mov) (Reg (General Sixteen r16_1))  (Storage (Memory 16 Mem))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mov_r16_m16[presimplify]:\n  shows  \"get_semantics \\<alpha> semantics (Binary (IS_8088 Mov)  (Reg (General Sixteen r16_1))  (Storage (Memory 16 Mem)) ) si =\n        (\\<lambda> \\<sigma>.  let op2 =read_mem64 \\<alpha> \\<sigma> 16 Mem  :: 64 word;\n                op1 = \\<langle>63,16\\<rangle>regs \\<sigma> r16_1 :: 64 word;\n                op3 = fst (bv_cat (op1, 48) (op2, 16)) :: 64 word\n          in \n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r16_1 := op3)\\<rparr>)\" \n    apply (rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add: semantics_def)\n    apply(rewrite_one_let')+\n    unfolding bv_cat.simps\n    apply (auto simp add:simp_rules)\n    apply (subst take_bits_bitOR[where ?h=63 and ?l=0 and ?a=\"(\\<langle>63,16\\<rangle>regs \\<sigma> r16_1 << 16) :: 1000 word\" and ?b=\"\\<langle>15,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 16 Mem)\"])\n    by (auto simp add:simp_rules take_bits_def word_rep_drop shiftl_of_bl)\n\nlemma is_manual_mov_r8_m8[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Mov) (Reg (General EightLow r8_1))  (Storage (Memory 8 Mem))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mov_r8_m8[presimplify]:\n  shows  \"get_semantics \\<alpha> semantics (Binary (IS_8088 Mov) (Reg (General EightLow r8_1))  (Storage (Memory 8 Mem))) si =\n        (\\<lambda> \\<sigma>.  let op2 =read_mem64 \\<alpha> \\<sigma> 8 Mem  :: 64 word;\n                op1 = \\<langle>63,8\\<rangle>regs \\<sigma> r8_1 :: 64 word;\n                op3 = fst (bv_cat (op1, 56) (op2, 8)) :: 64 word\n          in \n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r8_1 := op3)\\<rparr>)\" \n    apply (rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add: semantics_def)\n    apply(rewrite_one_let')+\n    unfolding bv_cat.simps\n    apply (auto simp add:simp_rules)\n    apply (subst take_bits_bitOR[where ?h=63 and ?l=0 and ?a=\"(\\<langle>63,8\\<rangle>regs \\<sigma> r8_1 << 8) :: 1000 word\" and ?b=\"\\<langle>7,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 8 Mem)\"])\n    by (auto simp add:simp_rules take_bits_def word_rep_drop shiftl_of_bl)\n\n\nlemma is_manual_mov_r64_m64[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Mov) (Reg (General SixtyFour r64)) (Storage (Memory 64 Mem))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mov_r64_m64[presimplify]:\n  shows  \"get_semantics \\<alpha> semantics (Binary (IS_8088 Mov) (Reg (General SixtyFour r64)) (Storage (Memory 64 Mem))) si =\n        (\\<lambda> \\<sigma>.   let op1 = regs \\<sigma> r64 :: 64 word;\n                op2 = read_mem64 \\<alpha> \\<sigma> 64 Mem :: 64 word\n          in \n          \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r64 := op2)\\<rparr>)\"\n\nproof-\n  show ?thesis\n    apply (rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add: semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    by (simp add: simp_rules)\nqed      \n\nlemma is_manual_mov_r32_m32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Mov) (Reg (General ThirtyTwo r32)) (Storage (Memory 32 Mem))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mov_r32_m32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Mov) (Reg (General ThirtyTwo r32)) (Storage (Memory 32 Mem))) si = \n        (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r32 :: 32 word;\n                   op2 = \\<langle>31,0\\<rangle>(read_mem64 \\<alpha> \\<sigma> 32 Mem) :: 32 word\n            in\n             \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r32 := \\<langle>31,0\\<rangle>op2)\\<rparr>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    by(simp add:simp_rules)\nqed\n\nlemma is_manual_mov_r32_r32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Mov) (Reg (General ThirtyTwo r1_32)) (Storage (Reg (General ThirtyTwo r2_32)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mov_r32_r32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Mov) (Reg (General ThirtyTwo r1_32)) (Storage (Reg (General ThirtyTwo r2_32)))) si = \n        (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r1_32 :: 32 word;\n                   op2 = \\<langle>31,0\\<rangle>regs \\<sigma> r2_32 :: 32 word\n            in\n             \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r1_32 := \\<langle>31,0\\<rangle>op2)\\<rparr>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    by(simp add:simp_rules)\nqed\n\n\nlemma truncating_word_of_int_32_bits[get_semantics_rewriting]:\n  shows \"(\\<lbrace>3,0\\<rbrace> (word_of_int imm :: 64 word)) = (\\<lbrace>3,0\\<rbrace> (word_of_int imm :: 32 word))\"\nproof-\n  let ?xs = \"\\<lbrace>3,0\\<rbrace> (word_of_int imm :: 64 word)\"\n  let ?ys = \"\\<lbrace>3,0\\<rbrace> (word_of_int imm :: 32 word)\"\n  {\n    fix i :: nat\n    assume i: \"i < length ?xs\"\n    {\n      fix j :: nat\n      have i: \"i \\<in> {0,1,2,3}\"\n        using i\n        by auto\n      assume \"j < 8\"\n      hence \"?xs ! i !! j = ?ys ! i !! j\"\n        using i\n        by (auto simp add: nth_bytes_of test_bit_of_take_bits test_bit_of_byte_of)\n    }\n    hence \"?xs ! i = ?ys ! i\"\n      apply (intro word_eqI)\n      by (auto simp add: word_size)\n  }\n  thus ?thesis\n    apply (intro nth_equalityI)\n    by auto\nqed\n\nlemma is_manual_mov_m32_imm32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Mov) (Memory 32 Mem) (Immediate (ImmSixtyFour imm))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mov_m32_imm32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Mov) (Memory 32 Mem) (Immediate (ImmSixtyFour imm))) si = \n        (\\<lambda> \\<sigma> . let op2 = imm  \n            in\n             write_mem32 \\<alpha> \\<sigma> Mem (word_of_int imm))\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n    by (simp add: truncating_word_of_int_32_bits )\n\nqed\n\nlemma is_manual_mov_r32_imm32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Mov) (Reg (General ThirtyTwo r1_32)) (Immediate (ImmSixtyFour imm))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mov_r32_imm32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Mov) (Reg (General ThirtyTwo r1_32)) (Immediate (ImmSixtyFour Imm))) si = \n        (\\<lambda> \\<sigma> . let op2 = word_of_int Imm :: 64 word\n            in\n             \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r1_32 := (\\<langle>31,0\\<rangle>op2) :: 64 word)\\<rparr>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n    by (auto simp add:simp_rules)\nqed\n\nlemma is_manual_mov_r64_imm64[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Mov) (Reg (General SixtyFour r64)) (Immediate (ImmSixtyFour imm))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mov_r64_imm64[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Mov) (Reg (General SixtyFour r64)) (Immediate (ImmSixtyFour Imm))) si = \n        (\\<lambda> \\<sigma> . let op2 = word_of_int Imm :: 64 word\n            in\n             \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r64 := op2)\\<rparr>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n    by (auto simp add:simp_rules)\nqed\n\nlemma is_manual_mov_m64_imm32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Mov) (Memory 64 Mem) (Immediate (ImmSixtyFour imm))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mov_m64_imm32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Mov) (Memory 64 Mem) (Immediate (ImmSixtyFour Imm))) si = \n        (\\<lambda> \\<sigma> . let op2 = imm  \n            in\n             write_mem64 \\<alpha> \\<sigma> Mem (word_of_int Imm::64 word))\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n    by (auto simp add:simp_rules sextend_useless_64_64)\nqed\n\n(*---------------------------------------------------proofs on cmovae ---------------------------------------*)\n\nlemma is_manual_cmovae_r32_r32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_PentiumPro Cmovae) (Reg (General ThirtyTwo r1)) (Storage (Reg (General ThirtyTwo r2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_cmovae_r32_r32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_PentiumPro Cmovae) (Reg (General ThirtyTwo r1)) (Storage (Reg (General ThirtyTwo r2)))) si =\n        (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r1 :: 32 word;\n                   op2 = \\<langle>31,0\\<rangle>regs \\<sigma> r2 :: 32 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r1 := if flags \\<sigma> flag_cf then ucast op1 else ucast op2)\\<rparr>)\"\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n    apply (auto simp add:simp_rules semantics_def)\n    apply(rewrite_one_let')+\n  by (auto simp add:simp_rules bv_to_bool_def word_lsb_alt test_bit_of_take_bits)\n\n(*---------------------------------------------------proofs on cmova ---------------------------------------*)\n\nlemma is_manual_cmova_r32_r32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_PentiumPro Cmova) (Reg (General ThirtyTwo r1)) (Storage (Reg (General ThirtyTwo r2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_cmova_r32_r32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_PentiumPro Cmova) (Reg (General ThirtyTwo r1)) (Storage (Reg (General ThirtyTwo r2)))) si =\n        (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r1 :: 32 word;\n                   op2 = \\<langle>31,0\\<rangle>regs \\<sigma> r2 :: 32 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r1 := if flags \\<sigma> flag_cf \\<or> flags \\<sigma> flag_zf then ucast op1 else ucast op2)\\<rparr>)\"\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n    apply (auto simp add:simp_rules semantics_def)\n    apply(rewrite_one_let')+\n  by (auto simp add:simp_rules bv_to_bool_def word_lsb_alt test_bit_of_take_bits)\n\n(*---------------------------------------------------proofs on movsx ---------------------------------------*)\nlemma is_manual_movsx_r32_r8[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_80386 Movsx) (Reg (General ThirtyTwo r1_32)) (Storage (Reg (General EightLow r2_8)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_movsx_r32_r8[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_80386 Movsx) (Reg (General ThirtyTwo r1_32)) (Storage (Reg (General EightLow r2_8)))) si = \n        (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r1_32 :: 32 word;\n                   op2 = sextend (\\<langle>7,0\\<rangle>regs \\<sigma> r2_8 :: 32 word) 8 32\n            in\n             \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r1_32 := ucast op2 )\\<rparr>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n    by (auto simp add:simp_rules)\nqed\n\n(*---------------------------------------------------proofs on movsxd ---------------------------------------*)\n\nlemma is_manual_movsxd_r64_r32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_X86_64 Movsxd) (Reg (General SixtyFour r1)) (Storage (Reg (General ThirtyTwo r2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_movsxd_r64_r32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_X86_64 Movsxd) (Reg (General SixtyFour r1)) (Storage (Reg (General ThirtyTwo r2)))) si =\n        (\\<lambda> \\<sigma> . let op2 = \\<langle>31,0\\<rangle>regs \\<sigma> r2 :: 32 word\n            in\n             \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r1 := sextend (ucast op2) 32 64)\\<rparr>)\"\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n    by (auto simp add:simp_rules)\n\n\nlemma is_manual_movsxd_r64_m32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_X86_64 Movsxd) (Reg (General SixtyFour r1)) (Storage (Memory 32 Mem))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_movsxd_r64_m32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_X86_64 Movsxd) (Reg (General SixtyFour r1)) (Storage (Memory 32 Mem))) si =\n        (\\<lambda> \\<sigma> . let op2 = \\<langle>31,0\\<rangle>(read_mem64 \\<alpha> \\<sigma> 32 Mem) :: 32 word\n            in\n             \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r1 := sextend (ucast op2) 32 64)\\<rparr>)\"\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (subst unfold_semantics)\n  apply (auto simp add: Let'_def simp_rules )\n  done\n\n\n\n\n(*---------------------------------------------------proofs on movzx ---------------------------------------*)\n\nlemma is_manual_movzx_r32_m8[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_80386 Movzx) (Reg (General ThirtyTwo r1_32)) (Storage (Memory 8 Mem))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_movzx_r32_m8[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_80386 Movzx) (Reg (General ThirtyTwo r1_32)) (Storage (Memory 8 Mem))) si = \n        (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r1_32 :: 32 word;\n                   op2 = \\<langle>7,0\\<rangle>(read_mem64 \\<alpha> \\<sigma> 8 Mem) :: 8 word\n            in\n             \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r1_32 := ucast op2 )\\<rparr>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n    by (auto simp add:simp_rules)\nqed\n\n\nlemma is_manual_movzx_r32_r8[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_80386 Movzx) (Reg (General ThirtyTwo r1_32)) (Storage (Reg (General EightLow r2_8)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_movzx_r32_r8[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_80386 Movzx) (Reg (General ThirtyTwo r1_32)) (Storage (Reg (General EightLow r2_8)))) si = \n        (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r1_32 :: 32 word;\n                   op2 = \\<langle>7,0\\<rangle>(regs \\<sigma> r2_8) :: 8 word\n            in\n             \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r1_32 := ucast op2 )\\<rparr>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n    by (auto simp add:simp_rules)\nqed\n\n\nlemma is_manual_movzx_r32_m16[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_80386 Movzx) (Reg (General ThirtyTwo r1_32)) (Storage (Memory 16 Mem))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_movzx_r32_m16[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_80386 Movzx) (Reg (General ThirtyTwo r1_32)) (Storage (Memory 16 Mem))) si = \n        (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r1_32 :: 32 word;\n                   op2 = \\<langle>15,0\\<rangle>(read_mem64 \\<alpha> \\<sigma> 16 Mem) :: 16 word\n            in\n             \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r1_32 := ucast op2 )\\<rparr>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n    by (auto simp add:simp_rules)\nqed\n\n\nlemma is_manual_movzx_r32_r16[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_80386 Movzx) (Reg (General ThirtyTwo r1_32)) (Storage (Reg (General Sixteen r16)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_movzx_r32_r16[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_80386 Movzx) (Reg (General ThirtyTwo r1_32)) (Storage (Reg (General Sixteen r16)))) si = \n        (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r1_32 :: 32 word;\n                   op2 = \\<langle>15,0\\<rangle>(regs \\<sigma> r16) :: 16 word\n            in\n             \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r1_32 := ucast op2 )\\<rparr>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n    by (auto simp add:simp_rules)\nqed\n\n\n\n(*---------------------------------------------------proofs on movapd ---------------------------------------*)\nlemma is_manual_movapd_xmm_xmm[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_SSE2_SIMD Movapd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_movapd_xmm_xmm[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_SSE2_SIMD Movapd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2)))) si = \n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r1 :: 64 word;\n                   op2 = regs \\<sigma> r2 :: 64 word\n            in\n            if r1 \\<noteq> r4 \\<and> r3 \\<noteq> r4 \\<and> r5 \\<noteq> r3 \\<and> r5 \\<noteq> r4 \\<and> r6 \\<noteq> r4 \\<and> r6 \\<noteq> r3 then\n              \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r3 := op1, r4 := op2)\\<rparr>\n            else (let' p = (IMF_SSE2_SIMD, IS_SSE2_SIMD Movapd,\n                    Binary_sig (Reg_sig SSE_sig) (Storage_sig (Reg_sig SSE_sig)));\n               family_list = instr_semantics semantics (fst p); family_list_not_found = family_list = None;\n               variant_list = if family_list_not_found then None else the family_list (fst (snd p));\n               variant_list_not_found = variant_list = None;\n               bv_formula = if variant_list_not_found then None else the variant_list (snd (snd p));\n               manual = bv_formula = None; op1_bvf = get_op1_bvf (the bv_formula);\n               exec =\n                 if manual\n                 then manual_exec_instr \\<alpha>\n                       (Binary (IS_SSE2_SIMD Movapd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2))))\n                       si\n                 else exec_learned_instr \\<alpha> (the bv_formula) op1_bvf\n                       (Binary (IS_SSE2_SIMD Movapd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2))))\n          in exec)\n          \\<sigma>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    defer\n    apply simp\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n    apply (simp_all add: Let'_def simp_rules )\n    done\nqed\n\n(*---------------------------------------------------proofs on movq ---------------------------------------*)\nlemma is_manual_movq_xmm_xmm[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_PentiumMMX_MMX Movq) (Reg (General SixtyFour r64)) (Storage (Reg (SSE r3 r4 r1 r2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_movq_xmm_xmm[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_PentiumMMX_MMX Movq) (Reg (General SixtyFour r64)) (Storage (Reg (SSE r3 r4 r1 r2)))) si = \n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r2 :: 64 word\n            in\n            \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r64 := op1)\\<rparr>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n    by (simp_all add: Let'_def simp_rules )\nqed\n\n(*---------------------------------------------------proofs on movsd ---------------------------------------*)\nlemma is_manual_movsd_xmm_xmm[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_SSE2_SIMD Movsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_movsd_xmm_xmm[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_SSE2_SIMD Movsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2)))) si = \n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r2 :: 64 word\n            in\n          if r1 \\<noteq> r4 \\<and> r3 \\<noteq> r4 \\<and> r5 \\<noteq> r3 \\<and> r5 \\<noteq> r4 \\<and> r6 \\<noteq> r4 \\<and> r6 \\<noteq> r3 then\n             \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r4 := op1)\\<rparr>\n          else  (let' p = (IMF_SSE2_SIMD, IS_SSE2_SIMD Movsd,\n                    Binary_sig (Reg_sig SSE_sig) (Storage_sig (Reg_sig SSE_sig)));\n               family_list = instr_semantics semantics (fst p); family_list_not_found = family_list = None;\n               variant_list = if family_list_not_found then None else the family_list (fst (snd p));\n               variant_list_not_found = variant_list = None;\n               bv_formula = if variant_list_not_found then None else the variant_list (snd (snd p));\n               manual = bv_formula = None; op1_bvf = get_op1_bvf (the bv_formula);\n               exec =\n                 if manual\n                 then manual_exec_instr \\<alpha>\n                       (Binary (IS_SSE2_SIMD Movsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2))))\n                       si\n                 else exec_learned_instr \\<alpha> (the bv_formula) op1_bvf\n                       (Binary (IS_SSE2_SIMD Movsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2))))\n          in exec) \\<sigma>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    defer\n    apply simp\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n    by (auto simp add:simp_rules)\nqed\n\n(*---------------------------------------------------proofs on pxor ---------------------------------------*)\n\nlemma take_bits_bitXOR_generic[get_semantics_rewriting]:\n  fixes a b :: \"'a::len0 word\"\n  assumes \"h < LENGTH('a)\"\n      and \"k < h\" \n    shows \"((\\<langle>h,k\\<rangle>(a XOR b)) :: 'b::len0 word) = ((\\<langle>h,k\\<rangle>a) :: 'b::len0 word) XOR \\<langle>h,k\\<rangle>b\"\nproof-\n  {\n    fix n :: nat\n    assume \"n < LENGTH('b)\"\n    hence \"((\\<langle>h,k\\<rangle>(a XOR b)) :: 'b::len0 word) !! n = (((\\<langle>h,k\\<rangle>a) :: 'b::len0 word) XOR \\<langle>h,k\\<rangle>b) !! n\"\n      using assms\n      apply (subst test_bit_of_take_bits)\n      by (auto simp add: test_bit_of_take_bits bitXOR_nth)\n  }\n  thus ?thesis\n    apply (intro word_eqI)\n    by (auto simp add: word_size)\nqed\n\n\n\nlemma xor_shift_and_take_upper[get_semantics_rewriting]:\n  fixes a b c d :: \"64 word\"\n  shows \"\\<langle>127,64\\<rangle>(((\\<langle>63,0\\<rangle>a << 64) OR (\\<langle>63,0\\<rangle>b :: 1000 word)) XOR (\\<langle>63,0\\<rangle>c << 64) OR (\\<langle>63,0\\<rangle>d :: 1000 word)) = (a XOR c)\"\nproof-\n  show ?thesis\n    apply (subst take_bits_bitXOR_generic)\n    apply (auto)\n    apply (subst take_bits_bitOR)\n    apply simp\n    apply (subst take_bits_bitOR)\n     apply simp\n    apply (subst take_bits_def)+\n    apply (auto)\n    by (auto simp add: word_rep_drop shiftl_of_bl)\nqed\n\nlemma xor_shift_and_take_lower[get_semantics_rewriting]:\n  fixes a b c d :: \"64 word\"\n  shows \"\\<langle>63,0\\<rangle>(((\\<langle>63,0\\<rangle>a << 64) OR (\\<langle>63,0\\<rangle>b :: 1000 word)) XOR (\\<langle>63,0\\<rangle>c << 64) OR (\\<langle>63,0\\<rangle>d :: 1000 word)) = (b XOR d)\"\nproof-\n  show ?thesis\n    apply (subst take_bits_bitXOR_generic)\n    apply (auto)\n    apply (subst take_bits_bitOR)\n    apply simp\n    apply (subst take_bits_bitOR)\n     apply simp\n    apply (subst take_bits_def)+\n    apply (auto)\n    by (auto simp add: word_rep_drop shiftl_of_bl)\nqed\n\nlemma is_manual_pxor_xmm_xmm[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_PentiumMMX_MMX Pxor) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n                                \nlemma get_semantics_pxor_xmm_xmm[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_PentiumMMX_MMX Pxor) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2)))) si = \n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r3 :: 64 word;\n                   op2= regs \\<sigma> r4 :: 64 word;\n                   op3 = regs \\<sigma> r1 :: 64 word;\n                   op4 = regs \\<sigma> r2 :: 64 word\n            in\n          if r1 \\<noteq> r4 \\<and> r3 \\<noteq> r4 \\<and> r5 \\<noteq> r3 \\<and> r5 \\<noteq> r4 \\<and> r6 \\<noteq> r4 \\<and> r6 \\<noteq> r3 then\n             \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r3 := op1 XOR op3, r4 := op2 XOR op4 )\\<rparr>\n          else (let' p = (IMF_PentiumMMX_MMX, IS_PentiumMMX_MMX Pxor,\n                    Binary_sig (Reg_sig SSE_sig) (Storage_sig (Reg_sig SSE_sig)));\n               family_list = instr_semantics semantics (fst p); family_list_not_found = family_list = None;\n               variant_list = if family_list_not_found then None else the family_list (fst (snd p));\n               variant_list_not_found = variant_list = None;\n               bv_formula = if variant_list_not_found then None else the variant_list (snd (snd p));\n               manual = bv_formula = None; op1_bvf = get_op1_bvf (the bv_formula);\n               exec =\n                 if manual\n                 then manual_exec_instr \\<alpha>\n                       (Binary (IS_PentiumMMX_MMX Pxor) (Reg (SSE r5 r6 r3 r4))\n                         (Storage (Reg (SSE r7 r17 r1 r2))))\n                       si\n                 else exec_learned_instr \\<alpha> (the bv_formula) op1_bvf\n                       (Binary (IS_PentiumMMX_MMX Pxor) (Reg (SSE r5 r6 r3 r4))\n                         (Storage (Reg (SSE r7 r17 r1 r2))))\n          in exec) \n        \\<sigma>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    defer\n    apply simp\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n    apply (auto simp add:simp_rules)\n    unfolding bv_cat.simps\n    by (auto simp add:simp_rules xor_shift_and_take_upper xor_shift_and_take_lower)\n  qed\n\nabbreviation \"read_mem_128 \\<alpha> \\<sigma> s a \\<equiv> fst (bv_slice s 0 (bv_read_memory \\<alpha> \\<sigma> s a))\"\n\nlemma is_manual_pxor_xmm_m128[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_PentiumMMX_MMX Pxor) (Reg (SSE r5 r6 r3 r4)) (Storage (Memory 128 Mem))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_pxor_xmm_m128[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_PentiumMMX_MMX Pxor) (Reg (SSE r5 r6 r3 r4)) (Storage (Memory 128 Mem))) si = \n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r3 :: 64 word;\n                   op2= regs \\<sigma> r4 :: 64 word;\n                   op3 = \\<langle>127,64\\<rangle>read_mem_128 \\<alpha> \\<sigma> 128 Mem :: 64 word;\n                   op4 = \\<langle>63,0\\<rangle>read_mem_128 \\<alpha> \\<sigma> 128 Mem :: 64 word\n\n            in\n          if r3 \\<noteq> r4 \\<and> r5 \\<noteq> r3 \\<and> r5 \\<noteq> r4 \\<and> r6 \\<noteq> r4 \\<and> r6 \\<noteq> r3 then\n             \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r3 := (op1 XOR op3),  r4 := (op2 XOR op4))\\<rparr>\n          else  (let' p = (IMF_PentiumMMX_MMX, IS_PentiumMMX_MMX Pxor,\n                    Binary_sig (Reg_sig SSE_sig) (Storage_sig (Memory_sig 128)));\n               family_list = instr_semantics semantics (fst p); family_list_not_found = family_list = None;\n               variant_list = if family_list_not_found then None else the family_list (fst (snd p));\n               variant_list_not_found = variant_list = None;\n               bv_formula = if variant_list_not_found then None else the variant_list (snd (snd p));\n               manual = bv_formula = None; op1_bvf = get_op1_bvf (the bv_formula);\n               exec =\n                 if manual\n                 then manual_exec_instr \\<alpha>\n                       (Binary (IS_PentiumMMX_MMX Pxor) (Reg (SSE r5 r6 r3 r4)) (Storage (Memory 128 Mem))) si\n                 else exec_learned_instr \\<alpha> (the bv_formula) op1_bvf\n                       (Binary (IS_PentiumMMX_MMX Pxor) (Reg (SSE r5 r6 r3 r4)) (Storage (Memory 128 Mem)))\n          in exec) \\<sigma>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    defer\n    apply simp\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n    apply (auto simp add:simp_rules)\n    unfolding bv_cat.simps\n    apply (auto simp add:simp_rules)\n    apply (subst take_bits_bitXOR_generic)\n    apply (auto)\n    apply (subst take_bits_bitXOR_generic)\n      apply (auto)\n    apply (subst take_bits_bitOR)\n    apply simp\n    apply (subst take_bits_bitOR)\n     apply simp\n    apply (subst take_bits_def)+\n    apply (auto)\n    by (auto simp add: word_rep_drop shiftl_of_bl)\n  qed\n\n(*---------------------------------------------------proofs on andpd ---------------------------------------*)\nlemma is_manual_andpd_xmm_xmm[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_SSE2_SIMD Andpd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_andpd_xmm_xmm[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_SSE2_SIMD Andpd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2)))) si = \n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r3 :: 64 word;\n                   op2= regs \\<sigma> r4 :: 64 word;\n                   op3 = regs \\<sigma> r1 :: 64 word;\n                   op4 = regs \\<sigma> r2 :: 64 word\n            in\n          if r1 \\<noteq> r4 \\<and> r3 \\<noteq> r4 \\<and> r5 \\<noteq> r3 \\<and> r5 \\<noteq> r4 \\<and> r6 \\<noteq> r4 \\<and> r6 \\<noteq> r3 then\n             \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r3 := op1 AND op3, r4 := op2 AND op4 )\\<rparr>\n          else (let' p = (IMF_SSE2_SIMD, IS_SSE2_SIMD Andpd,\n                    Binary_sig (Reg_sig SSE_sig) (Storage_sig (Reg_sig SSE_sig)));\n               family_list = instr_semantics semantics (fst p); family_list_not_found = family_list = None;\n               variant_list = if family_list_not_found then None else the family_list (fst (snd p));\n               variant_list_not_found = variant_list = None;\n               bv_formula = if variant_list_not_found then None else the variant_list (snd (snd p));\n               manual = bv_formula = None; op1_bvf = get_op1_bvf (the bv_formula);\n               exec =\n                 if manual\n                 then manual_exec_instr \\<alpha>\n                       (Binary (IS_SSE2_SIMD Andpd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2))))\n                       si\n                 else exec_learned_instr \\<alpha> (the bv_formula) op1_bvf\n                       (Binary (IS_SSE2_SIMD Andpd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2))))\n          in exec) \\<sigma>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    defer\n    apply simp\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n    apply (auto simp add:simp_rules)\n    apply (subst take_bits_bitAND)\n    apply simp\n    apply (subst take_bits_bitAND)\n    apply simp\n    unfolding bv_cat.simps\n    apply (auto simp add:simp_rules)\n    apply (subst take_bits_bitOR)\n     apply simp\n    apply (subst take_bits_bitOR)\n     apply simp\n    apply (subst take_bits_bitOR)\n     apply simp\n    apply (subst take_bits_bitOR)\n    apply simp\n    apply (subst take_bits_def)+\n    apply (auto)\n    by (auto simp add: word_rep_drop shiftl_of_bl)\n  qed\n\n(*---------------------------------------------------proofs on subsd ---------------------------------------*)\nlemma is_manual_subsd_xmm_xmm[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_SSE2_SIMD Subsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_subsd_xmm_xmm[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_SSE2_SIMD Subsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2)))) si = \n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r3 :: 64 word;\n                   op2= regs \\<sigma> r4 :: 64 word;\n                   op3 = regs \\<sigma> r1 :: 64 word;\n                   op4 = regs \\<sigma> r2 :: 64 word\n            in\n          if r1 \\<noteq> r4 \\<and> r3 \\<noteq> r4 \\<and> r5 \\<noteq> r3 \\<and> r5 \\<noteq> r4 \\<and> r6 \\<noteq> r4 \\<and> r6 \\<noteq> r3 then\n             \\<sigma>\\<lparr>regs := (regs \\<sigma>)( r4 := op2 -\\<^sup>f op4 )\\<rparr>\n          else   (let' p = (IMF_SSE2_SIMD, IS_SSE2_SIMD Subsd,\n                    Binary_sig (Reg_sig SSE_sig) (Storage_sig (Reg_sig SSE_sig)));\n               family_list = instr_semantics semantics (fst p); family_list_not_found = family_list = None;\n               variant_list = if family_list_not_found then None else the family_list (fst (snd p));\n               variant_list_not_found = variant_list = None;\n               bv_formula = if variant_list_not_found then None else the variant_list (snd (snd p));\n               manual = bv_formula = None; op1_bvf = get_op1_bvf (the bv_formula);\n               exec =\n                 if manual\n                 then manual_exec_instr \\<alpha>\n                       (Binary (IS_SSE2_SIMD Subsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2))))\n                       si\n                 else exec_learned_instr \\<alpha> (the bv_formula) op1_bvf\n                       (Binary (IS_SSE2_SIMD Subsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2))))\n          in exec) \\<sigma>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    defer\n    apply simp\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n    by (auto simp add:simp_rules)\n  qed\n\nlemma is_manual_subsd_xmm_m64[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_SSE2_SIMD Subsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Memory 64 Mem))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_subsd_xmm_m64[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_SSE2_SIMD Subsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Memory 64 Mem))) si = \n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r4 :: 64 word;\n                   op2 = read_mem64 \\<alpha> \\<sigma> 64 Mem :: 64 word\n\n            in\n          if r3 \\<noteq> r4 \\<and> r5 \\<noteq> r3 \\<and> r5 \\<noteq> r4 \\<and> r6 \\<noteq> r4 \\<and> r6 \\<noteq> r3 then\n           \\<sigma>\\<lparr>regs := (regs \\<sigma>)( r4 := op1 -\\<^sup>f op2 )\\<rparr>\n\n         else (let' p = (IMF_SSE2_SIMD, IS_SSE2_SIMD Subsd,\n                    Binary_sig (Reg_sig SSE_sig) (Storage_sig (Memory_sig 64)));\n               family_list = instr_semantics semantics (fst p); family_list_not_found = family_list = None;\n               variant_list = if family_list_not_found then None else the family_list (fst (snd p));\n               variant_list_not_found = variant_list = None;\n               bv_formula = if variant_list_not_found then None else the variant_list (snd (snd p));\n               manual = bv_formula = None; op1_bvf = get_op1_bvf (the bv_formula);\n               exec =\n                 if manual\n                 then manual_exec_instr \\<alpha>\n                       (Binary (IS_SSE2_SIMD Subsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Memory 64 Mem))) si\n                 else exec_learned_instr \\<alpha> (the bv_formula) op1_bvf\n                       (Binary (IS_SSE2_SIMD Subsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Memory 64 Mem)))\n          in exec) \\<sigma>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    defer\n    apply simp\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n     apply(rewrite_one_let')+\n    by (auto simp add:simp_rules)\n  qed\n\n(*---------------------------------------------------proofs on addsd ---------------------------------------*)\nlemma is_manual_addsd_xmm_xmm[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_SSE2_SIMD Addsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_addsd_xmm_xmm[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_SSE2_SIMD Addsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2)))) si = \n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r3 :: 64 word;\n                   op2= regs \\<sigma> r4 :: 64 word;\n                   op3 = regs \\<sigma> r1 :: 64 word;\n                   op4 = regs \\<sigma> r2 :: 64 word\n            in\n          if r1 \\<noteq> r4 \\<and> r3 \\<noteq> r4 \\<and> r5 \\<noteq> r3 \\<and> r5 \\<noteq> r4 \\<and> r6 \\<noteq> r4 \\<and> r6 \\<noteq> r3 then\n             \\<sigma>\\<lparr>regs := (regs \\<sigma>)( r4 := op2 +\\<^sup>f op4 )\\<rparr>\n          else (let' p = (IMF_SSE2_SIMD, IS_SSE2_SIMD Addsd,\n                    Binary_sig (Reg_sig SSE_sig) (Storage_sig (Reg_sig SSE_sig)));\n               family_list = instr_semantics semantics (fst p); family_list_not_found = family_list = None;\n               variant_list = if family_list_not_found then None else the family_list (fst (snd p));\n               variant_list_not_found = variant_list = None;\n               bv_formula = if variant_list_not_found then None else the variant_list (snd (snd p));\n               manual = bv_formula = None; op1_bvf = get_op1_bvf (the bv_formula);\n               exec =\n                 if manual\n                 then manual_exec_instr \\<alpha>\n                       (Binary (IS_SSE2_SIMD Addsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2))))\n                       si\n                 else exec_learned_instr \\<alpha> (the bv_formula) op1_bvf\n                       (Binary (IS_SSE2_SIMD Addsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2))))\n          in exec) \\<sigma>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    defer\n    apply simp\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n    apply(rewrite_one_let')+\n    by (auto simp add:simp_rules)\nqed\n\nlemma is_manual_addsd_xmm_m64[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_SSE2_SIMD Addsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Memory 64 Mem))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_addsd_xmm_m64[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_SSE2_SIMD Addsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Memory 64 Mem))) si = \n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r4 :: 64 word;\n                   op2 = read_mem64 \\<alpha> \\<sigma> 64 Mem :: 64 word\n\n            in\n          if r3 \\<noteq> r4 \\<and> r5 \\<noteq> r3 \\<and> r5 \\<noteq> r4 \\<and> r6 \\<noteq> r4 \\<and> r6 \\<noteq> r3 then\n           \\<sigma>\\<lparr>regs := (regs \\<sigma>)( r4 := op1 +\\<^sup>f op2 )\\<rparr>\n\n         else (let' p = (IMF_SSE2_SIMD, IS_SSE2_SIMD Addsd,\n                    Binary_sig (Reg_sig SSE_sig) (Storage_sig (Memory_sig 64)));\n               family_list = instr_semantics semantics (fst p); family_list_not_found = family_list = None;\n               variant_list = if family_list_not_found then None else the family_list (fst (snd p));\n               variant_list_not_found = variant_list = None;\n               bv_formula = if variant_list_not_found then None else the variant_list (snd (snd p));\n               manual = bv_formula = None; op1_bvf = get_op1_bvf (the bv_formula);\n               exec =\n                 if manual\n                 then manual_exec_instr \\<alpha>\n                       (Binary (IS_SSE2_SIMD Addsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Memory 64 Mem))) si\n                 else exec_learned_instr \\<alpha> (the bv_formula) op1_bvf\n                       (Binary (IS_SSE2_SIMD Addsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Memory 64 Mem)))\n          in exec) \\<sigma>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    defer\n    apply simp\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n     apply(rewrite_one_let')+\n    by (auto simp add:simp_rules)\n  qed\n\n\n(*---------------------------------------------------proofs on mulsd ---------------------------------------*)\nlemma is_manual_mulsd_xmm_xmm[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_SSE2_SIMD Mulsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mulsd_xmm_xmm[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_SSE2_SIMD Mulsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2)))) si = \n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r3 :: 64 word;\n                   op2= regs \\<sigma> r4 :: 64 word;\n                   op3 = regs \\<sigma> r1 :: 64 word;\n                   op4 = regs \\<sigma> r2 :: 64 word\n            in\n          if r1 \\<noteq> r4 \\<and> r3 \\<noteq> r4 \\<and> r5 \\<noteq> r3 \\<and> r5 \\<noteq> r4 \\<and> r6 \\<noteq> r4 \\<and> r6 \\<noteq> r3 then\n             \\<sigma>\\<lparr>regs := (regs \\<sigma>)( r4 := op2 *\\<^sup>f op4 )\\<rparr>\n          else \n        (let' p = (IMF_SSE2_SIMD, IS_SSE2_SIMD Mulsd,\n                    Binary_sig (Reg_sig SSE_sig) (Storage_sig (Reg_sig SSE_sig)));\n               family_list = instr_semantics semantics (fst p); family_list_not_found = family_list = None;\n               variant_list = if family_list_not_found then None else the family_list (fst (snd p));\n               variant_list_not_found = variant_list = None;\n               bv_formula = if variant_list_not_found then None else the variant_list (snd (snd p));\n               manual = bv_formula = None; op1_bvf = get_op1_bvf (the bv_formula);\n               exec =\n                 if manual\n                 then manual_exec_instr \\<alpha>\n                       (Binary (IS_SSE2_SIMD Mulsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2))))\n                       si\n                 else exec_learned_instr \\<alpha> (the bv_formula) op1_bvf\n                       (Binary (IS_SSE2_SIMD Mulsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Reg (SSE r7 r17 r1 r2))))\n          in exec) \\<sigma>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)        \n    apply(rewrite_one_let')\n    defer\n    apply simp\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n     apply(rewrite_one_let')+\n    by (auto simp add: set_def)\n  qed\n\nlemma is_manual_mulsd_xmm_m64[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_SSE2_SIMD Mulsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Memory 64 Mem))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_mulsd_xmm_m64[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_SSE2_SIMD Mulsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Memory 64 Mem))) si = \n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r4 :: 64 word;\n                   op2 = read_mem64 \\<alpha> \\<sigma> 64 Mem :: 64 word\n\n            in\n          if r3 \\<noteq> r4 \\<and> r5 \\<noteq> r3 \\<and> r5 \\<noteq> r4 \\<and> r6 \\<noteq> r4 \\<and> r6 \\<noteq> r3 then\n           \\<sigma>\\<lparr>regs := (regs \\<sigma>)( r4 := op1 *\\<^sup>f op2 )\\<rparr>\n\n         else (let' p = (IMF_SSE2_SIMD, IS_SSE2_SIMD Mulsd,\n                    Binary_sig (Reg_sig SSE_sig) (Storage_sig (Memory_sig 64)));\n               family_list = instr_semantics semantics (fst p); family_list_not_found = family_list = None;\n               variant_list = if family_list_not_found then None else the family_list (fst (snd p));\n               variant_list_not_found = variant_list = None;\n               bv_formula = if variant_list_not_found then None else the variant_list (snd (snd p));\n               manual = bv_formula = None; op1_bvf = get_op1_bvf (the bv_formula);\n               exec =\n                 if manual\n                 then manual_exec_instr \\<alpha>\n                       (Binary (IS_SSE2_SIMD Mulsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Memory 64 Mem))) si\n                 else exec_learned_instr \\<alpha> (the bv_formula) op1_bvf\n                       (Binary (IS_SSE2_SIMD Mulsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Memory 64 Mem)))\n          in exec) \\<sigma>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    defer\n    apply simp\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n     apply(rewrite_one_let')+\n    by (auto simp add:simp_rules)\n  qed\n\n(*---------------------------------------------------proofs on divsd ---------------------------------------*)\nlemma is_manual_divsd_xmm_m64[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_SSE2_SIMD Divsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Memory 64 Mem))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_divsd_xmm_m64[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_SSE2_SIMD Divsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Memory 64 Mem))) si = \n        (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r4 :: 64 word;\n                   op2 = read_mem64 \\<alpha> \\<sigma> 64 Mem :: 64 word\n\n            in\n          if r3 \\<noteq> r4 \\<and> r5 \\<noteq> r3 \\<and> r5 \\<noteq> r4 \\<and> r6 \\<noteq> r4 \\<and> r6 \\<noteq> r3 then\n           \\<sigma>\\<lparr>regs := (regs \\<sigma>)( r4 := op1 div\\<^sup>f op2 )\\<rparr>\n\n         else (let' p = (IMF_SSE2_SIMD, IS_SSE2_SIMD Divsd,\n                    Binary_sig (Reg_sig SSE_sig) (Storage_sig (Memory_sig 64)));\n               family_list = instr_semantics semantics (fst p); family_list_not_found = family_list = None;\n               variant_list = if family_list_not_found then None else the family_list (fst (snd p));\n               variant_list_not_found = variant_list = None;\n               bv_formula = if variant_list_not_found then None else the variant_list (snd (snd p));\n               manual = bv_formula = None; op1_bvf = get_op1_bvf (the bv_formula);\n               exec =\n                 if manual\n                 then manual_exec_instr \\<alpha>\n                       (Binary (IS_SSE2_SIMD Divsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Memory 64 Mem))) si\n                 else exec_learned_instr \\<alpha> (the bv_formula) op1_bvf\n                       (Binary (IS_SSE2_SIMD Divsd) (Reg (SSE r5 r6 r3 r4)) (Storage (Memory 64 Mem)))\n          in exec) \\<sigma>)\"\nproof-\n  show ?thesis\n    apply(rule ext)\n    apply(subst get_semantics_def)\n    apply(rewrite_one_let')\n    defer\n    apply simp\n    apply(rewrite_one_let')\n    apply(rewrite_one_let')\n    apply(rewrite_one_let' add:semantics_def)\n     apply(rewrite_one_let')+\n    by (auto simp add:simp_rules)\n  qed\n\n(*---------------------------------------------------proofs on sub ---------------------------------------*)\nabbreviation \"read_mem \\<alpha> \\<sigma> s a \\<equiv> fst (read_memory \\<alpha> \\<sigma> s a)\"\n\nlemma is_manual_sub_r32_m32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Sub) (Reg (General ThirtyTwo r32)) (Storage (Memory 32 a))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_sub_r32_m32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Sub) (Reg (General ThirtyTwo r32)) (Storage (Memory 32 a))) si = \n             (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r32 :: 32 word;\n                   op2 = \\<langle>31,0\\<rangle>(read_mem \\<alpha> \\<sigma> 32 a) :: 32 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r32 := ucast (op1 - op2)),\n          flags := (flags \\<sigma>)\n          (flag_pf := parity (op1 - op2),\n           flag_cf := op2 > op1,\n           flag_zf := op1 = op2,\n           flag_sf := sint (op1 - op2) < 0,\n           flag_of := (sint(op2) \\<ge> 0 \\<and> 0 \\<le> sint (op1 - op2) \\<and> sint(op1) < 0)\n                      \\<or>\n                      (sint(op2) < 0 \\<and> sint (op1  - op2) < 0 \\<and> sint(op1) \\<ge> 0))\\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n    apply (rewrite_one_let')+\n    apply (intro state_eqI,simp_all)\n    apply (auto simp add:simp_rules)\n    apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:simp_rules parity_ucast)\n      done\n    subgoal for \\<sigma>\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32 :: 32 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"(\\<langle>31,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 32 a)) :: 32 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"(\\<langle>31,0\\<rangle>regs \\<sigma> r32 - \\<langle>31,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 32 a)) :: 32 word\"]\n    by (auto simp add: simp_rules test_bit_of_take_bits )\n  done\nqed\n\nlemma is_manual_sub_m32_r32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Sub) (Memory 32 a) (Storage (Reg (General ThirtyTwo r32)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_sub_m32_r32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Sub) (Memory 32 Mem) (Storage (Reg (General ThirtyTwo r32)))) si = \n             (\\<lambda> \\<sigma> . let a = resolve_address \\<alpha> \\<sigma> Mem;\n                        op1 = \\<langle>31,0\\<rangle>(read_mem \\<alpha> \\<sigma> 32 Mem) :: 32 word;\n                        op2 = \\<langle>31,0\\<rangle>regs \\<sigma> r32 :: 32 word\n               in\n        \\<sigma>\\<lparr>mem := write_blocks [a \\<rhd> rev (\\<lbrace>3,0\\<rbrace> (op1 - op2))] (mem \\<sigma>),\n          flags := (flags \\<sigma>)\n          (flag_pf := parity (op1 - op2),\n           flag_cf := op2 > op1,\n           flag_zf := op1 = op2,\n           flag_sf := sint (op1 - op2) < 0,\n           flag_of := (sint(op2) \\<ge> 0 \\<and> 0 \\<le> sint (op1 - op2) \\<and> sint(op1) < 0)\n                      \\<or>\n                      (sint(op2) < 0 \\<and> sint (op1  - op2) < 0 \\<and> sint(op1) \\<ge> 0))\\<rparr>)\"\nproof-\n  show ?thesis\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n    apply (rewrite_one_let')+\n    apply (intro state_eqI,simp_all)\n    apply (auto simp add:simp_rules resolve_address_after_update_flag)\n    apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:simp_rules parity_ucast)\n      done\n    subgoal for \\<sigma>\n      apply (subst add.commute[of \"ucast (NOT \\<langle>31,0\\<rangle>regs \\<sigma> r32)\"])\n      apply (subst sign_sub_bit32)\n      by auto\n    subgoal for \\<sigma>\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32 :: 32 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"(\\<langle>31,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 32 Mem)) :: 32 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"\\<langle>31,0\\<rangle>fst (read_memory \\<alpha> \\<sigma> 32 Mem) - (\\<langle>31,0\\<rangle>regs \\<sigma> r32) :: 32 word\"]\n    using sign_sub_bit32[where b=\"regs \\<sigma> r32\" and a=\"fst (read_memory \\<alpha> \\<sigma> 32 Mem)\"]\n    by (auto simp add: simp_rules test_bit_of_take_bits)\n  done\nqed\n\nlemma is_manual_sub_r32_r32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Sub) (Reg (General ThirtyTwo r32_1)) (Storage (Reg (General ThirtyTwo r32_2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_sub_r32_r32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Sub) (Reg (General ThirtyTwo r32_1)) (Storage (Reg (General ThirtyTwo r32_2)))) si = \n         (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r32_1 :: 32 word;\n                   op2 = \\<langle>31,0\\<rangle>regs \\<sigma> r32_2 :: 32 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r32_1 := ucast (op1 - op2) :: 64 word),\n          flags := (flags \\<sigma>)\n          (flag_pf := parity (op1 - op2),\n           flag_cf := op2 > op1,\n           flag_zf := op1 = op2,\n           flag_sf := sint (op1 - op2) < 0,\n           flag_of := (sint(op2) \\<ge> 0 \\<and> 0 \\<le> sint (op1 - op2) \\<and> sint(op1) < 0)\n                      \\<or>\n                      (sint(op2) < 0 \\<and> sint (op1  - op2) < 0 \\<and> sint(op1) \\<ge> 0))\\<rparr>)\"\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')+\n    apply (intro state_eqI,simp_all)\n    apply (auto simp add:simp_rules)\n    apply (intro flags_eqI,simp_all)\n    subgoal for \\<sigma>\n      apply (auto simp add:simp_rules parity_ucast)\n      done\n    subgoal for \\<sigma>\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32_2 :: 32 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32_1 :: 32 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"(\\<langle>31,0\\<rangle>regs \\<sigma> r32_1 - \\<langle>31,0\\<rangle>regs \\<sigma> r32_2) :: 32 word\"]\n    by (auto simp add: simp_rules test_bit_of_take_bits )\n  done\n\nlemma test_32b_of_32AND1000_word[get_semantics_rewriting]:\n  fixes a :: \"1000 word\"\n  shows \"(a :: 1000 word) !! 31 = (\\<langle>31,0\\<rangle>(a :: 1000 word) :: 32 word) !! 31\"\n  by (simp add: test_bit_of_take_bits)\n\nlemma is_manual_sub_r32_Imm32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Sub) (Reg (General ThirtyTwo r32_1)) (Immediate (ImmSixtyFour Imm32))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_sub_r32_Imm32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Sub) (Reg (General ThirtyTwo r32_1)) (Immediate (ImmSixtyFour Imm32))) si = \n         (\\<lambda> \\<sigma> . let op1 = \\<langle>31,0\\<rangle>regs \\<sigma> r32_1 :: 32 word;\n                   op2 = \\<langle>31,0\\<rangle>(word_of_int Imm32 :: 64 word) :: 32 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r32_1 := (ucast (op1 - op2 :: 32 word)) :: 64 word),\n          flags := (flags \\<sigma>)\n          (flag_pf := parity (op1 - op2),\n           flag_cf := op2 > op1,\n           flag_zf := op1 = op2,\n           flag_sf := sint (op1 - op2) < 0,\n           flag_of := (sint(op2) \\<ge> 0 \\<and> 0 \\<le> sint (op1 - op2) \\<and> sint(op1) < 0)\n                      \\<or>\n                      (sint(op2) < 0 \\<and> sint (op1  - op2) < 0 \\<and> sint(op1) \\<ge> 0))\\<rparr>)\"\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')+\n  apply (intro state_eqI,simp_all)\n  subgoal for \\<sigma>\n    apply (auto simp add:simp_rules)\n    done\n  apply (intro flags_eqI,simp_all)\n  subgoal for \\<sigma>\n    apply (auto simp add: simp_rules parity_ucast)\n    done\n  subgoal for \\<sigma>\n    apply (subst test_32b_of_32AND64_word[where ?a=\"regs \\<sigma> r32_1\"])\n     using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"\\<langle>31,0\\<rangle>word_of_int Imm32 :: 32 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"\\<langle>31,0\\<rangle>regs \\<sigma> r32_1 :: 32 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"(\\<langle>31,0\\<rangle>regs \\<sigma> r32_1 - \\<langle>31,0\\<rangle>word_of_int Imm32) :: 32 word\"]\n    by (auto simp add: simp_rules test_bit_of_take_bits )\n  done\n\nlemma test_64b_of_1000AND_take_64_word[get_semantics_rewriting]:\n  fixes a :: \"1000 word\"\n  shows \"(a :: 1000 word) !! 63 = (\\<langle>63,0\\<rangle>(a :: 1000 word) :: 64 word) !! 63\"\n  by (simp add: test_bit_of_take_bits)\n\nlemma is_manual_sub_r64_Imm32[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Sub) (Reg (General SixtyFour r64_1)) (Immediate (ImmSixtyFour Imm32))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_sub_r64_Imm32[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Sub) (Reg (General SixtyFour r64_1)) (Immediate (ImmSixtyFour Imm32))) si = \n         (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r64_1 :: 64 word;\n                   op2 = (word_of_int Imm32 :: 64 word)\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r64_1 := (op1 - op2 ) :: 64 word),\n          flags := (flags \\<sigma>)\n          (flag_pf := parity (op1 - op2),\n           flag_cf := op2 > op1,\n           flag_zf := op1 = op2,\n           flag_sf := sint (op1 - op2) < 0,\n           flag_of := (sint(op2) \\<ge> 0 \\<and> 0 \\<le> sint (op1 - op2) \\<and> sint(op1) < 0)\n                      \\<or>\n                      (sint(op2) < 0 \\<and> sint (op1  - op2) < 0 \\<and> sint(op1) \\<ge> 0))\\<rparr>)\"\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')+\n  apply (intro state_eqI,simp_all)\n\n  subgoal for \\<sigma>\n    apply (auto simp add:simp_rules useless_sextend_hardocded)\n    done\n  apply (intro flags_eqI,simp_all)\n  subgoal for \\<sigma>\n    unfolding bv_slice.simps\n    apply (auto simp add:ucast_bitNOT ucast_id)\n    done\n  subgoal for \\<sigma>\n    using overflow_sub_bit64[where ?a=\"regs \\<sigma> r64_1\" and ?b=\"word_of_int Imm32\"]\n    apply (auto simp add:simp_rules )\n    done\n  subgoal for \\<sigma>\n    unfolding bv_slice.simps\n    apply (auto simp add: simp_rules parity_ucast)\n    done\n  subgoal for \\<sigma> \n    using sign_sub_bit64[where ?a=\"regs \\<sigma> r64_1\" and ?b=\"word_of_int Imm32\", simplified]\n    apply (auto simp add:simp_rules)\n    done\n  subgoal for \\<sigma>\n    apply(subst test_64b_of_AND1000_word[symmetric, where ?w=\"regs \\<sigma> r64_1\"])\n    using sign_sub_bit64[where ?a=\"regs \\<sigma> r64_1\" and ?b=\"word_of_int Imm32\", simplified]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"word_of_int Imm32 :: 64 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"regs \\<sigma> r64_1 :: 64 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"(regs \\<sigma> r64_1 - word_of_int Imm32) :: 64 word\"]\n    apply (auto simp add:simp_rules)\n    using sub_overflow_flag64_bit[where ?b=\"word_of_int Imm32 :: 64 word\" and ?a=\"regs \\<sigma> r64_1\"]\n    by (auto simp add: word_msb_sint msb_nth test_bit_of_take_bits)\n    done\n\n\nlemma is_manual_sub_r64_r64[is_manual]:\n  shows \"is_manual assembly semantics (Binary (IS_8088 Sub) (Reg (General SixtyFour r64_1)) (Storage (Reg (General SixtyFour r64_2)))) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_sub_r64_r64[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Binary (IS_8088 Sub) (Reg (General SixtyFour r64_1)) (Storage (Reg (General SixtyFour r64_2)))) si = \n         (\\<lambda> \\<sigma> . let op1 = regs \\<sigma> r64_1 :: 64 word;\n                   op2 = regs \\<sigma> r64_2 :: 64 word\n               in\n        \\<sigma>\\<lparr>regs := (regs \\<sigma>)(r64_1 := (op1 - op2 ) :: 64 word),\n          flags := (flags \\<sigma>)\n          (flag_pf := parity (op1 - op2),\n           flag_cf := op2 > op1,\n           flag_zf := op1 = op2,\n           flag_sf := sint (op1 - op2) < 0,\n           flag_of := (sint(op2) \\<ge> 0 \\<and> 0 \\<le> sint (op1 - op2) \\<and> sint(op1) < 0)\n                      \\<or>\n                      (sint(op2) < 0 \\<and> sint (op1  - op2) < 0 \\<and> sint(op1) \\<ge> 0))\\<rparr>)\"\n  apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let' add: semantics_def)\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')\n  apply (rewrite_one_let')+\n  apply (intro state_eqI,simp_all)\n  subgoal for \\<sigma>\n    apply (auto simp add:simp_rules )\n    done\n  apply (intro flags_eqI,simp_all)\n  subgoal for \\<sigma>\n    unfolding bv_slice.simps\n    apply (auto simp add:ucast_bitNOT ucast_id)\n    done\n  subgoal for \\<sigma>\n    using overflow_sub_bit64[where ?a=\"regs \\<sigma> r64_1\" and ?b=\"regs \\<sigma> r64_2\"]\n    apply (auto simp add:simp_rules )\n    done\n  subgoal for \\<sigma>\n    unfolding bv_slice.simps\n    apply (auto simp add: simp_rules parity_ucast)\n    done\n  subgoal for \\<sigma> \n    using sign_sub_bit64[where ?a=\"regs \\<sigma> r64_1\" and ?b=\"regs \\<sigma> r64_2\", simplified]\n    apply (auto simp add:simp_rules)\n    done\n  subgoal for \\<sigma>\n    apply(subst test_64b_of_AND1000_word[symmetric, where ?w=\"regs \\<sigma> r64_1\"])\n    using sign_sub_bit64[where ?a=\"regs \\<sigma> r64_1\" and ?b=\"regs \\<sigma> r64_2\", simplified]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"regs \\<sigma> r64_2 :: 64 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"regs \\<sigma> r64_1 :: 64 word\"]\n    using word_msb_sint[symmetric, unfolded msb_nth, where ?w=\"(regs \\<sigma> r64_1 - regs \\<sigma> r64_2) :: 64 word\"]\n    apply (auto simp add:simp_rules)\n    using sub_overflow_flag64_bit[where ?b=\"regs \\<sigma> r64_2 :: 64 word\" and ?a=\"regs \\<sigma> r64_1\"]\n    by (auto simp add: word_msb_sint msb_nth test_bit_of_take_bits)\n    done\n\n\n\n\n(*---------------------------------------------------proofs on cdq  ---------------------------------------*)\nlemma is_manual_cdq[is_manual]:\n  shows \"is_manual assembly semantics (Nullary (IS_80386 Cdq)) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_cdq[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Nullary (IS_80386 Cdq)) si = \n             (\\<lambda> \\<sigma> . let op1 = EAX \\<sigma>\n               in\n                \\<sigma>\\<lparr>regs := (regs \\<sigma>)(rdx := ucast (if sint op1 \\<ge> 0 then 0 else -1 :: 32 word)) \\<rparr> )\"\n   apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n   apply (rewrite_one_let' add: semantics_def)\n   apply (rewrite_one_let')+\n   apply (intro state_eqI,simp_all)\n  subgoal premises prems for \\<sigma>\n  proof(cases \"(\\<langle>31,0\\<rangle>regs \\<sigma> rax :: 1000 word) !! 31\")\n    case True\n    hence \"EAX \\<sigma> !! 31\"\n      by (auto simp add: test_bit_of_take_bits)      \n    hence False\n      using word_msb_sint[of \"EAX \\<sigma>\"] prems\n      by (auto simp add: msb_nth)\n    thus ?thesis\n      by simp\n  next\n    case False\n    have \"\\<langle>31,32\\<rangle>regs \\<sigma> rax = (0::64 word)\"\n      apply (intro word_eqI)\n      by (auto simp add: word_size test_bit_of_take_bits)\n    thus ?thesis\n      using False\n      by (auto simp add: simp_rules bv_slice.simps sextend.simps bv_cat'_def)[1]\n  qed\n  apply (rewrite_one_let') \n   apply (rewrite_one_let' add: semantics_def)\n   apply (rewrite_one_let')+\n   apply (intro state_eqI,simp_all)\n  subgoal premises prems for \\<sigma>\n  proof(cases \"(\\<langle>31,0\\<rangle>regs \\<sigma> rax :: 1000 word) !! 31\")\n    case True\n    have 1: \"\\<And> a b . a = b \\<Longrightarrow> (regs \\<sigma>)(rdx := a) = (regs \\<sigma>)(rdx := b)\"\n      by auto\n    thus ?thesis\n      using True\n      apply (auto simp add: simp_rules bv_slice.simps sextend.simps bv_cat'_def)[1]\n      apply (rule 1)\n      apply (intro word_eqI)\n      subgoal for n\n      apply (cases\"n=0\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)\n      apply (cases\"n=1\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=2\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=3\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=4\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=5\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=6\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=7\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=8\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=9\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=10\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=11\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=12\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=13\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=14\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=15\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=16\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=17\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=18\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=19\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=20\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=21\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=21\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=21\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=22\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=23\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=24\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=25\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=26\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=27\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=28\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=29\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=30\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=31\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n        apply unat_arith\n      apply (cases\"n=0\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)\n      apply (cases\"n=1\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=2\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=3\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=4\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=5\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=6\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=7\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=8\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=9\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=10\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=11\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=12\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=13\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=14\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=15\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=16\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=17\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=18\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=19\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=20\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=21\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=21\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=21\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=22\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=23\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=24\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=25\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=26\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=27\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=28\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=29\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=30\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n      apply (cases\"n=31\", auto simp add: word_size test_bit_of_take_bits word_ao_nth nth_ucast)  \n        apply unat_arith\n        done\n      done\n  next\n    case False\n    hence \"\\<not>EAX \\<sigma> !! 31\"\n      by (auto simp add: test_bit_of_take_bits)      \n    hence False\n      using word_msb_sint[of \"EAX \\<sigma>\"] prems\n      by (auto simp add: msb_nth)\n    thus ?thesis\n      by simp\n  qed\n  done\n\n(*---------------------------------------------------proofs on cdqe  ---------------------------------------*)\nlemma is_manual_cdqe[is_manual]:\n  shows \"is_manual assembly semantics (Nullary (IS_X86_64 Cdqe)) = False\"\n  by (auto simp add: is_manual_def Let'_def simp_rules unfold_semantics)\n\nlemma get_semantics_cdqe[presimplify]:\n  shows \"get_semantics \\<alpha> semantics (Nullary (IS_X86_64 Cdqe)) si = \n             (\\<lambda> \\<sigma> . let op1 = EAX \\<sigma>\n               in\n                \\<sigma>\\<lparr>regs := (regs \\<sigma>)(rax := sextend (ucast op1) 32 64) \\<rparr> )\"\n   apply (rule ext)\n  apply (subst get_semantics_def)\n  apply (rewrite_one_let') \n   apply (rewrite_one_let' add: semantics_def)\n   apply (rewrite_one_let')+\n   apply (intro state_eqI,simp_all add: set_def)\n      apply (auto simp add: simp_rules sextend.simps)[1]\n  done\n\n\n\nthm is_manual\nthm presimplify\n\nend\nend\n", "meta": {"author": "ssrg-vt", "repo": "Luce-src", "sha": "f7f1ef0fd07bba48bcb3d5e32404db6013a5f1bc", "save_path": "github-repos/isabelle/ssrg-vt-Luce-src", "path": "github-repos/isabelle/ssrg-vt-Luce-src/Luce-src-f7f1ef0fd07bba48bcb3d5e32404db6013a5f1bc/safecomp2019_artifact/current_work/isabelle/Presimplified_Semantics.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5273165382362517, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.2821662509990428}}
{"text": "theory doc\n  imports \"repliss_sem\"\n    \"repliss_sem_single_invocation\"\n    \"HOL-Library.OptionalSugar\"\n    unique_ids\nbegin\n\nsection \"Document Snippets\"\n\n\nnotation (tab output)\n  \"HOL.eq\"  (\"(_) = (1_)\" [50,49] 50) and\n  \"Pure.eq\"  (\"(_) \\<equiv> (1_)\" [1,1] 2)\n\n\ntext \\<open>\n\\DefineSnippet{local}{\n  @{thm [display] repliss_sem.local}\n}%EndSnippet\n\n\\DefineSnippet{newId}{\n  @{thm [display] repliss_sem.newId}\n}%EndSnippet\n\n\\DefineSnippet{beginAtomic}{\n  @{thm [display] repliss_sem.beginAtomic}\n}%EndSnippet\n\n\\DefineSnippet{endAtomic}{\n  @{thm [display] repliss_sem.endAtomic}\n}%EndSnippet\n\n\\DefineSnippet{dbop}{\n  @{thm [display] repliss_sem.dbop}\n}%EndSnippet\n\n\\DefineSnippet{invocation}{\n  @{thm [display] repliss_sem.invocation}\n}%EndSnippet\n\n\\DefineSnippet{return}{\n  @{thm [display] repliss_sem.return}\n}%EndSnippet\n\n\\DefineSnippet{crash}{\n  @{thm [display] repliss_sem.crash}\n}%EndSnippet\n\n\\DefineSnippet{invCheck}{\n  @{thm [display] repliss_sem.invCheck}\n}%EndSnippet\n\n\n\\<close>\n\n\n\ntext \\<open>\n\\DefineSnippet{s_local}{\n  @{thm [display] repliss_sem_single_invocation.local}\n}%EndSnippet\n\n\\DefineSnippet{s_newId}{\n  @{thm [display] repliss_sem_single_invocation.newId}\n}%EndSnippet\n\n\\DefineSnippet{s_beginAtomic}{\n  @{thm [display] repliss_sem_single_invocation.beginAtomic[unfolded atomize_all]}\n}%EndSnippet\n\n\\DefineSnippet{s_endAtomic}{\n  @{thm [display] repliss_sem_single_invocation.endAtomic}\n}%EndSnippet\n\n\\DefineSnippet{s_dbop}{\n  @{thm [display] repliss_sem_single_invocation.dbop}\n}%EndSnippet\n\n\\DefineSnippet{s_invocation}{\n  @{thm [display] repliss_sem_single_invocation.invocation[unfolded atomize_all]}\n}%EndSnippet\n\n\\DefineSnippet{s_return}{\n  @{thm [display] repliss_sem_single_invocation.return}\n}%EndSnippet\n\n\\<close>\n\ntext \\<open>\n\\DefineSnippet{traces}{\n  @{thm [display] traces_def}\n}%EndSnippet\n\n\\DefineSnippet{actionCorrect_def}{\n  @{thm [display] actionCorrect_def}\n}%EndSnippet\n\n\\DefineSnippet{traceCorrect}{\n  @{thm [display] traceCorrect_def}\n}%EndSnippet\n\n\n\\DefineSnippet{programCorrect}{\n  @{thm [display] programCorrect_def}\n}%EndSnippet\n\n\n\\<close>\n\nschematic_goal getContext_def: \"visibleCalls S i \\<triangleq> vis \\<Longrightarrow> getContext S i = ?x\"\n  unfolding getContextH_def\n  by auto\n\n\ntext \\<open>\\DefineSnippet{getContext_def}{\n  @{thm [display] getContext_def}\n}%EndSnippet\\<close>\n\n\ntext \\<open>\\DefineSnippet{getContext_def_prem}{\n  @{thm [display] (prem 1) getContext_def}\n}%EndSnippet\\<close>\n\n\ntext \\<open>\\DefineSnippet{getContext_def_concl}{\n  @{thm  [display] (concl) getContext_def}\n}%EndSnippet\\<close>\n\n\nschematic_goal invariant_all_def: \"invariant_all S = ?x\"\n  unfolding invContextH_def\n  by simp\n\ntext \\<open>\\DefineSnippet{invariant_all_def}{\n  @{thm [display] invariant_all_def}\n}%EndSnippet\\<close>\n\nlemma committedCalls_def: \"committedCalls S = {c. \\<exists>tx. callOrigin S c \\<triangleq> tx \\<and> txStatus S tx \\<triangleq> Committed}\"\n  unfolding committedCallsH_def isCommittedH_def\n  by simp\n\n\ntext \\<open>\\DefineSnippet{committedCalls_def}{\n  @{thm [display] committedCalls_def}\n}%EndSnippet\\<close>\n\n\ntext \\<open>\\DefineSnippet{traceCorrect_s_def}{\n  @{thm [display] traceCorrect_s_def}\n}%EndSnippet\\<close>\n\n\ntext \\<open>\\DefineSnippet{programCorrect_s_def}{\n  @{thm [display] programCorrect_s_def}\n}%EndSnippet\\<close>\n\n\ntext \\<open>\\DefineSnippet{steps_s_refl}{\n  @{thm [display] steps_s_refl}\n}%EndSnippet\\<close>\n\ntext \\<open>\\DefineSnippet{steps_s_step}{\n  @{thm [display] steps_s_step}\n}%EndSnippet\\<close>\n\n\ntext \\<open>\\DefineSnippet{state_monotonicGrowth_def}{\n  @{thm [display] state_monotonicGrowth_def}\n}%EndSnippet\\<close>\n\n\n\ntext \\<open>\\DefineSnippet{program_wellFormed_def}{\n  @{thm [display] program_wellFormed_def}\n}%EndSnippet\\<close>\n\n\n\ntext \\<open>\\DefineSnippet{invocations_cannot_guess_ids_def}{\n  @{thm [display] invocations_cannot_guess_ids_def}\n}%EndSnippet\\<close>\n\ntext \\<open>\\DefineSnippet{invocations_cannot_guess_ids_def2}{\n  @{thm [display] invocations_cannot_guess_ids_def2}\n}%EndSnippet\\<close>\n\ntext \\<open>\\DefineSnippet{invocation_cannot_guess_ids_def}{\n  @{thm [display] invocation_cannot_guess_ids_def}\n}%EndSnippet\\<close>\n\ntext \\<open>\\DefineSnippet{trace_outputs_def}{\n  @{thm [display] trace_outputs_def}\n}%EndSnippet\\<close>\n\ntext \\<open>\\DefineSnippet{action_outputs_simps}{\n  @{thm [display] action_outputs.simps}\n}%EndSnippet\\<close>\n\ntext \\<open>\\DefineSnippet{trace_inputs_def}{\n  @{thm [display] trace_inputs_def}\n}%EndSnippet\\<close>\n\ntext \\<open>\\DefineSnippet{action_inputs_simps}{\n  @{thm [display] action_inputs.simps}\n}%EndSnippet\\<close>\n\ntext \\<open>\\DefineSnippet{queries_cannot_guess_ids_def}{\n  @{thm [display] queries_cannot_guess_ids_def}\n}%EndSnippet\\<close>\n\ntext \\<open>\\DefineSnippet{query_cannot_guess_ids_def}{\n  @{thm [display] query_cannot_guess_ids_def}\n}%EndSnippet\\<close>\n\ntext \\<open>\\DefineSnippet{queries_cannot_guess_ids_def2}{\n  @{thm [display] queries_cannot_guess_ids_def2}\n}%EndSnippet\\<close>\n\n\n\nend", "meta": {"author": "peterzeller", "repo": "repliss-isabelle", "sha": "f43744678cc9c5a4684e8bd0e9c83510bae1d9a4", "save_path": "github-repos/isabelle/peterzeller-repliss-isabelle", "path": "github-repos/isabelle/peterzeller-repliss-isabelle/repliss-isabelle-f43744678cc9c5a4684e8bd0e9c83510bae1d9a4/doc.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.5350984286266116, "lm_q1q2_score": 0.2821662430492543}}
{"text": "section {* Host Properties *}\n\ntheory Wasm_Axioms imports Wasm begin\n\nlemma old_mem_size_def:\n  shows \"mem_size m = length (fst (Rep_mem m)) div Ki64\"\n  unfolding mem_size_def mem_length_def\n  by (simp split: prod.splits)\n\n(* these were originally axioms, but memory now has a concrete representation in the model *)\nlemma mem_grow_size:\n  assumes \"mem_grow m n = Some m'\"\n  shows \"(mem_size m + n) = mem_size m'\"\n  using assms Abs_mem_inverse\n  unfolding mem_grow_def old_mem_size_def mem_append_def bytes_replicate_def\n  by (auto simp add: Ki64_def Let_def split: prod.splits if_splits)\n\nlemma mem_grow_max1:\n  assumes \"mem_grow m n = Some m'\"\n  shows \"mem_max m = mem_max m'\"\n  using assms Abs_mem_inverse\n  unfolding mem_grow_def mem_max_def mem_append_def \n  by (auto simp add: Ki64_def Let_def split: prod.splits if_splits)\n\nlemma mem_grow_max2:\n  assumes \"mem_grow m n = Some m'\"\n  shows \"pred_option ((\\<le>) (mem_size m')) (mem_max m')\"\n  using assms Abs_mem_inverse\n  unfolding mem_grow_def mem_max_def mem_append_def\n  by (auto simp add: assms mem_grow_size Let_def split: prod.splits if_splits)\n\nlemma mem_grow_length:\n  assumes \"mem_grow m n = Some m'\"\n  shows \"(mem_length m + (n * Ki64)) = mem_length m'\"\n  using assms Abs_mem_inverse\n        bytes_replicate_def mem_append.rep_eq mem_length.rep_eq\n  unfolding mem_grow_def old_mem_size_def mem_append_def bytes_replicate_def\n  by (auto simp add: Let_def split: prod.splits if_splits)\n\nlemma mem_grow_byte_at_m:\n  assumes \"k < mem_length m\"\n          \"(mem_grow m n) = Some m'\"\n  shows \"byte_at m' k = byte_at m k\"\n  using assms\n  unfolding byte_at.rep_eq mem_length.rep_eq mem_grow_def mem_append.rep_eq mem_append_def\n  by (auto simp add: Abs_mem_inverse nth_append Let_def split: prod.splits if_splits)\n\nlemma mem_grow_byte_at_m_n:\n  assumes \"k \\<ge> mem_length m\"\n          \"(mem_grow m n) = Some m'\"\n          \"k < mem_length m'\"\n  shows \"byte_at m' k = (0::byte)\"\n  using assms\n  unfolding byte_at.rep_eq mem_length.rep_eq mem_grow_def mem_append.rep_eq bytes_replicate_def mem_append_def\n  by (auto simp add: Abs_mem_inverse nth_append Let_def split: prod.splits if_splits)\n\nlemma load_size:\n  \"(load m n off l = None) = (mem_length m < (off + n + l))\"\n  unfolding load_def\n  by (cases \"n + off + l \\<le> mem_length m\") auto\n\nlemma load_packed_size:\n  \"(load_packed sx m n off lp l = None) = (mem_length m < (off + n + lp))\"\n  using load_size\n  unfolding load_packed_def\n  by (cases \"n + off + l \\<le> mem_length m\") auto  \n\nlemma store_size1:\n  \"(store m n off v l = None) = (mem_length m < (off + n + l))\"\n  unfolding store_def\n  by (cases \"n + off + l \\<le> mem_length m\") auto\n\nlemma store_size:\n  assumes \"(store m n off v l = Some m')\"\n  shows \"mem_size m = mem_size m'\"\n  using assms Abs_mem_inverse mem_length.rep_eq\n  unfolding store_def write_bytes_def bytes_takefill_def\n  by (cases \"n + off + l \\<le> mem_length m\") (auto simp add: old_mem_size_def split: prod.splits)\n\nlemma store_max:\n  assumes \"(store m n off v l = Some m')\"\n  shows \"mem_max m = mem_max m'\"\n  using assms Abs_mem_inverse\n  unfolding store_def mem_max.rep_eq write_bytes_def\n  by (auto split: if_splits prod.splits)\n\nlemma store_length:\n  assumes \"(store m n off v l = Some m')\"\n  shows \"mem_length m = mem_length m'\"\n  using assms Abs_mem_inverse mem_length.rep_eq\n  unfolding store_def write_bytes_def bytes_takefill_def\n  by (cases \"n + off + l \\<le> mem_length m\") (auto split: prod.splits)\n\nlemma store_packed_size1:\n  \"(store_packed m n off v l = None) = (mem_length m < (off + n + l))\"\n  using store_size1\n  unfolding store_packed_def\n  by simp\n\nlemma store_packed_size:\n  assumes \"(store_packed m n off v l = Some m')\"\n  shows \"mem_size m = mem_size m'\"\n  using assms store_size\n  unfolding store_packed_def\n  by simp\n\nlemma store_packed_max:\n  assumes \"(store_packed m n off v l = Some m')\"\n  shows \"mem_max m = mem_max m'\"\n  using assms store_max\n  unfolding store_packed_def\n  by simp\n\naxiomatization where\n  wasm_deserialise_type:\"typeof (wasm_deserialise bs t) = t\"\n\naxiomatization where\n    host_apply_preserve_store1:\"host_apply s (t1s _> t2s) f vs hs = Some (s', vs') \\<Longrightarrow> store_extension s s'\"\nand host_apply_preserve_store2:\"host_apply s (t1s _> t2s) f vs hs = Some (s', vs') \\<Longrightarrow> store_typing s \\<Longrightarrow> store_typing s'\"\nand host_apply_respect_type:\"list_all2 types_agree t1s vs \\<Longrightarrow> host_apply s (t1s _> t2s) f vs hs = Some (s', vs') \\<Longrightarrow> list_all2 types_agree t2s vs'\"\n\nlemma host_apply_preserve_store:\n  assumes \"host_apply s (t1s _> t2s) f vs hs = Some (s', vs')\"\n          \"store_typing s\"\n  shows \"store_extension s s' \\<and> store_typing s'\"\n  using assms host_apply_preserve_store1 host_apply_preserve_store2\n  by blast\n\nend", "meta": {"author": "conrad-watt", "repo": "wasm-pl-isabelle", "sha": "265f292250c01770d50d4ecda998ed5961c6719e", "save_path": "github-repos/isabelle/conrad-watt-wasm-pl-isabelle", "path": "github-repos/isabelle/conrad-watt-wasm-pl-isabelle/wasm-pl-isabelle-265f292250c01770d50d4ecda998ed5961c6719e/WebAssembly/Wasm_Axioms.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6224593171945417, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.2821370604259934}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory longlong\nimports \"CParser.CTranslation\"\nbegin\n\nexternal_file \"longlong.c\"\ninstall_C_file \"longlong.c\"\n\nML \\<open>NameGeneration.return_var_name (Absyn.Signed Absyn.LongLong)\\<close>\n\n\ncontext longlong\nbegin\n\nthm f_body_def\nthm shifts1_body_def\nthm shifts2_body_def\n\nlemma \"(ucast :: 16 word \\<Rightarrow> 8 word) 32768 = 0\"\napply simp\ndone\n\nlemma \"(scast :: 16 word \\<Rightarrow> 8 word) 32768 = 0\"\nby simp\n\nlemma \"(scast :: 16 word \\<Rightarrow> 8 word) 65535 = 255\"\nby simp\n\nlemma \"(ucast :: 16 word \\<Rightarrow> 8 word) 65535 = 255\"\nby simp\n\nlemma \"(ucast :: 16 word \\<Rightarrow> 8 word) 32767 = 255\" by simp\nlemma \"(scast :: 16 word \\<Rightarrow> 8 word) 32767 = 255\" by simp\n\nlemma \"(scast :: 8 word \\<Rightarrow> 16 word) 255 = 65535\" by simp\nlemma \"(ucast :: 8 word \\<Rightarrow> 16 word) 255 = 255\" by simp\n\nlemma g_result:\n  \"\\<Gamma> \\<turnstile> \\<lbrace> True \\<rbrace> \\<acute>ret__int :== CALL callg() \\<lbrace> \\<acute>ret__int = 0 \\<rbrace>\"\napply vcg\napply (simp add: max_word_def)\ndone\n\nthm literals_body_def\n\nlemma literals_result:\n  \"\\<Gamma> \\<turnstile> \\<lbrace> True \\<rbrace> \\<acute>ret__int :== CALL literals() \\<lbrace> \\<acute>ret__int = 31 \\<rbrace>\"\napply vcg\napply simp\ndone\n\nend (* context *)\n\nend (* theory *)\n", "meta": {"author": "NICTA", "repo": "l4v", "sha": "3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b", "save_path": "github-repos/isabelle/NICTA-l4v", "path": "github-repos/isabelle/NICTA-l4v/l4v-3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b/tools/c-parser/testfiles/longlong.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.523420348936324, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.28211478544317137}}
{"text": "(*\n(C) Copyright Andreas Viktor Hess, DTU, 2018-2020\n(C) Copyright Sebastian A. Mödersheim, DTU, 2018-2020\n(C) Copyright Achim D. Brucker, University of Sheffield, 2018-2020\n\nAll Rights Reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\n- Redistributions of source code must retain the above copyright\n  notice, this list of conditions and the following disclaimer.\n\n- Redistributions in binary form must reproduce the above copyright\n  notice, this list of conditions and the following disclaimer in the\n  documentation and/or other materials provided with the distribution.\n\n- Neither the name of the copyright holder nor the names of its\n  contributors may be used to endorse or promote products\n  derived from this software without specific prior written\n  permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\nLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\nA PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\nOWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\nLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\nTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n*)\n\n(*  Title:      Labeled_Strands.thy\n    Author:     Andreas Viktor Hess, DTU\n    Author:     Sebastian A. Mödersheim, DTU\n    Author:     Achim D. Brucker, The University of Sheffield\n*)\n\nsection \\<open>Labeled Strands\\<close>\ntheory Labeled_Strands\nimports Strands_and_Constraints\nbegin\n\nsubsection \\<open>Definitions: Labeled Strands and Constraints\\<close>\ndatatype 'l strand_label =\n  LabelN (the_LabelN: \"'l\") (\"ln _\")\n| LabelS (\"\\<star>\")\n\ntext \\<open>Labeled strands are strands whose steps are equipped with labels\\<close>\ntype_synonym ('a,'b,'c) labeled_strand_step = \"'c strand_label \\<times> ('a,'b) strand_step\"\ntype_synonym ('a,'b,'c) labeled_strand = \"('a,'b,'c) labeled_strand_step list\"\n\nabbreviation is_LabelN where \"is_LabelN n x \\<equiv> fst x = ln n\"\nabbreviation is_LabelS where \"is_LabelS x \\<equiv> fst x = \\<star>\"\n\ndefinition unlabel where \"unlabel S \\<equiv> map snd S\"\ndefinition proj where \"proj n S \\<equiv> filter (\\<lambda>s. is_LabelN n s \\<or> is_LabelS s) S\"\nabbreviation proj_unl where \"proj_unl n S \\<equiv> unlabel (proj n S)\"\n\nabbreviation wfrestrictedvars\\<^sub>l\\<^sub>s\\<^sub>t where \"wfrestrictedvars\\<^sub>l\\<^sub>s\\<^sub>t S \\<equiv> wfrestrictedvars\\<^sub>s\\<^sub>t (unlabel S)\"\n\nabbreviation subst_apply_labeled_strand_step (infix \"\\<cdot>\\<^sub>l\\<^sub>s\\<^sub>t\\<^sub>p\" 51) where\n  \"x \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>t\\<^sub>p \\<theta> \\<equiv> (case x of (l, s) \\<Rightarrow> (l, s \\<cdot>\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>))\"\n\nabbreviation subst_apply_labeled_strand (infix \"\\<cdot>\\<^sub>l\\<^sub>s\\<^sub>t\" 51) where\n  \"S \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>t \\<theta> \\<equiv> map (\\<lambda>x. x \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) S\"\n\nabbreviation trms\\<^sub>l\\<^sub>s\\<^sub>t where \"trms\\<^sub>l\\<^sub>s\\<^sub>t S \\<equiv> trms\\<^sub>s\\<^sub>t (unlabel S)\"\nabbreviation trms_proj\\<^sub>l\\<^sub>s\\<^sub>t where \"trms_proj\\<^sub>l\\<^sub>s\\<^sub>t n S \\<equiv> trms\\<^sub>s\\<^sub>t (proj_unl n S)\"\n\nabbreviation vars\\<^sub>l\\<^sub>s\\<^sub>t where \"vars\\<^sub>l\\<^sub>s\\<^sub>t S \\<equiv> vars\\<^sub>s\\<^sub>t (unlabel S)\"\nabbreviation vars_proj\\<^sub>l\\<^sub>s\\<^sub>t where \"vars_proj\\<^sub>l\\<^sub>s\\<^sub>t n S \\<equiv> vars\\<^sub>s\\<^sub>t (proj_unl n S)\"\n\nabbreviation bvars\\<^sub>l\\<^sub>s\\<^sub>t where \"bvars\\<^sub>l\\<^sub>s\\<^sub>t S \\<equiv> bvars\\<^sub>s\\<^sub>t (unlabel S)\"\nabbreviation fv\\<^sub>l\\<^sub>s\\<^sub>t where \"fv\\<^sub>l\\<^sub>s\\<^sub>t S \\<equiv> fv\\<^sub>s\\<^sub>t (unlabel S)\"\n\nabbreviation wf\\<^sub>l\\<^sub>s\\<^sub>t where \"wf\\<^sub>l\\<^sub>s\\<^sub>t V S \\<equiv> wf\\<^sub>s\\<^sub>t V (unlabel S)\"\n\n\nsubsection \\<open>Lemmata: Projections\\<close>\nlemma is_LabelS_proj_iff_not_is_LabelN:\n  \"list_all is_LabelS (proj l A) \\<longleftrightarrow> \\<not>list_ex (is_LabelN l) A\"\nby (induct A) (auto simp add: proj_def)\n\nlemma proj_subset_if_no_label:\n  assumes \"\\<not>list_ex (is_LabelN l) A\"\n  shows \"set (proj l A) \\<subseteq> set (proj l' A)\"\n    and \"set (proj_unl l A) \\<subseteq> set (proj_unl l' A)\"\nusing assms by (induct A) (auto simp add: unlabel_def proj_def)\n\nlemma proj_in_setD:\n  assumes a: \"a \\<in> set (proj l A)\"\n  obtains k b where \"a = (k, b)\" \"k = (ln l) \\<or> k = \\<star>\"\nusing that a unfolding proj_def by (cases a) auto\n\nlemma proj_set_mono:\n  assumes \"set A \\<subseteq> set B\"\n  shows \"set (proj n A) \\<subseteq> set (proj n B)\"\n    and \"set (proj_unl n A) \\<subseteq> set (proj_unl n B)\"\nusing assms unfolding proj_def unlabel_def by auto\n\nlemma unlabel_nil[simp]: \"unlabel [] = []\"\nby (simp add: unlabel_def)\n\nlemma unlabel_mono: \"set A \\<subseteq> set B \\<Longrightarrow> set (unlabel A) \\<subseteq> set (unlabel B)\"\nby (auto simp add: unlabel_def)\n\nlemma unlabel_in: \"(l,x) \\<in> set A \\<Longrightarrow> x \\<in> set (unlabel A)\"\nunfolding unlabel_def by force\n\nlemma unlabel_mem_has_label: \"x \\<in> set (unlabel A) \\<Longrightarrow> \\<exists>l. (l,x) \\<in> set A\"\nunfolding unlabel_def by auto\n\nlemma proj_nil[simp]: \"proj n [] = []\" \"proj_unl n [] = []\"\nunfolding unlabel_def proj_def by auto\n\nlemma singleton_lst_proj[simp]:\n  \"proj_unl l [(ln l, a)] = [a]\"\n  \"l \\<noteq> l' \\<Longrightarrow> proj_unl l' [(ln l, a)] = []\"\n  \"proj_unl l [(\\<star>, a)] = [a]\"\n  \"unlabel [(l'', a)] = [a]\"\nunfolding proj_def unlabel_def by simp_all\n\nlemma unlabel_nil_only_if_nil[simp]: \"unlabel A = [] \\<Longrightarrow> A = []\"\nunfolding unlabel_def by auto\n\nlemma unlabel_Cons[simp]:\n  \"unlabel ((l,a)#A) = a#unlabel A\"\n  \"unlabel (b#A) = snd b#unlabel A\"\nunfolding unlabel_def by simp_all\n\nlemma unlabel_append[simp]: \"unlabel (A@B) = unlabel A@unlabel B\"\nunfolding unlabel_def by auto\n\nlemma proj_Cons[simp]:\n  \"proj n ((ln n,a)#A) = (ln n,a)#proj n A\"\n  \"proj n ((\\<star>,a)#A) = (\\<star>,a)#proj n A\"\n  \"m \\<noteq> n \\<Longrightarrow> proj n ((ln m,a)#A) = proj n A\"\n  \"l = (ln n) \\<Longrightarrow> proj n ((l,a)#A) = (l,a)#proj n A\"\n  \"l = \\<star> \\<Longrightarrow> proj n ((l,a)#A) = (l,a)#proj n A\"\n  \"fst b \\<noteq> \\<star> \\<Longrightarrow> fst b \\<noteq> (ln n) \\<Longrightarrow> proj n (b#A) = proj n A\"\nunfolding proj_def by auto\n\nlemma proj_append[simp]:\n  \"proj l (A'@B') = proj l A'@proj l B'\"\n  \"proj_unl l (A@B) = proj_unl l A@proj_unl l B\"\nunfolding proj_def unlabel_def by auto\n\nlemma proj_unl_cons[simp]:\n  \"proj_unl l ((ln l, a)#A) = a#proj_unl l A\"\n  \"l \\<noteq> l' \\<Longrightarrow> proj_unl l' ((ln l, a)#A) = proj_unl l' A\"\n  \"proj_unl l ((\\<star>, a)#A) = a#proj_unl l A\"\nunfolding proj_def unlabel_def by simp_all\n\nlemma trms_unlabel_proj[simp]:\n  \"trms\\<^sub>s\\<^sub>t\\<^sub>p (snd (ln l, x)) \\<subseteq> trms_proj\\<^sub>l\\<^sub>s\\<^sub>t l [(ln l, x)]\"\nby auto\n\nlemma trms_unlabel_star[simp]:\n  \"trms\\<^sub>s\\<^sub>t\\<^sub>p (snd (\\<star>, x)) \\<subseteq> trms_proj\\<^sub>l\\<^sub>s\\<^sub>t l [(\\<star>, x)]\"\nby auto\n\nlemma trms\\<^sub>l\\<^sub>s\\<^sub>t_union[simp]: \"trms\\<^sub>l\\<^sub>s\\<^sub>t A = (\\<Union>l. trms_proj\\<^sub>l\\<^sub>s\\<^sub>t l A)\"\nproof (induction A)\n  case (Cons a A)\n  obtain l s where ls: \"a = (l,s)\" by moura\n  have \"trms\\<^sub>l\\<^sub>s\\<^sub>t [a] = (\\<Union>l. trms_proj\\<^sub>l\\<^sub>s\\<^sub>t l [a])\"\n  proof -\n    have *: \"trms\\<^sub>l\\<^sub>s\\<^sub>t [a] = trms\\<^sub>s\\<^sub>t\\<^sub>p s\" using ls by simp\n    show ?thesis\n    proof (cases l)\n      case (LabelN n)\n      hence \"trms_proj\\<^sub>l\\<^sub>s\\<^sub>t n [a] = trms\\<^sub>s\\<^sub>t\\<^sub>p s\" using ls by simp\n      moreover have \"\\<forall>m. n \\<noteq> m \\<longrightarrow> trms_proj\\<^sub>l\\<^sub>s\\<^sub>t m [a] = {}\" using ls LabelN by auto\n      ultimately show ?thesis using * ls by fastforce\n    next\n      case LabelS\n      hence \"\\<forall>l. trms_proj\\<^sub>l\\<^sub>s\\<^sub>t l [a] = trms\\<^sub>s\\<^sub>t\\<^sub>p s\" using ls by auto\n      thus ?thesis using * ls by fastforce\n    qed\n  qed\n  moreover have \"\\<forall>l. trms_proj\\<^sub>l\\<^sub>s\\<^sub>t l (a#A) = trms_proj\\<^sub>l\\<^sub>s\\<^sub>t l [a] \\<union> trms_proj\\<^sub>l\\<^sub>s\\<^sub>t l A\"\n    unfolding unlabel_def proj_def by auto\n  hence \"(\\<Union>l. trms_proj\\<^sub>l\\<^sub>s\\<^sub>t l (a#A)) = (\\<Union>l. trms_proj\\<^sub>l\\<^sub>s\\<^sub>t l [a]) \\<union> (\\<Union>l. trms_proj\\<^sub>l\\<^sub>s\\<^sub>t l A)\" by auto\n  ultimately show ?case using Cons.IH ls by auto\nqed simp\n\nlemma trms\\<^sub>l\\<^sub>s\\<^sub>t_append[simp]: \"trms\\<^sub>l\\<^sub>s\\<^sub>t (A@B) = trms\\<^sub>l\\<^sub>s\\<^sub>t A \\<union> trms\\<^sub>l\\<^sub>s\\<^sub>t B\"\nby (metis trms\\<^sub>s\\<^sub>t_append unlabel_append)\n\nlemma trms_proj\\<^sub>l\\<^sub>s\\<^sub>t_append[simp]: \"trms_proj\\<^sub>l\\<^sub>s\\<^sub>t l (A@B) = trms_proj\\<^sub>l\\<^sub>s\\<^sub>t l A \\<union> trms_proj\\<^sub>l\\<^sub>s\\<^sub>t l B\"\nby (metis (no_types, lifting) filter_append proj_def trms\\<^sub>l\\<^sub>s\\<^sub>t_append)\n\nlemma trms_proj\\<^sub>l\\<^sub>s\\<^sub>t_subset[simp]:\n  \"trms_proj\\<^sub>l\\<^sub>s\\<^sub>t l A \\<subseteq> trms_proj\\<^sub>l\\<^sub>s\\<^sub>t l (A@B)\"\n  \"trms_proj\\<^sub>l\\<^sub>s\\<^sub>t l B \\<subseteq> trms_proj\\<^sub>l\\<^sub>s\\<^sub>t l (A@B)\"\nusing trms_proj\\<^sub>l\\<^sub>s\\<^sub>t_append[of l] by blast+\n\nlemma trms\\<^sub>l\\<^sub>s\\<^sub>t_subset[simp]:\n  \"trms\\<^sub>l\\<^sub>s\\<^sub>t A \\<subseteq> trms\\<^sub>l\\<^sub>s\\<^sub>t (A@B)\"\n  \"trms\\<^sub>l\\<^sub>s\\<^sub>t B \\<subseteq> trms\\<^sub>l\\<^sub>s\\<^sub>t (A@B)\"\nproof (induction A)\n  case (Cons a A)\n  obtain l s where *: \"a = (l,s)\" by moura\n  { case 1 thus ?case using Cons * by auto }\n  { case 2 thus ?case using Cons * by auto }\nqed simp_all\n\nlemma vars\\<^sub>l\\<^sub>s\\<^sub>t_union: \"vars\\<^sub>l\\<^sub>s\\<^sub>t A = (\\<Union>l. vars_proj\\<^sub>l\\<^sub>s\\<^sub>t l A)\"\nproof (induction A)\n  case (Cons a A)\n  obtain l s where ls: \"a = (l,s)\" by moura\n  have \"vars\\<^sub>l\\<^sub>s\\<^sub>t [a] = (\\<Union>l. vars_proj\\<^sub>l\\<^sub>s\\<^sub>t l [a])\"\n  proof -\n    have *: \"vars\\<^sub>l\\<^sub>s\\<^sub>t [a] = vars\\<^sub>s\\<^sub>t\\<^sub>p s\" using ls by auto\n    show ?thesis\n    proof (cases l)\n      case (LabelN n)\n      hence \"vars_proj\\<^sub>l\\<^sub>s\\<^sub>t n [a] = vars\\<^sub>s\\<^sub>t\\<^sub>p s\" using ls by simp\n      moreover have \"\\<forall>m. n \\<noteq> m \\<longrightarrow> vars_proj\\<^sub>l\\<^sub>s\\<^sub>t m [a] = {}\" using ls LabelN by auto\n      ultimately show ?thesis using * ls by fast\n    next\n      case LabelS\n      hence \"\\<forall>l. vars_proj\\<^sub>l\\<^sub>s\\<^sub>t l [a] = vars\\<^sub>s\\<^sub>t\\<^sub>p s\" using ls by auto\n      thus ?thesis using * ls by fast\n    qed\n  qed\n  moreover have \"\\<forall>l. vars_proj\\<^sub>l\\<^sub>s\\<^sub>t l (a#A) = vars_proj\\<^sub>l\\<^sub>s\\<^sub>t l [a] \\<union> vars_proj\\<^sub>l\\<^sub>s\\<^sub>t l A\"\n    unfolding unlabel_def proj_def by auto\n  hence \"(\\<Union>l. vars_proj\\<^sub>l\\<^sub>s\\<^sub>t l (a#A)) = (\\<Union>l. vars_proj\\<^sub>l\\<^sub>s\\<^sub>t l [a]) \\<union> (\\<Union>l. vars_proj\\<^sub>l\\<^sub>s\\<^sub>t l A)\"\n    using strand_vars_split(1) by auto\n  ultimately show ?case using Cons.IH ls strand_vars_split(1) by auto\nqed simp\n\nlemma unlabel_Cons_inv:\n  \"unlabel A = b#B \\<Longrightarrow> \\<exists>A'. (\\<exists>n. A = (ln n, b)#A') \\<or> A = (\\<star>, b)#A'\"\nproof -\n  assume *: \"unlabel A = b#B\"\n  then obtain l A' where \"A = (l,b)#A'\" unfolding unlabel_def by moura\n  thus \"\\<exists>A'. (\\<exists>l. A = (ln l, b)#A') \\<or> A = (\\<star>, b)#A'\" by (metis strand_label.exhaust)\nqed\n\nlemma unlabel_snoc_inv:\n  \"unlabel A = B@[b] \\<Longrightarrow> \\<exists>A'. (\\<exists>n. A = A'@[(ln n, b)]) \\<or> A = A'@[(\\<star>, b)]\"\nproof -\n  assume *: \"unlabel A = B@[b]\"\n  then obtain A' l where \"A = A'@[(l,b)]\"\n    unfolding unlabel_def by (induct A rule: List.rev_induct) auto\n  thus \"\\<exists>A'. (\\<exists>n. A = A'@[(ln n, b)]) \\<or> A = A'@[(\\<star>, b)]\" by (cases l) auto\nqed\n\nlemma proj_idem[simp]: \"proj l (proj l A) = proj l A\"\nunfolding proj_def by auto\n\nlemma proj_ik\\<^sub>s\\<^sub>t_is_proj_rcv_set:\n  \"ik\\<^sub>s\\<^sub>t (proj_unl n A) = {t. (ln n, Receive t) \\<in> set A \\<or> (\\<star>, Receive t) \\<in> set A} \"\nusing ik\\<^sub>s\\<^sub>t_is_rcv_set unfolding unlabel_def proj_def by force\n\nlemma unlabel_ik\\<^sub>s\\<^sub>t_is_rcv_set:\n  \"ik\\<^sub>s\\<^sub>t (unlabel A) = {t | l t. (l, Receive t) \\<in> set A}\"\nusing ik\\<^sub>s\\<^sub>t_is_rcv_set unfolding unlabel_def by force\n\nlemma proj_ik_union_is_unlabel_ik:\n  \"ik\\<^sub>s\\<^sub>t (unlabel A) = (\\<Union>l. ik\\<^sub>s\\<^sub>t (proj_unl l A))\"\nproof\n  show \"(\\<Union>l. ik\\<^sub>s\\<^sub>t (proj_unl l A)) \\<subseteq> ik\\<^sub>s\\<^sub>t (unlabel A)\"\n    using unlabel_ik\\<^sub>s\\<^sub>t_is_rcv_set[of A] proj_ik\\<^sub>s\\<^sub>t_is_proj_rcv_set[of _ A] by auto\n\n  show \"ik\\<^sub>s\\<^sub>t (unlabel A) \\<subseteq> (\\<Union>l. ik\\<^sub>s\\<^sub>t (proj_unl l A))\"\n  proof\n    fix t assume \"t \\<in> ik\\<^sub>s\\<^sub>t (unlabel A)\"\n    then obtain l where \"(l, Receive t) \\<in> set A\"\n      using ik\\<^sub>s\\<^sub>t_is_rcv_set unlabel_mem_has_label[of _ A]\n      by moura\n    thus \"t \\<in> (\\<Union>l. ik\\<^sub>s\\<^sub>t (proj_unl l A))\" using proj_ik\\<^sub>s\\<^sub>t_is_proj_rcv_set[of _ A] by (cases l) auto\n  qed\nqed\n\nlemma proj_ik_append[simp]:\n  \"ik\\<^sub>s\\<^sub>t (proj_unl l (A@B)) = ik\\<^sub>s\\<^sub>t (proj_unl l A) \\<union> ik\\<^sub>s\\<^sub>t (proj_unl l B)\"\nusing proj_append(2)[of l A B] ik_append by auto\n\nlemma proj_ik_append_subst_all:\n  \"ik\\<^sub>s\\<^sub>t (proj_unl l (A@B)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I = (ik\\<^sub>s\\<^sub>t (proj_unl l A) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I) \\<union> (ik\\<^sub>s\\<^sub>t (proj_unl l B) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I)\"\nusing proj_ik_append[of l] by auto\n\nlemma ik_proj_subset[simp]: \"ik\\<^sub>s\\<^sub>t (proj_unl n A) \\<subseteq> trms_proj\\<^sub>l\\<^sub>s\\<^sub>t n A\"\nby auto\n\nlemma prefix_proj:\n  \"prefix A B \\<Longrightarrow> prefix (unlabel A) (unlabel B)\"\n  \"prefix A B \\<Longrightarrow> prefix (proj n A) (proj n B)\"\n  \"prefix A B \\<Longrightarrow> prefix (proj_unl n A) (proj_unl n B)\"\nunfolding prefix_def unlabel_def proj_def by auto\n\n\nsubsection \\<open>Lemmata: Well-formedness\\<close>\nlemma wfvarsoccs\\<^sub>s\\<^sub>t_proj_union:\n  \"wfvarsoccs\\<^sub>s\\<^sub>t (unlabel A) = (\\<Union>l. wfvarsoccs\\<^sub>s\\<^sub>t (proj_unl l A))\"\nproof (induction A)\n  case (Cons a A)\n  obtain l s where ls: \"a = (l,s)\" by moura\n  have \"wfvarsoccs\\<^sub>s\\<^sub>t (unlabel [a]) = (\\<Union>l. wfvarsoccs\\<^sub>s\\<^sub>t (proj_unl l [a]))\"\n  proof -\n    have *: \"wfvarsoccs\\<^sub>s\\<^sub>t (unlabel [a]) = wfvarsoccs\\<^sub>s\\<^sub>t\\<^sub>p s\" using ls by auto\n    show ?thesis\n    proof (cases l)\n      case (LabelN n)\n      hence \"wfvarsoccs\\<^sub>s\\<^sub>t (proj_unl n [a]) = wfvarsoccs\\<^sub>s\\<^sub>t\\<^sub>p s\" using ls by simp\n      moreover have \"\\<forall>m. n \\<noteq> m \\<longrightarrow> wfvarsoccs\\<^sub>s\\<^sub>t (proj_unl m [a]) = {}\" using ls LabelN by auto\n      ultimately show ?thesis using * ls by fast\n    next\n      case LabelS\n      hence \"\\<forall>l. wfvarsoccs\\<^sub>s\\<^sub>t (proj_unl l [a]) = wfvarsoccs\\<^sub>s\\<^sub>t\\<^sub>p s\" using ls by auto\n      thus ?thesis using * ls by fast\n    qed\n  qed\n  moreover have\n      \"wfvarsoccs\\<^sub>s\\<^sub>t (proj_unl l (a#A)) =\n       wfvarsoccs\\<^sub>s\\<^sub>t (proj_unl l [a]) \\<union> wfvarsoccs\\<^sub>s\\<^sub>t (proj_unl l A)\"\n    for l\n    unfolding unlabel_def proj_def by auto\n  hence \"(\\<Union>l. wfvarsoccs\\<^sub>s\\<^sub>t (proj_unl l (a#A))) =\n         (\\<Union>l. wfvarsoccs\\<^sub>s\\<^sub>t (proj_unl l [a])) \\<union> (\\<Union>l. wfvarsoccs\\<^sub>s\\<^sub>t (proj_unl l A))\"\n    using strand_vars_split(1) by auto\n  ultimately show ?case using Cons.IH ls strand_vars_split(1) by auto\nqed simp\n\nlemma wf_if_wf_proj:\n  assumes \"\\<forall>l. wf\\<^sub>s\\<^sub>t V (proj_unl l A)\"\n  shows \"wf\\<^sub>s\\<^sub>t V (unlabel A)\"\nusing assms\nproof (induction A arbitrary: V rule: List.rev_induct)\n  case (snoc a A)\n  hence IH: \"wf\\<^sub>s\\<^sub>t V (unlabel A)\" using proj_append(2)[of _ A] by auto\n  obtain b l where b: \"a = (ln l, b) \\<or> a = (\\<star>, b)\" by (cases a, metis strand_label.exhaust)\n  hence *: \"wf\\<^sub>s\\<^sub>t V (proj_unl l A@[b])\"\n    by (metis snoc.prems proj_append(2) singleton_lst_proj(1) proj_unl_cons(1,3))\n  thus ?case using IH b snoc.prems proj_append(2)[of l A \"[a]\"] unlabel_append[of A \"[a]\"]\n  proof (cases b)\n    case (Receive t)\n    have \"fv t \\<subseteq> wfvarsoccs\\<^sub>s\\<^sub>t (unlabel A) \\<union> V\"\n    proof\n      fix x assume \"x \\<in> fv t\"\n      hence \"x \\<in> V \\<union> wfvarsoccs\\<^sub>s\\<^sub>t (proj_unl l A)\" using wf_append_exec[OF *] b Receive by auto\n      thus \"x \\<in> wfvarsoccs\\<^sub>s\\<^sub>t (unlabel A) \\<union> V\" using wfvarsoccs\\<^sub>s\\<^sub>t_proj_union[of A] by auto\n    qed\n    hence \"fv t \\<subseteq> wfrestrictedvars\\<^sub>s\\<^sub>t (unlabel A) \\<union> V\"\n      using vars_snd_rcv_strand_subset2(4)[of \"unlabel A\"] by blast\n    hence \"wf\\<^sub>s\\<^sub>t V (unlabel A@[Receive t])\" by (rule wf_rcv_append'''[OF IH])\n    thus ?thesis using b Receive unlabel_append[of A \"[a]\"] by auto\n  next\n    case (Equality ac s t)\n    have \"fv t \\<subseteq> wfvarsoccs\\<^sub>s\\<^sub>t (unlabel A) \\<union> V\" when \"ac = Assign\"\n    proof\n      fix x assume \"x \\<in> fv t\"\n      hence \"x \\<in> V \\<union> wfvarsoccs\\<^sub>s\\<^sub>t (proj_unl l A)\" using wf_append_exec[OF *] b Equality that by auto\n      thus \"x \\<in> wfvarsoccs\\<^sub>s\\<^sub>t (unlabel A) \\<union> V\" using wfvarsoccs\\<^sub>s\\<^sub>t_proj_union[of A] by auto\n    qed\n    hence \"fv t \\<subseteq> wfrestrictedvars\\<^sub>l\\<^sub>s\\<^sub>t A \\<union> V\" when \"ac = Assign\"\n      using vars_snd_rcv_strand_subset2(4)[of \"unlabel A\"] that by blast\n    hence \"wf\\<^sub>s\\<^sub>t V (unlabel A@[Equality ac s t])\"\n      by (cases ac) (metis wf_eq_append'''[OF IH], metis wf_eq_check_append''[OF IH])\n    thus ?thesis using b Equality unlabel_append[of A \"[a]\"] by auto\n  qed auto\nqed simp\n\nend\n", "meta": {"author": "logicalhacking", "repo": "Stateful_Protocol_Composition_and_Typing", "sha": "34755583e50bc8a2e3eb0f91350c0b8510422a16", "save_path": "github-repos/isabelle/logicalhacking-Stateful_Protocol_Composition_and_Typing", "path": "github-repos/isabelle/logicalhacking-Stateful_Protocol_Composition_and_Typing/Stateful_Protocol_Composition_and_Typing-34755583e50bc8a2e3eb0f91350c0b8510422a16/Stateful_Protocol_Composition_and_Typing/Labeled_Strands.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.523420348936324, "lm_q2_score": 0.538983220687684, "lm_q1q2_score": 0.2821147854431713}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |                    May 2005               |\n            |                   June 2005  (modified)   |\n            |              September 2005  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |                October 2005  (modified)   |\n            |                  April 2006  (modified)   |\n            |                  March 2007  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2016         |\n            |                    May 2016  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory CSP_T_op_rep_par\nimports CSP_T_op_alpha_par\nbegin\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite UnionT and InterT.                 *)\n(*                  Union (B ` A) = (UN x:A. B x)                      *)\n(*                  Inter (B ` A) = (INT x:A. B x)                     *)\n\n\ndeclare Sup_image_eq [simp del]\ndeclare Inf_image_eq [simp del]\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite (notick | t = <>)                  *)\n(*                                                                     *)\n(*                  disj_not1: (~ P | Q) = (P --> Q)                   *)\n\ndeclare disj_not1 [simp del]\n\n(*============================================================*\n |                                                            |\n |            replicated alphabetized parallel                |\n |                                                            |\n *============================================================*)\n\n(*** traces Inductive_parallel ***)\n\nlemma in_traces_Inductive_parallel_lm1: \n  \"(P, X) : set PXs ==> X <= Union (snd ` (set PXs))\"\nby (auto)\n\n(* main *)\n\nlemma in_traces_Inductive_parallel_lm:\n  \"PXs ~= [] --> (ALL u.\n    (u :t traces ([||] PXs) M) =\n     (sett(u) <= insert Tick (Ev ` (Union (snd ` (set PXs)))) & \n      (ALL P X. (P,X):(set PXs) --> (u rest-tr X) :t traces P M)))\"\napply (induct_tac PXs)\n\n(* case 0 *)\n apply (simp)\n\n(* case 1 *)\n apply (case_tac \"list = []\")\n apply (simp)\n apply (intro allI)\n apply (simp add: in_traces_Alpha_parallel in_traces)\n apply (simp add: pair_eq_decompo)\n apply (simp add: rest_tr_empty)\n apply (rule iffI)\n (* => *)\n  apply (simp)\n (* <= *)\n  apply (simp)\n\n(* step case *)\napply (simp add: in_traces_Alpha_parallel)\napply (intro allI impI)\napply (rule iffI)\n\n(* => *)\n apply (simp)\n apply (intro allI)\n apply (rule conjI)\n\n  apply (intro impI)\n  apply (simp add: pair_eq_decompo)\n\n  apply (intro impI)\n  apply (elim conjE)\n  apply (drule_tac x=\"P\" in spec)\n  apply (drule_tac x=\"X\" in spec)\n  apply (subgoal_tac \"X <= Union (snd ` set list)\")\n  apply (simp add: rest_tr_of_rest_tr_subset)\n  apply (simp add: in_traces_Inductive_parallel_lm1)\n\n(* <= *)\n apply (simp add: rest_tr_sett_subseteq_sett)\n apply (intro allI impI)\n apply (elim conjE)\n apply (drule_tac x=\"P\" in spec)\n apply (drule_tac x=\"X\" in spec)\n apply (subgoal_tac \"X <= Union (snd ` set list)\")\n apply (simp add: rest_tr_of_rest_tr_subset)\n apply (simp add: in_traces_Inductive_parallel_lm1)\ndone\n\n(*** remove ALL ***)\n\nlemma in_traces_Inductive_parallel:\n  \"PXs ~= [] \n   ==> (u :t traces ([||] PXs) M) =\n       (sett(u) <= insert Tick (Ev ` (Union (snd ` (set PXs)))) & \n        (ALL P X. (P,X):(set PXs) --> (u rest-tr X) :t traces P M))\"\nby (simp add: in_traces_Inductive_parallel_lm)\n\n(*** Semantics for replicated alphabetized parallel on T ***)\n\nlemma traces_Inductive_parallel:\n  \"PXs ~= []\n   ==> traces ([||] PXs) M =\n       {u. sett(u) <= insert Tick (Ev ` (Union (snd ` (set PXs)))) & \n        (ALL P X. (P,X):(set PXs) --> (u rest-tr X) :t traces P M)}t\"\napply (simp add: in_traces_Inductive_parallel[THEN sym])\ndone\n\n(************************************\n |              traces              |\n ************************************)\n\nlemma sett_in_traces_Inductive_parallel:\n  \"[| PXs ~= [] ; t :t traces ([||] PXs) M |] \n   ==> sett t <= insert Tick (Ev ` Union (snd ` set PXs))\"\nby (simp add: in_traces_Inductive_parallel)\n\n(*---------------------------------------------------------*\n |        another expression of Inductive_parallel_eval          |\n *---------------------------------------------------------*)\n\nlemma in_traces_Inductive_parallel_nth:\n  \"PXs ~= [] \n   ==> (u :t traces ([||] PXs) M) =\n       (sett(u) <= insert Tick (Ev ` (Union (snd ` (set PXs)))) & \n        (ALL i. i < length PXs --> (u rest-tr (snd (PXs!i))) :t traces (fst (PXs!i)) M))\"\napply (simp add: in_traces_Inductive_parallel)\napply (simp add: set_nth)\napply (simp add: pair_eq_decompo)\nby (auto)\n\n(*============================================================*\n |                                                            |\n |              indexed alphabetized parallel                 |\n |                                                            |\n *============================================================*)\n\n(*** index_style ***)\n\nlemma to_index_style_T:\n   \"(ALL P X. (P,X):(PXf ` I) --> (u rest-tr X) :t traces P M)\n  = (ALL i:I. u rest-tr (snd (PXf i)) :t traces (fst (PXf i)) M)\"\napply (auto)\napply (simp add: pair_eq_decompo)\ndone\n\n(*** in_traces_Rep_parallel (pre) ***)\n\nlemma in_traces_Rep_parallel_pre:\n  \"[| I ~= {} ; finite I |]\n   ==> (u :t traces ([||]:I PXf) M) =\n       (sett(u) <= insert Tick (Ev ` (Union (snd ` PXf ` I))) & \n        (ALL P X. (P,X):PXf ` I --> (u rest-tr X) :t traces P M))\"\napply (simp add: Rep_parallel_def)\napply (subgoal_tac \"EX Is. Is isListOf I\")\napply (elim conjE exE)\napply (subgoal_tac \"(map PXf (SOME Is. Is isListOf I)) ~= []\")\napply (simp add: in_traces in_traces_Inductive_parallel)\napply (rule someI2)\n apply (simp)\n apply (simp add: isListOf_set_eq)\n\napply (rule someI2)\n apply (simp)\n apply (simp add: isListOf_nonemptyset)\n\napply (simp add: isListOf_EX)\ndone\n\n(*** in_traces_Rep_parallel ***)\n\nlemma in_traces_Rep_parallel:\n  \"[| I ~= {} ; finite I |]\n   ==> (u :t traces ([||]:I PXf) M) =\n       (sett(u) <= insert Tick (Ev ` (Union (snd ` PXf ` I))) & \n        (ALL i:I. (u rest-tr (snd (PXf i))) :t traces (fst (PXf i)) M))\"\napply (simp add: in_traces_Rep_parallel_pre)\napply (simp add: to_index_style_T)\ndone\n\nlemmas in_traces_par = in_traces_Alpha_parallel\n                       in_traces_Inductive_parallel\n                       in_traces_Rep_parallel\n\n(*** Semantics for indexed alphabetized parallel on T ***)\n\nlemma traces_Rep_parallel:\n  \"[| I ~= {} ; finite I |]\n   ==> traces ([||]:I PXf) M =\n             {u. (sett(u) <= insert Tick (Ev ` (Union (snd ` PXf ` I))) & \n              (ALL i:I. (u rest-tr (snd (PXf i))) :t traces (fst (PXf i)) M))}t\"\napply (simp add: in_traces_Rep_parallel[THEN sym])\ndone\n\n(************************************\n |              traces              |\n ************************************)\n\nlemma sett_in_traces_Rep_parallel:\n  \"[| I ~= {} ; finite I ; t :t traces ([||]:I PXf) M |] \n   ==> sett t <= insert Tick (Ev ` Union (snd ` PXf ` I))\"\nby (simp add: in_traces_Rep_parallel)\n\n(****************** to add it again ******************)\n\ndeclare disj_not1   [simp]\n(*\ndeclare Union_image_eq [simp]\ndeclare Inter_image_eq [simp]\n*)\n\ndeclare Sup_image_eq [simp]\ndeclare Inf_image_eq [simp]\n\nend\n", "meta": {"author": "pefribeiro", "repo": "CSP-Prover", "sha": "8967cc482e5695fca4abb52d9dc2cf36b7b7a44e", "save_path": "github-repos/isabelle/pefribeiro-CSP-Prover", "path": "github-repos/isabelle/pefribeiro-CSP-Prover/CSP-Prover-8967cc482e5695fca4abb52d9dc2cf36b7b7a44e/CSP_T/CSP_T_op_rep_par.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5389832058771036, "lm_q2_score": 0.5234203489363239, "lm_q1q2_score": 0.28211477769101206}}
{"text": "section \\<open>Stack by Array\\<close>\ntheory Impl_Array_Stack\nimports\n  \"../../../Automatic_Refinement/Automatic_Refinement\"\n  \"../../Lib/Diff_Array\"\nbegin\n\ntype_synonym 'a array_stack = \"'a array \\<times> nat\"\n\nterm Diff_Array.array_length\n\ndefinition \"as_raw_\\<alpha> s \\<equiv> take (snd s) (list_of_array (fst s))\"\ndefinition \"as_raw_invar s \\<equiv> snd s \\<le> array_length (fst s)\"\n\ndefinition as_rel_def_internal: \"as_rel R \\<equiv> br as_raw_\\<alpha> as_raw_invar O \\<langle>R\\<rangle>list_rel\"\nlemma as_rel_def: \"\\<langle>R\\<rangle>as_rel \\<equiv> br as_raw_\\<alpha> as_raw_invar O \\<langle>R\\<rangle>list_rel\"\n  unfolding as_rel_def_internal[abs_def] by (simp add: relAPP_def)\n\nlemma [relator_props]: \"single_valued R \\<Longrightarrow> single_valued (\\<langle>R\\<rangle>as_rel)\"\n  unfolding as_rel_def\n  by tagged_solver\n\nlemmas [autoref_rel_intf] = REL_INTFI[of as_rel i_list]\n\n\ndefinition \"as_empty (_::unit) \\<equiv> (array_of_list [],0)\"\n\nlemma as_empty_refine[autoref_rules]: \"(as_empty (),[]) \\<in> \\<langle>R\\<rangle>as_rel\"\n  unfolding as_rel_def as_empty_def br_def\n  unfolding as_raw_\\<alpha>_def as_raw_invar_def\n  by auto\n\n\ndefinition \"as_push s x \\<equiv> let\n    (a,n)=s;\n    a = if n = array_length a then\n        array_grow a (max 4 (2*n)) x\n      else a;\n    a = array_set a n x\n  in\n    (a,n+1)\"\n\nlemma as_push_refine[autoref_rules]: \n  \"(as_push,op_list_append_elem) \\<in> \\<langle>R\\<rangle>as_rel \\<rightarrow> R \\<rightarrow> \\<langle>R\\<rangle>as_rel\"\n  apply (intro fun_relI)\n  apply (simp add: as_push_def op_list_append_elem_def as_rel_def br_def\n    as_raw_\\<alpha>_def as_raw_invar_def)\n  apply clarsimp\n  apply safe\n  apply (rule)\n  apply auto []\n  apply (clarsimp simp: array_length_list) []\n  apply parametricity\n\n  apply rule\n  apply auto []\n  apply (auto simp: take_Suc_conv_app_nth array_length_list list_update_append) []\n  apply parametricity\n  done\n\nterm array_shrink\n\ndefinition \"as_shrink s \\<equiv> let \n    (a,n) = s;\n    a = if 128*n \\<le> array_length a \\<and> n>4 then\n        array_shrink a n\n      else a\n  in\n    (a,n)\"\n\nlemma as_shrink_id_refine: \"(as_shrink,id) \\<in> \\<langle>R\\<rangle>as_rel \\<rightarrow> \\<langle>R\\<rangle>as_rel\"\n  apply (intro fun_relI)\n  apply (simp add: as_shrink_def as_rel_def br_def\n    as_raw_\\<alpha>_def as_raw_invar_def Let_def)\n  apply clarsimp\n  apply safe\n\n  apply (rule)\n  apply (auto simp: array_length_list)\n  done\n\nlemma as_shrinkI:\n  assumes [param]: \"(s,a)\\<in>\\<langle>R\\<rangle>as_rel\"\n  shows \"(as_shrink s,a)\\<in>\\<langle>R\\<rangle>as_rel\"\n  apply (subst id_apply[of a,symmetric])\n  apply (parametricity add: as_shrink_id_refine)\n  done\n\ndefinition \"as_pop s \\<equiv> let (a,n)=s in as_shrink (a,n - 1)\"\n\nlemma as_pop_refine[autoref_rules]: \"(as_pop,butlast) \\<in> \\<langle>R\\<rangle>as_rel \\<rightarrow> \\<langle>R\\<rangle>as_rel\"\n  apply (intro fun_relI)\n  apply (clarsimp simp add: as_pop_def split: prod.split)\n  apply (rule as_shrinkI)\n\n  apply (simp add: as_pop_def as_rel_def br_def\n    as_raw_\\<alpha>_def as_raw_invar_def Let_def)\n  apply clarsimp\n\n  apply rule\n  apply (auto simp: array_length_list) []\n  apply (clarsimp simp: array_length_list take_minus_one_conv_butlast) []\n  apply parametricity\n  done\n  \ndefinition \"as_get s i \\<equiv> let (a,_::nat)=s in array_get a i\"\n\nlemma as_get_refine: \n  assumes 1: \"i'<length l\" \n  assumes 2: \"(a,l)\\<in>\\<langle>R\\<rangle>as_rel\" \n  assumes 3[param]: \"(i,i')\\<in>nat_rel\"\n  shows \"(as_get a i,l!i')\\<in>R\"\n  using 2\n  apply (clarsimp \n    simp add: as_get_def as_rel_def br_def as_raw_\\<alpha>_def as_raw_invar_def\n    split: prod.split)\n  apply (rename_tac aa bb)\n  apply (case_tac aa, simp)\nproof -\n  fix n cl\n  assume TKR[param]: \"(take n cl, l) \\<in> \\<langle>R\\<rangle>list_rel\"\n\n  have \"(take n cl!i, l!i')\\<in>R\"\n    by parametricity (rule 1)\n  also have \"take n cl!i = cl!i\"\n    using 1 3 list_rel_imp_same_length[OF TKR]\n    by simp\n  finally show \"(cl!i,l!i')\\<in>R\" .\nqed\n  \ncontext begin interpretation autoref_syn .\nlemma as_get_autoref[autoref_rules]: \n  assumes \"(l,l')\\<in>\\<langle>R\\<rangle>as_rel\"\n  assumes \"(i,i')\\<in>Id\"\n  assumes \"SIDE_PRECOND (i' < length l')\"\n  shows \"(as_get l i,(OP nth ::: \\<langle>R\\<rangle>as_rel \\<rightarrow> nat_rel \\<rightarrow> R)$l'$i')\\<in>R\"\n  using assms by (simp add: as_get_refine)\n\ndefinition \"as_set s i x \\<equiv> let (a,n::nat)=s in (array_set a i x,n)\"\n\nlemma as_set_refine[autoref_rules]: \n  \"(as_set,list_update)\\<in>\\<langle>R\\<rangle>as_rel \\<rightarrow> nat_rel \\<rightarrow> R \\<rightarrow> \\<langle>R\\<rangle>as_rel\"\n  apply (intro fun_relI)\n  apply (clarsimp \n    simp: as_set_def as_rel_def br_def as_raw_\\<alpha>_def as_raw_invar_def\n    split: prod.split)\n  apply rule\n  apply auto []\n  apply parametricity\n  by simp\n\ndefinition as_length :: \"'a array_stack \\<Rightarrow> nat\" where \n  \"as_length = snd\"\n\nlemma as_length_refine[autoref_rules]: \n  \"(as_length,length) \\<in> \\<langle>R\\<rangle>as_rel \\<rightarrow> nat_rel\"\n  by (auto \n    simp: as_length_def as_rel_def br_def as_raw_\\<alpha>_def as_raw_invar_def\n      array_length_list\n    dest!: list_rel_imp_same_length\n  )\n\ndefinition \"as_top s \\<equiv> as_get s (as_length s - 1)\"\n\nlemma as_top_code[code]: \"as_top s = (let (a,n)=s in array_get a (n - 1))\"\n  unfolding as_top_def as_get_def as_length_def \n  by (auto split: prod.split)\n\nlemma as_top_refine: \"\\<lbrakk>l\\<noteq>[]; (s,l)\\<in>\\<langle>R\\<rangle>as_rel\\<rbrakk> \\<Longrightarrow> (as_top s,last l)\\<in>R\"\n  unfolding as_top_def\n  apply (simp add: last_conv_nth)\n  apply (rule as_get_refine)\n  apply (auto simp: as_length_def as_rel_def br_def as_raw_\\<alpha>_def \n    as_raw_invar_def array_length_list\n    dest!: list_rel_imp_same_length)\n  done\n\nlemma as_top_autoref[autoref_rules]:\n  assumes \"(l,l')\\<in>\\<langle>R\\<rangle>as_rel\"\n  assumes \"SIDE_PRECOND (l' \\<noteq> [])\"\n  shows \"(as_top l,(OP last ::: \\<langle>R\\<rangle>as_rel \\<rightarrow> R)$l')\\<in>R\"\n  using assms by (simp add: as_top_refine)\n\n\ndefinition \"as_is_empty s \\<equiv> as_length s = 0\"\nlemma as_is_empty_code[code]: \"as_is_empty s = (snd s = 0)\"\n  unfolding as_is_empty_def as_length_def by simp\n\nlemma as_is_empty_refine[autoref_rules]: \n  \"(as_is_empty,is_Nil) \\<in> \\<langle>R\\<rangle>as_rel \\<rightarrow> bool_rel\"\nproof\n  fix s l\n  assume [param]: \"(s,l)\\<in>\\<langle>R\\<rangle>as_rel\"\n  have \"(as_is_empty s,length l = 0) \\<in> bool_rel\"\n    unfolding as_is_empty_def\n    by (parametricity add: as_length_refine)\n  also have \"length l = 0 \\<longleftrightarrow> is_Nil l\"\n    by (cases l) auto\n  finally show \"(as_is_empty s, is_Nil l) \\<in> bool_rel\" .\nqed\n\ndefinition \"as_take m s \\<equiv> let (a,n) = s in \n  if m<n then \n    as_shrink (a,m)\n  else (a,n)\"\n\nlemma as_take_refine[autoref_rules]: \n  \"(as_take,take)\\<in>nat_rel \\<rightarrow> \\<langle>R\\<rangle>as_rel \\<rightarrow> \\<langle>R\\<rangle>as_rel\"\n  apply (intro fun_relI)\n  apply (clarsimp simp add: as_take_def, safe)\n\n  apply (rule as_shrinkI)\n  apply (simp add: as_rel_def br_def as_raw_\\<alpha>_def as_raw_invar_def)\n  apply rule\n  apply auto []\n  apply clarsimp\n  apply (subgoal_tac \"take a' (list_of_array a) = take a' (take ba (list_of_array a))\")\n  apply (simp only: )\n  apply (parametricity, rule IdI)\n  apply simp\n\n  apply (simp add: as_rel_def br_def as_raw_\\<alpha>_def as_raw_invar_def)\n  apply rule\n  apply auto []\n  apply clarsimp\n  apply (frule list_rel_imp_same_length)\n  apply simp\n  done\n\ndefinition \"as_singleton x \\<equiv> (array_of_list [x],1)\"\nlemma as_singleton_refine[autoref_rules]: \n  \"(as_singleton,op_list_singleton)\\<in>R \\<rightarrow> \\<langle>R\\<rangle>as_rel\"\n  apply (intro fun_relI)\n  apply (simp add: as_singleton_def as_rel_def br_def as_raw_\\<alpha>_def \n    as_raw_invar_def)\n  apply rule\n  apply (auto simp: array_length_list) []\n  apply simp\n  done\n\nend\n\nend\n", "meta": {"author": "VTrelat", "repo": "Hopcroft_verif", "sha": "ede77c3a2105fd6722cf96896a297db294edf269", "save_path": "github-repos/isabelle/VTrelat-Hopcroft_verif", "path": "github-repos/isabelle/VTrelat-Hopcroft_verif/Hopcroft_verif-ede77c3a2105fd6722cf96896a297db294edf269/Isabelle/Collections/GenCF/Impl/Impl_Array_Stack.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.2820290505130333}}
{"text": "theory VCTheoryLemmas\n  imports trafficLights\nbegin\n\nlemma substate_refl: \"substate s s\"\n  apply(cases s)\n         apply(auto)\n  done\n\nlemma substate_trans:\n\"substate s1 s2 \\<and> substate s2 s3 \\<Longrightarrow> substate s1 s3\"\nproof(induction s3)\n    case emptyState\n assume 1: \"substate s1 s2 \\<and> substate s2 emptyState\"\n    hence \"s2=emptyState\"\n    proof(cases)\n      assume \"s2=emptyState\"\n      thus ?thesis by assumption\n    next\n      assume  \"s2 \\<noteq> emptyState\"\n      with 1 show ?thesis by simp\n    qed\n    with 1 show ?case by auto\n  next\n    case (toEnv s3)\n    assume 1: \"substate s1 s2 \\<and> substate s2 (toEnv s3)\"\n     show ?case\n    proof(cases)\n      assume \"s2=toEnv s3\"\n      with 1 show ?case by auto\n    next\n      assume \"s2 \\<noteq> toEnv s3\"\n      with 1 toEnv.IH show ?case by auto\n    qed\n  next\n    case (toCon s3)\nassume 1: \"substate s1 s2 \\<and> substate s2 (toCon s3)\"\n     show ?case\n    proof(cases)\n      assume \"s2=toCon s3\"\n      with 1 show ?case by auto\n    next\n      assume \"s2 \\<noteq> toCon s3\"\n      with 1 toCon.IH show ?case by auto\n    qed\n  next\n    case (setVarBool s3 v u)\n      assume 1: \"substate s1 s2 \\<and> substate s2 (setVarBool s3 v u)\"\n      show ?case\n      proof(cases)\n        assume \"s2 = setVarBool s3 v u\"\n        with 1 show ?case by auto\n      next\n        assume \"s2 \\<noteq> setVarBool s3 v u\"\n        with 1 setVarBool.IH show ?case by auto\n      qed\n  next\n    case (setVarInt s3 v u)\n    assume 1:  \"substate s1 s2 \\<and> substate s2 (setVarInt s3 v u)\"\n    show ?case\n    proof(cases)\n      assume \"s2 = setVarInt s3 v u\"\n      with 1 show ?case by auto\n    next\n      assume \"s2 \\<noteq> setVarInt s3 v u\"\n      with 1 setVarInt.IH show ?case by auto\n    qed\n  next\n    case (setVarAny s3 u)\n    assume 1: \"substate s1 s2 \\<and>substate  s2 (setVarAny s3 u)\"\n    show ?case\n    proof(cases)\n      assume \"s2 = setVarAny s3 u\"\n      with 1 show ?case by auto\n    next\n      assume \"s2 \\<noteq> setVarAny s3 u\"\n      with 1 setVarAny.IH show ?case by auto\n    qed\n  next\n    case (setPstate s3 p q)\n    assume 1: \"substate s1 s2 \\<and> substate s2 (setPstate s3 p q)\"\n    show ?case\n    proof(cases)\n      assume \"s2 = setPstate s3 p q\"\n      with 1 show ?case by auto\n    next\n      assume \"s2 \\<noteq> setPstate s3 p q\"\n      with 1 setPstate.IH show ?case by auto\n    qed\n  next\n    case (reset s3 p)\n    assume 1: \"substate s1 s2 \\<and> substate s2 (reset s3 p)\"\n    show ?case\n    proof(cases)\n      assume \"s2 = reset s3 p\"\n      with 1 show ?case by auto\n    next\n      assume \"s2 \\<noteq> reset s3 p\"\n      with 1 reset.IH show ?case by auto\n    qed\n  qed\n\n\nlemma substate_asym:\n \"substate s1 s2 \\<and> substate s2 s1 \\<Longrightarrow> s1=s2\"\nproof(induction s2 arbitrary: s1)\n  case emptyState\n  assume 1: \"substate s1 emptyState \\<and> substate emptyState s1\"\n  show ?case\n  proof(cases)\n    assume \"s1=emptyState\"\n    thus ?case by assumption\n  next\n    assume \"s1 \\<noteq> emptyState\"\n    with 1 show ?case by auto\n  qed\nnext\n  case (toEnv s2)\n  assume 1: \"substate s1 (toEnv s2) \\<and> substate (toEnv s2) s1\"\n  show ?case\n  proof(cases)\n    assume \"s1 = toEnv s2\"\n    thus ?case by assumption\n  next\n    assume 2: \"s1 \\<noteq> toEnv s2\"\n    from 1 obtain 3: \"substate s1 (toEnv s2)\" \nand 4: \"substate (toEnv s2) s1\" ..\n    from 2 3 have \"substate s1 s2\" by simp\n    with 4 substate_trans \n    have 5: \"substate (toEnv s2) s2\" by blast\n    have \"substate s2 (toEnv s2)\" \n      using substate_refl by auto\n    with 5 toEnv.IH have \"toEnv s2 = s2\" by auto\n    with 3 4 toEnv.IH show ?case by auto\n  qed\nnext\n  case (toCon s2)\n    assume 1: \"substate s1 (toCon s2) \\<and> substate (toCon s2) s1\"\n  show ?case\n  proof(cases)\n    assume \"s1 = toCon s2\"\n    thus ?case by assumption\n  next\n    assume 2: \"s1 \\<noteq> toCon s2\"\n    from 1 obtain 3: \"substate s1 (toCon s2)\" \nand 4: \"substate (toCon s2) s1\" ..\n    from 2 3 have \"substate s1 s2\" by simp\n    with 4 substate_trans \n    have 5: \"substate (toCon s2) s2\" by blast\n    have \"substate s2 (toCon s2)\"\n      using substate_refl by auto\n    with 5 toCon.IH have \"toCon s2 = s2\" by auto\n    with 3 4 toCon.IH show ?case by auto\n  qed\nnext\n  case (setVarBool s2 v u)\n    assume 1: \"substate s1 (setVarBool s2 v u) \\<and> substate (setVarBool s2 v u) s1\"\n  show ?case\n  proof(cases)\n    assume \"s1 = setVarBool s2 v u\"\n    thus ?case by assumption\n  next\n    assume 2: \"s1 \\<noteq> setVarBool s2 v u\"\n    from 1 obtain 3: \"substate s1 (setVarBool s2 v u)\" \nand 4: \"substate (setVarBool s2 v u) s1\" ..\n    from 2 3 have \"substate s1 s2\" by simp\n    with 4 substate_trans \n    have 5: \"substate (setVarBool s2 v u) s2\" by blast\n    have \"substate s2 (setVarBool s2 v u)\" \n      using substate_refl by auto\n    with 5 setVarBool.IH have \"setVarBool s2 v u = s2\" by auto\n    with 3 4 setVarBool.IH show ?case by auto\n  qed\nnext\n  case (setVarInt s2 v u)\n    assume 1: \"substate s1 (setVarInt s2 v u) \\<and> substate (setVarInt s2 v u) s1\"\n  show ?case\n  proof(cases)\n    assume \"s1 = setVarInt s2 v u\"\n    thus ?case by assumption\n  next\n    assume 2: \"s1 \\<noteq> setVarInt s2 v u\"\n    from 1 obtain 3: \"substate s1 (setVarInt s2 v u)\" \nand 4: \"substate (setVarInt s2 v u) s1\" ..\n    from 2 3 have \"substate s1 s2\" by simp\n    with 4 substate_trans \n    have 5: \"substate (setVarInt s2 v u) s2\" by blast\n    have \"substate s2 (setVarInt s2 v u)\" \n      using substate_refl by auto\n    with 5 setVarInt.IH have \"setVarInt s2 v u = s2\" by auto\n    with 3 4 setVarInt.IH show ?case by auto\n  qed\nnext\n  case (setVarAny s2 u)\n    assume 1: \"substate s1 (setVarAny s2 u) \\<and> substate (setVarAny s2 u) s1\"\n  show ?case\n  proof(cases)\n    assume \"s1 = setVarAny s2 u\"\n    thus ?case by assumption\n  next\n    assume 2: \"s1 \\<noteq> setVarAny s2 u\"\n    from 1 obtain 3: \"substate s1 (setVarAny s2 u)\" \nand 4: \"substate (setVarAny s2 u) s1\" ..\n    from 2 3 have \"substate s1 s2\" by simp\n    with 4 substate_trans \n    have 5: \"substate (setVarAny s2 u) s2\" by blast\n    have \"substate s2 (setVarAny s2 u)\" \n      using substate_refl by auto\n    with 5 setVarAny.IH have \"setVarAny s2 u = s2\" by auto\n    with 3 4 setVarAny.IH show ?case by auto\n  qed\nnext\n  case (setPstate s2 p q)\n    assume 1: \"substate s1 (setPstate s2 p q) \\<and> substate (setPstate s2 p q) s1\"\n  show ?case\n  proof(cases)\n    assume \"s1 = setPstate s2 p q\"\n    thus ?case by assumption\n  next\n    assume 2: \"s1 \\<noteq> setPstate s2 p q\"\n    from 1 obtain 3: \"substate s1 (setPstate s2 p q)\" \nand 4: \"substate (setPstate s2 p q) s1\" ..\n    from 2 3 have \"substate s1 s2\" by simp\n    with 4 substate_trans \n    have 5: \"substate (setPstate s2 p q) s2\" by blast\n    have \"substate s2 (setPstate s2 p q)\" \n      using substate_refl by auto\n    with 5 setPstate.IH have \"setPstate s2 p q = s2\" by auto\n    with 3 4 setPstate.IH show ?case by auto\n  qed\nnext\n  case (reset s2 p)\n    assume 1: \"substate s1 (reset s2 p) \\<and> substate (reset s2 p) s1\"\n  show ?case\n  proof(cases)\n    assume \"s1 = reset s2 p\"\n    thus ?case by assumption\n  next\n    assume 2: \"s1 \\<noteq> reset s2 p\"\n    from 1 obtain 3: \"substate s1 (reset s2 p)\" \nand 4: \"substate (reset s2 p) s1\" ..\n    from 2 3 have \"substate s1 s2\" by simp\n    with 4 substate_trans \n    have 5: \"substate (reset s2 p) s2\" by blast\n    have \"substate s2 (reset s2 p)\" \n      using substate_refl by auto\n    with 5 reset.IH have \"reset s2 p = s2\" by auto\n    with 3 4 reset.IH show ?case by auto\n  qed\nqed\n\nlemma predEnv_substate: \"substate (predEnv s) s\"\n  apply(induction s)\n  using substate_refl  by auto\n\n\nlemma substate_eq_or_predEnv: \n\"substate s1 s2 \\<and> toEnvP s1 \\<longrightarrow> s1=s2 \\<or> substate s1 (predEnv s2)\"\n  apply(induction s2)\n         apply(auto)\n  done\n(*\n  case emptyState\n  then show ?case by force\nnext\n  case (toEnv s2)\n  assume 1:  \"substate s1 (toEnv s2) \\<and> toEnvP s1\"\n  show ?case\n  proof cases\n    assume \"s1= toEnv s2\"\n    then show ?case by auto\n  next\n    assume \"s1 \\<noteq> toEnv s2\"\n    with 1 have \"substate s1 s2\" by simp\n    with 1 toEnv.IH\n    have \"s1=s2 \\<or> substate s1 (predEnv s2)\" by auto\n    thus ?case\n    proof\n      assume \"s1=s2\"\n      with 1  \n      have \"predEnv (toEnv s2) = s1\" by auto\n      thus ?case by auto\n    next\n      assume 2: \"substate s1 (predEnv s2)\"\n      show ?case\n      proof(cases)\n        assume 3: \"toEnvP s2\" \n        from 2 predEnv_substate[of s2]\n substate_trans have \"substate s1 s2\" by auto\n        with 3 show ?case by auto\n      next\n        assume \"\\<not> toEnvP s2\" \n        with 2 show ?case by auto\n      qed\n    qed\n  qed        \nnext\n  case (toCon s2)\n  assume 1: \"substate s1 (toCon s2) \\<and> toEnvP s1\"\n  show ?case \n  proof cases\n    assume \"s1= toCon s2\"\n    thus ?case by auto\n  next\n    assume \"s1 \\<noteq> toCon s2\"\n    with 1 have \"substate s1 s2\" by simp\n    with 1 toCon.IH\n    have \"s1=s2 \\<or> substate s1 (predEnv s2)\" by auto\n    thus ?case\n    proof\n      assume \"s1=s2\"\n      with 1  \n      have \"predEnv (toCon s2) = s1\" by auto\n      thus ?case by auto\n    next\n      assume 2: \"substate s1 (predEnv s2)\"\n      show ?case\n      proof(cases)\n        assume 3: \"toEnvP s2\" \n        from 2 predEnv_substate[of s2]\n substate_trans have \"substate s1 s2\" by auto\n        with 3 show ?case by auto\n      next\n        assume \"\\<not> toEnvP s2\" \n        with 2 show ?case by auto\n      qed\n    qed\n  qed\nnext\n  case (setVarBool s2 v u)\n  assume 1: \"substate s1 (setVarBool s2 v u) \\<and> toEnvP s1\"\n  show ?case \n  proof cases\n    assume \"s1= setVarBool s2 v u\"\n    thus ?case by auto\n  next\n    assume \"s1 \\<noteq> setVarBool s2 v u\"\n    with 1 have \"substate s1 s2\" by simp\n    with 1 setVarBool.IH\n    have \"s1=s2 \\<or> substate s1 (predEnv s2)\" by auto\n    thus ?case\n    proof\n      assume \"s1=s2\"\n      with 1  \n      have \"predEnv (setVarBool s2 v u) = s1\" by auto\n      thus ?case by auto\n    next\n      assume 2: \"substate s1 (predEnv s2)\"\n      show ?case\n      proof(cases)\n        assume 3: \"toEnvP s2\" \n        from 2 predEnv_substate[of s2]\n substate_trans have \"substate s1 s2\" by auto\n        with 3 show ?case by auto\n      next\n        assume \"\\<not> toEnvP s2\" \n        with 2 show ?case by auto\n      qed\n    qed\n  qed\nnext\n  case (setVarInt s2 v u)\n  assume 1: \"substate s1 (setVarInt s2 v u) \\<and> toEnvP s1\"\n  show ?case \n  proof cases\n    assume \"s1= setVarInt s2 v u\"\n    thus ?case by auto\n  next\n    assume \"s1 \\<noteq> setVarInt s2 v u\"\n    with 1 have \"substate s1 s2\" by simp\n    with 1 setVarInt.IH\n    have \"s1=s2 \\<or> substate s1 (predEnv s2)\" by auto\n    thus ?case\n    proof\n      assume \"s1=s2\"\n      with 1  \n      have \"predEnv (setVarInt s2 v u) = s1\" by auto\n      thus ?case by auto\n    next\n      assume 2: \"substate s1 (predEnv s2)\"\n      show ?case\n      proof(cases)\n        assume 3: \"toEnvP s2\" \n        from 2 predEnv_substate[of s2]\n substate_trans have \"substate s1 s2\" by auto\n        with 3 show ?case by auto\n      next\n        assume \"\\<not> toEnvP s2\" \n        with 2 show ?case by auto\n      qed\n    qed\n  qed\nnext\n  case (setVarAny s2 u)\n  assume 1: \"substate s1 (setVarAny s2 u) \\<and> toEnvP s1\"\n  show ?case \n  proof cases\n    assume \"s1= setVarAny s2 u\"\n    thus ?case by auto\n  next\n    assume \"s1 \\<noteq> setVarAny s2 u\"\n    with 1 have \"substate s1 s2\" by simp\n    with 1 setVarAny.IH\n    have \"s1=s2 \\<or> substate s1 (predEnv s2)\" by auto\n    thus ?case\n    proof\n      assume \"s1=s2\"\n      with 1  \n      have \"predEnv (setVarAny s2 u) = s1\" by auto\n      thus ?case by auto\n    next\n      assume 2: \"substate s1 (predEnv s2)\"\n      show ?case\n      proof(cases)\n        assume 3: \"toEnvP s2\" \n        from 2 predEnv_substate[of s2]\n substate_trans have \"substate s1 s2\" by auto\n        with 3 show ?case by auto\n      next\n        assume \"\\<not> toEnvP s2\" \n        with 2 show ?case by auto\n      qed\n    qed\n  qed\nnext\n  case (setPstate s2 p q)\n  assume 1: \"substate s1 (setPstate s2 p q) \\<and> toEnvP s1\"\n  show ?case \n  proof cases\n    assume \"s1= setPstate s2 p q\"\n    thus ?case by auto\n  next\n    assume \"s1 \\<noteq> setPstate s2 p q\"\n    with 1 have \"substate s1 s2\" by simp\n    with 1 setPstate.IH\n    have \"s1=s2 \\<or> substate s1 (predEnv s2)\" by auto\n    thus ?case\n    proof\n      assume \"s1=s2\"\n      with 1  \n      have \"predEnv (setPstate s2 p q) = s1\" by auto\n      thus ?case by auto\n    next\n      assume 2: \"substate s1 (predEnv s2)\"\n      show ?case\n      proof(cases)\n        assume 3: \"toEnvP s2\" \n        from 2 predEnv_substate[of s2]\n substate_trans have \"substate s1 s2\" by auto\n        with 3 show ?case by auto\n      next\n        assume \"\\<not> toEnvP s2\" \n        with 2 show ?case by auto\n      qed\n    qed\n  qed\nnext\n  case (reset s2 p)\n  assume 1: \"substate s1 (reset s2 p) \\<and> toEnvP s1\"\n  show ?case \n  proof cases\n    assume \"s1= reset s2 p\"\n    thus ?case by auto\n  next\n    assume \"s1 \\<noteq> reset s2 p\"\n    with 1 have \"substate s1 s2\" by simp\n    with 1 reset.IH\n    have \"s1=s2 \\<or> substate s1 (predEnv s2)\" by auto\n    thus ?case\n    proof\n      assume \"s1=s2\"\n      with 1  \n      have \"predEnv (reset s2 p) = s1\" by auto\n      thus ?case by auto\n    next\n      assume 2: \"substate s1 (predEnv s2)\"\n      show ?case\n      proof(cases)\n        assume 3: \"toEnvP s2\" \n        from 2 predEnv_substate[of s2]\n substate_trans have \"substate s1 s2\" by auto\n        with 3 show ?case by auto\n      next\n        assume \"\\<not> toEnvP s2\" \n        with 2 show ?case by auto\n      qed\n    qed\n  qed\nqed\n*)\n\nlemma substate_total: \n\"substate s1 s \\<and> substate s2 s \\<longrightarrow>\n substate s1 s2 \\<or> substate s2 s1\"\n  apply(induction s)\n         apply(auto)\n  done\n\nlemma toEnvNum_id: \"toEnvNum s s = 0\"\n  apply(cases s)\n         apply(auto)\n  done\n\nlemma substate_toEnvNum_id:\n\"substate s1 s2 \\<and> toEnvNum s1 s2 = 0 \\<and> toEnvP s1 \\<and>\ntoEnvP s2 \\<longrightarrow> s1=s2\"\n  apply(cases s2)\n         apply(auto)\n  done\n\nlemma gtime_predI:\n \"\\<not> toEnvP s \\<Longrightarrow>   toEnvNum emptyState s =\n toEnvNum emptyState (predEnv s)\"\n  apply(induction s)\n         apply(auto)\n  done\n  (*\nproof(induction s)\n  case emptyState\n  then show ?case by auto\nnext\n  case (toEnv s)\n  then show ?case by auto\nnext\n  case (toCon s)\n  then show ?case \n  proof(cases)\n    assume \"toEnvP s\"\n    thus ?case by auto\n  next\n    assume 1: \"\\<not> toEnvP s\"\n    have 2: \"toEnvNum emptyState (toCon s) =\n toEnvNum emptyState s\" by auto\n    from 1 2 toCon.IH show ?case by auto\n  qed\nnext\n  case (setVarBool s v u)\n  then show ?case\n  then show ?case \n  proof(cases)\n    assume \"toEnvP s\"\n    thus ?case by auto\n  next\n    assume 1: \"\\<not> toEnvP s\"\n    have 2: \"toEnvNum emptyState (setVarBool s v u) =\n toEnvNum emptyState s\" by auto\n    from 1 2 setVarBool.IH show ?case by auto\n  qed\nnext\n  case (setVarInt s v u)\n  then show ?case \n  then show ?case \n  proof(cases)\n    assume \"toEnvP s\"\n    thus ?case by auto\n  next\n    assume 1: \"\\<not> toEnvP s\"\n    have 2: \"toEnvNum emptyState (setVarInt s v u) =\n toEnvNum emptyState s\" by auto\n    from 1 2 setVarInt.IH show ?case by auto\n  qed\nnext\n  case (setVarAny s u)\n  then show ?case \n  then show ?case \n  proof(cases)\n    assume \"toEnvP s\"\n    thus ?case by auto\n  next\n    assume 1: \"\\<not> toEnvP s\"\n    have 2: \"toEnvNum emptyState (setVarAny s u) =\n toEnvNum emptyState s\" by auto\n    from 1 2 setVarAny.IH show ?case by auto\n  qed\nnext\n  case (setPstate s p q)\n  then show ?case \n  proof(cases)\n    assume \"toEnvP s\"\n    thus ?case by auto\n  next\n    assume 1: \"\\<not> toEnvP s\"\n    have 2: \"toEnvNum emptyState (setPstate s p q) =\n toEnvNum emptyState s\" by auto\n    from 1 2 setPstate.IH show ?case by auto\n  qed\nnext\n  case (reset s p)\n  then show ?case \n  proof(cases)\n    assume \"toEnvP s\"\n    thus ?case by auto\n  next\n    assume 1: \"\\<not> toEnvP s\"\n    have 2: \"toEnvNum emptyState (reset s p) =\n toEnvNum emptyState s\" by auto\n    from 1 2 reset.IH show ?case by auto\n  qed\nqed\n*)\nlemma gtime_predE:\n\"toEnvP s \\<longrightarrow> toEnvNum emptyState s =\ntoEnvNum emptyState (predEnv s) + 1\"\nproof(induction s)\n  case emptyState\n  then show ?case by auto\nnext\n  case (toEnv s)\n  then show ?case \n  proof cases\n    assume \"toEnvP s\"\n    thus ?case by auto\n  next\n    assume 1: \"\\<not> toEnvP s\"\n    have \"toEnvNum emptyState (toEnv s) =\ntoEnvNum emptyState s + 1\" by auto\n    with 1 gtime_predI show ?thesis by auto\n  qed\nnext\n  case (toCon s)\n  then show ?case by auto\nnext\n  case (setVarBool s x2a x3a)\n  then show ?case by auto\nnext\n  case (setVarInt s x2a x3a)\n  then show ?case by auto\nnext\n  case (setVarAny s x2a)\n  then show ?case by auto\nnext\n  case (setPstate s x2a x3a)\n  then show ?case by auto\nnext\n  case (reset s x2a)\n  then show ?case by auto\nqed\n\nlemma predEnvPI: \"\\<not> toEnvP s \\<and>\ntoEnvNum emptyState s > 0 \\<longrightarrow>\ntoEnvP (predEnv s)\"\n  apply(induction s)\n         apply(auto)\n  done\n\nlemma predEnvP: \"toEnvNum emptyState s > 1 \\<Longrightarrow>\ntoEnvP (predEnv s)\"\nproof(induction s)\n  case emptyState\n  then show ?case by auto\nnext\n  case (toEnv s)\n  then show ?case \n  proof(cases)\n    assume \"toEnvP s\"\n    thus ?case by auto\n  next\n    assume 1: \"\\<not> toEnvP s\"\n    assume \"toEnvNum  emptyState (toEnv s) > 1\"\n    hence \"toEnvNum emptyState s > 0\" by auto\n    with 1  predEnvPI  show ?case by auto\n  qed\nnext\n  case (toCon s)\n  then show ?case\n  proof(cases)\n    assume \"toEnvP s\"\n    thus ?case by auto\n  next\n    assume 1: \"\\<not> toEnvP s\"\nassume \"toEnvNum  emptyState (toCon s) > 1\"\n  hence \"toEnvNum emptyState s > 1\" by auto\n  with 1 toCon.IH show ?case by auto\nqed\nnext\n  case (setVarBool s v u)\n  then show ?case \nproof(cases)\n    assume \"toEnvP s\"\n    thus ?case by auto\n  next\n    assume 1: \"\\<not> toEnvP s\"\nassume \"toEnvNum  emptyState (setVarBool s v u) > 1\"\n  hence \"toEnvNum emptyState s > 1\" by auto\n  with 1 setVarBool.IH show ?case by auto\nqed\nnext\n  case (setVarInt s v u)\n  then show ?case \nproof(cases)\n    assume \"toEnvP s\"\n    thus ?case by auto\n  next\n    assume 1: \"\\<not> toEnvP s\"\nassume \"toEnvNum  emptyState (setVarInt s v u) > 1\"\n  hence \"toEnvNum emptyState s > 1\" by auto\n  with 1 setVarInt.IH show ?case by auto\nqed\nnext\n  case (setVarAny s u)\n  then show ?case \nproof(cases)\n    assume \"toEnvP s\"\n    thus ?case by auto\n  next\n    assume 1: \"\\<not> toEnvP s\"\nassume \"toEnvNum  emptyState (setVarAny s u) > 1\"\n  hence \"toEnvNum emptyState s > 1\" by auto\n  with 1 setVarAny.IH show ?case by auto\nqed\nnext\n  case (setPstate s p q)\n  then show ?case \nproof(cases)\n    assume \"toEnvP s\"\n    thus ?case by auto\n  next\n    assume 1: \"\\<not> toEnvP s\"\nassume \"toEnvNum  emptyState (setPstate s p q) > 1\"\n  hence \"toEnvNum emptyState s > 1\" by auto\n  with 1 setPstate.IH show ?case by auto\nqed\nnext\n  case (reset s p)\n  then show ?case \nproof(cases)\n    assume \"toEnvP s\"\n    thus ?case by auto\n  next\n    assume 1: \"\\<not> toEnvP s\"\nassume \"toEnvNum  emptyState (reset s p) > 1\"\n  hence \"toEnvNum emptyState s > 1\" by auto\n  with 1 reset.IH show ?case by auto\nqed\nqed\n\n\nlemma shift_spec:\n \"toEnvP s \\<and> toEnvNum emptyState s > n \\<Longrightarrow>\ntoEnvP (shiftEnv s n) \\<and>\n toEnvNum emptyState (shiftEnv s n) =\n toEnvNum emptyState s - n\"\nproof(induction n)\n  case 0\n  then show ?case by auto\nnext\n  case (Suc n)\n  assume 1: \"toEnvP s \\<and>\n         Suc n < toEnvNum emptyState s\"\n  with Suc.IH\n  have \"toEnvNum emptyState (shiftEnv s n) > 1\"\n    by auto\n  with predEnvP have 2:\n \"toEnvP (shiftEnv s (Suc n))\"\n    by auto\n  from 1 Suc.IH have 3:  \"toEnvP (shiftEnv s n)\"\n    by auto\n  from 1 Suc.IH have\n \"toEnvNum emptyState (shiftEnv s n) =\ntoEnvNum emptyState s - n\" by auto\n  with 1 3  gtime_predE have\n\"toEnvNum emptyState (shiftEnv s (Suc n)) =\ntoEnvNum emptyState s - (Suc n)\" by auto\n  with 2 show ?case ..  \nqed\n\nlemma toEnvNum3: \"substate s1 s2 \\<and> substate s2 s3\n \\<Longrightarrow> toEnvNum s1 s3 = toEnvNum s1 s2 + toEnvNum s2 s3\"\n  proof(induction s3)\n    case emptyState\n    then show ?case by (cases s2; auto)\n  next\n    case (toEnv s3)\n    then show ?case \n    proof(cases)\n      assume \"s2= toEnv s3\"\n      thus ?case by auto\n    next\n      assume 1: \"s2 \\<noteq> toEnv s3\"\n      assume 2:  \"substate s1 s2 \\<and> substate s2 (toEnv s3)\"\n      with 1 have \"substate s2 s3\" by simp\n      show ?case\n      proof(cases)\n        assume \"s1 = toEnv s3\"\n        with 2 substate_asym[of \"(toEnv s3)\" s2]\n        have \"toEnv s3 = s2\" by auto\n        with 1 show ?case by auto\n      next\n        assume \"s1 \\<noteq> (toEnv s3)\"\n        with 1 2 toEnv.IH show?case by auto\n      qed\n    qed\n  next\n    case (toCon s3)\n    then show ?case\n    proof(cases)\n      assume \"s2= toCon s3\"\n      thus ?case by auto\n    next\n      assume 1: \"s2 \\<noteq> toCon s3\"\n      assume 2:  \"substate s1 s2 \\<and> substate s2 (toCon s3)\"\n      with 1 have \"substate s2 s3\" by simp\n      show ?case\n      proof(cases)\n        assume \"s1 = toCon s3\"\n        with 2 substate_asym[of \"(toCon s3)\" s2]\n        have \"toCon s3 = s2\" by auto\n        with 1 show ?case by auto\n      next\n        assume \"s1 \\<noteq> (toCon s3)\"\n        with 1 2 toCon.IH show?case by auto\n      qed\n    qed\n  next\n    case (setVarBool s3 v u)\n    then show ?case \n    proof(cases)\n      assume \"s2= setVarBool s3 v u\"\n      thus ?case by auto\n    next\n      assume 1: \"s2 \\<noteq> setVarBool s3 v u\"\n      assume 2:  \"substate s1 s2 \\<and> substate s2\n (setVarBool s3 v u)\"\n      with 1 have \"substate s2 s3\" by simp\n      show ?case\n      proof(cases)\n        assume \"s1 = setVarBool s3 v u\"\n        with 2 substate_asym[of \"(setVarBool s3 v u)\" s2]\n        have \"setVarBool s3 v u = s2\" by auto\n        with 1 show ?case by auto\n      next\n        assume \"s1 \\<noteq> (setVarBool s3 v u)\"\n        with 1 2 setVarBool.IH show?case by auto\n      qed\n    qed\n  next\n    case (setVarInt s3 v u)\n    then show ?case \n    proof(cases)\n      assume \"s2= setVarInt s3 v u\"\n      thus ?case by auto\n    next\n      assume 1: \"s2 \\<noteq> setVarInt s3 v u\"\n      assume 2:  \"substate s1 s2 \\<and> substate s2 (setVarInt s3 v u)\"\n      with 1 have \"substate s2 s3\" by simp\n      show ?case\n      proof(cases)\n        assume \"s1 = setVarInt s3 v u\"\n        with 2 substate_asym[of \"(setVarInt s3 v u)\" s2]\n        have \"setVarInt s3 v u = s2\" by auto\n        with 1 show ?case by auto\n      next\n        assume \"s1 \\<noteq> (setVarInt s3 v u)\"\n        with 1 2 setVarInt.IH show?case by auto\n      qed\n    qed\n  next\n    case (setVarAny s3 u)\n    then show ?case \n    proof(cases)\n      assume \"s2= setVarAny s3 u\"\n      thus ?case by auto\n    next\n      assume 1: \"s2 \\<noteq> setVarAny s3 u\"\n      assume 2:  \"substate s1 s2 \\<and> substate s2 (setVarAny s3 u)\"\n      with 1 have \"substate s2 s3\" by simp\n      show ?case\n      proof(cases)\n        assume \"s1 = setVarAny s3 u\"\n        with 2 substate_asym[of \"(setVarAny s3 u)\" s2]\n        have \"setVarAny s3 u = s2\" by auto\n        with 1 show ?case by auto\n      next\n        assume \"s1 \\<noteq> (setVarAny s3 u)\"\n        with 1 2 setVarAny.IH show?case by auto\n      qed\n    qed\n  next\n    case (setPstate s3 p q)\n    then show ?case \n    proof(cases)\n      assume \"s2= setPstate s3 p q\"\n      thus ?case by auto\n    next\n      assume 1: \"s2 \\<noteq> setPstate s3 p q\"\n      assume 2:  \"substate s1 s2 \\<and> substate s2 (setPstate s3 p q)\"\n      with 1 have \"substate s2 s3\" by simp\n      show ?case\n      proof(cases)\n        assume \"s1 = setPstate s3 p q\"\n        with 2 substate_asym[of \"(setPstate s3 p q)\" s2]\n        have \"setPstate s3 p q = s2\" by auto\n        with 1 show ?case by auto\n      next\n        assume \"s1 \\<noteq> (setPstate s3 p q)\"\n        with 1 2 setPstate.IH show?case by auto\n      qed\n    qed\n  next\n    case (reset s3 p)\n    then show ?case \n    proof(cases)\n      assume \"s2= reset s3 p\"\n      thus ?case by auto\n    next\n      assume 1: \"s2 \\<noteq> reset s3 p\"\n      assume 2:  \"substate s1 s2 \\<and> substate s2 (reset s3 p)\"\n      with 1 have \"substate s2 s3\" by simp\n      show ?case\n      proof(cases)\n        assume \"s1 = reset s3 p\"\n        with 2 substate_asym[of \"(reset s3 p)\" s2]\n        have \"reset s3 p = s2\" by auto\n        with 1 show ?case by auto\n      next\n        assume \"s1 \\<noteq> (reset s3 p)\"\n        with 1 2 reset.IH show?case by auto\n      qed\n    qed\n  qed\n\nlemma emptyState_substate: \"substate emptyState s\"\n  apply(induction s)\n         apply(auto)\n  done\n\n\nlemma gtimeE_inj:\n\"substate s1 s \\<and> toEnvP s1 \\<and> toEnvP s \\<and>\ntoEnvNum emptyState s1 = toEnvNum emptyState s \\<longrightarrow>\ns1=s\"\nproof(cases s)\n  case emptyState\n  then show ?thesis by auto\nnext\n  case (toEnv s2)\n  then show ?thesis \n  proof cases\n    assume \"s1 =s\"\n    then show ?thesis by auto\n  next\n    assume 1:  \"s1 \\<noteq> s\"\n    show ?thesis \n    proof\n      assume 2: \"substate s1 s \\<and>\n    toEnvP s1 \\<and>\n    toEnvP s \\<and>\n    toEnvNum emptyState s1 =\n    toEnvNum emptyState s\"\n      with 1 toEnv have 3: \"substate s1 s2\" by auto\n      from toEnv have 4: \"substate s2 s\" \n        using substate_refl by auto\n      from 3 emptyState_substate toEnvNum3 \n      have 5:  \"toEnvNum emptyState s2 =\ntoEnvNum emptyState s1 + toEnvNum s1 s2\" by auto\n      from emptyState_substate 4 toEnvNum3 have 6:\n\"toEnvNum emptyState s = toEnvNum emptyState s2 + toEnvNum s2 s\"\n        by auto\n      with toEnv  have 7: \"toEnvNum s2 s > 0\" by auto\n      from 5 have\n \"toEnvNum emptyState s1 \\<le> toEnvNum emptyState s2\"\n        by auto\n      also from 6 7 have\n\"toEnvNum emptyState s2 < toEnvNum emptyState s\"\n        by auto\n      finally have \n \"toEnvNum emptyState s1 < toEnvNum emptyState s\" .\n      with 2 show\n\"substate s1 s \\<and>\n    toEnvP s1 \\<and>\n    toEnvP s \\<and>\n    toEnvNum emptyState s1 =\n    toEnvNum emptyState s \\<Longrightarrow> s1=s\" by auto\n    qed\n  qed\nnext\n  case (toCon x3)\n  then show ?thesis by auto\nnext\n  case (setVarBool x41 x42 x43)\n  then show ?thesis by auto\nnext\n  case (setVarInt x51 x52 x53)\n  then show ?thesis by auto\nnext\n  case (setVarAny x61 x62)\n  then show ?thesis by auto\nnext\n  case (setPstate x71 x72 x73)\n  then show ?thesis by auto\nnext\n  case (reset x81 x82)\n  then show ?thesis by auto\nqed\n\nlemma shiftEnv_substate: \"substate (shiftEnv s n) s\"\nproof(induction n)\n  case 0\n  then show ?case using substate_refl by auto\nnext\n  case (Suc n)\n  then have \"substate (predEnv (shiftEnv s n)) s\"\n    using predEnv_substate[of \"shiftEnv s n\"]\nsubstate_trans by blast\n  thus ?case by simp\nqed\n\nlemma toEnvNum_shift: \"toEnvP s \\<and>\ntoEnvNum emptyState s > n\n  \\<Longrightarrow> toEnvNum (shiftEnv s n) s = n\"\nproof -\n  assume 1: \"toEnvP s \\<and> toEnvNum emptyState s > n\"\n  have 2:  \"toEnvNum emptyState s =\ntoEnvNum emptyState (shiftEnv s n) +\ntoEnvNum (shiftEnv s n) s\" \n    using emptyState_substate toEnvNum3 \nshiftEnv_substate by auto\n  with 1 shift_spec show ?thesis by force\nqed\n\nlemma substate_shift:\n\"toEnvP s1 \\<and> toEnvP s \\<and> substate s1 s \\<and> \ntoEnvNum s1 s \\<ge> n \\<Longrightarrow> \nsubstate s1 (shiftEnv s n)\"\nproof(induction n)\n  case 0\n  then show ?case by auto\nnext\n  case (Suc n)\n  then show ?case\n  proof -\n    assume 1:  \"toEnvP s1 \\<and>\n    toEnvP s \\<and>\n    substate s1 s \\<and> Suc n \\<le> toEnvNum s1 s\"\n    with Suc.IH have \"substate s1 (shiftEnv s n)\"\n      by auto\n    with 1 substate_eq_or_predEnv have\n\"s1 = shiftEnv s n \\<or> \nsubstate s1 (predEnv (shiftEnv s n))\" by auto\n    then show ?case\n    proof\n      assume 2: \"s1 = shiftEnv s n\"\n      with 1 emptyState_substate[of s1]  toEnvNum3\n      have  \"toEnvNum emptyState s > n\" by force\n      with 1 toEnvNum_shift have\n\"toEnvNum (shiftEnv s n) s = n\" by auto\n      with 1 2 show ?case by auto\n    next\n      assume \"substate s1 (predEnv (shiftEnv s n))\"\n      thus ?case by simp  \n    qed\n  qed\nqed\n\nlemma predEnvP_or_emptyState:\n\"toEnvP (predEnv s) \\<or> predEnv s = emptyState\"\n  apply(induction s)\n         apply(auto)\n  done\n\nlemma shiftEnvP_or_emptyState: \"n \\<noteq> 0 \\<longrightarrow>\n toEnvP (shiftEnv s n) \\<or> shiftEnv s n = emptyState\"\n  apply(cases n)\n  using predEnvP_or_emptyState by auto\n\nlemma shift_toEnvNum: \n\"toEnvP s \\<and> toEnvP s1 \\<and> substate s1 s \\<Longrightarrow>\nshiftEnv s (toEnvNum s1 s) = s1\"\nproof -\n  define s2:: state where\n \"s2 = shiftEnv s (toEnvNum s1 s)\"\n  assume 1: \"toEnvP s \\<and> toEnvP s1 \\<and> substate s1 s\"\n  with s2_def substate_shift have 2: \n\"substate s1 s2\" by auto\n  from 1 have \"toEnvNum emptyState s1 > 0\"\n    by (cases s1; auto)\n  with 1 emptyState_substate[of s1] toEnvNum3 have\n\"toEnvNum s1 s < toEnvNum emptyState s\" by force\n  with 1 shift_spec s2_def have \n\"toEnvNum emptyState s2 = \ntoEnvNum emptyState s - toEnvNum s1 s\" by auto\n  also from 1 emptyState_substate[of s1] toEnvNum3\n  have \"toEnvNum  emptyState s - toEnvNum s1 s = \ntoEnvNum emptyState s1\" by force\n  finally have 3:\n \"toEnvNum emptyState s2 = toEnvNum emptyState s1\"\n    .\n  show ?thesis\n  proof(cases)\n    assume 4: \"toEnvNum s1 s = 0\"\n    with 1 substate_toEnvNum_id have \"s1=s\"\n      by blast\n    with 1 show ?thesis using toEnvNum_id  by auto\n  next\n    assume \"toEnvNum s1 s \\<noteq> 0\"\n    with s2_def shiftEnvP_or_emptyState have\n\"toEnvP s2 \\<or> s2 = emptyState\" by auto\n    hence \"toEnvP s2\" \n    proof\n      assume \"toEnvP s2\"\n      thus ?thesis by assumption\n    next\n      assume \"s2 = emptyState\"\n      with 2 have \"s1=emptyState\"\n        by (cases s1; auto)\n      with 1 show ?thesis by auto\n    qed\n    with 1 2 3[symmetric]  gtimeE_inj\n    have \"s1=s2\" by blast\n    with s2_def show ?thesis by simp\n  qed\nqed\n\nlemma ltime_le_toEnvNum: \n\"ltimeEnv s p \\<le> toEnvNum emptyState s\"\n  apply(induction s)\n         apply(auto)\n  done\n\n(*\nlemma partitioning:\n\"substate s1 s2 \\<and> substate s2 s3 \\<and> substate s1 s \\<and>\nsubstate s s3 \\<longrightarrow> substate s1 s \\<and> substate s s2 \\<or>\nsubstate s2 s \\<and> substate s s3\"\n  using substate_total by blast\n*)\n\nlemma predEnv_substate_imp_eq_or_substate:\n\"toEnvP s1 \\<and> toEnvP s2 \\<and> substate s1 s \\<and>\n substate s2 s \\<and> substate (predEnv s1) s2 \\<longrightarrow> \ns2 = predEnv s1 \\<or> substate s1 s2\"\nproof cases\n  assume \"s1 = s2\"\n  with substate_refl show ?thesis by auto\nnext \n  assume 1: \"s1 \\<noteq> s2\"\n  show ?thesis\n  proof\n    assume 2: \"toEnvP s1 \\<and>\n    toEnvP s2 \\<and>\n    substate s1 s \\<and>\n    substate s2 s \\<and> substate (predEnv s1) s2 \"\n    with substate_total \n    have \"substate s1 s2 \\<or> substate s2 s1\" by auto\n    thus \" s2 = predEnv s1 \\<or> substate s1 s2\"\n    proof\n      assume \"substate s1 s2\" \n      thus ?thesis by auto\n    next\n      assume \"substate s2 s1\"\n      with 1 substate_eq_or_predEnv 2 substate_asym\n      show ?thesis by auto\n    qed\n  qed\nqed\n\nlemma state_down_ind: \n\"toEnvP s \\<and> toEnvP s1 \\<Longrightarrow> P s \\<Longrightarrow>\n (\\<And> s2. toEnvP s2 \\<Longrightarrow>\n (substate s1 s2 \\<and> substate s2 s \\<and> s1 \\<noteq> s2)\n \\<Longrightarrow> P s2 \\<Longrightarrow> P (predEnv s2)) \\<Longrightarrow>\ntoEnvP s2 \\<and> substate s1 s2 \\<and> substate s2 s \\<longrightarrow>\n P s2\"\nproof -\n  assume 1: \"toEnvP s \\<and> toEnvP s1\"\n  define Q:: \"nat \\<Rightarrow> bool\" where \n\"Q = (\\<lambda> n. P (shiftEnv s n))\"\n  from Q_def  1 shift_toEnvNum have P_def:\n\"\\<And> s'. toEnvP s' \\<and> substate s' s \\<Longrightarrow> \nP s' = Q (toEnvNum s' s)\" by auto\n  define n where \"n = toEnvNum s2 s\"\n  assume base: \"P s\" and ind_step:\n\"\\<And> s2. toEnvP s2 \\<Longrightarrow>\n (substate s1 s2 \\<and> substate s2 s \\<and> s1 \\<noteq> s2)\n \\<Longrightarrow> P s2 \\<Longrightarrow> P (predEnv s2)\"\n  show ?thesis\n  proof\n    assume 2: \"toEnvP s2 \\<and> substate s1 s2 \\<and>\n substate s2 s\"\n    with 1  n_def shift_toEnvNum have s2_def: \"s2 = shiftEnv s n\"\n      by auto\n     from 2 show \"P s2\"\n      apply(simp only: P_def n_def[symmetric])\n      apply(simp only: s2_def)\n    proof(induction n)\n      case 0\n      then show ?case using Q_def base by auto\n    next\n      case (Suc n)\n      then show ?case \n        apply(simp only: Q_def)\n        print_state\n      proof cases\n        assume 3: \"s1 = shiftEnv s n\"\n        assume 4: \"toEnvP (shiftEnv s (Suc n)) \\<and>\n    substate s1 (shiftEnv s (Suc n)) \\<and>\n    substate (shiftEnv s (Suc n)) s\"\n        from 3 have 5: \"substate (shiftEnv s n) s1\"\n          using substate_refl by auto\n        from predEnv_substate have\n\"substate (shiftEnv s (Suc n)) (shiftEnv s n)\"\n          by simp\n        with 4 5  substate_asym substate_trans\n        have \"s1 = shiftEnv s (Suc n)\"\n          by blast\n        with 3 have\n \"shiftEnv s n = shiftEnv s (Suc n)\" by simp\n        with 4 gtime_predE show\n \"P (shiftEnv s (Suc n))\" by fastforce\n      next\n        assume 3: \"s1 \\<noteq> shiftEnv s n\"\n        assume 4: \"toEnvP (shiftEnv s (Suc n)) \\<and>\n    substate s1 (shiftEnv s (Suc n)) \\<and>\n    substate (shiftEnv s (Suc n)) s\"\nfrom predEnv_substate have\n\"substate (shiftEnv s (Suc n)) (shiftEnv s n)\"\n  by simp\n  with 4 substate_trans have 5:\n \"substate s1 (shiftEnv s n)\" by blast\n  have 6: \"toEnvP (shiftEnv s n)\"\n  proof cases\n    assume \"n = 0\"\n    with 1 show ?thesis by auto\n  next \n    assume \"n \\<noteq> 0\"\n    with shiftEnvP_or_emptyState have\n\"toEnvP (shiftEnv s n) \\<or>\n (shiftEnv s n) =  emptyState\" by auto\n    thus ?thesis\n    proof\n      assume \"toEnvP (shiftEnv s n)\"\n      thus ?thesis by assumption\n    next\n      assume \"shiftEnv s n = emptyState\"\n      with 5 have \"s1 = emptyState\"\n        by (cases s1; auto)\n      with 1 show ?thesis by auto\n    qed\n  qed\n  assume \"(toEnvP (shiftEnv s n) \\<and>\n     substate s1 (shiftEnv s n) \\<and>\n     substate (shiftEnv s n) s \\<Longrightarrow>\n     P (shiftEnv s n))\"\n  with 3 5 6 shiftEnv_substate ind_step\n  show \"P (shiftEnv s (Suc n))\"\n    by auto\nqed\nqed\nqed\nqed\n\nend\n", "meta": {"author": "ivchernenko", "repo": "post_vcgenerator", "sha": "fadfff131086870a027d6bd1c78b8d5a3baf183b", "save_path": "github-repos/isabelle/ivchernenko-post_vcgenerator", "path": "github-repos/isabelle/ivchernenko-post_vcgenerator/post_vcgenerator-fadfff131086870a027d6bd1c78b8d5a3baf183b/case-studies/trafficLights/VCTheoryLemmas.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.519521321952093, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.2820290505130333}}
{"text": "subsection \\<open> UTP theory of Designs \\<close>\n\ntheory utp_des_theory\n  imports utp_des_healths\nbegin\n  \nsubsection \\<open> UTP theories \\<close>\n\ninterpretation des_theory: utp_theory_continuous \"\\<^bold>H\"\n  rewrites \"P \\<in> carrier des_theory.thy_order \\<longleftrightarrow> P is \\<^bold>H\"\n  and \"carrier des_theory.thy_order \\<rightarrow> carrier des_theory.thy_order \\<equiv> \\<lbrakk>\\<^bold>H\\<rbrakk>\\<^sub>H \\<rightarrow> \\<lbrakk>\\<^bold>H\\<rbrakk>\\<^sub>H\"\n  and \"le des_theory.thy_order = (\\<sqsubseteq>)\"\n  and \"eq des_theory.thy_order = (=)\"  \n  and des_top: \"des_theory.utp_top = \\<top>\\<^sub>D\"\n  and des_bottom: \"des_theory.utp_bottom = \\<bottom>\\<^sub>D\"\nproof -\n  show \"utp_theory_continuous \\<^bold>H\"\n    by (unfold_locales, simp_all add: H1_H2_idempotent H1_H2_Continuous)\n  then interpret utp_theory_continuous \"\\<^bold>H\"\n    by simp\n  show \"utp_top = \\<top>\\<^sub>D\" \"utp_bottom = \\<bottom>\\<^sub>D\"\n    by (simp_all add: H1_H2_false healthy_top H1_H2_true healthy_bottom)\nqed (simp_all)\n\ninterpretation ndes_theory: utp_theory_continuous \"\\<^bold>N\"\n  rewrites \"P \\<in> carrier ndes_theory.thy_order \\<longleftrightarrow> P is \\<^bold>N\"\n  and \"carrier ndes_theory.thy_order \\<rightarrow> carrier ndes_theory.thy_order \\<equiv> \\<lbrakk>\\<^bold>N\\<rbrakk>\\<^sub>H \\<rightarrow> \\<lbrakk>\\<^bold>N\\<rbrakk>\\<^sub>H\"\n  and \"le ndes_theory.thy_order = (\\<sqsubseteq>)\"\n  and \"eq ndes_theory.thy_order = (=)\"  \n  and ndes_top: \"ndes_theory.utp_top = \\<top>\\<^sub>D\"\n  and ndes_bottom: \"ndes_theory.utp_bottom = \\<bottom>\\<^sub>D\"\nproof -\n  show \"utp_theory_continuous \\<^bold>N\"\n    by (unfold_locales, simp_all add: H1_H3_idempotent H1_H3_Continuous)\n  then interpret utp_theory_continuous \"\\<^bold>N\"\n    by simp\n  show \"utp_top = \\<top>\\<^sub>D\" \"utp_bottom = \\<bottom>\\<^sub>D\"\n    by (simp_all add: H1_H3_false healthy_top H1_H3_true healthy_bottom)\nqed (simp_all)\n\ninterpretation des_left_unital: utp_theory_left_unital \"\\<^bold>H\" \"II\\<^sub>D\"\n  by (unfold_locales, simp_all add: H1_H2_left_unit closure)\n\ninterpretation ndes_unital: utp_theory_unital \"\\<^bold>N\" \"II\\<^sub>D\"\n  by (unfold_locales, simp_all add: H1_H3_left_unit H1_H3_right_unit closure)\n\ninterpretation ndes_kleene: utp_theory_kleene \"\\<^bold>N\" \"II\\<^sub>D\"\n  by (unfold_locales, simp add: ndes_top H1_H3_top_left)\n\nabbreviation ndes_star :: \"_ \\<Rightarrow> _\"  (\"_\\<^sup>\\<star>\\<^sup>D\" [999] 999) where\n\"P\\<^sup>\\<star>\\<^sup>D \\<equiv> ndes_unital.utp_star\"\n\nsubsection \\<open> Galois Connection \\<close>\n\ntext \\<open> Example Galois connection between designs and relations. Based on Jim's example in COMPASS\n        deliverable D23.5. \\<close>\n\ndefinition [upred_defs]: \"Des(R) = \\<^bold>H(\\<lceil>R\\<rceil>\\<^sub>D \\<and> $ok\\<acute>)\"\ndefinition [upred_defs]: \"Rel(D) = \\<lfloor>D\\<lbrakk>true,true/$ok,$ok\\<acute>\\<rbrakk>\\<rfloor>\\<^sub>D\"\n\nlemma Des_design: \"Des(R) = true \\<turnstile>\\<^sub>r R\"\n  by (rel_auto)\n\nlemma Rel_design: \"Rel(P \\<turnstile>\\<^sub>r Q) = (P \\<Rightarrow> Q)\"\n  by (rel_auto)\n\ninterpretation Des_Rel_coretract:\n  coretract \"\\<^bold>H \\<Leftarrow>\\<langle>Des,Rel\\<rangle>\\<Rightarrow> id\"\n  rewrites\n    \"\\<And> x. x \\<in> carrier \\<X>\\<^bsub>\\<^bold>H \\<Leftarrow>\\<langle>Des,Rel\\<rangle>\\<Rightarrow> id\\<^esub> = (x is \\<^bold>H)\" and\n    \"\\<And> x. x \\<in> carrier \\<Y>\\<^bsub>\\<^bold>H \\<Leftarrow>\\<langle>Des,Rel\\<rangle>\\<Rightarrow> id\\<^esub> = True\" and\n    \"\\<pi>\\<^sub>*\\<^bsub>\\<^bold>H \\<Leftarrow>\\<langle>Des,Rel\\<rangle>\\<Rightarrow> id\\<^esub> = Des\" and\n    \"\\<pi>\\<^sup>*\\<^bsub>\\<^bold>H \\<Leftarrow>\\<langle>Des,Rel\\<rangle>\\<Rightarrow> id\\<^esub> = Rel\" and\n    \"le \\<X>\\<^bsub>\\<^bold>H \\<Leftarrow>\\<langle>Des,Rel\\<rangle>\\<Rightarrow> id\\<^esub> = (\\<sqsubseteq>)\" and\n    \"le \\<Y>\\<^bsub>\\<^bold>H \\<Leftarrow>\\<langle>Des,Rel\\<rangle>\\<Rightarrow> id\\<^esub> = (\\<sqsubseteq>)\"\nproof (unfold_locales, simp_all)\n  show \"\\<And>x. x is id\"\n    by (simp add: Healthy_def)\nnext\n  show \"Rel \\<in> \\<lbrakk>\\<^bold>H\\<rbrakk>\\<^sub>H \\<rightarrow> \\<lbrakk>id\\<rbrakk>\\<^sub>H\"\n    by (auto simp add: Rel_def Healthy_def)\nnext\n  show \"Des \\<in> \\<lbrakk>id\\<rbrakk>\\<^sub>H \\<rightarrow> \\<lbrakk>\\<^bold>H\\<rbrakk>\\<^sub>H\"\n    by (auto simp add: Des_def Healthy_def H1_H2_commute H1_idem H2_idem)\nnext\n  fix R :: \"('a, 'b) urel\"\n  show \"R \\<sqsubseteq> Rel (Des R)\"\n    by (simp add: Des_design Rel_design)\nnext\n  fix R :: \"('a, 'b) urel\" and D :: \"('a, 'b) rel_des\"\n  assume a: \"D is \\<^bold>H\"\n  then obtain D\\<^sub>1 D\\<^sub>2 where D: \"D = D\\<^sub>1 \\<turnstile>\\<^sub>r D\\<^sub>2\"\n    by (metis H1_H2_commute H1_H2_is_rdesign H1_idem Healthy_def')\n  show \"(Rel D \\<sqsubseteq> R) = (D \\<sqsubseteq> Des R)\"\n  proof -\n    have \"(D \\<sqsubseteq> Des R) = (D\\<^sub>1 \\<turnstile>\\<^sub>r D\\<^sub>2 \\<sqsubseteq> true \\<turnstile>\\<^sub>r R)\"\n      by (simp add: D Des_design)\n    also have \"... = `D\\<^sub>1 \\<and> R \\<Rightarrow> D\\<^sub>2`\"\n      by (simp add: rdesign_refinement)\n    also have \"... = ((D\\<^sub>1 \\<Rightarrow> D\\<^sub>2) \\<sqsubseteq> R)\"\n      by (rel_auto)\n    also have \"... = (Rel D \\<sqsubseteq> R)\"\n      by (simp add: D Rel_design)\n    finally show ?thesis ..\n  qed\nqed\n\n\ntext \\<open> From this interpretation we gain many Galois theorems. Some require simplification to\n        remove superfluous assumptions. \\<close>\n\nthm Des_Rel_coretract.deflation[simplified]\nthm Des_Rel_coretract.inflation\nthm Des_Rel_coretract.upper_comp[simplified]\nthm Des_Rel_coretract.lower_comp\n\nsubsection \\<open> Fixed Points \\<close>\n\nnotation des_theory.utp_lfp (\"\\<mu>\\<^sub>D\")\nnotation des_theory.utp_gfp (\"\\<nu>\\<^sub>D\")\n\nnotation ndes_theory.utp_lfp (\"\\<mu>\\<^sub>N\")\nnotation ndes_theory.utp_gfp (\"\\<nu>\\<^sub>N\")\n\nutp_const des_theory.utp_lfp des_theory.utp_gfp\n  ndes_theory.utp_lfp ndes_theory.utp_gfp\n\nsyntax\n  \"_dmu\" :: \"pttrn \\<Rightarrow> logic \\<Rightarrow> logic\" (\"\\<mu>\\<^sub>D _ \\<bullet> _\" [0, 10] 10)\n  \"_dnu\" :: \"pttrn \\<Rightarrow> logic \\<Rightarrow> logic\" (\"\\<nu>\\<^sub>D _ \\<bullet> _\" [0, 10] 10)\n  \"_ndmu\" :: \"pttrn \\<Rightarrow> logic \\<Rightarrow> logic\" (\"\\<mu>\\<^sub>N _ \\<bullet> _\" [0, 10] 10)\n  \"_ndnu\" :: \"pttrn \\<Rightarrow> logic \\<Rightarrow> logic\" (\"\\<nu>\\<^sub>N _ \\<bullet> _\" [0, 10] 10)\n\ntranslations\n  \"\\<mu>\\<^sub>D X \\<bullet> P\" == \"\\<mu>\\<^sub>D (\\<lambda> X. P)\"\n  \"\\<nu>\\<^sub>D X \\<bullet> P\" == \"\\<nu>\\<^sub>D (\\<lambda> X. P)\"\n  \"\\<mu>\\<^sub>N X \\<bullet> P\" == \"\\<mu>\\<^sub>N (\\<lambda> X. P)\"\n  \"\\<nu>\\<^sub>N X \\<bullet> P\" == \"\\<nu>\\<^sub>N (\\<lambda> X. P)\"\n\nthm des_theory.LFP_unfold\nthm des_theory.GFP_unfold\n\ntext \\<open> Specialise @{thm [source] mu_refine_intro} to designs. \\<close>\n\nlemma design_mu_refine_intro:\n  assumes \"$ok\\<acute> \\<sharp> C\" \"$ok\\<acute> \\<sharp> S\" \"(C \\<turnstile> S) \\<sqsubseteq> F(C \\<turnstile> S)\" \"`C \\<Rightarrow> (\\<mu>\\<^sub>D F \\<Leftrightarrow> \\<nu>\\<^sub>D F)`\"\n  shows \"(C \\<turnstile> S) \\<sqsubseteq> \\<mu>\\<^sub>D F\"\nproof -\n  from assms have \"(C \\<turnstile> S) \\<sqsubseteq> \\<nu>\\<^sub>D F\"\n    by (simp add: design_is_H1_H2 des_theory.GFP_upperbound)\n  with assms show ?thesis\n    by (rel_auto, metis (no_types, lifting))\nqed\n\nlemma rdesign_mu_refine_intro:\n  assumes \"(C \\<turnstile>\\<^sub>r S) \\<sqsubseteq> F(C \\<turnstile>\\<^sub>r S)\" \"`\\<lceil>C\\<rceil>\\<^sub>D \\<Rightarrow> (\\<mu>\\<^sub>D F \\<Leftrightarrow> \\<nu>\\<^sub>D F)`\"\n  shows \"(C \\<turnstile>\\<^sub>r S) \\<sqsubseteq> \\<mu>\\<^sub>D F\"\n  using assms by (simp add: rdesign_def design_mu_refine_intro unrest)\n\nlemma H1_H2_mu_refine_intro:\n  assumes \"P is \\<^bold>H\" \"P \\<sqsubseteq> F(P)\" \"`\\<lceil>pre\\<^sub>D(P)\\<rceil>\\<^sub>D \\<Rightarrow> (\\<mu>\\<^sub>D F \\<Leftrightarrow> \\<nu>\\<^sub>D F)`\"\n  shows \"P \\<sqsubseteq> \\<mu>\\<^sub>D F\"\n  by (metis H1_H2_eq_rdesign Healthy_if assms rdesign_mu_refine_intro)\n\ntext \\<open> Foundational theorem for recursion introduction using a well-founded relation. Contributed\n  by Dr. Yakoub Nemouchi. \\<close>\n\ntheorem rdesign_mu_wf_refine_intro: \n  assumes   WF: \"wf R\"\n    and      M: \"Monotonic F\"\n    and      H: \"F \\<in> \\<lbrakk>\\<^bold>H\\<rbrakk>\\<^sub>H \\<rightarrow> \\<lbrakk>\\<^bold>H\\<rbrakk>\\<^sub>H\"\n    and  induct_step:\n    \"\\<And>st. (P \\<and> \\<lceil>e\\<rceil>\\<^sub>< =\\<^sub>u \\<guillemotleft>st\\<guillemotright>) \\<turnstile>\\<^sub>r Q \\<sqsubseteq> F ((P \\<and> (\\<lceil>e\\<rceil>\\<^sub><, \\<guillemotleft>st\\<guillemotright>)\\<^sub>u \\<in>\\<^sub>u \\<guillemotleft>R\\<guillemotright>) \\<turnstile>\\<^sub>r Q)\"\n  shows \"(P \\<turnstile>\\<^sub>r Q) \\<sqsubseteq> \\<mu>\\<^sub>D F\"            \nproof -          \n  {\n  fix st\n  have \"(P \\<and> \\<lceil>e\\<rceil>\\<^sub>< =\\<^sub>u \\<guillemotleft>st\\<guillemotright>) \\<turnstile>\\<^sub>r Q \\<sqsubseteq> \\<mu>\\<^sub>D F\" \n  using WF proof (induction rule: wf_induct_rule)\n    case (less st)\n    hence 0: \"(P \\<and> (\\<lceil>e\\<rceil>\\<^sub><, \\<guillemotleft>st\\<guillemotright>)\\<^sub>u \\<in>\\<^sub>u \\<guillemotleft>R\\<guillemotright>) \\<turnstile>\\<^sub>r Q \\<sqsubseteq> \\<mu>\\<^sub>D F\"\n      by rel_blast\n    from M H\n    have 1: \"\\<mu>\\<^sub>D F \\<sqsubseteq>  F (\\<mu>\\<^sub>D F)\"\n      by (simp add: des_theory.LFP_lemma3 mono_Monotone_utp_order)\n    from 0 1 have 2:\"(P \\<and> (\\<lceil>e\\<rceil>\\<^sub><,\\<guillemotleft>st\\<guillemotright>)\\<^sub>u\\<in>\\<^sub>u\\<guillemotleft>R\\<guillemotright>) \\<turnstile>\\<^sub>r Q \\<sqsubseteq> F (\\<mu>\\<^sub>D F)\"\n      by simp\n    have 3: \"F ((P \\<and> (\\<lceil>e\\<rceil>\\<^sub><, \\<guillemotleft>st\\<guillemotright>)\\<^sub>u \\<in>\\<^sub>u \\<guillemotleft>R\\<guillemotright>) \\<turnstile>\\<^sub>r Q) \\<sqsubseteq> F (\\<mu>\\<^sub>D F)\"\n      by (simp add: 0 M monoD)\n    have 4:\"(P \\<and> \\<lceil>e\\<rceil>\\<^sub>< =\\<^sub>u \\<guillemotleft>st\\<guillemotright>) \\<turnstile>\\<^sub>r Q \\<sqsubseteq> \\<dots>\" \n      by (rule induct_step)\n    show ?case\n      using order_trans[OF 3 4] H M des_theory.LFP_lemma2 dual_order.trans mono_Monotone_utp_order\n      by (metis (no_types) partial_object.simps(1) utp_order_def)\n  qed\n  }\n  thus ?thesis\n    by (pred_simp)\nqed  \n\ntheorem ndesign_mu_wf_refine_intro': \n  assumes   WF: \"wf R\"\n    and      M: \"Monotonic F\"\n    and      H: \"F \\<in> \\<lbrakk>\\<^bold>H\\<rbrakk>\\<^sub>H \\<rightarrow> \\<lbrakk>\\<^bold>H\\<rbrakk>\\<^sub>H\"\n    and  induct_step:\n    \"\\<And>st. ((p \\<and> e =\\<^sub>u \\<guillemotleft>st\\<guillemotright>) \\<turnstile>\\<^sub>n Q) \\<sqsubseteq> F ((p \\<and> (e, \\<guillemotleft>st\\<guillemotright>)\\<^sub>u \\<in>\\<^sub>u \\<guillemotleft>R\\<guillemotright>) \\<turnstile>\\<^sub>n Q)\"\n  shows \"(p \\<turnstile>\\<^sub>n Q) \\<sqsubseteq> \\<mu>\\<^sub>D F\"\n  using assms unfolding ndesign_def\n  by (rule_tac rdesign_mu_wf_refine_intro[of R F \"\\<lceil>p\\<rceil>\\<^sub><\" e], simp_all add: alpha)\n\ntheorem ndesign_mu_wf_refine_intro: \n  assumes   WF: \"wf R\"\n    and      M: \"Monotonic F\"\n    and      H: \"F \\<in> \\<lbrakk>\\<^bold>N\\<rbrakk>\\<^sub>H \\<rightarrow> \\<lbrakk>\\<^bold>N\\<rbrakk>\\<^sub>H\"\n    and  induct_step:\n    \"\\<And>st. ((p \\<and> e =\\<^sub>u \\<guillemotleft>st\\<guillemotright>) \\<turnstile>\\<^sub>n Q) \\<sqsubseteq> F ((p \\<and> (e, \\<guillemotleft>st\\<guillemotright>)\\<^sub>u \\<in>\\<^sub>u \\<guillemotleft>R\\<guillemotright>) \\<turnstile>\\<^sub>n Q)\"\n  shows \"(p \\<turnstile>\\<^sub>n Q) \\<sqsubseteq> \\<mu>\\<^sub>N F\"\nproof -          \n  {\n  fix st\n  have \"(p \\<and> e =\\<^sub>u \\<guillemotleft>st\\<guillemotright>) \\<turnstile>\\<^sub>n Q \\<sqsubseteq> \\<mu>\\<^sub>N F\" \n  using WF proof (induction rule: wf_induct_rule)\n    case (less st)\n    hence 0: \"(p \\<and> (e, \\<guillemotleft>st\\<guillemotright>)\\<^sub>u \\<in>\\<^sub>u \\<guillemotleft>R\\<guillemotright>) \\<turnstile>\\<^sub>n Q \\<sqsubseteq> \\<mu>\\<^sub>N F\"\n      by rel_blast\n    from M H des_theory.LFP_lemma3 mono_Monotone_utp_order\n    have 1: \"\\<mu>\\<^sub>N F \\<sqsubseteq>  F (\\<mu>\\<^sub>N F)\"\n      by (simp add: mono_Monotone_utp_order ndes_theory.LFP_lemma3)\n    from 0 1 have 2:\"(p \\<and> (e, \\<guillemotleft>st\\<guillemotright>)\\<^sub>u\\<in>\\<^sub>u\\<guillemotleft>R\\<guillemotright>) \\<turnstile>\\<^sub>n Q \\<sqsubseteq> F (\\<mu>\\<^sub>N F)\"\n      by simp\n    have 3: \"F ((p \\<and> (e, \\<guillemotleft>st\\<guillemotright>)\\<^sub>u \\<in>\\<^sub>u \\<guillemotleft>R\\<guillemotright>) \\<turnstile>\\<^sub>n Q) \\<sqsubseteq> F (\\<mu>\\<^sub>N F)\"\n      by (simp add: 0 M monoD)\n    have 4:\"(p \\<and> e =\\<^sub>u \\<guillemotleft>st\\<guillemotright>) \\<turnstile>\\<^sub>n Q \\<sqsubseteq> \\<dots>\" \n      by (rule induct_step)\n    show ?case\n      using order_trans[OF 3 4] H M ndes_theory.LFP_lemma2 dual_order.trans mono_Monotone_utp_order \n      by (metis (no_types) partial_object.simps(1) utp_order_def)\n  qed\n  }\n  thus ?thesis\n    by (pred_simp)\nqed  \n\nend", "meta": {"author": "isabelle-utp", "repo": "utp-main", "sha": "27bdf3aee6d4fc00c8fe4d53283d0101857e0d41", "save_path": "github-repos/isabelle/isabelle-utp-utp-main", "path": "github-repos/isabelle/isabelle-utp-utp-main/utp-main-27bdf3aee6d4fc00c8fe4d53283d0101857e0d41/theories/designs/utp_des_theory.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.519521321952093, "lm_q2_score": 0.5428632831725052, "lm_q1q2_score": 0.2820290505130333}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory fncall\nimports \"CParser.CTranslation\"\nbegin\n\ndeclare sep_conj_ac [simp add]\n\nprimrec\n  fac :: \"nat \\<Rightarrow> nat\"\nwhere\n  \"fac 0 = 1\"\n| \"fac (Suc n) = (Suc n) * fac n\"\n\nML \\<open>\n\nval ast = IsarInstall.get_Csyntax @{theory} \"fncall.c\"\n\n\\<close>\n\nexternal_file \"fncall.c\"\ninstall_C_file \"fncall.c\"\n\ncontext fncall\nbegin\n\n\nthm \"\\<Gamma>_def\"\nthm has_bogus_spec_'proc_def\nthm has_bogus_spec_impl\nthm f_impl\nthm g_impl\nthm h_impl\nthm i_impl\nthm calls_bogus_impl\nthm f_body_def\nthm g_body_def\nthm fact_body_def\n\nthm fact_'proc_def\n\nthm has_bogus_spec_modifies\nthm g_modifies\nthm f_modifies\nthm fact_modifies\n\nterm \"f_body\"\nterm \"\\<Gamma>\"\nterm \"fact_body\"\nterm \"f_'proc\"\n\nend\n\nprint_locale fncall_global_addresses\n\nprint_locale g_modifies\nthm g_modifies_def\n\nprint_locale f_spec\nthm f_spec_def\n\nlemma (in g_modifies)\n  shows \"\\<Gamma> \\<turnstile> \\<lbrace> \\<acute>t_hrs = t \\<rbrace> \\<acute>ret__int :== PROC g() \\<lbrace> \\<acute>t_hrs = t \\<rbrace>\"\napply (hoare_rule HoarePartial.ProcRec1)\napply (vcg spec=modifies)\ndone\n\n\nlemma (in fncall_global_addresses) f_impl_result:\n  \"\\<Gamma> f_'proc = Some f_body\"\n  apply (rule f_impl)\n  done\n\nlemma (in fncall_global_addresses) g_spec:\n  shows\n  \"\\<Gamma> \\<turnstile> \\<lbrace> True \\<rbrace> \\<acute>ret__int :== PROC g() \\<lbrace> \\<acute>ret__int = 257 \\<rbrace>\"\n  apply vcg\n  done\n\nlemma (in fncall_global_addresses) foo:\n  shows\n   \"\\<Gamma> \\<turnstile> \\<lbrace> True \\<rbrace> \\<acute>ret__int :== PROC f(n) \\<lbrace> \\<acute>ret__int = 1 \\<rbrace>\"\napply vcg\napply (simp )\ndone\n\nlemma (in f_spec) foo :\nshows\n  \"\\<Gamma> \\<turnstile> \\<lbrace> True \\<rbrace> \\<acute>ret__int :== CALL f(\\<acute>n) \\<lbrace> \\<acute>ret__int = 1 \\<rbrace>\"\n\napply vcg\ndone\n\nlemma (in fncall_global_addresses) bar:\nshows \"\\<Gamma> \\<turnstile> \\<lbrace> 1\\<le> \\<acute>n & \\<acute>n \\<le> 12 \\<rbrace> \\<acute>ret__int :== CALL fact(\\<acute>n) \\<lbrace> \\<acute>ret__int = of_nat (fac (unat \\<acute>n)) \\<rbrace>\"\napply vcg\napply unat_arith\noops\n\nlemma (in fncall_global_addresses) baz:\nshows \"\\<Gamma> \\<turnstile>\\<^bsub>/UNIV\\<^esub> \\<lbrace> \\<acute>t_hrs = t \\<rbrace> \\<acute>ret__int :== PROC i() \\<lbrace> \\<acute>t_hrs = t \\<rbrace>\"\napply (hoare_rule HoarePartial.ProcRec1)\napply (vcg spec=modifies)\ndone\n\nlocale ih = i_modifies + h_modifies\nlemma (in ih) qux:\nshows \"\\<forall>t. \\<Gamma> \\<turnstile> \\<lbrace>\\<acute>t_hrs = t\\<rbrace> \\<acute>ret__int :== CALL i() \\<lbrace> t = \\<acute>t_hrs \\<rbrace>\"\napply vcg\noops\n\nlocale ff = f_spec + f_modifies\n(* this lemma is bogus, because f does actually modify the globals *)\nlemma (in ff) bogus1:\nshows \"\\<forall>t. \\<Gamma> \\<turnstile> \\<lbrace> \\<acute>t_hrs = t \\<rbrace> \\<acute>ret__int :== CALL f(\\<acute>n) \\<lbrace> t = \\<acute>t_hrs \\<rbrace>\"\napply vcg\napply simp\ndone\n\nlemma (in has_bogus_spec_spec) bogus2:\nshows \"\\<Gamma> \\<turnstile> \\<lbrace> \\<acute>n = 42 \\<rbrace> \\<acute>ret__int :== CALL has_bogus_spec() \\<lbrace> \\<acute>ret__int = 4 \\<rbrace>\"\napply vcg\ndone\n\nlemma (in fncall_global_addresses) toldyou:\nshows \"\\<Gamma> \\<turnstile> \\<lbrace> \\<acute>n = 42 \\<rbrace> \\<acute>ret__int :== CALL has_bogus_spec() \\<lbrace> \\<acute>ret__int = 3 \\<rbrace>\"\napply vcg\ndone\n\nlemma (in has_bogus_spec_spec) bogus3:\nshows \"\\<Gamma> \\<turnstile> \\<lbrace> \\<acute>n = 42 \\<rbrace> \\<acute>ret__int :== CALL calls_bogus() \\<lbrace> \\<acute>ret__int = 4 \\<rbrace>\"\napply vcg\ndone\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/c-parser/testfiles/fncall.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953651858118, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.28198139768053615}}
{"text": "section \\<open>Modelling distributed systems\\<close>\n\ntext \\<open>We assume familiarity with Chandy and Lamport's\npaper \\emph{Distributed Snapshots: Determining Global States of\nDistributed Systems}~\\<^cite>\\<open>\"chandy\"\\<close>.\\<close>\n\ntheory Distributed_System\n\nimports Main\n\nbegin\n\ntype_synonym 'a fifo = \"'a list\"\ntype_synonym channel_id = nat\n\ndatatype 'm message =\n    Marker\n  | Msg 'm\n\ndatatype recording_state =\n    NotStarted\n  | Recording\n  | Done\n\ntext \\<open>We characterize distributed systems by three underlying type variables:\nType variable 'p captures the processes of the underlying system.\nType variable 's describes the possible states of the processes.\nFinally, type variable 'm describes all possible messages in said system.\n\nEach process is in exactly one state at any point in time of the system.\nProcesses are interconnected by directed channels, which hold messages in-flight\nbetween connected processes. There can be an arbitrary number of channels between\ndifferent processes. The entire state of the system including the (potentially unfinished)\nsnapshot state is called \\emph{configuration}.\\<close>\n\nrecord ('p, 's, 'm) configuration =\n  states :: \"'p \\<Rightarrow> 's\"\n  msgs :: \"channel_id \\<Rightarrow> 'm message fifo\"\n\n  process_snapshot :: \"'p \\<Rightarrow> 's option\"\n  channel_snapshot :: \"channel_id \\<Rightarrow> 'm fifo * recording_state\"\n\ntext \\<open>An event in Chandy and Lamport's formalization describes a\nprocess' state transition, optionally producing or consuming\n(but not both) a message on a channel. Additionally, a process may either initiate\na snapshot spontaneously, or is forced to do so by receiving a snapshot \\emph{marker}\non one of it's incoming channels.\\<close>\n\ndatatype ('p, 's, 'm) event =\n    isTrans: Trans (occurs_on: 'p) 's 's\n  | isSend:  Send  (getId: channel_id)\n                   (occurs_on: 'p)\n                   (partner: 'p)\n                   's 's (getMsg: 'm)\n  | isRecv:  Recv  (getId: channel_id)\n                   (occurs_on: 'p)\n                   (partner: 'p)\n                   's 's (getMsg: 'm)\n\n  | isSnapshot:   Snapshot   (occurs_on: 'p)\n  | isRecvMarker: RecvMarker (getId: channel_id)\n                             (occurs_on: 'p)\n                             (partner: 'p)\n\ntext \\<open>We introduce abbreviations and type synoyms for commonly used terms.\\<close>\n\ntype_synonym ('p, 's, 'm) trace = \"('p, 's, 'm) event list\"\n\nabbreviation ps where \"ps \\<equiv> process_snapshot\"\nabbreviation cs where \"cs \\<equiv> channel_snapshot\"\n\nabbreviation no_snapshot_change where\n  \"no_snapshot_change c c' \\<equiv> ((\\<forall>p'. ps c p' = ps c' p') \\<and> (\\<forall>i'. cs c i' = cs c' i'))\"\n\nabbreviation has_snapshotted where\n  \"has_snapshotted c p \\<equiv> process_snapshot c p \\<noteq> None\"\n\ntext \\<open>A regular event is an event as described in Chandy and Lamport's\noriginal paper: A state transition accompanied by the emission\nor receiving of a message. Nonregular events are related to\nsnapshotting and receiving markers along communication channels.\\<close>\n\ndefinition regular_event[simp]:\n  \"regular_event ev \\<equiv> (isTrans ev \\<or> isSend ev \\<or> isRecv ev)\"\n\nlemma nonregular_event:\n  \"~ regular_event ev = (isSnapshot ev \\<or> isRecvMarker ev)\" \n  by (meson event.distinct_disc event.exhaust_disc regular_event)\n\nlemma event_occurs_on_unique:\n  assumes\n    \"p \\<noteq> q\"\n    \"occurs_on ev = p\"\n  shows\n    \"occurs_on ev \\<noteq> q\"\n  using assms by (cases ev, auto)\n\nsubsection \\<open>The distributed system locale\\<close>\n\ntext \\<open>In order to capture Chandy and Lamport's computation system\nwe introduce two locales. The distributed system locale describes\nglobal truths, such as the mapping from channel IDs to sender and\nreceiver processes, the transition relations for the underlying\ncomputation system and the core assumption that no process has\na channel to itself. While not explicitly mentioned in Chandy's\nand Lamport's work, it makes sense to assume that a channel need\nnot communicate to itself via messages, since it shares memory with\nitself.\\<close>\n\nlocale distributed_system =\n  fixes\n    channel :: \"channel_id \\<Rightarrow> ('p * 'p) option\" and\n    trans :: \"'p \\<Rightarrow> 's \\<Rightarrow> 's \\<Rightarrow> bool\" and\n    send :: \"channel_id \\<Rightarrow> 'p \\<Rightarrow> 'p \\<Rightarrow> 's \\<Rightarrow> 's \\<Rightarrow> 'm \\<Rightarrow> bool\" and\n    recv :: \"channel_id \\<Rightarrow> 'p \\<Rightarrow> 'p \\<Rightarrow> 's \\<Rightarrow> 's \\<Rightarrow> 'm \\<Rightarrow> bool\"\n  assumes\n    no_self_channel:\n      \"\\<forall>i. \\<nexists>p. channel i = Some (p, p)\"\nbegin\n\nsubsubsection \\<open>State transitions\\<close>\n\ndefinition can_occur :: \"('p, 's, 'm) event \\<Rightarrow> ('p, 's, 'm) configuration \\<Rightarrow> bool\" where\n\"can_occur ev c \\<equiv> (case ev of\n    Trans p s s'        \\<Rightarrow> states c p = s\n                        \\<and> trans p s s'\n  | Send i p q s s' msg \\<Rightarrow> states c p = s\n                        \\<and> channel i = Some (p, q)\n                        \\<and> send i p q s s' msg\n  | Recv i p q s s' msg \\<Rightarrow> states c p = s\n                        \\<and> channel i = Some (q, p)\n                        \\<and> length (msgs c i) > 0\n                        \\<and> hd (msgs c i) = Msg msg\n                        \\<and> recv i p q s s' msg\n  | Snapshot p          \\<Rightarrow> \\<not> has_snapshotted c p\n  | RecvMarker i p q    \\<Rightarrow> channel i = Some (q, p)\n                        \\<and> length (msgs c i) > 0\n                        \\<and> hd (msgs c i) = Marker)\"\n\ndefinition src where\n  \"src i p \\<equiv> (\\<exists>q. channel i = Some (p, q))\"\n\ndefinition dest where\n  \"dest i q \\<equiv> (\\<exists>p. channel i = Some (p, q))\"\n\nlemma can_occur_Recv:\n  assumes\n    \"can_occur (Recv i p q s s' m) c\"\n  shows\n    \"states c p = s \\<and> channel i = Some (q, p) \\<and> (\\<exists>xs. msgs c i = Msg m # xs) \\<and> recv i p q s s' m\"\nproof -\n  have \"\\<exists>xs. msgs c i = Msg m # xs\" \n    using assms can_occur_def \n    by (metis (mono_tags, lifting) event.case(3) hd_Cons_tl length_greater_0_conv)\n  then show ?thesis using assms can_occur_def by auto\nqed\n\nabbreviation check_snapshot_occur where\n  \"check_snapshot_occur c c' p \\<equiv>\n    (can_occur (Snapshot p) c \\<and>\n    (ps c' p = Some (states c p))\n  \\<and> (\\<forall>p'. states c p' = states c' p')\n  \\<and> (\\<forall>p'. (p' \\<noteq> p) \\<longrightarrow> ps c' p' = ps c p')\n  \\<and> (\\<forall>i. (\\<exists>q. channel i = Some (p, q)) \\<longrightarrow> msgs c' i = msgs c i @ [Marker])\n  \\<and> (\\<forall>i. (\\<exists>q. channel i = Some (q, p)) \\<longrightarrow> channel_snapshot c' i = (fst (channel_snapshot c i), Recording))\n  \\<and> (\\<forall>i. (\\<nexists>q. channel i = Some (p, q)) \\<longrightarrow> msgs c' i = msgs c i)\n  \\<and> (\\<forall>i. (\\<nexists>q. channel i = Some (q, p)) \\<longrightarrow> channel_snapshot c' i = channel_snapshot c i))\"\n\nabbreviation check_recv_marker_occur where\n  \"check_recv_marker_occur c c' i p q \\<equiv>\n    (can_occur (RecvMarker i p q) c\n  \\<and> (\\<forall>r. states c r = states c' r)\n  \\<and> (\\<forall>r. (r \\<noteq> p) \\<longrightarrow> process_snapshot c r = process_snapshot c' r)\n  \\<and> (Marker # msgs c' i = msgs c i)\n  \\<and> (channel_snapshot c' i = (fst (channel_snapshot c i), Done))\n  \\<and> (if has_snapshotted c p\n        then (process_snapshot c p = process_snapshot c' p)\n           \\<and> (\\<forall>i'. (i' \\<noteq> i) \\<longrightarrow> msgs c' i' = msgs c i')\n           \\<and> (\\<forall>i'. (i' \\<noteq> i) \\<longrightarrow> channel_snapshot c i' = channel_snapshot c' i')\n        else (process_snapshot c' p = Some (states c p))\n           \\<and> (\\<forall>i'. i' \\<noteq> i \\<and> (\\<exists>r. channel i' = Some (p, r))\n             \\<longrightarrow> msgs c' i' = msgs c i' @ [Marker])\n           \\<and> (\\<forall>i'. i' \\<noteq> i \\<and> (\\<exists>r. channel i' = Some (r, p))\n             \\<longrightarrow> channel_snapshot c' i' = (fst (channel_snapshot c i'), Recording))\n           \\<and> (\\<forall>i'. i' \\<noteq> i \\<and> (\\<nexists>r. channel i' = Some (p, r))\n             \\<longrightarrow> msgs c' i' = msgs c i')\n           \\<and> (\\<forall>i'. i' \\<noteq> i \\<and> (\\<nexists>r. channel i' = Some (r, p))\n             \\<longrightarrow> channel_snapshot c' i' = channel_snapshot c i')))\"\n\nabbreviation check_trans_occur where\n  \"check_trans_occur c c' p s s'\\<equiv>\n    (can_occur (Trans p s s') c\n  \\<and> (states c' p = s')\n  \\<and> (\\<forall>r. (r \\<noteq> p) \\<longrightarrow> states c' r = states c r)\n  \\<and> (\\<forall>i. msgs c' i = msgs c i)\n  \\<and> (no_snapshot_change c c'))\"\n\nabbreviation check_send_occur where \n  \"check_send_occur c c' i p q s s' msg \\<equiv>\n    (can_occur (Send i p q s s' msg) c\n  \\<and> (states c' p = s')\n  \\<and> (\\<forall>r. (r \\<noteq> p) \\<longrightarrow> states c' r = states c r)\n  \\<and> (msgs c' i = msgs c i @ [Msg msg])\n  \\<and> (\\<forall>i'. i \\<noteq> i' \\<longrightarrow> msgs c' i' = msgs c i')\n  \\<and> (no_snapshot_change c c'))\"\n\nabbreviation check_recv_occur where\n  \"check_recv_occur c c' i p q s s' msg \\<equiv>\n    (can_occur (Recv i p q s s' msg) c\n  \\<and> (states c p = s \\<and> states c' p = s')\n  \\<and> (\\<forall>r. (r \\<noteq> p) \\<longrightarrow> states c' r = states c r)\n  \\<and> (msgs c i = Msg msg # msgs c' i)\n  \\<and> (\\<forall>i'. i \\<noteq> i' \\<longrightarrow> msgs c' i' = msgs c i')\n  \\<and> (\\<forall>r. process_snapshot c r = process_snapshot c' r)\n  \\<and> (\\<forall>i'. i' \\<noteq> i \\<longrightarrow> channel_snapshot c i' = channel_snapshot c' i')\n  \\<and> (if snd (channel_snapshot c i) = Recording\n     then channel_snapshot c' i = (fst (channel_snapshot c i) @ [msg], Recording)\n     else channel_snapshot c i = channel_snapshot c' i))\"\n\ntext \\<open>The \\emph{next} predicate lets us express configuration transitions\nusing events. The predicate $next(s_1, e, s_2)$ denotes the transition\nof the configuration $s_1$ to $s_2$ via the event $e$. It ensures that\n$e$ can occur in state $s_1$ and the state $s_2$ is correctly constructed\nfrom $s_1$.\\<close>\n\nprimrec \"next\" ::\n  \"('p, 's, 'm) configuration\n  \\<Rightarrow> ('p, 's, 'm) event\n  \\<Rightarrow> ('p, 's, 'm) configuration\n  \\<Rightarrow> bool\"\n  (\"_ \\<turnstile> _ \\<mapsto> _\" [70, 70, 70]) where\n    next_snapshot: \"c \\<turnstile> Snapshot p \\<mapsto> c' =\n      check_snapshot_occur c c' p\"\n  | next_recv_marker: \"c \\<turnstile> RecvMarker i p q \\<mapsto> c' =\n      check_recv_marker_occur c c' i p q\"\n  | next_trans: \"c \\<turnstile> Trans p s s' \\<mapsto> c' =\n      check_trans_occur c c' p s s'\"\n  | next_send: \"c \\<turnstile> Send i p q s s' msg \\<mapsto> c' =\n      check_send_occur c c' i p q s s' msg\"\n  | next_recv: \"c \\<turnstile> Recv i p q s s' msg \\<mapsto> c' =\n      check_recv_occur c c' i p q s s' msg\"\n\ntext \\<open>Useful lemmas about state transitions\\<close>\n\nlemma state_and_event_determine_next:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"c \\<turnstile> ev \\<mapsto> c''\"\n  shows\n    \"c' = c''\"\nproof (cases ev)\n  case (Snapshot p)\n  then have \"states c' = states c''\" using assms by auto\n  moreover have \"msgs c' = msgs c''\"\n  proof (rule ext)\n    fix i\n    show \"msgs c' i = msgs c'' i\"\n    proof (cases \"channel i = None\")\n      case True\n      then show ?thesis using Snapshot assms by auto\n    next\n      case False\n      then obtain r s where \"channel i = Some (r, s)\" by auto\n      with assms Snapshot show ?thesis by (cases \"r = p\", simp_all)\n    qed\n  qed\n  moreover have \"process_snapshot c' = process_snapshot c''\" by (metis Snapshot assms next_snapshot ext)\n  moreover have \"channel_snapshot c' = channel_snapshot c''\"\n  proof (rule ext)\n    fix i\n    show \"channel_snapshot c' i = channel_snapshot c'' i\"\n    proof (cases \"channel i = None\")\n      case True\n      then show ?thesis using assms Snapshot by simp\n    next\n      case False\n      then obtain r s where \"channel i = Some (r, s)\" by auto\n      with assms Snapshot show ?thesis by (cases \"s = p\", simp_all)\n    qed\n  qed\n  ultimately show \"c' = c''\" by simp\nnext\n  case (RecvMarker i p)\n  then have \"states c' = states c''\" using assms by auto\n  moreover have \"msgs c' = msgs c''\"\n  proof (rule ext)\n    fix i'\n    show \"msgs c' i' = msgs c'' i'\"\n    proof (cases \"i' = i\")\n      case True\n      then have \"Marker # msgs c' i' = msgs c i'\" using assms RecvMarker by simp\n      also have \"... = Marker # msgs c'' i'\" using assms RecvMarker \\<open>i' = i\\<close> by simp\n      finally show ?thesis by simp\n    next\n      case False\n      then show ?thesis\n      proof (cases \"has_snapshotted c p\")\n        case True\n        then show ?thesis using assms RecvMarker \\<open>i' \\<noteq> i\\<close> by simp\n      next\n        case no_snap: False\n        then show ?thesis\n        proof (cases \"channel i' = None\")\n          case True\n          then show ?thesis using assms RecvMarker \\<open>i' \\<noteq> i\\<close> no_snap by simp\n        next\n          case False\n          then obtain r s where \"channel i' = Some (r, s)\" by auto\n          with assms RecvMarker no_snap \\<open>i' \\<noteq> i\\<close> show ?thesis by (cases \"r = p\"; simp_all)\n        qed\n      qed\n    qed\n  qed\n  moreover have \"process_snapshot c' = process_snapshot c''\"\n  proof (rule ext)\n    fix r\n    show \"ps c' r = ps c'' r\"\n    proof (cases \"r \\<noteq> p\")\n      case True\n      then show ?thesis using assms RecvMarker by simp\n    next\n      case False\n      with assms RecvMarker \\<open>~ r \\<noteq> p\\<close> show ?thesis by (cases \"has_snapshotted c r\", auto)\n    qed\n  qed\n  moreover have \"channel_snapshot c' = channel_snapshot c''\"\n  proof (rule ext)\n    fix i'\n    show \"cs c' i' = cs c'' i'\"\n    proof (cases \"i' = i\")\n      case True\n      then show ?thesis using assms RecvMarker by simp\n    next\n      case False\n      then show ?thesis\n      proof (cases \"has_snapshotted c p\")\n        case True\n        then show ?thesis using assms RecvMarker \\<open>i' \\<noteq> i\\<close> by simp\n      next\n        case no_snap: False\n        then show ?thesis\n        proof (cases \"channel i' = None\")\n          case True\n          then show ?thesis using assms RecvMarker \\<open>i' \\<noteq> i\\<close> no_snap by simp\n        next\n          case False\n          then obtain r s where \"channel i' = Some (r, s)\" by auto\n          with assms RecvMarker no_snap \\<open>i' \\<noteq> i\\<close> show ?thesis by (cases \"s = p\"; simp_all)\n        qed\n      qed\n    qed\n  qed\n  ultimately show \"c' = c''\" by simp\nnext\n  case (Trans p s s')\n  then have \"states c' = states c''\" by (metis (no_types, lifting) assms next_trans ext)\n  moreover have \"msgs c' = msgs c''\" using assms Trans by auto\n  moreover have \"process_snapshot c' = process_snapshot c''\" using assms Trans by auto\n  moreover have \"channel_snapshot c' = channel_snapshot c''\" using assms Trans by auto\n  ultimately show \"c' = c''\" by simp\nnext\n  case (Send i p s s' m)\n  then have \"states c' = states c''\" by (metis (no_types, lifting) assms next_send ext)\n  moreover have \"msgs c' = msgs c''\"\n  proof (rule ext)\n    fix i'\n    from assms Send show \"msgs c' i' = msgs c'' i'\" by (cases \"i' = i\", simp_all)\n  qed\n  moreover have \"process_snapshot c' = process_snapshot c''\" using assms Send by auto\n  moreover have \"channel_snapshot c' = channel_snapshot c''\" using assms Send by auto\n  ultimately show \"c' = c''\" by simp\nnext\n  case (Recv i p s s' m)\n  then have \"states c' = states c''\" by (metis (no_types, lifting) assms next_recv ext)\n  moreover have \"msgs c' = msgs c''\"\n  proof (rule ext)\n    fix i'\n    from assms Recv show \"msgs c' i' = msgs c'' i'\" by (cases \"i' = i\", simp_all)\n  qed\n  moreover have \"process_snapshot c' = process_snapshot c''\" using assms Recv by auto\n  moreover have \"channel_snapshot c' = channel_snapshot c''\"\n  proof (rule ext)\n    fix i'\n    show \"cs c' i' = cs c'' i'\"\n    proof (cases \"i' \\<noteq> i\")\n      case True\n      then show ?thesis using assms Recv by simp\n    next\n      case False\n      with assms Recv show ?thesis by (cases \"snd (cs c i') = Recording\", auto)\n    qed\n  qed\n  ultimately show \"c' = c''\" by simp\nqed\n\nlemma exists_next_if_can_occur:\n  assumes\n    \"can_occur ev c\"\n  shows\n    \"\\<exists>c'. c \\<turnstile> ev \\<mapsto> c'\"\nproof (cases ev)\n  case (Snapshot p)\n  let ?c = \"\\<lparr> states = states c,\n              msgs = %i. if (\\<exists>q. channel i = Some (p, q)) then msgs c i @ [Marker] else msgs c i,\n              process_snapshot = %r. if r = p then Some (states c p) else ps c r,\n              channel_snapshot = %i. if (\\<exists>q. channel i = Some (q, p)) then (fst (cs c i), Recording) else cs c i \\<rparr>\"\n  have \"c \\<turnstile> ev \\<mapsto> ?c\" using Snapshot assms by auto\n  then show ?thesis by blast\nnext\n  case (RecvMarker i p q)\n  show ?thesis\n  proof (cases \"has_snapshotted c p\")\n    case True\n    let ?c = \"\\<lparr> states = states c,\n                msgs = %i'. if i = i' then tl (msgs c i') else msgs c i',\n                process_snapshot = ps c,\n                channel_snapshot = %i'. if i = i' then (fst (cs c i'), Done) else cs c i' \\<rparr>\"\n    have \"msgs c i = Marker # msgs ?c i\"\n      using assms can_occur_def RecvMarker hd_Cons_tl by fastforce\n    then have \"c \\<turnstile> ev \\<mapsto> ?c\" using True RecvMarker assms by auto\n    then show ?thesis by blast\n  next\n    case False\n    let ?c = \"\\<lparr> states = states c,\n                msgs = %i'. if i' = i\n                                  then tl (msgs c i')\n                                  else if (\\<exists>r. channel i' = Some (p, r))\n                                         then msgs c i' @ [Marker]\n                                         else msgs c i',\n                process_snapshot = %r. if r = p then Some (states c r) else ps c r,\n                channel_snapshot = %i'. if i = i' then (fst (cs c i'), Done)\n                                              else if (\\<exists>r. channel i' = Some (r, p))\n                                                     then (fst (cs c i'), Recording)\n                                                     else cs c i' \\<rparr>\"\n    have \"msgs c i = Marker # msgs ?c i\"\n      using assms can_occur_def RecvMarker hd_Cons_tl by fastforce\n    moreover have \"ps ?c p = Some (states c p)\" by simp\n    ultimately have \"c \\<turnstile> ev \\<mapsto> ?c\" using RecvMarker assms False by auto\n    then show ?thesis by blast\n  qed\nnext\n  case (Trans p s s')\n  let ?c = \"\\<lparr> states = %r. if r = p then s' else states c r,\n              msgs = msgs c,\n              process_snapshot = ps c,\n              channel_snapshot = cs c \\<rparr>\"\n  have \"c \\<turnstile> ev \\<mapsto> ?c\" \n    using Trans assms by auto\n  then show ?thesis by blast\nnext\n  case (Send i p q s s' msg)\n    let ?c = \"\\<lparr> states = %r. if r = p then s' else states c r,\n              msgs = %i'. if i = i' then msgs c i' @ [Msg msg] else msgs c i',\n              process_snapshot = ps c,\n              channel_snapshot = cs c \\<rparr>\"\n  have \"c \\<turnstile> ev \\<mapsto> ?c\" \n    using Send assms by auto\n  then show ?thesis by blast\nnext\n  case (Recv i p q s s' msg)\n  then show ?thesis\n  proof (cases \"snd (cs c i)\")\n    case Recording\n    let ?c = \"\\<lparr> states = %r. if r = p then s' else states c r,\n                msgs = %i'. if i = i' then tl (msgs c i') else msgs c i',\n                process_snapshot = ps c,\n                channel_snapshot = %i'. if i = i'\n                                              then (fst (cs c i') @ [msg], Recording)\n                                              else cs c i'\\<rparr>\"\n    have \"c \\<turnstile> ev \\<mapsto> ?c\" \n      using Recv Recording assms can_occur_Recv by fastforce\n    then show ?thesis by blast\n  next\n    case Done\n    let ?c = \"\\<lparr> states = %r. if r = p then s' else states c r,\n                msgs = %i'. if i = i' then tl (msgs c i') else msgs c i',\n                process_snapshot = ps c,\n                channel_snapshot = cs c \\<rparr>\"\n    have \"c \\<turnstile> ev \\<mapsto> ?c\"\n      using Done Recv assms can_occur_Recv by fastforce\n    then show ?thesis by blast\n  next\n    case NotStarted\n    let ?c = \"\\<lparr> states = %r. if r = p then s' else states c r,\n                msgs = %i'. if i = i' then tl (msgs c i') else msgs c i',\n                process_snapshot = ps c,\n                channel_snapshot = cs c \\<rparr>\"\n    have \"c \\<turnstile> ev \\<mapsto> ?c\"\n      using NotStarted Recv assms can_occur_Recv by fastforce\n    then show ?thesis by blast\n  qed\nqed\n\nlemma exists_exactly_one_following_state:\n  \"can_occur ev c \\<Longrightarrow> \\<exists>!c'. c \\<turnstile> ev \\<mapsto> c'\"\n  using exists_next_if_can_occur state_and_event_determine_next by blast\n\nlemma no_state_change_if_no_event:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"occurs_on ev \\<noteq> p\"\n  shows\n    \"states c p = states c' p \\<and> process_snapshot c p = process_snapshot c' p\"\n  using assms by (cases ev, auto)\n\n\n\nlemma no_cs_change_if_no_channel:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"channel i = None\"\n  shows\n    \"cs c i = cs c' i\"\nusing assms proof (cases ev)\n  case (RecvMarker cid p)\n  then have \"cid \\<noteq> i\" using assms RecvMarker can_occur_def by fastforce\n  with assms RecvMarker show ?thesis by (cases \"has_snapshotted c p\", auto)\nnext\n  case (Send cid p s s' m)\n  then have \"cid \\<noteq> i\" using assms Send can_occur_def by fastforce\n  then show ?thesis using assms Send by auto\nnext\n  case (Recv cid p s s' m)\n  then have \"cid \\<noteq> i\" using assms Recv can_occur_def by fastforce\n  then show ?thesis using assms Recv by simp\nqed simp_all\n\nlemma no_msg_change_if_no_event:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"isSend ev \\<longrightarrow> getId ev \\<noteq> i\" and\n    \"isRecv ev \\<longrightarrow> getId ev \\<noteq> i\" and\n    \"regular_event ev\"\n  shows\n    \"msgs c i = msgs c' i\"\nproof (cases \"channel i = None\")\n  case True\n  then show ?thesis using assms no_msgs_change_if_no_channel by simp\nnext\n  have \"isTrans ev \\<or> isSend ev \\<or> isRecv ev\" using assms by simp\n  then show ?thesis\n  proof (elim disjE)\n    assume \"isTrans ev\"\n    then show ?thesis \n      by (metis assms(1) event.collapse(1) next_trans)\n  next\n    assume \"isSend ev\"\n    then obtain i' r s u u' m where Send: \"ev = Send i' r s u u' m\" by (meson isSend_def)\n    then show ?thesis using Send assms by auto\n  next\n    assume \"isRecv ev\"\n    then obtain i' r s u u' m where \"ev = Recv i' r s u u' m\" by (meson isRecv_def)\n    then show ?thesis using assms by auto\n  qed\nqed\n\nlemma no_cs_change_if_no_event:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"isRecv ev \\<longrightarrow> getId ev \\<noteq> i\" and\n    \"regular_event ev\"\n  shows\n    \"cs c i = cs c' i\"\nproof -\n  have \"isTrans ev \\<or> isSend ev \\<or> isRecv ev\" using assms by simp\n  then show ?thesis\n  proof (elim disjE)\n    assume \"isTrans ev\"\n    then show ?thesis \n      by (metis assms(1) event.collapse(1) next_trans)\n  next\n    assume \"isSend ev\"\n    then obtain i' r s u u' m where \"ev = Send i' r s u u' m\" by (meson isSend_def)\n    then show ?thesis using assms by auto\n  next\n    assume \"isRecv ev\"\n    then obtain i r s u u' m where \"ev = Recv i r s u u' m\" by (meson isRecv_def)\n    then show ?thesis using assms by auto\n  qed\nqed\n\nlemma happen_implies_can_occur:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\"\n  shows\n    \"can_occur ev c\"\nproof -\n  show ?thesis using assms by (cases ev, auto)\nqed\n\nlemma snapshot_increases_message_length:\n  assumes\n    \"ev = Snapshot p\" and\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"channel i = Some (q, r)\"\n  shows\n    \"length (msgs c i) \\<le> length (msgs c' i)\"\n  using assms by (cases \"p = q\", auto)\n\nlemma recv_marker_changes_head_only_at_i:\n  assumes\n    \"ev = RecvMarker i p q\" and\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"i' \\<noteq> i\"\n  shows\n    \"msgs c i' = [] \\<or> hd (msgs c i') = hd (msgs c' i')\"\nproof (cases \"channel i' = None\")\n  case True\n  then show ?thesis using assms no_msgs_change_if_no_channel by presburger\nnext\n  case False\n  then show ?thesis\n  proof (cases \"msgs c i'\")\n    case Nil\n    then show ?thesis by simp\n  next\n    case (Cons m xs)\n    then obtain r s where \"channel i' = Some (r, s)\" using False by auto\n    then show ?thesis\n    proof (cases \"has_snapshotted c p\")\n      case True\n      then show ?thesis using assms by auto\n    next\n      case False\n      with assms show ?thesis by (cases \"r = p\", auto)\n    qed\n  qed\nqed\n\nlemma recv_marker_other_channels_not_shrinking:\n  assumes\n    \"ev = RecvMarker i p q\" and\n    \"c \\<turnstile> ev \\<mapsto> c'\"\n  shows\n    \"length (msgs c i') \\<le> length (msgs c' i') \\<longleftrightarrow> i \\<noteq> i'\"\nproof (rule iffI)\n  show \"length (msgs c i') \\<le> length (msgs c' i') \\<Longrightarrow> i \\<noteq> i'\"\n  proof (rule ccontr)\n    assume asm: \"~ i \\<noteq> i'\" \"length (msgs c i') \\<le> length (msgs c' i')\"\n    then have \"msgs c i = Marker # msgs c' i\" using assms by auto\n    then have \"length (msgs c i) > length (msgs c' i)\" by simp\n    then have \"length (msgs c i') > length (msgs c' i')\" using asm by simp\n    then show False using asm by simp\n  qed\nnext\n  show \"i \\<noteq> i' \\<Longrightarrow> length (msgs c i') \\<le> length (msgs c' i')\"\n  proof -\n    assume \"i \\<noteq> i'\"\n    then show ?thesis\n    proof (cases \"channel i' = None\")\n      case True\n      then show ?thesis using assms no_msgs_change_if_no_channel by presburger\n    next\n      case False\n      then obtain r s where chan: \"channel i' = Some (r, s)\" by auto\n      then show ?thesis\n      proof (cases \"has_snapshotted c p\")\n        case True\n        with assms \\<open>i \\<noteq> i'\\<close> show ?thesis by auto\n      next\n        case no_snap: False\n        then show ?thesis\n        proof (cases \"p = r\")\n          case True\n          then have \"msgs c' i' = msgs c i' @ [Marker]\" using \\<open>i \\<noteq> i'\\<close> assms no_snap chan by auto\n          then show ?thesis by auto\n        next\n          case False\n          then show ?thesis using assms \\<open>i \\<noteq> i'\\<close> chan no_snap by auto\n        qed\n      qed\n    qed\n  qed\nqed\n\nlemma regular_event_cannot_induce_snapshot:\n  assumes\n    \"~ has_snapshotted c p\" and\n    \"c \\<turnstile> ev \\<mapsto> c'\"\n  shows\n    \"regular_event ev \\<longrightarrow> ~ has_snapshotted c' p\"\nproof (cases ev)\n  case (Trans q s s')\n  then show ?thesis using assms(1) assms(2) by auto\nnext\n  case (Send q r s s' m)\n  then show ?thesis using assms by auto\nnext\n  case (Recv q r s s' m) \n  then show ?thesis using assms by auto\nqed simp_all\n\nlemma regular_event_preserves_process_snapshots:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\"\n  shows\n    \"regular_event ev \\<Longrightarrow> ps c r = ps c' r\"\nproof (cases ev)\n  case (Trans p s s')\n  then show ?thesis \n    using assms by auto\nnext\n  case (Send p q s s' m)\n  then show ?thesis \n    using assms by auto\nnext\n  case (Recv p q s s' m)\n  then show ?thesis \n    using assms by auto\nqed simp_all\n\nlemma no_state_change_if_nonregular_event:\n  assumes\n    \"~ regular_event ev\" and\n    \"c \\<turnstile> ev \\<mapsto> c'\"\n  shows\n    \"states c p = states c' p\"\nproof -\n  have \"isSnapshot ev \\<or> isRecvMarker ev\" using nonregular_event assms by auto\n  then show ?thesis\n  proof (elim disjE, goal_cases)\n    case 1\n    then obtain q where \"ev = Snapshot q\" \n      by (meson isSnapshot_def)\n    then show ?thesis \n      using assms(2) by auto\n  next\n    case 2\n    then obtain i q r where \"ev = RecvMarker i q r\"\n      by (meson isRecvMarker_def)\n    then show ?thesis using assms(2) by auto\n  qed\nqed\n\nlemma nonregular_event_induces_snapshot:\n  assumes\n    \"~ has_snapshotted c p\" and\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"occurs_on ev = p\" and\n    \"~ regular_event ev\"\n  shows\n    \"~ regular_event ev \\<longrightarrow> has_snapshotted c' p\"\nproof (cases ev)\n  case (Snapshot q)\n  then have \"q = p\" using assms by auto\n  then show ?thesis using Snapshot assms(2) by auto\nnext\n  case (RecvMarker i q r)\n  then have \"q = p\" using assms by auto\n  then show ?thesis using RecvMarker assms by auto\nqed (simp_all add: assms)\n\nlemma snapshot_state_unchanged:\n  assumes\n    step: \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"has_snapshotted c p\"\n  shows\n    \"ps c p = ps c' p\"\nproof (cases \"occurs_on ev = p\")\n  case False\n  then show ?thesis \n    using local.step no_state_change_if_no_event by auto\nnext\n  case True\n  then show ?thesis\n  proof (cases \"regular_event ev\")\n    case True\n    then show ?thesis \n      using local.step regular_event_preserves_process_snapshots by auto\n  next\n    case False\n    have \"isRecvMarker ev\"\n    proof (rule ccontr)\n      have \"isSnapshot ev \\<or> isRecvMarker ev\" \n        using False nonregular_event by blast\n      moreover assume \"~ isRecvMarker ev\"\n      ultimately have \"isSnapshot ev\" by simp\n      then have \"ev = Snapshot p\" by (metis True event.collapse(4))\n      then have \"can_occur ev c\" \n        using happen_implies_can_occur local.step by blast\n      then have \"~ has_snapshotted c p\" unfolding can_occur_def \n        by (simp add: \\<open>ev = Snapshot p\\<close>)\n      then show False using assms by auto\n    qed\n    then show ?thesis (* z3 sledgehammer fails for Isabelle2019 *)\n    proof -\n      have \"\\<exists>n pa. c \\<turnstile> RecvMarker n p pa \\<mapsto> c'\"\n        by (metis True \\<open>isRecvMarker ev\\<close> event.collapse(5) local.step)\n      then show ?thesis\n        using assms(2) by force\n    qed\n  qed\nqed\n\nlemma message_must_be_delivered:\n  assumes\n    valid: \"c \\<turnstile> ev \\<mapsto> c'\" and\n    delivered: \"(msgs c i \\<noteq> [] \\<and> hd (msgs c i) = m) \\<and> (msgs c' i = [] \\<or> hd (msgs c' i) \\<noteq> m)\"\n  shows\n    \"(\\<exists>p q.         ev = RecvMarker i p q   \\<and> m = Marker)\n   \\<or> (\\<exists>p q s s' m'. ev = Recv i p q s s' m' \\<and> m = Msg m')\"\nproof (cases ev)\n  case (Snapshot p)\n  then show ?thesis\n  proof (cases \"msgs c i\")\n    case Nil\n    then show ?thesis using delivered by simp\n  next\n    case (Cons m xs)\n    with assms Snapshot show ?thesis\n    proof (cases \"channel i = None\")\n      case True\n      then show ?thesis using assms Snapshot by auto\n    next\n      case False\n      then obtain r s where chan: \"channel i = Some (r, s)\" by auto\n      then show ?thesis\n      proof (cases \"r = p\")\n        case True\n        then have \"msgs c' i = msgs c i @ [Marker]\" using assms(1) Snapshot chan by auto\n        then show ?thesis using delivered by auto\n      next\n        case False\n        then have \"msgs c' i = msgs c i\" using assms Snapshot chan by simp\n        then show ?thesis using delivered Cons by simp\n      qed\n    qed\n  qed\nnext\n  case (RecvMarker i' p q)\n  then have \"i' = i\" \n    by (metis assms(1) delivered le_0_eq length_greater_0_conv list.size(3) recv_marker_changes_head_only_at_i recv_marker_other_channels_not_shrinking)\n  moreover have \"Marker = m\"\n    using \\<open>i' = i\\<close> RecvMarker assms(1) can_occur_def delivered by auto\n  moreover have \"channel i = Some (q, p)\" \n    using RecvMarker assms(1) calculation(1) can_occur_def by auto\n  ultimately show ?thesis using RecvMarker by simp\nnext\n  case (Trans p' s s')\n  then show ?thesis\n    using valid delivered by auto\nnext\n  case (Send p' q' s s' m')\n  then show ?thesis\n    by (metis (no_types, lifting) delivered distributed_system.next.simps(4) distributed_system_axioms hd_append2 snoc_eq_iff_butlast valid)\nnext\n  case (Recv i' p q s s' m')\n  then have \"i = i'\" \n    using assms(1) delivered by auto\n  also have \"m = Msg m'\" \n    by (metis (no_types, lifting) Recv delivered list.sel(1) next_recv valid)\n  ultimately show ?thesis using Recv by auto\nqed\n\nlemma message_must_be_delivered_2:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\"\n    \"m : set (msgs c i)\"\n    \"m \\<notin> set (msgs c' i)\"\n  shows\n    \"(\\<exists>p q. ev = RecvMarker i p q \\<and> m = Marker) \\<or> (\\<exists>p q s s' m'. ev = Recv i p q s s' m' \\<and> m = Msg m')\"\nproof -\n  have uneq_sets: \"set (msgs c i) \\<noteq> set (msgs c' i)\" \n    using assms(2) assms(3) by blast\n  then obtain p q where chan: \"channel i = Some (p, q)\"\n    using assms no_msgs_change_if_no_channel by fastforce\n  then show ?thesis\n  proof (cases ev)\n    case (Snapshot p')\n    with Snapshot assms chan have \"set (msgs c' i) = set (msgs c i)\" by (cases \"p' = p\", auto)\n    then show ?thesis using uneq_sets by simp\n  next\n    case (Trans p' s s')\n    then show ?thesis using uneq_sets assms by simp\n  next\n    case (Send i' p' q' s s' m)\n    then show ?thesis\n      by (metis (no_types, lifting) UnCI assms(1) assms(2) assms(3) local.next.simps(4) set_append)\n  next\n    case (RecvMarker i' p' q')\n    have \"i' = i\"\n    proof (rule ccontr)\n      assume \"~ i' = i\"\n      show False using assms chan RecvMarker\n      proof (cases \"has_snapshotted c p'\")\n        case True\n        then show False using assms chan RecvMarker \\<open>~ i' = i\\<close> by simp\n      next\n        case False\n        then show False using assms chan RecvMarker \\<open>~ i' = i\\<close> by (cases \"p' = p\", simp_all)\n      qed\n    qed\n    moreover have \"m = Marker\"\n    proof -\n      have \"msgs c i' = Marker # msgs c' i'\" using assms chan RecvMarker by auto\n      then show ?thesis using assms \\<open>i' = i\\<close> by simp\n    qed\n    ultimately show ?thesis using RecvMarker by simp\n  next\n    case (Recv i' p' q' s s' m')\n    have \"i' = i\"\n    proof (rule ccontr)\n      assume \"~ i' = i\"\n      then show False \n        using Recv assms(1) uneq_sets by auto\n    qed\n    then have \"i' = i \\<and> m = Msg m'\" \n      using Recv assms by auto\n    then show ?thesis using Recv by simp\n  qed\nqed\n\nlemma recv_marker_means_snapshotted_1:\n  assumes\n    \"ev = RecvMarker i p q\" and\n    \"c \\<turnstile> ev \\<mapsto> c'\"\n  shows\n    \"has_snapshotted c' p\"\n  using assms snapshot_state_unchanged by (cases \"has_snapshotted c p\", auto)\n\nlemma recv_marker_means_snapshotted_2:\n  fixes\n    c c' :: \"('p, 's, 'm) configuration\" and\n    ev :: \"('p, 's, 'm) event\" and\n    i :: channel_id\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"Marker : set (msgs c i)\" and\n    \"Marker \\<notin> set (msgs c' i)\" and\n    \"channel i = Some (q, p)\"\n  shows\n    \"has_snapshotted c' p\"\nproof -\n  have \"\\<exists>p q. ev = RecvMarker i p q\"\n    using assms message_must_be_delivered_2 by blast\n  then obtain r s where RecvMarker: \"ev = RecvMarker i r s\"\n    by blast\n  then have \"r = p\"\n    using assms(1) assms(4) can_occur_def by auto\n  then show ?thesis\n    using recv_marker_means_snapshotted_1 assms RecvMarker by blast\nqed\n\nlemma event_stays_valid_if_no_occurrence:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"occurs_on ev \\<noteq> occurs_on ev'\" and\n    \"can_occur ev' c\"\n  shows\n    \"can_occur ev' c'\"\nproof (cases ev')\n  case (Trans p s s')\n  have \"states c p = states c' p\"\n    using Trans assms(1) assms(2) no_state_change_if_no_event by auto\n  moreover have \"states c p = s\" using can_occur_def assms Trans by simp\n  ultimately have \"states c' p = s\" by simp\n  moreover have \"trans p s s'\" \n    using Trans assms(3) can_occur_def by auto\n  ultimately show ?thesis \n    by (simp add: Trans can_occur_def)\nnext\n  case (Recv i p q s s' m)\n  then have \"hd (msgs c i) = Msg m\"\n  proof -\n    from Recv have \"length (msgs c i) > 0\" using assms(3) can_occur_def by auto\n    then obtain m' xs where mcqp: \"msgs c i = m' # xs\"\n      by (metis list.size(3) nat_less_le neq_Nil_conv)\n    then have \"Msg m = m'\"\n    proof (cases m', auto)\n      case Marker\n      then have \"msgs c i = Marker # xs\" by (simp add:mcqp)\n      then have \"~ can_occur ev' c\" using Recv can_occur_def by simp\n      then show False using assms(3) by simp\n    next\n      case (Msg msg)\n      then have \"msgs c i = Msg msg # xs\" by (simp add: mcqp)\n      then show \"m = msg\" using Recv can_occur_def assms(3) by simp\n    qed\n    then show ?thesis by (simp add: mcqp)\n  qed\n  show ?thesis\n  proof (rule ccontr)\n    assume asm: \"~ can_occur ev' c'\"\n    then have \"msgs c' i = [] \\<or> hd (msgs c' i) \\<noteq> Msg m\"\n      using Recv assms can_occur_def no_state_change_if_no_event distributed_system_axioms list.case_eq_if by fastforce\n    then obtain i' p' q' s'' s''' m' where RMoR: \"ev = RecvMarker i' p' q' \\<or> ev = Recv i p' q' s'' s''' m'\"\n      by (metis Recv \\<open>hd (msgs c i) = Msg m\\<close> assms(1) assms(3) can_occur_Recv list.discI message_must_be_delivered)\n    then have \"occurs_on ev = p\" \n    proof -\n      have f1: \"states c p = s \\<and> channel i = Some (q, p) \\<and> recv i p q s s' m \\<and> 0 < length (msgs c i) \\<and> hd (msgs c i) = Msg m\"\n        using Recv assms(3) can_occur_def by force\n      have f2: \"RecvMarker i' p' q' = ev \\<or> states c p' = s'' \\<and> channel i = Some (q', p') \\<and> recv i p' q' s'' s''' m' \\<and> 0 < length (msgs c i) \\<and> hd (msgs c i) = Msg m'\"\n        using RMoR assms(1) can_occur_def by force\n      have \"\\<forall>e n c. \\<exists>p pa s sa m. \\<forall>ca cb. (\\<not> c \\<turnstile> e \\<mapsto> ca \\<or> msgs ca n \\<noteq> [] \\<or> hd (msgs c n) = Marker \\<or> msgs c n = [] \\<or> Recv n p pa s sa m = e) \\<and> (\\<not> c \\<turnstile> e \\<mapsto> cb \\<or> hd (msgs c n) = Marker \\<or> hd (msgs cb n) = hd (msgs c n) \\<or> msgs c n = [] \\<or> Recv n p pa s sa m = e)\"\n        by (metis (no_types) message_must_be_delivered)\n      then show ?thesis\n        using f2 f1 by (metis RMoR \\<open>msgs c' i = [] \\<or> hd (msgs c' i) \\<noteq> Msg m\\<close> assms(1) event.disc(13,15) event.sel(3,5) length_greater_0_conv message.distinct(1) option.inject prod.inject)\n    qed\n    then show False using assms Recv by simp\n  qed\nnext\n  case (Send i p q s s' m)\n  then have \"states c p = states c' p\" using assms no_state_change_if_no_event by auto\n  then show \"can_occur ev' c'\" using assms assms(3) can_occur_def Send by auto\nnext\n  case (RecvMarker i p q)\n  then have msgs_ci: \"hd (msgs c i) = Marker \\<and> length (msgs c i) > 0\"\n  proof -\n    from RecvMarker have \"length (msgs c i) > 0\" using assms(3) can_occur_def by auto\n    then obtain m' xs where mci: \"msgs c i = m' # xs\"\n      by (metis list.size(3) nat_less_le neq_Nil_conv)\n    then have m_mark: \"Marker = m'\"\n    proof (cases m', auto)\n      case (Msg msg)\n      then have \"msgs c i = Msg msg # xs\" by (simp add:mci)\n      then have \"~ can_occur ev' c\" using RecvMarker can_occur_def by simp\n      then show False using assms(3) by simp\n    qed\n    then show ?thesis by (simp add: mci)\n  qed\n  show ?thesis\n  proof (rule ccontr)\n    assume asm: \"~ can_occur ev' c'\"\n    then have \"msgs c' i = [] \\<or> hd (msgs c' i) \\<noteq> Marker\"\n      using RecvMarker assms(3) can_occur_def list.case_eq_if by fastforce\n    then have \"\\<exists>p q. ev = RecvMarker i p q \\<and> Marker = Marker\" using message_must_be_delivered msgs_ci assms by blast\n    then obtain r s where RecvMarker_ev: \"ev = RecvMarker i r s\" by blast\n    then have \"p = r \\<and> q = s\" \n      using RecvMarker assms(1) assms(3) can_occur_def by auto\n    then have \"occurs_on ev = p\" using assms RecvMarker_ev by auto\n    then show False using assms using RecvMarker by auto\n  qed\nnext\n  case (Snapshot p)\n  then have \"~ has_snapshotted c p\" using assms assms(3) can_occur_def by simp\n  show ?thesis\n  proof (rule ccontr)\n    assume asm: \"~ can_occur ev' c'\"\n    then have \"has_snapshotted c' p\" using can_occur_def Snapshot by simp\n    then have \"occurs_on ev = p\"\n      using \\<open>\\<not> has_snapshotted c p\\<close> assms(1) no_state_change_if_no_event by fastforce\n    then show False using assms(2) Snapshot by auto\n  qed\nqed\n\nlemma msgs_unchanged_for_other_is:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"regular_event ev\" and\n    \"getId ev = i\" and\n    \"i' \\<noteq> i\"\n  shows\n    \"msgs c i' = msgs c' i'\"\nproof -\n  have \"isTrans ev \\<or> isSend ev \\<or> isRecv ev\" using assms by simp\n  then show ?thesis\n  proof (elim disjE, goal_cases)\n    case 1\n    then obtain p s s' where \"ev = Trans p s s'\" by (meson isTrans_def)\n    then show ?thesis using assms by simp\n  next\n    case 2\n    then obtain i' p q s s' m where \"ev = Send i' p q s s' m\" by (meson isSend_def)\n    then show ?thesis using assms by simp\n  next\n    case 3\n    then obtain i' p q s s' m where \"ev = Recv i' p q s s' m\" by (meson isRecv_def)\n    with assms show ?thesis by auto\n  qed\nqed\n\nlemma msgs_unchanged_if_snapshotted_RecvMarker_for_other_is:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"ev = RecvMarker i p q\" and\n    \"has_snapshotted c p\" and\n    \"i' \\<noteq> i\"\n  shows\n    \"msgs c i' = msgs c' i'\"\n  using assms by auto\n\nlemma event_can_go_back_if_no_sender:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"occurs_on ev \\<noteq> occurs_on ev'\" and\n    \"can_occur ev' c'\" and\n    \"~ isRecvMarker ev'\" and\n    \"~ isSend ev\"\n  shows\n    \"can_occur ev' c\"\nproof (cases ev')\n  case (Snapshot p)\n  then have \"~ has_snapshotted c' p\" using assms(3) can_occur_def by simp\n  then have \"~ has_snapshotted c p\" using assms(1) snapshot_state_unchanged by force\n  then show ?thesis using can_occur_def Snapshot by simp\nnext\n  case (RecvMarker i p q)\n  then show ?thesis using assms(4) by auto\nnext\n  case (Trans p s s')\n  then show ?thesis\n    using assms(1) assms(2) can_occur_def no_state_change_if_no_event assms(3) by auto\nnext\n  case (Send p q s s' m)\n  then show ?thesis\n    using assms(1) assms(2) can_occur_def no_state_change_if_no_event assms(3) by auto\nnext\n  case (Recv i p q s s' m)\n  have \"msgs c' i \\<noteq> Nil\" using Recv can_occur_def assms by auto\n  moreover have \"hd (msgs c' i) = Msg m \\<and> length (msgs c' i) > 0\"\n  proof -\n    from Recv have \"length (msgs c' i) > 0\" using assms(3) can_occur_def by auto\n    then obtain m' xs where mcqp: \"msgs c' i = m' # xs\"\n      by (metis list.size(3) nat_less_le neq_Nil_conv)\n    then have \"Msg m = m'\"\n    proof (cases m', auto)\n      case Marker\n      then have \"msgs c' i = Marker # xs\" by (simp add:mcqp)\n      then have \"~ can_occur ev' c'\" using Recv can_occur_def by simp\n      then show False using assms(3) by simp\n    next\n      case (Msg msg)\n      then have \"msgs c' i = Msg msg # xs\" by (simp add: mcqp)\n      then show \"m = msg\" using Recv can_occur_def assms(3) by simp\n    qed\n    then show ?thesis by (simp add: mcqp)\n  qed\n  moreover have \"msgs c i \\<noteq> Nil \\<and> hd (msgs c' i) = hd (msgs c i)\"\n  proof (cases ev)\n    case (Snapshot p')\n    then have \"p' \\<noteq> p\" using assms Recv by simp\n    have chan: \"channel i = Some (q, p)\" \n      by (metis Recv assms(3) distributed_system.can_occur_Recv distributed_system_axioms)\n    with Snapshot assms have \"length (msgs c i) > 0 \\<and> hd (msgs c i) = hd (msgs c' i)\"\n    proof (cases \"q = p'\")\n      case True\n      then have \"msgs c' i = msgs c i @ [Marker]\" using Snapshot chan assms by simp\n      then show ?thesis \n        by (metis append_self_conv2 calculation(2) hd_append2 length_greater_0_conv list.sel(1) message.simps(3))\n    next\n      case False\n      then have \"msgs c' i = msgs c i\" using Snapshot chan assms by simp\n      then show ?thesis using calculation by simp\n    qed\n    then show ?thesis by simp\n  next\n    case (RecvMarker i' p' q')\n    then have \"i' \\<noteq> i\" \n      using Recv assms(1) assms(2) assms(3) can_occur_def by force\n    then show ?thesis\n    proof (cases \"has_snapshotted c p'\")\n      case True\n      then have \"msgs c i = msgs c' i\" using \\<open>i' \\<noteq> i\\<close> RecvMarker assms by simp\n      then show ?thesis using calculation by simp\n    next\n      case no_snap: False\n      then have chan: \"channel i = Some (q, p)\" \n        by (metis Recv assms(3) distributed_system.can_occur_Recv distributed_system_axioms)\n      then show ?thesis\n      proof (cases \"q = p'\")\n        case True\n        then have \"msgs c' i = msgs c i @ [Marker]\" \n          using no_snap RecvMarker \\<open>i' \\<noteq> i\\<close> assms(1) chan by auto\n        then show ?thesis \n          by (metis append_self_conv2 calculation(2) hd_append2 list.sel(1) message.simps(3))\n      next\n        case False\n        then have \"msgs c' i = msgs c i\" using RecvMarker no_snap False chan assms \\<open>i' \\<noteq> i\\<close> by simp\n        then show ?thesis using calculation by simp\n      qed\n    qed\n  next\n    case (Trans p' s'' s''')\n    then show ?thesis using assms(1) \\<open>msgs c' i \\<noteq> Nil\\<close> by auto\n  next\n    case (Send i' p' q' s'' s''' m'')\n    have \"p' \\<noteq> p\"\n      using Recv Send assms(2) by auto\n    then show ?thesis \n      using Recv Send assms(1) assms(5) calculation(1) by auto\n  next\n    case (Recv i' p' q' s'' s''' m'')\n    then have \"i' \\<noteq> i\" using assms \\<open>ev' = Recv i p q s s' m\\<close> \n      by (metis distributed_system.can_occur_Recv distributed_system_axioms event.sel(3) next_recv option.inject prod.inject)\n    have \"msgs c i = msgs c' i\" using msgs_unchanged_for_other_is Recv \\<open>i' \\<noteq> i\\<close> assms(1) by auto\n    then show ?thesis using \\<open>msgs c' i \\<noteq> Nil\\<close> by simp\n  qed\n  moreover have \"states c p = states c' p\" using no_state_change_if_no_event assms Recv by simp\n  ultimately show ?thesis\n    using Recv assms(3) can_occur_def list.case_eq_if by fastforce\nqed\n\nlemma nonregular_event_can_go_back_if_in_distinct_processes:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"regular_event ev\" and\n    \"~ regular_event ev'\" and\n    \"can_occur ev' c'\" and\n    \"occurs_on ev \\<noteq> occurs_on ev'\"\n  shows\n    \"can_occur ev' c\"\nproof -\n  let ?p = \"occurs_on ev\"\n  let ?q = \"occurs_on ev'\"\n  have \"isTrans ev \\<or> isSend ev \\<or> isRecv ev\" using assms by simp\n  moreover have \"isSnapshot ev' \\<or> isRecvMarker ev'\" using assms nonregular_event by auto\n  ultimately show ?thesis\n  proof (elim disjE, goal_cases)\n    case 1\n    then show ?case \n      using assms(1) assms(4) assms(5) event_can_go_back_if_no_sender by blast\n  next\n    case 2\n    then obtain s s' where Trans: \"ev = Trans ?p s s'\"\n      by (metis event.collapse(1))\n    obtain i r where RecvMarker: \"ev' = RecvMarker i ?q r\"\n      using 2 by (metis event.collapse(5))\n    have \"msgs c i = msgs c' i\" \n      using \"2\"(1) assms(1) assms(2) no_msg_change_if_no_event by blast\n    moreover have \"can_occur ev' c'\" using assms by simp\n    ultimately show ?thesis using can_occur_def RecvMarker \n      by (metis (mono_tags, lifting) \"2\"(2) event.case_eq_if event.distinct_disc(13) event.distinct_disc(17) event.distinct_disc(19) event.distinct_disc(7) event.sel(10))\n  next\n    case 3\n    then have \"ev' = Snapshot ?q\"\n      by (metis event.collapse(4))\n    have \"~ has_snapshotted c' ?q\" \n      by (metis (mono_tags, lifting) \"3\"(1) assms(4) can_occur_def event.case_eq_if event.distinct_disc(11) event.distinct_disc(16) event.distinct_disc(6))\n    then have \"~ has_snapshotted c ?q\" \n      using assms(1) assms(2) regular_event_preserves_process_snapshots by auto\n    then show ?case unfolding can_occur_def using \\<open>ev' = Snapshot ?q\\<close> \n      by (metis (mono_tags, lifting) event.simps(29))\n  next\n    case 4\n    then have \"ev' = Snapshot ?q\"\n      by (metis event.collapse(4))\n    have \"~ has_snapshotted c' ?q\"\n      by (metis (mono_tags, lifting) \\<open>ev' = Snapshot (occurs_on ev')\\<close> assms(4) can_occur_def event.simps(29))\n    then have \"~ has_snapshotted c ?q\"\n      using assms(1) assms(2) regular_event_preserves_process_snapshots by auto\n    then show ?case unfolding can_occur_def \n      by (metis (mono_tags, lifting) \\<open>ev' = Snapshot (occurs_on ev')\\<close> event.simps(29))\n  next\n    case 5\n    then obtain i s u u' m where \"ev = Send i ?p s u u' m\"\n      by (metis event.collapse(2))\n    from 5 obtain i' r where \"ev' = RecvMarker i' ?q r\"\n      by (metis event.collapse(5))\n    then have pre: \"hd (msgs c' i') = Marker \\<and> length (msgs c' i') > 0\" \n      by (metis (mono_tags, lifting) assms(4) can_occur_def event.simps(30))\n    have \"hd (msgs c i') = Marker \\<and> length (msgs c i') > 0\"\n    proof (cases \"i' = i\")\n      case False\n      then have \"msgs c i' = msgs c' i'\" \n        by (metis \\<open>ev = Send i (occurs_on ev) s u u' m\\<close> assms(1) assms(2) event.sel(8) msgs_unchanged_for_other_is)\n      then show ?thesis using pre by auto\n    next\n      case True\n      then have \"msgs c' i' = msgs c i' @ [Msg m]\" \n        by (metis \\<open>ev = Send i (occurs_on ev) s u u' m\\<close> assms(1) next_send)\n      then have \"length (msgs c' i') > 1\" \n        using pre by fastforce\n      then have \"length (msgs c i') > 0\" \n        by (simp add: \\<open>msgs c' i' = msgs c i' @ [Msg m]\\<close>)\n      then show ?thesis \n        using \\<open>msgs c' i' = msgs c i' @ [Msg m]\\<close> pre by auto\n    qed\n    then show ?case unfolding can_occur_def using \\<open>ev' = RecvMarker i' ?q r\\<close> \n      by (metis (mono_tags, lifting) assms(4) can_occur_def event.simps(30))\n  next\n    case 6\n    then obtain i s u u' m where \"ev = Recv i ?p s u u' m\"\n      by (metis event.collapse(3))\n    from 6 obtain i' r where \"ev' = RecvMarker i' ?q r\"\n      by (metis event.collapse(5))\n    then have \"i' \\<noteq> i\"\n    proof -\n      have \"?p \\<noteq> ?q\" using assms by simp\n      moreover have \"channel i = Some (s, ?p)\" \n        by (metis \\<open>ev = Recv i (occurs_on ev) s u u' m\\<close> assms(1) distributed_system.can_occur_Recv distributed_system_axioms happen_implies_can_occur)\n      moreover have \"channel i' = Some (r, ?q)\"\n        by (metis (mono_tags, lifting) \\<open>ev' = RecvMarker i' (occurs_on ev') r\\<close> assms(4) can_occur_def event.case_eq_if event.disc(5,10,15,20) event.sel(5,10,13))\n      ultimately show ?thesis by auto\n    qed\n    then show ?case\n      by (metis (mono_tags, lifting) \"6\"(1) \\<open>ev = Recv i (occurs_on ev) s u u' m\\<close> \\<open>ev' = RecvMarker i' (occurs_on ev') r\\<close> assms(1) assms(4) can_occur_def event.case_eq_if event.distinct_disc(13) event.distinct_disc(17) event.distinct_disc(7) event.sel(10) next_recv)\n  qed\nqed\n\nlemma same_state_implies_same_result_state:\n  assumes\n    \"states c p = states d p\"\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"d \\<turnstile> ev \\<mapsto> d'\"\n  shows\n    \"states d' p = states c' p\"\nproof (cases \"occurs_on ev = p\")\n  case False\n  then show ?thesis \n    by (metis assms(1-3) distributed_system.no_state_change_if_no_event distributed_system_axioms)\nnext\n  case True\n  then show ?thesis\n    using assms by (cases ev, auto)\nqed\n\nlemma same_snapshot_state_implies_same_result_snapshot_state:\n  assumes\n    \"ps c p = ps d p\" and\n    \"states c p = states d p\" and\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"d \\<turnstile> ev \\<mapsto> d'\"\n  shows\n    \"ps d' p = ps c' p\"\nproof (cases \"occurs_on ev = p\")\n  case False\n  then show ?thesis\n    using assms no_state_change_if_no_event by auto\nnext\n  case True\n  then show ?thesis\n  proof (cases ev)\n    case (Snapshot q)\n    then have \"p = q\" using True by auto\n    then show ?thesis \n      using Snapshot assms(2) assms(3) assms(4) by auto\n  next\n    case (RecvMarker i q r)\n    then have \"p = q\" using True by auto\n    then show ?thesis \n    proof -\n      have f1: \"\\<And>c ca. \\<not> c \\<turnstile> ev \\<mapsto> ca \\<or> ps c p = None \\<or> ps c p = ps ca p\"\n        using RecvMarker \\<open>p = q\\<close> by force\n      have \"\\<And>c ca. ps c p \\<noteq> None \\<or> \\<not> c \\<turnstile> ev \\<mapsto> ca \\<or> ps ca p = Some (states c p)\"\n        using RecvMarker \\<open>p = q\\<close> by force\n      then show ?thesis\n        using f1 by (metis (no_types) assms(1) assms(2) assms(3) assms(4))\n    qed\n  next\n    case (Trans q s s')\n    then have \"p = q\" \n      using True by auto\n    then show ?thesis \n      using Trans assms(1) assms(3) assms(4) by auto\n  next\n    case (Send i q r u u' m)\n    then have \"p = q\" using True by auto\n    then show ?thesis \n      using Send assms(1) assms(3) assms(4) by auto\n  next\n    case (Recv i q r u u' m)\n    then have \"p = q\" using True by auto\n    then show ?thesis \n      using Recv assms(1) assms(3) assms(4) by auto\n  qed\nqed\n\nlemma same_messages_imply_same_resulting_messages:\n  assumes\n    \"msgs c i = msgs d i\"\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"d \\<turnstile> ev \\<mapsto> d'\" and\n    \"regular_event ev\"\n  shows\n    \"msgs c' i = msgs d' i\"\nproof -\n  have \"isTrans ev \\<or> isSend ev \\<or> isRecv ev\" using assms \n    by simp\n  then show ?thesis\n  proof (elim disjE)\n    assume \"isTrans ev\"\n    then show ?thesis \n      by (metis assms(1) assms(2) assms(3) isTrans_def next_trans)\n  next\n    assume \"isSend ev\"\n    then obtain i' r s u u' m where \"ev = Send i' r s u u' m\"\n      by (metis event.collapse(2))\n    with assms show ?thesis by (cases \"i = i'\", auto)\n  next\n    assume \"isRecv ev\"\n    then obtain i' r s u u' m where Recv: \"ev = Recv i' r s u u' m\"\n      by (metis event.collapse(3))\n    with assms show ?thesis by (cases \"i = i'\", auto)\n  qed\nqed\n\nlemma Trans_msg:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"isTrans ev\"\n  shows\n    \"msgs c i = msgs c' i\"\n  using assms(1) assms(2) no_msg_change_if_no_event regular_event by blast\n\nlemma new_msg_in_set_implies_occurrence:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"m \\<notin> set (msgs c i)\" and\n    \"m \\<in> set (msgs c' i)\" and\n    \"channel i = Some (p, q)\"\n  shows\n    \"occurs_on ev = p\" (is ?P)\nproof (rule ccontr)\n  assume \"~ ?P\"\n  have \"set (msgs c' i) \\<subseteq> set (msgs c i)\" \n  proof (cases ev)\n    case (Snapshot r)\n    then have \"msgs c' i = msgs c i\" using \\<open>~ ?P\\<close> assms by simp\n    then show ?thesis by auto\n  next\n    case (RecvMarker i' r s)\n    then show ?thesis\n    proof (cases \"has_snapshotted c r\")\n      case True\n      then show ?thesis\n      proof (cases \"i' = i\")\n        case True\n        then have \"Marker # msgs c' i = msgs c i\" using RecvMarker True assms by simp\n        then show ?thesis \n          by (metis set_subset_Cons)\n      next\n        case False\n        then show ?thesis using RecvMarker True assms by simp\n      qed\n    next\n      case no_snap: False\n      have chan: \"channel i' = Some (s, r)\" \n        using RecvMarker assms(1) can_occur_def by auto\n      then show ?thesis\n      proof (cases \"i' = i\")\n        case True\n        then have \"Marker # msgs c' i = msgs c i\" using RecvMarker assms by simp\n        then show ?thesis by (metis set_subset_Cons)\n      next\n        case False\n        then have \"msgs c' i = msgs c i\" using \\<open>~ ?P\\<close> RecvMarker assms no_snap by simp\n        then show ?thesis by simp\n      qed\n    qed\n  next\n    case (Trans r u u')\n    then show ?thesis using assms \\<open>~ ?P\\<close> by simp\n  next\n    case (Send i' r s u u' m')\n    then have \"i' \\<noteq> i\" using \\<open>~ ?P\\<close> can_occur_def assms by auto\n    then have \"msgs c i = msgs c' i\" using \\<open>~ ?P\\<close> assms Send by simp\n    then show ?thesis by simp\n  next\n    case (Recv i' r s u u' m')\n    then show ?thesis \n      by (metis (no_types, lifting) assms(1) eq_iff local.next.simps(5) set_subset_Cons)\n  qed\n  moreover have \"~ set (msgs c' i) \\<subseteq> set (msgs c i)\" using assms by blast\n  ultimately show False by simp\nqed\n\nlemma new_Marker_in_set_implies_nonregular_occurence:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"Marker \\<notin> set (msgs c i)\" and\n    \"Marker \\<in> set (msgs c' i)\" and\n    \"channel i = Some (p, q)\"\n  shows\n    \"~ regular_event ev\" (is ?P)\nproof (rule ccontr)\n  have \"occurs_on ev = p\" \n    using assms new_msg_in_set_implies_occurrence by blast\n  assume \"~ ?P\"\n  then have \"isTrans ev \\<or> isSend ev \\<or> isRecv ev\" by simp\n  then have \"Marker \\<notin> set (msgs c' i)\"\n  proof (elim disjE, goal_cases)\n    case 1\n    then obtain r u u' where \"ev = Trans r u u'\"\n      by (metis event.collapse(1))\n    then show ?thesis \n      using assms(1) assms(2) by auto\n  next\n    case 2\n    then obtain i' r q u u' m where \"ev = Send i' r q u u' m\"\n      by (metis event.collapse(2))\n    then show ?thesis \n      by (metis (no_types, lifting) Un_iff assms(1) assms(2) empty_iff empty_set insert_iff list.set(2) message.distinct(1) next_send set_append)\n  next\n    case 3\n    then obtain i' r q u u' m where \"ev = Recv i' r q u u' m\"\n      by (metis event.collapse(3))\n    then show ?thesis \n      by (metis assms(1) assms(2) list.set_intros(2) next_recv)\n  qed\n  then show False using assms by simp\nqed\n\nlemma RecvMarker_implies_Marker_in_set:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"ev = RecvMarker cid p q\"\n  shows\n    \"Marker \\<in> set (msgs c cid)\"\n  by (metis (mono_tags, lifting) assms(1) assms(2) can_occur_def distributed_system.happen_implies_can_occur distributed_system_axioms event.simps(30) list.set_sel(1) list.size(3) nat_less_le)\n\nlemma RecvMarker_given_channel:\n  assumes\n    \"isRecvMarker ev\" and\n    \"getId ev = cid\" and\n    \"channel cid = Some (p, q)\" and\n    \"can_occur ev c\"\n  shows\n    \"ev = RecvMarker cid q p\"\n  by (metis (mono_tags, lifting) assms(1) assms(2) assms(3) assms(4) can_occur_def event.case_eq_if event.collapse(5) event.distinct_disc(8,14,18,20) option.inject prod.inject)\n\nlemma Recv_given_channel:\n  assumes\n    \"isRecv ev\" and\n    \"getId ev = cid\" and\n    \"channel cid = Some (p, q)\" and\n    \"can_occur ev c\"\n  shows\n    \"\\<exists>s s' m. ev = Recv cid q p s s' m\"\n  by (metis assms(1) assms(2) assms(3) assms(4) distributed_system.can_occur_Recv distributed_system_axioms event.collapse(3) option.inject prod.inject)\n\nlemma same_cs_if_not_recv:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"~ isRecv ev\"\n  shows\n     \"fst (cs c cid) = fst (cs c' cid)\"\nproof (cases \"channel cid = None\")\n  case True\n  then show ?thesis \n    using assms(1) no_cs_change_if_no_channel by auto\nnext\n  case False\n  then obtain p q where chan: \"channel cid = Some (p, q)\" by auto\n  then show ?thesis\n  proof (cases ev)\n    case (Snapshot r)\n    with Snapshot assms chan show ?thesis by (cases \"r = q\", auto)\n  next\n    case (RecvMarker cid' r s)\n    then show ?thesis\n    proof (cases \"has_snapshotted c r\")\n      case True\n      with assms RecvMarker chan show ?thesis by (cases \"cid' = cid\", auto)\n    next\n      case no_snap: False\n      then show ?thesis\n      proof (cases \"cid' = cid\")\n        case True\n        then show ?thesis using RecvMarker assms chan by auto\n      next\n        case False\n        with assms RecvMarker chan no_snap show ?thesis by (cases \"r = q\", auto)\n      qed\n    qed\n  next\n    case (Trans r u u')\n    then show ?thesis using assms by auto\n  next\n    case (Send r s u u')\n    then show ?thesis using assms by auto\n  qed (metis assms(2) isRecv_def)\nqed\n\nlemma done_only_from_recv_marker:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"channel cid = Some (p, q)\" and\n    \"snd (cs c cid) \\<noteq> Done\" and\n    \"snd (cs c' cid) = Done\"\n  shows\n    \"ev = RecvMarker cid q p\"\nproof (rule ccontr)\n  assume \"~ ev = RecvMarker cid q p\"\n  then show False\n  proof (cases \"isRecvMarker ev\")\n    case True\n    then obtain cid' s r where RecvMarker: \"ev = RecvMarker cid' s r\" by (meson isRecvMarker_def)\n    have \"cid \\<noteq> cid'\"\n    proof (rule ccontr)\n      assume \"~ cid \\<noteq> cid'\"\n      then show False\n        using \\<open>ev = RecvMarker cid' s r\\<close> \\<open>ev \\<noteq> RecvMarker cid q p\\<close> assms(1) assms(2) can_occur_def by auto\n    qed\n    then have \"snd (cs c' cid) \\<noteq> Done\"\n    proof (cases \"has_snapshotted c s\")\n      case True\n      then show ?thesis using RecvMarker assms \\<open>cid \\<noteq> cid'\\<close> by simp\n    next\n      case False\n      with RecvMarker assms \\<open>cid \\<noteq> cid'\\<close> show ?thesis by (cases \"s = q\", auto)\n    qed\n    then show False using assms by auto\n  next\n    case False\n    then have \"isSnapshot ev \\<or> isTrans ev \\<or> isSend ev \\<or> isRecv ev\"\n    using event.exhaust_disc by blast\n    then have \"snd (cs c' cid) \\<noteq> Done\"\n    proof (elim disjE, goal_cases)\n      case 1\n      then obtain r where Snapshot: \"ev = Snapshot r\"\n        by (meson isSnapshot_def)\n      with assms show ?thesis by (cases \"q = r\", auto)\n    next\n      case 2\n      then obtain r u u' where \"ev = Trans r u u'\"\n        by (meson isTrans_def)\n      then show ?case using assms by auto\n    next\n      case 3\n      then obtain cid' r s u u' m where \"ev = Send cid' r s u u' m\"\n        by (meson isSend_def)\n      then show ?thesis using assms by auto\n    next\n      case 4\n      then obtain cid' r s u u' m where Recv: \"ev = Recv cid' r s u u' m\"\n        by (meson isRecv_def)\n      show ?thesis\n      using Recv assms proof (cases \"cid = cid'\")\n        case True\n        then have \"snd (cs c cid) = NotStarted \\<or> snd (cs c cid) = Recording\"\n          using assms(3) recording_state.exhaust by blast\n        then show ?thesis\n        proof (elim disjE, goal_cases)\n          case 1\n          then have \"snd (cs c' cid') = NotStarted\" \n            using True Recv assms(1) by auto\n          then show ?case using True by auto\n        next\n          case 2\n          then have \"snd (cs c' cid') = Recording\"\n            using True Recv assms(1) by auto\n          then show ?case using True by auto\n        qed\n      qed auto\n    qed\n    then show False using assms by auto\n  qed\nqed\n\nlemma cs_not_not_started_stable:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"snd (cs c cid) \\<noteq> NotStarted\" and\n    \"channel cid = Some (p, q)\"\n  shows\n    \"snd (cs c' cid) \\<noteq> NotStarted\"\nusing assms proof (cases ev)\n  case (Snapshot r)\n  then show ?thesis \n    by (metis assms(1) assms(2) next_snapshot recording_state.simps(2) sndI)\nnext\n  case (RecvMarker cid' r s)\n  then show ?thesis\n  proof (cases \"has_snapshotted c r\")\n    case True\n    with RecvMarker assms show ?thesis by (cases \"cid = cid'\", auto)\n  next\n    case no_snap: False\n    then show ?thesis\n    proof (cases \"cid = cid'\")\n      case True\n      then show ?thesis using RecvMarker assms by auto\n    next\n      case False\n      with RecvMarker assms no_snap show ?thesis by (cases \"s = p\", auto)\n    qed\n  qed\nnext\n  case (Recv cid' r s u u' m)\n  then have \"snd (cs c cid) = Recording \\<or> snd (cs c cid) = Done\" \n    using assms(2) recording_state.exhaust by blast\n  then show ?thesis\n  proof (elim disjE, goal_cases)\n    case 1\n    then show ?thesis \n      by (metis (no_types, lifting) Recv assms(1) eq_snd_iff next_recv recording_state.distinct(1))\n  next\n    case 2\n    with Recv assms show ?thesis by (cases \"cid = cid'\", auto)\n  qed\nqed auto\n\nlemma fst_cs_changed_by_recv_recording:\n  assumes\n    step: \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"fst (cs c cid) \\<noteq> fst (cs c' cid)\" and\n    \"channel cid = Some (p, q)\"\n  shows\n    \"snd (cs c cid) = Recording \\<and> (\\<exists>p q u u' m. ev = Recv cid q p u u' m)\"\nproof -\n  have oc_on: \"occurs_on ev = q\" \n  proof -\n    obtain nn :: \"('p, 's, 'm) event \\<Rightarrow> nat\" and aa :: \"('p, 's, 'm) event \\<Rightarrow> 'p\" and aaa :: \"('p, 's, 'm) event \\<Rightarrow> 'p\" and bb :: \"('p, 's, 'm) event \\<Rightarrow> 's\" and bba :: \"('p, 's, 'm) event \\<Rightarrow> 's\" and cc :: \"('p, 's, 'm) event \\<Rightarrow> 'm\" where\n      f1: \"\\<forall>e. (\\<not> isRecv e \\<or> e = Recv (nn e) (aa e) (aaa e) (bb e) (bba e) (cc e)) \\<and> (isRecv e \\<or> (\\<forall>n a aa b ba c. e \\<noteq> Recv n a aa b ba c))\"\n      using isRecv_def by moura\n    then have f2: \"c \\<turnstile> Recv (nn ev) (aa ev) (aaa ev) (bb ev) (bba ev) (cc ev) \\<mapsto> c'\"\n      by (metis (no_types) assms(2) local.step same_cs_if_not_recv)\n    have f3: \"\\<forall>x0 x1 x7 x8. (x0 \\<noteq> x7 \\<longrightarrow> cs (x8::('p, 's, 'm) configuration) x0 = cs (x1::('p, 's, _) configuration) x0) = (x0 = x7 \\<or> cs x8 x0 = cs x1 x0)\"\n      by auto\n    have f4: \"\\<forall>x0 x1 x7 x8. (x7 \\<noteq> x0 \\<longrightarrow> msgs (x1::('p, 's, 'm) configuration) x0 = msgs (x8::('p, 's, _) configuration) x0) = (x7 = x0 \\<or> msgs x1 x0 = msgs x8 x0)\"\n      by auto\n    have \"\\<forall>x0 x1 x6 x8. (x0 \\<noteq> x6 \\<longrightarrow> states (x1::('p, 's, 'm) configuration) x0 = states (x8::(_, _, 'm) configuration) x0) = (x0 = x6 \\<or> states x1 x0 = states x8 x0)\"\n      by fastforce\n    then have \"can_occur (Recv (nn ev) (aa ev) (aaa ev) (bb ev) (bba ev) (cc ev)) c \\<and> states c (aa ev) = bb ev \\<and> states c' (aa ev) = bba ev \\<and> (\\<forall>a. a = aa ev \\<or> states c' a = states c a) \\<and> msgs c (nn ev) = Msg (cc ev) # msgs c' (nn ev) \\<and> (\\<forall>n. nn ev = n \\<or> msgs c' n = msgs c n) \\<and> (\\<forall>a. ps c a = ps c' a) \\<and> (\\<forall>n. n = nn ev \\<or> cs c n = cs c' n) \\<and> (if snd (cs c (nn ev)) = Recording then cs c' (nn ev) = (fst (cs c (nn ev)) @ [cc ev], Recording) else cs c (nn ev) = cs c' (nn ev))\"\n    using f4 f3 f2 by force\n  then show ?thesis\n    using f1 by (metis (no_types) Pair_inject assms(2) assms(3) can_occur_Recv event.sel(3) local.step option.sel same_cs_if_not_recv)\nqed\n  have \"isRecv ev\" (is ?P)\n  proof (rule ccontr)\n    assume \"~ ?P\"\n    then have \"fst (cs c cid) = fst (cs c' cid)\" by (metis local.step same_cs_if_not_recv)\n    then show False using assms by simp\n  qed\n  then obtain cid' r s u u' m where Recv: \"ev = Recv cid' r s u u' m\" by (meson isRecv_def)\n  have \"cid = cid'\"\n  proof (rule ccontr)\n    assume \"~ cid = cid'\"\n    then have \"fst (cs c cid) = fst (cs c' cid)\" using Recv step by auto\n    then show False using assms by simp\n  qed\n  moreover have \"snd (cs c cid) = Recording\"\n  proof (rule ccontr)\n    assume \"~ snd (cs c cid) = Recording\"\n    then have \"fst (cs c cid) = fst (cs c' cid)\" using Recv step \\<open>cid = cid'\\<close> by auto\n    then show False using assms by simp\n  qed\n  ultimately show ?thesis using Recv by simp\nqed\n\nlemma no_marker_and_snapshotted_implies_no_more_markers:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"has_snapshotted c p\" and\n    \"Marker \\<notin> set (msgs c cid)\" and\n    \"channel cid = Some (p, q)\"\n  shows\n    \"Marker \\<notin> set (msgs c' cid)\"\nproof (cases ev)\n  case (Snapshot r)\n  then have \"r \\<noteq> p\" \n    using assms(1) assms(2) can_occur_def by auto\n  then have \"msgs c cid = msgs c' cid\" using assms Snapshot by simp\n  then show ?thesis using assms by simp\nnext\n  case (RecvMarker cid' r s)\n  have \"cid \\<noteq> cid'\"\n  proof (rule ccontr)\n    assume \"~ cid \\<noteq> cid'\"\n    moreover have \"can_occur ev c\" using happen_implies_can_occur assms by blast\n    ultimately have \"Marker : set (msgs c cid)\" using can_occur_def RecvMarker \n      by (metis (mono_tags, lifting) assms(1) event.simps(30) hd_in_set list.size(3) recv_marker_other_channels_not_shrinking zero_order(1))\n    then show False using assms by simp\n  qed\n  then have \"msgs c cid = msgs c' cid\"\n  proof (cases \"r = p\")\n    case True\n    then show ?thesis \n      using RecvMarker \\<open>cid \\<noteq> cid'\\<close> assms(1) assms(2) msgs_unchanged_if_snapshotted_RecvMarker_for_other_is by blast\n  next\n    case False\n    with RecvMarker \\<open>cid \\<noteq> cid'\\<close> step assms show ?thesis by (cases \"has_snapshotted c r\", auto)\n  qed\n  then show ?thesis using assms by simp\nnext\n  case (Trans r u u')\n  then show ?thesis using assms by auto\nnext\n  case (Send cid' r s u u' m)\n  with assms Send show ?thesis by (cases \"cid = cid'\", auto)\nnext\n  case (Recv cid' r s u u' m)\n  with assms Recv show ?thesis by (cases \"cid = cid'\", auto)\nqed\n\nlemma same_messages_if_no_occurrence:\n  assumes\n    \"c \\<turnstile> ev \\<mapsto> c'\" and\n    \"~ occurs_on ev = p\" and\n    \"~ occurs_on ev = q\" and\n    \"channel cid = Some (p, q)\"\n  shows\n    \"msgs c cid = msgs c' cid \\<and> cs c cid = cs c' cid\"\nproof (cases ev)\n  case (Snapshot r)\n  then show ?thesis using assms by auto\nnext\n  case (RecvMarker cid' r s)\n  have \"cid \\<noteq> cid'\"\n    by (metis RecvMarker_given_channel assms(1) assms(3) assms(4) RecvMarker event.sel(5,10) happen_implies_can_occur isRecvMarker_def)\n  have \"\\<nexists>a. channel cid = Some (r, q)\" \n    using assms(2) assms(4) RecvMarker by auto\n  with RecvMarker assms \\<open>cid \\<noteq> cid'\\<close> show ?thesis by (cases \"has_snapshotted c r\", auto)\nnext\n  case (Trans r u u')\n  then show ?thesis using assms by auto\nnext\n  case (Send cid' r s u u' m)\n  then have \"cid \\<noteq> cid'\" \n    by (metis (mono_tags, lifting) Pair_inject assms(1) assms(2) assms(4) can_occur_def event.sel(2) event.simps(27) happen_implies_can_occur option.inject)\n  then show ?thesis using assms Send by simp\nnext\n  case (Recv cid' r s u u' m)\n  then have \"cid \\<noteq> cid'\" \n    by (metis assms(1) assms(3) assms(4) distributed_system.can_occur_Recv distributed_system.happen_implies_can_occur distributed_system_axioms event.sel(3) option.inject prod.inject)\n  then show ?thesis using assms Recv by simp\nqed\n\nend (* locale distributed_system *)\n\nend (* theory Distributed_System *)\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Chandy_Lamport/Distributed_System.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953651858117, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.2819813976805361}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |               December 2004               |\n            |                 August 2005  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |                October 2005  (modified)   |\n            |                  April 2006  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2009-2       |\n            |                October 2010  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2016         |\n            |                    May 2016  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2017         |\n            |                  April 2018  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2018         |\n            |               February 2019  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory Domain_F_cms\nimports Domain_F CSP_T.Domain_T_cms Set_F_cms \n        CSP.RS_pair CSP.RS_prod\nbegin\n\n(*****************************************************************\n\n         1. \n         2. \n         3. \n         4. \n\n *****************************************************************)\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite UnionT and InterT.                 *)\n(*                  Union (B ` A) = (UN x:A. B x)                      *)\n(*                  Inter (B ` A) = (INT x:A. B x)                     *)\n(*\ndeclare Union_image_eq [simp del]\ndeclare Inter_image_eq [simp del]\n*)\n(* no simp rules in Isabelle 2017 \ndeclare Sup_image_eq [simp del]\ndeclare Inf_image_eq [simp del]\n*)\n\n(*********************************************************\n                 Restriction in Dom_F\n *********************************************************)\n\n(*\ninstance domF :: (type) ms0\nby (intro_classes)\n*)\n\ndefinition\n restTF  :: \"'a domF => nat => 'a domTsetF\" (\"_ restTF _\" [84,900] 84)\n where\n restTF_def  : \n   \"F restTF n == (Rep_domF F) .|. n\"\n \ndefinition\n LimitTF :: \"'a domF infinite_seq => 'a domTsetF\"\n where\n  LimitTF_def : \n   \"LimitTF Fs == pair_Limit (Rep_domF o Fs)\"\n \ndefinition \n Limit_domF     :: \"'a domF infinite_seq => 'a domF\"\n where\n  Limit_domF_def     :\n   \"Limit_domF Fs == Abs_domF (LimitTF Fs)\"\n\n(* isabelle 2009-2 *)\n\ninstantiation domF :: (type) rs0\nbegin\n\ndefinition\n  rest_domF_def : \"F .|. n == Abs_domF (F restTF n)\"\n  instance ..\nend\n\n(*\ndefs (overloaded)\n  rest_domF_def : \"F .|. n == Abs_domF (F restTF n)\"\n*)\n\n(*********************************************************\n              Lemmas (Restriction in Dom_F)\n *********************************************************)\n\n(*** restTF (T2) ***)\n\nlemma restTF_T2: \"HC_T2 (F restTF n)\"\napply (simp add: HC_T2_def restTF_def)\napply (intro allI impI)\napply (simp add: pair_restriction_def)\n\napply (simp add: in_rest_domT)\napply (simp add: in_rest_setF)\nby (auto simp add: domTsetF_T2)\n\n(*** restTF (F3) ***)\n\nlemma restTF_F3: \"HC_F3 (F restTF n)\"\napply (simp add: HC_F3_def restTF_def)\napply (intro allI impI)\napply (simp add: pair_restriction_def)\n\napply (simp add: in_rest_domT)\napply (simp add: in_rest_setF)\nby (auto simp add: domTsetF_F3)\n\n(*** restTF (T3_F4) ***)\n\nlemma restTF_T3_F4: \"HC_T3_F4 (F restTF n)\"\napply (simp add: HC_T3_F4_def restTF_def)\napply (intro allI impI)\napply (simp add: pair_restriction_def)\n\napply (simp add: in_rest_domT)\napply (simp add: in_rest_setF)\napply (elim conjE)\nby (auto simp add: domTsetF_T3 domTsetF_F4)\n\n(*** restTF in domF ***)\n\nlemma restTF_in[simp]: \"F restTF n : domF\"\napply (simp add: domF_iff)\napply (simp add: restTF_T2)\napply (simp add: restTF_F3)\napply (simp add: restTF_T3_F4)\ndone\n\n(*********************************************************\n                     Dom_F --> RS\n *********************************************************)\n\n(*** rest_domF --> restTF ***)\n\nlemma Rep_rest_domF: \n  \"((F::'a domF) .|. n = E .|. m) =\n   ((Rep_domF F) .|. n = (Rep_domF E) .|. m)\"\napply (simp add: rest_domF_def)\napply (simp add: Abs_domF_inject)\napply (simp add: restTF_def)\ndone\n\n(*** zero_eq_rs_domF ***)\n\nlemma zero_eq_rs_domF: \"(F::'a domF) .|. 0 = E .|. 0\"\nby (simp add: Rep_rest_domF)\n\n(*** min_rs_domF ***)\n\nlemma min_rs_domF:\n  \"((F::'a domF) .|. m) .|. n = F .|. (min m n)\"\napply (simp add: Rep_rest_domF)\napply (simp add: rest_domF_def)\napply (simp add: Abs_domF_inverse)\napply (simp add: restTF_def)\napply (simp add: min_rs)\ndone\n\n(*** diff_rs_domF ***)\n\nlemma diff_rs_domF: \n  \"(F::'a domF) ~= E ==> (EX (n::nat). F .|. n ~= E .|. n)\"\napply (simp add: Rep_rest_domF)\napply (simp add: Rep_domF_inject[THEN sym])\napply (simp add: diff_rs)\ndone\n\n(***************************************************************\n                        domF ==> RS\n ***************************************************************)\n\ninstance domF :: (type) rs\napply (intro_classes)\napply (simp add: zero_eq_rs_domF)\napply (simp add: min_rs_domF)\napply (simp add: diff_rs_domF)\ndone\n\n(************************************************************\n                        domF ==> MS\n ************************************************************)\n\ninstantiation domF :: (type) ms0\nbegin\n\ndefinition\n  domF_distance_def:\n     \"distance (FF::('a domF * 'a domF)) = distance_rs FF\"\n  instance ..\nend\n\ninstance domF :: (type) ms\napply (intro_classes)\napply (simp_all add: domF_distance_def)\napply (simp add: diagonal_rs)\napply (simp add: symmetry_rs)\napply (simp add: triangle_inequality_rs)\ndone\n\n(************************************************************\n                 i.e.  domF ==> MS & RS \n ************************************************************)\n\ninstance domF :: (type) ms_rs\napply (intro_classes)\napply (simp add: domF_distance_def)\ndone\n\n\n(********************************************************** \n                      .|. decompo \n **********************************************************)\n\nlemma rest_decompo_domF:\n   \"(SF1 .|. n = SF2 .|. m)\n   = ((fstF SF1 .|. n = fstF SF2 .|. m &\n       sndF SF1 .|. n = sndF SF2 .|. m))\"\napply (simp add: rest_domF_def)\napply (simp add: Abs_domF_inject)\napply (simp add: restTF_def)\napply (simp add: pair_restriction_def)\napply (simp add: fold_fstF)\napply (simp add: fold_sndF)\ndone\n\n(***********************************************************\n                    lemmas (distance)\n ***********************************************************)\n\n(*** distance ***)\n\nlemma distance_Rep_domF:\n  \"distance((F::'a domF), E) = distance(Rep_domF F, Rep_domF E)\"\napply (simp add: to_distance_rs)\napply (simp add: Rep_rest_domF rest_distance_eq)\ndone\n\nlemma distance_Abs_domF:\n  \"[| (T1, F1) : domF ; (T2, F2) : domF |]\n   ==> distance (Abs_domF (T1, F1), Abs_domF (T2, F2))\n     = distance ((T1, F1), T2, F2)\"\nby (simp add: distance_Rep_domF Abs_domF_inverse)\n\n(*** normal ***)\n\nlemma normal_domF:\n  \"normal (Fs::'a domF infinite_seq) = normal (Rep_domF o Fs)\"\nby (simp add: normal_def distance_Rep_domF)\n\nlemma normal_domF_only_if:\n  \"normal (Fs::'a domF infinite_seq) ==> normal (Rep_domF o Fs)\"\nby (simp add: normal_domF)\n\n(* T and F *)\n\nlemma normal_of_domF:\n  \"normal (Fs::'a domF infinite_seq)\n   ==> (normal (fstF o Fs) & normal (sndF o Fs))\"\napply (simp add: normal_domF)\napply (simp add: fstF_def sndF_def)\napply (simp add: o_assoc[THEN sym])\napply (simp add: pair_normal_seq)\ndone\n\n(*** cauchy ***)\n\nlemma cauchy_domF:\n  \"cauchy (Fs::'a domF infinite_seq) = cauchy (Rep_domF o Fs)\"\nby (simp add: cauchy_def distance_Rep_domF)\n\nlemma cauchy_domF_only_if:\n  \"cauchy (Fs::'a domF infinite_seq) ==> cauchy (Rep_domF o Fs)\"\nby (simp add: cauchy_domF)\n\n(* T and F *)\n\nlemma cauchy_of_domF:\n  \"cauchy (Fs::'a domF infinite_seq)\n   ==> (cauchy (fstF o Fs) & cauchy (sndF o Fs))\"\napply (simp add: cauchy_domF)\napply (simp add: fstF_def sndF_def)\napply (simp add: o_assoc[THEN sym])\napply (simp add: pair_cauchy_seq)\ndone\n\n(***********************************************************\n                      lemmas (Limit)\n ***********************************************************)\n\n(*** convergeTo domF ***)\n\nlemma convergeTo_domF:\n  \"[| (Rep_domF o Fs) convergeTo TF ; TF : domF |]\n   ==> Fs convergeTo Abs_domF TF\"\napply (simp add: convergeTo_def)\napply (intro allI impI)\napply (drule_tac x=\"eps\" in spec)\napply (simp)\napply (erule exE)\napply (rule_tac x=\"n\" in exI)\napply (intro allI impI)\napply (drule_tac x=\"m\" in spec)\n\napply (simp add: distance_Rep_domF)\napply (simp add: Abs_domF_inverse)\ndone\n\n(*** LimitTF ***)\n\nlemma LimitTF_iff:\n  \"normal (Rep_domF o Fs) \n      ==> pair_Limit (Rep_domF o Fs)\n           = (Limit_domT (fstF o Fs) , Limit_setF (sndF o Fs))\"\napply (simp add: pair_Limit_def)\napply (simp add: fstF_def sndF_def)\napply (simp add: o_assoc[THEN sym])\napply (simp add: pair_normal_seq Limit_domT_Limit_eq Limit_setF_Limit_eq)\ndone\n\n(*******************************\n      LimitTF in domF\n *******************************)\n\n(*** F4 ***)\n\nlemma LimitTF_F4:\n  \"normal Fs ==> HC_F4 (Limit_domT (fstF o Fs) , Limit_setF (sndF o Fs))\"\napply (simp add: HC_F4_def)\napply (intro allI impI)\n\napply (simp add: normal_of_domF Limit_domT_memT)\napply (simp add: normal_of_domF Limit_setF_memF)\n\napply (subgoal_tac \"(Rep_domF (Fs (lengtht (s ^^^ <Tick>)))) : domF\")\napply (simp add: domF_def HC_F4_def)\napply (elim conjE)\napply (drule_tac x=\"s\" in spec)\napply (simp add: fstF_def sndF_def)\nby (simp)\n\n(*** T3 ***)\n\nlemma LimitTF_T3:\n  \"normal Fs ==> HC_T3 (Limit_domT (fstF o Fs) , Limit_setF (sndF o Fs))\"\napply (simp add: HC_T3_def)\napply (intro allI impI)\napply (simp add: normal_of_domF Limit_domT_memT)\napply (simp add: normal_of_domF Limit_setF_memF)\n\napply (subgoal_tac \"(Rep_domF (Fs (lengtht (s ^^^ <Tick>)))) : domF\")\napply (simp add: domF_def HC_T3_def)\napply (elim conjE)\napply (drule_tac x=\"s\" in spec)\napply (simp add: fstF_def sndF_def)\napply (rule disjI2)\napply (rule_tac x=\"s\" in exI)\napply (simp)\nby (simp)\n\n(*** F3 ***)\n\nlemma LimitTF_F3:\n  \"normal Fs ==> HC_F3 (Limit_domT (fstF o Fs) , Limit_setF (sndF o Fs))\"\napply (simp add: HC_F3_def)\napply (intro allI impI)\n\napply (simp add: normal_of_domF Limit_domT_memT)\napply (simp add: normal_of_domF Limit_setF_memF)\napply (elim conjE disjE)\n\napply (subgoal_tac \"(Rep_domF (Fs (Suc (lengtht s)))) : domF\")\napply (simp add: domF_def HC_F3_def)\napply (elim conjE)\napply (drule_tac x=\"s\" in spec)\napply (drule_tac x=\"X\" in spec)\napply (drule_tac x=\"Y\" in spec)\napply (simp add: fstF_def sndF_def)\napply (simp)\n\napply (erule exE)\napply (simp)\ndone\n\n(*** T2 ***)\n\nlemma LimitTF_T2:\n  \"normal Fs ==> HC_T2 (Limit_domT (fstF o Fs) , Limit_setF (sndF o Fs))\"\napply (simp add: HC_T2_def)\napply (intro allI impI)\n\napply (simp add: normal_of_domF Limit_domT_memT)\napply (simp add: normal_of_domF Limit_setF_memF)\napply (elim exE disjE)\n\napply (subgoal_tac \"(Rep_domF (Fs (Suc (lengtht s)))) : domF\")\napply (simp add: domF_def HC_T2_def)\napply (elim conjE)\napply (drule_tac x=\"s\" in spec)\napply (simp add: fstF_def sndF_def)\napply (drule mp)\napply (rule_tac x=\"X\" in exI, simp)\napply (rule normal_seq_domT_if)\n apply (subgoal_tac \"(%u. fst (Rep_domF (Fs u))) = (fstF o Fs )\")\n apply (simp add: normal_of_domF)\n apply (simp add: fun_eq_iff fstF_def)\n apply (simp_all)\n\n(* *)\n\napply (elim conjE exE)\napply (subgoal_tac \"(Rep_domF (Fs (lengtht s))) : domF\")\napply (simp add: domF_def HC_T2_def)\napply (elim conjE)\napply (drule_tac x=\"s\" in spec)\napply (simp add: fstF_def sndF_def)\napply (drule mp)\napply (rule_tac x=\"X\" in exI, simp)\napply (simp_all)\ndone\n\n(*** Limit_domFpari_in ***)\n\nlemma LimitTF_in:\n  \"normal Fs ==> LimitTF Fs : domF\"\napply (simp add: LimitTF_def)\napply (simp add: LimitTF_iff normal_domF_only_if)\napply (simp add: domF_def)\napply (simp add: LimitTF_F4)\napply (simp add: LimitTF_T3)\napply (simp add: LimitTF_F3)\napply (simp add: LimitTF_T2)\ndone\n\n(*** (normal) Fs converges to (Limit_domF Fs) ***)\n\nlemma Limit_domF_Limit: \"normal Fs ==> Fs convergeTo (Limit_domF Fs)\"\napply (simp add: Limit_domF_def)\napply (rule convergeTo_domF)\napply (simp add: LimitTF_def)\napply (simp add: pair_cms_cauchy_Limit normal_cauchy normal_domF)\n\nby (simp add: LimitTF_in)\n\n(*** (cauchy) Fs converges to (Limit_domF NF Fs) ***)\n\nlemma cauchy_Limit_domF_Limit:\n  \"cauchy Fs ==> Fs convergeTo (Limit_domF (NF Fs))\"\nby (simp add: Limit_domF_Limit normal_form_seq_same_Limit normal_form_seq_normal)\n\n(**************************************\n    Dom_F --> Complete Metric Space\n **************************************)\n\nlemma domF_cms:\n  \"cauchy (Fs::'a domF infinite_seq) ==> (EX F. Fs convergeTo F)\"\napply (rule_tac x=\"Limit_domF (NF Fs)\" in exI)\nby (simp add: cauchy_Limit_domF_Limit)\n\n(************************************************************\n                   domF ==> CMS and RS\n ************************************************************)\n\ninstance domF :: (type) cms\napply (intro_classes)\nby (simp add: domF_cms)\n\ninstance domF :: (type) cms_rs\nby (intro_classes)\n\n(*** (normal) Limit Fs = Limit_domF Fs ***)\n\nlemma Limit_domF_Limit_eq:\n  \"normal (Fs::'a domF infinite_seq) ==> Limit Fs = Limit_domF Fs\"\napply (rule unique_convergence[of Fs])\nby (simp_all add: Limit_domF_Limit Limit_is normal_cauchy)\n\n(************************************************************\n                 .|. domF decompostion\n ************************************************************)\n\nlemma rest_domF_decompo_sub:\n   \"ALL x. (f x, g x): domF ==>\n     ((f x1 ,, g x1) .|. n <= ((f x2 ,, g x2) .|. n))\n   = (f x1 .|. n <= f x2 .|. n &\n      g x1 .|. n <= g x2 .|. n)\"\napply (simp add: rest_domF_def)\napply (simp add: subdomF_def)\napply (simp add: Abs_domF_inverse)\n\napply (simp add: pairF_def)\napply (simp add: restTF_def)\napply (simp add: Abs_domF_inverse)\napply (simp add: pair_restriction_def)\napply (simp add: order_pair_def)\ndone\n\nlemma rest_domF_decompo:\n   \"ALL x. (f x, g x): domF ==>\n     ((f x1 ,, g x1) .|. n = ((f x2 ,, g x2) .|. n))\n   = (f x1 .|. n = f x2 .|. n &\n      g x1 .|. n = g x2 .|. n)\"\napply (rule)\napply (simp add: order_eq_iff)\napply (simp add: rest_domF_decompo_sub)\napply (simp add: order_eq_iff)\napply (simp add: rest_domF_decompo_sub)\ndone\n\n(************************************************************\n                  map domF decompostion\n ************************************************************)\n\n(* Abs_domF *)\n\nlemma map_alpha_Abs_domF:\n  \"ALL x. (f x, g x): domF ==>\n   map_alpha (%x. (f x,, g x)) alpha = map_alpha (f ** g) alpha\"\napply (simp add: pairF_def)\napply (simp add: contraction_alpha_def map_alpha_def)\napply (simp add: pair_fun_def)\napply (simp add: distance_Abs_domF)\ndone\n\n(* decompo *)\n\nlemma map_alpha_domF_decompo:\n  \"ALL (x::'a::ms_rs). (f x, g x): domF ==>\n   map_alpha  (%x. (f x,, g x)) alpha = \n   (map_alpha f alpha & map_alpha g alpha)\"\napply (simp add: map_alpha_Abs_domF)\napply (simp add: pair_map_alpha_compo)\ndone\n\nlemma non_expanding_domF_decompo:\n  \"ALL (x::'a::ms_rs). (f x, g x): domF ==>\n   non_expanding (%x. (f x,, g x)) =\n   (non_expanding f & non_expanding g)\"\napply (simp add: non_expanding_def)\napply (simp add: map_alpha_domF_decompo)\ndone\n\nlemma contraction_alpha_domF_decompo:\n  \"ALL (x::'a::ms_rs). (f x, g x): domF ==>\n   contraction_alpha (%x. (f x,, g x)) alpha =\n   (contraction_alpha f alpha & contraction_alpha g alpha)\"\napply (simp add: contraction_alpha_def)\napply (simp add: map_alpha_domF_decompo)\napply (auto)\ndone\n\n(********************************************************** \n                non expanding (op o fstF)\n **********************************************************)\n\nlemma non_expanding_Rep_domF: \"non_expanding Rep_domF\"\napply (simp add: non_expanding_def)\napply (simp add: map_alpha_def)\napply (simp add: distance_Rep_domF)\ndone\n\nlemma non_expanding_fstF: \"non_expanding fstF\"\napply (simp add: fstF_def)\napply (rule compo_non_expand)\napply (simp add: fst_non_expand)\napply (simp add: non_expanding_Rep_domF)\ndone\n\nlemma non_expanding_sndF: \"non_expanding sndF\"\napply (simp add: sndF_def)\napply (rule compo_non_expand)\napply (simp add: snd_non_expand)\napply (simp add: non_expanding_Rep_domF)\ndone\n\nlemma non_expanding_op_fstF: \"non_expanding ((o) fstF)\"\napply (simp add: prod_non_expand)\napply (insert non_expanding_fstF)\napply (simp add: proj_fun_def)\napply (simp add: non_expanding_def)\napply (simp add: map_alpha_def)\napply (intro allI)\napply (drule_tac x=\"x i\" in spec)\napply (drule_tac x=\"y i\" in spec)\napply (rule order_trans)\napply (simp)\n\napply (subgoal_tac \"non_expanding (proj_fun i)\")\napply (simp add: non_expanding_def)\napply (simp add: map_alpha_def)\napply (simp add: proj_fun_def)\napply (fast)\n\napply (simp add: proj_non_expand)\ndone\n\nlemma non_expanding_op_sndF: \"non_expanding ((o) sndF)\"\napply (simp add: prod_non_expand)\napply (insert non_expanding_sndF)\napply (simp add: proj_fun_def)\napply (simp add: non_expanding_def)\napply (simp add: map_alpha_def)\napply (intro allI)\napply (drule_tac x=\"x i\" in spec)\napply (drule_tac x=\"y i\" in spec)\napply (rule order_trans)\napply (simp)\n\napply (subgoal_tac \"non_expanding (proj_fun i)\")\napply (simp add: non_expanding_def)\napply (simp add: map_alpha_def)\napply (simp add: proj_fun_def)\napply (fast)\n\napply (simp add: proj_non_expand)\ndone\n\n(*** distance ***)\n\ndeclare [[show_sorts]]\n\n\nlemma distance_fstF_compo_le: \n  \"distance (fstF o x, fstF o y) <= distance (x, y)\"\napply (insert non_expanding_op_fstF)\napply (simp add: non_expanding_def)\napply (simp add: map_alpha_def)\napply (auto)\ndone\n\nlemma alpha_distance_fstF_compo_le: \n  \"0 <= alpha ==> alpha * distance (fstF o x, fstF o y) <= alpha * distance (x, y)\"\napply (insert mult_left_mono\n       [of \"distance (fstF o x, fstF o y)\" \"distance (x, y)\" \"alpha\" ])\napply (simp add: distance_fstF_compo_le)\ndone\n\n(*----------------------------------------------------------*\n |                                                          |\n |                       cms rs order                       |\n |                                                          |\n *----------------------------------------------------------*)\n\ninstance domF :: (type) ms_rs_order0\napply (intro_classes)\ndone\n\ninstance domF :: (type) ms_rs_order\napply (intro_classes)\napply (intro allI)\napply (rule iffI)\napply (simp add: rest_domF_def)\napply (simp add: subdomF_def)\napply (simp add: Abs_domF_inverse)\napply (simp add: restTF_def)\napply (simp add: pair_restriction_def)\napply (simp add: order_pair_def)\napply (erule dist_ALL_conjE)\napply (simp add: rs_order_iff)\n\napply (intro allI)\napply (simp add: rest_domF_def)\napply (simp add: subdomF_def)\napply (simp add: Abs_domF_inverse)\napply (simp add: restTF_def)\napply (simp add: pair_restriction_def)\napply (simp add: order_pair_def)\napply (simp add: rs_order_if)\ndone\n\ninstance domF :: (type) cms_rs_order\nby (intro_classes)\n\n(*----------------------------------------------------------*\n |                                                          |\n |  i.e. lemma \"continuous_rs (Ref_fun (S::'a domF))\"       |\n |       by (simp add: continuous_rs_Ref_fun)               |\n |                                                          |\n |  see RS.thy                                              |\n |                                                          |\n *----------------------------------------------------------*)\n\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/CSP_F/Domain_F_cms.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5774953651858117, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.2819813976805361}}
{"text": "(*  Title:      HOL/Auth/n_deadlock_on_inis.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\n(*header{*The n_deadlock Protocol Case Study*}*) \n\ntheory n_deadlock_on_inis imports n_deadlock_on_ini\nbegin\nlemma on_inis:\n  assumes b1: \"f \\<in> (invariants N)\" and b2: \"ini \\<in> {andList (allInitSpecs N)}\" and b3: \"formEval ini s\"\n  shows \"formEval f s\"\n  proof -\n  have c1: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__1  p__Inv3 p__Inv4)\\<or>\n    (\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__2  p__Inv4)\\<or>\n    (\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__3  p__Inv3 p__Inv4)\\<or>\n    (\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__4  p__Inv4)\\<or>\n    (\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__5  p__Inv3 p__Inv4)\"\n  apply (cut_tac b1, simp) done\n    moreover {\n      assume d1: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__1  p__Inv3 p__Inv4)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__1)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__2  p__Inv4)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__2)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__3  p__Inv3 p__Inv4)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__3)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__4  p__Inv4)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__4)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__5  p__Inv3 p__Inv4)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__5)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n  ultimately show \"formEval f s\"\n  by satx\nqed\n\nend\n", "meta": {"author": "hongjianjiang", "repo": "paraverif_dafny", "sha": "083d86afb46a847783cb9319d975b3c2ad0afe93", "save_path": "github-repos/isabelle/hongjianjiang-paraverif_dafny", "path": "github-repos/isabelle/hongjianjiang-paraverif_dafny/paraverif_dafny-083d86afb46a847783cb9319d975b3c2ad0afe93/examples/n_deadlock/n_deadlock_on_inis.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331606115021, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.2819240999295578}}
{"text": "theory LR3_Compressed\n  imports Compressed_Oracles.CO_Invariants General_Luby_Rackoff\nbegin\n\n(* U_UP,i, using compressed queries *)\ndefinition UPc :: \\<open>(whole \\<times> whole \\<times> db) ell2 \\<Rightarrow>\\<^sub>C\\<^sub>L (whole \\<times> whole \\<times> db) ell2\\<close> where \\<open>UPc = \n  (reg_1_3 o Fst; reg_2_3 o Snd) cnot o\\<^sub>C\\<^sub>L\n  (reg_1_3 o Snd; reg_2_3 o Fst) cnot o\\<^sub>C\\<^sub>L\n  (reg_1_3 o Fst; (reg_2_3 o Fst; reg_3_3)) query\\<close>\n(* U_UP,i, using compressed queries, query' variant *)\n(* We probably will only use this one because we want to use preserve_query1'_fixY_output which is only available for query *)\ndefinition UPc' :: \\<open>(whole \\<times> whole \\<times> db) ell2 \\<Rightarrow>\\<^sub>C\\<^sub>L (whole \\<times> whole \\<times> db) ell2\\<close> where \\<open>UPc' = \n  (reg_1_3 o Fst; reg_2_3 o Snd) cnot o\\<^sub>C\\<^sub>L\n  (reg_1_3 o Snd; reg_2_3 o Fst) cnot o\\<^sub>C\\<^sub>L\n  (reg_1_3 o Fst; (reg_2_3 o Fst; reg_3_3)) query'\\<close>\n\n(* LR3 using compressed oracles *)\ndefinition LR3c where \\<open>LR3c =\n  (X;(X1;D1)) UPc o\\<^sub>C\\<^sub>L (X1;(X2;D2)) UPc o\\<^sub>C\\<^sub>L (X2;(Y;D3)) UPc o\\<^sub>C\\<^sub>L (X1;(X2;D2)) UPc o\\<^sub>C\\<^sub>L (X;(X1;D1)) UPc\\<close>\ndefinition LR3c' where \\<open>LR3c' =\n  (X;(X1;D1)) UPc' o\\<^sub>C\\<^sub>L (X1;(X2;D2)) UPc' o\\<^sub>C\\<^sub>L (X2;(Y;D3)) UPc' o\\<^sub>C\\<^sub>L (X1;(X2;D2)) UPc' o\\<^sub>C\\<^sub>L (X;(X1;D1)) UPc'\\<close>\n\n(* Notion of good from the current eprint of the LR4-paper. Note: uniqueness condition missing. *)\ndefinition old_good where \\<open>old_good D1 D2 D3 \\<longleftrightarrow> (\\<forall>x2L \\<in> dom D3. \\<exists>xL\\<in>dom D1. \\<exists>\\<beta>\\<in>ran D2. x2L = xL + \\<beta>)\\<close>\n  for D1 D2 D3 :: db\n\n(* Notion of good from the current eprint of the LR4-paper, more intuitive formulation *)\nlemma old_good_alt_def: \\<open>old_good D1 D2 D3 \\<longleftrightarrow> (\\<forall>x2L \\<in> dom D3. \\<exists>xL xR. do { (x2L',x2R) \\<leftarrow> LR2 D1 D2 (xL,xR); Some (x2L=x2L') } = Some True)\\<close>\n  for D1 D2 D3\nproof (unfold old_good_def; intro iffI ballI)\n  fix x2L assume x2L_D3: \\<open>x2L \\<in> dom D3\\<close>\n  assume \\<open>\\<forall>x2L\\<in>dom D3. \\<exists>xL\\<in>dom D1. \\<exists>\\<beta>\\<in>ran D2. x2L = xL + \\<beta>\\<close>\n  from this[rule_format, OF x2L_D3]\n  obtain xL \\<beta> where \\<open>xL \\<in> dom D1\\<close> \\<open>\\<beta> \\<in> ran D2\\<close> \\<open>x2L = xL + \\<beta>\\<close>\n    by auto\n  from \\<open>xL \\<in> dom D1\\<close> obtain \\<alpha> where [simp]: \\<open>D1 xL = Some \\<alpha>\\<close>\n    by force\n  from \\<open>\\<beta> \\<in> ran D2\\<close> obtain D2_in where [simp]: \\<open>D2 D2_in = Some \\<beta>\\<close>\n    by (smt (verit, del_insts) mem_Collect_eq ran_def)\n  have \\<open>LR2 D1 D2 (xL, D2_in + \\<alpha>) \\<bind> (\\<lambda>(x2L', x2R). Some (x2L = x2L')) = Some True\\<close>\n    using \\<open>x2L = xL + \\<beta>\\<close> by (auto simp: LR2_def)\n  then show \\<open>\\<exists>xL xR. LR2 D1 D2 (xL, xR) \\<bind> (\\<lambda>(x2L', x2R). Some (x2L = x2L')) = Some True\\<close>\n    by auto\nnext\n  fix x2L assume x2L_D3: \\<open>x2L \\<in> dom D3\\<close>\n  assume \\<open>\\<forall>x2L\\<in>dom D3. \\<exists>xL xR. LR2 D1 D2 (xL, xR) \\<bind> (\\<lambda>(x2L', x2R). Some (x2L = x2L')) = Some True\\<close>\n  from this[rule_format, OF x2L_D3]\n  show \\<open>\\<exists>xL\\<in>dom D1. \\<exists>\\<beta>\\<in>ran D2. x2L = xL + \\<beta>\\<close>\n    by (smt (z3) LR2_def bind_eq_Some_conv domI old.prod.case option.inject ranI)\nqed\n\ndefinition x1_x2_00 :: \\<open>state set\\<close> where \\<open>x1_x2_00 = {(x,0,0,y,D1,D2,D3)| x y D1 D2 D3. True}\\<close>\ndefinition x2_0 :: \\<open>state set\\<close> where \\<open>x2_0 = {(x,x1,0,y,D1,D2,D3)| x x1 y D1 D2 D3. True}\\<close>\n\n(* definition old_good_state_00 :: \\<open>state set\\<close> where \\<open>old_good_state_00 = {(x,0,0,y,D1,D2,D3)| x y D1 D2 D3. old_good D1 D2 D3}\\<close> *)\n(* definition old_good_state_0 :: \\<open>state set\\<close> where \\<open>old_good_state_0 = {(x,x1,0,y,D1,D2,D3)| x x1 y D1 D2 D3. old_good D1 D2 D3}\\<close> *)\ndefinition old_good_state :: \\<open>state set\\<close> where \\<open>old_good_state = {(x,x1,x2,y,D1,D2,D3). old_good D1 D2 D3}\\<close>\n\nabbreviation \\<open>old_good_state_00 \\<equiv> old_good_state \\<inter> x1_x2_00\\<close> (* TODO remove *)\nabbreviation \\<open>old_good_state_0 \\<equiv> old_good_state \\<inter> x2_0\\<close> (* TODO remove *)\n\ndefinition \\<open>co1_old_good = 2 / sqrt N\\<close>\nlemma preserves_co1_old_good:\n  \\<open>preserves_ket ((X o Fst; (X1 o Fst; D1)) query) old_good_state_00 old_good_state_0 co1_old_good\\<close>\nproof -\n  define K :: \\<open>(half\\<times>half\\<times>whole\\<times>db\\<times>db\\<times>db) \\<Rightarrow> state ell2 ccsubspace\\<close> \n    where \\<open>K = (\\<lambda>(xL,xR,y,D1',D2,D3).\n          ket_invariant {((xL,xR),(x1L,0),0,y,D1'(xL:=d),D2,D3) | x1L d. True})\\<close>\n  define M :: \\<open>(half\\<times>half\\<times>whole\\<times>db\\<times>db\\<times>db) set\\<close> where\n    \\<open>M = {(xL,xR,y,D1',D2,D3). D1' xL = None \\<and> (\\<exists>d. old_good (D1'(xL:=d)) D2 D3)}\\<close>\n\n  define I1 J1 :: \\<open>(half\\<times>half\\<times>whole\\<times>db\\<times>db\\<times>db) \\<Rightarrow> (half \\<times> half option) set\\<close> \n    where \\<open>I1 = (\\<lambda>(xL,xR,y,D1',D2,D3).\n          {0} \\<times> {d. old_good (D1'(xL:=d)) D2 D3})\\<close>\n      and \\<open>J1 = (\\<lambda>(xL,xR,y,D1',D2,D3). \n          UNIV \\<times> {d. old_good (D1'(xL:=d)) D2 D3})\\<close>\n\n  show ?thesis\n  proof (rule inv_split_reg_query[where X=\\<open>X o Fst\\<close> and Y=\\<open>X1 o Fst\\<close> and H=\\<open>D1\\<close> and K=K\n        and ?I1.0=\\<open>\\<lambda>z. ket_invariant (I1 z)\\<close> and ?J1.0=\\<open>\\<lambda>z. ket_invariant (J1 z)\\<close>])\n    show \\<open>(X \\<circ> Fst;(X1 \\<circ> Fst;D1)) query = (X \\<circ> Fst;(X1 \\<circ> Fst;D1)) query\\<close>\n      by simp\n    show [simp]: \\<open>compatible (X \\<circ> Fst) (X1 \\<circ> Fst)\\<close> \\<open>compatible (X \\<circ> Fst) D1\\<close> \\<open>compatible (X1 \\<circ> Fst) D1\\<close>\n      by simp_all\n    show \\<open>compatible_register_invariant (X1 \\<circ> Fst) (K z)\\<close> for z\n      apply (cases z, hypsubst_thin)\n      by (auto simp add: K_def X1_def comp_assoc\n          intro!: compatible_register_invariant_Snd_comp compatible_register_invariant_Fst compatible_register_invariant_Fst_comp)\n    show \\<open>compatible_register_invariant (D1 \\<circ> function_at (fst z)) (K z)\\<close> for z\n      by (auto simp add: K_def D1_def comp_assoc case_prod_beta\n          intro!: compatible_register_invariant_Snd_comp compatible_register_invariant_Fst compatible_register_invariant_Fst_comp\n          compatible_register_invariant_function_at)\n    show \\<open>ket_invariant old_good_state_00 \\<le> (SUP z\\<in>M. K z \\<sqinter> lift_invariant (X1 \\<circ> Fst;D1 \\<circ> function_at (fst z)) (ket_invariant (I1 z)))\\<close>\n      apply (auto simp add: K_def D1_def lift_Fst_ket_inv ket_invariant_inter ket_invariant_SUP[symmetric] I1_def\n          old_good_state_def x1_x2_00_def case_prod_beta comp_assoc X1_def M_def zero_prod_def\n          lift_inv_prod lift_invariant_comp lift_invariant_function_at_ket_inv lift_Snd_ket_inv)\n      by (metis fun_upd_same fun_upd_triv fun_upd_upd)\n    show \\<open>K z \\<sqinter> lift_invariant (X1 \\<circ> Fst;D1 \\<circ> function_at (fst z)) (ket_invariant (J1 z)) \\<le> ket_invariant old_good_state_0\\<close>\n      if \\<open>z\\<in>M\\<close> for z\n      using that \n      apply (cases z, hypsubst_thin)\n      by (auto simp add: K_def lift_Fst_ket_inv ket_invariant_inter ket_invariant_SUP[symmetric] J1_def\n          case_prod_beta D1_def comp_assoc X1_def old_good_state_def x2_0_def M_def\n          lift_inv_prod lift_invariant_comp lift_invariant_function_at_ket_inv reg_3_3_def lift_Snd_ket_inv)\n    show \\<open>orthogonal_spaces (K z) (K z')\\<close> if \\<open>z\\<in>M\\<close> \\<open>z'\\<in>M\\<close> \\<open>z \\<noteq> z'\\<close> for z z'\n      apply (cases z; cases z')\n      using that apply (auto simp: K_def M_def)\n      by (metis fun_upd_triv fun_upd_upd)\n    show \\<open>K z \\<le> lift_invariant (X \\<circ> Fst) (ket_invariant {fst z})\\<close> for z\n      by (auto simp: K_def X_def lift_Fst_ket_inv lift_invariant_comp case_prod_beta)\n    show [simp]: \\<open>0 \\<le> co1_old_good\\<close>\n      by (simp add: co1_old_good_def)\n    show \\<open>preserves_ket query1 (I1 z) (J1 z) co1_old_good\\<close> if \\<open>z\\<in>M\\<close> for z\n    proof (cases z)\n      case (fields xL xR y D1' D2 D3)\n      from that have D1'xL: \\<open>D1' xL = None\\<close>\n        by (auto simp: M_def fields)\n      show ?thesis\n      proof (cases \\<open>old_good D1' D2 D3\\<close>)\n        case True\n        show ?thesis\n          apply (simp only: case_prod_beta I1_def J1_def fst_conv snd_conv fields)\n        proof (rule preserve_query1_fixY[where b\\<^sub>i=N and b\\<^sub>j\\<^sub>0=0])\n          show \\<open>{d. old_good (D1'(xL := d)) D2 D3} \\<subseteq> {d. old_good (D1'(xL := d)) D2 D3}\\<close> by simp\n          show \\<open>card (Some -` {d. old_good (D1'(xL := d)) D2 D3}) \\<le> N\\<close> by (simp add: card_mono)\n          show \\<open>card (- Some -` {d. old_good (D1'(xL := d)) D2 D3}) \\<le> 0\\<close> \n            using True D1'xL apply auto\n            by (simp add: old_good_def)\n          have *: \\<open>old_good (D1'(xL := None)) D2 D3\\<close>\n            by (simp add: D1'xL True domIff)\n          show \\<open>preserve_query1_fixY_bound\n             (None \\<in> {d. old_good (D1'(xL := d)) D2 D3}) (None \\<notin> {d. old_good (D1'(xL := d)) D2 D3})\n             (real N) (real 0) \\<le> co1_old_good\\<close>\n            by (simp add: * preserve_query1_fixY_bound_def)\n        qed\n      next\n        case False\n        show ?thesis\n          apply (simp only: case_prod_beta I1_def J1_def fst_conv snd_conv fields)\n        proof (rule preserve_query1_fixY[where b\\<^sub>i=N and b\\<^sub>j\\<^sub>0=0])\n          show \\<open>{d. old_good (D1'(xL := d)) D2 D3} \\<subseteq> {d. old_good (D1'(xL := d)) D2 D3}\\<close> by simp\n          show \\<open>card (Some -` {d. old_good (D1'(xL := d)) D2 D3}) \\<le> N\\<close>\n            by (simp add: card_mono)\n          show \\<open>card (- Some -` {d. old_good (D1'(xL := d)) D2 D3}) \\<le> 0\\<close>\n            using False \\<open>z\\<in>M\\<close>\n            apply (auto simp: M_def fields old_good_def)\n            by (metis DiffE domI insert_iff)\n          have *: \\<open>\\<not> old_good (D1'(xL := None)) D2 D3\\<close>\n            by (simp add: D1'xL False domIff)\n          show \\<open>preserve_query1_fixY_bound (None \\<in> {d. old_good (D1'(xL := d)) D2 D3}) (None \\<notin> {d. old_good (D1'(xL := d)) D2 D3})\n                     (real N) (real 0) \\<le> co1_old_good\\<close>\n            apply (auto simp add: * preserve_query1_fixY_bound_def co1_old_good_def)\n            by (simp add: inverse_eq_divide sqrt_divide_self_eq)\n        qed\n      qed\n    qed\n  qed\nqed\n\ndefinition \\<open>co1'_old_good = 2 / sqrt N\\<close>\nlemma preserves_co1'_old_good:\n  \\<open>preserves_ket ((X o Fst; (X1 o Fst; D1)) query') old_good_state_00 old_good_state_0 co1'_old_good\\<close>\nproof -\n  define K :: \\<open>(half\\<times>half\\<times>whole\\<times>db\\<times>db\\<times>db) \\<Rightarrow> state ell2 ccsubspace\\<close> \n    where \\<open>K = (\\<lambda>(xL,xR,y,D1',D2,D3).\n          ket_invariant {((xL,xR),(x1L,0),0,y,D1'(xL:=d),D2,D3) | x1L d. True})\\<close>\n  define M :: \\<open>(half\\<times>half\\<times>whole\\<times>db\\<times>db\\<times>db) set\\<close> where\n    \\<open>M = {(xL,xR,y,D1',D2,D3). D1' xL = None \\<and> (\\<exists>d. old_good (D1'(xL:=d)) D2 D3)}\\<close>\n\n  define I1 J1 :: \\<open>(half\\<times>half\\<times>whole\\<times>db\\<times>db\\<times>db) \\<Rightarrow> (half \\<times> half option) set\\<close> \n    where \\<open>I1 = (\\<lambda>(xL,xR,y,D1',D2,D3).\n          {0} \\<times> {d. old_good (D1'(xL:=d)) D2 D3})\\<close>\n      and \\<open>J1 = (\\<lambda>(xL,xR,y,D1',D2,D3). \n          UNIV \\<times> {d. old_good (D1'(xL:=d)) D2 D3})\\<close>\n\n  show ?thesis\n  proof (rule inv_split_reg_query'[where X=\\<open>X o Fst\\<close> and Y=\\<open>X1 o Fst\\<close> and H=\\<open>D1\\<close> and K=K\n        and ?I1.0=\\<open>\\<lambda>z. ket_invariant (I1 z)\\<close> and ?J1.0=\\<open>\\<lambda>z. ket_invariant (J1 z)\\<close>])\n    show \\<open>(X \\<circ> Fst;(X1 \\<circ> Fst;D1)) query' = (X \\<circ> Fst;(X1 \\<circ> Fst;D1)) query'\\<close>\n      by simp\n    show [simp]: \\<open>compatible (X \\<circ> Fst) (X1 \\<circ> Fst)\\<close> \\<open>compatible (X \\<circ> Fst) D1\\<close> \\<open>compatible (X1 \\<circ> Fst) D1\\<close>\n      by simp_all\n    show \\<open>compatible_register_invariant (X1 \\<circ> Fst) (K z)\\<close> for z\n      apply (cases z, hypsubst_thin)\n      by (auto simp add: K_def X1_def comp_assoc\n          intro!: compatible_register_invariant_Snd_comp compatible_register_invariant_Fst compatible_register_invariant_Fst_comp)\n    show \\<open>compatible_register_invariant (D1 \\<circ> function_at (fst z)) (K z)\\<close> for z\n      by (auto simp add: K_def D1_def comp_assoc case_prod_beta\n          intro!: compatible_register_invariant_Snd_comp compatible_register_invariant_Fst compatible_register_invariant_Fst_comp\n          compatible_register_invariant_function_at)\n    show \\<open>ket_invariant old_good_state_00 \\<le> (SUP z\\<in>M. K z \\<sqinter> lift_invariant (X1 \\<circ> Fst;D1 \\<circ> function_at (fst z)) (ket_invariant (I1 z)))\\<close>\n      apply (auto simp add: K_def D1_def lift_Fst_ket_inv ket_invariant_inter ket_invariant_SUP[symmetric] I1_def\n          old_good_state_def x1_x2_00_def case_prod_beta comp_assoc X1_def M_def zero_prod_def\n          lift_inv_prod lift_invariant_comp lift_invariant_function_at_ket_inv lift_Snd_ket_inv)\n      by (metis fun_upd_same fun_upd_triv fun_upd_upd)\n    show \\<open>K z \\<sqinter> lift_invariant (X1 \\<circ> Fst;D1 \\<circ> function_at (fst z)) (ket_invariant (J1 z)) \\<le> ket_invariant old_good_state_0\\<close>\n      if \\<open>z\\<in>M\\<close> for z\n      using that \n      apply (cases z, hypsubst_thin)\n      by (auto simp add: K_def lift_Fst_ket_inv ket_invariant_inter ket_invariant_SUP[symmetric] J1_def\n          case_prod_beta D1_def comp_assoc X1_def old_good_state_def x2_0_def M_def\n          lift_inv_prod lift_invariant_comp lift_invariant_function_at_ket_inv reg_3_3_def lift_Snd_ket_inv)\n    show \\<open>orthogonal_spaces (K z) (K z')\\<close> if \\<open>z\\<in>M\\<close> \\<open>z'\\<in>M\\<close> \\<open>z \\<noteq> z'\\<close> for z z'\n      apply (cases z; cases z')\n      using that apply (auto simp: K_def M_def)\n      by (metis fun_upd_triv fun_upd_upd)\n    show \\<open>K z \\<le> lift_invariant (X \\<circ> Fst) (ket_invariant {fst z})\\<close> for z\n      by (auto simp: K_def X_def lift_Fst_ket_inv lift_invariant_comp case_prod_beta)\n    show [simp]: \\<open>0 \\<le> co1'_old_good\\<close>\n      by (simp add: co1'_old_good_def)\n    show \\<open>preserves_ket query1' (I1 z) (J1 z) co1'_old_good\\<close> if \\<open>z\\<in>M\\<close> for z\n    proof (cases z)\n      case (fields xL xR y D1' D2 D3)\n      from that have D1'xL: \\<open>D1' xL = None\\<close>\n        by (auto simp: M_def fields)\n      show ?thesis\n      proof (cases \\<open>old_good D1' D2 D3\\<close>)\n        case True\n        show ?thesis\n          apply (simp only: case_prod_beta I1_def J1_def fst_conv snd_conv fields)\n        proof (rule preserve_query1'_fixY[where b\\<^sub>i=N and b\\<^sub>j\\<^sub>0=0])\n          show \\<open>{d. old_good (D1'(xL := d)) D2 D3} \\<subseteq> {d. old_good (D1'(xL := d)) D2 D3}\\<close> by simp\n          show \\<open>card (Some -` {d. old_good (D1'(xL := d)) D2 D3}) \\<le> N\\<close> by (simp add: card_mono)\n          show \\<open>card (- Some -` {d. old_good (D1'(xL := d)) D2 D3}) \\<le> 0\\<close> \n            using True D1'xL apply auto\n            by (simp add: old_good_def)\n          have *: \\<open>old_good (D1'(xL := None)) D2 D3\\<close>\n            by (simp add: D1'xL True domIff)\n          show \\<open>preserve_query1'_fixY_bound\n             (None \\<in> {d. old_good (D1'(xL := d)) D2 D3}) (None \\<notin> {d. old_good (D1'(xL := d)) D2 D3})\n             (real N) (real 0) \\<le> co1'_old_good\\<close>\n            by (simp add: * preserve_query1'_fixY_bound_def)\n        qed\n      next\n        case False\n        show ?thesis\n          apply (simp only: case_prod_beta I1_def J1_def fst_conv snd_conv fields)\n        proof (rule preserve_query1'_fixY[where b\\<^sub>i=N and b\\<^sub>j\\<^sub>0=0])\n          show \\<open>{d. old_good (D1'(xL := d)) D2 D3} \\<subseteq> {d. old_good (D1'(xL := d)) D2 D3}\\<close> by simp\n          show \\<open>card (Some -` {d. old_good (D1'(xL := d)) D2 D3}) \\<le> N\\<close>\n            by (simp add: card_mono)\n          show \\<open>card (- Some -` {d. old_good (D1'(xL := d)) D2 D3}) \\<le> 0\\<close>\n            using False \\<open>z\\<in>M\\<close>\n            apply (auto simp: M_def fields old_good_def)\n            by (metis DiffE domI insert_iff)\n          have *: \\<open>\\<not> old_good (D1'(xL := None)) D2 D3\\<close>\n            by (simp add: D1'xL False domIff)\n          show \\<open>preserve_query1'_fixY_bound (None \\<in> {d. old_good (D1'(xL := d)) D2 D3}) (None \\<notin> {d. old_good (D1'(xL := d)) D2 D3})\n                     (real N) (real 0) \\<le> co1'_old_good\\<close>\n            apply (auto simp add: * preserve_query1'_fixY_bound_def co1'_old_good_def)\n            by (simp add: inverse_eq_divide sqrt_divide_self_eq)\n        qed\n      qed\n    qed\n  qed\nqed\n\n\ndefinition \\<open>UPc1_old_good = co1_old_good\\<close>\nlemma preserves_UPc1_old_good:\n  \\<open>preserves_ket ((X;(X1;D1)) UPc) old_good_state_00 old_good_state_0 UPc1_old_good\\<close>\nproof -\n  note comp_apply[simp del]\n\n  have UPc: \\<open>((X;(X1;D1)) UPc) = \n      (X o Fst; X1 o Snd) cnot o\\<^sub>C\\<^sub>L (X \\<circ> Snd; X1 \\<circ> Fst) cnot o\\<^sub>C\\<^sub>L (X \\<circ> Fst; (X1 \\<circ> Fst; D1)) query\\<close>\n    by (simp add: UPc_def reg_1_3_def reg_2_3_def reg_3_3_def register_pair_Fst register_pair_Snd\n        flip: register_mult comp_assoc register_comp_pair \n        o_apply[where x=cnot and f=\\<open>(X;(X1;D1))\\<close>] o_apply[where x=query and f=\\<open>(X;(X1;D1))\\<close>])\n\n  have \\<open>preserves_ket ((X \\<circ> Fst; (X1 \\<circ> Fst; D1)) query) old_good_state_00 old_good_state_0 co1_old_good\\<close>\n    by (rule preserves_co1_old_good)\n  also have \\<open>preserves_ket ((X \\<circ> Snd; X1 \\<circ> Fst) cnot) old_good_state_0 old_good_state_0 0\\<close>\n    apply (rule preserves_compatible[where U=cnot])\n    by (auto simp add: old_good_state_def x2_0_def X_def X1_def comp_assoc\n        intro!: compatible_register_invariant_pair compatible_register_invariant_Fst_comp\n        compatible_register_invariant_Snd_comp)\n  also have \\<open>preserves_ket ((X \\<circ> Fst; X1 \\<circ> Snd) cnot) old_good_state_0 old_good_state_0 0\\<close>\n    apply (rule preserves_compatible[where U=cnot])\n    by (auto simp add: old_good_state_def x2_0_def X_def X1_def comp_assoc\n        intro!: compatible_register_invariant_pair compatible_register_invariant_Fst_comp\n        compatible_register_invariant_Snd_comp)\n  finally show ?thesis\n    by (auto simp add: UPc1_old_good_def UPc cblinfun_compose_assoc register_norm)\nqed\n\ndefinition \\<open>UPc1'_old_good = co1'_old_good\\<close>\nlemma preserves_UPc1'_old_good:\n  \\<open>preserves_ket ((X;(X1;D1)) UPc') old_good_state_00 old_good_state_0 UPc1'_old_good\\<close>\nproof -\n  note comp_apply[simp del]\n\n  have UPc: \\<open>((X;(X1;D1)) UPc') = \n      (X o Fst; X1 o Snd) cnot o\\<^sub>C\\<^sub>L (X \\<circ> Snd; X1 \\<circ> Fst) cnot o\\<^sub>C\\<^sub>L (X \\<circ> Fst; (X1 \\<circ> Fst; D1)) query'\\<close>\n    by (simp add: UPc'_def reg_1_3_def reg_2_3_def reg_3_3_def register_pair_Fst register_pair_Snd\n        flip: register_mult comp_assoc register_comp_pair \n        o_apply[where x=cnot and f=\\<open>(X;(X1;D1))\\<close>] o_apply[where x=query' and f=\\<open>(X;(X1;D1))\\<close>])\n\n  have \\<open>preserves_ket ((X \\<circ> Fst; (X1 \\<circ> Fst; D1)) query') old_good_state_00 old_good_state_0 co1'_old_good\\<close>\n    by (rule preserves_co1'_old_good)\n  also have \\<open>preserves_ket ((X \\<circ> Snd; X1 \\<circ> Fst) cnot) old_good_state_0 old_good_state_0 0\\<close>\n    apply (rule preserves_compatible[where U=cnot])\n    by (auto simp add: old_good_state_def x2_0_def X_def X1_def comp_assoc\n        intro!: compatible_register_invariant_pair compatible_register_invariant_Fst_comp\n        compatible_register_invariant_Snd_comp)\n  also have \\<open>preserves_ket ((X \\<circ> Fst; X1 \\<circ> Snd) cnot) old_good_state_0 old_good_state_0 0\\<close>\n    apply (rule preserves_compatible[where U=cnot])\n    by (auto simp add: old_good_state_def x2_0_def X_def X1_def comp_assoc\n        intro!: compatible_register_invariant_pair compatible_register_invariant_Fst_comp\n        compatible_register_invariant_Snd_comp)\n  finally show ?thesis\n    by (auto simp add: UPc1'_old_good_def UPc cblinfun_compose_assoc register_norm)\nqed\n\ndefinition num_queries_D1 :: \\<open>nat \\<Rightarrow> state set\\<close> where \\<open>num_queries_D1 q = {(x,x1,x2,y,D1,D2,D3). card (dom D1) \\<le> q}\\<close>\n\n(* TODO: preservation lemma for num_queries_1 *)\n\ndefinition \\<open>co2'_old_good q = 2 * sqrt q / N  +  2 * sqrt q / sqrt N  +  1 / sqrt N\\<close>\nlemma preserves_co2'_old_good:\n  \\<open>preserves_ket ((X1 o Fst; (X2 o Fst; D2)) query') (old_good_state_0 \\<inter> num_queries_D1 q) old_good_state (co2'_old_good q)\\<close>\nproof -\n  define K :: \\<open>(half\\<times>half\\<times>whole\\<times>whole\\<times>db\\<times>db\\<times>db) \\<Rightarrow> state ell2 ccsubspace\\<close> \n    where \\<open>K = (\\<lambda>(x1L,x1R,x,y,D1,D2',D3).\n          ket_invariant {(x,(x1L,x1R),(x2L,0),y,D1,D2'(x1L:=d),D3) | x2L d. True})\\<close>\n  define M :: \\<open>(half\\<times>half\\<times>whole\\<times>whole\\<times>db\\<times>db\\<times>db) set\\<close> where\n    \\<open>M = {(x1L,x1R,x,y,D1,D2',D3). D2' x1L = None \\<and> (\\<exists>d. old_good D1 (D2'(x1L:=d)) D3) \\<and> card (dom D1) \\<le> q}\\<close>\n\n  define I1 J1 :: \\<open>(half\\<times>half\\<times>whole\\<times>whole\\<times>db\\<times>db\\<times>db) \\<Rightarrow> (half \\<times> half option) set\\<close> \n    where \\<open>I1 = (\\<lambda>(x1L,x1R,x,y,D1,D2',D3).\n          {0} \\<times> {d. old_good D1 (D2'(x1L:=d)) D3})\\<close>\n      and \\<open>J1 = (\\<lambda>(x1L,x1R,x,y,D1,D2',D3).\n          UNIV \\<times> {d. old_good D1 (D2'(x1L:=d)) D3})\\<close>\n\n  show ?thesis\n  proof (rule inv_split_reg_query'[where X=\\<open>X1 o Fst\\<close> and Y=\\<open>X2 o Fst\\<close> and H=\\<open>D2\\<close> and K=K\n        and ?I1.0=\\<open>\\<lambda>z. ket_invariant (I1 z)\\<close> and ?J1.0=\\<open>\\<lambda>z. ket_invariant (J1 z)\\<close>])\n    show \\<open>(X1 \\<circ> Fst;(X2 \\<circ> Fst;D2)) query' = (X1 \\<circ> Fst;(X2 \\<circ> Fst;D2)) query'\\<close>\n      by simp\n    show [simp]: \\<open>compatible (X1 \\<circ> Fst) (X2 \\<circ> Fst)\\<close> \\<open>compatible (X1 \\<circ> Fst) D2\\<close> \\<open>compatible (X2 \\<circ> Fst) D2\\<close>\n      by simp_all\n    show \\<open>compatible_register_invariant (X2 \\<circ> Fst) (K z)\\<close> for z\n      apply (cases z, hypsubst_thin)\n      by (auto simp add: K_def X2_def comp_assoc\n          intro!: compatible_register_invariant_Snd_comp compatible_register_invariant_Fst compatible_register_invariant_Fst_comp)\n    show \\<open>compatible_register_invariant (D2 \\<circ> function_at (fst z)) (K z)\\<close> for z\n      by (auto simp add: K_def D2_def comp_assoc case_prod_beta\n          intro!: compatible_register_invariant_Snd_comp compatible_register_invariant_Fst compatible_register_invariant_Fst_comp\n          compatible_register_invariant_function_at)\n    show \\<open>ket_invariant (old_good_state_0 \\<inter> num_queries_D1 q) \\<le> (SUP z\\<in>M. K z \\<sqinter> lift_invariant (X2 \\<circ> Fst;D2 \\<circ> function_at (fst z)) (ket_invariant (I1 z)))\\<close>\n      apply (auto simp add: K_def D2_def lift_Fst_ket_inv ket_invariant_inter ket_invariant_SUP[symmetric] I1_def\n          old_good_state_def x2_0_def case_prod_beta comp_assoc X2_def M_def zero_prod_def num_queries_D1_def\n          lift_inv_prod lift_invariant_comp lift_invariant_function_at_ket_inv lift_Snd_ket_inv)\n      by (metis fun_upd_same fun_upd_triv fun_upd_upd)\n    show \\<open>K z \\<sqinter> lift_invariant (X2 \\<circ> Fst;D2 \\<circ> function_at (fst z)) (ket_invariant (J1 z)) \\<le> ket_invariant old_good_state\\<close>\n      if \\<open>z\\<in>M\\<close> for z\n      using that \n      apply (cases z, hypsubst_thin)\n      by (auto simp add: K_def lift_Fst_ket_inv ket_invariant_inter ket_invariant_SUP[symmetric] J1_def\n          case_prod_beta D2_def comp_assoc X2_def old_good_state_def M_def\n          lift_inv_prod lift_invariant_comp lift_invariant_function_at_ket_inv reg_3_3_def lift_Snd_ket_inv)\n    show \\<open>orthogonal_spaces (K z) (K z')\\<close> if \\<open>z\\<in>M\\<close> \\<open>z'\\<in>M\\<close> \\<open>z \\<noteq> z'\\<close> for z z'\n      apply (cases z; cases z')\n      using that apply (auto simp: K_def M_def)\n      by (metis fun_upd_triv fun_upd_upd)\n    show \\<open>K z \\<le> lift_invariant (X1 \\<circ> Fst) (ket_invariant {fst z})\\<close> for z\n      by (auto simp: K_def X1_def lift_Fst_ket_inv lift_Snd_ket_inv lift_invariant_comp case_prod_beta)\n    show [simp]: \\<open>0 \\<le> co2'_old_good q\\<close>\n      by (simp add: co2'_old_good_def)\n    show \\<open>preserves_ket query1' (I1 z) (J1 z) (co2'_old_good q)\\<close> if \\<open>z\\<in>M\\<close> for z\n    proof (cases z)\n      case (fields x1L x1R x y D1 D2' D3)\n      from that have D2'xL: \\<open>D2' x1L = None\\<close>\n        by (auto simp: M_def fields)\n      show ?thesis\n      proof (cases \\<open>old_good D1 D2' D3\\<close>)\n        case True\n        show ?thesis\n          apply (simp only: case_prod_beta I1_def J1_def fst_conv snd_conv fields)\n        proof (rule preserve_query1'_fixY[where b\\<^sub>i=N and b\\<^sub>j\\<^sub>0=0])\n          show \\<open>{d. old_good D1 (D2'(x1L := d)) D3} \\<subseteq> {d. old_good D1 (D2'(x1L := d)) D3}\\<close> by simp\n          show \\<open>card (Some -` {d. old_good D1 (D2'(x1L := d)) D3}) \\<le> N\\<close> by (simp add: card_mono)\n          show \\<open>card (- Some -` {d. old_good D1 (D2'(x1L := d)) D3}) \\<le> 0\\<close>\n            using True D2'xL apply auto\n            apply (simp add: old_good_def)\n            by meson\n          have *: \\<open>old_good D1 (D2'(x1L := None)) D3\\<close>\n            by (simp add: D2'xL True domIff)\n          show \\<open>preserve_query1'_fixY_bound\n             (None \\<in> {d. old_good D1 (D2'(x1L := d)) D3}) (None \\<notin> {d. old_good D1 (D2'(x1L := d)) D3})\n             (real N) (real 0) \\<le> (co2'_old_good q)\\<close>\n            by (simp add: * preserve_query1'_fixY_bound_def)\n        qed\n      next\n        case False\n        show ?thesis\n          apply (simp only: case_prod_beta I1_def J1_def fst_conv snd_conv fields)\n        proof (rule preserve_query1'_fixY[where b\\<^sub>i=q and b\\<^sub>j\\<^sub>0=N])\n          show \\<open>{d. old_good D1 (D2'(x1L := d)) D3} \\<subseteq> {d. old_good D1 (D2'(x1L := d)) D3}\\<close> by simp\n          have card_D1: \\<open>card (dom D1) \\<le> q\\<close>\n            using \\<open>z\\<in>M\\<close> by (simp add: fields M_def)\n          from False obtain x2L where \\<open>x2L \\<in> dom D3\\<close> and x2L_not_good: \\<open>\\<forall>xL\\<in>dom D1. \\<forall>\\<beta>\\<in>ran D2'. x2L \\<noteq> xL + \\<beta>\\<close>\n            by (auto simp: old_good_def)\n          have d_poss: \\<open>Some -` {d. old_good D1 (D2'(x1L := d)) D3} \\<subseteq> (+) x2L ` dom D1\\<close>\n          proof (rule subsetI, rename_tac d)\n            fix d assume \\<open>d \\<in> Some -` {d. old_good D1 (D2'(x1L := d)) D3}\\<close>\n            then have \\<open>old_good D1 (D2'(x1L \\<mapsto> d)) D3\\<close>\n              by simp\n            with \\<open>x2L \\<in> dom D3\\<close> have \\<open>\\<exists>xL\\<in>dom D1. \\<exists>\\<beta>\\<in>ran (D2'(x1L \\<mapsto> d)). x2L = xL + \\<beta>\\<close>\n              by (simp add: old_good_def)\n            with x2L_not_good have \\<open>\\<exists>xL\\<in>dom D1. x2L = xL + d\\<close>\n              using D2'xL by auto\n            then show \\<open>d \\<in> (+) x2L ` dom D1\\<close>\n              by force\n          qed\n          show \\<open>card (Some -` {d. old_good D1 (D2'(x1L := d)) D3}) \\<le> q\\<close>\n            using _ card_D1 apply (rule order.trans)\n            using d_poss by (simp add: surj_card_le)\n          show \\<open>card (- Some -` {d. old_good D1 (D2'(x1L := d)) D3}) \\<le> N\\<close>\n            by (simp add: card_mono)\n          have *: \\<open>\\<not> old_good D1 (D2'(x1L := None)) D3\\<close>\n            by (simp add: D2'xL False domIff)\n          show \\<open>preserve_query1'_fixY_bound (None \\<in> {d. old_good D1 (D2'(x1L := d)) D3}) (None \\<notin> {d. old_good D1 (D2'(x1L := d)) D3})\n                     (real q) (real N) \\<le> co2'_old_good q\\<close>\n            apply (auto simp add: * preserve_query1'_fixY_bound_def co2'_old_good_def)\n            by (metis ab_semigroup_mult_class.mult_ac(1) dual_order.refl of_nat_0_le_iff real_divide_square_eq sqrt_sqrt times_divide_eq_right)\n        qed\n      qed\n    qed\n  qed\nqed\n\n\ndefinition \\<open>UPc2'_old_good q = co2'_old_good q\\<close>\nlemma preserves_UPc2'_old_good:\n  \\<open>preserves_ket ((X1;(X2;D2)) UPc') (old_good_state_0 \\<inter> num_queries_D1 q) old_good_state (UPc2'_old_good q)\\<close>\nproof -\n  note comp_apply[simp del]\n\n  have UPc: \\<open>((X1;(X2;D2)) UPc') = \n      (X1 o Fst; X2 o Snd) cnot o\\<^sub>C\\<^sub>L (X1 \\<circ> Snd; X2 \\<circ> Fst) cnot o\\<^sub>C\\<^sub>L (X1 \\<circ> Fst; (X2 \\<circ> Fst; D2)) query'\\<close>\n    by (simp add: UPc'_def reg_1_3_def reg_2_3_def reg_3_3_def register_pair_Fst register_pair_Snd\n        flip: register_mult comp_assoc register_comp_pair \n        o_apply[where x=cnot and f=\\<open>(X1;(X2;D2))\\<close>] o_apply[where x=query' and f=\\<open>(X1;(X2;D2))\\<close>])\n\n  have \\<open>preserves_ket ((X1 \\<circ> Fst; (X2 \\<circ> Fst; D2)) query') (old_good_state_0 \\<inter> num_queries_D1 q) old_good_state (co2'_old_good q)\\<close>\n    by (rule preserves_co2'_old_good)\n  also have \\<open>preserves_ket ((X1 \\<circ> Snd; X2 \\<circ> Fst) cnot) old_good_state old_good_state 0\\<close>\n    apply (rule preserves_compatible[where U=cnot])\n    by (auto simp add: old_good_state_def X1_def X2_def comp_assoc\n        intro!: compatible_register_invariant_pair compatible_register_invariant_Fst_comp\n        compatible_register_invariant_Snd_comp)\n  also have \\<open>preserves_ket ((X1 \\<circ> Fst; X2 \\<circ> Snd) cnot) old_good_state old_good_state 0\\<close>\n    apply (rule preserves_compatible[where U=cnot])\n    by (auto simp add: old_good_state_def X1_def X2_def comp_assoc\n        intro!: compatible_register_invariant_pair compatible_register_invariant_Fst_comp\n        compatible_register_invariant_Snd_comp)\n  finally show ?thesis\n    by (auto simp add: UPc2'_old_good_def UPc cblinfun_compose_assoc register_norm)\nqed\n\n\ndefinition xx2_LR2 :: \\<open>state set\\<close> where \\<open>xx2_LR2 = {(x,x1,x2,y,D1,D2,D3). LR2 D1 D2 x = Some x2}\\<close>\n\ndefinition \\<open>co3'_old_good = 3 / sqrt N\\<close>\nlemma preserves_co3'_old_good:\n  \\<open>preserves_ket ((X2 o Fst; (Y o Fst; D3)) query') (old_good_state \\<inter> xx2_LR2) old_good_state co3'_old_good\\<close>\nproof -\n  define K :: \\<open>(half\\<times>half\\<times>half\\<times>whole\\<times>whole\\<times>db\\<times>db\\<times>db) \\<Rightarrow> state ell2 ccsubspace\\<close> \n    where \\<open>K = (\\<lambda>(x2L,x2R,yR,x1,x,D1,D2,D3').\n          ket_invariant {(x,x1,(x2L,x2R),(yL,yR),D1,D2,D3'(x2L:=d)) | yL d. True})\\<close>\n  define M :: \\<open>(half\\<times>half\\<times>half\\<times>whole\\<times>whole\\<times>db\\<times>db\\<times>db) set\\<close> where\n    \\<open>M = {(x2L,x2R,yR,x1,x,D1,D2,D3'). D3' x2L = None \\<and> (\\<exists>d. old_good D1 D2 (D3'(x2L:=d))) \\<and> LR2 D1 D2 x = Some (x2L,x2R)}\\<close>\n\n  define I1 J1 :: \\<open>(half\\<times>half\\<times>half\\<times>whole\\<times>whole\\<times>db\\<times>db\\<times>db) \\<Rightarrow> (half \\<times> half option) set\\<close> \n    where \\<open>I1 = (\\<lambda>(x2L,x2R,yR,x1,x,D1,D2,D3').\n          UNIV \\<times> {d. old_good D1 D2 (D3'(x2L:=d))})\\<close>\n      and \\<open>J1 = (\\<lambda>(x2L,x2R,yR,x1,x,D1,D2,D3').\n          UNIV \\<times> {d. old_good D1 D2 (D3'(x2L:=d))})\\<close>\n\n  show ?thesis\n  proof (rule inv_split_reg_query'[where X=\\<open>X2 o Fst\\<close> and Y=\\<open>Y o Fst\\<close> and H=\\<open>D3\\<close> and K=K\n        and ?I1.0=\\<open>\\<lambda>z. ket_invariant (I1 z)\\<close> and ?J1.0=\\<open>\\<lambda>z. ket_invariant (J1 z)\\<close>])\n    show \\<open>(X2 \\<circ> Fst;(Y \\<circ> Fst;D3)) query' = (X2 \\<circ> Fst;(Y \\<circ> Fst;D3)) query'\\<close>\n      by simp\n    show [simp]: \\<open>compatible (X2 \\<circ> Fst) (Y \\<circ> Fst)\\<close> \\<open>compatible (X2 \\<circ> Fst) D3\\<close> \\<open>compatible (Y \\<circ> Fst) D3\\<close>\n      by simp_all\n    show \\<open>compatible_register_invariant (Y \\<circ> Fst) (K z)\\<close> for z\n      apply (cases z, hypsubst_thin)\n      by (auto simp add: K_def Y_def comp_assoc\n          intro!: compatible_register_invariant_Snd_comp compatible_register_invariant_Fst compatible_register_invariant_Fst_comp)\n    show \\<open>compatible_register_invariant (D3 \\<circ> function_at (fst z)) (K z)\\<close> for z\n      by (auto simp add: K_def D3_def comp_assoc case_prod_beta\n          intro!: compatible_register_invariant_Snd_comp compatible_register_invariant_Fst compatible_register_invariant_Fst_comp\n          compatible_register_invariant_function_at)\n    show \\<open>ket_invariant (old_good_state \\<inter> xx2_LR2) \\<le> (SUP z\\<in>M. K z \\<sqinter> lift_invariant (Y \\<circ> Fst; D3 \\<circ> function_at (fst z)) (ket_invariant (I1 z)))\\<close>\n      apply (auto simp add: K_def D3_def lift_Fst_ket_inv ket_invariant_inter\n          ket_invariant_SUP[symmetric] I1_def xx2_LR2_def\n          old_good_state_def case_prod_beta comp_assoc Y_def M_def zero_prod_def num_queries_D1_def\n          lift_inv_prod lift_invariant_comp lift_invariant_function_at_ket_inv lift_Snd_ket_inv)\n      by (metis fun_upd_same fun_upd_triv fun_upd_upd)\n    show \\<open>K z \\<sqinter> lift_invariant (Y \\<circ> Fst; D3 \\<circ> function_at (fst z)) (ket_invariant (J1 z)) \\<le> ket_invariant old_good_state\\<close>\n      if \\<open>z\\<in>M\\<close> for z\n      using that \n      apply (cases z, hypsubst_thin)\n      by (auto simp add: K_def lift_Fst_ket_inv ket_invariant_inter ket_invariant_SUP[symmetric] J1_def\n          case_prod_beta D3_def comp_assoc Y_def old_good_state_def M_def\n          lift_inv_prod lift_invariant_comp lift_invariant_function_at_ket_inv reg_3_3_def lift_Snd_ket_inv)\n    show \\<open>orthogonal_spaces (K z) (K z')\\<close> if \\<open>z\\<in>M\\<close> \\<open>z'\\<in>M\\<close> \\<open>z \\<noteq> z'\\<close> for z z'\n      apply (cases z; cases z')\n      using that apply (auto simp: K_def M_def)\n      by (metis fun_upd_triv fun_upd_upd)\n    show \\<open>K z \\<le> lift_invariant (X2 \\<circ> Fst) (ket_invariant {fst z})\\<close> for z\n      by (auto simp: K_def X2_def lift_Fst_ket_inv lift_Snd_ket_inv lift_invariant_comp case_prod_beta)\n    show [simp]: \\<open>0 \\<le> co3'_old_good\\<close>\n      by (simp add: co3'_old_good_def)\n    show \\<open>preserves_ket query1' (I1 z) (J1 z) co3'_old_good\\<close> if \\<open>z\\<in>M\\<close> for z\n    proof (cases z)\n      case (fields x2L x2R yR x1 x D1 D2D3')\n      obtain D2 D3' where D2D3'[simp]: \\<open>D2D3' = (D2,D3')\\<close>\n        apply atomize_elim by auto\n      from that have D3'xL: \\<open>D3' x2L = None\\<close>\n        by (auto simp: M_def fields)\n      from that have \\<open>\\<exists>d. old_good D1 D2 (D3'(x2L:=d))\\<close>\n        by (auto simp: M_def fields)\n      then have D3'_good: \\<open>old_good D1 D2 D3'\\<close>\n        by (smt (verit) D3'xL domIff fun_upd_apply old_good_def)\n      then have None_I1: \\<open>None \\<in> snd ` I1 z\\<close> (* TODO used? *)\n        apply (auto simp: M_def fields I1_def D3'xL)\n        by (simp add: D3'xL fun_upd_idem)\n      from that have \\<open>LR2 D1 D2 x = Some (x2L,x2R)\\<close>\n        by (auto simp: M_def fields)\n      then have good_x2L: \\<open>\\<exists>xL xR. LR2 D1 D2 (xL, xR) \\<bind> (\\<lambda>(x2L', x2R). Some (x2L = x2L')) = Some True\\<close>\n        apply (rule_tac x=\\<open>fst x\\<close> in exI, rule_tac x=\\<open>snd x\\<close> in exI) by simp\n      with D3'_good have D3'x2L_good: \\<open>old_good D1 D2 (D3'(x2L:=d))\\<close> for d\n        unfolding old_good_alt_def by auto\n\n      show ?thesis\n        apply (simp only: case_prod_beta I1_def J1_def fst_conv snd_conv fields D2D3')\n      proof (rule preserve_query1'[where b\\<^sub>i=N and b\\<^sub>j\\<^sub>0=0])\n        show \\<open>{d. old_good D1 D2 (D3'(x2L := d))} \\<subseteq> {d. old_good D1 D2 (D3'(x2L := d))}\\<close> by simp\n        show \\<open>card (Some -` {d. old_good D1 D2 (D3'(x2L := d))}) \\<le> N\\<close> by (simp add: card_mono)\n        show \\<open>card (- Some -` {d. old_good D1 D2 (D3'(x2L := d))}) \\<le> 0\\<close>\n          using D3'x2L_good by auto\n        show \\<open>preserve_query1'_bound\n             (None \\<in> {d. old_good D1 D2 (D3'(x2L := d))})\n             (real N) (real 0) \\<le> co3'_old_good\\<close>\n          by (simp add: preserve_query1'_bound_def)\n        show \\<open>None \\<in> {d. old_good D1 D2 (D3'(x2L := d))}\\<close>\n          using D3'_good by (auto simp: M_def fields I1_def D3'xL fun_upd_idem)\n      qed\n    qed\n  qed\nqed\n\n\ndefinition \\<open>UPc3'_old_good = co3'_old_good\\<close>\nlemma preserves_UPc3'_old_good:\n  \\<open>preserves_ket ((X2;(Y;D3)) UPc') (old_good_state \\<inter> xx2_LR2) old_good_state UPc3'_old_good\\<close>\nproof -\n  note comp_apply[simp del]\n\n  have UPc: \\<open>((X2;(Y;D3)) UPc') = \n      (X2 o Fst; Y o Snd) cnot o\\<^sub>C\\<^sub>L (X2 \\<circ> Snd; Y \\<circ> Fst) cnot o\\<^sub>C\\<^sub>L (X2 \\<circ> Fst; (Y \\<circ> Fst; D3)) query'\\<close>\n    by (simp add: UPc'_def reg_1_3_def reg_2_3_def reg_3_3_def register_pair_Fst register_pair_Snd\n        flip: register_mult comp_assoc register_comp_pair \n        o_apply[where x=cnot and f=\\<open>(X2;(Y;D3))\\<close>] o_apply[where x=query' and f=\\<open>(X2;(Y;D3))\\<close>])\n\n  have \\<open>preserves_ket ((X2 \\<circ> Fst; (Y \\<circ> Fst; D3)) query') (old_good_state \\<inter> xx2_LR2) old_good_state co3'_old_good\\<close>\n    by (rule preserves_co3'_old_good)\n  also have \\<open>preserves_ket ((X2 \\<circ> Snd; Y \\<circ> Fst) cnot) old_good_state old_good_state 0\\<close>\n    apply (rule preserves_compatible[where U=cnot])\n    by (auto simp add: old_good_state_def X2_def Y_def comp_assoc\n        intro!: compatible_register_invariant_pair compatible_register_invariant_Fst_comp\n        compatible_register_invariant_Snd_comp)\n  also have \\<open>preserves_ket ((X2 \\<circ> Fst; Y \\<circ> Snd) cnot) old_good_state old_good_state 0\\<close>\n    apply (rule preserves_compatible[where U=cnot])\n    by (auto simp add: old_good_state_def X2_def Y_def comp_assoc\n        intro!: compatible_register_invariant_pair compatible_register_invariant_Fst_comp\n        compatible_register_invariant_Snd_comp)\n  finally show ?thesis\n    by (auto simp add: UPc3'_old_good_def UPc cblinfun_compose_assoc register_norm)\nqed\n\ndefinition x1_out_x2_0 :: \\<open>state set\\<close> where \\<open>x1_out_x2_0 = {((xL,xR), (the (D1 xL) + xR, xL), 0,y,D1,D2,D3)| xL xR y D1 D2 D3. D1 xL \\<noteq> None}\\<close>\n\nlemma cnotXSnd_apply: \\<open>((X \\<circ> Snd; X1 \\<circ> Fst) cnot) *\\<^sub>V ket ((xL,xR), (x1L,x1R), x,y,D1,D2,D3) = ket ((xL,xR), (x1L + xR,x1R), x,y,D1,D2,D3)\\<close>\n  for D1 D2 D3\n    apply (auto intro!: cblinfun_image_ket_invariant_leqI\n        simp: preserves0I explicit_pair cnot_apply)\n  apply (simp add: register_pair_apply Fst_def Snd_def X_def X1_def\n      tensor_op_ell2 ket_cinner' tensor_ell2_scaleC2 tensor_ell2_scaleC1\n      flip: tensor_butterfly of_bool_conj tensor_ell2_ket)\n  apply (subst sum_single[where i=\\<open>(xR,x1L)\\<close>])\n  by auto\n\nlemma cnotXFst_apply: \\<open>((X \\<circ> Fst; X1 \\<circ> Snd) cnot) *\\<^sub>V ket ((xL,xR), (x1L,x1R), x,y,D1,D2,D3)\n           = ket ((xL,xR), (x1L,x1R+xL), x,y,D1,D2,D3)\\<close>\n  for D1 D2 D3\n    apply (auto intro!: cblinfun_image_ket_invariant_leqI\n        simp: preserves0I explicit_pair cnot_apply)\n  apply (simp add: register_pair_apply Fst_def Snd_def X_def X1_def\n      tensor_op_ell2 ket_cinner' tensor_ell2_scaleC2 tensor_ell2_scaleC1\n      flip: tensor_butterfly of_bool_conj tensor_ell2_ket)\n  apply (subst sum_single[where i=\\<open>(xL,x1R)\\<close>])\n  by auto\n\nlemma cnotX1Snd_apply: \\<open>((X1 \\<circ> Snd; X2 \\<circ> Fst) cnot) *\\<^sub>V ket (x, (x1L,x1R), (x2L,x2R), y,D1,D2,D3)\n       = ket (x, (x1L,x1R), (x2L+x1R,x2R) ,y,D1,D2,D3)\\<close>\n  for D1 D2 D3\n    apply (auto intro!: cblinfun_image_ket_invariant_leqI\n        simp: preserves0I explicit_pair cnot_apply)\n  apply (simp add: register_pair_apply Fst_def Snd_def X_def X1_def X2_def\n      tensor_op_ell2 ket_cinner' tensor_ell2_scaleC2 tensor_ell2_scaleC1\n      flip: tensor_butterfly of_bool_conj tensor_ell2_ket)\n  apply (subst sum_single[where i=\\<open>(x1R,x2L)\\<close>])\n  by auto\n\nlemma cnotX1Fst_apply: \\<open>((X1 \\<circ> Fst; X2 \\<circ> Snd) cnot) *\\<^sub>V ket (x, (x1L,x1R), (x2L,x2R), y,D1,D2,D3)\n           = ket (x, (x1L,x1R), (x2L,x2R+x1L) ,y,D1,D2,D3)\\<close>\n  for D1 D2 D3\n    apply (auto intro!: cblinfun_image_ket_invariant_leqI\n        simp: preserves0I explicit_pair cnot_apply)\n  apply (simp add: register_pair_apply Fst_def Snd_def X_def X1_def X2_def\n      tensor_op_ell2 ket_cinner' tensor_ell2_scaleC2 tensor_ell2_scaleC1\n      flip: tensor_butterfly of_bool_conj tensor_ell2_ket)\n  apply (subst sum_single[where i=\\<open>(x1L,x2R)\\<close>])\n  by auto\n\ndefinition UPc1'_output where \\<open>UPc1'_output = 6 / sqrt N\\<close>\nlemma preserves_UPc1'_output: \\<open>preserves_ket ((X;(X1;D1)) UPc') x1_x2_00 x1_out_x2_0 UPc1'_output\\<close>\nproof -\n  have UPc: \\<open>((X;(X1;D1)) UPc') = \n      (X o Fst; X1 o Snd) cnot o\\<^sub>C\\<^sub>L (X \\<circ> Snd; X1 \\<circ> Fst) cnot o\\<^sub>C\\<^sub>L (X \\<circ> Fst; (X1 \\<circ> Fst; D1)) query'\\<close>\n    by (simp add: UPc'_def reg_1_3_def reg_2_3_def reg_3_3_def register_pair_Fst register_pair_Snd\n        flip: register_mult comp_assoc register_comp_pair \n        o_apply[where x=cnot and f=\\<open>(X;(X1;D1))\\<close>] o_apply[where x=query' and f=\\<open>(X;(X1;D1))\\<close>])\n\n  have \\<open>preserves_ket ((X o Fst; (X1 o Fst; D1)) query') x1_x2_00 {((xL,xR), (the (D1 xL), 0), 0,y,D1,D2,D3)| xL xR y D1 D2 D3. D1 xL \\<noteq> None} UPc1'_output\\<close>\n  proof -\n    define K :: \\<open>(half\\<times>half\\<times>whole\\<times>db\\<times>db\\<times>db) \\<Rightarrow> state ell2 ccsubspace\\<close> \n      where \\<open>K = (\\<lambda>(xL,xR,y,D1',D2,D3).\n          ket_invariant {((xL,xR),(x1L,0),0,y,D1'(xL:=d),D2,D3) | x1L d. True})\\<close>\n    define M :: \\<open>(half\\<times>half\\<times>whole\\<times>db\\<times>db\\<times>db) set\\<close> where\n      \\<open>M = {(xL,xR,y,D1',D2,D3). D1' xL = None}\\<close>\n\n    show ?thesis\n    proof (rule inv_split_reg_query'[where X=\\<open>X o Fst\\<close> and Y=\\<open>X1 o Fst\\<close> and H=\\<open>D1\\<close> and K=K\n          and ?I1.0=\\<open>\\<lambda>z. ket_invariant ({0} \\<times> UNIV)\\<close> and ?J1.0=\\<open>\\<lambda>z. ket_invariant {(d, Some d)| d. True}\\<close>])\n      show \\<open>(X \\<circ> Fst;(X1 \\<circ> Fst;D1)) query' = (X \\<circ> Fst;(X1 \\<circ> Fst;D1)) query'\\<close>\n        by simp\n      show [simp]: \\<open>compatible (X \\<circ> Fst) (X1 \\<circ> Fst)\\<close> \\<open>compatible (X \\<circ> Fst) D1\\<close> \\<open>compatible (X1 \\<circ> Fst) D1\\<close>\n        by simp_all\n      show \\<open>compatible_register_invariant (X1 \\<circ> Fst) (K z)\\<close> for z\n        apply (cases z, hypsubst_thin)\n        by (auto simp add: K_def X1_def comp_assoc\n            intro!: compatible_register_invariant_Snd_comp compatible_register_invariant_Fst compatible_register_invariant_Fst_comp)\n      show \\<open>compatible_register_invariant (D1 \\<circ> function_at (fst z)) (K z)\\<close> for z\n        by (auto simp add: K_def D1_def comp_assoc case_prod_beta\n            intro!: compatible_register_invariant_Snd_comp compatible_register_invariant_Fst compatible_register_invariant_Fst_comp\n            compatible_register_invariant_function_at)\n      show \\<open>ket_invariant x1_x2_00 \\<le> (SUP z\\<in>M. K z \\<sqinter> lift_invariant (X1 \\<circ> Fst; D1 \\<circ> function_at (fst z)) (ket_invariant ({0} \\<times> UNIV)))\\<close>\n        apply (auto simp add: K_def D1_def lift_Fst_ket_inv ket_invariant_inter\n            ket_invariant_SUP[symmetric] x1_x2_00_def X1_def\n            old_good_state_def case_prod_beta comp_assoc Y_def M_def zero_prod_def num_queries_D1_def\n            lift_inv_prod lift_invariant_comp lift_invariant_function_at_ket_inv lift_Snd_ket_inv)\n        by (metis fun_upd_same fun_upd_triv fun_upd_upd)\n      show \\<open>K z \\<sqinter> lift_invariant (X1 \\<circ> Fst; D1 \\<circ> function_at (fst z)) (ket_invariant {(d, Some d) |d. True})\n         \\<le> ket_invariant {((xL, xR), (the (D1 xL), 0), 0, y, D1, D2, D3) |xL xR y D1 D2 D3. D1 xL \\<noteq> None}\\<close>\n        if \\<open>z\\<in>M\\<close> for z\n        using that \n        apply (cases z, hypsubst_thin)\n        by (auto simp add: K_def lift_Fst_ket_inv ket_invariant_inter ket_invariant_SUP[symmetric]\n            case_prod_beta D3_def comp_assoc Y_def old_good_state_def M_def X1_def D1_def\n            lift_inv_prod' lift_invariant_comp lift_invariant_function_at_ket_inv reg_3_3_def lift_Snd_ket_inv)\n      show \\<open>orthogonal_spaces (K z) (K z')\\<close> if \\<open>z\\<in>M\\<close> \\<open>z'\\<in>M\\<close> \\<open>z \\<noteq> z'\\<close> for z z'\n        apply (cases z; cases z')\n        using that apply (auto simp: K_def M_def)\n        by (metis fun_upd_triv fun_upd_upd)\n      show \\<open>K z \\<le> lift_invariant (X \\<circ> Fst) (ket_invariant {fst z})\\<close> for z\n        by (auto simp: K_def X_def lift_Fst_ket_inv lift_Snd_ket_inv lift_invariant_comp case_prod_beta)\n      show \\<open>0 \\<le> UPc1'_output\\<close>\n        by (simp add: UPc1'_output_def)\n      show \\<open>preserves_ket query1'({0} \\<times> UNIV) {(d, Some d) |d. True} UPc1'_output\\<close> if \\<open>z\\<in>M\\<close> for z\n        apply (subst asm_rl[of \\<open>{(d, Some d) |d. True} = {(0+d, Some d) |d. True}\\<close>], simp)\n        apply (rule preserve_query1'_fixY_output[where b\\<^sub>i=N])\n         apply (auto simp: preserve_query1'_fixY_bound_output_def UPc1'_output_def)\n        by (metis (no_types, opaque_lifting) add_One_commute add_divide_distrib divide_inverse dual_order.refl numeral_plus_numeral of_nat_0_le_iff semiring_norm(3) semiring_norm(6) sqrt_divide_self_eq times_divide_eq_right)\n    qed\n  qed\n  also have \\<open>preserves_ket ((X \\<circ> Snd; X1 \\<circ> Fst) cnot)\n       {((xL,xR), (the (D1 xL), 0), 0,y,D1,D2,D3)| xL xR y D1 D2 D3. D1 xL \\<noteq> None}\n       {((xL,xR), (the (D1 xL) + xR, 0), 0,y,D1,D2,D3)| xL xR y D1 D2 D3. D1 xL \\<noteq> None}\n       0\\<close>\n    by (auto intro!: cblinfun_image_ket_invariant_leqI ket_in_ket_invariantI\n        simp: preserves0I cnotXSnd_apply ket_in_ket_invariantI)\n  also have \\<open>preserves_ket ((X \\<circ> Fst; X1 \\<circ> Snd) cnot)\n       {((xL,xR), (the (D1 xL) + xR, 0), 0,y,D1,D2,D3)| xL xR y D1 D2 D3. D1 xL \\<noteq> None}\n       x1_out_x2_0\n       0\\<close>\n    by (auto intro!: cblinfun_image_ket_invariant_leqI ket_in_ket_invariantI\n        simp: preserves0I cnotXFst_apply ket_in_ket_invariantI x1_out_x2_0_def)\n  finally show ?thesis\n    by (auto simp add: UPc1_old_good_def UPc cblinfun_compose_assoc register_norm)\nqed\n\ndefinition UPc2'_output where \\<open>UPc2'_output = 6 / sqrt N\\<close>\nlemma preserves_UPc2'_output: \\<open>preserves_ket ((X1;(X2;D2)) UPc') x1_out_x2_0 xx2_LR2 UPc2'_output\\<close>\nproof -\n  have UPc: \\<open>((X1;(X2;D2)) UPc') = \n      (X1 o Fst; X2 o Snd) cnot o\\<^sub>C\\<^sub>L (X1 \\<circ> Snd; X2 \\<circ> Fst) cnot o\\<^sub>C\\<^sub>L (X1 \\<circ> Fst; (X2 \\<circ> Fst; D2)) query'\\<close>\n    by (simp add: UPc'_def reg_1_3_def reg_2_3_def reg_3_3_def register_pair_Fst register_pair_Snd\n        flip: register_mult comp_assoc register_comp_pair \n        o_apply[where x=cnot and f=\\<open>(X1;(X2;D2))\\<close>] o_apply[where x=query' and f=\\<open>(X1;(X2;D2))\\<close>])\n\n  have \\<open>preserves_ket ((X1 o Fst; (X2 o Fst; D2)) query') x1_out_x2_0\n        {((xL,xR), (the (D1 xL) + xR, xL), (the (D2 (the (D1 xL) + xR)), 0), y,D1,D2,D3)| xL xR y D1 D2 D3. D1 xL \\<noteq> None \\<and> D2 (the (D1 xL) + xR) \\<noteq> None}\n        UPc2'_output\\<close>\n  proof -\n    define K :: \\<open>(half\\<times>half\\<times>half\\<times>whole\\<times>db\\<times>db\\<times>db) \\<Rightarrow> state ell2 ccsubspace\\<close> \n      where \\<open>K = (\\<lambda>(x1L,xL,xR,y,D1,D2',D3).\n          ket_invariant {((xL,xR), (x1L, xL), (x2L,0), y,D1,D2'(x1L:=d),D3) | x2L d. D1 xL \\<noteq> None})\\<close>\n    define M :: \\<open>(half\\<times>half\\<times>half\\<times>whole\\<times>db\\<times>db\\<times>db) set\\<close> where\n      \\<open>M = {(x1L,xL,xR,y,D1,D2',D3). D1 xL \\<noteq> None \\<and> D2' x1L = None \\<and> x1L = the (D1 xL) + xR}\\<close>\n\n    show ?thesis\n    proof (rule inv_split_reg_query'[where X=\\<open>X1 o Fst\\<close> and Y=\\<open>X2 o Fst\\<close> and H=\\<open>D2\\<close> and K=K\n          and ?I1.0=\\<open>\\<lambda>z. ket_invariant ({0} \\<times> UNIV)\\<close> and ?J1.0=\\<open>\\<lambda>z. ket_invariant {(d, Some d)| d. True}\\<close>])\n      show \\<open>(X1 \\<circ> Fst;(X2 \\<circ> Fst;D2)) query' = (X1 \\<circ> Fst;(X2 \\<circ> Fst;D2)) query'\\<close>\n        by simp\n      show [simp]: \\<open>compatible (X1 \\<circ> Fst) (X2 \\<circ> Fst)\\<close> \\<open>compatible (X1 \\<circ> Fst) D2\\<close> \\<open>compatible (X2 \\<circ> Fst) D2\\<close>\n        by simp_all\n      show \\<open>compatible_register_invariant (X2 \\<circ> Fst) (K z)\\<close> for z\n        apply (cases z, hypsubst_thin)\n        by (auto simp add: K_def X2_def comp_assoc\n            intro!: compatible_register_invariant_Snd_comp compatible_register_invariant_Fst compatible_register_invariant_Fst_comp)\n      show \\<open>compatible_register_invariant (D2 \\<circ> function_at (fst z)) (K z)\\<close> for z\n        by (auto simp add: K_def D2_def comp_assoc case_prod_beta\n            intro!: compatible_register_invariant_Snd_comp compatible_register_invariant_Fst compatible_register_invariant_Fst_comp\n            compatible_register_invariant_function_at)\n      show \\<open>ket_invariant x1_out_x2_0 \\<le> (SUP z\\<in>M. K z \\<sqinter> lift_invariant (X2 \\<circ> Fst; D2 \\<circ> function_at (fst z)) (ket_invariant ({0} \\<times> UNIV)))\\<close>\n        apply (auto simp add: K_def D1_def lift_Fst_ket_inv ket_invariant_inter\n            ket_invariant_SUP[symmetric] x1_out_x2_0_def X1_def X2_def D2_def\n            old_good_state_def case_prod_beta comp_assoc Y_def M_def zero_prod_def num_queries_D1_def\n            lift_inv_prod lift_invariant_comp lift_invariant_function_at_ket_inv lift_Snd_ket_inv)\n        by (metis fun_upd_same fun_upd_triv fun_upd_upd option.sel)\n      show \\<open>K z \\<sqinter> lift_invariant (X2 \\<circ> Fst; D2 \\<circ> function_at (fst z)) (ket_invariant {(d, Some d) |d. True})\n         \\<le> ket_invariant {((xL,xR), (the (D1 xL) + xR, xL), (the (D2 (the (D1 xL) + xR)), 0), y,D1,D2,D3)| xL xR y D1 D2 D3. D1 xL \\<noteq> None \\<and> D2 (the (D1 xL) + xR) \\<noteq> None}\\<close>\n        if \\<open>z\\<in>M\\<close> for z\n        using that \n        apply (cases z, hypsubst_thin)\n        by (auto simp add: K_def lift_Fst_ket_inv ket_invariant_inter ket_invariant_SUP[symmetric]\n            case_prod_beta D3_def comp_assoc Y_def old_good_state_def M_def X1_def D1_def X2_def D2_def\n            lift_inv_prod' lift_invariant_comp lift_invariant_function_at_ket_inv reg_3_3_def lift_Snd_ket_inv)\n      show \\<open>orthogonal_spaces (K z) (K z')\\<close> if \\<open>z\\<in>M\\<close> \\<open>z'\\<in>M\\<close> \\<open>z \\<noteq> z'\\<close> for z z'\n        apply (cases z; cases z')\n        using that apply (auto simp: K_def M_def)\n        by (metis fun_upd_triv fun_upd_upd)\n      show \\<open>K z \\<le> lift_invariant (X1 \\<circ> Fst) (ket_invariant {fst z})\\<close> for z\n        by (auto simp: K_def X_def X1_def lift_Fst_ket_inv lift_Snd_ket_inv lift_invariant_comp case_prod_beta)\n      show \\<open>0 \\<le> UPc2'_output\\<close>\n        by (simp add: UPc2'_output_def)\n      show \\<open>preserves_ket query1' ({0} \\<times> UNIV) {(d, Some d) |d. True} UPc2'_output\\<close> if \\<open>z\\<in>M\\<close> for z\n        apply (subst asm_rl[of \\<open>{(d, Some d) |d. True} = {(0+d, Some d) |d. True}\\<close>], simp)\n        apply (rule preserve_query1'_fixY_output[where b\\<^sub>i=N])\n         apply (auto simp: preserve_query1'_fixY_bound_output_def UPc2'_output_def)\n        by (metis (no_types, opaque_lifting) add_One_commute add_divide_distrib divide_inverse dual_order.refl numeral_plus_numeral of_nat_0_le_iff semiring_norm(3) semiring_norm(6) sqrt_divide_self_eq times_divide_eq_right)\n    qed\n  qed\n  also have \\<open>preserves_ket ((X1 \\<circ> Snd; X2 \\<circ> Fst) cnot)\n       {((xL,xR), (the (D1 xL) + xR, xL), (the (D2 (the (D1 xL) + xR)), 0), y,D1,D2,D3)| xL xR y D1 D2 D3. D1 xL \\<noteq> None \\<and> D2 (the (D1 xL) + xR) \\<noteq> None}\n       {((xL,xR), (the (D1 xL) + xR, xL), (the (D2 (the (D1 xL) + xR)) + xL, 0), y,D1,D2,D3)| xL xR y D1 D2 D3. D1 xL \\<noteq> None \\<and> D2 (the (D1 xL) + xR) \\<noteq> None}\n       0\\<close>\n    by (auto intro!: cblinfun_image_ket_invariant_leqI ket_in_ket_invariantI\n        simp: preserves0I cnotX1Snd_apply ket_in_ket_invariantI)\n  also have \\<open>preserves_ket ((X1 \\<circ> Fst; X2 \\<circ> Snd) cnot)\n       {((xL,xR), (the (D1 xL) + xR, xL), (the (D2 (the (D1 xL) + xR)) + xL, 0), y,D1,D2,D3)| xL xR y D1 D2 D3. D1 xL \\<noteq> None \\<and> D2 (the (D1 xL) + xR) \\<noteq> None}\n       xx2_LR2\n       0\\<close>\n    by (auto intro!: cblinfun_image_ket_invariant_leqI ket_in_ket_invariantI\n        simp: preserves0I cnotX1Fst_apply ket_in_ket_invariantI xx2_LR2_def LR2_def add.commute)\n  finally show ?thesis\n    by (auto simp add: UPc1_old_good_def UPc cblinfun_compose_assoc register_norm)\nqed\n\nlemma x1_out_x2_0_subset_x2_0: \\<open>x1_out_x2_0 \\<subseteq> x2_0\\<close>\n  by (smt (z3) Collect_mono_iff x1_out_x2_0_def x2_0_def)\n\nend\n\n(* What we have so far:\n\nUPc1': old_good_state \\<inter> x1_x2_00 \\<longrightarrow> old_good_state \\<inter> x2_0 (* Do we need the x2_0 part here? *)\n       x1_x2_00 \\<longrightarrow> x1_out_x2_0\n       x1_out_x2_0 \\<subseteq> x2_0\nUPc2': old_good_state \\<inter> x2_0 \\<inter> num_queries_1 q \\<longrightarrow> old_good_state\n       x1_out_x2_0 \\<longrightarrow> xx2_LR2\nUPc3': old_good_state \\<inter> xx1_LR3 \\<longrightarrow> old_good_state\n\nPlugging this together with other stuff:\nUPc1';UPc2': old_good_state_00 \\<inter> num_queries_1 q \\<inter> num_queries_2 q \n        \\<longrightarrow>  old_good_state_00 \\<inter> num_queries_1 (q+1) \\<inter> num_queries_2 (q+1)\n             \\<inter> x1,x2 have the right stuff given x,D1,D2\n\n*)\n", "meta": {"author": "dominique-unruh", "repo": "luby-rackoff-formalization", "sha": "9b4e48a1fe50baac4c93fc4ae4e9dbbaf68b0b2c", "save_path": "github-repos/isabelle/dominique-unruh-luby-rackoff-formalization", "path": "github-repos/isabelle/dominique-unruh-luby-rackoff-formalization/luby-rackoff-formalization-9b4e48a1fe50baac4c93fc4ae4e9dbbaf68b0b2c/LR3_Compressed.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331462646255, "lm_q2_score": 0.4726834766204329, "lm_q1q2_score": 0.28192409314802636}}
{"text": "(*<*)\ntheory Uv_Proofs\nimports Heard_Of.Reduction\n  Two_Step_Observing \"../HO_Transition_System\" Uv_Defs\nbegin\n(*>*)\n\nsubsection \\<open>Proofs\\<close>\ntype_synonym uv_TS_state = \"(nat \\<times> (process \\<Rightarrow> (val pstate)))\"\n\naxiomatization where val_linorder: \n  \"OFCLASS(val, linorder_class)\"\n\ninstance val :: linorder by (rule val_linorder)\n\nlemma two_step_step:\n   \"step = two_step\"\n   \"phase = two_phase\"\n   by(auto simp add: step_def two_step_def phase_def two_phase_def)\n\ncontext mono_quorum\nbegin\n\ndefinition UV_Alg :: \"(process, val pstate, val msg)CHOAlgorithm\" where\n  \"UV_Alg = CHOAlgorithm.truncate UV_M\"\n\ndefinition UV_TS ::\n  \"(round \\<Rightarrow> process HO) \\<Rightarrow> (round \\<Rightarrow> process HO) \\<Rightarrow> (round \\<Rightarrow> process) \\<Rightarrow> uv_TS_state TS\"\nwhere\n  \"UV_TS HOs SHOs crds = CHO_to_TS UV_Alg HOs SHOs (K o crds)\"\n\nlemmas UV_TS_defs = UV_TS_def CHO_to_TS_def UV_Alg_def CHOinitConfig_def\n  UV_initState_def\n\ntype_synonym rHO = \"nat \\<Rightarrow> process HO\"\n\ndefinition UV_trans_step \n  where\n  \"UV_trans_step HOs SHOs nxt_f snd_f stp \\<equiv> \\<Union>r \\<mu>.\n    {((r, cfg), (Suc r, cfg'))|cfg cfg'. step r = stp  \\<and> (\\<forall>p.\n      \\<mu> p \\<in> get_msgs (snd_f r) cfg (HOs r) (SHOs r) p\n      \\<and> nxt_f r p (cfg p) (\\<mu> p) (cfg' p)\n    )}\"\n\nlemma step_less_D:\n  \"0 < step r \\<Longrightarrow> step r = Suc 0\"\n  by(auto simp add: step_def)\n\nlemma UV_trans:\n  \"CSHO_trans_alt UV_sendMsg (\\<lambda>r p st msgs crd st'. UV_nextState r p st msgs st') HOs SHOs crds = \n  UV_trans_step HOs SHOs next0 send0 0\n  \\<union> UV_trans_step HOs SHOs  next1 send1 1\n  \"\nproof\n  show \"CSHO_trans_alt UV_sendMsg (\\<lambda>r p st msgs crd. UV_nextState r p st msgs) HOs SHOs crds\n    \\<subseteq> UV_trans_step HOs SHOs next0 send0 0 \\<union> UV_trans_step HOs SHOs next1 send1 1\"\n  by(force simp add: CSHO_trans_alt_def UV_sendMsg_def UV_nextState_def UV_trans_step_def \n    K_def dest!: step_less_D)\nnext\n  show \" UV_trans_step HOs SHOs next0 send0 0 \\<union>\n    UV_trans_step HOs SHOs next1 send1 1\n    \\<subseteq> CSHO_trans_alt UV_sendMsg\n        (\\<lambda>r p st msgs crd. UV_nextState r p st msgs) HOs SHOs crds\"\n  by(force simp add: CSHO_trans_alt_def UV_sendMsg_def UV_nextState_def UV_trans_step_def)\nqed\n\nsubsubsection \\<open>Invariants\\<close>\n(******************************************************************************)\n\ndefinition UV_inv1\n  :: \"uv_TS_state set\" \nwhere  \n  \"UV_inv1  = {(r, s). \n    two_step r = 0 \\<longrightarrow> (\\<forall>p. agreed_vote (s p) = None)\n  }\"\n\nlemmas UV_inv1I = UV_inv1_def [THEN setc_def_to_intro, rule_format]\nlemmas UV_inv1E [elim] = UV_inv1_def [THEN setc_def_to_elim, rule_format]\nlemmas UV_inv1D = UV_inv1_def [THEN setc_def_to_dest, rule_format]\n\nlemma UV_inv1_inductive:\n  \"init (UV_TS HOs SHOs crds) \\<subseteq> UV_inv1\"\n  \"{UV_inv1} TS.trans (UV_TS HOs SHOs crds) {> UV_inv1}\"\n  by(auto simp add: UV_inv1_def UV_TS_defs CHO_trans_alt UV_trans PO_hoare_def \n    UV_HOMachine_def CHOAlgorithm.truncate_def UV_trans_step_def \n    all_conj_distrib two_step_phase_Suc two_step_step next1_def)\n  \nlemma UV_inv1_invariant:\n  \"reach (UV_TS HOs SHOs crds) \\<subseteq> UV_inv1\"\n  by(intro inv_rule_basic UV_inv1_inductive)\n\nsubsubsection \\<open>Refinement\\<close>\n(******************************************************************************)\n\ndefinition ref_rel :: \"(tso_state \\<times> uv_TS_state)set\" where\n  \"ref_rel \\<equiv> {(sa, (r, sc)).\n    r = next_round sa\n    \\<and> (step r = 1 \\<longrightarrow> r_votes sa = agreed_vote o sc)\n    \\<and> (\\<forall>p v. last_obs (sc p) = v \\<longrightarrow> (\\<exists>q. opt_obsv_state.last_obs sa q \\<in> {None, Some v}))\n    \\<and> decisions sa = decide o sc\n  }\"\n\n(******************************************************************************)\ntext \\<open>Agreement for UV only holds if the communication predicates hold\\<close>\ncontext\n  fixes\n    HOs :: \"nat \\<Rightarrow> process \\<Rightarrow> process set\"\n    and rho :: \"nat \\<Rightarrow> process \\<Rightarrow> 'val pstate\"\n  assumes global: \"UV_commGlobal HOs\"\n  and per_rd: \"\\<forall>r. UV_commPerRd (HOs r)\"\n  and run: \"HORun fA rho HOs\"\nbegin\n(******************************************************************************)\n\nlemma HOs_intersect:\n  \"HOs r p \\<inter> HOs r' q \\<noteq> {}\" using per_rd\n  apply(simp add: UV_commPerRd_def)\n  apply(blast dest: qintersect)\n  done\n\nlemma HOs_nonempty:\n  \"HOs r p \\<noteq> {}\" \n  using HOs_intersect\n  by blast\n\nlemma vote_origin:\n  assumes\n  send: \"\\<forall>p. \\<mu> p \\<in> get_msgs (send0 r) cfg (HOs r) (HOs r) p\"\n  and step: \"\\<forall>p. next0 r p (cfg p) (\\<mu> p) (cfg' p)\"\n  and inv: \"(r, cfg) \\<in> UV_inv1\"\n  and step_r: \"two_step r = 0\"\n  shows \n    \"agreed_vote (cfg' p) = Some v \\<longleftrightarrow> (\\<forall>q \\<in> HOs r p. last_obs (cfg q) = v)\" \n  using send[THEN spec, where x=p] step[THEN spec, where x=p] inv step_r HOs_nonempty\n  by(auto simp add: next0_def get_msgs_benign send0_def msgRcvd_def o_def restrict_map_def)\n  \nlemma same_new_vote:\n  assumes \n  send: \"\\<forall>p. \\<mu> p \\<in> get_msgs (send0 r) cfg (HOs r) (HOs r) p\"\n  and step: \"\\<forall>p. next0 r p (cfg p) (\\<mu> p) (cfg' p)\"\n  and inv: \"(r, cfg) \\<in> UV_inv1\"\n  and step_r: \"two_step r = 0\"\n  obtains v where \"\\<forall>p w. agreed_vote (cfg' p) = Some w \\<longrightarrow> w = v\" \nproof(cases \"\\<exists>p v. agreed_vote (cfg' p) = Some v\")\n  case True\n  assume asm: \"\\<And>v. \\<forall>p w. agreed_vote (cfg' p) = Some w \\<longrightarrow> w = v \\<Longrightarrow> thesis\"\n  from True obtain p v where \"agreed_vote (cfg' p) = Some v\" by auto\n\n  hence \"\\<forall>p w. agreed_vote (cfg' p) = Some w \\<longrightarrow> w = v\" (is \"?LV(v)\")\n    using vote_origin[OF send step inv step_r] HOs_intersect\n    by(force)\n\n  from asm[OF this] show ?thesis .\nqed(auto)\n\nlemma x_origin1:\n  assumes\n  send: \"\\<forall>p. \\<mu> p \\<in> get_msgs (send0 r) cfg (HOs r) (HOs r) p\"\n  and step: \"\\<forall>p. next0 r p (cfg p) (\\<mu> p) (cfg' p)\"\n  and step_r: \"two_step r = 0\"\n  and last_obs: \"last_obs (cfg' p) = v\"\n  shows \n    \"\\<exists>q. last_obs (cfg q) = v\" \nproof-\n  have \"smallestValRcvd (\\<mu> p) \\<in> {v. \\<exists>q. \\<mu> p q = Some (Val v)}\" (is \"smallestValRcvd ?msgs \\<in> ?vals\")\n  unfolding smallestValRcvd_def\n  proof(rule Min_in)\n    have \"?vals \\<subseteq> getval ` ((the \\<circ> ?msgs) ` (HOs r p))\"\n      using send[THEN spec, where x=p]\n      by (auto simp: image_def get_msgs_benign restrict_map_def send0_def)\n    thus \"finite ?vals\" by (auto simp: finite_subset)\n  next\n    from send[THEN spec, where x=p]\n    show \"?vals \\<noteq> {}\" using HOs_nonempty[of r p]\n      by (auto simp: image_def get_msgs_benign restrict_map_def send0_def)\n  qed\n  hence \"v \\<in> ?vals\" using last_obs step[THEN spec, of p] \n    by(auto simp add: next0_def all_conj_distrib)\n  thus ?thesis using send[THEN spec, of p]\n    by(auto simp add: get_msgs_benign send0_def restrict_map_def)\nqed\n    \nlemma step0_ref:\n  \"{ref_rel \\<inter> UNIV \\<times> UV_inv1} \\<Union>r S v. tso_round0 r S v, \n    UV_trans_step HOs HOs next0 send0 0 {> ref_rel}\"\nproof(clarsimp simp add: PO_rhoare_defs UV_trans_step_def two_step_step all_conj_distrib)\n  fix sa r cfg \\<mu> cfg'\n  assume\n    R: \"(sa, (r, cfg)) \\<in> ref_rel\"\n    and step_r: \"two_step r = 0\" \n    and send: \"\\<forall>p. \\<mu> p \\<in> get_msgs (send0 r) cfg (HOs r) (HOs r) p\"\n    and step: \"\\<forall>p. next0 r p (cfg p) (\\<mu> p) (cfg' p)\"\n    and inv: \"(r, cfg) \\<in> UV_inv1\"\n\n  from R have next_r: \"next_round sa = r\"\n    by(simp add: ref_rel_def)\n\n  from HOs_nonempty send have \"\\<forall>p. \\<exists>q. q \\<in> msgRcvd (\\<mu> p)\"\n    by(fastforce simp add: get_msgs_benign send0_def msgRcvd_def restrict_map_def)\n  with step have same_dec: \"decide o cfg' = decide o cfg\"\n    apply(simp add: next0_def o_def)\n    by (metis pstate.select_convs(3) pstate.surjective pstate.update_convs(1) pstate.update_convs(2))\n\n  define S where \"S = {p. \\<exists>v. agreed_vote (cfg' p) = Some v}\"\n  from same_new_vote[OF send step inv step_r] \n  obtain v where v: \"\\<forall>p \\<in> S. agreed_vote (cfg' p) = Some v\"\n    by(simp add: S_def) (metis)\n  hence vote_const_map: \"agreed_vote o cfg' = const_map v S\"\n    by(auto simp add: S_def const_map_def restrict_map_def intro!: ext)\n\n  note x_origin = x_origin1[OF send step step_r]\n\n  define sa' where \"sa' = sa\\<lparr> next_round := Suc r, r_votes := const_map v S \\<rparr>\"\n\n  have \"\\<forall>p. p \\<in> S \\<longrightarrow> opt_obs_safe (opt_obsv_state.last_obs sa) v\"\n    using vote_origin[OF send step inv step_r] R per_rd[THEN spec, of r] v\n    apply(clarsimp simp add: UV_commPerRd_def opt_obs_safe_def ref_rel_def)\n    by metis\n    \n  hence \"(sa, sa') \\<in> tso_round0 r S v\" using next_r step_r v R \n    vote_origin[OF send step inv step_r]\n    by(auto simp add: tso_round0_def sa'_def all_conj_distrib)\n\n  moreover have \"(sa', Suc r, cfg') \\<in> ref_rel\" using step send v R same_dec step_r next_r\n    apply(clarsimp simp add: ref_rel_def sa'_def two_step_step two_step_phase_Suc vote_const_map)\n    by (metis x_origin)\n  ultimately show\n    \"\\<exists>sa'. (\\<exists>r S v. (sa, sa') \\<in> tso_round0 r S v) \\<and> (sa', Suc r, cfg') \\<in> ref_rel\"\n    by blast\nqed\n\n\nlemma x_origin2:\n  assumes\n  send: \"\\<forall>p. \\<mu> p \\<in> get_msgs (send1 r) cfg (HOs r) (HOs r) p\"\n  and step: \"\\<forall>p. next1 r p (cfg p) (\\<mu> p) (cfg' p)\"\n  and step_r: \"two_step r = Suc 0\"\n  and last_obs: \"last_obs (cfg' p) = v\"\n  shows \n    \"(\\<exists>q. last_obs (cfg q) = v) \\<or> (\\<exists>q. agreed_vote (cfg q) = Some v)\" \nproof(cases \"\\<forall>q \\<in> HOs r p. \\<exists>w. \\<mu> p q = Some (ValVote w None)\")\n  case True\n  hence empty: \"someVoteRcvd (\\<mu> p) = {}\" using send[THEN spec, of p] HOs_nonempty[of r p]\n    by(auto simp add: someVoteRcvd_def msgRcvd_def isValVote_def \n      get_msgs_benign send1_def restrict_map_def)\n  have \"smallestValNoVoteRcvd (\\<mu> p) \\<in> {v. \\<exists>q. \\<mu> p q = Some (ValVote v None)}\" \n    (is \"smallestValNoVoteRcvd ?msgs \\<in> ?vals\")\n  unfolding smallestValNoVoteRcvd_def\n  proof(rule Min_in)\n    have \"?vals \\<subseteq> getval ` ((the \\<circ> ?msgs) ` (HOs r p))\"\n      using send[THEN spec, where x=p]\n      by (auto simp: image_def get_msgs_benign restrict_map_def send0_def)\n    thus \"finite ?vals\" by (auto simp: finite_subset)\n  next\n    from send[THEN spec, where x=p] True HOs_nonempty[of r p]\n    show \"?vals \\<noteq> {}\" \n      by (auto simp: image_def get_msgs_benign restrict_map_def send1_def)\n  qed\n  hence \"v \\<in> ?vals\" using empty step[THEN spec, of p] last_obs\n    by(auto simp add: next1_def x_update_def)\n  thus ?thesis using send[THEN spec, of p]\n    by(auto simp add: get_msgs_benign restrict_map_def send1_def)\nnext\n  case False\n  hence \"someVoteRcvd (\\<mu> p) \\<noteq> {}\" using send[THEN spec, of p] HOs_nonempty[of r p]\n    by(auto simp add: someVoteRcvd_def msgRcvd_def isValVote_def \n      get_msgs_benign send1_def restrict_map_def)\n  hence \"\\<exists>q \\<in> someVoteRcvd (\\<mu> p). v = the (getvote (the (\\<mu> p q)))\" using step[THEN spec, of p] last_obs\n    by(auto simp add: next1_def x_update_def)\n  thus ?thesis using send[THEN spec, of p]\n    by(auto simp add: next1_def x_update_def someVoteRcvd_def isValVote_def \n      send1_def get_msgs_benign msgRcvd_def restrict_map_def)\nqed\n\ndefinition D where\n  \"D cfg cfg' \\<equiv> {p. decide (cfg' p) \\<noteq> decide (cfg p) }\"\n\nlemma decide_origin:\n  assumes\n  send: \"\\<forall>p. \\<mu> p \\<in> get_msgs (send1 r) cfg (HOs r) (HOs r) p\"\n  and step: \"\\<forall>p. next1 r p (cfg p) (\\<mu> p) (cfg' p)\"\n  and step_r: \"two_step r = Suc 0\"\n  shows \n    \"D cfg cfg' \\<subseteq> {p. \\<exists>v. decide (cfg' p) = Some v \\<and> (\\<forall>q \\<in> HOs r p. agreed_vote (cfg q) = Some v)}\" \n  using assms\n  by(fastforce simp add: D_def next1_def get_msgs_benign send1_def msgRcvd_def o_def restrict_map_def\n    x_update_def dec_update_def identicalVoteRcvd_def all_conj_distrib someVoteRcvd_def isValVote_def\n    smallestValNoVoteRcvd_def)\n  \nlemma step1_ref:\n  \"{ref_rel \\<inter> (TSO_inv1 \\<inter> TSO_inv2) \\<times> UNIV} \\<Union>r d_f o_f. tso_round1 r d_f o_f, \n    UV_trans_step HOs HOs next1 send1 (Suc 0) {> ref_rel}\"\nproof(clarsimp simp add: PO_rhoare_defs UV_trans_step_def two_step_step all_conj_distrib)\n  fix sa r cfg \\<mu> and cfg' :: \"process \\<Rightarrow> val pstate\"\n  assume\n    R: \"(sa, (r, cfg)) \\<in> ref_rel\"\n    and step_r: \"two_step r = Suc 0\" \n    and send: \"\\<forall>p. \\<mu> p \\<in> get_msgs (send1 r) cfg (HOs r) (HOs r) p\"\n    and step: \"\\<forall>p. next1 r p (cfg p) (\\<mu> p) (cfg' p)\"\n    and ainv: \"sa \\<in> TSO_inv1\"\n    and ainv2: \"sa \\<in> TSO_inv2\"\n\n  from R have next_r: \"next_round sa = r\"\n    by(simp add: ref_rel_def)\n\n  define S where \"S = {p. \\<exists>v. agreed_vote (cfg p) = Some v}\"\n  from R obtain v where v: \"\\<forall>p \\<in> S. agreed_vote (cfg p) = Some v\" using ainv step_r\n    by(auto simp add: ref_rel_def TSO_inv1_def S_def two_step_step)\n\n  define Ob where \"Ob = {p. last_obs (cfg' p) = v}\"\n  define o_f where \"o_f p = (if S \\<in> Quorum then Some v else None)\" for p :: process\n\n  define dec_f where \"dec_f p = (if p \\<in> D cfg cfg' then decide (cfg' p) else None)\" for p\n\n  {\n    fix p w\n    assume \"agreed_vote (cfg p) = Some w\"\n    hence \"w = v\" using v\n      by(unfold S_def, auto)\n  } note v'=this\n    \n  have d_guard: \"d_guard dec_f (agreed_vote \\<circ> cfg)\" using per_rd[THEN spec, of r]\n    by(fastforce simp add: d_guard_def locked_in_vf_def quorum_for_def dec_f_def\n      UV_commPerRd_def dest!: decide_origin[OF send step step_r, THEN subsetD])\n\n  have \"dom (agreed_vote \\<circ> cfg) \\<in> Quorum \\<longrightarrow> Ob = UNIV\"\n  proof(auto simp add: Ob_def)\n    fix p\n    assume Q: \"dom (agreed_vote \\<circ> cfg) \\<in> Quorum\" (is \"?Q \\<in> Quorum\")\n    hence \"?Q \\<inter> HOs r p \\<noteq> {}\"  using per_rd[THEN spec, of r]\n      by(auto simp add: UV_commPerRd_def dest: qintersect)\n    hence \"someVoteRcvd (\\<mu> p) \\<noteq> {}\" using send[THEN spec, of p]\n      by(force simp add: someVoteRcvd_def get_msgs_benign msgRcvd_def restrict_map_def \n        isValVote_def send1_def)\n    moreover have \"\\<forall>q \\<in> someVoteRcvd (\\<mu> p). \\<exists>x'. \\<mu> p q = Some (ValVote x' (Some v))\"\n      using send[THEN spec, of p]\n      by(auto simp add: someVoteRcvd_def get_msgs_benign msgRcvd_def restrict_map_def\n        isValVote_def send1_def dest: v')\n    ultimately show \"last_obs (cfg' p) = v\" using step[THEN spec, of p]\n      by(auto simp add: next1_def x_update_def)\n  qed\n  note Ob_UNIV=this[rule_format]\n\n  have obs_guard: \"obs_guard o_f (agreed_vote \\<circ> cfg)\"\n    apply(auto simp add: obs_guard_def o_f_def S_def dom_def\n      dest: v' Ob_UNIV quorum_non_empty) \n    apply (metis S_def all_not_in_conv  empty_not_quorum v)\n    done\n\n  define sa' where \"sa' = sa\\<lparr> \n    next_round := Suc (next_round sa)\n    , decisions := decisions sa ++ dec_f\n    , opt_obsv_state.last_obs := opt_obsv_state.last_obs sa ++ o_f\n    \\<rparr>\"\n\n\n  \\<comment> \\<open>Abstract step\\<close>\n  have abs_step: \"(sa, sa') \\<in> tso_round1 r dec_f o_f\"  using next_r step_r R d_guard obs_guard\n    by(auto simp add: tso_round1_def sa'_def ref_rel_def two_step_step)\n\n  \\<comment> \\<open>Relation preserved\\<close>\n  have \"\\<forall>p. ((decide \\<circ> cfg) ++ dec_f) p = decide (cfg' p)\"\n  proof\n    fix p\n    show \"((decide \\<circ> cfg) ++ dec_f) p = decide (cfg' p)\" using step[THEN spec, of p]\n      by(auto simp add: dec_f_def D_def next1_def dec_update_def map_add_def)\n  qed\n  note dec_rel=this[rule_format]\n\n  have \"\\<forall>p. (\\<exists>q. o_f q = None \\<and> opt_obsv_state.last_obs sa q = None \n        \\<or> (opt_obsv_state.last_obs sa ++ o_f) q = Some (last_obs (cfg' p)))\"\n  proof(intro allI impI, cases \"S \\<in> Quorum\")\n    fix p \n    case True \n    hence \"last_obs (cfg' p) = v\" using Ob_UNIV\n      by(auto simp add: S_def Ob_def dom_def)\n    thus \"(\\<exists>q. o_f q = None \\<and> opt_obsv_state.last_obs sa q = None \n        \\<or> (opt_obsv_state.last_obs sa ++ o_f) q = Some (last_obs (cfg' p)))\"\n      using True\n      by(auto simp add: o_f_def)\n  next\n    fix p\n    case False\n    hence empty: \"o_f = Map.empty\"\n      by(auto simp add: o_f_def)\n    note last_obs = x_origin2[OF send step step_r refl, of p]\n    thus \"(\\<exists>q. o_f q = None \\<and> opt_obsv_state.last_obs sa q = None \n        \\<or> (opt_obsv_state.last_obs sa ++ o_f) q = Some (last_obs (cfg' p)))\"\n    proof(elim disjE exE)\n      fix q\n      assume \"last_obs (cfg q) = last_obs (cfg' p)\"\n      from this[symmetric] show ?thesis using R step_r empty\n        by(simp add: ref_rel_def two_step_step)\n    next\n      fix q\n      assume \"agreed_vote (cfg q) = Some (last_obs (cfg' p))\" \n      from this[symmetric] show ?thesis using R ainv2 step_r empty\n        apply(auto simp add: ref_rel_def two_step_step TSO_inv2_def)\n        by metis\n    qed\n  qed\n  note obs_rel=this[rule_format]\n\n  have post_rel: \n    \"(sa', Suc r, cfg') \\<in> ref_rel\" using step send next_r R step_r\n    by(auto simp add: sa'_def ref_rel_def two_step_step\n      two_step_phase_Suc dec_rel obs_rel)\n    \n  from abs_step post_rel show\n    \"\\<exists>sa'. (\\<exists>r d_f o_f. (sa, sa') \\<in> tso_round1 r d_f o_f) \\<and> (sa', Suc r, cfg') \\<in> ref_rel\"\n    by blast\nqed\n\nlemma UV_Refines_votes:\n  \"PO_refines (ref_rel \\<inter> (TSO_inv1 \\<inter> TSO_inv2) \\<times> UV_inv1)\n    tso_TS (UV_TS HOs HOs crds)\"\nproof(rule refine_using_invariants)\n  show \"init (UV_TS HOs HOs crds) \\<subseteq> ref_rel `` init tso_TS\"\n    by(auto simp add: UV_TS_defs UV_HOMachine_def CHOAlgorithm.truncate_def \n      tso_TS_defs ref_rel_def tso_init_def Let_def o_def)\nnext\n  show \n    \"{ref_rel \\<inter> (TSO_inv1 \\<inter> TSO_inv2) \\<times> UV_inv1} TS.trans tso_TS, \n      TS.trans (UV_TS HOs HOs crds) {> ref_rel}\"\n    apply(simp add: tso_TS_defs UV_TS_defs UV_HOMachine_def CHOAlgorithm.truncate_def)\n    apply(auto simp add: CHO_trans_alt UV_trans intro!: step0_ref step1_ref)\n    done\nqed(auto intro!: TSO_inv1_inductive TSO_inv2_inductive UV_inv1_inductive)\n\nend (* HO predicate context *)\n\nend (* mono_quorum context *)\n\nsubsubsection \\<open>Termination\\<close>\n(******************************************************************************)\n\ntext \\<open>As the model of the algorithm is taken verbatim from the HO Model AFP, we\n  do not repeat the termination proof here and refer to that AFP entry.\\<close>\n\nend (* theory *)\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Consensus_Refined/Observing/Uv_Proofs.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331462646254, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.28192409314802624}}
{"text": "(* @TAG(OTHER_LGPL) *)\n\n(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      HoarePartial.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection {* Properties of Total Correctness Hoare Logic *}\n\ntheory HoareTotalProps imports SmallStep HoareTotalDef HoarePartialProps begin\n\nsubsection {* Soundness *}\n\nlemma hoaret_sound: \n assumes hoare: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nusing hoare\nproof (induct)\n  case (Skip \\<Theta> F P A)\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Skip P,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Skip,Normal s\\<rangle> \\<Rightarrow> t\" \"s \\<in> P\"\n    thus \"t \\<in> Normal ` P \\<union> Abrupt ` A\"\n      by cases auto\n  next\n    fix s show \"\\<Gamma>\\<turnstile>Skip \\<down> Normal s\"\n      by (rule terminates.intros)\n  qed\nnext\n  case (Basic \\<Theta> F f P A)\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. f s \\<in> P} (Basic f) P,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Basic f,Normal s\\<rangle> \\<Rightarrow> t\" \"s \\<in> {s. f s \\<in> P}\"\n    thus \"t \\<in> Normal ` P \\<union> Abrupt ` A\"\n      by cases auto\n  next\n    fix s show \"\\<Gamma>\\<turnstile>Basic f \\<down> Normal s\"\n      by (rule terminates.intros)\n  qed\nnext\n  case (Spec \\<Theta> F r Q A)\n  show \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. (\\<forall>t. (s, t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s, t) \\<in> r)} Spec r Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Spec r ,Normal s\\<rangle> \\<Rightarrow> t\" \n           \"s \\<in> {s. (\\<forall>t. (s, t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s, t) \\<in> r)}\"\n    thus \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by cases auto\n  next\n    fix s show \"\\<Gamma>\\<turnstile>Spec r \\<down> Normal s\"\n      by (rule terminates.intros)\n  qed\nnext\n  case (Seq \\<Theta> F P c1 R A c2 Q)\n  have valid_c1: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c1 R,A\" by fact\n  have valid_c2: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c2 Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Seq c1 c2 Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal s\\<rangle> \\<Rightarrow> t\" \n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    from exec P obtain r where\n      exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> r\" and exec_c2:  \"\\<Gamma>\\<turnstile>\\<langle>c2,r\\<rangle> \\<Rightarrow> t\"\n      by cases auto\n    with t_notin_F have \"r \\<notin> Fault ` F\"\n      by (auto dest: Fault_end)\n    from valid_c1 ctxt exec_c1 P this\n    have r: \"r \\<in> Normal ` R \\<union> Abrupt ` A\"\n      by (rule cvalidt_postD)\n    show \"t\\<in>Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases r)\n      case (Normal r')\n      with exec_c2 r\n      show \"t\\<in>Normal ` Q \\<union> Abrupt ` A\"\n        apply -\n        apply (rule cvalidt_postD [OF valid_c2 ctxt _ _ t_notin_F])\n        apply auto\n        done\n    next\n      case (Abrupt r')\n      with exec_c2 have \"t=Abrupt r'\"\n        by (auto elim: exec_elim_cases)\n      with Abrupt r show ?thesis\n        by auto\n    next\n      case Fault with r show ?thesis by blast\n    next\n      case Stuck with r show ?thesis by blast\n    qed\n  next\n    fix s \n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s\\<in>P\"\n    show \"\\<Gamma>\\<turnstile>Seq c1 c2 \\<down> Normal s\"\n    proof -\n      from valid_c1 ctxt P\n      have \"\\<Gamma>\\<turnstile>c1\\<down> Normal s\"\n        by (rule cvalidt_termD)\n      moreover\n      {\n        fix r assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> r\"\n        have \"\\<Gamma>\\<turnstile>c2 \\<down> r\"\n        proof (cases r)\n          case (Normal r')\n          with cvalidt_postD [OF valid_c1 ctxt exec_c1 P]\n          have r: \"r\\<in>Normal ` R\"\n            by auto\n          with cvalidt_termD [OF valid_c2 ctxt] exec_c1\n          show \"\\<Gamma>\\<turnstile>c2 \\<down> r\"\n            by auto\n        qed auto        \n      }\n      ultimately show ?thesis\n        by (iprover intro: terminates.intros)\n    qed\n  qed\nnext\n  case (Cond \\<Theta> F P b c1 Q A c2)\n  have valid_c1: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> b) c1 Q,A\" by fact\n  have valid_c2: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> - b) c2 Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Cond b c1 c2 Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow> t\"\n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases \"s\\<in>b\")\n      case True\n      with exec have \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> t\"\n        by cases auto\n      with P True \n      show ?thesis\n        by - (rule cvalidt_postD [OF valid_c1 ctxt _ _ t_notin_F],auto)\n    next\n      case False\n      with exec P have \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal s\\<rangle> \\<Rightarrow> t\"\n        by cases auto\n      with P False \n      show ?thesis\n        by - (rule cvalidt_postD [OF valid_c2 ctxt _ _ t_notin_F],auto)\n    qed\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s \\<in> P\"\n    thus \"\\<Gamma>\\<turnstile>Cond b c1 c2 \\<down> Normal s\"\n      using cvalidt_termD [OF valid_c1 ctxt] cvalidt_termD [OF valid_c2 ctxt]\n      by (cases \"s \\<in> b\") (auto intro: terminates.intros)\n  qed\nnext\n  case (While r \\<Theta> F P b c A)\n  assume wf: \"wf r\"\n  have valid_c: \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P \\<inter> b) c ({t. (t, \\<sigma>) \\<in> r} \\<inter> P),A\"\n    using While.hyps by iprover\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (While b c) (P \\<inter> - b),A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume wprems: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow> t\" \"s \\<in> P\" \"t \\<notin> Fault ` F\"\n    from wf\n    have \"\\<And>t. \\<lbrakk>\\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow> t; s \\<in> P; t \\<notin> Fault ` F\\<rbrakk> \n                 \\<Longrightarrow> t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\"\n    proof (induct)\n      fix s t\n      assume hyp: \n        \"\\<And>s' t. \\<lbrakk>(s',s)\\<in>r; \\<Gamma>\\<turnstile>\\<langle>While b c,Normal s'\\<rangle> \\<Rightarrow> t; s' \\<in> P; t \\<notin> Fault ` F\\<rbrakk>\n                 \\<Longrightarrow> t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\"\n      assume exec: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow> t\"\n      assume P: \"s \\<in> P\"\n      assume t_notin_F: \"t \\<notin> Fault ` F\"\n      from exec\n      show \"t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\"\n      proof (cases)\n        fix s'\n        assume b: \"s\\<in>b\"\n        assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> s'\" \n        assume exec_w: \"\\<Gamma>\\<turnstile>\\<langle>While b c,s'\\<rangle> \\<Rightarrow> t\"\n        from exec_w t_notin_F have \"s' \\<notin> Fault ` F\"\n          by (auto dest: Fault_end)\n        from exec_c P b valid_c ctxt this\n        have s': \"s' \\<in> Normal ` ({s'. (s', s) \\<in> r} \\<inter> P) \\<union> Abrupt ` A\"\n          by (auto simp add: cvalidt_def validt_def valid_def)\n        show ?thesis\n        proof (cases s')\n          case Normal \n          with exec_w s' t_notin_F\n          show ?thesis\n            by - (rule hyp,auto)\n        next\n          case Abrupt\n          with exec_w have \"t=s'\"\n            by (auto dest: Abrupt_end)\n          with Abrupt s' show ?thesis\n            by blast\n        next\n          case Fault\n          with exec_w have \"t=s'\"\n            by (auto dest: Fault_end)\n          with Fault s' show ?thesis\n            by blast\n        next\n          case Stuck\n          with exec_w have \"t=s'\"\n            by (auto dest: Stuck_end)\n          with Stuck s' show ?thesis\n            by blast\n        qed\n      next\n        assume \"s\\<notin>b\" \"t=Normal s\" with P show ?thesis by simp\n      qed\n    qed\n    with wprems show \"t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\" by blast\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume \"s \\<in> P\"\n    with wf \n    show \"\\<Gamma>\\<turnstile>While b c \\<down> Normal s\"\n    proof (induct)\n      fix s\n      assume hyp: \"\\<And>s'. \\<lbrakk>(s',s)\\<in>r; s' \\<in> P\\<rbrakk> \n                         \\<Longrightarrow> \\<Gamma>\\<turnstile>While b c \\<down> Normal s'\"\n      assume P: \"s \\<in> P\"\n      show \"\\<Gamma>\\<turnstile>While b c \\<down> Normal s\"\n      proof (cases \"s \\<in> b\")\n        case False with P show ?thesis\n          by (blast intro: terminates.intros)\n      next\n        case True\n        with valid_c P ctxt\n        have \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n          by (simp add: cvalidt_def validt_def)\n        moreover\n        {\n          fix s'\n          assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> s'\"\n          have \"\\<Gamma>\\<turnstile>While b c \\<down> s'\"\n          proof (cases s')\n            case (Normal s'')\n            with exec_c P True valid_c ctxt\n            have s': \"s' \\<in> Normal ` ({s'. (s', s) \\<in> r} \\<inter> P)\"\n              by (fastforce simp add: cvalidt_def validt_def valid_def)\n            then show ?thesis\n              by (blast intro: hyp)\n          qed auto\n        }\n        ultimately\n        show ?thesis\n          by (blast intro: terminates.intros)\n      qed\n    qed\n  qed\nnext\n  case (Guard \\<Theta> F g P c Q A  f)\n  have valid_c: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) Guard f g c Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow> t\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    assume P:\"s \\<in> (g \\<inter> P)\"\n    from exec P have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by cases auto\n    from valid_c ctxt this P t_notin_F\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by (rule cvalidt_postD)\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P:\"s \\<in> (g \\<inter> P)\"\n    thus \"\\<Gamma>\\<turnstile>Guard f g c  \\<down> Normal s\"\n      by (auto intro: terminates.intros cvalidt_termD [OF valid_c ctxt])\n  qed\nnext\n  case (Guarantee f F \\<Theta> g P c Q A)\n  have valid_c: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\" by fact\n  have f_F: \"f \\<in> F\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Guard f g c Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow> t\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    assume P:\"s \\<in> P\"\n    from exec f_F t_notin_F have g: \"s \\<in> g\"\n      by cases auto\n    with P have P': \"s \\<in> g \\<inter> P\"\n      by blast\n    from exec g have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by cases auto\n    from valid_c ctxt this P' t_notin_F\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by (rule cvalidt_postD)\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P:\"s \\<in> P\"\n    thus \"\\<Gamma>\\<turnstile>Guard f g c  \\<down> Normal s\"\n      by (auto intro: terminates.intros cvalidt_termD [OF valid_c ctxt])\n  qed\nnext\n  case (CallRec P p Q A Specs r Specs_wf \\<Theta>  F)\n  have p: \"(P,p,Q,A) \\<in> Specs\"  by fact\n  have wf: \"wf r\" by fact\n  have Specs_wf: \n    \"Specs_wf = (\\<lambda>p \\<tau>. (\\<lambda>(P,q,Q,A). (P \\<inter> {s. ((s, q),\\<tau>,p) \\<in> r},q,Q,A)) ` Specs)\" by fact\n  from CallRec.hyps\n  have valid_body: \n    \"\\<forall>(P, p, Q, A)\\<in>Specs. p \\<in> dom \\<Gamma> \\<and>\n        (\\<forall>\\<tau>. \\<Gamma>,\\<Theta> \\<union> Specs_wf p \\<tau>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) the (\\<Gamma> p) Q,A)\" by auto\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  proof -\n    {\n      fix \\<tau>p \n      assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n      from wf\n      have \"\\<And>\\<tau> p P Q A.  \\<lbrakk>\\<tau>p = (\\<tau>,p); (P,p,Q,A) \\<in> Specs\\<rbrakk> \\<Longrightarrow> \n                  \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> (p))) Q,A\"    \n      proof (induct \\<tau>p rule: wf_induct [rule_format, consumes 1, case_names WF])\n        case (WF \\<tau>p \\<tau> p P Q A)\n        have \\<tau>p: \"\\<tau>p = (\\<tau>, p)\" by fact\n        have p: \"(P, p, Q, A) \\<in> Specs\" by fact\n        {\n          fix q P' Q' A'\n          assume q: \"(P',q,Q',A') \\<in> Specs\"\n          have \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' \\<inter> {s. ((s,q), \\<tau>,p) \\<in> r}) (Call q) Q',A'\"\n          proof (rule validtI)\n            fix s t\n            assume exec_q: \n              \"\\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow> t\"\n            assume Pre: \"s \\<in> P' \\<inter> {s. ((s,q), \\<tau>,p) \\<in> r}\"\n            assume t_notin_F: \"t \\<notin> Fault ` F\"\n            from Pre q \\<tau>p\n            have valid_bdy: \n              \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s} \\<inter> P') the (\\<Gamma> q) Q',A'\"\n              by - (rule WF.hyps, auto)\n            from Pre q\n            have Pre': \"s \\<in> {s} \\<inter> P'\"\n              by auto\n            from exec_q show \"t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n            proof (cases)\n              fix bdy \n              assume bdy: \"\\<Gamma> q = Some bdy\"\n              assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal s\\<rangle> \\<Rightarrow> t\"\n              from valid_bdy [simplified bdy option.sel]  t_notin_F exec_bdy Pre'\n              have \"t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n                by (auto simp add: validt_def valid_def)\n              with Pre q \n              show ?thesis\n                by auto\n            next\n              assume \"\\<Gamma> q = None\"\n              with q valid_body have False by auto\n              thus ?thesis ..\n            qed\n          next\n            fix s\n            assume Pre: \"s \\<in> P' \\<inter> {s. ((s,q), \\<tau>,p) \\<in> r}\"\n            from Pre q \\<tau>p\n            have valid_bdy: \n              \"\\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s} \\<inter> P') (the (\\<Gamma> q)) Q',A'\"\n              by - (rule WF.hyps, auto)\n            from Pre q\n            have Pre': \"s \\<in> {s} \\<inter> P'\"\n              by auto\n            from valid_bdy ctxt Pre'\n            have \"\\<Gamma>\\<turnstile>the (\\<Gamma> q) \\<down> Normal s\"\n              by (auto simp add: validt_def)\n            with valid_body q \n            show \"\\<Gamma>\\<turnstile>Call q\\<down> Normal s\"\n              by (fastforce intro: terminates.Call)\n          qed\n        }\n        hence \"\\<forall>(P, p, Q, A)\\<in>Specs_wf p \\<tau>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Call p Q,A\"\n          by (auto simp add: cvalidt_def Specs_wf)\n        with ctxt have \"\\<forall>(P, p, Q, A)\\<in>\\<Theta> \\<union> Specs_wf p \\<tau>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Call p Q,A\"\n          by auto\n        with p valid_body \n        show \"\\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> p)) Q,A\"\n          by (simp add: cvalidt_def) blast\n      qed\n    }\n    note lem = this\n    have valid_body': \n      \"\\<And>\\<tau>. \\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A \\<Longrightarrow> \n      \\<forall>(P,p,Q,A)\\<in>Specs. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> p)) Q,A\"\n      by (auto intro: lem)\n    show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    proof (rule cvalidtI)\n      fix s t\n      assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n      assume exec_call: \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow> t\"\n      assume P: \"s \\<in> P\"\n      assume t_notin_F: \"t \\<notin> Fault ` F\"\n      from exec_call show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      proof (cases)\n        fix bdy \n        assume bdy: \"\\<Gamma> p = Some bdy\"\n        assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal s\\<rangle> \\<Rightarrow> t\"\n        from exec_body bdy p P t_notin_F \n          valid_body' [of \"s\", OF ctxt] \n          ctxt\n        have \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n          apply (simp only: cvalidt_def validt_def valid_def) \n          apply (drule (1) bspec)\n          apply auto\n          done\n        with p P \n        show ?thesis\n          by simp\n      next\n        assume \"\\<Gamma> p = None\"\n        with p valid_body have False by auto\n        thus ?thesis by simp\n      qed\n    next\n      fix s\n      assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n      assume P: \"s \\<in> P\"\n      show \"\\<Gamma>\\<turnstile>Call p \\<down> Normal s\"\n      proof -\n        from ctxt P p valid_body' [of \"s\",OF ctxt]\n        have \"\\<Gamma>\\<turnstile>(the (\\<Gamma> p)) \\<down> Normal s\"\n          by (auto simp add: cvalidt_def validt_def)\n        with valid_body p show ?thesis\n          by (fastforce intro: terminates.Call)\n      qed\n    qed\n  qed\nnext\n  case (DynCom P \\<Theta> F c Q A)\n  hence valid_c: \"\\<forall>s\\<in>P. \\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (c s) Q,A\" by simp\n  show \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P DynCom c Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal s\\<rangle> \\<Rightarrow> t\" \n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    from exec show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases)\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c s,Normal s\\<rangle> \\<Rightarrow> t\"      \n      from cvalidt_postD [OF valid_c [rule_format, OF P] ctxt this P t_notin_F]\n      show ?thesis .\n    qed\n  next\n    fix s \n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s \\<in> P\"\n    show \"\\<Gamma>\\<turnstile>DynCom c \\<down> Normal s\"\n    proof -\n      from cvalidt_termD [OF valid_c [rule_format, OF P] ctxt P]\n      have \"\\<Gamma>\\<turnstile>c s \\<down> Normal s\" .\n      thus ?thesis\n        by (rule terminates.intros)\n    qed\n  qed\nnext\n  case (Throw \\<Theta> F A Q)\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> A Throw Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Throw,Normal s\\<rangle> \\<Rightarrow> t\" \"s \\<in> A\"\n    then show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by cases simp\n  next\n    fix s\n    show \"\\<Gamma>\\<turnstile>Throw \\<down> Normal s\"\n      by (rule terminates.intros)\n  qed\nnext\n  case (Catch \\<Theta> F P c\\<^sub>1 Q R c\\<^sub>2 A)\n  have valid_c1: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,R\" by fact\n  have valid_c2: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Catch c\\<^sub>1 c\\<^sub>2 Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow> t\" \n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    from exec show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases)\n      fix s'\n      assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Abrupt s'\" \n      assume exec_c2: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s'\\<rangle> \\<Rightarrow> t\"\n      from cvalidt_postD [OF valid_c1 ctxt exec_c1 P]\n      have \"Abrupt s' \\<in> Abrupt ` R\"\n        by auto\n      with cvalidt_postD [OF valid_c2 ctxt] exec_c2 t_notin_F\n      show ?thesis\n        by fastforce\n    next\n      assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t\" \n      assume notAbr: \"\\<not> isAbr t\"\n      from cvalidt_postD [OF valid_c1 ctxt exec_c1 P] t_notin_F\n      have \"t \\<in> Normal ` Q \\<union> Abrupt ` R\" .\n      with notAbr\n      show ?thesis\n        by auto\n    qed\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s \\<in> P\"\n    show \"\\<Gamma>\\<turnstile>Catch c\\<^sub>1 c\\<^sub>2 \\<down> Normal s\"  \n    proof -\n      from valid_c1 ctxt P\n      have \"\\<Gamma>\\<turnstile>c\\<^sub>1\\<down> Normal s\"\n        by (rule cvalidt_termD)\n      moreover\n      {\n        fix r assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Abrupt r\"\n        from cvalidt_postD [OF valid_c1 ctxt exec_c1 P]\n        have r: \"Abrupt r\\<in>Normal ` Q \\<union> Abrupt ` R\"\n          by auto\n        hence \"Abrupt r\\<in>Abrupt ` R\" by fast\n        with cvalidt_termD [OF valid_c2 ctxt] exec_c1\n        have \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal r\"\n          by fast\n      }\n      ultimately show ?thesis\n        by (iprover intro: terminates.intros)\n    qed\n  qed\nnext\n  case (Conseq P \\<Theta> F c Q A)\n  hence adapt: \n    \"\\<forall>s \\<in> P. (\\<exists>P' Q' A'. (\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A') \\<and> s \\<in> P'\\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A)\" by blast\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof -\n      from adapt [rule_format, OF P]\n      obtain P' and Q' and A' where \n        valid_P'_Q': \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A'\"\n        and weaken: \"s \\<in> P'\" \"Q' \\<subseteq>  Q\" \"A'\\<subseteq> A\"\n        by blast\n      from exec valid_P'_Q' ctxt t_notin_F\n      have P'_Q': \"Normal s \\<in> Normal ` P' \\<longrightarrow> \n        t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n        by (unfold cvalidt_def validt_def valid_def) blast\n      hence \"s \\<in> P' \\<longrightarrow> t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n        by blast\n      with weaken \n      show ?thesis\n        by blast\n    qed\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s \\<in> P\"\n    show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    proof -\n      from P adapt\n      obtain P' and Q' and  A' where \n        \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A'\"\n        \"s \\<in> P'\"\n        by blast\n      with ctxt\n      show ?thesis\n        by (simp add: cvalidt_def validt_def)\n    qed\n  qed\nnext\n  case (Asm P p Q A \\<Theta> F)\n  assume \"(P, p, Q, A) \\<in> \\<Theta>\"\n  then show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (auto simp add: cvalidt_def )\nnext\n  case ExFalso thus ?case by iprover\nqed\n\nlemma hoaret_sound':\n\"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (drule hoaret_sound)\n  apply (simp add: cvalidt_def)\n  done\n\ntheorem total_to_partial: \n assumes total: \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" shows \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from total have \"\\<Gamma>,{}\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (rule hoaret_sound)\n  hence \"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (simp add: cvalidt_def validt_def cvalid_def)\n  thus ?thesis\n    by (rule hoare_complete)\nqed\n\nsubsection {* Completeness *}\n\nlemma MGT_valid:\n\"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \\<Gamma>\\<turnstile>c\\<down>Normal s} c \n    {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t}, {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\nproof (rule validtI) \n  fix s t\n  assume \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n         \"s \\<in> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \\<Gamma>\\<turnstile>c\\<down>Normal s}\"\n         \"t \\<notin> Fault ` F\"\n  thus \"t \\<in> Normal ` {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t} \\<union> \n            Abrupt ` {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    apply (cases t) \n    apply (auto simp add: final_notin_def)\n    done\nnext\n  fix s\n  assume \"s \\<in> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \\<Gamma>\\<turnstile>c\\<down>Normal s}\"\n  thus \"\\<Gamma>\\<turnstile>c\\<down>Normal s\"\n    by blast\nqed\n\ntext {* The consequence rule where the existential @{term Z} is instantiated\nto @{term s}. Usefull in proof of @{text \"MGT_lemma\"}.*}\nlemma ConseqMGT: \n  assumes modif: \"\\<forall>Z::'a. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z::'a assn) c (Q' Z),(A' Z)\"\n  assumes impl: \"\\<And>s. s \\<in> P \\<Longrightarrow> s \\<in> P' s \\<and> (\\<forall>t. t \\<in> Q' s \\<longrightarrow> t \\<in> Q) \\<and> \n                                            (\\<forall>t. t \\<in> A' s \\<longrightarrow> t \\<in> A)\"\n  shows \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nusing impl \nby - (rule conseq [OF modif],blast)\n\nlemma MGT_implies_complete:\n  assumes MGT: \"\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                                 \\<Gamma>\\<turnstile>c\\<down>Normal s}\n                              c \n                            {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                            {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  assumes valid: \"\\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" \n  shows \"\\<Gamma>,{} \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  using MGT\n  apply (rule ConseqMGT) \n  apply (insert valid)\n  apply (auto simp add: validt_def valid_def intro!: final_notinI)\n  done\n\nlemma conseq_extract_state_indep_prop: \n  assumes state_indep_prop:\"\\<forall>s \\<in> P. R\" \n  assumes to_show: \"R \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule Conseq)\n  apply (clarify)\n  apply (rule_tac x=\"P\" in exI)\n  apply (rule_tac x=\"Q\" in exI)\n  apply (rule_tac x=\"A\" in exI)\n  using state_indep_prop to_show\n  by blast\n\nlemma MGT_lemma:\n  assumes MGT_Calls: \n    \"\\<forall>p \\<in> dom \\<Gamma>. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> \n       {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n           \\<Gamma>\\<turnstile>(Call p)\\<down>Normal s}\n             (Call p)\n       {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n       {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  shows \"\\<And>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                          \\<Gamma>\\<turnstile>c\\<down>Normal s} \n               c \n             {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\nproof (induct c)\n  case Skip\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Skip,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                   \\<Gamma>\\<turnstile>Skip \\<down> Normal s} \n               Skip\n            {t. \\<Gamma>\\<turnstile>\\<langle>Skip,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>Skip,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoaret.Skip [THEN conseqPre])\n       (auto elim: exec_elim_cases simp add: final_notin_def \n             intro: exec.intros terminates.intros)\nnext\n  case (Basic f)\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Basic f,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                 \\<Gamma>\\<turnstile>Basic f \\<down> Normal s} \n                Basic f\n              {t. \\<Gamma>\\<turnstile>\\<langle>Basic f,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Basic f,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoaret.Basic [THEN conseqPre]) \n       (auto elim: exec_elim_cases simp add: final_notin_def \n             intro: exec.intros terminates.intros)\nnext\n  case (Spec r)\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Spec r,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Spec r \\<down> Normal s} \n                Spec r\n              {t. \\<Gamma>\\<turnstile>\\<langle>Spec r,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Spec r,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    apply (rule hoaret.Spec [THEN conseqPre])\n    apply (clarsimp simp add: final_notin_def)\n    apply (case_tac \"\\<exists>t. (Z,t) \\<in> r\")\n    apply (auto elim: exec_elim_cases simp add: final_notin_def intro: exec.intros)\n    done\nnext\n  case (Seq c1 c2) \n  have hyp_c1: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                                \\<Gamma>\\<turnstile>c1\\<down>Normal s}\n                            c1 \n                           {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                           {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" \n    using Seq.hyps by iprover\n  have hyp_c2: \"\\<forall> Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                                 \\<Gamma>\\<turnstile>c2\\<down>Normal s}\n                              c2 \n                            {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                            {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" \n    using Seq.hyps by iprover\n  from hyp_c1 \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                \\<Gamma>\\<turnstile>Seq c1 c2\\<down>Normal s} c1 \n    {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t \\<and> \\<Gamma>\\<turnstile>\\<langle>c2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n        \\<Gamma>\\<turnstile>c2\\<down>Normal t},\n    {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT)\n       (auto dest: Seq_NoFaultStuckD1 [simplified] Seq_NoFaultStuckD2 [simplified]\n             elim: terminates_Normal_elim_cases \n             intro: exec.intros)\n  thus \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                 \\<Gamma>\\<turnstile>Seq c1 c2\\<down>Normal s} \n                Seq c1 c2\n              {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  proof (rule hoaret.Seq )\n    show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t \\<and>\n                    \\<Gamma>\\<turnstile>\\<langle>c2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \\<Gamma>\\<turnstile>c2 \\<down> Normal t}\n                 c2 \n                {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    proof (rule ConseqMGT [OF hyp_c2],safe)\n      fix r t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal r\" \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal r\\<rangle> \\<Rightarrow> Normal t\"\n      then show \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n        by (rule exec.intros)\n    next\n      fix r t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal r\" \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal r\\<rangle> \\<Rightarrow> Abrupt t\"\n      then show \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n        by (rule exec.intros)\n    qed\n  qed\nnext\n  case (Cond b c1 c2) \n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                         \\<Gamma>\\<turnstile>c1\\<down>Normal s} \n                     c1 \n                   {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                   {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" \n    using Cond.hyps by iprover  \n  hence \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                     \\<Gamma>\\<turnstile>(Cond b c1 c2)\\<down>Normal s}\\<inter>b) \n                c1 \n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"  \n    by (rule ConseqMGT)\n       (fastforce simp add: final_notin_def intro: exec.CondTrue \n                 elim: terminates_Normal_elim_cases)\n  moreover\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                               \\<Gamma>\\<turnstile>c2\\<down>Normal s} \n                      c2 \n                    {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                    {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"  \n    using Cond.hyps by iprover  \n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>(Cond b c1 c2)\\<down>Normal s}\\<inter>-b) \n                c2 \n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" \n    by (rule ConseqMGT)\n       (fastforce simp add: final_notin_def intro: exec.CondFalse \n                 elim: terminates_Normal_elim_cases)\n  ultimately\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n               \\<Gamma>\\<turnstile>(Cond b c1 c2)\\<down>Normal s} \n               (Cond b c1 c2)\n              {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoaret.Cond)       \nnext\n  case (While b c)\n  let ?unroll = \"({(s,t). s\\<in>b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t})\\<^sup>*\"\n  let ?P' = \"\\<lambda>Z. {t. (Z,t)\\<in>?unroll \\<and> \n                    (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                         \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                             (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)) \\<and>\n                    \\<Gamma>\\<turnstile>(While b c)\\<down>Normal t}\"\n  let ?A = \"\\<lambda>Z. {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  let ?r = \"{(t,s). \\<Gamma>\\<turnstile>(While b c)\\<down>Normal s \\<and> s\\<in>b \\<and> \n                    \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t}\"\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>  \n                  \\<Gamma>\\<turnstile>(While b c)\\<down>Normal s} \n              (While b c)\n              {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  proof (rule ConseqMGT [where ?P'=\"\\<lambda> Z. ?P' Z\" \n                         and ?Q'=\"\\<lambda> Z. ?P' Z \\<inter> - b\"])\n    have wf_r: \"wf ?r\" by (rule wf_terminates_while)\n    show \"\\<forall> Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (?P' Z) (While b c) (?P' Z \\<inter> - b),(?A Z)\"\n    proof (rule allI, rule hoaret.While [OF wf_r])\n      fix Z\n      from While \n      have hyp_c: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                                  \\<Gamma>\\<turnstile>c\\<down>Normal s}\n                                c\n                              {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                              {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" by iprover\n      show \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> ?P' Z  \\<inter> b) c \n                       ({t. (t, \\<sigma>) \\<in> ?r} \\<inter> ?P' Z),(?A Z)\"\n      proof (rule allI, rule ConseqMGT [OF hyp_c])\n        fix \\<sigma> s\n        assume  \"s\\<in> {\\<sigma>} \\<inter>  \n                   {t. (Z, t) \\<in> ?unroll \\<and> \n                      (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                           \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                               (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                                    \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)) \\<and>\n                      \\<Gamma>\\<turnstile>(While b c)\\<down>Normal t}\n                   \\<inter> b\"\n        then obtain \n          s_eq_\\<sigma>: \"s=\\<sigma>\" and\n          Z_s_unroll: \"(Z,s) \\<in> ?unroll\" and\n          noabort:\"\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                        \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                            (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)\" and\n          while_term:  \"\\<Gamma>\\<turnstile>(While b c)\\<down>Normal s\" and\n          s_in_b: \"s\\<in>b\" \n          by blast\n        show \"s \\<in> {t. t = s \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                       \\<Gamma>\\<turnstile>c\\<down>Normal t} \\<and>\n        (\\<forall>t. t \\<in> {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t} \\<longrightarrow>\n             t \\<in> {t. (t,\\<sigma>) \\<in> ?r} \\<inter>  \n                 {t. (Z, t) \\<in> ?unroll \\<and> \n                     (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow>  e\\<in>b \n                           \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                              (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)) \\<and> \n                      \\<Gamma>\\<turnstile>(While b c)\\<down>Normal t})  \\<and> \n         (\\<forall>t. t \\<in> {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Abrupt t} \\<longrightarrow>\n             t \\<in> {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})\"\n          (is \"?C1 \\<and> ?C2 \\<and> ?C3\")\n        proof (intro conjI)\n          from Z_s_unroll noabort s_in_b while_term show ?C1 \n            by (blast elim: terminates_Normal_elim_cases)\n        next\n          {\n            fix t \n            assume s_t: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t\"\n            with s_eq_\\<sigma> while_term s_in_b have \"(t,\\<sigma>) \\<in> ?r\"\n              by blast\n            moreover\n            from Z_s_unroll s_t s_in_b \n            have \"(Z, t) \\<in> ?unroll\"\n              by (blast intro: rtrancl_into_rtrancl)\n            moreover from while_term s_t s_in_b \n            have \"\\<Gamma>\\<turnstile>(While b c)\\<down>Normal t\"\n              by (blast elim: terminates_Normal_elim_cases)\n            moreover note noabort\n            ultimately \n            have \"(t,\\<sigma>) \\<in> ?r \\<and> (Z, t) \\<in> ?unroll \\<and> \n                  (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                        \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                            (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)) \\<and>\n                  \\<Gamma>\\<turnstile>(While b c)\\<down>Normal t\"\n              by iprover\n          }\n          then show ?C2 by blast\n        next\n          {\n            fix t\n            assume s_t:  \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Abrupt t\" \n            from Z_s_unroll noabort s_t s_in_b\n            have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n              by blast\n          } thus ?C3 by simp\n        qed\n      qed\n    qed\n  next\n    fix s\n    assume P: \"s \\<in> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                       \\<Gamma>\\<turnstile>While b c \\<down> Normal s}\"\n    hence WhileNoFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n      by auto\n    show \"s \\<in> ?P' s \\<and> \n     (\\<forall>t. t\\<in>(?P' s \\<inter> - b)\\<longrightarrow>\n          t\\<in>{t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t})\\<and>\n     (\\<forall>t. t\\<in>?A s \\<longrightarrow> t\\<in>?A Z)\"\n    proof (intro conjI)\n      {\n        fix e\n        assume \"(Z,e) \\<in> ?unroll\" \"e \\<in> b\"\n        from this WhileNoFault\n        have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n               (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)\" (is \"?Prop Z e\")\n        proof (induct rule: converse_rtrancl_induct [consumes 1])\n          assume e_in_b: \"e \\<in> b\"\n          assume WhileNoFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n          with e_in_b WhileNoFault\n          have cNoFault: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n            by (auto simp add: final_notin_def intro: exec.intros)\n          moreover\n          {\n            fix u assume \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow> Abrupt u\"\n            with e_in_b have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal e\\<rangle> \\<Rightarrow> Abrupt u\"\n              by (blast intro: exec.intros)\n          }\n          ultimately\n          show \"?Prop e e\"\n            by iprover\n        next\n          fix Z r\n          assume e_in_b: \"e\\<in>b\" \n          assume WhileNoFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n          assume hyp: \"\\<lbrakk>e\\<in>b;\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\\<rbrakk>\n                       \\<Longrightarrow> ?Prop r e\"\n          assume Z_r:\n            \"(Z, r) \\<in> {(Z, r). Z \\<in> b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal r}\"\n          with WhileNoFault\n          have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n            by (auto simp add: final_notin_def intro: exec.intros)\n          from hyp [OF e_in_b this] obtain\n            cNoFault: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\" and\n            Abrupt_r: \"\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow> Abrupt u \\<longrightarrow> \n                            \\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow> Abrupt u\"\n            by simp\n          \n           {\n            fix u assume \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow> Abrupt u\"\n            with Abrupt_r have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow> Abrupt u\" by simp\n            moreover from  Z_r obtain\n              \"Z \\<in> b\"  \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal r\"\n              by simp\n            ultimately have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u\"\n              by (blast intro: exec.intros)\n          }\n          with cNoFault show \"?Prop Z e\"\n            by iprover\n        qed\n      }\n      with P show \"s \\<in> ?P' s\"\n        by blast\n    next\n      {\n        fix t\n        assume \"termination\": \"t \\<notin> b\"\n        assume \"(Z, t) \\<in> ?unroll\"\n        hence \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n        proof (induct rule: converse_rtrancl_induct [consumes 1])\n          from \"termination\" \n          show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal t\\<rangle> \\<Rightarrow> Normal t\"\n            by (blast intro: exec.WhileFalse)\n        next\n          fix Z r\n          assume first_body: \n                 \"(Z, r) \\<in> {(s, t). s \\<in> b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t}\"\n          assume \"(r, t) \\<in> ?unroll\"\n          assume rest_loop: \"\\<Gamma>\\<turnstile>\\<langle>While b c, Normal r\\<rangle> \\<Rightarrow> Normal t\"\n          show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n          proof -\n            from first_body obtain\n              \"Z \\<in> b\" \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal r\"\n              by fast\n            moreover\n            from rest_loop have\n              \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow> Normal t\"\n              by fast\n            ultimately show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n              by (rule exec.WhileTrue)\n          qed\n        qed\n      }\n      with P\n      show \"(\\<forall>t. t\\<in>(?P' s \\<inter> - b)\n            \\<longrightarrow>t\\<in>{t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t})\"\n        by blast\n    next\n      from P show \"\\<forall>t. t\\<in>?A s \\<longrightarrow> t\\<in>?A Z\"\n        by simp\n    qed\n  qed\nnext\n  case (Call p)\n  from noStuck_Call\n  have \"\\<forall>s \\<in> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                         \\<Gamma>\\<turnstile>Call p\\<down> Normal s}.\n          p \\<in> dom \\<Gamma>\"\n    by (fastforce simp add: final_notin_def)\n  then show ?case\n  proof (rule conseq_extract_state_indep_prop)\n    assume p_defined: \"p \\<in> dom \\<Gamma>\"\n    with MGT_Calls show\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s=Z \\<and> \n                 \\<Gamma>\\<turnstile>\\<langle>Call p ,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\\<and>\n                 \\<Gamma>\\<turnstile>Call  p\\<down>Normal s}\n                (Call p)\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      by (auto)\n  qed\nnext\n  case (DynCom c)\n  have hyp: \n    \"\\<And>s'. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c s',Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                       \\<Gamma>\\<turnstile>c s'\\<down>Normal s} c s'\n      {t. \\<Gamma>\\<turnstile>\\<langle>c s',Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c s',Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using DynCom by simp\n  have hyp':\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n            \\<Gamma>\\<turnstile>DynCom c\\<down>Normal s} \n         (c Z)\n        {t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT [OF hyp]) \n       (fastforce simp add: final_notin_def intro: exec.intros \n          elim: terminates_Normal_elim_cases)\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                 \\<Gamma>\\<turnstile>DynCom c\\<down>Normal s}\n                DynCom c\n             {t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    apply (rule hoaret.DynCom)\n    apply (clarsimp)\n    apply (rule hyp' [simplified])\n    done\nnext\n  case (Guard f g c)\n  have hyp_c: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                              \\<Gamma>\\<turnstile>c\\<down>Normal s} \n                     c \n                   {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                   {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Guard by iprover\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Guard f g c\\<down> Normal s} \n                Guard f g c \n              {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  proof (cases \"f \\<in> F\")\n    case True\n    from hyp_c\n    have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>(g \\<inter> {s. s=Z \\<and> \n                     \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck}\\<union> Fault ` (-F))\\<and>\n                     \\<Gamma>\\<turnstile>Guard f g c\\<down> Normal s})\n                   c\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      apply (rule ConseqMGT)\n      apply (insert True)\n      apply  (auto simp add: final_notin_def intro: exec.intros \n                   elim: terminates_Normal_elim_cases)\n      done\n    from True this\n    show ?thesis\n      by (rule conseqPre [OF Guarantee]) auto\n  next\n    case False\n    from hyp_c\n    have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>(g \\<inter> {s. s \\<in> g \\<and> s=Z \\<and> \n                     \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck}\\<union> Fault ` (-F))\\<and>\n                     \\<Gamma>\\<turnstile>Guard f g c\\<down> Normal s} )\n                   c\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      apply (rule ConseqMGT)\n      apply clarify\n      apply (frule Guard_noFaultStuckD [OF _ False])\n      apply  (auto simp add: final_notin_def intro: exec.intros \n                   elim: terminates_Normal_elim_cases)\n      done\n    then show ?thesis\n      apply (rule conseqPre [OF hoaret.Guard])\n      apply clarify\n      apply (frule Guard_noFaultStuckD [OF _ False])\n      apply auto\n      done\n  qed\nnext\n  case Throw\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Throw,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Throw \\<down> Normal s}\n              Throw\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule conseqPre [OF hoaret.Throw]) \n       (blast intro: exec.intros terminates.intros)\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                        \\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s} \n                    c\\<^sub>1\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                   \\<Gamma>\\<turnstile>Catch c\\<^sub>1 c\\<^sub>2 \\<down> Normal s} \n                c\\<^sub>1\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t \\<and> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal t \\<and>\n                   \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\"\n    by (rule ConseqMGT)\n       (fastforce intro: exec.intros terminates.intros \n                 elim: terminates_Normal_elim_cases\n                 simp add: final_notin_def)\n  moreover\n  have \n    \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                     \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s} c\\<^sub>2\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow>Abrupt s \\<and> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s \\<and> \n                   \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} \n               c\\<^sub>2\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      by (rule ConseqMGT)\n         (fastforce intro: exec.intros terminates.intros \n                   simp add: noFault_def')\n  ultimately\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                   \\<Gamma>\\<turnstile>Catch c\\<^sub>1 c\\<^sub>2 \\<down> Normal s} \n                Catch c\\<^sub>1 c\\<^sub>2\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoaret.Catch )\nqed\n\n\n\n\n      assume \"Z \\<in> g\"\n      from this have \"\\<Gamma>\\<turnstile>(Guard f g c,Normal Z) \\<rightarrow> (c,Normal Z)\"\n        by (rule step.Guard)\n      from step_redexes [OF this c'] obtain c'' where\n        step: \"\\<Gamma>\\<turnstile> (c', Normal Z) \\<rightarrow> (c'', Normal Z)\"  and c'': \"c \\<in> redexes c''\"\n        by blast\n      note steps also note step \n      finally show \"\\<exists>c'. \\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z) \\<and> c \\<in> redexes c'\"\n        using c'' by blast\n    next\n      fix t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\" \n        \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n      thus \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n        using False\n        by (cases \"Z\\<in> g\") (auto simp add: final_notin_def intro: exec.intros )\n    next\n      fix t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\" \n             \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n      thus \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n        using False\n        by (cases \"Z\\<in> g\") (auto simp add: final_notin_def intro: exec.intros )\n    qed\n    then show ?thesis\n      apply (rule conseqPre [OF hoaret.Guard])\n      apply clarify\n      apply (frule Guard_noFaultStuckD [OF _ False])\n      apply auto\n      done\n  qed\nnext\n  case Throw\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Throw,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                  \\<Gamma>\\<turnstile>Call p\\<down>Normal \\<sigma> \\<and>\n                (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and> Throw \\<in> redexes c')}\n              Throw\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule conseqPre [OF hoaret.Throw]) \n       (blast intro: exec.intros terminates.intros)\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have hyp_c1:\n   \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s= Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call p \\<down> Normal \\<sigma> \\<and>\n                (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and> \n                      c\\<^sub>1 \\<in> redexes c')}\n               c\\<^sub>1 \n              {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  have hyp_c2:\n   \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s= Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                     \\<Gamma>\\<turnstile>Call p\\<down> Normal \\<sigma> \\<and>\n                (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and> c\\<^sub>2 \\<in> redexes c')}\n               c\\<^sub>2\n              {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  have\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n               \\<Gamma>\\<turnstile>Call p\\<down> Normal \\<sigma> \\<and>\n            (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>)\\<rightarrow>\\<^sup>+(c',Normal s) \\<and>\n                   Catch c\\<^sub>1 c\\<^sub>2 \\<in> redexes c')}\n            c\\<^sub>1\n           {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n           {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t \\<and> \n               \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault`(-F)) \\<and> \\<Gamma>\\<turnstile>Call p \\<down> Normal \\<sigma> \\<and>\n               (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal t) \\<and> c\\<^sub>2 \\<in> redexes c')}\"\n  proof (rule ConseqMGT [OF hyp_c1],clarify,safe) \n    assume \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n    thus \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n      by (fastforce simp add: final_notin_def intro: exec.intros)\n  next\n    fix c'\n    assume steps: \"\\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z)\" \n    assume c': \"Catch c\\<^sub>1 c\\<^sub>2 \\<in> redexes c'\"\n    from steps redexes_subset [OF this]\n    show \"\\<exists>c'. \\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z) \\<and> c\\<^sub>1 \\<in> redexes c'\"\n      by (auto iff:  root_in_redexes)\n  next\n    fix t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n    thus \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n      by (auto intro: exec.intros)\n  next\n    fix t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\" \n      \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n    thus \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n      by (auto simp add: final_notin_def intro: exec.intros)\n  next\n    fix c' t\n    assume steps_c': \"\\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z)\" \n    assume red: \"Catch c\\<^sub>1 c\\<^sub>2 \\<in> redexes c'\"\n    assume exec_c\\<^sub>1: \"\\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n    show \"\\<exists>c'. \\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal t) \\<and> c\\<^sub>2 \\<in> redexes c'\"\n    proof -\n      note steps_c'\n      also\n      from exec_impl_steps_Normal_Abrupt [OF exec_c\\<^sub>1]\n      have \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal Z) \\<rightarrow>\\<^sup>* (Throw, Normal t)\".\n      from steps_redexes_Catch [OF this red] \n      obtain c'' where\n        steps_c'': \"\\<Gamma>\\<turnstile> (c', Normal Z) \\<rightarrow>\\<^sup>* (c'', Normal t)\" and\n        Catch: \"Catch Throw c\\<^sub>2 \\<in> redexes c''\"\n        by blast\n      note steps_c''\n      also \n      have step_Catch: \"\\<Gamma>\\<turnstile> (Catch Throw c\\<^sub>2,Normal t) \\<rightarrow> (c\\<^sub>2,Normal t)\"\n        by (rule step.CatchThrow)\n      from step_redexes [OF step_Catch Catch]\n      obtain c''' where\n        step_c''': \"\\<Gamma>\\<turnstile> (c'', Normal t) \\<rightarrow> (c''', Normal t)\" and\n        c2: \"c\\<^sub>2 \\<in> redexes c'''\"\n        by blast\n      note step_c'''\n      finally show ?thesis\n        using c2\n        by blast\n    qed\n  qed\n  moreover\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t \\<and> \n                  \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                  \\<Gamma>\\<turnstile>Call p \\<down> Normal \\<sigma> \\<and>\n                  (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal t) \\<and> c\\<^sub>2 \\<in> redexes c')} \n               c\\<^sub>2\n              {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT [OF hyp_c2]) (fastforce intro: exec.intros)\n  ultimately show ?case\n    by (rule hoaret.Catch)\nqed\n\n\ntext {* To prove a procedure implementation correct it suffices to assume\n       only the procedure specifications of procedures that actually\n       occur during evaluation of the body.  \n    *}\n\nlemma Call_lemma:\n assumes A: \n \"\\<forall>q \\<in> dom \\<Gamma>. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> \n                 {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call q\\<down>Normal s \\<and> ((s,q),(\\<sigma>,p)) \\<in> termi_call_steps \\<Gamma>}\n                 (Call q)\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n assumes pdef: \"p \\<in> dom \\<Gamma>\"\n shows \"\\<And>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>  \n              ({\\<sigma>} \\<inter> {s. s=Z \\<and>\\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>  \n                                 \\<Gamma>\\<turnstile>the (\\<Gamma> p)\\<down>Normal s}) \n                 the (\\<Gamma> p) \n              {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (rule conseqPre)\napply (rule Call_lemma' [OF A])\nusing pdef\napply (fastforce intro: terminates.intros tranclp.r_into_trancl [of \"(step \\<Gamma>)\", OF step.Call] root_in_redexes)\ndone\n\nlemma Call_lemma_switch_Call_body:\n assumes \n call: \"\\<forall>q \\<in> dom \\<Gamma>. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> \n                 {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call q\\<down>Normal s \\<and> ((s,q),(\\<sigma>,p)) \\<in> termi_call_steps \\<Gamma>}\n                 (Call q)\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n assumes p_defined: \"p \\<in> dom \\<Gamma>\"\n shows \"\\<And>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>  \n              ({\\<sigma>} \\<inter> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>  \n                                 \\<Gamma>\\<turnstile>Call p\\<down>Normal s}) \n                 the (\\<Gamma> p) \n              {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (simp only: exec_Call_body' [OF p_defined] noFaultStuck_Call_body' [OF p_defined] terminates_Normal_Call_body [OF p_defined])\napply (rule conseqPre)\napply (rule Call_lemma')\napply (rule call)\nusing p_defined\napply (fastforce intro: terminates.intros tranclp.r_into_trancl [of \"(step \\<Gamma>)\", OF step.Call] \nroot_in_redexes)\ndone\n\nlemma MGT_Call:\n\"\\<forall>p \\<in> dom \\<Gamma>. \\<forall>Z. \n  \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n             \\<Gamma>\\<turnstile>(Call p)\\<down>Normal s}\n           (Call p)\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (intro ballI allI)\napply (rule CallRec' [where Procs=\"dom \\<Gamma>\" and\n    P=\"\\<lambda>p Z. {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call p\\<down>Normal s}\" and\n    Q=\"\\<lambda>p Z. {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t}\" and\n    A=\"\\<lambda>p Z. {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" and\n    r=\"termi_call_steps \\<Gamma>\"\n    ]) \napply    simp\napply   simp\napply  (rule wf_termi_call_steps)\napply (intro ballI allI)\napply simp\napply (rule Call_lemma_switch_Call_body [rule_format, simplified])\napply  (rule hoaret.Asm)\napply  fastforce\napply assumption\ndone\n\n\nlemma CollInt_iff: \"{s. P s} \\<inter> {s. Q s} = {s. P s \\<and> Q s}\"\n  by auto\n\nlemma image_Un_conv: \"f ` (\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. {x p Z}) =  (\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. {f (x p Z)})\"\n  by (auto iff: not_None_eq)\n\n\ntext {* Another proof of @{text MGT_Call}, maybe a little more readable *}\nlemma \n\"\\<forall>p \\<in> dom \\<Gamma>. \\<forall>Z. \n  \\<Gamma>,{} \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n             \\<Gamma>\\<turnstile>(Call p)\\<down>Normal s}\n           (Call p)\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\nproof -\n  {\n    fix p Z \\<sigma>\n    assume defined: \"p \\<in> dom \\<Gamma>\"\n    def Specs == \"(\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. \n            {({s. s=Z \\<and> \n              \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n              \\<Gamma>\\<turnstile>Call p\\<down>Normal s},\n             p,\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})})\"\n    def Specs_wf == \"(\\<lambda>p \\<sigma>. (\\<lambda>(P,q,Q,A). \n                       (P \\<inter> {s. ((s,q),\\<sigma>,p) \\<in> termi_call_steps \\<Gamma>}, q, Q, A)) ` Specs)\"\n    have \"\\<Gamma>,Specs_wf p \\<sigma>\n            \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>({\\<sigma>} \\<inter>\n                 {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                  \\<Gamma>\\<turnstile>the (\\<Gamma> p)\\<down>Normal s}) \n                (the (\\<Gamma> p))\n               {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      apply (rule Call_lemma [rule_format, OF _ defined])\n      apply (rule hoaret.Asm)\n      apply (clarsimp simp add: Specs_wf_def Specs_def image_Un_conv)\n      apply (rule_tac x=q in bexI)\n      apply (rule_tac x=Z in exI)\n      apply (clarsimp simp add: CollInt_iff)\n      apply auto\n      done\n    hence \"\\<Gamma>,Specs_wf p \\<sigma>\n            \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>({\\<sigma>} \\<inter>\n                 {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                  \\<Gamma>\\<turnstile>Call p\\<down>Normal s}) \n                (the (\\<Gamma> p))\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      by (simp only: exec_Call_body' [OF defined] \n                   noFaultStuck_Call_body' [OF defined] \n                  terminates_Normal_Call_body [OF defined])\n  } note bdy=this\n  show ?thesis\n    apply (intro ballI allI)\n    apply (rule hoaret.CallRec [where Specs=\"(\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. \n            {({s. s=Z \\<and> \n              \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n              \\<Gamma>\\<turnstile>Call p\\<down>Normal s},\n             p,\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})})\", \n             OF _ wf_termi_call_steps [of \\<Gamma>] refl])\n    apply fastforce\n    apply clarify\n    apply (rule conjI)\n    apply  fastforce\n    apply (rule allI)\n    apply (simp (no_asm_use) only : Un_empty_left)\n    apply (rule bdy)\n    apply auto\n    done\nqed\n\n\ntheorem hoaret_complete: \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (iprover intro: MGT_implies_complete MGT_lemma [OF MGT_Call])\n\nlemma hoaret_complete': \n  assumes cvalid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (cases \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\")\n  case True\n  hence \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (rule hoaret_complete)\n  thus \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (rule hoaret_augment_context) simp\nnext\n  case False\n  with cvalid\n  show ?thesis\n    by (rule ExFalso)\nqed\n\nsubsection {* And Now: Some Useful Rules *}\n\nsubsubsection {* Modify Return *}\n\nlemma ProcModifyReturn_sound:\n  assumes valid_call: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P call init p return' c Q,A\"\n  assumes valid_modif: \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call p) (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \n  assumes res_modif:\n  \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\n  assumes ret_modifAbr: \n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\n  shows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>call init p return c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from exec\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: exec_call_Normal_elim)\n    fix bdy t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\" \n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> \\<Rightarrow> t\" \n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>(Call p ),Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with res_modif have \"Normal (return' s t') = Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy \n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_call)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\" \n    assume t: \"t = Abrupt (return s t')\"\n    also from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>(Call p),Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_callAbrupt)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy f\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Fault f\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callFault)\n    from cvalidt_postD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Stuck\"  \n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callStuck)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    assume \"\\<Gamma> p = None\" \"t=Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callUndefined)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults)\n  assume P: \"s \\<in> P\"\n  from valid_call ctxt P\n  have call: \"\\<Gamma>\\<turnstile>call init p return' c\\<down> Normal s\"\n    by (rule cvalidt_termD)\n  show \"\\<Gamma>\\<turnstile>call init p return c \\<down> Normal s\"\n  proof (cases \"p \\<in> dom \\<Gamma>\")\n    case True\n    with call obtain bdy where \n      bdy: \"\\<Gamma> p = Some bdy\" and termi_bdy: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\" and \n      termi_c: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>c s t \\<down> Normal (return' s t)\"\n      by cases auto \n    {\n      fix t\n      assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n      hence \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n      proof -\n        from exec_bdy bdy\n        have \"\\<Gamma>\\<turnstile>\\<langle>(Call p ),Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n          by (auto simp add: intro: exec.intros)\n        from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P \n          res_modif\n        have \"return' s t = return s t\"\n          by auto\n        with termi_c exec_bdy show ?thesis by auto\n      qed\n    }\n    with bdy termi_bdy\n    show ?thesis\n      by (iprover intro: terminates_call)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates_callUndefined)\n  qed\nqed\n\nlemma ProcModifyReturn:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes res_modif:\n  \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes ret_modifAbr: \n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:    \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call p) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule hoaret_complete') \napply (rule ProcModifyReturn_sound [where Modif=Modif and ModifAbr=ModifAbr, \n        OF _ _ res_modif ret_modifAbr])\napply (rule hoaret_sound [OF spec])\nusing modifies_spec\napply (blast intro: hoare_sound)\ndone\n\nlemma ProcModifyReturnSameFaults_sound:\n  assumes valid_call: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P call init p return' c Q,A\"\n  assumes valid_modif: \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call p (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \n  assumes res_modif:\n  \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\n  assumes ret_modifAbr: \n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\n  shows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>call init p return c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from exec\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: exec_call_Normal_elim)\n    fix bdy t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\" \n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> \\<Rightarrow> t\" \n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>(Call p) ,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with res_modif have \"Normal (return' s t') = Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy \n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_call)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\" \n    assume t: \"t = Abrupt (return s t')\"\n    also \n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call p ,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_callAbrupt)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy f\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Fault f\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callFault)\n    from cvalidt_postD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Stuck\"  \n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callStuck)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    assume \"\\<Gamma> p = None\" \"t=Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callUndefined)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  assume P: \"s \\<in> P\"\n  from valid_call ctxt P\n  have call: \"\\<Gamma>\\<turnstile>call init p return' c\\<down> Normal s\"\n    by (rule cvalidt_termD)\n  show \"\\<Gamma>\\<turnstile>call init p return c \\<down> Normal s\"\n  proof (cases \"p \\<in> dom \\<Gamma>\")\n    case True\n    with call obtain bdy where \n      bdy: \"\\<Gamma> p = Some bdy\" and termi_bdy: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\" and \n      termi_c: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>c s t \\<down> Normal (return' s t)\"\n      by cases auto \n    {\n      fix t\n      assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n      hence \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n      proof -\n        from exec_bdy bdy\n        have \"\\<Gamma>\\<turnstile>\\<langle>(Call p ),Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n          by (auto simp add: intro: exec.intros)\n        from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P \n          res_modif\n        have \"return' s t = return s t\"\n          by auto\n        with termi_c exec_bdy show ?thesis by auto\n      qed\n    }\n    with bdy termi_bdy\n    show ?thesis\n      by (iprover intro: terminates_call)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates_callUndefined)\n  qed\nqed\n\nlemma ProcModifyReturnSameFaults:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes res_modif:\n  \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes ret_modifAbr: \n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:    \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} (Call p) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule hoaret_complete') \napply (rule ProcModifyReturnSameFaults_sound [where Modif=Modif and ModifAbr=ModifAbr,\n          OF _ _ res_modif ret_modifAbr])\napply (rule hoaret_sound [OF spec])\nusing modifies_spec\napply (blast intro: hoare_sound)\ndone\n\n\nsubsubsection {* DynCall *}\n\n\nlemma dynProcModifyReturn_sound:\nassumes valid_call: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes valid_modif: \n    \"\\<forall>s\\<in>P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call (p s)) (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\nshows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  assume P: \"s \\<in> P\"\n  with valid_modif \n  have valid_modif': \n    \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call (p s)) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n    by blast\n  from exec\n  have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return c,Normal s\\<rangle> \\<Rightarrow> t\"\n    by (cases rule: exec_dynCall_Normal_elim)\n  then show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: exec_call_Normal_elim)\n    fix bdy t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\" \n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> \\<Rightarrow> t\" \n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s),Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: exec.Call)\n    from cvalidD [OF valid_modif' [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with ret_modif have \"Normal (return' s t') = \n      Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_call)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\" \n    assume t: \"t = Abrupt (return s t')\"\n    also from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s) ,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif' [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_callAbrupt)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy f\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Fault f\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callFault)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by blast\n  next\n    fix bdy\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Stuck\"  \n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callStuck)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    fix bdy\n    assume \"\\<Gamma> (p s) = None\" \"t=Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callUndefined)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults)\n  assume P: \"s \\<in> P\"\n  from valid_call ctxt P\n  have \"\\<Gamma>\\<turnstile>dynCall init p return' c\\<down> Normal s\"\n    by (rule cvalidt_termD)\n  hence call: \"\\<Gamma>\\<turnstile>call init (p s) return' c\\<down> Normal s\"\n    by cases\n  have \"\\<Gamma>\\<turnstile>call init (p s) return c \\<down> Normal s\"\n  proof (cases \"p s \\<in> dom \\<Gamma>\")\n    case True\n    with call obtain bdy where \n      bdy: \"\\<Gamma> (p s) = Some bdy\" and termi_bdy: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\" and \n      termi_c: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>c s t \\<down> Normal (return' s t)\"\n      by cases auto \n    {\n      fix t\n      assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n      hence \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n      proof -\n        from exec_bdy bdy\n        have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s),Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n          by (auto simp add: intro: exec.intros)\n        from cvalidD [OF valid_modif [rule_format, of s \"init s\"] ctxt' this] P \n          ret_modif\n        have \"return' s t = return s t\"\n          by auto\n        with termi_c exec_bdy show ?thesis by auto\n      qed\n    }\n    with bdy termi_bdy\n    show ?thesis\n      by (iprover intro: terminates_call)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates_callUndefined)\n  qed\n  thus \"\\<Gamma>\\<turnstile>dynCall init p return c \\<down> Normal s\"\n    by (iprover intro: terminates_dynCall)\nqed\n\nlemma dynProcModifyReturn:\nassumes dyn_call: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s) \n           \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s) \n                             \\<longrightarrow> return' s t = return s t\"\nassumes modif: \n    \"\\<forall>s \\<in> P. \\<forall>\\<sigma>.  \n       \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \nshows \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\napply (rule hoaret_complete')\napply (rule dynProcModifyReturn_sound \n        [where Modif=Modif and ModifAbr=ModifAbr,\n            OF hoaret_sound [OF dyn_call] _ ret_modif ret_modifAbr])\napply (intro ballI allI)\napply (rule hoare_sound [OF modif [rule_format]])\napply assumption\ndone\n\nlemma dynProcModifyReturnSameFaults_sound:\nassumes valid_call: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes valid_modif: \n    \"\\<forall>s\\<in>P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\nshows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  assume P: \"s \\<in> P\"\n  with valid_modif \n  have valid_modif': \n    \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} (Call (p s)) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n    by blast\n  from exec\n  have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return c,Normal s\\<rangle> \\<Rightarrow> t\"\n    by (cases rule: exec_dynCall_Normal_elim)\n  then show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: exec_call_Normal_elim)\n    fix bdy t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\" \n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> \\<Rightarrow> t\" \n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s),Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif' [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with ret_modif have \"Normal (return' s t') = \n      Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_call)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\" \n    assume t: \"t = Abrupt (return s t')\"\n    also from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s)  ,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif' [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_callAbrupt)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy f\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Fault f\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callFault)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Stuck\"  \n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callStuck)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    fix bdy\n    assume \"\\<Gamma> (p s) = None\" \"t=Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callUndefined)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  assume P: \"s \\<in> P\"\n  from valid_call ctxt P\n  have \"\\<Gamma>\\<turnstile>dynCall init p return' c\\<down> Normal s\"\n    by (rule cvalidt_termD)\n  hence call: \"\\<Gamma>\\<turnstile>call init (p s) return' c\\<down> Normal s\"\n    by cases\n  have \"\\<Gamma>\\<turnstile>call init (p s) return c \\<down> Normal s\"\n  proof (cases \"p s \\<in> dom \\<Gamma>\")\n    case True\n    with call obtain bdy where \n      bdy: \"\\<Gamma> (p s) = Some bdy\" and termi_bdy: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\" and \n      termi_c: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>c s t \\<down> Normal (return' s t)\"\n      by cases auto \n    {\n      fix t\n      assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n      hence \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n      proof -\n        from exec_bdy bdy\n        have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s),Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n          by (auto simp add: intro: exec.intros)\n        from cvalidD [OF valid_modif [rule_format, of s \"init s\"] ctxt' this] P \n          ret_modif\n        have \"return' s t = return s t\"\n          by auto\n        with termi_c exec_bdy show ?thesis by auto\n      qed\n    }\n    with bdy termi_bdy\n    show ?thesis\n      by (iprover intro: terminates_call)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates_callUndefined)\n  qed\n  thus \"\\<Gamma>\\<turnstile>dynCall init p return c \\<down> Normal s\"\n    by (iprover intro: terminates_dynCall)\nqed\n\nlemma dynProcModifyReturnSameFaults:\nassumes dyn_call: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\nassumes modif: \n    \"\\<forall>s \\<in> P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \nshows \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\napply (rule hoaret_complete')\napply (rule dynProcModifyReturnSameFaults_sound \n        [where Modif=Modif and ModifAbr=ModifAbr,\n          OF hoaret_sound [OF dyn_call] _ ret_modif ret_modifAbr])\napply (intro ballI allI)\napply (rule hoare_sound [OF modif [rule_format]])\napply assumption\ndone\n\nsubsubsection {* Conjunction of Postcondition *}\n\nlemma PostConjI_sound:\n  assumes valid_Q: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes valid_R: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c R,B\"\n  shows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from valid_Q ctxt exec P t_notin_F have \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    by (rule cvalidt_postD)\n  moreover\n  from valid_R ctxt exec P t_notin_F have \"t \\<in> Normal ` R \\<union> Abrupt ` B\"\n    by (rule cvalidt_postD)\n  ultimately show \"t \\<in> Normal ` (Q \\<inter> R) \\<union> Abrupt ` (A \\<inter> B)\"\n    by blast\nnext \n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  from valid_Q ctxt P\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule cvalidt_termD)\nqed\n\nlemma PostConjI:\n  assumes deriv_Q: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" \n  assumes deriv_R: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c R,B\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\napply (rule hoaret_complete')\napply (rule PostConjI_sound)\napply (rule hoaret_sound [OF deriv_Q])\napply (rule hoaret_sound [OF deriv_R])\ndone\n\n\nlemma Merge_PostConj_sound: \n  assumes validF: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes validG: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/G\\<^esub> P' c R,X\"\n  assumes F_G: \"F \\<subseteq> G\"\n  assumes P_P': \"P \\<subseteq> P'\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> X)\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  with F_G have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/G\\<^esub> P (Call p) Q,A\" \n    by (auto intro: validt_augment_Faults)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\" \n  with P_P' have P': \"s \\<in> P'\"\n    by auto\n  assume t_noFault: \"t \\<notin> Fault ` F\"\n  show \"t \\<in> Normal ` (Q \\<inter> R) \\<union> Abrupt ` (A \\<inter> X)\"\n  proof -\n    from cvalidt_postD [OF validF [rule_format] ctxt exec P t_noFault]\n    have \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\n    moreover from this have \"t \\<notin> Fault ` G\"\n      by auto\n    from cvalidt_postD [OF validG [rule_format] ctxt' exec P' this]\n    have \"t \\<in> Normal ` R \\<union> Abrupt ` X\" .\n    ultimately show ?thesis by auto\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  from validF ctxt P\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule cvalidt_termD)\nqed\n\n\n\nlemma Merge_PostConj: \n  assumes validF: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes validG: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/G\\<^esub> P' c R,X\"\n  assumes F_G: \"F \\<subseteq> G\"\n  assumes P_P': \"P \\<subseteq> P'\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> X)\"\napply (rule hoaret_complete')\napply (rule Merge_PostConj_sound [OF _ _ F_G P_P'])\nusing validF apply (blast intro:hoaret_sound)\nusing validG apply (blast intro:hoaret_sound)\ndone\n\n\nsubsubsection {* Guards and Guarantees *}\n\nlemma SplitGuards_sound:\n  assumes valid_c1: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,A\"\n  assumes valid_c2: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>2 UNIV,UNIV\"\n  assumes c: \"(c\\<^sub>1 \\<inter>\\<^sub>g c\\<^sub>2) = Some c\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def) \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases t)\n    case Normal\n    with inter_guards_exec_noFault [OF c exec]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t\" by simp\n    from valid_c1 ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    case Abrupt\n    with inter_guards_exec_noFault [OF c exec]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t\" by simp\n    from valid_c1 ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    case (Fault f)\n    assume t: \"t=Fault f\"\n    with exec inter_guards_exec_Fault [OF c]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Fault f \\<or> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow> Fault f\"\n      by auto\n    then show ?thesis\n    proof (cases rule: disjE [consumes 1])\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Fault f\"\n      from cvalidt_postD [OF valid_c1 ctxt this P] t t_notin_F\n      show ?thesis\n        by blast\n    next\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow> Fault f\"\n      from cvalidD [OF valid_c2 ctxt' this P] t t_notin_F\n      show ?thesis\n        by blast\n    qed\n  next\n    case Stuck\n    with inter_guards_exec_noFault [OF c exec]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t\" by simp\n    from valid_c1 ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n  proof -\n    from valid_c1 ctxt P\n    have \"\\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s\"\n      by (rule cvalidt_termD)\n    with c show ?thesis\n      by (rule inter_guards_terminates)\n  qed\nqed\n\nlemma SplitGuards: \n  assumes c: \"(c\\<^sub>1 \\<inter>\\<^sub>g c\\<^sub>2) = Some c\" \n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,A\" \n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>2 UNIV,UNIV\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule SplitGuards_sound [OF _ _ c])\napply (rule hoaret_sound [OF deriv_c1])\napply (rule hoare_sound [OF deriv_c2])\ndone\n\nlemma CombineStrip_sound:\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes valid_strip: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/{}\\<^esub> P (strip_guards (-F) c) UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n    by (auto simp add: validt_def)\n  from ctxt have ctxt'': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\" \n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases t)\n    case (Normal t')\n    from cvalidt_postD [OF valid ctxt'' exec P] Normal \n    show ?thesis\n      by auto\n  next\n    case (Abrupt t')\n    from cvalidt_postD [OF valid ctxt'' exec P] Abrupt \n    show ?thesis\n      by auto\n  next\n    case (Fault f)\n    show ?thesis\n    proof (cases \"f \\<in> F\")\n      case True\n      hence \"f \\<notin> -F\" by simp\n      with exec Fault\n      have \"\\<Gamma>\\<turnstile>\\<langle>strip_guards (-F) c,Normal s\\<rangle> \\<Rightarrow> Fault f\" \n        by (auto intro: exec_to_exec_strip_guards_Fault)\n      from cvalidD [OF valid_strip ctxt' this P] Fault\n      have False\n        by auto\n      thus ?thesis ..\n    next\n      case False\n      with cvalidt_postD [OF valid ctxt'' exec P] Fault\n      show ?thesis\n        by auto\n    qed\n  next\n    case Stuck\n    from cvalidt_postD [OF valid ctxt'' exec P] Stuck\n    show ?thesis\n      by auto\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  assume P: \"s \\<in> P\"\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n  proof -\n    from valid ctxt' P\n    show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n      by (rule cvalidt_termD)\n  qed\nqed\n\nlemma CombineStrip:\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes deriv_strip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P (strip_guards (-F) c) UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule CombineStrip_sound)\napply  (iprover intro: hoaret_sound [OF deriv])\napply (iprover intro: hoare_sound [OF deriv_strip])\ndone\n\nlemma GuardsFlip_sound:\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes validFlip: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/-F\\<^esub> P c UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  from ctxt have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  from ctxt have ctxtFlip: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^bsub>/-F\\<^esub> P (Call p) Q,A\" \n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\" \n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases t)\n    case (Normal t')\n    from cvalidt_postD [OF valid ctxt' exec P] Normal \n    show ?thesis\n      by auto\n  next\n    case (Abrupt t')\n    from cvalidt_postD [OF valid ctxt' exec P] Abrupt \n    show ?thesis\n      by auto\n  next\n    case (Fault f)\n    show ?thesis\n    proof (cases \"f \\<in> F\")\n      case True\n      hence \"f \\<notin> -F\" by simp\n      with cvalidD [OF validFlip ctxtFlip exec P] Fault\n      have False\n        by auto\n      thus ?thesis ..\n    next\n      case False\n      with cvalidt_postD [OF valid ctxt' exec P] Fault\n      show ?thesis\n        by auto\n    qed\n  next\n    case Stuck\n    from cvalidt_postD [OF valid ctxt' exec P] Stuck\n    show ?thesis\n      by auto\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  assume P: \"s \\<in> P\"\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n  proof -\n    from valid ctxt' P\n    show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n      by (rule cvalidt_termD)\n  qed\nqed\n\n\nlemma GuardsFlip: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes derivFlip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/-F\\<^esub> P c UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule GuardsFlip_sound)\napply  (iprover intro: hoaret_sound [OF deriv])\napply (iprover intro: hoare_sound [OF derivFlip])\ndone\n\nlemma MarkGuardsI_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c,Normal s\\<rangle> \\<Rightarrow> t\" \n  from exec_mark_guards_to_exec [OF exec] obtain t' where\n    exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t'\" and\n    t'_noFault: \"\\<not> isFault t' \\<longrightarrow> t' = t\"\n    by blast\n  assume P: \"s \\<in> P\" \n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof -\n    from cvalidt_postD [OF valid [rule_format] ctxt exec_c P]\n    have \"t' \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by blast\n    with t'_noFault\n    show ?thesis\n      by auto\n  qed\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>mark_guards f c \\<down> Normal s\"\n    by (rule terminates_to_terminates_mark_guards)\nqed\n\nlemma MarkGuardsI: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\"\napply (rule hoaret_complete')\napply (rule MarkGuardsI_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\n\nlemma MarkGuardsD_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\" \n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\" \n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases \"isFault t\")\n    case True\n    with exec_to_exec_mark_guards_Fault exec\n    obtain f' where \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c,Normal s\\<rangle> \\<Rightarrow> Fault f'\"\n      by (fastforce elim: isFaultE)\n    from cvalidt_postD [OF valid [rule_format] ctxt this P]\n    have False\n      by auto\n    thus ?thesis ..\n  next\n    case False\n    from exec_to_exec_mark_guards [OF exec False]\n    obtain f' where \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by auto\n    from cvalidt_postD [OF valid [rule_format] ctxt this P]\n    show ?thesis\n      by auto\n  qed\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>mark_guards f c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule terminates_mark_guards_to_terminates)\nqed\n\nlemma MarkGuardsD: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule MarkGuardsD_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nlemma MergeGuardsI_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P merge_guards c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume exec_merge: \"\\<Gamma>\\<turnstile>\\<langle>merge_guards c,Normal s\\<rangle> \\<Rightarrow> t\"\n  from exec_merge_guards_to_exec [OF exec_merge] \n  have exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" .\n  assume P: \"s \\<in> P\" \n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec P t_notin_F]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>merge_guards c \\<down> Normal s\"\n    by (rule terminates_to_terminates_merge_guards)\nqed\n\nlemma MergeGuardsI: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P merge_guards c Q,A\"\napply (rule hoaret_complete')\napply (rule MergeGuardsI_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nlemma MergeGuardsD_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P merge_guards c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  from exec_to_exec_merge_guards [OF exec] \n  have exec_merge: \"\\<Gamma>\\<turnstile>\\<langle>merge_guards c,Normal s\\<rangle> \\<Rightarrow> t\".\n  assume P: \"s \\<in> P\" \n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec_merge P t_notin_F]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>merge_guards c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule terminates_merge_guards_to_terminates)\nqed\n\n\n\n\nlemma SubsetGuards_sound: \n  assumes c_c': \"c \\<subseteq>\\<^sub>g c'\"\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c' Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  from exec_to_exec_subseteq_guards [OF c_c' exec] obtain t' where\n    exec_c': \"\\<Gamma>\\<turnstile>\\<langle>c',Normal s\\<rangle> \\<Rightarrow> t'\" and\n    t'_noFault: \"\\<not> isFault t' \\<longrightarrow> t' = t\"\n    by blast\n  assume P: \"s \\<in> P\" \n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec_c' P] t'_noFault t_noFault\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    by auto\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have termi_c': \"\\<Gamma>\\<turnstile>c' \\<down> Normal s\".\n  from cvalidt_postD [OF valid ctxt _ P]\n  have noFault_c': \"\\<Gamma>\\<turnstile>\\<langle>c',Normal s\\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\"\n    by (auto simp add: final_notin_def)\n  from termi_c' c_c' noFault_c'\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule terminates_fewer_guards)\nqed\n\nlemma SubsetGuards: \n  assumes c_c': \"c \\<subseteq>\\<^sub>g c'\"\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c' Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule SubsetGuards_sound [OF c_c'])\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nlemma NormalizeD_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  hence exec_norm: \"\\<Gamma>\\<turnstile>\\<langle>normalize c,Normal s\\<rangle> \\<Rightarrow> t\" \n    by (rule exec_to_exec_normalize)\n  assume P: \"s \\<in> P\" \n  assume noFault: \"t \\<notin> Fault ` F\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec_norm P noFault]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>normalize c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule terminates_normalize_to_terminates)\nqed\n\nlemma NormalizeD: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule NormalizeD_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nlemma NormalizeI_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume \"\\<Gamma>\\<turnstile>\\<langle>normalize c,Normal s\\<rangle> \\<Rightarrow> t\" \n  hence exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n    by (rule exec_normalize_to_exec)\n  assume P: \"s \\<in> P\" \n  assume noFault: \"t \\<notin> Fault ` F\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec P noFault]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile> c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>normalize c \\<down> Normal s\"\n    by (rule terminates_to_terminates_normalize)\nqed\n\nlemma NormalizeI: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\napply (rule hoaret_complete')\napply (rule NormalizeI_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nsubsubsection {* Restricting the Procedure Environment *}\n\nlemma validt_restrict_to_validt:\nassumes validt_c: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nshows \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from validt_c\n  have valid_c: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\" by (simp add: validt_def)\n  hence \"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\" by (rule valid_restrict_to_valid)\n  moreover\n  {\n    fix s\n    assume P: \"s \\<in> P\"\n    have \"\\<Gamma>\\<turnstile>c\\<down>Normal s\"\n    proof -\n      from P validt_c have \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>c\\<down>Normal s\"\n        by (auto simp add: validt_def)\n      moreover\n      from P valid_c\n      have \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>{Stuck}\"\n        by (auto simp add: valid_def  final_notin_def)\n      ultimately show ?thesis\n        by (rule terminates_restrict_to_terminates)\n    qed\n   }\n   ultimately show ?thesis\n     by (auto simp add: validt_def)\nqed\n\n\nlemma augment_procs:\nassumes deriv_c: \"\\<Gamma>|\\<^bsub>M\\<^esub>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nshows \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule hoaret_complete)\n  apply (rule validt_restrict_to_validt)\n  apply (insert hoaret_sound [OF deriv_c])\n  by (simp add: cvalidt_def)\n\nsubsubsection {* Miscellaneous *}\n\nlemma augment_Faults:\nassumes deriv_c: \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nassumes F: \"F \\<subseteq> F'\"\nshows \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F'\\<^esub> P c Q,A\"\n  apply (rule hoaret_complete)\n  apply (rule validt_augment_Faults [OF _ F])\n  apply (insert hoaret_sound [OF deriv_c])\n  by (simp add: cvalidt_def)\n\nlemma TerminationPartial_sound:\n  assumes \"termination\": \"\\<forall>s \\<in> P. \\<Gamma>\\<turnstile>c\\<down>Normal s\"\n  assumes partial_corr: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nusing \"termination\" partial_corr \nby (auto simp add: cvalidt_def validt_def cvalid_def)\n\nlemma TerminationPartial:\n  assumes partial_deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes \"termination\": \"\\<forall>s \\<in> P. \\<Gamma>\\<turnstile>c\\<down>Normal s\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule hoaret_complete')\n  apply (rule TerminationPartial_sound [OF \"termination\"])\n  apply (rule hoare_sound [OF partial_deriv])\n  done\n\nlemma TerminationPartialStrip:\n  assumes partial_deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes \"termination\": \"\\<forall>s \\<in> P. strip F' \\<Gamma>\\<turnstile>strip_guards F' c\\<down>Normal s\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from \"termination\" have \"\\<forall>s \\<in> P. \\<Gamma>\\<turnstile>c\\<down>Normal s\"\n    by (auto intro: terminates_strip_guards_to_terminates \n      terminates_strip_to_terminates)\n  with partial_deriv\n  show ?thesis\n    by (rule TerminationPartial)\nqed\n\nlemma SplitTotalPartial:\n  assumes termi: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q',A'\"\n  assumes part: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from hoaret_sound [OF termi] hoare_sound [OF part]\n  have \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (fastforce simp add: cvalidt_def validt_def cvalid_def valid_def)\n  thus ?thesis\n    by (rule hoaret_complete')\nqed\n   \nlemma SplitTotalPartial':\n  assumes termi: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/UNIV\\<^esub> P c Q',A'\"\n  assumes part: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from hoaret_sound [OF termi] hoare_sound [OF part]\n  have \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (fastforce simp add: cvalidt_def validt_def cvalid_def valid_def)\n  thus ?thesis\n    by (rule hoaret_complete')\nqed\n \nend\n", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/c-parser/Simpl/HoareTotalProps.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5467381667555713, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.28190908746506377}}
{"text": "theory Simple_Network_Language_Impl\n  imports\n    Simple_Network_Language\n    TA_Impl.Normalized_Zone_Semantics_Impl_Refine\n    \"HOL-Library.IArray\" \"HOL-Library.AList\"\n    TA_Library.More_Methods\n    TA_Library.Bijective_Embedding\n    TA_Impl_Misc2\n    TA_More2\n    TA_Equivalences\n    \"HOL-Eisbach.Eisbach_Tools\"\n    TA_Library.Syntax_Bundles\nbegin\n\nunbundle no_library_syntax\n\nparagraph \\<open>Default maps\\<close>\n\ndefinition default_map_of :: \"'b \\<Rightarrow> ('a \\<times> 'b) list \\<Rightarrow> 'a \\<Rightarrow> 'b\" where\n  \"default_map_of a xs \\<equiv> FinFun.map_default a (map_of xs)\"\n\nlemma default_map_of_alt_def:\n  \"default_map_of a xs x = (if x \\<in> dom (map_of xs) then the (map_of xs x) else a)\"\n  unfolding default_map_of_def map_default_def by (auto split: option.split_asm)\n\nlemma range_default_map_of:\n  \"range (default_map_of x xs) \\<subseteq> snd ` set xs \\<union> {x}\"\n  unfolding default_map_of_def map_default_def\n  by (auto split: option.split_asm) (meson img_snd map_of_SomeD)\n\nlemma finite_range_default_map_of:\n  \"finite (range (default_map_of x m))\"\nproof -\n  have \"range (default_map_of x m) \\<subseteq> the ` range (map_of m) \\<union> {x}\"\n    unfolding default_map_of_def FinFun.map_default_def\n    by (auto split: option.splits) (metis image_eqI option.sel rangeI)\n  also have \"finite \\<dots>\"\n    by (blast intro: finite_range_map_of)\n  finally show ?thesis .\nqed\n\nlemma map_index'_inj:\n  \"L = L'\"\n  if \"length L = length L'\" \"map_index' n f L = map_index' n g L'\" \"set L \\<subseteq> S\" \"set L' \\<subseteq> T\"\n     \"\\<forall> i < length L + n. \\<forall> x \\<in> S. \\<forall>y \\<in> T. f i x = g i y \\<longrightarrow> x = y\"\n  using that\nproof (induction \"length L\" arbitrary: L L' n)\n  case 0\n  then show ?case\n    by simp\nnext\n  case (Suc x)\n  from Suc.prems obtain a b L1 L1' where *:\n    \"length L1 = x\" \"length L1' = x\" \"L = a # L1\" \"L' = b # L1'\"\n    by (smt Suc.hyps(2) length_Suc_conv)\n  show ?case\n    unfolding \\<open>L = _\\<close> \\<open>L' = _\\<close>\n    apply (clarsimp, rule conjI)\n    subgoal\n      by (smt *(3,4) Suc.hyps(2) Suc.prems Suc_less_eq add_Suc_shift less_add_Suc2 list.set_intros(1) list_tail_coinc map_index'.simps(2) set_mp)\n    subgoal\n      apply (rule Suc.hyps)\n      using Suc.prems * by auto\n    done\nqed\n\nlemma map_index_inj:\n  \"L = L'\"\n  if \"map_index f L = map_index g L'\" \"set L \\<subseteq> S\" \"set L' \\<subseteq> T\"\n     \"\\<forall> i < length L. \\<forall> x \\<in> S. \\<forall>y \\<in> T. f i x = g i y \\<longrightarrow> x = y\"\n  using that by - (rule map_index'_inj, auto dest: map_index_eq_imp_length_eq)\n\nlemma map_index_inj1:\n  \"L = L'\"\n  if \"map_index f L = map_index g L'\"\n     \"\\<forall> i < length L. f i (L ! i) = g i (L' ! i) \\<longrightarrow> L ! i = L' ! i\"\nproof (intros add: nth_equalityI)\n  from that(1) show \\<open>length L = length L'\\<close>\n    by (rule map_index_eq_imp_length_eq)\n  fix i :: \\<open>nat\\<close>\n  assume \\<open>i < length L\\<close>\n  with that have \"map_index f L ! i = map_index g L' ! i\"\n    by auto\n  with \\<open>i < length L\\<close> \\<open>length L = length L'\\<close> have \"f i (L ! i) = g i (L' ! i)\"\n    by simp\n  with \\<open>i < length L\\<close> that(2) show \\<open>L ! i = L' ! i\\<close>\n    by simp\nqed\n\nlemma map_index_update:\n  \"map_index f (xs[i := a]) = (map_index f xs)[i := f i a]\"\n  by (rule nth_equalityI) (auto simp: nth_list_update')\n\nlemma map_trans_broad_aux1:\n  \"map_index map_loc (fold (\\<lambda>p L. L[p := ls' p]) ps L) =\n  fold (\\<lambda>p L. L[p := map_loc p (ls' p)]) ps (map_index map_loc L)\"\n  by (induction ps arbitrary: L) (auto simp: map_index_update)\n\nlemma InD2:\n  fixes map_action\n  assumes \"inj map_action\" \"In (map_action a) = map_act map_action a'\"\n  shows \"a' = In a\"\n  using assms(2) by (cases a')  (auto simp: injD[OF assms(1)])\n\nlemma OutD2:\n  fixes map_action\n  assumes \"inj map_action\" \"Out (map_action a) = map_act map_action a'\"\n  shows \"a' = Out a\"\n  using assms(2) by (cases a')  (auto simp: injD[OF assms(1)])\n\nlemma (in Prod_TA_Defs) trans_broad_alt_def:\n  \"trans_broad =\n    {((L, s), g @ concat (map gs ps), Broad a, r @ concat (map rs ps), (L', s'')) |\n    L s L' s' s'' a p l b g f r l' bs gs fs rs ls' ps.\n      a \\<in> broadcast  \\<and>\n      (l, b, g, Out a, f, r, l') \\<in> trans (N p) \\<and>\n      (\\<forall>p \\<in> set ps. (L ! p, bs p, gs p, In a, fs p, rs p, ls' p) \\<in> trans (N p)) \\<and>\n      (l \\<in> committed (N p) \\<or> (\\<exists>p \\<in> set ps. L ! p \\<in> committed (N p))\n      \\<or> (\\<forall>p < n_ps. L ! p \\<notin> committed (N p))) \\<and>\n      (\\<forall>q < n_ps. q \\<notin> set ps \\<and> p \\<noteq> q \\<longrightarrow>\n        \\<not> (\\<exists>b g f r l'. (L!q, b, g, In a, f, r, l') \\<in> trans (N q) \\<and> check_bexp s b True)) \\<and>\n      L!p = l \\<and>\n      p < length L \\<and> set ps \\<subseteq> {0..<n_ps} \\<and> p \\<notin> set ps \\<and> distinct ps \\<and> sorted ps \\<and>\n      check_bexp s b True \\<and> (\\<forall>p \\<in> set ps. check_bexp s (bs p) True) \\<and>\n      L' = (fold (\\<lambda>p L . L[p := ls' p]) ps L)[p := l'] \\<and>\n      is_upd s f s' \\<and> is_upds s' (map fs ps) s'' \\<and>\n      L \\<in> states \\<and> bounded bounds s \\<and> bounded bounds s'' \\<and>\n      (\\<forall>p. p\\<notin>set ps \\<longrightarrow> bs p = bexp.true) \\<and> (\\<forall>p. p\\<notin>set ps \\<longrightarrow> gs p = []) \\<and>\n      (\\<forall>p. p\\<notin>set ps \\<longrightarrow> fs p = []) \\<and> (\\<forall>p. p\\<notin>set ps \\<longrightarrow> rs p = [])\n    }\"\n  unfolding trans_broad_def\nproof ((intro Collect_eqI iffI; elims add: more_elims), goal_cases)\n  case prems: (1 x L s L' s' s'' a p l b g f r l' bs gs fs rs ls' ps)\n  let ?f = \"\\<lambda>gs p. if p \\<in> set ps then gs p else []\"\n  let ?bs = \"\\<lambda>p. if p \\<in> set ps then bs p else bexp.true\"\n  let ?gs = \"?f gs\" let ?fs = \"?f fs\" let ?rs = \"?f rs\"\n  have [simp]: \"map gs ps = map ?gs ps\" \"map rs ps = map ?rs ps\" \"map fs ps = map ?fs ps\"\n    by (simp cong: map_cong)+\n  with prems show ?case\n    by (inst_existentials L s L' s' s'' a p l b g f r l' ?bs ?gs ?fs ?rs ls' ps; (assumption | simp))\nnext\n  case (2 x L s L' s' s'' a p l b g f r l' bs gs fs rs ls' ps)\n  then show ?case\n    by blast\nqed\n\n(* XXX Move to distribution *)\ntext \\<open>Stronger version of @{thm Map.map_of_mapk_SomeI}\\<close>\ntheorem map_of_mapk_SomeI':\n  assumes \"inj_on f (fst ` set t)\"\n    and \"map_of t k = Some x\"\n  shows \"map_of (map (\\<lambda>(k, y). (f k, g y)) t) (f k) = Some (g x)\"\n  using assms\n  apply (induction t)\n   apply (auto split: if_split_asm)\n  apply (metis DiffI imageI img_fst map_of_SomeD singletonD)\n  done\n\ntheorem map_of_mapk_SomeI:\n  assumes \"inj f\"\n    and \"map_of t k = Some x\"\n  shows \"map_of (map (\\<lambda>(k, y). (f k, g y)) t) (f k) = Some (g x)\"\n  using assms by - (rule map_of_mapk_SomeI', erule inj_on_subset, auto)\n\n\ndefinition\n  \"conv_automaton \\<equiv> \\<lambda>(committed, urgent, trans, inv).\n    (committed,\n     urgent,\n     map (\\<lambda>(l, b, g, a, f, r, l'). (l, b, conv_cc g, a, f, r, l')) trans,\n     map (\\<lambda>(s, cc). (s, conv_cc cc)) inv)\"\n\ndefinition\n  \"automaton_of \\<equiv>\n    \\<lambda>(committed, urgent, trans, inv). (set committed, set urgent, set trans, default_map_of [] inv)\"\n\nlocale Simple_Network_Impl_Defs =\n  fixes automata ::\n    \"('s list \\<times> 's list \\<times> ('a act, 's, 'c, 't, 'x, int) transition list\n      \\<times> ('s \\<times> ('c, 't) cconstraint) list) list\"\n    and broadcast :: \"'a list\"\n    and bounds' :: \"('x \\<times> (int \\<times> int)) list\"\nbegin\n\ndefinition \\<comment>\\<open>Number of state variables\\<close>\n  \"n_vs = length bounds'\"\n\ndefinition\n  \"B x \\<equiv> if x \\<in> dom (map_of bounds') then the (map_of bounds' x) else (0, 0)\"\n\nsublocale Prod_TA_Defs\n  \"(set broadcast, map automaton_of automata, map_of bounds')\" .\n\nlemma L_len[intro, dest]:\n  \"length L = n_ps\" if \"L \\<in> states\"\n  using that unfolding states_def by simp\n\nend\n\n(*\nlocale Simple_Network_Impl =\n  Simple_Network_Impl_Defs automata broadcast bounds\n  for\n    automata ::\n    \"('s list \\<times> ('a act, 's, 'c, int, 'x, int) transition list\n      \\<times> ('s \\<times> ('c, int) cconstraint) list) list\"\n  and broadcast bounds\n*)\n\nlocale Simple_Network_Impl =\n  fixes automata ::\n    \"('s list \\<times> 's list \\<times> ('a act, 's, 'c, int, 'x, int) transition list\n      \\<times> ('s \\<times> ('c, int) cconstraint) list) list\"\n    and broadcast :: \"'a list\"\n    and bounds' :: \"('x \\<times> (int \\<times> int)) list\"\nbegin\n\nsublocale Simple_Network_Impl_Defs automata broadcast bounds' .\n\nend\n\n\nparagraph \\<open>Mapping through the product construction\\<close>\n\nlemma f_the_inv_f:\n  \"f (the_inv f x) = x\" if \"inj f\" \"x \\<in> range f\"\n  using that by (auto simp: the_inv_f_f)\n\ncontext Simple_Network_Impl\nbegin\n\nlemma N_eq:\n  \\<open>N i = automaton_of (automata ! i)\\<close> if \\<open>i < n_ps\\<close>\n  using that unfolding N_def n_ps_def fst_conv snd_conv by (intro nth_map; simp)\n\n(* XXX Remove? *)\nlemma covn_N_eq:\n  \\<open>N i = automaton_of (automata ! i)\\<close> if \\<open>i < n_ps\\<close>\n  using that unfolding N_def n_ps_def fst_conv snd_conv by (intro nth_map; simp)\n\nend\n\ninductive_cases check_bexp_elims:\n  \"check_bexp s bexp.true bv\"\n  \"check_bexp s (bexp.not b) bv\"\n  \"check_bexp s (bexp.and b1 b2) bv\"\n  \"check_bexp s (bexp.or b1 b2) bv\"\n  \"check_bexp s (bexp.imply b1 b2) bv\"\n  \"check_bexp s (le i x) bv\"\n  \"check_bexp s (lt i x) bv\"\n  \"check_bexp s (ge i x) bv\"\n  \"check_bexp s (eq i x) bv\"\n  \"check_bexp s (gt i x) bv\"\n\ninductive_cases is_val_elims:\n  \"is_val s (const c) d\"\n  \"is_val s (var x)   v\"\n  \"is_val s (if_then_else b e1 e2) v\"\n  \"is_val s (binop f e1 e2) v\"\n  \"is_val s (unop f e) v\"\n\nmethod fprem =\n  (match premises in R: _ \\<Rightarrow> \\<open>rule R[elim_format]\\<close>, assumption)\n\ncontext Simple_Network_Impl\nbegin\n\nparagraph \\<open>Conversion from integers to reals commutes with product construction.\\<close>\n\nsublocale conv: Prod_TA_Defs\n  \"(set broadcast, map (Simple_Network_Language.conv_A o automaton_of) automata, map_of bounds')\" .\n\nlemma (in -) conv_ac_inj:\n  \"ac = ac'\" if \"conv_ac ac = conv_ac ac'\"\n  using that by (cases ac; cases ac'; auto)\n\nlemma (in -) conv_cc_inj:\n  \"cc = cc'\" if \"conv_cc cc = conv_cc cc'\"\n  using that by (subst (asm) inj_map_eq_map) (auto simp add: conv_ac_inj intro: injI)\n\ncontext\nbegin\n\nlemma conv_alt_def:\n  \"conv (set broadcast, map automaton_of automata, map_of bounds') =\n    (set broadcast, map (Simple_Network_Language.conv_A o automaton_of) automata, map_of bounds')\"\n  unfolding conv_def by simp\n\nprivate lemma 2:\n  \"Simple_Network_Language.conv_A o automaton_of = (\\<lambda>(committed, urgent, trans, inv).\n    (set committed,\n     set urgent,\n     set (map Simple_Network_Language.conv_t trans),\n     default_map_of [] (map (\\<lambda> (l, g). (l, conv_cc g)) inv)))\"\n  apply (rule ext)\n  apply clarsimp\n  unfolding Simple_Network_Language.conv_A_def automaton_of_def\n  apply (clarsimp split: prod.split)\n  unfolding default_map_of_def\n  unfolding FinFun.map_default_def\n  apply (rule ext)\n  subgoal for xs a\n    by (induction xs) auto\n  done\n\nlemma conv_n_ps_eq:\n  \"conv.n_ps = n_ps\"\n  by (simp add: Prod_TA_Defs.n_ps_def)\n\nlemma conv_N_eq:\n  \"conv.N i = Simple_Network_Language.conv_A (N i)\" if \"i < n_ps\"\n  using that unfolding n_ps_def Prod_TA_Defs.N_def fst_conv snd_conv by (subst nth_map | simp)+\n\nprivate lemma 5:\n  \"inv (conv.N i) = conv_cc o (inv (N i))\" if \"i < n_ps\"\n  unfolding conv_N_eq[OF that] unfolding Simple_Network_Language.conv_A_def\n  by (simp split: prod.split add: inv_def)\n\nlemma trans_conv_N_eq:\n  \"trans (conv.N i) = Simple_Network_Language.conv_t ` (trans (N i))\"  if \"i < n_ps\"\n  unfolding conv_N_eq[OF that] unfolding Simple_Network_Language.conv_A_def\n  by (simp split: prod.split add: trans_def)\n\nprivate lemma 71:\n  \"(l, b, conv_cc g, a, r, u, l')\\<in>Simple_Network_Language.trans (conv.N i)\"\n  if \"(l, b, g, a, r, u, l')\\<in>Simple_Network_Language.trans (N i)\" \"i < n_ps\"\n  using that by (force simp add: trans_conv_N_eq Simple_Network_Language.conv_t_def)\n\nprivate lemma 72:\n  \"(l, b, conv_cc g, a, r, u, l')\\<in>Simple_Network_Language.trans (conv.N i)\n\\<longleftrightarrow> (l, b, g, a, r, u, l')\\<in>Simple_Network_Language.trans (N i)\" if \"i < n_ps\"\n  by (auto simp: trans_conv_N_eq[OF that] Simple_Network_Language.conv_t_def\n           dest: conv_cc_inj intro: image_eqI[rotated])\n\nprivate lemma 73:\n  \"\\<exists>g'. g = conv_cc g' \\<and> (l, b, g', a, r, u, l')\\<in>Simple_Network_Language.trans (N i)\"\n  if \"(l, b, g, a, r, u, l')\\<in>Simple_Network_Language.trans (conv.N i)\" \"i < n_ps\"\n  using that by (force simp: trans_conv_N_eq Simple_Network_Language.conv_t_def)\n\nlemma conv_bounds[simp]:\n  \"conv.bounds = bounds\"\n  unfolding conv.bounds_def bounds_def by simp\n\nlemma conv_states[simp]:\n  \"conv.states = states\"\n  unfolding conv.states_def states_def conv_n_ps_eq\n  by (auto simp add: trans_conv_N_eq Simple_Network_Language.conv_t_def) (fastforce, force)\n\nprivate lemma 9:\n  \"committed (conv.N p) = committed (N p)\" if \\<open>p < n_ps\\<close>\n  unfolding conv_N_eq[OF that] unfolding Simple_Network_Language.conv_A_def\n  by (simp split: prod.split add: committed_def)\n\nprivate lemma 10:\n  \"conv.broadcast = set broadcast\"\n  unfolding conv.broadcast_def by simp\n\nlemma conv_trans_int:\n  \"conv.trans_int = (\\<lambda>(l, g, a, r, l'). (l, map conv_ac g, a, r, l')) ` trans_int\"\n  unfolding conv.trans_int_def trans_int_def\n  supply [simp] = L_len\n  apply standard\n  subgoal\n    by (clarsimp simp: Simple_Network_Language.conv_t_def conv_n_ps_eq trans_conv_N_eq 9)\n      (intros add: more_intros, solve_triv+)\n  subgoal\n    by (rule subsetI,\n        clarsimp simp: Simple_Network_Language.conv_t_def conv_n_ps_eq trans_conv_N_eq 9[symmetric])\n      ((drule (1) 71)+, intros add: more_intros, solve_triv+)\n  done\n\nlemma conv_trans_bin:\n  \"conv.trans_bin = (\\<lambda>(l, g, a, r, l'). (l, map conv_ac g, a, r, l')) ` trans_bin\"\n  unfolding conv.trans_bin_def trans_bin_def 10 broadcast_def\n  supply [simp] = L_len\n  apply standard\n  subgoal\n    by (clarsimp simp add: Simple_Network_Language.conv_t_def conv_n_ps_eq trans_conv_N_eq 9)\n      (intros add: more_intros, solve_triv+)\n  subgoal\n    by (rule subsetI,\n        clarsimp simp: Simple_Network_Language.conv_t_def conv_n_ps_eq trans_conv_N_eq 9[symmetric])\n      ((drule (1) 71)+, intros add: more_intros, solve_triv+)\n  done\n\nlemma n_ps_rangeD:\n  \"p < n_ps\" if \"p \\<in> set ps\" \"set ps \\<subseteq> {0..<n_ps}\"\n  using that by auto\n\nlemma maximalD:\n  \"(\\<forall>g f r l'.\n       (L ! q, b, g, In a', f, r, l')\n       \\<notin> (\\<lambda>(l, b, g, a, f, r, l').\n              (l, b, map conv_ac g, a, f, r, l')) ` trans (N q)) \\<or> \\<not> check_bexp s b True\" if\n  \"\\<forall>q<n_ps. q \\<notin> set ps \\<and> p \\<noteq> q \\<longrightarrow> (\\<forall>b. (\\<forall>g f r l'.\n     (L ! q, b, g, In a', f, r, l') \\<notin> trans (N q)) \\<or> \\<not> check_bexp s b True)\"\n  \"q<n_ps\" \"q \\<notin> set ps\" \"p \\<noteq> q\"\n  for b ps p q L a' s using that by fastforce\n\nlemma conv_trans_broad:\n  \"conv.trans_broad = (\\<lambda>(l, g, a, r, l'). (l, map conv_ac g, a, r, l')) ` trans_broad\"\n  unfolding conv.trans_broad_alt_def trans_broad_alt_def\n  apply standard\n   supply [simp] = L_len\n  subgoal\n  proof -\n    have **: \"\\<exists> gs'. gs = conv_cc o gs' \\<and>\n          (\\<forall>p\\<in>set ps.(L ! p, bs p, gs' p, In a, fs p, rs p, ls' p) \\<in> trans (N p))\"\n      if assms:\n        \"\\<forall>p\\<in>set ps. (L ! p, bs p, gs p, In a, fs p, rs p, ls' p) \\<in> trans (conv.N p)\"\n        \"set ps \\<subseteq> {0..<n_ps}\" \"\\<forall>p. p \\<notin> set ps \\<longrightarrow> gs p = []\"\n      for L ps bs gs a fs rs ls'\n    proof -\n      have *: \"gs p = conv_cc (Hilbert_Choice.inv conv_cc (gs p))\" if \"p \\<in> set ps\" for p\n        using that assms by (auto 4 3 simp: f_inv_into_f dest!: 73)\n      show ?thesis\n        apply (inst_existentials \"Hilbert_Choice.inv conv_cc o gs\")\n        subgoal\n          apply (rule ext)\n          subgoal for p\n            apply (cases \"p \\<in> set ps\")\n            subgoal\n              by (simp, erule *)\n            subgoal\n              using that(3) by (auto intro: injI inv_f_eq conv_ac_inj)\n            done\n          done\n        subgoal\n          using that * by (force dest!: conv_cc_inj 73)\n        done\n    qed\n    have *: \"set ps \\<subseteq> {0..<n_ps} \\<longleftrightarrow> (\\<forall>p \\<in> set ps. p < n_ps)\" for ps\n      by auto\n    have maximalI:\n      \"\\<forall>q<n_ps. q \\<notin> set ps \\<and> p \\<noteq> q \\<longrightarrow> (\\<forall>b. (\\<forall>g f r l'.\n         (L ! q, b, g, In a', f, r, l') \\<notin> trans (N q)) \\<or> \\<not> check_bexp s b True)\" if\n      \"\\<forall>q<n_ps. q \\<notin> set ps \\<and> p \\<noteq> q \\<longrightarrow> (\\<forall>b. (\\<forall>g f r l'.\n         (L ! q, b, g, In a', f, r, l') \\<notin> trans (conv.N q)) \\<or> \\<not> check_bexp s b True)\"\n    for ps p L a' s\n      using that by (blast dest!: 71)\n    show ?thesis\n      apply (rule subsetI)\n      apply (clarsimp simp add: conv_n_ps_eq 9 10 broadcast_def split: prod.split_asm)\n      apply (drule (2) **)\n      apply (drule (1) 73)+\n      apply elims\n      apply (intro image_eqI[rotated] CollectI exI conjI)\n                          apply solve_triv+\n      subgoal premises prems \\<comment>\\<open>Commited\\<close>\n        using prems(2) \\<open>set _ \\<subseteq> {0..<n_ps}\\<close> by (auto dest: n_ps_rangeD simp: 9)\n                        apply (erule maximalI; fail) \\<comment>\\<open>Maximal set\\<close>\n      by solve_triv+ (simp split: prod.split add: map_concat)\n  qed\n  subgoal\n    apply (rule subsetI)\n    apply (clarsimp simp:\n        Simple_Network_Language.conv_t_def\n        conv_n_ps_eq trans_conv_N_eq 9[symmetric] 10 broadcast_def map_concat)\n    apply (drule (1) 71)\n    apply (intros add: more_intros)\n                        apply solve_triv+\n                    apply (subst comp_def; rule 71; fast elim: n_ps_rangeD; fail)\n    subgoal premises prems for L s s' s'' aj p g f r l' gs fs rs ls' ps\n      using prems(3,6) 9 by fastforce\n                  apply (erule maximalD)\n                    apply (solve_triv | blast)+\n    done\n  done\n\nlemma conv_prod_ta:\n  \"conv.prod_ta = Normalized_Zone_Semantics_Impl.conv_A prod_ta\"\n  unfolding conv.prod_ta_def prod_ta_def\n  unfolding conv.trans_prod_def trans_prod_def\n  unfolding conv.prod_inv_def prod_inv_def\n  unfolding conv.N_def N_def conv_n_ps_eq\n  unfolding conv_A_def\n  apply simp\n  apply (rule conjI)\n  subgoal\n    unfolding image_Un\n    by ((fo_rule arg_cong2)+; rule conv_trans_int conv_trans_bin conv_trans_broad)\n  subgoal \\<comment>\\<open>Invariant\\<close>\n    unfolding conv.N_def N_def\n    by (rule ext) (auto simp: 5 map_concat intro!: map_cong arg_cong[where f = concat])\n  done\n\nend (* Anonymous context for private lemmas *)\n\nparagraph \\<open>Fundamentals\\<close>\n\ndefinition \"clkp_set' \\<equiv>\n    (\\<Union> A \\<in> set automata. \\<Union> g \\<in> set (snd (snd (snd A))). collect_clock_pairs (snd g))\n  \\<union> (\\<Union> A \\<in> set automata. \\<Union> (l, b, g, _) \\<in> set (fst (snd (snd A))). collect_clock_pairs g)\"\n\ndefinition clk_set'  where\n  \\<open>clk_set'  =\n  fst ` clkp_set' \\<union>\n  (\\<Union> A \\<in> set automata. \\<Union> (_, _, _, _, _, r, _) \\<in> set (fst (snd (snd A))). set r)\\<close>\n\nlemma (in -) default_map_of_in_listD:\n  \"x \\<in> \\<Union> (set ` snd ` set invs)\" if \"x \\<in> set (default_map_of [] invs l)\"\nproof -\n  have \"[] \\<noteq> default_map_of [] invs l\"\n    using that by force\n  then have \"default_map_of [] invs l \\<in> snd ` set invs\"\n    by (metis (no_types) UNIV_I Un_insert_right range_default_map_of[of \"[]\" \"invs\"]\n          image_eqI insertE subsetCE sup_bot.right_neutral)\n  with that show ?thesis\n    by blast\nqed\n\nlemma collect_clock_pairs_invsI:\n  \"(a, b) \\<in> \\<Union> ((collect_clock_pairs o snd) ` set invs)\"\n  if \"(a, b) \\<in> collect_clock_pairs (default_map_of [] invs l)\"\n  using that unfolding collect_clock_pairs_def by (auto dest!: default_map_of_in_listD)\n\nlemma mem_trans_N_iff:\n  \"t \\<in> Simple_Network_Language.trans (N i) \\<longleftrightarrow> t \\<in> set (fst (snd (snd (automata ! i))))\"\n  if \"i < n_ps\"\n  unfolding N_eq[OF that] by (auto split: prod.splits simp: automaton_of_def trans_def)\n\nlemma length_automata_eq_n_ps:\n  \"length automata = n_ps\"\n  unfolding n_ps_def by simp\n\nlemma clkp_set'_subs:\n  \"Timed_Automata.clkp_set prod_ta \\<subseteq> clkp_set'\"\n  unfolding Timed_Automata.clkp_set_def clkp_set'_def\n  apply (rule union_subsetI)\n  subgoal\n    unfolding Timed_Automata.collect_clki_def inv_of_prod prod_inv_def\n    apply (auto simp: collect_clock_pairs_concat)\n    apply (subst (asm) N_eq)\n     apply assumption\n    subgoal for a b L i\n      apply (inst_existentials \"automata ! i\")\n      subgoal\n        unfolding automaton_of_def\n        by (force dest!: nth_mem collect_clock_pairs_invsI\n            split: prod.split_asm simp: inv_def Prod_TA_Defs.n_ps_def)\n      done\n    done\n  subgoal\n    apply simp\n    unfolding trans_prod_def Timed_Automata.collect_clkt_def\n    apply safe\n    subgoal\n      unfolding trans_int_def by (fastforce simp: length_automata_eq_n_ps mem_trans_N_iff)\n    subgoal\n      unfolding trans_bin_def\n      by (fastforce\n          simp: length_automata_eq_n_ps mem_trans_N_iff\n          dest!: collect_clock_pairs_append_cases)\n    subgoal\n      unfolding trans_broad_def\n      apply (clarsimp simp: length_automata_eq_n_ps mem_trans_N_iff)\n      apply (drule collect_clock_pairs_append_cases)\n      unfolding collect_clock_pairs_concat\n      apply auto\n           apply (fastforce simp: length_automata_eq_n_ps mem_trans_N_iff)+\n      done\n    done\n  done\n\nlemma collect_clkvt_subs:\n  \"collect_clkvt (trans_of prod_ta) \\<subseteq>\n    (\\<Union> A \\<in> set automata. \\<Union> (_, _, _, _, _, r, _) \\<in> set (fst (snd (snd A))). set r)\"\n  apply simp\n  unfolding collect_clkvt_def\n  apply auto\n  unfolding trans_prod_def\n  subgoal\n    apply simp\n    unfolding trans_prod_def Timed_Automata.collect_clkt_def\n    apply safe\n    subgoal\n      unfolding trans_int_def\n      by (fastforce\n          simp: length_automata_eq_n_ps mem_trans_N_iff\n          dest!: collect_clock_pairs_append_cases)\n    subgoal\n      unfolding trans_bin_def\n      by (fastforce\n          simp: length_automata_eq_n_ps mem_trans_N_iff\n          dest!: collect_clock_pairs_append_cases)\n    subgoal\n      unfolding trans_broad_def\n      apply (clarsimp simp: length_automata_eq_n_ps mem_trans_N_iff)\n      unfolding collect_clock_pairs_concat\n      apply safe\n           apply (fastforce simp: length_automata_eq_n_ps mem_trans_N_iff)+\n      done\n    done\n  done\n\nlemma clk_set'_subs: \"clk_set prod_ta \\<subseteq> clk_set'\"\n  using collect_clkvt_subs clkp_set'_subs unfolding clk_set'_def by auto\n\nend (* Simple Network Impl *)\n\n\nlemma (in Prod_TA_Defs) finite_range_invI:\n  \"finite (range prod_inv)\" if assms: \"\\<forall> i < n_ps. finite (range (inv (N i)))\"\nproof -\n  let ?N = \"\\<Union> (range ` inv ` N ` {0..<n_ps})\"\n  let ?X = \"{I. set I \\<subseteq> ?N \\<and> length I \\<le> n_ps}\"\n  have \"finite ?N\"\n    using assms by auto\n  then have \"finite ?X\"\n    by (rule finite_lists_length_le)\n  moreover have \"range prod_inv \\<subseteq> concat ` ?X \\<union> {[]}\"\n  proof\n    fix x assume \"x \\<in> range prod_inv\"\n    then consider L where \"x = concat (map (\\<lambda>p. (inv (N p)) (L ! p)) [0..<n_ps])\" | \"x = []\"\n      unfolding prod_inv_def by (auto split: if_split_asm)\n    then show \"x \\<in> concat ` ?X \\<union> {[]}\"\n      by (cases; force)\n  qed\n  ultimately show ?thesis by - (drule finite_subset; auto)\nqed\n\ndefinition (in Prod_TA_Defs)\n  \"loc_set =\n  (\\<Union> {fst ` trans (N p) | p. p < n_ps} \\<union>\n        \\<Union> {(snd o snd o snd \\<circ> snd \\<circ> snd \\<circ> snd) ` trans (N p) | p. p < n_ps})\"\n\nlemma (in Prod_TA_Defs) states_loc_set:\n  \"states \\<subseteq> {L. set L \\<subseteq> loc_set \\<and> length L = n_ps}\"\n  unfolding states_def loc_set_def\n  apply (intros add: more_intros)\n   apply (elims add: more_elims)\n   apply (drule mem_nth)\n   apply simp\n   apply (elims add: allE, assumption)\n   apply (simp split: prod.split_asm)\n   apply (erule disjE; (intros add: disjI1 disjI2 more_intros, solve_triv+); fail)\n  by (elims add: more_elims)\n\nlemma (in Prod_TA_Defs) finite_states:\n  assumes finite_trans: \"\\<forall>p < n_ps. finite (Simple_Network_Language.trans (N p))\"\n  shows \"finite states\"\nproof -\n  have \"states \\<subseteq> {L. set L \\<subseteq> loc_set \\<and> length L = n_ps}\"\n    by (rule states_loc_set)\n  also from finite_trans have \"finite \\<dots>\"\n    unfolding loc_set_def by (intro finite_intros) auto\n  finally show ?thesis .\nqed\n\ncontext Simple_Network_Impl\nbegin\n\nlemma trans_N_finite:\n  assumes \"p < n_ps\"\n  shows \"finite (Simple_Network_Language.trans (N p))\"\n  using assms by (subst N_eq) (auto simp: automaton_of_def trans_def split: prod.split)\n\nlemma states_finite:\n  \"finite states\"\n  by (intros add: finite_states trans_N_finite)\n\nlemma bounded_finite:\n  \"finite {s. bounded bounds s}\"\nproof -\n  let ?l = \"Min {fst (the (bounds x)) | x. x \\<in> dom bounds}\"\n  let ?u = \"Max {snd (the (bounds x)) | x. x \\<in> dom bounds}\"\n  have \"finite (dom bounds)\"\n    unfolding bounds_def by simp\n  then have \"{s. bounded bounds s} \\<subseteq> {s. dom s = dom bounds \\<and> ran s \\<subseteq> {?l..?u}}\"\n    unfolding bounded_def\n    apply clarsimp\n    apply (rule conjI)\n    subgoal for s v\n      unfolding ran_is_image\n      apply clarsimp\n      subgoal for x l u\n        by (rule order.trans[where b = \"fst (the (bounds x))\"]; (rule Min_le)?; force)\n      done\n    subgoal for s v\n      unfolding ran_is_image\n      apply clarsimp\n      subgoal for x l u\n        by (rule order.trans[where b = \"snd (the (bounds x))\"]; (rule Max_ge)?; force)\n      done\n    done\n  also from \\<open>finite (dom bounds)\\<close> have \"finite \\<dots>\"\n    by (rule finite_set_of_finite_maps) rule\n  finally show ?thesis .\nqed\n\nlemma trans_prod_finite:\n  \"finite trans_prod\"\nproof -\n  have \"finite trans_int\"\n  proof -\n    have \"trans_int \\<subseteq>\n      {((L, s), g, Internal a, r, (L', s')) | L s p l b g a f r l' s' L'.\n        L \\<in> states \\<and> bounded bounds s \\<and> p < n_ps \\<and>\n        (l, b, g, Sil a, f, r, l') \\<in> trans (N p) \\<and>\n        bounded bounds s'\n        \\<and> L' = L[p := l']\n      }\"\n      unfolding trans_int_def by (force simp: L_len)\n    also have \"finite \\<dots>\"\n    proof -\n      have \"finite {(a, b, c, d, e, f, g). (a, b, c, Sil d, e, f, g) \\<in> trans (N p)}\"\n        if \"p < n_ps\" for p\n        using [[simproc add: finite_Collect]] that\n        by (auto intro: trans_N_finite finite_vimageI injI)\n      with states_finite bounded_finite show ?thesis\n        by defer_ex\n    qed\n    finally show ?thesis .\n  qed\n  moreover have \"finite trans_bin\"\n  proof -\n    have \"trans_bin \\<subseteq>\n      {((L, s), g1 @ g2, Bin a, r1 @ r2, (L', s'')) |\n        L s p q l1 b1 g1 a f1 r1 l1' l2 b2 g2 f2 r2 l2' s'' L'.\n          L \\<in> states \\<and> bounded bounds s \\<and>\n          p < n_ps \\<and> q < n_ps \\<and>\n          (l1, b1, g1, In a,  f1, r1, l1') \\<in> trans (N p) \\<and>\n          (l2, b2, g2, Out a, f2, r2, l2') \\<in> trans (N q) \\<and>\n          bounded bounds s'' \\<and>\n          L' = L[p := l1', q := l2']\n    }\"\n      unfolding trans_bin_def by (fastforce simp: L_len) (* slow *)\n    also have \"finite \\<dots>\"\n    proof -\n      have \"finite {(a, b, c, d, e, f, g). (a, b, c, In d, e, f, g) \\<in> trans (N p)}\"\n        if \"p < n_ps\" for p\n        using [[simproc add: finite_Collect]] that\n        by (auto intro: trans_N_finite finite_vimageI injI)\n      moreover have \"finite {(a, b, c, e, f, g). (a, b, c, Out d, e, f, g) \\<in> trans (N p)}\"\n        if \"p < n_ps\" for p d\n        using [[simproc add: finite_Collect]] that\n        by (auto intro: trans_N_finite finite_vimageI injI)\n      ultimately show ?thesis\n        using states_finite bounded_finite by defer_ex\n    qed\n    finally show ?thesis .\n  qed\n  moreover have \"finite trans_broad\"\n  proof -\n    define P where \"P ps \\<equiv> set ps \\<subseteq> {0..<n_ps} \\<and> distinct ps\" for ps\n    define Q where \"Q a n bs gs fs rs \\<equiv>\n      (\\<forall>p < n. \\<exists> q < n_ps. \\<exists> l l'. (l, bs ! p, gs ! p, In a, fs ! p, rs ! p, l') \\<in> trans (N q)) \\<and>\n              length bs = n \\<and> length gs = n \\<and> length fs = n \\<and> length rs = n\" for a n bs gs fs rs\n    define tag where \"tag x = True\" for x :: 's\n    have Q_I: \"Q a (length ps) (map bs ps) (map gs ps) (map fs ps) (map rs ps)\"\n      if \"set ps \\<subseteq> {0..<n_ps}\"\n         \"\\<forall>p\\<in>set ps. (L ! p, bs p, gs p, In a, fs p, rs p, ls' p) \\<in> trans (N p)\"\n      for ps :: \"nat list\" and L a bs gs fs rs ls'\n      using that unfolding Q_def by (auto 4 4 dest!: nth_mem)\n    have \"trans_broad \\<subseteq>\n      {((L, s), g @ concat gs, Broad a, r @ concat rs, (L', s'')) |\n      L s a p l b g f r l' ps bs gs fs rs L' s''.\n        L \\<in> states \\<and> bounded bounds s \\<and> a \\<in> set broadcast \\<and>\n        p < n_ps \\<and>\n        (l, b, g, Out a, f, r, l') \\<in> trans (N p) \\<and>\n        P ps \\<and>\n        Q a (length ps) bs gs fs rs \\<and>\n        L' \\<in> states \\<and>\n        bounded bounds s'' \\<and>\n        tag l'\n    }\"\n      unfolding trans_broad_def broadcast_def\n      apply (rule subsetI)\n      apply (elims add: more_elims)\n      apply (intros add: more_intros)\n                apply solve_triv+\n            apply (simp add: L_len; fail)\n           apply assumption\n          apply (unfold P_def; intros; assumption)\n         apply (rule Q_I; assumption)\n      subgoal\n        by (blast intro: state_preservation_updI state_preservation_fold_updI)\n       apply assumption\n      unfolding tag_def ..\n    also have \"finite \\<dots>\"\n    proof -\n      have \"finite {(a, b, c, e, f, g). (a, b, c, Out d, e, f, g) \\<in> trans (N p)}\"\n        if \"p < n_ps\" for p d\n        using [[simproc add: finite_Collect]] that\n        by (auto intro: trans_N_finite finite_vimageI injI)\n      moreover have \"finite {ps. P ps}\"\n        unfolding P_def by (simp add: finite_intros)\n      moreover have \"finite {(bs, gs, fs, rs). Q a n bs gs fs rs}\" (is \"finite ?S\") for a n\n      proof -\n        let ?T = \"\\<Union> (trans ` N ` {0..<n_ps})\"\n        have \"?S \\<subseteq> {(bs, gs, fs, rs).\n          (set bs \\<subseteq> (\\<lambda>(_,b,_). b) ` ?T \\<and> length bs = n) \\<and>\n          (set gs \\<subseteq> (\\<lambda>(_,_,g,_). g) ` ?T \\<and> length gs = n) \\<and>\n          (set fs \\<subseteq> (\\<lambda>(_,_,_,_,f,_). f) ` ?T \\<and> length fs = n) \\<and>\n          (set rs \\<subseteq> (\\<lambda>(_,_,_,_,_,r,_). r) ` ?T \\<and> length rs = n)\n        }\"\n          unfolding Q_def\n          by safe (drule mem_nth; elims; drule spec; elims; force)+\n        also have \"finite \\<dots>\"\n          using trans_N_finite by (intro finite_intros more_finite_intros) auto\n        finally show ?thesis .\n      qed\n      ultimately show ?thesis\n        using states_finite bounded_finite by defer_ex\n    qed\n    finally show ?thesis .\n  qed\n  ultimately show ?thesis\n    by (simp add: trans_prod_def)\nqed\n\nlemma prod_inv_finite:\n  \"finite (range prod_inv)\"\n  apply (intros add: finite_range_invI)\n  unfolding length_automata_eq_n_ps[symmetric]\n  unfolding N_def\n  unfolding automaton_of_def\n  by (auto intro: finite_range_default_map_of split: prod.split simp: inv_def)\n\nend (* Simple Network Impl *)\n\nparagraph \\<open>Collecting variables from expressions.\\<close>\n\nfun vars_of_bexp and vars_of_exp where\n  \"vars_of_bexp (not e) = vars_of_bexp e\"\n| \"vars_of_bexp (and e1 e2) = (vars_of_bexp e1 \\<union> vars_of_bexp e2)\"\n| \"vars_of_bexp (bexp.or e1 e2) = (vars_of_bexp e1 \\<union> vars_of_bexp e2)\"\n| \"vars_of_bexp (imply e1 e2) = (vars_of_bexp e1 \\<union> vars_of_bexp e2)\"\n| \"vars_of_bexp (eq i x) = vars_of_exp i \\<union> vars_of_exp x\"\n| \"vars_of_bexp (le i x) = vars_of_exp i \\<union> vars_of_exp x\"\n| \"vars_of_bexp (lt i x) = vars_of_exp i \\<union> vars_of_exp x\"\n| \"vars_of_bexp (ge i x) = vars_of_exp i \\<union> vars_of_exp x\"\n| \"vars_of_bexp (gt i x) = vars_of_exp i \\<union> vars_of_exp x\"\n| \"vars_of_bexp bexp.true = {}\"\n| \"vars_of_exp (const c) = {}\"\n| \"vars_of_exp (var x) = {x}\"\n| \"vars_of_exp (if_then_else b e1 e2) = vars_of_bexp b \\<union> vars_of_exp e1 \\<union> vars_of_exp e2\"\n| \"vars_of_exp (binop _ e1 e2) = vars_of_exp e1 \\<union> vars_of_exp e2\"\n| \"vars_of_exp (unop _ e) = vars_of_exp e\"\n\ndefinition (in Prod_TA_Defs)\n  \"var_set =\n  (\\<Union>S \\<in> {(fst \\<circ> snd) ` trans (N p) | p. p < n_ps}. \\<Union>b \\<in> S. vars_of_bexp b) \\<union>\n  (\\<Union>S \\<in> {(fst \\<circ> snd \\<circ> snd \\<circ> snd \\<circ> snd) ` trans (N p) | p. p < n_ps}.\n    \\<Union>f \\<in> S. \\<Union> (x, e) \\<in> set f. {x} \\<union> vars_of_exp e)\"\n\nlocale Simple_Network_Impl_nat_defs =\n  Simple_Network_Impl automata\n  for automata ::\n    \"(nat list \\<times> nat list \\<times> (nat act, nat, nat, int, nat, int) transition list\n      \\<times> (nat \\<times> (nat, int) cconstraint) list) list\" +\n  fixes m :: nat and num_states :: \"nat \\<Rightarrow> nat\" and num_actions :: nat\n\nlocale Simple_Network_Impl_nat =\n  Simple_Network_Impl_nat_defs +\n  assumes has_clock: \"m > 0\"\n  assumes non_empty: \"0 < length automata\"\n    (* assumes \"length automata = length state_nums\" *)\n  assumes trans_num_states:\n    \"\\<forall>i < n_ps. let (_, _, trans, _) = (automata ! i) in \\<forall> (l, _, _, _, _, _, l') \\<in> set trans.\n      l < num_states i \\<and> l' < num_states i\"\n    and inv_num_states:\n    \"\\<forall>i < n_ps. let (_, _, _, inv) = (automata ! i) in \\<forall> (x, _) \\<in> set inv. x < num_states i\"\n  assumes var_set:\n    \"\\<forall>(_, _, trans, _) \\<in> set automata. \\<forall>(_, _, _, _, f, _, _) \\<in> set trans.\n      \\<forall>(x, upd) \\<in> set f. x < n_vs \\<and> (\\<forall>i \\<in> vars_of_exp upd. i < n_vs)\"\n    \"\\<forall>(_, _, trans, _) \\<in> set automata. \\<forall>(_, b, _, _, _, _, _) \\<in> set trans.\n      \\<forall>i \\<in> vars_of_bexp b. i < n_vs\"\n  assumes bounds:\n    \"\\<forall> i < n_vs. fst (bounds' ! i) = i\"\n  assumes action_set:\n    \"\\<forall>a \\<in> set broadcast. a < num_actions\"\n    \"\\<forall>(_, _, trans, _) \\<in> set automata. \\<forall>(_, _, _, a, _, _, _) \\<in> set trans.\n        pred_act (\\<lambda>a. a < num_actions) a\"\n  assumes clock_set:\n    \"\\<forall>(_, _, trans, _) \\<in> set automata. \\<forall>(_, _, g, _, _, r, _) \\<in> set trans.\n      (\\<forall>c \\<in> set r. 0 < c \\<and> c \\<le> m) \\<and>\n      (\\<forall> (c, x) \\<in> collect_clock_pairs g. 0 < c \\<and> c \\<le> m \\<and> x \\<in> \\<nat>)\n      \"\n    \"\\<forall>(_, _, _, inv) \\<in> set automata. \\<forall>(l, g) \\<in> set inv.\n      (\\<forall> (c, x) \\<in> collect_clock_pairs g. 0 < c \\<and> c \\<le> m \\<and> x \\<in> \\<nat>)\n      \"\n  assumes broadcast_receivers:\n  \"\\<forall>(_, _, trans, _) \\<in> set automata. \\<forall>(_, _, g, a, _, _, _) \\<in> set trans.\n      case a of In a \\<Rightarrow> a \\<in> set broadcast \\<longrightarrow> g = [] | _ \\<Rightarrow> True\"\nbegin\n\nlemma broadcast_receivers_unguarded:\n  \"\\<forall>p<n_ps. \\<forall>l b g a f r l'.\n    (l, b, g, In a, f, r, l') \\<in> Simple_Network_Language.trans (N p) \\<and> a \\<in> set broadcast \\<longrightarrow> g = []\"\n  using broadcast_receivers by (fastforce dest: nth_mem simp: n_ps_def mem_trans_N_iff)\n\nsublocale conv: Prod_TA\n  \"(set broadcast, map (Simple_Network_Language.conv_A o automaton_of) automata, map_of bounds')\"\n  using broadcast_receivers_unguarded\n  by - (standard,\n fastforce simp: conv.broadcast_def Simple_Network_Language.conv_t_def conv_n_ps_eq trans_conv_N_eq)\n\nsublocale TA_Start_No_Ceiling prod_ta init m\nproof standard\n  show \"finite (trans_of prod_ta)\"\n    using trans_prod_finite by simp\nnext\n  show \"finite (range (inv_of prod_ta))\"\n    using prod_inv_finite by simp\nnext\n  from clk_set'_subs have \"clk_set prod_ta \\<subseteq> clk_set'\" .\n  also have \"\\<dots> \\<subseteq> {1..m}\"\n    using clock_set unfolding clk_set'_def clkp_set'_def by force\n  finally show \"clk_set prod_ta \\<subseteq> {1..m}\" .\nnext\n  from clock_set have \"\\<forall>(_, d)\\<in>clkp_set'. d \\<in> \\<nat>\"\n    unfolding clkp_set'_def by force\n  then show \"\\<forall>(_, d)\\<in>Timed_Automata.clkp_set prod_ta. d \\<in> \\<nat>\"\n    by (auto dest!: subsetD[OF clkp_set'_subs])\nnext\n  show \"0 < m\"\n    by (rule has_clock)\nqed\n\nend (* Simple Network Impl nat *)\n\n\ncontext Simple_Network_Impl\nbegin\n\ndefinition \"sem \\<equiv> (set broadcast, map (automaton_of o conv_automaton) automata, map_of bounds')\"\n\nsublocale sem: Prod_TA_sem sem .\n\nlemma sem_N_eq:\n  \"sem.N p = automaton_of (conv_automaton (automata ! p))\" if \\<open>p < n_ps\\<close>\n  using that unfolding sem.N_def n_ps_def unfolding sem_def fst_conv snd_conv\n  by (subst nth_map) auto\n\nend (* Simple Network Impl *)\n\ninductive_cases step_u_elims:\n  \"A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>Del\\<^esub> \\<langle>L', s', u'\\<rangle>\"\n  \"A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>Internal a\\<^esub> \\<langle>L', s', u'\\<rangle>\"\n  \"A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>Bin a\\<^esub> \\<langle>L', s'', u'\\<rangle>\"\n  \"A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>Broad a\\<^esub> \\<langle>L', s'', u'\\<rangle>\"\n\ninductive_cases step_u_elims':\n  \"(broadcast, N, B) \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>Del\\<^esub> \\<langle>L', s', u'\\<rangle>\"\n  \"(broadcast, N, B) \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>Internal a\\<^esub> \\<langle>L', s', u'\\<rangle>\"\n  \"(broadcast, N, B) \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>Bin a\\<^esub> \\<langle>L', s'', u'\\<rangle>\"\n  \"(broadcast, N, B) \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>Broad a\\<^esub> \\<langle>L', s'', u'\\<rangle>\"\n\nlemma (in Prod_TA_Defs) states_lengthD:\n  \"length L = n_ps\" if \"L \\<in> states\"\n  using that unfolding states_def by simp\n\nend (* Theory *)", "meta": {"author": "wimmers", "repo": "munta", "sha": "62cb1a4a4dbcfcf62c365e90faba15b0012d5a12", "save_path": "github-repos/isabelle/wimmers-munta", "path": "github-repos/isabelle/wimmers-munta/munta-62cb1a4a4dbcfcf62c365e90faba15b0012d5a12/Simple_Networks/Simple_Network_Language_Impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5156199157230157, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.28190907984886393}}
{"text": "section \\<open>Reference Guide\\<close>\ntheory Sepref_Guide_Reference\nimports \"../IICF/IICF\" (*\"~~/src/Doc/Isar_Ref/Base\"*)\nbegin\ntext \\<open>This guide contains a short reference of the most \n  important Sepref commands, methods, and attributes, as well as\n  a short description of the internal working, and troubleshooting information\n  with examples.\n\n  Note: To get an impression how to actually use the Sepref-tool, read the\n  quickstart guide first!\n\\<close>\n\nsubsection \\<open>The Sepref Method\\<close>\ntext \\<open>The @{method sepref} method is the central method of the tool.\n  Given a schematic goal of the form \\<open>hn_refine \\<Gamma> ?c ?\\<Gamma>' ?R f\\<close>, it tries \n  to synthesize terms for the schematics and prove the theorem. Note that the\n  \\<open>?\\<Gamma>'\\<close> and \\<open>?R\\<close> may also be fixed terms, in which case frame inference is used \n  to match the generated assertions with the given ones.\n  \\<open>\\<Gamma>\\<close> must contain a description of the available refinements on the heap, the \n  assertion for each variable must be marked with a \\<open>hn_ctxt\\<close> tag. \n\n  Alternatively, a term of the form \\<open>(?c,f)\\<in>[P]\\<^sub>a A\\<rightarrow>R\\<close> is accepted, where \\<open>A\\<close> \n  describes the refinement and preservation of the arguments, and \\<open>R\\<close> the refinement \n  of the result. \\<open>f\\<close> must be in uncurried form (i.e. have exactly one argument).\n\n  We give some very basic examples here. In practice, you would almost always use\n  the higher-level commands @{command sepref_definition} and @{command sepref_register}.\n\\<close>\n\ntext \\<open>In its most primitive form, the Sepref-tool is applied like this:\\<close>\nschematic_goal \n  notes [id_rules] = itypeI[of x \"TYPE(nat)\"] itypeI[of a \"TYPE(bool list)\"]\n  shows \"hn_refine \n    (hn_ctxt nat_assn x xi * hn_ctxt (array_assn bool_assn) a ai) \n    (?c::?'c Heap) ?\\<Gamma>' ?R \n    (do { ASSERT (x<length a); RETURN (a!x) })\"\n  by sepref\n\ntext \\<open>The above command asks Sepref to synthesize a program, in a heap context where there \n  is a natural number, refined by \\<open>nat_assn\\<close>, and a list of booleans, refined \n  by \\<open>array_assn bool_assn\\<close>. The \\<open>id_rules\\<close> declarations declare the abstract variables to the \n  operation identification heuristics, such that they are recognized as operands.\\<close>\n\ntext \\<open>Using the alternative hfref-form, we can write:\\<close>\nschematic_goal \"(uncurry (?c), uncurry (\\<lambda>x a. do {ASSERT (x<length a); RETURN (a!x)}))\n  \\<in> nat_assn\\<^sup>k *\\<^sub>a (array_assn bool_assn)\\<^sup>k \\<rightarrow>\\<^sub>a bool_assn\"\n  by sepref\ntext \\<open>This uses the specified assertions to derive the rules for \n  operation identification automatically. For this, it uses the\n  assertion-interface bindings declared in @{attribute intf_of_assn}.\n  If there is no such binding, it uses the HOL type as interface type.\n\\<close>\nthm intf_of_assn\n\ntext \\<open>\n  The sepref-method is split into various phases, which we will explain now\n\\<close>\n\nsubsubsection \\<open>Preprocessing Phase\\<close>\ntext \\<open>\n  This tactic converts a goal in \\<open>hfref\\<close> form to the more basic \\<open>hn_refine\\<close> form.\n  It uses the theorems from @{attribute intf_of_assn} to add interface type declarations\n  for the generated operands. The final result is massaged by rewriting with\n  @{attribute to_hnr_post}, and then with @{attribute sepref_preproc}.\n\n  Moreover, this phase ensures that there is a constraint slot goal (see section on constraints).\n\\<close>\n\ntext \\<open>The method @{method sepref_dbg_preproc} gives direct access to the preprocessing phase.\\<close>\nthm sepref_preproc\nthm intf_of_assn\nthm to_hnr_post \\<comment> \\<open>Note: These rules are only instantiated for up to 5 arguments. \n  If you have functions with more arguments, you need to add corresponding theorems here!\\<close>\n\nsubsubsection \\<open>Consequence Rule  Phase\\<close>\ntext \\<open>This phase rewrites \\<open>hn_invalid _ x y\\<close> assertions in the postcondition to \n  \\<open>hn_ctxt (\\<lambda>_ _. true) x y\\<close> assertions, which are trivial to discharge. \n  Then, it applies @{thm [source] CONS_init}, to make postcondition and \n  result relation schematic, and introduce (separation logic) implications to\n  the originals, which are discharged after synthesis.\n\\<close>\ntext \\<open>Use @{method sepref_dbg_cons_init} for direct access to this phase.\n  The method @{method weaken_hnr_post} performs the rewriting of \\<open>hn_invalid\\<close>\n  to \\<open>\\<lambda>_ _. true\\<close> postconditions, and may be useful on its own for proving \n  combinator rules. \n\\<close>\n\nsubsubsection \\<open>Operation Identification Phase\\<close>\ntext \\<open>The purpose of this phase is to identify the conceptual operations in the given program.\n  Consider, for example, a map @{term_type \"m::'k\\<rightharpoonup>'v\"}. \n  If one writes @{term \"m(k\\<mapsto>v)\"}, this is a map update. However, in Isabelle/HOL maps\n  are encoded as functions @{typ \"'k \\<Rightarrow> 'v option\"}, and the map update is just syntactic\n  sugar for @{term [source] \"fun_upd m k (Some v)\"}. And, likewise, map lookup is just \n  function application.\n\n  However, the Sepref tool must be able to distinguish between maps and functions into the\n  option type, because maps shall be refined, to e.g., hash-tables, while functions into the\n  option type shall be not. Consider, e.g., the term @{term \"Some x\"}. Shall \\<open>Some\\<close> be \n  interpreted as the constructor of the option datatype, or as a map, mapping each element to\n  itself, and perhaps be implemented with a hashtable.\n  \n  Moreover, for technical reasons, the translation phase of Sepref expects each operation \n  to be a single constant applied to its operands. This criterion is neither matched by map \n  lookup (no constant, just application of the first to the second operand), nor map update \n  (complex expression, involving several constants).\n\n  The operation identification phase uses a heuristics to find the conceptual types in a term\n  (e.g., discriminate between map and function to option), and rewrite the operations to single \n  constants (e.g. @{const op_map_lookup} for map lookup). The heuristics is a type-inference \n  algorithm combined with rewriting. Note that the inferred conceptual type does not necessarily\n  match the HOL type, nor does it have a semantic meaning, other than guiding the heuristics.\n\n  The heuristics store a set of typing rules for constants, in @{attribute id_rules}.\n  Moreover, it stores two sets of rewrite rules, in @{attribute pat_rules} \n  and @{attribute def_pat_rules}. A term is typed by first trying to apply a rewrite rule, and\n  then applying standard Hindley-Milner type inference rules for application and abstraction. \n  Constants (and free variables) are typed\n  using the \\<open>id_rules\\<close>. If no rule for a constant exists, one is inferred from the constant's \n  signature. This does not work for free variables, such that rules must be available\n  for all free variables. Rewrite rules from \\<open>pat_rules\\<close> are backtracked over, while rewrite rules\n  from \\<open>def_pat_rules\\<close> are always tried first and never backtracked over.\n  \n  If typing succeeds, the result is the rewritten term.\n\n  For example, consider the type of maps. Their interface (or conceptual) type is \n  @{typ \"('k,'v) i_map\"}. The \\<open>id_rule\\<close> for map lookup is @{thm \"op_map_lookup.itype\"}.\n  Moreover, there is a rule to rewrite function application to map lookup (@{thm pat_map_lookup}). \n  It can be backtracked over, such that also functions into the option type are possible.\n\\<close>\nthm op_map_lookup.itype\nthm pat_map_lookup\nthm id_rules\ntext \\<open>\n  The operation identification phase, and all further phases, work on a tagged \n  version of the input term, where all function applications are replaced by the\n  tagging constant @{term \"($)\"}, and all abstractions are replaced by \n  @{term \"\\<lambda>x. PROTECT2 (t x) DUMMY\"} (syntax: @{term \"\\<lambda>x. (#t x#)\"}, \n  input syntax: @{term \"\\<lambda>\\<^sub>2x. t x\"}). This is required to tame Isabelle's \n  higher-order unification. However, it makes tagged terms quite unreadable, and it\n  may be helpful to \\<open>unfold APP_def PROTECT2_def\\<close> to get back the untagged form when inspecting\n  internal states for debugging purposes.\n\n  To prevent looping, rewrite-rules can use @{term \"($')\"} on the RHS. This is\n  a synonym for @{term \"($)\"}, and gets rewritten to @{term \"($)\"} after the operation\n  identification phase. During the operation identification phase, it prevents infinite\n  loops of pattern rewrite rules.\n\n\n  Interface type annotations can be added to the term using @{const CTYPE_ANNOT} \n  (syntax @{term \"t:::\\<^sub>iTYPE('a)\"}).\n\n  In many cases, it is desirable to treat complex terms as a single constant, \n  a standard example are constants defined inside locales, which may have locale \n  parameters attached. Those terms can be wrapped into an @{const PR_CONST} tag,\n  which causes them to be treated like a single constant. Such constants must always \n  have \\<open>id_rules\\<close>, as the interface type inference from the signature does not apply here.\n\\<close>\n\nsubsubsection \\<open>Troubleshooting Operation Identification\\<close>\ntext \\<open>\n  If the operation identification fails, in most cases one has forgotten to register \n  an \\<open>id_rule\\<close> for a free variable or complex \\<open>PR_CONST\\<close> constant, or the identification \n  rule is malformed. Note that, in practice, identification rules are registered by \n  the @{command sepref_register} (see below), which catches many malformed rules, and\n  handles \\<open>PR_CONST\\<close> tagging automatically. Another frequent source of errors here is \n  forgetting to register a constant with a conceptual type other than its signature. \n  In this case, operation identification gets stuck trying to unify the signature's type with\n  the interface type, e.g., @{typ \"'k \\<Rightarrow> 'v option\"} with @{typ \"('k,'v)i_map\"}.\n\n  The method @{method sepref_dbg_id} invokes the id-phase in isolation.\n  The method @{method sepref_dbg_id_keep} returns the internal state where type \n  inference got stuck. It returns a sequence of all stuck states, which can be inspected\n  using @{command back}. \n\n  The methods @{method sepref_dbg_id_init},@{method sepref_dbg_id_step}, \n  and @{method sepref_dbg_id_solve} can be used to single-step the operation \n  identification phase. Here, solve applies single steps until the current subgoal is discharged.\n  Be aware that application of single steps allows no automatic backtracking, such that backtracking\n  has to be done manually.\n\\<close>\n\ntext \\<open>Examples for identification errors\\<close>\ncontext \n  fixes N::nat \n  notes [sepref_import_param] = IdI[of N]\nbegin\n  sepref_thm N_plus_2_example is \"uncurry0 (RETURN (N+2))\" :: \"unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a nat_assn\"\n    apply sepref_dbg_keep\n    apply sepref_dbg_id_keep\n    \\<comment> \\<open>Forgot to register \\<open>n\\<close>\\<close>\n    oops\n\n  text \\<open>Solution: Register \\<open>n\\<close>, be careful not to export meaningless registrations from context!\\<close>\n  context\n    notes [[sepref_register_adhoc N]]\n  begin\n    sepref_thm N_plus_2_example is \"uncurry0 (RETURN (N+2))\" :: \"unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a nat_assn\" by sepref\n  end  \nend\n\ndefinition \"my_map \\<equiv> op_map_empty\"\nlemmas [sepref_fr_rules] = hm.empty_hnr[folded my_map_def]\n\nsepref_thm my_map_example is \"uncurry0 (RETURN (my_map(False\\<mapsto>1)))\" :: \"unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a hm.assn bool_assn nat_assn\"\n  apply sepref_dbg_keep\n  apply sepref_dbg_trans_keep\n  \\<comment> \\<open>Stuck at refinement for function update on map\\<close>\n  oops\n\ntext \\<open>Solution: Register with correct interface type\\<close>\nsepref_register my_map :: \"('k,'v) i_map\"\nsepref_thm my_map_example is \"uncurry0 (RETURN (my_map(False\\<mapsto>1)))\" :: \"unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a hm.assn bool_assn nat_assn\"\n  by sepref\n\n\nsubsubsection \\<open>Monadify Phase\\<close>\ntext \\<open>\n  The monadify phase rewrites the program such that every operation becomes \n  visible on the monad level, that is, nested HOL-expressions are flattened.\n  Also combinators (e.g. if, fold, case) may get flattened, if special rules \n  are registered for that.\n\n  Moreover, the monadify phase fixes the number of operands applied to an operation,\n  using eta-expansion to add missing operands. \n\n  Finally, the monadify phase handles duplicate parameters to an operation, by\n  inserting a @{const COPY} tag. This is necessary as our tool expects the \n  parameters of a function to be separate, even for read-only \n  parameters@{footnote \\<open>Using fractional permissions or some other more fine grained\n    ownership model might lift this restriction in the future.\\<close>}. \n\\<close>\n\ntext \\<open>The monadify phase consists of a number of sub-phases.\n  The method @{method sepref_dbg_monadify} executes the monadify phase,\n  the method @{method sepref_dbg_monadify_keep} stops at a failing sub-phase\n  and presents the internal goal state before the failing sub-phase.\n\\<close>\n\nsubsubsection \\<open>Monadify: Arity\\<close>\ntext \\<open>In the first sub-phase, the rules from @{attribute sepref_monadify_arity} \n  are used to standardize the number of operands applied to a constant.\n  The rules work by rewriting each constant to a lambda-expression with the \n  desired number of arguments, and the using beta-reduction to account for\n  already existing arguments. Also higher-order arguments can be enforced,\n  for example, the rule for fold enforces three arguments, the function itself\n  having two arguments (@{thm fold_arity}).\n\n  In order to prevent arity rules being applied infinitely often, \n  the @{const SP} tag can be used on the RHS. It prevents anything inside \n  from being changed, and gets removed after the arity step.\n\n  The method @{method sepref_dbg_monadify_arity} gives you direct access to this phase.\n\n  In the Sepref-tool, we use the terminology @{emph \\<open>operator/operation\\<close>} for a function that\n  only has first-order arguments, which are evaluated before the function is applied (e.g. @{term \"(+)\"}),\n  and @{emph \\<open>combinator\\<close>} for operations with higher-order arguments or custom \n  evaluation orders (e.g. @{term \"fold\"}, @{term \"If\"}).\n\n  Note: In practice, most arity (and combinator) rules are declared automatically\n    by @{command sepref_register} or @{command sepref_decl_op}. Manual declaration\n    is only required for higher-order functions.\n\\<close>\nthm sepref_monadify_arity\n\nsubsubsection \\<open>Monadify: Combinators\\<close>\ntext \\<open>The second sub-phase flattens the term. \n  It has a rule for every function into @{typ \"_ nres\"} type, that determines\n  the evaluation order of the arguments. First-order arguments are evaluated before\n  an operation is applied. Higher-order arguments are treated specially, as they\n  are evaluated during executing the (combinator) operation. The rules are in\n  @{attribute sepref_monadify_comb}.\n\n  Evaluation of plain (non-monadic) terms is triggered by wrapping them into\n  the @{const EVAL} tag. The @{attribute sepref_monadify_comb} rules may also contain\n  rewrite-rules for the @{const EVAL} tag, for example to unfold plain combinators\n  into the monad (e.g. @{thm dflt_plain_comb}). If no such rule applies, the \n  default method is to interpret the head of the term as a function, and recursively\n  evaluate the arguments, using left-to-right evaluation order. The head of \n  a term inside @{const EVAL} must not be an abstraction. Otherwise, the \n  @{const EVAL} tag remains in the term, and the next sub-phase detects this \n  and fails.\n\n  The method @{method sepref_dbg_monadify_comb} executes the combinator-phase \n  in isolation.\n\\<close>\n\nsubsubsection \\<open>Monadify: Check-Eval\\<close>\ntext \\<open>This phase just checks for remaining @{const EVAL} tags in the term,\n  and fails if there are such tags. The method @{method sepref_dbg_monadify_check_EVAL}\n  gives direct access to this phase.\n\n  Remaining @{const EVAL} tags indicate\n  higher-order functions without an appropriate setup of the combinator-rules\n  being used. For example:\n\\<close>\ndefinition \"my_fold \\<equiv> fold\"\nsepref_thm my_fold_test is \"\\<lambda>l. do { RETURN (my_fold (\\<lambda>x y. x+y*2) l 0)}\" :: \"(list_assn nat_assn)\\<^sup>k\\<rightarrow>\\<^sub>anat_assn\"\n  apply sepref_dbg_keep\n  apply sepref_dbg_monadify_keep\n  \\<comment> \\<open>An \\<open>EVAL\\<close>-tag with an abstraction remains. This is b/c the default heuristics\n    tries to interpret the function inside the fold as a plain value argument.\\<close>\n  oops\n\ntext \\<open>Solution: Register appropriate arity and combinator-rules\\<close>\nlemma my_fold_arity[sepref_monadify_arity]: \"my_fold \\<equiv> \\<lambda>\\<^sub>2f l s. SP my_fold$(\\<lambda>\\<^sub>2x s. f$x$s)$l$s\" by auto\n\ntext \\<open>The combinator-rule rewrites to the already existing and set up combinator @{term nfoldli}:\\<close>\nlemma monadify_plain_my_fold[sepref_monadify_comb]: \n  \"EVAL$(my_fold$(\\<lambda>\\<^sub>2x s. f x s)$l$s) \\<equiv> (\\<bind>)$(EVAL$l)$(\\<lambda>\\<^sub>2l. (\\<bind>)$(EVAL$s)$(\\<lambda>\\<^sub>2s. nfoldli$l$(\\<lambda>\\<^sub>2_. True)$(\\<lambda>\\<^sub>2x s. EVAL$(f x s))$s))\"\n  by (simp add: fold_eq_nfoldli my_fold_def)\n\nsepref_thm my_fold_test is \"\\<lambda>l. do { RETURN (my_fold (\\<lambda>x y. x+y*2) l 0)}\" :: \"(list_assn nat_assn)\\<^sup>k\\<rightarrow>\\<^sub>anat_assn\"\n  by sepref\n\nsubsubsection \\<open>Monadify: Dup\\<close>\ntext \\<open>The last three phases, \\<open>mark_params\\<close>, \\<open>dup\\<close>, \\<open>remove_pass\\<close> are to detect \n  duplicate parameters, and insert \\<open>COPY\\<close> tags. \n  The first phase, \\<open>mark_params\\<close>, adds @{const PASS} tags around all parameters.\n  Parameters are bound variables and terms that have a refinement in the \n  precondition.\n\n  The second phase detects duplicate parameters and inserts @{const COPY} tags\n  to remove them. Finally, the last phase removes the @{const PASS} tags again.\n\n  The methods @{method sepref_dbg_monadify_mark_params}, \n  @{method sepref_dbg_monadify_dup}, and @{method sepref_dbg_monadify_remove_pass}\n  gives you access to these phases.\n\\<close>\n\nsubsubsection \\<open>Monadify: Step-Through Example\\<close>\ntext \\<open>\n  We give an annotated example of the monadify phase.\n  Note that the program utilizes a few features of monadify:\n    \\<^item> The fold function is higher-order, and gets flattened\n    \\<^item> The first argument to fold is eta-contracted. The missing argument is added.\n    \\<^item> The multiplication uses the same argument twice. A copy-tag is inserted.\n\\<close>\nsepref_thm monadify_step_thru_test is \"\\<lambda>l. do {\n    let i = length l;\n    RETURN (fold (\\<lambda>x. (+) (x*x)) l i)\n  }\" :: \"(list_assn nat_assn)\\<^sup>k \\<rightarrow>\\<^sub>a nat_assn\"\n  apply sepref_dbg_preproc\n  apply sepref_dbg_cons_init\n  apply sepref_dbg_id\n\n  apply sepref_dbg_monadify_arity \\<comment> \\<open>Second operand of fold-function is added\\<close>\n  apply sepref_dbg_monadify_comb \\<comment> \\<open>Flattened. \\<open>fold\\<close> rewritten to \\<open>monadic_nfoldli\\<close>.\\<close>\n  (*apply (unfold APP_def PROTECT2_def) (* Make term readable for inspection*) *)\n  apply sepref_dbg_monadify_check_EVAL \\<comment> \\<open>No \\<open>EVAL\\<close> tags left\\<close>\n  apply sepref_dbg_monadify_mark_params \\<comment> \\<open>Parameters marked by \\<open>PASS\\<close>. Note the multiplication \\<open>x*x\\<close>.\\<close>\n  (*apply (unfold APP_def PROTECT2_def) (* Make term readable for inspection*) *)\n  apply sepref_dbg_monadify_dup \\<comment> \\<open>\\<open>COPY\\<close> tag inserted.\\<close>\n  (*apply (unfold APP_def PROTECT2_def) (* Make term readable for inspection*) *)\n  apply sepref_dbg_monadify_remove_pass \\<comment> \\<open>\\<open>PASS\\<close> tag removed again\\<close>\n  (*apply (unfold APP_def PROTECT2_def) (* Make term readable for inspection*) *)\n  \n  apply sepref_dbg_opt_init\n  apply sepref_dbg_trans\n  apply sepref_dbg_opt\n  apply sepref_dbg_cons_solve\n  apply sepref_dbg_cons_solve\n  apply sepref_dbg_constraints\n  done\n\nsubsubsection \\<open>Optimization Init Phase\\<close>\ntext \\<open>This phase, accessed by @{method sepref_dbg_opt_init}, just applies the \n  rule @{thm TRANS_init} to set up a subgoal for a-posteriori optimization\\<close>\n\nsubsubsection \\<open>Translation Phase\\<close>\ntext \\<open>\n  The translation phase is the main phase of the Sepref tool. \n  It performs the actual synthesis of the imperative program from\n  the abstract one. For this, it integrates various components, among others,\n  a frame inference tool, a semantic side-condition solver and a monotonicity prover.\n\n  The translation phase consists of two major sub-phases: \n  Application of translation rules and solving of deferred constraints.\n\n  The method @{method sepref_dbg_trans} executes the translation phase,\n  @{method sepref_dbg_trans_keep} executes the translation phase, \n  presenting the internal goal state of a failed sub-phase.\n\n  The translation rule phase repeatedly applies translation steps, until the \n  subgoal is completely solved. \n\n  The main idea of the translation phase is, that for every abstract variable \\<open>x\\<close> in scope,\n  the precondition contains an assertion of the form @{term \"hn_ctxt A x xi\"}, indicating how\n  this variable is implemented. Common abbreviations are \n  @{term \"hn_val R x xi \\<equiv> hn_ctxt (pure R) x xi\"} \n  and @{term \"hn_invalid A x xi \\<equiv> hn_ctxt (invalid_assn A) x xi\"}.\n\\<close>\n\nsubsubsection \\<open>Translation: Step\\<close>\ntext \\<open>\n  A translation step applies a single synthesis step for an operator,\n  or solves a deferred side-condition. \n\n  There are two types of translation steps: Combinator steps and operator steps.\n  A combinator step consists of applying a rule from @{attribute sepref_comb_rules}\n  to the goal-state. If no such rule applies, the rules are tried again after rewriting\n  the precondition with @{attribute sepref_frame_normrel_eqs} (see frame-inference).\n  The premises of the combinator rule become new subgoals, which are solved by \n  subsequent steps. No backtracking is applied over combinator rules. \n  This restriction has been introduced to make the tool more deterministic, and hence\n  more manageable. \n\n  An operator step applies an operator rule (from @{attribute sepref_fr_rules}) \n  with frame-inference, and then tries to solve the resulting side conditions \n  immediately. If not all side-conditions can be solved, it backtracks over the \n  application of the operator rule. \n\n  Note that, currently, side conditions to operator rules cannot contain \n  synthesis goals themselves. Again, this restriction reduces the tool's \n  complexity by avoiding deep nesting of synthesis. However, it hinders\n  the important feature of generic algorithms, where an operation can issue \n  synthesis subgoals for required operations it is built from (E.g., set union\n  can be implemented by insert and iteration). Our predecessor tool, Autoref,\n  makes heavy use of this feature, and we consider dropping the restriction in \n  the near future.\n\n  An operator-step itself consists of several sub-phases:\n  \\<^descr>[Align goal] Splits the precondition into the arguments actually occurring in\n    the operation, and the rest (called frame).\n  \\<^descr>[Frame rule] Applies a frame rule to focus on the actual arguments. Moreover,\n    it inserts a subgoal of the form @{term \"RECOVER_PURE \\<Gamma> \\<Gamma>'\"}, which is used \n    to restore invalidated arguments if possible. Finally, it generates an assumption\n    of the form @{term \"vassn_tag \\<Gamma>'\"}, which means that the precondition holds\n    on some heap. This assumption is used to extract semantic information from the \n    precondition during side-condition solving.\n\n  \\<^descr>[Recover pure] This phase tries to recover invalidated arguments. \n    An invalidated argument is one that has been destroyed by a previous operation.\n    It occurs in the precondition as @{term \"hn_invalid A x xi\"}, which indicates\n    that there exists a heap where the refinement holds. However, if the refinement \n    assertion \\<open>A\\<close> does not depend on the heap (is \\<^emph>\\<open>pure\\<close>), the invalidated argument\n    can be recovered. The purity assumption is inserted as a constraint (see constraints),\n    such that it can be deferred.\n  \\<^descr>[Apply rule] This phase applies a rule from @{attribute sepref_fr_rules} to\n    the subgoal. If there is no matching rule, matching is retried after rewriting\n    the precondition with @{attribute sepref_frame_normrel_eqs}. If this does not succeed\n    either, a consequence rule is used on the precondition. The implication becomes an \n    additional side condition, which will be solved by the frame inference tool.\n\n    To avoid too much backtracking, the new precondition\n    is massaged to have the same structure as the old one, i.e., it contains a (now schematic)\n    refinement assertion for each operand. This excludes rules for which the frame inference\n    would fail anyway.\n\n    If a matching rule is found, it is applied and all new subgoals are solved by the \n    side-condition solver. If this fails, the tool backtracks over the application of \n    the @{attribute sepref_fr_rules}-rules. Note that direct matches prevent precondition \n    simplification, and matches after precondition simplification prevent the consequence \n    rule to be applied.\n\n  \n  The method @{method sepref_dbg_trans_step} performs a single translation step.\n  The method @{method sepref_dbg_trans_step_keep} presents the internal goal state \n  on failure. If it fails in the \\<open>apply-rule\\<close> phase, it presents the sequence of \n  states with partially unsolved side conditions for all matching rules. \n\\<close>\n\nsubsubsection \\<open>Translation: Side Conditions\\<close>\ntext \\<open>The side condition solver is used to discharge goals that arise as \n  side-conditions to the translation rules. It does a syntactic discrimination \n  of the side condition type, and then invokes the appropriate solver. Currently,\n  it supports the following side conditions:\n  \\<^descr>[Merge] (\\<open>_\\<or>\\<^sub>A_ \\<Longrightarrow>\\<^sub>t _\\<close>). These are used to merge postconditions from different \n    branches of the program (e.g. after an if-then-else). They are solved by the \n    frame inference tool (see section on frame inference).\n  \\<^descr>[Frame] (\\<open>_ \\<Longrightarrow>\\<^sub>t _\\<close>). Used to match up the current precondition against the \n    precondition of the applied rule. Solved by the frame inference tool (see section on frame inference).\n  \\<^descr>[Independence] (\\<open>INDEP (?R x\\<^sub>1 \\<dots> x\\<^sub>n)\\<close>). Deprecated. Used to instantiate a \n    schematic variable such that it does not depend on any bound variables any more. \n    Originally used to make goals more readable, we are considering of dropping this.\n  \\<^descr>[Constraints] (\\<open>CONSTRAINT _ _\\<close>) Apply solver for deferrable constraints (see section on constraints).\n  \\<^descr>[Monotonicity] (\\<open>mono_Heap _\\<close>) Apply monotonicity solver. Monotonicity subgoals occur when\n    translating recursion combinators. Monadic expressions are monotonic by construction, and \n    this side-condition solver just forwards to the monotonicity prover of the partial \n    function package, after stripping any preconditions from the subgoal, which are \n    not supported by the case split mechanism of the monotonicity prover (as of Isabelle2016).\n  \\<^descr>[Prefer/Defer] (\\<open>PREFER_tag _\\<close>/\\<open>DEFER_tag\\<close>). Deprecated. Invoke the tagged solver of \n    the Autoref tool. Used historically for importing refinements from the Autoref tool,\n    but as Sepref becomes more complete imports from Autoref are not required any more.\n  \\<^descr>[Resolve with Premise] \\<open>RPREM _\\<close> Resolve subgoal with one of its premises. \n    Used for translation of recursion combinators. \n  \\<^descr>[Generic Algorithm] \\<open>GEN_ALGO _ _\\<close> Triggers resolution with a rule from\n    @{attribute sepref_gen_algo_rules}. This is a poor-man's version of generic \n    algorithm, which is currently only used to synthesize to-list conversions for foreach-loops.\n  \\<^descr>[Fallback] (Any pattern not matching the above, nor being a \\<open>hn_refine\\<close> goal).\n    Unfolds the application and abstraction tagging, as well as @{term bind_ref_tag} tags \n    which are inserted by several translation rules to indicate the value a variable has \n    been bound to, and then tries to solve the goal by @{method auto}, after freezing \n    schematic variables. This tactic is used to discharge semantic side conditions, e.g.,\n    in-range conditions for array indexing. \n\n\n  Methods: @{method sepref_dbg_side} to apply a side-condition solving step,\n    @{method sepref_dbg_side_unfold} to apply the unfolding of application and binding tags and \n    @{method sepref_dbg_side_keep} to return the internal state after failed side-condition solving.\n\\<close>\n\nsubsubsection \\<open>Translation: Constraints\\<close>\ntext \\<open>During the translation phase, the refinement of operands is not \n  always known immediately, such that schematic variables may occur as refinement \n  assertions. Side conditions on those refinement assertions cannot be discharged \n  until the schematic variable gets instantiated. \n\n  Thus, side conditions may be tagged with @{const CONSTRAINT}. \n  If the side condition solver encounters a constraint side condition, it first removes\n  the constraint tag (@{thm CONSTRAINT_I}) and freezes all schematic variables to prevent them from \n  accidentally getting instantiated. Then it simplifies with @{attribute constraint_simps} and\n  tries to solve the goal using rules from \n  @{attribute safe_constraint_rules} (no backtracking) \n  and @{attribute constraint_rules} (with backtracking).\n\n  If solving the constraint is not successful, only the safe rules are applied, and the \n  remaining subgoals are moved to a special \\<open>CONSTRAINT_SLOT\\<close> subgoal, that always is the \n  last subgoal, and is initialized by the preprocessing phase of Sepref.\n  Moving the subgoal to the constraint slot looks for Isabelle's tacticals like the subgoal \n  has been solved. In reality, it is only deferred and must be solved later.\n  \n  Constraints are used in several phases of Sepref, and all constraints are solved\n  at the end of the translation phase, and at the end of the Sepref invocation.\n  \n  Methods: \n    \\<^item> @{method solve_constraint} to apply constraint solving, the @{const CONSTRAINT}-tag is optional.\n    \\<^item> @{method safe_constraint} to apply safe rules, the @{const CONSTRAINT}-tag is optional.\n    \\<^item> @{method print_slot} to print the contents of the constraint slot.\n\n\\<close>\n\nsubsubsection \\<open>Translation: Merging and Frame Inference\\<close>\ntext \\<open>Frame inference solves goals of the form \\<open>\\<Gamma> \\<Longrightarrow>\\<^sub>t \\<Gamma>'\\<close>.\n  For this, it matches \\<open>hn_ctxt\\<close> components in \\<open>\\<Gamma>'\\<close> with those in \\<open>\\<Gamma>\\<close>.\n  Matching is done according to the refined variables. \n  The matching pairs and the rest is then treated differently: \n  The rest is resolved by repeatedly applying the rules from @{thm frame_rem_thms}.\n  The matching pairs are resolved by repeatedly applying rules from \n  @{thm frame_thms} and @{attribute sepref_frame_match_rules}. \n  Any non-frame premise of these rules must be solved immediately by the \n  side-condition's constraint or fallback tactic (see above). The tool backtracks over rules.\n  If no rule matches (or side-conditions cannot be solved), it simplifies the goal \n  with @{attribute sepref_frame_normrel_eqs} and tries again.\n\n  For merge rules, the theorems @{thm merge_thms} \n  and @{attribute sepref_frame_merge_rules} are used.\n\n  Note that a smart setup of frame and match rules together with side conditions makes \n  the frame matcher a powerful tool for encoding structural and semantic information \n  into relations. An example for structural information are the match rules for lists,\n  which forward matching of list assertions to matching of the element assertions,\n  maintaining the congruence assumption that the refined elements are actually elements \n  of the list: @{thm list_match_cong}.\n  An example for semantic information is the bounded assertion, which intersects\n  any given assertion with a predicate on the abstract domain. The frame matcher is \n  set up such that it can convert between bounded assertions, generating semantic \n  side conditions to discharge implications between bounds (@{thm b_assn_subtyping_match}). \n\n  This is essentially a subtyping mechanism on the level of refinement assertions,\n  which is quite useful for maintaining natural side conditions on operands. \n  A standard example is to maintain a list of array indices: The refinement assertion \n  for array indices is @{term nat_assn} restricted to indices that are in range:\n  @{term \"nbn_assn N\"}. When inserting natural numbers into this list, one has to \n  prove that they are actually in range (conversion from @{term nat_assn} to @{term nbn_assn}).\n  Elements of the list can be used as natural numbers (conversion from @{term nbn_assn} \n  to @{term nat_assn}). Additionally, the side condition solver can derive that the predicate\n  holds on the abstract variable (via the @{const vassn_tag} inserted by the operator steps). \n\\<close>\n\nsubsubsection \\<open>Translation: Annotated Example\\<close>\n\ncontext \n  fixes N::nat \n  notes [[sepref_register_adhoc N]]\n  notes [sepref_import_param] = IdI[of N]\nbegin\n\ntext \\<open>This worked example utilizes the following features of the translation phase:\n  \\<^item> We have a fold combinator, which gets translated by its combinator rule\n  \\<^item> We add a type annotation which enforces converting the natural numbers\n    inserted into the list being refined by \\<open>nbn_assn N\\<close>, i.e., smaller than \\<open>N\\<close>.\n  \\<^item> We can only prove the numbers inserted into the list to be smaller than \\<open>N\\<close>  \n    because the combinator rule for \\<open>If\\<close> inserts congruence assumptions.\n  \\<^item> By moving the elements from the list to the set, they get invalidated.\n    However, as \\<open>nat_assn\\<close> is pure, they can be recovered later, allowing us to \n    mark the list argument as read-only.\n\\<close>\n\nsepref_thm filter_N_test is \"\\<lambda>l. RETURN (fold (\\<lambda>x s.\n  if x<N then insert (ASSN_ANNOT (nbn_assn N) x) s else s\n) l op_hs_empty)\" :: \"(list_assn nat_assn)\\<^sup>k \\<rightarrow>\\<^sub>a hs.assn (nbn_assn N)\"\n\n  apply sepref_dbg_preproc\n  apply sepref_dbg_cons_init\n  apply sepref_dbg_id\n  apply sepref_dbg_monadify\n  \n  apply sepref_dbg_opt_init\n\n  apply sepref_dbg_trans_step \\<comment> \\<open>Combinator rule for bind, \n    generating two \\<open>hn_refine\\<close> goals, and a frame rule to\n    separate the bound variable from the rest.\\<close>\n  apply sepref_dbg_trans_step \\<comment> \\<open>Rule for empty hashset, solves goal\\<close>\n  apply sepref_dbg_trans_step \\<comment> \\<open>Combinator rule for nfoldli (@{thm hn_monadic_nfoldli_rl'})\\<close>\n    apply sepref_dbg_trans_step \\<comment> \\<open>INDEP\\<close>\n    apply sepref_dbg_trans_step \\<comment> \\<open>INDEP\\<close>\n    apply sepref_dbg_trans_step \\<comment> \\<open>Frame to get list and initial state\\<close>\n    apply sepref_dbg_trans_step \\<comment> \\<open>Refinement of continuation condition\\<close>\n    apply sepref_dbg_trans_step \\<comment> \\<open>Frame to recover state after continuation condition\\<close>\n\n    \\<comment> \\<open>Loop body\\<close>\n    apply sepref_dbg_trans_step\n    apply sepref_dbg_trans_step\n    apply sepref_dbg_trans_step\n    apply sepref_dbg_trans_step\n    apply sepref_dbg_trans_step\n    apply sepref_dbg_trans_step\n    apply sepref_dbg_trans_step\n    apply sepref_dbg_trans_step\n    \\<comment> \\<open>At this point, we arrived at the \\<open>nbn_rel\\<close> annotation. \n      There is enough information to show \\<open>x'a < N\\<close>\\<close>\n    apply sepref_dbg_trans_step\n    apply sepref_dbg_trans_step\n    apply sepref_dbg_trans_step\n    apply sepref_dbg_trans_step\n    \\<comment> \\<open>At this point, we have to merge the postconditions from the two if \n      branches. \\<open>nat_rel\\<close> gets merged with \\<open>invalid_assn (nbn_assn n)\\<close>, \n      yielding \\<open>invalid_assn nat_assn\\<close>\\<close>\n    apply sepref_dbg_trans_step\n    apply sepref_dbg_trans_step \\<comment> \\<open>Frame rule separating bound variable from rest\\<close>\n\n    apply sepref_dbg_trans_step \\<comment> \\<open>Frame rule separating fold-state from rest\\<close>\n    apply sepref_dbg_trans_step \\<comment> \\<open>Merging elements of list before body \n      with elements of list after body, to get refinement for resulting list\\<close>\n    \n    apply sepref_dbg_trans_step \\<comment> \\<open>Frame rule from initial bind, separating \n      bound variable from the rest\\<close>\n\n  apply sepref_dbg_opt\n  apply sepref_dbg_cons_solve \\<comment> \\<open>Frame rule, recovering the invalidated list \n    or pure elements, propagating recovery over the list structure\\<close>\n  apply sepref_dbg_cons_solve \\<comment> \\<open>Trivial frame rule\\<close>\n  apply sepref_dbg_constraints\n  done\n\n\n\nend\n\nsubsubsection \\<open>Optimization Phase\\<close>\ntext \\<open>The optimization phase simplifies the generated\n  program, first with @{attribute sepref_opt_simps}, and\n  then with @{attribute sepref_opt_simps2}. \n  For simplification, the tag @{const CNV} is used, which is discharged\n  with @{thm CNV_I} after simplification. \n\n  Method @{method sepref_dbg_opt} gives direct access to this phase.\n  The simplification is used to beautify the generated code.\n  The most important simplifications collapse code that does not \n  depend on the heap to plain expressions (using the monad laws), and\n  apply certain deforestation optimizations.\n  \n  Consider the following example:\n\\<close>\n\nsepref_thm opt_example is \"\\<lambda>n. do { let r = fold (+) [1..<n] 0; RETURN (n*n+2) }\"\n  :: \"nat_assn\\<^sup>k \\<rightarrow>\\<^sub>a nat_assn\"\n  apply sepref_dbg_preproc\n  apply sepref_dbg_cons_init\n  apply sepref_dbg_id\n  apply sepref_dbg_monadify\n  apply sepref_dbg_opt_init\n  apply sepref_dbg_trans\n  \\<comment> \\<open>The generated program contains many superfluous binds, moreover, it actually \n    generates a list and then folds over it\\<close>\n  supply [[show_main_goal]]\n  apply sepref_dbg_opt\n  \\<comment> \\<open>The superfluous binds have been collapsed, and the fold over the list\n    has been replaced by @{const imp_for'}, which uses a counter.\\<close>\n  apply sepref_dbg_cons_solve\n  apply sepref_dbg_cons_solve\n  apply sepref_dbg_constraints\n  done\n\nsubsubsection \\<open>Cons-Solve Phases\\<close>\ntext \\<open>These two phases, accessible via @{method sepref_dbg_cons_solve},\n  applies the frame inference tool to solve the two implications generated\n  by the consequence rule phase.\n\\<close>\n\nsubsubsection \\<open>Constraints Phase\\<close>\ntext \\<open>\n  This phase, accessible via @{method sepref_dbg_constraints}, solve the\n  deferred constraints that are left, and then removes the \\<open>CONSTRAINT_SLOT\\<close> \n  subgoal.\n\\<close>\n\nsubsection \\<open>Refinement Rules\\<close>\ntext \\<open>\n  There are two forms of specifying refinement between an Imperative/HOL program\n  and an abstract program in the \\<open>nres\\<close>-monad.\n  The \\<open>hn_refine\\<close> form (also hnr-form) is the more low-level form.\n  The term @{term \"P \\<Longrightarrow> hn_refine \\<Gamma> c \\<Gamma>' R a\"} states that, under precondition \\<open>P\\<close>, for \n  a heap described by \\<open>\\<Gamma>\\<close>, the Imperative/HOL program \\<open>c\\<close> produces a heap described by \n  \\<open>\\<Gamma>'\\<close> and the result is refined by \\<open>R\\<close>. Moreover, the abstract result is among the possible \n  results of the abstract program \\<open>a\\<close>.\n  \n  This low-level form formally enforces no restrictions on its arguments, however, there are\n  some assumed by our tool:\n    \\<^item> \\<open>\\<Gamma>\\<close> must have the form \\<open>hn_ctxt A\\<^sub>1 x\\<^sub>1 xi\\<^sub>1 * \\<dots> * hn_ctxt A\\<^sub>n x\\<^sub>n xi\\<^sub>n\\<close>\n    \\<^item> \\<open>\\<Gamma>'\\<close> must have the form \\<open>hn_ctxt B\\<^sub>1 x\\<^sub>1 xi\\<^sub>1 * \\<dots> * hn_ctxt B\\<^sub>n x\\<^sub>n xi\\<^sub>n\\<close>\n      where either \\<open>B\\<^sub>i = A\\<^sub>i\\<close> or \\<open>B\\<^sub>i = invalid_assn A\\<^sub>i\\<close>. This means that each argument to\n      the program is either preserved or destroyed.\n    \\<^item> \\<open>R\\<close> must not contain a \\<open>hn_ctxt\\<close> tag.\n    \\<^item> \\<open>a\\<close> must be in protected form (@{term \"($)\"} and @{term \"PROTECT2\"} tags)\n\n  The high-level \\<open>hfref\\<close> form formally enforces these restrictions. Moreover,\n  it assumes \\<open>c\\<close> and \\<open>a\\<close> to be presented as functions from exactly one argument.\n  For constants or functions with more arguments, you may use @{term uncurry0} \n  and @{term uncurry}. (Also available @{term uncurry2} to @{term uncurry5}).\n\n  The general form is \\<open>PC \\<Longrightarrow> (uncurry\\<^sub>x f, uncurry\\<^sub>x g) \\<in> [P]\\<^sub>a A\\<^sub>1\\<^sup>k\\<^sup>1 *\\<^sub>a \\<dots> *\\<^sub>a A\\<^sub>n\\<^sup>k\\<^sup>n \\<rightarrow> R\\<close>,\n  where \\<open>ki\\<close> is \\<open>k\\<close> if the argument is preserved (kept) or \\<open>d\\<close> is it is destroyed.\n  \\<open>PC\\<close> are preconditions of the rule that do not depend on the arguments, usually\n  restrictions on the relations. \\<open>P\\<close> is a predicate on the single argument of \\<open>g\\<close>,\n  representing the precondition that depends on the arguments.\n\n  Optionally, \\<open>g\\<close> may be of the form \\<open>RETURN o\\<dots>o g'\\<close>, in which case the rule \n  applies to a plain function.\n\n  If there is no precondition, there is a shorter \n  syntax: @{term \"Args\\<rightarrow>\\<^sub>aR \\<equiv> [\\<lambda>_. True]\\<^sub>a Args\\<rightarrow>R\"}.\n\n  For example, consider @{thm [source] arl_swap_hnr[unfolded pre_list_swap_def]}.\n  It reads @{term \"CONSTRAINT is_pure A \\<Longrightarrow>\n    (uncurry2 arl_swap, uncurry2 (RETURN \\<circ>\\<circ>\\<circ> op_list_swap))\n    \\<in> [\\<lambda>((l, i), j). i < length l \\<and> j < length l]\\<^sub>a \n    (arl_assn A)\\<^sup>d *\\<^sub>a nat_assn\\<^sup>k *\\<^sub>a nat_assn\\<^sup>k \\<rightarrow> arl_assn A\"}\n\n  We have three arguments, the list and two indexes. The refinement assertion \\<open>A\\<close>\n  for the list elements must be pure, and the indexes must be in range.\n  The original list is destroyed, the indexes are kept.\n\\<close>\nthm arl_swap_hnr[unfolded pre_list_swap_def, no_vars]\n\nsubsubsection \\<open>Converting between hfref and hnr form\\<close>\ntext \\<open>A subgoal in hfref form is converted to hnr form by\n  the preprocessing phase of Sepref (see there for a description).\n\n  Theorems with hnr/hfref conclusions can be converted\n  using @{attribute to_hfref}/@{attribute to_hnr}.\n  This conversion is automatically done for rules registered with \n  @{attribute sepref_fr_rules}, such that this attribute accepts both forms.\n\n  Conversion to hnr-form can be controlled by specifying \n  @{attribute to_hnr_post} unfold-rules, which are applied after the conversion.\n\n  Note: These currently contain hard-coded rules to handle \\<open>RETURN o\\<dots>o _\\<close> for up \n    to six arguments. If you have more arguments, you need to add corresponding rules here,\n    until this issue is fixed and the tool can produce such rules automatically.\n    \n  Similarly, @{attribute to_hfref_post} is applied after conversion to hfref form.\n\\<close>\n\nthm to_hnr_post\nthm to_hfref_post\n\nsubsubsection \\<open>Importing Parametricity Theorems\\<close>\ntext \\<open>For pure refinements, it is sometimes simpler to specify a parametricity \n  theorem than a hnr/hfref theorem, in particular as there is a large number of \n  parametricity theorems readily available, in the parametricity component or Autoref,\n  and in the Lifting/Transfer tool.\n  \n  Autoref uses a set-based notation for parametricity theorems \n  (e.g. @{term \"((@),(@)) \\<in> \\<langle>A\\<rangle>list_rel \\<rightarrow> \\<langle>A\\<rangle>list_rel \\<rightarrow> \\<langle>A\\<rangle>list_rel\"}), \n  while lifting/transfer uses a predicate based notation (e.g. \n    @{term \"rel_fun (list_all2 A) (rel_fun (list_all2 A) (list_all2 A)) (@) (@)\"}).\n\n  Currently, we only support the Autoref style, but provide a few lemmas that \n  ease manual conversion from the Lifting/Transfer style.\n\n  Given a parametricity theorem, the attribute @{attribute sepref_param}\n  converts it to a hfref theorem, the attribute \n  @{attribute sepref_import_param} does the conversion and registers the result\n  as operator rule.\n  Relation variables are converted to assertion variables with an \\<open>is_pure\\<close> constraint.\n\n  The behaviour can be customized by @{attribute sepref_import_rewrite}, which\n  contains rewrite rules applied in the last but one step of the conversion, before\n  converting relation variables to assertion variables. \n  These theorems can be used to convert relations to there corresponding assertions,\n  e.g., @{thm list_assn_pure_conv[symmetric]} converts a list relation to a list \n  assertion.\n\n\n  For debugging purposes, the attribute @{attribute sepref_dbg_import_rl_only}\n  converts a parametricity theorem to a hnr-theorem. This is the first step of \n  the standard conversion, followed by a conversion to hfref form.\n\\<close>\n\nthm sepref_import_rewrite\nthm param_append \\<comment> \\<open>Parametricity theorem for append\\<close>\nthm param_append[sepref_param] \\<comment> \\<open>Converted to hfref-form. \n  \\<open>list_rel\\<close> is rewritten to \\<open>list_assn\\<close>, and the relation variable is replaced by an \n  assertion variable and a \\<open>is_pure\\<close> constraint.\\<close>\nthm param_append[sepref_dbg_import_rl_only]\n\n\ntext \\<open>For re-using Lifting/Transfer style theorems, the constants \n  @{const p2rel} and @{const rel2p} may be helpful, however, there is no\n  automation available yet.\n\n  Usage examples can be found in, e.g., @{theory Refine_Imperative_HOL.IICF_Multiset}, where we \n  import parametricity lemmas for multisets from the Lifting/Transfer package.\n\\<close>\n\nthm p2rel \\<comment> \\<open>Simp rules to convert predicate to relational style\\<close>\nthm rel2p \\<comment> \\<open>Simp rules to convert relational to predicate style\\<close>\n\n\nsubsection \\<open>Composition\\<close>\n\nsubsubsection \\<open>Fref-Rules\\<close>\ntext \\<open>\n  In standard parametricity theorems as described above, one cannot specify\n  preconditions for the parameters, e.g., @{term hd} is only parametric for \n  non-empty lists. \n\n  As of Isabelle2016, the Lifting/Transfer package cannot specify\n  such preconditions at all.\n\n  Autoref's parametricity tool can specify such preconditions by using first-order rules,\n  (cf. @{thm param_hd}). However, currently, @{attribute sepref_import_param} cannot handle \n  these first-order rules. \n\n  Instead, Sepref supports the fref-format for parametricity rules, which resembles the \n  hfref-format: Abstract and concrete objects are functions with exactly one parameter, \n  uncurried if necessary. Moreover, there is an explicit precondition.\n  The syntax is \\<open>(uncurry\\<^sub>x f, uncurry\\<^sub>x g) \\<in> [P]\\<^sub>f (...(R\\<^sub>1\\<times>\\<^sub>rR\\<^sub>2)\\<times>\\<^sub>r...)\\<times>\\<^sub>rR\\<^sub>n) \\<rightarrow> R\\<close>,\n  and without precondition, we have \\<open>(...(R\\<^sub>1\\<times>\\<^sub>rR\\<^sub>2)\\<times>\\<^sub>r...)\\<times>\\<^sub>rR\\<^sub>n) \\<rightarrow>\\<^sub>f R\\<close>. \n  Note the left-bracketing of the tuples, which is non-standard in Isabelle.\n  As we currently have no syntax for a left-associative product relation, we\n  use the right-associative syntax @{term \"(\\<times>\\<^sub>r)\"} and explicit brackets.\n\n  The attribute @{attribute to_fref} can convert (higher-order form) parametricity \n  theorems to the fref-form.\n\\<close>\n\nsubsubsection \\<open>Composition of hfref and fref theorems\\<close>\ntext \\<open>\n  fref and hfref theorems can be composed, if the \n  abstract function or the first theorem equals the concrete function of the \n  second theorem. Currently, we can compose an hfref with an fref theorem, \n  yielding a hfref theorem, and two fref-theorems, yielding an fref theorem.\n  As we do not support refinement of heap-programs, but only refinement \\<^emph>\\<open>into\\<close> heap \n  programs, we cannot compose two hfref theorems.\n\n  The attribute @{attribute FCOMP} does these compositions and normalizes the result.\n  Normalization consists of precondition simplification, and distributing composition\n  over products, such that composition can be done argument-wise. \n  For this, we unfold with @{attribute fcomp_norm_unfold}, and then simplify with\n  @{attribute fcomp_norm_simps}.\n\n  The \\<open>FCOMP\\<close> attribute tries to convert its arguments to hfref/fref form, such that\n  it also accepts hnr-rules and parametricity rules.\n\n  The standard use-case for \\<open>FCOMP\\<close> is to compose multiple refinement steps to\n  get the final correctness theorem. Examples for this are in the quickstart guide.\n\n  Another use-case for \\<open>FCOMP\\<close> is to compose a refinement theorem of a \n  container operation, that refines the elements by identity, with a parametricity theorem\n  for the container operation, that adds a (pure) refinement of the elements.\n  In practice, the high-level utilities @{command sepref_decl_op} and \n  @{command sepref_decl_impl} are used for this purpose. Internally, they use \\<open>FCOMP\\<close>.\n\\<close>\n\nthm fcomp_norm_unfold\nthm fcomp_norm_simps\n\nthm array_get_hnr_aux \\<comment> \\<open>Array indexing, array elements are refined by identity\\<close>\nthm \"op_list_get.fref\" \\<comment> \\<open>Parametricity theorem for list indexing\\<close>\n\nthm array_get_hnr_aux[FCOMP op_list_get.fref] \\<comment> \\<open>Composed theorem\\<close>\n\n\\<comment> \\<open>Note the definition @{thm array_assn_def}\\<close>\ncontext\n  notes [fcomp_norm_unfold] = array_assn_def[symmetric]\nbegin\n  thm array_get_hnr_aux[FCOMP op_list_get.fref] \\<comment> \\<open>Composed theorem, \\<open>array_assn\\<close> folded.\\<close>\nend\n\nsubsection \\<open>Registration of Interface Types\\<close>\ntext \\<open>\n  An interface type represents some conceptual type, which is encoded to a \n  more complex type in HOL. For example, the interface type @{typ \"('k,'v)i_map\"}\n  represents maps, which are encoded as @{typ \"'k \\<Rightarrow> 'v option\"} in HOL.\n\n  New interface types must be registered by the command @{command sepref_decl_intf}.\n\\<close>\n\nsepref_decl_intf ('a,'b) i_my_intf is \"'a*'a \\<Rightarrow> 'b option\"\n\\<comment> \\<open>Declares @{typ \"('a,'b) i_my_intf\"} as new interface type, and registers it\n  to correspond to @{typ \"'a*'a \\<Rightarrow> 'b option\"}. \n  Note: For HOL, the interface type is just an arbitrary new type, which is \n    not related to he corresponding HOL type.\\<close>\n\nsepref_decl_intf ('a,'b) i_my_intf2 (infix \"*\\<rightarrow>\\<^sub>i\" 0) is \"'a*'a \\<Rightarrow> 'b option\"\n\\<comment> \\<open>There is also a version that declares infix-syntax for the interface type.\n  In this case we have @{typ \"'a *\\<rightarrow>\\<^sub>i 'b\"}. @{typ \"'a\\<rightharpoonup>'b\"}\n  Be aware of syntax space pollution, as the syntax for interface types and \n  HOL types is the same.\\<close>\n\n\n\nsubsection \\<open>Registration of Abstract Operations\\<close>\ntext \\<open>\n  Registering a new abstract operation requires some amount of setup,\n  which is automated by the \\<open>sepref_register\\<close> tool. Currently, it only \n  works for operations, not for combinators. \n\n  The @{command sepref_register} command takes a list of terms and registers \n  them as operators. Optionally, each term can have an interface type annotation. \n\n  If there is no interface type annotation, the interface type is derived from the \n  terms HOL type, which is rewritten by the theorems from @{attribute map_type_eqs}.\n  This rewriting is useful for bulk-setup of many constants with conceptual types \n  different from there HOL-types. \n  Note that the interface type must correspond to the HOL type of the registered term,\n  otherwise, you'll get an error message.\n\n  If the term is not a single constant or variable, and does not already start \n  with a @{const PR_CONST} tag, such a tag will be added, and also a pattern rule \n  will be registered to add the tag on operator identification.\n  \n  If the term has a monadic result type (@{typ \"_ nres\"}), also an \n  arity and combinator rule for the monadify phase are generated.\n\n  There is also an attribute version @{attribute \"sepref_register_adhoc\"}.\n  It has the same syntax, and generates the same theorems, but does not give\n  names to the theorems. It's main application is to conveniently register fixed\n  variables of a context. Warning: Make sure not to export such an attribute from \n  the context, as it may become meaningless outside the context, or worse, confuse \n  the tool.\n\\<close>\n\ntext \\<open>Example for bulk-registration, utilizing type-rewriting\\<close>\n\ndefinition \"map_op1 m n \\<equiv> m(n\\<mapsto>n+1)\"\ndefinition \"map_op2 m n \\<equiv> m(n\\<mapsto>n+2)\"\ndefinition \"map_op3 m n \\<equiv> m(n\\<mapsto>n+3)\"\ndefinition \"map_op_to_map (m::'a\\<rightharpoonup>'b) \\<equiv> m\"\n\ncontext\n  notes [map_type_eqs] = map_type_eqI[of \"TYPE('a\\<rightharpoonup>'b)\" \"TYPE(('a,'b)i_map)\"]\nbegin\n  sepref_register map_op1 map_op2 map_op3 \n  \\<comment> \\<open>Registered interface types use \\<open>i_map\\<close>\\<close>\n  sepref_register map_op_to_map :: \"('a\\<rightharpoonup>'b) \\<Rightarrow> ('a,'b) i_map\"\n  \\<comment> \\<open>Explicit type annotation is not rewritten\\<close>\nend\n\ntext \\<open>Example for insertion of \\<open>PR_CONST\\<close> tag and attribute-version\\<close>\n\ncontext\n  fixes N :: nat and D :: int\n  notes [[sepref_register_adhoc N D]]\n  \\<comment> \\<open>In order to use \\<open>N\\<close> and \\<open>D\\<close> as operators (constant) inside this context,\n    they have to be registered. However, issuing a \\<open>sepref_register\\<close> command \n    inside the context would export meaningless registrations to the global \n    theory.\\<close>\n\n  notes [sepref_import_param] = IdI[of N] IdI[of D]\n  \\<comment> \\<open>For declaring refinement rules, the \\<open>sepref_import_param\\<close> attribute comes \n    in handy here. If this is not possible, you have to work with nested contexts,\n    proving the refinement lemmas in the first level, and declaring them as\n    \\<open>sepref_fr_rules\\<close> on the second level.\\<close>\n\nbegin\n  definition \"newlist \\<equiv> replicate N D\"\n\n  sepref_register newlist\n  print_theorems\n  \\<comment> \\<open>\\<open>PR_CONST\\<close> tag is added, pattern rule is generated\\<close>\n\n  sepref_register other_basename_newlist: newlist\n  print_theorems\n  \\<comment> \\<open>The base name for the generated theorems can be overridden\\<close>\n\n  sepref_register yet_another_basename_newlist: \"PR_CONST newlist\"\n  print_theorems\n  \\<comment> \\<open>If \\<open>PR_CONST\\<close> tag is specified, no pattern rule is generated automatically\\<close>\n\nend\n\ntext \\<open>Example for mcomb/arity theorems\\<close>\ndefinition \"select_a_one l \\<equiv> SPEC (\\<lambda>i. i<length l \\<and> l!i = (1::nat))\"\n\nsepref_register \"select_a_one\"\n  print_theorems\n  \\<comment> \\<open>Arity and mcomb theorem is generated\\<close>\n\n\ntext \\<open>\n  The following command fails, as the specified interface type does not\n  correspond to the HOL type of the term:\n  @{theory_text \\<open>sepref_register hd :: \"(nat,nat) i_map\"\\<close>}\n\\<close>\n\nsubsection \\<open>High-Level tools for Interface/Implementation Declaration\\<close>\ntext \\<open>\n  The Imperative Isabelle Collections Framework (IICF), which comes with Sepref,\n  has a concept of interfaces, which specify a set of abstract operations for\n  a conceptual type, and implementations, which implement these operations.\n  \n  Each operation may have a natural precondition, which is established already \n  for the abstract operation. Many operations come in a plain version, and a \n  monadic version which asserts the precondition. Implementations may \n  strengthen the precondition with implementation specific preconditions.\n\n  Moreover, each operation comes with a parametricity lemma. \n  When registering an implementation, the refinement of the implementation is\n  combined with the parametricity lemma to allow for (pure) refinements of the \n  element types.\n\n  @{rail \\<open>@@{command sepref_decl_op} ('(' @{text flags} ')')? \\<newline>\n      (@{text name} @':')?  @{text term} @'::' @{text term} \\<newline>\n      (@'where' @{text props})? \\<close>}  \n  \n  The command @{command sepref_decl_op} declares an abstract operation.\n  It takes a term defining the operation, and a parametricity relation.\n  It generates the monadic version from the plain version, defines constants\n  for the operations, registers them, and tries to prove parametricity lemmas\n  automatically. Parametricity must be proved for the operation, and for the \n  precondition. If the automatic parametricity proofs fail, the user gets \n  presented goals that can be proven manually.\n\n  Optionally, a basename for the operation can be specified. If none is specified, \n  a heuristics tries to derive one from the specified term.\n\n  A list of properties (separated by space and/or \\<open>and\\<close>) can be specified, \n  which get constraint-preconditions of the relation. \n\n  Finally, the following flags can be specified. Each flag can be prefixed by \\<open>no_\\<close> \n  to invert its meaning:\n  \\<^descr>[mop] (default: true) Generate monadic version of operation\n  \\<^descr>[ismop] (default: false) Indicate that given term is the monadic version\n  \\<^descr>[rawgoals] (default: false) Present raw goals to user, without attempting to prove them\n  \\<^descr>[def] (default: true) Define a constant for the specified term. Otherwise, use the specified term literally.\n\n\\<close>\n\ntext \\<open>\n  \n  @{rail \\<open>@@{command sepref_decl_impl} ('(' @{text flags} ')')? \\<newline>\n    (@{text name} @':')? (@'[' @{text term} @']')? \\<newline>\n    @{text thm} (@'uses' @{text thm})?\n    \\<close>}  \n\n  The @{command sepref_decl_impl} command declares an implementation of an interface operation.\n  It takes a refinement theorem for the implementation, and combines it with the corresponding\n  parametricity theorem. After \\<open>uses\\<close>, one can override the parametricity theorem to be used.\n  A heuristics is used to merge the preconditions of the refinement and parametricity theorem.\n  This heuristics can be overridden by specifiying the desired precondition inside \\<open>[\\<dots>]\\<close>.\n  Finally, the user gets presented remaining subgoals that cannot be solved by the heuristics.\n  The command accepts the following flags:\n  \\<^descr>[mop] (default: true) Generate implementation for monadic version\n  \\<^descr>[ismop] (default: false) Declare that the given theorems refer to the monadic version\n  \\<^descr>[transfer] (default: true) Try to automatically transfer the implementation's precondition\n    over the argument relation from the parametricity theorem.\n  \\<^descr>[rawgoals] (default: false) Do not attempt to solve or simplify the goals\n  \\<^descr>[register] (default: true) Register the generated theorems as operation rules. \n\\<close>\n\nsubsection \\<open>Defining synthesized Constants\\<close>\ntext \\<open>\n  The @{command sepref_definition} allows one to specify a name, an abstract term and\n  a desired refinement relation in hfref-form. It then sets up a goal that can be\n  massaged (usually, constants are unfolded and annotations/implementation specific \n  operations are added) and then solved by @{method sepref}.\n  After the goal is solved, the command extracts the synthesized term and defines it as\n  a constant with the specified name. Moreover, it sets up code equations for the constant,\n  correctly handling recursion combinators. Extraction of code equations is controlled by the\n  \\<open>prep_code\\<close> flag. Examples for this command can be found in the quickstart guide.\n\\<close>\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Evaluation/Refine_Imperative_HOL/Userguides/Sepref_Guide_Reference.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5156199157230157, "lm_q2_score": 0.5467381519846138, "lm_q1q2_score": 0.28190907984886393}}
{"text": "section \\<open> COMPASS Modelling Language \\<close>\n\ntheory utp_cml\nimports \"UTP1-Reactive-Designs.utp_rea_designs\" \"UTP1.utp_full\"\nbegin\n\nsubsection \\<open> Preliminaries \\<close>\n\ndatatype '\\<theta> tevent = Tock \"'\\<theta> set\" | Event '\\<theta>\n\ntype_synonym ('\\<sigma>,'\\<theta>) st_cml      = \"('\\<sigma>, '\\<theta> tevent list, unit) rsp\"\ntype_synonym ('\\<sigma>,'\\<theta>) cmlact      = \"('\\<sigma>,'\\<theta>) st_cml hrel\"\ntype_synonym ('a,'\\<sigma>,'\\<theta>) expr_cml = \"('a, ('\\<sigma>,'\\<theta>) st_cml \\<times> ('\\<sigma>,'\\<theta>) st_cml) uexpr\"\n\nfun events :: \"'\\<theta> tevent list \\<Rightarrow> '\\<theta> tevent list\" where\n\"events [] = []\" |\n\"events (Tock A # t) = events t\" |\n\"events (Event x # t) = (Event x # events t)\"\n\nlemma events_append [simp]: \"events (xs @ ys) = events(xs) @ events(ys)\"\n  apply (induct xs, simp_all)\n  apply (rename_tac x xs)\n  apply (case_tac x)\n  apply (simp_all)\ndone\n\nfun tocks :: \"'\\<theta> tevent list \\<Rightarrow> '\\<theta> tevent list\" where\n\"tocks [] = []\" |\n\"tocks (Tock A # xs) = Tock A # tocks xs\" |\n\"tocks (Event x # xs) = tocks xs\"\n\nfun refusals :: \"'\\<theta> tevent list \\<Rightarrow> '\\<theta> set\" where\n\"refusals [] = {}\" |\n\"refusals (Tock A # t) = A \\<union> refusals t\" |\n\"refusals (Event x # t) = refusals t\"\n\nfun idleprefix :: \"'\\<theta> tevent list \\<Rightarrow> '\\<theta> tevent list\" where\n\"idleprefix [] = []\" |\n\"idleprefix (Tock A # t) = (Tock A # idleprefix t)\" |\n\"idleprefix (Event x # t) = []\"\n\ndefinition \"idlesuffix = idleprefix \\<circ> rev\"\n\nsyntax\n  \"_events\"     :: \"logic \\<Rightarrow> logic\" (\"events\\<^sub>u'(_')\")\n  \"_tocks\"      :: \"logic \\<Rightarrow> logic\" (\"tocks\\<^sub>u'(_')\")\n  \"_refusals\"   :: \"logic \\<Rightarrow> logic\" (\"refusals\\<^sub>u'(_')\")\n  \"_idleprefix\" :: \"logic \\<Rightarrow> logic\" (\"idleprefix\\<^sub>u'(_')\")\n  \"_idlesuffix\" :: \"logic \\<Rightarrow> logic\" (\"idlesuffix\\<^sub>u'(_')\")\n  \"_ev\"         :: \"logic \\<Rightarrow> logic\" (\"ev\\<^sub>u'(_')\")\n  \"_tock\"       :: \"logic \\<Rightarrow> logic \\<Rightarrow> logic\" (\"tock\\<^sub>u'(_,_')\")\n\ntranslations\n  \"events\\<^sub>u(t)\" == \"CONST uop CONST events t\"\n  \"tocks\\<^sub>u(t)\" == \"CONST uop CONST tocks t\"\n  \"refusals\\<^sub>u(t)\" == \"CONST uop CONST refusals t\"\n  \"idleprefix\\<^sub>u(t)\" == \"CONST uop CONST idleprefix t\"\n  \"idlesuffix\\<^sub>u(t)\" == \"CONST uop CONST idlesuffix t\"\n  \"ev\\<^sub>u(e)\" == \"CONST uop CONST Event e\"\n  \"tock\\<^sub>u(t,A)\" == \"CONST bop CONST Tock t A\"\n\nsubsection \\<open> Signature \\<close>\n\nabbreviation time_length :: \"(nat,'\\<sigma>,'\\<theta>) expr_cml\" (\"\\<^bold>l\")\n  where \"\\<^bold>l \\<equiv> U(length(tocks(&tt)))\"\n\nabbreviation CML :: \"(('\\<sigma>, '\\<phi>) st_cml \\<times> ('\\<sigma>, '\\<phi>) st_cml) health\"\n  where \"CML \\<equiv> SRD\"\n\nabbreviation Skip :: \"('\\<sigma>,'\\<theta>) cmlact\" where\n\"Skip \\<equiv> II\\<^sub>R\"\n\nabbreviation Assigns :: \"'\\<sigma> usubst \\<Rightarrow> ('\\<sigma>,'\\<theta>) cmlact\" (\"\\<langle>_\\<rangle>\\<^sub>C\") where\n\"Assigns \\<sigma> \\<equiv> \\<langle>\\<sigma>\\<rangle>\\<^sub>R\"\n\ndefinition Stop :: \"('\\<sigma>,'\\<theta>) cmlact\" where\n[upred_defs]: \"Stop = \\<^bold>R\\<^sub>s(true \\<turnstile> U(events(&tt) = []) \\<diamondop> false)\"\n\ndefinition DoCML :: \"('\\<theta>, '\\<sigma>) uexpr \\<Rightarrow> ('\\<sigma>,'\\<theta>) cmlact\" where\n  [upred_defs]:\n  \"DoCML a = \\<^bold>R\\<^sub>s(true \\<turnstile> U(events(&tt) = [] \\<and> \\<lceil>a\\<rceil>\\<^sub>S\\<^sub>< \\<notin> refusals(&tt))\n                      \\<diamondop> U(&tt = idleprefix(&tt) @ [Event(\\<lceil>a\\<rceil>\\<^sub>S\\<^sub><)]\n                         \\<and> $st\\<acute> = $st \\<and> \\<lceil>a\\<rceil>\\<^sub>S\\<^sub>< \\<notin> refusals(&tt)))\"\n\ndefinition Wait :: \"(nat, '\\<sigma>) uexpr \\<Rightarrow> ('\\<sigma>,'\\<theta>) cmlact\" where\n  [upred_defs, rdes_def]:\n  \"Wait n = \\<^bold>R\\<^sub>s(true \\<turnstile> U(events(&tt) = [] \\<and> length(&tt) < \\<lceil>n\\<rceil>\\<^sub>S\\<^sub><)\n                    \\<diamondop> U(events(&tt) = [] \\<and> length(&tt) = \\<lceil>n\\<rceil>\\<^sub>S\\<^sub><\n                       \\<and> $st\\<acute> = $st))\"\n\nlemma Skip_def: \"Skip = \\<^bold>R\\<^sub>s(true \\<turnstile> false \\<diamondop> ($tr\\<acute> =\\<^sub>u $tr \\<and> $st\\<acute> =\\<^sub>u $st))\"\n  by (simp add: srdes_skip_def, rel_auto)\n\nsubsection \\<open> Healthiness conditions \\<close>\n\nabbreviation RT1 :: \"('\\<sigma>,'\\<theta>) cmlact \\<Rightarrow> ('\\<sigma>,'\\<theta>) cmlact\" where \"RT1 \\<equiv> R1\"\nabbreviation RT2 :: \"('\\<sigma>,'\\<theta>) cmlact \\<Rightarrow> ('\\<sigma>,'\\<theta>) cmlact\" where \"RT2 \\<equiv> R2c\"\nabbreviation RT3 :: \"('\\<sigma>,'\\<theta>) cmlact \\<Rightarrow> ('\\<sigma>,'\\<theta>) cmlact\" where \"RT3 \\<equiv> R3h\"\nabbreviation RT4 :: \"('\\<sigma>,'\\<theta>) cmlact \\<Rightarrow> ('\\<sigma>,'\\<theta>) cmlact\" where \"RT4 \\<equiv> RD1\"\nabbreviation RT5 :: \"('\\<sigma>,'\\<theta>) cmlact \\<Rightarrow> ('\\<sigma>,'\\<theta>) cmlact\" where \"RT5 \\<equiv> RD2\"\nabbreviation RT6 :: \"('\\<sigma>,'\\<theta>) cmlact \\<Rightarrow> ('\\<sigma>,'\\<theta>) cmlact\" where \"RT6(P) \\<equiv> Skip ;; P\"\nabbreviation RT7 :: \"('\\<sigma>,'\\<theta>) cmlact \\<Rightarrow> ('\\<sigma>,'\\<theta>) cmlact\" where \"RT7 \\<equiv> RD3\"\n\nabbreviation RT :: \"('\\<sigma>,'\\<theta>) cmlact \\<Rightarrow> ('\\<sigma>,'\\<theta>) cmlact\"\nwhere \"RT \\<equiv> RT1 \\<circ> RT2 \\<circ> RT3 \\<circ> RT4 \\<circ> RT7\"\n\ntext \\<open> For the time being we omit RT8. We also omit RT5 and RT6 as, as they are both tautologies \n  of the reduced theory, as we shall show. \\<close>\n\ntext \\<open> The following definition is taken from (Canham and Woodcock, 2014) \\<close>\n\nlemma Skip_CML_def: \"Skip = (RT3 \\<circ> RT4) (\\<not> $wait\\<acute> \\<and> $tr\\<acute> =\\<^sub>u $tr \\<and> $st\\<acute> =\\<^sub>u $st \\<and> $ok\\<acute>)\"\n  by (rel_auto)\n\nsubsection \\<open> Laws \\<close>\n\nlemma Wait_0: \"Wait 0 = Skip\"\nproof -\n  have \"Wait 0 = \\<^bold>R\\<^sub>s(true \\<turnstile> U(events(&tt) = [] \\<and> 0 > length(&tt)) \\<diamondop> U(events(&tt) = [] \\<and> length(&tt) = 0 \\<and> $st\\<acute> = $st))\"\n    (is \"?lhs = \\<^bold>R\\<^sub>s(?P \\<turnstile> ?Q \\<diamondop> ?R)\")\n    by (simp add: Wait_def alpha)\n  also have \"... = \\<^bold>R\\<^sub>s(true \\<turnstile> false \\<diamondop> ($tr\\<acute> =\\<^sub>u $tr \\<and> $st\\<acute> =\\<^sub>u $st))\"\n  proof -\n    have 1:\"?Q = false\"\n      by (pred_auto)\n    have 2:\"R1(?R) = ($tr\\<acute> =\\<^sub>u $tr \\<and> $st\\<acute> =\\<^sub>u $st)\"\n      by (rel_auto)\n    show ?thesis\n      by (metis (no_types, lifting) \"1\" \"2\" RHS_design_post_R1)\n  qed\n  also have \"... = Skip\"\n    by (simp add: Skip_def)\n  finally show ?thesis .\nqed\n\nlemma skip_lift_state [alpha]: \"\\<lceil>II\\<rceil>\\<^sub>S = ($st\\<acute> =\\<^sub>u $st)\"\n  by (rel_auto)\n\nlemma Stop_left_zero:\n  assumes \"P is CML\"\n  shows \"Stop ;; P = Stop\"\nproof -\n  have \"Stop ;; P = \\<^bold>R\\<^sub>s(true \\<turnstile> U(events(&tt) = []) \\<diamondop> false) ;; \\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> peri\\<^sub>R(P) \\<diamondop> post\\<^sub>R(P))\"\n    by (simp add: SRD_reactive_tri_design Stop_def assms)\n  also have \"... = \\<^bold>R\\<^sub>s (true \\<turnstile> U(\\<exists> $st\\<acute> \\<bullet> events(&tt) = []) \\<diamondop> false)\"\n    by (subst RHS_tri_design_composition, simp_all add: unrest R2s_true R1_false R2s_false)\n  also have \"... = \\<^bold>R\\<^sub>s (true \\<turnstile> U(events(&tt) = []) \\<diamondop> false)\"\n    by (simp add: ex_unrest unrest)\n  finally show ?thesis\n    by (simp add: Stop_def)\nqed\n\n(*\nlemma Wait_m_plus_n: \"(Wait m ;; Wait n) = (Wait (m + n))\"\nproof -\n  have 1: \"(R2 (events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> #\\<^sub>u(&tt) =\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st) ;; R2 (events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> \\<lceil>n\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(&tt))) =\n         R2 (events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<le>\\<^sub>u #\\<^sub>u(&tt) \\<and> #\\<^sub>u(&tt) <\\<^sub>u \\<lceil>m + n\\<rceil>\\<^sub>S\\<^sub><)\" (is \"?lhs = ?rhs\")\n  proof -\n    have \"?lhs = (\\<^bold>\\<exists> tt\\<^sub>1 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>2 \\<bullet> (((events\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> #\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st) ;;\\<^sub>h\n                                   (events\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> \\<lceil>n\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>))) \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>1\\<guillemotright> + \\<guillemotleft>tt\\<^sub>2\\<guillemotright>))\"\n      by (simp add: R2_seqr_form usubst unrest, rel_auto)\n    also have \"... = (\\<^bold>\\<exists> tt\\<^sub>1 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>2 \\<bullet> ((events\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> (#\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st) ;;\\<^sub>h\n                                       (\\<lceil>n\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>) \\<and> events\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle>))) \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>1\\<guillemotright> + \\<guillemotleft>tt\\<^sub>2\\<guillemotright>)\"\n      by (simp add: seqr_pre_out unrest conj_assoc, simp add: conj_comm)\n    also have \"... = (\\<^bold>\\<exists> tt\\<^sub>1 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>2 \\<bullet> events\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> ((#\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st) ;;\\<^sub>h\n                                  (\\<lceil>n\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>))) \\<and> events\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>1\\<guillemotright> + \\<guillemotleft>tt\\<^sub>2\\<guillemotright>)\"\n      by (simp add: seqr_post_out unrest conj_assoc)\n    also have \"... = (\\<^bold>\\<exists> tt\\<^sub>1 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>2 \\<bullet> ((#\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st) ;;\\<^sub>h (\\<lceil>n\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>))) \\<and>\n                                      events\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> events\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>1\\<guillemotright> + \\<guillemotleft>tt\\<^sub>2\\<guillemotright>)\"\n      by (meson shEx_cong utp_pred_laws.inf.left_commute)\n    also have \"... = (\\<^bold>\\<exists> tt\\<^sub>1 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>2 \\<bullet> (\\<lceil>(\\<lceil>#\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u m\\<rceil>\\<^sub>< \\<and> II) ;;\\<^sub>h (\\<lceil>n\\<rceil>\\<^sub>< >\\<^sub>u #\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>))\\<rceil>\\<^sub>S) \\<and>\n                                      events\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> events\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>1\\<guillemotright> + \\<guillemotleft>tt\\<^sub>2\\<guillemotright>)\"\n      by (simp add: alpha)\n    also have \"... = (\\<^bold>\\<exists> tt\\<^sub>1 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>2 \\<bullet> (\\<lceil>(II \\<and> \\<lceil>#\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u m\\<rceil>\\<^sub>>) ;;\\<^sub>h (\\<lceil>n\\<rceil>\\<^sub>< >\\<^sub>u #\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>))\\<rceil>\\<^sub>S) \\<and>\n                                      events\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> events\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>1\\<guillemotright> + \\<guillemotleft>tt\\<^sub>2\\<guillemotright>)\"\n      by (simp add: pre_skip_post)\n    also have \"... = (\\<^bold>\\<exists> tt\\<^sub>1 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>2 \\<bullet> (\\<lceil>\\<lceil>#\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u m\\<rceil>\\<^sub>< \\<and> \\<lceil>n\\<rceil>\\<^sub>< >\\<^sub>u #\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>)\\<rceil>\\<^sub>S) \\<and>\n                                      events\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> events\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>1\\<guillemotright> + \\<guillemotleft>tt\\<^sub>2\\<guillemotright>)\"\n      by (simp add: seqr_pre_transfer unrest)\n    also have \"... = (\\<^bold>\\<exists> tt\\<^sub>1 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>2 \\<bullet> (#\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<and> \\<lceil>n\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>)) \\<and>\n                                      events\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> events\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>1\\<guillemotright> + \\<guillemotleft>tt\\<^sub>2\\<guillemotright>)\"\n      by (simp add: alpha)\n    also have \"... = (\\<^bold>\\<exists> tt\\<^sub>1 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>2 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>0 \\<bullet> #\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<and> \\<lceil>n\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(drop\\<^sub>u(#\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>), \\<guillemotleft>tt\\<^sub>0\\<guillemotright>)) \\<and>\n                                      events\\<^sub>u(\\<guillemotleft>tt\\<^sub>0\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>0\\<guillemotright> \\<and> \\<guillemotleft>tt\\<^sub>0\\<guillemotright> =\\<^sub>u \\<guillemotleft>tt\\<^sub>1\\<guillemotright> + \\<guillemotleft>tt\\<^sub>2\\<guillemotright> \\<and>\n                                      \\<guillemotleft>tt\\<^sub>1\\<guillemotright> =\\<^sub>u take\\<^sub>u(#\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>), \\<guillemotleft>tt\\<^sub>0\\<guillemotright>) \\<and> \\<guillemotleft>tt\\<^sub>2\\<guillemotright> =\\<^sub>u drop\\<^sub>u(#\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>), \\<guillemotleft>tt\\<^sub>0\\<guillemotright>))\"\n      by ((rule shEx_cong)+, rel_auto)\n    also have \"... = (\\<^bold>\\<exists> tt\\<^sub>1 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>2 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>0 \\<bullet> \\<lceil>n\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(drop\\<^sub>u(\\<lceil>m\\<rceil>\\<^sub>S\\<^sub><, \\<guillemotleft>tt\\<^sub>0\\<guillemotright>)) \\<and>\n                                      events\\<^sub>u(\\<guillemotleft>tt\\<^sub>0\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>0\\<guillemotright> \\<and>\n                                      \\<guillemotleft>tt\\<^sub>1\\<guillemotright> =\\<^sub>u take\\<^sub>u(\\<lceil>m\\<rceil>\\<^sub>S\\<^sub><, \\<guillemotleft>tt\\<^sub>0\\<guillemotright>) \\<and> \\<guillemotleft>tt\\<^sub>2\\<guillemotright> =\\<^sub>u drop\\<^sub>u(\\<lceil>m\\<rceil>\\<^sub>S\\<^sub><, \\<guillemotleft>tt\\<^sub>0\\<guillemotright>) \\<and> #\\<^sub>u(\\<guillemotleft>tt\\<^sub>0\\<guillemotright>) \\<ge>\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub><)\"\n      by ((rule shEx_cong)+, rel_auto, simp_all add: min_absorb2)\n    also have \"... = (\\<^bold>\\<exists> tt\\<^sub>0 \\<bullet> \\<lceil>m + n\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(\\<guillemotleft>tt\\<^sub>0\\<guillemotright>) \\<and> events\\<^sub>u(\\<guillemotleft>tt\\<^sub>0\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>0\\<guillemotright> \\<and> #\\<^sub>u(\\<guillemotleft>tt\\<^sub>0\\<guillemotright>) \\<ge>\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub><)\"\n      by (rel_auto)\n    also have \"... = R2 (events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<le>\\<^sub>u #\\<^sub>u(&tt) \\<and> #\\<^sub>u(&tt) <\\<^sub>u \\<lceil>m + n\\<rceil>\\<^sub>S\\<^sub><)\"\n      by (simp add: R2_form usubst unrest, rel_auto)\n    finally show ?thesis .\n  qed\n  have 2:\"(R2 (events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> #\\<^sub>u(&tt) =\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st) ;; R2 (events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> #\\<^sub>u(&tt) =\\<^sub>u \\<lceil>n\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st)) =\n                 R2 (events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> #\\<^sub>u(&tt) =\\<^sub>u \\<lceil>m + n\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st)\" (is \"?lhs = ?rhs\")\n  proof -\n    have \"?lhs = (\\<^bold>\\<exists> tt\\<^sub>1 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>2 \\<bullet> ((events\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> #\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st) ;;\\<^sub>h\n                                   (events\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> #\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>) =\\<^sub>u \\<lceil>n\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st))\n                         \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>1\\<guillemotright> + \\<guillemotleft>tt\\<^sub>2\\<guillemotright>)\"\n      by (simp add: R2_seqr_form usubst unrest, rel_auto)\n    also have \"... = (\\<^bold>\\<exists> tt\\<^sub>1 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>2 \\<bullet> ((#\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st) ;;\\<^sub>h (#\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>) =\\<^sub>u \\<lceil>n\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st)) \\<and>\n                            events\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright> + \\<guillemotleft>tt\\<^sub>2\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>1\\<guillemotright> + \\<guillemotleft>tt\\<^sub>2\\<guillemotright>)\"\n      by (rel_auto)\n    also have \"... = (\\<^bold>\\<exists> tt\\<^sub>1 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>2 \\<bullet> (\\<lceil>(\\<lceil>#\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u m\\<rceil>\\<^sub>< \\<and> II) ;;\\<^sub>h (#\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>) =\\<^sub>u \\<lceil>n\\<rceil>\\<^sub>< \\<and> II)\\<rceil>\\<^sub>S) \\<and>\n                            events\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright> + \\<guillemotleft>tt\\<^sub>2\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>1\\<guillemotright> + \\<guillemotleft>tt\\<^sub>2\\<guillemotright>)\"\n      by (simp add: alpha)\n    also have \"... = (\\<^bold>\\<exists> tt\\<^sub>1 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>2 \\<bullet> (\\<lceil>\\<lceil>#\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u m\\<rceil>\\<^sub>< \\<and> #\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>) =\\<^sub>u \\<lceil>n\\<rceil>\\<^sub>< \\<and> II\\<rceil>\\<^sub>S) \\<and>\n                            events\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright> + \\<guillemotleft>tt\\<^sub>2\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>1\\<guillemotright> + \\<guillemotleft>tt\\<^sub>2\\<guillemotright>)\"\n      by (simp add: pre_skip_post, simp add: seqr_pre_transfer unrest)\n    also have \"... = (\\<^bold>\\<exists> tt\\<^sub>1 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>2 \\<bullet> (#\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<and> #\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>) =\\<^sub>u \\<lceil>n\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st) \\<and>\n                            events\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright> + \\<guillemotleft>tt\\<^sub>2\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>1\\<guillemotright> + \\<guillemotleft>tt\\<^sub>2\\<guillemotright>)\"\n      by (simp add: alpha)\n    also have \"... = (\\<^bold>\\<exists> tt\\<^sub>1 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>2 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>0 \\<bullet> (#\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<and> #\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>) =\\<^sub>u \\<lceil>n\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st) \\<and>\n                            events\\<^sub>u(\\<guillemotleft>tt\\<^sub>0\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>0\\<guillemotright> \\<and> \\<guillemotleft>tt\\<^sub>0\\<guillemotright> =\\<^sub>u \\<guillemotleft>tt\\<^sub>1\\<guillemotright> + \\<guillemotleft>tt\\<^sub>2\\<guillemotright>)\"\n      by (rel_auto)\n    also have \"... = (\\<^bold>\\<exists> tt\\<^sub>1 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>2 \\<bullet> \\<^bold>\\<exists> tt\\<^sub>0 \\<bullet> (#\\<^sub>u(\\<guillemotleft>tt\\<^sub>1\\<guillemotright>) =\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<and> #\\<^sub>u(\\<guillemotleft>tt\\<^sub>2\\<guillemotright>) =\\<^sub>u \\<lceil>n\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st) \\<and>\n                            events\\<^sub>u(\\<guillemotleft>tt\\<^sub>0\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>0\\<guillemotright> \\<and> #\\<^sub>u(\\<guillemotleft>tt\\<^sub>0\\<guillemotright>) \\<ge>\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<and>\n                            \\<guillemotleft>tt\\<^sub>1\\<guillemotright> =\\<^sub>u take\\<^sub>u(\\<lceil>m\\<rceil>\\<^sub>S\\<^sub><, \\<guillemotleft>tt\\<^sub>0\\<guillemotright>) \\<and> \\<guillemotleft>tt\\<^sub>2\\<guillemotright> =\\<^sub>u drop\\<^sub>u(\\<lceil>m\\<rceil>\\<^sub>S\\<^sub><, \\<guillemotleft>tt\\<^sub>0\\<guillemotright>))\"\n      by ((rule shEx_cong)+, rel_auto)\n    also have \"... = (\\<^bold>\\<exists> tt\\<^sub>0 \\<bullet> (#\\<^sub>u(drop\\<^sub>u(\\<lceil>m\\<rceil>\\<^sub>S\\<^sub><, \\<guillemotleft>tt\\<^sub>0\\<guillemotright>)) =\\<^sub>u \\<lceil>n\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st) \\<and>\n                            events\\<^sub>u(\\<guillemotleft>tt\\<^sub>0\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>0\\<guillemotright> \\<and> #\\<^sub>u(\\<guillemotleft>tt\\<^sub>0\\<guillemotright>) \\<ge>\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub><)\"\n      by (rel_auto)\n    also have \"... = (\\<^bold>\\<exists> tt\\<^sub>0 \\<bullet> (#\\<^sub>u(\\<guillemotleft>tt\\<^sub>0\\<guillemotright>) - \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< =\\<^sub>u \\<lceil>n\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st) \\<and>\n                            events\\<^sub>u(\\<guillemotleft>tt\\<^sub>0\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>0\\<guillemotright> \\<and> #\\<^sub>u(\\<guillemotleft>tt\\<^sub>0\\<guillemotright>) \\<ge>\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub><)\"\n      by (rel_auto)\n    also have \"... = (\\<^bold>\\<exists> tt\\<^sub>0 \\<bullet> (#\\<^sub>u(\\<guillemotleft>tt\\<^sub>0\\<guillemotright>) =\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< + \\<lceil>n\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st) \\<and>\n                            events\\<^sub>u(\\<guillemotleft>tt\\<^sub>0\\<guillemotright>) =\\<^sub>u \\<langle>\\<rangle> \\<and> $tr\\<acute> =\\<^sub>u $tr + \\<guillemotleft>tt\\<^sub>0\\<guillemotright> \\<and> #\\<^sub>u(\\<guillemotleft>tt\\<^sub>0\\<guillemotright>) \\<ge>\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub><)\"\n      by (rel_auto)\n    also have \"... = ?rhs\"\n      by (simp add: R2_form usubst unrest, rel_auto)\n    finally show ?thesis .\n  qed\n  show ?thesis\n  proof -\n    have \"(Wait m ;; Wait n) =\n          \\<^bold>R\\<^sub>s (true \\<turnstile> ((\\<exists> $st\\<acute> \\<bullet> events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(&tt)) \\<or> R2 (events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> #\\<^sub>u(&tt) \\<ge>\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<and> \\<lceil>m + n\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(&tt)))\n                   \\<diamondop> R2 (events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> #\\<^sub>u(&tt) =\\<^sub>u \\<lceil>m + n\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st))\"\n      by (simp add: Wait_def RHS_tri_design_composition unrest R2s_true R1_false R2_def[THEN sym] 1[simplified] 2[simplified])\n    also have \"... =\n          \\<^bold>R\\<^sub>s (true \\<turnstile> R2(((\\<exists> $st\\<acute> \\<bullet> events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(&tt)) \\<or> R2 (events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> #\\<^sub>u(&tt) \\<ge>\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<and> \\<lceil>m + n\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(&tt)))\n                   \\<diamondop> R2(events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> #\\<^sub>u(&tt) =\\<^sub>u \\<lceil>m + n\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st)))\"\n      using RHS_design_export_R2 by blast\n    also have \"... =\n          \\<^bold>R\\<^sub>s (true \\<turnstile> R2((events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(&tt) \\<or> R2 (events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> #\\<^sub>u(&tt) \\<ge>\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<and> \\<lceil>m + n\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(&tt)))\n                   \\<diamondop> R2(events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> #\\<^sub>u(&tt) =\\<^sub>u \\<lceil>m + n\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st)))\"\n      by (simp add: ex_unrest unrest)\n    also have \"... =\n          \\<^bold>R\\<^sub>s (true \\<turnstile> R2((events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(&tt) \\<or> (events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> #\\<^sub>u(&tt) \\<ge>\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<and> \\<lceil>m + n\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(&tt)))\n                   \\<diamondop> (events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> #\\<^sub>u(&tt) =\\<^sub>u \\<lceil>m + n\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st)))\"\n      by (simp add: R2_wait'_cond R2_idem R2_disj)\n    also have \"... =\n          \\<^bold>R\\<^sub>s (true \\<turnstile> (events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(&tt) \\<or> (events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> #\\<^sub>u(&tt) \\<ge>\\<^sub>u \\<lceil>m\\<rceil>\\<^sub>S\\<^sub>< \\<and> \\<lceil>m + n\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(&tt)))\n                   \\<diamondop> (events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> #\\<^sub>u(&tt) =\\<^sub>u \\<lceil>m + n\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st))\" (is \"?lhs = \\<^bold>R\\<^sub>s(?P \\<turnstile> ?Q \\<diamondop> ?R)\")\n      by (metis (mono_tags, hide_lams) R2_def RHS_design_export_R1 RHS_design_export_R2s)\n    also have \"... = \\<^bold>R\\<^sub>s (true \\<turnstile> (events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> \\<lceil>m + n\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(&tt)) \\<diamondop> (events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> #\\<^sub>u(&tt) =\\<^sub>u \\<lceil>m + n\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> =\\<^sub>u $st))\"\n    proof -\n      have 1:\"?Q = (events\\<^sub>u(&tt) =\\<^sub>u \\<langle>\\<rangle> \\<and> \\<lceil>m + n\\<rceil>\\<^sub>S\\<^sub>< >\\<^sub>u #\\<^sub>u(&tt))\"\n        by (pred_auto)\n      show ?thesis\n        by (simp add: 1)\n    qed\n    also have \"... = Wait (m + n)\"\n      by (simp add: Wait_def)\n    finally show ?thesis .\n  qed\nqed\n*)\n\nend", "meta": {"author": "isabelle-utp", "repo": "utp-main", "sha": "27bdf3aee6d4fc00c8fe4d53283d0101857e0d41", "save_path": "github-repos/isabelle/isabelle-utp-utp-main", "path": "github-repos/isabelle/isabelle-utp-utp-main/utp-main-27bdf3aee6d4fc00c8fe4d53283d0101857e0d41/theories/utp_cml.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.2819090798488639}}
{"text": "(*  Title:      Imperative_HOL_Time/Ref_Time.thy\n    Author:     Maximilian P. L. Haslbeck & Bohua Zhan, TU Muenchen\n*)\n\nsection \\<open>Monadic references\\<close>\n\ntext \\<open>This theory is an adaptation of \\<open>HOL/Imperative_HOL/Ref.thy\\<close>,\n adding time bookkeeping.\\<close>\n\ntheory Ref_Time\nimports Array_Time\nbegin\n\ntext \\<open>\n  Imperative reference operations; modeled after their ML counterparts.\n  See \\<^url>\\<open>https://caml.inria.fr/pub/docs/manual-caml-light/node14.15.html\\<close>\n  and \\<^url>\\<open>https://www.smlnj.org/doc/Conversion/top-level-comparison.html\\<close>.\n\\<close>\n\nsubsection \\<open>Primitives\\<close>\n\ndefinition present :: \"heap \\<Rightarrow> 'a::heap ref \\<Rightarrow> bool\" where\n  \"present h r \\<longleftrightarrow> addr_of_ref r < lim h\"\n\ndefinition get :: \"heap \\<Rightarrow> 'a::heap ref \\<Rightarrow> 'a\" where\n  \"get h = from_nat \\<circ> refs h TYPEREP('a) \\<circ> addr_of_ref\"\n\ndefinition set :: \"'a::heap ref \\<Rightarrow> 'a \\<Rightarrow> heap \\<Rightarrow> heap\" where\n  \"set r x = refs_update\n    (\\<lambda>h. h(TYPEREP('a) := ((h (TYPEREP('a))) (addr_of_ref r := to_nat x))))\"\n\ndefinition alloc :: \"'a \\<Rightarrow> heap \\<Rightarrow> 'a::heap ref \\<times> heap\" where\n  \"alloc x h = (let\n     l = lim h;\n     r = Ref l\n   in (r, set r x (h\\<lparr>lim := l + 1\\<rparr>)))\"\n\ndefinition noteq :: \"'a::heap ref \\<Rightarrow> 'b::heap ref \\<Rightarrow> bool\" (infix \"=!=\" 70) where\n  \"r =!= s \\<longleftrightarrow> TYPEREP('a) \\<noteq> TYPEREP('b) \\<or> addr_of_ref r \\<noteq> addr_of_ref s\"\n\n\nsubsection \\<open>Monad operations\\<close>\n\ndefinition ref :: \"'a::heap \\<Rightarrow> 'a ref Heap\" where\n  [code del]: \"ref v = Heap_Time_Monad.heap (%h. let (r,h') = alloc v h in (r,h',1))\"\n\ndefinition lookup :: \"'a::heap ref \\<Rightarrow> 'a Heap\" (\"!_\" 61) where\n  [code del]: \"lookup r = Heap_Time_Monad.tap (\\<lambda>h. get h r)\"\n\ndefinition update :: \"'a ref \\<Rightarrow> 'a::heap \\<Rightarrow> unit Heap\" (\"_ := _\" 62) where\n  [code del]: \"update r v = Heap_Time_Monad.heap (\\<lambda>h. ((), set r v h, 1))\"\n\ndefinition change :: \"('a::heap \\<Rightarrow> 'a) \\<Rightarrow> 'a ref \\<Rightarrow> 'a Heap\" where\n  \"change f r = do {\n     x \\<leftarrow> ! r;\n     let y = f x;\n     r := y;\n     return y\n   }\"\n\n\nsubsection \\<open>Properties\\<close>\n\ntext \\<open>Primitives\\<close>\n\nlemma noteq_sym: \"r =!= s \\<Longrightarrow> s =!= r\"\n  and unequal [simp]: \"r \\<noteq> r' \\<longleftrightarrow> r =!= r'\" \\<comment> \\<open>same types!\\<close>\n  by (auto simp add: noteq_def)\n\nlemma noteq_irrefl: \"r =!= r \\<Longrightarrow> False\"\n  by (auto simp add: noteq_def)\n\nlemma present_alloc_neq: \"present h r \\<Longrightarrow> r =!= fst (alloc v h)\"\n  by (simp add: present_def alloc_def noteq_def Let_def)\n\nlemma next_fresh [simp]:\n  assumes \"(r, h') = alloc x h\"\n  shows \"\\<not> present h r\"\n  using assms by (cases h) (auto simp add: alloc_def present_def Let_def)\n\nlemma next_present [simp]:\n  assumes \"(r, h') = alloc x h\"\n  shows \"present h' r\"\n  using assms by (cases h) (auto simp add: alloc_def set_def present_def Let_def)\n\nlemma get_set_eq [simp]:\n  \"get (set r x h) r = x\"\n  by (simp add: get_def set_def)\n\nlemma get_set_neq [simp]:\n  \"r =!= s \\<Longrightarrow> get (set s x h) r = get h r\"\n  by (simp add: noteq_def get_def set_def)\n\nlemma set_same [simp]:\n  \"set r x (set r y h) = set r x h\"\n  by (simp add: set_def)\n\nlemma not_present_alloc [simp]:\n  \"\\<not> present h (fst (alloc v h))\"\n  by (simp add: present_def alloc_def Let_def)\n\nlemma set_set_swap:\n  \"r =!= r' \\<Longrightarrow> set r x (set r' x' h) = set r' x' (set r x h)\"\n  by (simp add: noteq_def set_def fun_eq_iff)\n\nlemma alloc_set:\n  \"fst (alloc x (set r x' h)) = fst (alloc x h)\"\n  by (simp add: alloc_def set_def Let_def)\n\nlemma get_alloc [simp]:\n  \"get (snd (alloc x h)) (fst (alloc x' h)) = x\"\n  by (simp add: alloc_def Let_def)\n\nlemma set_alloc [simp]:\n  \"set (fst (alloc v h)) v' (snd (alloc v h)) = snd (alloc v' h)\"\n  by (simp add: alloc_def Let_def)\n\nlemma get_alloc_neq: \"r =!= fst (alloc v h) \\<Longrightarrow> \n  get (snd (alloc v h)) r  = get h r\"\n  by (simp add: get_def set_def alloc_def Let_def noteq_def)\n\nlemma lim_set [simp]:\n  \"lim (set r v h) = lim h\"\n  by (simp add: set_def)\n\nlemma present_alloc [simp]: \n  \"present h r \\<Longrightarrow> present (snd (alloc v h)) r\"\n  by (simp add: present_def alloc_def Let_def)\n\nlemma present_set [simp]:\n  \"present (set r v h) = present h\"\n  by (simp add: present_def fun_eq_iff)\n\nlemma noteq_I:\n  \"present h r \\<Longrightarrow> \\<not> present h r' \\<Longrightarrow> r =!= r'\"\n  by (auto simp add: noteq_def present_def)\n\n\ntext \\<open>Monad operations\\<close>\n\nlemma execute_ref [execute_simps]:\n  \"execute (ref v) h = Some (let (r,h') = alloc v h in (r,h',1))\"\n  by (simp add: ref_def execute_simps)\n\nlemma success_refI [success_intros]:\n  \"success (ref v) h\"\n  by (auto intro: success_intros simp add: ref_def)\n\nlemma effect_refI [effect_intros]:\n  assumes \"(r, h') = alloc v h\" \"n=1\"\n  shows \"effect (ref v) h h' r n\"\n  apply (rule effectI) apply (insert assms, simp add:  execute_simps)\n  by (metis case_prod_conv) \n\nlemma effect_refE [effect_elims]:\n  assumes \"effect (ref v) h h' r n\" \n  obtains \"get h' r = v\" and \"present h' r\" and \"\\<not> present h r\" and \"n=1\"\n  using assms apply (rule effectE) apply (simp add: execute_simps)\n  by (metis (no_types, lifting) Ref_Time.alloc_def Ref_Time.get_set_eq fst_conv next_fresh next_present prod.case_eq_if snd_conv)\n\nlemma execute_lookup [execute_simps]:\n  \"Heap_Time_Monad.execute (lookup r) h = Some (get h r, h, 1)\"\n  by (simp add: lookup_def execute_simps)\n\nlemma success_lookupI [success_intros]:\n  \"success (lookup r) h\"\n  by (auto intro: success_intros  simp add: lookup_def)\n\nlemma effect_lookupI [effect_intros]:\n  assumes \"h' = h\" \"x = get h r\" \"n=1\"\n  shows \"effect (!r) h h' x n\"\n  by (rule effectI) (insert assms, simp add: execute_simps)\n\nlemma effect_lookupE [effect_elims]:\n  assumes \"effect (!r) h h' x n\"\n  obtains \"h' = h\" \"x = get h r\" \"n=1\"\n  using assms by (rule effectE) (simp add: execute_simps)\n\nlemma execute_update [execute_simps]:\n  \"Heap_Time_Monad.execute (update r v) h = Some ((), set r v h, 1)\"\n  by (simp add: update_def execute_simps)\n\nlemma success_updateI [success_intros]:\n  \"success (update r v) h\"\n  by (auto intro: success_intros  simp add: update_def)\n\nlemma effect_updateI [effect_intros]:\n  assumes \"h' = set r v h\" \"n=1\"\n  shows \"effect (r := v) h h' x n\"\n  by (rule effectI) (insert assms, simp add: execute_simps)\n\nlemma effect_updateE [effect_elims]:\n  assumes \"effect (r' := v) h h' r n\"\n  obtains \"h' = set r' v h\" \"n=1\"\n  using assms by (rule effectE) (simp add: execute_simps)\n\nlemma execute_change [execute_simps]:\n  \"Heap_Time_Monad.execute (change f r) h = Some (f (get h r), set r (f (get h r)) h, 3)\"\n  by (simp add: change_def bind_def Let_def execute_simps)\n\nlemma success_changeI [success_intros]:\n  \"success (change f r) h\"\n  by (auto intro!: success_intros effect_intros simp add: change_def)\n\nlemma effect_changeI [effect_intros]: \n  assumes \"h' = set r (f (get h r)) h\" \"x = f (get h r)\" \"n=3\"\n  shows \"effect (change f r) h h' x n\"\n  by (rule effectI) (insert assms, simp add: execute_simps)  \n\nlemma effect_changeE [effect_elims]:\n  assumes \"effect (change f r') h h' r n\"\n  obtains \"h' = set r' (f (get h r')) h\" \"r = f (get h r')\" \"n=3\"\n  using assms by (rule effectE) (simp add: execute_simps)\n\nlemma lookup_chain:\n  \"(!r \\<then> f) = wait 1 \\<then> f\"\n  by (rule Heap_eqI) (auto simp add: lookup_def execute_simps intro: execute_bind)\n\n(* this one is wrong! \nlemma update_change [code]:\n  \"r := e = change (\\<lambda>_. e) r \\<then> return ()\"\n  by (rule Heap_eqI) (simp add: change_def lookup_chain)\n*)\n\ntext \\<open>Non-interaction between imperative arrays and imperative references\\<close>\n\nlemma array_get_set [simp]:\n  \"Array_Time.get (set r v h) = Array_Time.get h\"\n  by (simp add: Array_Time.get_def set_def fun_eq_iff)\n\nlemma get_update [simp]:\n  \"get (Array_Time.update a i v h) r = get h r\"\n  by (simp add: get_def Array_Time.update_def Array_Time.set_def)\n\nlemma alloc_update:\n  \"fst (alloc v (Array_Time.update a i v' h)) = fst (alloc v h)\"\n  by (simp add: Array_Time.update_def Array_Time.get_def Array_Time.set_def alloc_def Let_def)\n\nlemma update_set_swap:\n  \"Array_Time.update a i v (set r v' h) = set r v' (Array_Time.update a i v h)\"\n  by (simp add: Array_Time.update_def Array_Time.get_def Array_Time.set_def set_def)\n\nlemma length_alloc [simp]: \n  \"Array_Time.length (snd (alloc v h)) a = Array_Time.length h a\"\n  by (simp add: Array_Time.length_def Array_Time.get_def alloc_def set_def Let_def)\n\nlemma array_get_alloc [simp]: \n  \"Array_Time.get (snd (alloc v h)) = Array_Time.get h\"\n  by (simp add: Array_Time.get_def alloc_def set_def Let_def fun_eq_iff)\n\nlemma present_update [simp]: \n  \"present (Array_Time.update a i v h) = present h\"\n  by (simp add: Array_Time.update_def Array_Time.set_def fun_eq_iff present_def)\n\nlemma array_present_set [simp]:\n  \"Array_Time.present (set r v h) = Array_Time.present h\"\n  by (simp add: Array_Time.present_def set_def fun_eq_iff)\n\nlemma array_present_alloc [simp]:\n  \"Array_Time.present h a \\<Longrightarrow> Array_Time.present (snd (alloc v h)) a\"\n  by (simp add: Array_Time.present_def alloc_def Let_def)\n\nlemma set_array_set_swap:\n  \"Array_Time.set a xs (set r x' h) = set r x' (Array_Time.set a xs h)\"\n  by (simp add: Array_Time.set_def set_def)\n\nhide_const (open) present get set alloc noteq lookup update change\n\n\nsubsection \\<open>Code generator setup\\<close>\n\ntext \\<open>Intermediate operation avoids invariance problem in \\<open>Scala\\<close> (similar to value restriction)\\<close>\n\ndefinition ref' where\n  [code del]: \"ref' = ref\"\n\n\n\n\ntext \\<open>SML / Eval\\<close>\n\ncode_printing type_constructor ref \\<rightharpoonup> (SML) \"_/ ref\"\ncode_printing type_constructor ref \\<rightharpoonup> (Eval) \"_/ Unsynchronized.ref\"\ncode_printing constant Ref \\<rightharpoonup> (SML) \"raise/ (Fail/ \\\"bare Ref\\\")\"\ncode_printing constant ref' \\<rightharpoonup> (SML) \"(fn/ ()/ =>/ ref/ _)\"\ncode_printing constant ref' \\<rightharpoonup> (Eval) \"(fn/ ()/ =>/ Unsynchronized.ref/ _)\"\ncode_printing constant Ref_Time.lookup \\<rightharpoonup> (SML) \"(fn/ ()/ =>/ !/ _)\"\ncode_printing constant Ref_Time.update \\<rightharpoonup> (SML) \"(fn/ ()/ =>/ _/ :=/ _)\"\ncode_printing constant \"HOL.equal :: 'a ref \\<Rightarrow> 'a ref \\<Rightarrow> bool\" \\<rightharpoonup> (SML) infixl 6 \"=\"\n\ncode_reserved Eval Unsynchronized\n\n\ntext \\<open>OCaml\\<close>\n\ncode_printing type_constructor ref \\<rightharpoonup> (OCaml) \"_/ ref\"\ncode_printing constant Ref \\<rightharpoonup> (OCaml) \"failwith/ \\\"bare Ref\\\"\"\ncode_printing constant ref' \\<rightharpoonup> (OCaml) \"(fun/ ()/ ->/ ref/ _)\"\ncode_printing constant Ref_Time.lookup \\<rightharpoonup> (OCaml) \"(fun/ ()/ ->/ !/ _)\"\ncode_printing constant Ref_Time.update \\<rightharpoonup> (OCaml) \"(fun/ ()/ ->/ _/ :=/ _)\"\ncode_printing constant \"HOL.equal :: 'a ref \\<Rightarrow> 'a ref \\<Rightarrow> bool\" \\<rightharpoonup> (OCaml) infixl 4 \"=\"\n\ncode_reserved OCaml ref\n\n\ntext \\<open>Haskell\\<close>\n\ncode_printing type_constructor ref \\<rightharpoonup> (Haskell) \"Heap.STRef/ Heap.RealWorld/ _\"\ncode_printing constant Ref \\<rightharpoonup> (Haskell) \"error/ \\\"bare Ref\\\"\"\ncode_printing constant ref' \\<rightharpoonup> (Haskell) \"Heap.newSTRef\"\ncode_printing constant Ref_Time.lookup \\<rightharpoonup> (Haskell) \"Heap.readSTRef\"\ncode_printing constant Ref_Time.update \\<rightharpoonup> (Haskell) \"Heap.writeSTRef\"\ncode_printing constant \"HOL.equal :: 'a ref \\<Rightarrow> 'a ref \\<Rightarrow> bool\" \\<rightharpoonup> (Haskell) infix 4 \"==\"\ncode_printing class_instance ref :: HOL.equal \\<rightharpoonup> (Haskell) -\n\n\ntext \\<open>Scala\\<close>\n\ncode_printing type_constructor ref \\<rightharpoonup> (Scala) \"!Ref[_]\"\ncode_printing constant Ref \\<rightharpoonup> (Scala) \"!sys.error(\\\"bare Ref\\\")\"\ncode_printing constant ref' \\<rightharpoonup> (Scala) \"('_: Unit)/ =>/ Ref((_))\"\ncode_printing constant Ref_Time.lookup \\<rightharpoonup> (Scala) \"('_: Unit)/ =>/ Ref.lookup((_))\"\ncode_printing constant Ref_Time.update \\<rightharpoonup> (Scala) \"('_: Unit)/ =>/ Ref.update((_), (_))\"\ncode_printing constant \"HOL.equal :: 'a ref \\<Rightarrow> 'a ref \\<Rightarrow> bool\" \\<rightharpoonup> (Scala) infixl 5 \"==\"\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Van_Emde_Boas_Trees/Imperative_HOL_Time/Ref_Time.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.2819090798488639}}
{"text": "theory Refinement_MMU_No_ASIDs\n\nimports  Update_Root_Ref\n\nbegin    \n\n\ndefinition \n  tlb_rel :: \"(unit tlb_entry set)  state_scheme  \\<Rightarrow> (vaddr set) state_scheme \\<Rightarrow> bool\"\nwhere                                                                \n  \"tlb_rel r t \\<equiv> \\<exists>(s:: unit det_tlb_state_scheme) (s':: unit sat_tlb_state_scheme).  \n                    tlb_rel_det r (typ_det_tlb s) \\<and> tlb_rel_sat (typ_det_tlb s) (typ_sat_tlb s') \\<and> \n                           tlb_rel_abs (typ_sat_tlb s') t\"\n\n\nlemmas  abc =  mmu_translate_det_sat_refine [simplified split_def Let_def, rotated 2]   \nlemmas  abc' =  mmu_translate_non_det_det_refine [simplified split_def Let_def, rotated 2]\n\n\nlemma address_refinement:\n  \"\\<lbrakk> mmu_translate va r = (pa, r');  mmu_translate va t = (pa', t') ;\n           va \\<notin> set_tlb t ; tlb_rel (typ_non_det_tlb r) (typ_set_tlb t) \\<rbrakk> \\<Longrightarrow> \n                               pa = pa' \\<and>   tlb_rel  (typ_non_det_tlb r') (typ_set_tlb t') \" \n  apply (clarsimp simp: tlb_rel_def)\n  apply (frule_tac s = s' and pa = \"fst(mmu_translate va s')\" and s' = \"snd(mmu_translate va s')\" in \n      mmu_translate_sat_incon_refine [rotated]; clarsimp?)\n  apply (frule_tac va = va and pa =  \"fst(mmu_translate va s)\" and s' = \"snd(mmu_translate va s)\"in  abc; clarsimp?)\n  using tlb_rel_abs_consistent apply force\n  apply (frule_tac va = va and pa =  \"fst(mmu_translate va r)\" and s' = \"snd(mmu_translate va r)\"in  abc'; clarsimp?)\n   apply (smt det_tlb_more mmu_incon_eq_asid_root_mem mmu_translate_sat_const_tlb sat_tlb_more tlb_rel_absD tlb_rel_sat_consistent typ_det_prim_parameter typ_sat_prim_parameter typ_set_prim_parameter)\n  by force\n\n\nlemma read_refinement:\n  \"\\<lbrakk> mmu_read_size (va, sz) r = (val, r');  mmu_read_size (va, sz) t = (val', t');\n           va \\<notin> set_tlb t ; tlb_rel (typ_non_det_tlb r) (typ_set_tlb t) \\<rbrakk> \\<Longrightarrow> \n                               val = val' \\<and>  tlb_rel  (typ_non_det_tlb r') (typ_set_tlb t') \" \n  apply (clarsimp simp: tlb_rel_def)\n  apply (frule_tac s = s' and val = \"fst(mmu_read_size (va, sz) s')\" and s' = \"snd(mmu_read_size (va, sz) s')\" in \n      mmu_read_sat_incon_refine [rotated]; clarsimp?)\n  apply (frule_tac va = va and sz= sz and val =  \"fst(mmu_read_size (va, sz)s)\" and s' = \"snd(mmu_read_size (va, sz) s)\" and \n      val' =  \"fst(mmu_read_size (va, sz)s')\"  and t' = \"snd(mmu_read_size (va, sz) s')\" in  mmu_read_non_det_sat_refine [rotated 2]; clarsimp?)\n  using tlb_rel_abs_consistent apply force\n\n  apply (frule_tac va = va and sz= sz and val =  \"fst(mmu_read_size (va, sz)r)\" and s' = \"snd(mmu_read_size (va, sz) r)\" and \n      val' =  \"fst(mmu_read_size (va, sz)s)\"  and t' = \"snd(mmu_read_size (va, sz) s)\" in  mmu_read_non_det_det_refine [rotated 2]; clarsimp?)\n  using tlb_rel_abs_consistent tlb_rel_sat_consistent apply fastforce\n   apply (metis (no_types) prod.collapse)\n  by force\n\nlemma write_refinement:\n  \"\\<lbrakk> mmu_write_size (val,va, sz) r = ((), r');  mmu_write_size (val,va, sz)  t = ((), t');\n           va \\<notin> set_tlb t ; tlb_rel (typ_non_det_tlb r) (typ_set_tlb t) \\<rbrakk> \\<Longrightarrow> \n                              tlb_rel  (typ_non_det_tlb r') (typ_set_tlb t') \" \n  apply (clarsimp simp: tlb_rel_def)\n  apply (frule_tac s = s' and s' = \"snd(mmu_write_size (val,va, sz) s')\" in \n      mmu_write_sat_incon_refine [rotated]; clarsimp?)\n   apply (metis eq_snd_iff old.unit.exhaust)\n  apply (frule_tac va = va and sz= sz  and s' = \"snd(mmu_write_size (val,va, sz)  s)\" and t' = \"snd(mmu_write_size (val,va, sz)  s')\" and val = val in  \n      mmu_write_det_sat_refine [rotated]; clarsimp?)\n  using tlb_rel_abs_consistent apply force \n    apply (metis eq_snd_iff old.unit.exhaust)\n   apply (metis eq_snd_iff old.unit.exhaust)\n  apply (frule_tac va = va and sz= sz and val =  val and s' = \"snd(mmu_write_size (val,va, sz) r)\" and \n      t' = \"snd(mmu_write_size (val,va, sz) s)\" in  mmu_write_non_det_det_refine [rotated]; clarsimp?)\n  using tlb_rel_abs_consistent tlb_rel_sat_consistent apply fastforce\n   apply (metis eq_snd_iff old.unit.exhaust)\n  by force\n\n\n\ndatatype op_typ = translate     vaddr \n                | memread       \"vaddr \\<times> nat\" \n                | memwrite      \"bool list \\<times> vaddr \\<times> nat\"\n\n\ndatatype res_typ = PA paddr\n                 | BL \"bool list\"\n                 | UT unit\n\nfun \n  mem_op :: \"op_typ \\<Rightarrow> 'a::mmu state_scheme \\<Rightarrow> _\"\n  where \n  \"mem_op (translate va) s             = (PA (fst (mmu_translate va s)),            snd (mmu_translate va s))\"\n| \"mem_op (memread (va, sz)) s         = (BL (fst (mmu_read_size (va, sz) s)),      snd (mmu_read_size (va, sz) s))\"\n| \"mem_op (memwrite (bl, va, sz)) s    = (UT (fst (mmu_write_size (bl, va, sz) s)), snd (mmu_write_size (bl, va, sz) s))\"\n\n\nfun\n  consistent_f :: \"op_typ \\<Rightarrow> 'a::mmu set_tlb_state_scheme \\<Rightarrow> bool\"\nwhere\n  \"consistent_f (translate va) s             =  (va \\<notin> set_tlb s)\"\n| \"consistent_f (memread (va, sz)) s         =  (va \\<notin> set_tlb s)\"\n| \"consistent_f (memwrite (bl, va, sz)) s    =  (va \\<notin> set_tlb s)\"\n\n\nlemma mem_refine:\n    \"\\<lbrakk> mem_op f r = (res, r') ; mem_op f t = (res', t'); \n          consistent_f f t ; tlb_rel (typ_non_det_tlb r) (typ_set_tlb t) \\<rbrakk> \\<Longrightarrow> \n                 res = res' \\<and> tlb_rel (typ_non_det_tlb r') (typ_set_tlb t')\"\n  apply (cases f; clarsimp)\n    apply (rename_tac va)\n    apply (rule_tac  va = va and  r = r and t = t in address_refinement; force?) \n   apply (rename_tac va sz)\n   apply (rule_tac read_refinement; force?) \n  apply (rename_tac bl va sz)\n  apply (rule_tac val = bl and va = va and sz = sz and r = r and t = t in write_refinement; force?) \n   apply (metis eq_snd_iff old.unit.exhaust)    \n  by (metis eq_snd_iff old.unit.exhaust)\n\n\n\ndatatype op_typ' = root_update  paddr \n                 | flush_op        flush_type\n\n\nlemma root_refinement:\n  \"\\<lbrakk> update_TTBR0 rt r = ((), r');  update_TTBR0 rt t = ((), t') ; tlb_rel (typ_non_det_tlb r) (typ_set_tlb t) \\<rbrakk> \\<Longrightarrow> \n                               tlb_rel  (typ_non_det_tlb r') (typ_set_tlb t') \" \n  apply (clarsimp simp: tlb_rel_def)\n  apply (frule_tac s = s'  and s' = \"snd (update_TTBR0 rt s')\"  in update_root_sat_incon_refine [rotated]; clarsimp?)\n   apply (metis eq_snd_iff old.unit.exhaust)  \n  apply (frule_tac  r = rt and s' =\"snd ( update_TTBR0 rt s) \" and t' = \"snd (update_TTBR0 rt s')\" in update_root_det_sat_refine [rotated 2]; clarsimp?)\n    apply (metis eq_snd_iff old.unit.exhaust)     \n   apply (metis eq_snd_iff old.unit.exhaust)  \n  apply (frule_tac  r = rt and s' =\"snd ( update_TTBR0 rt r) \" and t' = \"snd (update_TTBR0 rt s)\" in update_root_non_det_det_refine [rotated 2]; clarsimp?)\n   apply (metis eq_snd_iff old.unit.exhaust)  \n  by force\n  \nlemma flush_refinement:\n  \"\\<lbrakk> flush f r = ((), r');  flush f t = ((), t') ; tlb_rel (typ_non_det_tlb r) (typ_set_tlb t) \\<rbrakk> \\<Longrightarrow> \n                               tlb_rel  (typ_non_det_tlb r') (typ_set_tlb t') \" \n  apply (clarsimp simp: tlb_rel_def)\n  apply (frule_tac s = s'  and s' = \"snd (flush f s')\"  in flush_sat_incon_refine [rotated]; clarsimp?)\n   apply (metis eq_snd_iff old.unit.exhaust)  \n  apply (frule_tac f= f and s' =\"snd ( flush f s) \" and t' = \"snd (flush f s')\" in flush_det_sat_refine [rotated 2]; clarsimp?)\n    apply (metis eq_snd_iff old.unit.exhaust)     \n   apply (metis eq_snd_iff old.unit.exhaust)  \n  apply (frule_tac  f = f and s' =\"snd ( flush f r) \" and t' = \"snd (flush f s)\" in flush_non_det_det_refine [rotated 2]; clarsimp?)\n   apply (metis eq_snd_iff old.unit.exhaust)  \n  by force\n  \nfun \n  main_op :: \"op_typ' \\<Rightarrow> 'a::mmu state_scheme \\<Rightarrow> _\"\n  where \n  \"main_op (root_update rt) s     = ((),  snd (update_TTBR0 rt s))\"\n| \"main_op (flush_op f) s         = ((), snd (flush f s))\"\n\nlemma main_refine:\n    \"\\<lbrakk> main_op f r = ((), r') ; main_op f t = ((), t'); \n         tlb_rel (typ_non_det_tlb r) (typ_set_tlb t) \\<rbrakk> \\<Longrightarrow> \n                  tlb_rel (typ_non_det_tlb r') (typ_set_tlb t')\"\n  apply (cases f; clarsimp)\n   apply (rename_tac rt)\n   apply (rule_tac  rt = rt and  r = r and t = t in root_refinement; force?) \n    apply (metis eq_snd_iff old.unit.exhaust)    \n   apply (metis eq_snd_iff old.unit.exhaust)    \n  apply (rule_tac f = x2 in flush_refinement; force?) \n   apply (metis eq_snd_iff old.unit.exhaust)    \n  by (metis eq_snd_iff old.unit.exhaust)    \n \n\n\nend", "meta": {"author": "SEL4PROJ", "repo": "tlb", "sha": "88bb017dd96c3830baed93ba62e45b45050d1417", "save_path": "github-repos/isabelle/SEL4PROJ-tlb", "path": "github-repos/isabelle/SEL4PROJ-tlb/tlb-88bb017dd96c3830baed93ba62e45b45050d1417/TLB_No_ASID/Refinement_MMU_No_ASIDs.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.679178699175393, "lm_q2_score": 0.41489884579676883, "lm_q1q2_score": 0.2817904583776214}}
{"text": "section {*FUNCTION\\_\\_PARSER\\_TO\\_EDPDA*}\ntheory\n  FUNCTION__PARSER_TO_EDPDA\n\nimports\n  PRJ_12_07_01__ENTRY\n\nbegin\n\ndefinition F_PARSER_TO_EDPDA__rules_rev :: \"\n  ('stack, 'event, 'stack) epda_step_label\n  \\<Rightarrow> ('stack, 'event) parser_step_label\"\n  where\n    \"F_PARSER_TO_EDPDA__rules_rev e \\<equiv>\n  \\<lparr>rule_lpop = rev (edge_pop e) @ [edge_src e],\n  rule_rpop = option_to_list (edge_event e),\n  rule_lpush = rev (edge_push e) @ [edge_trg e],\n  rule_rpush = []\\<rparr>\"\n\ndefinition F_PARSER_TO_EDPDA__configuration :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserS_conf\n  \\<Rightarrow> 'stack\n  \\<Rightarrow> ('stack, 'event, 'stack) epdaS_conf\"\n  where\n    \"F_PARSER_TO_EDPDA__configuration G c BOX \\<equiv>\n  \\<lparr>epdaS_conf_state = last (parserS_conf_stack c),\n  epdaS_conf_scheduler = butlast_if_match (parserS_conf_scheduler c) (parser_bottom G),\n  epdaS_conf_stack = rev (butlast (parserS_conf_stack c)) @ [BOX]\\<rparr>\"\n\ndefinition F_PARSER_TO_EDPDA__configuration_rev :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ('stack, 'event) parserS_conf\"\n  where\n    \"F_PARSER_TO_EDPDA__configuration_rev G c \\<equiv>\n  \\<lparr>parserS_conf_stack =\n      (if epdaS_conf_stack c = []\n      then []\n      else rev (butlast (epdaS_conf_stack c)))\n    @ [epdaS_conf_state c],\n  parserS_conf_scheduler = epdaS_conf_scheduler c @ [parser_bottom G]\\<rparr>\"\n\nlemma F_PARSER_TO_EDPDA__configuration_rev_F_PARSER_TO_EDPDA__configuration: \"\n  parserS_conf_stack c \\<noteq> []\n  \\<Longrightarrow> \\<exists>w. parserS_conf_scheduler c = w @ [parser_bottom G]\n  \\<Longrightarrow> F_PARSER_TO_EDPDA__configuration_rev G (F_PARSER_TO_EDPDA__configuration G c BOX) = c\"\n  apply(simp add: F_PARSER_TO_EDPDA__configuration_rev_def F_PARSER_TO_EDPDA__configuration_def)\n  apply(case_tac c)\n  apply(rename_tac parserS_conf_stacka parserS_conf_schedulera)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac parserS_conf_stack w)(*strict*)\n  apply (metis butlast_if_match_direct)\n  done\n\nlemma F_PARSER_TO_EDPDA__configuration_F_PARSER_TO_EDPDA__configuration_rev: \"\n  epdaS_conf_stack c \\<noteq> []\n  \\<Longrightarrow> last (epdaS_conf_stack c) = BOX\n  \\<Longrightarrow> F_PARSER_TO_EDPDA__configuration G (F_PARSER_TO_EDPDA__configuration_rev G c) BOX = c\"\n  apply(simp add: F_PARSER_TO_EDPDA__configuration_rev_def F_PARSER_TO_EDPDA__configuration_def)\n  apply(clarsimp)\n  apply(case_tac c)\n  apply(rename_tac epdaS_conf_statea epdaS_conf_schedulera epdaS_conf_stacka)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac epdaS_conf_scheduler epdaS_conf_stack)(*strict*)\n  apply (metis butlast_if_match_direct)\n  done\n\ndefinition F_PARSER_TO_EDPDA__SpecInput1 :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> 'stack\n  \\<Rightarrow> bool\"\n  where\n    \"F_PARSER_TO_EDPDA__SpecInput1 G BOX \\<equiv>\n  valid_parser G\n  \\<and> (\\<forall>r \\<in> parser_rules G.\n      rule_rpush r = []\n      \\<and> length (rule_rpop r) \\<le> Suc 0\n      \\<and> rule_lpop r \\<noteq> []\n      \\<and> rule_lpush r \\<noteq> [])\n  \\<and> BOX \\<notin> parser_nonterms G\"\n\nlemma F_PARSER_TO_EDPDA__rules_rev_F_PARSER_TO_EDPDA__rules: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G BOX\n  \\<Longrightarrow> e \\<in> parser_rules G\n  \\<Longrightarrow> F_PARSER_TO_EDPDA__rules_rev (F_PARSER_TO_EDPDA__rules e) = e\"\n  apply(simp add: F_PARSER_TO_EDPDA__rules_rev_def F_PARSER_TO_EDPDA__rules_def)\n  apply(case_tac e)\n  apply(rename_tac rule_lpopa rule_rpopa rule_lpusha rule_rpush)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac rule_lpop rule_rpop rule_lpush rule_rpush)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n  apply(rename_tac rule_lpopa rule_rpopa rule_lpusha rule_rpusha)(*strict*)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"\\<lparr>rule_lpop = rule_lpopa, rule_rpop = rule_rpopa, rule_lpush = rule_lpusha, rule_rpush = rule_rpusha\\<rparr>\"\n      in ballE)\n   apply(rename_tac rule_lpopa rule_rpopa rule_lpusha rule_rpusha)(*strict*)\n   prefer 2\n   apply(rename_tac rule_lpop rule_rpop rule_lpush rule_rpush)(*strict*)\n   apply(force)\n  apply(rename_tac rule_lpopa rule_rpopa rule_lpusha rule_rpusha)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac rule_lpop rule_rpop rule_lpush)(*strict*)\n  apply(simp add: option_to_list_def list_to_option_def)\n  apply(case_tac \"rule_rpop\")\n   apply(rename_tac rule_lpop rule_rpop rule_lpush)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac rule_lpop rule_rpop rule_lpush a list)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma F_PARSER_TO_EDPDA__rules_F_PARSER_TO_EDPDA__rules_rev: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G BOX\n  \\<Longrightarrow> e \\<in> epda_delta (F_PARSER_TO_EDPDA G BOX)\n  \\<Longrightarrow> F_PARSER_TO_EDPDA__rules (F_PARSER_TO_EDPDA__rules_rev e) = e\"\n  apply(simp add: F_PARSER_TO_EDPDA__rules_rev_def F_PARSER_TO_EDPDA__rules_def)\n  apply(case_tac e)\n  apply(rename_tac edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac edge_src edge_event edge_pop edge_push edge_trg)(*strict*)\n  apply(simp add: option_to_list_def list_to_option_def)\n  apply(case_tac \"edge_event\")\n   apply(rename_tac edge_src edge_event edge_pop edge_push edge_trg)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac edge_src edge_event edge_pop edge_push edge_trg a)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma F_PARSER_TO_EDPDA__SpecInput1_implies_never_fixed: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G BOX\n  \\<Longrightarrow> parserS.derivation_initial G d\n  \\<Longrightarrow> parser_fixed_input_length_recN d n = 0\"\n  apply(induct n)\n   apply(clarsimp)\n  apply(rename_tac n)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"d (Suc n)\")\n   apply(rename_tac n)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac n a)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d n = Some (pair e1 c1) \\<and> d (Suc n) = Some (pair (Some e2) c2) \\<and> parserS_step_relation G c1 e2 c2\")\n   apply(rename_tac n a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc n\"\n      in parserS.step_detail_before_some_position)\n     apply(rename_tac n a)(*strict*)\n     apply(rule parserS.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac n a)(*strict*)\n    apply(force)\n   apply(rename_tac n a)(*strict*)\n   apply(force)\n  apply(rename_tac n a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n e1 e2 c1 c2)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"e2\"\n      in ballE)\n   apply(rename_tac n e1 e2 c1 c2)(*strict*)\n   prefer 2\n   apply(simp add: parserS_step_relation_def)\n  apply(rename_tac n e1 e2 c1 c2)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma F_PARSER_TO_EDPDA__SpecInput1_implies_parser_not_observes_input_terminator: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G BOX\n  \\<Longrightarrow> parser_not_observes_input_terminator G\"\n  apply(simp add: parser_not_observes_input_terminator_def F_PARSER_TO_EDPDA__SpecInput1_def)\n  done\n\nlemma F_PARSER_TO_EDPDA_generates_epda: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G BOX\n  \\<Longrightarrow> valid_epda (F_PARSER_TO_EDPDA G BOX)\"\n  apply(subgoal_tac \"parser_not_observes_input_terminator G\")\n   prefer 2\n   apply(rule F_PARSER_TO_EDPDA__SpecInput1_implies_parser_not_observes_input_terminator)\n   apply(force)\n  apply(simp add: valid_epda_def F_PARSER_TO_EDPDA__SpecInput1_def)\n  apply(rule conjI)\n   apply(simp add: valid_parser_def)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rule conjI)\n   apply(simp add: valid_parser_def)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rule conjI)\n   apply(simp add: valid_parser_def)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rule conjI)\n   apply(simp add: valid_parser_def)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rule conjI)\n   apply(simp add: valid_parser_def)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rule conjI)\n   apply(simp add: valid_parser_def)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rule conjI)\n   apply(simp add: valid_parser_def)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(clarsimp)\n  apply(rename_tac e)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__rules_def F_PARSER_TO_EDPDA_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(subgoal_tac \"valid_parser_step_label G x\")\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(simp add: valid_parser_def)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__rules_def F_PARSER_TO_EDPDA_def)\n  apply(simp add: valid_epda_step_label_def)\n  apply(rule conjI)\n   apply(rename_tac x)(*strict*)\n   apply(simp add: valid_parser_step_label_def)\n   apply(clarsimp)\n   apply(rename_tac x k w)(*strict*)\n   apply (metis last_in_set_X)\n  apply(rename_tac x)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac x)(*strict*)\n   apply(simp add: valid_parser_step_label_def)\n   apply(clarsimp)\n   apply(rename_tac x k w)(*strict*)\n   apply(simp add: option_to_set_def list_to_option_def kPrefix_def)\n   apply(case_tac \"k-length w\")\n    apply(rename_tac x k w)(*strict*)\n    apply(clarsimp)\n    apply(case_tac \"take k w\")\n     apply(rename_tac x k w)(*strict*)\n     apply(force)\n    apply(rename_tac x k w a list)(*strict*)\n    apply(clarsimp)\n    apply (metis last_in_set_X)\n   apply(rename_tac x k w nat)(*strict*)\n   apply(clarsimp)\n  apply(simp add: parser_not_observes_input_terminator_def)\n  apply(rename_tac x)(*strict*)\n  apply(erule_tac\n      x=\"x\"\n      in ballE)\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac x)(*strict*)\n   apply(simp add: valid_parser_step_label_def option_to_set_def list_to_option_def)\n   apply(clarsimp)\n   apply(rename_tac x xa k w)(*strict*)\n   apply(case_tac \"kPrefix k (w @ [parser_bottom G])\")\n    apply(rename_tac x xa k w)(*strict*)\n    apply(force)\n   apply(rename_tac x xa k w a list)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x k w a)(*strict*)\n   apply(simp add: kPrefix_def)\n   apply(simp add: valid_parser_def)\n   apply(case_tac \"k-length w\")\n    apply(rename_tac x k w a)(*strict*)\n    apply(clarsimp)\n    apply (metis DiffE List.set_simps(2) kPrefix_def set_kPrefix_subset set_subset_in)\n   apply(rename_tac x k w a nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac x)(*strict*)\n   apply(simp add: valid_parser_step_label_def)\n   apply(simp add: may_terminated_by_def kleene_star_def append_language_def)\n   apply(clarsimp)\n   apply(rename_tac x k w)(*strict*)\n   apply(simp add: kPrefix_def)\n   apply(case_tac \"k-length w\")\n    apply(rename_tac x k w)(*strict*)\n    prefer 2\n    apply(rename_tac x k w nat)(*strict*)\n    apply(force)\n   apply(rename_tac x k w)(*strict*)\n   apply(clarsimp)\n   apply(rule_tac\n      x=\"rev (butlast (rule_lpop x))\"\n      in exI)\n   apply(clarsimp)\n   apply(rename_tac x k w xa)(*strict*)\n   apply (metis in_set_butlastD subsetE)\n  apply(rename_tac x)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac x)(*strict*)\n   apply(simp add: valid_parser_step_label_def)\n   apply(simp add: may_terminated_by_def kleene_star_def append_language_def)\n   apply(clarsimp)\n   apply(rename_tac x k w)(*strict*)\n   apply(simp add: kPrefix_def)\n   apply(case_tac \"k-length w\")\n    apply(rename_tac x k w)(*strict*)\n    prefer 2\n    apply(rename_tac x k w nat)(*strict*)\n    apply(force)\n   apply(rename_tac x k w)(*strict*)\n   apply(clarsimp)\n   apply(rule_tac\n      x=\"rev (butlast (rule_lpush x))\"\n      in exI)\n   apply(clarsimp)\n   apply(rename_tac x k w xa)(*strict*)\n   apply (metis in_set_butlastD subsetE)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: must_terminated_by_def kleene_star_def append_language_def)\n  apply(clarsimp)\n  apply(rule order_antisym)\n   apply(rename_tac x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x a)(*strict*)\n   apply(simp add: valid_parser_step_label_def)\n   apply(clarsimp)\n   apply(rename_tac x a k w)(*strict*)\n   apply(simp add: kPrefix_def)\n   apply(case_tac \"k-length w\")\n    apply(rename_tac x a k w)(*strict*)\n    prefer 2\n    apply(rename_tac x a k w nat)(*strict*)\n    apply(force)\n   apply(rename_tac x a k w)(*strict*)\n   apply(clarsimp)\n   apply (metis in_set_butlastD set_append2 set_rev set_subset_in subsetE)\n  apply(rename_tac x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x a)(*strict*)\n  apply(simp add: valid_parser_step_label_def)\n  apply(clarsimp)\n  apply(rename_tac x a k w)(*strict*)\n  apply(simp add: kPrefix_def)\n  apply(case_tac \"k-length w\")\n   apply(rename_tac x a k w)(*strict*)\n   prefer 2\n   apply(rename_tac x a k w nat)(*strict*)\n   apply(force)\n  apply(rename_tac x a k w)(*strict*)\n  apply(clarsimp)\n  apply (metis in_set_butlastD set_append2 set_rev set_subset_in subsetE)\n  done\n\nlemma F_PARSER_TO_EDPDA__configuration_reflects_steps: \"\n  e1 \\<in> parser_rules G1\n  \\<Longrightarrow> parserS_step_relation G1 c1 e1 c1'\n  \\<Longrightarrow> c1 \\<in> parserS.get_accessible_configurations G1\n  \\<Longrightarrow> F_PARSER_TO_EDPDA__SpecInput1 G1 BOX\n  \\<Longrightarrow> epdaS_step_relation (F_PARSER_TO_EDPDA G1 BOX) (F_PARSER_TO_EDPDA__configuration G1 c1 BOX) (F_PARSER_TO_EDPDA__rules e1) (F_PARSER_TO_EDPDA__configuration G1 c1' BOX)\"\n  apply(subgoal_tac \"c1 \\<in> parserS_configurations G1\")\n   prefer 2\n   apply(simp add: parserS.get_accessible_configurations_def)\n   apply(clarsimp)\n   apply(rename_tac d i)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(case_tac \"d i\")\n    apply(rename_tac d i)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d i a)(*strict*)\n   apply(case_tac a)\n   apply(rename_tac d i a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i option)(*strict*)\n   apply(rule parserS.belongs_configurations)\n    apply(rename_tac d i option)(*strict*)\n    apply(rule parserS.derivation_initial_belongs)\n     apply(rename_tac d i option)(*strict*)\n     apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n    apply(rename_tac d i option)(*strict*)\n    apply(force)\n   apply(rename_tac d i option)(*strict*)\n   apply(force)\n  apply(subgoal_tac \"valid_parser_step_label G1 e1\")\n   prefer 2\n   apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def valid_parser_def)\n  apply(simp add: epdaS_step_relation_def)\n  apply(rule conjI)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rule conjI)\n   apply(simp add: F_PARSER_TO_EDPDA__configuration_def)\n   apply(simp add: F_PARSER_TO_EDPDA__rules_def)\n   apply(simp add: parserS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac x xa)(*strict*)\n   apply(simp add: valid_parser_step_label_def)\n  apply(rule conjI)\n   apply(simp add: F_PARSER_TO_EDPDA__configuration_def)\n   apply(simp add: F_PARSER_TO_EDPDA__rules_def)\n   apply(simp add: parserS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac x xa)(*strict*)\n   apply(simp add: valid_parser_step_label_def)\n  apply(rule conjI)\n   apply(simp add: F_PARSER_TO_EDPDA__configuration_def)\n   apply(simp add: F_PARSER_TO_EDPDA__rules_def)\n   apply(simp add: parserS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac x xa)(*strict*)\n   apply(simp add: valid_parser_step_label_def)\n   apply(simp add: parserS_configurations_def)\n   apply(clarsimp)\n   apply(rename_tac x xa k w wa xc)(*strict*)\n   apply(case_tac xa)\n    apply(rename_tac x xa k w wa xc)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac x k w wa xc)(*strict*)\n    apply(simp add: kPrefix_def)\n    apply(clarsimp)\n    apply(case_tac \"k-length w\")\n     apply(rename_tac x k w wa xc)(*strict*)\n     apply(clarsimp)\n     apply (metis F_PARSER_TO_EDPDA__SpecInput1_def Suc_length Zero_not_Suc append_Nil2 list.size(3))\n    apply(rename_tac x k w wa xc nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac x k w xc nat xa)(*strict*)\n    apply(rule_tac\n      t=\"butlast_if_match (w @ [parser_bottom G1]) (parser_bottom G1)\"\n      and s=\"w\"\n      in ssubst)\n     apply(rename_tac x k w xc nat xa)(*strict*)\n     apply (metis butlast_if_match_direct)\n    apply(rename_tac x k w xc nat xa)(*strict*)\n    apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n   apply(rename_tac x xa k w wa xc a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. xa = w' @ [x']\")\n    apply(rename_tac x xa k w wa xc a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac x xa k w wa xc a list)(*strict*)\n   apply(thin_tac \"xa=a#list\")\n   apply(clarsimp)\n   apply(rename_tac x k w xc w')(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n   apply(clarsimp)\n   apply(rename_tac x k w w')(*strict*)\n   apply(rule_tac\n      t=\"butlast_if_match (kPrefix k (w @ [parser_bottom G1]) @ w' @ [parser_bottom G1]) (parser_bottom G1)\"\n      and s=\"kPrefix k (w @ [parser_bottom G1]) @ w'\"\n      in ssubst)\n    apply(rename_tac x k w w')(*strict*)\n    apply (metis butlast_if_match_direct butlast_if_match_pull_out_prime)\n   apply(rename_tac x k w w')(*strict*)\n   apply(rule_tac\n      t=\"butlast_if_match (w' @ [parser_bottom G1]) (parser_bottom G1)\"\n      and s=\"w'\"\n      in ssubst)\n    apply(rename_tac x k w w')(*strict*)\n    apply (metis butlast_if_match_direct)\n   apply(rename_tac x k w w')(*strict*)\n   apply(clarsimp)\n   apply(simp add: kPrefix_def)\n   apply(clarsimp)\n   apply(case_tac \"k-length w\")\n    apply(rename_tac x k w w')(*strict*)\n    prefer 2\n    apply(rename_tac x k w w' nat)(*strict*)\n    apply(force)\n   apply(rename_tac x k w w')(*strict*)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"e1\"\n      in ballE)\n    apply(rename_tac x k w w')(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac x k w w')(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"w\")\n    apply(rename_tac x k w w')(*strict*)\n    apply(simp add: option_to_list_def list_to_option_def)\n   apply(rename_tac x k w w' a list)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x k w' a list)(*strict*)\n   apply(case_tac k)\n    apply(rename_tac x k w' a list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac x w' a list)(*strict*)\n    apply(simp add: option_to_list_def list_to_option_def)\n   apply(rename_tac x k w' a list nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x w' a list nat)(*strict*)\n   apply(simp add: option_to_list_def list_to_option_def)\n   apply(clarsimp)\n   apply (metis List.length_take length_0_conv list.size(3) take_all_length)\n  apply(simp add: F_PARSER_TO_EDPDA__configuration_def)\n  apply(simp add: F_PARSER_TO_EDPDA__rules_def)\n  apply(simp add: parserS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac x xa)(*strict*)\n  apply(simp add: valid_parser_step_label_def)\n  apply(clarsimp)\n  apply(rename_tac x xa k w xc)(*strict*)\n  apply(case_tac \"rule_lpush e1\")\n   apply(rename_tac x xa k w xc)(*strict*)\n   apply(force)\n  apply(rename_tac x xa k w xc a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. rule_lpush e1 = w' @ [x']\")\n   apply(rename_tac x xa k w xc a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac x xa k w xc a list)(*strict*)\n  apply(thin_tac \"rule_lpush e1=a#list\")\n  apply(clarsimp)\n  apply(rename_tac x xa k w xc w' x')(*strict*)\n  apply(case_tac \"rule_lpop e1\")\n   apply(rename_tac x xa k w xc w' x')(*strict*)\n   apply(force)\n  apply(rename_tac x xa k w xc w' x' a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. rule_lpop e1 = w' @ [x']\")\n   apply(rename_tac x xa k w xc w' x' a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac x xa k w xc w' x' a list)(*strict*)\n  apply(thin_tac \"rule_lpop e1=a#list\")\n  apply(clarsimp)\n  apply(rename_tac x xa k w xc w' x' w'a x'a)(*strict*)\n  apply(rule_tac\n      t=\"butlast (x @ w'a @ [x'a])\"\n      and s=\"x @ w'a\"\n      in ssubst)\n   apply(rename_tac x xa k w xc w' x' w'a x'a)(*strict*)\n   apply (metis butlast_snoc_2)\n  apply(rename_tac x xa k w xc w' x' w'a x'a)(*strict*)\n  apply(rule_tac\n      t=\"butlast (x @ w' @ [x'])\"\n      and s=\"x @ w'\"\n      in ssubst)\n   apply(rename_tac x xa k w xc w' x' w'a x'a)(*strict*)\n   apply (metis butlast_snoc_2)\n  apply(rename_tac x xa k w xc w' x' w'a x'a)(*strict*)\n  apply(rule_tac\n      x=\"rev x@[BOX]\"\n      in exI)\n  apply (metis NoteAboutRev append_Cons rev_append)\n  done\n\nlemma F_PARSER_TO_EDPDA__SpecInput1_never_empty_lhs: \"\n  e1 \\<in> parser_rules G1\n  \\<Longrightarrow> F_PARSER_TO_EDPDA__SpecInput1 G1 BOX\n  \\<Longrightarrow> parserS.derivation_initial G1 d\n  \\<Longrightarrow> d i = Some (pair option c1)\n  \\<Longrightarrow> parserS_conf_stack c1 \\<noteq> []\"\n  apply(induct i arbitrary: option c1)\n   apply(rename_tac option c1)(*strict*)\n   apply(simp add: parserS.derivation_initial_def)\n   apply(clarsimp)\n   apply(rename_tac c1)(*strict*)\n   apply(simp add: parserS_initial_configurations_def)\n  apply(rename_tac i option c1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i option c1)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d i = Some (pair e1 c1) \\<and> d (Suc i) = Some (pair (Some e2) c2) \\<and> parserS_step_relation G1 c1 e2 c2\")\n   apply(rename_tac i option c1)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc i\"\n      in parserS.step_detail_before_some_position)\n     apply(rename_tac i option c1)(*strict*)\n     apply(rule parserS.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac i option c1)(*strict*)\n    apply(force)\n   apply(rename_tac i option c1)(*strict*)\n   apply(force)\n  apply(rename_tac i option c1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i c1 e1a e2 c1a)(*strict*)\n  apply(erule_tac\n      x=\"e1a\"\n      in meta_allE)\n  apply(erule_tac\n      x=\"c1a\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(simp add: parserS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac i c1 e1a e2 c1a x)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n  done\n\nlemma F_PARSER_TO_EDPDA_preserves_steps: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G BOX\n  \\<Longrightarrow> c \\<in> epdaS.get_accessible_configurations (F_PARSER_TO_EDPDA G BOX)\n  \\<Longrightarrow> epdaS_step_relation (F_PARSER_TO_EDPDA G BOX) c (F_PARSER_TO_EDPDA__rules x) c1\n  \\<Longrightarrow> x \\<in> parser_rules G\n  \\<Longrightarrow> parserS_step_relation G (F_PARSER_TO_EDPDA__configuration_rev G c) x (F_PARSER_TO_EDPDA__configuration_rev G c1)\"\n  apply(subgoal_tac \"\\<exists>w. BOX \\<notin> set w \\<and> epdaS_conf_stack c = w @ [BOX]\")\n   prefer 2\n   apply(rule_tac\n      t=\"BOX\"\n      and s=\"epda_box (F_PARSER_TO_EDPDA G BOX)\"\n      in ssubst)\n    apply(simp add: F_PARSER_TO_EDPDA_def)\n   apply(simp add: epdaS.get_accessible_configurations_def)\n   apply(clarsimp)\n   apply(rename_tac d i)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(case_tac \"d i\")\n    apply(rename_tac d i)(*strict*)\n    apply(force)\n   apply(rename_tac d i a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac d i a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i option)(*strict*)\n   apply(rule epda_no_use_epda_box_implies_stack_content)\n      apply(rename_tac d i option)(*strict*)\n      apply (metis F_PARSER_TO_EDPDA_generates_epda)\n     apply(rename_tac d i option)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac d i option)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac d i option)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i option r)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n   apply(clarsimp)\n   apply(rename_tac d i option xa)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__rules_def)\n   apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n   apply(clarsimp)\n   apply(subgoal_tac \"valid_parser_step_label G xa\")\n    apply(rename_tac d i option xa)(*strict*)\n    prefer 2\n    apply(simp add: valid_parser_def)\n   apply(rename_tac d i option xa)(*strict*)\n   apply(simp add: valid_parser_step_label_def)\n   apply(clarsimp)\n   apply(rename_tac d i option xa k w)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac d i option xa k w)(*strict*)\n    apply (metis in_set_butlastD insert_absorb insert_subset)\n   apply(rename_tac d i option xa k w)(*strict*)\n   apply (metis in_set_butlastD insert_absorb insert_subset)\n  apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def parserS_step_relation_def epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac w wa)(*strict*)\n  apply(subgoal_tac \"valid_parser_step_label G x\")\n   apply(rename_tac w wa)(*strict*)\n   prefer 2\n   apply(simp add: valid_parser_def)\n  apply(rename_tac w wa)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac w wa)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__configuration_rev_def F_PARSER_TO_EDPDA__rules_def)\n   apply(case_tac wa)\n    apply(rename_tac w wa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac w)(*strict*)\n    apply(subgoal_tac \"False\")\n     apply(rename_tac w)(*strict*)\n     apply(force)\n    apply(rename_tac w)(*strict*)\n    apply(subgoal_tac \"BOX \\<in> set (rule_lpop x)\")\n     apply(rename_tac w)(*strict*)\n     apply(simp add: valid_parser_step_label_def)\n     apply(clarsimp)\n     apply(rename_tac w k wa)(*strict*)\n     apply (metis set_mp_prime)\n    apply(rename_tac w)(*strict*)\n    apply (metis last_in_set_X set_rev snoc_eq_iff_butlast trivButLast)\n   apply(rename_tac w wa a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. wa = w' @ [x']\")\n    apply(rename_tac w wa a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac w wa a list)(*strict*)\n   apply(thin_tac \"wa=a#list\")\n   apply(clarsimp)\n   apply(rename_tac w')(*strict*)\n   apply(simp add: valid_parser_step_label_def)\n   apply(clarsimp)\n   apply(rename_tac w' k w)(*strict*)\n   apply(case_tac \"rule_lpush x\")\n    apply(rename_tac w' k w)(*strict*)\n    apply(force)\n   apply(rename_tac w' k w a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. rule_lpush x = w' @ [x']\")\n    apply(rename_tac w' k w a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac w' k w a list)(*strict*)\n   apply(thin_tac \"rule_lpush x=a#list\")\n   apply(clarsimp)\n   apply(rename_tac w' k w w'a)(*strict*)\n   apply(rule_tac\n      t=\"butlast (rev w'a @ w' @ [BOX])\"\n      and s=\"rev w'a @ w'\"\n      in ssubst)\n    apply(rename_tac w' k w w'a)(*strict*)\n    apply (metis append_eq_appendI snoc_eq_iff_butlast)\n   apply(rename_tac w' k w w'a)(*strict*)\n   apply (metis rev_append rev_rev_ident)\n  apply(rename_tac w wa)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__configuration_rev_def)\n  apply(simp add: F_PARSER_TO_EDPDA__rules_def)\n  apply(erule_tac\n      x=\"x\"\n      in ballE)\n   apply(rename_tac w wa)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac w wa)(*strict*)\n  apply(simp add: option_to_list_def list_to_option_def)\n  apply(case_tac \"rule_rpop x\")\n   apply(rename_tac w wa)(*strict*)\n   apply(force)\n  apply(rename_tac w wa a list)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma F_PARSER_TO_EDPDA_preserves_steps_prime: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G BOX\n  \\<Longrightarrow> \\<exists>w. BOX \\<notin> set w \\<and> epdaS_conf_stack c = w @ [BOX]\n  \\<Longrightarrow> epdaS_step_relation (F_PARSER_TO_EDPDA G BOX) c (F_PARSER_TO_EDPDA__rules x) c1\n  \\<Longrightarrow> x \\<in> parser_rules G\n  \\<Longrightarrow> parserS_step_relation G (F_PARSER_TO_EDPDA__configuration_rev G c) x (F_PARSER_TO_EDPDA__configuration_rev G c1)\"\n  apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def parserS_step_relation_def epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac w wa)(*strict*)\n  apply(subgoal_tac \"valid_parser_step_label G x\")\n   apply(rename_tac w wa)(*strict*)\n   prefer 2\n   apply(simp add: valid_parser_def)\n  apply(rename_tac w wa)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac w wa)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__configuration_rev_def F_PARSER_TO_EDPDA__rules_def)\n   apply(case_tac wa)\n    apply(rename_tac w wa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac w)(*strict*)\n    apply(subgoal_tac \"False\")\n     apply(rename_tac w)(*strict*)\n     apply(force)\n    apply(rename_tac w)(*strict*)\n    apply(subgoal_tac \"BOX \\<in> set (rule_lpop x)\")\n     apply(rename_tac w)(*strict*)\n     apply(simp add: valid_parser_step_label_def)\n     apply(clarsimp)\n     apply(rename_tac w k wa)(*strict*)\n     apply (metis set_mp_prime)\n    apply(rename_tac w)(*strict*)\n    apply (metis last_in_set_X set_rev snoc_eq_iff_butlast trivButLast)\n   apply(rename_tac w wa a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. wa = w' @ [x']\")\n    apply(rename_tac w wa a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac w wa a list)(*strict*)\n   apply(thin_tac \"wa=a#list\")\n   apply(clarsimp)\n   apply(rename_tac w')(*strict*)\n   apply(simp add: valid_parser_step_label_def)\n   apply(clarsimp)\n   apply(rename_tac w' k w)(*strict*)\n   apply(case_tac \"rule_lpush x\")\n    apply(rename_tac w' k w)(*strict*)\n    apply(force)\n   apply(rename_tac w' k w a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. rule_lpush x = w' @ [x']\")\n    apply(rename_tac w' k w a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac w' k w a list)(*strict*)\n   apply(thin_tac \"rule_lpush x=a#list\")\n   apply(clarsimp)\n   apply(rename_tac w' k w w'a)(*strict*)\n   apply(rule_tac\n      t=\"butlast (rev w'a @ w' @ [BOX])\"\n      and s=\"rev w'a @ w'\"\n      in ssubst)\n    apply(rename_tac w' k w w'a)(*strict*)\n    apply (metis append_eq_appendI snoc_eq_iff_butlast)\n   apply(rename_tac w' k w w'a)(*strict*)\n   apply (metis rev_append rev_rev_ident)\n  apply(rename_tac w wa)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__configuration_rev_def)\n  apply(simp add: F_PARSER_TO_EDPDA__rules_def)\n  apply(erule_tac\n      x=\"x\"\n      in ballE)\n   apply(rename_tac w wa)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac w wa)(*strict*)\n  apply(simp add: option_to_list_def list_to_option_def)\n  apply(case_tac \"rule_rpop x\")\n   apply(rename_tac w wa)(*strict*)\n   apply(force)\n  apply(rename_tac w wa a list)(*strict*)\n  apply(clarsimp)\n  done\n\ndefinition F_PARSER_TO_EDPDA__LR__relation_TSstructure :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"F_PARSER_TO_EDPDA__LR__relation_TSstructure G1 G2 \\<equiv>\n  \\<exists>BOX.\n    F_PARSER_TO_EDPDA__SpecInput1 G1 BOX\n    \\<and> G2 = F_PARSER_TO_EDPDA G1 BOX\"\n\ndefinition F_PARSER_TO_EDPDA__LR__relation_configuration :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event, 'stack) epda\n  \\<Rightarrow> ('stack, 'event) parserS_conf\n  \\<Rightarrow> ('stack, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_PARSER_TO_EDPDA__LR__relation_configuration G1 G2 c1 c2 \\<equiv>\n  F_PARSER_TO_EDPDA__LR__relation_TSstructure G1 G2\n  \\<and> c1 \\<in> parserS.get_accessible_configurations G1\n  \\<and> F_PARSER_TO_EDPDA__configuration G1 c1 (epda_box G2) = c2\"\n\ndefinition F_PARSER_TO_EDPDA__LR__relation_initial_configuration :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event, 'stack) epda\n  \\<Rightarrow> ('stack, 'event) parserS_conf\n  \\<Rightarrow> ('stack, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_PARSER_TO_EDPDA__LR__relation_initial_configuration G1 G2 c1 c2 \\<equiv>\n  F_PARSER_TO_EDPDA__LR__relation_TSstructure G1 G2\n  \\<and> c1 \\<in> parserS_initial_configurations G1\n  \\<and> F_PARSER_TO_EDPDA__configuration G1 c1 (epda_box G2) = c2\"\n\ndefinition F_PARSER_TO_EDPDA__LR__relation_effect :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event, 'stack) epda\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> bool\"\n  where\n    \"F_PARSER_TO_EDPDA__LR__relation_effect G1 G2 w1 w2 \\<equiv>\n  F_PARSER_TO_EDPDA__LR__relation_TSstructure G1 G2\n  \\<and> w1 = w2\"\n\ndefinition F_PARSER_TO_EDPDA__LR__relation_step_labels :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event, 'stack) epda\n  \\<Rightarrow> ('stack, 'event) parser_step_label\n  \\<Rightarrow> ('stack, 'event, 'stack) epda_step_label\n  \\<Rightarrow> bool\"\n  where\n    \"F_PARSER_TO_EDPDA__LR__relation_step_labels G1 G2 e1 e2 \\<equiv>\n  F_PARSER_TO_EDPDA__LR__relation_TSstructure G1 G2\n  \\<and> e1 \\<in> parser_rules G1\n  \\<and> F_PARSER_TO_EDPDA__rules e1 = e2\"\n\nlemma parserS_epdaS_P2A_StateSimLR_AX_TSstructure_relation_TSstructure1_belongs: \"\n  (\\<forall>G1. Ex (F_PARSER_TO_EDPDA__LR__relation_TSstructure G1) \\<longrightarrow> valid_parser G1)\"\n  apply(clarsimp)\n  apply(rename_tac G1 x)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__LR__relation_TSstructure_def)\n  apply(clarsimp)\n  apply(rename_tac G1 BOX)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n  done\n\nlemma parserS_epdaS_P2A_StateSimLR_AX_TSstructure_relation_TSstructure2_belongs: \"\n  (\\<forall>G1 G2. F_PARSER_TO_EDPDA__LR__relation_TSstructure G1 G2 \\<longrightarrow> valid_epda G2)\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__LR__relation_TSstructure_def)\n  apply(clarsimp)\n  apply(rename_tac G1 BOX)(*strict*)\n  apply (metis F_PARSER_TO_EDPDA_generates_epda)\n  done\n\ndefinition F_PARSER_TO_EDPDA__LR__relation_initial_simulation :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event, 'stack) epda\n  \\<Rightarrow> ('stack, 'event) parserS_conf\n  \\<Rightarrow> (('stack, 'event, 'stack) epda_step_label, ('stack, 'event, 'stack) epdaS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_PARSER_TO_EDPDA__LR__relation_initial_simulation G1 G2 c1 d \\<equiv>\n  d = der1 (F_PARSER_TO_EDPDA__configuration G1 c1 (epda_box G2))\"\n\ndefinition F_PARSER_TO_EDPDA__LR__relation_step_simulation :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event, 'stack) epda\n  \\<Rightarrow> ('stack, 'event) parserS_conf\n  \\<Rightarrow> ('stack, 'event) parser_step_label\n  \\<Rightarrow> ('stack, 'event) parserS_conf\n  \\<Rightarrow> ('stack, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> (('stack, 'event, 'stack) epda_step_label, ('stack, 'event, 'stack) epdaS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_PARSER_TO_EDPDA__LR__relation_step_simulation G1 G2 c1 e1 c1' c2 d \\<equiv>\n  d = der2 (F_PARSER_TO_EDPDA__configuration G1 c1 (epda_box G2)) (F_PARSER_TO_EDPDA__rules e1) (F_PARSER_TO_EDPDA__configuration G1 c1' (epda_box G2))\"\n\nlemma F_PARSER_TO_EDPDA__configuration_preserves_configurations: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G1 BOX\n  \\<Longrightarrow> G2 = F_PARSER_TO_EDPDA G1 BOX\n  \\<Longrightarrow> c1 \\<in> parserS_configurations G1\n  \\<Longrightarrow> parserS_conf_stack c1 \\<noteq> []\n  \\<Longrightarrow> F_PARSER_TO_EDPDA__configuration G1 c1 (epda_box G2) \\<in> epdaS_configurations G2\"\n  apply(simp add: epdaS_configurations_def F_PARSER_TO_EDPDA__configuration_def parserS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac l w)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac l w)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n   apply (metis last_in_set_X)\n  apply(rename_tac l w)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac l w)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n   apply (metis butlast_if_match_direct insert_Diff_single subset_insertI2 subset_insert_iff)\n  apply(rename_tac l w)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac l w)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rename_tac l w)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply (metis subset_insertI2 subset_trans trivButLast)\n  done\n\nlemma F_PARSER_TO_EDPDA__configuration_preserves_initial_configurations: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G1 BOX\n  \\<Longrightarrow> G2 = F_PARSER_TO_EDPDA G1 BOX\n  \\<Longrightarrow> c1 \\<in> parserS_initial_configurations G1\n  \\<Longrightarrow> F_PARSER_TO_EDPDA__configuration G1 c1 (epda_box G2) \\<in> epdaS_initial_configurations G2\"\n  apply(simp add: epdaS_initial_configurations_def)\n  apply(rule conjI)\n   apply(simp only: F_PARSER_TO_EDPDA__configuration_def)\n   apply(clarsimp)\n   apply(simp only: parserS_initial_configurations_def)\n   apply(clarsimp)\n  apply(rule conjI)\n   apply(simp only: F_PARSER_TO_EDPDA__configuration_def)\n   apply(clarsimp)\n   apply(simp only: parserS_initial_configurations_def)\n   apply(clarsimp)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rule F_PARSER_TO_EDPDA__configuration_preserves_configurations)\n     apply(force)\n    apply(force)\n   apply (metis parserS_inst_AX_initial_configuration_belongs subsetE)\n  apply(simp add: parserS_initial_configurations_def)\n  done\n\nlemma parserS_epdaS_P2A_StateSimLR_inst_relation_initial_simulation: \"\n  (\\<forall>G1 G2. F_PARSER_TO_EDPDA__LR__relation_TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> parserS_initial_configurations G1 \\<longrightarrow> (\\<exists>d2. epdaS.derivation_initial G2 d2 \\<and> F_PARSER_TO_EDPDA__LR__relation_initial_configuration G1 G2 c1 (the (get_configuration (d2 0))) \\<and> F_PARSER_TO_EDPDA__LR__relation_initial_simulation G1 G2 c1 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_PARSER_TO_EDPDA__LR__relation_configuration G1 G2 c1 (the (get_configuration (d2 n)))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__LR__relation_initial_simulation_def)\n  apply(simp add: F_PARSER_TO_EDPDA__LR__relation_initial_configuration_def)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: epdaS.derivation_initial_def)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1)(*strict*)\n    apply(rule epdaS.der1_is_derivation)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: der1_def)\n   apply(simp add: F_PARSER_TO_EDPDA__LR__relation_TSstructure_def)\n   apply(clarsimp)\n   apply(rename_tac G1 c1 BOX)(*strict*)\n   apply(rule F_PARSER_TO_EDPDA__configuration_preserves_initial_configurations)\n     apply(rename_tac G1 c1 BOX)(*strict*)\n     apply(force)\n    apply(rename_tac G1 c1 BOX)(*strict*)\n    apply(force)\n   apply(rename_tac G1 c1 BOX)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: get_configuration_def der1_def)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule_tac\n      x=\"0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule der1_maximum_of_domain)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__LR__relation_configuration_def F_PARSER_TO_EDPDA__LR__relation_TSstructure_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 BOX)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 c1 BOX)(*strict*)\n   apply(simp add: parserS.get_accessible_configurations_def)\n   apply(rule_tac\n      x=\"der1 c1\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac G1 c1 BOX)(*strict*)\n    apply(simp add: parserS.derivation_initial_def)\n    apply(rule conjI)\n     apply(rename_tac G1 c1 BOX)(*strict*)\n     apply(rule parserS.der1_is_derivation)\n    apply(rename_tac G1 c1 BOX)(*strict*)\n    apply(simp add: der1_def)\n   apply(rename_tac G1 c1 BOX)(*strict*)\n   apply(rule_tac\n      x=\"0\"\n      in exI)\n   apply(simp add: get_configuration_def)\n   apply(simp add: der1_def)\n  apply(rename_tac G1 c1 BOX)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__configuration_def get_configuration_def der1_def)\n  done\n\nlemma parserS_epdaS_P2A_StateSimLR_inst_relation_step_simulation: \"\n  (\\<forall>G1 G2. F_PARSER_TO_EDPDA__LR__relation_TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_PARSER_TO_EDPDA__LR__relation_configuration G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> parser_step_labels G1 \\<longrightarrow> (\\<forall>c1'. parserS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<exists>d2. epdaS.derivation G2 d2 \\<and> epdaS.belongs G2 d2 \\<and> the (get_configuration (d2 0)) = c2 \\<and> F_PARSER_TO_EDPDA__LR__relation_step_simulation G1 G2 c1 e1 c1' c2 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_PARSER_TO_EDPDA__LR__relation_configuration G1 G2 c1' (the (get_configuration (d2 n)))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__LR__relation_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n  apply(rule_tac\n      x=\"der2 (F_PARSER_TO_EDPDA__configuration G1 c1 (epda_box G2)) (F_PARSER_TO_EDPDA__rules e1) (F_PARSER_TO_EDPDA__configuration G1 c1' (epda_box G2))\"\n      in exI)\n  apply(rule context_conjI)\n   apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n   apply(rule epdaS.der2_is_derivation)\n   apply(simp add: F_PARSER_TO_EDPDA__LR__relation_TSstructure_def)\n   apply(clarsimp)\n   apply(rename_tac G1 c1 e1 c1' BOX)(*strict*)\n   apply(rule_tac\n      t=\"epda_box (F_PARSER_TO_EDPDA G1 BOX)\"\n      and s=\"BOX\"\n      in ssubst)\n    apply(rename_tac G1 c1 e1 c1' BOX)(*strict*)\n    apply(simp add: F_PARSER_TO_EDPDA_def parser_step_labels_def)\n   apply(rename_tac G1 c1 e1 c1' BOX)(*strict*)\n   apply(simp add: parser_step_labels_def)\n   apply(rule F_PARSER_TO_EDPDA__configuration_reflects_steps)\n      apply(rename_tac G1 c1 e1 c1' BOX)(*strict*)\n      apply(force)\n     apply(rename_tac G1 c1 e1 c1' BOX)(*strict*)\n     apply(force)\n    apply(rename_tac G1 c1 e1 c1' BOX)(*strict*)\n    apply(force)\n   apply(rename_tac G1 c1 e1 c1' BOX)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n  apply(subgoal_tac \"c1 \\<in> parserS_configurations G1\")\n   apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n   prefer 2\n   apply(simp add: parserS.get_accessible_configurations_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' d i)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(case_tac \"d i\")\n    apply(rename_tac G1 G2 c1 e1 c1' d i)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' d i a)(*strict*)\n   apply(case_tac a)\n   apply(rename_tac G1 G2 c1 e1 c1' d i a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' d i option)(*strict*)\n   apply(rule parserS.belongs_configurations)\n    apply(rename_tac G1 G2 c1 e1 c1' d i option)(*strict*)\n    apply(rule parserS.derivation_initial_belongs)\n     apply(rename_tac G1 G2 c1 e1 c1' d i option)(*strict*)\n     apply(simp add: F_PARSER_TO_EDPDA__LR__relation_TSstructure_def F_PARSER_TO_EDPDA__SpecInput1_def)\n    apply(rename_tac G1 G2 c1 e1 c1' d i option)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 e1 c1' d i option)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__LR__relation_TSstructure_def)\n   apply(clarsimp)\n   apply(rename_tac G1 c1 e1 c1' BOX)(*strict*)\n   apply(rule epdaS.der2_belongs_prime)\n     apply(rename_tac G1 c1 e1 c1' BOX)(*strict*)\n     apply (metis F_PARSER_TO_EDPDA_generates_epda)\n    apply(rename_tac G1 c1 e1 c1' BOX)(*strict*)\n    apply(rule F_PARSER_TO_EDPDA__configuration_preserves_configurations)\n       apply(rename_tac G1 c1 e1 c1' BOX)(*strict*)\n       apply(force)\n      apply(rename_tac G1 c1 e1 c1' BOX)(*strict*)\n      apply(force)\n     apply(rename_tac G1 c1 e1 c1' BOX)(*strict*)\n     apply(force)\n    apply(rename_tac G1 c1 e1 c1' BOX)(*strict*)\n    apply(simp add: parserS.get_accessible_configurations_def parser_step_labels_def)\n    apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1' BOX d i)(*strict*)\n    apply(simp add: get_configuration_def)\n    apply(case_tac \"d i\")\n     apply(rename_tac G1 c1 e1 c1' BOX d i)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1' BOX d i a)(*strict*)\n    apply(clarsimp)\n    apply(case_tac a)\n    apply(rename_tac G1 c1 e1 c1' BOX d i a option b)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1' BOX d i option)(*strict*)\n    apply(subgoal_tac \"parserS_conf_stack c1 \\<noteq> []\")\n     apply(rename_tac G1 c1 e1 c1' BOX d i option)(*strict*)\n     apply(force)\n    apply(rename_tac G1 c1 e1 c1' BOX d i option)(*strict*)\n    apply(rule F_PARSER_TO_EDPDA__SpecInput1_never_empty_lhs)\n       apply(rename_tac G1 c1 e1 c1' BOX d i option)(*strict*)\n       apply(force)\n      apply(rename_tac G1 c1 e1 c1' BOX d i option)(*strict*)\n      apply(force)\n     apply(rename_tac G1 c1 e1 c1' BOX d i option)(*strict*)\n     apply(force)\n    apply(rename_tac G1 c1 e1 c1' BOX d i option)(*strict*)\n    apply(force)\n   apply(rename_tac G1 c1 e1 c1' BOX)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n   apply(simp add: der2_def)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__LR__relation_step_simulation_def)\n  apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n  apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n   apply(simp add: der2_maximum_of_domain)\n  apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n   apply(simp add: parserS.get_accessible_configurations_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' d i)(*strict*)\n   apply(rule_tac\n      x=\"derivation_append d (der2 c1 e1 c1') i\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 e1 c1' d i)(*strict*)\n    apply(simp add: parserS.derivation_initial_def)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 e1 c1' d i)(*strict*)\n     apply(rule parserS.derivation_append_preserves_derivation)\n       apply(rename_tac G1 G2 c1 e1 c1' d i)(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 e1 c1' d i)(*strict*)\n      apply(rule parserS.der2_is_derivation)\n      apply(force)\n     apply(rename_tac G1 G2 c1 e1 c1' d i)(*strict*)\n     apply(clarsimp)\n     apply(case_tac \"d i\")\n      apply(rename_tac G1 G2 c1 e1 c1' d i)(*strict*)\n      apply(clarsimp)\n      apply(simp add: get_configuration_def)\n     apply(rename_tac G1 G2 c1 e1 c1' d i a)(*strict*)\n     apply(clarsimp)\n     apply(case_tac a)\n     apply(rename_tac G1 G2 c1 e1 c1' d i a option b)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G1 G2 c1 e1 c1' d i option b)(*strict*)\n     apply(simp add: der2_def)\n     apply(clarsimp)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac G1 G2 c1 e1 c1' d i)(*strict*)\n    apply(simp add: derivation_append_def)\n   apply(rename_tac G1 G2 c1 e1 c1' d i)(*strict*)\n   apply(rule_tac\n      x=\"Suc i\"\n      in exI)\n   apply(simp add: get_configuration_def)\n   apply(simp add: derivation_append_def)\n   apply(simp add: der2_def)\n  apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n  apply(simp add: der2_def)\n  apply(simp add: get_configuration_def)\n  done\n\nlemma parserS_epdaS_P2A_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms: \"\n  ATS_Simulation_Configuration_Weak_axioms valid_parser parserS_initial_configurations parser_step_labels parserS_step_relation valid_epda epdaS_configurations epdaS_initial_configurations epda_step_labels epdaS_step_relation F_PARSER_TO_EDPDA__LR__relation_configuration F_PARSER_TO_EDPDA__LR__relation_initial_configuration F_PARSER_TO_EDPDA__LR__relation_TSstructure F_PARSER_TO_EDPDA__LR__relation_initial_simulation F_PARSER_TO_EDPDA__LR__relation_step_simulation\"\n  apply(simp add: ATS_Simulation_Configuration_Weak_axioms_def)\n  apply(simp add: parserS_epdaS_P2A_StateSimLR_inst_relation_initial_simulation parserS_epdaS_P2A_StateSimLR_inst_relation_step_simulation parserS_epdaS_P2A_StateSimLR_AX_TSstructure_relation_TSstructure1_belongs parserS_epdaS_P2A_StateSimLR_AX_TSstructure_relation_TSstructure2_belongs )\n  done\n\ninterpretation \"parserS_epdaS_P2A_StateSimLR\" : ATS_Simulation_Configuration_Weak\n  (* TSstructure1 *)\n  \"valid_parser\"\n  (* configurations1 *)\n  \"parserS_configurations\"\n  (* initial_configurations1 *)\n  \"parserS_initial_configurations\"\n  (* step_labels1 *)\n  \"parser_step_labels\"\n  (* step_relation1 *)\n  \"parserS_step_relation\"\n  (* effects1 *)\n  \"parser_markers\"\n  (* marking_condition1 *)\n  \"parserS_marking_condition\"\n  (* marked_effect1 *)\n  \"parserS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"parserS_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_PARSER_TO_EDPDA__LR__relation_configuration\"\n  (* relation_initial_configuration *)\n  \"F_PARSER_TO_EDPDA__LR__relation_initial_configuration\"\n  (* relation_effect *)\n  \"F_PARSER_TO_EDPDA__LR__relation_effect\"\n  (* relation_TSstructure *)\n  \"F_PARSER_TO_EDPDA__LR__relation_TSstructure\"\n  (* relation_initial_simulation *)\n  \"F_PARSER_TO_EDPDA__LR__relation_initial_simulation\"\n  (* relation_step_simulation *)\n  \"F_PARSER_TO_EDPDA__LR__relation_step_simulation\"\n  apply(simp add: LOCALE_DEFS epda_interpretations parser_interpretations)\n  apply(simp add: parserS_epdaS_P2A_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms)\n  done\n\nlemma parserS_epdaS_P2A_StateSimLR_inst_relation_step_simulation_preserves_unmarked_effect: \"\n  (\\<forall>G1 G2. F_PARSER_TO_EDPDA__LR__relation_TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_PARSER_TO_EDPDA__LR__relation_configuration G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> parser_step_labels G1 \\<longrightarrow> (\\<forall>c1'. parserS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<forall>d2. F_PARSER_TO_EDPDA__LR__relation_step_simulation G1 G2 c1 e1 c1' c2 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. parserS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_PARSER_TO_EDPDA__LR__relation_initial_configuration G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der2 c1 e1 c1') deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_PARSER_TO_EDPDA__LR__relation_configuration F_PARSER_TO_EDPDA__LR__relation_initial_simulation F_PARSER_TO_EDPDA__LR__relation_step_simulation G1 G2 (derivation_append deri1 (der2 c1 e1 c1') deri1n) (Suc deri1n) (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> left_total_on (F_PARSER_TO_EDPDA__LR__relation_effect G1 G2) (parserS_unmarked_effect G1 (derivation_append deri1 (der2 c1 e1 c1') deri1n)) (epdaS_unmarked_effect G2 (derivation_append deri2 d2 deri2n))))))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(rule_tac\n      x=\"a\"\n      in bexI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__LR__relation_effect_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(simp add: epdaS_unmarked_effect_def parserS_unmarked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri1 0 = Some (pair None c)\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca)(*strict*)\n   apply(subgoal_tac \"\\<exists>c. deri2 0 = Some (pair None c)\")\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb)(*strict*)\n    apply(rule_tac\n      x=\"cb\"\n      in exI)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb)(*strict*)\n     apply(simp add: derivation_append_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb)(*strict*)\n    apply(subgoal_tac \"parser_fixed_input_length_recN (derivation_append deri1 (der2 c1 e1 c1') deri1n) i=0\")\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb)(*strict*)\n     apply(clarsimp)\n     apply(thin_tac \"parser_fixed_input_length_recN (derivation_append deri1 (der2 c1 e1 c1') deri1n) i=0\")\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb)(*strict*)\n     apply(simp add: get_configuration_def)\n     apply(simp add: F_PARSER_TO_EDPDA__LR__relation_initial_configuration_def)\n     apply(clarsimp)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca)(*strict*)\n     apply(subgoal_tac \"c=ca\")\n      apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca)(*strict*)\n      prefer 2\n      apply(simp add: derivation_append_def)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' i e v ca)(*strict*)\n     apply(case_tac i)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' i e v ca)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c')(*strict*)\n      apply(rule_tac\n      x=\"F_PARSER_TO_EDPDA__configuration G1 c' (epda_box G2)\"\n      in exI)\n      apply(clarsimp)\n      apply(rule_tac\n      x=\"0\"\n      in exI)\n      apply(rule_tac\n      x=\"None\"\n      in exI)\n      apply(simp add: derivation_append_def)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' i e v ca nat)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca nat)(*strict*)\n     apply(rename_tac i)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i)(*strict*)\n     apply(simp add: parserS_epdaS_P2A_StateSimLR.simulating_derivation_def)\n     apply(simp add: parserS_epdaS_P2A_StateSimLR.simulating_derivation_DEF_def)\n     apply(clarsimp)\n     apply(subgoal_tac \"i < Suc deri1n\")\n      apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i)(*strict*)\n      prefer 2\n      apply(case_tac \"i<Suc deri1n\")\n       apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i)(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i)(*strict*)\n      apply(clarsimp)\n      apply(simp add: derivation_append_def der2_def)\n      apply(case_tac \"Suc i-deri1n\")\n       apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i nat)(*strict*)\n      apply(clarsimp)\n      apply(case_tac nat)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i nat)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' v ca i)(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i nat nata)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i)(*strict*)\n     apply(erule_tac\n      x=\"Suc i\"\n      in allE)\n     apply(erule impE)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i y)(*strict*)\n     apply(case_tac y)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i y option b)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i option b)(*strict*)\n     apply(rule_tac\n      x=\"b\"\n      in exI)\n     apply(rule conjI)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i option b)(*strict*)\n      apply(rule_tac\n      x=\"f (Suc i)\"\n      in exI)\n      apply(rule_tac\n      x=\"option\"\n      in exI)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i option b)(*strict*)\n     apply(simp add: F_PARSER_TO_EDPDA__LR__relation_configuration_def)\n     apply(clarsimp)\n     apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i option b)(*strict*)\n     apply(rule_tac\n      v=\"[parser_bottom G1]\"\n      in append_injr)\n     apply(rule_tac\n      t=\"epdaS_conf_scheduler (F_PARSER_TO_EDPDA__configuration G1 ca (epda_box G2)) @ [parser_bottom G1]\"\n      and s=\"parserS_conf_scheduler ca\"\n      in ssubst)\n      apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i option b)(*strict*)\n      apply(simp add: F_PARSER_TO_EDPDA__configuration_def)\n      apply(simp add: derivation_append_def parserS.derivation_initial_def parserS_initial_configurations_def parserS_configurations_def)\n      apply(clarsimp)\n      apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v i option b w)(*strict*)\n      apply (metis butlast_if_match_direct)\n     apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i option b)(*strict*)\n     apply(subgoal_tac \"epdaS_conf_scheduler b @ [parser_bottom G1] = parserS_conf_scheduler c'\")\n      apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i option b)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i option b)(*strict*)\n     apply(simp add: get_configuration_def)\n     apply(simp add: F_PARSER_TO_EDPDA__configuration_def)\n     apply(clarsimp)\n     apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i option)(*strict*)\n     apply(subgoal_tac \"c' \\<in> parserS_configurations G1\")\n      apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i option)(*strict*)\n      apply(simp add: parserS_configurations_def)\n      apply(clarsimp)\n      apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f e v ca i option l w)(*strict*)\n      apply (metis butlast_if_match_direct)\n     apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f c' e v ca i option)(*strict*)\n     apply (metis parserS_epdaS_P2A_StateSimLR.AX_TSstructure_relation_TSstructure1_belongs parserS.belongs_configurations parserS.der2_is_derivation parserS.derivation_append_preserves_derivation_initial_prime parserS.derivation_initial_belongs)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb)(*strict*)\n    prefer 2\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca)(*strict*)\n    apply(rule epdaS.some_position_has_details_at_0)\n    apply(rule epdaS.derivation_initial_is_derivation)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb)(*strict*)\n   prefer 2\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n   apply(rule parserS.some_position_has_details_at_0)\n   apply(rule parserS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__LR__relation_TSstructure_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb BOX)(*strict*)\n  apply(rule F_PARSER_TO_EDPDA__SpecInput1_implies_never_fixed)\n   apply(rename_tac G1 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb BOX)(*strict*)\n   apply(force)\n  apply(rename_tac G1 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb BOX)(*strict*)\n  apply(rule parserS.derivation_append_preserves_derivation_initial)\n    apply(rename_tac G1 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb BOX)(*strict*)\n    apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n   apply(rename_tac G1 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb BOX)(*strict*)\n   apply(force)\n  apply(rename_tac G1 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb BOX)(*strict*)\n  apply(rule parserS.derivation_append_preserves_derivation)\n    apply(rename_tac G1 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb BOX)(*strict*)\n    apply(rule parserS.derivation_initial_is_derivation)\n    apply(force)\n   apply(rename_tac G1 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb BOX)(*strict*)\n   apply(rule parserS.der2_is_derivation)\n   apply(force)\n  apply(rename_tac G1 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb BOX)(*strict*)\n  apply(simp add: derivation_append_fit_def)\n  apply(case_tac \"deri1 deri1n\")\n   apply(rename_tac G1 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb BOX)(*strict*)\n   apply(force)\n  apply(rename_tac G1 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb BOX a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac G1 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb BOX a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c c' i e v ca cb BOX option b)(*strict*)\n  apply(simp add: der2_def)\n  done\n\nlemma parserS_epdaS_P2A_StateSimLR_inst_relation_initial_simulation_preserves_unmarked_effect: \"\n  (\\<forall>G1 G2. F_PARSER_TO_EDPDA__LR__relation_TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> parserS_initial_configurations G1 \\<longrightarrow> (\\<forall>d2. F_PARSER_TO_EDPDA__LR__relation_initial_simulation G1 G2 c1 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. parserS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_PARSER_TO_EDPDA__LR__relation_initial_configuration G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der1 c1) deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_PARSER_TO_EDPDA__LR__relation_configuration F_PARSER_TO_EDPDA__LR__relation_initial_simulation F_PARSER_TO_EDPDA__LR__relation_step_simulation G1 G2 (derivation_append deri1 (der1 c1) deri1n) deri1n (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> left_total_on (F_PARSER_TO_EDPDA__LR__relation_effect G1 G2) (parserS_unmarked_effect G1 (derivation_append deri1 (der1 c1) deri1n)) (epdaS_unmarked_effect G2 (derivation_append deri2 d2 deri2n))))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(rule_tac\n      t=\"derivation_append deri1 (der1 c1) deri1n\"\n      and s=\"deri1\"\n      in ssubst)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(rule ext)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f x)(*strict*)\n   apply(simp add: derivation_append_def)\n   apply(clarsimp)\n   apply(simp add: der1_def)\n   apply(rule sym)\n   apply(rule parserS.none_position_after_max_dom)\n     apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f x)(*strict*)\n     apply(rule parserS.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f x)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f x)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(rule_tac\n      x=\"a\"\n      in bexI)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__LR__relation_effect_def)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__LR__relation_initial_simulation_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__LR__relation_initial_configuration_def)\n  apply(clarsimp)\n  apply(rule_tac\n      t=\"derivation_append deri2 (der1 (F_PARSER_TO_EDPDA__configuration G1 c1 (epda_box G2))) deri2n\"\n      and s=\"deri2\"\n      in ssubst)\n   apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f a)(*strict*)\n   apply(rule ext)\n   apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f a x)(*strict*)\n   apply(simp add: derivation_append_def)\n   apply(clarsimp)\n   apply(simp add: der1_def)\n   apply(rule sym)\n   apply(rule epdaS.none_position_after_max_dom)\n     apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f a x)(*strict*)\n     apply(rule epdaS.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f a x)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f a x)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri1 0 = Some (pair None c)\")\n   apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f a)(*strict*)\n   prefer 2\n   apply(rule parserS.some_position_has_details_at_0)\n   apply(rule parserS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri2 0 = Some (pair None c)\")\n   apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f a)(*strict*)\n   prefer 2\n   apply(rule epdaS.some_position_has_details_at_0)\n   apply(rule epdaS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f a c ca)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(simp add: parserS_unmarked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n  apply(rule_tac\n      t=\"parser_fixed_input_length_recN deri1 i\"\n      and s=\"0\"\n      in ssubst)\n   apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__LR__relation_TSstructure_def)\n   apply(clarsimp)\n   apply(rename_tac G1 c1 n deri1 deri1n deri2 deri2n f c c' i e v BOX)(*strict*)\n   apply(rule F_PARSER_TO_EDPDA__SpecInput1_implies_never_fixed)\n    apply(rename_tac G1 c1 n deri1 deri1n deri2 deri2n f c c' i e v BOX)(*strict*)\n    apply(force)\n   apply(rename_tac G1 c1 n deri1 deri1n deri2 deri2n f c c' i e v BOX)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n  apply(clarsimp)\n  apply(simp add: epdaS_unmarked_effect_def)\n  apply(rule_tac\n      x=\"F_PARSER_TO_EDPDA__configuration G1 c' (epda_box G2)\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n   prefer 2\n   apply(simp add: F_PARSER_TO_EDPDA__configuration_def)\n   apply(subgoal_tac \"c' \\<in> parserS_configurations G1\")\n    apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n    apply(subgoal_tac \"c \\<in> parserS_configurations G1\")\n     apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n     apply(simp add: parserS_configurations_def)\n     apply(clarsimp)\n     apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f i e v l la w)(*strict*)\n     apply(rule_tac\n      t=\"butlast_if_match (w @ [parser_bottom G1]) (parser_bottom G1)\"\n      and s=\"w\"\n      in ssubst)\n      apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f i e v l la w)(*strict*)\n      apply (metis butlast_if_match_direct)\n     apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f i e v l la w)(*strict*)\n     apply(rule_tac\n      t=\"v @ w @ [parser_bottom G1]\"\n      and s=\"(v @ w) @ [parser_bottom G1]\"\n      in ssubst)\n      apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f i e v l la w)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f i e v l la w)(*strict*)\n     apply (metis butlast_if_match_direct)\n    apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n    apply(simp add: parserS_initial_configurations_def)\n   apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n   apply(rule parserS.belongs_configurations)\n    apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n    apply(rule parserS.derivation_initial_belongs)\n     apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n     apply(simp add: F_PARSER_TO_EDPDA__LR__relation_TSstructure_def F_PARSER_TO_EDPDA__SpecInput1_def)\n    apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n  apply(subgoal_tac \"n=0\")\n   apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n   apply(subgoal_tac \"f i \\<le> f deri1n\")\n    apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n    prefer 2\n    apply(rule_tac\n      f=\"f\"\n      in parserS_epdaS_P2A_StateSimLR.mono_all)\n        apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n        apply(force)\n       apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n       apply(rule parserS.derivation_append_preserves_derivation_initial)\n         apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n         apply(simp add: F_PARSER_TO_EDPDA__LR__relation_TSstructure_def F_PARSER_TO_EDPDA__SpecInput1_def)\n        apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n        apply(force)\n       apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n       apply(rule parserS.derivation_append_preserves_derivation)\n         apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n         apply(rule parserS.derivation_initial_is_derivation)\n         apply(force)\n        apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n        apply(rule parserS.der1_is_derivation)\n       apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n       apply(simp add: derivation_append_fit_def)\n       apply(case_tac \"deri1 deri1n\")\n        apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n        apply(force)\n       apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v a)(*strict*)\n       apply(clarsimp)\n       apply(case_tac a)\n       apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v a option b)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v option b)(*strict*)\n       apply(simp add: der1_def)\n      apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n      apply(simp add: derivation_append_def)\n      apply(simp add: maximum_of_domain_def)\n     apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n     apply(rule_tac\n      d=\"deri1\"\n      in parserS.allPreMaxDomSome_prime)\n       apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n       apply(rule parserS.derivation_initial_is_derivation)\n       apply(force)\n      apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n   apply(rule_tac\n      x=\"f i\"\n      in exI)\n   apply(simp add: parserS_epdaS_P2A_StateSimLR.simulating_derivation_def)\n   apply(simp add: parserS_epdaS_P2A_StateSimLR.simulating_derivation_DEF_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 deri1 deri1n deri2 f c c' i e v)(*strict*)\n   apply(erule_tac\n      x=\"i\"\n      in allE)\n   apply(erule impE)\n    apply(rename_tac G1 G2 c1 deri1 deri1n deri2 f c c' i e v)(*strict*)\n    apply (metis not_None_eq parserS.allPreMaxDomSome_prime parserS.derivation_initial_is_derivation)\n   apply(rename_tac G1 G2 c1 deri1 deri1n deri2 f c c' i e v)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 deri1 deri1n deri2 f c c' i e v y)(*strict*)\n   apply(subgoal_tac \"f i \\<le> f deri1n\")\n    apply(rename_tac G1 G2 c1 deri1 deri1n deri2 f c c' i e v y)(*strict*)\n    apply(simp add: derivation_append_def)\n    apply(case_tac y)\n    apply(rename_tac G1 G2 c1 deri1 deri1n deri2 f c c' i e v y option b)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 deri1 deri1n deri2 f c c' i e v option b)(*strict*)\n    apply(subgoal_tac \"i\\<le> deri1n\")\n     apply(rename_tac G1 G2 c1 deri1 deri1n deri2 f c c' i e v option b)(*strict*)\n     apply(simp add: derivation_append_def)\n     apply(simp add: F_PARSER_TO_EDPDA__LR__relation_configuration_def)\n     apply(clarsimp)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac G1 G2 c1 deri1 deri1n deri2 f c c' i e v option b)(*strict*)\n    apply(rule parserS.allPreMaxDomSome_prime)\n      apply(rename_tac G1 G2 c1 deri1 deri1n deri2 f c c' i e v option b)(*strict*)\n      apply(rule parserS.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac G1 G2 c1 deri1 deri1n deri2 f c c' i e v option b)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 deri1 deri1n deri2 f c c' i e v option b)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 deri1 deri1n deri2 f c c' i e v y)(*strict*)\n   apply(simp add: parserS_epdaS_P2A_StateSimLR.simulating_derivation_S_def)\n  apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n  apply(rule_tac\n      d=\"der1 (F_PARSER_TO_EDPDA__configuration G1 c1 (epda_box G2))\"\n      in epdaS.maximum_of_domainUnique)\n    apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n    apply(rule epdaS.der1_is_derivation)\n   apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G1 G2 c1 n deri1 deri1n deri2 deri2n f c c' i e v)(*strict*)\n  apply(simp add: maximum_of_domain_def der1_def)\n  done\n\nlemma parserS_epdaS_P2A_StateSimLR_inst_ATS_Simulation_Configuration_Weak_Unmarked_Effect: \"\n  ATS_Simulation_Configuration_Weak_Unmarked_Effect_axioms parserS_initial_configurations parser_step_labels parserS_step_relation parserS_unmarked_effect epdaS_initial_configurations epdaS_step_relation epdaS_unmarked_effect F_PARSER_TO_EDPDA__LR__relation_configuration F_PARSER_TO_EDPDA__LR__relation_initial_configuration F_PARSER_TO_EDPDA__LR__relation_effect F_PARSER_TO_EDPDA__LR__relation_TSstructure F_PARSER_TO_EDPDA__LR__relation_initial_simulation F_PARSER_TO_EDPDA__LR__relation_step_simulation\"\n  apply(simp add: ATS_Simulation_Configuration_Weak_Unmarked_Effect_axioms_def)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(rule parserS_epdaS_P2A_StateSimLR.relation_step_simulation_preservation_PROVE2)\n    apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n    prefer 2\n    apply(rename_tac G1 G2 d1' d2')(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(thin_tac \"parserS_epdaS_P2A_StateSimLR.relation_step_simulation_preservation G1 G2 d1' d2'\")\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(metis parserS_epdaS_P2A_StateSimLR_inst_relation_step_simulation_preserves_unmarked_effect)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 d1' d2')(*strict*)\n  apply(rule parserS_epdaS_P2A_StateSimLR.relation_initial_simulation_preservation_PROVE2)\n   apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   prefer 2\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(thin_tac \"parserS_epdaS_P2A_StateSimLR.relation_initial_simulation_preservation G1 G2 d1' d2'\")\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(metis parserS_epdaS_P2A_StateSimLR_inst_relation_initial_simulation_preserves_unmarked_effect)\n  done\n\nlemma parserS_epdaS_P2A_StateSimLR_inst_relation_step_simulation_preserves_marking_condition: \"\n  (\\<forall>G1 G2. F_PARSER_TO_EDPDA__LR__relation_TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_PARSER_TO_EDPDA__LR__relation_configuration G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> parser_step_labels G1 \\<longrightarrow> (\\<forall>c1'. parserS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<forall>d2. F_PARSER_TO_EDPDA__LR__relation_step_simulation G1 G2 c1 e1 c1' c2 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. parserS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_PARSER_TO_EDPDA__LR__relation_initial_configuration G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der2 c1 e1 c1') deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> parserS_marking_condition G1 (derivation_append deri1 (der2 c1 e1 c1') deri1n) \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_PARSER_TO_EDPDA__LR__relation_configuration F_PARSER_TO_EDPDA__LR__relation_initial_simulation F_PARSER_TO_EDPDA__LR__relation_step_simulation G1 G2 (derivation_append deri1 (der2 c1 e1 c1') deri1n) (Suc deri1n) (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> epdaS_marking_condition G2 (derivation_append deri2 d2 deri2n)))))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__LR__relation_TSstructure_def F_PARSER_TO_EDPDA__LR__relation_configuration_def F_PARSER_TO_EDPDA__LR__relation_step_simulation_def F_PARSER_TO_EDPDA__LR__relation_initial_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX)(*strict*)\n  apply(simp add: parserS_marking_condition_def epdaS_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c i e ca)(*strict*)\n  apply(rule_tac\n      x=\"f i\"\n      in exI)\n  apply(simp add: parserS_epdaS_P2A_StateSimLR.simulating_derivation_def)\n  apply(simp add: parserS_epdaS_P2A_StateSimLR.simulating_derivation_DEF_def)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"i\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c i e ca)(*strict*)\n   apply(case_tac \"i\\<le>Suc deri1n\")\n    apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c i e ca)(*strict*)\n    apply(force)\n   apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c i e ca)(*strict*)\n   apply(clarsimp)\n   apply(simp add: derivation_append_def der2_def)\n   apply(case_tac \"i-deri1n\")\n    apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c i e ca)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c i e ca nat)(*strict*)\n   apply(clarsimp)\n   apply(case_tac nat)\n    apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c i e ca nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c i ca)(*strict*)\n    apply(force)\n   apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c i e ca nat nata)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c i e ca)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c i e ca y)(*strict*)\n  apply(case_tac y)\n  apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c i e ca y option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c i e ca option b)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__LR__relation_configuration_def)\n  apply(clarsimp)\n  apply(simp add: get_configuration_def)\n  apply(simp add: F_PARSER_TO_EDPDA__configuration_def)\n  apply(simp add: parserS_marking_configurations_def epdaS_marking_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c i e ca option fa w)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c i e ca option fa w)(*strict*)\n   apply (metis append_Nil butlast_if_match_direct)\n  apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c i e ca option fa w)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c i e ca option fa w)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c i e ca option fa w)(*strict*)\n  apply(simp add: epdaS_configurations_def parserS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e option fa w l wa)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e option fa w l wa)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e option fa w l wa)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e option fa w l wa)(*strict*)\n   apply(rule_tac\n      t=\"butlast_if_match [parser_bottom G1] (parser_bottom G1)\"\n      and s=\"[]\"\n      in ssubst)\n    apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e option fa w l wa)(*strict*)\n    apply (metis append_Nil butlast_if_match_direct)\n   apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e option fa w l wa)(*strict*)\n   apply(force)\n  apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e option fa w l wa)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e option fa w l wa)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e option fa w l wa)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e option fa w l wa x)(*strict*)\n  apply (metis set_mp_prime)\n  done\n\nlemma parserS_epdaS_P2A_StateSimLR_inst_relation_initial_simulation_preserves_marking_condition: \"\n  (\\<forall>G1 G2. F_PARSER_TO_EDPDA__LR__relation_TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> parserS_initial_configurations G1 \\<longrightarrow> (\\<forall>d2. F_PARSER_TO_EDPDA__LR__relation_initial_simulation G1 G2 c1 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. parserS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow>F_PARSER_TO_EDPDA__LR__relation_initial_configuration G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow>derivation_append_fit deri1 (der1 c1) deri1n \\<longrightarrow>derivation_append_fit deri2 d2 deri2n \\<longrightarrow>parserS_marking_condition G1 (derivation_append deri1 (der1 c1) deri1n) \\<longrightarrow>Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_PARSER_TO_EDPDA__LR__relation_configuration F_PARSER_TO_EDPDA__LR__relation_initial_simulation F_PARSER_TO_EDPDA__LR__relation_step_simulation G1 G2 (derivation_append deri1 (der1 c1) deri1n) deri1n (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow>epdaS_marking_condition G2 (derivation_append deri2 d2 deri2n)))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__LR__relation_TSstructure_def F_PARSER_TO_EDPDA__LR__relation_configuration_def F_PARSER_TO_EDPDA__LR__relation_step_simulation_def F_PARSER_TO_EDPDA__LR__relation_initial_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX)(*strict*)\n  apply(simp add: parserS_marking_condition_def epdaS_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c i e ca)(*strict*)\n  apply(rule_tac\n      x=\"f i\"\n      in exI)\n  apply(simp add: parserS_epdaS_P2A_StateSimLR.simulating_derivation_def)\n  apply(simp add: parserS_epdaS_P2A_StateSimLR.simulating_derivation_DEF_def)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"i\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c i e ca)(*strict*)\n   apply(subgoal_tac \"derivation_append deri1 (der1 c1) deri1n = deri1\")\n    apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c i e ca)(*strict*)\n    prefer 2\n    apply(rule ext)\n    apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c i e ca x)(*strict*)\n    apply(simp add: derivation_append_def)\n    apply(clarsimp)\n    apply(simp add: der1_def)\n    apply(rule sym)\n    apply(rule parserS.none_position_after_max_dom)\n      apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c i e ca x)(*strict*)\n      apply(rule parserS.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c i e ca x)(*strict*)\n     apply(force)\n    apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c i e ca x)(*strict*)\n    apply(force)\n   apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c i e ca)(*strict*)\n   apply(clarsimp)\n   apply (metis not_None_eq parserS.allPreMaxDomSome_prime parserS.derivation_initial_is_derivation)\n  apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c i e ca)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c i e ca y)(*strict*)\n  apply(case_tac y)\n  apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c i e ca y option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c i e ca option b)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__LR__relation_configuration_def)\n  apply(clarsimp)\n  apply(simp add: get_configuration_def)\n  apply(simp add: F_PARSER_TO_EDPDA__configuration_def)\n  apply(simp add: parserS_marking_configurations_def epdaS_marking_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c i e ca option fa w)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c i e ca option fa w)(*strict*)\n   apply (metis append_Nil butlast_if_match_direct)\n  apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c i e ca option fa w)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c i e ca option fa w)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c i e ca option fa w)(*strict*)\n  apply(simp add: epdaS_configurations_def parserS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX i e option fa w l wa)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX i e option fa w l wa)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX i e option fa w l wa)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX i e option fa w l wa)(*strict*)\n   apply(rule_tac\n      t=\"butlast_if_match [parser_bottom G1] (parser_bottom G1)\"\n      and s=\"[]\"\n      in ssubst)\n    apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX i e option fa w l wa)(*strict*)\n    apply (metis append_Nil butlast_if_match_direct)\n   apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX i e option fa w l wa)(*strict*)\n   apply(force)\n  apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX i e option fa w l wa)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX i e option fa w l wa)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX i e option fa w l wa)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX i e option fa w l wa x)(*strict*)\n  apply (metis set_mp_prime)\n  done\n\nlemma parserS_epdaS_P2A_StateSimLR_inst_ATS_Simulation_Configuration_WeakLR_Marking_Condition: \"\n  ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms parserS_initial_configurations parser_step_labels parserS_step_relation parserS_marking_condition epdaS_initial_configurations epdaS_step_relation epdaS_marking_condition F_PARSER_TO_EDPDA__LR__relation_configuration F_PARSER_TO_EDPDA__LR__relation_initial_configuration F_PARSER_TO_EDPDA__LR__relation_TSstructure F_PARSER_TO_EDPDA__LR__relation_initial_simulation F_PARSER_TO_EDPDA__LR__relation_step_simulation\"\n  apply(simp add: ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms_def)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(rule parserS_epdaS_P2A_StateSimLR.relation_step_simulation_preservation_PROVE2)\n    apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n    prefer 2\n    apply(rename_tac G1 G2 d1' d2')(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(thin_tac \"parserS_epdaS_P2A_StateSimLR.relation_step_simulation_preservation G1 G2 d1' d2'\")\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(metis parserS_epdaS_P2A_StateSimLR_inst_relation_step_simulation_preserves_marking_condition)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 d1' d2')(*strict*)\n  apply(rule parserS_epdaS_P2A_StateSimLR.relation_initial_simulation_preservation_PROVE2)\n   apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   prefer 2\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(thin_tac \"parserS_epdaS_P2A_StateSimLR.relation_initial_simulation_preservation G1 G2 d1' d2'\")\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(metis parserS_epdaS_P2A_StateSimLR_inst_relation_initial_simulation_preserves_marking_condition)\n  done\n\nlemma parserS_epdaS_P2A_StateSimLR_inst_relation_step_simulation_preserves_marked_effect: \"\n  (\\<forall>G1 G2. F_PARSER_TO_EDPDA__LR__relation_TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_PARSER_TO_EDPDA__LR__relation_configuration G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> parser_step_labels G1 \\<longrightarrow> (\\<forall>c1'. parserS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<forall>d2. F_PARSER_TO_EDPDA__LR__relation_step_simulation G1 G2 c1 e1 c1' c2 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. parserS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_PARSER_TO_EDPDA__LR__relation_initial_configuration G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der2 c1 e1 c1') deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_PARSER_TO_EDPDA__LR__relation_configuration F_PARSER_TO_EDPDA__LR__relation_initial_simulation F_PARSER_TO_EDPDA__LR__relation_step_simulation G1 G2 (derivation_append deri1 (der2 c1 e1 c1') deri1n) (Suc deri1n) (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> left_total_on (F_PARSER_TO_EDPDA__LR__relation_effect G1 G2) (parserS_marked_effect G1 (derivation_append deri1 (der2 c1 e1 c1') deri1n)) (epdaS_marked_effect G2 (derivation_append deri2 d2 deri2n))))))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__LR__relation_TSstructure_def F_PARSER_TO_EDPDA__LR__relation_configuration_def F_PARSER_TO_EDPDA__LR__relation_step_simulation_def F_PARSER_TO_EDPDA__LR__relation_initial_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX)(*strict*)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX a)(*strict*)\n  apply(rule_tac\n      x=\"a\"\n      in bexI)\n   apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX a)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__LR__relation_effect_def F_PARSER_TO_EDPDA__LR__relation_TSstructure_def)\n   apply(force)\n  apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX a)(*strict*)\n  apply(simp add: parserS_marked_effect_def epdaS_marked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c)(*strict*)\n  apply(simp add: derivation_append_def)\n  apply(subgoal_tac \"\\<exists>c. deri2 0 = Some (pair None c)\")\n   apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c)(*strict*)\n   apply(subgoal_tac \"\\<exists>c. deri1 0 = Some (pair None c)\")\n    apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c ca)(*strict*)\n    apply(simp add: F_PARSER_TO_EDPDA__configuration_def get_configuration_def)\n    apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c)(*strict*)\n    apply(simp add: parserS_initial_configurations_def parserS_configurations_def)\n    apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX w)(*strict*)\n    apply (metis butlast_if_match_direct)\n   apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c)(*strict*)\n   apply(rule parserS.some_position_has_details_at_0)\n   apply(rule parserS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac G1 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX c)(*strict*)\n  apply(rule epdaS.some_position_has_details_at_0)\n  apply(rule epdaS.derivation_initial_is_derivation)\n  apply(force)\n  done\n\nlemma parserS_epdaS_P2A_StateSimLR_inst_relation_initial_simulation_preserves_marked_effect: \"\n  \\<forall>G1 G2. F_PARSER_TO_EDPDA__LR__relation_TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> parserS_initial_configurations G1 \\<longrightarrow> (\\<forall>d2. F_PARSER_TO_EDPDA__LR__relation_initial_simulation G1 G2 c1 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. parserS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_PARSER_TO_EDPDA__LR__relation_initial_configuration G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der1 c1) deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_PARSER_TO_EDPDA__LR__relation_configuration F_PARSER_TO_EDPDA__LR__relation_initial_simulation F_PARSER_TO_EDPDA__LR__relation_step_simulation G1 G2 (derivation_append deri1 (der1 c1) deri1n) deri1n (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> left_total_on (F_PARSER_TO_EDPDA__LR__relation_effect G1 G2) (parserS_marked_effect G1 (derivation_append deri1 (der1 c1) deri1n)) (epdaS_marked_effect G2 (derivation_append deri2 d2 deri2n)))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__LR__relation_TSstructure_def F_PARSER_TO_EDPDA__LR__relation_configuration_def F_PARSER_TO_EDPDA__LR__relation_step_simulation_def F_PARSER_TO_EDPDA__LR__relation_initial_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX)(*strict*)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX a)(*strict*)\n  apply(rule_tac\n      x=\"a\"\n      in bexI)\n   apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX a)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__LR__relation_effect_def F_PARSER_TO_EDPDA__LR__relation_TSstructure_def)\n   apply(force)\n  apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX a)(*strict*)\n  apply(simp add: parserS_marked_effect_def epdaS_marked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c)(*strict*)\n  apply(simp add: derivation_append_def)\n  apply(subgoal_tac \"\\<exists>c. deri2 0 = Some (pair None c)\")\n   apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c)(*strict*)\n   apply(subgoal_tac \"\\<exists>c. deri1 0 = Some (pair None c)\")\n    apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c ca)(*strict*)\n    apply(simp add: F_PARSER_TO_EDPDA__configuration_def get_configuration_def)\n    apply(clarsimp)\n    apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c)(*strict*)\n    apply(simp add: parserS_initial_configurations_def parserS_configurations_def)\n    apply(clarsimp)\n    apply(rename_tac G1 d2 n deri1 deri1n deri2 deri2n f BOX w wa)(*strict*)\n    apply (metis butlast_if_match_direct)\n   apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c)(*strict*)\n   apply(rule parserS.some_position_has_details_at_0)\n   apply(rule parserS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac G1 c1 d2 n deri1 deri1n deri2 deri2n f BOX c)(*strict*)\n  apply(rule epdaS.some_position_has_details_at_0)\n  apply(rule epdaS.derivation_initial_is_derivation)\n  apply(force)\n  done\n\nlemma parserS_epdaS_P2A_StateSimLR_inst_ATS_Simulation_Configuration_Weak_Marked_Effect: \"\n  ATS_Simulation_Configuration_Weak_Marked_Effect_axioms parserS_initial_configurations parser_step_labels parserS_step_relation parserS_marked_effect epdaS_initial_configurations epdaS_step_relation epdaS_marked_effect F_PARSER_TO_EDPDA__LR__relation_configuration F_PARSER_TO_EDPDA__LR__relation_initial_configuration F_PARSER_TO_EDPDA__LR__relation_effect F_PARSER_TO_EDPDA__LR__relation_TSstructure F_PARSER_TO_EDPDA__LR__relation_initial_simulation F_PARSER_TO_EDPDA__LR__relation_step_simulation\"\n  apply(simp add: ATS_Simulation_Configuration_Weak_Marked_Effect_axioms_def)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(rule parserS_epdaS_P2A_StateSimLR.relation_step_simulation_preservation_PROVE2)\n    apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n    prefer 2\n    apply(rename_tac G1 G2 d1' d2')(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(thin_tac \"parserS_epdaS_P2A_StateSimLR.relation_step_simulation_preservation G1 G2 d1' d2'\")\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(metis parserS_epdaS_P2A_StateSimLR_inst_relation_step_simulation_preserves_marked_effect)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 d1' d2')(*strict*)\n  apply(rule parserS_epdaS_P2A_StateSimLR.relation_initial_simulation_preservation_PROVE2)\n   apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   prefer 2\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(thin_tac \"parserS_epdaS_P2A_StateSimLR.relation_initial_simulation_preservation G1 G2 d1' d2'\")\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(metis parserS_epdaS_P2A_StateSimLR_inst_relation_initial_simulation_preserves_marked_effect)\n  done\n\ninterpretation \"parserS_epdaS_P2A_StateSimLR\" : ATS_Simulation_Configuration_WeakLR_FULL\n  (* TSstructure1 *)\n  \"valid_parser\"\n  (* configurations1 *)\n  \"parserS_configurations\"\n  (* initial_configurations1 *)\n  \"parserS_initial_configurations\"\n  (* step_labels1 *)\n  \"parser_step_labels\"\n  (* step_relation1 *)\n  \"parserS_step_relation\"\n  (* effects1 *)\n  \"parser_markers\"\n  (* marking_condition1 *)\n  \"parserS_marking_condition\"\n  (* marked_effect1 *)\n  \"parserS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"parserS_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_PARSER_TO_EDPDA__LR__relation_configuration\"\n  (* relation_initial_configuration *)\n  \"F_PARSER_TO_EDPDA__LR__relation_initial_configuration\"\n  (* relation_effect *)\n  \"F_PARSER_TO_EDPDA__LR__relation_effect\"\n  (* relation_TSstructure *)\n  \"F_PARSER_TO_EDPDA__LR__relation_TSstructure\"\n  (* relation_initial_simulation *)\n  \"F_PARSER_TO_EDPDA__LR__relation_initial_simulation\"\n  (* relation_step_simulation *)\n  \"F_PARSER_TO_EDPDA__LR__relation_step_simulation\"\n  apply(simp add: LOCALE_DEFS epda_interpretations parser_interpretations)\n  apply(simp add:\n      parserS_epdaS_P2A_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms parserS_epdaS_P2A_StateSimLR_inst_ATS_Simulation_Configuration_Weak_Unmarked_Effect parserS_epdaS_P2A_StateSimLR_inst_ATS_Simulation_Configuration_WeakLR_Marking_Condition parserS_epdaS_P2A_StateSimLR_inst_ATS_Simulation_Configuration_Weak_Marked_Effect )\n  done\n\ndefinition F_PARSER_TO_EDPDA__RL__relation_TSstructure :: \"\n  ('stack, 'event, 'stack) epda\n  \\<Rightarrow> ('stack, 'event, 'marker) parser\n  \\<Rightarrow> bool\"\n  where\n    \"F_PARSER_TO_EDPDA__RL__relation_TSstructure G1 G2 \\<equiv>\n  \\<exists>BOX.\n    F_PARSER_TO_EDPDA__SpecInput1 G2 BOX\n    \\<and> G1 = F_PARSER_TO_EDPDA G2 BOX\"\n\ndefinition F_PARSER_TO_EDPDA__RL__relation_configuration :: \"\n  ('stack, 'event, 'stack) epda\n  \\<Rightarrow> ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ('stack, 'event) parserS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_PARSER_TO_EDPDA__RL__relation_configuration G1 G2 c1 c2 \\<equiv>\n  F_PARSER_TO_EDPDA__RL__relation_TSstructure G1 G2\n  \\<and> c1 \\<in> epdaS.get_accessible_configurations G1\n  \\<and> F_PARSER_TO_EDPDA__configuration_rev G2 c1 = c2\"\n\ndefinition F_PARSER_TO_EDPDA__RL__relation_initial_configuration :: \"\n  ('stack, 'event, 'stack) epda\n  \\<Rightarrow> ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ('stack, 'event) parserS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_PARSER_TO_EDPDA__RL__relation_initial_configuration G1 G2 c1 c2 \\<equiv>\n  F_PARSER_TO_EDPDA__RL__relation_TSstructure G1 G2\n  \\<and> c1 \\<in> epdaS_initial_configurations G1\n  \\<and> F_PARSER_TO_EDPDA__configuration_rev G2 c1 = c2\"\n\ndefinition F_PARSER_TO_EDPDA__RL__relation_effect :: \"\n  ('stack, 'event, 'stack) epda\n  \\<Rightarrow> ('stack, 'event, 'marker) parser\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> bool\"\n  where\n    \"F_PARSER_TO_EDPDA__RL__relation_effect G1 G2 w1 w2 \\<equiv>\n  F_PARSER_TO_EDPDA__RL__relation_TSstructure G1 G2\n  \\<and> w1 = w2\"\n\ndefinition F_PARSER_TO_EDPDA__RL__relation_step_labels :: \"\n  ('stack, 'event, 'stack) epda\n  \\<Rightarrow> ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event, 'stack) epda_step_label\n  \\<Rightarrow> ('stack, 'event) parser_step_label\n  \\<Rightarrow> bool\"\n  where\n    \"F_PARSER_TO_EDPDA__RL__relation_step_labels G1 G2 e1 e2 \\<equiv>\n  F_PARSER_TO_EDPDA__RL__relation_TSstructure G1 G2\n  \\<and> e1 \\<in> epda_delta G1\n  \\<and> F_PARSER_TO_EDPDA__rules_rev e1 = e2\"\n\nlemma epdaS_parserS_P2A_StateSimRL_inst_AX_TSstructure_relation_TSstructure1_belongs: \"\n  (\\<forall>G1. Ex (F_PARSER_TO_EDPDA__RL__relation_TSstructure G1) \\<longrightarrow> valid_epda G1)\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__RL__relation_TSstructure_def)\n  apply(clarsimp)\n  apply(rename_tac G1 BOX)(*strict*)\n  apply (metis F_PARSER_TO_EDPDA_generates_epda)\n  done\n\nlemma epdaS_parserS_P2A_StateSimRL_inst_AX_TSstructure_relation_TSstructure2_belongs: \"\n  (\\<forall>G1 G2. F_PARSER_TO_EDPDA__RL__relation_TSstructure G1 G2 \\<longrightarrow> valid_parser G2)\"\n  apply(clarsimp)\n  apply(rename_tac G1 x)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__RL__relation_TSstructure_def)\n  apply(clarsimp)\n  apply(rename_tac G1 BOX)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n  done\n\ndefinition F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL :: \"\n  ('stack, 'event, 'stack) epda\n  \\<Rightarrow> ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> (('stack, 'event) parser_step_label, ('stack, 'event) parserS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL G1 G2 c1 d \\<equiv>\n  d = der1 (F_PARSER_TO_EDPDA__configuration_rev G2 c1)\"\n\ndefinition F_PARSER_TO_EDPDA__LR__relation_step_simulationRL :: \"\n  ('stack, 'event, 'stack) epda\n  \\<Rightarrow> ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ('stack, 'event, 'stack) epda_step_label\n  \\<Rightarrow> ('stack, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ('stack, 'event) parserS_conf\n  \\<Rightarrow> (('stack, 'event) parser_step_label, ('stack, 'event) parserS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_PARSER_TO_EDPDA__LR__relation_step_simulationRL G1 G2 c1 e1 c1' c2 d \\<equiv>\n  d = der2 (F_PARSER_TO_EDPDA__configuration_rev G2 c1) (F_PARSER_TO_EDPDA__rules_rev e1) (F_PARSER_TO_EDPDA__configuration_rev G2 c1')\"\n\nlemma epdaS_parserS_P2A_StateSimRL_inst_relation_initial_simulation: \"\n  (\\<forall>G1 G2. F_PARSER_TO_EDPDA__RL__relation_TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<exists>d2. parserS.derivation_initial G2 d2 \\<and> F_PARSER_TO_EDPDA__RL__relation_initial_configuration G1 G2 c1 (the (get_configuration (d2 0))) \\<and> F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL G1 G2 c1 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_PARSER_TO_EDPDA__RL__relation_configuration G1 G2 c1 (the (get_configuration (d2 n)))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__RL__relation_TSstructure_def F_PARSER_TO_EDPDA__RL__relation_initial_configuration_def F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL_def F_PARSER_TO_EDPDA__RL__relation_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 BOX)(*strict*)\n  apply(subgoal_tac \"the (get_configuration (der1 (F_PARSER_TO_EDPDA__configuration_rev G2 c1) 0)) \\<in> parserS_initial_configurations G2\")\n   apply(rename_tac G2 c1 BOX)(*strict*)\n   prefer 2\n   apply(simp add: get_configuration_def der1_def)\n   apply(simp add: epdaS_initial_configurations_def parserS_initial_configurations_def)\n   apply(clarsimp)\n   apply(rule conjI)\n    apply(rename_tac G2 c1 BOX)(*strict*)\n    apply(simp add: F_PARSER_TO_EDPDA__configuration_rev_def)\n    apply(simp add: F_PARSER_TO_EDPDA_def)\n   apply(rename_tac G2 c1 BOX)(*strict*)\n   apply(simp add: parserS_configurations_def epdaS_configurations_def)\n   apply(clarsimp)\n   apply(rename_tac G2 BOX i)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__configuration_rev_def)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n   apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def valid_parser_def)\n   apply(clarsimp)\n   apply(force)\n  apply(rename_tac G2 c1 BOX)(*strict*)\n  apply(rule context_conjI)\n   apply(rename_tac G2 c1 BOX)(*strict*)\n   apply(rule parserS.derivation_initialI)\n    apply(rename_tac G2 c1 BOX)(*strict*)\n    apply(rule parserS.der1_is_derivation)\n   apply(rename_tac G2 c1 BOX)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 BOX)(*strict*)\n   apply(simp add: der1_def get_configuration_def)\n  apply(rename_tac G2 c1 BOX)(*strict*)\n  apply(simp add: der1_def get_configuration_def)\n  apply(rule_tac\n      x=\"0\"\n      in exI)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 BOX)(*strict*)\n   apply(fold der1_def)\n   apply(rule der1_maximum_of_domain)\n  apply(rename_tac G2 c1 BOX)(*strict*)\n  apply(simp add: epdaS.get_accessible_configurations_def)\n  apply(rule_tac\n      x=\"der1 c1\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 BOX)(*strict*)\n   apply(rule epdaS.derivation_initialI)\n    apply(rename_tac G2 c1 BOX)(*strict*)\n    apply(rule epdaS.der1_is_derivation)\n   apply(rename_tac G2 c1 BOX)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 BOX c)(*strict*)\n   apply(simp add: der1_def get_configuration_def)\n  apply(rename_tac G2 c1 BOX)(*strict*)\n  apply(rule_tac\n      x=\"0\"\n      in exI)\n  apply(simp add: der1_def get_configuration_def)\n  done\n\nlemma F_PARSER_TO_EDPDA__rules_rev_preserves_rules: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G2 BOX\n  \\<Longrightarrow> e1 \\<in> epda_step_labels (F_PARSER_TO_EDPDA G2 BOX)\n  \\<Longrightarrow> F_PARSER_TO_EDPDA__rules_rev e1 \\<in> parser_rules G2\"\n  apply(simp add: epda_step_labels_def)\n  apply(simp add: F_PARSER_TO_EDPDA__rules_rev_def F_PARSER_TO_EDPDA_def F_PARSER_TO_EDPDA__rules_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(rule_tac\n      t=\"\\<lparr>rule_lpop = rev (edge_pop (F_PARSER_TO_EDPDA__rules x)) @ [edge_src (F_PARSER_TO_EDPDA__rules x)], rule_rpop = option_to_list (edge_event (F_PARSER_TO_EDPDA__rules x)), rule_lpush = rev (edge_push (F_PARSER_TO_EDPDA__rules x)) @ [edge_trg (F_PARSER_TO_EDPDA__rules x)], rule_rpush = []\\<rparr>\"\n      and s=\"x\"\n      in ssubst)\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"x\"\n      in ballE)\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(case_tac x)\n  apply(rename_tac x rule_lpopa rule_rpopa rule_lpusha rule_rpusha)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac rule_lpop rule_rpop rule_lpush)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__rules_rev_def F_PARSER_TO_EDPDA_def F_PARSER_TO_EDPDA__rules_def)\n  apply(simp add: option_to_list_def list_to_option_def)\n  apply(case_tac \"rule_rpop\")\n   apply(rename_tac rule_lpop rule_rpop rule_lpush)(*strict*)\n   apply(force)\n  apply(rename_tac rule_lpop rule_rpop rule_lpush a list)(*strict*)\n  apply(force)\n  done\n\nlemma F_PARSER_TO_EDPDA__configuration_rev_preserves_configurations: \"\n  c1 \\<in> epdaS_configurations (F_PARSER_TO_EDPDA G2 BOX)\n  \\<Longrightarrow> \\<exists>w. epda_box (F_PARSER_TO_EDPDA G2 BOX) \\<notin> set w \\<and> epdaS_conf_stack c1 = w @ [epda_box G]\n  \\<Longrightarrow> F_PARSER_TO_EDPDA__SpecInput1 G2 BOX\n  \\<Longrightarrow> F_PARSER_TO_EDPDA__configuration_rev G2 c1 \\<in> parserS_configurations G2\"\n  apply(simp add: parserS_configurations_def epdaS_configurations_def F_PARSER_TO_EDPDA__configuration_rev_def)\n  apply(clarsimp)\n  apply(rename_tac q w i)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n  apply(clarsimp)\n  apply(simp add: valid_parser_def)\n  apply(rule conjI)\n   apply(rename_tac q w i)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac q w i x)(*strict*)\n   apply(force)\n  apply(rename_tac q w i)(*strict*)\n  apply(force)\n  done\n\nlemma epdaS_parserS_P2A_StateSimRL_inst_relation_step_simulation: \"\n  (\\<forall>G1 G2. F_PARSER_TO_EDPDA__RL__relation_TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_PARSER_TO_EDPDA__RL__relation_configuration G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<exists>d2. parserS.derivation G2 d2 \\<and> parserS.belongs G2 d2 \\<and> the (get_configuration (d2 0)) = c2 \\<and> F_PARSER_TO_EDPDA__LR__relation_step_simulationRL G1 G2 c1 e1 c1' c2 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_PARSER_TO_EDPDA__RL__relation_configuration G1 G2 c1' (the (get_configuration (d2 n)))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__RL__relation_TSstructure_def F_PARSER_TO_EDPDA__RL__relation_initial_configuration_def F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL_def F_PARSER_TO_EDPDA__RL__relation_configuration_def F_PARSER_TO_EDPDA__LR__relation_step_simulationRL_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n  apply(rule context_conjI)\n   apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n   apply(rule parserS.der2_is_derivation)\n   apply(rule F_PARSER_TO_EDPDA_preserves_steps)\n      apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n      apply(force)\n     apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n     apply(force)\n    apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n    apply(rule_tac\n      t=\"F_PARSER_TO_EDPDA__rules (F_PARSER_TO_EDPDA__rules_rev e1)\"\n      and s=\"e1\"\n      in ssubst)\n     apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n     apply (metis F_PARSER_TO_EDPDA__rules_F_PARSER_TO_EDPDA__rules_rev epda_step_labels_def)\n    apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n    apply(force)\n   apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n   apply(rule F_PARSER_TO_EDPDA__rules_rev_preserves_rules)\n    apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n    apply(force)\n   apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n   apply(force)\n  apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n  apply(rule context_conjI)\n   apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n   apply(rule parserS.derivation_belongs)\n      apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n      apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n     apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n     apply(simp add: der2_def)\n    apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n    apply(rule_tac\n      BOX=\"BOX\"\n      in F_PARSER_TO_EDPDA__configuration_rev_preserves_configurations)\n      apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n      apply (metis (full_types) F_PARSER_TO_EDPDA_generates_epda epdaS.get_accessible_configurations_are_configurations subsetD)\n     apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n     apply(simp add: epdaS.get_accessible_configurations_def)\n     apply(clarsimp)\n     apply(rename_tac G2 c1 e1 c1' BOX d i)(*strict*)\n     apply(case_tac \"d i\")\n      apply(rename_tac G2 c1 e1 c1' BOX d i)(*strict*)\n      apply(simp add: get_configuration_def)\n     apply(rename_tac G2 c1 e1 c1' BOX d i a)(*strict*)\n     apply(simp add: get_configuration_def)\n     apply(case_tac a)\n     apply(rename_tac G2 c1 e1 c1' BOX d i a option b)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G2 c1 e1 c1' BOX d i option)(*strict*)\n     apply(rule epda_no_use_epda_box_implies_stack_content)\n        apply(rename_tac G2 c1 e1 c1' BOX d i option)(*strict*)\n        apply (metis F_PARSER_TO_EDPDA_generates_epda)\n       apply(rename_tac G2 c1 e1 c1' BOX d i option)(*strict*)\n       apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n       apply(simp add: F_PARSER_TO_EDPDA_def)\n       apply(clarsimp)\n       apply(rename_tac G2 c1 e1 c1' BOX d i option r)(*strict*)\n       apply(simp add: F_PARSER_TO_EDPDA__rules_def)\n       apply(erule_tac\n      x=\"r\"\n      in ballE)\n        apply(rename_tac G2 c1 e1 c1' BOX d i option r)(*strict*)\n        prefer 2\n        apply(force)\n       apply(rename_tac G2 c1 e1 c1' BOX d i option r)(*strict*)\n       apply(clarsimp)\n       apply(subgoal_tac \"valid_parser_step_label G2 r\")\n        apply(rename_tac G2 c1 e1 c1' BOX d i option r)(*strict*)\n        prefer 2\n        apply(simp add: valid_parser_def)\n       apply(rename_tac G2 c1 e1 c1' BOX d i option r)(*strict*)\n       apply(simp add: valid_parser_step_label_def)\n       apply(clarsimp)\n       apply(rename_tac G2 c1 e1 c1' BOX d i option r k w)(*strict*)\n       apply(rule conjI)\n        apply(rename_tac G2 c1 e1 c1' BOX d i option r k w)(*strict*)\n        apply (metis in_set_butlastD insert_absorb insert_subset)\n       apply(rename_tac G2 c1 e1 c1' BOX d i option r k w)(*strict*)\n       apply (metis in_set_butlastD insert_absorb insert_subset)\n      apply(rename_tac G2 c1 e1 c1' BOX d i option)(*strict*)\n      apply(force)\n     apply(rename_tac G2 c1 e1 c1' BOX d i option)(*strict*)\n     apply(force)\n    apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n    apply(force)\n   apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n   apply(force)\n  apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n   apply(simp add: der2_def get_configuration_def)\n  apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n  apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n   apply(rule der2_maximum_of_domain)\n  apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n   apply(simp add: epdaS.get_accessible_configurations_def)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 e1 c1' BOX d i)(*strict*)\n   apply(case_tac \"d i\")\n    apply(rename_tac G2 c1 e1 c1' BOX d i)(*strict*)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac G2 c1 e1 c1' BOX d i a)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(case_tac a)\n   apply(rename_tac G2 c1 e1 c1' BOX d i a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 e1 c1' BOX d i option)(*strict*)\n   apply(rule_tac\n      x=\"derivation_append d (der2 c1 e1 c1') i\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac G2 c1 e1 c1' BOX d i option)(*strict*)\n    apply(rule epdaS.derivation_append_preserves_derivation_initial)\n      apply(rename_tac G2 c1 e1 c1' BOX d i option)(*strict*)\n      apply (metis F_PARSER_TO_EDPDA_generates_epda)\n     apply(rename_tac G2 c1 e1 c1' BOX d i option)(*strict*)\n     apply(force)\n    apply(rename_tac G2 c1 e1 c1' BOX d i option)(*strict*)\n    apply(rule epdaS.derivation_append_preserves_derivation)\n      apply(rename_tac G2 c1 e1 c1' BOX d i option)(*strict*)\n      apply (metis epdaS.derivation_initial_is_derivation)\n     apply(rename_tac G2 c1 e1 c1' BOX d i option)(*strict*)\n     apply(rule epdaS.der2_is_derivation)\n     apply(force)\n    apply(rename_tac G2 c1 e1 c1' BOX d i option)(*strict*)\n    apply(clarsimp)\n    apply(simp add: der2_def)\n   apply(rename_tac G2 c1 e1 c1' BOX d i option)(*strict*)\n   apply(rule_tac\n      x=\"Suc i\"\n      in exI)\n   apply(simp add: derivation_append_def der2_def)\n  apply(rename_tac G2 c1 e1 c1' BOX)(*strict*)\n  apply(simp add: der2_def)\n  apply(simp add: get_configuration_def)\n  done\n\nlemma epdaS_parserS_P2A_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axioms: \"\n  ATS_Simulation_Configuration_Weak_axioms valid_epda epdaS_initial_configurations epda_step_labels epdaS_step_relation valid_parser parserS_configurations parserS_initial_configurations parser_step_labels parserS_step_relation F_PARSER_TO_EDPDA__RL__relation_configuration F_PARSER_TO_EDPDA__RL__relation_initial_configuration F_PARSER_TO_EDPDA__RL__relation_TSstructure F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL F_PARSER_TO_EDPDA__LR__relation_step_simulationRL\"\n  apply(simp add: ATS_Simulation_Configuration_Weak_axioms_def)\n  apply(simp add: epdaS_parserS_P2A_StateSimRL_inst_relation_initial_simulation epdaS_parserS_P2A_StateSimRL_inst_relation_step_simulation epdaS_parserS_P2A_StateSimRL_inst_AX_TSstructure_relation_TSstructure1_belongs epdaS_parserS_P2A_StateSimRL_inst_AX_TSstructure_relation_TSstructure2_belongs )\n  done\n\ninterpretation \"epdaS_parserS_P2A_StateSimRL\" : ATS_Simulation_Configuration_Weak\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* TSstructure1 *)\n  \"valid_parser\"\n  (* configurations1 *)\n  \"parserS_configurations\"\n  (* initial_configurations1 *)\n  \"parserS_initial_configurations\"\n  (* step_labels1 *)\n  \"parser_step_labels\"\n  (* step_relation1 *)\n  \"parserS_step_relation\"\n  (* effects1 *)\n  \"parser_markers\"\n  (* marking_condition1 *)\n  \"parserS_marking_condition\"\n  (* marked_effect1 *)\n  \"parserS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"parserS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_PARSER_TO_EDPDA__RL__relation_configuration\"\n  (* relation_initial_configuration *)\n  \"F_PARSER_TO_EDPDA__RL__relation_initial_configuration\"\n  (* relation_effect *)\n  \"F_PARSER_TO_EDPDA__RL__relation_effect\"\n  (* relation_TSstructure *)\n  \"F_PARSER_TO_EDPDA__RL__relation_TSstructure\"\n  (* relation_initial_simulation *)\n  \"F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL\"\n  (* relation_step_simulation *)\n  \"F_PARSER_TO_EDPDA__LR__relation_step_simulationRL\"\n  apply(simp add: LOCALE_DEFS epda_interpretations parser_interpretations)\n  apply(simp add: epdaS_parserS_P2A_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axioms)\n  done\n\nlemma epdaS_parserS_P2A_StateSimRL_inst_relation_step_simulation_preserves_unmarked_effect: \"\n  (\\<forall>G1 G2. F_PARSER_TO_EDPDA__RL__relation_TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_PARSER_TO_EDPDA__RL__relation_configuration G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<forall>d2. F_PARSER_TO_EDPDA__LR__relation_step_simulationRL G1 G2 c1 e1 c1' c2 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. parserS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_PARSER_TO_EDPDA__RL__relation_initial_configuration G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der2 c1 e1 c1') deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_PARSER_TO_EDPDA__RL__relation_configuration F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL F_PARSER_TO_EDPDA__LR__relation_step_simulationRL G1 G2 (derivation_append deri1 (der2 c1 e1 c1') deri1n) (Suc deri1n) (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> left_total_on (F_PARSER_TO_EDPDA__RL__relation_effect G1 G2) (epdaS_unmarked_effect G1 (derivation_append deri1 (der2 c1 e1 c1') deri1n)) (parserS_unmarked_effect G2 (derivation_append deri2 d2 deri2n))))))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__RL__relation_TSstructure_def F_PARSER_TO_EDPDA__RL__relation_initial_configuration_def F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL_def F_PARSER_TO_EDPDA__RL__relation_configuration_def F_PARSER_TO_EDPDA__LR__relation_step_simulationRL_def F_PARSER_TO_EDPDA__RL__relation_effect_def)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX)(*strict*)\n  apply(rule_tac\n      x=\"a\"\n      in bexI)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__RL__relation_TSstructure_def F_PARSER_TO_EDPDA__RL__relation_initial_configuration_def F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL_def F_PARSER_TO_EDPDA__RL__relation_configuration_def F_PARSER_TO_EDPDA__LR__relation_step_simulationRL_def F_PARSER_TO_EDPDA__RL__relation_effect_def)\n   apply(force)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri1 0 = Some (pair None c)\")\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX)(*strict*)\n   prefer 2\n   apply(rule epdaS.some_position_has_details_at_0)\n   apply(rule epdaS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri2 0 = Some (pair None c)\")\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX)(*strict*)\n   prefer 2\n   apply(rule parserS.some_position_has_details_at_0)\n   apply(rule parserS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c ca)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(simp add: epdaS_unmarked_effect_def parserS_unmarked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n  apply(simp add: epdaS_parserS_P2A_StateSimRL.simulating_derivation_def)\n  apply(simp add: epdaS_parserS_P2A_StateSimRL.simulating_derivation_DEF_def)\n  apply(clarsimp)\n  apply(rule_tac\n      x=\"F_PARSER_TO_EDPDA__configuration_rev G2 c\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n   apply(simp add: derivation_append_def)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n  apply(erule_tac\n      x=\"i\"\n      in allE)\n  apply(clarsimp)\n  apply(erule impE)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n   apply(rule_tac\n      d=\"derivation_append deri1 (der2 c1 e1 c1') deri1n\"\n      in epdaS.allPreMaxDomSome_prime)\n     apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n     apply(rule epdaS.derivation_append_preserves_derivation)\n       apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n       apply(rule epdaS.derivation_initial_is_derivation)\n       apply(force)\n      apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n      apply(simp add: epdaS.der2_is_derivation)\n     apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n     apply(simp add: derivation_append_fit_def)\n     apply(case_tac \"deri1 deri1n\")\n      apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n      apply(force)\n     apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e aa)(*strict*)\n     apply(clarsimp)\n     apply(case_tac aa)\n     apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e aa option b)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n     apply(simp add: der2_def)\n    apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n    apply(force)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n   apply(rule_tac\n      t=\"Suc deri1n\"\n      and s=\"deri1n + Suc 0\"\n      in ssubst)\n    apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n    apply(force)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n   apply (metis concat_has_max_dom der2_maximum_of_domain)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e y)(*strict*)\n  apply(case_tac y)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e y option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n  apply(rule_tac\n      x=\"b\"\n      in exI)\n  apply(rule_tac\n      x=\"f i\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n   apply(force)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n  apply(rule_tac\n      t=\"parser_fixed_input_length_recN (derivation_append deri2 (der2 (F_PARSER_TO_EDPDA__configuration_rev G2 c1) (F_PARSER_TO_EDPDA__rules_rev e1) (F_PARSER_TO_EDPDA__configuration_rev G2 c1')) deri2n) (f i)\"\n      and s=\"0\"\n      in ssubst)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n   apply(rule F_PARSER_TO_EDPDA__SpecInput1_implies_never_fixed)\n    apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n    apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n   apply(rule parserS.derivation_append_preserves_derivation_initial)\n     apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n     apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n    apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n    apply(force)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n   apply(rule parserS.derivation_append_preserves_derivation)\n     apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n     apply(rule parserS.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n    apply(rule parserS.der2_is_derivation)\n    apply(rule F_PARSER_TO_EDPDA_preserves_steps)\n       apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n       apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n       apply(force)\n      apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n      apply(force)\n     apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n     apply(rule_tac\n      t=\"F_PARSER_TO_EDPDA__rules (F_PARSER_TO_EDPDA__rules_rev e1)\"\n      and s=\"e1\"\n      in ssubst)\n      apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n     apply(rule F_PARSER_TO_EDPDA__rules_F_PARSER_TO_EDPDA__rules_rev)\n      apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n      apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n     apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n     apply(simp add: epdaS_step_relation_def)\n    apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n    apply(simp add: epda_step_labels_def)\n    apply(rule F_PARSER_TO_EDPDA__rules_rev_preserves_rules)\n     apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n     apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n     apply(force)\n    apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n    apply(simp add: epda_step_labels_def)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n   apply(simp add: derivation_append_fit_def)\n   apply(case_tac \"deri2 deri2n\")\n    apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b aa)(*strict*)\n   apply(clarsimp)\n   apply(case_tac aa)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b aa optiona ba)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b optiona ba)(*strict*)\n   apply(simp add: der2_def)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n      t=\"parserS_conf_scheduler b\"\n      and s=\"epdaS_conf_scheduler c'@[parser_bottom G2]\"\n      in ssubst)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__RL__relation_configuration_def)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def F_PARSER_TO_EDPDA__configuration_def)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__configuration_rev_def)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n  apply(rule_tac\n      t=\"parserS_conf_scheduler (F_PARSER_TO_EDPDA__configuration_rev G2 c)\"\n      and s=\"epdaS_conf_scheduler cb@[parser_bottom G2]\"\n      in ssubst)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n  apply(simp add: derivation_append_def)\n  apply(simp add: F_PARSER_TO_EDPDA__configuration_rev_def)\n  done\n\nlemma epdaS_parserS_P2A_StateSimRL_inst_relation_initial_simulation_preserves_unmarked_effect: \"\n  \\<forall>G1 G2. F_PARSER_TO_EDPDA__RL__relation_TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<forall>d2. F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL G1 G2 c1 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. parserS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_PARSER_TO_EDPDA__RL__relation_initial_configuration G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der1 c1) deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_PARSER_TO_EDPDA__RL__relation_configuration F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL F_PARSER_TO_EDPDA__LR__relation_step_simulationRL G1 G2 (derivation_append deri1 (der1 c1) deri1n) deri1n (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> left_total_on (F_PARSER_TO_EDPDA__RL__relation_effect G1 G2) (epdaS_unmarked_effect G1 (derivation_append deri1 (der1 c1) deri1n)) (parserS_unmarked_effect G2 (derivation_append deri2 d2 deri2n)))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__RL__relation_TSstructure_def F_PARSER_TO_EDPDA__RL__relation_initial_configuration_def F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL_def F_PARSER_TO_EDPDA__RL__relation_configuration_def F_PARSER_TO_EDPDA__LR__relation_step_simulationRL_def F_PARSER_TO_EDPDA__RL__relation_effect_def)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX)(*strict*)\n  apply(rule_tac\n      x=\"a\"\n      in bexI)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__RL__relation_TSstructure_def F_PARSER_TO_EDPDA__RL__relation_initial_configuration_def F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL_def F_PARSER_TO_EDPDA__RL__relation_configuration_def F_PARSER_TO_EDPDA__LR__relation_step_simulationRL_def F_PARSER_TO_EDPDA__RL__relation_effect_def)\n   apply(force)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri1 0 = Some (pair None c)\")\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX)(*strict*)\n   prefer 2\n   apply(rule epdaS.some_position_has_details_at_0)\n   apply(rule epdaS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri2 0 = Some (pair None c)\")\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX)(*strict*)\n   prefer 2\n   apply(rule parserS.some_position_has_details_at_0)\n   apply(rule parserS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c ca)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(simp add: epdaS_unmarked_effect_def parserS_unmarked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n  apply(simp add: epdaS_parserS_P2A_StateSimRL.simulating_derivation_def)\n  apply(simp add: epdaS_parserS_P2A_StateSimRL.simulating_derivation_DEF_def)\n  apply(clarsimp)\n  apply(rule_tac\n      x=\"F_PARSER_TO_EDPDA__configuration_rev G2 c\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n   apply(simp add: derivation_append_def)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n  apply(erule_tac\n      x=\"i\"\n      in allE)\n  apply(clarsimp)\n  apply(erule impE)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n   apply(rule_tac\n      d=\"derivation_append deri1 (der1 c1) deri1n\"\n      in epdaS.allPreMaxDomSome_prime)\n     apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n     apply(rule epdaS.derivation_append_preserves_derivation)\n       apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n       apply(rule epdaS.derivation_initial_is_derivation)\n       apply(force)\n      apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n      apply(simp add: epdaS.der1_is_derivation)\n     apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n     apply(simp add: derivation_append_fit_def)\n     apply(case_tac \"deri1 deri1n\")\n      apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n      apply(force)\n     apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e aa)(*strict*)\n     apply(clarsimp)\n     apply(case_tac aa)\n     apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e aa option b)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n     apply(simp add: der1_def)\n    apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n    apply(force)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n   apply(rule maximum_of_domain_derivation_append_der1)\n   apply(force)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e y)(*strict*)\n  apply(case_tac y)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e y option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n  apply(rule_tac\n      x=\"b\"\n      in exI)\n  apply(rule_tac\n      x=\"f i\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n   apply(force)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n  apply(rule_tac\n      t=\"parser_fixed_input_length_recN (derivation_append deri2 (der1 (F_PARSER_TO_EDPDA__configuration_rev G2 c1)) deri2n) (f i)\"\n      and s=\"0\"\n      in ssubst)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n   apply(rule F_PARSER_TO_EDPDA__SpecInput1_implies_never_fixed)\n    apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n    apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n   apply(rule parserS.derivation_append_preserves_derivation_initial)\n     apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n     apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n    apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n    apply(force)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n   apply(rule parserS.derivation_append_preserves_derivation)\n     apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n     apply(rule parserS.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n    apply(rule parserS.der1_is_derivation)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n   apply(simp add: derivation_append_fit_def)\n   apply(case_tac \"deri2 deri2n\")\n    apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b aa)(*strict*)\n   apply(clarsimp)\n   apply(case_tac aa)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b aa optiona ba)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b optiona ba)(*strict*)\n   apply(simp add: der1_def)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n      t=\"parserS_conf_scheduler b\"\n      and s=\"epdaS_conf_scheduler c'@[parser_bottom G2]\"\n      in ssubst)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__RL__relation_configuration_def)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def F_PARSER_TO_EDPDA__configuration_def)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__configuration_rev_def)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n  apply(rule_tac\n      t=\"parserS_conf_scheduler (F_PARSER_TO_EDPDA__configuration_rev G2 c)\"\n      and s=\"epdaS_conf_scheduler cb@[parser_bottom G2]\"\n      in ssubst)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f a BOX c cb c' i e option b)(*strict*)\n  apply(simp add: derivation_append_def)\n  apply(simp add: F_PARSER_TO_EDPDA__configuration_rev_def)\n  done\n\nlemma epdaS_parserS_P2A_StateSimRL_inst_ATS_Simulation_Configuration_Weak_Unmarked_Effect_axioms: \"\n  ATS_Simulation_Configuration_Weak_Unmarked_Effect_axioms epdaS_initial_configurations epda_step_labels epdaS_step_relation epdaS_unmarked_effect parserS_initial_configurations parserS_step_relation parserS_unmarked_effect F_PARSER_TO_EDPDA__RL__relation_configuration F_PARSER_TO_EDPDA__RL__relation_initial_configuration F_PARSER_TO_EDPDA__RL__relation_effect F_PARSER_TO_EDPDA__RL__relation_TSstructure F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL F_PARSER_TO_EDPDA__LR__relation_step_simulationRL\"\n  apply(simp add: ATS_Simulation_Configuration_Weak_Unmarked_Effect_axioms_def)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(rule epdaS_parserS_P2A_StateSimRL.relation_step_simulation_preservation_PROVE2)\n    apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n    prefer 2\n    apply(rename_tac G1 G2 d1' d2')(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(thin_tac \"epdaS_parserS_P2A_StateSimRL.relation_step_simulation_preservation G1 G2 d1' d2'\")\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(metis epdaS_parserS_P2A_StateSimRL_inst_relation_step_simulation_preserves_unmarked_effect)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 d1' d2')(*strict*)\n  apply(rule epdaS_parserS_P2A_StateSimRL.relation_initial_simulation_preservation_PROVE2)\n   apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   prefer 2\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(thin_tac \"epdaS_parserS_P2A_StateSimRL.relation_initial_simulation_preservation G1 G2 d1' d2'\")\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(metis epdaS_parserS_P2A_StateSimRL_inst_relation_initial_simulation_preserves_unmarked_effect)\n  done\n\nlemma F_PARSER_TO_EDPDA__SpecInput1_no_pop_of_box: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G2 BOX\n  \\<Longrightarrow> \\<forall>r \\<in> epda_delta (F_PARSER_TO_EDPDA G2 BOX) . epda_box (F_PARSER_TO_EDPDA G2 BOX) \\<notin> set (edge_pop r) \\<and> epda_box (F_PARSER_TO_EDPDA G2 BOX) \\<notin> set (edge_push r)\"\n  apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n  apply(clarsimp)\n  apply(rename_tac r)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__rules_def)\n  apply(subgoal_tac \"valid_parser_step_label G2 x\")\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(simp add: valid_parser_def)\n  apply(rename_tac x)(*strict*)\n  apply(erule_tac\n      x=\"x\"\n      in ballE)\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(clarsimp)\n  apply(simp add: valid_parser_step_label_def)\n  apply(clarsimp)\n  apply(rename_tac x k w)(*strict*)\n  apply (metis in_set_butlastD subsetD)\n  done\n\nlemma epdaS_parserS_P2A_StateSimRL_inst_relation_step_simulation_preserves_marking_condition: \"\n  (\\<forall>G1 G2. F_PARSER_TO_EDPDA__RL__relation_TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_PARSER_TO_EDPDA__RL__relation_configuration G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<forall>d2. F_PARSER_TO_EDPDA__LR__relation_step_simulationRL G1 G2 c1 e1 c1' c2 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. parserS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_PARSER_TO_EDPDA__RL__relation_initial_configuration G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der2 c1 e1 c1') deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> epdaS_marking_condition G1 (derivation_append deri1 (der2 c1 e1 c1') deri1n) \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_PARSER_TO_EDPDA__RL__relation_configuration F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL F_PARSER_TO_EDPDA__LR__relation_step_simulationRL G1 G2 (derivation_append deri1 (der2 c1 e1 c1') deri1n) (Suc deri1n) (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> parserS_marking_condition G2 (derivation_append deri2 d2 deri2n)))))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__RL__relation_TSstructure_def F_PARSER_TO_EDPDA__RL__relation_initial_configuration_def F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL_def F_PARSER_TO_EDPDA__RL__relation_configuration_def F_PARSER_TO_EDPDA__LR__relation_step_simulationRL_def F_PARSER_TO_EDPDA__RL__relation_effect_def)\n  apply(simp add: parserS_marking_condition_def epdaS_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri1 0 = Some (pair None c)\")\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c)(*strict*)\n   prefer 2\n   apply(rule epdaS.some_position_has_details_at_0)\n   apply(rule epdaS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri2 0 = Some (pair None c)\")\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c)(*strict*)\n   prefer 2\n   apply(rule parserS.some_position_has_details_at_0)\n   apply(rule parserS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n   apply(rule_tac\n      x=\"cb\"\n      in exI)\n   apply(simp add: derivation_append_def)\n   apply(simp add: parserS.derivation_initial_def)\n   apply(simp add: parserS_initial_configurations_def)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n  apply(simp add: epdaS_parserS_P2A_StateSimRL.simulating_derivation_def)\n  apply(simp add: epdaS_parserS_P2A_StateSimRL.simulating_derivation_DEF_def)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"i\"\n      in allE)\n  apply(clarsimp)\n  apply(rule_tac\n      x=\"f i\"\n      in exI)\n  apply(subgoal_tac \"i\\<le>Suc deri1n\")\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"derivation_append deri1 (der2 c1 e1 c1') deri1n\"\n      in epdaS.allPreMaxDomSome_prime)\n     apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n     apply(rule epdaS.derivation_append_preserves_derivation)\n       apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n       apply(rule epdaS.derivation_initial_is_derivation)\n       apply(force)\n      apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n      apply(simp add: epdaS.der2_is_derivation)\n     apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n     apply(simp add: derivation_append_fit_def)\n     apply(case_tac \"deri1 deri1n\")\n      apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n      apply(force)\n     apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca cb a)(*strict*)\n     apply(clarsimp)\n     apply(case_tac a)\n     apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca cb a option b)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca cb option b)(*strict*)\n     apply(simp add: der2_def)\n    apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n    apply(force)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n   apply(rule maximum_of_domain_derivation_append_der2)\n   apply(force)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n  apply(erule impE)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n   apply(force)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca cb y)(*strict*)\n  apply(case_tac y)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca cb y option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca cb option b)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__RL__relation_configuration_def)\n  apply(clarsimp)\n  apply(simp add: get_configuration_def F_PARSER_TO_EDPDA__configuration_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca option)(*strict*)\n  apply(simp add: epdaS_marking_configurations_def parserS_marking_configurations_def)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca option)(*strict*)\n   apply(rule_tac\n      x=\"epdaS_conf_state c\"\n      in bexI)\n    apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca option)(*strict*)\n    apply(simp add: F_PARSER_TO_EDPDA__configuration_rev_def)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca option)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca option)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca option)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA_def F_PARSER_TO_EDPDA__configuration_rev_def)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca option)(*strict*)\n  apply(rule_tac\n      G=\"F_PARSER_TO_EDPDA G2 BOX\"\n      in F_PARSER_TO_EDPDA__configuration_rev_preserves_configurations)\n    apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca option)(*strict*)\n    apply(force)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca option)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca option)(*strict*)\n  apply(simp add: epdaS.get_accessible_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca option d da ia ib)(*strict*)\n  apply(case_tac \"da ib\")\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca option d da ia ib)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca option d da ia ib a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca option d da ia ib a optiona b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca option d da ia ib optiona b)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca option d da ia ib optiona)(*strict*)\n  apply(rule_tac\n      d=\"da\"\n      in epda_no_use_epda_box_implies_stack_content)\n     apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca option d da ia ib optiona)(*strict*)\n     apply (metis epdaS_parserS_P2A_StateSimRL.AX_TSstructure_relation_TSstructure1_belongs)\n    apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca option d da ia ib optiona)(*strict*)\n    prefer 3\n    apply(force)\n   apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca option d da ia ib optiona)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G2 c1 e1 c1' n deri1 deri1n deri2 deri2n f BOX i e c ca option d da ia ib optiona)(*strict*)\n  apply(rule F_PARSER_TO_EDPDA__SpecInput1_no_pop_of_box)\n  apply(force)\n  done\n\nlemma epdaS_parserS_P2A_StateSimRL_inst_relation_initial_simulation_preserves_marking_condition: \"\n  (\\<forall>G1 G2. F_PARSER_TO_EDPDA__RL__relation_TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<forall>d2. F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL G1 G2 c1 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. parserS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow>F_PARSER_TO_EDPDA__RL__relation_initial_configuration G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow>derivation_append_fit deri1 (der1 c1) deri1n \\<longrightarrow>derivation_append_fit deri2 d2 deri2n \\<longrightarrow>epdaS_marking_condition G1 (derivation_append deri1 (der1 c1) deri1n) \\<longrightarrow>Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_PARSER_TO_EDPDA__RL__relation_configuration F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL F_PARSER_TO_EDPDA__LR__relation_step_simulationRL G1 G2 (derivation_append deri1 (der1 c1) deri1n) deri1n (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow>parserS_marking_condition G2 (derivation_append deri2 d2 deri2n)))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__RL__relation_TSstructure_def F_PARSER_TO_EDPDA__RL__relation_initial_configuration_def F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL_def F_PARSER_TO_EDPDA__RL__relation_configuration_def F_PARSER_TO_EDPDA__LR__relation_step_simulationRL_def F_PARSER_TO_EDPDA__RL__relation_effect_def)\n  apply(simp add: parserS_marking_condition_def epdaS_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri1 0 = Some (pair None c)\")\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c)(*strict*)\n   prefer 2\n   apply(rule epdaS.some_position_has_details_at_0)\n   apply(rule epdaS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri2 0 = Some (pair None c)\")\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c)(*strict*)\n   prefer 2\n   apply(rule parserS.some_position_has_details_at_0)\n   apply(rule parserS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n   apply(rule_tac\n      x=\"cb\"\n      in exI)\n   apply(simp add: derivation_append_def)\n   apply(simp add: parserS.derivation_initial_def)\n   apply(simp add: parserS_initial_configurations_def)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n  apply(simp add: epdaS_parserS_P2A_StateSimRL.simulating_derivation_def)\n  apply(simp add: epdaS_parserS_P2A_StateSimRL.simulating_derivation_DEF_def)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"i\"\n      in allE)\n  apply(clarsimp)\n  apply(rule_tac\n      x=\"f i\"\n      in exI)\n  apply(subgoal_tac \"i\\<le>deri1n\")\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"derivation_append deri1 (der1 c1) deri1n\"\n      in epdaS.allPreMaxDomSome_prime)\n     apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n     apply(rule epdaS.derivation_append_preserves_derivation)\n       apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n       apply(rule epdaS.derivation_initial_is_derivation)\n       apply(force)\n      apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n      apply(simp add: epdaS.der1_is_derivation)\n     apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n     apply(simp add: derivation_append_fit_def)\n     apply(case_tac \"deri1 deri1n\")\n      apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n      apply(force)\n     apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca cb a)(*strict*)\n     apply(clarsimp)\n     apply(case_tac a)\n     apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca cb a option b)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca cb option b)(*strict*)\n     apply(simp add: der1_def)\n    apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n    apply(force)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n   apply(rule maximum_of_domain_derivation_append_der1)\n   apply(force)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n  apply(erule impE)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n   apply(force)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca cb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca cb y)(*strict*)\n  apply(case_tac y)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca cb y option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca cb option b)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__RL__relation_configuration_def)\n  apply(clarsimp)\n  apply(simp add: get_configuration_def F_PARSER_TO_EDPDA__configuration_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca option)(*strict*)\n  apply(simp add: epdaS_marking_configurations_def parserS_marking_configurations_def)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca option)(*strict*)\n   apply(rule_tac\n      x=\"epdaS_conf_state c\"\n      in bexI)\n    apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca option)(*strict*)\n    apply(simp add: F_PARSER_TO_EDPDA__configuration_rev_def)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca option)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca option)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca option)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA_def F_PARSER_TO_EDPDA__configuration_rev_def)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca option)(*strict*)\n  apply(rule_tac\n      G=\"F_PARSER_TO_EDPDA G2 BOX\"\n      in F_PARSER_TO_EDPDA__configuration_rev_preserves_configurations)\n    apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca option)(*strict*)\n    apply(force)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca option)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca option)(*strict*)\n  apply(simp add: epdaS.get_accessible_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca option d ia)(*strict*)\n  apply(case_tac \"d ia\")\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca option d ia)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca option d ia a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca option d ia a optiona b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca option d ia optiona b)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca option d ia optiona)(*strict*)\n  apply(rule_tac\n      d=\"d\"\n      in epda_no_use_epda_box_implies_stack_content)\n     apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca option d ia optiona)(*strict*)\n     apply (metis epdaS_parserS_P2A_StateSimRL.AX_TSstructure_relation_TSstructure1_belongs)\n    apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca option d ia optiona)(*strict*)\n    prefer 3\n    apply(force)\n   apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca option d ia optiona)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G2 c1 n deri1 deri1n deri2 deri2n f BOX i e c ca option d ia optiona)(*strict*)\n  apply(rule F_PARSER_TO_EDPDA__SpecInput1_no_pop_of_box)\n  apply(force)\n  done\n\nlemma epdaS_parserS_P2A_StateSimRL_inst_ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms: \"\n  ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms epdaS_initial_configurations epda_step_labels epdaS_step_relation epdaS_marking_condition parserS_initial_configurations parserS_step_relation parserS_marking_condition F_PARSER_TO_EDPDA__RL__relation_configuration F_PARSER_TO_EDPDA__RL__relation_initial_configuration F_PARSER_TO_EDPDA__RL__relation_TSstructure F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL F_PARSER_TO_EDPDA__LR__relation_step_simulationRL\"\n  apply(simp add: ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms_def)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(rule epdaS_parserS_P2A_StateSimRL.relation_step_simulation_preservation_PROVE2)\n    apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n    prefer 2\n    apply(rename_tac G1 G2 d1' d2')(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(thin_tac \"epdaS_parserS_P2A_StateSimRL.relation_step_simulation_preservation G1 G2 d1' d2'\")\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(metis epdaS_parserS_P2A_StateSimRL_inst_relation_step_simulation_preserves_marking_condition)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 d1' d2')(*strict*)\n  apply(rule epdaS_parserS_P2A_StateSimRL.relation_initial_simulation_preservation_PROVE2)\n   apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   prefer 2\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(thin_tac \"epdaS_parserS_P2A_StateSimRL.relation_initial_simulation_preservation G1 G2 d1' d2'\")\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(metis epdaS_parserS_P2A_StateSimRL_inst_relation_initial_simulation_preserves_marking_condition)\n  done\n\nlemma epdaS_parserS_P2A_StateSimRL_inst_relation_step_simulation_preserves_marked_effect: \"\n  (\\<forall>G1 G2. F_PARSER_TO_EDPDA__RL__relation_TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_PARSER_TO_EDPDA__RL__relation_configuration G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<forall>d2. F_PARSER_TO_EDPDA__LR__relation_step_simulationRL G1 G2 c1 e1 c1' c2 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. parserS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_PARSER_TO_EDPDA__RL__relation_initial_configuration G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der2 c1 e1 c1') deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_PARSER_TO_EDPDA__RL__relation_configuration F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL F_PARSER_TO_EDPDA__LR__relation_step_simulationRL G1 G2 (derivation_append deri1 (der2 c1 e1 c1') deri1n) (Suc deri1n) (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> left_total_on (F_PARSER_TO_EDPDA__RL__relation_effect G1 G2) (epdaS_marked_effect G1 (derivation_append deri1 (der2 c1 e1 c1') deri1n)) (parserS_marked_effect G2 (derivation_append deri2 d2 deri2n))))))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(rule_tac\n      x=\"a\"\n      in bexI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__RL__relation_effect_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(simp add: parserS_marked_effect_def epdaS_marked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri1 0 = Some (pair None c)\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n   prefer 2\n   apply(rule epdaS.some_position_has_details_at_0)\n   apply(rule epdaS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri2 0 = Some (pair None c)\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n   prefer 2\n   apply(rule parserS.some_position_has_details_at_0)\n   apply(rule parserS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c ca cb)(*strict*)\n  apply(rule_tac\n      x=\"cb\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c ca cb)(*strict*)\n   apply(simp add: derivation_append_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c ca cb)(*strict*)\n  apply(simp add: derivation_append_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c cb)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__RL__relation_initial_configuration_def get_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__configuration_rev_def)\n  done\n\nlemma epdaS_parserS_P2A_StateSimRL_inst_relation_initial_simulation_preserves_marked_effect: \"\n  \\<forall>G1 G2. F_PARSER_TO_EDPDA__RL__relation_TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<forall>d2. F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL G1 G2 c1 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. parserS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_PARSER_TO_EDPDA__RL__relation_initial_configuration G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der1 c1) deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_PARSER_TO_EDPDA__RL__relation_configuration F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL F_PARSER_TO_EDPDA__LR__relation_step_simulationRL G1 G2 (derivation_append deri1 (der1 c1) deri1n) deri1n (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> left_total_on (F_PARSER_TO_EDPDA__RL__relation_effect G1 G2) (epdaS_marked_effect G1 (derivation_append deri1 (der1 c1) deri1n)) (parserS_marked_effect G2 (derivation_append deri2 d2 deri2n)))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(rule_tac\n      x=\"a\"\n      in bexI)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__RL__relation_effect_def)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(simp add: parserS_marked_effect_def epdaS_marked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri1 0 = Some (pair None c)\")\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n   prefer 2\n   apply(rule epdaS.some_position_has_details_at_0)\n   apply(rule epdaS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri2 0 = Some (pair None c)\")\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n   prefer 2\n   apply(rule parserS.some_position_has_details_at_0)\n   apply(rule parserS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c ca cb)(*strict*)\n  apply(rule_tac\n      x=\"cb\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c ca cb)(*strict*)\n   apply(simp add: derivation_append_def)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c ca cb)(*strict*)\n  apply(simp add: derivation_append_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c cb)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__RL__relation_initial_configuration_def get_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__configuration_rev_def)\n  done\n\nlemma epdaS_parserS_P2A_StateSimRL_inst_ATS_Simulation_Configuration_Weak_Marked_Effect_axioms: \"\n  ATS_Simulation_Configuration_Weak_Marked_Effect_axioms epdaS_initial_configurations epda_step_labels epdaS_step_relation epdaS_marked_effect parserS_initial_configurations parserS_step_relation parserS_marked_effect F_PARSER_TO_EDPDA__RL__relation_configuration F_PARSER_TO_EDPDA__RL__relation_initial_configuration F_PARSER_TO_EDPDA__RL__relation_effect F_PARSER_TO_EDPDA__RL__relation_TSstructure F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL F_PARSER_TO_EDPDA__LR__relation_step_simulationRL\"\n  apply(simp add: ATS_Simulation_Configuration_Weak_Marked_Effect_axioms_def)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(rule epdaS_parserS_P2A_StateSimRL.relation_step_simulation_preservation_PROVE2)\n    apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n    prefer 2\n    apply(rename_tac G1 G2 d1' d2')(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(thin_tac \"epdaS_parserS_P2A_StateSimRL.relation_step_simulation_preservation G1 G2 d1' d2'\")\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(metis epdaS_parserS_P2A_StateSimRL_inst_relation_step_simulation_preserves_marked_effect)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 d1' d2')(*strict*)\n  apply(rule epdaS_parserS_P2A_StateSimRL.relation_initial_simulation_preservation_PROVE2)\n   apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   prefer 2\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(thin_tac \"epdaS_parserS_P2A_StateSimRL.relation_initial_simulation_preservation G1 G2 d1' d2'\")\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(metis epdaS_parserS_P2A_StateSimRL_inst_relation_initial_simulation_preserves_marked_effect)\n  done\n\ninterpretation \"epdaS_parserS_P2A_StateSimRL\" : ATS_Simulation_Configuration_WeakLR_FULL\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* TSstructure1 *)\n  \"valid_parser\"\n  (* configurations1 *)\n  \"parserS_configurations\"\n  (* initial_configurations1 *)\n  \"parserS_initial_configurations\"\n  (* step_labels1 *)\n  \"parser_step_labels\"\n  (* step_relation1 *)\n  \"parserS_step_relation\"\n  (* effects1 *)\n  \"parser_markers\"\n  (* marking_condition1 *)\n  \"parserS_marking_condition\"\n  (* marked_effect1 *)\n  \"parserS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"parserS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_PARSER_TO_EDPDA__RL__relation_configuration\"\n  (* relation_initial_configuration *)\n  \"F_PARSER_TO_EDPDA__RL__relation_initial_configuration\"\n  (* relation_effect *)\n  \"F_PARSER_TO_EDPDA__RL__relation_effect\"\n  (* relation_TSstructure *)\n  \"F_PARSER_TO_EDPDA__RL__relation_TSstructure\"\n  (* relation_initial_simulation *)\n  \"F_PARSER_TO_EDPDA__LR__relation_initial_simulationRL\"\n  (* relation_step_simulation *)\n  \"F_PARSER_TO_EDPDA__LR__relation_step_simulationRL\"\n  apply(simp add: LOCALE_DEFS epda_interpretations parser_interpretations)\n  apply(simp add: epdaS_parserS_P2A_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axioms  epdaS_parserS_P2A_StateSimRL_inst_ATS_Simulation_Configuration_Weak_Unmarked_Effect_axioms epdaS_parserS_P2A_StateSimRL_inst_ATS_Simulation_Configuration_Weak_Marked_Effect_axioms epdaS_parserS_P2A_StateSimRL_inst_ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms )\n  done\n\nlemma F_PARSER_TO_EDPDA_preserves_lang1: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G BOX\n  \\<Longrightarrow> parserS.marked_language G \\<subseteq> epdaS.marked_language (F_PARSER_TO_EDPDA G BOX)\"\n  apply(subgoal_tac \"left_total_on (F_PARSER_TO_EDPDA__LR__relation_effect SSG1 SSG2) (parserS.finite_marked_language SSG1) (epdaS.finite_marked_language SSG2)\" for SSG1 SSG2)\n   prefer 2\n   apply(rule parserS_epdaS_P2A_StateSimLR.ATS_Simulation_Configuration_Weak_Marked_Effect_sound)\n   apply(simp add: F_PARSER_TO_EDPDA__LR__relation_TSstructure_def)\n   apply(force)\n  apply(rule_tac\n      t=\"parserS.marked_language G\"\n      and s=\"parserS.finite_marked_language G\"\n      in ssubst)\n   apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n   apply (metis parserS.AX_marked_language_finite)\n  apply(rule_tac\n      t=\"epdaS.marked_language (F_PARSER_TO_EDPDA G BOX)\"\n      and s=\"epdaS.finite_marked_language (F_PARSER_TO_EDPDA G BOX)\"\n      in ssubst)\n   apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n   apply(rule sym)\n   apply (rule epdaS.AX_marked_language_finite)\n   apply (metis F_PARSER_TO_EDPDA_generates_epda F_PARSER_TO_EDPDA__SpecInput1_def)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(erule_tac\n      x=\"x\"\n      in ballE)\n   apply(rename_tac x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x b)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__LR__relation_effect_def)\n  apply(rename_tac x)(*strict*)\n  apply(force)\n  done\n\nlemma F_PARSER_TO_EDPDA_preserves_lang2: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G BOX\n  \\<Longrightarrow> parserS.marked_language G \\<supseteq> epdaS.marked_language (F_PARSER_TO_EDPDA G BOX)\"\n  apply(subgoal_tac \"left_total_on (F_PARSER_TO_EDPDA__RL__relation_effect SSG1 SSG2) (epdaS.finite_marked_language SSG1) (parserS.finite_marked_language SSG2)\" for SSG1 SSG2)\n   prefer 2\n   apply(rule epdaS_parserS_P2A_StateSimRL.ATS_Simulation_Configuration_Weak_Marked_Effect_sound)\n   apply(simp add: F_PARSER_TO_EDPDA__RL__relation_TSstructure_def)\n   apply(force)\n  apply(rule_tac\n      t=\"parserS.marked_language G\"\n      and s=\"parserS.finite_marked_language G\"\n      in ssubst)\n   apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n   apply (metis parserS.AX_marked_language_finite)\n  apply(rule_tac\n      t=\"epdaS.marked_language (F_PARSER_TO_EDPDA G BOX)\"\n      and s=\"epdaS.finite_marked_language (F_PARSER_TO_EDPDA G BOX)\"\n      in ssubst)\n   apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n   apply(rule sym)\n   apply (rule epdaS.AX_marked_language_finite)\n   apply (metis F_PARSER_TO_EDPDA_generates_epda F_PARSER_TO_EDPDA__SpecInput1_def)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(erule_tac\n      x=\"x\"\n      in ballE)\n   apply(rename_tac x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x b)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__RL__relation_effect_def)\n  apply(rename_tac x)(*strict*)\n  apply(force)\n  done\n\ntheorem F_PARSER_TO_EDPDA_preserves_lang: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G BOX\n  \\<Longrightarrow> parserS.marked_language G = epdaS.marked_language (F_PARSER_TO_EDPDA G BOX)\"\n  apply(rule order_antisym)\n   apply(metis F_PARSER_TO_EDPDA_preserves_lang1)\n  apply(metis F_PARSER_TO_EDPDA_preserves_lang2)\n  done\n\nlemma F_PARSER_TO_EDPDA_preserves_unmarked_language1: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G BOX\n  \\<Longrightarrow> parserS.unmarked_language G \\<subseteq> epdaS.unmarked_language (F_PARSER_TO_EDPDA G BOX)\"\n  apply(subgoal_tac \"left_total_on (F_PARSER_TO_EDPDA__LR__relation_effect SSG1 SSG2) (parserS.finite_unmarked_language SSG1) (epdaS.finite_unmarked_language SSG2)\" for SSG1 SSG2)\n   prefer 2\n   apply(rule parserS_epdaS_P2A_StateSimLR.ATS_Simulation_Configuration_Weak_Unmarked_Effect_sound)\n   apply(simp add: F_PARSER_TO_EDPDA__LR__relation_TSstructure_def)\n   apply(force)\n  apply(rule_tac\n      t=\"parserS.unmarked_language G\"\n      and s=\"parserS.finite_unmarked_language G\"\n      in ssubst)\n   apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n   apply (metis parserS.AX_unmarked_language_finite)\n  apply(rule_tac\n      t=\"epdaS.unmarked_language (F_PARSER_TO_EDPDA G BOX)\"\n      and s=\"epdaS.finite_unmarked_language (F_PARSER_TO_EDPDA G BOX)\"\n      in ssubst)\n   apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n   apply(rule sym)\n   apply (rule epdaS.AX_unmarked_language_finite)\n   apply (metis F_PARSER_TO_EDPDA_generates_epda F_PARSER_TO_EDPDA__SpecInput1_def)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(erule_tac\n      x=\"x\"\n      in ballE)\n   apply(rename_tac x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x b)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__LR__relation_effect_def)\n  apply(rename_tac x)(*strict*)\n  apply(force)\n  done\n\nlemma F_PARSER_TO_EDPDA_preserves_unmarked_language2: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G BOX\n  \\<Longrightarrow> parserS.unmarked_language G \\<supseteq> epdaS.unmarked_language (F_PARSER_TO_EDPDA G BOX)\"\n  apply(subgoal_tac \"left_total_on (F_PARSER_TO_EDPDA__RL__relation_effect SSG1 SSG2) (epdaS.finite_unmarked_language SSG1) (parserS.finite_unmarked_language SSG2)\" for SSG1 SSG2)\n   prefer 2\n   apply(rule epdaS_parserS_P2A_StateSimRL.ATS_Simulation_Configuration_Weak_Unmarked_Effect_sound)\n   apply(simp add: F_PARSER_TO_EDPDA__RL__relation_TSstructure_def)\n   apply(force)\n  apply(rule_tac\n      t=\"parserS.unmarked_language G\"\n      and s=\"parserS.finite_unmarked_language G\"\n      in ssubst)\n   apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n   apply (metis parserS.AX_unmarked_language_finite)\n  apply(rule_tac\n      t=\"epdaS.unmarked_language (F_PARSER_TO_EDPDA G BOX)\"\n      and s=\"epdaS.finite_unmarked_language (F_PARSER_TO_EDPDA G BOX)\"\n      in ssubst)\n   apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n   apply(rule sym)\n   apply (rule epdaS.AX_unmarked_language_finite)\n   apply (metis F_PARSER_TO_EDPDA_generates_epda F_PARSER_TO_EDPDA__SpecInput1_def)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(erule_tac\n      x=\"x\"\n      in ballE)\n   apply(rename_tac x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x b)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__RL__relation_effect_def)\n  apply(rename_tac x)(*strict*)\n  apply(force)\n  done\n\ntheorem F_PARSER_TO_EDPDA_preserves_unmarked_language: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G BOX\n  \\<Longrightarrow> parserS.unmarked_language G = epdaS.unmarked_language (F_PARSER_TO_EDPDA G BOX)\"\n  apply(rule order_antisym)\n   apply(metis F_PARSER_TO_EDPDA_preserves_unmarked_language1)\n  apply(metis F_PARSER_TO_EDPDA_preserves_unmarked_language2)\n  done\n\ndefinition F_PARSER_TO_EDPDA__LR__relation_initial_simulationRLB :: \"\n  ('stack, 'event, 'stack) epda\n  \\<Rightarrow> ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ('stack, 'event) parserS_conf\n  \\<Rightarrow> (('stack, 'event) parser_step_label, ('stack, 'event) parserS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_PARSER_TO_EDPDA__LR__relation_initial_simulationRLB G1 G2 c1 c2 d \\<equiv>\n  d = der1 (F_PARSER_TO_EDPDA__configuration_rev G2 c1)\"\n\ndefinition F_PARSER_TO_EDPDA__LR__relation_step_simulationRLB :: \"\n  ('stack, 'event, 'stack) epda\n  \\<Rightarrow> ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ('stack, 'event, 'stack) epda_step_label\n  \\<Rightarrow> ('stack, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ('stack, 'event) parserS_conf\n  \\<Rightarrow> (('stack, 'event) parser_step_label, ('stack, 'event) parserS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_PARSER_TO_EDPDA__LR__relation_step_simulationRLB G1 G2 c1 e1 c1' c2 d \\<equiv>\n  d = der2 (F_PARSER_TO_EDPDA__configuration_rev G2 c1) (F_PARSER_TO_EDPDA__rules_rev e1) (F_PARSER_TO_EDPDA__configuration_rev G2 c1')\"\n\ndefinition F_PARSER_TO_EDPDA__RL__relation_configurationB :: \"\n  ('stack, 'event, 'stack) epda\n  \\<Rightarrow> ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ('stack, 'event) parserS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_PARSER_TO_EDPDA__RL__relation_configurationB G1 G2 c1 c2 \\<equiv>\n  \\<exists>BOX.\n    F_PARSER_TO_EDPDA__SpecInput1 G2 BOX\n    \\<and> G1 = F_PARSER_TO_EDPDA G2 BOX\n    \\<and> (\\<exists>w.\n        BOX \\<notin> set w\n        \\<and> epdaS_conf_stack c1 = w @ [BOX])\n    \\<and> (F_PARSER_TO_EDPDA__configuration_rev G2 c1 = c2)\"\n\nlemma epdaS_parserS_P2A_StateSimRLB_inst_AX_relation_initial_simulationB: \"\n  (\\<forall>G1 G2. F_PARSER_TO_EDPDA__RL__relation_TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<forall>c2. F_PARSER_TO_EDPDA__RL__relation_configurationB G1 G2 c1 c2 \\<longrightarrow> (\\<exists>d2. parserS.derivation_initial G2 d2 \\<and> F_PARSER_TO_EDPDA__RL__relation_initial_configuration G1 G2 c1 (the (get_configuration (d2 0))) \\<and> F_PARSER_TO_EDPDA__LR__relation_initial_simulationRLB G1 G2 c1 c2 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> get_configuration (d2 n) = Some c2)))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__RL__relation_configurationB_def F_PARSER_TO_EDPDA__RL__relation_TSstructure_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 BOX BOXa w)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__LR__relation_initial_simulationRLB_def)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 BOX BOXa w)(*strict*)\n   apply(rule parserS.derivation_initialI)\n    apply(rename_tac G2 c1 BOX BOXa w)(*strict*)\n    apply(rule parserS.der1_is_derivation)\n   apply(rename_tac G2 c1 BOX BOXa w)(*strict*)\n   apply(simp add: der1_def get_configuration_def)\n   apply(simp add: parserS_initial_configurations_def epdaS_initial_configurations_def)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 BOX BOXa)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G2 c1 BOX BOXa)(*strict*)\n    prefer 2\n    apply(rule F_PARSER_TO_EDPDA__configuration_rev_preserves_configurations)\n      apply(rename_tac G2 c1 BOX BOXa)(*strict*)\n      apply(force)\n     apply(rename_tac G2 c1 BOX BOXa)(*strict*)\n     apply(force)\n    apply(rename_tac G2 c1 BOX BOXa)(*strict*)\n    apply(force)\n   apply(rename_tac G2 c1 BOX BOXa)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__configuration_rev_def)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rename_tac G2 c1 BOX BOXa w)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 BOX BOXa w)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA__RL__relation_initial_configuration_def)\n   apply(rule conjI)\n    apply(rename_tac G2 c1 BOX BOXa w)(*strict*)\n    apply(simp add: F_PARSER_TO_EDPDA__RL__relation_TSstructure_def)\n    apply(force)\n   apply(rename_tac G2 c1 BOX BOXa w)(*strict*)\n   apply(simp add: get_configuration_def der1_def)\n  apply(rename_tac G2 c1 BOX BOXa w)(*strict*)\n  apply(rule_tac\n      x=\"0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 BOX BOXa w)(*strict*)\n   apply(rule der1_maximum_of_domain)\n  apply(rename_tac G2 c1 BOX BOXa w)(*strict*)\n  apply(simp add: get_configuration_def der1_def)\n  done\n\nlemma epdaS_parserS_P2A_StateSimRLB_inst_AX_relation_step_simulationB: \"\n  (\\<forall>G1 G2. F_PARSER_TO_EDPDA__RL__relation_TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_PARSER_TO_EDPDA__RL__relation_configurationB G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. c1' \\<in> epdaS_configurations G1 \\<longrightarrow> epdaS_step_relation G1 c1' e1 c1 \\<longrightarrow> (\\<exists>d2. parserS.derivation G2 d2 \\<and> parserS.belongs G2 d2 \\<and> (\\<exists>n. the (get_configuration (d2 n)) = c2 \\<and> F_PARSER_TO_EDPDA__LR__relation_step_simulationRLB G1 G2 c1' e1 c1 c2 d2 \\<and> maximum_of_domain d2 n \\<and> F_PARSER_TO_EDPDA__RL__relation_configurationB G1 G2 c1' (the (get_configuration (d2 0)))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__RL__relation_configurationB_def F_PARSER_TO_EDPDA__RL__relation_TSstructure_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1 c1' BOX BOXa w)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__LR__relation_step_simulationRLB_def)\n  apply(rule_tac\n      x=\"der2 (F_PARSER_TO_EDPDA__configuration_rev G2 c1') (F_PARSER_TO_EDPDA__rules_rev e1) (F_PARSER_TO_EDPDA__configuration_rev G2 c1)\"\n      in exI)\n  apply(rename_tac G2 c1 e1 c1' BOX BOXa w)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"BOX=BOXa\")\n   apply(rename_tac G2 c1 e1 c1' BOX BOXa w)(*strict*)\n   prefer 2\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rename_tac G2 c1 e1 c1' BOX BOXa w)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1 c1' BOXa w)(*strict*)\n  apply(rename_tac BOX w)\n  apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. BOX \\<notin> set w \\<and> epdaS_conf_stack c1' = w @ [BOX]\")\n   apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 e1 c1' BOX w wa)(*strict*)\n   apply(subgoal_tac \"\\<forall>r \\<in> epda_delta (F_PARSER_TO_EDPDA G2 BOX). epda_box (F_PARSER_TO_EDPDA G2 BOX) \\<notin> set (edge_pop r) \\<and> epda_box (F_PARSER_TO_EDPDA G2 BOX) \\<notin> set (edge_push r)\")\n    apply(rename_tac G2 c1 e1 c1' BOX w wa)(*strict*)\n    prefer 2\n    apply(rule F_PARSER_TO_EDPDA__SpecInput1_no_pop_of_box)\n    apply(force)\n   apply(rename_tac G2 c1 e1 c1' BOX w wa)(*strict*)\n   apply(erule_tac\n      x=\"e1\"\n      in ballE)\n    apply(rename_tac G2 c1 e1 c1' BOX w wa)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G2 c1 e1 c1' BOX w wa)(*strict*)\n   apply(case_tac wa)\n    apply(rename_tac G2 c1 e1 c1' BOX w wa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n    apply(simp add: F_PARSER_TO_EDPDA_def)\n    apply(subgoal_tac \"BOX \\<in> set (edge_push e1)\")\n     apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n     apply(force)\n    apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n    apply (metis elem_set_app head_in_set)\n   apply(rename_tac G2 c1 e1 c1' BOX w wa a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. wa = w' @ [x']\")\n    apply(rename_tac G2 c1 e1 c1' BOX w wa a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac G2 c1 e1 c1' BOX w wa a list)(*strict*)\n   apply(thin_tac \"wa=a#list\")\n   apply(clarsimp)\n   apply(rename_tac G2 c1 e1 c1' w' x')(*strict*)\n   apply(rename_tac BOX)\n   apply(rename_tac G2 c1 e1 c1' w' BOX)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n   apply(rule parserS.der2_is_derivation)\n   apply(rule F_PARSER_TO_EDPDA_preserves_steps_prime)\n      apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n      apply(force)\n     apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n     apply(force)\n    apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n    apply(simp add: F_PARSER_TO_EDPDA_def)\n    apply(rule_tac\n      t=\"F_PARSER_TO_EDPDA__rules (F_PARSER_TO_EDPDA__rules_rev e1)\"\n      and s=\"e1\"\n      in ssubst)\n     apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n    apply(rule F_PARSER_TO_EDPDA__rules_F_PARSER_TO_EDPDA__rules_rev)\n     apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n     apply(blast)\n    apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n    apply(simp add: epda_step_labels_def)\n    apply(simp add: F_PARSER_TO_EDPDA_def)\n   apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n   apply(rule F_PARSER_TO_EDPDA__rules_rev_preserves_rules)\n    apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n    apply(force)\n   apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n   apply(force)\n  apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n   apply(rule parserS.der2_belongs)\n     apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n     apply(rule_tac\n      G=\"F_PARSER_TO_EDPDA G2 BOX\"\n      in F_PARSER_TO_EDPDA__configuration_rev_preserves_configurations)\n       apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n       apply(force)\n      apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac G2 c1 e1 c1' BOX w wa)(*strict*)\n      apply(simp add: F_PARSER_TO_EDPDA_def F_PARSER_TO_EDPDA__SpecInput1_def)\n     apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n     apply(force)\n    apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n    apply(simp add: parser_step_labels_def)\n    apply(rule F_PARSER_TO_EDPDA__rules_rev_preserves_rules)\n     apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n     apply(force)\n    apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n    apply(force)\n   apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n   apply(rule_tac\n      G=\"F_PARSER_TO_EDPDA G2 BOX\"\n      and BOX=\"BOX\"\n      in F_PARSER_TO_EDPDA__configuration_rev_preserves_configurations)\n     apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n     prefer 2\n     apply(clarsimp)\n     apply(rename_tac G2 c1 e1 c1' BOX w wa)(*strict*)\n     apply(simp add: F_PARSER_TO_EDPDA_def F_PARSER_TO_EDPDA__SpecInput1_def)\n    apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n    apply (metis F_PARSER_TO_EDPDA_generates_epda epdaS.AX_step_relation_preserves_belongsC)\n   apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n   apply(force)\n  apply(rename_tac G2 c1 e1 c1' BOX w)(*strict*)\n  apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1 c1' BOX w wa)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 e1 c1' BOX w wa)(*strict*)\n   apply(simp add: der2_def get_configuration_def)\n  apply(rename_tac G2 c1 e1 c1' BOX w wa)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 e1 c1' BOX w wa)(*strict*)\n   apply(rule der2_maximum_of_domain)\n  apply(rename_tac G2 c1 e1 c1' BOX w wa)(*strict*)\n  apply(simp add: der2_def get_configuration_def)\n  done\n\nlemma epdaS_parserS_P2A_StateSimRLB_inst_AX_initial_contained: \"\n  \\<forall>G1 G2. F_PARSER_TO_EDPDA__RL__relation_TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_PARSER_TO_EDPDA__RL__relation_initial_configuration G1 G2 c1 c2 \\<longrightarrow> F_PARSER_TO_EDPDA__RL__relation_configurationB G1 G2 c1 c2)\"\n  apply(simp add: F_PARSER_TO_EDPDA__RL__relation_initial_configuration_def F_PARSER_TO_EDPDA__RL__relation_configurationB_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__RL__relation_TSstructure_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 BOX)(*strict*)\n  apply(rule_tac\n      x=\"BOX\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 BOX)(*strict*)\n   apply(force)\n  apply(rename_tac G2 c1 BOX)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 BOX)(*strict*)\n   apply(force)\n  apply(rename_tac G2 c1 BOX)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def epdaS_initial_configurations_def)\n  apply(clarsimp)\n  apply(simp add: F_PARSER_TO_EDPDA_def)\n  done\n\nlemma F_PARSER_TO_EDPDA_preserves_is_forward_edge_deterministic: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G BOX\n  \\<Longrightarrow> valid_epda (F_PARSER_TO_EDPDA G BOX)\n  \\<Longrightarrow> parserS.is_forward_edge_deterministic_accessible G\n  \\<Longrightarrow> epdaS.is_forward_edge_deterministic_accessible (F_PARSER_TO_EDPDA G BOX)\"\n  apply(subgoal_tac \"parser_not_observes_input_terminator G\")\n   prefer 2\n   apply(rule F_PARSER_TO_EDPDA__SpecInput1_implies_parser_not_observes_input_terminator)\n   apply(force)\n  apply(simp add: epdaS.is_forward_edge_deterministic_accessible_def)\n  apply(clarsimp)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"edge_src e1 = epdaS_conf_state c\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"edge_src e2 = epdaS_conf_state c\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"prefix (option_to_list (edge_event e1)) (epdaS_conf_scheduler c)\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n   apply(simp add: prefix_def)\n   apply(clarsimp)\n   apply(rename_tac c c1 c2 e1 e2 w wa)(*strict*)\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"prefix (option_to_list (edge_event e2)) (epdaS_conf_scheduler c)\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n   apply(simp add: prefix_def)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"prefix (edge_pop e1) (epdaS_conf_stack c)\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n   apply(simp add: prefix_def)\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"prefix (edge_pop e2) (epdaS_conf_stack c)\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n   apply(simp add: prefix_def)\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"e1 \\<in> epda_delta (F_PARSER_TO_EDPDA G BOX)\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"e2 \\<in> epda_delta (F_PARSER_TO_EDPDA G BOX)\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(simp add: parserS.is_forward_edge_deterministic_accessible_def)\n  apply(erule_tac\n      x=\"F_PARSER_TO_EDPDA__configuration_rev G c\"\n      in ballE)\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   apply(erule_tac\n      x=\"F_PARSER_TO_EDPDA__configuration_rev G c1\"\n      in allE)\n   apply(erule_tac\n      x=\"F_PARSER_TO_EDPDA__configuration_rev G c2\"\n      in allE)\n   apply(subgoal_tac \"e1 \\<in> F_PARSER_TO_EDPDA__rules ` parser_rules G\")\n    apply(rename_tac c c1 c2 e1 e2)(*strict*)\n    prefer 2\n    apply(simp add: F_PARSER_TO_EDPDA_def)\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   apply(thin_tac \"e1 \\<in> epda_delta (F_PARSER_TO_EDPDA G BOX)\")\n   apply(clarsimp)\n   apply(rename_tac c c1 c2 e2 x)(*strict*)\n   apply(subgoal_tac \"e2 \\<in> F_PARSER_TO_EDPDA__rules ` parser_rules G\")\n    apply(rename_tac c c1 c2 e2 x)(*strict*)\n    prefer 2\n    apply(simp add: F_PARSER_TO_EDPDA_def)\n   apply(rename_tac c c1 c2 e2 x)(*strict*)\n   apply(thin_tac \"e2 \\<in> epda_delta (F_PARSER_TO_EDPDA G BOX)\")\n   apply(clarsimp)\n   apply(rename_tac c c1 c2 x xa)(*strict*)\n   apply(subgoal_tac \"valid_parser_step_label G x\")\n    apply(rename_tac c c1 c2 x xa)(*strict*)\n    prefer 2\n    apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def valid_parser_def)\n   apply(rename_tac c c1 c2 x xa)(*strict*)\n   apply(subgoal_tac \"valid_parser_step_label G xa\")\n    apply(rename_tac c c1 c2 x xa)(*strict*)\n    prefer 2\n    apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def valid_parser_def)\n   apply(rename_tac c c1 c2 x xa)(*strict*)\n   apply(erule_tac\n      x=\"x\"\n      in allE)\n   apply(erule_tac\n      x=\"xa\"\n      in allE)\n   apply(erule impE)\n    apply(rename_tac c c1 c2 x xa)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac c c1 c2 x xa)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac c c1 c2 x xa)(*strict*)\n    apply(rule F_PARSER_TO_EDPDA_preserves_steps)\n       apply(rename_tac c c1 c2 x xa)(*strict*)\n       apply(force)\n      apply(rename_tac c c1 c2 x xa)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 x xa)(*strict*)\n     apply(force)\n    apply(rename_tac c c1 c2 x xa)(*strict*)\n    apply(force)\n   apply(rename_tac c c1 c2 x xa)(*strict*)\n   apply(rule F_PARSER_TO_EDPDA_preserves_steps)\n      apply(rename_tac c c1 c2 x xa)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 x xa)(*strict*)\n     apply(force)\n    apply(rename_tac c c1 c2 x xa)(*strict*)\n    apply(force)\n   apply(rename_tac c c1 c2 x xa)(*strict*)\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"F_PARSER_TO_EDPDA__configuration_rev G c \\<in> parserS.get_accessible_configurations G\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(thin_tac \"F_PARSER_TO_EDPDA__configuration_rev G c \\<notin> parserS.get_accessible_configurations G\")\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(rule_tac\n      ?c1.0=\"c\"\n      and ?G1.0=\"F_PARSER_TO_EDPDA G BOX\"\n      in epdaS_parserS_P2A_StateSimRL.get_accessible_configurations_transfer)\n      apply(rename_tac c c1 c2 e1 e2)(*strict*)\n      apply(simp add: F_PARSER_TO_EDPDA__RL__relation_TSstructure_def)\n      apply(force)\n     apply(rename_tac c c1 c2 e1 e2)(*strict*)\n     apply(rule_tac ?G.0=\"F_PARSER_TO_EDPDA G BOX\" and BOX=\"BOX\" in F_PARSER_TO_EDPDA__configuration_rev_preserves_configurations)\n       apply(rename_tac c c1 c2 e1 e2)(*strict*)\n       apply (metis epdaS.get_accessible_configurations_are_configurations2)\n      apply(rename_tac c c1 c2 e1 e2)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac c c1 c2 e1 e2)(*strict*)\n     prefer 2\n     apply(simp add: F_PARSER_TO_EDPDA__RL__relation_configuration_def)\n     apply(simp add: F_PARSER_TO_EDPDA__RL__relation_TSstructure_def)\n     apply(force)\n    apply(rename_tac c c1 c2 e1 e2)(*strict*)\n    prefer 2\n    apply(rename_tac c c1 c2 e1 e2 cA cB)(*strict*)\n    apply(simp add: F_PARSER_TO_EDPDA__RL__relation_configuration_def)\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(simp add: epdaS.get_accessible_configurations_def get_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac c c1 c2 e1 e2 d i)(*strict*)\n  apply(case_tac \"d i\")\n   apply(rename_tac c c1 c2 e1 e2 d i)(*strict*)\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2 d i a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac c c1 c2 e1 e2 d i a option conf)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c c1 c2 e1 e2 d i option)(*strict*)\n  apply(rule epda_no_use_epda_box_implies_stack_content)\n     apply(rename_tac c c1 c2 e1 e2 d i option)(*strict*)\n     apply(force)\n    apply(rename_tac c c1 c2 e1 e2 d i option)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac c c1 c2 e1 e2 d i option)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2 d i option)(*strict*)\n  apply(simp (no_asm) add: F_PARSER_TO_EDPDA__SpecInput1_def parser_not_observes_input_terminator_def F_PARSER_TO_EDPDA_def)\n  apply(simp add: valid_epda_def)\n  apply(clarsimp)\n  apply(rename_tac c c1 c2 e1 e2 d i option r)(*strict*)\n  apply(erule_tac x=\"F_PARSER_TO_EDPDA__rules r\" in ballE)\n   apply(rename_tac c c1 c2 e1 e2 d i option r)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"F_PARSER_TO_EDPDA__rules r \\<in> epda_delta (F_PARSER_TO_EDPDA G BOX)\")\n    apply(rename_tac c c1 c2 e1 e2 d i option r)(*strict*)\n    apply(force)\n   apply(rename_tac c c1 c2 e1 e2 d i option r)(*strict*)\n   apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(rename_tac c c1 c2 e1 e2 d i option r)(*strict*)\n  apply(thin_tac \"epdaS_step_relation (F_PARSER_TO_EDPDA G BOX) c e1 c1\")\n  apply(thin_tac \"epdaS_step_relation (F_PARSER_TO_EDPDA G BOX) c e2 c2\")\n  apply(thin_tac \"edge_src e1 = epdaS_conf_state c\")\n  apply(thin_tac \"edge_src e2 = epdaS_conf_state c\")\n  apply(thin_tac \"option_to_list (edge_event e1) \\<sqsubseteq> epdaS_conf_scheduler c\")\n  apply(thin_tac \"option_to_list (edge_event e2) \\<sqsubseteq> epdaS_conf_scheduler c\")\n  apply(thin_tac \"edge_pop e1 \\<sqsubseteq> epdaS_conf_stack c\")\n  apply(thin_tac \"edge_pop e2 \\<sqsubseteq> epdaS_conf_stack c\")\n  apply(thin_tac \"e1 \\<in> epda_delta (F_PARSER_TO_EDPDA G BOX)\")\n  apply(thin_tac \"e2 \\<in> epda_delta (F_PARSER_TO_EDPDA G BOX)\")\n  apply(thin_tac \"epdaS.derivation_initial (F_PARSER_TO_EDPDA G BOX) d\")\n  apply(thin_tac \"d i = Some (pair option c) \")\n  apply(thin_tac \"epda_initial (F_PARSER_TO_EDPDA G BOX) \\<in> epda_states (F_PARSER_TO_EDPDA G BOX)\")\n  apply(thin_tac \"epda_box (F_PARSER_TO_EDPDA G BOX) \\<in> epda_gamma (F_PARSER_TO_EDPDA G BOX)\")\n  apply(thin_tac \"epda_marking (F_PARSER_TO_EDPDA G BOX) \\<subseteq> epda_states (F_PARSER_TO_EDPDA G BOX)\")\n  apply(simp add: valid_epda_step_label_def)\n  apply(rename_tac r)(*strict*)\n  apply(simp (no_asm_use) add: F_PARSER_TO_EDPDA__SpecInput1_def parser_not_observes_input_terminator_def F_PARSER_TO_EDPDA_def F_PARSER_TO_EDPDA__rules_def valid_parser_def)\n  apply(erule_tac x=\"r\" in ballE)\n   apply(rename_tac r)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac r)(*strict*)\n  apply(clarsimp)\n  apply(erule_tac x=\"r\" in ballE)\n   apply(rename_tac r)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac r)(*strict*)\n  apply(erule_tac x=\"r\" in ballE)\n   apply(rename_tac r)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac r)(*strict*)\n  apply(simp add: must_terminated_by_def kleene_star_def append_language_def)\n  apply(clarsimp)\n  apply(case_tac r)\n  apply(rename_tac r rule_lpopa rule_rpopa rule_lpusha rule_rpusha)(*strict*)\n  apply(rename_tac a b c d)\n  apply(rename_tac r a b c d)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac a b c)(*strict*)\n  apply(rule_tac xs=\"a\" in rev_cases)\n   apply(rename_tac a b c)(*strict*)\n   apply(force)\n  apply(rename_tac a b c ys y)(*strict*)\n  apply(rule_tac xs=\"c\" in rev_cases)\n   apply(rename_tac a b c ys y)(*strict*)\n   apply(force)\n  apply(rename_tac a b c ys y ysa ya)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac b ys y ysa ya)(*strict*)\n  apply(simp add: valid_parser_step_label_def)\n  apply(clarsimp)\n  apply(rename_tac ys y ysa ya k w)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac ys y ysa ya k w)(*strict*)\n   apply(rule_tac B=\"parser_nonterms G\" in nset_mp)\n    apply(rename_tac ys y ysa ya k w)(*strict*)\n    apply(force)\n   apply(rename_tac ys y ysa ya k w)(*strict*)\n   apply(force)\n  apply(rename_tac ys y ysa ya k w)(*strict*)\n  apply(rule_tac B=\"parser_nonterms G\" in nset_mp)\n   apply(rename_tac ys y ysa ya k w)(*strict*)\n   apply(force)\n  apply(rename_tac ys y ysa ya k w)(*strict*)\n  apply(force)\n  done\n\nlemma F_PARSER_TO_EDPDA_determ_sound: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G BOX\n  \\<Longrightarrow> parserS.Nonblockingness_linear_DB G\n  \\<Longrightarrow> parserS.is_forward_edge_deterministic_accessible G\n  \\<Longrightarrow> epdaS.Nonblockingness_linear_DB (F_PARSER_TO_EDPDA G BOX)\"\n  apply(subgoal_tac \"valid_epda (F_PARSER_TO_EDPDA G BOX)\")\n   prefer 2\n   apply (metis F_PARSER_TO_EDPDA_generates_epda)\n  apply(subgoal_tac \"epdaS.Nonblockingness_linear_restricted_DB SSM\" for SSM)\n   prefer 2\n   apply(rule epdaS.AX_BF_LinDBRest_DetR_LaOp)\n     apply(force)\n    apply(simp add: epdaS.is_forward_deterministic_accessible_def)\n    apply(rule conjI)\n     apply (metis epda_is_is_forward_target_deterministic_accessible)\n    apply(rule F_PARSER_TO_EDPDA_preserves_is_forward_edge_deterministic)\n      apply(force)\n     apply(force)\n    apply(simp add: parserS.is_forward_deterministic_accessible_def)\n   apply(rule_tac\n      t=\"epdaS.unmarked_language (F_PARSER_TO_EDPDA G BOX)\"\n      and s=\"parserS.unmarked_language G\"\n      in ssubst)\n    apply (metis F_PARSER_TO_EDPDA_preserves_unmarked_language)\n   apply(rule_tac\n      t=\"epdaS.marked_language (F_PARSER_TO_EDPDA G BOX)\"\n      and s=\"parserS.marked_language G\"\n      in ssubst)\n    apply (metis F_PARSER_TO_EDPDA_preserves_lang)\n   apply(rule parserS.AX_BF_LinDB_OpLa)\n    apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n   apply(force)\n  apply(simp add: epdaS.Nonblockingness_linear_restricted_DB_def epdaS.Nonblockingness_linear_DB_def)\n  done\n\nlemma P2A_epda_no_empty_steps_from_marking_states: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G BOX\n  \\<Longrightarrow> (\\<forall>e. e \\<in> parser_rules G \\<longrightarrow> last (rule_lpop e) \\<in> parser_marking G \\<longrightarrow> rule_rpop e \\<noteq> [])\n  \\<Longrightarrow> R = F_PARSER_TO_EDPDA G BOX\n  \\<Longrightarrow> q \\<in> epda_marking R\n  \\<Longrightarrow> e \\<in> epda_delta R\n  \\<Longrightarrow> edge_src e \\<in> epda_marking R\n  \\<Longrightarrow> edge_event e \\<noteq> None\"\n  apply(simp add: F_PARSER_TO_EDPDA_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: F_PARSER_TO_EDPDA__rules_def)\n  apply(simp add: list_to_option_def)\n  apply(case_tac \"rule_rpop x\")\n   apply(rename_tac x)(*strict*)\n   apply(force)\n  apply(rename_tac x a list)(*strict*)\n  apply(force)\n  done\n\nlemma F_PARSER_TO_EDPDA_enforces_epda_no_empty_steps_from_marking_states: \"\n  F_PARSER_TO_EDPDA__SpecInput1 G BOX\n  \\<Longrightarrow> parser_no_empty_steps_from_marking_states G\n  \\<Longrightarrow> epda_no_empty_steps_from_marking_states (F_PARSER_TO_EDPDA G BOX)\"\n  apply(simp add: epda_no_empty_steps_from_marking_states_def parser_no_empty_steps_from_marking_states_def)\n  apply(clarsimp)\n  apply(rename_tac e)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac e)(*strict*)\n   prefer 2\n   apply(rule P2A_epda_no_empty_steps_from_marking_states)\n        apply(rename_tac e)(*strict*)\n        apply(force)\n       apply(rename_tac e)(*strict*)\n       apply(force)\n      apply(rename_tac e)(*strict*)\n      apply(force)\n     apply(rename_tac e)(*strict*)\n     apply(force)\n    apply(rename_tac e)(*strict*)\n    apply(force)\n   apply(rename_tac e)(*strict*)\n   apply(force)\n  apply(rename_tac e)(*strict*)\n  apply(force)\n  done\n\ndefinition F_PARSER_TO_EDPDA__SpecInput :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> 'stack\n  \\<Rightarrow> bool\"\n  where\n    \"F_PARSER_TO_EDPDA__SpecInput G BOX \\<equiv>\n  valid_bounded_parser G (Suc 0)\n  \\<and> BOX \\<notin> parser_nonterms G\n  \\<and> parserFS.is_forward_edge_deterministic_accessible G\n  \\<and> nonblockingness_language (parserS.unmarked_language G) (parserS.marked_language G)\n  \\<and> parser_not_observes_input_terminator G\n  \\<and> parser_no_top_rules G\n  \\<and> parser_no_empty_steps_from_marking_states G\"\n\ndefinition F_PARSER_TO_EDPDA__SpecOutput :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('state, 'event, 'stackx) epda\n  \\<Rightarrow> bool\"\n  where\n    \"F_PARSER_TO_EDPDA__SpecOutput Gi Go \\<equiv>\n  valid_epda Go\n  \\<and> epdaS.is_forward_edge_deterministic_accessible Go\n  \\<and> parserS.marked_language Gi = epdaS.marked_language Go\n  \\<and> nonblockingness_language (epdaS.unmarked_language Go) (epdaS.marked_language Go)\n  \\<and> epda_no_empty_steps_from_marking_states Go\"\n\ntheorem F_PARSER_TO_EDPDA__SOUND: \"\n  F_PARSER_TO_EDPDA__SpecInput G BOX\n  \\<Longrightarrow> F_PARSER_TO_EDPDA__SpecOutput G (F_PARSER_TO_EDPDA G BOX)\"\n  apply(simp add: F_PARSER_TO_EDPDA__SpecInput_def F_PARSER_TO_EDPDA__SpecOutput_def)\n  apply(clarsimp)\n  apply(subgoal_tac \"F_PARSER_TO_EDPDA__SpecInput1 G BOX\")\n   prefer 2\n   apply(simp add: F_PARSER_TO_EDPDA__SpecInput1_def)\n   apply(simp add: valid_bounded_parser_def)\n   apply(clarsimp)\n   apply(rename_tac r)(*strict*)\n   apply(simp add: parser_no_top_rules_def)\n   apply(subgoal_tac \"valid_parser_step_label G r\")\n    apply(rename_tac r)(*strict*)\n    prefer 2\n    apply(simp add: valid_parser_def)\n   apply(rename_tac r)(*strict*)\n   apply(simp add: valid_parser_step_label_def)\n  apply(rule context_conjI)\n   apply(rule F_PARSER_TO_EDPDA_generates_epda)\n   apply(force)\n  apply(rule conjI)\n   apply(rule F_PARSER_TO_EDPDA_preserves_is_forward_edge_deterministic)\n     apply(force)\n    apply(force)\n   apply(rule_tac parserS_vs_parserFS.preserve_FEdetermR2)\n    prefer 2\n    apply(force)\n   apply(simp add: valid_bounded_parser_def)\n  apply(rule context_conjI)\n   apply(rule F_PARSER_TO_EDPDA_preserves_lang)\n   apply(force)\n  apply(rule conjI)\n   apply(subgoal_tac \"parserS.unmarked_language G = epdaS.unmarked_language (F_PARSER_TO_EDPDA G BOX)\")\n    apply(force)\n   apply(rule F_PARSER_TO_EDPDA_preserves_unmarked_language)\n   apply(force)\n  apply(rule F_PARSER_TO_EDPDA_enforces_epda_no_empty_steps_from_marking_states)\n   apply(force)\n  apply(force)\n  done\n\nend\n\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_12_07_01/FUNCTION__PARSER_TO_EDPDA.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.679178699175393, "lm_q2_score": 0.4148988457967688, "lm_q1q2_score": 0.2817904583776214}}
{"text": "(*  Title:      HOL/NanoJava/TypeRel.thy\n    Author:     David von Oheimb, Technische Universitaet Muenchen\n*)\n\nsection \"Type relations\"\n\ntheory TypeRel\nimports Decl\nbegin\n\ntext\\<open>Direct subclass relation\\<close>\n\ndefinition subcls1 :: \"(cname \\<times> cname) set\"\nwhere\n  \"subcls1 \\<equiv> {(C,D). C\\<noteq>Object \\<and> (\\<exists>c. class C = Some c \\<and> super c=D)}\"\n\nabbreviation\n  subcls1_syntax :: \"[cname, cname] => bool\"  (\"_ \\<prec>C1 _\" [71,71] 70)\n  where \"C \\<prec>C1 D == (C,D) \\<in> subcls1\"\nabbreviation\n  subcls_syntax  :: \"[cname, cname] => bool\" (\"_ \\<preceq>C _\"  [71,71] 70)\n  where \"C \\<preceq>C D \\<equiv> (C,D) \\<in> subcls1\\<^sup>*\"\n\n\nsubsection \"Declarations and properties not used in the meta theory\"\n\ntext\\<open>Widening, viz. method invocation conversion\\<close>\ninductive\n  widen :: \"ty => ty => bool\"  (\"_ \\<preceq> _\" [71,71] 70)\nwhere\n  refl [intro!, simp]: \"T \\<preceq> T\"\n| subcls: \"C\\<preceq>C D \\<Longrightarrow> Class C \\<preceq> Class D\"\n| null [intro!]: \"NT \\<preceq> R\"\n\nlemma subcls1D: \n  \"C\\<prec>C1D \\<Longrightarrow> C \\<noteq> Object \\<and> (\\<exists>c. class C = Some c \\<and> super c=D)\"\napply (unfold subcls1_def)\napply auto\ndone\n\nlemma subcls1I: \"\\<lbrakk>class C = Some m; super m = D; C \\<noteq> Object\\<rbrakk> \\<Longrightarrow> C\\<prec>C1D\"\napply (unfold subcls1_def)\napply auto\ndone\n\nlemma subcls1_def2: \n  \"subcls1 = \n    (SIGMA C: {C. is_class C} . {D. C\\<noteq>Object \\<and> super (the (class C)) = D})\"\napply (unfold subcls1_def is_class_def)\napply (auto split:if_split_asm)\ndone\n\nlemma finite_subcls1: \"finite subcls1\"\napply(subst subcls1_def2)\napply(rule finite_SigmaI [OF finite_is_class])\napply(rule_tac B = \"{super (the (class C))}\" in finite_subset)\napply  auto\ndone\n\ndefinition ws_prog :: \"bool\" where\n \"ws_prog \\<equiv> \\<forall>(C,c)\\<in>set Prog. C\\<noteq>Object \\<longrightarrow> \n                              is_class (super c) \\<and> (super c,C)\\<notin>subcls1\\<^sup>+\"\n\nlemma ws_progD: \"\\<lbrakk>class C = Some c; C\\<noteq>Object; ws_prog\\<rbrakk> \\<Longrightarrow>  \n  is_class (super c) \\<and> (super c,C)\\<notin>subcls1\\<^sup>+\"\napply (unfold ws_prog_def class_def)\napply (drule_tac map_of_SomeD)\napply auto\ndone\n\nlemma subcls1_irrefl_lemma1: \"ws_prog \\<Longrightarrow> subcls1\\<inverse> \\<inter> subcls1\\<^sup>+ = {}\"\nby (fast dest: subcls1D ws_progD)\n\n(* irrefl_tranclI in Transitive_Closure.thy is more general *)\nlemma irrefl_tranclI': \"r\\<inverse> \\<inter> r\\<^sup>+ = {} \\<Longrightarrow> \\<forall>x. (x, x) \\<notin> r\\<^sup>+\"\nby(blast elim: tranclE dest: trancl_into_rtrancl)\n\n\nlemmas subcls1_irrefl_lemma2 = subcls1_irrefl_lemma1 [THEN irrefl_tranclI']\n\nlemma subcls1_irrefl: \"\\<lbrakk>(x, y) \\<in> subcls1; ws_prog\\<rbrakk> \\<Longrightarrow> x \\<noteq> y\"\napply (rule irrefl_trancl_rD)\napply (rule subcls1_irrefl_lemma2)\napply auto\ndone\n\nlemmas subcls1_acyclic = subcls1_irrefl_lemma2 [THEN acyclicI]\n\nlemma wf_subcls1: \"ws_prog \\<Longrightarrow> wf (subcls1\\<inverse>)\"\nby (auto intro: finite_acyclic_wf_converse finite_subcls1 subcls1_acyclic)\n\ndefinition class_rec ::\"cname \\<Rightarrow> (class \\<Rightarrow> ('a \\<times> 'b) list) \\<Rightarrow> ('a \\<rightharpoonup> 'b)\"\nwhere\n  \"class_rec \\<equiv> wfrec (subcls1\\<inverse>) (\\<lambda>rec C f.\n     case class C of None \\<Rightarrow> undefined\n      | Some m \\<Rightarrow> (if C = Object then Map.empty else rec (super m) f) ++ map_of (f m))\"\n\nlemma class_rec: \"\\<lbrakk>class C = Some m;  ws_prog\\<rbrakk> \\<Longrightarrow>\n class_rec C f = (if C = Object then Map.empty else class_rec (super m) f) ++ \n                 map_of (f m)\"\napply (drule wf_subcls1)\napply (subst def_wfrec[OF class_rec_def], auto)\napply (subst cut_apply, auto intro: subcls1I)\ndone\n\n\\<comment> \\<open>Methods of a class, with inheritance and hiding\\<close>\ndefinition \"method\" :: \"cname => (mname \\<rightharpoonup> methd)\" where\n  \"method C \\<equiv> class_rec C methods\"\n\nlemma method_rec: \"\\<lbrakk>class C = Some m; ws_prog\\<rbrakk> \\<Longrightarrow>\nmethod C = (if C=Object then Map.empty else method (super m)) ++ map_of (methods m)\"\napply (unfold method_def)\napply (erule (1) class_rec [THEN trans])\napply simp\ndone\n\n\n\\<comment> \\<open>Fields of a class, with inheritance and hiding\\<close>\ndefinition field  :: \"cname => (fname \\<rightharpoonup> ty)\" where\n  \"field C \\<equiv> class_rec C flds\"\n\nlemma flds_rec: \"\\<lbrakk>class C = Some m; ws_prog\\<rbrakk> \\<Longrightarrow>\nfield C = (if C=Object then Map.empty else field (super m)) ++ map_of (flds m)\"\napply (unfold field_def)\napply (erule (1) class_rec [THEN trans])\napply simp\ndone\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/NanoJava/TypeRel.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6548947290421275, "lm_q2_score": 0.43014734858584286, "lm_q1q2_score": 0.28170123130031516}}
{"text": "section \\<open>Correctness of Type Checker\\<close>\n\ntheory Wasm_Checker_Properties imports Wasm_Checker Wasm_Properties begin\n\nsubsection \\<open>Soundness\\<close>\n\nlemma b_e_check_single_type_sound:\n  assumes \"type_update (Type x1) (to_ct_list t_in) (Type t_out) = Type x2\"\n          \"c_types_agree (Type x2) tm\"\n          \"\\<C> \\<turnstile> [e] : (t_in _> t_out)\"\n        shows \"\\<exists>tn. c_types_agree (Type x1) tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\n  using assms(2) b_e_typing.intros(39)[OF assms(3)] type_update_type[OF assms(1)]\n  by auto\n\nlemma b_e_check_single_top_sound:\n  assumes \"type_update (TopType x1) (to_ct_list t_in) (Type t_out) = TopType x2\"\n          \"c_types_agree (TopType x2) tm\"\n          \"\\<C> \\<turnstile> [e] : (t_in _> t_out)\"\n  shows \"\\<exists>tn. c_types_agree (TopType x1) tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\nproof -\n  obtain t_ag where t_ag_def:\"ct_suffix (to_ct_list t_out) x2\"\n                             \"tm = t_ag @ t_out\"\n                             \"c_types_agree (TopType x1) (t_ag @ t_in)\"\n    using type_update_top_top[OF assms(1,2)]\n    by fastforce\n  hence \"\\<C> \\<turnstile> [e] : (t_ag@t_in _> t_ag@t_out)\"\n    using b_e_typing.intros(39)[OF assms(3)]\n    by fastforce\n  thus ?thesis\n    using t_ag_def\n    by fastforce\nqed\n\nlemma b_e_check_single_top_not_bot_sound:\n  assumes \"type_update ts (to_ct_list t_in) (TopType []) = ts'\"\n          \"ts \\<noteq> Bot\"\n          \"ts' \\<noteq> Bot\"\n  shows \"\\<exists>tn. c_types_agree ts tn \\<and> suffix t_in tn\"\nproof (cases ts)\n  case (TopType x1)\n  then obtain t_int where \"consume (TopType x1) (to_ct_list t_in) = t_int\" \"t_int \\<noteq> Bot\"\n    using assms(1,2,3)\n    by fastforce\n  thus ?thesis\n    using TopType ct_suffix_ct_list_eq_exists ct_suffix_ts_conv_suffix\n    unfolding consume.simps\n    by (metis append_Nil c_types_agree.simps(2) ct_suffix_def)\nnext\n  case (Type x2)\n  then obtain t_int where \"consume (Type x2) (to_ct_list t_in) = t_int\" \"t_int \\<noteq> Bot\"\n    using assms(1,2,3)\n    by fastforce\n  thus ?thesis\n    using c_types_agree_id Type consume_type suffixI ct_suffix_ts_conv_suffix\n    by fastforce\nnext\n  case Bot\n  thus ?thesis\n    using assms(2)\n    by simp\nqed\n\nlemma b_e_check_single_type_not_bot_sound:\n  assumes \"type_update ts (to_ct_list t_in) (Type t_out) = ts'\"\n          \"ts \\<noteq> Bot\"\n          \"ts' \\<noteq> Bot\"\n          \"c_types_agree ts' tm\"\n          \"\\<C> \\<turnstile> [e] : (t_in _> t_out)\"\n  shows \"\\<exists>tn. c_types_agree ts tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\n  using assms b_e_check_single_type_sound\nproof (cases ts)\n  case (TopType x1)\n  then obtain x1' where x_def:\"TopType x1' = ts'\"\n    using assms\n    by (simp, metis (full_types) produce.simps(1) produce.simps(6))\n  thus ?thesis\n    using assms b_e_check_single_top_sound TopType\n    by fastforce\nnext\n  case (Type x2)\n  then obtain x2' where x_def:\"Type x2' = ts'\"\n    using assms\n    by (simp, metis (full_types) produce.simps(2) produce.simps(6))\n  thus ?thesis\n    using assms b_e_check_single_type_sound Type\n    by fastforce\nnext\n  case Bot\n  thus ?thesis\n    using assms(2)\n    by simp\nqed\n\nlemma b_e_check_single_sound_unop_testop_cvtop:\n  assumes \"check_single \\<C> e tn' = tm'\"\n          \"((e = (Unop_i t uu) \\<or> e = (ExtendS t uv) \\<or> e = (Testop t uw)) \\<and> is_int_t t)\n           \\<or> (e = (Unop_f t ux) \\<and> is_float_t t)\n           \\<or> (e = (Cvtop t1 Convert t sx) \\<and> convert_cond t1 t sx)\n           \\<or> (e = (Cvtop t1 ConvertSat t sx) \\<and> convert_cond t1 t sx)\n           \\<or> (e = (Cvtop t1 Reinterpret t sx) \\<and> ((t1 \\<noteq> t) \\<and> t_length t1 = t_length t \\<and> sx = None))\"\n          \"c_types_agree tm' tm\"\n          \"tn' \\<noteq> Bot\"\n          \"tm' \\<noteq> Bot\"\n shows \"\\<exists>tn. c_types_agree tn' tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\nproof -\n  have \"(e = (Cvtop t1 Convert t sx) \\<Longrightarrow> convert_cond t1 t sx)\"\n    using assms(2)\n    by simp\n  hence temp0:\"(e = (Cvtop t1 Convert t sx)) \\<Longrightarrow> (type_update tn' [TSome t] (Type [arity_1_result e]) = tm')\"\n    using assms(1,5) arity_1_result_def\n    by (simp del: convert_cond.simps)\n  have \"(e = (Cvtop t1 ConvertSat t sx) \\<Longrightarrow> convert_cond t1 t sx)\"\n    using assms(2)\n    by simp\n  hence temp1:\"(e = (Cvtop t1 ConvertSat t sx)) \\<Longrightarrow> (type_update tn' [TSome t] (Type [arity_1_result e]) = tm')\"\n    using assms(1,5) arity_1_result_def\n    by (simp del: convert_cond.simps)\n  have temp2:\"(e = (Cvtop t1 Reinterpret t sx)) \\<Longrightarrow> (type_update tn' [TSome t] (Type [arity_1_result e]) = tm')\"\n    using assms(1,2,5) arity_1_result_def\n    by simp\n  have 1:\"type_update tn' (to_ct_list [t]) (Type [arity_1_result e]) = tm'\"\n    using assms arity_1_result_def\n    unfolding to_ct_list_def\n    apply (simp del: convert_cond.simps)\n    apply (metis (no_types, lifting) b_e.simps(1175) b_e.simps(1176) b_e.simps(1177) b_e.simps(1180) check_single.simps(2) check_single.simps(3) check_single.simps(4) check_single.simps(7) temp0 temp1 temp2 type_update.simps)\n    done\n  have \"\\<C> \\<turnstile> [e] : ([t] _> [arity_1_result e])\"\n    using assms(2) b_e_typing.intros(2,3,4,7,10,11,12)\n    unfolding arity_1_result_def\n    by fastforce\n  thus ?thesis\n    using b_e_check_single_type_not_bot_sound[OF 1 assms(4,5,3)]\n    by fastforce\nqed\n\nlemma b_e_check_single_sound_binop_relop:\n  assumes \"check_single \\<C> e tn' = tm'\"\n          \"((e = Binop_i t iop \\<and> is_int_t t)\n            \\<or> (e = Binop_f t fop \\<and> is_float_t t)\n            \\<or> (e = Relop_i t irop \\<and> is_int_t t)\n            \\<or> (e = Relop_f t frop \\<and> is_float_t t))\"\n          \"c_types_agree tm' tm\"\n          \"tn' \\<noteq> Bot\"\n          \"tm' \\<noteq> Bot\"\n shows \"\\<exists>tn. c_types_agree tn' tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\nproof -\n  have \"type_update tn' (to_ct_list [t,t]) (Type [arity_2_result e]) = tm'\"\n    using assms arity_2_result_def\n    unfolding to_ct_list_def\n    by auto\n  moreover\n  have \"\\<C> \\<turnstile> [e] : ([t,t] _> [arity_2_result e])\"\n    using assms(2) b_e_typing.intros(5,6,8,9)\n    unfolding arity_2_result_def\n    by fastforce\n  ultimately\n  show ?thesis\n    using b_e_check_single_type_not_bot_sound[OF _ assms(4,5,3)]\n    by fastforce\nqed\n\nlemma b_e_type_checker_sound:\n  assumes \"b_e_type_checker \\<C> es (tn _> tm)\"\n  shows \"\\<C> \\<turnstile> es : (tn _> tm)\"\nproof -\n  fix e tn'\n  have \"b_e_type_checker \\<C> es (tn _> tm) \\<Longrightarrow>\n          \\<C> \\<turnstile> es : (tn _> tm)\"\n  and \"\\<And>tm' tm.\n       check \\<C> es tn' = tm' \\<Longrightarrow>\n       c_types_agree tm' tm \\<Longrightarrow>\n         \\<exists>tn. c_types_agree tn' tn \\<and> \\<C> \\<turnstile> es : (tn _> tm)\"\n  and \"\\<And>tm' tm.\n       check_single \\<C> e tn' = tm' \\<Longrightarrow>\n       c_types_agree tm' tm \\<Longrightarrow>\n       tn' \\<noteq> Bot \\<Longrightarrow>\n       tm' \\<noteq> Bot \\<Longrightarrow>\n         \\<exists>tn. c_types_agree tn' tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\n  proof (induction rule: b_e_type_checker_check_check_single.induct)\n    case (1 \\<C> es tn' tm)\n    thus ?case\n      by simp\n  next\n    case (2 \\<C> es' ts)\n    show ?case\n    proof (cases es')\n      case Nil\n      thus ?thesis\n        using 2(5,6)\n        by (simp add: b_e_type_empty)\n    next\n      case (Cons e es)\n        thus ?thesis\n        proof (cases ts)\n        case (TopType x1)\n        have check_expand:\"check \\<C> es (check_single \\<C> e ts) = tm'\"\n          using 2(5,6) TopType Cons\n          by simp\n        obtain ts' where ts'_def:\"check_single \\<C> e ts = ts'\"\n          by blast\n        obtain t_int where t_int_def:\"\\<C> \\<turnstile> es : (t_int _> tm)\"\n                                     \"c_types_agree ts' t_int\"\n          using 2(2)[OF Cons TopType check_expand 2(6)] ts'_def\n          by blast\n        obtain t_int' where \"c_types_agree ts t_int'\" \"\\<C> \\<turnstile> [e] : (t_int' _> t_int)\"\n          using 2(1)[OF Cons _ ts'_def] TopType c_types_agree.simps(3) t_int_def(2)\n          by blast\n        thus ?thesis\n          using t_int_def(1) b_e_type_comp_conc Cons\n          by fastforce\n      next\n        case (Type x2)\n        have check_expand:\"check \\<C> es (check_single \\<C> e ts) = tm'\"\n          using 2(5,6) Type Cons\n          by simp\n        obtain ts' where ts'_def:\"check_single \\<C> e ts = ts'\"\n          by blast\n        obtain t_int where t_int_def:\"\\<C> \\<turnstile> es : (t_int _> tm)\"\n                                     \"c_types_agree ts' t_int\"\n          using 2(4)[OF Cons Type check_expand 2(6)] ts'_def\n          by blast\n        obtain t_int' where \"c_types_agree ts t_int'\" \"\\<C> \\<turnstile> [e] : (t_int' _> t_int)\"\n          using 2(3)[OF Cons _ ts'_def] Type c_types_agree.simps(3) t_int_def(2)\n          by blast\n        thus ?thesis\n          using t_int_def(1) b_e_type_comp_conc Cons\n          by fastforce\n      next\n        case Bot\n        then show ?thesis\n          using 2(5,6) Cons\n          by auto\n      qed\n    qed\n  next\n    case (3 \\<C> v ts)\n    hence \"type_update ts [] (Type [typeof v]) = tm'\"\n      by simp\n    moreover\n    have \"\\<C> \\<turnstile> [C v] : ([] _> [typeof v])\"\n      using b_e_typing.intros(1)\n      by blast\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 3(3,4,2)]\n      by (metis list.simps(8) to_ct_list_def)\n  next\n    case (4 \\<C> t uu ts)\n    hence \"is_int_t t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_unop_testop_cvtop 4\n      by fastforce\n  next\n    case (5 \\<C> t uv ts)\n    hence \"is_float_t t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_unop_testop_cvtop 5\n      by fastforce\n  next\n    case (6 \\<C> t uw ts)\n    hence \"is_int_t t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_unop_testop_cvtop 6\n      by fastforce\n  next\n    case (7 \\<C> t ux ts)\n    hence \"is_int_t t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_binop_relop 7\n      by fastforce\n  next\n    case (8 \\<C> t uy ts)\n    hence \"is_float_t t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_binop_relop 8\n      by fastforce\n  next\n    case (9 \\<C> t uz ts)\n    hence \"is_int_t t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_unop_testop_cvtop 9\n      by fastforce\n  next\n    case (10 \\<C> t va ts)\n    hence \"is_int_t t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_binop_relop 10\n      by fastforce\n  next\n    case (11 \\<C> t vb ts)\n    hence \"is_float_t t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_binop_relop 11\n      by fastforce\n  next\n    case (12 \\<C> t1 t2 sx ts)\n    hence \"convert_cond t1 t2 sx\"\n      by (simp del: convert_cond.simps, meson)\n    thus ?case\n      using b_e_check_single_sound_unop_testop_cvtop 12\n      by fastforce\n  next\n    case (13 \\<C> t1 t2 sx ts)\n    hence \"convert_cond t1 t2 sx\"\n      by (simp del: convert_cond.simps, meson)\n    thus ?case\n      using b_e_check_single_sound_unop_testop_cvtop 13\n      by fastforce\n  next\n    case (14 \\<C> t1 t2 sx ts)\n    hence \"t1 \\<noteq> t2 \\<and>  t_length t1 = t_length t2 \\<and> sx = None\"\n      by (simp, presburger)\n    thus ?case\n      using b_e_check_single_sound_unop_testop_cvtop 14\n      by fastforce\n  next\n    case (15 \\<C> ts)\n    thus ?case\n      using b_e_typing.intros(13) c_types_agree_not_bot_exists\n      by blast\n  next\n    case (16 \\<C> ts)\n    thus ?case\n      using b_e_typing.intros(14,39)\n      by fastforce\n  next\n    case (17 \\<C> ts)\n    thus ?case\n    proof (cases ts)\n      case (TopType x1)\n      thus ?thesis\n        proof (cases x1 rule: List.rev_cases)\n          case Nil\n          have \"\\<C> \\<turnstile> [Drop] : (tm@[T_i32] _> tm)\"\n            using b_e_typing.intros(15,39)\n            by fastforce\n          thus ?thesis\n            using c_types_agree_top1 Nil TopType\n            by fastforce\n        next\n          case (snoc ys y)\n            hence temp1:\"(consume (TopType (ys@[y])) [TAny]) = tm'\"\n              using 17 TopType type_update_empty\n              by (metis check_single.simps(15))\n            hence temp2:\"c_types_agree (TopType ys) tm\"\n              using consume_top_geq[OF temp1] 17(2,3,4)\n              by (metis Suc_leI add_diff_cancel_right' append_eq_conv_conj consume.simps(2)\n                        ct_suffix_def length_Cons length_append list.size(3) trans_le_add2\n                        zero_less_Suc)\n            obtain t where \"ct_list_eq [y] (to_ct_list [t])\"\n              using ct_list_eq_exists\n              unfolding ct_list_eq_def to_ct_list_def list_all2_map2\n              by (metis list_all2_Cons1 list_all2_Nil)\n            hence \"c_types_agree ts (tm@[t])\"\n              using temp2 ct_suffix_extend_ct_list_eq snoc TopType\n              by (simp add: to_ct_list_def)\n            thus ?thesis\n              using b_e_typing.intros(15,39)\n              by fastforce\n        qed\n    next\n      case (Type x2)\n      thus ?thesis\n      proof (cases x2 rule: List.rev_cases)\n        case Nil\n        hence \"(consume (Type []) [TAny]) = tm'\"\n          using 17 Type type_update_empty\n          by fastforce\n        thus ?thesis\n          using 17(4) ct_list_eq_def ct_suffix_def to_ct_list_def\n          by simp\n      next\n        case (snoc ys y)\n            hence temp1:\"(consume (Type (ys@[y])) [TAny]) = tm'\"\n              using 17 Type type_update_empty\n              by (metis check_single.simps(15))\n            hence temp2:\"c_types_agree (Type ys) tm\"\n              using 17(2,3,4) ct_suffix_def\n              by (simp, metis One_nat_def butlast_conv_take butlast_snoc c_types_agree.simps(1)\n                              length_Cons list.size(3))\n            obtain t where \"ct_list_eq [TSome y] (to_ct_list [t])\"\n              using ct_list_eq_exists\n              unfolding ct_list_eq_def to_ct_list_def list_all2_map2\n              by (metis list_all2_Cons1 list_all2_Nil)\n            hence \"c_types_agree ts (tm@[t])\"\n              using temp2 ct_suffix_extend_ct_list_eq snoc Type\n              by (simp add: ct_list_eq_def to_ct_list_def)\n            thus ?thesis\n              using b_e_typing.intros(15,39)\n              by fastforce\n      qed\n    qed simp\n  next\n    case (18 \\<C> ts)\n    thus ?case\n    proof (cases ts)\n      case (TopType x1)\n      consider\n          (1) \"length x1 = 0\"\n        | (2) \"length x1 = 1\"\n        | (3) \"length x1 = 2\"\n        | (4) \"length x1 \\<ge> 3\"\n        by linarith\n      thus ?thesis\n      proof (cases)\n        case 1\n        hence \"tm' = TopType [TAny]\"\n          using TopType 18\n          by simp\n        then obtain t'' tm'' where tm_def:\"tm = tm''@[t'']\"\n          using 18(2) ct_suffix_def\n          by (simp, metis Nil_is_append_conv append_butlast_last_id checker_type.inject(1)\n                          ct_prefixI ct_prefix_nil(2) produce.simps(1) produce_nil)\n        have \"\\<C> \\<turnstile> [Select] : ([t'',t'',T_i32] _> [t''])\"\n          using b_e_typing.intros(16)\n          by blast\n        thus ?thesis\n          using TopType 18 1 tm_def b_e_typing.intros(39) c_types_agree.simps(2) c_types_agree_top1\n          by fastforce\n      next\n        case 2\n        have \"type_update_select (TopType x1) = tm'\"\n          using 18 TopType\n          unfolding check_single.simps\n          by simp\n        hence x1_def:\"ct_list_eq x1 [TSome T_i32]\" \"tm' = TopType [TAny]\"\n          using type_update_select_length1[OF _ 2 18(4)]\n          by simp_all\n        then obtain t'' tm'' where tm_def:\"tm = tm''@[t'']\"\n          using 18(2) ct_suffix_def\n          by (metis Nil_is_append_conv append_butlast_last_id c_types_agree.simps(2) ct_prefixI\n                    ct_prefix_nil(2) list.simps(8) to_ct_list_def)\n        have \"c_types_agree (TopType x1) ((tm''@[t'',t''])@[T_i32])\"\n          using x1_def(1)\n          by (metis c_types_agree_top2 list.simps(8,9) to_ct_list_def)\n        thus ?thesis\n          using TopType b_e_typing.intros(16,39) tm_def\n          by auto\n      next\n        case 3\n        have \"type_update_select (TopType x1) = tm'\"\n          using 18 TopType\n          unfolding check_single.simps\n          by simp\n        then obtain ct1 ct2 where x1_def:\"x1 = [ct1, ct2]\"\n                                         \"ct_eq ct2 (TSome T_i32)\"\n                                         \"tm' = TopType [ct1]\"\n          using type_update_select_length2[OF _ 3 18(4)]\n          by blast\n        then obtain t'' tm'' where tm_def:\"tm = tm''@[t'']\"\n                                          \"ct_list_eq [ct1] [(TSome t'')]\"\n          using 18(2) c_types_agree_imp_ct_list_eq[of \"[ct1]\" tm]\n          by (metis append_Nil2 append_butlast_last_id append_eq_append_conv_if append_eq_conv_conj\n                    ct_list_eq_length diff_Suc_1 length_Cons length_butlast length_map\n                    list.simps(8,9) list.size(3) nat.distinct(2) to_ct_list_def)\n        hence \"ct_list_eq x1 (to_ct_list [ t'', T_i32])\"\n          using x1_def(1,2)\n          unfolding ct_list_eq_def to_ct_list_def\n          by fastforce\n        hence \"c_types_agree (TopType x1) ((tm''@[t''])@[t'',T_i32])\"\n          using c_types_agree_top2\n          by blast\n        thus ?thesis\n          using TopType b_e_typing.intros(16,39) tm_def\n          by auto\n      next\n        case 4\n        then obtain nat where nat_def:\"length x1 = Suc (Suc (Suc nat))\"\n          by (metis add_eq_if diff_Suc_1 le_Suc_ex numeral_3_eq_3 nat.distinct(2))\n        hence tm'_def:\"type_update_select (TopType x1) = tm'\"\n          using 18 TopType\n          by simp\n        then obtain tm_int where \"(select_return_top x1\n                                    (x1 ! (length x1 - 2))\n                                    (x1 ! (length x1 - 3))) = tm_int\"\n                                 \"tm_int \\<noteq> Bot\"\n          using nat_def 18(4)\n          unfolding type_update_select.simps\n          by fastforce\n        then obtain x2 where x2_def:\"(select_return_top x1\n                                       (x1 ! (length x1 - 2))\n                                       (x1 ! (length x1 - 3))) = TopType x2\"\n          using select_return_top_exists\n          by fastforce\n        have \"ct_suffix x1 [TAny, TAny, TSome T_i32] \\<or> ct_suffix [TAny, TAny, TSome T_i32] x1\"\n          using tm'_def nat_def 18(4)\n          by (simp, metis (full_types) produce.simps(6))\n        hence tm'_eq:\"tm' = TopType x2\"\n          using tm'_def nat_def 18(4) x2_def\n          by force\n        then obtain cts' ct1 ct2 ct3 where cts'_def:\"x1 = cts'@[ct1, ct2, ct3]\"\n                                                    \"ct_eq ct3 (TSome T_i32)\"\n          using type_update_select_length3 tm'_def 4\n          by blast\n        then obtain c' cm' where tm_def:\"tm = cm'@[c']\"\n                                        \"ct_suffix cts' (to_ct_list cm')\"\n                                        \"ct_eq (x1 ! (length x1 - 2)) (TSome c')\"\n                                        \"ct_eq (x1 ! (length x1 - 3)) (TSome c')\"\n          using select_return_top_ct_eq[OF x2_def 4] tm'_eq 4 18(2)\n          by fastforce\n        then obtain as bs where cm'_def:\"cm' = as@bs\"\n                                        \"ct_list_eq (to_ct_list bs) cts'\"\n          using ct_list_eq_cons_ct_list1 ct_list_eq_ts_conv_eq\n          by (metis ct_suffix_def to_ct_list_append(2))\n        hence \"ct_eq ct1 (TSome c')\"\n              \"ct_eq ct2 (TSome c')\"\n          using cts'_def tm_def\n          apply simp_all\n          apply (metis append.assoc append_Cons append_Nil length_append_singleton nth_append_length)\n          done\n        hence \"c_types_agree ts (cm'@[c',c',T_i32])\"\n          using c_types_agree_top2[of _ _ as] cm'_def(1) TopType\n                ct_list_eq_concat[OF ct_list_eq_commute[OF cm'_def(2)]] cts'_def\n          unfolding to_ct_list_def ct_list_eq_def\n          by fastforce\n        thus ?thesis\n          using b_e_typing.intros(16,39) tm_def\n          by auto\n      qed\n    next\n      (* TODO: refactor *)\n      case (Type x2)\n      hence x2_cond:\"(length x2 \\<ge> 3 \\<and> (x2!(length x2-2)) = (x2!(length x2-3)))\"\n        using 18\n        by (simp, meson)\n      hence tm'_def:\"consume (Type x2) [TAny, TSome T_i32] = tm'\"\n        using 18 Type\n        by simp\n      obtain ts' ts'' where cts_def:\"x2 = ts'@ ts''\" \"length ts'' = 3\"\n        using x2_cond\n        by (metis append_take_drop_id diff_diff_cancel length_drop)\n      then obtain t1 ts''2 where \"ts'' = t1#ts''2\" \"length ts''2 = Suc (Suc 0)\"\n        using List.length_Suc_conv[of ts' \"Suc (Suc 0)\"]\n        by (metis length_Suc_conv numeral_3_eq_3)\n      then obtain t2 t3 where \"ts'' = [t1,t2,t3]\"\n        using List.length_Suc_conv[of ts''2 \"Suc 0\"]\n        by (metis length_0_conv length_Suc_conv)\n      hence cts_def2:\"x2 = ts'@ [t1,t2,t3]\"\n        using cts_def\n        by simp\n      have ts'_suffix:\"ct_suffix [TAny, TSome T_i32] (to_ct_list (ts' @ [t1, t2, t3]))\"\n        using tm'_def 18(4)\n        by (simp, metis cts_def2)\n      hence tm'_def:\"tm' = Type (ts'@[t1])\"\n        using tm'_def 18(4) cts_def2\n        by simp\n      obtain as bs where \"(to_ct_list (ts' @ [t1])) @ (to_ct_list ([t2, t3])) = as@bs\"\n                         \"ct_list_eq bs [TAny, TSome T_i32]\"\n        using ts'_suffix\n        unfolding ct_suffix_def to_ct_list_def\n        by fastforce\n      hence \"t3 = T_i32\"\n        unfolding to_ct_list_def ct_list_eq_def\n        by (metis (no_types, lifting) Nil_is_map_conv append_eq_append_conv ct_eq.simps(1)\n                  length_Cons list.sel(1,3) list.simps(9) list_all2_Cons2 list_all2_lengthD)\n      moreover\n      have \"t1 = t2\"\n        using x2_cond cts_def2\n        by (simp, metis append.left_neutral append_Cons append_assoc length_append_singleton\n                        nth_append_length)\n      ultimately\n      have \"c_types_agree (Type x2) ((ts'@[t1,t1])@[T_i32])\"\n        using cts_def2\n        by simp\n      thus ?thesis\n        using b_e_typing.intros(16,39) Type tm'_def 18(2)\n        by fastforce\n    qed simp\n  next\n    case (19 \\<C> tn'' tm'' es ts)\n    hence \"type_update ts (to_ct_list tn'') (Type tm'') = tm'\"\n      by auto\n    moreover\n    have \"(b_e_type_checker (\\<C>\\<lparr>label := ([tm''] @ (label \\<C>))\\<rparr>) es (tn'' _> tm''))\"\n      using 19\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Block (tn'' _> tm'') es] : (tn'' _> tm'')\"\n      using b_e_typing.intros(17)[OF _ 19(1)]\n      by blast\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 19(4,5,3)]\n      by blast\n  next\n    case (20 \\<C> tn'' tm'' es ts)\n    hence \"type_update ts (to_ct_list tn'') (Type tm'') = tm'\"\n      by auto\n    moreover\n    have \"(b_e_type_checker (\\<C>\\<lparr>label := ([tn''] @ (label \\<C>))\\<rparr>) es (tn'' _> tm''))\"\n      using 20\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Loop (tn'' _> tm'') es] : (tn'' _> tm'')\"\n      using b_e_typing.intros(18)[OF _ 20(1)]\n      by blast\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 20(4,5,3)]\n      by blast\n  next\n    case (21 \\<C> tn'' tm'' es1 es2 ts)\n    hence \"type_update ts (to_ct_list (tn''@[T_i32])) (Type tm'') = tm'\"\n      by auto\n    moreover\n    have \"(b_e_type_checker (\\<C>\\<lparr>label := ([tm''] @ (label \\<C>))\\<rparr>) es1 (tn'' _> tm''))\"\n         \"(b_e_type_checker (\\<C>\\<lparr>label := ([tm''] @ (label \\<C>))\\<rparr>) es2 (tn'' _> tm''))\"\n      using 21\n      by (simp, meson)+\n    hence \"\\<C> \\<turnstile> [If (tn'' _> tm'') es1 es2] : (tn''@[T_i32] _> tm'')\"\n      using b_e_typing.intros(19)[OF _ 21(1,2)]\n      by blast\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 21(5,6,4)]\n      by blast\n  next\n    case (22 \\<C> i ts)\n    hence \"type_update ts (to_ct_list ((label \\<C>)!i)) (TopType []) = tm'\"\n      by auto\n    moreover\n    have \"i < length (label \\<C>)\"\n      using 22\n      by (simp, meson)\n    ultimately\n    show ?case\n      using b_e_check_single_top_not_bot_sound[OF _ 22(3,4)]\n            b_e_typing.intros(20,37)\n      by (metis suffix_def)\n  next\n    case (23 \\<C> i ts)\n    hence \"type_update ts (to_ct_list ((label \\<C>)!i @ [T_i32])) (Type ((label \\<C>)!i)) = tm'\"\n      by auto\n    moreover\n    have \"i < length (label \\<C>)\"\n      using 23\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Br_if i] : ((label \\<C>)!i @ [T_i32] _> (label \\<C>)!i)\"\n      using b_e_typing.intros(21)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 23(3,4,2)]\n      by fastforce\n  next\n    case (24 \\<C> \"is\" i ts)\n    then obtain tls where tls_def:\"(same_lab (is@[i]) (label \\<C>)) = Some tls\"\n      by fastforce\n    hence \"type_update ts (to_ct_list (tls @ [T_i32])) (TopType []) = tm'\"\n      using 24\n      by simp\n    thus ?case\n      using b_e_check_single_top_not_bot_sound[OF _ 24(3,4)]\n            b_e_typing.intros(22)[OF same_lab_conv_list_all[OF tls_def]]\n            b_e_typing.intros(37)\n      by (metis suffix_def)\n  next\n    case (25 \\<C> ts)\n    then obtain ts_r where \"(return \\<C>) = Some ts_r\"\n      by fastforce\n    moreover\n    hence \"type_update ts (to_ct_list ts_r) (TopType []) = tm'\"\n      using 25\n      by simp\n    ultimately\n    show ?case\n      using b_e_check_single_top_not_bot_sound[OF _ 25(3,4)]\n            b_e_typing.intros(23,37)\n      by (metis suffix_def)\n  next\n    case (26 \\<C> i ts)\n    obtain tn'' tm'' where func_def:\"(func_t \\<C>)!i = (tn'' _> tm'')\"\n      using tf.exhaust\n      by blast\n    hence \"type_update ts (to_ct_list tn'') (Type tm'') = tm'\"\n      using 26\n      by auto\n    moreover\n    have \"i < length (func_t \\<C>)\"\n      using 26\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Call i] : (tn'' _> tm'')\"\n      using b_e_typing.intros(24) func_def\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 26(3,4,2)]\n      by fastforce\n  next\n    case (27 \\<C> i ts)\n    obtain tn'' tm'' where type_def:\"(types_t \\<C>)!i = (tn'' _> tm'')\"\n      using tf.exhaust\n      by blast\n    hence \"type_update ts (to_ct_list (tn''@[T_i32])) (Type tm'') = tm'\"\n      using 27\n      by auto\n    moreover\n    have \"(table \\<C>) \\<noteq> None \\<and> i < length (types_t \\<C>)\"\n      using 27\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Call_indirect i] : (tn''@[T_i32] _> tm'')\"\n      using b_e_typing.intros(25) type_def\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 27(3,4,2)]\n      by fastforce\n  next\n    case (28 \\<C> i ts)\n    then have length_def:\"i < length (func_t \\<C>)\"\n      using 28\n      by (simp, meson)\n    then obtain tn'' tm'' where func_def:\"(func_t \\<C>)!i = (tn'' _> tm'')\"\n      using tf.exhaust 28 length_def\n      by (simp, meson)\n    hence return_def:\"(return \\<C>) = Some tm''\"\n      using 28 length_def\n      by (simp, meson)\n    moreover\n    hence \"type_update ts (to_ct_list tn'') (TopType []) = tm'\"\n      using 28 return_def func_def length_def\n      by simp\n    ultimately\n    show ?case\n      using b_e_check_single_top_not_bot_sound[OF _ 28(3,4)]\n            b_e_typing.intros(26,37) return_def func_def length_def\n      by (metis suffix_def)\n  next\n    case (29 \\<C> i ts)\n    obtain tn'' tm'' where type_def:\"(types_t \\<C>)!i = (tn'' _> tm'')\"\n      using tf.exhaust\n      by blast\n    moreover\n    have length_def:\"(table \\<C>) \\<noteq> None \\<and> i < length (types_t \\<C>)\"\n      using 29\n      by (simp, meson)\n    hence return_def:\"(return \\<C>) = Some tm''\"\n      using 29 type_def\n      by (simp, meson)\n    moreover\n    hence \"type_update ts (to_ct_list (tn''@[T_i32])) (TopType []) = tm'\"\n      using 29 length_def type_def return_def\n      by auto\n    ultimately\n    show ?case\n      using b_e_check_single_top_not_bot_sound[OF _ 29(3,4)]\n            b_e_typing.intros(27,37) return_def length_def type_def\n      by (metis suffix_def)\n  next\n    case (30 \\<C> i ts)\n    hence \"type_update ts [] (Type [(local \\<C>)!i]) = tm'\"\n      by auto\n    moreover\n    have \"i < length (local \\<C>)\"\n      using 30\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Get_local i] : ([] _> [(local \\<C>)!i])\"\n      using b_e_typing.intros(28)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 30(3,4,2)]\n      unfolding to_ct_list_def\n      by (metis list.map_disc_iff)\n  next\n    case (31 \\<C> i ts)\n    hence \"type_update ts (to_ct_list [(local \\<C>)!i]) (Type []) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"i < length (local \\<C>)\"\n      using 31\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Set_local i] : ([(local \\<C>)!i] _> [])\"\n      using b_e_typing.intros(29)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 31(3,4,2)]\n      by fastforce\n  next\n    case (32 \\<C> i ts)\n    hence \"type_update ts (to_ct_list [(local \\<C>)!i]) (Type [(local \\<C>)!i]) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"i < length (local \\<C>)\"\n      using 32\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Tee_local i] : ([(local \\<C>)!i] _> [(local \\<C>)!i])\"\n      using b_e_typing.intros(30)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 32(3,4,2)]\n      by fastforce\n  next\n    case (33 \\<C> i ts)\n    hence \"type_update ts [] (Type [tg_t ((global \\<C>)!i)]) = tm'\"\n      by auto\n    moreover\n    have \"i < length (global \\<C>)\"\n      using 33\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Get_global i] : ([] _> [tg_t ((global \\<C>)!i)])\"\n      using b_e_typing.intros(31)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 33(3,4,2)]\n      unfolding to_ct_list_def\n      by (metis list.map_disc_iff)\n  next\n    case (34 \\<C> i ts)\n    hence \"type_update ts (to_ct_list [tg_t ((global \\<C>)!i)]) (Type []) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"i < length (global \\<C>) \\<and> is_mut (global \\<C> ! i)\"\n      using 34\n      by (simp, meson)\n    then obtain t where \"(global \\<C> ! i) = \\<lparr>tg_mut = T_mut, tg_t = t\\<rparr>\" \"i < length (global \\<C>)\"\n      unfolding is_mut_def\n      by (cases \"global \\<C> ! i\", auto)\n    hence \"\\<C> \\<turnstile> [Set_global i] : ([tg_t (global \\<C> ! i)] _> [])\"\n      using b_e_typing.intros(32)[of i \\<C> \"tg_t (global \\<C> ! i)\"]\n      unfolding is_mut_def tg_t_def\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 34(3,4,2)]\n      by fastforce\n  next\n    case (35 \\<C> t tp_sx a off ts)\n    hence \"type_update ts (to_ct_list [T_i32]) (Type [t]) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"(memory \\<C>) \\<noteq> None \\<and> load_store_t_bounds a (option_projl tp_sx) t\"\n      using 35\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Load t tp_sx a off] : ([T_i32] _> [t])\"\n      using b_e_typing.intros(33)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 35(3,4,2)]\n      by fastforce\n  next\n    case (36 \\<C> t tp a off ts)\n    hence \"type_update ts (to_ct_list [T_i32,t]) (Type []) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"(memory \\<C>) \\<noteq> None \\<and> load_store_t_bounds a tp t\"\n      using 36\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Store t tp a off] : ([T_i32,t] _> [])\"\n      using b_e_typing.intros(34)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 36(3,4,2)]\n      by fastforce\n  next\n    case (37 \\<C> ts)\n    hence \"type_update ts [] (Type [T_i32]) = tm'\"\n      by auto\n    moreover\n    have \"memory \\<C> \\<noteq> None\"\n      using 37\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Current_memory] : ([] _> [T_i32])\"\n      using b_e_typing.intros(35)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 37(3,4,2)]\n      unfolding to_ct_list_def\n      by (metis list.map_disc_iff)\n  next\n    case (38 \\<C> ts)\n    hence \"type_update ts (to_ct_list [T_i32]) (Type [T_i32]) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"memory \\<C> \\<noteq> None\"\n      using 38\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Grow_memory] : ([T_i32] _> [T_i32])\"\n      using b_e_typing.intros(36)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 38(3,4,2)]\n      by fastforce\n  qed\n  thus ?thesis\n    using assms\n    by simp\nqed\n\nsubsection \\<open>Completeness\\<close>\n\nlemma check_single_imp:\n  assumes \"check_single \\<C> e ctn = ctm\"\n          \"ctm \\<noteq> Bot\"\n  shows \"check_single \\<C> e = id\n         \\<or> check_single \\<C> e = (\\<lambda>ctn. type_update_select ctn)\n         \\<or> (\\<exists>cons prods. (check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)))\"\nproof -\n  have True\n  and True\n  and \"check_single \\<C> e ctn = ctm \\<Longrightarrow>\n       ctm \\<noteq> Bot \\<Longrightarrow>\n         ?thesis\"\n  proof (induction rule: b_e_type_checker_check_check_single.induct)\n    case (1 \\<C> es tn tm)\n    thus ?case\n      by simp\n  next\n    case (2 \\<C> es ts)\n    thus ?case\n      by simp\n  next\n    case (3 \\<C> v ts)\n    thus ?case\n      by fastforce\n  next\n    case (4 \\<C> t uu ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (5 \\<C> t uv ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (6 \\<C> t uw ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (7 \\<C> t ux ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (8 \\<C> t uy ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (9 \\<C> t uz ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (10 \\<C> t va ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (11 \\<C> t va ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (12 \\<C> t1 t2 sx ts)\n    thus ?case\n      by (simp del: convert_cond.simps, meson assms(2) type_update.simps)\n  next\n  next\n    case (13 \\<C> t1 t2 sx ts)\n    thus ?case\n      by (simp del: convert_cond.simps, meson assms(2) type_update.simps)\n  next\n    case (14 \\<C> t1 t2 sx ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (15 \\<C> ts)\n    thus ?case\n      by fastforce\n  next\n    case (16 \\<C> ts)\n    thus ?case\n      by fastforce\n  next\n    case (17 \\<C> ts)\n    thus ?case\n      by fastforce\n  next\n    case (18 \\<C> ts)\n    thus ?case\n      by fastforce\n  next\n    case (19 \\<C> tn tm es ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (20 \\<C> tn tm es ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (21 \\<C> tn tm es1 es2 ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (22 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (23 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (24 \\<C> \"is\" ts)\n    thus ?case\n      by (simp, metis assms(2) option.case_eq_if type_update.simps)\n  next\n    case (25 \\<C> ts)\n    thus ?case\n      by (simp, metis assms(2) option.case_eq_if type_update.simps)\n  next\n    case (26 \\<C> i ts)\n    thus ?case\n      by (simp, metis (no_types, lifting) assms(2) tf.case tf.exhaust type_update.simps)\n  next\n    case (27 \\<C> i ts)\n    thus ?case\n      by (simp, metis (no_types, lifting) assms(2) tf.case tf.exhaust type_update.simps)\n  next\n    case (28 \\<C> i ts)\n    then have length_def:\"i < length (func_t \\<C>)\"\n      using assms(2)\n      by (simp, meson)\n    then obtain tn'' tm'' where func_def:\"(func_t \\<C>)!i = (tn'' _> tm'')\"\n      using tf.exhaust 28 length_def\n      by (simp, meson)\n    hence return_def:\"(return \\<C>) = Some tm''\"\n      using assms(2) length_def 28\n      by (simp, meson)\n    moreover\n    hence \"check_single \\<C> (ReturnCall i) ctn = (type_update ctn (to_ct_list tn'') (TopType []))\"\n      using 28(1) return_def func_def length_def assms(2)\n      by simp\n    thus ?case\n      using 28(1) return_def func_def length_def assms(2)\n      by (simp, metis)\n  next\n    case (29 \\<C> i ts)\n    obtain tn'' tm'' where type_def:\"(types_t \\<C>)!i = (tn'' _> tm'')\"\n      using tf.exhaust\n      by blast\n    moreover\n    have length_def:\"(table \\<C>) \\<noteq> None \\<and> i < length (types_t \\<C>)\"\n      using assms(2) 29\n      by (simp, meson)\n    hence return_def:\"(return \\<C>) = Some tm''\"\n      using 29 type_def assms(2)\n      by (simp, meson)\n    moreover\n    hence \"check_single \\<C> (ReturnCall_indirect i) ctn = type_update ctn (to_ct_list (tn''@[T_i32])) (TopType [])\"\n      using 29 length_def type_def return_def assms(2)\n      by auto\n    thus ?case\n      using 29(1) return_def length_def assms(2) type_def\n      by (simp, metis)\n  next\n    case (30 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (31 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (32 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (33 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (34 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (35 \\<C> t tp_sx a off ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (36 \\<C> t tp a off ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (37 \\<C> ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (38 \\<C> ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  qed\n  thus ?thesis\n    using assms\n    by simp\nqed\n\nlemma check_equiv_fold:\n  \"check \\<C> es ts = foldl (\\<lambda> ts e. (case ts of Bot \\<Rightarrow> Bot | _ \\<Rightarrow> check_single \\<C> e ts)) ts es\"\nproof (induction es arbitrary: ts)\n  case Nil\n  thus ?case\n    by simp\nnext\n  case (Cons e es)\n  obtain ts' where ts'_def:\"check \\<C> (e # es) ts = ts'\"\n    by blast\n  show ?case\n  proof (cases \"ts = Bot\")\n    case True\n    thus ?thesis\n      using ts'_def\n      by (induction es, simp_all)\n  next\n    case False\n    thus ?thesis\n      using ts'_def Cons\n      by (cases ts, simp_all)\n  qed\nqed\n\nlemma check_neq_bot_snoc:\n  assumes \"check \\<C> (es@[e]) ts \\<noteq> Bot\"\n  shows \"check \\<C> es ts \\<noteq> Bot\"\n  using assms\nproof (induction es arbitrary: ts)\n  case Nil\n  thus ?case\n    by (cases ts, simp_all)\nnext\n  case (Cons a es)\n  thus ?case\n    by (cases ts, simp_all)\nqed\n\nlemma check_unfold_snoc:\n  assumes \"check \\<C> es ts \\<noteq> Bot\"\n  shows \"check \\<C> (es@[e]) ts = check_single \\<C> e (check \\<C> es ts)\"\nproof -\n  obtain f where f_def:\"f = (\\<lambda> e ts. (case ts of Bot \\<Rightarrow> Bot | _ \\<Rightarrow> check_single \\<C> e ts))\"\n    by blast\n  have f_simp:\"\\<And>ts. ts \\<noteq> Bot \\<Longrightarrow> (f e ts = check_single \\<C> e ts)\"\n  proof -\n    fix ts\n    show \"ts \\<noteq> Bot \\<Longrightarrow> (f e ts = check_single \\<C> e ts)\"\n      using f_def\n      by (cases ts, simp_all)\n  qed\n  have \"check \\<C> (es@[e]) ts = foldl (\\<lambda> ts e. (case ts of Bot \\<Rightarrow> Bot | _ \\<Rightarrow> check_single \\<C> e ts)) ts (es@[e])\"\n    using check_equiv_fold\n    by simp\n  also\n  have \"... = foldr (\\<lambda> e ts. (case ts of Bot \\<Rightarrow> Bot | _ \\<Rightarrow> check_single \\<C> e ts)) (rev (es@[e])) ts\"\n    using foldl_conv_foldr\n    by fastforce\n  also\n  have \"... = f e (foldr (\\<lambda> e ts. (case ts of Bot \\<Rightarrow> Bot | _ \\<Rightarrow> check_single \\<C> e ts)) (rev es) ts)\"\n    using f_def\n    by simp\n  also\n  have \"... = f e (check \\<C> es ts)\"\n    using foldr_conv_foldl[of _ \"(rev es)\" ts] rev_rev_ident[of es] check_equiv_fold\n    by simp\n  also\n  have \"... = check_single \\<C> e (check \\<C> es ts)\"\n    using assms f_simp\n    by simp\n  finally\n  show ?thesis .\nqed\n\nlemma check_single_imp_weakening:\n  assumes \"check_single \\<C> e (Type t1s) = ctm\"\n          \"ctm \\<noteq> Bot\"\n          \"c_types_agree ctn t1s\"\n          \"c_types_agree ctm t2s\"\n  shows \"\\<exists>ctm'. check_single \\<C> e ctn = ctm' \\<and> c_types_agree ctm' t2s\"\nproof -\n  consider (1) \"check_single \\<C> e = id\"\n         | (2) \"check_single \\<C> e = (\\<lambda>ctn. type_update_select ctn)\"\n         | (3) \"(\\<exists>cons prods. (check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)))\"\n    using check_single_imp assms\n    by blast\n  thus ?thesis\n  proof (cases)\n    case 1\n    thus ?thesis\n      using assms(1,3,4)\n      by fastforce\n  next\n    (* TODO: better proof *)\n    case 2\n    note outer_2 = 2\n    hence t1s_cond:\"(length t1s \\<ge> 3 \\<and> (t1s!(length t1s-2)) = (t1s!(length t1s-3)))\"\n      using assms(1,2)\n      by (simp, meson)\n    hence ctm_def:\"ctm = consume (Type t1s) [TAny, TSome T_i32]\"\n      using assms(1,2) 2\n      by simp\n    then obtain c_t where c_t_def:\"ctm = Type c_t\"\n      using assms(2)\n      by (meson consume.simps(1))\n    hence t2s_eq:\"t2s = c_t\"\n      using assms(4)\n      by simp\n    hence t2s_len:\"length t2s > 0\"\n      using t1s_cond ctm_def c_t_def assms(2)\n      by (metis Suc_leI Suc_n_not_le_n checker_type.inject(2) consume.simps(1)\n                diff_is_0_eq dual_order.trans length_0_conv length_Cons length_greater_0_conv\n                nat.simps(3) numeral_3_eq_3 take_eq_Nil)\n    have t1s_suffix_full:\"ct_suffix [TAny, TSome T_i32] (to_ct_list t1s)\"\n      using assms(2) ctm_def ct_suffix_less\n      by (metis consume.simps(1))\n    hence t1s_suffix:\"ct_suffix [TSome T_i32] (to_ct_list t1s)\"\n      using assms(2) ctm_def ct_suffix_less\n      by (metis append_butlast_last_id last.simps list.distinct(1))\n    obtain t t1s' where t1s_suffix2:\"t1s = t1s'@[t,t,T_i32]\"\n      using type_update_select_type_length3 assms(1) c_t_def outer_2\n      by fastforce\n    hence t2s_def:\"t2s = t1s'@[t]\"\n      using ctm_def c_t_def t2s_eq t1s_suffix assms(2) t1s_suffix_full\n      by simp\n    show ?thesis\n      using assms(1,3,4)\n    proof (cases ctn)\n      case (TopType x1)\n      consider\n          (1) \"length x1 = 0\"\n        | (2) \"length x1 = 1\"\n        | (3) \"length x1 = 2\"\n        | (4) \"length x1 \\<ge> 3\"\n        by linarith\n      thus ?thesis\n      proof (cases)\n        case 1\n        hence \"check_single \\<C> e ctn = TopType [TAny]\"\n          using 2 TopType\n          by simp\n        thus ?thesis\n          using ct_suffix_singleton to_ct_list_def t2s_len\n          by auto\n      next\n        case 2\n        hence \"ct_suffix [TSome T_i32] x1\"\n          using assms(3) TopType ct_suffix_imp_ct_list_eq ct_suffix_shared t1s_suffix\n          by (metis One_nat_def append_Nil c_types_agree.simps(2) ct_list_eq_commute ct_suffix_def\n                    diff_self_eq_0 drop_0 length_Cons list.size(3))\n        hence \"check_single \\<C> e ctn = TopType [TAny]\"\n          using outer_2 TopType 2\n          by simp\n        thus ?thesis\n          using t2s_len ct_suffix_singleton\n          by (simp add: to_ct_list_def)\n      next\n        case 3\n        have \"ct_list_eq (to_ct_list t1s) (to_ct_list (t1s' @ [t, t, T_i32]))\"\n          using t1s_suffix2\n          by (simp add: ct_list_eq_ts_conv_eq)\n        hence temp1:\"to_ct_list t1s = (to_ct_list (t1s' @ [t])) @ (to_ct_list [t, T_i32])\"\n          using t1s_suffix2 to_ct_list_def\n          by simp\n        hence \"ct_suffix (to_ct_list [t, T_i32]) (to_ct_list t1s)\"\n          using ct_suffix_def[of \"(to_ct_list [t, T_i32])\" \"(to_ct_list t1s)\"]\n          by (simp add: ct_suffix_cons_it)\n        hence \"ct_suffix (to_ct_list [t, T_i32]) x1\"\n          using assms(3) TopType 3\n          by (simp, metis temp1 append_Nil ct_suffix_cons2 ct_suffix_def length_Cons length_map\n                          list.size(3) numeral_2_eq_2 to_ct_list_def)\n        hence temp3:\"ct_list_eq (to_ct_list [t, T_i32]) x1\"\n          using 3 ct_suffix_imp_ct_list_eq\n          unfolding to_ct_list_def\n          by (metis Suc_leI ct_list_eq_commute diff_is_0_eq drop_0 length_Cons length_map lessI\n                    list.size(3) numeral_2_eq_2)\n        hence temp4:\"ct_suffix [TSome T_i32] x1\"\n          using ct_suffix_less[of \"[TSome t]\" \"[TSome T_i32]\" x1]\n                ct_suffix_extend_ct_list_eq[of \"[]\" \"[]\"] ct_suffix_nil\n          unfolding to_ct_list_def\n          by fastforce\n        hence \"ct_suffix (take 1 x1) (to_ct_list [t])\"\n          using temp3 ct_suffix_nil ct_list_eq_commute ct_suffix_extend_ct_list_eq[of \"[]\" \"[]\" \"(take 1 x1)\" \"(to_ct_list [t])\"]\n          unfolding to_ct_list_def\n          by (simp, metis butlast.simps(2) butlast_conv_take ct_list_eq_take diff_Suc_1 length_Cons\n                          list.distinct(1) list.size(3))\n        thus ?thesis\n          using TopType 2 3 ct_suffix_nil temp3 temp4 t2s_def to_ct_list_def\n          apply (simp, safe)\n          apply (metis append.assoc ct_suffix_def)\n          done\n      next\n        case 4\n        then obtain nat where nat_def:\"length x1 = Suc (Suc (Suc nat))\"\n          by (metis add_eq_if diff_Suc_1 le_Suc_ex numeral_3_eq_3 nat.distinct(2))\n        obtain x1' x x' x'' where x1_split:\"x1 = x1'@[x,x',x'']\"\n        proof -\n          assume local_assms:\"(\\<And>x1' x x' x''. x1 = x1' @ [x, x', x''] \\<Longrightarrow> thesis)\"\n          obtain x1' x1'' where tn_split:\"x1 = x1'@x1''\"\n                               \"length x1'' = 3\"\n            using 4\n            by (metis append_take_drop_id diff_diff_cancel length_drop)\n          then obtain x x1''2 where \"x1'' = x#x1''2\" \"length x1''2 = Suc (Suc 0)\"\n            by (metis length_Suc_conv numeral_3_eq_3)\n          then obtain x' x'' where tn''_def:\"x1''= [x,x',x'']\"\n            using List.length_Suc_conv[of x1''2 \"Suc 0\"]\n            by (metis length_0_conv length_Suc_conv)\n          thus ?thesis\n            using tn_split local_assms\n            by simp\n        qed\n        hence a:\"ct_suffix (x1'@[x,x',x'']) (to_ct_list (t1s' @ [t, t, T_i32]))\"\n          using t1s_suffix2 assms(3) TopType\n          by simp\n        hence b:\"ct_suffix (x1'@[x,x']) (to_ct_list (t1s' @ [t, t])) \\<and> (ct_eq x'' (TSome T_i32))\"\n          using to_ct_list_def ct_suffix_unfold_one[of \"(x1'@[x,x'])\" \"x''\" \"to_ct_list (t1s' @ [t, t])\"]\n          by fastforce\n        hence c:\"ct_suffix (x1'@[x]) (to_ct_list (t1s' @ [t])) \\<and> (ct_eq x' (TSome t))\"\n          using to_ct_list_def ct_suffix_unfold_one[of \"(x1'@[x])\" \"x'\" \"to_ct_list (t1s' @ [t])\"]\n          by fastforce\n        hence d:\"ct_suffix x1' (to_ct_list t1s') \\<and> (ct_eq x (TSome t))\"\n          using to_ct_list_def ct_suffix_unfold_one[of \"(x1')\" \"x\" \"to_ct_list (t1s')\"]\n          by fastforce\n        have \"(take (length x1 - 3) x1) = x1'\"\n          using x1_split\n          by simp\n        have x'_ind:\"(x1!(length x1-2)) = x'\"\n          using x1_split List.nth_append_length[of \"x1' @ [x]\"]\n          by simp\n        have x_ind:\"(x1!(length x1-3)) = x\"\n          using x1_split\n          by simp\n        have \"ct_suffix [TSome T_i32] x1\"\n          using b x1_split ct_suffix_def ct_list_eq_def ct_suffixI[of x1 \"x1' @ [x, x']\"]\n          by simp\n        hence \"check_single \\<C> e (TopType x1) = (select_return_top x1 (x1!(length x1-2)) (x1!(length x1-3)))\"\n          using type_update_select_conv_select_return_top[OF _ 4]\n          unfolding 2\n          by blast\n        moreover\n        have \"... = (TopType (x1'@[x])) \\<or> ... = (TopType (x1'@[x']))\"\n          apply (cases x; cases x')\n          using x1_split 4 nat_def 2 x_ind x'_ind c d\n          by simp_all\n        moreover\n        have \"ct_suffix (x1'@[x]) (to_ct_list t2s)\"\n          by (simp add: c t2s_def)\n        moreover\n        have \"ct_suffix (x1'@[x']) (to_ct_list t2s)\"\n          using ct_suffix_unfold_one[symmetric, of x' \"(TSome t)\" x1' \"(to_ct_list t1s')\"] c d\n                t2s_def\n          unfolding to_ct_list_def\n          by fastforce\n        ultimately\n        show ?thesis\n          using TopType\n          by auto\n      qed\n    qed simp_all\n  next\n    case 3\n    then obtain cons prods where c_s_def:\"check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)\"\n      by blast\n    hence ctm_def:\"ctm = type_update (Type t1s) cons prods\"\n      using assms(1)\n      by fastforce\n    hence cons_suffix:\"ct_suffix cons (to_ct_list t1s)\"\n      using assms\n      by (simp, metis (full_types) produce.simps(6))\n    hence t_int_def:\"consume (Type t1s) cons = (Type (take (length t1s - length cons) t1s))\"\n      using ctm_def\n      by simp\n    hence ctm_def2:\"ctm = produce (Type (take (length t1s - length cons) t1s)) prods\"\n      using ctm_def\n      by simp\n    show ?thesis\n    proof (cases ctn)\n      case (TopType x1)\n      hence \"ct_suffix x1 (to_ct_list t1s)\"\n        using assms(3)\n        by simp\n      thus ?thesis\n        using assms(2) ctm_def2\n      proof (cases prods)\n        case (TopType x1)\n        thus ?thesis\n          using consume_c_types_agree[OF t_int_def assms(3)] ctm_def2 assms(4) c_s_def\n          by (metis c_types_agree.elims(2) produce.simps(3,4) type_update.simps)\n      next\n        case (Type x2)\n        hence ctm_def3:\"ctm = Type ((take (length t1s - length cons) t1s)@ x2)\"\n          using ctm_def2\n          by simp\n        have \"ct_suffix x1 cons \\<or> ct_suffix cons x1\"\n          using ct_suffix_shared assms(3) TopType cons_suffix\n          by auto\n        thus ?thesis\n        proof (rule disjE)\n          assume \"ct_suffix x1 cons\"\n          hence \"consume (TopType x1) cons = TopType []\"\n            by (simp add: ct_suffix_length)\n          hence \"check_single \\<C> e ctn = TopType (to_ct_list x2)\"\n            using c_s_def TopType Type\n            by simp\n          thus ?thesis\n            using TopType ctm_def3 assms(4) c_types_agree_top2 ct_list_eq_refl\n            by auto\n        next\n          assume \"ct_suffix cons x1\"\n          hence 4:\"consume (TopType x1) cons = TopType (take (length x1 - length cons ) x1)\"\n            by (simp add: ct_suffix_length)\n          hence 3:\"check_single \\<C> e ctn = TopType ((take (length x1 - length cons ) x1) @ to_ct_list x2)\"\n            using c_s_def TopType Type\n            by simp\n          have \"((take (length t1s - length cons ) t1s) @  x2) = t2s\"\n            using assms(4) ctm_def3\n            by simp\n          have \"c_types_agree (TopType (take (length x1 - length cons ) x1)) (take (length t1s - length cons) t1s)\"\n            using consume_c_types_agree[OF t_int_def assms(3)] 4 TopType\n            by simp\n          hence \"c_types_agree (TopType (take (length x1 - length cons ) x1 @ to_ct_list x2)) (take (length t1s - length cons) t1s @ x2)\"\n            unfolding c_types_agree.simps to_ct_list_def\n            by (simp add: ct_suffix_cons2 ct_suffix_cons_it ct_suffix_extend_ct_list_eq)\n          thus ?thesis\n            using ctm_def3 assms 3\n            by simp\n        qed\n      qed simp\n    next\n      case (Type x2)\n      thus ?thesis\n        using assms\n        by simp\n    next\n      case Bot\n      thus ?thesis\n        using assms\n        by simp\n    qed\n  qed\nqed\n\nlemma b_e_type_checker_compose:\n  assumes \"b_e_type_checker \\<C> es (t1s _> t2s)\"\n          \"b_e_type_checker \\<C> [e] (t2s _> t3s)\"\n  shows \"b_e_type_checker \\<C> (es @ [e]) (t1s _> t3s)\"\nproof -\n  have \"c_types_agree (check_single \\<C> e (Type t2s)) t3s\"\n    using assms(2)\n    by simp\n  then obtain ctm where ctm_def:\"check_single \\<C> e (Type t2s) = ctm\"\n                                \"c_types_agree ctm t3s\"\n                                \"ctm \\<noteq> Bot\"\n    by fastforce\n  have \"c_types_agree (check \\<C> es (Type t1s)) t2s\"\n    using assms(1)\n    by simp\n  then obtain ctn where ctn_def:\"check \\<C> es (Type t1s) = ctn\"\n                                \"c_types_agree ctn t2s\"\n                                \"ctn \\<noteq> Bot\"\n    by fastforce\n  thus ?thesis\n    using check_single_imp_weakening[OF ctm_def(1,3) ctn_def(2) ctm_def(2)]\n          check_unfold_snoc[of \\<C> es \"(Type t1s)\" e]\n    by simp\nqed\n\nlemma b_e_check_single_type_type:\n  assumes \"check_single \\<C> e xs = (Type tm)\"\n  shows \"\\<exists>tn. xs = (Type tn)\"\nproof -\n  consider (1) \"check_single \\<C> e = id\"\n         | (2) \"check_single \\<C> e = (\\<lambda>ctn. type_update_select ctn)\"\n         | (3) \"(\\<exists>cons prods. (check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)))\"\n    using check_single_imp assms\n    by blast\n  thus ?thesis\n  proof (cases)\n    case 1\n    thus ?thesis\n      using assms\n      by simp\n  next\n    case 2\n    note outer_2 = 2\n    thus ?thesis\n      using assms\n    proof (cases xs)\n      case (TopType x1)\n      consider\n          (1) \"length x1 = 0\"\n        | (2) \"length x1 = Suc 0\"\n        | (3) \"length x1 = Suc (Suc 0)\"\n        | (4) \"length x1 \\<ge> 3\"\n        by linarith\n      thus ?thesis\n      proof cases\n        case 1\n        thus ?thesis\n          using assms 2 TopType\n          by simp\n      next\n        case 2\n        thus ?thesis\n          using assms outer_2 TopType produce_type_type\n          by fastforce\n      next\n        case 3\n        thus ?thesis\n          using assms 2 TopType\n          by (simp, metis checker_type.distinct(1) checker_type.distinct(5))\n      next\n        case 4\n        then obtain nat where nat_def:\"length x1 = Suc (Suc (Suc nat))\"\n          by (metis add_eq_if diff_Suc_1 le_Suc_ex numeral_3_eq_3 nat.distinct(2))\n        thus ?thesis\n          using assms 2 TopType\n        proof -\n          {\n            assume a1: \"produce (if ct_suffix [TAny, TAny, TSome T_i32] x1 then TopType (take (length x1 - length [TAny, TAny, TSome T_i32]) x1) else if ct_suffix x1 [TAny, TAny, TSome T_i32] then TopType [] else Bot) (select_return_top x1 (x1 ! Suc nat) (x1 ! nat)) = Type tm\"\n            obtain tts :: \"checker_type \\<Rightarrow> t list\" where\n              f2: \"\\<forall>c. (\\<forall>ca ts. produce c ca \\<noteq> Type ts) \\<or> c = Type (tts c)\"\n              using produce_type_type by moura\n            then have f3: \"\\<And>ts. \\<not> ct_suffix [TAny, TAny, TSome T_i32] x1 \\<or> Type tm \\<noteq> Type ts\"\n              using a1 by fastforce\n            then have \"\\<And>ts. \\<not> ct_suffix x1 [TAny, TAny, TSome T_i32] \\<or> Type tm \\<noteq> Type ts\"\n              using f2 a1 by fastforce\n            then have False\n              using f3 a1 by fastforce\n          }\n          thus ?thesis\n            using assms 2 TopType nat_def\n            by simp\n        qed\n      qed\n    qed simp_all\n  next\n    case 3\n    then obtain cons prods where check_def:\"check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)\"\n      by blast\n    hence \"produce (consume xs cons) prods = (Type tm)\"\n      using assms(1)\n      by simp\n    thus ?thesis\n      using assms check_def consume_type_type produce_type_type\n      by blast\n  qed\nqed\n\nlemma b_e_check_single_weaken_type:\n  assumes \"check_single \\<C> e (Type tn) = (Type tm)\"\n  shows \"check_single \\<C> e (Type (ts@tn)) = Type (ts@tm)\"\nproof -\n  consider (1) \"check_single \\<C> e = id\"\n         | (2) \"check_single \\<C> e = (\\<lambda>ctn. type_update_select ctn)\"\n         | (3) \"(\\<exists>cons prods. (check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)))\"\n    using check_single_imp assms\n    by blast\n  thus ?thesis\n  proof (cases)\n    case 1\n    thus ?thesis\n      using assms(1)\n      by simp\n  next\n    case 2\n    hence cond:\"(length tn \\<ge> 3 \\<and> (tn!(length tn-2)) = (tn!(length tn-3)))\"\n      using assms\n      by (simp, metis checker_type.distinct(5))\n    hence \"consume (Type tn) [TAny, TSome T_i32] = (Type tm)\"\n      using assms 2\n      by simp\n    hence \"consume (Type (ts@tn)) [TAny, TSome T_i32] = (Type (ts@tm))\"\n      using consume_weaken_type\n      by blast\n    moreover\n    have \"(length (ts@tn) \\<ge> 3 \\<and> ((ts@tn)!(length (ts@tn)-2)) = ((ts@tn)!(length (ts@tn)-3)))\"\n      using cond\n      by (simp, metis add.commute add_leE nth_append_length_plus numeral_Bit1 numeral_One\n                      one_add_one ordered_cancel_comm_monoid_diff_class.diff_add_assoc2)\n    ultimately\n    show ?thesis\n      using 2\n      by simp\n  next\n    case 3\n    then obtain cons prods where check_def:\"check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)\"\n      by blast\n    hence \"produce (consume (Type tn) cons) prods = (Type tm)\"\n      using assms(1)\n      by simp\n    then obtain t_int where t_int_def:\"consume (Type tn) cons = (Type t_int)\"\n      by (metis consume.simps(1) produce.simps(6))\n    thus ?thesis\n      using assms(1) check_def\n            consume_weaken_type[OF t_int_def, of ts]\n            produce_weaken_type[of t_int prods tm ts]\n      by simp\n  qed\nqed\n\nlemma b_e_check_single_weaken_top:\n  assumes \"check_single \\<C> e (Type tn) = TopType tm\"\n  shows \"check_single \\<C> e (Type (ts@tn)) = TopType tm\"\nproof -\n  consider (1) \"check_single \\<C> e = id\"\n         | (2) \"check_single \\<C> e = (\\<lambda>ctn. type_update_select ctn)\"\n         | (3) \"(\\<exists>cons prods. (check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)))\"\n    using check_single_imp assms\n    by blast\n  thus ?thesis\n  proof (cases)\n    case 1\n    thus ?thesis\n      using assms\n      by simp\n  next\n    case 2\n    thus ?thesis\n      using assms\n      by (simp, metis checker_type.distinct(1) checker_type.distinct(3) consume.simps(1))\n  next\n    case 3\n    then obtain cons prods where check_def:\"check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)\"\n      by blast\n    hence \"produce (consume (Type tn) cons) prods = (TopType tm)\"\n      using assms(1)\n      by simp\n    moreover\n    then obtain t_int where t_int_def:\"consume (Type tn) cons = (Type t_int)\"\n      by (metis checker_type.distinct(3) consume.simps(1) produce.simps(6))\n    ultimately\n    show ?thesis\n      using check_def consume_weaken_type\n      by (cases prods, auto)\n  qed\nqed\n\nlemma b_e_check_weaken_type:\n  assumes \"check \\<C> es (Type tn) = (Type tm)\"\n  shows \"check \\<C> es (Type (ts@tn)) = (Type (ts@tm))\"\n  using assms\nproof (induction es arbitrary: tn tm rule: List.rev_induct)\n  case Nil\n  thus ?case\n    by simp\nnext\n  case (snoc e es)\n  hence \"check_single \\<C> e (check \\<C> es (Type tn)) = Type tm\"\n    using check_unfold_snoc[OF check_neq_bot_snoc]\n    by (metis checker_type.distinct(5))\n  thus ?case\n    using b_e_check_single_weaken_type b_e_check_single_type_type snoc\n    by (metis check_unfold_snoc checker_type.distinct(5))\nqed\n\nlemma check_bot: \"check \\<C> es Bot = Bot\"\n  by (simp add: list.case_eq_if)\n\nlemma b_e_check_weaken_top:\n  assumes \"check \\<C> es (Type tn) = (TopType tm)\"\n  shows \"check \\<C> es (Type (ts@tn)) = (TopType tm)\"\n  using assms\nproof (induction es arbitrary: tn tm)\n  case Nil\n  thus ?case\n    by simp\nnext\n  case (Cons e es)\n  show ?case\n  proof (cases \"(check_single \\<C> e (Type tn))\")\n    case (TopType x1)\n    hence \"check_single \\<C> e (Type (ts@tn)) = TopType x1\"\n      using b_e_check_single_weaken_top\n      by blast\n    thus ?thesis\n      using TopType Cons\n      by simp\n  next\n    case (Type x2)\n    hence \"check_single \\<C> e (Type (ts@tn)) = Type (ts@x2)\"\n      using b_e_check_single_weaken_type\n      by blast\n    thus ?thesis\n      using Cons Type\n      by fastforce\n  next\n    case Bot\n    thus ?thesis\n      using check_bot Cons\n      by simp\n  qed\n\nqed\n\nlemma b_e_type_checker_weaken:\n  assumes \"b_e_type_checker \\<C> es (t1s _> t2s)\"\n  shows \"b_e_type_checker \\<C> es (ts@t1s _> ts@t2s)\"\nproof -\n  have \"c_types_agree (check \\<C> es (Type t1s)) t2s\"\n    using assms(1)\n    by simp\n  then obtain ctn where ctn_def:\"check \\<C> es (Type t1s) = ctn\"\n                                \"c_types_agree ctn t2s\"\n                                \"ctn \\<noteq> Bot\"\n    by fastforce\n  show ?thesis\n  proof (cases ctn)\n    case (TopType x1)\n    thus ?thesis\n      using ctn_def(1,2) b_e_check_weaken_top[of \\<C> es t1s x1 ts]\n      by (metis append_assoc b_e_type_checker.simps c_types_agree_imp_ct_list_eq c_types_agree_top2)\n  next\n    case (Type x2)\n    thus ?thesis\n      using ctn_def(1,2) b_e_check_weaken_type[of \\<C> es t1s x2 ts]\n      by simp\n  next\n    case Bot\n    thus ?thesis\n      using ctn_def(3)\n      by simp\n  qed\nqed\n\nlemma b_e_type_checker_complete:\n  assumes \"\\<C> \\<turnstile> es : (tn _> tm)\"\n  shows \"b_e_type_checker \\<C> es (tn _> tm)\"\n  using assms\nproof (induction es \"(tn _> tm)\" arbitrary: tn tm rule: b_e_typing.induct)\n  case (select \\<C> t)\n  have \"ct_list_eq [TAny, TSome T_i32] [TSome t, TSome T_i32]\"\n    by (simp add: to_ct_list_def ct_list_eq_def)\n  thus ?case\n    using ct_suffix_extend_ct_list_eq[OF ct_suffix_nil[of \"[TSome t]\"]] to_ct_list_def\n    by auto\nnext\n  case (br_table \\<C> ts \"is\" i t1s t2s)\n  show ?case\n    using list_all_conv_same_lab[OF br_table]\n    by (auto simp add: to_ct_list_def ct_suffix_nil ct_suffix_cons_it)\nnext\n  case (set_global i \\<C> t)\n  thus ?case\n    using to_ct_list_def ct_suffix_refl is_mut_def tg_t_def\n    by auto\nnext\n  case (composition \\<C> es t1s t2s e t3s)\n  thus ?case\n    using b_e_type_checker_compose\n    by simp\nnext\n  case (weakening \\<C> es t1s t2s ts)\n  thus ?case\n    using b_e_type_checker_weaken\n    by simp\nqed (auto simp add: to_ct_list_def ct_suffix_refl ct_suffix_nil ct_suffix_cons_it\n                    ct_suffix_singleton_any)\n\ntheorem b_e_typing_equiv_b_e_type_checker:\n  shows \"(\\<C> \\<turnstile> es : (tn _> tm)) = (b_e_type_checker \\<C> es (tn _> tm))\"\n  using b_e_type_checker_sound b_e_type_checker_complete\n  by blast\n\nend\n", "meta": {"author": "jacobmischka", "repo": "wasm-isabelle", "sha": "a7c0395023d06d701848ddaf850e6997206489a5", "save_path": "github-repos/isabelle/jacobmischka-wasm-isabelle", "path": "github-repos/isabelle/jacobmischka-wasm-isabelle/wasm-isabelle-a7c0395023d06d701848ddaf850e6997206489a5/WebAssembly/Wasm_Checker_Properties.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5813030906443133, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.28157164003676394}}
{"text": "(* \n   Title: Psi-calculi   \n   Author/Maintainer: Jesper Bengtson (jebe@itu.dk), 2012\n*)\ntheory Weakening\n  imports Weak_Bisimulation\nbegin\n\nlocale weak = env + \n  assumes weaken: \"\\<Psi> \\<hookrightarrow> \\<Psi> \\<otimes> \\<Psi>'\"\nbegin\n\nlemma entWeaken:\n  fixes \\<Psi> :: 'b\n  and   \\<phi> :: 'c\n\n  assumes \"\\<Psi> \\<turnstile> \\<phi>\"\n\n  shows \"\\<Psi> \\<otimes> \\<Psi>' \\<turnstile> \\<phi>\"\nusing assms weaken\nby(auto simp add: AssertionStatImp_def)\n\nlemma assertWeaken:\n  fixes \\<Psi>  :: 'b\n  and   \\<Psi>' :: 'b\n\n  shows \"\\<Psi> \\<hookrightarrow> \\<Psi> \\<otimes> \\<Psi>'\"\nby(auto simp add: AssertionStatImp_def entWeaken)\n\nlemma frameWeaken:\n  fixes F :: \"'b frame\"\n  and   G :: \"'b frame\"\n\n  shows \"F \\<hookrightarrow>\\<^sub>F F \\<otimes>\\<^sub>F G\"\nproof -\n  obtain A\\<^sub>F \\<Psi>\\<^sub>F where FrF: \"F = \\<langle>A\\<^sub>F, \\<Psi>\\<^sub>F\\<rangle>\" and \"A\\<^sub>F \\<sharp>* F\" and  \"A\\<^sub>F \\<sharp>* G\"\n    by(rule_tac F=F and C=\"(F, G)\" in freshFrame) auto\n  obtain A\\<^sub>G \\<Psi>\\<^sub>G where FrG: \"G = \\<langle>A\\<^sub>G, \\<Psi>\\<^sub>G\\<rangle>\" and \"A\\<^sub>G \\<sharp>* F\" and  \"A\\<^sub>G \\<sharp>* G\" and \"A\\<^sub>G \\<sharp>* A\\<^sub>F\" and \"A\\<^sub>G \\<sharp>* \\<Psi>\\<^sub>F\"\n    by(rule_tac F=G and C=\"(F, G, A\\<^sub>F, \\<Psi>\\<^sub>F)\" in freshFrame) auto\n  from FrG \\<open>A\\<^sub>F \\<sharp>* G\\<close> \\<open>A\\<^sub>G \\<sharp>* A\\<^sub>F\\<close> have \"A\\<^sub>F \\<sharp>* \\<Psi>\\<^sub>G\" by auto\n  have \"\\<Psi>\\<^sub>F \\<hookrightarrow> \\<Psi>\\<^sub>F \\<otimes> \\<Psi>\\<^sub>G\" by(rule weaken)\n  hence \"\\<langle>A\\<^sub>G, \\<Psi>\\<^sub>F\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>G, \\<Psi>\\<^sub>F \\<otimes> \\<Psi>\\<^sub>G\\<rangle>\" by(rule_tac frameImpResChainPres) auto\n  with \\<open>A\\<^sub>G \\<sharp>* \\<Psi>\\<^sub>F\\<close> have \"\\<langle>\\<epsilon>, \\<Psi>\\<^sub>F\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>G, \\<Psi>\\<^sub>F \\<otimes> \\<Psi>\\<^sub>G\\<rangle>\" using frameResFreshChain\n    by(rule_tac FrameStatImpTrans) (auto simp add: FrameStatEq_def)\n  with FrF FrG \\<open>A\\<^sub>G \\<sharp>* A\\<^sub>F\\<close> \\<open>A\\<^sub>G \\<sharp>* \\<Psi>\\<^sub>F\\<close> \\<open>A\\<^sub>F \\<sharp>* \\<Psi>\\<^sub>G\\<close> show ?thesis\n    by(force simp add: frameChainAppend intro: frameImpResChainPres)\nqed\n\nlemma unitAssertWeaken:\n  fixes \\<Psi> :: 'b\n\n  shows \"\\<one> \\<hookrightarrow> \\<Psi>\"\nproof -\n  have \"\\<one> \\<hookrightarrow> \\<one> \\<otimes> \\<Psi>\" by(rule assertWeaken)\n  moreover have \"\\<one> \\<otimes> \\<Psi> \\<hookrightarrow> \\<Psi>\" by(metis Identity AssertionStatEq_def Commutativity AssertionStatEqTrans)\n  ultimately show ?thesis by(rule AssertionStatImpTrans)\nqed\n\nlemma unitFrameWeaken:\n  fixes F :: \"'b frame\"\n\n  shows \"\\<langle>\\<epsilon>, \\<one>\\<rangle> \\<hookrightarrow>\\<^sub>F F\"\nproof -\n  have \"\\<langle>\\<epsilon>, \\<one>\\<rangle> \\<hookrightarrow>\\<^sub>F ((\\<langle>\\<epsilon>, \\<one>\\<rangle>) \\<otimes>\\<^sub>F F)\" by(rule frameWeaken)\n  moreover obtain A\\<^sub>F \\<Psi>\\<^sub>F where FrF: \"F = \\<langle>A\\<^sub>F, \\<Psi>\\<^sub>F\\<rangle>\"\n    by(rule_tac F=F and C=\"()\" in freshFrame) auto\n  hence \"(\\<langle>\\<epsilon>, \\<one>\\<rangle>) \\<otimes>\\<^sub>F F \\<simeq>\\<^sub>F F\" \n    by simp (metis frameIntIdentity frameIntCommutativity FrameStatEqTrans FrameStatEqSym)\n  ultimately show ?thesis by(metis FrameStatImpTrans FrameStatEq_def)\nqed\n\nlemma insertAssertionWeaken:\n  fixes F :: \"'b frame\"\n  and   \\<Psi> :: 'b\n\n  shows \"\\<langle>\\<epsilon>, \\<Psi>\\<rangle> \\<hookrightarrow>\\<^sub>F insertAssertion F \\<Psi>\"\nproof -\n  have \"\\<langle>\\<epsilon>, \\<Psi>\\<rangle> \\<hookrightarrow>\\<^sub>F (\\<langle>\\<epsilon>, \\<Psi>\\<rangle>) \\<otimes>\\<^sub>F F\" by(rule frameWeaken)\n  thus ?thesis by simp\nqed\n\nlemma frameImpStatEq:\n  fixes A\\<^sub>F  :: \"name list\"\n  and   \\<Psi>  :: 'b\n  and   \\<Psi>' :: 'b\n  and   \\<phi>  :: 'c\n\n  assumes \"(\\<langle>A\\<^sub>F, \\<Psi>\\<rangle>) \\<turnstile>\\<^sub>F \\<phi>\"\n  and     \"\\<Psi> \\<simeq> \\<Psi>'\"\n\n  shows \"(\\<langle>A\\<^sub>F, \\<Psi>'\\<rangle>) \\<turnstile>\\<^sub>F \\<phi>\"\nproof -\n  obtain p::\"name prm\" where \"(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<phi>\" and \"(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<Psi>\" and \"(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<Psi>'\"\n                         and \"distinctPerm p\" and S: \"set p \\<subseteq> set A\\<^sub>F \\<times> set(p \\<bullet> A\\<^sub>F)\"\n    by(rule_tac c=\"(\\<phi>, \\<Psi>, \\<Psi>')\" in name_list_avoiding) auto\n  from \\<open>(\\<langle>A\\<^sub>F, \\<Psi>\\<rangle>) \\<turnstile>\\<^sub>F \\<phi>\\<close> \\<open>(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<Psi>\\<close> S have \"(\\<langle>(p \\<bullet> A\\<^sub>F), p \\<bullet> \\<Psi>\\<rangle>) \\<turnstile>\\<^sub>F \\<phi>\" by(simp add: frameChainAlpha)\n  hence \"(p \\<bullet> \\<Psi>) \\<turnstile> \\<phi>\" using \\<open>(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<phi>\\<close> by(rule frameImpE)\n  moreover from \\<open>\\<Psi> \\<simeq> \\<Psi>'\\<close> have \"(p \\<bullet> \\<Psi>) \\<simeq> (p \\<bullet> \\<Psi>')\" by(rule AssertionStatEqClosed)\n  ultimately have \"(p \\<bullet> \\<Psi>') \\<turnstile> \\<phi>\" by(simp add: AssertionStatEq_def AssertionStatImp_def)\n  hence \"(\\<langle>(p \\<bullet> A\\<^sub>F), p \\<bullet> \\<Psi>'\\<rangle>) \\<turnstile>\\<^sub>F \\<phi>\" using \\<open>(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<phi>\\<close> \n    by(rule_tac frameImpI) auto\n  with \\<open>(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<Psi>'\\<close> S show ?thesis by(simp add: frameChainAlpha)\nqed\n\n\n\n  assumes \"\\<Psi> \\<rhd> P \\<longmapsto>\\<tau> \\<prec> P'\"\n\n  shows \"insertAssertion (extractFrame P) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P') \\<Psi>\"\nproof(auto simp add: FrameStatImp_def)\n  fix \\<phi> :: 'c\n  obtain A\\<^sub>P \\<Psi>\\<^sub>P where FrP: \"extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" and \"A\\<^sub>P \\<sharp>* P\" and \"A\\<^sub>P \\<sharp>* \\<phi>\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\" and \"distinct A\\<^sub>P\" \n    by(rule_tac C=\"(P, \\<phi>, \\<Psi>)\" in freshFrame) auto\n  with \\<open>\\<Psi> \\<rhd> P \\<longmapsto>\\<tau> \\<prec> P'\\<close> obtain \\<Psi>' A\\<^sub>P' \\<Psi>\\<^sub>P' where FrP': \"extractFrame P' = \\<langle>A\\<^sub>P', \\<Psi>\\<^sub>P'\\<rangle>\" and \"\\<Psi>\\<^sub>P \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>P'\" \n                                              and \"A\\<^sub>P' \\<sharp>* P'\" and \"A\\<^sub>P' \\<sharp>* \\<phi>\"  and \"A\\<^sub>P' \\<sharp>* \\<Psi>\" \n    by(rule_tac C=\"(\\<Psi>, \\<phi>)\" in expandTauFrame) auto\n  assume \"insertAssertion (extractFrame P) \\<Psi> \\<turnstile>\\<^sub>F \\<phi>\"\n  with FrP \\<open>A\\<^sub>P \\<sharp>* \\<phi>\\<close> \\<open>A\\<^sub>P \\<sharp>* \\<Psi>\\<close> have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<turnstile> \\<phi>\" by(auto dest: frameImpE)\n  hence \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>' \\<turnstile> \\<phi>\" by(rule entWeaken)\n  hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P' \\<turnstile> \\<phi>\" using \\<open>\\<Psi>\\<^sub>P \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>P'\\<close>\n    by(rule_tac statEqEnt, auto) (metis Associativity compositionSym AssertionStatEqTrans AssertionStatEqSym Commutativity)\n  with \\<open>A\\<^sub>P' \\<sharp>* \\<phi>\\<close> \\<open>A\\<^sub>P' \\<sharp>* \\<Psi>\\<close> FrP' show \"insertAssertion (extractFrame P') \\<Psi> \\<turnstile>\\<^sub>F \\<phi>\"\n    by(force intro: frameImpI)\nqed\n\nlemma weakenTransition:\n  fixes \\<Psi>  :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   Rs :: \"('a, 'b, 'c) residual\"\n  and   \\<Psi>' :: 'b\n\n  assumes \"\\<Psi> \\<rhd> P \\<longmapsto> Rs\"\n\n  shows \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<longmapsto> Rs\"\nusing assms\nproof(nominal_induct avoiding: \\<Psi>' rule: semantics.strong_induct)\n  case(cInput \\<Psi> M K xvec N Tvec P \\<Psi>')\n  from \\<open>\\<Psi> \\<turnstile> M \\<leftrightarrow> K\\<close> have \"\\<Psi> \\<otimes> \\<Psi>' \\<turnstile> M \\<leftrightarrow> K\" by(rule entWeaken)\n  thus ?case using \\<open>distinct xvec\\<close> \\<open>set xvec \\<subseteq> (supp N)\\<close> \\<open>length xvec = length Tvec\\<close> \n    by(rule Input)\nnext\n  case(Output \\<Psi> M K N P \\<Psi>')\n  from \\<open>\\<Psi> \\<turnstile> M \\<leftrightarrow> K\\<close> have \"\\<Psi> \\<otimes> \\<Psi>' \\<turnstile> M \\<leftrightarrow> K\" by(rule entWeaken)\n  thus ?case by(rule semantics.Output)\nnext\n  case(Case \\<Psi> P Rs \\<phi> Cs \\<Psi>')\n  have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<longmapsto> Rs\" by(rule Case)\n  moreover note \\<open>(\\<phi>, P) mem Cs\\<close>\n  moreover from \\<open>\\<Psi> \\<turnstile> \\<phi>\\<close> have \"\\<Psi> \\<otimes> \\<Psi>' \\<turnstile> \\<phi>\" by(rule entWeaken)\n  ultimately show ?case using \\<open>guarded P\\<close>\n    by(rule semantics.Case)\nnext\n  case(cPar1 \\<Psi> \\<Psi>\\<^sub>Q P \\<alpha> P' Q A\\<^sub>Q \\<Psi>')\n  have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>' \\<rhd> P \\<longmapsto>\\<alpha> \\<prec> P'\" by(rule cPar1)\n  hence \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<longmapsto>\\<alpha> \\<prec> P'\"\n    by(metis statEqTransition Composition Associativity Commutativity AssertionStatEqTrans)\n  thus ?case using \\<open>extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\\<close> \\<open>bn \\<alpha> \\<sharp>* Q\\<close> \\<open>A\\<^sub>Q \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>Q \\<sharp>* \\<Psi>'\\<close> \\<open>A\\<^sub>Q \\<sharp>* P\\<close> \\<open>A\\<^sub>Q \\<sharp>* \\<alpha>\\<close>\n    by(rule_tac Par1) auto\nnext\n  case(cPar2 \\<Psi> \\<Psi>\\<^sub>P Q \\<alpha> Q' P A\\<^sub>P \\<Psi>')\n  have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>' \\<rhd> Q \\<longmapsto>\\<alpha> \\<prec> Q'\" by(rule cPar2)\n  hence \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<longmapsto>\\<alpha> \\<prec> Q'\"\n    by(metis statEqTransition Composition Associativity Commutativity AssertionStatEqTrans)\n  thus ?case using \\<open>extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\\<close> \\<open>bn \\<alpha> \\<sharp>* P\\<close> \\<open>A\\<^sub>P \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>P \\<sharp>* \\<Psi>'\\<close> \\<open>A\\<^sub>P \\<sharp>* Q\\<close> \\<open>A\\<^sub>P \\<sharp>* \\<alpha>\\<close>\n    by(rule_tac Par2) auto\nnext\n  case(cComm1 \\<Psi> \\<Psi>\\<^sub>Q P M N P' A\\<^sub>P \\<Psi>\\<^sub>P Q K xvec Q' A\\<^sub>Q \\<Psi>')\n  have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>' \\<rhd> P \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> P'\" by(rule cComm1)\n  hence \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> P'\"\n    by(metis statEqTransition Composition Associativity Commutativity AssertionStatEqTrans)\n  moreover note \\<open>extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\\<close>\n  moreover have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>' \\<rhd> Q \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'\" by(rule cComm1)\n  hence \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'\"\n    by(metis statEqTransition Composition Associativity Commutativity AssertionStatEqTrans)\n  moreover note \\<open>extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\\<close>\n  moreover from \\<open>\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M \\<leftrightarrow> K\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>' \\<turnstile> M \\<leftrightarrow> K\" by(rule entWeaken)\n  hence \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M \\<leftrightarrow> K\" by(metis statEqEnt Composition Associativity Commutativity AssertionStatEqTrans)\n  ultimately show ?case using \\<open>A\\<^sub>P \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>P \\<sharp>* \\<Psi>'\\<close> \\<open>A\\<^sub>P \\<sharp>* P\\<close> \\<open>A\\<^sub>P \\<sharp>* Q\\<close> \\<open>A\\<^sub>P \\<sharp>* M\\<close> \\<open>A\\<^sub>P \\<sharp>* A\\<^sub>Q\\<close>\n                              \\<open>A\\<^sub>Q \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>Q \\<sharp>* \\<Psi>'\\<close> \\<open>A\\<^sub>Q \\<sharp>* P\\<close> \\<open>A\\<^sub>Q \\<sharp>* Q\\<close> \\<open>A\\<^sub>Q \\<sharp>* K\\<close> \\<open>xvec \\<sharp>* P\\<close>\n    by(rule_tac Comm1) (assumption | auto)+\nnext\n  case(cComm2 \\<Psi> \\<Psi>\\<^sub>Q P M xvec N P' A\\<^sub>P \\<Psi>\\<^sub>P Q K Q' A\\<^sub>Q \\<Psi>')\n  have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>' \\<rhd> P \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\" by(rule cComm2)\n  hence \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n    by(metis statEqTransition Composition Associativity Commutativity AssertionStatEqTrans)\n  moreover note \\<open>extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\\<close>\n  moreover have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>' \\<rhd> Q \\<longmapsto>K\\<lparr>N\\<rparr> \\<prec> Q'\" by(rule cComm2)\n  hence \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<longmapsto>K\\<lparr>N\\<rparr> \\<prec> Q'\"\n    by(metis statEqTransition Composition Associativity Commutativity AssertionStatEqTrans)\n  moreover note \\<open>extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\\<close>\n  moreover from \\<open>\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M \\<leftrightarrow> K\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>' \\<turnstile> M \\<leftrightarrow> K\" by(rule entWeaken)\n  hence \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M \\<leftrightarrow> K\" by(metis statEqEnt Composition Associativity Commutativity AssertionStatEqTrans)\n  ultimately show ?case using \\<open>A\\<^sub>P \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>P \\<sharp>* \\<Psi>'\\<close> \\<open>A\\<^sub>P \\<sharp>* P\\<close> \\<open>A\\<^sub>P \\<sharp>* Q\\<close> \\<open>A\\<^sub>P \\<sharp>* M\\<close> \\<open>A\\<^sub>P \\<sharp>* A\\<^sub>Q\\<close>\n                              \\<open>A\\<^sub>Q \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>Q \\<sharp>* \\<Psi>'\\<close> \\<open>A\\<^sub>Q \\<sharp>* P\\<close> \\<open>A\\<^sub>Q \\<sharp>* Q\\<close> \\<open>A\\<^sub>Q \\<sharp>* K\\<close> \\<open>xvec \\<sharp>* Q\\<close>\n    by(rule_tac Comm2) (assumption | auto)+\nnext\n  case(cOpen \\<Psi> P M xvec yvec N P' x \\<Psi>')\n  have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<longmapsto>M\\<lparr>\\<nu>*(xvec@yvec)\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\" by(rule cOpen)\n  thus ?case using \\<open>x \\<in> supp N\\<close> \\<open>x \\<sharp> \\<Psi>\\<close> \\<open>x \\<sharp> \\<Psi>'\\<close> \\<open>x \\<sharp> M\\<close> \\<open>x \\<sharp> xvec\\<close> \\<open>x \\<sharp> yvec\\<close>\n    by(rule_tac Open) auto\nnext  \n  case(cScope \\<Psi> P \\<alpha> P' x \\<Psi>')\n  have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<longmapsto>\\<alpha> \\<prec> P'\" by(rule cScope)\n  thus ?case using \\<open>x \\<sharp> \\<Psi>\\<close> \\<open>x \\<sharp> \\<Psi>'\\<close> \\<open>x \\<sharp> \\<alpha>\\<close> by(rule_tac Scope) auto\nnext\n  case(Bang \\<Psi> P Rs \\<Psi>')\n  have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<parallel> !P\\<longmapsto> Rs\" by(rule Bang)\n  thus ?case using \\<open>guarded P\\<close> by(rule semantics.Bang)\nqed\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Psi_Calculi/Weakening.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.2815666804993119}}
{"text": "(*\n * Copyright 2019, NTU\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n *  Author: Albert Rizaldi, NTU Singapore\n *)\n\ntheory Signed_Add_Inert_Typed\n  imports VHDL_Hoare_Typed Bits_Int_Aux\nbegin\n\ndatatype sig = A | B | C\n\ndefinition add :: \"sig conc_stmt\" where\n  \"add \\<equiv> process {A, B} : Bassign_inert C (Badd (Bsig A) (Bsig B)) 1\"\n\nlocale signed_addition =\n  fixes \\<Gamma> :: \"sig tyenv\"\n  fixes len len1 len2 :: nat\n  assumes len_def: \"len = max len1 len2\"\n  assumes atype: \"\\<Gamma> A = Lty Sig len1\" and btype: \"\\<Gamma> B = Lty Sig len2\" and ctype: \"\\<Gamma> C = Lty Sig len\"\n  assumes len1: \"0 < len1\" and len2: \"0 < len2\"\nbegin\n\nlemma well_typed:\n  \"seq_wt \\<Gamma> (Bassign_inert C (Badd (Bsig A) (Bsig B)) 1)\"\n  by (metis atype bexp_wt.intros(16) bexp_wt.intros(3) btype ctype len1 len2 len_def\n  seq_wt.intros(5))\n\nabbreviation \"lof_wline tw sig n \\<equiv> lval_of (wline_of tw sig n)\"\n\ntext \\<open>Here we factor out common expression in both inv1 and inv2. It is parametrised by the index\nwe are interested with for C (first argument) and A (the second argument). Note that the index\nwe are interested with for A should be the same as the index for B.\\<close>\n\ndefinition inv :: \"sig assn2\" where\n  \"inv tw \\<equiv> (lof_wline tw C (fst tw) = bin_to_bl len (sbl_to_bin (lof_wline tw A (fst tw - 1)) + sbl_to_bin (lof_wline tw B (fst tw - 1))))\"\n\ndefinition inv2 :: \"sig assn2\" where\n  \"inv2 tw \\<equiv> (disjnt {A, B} (event_of tw) \\<longrightarrow> (\\<forall>i > fst tw. lof_wline tw C i = lof_wline tw C (fst tw)))\"\n\nlemma inv_next_time:\n  fixes tw\n  defines \"v \\<equiv> eval_world_raw2 tw (Badd (Bsig A) (Bsig B))\"\n  defines \"tw' \\<equiv> tw\\<lbrakk>C, 1 :=\\<^sub>2 v\\<rbrakk>\"\n  assumes \"wityping \\<Gamma> (snd tw)\"\n  shows   \"inv (fst tw' + 1, snd tw')\"\nproof - \n  have bexpA: \"bexp_wt \\<Gamma> (Bsig A) (Lty Sig len1)\" and bexpB: \"bexp_wt \\<Gamma> (Bsig B) (Lty Sig len2)\"\n    using signed_addition_axioms unfolding signed_addition_def by (metis bexp_wt.intros(3))+\n  obtain bsA bsB where evalA: \"eval_world_raw (fst tw) (snd tw) (Bsig A) = Lv Sig bsA\" and\" length bsA = len1 \" and\n                       evalB: \"eval_world_raw (fst tw) (snd tw) (Bsig B) = Lv Sig bsB\" and\" length bsB = len2 \"\n    using eval_world_raw_lv[OF bexpA `wityping \\<Gamma> (snd tw)`] eval_world_raw_lv[OF bexpB `wityping \\<Gamma> (snd tw)`] by blast\n  have \"type_of v = Lty Sig len\"\n    using assms(3) bexpA bexpB bexp_wt.intros(9) type_of_eval_world_raw2 v_def \n    by (metis ctype seq_wt_cases(5) well_typed)\n  hence \"lof_wline tw' C (fst tw + 1) = lval_of v\"\n    unfolding tw'_def\n  proof (induction v)\n    case (Bv x) \n    then show ?case by auto\n  next\n    case (Lv sign bs)\n    hence \"sign = Sig\" and \"length bs = len\"\n      by auto\n    let ?w' = \"\\<lambda>b. snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)]\"\n    let ?time = \"LEAST n. get_time tw < n \\<and> n \\<le> get_time tw + 1 \\<and> (\\<exists>b\\<in>set [0..<length bs]. ?w' b C (n - 1) \\<noteq> ?w' b C n)\"\n    have *: \" bs = (map (\\<lambda>b. bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (fst tw + 1))) [0..<length bs])\"\n    proof (rule nth_equalityI)\n      show \"length bs = length (map (\\<lambda>b. bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (fst tw + 1))) [0..<length bs])\"\n        by auto\n    next\n      fix b\n      assume \"b < length bs\"\n      hence \"map (\\<lambda>b. bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (fst tw + 1))) [0..<length bs] ! b = \n            bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (fst tw + 1))\"\n        by auto\n      have \"((snd (snd tw))(C := to_bit b \\<circ> snd (snd tw) C)) C (get_time tw)  \\<noteq> Bv (bs ! b) \\<and>\n           ((snd (snd tw))(C := to_bit b \\<circ> snd (snd tw) C)) C (get_time tw + 1) = Bv (bs ! b) \\<Longrightarrow> \n          ( GREATEST n.\n                n \\<le> get_time tw + 1 \\<and>\n                ((snd (snd tw))(C := to_bit b \\<circ> snd (snd tw) C)) C (n - 1) \\<noteq> Bv (bs ! b) \\<and>\n                ((snd (snd tw))(C := to_bit b \\<circ> snd (snd tw) C)) C n = Bv (bs ! b)) = fst tw + 1\"\n        by (metis (mono_tags, lifting) Greatest_equality add_diff_cancel_right' le_eq_less_or_eq)\n      hence \"bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (fst tw + 1)) = (bs ! b)\"\n        unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv by auto\n      thus \" bs ! b =\n      map (\\<lambda>b. bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (fst tw + 1))) [0..<length bs] !\n      b \"\n        using \\<open>map (\\<lambda>b. bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (fst tw + 1))) [0..<length bs] ! b = bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (fst tw + 1))\\<close> \n        by blast\n    qed\n    then show ?case \n    proof (cases \"\\<exists>n>get_time tw. n \\<le> get_time tw + 1 \\<and> (\\<exists>b\\<in>set [0..<length bs]. ?w' b C (n - 1) \\<noteq> ?w' b C n)\")\n      case True\n      hence \"?time = fst tw + 1\"\n        by (metis (mono_tags, lifting) LeastI_ex antisym_conv1 discrete leD)\n      then show ?thesis \n        using True *\n        unfolding worldline_inert_upd2_def comp_def snd_conv VHDL_Hoare.worldline_inert_upd2.simps\n        by auto\n    next\n      case False\n      then show ?thesis \n        using *\n        unfolding worldline_inert_upd2_def comp_def snd_conv VHDL_Hoare.worldline_inert_upd2.simps\n        by auto\n    qed\n  qed\n  also have \"... = bin_to_bl len (sbl_to_bin (lof_wline tw A (fst tw)) + sbl_to_bin (lof_wline tw B (fst tw)))\"\n    using evalA evalB `length bsA = len1` `length bsB = len2`\n    unfolding v_def eval_world_raw.simps eval_arith.simps len_def Let_def by auto\n  finally show ?thesis\n    unfolding inv_def tw'_def worldline_inert_upd2_def worldline_inert_upd_def  \n    by (metis (no_types, hide_lams) add.right_neutral add_diff_cancel_right' comp_apply fst_conv less_not_refl not_less_less_Suc_eq order_refl plus_1_eq_Suc snd_conv snd_worldline_inert_upd2 worldline_inert_upd2_def)\nqed\n\nlemma inv2_next_time:\n  fixes tw v\n  defines \"tw' \\<equiv> tw\\<lbrakk>C, 1 :=\\<^sub>2 v\\<rbrakk>\"\n  shows   \"inv2 (fst tw' + 1, snd tw')\"\nproof -\n  { assume \"disjnt {A, B} (event_of (fst tw' + 1, snd tw'))\"\n    have \"\\<And>j. fst tw + 1 < j \\<Longrightarrow> lof_wline tw' C j = lof_wline tw' C (fst tw + 1)\"\n      unfolding tw'_def \n    proof (induction v)\n      case (Bv x)\n      then show ?case \n      proof (cases \"snd (snd tw) C (get_time tw) = Bv x \\<or> snd (snd tw) C (get_time tw + 1) \\<noteq> Bv x \")\n        case True\n        then show ?thesis \n          using Bv\n          unfolding worldline_inert_upd2_def VHDL_Hoare.worldline_inert_upd2.simps worldline_inert_upd_def\n          comp_def snd_conv by auto\n      next\n        case False\n        hence \"snd (snd tw) C (get_time tw) \\<noteq> Bv x \\<and> snd (snd tw) C (get_time tw + 1) = Bv x\"\n          by auto\n        hence \"(GREATEST n. n \\<le> get_time tw + 1 \\<and> snd (snd tw) C (n - 1) \\<noteq> Bv x \\<and> snd (snd tw) C n = Bv x) = fst tw + 1\"\n          using GreatestI_nat[where k=\"fst tw + 1\"] \n          by (metis (mono_tags, lifting) Greatest_equality Suc_eq_plus1 diff_Suc_1 le_eq_less_or_eq)\n        then show ?thesis\n          using Bv False\n          unfolding worldline_inert_upd2_def VHDL_Hoare.worldline_inert_upd2.simps worldline_inert_upd_def\n          comp_def snd_conv by auto\n      qed\n    next\n      case (Lv sign bs)\n      let ?w' = \"\\<lambda>b. snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)]\"\n      let ?time = \"LEAST n. get_time tw < n \\<and> n \\<le> get_time tw + 1 \\<and> (\\<exists>b\\<in>set [0..<length bs]. ?w' b C (n - 1) \\<noteq> ?w' b C n)\"\n      have *: \" bs = (map (\\<lambda>b. bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (fst tw + 1))) [0..<length bs])\"\n      proof (rule nth_equalityI)\n        show \"length bs = length (map (\\<lambda>b. bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (fst tw + 1))) [0..<length bs])\"\n          by auto\n      next\n        fix b\n        assume \"b < length bs\"\n        hence \"map (\\<lambda>b. bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (fst tw + 1))) [0..<length bs] ! b = \n              bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (fst tw + 1))\"\n          by auto\n        have \"((snd (snd tw))(C := to_bit b \\<circ> snd (snd tw) C)) C (get_time tw)  \\<noteq> Bv (bs ! b) \\<and>\n             ((snd (snd tw))(C := to_bit b \\<circ> snd (snd tw) C)) C (get_time tw + 1) = Bv (bs ! b) \\<Longrightarrow> \n            ( GREATEST n.\n                  n \\<le> get_time tw + 1 \\<and>\n                  ((snd (snd tw))(C := to_bit b \\<circ> snd (snd tw) C)) C (n - 1) \\<noteq> Bv (bs ! b) \\<and>\n                  ((snd (snd tw))(C := to_bit b \\<circ> snd (snd tw) C)) C n = Bv (bs ! b)) = fst tw + 1\"\n          by (metis (mono_tags, lifting) Greatest_equality add_diff_cancel_right' le_eq_less_or_eq)\n        hence \"bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (fst tw + 1)) = (bs ! b)\"\n          unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv by auto\n        thus \" bs ! b =\n        map (\\<lambda>b. bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (fst tw + 1))) [0..<length bs] !\n        b \"\n          using \\<open>map (\\<lambda>b. bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (fst tw + 1))) [0..<length bs] ! b = bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (fst tw + 1))\\<close> \n          by blast\n      qed\n      have **: \" bs = (map (\\<lambda>b. bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (j))) [0..<length bs])\"\n      proof (rule nth_equalityI)\n        show \"length bs = length (map (\\<lambda>b. bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (j))) [0..<length bs])\"\n          by auto\n      next\n        fix b\n        assume \"b < length bs\"\n        hence \"map (\\<lambda>b. bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (j))) [0..<length bs] ! b = \n              bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (j))\"\n          by auto\n        have \"((snd (snd tw))(C := to_bit b \\<circ> snd (snd tw) C)) C (get_time tw)  \\<noteq> Bv (bs ! b) \\<and>\n             ((snd (snd tw))(C := to_bit b \\<circ> snd (snd tw) C)) C (get_time tw + 1) = Bv (bs ! b) \\<Longrightarrow> \n            ( GREATEST n.\n                  n \\<le> get_time tw + 1 \\<and>\n                  ((snd (snd tw))(C := to_bit b \\<circ> snd (snd tw) C)) C (n - 1) \\<noteq> Bv (bs ! b) \\<and>\n                  ((snd (snd tw))(C := to_bit b \\<circ> snd (snd tw) C)) C n = Bv (bs ! b)) = fst tw + 1\"\n          by (metis (mono_tags, lifting) Greatest_equality add_diff_cancel_right' le_eq_less_or_eq)\n        hence \"bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (j)) = (bs ! b)\"\n          unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv \n          using Lv by auto\n        thus \" bs ! b =\n        map (\\<lambda>b. bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (j))) [0..<length bs] !\n        b \"\n          using \\<open>map (\\<lambda>b. bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (j))) [0..<length bs] ! b = bval_of (snd to_worldline_init_bit (snd tw) C b[C, get_time tw, 1 := Bv (bs ! b)] C (j))\\<close> \n          by blast\n      qed\n      show ?case \n      proof (cases \"\\<exists>n>get_time tw. n \\<le> get_time tw + 1 \\<and> (\\<exists>b\\<in>set [0..<length bs]. ?w' b C (n - 1) \\<noteq> ?w' b C n)\")\n        case True\n        hence \"?time = fst tw + 1\"\n          by (metis (mono_tags, lifting) LeastI_ex antisym_conv1 discrete leD)\n        hence \"wline_of tw\\<lbrakk> C, 1 :=\\<^sub>2 Lv sign bs\\<rbrakk> C (get_time tw + 1) = Lv sign bs\"\n          using *[THEN sym] True unfolding worldline_inert_upd2_def VHDL_Hoare.worldline_inert_upd2.simps comp_def snd_conv fun_upd_def\n          by auto\n        moreover have \" wline_of tw\\<lbrakk> C, 1 :=\\<^sub>2 Lv sign bs\\<rbrakk> C j =  Lv sign bs\"\n          using Lv True \\<open>?time = fst tw + 1\\<close> **\n          unfolding worldline_inert_upd2_def comp_def snd_conv VHDL_Hoare.worldline_inert_upd2.simps\n            fun_upd_def by auto\n        ultimately show ?thesis\n          by auto\n      next\n        case False\n        then show ?thesis\n          using Lv * **\n          unfolding worldline_inert_upd2_def comp_def snd_conv VHDL_Hoare.worldline_inert_upd2.simps\n          fun_upd_def by auto \n      qed\n    qed }\n  thus \"inv2 (fst tw' + 1, snd tw')\"\n    unfolding inv2_def by (simp add: tw'_def worldline_inert_upd2_def)\nqed\n\nlemma add_conc_hoare:\n  \"\\<And>tw. inv tw \\<and> inv2 tw \\<and> disjnt {A, B} (event_of tw) \\<Longrightarrow> inv (fst tw + 1, snd tw)\"\nproof -\n  fix tw\n  assume \"inv tw \\<and> inv2 tw \\<and> disjnt {A, B} (event_of tw)\"\n  hence \"inv tw\" and \"inv2 tw\" and \"disjnt {A, B} (event_of tw)\"\n    by auto\n  have \"lof_wline tw C (fst tw + 1) = lof_wline tw C (fst tw)\"\n    using `inv2 tw` `disjnt {A, B} (event_of tw)` unfolding inv2_def by auto \n  also have \"... = bin_to_bl len (sbl_to_bin (lval_of (wline_of tw A (get_time tw - 1))) + sbl_to_bin (lval_of (wline_of tw B (get_time tw - 1))))\"\n    using `inv tw` unfolding inv_def by auto\n  also have \"... = bin_to_bl len (sbl_to_bin (lval_of (wline_of tw A (fst tw))) + sbl_to_bin (lval_of (wline_of tw B (fst tw))))\"\n    using `disjnt {A, B} (event_of tw)`  unfolding event_of_alt_def  \n    by (smt diff_0_eq_0 disjnt_insert1 mem_Collect_eq)\n  finally show \"inv (fst tw + 1, snd tw)\"\n    unfolding inv_def by auto\nqed\n\nlemma add_conc_hoare2:\n  \"\\<And>tw. inv2 tw \\<and> disjnt {A, B} (event_of tw) \\<Longrightarrow> inv2 (fst tw + 1, snd tw)\"\n  unfolding inv2_def by auto\n\nlemma conc_stmt_wf_add:\n  \"conc_stmt_wf add\"\n  unfolding add_def conc_stmt_wf_def by auto  \n\nlemma nonneg_delay_conc_add:\n  \"nonneg_delay_conc add\"\n  unfolding add_def by auto\n\nlemma nonneg_delay_conc_add':\n  \"nonneg_delay_conc ( process {A, B} : Bassign_inert C (Badd (Bsig A) (Bsig B)) 1)\"\n  using nonneg_delay_conc_add unfolding add_def by auto\n\nlemma conc_wt_add:\n  \"conc_wt \\<Gamma> add\"\n  unfolding add_def  by (meson conc_wt.intros(1) seq_wt.intros(5) seq_wt_cases(4) well_typed)\n\nlemma conc_wt_add':\n  \"conc_wt \\<Gamma> ( process {A, B} : Bassign_inert C (Badd (Bsig A) (Bsig B)) 1)\"\n  using conc_wt_add unfolding add_def by auto\n\nlemma add_conc_sim2':\n  \"\\<Gamma> \\<turnstile>\\<^sub>s \\<lbrace>\\<lambda>tw. inv tw \\<and> inv2 tw\\<rbrace> add \\<lbrace>\\<lambda>tw. inv tw \\<and> inv2 tw\\<rbrace>\"\n  apply (rule While_Suc)\n  apply (rule Conseq'[where P=\"wp3_conc \\<Gamma> add (\\<lambda>tw. inv  (fst tw + 1, snd tw) \\<and> \n                                                    inv2 (fst tw + 1, snd tw))\", rotated])\n  apply (rule wp3_conc_is_pre, rule conc_stmt_wf_add, rule nonneg_delay_conc_add, rule conc_wt_add, simp)\n  unfolding add_def  wp3_conc_single'[OF conc_wt_add' nonneg_delay_conc_add'] wp3_fun.simps\n  using inv_next_time inv2_next_time add_conc_hoare add_conc_hoare2 by presburger\n\ntext \\<open>Initialisation preserves the invariant\\<close>\n\nlemma nonneg_delay_add:\n  \" nonneg_delay (Bassign_inert C (Badd (Bsig A) (Bsig B)) 1)\"\n  using nonneg_delay_conc_add' by auto\n\nlemma init_sat_nand_inv_comb:\n  \"init_sim2_hoare_wt \\<Gamma> (\\<lambda>tw. fst tw = 0) add (\\<lambda>tw. inv tw \\<and> inv2 tw)\"\n  unfolding add_def\n  apply (rule AssignI_suc, rule SingleI)\n  apply (rule Conseq3[where Q=\"\\<lambda>tw. inv (fst tw + 1, snd tw) \\<and> inv2 (fst tw + 1, snd tw)\", rotated])\n  apply (rule wp3_fun_is_pre[OF well_typed nonneg_delay_add], simp)\n  unfolding wp3_fun.simps using inv_next_time inv2_next_time by blast\n\nlemma correctness:\n  assumes \"sim_fin2 w (i + 1) add tw'\" and \"wityping \\<Gamma> w\"\n  shows \"lof_wline tw' C (i + 1) = bin_to_bl len (sbl_to_bin (lof_wline tw' A i) + sbl_to_bin (lof_wline tw' B i))\"\n  using grand_correctness[OF assms conc_stmt_wf_add conc_wt_add nonneg_delay_conc_add add_conc_sim2' init_sat_nand_inv_comb]\n  unfolding add_def inv_def by (metis (no_types, lifting) add_diff_cancel_right' assms(1)\n  sim_fin2.cases world_maxtime_lt_fst_tres)\nend\n\nend\n", "meta": {"author": "rizaldialbert", "repo": "vhdl-semantics", "sha": "352f89c9ccdfe830c054757dfd86caeadbd67159", "save_path": "github-repos/isabelle/rizaldialbert-vhdl-semantics", "path": "github-repos/isabelle/rizaldialbert-vhdl-semantics/vhdl-semantics-352f89c9ccdfe830c054757dfd86caeadbd67159/Signed_Add_Inert_Typed.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5078118642792044, "lm_q2_score": 0.5544704649604273, "lm_q1q2_score": 0.2815666804993119}}
{"text": "(*  File:       Loop_Composition.thy\n    Copyright   2021  Karlsruhe Institute of Technology (KIT)\n*)\n\\<^marker>\\<open>creator \"Karsten Diekhoff, Karlsruhe Institute of Technology (KIT)\"\\<close>\n\\<^marker>\\<open>contributor \"Jonas Kraemer, Karlsruhe Institute of Technology (KIT)\"\\<close>\n\\<^marker>\\<open>contributor \"Michael Kirsten, Karlsruhe Institute of Technology (KIT)\"\\<close>\n\nsection \\<open>Loop Composition\\<close>\n\ntheory Loop_Composition\n  imports \"Basic_Modules/Component_Types/Termination_Condition\"\n          \"Basic_Modules/Defer_Module\"\n          Sequential_Composition\nbegin\n\ntext\n\\<open>The loop composition uses the same module in sequence,\ncombined with a termination condition, until either\n  (1) the termination condition is met or\n  (2) no new decisions are made (i.e., a fixed point is reached).\\<close>\n\nsubsection \\<open>Definition\\<close>\n\nlemma loop_termination_helper:\n  assumes             \n    not_term: \"\\<not>t (acc A p vs)\" and\n    subset: \"defer (acc \\<triangleright> m) A p vs \\<subset> defer acc A p vs\" and\n    not_inf: \"\\<not>infinite (defer acc A p vs)\"\n  shows\n    \"((acc \\<triangleright> m, m, t, A, p, vs), (acc, m, t, A, p, vs)) \\<in>\n        measure (\\<lambda>(acc, m, t, A, p, vs). card (defer acc A p vs))\"\n  using assms psubset_card_mono\n  by auto\n\n(*\n   This function handles the accumulator for the following loop composition\n   function.\n*)\nfunction loop_comp_helper ::\n    \"'a Electoral_Module \\<Rightarrow> 'a Electoral_Module \\<Rightarrow>\n        'a Termination_Condition \\<Rightarrow> 'a Electoral_Module\" where\n  \"t (acc A p vs) \\<or> \\<not>((defer (acc \\<triangleright> m) A p vs) \\<subset> (defer acc A p vs)) \\<or>\n    infinite (defer acc A p vs) \\<Longrightarrow>\n      loop_comp_helper acc m t A p vs = acc A p vs\" |\n  \"\\<not>(t (acc A p vs) \\<or> \\<not>((defer (acc \\<triangleright> m) A p vs) \\<subset> (defer acc A p vs)) \\<or>\n    infinite (defer acc A p vs)) \\<Longrightarrow>\n      loop_comp_helper acc m t A p vs = loop_comp_helper (acc \\<triangleright> m) m t A p vs\"\nproof -\n  fix\n    P :: bool and\n    x :: \"('a Electoral_Module) \\<times> ('a Electoral_Module) \\<times>\n          ('a Termination_Condition) \\<times> 'a set \\<times> 'a Profile \\<times> 'a Pair_Vectors\"\n  assume\n    a1: \"\\<And>t acc A p vs m.\n          \\<lbrakk>t (acc A p vs) \\<or> \\<not> defer (acc \\<triangleright> m) A p vs \\<subset> defer acc A p vs \\<or>\n              infinite (defer acc A p vs);\n            x = (acc, m, t, A, p, vs)\\<rbrakk> \\<Longrightarrow> P\" and\n    a2: \"\\<And>t acc A p vs m.\n          \\<lbrakk>\\<not> (t (acc A p vs) \\<or> \\<not> defer (acc \\<triangleright> m) A p vs \\<subset> defer acc A p vs \\<or>\n              infinite (defer acc A p vs));\n            x = (acc, m, t, A, p, vs)\\<rbrakk> \\<Longrightarrow> P\"\n  have \"\\<exists>f A p p2 g vs. (g, f, p, A, p2, vs) = x\"\n    using prod_cases5\n    by metis\n  then show P\n    using a2 a1\n    by (metis (no_types))\nnext\n  show\n    \"\\<And>t acc A p vs m ta acca Aa pa vsa ma.\n       t (acc A p vs) \\<or> \\<not> defer (acc \\<triangleright> m) A p vs \\<subset> defer acc A p vs \\<or>\n        infinite (defer acc A p vs) \\<Longrightarrow>\n          ta (acca Aa pa vsa) \\<or> \\<not> defer (acca \\<triangleright> ma) Aa pa vsa \\<subset> defer acca Aa pa vsa \\<or>\n          infinite (defer acca Aa pa vsa) \\<Longrightarrow>\n           (acc, m, t, A, p, vs) = (acca, ma, ta, Aa, pa, vsa) \\<Longrightarrow>\n              acc A p vs= acca Aa pa vsa\"\n    by fastforce\nnext\n  show\n    \"\\<And>t acc A p vs m ta acca Aa pa vsa ma.\n       t (acc A p vs) \\<or> \\<not> defer (acc \\<triangleright> m) A p vs \\<subset> defer acc A p vs \\<or>\n        infinite (defer acc A p vs) \\<Longrightarrow>\n          \\<not> (ta (acca Aa pa vsa) \\<or> \\<not> defer (acca \\<triangleright> ma) Aa pa vsa \\<subset> defer acca Aa pa vsa \\<or>\n          infinite (defer acca Aa pa vsa)) \\<Longrightarrow>\n           (acc, m, t, A, p, vs) = (acca, ma, ta, Aa, pa, vsa) \\<Longrightarrow>\n              acc A p vs = loop_comp_helper_sumC (acca \\<triangleright> ma, ma, ta, Aa, pa, vsa)\"\n  proof -\n    fix\n      t :: \"'a Termination_Condition\" and\n      acc :: \"'a Electoral_Module\" and\n      A :: \"'a set\" and\n      p :: \"'a Profile\" and\n      vs :: \"'a Pair_Vectors\" and\n      m :: \"'a Electoral_Module\" and\n      ta :: \"'a Termination_Condition\" and\n      acca :: \"'a Electoral_Module\" and\n      Aa :: \"'a set\" and\n      pa :: \"'a Profile\" and\n      vsa :: \"'a Pair_Vectors\" and\n      ma :: \"'a Electoral_Module\"\n    assume\n      a1: \"t (acc A p vs) \\<or> \\<not> defer (acc \\<triangleright> m) A p vs \\<subset> defer acc A p vs \\<or>\n            infinite (defer acc A p vs)\" and\n      a2: \"\\<not> (ta (acca Aa pa vsa) \\<or> \\<not> defer (acca \\<triangleright> ma) Aa pa vsa \\<subset> defer acca Aa pa vsa \\<or>\n            infinite (defer acca Aa pa vsa))\" and\n      \"(acc, m, t, A, p, vs) = (acca, ma, ta, Aa, pa, vsa)\"\n    hence False\n      using a2 a1\n      by force\n  thus \"acc A p vs = loop_comp_helper_sumC (acca \\<triangleright> ma, ma, ta, Aa, pa, vsa)\"\n    by auto\nqed\nnext\n  show\n    \"\\<And>t acc A p vs m ta acca Aa pa vsa ma.\n       \\<not> (t (acc A p vs) \\<or> \\<not> defer (acc \\<triangleright> m) A p vs \\<subset> defer acc A p vs \\<or>\n          infinite (defer acc A p vs)) \\<Longrightarrow>\n           \\<not> (ta (acca Aa pa vsa) \\<or> \\<not> defer (acca \\<triangleright> ma) Aa pa vsa \\<subset> defer acca Aa pa vsa \\<or>\n            infinite (defer acca Aa pa vsa)) \\<Longrightarrow>\n             (acc, m, t, A, p, vs) = (acca, ma, ta, Aa, pa, vsa) \\<Longrightarrow>\n                loop_comp_helper_sumC (acc \\<triangleright> m, m, t, A, p, vs) =\n                  loop_comp_helper_sumC (acca \\<triangleright> ma, ma, ta, Aa, pa, vsa)\"\n    by force\nqed\ntermination\nproof - \n  have f0:\n    \"\\<exists>r. wf r \\<and>\n        (\\<forall>p f (A::'a set) prof g vs.\n          p (f A prof vs) \\<or>\n          \\<not> defer (f \\<triangleright> g) A prof vs \\<subset> defer f A prof vs \\<or>\n          infinite (defer f A prof vs) \\<or>\n          ((f \\<triangleright> g, g, p, A, prof, vs), (f, g, p, A, prof, vs)) \\<in> r)\"\n    using loop_termination_helper wf_measure \"termination\" \n    by (metis (no_types))\n  hence\n    \"\\<forall>r p.\n      Ex ((\\<lambda>ra. \\<forall>f (A::'a set) prof pa g vs.\n            \\<exists>prof2 pb p_rel pc pd h (B::'a set) prof3 i pe vs1.\n        \\<not> wf r \\<or>\n          loop_comp_helper_dom\n            (p::('a Electoral_Module) \\<times> (_ Electoral_Module) \\<times>\n              (_ Termination_Condition) \\<times> _ set \\<times> _ Profile \\<times> _ Pair_Vectors) \\<or>\n          infinite (defer f A prof vs) \\<or>\n          pa (f A prof vs) \\<and>\n            wf\n              (prof2::((\n                ('a Electoral_Module) \\<times> ('a Electoral_Module) \\<times>\n                ('a Termination_Condition) \\<times> 'a set \\<times> 'a Profile \\<times> 'a Pair_Vectors) \\<times> _) set) \\<and>\n            \\<not> loop_comp_helper_dom (pb::\n                ('a Electoral_Module) \\<times> (_ Electoral_Module) \\<times>\n                (_ Termination_Condition) \\<times> _ set \\<times> _ Profile \\<times> _ Pair_Vectors) \\<or>\n          wf p_rel \\<and> \\<not> defer (f \\<triangleright> g) A prof vs \\<subset> defer f A prof vs \\<and>\n            \\<not> loop_comp_helper_dom\n                (pc::('a Electoral_Module) \\<times> (_ Electoral_Module) \\<times>\n                  (_ Termination_Condition) \\<times> _ set \\<times> _ Profile \\<times> _ Pair_Vectors) \\<or>\n            ((f \\<triangleright> g, g, pa, A, prof, vs), f, g, pa, A, prof, vs) \\<in> p_rel \\<and> wf p_rel \\<and>\n            \\<not> loop_comp_helper_dom\n                (pd::('a Electoral_Module) \\<times> (_ Electoral_Module) \\<times>\n                  (_ Termination_Condition) \\<times> _ set \\<times> _ Profile \\<times> _ Pair_Vectors) \\<or>\n            finite (defer h B prof3 vs1) \\<and>\n            defer (h \\<triangleright> i) B prof3 vs1 \\<subset> defer h B prof3 vs1\\<and>\n            \\<not> pe (h B prof3 vs1) \\<and>\n            ((h \\<triangleright> i, i, pe, B, prof3, vs1), h, i, pe, B, prof3, vs1) \\<notin> r)::\n          ((('a Electoral_Module) \\<times> ('a Electoral_Module) \\<times>\n            ('a Termination_Condition) \\<times> 'a set \\<times> 'a Profile \\<times> 'a Pair_Vectors) \\<times>\n            ('a Electoral_Module) \\<times> ('a Electoral_Module) \\<times>\n            ('a Termination_Condition) \\<times> 'a set \\<times> 'a Profile \\<times> 'a Pair_Vectors) set \\<Rightarrow> bool)\"\n    by metis\n  obtain\n    p_rel ::  \"((('a Electoral_Module) \\<times> ('a Electoral_Module) \\<times>\n               ('a Termination_Condition) \\<times> 'a set \\<times> 'a Profile \\<times> 'a Pair_Vectors) \\<times>\n               ('a Electoral_Module) \\<times> ('a Electoral_Module) \\<times>\n               ('a Termination_Condition) \\<times> 'a set \\<times> 'a Profile \\<times> 'a Pair_Vectors) set\" where\n      \"wf p_rel \\<and>\n        (\\<forall>p f A prof g vs. p (f A prof vs) \\<or>\n          \\<not> defer (f \\<triangleright> g) A prof vs \\<subset> defer f A prof vs \\<or>\n          infinite (defer f A prof vs) \\<or>\n          ((f \\<triangleright> g, g, p, A, prof, vs), f, g, p, A, prof, vs) \\<in> p_rel)\"\n    using f0\n    by presburger\n  thus ?thesis\n    using \"termination\" \n    by metis\nqed\n\nlemma loop_comp_code_helper[code]:\n  \"loop_comp_helper acc m t A p vs =\n    (if (t (acc A p vs) \\<or> \\<not>((defer (acc \\<triangleright> m) A p vs) \\<subset> (defer acc A p vs)) \\<or>\n      infinite (defer acc A p vs))\n    then (acc A p vs) else (loop_comp_helper (acc \\<triangleright> m) m t A p vs))\" \n  by simp \n  \n\nfunction loop_composition ::\n    \"'a Electoral_Module \\<Rightarrow> 'a Termination_Condition \\<Rightarrow>\n        'a Electoral_Module\" where\n  \"t ({}, {}, A) \\<Longrightarrow>\n    loop_composition m t A p vs = defer_module A p vs\" |\n  \"\\<not>(t ({}, {}, A)) \\<Longrightarrow>\n    loop_composition m t A p vs = (loop_comp_helper m m t) A p vs\"\n  by (fastforce, simp_all)\ntermination\n  using  \"termination\" wf_empty\n  by blast\n\nabbreviation loop ::\n  \"'a Electoral_Module \\<Rightarrow> 'a Termination_Condition \\<Rightarrow> 'a Electoral_Module\"\n    (\"_ \\<circlearrowleft>\\<^sub>_\" 50) where\n  \"m \\<circlearrowleft>\\<^sub>t \\<equiv> loop_composition m t\"\n\nlemma loop_comp_code[code]:\n  \"loop_composition m t A p vs =\n    (if (t ({},{},A))\n    then (defer_module A p vs) else (loop_comp_helper m m t) A p vs)\"\n  by simp\n\nlemma loop_comp_helper_imp_partit:\n  assumes\n    module_m: \"electoral_module m\" and\n    profile: \"finite_profile A p\" and\n    vectors: \"finite_pair_vectors A vs\"\n  shows\n    \"electoral_module acc \\<and> (n = card (defer acc A p vs)) \\<Longrightarrow>\n        well_formed A (loop_comp_helper acc m t A p vs)\"\nproof (induct arbitrary: acc rule: less_induct)\n  case (less)\n  have\n    \"\\<forall>(f::'a set \\<Rightarrow> 'a Profile \\<Rightarrow> 'a Pair_Vectors \\<Rightarrow> 'a Result) g.\n      (electoral_module f \\<and> electoral_module g) \\<longrightarrow>\n        electoral_module (f \\<triangleright> g)\"\n    by auto\n  hence \"electoral_module (acc \\<triangleright> m)\"\n    using less.prems module_m\n    by metis\n  hence wf_acc:\n    \"\\<not> t (acc A p vs) \\<and> \\<not> t (acc A p vs) \\<and>\n      defer (acc \\<triangleright> m) A p vs \\<subset> defer acc A p vs \\<and>\n      finite (defer acc A p vs) \\<longrightarrow>\n        well_formed A (loop_comp_helper acc m t A p vs)\"\n    using less.hyps less.prems loop_comp_helper.simps(2)\n          psubset_card_mono\n  by metis\n  have \"well_formed A (acc A p vs)\"\n    using electoral_module_def less.prems profile vectors\n    by blast\n  thus ?case\n    using wf_acc loop_comp_helper.simps(1)\n    by (metis (no_types))\nqed\n\nsubsection \\<open>Soundness\\<close>\n\ntheorem loop_comp_sound:\n  assumes m_module: \"electoral_module m\"\n  shows \"electoral_module (m \\<circlearrowleft>\\<^sub>t)\"\n  using def_mod_sound electoral_module_def loop_composition.simps(1)\n        loop_composition.simps(2) loop_comp_helper_imp_partit m_module\n  by metis\n\nlemma loop_comp_helper_imp_no_def_incr:\n  assumes\n    module_m: \"electoral_module m\"\n  shows\n    \"(electoral_module acc \\<and> n = card (defer acc A p vs)) \\<Longrightarrow>\n        defer (loop_comp_helper acc m t) A p vs \\<subseteq> defer acc A p vs\"\nproof (induct arbitrary: acc rule: less_induct)\n  case (less)\n  have emod_acc_m: \"electoral_module (acc \\<triangleright> m)\"\n    using less.prems module_m\n    by simp\n  have \"\\<forall>A Aa. infinite (A::'a set) \\<or> \\<not> Aa \\<subset> A \\<or> card Aa < card A\"\n    using psubset_card_mono\n    by metis\n  hence\n    \"\\<not> t (acc A p vs) \\<and> defer (acc \\<triangleright> m) A p vs \\<subset> defer acc A p vs \\<and>\n      finite (defer acc A p vs) \\<longrightarrow>\n        defer (loop_comp_helper (acc \\<triangleright> m) m t) A p vs \\<subseteq> defer acc A p vs\"\n    using emod_acc_m less.hyps less.prems\n    by blast\n  hence\n    \"\\<not> t (acc A p vs) \\<and> defer (acc \\<triangleright> m) A p vs \\<subset> defer acc A p vs \\<and>\n        finite (defer acc A p vs) \\<longrightarrow>\n          defer (loop_comp_helper acc m t) A p vs \\<subseteq> defer acc A p vs\"\n    using loop_comp_helper.simps(2)\n    by (metis (no_types))\n  thus ?case\n    using eq_iff loop_comp_helper.simps(1)\n    by (metis (no_types))\nqed\n\nsubsection \\<open>Lemmata\\<close>\n\nlemma loop_comp_helper_def_lift_inv_helper:\n  assumes\n    monotone_m: \"defer_lift_invariance m\" and\n    f_prof: \"finite_profile A p\" and\n    f_vec: \"finite_pair_vectors A vs\"\n  shows\n    \"(defer_lift_invariance acc \\<and> n = card (defer acc A p vs)) \\<longrightarrow>\n        (\\<forall>q a.\n          (a \\<in> (defer (loop_comp_helper acc m t) A p vs) \\<and> finite_pair_vectors A vs \\<and>\n            lifted A p q a) \\<longrightarrow>\n                (loop_comp_helper acc m t) A p vs =\n                  (loop_comp_helper acc m t) A q vs)\"\nproof (induct n arbitrary: acc rule: less_induct)\n  case (less n)\n  have defer_card_comp:\n    \"defer_lift_invariance acc \\<longrightarrow>\n        (\\<forall>q a. (a \\<in> (defer (acc \\<triangleright> m) A p vs) \\<and> finite_pair_vectors A vs \\<and> lifted A p q a) \\<longrightarrow>\n            card (defer (acc \\<triangleright> m) A p vs) = card (defer (acc \\<triangleright> m) A q vs))\"\n    using monotone_m def_lift_inv_seq_comp_help \n    by metis\n  have defer_card_acc:\n    \"defer_lift_invariance acc \\<longrightarrow>\n        (\\<forall>q a. (a \\<in> (defer (acc) A p vs) \\<and> finite_pair_vectors A vs \\<and> lifted A p q a) \\<longrightarrow>\n            card (defer (acc) A p vs) = card (defer (acc) A q vs))\"\n    by (smt (verit, del_insts) defer_lift_invariance_def)\n  hence defer_card_acc_2:\n    \"defer_lift_invariance acc \\<longrightarrow>\n        (\\<forall>q a. (a \\<in> (defer (acc \\<triangleright> m) A p vs) \\<and> finite_pair_vectors A vs \\<and> lifted A p q a) \\<longrightarrow>\n            card (defer (acc) A p vs) = card (defer (acc) A q vs))\"\n    using monotone_m f_prof defer_lift_invariance_def seq_comp_def_set_trans \n    by metis\n  thus ?case\n  proof cases\n    assume card_unchanged: \"card (defer (acc \\<triangleright> m) A p vs) = card (defer acc A p vs)\"\n    with defer_card_comp defer_card_acc monotone_m\n    have\n      \"defer_lift_invariance (acc) \\<longrightarrow>\n          (\\<forall>q a. (a \\<in> (defer (acc) A p vs) \\<and> finite_pair_vectors A vs \\<and> lifted A p q a) \\<longrightarrow>\n              (loop_comp_helper acc m t) A q vs= acc A q vs)\"\n    proof (safe)\n      fix\n        q :: \"'a Profile\" and\n        a :: \"'a\"\n      assume\n        def_card_eq:\n        \"card (defer (acc \\<triangleright> m) A p vs) = card (defer acc A p vs)\" and\n        dli_acc: \"defer_lift_invariance acc\" and\n        def_seq_lift_card:\n        \"\\<forall>q a. a \\<in> defer (acc \\<triangleright> m) A p vs \\<and> finite_pair_vectors A vs \\<and> Profile.lifted A p q a \\<longrightarrow>\n          card (defer (acc \\<triangleright> m) A p vs) = card (defer (acc \\<triangleright> m) A q vs)\" and\n        a_in_def_acc: \"a \\<in> defer acc A p vs\" and\n        lifted_A: \"Profile.lifted A p q a\"  \n      have emod_m: \"electoral_module m\"\n        using defer_lift_invariance_def monotone_m\n        by auto\n      have emod_acc: \"electoral_module acc\"\n        using defer_lift_invariance_def dli_acc\n        by blast\n       have acc_eq_pq: \"acc A q vs = acc A p vs\"\n        using a_in_def_acc defer_lift_invariance_def dli_acc lifted_A f_vec\n        by (metis (full_types))\n      with emod_acc emod_m\n      have\n        \"finite (defer acc A p vs) \\<longrightarrow>\n          loop_comp_helper acc m t A q vs = acc A q vs\"\n        using a_in_def_acc def_card_eq def_seq_lift_card\n              dual_order.strict_iff_order f_prof lifted_A\n              loop_comp_code_helper psubset_card_mono\n              seq_comp_def_set_bounded f_vec\n        by (metis (no_types))\n      thus \"loop_comp_helper acc m t A q vs = acc A q vs\"\n        using acc_eq_pq loop_comp_code_helper\n        by (metis (full_types))\n    qed\n    moreover from card_unchanged have\n      \"(loop_comp_helper acc m t) A p vs = acc A p vs\"\n      using loop_comp_helper.simps(1) order.strict_iff_order\n            psubset_card_mono\n      by metis\n    ultimately have\n      \"(defer_lift_invariance (acc \\<triangleright> m) \\<and> defer_lift_invariance acc) \\<longrightarrow>\n          (\\<forall>q a. (a \\<in> (defer (loop_comp_helper acc m t) A p vs) \\<and>\n              finite_pair_vectors A vs \\<and> lifted A p q a) \\<longrightarrow>\n                  (loop_comp_helper acc m t) A p vs =\n                    (loop_comp_helper acc m t) A q vs)\"\n      using defer_lift_invariance_def \n      by metis\n    thus ?thesis\n      using monotone_m seq_comp_presv_def_lift_inv  \n      by blast\n  next\n    assume card_changed:\n      \"\\<not> (card (defer (acc \\<triangleright> m) A p vs) = card (defer acc A p vs))\"\n    with f_prof seq_comp_def_card_bounded have card_smaller_for_p:\n      \"electoral_module (acc) \\<longrightarrow>\n          (card (defer (acc \\<triangleright> m) A p vs) < card (defer acc A p vs))\"\n      using monotone_m order.not_eq_order_implies_strict\n            defer_lift_invariance_def f_vec\n      by (metis (full_types))\n    with defer_card_acc_2 defer_card_comp\n    have card_changed_for_q:\n      \"defer_lift_invariance (acc) \\<longrightarrow>\n          (\\<forall>q a. (a \\<in> (defer (acc \\<triangleright> m) A p vs) \\<and> finite_pair_vectors A vs \\<and> lifted A p q a) \\<longrightarrow>\n              (card (defer (acc \\<triangleright> m) A q vs) < card (defer acc A q vs)))\"\n      using defer_lift_invariance_def\n      by (metis (no_types, lifting))\n    thus ?thesis\n    proof cases\n      assume t_not_satisfied_for_p: \"\\<not> t (acc A p vs)\"\n      hence t_not_satisfied_for_q:\n        \"defer_lift_invariance (acc) \\<longrightarrow>\n            (\\<forall>q a. (a \\<in> (defer (acc \\<triangleright> m) A p vs) \\<and> finite_pair_vectors A vs \\<and> lifted A p q a) \\<longrightarrow>\n                \\<not> t (acc A q vs))\"\n        using monotone_m f_prof defer_lift_invariance_def seq_comp_def_set_trans \n        by metis\n      from card_changed defer_card_comp defer_card_acc\n      have dli_card_def:\n        \"(defer_lift_invariance (acc \\<triangleright> m) \\<and> defer_lift_invariance (acc)) \\<longrightarrow>\n            (\\<forall>q a. (a \\<in> (defer (acc \\<triangleright> m) A p vs) \\<and> finite_pair_vectors A vs \\<and>\n               Profile.lifted A p q a) \\<longrightarrow>\n                card (defer (acc \\<triangleright> m) A q vs) \\<noteq> (card (defer acc A q vs)))\"\n      proof -\n        have\n          \"\\<forall>f.\n            (defer_lift_invariance f \\<or>\n              (\\<exists>A prof prof2 (a::'a) vs.\n                f A prof vs \\<noteq> f A prof2 vs \\<and>\n                  Profile.lifted A prof prof2 a \\<and>\n                  finite_pair_vectors A vs \\<and>\n                  a \\<in> defer f A prof vs) \\<or> \\<not> electoral_module f) \\<and>\n                  ((\\<forall>A p1 p2 b vs. f A p1 vs = f A p2 vs \\<or> \\<not> Profile.lifted A p1 p2 b \\<or>\n                    \\<not> finite_pair_vectors A vs \\<or> b \\<notin> defer f A p1 vs) \\<and>\n                  electoral_module f \\<or> \\<not> defer_lift_invariance f)\"\n          using defer_lift_invariance_def by blast\n        thus ?thesis\n          using card_changed monotone_m f_prof seq_comp_def_set_trans \n          by (metis (no_types, hide_lams))\n      qed\n      hence dli_def_subset:\n        \"defer_lift_invariance (acc \\<triangleright> m) \\<and> defer_lift_invariance (acc) \\<longrightarrow>\n            (\\<forall>q a. (a \\<in> (defer (acc \\<triangleright> m) A p vs) \\<and> finite_pair_vectors A vs \\<and> lifted A p q a) \\<longrightarrow>\n                defer (acc \\<triangleright> m) A q vs \\<subset> defer acc A q vs)\"\n      proof -\n        {\n          fix\n            alt :: 'a and\n            prof :: \"'a Profile\"\n          have\n            \"(\\<not> defer_lift_invariance (acc \\<triangleright> m) \\<or> \\<not> defer_lift_invariance acc) \\<or>\n              (alt \\<notin> defer (acc \\<triangleright> m) A p vs \\<or> \\<not> finite_pair_vectors A vs \\<or> \\<not> lifted A p prof alt) \\<or>\n              defer (acc \\<triangleright> m) A prof vs \\<subset> defer acc A prof vs\"\n            using Profile.lifted_def dli_card_def defer_lift_invariance_def\n                  monotone_m psubsetI seq_comp_def_set_bounded \n            by (metis (no_types))\n        }\n        thus ?thesis\n          by metis\n      qed\n      with t_not_satisfied_for_p\n      have rec_step_q:\n        \"(defer_lift_invariance (acc \\<triangleright> m) \\<and> defer_lift_invariance (acc)) \\<longrightarrow>\n            (\\<forall>q a. (a \\<in> (defer (acc \\<triangleright> m) A p vs) \\<and> finite_pair_vectors A vs \\<and> lifted A p q a) \\<longrightarrow>\n                loop_comp_helper acc m t A q vs=\n                  loop_comp_helper (acc \\<triangleright> m) m t A q vs)\"\n      proof (safe)\n        fix\n          q :: \"'a Profile\" and\n          a :: \"'a\"\n        assume\n          a_in_def_impl_def_subset:\n          \"\\<forall>q a. a \\<in> defer (acc \\<triangleright> m) A p vs \\<and> finite_pair_vectors A vs \\<and> lifted A p q a \\<longrightarrow>\n            defer (acc \\<triangleright> m) A q vs \\<subset> defer acc A q vs\" and\n          dli_acc: \"defer_lift_invariance acc\" and\n          a_in_def_seq_acc_m: \"a \\<in> defer (acc \\<triangleright> m) A p vs\" and\n          lifted_pq_a: \"lifted A p q a\" and\n          vec_A: \"vector_pair A vs\"\n        have defer_subset_acc:\n          \"defer (acc \\<triangleright> m) A q vs \\<subset> defer acc A q vs\"\n          using a_in_def_impl_def_subset lifted_pq_a\n                a_in_def_seq_acc_m vec_A f_prof\n          by metis\n        have \"electoral_module acc\"\n          using dli_acc defer_lift_invariance_def\n          by auto\n        hence \"finite (defer acc A q vs) \\<and> \\<not> t (acc A q vs)\"\n          using lifted_def dli_acc a_in_def_seq_acc_m\n                lifted_pq_a def_presv_fin_prof\n                t_not_satisfied_for_q vec_A f_prof \n          by metis\n        with defer_subset_acc\n        show\n          \"loop_comp_helper acc m t A q vs=\n            loop_comp_helper (acc \\<triangleright> m) m t A q vs\"\n          using loop_comp_code_helper \n          by metis\n      qed\n      have rec_step_p:\n        \"electoral_module acc \\<longrightarrow>\n            loop_comp_helper acc m t A p vs = loop_comp_helper (acc \\<triangleright> m) m t A p vs\"\n      proof (safe)\n        assume emod_acc: \"electoral_module acc\"\n        have emod_implies_defer_subset:\n          \"electoral_module m \\<longrightarrow> defer (acc \\<triangleright> m) A p vs \\<subseteq> defer acc A p vs\"\n          using emod_acc f_prof seq_comp_def_set_bounded f_vec\n          by blast\n        have card_ineq: \"card (defer (acc \\<triangleright> m) A p vs) < card (defer acc A p vs)\"\n          using card_smaller_for_p emod_acc\n          by force\n        have fin_def_limited_acc:\n          \"finite_profile (defer acc A p vs) (limit_profile (defer acc A p vs) p)\"\n          using def_presv_fin_prof emod_acc f_prof f_vec\n          by metis\n        have \"defer (acc \\<triangleright> m) A p vs \\<subseteq> defer acc A p vs\"\n          using emod_implies_defer_subset defer_lift_invariance_def monotone_m\n          by blast\n        hence \"defer (acc \\<triangleright> m) A p vs \\<subset> defer acc A p vs\"\n          using fin_def_limited_acc card_ineq card_psubset\n          by metis\n        with fin_def_limited_acc\n        show \"loop_comp_helper acc m t A p vs = loop_comp_helper (acc \\<triangleright> m) m t A p vs\"\n          using loop_comp_code_helper t_not_satisfied_for_p\n          by (metis (no_types))\n      qed\n      show ?thesis\n      proof (safe)\n        fix\n          q :: \"'a Profile\" and\n          a :: \"'a\"\n        assume\n          dli_acc: \"defer_lift_invariance acc\" and\n          n_card_acc: \"n = card (defer acc A p vs)\" and\n          a_in_defer_lch: \"a \\<in> defer (loop_comp_helper acc m t) A p vs\" and\n          a_lifted: \"Profile.lifted A p q a\"\n        hence emod_acc: \"electoral_module acc\"\n          using defer_lift_invariance_def\n          by metis\n        have \"defer_lift_invariance (acc \\<triangleright> m) \\<and> a \\<in> defer (acc \\<triangleright> m) A p vs\"\n          using a_in_defer_lch defer_lift_invariance_def dli_acc\n                f_prof loop_comp_helper_imp_no_def_incr monotone_m\n                rec_step_p seq_comp_presv_def_lift_inv subsetD f_vec\n          by (metis (no_types))\n        with emod_acc\n        show \"loop_comp_helper acc m t A p vs = loop_comp_helper acc m t A q vs\"\n          using a_in_defer_lch a_lifted card_smaller_for_p dli_acc\n                less.hyps n_card_acc rec_step_p rec_step_q f_vec\n          by (metis (full_types))\n      qed\n    next\n      assume \"\\<not> \\<not>t (acc A p vs)\"\n      with defer_lift_invariance_def\n      show ?thesis\n        using loop_comp_helper.simps(1) f_vec\n        by metis\n    qed\n  qed\nqed\n\nlemma loop_comp_helper_def_lift_inv:\n  assumes\n    monotone_m: \"defer_lift_invariance m\" and\n    monotone_acc: \"defer_lift_invariance acc\" and\n    profile: \"finite_profile A p\" and\n    vector: \"finite_pair_vectors A vs\"\n    \n  shows\n    \"\\<forall>q a. (lifted A p q a \\<and> a \\<in> (defer (loop_comp_helper acc m t) A p vs)) \\<longrightarrow>\n        (loop_comp_helper acc m t) A p vs= (loop_comp_helper acc m t) A q vs\"\n  using loop_comp_helper_def_lift_inv_helper\n        monotone_m monotone_acc profile vector \n  by blast\n\nlemma loop_comp_helper_def_lift_inv2:\n  assumes\n    monotone_m: \"defer_lift_invariance m\" and\n    monotone_acc: \"defer_lift_invariance acc\" and\n    finite_A_p: \"finite_profile A p\" and\n    lifted_A_pq: \"lifted A p q a\" and\n    finite_vec: \"finite_pair_vectors A vs\" and\n    a_in_defer_acc: \"a \\<in> defer (loop_comp_helper acc m t) A p vs\"\n  shows\n    \"(loop_comp_helper acc m t) A p vs = (loop_comp_helper acc m t) A q vs\"\n  using finite_A_p lifted_A_pq a_in_defer_acc\n        loop_comp_helper_def_lift_inv\n        monotone_acc monotone_m finite_vec\n  by blast\n\nlemma lifted_imp_fin_prof:\n  assumes \"lifted A p q a\"\n  shows \"finite_profile A p\"\n  using assms Profile.lifted_def\n  by fastforce\n\nlemma loop_comp_helper_presv_def_lift_inv:\n  assumes\n    monotone_m: \"defer_lift_invariance m\" and\n    monotone_acc: \"defer_lift_invariance acc\" and\n    f_vec: \"finite_pair_vectors A vs\"\n  shows \"defer_lift_invariance (loop_comp_helper acc m t)\"\nproof -\n  have\n    \"\\<forall>f. (defer_lift_invariance f \\<or>\n         (\\<exists>A prof prof2 (a::'a) vs.\n            f A prof vs \\<noteq> f A prof2 vs \\<and>\n              Profile.lifted A prof prof2 a \\<and>\n              finite_pair_vectors A vs \\<and>\n              a \\<in> defer f A prof vs) \\<or>\n         \\<not> electoral_module f) \\<and>\n      ((\\<forall>A prof prof2 a vs. f A prof vs = f A prof2 vs \\<or>\n          \\<not> Profile.lifted A prof prof2 a \\<or>\n          \\<not> finite_pair_vectors A vs \\<or>\n          a \\<notin> defer f A prof vs) \\<and>\n      electoral_module f \\<or> \\<not> defer_lift_invariance f)\"\n    using defer_lift_invariance_def f_vec \n    by blast\n  thus ?thesis\n    using electoral_module_def lifted_imp_fin_prof\n          loop_comp_helper_def_lift_inv loop_comp_helper_imp_partit\n          monotone_acc monotone_m f_vec defer_lift_invariance_def\n    by (metis (full_types))\nqed\n\nlemma loop_comp_presv_non_electing_helper:\n  assumes\n    non_electing_m: \"non_electing m\" and\n    non_electing_acc: \"non_electing acc\" and\n    f_prof: \"finite_profile A p\" and\n    f_vec: \"finite_pair_vectors A vs\" and\n    acc_defer_card: \"n = card (defer acc A p vs)\"\n  shows \"elect (loop_comp_helper acc m t) A p vs = {}\"\n  using acc_defer_card non_electing_acc\nproof (induct n arbitrary: acc rule: less_induct)\n  case (less n)\n  thus ?case\n  proof (safe)\n    fix x :: \"'a\"\n    assume\n      y_acc_no_elect:\n      \"(\\<And>y acc'. y < card (defer acc A p vs) \\<Longrightarrow>\n        y = card (defer acc' A p vs) \\<Longrightarrow> non_electing acc' \\<Longrightarrow>\n          elect (loop_comp_helper acc' m t) A p vs = {})\" and\n      acc_non_elect:\n      \"non_electing acc\" and\n      x_in_acc_elect:\n      \"x \\<in> elect (loop_comp_helper acc m t) A p vs\"\n    have\n      \"\\<forall>(f::'a set \\<Rightarrow> 'a Profile \\<Rightarrow> 'a Pair_Vectors \\<Rightarrow> 'a Result) g.\n        (non_electing f \\<and> non_electing g) \\<longrightarrow>\n          non_electing (f \\<triangleright> g)\"\n      by simp\n    hence seq_acc_m_non_elect: \"non_electing (acc \\<triangleright> m)\"\n      using acc_non_elect non_electing_m\n      by blast\n    have \"\\<forall>A B. (finite (A::'a set) \\<and> B \\<subset> A) \\<longrightarrow> card B < card A\"\n      using psubset_card_mono\n      by metis\n    hence card_ineq:\n      \"\\<forall>A B. (finite (A::'a set) \\<and> B \\<subset> A) \\<longrightarrow> card B < card A\"\n      by presburger\n    have no_elect_acc: \"elect acc A p vs = {}\"\n      using acc_non_elect f_prof non_electing_def f_vec\n      by blast\n    have card_n_no_elect:\n      \"\\<forall>n f.\n        (n < card (defer acc A p vs) \\<and> n = card (defer f A p vs) \\<and> non_electing f) \\<longrightarrow>\n          elect (loop_comp_helper f m t) A p vs = {}\"\n      using y_acc_no_elect\n      by blast\n    have\n      \"\\<And>f.\n        (finite (defer acc A p vs) \\<and> defer f A p vs \\<subset> defer acc A p vs \\<and> non_electing f) \\<longrightarrow>\n          elect (loop_comp_helper f m t) A p vs = {}\"\n      using card_n_no_elect psubset_card_mono\n      by metis\n    hence f0:\n      \"(\\<not> t (acc A p vs) \\<and> defer (acc \\<triangleright> m) A p vs \\<subset> defer acc A p vs \\<and>\n            finite (defer acc A p vs)) \\<and>\n          \\<not> t (acc A p vs) \\<longrightarrow>\n        elect (loop_comp_helper acc m t) A p vs = {}\"\n      using loop_comp_code_helper seq_acc_m_non_elect\n      by (metis (no_types))\n    obtain set_func :: \"'a set \\<Rightarrow> 'a\" where\n      \"\\<forall>A. (A = {} \\<longrightarrow> (\\<forall>a. a \\<notin> A)) \\<and> (A \\<noteq> {} \\<longrightarrow> set_func A \\<in> A)\"\n      using all_not_in_conv\n      by (metis (no_types))\n    thus \"x \\<in> {}\"\n      using loop_comp_code_helper no_elect_acc x_in_acc_elect f0\n      by (metis (no_types))\n  qed\nqed\n\nlemma loop_comp_helper_iter_elim_def_n_helper:\n  assumes\n    non_electing_m: \"non_electing m\" and\n    single_elimination: \"eliminates 1 m\" and\n    terminate_if_n_left: \"\\<forall> r. ((t r) \\<longleftrightarrow> (card (defer_r r) = x))\" and\n    x_greater_zero: \"x > 0\" and\n    f_prof: \"finite_profile A p\" and\n    f_vec: \"vector_pair A vs\" and\n    n_acc_defer_card: \"n = card (defer acc A p vs)\" and\n    n_ge_x: \"n \\<ge> x\" and\n    def_card_gt_one: \"card (defer acc A p vs) > 1\" and\n    acc_nonelect: \"non_electing acc\"\n  shows \"card (defer (loop_comp_helper acc m t) A p vs) = x\"\n  using n_ge_x def_card_gt_one acc_nonelect n_acc_defer_card\nproof (induct n arbitrary: acc rule: less_induct)\n  case (less n)\n  have subset:\n    \"(card (defer acc A p vs) > 1 \\<and> finite_profile A p \\<and> finite_pair_vectors A vs \n        \\<and> electoral_module acc) \\<longrightarrow> defer (acc \\<triangleright> m) A p vs \\<subset> defer acc A p vs\"\n    using seq_comp_elim_one_red_def_set single_elimination\n    by blast\n  hence step_reduces_defer_set:\n    \"(card (defer acc A p vs) > 1 \\<and> finite_profile A p \\<and> finite_pair_vectors A vs \n        \\<and> non_electing acc) \\<longrightarrow> defer (acc \\<triangleright> m) A p vs \\<subset> defer acc A p vs\"\n    using non_electing_def\n    by auto\n  thus ?case\n  proof cases\n    assume term_satisfied: \"t (acc A p vs)\"\n    have \"card (defer_r (loop_comp_helper acc m t A p vs)) = x\"\n      using loop_comp_helper.simps(1) term_satisfied terminate_if_n_left\n      by metis\n    thus ?case\n      by blast\n  next\n    assume term_not_satisfied: \"\\<not>(t (acc A p vs))\"\n    hence card_not_eq_x: \"card (defer acc A p vs) \\<noteq> x\"\n      by (simp add: terminate_if_n_left)\n    have rec_step:\n      \"(card (defer acc A p vs) > 1 \\<and> finite_profile A p \\<and> finite_pair_vectors A vs \n          \\<and> non_electing acc) \\<longrightarrow> loop_comp_helper acc m t A p vs =\n              loop_comp_helper (acc \\<triangleright> m) m t A p vs\" (*needed for step*)\n      using loop_comp_helper.simps(2) non_electing_def def_presv_fin_prof\n            step_reduces_defer_set term_not_satisfied\n      by metis\n    thus ?case\n    proof cases\n      assume card_too_small:\n        \"card (defer acc A p vs) < x\"\n      thus ?thesis\n        using not_le card_too_small less.prems(1) less.prems(4) not_le\n        by (metis (no_types))\n    next\n      assume old_card_at_least_x: \"\\<not>(card (defer acc A p vs) < x)\"\n      obtain i where i_is_new_card: \"i = card (defer (acc \\<triangleright> m) A p vs)\"\n        by blast\n      with card_not_eq_x\n      have card_too_big:\n        \"card (defer acc A p vs) > x\"\n        using nat_neq_iff old_card_at_least_x\n        by blast\n      hence enough_leftover:\n        \"card (defer acc A p vs) > 1\"\n        using x_greater_zero\n        by auto\n      have \"electoral_module acc \\<longrightarrow> (defer acc A p vs) \\<subseteq> A\"\n        by (simp add: defer_in_alts f_prof f_vec)\n      hence step_profile:\n        \"electoral_module acc \\<longrightarrow>\n            finite_profile (defer acc A p vs)\n              (limit_profile (defer acc A p vs) p)\"\n        using f_prof limit_profile_sound\n        by auto\n      hence\n        \"electoral_module acc \\<longrightarrow>\n            card (defer m (defer acc A p vs)\n              (limit_profile (defer acc A p vs) p) \n              (limit_pair_vectors (defer acc A p vs) vs)) =\n                card (defer acc A p vs) - 1\"\n        using non_electing_m single_elimination\n              single_elim_decr_def_card2 enough_leftover\n        by (metis def_presv_fin_vector_pair f_prof f_vec)\n      hence \"electoral_module acc \\<longrightarrow> i = card (defer acc A p vs) - 1\"\n        using sequential_composition.simps snd_conv i_is_new_card\n        by metis\n      hence \"electoral_module acc \\<longrightarrow> i \\<ge> x\"\n        using card_too_big\n        by linarith\n      hence new_card_still_big_enough: \"electoral_module acc \\<longrightarrow> x \\<le> i\"\n        by blast\n      have\n        \"electoral_module acc \\<and> electoral_module m \\<longrightarrow>\n            defer (acc \\<triangleright> m) A p vs \\<subseteq> defer acc A p vs\"\n        using enough_leftover f_prof subset f_vec\n        by blast\n      hence\n        \"electoral_module acc \\<and> electoral_module m \\<longrightarrow>\n            i \\<le> card (defer acc A p vs)\"\n        using card_mono i_is_new_card step_profile\n        by blast\n      hence i_geq_x:\n        \"electoral_module acc \\<and> electoral_module m \\<longrightarrow> (i = x \\<or> i > x)\"\n        using nat_less_le new_card_still_big_enough\n        by blast\n      thus ?thesis\n      proof cases\n        assume new_card_greater_x: \"electoral_module acc \\<longrightarrow> i > x\"\n        hence \"electoral_module acc \\<longrightarrow> 1 < card (defer (acc \\<triangleright> m) A p vs)\"\n          using x_greater_zero i_is_new_card\n          by linarith\n        moreover have new_card_still_big_enough2:\n          \"electoral_module acc \\<longrightarrow> x \\<le> i\" (* Needed for step *)\n          using i_is_new_card new_card_still_big_enough\n          by blast\n        moreover have\n          \"n = card (defer acc A p vs) \\<longrightarrow>\n              (electoral_module acc \\<longrightarrow> i < n)\" (* Needed for step *)\n          using subset step_profile enough_leftover f_prof psubset_card_mono\n                i_is_new_card f_vec\n          by blast\n        moreover have\n          \"electoral_module acc \\<longrightarrow>\n              electoral_module (acc \\<triangleright> m)\" (* Needed for step *)\n          using non_electing_def non_electing_m seq_comp_sound\n          by blast\n        moreover have non_electing_new:\n          \"non_electing acc \\<longrightarrow> non_electing (acc \\<triangleright> m)\"\n          by (simp add: non_electing_m)\n        ultimately have card_x:\n          \"(n = card (defer acc A p vs) \\<and> non_electing acc \\<and>\n              electoral_module acc) \\<longrightarrow>\n                  card (defer (loop_comp_helper (acc \\<triangleright> m) m t) A p vs) = x\"\n          using less.hyps i_is_new_card new_card_greater_x\n          by blast\n        have f1: \"loop_comp_helper acc m t A p vs = loop_comp_helper (acc \\<triangleright> m) m t A p vs\"\n          using enough_leftover f_prof less.prems(3) rec_step f_vec\n          by blast\n        have \"electoral_module acc\"\n          using less.prems(3) non_electing_def\n          by blast\n        thus ?thesis\n          using f1 card_x less.prems(3) less.prems(4)\n          by presburger\n      next\n        assume i_not_gt_x: \"\\<not>(electoral_module acc \\<longrightarrow> i > x)\"\n        hence \"electoral_module acc \\<and> electoral_module m \\<longrightarrow> i = x\"\n          using i_geq_x\n          by blast\n        hence \"electoral_module acc \\<and> electoral_module m \\<longrightarrow> t ((acc \\<triangleright> m) A p vs)\"\n          using i_is_new_card terminate_if_n_left\n          by blast\n        hence\n          \"electoral_module acc \\<and> electoral_module m \\<longrightarrow>\n              card (defer_r (loop_comp_helper (acc \\<triangleright> m) m t A p vs)) = x\"\n          using loop_comp_helper.simps(1) terminate_if_n_left\n          by metis\n        thus ?thesis\n          using i_not_gt_x dual_order.strict_iff_order i_is_new_card\n                loop_comp_helper.simps(1) new_card_still_big_enough\n                f_prof rec_step terminate_if_n_left\n                enough_leftover less.prems(3) f_vec\n          by metis\n      qed\n    qed\n  qed\nqed\n\nlemma loop_comp_helper_iter_elim_def_n:\n  assumes\n    non_electing_m: \"non_electing m\" and\n    single_elimination: \"eliminates 1 m\" and\n    terminate_if_n_left: \"\\<forall> r. ((t r) \\<longleftrightarrow> (card (defer_r r) = x))\" and\n    x_greater_zero: \"x > 0\" and\n    f_prof: \"finite_profile A p\" and\n    f_vec: \"vector_pair A vs\" and\n    acc_defers_enough: \"card (defer acc A p vs) \\<ge> x\" and\n    non_electing_acc: \"non_electing acc\"\n  shows \"card (defer (loop_comp_helper acc m t) A p vs) = x\"\n  using acc_defers_enough gr_implies_not0 le_neq_implies_less\n        less_one linorder_neqE_nat loop_comp_helper.simps(1)\n        loop_comp_helper_iter_elim_def_n_helper non_electing_acc\n        non_electing_m f_prof single_elimination nat_neq_iff\n        terminate_if_n_left x_greater_zero less_le f_vec\n  by (metis (no_types, lifting))\n\nlemma iter_elim_def_n_helper:\n  assumes\n    non_electing_m: \"non_electing m\" and\n    single_elimination: \"eliminates 1 m\" and\n    terminate_if_n_left: \"\\<forall> r. ((t r) \\<longleftrightarrow> (card (defer_r r) = x))\" and\n    x_greater_zero: \"x > 0\" and\n    f_prof: \"finite_profile A p\" and\n    f_vec: \"vector_pair A vs\" and\n    enough_alternatives: \"card A \\<ge> x\"\n  shows \"card (defer (m \\<circlearrowleft>\\<^sub>t) A p vs) = x\"\nproof cases\n  assume \"card A = x\"\n  thus ?thesis\n    by (simp add: terminate_if_n_left)\nnext\n  assume card_not_x: \"\\<not> card A = x\"\n  thus ?thesis\n  proof cases\n    assume \"card A < x\"\n    thus ?thesis\n      using enough_alternatives not_le\n      by blast\n  next\n    assume \"\\<not>card A < x\"\n    hence card_big_enough_A: \"card A > x\"\n      using card_not_x\n      by linarith\n    hence card_m: \"card (defer m A p vs) = card A - 1\"\n      using non_electing_m f_prof single_elimination\n            single_elim_decr_def_card2 x_greater_zero f_vec\n      by fastforce\n    hence card_big_enough_m: \"card (defer m A p vs) \\<ge> x\"\n      using card_big_enough_A\n      by linarith\n    hence \"(m \\<circlearrowleft>\\<^sub>t) A p vs = (loop_comp_helper m m t) A p vs\"\n      by (simp add: card_not_x terminate_if_n_left)\n    thus ?thesis\n      using card_big_enough_m non_electing_m f_prof single_elimination\n            terminate_if_n_left x_greater_zero f_vec\n            loop_comp_helper_iter_elim_def_n\n      by metis\n  qed\nqed\n\nsubsection \\<open>Composition Rules\\<close>\n\n(*The loop composition preserves defer-lift-invariance.*)\ntheorem loop_comp_presv_def_lift_inv[simp]:\n  assumes monotone_m: \"defer_lift_invariance m\" and\n          f_vec: \"vector_pair A vs\"\n  shows \"defer_lift_invariance (m \\<circlearrowleft>\\<^sub>t)\"\n  unfolding defer_lift_invariance_def\nproof (safe)\n  from monotone_m\n  have \"electoral_module m\"\n    unfolding defer_lift_invariance_def\n    by simp\n  thus \"electoral_module (m \\<circlearrowleft>\\<^sub>t)\"\n    by (simp add: loop_comp_sound)\nnext\n  fix\n    A :: \"'a set\" and\n    p :: \"'a Profile\" and\n    q :: \"'a Profile\" and\n    vs :: \"'a Pair_Vectors\" and\n    a :: \"'a\"\n  assume\n    a_in_loop_defer: \"a \\<in> defer (m \\<circlearrowleft>\\<^sub>t) A p vs\" and\n    lifted_a: \"Profile.lifted A p q a\" and\n    fin_vec: \"vector_pair A vs\"\n  have defer_lift_loop:\n    \"\\<forall> p q a vs. (a \\<in> (defer (m \\<circlearrowleft>\\<^sub>t) A p vs)\\<and> vector_pair A vs \\<and> lifted A p q a) \\<longrightarrow>\n        (m \\<circlearrowleft>\\<^sub>t) A p vs = (m \\<circlearrowleft>\\<^sub>t) A q vs\"\n    using monotone_m lifted_imp_fin_prof loop_comp_helper_def_lift_inv2\n          loop_composition.simps defer_module.simps\n    by (metis (full_types))\n  show \"(m \\<circlearrowleft>\\<^sub>t) A p vs = (m \\<circlearrowleft>\\<^sub>t) A q vs\"\n    using a_in_loop_defer lifted_a defer_lift_loop fin_vec\n    by metis\nqed\n\n(*The loop composition preserves the property non-electing.*)\ntheorem loop_comp_presv_non_electing[simp]:\n  assumes non_electing_m: \"non_electing m\"\n  shows \"non_electing (m \\<circlearrowleft>\\<^sub>t)\"\n  unfolding non_electing_def\nproof (safe, simp_all)\n  show \"electoral_module (m \\<circlearrowleft>\\<^sub>t)\"\n    using loop_comp_sound non_electing_def non_electing_m\n    by metis\nnext\n    fix\n      A :: \"'a set\" and\n      p :: \"'a Profile\" and\n      vs :: \"'a Pair_Vectors\" and\n      x :: \"'a\"\n    assume\n      fin_A: \"finite A\" and\n      prof_A: \"profile A p\" and\n      vec_A: \"vector_pair A vs\" and\n      x_elect: \"x \\<in> elect (m \\<circlearrowleft>\\<^sub>t) A p vs\"\n    show \"False\"\n  using def_mod_non_electing loop_comp_presv_non_electing_helper\n        non_electing_m empty_iff fin_A loop_comp_code\n        non_electing_def prof_A x_elect vec_A\n  by metis\nqed\n\ntheorem iter_elim_def_n[simp]:\n  assumes\n    non_electing_m: \"non_electing m\" and\n    single_elimination: \"eliminates 1 m\" and\n    terminate_if_n_left: \"\\<forall> r. ((t r) \\<longleftrightarrow> (card (defer_r r) = n))\" and\n    x_greater_zero: \"n > 0\"\n  shows \"defers n (m \\<circlearrowleft>\\<^sub>t)\"\nproof -\n  have\n    \"\\<forall> A p vs. finite_profile A p \\<and> vector_pair A vs \\<and> card A \\<ge> n \\<longrightarrow>\n        card (defer (m \\<circlearrowleft>\\<^sub>t) A p vs) = n\"\n    using iter_elim_def_n_helper non_electing_m single_elimination\n          terminate_if_n_left x_greater_zero\n    by blast\n  moreover have \"electoral_module (m \\<circlearrowleft>\\<^sub>t)\"\n    using loop_comp_sound eliminates_def single_elimination\n    by blast\n  thus ?thesis\n    by (simp add: calculation defers_def)\nqed\n\nend\n", "meta": {"author": "ChrisMackKit", "repo": "ba-scoring-rule-reinforcement-homogeneity", "sha": "d87febd04743389ac578b332349ae446b9c55e89", "save_path": "github-repos/isabelle/ChrisMackKit-ba-scoring-rule-reinforcement-homogeneity", "path": "github-repos/isabelle/ChrisMackKit-ba-scoring-rule-reinforcement-homogeneity/ba-scoring-rule-reinforcement-homogeneity-d87febd04743389ac578b332349ae446b9c55e89/verifiedVotingRuleConstruction-master/theories/Compositional_Structures/Loop_Composition.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6001883735630721, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.28136268373641865}}
{"text": "theory Key\n  imports\n    \"../Fused_Resource\"\nbegin\n\n\nsection \\<open>Key specification\\<close>\n\nlocale ideal_key =\n  fixes valid_keys :: \"'key set\"\nbegin\n\nsubsection \\<open>Data-types for Parties, State, Events, Input, and Output\\<close>\n\ndatatype party = Alice | Bob\n\ntype_synonym s_shell = \"party set\"\ndatatype 'key' s_kernel = PState_Store | State_Store 'key'\ntype_synonym 'key' state = \"'key' s_kernel \\<times> s_shell\"\n\ndatatype event = Event_Shell party | Event_Kernel\n\ndatatype iadv = Inp_Adversary\n\ndatatype iusr_alice = Inp_Alice\ndatatype iusr_bob = Inp_Bob\ntype_synonym iusr = \"iusr_alice + iusr_bob\"\n\ndatatype oadv = Out_Adversary\n\ndatatype 'key' ousr_alice = Out_Alice 'key'\ndatatype 'key' ousr_bob = Out_Bob 'key'\ntype_synonym 'key' ousr = \"'key' ousr_alice + 'key' ousr_bob\"\n\n\nsubsubsection \\<open>Basic lemmas for automated handling of party sets (i.e. @{text s_shell})\\<close>\n\nlemma Alice_neq_iff [simp]: \"Alice \\<noteq> x \\<longleftrightarrow> x = Bob\"\n  by(cases x) simp_all\n\nlemma neq_Alice_iff [simp]: \"x \\<noteq> Alice \\<longleftrightarrow> x = Bob\"\n  by(cases x) simp_all\n\nlemma Bob_neq_iff [simp]: \"Bob \\<noteq> x \\<longleftrightarrow> x = Alice\"\n  by(cases x) simp_all\n\nlemma neq_Bob_iff [simp]: \"x \\<noteq> Bob \\<longleftrightarrow> x = Alice\"\n  by(cases x) simp_all\n\nlemma Alice_in_iff_nonempty: \"Alice \\<in> A \\<longleftrightarrow> A \\<noteq> {}\" if \"Bob \\<notin> A\"\n  using that by(auto)(metis (full_types) party.exhaust)\n\nlemma Bob_in_iff_nonempty: \"Bob \\<in> A \\<longleftrightarrow> A \\<noteq> {}\" if \"Alice \\<notin> A\"\n  using that by(auto)(metis (full_types) party.exhaust)\n\n\nsubsection \\<open>Defining the event handler\\<close>\n\nfun poke :: \"('key state, event) handler\"\n  where\n    \"poke (s_kernel, parties) (Event_Shell party) = \n      (if party \\<in> parties then \n        return_pmf None\n      else \n        return_spmf (s_kernel, insert party parties))\"\n  | \"poke (PState_Store, s_shell) (Event_Kernel) = do {\n      key \\<leftarrow> spmf_of_set valid_keys;\n      return_spmf (State_Store key, s_shell)  } \"\n  | \"poke _ _ = return_pmf None\"\n\nlemma in_set_spmf_poke:\n  \"s' \\<in> set_spmf (poke s x) \\<longleftrightarrow>\n  (\\<exists>s_kernel parties party. s = (s_kernel, parties) \\<and> x = Event_Shell party \\<and> party \\<notin> parties \\<and> s' = (s_kernel, insert party parties)) \\<or>\n  (\\<exists>s_shell key. s = (PState_Store, s_shell) \\<and> x = Event_Kernel \\<and> key \\<in> valid_keys \\<and> finite valid_keys \\<and> s' = (State_Store key, s_shell))\"\n  by(cases \"(s, x)\" rule: poke.cases)(auto simp add: set_spmf_of_set)\n\nlemma foldl_poke_invar:\n  \"\\<lbrakk> (s_kernel', parties') \\<in> set_spmf (foldl_spmf poke p events); \\<forall>(s_kernel, parties)\\<in>set_spmf p. set_s_kernel s_kernel \\<subseteq> valid_keys \\<rbrakk>\n  \\<Longrightarrow> set_s_kernel s_kernel' \\<subseteq> valid_keys\"\n  by(induction events arbitrary: parties' rule: rev_induct)\n    (auto 4 3 simp add: split_def foldl_spmf_append in_set_spmf_poke dest: bspec)\n\nsubsection \\<open>Defining the adversary interface\\<close>\n\nfun iface_adv :: \"('key state, iadv, oadv) oracle'\"\n  where\n   \"iface_adv state _ = return_spmf (Out_Adversary, state)\"\n\n\nsubsection \\<open>Defining the user interfaces\\<close>\n\ncontext\nbegin\n\nprivate fun iface_usr_func :: \"party \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> 'inp \\<Rightarrow> ('wrap_key \\<times> 'key state) spmf\"\n  where\n    \"iface_usr_func party wrap (State_Store key, parties) inp = \n      (if party \\<in> parties then\n        return_spmf (wrap key, State_Store key, parties)\n      else\n        return_pmf None)\"\n  | \"iface_usr_func _ _ _ _ = return_pmf None\"\n\nabbreviation iface_alice :: \"('key state, iusr_alice, 'key ousr_alice) oracle'\"\n  where\n    \"iface_alice \\<equiv> iface_usr_func Alice Out_Alice\"\n\nabbreviation iface_bob :: \"('key state, iusr_bob, 'key ousr_bob) oracle'\"\n  where\n    \"iface_bob \\<equiv> iface_usr_func Bob Out_Bob\"\n\nabbreviation iface_usr :: \"('key state, iusr, 'key ousr) oracle'\"\n  where\n    \"iface_usr \\<equiv> plus_oracle iface_alice iface_bob\"\n\nlemma in_set_iface_usr_func [simp]:\n  \"x \\<in> set_spmf (iface_usr_func party wrap state inp) \\<longleftrightarrow>\n   (\\<exists>key parties. state = (State_Store key, parties) \\<and> party \\<in> parties \\<and> x = (wrap key, State_Store key, parties))\"\n  by(cases \"(party, wrap, state, inp)\" rule: iface_usr_func.cases) auto\n\nend\n\n\nsubsection \\<open>Defining the Fuse Resource\\<close>\n\nprimcorec core :: \"('key state, event, iadv, iusr, oadv,'key ousr) core\" \n  where\n    \"cpoke core = poke\"\n  | \"cfunc_adv core = iface_adv\"\n  | \"cfunc_usr core = iface_usr\"\n\nsublocale fused_resource core \"(PState_Store, {})\" .\n\n\nsubsubsection \\<open>Lemma showing that the resulting resource is well-typed\\<close>\n\nlemma WT_core [WT_intro]: \n  \"WT_core \\<I>_full (\\<I>_uniform UNIV (Out_Alice ` valid_keys) \\<oplus>\\<^sub>\\<I> \\<I>_uniform UNIV (Out_Bob ` valid_keys))\n     (pred_prod (pred_s_kernel (\\<lambda>key. key \\<in> valid_keys)) (\\<lambda>_. True)) core\"\n  apply (rule WT_core.intros)\n  subgoal for s e s' by(cases \"(s, e)\" rule: poke.cases)(auto split: if_split_asm simp add: set_spmf_of_set)\n  by auto\n\nlemma WT_fuse [WT_intro]: \n  assumes [WT_intro]: \"WT_rest \\<I>_adv_rest \\<I>_usr_rest I_rest rest\"\n  shows \"(\\<I>_full \\<oplus>\\<^sub>\\<I> \\<I>_adv_rest) \\<oplus>\\<^sub>\\<I> ((\\<I>_uniform UNIV (Out_Alice ` valid_keys) \\<oplus>\\<^sub>\\<I> \\<I>_uniform UNIV (Out_Bob ` valid_keys)) \\<oplus>\\<^sub>\\<I> \\<I>_usr_rest) \\<turnstile>res resource rest \\<surd>\"\n  by(rule WT_intro)+ simp\n \nend\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Constructive_Cryptography_CM/Specifications/Key.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.600188359260205, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.2813626770313686}}
{"text": "header {*\\isaheader{Dependent Live Variables} *}\n\ntheory DependentLiveVariables imports DynPDG begin\n\ntext {* @{text dependent_live_vars} calculates variables which\n  can change\\\\ the value of the @{term Use} variables of the target node *}\n\ncontext DynPDG begin\n\ninductive_set\n  dependent_live_vars :: \"'node \\<Rightarrow> ('var \\<times> 'edge list \\<times> 'edge list) set\"\n  for n' :: \"'node\"\n  where dep_vars_Use: \n  \"V \\<in> Use n' \\<Longrightarrow> (V,[],[]) \\<in> dependent_live_vars n'\"\n\n  | dep_vars_Cons_cdep:\n  \"\\<lbrakk>V \\<in> Use (sourcenode a); sourcenode a -a#as'\\<rightarrow>\\<^bsub>cd\\<^esub> n''; n'' -as''\\<rightarrow>\\<^sub>d* n'\\<rbrakk>\n  \\<Longrightarrow> (V,[],a#as'@as'') \\<in> dependent_live_vars n'\"\n\n  | dep_vars_Cons_ddep:\n  \"\\<lbrakk>(V,as',as) \\<in> dependent_live_vars n'; V' \\<in> Use (sourcenode a);\n    n' = last(targetnodes (a#as));\n    sourcenode a -{V}a#as'\\<rightarrow>\\<^bsub>dd\\<^esub> last(targetnodes (a#as'))\\<rbrakk>\n  \\<Longrightarrow> (V',[],a#as) \\<in> dependent_live_vars n'\"\n\n  | dep_vars_Cons_keep:\n  \"\\<lbrakk>(V,as',as) \\<in> dependent_live_vars n'; n' = last(targetnodes (a#as));\n     \\<not> sourcenode a -{V}a#as'\\<rightarrow>\\<^bsub>dd\\<^esub> last(targetnodes (a#as'))\\<rbrakk>\n  \\<Longrightarrow> (V,a#as',a#as) \\<in> dependent_live_vars n'\"\n\n\n\nlemma dependent_live_vars_fst_prefix_snd:\n  \"(V,as',as) \\<in> dependent_live_vars n' \\<Longrightarrow> \\<exists>as''. as'@as'' = as\"\nby(induct rule:dependent_live_vars.induct,simp_all)\n\n\nlemma dependent_live_vars_Exit_empty [dest]:\n  \"(V,as',as) \\<in> dependent_live_vars (_Exit_) \\<Longrightarrow> False\"\nproof(induct rule:dependent_live_vars.induct)\n  case (dep_vars_Cons_cdep V a as' n'' as'')\n  from `n'' -as''\\<rightarrow>\\<^sub>d* (_Exit_)` have \"n'' = (_Exit_)\"\n    by(fastforce intro:DynPDG_path_Exit)\n  with `sourcenode a -a#as'\\<rightarrow>\\<^bsub>cd\\<^esub> n''` have \"sourcenode a -a#as'\\<rightarrow>\\<^sub>d* (_Exit_)\"\n    by(fastforce intro:DynPDG_path_cdep)\n  hence \"sourcenode a = (_Exit_)\" by(fastforce intro:DynPDG_path_Exit)\n  with `V \\<in> Use (sourcenode a)` show False by simp(erule Exit_Use_empty)\nqed auto\n\n\nlemma dependent_live_vars_lastnode:\n  \"\\<lbrakk>(V,as',as) \\<in> dependent_live_vars n'; as \\<noteq> []\\<rbrakk> \n  \\<Longrightarrow> n' = last(targetnodes as)\"\nproof(induct rule:dependent_live_vars.induct)\n  case (dep_vars_Cons_cdep V a as' n'' as'')\n  from `sourcenode a -a#as'\\<rightarrow>\\<^bsub>cd\\<^esub> n''` have \"sourcenode a -a#as'\\<rightarrow>* n''\"\n    by(rule DynPDG_cdep_edge_CFG_path(1))\n  from `n'' -as''\\<rightarrow>\\<^sub>d* n'` have \"n'' -as''\\<rightarrow>* n'\" by(rule DynPDG_path_CFG_path)\n  show ?case\n  proof(cases \"as'' = []\")\n    case True\n    with `n'' -as''\\<rightarrow>* n'` have \"n'' = n'\" by (auto elim: DynPDG.dependent_live_vars.cases)\n    with `sourcenode a -a#as'\\<rightarrow>* n''` True\n    show ?thesis by(fastforce intro:path_targetnode[THEN sym])\n  next\n    case False\n    with `n'' -as''\\<rightarrow>* n'` have \"n' = last(targetnodes as'')\"\n      by(fastforce intro:path_targetnode[THEN sym])\n    with False show ?thesis by(fastforce simp:targetnodes_def)\n  qed\nqed simp_all\n\n\nlemma dependent_live_vars_Use_cases:\n  \"\\<lbrakk>(V,as',as) \\<in> dependent_live_vars n'; n -as\\<rightarrow>* n'\\<rbrakk>\n  \\<Longrightarrow> \\<exists>nx as''. as = as'@as'' \\<and> n -as'\\<rightarrow>* nx \\<and> nx -as''\\<rightarrow>\\<^sub>d* n' \\<and> V \\<in> Use nx \\<and> \n               (\\<forall>n'' \\<in> set (sourcenodes as'). V \\<notin> Def n'')\"\nproof(induct arbitrary:n rule:dependent_live_vars.induct)\n  case (dep_vars_Use V)\n  from `n -[]\\<rightarrow>* n'` have \"valid_node n'\" by(rule path_valid_node(2))\n  hence \"n' -[]\\<rightarrow>\\<^sub>d* n'\" by(rule DynPDG_path_Nil)\n  with `V \\<in> Use n'` `n -[]\\<rightarrow>* n'` show ?case \n    by(auto simp:sourcenodes_def)\nnext\n  case (dep_vars_Cons_cdep V a as' n'' as'' n)\n  from `n -a#as'@as''\\<rightarrow>* n'` have \"sourcenode a = n\"\n    by(auto elim:path.cases)\n  from `sourcenode a -a#as'\\<rightarrow>\\<^bsub>cd\\<^esub> n''` have \"sourcenode a -a#as'\\<rightarrow>* n''\"\n    by(rule DynPDG_cdep_edge_CFG_path(1))\n  hence \"valid_edge a\" by(auto elim:path.cases) \n  hence \"sourcenode a -[]\\<rightarrow>* sourcenode a\" by(fastforce intro:empty_path)\n  from `sourcenode a -a#as'\\<rightarrow>\\<^bsub>cd\\<^esub> n''` have \"sourcenode a -a#as'\\<rightarrow>\\<^sub>d* n''\"\n    by(rule DynPDG_path_cdep)\n  with `n'' -as''\\<rightarrow>\\<^sub>d* n'` have \"sourcenode a -(a#as')@as''\\<rightarrow>\\<^sub>d* n'\"\n    by(rule DynPDG_path_Append)\n  with `sourcenode a -[]\\<rightarrow>* sourcenode a` `V \\<in> Use (sourcenode a)` `sourcenode a = n`\n  show ?case by(auto simp:sourcenodes_def)\nnext\n  case(dep_vars_Cons_ddep V as' as V' a n)\n  note ddep = `sourcenode a -{V}a#as'\\<rightarrow>\\<^bsub>dd\\<^esub> last (targetnodes (a#as'))`\n  note IH = `\\<And>n. n -as\\<rightarrow>* n'\n    \\<Longrightarrow> \\<exists>nx as''. as = as'@as'' \\<and> n -as'\\<rightarrow>* nx \\<and> nx -as''\\<rightarrow>\\<^sub>d* n' \\<and> \n                   V \\<in> Use nx \\<and> (\\<forall>n''\\<in>set (sourcenodes as'). V \\<notin> Def n'')`\n  from `n -a#as\\<rightarrow>* n'` have \"n -[]@a#as\\<rightarrow>* n'\" by simp\n  hence \"n = sourcenode a\" and \"targetnode a -as\\<rightarrow>* n'\" and \"valid_edge a\"\n    by(fastforce dest:path_split)+\n  hence \"n -[]\\<rightarrow>* n\" \n    by(fastforce intro:empty_path simp:valid_node_def)\n  from IH[OF `targetnode a -as\\<rightarrow>* n'`]\n  have \"\\<exists>nx as''. as = as'@as'' \\<and> targetnode a -as'\\<rightarrow>* nx \\<and> nx -as''\\<rightarrow>\\<^sub>d* n' \\<and> \n                  V \\<in> Use nx \\<and> (\\<forall>n''\\<in>set (sourcenodes as'). V \\<notin> Def n'')\" .\n  then obtain nx'' as'' where \"targetnode a -as'\\<rightarrow>* nx''\"\n    and \"nx'' -as''\\<rightarrow>\\<^sub>d* n'\" and \"as = as'@as''\" by blast\n  have \"last (targetnodes (a#as')) -as''\\<rightarrow>\\<^sub>d* n'\"\n  proof(cases as')\n    case Nil\n    with `targetnode a -as'\\<rightarrow>* nx''` have \"nx'' = targetnode a\"\n      by(auto elim:path.cases)\n    with `nx'' -as''\\<rightarrow>\\<^sub>d* n'` Nil show ?thesis by(simp add:targetnodes_def)\n  next\n    case (Cons ax asx)\n    hence \"last (targetnodes (a#as')) = last (targetnodes as')\"\n      by(simp add:targetnodes_def)\n    from Cons `targetnode a -as'\\<rightarrow>* nx''` have \"last (targetnodes as') = nx''\"\n      by(fastforce intro:path_targetnode)\n    with `last (targetnodes (a#as')) = last (targetnodes as')` `nx'' -as''\\<rightarrow>\\<^sub>d* n'`\n    show ?thesis by simp\n  qed\n  with ddep `as = as'@as''` have \"sourcenode a -a#as\\<rightarrow>\\<^sub>d* n'\"\n    by(fastforce dest:DynPDG_path_ddep DynPDG_path_Append)\n  with `V' \\<in> Use (sourcenode a)` `n = sourcenode a` `n -[]\\<rightarrow>* n`\n  show ?case by(auto simp:sourcenodes_def)\nnext\n  case (dep_vars_Cons_keep V as' as a n)\n  note no_dep = `\\<not> sourcenode a -{V}a#as'\\<rightarrow>\\<^bsub>dd\\<^esub> last (targetnodes (a#as'))`\n  note IH = `\\<And>n. n -as\\<rightarrow>* n'\n    \\<Longrightarrow> \\<exists>nx as''. (as = as'@as'') \\<and> (n -as'\\<rightarrow>* nx) \\<and> (nx -as''\\<rightarrow>\\<^sub>d* n') \\<and> \n                   V \\<in> Use nx \\<and> (\\<forall>n''\\<in>set (sourcenodes as'). V \\<notin> Def n'')`\n  from `n -a#as\\<rightarrow>* n'` have \"n = sourcenode a\" and \"valid_edge a\"\n    and \"targetnode a -as\\<rightarrow>* n'\" by(auto elim:path_split_Cons)\n  from IH[OF `targetnode a -as\\<rightarrow>* n'`]\n  have \"\\<exists>nx as''. as = as'@as'' \\<and> targetnode a -as'\\<rightarrow>* nx \\<and> nx -as''\\<rightarrow>\\<^sub>d* n' \\<and> \n               V \\<in> Use nx \\<and> (\\<forall>n''\\<in>set (sourcenodes as'). V \\<notin> Def n'')\" .\n  then obtain nx'' as'' where \"V \\<in> Use nx''\"\n    and \"\\<forall>n''\\<in>set (sourcenodes as'). V \\<notin> Def n''\" and \"targetnode a -as'\\<rightarrow>* nx''\"\n    and \"nx'' -as''\\<rightarrow>\\<^sub>d* n'\" and \"as = as'@as''\" by blast\n  from `valid_edge a` `targetnode a -as'\\<rightarrow>* nx''` have \"sourcenode a -a#as'\\<rightarrow>* nx''\"\n    by(fastforce intro:Cons_path)\n  hence \"last(targetnodes (a#as')) = nx''\" by(fastforce dest:path_targetnode)\n  { assume \"V \\<in> Def (sourcenode a)\"\n    with `V \\<in> Use nx''` `sourcenode a -a#as'\\<rightarrow>* nx''`\n      `\\<forall>n''\\<in>set (sourcenodes as'). V \\<notin> Def n''` \n    have \"(sourcenode a) influences V in nx'' via a#as'\"\n      by(simp add:dyn_data_dependence_def sourcenodes_def)\n    with no_dep `last(targetnodes (a#as')) = nx''`\n      `\\<forall>n''\\<in>set (sourcenodes as'). V \\<notin> Def n''` `V \\<in> Def (sourcenode a)`\n    have False by(fastforce dest:DynPDG_ddep_edge) }\n  with `\\<forall>n''\\<in>set (sourcenodes as'). V \\<notin> Def n''` \n  have \"\\<forall>n''\\<in>set (sourcenodes (a#as')). V \\<notin> Def n''\"\n    by(fastforce simp:sourcenodes_def)\n  with `V \\<in> Use nx''` `sourcenode a -a#as'\\<rightarrow>* nx''` `nx'' -as''\\<rightarrow>\\<^sub>d* n'`\n    `as = as'@as''` `n = sourcenode a` show ?case by fastforce\nqed\n\n\nlemma dependent_live_vars_dependent_edge:\n  assumes \"(V,as',as) \\<in> dependent_live_vars n'\" \n  and \"targetnode a -as\\<rightarrow>* n'\"\n  and \"V \\<in> Def (sourcenode a)\" and \"valid_edge a\"\n  obtains nx as'' where \"as = as'@as''\" and \"sourcenode a -{V}a#as'\\<rightarrow>\\<^bsub>dd\\<^esub> nx\"\n  and \"nx -as''\\<rightarrow>\\<^sub>d* n'\"\nproof(atomize_elim)\n  from `(V,as',as) \\<in> dependent_live_vars n'` `targetnode a -as\\<rightarrow>* n'`\n  have \"\\<exists>nx as''. as = as'@as'' \\<and> targetnode a -as'\\<rightarrow>* nx \\<and> nx -as''\\<rightarrow>\\<^sub>d* n' \\<and> \n    V \\<in> Use nx \\<and> (\\<forall>n'' \\<in> set (sourcenodes as'). V \\<notin> Def n'')\"\n    by(rule dependent_live_vars_Use_cases)\n  then obtain nx as'' where \"V \\<in> Use nx\"\n    and \"\\<forall>n''\\<in> set(sourcenodes as'). V \\<notin> Def n''\"\n    and \"targetnode a -as'\\<rightarrow>* nx\" and \"nx -as''\\<rightarrow>\\<^sub>d* n'\"\n    and \"as = as'@as''\" by blast\n  from `targetnode a -as'\\<rightarrow>* nx` `valid_edge a` have \"sourcenode a -a#as'\\<rightarrow>* nx\"\n    by(fastforce intro:Cons_path)\n  with `V \\<in> Def (sourcenode a)` `V \\<in> Use nx` \n    `\\<forall>n''\\<in> set(sourcenodes as'). V \\<notin> Def n''` \n  have \"sourcenode a influences V in nx via a#as'\"\n    by(auto simp:dyn_data_dependence_def sourcenodes_def)\n  hence \"sourcenode a -{V}a#as'\\<rightarrow>\\<^bsub>dd\\<^esub> nx\" by(rule DynPDG_ddep_edge)\n  with `nx -as''\\<rightarrow>\\<^sub>d* n'` `as = as'@as''` \n  show \"\\<exists>as'' nx. (as = as'@as'') \\<and> (sourcenode a -{V}a#as'\\<rightarrow>\\<^bsub>dd\\<^esub> nx) \\<and> \n    (nx -as''\\<rightarrow>\\<^sub>d* n')\" by fastforce\nqed\n\n\n\nlemma dependent_live_vars_same_pathsI:\n  assumes \"V \\<in> Use n'\"\n  shows \"\\<lbrakk>\\<forall>as' a as''. as = as'@a#as'' \\<longrightarrow> \\<not> sourcenode a -{V}a#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'; \n          as \\<noteq> [] \\<longrightarrow> n' = last(targetnodes as)\\<rbrakk>\n  \\<Longrightarrow> (V,as,as) \\<in> dependent_live_vars n'\"\nproof(induct as)\n  case Nil\n  from `V \\<in> Use n'` show ?case by(rule dep_vars_Use)\nnext\n  case (Cons ax asx)\n  note lastnode = `ax#asx \\<noteq> [] \\<longrightarrow> n' = last (targetnodes (ax#asx))`\n  note IH = `\\<lbrakk>\\<forall>as' a as''. asx = as'@a#as'' \\<longrightarrow>\n                           \\<not> sourcenode a -{V}a#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n';\n             asx \\<noteq> [] \\<longrightarrow> n' = last (targetnodes asx)\\<rbrakk>\n           \\<Longrightarrow> (V, asx, asx) \\<in> dependent_live_vars n'`\n  from `\\<forall>as' a as''. ax#asx = as'@a#as'' \\<longrightarrow> \\<not> sourcenode a -{V}a#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'`\n  have all':\"\\<forall>as' a as''. asx = as'@a#as'' \\<longrightarrow> \\<not> sourcenode a -{V}a#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'\"\n    and \"\\<not> sourcenode ax -{V}ax#asx\\<rightarrow>\\<^bsub>dd\\<^esub> n'\"\n    by simp_all\n  show ?case\n  proof(cases \"asx = []\")\n    case True\n    from `V \\<in> Use n'` have \"(V,[],[]) \\<in> dependent_live_vars n'\" by(rule dep_vars_Use)\n    with `\\<not> sourcenode ax -{V}ax#asx\\<rightarrow>\\<^bsub>dd\\<^esub> n'` True lastnode\n    have \"(V,[ax],[ax]) \\<in> dependent_live_vars n'\"\n      by(fastforce intro:dep_vars_Cons_keep)\n    with True show ?thesis by simp\n  next\n    case False\n    with lastnode have \"asx \\<noteq> [] \\<longrightarrow> n' = last (targetnodes asx)\"\n      by(simp add:targetnodes_def)\n    from IH[OF all' this] have \"(V, asx, asx) \\<in> dependent_live_vars n'\" .\n    with `\\<not> sourcenode ax -{V}ax#asx\\<rightarrow>\\<^bsub>dd\\<^esub> n'` lastnode \n    show ?thesis by(fastforce intro:dep_vars_Cons_keep)\n  qed\nqed\n\n\nlemma dependent_live_vars_same_pathsD:\n  \"\\<lbrakk>(V,as,as) \\<in> dependent_live_vars n';  as \\<noteq> [] \\<longrightarrow> n' = last(targetnodes as)\\<rbrakk>\n  \\<Longrightarrow> V \\<in> Use n' \\<and> (\\<forall>as' a as''. as = as'@a#as'' \\<longrightarrow>\n                       \\<not> sourcenode a -{V}a#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n')\"\nproof(induct as)\n  case Nil\n  have \"(V,[],[]) \\<in> dependent_live_vars n'\" by fact\n  thus ?case\n    by(fastforce elim:dependent_live_vars.cases simp:targetnodes_def sourcenodes_def)\nnext\n  case (Cons ax asx)\n  note IH = `\\<lbrakk>(V,asx,asx) \\<in> dependent_live_vars n'; \n              asx \\<noteq> [] \\<longrightarrow> n' = last (targetnodes asx)\\<rbrakk>\n    \\<Longrightarrow> V \\<in> Use n' \\<and> (\\<forall>as' a as''. asx = as'@a#as'' \\<longrightarrow>\n                          \\<not> sourcenode a -{V}a#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n')`\n  from `(V,ax#asx,ax#asx) \\<in> dependent_live_vars n'`\n  have \"(V,asx,asx) \\<in> dependent_live_vars n'\"\n    and \"\\<not> sourcenode ax -{V}ax#asx\\<rightarrow>\\<^bsub>dd\\<^esub> last(targetnodes (ax#asx))\"\n    by(auto elim:dependent_live_vars.cases)\n  from `ax#asx \\<noteq> [] \\<longrightarrow> n' = last (targetnodes (ax#asx))`\n  have \"n' = last (targetnodes (ax#asx))\" by simp\n  show ?case\n  proof(cases \"asx = []\")\n    case True\n    with `(V,asx,asx) \\<in> dependent_live_vars n'` have \"V \\<in> Use n'\"\n      by(fastforce elim:dependent_live_vars.cases)\n    from `\\<not> sourcenode ax -{V}ax#asx\\<rightarrow>\\<^bsub>dd\\<^esub> last(targetnodes (ax#asx))` \n      True `n' = last (targetnodes (ax#asx))`\n    have \"\\<forall>as' a as''. ax#asx = as'@a#as'' \\<longrightarrow> \\<not> sourcenode a -{V}a#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'\"\n      by auto(case_tac as',auto)\n    with `V \\<in> Use n'` show ?thesis by simp\n  next\n    case False\n    with `n' = last (targetnodes (ax#asx))`\n    have \"asx \\<noteq> [] \\<longrightarrow> n' = last (targetnodes asx)\"\n      by(simp add:targetnodes_def)\n    from IH[OF `(V,asx,asx) \\<in> dependent_live_vars n'` this] \n    have \"V \\<in> Use n' \\<and> (\\<forall>as' a as''. asx = as'@a#as'' \\<longrightarrow>\n                            \\<not> sourcenode a -{V}a#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n')\" .\n    with `\\<not> sourcenode ax -{V}ax#asx\\<rightarrow>\\<^bsub>dd\\<^esub> last(targetnodes (ax#asx))`\n      `n' = last (targetnodes (ax#asx))` have \"V \\<in> Use n'\"\n      and \"\\<forall>as' a as''. ax#asx = as'@a#as'' \\<longrightarrow>\n                            \\<not> sourcenode a -{V}a#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'\"\n      by auto(case_tac as',auto)\n    thus ?thesis by simp\n  qed\nqed\n\n\nlemma dependent_live_vars_same_paths:\n  \"as \\<noteq> [] \\<longrightarrow> n' = last(targetnodes as) \\<Longrightarrow>\n  (V,as,as) \\<in> dependent_live_vars n' = \n  (V \\<in> Use n' \\<and> (\\<forall>as' a as''. as = as'@a#as'' \\<longrightarrow>\n                       \\<not> sourcenode a -{V}a#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'))\"\nby(fastforce intro!:dependent_live_vars_same_pathsD dependent_live_vars_same_pathsI)\n\n\nlemma dependent_live_vars_cdep_empty_fst:\nassumes \"n'' -as\\<rightarrow>\\<^bsub>cd\\<^esub> n'\" and \"V' \\<in> Use n''\"\n  shows \"(V',[],as) \\<in> dependent_live_vars n'\"\nproof(cases as)\n  case Nil\n  with `n'' -as\\<rightarrow>\\<^bsub>cd\\<^esub> n'` show ?thesis\n    by(fastforce elim:DynPDG_edge.cases dest:dyn_control_dependence_path)\nnext\n  case (Cons ax asx)\n  with `n'' -as\\<rightarrow>\\<^bsub>cd\\<^esub> n'` have \"sourcenode ax = n''\"\n    by(auto dest:DynPDG_cdep_edge_CFG_path elim:path.cases)\n  from `n'' -as\\<rightarrow>\\<^bsub>cd\\<^esub> n'` have \"valid_node n'\"\n    by(fastforce intro:path_valid_node(2) DynPDG_cdep_edge_CFG_path(1))\n  from Cons `n'' -as\\<rightarrow>\\<^bsub>cd\\<^esub> n'` have \"last(targetnodes as) = n'\"\n    by(fastforce intro:path_targetnode dest:DynPDG_cdep_edge_CFG_path)\n  with Cons `n'' -as\\<rightarrow>\\<^bsub>cd\\<^esub> n'` `V' \\<in> Use n''` `sourcenode ax = n''` `valid_node n'`\n  have \"(V', [], ax#asx@[]) \\<in> dependent_live_vars n'\"\n    by(fastforce intro:dep_vars_Cons_cdep DynPDG_path_Nil)\n  with Cons show ?thesis by simp\nqed\n  \n\nlemma dependent_live_vars_ddep_empty_fst:\n  assumes \"n'' -{V}as\\<rightarrow>\\<^bsub>dd\\<^esub> n'\" and \"V' \\<in> Use n''\"\n  shows \"(V',[],as) \\<in> dependent_live_vars n'\"\nproof(cases as)\n  case Nil\n  with `n'' -{V}as\\<rightarrow>\\<^bsub>dd\\<^esub> n'` show ?thesis\n    by(fastforce elim:DynPDG_edge.cases simp:dyn_data_dependence_def)\nnext\n  case (Cons ax asx)\n  with `n'' -{V}as\\<rightarrow>\\<^bsub>dd\\<^esub> n'` have \"sourcenode ax = n''\"\n    by(auto dest:DynPDG_ddep_edge_CFG_path elim:path.cases)\n  from Cons `n'' -{V}as\\<rightarrow>\\<^bsub>dd\\<^esub> n'` have \"last(targetnodes as) = n'\"\n    by(fastforce intro:path_targetnode elim:DynPDG_ddep_edge_CFG_path(1))\n  from Cons `n'' -{V}as\\<rightarrow>\\<^bsub>dd\\<^esub> n'` have all:\"\\<forall>as' a as''. asx = as'@a#as'' \\<longrightarrow>\n                             \\<not> sourcenode a -{V}a#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'\"\n    by(fastforce dest:DynPDG_ddep_edge_no_shorter_ddep_edge)\n  from `n'' -{V}as\\<rightarrow>\\<^bsub>dd\\<^esub> n'` have \"V \\<in> Use n'\" \n    by(auto elim!:DynPDG_edge.cases simp:dyn_data_dependence_def)\n  from Cons `n'' -{V}as\\<rightarrow>\\<^bsub>dd\\<^esub> n'` have \"as \\<noteq> [] \\<longrightarrow> n' = last(targetnodes as)\"\n    by(fastforce dest:DynPDG_ddep_edge_CFG_path path_targetnode)\n  with Cons have \"asx \\<noteq> [] \\<longrightarrow> n' = last(targetnodes asx)\"\n    by(fastforce simp:targetnodes_def)\n  with all `V \\<in> Use n'` have \"(V,asx,asx) \\<in> dependent_live_vars n'\"\n    by -(rule dependent_live_vars_same_pathsI)\n  with `V' \\<in> Use n''` `n'' -{V}as\\<rightarrow>\\<^bsub>dd\\<^esub> n'` `last(targetnodes as) = n'`\n    Cons `sourcenode ax = n''` show ?thesis\n    by(fastforce intro:dep_vars_Cons_ddep)\nqed\n\n\n\n\nlemma ddep_dependent_live_vars_keep_notempty:\n  assumes \"n -{V}a#as\\<rightarrow>\\<^bsub>dd\\<^esub> n''\" and \"as' \\<noteq> []\"\n  and \"(V,as'',as') \\<in> dependent_live_vars n'\"\n  shows \"(V,as@as'',as@as') \\<in> dependent_live_vars n'\"\nproof -\n  from `n -{V}a#as\\<rightarrow>\\<^bsub>dd\\<^esub> n''` have \"\\<forall>n'' \\<in> set (sourcenodes as). V \\<notin> Def n''\"\n    by(auto elim:DynPDG_edge.cases simp:dyn_data_dependence_def)\n  with `(V,as'',as') \\<in> dependent_live_vars n'` show ?thesis\n  proof(induct as)\n    case Nil thus ?case by simp\n  next\n    case (Cons ax asx)\n    note IH = `\\<lbrakk>(V,as'',as') \\<in> dependent_live_vars n';\n                \\<forall>n''\\<in>set (sourcenodes asx). V \\<notin> Def n''\\<rbrakk>\n               \\<Longrightarrow> (V, asx@as'',asx@as') \\<in> dependent_live_vars n'`\n    from `\\<forall>n''\\<in>set (sourcenodes (ax#asx)). V \\<notin> Def n''`\n    have \"\\<forall>n''\\<in>set (sourcenodes asx). V \\<notin> Def n''\"\n      by(auto simp:sourcenodes_def)\n    from IH[OF `(V,as'',as') \\<in> dependent_live_vars n'` this]\n    have \"(V,asx@as'',asx@as') \\<in> dependent_live_vars n'\" .\n    from `as' \\<noteq> []` `(V,as'',as') \\<in> dependent_live_vars n'`\n    have \"n' = last(targetnodes as')\" \n      by(fastforce intro:dependent_live_vars_lastnode)\n    with `as' \\<noteq> []` have \"n' = last(targetnodes (ax#asx@as'))\"\n      by(fastforce simp:targetnodes_def)\n    have \"\\<not> sourcenode ax -{V}ax#asx@as''\\<rightarrow>\\<^bsub>dd\\<^esub> last(targetnodes (ax#asx@as''))\"\n    proof\n      assume \"sourcenode ax -{V}ax#asx@as''\\<rightarrow>\\<^bsub>dd\\<^esub> last(targetnodes (ax#asx@as''))\"\n      hence \"sourcenode ax -{V}ax#asx@as''\\<rightarrow>\\<^bsub>dd\\<^esub> last(targetnodes (ax#asx@as''))\"\n        by simp\n      with `\\<forall>n''\\<in>set (sourcenodes (ax#asx)). V \\<notin> Def n''`\n      show False\n        by(fastforce elim:DynPDG_edge.cases \n                    simp:dyn_data_dependence_def sourcenodes_def)\n    qed\n    with `(V,asx@as'',asx@as') \\<in> dependent_live_vars n'` \n      `n' = last(targetnodes (ax#asx@as'))`\n    show ?case by(fastforce intro:dep_vars_Cons_keep)\n  qed\nqed\n\n\n\nlemma dependent_live_vars_cdep_dependent_live_vars:\n  assumes \"n'' -as''\\<rightarrow>\\<^bsub>cd\\<^esub> n'\" and \"(V',as',as) \\<in> dependent_live_vars n''\"\n  shows \"(V',as',as@as'') \\<in> dependent_live_vars n'\"\nproof -\n  from `n'' -as''\\<rightarrow>\\<^bsub>cd\\<^esub> n'` have \"as'' \\<noteq> []\"\n    by(fastforce elim:DynPDG_edge.cases dest:dyn_control_dependence_path)\n  with `n'' -as''\\<rightarrow>\\<^bsub>cd\\<^esub> n'` have \"last(targetnodes as'') = n'\"\n    by(fastforce intro:path_targetnode elim:DynPDG_cdep_edge_CFG_path(1))\n  from `(V',as',as) \\<in> dependent_live_vars n''` show ?thesis\n  proof(induct rule:dependent_live_vars.induct)\n    case (dep_vars_Use V')\n    from `V' \\<in> Use n''` `n'' -as''\\<rightarrow>\\<^bsub>cd\\<^esub> n'` `last(targetnodes as'') = n'` show ?case\n      by(fastforce intro:dependent_live_vars_cdep_empty_fst simp:targetnodes_def)\n  next\n    case (dep_vars_Cons_cdep V a as' nx asx)\n    from `n'' -as''\\<rightarrow>\\<^bsub>cd\\<^esub> n'` have \"n'' -as''\\<rightarrow>\\<^sub>d* n'\" by(rule DynPDG_path_cdep)\n    with `nx -asx\\<rightarrow>\\<^sub>d* n''` have \"nx -asx@as''\\<rightarrow>\\<^sub>d* n'\"\n      by -(rule DynPDG_path_Append)\n    with `V \\<in> Use (sourcenode a)` `(sourcenode a) -a#as'\\<rightarrow>\\<^bsub>cd\\<^esub> nx`\n    show ?case by(fastforce intro:dependent_live_vars.dep_vars_Cons_cdep)\n  next\n    case (dep_vars_Cons_ddep V as' as V' a)\n    from `as'' \\<noteq> []` `last(targetnodes as'') = n'`\n    have \"n' = last(targetnodes ((a#as)@as''))\"\n      by(simp add:targetnodes_def)\n    with dep_vars_Cons_ddep\n    show ?case by(fastforce intro:dependent_live_vars.dep_vars_Cons_ddep)\n  next\n    case (dep_vars_Cons_keep V as' as a)\n    from `as'' \\<noteq> []` `last(targetnodes as'') = n'`\n    have \"n' = last(targetnodes ((a#as)@as''))\"\n      by(simp add:targetnodes_def)\n    with dep_vars_Cons_keep\n    show ?case by(fastforce intro:dependent_live_vars.dep_vars_Cons_keep)\n  qed\nqed\n\n\nlemma dependent_live_vars_ddep_dependent_live_vars:\n  assumes \"n'' -{V}as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'\" and \"(V',as',as) \\<in> dependent_live_vars n''\"\n  shows \"(V',as',as@as'') \\<in> dependent_live_vars n'\"\nproof -\n  from `n'' -{V}as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'` have \"as'' \\<noteq> []\"\n    by(rule DynPDG_ddep_edge_CFG_path(2))\n  with `n'' -{V}as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'` have \"last(targetnodes as'') = n'\"\n    by(fastforce intro:path_targetnode elim:DynPDG_ddep_edge_CFG_path(1))\n  from `n'' -{V}as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'` have notExit:\"n' \\<noteq> (_Exit_)\" \n    by(fastforce elim:DynPDG_edge.cases simp:dyn_data_dependence_def)\n  from `(V',as',as) \\<in> dependent_live_vars n''` show ?thesis\n  proof(induct rule:dependent_live_vars.induct)\n    case (dep_vars_Use V')\n    from `V' \\<in> Use n''` `n'' -{V}as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'` `last(targetnodes as'') = n'` show ?case\n      by(fastforce intro:dependent_live_vars_ddep_empty_fst simp:targetnodes_def)\n  next\n    case (dep_vars_Cons_cdep V' a as' nx asx)\n    from `n'' -{V}as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'` have \"n'' -as''\\<rightarrow>\\<^sub>d* n'\" by(rule DynPDG_path_ddep)\n    with `nx -asx\\<rightarrow>\\<^sub>d* n''` have \"nx -asx@as''\\<rightarrow>\\<^sub>d* n'\"\n      by -(rule DynPDG_path_Append)\n    with `V' \\<in> Use (sourcenode a)` `sourcenode a -a#as'\\<rightarrow>\\<^bsub>cd\\<^esub> nx` notExit\n    show ?case by(fastforce intro:dependent_live_vars.dep_vars_Cons_cdep)\n  next\n    case (dep_vars_Cons_ddep V as' as V' a)\n    from `as'' \\<noteq> []` `last(targetnodes as'') = n'`\n    have \"n' = last(targetnodes ((a#as)@as''))\"\n      by(simp add:targetnodes_def)\n    with dep_vars_Cons_ddep\n    show ?case by(fastforce intro:dependent_live_vars.dep_vars_Cons_ddep)\n  next\n    case (dep_vars_Cons_keep V as' as a)\n    from `as'' \\<noteq> []` `last(targetnodes as'') = n'`\n    have \"n' = last(targetnodes ((a#as)@as''))\"\n      by(simp add:targetnodes_def)\n    with dep_vars_Cons_keep\n    show ?case by(fastforce intro:dependent_live_vars.dep_vars_Cons_keep)\n  qed\nqed\n\n\nlemma dependent_live_vars_dep_dependent_live_vars:\n  \"\\<lbrakk>n'' -as''\\<rightarrow>\\<^sub>d* n'; (V',as',as) \\<in> dependent_live_vars n''\\<rbrakk>\n  \\<Longrightarrow> (V',as',as@as'') \\<in> dependent_live_vars n'\"\nproof(induct rule:DynPDG_path.induct)\n  case (DynPDG_path_Nil n) thus ?case by simp\nnext\n  case (DynPDG_path_Append_cdep n asx n'' asx' n')\n  note IH = `(V', as', as) \\<in> dependent_live_vars n \\<Longrightarrow>\n             (V', as', as @ asx) \\<in> dependent_live_vars n''`\n  from IH[OF `(V',as',as) \\<in> dependent_live_vars n`]\n  have \"(V',as',as@asx) \\<in> dependent_live_vars n''\" .\n  with `n'' -asx'\\<rightarrow>\\<^bsub>cd\\<^esub> n'` have \"(V',as',(as@asx)@asx') \\<in> dependent_live_vars n'\"\n    by(rule dependent_live_vars_cdep_dependent_live_vars)\n  thus ?case by simp\nnext\n  case (DynPDG_path_Append_ddep n asx n'' V asx' n')\n  note IH = `(V', as', as) \\<in> dependent_live_vars n \\<Longrightarrow>\n             (V', as', as @ asx) \\<in> dependent_live_vars n''`\n  from IH[OF `(V',as',as) \\<in> dependent_live_vars n`]\n  have \"(V',as',as@asx) \\<in> dependent_live_vars n''\" .\n  with `n'' -{V}asx'\\<rightarrow>\\<^bsub>dd\\<^esub> n'` have \"(V',as',(as@asx)@asx') \\<in> dependent_live_vars n'\"\n    by(rule dependent_live_vars_ddep_dependent_live_vars)\n  thus ?case by simp\nqed\n\nend\n\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Slicing/Dynamic/DependentLiveVariables.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.600188359260205, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.2813626770313686}}
{"text": "header {* ICF-setup for Automatic Refinement *}\ntheory ICF_Autoref\nimports \n  ICF_Refine_Monadic \n  \"../GenCF/Intf/Intf_Set\"\n  \"../GenCF/Intf/Intf_Map\"\nbegin\n\nsubsection {* Unique Priority Queue *}\nconsts i_prio :: \"interface \\<Rightarrow> interface \\<Rightarrow> interface\"\ndefinition [simp]: \"op_uprio_empty \\<equiv> Map.empty\"\ndefinition [simp]: \"op_uprio_is_empty x \\<equiv> x = Map.empty\"\ndefinition [simp]: \"op_uprio_insert s e a \\<equiv> s(e \\<mapsto> a)\"\ndefinition op_uprio_prio :: \"('e\\<rightharpoonup>'a)\\<Rightarrow>'e\\<rightharpoonup>'a\"\n  where [simp]: \"op_uprio_prio s e \\<equiv> s e\"\n\n(* FIXME: Tune id-op phase such that it can distinguish those patterns!\n  For now: Only include this patterns on demand!\n*)\ncontext begin interpretation autoref_syn .\n\nlemma uprio_pats:\n  fixes s :: \"'e\\<rightharpoonup>'a\"\n  shows\n  \"Map.empty::'e\\<rightharpoonup>'a \\<equiv> op_uprio_empty\"\n  \"s e \\<equiv> op_uprio_prio$s$e\"\n  \"s(e\\<mapsto>a) \\<equiv> op_uprio_insert$s$e$a\"\n\n  \"dom s = {} \\<equiv> op_uprio_is_empty$s\"\n  \"{} = dom s \\<equiv> op_uprio_is_empty$s\"\n  \"s=Map.empty \\<equiv> op_uprio_is_empty$s\"\n  \"Map.empty=s \\<equiv> op_uprio_is_empty$s\"\n  by (auto intro!: eq_reflection)\n\nend\n\nterm prio_pop_min\n\nlemma [autoref_itype]:\n  \"op_uprio_empty ::\\<^sub>i \\<langle>Ie,Ia\\<rangle>\\<^sub>ii_prio\"\n  \"op_uprio_prio ::\\<^sub>i \\<langle>Ie,Ia\\<rangle>\\<^sub>ii_prio \\<rightarrow>\\<^sub>i Ie \\<rightarrow>\\<^sub>i \\<langle>Ia\\<rangle>\\<^sub>ii_option\"\n  \"op_uprio_is_empty ::\\<^sub>i \\<langle>Ie,Ia\\<rangle>\\<^sub>ii_prio \\<rightarrow>\\<^sub>i i_bool\"\n  \"op_uprio_insert ::\\<^sub>i \\<langle>Ie,Ia\\<rangle>\\<^sub>ii_prio \\<rightarrow>\\<^sub>i Ie \\<rightarrow>\\<^sub>i Ia \\<rightarrow>\\<^sub>i \\<langle>Ie,Ia\\<rangle>\\<^sub>ii_prio\"\n  \"prio_pop_min ::\\<^sub>i \\<langle>Ie,Ia\\<rangle>\\<^sub>ii_prio \\<rightarrow>\\<^sub>i \\<langle>\\<langle>Ie,\\<langle>Ia,\\<langle>Ie,Ia\\<rangle>\\<^sub>ii_prio\\<rangle>\\<^sub>ii_prod\\<rangle>\\<^sub>ii_prod\\<rangle>\\<^sub>ii_nres\"\n  by simp_all\n\ncontext uprio begin\n  definition rel_def_internal: \n    \"rel Re Ra \\<equiv> br \\<alpha> invar O (Re \\<rightarrow> \\<langle>Ra\\<rangle> option_rel)\"\n  lemma rel_def:\n    \"\\<langle>Re,Ra\\<rangle>rel \\<equiv> br \\<alpha> invar O (Re \\<rightarrow> \\<langle>Ra\\<rangle> option_rel)\" \n    by (simp add: rel_def_internal relAPP_def)\n    \n  \n\n  lemma rel_sv[relator_props]: \n    \"\\<lbrakk>Range Re = UNIV; single_valued Ra\\<rbrakk> \\<Longrightarrow> single_valued (\\<langle>Re,Ra\\<rangle>rel)\"\n    unfolding rel_def by tagged_solver\n\n  lemmas [autoref_rel_intf] = REL_INTFI[of rel i_prio]\nend\n\n\nlemma (in uprio) rel_alt: \"\\<langle>Id,Rv\\<rangle>rel = \n  { (c,a). \\<forall>x. (\\<alpha> c x,a x)\\<in>\\<langle>Rv\\<rangle>option_rel \\<and> invar c }\"\n  by (auto simp: rel_def br_def dest: fun_relD)\n\nlemma (in uprio_empty) autoref_empty[autoref_rules]:\n  \"PREFER_id Re \\<Longrightarrow> (empty (),op_uprio_empty)\\<in>\\<langle>Re,Ra\\<rangle>rel\"\n  by (auto simp: empty_correct rel_alt)\n\nlemma (in uprio_isEmpty) autoref_is_empty[autoref_rules]:\n  \"PREFER_id Re \\<Longrightarrow> (isEmpty,op_uprio_is_empty)\\<in>\\<langle>Re,Ra\\<rangle>rel\\<rightarrow>bool_rel\"\n  by (auto simp: isEmpty_correct rel_alt intro!: ext)\n\nlemma (in uprio_prio) autoref_prio[autoref_rules]:\n  \"PREFER_id Re \\<Longrightarrow> (prio,op_uprio_prio)\\<in>\\<langle>Re,Ra\\<rangle>rel\\<rightarrow>Re\\<rightarrow>\\<langle>Ra\\<rangle>option_rel\"\n  by (auto simp: prio_correct rel_alt intro!: ext)\n\nlemma (in uprio_insert) autoref_insert[autoref_rules]:\n  \"PREFER_id Re \\<Longrightarrow> (insert,op_uprio_insert)\\<in>\\<langle>Re,Ra\\<rangle>rel\\<rightarrow>Re\\<rightarrow>Ra\\<rightarrow>\\<langle>Re,Ra\\<rangle>rel\"\n  by (auto simp: insert_correct rel_alt intro!: ext)\n\nlemma (in uprio_pop) autoref_prio_pop_min[autoref_rules]:\n  \"\\<lbrakk>PREFER_id Re; PREFER_id Ra \\<rbrakk> \n  \\<Longrightarrow> (\\<lambda>s. RETURN (pop s),prio_pop_min)\\<in>\\<langle>Re,Ra\\<rangle>rel\\<rightarrow>\\<langle>\\<langle>Re,\\<langle>Ra,\\<langle>Re,Ra\\<rangle>rel\\<rangle>prod_rel\\<rangle>prod_rel\\<rangle>nres_rel\"\n  apply simp\n  apply (intro fun_relI nres_relI)\n  by (rule prio_pop_min_refine)\n\n\n\n\ncontext set begin\n  definition rel_def_internal: \"rel R \\<equiv> br \\<alpha> invar O \\<langle>R\\<rangle>set_rel\"\n  lemma rel_def: \"\\<langle>R\\<rangle>rel \\<equiv> br \\<alpha> invar O \\<langle>R\\<rangle>set_rel\" \n    by (simp add: rel_def_internal relAPP_def)\n    \n  lemma rel_id[simp]: \"\\<langle>Id\\<rangle>rel = br \\<alpha> invar\" by (simp add: rel_def)\n\n  lemma rel_sv[relator_props]: \"single_valued R \\<Longrightarrow> single_valued (\\<langle>R\\<rangle>rel)\"\n    unfolding rel_def by tagged_solver\n\n  lemmas [autoref_rel_intf] = REL_INTFI[of rel i_set]\n\nend\n\ncontext map begin\n  definition rel_def_internal: \n    \"rel Rk Rv \\<equiv> br \\<alpha> invar O (Rk \\<rightarrow> \\<langle>Rv\\<rangle> option_rel)\"\n  lemma rel_def: \n    \"\\<langle>Rk,Rv\\<rangle>rel \\<equiv> br \\<alpha> invar O (Rk \\<rightarrow> \\<langle>Rv\\<rangle> option_rel)\" \n    by (simp add: rel_def_internal relAPP_def)\n    \n  lemma rel_id[simp]: \"\\<langle>Id,Id\\<rangle>rel = br \\<alpha> invar\" \n    by (simp add: rel_def)\n\n  lemma rel_sv[relator_props]: \n    \"\\<lbrakk>Range Rk = UNIV; single_valued Rv\\<rbrakk> \\<Longrightarrow> single_valued (\\<langle>Rk,Rv\\<rangle>rel)\"\n    unfolding rel_def \n    by (tagged_solver (trace))\n\n  lemmas [autoref_rel_intf] = REL_INTFI[of rel i_map]\n\nend\n\n\n(*\ncontext list begin\n  definition rel_def_internal: \n    \"rel R \\<equiv> br \\<alpha> invar O R\"\n  lemma rel_def: \"\\<langle>R\\<rangle>rel \\<equiv> br \\<alpha> invar O R\" \n    by (simp add: rel_def_internal relAPP_def)\n    \n  lemma rel_id[simp]: \"\\<langle>Id\\<rangle>rel = br \\<alpha> invar\" \n    by (simp add: rel_def)\n\n  lemma rel_sv[relator_props]: \"single_valued R \\<Longrightarrow> single_valued (\\<langle>R\\<rangle>rel)\"\n    unfolding rel_def by refine_post\nend\n\ncontext al begin\n  definition rel_def_internal: \n    \"rel Re Ra \\<equiv> br \\<alpha> invar O \\<langle>\\<langle>Re,Ra\\<rangle> prod_rel\\<rangle>list_rel\"\n  lemma rel_def: \n    \"\\<langle>Re,Ra\\<rangle>rel \\<equiv> br \\<alpha> invar O \\<langle>\\<langle>Re,Ra\\<rangle> prod_rel\\<rangle>list_rel\" \n    by (simp add: rel_def_internal relAPP_def)\n    \n  lemma rel_id[simp]: \"\\<langle>Id,Id\\<rangle>rel = br \\<alpha> invar\" \n    by (simp add: rel_def)\n\n  lemma rel_sv[relator_props]: \n    \"\\<lbrakk>single_valued Re; single_valued Ra\\<rbrakk> \\<Longrightarrow> single_valued (\\<langle>Re,Ra\\<rangle>rel)\"\n    unfolding rel_def by refine_post\n\nend\n\ncontext prio begin\n  (* TODO: Fix that to use multiset_rel! *)\n  definition rel_def[simp]: \"rel \\<equiv> br \\<alpha> invar\"\n  lemma rel_sv: \"single_valued rel\" unfolding rel_def by refine_post\nend\n\ncontext uprio begin\n  definition rel_def_internal: \n    \"rel Re Ra \\<equiv> br \\<alpha> invar O (Re \\<rightarrow> \\<langle>Ra\\<rangle> option_rel)\"\n  lemma rel_def:\n    \"\\<langle>Re,Ra\\<rangle>rel \\<equiv> br \\<alpha> invar O (Re \\<rightarrow> \\<langle>Ra\\<rangle> option_rel)\" \n    by (simp add: rel_def_internal relAPP_def)\n    \n  lemma rel_id[simp]: \"\\<langle>Id,Id\\<rangle>rel = br \\<alpha> invar\" \n    by (simp add: rel_def)\n\n  lemma rel_sv[relator_props]: \n    \"\\<lbrakk>Range Re = UNIV; single_valued Ra\\<rbrakk> \\<Longrightarrow> single_valued (\\<langle>Re,Ra\\<rangle>rel)\"\n    unfolding rel_def by refine_post\n\nend\n*)\n\n\nsetup {* Revert_Abbrev.revert_abbrev \"Autoref_Binding_ICF.*.rel\" *}\n\n\n\n\n(* TODO: Move *)\nlemma Collect_x_x_pairs_rel_image[simp]: \"{p. \\<exists>x. p = (x, x)}``x = x\" \n    by auto\n\n\nsubsection \"Set\"\n\nlemma (in set_empty) empty_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (empty (), {}) \\<in> \\<langle>Rk\\<rangle>rel\"\n  by (simp add: br_def empty_correct)\n\nlemma (in set_memb) memb_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (memb,op \\<in>)\\<in>Rk\\<rightarrow>\\<langle>Rk\\<rangle>rel\\<rightarrow>Id\"\n  apply simp\n  by (auto simp add: memb_correct br_def)\n\nlemma (in set_ins) ins_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (ins,Set.insert)\\<in>Rk\\<rightarrow>\\<langle>Rk\\<rangle>rel\\<rightarrow>\\<langle>Rk\\<rangle>rel\"\n  by simp (auto simp add: ins_correct br_def)\n\ncontext set_ins_dj begin\ncontext begin interpretation autoref_syn .\nlemma ins_dj_autoref[autoref_rules]: \n  assumes \"SIDE_PRECOND_OPT (x'\\<notin>s')\"\n  assumes \"PREFER_id Rk\"\n  assumes \"(x,x')\\<in>Rk\"\n  assumes \"(s,s')\\<in>\\<langle>Rk\\<rangle>rel\"\n  shows \"(ins_dj x s,(OP Set.insert ::: Rk \\<rightarrow> \\<langle>Rk\\<rangle>rel \\<rightarrow> \\<langle>Rk\\<rangle>rel)$x'$s')\\<in>\\<langle>Rk\\<rangle>rel\"\n  using assms \n  apply simp\n  apply (auto simp add: ins_dj_correct br_def)\n  done\nend\nend\n\nlemma (in set_delete) delete_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (delete,op_set_delete)\\<in>Rk\\<rightarrow>\\<langle>Rk\\<rangle>rel\\<rightarrow>\\<langle>Rk\\<rangle>rel\"\n  by simp (auto simp add: delete_correct op_set_delete_def br_def)\n \nlemma (in set_isEmpty) isEmpty_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (isEmpty,op_set_isEmpty) \\<in> \\<langle>Rk\\<rangle>rel\\<rightarrow>Id\"\n  apply (simp add: br_def)\n  apply (fastforce simp: isEmpty_correct)\n  done\n\nlemma (in set_isSng) isSng_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (isSng,op_set_isSng) \\<in> \\<langle>Rk\\<rangle>rel\\<rightarrow>Id\"\n  by simp\n    (auto simp add: isSng_correct op_set_isSng_def br_def card_Suc_eq)\n\nlemma (in set_ball) ball_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (ball,Set.Ball) \\<in> \\<langle>Rk\\<rangle>rel\\<rightarrow>(Rk\\<rightarrow>Id)\\<rightarrow>Id\"\n  by simp (auto simp add: ball_correct fun_rel_def br_def)\n\nlemma (in set_bex) bex_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (bex,Set.Bex) \\<in> \\<langle>Rk\\<rangle>rel\\<rightarrow>(Rk\\<rightarrow>Id)\\<rightarrow>Id\"\n  apply simp\n  apply (auto simp: bex_correct fun_rel_def br_def intro!: ext)\n  done\n\nlemma (in set_size) size_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (size,card) \\<in> \\<langle>Rk\\<rangle>rel \\<rightarrow> Id\"\n  by simp (auto simp add: size_correct br_def)\n\nlemma (in set_size_abort) size_abort_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (size_abort,op_set_size_abort) \\<in> Id \\<rightarrow> \\<langle>Rk\\<rangle>rel \\<rightarrow> Id\"\n  by simp\n    (auto simp add: size_abort_correct op_set_size_abort_def br_def)\n\nlemma (in set_union) union_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (union,op \\<union>)\\<in>\\<langle>Rk\\<rangle>s1.rel\\<rightarrow>\\<langle>Rk\\<rangle>s2.rel\\<rightarrow>\\<langle>Rk\\<rangle>s3.rel\"\n  by simp (auto simp add: union_correct br_def)\n\ncontext set_union_dj begin\ncontext begin interpretation autoref_syn .\n\nlemma union_dj_autoref[autoref_rules]:\n  assumes \"PREFER_id Rk\"\n  assumes \"SIDE_PRECOND_OPT (a'\\<inter>b'={})\"\n  assumes \"(a,a')\\<in>\\<langle>Rk\\<rangle>s1.rel\"\n  assumes \"(b,b')\\<in>\\<langle>Rk\\<rangle>s2.rel\"\n  shows \"(union_dj a b,(OP op \\<union> ::: \\<langle>Rk\\<rangle>s1.rel \\<rightarrow> \\<langle>Rk\\<rangle>s2.rel \\<rightarrow> \\<langle>Rk\\<rangle>s3.rel)$a'$b')\n    \\<in>\\<langle>Rk\\<rangle>s3.rel\"\n  using assms \n  by simp (auto simp: union_dj_correct br_def)\nend \nend\n\nlemma (in set_diff) diff_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (diff,op -)\\<in>\\<langle>Rk\\<rangle>s1.rel\\<rightarrow>\\<langle>Rk\\<rangle>s2.rel\\<rightarrow>\\<langle>Rk\\<rangle>s1.rel\"\n  by simp (auto simp add: diff_correct br_def)\n\nlemma (in set_filter) filter_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (filter,op_set_filter)\\<in>(Rk \\<rightarrow> Id) \\<rightarrow> \\<langle>Rk\\<rangle>s1.rel\\<rightarrow>\\<langle>Rk\\<rangle>s2.rel\"\n  by simp (auto simp add: filter_correct op_set_filter_def fun_rel_def \n    br_def)\n\nlemma (in set_inter) inter_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (inter,op \\<inter>)\\<in>\\<langle>Rk\\<rangle>s1.rel\\<rightarrow>\\<langle>Rk\\<rangle>s2.rel\\<rightarrow>\\<langle>Rk\\<rangle>s3.rel\"\n  by simp (auto simp add: inter_correct br_def)\n\nlemma (in set_subset) subset_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (subset,op \\<subseteq>)\\<in>\\<langle>Rk\\<rangle>s1.rel\\<rightarrow>\\<langle>Rk\\<rangle>s2.rel\\<rightarrow>Id\"\n  by simp (auto simp add: subset_correct br_def)\n\nlemma (in set_equal) equal_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (equal,op =)\\<in>\\<langle>Rk\\<rangle>s1.rel\\<rightarrow>\\<langle>Rk\\<rangle>s2.rel\\<rightarrow>Id\"\n  by simp (auto simp add: equal_correct br_def)\n\nlemma (in set_disjoint) disjoint_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (disjoint,op_set_disjoint)\\<in>\\<langle>Rk\\<rangle>s1.rel\\<rightarrow>\\<langle>Rk\\<rangle>s2.rel\\<rightarrow>Id\"\n  by simp (auto simp add: disjoint_correct op_set_disjoint_def br_def)\n\nlemma (in list_to_set) to_set_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (to_set,set)\\<in>\\<langle>Rk\\<rangle>list_rel \\<rightarrow> \\<langle>Rk\\<rangle>rel\"\n  apply simp\n  apply (auto simp add: to_set_correct br_def)\n  done\n\ncontext set_sel' begin\ncontext begin interpretation autoref_syn .\n\nlemma autoref_op_set_pick[autoref_rules]: \n  assumes \"SIDE_PRECOND (s'\\<noteq>{})\"\n  assumes \"PREFER_id Rk\"\n  assumes \"(s,s')\\<in>\\<langle>Rk\\<rangle>rel\"\n  shows \"(RETURN (the (sel' s (\\<lambda>_. True))), \n          (OP op_set_pick ::: \\<langle>Rk\\<rangle>rel \\<rightarrow> \\<langle>Rk\\<rangle>nres_rel) $ s')\n    \\<in> \\<langle>Rk\\<rangle>nres_rel\"\n  using assms\n  apply (clarsimp simp add: br_def nres_rel_def ex_in_conv[symmetric])\n  apply (erule (1) sel'E[OF _ _ TrueI])\n  apply (auto intro: RES_refine)\n  done\nend\nend\n\nlemma (in poly_set_iteratei) proper[proper_it]:\n  \"proper_it' iteratei iteratei\"\n  apply (rule proper_it'I)\n  by (rule pi_iteratei)\n\nlemma (in poly_set_iteratei) autoref_iteratei[autoref_ga_rules]: \n  \"REL_IS_ID Rk \\<Longrightarrow> is_set_to_list Rk rel (it_to_list iteratei)\"\n  unfolding is_set_to_list_def is_set_to_sorted_list_def it_to_list_def \n    it_to_sorted_list_def\n  apply (simp add: br_def, intro allI impI)\n  apply (drule iteratei_correct)\n  unfolding set_iterator_def set_iterator_genord_foldli_conv\n  apply (elim exE)\n  apply clarsimp\n  apply (drule fun_cong[where x=\"\\<lambda>_::'x list. True\"])\n  apply simp\n  done\n\nlemma (in poly_set_iterateoi) proper_o[proper_it]:\n  \"proper_it' iterateoi iterateoi\"\n  apply (rule proper_it'I)\n  by (rule pi_iterateoi)\n\n\n\nlemma (in poly_set_rev_iterateoi) autoref_rev_iterateoi[autoref_ga_rules]: \n  \"REL_IS_ID Rk \\<Longrightarrow> \n    is_set_to_sorted_list op \\<ge> Rk rel (it_to_list rev_iterateoi)\"\n  unfolding is_set_to_sorted_list_def it_to_list_def it_to_sorted_list_def\n  apply (simp add: br_def, intro allI impI)\n  apply (drule rev_iterateoi_correct)\n  unfolding set_iterator_rev_linord_def set_iterator_genord_foldli_conv\n  apply (elim exE)\n  apply clarsimp\n  apply (drule fun_cong[where x=\"\\<lambda>_::'x list. True\"])\n  apply simp\n  done\n\nlemma (in poly_set_rev_iterateoi) proper_ro[proper_it]:\n  \"proper_it' rev_iterateoi rev_iterateoi\"\n  apply (rule proper_it'I)\n  by (rule pi_rev_iterateoi)\n\nsubsection \"Map\"\n\nlemma (in map) rel_alt: \"\\<langle>Id,Rv\\<rangle>rel = \n  { (c,a). \\<forall>x. (\\<alpha> c x,a x)\\<in>\\<langle>Rv\\<rangle>option_rel \\<and> invar c }\"\n  by (auto simp: rel_def br_def dest: fun_relD)\n\nlemma (in map_empty) empty_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (empty (),op_map_empty)\\<in>\\<langle>Rk,Rv\\<rangle>rel\"\n  by (auto simp: empty_correct rel_alt)\n  \nlemma (in map_lookup) lookup_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (lookup,op_map_lookup)\\<in>Rk\\<rightarrow>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>\\<langle>Rv\\<rangle>option_rel\"\n  apply (intro fun_relI option_relI)\n  apply (auto simp: lookup_correct rel_alt\n    dest: fun_relD2)\n  done\n\nlemma (in map_update) update_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (update,op_map_update)\\<in>Rk\\<rightarrow>Rv\\<rightarrow>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>\\<langle>Rk,Rv\\<rangle>rel\"\n  apply (intro fun_relI)\n  apply (simp add: update_correct rel_alt)\n  done\n\ncontext map_update_dj begin\ncontext begin interpretation autoref_syn .\n\nlemma update_dj_autoref[autoref_rules]: \n  assumes \"SIDE_PRECOND_OPT (k'\\<notin>dom m')\"\n  assumes \"PREFER_id Rk\"\n  assumes \"(k,k')\\<in>Rk\"\n  assumes \"(v,v')\\<in>Rv\"\n  assumes \"(m,m')\\<in>\\<langle>Rk,Rv\\<rangle>rel\"\n  shows \"(update_dj k v m,\n    (OP op_map_update ::: Rk \\<rightarrow> Rv \\<rightarrow> \\<langle>Rk,Rv\\<rangle>rel \\<rightarrow> \\<langle>Rk,Rv\\<rangle>rel)$k'$v'$m'\n  )\\<in>\\<langle>Rk,Rv\\<rangle>rel\"\n  using assms\n  apply (subgoal_tac \"k\\<notin>dom (\\<alpha> m)\")\n  apply (simp add: update_dj_correct rel_alt)\n  apply (auto simp add: rel_alt option_rel_def)\n  apply (metis option.simps(3))\n  done\nend\nend\n\nlemma (in map_delete) delete_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (delete,op_map_delete)\\<in>Rk\\<rightarrow>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>\\<langle>Rk,Rv\\<rangle>rel\"\n  apply (intro fun_relI)\n  apply (simp add: delete_correct restrict_map_def rel_alt)\n  done\n\nlemma (in map_restrict) restrict_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> \n    (restrict,op_map_restrict) \n    \\<in> (\\<langle>Rk,Rv\\<rangle>prod_rel \\<rightarrow> Id) \\<rightarrow> \\<langle>Rk,Rv\\<rangle>m1.rel \\<rightarrow> \\<langle>Rk,Rv\\<rangle>m2.rel\"\n  apply (intro fun_relI)\n  apply (simp add: restrict_correct br_comp_alt m1.rel_def m2.rel_def )\n  apply (intro fun_relI)\n  apply (auto simp: restrict_map_def split: split_if_asm)\n  apply (drule (1) fun_relD1)\n  apply (auto simp: option_rel_def) []\n  apply (drule (1) fun_relD1)\n  apply (auto simp: option_rel_def) []\n  apply (drule (1) fun_relD1)\n  apply (auto simp: option_rel_def prod_rel_def fun_rel_def) []\n  apply (drule (1) fun_relD2)\n  apply (auto simp: option_rel_def prod_rel_def fun_rel_def) []\n  done\n\nlemma (in map_add) add_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (add,op ++)\\<in>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>\\<langle>Rk,Rv\\<rangle>rel\"\n  apply (auto simp add: add_correct rel_alt Map.map_add_def\n    split: option.split)\n  apply (drule_tac x=x in spec)+\n  apply simp\n  apply (metis option.simps(3) option_rel_simp(2))\n  by (metis (lifting) option_rel_simp(3))\n\n\ncontext map_add_dj begin\ncontext begin interpretation autoref_syn .\n\nlemma add_dj_autoref[autoref_rules]: \n  assumes \"PREFER_id Rk\"\n  assumes \"SIDE_PRECOND_OPT (dom a' \\<inter> dom b' = {})\"\n  assumes \"(a,a')\\<in>\\<langle>Rk,Rv\\<rangle>rel\"\n  assumes \"(b,b')\\<in>\\<langle>Rk,Rv\\<rangle>rel\"\n  shows \"(add_dj a b, (OP op ++ ::: \\<langle>Rk,Rv\\<rangle>rel \\<rightarrow> \\<langle>Rk,Rv\\<rangle>rel \\<rightarrow> \\<langle>Rk,Rv\\<rangle>rel) $ a' $ b')\\<in>\\<langle>Rk,Rv\\<rangle>rel\"\n  using assms\n  apply simp\n  apply (subgoal_tac \"dom (\\<alpha> a) \\<inter> dom (\\<alpha> b) = {}\")\n  apply (clarsimp simp add: add_dj_correct rel_def br_comp_alt)\n  apply (auto \n    simp add: rel_def br_comp_alt Map.map_add_def\n    split: option.split\n    elim: fun_relE1 dest: fun_relD1 intro: option_relI\n  ) []\n\n  apply (clarsimp simp add: rel_def br_comp_alt)\n\n  apply (auto simp: dom_def)\n  apply (drule (1) fun_relD1)\n  apply (drule (1) fun_relD1)\n  apply (auto simp: option_rel_def)\n  done\nend\nend\n\nlemma (in map_isEmpty) isEmpty_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (isEmpty,op_map_isEmpty)\\<in>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>Id\"\n  by (auto simp: isEmpty_correct rel_alt\n    intro!: ext)\n\nlemma sngI: \n  assumes \"m k = Some v\"\n  assumes \"\\<forall>k'. k'\\<noteq>k \\<longrightarrow> m k' = None\"\n  shows \"m = [k\\<mapsto>v]\"\n  using assms\n  by (auto intro!: ext)\n\nlemma (in map_isSng) isSng_autoref[autoref_rules]: \n  \"PREFER_id Rk \\<Longrightarrow> (isSng,op_map_isSng)\\<in>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>Id\"\n  (* TODO: Clean up this mess *)\n  apply (auto simp add: isSng_correct rel_alt)\n  apply (rule_tac x=k in exI)\n  apply (rule_tac x=\"the (a' k)\" in exI)\n  apply (rule sngI)\n  apply (drule_tac x=k in spec)\n  apply (auto elim: option_relE) []\n  apply (force elim: option_relE) []\n\n  apply (rule_tac x=k in exI)\n  apply (rule_tac x=\"the (\\<alpha> a k)\" in exI)\n  apply (rule sngI)\n  apply (drule_tac x=k in spec)\n  apply (auto elim: option_relE) []\n  apply (force elim: option_relE) []\n  done\n\nlemma (in map_ball) ball_autoref[autoref_rules]:\n  \"PREFER_id Rk \\<Longrightarrow> (ball,op_map_ball)\\<in>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>(\\<langle>Rk,Rv\\<rangle>prod_rel\\<rightarrow>Id)\\<rightarrow>Id\"\n  apply (auto simp: ball_correct rel_alt map_to_set_def\n    option_rel_def prod_rel_def fun_rel_def)\n  apply (metis option.inject option.simps(3))+\n  done\n\nlemma (in map_bex) bex_autoref[autoref_rules]:\n  \"PREFER_id Rk \\<Longrightarrow> (bex,op_map_bex)\\<in>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>(\\<langle>Rk,Rv\\<rangle>prod_rel\\<rightarrow>Id)\\<rightarrow>Id\"\n  apply (auto simp: bex_correct map_to_set_def rel_alt \n    option_rel_def prod_rel_def fun_rel_def)\n  apply (metis option.inject option.simps(3))+\n  done\n\nlemma (in map_size) size_autoref[autoref_rules]:\n  \"PREFER_id Rk \\<Longrightarrow> (size,op_map_size)\\<in>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>Id\"\n  apply (auto simp: size_correct rel_alt option_rel_def dom_def \n    intro!: arg_cong[where f=card])\n  apply (metis option.simps(3))+\n  done\n\nlemma (in map_size_abort) size_abort_autoref[autoref_rules]:\n  \"PREFER_id Rk \\<Longrightarrow> (size_abort,op_map_size_abort)\\<in>Id\\<rightarrow>\\<langle>Rk,Rv\\<rangle>rel\\<rightarrow>Id\"\n  apply (auto simp: size_abort_correct  \n    rel_alt option_rel_def\n    dom_def intro!: arg_cong[where f=card] cong[OF arg_cong[where f=min]])\n  apply (metis option.simps(3))+\n  done\n\nlemma (in list_to_map) to_map_autoref[autoref_rules]:\n  \"PREFER_id Rk \\<Longrightarrow> (to_map,map_of)\\<in> \\<langle>\\<langle>Rk,Rv\\<rangle>prod_rel\\<rangle>list_rel \\<rightarrow> \\<langle>Rk,Rv\\<rangle>rel\"\nproof (intro fun_relI)\n  fix l :: \"('u\\<times>'v) list\" and l' :: \"('u\\<times>'a) list\"\n  assume \"PREFER_id Rk\" hence [simp]: \"Rk=Id\" by simp\n  assume \"(l,l')\\<in>\\<langle>\\<langle>Rk,Rv\\<rangle>prod_rel\\<rangle>list_rel\"\n  thus \"(to_map l, map_of l') \\<in> \\<langle>Rk,Rv\\<rangle>rel\"\n    apply (simp add: list_rel_def)\n  proof (induct rule: list_all2_induct)\n    case Nil thus ?case \n      by (auto simp add: to_map_correct rel_alt)\n  next\n    case (Cons x x' l l') thus ?case\n      by (auto simp add: to_map_correct \n        rel_alt prod_rel_def)\n  qed\nqed\n\n(* TODO: Move *)\nlemma key_rel_true[simp]: \"key_rel (\\<lambda>_ _. True) = (\\<lambda>_ _. True)\"\n  by (auto intro!: ext simp: key_rel_def)\n\n\nlemma (in poly_map_iteratei) proper[proper_it]:\n  \"proper_it' iteratei iteratei\"\n  apply (rule proper_it'I)\n  by (rule pi_iteratei)\n\nlemma (in poly_map_iteratei) autoref_iteratei[autoref_ga_rules]: \n  assumes ID: \"REL_IS_ID Rk\"\n    \"REL_IS_ID Rv\" (* TODO: Unnecessary*)\n  shows \"is_map_to_list Rk Rv rel (it_to_list iteratei)\"\nproof -\n  from ID have [simp]: \"Rk=Id\" \"Rv = Id\" by simp_all\n\n  show ?thesis\n    unfolding is_map_to_sorted_list_def is_map_to_list_def\n      it_to_sorted_list_def\n    apply simp\n    apply (intro allI impI conjI)\n  proof -\n    fix m m'\n    assume \"(m, m') \\<in> br \\<alpha> invar\"\n    hence I: \"invar m\" and M': \"m' = \\<alpha> m\" by (simp_all add: br_def)\n\n    have [simp]: \"\\<And>c. (\\<lambda>(_,_). c) = (\\<lambda>_. c)\" by auto\n\n    from map_it_to_list_genord_correct[where it = iteratei, \n      where R=\"\\<lambda>_ _. True\", simplified, OF \n      iteratei_correct[OF I, unfolded set_iterator_def]\n    ] have \n        M: \"Map.map_of (it_to_list iteratei m) = \\<alpha> m\"\n        and D: \"distinct (List.map fst (it_to_list iteratei m))\"\n      by (simp_all)\n\n    from D show \"distinct (it_to_list iteratei m)\"\n      by (rule distinct_mapI)\n\n    from M show \"map_to_set m' = set (it_to_list iteratei m)\"\n      by (simp add: M' map_of_map_to_set[OF D])\n  qed\nqed\n\nlemma (in poly_map_iterateoi) proper_o[proper_it]:\n  \"proper_it' iterateoi iterateoi\"\n  apply (rule proper_it'I)\n  by (rule pi_iterateoi)\n\nlemma (in poly_map_iterateoi) autoref_iterateoi[autoref_ga_rules]: \n  assumes ID: \"REL_IS_ID Rk\"\n    \"REL_IS_ID Rv\" (* TODO: Unnecessary*)\n  shows \"is_map_to_sorted_list op \\<le> Rk Rv rel (it_to_list iterateoi)\"\nproof -\n  from ID have [simp]: \"Rk=Id\" \"Rv = Id\" by simp_all\n\n  show ?thesis\n    unfolding is_map_to_sorted_list_def\n      it_to_sorted_list_def\n    apply simp\n    apply (intro allI impI conjI)\n  proof -\n    fix m m'\n    assume \"(m, m') \\<in> br \\<alpha> invar\"\n    hence I: \"invar m\" and M': \"m' = \\<alpha> m\" by (simp_all add: br_def)\n\n    have [simp]: \"\\<And>c. (\\<lambda>(_,_). c) = (\\<lambda>_. c)\" by auto\n\n    from map_it_to_list_linord_correct[where it = iterateoi, \n      OF iterateoi_correct[OF I]\n    ] have \n        M: \"map_of (it_to_list iterateoi m) = \\<alpha> m\"\n        and D: \"distinct (map fst (it_to_list iterateoi m))\"\n        and S: \"sorted (map fst (it_to_list iterateoi m))\"\n      by (simp_all)\n\n    from D show \"distinct (it_to_list iterateoi m)\"\n      by (rule distinct_mapI)\n\n    from M show \"map_to_set m' = set (it_to_list iterateoi m)\"\n      by (simp add: M' map_of_map_to_set[OF D])\n\n    from S show \"sorted_by_rel (key_rel op \\<le>) (it_to_list iterateoi m)\"\n      by (simp add: key_rel_def[abs_def])\n\n  qed\nqed\n\nlemma (in poly_map_rev_iterateoi) proper_ro[proper_it]:\n  \"proper_it' rev_iterateoi rev_iterateoi\"\n  apply (rule proper_it'I)\n  by (rule pi_rev_iterateoi)\n\nlemma (in poly_map_rev_iterateoi) autoref_rev_iterateoi[autoref_ga_rules]: \n  assumes ID: \"REL_IS_ID Rk\"\n    \"REL_IS_ID Rv\" (* TODO: Unnecessary*)\n  shows \"is_map_to_sorted_list op \\<ge> Rk Rv rel (it_to_list rev_iterateoi)\"\nproof -\n  from ID have [simp]: \"Rk=Id\" \"Rv = Id\" by simp_all\n\n  show ?thesis\n    unfolding is_map_to_sorted_list_def\n      it_to_sorted_list_def\n    apply simp\n    apply (intro allI impI conjI)\n  proof -\n    fix m m'\n    assume \"(m, m') \\<in> br \\<alpha> invar\"\n    hence I: \"invar m\" and M': \"m' = \\<alpha> m\" by (simp_all add: br_def)\n\n    have [simp]: \"\\<And>c. (\\<lambda>(_,_). c) = (\\<lambda>_. c)\" by auto\n\n    from map_it_to_list_rev_linord_correct[where it = rev_iterateoi, \n      OF rev_iterateoi_correct[OF I]\n    ] have \n        M: \"map_of (it_to_list rev_iterateoi m) = \\<alpha> m\"\n        and D: \"distinct (map fst (it_to_list rev_iterateoi m))\"\n        and S: \"sorted (rev (map fst (it_to_list rev_iterateoi m)))\"\n      by (simp_all)\n\n    from D show \"distinct (it_to_list rev_iterateoi m)\"\n      by (rule distinct_mapI)\n\n    from M show \"map_to_set m' = set (it_to_list rev_iterateoi m)\"\n      by (simp add: M' map_of_map_to_set[OF D])\n\n    from S show \"sorted_by_rel (key_rel op \\<ge>) (it_to_list rev_iterateoi m)\"\n      by (simp add: key_rel_def[abs_def])\n\n  qed\nqed\n\n\n\n\n\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Collections/ICF/ICF_Autoref.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5583269796369905, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.2813444102119438}}
{"text": "(******************************************************************************\n * HOL-TestGen --- theorem-prover based test case generation\n *                 http://www.brucker.ch/projects/hol-testgen/\n *\n * Monads.thy --- a base testing theory for sequential computations.\n * This file is part of HOL-TestGen.\n *\n * Copyright (c) 2005-2007 ETH Zurich, Switzerland\n *               2009 B. Wolff, Univ. Paris-Saclay, Univ. Paris-Sud, France\n *               2009,2012 Achim D. Brucker, Germany\n *               2013-2016 Université Paris-Saclay, Univ. Paris-Sud, France\n *               2013-2016 IRT SystemX, France\n *\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are\n * met:\n *\n *     * Redistributions of source code must retain the above copyright\n *       notice, this list of conditions and the following disclaimer.\n *\n *     * Redistributions in binary form must reproduce the above\n *       copyright notice, this list of conditions and the following\n *       disclaimer in the documentation and/or other materials provided\n *       with the distribution.\n *\n *     * Neither the name of the copyright holders nor the names of its\n *       contributors may be used to endorse or promote products derived\n *       from this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n ******************************************************************************)\n\nchapter {* Basic Monad Theory for Sequential Computations *}\n\ntheory Monads imports Main\nbegin\n\n\nsection{*General Framework for Monad-based Sequence-Test *}\ntext{* As such, Higher-order Logic as a purely functional specification\n       formalism has no built-in mechanism for state and state-transitions.\n       Forms of testing involving state require therefore explicit mechanisms\n       for their treatment inside the logic; a well-known technique to model\n       states inside purely functional languages are \\emph{monads} made popular\n       by Wadler and Moggi and extensively used in Haskell. \\HOL is powerful\n       enough to represent the most important standard monads;\n       however, it is not possible to represent monads as such due to well-known\n       limitations of the Hindley-Milner type-system. *}\n\ntext{* Here is a variant for state-exception monads, that models precisely\n       transition functions with preconditions. Next, we declare the\n       state-backtrack-monad. In all of them, our concept of i/o stepping\n       functions can be formulated; these are functions mapping input\n       to a given monad. Later on, we will build the usual concepts of:\n       \\begin{enumerate}\n       \\item deterministic i/o automata,\n       \\item non-deterministic i/o automata, and\n       \\item labelled transition systems (LTS)\n       \\end{enumerate}\n*}\n\nsubsection{* Standard State Exception Monads *}\ntype_synonym ('o, '\\<sigma>) MON\\<^sub>S\\<^sub>E = \"'\\<sigma> \\<rightharpoonup> ('o \\<times> '\\<sigma>)\" (* = '\\<sigma> \\<Rightarrow> ('o \\<times> '\\<sigma>)option *)\n\n\ndefinition bind_SE :: \"('o,'\\<sigma>)MON\\<^sub>S\\<^sub>E \\<Rightarrow> ('o \\<Rightarrow> ('o','\\<sigma>)MON\\<^sub>S\\<^sub>E) \\<Rightarrow> ('o','\\<sigma>)MON\\<^sub>S\\<^sub>E\"\nwhere     \"bind_SE f g = (\\<lambda>\\<sigma>. case f \\<sigma> of None \\<Rightarrow> None\n                                        | Some (out, \\<sigma>') \\<Rightarrow> g out \\<sigma>')\"\n\nnotation bind_SE (\"bind\\<^sub>S\\<^sub>E\")\n\nsyntax    (xsymbols)\n          \"_bind_SE\" :: \"[pttrn,('o,'\\<sigma>)MON\\<^sub>S\\<^sub>E,('o','\\<sigma>)MON\\<^sub>S\\<^sub>E] \\<Rightarrow> ('o','\\<sigma>)MON\\<^sub>S\\<^sub>E\"\n          (\"(2 _ \\<leftarrow> _; _)\" [5,8,8]8)\ntranslations\n          \"x \\<leftarrow> f; g\" == \"CONST bind_SE f (% x . g)\"\n\n\ndefinition unit_SE :: \"'o \\<Rightarrow> ('o, '\\<sigma>)MON\\<^sub>S\\<^sub>E\"   (\"(return _)\" 8)\nwhere     \"unit_SE e = (\\<lambda>\\<sigma>. Some(e,\\<sigma>))\"\nnotation   unit_SE (\"unit\\<^sub>S\\<^sub>E\")\n\ndefinition fail_SE :: \"('o, '\\<sigma>)MON\\<^sub>S\\<^sub>E\"\nwhere     \"fail_SE = (\\<lambda>\\<sigma>. None)\"\nnotation   fail_SE (\"fail\\<^sub>S\\<^sub>E\")\n\ndefinition assert_SE :: \"('\\<sigma> \\<Rightarrow> bool) \\<Rightarrow> (bool, '\\<sigma>)MON\\<^sub>S\\<^sub>E\"\nwhere     \"assert_SE P = (\\<lambda>\\<sigma>. if P \\<sigma> then Some(True,\\<sigma>) else None)\"\nnotation   assert_SE (\"assert\\<^sub>S\\<^sub>E\")\n\ndefinition assume_SE :: \"('\\<sigma> \\<Rightarrow> bool) \\<Rightarrow> (unit, '\\<sigma>)MON\\<^sub>S\\<^sub>E\"\nwhere     \"assume_SE P = (\\<lambda>\\<sigma>. if \\<exists>\\<sigma> . P \\<sigma> then Some((), SOME \\<sigma> . P \\<sigma>) else None)\"\nnotation   assume_SE (\"assume\\<^sub>S\\<^sub>E\")\n\ntext{* The standard monad theorems about unit and associativity: *}\n\nlemma bind_left_unit [simp]: \"(x \\<leftarrow> return c; P x) = P c\"\n  by (simp add: unit_SE_def bind_SE_def)\n\n\nlemma bind_left_fail_SE[simp] : \"(x \\<leftarrow> fail\\<^sub>S\\<^sub>E; P x) = fail\\<^sub>S\\<^sub>E\"\n  by (simp add: fail_SE_def bind_SE_def)\n\n\nlemma bind_right_unit[simp]: \"(x \\<leftarrow> m; return x) = m\"\n  apply (simp add:  unit_SE_def bind_SE_def)\n  apply (rule ext)\n  apply (case_tac \"m \\<sigma>\", simp_all)\n  done\n\nlemma bind_assoc[simp]: \"(y \\<leftarrow> (x \\<leftarrow> m; k x); h y) = (x \\<leftarrow> m; (y \\<leftarrow> k x; h y))\"\n  apply (simp add: unit_SE_def bind_SE_def, rule ext)\n  apply (case_tac \"m \\<sigma>\", simp_all)\n  apply (case_tac \"a\", simp_all)\n  done\n\n\ntext{* The bind-operator in the state-exception monad yields already\n       a semantics for the concept of an input sequence on the meta-level: *}\nlemma     syntax_test: \"(o1 \\<leftarrow> f1 ; o2 \\<leftarrow> f2; return (post o1 o2)) = X\"\noops\n\n\n\nsubsection {* \"Pipe-free\" - variant of the bind. *}\n\ndefinition seq_SE :: \"[('\\<alpha>, '\\<sigma>)MON\\<^sub>S\\<^sub>E, ('\\<beta>, '\\<sigma>)MON\\<^sub>S\\<^sub>E] \\<Rightarrow> ('\\<beta>, '\\<sigma>)MON\\<^sub>S\\<^sub>E\" (infixl \";-\" 65)\nwhere     \"f ;- g = (_ \\<leftarrow> f ; g)\"\n\n\n\nsubsection {* Monadic If *}\n\ndefinition if_SE :: \"['\\<sigma> \\<Rightarrow> bool, ('\\<alpha>, '\\<sigma>)MON\\<^sub>S\\<^sub>E, ('\\<alpha>, '\\<sigma>)MON\\<^sub>S\\<^sub>E] \\<Rightarrow> ('\\<alpha>, '\\<sigma>)MON\\<^sub>S\\<^sub>E\"\nwhere     \"if_SE c E F = (\\<lambda>\\<sigma>. if c \\<sigma> then E \\<sigma> else F \\<sigma>)\"\n\nsyntax    (xsymbols)\n          \"_if_SE\" :: \"['\\<sigma> \\<Rightarrow> bool,('o,'\\<sigma>)MON\\<^sub>S\\<^sub>E,('o','\\<sigma>)MON\\<^sub>S\\<^sub>E] \\<Rightarrow> ('o','\\<sigma>)MON\\<^sub>S\\<^sub>E\"\n          (\"(if\\<^sub>S\\<^sub>E _ then _ else _fi)\" [5,8,8]8)\ntranslations\n          \"(if\\<^sub>S\\<^sub>E cond then T1 else T2 fi)\" == \"CONST if_SE cond T1 T2\"\n\n\n\nsubsubsection{* Theory of a Monadic While *}\n\ntext{* First Step : Establishing an embedding between partial functions and relations *}\n(* plongement *)\ndefinition Mon2Rel :: \"(unit, '\\<sigma>)MON\\<^sub>S\\<^sub>E \\<Rightarrow> ('\\<sigma> \\<times> '\\<sigma>) set\"\nwhere \"Mon2Rel f = {(x, y). (f x = Some((), y))}\"\n(* ressortir *)\ndefinition Rel2Mon :: \" ('\\<sigma> \\<times> '\\<sigma>) set \\<Rightarrow> (unit, '\\<sigma>)MON\\<^sub>S\\<^sub>E \"\nwhere \"Rel2Mon S = (\\<lambda> \\<sigma>. if \\<exists>\\<sigma>'. (\\<sigma>, \\<sigma>') \\<in> S then Some((), SOME \\<sigma>'. (\\<sigma>, \\<sigma>') \\<in> S) else None)\"\n\nlemma Mon2Rel_Rel2Mon_id: assumes det:\"single_valued R\" shows \"(Mon2Rel \\<circ> Rel2Mon) R = R\"\napply (simp add: comp_def Mon2Rel_def Rel2Mon_def,auto)\napply (case_tac \"\\<exists>\\<sigma>'. (a, \\<sigma>') \\<in> R\", auto)\napply (subst some_eq_ex) back\napply (insert det[simplified single_valued_def])\napply (auto)\ndone\n\nlemma Rel2Mon_Id: \"(Rel2Mon \\<circ> Mon2Rel) x = x\"\napply (rule ext)\napply (auto simp: comp_def Mon2Rel_def Rel2Mon_def)\napply (erule contrapos_pp, drule HOL.not_sym, simp)\ndone\n\nlemma single_valued_Mon2Rel: \"single_valued (Mon2Rel B)\"\nby (auto simp: single_valued_def Mon2Rel_def)\n\ntext{* Second Step : Proving an induction principle allowing to establish that lfp remains\n       deterministic *}\n\n\n(* Due to Tobias Nipkow *)\ndefinition chain :: \"(nat => 'a set) => bool\"\nwhere     \"chain S = (\\<forall>i. S i \\<subseteq> S(Suc i))\"\n\nlemma chain_total: \"chain S ==> S i \\<le> S j \\<or> S j \\<le> S i\"\nby (metis chain_def le_cases lift_Suc_mono_le)\n\ndefinition cont :: \"('a set => 'b set) => bool\"\nwhere     \"cont f = (\\<forall>S. chain S \\<longrightarrow> f(UN n. S n) = (UN n. f(S n)))\"\n\nlemma mono_if_cont: fixes f :: \"'a set => 'b set\"\n  assumes \"cont f\" shows \"mono f\"\nproof\n  fix a b :: \"'a set\" assume \"a \\<subseteq> b\"\n  let ?S = \"\\<lambda>n::nat. if n=0 then a else b\"\n  have \"chain ?S\" using `a \\<subseteq> b` by(auto simp: chain_def)\n  hence \"f(UN n. ?S n) = (UN n. f(?S n))\"\n    using assms by(simp add: cont_def)\n  moreover have \"(UN n. ?S n) = b\" using `a \\<subseteq> b` by (auto split: if_splits)\n  moreover have \"(UN n. f(?S n)) = f a \\<union> f b\" by (auto split: if_splits)\n  ultimately show \"f a \\<subseteq> f b\" by (metis Un_upper1)\nqed\n\nlemma chain_iterates: fixes f :: \"'a set => 'a set\"\n  assumes \"mono f\" shows \"chain(\\<lambda>n. (f^^n) {})\"\nproof-\n  { fix n have \"(f ^^ n) {} \\<subseteq> (f ^^ Suc n) {}\" using assms\n    by(induction n) (auto simp: mono_def) }\n  thus ?thesis by(auto simp: chain_def)\nqed\n\ntheorem lfp_if_cont:\n  assumes \"cont f\" shows \"lfp f = (UN n. (f^^n) {})\" (is \"_ = ?U\")\nproof\n  show \"lfp f \\<subseteq> ?U\"\n  proof (rule lfp_lowerbound)\n    have \"f ?U = (UN n. (f^^Suc n){})\"\n      using chain_iterates[OF mono_if_cont[OF assms]] assms\n      by(simp add: cont_def)\n    also have \"\\<dots> = (f^^0){} \\<union> \\<dots>\" by simp\n    also have \"\\<dots> = ?U\"\n      by(auto simp del: funpow.simps) (metis empty_iff funpow_0 old.nat.exhaust)\n    finally show \"f ?U \\<subseteq> ?U\" by simp\n  qed\nnext\n  { fix n p assume \"f p \\<subseteq> p\"\n    have \"(f^^n){} \\<subseteq> p\"\n    proof(induction n)\n      case 0 show ?case by simp\n    next\n      case Suc\n      from monoD[OF mono_if_cont[OF assms] Suc] `f p \\<subseteq> p`\n      show ?case by simp\n    qed\n  }\n  thus \"?U \\<subseteq> lfp f\" by(auto simp: lfp_def)\nqed\n\n\nlemma single_valued_UN_chain:\n  assumes \"chain S\" \"(!!n. single_valued (S n))\"\n  shows \"single_valued(UN n. S n)\"\nproof(auto simp: single_valued_def)\n  fix m n x y z assume \"(x, y) \\<in> S m\" \"(x, z) \\<in> S n\"\n  with chain_total[OF assms(1), of m n] assms(2)\n  show \"y = z\" by (auto simp: single_valued_def)\nqed\n\nlemma single_valued_lfp:\nfixes f :: \"('a \\<times> 'a) set => ('a \\<times> 'a) set\"\nassumes \"cont f\" \"\\<And>r. single_valued r \\<Longrightarrow> single_valued (f r)\"\nshows \"single_valued(lfp f)\"\nunfolding lfp_if_cont[OF assms(1)]\nproof(rule single_valued_UN_chain[OF chain_iterates[OF mono_if_cont[OF assms(1)]]])\n  fix n show \"single_valued ((f ^^ n) {})\"\n  by(induction n)(auto simp: assms(2))\nqed\n\n\ntext{* Third Step: Definition of the Monadic While *}\ndefinition \\<Gamma> :: \"['\\<sigma> \\<Rightarrow> bool,('\\<sigma> \\<times> '\\<sigma>) set] \\<Rightarrow> (('\\<sigma> \\<times> '\\<sigma>) set \\<Rightarrow> ('\\<sigma> \\<times> '\\<sigma>) set)\"\nwhere     \"\\<Gamma> b cd = (\\<lambda>cw. {(s,t). if b s then (s, t) \\<in> cd O cw else s = t})\"\n\n\ndefinition while_SE :: \"['\\<sigma> \\<Rightarrow> bool, (unit, '\\<sigma>)MON\\<^sub>S\\<^sub>E] \\<Rightarrow> (unit, '\\<sigma>)MON\\<^sub>S\\<^sub>E\"\nwhere     \"while_SE c B \\<equiv> (Rel2Mon(lfp(\\<Gamma> c (Mon2Rel B))))\"\n\nsyntax    (xsymbols)\n          \"_while_SE\" :: \"['\\<sigma> \\<Rightarrow> bool, (unit, '\\<sigma>)MON\\<^sub>S\\<^sub>E] \\<Rightarrow> (unit, '\\<sigma>)MON\\<^sub>S\\<^sub>E\"\n          (\"(while\\<^sub>S\\<^sub>E _ do _ od)\" [8,8]8)\ntranslations\n          \"while\\<^sub>S\\<^sub>E c do b od\" == \"CONST while_SE c b\"\n\nlemma cont_\\<Gamma>: \"cont (\\<Gamma> c b)\"\nby (auto simp: cont_def \\<Gamma>_def)\n\ntext{* The fixpoint theory now allows us to establish that the lfp constructed over\n       @{term Mon2Rel} remains deterministic *}\n\ntheorem single_valued_lfp_Mon2Rel: \"single_valued (lfp(\\<Gamma> c (Mon2Rel B)))\"\napply(rule single_valued_lfp, simp_all add: cont_\\<Gamma>)\napply(auto simp: \\<Gamma>_def single_valued_def)\napply(metis single_valued_Mon2Rel[of \"B\"] single_valued_def)\ndone\n\n\nlemma Rel2Mon_if:\n  \"Rel2Mon {(s, t). if b s then (s, t) \\<in> Mon2Rel c O lfp (\\<Gamma> b (Mon2Rel c)) else s = t} \\<sigma> =\n  (if b \\<sigma> then Rel2Mon (Mon2Rel c O lfp (\\<Gamma> b (Mon2Rel c))) \\<sigma> else Some ((), \\<sigma>))\"\nby (simp add: Rel2Mon_def)\n\nlemma Rel2Mon_homomorphism:\n  assumes determ_X: \"single_valued X\" and determ_Y: \"single_valued Y\"\n  shows   \"Rel2Mon (X O Y) = (Rel2Mon X) ;- (Rel2Mon Y)\"\nproof -\n    have relational_partial_next_in_O: \"!!x E F. (\\<exists>y. (x, y) \\<in> (E O F)) \\<Longrightarrow> (\\<exists>y. (x, y) \\<in> E)\"\n                        by (auto)\n    have some_eq_intro: \"\\<And>X x y . single_valued X \\<Longrightarrow> (x, y) \\<in> X \\<Longrightarrow> (SOME y. (x, y) \\<in> X) = y\"\n                        by (auto simp: single_valued_def)\n\nshow ?thesis\napply (simp add: Rel2Mon_def seq_SE_def bind_SE_def)\napply (rule ext, rename_tac \"\\<sigma>\")\napply (case_tac \" \\<exists>\\<sigma>'. (\\<sigma>, \\<sigma>') \\<in> X O Y\")\napply (simp only: HOL.if_True)\napply (frule relational_partial_next_in_O)\napply (auto)\napply (insert determ_X determ_Y)\n\napply (subgoal_tac \"(SOME \\<sigma>'. (x, \\<sigma>') \\<in> X) = y\")\napply (simp)\n      apply (subgoal_tac \"(SOME \\<sigma>'. (y, \\<sigma>') \\<in> Y) = z\")\n      apply (simp)\n            apply (subgoal_tac \"(SOME \\<sigma>'. (x, \\<sigma>') \\<in> X O Y) = z\")\n            apply (simp)\n      apply (auto simp: single_valued_def)\napply (subgoal_tac \"(SOME \\<sigma>'. (x, \\<sigma>') \\<in> X) = ya\")\n      apply (simp_all)\napply (subgoal_tac \"(SOME \\<sigma>'. (ya, \\<sigma>') \\<in> Y) = \\<sigma>''\")\n      apply (simp_all)\napply (subgoal_tac \"(SOME \\<sigma>'. (x, \\<sigma>') \\<in> X O Y) = \\<sigma>''\")\n      apply (assumption)\napply (subgoal_tac \"single_valued (X O Y)\")\n      apply (fold single_valued_def)\n      apply (subgoal_tac \"(x, \\<sigma>'') \\<in> X O Y\")\n            apply (auto, rule some_eq_intro)\n            apply (auto, rule Relation.relcomp.relcompI Relation.single_valued_relcomp, auto)\n\napply (rule_tac x=z in exI)\napply (rule someI2)\napply (assumption)+\napply (simp add: single_valued_def)\napply (metis)\n\napply (erule contrapos_pp)\napply (simp)\napply (rule_tac x=\\<sigma>' in exI)\n    apply (subgoal_tac \"(SOME \\<sigma>'. (\\<sigma>, \\<sigma>') \\<in> X) = \\<sigma>''\")\n    apply (auto)\n  apply (auto simp: single_valued_def)\ndone\nqed\n\ntext{* Putting everything together, the theory of embedding and the invariance of\n       determinism of the while-body, gives us the usual unfold-theorem: *}\ntheorem \"(while\\<^sub>S\\<^sub>E b do c od) = (if\\<^sub>S\\<^sub>E b then (c ;- (while\\<^sub>S\\<^sub>E b do c od)) else return () fi)\"\napply (simp add: if_SE_def seq_SE_def while_SE_def unit_SE_def)\napply (subst lfp_unfold [OF mono_if_cont, OF cont_\\<Gamma>])\napply (rule ext)\napply (subst \\<Gamma>_def)\napply (auto simp: Rel2Mon_if Rel2Mon_homomorphism seq_SE_def Rel2Mon_Id [simplified comp_def]\n                  single_valued_Mon2Rel single_valued_lfp_Mon2Rel )\ndone\n\n\n\nsubsection{* Multi-binds *}\n\ntext{*  In order to express test-sequences also on the object-level and\nto make our theory amenable to formal reasoning over test-sequences,\nwe represent them as lists of input and generalize the bind-operator\nof the state-exception monad accordingly. The approach is straightforward,\nbut comes with a price: we have to encapsulate all input and output data\ninto one type. Assume that we have a typed interface to a module with\nthe operations $op_1$, $op_2$, \\ldots, $op_n$ with the inputs\n$\\iota_1$, $\\iota_2$, \\ldots, $\\iota_n$ (outputs are treated analogously).\nThen we can encode for this interface the general input - type:\n\\begin{displaymath}\n\\texttt{datatype}\\ \\texttt{in}\\ =\\ op_1\\ ::\\ \\iota_1\\ |\\ ...\\ |\\ \\iota_n\n\\end{displaymath}\nObviously, we loose some type-safety in this approach; we have to express\nthat in traces only \\emph{corresponding} input and output belonging to the\nsame operation will occur; this form of side-conditions have to be expressed\ninside \\HOL. From the user perspective, this will not make much difference,\nsince junk-data resulting from too weak typing can be ruled out by adopted\nfront-ends.\n*}\n\ntext{* Note that the subsequent notion of a test-sequence allows the io stepping\nfunction (and the special case of a program under test) to stop execution\n\\emph{within} the sequence; such premature terminations are characterized by an\noutput list which is shorter than the input list. *}\n\nfun    mbind :: \"'\\<iota> list  \\<Rightarrow>  ('\\<iota> \\<Rightarrow> ('o,'\\<sigma>) MON\\<^sub>S\\<^sub>E) \\<Rightarrow> ('o list,'\\<sigma>) MON\\<^sub>S\\<^sub>E\"\nwhere \"mbind [] iostep \\<sigma> = Some([], \\<sigma>)\" |\n      \"mbind (a#H) iostep \\<sigma> =\n                (case iostep a \\<sigma> of\n                     None   \\<Rightarrow> Some([], \\<sigma>)\n                  |  Some (out, \\<sigma>') \\<Rightarrow> (case mbind H iostep \\<sigma>' of\n                                          None    \\<Rightarrow> Some([out],\\<sigma>')\n                                        | Some(outs,\\<sigma>'') \\<Rightarrow> Some(out#outs,\\<sigma>'')))\"\n\nnotation mbind (\"mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>a\\<^sub>v\\<^sub>e\") (* future name: mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>a\\<^sub>v\\<^sub>e *)\n\ntext{* This definition is fail-safe; in case of an exception, the current state is maintained,\n       the computation as a whole is marked as success.\n       Compare to the fail-strict variant @{text \"mbind'\"}: *}\n\nlemma mbind_unit [simp]:\n     \"mbind [] f = (return [])\"\n      by(rule ext, simp add: unit_SE_def)\n\ntext{* The characteristic property of @{term mbind} --- which distinguishes it from\n       @{text mbind'} defined in the sequel --- is that it never fails; it ``swallows'' internal\n       errors occurring during the computation. *}\nlemma mbind_nofailure [simp]:\n     \"mbind S f \\<sigma> \\<noteq> None\"\n      apply(rule_tac x=\\<sigma> in spec)\n      apply(induct S, auto simp:unit_SE_def)\n      apply(case_tac \"f a x\", auto)\n      apply(erule_tac x=\"b\" in allE)\n      apply(erule exE, erule exE, simp)\n      done\n\n\nfun    mbind' :: \"'\\<iota> list  \\<Rightarrow>  ('\\<iota> \\<Rightarrow> ('o,'\\<sigma>) MON\\<^sub>S\\<^sub>E) \\<Rightarrow> ('o list,'\\<sigma>) MON\\<^sub>S\\<^sub>E\"\nwhere \"mbind' [] iostep \\<sigma> = Some([], \\<sigma>)\" |\n      \"mbind' (a#S) iostep \\<sigma> =\n                (case iostep a \\<sigma> of\n                     None   \\<Rightarrow> None\n                  |  Some (out, \\<sigma>') \\<Rightarrow> (case mbind' S iostep \\<sigma>' of\n                                          None    \\<Rightarrow> None   (*  fail-strict *)\n                                        | Some(outs,\\<sigma>'') \\<Rightarrow> Some(out#outs,\\<sigma>'')))\"\nnotation mbind' (\"mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>t\\<^sub>o\\<^sub>p\") (* future name: mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>t\\<^sub>o\\<^sub>p *)\n\n\n\nlemma mbind'_bind [simp]:\n     \"(x \\<leftarrow> mbind' (a#S) F; M x) = (a \\<leftarrow> (F a); (x \\<leftarrow> mbind' S F; M (a # x)))\"\n      by(rule ext, rename_tac \"z\",simp add: bind_SE_def split: option.split)\n\ndeclare mbind'.simps[simp del] (* use only more abstract definitions *)\n\n\nfun    mbind'' :: \"'\\<iota> list  \\<Rightarrow>  ('\\<iota> \\<Rightarrow> ('o,'\\<sigma>) MON\\<^sub>S\\<^sub>E) \\<Rightarrow> ('o list,'\\<sigma>) MON\\<^sub>S\\<^sub>E\"\nwhere \"mbind'' [] iostep \\<sigma> = Some([], \\<sigma>)\" |\n      \"mbind'' (a#S) iostep \\<sigma> =\n                (case iostep a \\<sigma> of\n                     None           \\<Rightarrow> mbind'' S iostep \\<sigma>\n                  |  Some (out, \\<sigma>') \\<Rightarrow> (case mbind'' S iostep \\<sigma>' of\n                                          None    \\<Rightarrow> None   (*  does not occur *)\n                                        | Some(outs,\\<sigma>'') \\<Rightarrow> Some(out#outs,\\<sigma>'')))\"\n\nnotation mbind'' (\"mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>P\\<^sub>u\\<^sub>r\\<^sub>g\\<^sub>e\") (* future name: mbind\\<^sub>P\\<^sub>u\\<^sub>r\\<^sub>g\\<^sub>e\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l *)\ndeclare  mbind''.simps[simp del] (* use only more abstract definitions *)\n\n\ntext{* mbind' as failure strict operator can be seen as a foldr on bind -\n       if the types would match \\ldots *}\n\ndefinition try_SE :: \"('o,'\\<sigma>) MON\\<^sub>S\\<^sub>E \\<Rightarrow> ('o option,'\\<sigma>) MON\\<^sub>S\\<^sub>E\" (\"try\\<^sub>S\\<^sub>E\")\nwhere     \"try\\<^sub>S\\<^sub>E ioprog = (\\<lambda>\\<sigma>. case ioprog \\<sigma> of\n                                      None \\<Rightarrow> Some(None, \\<sigma>)\n                                    | Some(outs, \\<sigma>') \\<Rightarrow> Some(Some outs, \\<sigma>'))\"\ntext{* In contrast, mbind as a failure safe operator can roughly be seen\n       as a foldr on bind - try:\n       m1 ; try m2 ; try m3; ... Note, that the rough equivalence only holds for\n       certain predicates in the sequence - length equivalence modulo None,\n       for example. However, if a conditional is added, the equivalence\n       can be made precise: *}\n\nlemma mbind_try:\n  \"(x \\<leftarrow> mbind (a#S) F; M x) =\n   (a' \\<leftarrow> try\\<^sub>S\\<^sub>E(F a);\n      if a' = None\n      then (M [])\n      else (x \\<leftarrow> mbind S F; M (the a' # x)))\"\napply(rule ext)\napply(simp add: bind_SE_def try_SE_def)\napply(case_tac \"F a x\", auto)\napply(simp add: bind_SE_def try_SE_def)\napply(case_tac \"mbind S F b\", auto)\ndone\n\ntext{* On this basis, a symbolic evaluation scheme can be established\n  that reduces mbind-code to try\\_SE\\_code and ite-cascades. *}\n\ndefinition alt_SE :: \"[('o, '\\<sigma>)MON\\<^sub>S\\<^sub>E, ('o, '\\<sigma>)MON\\<^sub>S\\<^sub>E] \\<Rightarrow> ('o, '\\<sigma>)MON\\<^sub>S\\<^sub>E\"   (infixl \"\\<sqinter>\\<^sub>S\\<^sub>E\" 10)\nwhere     \"(f \\<sqinter>\\<^sub>S\\<^sub>E g) = (\\<lambda> \\<sigma>. case f \\<sigma> of None \\<Rightarrow> g \\<sigma>\n                                      | Some H \\<Rightarrow> Some H)\"\n\ndefinition malt_SE :: \"('o, '\\<sigma>)MON\\<^sub>S\\<^sub>E list \\<Rightarrow> ('o, '\\<sigma>)MON\\<^sub>S\\<^sub>E\"\nwhere     \"malt_SE S = foldr alt_SE S fail\\<^sub>S\\<^sub>E\"\nnotation   malt_SE (\"\\<Sqinter>\\<^sub>S\\<^sub>E\")\n\nlemma malt_SE_mt [simp]: \"\\<Sqinter>\\<^sub>S\\<^sub>E [] = fail\\<^sub>S\\<^sub>E\"\nby(simp add: malt_SE_def)\n\nlemma malt_SE_cons [simp]: \"\\<Sqinter>\\<^sub>S\\<^sub>E (a # S) = (a \\<sqinter>\\<^sub>S\\<^sub>E (\\<Sqinter>\\<^sub>S\\<^sub>E S))\"\nby(simp add: malt_SE_def)\n\n\nsubsection{* State Backtrack Monads *}\ntext{*This subsection is still rudimentary and as such an interesting\nformal analogue to the previous monad definitions. It is doubtful that it is\ninteresting for testing and as a cmputational stucture at all.\nClearly more relevant is ``sequence'' instead of ``set,'' which would\nrephrase Isabelle's internal tactic concept. *}\n\ntype_synonym ('o, '\\<sigma>) MON\\<^sub>S\\<^sub>B = \"'\\<sigma> \\<Rightarrow> ('o \\<times> '\\<sigma>) set\"\n\ndefinition bind_SB :: \"('o, '\\<sigma>)MON\\<^sub>S\\<^sub>B \\<Rightarrow> ('o \\<Rightarrow>  ('o', '\\<sigma>)MON\\<^sub>S\\<^sub>B) \\<Rightarrow> ('o', '\\<sigma>)MON\\<^sub>S\\<^sub>B\"\nwhere     \"bind_SB f g \\<sigma> = \\<Union> ((\\<lambda>(out, \\<sigma>). (g out \\<sigma>)) ` (f \\<sigma>))\"\nnotation   bind_SB (\"bind\\<^sub>S\\<^sub>B\")\n\ndefinition unit_SB :: \"'o \\<Rightarrow> ('o, '\\<sigma>)MON\\<^sub>S\\<^sub>B\" (\"(returns _)\" 8)\nwhere     \"unit_SB e = (\\<lambda>\\<sigma>. {(e,\\<sigma>)})\"\nnotation   unit_SB (\"unit\\<^sub>S\\<^sub>B\")\n\nsyntax    (xsymbols)\n          \"_bind_SB\" :: \"[pttrn,('o,'\\<sigma>)MON\\<^sub>S\\<^sub>B,('o','\\<sigma>)MON\\<^sub>S\\<^sub>B] \\<Rightarrow> ('o','\\<sigma>)MON\\<^sub>S\\<^sub>B\"\n          (\"(2 _ := _; _)\" [5,8,8]8)\ntranslations\n          \"x := f; g\" == \"CONST bind_SB f (% x . g)\"\n\n\n\nlemma bind_left_unit_SB : \"(x := returns a; m x) = m a\"\n  by (rule ext,simp add: unit_SB_def bind_SB_def)\n\nlemma bind_right_unit_SB: \"(x := m; returns x) = m\"\n  by (rule ext, simp add: unit_SB_def bind_SB_def)\n\n\nlemma bind_assoc_SB: \"(y := (x := m; k x); h y) = (x := m; (y := k x; h y))\"\n  by (rule ext, simp add: unit_SB_def bind_SB_def split_def)\n\n\nsubsection{* State Backtrack Exception Monad (vulgo: Boogie-PL) *}\ntext{* The following combination of the previous two Monad-Constructions\nallows for the semantic foundation of a simple generic assertion language\nin the style of Schirmers Simpl-Language or Rustan Leino's Boogie-PL language.\nThe key is to use the exceptional element None for violations of\nthe assert-statement. *}\ntype_synonym  ('o, '\\<sigma>) MON\\<^sub>S\\<^sub>B\\<^sub>E = \"'\\<sigma> \\<Rightarrow> (('o \\<times> '\\<sigma>) set) option\"\n\n\ndefinition bind_SBE :: \"('o,'\\<sigma>)MON\\<^sub>S\\<^sub>B\\<^sub>E \\<Rightarrow> ('o \\<Rightarrow> ('o','\\<sigma>)MON\\<^sub>S\\<^sub>B\\<^sub>E) \\<Rightarrow> ('o','\\<sigma>)MON\\<^sub>S\\<^sub>B\\<^sub>E\"\nwhere     \"bind_SBE f g = (\\<lambda>\\<sigma>. case f \\<sigma> of None \\<Rightarrow> None\n                                         | Some S \\<Rightarrow> (let S' = (\\<lambda>(out, \\<sigma>'). g out \\<sigma>') ` S\n                                                      in  if None \\<in> S' then None\n                                                          else Some(\\<Union> (the ` S'))))\"\n\nsyntax    (xsymbols)\n          \"_bind_SBE\" :: \"[pttrn,('o,'\\<sigma>)MON\\<^sub>S\\<^sub>B\\<^sub>E,('o','\\<sigma>)MON\\<^sub>S\\<^sub>B\\<^sub>E] \\<Rightarrow> ('o','\\<sigma>)MON\\<^sub>S\\<^sub>B\\<^sub>E\"\n          (\"(2 _ :\\<equiv> _; _)\" [5,8,8]8)\ntranslations\n          \"x :\\<equiv> f; g\" == \"CONST bind_SBE f (% x . g)\"\n\ndefinition unit_SBE :: \"'o \\<Rightarrow> ('o, '\\<sigma>)MON\\<^sub>S\\<^sub>B\\<^sub>E\"   (\"(returning _)\" 8)\nwhere     \"unit_SBE e = (\\<lambda>\\<sigma>. Some({(e,\\<sigma>)}))\"\n\ndefinition assert_SBE :: \"('\\<sigma> \\<Rightarrow> bool) \\<Rightarrow> (unit, '\\<sigma>)MON\\<^sub>S\\<^sub>B\\<^sub>E\"\nwhere     \"assert_SBE e = (\\<lambda>\\<sigma>. if e \\<sigma> then Some({((),\\<sigma>)})\n                               else None)\"\nnotation   assert_SBE (\"assert\\<^sub>S\\<^sub>B\\<^sub>E\")\n\ndefinition assume_SBE :: \"('\\<sigma> \\<Rightarrow> bool) \\<Rightarrow> (unit, '\\<sigma>)MON\\<^sub>S\\<^sub>B\\<^sub>E\"\nwhere     \"assume_SBE e = (\\<lambda>\\<sigma>. if e \\<sigma> then Some({((),\\<sigma>)})\n                               else Some {})\"\nnotation   assume_SBE (\"assume\\<^sub>S\\<^sub>B\\<^sub>E\")\n\n\ndefinition havoc_SBE :: \" (unit, '\\<sigma>)MON\\<^sub>S\\<^sub>B\\<^sub>E\"\nwhere     \"havoc_SBE = (\\<lambda>\\<sigma>.  Some({x. True}))\"\nnotation   havoc_SBE (\"havoc\\<^sub>S\\<^sub>B\\<^sub>E\")\n\n\nlemma bind_left_unit_SBE : \"(x :\\<equiv> returning a; m x) = m a\"\nby (rule ext,simp add: unit_SBE_def bind_SBE_def)\n\nlemma bind_right_unit_SBE: \"(x :\\<equiv> m; returning x) = m\"\n  apply (rule ext, simp add: unit_SBE_def bind_SBE_def)\n  apply (case_tac \"m x\", simp_all add:Let_def)\n  apply (rule HOL.ccontr, simp add: Set.image_iff)\n  done\n\n\nlemmas aux = trans[OF HOL.neq_commute,OF Option.not_None_eq]\n\nlemma bind_assoc_SBE: \"(y :\\<equiv> (x :\\<equiv> m; k); h y) = (x :\\<equiv> m; (y :\\<equiv> k; h y))\"\nproof (rule ext, rename_tac z, simp add: unit_SBE_def bind_SBE_def,\n       case_tac \"m z\", simp_all add: Let_def Set.image_iff, safe)\n  case goal1 then show ?case\n       by(rule_tac x=\"(a, b)\" in bexI, simp_all)\nnext\n  case goal2 then show ?case\n       apply(rule_tac  x=\"(aa,b)\" in bexI, simp_all add:split_def)\n       apply(erule_tac x=\"(aa,b)\" in ballE)\n       apply(auto simp: aux image_def split_def intro!: rev_bexI)\n       done\nnext\n  case goal3 then show ?case\n       by(rule_tac x=\"(a, b)\" in bexI, simp_all)\nnext\n  case goal4 then show ?case\n       apply(erule_tac Q=\"None = (* FIXME to be shorten *) (case k b of None \\<Rightarrow> None | Some S \\<Rightarrow> let S' = (\\<lambda>(x, y). h x y) ` S in if None \\<in> S' then None else Some (\\<Union>(the ` S')))\" in contrapos_pp)\n       apply(erule_tac x=\"(aa,b)\" in ballE)\n       apply(auto simp: aux Option.not_None_eq image_def split_def intro!: rev_bexI)\n       done\nnext\n  case goal5 then show ?case\n       apply simp apply((erule_tac x=\"(ab,ba)\" in ballE)+)\n       apply(simp_all add: aux Option.not_None_eq, (erule exE)+, simp add:split_def)\n       apply(erule rev_bexI,case_tac \"None\\<in>(\\<lambda>p. h (fst p) (snd p))`y\",auto simp:split_def)\n       done\n\nnext\n  case goal6 then show ?case\n       apply simp apply((erule_tac x=\"(a,b)\" in ballE)+)\n       apply(simp_all add: aux Option.not_None_eq, (erule exE)+, simp add:split_def)\n       apply(erule rev_bexI, case_tac \"None\\<in>(\\<lambda>p. h(fst p)(snd p))`y\",auto simp:split_def)\n       done\nqed\n\n\n\n(* TODO: IF THEN ELSE and WHILE + Monadic Laws + Operational Rules. *)\n\n\n\nsection{* Valid Execution Sequences in the State Exception Monad *}\ntext{* This is still an unstructured merge of executable monad concepts\nand specification oriented high-level properties initiating test procedures. *}\n\ndefinition valid_SE :: \"'\\<sigma> \\<Rightarrow> (bool,'\\<sigma>) MON\\<^sub>S\\<^sub>E \\<Rightarrow> bool\" (infix \"\\<Turnstile>\" 15)\nwhere \"(\\<sigma> \\<Turnstile> m) = (m \\<sigma> \\<noteq> None \\<and> fst(the (m \\<sigma>)))\"\ntext{* This notation consideres failures as valid -- a definition\ninspired by I/O conformance. BUG: It is not possible to define\nthis concept once and for all in a Hindley-Milner type-system.\nFor the moment, we present it only for the state-exception\nmonad, although for the same definition, this notion is applicable\nto other monads as well.  *}\n\n\nlemma exec_unit_SE [simp]: \"(\\<sigma> \\<Turnstile> (return P)) = (P)\"\nby(auto simp: valid_SE_def unit_SE_def)\n\nlemma exec_unit_SE' [simp]: \"(\\<sigma>\\<^sub>0 \\<Turnstile> (\\<lambda>\\<sigma>. Some (f \\<sigma>, \\<sigma>))) = (f \\<sigma>\\<^sub>0)\"\nby(simp add: valid_SE_def )\n\nlemma exec_fail_SE [simp]: \"(\\<sigma> \\<Turnstile> fail\\<^sub>S\\<^sub>E) = False\"\nby(auto simp: valid_SE_def fail_SE_def)\n\n\nlemma exec_fail_SE'[simp]: \"\\<not>(\\<sigma>\\<^sub>0 \\<Turnstile> (\\<lambda>\\<sigma>. None))\"\nby(simp add: valid_SE_def )\n\nlemma  exec_bind_SE_failure:\n\"A \\<sigma> = None \\<Longrightarrow> \\<not>(\\<sigma> \\<Turnstile> ((s \\<leftarrow> A ; M s)))\"\nby(simp add: valid_SE_def unit_SE_def bind_SE_def)\n\nlemma exec_bind_SE_success:\n\"A \\<sigma> = Some(b,\\<sigma>') \\<Longrightarrow> (\\<sigma> \\<Turnstile> ((s \\<leftarrow> A ; M s))) = (\\<sigma>' \\<Turnstile> (M b))\"\nby(simp add: valid_SE_def unit_SE_def bind_SE_def )\n\nlemma exec_bind_SE_success': (* atomic boolean Monad \"Query Functions\" *)\n\"M \\<sigma> = Some(f \\<sigma>,\\<sigma>) \\<Longrightarrow>  (\\<sigma> \\<Turnstile> M) = f \\<sigma>\"\nby(simp add: valid_SE_def unit_SE_def bind_SE_def )\n\n\n\nlemma exec_bind_SE_success'':\n\"\\<sigma> \\<Turnstile> ((s \\<leftarrow> A ; M s)) \\<Longrightarrow>  \\<exists> v \\<sigma>'. the(A \\<sigma>) = (v,\\<sigma>') \\<and> \\<sigma>' \\<Turnstile> (M v)\"\napply(auto simp: valid_SE_def unit_SE_def bind_SE_def)\napply(cases \"A \\<sigma>\", simp_all)\napply(simp add: case_prod_unfold)\napply(drule_tac x=\"A \\<sigma>\" and f=the in arg_cong, simp)\napply(rule_tac x=\"fst aa\" in exI)\napply(rule_tac x=\"snd aa\" in exI, auto)\ndone\n\n\nlemma exec_bind_SE_success''':\n\"\\<sigma> \\<Turnstile> ((s \\<leftarrow> A ; M s)) \\<Longrightarrow>  \\<exists> a. (A \\<sigma>) = Some a \\<and> (snd a) \\<Turnstile> (M (fst a))\"\napply(auto simp: valid_SE_def unit_SE_def bind_SE_def)\napply(cases \"A \\<sigma>\", simp_all)\napply(simp_all add: case_prod_unfold\n           split: prod.splits)\napply(drule_tac x=\"A \\<sigma>\" and f=the in arg_cong, simp)\napply(rule_tac x=\"fst aa\" in exI)\napply(rule_tac x=\"snd aa\" in exI, auto)\ndone\n\n\nlemma  exec_bind_SE_success'''' :\n\"\\<sigma> \\<Turnstile> ((s \\<leftarrow> A ; M s)) \\<Longrightarrow>  \\<exists> v \\<sigma>'. A \\<sigma> = Some(v,\\<sigma>') \\<and> \\<sigma>' \\<Turnstile> (M v)\"\napply(auto simp: valid_SE_def unit_SE_def bind_SE_def)\napply(cases \"A \\<sigma>\", simp_all)\napply(simp add: case_prod_unfold)\napply(drule_tac x=\"A \\<sigma>\" and f=the in arg_cong, simp)\napply(rule_tac x=\"fst aa\" in exI)\napply(rule_tac x=\"snd aa\" in exI, auto)\ndone\n\n\ntext{* Recall \\verb+mbind_unit+ for the base case. *}\n\nlemma exec_mbindFSave_failure:\n\"ioprog a \\<sigma> = None \\<Longrightarrow>\n   (\\<sigma> \\<Turnstile> (s \\<leftarrow> mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>a\\<^sub>v\\<^sub>e (a#S) ioprog ; M s)) =  (\\<sigma> \\<Turnstile> (M []))\"\nby(simp add: valid_SE_def unit_SE_def bind_SE_def)\n\nlemma exec_mbindFStop_failure:\n\"ioprog a \\<sigma> = None \\<Longrightarrow>\n   (\\<sigma> \\<Turnstile> (s \\<leftarrow> mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>t\\<^sub>o\\<^sub>p (a#S) ioprog ; M s)) =  (False)\"\nby(simp add: exec_bind_SE_failure)\n\nlemma exec_mbindFPurge_failure:\n\"ioprog a \\<sigma> = None \\<Longrightarrow>\n   (\\<sigma> \\<Turnstile> (s \\<leftarrow> mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>P\\<^sub>u\\<^sub>r\\<^sub>g\\<^sub>e (a#S) ioprog ; M s)) = (\\<sigma> \\<Turnstile> (s \\<leftarrow> mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>P\\<^sub>u\\<^sub>r\\<^sub>g\\<^sub>e (S) ioprog ; M s))\"\nby(simp add: valid_SE_def unit_SE_def bind_SE_def mbind''.simps)\n\n\nlemma exec_mbindFSave_success :\n\"ioprog a \\<sigma> = Some(b,\\<sigma>') \\<Longrightarrow>\n   (\\<sigma>  \\<Turnstile> (s \\<leftarrow> mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>a\\<^sub>v\\<^sub>e (a#S) ioprog ; M s)) =\n   (\\<sigma>' \\<Turnstile> (s \\<leftarrow> mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>a\\<^sub>v\\<^sub>e S ioprog ; M (b#s)))\"\nunfolding valid_SE_def unit_SE_def bind_SE_def\nby(cases \"mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>a\\<^sub>v\\<^sub>e S ioprog \\<sigma>'\", auto)\n\nlemma exec_mbindFStop_success :\n\"ioprog a \\<sigma> = Some(b,\\<sigma>') \\<Longrightarrow>\n   (\\<sigma>  \\<Turnstile> (s \\<leftarrow> mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>t\\<^sub>o\\<^sub>p (a#S) ioprog ; M s)) =\n   (\\<sigma>' \\<Turnstile> (s \\<leftarrow> mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>t\\<^sub>o\\<^sub>p S ioprog ; M (b#s)))\"\nunfolding valid_SE_def unit_SE_def bind_SE_def\nby(cases \"mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>t\\<^sub>o\\<^sub>p S ioprog \\<sigma>'\", auto simp:  mbind'.simps)\n\nlemma exec_mbindFPurge_success :\n\"ioprog a \\<sigma> = Some(b,\\<sigma>') \\<Longrightarrow>\n   (\\<sigma>  \\<Turnstile> (s \\<leftarrow> mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>P\\<^sub>u\\<^sub>r\\<^sub>g\\<^sub>e (a#S) ioprog ; M s)) =\n   (\\<sigma>' \\<Turnstile> (s \\<leftarrow> mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>P\\<^sub>u\\<^sub>r\\<^sub>g\\<^sub>e S ioprog ; M (b#s)))\"\nunfolding valid_SE_def unit_SE_def bind_SE_def\nby(cases \"mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>P\\<^sub>u\\<^sub>r\\<^sub>g\\<^sub>e S ioprog \\<sigma>'\", auto simp:  mbind''.simps)\n\nlemma exec_mbindFSave:\n\"(\\<sigma> \\<Turnstile> (s \\<leftarrow> mbind (a#S) ioprog ; return (P s))) =\n    (case ioprog a \\<sigma> of\n       None \\<Rightarrow> (\\<sigma>  \\<Turnstile> (return (P [])))\n     | Some(b,\\<sigma>') \\<Rightarrow> (\\<sigma>'  \\<Turnstile> (s \\<leftarrow> mbind S ioprog ; return (P (b#s)))))\"\napply(case_tac \"ioprog a \\<sigma>\")\nby(auto simp: exec_mbindFSave_failure  exec_mbindFSave_success split: prod.splits)\n\n\ntext{* Universal splitting and symbolic execution rule *}\nlemma exec_mbindFSave_E:\nassumes seq : \"(\\<sigma> \\<Turnstile> (s \\<leftarrow> mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>a\\<^sub>v\\<^sub>e (a#S) ioprog ;  (P s)))\"\n  and   none: \"ioprog a \\<sigma> = None \\<Longrightarrow> (\\<sigma> \\<Turnstile> (P [])) \\<Longrightarrow> Q\"\n  and   some: \"\\<And> b \\<sigma>'. ioprog a \\<sigma> = Some(b,\\<sigma>') \\<Longrightarrow> (\\<sigma>' \\<Turnstile> (s \\<leftarrow> mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>a\\<^sub>v\\<^sub>e S ioprog;(P (b#s)))) \\<Longrightarrow> Q \"\nshows   \"Q\"\nusing seq\nproof(cases \"ioprog a \\<sigma>\")\n   case None  assume ass:\"ioprog a \\<sigma> = None\" show \"Q\"\n        apply(rule none[OF ass])\n        apply(insert ass, erule_tac ioprog1=ioprog in exec_mbindFSave_failure[THEN iffD1],rule seq)\n        done\nnext\n   case (Some aa) assume ass:\"ioprog a \\<sigma> = Some aa\" show \"Q\"\n        apply(insert ass,cases \"aa\",simp, rename_tac \"out\" \"\\<sigma>'\")\n        apply(erule some)\n        apply(insert ass,simp)\n        apply(erule_tac ioprog1=ioprog in exec_mbindFSave_success[THEN iffD1],rule seq)\n        done\nqed\n\ntext{* The next rule reveals the particular interest in deduction;\n       as an elimination rule, it allows for a linear conversion of a validity judgement\n       @{term \"mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>t\\<^sub>o\\<^sub>p\"} over an input list @{term \"S\"} into a constraint system; without any\n       branching ... Symbolic execution can even be stopped tactically whenever\n       @{term \"ioprog a \\<sigma> = Some(b,\\<sigma>')\"} comes to a contradiction. *}\nlemma exec_mbindFStop_E:\nassumes seq : \"(\\<sigma> \\<Turnstile> (s \\<leftarrow> mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>t\\<^sub>o\\<^sub>p (a#S) ioprog ; (P s)))\"\n  and   some: \"\\<And>b \\<sigma>'. ioprog a \\<sigma> = Some(b,\\<sigma>') \\<Longrightarrow> (\\<sigma>'\\<Turnstile> (s \\<leftarrow> mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>t\\<^sub>o\\<^sub>p S ioprog;(P(b#s)))) \\<Longrightarrow> Q\"\nshows   \"Q\"\nusing seq\nproof(cases \"ioprog a \\<sigma>\")\n   case None  assume ass:\"ioprog a \\<sigma> = None\" show \"Q\"\n        apply(insert ass seq)\n        apply(drule_tac \\<sigma>=\\<sigma> and S=S and M=P in exec_mbindFStop_failure, simp)\n        done\nnext\n   case (Some aa) assume ass:\"ioprog a \\<sigma> = Some aa\" show \"Q\"\n        apply(insert ass,cases \"aa\",simp, rename_tac \"out\" \"\\<sigma>'\")\n        apply(erule some)\n        apply(insert ass,simp)\n        apply(erule_tac ioprog1=ioprog in exec_mbindFStop_success[THEN iffD1],rule seq)\n        done\nqed\n\n\nlemma exec_mbindFPurge_E:\nassumes seq : \"(\\<sigma> \\<Turnstile> (s \\<leftarrow> mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>P\\<^sub>u\\<^sub>r\\<^sub>g\\<^sub>e (a#S) ioprog ;  (P s)))\"\n  and   none: \"ioprog a \\<sigma> = None \\<Longrightarrow> (\\<sigma> \\<Turnstile> (s \\<leftarrow> mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>P\\<^sub>u\\<^sub>r\\<^sub>g\\<^sub>e S ioprog;(P (s)))) \\<Longrightarrow> Q\"\n  and   some: \"\\<And> b \\<sigma>'. ioprog a \\<sigma> = Some(b,\\<sigma>') \\<Longrightarrow> (\\<sigma>' \\<Turnstile> (s \\<leftarrow> mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>P\\<^sub>u\\<^sub>r\\<^sub>g\\<^sub>e S ioprog;(P (b#s)))) \\<Longrightarrow> Q \"\nshows   \"Q\"\nusing seq\nproof(cases \"ioprog a \\<sigma>\")\n   case None  assume ass:\"ioprog a \\<sigma> = None\" show \"Q\"\n        apply(rule none[OF ass])\n        apply(insert ass, erule_tac ioprog1=ioprog in exec_mbindFPurge_failure[THEN iffD1],rule seq)\n        done\nnext\n   case (Some aa) assume ass:\"ioprog a \\<sigma> = Some aa\" show \"Q\"\n        apply(insert ass,cases \"aa\",simp, rename_tac \"out\" \"\\<sigma>'\")\n        apply(erule some)\n        apply(insert ass,simp)\n        apply(erule_tac ioprog1=ioprog in exec_mbindFPurge_success[THEN iffD1],rule seq)\n        done\nqed\n\n\nlemma assert_disch1 :\" P \\<sigma> \\<Longrightarrow> (\\<sigma> \\<Turnstile> (x \\<leftarrow> assert\\<^sub>S\\<^sub>E P; M x)) = (\\<sigma> \\<Turnstile> (M True))\"\nby(auto simp: bind_SE_def assert_SE_def valid_SE_def)\n\nlemma assert_disch2 :\" \\<not> P \\<sigma> \\<Longrightarrow> \\<not> (\\<sigma> \\<Turnstile> (x \\<leftarrow> assert\\<^sub>S\\<^sub>E P ; M s))\"\nby(auto simp: bind_SE_def assert_SE_def valid_SE_def)\n\nlemma assert_disch3 :\" \\<not> P \\<sigma> \\<Longrightarrow> \\<not> (\\<sigma> \\<Turnstile> (assert\\<^sub>S\\<^sub>E P))\"\nby(auto simp: bind_SE_def assert_SE_def valid_SE_def)\n\nlemma assert_D : \"(\\<sigma> \\<Turnstile> (x \\<leftarrow> assert\\<^sub>S\\<^sub>E P; M x)) \\<Longrightarrow> P \\<sigma> \\<and> (\\<sigma> \\<Turnstile> (M True))\"\nby(auto simp: bind_SE_def assert_SE_def valid_SE_def split: HOL.if_split_asm)\n\nlemma assume_D : \"(\\<sigma> \\<Turnstile> (x \\<leftarrow> assume\\<^sub>S\\<^sub>E P; M x)) \\<Longrightarrow> \\<exists> \\<sigma>. (P \\<sigma> \\<and>  \\<sigma> \\<Turnstile> (M ()))\"\napply(auto simp: bind_SE_def assume_SE_def valid_SE_def split: HOL.if_split_asm)\napply(rule_tac x=\"Eps P\" in exI, auto)\napply(rule_tac x=\"True\" in exI, rule_tac x=\"b\" in exI)\napply(subst Hilbert_Choice.someI,assumption,simp)\napply(subst Hilbert_Choice.someI,assumption,simp)\ndone\ntext{* These two rule prove that the SE Monad in connection with the notion of valid sequence\nis actually sufficient for a representation of a Boogie-like language. The SBE monad with explicit\nsets of states --- to be shown below --- is strictly speaking not necessary (and will therefore\nbe discontinued in the development). *}\n\nterm \"if\\<^sub>S\\<^sub>E P then B\\<^sub>1 else B\\<^sub>2 fi\"\n\nlemma if_SE_D1 : \"P \\<sigma> \\<Longrightarrow> (\\<sigma> \\<Turnstile> (if\\<^sub>S\\<^sub>E P then B\\<^sub>1 else B\\<^sub>2 fi)) = (\\<sigma> \\<Turnstile> B\\<^sub>1)\"\nby(auto simp: if_SE_def valid_SE_def)\n\nlemma if_SE_D2 : \"\\<not> P \\<sigma> \\<Longrightarrow> (\\<sigma> \\<Turnstile> (if\\<^sub>S\\<^sub>E P then B\\<^sub>1 else B\\<^sub>2 fi)) = (\\<sigma> \\<Turnstile> B\\<^sub>2)\"\nby(auto simp: if_SE_def valid_SE_def)\n\nlemma if_SE_split_asm : \" (\\<sigma> \\<Turnstile> (if\\<^sub>S\\<^sub>E P then B\\<^sub>1 else B\\<^sub>2 fi)) = ((P \\<sigma> \\<and> (\\<sigma> \\<Turnstile> B\\<^sub>1)) \\<or> (\\<not> P \\<sigma> \\<and> (\\<sigma> \\<Turnstile> B\\<^sub>2)))\"\nby(cases \"P \\<sigma>\",auto simp: if_SE_D1 if_SE_D2)\n\nlemma if_SE_split : \" (\\<sigma> \\<Turnstile> (if\\<^sub>S\\<^sub>E P then B\\<^sub>1 else B\\<^sub>2 fi)) = ((P \\<sigma> \\<longrightarrow> (\\<sigma> \\<Turnstile> B\\<^sub>1)) \\<and> (\\<not> P \\<sigma> \\<longrightarrow> (\\<sigma> \\<Turnstile> B\\<^sub>2)))\"\nby(cases \"P \\<sigma>\", auto simp: if_SE_D1 if_SE_D2)\n\n\nlemma if_SE_execE:\n  assumes A: \"\\<sigma> \\<Turnstile> (if\\<^sub>S\\<^sub>E P then B\\<^sub>1 else B\\<^sub>2 fi)\"\n   and   B: \"P \\<sigma> \\<Longrightarrow> \\<sigma> \\<Turnstile> B\\<^sub>1 \\<Longrightarrow> Q\"\n   and   C: \"\\<not> P \\<sigma>\\<Longrightarrow> \\<sigma> \\<Turnstile> B\\<^sub>2 \\<Longrightarrow> Q\"\n  shows  \"Q\"\nby(insert A [simplified if_SE_split],cases  \"P \\<sigma>\", simp_all, auto elim: B C)\n\n\n\n\n\ntext{* Test-Refinements will be stated in terms of the failsave @{term mbind}, opting\n       more generality. The following lemma allows for an  optimization both in\n       test execution as well as in symbolic execution for an important special case of\n       the post-codition: Whenever the latter has the constraint that the length of input and\n       output sequence equal each other (that is to say: no failure occured), failsave mbind\n       can be reduced to failstop mbind ... *}\nlemma mbindFSave_vs_mbindFStop :\n  \"(\\<sigma> \\<Turnstile> (os \\<leftarrow> (mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>a\\<^sub>v\\<^sub>e \\<iota>s ioprog); return(length \\<iota>s = length os \\<and> P \\<iota>s os))) =\n   (\\<sigma> \\<Turnstile> (os \\<leftarrow> (mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>t\\<^sub>o\\<^sub>p \\<iota>s ioprog); return(P \\<iota>s os)))\"\n  apply(rule_tac x=P in spec)\n  apply(rule_tac x=\\<sigma> in spec)\n  proof(induct \"\\<iota>s\")\n     case Nil show ?case by(simp_all add: mbind_try try_SE_def del: Monads.mbind.simps)\n     case (Cons a \\<iota>s) show ?case\n          apply(rule allI, rename_tac \"\\<sigma>\",rule allI, rename_tac \"P\")\n          apply(insert Cons.hyps)\n          apply(case_tac \"ioprog a \\<sigma>\")\n          apply(simp only: exec_mbindFSave_failure exec_mbindFStop_failure, simp)\n          apply(simp add:  split_paired_all del: Monads.mbind.simps )\n          apply(rename_tac \"\\<sigma>'\")\n          apply(subst exec_mbindFSave_success, assumption)\n          apply(subst (2) exec_bind_SE_success, assumption)\n          apply(erule_tac x=\"\\<sigma>'\" in allE)\n          apply(erule_tac x=\"\\<lambda>\\<iota>s s. P (a # \\<iota>s) (aa # s)\" in allE) (* heureka ! *)\n          apply(simp)\n      done\n  qed\n\n\nlemma mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>a\\<^sub>v\\<^sub>e_vs_mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>t\\<^sub>o\\<^sub>p:\nassumes A: \"\\<forall> \\<iota> \\<sigma>. ioprog \\<iota> \\<sigma> \\<noteq> None\"\nshows      \"(\\<sigma> \\<Turnstile> (os \\<leftarrow> (mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>a\\<^sub>v\\<^sub>e \\<iota>s ioprog); P os)) =\n            (\\<sigma> \\<Turnstile> (os \\<leftarrow> (mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>t\\<^sub>o\\<^sub>p \\<iota>s ioprog); P os))\"\nproof(induct \"\\<iota>s\") print_cases\n  case Nil show ?case by simp\nnext\n  case (Cons a \\<iota>s)\n       from Cons.hyps\n       have B:\"\\<forall> S f \\<sigma>. mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>a\\<^sub>v\\<^sub>e S f \\<sigma> \\<noteq> None \" by simp\n       have C:\"\\<forall>\\<sigma>. mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>t\\<^sub>o\\<^sub>p \\<iota>s ioprog \\<sigma> = mbind\\<^sub>F\\<^sub>a\\<^sub>i\\<^sub>l\\<^sub>S\\<^sub>a\\<^sub>v\\<^sub>e \\<iota>s ioprog \\<sigma>\"\n               apply(induct \\<iota>s, simp)\n               apply(rule allI,rename_tac \"\\<sigma>\")\n               apply(simp add: Monads.mbind'.simps(2))\n               apply(insert A, erule_tac x=\"a\" in allE)\n               apply(erule_tac x=\"\\<sigma>\" and P=\"\\<lambda>\\<sigma> . ioprog a \\<sigma> \\<noteq> None\" in allE)\n               apply(auto split:option.split)\n               done\n       show ?case\n       apply(insert A,erule_tac x=\"a\" in allE,erule_tac x=\"\\<sigma>\" in allE)\n       apply(simp, elim exE)\n       apply(rename_tac  \"out\" \"\\<sigma>'\")\n       apply(insert B, erule_tac x=\\<iota>s in allE, erule_tac x=ioprog in allE, erule_tac x=\\<sigma>' in allE)\n       apply(subst(asm) not_None_eq, elim exE)\n       apply(subst  Monads.exec_bind_SE_success)\n       apply(simp   split: option.split, auto)\n       apply(rule_tac s=\"(\\<lambda> a b c. a # (fst c)) out \\<sigma>' (aa, b)\" in trans, simp,rule refl)\n       apply(rule_tac s=\"(\\<lambda> a b c. (snd c)) out \\<sigma>' (aa, b)\" in trans, simp,rule refl)\n       apply(simp_all)\n       apply(subst  Monads.exec_bind_SE_success, assumption)\n       apply(subst  Monads.exec_bind_SE_success)\n       apply(rule_tac s=\"Some (aa, b)\" in  trans,simp_all add:C)\n       apply(subst(asm)  Monads.exec_bind_SE_success, assumption)\n       apply(subst(asm)  Monads.exec_bind_SE_success)\n       apply(rule_tac s=\"Some (aa, b)\" in  trans,simp_all add:C)\n    done\nqed\n\n\nsection{* Valid Test Sequences in the State Exception Backtrack Monad *}\ntext{* This is still an unstructured merge of executable monad concepts\nand specification oriented high-level properties initiating test procedures. *}\n\ndefinition valid_SBE :: \"'\\<sigma> \\<Rightarrow> ('a,'\\<sigma>) MON\\<^sub>S\\<^sub>B\\<^sub>E \\<Rightarrow> bool\" (infix \"\\<Turnstile>\\<^sub>S\\<^sub>B\\<^sub>E\" 15)\nwhere \"\\<sigma> \\<Turnstile>\\<^sub>S\\<^sub>B\\<^sub>E m \\<equiv> (m \\<sigma> \\<noteq> None)\"\ntext{* This notation consideres all non-failures as valid. *}\n\n\nlemma assume_assert: \"(\\<sigma> \\<Turnstile>\\<^sub>S\\<^sub>B\\<^sub>E ( _ :\\<equiv> assume\\<^sub>S\\<^sub>B\\<^sub>E P ; assert\\<^sub>S\\<^sub>B\\<^sub>E Q)) = (P \\<sigma> \\<longrightarrow> Q \\<sigma>)\"\n  by(simp add: valid_SBE_def assume_SBE_def assert_SBE_def bind_SBE_def)\n\n\n\nlemma assume_dest:\n  \"\\<lbrakk> \\<sigma> \\<Turnstile>\\<^sub>S\\<^sub>B\\<^sub>E (x :\\<equiv> assume\\<^sub>S\\<^sub>B\\<^sub>E Q; M x); Q \\<sigma>' \\<rbrakk> \\<Longrightarrow> \\<sigma> \\<Turnstile>\\<^sub>S\\<^sub>B\\<^sub>E M ()\"\n  apply(auto simp: valid_SBE_def assume_SBE_def assert_SBE_def bind_SBE_def)\n  apply(cases \"Q \\<sigma>\",simp_all)\n  oops\n\ntext{* This still needs work. What would be needed is a kind\n       of wp - calculus that comes out of that. So far: nope. *}\n\nsubsection{* Legacy Bindings *}\n\n\nlemma valid_true[simp]: (* legacy: special case *)\n  \"(\\<sigma> \\<Turnstile> (s \\<leftarrow> return x ; return (P s))) = P x\" by simp\n\n\n(*\nlemmas valid_both = exec_mbindFSave (* legacy *)\nlemmas valid_success = exec_mbindFSave_success (* legacy *)\nlemmas valid_success'' = exec_mbindFSave_success(* legacy *)\nlemmas valid_success' = exec_bind_SE_success (* legacy *)\nlemmas valid_failure = exec_mbindFSave_failure (* legacy : *)\nlemmas valid_failure' = exec_bind_SE_failure (* legacy *)\nlemmas valid_failure''=valid_failure (* legacy : *)\nlemmas valid_failure''' = exec_mbindFStop_failure (* legacy : *)\nlemmas valid_propagate_fail = exec_fail_SE (* legacy *)\nlemmas valid_propagate_fail' = exec_fail_SE' (* legacy *)\nlemmas valid_propoagate_3' = valid_propagate_fail' (* legacy *)\nlemmas valid_propagate_2 = exec_bind_SE_success''(* legacy *)\nlemmas valid_propagate_1 = exec_unit_SE (* legacy *)\nlemmas valid_successElem = exec_bind_SE_success' (* legacy *)\nlemmas valid_propagate_2' = exec_bind_SE_success'''(* legacy *)\nlemmas valid_propagate_2'' = exec_bind_SE_success'''' (* legacy *)\nlemmas valid_propoagate_3 = exec_unit_SE' (* legacy *)\n  *)\n(* legacy ?:\nlemma valid_success'':\n\"ioprog a \\<sigma> = Some(b,\\<sigma>') \\<Longrightarrow>\n   (\\<sigma>  \\<Turnstile> (s \\<leftarrow> mbind (a#S) ioprog ; return (P s))) =\n   (\\<sigma>' \\<Turnstile> (s \\<leftarrow> mbind S ioprog ; return (P (b#s))))\"\nunfolding valid_SE_def unit_SE_def bind_SE_def\nby(cases \"mbind S ioprog \\<sigma>'\", auto)\n*)\n\nend\n", "meta": {"author": "object-logics", "repo": "citadelle-devel", "sha": "fd4d57977d1a8a7330ae7d8651d003789980c802", "save_path": "github-repos/isabelle/object-logics-citadelle-devel", "path": "github-repos/isabelle/object-logics-citadelle-devel/citadelle-devel-fd4d57977d1a8a7330ae7d8651d003789980c802/examples/archive/Monads.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6150878696277513, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.2811792492820484}}
{"text": "(*******************************************************************************\n\n  Project: Development of Security Protocols by Refinement\n\n  Module:  Key_establish/m3_ds_par.thy (Isabelle/HOL 2016-1)\n  ID:      $Id: m3_ds_par.thy 132890 2016-12-24 10:25:57Z csprenge $\n  Authors: Christoph Sprenger, ETH Zurich <sprenger@inf.ethz.ch>\n           Ivano Somaini, ETH Zurich <somainii@student.ethz.ch>\n\n  Key distribution protocols\n  Level 3: parallel version of Denning-Sacco protocol\n\n  Copyright (c) 2009-2016 Christoph Sprenger, Ivano Somaini\n  Licence: LGPL\n\n*******************************************************************************)\n\nsection \\<open>Denning-Sacco, direct variant (L3)\\<close>\n\ntheory m3_ds_par imports m2_ds \"../Refinement/Message\"\nbegin\n\ntext \\<open>\nWe model a direct implementation of the channel-based Denning-Sacco protocol\nat Level 2. In this version, there is no ticket forwarding.\n\\[\n\\begin{array}{lll}\n  \\mathrm{M1.} & A \\rightarrow S: & A, B \\\\ \n  \\mathrm{M2a.} & S \\rightarrow A: & \\{Kab, B, Ts\\}_{Kas} \\\\\n  \\mathrm{M2b.} & S \\rightarrow B: & \\{Kab, A, Ts\\}_{Kbs}\n\\end{array}\n\\]\n\\<close>\n\ntext \\<open>Proof tool configuration. Avoid annoying automatic unfolding of\n\\<open>dom\\<close>.\\<close>\n\ndeclare domIff [simp, iff del]\n\n\n(******************************************************************************)\nsubsection \\<open>Setup\\<close>\n(******************************************************************************)\n\ntext \\<open>Now we can define the initial key knowledge.\\<close>\n\noverloading ltkeySetup' \\<equiv> ltkeySetup begin\ndefinition ltkeySetup_def: \"ltkeySetup' \\<equiv> {(sharK C, A) | C A. A = C \\<or> A = Sv}\"\nend\n\nlemma corrKey_shrK_bad [simp]: \"corrKey = shrK`bad\"\nby (auto simp add: keySetup_def ltkeySetup_def corrKey_def)\n\n\n(******************************************************************************)\nsubsection \\<open>State\\<close>\n(******************************************************************************)\n\ntext \\<open>The secure channels are star-shaped to/from the server.  Therefore,\nwe have only one agent in the relation.\\<close>\n\nrecord m3_state = \"m1_state\" +\n  IK :: \"msg set\"                                \\<comment> \\<open>intruder knowledge\\<close>\n\n\ntext \\<open>Observable state:\n@{term \"runs\"}, @{term \"leak\"}, @{term \"clk\"}, and @{term \"cache\"}.\\<close>\n\ntype_synonym\n  m3_obs = \"m2_obs\"\n\ndefinition\n  m3_obs :: \"m3_state \\<Rightarrow> m3_obs\" where\n  \"m3_obs s \\<equiv> \\<lparr> runs = runs s, leak = leak s, clk = clk s \\<rparr>\"\n\ntype_synonym\n  m3_pred = \"m3_state set\"\n\ntype_synonym\n  m3_trans = \"(m3_state \\<times> m3_state) set\"\n\n\n(******************************************************************************)\nsubsection \\<open>Events\\<close>\n(******************************************************************************)\n\ntext \\<open>Protocol events.\\<close>\n\ndefinition     \\<comment> \\<open>by @{term \"A\"}, refines @{term \"m2_step1\"}\\<close>\n  m3_step1 :: \"[rid_t, agent, agent] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step1 Ra A B \\<equiv> {(s, s1).\n    \\<comment> \\<open>guards:\\<close>\n    Ra \\<notin> dom (runs s) \\<and>                                \\<comment> \\<open>\\<open>Ra\\<close> is fresh\\<close>\n\n    \\<comment> \\<open>actions:\\<close>\n    s1 = s\\<lparr>\n      runs := (runs s)(Ra \\<mapsto> (Init, [A, B], [])),\n      IK := insert \\<lbrace>Agent A, Agent B\\<rbrace> (IK s)        \\<comment> \\<open>send \\<open>M1\\<close>\\<close>\n    \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by @{term \"B\"}, refines @{term \"m2_step2\"}\\<close>\n  m3_step2 :: \"[rid_t, agent, agent] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step2 \\<equiv> m1_step2\"\n\ndefinition     \\<comment> \\<open>by @{text \"Server\"}, refines @{term m2_step3}\\<close>\n  m3_step3 :: \"[rid_t, agent, agent, key, time] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step3 Rs A B Kab Ts \\<equiv> {(s, s1).\n    \\<comment> \\<open>guards:\\<close>\n    Rs \\<notin> dom (runs s) \\<and>                           \\<comment> \\<open>fresh server run\\<close>\n    Kab = sesK (Rs$sk) \\<and>                          \\<comment> \\<open>fresh session key\\<close>\n\n     \\<lbrace>Agent A, Agent B\\<rbrace> \\<in> IK s \\<and>                   \\<comment> \\<open>recv \\<open>M1\\<close>\\<close>\n     Ts = clk s \\<and>                                   \\<comment> \\<open>fresh timestamp\\<close>\n\n     \\<comment> \\<open>actions:\\<close>\n     \\<comment> \\<open>record session key and send \\<open>M2\\<close>\\<close>\n     s1 = s\\<lparr>\n       runs := (runs s)(Rs \\<mapsto> (Serv, [A, B], [aNum Ts])),   \\<comment> \\<open>send \\<open>M2a\\<close>, \\<open>M2b\\<close>\\<close>\n       IK := insert (Crypt (shrK A) \\<lbrace>Agent B, Key Kab, Number Ts\\<rbrace>)\n             (insert (Crypt (shrK B) \\<lbrace>Key Kab, Agent A, Number Ts\\<rbrace>) (IK s))\n     \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by @{term \"A\"}, refines @{term m2_step4}\\<close>\n  m3_step4 :: \"[rid_t, agent, agent, key, time] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step4 Ra A B Kab Ts \\<equiv> {(s, s1).\n\n     \\<comment> \\<open>guards:\\<close>\n     runs s Ra = Some (Init, [A, B], []) \\<and>           \\<comment> \\<open>key not yet recv'd\\<close>\n\n     Crypt (shrK A)                                  \\<comment> \\<open>recv \\<open>M2\\<close>\\<close>\n       \\<lbrace>Agent B, Key Kab, Number Ts\\<rbrace> \\<in> IK s \\<and>\n\n     \\<comment> \\<open>check freshness of session key\\<close>\n     clk s < Ts + Ls \\<and>\n\n     \\<comment> \\<open>actions:\\<close>\n     \\<comment> \\<open>record session key\\<close>\n     s1 = s\\<lparr>\n       runs := (runs s)(Ra \\<mapsto> (Init, [A, B], [aKey Kab, aNum Ts]))\n     \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by @{term \"B\"}, refines @{term m2_step5}\\<close>\n  m3_step5 :: \"[rid_t, agent, agent, key, time] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step5 Rb A B Kab Ts \\<equiv> {(s, s1).\n     \\<comment> \\<open>guards:\\<close>\n     runs s Rb = Some (Resp, [A, B], []) \\<and>             \\<comment> \\<open>key not yet recv'd\\<close>\n\n     Crypt (shrK B) \\<lbrace>Key Kab, Agent A, Number Ts\\<rbrace> \\<in> IK s \\<and>    \\<comment> \\<open>recv \\<open>M3\\<close>\\<close>\n\n     \\<comment> \\<open>ensure freshness of session key; replays with fresh authenticator ok!\\<close>\n     clk s < Ts + Ls \\<and>\n\n     \\<comment> \\<open>actions:\\<close>\n     \\<comment> \\<open>record session key\\<close>\n     s1 = s\\<lparr>\n       runs := (runs s)(Rb \\<mapsto> (Resp, [A, B], [aKey Kab, aNum Ts]))\n     \\<rparr>\n  }\"\n\n\ntext \\<open>Clock tick event\\<close>\n\ndefinition   \\<comment> \\<open>refines @{term \"m2_tick\"}\\<close>\n  m3_tick :: \"time \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_tick \\<equiv> m1_tick\"\n\n\ntext \\<open>Session key compromise.\\<close>\n\ndefinition     \\<comment> \\<open>refines @{term m2_leak}\\<close>\n  m3_leak :: \"rid_t \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_leak Rs \\<equiv> {(s, s1).\n    \\<comment> \\<open>guards:\\<close>\n    Rs \\<in> dom (runs s) \\<and>\n    fst (the (runs s Rs)) = Serv \\<and>         \\<comment> \\<open>compromise server run \\<open>Rs\\<close>\\<close>\n\n    \\<comment> \\<open>actions:\\<close>\n    \\<comment> \\<open>record session key as leaked and add it to intruder knowledge\\<close>\n    s1 = s\\<lparr> leak := insert (sesK (Rs$sk)) (leak s),\n            IK := insert (Key (sesK (Rs$sk))) (IK s) \\<rparr>\n  }\"\n\ntext \\<open>Intruder fake event. The following \"Dolev-Yao\" event generates all\nintruder-derivable messages.\\<close>\n\ndefinition     \\<comment> \\<open>refines @{term \"m2_fake\"}\\<close>\n  m3_DY_fake :: \"m3_trans\"\nwhere\n  \"m3_DY_fake \\<equiv> {(s, s1).\n\n     \\<comment> \\<open>actions:\\<close>\n     s1 = s\\<lparr> IK := synth (analz (IK s)) \\<rparr>       \\<comment> \\<open>take DY closure\\<close>\n  }\"\n\n\n(******************************************************************************)\nsubsection \\<open>Transition system\\<close>\n(******************************************************************************)\n\ndefinition\n  m3_init :: \"m3_pred\"\nwhere\n  \"m3_init \\<equiv> { \\<lparr>\n     runs = Map.empty,\n     leak = shrK`bad,\n     clk = 0,\n     IK = Key`shrK`bad\n  \\<rparr> }\"\n\ndefinition\n  m3_trans :: \"m3_trans\" where\n  \"m3_trans \\<equiv> (\\<Union>A B Ra Rb Rs Kab Ts T.\n     m3_step1 Ra A B \\<union>\n     m3_step2 Rb A B \\<union>\n     m3_step3 Rs A B Kab Ts \\<union>\n     m3_step4 Ra A B Kab Ts \\<union>\n     m3_step5 Rb A B Kab Ts \\<union>\n     m3_tick T \\<union>\n     m3_leak Rs \\<union>\n     m3_DY_fake \\<union>\n     Id\n  )\"\n\ndefinition\n  m3 :: \"(m3_state, m3_obs) spec\" where\n  \"m3 \\<equiv> \\<lparr>\n    init = m3_init,\n    trans = m3_trans,\n    obs = m3_obs\n  \\<rparr>\"\n\nlemmas m3_loc_defs =\n  m3_def m3_init_def m3_trans_def m3_obs_def\n  m3_step1_def m3_step2_def m3_step3_def m3_step4_def m3_step5_def\n  m3_tick_def m3_leak_def m3_DY_fake_def\n\nlemmas m3_defs = m3_loc_defs m2_defs\n\n\n(******************************************************************************)\nsubsection \\<open>Invariants\\<close>\n(******************************************************************************)\n\ntext \\<open>Specialized injection that we can apply more aggressively.\\<close>\n\nlemmas analz_Inj_IK = analz.Inj [where H=\"IK s\" for s]\nlemmas parts_Inj_IK = parts.Inj [where H=\"IK s\" for s]\n\ndeclare parts_Inj_IK [dest!]\n\ndeclare analz_into_parts [dest]\n\n\nsubsubsection \\<open>inv1: Secrecy of pre-distributed shared keys\\<close>\n(******************************************************************************)\n\ndefinition\n  m3_inv1_lkeysec :: \"m3_pred\"\nwhere\n  \"m3_inv1_lkeysec \\<equiv> {s. \\<forall>C.\n     (Key (shrK C) \\<in> parts (IK s) \\<longrightarrow> C \\<in> bad) \\<and>\n     (C \\<in> bad \\<longrightarrow> Key (shrK C) \\<in> IK s)\n  }\"\n\nlemmas m3_inv1_lkeysecI = m3_inv1_lkeysec_def [THEN setc_def_to_intro, rule_format]\nlemmas m3_inv1_lkeysecE [elim] = m3_inv1_lkeysec_def [THEN setc_def_to_elim, rule_format]\nlemmas m3_inv1_lkeysecD = m3_inv1_lkeysec_def [THEN setc_def_to_dest, rule_format]\n\n\ntext \\<open>Invariance proof.\\<close>\n\nlemma PO_m3_inv1_lkeysec_init [iff]:\n  \"init m3 \\<subseteq> m3_inv1_lkeysec\"\nby (auto simp add: m3_defs intro!: m3_inv1_lkeysecI)\n\nlemma PO_m3_inv1_lkeysec_trans [iff]:\n  \"{m3_inv1_lkeysec} trans m3 {> m3_inv1_lkeysec}\"\nby (fastforce simp add: PO_hoare_defs m3_defs intro!: m3_inv1_lkeysecI)\n\nlemma PO_m3_inv1_lkeysec [iff]: \"reach m3 \\<subseteq> m3_inv1_lkeysec\"\nby (rule inv_rule_incr) (fast+)\n\n\ntext \\<open>Useful simplifier lemmas\\<close>\n\nlemma m3_inv1_lkeysec_for_parts [simp]:\n  \"\\<lbrakk> s \\<in> m3_inv1_lkeysec \\<rbrakk> \\<Longrightarrow> Key (shrK C) \\<in> parts (IK s) \\<longleftrightarrow> C \\<in> bad\"\nby auto\n\nlemma m3_inv1_lkeysec_for_analz [simp]:\n  \"\\<lbrakk> s \\<in> m3_inv1_lkeysec \\<rbrakk> \\<Longrightarrow> Key (shrK C) \\<in> analz (IK s) \\<longleftrightarrow> C \\<in> bad\"\nby auto\n\n\nsubsubsection \\<open>inv3: Session keys not used to encrypt other session keys\\<close>\n(******************************************************************************)\n\ntext \\<open>Session keys are not used to encrypt other keys. Proof requires\ngeneralization to sets of session keys.\n\nNOTE: This invariant will be derived from the corresponding L2 invariant\nusing the simulation relation.\n\\<close>\n\ndefinition\n  m3_inv3_sesK_compr :: \"m3_pred\"\nwhere\n  \"m3_inv3_sesK_compr \\<equiv> {s. \\<forall>K KK.\n     KK \\<subseteq> range sesK \\<longrightarrow>\n     (Key K \\<in> analz (Key`KK \\<union> (IK s))) = (K \\<in> KK \\<or> Key K \\<in> analz (IK s))\n  }\"\n\nlemmas m3_inv3_sesK_comprI = m3_inv3_sesK_compr_def [THEN setc_def_to_intro, rule_format]\nlemmas m3_inv3_sesK_comprE = m3_inv3_sesK_compr_def [THEN setc_def_to_elim, rule_format]\nlemmas m3_inv3_sesK_comprD = m3_inv3_sesK_compr_def [THEN setc_def_to_dest, rule_format]\n\ntext \\<open>Additional lemma\\<close>\nlemmas insert_commute_Key = insert_commute [where x=\"Key K\" for K]\n\nlemmas m3_inv3_sesK_compr_simps =\n  m3_inv3_sesK_comprD\n  m3_inv3_sesK_comprD [where KK=\"insert Kab KK\" for Kab KK, simplified]\n  m3_inv3_sesK_comprD [where KK=\"{Kab}\" for Kab, simplified]\n  insert_commute_Key\n\n\n(******************************************************************************)\nsubsection \\<open>Refinement\\<close>\n(******************************************************************************)\n\nsubsubsection \\<open>Message abstraction and simulation relation\\<close>\n(******************************************************************************)\n\ntext \\<open>Abstraction function on sets of messages.\\<close>\n\ninductive_set\n  abs_msg :: \"msg set \\<Rightarrow> chmsg set\"\n  for H :: \"msg set\"\nwhere\n  am_M1:\n    \"\\<lbrace>Agent A, Agent B\\<rbrace> \\<in> H\n  \\<Longrightarrow> Insec A B (Msg []) \\<in> abs_msg H\"\n| am_M2a:\n    \"Crypt (shrK C) \\<lbrace>Agent B, Key K, Number T\\<rbrace> \\<in> H\n  \\<Longrightarrow> Secure Sv C (Msg [aAgt B, aKey K, aNum T]) \\<in> abs_msg H\"\n| am_M2b:\n    \"Crypt (shrK C) \\<lbrace>Key K, Agent A, Number T\\<rbrace> \\<in> H\n  \\<Longrightarrow> Secure Sv C (Msg [aKey K, aAgt A, aNum T]) \\<in> abs_msg H\"\n\n\ntext \\<open>R23: The simulation relation. This is a data refinement of\nthe insecure and secure channels of refinement 2.\\<close>\n\ndefinition\n  R23_msgs :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23_msgs \\<equiv> {(s, t). abs_msg (parts (IK t)) \\<subseteq> chan s }\"\n\ndefinition\n  R23_keys :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23_keys \\<equiv> {(s, t). \\<forall>KK K. KK \\<subseteq> range sesK \\<longrightarrow>\n     Key K \\<in> analz (Key`KK \\<union> (IK t)) \\<longleftrightarrow> aKey K \\<in> extr (aKey`KK \\<union> ik0) (chan s)\n  }\"\n\ndefinition\n  R23_pres :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23_pres \\<equiv> {(s, t). runs s = runs t \\<and> leak s = leak t \\<and> clk s = clk t}\"\n\ndefinition\n  R23 :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23 \\<equiv> R23_msgs \\<inter> R23_keys \\<inter> R23_pres\"\n\nlemmas R23_defs =\n  R23_def R23_msgs_def R23_keys_def R23_pres_def\n\n\ntext \\<open>The mediator function is the identity here.\\<close>\n\ndefinition\n  med32 :: \"m3_obs \\<Rightarrow> m2_obs\" where\n  \"med32 \\<equiv> id\"\n\n\nlemmas R23_msgsI = R23_msgs_def [THEN rel_def_to_intro, simplified, rule_format]\nlemmas R23_msgsE [elim] = R23_msgs_def [THEN rel_def_to_elim, simplified, rule_format]\n\nlemmas R23_keysI = R23_keys_def [THEN rel_def_to_intro, simplified, rule_format]\nlemmas R23_keysE [elim] = R23_keys_def [THEN rel_def_to_elim, simplified, rule_format]\n\nlemmas R23_presI = R23_pres_def [THEN rel_def_to_intro, simplified, rule_format]\nlemmas R23_presE [elim] = R23_pres_def [THEN rel_def_to_elim, simplified, rule_format]\n\nlemmas R23_intros = R23_msgsI R23_keysI R23_presI\n\n\ntext \\<open>Simplifier lemmas for various instantiations (for keys).\\<close>\n\nlemmas R23_keys_simp = R23_keys_def [THEN rel_def_to_dest, simplified, rule_format]\nlemmas R23_keys_simps =\n  R23_keys_simp\n  R23_keys_simp [where KK=\"{}\", simplified]\n  R23_keys_simp [where KK=\"{K'}\" for K', simplified]\n  R23_keys_simp [where KK=\"insert K' KK\" for K' KK, simplified, OF _ conjI]\n\n\nsubsubsection \\<open>General lemmas\\<close>\n(******************************************************************************)\n\ntext \\<open>General facts about @{term \"abs_msg\"}\\<close>\n\ndeclare abs_msg.intros [intro!]\ndeclare abs_msg.cases [elim!]\n\nlemma abs_msg_empty: \"abs_msg {} = {}\"\nby (auto)\n\nlemma abs_msg_Un [simp]:\n  \"abs_msg (G \\<union> H) = abs_msg G \\<union> abs_msg H\"\nby (auto)\n\nlemma abs_msg_mono [elim]:\n  \"\\<lbrakk> m \\<in> abs_msg G; G \\<subseteq> H \\<rbrakk> \\<Longrightarrow> m \\<in> abs_msg H\"\nby (auto)\n\nlemma abs_msg_insert_mono [intro]:\n  \"\\<lbrakk> m \\<in> abs_msg H \\<rbrakk> \\<Longrightarrow> m \\<in> abs_msg (insert m' H)\"\nby (auto)\n\n\ntext \\<open>Facts about @{term \"abs_msg\"} concerning abstraction of fakeable\nmessages. This is crucial for proving the refinement of the intruder event.\\<close>\n\nlemma abs_msg_DY_subset_fakeable:\n  \"\\<lbrakk> (s, t) \\<in> R23_msgs; (s, t) \\<in> R23_keys; t \\<in> m3_inv1_lkeysec \\<rbrakk>\n  \\<Longrightarrow> abs_msg (synth (analz (IK t))) \\<subseteq> fake ik0 (dom (runs s)) (chan s)\"\napply (auto)\n\\<comment> \\<open>4 subgoals, deal with replays first\\<close>\napply (blast)\ndefer 1 apply (blast)\n\\<comment> \\<open>remaining 2 subgoals are real fakes\\<close>\napply (rule fake_StatCh, auto simp add: R23_keys_simps)+\ndone\n\n\nsubsubsection \\<open>Refinement proof\\<close>\n(******************************************************************************)\n\ntext \\<open>Pair decomposition. These were set to \\texttt{elim!}, which is too\nagressive here.\\<close>\n\ndeclare MPair_analz [rule del, elim]\ndeclare MPair_parts [rule del, elim]\n\n\ntext \\<open>Protocol events.\\<close>\n\nlemma PO_m3_step1_refines_m2_step1:\n  \"{R23}\n     (m2_step1 Ra A B), (m3_step1 Ra A B)\n   {> R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n   (auto)\n\nlemma PO_m3_step2_refines_m2_step2:\n  \"{R23}\n     (m2_step2 Rb A B), (m3_step2 Rb A B)\n   {> R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n   (auto)\n\nlemma PO_m3_step3_refines_m2_step3:\n  \"{R23 \\<inter> (m2_inv3a_sesK_compr) \\<times> (m3_inv3_sesK_compr \\<inter> m3_inv1_lkeysec)}\n     (m2_step3 Rs A B Kab Ts), (m3_step3 Rs A B Kab Ts)\n   {> R23}\"\nproof -\n  { fix s t\n    assume H:\n      \"(s, t) \\<in> R23_msgs\" \"(s, t) \\<in> R23_keys\" \"(s, t) \\<in> R23_pres\"\n      \"s \\<in> m2_inv3a_sesK_compr\" \"t \\<in> m3_inv3_sesK_compr\" \"t \\<in> m3_inv1_lkeysec\"\n      \"Kab = sesK (Rs$sk)\" \"Rs \\<notin> dom (runs t)\"\n      \"\\<lbrace> Agent A, Agent B \\<rbrace> \\<in> parts (IK t)\"\n    let ?s'=\n      \"s\\<lparr> runs := runs s(Rs \\<mapsto> (Serv, [A, B], [aNum (clk t)])),\n          chan := insert (Secure Sv A (Msg [aAgt B, aKey Kab, aNum (clk t)]))\n                 (insert (Secure Sv B (Msg [aKey Kab, aAgt A, aNum (clk t)])) (chan s)) \\<rparr>\"\n    let ?t'=\n      \"t\\<lparr> runs := runs t(Rs \\<mapsto> (Serv, [A, B], [aNum (clk t)])),\n          IK := insert\n                  (Crypt (shrK A) \\<lbrace> Agent B, Key Kab, Number (clk t) \\<rbrace>)\n                (insert\n                  (Crypt (shrK B) \\<lbrace> Key Kab, Agent A, Number (clk t) \\<rbrace>)\n                (IK t)) \\<rparr>\"\n    have \"(?s', ?t') \\<in> R23_msgs\" using H\n    by (-) (rule R23_intros, auto)\n  moreover\n    have \"(?s', ?t') \\<in> R23_keys\" using H\n    by (-) (rule R23_intros,\n            auto simp add: m2_inv3a_sesK_compr_simps m3_inv3_sesK_compr_simps,\n            auto simp add: R23_keys_simps)\n  moreover\n    have \"(?s', ?t') \\<in> R23_pres\" using H\n    by (-) (rule R23_intros, auto)\n  moreover\n    note calculation\n  }\n  thus ?thesis\n  by  (auto simp add: PO_rhoare_defs R23_def m3_defs)\nqed\n\nlemma PO_m3_step4_refines_m2_step4:\n  \"{R23 \\<inter> UNIV \\<times> (m3_inv1_lkeysec)}\n     (m2_step4 Ra A B Kab Ts), (m3_step4 Ra A B Kab Ts)\n   {> R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n   (auto)\n\nlemma PO_m3_step5_refines_m2_step5:\n  \"{R23}\n     (m2_step5 Rb A B Kab Ts), (m3_step5 Rb A B Kab Ts)\n   {> R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n   (auto)\n\nlemma PO_m3_tick_refines_m2_tick:\n  \"{R23}\n     (m2_tick T), (m3_tick T)\n   {>R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n   (auto)\n\n\ntext \\<open>Intruder events.\\<close>\n\nlemma PO_m3_leak_refines_m2_leak:\n  \"{R23}\n     (m2_leak Rs), (m3_leak Rs)\n   {>R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs  intro!: R23_intros)\n   (auto simp add: R23_keys_simps)\n\nlemma PO_m3_DY_fake_refines_m2_fake:\n  \"{R23 \\<inter> UNIV \\<times> (m3_inv1_lkeysec)}\n     m2_fake, m3_DY_fake\n   {> R23}\"\napply (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros\n            del: abs_msg.cases)\napply (auto intro: abs_msg_DY_subset_fakeable [THEN subsetD]\n            del: abs_msg.cases)\napply (auto simp add: R23_keys_simps)\ndone\n\n\ntext \\<open>All together now...\\<close>\n\nlemmas PO_m3_trans_refines_m2_trans =\n  PO_m3_step1_refines_m2_step1 PO_m3_step2_refines_m2_step2\n  PO_m3_step3_refines_m2_step3 PO_m3_step4_refines_m2_step4\n  PO_m3_step5_refines_m2_step5 PO_m3_tick_refines_m2_tick\n  PO_m3_leak_refines_m2_leak PO_m3_DY_fake_refines_m2_fake\n\n\nlemma PO_m3_refines_init_m2 [iff]:\n  \"init m3 \\<subseteq> R23``(init m2)\"\nby (auto simp add: R23_def m3_defs intro!: R23_intros)\n\nlemma PO_m3_refines_trans_m2 [iff]:\n  \"{R23 \\<inter> (m2_inv3a_sesK_compr) \\<times> (m3_inv3_sesK_compr \\<inter> m3_inv1_lkeysec)}\n     (trans m2), (trans m3)\n   {> R23}\"\nby (auto simp add: m3_def m3_trans_def m2_def m2_trans_def)\n   (blast intro!: PO_m3_trans_refines_m2_trans)+\n\nlemma PO_m3_observation_consistent [iff]:\n  \"obs_consistent R23 med32 m2 m3\"\nby (auto simp add: obs_consistent_def R23_def med32_def m3_defs)\n\n\ntext \\<open>Refinement result.\\<close>\n\nlemma m3_refines_m2 [iff]:\n  \"refines\n     (R23 \\<inter> (m2_inv3a_sesK_compr) \\<times> (m3_inv1_lkeysec))\n     med32 m2 m3\"\nproof -\n  have \"R23 \\<inter> m2_inv3a_sesK_compr \\<times> UNIV \\<subseteq> UNIV \\<times> m3_inv3_sesK_compr\"\n    by (auto simp add: R23_def R23_keys_simps intro!: m3_inv3_sesK_comprI)\n  thus ?thesis\n    by (-) (rule Refinement_using_invariants, auto)\nqed\n\nlemma m3_implements_m2 [iff]:\n  \"implements med32 m2 m3\"\nby (rule refinement_soundness) (auto)\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Security_Protocol_Refinement/Key_establish/m3_ds_par.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6150878555160665, "lm_q2_score": 0.45713671682749485, "lm_q1q2_score": 0.28117924283107915}}
{"text": "(*  Title:      HOL/Auth/n_mutualExDeadFree_lemma_invs_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mutualExDeadFree Protocol Case Study*} \n\ntheory n_mutualExDeadFree_lemma_invs_on_rules imports n_mutualExDeadFree_lemma_inv__2_on_rules n_mutualExDeadFree_lemma_inv__3_on_rules\nbegin\nlemma invs_on_rules:\n  assumes a1: \"f \\<in> invariants N\" and a2: \"r \\<in> rules N\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have b1: \"(\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__2  p__Inv0 p__Inv1)\\<or>\n    (\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__3  p__Inv0 p__Inv1)\"\n  apply (cut_tac a1, auto) done\n    moreover {\n      assume c1: \"(\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__2  p__Inv0 p__Inv1)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__2_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__3  p__Inv0 p__Inv1)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__3_on_rules) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "hongjianjiang", "repo": "paraverif_dafny", "sha": "083d86afb46a847783cb9319d975b3c2ad0afe93", "save_path": "github-repos/isabelle/hongjianjiang-paraverif_dafny", "path": "github-repos/isabelle/hongjianjiang-paraverif_dafny/paraverif_dafny-083d86afb46a847783cb9319d975b3c2ad0afe93/examples/n_mutualExDeadFree/n_mutualExDeadFree_lemma_invs_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6654105454764747, "lm_q2_score": 0.42250463481418826, "lm_q1q2_score": 0.28113903951804775}}
{"text": "(*****************************************************************************\n * ESPL --- an embedded security protocol logic\n *          http://people.inf.ethz.ch/meiersi/espl/\n *\n *   Copyright (c) 2009-2011, Simon Meier, ETH Zurich, Switzerland\n *\n * Extension to compromising adversaries:\n *\n *   Copyright (c) 2010-2011, Martin Schaub, ETH Zurich, Switzerland\n *\n * All rights reserved. See file LICENCE for more information.\n ******************************************************************************)\ntheory WeakTyping\nimports\n  InferenceRules\n  Syntax\nbegin\n\nsection{* A Shallow Embedding of a Message Type System *}\n\nsubsection{* Introduction *}\n\ntext{*\n  The goal of this theory is to develop a simple way for specifying\n  type invariants for the message variables of a protocol. A message\n  type is a set of messages that depends on the thread and the \n  system state that this message type is interpreted relative to.\n  \n  A typing is then a function assigning to each combination of a\n  role and an identifier of a message variable in this role a \n  message type. \n\n  Each typing approximates the set of states where all instantiated\n  message variables are instantiated with a message corresponding \n  to their type.\n*}\n\ntype_synonym msgtype = \"tid \\<Rightarrow> state \\<Rightarrow> execmsg set\"\n\ntype_synonym typing = \"(role \\<times> id) \\<Rightarrow> msgtype\"\n\ndefinition approx :: \"typing \\<Rightarrow> state set\"\nwhere \"approx typing \\<equiv> {q. case q of (t,r,s) \\<Rightarrow>\n  \\<forall> (i,step) \\<in> steps t. \n    \\<forall> R. roleMap r i = Some R \\<longrightarrow>\n      (\\<forall> n. MVar n \\<in> FV_rolestep step \\<longrightarrow>\n         s (MVar n, i) \\<in> typing (R, n) i (t,r,s)\n      )}\"\n\nlocale typed_state = reachable_state+\n  fixes typing :: \"typing\"\n  assumes approximates: \"(t,r,s) \\<in> approx typing\"\n\nlocale typed_thread = reachable_thread+\n  fixes typing :: \"typing\"\n  assumes approximates: \"(t,r,s) \\<in> approx typing\"\n\nsublocale typed_thread \\<subseteq> typed_state\n  using approximates by unfold_locales\n\n\nlemma approx_unfold:\n  \"((t,r,s) \\<in> approx typing) = \n   (\\<forall> (i,step) \\<in> steps t. \n      \\<forall> R. roleMap r i = Some R \\<longrightarrow>\n        (\\<forall> n. MVar n \\<in> FV_rolestep step \\<longrightarrow>\n           s (MVar n, i) \\<in> typing (R, n) i (t,r,s)))\"\nby (auto simp: approx_def)\n\nlemma in_approxI:\n  assumes all_vars:\n    \"\\<And> i step R n.\n     \\<lbrakk> (i,step) \\<in> steps t;\n       roleMap r i = Some R;\n       MVar n \\<in> FV_rolestep step\n     \\<rbrakk>\n       \\<Longrightarrow> s (MV n i) \\<in> typing (R, n) i (t,r,s)\"\n  shows \"(t,r,s) \\<in> approx typing\"\nby (auto simp: approx_unfold dest!: all_vars)\n\nlemma in_approxD:\n  assumes approx: \"(t,r,s) \\<in> approx typing\"\n  and asms: \"(i,step) \\<in> steps t\"\n            \"roleMap r i = Some R\"\n            \"MVar n \\<in> FV_rolestep step\"\n  shows \"s (MV n i) \\<in> typing (R, n) i (t,r,s)\"\nusing approx asms\nby (auto simp: approx_unfold)\n\n\nsubsection{* A Combinator Language for Message Types *}\n\nsubsubsection{* Structural Types *}\n\ntext{*\n  Structural message types specify the structure of a message.\n  Their interpretation is independent of the thread that they\n  are interpreted in. All of them except the type for nonces of\n  a specific role are also independent of the state that they\n  are interpreted in.\n*}\n\ndefinition ConstT :: \"id \\<Rightarrow> msgtype\"\nwhere \"ConstT c i q \\<equiv> { LC c }\"\n\ndefinition AgentT :: msgtype\nwhere \"AgentT i q \\<equiv>  Agent\"\n\ndeclare AgentT_def [simp]\n\ndefinition NonceT :: \"role \\<Rightarrow> id \\<Rightarrow> msgtype\"\nwhere \"NonceT R n i q  \\<equiv> case q of \n         (t,r,s) \\<Rightarrow> { LN n i' | i'. roleMap r i' = Some R }\"\n\ndefinition HashT :: \"msgtype \\<Rightarrow> msgtype\"\nwhere \"HashT ty  i q \\<equiv> { Hash m | m. m \\<in> ty i q }\"\n\ndefinition TupT :: \"msgtype \\<Rightarrow> msgtype \\<Rightarrow> msgtype\"\nwhere \"TupT ty1 ty2 i q \\<equiv> \n         { \\<lbrace>x, y\\<rbrace> | x y. x \\<in> ty1 i q \\<and> y \\<in> ty2 i q }\"\n\ndefinition EncT :: \"msgtype \\<Rightarrow> msgtype \\<Rightarrow> msgtype\"\nwhere \"EncT tym tyk i q \\<equiv> \n         { Enc m k | m k. m \\<in> tym i q \\<and> k \\<in> tyk i q }\"\n\ndefinition PKT :: \"msgtype \\<Rightarrow> msgtype\"\nwhere \"PKT ty  i q \\<equiv> { PK m | m. m \\<in> ty i q }\"\n\ndefinition SKT :: \"msgtype \\<Rightarrow> msgtype\"\nwhere \"SKT ty  i q \\<equiv> { SK m | m. m \\<in> ty i q }\"\n\ndefinition KT :: \"msgtype \\<Rightarrow> msgtype \\<Rightarrow> msgtype\"\nwhere \"KT ty1 ty2 i q \\<equiv> \n         { K m1 m2 | m1 m2. m1 \\<in> ty1 i q \\<and> m2 \\<in> ty2 i q }\"\n\ndefinition KShrT :: \"msgtype\"\nwhere \"KShrT i q \\<equiv> { KShr A | A. True }\" \n\n\ntext{* TODO: Make this syntax abbreviation work. *}\nsyntax\n  \"@TTuple\"      :: \"['a, args] => 'a * 'b\"       (\"(2{$_,/ _$})\")\n\nsyntax (xsymbols)\n  \"@TTuple\"      :: \"['a, args] => 'a * 'b\"       (\"(2\\<lbrace>$_,/ _$\\<rbrace>)\")\n\ntranslations\n  \"{$x, y, z$}\"   == \"{$x, {$y, z$}$}\" \n  \"{$x, y$}\"      == \"WeakTyping.TupT x y\"\n\n\nsubsubsection{* Special Types *}\n\ntext{* \n  The empty type denotes that a variable is never instantiated.\n  The sum type denotes the union of two message types, while\n  the intersection type denotes the intersection of the two \n  message types.\n*}\n\ndefinition EmptyT :: \"msgtype\"\nwhere \"EmptyT i q \\<equiv> {}\"\n\ndeclare EmptyT_def [simp]\n\ndefinition SumT :: \"msgtype \\<Rightarrow> msgtype \\<Rightarrow> msgtype\"\nwhere \"SumT ty1 ty2 i q \\<equiv> ty1 i q \\<union> ty2 i q\"\n\ndefinition InterT :: \"msgtype \\<Rightarrow> msgtype \\<Rightarrow> msgtype\"\nwhere \"InterT ty1 ty2 i q \\<equiv> ty1 i q \\<inter> ty2 i q\"\n\n\ntext{*\n  The known before a specific role step type captures the\n  interaction of the intruder with the execution of a protocol.\n  If the intruder fakes a message being received, then the\n  variables are instantiated with messages known to the intruder\n  \\emph{before} the receive step was executed.\n*}\n\ndefinition KnownT :: \"rolestep \\<Rightarrow> msgtype\"\nwhere \"KnownT step i q \\<equiv> case q of  (t,r,s) \\<Rightarrow> \n  { m | m. predOrd t (Ln m) (St (i,step)) }\"\n\n\nsubsubsection{* Constructing Type Invariants *}\n\ntext{*\n  The following function converts a list of type assignments to a\n  typing. It will be used to specify the type invariants of specific\n  protocols.\n*}\n\ndefinition mk_typing :: \"((role \\<times> id) \\<times> msgtype) list \\<Rightarrow> typing\"\nwhere \"mk_typing tyeqs \\<equiv> \n         foldr (\\<lambda>(x, ty) typing. typing(x:=ty)) tyeqs (\\<lambda>x. EmptyT)\"\n\n\nsubsection{* Proving Well-Typedness *}\n\ntext{*\n  A protocol is well-typed with respect to a typing iff\n  all its reachable state are approximated by the typing.\n\n  We specialize the induction scheme that we get from the definition\n  of the set of reachable states to a ``type checking'' induction\n  scheme. It works for message typings that are monotoneous with\n  respect to state updates.\n*}\n\ndefinition monoTyp :: \"typing \\<Rightarrow> bool\" \nwhere \"monoTyp typ \\<equiv> \n  (\\<forall> x i t r s t' r'.\n      roleMap r \\<subseteq>\\<^sub>m roleMap r' \\<longrightarrow>\n      typ x i (t,r,s) \\<subseteq> typ x i (t@t',r',s)\n  )\"\n\nlemma monoTypI:\n  \"\\<lbrakk> \\<And> x i t r s t' r' s' m. \n     \\<lbrakk> roleMap r \\<subseteq>\\<^sub>m roleMap r'; m \\<in> typ x i (t,r,s) \\<rbrakk>\n     \\<Longrightarrow> m \\<in> typ x i (t@t',r',s)\n   \\<rbrakk> \\<Longrightarrow> monoTyp typ\"\n  by(auto simp: monoTyp_def)\n\nlemma monoTypD:\n  \"\\<lbrakk> monoTyp typ;\n     m \\<in> typ x i (t,r,s);\n     roleMap r \\<subseteq>\\<^sub>m roleMap r'\n   \\<rbrakk> \\<Longrightarrow>\n   m \\<in> typ x i (t@t',r',s)\"\n  unfolding monoTyp_def by blast\n\nlemma monoTyp_freeD:\n  \"\\<lbrakk> monoTyp typ;\n     m \\<in> typ x i (t,r,s);\n     roleMap r \\<subseteq>\\<^sub>m roleMap r';\n     t' = t@t''\n   \\<rbrakk> \\<Longrightarrow>\n   m \\<in> typ x i (t',r',s)\"\n  unfolding monoTyp_def by blast\n\nlemma monoTyp_appendD:\n  \"\\<lbrakk> monoTyp typ;\n     m \\<in> typ x i (t,r,s)\n   \\<rbrakk> \\<Longrightarrow>\n   m \\<in> typ x i (t@t',r,s)\"\n  by (rule monoTyp_freeD) auto\n\n\nlemma (in reachable_thread) step_done_typing:\n  assumes typ_rule:\n    \"\\<And> step.\n     \\<lbrakk> (i, step) \\<in> steps t;\n       MVar v \\<in> FV_rolestep step\n     \\<rbrakk> \\<Longrightarrow> s (MV v i) \\<in> typing (done @ todo, v) i (t, r, s)\"\n  and step_done: \"step \\<in> set done\"\n  and step_var: \"MVar v \\<in> FV_rolestep step\"\n  shows \"s (MV v i) \\<in> typing (done @ todo, v) i (t, r, s)\"\nproof (cases \"step \\<in> skipped\")\n  case False\n  thus ?thesis using assms by auto\nnext\n  case True\n  note inSkipped = this\n  then obtain l ty pt\n    where noteEq: \"(Note l ty pt) = step\"\n    by(auto dest!: note_in_skipped)\n  hence \"\\<exists> step'. listOrd (done@todo) step' (Note l ty pt) \\<and> v \\<in> sourced_vars step'\"\n    using inSkipped step_done step_var\n    apply -\n    apply(subgoal_tac \"v \\<in> used_vars step\")\n      apply(subgoal_tac \"Note l ty pt \\<in> set (done@todo)\")\n        apply(drule source_use_ord)\n    by auto\n  then obtain step'\n    where roleBefore: \"listOrd (done@todo) step' (Note l ty pt)\"\n    and varSourced: \"v \\<in> sourced_vars step'\"\n    by auto\n  have notNote: \"\\<not> noteStep step'\" using varSourced by auto\n  have \"step' \\<in> set done\" \n    using roleBefore step_done noteEq\n    apply -\n    apply(drule listOrd_append[THEN iffD1])\n    apply(case_tac \"listOrd done step' (Note l ty pt)\")\n      apply(fastforce dest: in_set_listOrd1)\n    apply(case_tac \"listOrd todo step' (Note l ty pt)\")\n      apply(fastforce dest: in_set_listOrd2 done_notin_todoD)\n    apply(case_tac \"step' \\<in> set done \\<and> Note l ty pt \\<in> set todo\")\n    by(auto dest: done_notin_todoD)\n  hence \"(i, step') \\<in> steps t\" using notNote by (cases step', auto)\n  thus ?thesis\n    using varSourced by (auto intro!: typ_rule thread_exists)\nqed\n\n\nlemma (in reachable_state) reachable_in_approxI:\n  assumes monoTyp: \"monoTyp typing\"\n  and source_case:\n    \"\\<And> t r s i done todo skipped m R step n.\n     \\<lbrakk> R \\<in> P; \n       roleMap r i = Some R;\n       (done, step # todo) \\<in> set (splits R);\n       \\<not> sendStep step; \\<not> noteStep step;\n       n \\<in> sourced_vars step;\n       \\<forall> step' \\<in> set done. MVar n \\<notin> FV_rolestep step';\n       hint ''completenessCase'' (step, n);\n       \n       (t,r,s) \\<in> reachable P;\n       (t,r,s) \\<in> approx typing;\n       r i = Some (done, step # todo, skipped);\n       \n       recvStep step \\<Longrightarrow> Some m = inst s i (stepPat step) \\<and> m \\<in> knows t;\n       matchEqStep step \\<Longrightarrow> exec_match s i (matchVar step) (stepPat step)\n     \\<rbrakk> \\<Longrightarrow> \n        s (MV n i) \\<in> typing (R, n) i (t @ [Step (i, step)], r(i \\<mapsto> (done @ [step], todo, skipped)), s)\"\n  shows \"(t,r,s) \\<in> approx typing\"\nproof -\n  { fix i step \"done\" todo skipped n\n    have\n     \"\\<lbrakk> r i = Some (done, todo, skipped);\n        (i,step) \\<in> steps t;\n        MVar n \\<in> FV_rolestep step\n      \\<rbrakk> \\<Longrightarrow> s (MV n i) \\<in> typing (done@todo, n) i (t,r,s)\"\n    proof(induct arbitrary: i \"done\" todo step n skipped rule: reachable_induct)\n      case (send t r s i \"done\" l pt todo skipped m i' done' todo' step n skipped')\n      then interpret th1: \n        reachable_thread P t r s i \"done\" \"Send l pt # todo\" skipped\n        by unfold_locales auto\n      from send \n      have \"(i', step) \\<in> steps t \\<or> (i' = i) \\<and> step = Send l pt\"\n        (is \"?old \\<or> ?new\") by auto\n      moreover\n      { assume ?old\n        hence \"s(MV n i') \\<in> typing (done'@todo', n) i' (t,r,s)\"\n          using send by (auto split: if_splits)\n        hence ?case\n        proof(rule monoTyp_freeD[OF monoTyp])\n        qed (auto simp: th1.thread_exists)\n      }\n      moreover\n      { let ?role = \"done @ Send l pt # todo\"\n        note IH = send(2)\n        assume \"?new\"\n        moreover hence \"n \\<in> used_vars step\" using send by auto\n        ultimately obtain step' \n          where \"(i, step') \\<in> steps t\" \n                \"n \\<in> sourced_vars step'\"   \n          by (fastforce dest!: th1.source_step[OF th1.thread_exists])\n        hence typed: \"s (MV n i) \\<in> typing (?role, n) i (t, r, s)\"\n          by (auto dest: IH[OF th1.thread_exists])\n        have \"done'@todo' = ?role\"\n          using send `?new` by auto\n        hence ?case using `?new`\n          apply -\n          apply(rule monoTyp_freeD[OF monoTyp])\n          by (auto intro!: typed simp: th1.thread_exists)\n      }\n      ultimately show ?case by fast\n    next\n      case (recv t r s i \"done\" l pt todo skipped m i' done' todo' step n skipped') then\n      interpret th1: \n        reachable_thread P t r s i \"done\" \"Recv l pt # todo\" skipped\n        by unfold_locales auto\n      from recv\n      have \"(i', step) \\<in> steps t \\<or> (i' = i) \\<and> step = Recv l pt\"\n        (is \"?old \\<or> ?new\") by auto\n      moreover\n      { assume ?old\n        hence \"s(MV n i') \\<in> typing (done'@todo', n) i' (t,r,s)\"\n          using recv by (auto split: if_splits)\n        hence ?case using `?old`\n          apply -\n          apply(rule monoTyp_freeD[OF monoTyp])\n          apply(auto simp: th1.thread_exists)\n          done\n      }\n      moreover\n      { let ?role = \"done @ Recv l pt # todo\"\n        note IH = recv(2)\n        assume \"?new\"\n        hence cur_thread: \"?role = done' @ todo'\" \"i = i'\" \n          using recv by auto\n        have ?case\n        proof(cases \"\\<exists> step' \\<in> set done. MVar n \\<in> FV_rolestep step'\")\n          case True\n          with recv\n          obtain step'\n            where FV: \"MVar n \\<in> FV_rolestep step'\" \n            and step': \"step' \\<in> set done\"\n            by auto\n          hence \"s (MV n i) \\<in> typing (done'@todo', n) i (t, r, s)\"\n            using th1.thread_exists cur_thread IH\n            by (metis th1.step_done_typing)\n          thus ?thesis using `?new`\n            apply -\n            apply(rule monoTyp_freeD[OF monoTyp])\n            apply(auto simp: th1.thread_exists)\n            done\n        next\n          case False\n            moreover have \"(t, r, s) \\<in> approx typing\"\n              by (auto simp: approx_unfold dest!: IH roleMap_SomeD)\n            moreover note `?new`\n            moreover note `MVar n \\<in> FV_rolestep step`\n            moreover note `Some m = inst s i pt`\n            moreover note `m \\<in> knows t`\n            moreover note cur_thread[symmetric]\n          \n            ultimately show ?thesis\n              apply -\n              apply(clarsimp simp del: fun_upd_apply)\n              apply(rule source_case)\n              apply(simp_all add: th1.role_in_P th1.roleMap th1.thread_exists \n                                  in_set_splits_conv remove_hints)\n              done\n         qed\n      }\n      ultimately show ?case by fastforce\n    next\n      case (compr t r s i \"done\" l ty pt todo skipped m i' done' todo' step n skipped')\n      then interpret th1: \n        reachable_thread P t r s i \"done\" \"Note l ty pt # todo\" skipped\n        by unfold_locales auto\n      from compr\n      have \"(i', step) \\<in> steps t \\<or> (i' = i) \\<and> step = Note l ty pt\"\n        (is \"?old \\<or> ?new\") by auto\n      moreover\n      { assume ?old\n        hence \"s(MV n i') \\<in> typing (done'@todo', n) i' (t,r,s)\"\n          using compr by (auto split: if_splits)\n        hence ?case\n        proof(rule monoTyp_freeD[OF monoTyp])\n        qed (auto simp: th1.thread_exists)\n      }\n      moreover\n      { let ?role = \"done @ Note l ty pt # todo\"\n        note IH = compr(2)\n        assume \"?new\"\n        hence \"n \\<in> used_vars (Note l ty pt)\"\n          using compr by auto\n        then obtain step' \n          where \"(i, step') \\<in> steps t\" \n                \"n \\<in> sourced_vars step'\"\n          by (fastforce dest!: th1.source_step[OF th1.thread_exists])\n        moreover hence \"MVar n \\<in> FV_rolestep step'\" by auto\n        ultimately have typed: \"s (MV n i) \\<in> typing (?role, n) i (t, r, s)\"\n          by (auto dest: IH[OF th1.thread_exists])\n        have \"done'@todo' = ?role\"\n          using compr `?new` by auto\n        hence ?case using `?new`\n          apply -\n          apply(rule monoTyp_freeD[OF monoTyp])\n          by (auto intro!: typed simp: th1.thread_exists)\n      }\n      ultimately show ?case by fast\n    next\n      case (skip t r s i \"done\" l ty pt todo skipped i' done' todo' step n skipped')\n      then interpret th1: \n        reachable_thread P t r s i \"done\" \"Note l ty pt # todo\" skipped\n        by unfold_locales auto\n      from skip\n      have \"(i', step) \\<in> steps t\" (is \"?old\") by auto\n      hence \"s(MV n i') \\<in> typing (done'@todo', n) i' (t,r,s)\"\n        using skip by (auto split: if_splits)\n      thus ?case\n      proof(rule monoTyp_freeD[OF monoTyp])\n      qed (auto simp: th1.thread_exists)\n    next\n      case (match t r s i \"done\" l eq mv pt todo skipped i' done' todo' step n skipped') then\n      interpret th1:\n        reachable_thread P t r s i \"done\" \"Match l eq mv pt # todo\" skipped\n        by unfold_locales auto\n      from match\n      have \"(i', step) \\<in> steps t \\<or> (i' = i) \\<and> step = Match l eq mv pt\"\n        (is \"?old \\<or> ?new\") by auto\n      moreover\n      { assume ?old\n        hence \"s (MV n i') \\<in> typing (done'@todo', n) i' (t,r,s)\"\n          using match by (auto split: if_splits)\n        hence ?case\n        proof (rule monoTyp_freeD[OF monoTyp])\n        qed (auto simp: th1.thread_exists)\n      }\n      moreover\n      { let ?role = \"done @ Match l eq mv pt # todo\"\n        note IH = match(2)\n        assume \"?new\"\n        have ?case proof (cases eq)\n          case True\n          note eq_case = this\n          hence cur_thread: \"?role = done' @ todo'\" \"i = i'\" and\n                match_FV: \"n \\<in> used_vars step \\<or> n \\<in> sourced_vars step\"\n          using `?new` match by auto\n          from match_FV show ?thesis proof\n            assume \"n \\<in> used_vars step\"\n            with `?new` obtain step'\n              where \"(i, step') \\<in> steps t\"\n                    \"n \\<in> sourced_vars step'\"\n              by (fastforce dest!: th1.source_step[OF th1.thread_exists])\n            hence typed: \"s (MV n i) \\<in> typing (?role, n) i (t, r, s)\"\n              by (auto dest: IH[OF th1.thread_exists])\n            thus ?thesis using `?new` cur_thread(1)\n              apply -\n              apply(rule monoTyp_freeD[OF monoTyp])\n              by (auto intro!: typed simp: th1.thread_exists)\n          next\n            assume \"n \\<in> sourced_vars step\"\n            thus ?thesis\n            proof (cases \"\\<exists> step' \\<in> set done. MVar n \\<in> FV_rolestep step'\")\n              case True\n              with match\n              obtain step'\n                where FV: \"MVar n \\<in> FV_rolestep step'\"\n                and step': \"step' \\<in> set done\"\n                by auto\n              hence \"s (MV n i) \\<in> typing (done'@todo', n) i (t, r, s)\"\n                using th1.thread_exists cur_thread IH\n                by (metis th1.step_done_typing)\n              thus ?thesis using `?new`\n                apply -\n                apply(rule monoTyp_freeD[OF monoTyp])\n                apply(auto simp: th1.thread_exists)\n                done\n            next\n              case False\n                moreover have \"(t, r, s) \\<in> approx typing\"\n                  by (auto simp: approx_unfold dest!: IH roleMap_SomeD)\n                moreover note `?new`\n                moreover note `n \\<in> sourced_vars step`\n                moreover have \"exec_match s i mv pt\"\n                  using match eq_case by simp\n                moreover note cur_thread[symmetric]\n\n                ultimately show ?thesis\n                  apply -\n                  apply(clarsimp simp del: fun_upd_apply)\n                  apply(rule source_case)\n                  apply(simp_all add: th1.role_in_P th1.roleMap th1.thread_exists\n                                      in_set_splits_conv remove_hints)\n                  done\n            qed\n          qed\n\n        next\n          case False note notMatch = this\n          moreover note `?new`\n          moreover hence \"n \\<in> used_vars step\" using match notMatch by auto\n          ultimately obtain step'\n            where \"(i, step') \\<in> steps t\" \n                  \"n \\<in> sourced_vars step'\"   \n            by (fastforce dest!: th1.source_step[OF th1.thread_exists])\n          hence typed: \"s (MV n i) \\<in> typing (?role, n) i (t, r, s)\"\n            by (auto dest: IH[OF th1.thread_exists])\n          have \"done'@todo' = ?role\" using match `?new` by auto\n          thus ?thesis using `?new`\n            apply -\n            apply(rule monoTyp_freeD[OF monoTyp])\n            by (auto intro!: typed simp: th1.thread_exists)\n        qed\n      }\n      ultimately show ?case by fastforce\n\n    qed (auto intro: monoTyp_appendD[OF monoTyp])\n  }\n  thus ?thesis unfolding approx_unfold by(auto elim!: roleMap_SomeE)\nqed\n\ntext{*\n  We prove a variant of the above lemma, which is suitable for\n  automation. The difference is the description of the variables\n  that need to be checked. Here, it is done such that Isabelle's\n  simplifier gets a finite set that it can rewrite into normal\n  form.\n*}\nlemma (in reachable_state) reachable_in_approxI_ext:\n  assumes monoTyp: \"monoTyp typing\"\n  and source_case:\n    \"\\<And> t r s i done todo skipped m R step n.\n     \\<lbrakk> R \\<in> P; \n       roleMap r i = Some R;\n       (done, step # todo) \\<in> set (splits R);\n       \\<not> sendStep step; \\<not> noteStep step;\n       n \\<in> foldl (\\<lambda> fv step'. fv - sourced_vars step') (sourced_vars step) done;\n       hint ''completenessCase'' (step, n);\n       \n       (t,r,s) \\<in> reachable P;\n       (t,r,s) \\<in> approx typing;\n       r i = Some (done, step # todo, skipped);\n       \\<forall> st'. st' \\<in> set done \\<longrightarrow> \\<not> noteStep st' \\<longrightarrow> (i, st') \\<in> steps t;\n\n       recvStep step \\<Longrightarrow> Some m = inst s i (stepPat step) \\<and> m \\<in> knows t;\n       matchEqStep step \\<Longrightarrow> exec_match s i (matchVar step) (stepPat step)\n     \\<rbrakk> \\<Longrightarrow>\n        s (MV n i) \\<in> typing (R, n) i ( t @ [Step (i, step)], r(i \\<mapsto> (done @ [step], todo, skipped)), s)\"\n  shows \"(t,r,s) \\<in> approx typing\"\nproof(induct rule: reachable_in_approxI[OF monoTyp])\n  case (1 t r s i \"done\" todo skipped m R step n)\n  { fix v V\n    assume \"v \\<in> V\"\n      and \"\\<forall>step'\\<in>set done. MVar v \\<notin> FV_rolestep step'\"\n    hence \"v \\<in> foldl (\\<lambda> fv step'. fv - sourced_vars step') V done\"\n      by (induct \"done\" arbitrary: V) (auto intro!: sourced_imp_FV)\n  }\n  hence \"n \\<in> foldl (\\<lambda> fv step'. fv - sourced_vars step') (sourced_vars step) done\"\n    using 1 by auto\n  moreover {\n    interpret thread: reachable_thread P t r s i \"done\" \"(step # todo)\" skipped\n      using 1 by unfold_locales auto\n    fix st'\n    assume \"st' \\<in> set done\" and \"\\<not> noteStep st'\"\n    hence \"(i, st') \\<in> steps t\" by (auto intro: thread.not_note_done_in_steps)\n  }\n  ultimately show ?case using 1\n    apply(subgoal_tac \"True\")\n    apply(clarsimp)\n    apply(rule source_case)\n    by(assumption | simp add: remove_hints)+\nqed\n\ntext{* Proving typing monotonicity *}\n\nsubsubsection{* Monotonicity Proofs *}\n\ndefinition monoMsgTyp :: \"msgtype \\<Rightarrow> bool\"\nwhere \"monoMsgTyp ty \\<equiv>\n         (\\<forall>i t r s t' r'.\n            roleMap r \\<subseteq>\\<^sub>m roleMap r' \\<longrightarrow>\n            ty i (t, r, s) \\<subseteq> ty i (t @ t', r', s))\"\n\nlemma monoMsgTypD:\n  \"\\<lbrakk> monoMsgTyp ty;\n     m \\<in> ty i (t,r,s);\n     roleMap r \\<subseteq>\\<^sub>m roleMap r'\n   \\<rbrakk> \\<Longrightarrow>\n   m \\<in> ty  i (t@t',r',s)\"\n  unfolding monoMsgTyp_def by blast\n\n\nlemma monoMsgTyp_SumTI[intro!]:\n  assumes ty1: \"monoMsgTyp ty1\"\n  and     ty2: \"monoMsgTyp ty2\"\n  shows \"monoMsgTyp (SumT ty1 ty2)\"\n  by(auto simp: monoMsgTyp_def SumT_def \n          dest: monoMsgTypD[OF ty1] monoMsgTypD[OF ty2])\n\nlemma monoMsgTyp_InterTI[intro!]:\n  assumes ty1: \"monoMsgTyp ty1\"\n  and     ty2: \"monoMsgTyp ty2\"\n  shows \"monoMsgTyp (InterT ty1 ty2)\"\n  by(auto simp: monoMsgTyp_def InterT_def \n          dest: monoMsgTypD[OF ty1] monoMsgTypD[OF ty2])\n\nlemma monoMsgTyp_KnownTI[iff]:\n  shows \"monoMsgTyp (KnownT step)\"\n  by(auto simp: monoMsgTyp_def KnownT_def )\n      \nlemma monoMsgTyp_NonceTI[iff]:\n  shows \"monoMsgTyp (NonceT R n)\"\n  by(auto simp: monoMsgTyp_def NonceT_def dest: map_leD)\n\nlemma monoMsgTyp_ConstTI[iff]:\n  shows \"monoMsgTyp (ConstT c)\"\n  by(auto simp: monoMsgTyp_def ConstT_def dest: map_leD)\n\nlemma monoMsgTyp_AgentTI[iff]:\n  shows \"monoMsgTyp AgentT\"\n  by(auto simp: monoMsgTyp_def AgentT_def dest: map_leD)\n\nlemma monoMsgTyp_EncTI[intro!]:\n  assumes ty1: \"monoMsgTyp ty1\"\n  and     ty2: \"monoMsgTyp ty2\"\n  shows \"monoMsgTyp (EncT ty1 ty2)\"\n  by(auto simp: monoMsgTyp_def EncT_def \n          dest: monoMsgTypD[OF ty1] monoMsgTypD[OF ty2])\n\nlemma monoMsgTyp_KTI[intro!]:\n  assumes ty1: \"monoMsgTyp ty1\"\n  and     ty2: \"monoMsgTyp ty2\"\n  shows \"monoMsgTyp (KT ty1 ty2)\"\n  by(auto simp: monoMsgTyp_def KT_def \n          dest: monoMsgTypD[OF ty1] monoMsgTypD[OF ty2])\n\nlemma monoMsgTyp_KShrTI[intro!]:\n  shows \"monoMsgTyp KShrT\"\n  by(auto simp: monoMsgTyp_def KShrT_def)\n\nlemma monoMsgTyp_TupTI[intro!]:\n  assumes ty1: \"monoMsgTyp ty1\"\n  and     ty2: \"monoMsgTyp ty2\"\n  shows \"monoMsgTyp (TupT ty1 ty2)\"\n  by(auto simp: monoMsgTyp_def TupT_def \n          dest: monoMsgTypD[OF ty1] monoMsgTypD[OF ty2])\n\nlemma monoMsgTyp_HashTI[intro!]:\n  assumes ty: \"monoMsgTyp ty\"\n  shows \"monoMsgTyp (HashT ty)\"\n  by(auto simp: monoMsgTyp_def HashT_def \n          dest: monoMsgTypD[OF ty])\n\nlemma monoMsgTyp_PKTI[intro!]:\n  assumes ty: \"monoMsgTyp ty\"\n  shows \"monoMsgTyp (PKT ty)\"\n  by(auto simp: monoMsgTyp_def PKT_def \n          dest: monoMsgTypD[OF ty])\n\nlemma monoMsgTyp_SKTI[intro!]:\n  assumes ty: \"monoMsgTyp ty\"\n  shows \"monoMsgTyp (SKT ty)\"\n  by(auto simp: monoMsgTyp_def SKT_def \n          dest: monoMsgTypD[OF ty])\n\nlemma monoTyp_mk_typing[intro!]:\n  assumes monoMsgTyp: \n     \"\\<And> pos ty. (pos, ty) \\<in> set tyeqs \\<Longrightarrow> monoMsgTyp ty\"\n  shows \"monoTyp (mk_typing tyeqs)\"\nusing monoMsgTyp\nproof(induct tyeqs)\n  case Nil thus ?case\n    by(auto intro!: monoTypI simp: mk_typing_def EmptyT_def)\nnext\n  case (Cons tyeq tyeqs) \n  thus ?case\n    proof(cases tyeq)\n      case (Pair pos' ty') \n      have mk_typing_Cons [simp]:\n        \"mk_typing ((pos',ty')#tyeqs) = (mk_typing tyeqs)(pos' := ty')\"\n        by (simp add: mk_typing_def)\n      with Pair show ?thesis\n        apply(auto intro!: monoTypI)\n        apply(auto intro: monoTypD[OF Cons(1), OF Cons(2)]\n                          monoMsgTypD[OF Cons(2)]\n                   simp: Pair)\n        done\n    qed\nqed\n\nsubsection{* Automation *}\n\ntext{*\nThe automation of the welltypedness proofs is rather fragile.\nAs a general rule of operation we try to unfold type information\nas late as possible. This allows to guide the automation tools\nby matching on the structure of the types. However, it also\nimplies that more rules are necessary. Moreover the current set\nof rules is not guaranteed to be complete.\n*}\n\nsubsubsection{* ACI of Sum and Intersection Types *}\n\nlemma SumT_absorb [simp]: \"SumT ty ty = ty\"\n  by (rule ext, rule ext) (auto simp: SumT_def)\n\nlemma SumT_left_absorb: \"SumT ty1 (SumT ty1 ty2) = SumT ty1 ty2\"\n  by (rule ext, rule ext) (auto simp: SumT_def)\n\nlemma SumT_commute: \"SumT ty1 ty2 = SumT ty1 ty2\"\n  by (rule ext, rule ext) (auto simp: SumT_def)\n\nlemma SumT_left_commute: \"SumT ty1 (SumT ty2 ty3) = SumT ty2 (SumT ty1 ty3)\"\n  by (rule ext, rule ext) (auto simp: SumT_def)\n\nlemma SumT_assoc: \"SumT (SumT ty1 ty2) ty3  = SumT ty1 (SumT ty2 ty3)\"\n  by (rule ext, rule ext) (auto simp: SumT_def)\n\nlemmas SumT_ac = SumT_assoc SumT_left_absorb SumT_commute SumT_left_commute\n  -- {* Type sum is an AC-operator *}\n\nlemma InterT_absorb [simp]: \"InterT ty ty = ty\"\n  by (rule ext, rule ext) (auto simp: InterT_def)\n\nlemma InterT_left_absorb: \"InterT ty1 (InterT ty1 ty2) = InterT ty1 ty2\"\n  by (rule ext, rule ext) (auto simp: InterT_def)\n\nlemma InterT_commute: \"InterT ty1 ty2 = InterT ty1 ty2\"\n  by (rule ext, rule ext) (auto simp: InterT_def)\n\nlemma InterT_left_commute: \"InterT ty1 (InterT ty2 ty3) = InterT ty2 (InterT ty1 ty3)\"\n  by (rule ext, rule ext) (auto simp: InterT_def)\n\nlemma InterT_assoc: \"InterT (InterT ty1 ty2) ty3  = InterT ty1 (InterT ty2 ty3)\"\n  by (rule ext, rule ext) (auto simp: InterT_def)\n\n\nlemmas InterT_ac = InterT_assoc InterT_left_absorb InterT_commute InterT_left_commute\n  -- {* Type intersection is an AC-operator *}\n\n\nsubsubsection{* Type Membership *}\n\n\ntext{* Special types *}\n\ntext{* The rules for SumT are special, as their usage currently\ndepends on the combination of SumT and KnownT.\n*}\nlemma in_SumTE:\n  \"\\<lbrakk> m \\<in> SumT ty1 ty2 i q; m \\<in> ty1 i q \\<Longrightarrow> R; m \\<in> ty2 i q \\<Longrightarrow> R \n   \\<rbrakk> \\<Longrightarrow> R\"\n  by(auto simp: SumT_def)\n\nlemma notin_SumTE [elim!]: \n  \"\\<lbrakk> m \\<notin> SumT ty1 ty2 i q; \n     \\<lbrakk> m \\<notin> ty1 i q; m \\<notin> ty2 i q \\<rbrakk> \\<Longrightarrow> R\n   \\<rbrakk> \\<Longrightarrow> R\"\n  by(auto simp: SumT_def)\n\nlemma notin_KnownT_append_StepE [dest!]:\n  \"m \\<notin> KnownT step i (t@ [Step (i, step)], r, s) \\<Longrightarrow>\n   m \\<notin> knows t\"\n  by(auto simp: KnownT_def)\n\nlemma in_SumT_NonceT_NonceTE [elim!]:\n  \"\\<lbrakk> m \\<in> SumT (NonceT Ro n) (NonceT Ro' n') i q; \n     m \\<in> NonceT Ro n i q \\<Longrightarrow> R; \n     m \\<in> NonceT Ro' n' i q \\<Longrightarrow> R \n   \\<rbrakk> \\<Longrightarrow> R\"\n  by(auto simp: SumT_def)\n\n(* TODO: Add more of the restricted SumT unfoldings analogous to the ones above.\n   We don't unfold SumT eagerly, as this would result in too many branches being created.\n   The above lemma is a hack to get triple types of the form SumT KnownT (SumT NonceT NonceT)\n   to work. The proper way would be to only expand types of variables that are being analyzed\n   by the decrChain function.\n*)\n\ntext{* Direct unfoldings *}\n\nlemma in_ConstT_simp [iff]:\n  \"(m \\<in> ConstT c i q) = (m = LC c)\"\n  by(auto simp: ConstT_def)\n\nlemma in_KnownTD [dest!]:\n  \"(x \\<in> KnownT step i (t,r,s)) \\<Longrightarrow> (predOrd t (Ln x) (St (i, step)))\"\n  by(simp add: KnownT_def)\n\n\ntext{* To be used together with if\\_splits in a well-typedness\nproof *}\nlemma in_NonceT [simp]: \n  \"(LN n i \\<in> NonceT R n i' (t,r,s)) = (roleMap r i = Some R)\"\n  by(simp add: NonceT_def)\n\nlemma in_NonceTE [elim!]:\n  \"\\<lbrakk> m \\<in> NonceT R n i (t,r,s); \n    \\<And> nTid. \\<lbrakk> m = LN n nTid; roleMap r nTid = Some R \\<rbrakk> \\<Longrightarrow> Q \n   \\<rbrakk> \\<Longrightarrow> Q\"\n  by(auto simp: NonceT_def)\n\nlemma notin_NonceT_thenonceE [elim!]:\n  \"\\<lbrakk> LN n nTid \\<notin> NonceT nR n i (t, r(i \\<mapsto> (done,todo,skipped)), s);\n     nTid = i \\<Longrightarrow> Q;\n     \\<lbrakk> nTid \\<noteq> i; roleMap r nTid \\<noteq> Some nR \\<rbrakk> \\<Longrightarrow> Q\n   \\<rbrakk> \\<Longrightarrow> Q\"\n  by(auto simp: NonceT_def split: if_splits)\n\n\ntext{* These rules ensure that type information is exploited\nwhen a match impossible without intruder activity happening.\n*}\nlemma Tup_in_SumT_KnownT_NonceTD [dest!]:\n  \"Tup x y \\<in> SumT (KnownT step) (NonceT R n) i (t, r, s)\n   \\<Longrightarrow> predOrd t (Ln (Tup x y)) (St (i, step))\"\n  by(auto simp: KnownT_def SumT_def)\n\nlemma Hash_in_SumT_KnownT_NonceTD [dest!]:\n  \"Hash x \\<in> SumT (KnownT step) (NonceT R n) i (t, r, s)\n   \\<Longrightarrow> predOrd t (Ln (Hash x)) (St (i, step))\"\n  by(auto simp: KnownT_def SumT_def)\n\nlemma Enc_in_SumT_KnownT_NonceTD [dest!]:\n  \"Enc x y \\<in> SumT (KnownT step) (NonceT R n) i (t, r, s)\n   \\<Longrightarrow> predOrd t (Ln (Enc x y)) (St (i, step))\"\n  by(auto simp: KnownT_def SumT_def)\n\ntext{* TODO: Extend these lemmas for further combinations. This requires\nsome more thinking. However, for a well-designed protocols the message\nstructure is not required for disambiguation because the encryptions\ncontain tags that identify them.\n*}\n\ntext{* Structural types *}\n\ntext{* The following rules are used in well-typedness proofs *}\nlemma Hash_in_HashT [simp]: \n  \"(Hash x \\<in> HashT ty i q) = (x \\<in> ty i q)\"\n  by (simp add: HashT_def)\n\nlemma Tup_in_TupT [simp]: \n  \"(Tup x y \\<in> TupT ty1 ty2 i q) = (x \\<in> ty1 i q \\<and> y \\<in> ty2 i q)\"\n  by (simp add: TupT_def)\n\nlemma Enc_in_EncT [simp]: \n  \"(Enc x y \\<in> EncT ty1 ty2 i q) = (x \\<in> ty1 i q \\<and> y \\<in> ty2 i q)\"\n  by (simp add: EncT_def)\n\nlemma PK_in_PKT [simp]: \"(PK x \\<in> PKT ty i q) = (x \\<in> ty i q)\"\n  by (simp add: PKT_def)\n\nlemma SK_in_SKT [simp]: \"(SK x \\<in> SKT ty i q) = (x \\<in> ty i q)\"\n  by (simp add: SKT_def)\n\nlemma K_in_KT [simp]: \n  \"(K x y \\<in> KT ty1 ty2 i q) = (x \\<in> ty1 i q \\<and> y \\<in> ty2 i q)\"\n  by (simp add: KT_def)\n\n\n\ntext{* The following rules ensure that messages are expanded\nautomatically in when applying the sources rule.\n*}\n\nlemma in_HashTE [elim!]:\n  \"\\<lbrakk> m \\<in> HashT ty i q;\n     \\<And> x. \\<lbrakk> m = Hash x; x \\<in> ty i q \\<rbrakk> \\<Longrightarrow> Q\n   \\<rbrakk> \\<Longrightarrow> Q\"\n  by(auto simp: HashT_def)\n\nlemma in_EncTE [elim!]:\n  \"\\<lbrakk> m \\<in> EncT ty1 ty2 i q;\n     \\<And> x k. \\<lbrakk> m = Enc x k; x \\<in> ty1 i q; k \\<in> ty2 i q \\<rbrakk> \\<Longrightarrow> Q\n   \\<rbrakk> \\<Longrightarrow> Q\"\n  by(auto simp: EncT_def)\n\nlemma in_TupTE [elim!]:\n  \"\\<lbrakk> m \\<in> TupT ty1 ty2 i q;\n     \\<And> x y. \\<lbrakk> m = \\<lbrace> x, y \\<rbrace>; x \\<in> ty1 i q; y \\<in> ty2 i q \\<rbrakk> \\<Longrightarrow> Q\n   \\<rbrakk> \\<Longrightarrow> Q\"\n  by(auto simp: TupT_def)\n\nlemma in_KTE [elim!]:\n  \"\\<lbrakk> m \\<in> KT ty1 ty2 i q;\n     \\<And> x y. \\<lbrakk> m = K x y; x \\<in> ty1 i q; y \\<in> ty2 i q \\<rbrakk> \\<Longrightarrow> Q\n   \\<rbrakk> \\<Longrightarrow> Q\"\n  by(auto simp: KT_def)\n\nlemma in_PKTE [elim!]:\n  \"\\<lbrakk> m \\<in> PKT ty i q;\n     \\<And> x. \\<lbrakk> m = PK x; x \\<in> ty i q \\<rbrakk> \\<Longrightarrow> Q\n   \\<rbrakk> \\<Longrightarrow> Q\"\n  by(auto simp: PKT_def)\n\nlemma in_SKTE [elim!]:\n  \"\\<lbrakk> m \\<in> SKT ty i q;\n     \\<And> x. \\<lbrakk> m = SK x; x \\<in> ty i q \\<rbrakk> \\<Longrightarrow> Q\n   \\<rbrakk> \\<Longrightarrow> Q\"\n  by(auto simp: SKT_def)\n\n\nsubsection{* Specialization of the Chain Rule *}\n\ntext{* We prove the case distinction on messages known to the\n  intruder with respect to an typed state, because we need\n  a sufficiently precise invariant when reasoning about the\n  contents of a variable.\n*}\nlemma (in typed_state) knows_cases:\n  assumes known: \"m' \\<in> knows t\"\n  shows \"\n   (m' \\<in> IK0 \\<and> \n    hint ''case_name'' ''ik0''\n   ) \\<or>\n   (\\<exists> m. m' = Hash m \\<and> Ln m \\<prec> Ln (Hash m) \\<and>\n         hint ''case_name'' ''fake''\n   ) \\<or>\n   (\\<exists> m k. m' = Enc m k \\<and> \n           Ln m \\<prec> Ln (Enc m k) \\<and> Ln k \\<prec> Ln (Enc m k) \\<and>\n           hint ''case_name'' ''fake''\n   ) \\<or>\n   (\\<exists> x y. m' = Tup x y \\<and> \n           Ln x \\<prec> Ln (Tup x y) \\<and> Ln y \\<prec> Ln (Tup x y) \\<and>\n           hint ''case_name'' ''fake''\n   ) \\<or>\n   (\\<exists> R \\<in> P. \\<exists> i. roleMap r i = Some R \\<and> \n      (\\<exists> step \\<in> set R.\n         (sendStep step \\<or> noteStep step) \\<and>\n         (\\<exists> m. Some m = inst s i (stepPat step) \\<and> decrChain [] t {St (i, step)} m m') \\<and>\n         prefixClose s t R step i \\<and>\n         (\\<forall> v \\<in> FV (stepPat step). \\<forall> n. v = MVar n \\<longrightarrow> \n            s (MVar n, i) \\<in> typing (R, n) i (t,r,s) \\<and>\n            hint ''case_name_subst'' n) \\<and>\n         hint ''decrChainFrom'' (i, R, step) \\<and>\n         hint ''case_name'' ''decrypt''\n      )\n\n   ) \\<or>\n   (\\<exists> a. m' = SK a \\<and> LKR a \\<prec> Ln m' \\<and> hint ''case_name'' ''asym_lkr'') \\<or>\n   (\\<exists> a b. m' = K a b \\<and> LKR a \\<prec> Ln m' \\<and> hint ''case_name'' ''sym_lkr1'') \\<or>\n   (\\<exists> a b. m' = K a b \\<and> LKR b \\<prec> Ln m' \\<and> hint ''case_name'' ''sym_lkr2'') \\<or>\n   (\\<exists> A. \\<exists> a \\<in> A. m' = KShr A \\<and> LKR (LAg a) \\<prec> Ln m' \\<and> hint ''case_name'' ''shr_lkr'')\n   \"\n  (is \"?ik0 \\<or> ?hash \\<or> ?encr \\<or> ?tup \\<or> ?decr \\<or> ?keys\")\nproof -\n  from known have\n   \"(m' \\<in> IK0) \\<or>\n    (\\<exists> m.   m' = Hash m   \\<and> Ln m \\<prec> Ln (Hash m)) \\<or>\n    (\\<exists> m k. m' = Enc  m k \\<and> Ln m \\<prec> Ln (Enc m k) \\<and> Ln k \\<prec> Ln (Enc m k)) \\<or>\n    (\\<exists> x y. m' = Tup  x y \\<and> Ln x \\<prec> Ln (Tup x y) \\<and> Ln y \\<prec> Ln (Tup x y)) \\<or>\n    (\\<exists> i done todo skipped. r i = Some (done, todo, skipped) \\<and> \n       (\\<exists> l pt m. \n          Send l pt \\<in> set done \\<and> Some m = inst s i pt \\<and> \n          decrChain [] t {St (i, Send l pt)} m m'\n       )\n    ) \\<or>\n    (\\<exists> i done todo skipped. r i = Some (done, todo, skipped) \\<and> \n       (\\<exists> l ty pt m. \n          Note l ty pt \\<in> set done \\<and> Note l ty pt \\<notin> skipped \\<and> \n          Some m = inst s i pt \\<and> \n          decrChain [] t {St (i, Note l ty pt)} m m'\n       )\n    ) \\<or>\n   (\\<exists> a. m' = SK a \\<and> LKR a \\<prec> Ln m') \\<or>\n   (\\<exists> a b. m' = K a b \\<and> LKR a \\<prec> Ln m') \\<or>\n   (\\<exists> a b. m' = K a b \\<and> LKR b \\<prec> Ln m') \\<or> \n   (\\<exists> A. \\<exists> a \\<in> A. m' = KShr A \\<and> LKR (LAg a) \\<prec> Ln m')\n   \"\n    (is \"?ik0_raw \\<or> ?hash_raw \\<or> ?encr_raw \\<or> ?tup_raw \\<or> ?decr_raw \\<or> ?note_raw \\<or> ?keys_raw\")\n    by (rule knows_cases_raw)\n  moreover \n  {\n    assume \"?ik0_raw\" \n    hence ?thesis by( simp add: remove_hints)\n  }\n  moreover \n  {\n    assume \"?hash_raw\" \n    hence ?thesis by( simp add: remove_hints)\n  }\n  moreover \n  {\n    assume \"?encr_raw\" \n    hence ?thesis by( simp add: remove_hints)\n  }\n  moreover \n  {\n    assume \"?tup_raw\" \n    hence ?thesis by( simp add: remove_hints)\n  }\n  moreover \n  {\n    assume \"?keys_raw\" \n    hence ?thesis by( simp add: remove_hints)\n  }\n  moreover\n  { assume ?decr_raw then\n    obtain i \"done\" todo l msg skipped m\n      where thread_exists: \"r i = Some (done, todo,skipped)\"\n      and send_done: \"Send l msg \\<in> set done\"\n      and msg:       \"Some m = inst s i msg\"\n      and decrChain: \"decrChain [] t {St (i, Send l msg)} m m'\"\n      by fast\n    then interpret th1: typed_thread P t r s i \"done\" todo skipped \"typing\"\n      using approximates by unfold_locales\n    from send_done have send_step: \"(i, Send l msg) \\<in> steps t\" \n      by (rule th1.in_steps_send[THEN iffD1])\n    moreover\n    have \"prefixClose s t (done@todo) (Send l msg) i\" using send_step\n      by(auto intro!: prefixCloseI th1.roleMap)\n    moreover\n    have send_in_role: \"Send l msg \\<in> set (done @ todo)\"\n      using send_done by simp\n    moreover\n    note in_approxD[OF th1.approximates send_step th1.roleMap, simplified]\n    ultimately\n    have ?decr using decrChain msg\n      apply -\n      apply(rule bexI[OF _ th1.role_in_P])\n      apply(rule exI)\n      apply(rule conjI[OF th1.roleMap])\n      apply(rule bexI[OF _ send_in_role])\n      by(auto simp: remove_hints)\n    hence ?thesis by blast \n  }\n  moreover\n  {\n    assume ?note_raw\n    then obtain i \"done\" todo skipped l ty pt m\n      where thread_exists: \"r i = Some (done, todo,skipped)\"\n      and inDone: \"Note l ty pt \\<in> set done\"\n      and notinSkipped:  \"Note l ty pt \\<notin> skipped\"\n      and msg:       \"Some m = inst s i pt\"\n      and decrChain: \"decrChain [] t {St (i, Note l ty pt)} m m'\"\n      by fast\n    then interpret th1: typed_thread P t r s i \"done\" todo skipped \"typing\"\n      using approximates by unfold_locales\n    from inDone and notinSkipped have note_step: \"(i, Note l ty pt) \\<in> steps t\" \n      by (fastforce dest!: th1.in_steps_eq_in_done)\n    moreover\n    have \"prefixClose s t (done@todo) (Note l ty pt) i\" using note_step\n      by(auto intro!: prefixCloseI th1.roleMap)\n    moreover\n    have note_in_role: \"Note l ty pt \\<in> set (done @ todo)\"\n      using inDone by simp\n    moreover\n    note in_approxD[OF th1.approximates note_step th1.roleMap, simplified]\n    ultimately\n    have ?decr using decrChain msg\n      apply -\n      apply(rule bexI[OF _ th1.role_in_P])\n      apply(rule exI)+\n      apply(rule conjI[OF th1.roleMap])\n      apply(rule bexI[OF _ note_in_role])\n      by(auto simp: remove_hints)\n    hence ?thesis by blast \n  }\n  ultimately\n  show ?thesis by fastforce\nqed\n\n\nlemma (in reachable_state) decrChain_AgentE:\n  assumes decrChain: \"decrChain path t from m m'\"\n  and         Agent: \"m \\<in> Agent\"\n  and      nonempty: \"from = {} \\<Longrightarrow> Q\"\n  shows \"Q\"\n  using decrChain Agent nonempty\n  by (auto simp: Agent_def)\n\n(*\nlemma (in reachable_state) decrChain_AgentTE:\n  assumes decrChain: \"decrChain path t from m m'\"\n  and        AgentT: \"m \\<in> AgentT i (t,r,s)\" \n  and          elim: \"m = m' \\<Longrightarrow> Q\"\n  shows \"Q\"\n  using decrChain AgentT elim\n  by (auto simp: AgentT_def)\n*)\n\nlemma (in reachable_state) decrChain_imp_predOrd:\n  \"\\<lbrakk> decrChain path t from m m' \\<rbrakk> \\<Longrightarrow>\n  \\<exists> im \\<in> pairParts m. (\\<forall> f \\<in> from. f \\<prec> Ln im) \\<and> Ln im \\<preceq> Ln m'\"\nproof(induct m arbitrary: path \"from\")\n  case (Tup x y) thus ?case\n    apply(simp)\n    apply(erule disjE)\n    apply(clarsimp)\n    apply(rule disjI2)\n    apply(fastforce intro: less_le_trans)\n    done\nqed fastforce+\n\nlemma (in reachable_state) decrChain_KnownT:\n  assumes decrChain: \"decrChain path t from m m'\"\n  and        KnownT: \"predOrd t (Ln m) (St (i, step))\"\n  shows \"\\<exists> im \\<in> pairParts m. \n           (\\<forall> f \\<in> from. f \\<prec> Ln im) \\<and> Ln im \\<prec> St (i, step)\"\nproof -\n  obtain im\n    where \"im \\<in> pairParts m\" and \"\\<forall>f \\<in> from. f \\<prec> Ln im\"\n    using decrChain by (fast dest!: decrChain_imp_predOrd)\n  with KnownT show ?thesis\n    by (fastforce intro: pairParts_before)\nqed\n\nlemma (in reachable_state) decrChain_KnownTE:\n  assumes decrChain: \"decrChain path t from m m'\"\n  and        KnownT: \"predOrd t (Ln m) (St (i, step))\"\n  and elim: \"\\<And> im. \\<lbrakk> im \\<in> pairParts m; \n                      \\<forall> f \\<in> from. f \\<prec> Ln im;\n                      Ln im \\<prec> St (i, step)\n                    \\<rbrakk> \\<Longrightarrow> Q\"\n  shows \"Q\"\n  using decrChain KnownT\n  by(auto dest!: decrChain_KnownT elim)\n\nlemma (in reachable_state) decrChain_SumT_KnownTE:\n  assumes KnownT: \"m \\<in> SumT (KnownT step) ty i (t,r,s)\" \n  and  decrChain: \"decrChain path t from m m'\"\n  and elimK: \"\\<And> im. \\<lbrakk> im \\<in> pairParts m; \n                       \\<forall> f \\<in> from. f \\<prec> Ln im;\n                       Ln im \\<prec> St (i, step)\n                     \\<rbrakk> \\<Longrightarrow> Q\"\n  and elimTy: \"m \\<in> ty i (t,r,s) \\<Longrightarrow> Q\"\n  shows \"Q\"\n  using decrChain KnownT elimK elimTy\n  by(auto elim!: in_SumTE decrChain_KnownTE)\n\n\nlemma (in reachable_state) AV_in_Agent [iff]: \n  \"s (AV a aTid) \\<in> Agent\"\nusing inst_AVar_cases \nby (auto simp: Agent_def)\n\n\nend\n\n(* TODO: \n    - Remove agent variables from protocol model by \n      replacing them with type annotations. \n\n      [General version will require us to reintroduce create event.\n       But composition becomes nicer, as we can now model protocols, which\n       use parameters that are secret values and so on.\n      ]\n\n\n    - Put decryption chain case into recursion of chain\n      predicate to make more information available locally.\n*)\n\n\n", "meta": {"author": "meiersi", "repo": "scyther-proof", "sha": "84e42366a46f66f1b090651be3bfaa3497696280", "save_path": "github-repos/isabelle/meiersi-scyther-proof", "path": "github-repos/isabelle/meiersi-scyther-proof/scyther-proof-84e42366a46f66f1b090651be3bfaa3497696280/data/isabelle/src/ESPLogic/WeakTyping.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.281132419524212}}
{"text": "section \\<open>Security\\<close>\n\ntheory Constructive_Cryptography imports\n  Wiring\nbegin\n\ndefinition \"advantage \\<A> res1 res2 = \\<bar>spmf (connect \\<A> res1) True - spmf (connect \\<A> res2) True\\<bar>\"\n\nlocale constructive_security_aux =\n  fixes real_resource :: \"security \\<Rightarrow> ('a + 'e, 'b + 'f) resource\"\n    and ideal_resource :: \"security \\<Rightarrow> ('c + 'e, 'd + 'f) resource\"\n    and sim :: \"security \\<Rightarrow> ('a, 'b, 'c, 'd) converter\"\n    and \\<I>_real :: \"security \\<Rightarrow> ('a, 'b) \\<I>\"\n    and \\<I>_ideal :: \"security \\<Rightarrow> ('c, 'd) \\<I>\"\n    and \\<I>_common :: \"security \\<Rightarrow> ('e, 'f) \\<I>\"\n    and bound :: \"security \\<Rightarrow> enat\"\n    and lossless :: \"bool\"\n  assumes WT_real [WT_intro]: \"\\<And>\\<eta>. \\<I>_real \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>res real_resource \\<eta> \\<surd>\"\n    and WT_ideal [WT_intro]: \"\\<And>\\<eta>. \\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>res ideal_resource \\<eta> \\<surd>\"\n    and WT_sim [WT_intro]: \"\\<And>\\<eta>. \\<I>_real \\<eta>, \\<I>_ideal \\<eta> \\<turnstile>\\<^sub>C sim \\<eta> \\<surd>\"\n    and adv: \"\\<And>\\<A> :: security \\<Rightarrow> ('a + 'e, 'b + 'f) distinguisher. \n    \\<lbrakk> \\<And>\\<eta>. \\<I>_real \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g \\<A> \\<eta> \\<surd>; \n      \\<And>\\<eta>. interaction_bounded_by (\\<lambda>_. True) (\\<A> \\<eta>) (bound \\<eta>);\n      \\<And>\\<eta>. lossless \\<Longrightarrow> plossless_gpv (\\<I>_real \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) (\\<A> \\<eta>) \\<rbrakk>\n    \\<Longrightarrow> negligible (\\<lambda>\\<eta>. advantage (\\<A> \\<eta>) (sim \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> ideal_resource \\<eta>) (real_resource \\<eta>))\"\n\n\nlocale constructive_security =\n  constructive_security_aux real_resource ideal_resource sim \\<I>_real \\<I>_ideal \\<I>_common bound lossless\n  for real_resource :: \"security \\<Rightarrow> ('a + 'e, 'b + 'f) resource\"\n    and ideal_resource :: \"security \\<Rightarrow> ('c + 'e, 'd + 'f) resource\"\n    and sim :: \"security \\<Rightarrow> ('a, 'b, 'c, 'd) converter\"\n    and \\<I>_real :: \"security \\<Rightarrow> ('a, 'b) \\<I>\"\n    and \\<I>_ideal :: \"security \\<Rightarrow> ('c, 'd) \\<I>\"\n    and \\<I>_common :: \"security \\<Rightarrow> ('e, 'f) \\<I>\"\n    and bound :: \"security \\<Rightarrow> enat\"\n    and lossless :: \"bool\"\n    and w :: \"security \\<Rightarrow> ('c, 'd, 'a, 'b) wiring\"\n  +\n  assumes correct: \"\\<exists>cnv. \\<forall>\\<D> :: security \\<Rightarrow> ('c + 'e, 'd + 'f) distinguisher.\n    (\\<forall>\\<eta>. \\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g \\<D> \\<eta> \\<surd>) \n  \\<longrightarrow> (\\<forall>\\<eta>. interaction_bounded_by (\\<lambda>_. True) (\\<D> \\<eta>) (bound \\<eta>))\n  \\<longrightarrow> (\\<forall>\\<eta>. lossless \\<longrightarrow> plossless_gpv (\\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) (\\<D> \\<eta>))\n  \\<longrightarrow> (\\<forall>\\<eta>. wiring (\\<I>_ideal \\<eta>) (\\<I>_real \\<eta>) (cnv \\<eta>) (w \\<eta>)) \\<and>\n       negligible (\\<lambda>\\<eta>. advantage (\\<D> \\<eta>) (ideal_resource \\<eta>) (cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real_resource \\<eta>))\"\n\nlocale constructive_security2 =\n  constructive_security_aux real_resource ideal_resource sim \\<I>_real \\<I>_ideal \\<I>_common bound lossless\n  for real_resource :: \"security \\<Rightarrow> ('a + 'e, 'b + 'f) resource\"\n    and ideal_resource :: \"security \\<Rightarrow> ('c + 'e, 'd + 'f) resource\"\n    and sim :: \"security \\<Rightarrow> ('a, 'b, 'c, 'd) converter\"\n    and \\<I>_real :: \"security \\<Rightarrow> ('a, 'b) \\<I>\"\n    and \\<I>_ideal :: \"security \\<Rightarrow> ('c, 'd) \\<I>\"\n    and \\<I>_common :: \"security \\<Rightarrow> ('e, 'f) \\<I>\"\n    and bound :: \"security \\<Rightarrow> enat\"\n    and lossless :: \"bool\"\n    and w :: \"security \\<Rightarrow> ('c, 'd, 'a, 'b) wiring\"\n  +\n  assumes sim: \"\\<exists>cnv. \\<forall>\\<eta>. wiring (\\<I>_ideal \\<eta>) (\\<I>_real \\<eta>) (cnv \\<eta>) (w \\<eta>) \\<and> wiring (\\<I>_ideal \\<eta>) (\\<I>_ideal \\<eta>) (cnv \\<eta> \\<odot> sim \\<eta>) (id, id)\"\nbegin\n\nlemma constructive_security:\n  \"constructive_security real_resource ideal_resource sim \\<I>_real \\<I>_ideal \\<I>_common bound lossless w\"\nproof\n  from sim obtain cnv\n    where w: \"\\<And>\\<eta>. wiring (\\<I>_ideal \\<eta>) (\\<I>_real \\<eta>) (cnv \\<eta>) (w \\<eta>)\"\n      and inverse: \"\\<And>\\<eta>. wiring (\\<I>_ideal \\<eta>) (\\<I>_ideal \\<eta>) (cnv \\<eta> \\<odot> sim \\<eta>) (id, id)\"\n    by blast\n  show \"\\<exists>cnv. \\<forall>\\<D>. (\\<forall>\\<eta>. \\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g \\<D> \\<eta> \\<surd>)\n    \\<longrightarrow> (\\<forall>\\<eta>. interaction_any_bounded_by (\\<D> \\<eta>) (bound \\<eta>))\n    \\<longrightarrow> (\\<forall>\\<eta>. lossless \\<longrightarrow> plossless_gpv (\\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) (\\<D> \\<eta>))\n    \\<longrightarrow> (\\<forall>\\<eta>. wiring (\\<I>_ideal \\<eta>) (\\<I>_real \\<eta>) (cnv \\<eta>) (w \\<eta>)) \\<and>\n        negligible (\\<lambda>\\<eta>. advantage (\\<D> \\<eta>) (ideal_resource \\<eta>) (cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real_resource \\<eta>))\"\n  proof(intro strip exI conjI)\n    fix \\<D> :: \"security \\<Rightarrow> ('c + 'e, 'd + 'f) distinguisher\"\n    assume WT_D [rule_format, WT_intro]: \"\\<forall>\\<eta>. \\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g \\<D> \\<eta> \\<surd>\"\n      and bound [rule_format, interaction_bound]: \"\\<forall>\\<eta>. interaction_bounded_by (\\<lambda>_. True) (\\<D> \\<eta>) (bound \\<eta>)\"\n      and lossless [rule_format]: \"\\<forall>\\<eta>. lossless \\<longrightarrow> plossless_gpv (\\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) (\\<D> \\<eta>)\"\n    \n    show \"wiring (\\<I>_ideal \\<eta>) (\\<I>_real \\<eta>) (cnv \\<eta>) (w \\<eta>)\" for \\<eta> by fact\n\n    let ?A = \"\\<lambda>\\<eta>. outs_\\<I> (\\<I>_ideal \\<eta>)\"\n    let ?cnv = \"\\<lambda>\\<eta>. restrict_converter (?A \\<eta>) (\\<I>_real \\<eta>) (cnv \\<eta>)\"\n    let ?\\<A> = \"\\<lambda>\\<eta>. absorb (\\<D> \\<eta>) (?cnv \\<eta> |\\<^sub>= 1\\<^sub>C)\"\n\n    have eq: \"advantage (\\<D> \\<eta>) (ideal_resource \\<eta>) (cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real_resource \\<eta>) =\n    advantage (?\\<A> \\<eta>) (sim \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> ideal_resource \\<eta>) (real_resource \\<eta>)\" for \\<eta>\n    proof -\n      from w[of \\<eta>] have [WT_intro]: \"\\<I>_ideal \\<eta>, \\<I>_real \\<eta> \\<turnstile>\\<^sub>C cnv \\<eta> \\<surd>\" by cases\n      have \"\\<I>_ideal \\<eta>, \\<I>_ideal \\<eta> \\<turnstile>\\<^sub>C ?cnv \\<eta> \\<odot> sim \\<eta> \\<sim> cnv \\<eta> \\<odot> sim \\<eta>\"\n        by(rule eq_\\<I>_comp_cong eq_\\<I>_restrict_converter WT_intro order_refl eq_\\<I>_converter_reflI)+\n      also from inverse[of \\<eta>] have \"\\<I>_ideal \\<eta>, \\<I>_ideal \\<eta> \\<turnstile>\\<^sub>C cnv \\<eta> \\<odot> sim \\<eta> \\<sim> 1\\<^sub>C\" by cases simp\n      finally have inverse': \"\\<I>_ideal \\<eta>, \\<I>_ideal \\<eta> \\<turnstile>\\<^sub>C ?cnv \\<eta> \\<odot> sim \\<eta> \\<sim> 1\\<^sub>C\" .\n      hence \"\\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>, \\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>\\<^sub>C ?cnv \\<eta> \\<odot> sim \\<eta> |\\<^sub>= 1\\<^sub>C \\<sim> 1\\<^sub>C |\\<^sub>= 1\\<^sub>C\"\n        by(rule parallel_converter2_eq_\\<I>_cong)(intro eq_\\<I>_converter_reflI WT_intro)\n      also have \"\\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>, \\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>\\<^sub>C 1\\<^sub>C |\\<^sub>= 1\\<^sub>C \\<sim> 1\\<^sub>C\"\n        by(rule parallel_converter2_id_id)\n      also\n      have eq1: \"connect (\\<D> \\<eta>) (?cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> sim \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> ideal_resource \\<eta>) = \n        connect (\\<D> \\<eta>) (1\\<^sub>C \\<rhd> ideal_resource \\<eta>)\"\n        unfolding attach_compose[symmetric] comp_converter_parallel2 comp_converter_id_right\n        by(rule connect_eq_resource_cong WT_intro eq_\\<I>_attach_on' calculation)+(fastforce intro: WT_intro)+\n\n      have *: \"\\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>, \\<I>_real \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>\\<^sub>C ?cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<sim> cnv \\<eta> |\\<^sub>= 1\\<^sub>C\"\n        by(rule parallel_converter2_eq_\\<I>_cong eq_\\<I>_restrict_converter)+(auto intro: WT_intro eq_\\<I>_converter_reflI)\n      have eq2: \"connect (\\<D> \\<eta>) (?cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real_resource \\<eta>) = connect (\\<D> \\<eta>) (cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real_resource \\<eta>)\"\n        by(rule connect_eq_resource_cong WT_intro eq_\\<I>_attach_on' *)+(auto intro: WT_intro)\n      show ?thesis unfolding advantage_def by(simp add: distinguish_attach[symmetric] eq1 eq2)\n    qed\n    have \"\\<I>_real \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g ?\\<A> \\<eta> \\<surd>\" for \\<eta>\n    proof -\n      from w have [WT_intro]: \"\\<I>_ideal \\<eta>, \\<I>_real \\<eta> \\<turnstile>\\<^sub>C cnv \\<eta> \\<surd>\" by cases\n      show ?thesis by(rule WT_intro)+\n    qed\n    moreover\n    have \"interaction_any_bounded_by (absorb (\\<D> \\<eta>) (?cnv \\<eta> |\\<^sub>= 1\\<^sub>C)) (bound \\<eta>)\" for \\<eta>\n    proof -\n      from w[of \\<eta>] obtain f g where [simp]: \"w \\<eta> = (f, g)\"\n        and [WT_intro]: \"\\<I>_ideal \\<eta>, \\<I>_real \\<eta> \\<turnstile>\\<^sub>C cnv \\<eta> \\<surd>\"\n        and eq: \"\\<I>_ideal \\<eta>, \\<I>_real \\<eta> \\<turnstile>\\<^sub>C cnv \\<eta> \\<sim> map_converter id id f g 1\\<^sub>C\" by cases\n      from eq_\\<I>_restrict_converter_cong[OF eq order_refl]\n      have *: \"restrict_converter (?A \\<eta>) (\\<I>_real \\<eta>) (cnv \\<eta>) =\n      restrict_converter (?A \\<eta>) (\\<I>_real \\<eta>) (map_converter f g id id 1\\<^sub>C)\"\n        by(subst map_converter_id_move_right) simp\n      show ?thesis unfolding * by interaction_bound_converter simp\n    qed\n    moreover have \"plossless_gpv (\\<I>_real \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) (?\\<A> \\<eta>)\"\n      if \"lossless\" for \\<eta> \n    proof -\n      from w[of \\<eta>] obtain f g where [simp]: \"w \\<eta> = (f, g)\"\n        and cnv [WT_intro]: \"\\<I>_ideal \\<eta>, \\<I>_real \\<eta> \\<turnstile>\\<^sub>C cnv \\<eta> \\<surd>\"\n        and eq: \"\\<I>_ideal \\<eta>, \\<I>_real \\<eta> \\<turnstile>\\<^sub>C cnv \\<eta> \\<sim> map_converter id id f g 1\\<^sub>C\" by cases\n      from eq_\\<I>_converterD_WT1[OF eq cnv] have \\<I>: \"\\<I>_ideal \\<eta> \\<le> map_\\<I> f g (\\<I>_real \\<eta>)\"\n        by(rule WT_map_converter_idD)\n      with WT_converter_id have [WT_intro]: \"\\<I>_ideal \\<eta>, map_\\<I> f g (\\<I>_real \\<eta>) \\<turnstile>\\<^sub>C 1\\<^sub>C \\<surd>\" \n        by(rule WT_converter_mono) simp\n      have id: \"plossless_converter (\\<I>_ideal \\<eta>) (map_\\<I> f g (\\<I>_real \\<eta>)) 1\\<^sub>C\"\n        by(rule plossless_converter_mono)(rule plossless_id_converter order_refl \\<I> WT_intro)+\n      show ?thesis unfolding eq_\\<I>_restrict_converter_cong[OF eq order_refl]\n        by(rule plossless_gpv_absorb lossless[OF that] plossless_parallel_converter2 plossless_restrict_converter plossless_map_converter)+\n          (fastforce intro: WT_intro id WT_converter_map_converter)+\n    qed\n    ultimately show \"negligible (\\<lambda>\\<eta>. advantage (\\<D> \\<eta>) (ideal_resource \\<eta>) (cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real_resource \\<eta>))\"\n      unfolding eq by(rule adv)\n  qed\nqed\n\nsublocale constructive_security real_resource ideal_resource sim \\<I>_real \\<I>_ideal \\<I>_common bound lossless w\n  by(rule constructive_security)\n\nend\n\nsubsection \\<open>Composition theorems\\<close>\n\ntheorem composability:\n  fixes real\n  assumes \"constructive_security middle ideal sim_inner \\<I>_middle \\<I>_inner \\<I>_common bound_inner lossless_inner w1\"\n  assumes \"constructive_security real middle sim_outer \\<I>_real \\<I>_middle \\<I>_common bound_outer lossless_outer w2\"\n  and bound [interaction_bound]: \"\\<And>\\<eta>. interaction_any_bounded_converter (sim_outer \\<eta>) (bound_sim \\<eta>)\"\n  and bound_le: \"\\<And>\\<eta>. bound_outer \\<eta> * max (bound_sim \\<eta>) 1 \\<le> bound_inner \\<eta>\"\n  and lossless_sim [plossless_intro]: \"\\<And>\\<eta>. lossless_inner \\<Longrightarrow> plossless_converter (\\<I>_real \\<eta>) (\\<I>_middle \\<eta>) (sim_outer \\<eta>)\"\n  shows \"constructive_security real ideal (\\<lambda>\\<eta>. sim_outer \\<eta> \\<odot> sim_inner \\<eta>) \\<I>_real \\<I>_inner \\<I>_common bound_outer (lossless_outer \\<or> lossless_inner) (\\<lambda>\\<eta>. w1 \\<eta> \\<circ>\\<^sub>w w2 \\<eta>)\"\nproof\n  interpret inner: constructive_security middle ideal sim_inner \\<I>_middle \\<I>_inner \\<I>_common bound_inner lossless_inner w1 by fact\n  interpret outer: constructive_security real middle sim_outer \\<I>_real \\<I>_middle \\<I>_common bound_outer lossless_outer w2 by fact\n\n  show \"\\<I>_real \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>res real \\<eta> \\<surd>\"\n    and \"\\<I>_inner \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>res ideal \\<eta> \\<surd>\"\n    and \"\\<I>_real \\<eta>, \\<I>_inner \\<eta> \\<turnstile>\\<^sub>C sim_outer \\<eta> \\<odot> sim_inner \\<eta> \\<surd>\" for \\<eta> by(rule WT_intro)+\n\n  { fix \\<A> :: \"security \\<Rightarrow> ('g + 'b, 'h + 'd) distinguisher\"\n    assume WT [WT_intro]: \"\\<I>_real \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g \\<A> \\<eta> \\<surd>\" for \\<eta>\n    assume bound_outer [interaction_bound]: \"interaction_bounded_by (\\<lambda>_. True) (\\<A> \\<eta>) (bound_outer \\<eta>)\" for \\<eta>\n    assume lossless [plossless_intro]:\n      \"lossless_outer \\<or> lossless_inner \\<Longrightarrow> plossless_gpv (\\<I>_real \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) (\\<A> \\<eta>)\" for \\<eta>\n\n    let ?\\<A> = \"\\<lambda>\\<eta>. absorb (\\<A> \\<eta>) (sim_outer \\<eta> |\\<^sub>= 1\\<^sub>C)\"\n    have \"\\<I>_middle \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g ?\\<A> \\<eta> \\<surd>\" for \\<eta> by(rule WT_intro)+\n    moreover have \"interaction_any_bounded_by (?\\<A> \\<eta>) (bound_inner \\<eta>)\" for \\<eta>\n      by interaction_bound_converter(rule bound_le)\n    moreover have \"plossless_gpv (\\<I>_middle \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) (?\\<A> \\<eta>)\" if lossless_inner for \\<eta>\n      by(rule plossless_intro WT_intro | simp add: that)+\n    ultimately have \"negligible (\\<lambda>\\<eta>. advantage (?\\<A> \\<eta>) (sim_inner \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> ideal \\<eta>) (middle \\<eta>))\"\n      by(rule inner.adv)\n    also have \"negligible (\\<lambda>\\<eta>. advantage (\\<A> \\<eta>) (sim_outer \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> middle \\<eta>) (real \\<eta>))\"\n      by(rule outer.adv[OF WT bound_outer lossless]) simp\n    finally (negligible_plus)\n    show \"negligible (\\<lambda>\\<eta>. advantage (\\<A> \\<eta>) (sim_outer \\<eta> \\<odot> sim_inner \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> ideal \\<eta>) (real \\<eta>))\"\n      apply(rule negligible_mono)\n      apply(simp add: bigo_def)\n      apply(rule exI[where x=1])\n      apply simp\n      apply(rule always_eventually)\n      apply(clarsimp simp add: advantage_def)\n      apply(rule order_trans)\n       apply(rule abs_diff_triangle_ineq2)\n      apply(rule add_right_mono)\n      apply(clarsimp simp add: advantage_def distinguish_attach[symmetric] attach_compose[symmetric] comp_converter_parallel2 comp_converter_id_left)\n      done\n  next\n    from inner.correct obtain cnv_inner\n      where correct_inner: \"\\<And>\\<D>. \\<lbrakk> \\<And>\\<eta>. \\<I>_inner \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g \\<D> \\<eta> \\<surd>;\n             \\<And>\\<eta>. interaction_any_bounded_by (\\<D> \\<eta>) (bound_inner \\<eta>);\n             \\<And>\\<eta>. lossless_inner \\<Longrightarrow> plossless_gpv (\\<I>_inner \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) (\\<D> \\<eta>) \\<rbrakk>\n           \\<Longrightarrow> (\\<forall>\\<eta>. wiring (\\<I>_inner \\<eta>) (\\<I>_middle \\<eta>) (cnv_inner \\<eta>) (w1 \\<eta>)) \\<and>\n               negligible (\\<lambda>\\<eta>. advantage (\\<D> \\<eta>) (ideal \\<eta>) (cnv_inner \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> middle \\<eta>))\"\n      by blast\n    from outer.correct obtain cnv_outer\n      where correct_outer: \"\\<And>\\<D>. \\<lbrakk> \\<And>\\<eta>. \\<I>_middle \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g \\<D> \\<eta> \\<surd>;\n             \\<And>\\<eta>. interaction_any_bounded_by (\\<D> \\<eta>) (bound_outer \\<eta>);\n             \\<And>\\<eta>. lossless_outer \\<Longrightarrow> plossless_gpv (\\<I>_middle \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) (\\<D> \\<eta>) \\<rbrakk>\n           \\<Longrightarrow> (\\<forall>\\<eta>. wiring (\\<I>_middle \\<eta>) (\\<I>_real \\<eta>) (cnv_outer \\<eta>) (w2 \\<eta>)) \\<and>\n               negligible (\\<lambda>\\<eta>. advantage (\\<D> \\<eta>) (middle \\<eta>) (cnv_outer \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real \\<eta>))\"\n      by blast\n    show \"\\<exists>cnv. \\<forall>\\<D>. (\\<forall>\\<eta>. \\<I>_inner \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g \\<D> \\<eta> \\<surd>) \\<longrightarrow>\n               (\\<forall>\\<eta>. interaction_any_bounded_by (\\<D> \\<eta>) (bound_outer \\<eta>)) \\<longrightarrow>\n               (\\<forall>\\<eta>. lossless_outer \\<or> lossless_inner \\<longrightarrow> plossless_gpv (\\<I>_inner \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) (\\<D> \\<eta>)) \\<longrightarrow>\n               (\\<forall>\\<eta>. wiring (\\<I>_inner \\<eta>) (\\<I>_real \\<eta>) (cnv \\<eta>) (w1 \\<eta> \\<circ>\\<^sub>w w2 \\<eta>)) \\<and>\n               negligible (\\<lambda>\\<eta>. advantage (\\<D> \\<eta>) (ideal \\<eta>) (cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real \\<eta>))\"\n    proof(intro exI strip conjI)\n      fix \\<D> :: \"security \\<Rightarrow> ('e + 'b, 'f + 'd) distinguisher\"\n      assume WT_D [rule_format, WT_intro]: \"\\<forall>\\<eta>. \\<I>_inner \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g \\<D> \\<eta> \\<surd>\"\n        and bound [rule_format, interaction_bound]: \"\\<forall>\\<eta>. interaction_bounded_by (\\<lambda>_. True) (\\<D> \\<eta>) (bound_outer \\<eta>)\"\n        and lossless [rule_format]: \"\\<forall>\\<eta>. lossless_outer \\<or> lossless_inner \\<longrightarrow> plossless_gpv (\\<I>_inner \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) (\\<D> \\<eta>)\"\n\n      let ?cnv = \"\\<lambda>\\<eta>. cnv_inner \\<eta> \\<odot> cnv_outer \\<eta>\"\n\n      have bound': \"interaction_any_bounded_by (\\<D> \\<eta>) (bound_inner \\<eta>)\" for \\<eta> using bound[of \\<eta>] bound_le[of \\<eta>]\n        by(clarsimp elim!: interaction_bounded_by_mono order_trans[rotated] simp add: max_def)\n          (metis (full_types) linorder_linear more_arith_simps(6) mult_left_mono zero_le)\n      from correct_inner[OF WT_D bound' lossless]\n      have w1: \"\\<And>\\<eta>. wiring (\\<I>_inner \\<eta>) (\\<I>_middle \\<eta>) (cnv_inner \\<eta>) (w1 \\<eta>)\"\n        and adv1: \"negligible (\\<lambda>\\<eta>. advantage (\\<D> \\<eta>) (ideal \\<eta>) (cnv_inner \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> middle \\<eta>))\"\n        by auto\n\n      obtain f g where WT_inner [WT_intro]: \"\\<And>\\<eta>. \\<I>_inner \\<eta>, \\<I>_middle \\<eta> \\<turnstile>\\<^sub>C cnv_inner \\<eta> \\<surd>\"\n        and fg [simp]: \"\\<And>\\<eta>. w1 \\<eta> = (f \\<eta>, g \\<eta>)\"\n        and eq1: \"\\<And>\\<eta>. \\<I>_inner \\<eta>, \\<I>_middle \\<eta> \\<turnstile>\\<^sub>C cnv_inner \\<eta> \\<sim> map_converter id id (f \\<eta>) (g \\<eta>) 1\\<^sub>C\"\n        using w1\n        apply(atomize_elim)\n        apply(fold all_conj_distrib)\n        apply(subst choice_iff[symmetric])+\n        apply(fastforce elim!: wiring.cases)\n        done\n\n      from w1 have [WT_intro]: \"\\<I>_inner \\<eta>, \\<I>_middle \\<eta> \\<turnstile>\\<^sub>C cnv_inner \\<eta> \\<surd>\" for \\<eta> by cases\n\n      let ?\\<D> = \"\\<lambda>\\<eta>. absorb (\\<D> \\<eta>) (map_converter id id (f \\<eta>) (g \\<eta>) 1\\<^sub>C |\\<^sub>= 1\\<^sub>C)\"\n      have \\<I>: \"\\<I>_inner \\<eta> \\<le> map_\\<I> (f \\<eta>) (g \\<eta>) (\\<I>_middle \\<eta>)\" for \\<eta>\n        using eq_\\<I>_converterD_WT1[OF eq1 WT_inner, of \\<eta>] by(rule WT_map_converter_idD)\n      with WT_converter_id have [WT_intro]: \"\\<I>_inner \\<eta>, map_\\<I> (f \\<eta>) (g \\<eta>) (\\<I>_middle \\<eta>) \\<turnstile>\\<^sub>C 1\\<^sub>C \\<surd>\" \n        for \\<eta> by(rule WT_converter_mono) simp\n\n      have WT_D': \"\\<I>_middle \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g ?\\<D> \\<eta> \\<surd>\" for \\<eta> by(rule WT_intro | simp)+\n      have bound': \"interaction_any_bounded_by (?\\<D> \\<eta>) (bound_outer \\<eta>)\" for \\<eta>\n        by(subst map_converter_id_move_left)(interaction_bound; simp)\n      have [simp]: \"plossless_converter (\\<I>_inner \\<eta>) (map_\\<I> (f \\<eta>) (g \\<eta>) (\\<I>_middle \\<eta>)) 1\\<^sub>C \" for \\<eta>\n        using plossless_id_converter _ \\<I>[of \\<eta>] by(rule plossless_converter_mono) auto\n      from lossless\n      have \"plossless_gpv (\\<I>_middle \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) (?\\<D> \\<eta>)\" if lossless_outer for \\<eta>\n        by(rule plossless_gpv_absorb)(auto simp add: that intro!: WT_intro plossless_parallel_converter2 plossless_map_converter)\n      from correct_outer[OF WT_D' bound' this]\n      have w2: \"\\<And>\\<eta>. wiring (\\<I>_middle \\<eta>) (\\<I>_real \\<eta>) (cnv_outer \\<eta>) (w2 \\<eta>)\"\n        and adv2: \"negligible (\\<lambda>\\<eta>. advantage (?\\<D> \\<eta>) (middle \\<eta>) (cnv_outer \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real \\<eta>))\"\n        by auto\n      from w2 have [WT_intro]: \"\\<I>_middle \\<eta>, \\<I>_real \\<eta> \\<turnstile>\\<^sub>C cnv_outer \\<eta> \\<surd>\" for \\<eta> by cases\n\n      show \"wiring (\\<I>_inner \\<eta>) (\\<I>_real \\<eta>) (?cnv \\<eta>) (w1 \\<eta> \\<circ>\\<^sub>w w2 \\<eta>)\" for \\<eta>\n        using w1 w2 by(rule wiring_comp_converterI)\n\n      have eq1': \"connect (\\<D> \\<eta>) (cnv_inner \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> middle \\<eta>) = connect (?\\<D> \\<eta>) (middle \\<eta>)\" for \\<eta>\n        unfolding distinguish_attach[symmetric]\n        by(rule connect_eq_resource_cong WT_intro eq_\\<I>_attach_on' parallel_converter2_eq_\\<I>_cong eq1 eq_\\<I>_converter_reflI order_refl)+\n      have eq2': \"connect (?\\<D> \\<eta>) (cnv_outer \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real \\<eta>) = connect (\\<D> \\<eta>) (?cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<odot> 1\\<^sub>C \\<rhd> real \\<eta>)\" for \\<eta>\n        unfolding distinguish_attach[symmetric] attach_compose comp_converter_parallel2[symmetric]\n        by(rule connect_eq_resource_cong WT_intro eq_\\<I>_attach_on' parallel_converter2_eq_\\<I>_cong eq1[symmetric] eq_\\<I>_converter_reflI order_refl|simp)+\n\n      show \"negligible (\\<lambda>\\<eta>. advantage (\\<D> \\<eta>) (ideal \\<eta>) (?cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real \\<eta>))\"\n        using negligible_plus[OF adv1 adv2] unfolding advantage_def eq1' eq2' comp_converter_id_right\n        by(rule negligible_le) simp\n    qed\n  }\nqed\n\ntheorem (in constructive_security) lifting:\n  assumes WT_conv [WT_intro]: \"\\<And>\\<eta>. \\<I>_common' \\<eta>, \\<I>_common \\<eta> \\<turnstile>\\<^sub>C conv \\<eta> \\<surd>\"\n    and bound [interaction_bound]: \"\\<And>\\<eta>. interaction_any_bounded_converter (conv \\<eta>) (bound_conv \\<eta>)\"\n    and bound_le: \"\\<And>\\<eta>. bound' \\<eta> * max (bound_conv \\<eta>) 1 \\<le> bound \\<eta>\"\n    and lossless [plossless_intro]: \"\\<And>\\<eta>. lossless \\<Longrightarrow> plossless_converter (\\<I>_common' \\<eta>) (\\<I>_common \\<eta>) (conv \\<eta>)\"\n  shows \"constructive_security\n     (\\<lambda>\\<eta>. 1\\<^sub>C |\\<^sub>= conv \\<eta> \\<rhd> real_resource \\<eta>) (\\<lambda>\\<eta>. 1\\<^sub>C |\\<^sub>= conv \\<eta> \\<rhd> ideal_resource \\<eta>) sim\n     \\<I>_real \\<I>_ideal \\<I>_common' bound' lossless w\"\nproof\n  fix \\<A> :: \"security \\<Rightarrow> ('a + 'g, 'b + 'h) distinguisher\"\n  assume WT_\\<A> [WT_intro]: \"\\<I>_real \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common' \\<eta> \\<turnstile>g \\<A> \\<eta> \\<surd>\" for \\<eta>\n  assume bound_\\<A> [interaction_bound]: \"interaction_any_bounded_by (\\<A> \\<eta>) (bound' \\<eta>)\" for \\<eta>\n  assume lossless_\\<A> [plossless_intro]: \"lossless \\<Longrightarrow> plossless_gpv (\\<I>_real \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common' \\<eta>) (\\<A> \\<eta>)\" for \\<eta>\n\n  let ?\\<A> = \"\\<lambda>\\<eta>. absorb (\\<A> \\<eta>) (1\\<^sub>C |\\<^sub>= conv \\<eta>)\"\n\n  have ideal: \"connect (\\<A> \\<eta>) (sim \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> 1\\<^sub>C |\\<^sub>= conv \\<eta> \\<rhd> ideal_resource \\<eta>) = connect (?\\<A> \\<eta>) (sim \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> ideal_resource \\<eta>)\" for \\<eta>\n    by(simp add: distinguish_attach[symmetric] attach_compose[symmetric] comp_converter_parallel2 comp_converter_id_left comp_converter_id_right)\n  have real: \"connect (\\<A> \\<eta>) (1\\<^sub>C |\\<^sub>= conv \\<eta> \\<rhd> real_resource \\<eta>) = connect (?\\<A> \\<eta>) (real_resource \\<eta>)\" for \\<eta>\n    by(simp add: distinguish_attach[symmetric])\n  have \"\\<I>_real \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g ?\\<A> \\<eta> \\<surd>\" for \\<eta> by(rule WT_intro)+\n  moreover have \"interaction_any_bounded_by (?\\<A> \\<eta>) (bound \\<eta>)\" for \\<eta>\n    by interaction_bound_converter(use bound_le[of \\<eta>] in \\<open>simp add: max.commute\\<close>)\n  moreover have \" plossless_gpv (\\<I>_real \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) (absorb (\\<A> \\<eta>) (1\\<^sub>C |\\<^sub>= conv \\<eta>))\" if lossless for \\<eta>\n    by(rule plossless_intro WT_intro | simp add: that)+\n  ultimately show \"negligible (\\<lambda>\\<eta>. advantage (\\<A> \\<eta>) (sim \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> 1\\<^sub>C |\\<^sub>= conv \\<eta> \\<rhd> ideal_resource \\<eta>) (1\\<^sub>C |\\<^sub>= conv \\<eta> \\<rhd> real_resource \\<eta>))\"\n    unfolding advantage_def ideal real by(rule adv[unfolded advantage_def])\nnext\n  from correct obtain cnv \n    where correct': \"\\<And>\\<D>. \\<lbrakk> \\<And>\\<eta>. \\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g \\<D> \\<eta> \\<surd>;\n          \\<And>\\<eta>. interaction_any_bounded_by (\\<D> \\<eta>) (bound \\<eta>);\n          \\<And>\\<eta>. lossless \\<Longrightarrow> plossless_gpv (\\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) (\\<D> \\<eta>) \\<rbrakk>\n          \\<Longrightarrow> (\\<forall>\\<eta>. wiring (\\<I>_ideal \\<eta>) (\\<I>_real \\<eta>) (cnv \\<eta>) (w \\<eta>)) \\<and>\n              negligible (\\<lambda>\\<eta>. advantage (\\<D> \\<eta>) (ideal_resource \\<eta>) (cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real_resource \\<eta>))\"\n    by blast\n  show \"\\<exists>cnv. \\<forall>\\<D>. (\\<forall>\\<eta>. \\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common' \\<eta> \\<turnstile>g \\<D> \\<eta> \\<surd>) \\<longrightarrow>\n         (\\<forall>\\<eta>. interaction_any_bounded_by (\\<D> \\<eta>) (bound' \\<eta>)) \\<longrightarrow>\n         (\\<forall>\\<eta>. lossless \\<longrightarrow> plossless_gpv (\\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common' \\<eta>) (\\<D> \\<eta>)) \\<longrightarrow>\n         (\\<forall>\\<eta>. wiring (\\<I>_ideal \\<eta>) (\\<I>_real \\<eta>) (cnv \\<eta>) (w \\<eta>)) \\<and>\n         negligible (\\<lambda>\\<eta>. advantage (\\<D> \\<eta>) (1\\<^sub>C |\\<^sub>= conv \\<eta> \\<rhd> ideal_resource \\<eta>) (cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> 1\\<^sub>C |\\<^sub>= conv \\<eta> \\<rhd> real_resource \\<eta>))\"\n  proof(intro exI conjI strip)\n    fix \\<D> :: \"security \\<Rightarrow> ('c + 'g, 'd + 'h) distinguisher\"\n    assume WT_D [rule_format, WT_intro]: \"\\<forall>\\<eta>. \\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common' \\<eta> \\<turnstile>g \\<D> \\<eta> \\<surd>\"\n      and bound [rule_format, interaction_bound]: \"\\<forall>\\<eta>. interaction_bounded_by (\\<lambda>_. True) (\\<D> \\<eta>) (bound' \\<eta>)\"\n      and lossless [rule_format]: \"\\<forall>\\<eta>. lossless \\<longrightarrow> plossless_gpv (\\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common' \\<eta>) (\\<D> \\<eta>)\"\n\n    let ?\\<D> = \"\\<lambda>\\<eta>. absorb (\\<D> \\<eta>) (1\\<^sub>C |\\<^sub>= conv \\<eta>)\"\n    have WT_D' [WT_intro]: \"\\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g ?\\<D> \\<eta> \\<surd>\" for \\<eta> by(rule WT_intro)+\n    have bound': \"interaction_any_bounded_by (?\\<D> \\<eta>) (bound \\<eta>)\" for \\<eta>\n      by interaction_bound(use bound_le[of \\<eta>] in \\<open>auto simp add: max_def split: if_split_asm\\<close>)\n    have \"plossless_gpv (\\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) (?\\<D> \\<eta>)\" if lossless for \\<eta>\n      by(rule lossless that WT_intro plossless_intro)+\n    from correct'[OF WT_D' bound' this]\n    have w1: \"wiring (\\<I>_ideal \\<eta>) (\\<I>_real \\<eta>) (cnv \\<eta>) (w \\<eta>)\" \n      and adv': \"negligible (\\<lambda>\\<eta>. advantage (?\\<D> \\<eta>) (ideal_resource \\<eta>) (cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real_resource \\<eta>))\" for \\<eta>\n      by auto\n    show \"wiring (\\<I>_ideal \\<eta>) (\\<I>_real \\<eta>) (cnv \\<eta>) (w \\<eta>)\" for \\<eta> by(rule w1)\n    have \"cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> 1\\<^sub>C |\\<^sub>= conv \\<eta> \\<rhd> real_resource \\<eta> = 1\\<^sub>C |\\<^sub>= conv \\<eta> \\<rhd> cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real_resource \\<eta>\" for \\<eta>\n      by(simp add: attach_compose[symmetric] comp_converter_parallel2 comp_converter_id_left comp_converter_id_right)\n    with adv'\n    show \"negligible (\\<lambda>\\<eta>. advantage (\\<D> \\<eta>) (1\\<^sub>C |\\<^sub>= conv \\<eta> \\<rhd> ideal_resource \\<eta>) (cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> 1\\<^sub>C |\\<^sub>= conv \\<eta> \\<rhd> real_resource \\<eta>))\"\n      by(simp add: advantage_def distinguish_attach[symmetric])\n  qed\nqed(rule WT_intro)+\n\ntheorem constructive_security_trivial:\n  fixes res\n  assumes [WT_intro]: \"\\<And>\\<eta>. \\<I> \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>res res \\<eta> \\<surd>\"\n  shows \"constructive_security res res (\\<lambda>_. 1\\<^sub>C) \\<I> \\<I> \\<I>_common bound lossless (\\<lambda>_. (id, id))\"\nproof\n  show \"\\<I> \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>res res \\<eta> \\<surd>\" and \"\\<I> \\<eta>, \\<I> \\<eta> \\<turnstile>\\<^sub>C 1\\<^sub>C \\<surd>\" for \\<eta> by(rule WT_intro)+\n\n  fix \\<A> :: \"security \\<Rightarrow> ('a + 'b, 'c + 'd) distinguisher\"\n  assume WT [WT_intro]: \"\\<I> \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g \\<A> \\<eta> \\<surd>\" for \\<eta>\n  have \"connect (\\<A> \\<eta>) (1\\<^sub>C |\\<^sub>= 1\\<^sub>C \\<rhd> res \\<eta>) = connect (\\<A> \\<eta>) (1\\<^sub>C \\<rhd> res \\<eta>)\" for \\<eta>\n    by(rule connect_eq_resource_cong[OF WT])(fastforce intro: WT_intro eq_\\<I>_attach_on' parallel_converter2_id_id)+\n  then show \"negligible (\\<lambda>\\<eta>. advantage (\\<A> \\<eta>) (1\\<^sub>C |\\<^sub>= 1\\<^sub>C \\<rhd> res \\<eta>) (res \\<eta>))\"\n    unfolding advantage_def by simp\nnext\n  show \"\\<exists>cnv. \\<forall>\\<D>. (\\<forall>\\<eta>. \\<I> \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g \\<D> \\<eta> \\<surd>) \\<longrightarrow>\n         (\\<forall>\\<eta>. interaction_any_bounded_by (\\<D> \\<eta>) (bound \\<eta>)) \\<longrightarrow>\n         (\\<forall>\\<eta>. lossless \\<longrightarrow> plossless_gpv (\\<I> \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) (\\<D> \\<eta>)) \\<longrightarrow>\n         (\\<forall>\\<eta>. wiring (\\<I> \\<eta>) (\\<I> \\<eta>) (cnv \\<eta>) (id, id)) \\<and>\n         negligible (\\<lambda>\\<eta>. advantage (\\<D> \\<eta>) (res \\<eta>) (cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> res \\<eta>))\"\n  proof(intro exI strip conjI)\n    fix \\<D> :: \"security \\<Rightarrow> ('a + 'b, 'c + 'd) distinguisher\"\n    assume WT_D [rule_format, WT_intro]: \"\\<forall>\\<eta>. \\<I> \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g \\<D> \\<eta> \\<surd>\"\n      and bound [rule_format, interaction_bound]: \"\\<forall>\\<eta>. interaction_bounded_by (\\<lambda>_. True) (\\<D> \\<eta>) (bound \\<eta>)\"\n      and lossless [rule_format]: \"\\<forall>\\<eta>. lossless \\<longrightarrow> plossless_gpv (\\<I> \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) (\\<D> \\<eta>)\"\n    show \"wiring (\\<I> \\<eta>) (\\<I> \\<eta>) 1\\<^sub>C (id, id)\" for \\<eta> by simp\n    have \"connect (\\<D> \\<eta>) (1\\<^sub>C |\\<^sub>= 1\\<^sub>C \\<rhd> res \\<eta>) = connect (\\<D> \\<eta>) (1\\<^sub>C \\<rhd> res \\<eta>)\" for \\<eta>\n      by(rule connect_eq_resource_cong)(rule WT_intro eq_\\<I>_attach_on' parallel_converter2_id_id order_refl)+\n    then show \"negligible (\\<lambda>\\<eta>. advantage (\\<D> \\<eta>) (res \\<eta>) (1\\<^sub>C |\\<^sub>= 1\\<^sub>C \\<rhd> res \\<eta>))\"\n      by(auto simp add: advantage_def)\n  qed\nqed\n\ntheorem parallel_constructive_security:\n  assumes \"constructive_security real1 ideal1 sim1 \\<I>_real1 \\<I>_inner1 \\<I>_common1 bound1 lossless1 w1\"\n  assumes \"constructive_security real2 ideal2 sim2 \\<I>_real2 \\<I>_inner2 \\<I>_common2 bound2 lossless2 w2\"\n    (* TODO: add symmetric case for lossless1/2 *)\n    and lossless_real1 [plossless_intro]: \"\\<And>\\<eta>. lossless2 \\<Longrightarrow> lossless_resource (\\<I>_real1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common1 \\<eta>) (real1 \\<eta>)\"\n    and lossless_sim2 [plossless_intro]: \"\\<And>\\<eta>. lossless1 \\<Longrightarrow> plossless_converter (\\<I>_real2 \\<eta>) (\\<I>_inner2 \\<eta>) (sim2 \\<eta>)\"\n    and lossless_ideal2 [plossless_intro]: \"\\<And>\\<eta>. lossless1 \\<Longrightarrow> lossless_resource (\\<I>_inner2 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>) (ideal2 \\<eta>)\"\n  shows \"constructive_security (\\<lambda>\\<eta>. parallel_wiring \\<rhd> real1 \\<eta> \\<parallel> real2 \\<eta>) (\\<lambda>\\<eta>. parallel_wiring \\<rhd> ideal1 \\<eta> \\<parallel> ideal2 \\<eta>) (\\<lambda>\\<eta>. sim1 \\<eta> |\\<^sub>= sim2 \\<eta>) \n    (\\<lambda>\\<eta>. \\<I>_real1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_real2 \\<eta>) (\\<lambda>\\<eta>. \\<I>_inner1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_inner2 \\<eta>) (\\<lambda>\\<eta>. \\<I>_common1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>)\n    (\\<lambda>\\<eta>. min (bound1 \\<eta>) (bound2 \\<eta>)) (lossless1 \\<or> lossless2) (\\<lambda>\\<eta>. w1 \\<eta> |\\<^sub>w w2 \\<eta>)\"\nproof\n  interpret sec1: constructive_security real1 ideal1 sim1 \\<I>_real1 \\<I>_inner1 \\<I>_common1 bound1 lossless1 w1 by fact\n  interpret sec2: constructive_security real2 ideal2 sim2 \\<I>_real2 \\<I>_inner2 \\<I>_common2 bound2 lossless2 w2 by fact\n\n  show \"(\\<I>_real1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_real2 \\<eta>) \\<oplus>\\<^sub>\\<I> (\\<I>_common1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>) \\<turnstile>res parallel_wiring \\<rhd> real1 \\<eta> \\<parallel> real2 \\<eta> \\<surd>\"\n    and \"(\\<I>_inner1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_inner2 \\<eta>) \\<oplus>\\<^sub>\\<I> (\\<I>_common1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>) \\<turnstile>res parallel_wiring \\<rhd> ideal1 \\<eta> \\<parallel> ideal2 \\<eta> \\<surd>\"\n    and \"\\<I>_real1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_real2 \\<eta>, \\<I>_inner1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_inner2 \\<eta> \\<turnstile>\\<^sub>C sim1 \\<eta> |\\<^sub>= sim2 \\<eta> \\<surd>\" for \\<eta> by(rule WT_intro)+\n\n  fix \\<A> :: \"security \\<Rightarrow> (('a + 'g) + 'b + 'h, ('c + 'i) + 'd + 'j) distinguisher\"\n  assume WT [WT_intro]: \"(\\<I>_real1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_real2 \\<eta>) \\<oplus>\\<^sub>\\<I> (\\<I>_common1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>) \\<turnstile>g \\<A> \\<eta> \\<surd>\" for \\<eta>\n  assume bound [interaction_bound]: \"interaction_any_bounded_by (\\<A> \\<eta>) (min (bound1 \\<eta>) (bound2 \\<eta>))\" for \\<eta>\n  assume lossless [plossless_intro]: \"lossless1 \\<or> lossless2 \\<Longrightarrow> plossless_gpv ((\\<I>_real1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_real2 \\<eta>) \\<oplus>\\<^sub>\\<I> (\\<I>_common1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>)) (\\<A> \\<eta>)\" for \\<eta>\n\n  let ?\\<A> = \"\\<lambda>\\<eta>. absorb (\\<A> \\<eta>) (parallel_wiring \\<odot> parallel_converter (converter_of_resource (real1 \\<eta>)) 1\\<^sub>C)\"\n\n  have *:\"\\<I>_uniform (outs_\\<I> ((\\<I>_real1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_real2 \\<eta>) \\<oplus>\\<^sub>\\<I> (\\<I>_common1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>)))\n     UNIV,(\\<I>_real1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common1 \\<eta>) \\<oplus>\\<^sub>\\<I> (\\<I>_inner2 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>) \\<turnstile>\\<^sub>C\n    ((1\\<^sub>C |\\<^sub>= sim2 \\<eta>) |\\<^sub>= 1\\<^sub>C) \\<odot> parallel_wiring \\<sim> ((1\\<^sub>C |\\<^sub>= sim2 \\<eta>) |\\<^sub>= 1\\<^sub>C |\\<^sub>= 1\\<^sub>C) \\<odot> parallel_wiring\" for \\<eta>\n    by(rule eq_\\<I>_comp_cong, rule eq_\\<I>_converter_mono)\n      (auto simp add: le_\\<I>_def intro: parallel_converter2_eq_\\<I>_cong eq_\\<I>_converter_reflI WT_converter_parallel_converter2\n        WT_converter_id sec2.WT_sim parallel_converter2_id_id[symmetric] eq_\\<I>_converter_reflI WT_parallel_wiring)\n\n  have **: \"outs_\\<I> ((\\<I>_real1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_real2 \\<eta>) \\<oplus>\\<^sub>\\<I> (\\<I>_common1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>)) \\<turnstile>\\<^sub>R\n    ((1\\<^sub>C |\\<^sub>= sim2 \\<eta>) |\\<^sub>= 1\\<^sub>C |\\<^sub>= 1\\<^sub>C) \\<odot> parallel_wiring \\<rhd> real1 \\<eta> \\<parallel> ideal2 \\<eta> \\<sim>\n    parallel_wiring \\<odot> (converter_of_resource (real1 \\<eta>) |\\<^sub>\\<propto> 1\\<^sub>C) \\<rhd> sim2 \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> ideal2 \\<eta>\" for \\<eta>\n    unfolding comp_parallel_wiring\n    by(rule eq_resource_on_trans, rule eq_\\<I>_attach_on[where conv'=\"parallel_wiring \\<odot> (1\\<^sub>C |\\<^sub>= sim2 \\<eta> |\\<^sub>= 1\\<^sub>C)\"]\n        , (rule WT_intro)+, rule eq_\\<I>_comp_cong, rule eq_\\<I>_converter_mono)\n      (auto simp add: le_\\<I>_def attach_compose attach_parallel2 attach_converter_of_resource_conv_parallel_resource\n        intro: WT_intro parallel_converter2_eq_\\<I>_cong parallel_converter2_id_id eq_\\<I>_converter_reflI)\n\n  have ideal2:\n    \"connect (\\<A> \\<eta>) ((1\\<^sub>C |\\<^sub>= sim2 \\<eta>) |\\<^sub>= 1\\<^sub>C \\<rhd> parallel_wiring \\<rhd> real1 \\<eta> \\<parallel> ideal2 \\<eta>) =\n     connect (?\\<A> \\<eta>) (sim2 \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> ideal2 \\<eta>)\" for \\<eta>\n    unfolding distinguish_attach[symmetric]\n  proof (rule connect_eq_resource_cong[OF WT, rotated], goal_cases)\n    case 2\n    then show ?case \n      by(subst attach_compose[symmetric], rule eq_resource_on_trans\n          , rule eq_\\<I>_attach_on[where conv'=\"((1\\<^sub>C |\\<^sub>= sim2 \\<eta>) |\\<^sub>= 1\\<^sub>C |\\<^sub>= 1\\<^sub>C) \\<odot> parallel_wiring\"])\n        ((rule WT_intro)+ | intro * | intro ** )+\n  qed (rule WT_intro)+\n  have real2: \"connect (\\<A> \\<eta>) (parallel_wiring \\<rhd> real1 \\<eta> \\<parallel> real2 \\<eta>) = connect (?\\<A> \\<eta>) (real2 \\<eta>)\" for \\<eta>\n    unfolding distinguish_attach[symmetric]\n    by(simp add: attach_compose attach_converter_of_resource_conv_parallel_resource)\n  have \"\\<I>_real2 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta> \\<turnstile>g ?\\<A> \\<eta> \\<surd>\" for \\<eta> by(rule WT_intro)+\n  moreover have \"interaction_any_bounded_by (?\\<A> \\<eta>) (bound2 \\<eta>)\" for \\<eta>\n    by interaction_bound_converter simp\n  moreover have \"plossless_gpv (\\<I>_real2 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>) (?\\<A> \\<eta>)\" if \"lossless2\" for \\<eta> \n    by(rule plossless_intro WT_intro | simp add: that)+\n  ultimately\n  have negl2: \"negligible (\\<lambda>\\<eta>. advantage (\\<A> \\<eta>)\n     ((1\\<^sub>C |\\<^sub>= sim2 \\<eta>) |\\<^sub>= 1\\<^sub>C \\<rhd> parallel_wiring \\<rhd> real1 \\<eta> \\<parallel> ideal2 \\<eta>)\n     (parallel_wiring \\<rhd> real1 \\<eta> \\<parallel> real2 \\<eta>))\"\n    unfolding advantage_def ideal2 real2 by(rule sec2.adv[unfolded advantage_def])\n\n  let ?\\<A> = \"\\<lambda>\\<eta>. absorb (\\<A> \\<eta>) (parallel_wiring \\<odot> parallel_converter 1\\<^sub>C (converter_of_resource (sim2 \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> ideal2 \\<eta>)))\"\n  have ideal1: \n    \"connect (\\<A> \\<eta>) ((sim1 \\<eta> |\\<^sub>= sim2 \\<eta>) |\\<^sub>= 1\\<^sub>C \\<rhd> parallel_wiring \\<rhd> ideal1 \\<eta> \\<parallel> ideal2 \\<eta>) =\n     connect (?\\<A> \\<eta>) (sim1 \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> ideal1 \\<eta>)\" for \\<eta>\n  proof -\n    have *: \"\\<I>_uniform ((outs_\\<I> (\\<I>_real1 \\<eta>) <+> outs_\\<I> (\\<I>_real2 \\<eta>)) <+>  outs_\\<I> (\\<I>_common1 \\<eta>) <+> \n      outs_\\<I> (\\<I>_common2 \\<eta>)) UNIV,(\\<I>_inner1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common1 \\<eta>) \\<oplus>\\<^sub>\\<I> (\\<I>_inner2 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>) \\<turnstile>\\<^sub>C\n    ((sim1 \\<eta> |\\<^sub>= sim2 \\<eta>) |\\<^sub>= 1\\<^sub>C) \\<odot> parallel_wiring \\<sim> ((sim1 \\<eta> |\\<^sub>= sim2 \\<eta>) |\\<^sub>= 1\\<^sub>C |\\<^sub>= 1\\<^sub>C) \\<odot> parallel_wiring\"\n      by(rule eq_\\<I>_comp_cong, rule eq_\\<I>_converter_mono)\n        (auto simp add: le_\\<I>_def comp_parallel_wiring' attach_compose attach_parallel2 attach_converter_of_resource_conv_parallel_resource2\n          intro: WT_intro parallel_converter2_id_id[symmetric] eq_\\<I>_converter_reflI parallel_converter2_eq_\\<I>_cong eq_\\<I>_converter_mono)\n\n    have **:\"((outs_\\<I> (\\<I>_real1 \\<eta>) <+> outs_\\<I> (\\<I>_real2 \\<eta>)) <+> outs_\\<I> (\\<I>_common1 \\<eta>) <+> outs_\\<I> (\\<I>_common2 \\<eta>)) \\<turnstile>\\<^sub>R\n    (sim1 \\<eta> |\\<^sub>= sim2 \\<eta>) |\\<^sub>= 1\\<^sub>C \\<rhd> parallel_wiring \\<rhd> ideal1 \\<eta> \\<parallel> ideal2 \\<eta> \\<sim>\n    parallel_wiring \\<odot> (1\\<^sub>C |\\<^sub>\\<propto> converter_of_resource (sim2 \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> ideal2 \\<eta>)) \\<rhd>  sim1 \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> ideal1 \\<eta>\"\n      unfolding attach_compose[symmetric]\n      by(rule eq_resource_on_trans, rule eq_\\<I>_attach_on[where conv'=\"((sim1 \\<eta> |\\<^sub>= sim2 \\<eta>) |\\<^sub>= 1\\<^sub>C |\\<^sub>= 1\\<^sub>C) \\<odot> parallel_wiring\"])\n        ((rule WT_intro)+ | intro * | auto simp add: le_\\<I>_def comp_parallel_wiring' attach_compose \n          attach_parallel2 attach_converter_of_resource_conv_parallel_resource2 intro: WT_intro *)+\n\n    show ?thesis\n      unfolding distinguish_attach[symmetric] using WT\n      by(rule connect_eq_resource_cong) (simp add: **, (rule WT_intro)+)\n  qed\n\n  have real1:\n    \"connect (\\<A> \\<eta>) ((1\\<^sub>C |\\<^sub>= sim2 \\<eta>) |\\<^sub>= 1\\<^sub>C \\<rhd> parallel_wiring \\<rhd> real1 \\<eta> \\<parallel> ideal2 \\<eta>) =\n     connect (?\\<A> \\<eta>) (real1 \\<eta>)\" for \\<eta>\n  proof -\n    have **: \"\\<I>_uniform (outs_\\<I> ((\\<I>_real1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_real2 \\<eta>) \\<oplus>\\<^sub>\\<I> (\\<I>_common1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>)))\n     UNIV,(\\<I>_real1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common1 \\<eta>) \\<oplus>\\<^sub>\\<I> (\\<I>_inner2 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>) \\<turnstile>\\<^sub>C\n      ((1\\<^sub>C |\\<^sub>= sim2 \\<eta>) |\\<^sub>= 1\\<^sub>C) \\<odot> parallel_wiring \\<sim> ((1\\<^sub>C |\\<^sub>= sim2 \\<eta>) |\\<^sub>= 1\\<^sub>C |\\<^sub>= 1\\<^sub>C) \\<odot> parallel_wiring\" \n      by(rule eq_\\<I>_comp_cong, rule eq_\\<I>_converter_mono)\n        (auto simp add: le_\\<I>_def intro: WT_intro parallel_converter2_eq_\\<I>_cong WT_converter_parallel_converter2\n          parallel_converter2_id_id[symmetric] eq_\\<I>_converter_reflI WT_parallel_wiring)\n\n    have *: \"outs_\\<I> ((\\<I>_real1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_real2 \\<eta>) \\<oplus>\\<^sub>\\<I> (\\<I>_common1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>)) \\<turnstile>\\<^sub>R\n    parallel_wiring \\<odot> ((1\\<^sub>C |\\<^sub>= 1\\<^sub>C) |\\<^sub>= sim2 \\<eta> |\\<^sub>= 1\\<^sub>C) \\<rhd> real1 \\<eta> \\<parallel> ideal2 \\<eta> \\<sim>\n    parallel_wiring \\<odot> (1\\<^sub>C |\\<^sub>\\<propto> converter_of_resource (sim2 \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> ideal2 \\<eta>)) \\<rhd> real1 \\<eta>\"\n      by(rule eq_resource_on_trans, rule eq_\\<I>_attach_on[where conv'=\"parallel_wiring \\<odot> (1\\<^sub>C |\\<^sub>= sim2 \\<eta> |\\<^sub>= 1\\<^sub>C)\"]\n          , (rule WT_intro)+, rule eq_\\<I>_comp_cong, rule eq_\\<I>_converter_mono)\n        (auto simp add: le_\\<I>_def attach_compose attach_converter_of_resource_conv_parallel_resource2 attach_parallel2 \n          intro: WT_intro parallel_converter2_eq_\\<I>_cong parallel_converter2_id_id eq_\\<I>_converter_reflI)\n\n    show ?thesis\n      unfolding distinguish_attach[symmetric] using WT\n      by(rule connect_eq_resource_cong, fold attach_compose)\n        (rule eq_resource_on_trans[where res'=\"((1\\<^sub>C |\\<^sub>= sim2 \\<eta>) |\\<^sub>= 1\\<^sub>C |\\<^sub>= 1\\<^sub>C) \\<odot> parallel_wiring \\<rhd> real1 \\<eta> \\<parallel> ideal2 \\<eta>\"]\n          , (rule eq_\\<I>_attach_on, (intro * ** | subst comp_parallel_wiring | rule eq_\\<I>_attach_on | (rule WT_intro eq_\\<I>_attach_on)+ )+))\n  qed\n\n  have \"\\<I>_real1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common1 \\<eta> \\<turnstile>g ?\\<A> \\<eta> \\<surd>\" for \\<eta> by(rule WT_intro)+\n  moreover have \"interaction_any_bounded_by (?\\<A> \\<eta>) (bound1 \\<eta>)\" for \\<eta>\n    by interaction_bound_converter simp\n  moreover have \"plossless_gpv (\\<I>_real1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common1 \\<eta>) (?\\<A> \\<eta>)\" if \"lossless1\" for \\<eta> \n    by(rule plossless_intro WT_intro | simp add: that)+\n  ultimately\n  have negl1: \"negligible (\\<lambda>\\<eta>. advantage (\\<A> \\<eta>) \n     ((sim1 \\<eta> |\\<^sub>= sim2 \\<eta>) |\\<^sub>= 1\\<^sub>C \\<rhd> parallel_wiring \\<rhd> ideal1 \\<eta> \\<parallel> ideal2 \\<eta>)\n     ((1\\<^sub>C |\\<^sub>= sim2 \\<eta>) |\\<^sub>= 1\\<^sub>C \\<rhd> parallel_wiring \\<rhd> real1 \\<eta> \\<parallel> ideal2 \\<eta>))\"\n    unfolding advantage_def ideal1 real1 by(rule sec1.adv[unfolded advantage_def])\n\n  from negligible_plus[OF negl1 negl2]\n  show \"negligible (\\<lambda>\\<eta>. advantage (\\<A> \\<eta>) ((sim1 \\<eta> |\\<^sub>= sim2 \\<eta>) |\\<^sub>= 1\\<^sub>C \\<rhd> parallel_wiring \\<rhd> ideal1 \\<eta> \\<parallel> ideal2 \\<eta>)\n         (parallel_wiring \\<rhd> real1 \\<eta> \\<parallel> real2 \\<eta>))\"\n    by(rule negligible_mono) (auto simp add: advantage_def intro!: eventuallyI landau_o.big_mono )\nnext\n  interpret sec1: constructive_security real1 ideal1 sim1 \\<I>_real1 \\<I>_inner1 \\<I>_common1 bound1 lossless1 w1 by fact\n  interpret sec2: constructive_security real2 ideal2 sim2 \\<I>_real2 \\<I>_inner2 \\<I>_common2 bound2 lossless2 w2 by fact\n  from sec1.correct obtain cnv1\n    where correct1: \"\\<And>\\<D>. \\<lbrakk> \\<And>\\<eta>. \\<I>_inner1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common1 \\<eta> \\<turnstile>g \\<D> \\<eta> \\<surd>;\n      \\<And>\\<eta>. interaction_any_bounded_by (\\<D> \\<eta>) (bound1 \\<eta>);\n      \\<And>\\<eta>. lossless1 \\<Longrightarrow> plossless_gpv (\\<I>_inner1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common1 \\<eta>) (\\<D> \\<eta>) \\<rbrakk>\n     \\<Longrightarrow> (\\<forall>\\<eta>. wiring (\\<I>_inner1 \\<eta>) (\\<I>_real1 \\<eta>) (cnv1 \\<eta>) (w1 \\<eta>)) \\<and>\n         negligible (\\<lambda>\\<eta>. advantage (\\<D> \\<eta>) (ideal1 \\<eta>) (cnv1 \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real1 \\<eta>))\"\n    by blast\n  from sec2.correct obtain cnv2\n    where correct2: \"\\<And>\\<D>. \\<lbrakk> \\<And>\\<eta>. \\<I>_inner2 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta> \\<turnstile>g \\<D> \\<eta> \\<surd>;\n      \\<And>\\<eta>. interaction_any_bounded_by (\\<D> \\<eta>) (bound2 \\<eta>);\n      \\<And>\\<eta>. lossless2 \\<Longrightarrow> plossless_gpv (\\<I>_inner2 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>) (\\<D> \\<eta>) \\<rbrakk>\n     \\<Longrightarrow> (\\<forall>\\<eta>. wiring (\\<I>_inner2 \\<eta>) (\\<I>_real2 \\<eta>) (cnv2 \\<eta>) (w2 \\<eta>)) \\<and>\n         negligible (\\<lambda>\\<eta>. advantage (\\<D> \\<eta>) (ideal2 \\<eta>) (cnv2 \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real2 \\<eta>))\"\n    by blast\n  show \"\\<exists>cnv. \\<forall>\\<D>. (\\<forall>\\<eta>. (\\<I>_inner1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_inner2 \\<eta>) \\<oplus>\\<^sub>\\<I> (\\<I>_common1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>) \\<turnstile>g \\<D> \\<eta> \\<surd>) \\<longrightarrow>\n       (\\<forall>\\<eta>. interaction_any_bounded_by (\\<D> \\<eta>) (min (bound1 \\<eta>) (bound2 \\<eta>))) \\<longrightarrow>\n       (\\<forall>\\<eta>. lossless1 \\<or> lossless2 \\<longrightarrow> plossless_gpv ((\\<I>_inner1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_inner2 \\<eta>) \\<oplus>\\<^sub>\\<I> (\\<I>_common1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>)) (\\<D> \\<eta>)) \\<longrightarrow>\n       (\\<forall>\\<eta>. wiring (\\<I>_inner1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_inner2 \\<eta>) (\\<I>_real1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_real2 \\<eta>) (cnv \\<eta>) (w1 \\<eta> |\\<^sub>w w2 \\<eta>)) \\<and>\n       negligible (\\<lambda>\\<eta>. advantage (\\<D> \\<eta>) (parallel_wiring \\<rhd> ideal1 \\<eta> \\<parallel> ideal2 \\<eta>) (cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> parallel_wiring \\<rhd> real1 \\<eta> \\<parallel> real2 \\<eta>))\"\n  proof(intro exI strip conjI)\n    fix \\<D> :: \"security \\<Rightarrow> (('e + 'k) + 'b + 'h, ('f + 'l) + 'd + 'j) distinguisher\"\n    assume WT_D [rule_format, WT_intro]: \"\\<forall>\\<eta>. (\\<I>_inner1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_inner2 \\<eta>) \\<oplus>\\<^sub>\\<I> (\\<I>_common1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>) \\<turnstile>g \\<D> \\<eta> \\<surd>\"\n      and bound [rule_format, interaction_bound]: \"\\<forall>\\<eta>. interaction_any_bounded_by (\\<D> \\<eta>) (min (bound1 \\<eta>) (bound2 \\<eta>))\"\n      and lossless [rule_format, plossless_intro]: \"\\<forall>\\<eta>. lossless1 \\<or> lossless2 \\<longrightarrow> plossless_gpv ((\\<I>_inner1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_inner2 \\<eta>) \\<oplus>\\<^sub>\\<I> (\\<I>_common1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>)) (\\<D> \\<eta>)\"\n\n    let ?cnv = \"\\<lambda>\\<eta>. cnv1 \\<eta> |\\<^sub>= cnv2 \\<eta>\"\n\n    let ?\\<D>1 = \"\\<lambda>\\<eta>. absorb (\\<D> \\<eta>) (parallel_wiring \\<odot> parallel_converter 1\\<^sub>C (converter_of_resource (ideal2 \\<eta>)))\"\n    have WT1: \"\\<I>_inner1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common1 \\<eta> \\<turnstile>g ?\\<D>1 \\<eta> \\<surd>\" for \\<eta> by(rule WT_intro)+\n    have bound1: \"interaction_any_bounded_by (?\\<D>1 \\<eta>) (bound1 \\<eta>)\" for \\<eta> by interaction_bound simp\n    have \"plossless_gpv (\\<I>_inner1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common1 \\<eta>) (?\\<D>1 \\<eta>)\" if lossless1 for \\<eta>\n      by(rule plossless_intro WT_intro | simp add: that)+\n    from correct1[OF WT1 bound1 this]\n    have w1: \"wiring (\\<I>_inner1 \\<eta>) (\\<I>_real1 \\<eta>) (cnv1 \\<eta>) (w1 \\<eta>)\" \n      and adv1: \"negligible (\\<lambda>\\<eta>. advantage (?\\<D>1 \\<eta>) (ideal1 \\<eta>) (cnv1 \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real1 \\<eta>))\" for \\<eta>\n      by auto\n\n    from w1 obtain f g where fg: \"\\<And>\\<eta>. w1 \\<eta> = (f \\<eta>, g \\<eta>)\"\n      and [WT_intro]: \"\\<And>\\<eta>. \\<I>_inner1 \\<eta>, \\<I>_real1 \\<eta> \\<turnstile>\\<^sub>C cnv1 \\<eta> \\<surd>\" \n      and eq1: \"\\<And>\\<eta>. \\<I>_inner1 \\<eta>, \\<I>_real1 \\<eta> \\<turnstile>\\<^sub>C cnv1 \\<eta> \\<sim> map_converter id id (f \\<eta>) (g \\<eta>) 1\\<^sub>C\"\n      apply atomize_elim\n      apply(fold all_conj_distrib)\n      apply(subst choice_iff[symmetric])+\n      apply(fastforce elim!: wiring.cases)\n      done\n    have \\<I>1: \"\\<I>_inner1 \\<eta> \\<le> map_\\<I> (f \\<eta>) (g \\<eta>) (\\<I>_real1 \\<eta>)\" for \\<eta>\n      using eq_\\<I>_converterD_WT1[OF eq1] by(rule WT_map_converter_idD)(rule WT_intro)\n    with WT_converter_id order_refl have [WT_intro]: \"\\<I>_inner1 \\<eta>, map_\\<I> (f \\<eta>) (g \\<eta>) (\\<I>_real1 \\<eta>) \\<turnstile>\\<^sub>C 1\\<^sub>C \\<surd>\" for \\<eta>\n      by(rule WT_converter_mono)\n    have lossless1 [plossless_intro]: \"plossless_converter (\\<I>_inner1 \\<eta>) (\\<I>_real1 \\<eta>) (map_converter id id (f \\<eta>) (g \\<eta>) 1\\<^sub>C)\" for \\<eta>\n      by(rule plossless_map_converter)(rule plossless_intro order_refl \\<I>1 WT_intro plossless_converter_mono | simp)+\n\n    let ?\\<D>2 = \"\\<lambda>\\<eta>. absorb (\\<D> \\<eta>) (parallel_wiring \\<odot> parallel_converter (converter_of_resource (map_converter id id (f \\<eta>) (g \\<eta>) 1\\<^sub>C |\\<^sub>= 1\\<^sub>C \\<rhd> real1 \\<eta>)) 1\\<^sub>C)\"\n    have WT2: \"\\<I>_inner2 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta> \\<turnstile>g ?\\<D>2 \\<eta> \\<surd>\" for \\<eta> by(rule WT_intro | simp)+\n    have bound2: \"interaction_any_bounded_by (?\\<D>2 \\<eta>) (bound2 \\<eta>)\" for \\<eta> by interaction_bound simp\n    have \"plossless_gpv (\\<I>_inner2 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>) (?\\<D>2 \\<eta>)\" if lossless2 for \\<eta>\n      by(rule plossless_intro WT_intro | simp add: that)+\n    from correct2[OF WT2 bound2 this]\n    have w2: \"wiring (\\<I>_inner2 \\<eta>) (\\<I>_real2 \\<eta>) (cnv2 \\<eta>) (w2 \\<eta>)\" \n      and adv2: \"negligible (\\<lambda>\\<eta>. advantage (?\\<D>2 \\<eta>) (ideal2 \\<eta>) (cnv2 \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real2 \\<eta>))\" for \\<eta>\n      by auto\n\n    from w2 have [WT_intro]: \"\\<I>_inner2 \\<eta>, \\<I>_real2 \\<eta> \\<turnstile>\\<^sub>C cnv2 \\<eta> \\<surd>\" for \\<eta> by cases\n\n    have *: \"connect (\\<D> \\<eta>) (?cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> parallel_wiring \\<rhd> real1 \\<eta> \\<parallel> real2 \\<eta>) =\n      connect (?\\<D>2 \\<eta>) (cnv2 \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real2 \\<eta>)\" for \\<eta>\n    proof -\n      have \"outs_\\<I> ((\\<I>_inner1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_inner2 \\<eta>) \\<oplus>\\<^sub>\\<I> (\\<I>_common1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common2 \\<eta>)) \\<turnstile>\\<^sub>R\n         ?cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> parallel_wiring \\<rhd> real1 \\<eta> \\<parallel> real2 \\<eta> \\<sim> \n         (map_converter id id (f \\<eta>) (g \\<eta>) 1\\<^sub>C |\\<^sub>= cnv2 \\<eta>) |\\<^sub>= (1\\<^sub>C |\\<^sub>= 1\\<^sub>C) \\<rhd> parallel_wiring \\<rhd> real1 \\<eta> \\<parallel> real2 \\<eta>\"\n        by(rule eq_\\<I>_attach_on' WT_intro parallel_converter2_eq_\\<I>_cong eq1 eq_\\<I>_converter_reflI parallel_converter2_id_id[symmetric])+ simp\n      also have \"(map_converter id id (f \\<eta>) (g \\<eta>) 1\\<^sub>C |\\<^sub>= cnv2 \\<eta>) |\\<^sub>= (1\\<^sub>C |\\<^sub>= 1\\<^sub>C) \\<rhd> parallel_wiring \\<rhd> real1 \\<eta> \\<parallel> real2 \\<eta> =\n        parallel_wiring \\<rhd> (map_converter id id (f \\<eta>) (g \\<eta>) 1\\<^sub>C |\\<^sub>= 1\\<^sub>C \\<rhd> real1 \\<eta>) \\<parallel> (cnv2 \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real2 \\<eta>)\"\n        by(simp add: comp_parallel_wiring' attach_compose attach_parallel2)\n      finally show ?thesis\n        by(auto intro!: connect_eq_resource_cong[OF WT_D] intro: WT_intro simp add: distinguish_attach[symmetric] attach_compose attach_converter_of_resource_conv_parallel_resource)\n    qed\n\n    have **: \"connect (?\\<D>2 \\<eta>) (ideal2 \\<eta>) = connect (?\\<D>1 \\<eta>) (cnv1 \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real1 \\<eta>)\" for \\<eta>\n    proof -\n      have \"connect (?\\<D>2 \\<eta>) (ideal2 \\<eta>) = \n        connect (\\<D> \\<eta>) (parallel_wiring \\<rhd> ((map_converter id id (f \\<eta>) (g \\<eta>) 1\\<^sub>C |\\<^sub>= 1\\<^sub>C) |\\<^sub>= 1\\<^sub>C) \\<rhd> (real1 \\<eta> \\<parallel> ideal2 \\<eta>))\"\n        by(simp add: distinguish_attach[symmetric] attach_converter_of_resource_conv_parallel_resource attach_compose attach_parallel2)\n      also have \"\\<dots> = connect (\\<D> \\<eta>) (parallel_wiring \\<rhd> ((cnv1 \\<eta> |\\<^sub>= 1\\<^sub>C) |\\<^sub>= 1\\<^sub>C) \\<rhd> (real1 \\<eta> \\<parallel> ideal2 \\<eta>))\"\n        unfolding attach_compose[symmetric] using WT_D\n        by(rule connect_eq_resource_cong[symmetric])\n          (rule eq_\\<I>_attach_on' WT_intro eq_\\<I>_comp_cong eq_\\<I>_converter_reflI parallel_converter2_eq_\\<I>_cong eq1 | simp)+\n      also have \"\\<dots> = connect (?\\<D>1 \\<eta>) (cnv1 \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real1 \\<eta>)\"\n        by(simp add: distinguish_attach[symmetric] attach_converter_of_resource_conv_parallel_resource2 attach_compose attach_parallel2)\n      finally show ?thesis .\n    qed\n\n    have ***: \"connect (?\\<D>1 \\<eta>) (ideal1 \\<eta>) = connect (\\<D> \\<eta>) (parallel_wiring \\<rhd> ideal1 \\<eta> \\<parallel> ideal2 \\<eta>)\" for \\<eta>\n      by(auto intro!: connect_eq_resource_cong[OF WT_D] simp add: attach_converter_of_resource_conv_parallel_resource2 distinguish_attach[symmetric] attach_compose intro: WT_intro)\n\n    show \"wiring (\\<I>_inner1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_inner2 \\<eta>) (\\<I>_real1 \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_real2 \\<eta>) (?cnv \\<eta>) (w1 \\<eta> |\\<^sub>w w2 \\<eta>)\" for \\<eta>\n      using w1 w2 by(rule wiring_parallel_converter2)\n    from negligible_plus[OF adv1 adv2]\n    show \"negligible (\\<lambda>\\<eta>. advantage (\\<D> \\<eta>) (parallel_wiring \\<rhd> ideal1 \\<eta> \\<parallel> ideal2 \\<eta>) (?cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> parallel_wiring \\<rhd> real1 \\<eta> \\<parallel> real2 \\<eta>))\"\n      by(rule negligible_le)(simp add: advantage_def * ** ***)\n  qed\nqed\n\ntheorem (in constructive_security) parallel_realisation1:\n  assumes WT_res: \"\\<And>\\<eta>. \\<I>_res \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common' \\<eta> \\<turnstile>res res \\<eta> \\<surd>\"\n    and lossless_res: \"\\<And>\\<eta>. lossless \\<Longrightarrow> lossless_resource (\\<I>_res \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common' \\<eta>) (res \\<eta>)\"\n  shows \"constructive_security (\\<lambda>\\<eta>. parallel_wiring \\<rhd> res \\<eta> \\<parallel> real_resource \\<eta>)\n    (\\<lambda>\\<eta>. parallel_wiring \\<rhd> (res \\<eta> \\<parallel> ideal_resource \\<eta>)) (\\<lambda>\\<eta>. parallel_converter2 id_converter (sim \\<eta>)) \n    (\\<lambda>\\<eta>. \\<I>_res \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_real \\<eta>) (\\<lambda>\\<eta>. \\<I>_res \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_ideal \\<eta>) (\\<lambda>\\<eta>. \\<I>_common' \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) bound lossless (\\<lambda>\\<eta>. (id, id) |\\<^sub>w w \\<eta>)\"\n  by(rule parallel_constructive_security[OF constructive_security_trivial[where lossless=False and bound=\"\\<lambda>_. \\<infinity>\", OF WT_res], simplified, OF _ lossless_res])\n    unfold_locales\n\ntheorem (in constructive_security) parallel_realisation2:\n  assumes WT_res: \"\\<And>\\<eta>. \\<I>_res \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common' \\<eta> \\<turnstile>res res \\<eta> \\<surd>\"\n    and lossless_res: \"\\<And>\\<eta>. lossless \\<Longrightarrow> lossless_resource (\\<I>_res \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common' \\<eta>) (res \\<eta>)\"\n  shows \"constructive_security (\\<lambda>\\<eta>. parallel_wiring \\<rhd> real_resource \\<eta> \\<parallel> res \\<eta>)\n    (\\<lambda>\\<eta>. parallel_wiring \\<rhd> (ideal_resource \\<eta> \\<parallel> res \\<eta>)) (\\<lambda>\\<eta>. parallel_converter2 (sim \\<eta>) id_converter) \n    (\\<lambda>\\<eta>. \\<I>_real \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_res \\<eta>) (\\<lambda>\\<eta>. \\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_res \\<eta>) (\\<lambda>\\<eta>. \\<I>_common \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common' \\<eta>) bound lossless (\\<lambda>\\<eta>. w \\<eta> |\\<^sub>w (id, id))\"\n  by(rule parallel_constructive_security[OF _ constructive_security_trivial[where lossless=False and bound=\"\\<lambda>_. \\<infinity>\", OF WT_res], simplified, OF _ lossless_res])\n    unfold_locales\n\ntheorem (in constructive_security) parallel_resource1:\n  assumes WT_res [WT_intro]: \"\\<And>\\<eta>. \\<I>_res \\<eta> \\<turnstile>res res \\<eta> \\<surd>\"\n    and lossless_res [plossless_intro]: \"\\<And>\\<eta>. lossless \\<Longrightarrow> lossless_resource (\\<I>_res \\<eta>) (res \\<eta>)\"\n  shows \"constructive_security (\\<lambda>\\<eta>. parallel_resource1_wiring \\<rhd> res \\<eta> \\<parallel> real_resource \\<eta>)\n    (\\<lambda>\\<eta>. parallel_resource1_wiring \\<rhd> res \\<eta> \\<parallel> ideal_resource \\<eta>) sim \n    \\<I>_real \\<I>_ideal (\\<lambda>\\<eta>. \\<I>_res \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) bound lossless w\"\nproof\n  fix \\<A> :: \"security \\<Rightarrow> ('a + 'g + 'e, 'b + 'h + 'f) distinguisher\"\n  assume WT [WT_intro]: \"\\<I>_real \\<eta> \\<oplus>\\<^sub>\\<I> (\\<I>_res \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) \\<turnstile>g \\<A> \\<eta> \\<surd>\" for \\<eta>\n  assume bound [interaction_bound]: \"interaction_any_bounded_by (\\<A> \\<eta>) (bound \\<eta>)\" for \\<eta>\n  assume lossless [plossless_intro]: \"lossless \\<Longrightarrow> plossless_gpv (\\<I>_real \\<eta> \\<oplus>\\<^sub>\\<I> (\\<I>_res \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>)) (\\<A> \\<eta>)\" for \\<eta>\n\n  let ?\\<A> = \"\\<lambda>\\<eta>. absorb (\\<A> \\<eta>) (swap_lassocr \\<odot> parallel_converter (converter_of_resource (res \\<eta>)) 1\\<^sub>C)\"\n  have ideal:\n    \"connect (\\<A> \\<eta>) (sim \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> parallel_resource1_wiring \\<rhd> res \\<eta> \\<parallel> ideal_resource \\<eta>) =\n     connect (?\\<A> \\<eta>) (sim \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> ideal_resource \\<eta>)\" for \\<eta>\n  proof -\n    have[intro]: \"\\<I>_uniform (outs_\\<I> (\\<I>_real \\<eta>) <+> outs_\\<I> (\\<I>_res \\<eta>) <+> outs_\\<I> (\\<I>_common \\<eta>))\n     UNIV,\\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> (\\<I>_res \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) \\<turnstile>\\<^sub>C  sim \\<eta> |\\<^sub>= 1\\<^sub>C \\<sim> sim \\<eta> |\\<^sub>= 1\\<^sub>C |\\<^sub>= 1\\<^sub>C \" \n      by(rule eq_\\<I>_converter_mono) (auto simp add: le_\\<I>_def intro!: \n          WT_intro parallel_converter2_id_id[symmetric] parallel_converter2_eq_\\<I>_cong eq_\\<I>_converter_reflI)\n\n    have *: \"outs_\\<I> (\\<I>_real \\<eta> \\<oplus>\\<^sub>\\<I> (\\<I>_res \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>)) \\<turnstile>\\<^sub>R  (sim \\<eta> |\\<^sub>= 1\\<^sub>C) \\<odot> parallel_resource1_wiring \\<rhd> res \\<eta> \\<parallel> ideal_resource \\<eta> \\<sim>\n      swap_lassocr \\<odot> (converter_of_resource (res \\<eta>) |\\<^sub>\\<propto> 1\\<^sub>C) \\<rhd> sim \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> ideal_resource \\<eta>\" \n      by (rule eq_resource_on_trans[where res'=\"(sim \\<eta> |\\<^sub>= 1\\<^sub>C |\\<^sub>= 1\\<^sub>C) \\<odot> parallel_resource1_wiring \\<rhd> res \\<eta> \\<parallel> ideal_resource \\<eta>\"], \n          rule eq_\\<I>_attach_on, (rule  WT_intro)+, rule eq_\\<I>_comp_cong)\n        (auto simp add: parallel_resource1_wiring_def comp_swap_lassocr attach_compose attach_parallel2 \n          attach_converter_of_resource_conv_parallel_resource intro!: WT_intro eq_\\<I>_converter_reflI)  \n\n    show ?thesis\n      unfolding distinguish_attach[symmetric] using WT\n      by(rule connect_eq_resource_cong, subst attach_compose[symmetric])\n        (intro *, (rule WT_intro)+)\n  qed\n  have real:\n    \"connect (\\<A> \\<eta>) (parallel_resource1_wiring \\<rhd> res \\<eta> \\<parallel> real_resource \\<eta>) =\n     connect (?\\<A> \\<eta>) (real_resource \\<eta>)\" for \\<eta>\n    unfolding distinguish_attach[symmetric]\n    by(simp add: attach_compose attach_converter_of_resource_conv_parallel_resource parallel_resource1_wiring_def)\n  have \"\\<I>_real \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g ?\\<A> \\<eta> \\<surd>\" for \\<eta> by(rule WT_intro)+\n  moreover have \"interaction_any_bounded_by (?\\<A> \\<eta>) (bound \\<eta>)\" for \\<eta>\n    by interaction_bound_converter simp\n  moreover have \"plossless_gpv (\\<I>_real \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) (?\\<A> \\<eta>)\" if lossless for \\<eta> \n    by(rule plossless_intro WT_intro | simp add: that)+\n  ultimately show \"negligible (\\<lambda>\\<eta>. advantage (\\<A> \\<eta>) (sim \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd>\n                        parallel_resource1_wiring \\<rhd> res \\<eta> \\<parallel> ideal_resource \\<eta>)\n                       (parallel_resource1_wiring \\<rhd> res \\<eta> \\<parallel> real_resource \\<eta>))\"\n    unfolding advantage_def ideal real by(rule adv[unfolded advantage_def])\nnext\n  from correct obtain cnv \n    where correct': \"\\<And>\\<D>. \\<lbrakk> \\<And>\\<eta>. \\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g \\<D> \\<eta> \\<surd>;\n          \\<And>\\<eta>. interaction_any_bounded_by (\\<D> \\<eta>) (bound \\<eta>);\n          \\<And>\\<eta>. lossless \\<Longrightarrow> plossless_gpv (\\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) (\\<D> \\<eta>) \\<rbrakk>\n          \\<Longrightarrow> (\\<forall>\\<eta>. wiring (\\<I>_ideal \\<eta>) (\\<I>_real \\<eta>) (cnv \\<eta>) (w \\<eta>)) \\<and>\n              negligible (\\<lambda>\\<eta>. advantage (\\<D> \\<eta>) (ideal_resource \\<eta>) (cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real_resource \\<eta>))\"\n    by blast\n  show \"\\<exists>cnv. \\<forall>\\<D>. (\\<forall>\\<eta>. \\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> (\\<I>_res \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) \\<turnstile>g \\<D> \\<eta> \\<surd>) \\<longrightarrow>\n        (\\<forall>\\<eta>. interaction_any_bounded_by (\\<D> \\<eta>) (bound \\<eta>)) \\<longrightarrow>\n        (\\<forall>\\<eta>. lossless \\<longrightarrow> plossless_gpv (\\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> (\\<I>_res \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>)) (\\<D> \\<eta>)) \\<longrightarrow>\n        (\\<forall>\\<eta>. wiring (\\<I>_ideal \\<eta>) (\\<I>_real \\<eta>) (cnv \\<eta>) (w \\<eta>)) \\<and>\n        negligible (\\<lambda>\\<eta>. advantage (\\<D> \\<eta>) (parallel_resource1_wiring \\<rhd> res \\<eta> \\<parallel> ideal_resource \\<eta>)\n          (cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> parallel_resource1_wiring \\<rhd> res \\<eta> \\<parallel> real_resource \\<eta>))\"\n  proof(intro exI conjI strip)\n    fix \\<D> :: \"security \\<Rightarrow> ('c + 'g + 'e, 'd + 'h + 'f) distinguisher\"\n    assume WT_D [rule_format, WT_intro]: \"\\<forall>\\<eta>. \\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> (\\<I>_res \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) \\<turnstile>g \\<D> \\<eta> \\<surd>\"\n      and bound [rule_format, interaction_bound]: \"\\<forall>\\<eta>. interaction_any_bounded_by (\\<D> \\<eta>) (bound \\<eta>)\"\n      and lossless [rule_format, plossless_intro]: \"\\<forall>\\<eta>. lossless \\<longrightarrow> plossless_gpv (\\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> (\\<I>_res \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>)) (\\<D> \\<eta>)\"\n\n    let ?\\<D> = \"\\<lambda>\\<eta>. absorb (\\<D> \\<eta>) (swap_lassocr \\<odot> parallel_converter (converter_of_resource (res \\<eta>)) 1\\<^sub>C)\"\n    have WT': \"\\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta> \\<turnstile>g ?\\<D> \\<eta> \\<surd>\" for \\<eta> by(rule WT_intro)+\n    have bound': \"interaction_any_bounded_by (?\\<D> \\<eta>) (bound \\<eta>)\" for \\<eta> by interaction_bound simp\n    have lossless': \"plossless_gpv (\\<I>_ideal \\<eta> \\<oplus>\\<^sub>\\<I> \\<I>_common \\<eta>) (?\\<D> \\<eta>)\" if lossless for \\<eta>\n      by(rule plossless_intro WT_intro that)+\n    from correct'[OF WT' bound' lossless']\n    have w: \"wiring (\\<I>_ideal \\<eta>) (\\<I>_real \\<eta>) (cnv \\<eta>) (w \\<eta>)\" \n      and adv: \"negligible (\\<lambda>\\<eta>. advantage (?\\<D> \\<eta>) (ideal_resource \\<eta>) (cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real_resource \\<eta>))\"\n      for \\<eta> by auto\n    show  \"wiring (\\<I>_ideal \\<eta>) (\\<I>_real \\<eta>) (cnv \\<eta>) (w \\<eta>)\" for \\<eta> by(rule w)\n    from w have [WT_intro]: \"\\<I>_ideal \\<eta>, \\<I>_real \\<eta> \\<turnstile>\\<^sub>C cnv \\<eta> \\<surd>\" for \\<eta> by cases\n    have \"connect (\\<D> \\<eta>) (swap_lassocr \\<rhd> res \\<eta> \\<parallel> (cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real_resource \\<eta>)) =\n      connect (\\<D> \\<eta>) (cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> swap_lassocr \\<rhd> res \\<eta> \\<parallel> real_resource \\<eta>)\" for \\<eta>\n    proof -\n      have \"connect (\\<D> \\<eta>) (cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> swap_lassocr \\<rhd> res \\<eta> \\<parallel> real_resource \\<eta>) =\n        connect (\\<D> \\<eta>) (cnv \\<eta> |\\<^sub>= 1\\<^sub>C |\\<^sub>= 1\\<^sub>C \\<rhd> swap_lassocr \\<rhd> res \\<eta> \\<parallel> real_resource \\<eta>)\"\n        by(rule connect_eq_resource_cong[OF WT_D])                                                                \n          (rule eq_\\<I>_attach_on' WT_intro parallel_converter2_eq_\\<I>_cong eq_\\<I>_converter_reflI parallel_converter2_id_id[symmetric] | simp)+\n      also have \"\\<dots> = connect (\\<D> \\<eta>) (swap_lassocr \\<rhd> res \\<eta> \\<parallel> (cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> real_resource \\<eta>))\"\n        by(simp add: comp_swap_lassocr' attach_compose attach_parallel2)\n      finally show ?thesis by simp\n    qed\n    with adv show \"negligible (\\<lambda>\\<eta>. advantage (\\<D> \\<eta>) (parallel_resource1_wiring \\<rhd> res \\<eta> \\<parallel> ideal_resource \\<eta>)\n          (cnv \\<eta> |\\<^sub>= 1\\<^sub>C \\<rhd> parallel_resource1_wiring \\<rhd> res \\<eta> \\<parallel> real_resource \\<eta>))\"\n      by(simp add: advantage_def distinguish_attach[symmetric] attach_compose attach_converter_of_resource_conv_parallel_resource parallel_resource1_wiring_def)\n  qed\nqed(rule WT_intro)+\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Constructive_Cryptography/Constructive_Cryptography.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.4339814648038985, "lm_q1q2_score": 0.2811324195242119}}
{"text": "section {*L\\_ATS\\_Simulation\\_Configuration\\_WeakLR\\_Unmarked\\_Effect*}\ntheory\n  L_ATS_Simulation_Configuration_WeakLR_Unmarked_Effect\n\nimports\n  L_ATS_Simulation_Configuration_Weak\n\nbegin\n\nlocale ATS_Simulation_Configuration_Weak_Unmarked_Effect =\n  ATS_Simulation_Configuration_Weak\n  \"TSstructure1 :: 'TSstructure1 \\<Rightarrow> bool\"\n  \"configurations1 :: 'TSstructure1 \\<Rightarrow> 'conf1 set\"\n  \"initial_configurations1 :: 'TSstructure1 \\<Rightarrow> 'conf1 set\"\n  \"step_labels1 :: 'TSstructure1 \\<Rightarrow> 'label1 set\"\n  \"step_relation1 :: 'TSstructure1 \\<Rightarrow> 'conf1 \\<Rightarrow> 'label1 \\<Rightarrow> 'conf1 \\<Rightarrow> bool\"\n  \"effects1 :: 'TSstructure1 \\<Rightarrow> 'event1 set\"\n  \"marking_condition1 :: 'TSstructure1 \\<Rightarrow> ('label1,'conf1)derivation \\<Rightarrow> bool\"\n  \"marked_effect1 :: 'TSstructure1 \\<Rightarrow> ('label1,'conf1)derivation \\<Rightarrow> 'event1 set\"\n  \"unmarked_effect1 :: 'TSstructure1 \\<Rightarrow> ('label1,'conf1)derivation \\<Rightarrow> 'event1 set\"\n  \"TSstructure2 :: 'TSstructure2 \\<Rightarrow> bool\"\n  \"configurations2 :: 'TSstructure2 \\<Rightarrow> 'conf2 set\"\n  \"initial_configurations2 :: 'TSstructure2 \\<Rightarrow> 'conf2 set\"\n  \"step_labels2 :: 'TSstructure2 \\<Rightarrow> 'label2 set\"\n  \"step_relation2 :: 'TSstructure2 \\<Rightarrow> 'conf2 \\<Rightarrow> 'label2 \\<Rightarrow> 'conf2 \\<Rightarrow> bool\"\n  \"effects2 :: 'TSstructure2 \\<Rightarrow> 'event2 set\"\n  \"marking_condition2 :: 'TSstructure2 \\<Rightarrow> ('label2,'conf2)derivation \\<Rightarrow> bool\"\n  \"marked_effect2 :: 'TSstructure2 \\<Rightarrow> ('label2,'conf2)derivation \\<Rightarrow> 'event2 set\"\n  \"unmarked_effect2 :: 'TSstructure2 \\<Rightarrow> ('label2,'conf2)derivation \\<Rightarrow> 'event2 set\"\n  \"relation_configuration :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'conf1 \\<Rightarrow> 'conf2 \\<Rightarrow> bool\"\n  \"relation_initial_configuration :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'conf1 \\<Rightarrow> 'conf2 \\<Rightarrow> bool\"\n  \"relation_effect :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'event1 \\<Rightarrow> 'event2 \\<Rightarrow> bool\"\n  \"relation_TSstructure :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> bool\"\n  \"relation_initial_simulation :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'conf1 \\<Rightarrow> (nat \\<Rightarrow> ('label2, 'conf2) derivation_configuration option) \\<Rightarrow> bool\"\n  \"relation_step_simulation :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'conf1 \\<Rightarrow> 'label1 \\<Rightarrow> 'conf1 \\<Rightarrow> 'conf2 \\<Rightarrow> (nat \\<Rightarrow> ('label2, 'conf2) derivation_configuration option) \\<Rightarrow> bool\"\n  for\n    TSstructure1 configurations1 initial_configurations1 step_labels1 step_relation1 effects1 marking_condition1 marked_effect1 unmarked_effect1 TSstructure2 configurations2 initial_configurations2 step_labels2 step_relation2 effects2 marking_condition2 marked_effect2 unmarked_effect2 relation_configuration relation_initial_configuration relation_effect relation_TSstructure relation_initial_simulation relation_step_simulation\n    +\n\nassumes AX_relation_step_simulation_preserves_unmarked_effect: \"\n  relation_step_simulation_preservation G1 G2 d1' d2'\n  \\<Longrightarrow> left_total_on\n        (relation_effect G1 G2)\n        (unmarked_effect1 G1 d1')\n        (unmarked_effect2 G2 d2')\"\n\nassumes AX_relation_initial_simulation_preserves_unmarked_effect: \"\n  relation_initial_simulation_preservation G1 G2 d1' d2'\n  \\<Longrightarrow> left_total_on\n        (relation_effect G1 G2)\n        (unmarked_effect1 G1 d1')\n        (unmarked_effect2 G2 d2')\"\n\ncontext ATS_Simulation_Configuration_Weak_Unmarked_Effect begin\n\ntheorem ATS_Simulation_Configuration_Weak_Unmarked_Effect_sound: \"\n  relation_TSstructure G1 G2\n  \\<Longrightarrow> left_total_on (relation_effect G1 G2) (GL.finite_unmarked_language G1) (GR.finite_unmarked_language G2)\"\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac a)(*strict*)\n  apply(simp add: GL.finite_unmarked_language_def)\n  apply(clarsimp)\n  apply(rename_tac a d x)(*strict*)\n  apply(case_tac x)\n   apply(rename_tac a d x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac a d)(*strict*)\n   apply(subgoal_tac \"\\<exists>c. d 0 = Some (pair None c)\")\n    apply(rename_tac a d)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac a d c)(*strict*)\n    apply(rename_tac c1)\n    apply(rename_tac a d c1)(*strict*)\n    apply(subgoal_tac \"c1 \\<in> initial_configurations1 G1\")\n     apply(rename_tac a d c1)(*strict*)\n     prefer 2\n     apply(simp add: GL.derivation_initial_def)\n    apply(rename_tac a d c1)(*strict*)\n    apply(subgoal_tac \"\\<exists>ds n. GR.derivation_initial G2 ds \\<and> relation_initial_configuration G1 G2 c1 (the(get_configuration(ds 0))) \\<and> relation_initial_simulation G1 G2 c1 ds \\<and> maximum_of_domain ds n \\<and> relation_configuration G1 G2 c1 (the(get_configuration(ds n)))\")\n     apply(rename_tac a d c1)(*strict*)\n     prefer 2\n     apply(rule AX_relation_initial_simulation)\n      apply(rename_tac a d c1)(*strict*)\n      apply(force)\n     apply(rename_tac a d c1)(*strict*)\n     apply(force)\n    apply(rename_tac a d c1)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac a d c1 ds n)(*strict*)\n    apply(subgoal_tac \"\\<exists>c2. ds 0 = Some (pair None c2)\")\n     apply(rename_tac a d c1 ds n)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac a d c1 ds n c2)(*strict*)\n     apply(subgoal_tac \"left_total_on (relation_effect G1 G2) (unmarked_effect1 G1 (derivation_append (der1 c1) (der1 c1) 0)) (unmarked_effect2 G2 (derivation_append (der1 (the(get_configuration(ds 0)))) ds 0))\")\n      apply(rename_tac a d c1 ds n c2)(*strict*)\n      prefer 2\n      apply(rule AX_relation_initial_simulation_preserves_unmarked_effect)\n      apply(rule relation_initial_simulation_preservation_PROVE)\n                   apply(rename_tac a d c1 ds n c2)(*strict*)\n                   prefer 13\n                   apply(force)\n                  apply(rename_tac a d c1 ds n c2)(*strict*)\n                  prefer 12\n                  apply(force)\n                 apply(rename_tac a d c1 ds n c2)(*strict*)\n                 apply(force)\n                apply(rename_tac a d c1 ds n c2)(*strict*)\n                apply(force)\n               apply(rename_tac a d c1 ds n c2)(*strict*)\n               apply(force)\n              apply(rename_tac a d c1 ds n c2)(*strict*)\n              apply(force)\n             apply(rename_tac a d c1 ds n c2)(*strict*)\n             apply(simp add: GL.derivation_initial_def)\n             apply(rule conjI)\n              apply(rename_tac a d c1 ds n c2)(*strict*)\n              apply(rule GL.der1_is_derivation)\n             apply(rename_tac a d c1 ds n c2)(*strict*)\n             apply(simp add: der1_def)\n            apply(rename_tac a d c1 ds n c2)(*strict*)\n            apply(rule der1_maximum_of_domain)\n           apply(rename_tac a d c1 ds n c2)(*strict*)\n           apply(simp add: GR.derivation_initial_def)\n           apply(rule conjI)\n            apply(rename_tac a d c1 ds n c2)(*strict*)\n            apply(rule GR.der1_is_derivation)\n           apply(rename_tac a d c1 ds n c2)(*strict*)\n           apply(simp add: der1_def get_configuration_def)\n          apply(rename_tac a d c1 ds n c2)(*strict*)\n          apply(rule der1_maximum_of_domain)\n         apply(rename_tac a d c1 ds n c2)(*strict*)\n         apply(simp add: der1_def get_configuration_def)\n        apply(rename_tac a d c1 ds n c2)(*strict*)\n        apply(simp add: derivation_append_fit_def der1_def)\n       apply(rename_tac a d c1 ds n c2)(*strict*)\n       apply(simp add: derivation_append_fit_def der1_def get_configuration_def)\n      apply(rename_tac a d c1 ds n c2)(*strict*)\n      apply(rule_tac\n      t=\"Some (pair None c2)\"\n      and s=\"ds 0\"\n      in ssubst)\n       apply(rename_tac a d c1 ds n c2)(*strict*)\n       apply(simp add: derivation_append_fit_def der1_def get_configuration_def)\n      apply(rename_tac a d c1 ds n c2)(*strict*)\n      apply(rule simulating_derivation_exist_initial)\n          apply(rename_tac a d c1 ds n c2)(*strict*)\n          apply(force)\n         apply(rename_tac a d c1 ds n c2)(*strict*)\n         apply(force)\n        apply(rename_tac a d c1 ds n c2)(*strict*)\n        apply(force)\n       apply(rename_tac a d c1 ds n c2)(*strict*)\n       apply(force)\n      apply(rename_tac a d c1 ds n c2)(*strict*)\n      apply(force)\n     apply(rename_tac a d c1 ds n c2)(*strict*)\n     apply(subgoal_tac \"left_total_on (relation_effect G1 G2) (unmarked_effect1 G1 d) (unmarked_effect2 G2 ds)\")\n      apply(rename_tac a d c1 ds n c2)(*strict*)\n      prefer 2\n      apply(rule_tac\n      t=\"d\"\n      and s=\"derivation_append (der1 c1) (der1 c1) 0\"\n      in ssubst)\n       apply(rename_tac a d c1 ds n c2)(*strict*)\n       apply(rule ext)\n       apply(rename_tac a d c1 ds n c2 x)(*strict*)\n       apply(simp add: derivation_append_def der1_def)\n       apply(clarsimp)\n       apply (metis GL.derivation_initial_is_derivation GL.noSomeAfterMaxDom)\n      apply(rename_tac a d c1 ds n c2)(*strict*)\n      apply(rule_tac\n      t=\"ds\"\n      and s=\"derivation_append (der1 (the (get_configuration (Some (pair None c2))))) ds 0\"\n      in ssubst)\n       apply(rename_tac a d c1 ds n c2)(*strict*)\n       apply(rule ext)\n       apply(rename_tac a d c1 ds n c2 x)(*strict*)\n       apply(simp add: derivation_append_def der1_def get_configuration_def)\n      apply(rename_tac a d c1 ds n c2)(*strict*)\n      apply(force)\n     apply(rename_tac a d c1 ds n c2)(*strict*)\n     apply(thin_tac \"left_total_on (relation_effect G1 G2) (unmarked_effect1 G1 (derivation_append (der1 c1) (der1 c1) 0)) (unmarked_effect2 G2 (derivation_append (der1 (the (get_configuration (ds 0)))) ds 0))\")\n     apply(rename_tac a d c1 ds n c2)(*strict*)\n     apply(simp add: left_total_on_def)\n     apply(erule_tac\n      x=\"a\"\n      in ballE)\n      apply(rename_tac a d c1 ds n c2)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac a d c1 ds n c2 b)(*strict*)\n      apply(rule_tac\n      x=\"b\"\n      in bexI)\n       apply(rename_tac a d c1 ds n c2 b)(*strict*)\n       apply(force)\n      apply(rename_tac a d c1 ds n c2 b)(*strict*)\n      apply(simp add: GR.finite_unmarked_language_def)\n      apply(rule_tac\n      x=\"ds\"\n      in exI)\n      apply(clarsimp)\n      apply (metis)\n     apply(rename_tac a d c1 ds n c2)(*strict*)\n     apply(force)\n    apply(rename_tac a d c1 ds n)(*strict*)\n    apply (metis GR.derivation_initial_is_derivation GR.some_position_has_details_at_0)\n   apply(rename_tac a d)(*strict*)\n   apply (metis GL.derivation_initial_is_derivation GL.some_position_has_details_at_0)\n  apply(rename_tac a d x nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac a d nat)(*strict*)\n  apply(rename_tac x)\n  apply(rename_tac a d x)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d x = Some (pair e1 c1) \\<and> d (Suc x) = Some (pair (Some e2) c2) \\<and> step_relation1 G1 c1 e2 c2\")\n   apply(rename_tac a d x)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc x\"\n      in GL.step_detail_before_some_position)\n     apply(rename_tac a d x)(*strict*)\n     apply(rule GL.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac a d x)(*strict*)\n    apply(simp add: maximum_of_domain_def)\n   apply(rename_tac a d x)(*strict*)\n   apply(force)\n  apply(rename_tac a d x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac a d x e1 e2 c1 c2)(*strict*)\n  apply(rename_tac e0 e1 c1 c1')\n  apply(rename_tac a d x e0 e1 c1 c1')(*strict*)\n  apply(subgoal_tac \"\\<exists>d2 n2 f. GR.derivation_initial G2 d2 \\<and> maximum_of_domain d2 n2 \\<and> relation_initial_configuration G1 G2 (the(get_configuration(d 0))) (the(get_configuration(d2 0))) \\<and> relation_configuration G1 G2 c1 (the(get_configuration(d2 n2))) \\<and> simulating_derivation G1 G2 d x d2 n2 f\")\n   apply(rename_tac a d x e0 e1 c1 c1')(*strict*)\n   prefer 2\n   apply(rule ATS_Simulation_Configuration_Weak_simulation_derivation_exists_witness)\n     apply(rename_tac a d x e0 e1 c1 c1')(*strict*)\n     apply(force)\n    apply(rename_tac a d x e0 e1 c1 c1')(*strict*)\n    apply(force)\n   apply(rename_tac a d x e0 e1 c1 c1')(*strict*)\n   apply(force)\n  apply(rename_tac a d x e0 e1 c1 c1')(*strict*)\n  apply(clarsimp)\n  apply(rename_tac a d x e0 e1 c1 c1' d2 n2 xa)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d2 n2 = Some (pair e c)\")\n   apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e c)(*strict*)\n   apply(rename_tac c2)\n   apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e c2)(*strict*)\n   apply(subgoal_tac \"\\<exists>ds n. GR.derivation G2 ds \\<and> GR.belongs G2 ds \\<and> the(get_configuration(ds 0)) = c2 \\<and> relation_step_simulation G1 G2 c1 e1 c1' c2 ds \\<and> maximum_of_domain ds n \\<and> relation_configuration G1 G2 c1' (the(get_configuration(ds n)))\")\n    apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e c2)(*strict*)\n    prefer 2\n    apply(rule AX_relation_step_simulation)\n       apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e c2)(*strict*)\n       apply(force)\n      apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e c2)(*strict*)\n      apply(simp add: get_configuration_def)\n     apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e c2)(*strict*)\n     apply (metis GL.belongs_step_labels GL.derivation_initial_belongs AX_TSstructure_relation_TSstructure1_belongs)\n    apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e c2)(*strict*)\n    apply(force)\n   apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e c2)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n)(*strict*)\n   apply(subgoal_tac \"\\<exists>c2. ds 0 = Some (pair None c2)\")\n    apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n    apply(subgoal_tac \"left_total_on (relation_effect G1 G2) (unmarked_effect1 G1 (derivation_append SSd1 (der2 c1 e1 c1') SSn1)) (unmarked_effect2 G2 (derivation_append SSd2 ds SSn2))\" for SSd1 SSn1 SSd2 SSn2)\n     apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n     prefer 2\n     apply(rule AX_relation_step_simulation_preserves_unmarked_effect)\n     apply(rule_tac\n      ?d1.0=\"derivation_take d x\"\n      and ?d2.0=\"d2\"\n      and ?n1.0=\"x\"\n      and ?n2.0=\"n2\"\n      and f=\"\\<lambda>a. if a \\<le> x then f a else f x + n\"\n      in relation_step_simulation_preservation_PROVE)\n                    apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n                    prefer 14\n                    apply(force)\n                   apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n                   prefer 14\n                   apply(force)\n                  apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n                  apply(force)\n                 apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n                 apply(force)\n                apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n                apply (metis GL.belongs_step_labels GL.derivation_initial_belongs AX_TSstructure_relation_TSstructure1_belongs)\n               apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n               apply(force)\n              apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n              apply(simp add: get_configuration_def)\n             apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n             apply(force)\n            apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n            apply (metis GL.derivation_take_preserves_derivation_initial)\n           apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n           apply (metis GL.derivationNoFromNone GL.derivation_initial_is_derivation maximum_of_domain_derivation_take)\n          apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n          apply(force)\n         apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n         apply(force)\n        apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n        apply(simp add: get_configuration_def derivation_take_def)\n       apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n       apply(simp add: derivation_append_fit_def derivation_take_def der2_def)\n      apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n      apply(simp add: derivation_append_fit_def get_configuration_def)\n     apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n     apply(rule simulating_derivation_exist_step)\n                 apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n                 apply(force)+\n    apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n    apply(subgoal_tac \"left_total_on (relation_effect G1 G2) (unmarked_effect1 G1 d) (unmarked_effect2 G2 (derivation_append d2 ds n2))\")\n     apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n     prefer 2\n     apply(rule_tac\n      t=\"d\"\n      and s=\"(derivation_append (derivation_take d x) (der2 c1 e1 c1') x)\"\n      in ssubst)\n      apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n      apply(rule ext)\n      apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 xa)(*strict*)\n      apply(simp add: derivation_append_def derivation_take_def der2_def)\n      apply(case_tac \"xa-x\")\n       apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 xa)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 xa nat)(*strict*)\n      apply(clarsimp)\n      apply(case_tac nat)\n       apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 xa nat)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 xa)(*strict*)\n       apply(subgoal_tac \"Suc x=xa\")\n        apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 xa)(*strict*)\n        prefer 2\n        apply(force)\n       apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 xa)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 xa nat nata)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 xa nata)(*strict*)\n      apply(subgoal_tac \"xa=x+Suc(Suc nata)\")\n       apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 xa nata)(*strict*)\n       prefer 2\n       apply(force)\n      apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 xa nata)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 nata)(*strict*)\n      apply(rule GL.none_position_after_max_dom)\n        apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 nata)(*strict*)\n        apply(rule GL.derivation_initial_is_derivation)\n        apply(force)\n       apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 nata)(*strict*)\n       apply(force)\n      apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 nata)(*strict*)\n      apply(force)\n     apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n     apply(force)\n    apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n    apply(thin_tac \"left_total_on (relation_effect G1 G2) (unmarked_effect1 G1 (derivation_append (derivation_take d x) (der2 c1 e1 c1') x)) (unmarked_effect2 G2 (derivation_append d2 ds n2))\")\n    apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n    apply(simp add: left_total_on_def)\n    apply(erule_tac\n      x=\"a\"\n      in ballE)\n     apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 b)(*strict*)\n     apply(rule_tac\n      x=\"b\"\n      in bexI)\n      apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 b)(*strict*)\n      apply(force)\n     apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 b)(*strict*)\n     apply(simp add: GR.finite_unmarked_language_def)\n     apply(rule_tac\n      x=\"derivation_append d2 ds n2\"\n      in exI)\n     apply(clarsimp)\n     apply(rule context_conjI)\n      apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 b)(*strict*)\n      apply(rule GR.derivation_append_preserves_derivation_initial)\n        apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 b)(*strict*)\n        apply (metis AX_TSstructure_relation_TSstructure2_belongs)\n       apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 b)(*strict*)\n       apply(force)\n      apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 b)(*strict*)\n      apply(rule GR.derivation_append_preserves_derivation)\n        apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 b)(*strict*)\n        apply(rule GR.derivation_initial_is_derivation)\n        apply(force)\n       apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 b)(*strict*)\n       apply(force)\n      apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 b)(*strict*)\n      apply(clarsimp)\n      apply(simp add: get_configuration_def)\n     apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2 b)(*strict*)\n     apply(rule_tac\n      x=\"n2+n\"\n      in exI)\n     apply (metis concat_has_max_dom)\n    apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n c2)(*strict*)\n    apply(force)\n   apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f e ds n)(*strict*)\n   apply (metis GR.some_position_has_details_at_0)\n  apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f)(*strict*)\n  apply(rule GR.some_position_has_details_before_max_dom)\n    apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f)(*strict*)\n    apply(rule GR.derivation_initial_is_derivation)\n    apply(force)\n   apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f)(*strict*)\n   apply(force)\n  apply(rename_tac a d x e0 e1 c1 c1' d2 n2 f)(*strict*)\n  apply(force)\n  done\n\nend\n\nend\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_06_06/L_ATS_Simulation_Configuration_WeakLR_Unmarked_Effect.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982043529715, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.2811324136224378}}
{"text": "(* LLVM.thy *)\n(* William Mansky *)\n(* MiniLLVM for VeriF-OPT. *)\n\ntheory LLVM\nimports trans_flowgraph AxiomaticModel step_rel\nbegin\n\n(* Maybe I shouldn't have this\ntype_synonym 'a pat = \"('a, string)literal\"\n*)\n\n(* Syntax *)\ndatatype element_flag = ReadFlag | WriteFlag | RMWFlag | FenceFlag | ControlFlag | CallFlag\n\ndatatype ('thread, 'loc, 'val) access = Read 'thread 'loc 'val | Write 'thread 'loc 'val \n  | ARW 'thread 'loc 'val 'val | Alloc 'thread 'loc | Free 'thread 'loc\n\ndatatype LLVM_type = Int_ty | (* Float_ty | Void_ty | Label_ty | Array_ty nat LLVM_type (\"[_ \\<times> _]\") |*)\n(* Structure? | *) Pointer_ty LLVM_type (\"_*\")  (* Ignoring size for now. *)\n| Array_ty nat LLVM_type (\"[_ \\<times> _]\")\n\ndatatype 'mvar LLVM_type_pat = PInt_ty | Tymvar 'mvar | PPointer_ty \"'mvar LLVM_type_pat\"\n  | PArray_ty nat \"'mvar LLVM_type_pat\"\n\nprimrec LLVM_type_lit_fv where\n   \"LLVM_type_lit_fv PInt_ty = {}\"\n | \"LLVM_type_lit_fv (Tymvar x) = {x}\"\n | \"LLVM_type_lit_fv (PPointer_ty ty) = LLVM_type_lit_fv ty\"\n | \"LLVM_type_lit_fv (PArray_ty x ty) = LLVM_type_lit_fv ty\"\n\nlemma finite_LLVM_type_lit_fv [simp]: \"finite (LLVM_type_lit_fv ty)\"\nby (induct_tac ty, auto)\n\ndatatype ('loc,'int) LLVM_const = CInt 'int | (* Float? | *) CNull (* | CArray \"(LLVM_type \\<times> LLVM_const) list\" *) | \n CPointer 'loc | CUndef | CArray \"('loc,'int) LLVM_const list\"\n(* Poison values? *)\n\n(* defining the size of a non-atomic reads/writes *)\ndefinition fixedIntSize :: \"nat\" where\n\"fixedIntSize = 4\"\n\nfun LLVM_sizeof where\n\"LLVM_sizeof Int_ty = fixedIntSize\"\n| \"LLVM_sizeof (b*) = fixedIntSize\"\n| \"LLVM_sizeof ([a\\<times>b]) = a * (LLVM_sizeof b)\"\n\ntype_synonym concrete_LLVM_const = \"(int, int)LLVM_const\"\ntype_synonym 'mvar gen_LLVM_const = \"((int,'mvar)literal,(int,'mvar)literal) LLVM_const\"\n\nfun LLVM_const_lit_fv where\n   \"LLVM_const_lit_fv (CInt ip) = base_lit_fv ip\"\n | \"LLVM_const_lit_fv CNull = {}\"\n | \"LLVM_const_lit_fv (CPointer lp) = base_lit_fv lp\"\n | \"LLVM_const_lit_fv CUndef = {}\"\n | \"LLVM_const_lit_fv (CArray il) = (\\<Union>e\\<in>set il.  LLVM_const_lit_fv e)\"\n\nlemma finite_LLVM_const_lit_fv [simp]: \n  \"finite (LLVM_const_lit_fv c)\"\n  by (induct_tac c, auto)\n\n(* from PL prospective, LLVM global and local variables have no difference after parsing.\n   They are just identifier for names, since MiniLLVM will not have levels outisde of a function,\n    it is useless to have the two difference. *)\ndatatype ('var, 'cvar) LLVM_expr =\n    Var 'var (\"%_\")\n  | Const \"'cvar\"\n (* | Global 'gvar string*) (*(\"@_\")*) (* | Constant expressions? *)\n\ntype_synonym concrete_LLVM_expr = \"(string, concrete_LLVM_const) LLVM_expr\"\ntype_synonym 'mvar gen_LLVM_expr = \"('mvar, ('mvar gen_LLVM_const, 'mvar)literal) LLVM_expr\"\ntype_synonym 'mvar LLVM_expr_pat = \"('mvar gen_LLVM_expr,'mvar) expr_pattern\"\n\n(* datatype of have var and pointer togeter *)\ndatatype ('loc, 'var) twoVar = TheVar 'var | TheLoc 'loc\n\n\n(* If we are calculating free variables, then we are dealing with patterns,\n   ie things with \"literals\" --ELG *)\n\nprimrec expr_fv :: \"'mvar gen_LLVM_expr \\<Rightarrow> 'mvar set\" where\n\"expr_fv (Var x) = {x}\" |\n\"expr_fv (Const c) = lit_fv LLVM_const_lit_fv c\"\n\nlemma finite_expr_fv [simp]:\nfixes e shows \"finite (expr_fv e)\"\nby (case_tac e, auto)\n\ncorollary finite_expr_pattern_fv:\nfixes ep shows \"finite (expr_pattern_fv expr_fv ep)\"\nby simp\n\nprimrec expr_lfv :: \"concrete_LLVM_expr \\<Rightarrow> string set\" where\n\"expr_lfv (Var x) = {x}\" |\n\"expr_lfv (Const c) = {}\" \n\ndatatype LLVM_op = add | sub | mul\ndatatype LLVM_cmp = eq | ne | sgt | sge | slt | sle\ndatatype LLVM_order = monotonic | acquire | release | acqrel | seqcst\n\nfun tranOrder where\n\"tranOrder monotonic = Relaxed\"\n| \"tranOrder acquire = Acquire\"\n| \"tranOrder release = Release\"\n| \"tranOrder acqrel = AcqRel\"\n| \"tranOrder seqcst = SeqCst\"\n\nabbreviation eplist_fv :: \"'mvar LLVM_expr_pat list \\<Rightarrow> 'mvar set\" where\n\"eplist_fv \\<equiv> \\<lambda> epl. foldr\n (\\<lambda> ep vs. (expr_pattern_fv expr_fv ep) \\<union> vs) epl {}\"\n\nabbreviation eplist_lfv :: \"concrete_LLVM_expr list \\<Rightarrow> string set\" where\n\"eplist_lfv \\<equiv> \\<lambda> epl. foldr (\\<lambda> ep vs. (expr_lfv ep) \\<union> vs) epl {}\"\n\nlemma finite_eplist_fv [simp]:\nfixes epl shows \"finite (eplist_fv epl)\"\nby (induct \"epl\", auto)\n\n(*\ntype_synonym 'thread gen_node = \"(('thread, string) literal) node_const\"\n\nterm \"(x::('thread gen_node, string) literal)\"\n*)\n\ntype_synonym 'node concrete_philist = \"('node \\<times> concrete_LLVM_expr) list\"\ntype_synonym 'mvar gen_philist = \"(('mvar node_const,'mvar)literal  \\<times> ('mvar LLVM_expr_pat))list\"\n\nabbreviation philist_fv :: \"'mvar gen_philist \\<Rightarrow> 'mvar set\" where\n\"philist_fv \\<equiv> \\<lambda> es. foldr (\\<lambda>(n, e) r. lit_fv node_fv n \\<union> expr_pattern_fv expr_fv e \\<union> r) es {}\"\n\nlemma finite_philist_fv [simp]:\nfixes phi_list  shows \"finite (philist_fv phi_list)\"\nby (induct \"phi_list\", auto)\n\nterm \"expr_lfv\"\nabbreviation philist_lfv :: \"'node concrete_philist \\<Rightarrow> string set\" where\n\"philist_lfv \\<equiv> \\<lambda> es. foldr (\\<lambda>(n, e) r. expr_lfv e \\<union> r) es {}\"\n\ndefinition mapSetCon where\n\"mapSetCon S f = (\\<Union> s \\<in> S . f s)\"\n\n(* TODO: better concrete syntax *)\ndatatype ('var, 'type, 'expr, 'opr, 'cmp, 'phi_list, 'args) LLVM_instr =\n   Assign 'var 'opr 'type 'expr 'expr (\"_ = _ _ _, _\" 160)\n | Ret 'type 'expr\n | Br_i1 'expr(* conditional branch *)\n | Br_label (* unconditional *)\n (* two ops dealing with inserting a value to an array and extracting value from an array *)\n | Extract_value 'var 'type 'expr \"nat list\" (* array type, value, index list natural number list *)\n | Insert_value 'var 'type 'expr 'type 'expr \"nat list\" (* array type , value, element type value, index list*)\n(* Note that, since control flow is implicit in the function body, label targets are unnecessary. \n   Well, sort of.  If we were linking to outside things, using label names would let us refer outside\n   the context.  *)\n(* Switch | Indirectbr | Invoke | Resume | *)  \n | Malloc 'var 'type\n | Load bool 'var 'type 'expr\n | Atomic_load bool 'var 'type 'expr LLVM_order\n | Store bool 'type 'expr 'type 'expr\n | Atomic_store bool 'type 'expr 'type 'expr LLVM_order\n | LLVM_Fence LLVM_order\n | Cmpxchg bool 'var 'type 'expr 'type 'expr 'type 'expr LLVM_order(* ordering constraint *)\n | ICmp 'var 'cmp 'type 'expr 'expr (\"_ = icmp _ _ _, _\" 160) (* | Atomicrmw *)\n | Phi 'var 'type 'phi_list (*\"('node \\<times> 'expr) list\"*) (\"_ = phi _ _\" 160)  (* Select | *) \n | Call 'var 'type 'var \"'args\" (\"_ = call _ _ _\" 160)  (* list patterns? *)\n(* This might be controversial: eliminate function names entirely, indicate call target by call edge.\n   This is inadequate for 1) calls to outside functions and 2) function pointers.  *) \n (*| IsPointer 'expr why need this? *)\n | Mutex_lock 'expr (*lock on a input lock key *)\n | Mutex_unlock 'expr (* unlock on a input lock key *)\n\ndatatype returnExpr = MemWrite \"LLVM_type \\<times> (int,int) LLVM_const \\<times> int \\<times> LLVM_order option\"\n  | NoReturn\n\ndatatype 'a returnAction = NoAction\n  | MemAction \"'a list\"\n\n\ntype_synonym 'node concrete_LLVM_instr =\n\"(string, LLVM_type, concrete_LLVM_expr, LLVM_op, LLVM_cmp, 'node concrete_philist,\n  concrete_LLVM_expr list) LLVM_instr\"\n\ntype_synonym 'mvar gen_LLVM_instr =\n\"('mvar, 'mvar LLVM_type_pat,'mvar  LLVM_expr_pat, (LLVM_op, 'mvar)literal, (LLVM_cmp,'mvar)literal,\n ('mvar gen_philist,'mvar)literal, ('mvar LLVM_expr_pat list, 'mvar)literal) LLVM_instr\"\n\ntype_synonym 'mvar pattern = \"('mvar gen_LLVM_instr, 'mvar) literal\"\n\nprimrec instr_pattern_fv ::\"'mvar gen_LLVM_instr \\<Rightarrow> 'mvar set\" where\n\"instr_pattern_fv (Assign x bop ty e1 e2) =\n  {x} \\<union> LLVM_type_lit_fv ty \\<union> (base_lit_fv bop) \\<union> (expr_pattern_fv expr_fv)  e1 \\<union> (expr_pattern_fv expr_fv) e2\" |\n\"instr_pattern_fv (Ret ty e) = LLVM_type_lit_fv ty \\<union> (expr_pattern_fv expr_fv) e\" |\n\"instr_pattern_fv (Br_i1 e) = (expr_pattern_fv expr_fv) e\" |\n\"instr_pattern_fv (Br_label) = {}\" |\n\"instr_pattern_fv (Extract_value x ty e nl) = {x} \\<union> LLVM_type_lit_fv ty \\<union> (expr_pattern_fv expr_fv) e\" |\n\"instr_pattern_fv (Insert_value x ty1 e1 ty2 e2 nl) = {x} \\<union> LLVM_type_lit_fv ty1 \\<union> (expr_pattern_fv expr_fv) e1\n                                  \\<union> LLVM_type_lit_fv ty2 \\<union> (expr_pattern_fv expr_fv) e2\" |\n\"instr_pattern_fv (Load vol x ty e) = {x} \\<union> LLVM_type_lit_fv ty \\<union> (expr_pattern_fv expr_fv) e\" |\n\"instr_pattern_fv (Malloc x ty) = {x} \\<union> LLVM_type_lit_fv ty\" |\n\"instr_pattern_fv (Atomic_load vol x ty e or1) = {x} \\<union> LLVM_type_lit_fv ty \\<union> (expr_pattern_fv expr_fv) e\" |\n\"instr_pattern_fv (Store vol ty1 e1 ty2 e2) =\n  LLVM_type_lit_fv ty1 \\<union> (expr_pattern_fv expr_fv) e1 \\<union> LLVM_type_lit_fv ty2 \\<union> (expr_pattern_fv expr_fv) e2\" |\n\"instr_pattern_fv (Atomic_store vol ty1 e1 ty2 e2 or1) =\n  LLVM_type_lit_fv ty1 \\<union> (expr_pattern_fv expr_fv) e1 \\<union> LLVM_type_lit_fv ty2 \\<union> (expr_pattern_fv expr_fv) e2\" |\n\"instr_pattern_fv (Cmpxchg vol x ty1 e1 ty2 e2 ty3 e3 or1) =\n  {x} \\<union> LLVM_type_lit_fv ty1 \\<union> (expr_pattern_fv expr_fv) e1 \\<union> LLVM_type_lit_fv ty2 \\<union> (expr_pattern_fv expr_fv) e2\n   \\<union> LLVM_type_lit_fv ty3 \\<union> (expr_pattern_fv expr_fv) e3\" |\n\"instr_pattern_fv (ICmp x cop ty e1 e2) =\n  {x} \\<union> lit_fv (\\<lambda> x. {}) cop \\<union> LLVM_type_lit_fv ty \\<union> (expr_pattern_fv expr_fv) e1 \\<union> (expr_pattern_fv expr_fv) e2\" |\n\"instr_pattern_fv (Phi x ty phl) =\n  {x} \\<union> LLVM_type_lit_fv ty \\<union> lit_fv philist_fv phl\" |\n\"instr_pattern_fv (Call x ty fn el) = {x} \\<union> LLVM_type_lit_fv ty \\<union> {fn} \\<union> lit_fv eplist_fv el\" |\n\"instr_pattern_fv (LLVM_Fence or1) = {}\" |\n\"instr_pattern_fv (Mutex_lock e) = (expr_pattern_fv expr_fv) e\" |\n\"instr_pattern_fv (Mutex_unlock e) = (expr_pattern_fv expr_fv) e\"\n\nlemma finite_instr_pattern_fv [simp]:\n fixes instr shows \"finite (instr_pattern_fv instr)\"\nby (case_tac instr, auto)\n\nprimrec instr_fv where\n\"instr_fv (Assign x _ _ e1 e2) = {x} \\<union> expr_lfv e1 \\<union> expr_lfv e2\" |\n\"instr_fv (Ret _ e) = expr_lfv e\" |\n\"instr_fv (Br_i1 e) = expr_lfv e\" |\n\"instr_fv (Br_label) = {}\" |\n\"instr_fv (Extract_value x ty e nl) = {x} \\<union> expr_lfv e\" |\n\"instr_fv (Insert_value x ty1 e1 ty2 e2 nl) = {x} \\<union> expr_lfv e1 \\<union> expr_lfv e2\" |\n\"instr_fv (Malloc x _) = {x}\" |\n\"instr_fv (Load vol x _ e) = {x} \\<union> expr_lfv e\" |\n\"instr_fv (Atomic_load vol x _ e or1) = {x} \\<union> expr_lfv e\" |\n\"instr_fv (Store vol _ e1 _ e2) = expr_lfv e1 \\<union> expr_lfv e2\" |\n\"instr_fv (Atomic_store vol _ e1 _ e2 or1) = expr_lfv e1 \\<union> expr_lfv e2\" |\n\"instr_fv (Cmpxchg vol x _ e1 _ e2 _ e3 or1) = {x} \\<union> expr_lfv e1 \\<union> expr_lfv e2 \\<union> expr_lfv e3\" |\n\"instr_fv (ICmp x _ _ e1 e2) = {x} \\<union> expr_lfv e1 \\<union> expr_lfv e2\" |\n\"instr_fv (Phi x _ es) = {x} \\<union> (\\<Union>(_, e)\\<in>set es. expr_lfv e)\" |\n\"instr_fv (Call x _ v es) = {x, v} \\<union> (\\<Union>e\\<in>set es. expr_lfv e)\" |\n\"instr_fv (LLVM_Fence or1) = {}\" |\n\"instr_fv (Mutex_lock e) = expr_lfv e\" |\n\"instr_fv (Mutex_unlock e) = expr_lfv e\"\n\ndatatype 'var LLVM_decl = Global_Decl 'var concrete_LLVM_const\n\n(* We aren't bothering with linking in this pass, surely. *)\n(*datatype LLVM_function = Define LLVM_type string \"LLVM_instr list\"*)\n(* Alternatively:*)\ndatatype LLVM_edge_type = seq | true | false | proc_call | ret\n\nlemma finite_edge_types [simp]: \"finite (UNIV::LLVM_edge_type set)\"\napply (simp add: finite_conv_nat_seg_image)\napply (rule_tac x=5 in exI, rule_tac x=\"\\<lambda>n. if n = 0 then seq else if n = 1 then true else\n if n = 2 then false else if n = 3 then proc_call else ret\" in exI, auto)\napply (case_tac x, auto)\napply force\ndone\ndeclare finite_edge_types [simp del] (* Why?  ---ELG *)\n\ndatatype ('node, 'var, 'type, 'expr, 'opr, 'cmp, 'phi_list, 'args) LLVM_function =\n   Define 'type 'var \"('type \\<times> 'var) list\" \n                    \"('node, LLVM_edge_type, ('var, 'type, 'expr, 'opr, 'cmp, 'phi_list, 'args) LLVM_instr) flowgraph\"\n                     (\"define _ __ { _ }\")\n(* Basic block structure? *)\n\ndatatype ('node, 'var, 'type, 'expr, 'opr, 'cmp,'phi_list, 'args) LLVM_module = \n Module \"('node, 'var, 'type, 'expr, 'opr, 'cmp, 'phi_list, 'args) LLVM_function list\"\n(* If we do this, we still have to parse a module into a tICFG.  We might instead skip everything\n   after LLVM_instr and just work on t(I)CFGs of LLVM_instrs.  Doing this for now. *)\n\n(* TODO: Improve program model - functions *)\n\n(* Free variables *)\n\n(* tICFG for LLVM module *)\nfun LLVM_instr_edges where\n\"LLVM_instr_edges (Ret _ _) = {no_edges(ret := n) | n. True}\" |\n\"LLVM_instr_edges (Br_i1 _) = {no_edges(true := 1, false := 1)}\" |\n\"LLVM_instr_edges (Call _ _ _ _) = {no_edges(proc_call := 1, seq := 1)}\" |\n\"LLVM_instr_edges _ = {no_edges(seq := (1::nat))}\"\n\ncorollary one_seq [simp]: \"finite (Edges G) \\<Longrightarrow> (edge_types {(u, t). (n, u, t) \\<in> Edges G} = no_edges(seq := Suc 0)) = \n (\\<exists>m. (n, m, seq) \\<in> Edges G \\<and> (\\<forall>u t. (n, u, t) \\<in> Edges G \\<longrightarrow> u = m \\<and> t = seq))\"\nby (drule_tac n=n and ty=seq in out_one, auto simp add: out_edges_def)\n\nlemma out_br [simp]: \"finite (Edges G) \\<Longrightarrow> (edge_types (out_edges (Edges G) n) = \n no_edges(true := Suc 0, false := Suc 0)) = \n (\\<exists>m1 m2. out_edges (Edges G) n = {(m1, true), (m2, false)})\"\napply (rule iffI, frule_tac x=true in cong, simp, simp (no_asm_use) add: edge_types_def)\napply (frule_tac x=false in cong, simp, simp (no_asm_use) add: edge_types_def)\napply (auto simp add: card_Suc_eq)\ndone\n\n(* Hypothesis: the additional bookkeeping involved in an ICFG is redundant for our purposes. \n   Calls and returns can be stored in edge labels. *)\n(* Note that the tICFG assumes that threads execute mutually distinct code, i.e., don't execute \n   each other's procedures.   We'll run with that assumption for now. *)\n\n(* Semantics *)\n(* basic expressions *)\nabbreviation \"start_env \\<equiv> \\<lambda>x. CUndef\"\n\n\nprimrec eval_expr (*:: \"('a \\<Rightarrow> 'b LLVM_const) \\<Rightarrow> (char list \\<Rightarrow> 'b LLVM_const) \\<Rightarrow> 'a LLVM_expr \\<Rightarrow> 'b LLVM_const\" *)\nwhere\n\"eval_expr env (Var i) = env i\" | (* i::type of LLVM_expr *)\n\"eval_expr env (Const c) = c\"      (* c::LLVM_const *)\n\nterm eval_expr\n\nprimrec cmp_helper where\n\"cmp_helper eq v1 v2 = (v1 = v2)\" |\n\"cmp_helper ne v1 v2 = (v1 \\<noteq> v2)\" |\n\"cmp_helper sgt v1 v2 = (v1 > v2)\" |\n\"cmp_helper sge v1 v2 = (v1 \\<ge> v2)\" |\n\"cmp_helper slt v1 v2 = (v1 < v2)\" |\n\"cmp_helper sle v1 v2 = (v1 \\<le> v2)\"\n\nfun eval_cmp where\n\"eval_cmp env cmp e1 e2 = (case (eval_expr env e1, eval_expr env e2) of\n   (CInt v1, CInt v2) \\<Rightarrow> if cmp_helper cmp v1 v2 then CInt 1 else CInt 0\n | (CPointer v1, CPointer v2) \\<Rightarrow> if cmp_helper cmp v1 v2 then CInt 1 else CInt 0\n | _ \\<Rightarrow> CUndef)\"\n\nfun eval where\n\"eval env opr e1 e2 = (case (eval_expr env e1, eval_expr env e2) of\n (CInt v1, CInt v2) \\<Rightarrow> (case opr of add \\<Rightarrow> CInt (v1 + v2) | sub \\<Rightarrow> CInt (v1 - v2) | mul \\<Rightarrow> CInt (v1 * v2)) \n | _ \\<Rightarrow> CUndef)\"\n\n(* counting on the right element of an array *)\nfun getElement where\n\"getElement (x#xl) 0 = Some x\"\n| \"getElement (x#xl) (Suc n) = getElement xl n\"\n| \"getElement [] n = None\"\n\nfun eval_extract where\n\"eval_extract a [] = a\"\n| \"eval_extract (CArray al) (x#xl) = (case getElement al x of None \\<Rightarrow> CUndef\n                                        | Some a \\<Rightarrow> eval_extract a xl)\"\n| \"eval_extract x y = CUndef\"\n\nfun setElement where\n\"setElement a (x#xl) 0 = Some (a#xl)\"\n| \"setElement a (x#xl) (Suc n) = (case setElement a xl n of None \\<Rightarrow> None | Some al \\<Rightarrow> Some (x#al))\"\n| \"setElement a [] n = None\"\n\nfun eval_insert where\n\"eval_insert a b [] = CUndef\"\n| \"eval_insert CUndef b x = CUndef\"\n| \"eval_insert a (CArray b) [x] = (case setElement a b x of None \\<Rightarrow> CUndef | Some b' \\<Rightarrow> CArray b')\"\n| \"eval_insert a (CArray b) (x#xl) = (case getElement b x of None \\<Rightarrow> CUndef | Some b' \\<Rightarrow> eval_insert a b' xl)\"\n| \"eval_insert a b x = CUndef\"\n\n(* Copied and adapted the good bits from JinjaThreads' ToString.thy.  Why isn't this in Main? *)\nfunction digit_toString :: \"int \\<Rightarrow> string\"\nwhere\n  \"digit_toString 0 = ''0''\"\n| \"digit_toString 1 = ''1''\"\n| \"digit_toString 2 = ''2''\"\n| \"digit_toString 3 = ''3''\"\n| \"digit_toString 4 = ''4''\"\n| \"digit_toString 5 = ''5''\"\n| \"digit_toString 6 = ''6''\"\n| \"digit_toString 7 = ''7''\"\n| \"digit_toString 8 = ''8''\"\n| \"digit_toString 9 = ''9''\"\n| \"n \\<notin> {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ==> digit_toString n = undefined\"\napply(case_tac x)\napply simp_all\napply(rename_tac n', case_tac n', simp)\napply(rename_tac n', case_tac n', simp)\napply(rename_tac n', case_tac n', simp)\napply(rename_tac n', case_tac n', simp)\napply(rename_tac n', case_tac n', simp)\napply(rename_tac n', case_tac n', simp)\napply(rename_tac n', case_tac n', simp)\napply(rename_tac n', case_tac n', simp)\napply(rename_tac n', case_tac n', simp)\napply(rename_tac n', case_tac n', simp)\napply simp\ndone\ntermination by lexicographic_order\n\nfunction int_toString :: \"int \\<Rightarrow> string\"\nwhere\n  \"int_toString n = \n  (if n < 0 then ''-'' @ int_toString (- n)\n   else if n < 10 then digit_toString n\n   else int_toString (n div 10) @ digit_toString (n mod 10))\"\nby pat_completeness simp\ntermination by size_change\n\nlemma neg_int_toString [simp]: \"n < 0 \\<Longrightarrow> int_toString n = ''-'' @ int_toString (- n)\"\nby simp\n\nlemma digit_int_toString [simp]: \"\\<lbrakk>n \\<ge> 0; n < 10\\<rbrakk> \\<Longrightarrow> int_toString n = digit_toString n\"\nby simp\n\nlemma ten_int_toString [simp]: \"n \\<ge> 10 \\<Longrightarrow> int_toString n = int_toString (n div 10) @ \n  digit_toString (n mod 10)\"\nby simp\n\nlemmas int_toString.simps [simp del]\n\nlemma int_digit: \"\\<lbrakk>(i::int) \\<ge> 0; i < 10\\<rbrakk> \\<Longrightarrow> i \\<in> {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}\"\nby (case_tac i, auto)\n\nlemma one_digit: \"i \\<in> {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} \\<Longrightarrow> length (digit_toString i) = 1\"\nby auto\n\nlemma inj_digit: \"\\<lbrakk>i \\<ge> 0; i < 10; j \\<ge> 0; j < 10; digit_toString i = digit_toString j\\<rbrakk> \\<Longrightarrow> \n i = j\"\nby (drule int_digit, simp, drule int_digit, auto)\n\n(*\nlemma toString_nonempty [simp]: \"int_toString i \\<noteq> []\"\napply (induct rule: int_toString.induct)\napply (case_tac \"n < 0\", simp)\napply (case_tac \"n < 10\", simp)\napply (cut_tac i=n in one_digit [OF int_digit], simp+)\napply (case_tac \"digit_toString n\", simp, simp)\napply (simp only: ten_int_toString)\nby (metis Nil_is_append_conv)\n*)\n\nabbreviation \"nat_toString n \\<equiv> int_toString (int n)\"\n\nlemma inj_toString: \"\\<lbrakk>int_toString x = int_toString y; x \\<ge> 0; y \\<ge> 0\\<rbrakk> \\<Longrightarrow> x = y\"\noops\n\n(* For now, a bogus calling convention: arguments are named arg0, etc. instead of\n   using function definitions and formal parameter names. *)\nprimrec init_env_aux where\n\"init_env_aux _ [] _ = start_env\" |\n\"init_env_aux env (e # rest) n = (init_env_aux env rest (Suc n))((''arg'' @ nat_toString n) := eval_expr env e)\"\nabbreviation \"init_env env args \\<equiv> init_env_aux env args 0\"\n\n(* gen new varMap and loactionMap *)\nabbreviation \"initLocMap \\<equiv> \\<lambda> x . {}\"\nprimrec initVarMapAux where\n\"initVarMapAux [] _ n = (\\<lambda> x . {})\" |\n\"initVarMapAux (e#rest) memVarMap n =\n    (initVarMapAux rest memVarMap (Suc n))((''arg'' @ nat_toString n) := mapSetCon (expr_lfv e) memVarMap)\"\nabbreviation \"initVarMap args memVarMap \\<equiv> initVarMapAux args memVarMap 0\"\nabbreviation \"allVars args \\<equiv> foldl (\\<lambda> a b . a \\<union> expr_lfv b) {} args\"\n\nterm \"seq\"\nlocale LLVM_flowgraph = flowgraph\n where Nodes = \"Nodes :: 'node set\"\n   and Start = \"Start :: 'node\" \n   and Exit =\"Exit ::'node\" \n   and Edges = \"Edges :: ('node \\<times> 'node \\<times> LLVM_edge_type) set\" \n   and L = \"L::'node \\<Rightarrow> ('var, 'type, 'expr, 'opr, 'cmp, 'phi_list, 'args) LLVM_instr\"\n   and instr_edges=LLVM_instr_edges\n   and Seq=\"seq::LLVM_edge_type\"\n for Nodes and Start and Exit and Edges and L\n\nlocale LLVM_tCFG = tCFG\n  where CFGs = \"CFGs::'thread \\<Rightarrow> ('node, LLVM_edge_type,\n                               ('var, 'type, 'expr, 'opr, 'cmp, 'phi_list, 'args) LLVM_instr) flowgraph option\" \n and instr_edges=LLVM_instr_edges\n and Seq=seq\n for CFGs\nbegin\n\nlemma LLVM_graph [simp, intro]: \"CFGs t = Some G \\<Longrightarrow> \n LLVM_flowgraph (Nodes G) (Start G) (Exit G) (Edges G) (Label G)\"\napply (frule CFGs, simp add: is_flowgraph_def flowgraph_def pointed_graph_def flowgraph_axioms_def)\napply (unfold_locales, auto)\napply force\napply force\n  done\n\n(*\nlemma abc :  \"finite a \\<and> finite b \\<Longrightarrow> finite (a \\<union> b)\"\n  by simp\n*)\n\nend\n\n(* in-order LLVM execution model *)\nlocale LLVM_MM = memory_model\n where actions =  \"actions :: (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action set\"\n    and locations = \"locations :: loc_type set\"\n    and actionIDs = \"actionIDs :: aid_type set\"\n    and times = \"times :: time_type set\"\n    and threads = \"threads :: 'tid set\"\n    and locks = \"locks :: 'lock set\"\n    and names = \"names :: 'name set\"\n    and callIDs = \"callIDs :: 'callID set\" \n    and free_set = \"free_set:: (('tid \\<times> time_type \\<times> loc_type)\n            \\<Rightarrow> (aid_type \\<times> (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action) option)\n             \\<Rightarrow> time_type \\<Rightarrow> loc_type set\"\n    and can_read = \"can_read:: (('tid \\<times> time_type \\<times> loc_type)\n            \\<Rightarrow> (aid_type \\<times> (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action) option)\n                 \\<Rightarrow> 'tid \\<Rightarrow> time_type \\<Rightarrow> loc_type \\<Rightarrow> 'val set\"\n    and update_mem = \"update_mem:: (('tid \\<times> time_type \\<times> loc_type)\n            \\<Rightarrow> (aid_type \\<times> (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action) option)\n                       \\<Rightarrow> time_type \\<Rightarrow> ('tid \\<times> aid_type \\<times>\n                             (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action) set\n                        \\<Rightarrow> (('tid \\<times> time_type \\<times> loc_type)\n            \\<Rightarrow> (aid_type \\<times> (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action) option) \\<Rightarrow> bool\"\n    and start_mem = \"start_mem:: (('tid \\<times> time_type \\<times> loc_type)\n            \\<Rightarrow> (aid_type \\<times> (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action) option)\"\n  for actions locations actionIDs times threads locks names callIDs \n         free_set can_read update_mem start_mem\n\nlocale LLVM = LLVM_flowgraph (* ASSUMED INT *)\n where Nodes = \"Nodes :: 'node set\"\n   and Start = \"Start :: 'node\" \n   and Exit =\"Exit ::'node\" \n   and Edges = \"Edges :: ('node \\<times> 'node \\<times> LLVM_edge_type) set\" \n   and L=\"L::'node \\<Rightarrow> 'node concrete_LLVM_instr\" + \n LLVM_MM\n where actions =  \"actions :: (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action set\"\n    and locations = \"locations :: loc_type set\"\n    and actionIDs = \"actionIDs :: aid_type set\"\n    and times = \"times :: time_type set\"\n    and threads = \"threads :: 'tid set\"\n    and locks = \"locks :: 'lock set\"\n    and names = \"names :: 'name set\"\n    and callIDs = \"callIDs :: 'callID set\" \n    and free_set = \"free_set:: (('tid \\<times> time_type \\<times> loc_type)\n            \\<Rightarrow> (aid_type \\<times> (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action) option)\n             \\<Rightarrow> time_type \\<Rightarrow> loc_type set\"\n    and can_read = \"can_read:: (('tid \\<times> time_type \\<times> loc_type)\n            \\<Rightarrow> (aid_type \\<times> (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action) option)\n                 \\<Rightarrow> 'tid \\<Rightarrow> time_type \\<Rightarrow> loc_type \\<Rightarrow> 'val set\"\n    and update_mem = \"update_mem:: (('tid \\<times> time_type \\<times> loc_type)\n            \\<Rightarrow> (aid_type \\<times> (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action) option)\n                       \\<Rightarrow> time_type \\<Rightarrow> ('tid \\<times> aid_type \\<times>\n                             (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action) set\n                        \\<Rightarrow> (('tid \\<times> time_type \\<times> loc_type)\n            \\<Rightarrow> (aid_type \\<times> (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action) option) \\<Rightarrow> bool\"\n    and start_mem = \"start_mem:: (('tid \\<times> time_type \\<times> loc_type)\n            \\<Rightarrow> (aid_type \\<times> (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action) option)\"\n  for Nodes Start Exit Edges L actions locations actionIDs times threads locks names callIDs \n         free_set can_read update_mem start_mem\nbegin\n\n(* first define semantics for each line of MiniLLVM instruction. step semantics *)\n\ninductive LLVM_step :: \"'tid \\<Rightarrow> (int \\<Rightarrow> (int, int) LLVM_const)\n            \\<Rightarrow> 'note \\<times>\n               'node \\<times>\n               (char list \\<Rightarrow> (int, int) LLVM_const) \\<times>\n               ('node \\<times> char list \\<times> (char list \\<Rightarrow> (int, int) LLVM_const)) list \\<times> int set \\<times> (int \\<Rightarrow> 'tid option)\n               \\<Rightarrow> (aid_type, (int, int) LLVM_const, int, int, char list, int) AxiomaticModel.action set\n                  \\<Rightarrow> 'node \\<times>\n                     'node \\<times>\n                     (char list \\<Rightarrow> (int, int) LLVM_const) \\<times>\n                     ('node \\<times> char list \\<times> (char list \\<Rightarrow> (int, int) LLVM_const)) list \\<times> int set \\<times> (int \\<Rightarrow> 'tid option)\n                     \\<Rightarrow> bool\" where\nassign [intro]: \"\\<lbrakk>L p = Assign x opr ty e1 e2;p \\<noteq> Exit\\<rbrakk> \\<Longrightarrow>\n      LLVM_step (tid::'tid) mem ((p0::'note), p, env, stack,alloced, lockMap) {}\n    (p,next_node Edges seq p,env(x := eval env opr e1 e2), stack, alloced,lockMap)\" |\nret_pop [intro]: \"\\<lbrakk>L p = Ret ty e;p \\<noteq> Exit; (p, ret_addr, ret) \\<in> Edges\\<rbrakk> \\<Longrightarrow> \n LLVM_step tid mem (_,p, env, (ret_addr, ret_var, ret_env) # rest,alloced,lockMap) {CallFence name 0}\n         (p,ret_addr, ret_env(ret_var := eval_expr env  e), rest, alloced,lockMap)\" |\nret_main [intro]: \"\\<lbrakk>L p = Ret ty e; p \\<noteq> Exit; (p, Exit, ret) \\<in> Edges\\<rbrakk> \\<Longrightarrow> \n LLVM_step tid mem (_,p, env, [], alloced,lockMap) {}\n (p,Exit, env, [], alloced,lockMap)\" (* what to do when main function returns? *) |\nbranch_i [intro]: \"\\<lbrakk> L p = Br_i1 e; p \\<noteq> Exit\\<rbrakk> \\<Longrightarrow>\n   LLVM_step tid mem  (_,p, env, stack,alloced,lockMap) {ControlFence}\n (p,next_node Edges (if eval_expr env  e = CInt 0 then false else true) p,\n       env, stack, alloced,lockMap)\" |\nbranch_u [intro]: \"\\<lbrakk> L p = Br_label; p \\<noteq> Exit\\<rbrakk> \\<Longrightarrow>\n   LLVM_step tid mem (_,p, env, stack,alloced,lockMap) {}\n ( p,next_node Edges seq p, env, stack, alloced,lockMap)\"|\nextract_v [intro]: \"\\<lbrakk> L p = Extract_value x ty e1 nl;p \\<noteq> Exit \\<rbrakk> \n\\<Longrightarrow>  LLVM_step tid mem (_,p, env, stack,alloced,lockMap) {}\n    ( p,next_node Edges seq p, env(x := eval_extract (eval_expr env e1) nl), stack, alloced,lockMap)\" |\ninsert_v [intro]: \"\\<lbrakk> L p = Insert_value x ty1 e1 ty2 e2 nl;p \\<noteq> Exit\\<rbrakk> \\<Longrightarrow>\n      LLVM_step tid mem (_,p, env, stack,alloced,lockMap) {}\n    (p,next_node Edges seq p,\n             env(x := eval_insert (eval_expr env  e2) (eval_expr env  e1) nl), stack, alloced,lockMap)\" |\nload [intro!]: \"\\<lbrakk>L p = Load vol x ty e; eval_expr env e = CPointer l; v = mem l; p \\<noteq> Exit\\<rbrakk> \\<Longrightarrow> \n LLVM_step tid mem (_,p, env, stack,alloced,lockMap) {NRead vol v l 0 0 0 []}\n                (p,next_node Edges seq p, env(x := v), stack, alloced,lockMap)\" \n| atomic_load [intro!]: \"\\<lbrakk>L p = Atomic_load vol x ty e or1;eval_expr env  e = CPointer l; v = mem l; p \\<noteq> Exit\\<rbrakk>\n \\<Longrightarrow> \n LLVM_step tid mem (_,p, env, stack,alloced, lockMap) {ARead vol v l (tranOrder or1) []}\n                (p,next_node Edges seq p, env(x := v), stack, alloced,lockMap)\"\n| store [intro]: \"\\<lbrakk>L p = Store vol ty1 e1 ty2 e2;eval_expr env  e2 = CPointer l; p \\<noteq> Exit\\<rbrakk> \\<Longrightarrow> \n LLVM_step tid mem (_,p, env, stack,alloced, lockMap) {NWrite vol (eval_expr env e1) l 0 0 0 []}\n           (p,next_node Edges seq p, env, stack, alloced,lockMap)\"\n| atomic_store [intro]: \"\\<lbrakk>L p = Atomic_store vol ty1 e1 ty2 e2 or1;eval_expr env  e2 = CPointer l; p \\<noteq> Exit\\<rbrakk> \\<Longrightarrow> \n LLVM_step tid mem (_,p, env, stack,alloced, lockMap) {AWrite vol (eval_expr env e1) l (tranOrder or1) []}\n        (p,next_node Edges seq p, env, stack, alloced,lockMap)\"\n| malloc [intro] : \"\\<lbrakk>L P = Malloc x ty; p \\<noteq> Exit\\<rbrakk> \\<Longrightarrow>\n    LLVM_step tid mem (_,p, env, stack, alloced,lockMap) {Create v}\n           (p,next_node Edges seq p, env(x := CPointer v), stack,alloced \\<union> nexts, lockMap)\"\n| fence [intro]: \"\\<lbrakk>L P = LLVM_Fence or1;p \\<noteq> Exit \\<rbrakk>\n \\<Longrightarrow> LLVM_step tid mem (_,p,env, stack,alloced,lockMap) {Fence (tranOrder or1)}\n                       (p,next_node Edges seq p, env, stack, alloced,lockMap)\"\n| cmpxchg_false [intro]: \"\\<lbrakk>L p = Cmpxchg vol x ty1 e1 ty2 e2 ty3 e3 or1;\n       eval_expr env  e1 = CPointer l; eval_expr env  e2 = v;v \\<noteq> mem l; p \\<noteq> Exit\\<rbrakk> \\<Longrightarrow> \n LLVM_step tid mem (_,p, env, stack,alloced,lockMap) {ARead vol (mem l) l (tranOrder or1) []}\n                       (p,next_node Edges seq p, env(x := mem l), stack, alloced,lockMap)\"\n| cmpxchg_true [intro]: \"\\<lbrakk>L p = Cmpxchg vol x ty1 e1 ty2 e2 ty3 e3 or1;\n          eval_expr env  e1 = CPointer l; eval_expr env  e2 = v;v = mem l; p \\<noteq> Exit\\<rbrakk> \\<Longrightarrow> \n LLVM_step tid mem (_,p, env, stack,alloced,lockMap) {RMW vol (eval_expr env e3) l (tranOrder or1) []}\n                       (p,next_node Edges seq p, env(x := mem l), stack, alloced, lockMap)\"\n| icmp [intro]: \"\\<lbrakk>L p = ICmp x cop ty e1 e2;eval_cmp env cop e1 e2 = v; p \\<noteq> Exit\\<rbrakk> \\<Longrightarrow> \n LLVM_step tid mem (_,p, env, stack,alloced, lockMap) {}\n                       (p,next_node Edges seq p, env(x := v), stack, alloced,lockMap)\"\n| phi [intro]: \"\\<lbrakk>L p = (x = phi ty vals); p \\<noteq> Exit; (p0,p,l1) \\<in> Edges; (p0, e) \\<in> set vals\\<rbrakk>\n   \\<Longrightarrow> LLVM_step tid mem\n        (_,p, env, stack,alloced, lockMap) {}\n         (p,next_node Edges seq p, env(x := eval_expr env e), stack, alloced,lockMap)\"\n| call [intro]: \"\\<lbrakk>L p = (x = call ty name args);p \\<noteq> Exit\\<rbrakk>\n \\<Longrightarrow> LLVM_step tid mem (_,p, env, stack,alloced, lockMap) {CallFence name 0}\n (p,next_node Edges proc_call p, init_env env args, (next_node Edges seq p, x, env) # stack,\n        alloced,lockMap)\"\n| mutex_lock [intro]: \"\\<lbrakk> L p = Mutex_lock e;\n        p \\<noteq> Exit; lockMap lock = None; eval_expr env e = CInt lock\\<rbrakk> \\<Longrightarrow>\n   LLVM_step tid mem (_,p, env, stack,alloced,lockMap) {Lock lock}\n (p,next_node Edges seq p, env,stack, alloced,lockMap(lock := Some tid))\"\n| mutex_unlock [intro]: \"\\<lbrakk> L p = Mutex_unlock e;\n         p \\<noteq> Exit; lockMap lock = Some tid; eval_expr env e = CInt lock\\<rbrakk> \\<Longrightarrow>\n   LLVM_step tid mem (_,p, env, stack,alloced,lockMap) {UnLock lock}\n (p,next_node Edges seq p, env,stack, alloced,lockMap(lock := None))\"\n\nterm LLVM_step\n\nfun genReadList :: \"'tid \\<Rightarrow> bool \\<Rightarrow> 'val \\<Rightarrow> 'loc \\<Rightarrow> 'aid \\<Rightarrow> nat \\<Rightarrow> nat\n                       \\<Rightarrow> 'aid list  \\<Rightarrow> ('tid \\<times> 'aid \\<times> ('aid,  'val, 'loc, 'lock,'name,'key) action) list\" where\n\"genReadList tid vol v l aid n 0 al = [(tid, aid, NRead vol v l aid n n al)]\"\n| \"genReadList tid vol v l aid n (Suc x) al = ((tid,aid,NRead vol v l aid (n - (Suc x)) n al)#(genReadList tid vol v l aid n x al))\"\n\nfun genWriteList where\n\"genWriteList tid vol v l aid n 0 al = [(tid, aid, NWrite vol v l aid n n al)]\"\n| \"genWriteList tid vol v l aid n (Suc x) al = ((tid,aid,NWrite vol v l aid (n - (Suc x)) n al)#(genWriteList tid vol v l aid n x al))\"\n\ninductive LLVM_step_sb where\nsb_assign [intro]: \"\\<lbrakk> L p = Assign x opr ty e1 e2;\n             LLVM_step tid mem (p0, p, env, stack, alloced,lockMap) {}\n                     (p,p', env', stack,alloced',lockMap) \\<rbrakk> \\<Longrightarrow>\n      LLVM_step_sb tid (mem, aidCount,lockMap, funStack,fCount,funName,funCount,\n                        memVarMap,memLocMap, p0,p, env, stack,alloced)\n                       (mem, aidCount,lockMap, funStack,fCount,funName,funCount,\n              memVarMap(x := mapSetCon (expr_lfv e1 \\<union> expr_lfv e2) memVarMap),memLocMap,\n                        p, p', env', stack, alloced',NoAction)\"|\nsb_branch_i [intro]: \"\\<lbrakk> L p = Br_i1 e;\n     LLVM_step tid mem (p0,p, env, stack,alloced,lockMap) {ControlFence}\n          (p,p1, env', stack',alloced', lockMap) \\<rbrakk>\n     \\<Longrightarrow> LLVM_step_sb tid (mem, aidCount,lockMap,funStack,fCount,funName,funCount,varMap,locMap,p0,p, env, stack,alloced)\n            (mem, aidCount,lockMap,funStack,fCount,funName,funCount,varMap,locMap,p,p1, env', stack',alloced',\n                              MemAction [(tid,aidCount,ControlFence)])\" |\nsb_branch_u [intro]: \"\\<lbrakk>L p = Br_label; LLVM_step tid mem (p0,p, env, stack,alloced,lockMap) {ControlFence}\n          ( p, p1, env', stack',alloced', lockMap')\\<rbrakk> \\<Longrightarrow>\n       LLVM_step_sb tid (mem, aidCount,lockMap,funStack,fCount,funName,funCount,varMap,locMap,p0,p, env, stack,alloced)\n            (mem, aidCount,lockMap',funStack, fCount,funName,funCount,varMap,locMap,p,p1, env', stack',alloced', NoAction)\" |\nsb_extract_v [intro]: \"\\<lbrakk> L p = Extract_value x ty e1 nl; LLVM_step tid mem\n          (p0,p, env, stack,alloced,lockMap) {}\n    (p, p', env', stack',alloced', lockMap)\\<rbrakk> \\<Longrightarrow>\n      LLVM_step_sb tid (mem, aidCount,lockMap,funStack,fCount,funName,funCount,varMap,locMap,p0,p, env, stack,alloced)\n             ( mem, aidCount,lockMap, funStack,fCount,funName,funCount,\n                varMap(x := mapSetCon (expr_lfv e1) varMap),locMap,p,\n                        p', env', stack',alloced', NoAction)\" |\nsb_insert_v [intro]: \"\\<lbrakk> L p = Insert_value x ty1 e1 ty2 e2 nl; LLVM_step tid mem\n          (p0,p, env, stack,alloced,lockMap) {}\n    (p, p', env', stack',alloced', lockMap)\\<rbrakk> \\<Longrightarrow>\n      LLVM_step_sb tid (mem, aidCount,lockMap,funStack,fCount,funName,funCount,varMap,locMap,p0,p, env, stack,alloced)\n             (mem,  aidCount,lockMap, funStack,fCount,funName,funCount,\n              varMap(x := mapSetCon (expr_lfv e1 \\<union> expr_lfv e2) varMap),locMap,p,\n                        p', env', stack',alloced', NoAction)\" \n| sb_load[intro]: \"\\<lbrakk>eval_expr env e = CPointer l; L p = Load vol x ty e;\n          LLVM_step tid mem (p0,p, env, stack,alloced,lockMap) R\n                ( p,p', env', stack',alloced', lockMap); env x = v\\<rbrakk> \\<Longrightarrow> \n LLVM_step_sb tid (mem, aidCount,lockMap,funStack,fCount,funName,funCount,varMap,locMap,p0,p, env, stack,alloced)\n             (mem, aidCount+1,lockMap, funStack,fCount,funName,funCount,\n                   varMap(x := mapSetCon (expr_lfv e) varMap \\<union> {aidCount}),locMap,\n                        p,p', env', stack',alloced', MemAction (genReadList tid vol v l\n                                                   aidCount (LLVM_sizeof ty) (LLVM_sizeof ty)\n                            (sorted_list_of_set ((mapSetCon (expr_lfv e) varMap) \\<union> locMap l))))\"\n| sb_atomic_load[intro]: \"\\<lbrakk>eval_expr env e = CPointer l; L p = Atomic_load vol x ty e or1;\n          LLVM_step tid mem (p0,p, env, stack,alloced,lockMap) R\n                (p,p', env', stack',alloced', lockMap)\\<rbrakk> \\<Longrightarrow> \n LLVM_step_sb tid (mem, aidCount,lockMap,funStack,fCount,funName,funCount,varMap,locMap,p0,p, env, stack,alloced)\n             ( mem, aidCount+1,lockMap, funStack,fCount,funName,funCount,\n                 varMap(x := mapSetCon (expr_lfv e) varMap \\<union> {aidCount}),locMap,\n                        p,p', env', stack',alloced', MemAction [(tid,aidCount,ARead vol (env x) l\n                               (tranOrder or1) (sorted_list_of_set ((mapSetCon (expr_lfv e) varMap) \\<union> locMap l)))])\"\n| sb_store [intro]: \"\\<lbrakk>eval_expr env e2 = CPointer l; L p = Store vol ty1 e1 ty2 e2; eval_expr env e1 = v;\n                      LLVM_step tid mem (p0,p, env, stack,alloced,lockMap) R\n           (p,p', env', stack',alloced', lockMap)  \\<rbrakk>\n   \\<Longrightarrow> \n LLVM_step_sb tid (mem, aidCount,lockMap,funStack,fCount,funName,funCount,varMap,locMap,p0,p, env, stack,alloced)\n             (mem, aidCount+1,lockMap, funStack,fCount,funName,funCount,\n                  varMap,locMap(l := {aidCount}),\n                        p,p', env', stack',alloced', MemAction (genWriteList tid vol v l\n                                                   aidCount (LLVM_sizeof ty1) (LLVM_sizeof ty1)\n                                    (sorted_list_of_set (mapSetCon (expr_lfv e1 \\<union> expr_lfv e2) varMap))))\"\n| sb_atomic_store[intro]: \"\\<lbrakk>eval_expr env e1 = v;\n              eval_expr env e2 = CPointer l; L p = Atomic_store vol ty1 e1 ty2 e2 or1;\n          LLVM_step tid mem (p0,p, env, stack,alloced,lockMap) R\n                (p,p', env', stack',alloced', lockMap)\\<rbrakk> \\<Longrightarrow> \n LLVM_step_sb tid (mem, aidCount,lockMap,funStack,fCount,funName,funCount,varMap,locMap,p0,p, env, stack,alloced)\n             (mem, aidCount+1,lockMap, funStack,fCount,funName,funCount,\n                 varMap,locMap(l := {aidCount}), p,p', env', stack',alloced',\n                         MemAction [(tid,aidCount,AWrite vol v l (tranOrder or1)\n                                    (sorted_list_of_set (mapSetCon (expr_lfv e1 \\<union> expr_lfv e2) varMap)))])\"\n| sb_malloc [intro]: \"\\<lbrakk> L p = Malloc x ty; env' x = CPointer l;\n          LLVM_step tid mem (p0,p, env, stack, alloced,lockMap) R\n           (p,p', env', stack',alloced', lockMap)\\<rbrakk> \\<Longrightarrow> \n LLVM_step_sb tid (mem, aidCount,lockMap,funStack,fCount,funName,funCount,varMap,locMap,p0,p, env, stack,alloced)\n             (mem, aidCount+1,lockMap, funStack,fCount,funName,funCount,\n                 varMap(x := {aidCount}),locMap(l := {aidCount}),\n                    p,p', env', stack',alloced', MemAction [(tid,aidCount,Create l)])\"\n| sb_fence [intro]: \"\\<lbrakk> L p = LLVM_Fence or1;\n          LLVM_step tid mem (p0,p,env, stack, alloced,lockMap) R\n           (p,p', env', stack',alloced', lockMap)\\<rbrakk> \\<Longrightarrow> \n LLVM_step_sb tid (mem, aidCount,lockMap,funStack,fCount,funName,funCount,varMap,locMap,p0,p, env, stack,alloced)\n             (mem, aidCount+1,lockMap, funStack,fCount,funName,funCount, varMap,locMap,\n                 p, p', env', stack',alloced', MemAction [(tid,aidCount,Fence (tranOrder or1))])\"\n| sb_cmpxchg [intro]: \"\\<lbrakk>eval_expr env' e1 = CPointer l;\n                            L p = Cmpxchg vol x ty1 e1 ty2 e2 ty3 e3 or1;\n        LLVM_step tid mem (p0,p, env, stack,alloced,lockMap) R\n                       (p,p', env', stack', alloced',lockMap)\\<rbrakk>\n  \\<Longrightarrow> LLVM_step_sb tid (mem, aidCount,lockMap,funStack,fCount,funName,funCount,varMap,locMap,p0,p, env, stack,alloced)\n             (mem, aidCount+1,lockMap, funStack,fCount,funName,funCount,\n                  varMap(x := mapSetCon ((expr_lfv e1) \\<union> (expr_lfv e2)) varMap \\<union> {aidCount}),locMap(l := {aidCount}),\n                    p,p', env', stack',alloced',\n              MemAction [(tid, aidCount, RMW vol (eval_expr env e3) l (tranOrder or1)\n               (sorted_list_of_set ((mapSetCon ((expr_lfv e1) \\<union> (expr_lfv e2) \\<union> (expr_lfv e3)) varMap) \\<union> locMap l)))])\"\n| sb_icmp [intro]: \"\\<lbrakk> L p = ICmp x cop ty e1 e2;\n          LLVM_step tid mem (p0,p, env, stack,alloced,lockMap) {}\n                       (p,p', env', stack', alloced',lockMap)\\<rbrakk> \\<Longrightarrow> \n LLVM_step_sb tid (mem, aidCount,lockMap, funStack,fCount,funName,funCount,\n                        memVarMap,memLocMap, p0,p, env, stack,alloced)\n                       (mem, aidCount,lockMap, funStack,fCount,funName,funCount,\n              memVarMap(x := mapSetCon (expr_lfv e1 \\<union> expr_lfv e2) memVarMap),memLocMap,\n                        p,p', env', stack', alloced',NoAction)\"\n| sb_phi [intro]: \"\\<lbrakk> L p = (x = phi ty vals);(p0,p,l1) \\<in> Edges; (p0, e) \\<in> set vals;\n          LLVM_step tid mem (p0,p, env, stack,alloced,lockMap) {}\n                       ( p,p', env', stack', alloced',lockMap)\\<rbrakk> \\<Longrightarrow> \n LLVM_step_sb tid (mem, aidCount,lockMap, funStack,fCount,funName,funCount,\n                        memVarMap,memLocMap,p0, p, env, stack,alloced)\n                       (mem, aidCount,lockMap, funStack,fCount,funName,funCount,\n              memVarMap(x := mapSetCon (expr_lfv e) memVarMap),memLocMap,\n                        p,p', env', stack', alloced',NoAction)\"\n| sb_ret_move [intro]: \"\\<lbrakk>L p = Ret ty e; ret_addr \\<noteq> Exit;\n    LLVM_step tid mem (p0,p, env, stack,alloced,lockMap) R\n         (p,ret_addr, env', stack',alloced', lockMap)\\<rbrakk> \\<Longrightarrow> \n LLVM_step_sb tid (mem, aidCount,lockMap,(funName',funCount', memVarMap',memLocMap')#funStack,\n                           fCount,funName,funCount,memVarMap,memLocMap, p0,p, env, stack,alloced)\n         (mem, aidCount+1,lockMap,funStack,fCount,funName',funCount',memVarMap',memLocMap',p,ret_addr,\n             env', stack',alloced', MemAction [(tid,aidCount,CallFence funName funCount)])\" |\nsb_ret_main [intro]: \"\\<lbrakk>L p = Ret ty e;\n    LLVM_step tid mem (p0,p, env, stack,alloced,lockMap) {}\n         (p,Exit, env', stack',alloced', lockMap)\\<rbrakk> \\<Longrightarrow> \n LLVM_step_sb tid (mem, aidCount,lockMap,funStack,fCount,funName,funCount,varMap,locMap,p0,p, env, stack,alloced)\n         (mem, aidCount,lockMap,funStack,fCount,funName,funCount,\n                          varMap,locMap,p,Exit, env', stack',alloced', NoAction)\"\n| sb_call [intro]: \"\\<lbrakk>L p = (x = call ty name args);\nLLVM_step tid mem (p0,p, env, stack,alloced,lockMap) R\n (p,p', env', stack', alloced',lockMap)\\<rbrakk>\n  \\<Longrightarrow> LLVM_step_sb tid (mem, aidCount,lockMap,funStack,fCount,\n                           funName,funCount,memVarMap,memLocMap,p0, p, env, stack,alloced)\n         (mem, aidCount+1,lockMap,(funName,funCount, memVarMap,memLocMap)#funStack,\n              fCount+1,name,fCount,initVarMap args memVarMap,initLocMap,p,p',\n                env', stack',alloced', MemAction [(tid,aidCount,CallFence funName funCount)])\"\n| sb_mutex_lock [intro]: \"\\<lbrakk> eval_expr env e = CInt lock; L p = Mutex_lock e;\n    LLVM_step tid mem (p0,p, env, stack,alloced,lockMap) R\n (p,p', env',stack', alloced',lockMap')\\<rbrakk> \\<Longrightarrow>\n   LLVM_step_sb tid (mem, aidCount,lockMap,funStack,fCount,\n                           funName,funCount,memVarMap,memLocMap, p0,p, env, stack,alloced)\n         (mem, aidCount+1,lockMap',funStack,\n              fCount,funName,funCount,memVarMap,memLocMap,p,p',\n               env', stack',alloced', MemAction [(tid,aidCount,Lock lock)])\"\n| sb_mutex_unlock [intro]: \"\\<lbrakk> eval_expr env e = CInt lock; L p =  Mutex_unlock e;\n    LLVM_step tid mem (p0,p, env, stack,alloced,lockMap) R\n (p,p', env',stack', alloced',lockMap')\\<rbrakk> \\<Longrightarrow>\n   LLVM_step_sb tid (mem, aidCount,lockMap,funStack,fCount,\n                           funName,funCount,memVarMap,memLocMap, p0,p, env, stack,alloced)\n         (mem, aidCount+1,lockMap',funStack,\n              fCount,funName,funCount,memVarMap,memLocMap,p,p',\n            env', stack',alloced', MemAction [(tid,aidCount,UnLock lock)])\"\n\nlemma step_next [simp]: \"LLVM_step t mem (p0, p, rest) a (p', rest') \\<Longrightarrow> p' = p\"\nby (erule LLVM_step.cases, simp_all)\n\nlemma not_exit: \"LLVM_step t mem (p0, p, rest) a C' \\<Longrightarrow> p \\<noteq> Exit\"\nby (erule LLVM_step.cases, simp_all)\n\nlemma branch_true [intro]: \"\\<lbrakk>L p = Br_i1 e; p \\<noteq> Exit; eval_expr env e \\<noteq> CInt 0\\<rbrakk>\n\\<Longrightarrow>\n LLVM_step t mem (p0, p, env, stack, allocad,lockMap) {ControlFence}\n                     (p, next_node Edges true p, env, stack, allocad,lockMap)\"\nproof -\n  assume a1: \"L p = Br_i1 e\"\n  assume a2: \"p \\<noteq> Exit\"\n  assume a3: \"eval_expr env e \\<noteq> CInt 0\"\n  have \"\\<forall>x3 x7 x8. next_node Edges (if eval_expr (x3::char list \\<Rightarrow> (int, int) LLVM_const) x7 = CInt 0 then false else true) x8 = (if eval_expr x3 x7 = CInt 0 then next_node Edges false x8 else next_node Edges true x8)\"\n    by presburger\n  then show ?thesis\n    using a3 a2 a1 by (metis (no_types) branch_i)\nqed \n\nlemma branch_false [intro]: \"\\<lbrakk>L p = Br_i1 e; p \\<noteq> Exit; eval_expr env e = CInt 0\\<rbrakk> \\<Longrightarrow> \n LLVM_step t mem (p0, p, env, stack, allocad,lockMap) {ControlFence}\n            (p, next_node Edges false p, env, stack, allocad,lockMap)\"\nproof -\n  assume a1: \"L p = Br_i1 e\"\n  assume a2: \"p \\<noteq> Exit\"\n  assume a3: \"eval_expr env e = CInt 0\"\n  have \"\\<forall>x3 x7 x8. next_node Edges (if eval_expr (x3::char list \\<Rightarrow> (int, int) LLVM_const) x7 = CInt 0 then false else true) x8 = (if eval_expr x3 x7 = CInt 0 then next_node Edges false x8 else next_node Edges true x8)\"\n    by presburger\n  then show ?thesis\n    using a3 a2 a1 by (metis (no_types) branch_i)\nqed\n\nend\n\ndefinition \"alloc_mem r \\<equiv> case r of (stack, allocad) \\<Rightarrow> allocad \\<union> (\\<Union>(a, b, c, d)\\<in>set stack. d)\"\n\ncontext LLVM begin\n\n(*\nlemma finite_ops: \"\\<lbrakk>LLVM_step t mem gt (p0, p, env, stack, allocad) ops (p, p', env', stack', allocad'); \n finite (alloc_mem (stack, allocad))\\<rbrakk> \\<Longrightarrow> finite ops \\<and> finite (alloc_mem (stack', allocad'))\"\nby (erule LLVM_step.cases, auto simp add: alloc_mem_def)\n\nlemma step_mem: \"\\<lbrakk>LLVM_step t mem gt (p0, p, env, stack, allocad) ops (p, p', env', stack', allocad'); \n l \\<notin> free_set mem; l \\<notin> alloc_mem (stack, allocad)\\<rbrakk> \\<Longrightarrow> l \\<notin> alloc_mem (stack', allocad')\"\nby (erule LLVM_step.cases, auto simp add: alloc_mem_def)\n*)\n\nend\n\ntype_synonym ('thread, 'node) LLVM_tCFG =\n \"('thread, ('node, LLVM_edge_type, 'node concrete_LLVM_instr) flowgraph) map\"\n\n\nlocale LLVM_decls = fixes decls::\"'var LLVM_decl list\"\n\nlocale LLVM_base =\n LLVM_MM\n where actions = \"actions :: (time_type, concrete_LLVM_const, loc_type, int, string, int) action set\"\n    and locations = \"locations :: loc_type set\"\n    and actionIDs = \"actionIDs :: aid_type set\"\n    and times = \"times :: time_type set\"\n    and threads = \"threads :: int set\"\n    and locks = \"locks :: int set\"\n    and names = \"names :: string set\"\n    and callIDs = \"callIDs :: int set\" +\n LLVM_decls where decls = \"decls:: 'var LLVM_decl list\"\n for actions locations actionIDs times threads locks names callIDs decls +\n fixes gt::\"string \\<Rightarrow> concrete_LLVM_const\"\nbegin\n\n(*\nabbreviation \"step t G mem \\<equiv> LLVM.LLVM_step (Exit G) (Edges G) free_set can_read (Label G) t mem gt\"\n\nlemma LLVM_graph': \"is_flowgraph G seq LLVM_instr_edges \\<Longrightarrow> \n  LLVM (Nodes G) (Start G) (Exit G) (Edges G) free_set (Label G) update_mem\"\nby (simp add: LLVM_def is_flowgraph_def LLVM_flowgraph_def, unfold_locales)\n\nlemmas step_cases' = LLVM.LLVM_step.cases [OF LLVM_graph']\nlemmas step_next' [simp] = LLVM.step_next [OF LLVM_graph']\n\nlemma out_edges_shape: \"\\<lbrakk>{(u, t). (p, u, t) \\<in> Edges G} = S; (p', t) \\<in> S\\<rbrakk> \\<Longrightarrow>\n  (p, p', t) \\<in> Edges G\"\nby force\n\nlemma step_along_edge': \"\\<lbrakk>is_flowgraph G seq LLVM_instr_edges; step t G m (pp, p, r) a (p, p', r'); p \\<in> Nodes G\\<rbrakk> \\<Longrightarrow> \n \\<exists>e. (p, p', e) \\<in> Edges G\"\napply (subgoal_tac \"LLVM (Nodes G) (Start G) (Exit G) (Edges G) free_set (Label G) update_mem\") \napply (clarsimp simp add: is_flowgraph_def flowgraph_def flowgraph_axioms_def)\napply ((erule_tac x=p in allE)+)\napply (frule pointed_graph.finite_edges)\napply (erule LLVM.LLVM_step.cases, simp_all, simp_all, clarsimp)\napply (clarsimp simp add: out_edges_def, force)\napply (clarsimp simp add: out_edges_def, force)\napply force\napply clarsimp\napply (rule conjI, clarsimp simp add: out_edges_def, frule_tac p'=p' in out_edges_shape, force, force)\napply (clarsimp simp add: out_edges_def, frule_tac p'=p' in out_edges_shape, force, force)\napply (clarsimp simp add: out_edges_def, frule_tac p'=p' in out_edges_shape, force, force)\napply (clarsimp simp add: out_edges_def, frule_tac p'=p' in out_edges_shape, force, force)\napply (clarsimp simp add: out_edges_def, frule_tac p'=p' in out_edges_shape, force, force)\napply (clarsimp simp add: out_edges_def, frule_tac p'=p' in out_edges_shape, force, force)\napply (clarsimp simp add: out_edges_def, frule_tac p'=p' in out_edges_shape, force, force)\napply (clarsimp simp add: out_edges_def, frule_tac p'=p' in out_edges_shape, force, force)\napply (clarsimp simp add: out_edges_def, frule_tac p'=p' in out_edges_shape, force, force)\napply (clarsimp simp add: out_edges_def, frule_tac p'=p' in out_edges_shape, force, force)\napply (clarsimp simp add: out_edges_def, frule_tac p'=p' in out_edges_shape, force, force)\napply (clarsimp simp add: out_edges_def, frule_tac p'=p' in out_edges_shape, force, force)\napply (simp add: LLVM_def LLVM_flowgraph_def is_flowgraph_def, unfold_locales)\ndone\n*)\nend\n\nlemmas option.splits [split]\n\n(* Concurrent semantics *)\nfun get_point where \"get_point (_, p, _) = p\"\n\nsublocale LLVM_base \\<subseteq> step_rel where free_set=free_set and update_mem=update_mem \n  and start_mem=start_mem and can_read=can_read and step_rel=step\n  and get_point=get_point \n  and instr_edges=\"LLVM_instr_edges::'node concrete_LLVM_instr \\<Rightarrow> (LLVM_edge_type \\<Rightarrow> nat) set\" \n  and Seq=seq \n  and start_state=\"\\<lambda>CFGs C0 mem0. declare_globals (start_env, start_mem) decls (gt, mem0) \\<and> \n     C0 = (\\<lambda>t. case CFGs t of Some G \\<Rightarrow> Some (Start G, Start G, start_env, [], {}) | None \\<Rightarrow> None)\"\napply unfold_locales\napply (rule ext, simp add: start_points_def map_comp_def)\napply clarsimp\napply (frule step_next', simp, clarsimp)\napply (metis step_along_edge')\ndone\n\nlemma (in LLVM_base) one_step_next: \"\\<lbrakk>one_step t G ((p0, p, rest), m) ((p', rest'), m');\n  is_flowgraph G seq LLVM_instr_edges\\<rbrakk> \\<Longrightarrow> p' = p\"\nby (erule one_step.cases, auto)\n\nprint_locale LLVM_base\nlocale LLVM_threads = LLVM_tCFG\n where CFGs=\"CFGs::('thread, 'node) LLVM_tCFG\" + \n LLVM_base\n where update_mem=\"update_mem::'memory \\<Rightarrow> ('thread, int, concrete_LLVM_const) access set \\<Rightarrow> 'memory \\<Rightarrow> bool\"\n   and free_set = \"free_set :: 'memory \\<Rightarrow> int set\" \n    and can_read = \"can_read :: 'memory \\<Rightarrow> 'thread \\<Rightarrow> int \\<Rightarrow> (int, int) LLVM_const set\" \n    and start_mem = \"start_mem:: 'memory\"\n    and decls = \"decls::LLVM_decl list\"\n    and gt = \"gt::char list \\<Rightarrow> (int, int) LLVM_const\" \n for free_set CFGs update_mem can_read start_mem decls gt\n\nbegin\n\nlemma LLVM_graph [simp, intro]: \"CFGs t = Some G \\<Longrightarrow> \n LLVM (Nodes G) (Start G) (Exit G) (Edges G) free_set (Label G) update_mem\"\nby (frule CFGs, erule LLVM_graph')\n\nlemmas step_cases = LLVM.LLVM_step.cases [OF LLVM_graph]\nlemmas step_next [simp] = LLVM.step_next [OF LLVM_graph]\n\nlemma step_along_edge: \"\\<lbrakk>CFGs t = Some G; step t G m (pp, p, r) a (p, p', r'); p \\<in> Nodes G\\<rbrakk> \\<Longrightarrow> \n \\<exists>e. (p, p', e) \\<in> Edges G\"\nby (rule step_along_edge', drule CFGs, auto)\n\nabbreviation \"conc_step_star \\<equiv> (conc_step CFGs)^**\"\n\nlemma ops_thread: \"\\<lbrakk>step t G mem state ops state'; CFGs t = Some G; a \\<in> ops\\<rbrakk> \\<Longrightarrow> get_thread a = t\"\nby (rule step_cases, auto)\n\ndefinition \"all_alloc_mem states \\<equiv> \\<Union>(a0, a, b, c, d)\\<in>ran states. alloc_mem (c, d)\"\n\nlemma run_global: \"\\<lbrakk>run_prog CFGs C; Global_Decl s c \\<in> set decls\\<rbrakk> \\<Longrightarrow>\n \\<exists>l. gt s = CPointer l \\<and> l \\<notin> free_set (snd C) \\<and> l \\<notin> all_alloc_mem (fst C)\"\napply (rule run_prog_induct, simp, clarsimp simp add: run_prog_def)\napply (drule global_alloc, simp+, clarsimp simp add: all_alloc_mem_def ran_def alloc_mem_def \n split: option.splits)\napply clarsimp\napply (erule conc_step.cases, clarsimp simp add: all_alloc_mem_def ran_def)\napply (rule conjI, clarsimp)\napply (drule stays_not_free, simp, clarsimp simp add: alloc_mem_def)\napply (drule step_cases, simp, simp_all, force, force)\napply clarsimp\napply (case_tac \"al \\<noteq> t\", force, clarsimp)\napply (frule step_next, simp+)\napply (drule_tac can_read=can_read and t=t in LLVM.step_mem [OF LLVM_graph], simp+, force, simp)\ndone\n\nlemma call_edges [simp]: \"finite (Edges G) \\<Longrightarrow>\n  (edge_types (out_edges (Edges G) p) = no_edges(proc_call := Suc 0, seq := Suc 0))\n = (\\<exists>m n. out_edges (Edges G) p = {(m, proc_call), (n, seq)})\"\nby simp\n\nend\n\n(* Memory models *)\nlocale LLVM_TSO = tCFG where instr_edges=LLVM_instr_edges and Seq=seq and \n  CFGs=\"CFGs::('thread, 'node) LLVM_tCFG\" + TSO where undef=\"CUndef::concrete_LLVM_const\" for CFGs\n\nsublocale LLVM_TSO \\<subseteq> TSO: LLVM_threads where update_mem=update_mem and free_set=free_set \n  and can_read=can_read and start_mem=start_mem\nby (unfold_locales)\n\nlocale LLVM_SC = tCFG where instr_edges=LLVM_instr_edges and Seq=seq and \n  CFGs=\"CFGs::('thread, 'node) LLVM_tCFG\" + SC where undef=\"CUndef::concrete_LLVM_const\" for CFGs\n\nsublocale LLVM_SC \\<subseteq> SC: LLVM_threads where update_mem=update_mem and free_set=free_set \n  and can_read=can_read and start_mem=start_mem\nby (unfold_locales)\n\nlocale LLVM_PSO = tCFG where instr_edges=LLVM_instr_edges and Seq=seq and \n  CFGs=\"CFGs::('thread, 'node) LLVM_tCFG\" + PSO where undef=\"CUndef::concrete_LLVM_const\" for CFGs\n\nsublocale LLVM_PSO \\<subseteq> PSO: LLVM_threads where update_mem=update_mem and free_set=free_set \n  and can_read=can_read and start_mem=start_mem\nby (unfold_locales)\n\nlemma (in LLVM_SC) safe_mem: \"\\<lbrakk>l \\<notin> free_set mem; l \\<notin> alloc_mem (stack, allocad); CFGs t = Some G;\n LLVM.LLVM_step (Exit G) (Edges G) free_set can_read (Label G) t mem gt (p0, p, env, stack, allocad) \n ops (p, p', env', stack', allocad'); update_mem mem ops mem'; finite (alloc_mem (stack, allocad))\\<rbrakk> \\<Longrightarrow>\n l \\<notin> free_set mem' \\<and> l \\<notin> alloc_mem (stack', allocad') \\<and> finite (alloc_mem (stack', allocad'))\"\nby (rule LLVM.LLVM_step.cases, erule LLVM_graph, simp, auto simp add: alloc_mem_def)\n\n(* Memory models in LLVM. *)\ncontext LLVM_threads begin\n\ndeclare step_cases [elim]\n\nabbreviation \"step_SC \\<equiv> LLVM_base.step SC.free_set SC.can_read gt\"\nabbreviation \"step_TSO \\<equiv> LLVM_base.step TSO.free_set TSO.can_read gt\"\n\ndeclare eval.simps [simp del] eval_cmp.simps [simp del]\n\nend\n\n(*context LLVM_SC begin\n\nlemma LLVM_TSO_graph: \"CFGs t = Some G \\<Longrightarrow> LLVM (Nodes G) (Start G) (Exit G) (Edges G) TSO.free_set \n (Label G) TSO.update_mem\"\napply (drule LLVM_graph, clarsimp simp add: LLVM_def)\napply unfold_locales\napply (metis TSO_alloc_not_free)\napply (metis TSO_stays_not_free)\ndone\n\n(* automate? *)\nlemma SC_lt_TSO_step: \"\\<lbrakk>step_SC t mem gt state ops state'; t \\<in> dom CFGs\\<rbrakk> \\<Longrightarrow> \n step_TSO t (mem, \\<lambda>t. []) gt state ops state'\"\napply (drule domD, clarsimp)\napply (rule step_cases, simp_all, simp_all)\napply (rule LLVM.assign, rule LLVM_TSO_graph, simp+)\napply (rule LLVM.ret_pop, rule LLVM_TSO_graph, simp+)\napply (rule LLVM.ret_main, rule LLVM_TSO_graph, simp_all, force)\napply (rule conjI)\napply (clarsimp, rule LLVM.branch_false, rule LLVM_TSO_graph, simp+)\napply (clarsimp, rule LLVM.branch_true, rule LLVM_TSO_graph, simp+)\napply (rule LLVM.branch_u, rule LLVM_TSO_graph, simp+)\napply (rule LLVM.alloca, rule LLVM_TSO_graph, simp_all)\napply (rule LLVM.load, rule LLVM_TSO_graph, simp, force, simp+)\napply (rule LLVM.store, rule LLVM_TSO_graph, simp_all, force)\napply (rule LLVM.cmpxchg_eq, rule LLVM_TSO_graph, simp, force, simp+)\napply (rule LLVM.cmpxchg_no, rule LLVM_TSO_graph, simp, force, simp+)\napply (rule LLVM.icmp, rule LLVM_TSO_graph, simp+)\napply (rule LLVM.phi, rule LLVM_TSO_graph, simp+, force, simp+)\napply (rule LLVM.call, rule LLVM_TSO_graph, simp+)\napply (rule LLVM.ispointer, rule LLVM_TSO_graph, auto)\ndone\n\nthm LLVM_threads.step_thread\nabbreviation \"conc_step_SC \\<equiv> LLVM_threads.conc_step free_set_SC CFGs can_read_SC update_mem_SC\"\nabbreviation \"conc_step_TSO \\<equiv> LLVM_threads.conc_step free_set_TSO CFGs can_read_TSO update_mem_TSO\"\n\nlemma SC_lt_TSO_step_threads: \"conc_step_SC gt (states, mem) (states', mem') \\<Longrightarrow> \n conc_step_TSO gt (states, mem, \\<lambda>t. []) (states', mem', \\<lambda>t. [])\"\napply (rule LLVM_threads.conc_step.cases, unfold_locales, simp, clarsimp)\napply (rule_tac ops=ops in LLVM_threads.step_thread, unfold_locales)\napply (metis TSO_alloc_not_free)\napply (metis TSO_stays_not_free)\napply (simp add: dom_def, force)\napply (cut_tac t=t in SC_lt_TSO_step, auto)\ndone\n\nterm LLVM_threads.conc_step_star\nabbreviation \"conc_step_star_SC \\<equiv> LLVM_threads.conc_step_star free_set_SC CFGs can_read_SC update_mem_SC\"\nabbreviation \"conc_step_star_TSO \\<equiv> LLVM_threads.conc_step_star free_set_TSO CFGs can_read_TSO update_mem_TSO\"\n\n(* SC is stricter than TSO. *)\ntheorem SC_lt_TSO_star: \"conc_step_star_SC gt (states, mem) (states', mem') \\<Longrightarrow> \n conc_step_star_TSO gt (states, mem, \\<lambda>t. []) (states', mem', \\<lambda>t. [])\"\napply (induct rule: rtranclp_induct2, auto)\napply (drule SC_lt_TSO_step_threads, auto)\ndone\n\nend*)\n\n(* Patterns and substitution *)\n(*\ntype_synonym 'mvar pattern =\n \"(('mvar node_lit, 'mvar, (LLVM_type, 'mvar) literal, \n ('mvar, ('mvar,int) LLVM_expr) expr_pattern, (LLVM_op, 'mvar) literal, (LLVM_cmp, 'mvar) literal) LLVM_instr, 'mvar) literal\"\n*)\nterm \"expr_pattern_fv\"\n(* Replaced by earlier instr_pattern_fv\nprimrec instr_pattern_fv :: \"(string, LLVM_type_pat, LLVM_expr_pat, LLVM_op pat, (LLVM_cmp,'mvar)literal,\n (string node_const pat \\<times> LLVM_expr_pat)list pat, LLVM_expr_pat list pat) LLVM_instr \\<Rightarrow> string set\" where\n\"instr_pattern_fv (Assign x opr ty e1 e2) = {x} \\<union> base_lit_fv opr \\<union> LLVM_type_lit_fv ty \\<union> expr_pattern_fv expr_fv e1 \\<union> expr_pattern_fv expr_fv e2\" |\n\"instr_pattern_fv (Ret ty e) = LLVM_type_lit_fv ty \\<union> expr_pattern_fv expr_fv e\" |\n\"instr_pattern_fv (Br_i1 e) = expr_pattern_fv expr_fv e\" |\n\"instr_pattern_fv (Br_label) = {}\" |\n\"instr_pattern_fv (Alloca x ty) = {x} \\<union> LLVM_type_lit_fv ty\" |\n\"instr_pattern_fv (Load x ty e) = {x} \\<union> LLVM_type_lit_fv ty \\<union> expr_pattern_fv expr_fv e\" |\n\"instr_pattern_fv (Store ty1 e1 ty2 e2) = LLVM_type_lit_fv ty1 \\<union> expr_pattern_fv expr_fv e1 \\<union> LLVM_type_lit_fv ty2 \\<union> expr_pattern_fv expr_fv e2\" |\n\"instr_pattern_fv (Cmpxchg x ty1 e1 ty2 e2 ty3 e3) = {x} \\<union> LLVM_type_lit_fv ty1 \\<union> expr_pattern_fv expr_fv e1 \\<union> \n LLVM_type_lit_fv ty2 \\<union> expr_pattern_fv expr_fv e2 \\<union> LLVM_type_lit_fv ty3 \\<union> expr_pattern_fv expr_fv e3\" |\n\"instr_pattern_fv (ICmp x cmp ty e1 e2) = {x} \\<union> base_lit_fv cmp \\<union> LLVM_type_lit_fv ty \\<union> expr_pattern_fv expr_fv e1 \\<union> expr_pattern_fv expr_fv e2\" |\n\"instr_pattern_fv (Phi x ty es) = {x} \\<union> LLVM_type_lit_fv ty \\<union> lit_fv philist_fv es\n(*(\\<Union>(n, e)\\<in>set es. node_fv n \\<union> expr_pattern_fv expr_fv e)*)\" |\n\"instr_pattern_fv (Call x ty es) = {x} \\<union> LLVM_type_lit_fv ty \\<union> lit_fv eplist_fv es\n (*(\\<Union>e\\<in>set es. expr_pattern_fv expr_fv e)*)\" |\n\"instr_pattern_fv (IsPointer e) = expr_pattern_fv expr_fv e\"\n\nlemma finite_instr_pattern_fv [simp]: \"finite (instr_pattern_fv i)\"\nby (induct i, auto)\n*)\n\nabbreviation pattern_fv::\" ('mvar gen_LLVM_instr, 'mvar)literal  \\<Rightarrow> 'mvar set\" where\n\"pattern_fv \\<equiv> \\<lambda> p. lit_fv instr_pattern_fv p\"\n\nlemma finite_pattern_fv [simp]:\nfixes p shows \"finite (pattern_fv p)\"\nby (case_tac p, auto)\n\n(* Applying a valuation of metavariables to an expression pattern yields a concrete expression. *)\n\n(* Objects are the values metavariables can take. *)\ndatatype ('thread, 'node, 'mvar) object =\n   ONode 'node \n | OThread 'thread\n | OInt int\n | OLoc int\n | OType LLVM_type\n | OConst concrete_LLVM_const\n | OExpr concrete_LLVM_expr\n | OVarName \"string\"\n | OInstr \"'node concrete_LLVM_instr\"\n | OSynFunc \"'mvar\" \"'mvar gen_LLVM_expr\"\n | OEdgeType LLVM_edge_type\n | OOp LLVM_op\n | OCmp LLVM_cmp\n | OPhiList \"'node concrete_philist\"\n | OEPList \"concrete_LLVM_expr list\"\n\nfun get_node where \"get_node (ONode n) = Some n\" | \"get_node _ = None\"\nfun get_thread where \"get_thread (OThread t) = Some t\" | \"get_thread _ = None\"\nfun get_int where \"get_int (OInt n) = Some n\" | \"get_int _ = None\"\nfun get_memloc where \"get_memloc (OLoc n) = Some n\" | \"get_memloc _ = None\"\nfun get_type where \"get_type (OType ty) = Some ty\" | \"get_type _ = None\"\nfun get_const where \"get_const (OConst n) = Some n\" | \"get_const _ = None\"\nfun get_expr where \"get_expr (OExpr n) = Some n\" | \"get_expr _ = None\"\nfun get_var_name where \"get_var_name (OVarName v) = Some v\" | \"get_var_name _ = None\"\n(*\nfun get_local_var where \"get_local_var (OExpr (Local v)) = Some v\" | \"get_local_var _ = None\"\nfun get_global_var where \"get_global_var (OExpr (Global v)) = Some v\" | \"get_global_var _ = None\"\n*)\nfun get_instr where \"get_instr (OInstr i) = Some i\" | \"get_instr _ = None\"\nfun get_synfunc where \"get_synfunc (OSynFunc x f) = Some (x, f)\" | \"get_synfunc _ = None\"\nfun get_edgetype where \"get_edgetype (OEdgeType e) = Some e\" | \"get_edgetype _ = None\"\nfun get_op where \"get_op (OOp n) = Some n\" | \"get_op _ = None\"\nfun get_cmp where \"get_cmp (OCmp n) = Some n\" | \"get_cmp _ = None\"\nfun get_philist where \"get_philist (OPhiList phl) = Some phl\" | \"get_philist _ = None\"\nfun get_eplist where \"get_eplist (OEPList epl) = Some epl\" | \"get_eplist _ = None\"\n\nprimrec LLVM_type_lit_subst where\n  \"LLVM_type_lit_subst \\<sigma> PInt_ty = Some Int_ty\"\n| \"LLVM_type_lit_subst \\<sigma> (Tymvar x) = get_type (\\<sigma> x)\"\n| \"LLVM_type_lit_subst \\<sigma> (PPointer_ty pty) =\n   (case LLVM_type_lit_subst \\<sigma> pty of Some ty \\<Rightarrow> Some (Pointer_ty ty)  | _ \\<Rightarrow> None)\"\n\nlemma LLVM_type_lit_same_subst [simp]:\n \"\\<forall>x\\<in>LLVM_type_lit_fv ty. \\<sigma> x = \\<sigma>' x \\<Longrightarrow>\n  LLVM_type_lit_subst \\<sigma> ty = LLVM_type_lit_subst \\<sigma>' ty\"\nby (induct ty, auto)\n\n\nprimrec const_subst :: \"('mvar \\<Rightarrow> ('thread, 'node, 'mvar) object) \\<Rightarrow>\n 'mvar gen_LLVM_const \\<Rightarrow> concrete_LLVM_const option\" where\n  \"const_subst \\<sigma> (CInt ip) = map_option CInt (base_lit_subst get_int \\<sigma> ip)\"\n| \"const_subst \\<sigma> CNull = Some CNull\"\n| \"const_subst \\<sigma> (CPointer ip) = map_option CPointer (base_lit_subst get_int \\<sigma> ip)\"\n| \"const_subst \\<sigma> CUndef = Some CUndef\"\n\nlemma const_same_subst [simp]: \"\\<forall>x\\<in>LLVM_const_lit_fv c. \\<sigma> x = \\<sigma>' x \\<Longrightarrow> const_subst \\<sigma> c = const_subst \\<sigma>' c\"\nproof (cases c, auto)\n fix var\n assume A: \"\\<forall>x\\<in>base_lit_fv var. \\<sigma> x = \\<sigma>' x \" and B: \"c = CInt var\"\n from A\n have B: \"base_lit_subst get_int \\<sigma> var = base_lit_subst get_int \\<sigma>' var\"\n by simp\n from B\n show \"map_option CInt (base_lit_subst get_int \\<sigma> var) = map_option CInt (base_lit_subst get_int \\<sigma>' var)\"\n by simp\n next fix loc\n assume A: \"\\<forall>x\\<in>base_lit_fv loc. \\<sigma> x = \\<sigma>' x\" and B: \"c = CPointer loc\"\n from A\n have B: \"base_lit_subst get_int \\<sigma> loc = base_lit_subst get_int \\<sigma>' loc\"\n by simp\n from B\n show \" map_option CPointer (base_lit_subst get_int \\<sigma> loc) = map_option CPointer (base_lit_subst get_int \\<sigma>' loc)\"\n by simp\nqed\n\nprimrec expr_subst ::\n \"('mvar \\<Rightarrow> ('thread, 'node, 'mvar) object) \\<Rightarrow> 'mvar gen_LLVM_expr \\<Rightarrow>\n  concrete_LLVM_expr option\" where\n  \"expr_subst \\<sigma> (Local i) = map_option Local (get_var_name (\\<sigma> i))\" \n| \"expr_subst \\<sigma> (Const p) = map_option Const (lit_subst const_subst get_const \\<sigma> p)\"\n| \"expr_subst \\<sigma> (Global s) = map_option Global (get_var_name (\\<sigma> s))\"\n\nterm \"expr_subst\"\n\nlemma expr_same_subst [simp]:\n fixes \\<sigma> :: \"'mvar \\<Rightarrow> ('thread, 'node, 'mvar) object\"\n   and \\<sigma>' :: \"'mvar \\<Rightarrow> ('thread, 'node, 'mvar) object\"\n   and e :: \"'mvar gen_LLVM_expr\"\n shows \"\\<forall>v\\<in>expr_fv e. \\<sigma> v = \\<sigma>' v \\<Longrightarrow> expr_subst \\<sigma> e = expr_subst \\<sigma>' e\"\nproof (case_tac e, auto, case_tac cvar, simp_all)\n fix c :: \"'mvar gen_LLVM_const\"\n assume A: \"\\<forall>(v::'mvar)\\<in>LLVM_const_lit_fv c. \\<sigma> v = \\<sigma>' v\"\n from A have A1: \"const_subst \\<sigma> c = const_subst \\<sigma>' c\" by simp\n from A1\n show \"map_option Const (const_subst \\<sigma> c) = map_option Const (const_subst \\<sigma>' c)\" by simp\nqed\n\nterm \"expr_subst\"\n\n(* Why would you expect this to be true?  You could very well have two different\n   metavariables referring to the same programming variable \nlemma self_subst: \"expr_subst (\\<lambda>y. OExpr (Local y)) e = Some e\"\nby (induct e, auto)\n\ncorollary subst_out: \"\\<forall>v\\<in>expr_fv e. \\<sigma> v = OExpr (Local v) \\<Longrightarrow> expr_subst \\<sigma> e = Some e\"\nby (rule trans, rule expr_same_subst, auto simp add: self_subst)\n\nlemma sub_out: \"\\<lbrakk>v \\<in> expr_fv e; v' \\<notin> expr_fv e\\<rbrakk> \\<Longrightarrow> \\<exists>e'. \n expr_subst ((\\<lambda>y. OExpr (Local y))(v := OExpr (Local v'))) e = Some e' \\<and>\n expr_subst ((\\<lambda>y. OExpr (Local y))(v' := OExpr (Local v))) e' = Some e\"\nby (induct e, auto)\n*)\n\nprimrec expr_pattern_subst :: \"('mvar \\<Rightarrow> ('thread, 'node, 'mvar) object) \\<Rightarrow>\n 'mvar LLVM_expr_pat \\<Rightarrow> concrete_LLVM_expr option\"\n where\n\"expr_pattern_subst \\<sigma> (EPInj e) = expr_subst \\<sigma> e\"\n(*| \"expr_pattern_subst \\<sigma> (x<e>) = (case (\\<sigma> x, expr_subst \\<sigma> e) of \n (OSynFunc x e, Some e') \\<Rightarrow> expr_subst ((\\<lambda>y. OExpr (Local y))(x := OExpr e')) e\n | _ \\<Rightarrow> None)\"*)\n| \"expr_pattern_subst \\<sigma> (x<e>) =\n    (case (\\<sigma> x, expr_subst \\<sigma> e) of (OSynFunc y e', Some e'') \\<Rightarrow>\n       expr_subst (\\<lambda> y. ((OExpr e''):: ('thread, 'node, 'mvar) object)) e'\n      | _ \\<Rightarrow> None)\"\n| \"expr_pattern_subst \\<sigma> (EPMVar x) = get_expr (\\<sigma> x)\"\n\n\n(* Isabelle note: this type annotation is necessary because OExpr e', in itself,\n   is of type (?, ?) object.  We need to identify the missing types with existing\n   type variables, or they'll be introduced as separate variables. *)\n\nlemma expr_pattern_same_subst [simp]: \"\\<forall>v\\<in>expr_pattern_fv expr_fv e. \\<sigma> v = \\<sigma>' v \\<Longrightarrow>\n expr_pattern_subst \\<sigma> e = expr_pattern_subst \\<sigma>' e\"\napply (induct e, auto split: object.split LLVM_expr.split)\napply (drule expr_same_subst, simp)+\ndone\n\nterm \"(\\<lambda> epl'. map_option (\\<lambda> ep'. ep' # epl) (expr_pattern_subst \\<sigma> ep))\"\n\nabbreviation eplist_subst :: \"('mvar \\<Rightarrow> ('thread, 'node, 'mvar) object) \\<Rightarrow>\n 'mvar LLVM_expr_pat list \\<Rightarrow> concrete_LLVM_expr list option\" where\n\"eplist_subst \\<equiv> \n\\<lambda> \\<sigma> epl. foldr \n (\\<lambda> ep r. flatten_option\n    (map_option\n      (\\<lambda> epl'. map_option (\\<lambda> ep'. ep' # epl') (expr_pattern_subst \\<sigma> ep))\n      r)) epl (Some [])\"\n\n(* Reformulate this in terms of map_option and flatten_option ---ELG *)\nlemma eplist_same_subst :\n\"\\<forall> es. (\\<forall>v\\<in>eplist_fv es. \\<sigma> v = \\<sigma>' v) \\<longrightarrow> (eplist_subst \\<sigma> es = eplist_subst \\<sigma>' es)\"\nproof (rule allI)\n fix es \n show \"(\\<forall>v\\<in>eplist_fv es. \\<sigma> v = \\<sigma>' v) \\<longrightarrow> (eplist_subst \\<sigma> es = eplist_subst \\<sigma>' es)\"\n proof (induct es, auto)\n  fix a es\n  assume A1: \"eplist_subst \\<sigma> es = eplist_subst \\<sigma>' es\"\n   and A2: \"\\<forall>v\\<in>expr_pattern_fv expr_fv a \\<union> eplist_fv es. \\<sigma> v = \\<sigma>' v\"\n  show \"flatten_option (map_option (\\<lambda>epl'. map_option (\\<lambda>ep'. ep' # epl') (expr_pattern_subst \\<sigma> a)) (eplist_subst \\<sigma>' es)) =\n       flatten_option (map_option (\\<lambda>epl'. map_option (\\<lambda>ep'. ep' # epl') (expr_pattern_subst \\<sigma>' a)) (eplist_subst \\<sigma>' es))\"\n  proof -\n   from A2\n   have A3: \"expr_pattern_subst \\<sigma> a = expr_pattern_subst \\<sigma>' a\"\n   by auto\n   from A3 show ?thesis\n   by simp\n  qed\n qed\nqed\n\n(* We make no assumptions about our type of concrete nodes here *)\nfun node_subst where\n  \"node_subst CFGs \\<sigma> (MVar m) = get_node (\\<sigma> m)\"\n| \"node_subst CFGs \\<sigma> (Inj (NExit t)) = map_option Exit (flatten_option (map_option CFGs (get_thread (\\<sigma> t))))\"\n(*   (case \\<sigma> t of OThread t' \\<Rightarrow>  map_option Exit t' | _ \\<Rightarrow> None) *)\n| \"node_subst CFGs \\<sigma> (Inj (NStart t)) = map_option Start (flatten_option (map_option CFGs (get_thread (\\<sigma> t))))\"\n(*   (case \\<sigma> t of OThread t' \\<Rightarrow> map_option Start t' | _ \\<Rightarrow> None)*)\n\nterm \"node_subst\"\n\nlemma node_same_subst:\n \"\\<forall>x\\<in> lit_fv node_fv n. \\<sigma> x = \\<sigma>' x \\<Longrightarrow> node_subst CFGs \\<sigma> n = node_subst CFGs \\<sigma>' n\"\napply (cases n, auto)\napply (case_tac data, auto split: object.splits)\ndone\nabbreviation edge_type_subst where \"edge_type_subst \\<equiv> base_lit_subst get_edgetype\"\nterm \"edge_type_subst =  base_lit_subst get_edgetype\"\n\nlemma edge_type_same_subst: \"\\<forall>x\\<in>base_lit_fv ety. \\<sigma> x = \\<sigma>' x \\<Longrightarrow> edge_type_subst \\<sigma> ety = edge_type_subst \\<sigma>' ety\"\nby simp\n\nabbreviation op_subst where \"op_subst \\<equiv> base_lit_subst get_op\"\n\n(*\nlemma op_same_subst: \"\\<forall>x\\<in>base_lit_fv p. \\<sigma> x = \\<sigma>' x \\<Longrightarrow> op_subst \\<sigma> p = op_subst \\<sigma>' p\"\nby (simp)\n*)\n\nabbreviation cmp_subst where \"cmp_subst \\<equiv> base_lit_subst get_cmp\"\n\nlemma cmp_same_subst: \"\\<forall>x\\<in>base_lit_fv p. \\<sigma> x = \\<sigma>' x \\<Longrightarrow> cmp_subst \\<sigma> p = cmp_subst \\<sigma>' p\"\nby auto\n\nlemma case_node [simp]: \"(get_node v = Some n) = (v = ONode n)\"\nby (case_tac \"v\", auto)\n\nlemma case_int [simp]: \"(get_int v = Some i) = (v = OInt i)\"\nby (case_tac \"v\", auto)\n\nlemma case_loc [simp]: \"(get_memloc v = Some i) = (v = OLoc i)\"\nby (case_tac \"v\", auto)\n\nlemma case_instr [simp]: \"(get_instr v = Some i) = (v = OInstr i)\"\nby (case_tac \"v\", auto)\n\nlemma case_expr [simp]: \"(get_expr v = Some a) = (v = OExpr a)\"\nby (case_tac \"v\", auto)\n\n(*  When do we actually use OSynFunc? Is x<e> used in any examples we have? ---ELG *)\nlemma case_syn_func [simp]: \"(get_synfunc v = Some (x,f)) = (v = OSynFunc x f)\"\nby (case_tac \"v\", auto)\n\nlemma case_edge_type [simp]: \"(get_edgetype v = Some e) = (v = OEdgeType e)\"\nby (case_tac \"v\", auto)\n\nlemma case_thread [simp]: \"((case v of OThread x \\<Rightarrow> P x | _ \\<Rightarrow> False)) = (\\<exists>t. v = OThread t \\<and> P t)\"\nby (case_tac \"v\", auto)\n\nlemma get_thread_simp [simp]: \"(get_thread v = Some t) = (v = OThread t)\"\nby (case_tac \"v\", auto)\n\nlemma case_const [simp]: \"(get_const v = Some c) = (v = OConst c)\"\nby (case_tac \"v\", auto)\n\nlemma case_type [simp]: \"(get_type v = Some a) = (v = OType a)\"\nby (case_tac \"v\", auto)\n\nlemma case_op [simp]: \"(get_op v = Some a) = (v = OOp a)\"\nby (case_tac \"v\", auto)\n\nterm \"node_subst (G::('thread \\<Rightarrow> ('node, LLVM_edge_type, 'node concrete_LLVM_instr)flowgraph option))\"\nabbreviation philist_subst\n(*\n:: \"('thread \\<Rightarrow> ('thread, 'node, 'mvar)flowgraph option) \\<Rightarrow> \n  ('mvar \\<Rightarrow> ('thread, 'node, 'mvar) object) \\<Rightarrow>\n  (('mvar node_const,'mvar)literal, 'mvar) gen_philist \\<Rightarrow>\n  ('node \\<times> concrete_LLVM_expr) list option\" \n*)\n where\n\"philist_subst \\<equiv> \\<lambda> (G::('thread \\<Rightarrow> ('node, LLVM_edge_type, 'node concrete_LLVM_instr)flowgraph option))\n (\\<sigma>::('mvar \\<Rightarrow> ('thread, 'node, 'mvar) object))\n (es::'mvar gen_philist).\n foldr (\\<lambda>(n, e) r.\n  flatten_option (map_option\n  (\\<lambda> es'. flatten_option (map_option\n         (\\<lambda> e'. map_option\n                (\\<lambda> n'. (n',e') # es')\n                (node_subst G \\<sigma> n ))\n         (expr_pattern_subst \\<sigma> e)))\n  r))\n  (es:: 'mvar gen_philist)\n  (Some [])\"\n\nterm \"philist_subst\"\nterm \"philist_fv\"\nlemma philist_same_subst [simp]:\n\"(\\<forall>x\\<in> philist_fv es. \\<sigma> x = \\<sigma>' x) \\<Longrightarrow> philist_subst CFGs \\<sigma> es = philist_subst CFGs \\<sigma>' es\"\napply (erule rev_mp)\napply (induct es, auto (*split del: option.splits*))\napply (cut_tac \\<sigma>=\\<sigma> and \\<sigma>'=\\<sigma>' and e=b in expr_pattern_same_subst, simp, simp (no_asm_simp))\nby (cut_tac \\<sigma>=\\<sigma> and \\<sigma>'=\\<sigma>' and n=a and CFGs = CFGs in node_same_subst, simp, simp (no_asm_simp))\n\nterm \"philist_subst\"\n(* Similarly, applying a valuation of metavariables to an instruction pattern yields a concrete instruction. *)\nprimrec instr_subst ::\n\"('thread \\<Rightarrow> ('node, LLVM_edge_type, 'node concrete_LLVM_instr)flowgraph option) \\<Rightarrow>\n ('mvar \\<Rightarrow> ('thread, 'node, 'mvar) object) \\<Rightarrow>\n 'mvar gen_LLVM_instr \\<Rightarrow>\n 'node concrete_LLVM_instr option\" where\n\"instr_subst CFGs \\<sigma> (Assign x opr ty e1 e2) =\n flatten_option (map_option (\\<lambda> x'. flatten_option (map_option\n  (\\<lambda> opr'. flatten_option (map_option (\\<lambda> ty'. flatten_option (map_option\n   (\\<lambda> e1'. map_option (\\<lambda> e2'. Assign x' opr' ty' e1' e2') (expr_pattern_subst \\<sigma> e2))\n   (expr_pattern_subst \\<sigma> e1)))\n   (LLVM_type_lit_subst \\<sigma> ty)))\n  (op_subst \\<sigma> opr)))\n  (get_var_name (\\<sigma> x)))\" |\n\"instr_subst CFGs \\<sigma> (Ret ty e) =\n (case (LLVM_type_lit_subst \\<sigma> ty, expr_pattern_subst \\<sigma> e) of (Some ty', Some e') \\<Rightarrow> \n   Some (Ret ty' e') | _ \\<Rightarrow> None)\" |\n\"instr_subst CFGs \\<sigma> (Br_i1 e) = map_option Br_i1 (expr_pattern_subst \\<sigma> e)\" |\n\"instr_subst CFGs \\<sigma> Br_label = Some Br_label\" |\n\"instr_subst CFGs \\<sigma> (Alloca x ty) =\n flatten_option (map_option (\\<lambda> x'. map_option (\\<lambda> ty'. Alloca x' ty')\n                                  (LLVM_type_lit_subst \\<sigma> ty))\n                 (get_var_name (\\<sigma> x)))\" |\n\"instr_subst CFGs \\<sigma> (Load x ty e) = \n flatten_option (map_option\n  (\\<lambda> x'. flatten_option (map_option\n  (\\<lambda> ty'. map_option (\\<lambda> e'. Load x' ty' e') (expr_pattern_subst \\<sigma> e))\n  (LLVM_type_lit_subst \\<sigma> ty)))\n  (get_var_name (\\<sigma> x)))\" |\n\"instr_subst CFGs \\<sigma> (Store ty1 e1 ty2 e2) =\n flatten_option (map_option\n  (\\<lambda> ty1'. flatten_option (map_option\n  (\\<lambda> e1'. flatten_option (map_option\n  (\\<lambda> ty2'. map_option (\\<lambda> e2'. Store ty1' e1' ty2' e2') (expr_pattern_subst \\<sigma> e2))\n  (LLVM_type_lit_subst \\<sigma> ty2)))\n  (expr_pattern_subst \\<sigma> e1)))\n  (LLVM_type_lit_subst \\<sigma> ty1))\" |\n\"instr_subst CFGs \\<sigma> (Cmpxchg x ty1 e1 ty2 e2 ty3 e3) =\n flatten_option (map_option\n  (\\<lambda> x'. flatten_option (map_option\n  (\\<lambda> ty1'. flatten_option (map_option\n  (\\<lambda> e1'. flatten_option (map_option\n  (\\<lambda> ty2'. flatten_option (map_option\n  (\\<lambda> e2'. flatten_option (map_option\n  (\\<lambda> ty3'. (map_option \n  (\\<lambda> e3'. Cmpxchg x' ty1' e1' ty2' e2' ty3' e3')\n  (expr_pattern_subst \\<sigma> e3)))\n  (LLVM_type_lit_subst \\<sigma> ty3)))\n  (expr_pattern_subst \\<sigma> e2)))\n  (LLVM_type_lit_subst \\<sigma> ty2)))\n  (expr_pattern_subst \\<sigma> e1)))\n  (LLVM_type_lit_subst \\<sigma> ty1)))\n  (get_var_name (\\<sigma> x)))\" |\n\"instr_subst CFGs \\<sigma> (ICmp x opr ty e1 e2) =\n flatten_option (map_option\n  (\\<lambda> x'. flatten_option (map_option\n  (\\<lambda> opr'. flatten_option (map_option\n  (\\<lambda> ty'. flatten_option (map_option\n  (\\<lambda> e1'. (map_option\n  (\\<lambda> e2'. ICmp x' opr' ty' e1' e2')\n  (expr_pattern_subst \\<sigma> e2)))\n  (expr_pattern_subst \\<sigma> e1)))\n  (LLVM_type_lit_subst \\<sigma> ty)))\n  (cmp_subst \\<sigma> opr)))\n  (get_var_name (\\<sigma> x)))\" |\n\"instr_subst CFGs \\<sigma> (Phi x ty es) =\n flatten_option (map_option\n  (\\<lambda> x'. flatten_option (map_option\n  (\\<lambda> ty'. (map_option\n  (\\<lambda> es'. Phi x' ty' es')\n  (lit_subst (philist_subst CFGs) get_philist \\<sigma> es)))\n  (LLVM_type_lit_subst \\<sigma> ty)))\n  (get_var_name (\\<sigma> x)))\" |\n\"instr_subst CFGs \\<sigma> (Call x ty es) = \n flatten_option (map_option\n  (\\<lambda> x'. flatten_option (map_option\n  (\\<lambda> ty'. (map_option\n  (\\<lambda> es'. Call x' ty' es')\n  (lit_subst eplist_subst get_eplist \\<sigma> es)))\n  (LLVM_type_lit_subst \\<sigma> ty)))\n  (get_var_name (\\<sigma> x)))\" |\n\"instr_subst CFGs \\<sigma> (IsPointer e) = map_option IsPointer (expr_pattern_subst \\<sigma> e)\"\n\n(*\ndeclare [[show_types = true]]\n*)\n\nlemma instr_same_subst [simp]:\n fixes CFGs :: \"'thread \\<Rightarrow> ('node, LLVM_edge_type, 'node concrete_LLVM_instr)flowgraph option\"\n and \\<sigma> :: \"'mvar \\<Rightarrow> ('thread, 'node, 'mvar) object\"\n and \\<sigma>':: \"'mvar \\<Rightarrow> ('thread, 'node, 'mvar) object\"\n and i :: \"'mvar gen_LLVM_instr\"\n assumes FV_assum:\"\\<forall>x\\<in>instr_pattern_fv i. \\<sigma> x = \\<sigma>' x\"\n shows \"instr_subst CFGs \\<sigma> i = instr_subst CFGs \\<sigma>' i\"\nusing FV_assum\nproof (cases i, auto)\n fix var and opr::\"(LLVM_op,'mvar)literal\" and type and expr1 and expr2\n assume A1: \"\\<sigma> var = \\<sigma>' var\"\n  and B1: \"\\<forall>x\\<in>LLVM_type_lit_fv type \\<union> base_lit_fv opr \\<union> expr_pattern_fv expr_fv expr1 \\<union> expr_pattern_fv expr_fv expr2. \\<sigma> x = \\<sigma>' x\"\n  from B1 have E1: \"(op_subst \\<sigma> opr = op_subst \\<sigma>' opr) \\<and>\n                     (LLVM_type_lit_subst \\<sigma> type = LLVM_type_lit_subst \\<sigma>' type) \\<and>\n                     (expr_pattern_subst \\<sigma> expr1) = (expr_pattern_subst \\<sigma>' expr1) \\<and>\n                     (expr_pattern_subst \\<sigma> expr2) = (expr_pattern_subst \\<sigma>' expr2)\"\n   by simp\n   from E1 show \"flatten_option\n        (map_option\n          (\\<lambda>x'. flatten_option\n                  (map_option\n                    (\\<lambda>opr'. flatten_option\n                              (map_option\n                                (\\<lambda>ty'. flatten_option\n                                         (map_option (\\<lambda>e1'. map_option (Assign x' opr' ty' e1')\n                                          (expr_pattern_subst \\<sigma> expr2)) (expr_pattern_subst \\<sigma> expr1)))\n                                (LLVM_type_lit_subst \\<sigma> type)))\n                    (op_subst \\<sigma> opr)))\n          (get_var_name (\\<sigma>' var))) =\n       flatten_option\n        (map_option\n          (\\<lambda>x'. flatten_option\n                  (map_option\n                    (\\<lambda>opr'. flatten_option\n                              (map_option\n                                (\\<lambda>ty'. flatten_option\n                                         (map_option (\\<lambda>e1'. map_option (Assign x' opr' ty' e1') (expr_pattern_subst \\<sigma>' expr2)) (expr_pattern_subst \\<sigma>' expr1)))\n                                (LLVM_type_lit_subst \\<sigma>' type)))\n                    (op_subst \\<sigma>' opr)))\n          (get_var_name (\\<sigma>' var)))\" by simp\n next (* 15 *)\n fix type and expr and x2\n assume A2: \"\\<forall>x\\<in>LLVM_type_lit_fv type \\<union> expr_pattern_fv expr_fv expr. \\<sigma> x = \\<sigma>' x \"\n from A2 have E2: \"(LLVM_type_lit_subst \\<sigma>' type = LLVM_type_lit_subst \\<sigma> type)\" by simp\n assume B2: \"LLVM_type_lit_subst \\<sigma> type = None\"\n from B2 and E2 show \"LLVM_type_lit_subst \\<sigma>' type = None\" by simp\n next (* 14 *)\n fix type expr x2 x2a\n assume A3: \"\\<forall>x\\<in>LLVM_type_lit_fv type \\<union> expr_pattern_fv expr_fv expr. \\<sigma> x = \\<sigma>' x\"\n from A3 have E3:  \"(expr_pattern_subst \\<sigma> expr) = (expr_pattern_subst \\<sigma>' expr)\" by simp\n assume B3: \"expr_pattern_subst \\<sigma> expr = None\" and C3: \"expr_pattern_subst \\<sigma>' expr = \\<lfloor>x2a\\<rfloor>\"\n from B3 and C3 and E3 show \"LLVM_type_lit_subst \\<sigma>' type = None\" by simp\n next (* 13 *)\n fix type and expr x2\n assume A4: \"\\<forall>x\\<in>LLVM_type_lit_fv type \\<union> expr_pattern_fv expr_fv expr. \\<sigma> x = \\<sigma>' x\"\n  from A4 have E4: \"(LLVM_type_lit_subst \\<sigma> type = LLVM_type_lit_subst \\<sigma>' type)\"\n   by simp\n assume B4: \"LLVM_type_lit_subst \\<sigma> type = \\<lfloor>x2\\<rfloor>\"\n from E4 and B4\n show \"\\<exists>y. LLVM_type_lit_subst \\<sigma>' type = Some y\"\n by (rule_tac x = \"x2\" in exI, clarsimp)\n next (* 12 *)\n fix type expr x2 x2a x2b\n assume A5: \"\\<forall>x\\<in>LLVM_type_lit_fv type \\<union> expr_pattern_fv expr_fv expr. \\<sigma> x = \\<sigma>' x \"\n from A5 have E5: \"(expr_pattern_subst \\<sigma> expr) = (expr_pattern_subst \\<sigma>' expr)\" by simp\n assume B5: \"expr_pattern_subst \\<sigma> expr = \\<lfloor>x2a\\<rfloor>\" and C5: \"expr_pattern_subst \\<sigma>' expr = None\"\n from E5 and B5 and C5\n show \"False\" by simp\n next (* 11 *)\n fix type expr x2 x2a x2b x2c\n assume A6: \"\\<forall>x\\<in>LLVM_type_lit_fv type \\<union> expr_pattern_fv expr_fv expr. \\<sigma> x = \\<sigma>' x\"\n from A6 have E6: \"(LLVM_type_lit_subst \\<sigma> type = LLVM_type_lit_subst \\<sigma>' type)\" by simp\n assume B6: \"LLVM_type_lit_subst \\<sigma> type = \\<lfloor>x2\\<rfloor>\" and C6: \"LLVM_type_lit_subst \\<sigma>' type = \\<lfloor>x2b\\<rfloor>\"\n from E6 and B6 and C6\n show \"x2 = x2b\" by simp\n next (* 10 *)\n fix type expr x2 x2a x2b x2c\n assume A7: \"\\<forall>x\\<in>LLVM_type_lit_fv type \\<union> expr_pattern_fv expr_fv expr. \\<sigma> x = \\<sigma>' x\"\n from A7 have E7: \"(expr_pattern_subst \\<sigma> expr) = (expr_pattern_subst \\<sigma>' expr)\" by simp\n assume B7: \"expr_pattern_subst \\<sigma> expr = \\<lfloor>x2a\\<rfloor>\" and C7: \"expr_pattern_subst \\<sigma>' expr = \\<lfloor>x2c\\<rfloor>\"\n from E7 and B7 and C7 \n show \"x2a = x2c\" by simp\n next (* 9 *)\n fix expr\n assume A8: \"\\<forall>x\\<in>expr_pattern_fv expr_fv expr. \\<sigma> x = \\<sigma>' x\"\n from A8 have E8: \"(expr_pattern_subst \\<sigma> expr) = (expr_pattern_subst \\<sigma>' expr)\" by simp\n from E8\n show \"map_option Br_i1 (expr_pattern_subst \\<sigma> expr) = map_option Br_i1 (expr_pattern_subst \\<sigma>' expr)\"\n by simp\n next (* 8 *)\n fix var type\n assume A9: \"\\<sigma> var = \\<sigma>' var\" and B9: \"\\<forall>x\\<in>LLVM_type_lit_fv type. \\<sigma> x = \\<sigma>' x\"\n from A9 and B9 have E9: \"(LLVM_type_lit_subst \\<sigma> type = LLVM_type_lit_subst \\<sigma>' type)\" by simp\n from E9\n show \"flatten_option (map_option (\\<lambda>x'. map_option (Alloca x') (LLVM_type_lit_subst \\<sigma> type)) (get_var_name (\\<sigma>' var))) =\n       flatten_option (map_option (\\<lambda>x'. map_option (Alloca x') (LLVM_type_lit_subst \\<sigma>' type)) (get_var_name (\\<sigma>' var)))\"\n by simp\n next (* 7 *)\n fix var type expr\n assume A10: \"\\<sigma> var = \\<sigma>' var\"\n   and B10: \"\\<forall>x\\<in>LLVM_type_lit_fv type \\<union> expr_pattern_fv expr_fv expr. \\<sigma> x = \\<sigma>' x\"\n from A10 and B10\n have E10: \"(LLVM_type_lit_subst \\<sigma> type = LLVM_type_lit_subst \\<sigma>' type) \\<and>\n            (expr_pattern_subst \\<sigma> expr) = (expr_pattern_subst \\<sigma>' expr)\" by simp\n from E10\n show \"flatten_option\n        (map_option (\\<lambda>x'. flatten_option (map_option (\\<lambda>ty'. map_option (Load x' ty') (expr_pattern_subst \\<sigma> expr)) (LLVM_type_lit_subst \\<sigma> type)))\n          (get_var_name (\\<sigma>' var))) =\n       flatten_option\n        (map_option (\\<lambda>x'. flatten_option (map_option (\\<lambda>ty'. map_option (Load x' ty') (expr_pattern_subst \\<sigma>' expr)) (LLVM_type_lit_subst \\<sigma>' type)))\n          (get_var_name (\\<sigma>' var)))\" by simp\n next (* 6 *)\n fix type1 expr1 type2 expr2\n assume A11: \"\\<forall>x\\<in>LLVM_type_lit_fv type1 \\<union> expr_pattern_fv expr_fv expr1 \\<union> LLVM_type_lit_fv type2 \\<union> expr_pattern_fv expr_fv expr2. \\<sigma> x = \\<sigma>' x \"\n from A11 have E11: \"(LLVM_type_lit_subst \\<sigma> type1 = LLVM_type_lit_subst \\<sigma>' type1) \\<and>\n                     (expr_pattern_subst \\<sigma> expr1) = (expr_pattern_subst \\<sigma>' expr1) \\<and>\n                     (LLVM_type_lit_subst \\<sigma> type2 = LLVM_type_lit_subst \\<sigma>' type2) \\<and>\n                     (expr_pattern_subst \\<sigma> expr2) = (expr_pattern_subst \\<sigma>' expr2)\" by simp\n from E11\n show \"flatten_option\n        (map_option\n          (\\<lambda>ty1'. flatten_option\n                    (map_option (\\<lambda>e1'. flatten_option (map_option (\\<lambda>ty2'. map_option (Store ty1' e1' ty2') (expr_pattern_subst \\<sigma> expr2)) (LLVM_type_lit_subst \\<sigma> type2)))\n                      (expr_pattern_subst \\<sigma> expr1)))\n          (LLVM_type_lit_subst \\<sigma> type1)) =\n       flatten_option\n        (map_option\n          (\\<lambda>ty1'. flatten_option\n                    (map_option\n                      (\\<lambda>e1'. flatten_option (map_option (\\<lambda>ty2'. map_option (Store ty1' e1' ty2') (expr_pattern_subst \\<sigma>' expr2)) (LLVM_type_lit_subst \\<sigma>' type2)))\n                      (expr_pattern_subst \\<sigma>' expr1)))\n          (LLVM_type_lit_subst \\<sigma>' type1))\" by simp\n next (* 5 *)\n fix var type1 expr1 type2 expr2 type3 expr3\n assume A12: \"\\<sigma> var = \\<sigma>' var\"\n   and B12: \"\\<forall>x\\<in>LLVM_type_lit_fv type1 \\<union> expr_pattern_fv expr_fv expr1 \\<union> LLVM_type_lit_fv type2 \\<union> expr_pattern_fv expr_fv expr2 \\<union> LLVM_type_lit_fv type3 \\<union>\n           expr_pattern_fv expr_fv expr3. \\<sigma> x = \\<sigma>' x\"\n from A12 and B12 have E12: \"(LLVM_type_lit_subst \\<sigma> type1 = LLVM_type_lit_subst \\<sigma>' type1) \\<and>\n                     (expr_pattern_subst \\<sigma> expr1) = (expr_pattern_subst \\<sigma>' expr1) \\<and>\n                     (LLVM_type_lit_subst \\<sigma> type2 = LLVM_type_lit_subst \\<sigma>' type2) \\<and>\n                     (expr_pattern_subst \\<sigma> expr2) = (expr_pattern_subst \\<sigma>' expr2) \\<and>\n                     (LLVM_type_lit_subst \\<sigma> type3 = LLVM_type_lit_subst \\<sigma>' type3) \\<and>\n                     (expr_pattern_subst \\<sigma> expr3) = (expr_pattern_subst \\<sigma>' expr3)\" by simp\n from E12 show \"flatten_option\n        (map_option\n          (\\<lambda>x'. flatten_option\n                  (map_option\n                    (\\<lambda>ty1'. flatten_option\n                              (map_option\n                                (\\<lambda>e1'. flatten_option\n                                         (map_option\n                                           (\\<lambda>ty2'. flatten_option\n                                                     (map_option\n                                                       (\\<lambda>e2'. flatten_option\n                                                                (map_option (\\<lambda>ty3'. map_option (Cmpxchg x' ty1' e1' ty2' e2' ty3') (expr_pattern_subst \\<sigma> expr3))\n                                                                  (LLVM_type_lit_subst \\<sigma> type3)))\n                                                       (expr_pattern_subst \\<sigma> expr2)))\n                                           (LLVM_type_lit_subst \\<sigma> type2)))\n                                (expr_pattern_subst \\<sigma> expr1)))\n                    (LLVM_type_lit_subst \\<sigma> type1)))\n          (get_var_name (\\<sigma>' var))) =\n       flatten_option\n        (map_option\n          (\\<lambda>x'. flatten_option\n                  (map_option\n                    (\\<lambda>ty1'. flatten_option\n                              (map_option\n                                (\\<lambda>e1'. flatten_option\n                                         (map_option\n                                           (\\<lambda>ty2'. flatten_option\n                                                     (map_option\n                                                       (\\<lambda>e2'. flatten_option\n                                                                (map_option (\\<lambda>ty3'. map_option (Cmpxchg x' ty1' e1' ty2' e2' ty3') (expr_pattern_subst \\<sigma>' expr3))\n                                                                  (LLVM_type_lit_subst \\<sigma>' type3)))\n                                                       (expr_pattern_subst \\<sigma>' expr2)))\n                                           (LLVM_type_lit_subst \\<sigma>' type2)))\n                                (expr_pattern_subst \\<sigma>' expr1)))\n                    (LLVM_type_lit_subst \\<sigma>' type1)))\n          (get_var_name (\\<sigma>' var)))\" by simp\n next (* 4 *)\n fix var and cmp :: \"(LLVM_cmp,'mvar)literal\" and type and expr1 and expr2\n assume A13: \"\\<sigma> var = \\<sigma>' var\"\n  and B13: \"\\<forall>x\\<in>base_lit_fv cmp \\<union> LLVM_type_lit_fv type \\<union> expr_pattern_fv expr_fv expr1 \\<union> expr_pattern_fv expr_fv expr2. \\<sigma> x = \\<sigma>' x\"\n from A13 and B13 \n have E13: \"(cmp_subst \\<sigma> cmp = cmp_subst \\<sigma>' cmp) \\<and>\n                     (LLVM_type_lit_subst \\<sigma> type = LLVM_type_lit_subst \\<sigma>' type) \\<and>\n                     (expr_pattern_subst \\<sigma> expr1) = (expr_pattern_subst \\<sigma>' expr1) \\<and>\n                     (expr_pattern_subst \\<sigma> expr2) = (expr_pattern_subst \\<sigma>' expr2)\"\n   by simp\n from E13\n show \"flatten_option\n        (map_option\n          (\\<lambda>x'. flatten_option\n                  (map_option\n                    (\\<lambda>opr'. flatten_option\n                              (map_option\n                                (\\<lambda>ty'. flatten_option (map_option (\\<lambda>e1'. map_option (ICmp x' opr' ty' e1') (expr_pattern_subst \\<sigma> expr2)) (expr_pattern_subst \\<sigma> expr1)))\n                                (LLVM_type_lit_subst \\<sigma> type)))\n                    (cmp_subst \\<sigma> cmp)))\n          (get_var_name (\\<sigma>' var))) =\n       flatten_option\n        (map_option\n          (\\<lambda>x'. flatten_option\n                  (map_option\n                    (\\<lambda>opr'. flatten_option\n                              (map_option\n                                (\\<lambda>ty'. flatten_option\n                                         (map_option (\\<lambda>e1'. map_option (ICmp x' opr' ty' e1') (expr_pattern_subst \\<sigma>' expr2)) (expr_pattern_subst \\<sigma>' expr1)))\n                                (LLVM_type_lit_subst \\<sigma>' type)))\n                    (cmp_subst \\<sigma>' cmp)))\n          (get_var_name (\\<sigma>' var)))\" by simp\n next (* 3 *)\n fix var type phi_list\n assume A14: \"\\<sigma> var = \\<sigma>' var\"\n  and B14: \"\\<forall>x\\<in>LLVM_type_lit_fv type \\<union> lit_fv philist_fv phi_list. \\<sigma> x = \\<sigma>' x\"\n from A14 and B14\n have E14: \"(lit_subst (philist_subst CFGs) get_philist \\<sigma> phi_list = lit_subst(philist_subst CFGs) get_philist \\<sigma>' phi_list) \\<and>\n            (LLVM_type_lit_subst \\<sigma> type = LLVM_type_lit_subst \\<sigma>' type)\"\n proof auto\n show \"lit_subst (philist_subst CFGs) get_philist \\<sigma> phi_list = lit_subst (philist_subst CFGs) get_philist \\<sigma>' phi_list\"\nthm lit_same_subst\n  proof (rule_tac data_fv = \"philist_fv\" and data_subst = \"philist_subst CFGs\"  and get_data = get_philist in lit_same_subst)\n   show \"\\<forall>x. (\\<forall>v\\<in>philist_fv x. \\<sigma> v = \\<sigma>' v) \\<longrightarrow> philist_subst CFGs \\<sigma> x = philist_subst CFGs \\<sigma>' x\"\n   by auto\n  next\n  from B14\n  show \"\\<forall>v\\<in>lit_fv philist_fv phi_list. \\<sigma> v = \\<sigma>' v\" by auto\n  qed\n qed\n from E14\n show \"flatten_option\n        (map_option\n          (\\<lambda>x'. flatten_option\n                 (map_option\n                   (\\<lambda>ty'. map_option (Phi x' ty')\n                           (lit_subst (philist_subst CFGs) get_philist \\<sigma>\n                             phi_list))\n                   (LLVM_type_lit_subst \\<sigma> type)))\n          (get_var_name (\\<sigma>' var))) =\n       flatten_option\n        (map_option\n          (\\<lambda>x'. flatten_option\n                 (map_option\n                   (\\<lambda>ty'. map_option (Phi x' ty')\n                           (lit_subst (philist_subst CFGs) get_philist \\<sigma>'\n                             phi_list))\n                   (LLVM_type_lit_subst \\<sigma>' type)))\n          (get_var_name (\\<sigma>' var)))\"\n by simp\n next (* 2 *)\n fix var type args\n assume A15: \"\\<sigma> var = \\<sigma>' var\"\n  and B15: \"\\<forall>x\\<in>LLVM_type_lit_fv type \\<union> lit_fv eplist_fv args. \\<sigma> x = \\<sigma>' x \"\n from A15 and B15\n have E15: \"((lit_subst eplist_subst get_eplist \\<sigma> args) = (lit_subst eplist_subst get_eplist \\<sigma>' args)) \\<and>\n            (LLVM_type_lit_subst \\<sigma> type = LLVM_type_lit_subst \\<sigma>' type)\"\n proof auto\n  show \"lit_subst eplist_subst get_eplist \\<sigma> args = lit_subst eplist_subst get_eplist \\<sigma>' args\"\n  proof (rule_tac data_fv = \"eplist_fv\" and data_subst = \"eplist_subst\"  and get_data = get_eplist in lit_same_subst)\n   show \"\\<forall>x. (\\<forall>v\\<in>eplist_fv x. \\<sigma> v = \\<sigma>' v) \\<longrightarrow> eplist_subst \\<sigma> x = eplist_subst \\<sigma>' x\" \n   by (rule eplist_same_subst)\n   next\n   from B15\n   show \" \\<forall>v\\<in>lit_fv eplist_fv args. \\<sigma> v = \\<sigma>' v\" by auto\n  qed\n qed\n from E15\n show \"flatten_option\n        (map_option\n          (\\<lambda>x'. flatten_option\n                 (map_option (\\<lambda>ty'. map_option (Call x' ty') (lit_subst eplist_subst get_eplist \\<sigma> args)) (LLVM_type_lit_subst \\<sigma> type)))\n          (get_var_name (\\<sigma>' var))) =\n       flatten_option\n        (map_option\n          (\\<lambda>x'. flatten_option\n                 (map_option (\\<lambda>ty'. map_option (Call x' ty') (lit_subst eplist_subst get_eplist \\<sigma>' args)) (LLVM_type_lit_subst \\<sigma>' type)))\n          (get_var_name (\\<sigma>' var)))\"\n by simp\n next (* 1 *)\n fix expr\n assume A16: \"\\<forall>x\\<in>expr_pattern_fv expr_fv expr. \\<sigma> x = \\<sigma>' x\"\n from A16\n have E16: \"(expr_pattern_subst \\<sigma> expr = expr_pattern_subst \\<sigma>' expr)\" by simp\n from E16\n show \"map_option IsPointer (expr_pattern_subst \\<sigma> expr) = map_option IsPointer (expr_pattern_subst \\<sigma>' expr)\"\n by simp\nqed\n\n\nprimrec subst where\n\"subst CFGs \\<sigma> (Inj i) = instr_subst CFGs \\<sigma> i\" |\n\"subst CFGs \\<sigma> (MVar x) = get_instr (\\<sigma> x)\"\n\nterm \"subst\"\n\nterm \"pattern_fv\"\nterm \"instr_subst G \\<sigma>\"\nlemma pattern_same_subst:\nfixes CFGs and \\<sigma> and \\<sigma>'\nshows  \"\\<forall>x\\<in>pattern_fv p. \\<sigma> x = \\<sigma>' x \\<Longrightarrow> subst CFGs \\<sigma> p = subst CFGs \\<sigma>' p\"\nby (cases p, auto)\n\nend\n", "meta": {"author": "liyili2", "repo": "timed-relaxed-memory-model", "sha": "6d85bc75d8b04228b3e581b945e3f672395f0c66", "save_path": "github-repos/isabelle/liyili2-timed-relaxed-memory-model", "path": "github-repos/isabelle/liyili2-timed-relaxed-memory-model/timed-relaxed-memory-model-6d85bc75d8b04228b3e581b945e3f672395f0c66/LLVM.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5851011686727231, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.28112863604815547}}
{"text": "theory RepeatUpdate\n  imports UpdateSemHelper\nbegin\n\nsection \"Repeat loop definitions\" \n\ntext \"Main body:\n  Summary:\n    Does at most @{term \\<open>n::nat\\<close>} iterations and apply @{term \\<open>g ::'f expr\\<close>} to update the input\n    accumulator and heap. If @{term \\<open>f ::'f expr\\<close>} returns @{term True} then terminate early.\n  Arguments:\n    @{term \\<open>\\<xi>'::('f, 'a, 'l) uabsfuns\\<close>} is a partial mapping from abstract function names to their specifications,\n    @{term \\<open>n::nat\\<close>} is a natural number that is recursed on, i.e. terminate if 0 else subtract 1, apply body and repeat ,\n    @{term \\<open>f ::'f expr\\<close>} is a Cogent expression that is used to check if the loop should terminate early,\n    @{term \\<open>g ::'f expr\\<close>} is a Cogent expression that is used to update the heap and the accumulator,\n    @{term \\<open>\\<sigma>::('f, 'a, 'l) store\\<close>} is the input heap that is updated each loop iteration,\n    @{term \\<open>\\<sigma>'::('f, 'a, 'l) store\\<close>} is the output heap,\n    @{term \\<open>\\<tau>a::type\\<close>} is the Cogent type of the accumulator,\n    @{term \\<open>acc::('f, 'a, 'l) uval\\<close>} is the accumulator that is updated each loop iteration,\n    @{term \\<open>\\<tau>o::type\\<close>} is the Cogent type of the observer,\n    @{term \\<open>obsv::('f, 'a, 'l) uval\\<close>} is the observer that does not change throughout the loop,\n    @{term \\<open>ret::('f, 'a, 'l) uval\\<close>} is the is the output accumulator value.\n  Output:\n    @{term True} if the loop evaluates to the output heap and accumulator,\n    @{term False} otherwise.\"\n\nfun urepeat_bod\n  where\n\"urepeat_bod _ 0 _ _ \\<sigma> \\<sigma>' _ acc _ _ ret = (\\<sigma> = \\<sigma>' \\<and> acc = ret)\" |\n\"urepeat_bod \\<xi>' (Suc n) f g \\<sigma> \\<sigma>' \\<tau>a acc \\<tau>o obsv ret =\n  (\\<exists>b. (\\<xi>' , [URecord [(acc, type_repr (bang \\<tau>a)), (obsv, type_repr \\<tau>o)] None] \n      \\<turnstile> (\\<sigma>, App f (Var 0)) \\<Down>! (\\<sigma>, UPrim (LBool b))) \\<and>\n    (if b then \\<sigma> = \\<sigma>' \\<and> acc = ret\n     else (\\<exists>\\<sigma>'' acc'. (\\<xi>' , [URecord [(acc, type_repr \\<tau>a), (obsv, type_repr \\<tau>o)] None] \n        \\<turnstile> (\\<sigma>, App g (Var 0)) \\<Down>! (\\<sigma>'', acc')) \\<and>\n      urepeat_bod \\<xi>' n f g \\<sigma>'' \\<sigma>' \\<tau>a acc' \\<tau>o obsv ret)))\"\n\ntext \"Wrapper with extra checks:\n  Summary:\n    Checks the arguments are of the correct form and type and then passes these to\n    @{term urepeat_bod} with minor processing.\n  Checks:\n    * The observer type has been banged, i.e. is read-only or is drop-able.\n    * The functions f and g are of the correct type and form.\"\n\ndefinition urepeat\n  where\n\"urepeat \\<Xi>' \\<xi>' \\<tau>a \\<tau>o x y =\n  (\\<exists>\\<sigma> \\<sigma>' n f g acc obsv ret.\n    x = (\\<sigma>, URecord [(UPrim (LU64 n), RPrim (Num U64)), (f, RFun), (g, RFun),\n      (acc, type_repr \\<tau>a), (obsv, type_repr \\<tau>o)] None) \\<and>\n    y = (\\<sigma>', ret) \\<and>\n    is_uvalfun f \\<and>\n    is_uvalfun g \\<and>\n    bang \\<tau>o = \\<tau>o \\<and>\n    (\\<Xi>', 0, [], {}, \n      [option.Some (TRecord [(''acc'', bang \\<tau>a, Present), (''obsv'', \\<tau>o, Present)] Unboxed)]\n      \\<turnstile> (App (uvalfun_to_expr f) (Var 0)) : TPrim Bool) \\<and>\n    (\\<Xi>', 0, [], {}, \n      [option.Some (TRecord [(''acc'', \\<tau>a, Present), (''obsv'', \\<tau>o, Present)] Unboxed)]\n      \\<turnstile> (App (uvalfun_to_expr g) (Var 0)) : \\<tau>a) \\<and>\n    urepeat_bod \\<xi>' (unat n) (uvalfun_to_expr f) (uvalfun_to_expr g) \\<sigma> \\<sigma>' \\<tau>a acc \\<tau>o obsv ret)\"\n\nsection \"Repeat loop lemmas\"\n\ncontext update_sem begin\n\nsubsection \"Preservation and frame constraint satisfaction\"\n\nlemma urepeat_bod_preservation:\n  \"\\<lbrakk>proc_ctx_wellformed \\<Xi>';\n    \\<xi>' matches-u \\<Xi>';\n    \\<Xi>', \\<sigma> \\<turnstile> acc :u \\<tau>a \\<langle>ra, wa\\<rangle>;\n    \\<Xi>', \\<sigma> \\<turnstile> obsv :u \\<tau>o \\<langle>ro, {}\\<rangle>;\n    ro \\<inter> wa = {};\n    urepeat_bod \\<xi>' n f g \\<sigma> \\<sigma>' \\<tau>a acc \\<tau>o obsv ret;\n    \\<Xi>', 0, [], {}, \n    [option.Some (TRecord [(''acc'', \\<tau>a, Present), (''obsv'', \\<tau>o, Present)] Unboxed)] \\<turnstile> (App g (Var 0)) : \\<tau>a\\<rbrakk>\n      \\<Longrightarrow> \\<exists>r' w'. \\<Xi>', \\<sigma>' \\<turnstile> ret :u \\<tau>a \\<langle>r', w'\\<rangle> \\<and> r' \\<subseteq> (ra \\<union> ro) \\<and> frame \\<sigma> wa \\<sigma>' w'\"\n  apply (induct arbitrary: ra wa rule: urepeat_bod.induct[of _ \\<xi>' n f g \\<sigma> \\<sigma>' \\<tau>a acc \\<tau>o obsv ret])\n   apply (rename_tac \\<xi>' f g \\<sigma> \\<sigma>' \\<tau>a acc \\<tau>o obsv ret ra wa)\n   apply clarsimp\n   apply (intro exI conjI, assumption, blast, rule frame_id)\n  apply (rename_tac \\<xi>' n f g \\<sigma> \\<sigma>' \\<tau>a acc \\<tau>o obsv ret ra wa)\n  apply clarsimp\n  apply (rename_tac b)\n  apply (case_tac b; clarsimp)\n   apply (intro exI conjI, assumption, blast, rule frame_id)\n  apply (drule_tac x = False in meta_spec; clarsimp)\n  apply (drule_tac x = \\<sigma>'' and y = acc' in meta_spec2)\n  apply clarsimp\n  apply (drule_tac \\<gamma> = \"[URecord [(acc, type_repr \\<tau>a), (obsv, type_repr \\<tau>o)] None]\" and\n      \\<sigma>' = \\<sigma>'' and v = acc' and r = \"ra \\<union> ro\" and w = wa in preservation_mono(1)[rotated -1]; simp?)\n   apply (intro matches_ptrs_some[where r' = \"{}\" and w' = \"{}\", simplified]\n      matches_ptrs_empty[where \\<tau>s = \"[]\", simplified])\n    apply (rule u_t_struct; simp?) \n    apply (intro u_t_r_cons1[where  r' = ro and w' = \"{}\", simplified]\n      u_t_r_cons1[where  r' = \"{}\" and w' = \"{}\", simplified] u_t_r_empty; simp?)\n    apply blast \n   apply (simp add: matches_ptrs.matches_ptrs_empty)\n  apply clarsimp\n  apply (rename_tac r' w')\n  apply (drule_tac x = r' and y = w' in meta_spec2; simp)\n  apply (erule meta_impE)\n   apply (drule_tac u = obsv in uval_typing_frame(1); simp?)\n  apply (drule meta_mp)\n   apply (drule_tac v = obsv in frame_noalias_uval_typing'(2); simp?)\n  apply clarsimp\n  apply (rename_tac r'' w'')\n  apply (intro exI conjI, assumption)\n   apply blast\n  apply (rule frame_trans; simp?)\n  done\n\nlemma urepeat_preservation:\n  \"\\<And>\\<sigma> \\<sigma>' v v' r w.\n       \\<lbrakk>proc_ctx_wellformed \\<Xi>';\n        \\<xi>' matches-u \\<Xi>';\n        \\<Xi>', \\<sigma> \\<turnstile> v :u TRecord\n                     [(''n'', TPrim (Num U64), Present),\n                      (''stop'', TFun (TRecord [(''acc'', bang \\<tau>a, Present), (''obsv'', \\<tau>o, Present)] Unboxed) (TPrim Bool), Present),\n                      (''step'', TFun (TRecord [(''acc'', \\<tau>a, Present), (''obsv'', \\<tau>o, Present)] Unboxed) \\<tau>a, Present),\n                      (''acc'', \\<tau>a, Present), (''obsv'', \\<tau>o, Present)]\n                     Unboxed \\<langle>r, w\\<rangle>;\n        urepeat \\<Xi>' \\<xi>' \\<tau>a \\<tau>o (\\<sigma>, v) (\\<sigma>', v')\\<rbrakk>\n       \\<Longrightarrow> \\<exists>r' w'. \\<Xi>', \\<sigma>' \\<turnstile> v' :u \\<tau>a \\<langle>r', w'\\<rangle> \\<and> r' \\<subseteq> r \\<and> frame \\<sigma> w \\<sigma>' w'\"\n  unfolding urepeat_def\n  apply clarsimp\n  apply (erule u_t_recE; clarsimp)\n  apply (erule u_t_r_consE; clarsimp)+\n  apply (erule u_t_r_emptyE; clarsimp)\n  apply (frule tfun_no_pointers)\n  apply (drule tfun_no_pointers(2))\n  apply clarsimp\n  apply (frule tfun_no_pointers)\n  apply (drule tfun_no_pointers(2))\n  apply clarsimp\n  apply (frule tprim_no_pointers)\n  apply (drule tprim_no_pointers(2))\n  apply clarsimp\n  apply (rename_tac \\<sigma> \\<sigma>' v' n f g acc ra wa obsv ro wo)\n  apply (cut_tac \\<Xi>' = \\<Xi>' and \\<sigma> = \\<sigma> and \\<tau> = \\<tau>o and v = obsv and r = ro and w = wo in bang_not_writable(1); simp?)\n  apply (rule urepeat_bod_preservation; simp?)\n  apply blast\n  done\n\nend (* of context *)\n\nsubsection \"Early termination and step lemmas\"\n\nlemma urepeat_bod_early_termination:\n  \"\\<lbrakk>urepeat_bod \\<xi>' i f g \\<sigma> \\<sigma>' \\<tau>a acc \\<tau>o obsv ret; i < n;\n    \\<xi>', [URecord [(ret, type_repr (bang \\<tau>a)), (obsv, type_repr \\<tau>o)] None]  \\<turnstile> (\\<sigma>', App f (Var 0)) \\<Down>! (\\<sigma>', UPrim (LBool True))\\<rbrakk>\n    \\<Longrightarrow> urepeat_bod \\<xi>' n f g \\<sigma> \\<sigma>' \\<tau>a acc \\<tau>o obsv ret\"\n  apply (induct arbitrary: i rule: urepeat_bod.induct[of _ \\<xi>' n f g \\<sigma> \\<sigma>' \\<tau>a acc \\<tau>o obsv ret])\n   apply clarsimp\n  apply clarsimp\n  apply (rename_tac i)\n  apply (case_tac i; clarsimp)\n   apply blast\n  apply (rename_tac b)\n  apply (case_tac b; clarsimp)\n   apply blast\n  apply (rename_tac ret nat b \\<sigma>'' acc')\n  apply (rule_tac x = b in exI)\n  apply (rule conjI; clarsimp)\n  apply (intro exI conjI; assumption)\n  done\n\ndeclare urepeat_bod.simps[simp del]\nlemma urepeat_bod_step:\n  \"\\<lbrakk>\\<xi>', [URecord [(ret, type_repr (bang \\<tau>a)), (obsv, type_repr \\<tau>o)] None] \\<turnstile> (\\<sigma>', App f (Var 0)) \\<Down>! (\\<sigma>', UPrim (LBool False));\n    \\<not>(\\<xi>', [URecord [(ret, type_repr (bang \\<tau>a)), (obsv, type_repr \\<tau>o)] None] \\<turnstile> (\\<sigma>', App f (Var 0)) \\<Down>! (\\<sigma>', UPrim (LBool True)));\n    \\<xi>', [URecord [(ret, type_repr \\<tau>a), (obsv, type_repr \\<tau>o)] None] \\<turnstile> (\\<sigma>', App g (Var 0)) \\<Down>! (\\<sigma>'', ret');\n    urepeat_bod \\<xi>' n f g \\<sigma> \\<sigma>' \\<tau>a acc \\<tau>o obsv ret\\<rbrakk> \n    \\<Longrightarrow> urepeat_bod \\<xi>' (Suc n) f g \\<sigma> \\<sigma>'' \\<tau>a acc \\<tau>o obsv ret'\"\n  apply (induct arbitrary: \\<sigma>'' ret' rule: urepeat_bod.induct[of _ \\<xi>' n f g \\<sigma> \\<sigma>' \\<tau>a acc \\<tau>o obsv ret])\n   apply (clarsimp simp: urepeat_bod.simps)\n  apply clarsimp\n  apply (erule urepeat_bod.elims; clarsimp)\n  apply (rename_tac \\<sigma>'' ret' \\<xi> n f g \\<sigma> \\<sigma>' \\<tau>a acc \\<tau>o obsv ret b)\n  apply (case_tac b; clarsimp)\n  apply (drule_tac x = b in meta_spec; clarsimp)\n  apply (elim meta_allE meta_impE, assumption, assumption)\n  apply (subst urepeat_bod.simps; clarsimp)\n  apply (rule_tac x = b in exI; clarsimp)\n  apply (intro exI conjI; assumption)\n  done\ndeclare urepeat_bod.simps[simp]\n\nsubsection \"Deterministic\"\n\nlemma urepeat_bod_deterministic:\n  \"\\<lbrakk>determ \\<xi>;\n    urepeat_bod \\<xi> n f g \\<sigma> \\<sigma>' \\<tau>a acc \\<tau>o obsv ret;\n    urepeat_bod \\<xi> n f g \\<sigma> \\<sigma>'' \\<tau>a acc \\<tau>o obsv ret'\\<rbrakk>\n    \\<Longrightarrow> \\<sigma>' = \\<sigma>'' \\<and> ret = ret'\"\n  apply (induct n arbitrary: \\<sigma> acc)\n   apply simp\n  apply clarsimp\n  apply (drule (2) u_sem_u_sem_all_determ(1)[rotated 1]; simp)\n  apply clarsimp\n  apply (rename_tac n \\<sigma> acc b)\n  apply (case_tac b; clarsimp)\n  apply (drule (2) u_sem_u_sem_all_determ(1)[rotated 1]; simp)\n  done\n\nlemma urepeat_deterministic:\n  \"\\<lbrakk>determ \\<xi>;\n    urepeat \\<Xi> \\<xi> \\<tau>a \\<tau>o x y;\n    urepeat \\<Xi> \\<xi> \\<tau>a \\<tau>o x z\\<rbrakk>\n    \\<Longrightarrow> y = z\"\n  unfolding urepeat_def\n  apply clarsimp\n  apply (drule (3) urepeat_bod_deterministic)\n  done\n\nlemma urepeat_bod_step_determ:\n  \"\\<lbrakk>\\<xi>', [URecord [(ret, type_repr (bang \\<tau>a)), (obsv, type_repr \\<tau>o)] None] \\<turnstile> (\\<sigma>', App f (Var 0)) \\<Down>! (\\<sigma>', UPrim (LBool False));\n    \\<xi>', [URecord [(ret, type_repr \\<tau>a), (obsv, type_repr \\<tau>o)] None] \\<turnstile> (\\<sigma>', App g (Var 0)) \\<Down>! (\\<sigma>'', ret');\n    urepeat_bod \\<xi>' n f g \\<sigma> \\<sigma>' \\<tau>a acc \\<tau>o obsv ret;\n    determ \\<xi>'\\<rbrakk> \n    \\<Longrightarrow> urepeat_bod \\<xi>' (Suc n) f g \\<sigma> \\<sigma>'' \\<tau>a acc \\<tau>o obsv ret'\"\n  apply (rule urepeat_bod_step; simp?)\n  apply clarsimp\n  apply (drule (2) u_sem_u_sem_all_determ(1)[rotated 1]; simp)\n  done\n\nsubsection \"Ordering\"\n\nlemma urepeat_bod_rel_leqD:\n  \"\\<lbrakk>rel_leq \\<xi>a \\<xi>b;\n    urepeat_bod \\<xi>a n f g \\<sigma> \\<sigma>' \\<tau>a acc \\<tau>o obsv ret\\<rbrakk>\n    \\<Longrightarrow> urepeat_bod \\<xi>b n f g \\<sigma> \\<sigma>' \\<tau>a acc \\<tau>o obsv ret\"\n  apply (induct n arbitrary: \\<sigma> acc)\n   apply simp\n  apply clarsimp\n  apply (rename_tac n \\<sigma> acc b)\n  apply (case_tac b; clarsimp)\n   apply (drule (1) u_sem_u_sem_all_rel_leqD)\n   apply (rule_tac x = b in exI; clarsimp)\n  apply (drule (1) u_sem_u_sem_all_rel_leqD[rotated 1])\n  apply (drule (1) u_sem_u_sem_all_rel_leqD[rotated 1])\n  apply (rule_tac x = b in exI; clarsimp)\n  apply (elim meta_allE meta_impE, assumption)\n  apply (intro exI conjI; assumption)\n  done\n\nlemma urepeat_rel_leqD:\n  \"\\<lbrakk>rel_leq \\<xi>a \\<xi>b;\n    urepeat \\<Xi> \\<xi>a \\<tau>a \\<tau>o x y\\<rbrakk>\n    \\<Longrightarrow> urepeat \\<Xi> \\<xi>b \\<tau>a \\<tau>o x y\"\n  unfolding urepeat_def\n  apply clarsimp\n  apply (drule (2) urepeat_bod_rel_leqD)\n  done\n\nend", "meta": {"author": "zilinc", "repo": "popl23-artefact", "sha": "1fe1490d2d34f93dc01ada940c160477db3b9b72", "save_path": "github-repos/isabelle/zilinc-popl23-artefact", "path": "github-repos/isabelle/zilinc-popl23-artefact/popl23-artefact-1fe1490d2d34f93dc01ada940c160477db3b9b72/arrays/loops/RepeatUpdate.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5851011542032313, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.28112862909587316}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      HoareTotal.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer\nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection \\<open>Derived Hoare Rules for Total Correctness\\<close>\n\ntheory HoareTotal imports HoareTotalProps begin\n\nlemma conseq_no_aux:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A';\n    \\<forall>s. s \\<in> P \\<longrightarrow> (s\\<in>P' \\<and> (Q' \\<subseteq> Q)\\<and> (A' \\<subseteq> A))\\<rbrakk>\n  \\<Longrightarrow>\n  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule conseq [where P'=\"\\<lambda>Z. P'\" and Q'=\"\\<lambda>Z. Q'\" and A'=\"\\<lambda>Z. A'\"]) auto\n\ntext \\<open>If for example a specification for a \"procedure pointer\" parameter\nis in the precondition we can extract it with this rule\\<close>\nlemma conseq_exploit_pre:\n             \"\\<lbrakk>\\<forall>s \\<in> P. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s} \\<inter> P) c Q,A\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule Conseq)\n  apply clarify\n  apply (rule_tac x=\"{s} \\<inter> P\" in exI)\n  apply (rule_tac x=\"Q\" in exI)\n  apply (rule_tac x=\"A\" in exI)\n  by simp\n\n\nlemma conseq:\"\\<lbrakk>\\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z);\n              \\<forall>s. s \\<in> P \\<longrightarrow> (\\<exists> Z. s\\<in>P' Z \\<and> (Q' Z \\<subseteq> Q)\\<and> (A' Z \\<subseteq> A))\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule Conseq') blast\n\n\nlemma Lem:\"\\<lbrakk>\\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z);\n            P \\<subseteq> {s. \\<exists> Z. s\\<in>P' Z \\<and> (Q' Z \\<subseteq> Q) \\<and> (A' Z \\<subseteq> A)}\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (lem x c) Q,A\"\n  apply (unfold lem_def)\n  apply (erule conseq)\n  apply blast\n  done\n\n\nlemma LemAnno:\nassumes conseq:  \"P \\<subseteq> {s. \\<exists>Z. s\\<in>P' Z \\<and>\n                     (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> t \\<in> Q) \\<and> (\\<forall>t. t \\<in> A' Z \\<longrightarrow> t \\<in> A)}\"\nassumes lem: \"\\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (lem x c) Q,A\"\n  apply (rule Lem [OF lem])\n  using conseq\n  by blast\n\nlemma LemAnnoNoAbrupt:\nassumes conseq:  \"P \\<subseteq>  {s. \\<exists>Z. s\\<in>P' Z \\<and> (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> t \\<in> Q)}\"\nassumes lem: \"\\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),{}\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (lem x c) Q,{}\"\n  apply (rule Lem [OF lem])\n  using conseq\n  by blast\n\nlemma TrivPost: \"\\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z)\n                 \\<Longrightarrow>\n                 \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c UNIV,UNIV\"\napply (rule allI)\napply (erule conseq)\napply auto\ndone\n\nlemma TrivPostNoAbr: \"\\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),{}\n                 \\<Longrightarrow>\n                 \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c UNIV,{}\"\napply (rule allI)\napply (erule conseq)\napply auto\ndone\n\nlemma DynComConseq:\n  assumes \"P \\<subseteq> {s. \\<exists>P' Q' A'.  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>P' (c s) Q',A' \\<and> P \\<subseteq> P' \\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>P DynCom c Q,A\"\n  using assms\n  apply -\n  apply (rule hoaret.DynCom)\n  apply clarsimp\n  apply (rule hoaret.Conseq)\n  apply clarsimp\n  apply blast\n  done\n\nlemma SpecAnno:\n assumes consequence: \"P \\<subseteq> {s. (\\<exists> Z. s\\<in>P' Z \\<and> (Q' Z \\<subseteq> Q) \\<and> (A' Z \\<subseteq> A))}\"\n assumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) (c Z) (Q' Z),(A' Z)\"\n assumes bdy_constant:  \"\\<forall>Z. c Z = c undefined\"\n shows   \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (specAnno P' c Q' A') Q,A\"\nproof -\n  from spec bdy_constant\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) (c undefined) (Q' Z),(A' Z)\"\n    apply -\n    apply (rule allI)\n    apply (erule_tac x=Z in allE)\n    apply (erule_tac x=Z in allE)\n    apply simp\n    done\n  with consequence show ?thesis\n    apply (simp add: specAnno_def)\n    apply (erule conseq)\n    apply blast\n    done\nqed\n\n\n\nlemma SpecAnno':\n \"\\<lbrakk>P \\<subseteq> {s.  \\<exists> Z. s\\<in>P' Z \\<and>\n            (\\<forall>t. t \\<in> Q' Z \\<longrightarrow>  t \\<in> Q) \\<and> (\\<forall>t. t \\<in> A' Z \\<longrightarrow> t \\<in>  A)};\n   \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) (c Z) (Q' Z),(A' Z);\n   \\<forall>Z. c Z = c undefined\n  \\<rbrakk> \\<Longrightarrow>\n    \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (specAnno P' c Q' A') Q,A\"\napply (simp only: subset_iff [THEN sym])\napply (erule (1) SpecAnno)\napply assumption\ndone\n\nlemma SpecAnnoNoAbrupt:\n \"\\<lbrakk>P \\<subseteq> {s.  \\<exists> Z. s\\<in>P' Z \\<and>\n            (\\<forall>t. t \\<in> Q' Z \\<longrightarrow>  t \\<in> Q)};\n   \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) (c Z) (Q' Z),{};\n   \\<forall>Z. c Z = c undefined\n  \\<rbrakk> \\<Longrightarrow>\n    \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (specAnno P' c Q' (\\<lambda>s. {})) Q,A\"\napply (rule SpecAnno')\napply auto\ndone\n\nlemma Skip: \"P \\<subseteq> Q \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Skip Q,A\"\n  by (rule hoaret.Skip [THEN conseqPre],simp)\n\nlemma Basic: \"P \\<subseteq> {s. (f s) \\<in> Q} \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Basic f) Q,A\"\n  by (rule hoaret.Basic [THEN conseqPre])\n\nlemma BasicCond:\n  \"\\<lbrakk>P \\<subseteq> {s. (b s \\<longrightarrow> f s\\<in>Q) \\<and> (\\<not> b s \\<longrightarrow> g s\\<in>Q)}\\<rbrakk> \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Basic (\\<lambda>s. if b s then f s else g s) Q,A\"\n  apply (rule Basic)\n  apply auto\n  done\n\nlemma Spec: \"P \\<subseteq> {s. (\\<forall>t. (s,t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s,t) \\<in> r)}\n            \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Spec r) Q,A\"\nby (rule hoaret.Spec [THEN conseqPre])\n\nlemma SpecIf:\n  \"\\<lbrakk>P \\<subseteq> {s. (b s \\<longrightarrow> f s \\<in> Q) \\<and> (\\<not> b s \\<longrightarrow> g s \\<in> Q \\<and> h s \\<in> Q)}\\<rbrakk> \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Spec (if_rel b f g h) Q,A\"\n  apply (rule Spec)\n  apply (auto simp add: if_rel_def)\n  done\n\nlemma Seq [trans, intro?]:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 R,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Seq c\\<^sub>1 c\\<^sub>2 Q,A\"\n  by (rule hoaret.Seq)\n\nlemma SeqSwap:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c2 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c1 R,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Seq c1 c2 Q,A\"\n  by (rule Seq)\n\nlemma BSeq:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 R,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (bseq c\\<^sub>1 c\\<^sub>2) Q,A\"\n  by (unfold bseq_def) (rule Seq)\n\nlemma Cond:\n  assumes wp: \"P \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\"\n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P\\<^sub>1 c\\<^sub>1 Q,A\"\n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P\\<^sub>2 c\\<^sub>2 Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) Q,A\"\nproof (rule hoaret.Cond [THEN conseqPre])\n  from deriv_c1\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. (s \\<in> b \\<longrightarrow> s \\<in> P\\<^sub>1) \\<and> (s \\<notin> b \\<longrightarrow> s \\<in> P\\<^sub>2)} \\<inter> b) c\\<^sub>1 Q,A\"\n    by (rule conseqPre) blast\nnext\n  from deriv_c2\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. (s \\<in> b \\<longrightarrow> s \\<in> P\\<^sub>1) \\<and> (s \\<notin> b \\<longrightarrow> s \\<in> P\\<^sub>2)} \\<inter> - b) c\\<^sub>2 Q,A\"\n    by (rule conseqPre) blast\nqed (insert wp)\n\n\nlemma CondSwap:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P1 c1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P2 c2 Q,A;\n    P \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P2)}\\<rbrakk>\n   \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Cond b c1 c2) Q,A\"\n  by (rule Cond)\n\nlemma Cond':\n  \"\\<lbrakk>P \\<subseteq> {s. (b \\<subseteq> P1) \\<and> (- b \\<subseteq> P2)};\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P1 c1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P2 c2 Q,A\\<rbrakk>\n   \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Cond b c1 c2) Q,A\"\n  by (rule CondSwap) blast+\n\nlemma CondInv:\n  assumes wp: \"P \\<subseteq> Q\"\n  assumes inv: \"Q \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\"\n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P\\<^sub>1 c\\<^sub>1 Q,A\"\n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P\\<^sub>2 c\\<^sub>2 Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) Q,A\"\nproof -\n  from wp inv\n  have \"P \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\"\n    by blast\n  from Cond [OF this deriv_c1 deriv_c2]\n  show ?thesis .\nqed\n\nlemma CondInv':\n  assumes wp: \"P \\<subseteq> I\"\n  assumes inv: \"I \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\"\n  assumes wp': \"I \\<subseteq> Q\"\n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P\\<^sub>1 c\\<^sub>1 I,A\"\n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P\\<^sub>2 c\\<^sub>2 I,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) Q,A\"\nproof -\n  from CondInv [OF wp inv deriv_c1 deriv_c2]\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) I,A\" .\n  from conseqPost [OF this wp' subset_refl]\n  show ?thesis .\nqed\n\n\nlemma switchNil:\n  \"P \\<subseteq> Q \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>P (switch v []) Q,A\"\n  by (simp add: Skip)\n\nlemma switchCons:\n  \"\\<lbrakk>P \\<subseteq> {s. (v s \\<in> V \\<longrightarrow> s \\<in> P\\<^sub>1) \\<and> (v s \\<notin> V \\<longrightarrow> s \\<in> P\\<^sub>2)};\n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>P\\<^sub>1 c Q,A;\n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>P\\<^sub>2 (switch v vs) Q,A\\<rbrakk>\n\\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>P (switch v ((V,c)#vs)) Q,A\"\n  by (simp add: Cond)\n\n\nlemma Guard:\n \"\\<lbrakk>P \\<subseteq> g \\<inter> R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c Q,A\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Guard f g c Q,A\"\napply (rule HoareTotalDef.Guard [THEN conseqPre, of _ _ _ _ R])\napply (erule conseqPre)\napply auto\ndone\n\nlemma GuardSwap:\n \"\\<lbrakk> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> g \\<inter> R\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Guard f g c Q,A\"\n  by (rule Guard)\n\nlemma Guarantee:\n \"\\<lbrakk>P \\<subseteq> {s. s \\<in> g \\<longrightarrow> s \\<in> R}; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c Q,A; f \\<in> F\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\napply (rule Guarantee [THEN conseqPre, of _ _ _ _ _ \"{s. s \\<in> g \\<longrightarrow> s \\<in> R}\"])\napply   assumption\napply  (erule conseqPre)\napply auto\ndone\n\nlemma GuaranteeSwap:\n \"\\<lbrakk> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> {s. s \\<in> g \\<longrightarrow> s \\<in> R}; f \\<in> F\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\n  by (rule Guarantee)\n\n\nlemma GuardStrip:\n \"\\<lbrakk>P \\<subseteq> R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c Q,A; f \\<in> F\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\napply (rule Guarantee [THEN conseqPre])\napply auto\ndone\n\nlemma GuardStripSwap:\n \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> R; f \\<in> F\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\n  by (rule GuardStrip)\n\nlemma GuaranteeStrip:\n \"\\<lbrakk>P \\<subseteq> R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c Q,A; f \\<in> F\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (guaranteeStrip f g c) Q,A\"\n  by (unfold guaranteeStrip_def) (rule GuardStrip)\n\nlemma GuaranteeStripSwap:\n \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> R; f \\<in> F\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (guaranteeStrip f g c) Q,A\"\n  by (unfold guaranteeStrip_def) (rule GuardStrip)\n\nlemma GuaranteeAsGuard:\n \"\\<lbrakk>P \\<subseteq> g \\<inter> R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c Q,A\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P guaranteeStrip f g c Q,A\"\n  by (unfold guaranteeStrip_def) (rule Guard)\n\nlemma GuaranteeAsGuardSwap:\n \"\\<lbrakk> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> g \\<inter> R\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P guaranteeStrip f g c Q,A\"\n  by (rule GuaranteeAsGuard)\n\nlemma GuardsNil:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (guards [] c) Q,A\"\n  by simp\n\n\n\nlemma GuardsConsGuaranteeStrip:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P guaranteeStrip f g (guards gs c) Q,A \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (guards (guaranteeStripPair f g#gs) c) Q,A\"\n  by (simp add: guaranteeStripPair_def guaranteeStrip_def)\n\nlemma While:\n  assumes P_I: \"P \\<subseteq> I\"\n  assumes deriv_body:\n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> I \\<inter> b) c ({t. (t, \\<sigma>) \\<in> V} \\<inter> I),A\"\n  assumes I_Q: \"I \\<inter> -b \\<subseteq> Q\"\n  assumes wf: \"wf V\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (whileAnno  b I V c) Q,A\"\nproof -\n  from wf deriv_body P_I I_Q\n  show ?thesis\n    apply (unfold whileAnno_def)\n    apply (erule conseqPrePost [OF HoareTotalDef.While])\n    apply auto\n    done\nqed\n\n\n\nlemma WhileInvPost:\n  assumes P_I: \"P \\<subseteq> I\"\n  assumes termi_body:\n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/UNIV\\<^esub> ({\\<sigma>} \\<inter> I \\<inter> b) c ({t. (t, \\<sigma>) \\<in> V} \\<inter> P),A\"\n  assumes deriv_body:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (I \\<inter> b) c I,A\"\n  assumes I_Q: \"I \\<inter> -b \\<subseteq> Q\"\n  assumes wf: \"wf V\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (whileAnno  b I V c) Q,A\"\nproof -\n  have \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> I \\<inter> b) c ({t. (t, \\<sigma>) \\<in> V} \\<inter> I),A\"\n  proof\n    fix \\<sigma>\n    from hoare_sound [OF deriv_body] hoaret_sound [OF termi_body [rule_format, of \\<sigma>]]\n    have \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> I \\<inter> b) c ({t. (t, \\<sigma>) \\<in> V} \\<inter> I),A\"\n      by (fastforce simp add: cvalidt_def validt_def cvalid_def valid_def)\n    then\n    show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> I \\<inter> b) c ({t. (t, \\<sigma>) \\<in> V} \\<inter> I),A\"\n      by (rule hoaret_complete')\n  qed\n\n  from While [OF P_I this I_Q wf]\n  show ?thesis .\nqed\n\n(* *)\nlemma \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> b) c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> b) (Seq c (Guard f Q Skip)) Q,A\"\noops\n\ntext \\<open>@{term \"J\"} will be instantiated by tactic with @{term \"gs' \\<inter> I\"} for\n  those guards that are not stripped.\\<close>\nlemma WhileAnnoG:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (guards gs\n                    (whileAnno  b J V (Seq c (guards gs Skip)))) Q,A\n        \\<Longrightarrow>\n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (whileAnnoG gs b I V c) Q,A\"\n  by (simp add: whileAnnoG_def whileAnno_def while_def)\n\ntext \\<open>This form stems from @{term \"strip_guards F (whileAnnoG gs b I V c)\"}\\<close>\n\n\n\n\nlemma WhileAnnoFix':\nassumes consequence: \"P \\<subseteq> {s. (\\<exists> Z. s\\<in>I Z \\<and>\n                               (\\<forall>t. t \\<in> I Z \\<inter> -b \\<longrightarrow> t \\<in> Q)) }\"\nassumes bdy: \"\\<forall>Z \\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> I Z \\<inter> b) (c Z) ({t. (t, \\<sigma>) \\<in> V Z} \\<inter> I Z),A\"\nassumes bdy_constant:  \"\\<forall>Z. c Z = c undefined\"\nassumes wf: \"\\<forall>Z. wf (V Z)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (whileAnnoFix b I V c) Q,A\"\n  apply (rule WhileAnnoFix [OF _ bdy bdy_constant wf])\n  using consequence by blast\n\nlemma WhileAnnoGFix:\nassumes whileAnnoFix:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (guards gs\n                (whileAnnoFix  b J V (\\<lambda>Z. (Seq (c Z) (guards gs Skip))))) Q,A\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (whileAnnoGFix gs b I V c) Q,A\"\n  using whileAnnoFix\n  by (simp add: whileAnnoGFix_def whileAnnoFix_def while_def)\n\nlemma Bind:\n  assumes adapt: \"P \\<subseteq> {s. s \\<in> P' s}\"\n  assumes c: \"\\<forall>s. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' s) (c (e s)) Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (bind e c) Q,A\"\napply (rule conseq [where P'=\"\\<lambda>Z. {s. s=Z \\<and> s \\<in> P' Z}\" and Q'=\"\\<lambda>Z. Q\" and\nA'=\"\\<lambda>Z. A\"])\napply  (rule allI)\napply  (unfold bind_def)\napply  (rule HoareTotalDef.DynCom)\napply  (rule ballI)\napply  clarsimp\napply  (rule conseqPre)\napply   (rule c [rule_format])\napply  blast\nusing adapt\napply blast\ndone\n\nlemma Block:\nassumes adapt: \"P \\<subseteq> {s. init s \\<in> P' s}\"\nassumes bdy: \"\\<forall>s. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' s) bdy {t. return s t \\<in> R s t},{t. return s t \\<in> A}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (block init bdy return c) Q,A\"\napply (rule conseq [where P'=\"\\<lambda>Z. {s. s=Z \\<and> init s \\<in> P' Z}\" and Q'=\"\\<lambda>Z. Q\" and\nA'=\"\\<lambda>Z. A\"])\nprefer 2\nusing adapt\napply  blast\napply (rule allI)\napply (unfold block_def)\napply (rule HoareTotalDef.DynCom)\napply (rule ballI)\napply clarsimp\napply (rule_tac R=\"{t. return Z t \\<in> R Z t}\" in SeqSwap )\napply  (rule_tac  P'=\"\\<lambda>Z'. {t. t=Z' \\<and> return Z t \\<in> R Z t}\" and\n          Q'=\"\\<lambda>Z'. Q\" and A'=\"\\<lambda>Z'. A\" in conseq)\nprefer 2 apply simp\napply  (rule allI)\napply  (rule HoareTotalDef.DynCom)\napply  (clarsimp)\napply  (rule SeqSwap)\napply   (rule c [rule_format])\napply  (rule Basic)\napply  clarsimp\napply (rule_tac R=\"{t. return Z t \\<in> A}\" in HoareTotalDef.Catch)\napply  (rule_tac R=\"{i. i \\<in> P' Z}\" in Seq)\napply   (rule Basic)\napply   clarsimp\napply  simp\napply  (rule bdy [rule_format])\napply (rule SeqSwap)\napply  (rule Throw)\napply (rule Basic)\napply simp\ndone\n\nlemma BlockSwap:\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes bdy: \"\\<forall>s. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' s) bdy {t. return s t \\<in> R s t},{t. return s t \\<in> A}\"\nassumes adapt: \"P \\<subseteq> {s. init s \\<in> P' s}\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (block init bdy return c) Q,A\"\n  using adapt bdy c\n  by (rule Block)\n\nlemma BlockSpec:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' Z \\<and>\n                             (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t) \\<and>\n                             (\\<forall>t. t \\<in> A' Z \\<longrightarrow> return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes bdy: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) bdy (Q' Z),(A' Z)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (block init bdy return c) Q,A\"\napply (rule conseq [where P'=\"\\<lambda>Z. {s. init s \\<in> P' Z \\<and>\n                             (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t) \\<and>\n                             (\\<forall>t. t \\<in> A' Z \\<longrightarrow> return s t \\<in> A)}\" and Q'=\"\\<lambda>Z. Q\" and\nA'=\"\\<lambda>Z. A\"])\nprefer 2\nusing adapt\napply  blast\napply (rule allI)\napply (unfold block_def)\napply (rule HoareTotalDef.DynCom)\napply (rule ballI)\napply clarsimp\napply (rule_tac R=\"{t. return s t \\<in> R s t}\" in SeqSwap )\napply  (rule_tac  P'=\"\\<lambda>Z'. {t. t=Z' \\<and> return s t \\<in> R s t}\" and\n          Q'=\"\\<lambda>Z'. Q\" and A'=\"\\<lambda>Z'. A\" in conseq)\nprefer 2 apply simp\napply  (rule allI)\napply  (rule HoareTotalDef.DynCom)\napply  (clarsimp)\napply  (rule SeqSwap)\napply   (rule c [rule_format])\napply  (rule Basic)\napply  clarsimp\napply (rule_tac R=\"{t. return s t \\<in> A}\" in HoareTotalDef.Catch)\napply  (rule_tac R=\"{i. i \\<in> P' Z}\" in Seq)\napply   (rule Basic)\napply   clarsimp\napply  simp\napply  (rule conseq [OF bdy])\napply  clarsimp\napply  blast\napply (rule SeqSwap)\napply  (rule Throw)\napply (rule Basic)\napply simp\ndone\n\n\nlemma Throw: \"P \\<subseteq> A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Throw Q,A\"\n  by (rule hoaret.Throw [THEN conseqPre])\n\nlemmas Catch = hoaret.Catch\nlemma CatchSwap: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,R\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Catch c\\<^sub>1 c\\<^sub>2 Q,A\"\n  by (rule hoaret.Catch)\n\nlemma raise: \"P \\<subseteq> {s. f s \\<in> A} \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P raise f Q,A\"\n  apply (simp add: raise_def)\n  apply (rule Seq)\n  apply  (rule Basic)\n  apply  (assumption)\n  apply (rule Throw)\n  apply (rule subset_refl)\n  done\n\nlemma condCatch: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,((b \\<inter> R) \\<union> (-b \\<inter> A));\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk>\n                  \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P condCatch c\\<^sub>1 b c\\<^sub>2 Q,A\"\n  apply (simp add: condCatch_def)\n  apply (rule Catch)\n  apply  assumption\n  apply (rule CondSwap)\n  apply   (assumption)\n  apply  (rule hoaret.Throw)\n  apply blast\n  done\n\nlemma condCatchSwap: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,((b \\<inter> R) \\<union> (-b \\<inter> A))\\<rbrakk>\n                     \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P condCatch c\\<^sub>1 b c\\<^sub>2 Q,A\"\n  by (rule condCatch)\n\n\nlemma ProcSpec:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' Z \\<and>\n                             (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t) \\<and>\n                             (\\<forall>t. t \\<in> A' Z \\<longrightarrow> return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) Call p (Q' Z),(A' Z)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nusing adapt c p\napply (unfold call_def)\nby (rule BlockSpec)\n\nlemma ProcSpec':\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' Z \\<and>\n                             (\\<forall>t \\<in> Q' Z. return s t \\<in> R s t) \\<and>\n                             (\\<forall>t \\<in> A' Z. return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) Call p (Q' Z),(A' Z)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule ProcSpec [OF _ c p])\napply (insert adapt)\napply clarsimp\napply (drule (1) subsetD)\napply (clarsimp)\napply (rule_tac x=Z in exI)\napply blast\ndone\n\n\nlemma ProcSpecNoAbrupt:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' Z \\<and>\n                             (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) Call p (Q' Z),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule ProcSpec [OF _ c p])\nusing adapt\napply simp\ndone\n\nlemma FCall:\n\"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return (\\<lambda>s t. c (result t))) Q,A\n\\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (fcall init p return result c) Q,A\"\n  by (simp add: fcall_def)\n\nlemma ProcRec:\n  assumes deriv_bodies:\n   \"\\<forall>p\\<in>Procs.\n    \\<forall>\\<sigma> Z. \\<Gamma>,\\<Theta>\\<union>(\\<Union>q\\<in>Procs. \\<Union>Z.\n       {(P q Z \\<inter> {s. ((s,q), \\<sigma>,p) \\<in> r},q,Q q Z,A q Z)})\n        \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n  assumes wf: \"wf r\"\n  assumes Procs_defined: \"Procs \\<subseteq> dom \\<Gamma>\"\n  shows \"\\<forall>p\\<in>Procs. \\<forall>Z.\n  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>(P p Z) Call p (Q p Z),(A p Z)\"\n  by (intro strip)\n     (rule HoareTotalDef.CallRec'\n     [OF _  Procs_defined wf deriv_bodies],\n     simp_all)\n\nlemma ProcRec':\n  assumes ctxt:\n   \"\\<Theta>'=(\\<lambda>\\<sigma> p. \\<Theta>\\<union>(\\<Union>q\\<in>Procs.\n                   \\<Union>Z. {(P q Z \\<inter> {s. ((s,q), \\<sigma>,p) \\<in> r},q,Q q Z,A q Z)}))\"\n  assumes deriv_bodies:\n   \"\\<forall>p\\<in>Procs.\n    \\<forall>\\<sigma> Z. \\<Gamma>,\\<Theta>' \\<sigma> p\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n  assumes wf: \"wf r\"\n  assumes Procs_defined: \"Procs \\<subseteq> dom \\<Gamma>\"\n  shows \"\\<forall>p\\<in>Procs. \\<forall>Z.  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>(P p Z) Call p (Q p Z),(A p Z)\"\n  using ctxt deriv_bodies\n  apply simp\n  apply (erule ProcRec [OF _ wf Procs_defined])\n  done\n\n\nlemma ProcRecList:\n  assumes deriv_bodies:\n   \"\\<forall>p\\<in>set Procs.\n    \\<forall>\\<sigma> Z. \\<Gamma>,\\<Theta>\\<union>(\\<Union>q\\<in>set Procs. \\<Union>Z.\n       {(P q Z \\<inter> {s. ((s,q), \\<sigma>,p) \\<in> r},q,Q q Z,A q Z)})\n        \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n  assumes wf: \"wf r\"\n  assumes dist: \"distinct Procs\"\n  assumes Procs_defined: \"set Procs \\<subseteq> dom \\<Gamma>\"\n  shows \"\\<forall>p\\<in>set Procs. \\<forall>Z.\n  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>(P p Z) Call p (Q p Z),(A p Z)\"\n  using deriv_bodies wf Procs_defined\n  by (rule ProcRec)\n\nlemma  ProcRecSpecs:\n  \"\\<lbrakk>\\<forall>\\<sigma>. \\<forall>(P,p,Q,A) \\<in> Specs.\n     \\<Gamma>,\\<Theta>\\<union> ((\\<lambda>(P,q,Q,A). (P \\<inter> {s. ((s,q),(\\<sigma>,p)) \\<in> r},q,Q,A)) ` Specs)\n      \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P) (the (\\<Gamma> p)) Q,A;\n    wf r;\n    \\<forall>(P,p,Q,A) \\<in> Specs. p \\<in> dom \\<Gamma>\\<rbrakk>\n  \\<Longrightarrow> \\<forall>(P,p,Q,A) \\<in> Specs. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\napply (rule ballI)\napply (case_tac x)\napply (rename_tac x P p Q A)\napply simp\napply (rule hoaret.CallRec)\napply auto\ndone\n\nlemma ProcRec1:\n  assumes deriv_body:\n   \"\\<forall>\\<sigma> Z. \\<Gamma>,\\<Theta>\\<union>(\\<Union>Z. {(P Z \\<inter> {s. ((s,p), \\<sigma>,p) \\<in> r},p,Q Z,A Z)})\n           \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P Z) (the (\\<Gamma> p)) (Q Z),(A Z)\"\n  assumes wf: \"wf r\"\n  assumes p_defined: \"p \\<in> dom \\<Gamma>\"\n  shows \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P Z) Call p (Q Z),(A Z)\"\nproof -\n  from deriv_body wf p_defined\n  have \"\\<forall>p\\<in>{p}. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P Z) Call p (Q Z),(A Z)\"\n    apply -\n    apply (rule ProcRec [where  A=\"\\<lambda>p. A\" and P=\"\\<lambda>p. P\" and Q=\"\\<lambda>p. Q\"])\n    apply simp_all\n    done\n  thus ?thesis\n    by simp\nqed\n\nlemma ProcNoRec1:\n  assumes deriv_body:\n   \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P Z) (the (\\<Gamma> p)) (Q Z),(A Z)\"\n  assumes p_defined: \"p \\<in> dom \\<Gamma>\"\n  shows \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P Z) Call p (Q Z),(A Z)\"\nproof -\n  have \"\\<forall>\\<sigma> Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P Z) (the (\\<Gamma> p)) (Q Z),(A Z)\"\n    by (blast intro: conseqPre deriv_body [rule_format])\n  with p_defined have \"\\<forall>\\<sigma> Z. \\<Gamma>,\\<Theta>\\<union>(\\<Union>Z. {(P Z \\<inter> {s. ((s,p), \\<sigma>,p) \\<in> {}},\n                         p,Q Z,A Z)})\n             \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P Z) (the (\\<Gamma> p)) (Q Z),(A Z)\"\n    by (blast intro: hoaret_augment_context)\n  from this\n  show ?thesis\n    by (rule ProcRec1) (auto simp add: p_defined)\nqed\n\nlemma ProcBody:\n assumes WP: \"P \\<subseteq> P'\"\n assumes deriv_body: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' body Q,A\"\n assumes body: \"\\<Gamma> p = Some body\"\n shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Call p Q,A\"\napply (rule conseqPre [OF _ WP])\napply (rule ProcNoRec1 [rule_format, where P=\"\\<lambda>Z. P'\" and Q=\"\\<lambda>Z. Q\" and A=\"\\<lambda>Z. A\"])\napply  (insert body)\napply  simp\napply  (rule hoaret_augment_context [OF deriv_body])\napply  blast\napply fastforce\ndone\n\nlemma CallBody:\nassumes adapt: \"P \\<subseteq> {s. init s \\<in> P' s}\"\nassumes bdy: \"\\<forall>s. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' s) body {t. return s t \\<in> R s t},{t. return s t \\<in> A}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes body: \"\\<Gamma> p = Some body\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (unfold call_def)\napply (rule Block [OF adapt _ c])\napply (rule allI)\napply (rule ProcBody [where \\<Gamma>=\\<Gamma>, OF _ bdy [rule_format] body])\napply simp\ndone\n\nlemmas ProcModifyReturn = HoareTotalProps.ProcModifyReturn\nlemmas ProcModifyReturnSameFaults = HoareTotalProps.ProcModifyReturnSameFaults\n\nlemma ProcModifyReturnNoAbr:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes result_conform:\n      \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:\n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} Call p (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nby (rule ProcModifyReturn [OF spec result_conform _ modifies_spec]) simp\n\n\nlemma ProcModifyReturnNoAbrSameFaults:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes result_conform:\n      \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:\n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call p (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nby (rule ProcModifyReturnSameFaults [OF spec result_conform _ modifies_spec]) simp\n\n\nlemma DynProc:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' s Z \\<and>\n                          (\\<forall>t. t \\<in> Q' s Z \\<longrightarrow>  return s t \\<in> R s t) \\<and>\n                          (\\<forall>t. t \\<in> A' s Z \\<longrightarrow> return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>s\\<in> P. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' s Z) Call (p s) (Q' s Z),(A' s Z)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return c Q,A\"\napply (rule conseq [where P'=\"\\<lambda>Z. {s. s=Z \\<and> s \\<in> P}\"\n  and Q'=\"\\<lambda>Z. Q\" and A'=\"\\<lambda>Z. A\"])\nprefer 2\nusing adapt\napply  blast\napply (rule allI)\napply (unfold dynCall_def call_def block_def)\napply (rule HoareTotalDef.DynCom)\napply clarsimp\napply (rule HoareTotalDef.DynCom)\napply clarsimp\napply (frule in_mono [rule_format, OF adapt])\napply clarsimp\napply (rename_tac Z')\napply (rule_tac R=\"Q' Z Z'\" in Seq)\napply  (rule CatchSwap)\napply   (rule SeqSwap)\napply    (rule Throw)\napply    (rule subset_refl)\napply   (rule Basic)\napply   (rule subset_refl)\napply  (rule_tac R=\"{i. i \\<in> P' Z Z'}\" in Seq)\napply   (rule Basic)\napply   clarsimp\napply  simp\napply  (rule_tac Q'=\"Q' Z Z'\" and A'=\"A' Z Z'\" in conseqPost)\nusing p\napply    clarsimp\napply   simp\napply  clarsimp\napply  (rule_tac  P'=\"\\<lambda>Z''. {t. t=Z'' \\<and> return Z t \\<in> R Z t}\" and\n          Q'=\"\\<lambda>Z''. Q\" and A'=\"\\<lambda>Z''. A\" in conseq)\nprefer 2 apply simp\napply (rule allI)\napply (rule HoareTotalDef.DynCom)\napply clarsimp\napply (rule SeqSwap)\napply  (rule c [rule_format])\napply (rule Basic)\napply clarsimp\ndone\n\nlemma DynProc':\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' s Z \\<and>\n                          (\\<forall>t \\<in> Q' s Z. return s t \\<in> R s t) \\<and>\n                          (\\<forall>t \\<in> A' s Z. return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>s\\<in> P. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' s Z) Call (p s) (Q' s Z),(A' s Z)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return c Q,A\"\nproof -\n  from adapt have \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' s Z \\<and>\n                          (\\<forall>t. t \\<in> Q' s Z \\<longrightarrow>  return s t \\<in> R s t) \\<and>\n                          (\\<forall>t. t \\<in> A' s Z \\<longrightarrow> return s t \\<in> A)}\"\n    by blast\n  from this c p show ?thesis\n    by (rule DynProc)\nqed\n\nlemma DynProcStaticSpec:\nassumes adapt: \"P \\<subseteq> {s. s \\<in> S \\<and> (\\<exists>Z. init s \\<in> P' Z  \\<and>\n                            (\\<forall>\\<tau>. \\<tau> \\<in> Q' Z \\<longrightarrow> return s \\<tau> \\<in> R s \\<tau>) \\<and>\n                            (\\<forall>\\<tau>. \\<tau> \\<in> A' Z \\<longrightarrow> return s \\<tau> \\<in> A))}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes spec: \"\\<forall>s\\<in>S. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) Call (p s) (Q' Z),(A' Z)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from adapt have P_S: \"P \\<subseteq> S\"\n    by blast\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> S) (dynCall init p return c) Q,A\"\n    apply (rule DynProc [where P'=\"\\<lambda>s Z. P' Z\" and Q'=\"\\<lambda>s Z. Q' Z\"\n                         and A'=\"\\<lambda>s Z. A' Z\", OF _ c])\n    apply  clarsimp\n    apply  (frule in_mono [rule_format, OF adapt])\n    apply  clarsimp\n    using spec\n    apply clarsimp\n    done\n  thus ?thesis\n    by (rule conseqPre) (insert P_S,blast)\nqed\n\n\n\nlemma DynProcProcPar:\nassumes adapt: \"P \\<subseteq> {s. p s = q \\<and> (\\<exists>Z. init s \\<in> P' Z  \\<and>\n                            (\\<forall>\\<tau>. \\<tau> \\<in> Q' Z \\<longrightarrow> return s \\<tau> \\<in> R s \\<tau>) \\<and>\n                            (\\<forall>\\<tau>. \\<tau> \\<in> A' Z \\<longrightarrow> return s \\<tau> \\<in> A))}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) Call q (Q' Z),(A' Z)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\n  apply (rule DynProcStaticSpec [where S=\"{s. p s = q}\",simplified, OF adapt c])\n  using spec\n  apply simp\n  done\n\n\nlemma DynProcProcParNoAbrupt:\nassumes adapt: \"P \\<subseteq> {s. p s = q \\<and> (\\<exists>Z. init s \\<in> P' Z  \\<and>\n                            (\\<forall>\\<tau>. \\<tau> \\<in> Q' Z \\<longrightarrow> return s \\<tau> \\<in> R s \\<tau>))}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) Call q (Q' Z),{}\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  have \"P \\<subseteq> {s. p s = q \\<and> (\\<exists> Z. init s \\<in> P' Z \\<and>\n                      (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t) \\<and>\n                      (\\<forall>t. t \\<in> {} \\<longrightarrow> return s t \\<in> A))}\"\n    (is \"P \\<subseteq> ?P'\")\n  proof\n    fix s\n    assume P: \"s\\<in>P\"\n    with adapt obtain Z where\n      Pre: \"p s = q \\<and> init s \\<in> P' Z\" and\n      adapt_Norm: \"\\<forall>\\<tau>. \\<tau> \\<in> Q' Z \\<longrightarrow> return s \\<tau> \\<in> R s \\<tau>\"\n      by blast\n    from  adapt_Norm\n    have \"\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t\"\n      by auto\n    then\n    show \"s\\<in>?P'\"\n      using Pre by blast\n  qed\n  note P = this\n  show ?thesis\n    apply -\n    apply (rule DynProcStaticSpec [where S=\"{s. p s = q}\",simplified, OF P c])\n    apply (insert spec)\n    apply auto\n    done\nqed\n\nlemma DynProcModifyReturnNoAbr:\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s))\n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause:\n            \"\\<forall>s \\<in> P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} Call (p s)  (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from ret_nrm_modif\n  have \"\\<forall>s t. t  \\<in> (Modif (init s))\n        \\<longrightarrow> return' s t = return s t\"\n    by iprover\n  then\n  have ret_nrm_modif': \"\\<forall>s t. t \\<in> (Modif (init s))\n                      \\<longrightarrow> return' s t = return s t\"\n    by simp\n  have ret_abr_modif': \"\\<forall>s t. t \\<in> {}\n                        \\<longrightarrow> return' s t = return s t\"\n    by simp\n  from to_prove ret_nrm_modif' ret_abr_modif' modif_clause show ?thesis\n    by (rule dynProcModifyReturn)\nqed\n\nlemma ProcDynModifyReturnNoAbrSameFaults:\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s))\n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause:\n            \"\\<forall>s \\<in> P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} (Call (p s)) (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from ret_nrm_modif\n  have \"\\<forall>s t. t  \\<in> (Modif (init s))\n        \\<longrightarrow> return' s t = return s t\"\n    by iprover\n  then\n  have ret_nrm_modif': \"\\<forall>s t. t \\<in> (Modif (init s))\n                      \\<longrightarrow> return' s t = return s t\"\n    by simp\n  have ret_abr_modif': \"\\<forall>s t. t \\<in> {}\n                        \\<longrightarrow> return' s t = return s t\"\n    by simp\n  from to_prove ret_nrm_modif' ret_abr_modif' modif_clause show ?thesis\n    by (rule dynProcModifyReturnSameFaults)\nqed\n\nlemma ProcProcParModifyReturn:\n  assumes q: \"P \\<subseteq> {s. p s = q} \\<inter> P'\"\n   \\<comment> \\<open>@{thm[source] DynProcProcPar} introduces the same constraint as first conjunction in\n         @{term P'}, so the vcg can simplify it.\\<close>\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s))\n                            \\<longrightarrow> return' s t = return s t\"\n  assumes ret_abr_modif: \"\\<forall>s t. t \\<in> (ModifAbr (init s))\n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause:\n          \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call q) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from to_prove have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return' c) Q,A\"\n    by (rule conseqPre) blast\n  from this ret_nrm_modif\n       ret_abr_modif\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return c) Q,A\"\n    by (rule dynProcModifyReturn) (insert modif_clause,auto)\n  from this q show ?thesis\n    by (rule conseqPre)\nqed\n\n\n\nlemma ProcProcParModifyReturnSameFaults:\n  assumes q: \"P \\<subseteq> {s. p s = q} \\<inter> P'\"\n   \\<comment> \\<open>@{thm[source] DynProcProcPar} introduces the same constraint as first conjunction in\n         @{term P'}, so the vcg can simplify it.\\<close>\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s))\n                            \\<longrightarrow> return' s t = return s t\"\n  assumes ret_abr_modif: \"\\<forall>s t. t \\<in> (ModifAbr (init s))\n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause:\n          \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call q (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from to_prove\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return' c) Q,A\"\n    by (rule conseqPre) blast\n  from this ret_nrm_modif\n       ret_abr_modif\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return c) Q,A\"\n    by (rule dynProcModifyReturnSameFaults) (insert modif_clause,auto)\n  from this q show ?thesis\n    by (rule conseqPre)\nqed\n\nlemma ProcProcParModifyReturnNoAbr:\n  assumes q: \"P \\<subseteq> {s. p s = q} \\<inter> P'\"\n   \\<comment> \\<open>@{thm[source] DynProcProcParNoAbrupt} introduces the same constraint as\n      first conjunction in @{term P'}, so the vcg can simplify it.\\<close>\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s))\n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause:\n            \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call q) (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from to_prove have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return' c) Q,A\"\n    by (rule conseqPre) blast\n  from this ret_nrm_modif\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return c) Q,A\"\n    by (rule DynProcModifyReturnNoAbr) (insert modif_clause,auto)\n  from this q show ?thesis\n    by (rule conseqPre)\nqed\n\n\nlemma ProcProcParModifyReturnNoAbrSameFaults:\n  assumes q: \"P \\<subseteq> {s. p s = q} \\<inter> P'\"\n      \\<comment> \\<open>@{thm[source] DynProcProcParNoAbrupt} introduces the same constraint as\n      first conjunction in @{term P'}, so the vcg can simplify it.\\<close>\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s))\n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause:\n            \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} (Call q) (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from to_prove have\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return' c) Q,A\"\n    by (rule conseqPre) blast\n  from this ret_nrm_modif\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return c) Q,A\"\n    by (rule ProcDynModifyReturnNoAbrSameFaults) (insert modif_clause,auto)\n  from this q show ?thesis\n    by (rule conseqPre)\nqed\n\nlemma MergeGuards_iff: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P merge_guards c Q,A = \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (auto intro: MergeGuardsI MergeGuardsD)\n\nlemma CombineStrip':\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c' Q,A\"\n  assumes deriv_strip_triv: \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/{}\\<^esub> P c'' UNIV,UNIV\"\n  assumes c'': \"c''= mark_guards False (strip_guards (-F) c')\"\n  assumes c: \"merge_guards c = merge_guards (mark_guards False c')\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof -\n  from deriv_strip_triv have deriv_strip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c'' UNIV,UNIV\"\n    by (auto intro: hoare_augment_context)\n  from deriv_strip [simplified c'']\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P (strip_guards (- F) c') UNIV,UNIV\"\n    by (rule HoarePartialProps.MarkGuardsD)\n  with deriv\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c' Q,A\"\n    by (rule CombineStrip)\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards False c' Q,A\"\n    by (rule MarkGuardsI)\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P merge_guards (mark_guards False c') Q,A\"\n    by (rule MergeGuardsI)\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P merge_guards c Q,A\"\n    by (simp add: c)\n  thus ?thesis\n    by (rule MergeGuardsD)\nqed\n\nlemma CombineStrip'':\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{True}\\<^esub> P c' Q,A\"\n  assumes deriv_strip_triv: \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/{}\\<^esub> P c'' UNIV,UNIV\"\n  assumes c'': \"c''= mark_guards False (strip_guards ({False}) c')\"\n  assumes c: \"merge_guards c = merge_guards (mark_guards False c')\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\n  apply (rule CombineStrip' [OF deriv deriv_strip_triv _ c])\n  apply (insert c'')\n  apply (subgoal_tac \"- {True} = {False}\")\n  apply auto\n  done\n\nlemma AsmUN:\n  \"(\\<Union>Z. {(P Z, p, Q Z,A Z)}) \\<subseteq> \\<Theta>\n  \\<Longrightarrow>\n  \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P Z) (Call p) (Q Z),(A Z)\"\n  by (blast intro: hoaret.Asm)\n\n\nlemma hoaret_to_hoarep':\n  \"\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z) \\<Longrightarrow> \\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z)\"\n  by (iprover intro: total_to_partial)\n\nlemma augment_context':\n  \"\\<lbrakk>\\<Theta> \\<subseteq> \\<Theta>'; \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P Z)  p (Q Z),(A Z)\\<rbrakk>\n   \\<Longrightarrow> \\<forall>Z. \\<Gamma>,\\<Theta>'\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z)\"\n  by (iprover intro: hoaret_augment_context)\n\n\nlemma augment_emptyFaults:\n \"\\<lbrakk>\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> (P Z) p (Q Z),(A Z)\\<rbrakk> \\<Longrightarrow>\n    \\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z)\"\n  by (blast intro: augment_Faults)\n\nlemma augment_FaultsUNIV:\n \"\\<lbrakk>\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z)\\<rbrakk> \\<Longrightarrow>\n    \\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/UNIV\\<^esub> (P Z) p (Q Z),(A Z)\"\n  by (blast intro: augment_Faults)\n\nlemma PostConjI [trans]:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c R,B\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\n  by (rule PostConjI)\n\nlemma PostConjI' :\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c R,B\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\n  by (rule PostConjI) iprover+\n\nlemma PostConjE [consumes 1]:\n  assumes conj: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\n  assumes E: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c R,B\\<rbrakk> \\<Longrightarrow> S\"\n  shows \"S\"\nproof -\n  from conj have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" by (rule conseqPost) blast+\n  moreover\n  from conj have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c R,B\" by (rule conseqPost) blast+\n  ultimately show \"S\"\n    by (rule E)\nqed\n\nsubsubsection \\<open>Rules for Single-Step Proof \\label{sec:hoare-isar}\\<close>\n\ntext \\<open>\n We are now ready to introduce a set of Hoare rules to be used in\n single-step structured proofs in Isabelle/Isar.\n\n \\medskip Assertions of Hoare Logic may be manipulated in\n calculational proofs, with the inclusion expressed in terms of sets\n or predicates.  Reversed order is supported as well.\n\\<close>\n\n\nlemma annotateI [trans]:\n\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P anno Q,A; c = anno\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (simp)\n\nlemma annotate_normI:\n  assumes deriv_anno: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>P anno Q,A\"\n  assumes norm_eq: \"normalize c = normalize anno\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>P c Q,A\"\nproof -\n  from HoareTotalProps.NormalizeI [OF deriv_anno] norm_eq\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>P normalize c Q,A\"\n    by simp\n  from NormalizeD [OF this]\n  show ?thesis .\nqed\n\n\nlemma annotateWhile:\n\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (whileAnnoG gs b I V c) Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (while gs b c) Q,A\"\n  by (simp add: whileAnnoG_def)\n\n\nlemma reannotateWhile:\n\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (whileAnnoG gs b I V c) Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (whileAnnoG gs b J V c) Q,A\"\n  by (simp add: whileAnnoG_def)\n\nlemma reannotateWhileNoGuard:\n\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (whileAnno b I V c) Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (whileAnno b J V c) Q,A\"\n  by (simp add: whileAnno_def)\n\nlemma [trans] : \"P' \\<subseteq> P \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q,A\"\n  by (rule conseqPre)\n\nlemma [trans]: \"Q \\<subseteq> Q' \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q',A\"\n  by (rule conseqPost) blast+\n\nlemma [trans]:\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. P s} c Q,A \\<Longrightarrow> (\\<And>s. P' s \\<longrightarrow> P s) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. P' s} c Q,A\"\n  by (rule conseqPre) auto\n\nlemma [trans]:\n    \"(\\<And>s. P' s \\<longrightarrow> P s) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. P s} c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. P' s} c Q,A\"\n  by (rule conseqPre) auto\n\nlemma [trans]:\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c {s. Q s},A \\<Longrightarrow> (\\<And>s. Q s \\<longrightarrow> Q' s) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c {s. Q' s},A\"\n  by (rule conseqPost) auto\n\nlemma [trans]:\n    \"(\\<And>s. Q s \\<longrightarrow> Q' s) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c {s. Q s},A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c {s. Q' s},A\"\n  by (rule conseqPost) auto\n\nlemma [intro?]: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Skip P,A\"\n  by (rule Skip) auto\n\nlemma CondInt [trans,intro?]:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> b) c1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> - b) c2 Q,A\\<rbrakk>\n   \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Cond b c1 c2) Q,A\"\n  by (rule Cond) auto\n\nlemma CondConj [trans, intro?]:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. P s \\<and> b s} c1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. P s \\<and> \\<not> b s} c2 Q,A\\<rbrakk>\n   \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. P s} (Cond {s. b s} c1 c2) Q,A\"\n  by (rule Cond) auto\nend\n\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/c-parser/Simpl/HoareTotal.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5851011542032312, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.2811286290958731}}
{"text": "section \\<open> CSP Operators \\<close>\n\ntheory ITree_CSP\n  imports \"Interaction_Trees.ITrees\" \"Optics.Optics\"\nbegin\n\nsubsection \\<open> Event Trace and Set Syntax\\<close>\n\ndefinition evinsert :: \"'e \\<Rightarrow> 'e set \\<Rightarrow> 'e set\" where\n[code_unfold]: \"evinsert e E = insert e E\"\n\ndefinition evsimple :: \"(unit \\<Longrightarrow>\\<^sub>\\<triangle> 'e) \\<Rightarrow> 'e\" where\n[code_unfold]: \"evsimple c = build\\<^bsub>c\\<^esub> ()\"\n\ndefinition evparam :: \"('a \\<Longrightarrow>\\<^sub>\\<triangle> 'e) \\<Rightarrow> 'a \\<Rightarrow> 'e\" where\n[code_unfold]: \"evparam c v = build\\<^bsub>c\\<^esub> v\"\n\ndefinition evcollect :: \"('a \\<Longrightarrow>\\<^sub>\\<triangle> 'e) \\<Rightarrow> 'a set \\<Rightarrow> ('a \\<Rightarrow> bool) \\<Rightarrow> 'e set\" where\n[code_unfold]: \"evcollect c A P = {build\\<^bsub>c\\<^esub> v | v. v \\<in> A \\<and> P v}\"\n\ndefinition empty_evset (\"\\<lbrace>\\<rbrace>\") where [code_unfold]: \"\\<lbrace>\\<rbrace> = {}\"\n\nnonterminal evt and evts\n\nsyntax \n  \"_evt\"       :: \"evt \\<Rightarrow> evts\" (\"_\")\n  \"_evts\"      :: \"evt \\<Rightarrow> evts \\<Rightarrow> evts\" (\"_,/ _\")\n  \"_evt_id\"    :: \"id \\<Rightarrow> evt\" (\"_\")\n  \"_evt_param\" :: \"id \\<Rightarrow> logic \\<Rightarrow> evt\" (\"_/ _\")\n  \"_evt_set\"   :: \"evts \\<Rightarrow> logic\" (\"\\<lbrace>_\\<rbrace>\")\n  \"_evt_collect\" :: \"id \\<Rightarrow> pttrn \\<Rightarrow> logic \\<Rightarrow> logic \\<Rightarrow> logic\" (\"\\<lbrace>_/ _ \\<in> _./ _\\<rbrace>\")\n  \"_evt_collect_ns\" :: \"id \\<Rightarrow> pttrn \\<Rightarrow> logic \\<Rightarrow> logic\" (\"\\<lbrace>_/ _./ _\\<rbrace>\")\n  \"_evt_trace\"   :: \"evts \\<Rightarrow> logic\" (\"\\<langle>_\\<rangle>\")\n\ntranslations \n  \"_evt e\" => \"CONST evinsert e \\<lbrace>\\<rbrace>\"\n  \"_evts e es\" => \"CONST evinsert e es\"\n  \"_evt_id x\" == \"CONST evsimple x\"\n  \"_evt_param x v\" == \"CONST evparam x v\"\n  \"_evt_set A\" => \"A\"\n  \"_evt_collect e x A P\" == \"CONST evcollect e A (\\<lambda> x. P)\"\n  \"_evt_collect_ns e x P\" == \"_evt_collect e x (CONST UNIV) P\"\n  \"\\<lbrace>e\\<rbrace>\" <= \"CONST evinsert e \\<lbrace>\\<rbrace>\"\n  \"\\<lbrace>e, es\\<rbrace>\" <= \"CONST evinsert e (_evt_set es)\"\n  \"_evt_trace (_evt e)\" => \"[e]\"\n  \"_evt_trace (_evts e tr)\" => \"e # _evt_trace tr\"\n\nsubsection \\<open> Basic Constructs \\<close>\n\ndefinition skip :: \"('e, unit) itree\" where\n\"skip = Ret ()\"\n\nabbreviation inp_in_where_choice :: \"('a \\<Longrightarrow>\\<^sub>\\<triangle> 'e) \\<Rightarrow> 'a set \\<Rightarrow> ('a \\<Rightarrow> bool) \\<Rightarrow> _\" where\n  \"inp_in_where_choice c A P \\<equiv> (\\<lambda> e \\<in> build\\<^bsub>c\\<^esub> ` A | P (the (match\\<^bsub>c\\<^esub> e)) \\<bullet> \\<checkmark> (the (match\\<^bsub>c\\<^esub> e)))\"\n\ndefinition inp_in_where :: \"('a \\<Longrightarrow>\\<^sub>\\<triangle> 'e) \\<Rightarrow> 'a set \\<Rightarrow> ('a \\<Rightarrow> bool) \\<Rightarrow> ('e, 'a) itree\" where\n\"inp_in_where c A P = Vis (inp_in_where_choice c A P)\"\n\nabbreviation \"inp_in c A \\<equiv> inp_in_where c A (\\<lambda> s. True)\"\n\nabbreviation \"inp_where c P \\<equiv> inp_in_where c UNIV P\"\n\nlemma retvals_inp_in_where: \"wb_prism c \\<Longrightarrow> \\<^bold>R(inp_in_where c A P) = {x \\<in> A. P x}\"\n  by (auto simp add: inp_in_where_def)\n     (metis image_insert insertCI insert_Diff option.sel retvals_Ret wb_prism.match_build)\n\nlemma retvals_inp_in: \"wb_prism c \\<Longrightarrow> \\<^bold>R(inp_in c A) = A\"\n  by (simp add: retvals_inp_in_where)\n\nlemma div_free_inp_in: \"div_free (inp_in c A)\"\n  by (auto simp add: inp_in_where_def div_free_Vis)\n\nabbreviation inp :: \"('a \\<Longrightarrow>\\<^sub>\\<triangle> 'e)\\<Rightarrow> ('e, 'a) itree\" where\n\"inp c \\<equiv> inp_in c UNIV\"\n\ndefinition inp_list :: \"('a \\<Longrightarrow>\\<^sub>\\<triangle> 'e) \\<Rightarrow> 'a list \\<Rightarrow> ('e, 'a) itree\" where\n\"inp_list c B = Vis (pfun_of_alist (map (\\<lambda>x. (build\\<^bsub>c\\<^esub> x, \\<checkmark> (the (match\\<^bsub>c\\<^esub> (build\\<^bsub>c\\<^esub> x))))) (filter (\\<lambda>x. build\\<^bsub>c\\<^esub> x \\<in> dom match\\<^bsub>c\\<^esub> ) B)))\"\n\ndefinition inp_list_where :: \"('a \\<Longrightarrow>\\<^sub>\\<triangle> 'e) \\<Rightarrow> 'a list \\<Rightarrow> ('a \\<Rightarrow> bool) \\<Rightarrow> ('e, 'a) itree\" where\n\"inp_list_where c B P = Vis (pfun_of_alist (map (\\<lambda>x. (build\\<^bsub>c\\<^esub> x, \\<checkmark> x)) (filter P B)))\"\n\ndefinition inp_map_in_where :: \"('a \\<Longrightarrow>\\<^sub>\\<triangle> 'e) \\<Rightarrow> 'a set \\<Rightarrow> ('a \\<Rightarrow> bool) \\<Rightarrow> ('e, 'a) itree\" where\n\"inp_map_in_where c B P = Vis (pfun_of_map (\\<lambda> e. case match\\<^bsub>c\\<^esub> e of \n                                                  Some v \\<Rightarrow> if (v \\<in> B \\<and> P v) then Some (Ret v) else None | \n                                                  None \\<Rightarrow> None))\"\n\ndefinition inp_map :: \"('a \\<Longrightarrow>\\<^sub>\\<triangle> 'e)\\<Rightarrow> ('e, 'a) itree\" where\n\"inp_map c = Vis (pfun_of_map (\\<lambda> e. case match\\<^bsub>c\\<^esub> e of Some v \\<Rightarrow> Some (Ret v) | None \\<Rightarrow> None))\"\n\nlemma inp_in_where_map_code [code_unfold]:\n  \"wb_prism c \\<Longrightarrow> inp_in_where c A P = inp_map_in_where c A P\"\n  apply (auto simp add: inp_in_where_def inp_map_in_where_def fun_eq_iff pfun_eq_iff domI pdom.abs_eq option.case_eq_if)\n  apply (metis (no_types, opaque_lifting) imageI option.distinct(1) option.exhaust_sel wb_prism_def)\n  done\n\nlemma inp_in_where_list_code [code_unfold]:\n  \"wb_prism c \\<Longrightarrow> inp_in_where c (set xs) P = inp_list_where c xs P\"\n  unfolding inp_in_where_def inp_list_where_def\n  by (simp only: set_map [THEN sym] inter_set_filter pabs_set filter_map comp_def, simp add: comp_def)\n\nlemma inp_map_in_where_list_code [code_unfold]:\n  \"wb_prism c \\<Longrightarrow> inp_map_in_where c (set xs) P = inp_list_where c xs P\"\n  by (metis inp_in_where_list_code inp_in_where_map_code)\n\n(*\nlemma inp_where_code [code_unfold]:\n  \"wb_prism c \\<Longrightarrow>inp_where c P = Vis (pfun_of_map (\\<lambda> e. case match\\<^bsub>c\\<^esub> e of Some v \\<Rightarrow> if (P v) then Some (Ret v) else None | None \\<Rightarrow> None))\"\n  apply (auto simp add: inp_in_where_def fun_eq_iff pfun_eq_iff domI pdom.abs_eq option.case_eq_if)\n  apply (metis domIff option.simps(3) wb_prism.range_build)\n  apply (meson option.distinct(1) option.exhaust_sel)\n*)\n\nlemma build_in_dom_match [simp]: \"wb_prism c \\<Longrightarrow> build\\<^bsub>c\\<^esub> x \\<in> dom match\\<^bsub>c\\<^esub>\"\n  by (simp add: dom_def)\n\ntext \\<open> Is there a way to use this optimise the above definition when applied to a well-behaved prism? \\<close>\n\nlemma inp_list_wb_prism: \"wb_prism c \\<Longrightarrow> inp_list c B = Vis (pfun_of_alist (map (\\<lambda>x. (build\\<^bsub>c\\<^esub> x, \\<checkmark> x)) B))\"\n  by (simp add: inp_list_def)\n\nlemma inp_where_enum [code_unfold]:\n  assumes \"wb_prism c\"\n  shows \"inp_where c P = inp_list_where c enum_class.enum P\"\nproof -\n  have \"inp_where c P = inp_in_where c (set enum_class.enum) P\"\n    by (simp add:  enum_class.UNIV_enum)\n  also have \"... = inp_list_where c enum_class.enum P\"\n    by (simp add: assms inp_in_where_list_code)\n  finally show ?thesis .\nqed\n\nlemma inp_map_where_enum [code_unfold]:\n  assumes \"wb_prism c\"\n  shows \"inp_map_in_where c UNIV P = inp_list_where c enum_class.enum P\"\n  using inp_where_enum[of c P] by (simp add: inp_in_where_map_code assms)\n\n(*\nlemma inp_alist [code]:\n  \"inp_in c (set B) = inp_list c B\"\n  unfolding inp_in_where_def inp_list_def\n  by (simp only: set_map[THEN sym] inter_set_filter pabs_set filter_map comp_def, simp add: comp_def)\n\nlemma inp_enum [code_unfold]:\n  \"wb_prism c \\<Longrightarrow> inp c = inp_list c enum_class.enum\"\n  apply (simp add: inp_list_def inp_in_where_def wb_prism.range_build[THEN sym] enum_class.UNIV_enum)\n  apply (simp only: image_set pabs_set)\n  apply (simp add: comp_def)\n  done\n\nlemma inp_in_coset [code_unfold]: \n  \"wb_prism c \\<Longrightarrow> inp_in c (List.coset []) = Vis (pfun_of_map (\\<lambda> e. case match\\<^bsub>c\\<^esub> e of Some v \\<Rightarrow> Some (Ret v) | None \\<Rightarrow> None))\"\n  by (auto simp add: inp_in_def pabs_def pfun_entries_def pdom_res_def pfun_of_map_inject restrict_map_def fun_eq_iff domIff wb_prism.range_build)\n*)\n\ndefinition outp :: \"('a \\<Longrightarrow>\\<^sub>\\<triangle> 'e) \\<Rightarrow> 'a \\<Rightarrow> ('e, unit) itree\" where\n\"outp c v = Vis (pfun_of_alist [(build\\<^bsub>c\\<^esub> v, Ret())])\"\n\ndefinition sync :: \"(unit \\<Longrightarrow>\\<^sub>\\<triangle> 'e) \\<Rightarrow> ('e, unit) itree\" where\n\"sync c = Vis (pfun_of_alist [(build\\<^bsub>c\\<^esub> (), Ret())])\"\n\ndefinition guard :: \"bool \\<Rightarrow> ('e, unit) itree\" where\n\"guard b = (if b then Ret () else deadlock)\"\n\nsubsection \\<open> Generalised Choice \\<close>\n\ntext \\<open> Generalised choice is parametric over a function to merge the choice functions. \\<close>\n\nprimcorec \n  genchoice :: \"(('e \\<Zpfun> ('e, 'a) itree) \\<Rightarrow> ('e \\<Zpfun> ('e, 'a) itree) \\<Rightarrow> 'e \\<Zpfun> ('e, 'a) itree) \n                \\<Rightarrow> ('e, 'a) itree \\<Rightarrow> ('e, 'a) itree \\<Rightarrow> ('e, 'a) itree\"  where\n\"genchoice \\<M> P Q =\n   (case (P, Q) of \n      (Vis F, Vis G) \\<Rightarrow> Vis (\\<M> F G) |\n      (Sil P', _) \\<Rightarrow> Sil (genchoice \\<M> P' Q) | \\<comment> \\<open> Maximal progress \\<close>\n      (_, Sil Q') \\<Rightarrow> Sil (genchoice \\<M> P Q') |\n      \\<comment> \\<open> cf. Butterfield's external choice miraculous issue and a quantum-like computation with reconciliation \\<close>\n      (Ret x, Ret y) \\<Rightarrow> if (x = y) then Ret x else Vis {}\\<^sub>p |\n      (Ret v, Vis _) \\<Rightarrow> Ret v | \\<comment> \\<open> Is this like sliding choice? \\<close>\n      (Vis _, Ret v) \\<Rightarrow> Ret v\n   )\"\n\nlemma genchoice_Vis_Vis [simp]: \"genchoice \\<M> (Vis F) (Vis G) = Vis (\\<M> F G)\"\n  by (simp add: genchoice.code)\n\nlemma genchoice_diverge: \"genchoice \\<M> diverge P = diverge\"\n  by (coinduction arbitrary: P, auto elim!: stableE is_RetE is_VisE unstableE, metis diverge.code itree.simps(11))\n\nlemma is_Sil_genchoice: \"is_Sil (genchoice \\<M> P Q) = (is_Sil P \\<or> is_Sil Q)\"\n  using itree.exhaust_disc by (auto)\n\nlemma genchoice_Vis_iff: \n  \"genchoice \\<M> P Q = Vis H \\<longleftrightarrow> ((\\<exists> F G. P = Vis F \\<and> Q = Vis G \\<and> H = (\\<M> F G)) \\<or> (\\<exists> x y. P = Ret x \\<and> Q = Ret y \\<and> x \\<noteq> y \\<and> H = {}\\<^sub>p))\"\n  (is \"?lhs = ?rhs\")\nproof\n  assume a: ?lhs\n  hence is_Vis: \"is_Vis (genchoice \\<M> P Q)\"\n    by simp\n  thus ?rhs\n    apply (auto elim!: is_RetE is_VisE)\n    using a\n     apply (simp_all add: a genchoice.code)\n    done\nnext\n  assume ?rhs\n  thus ?lhs\n    by (auto simp add: genchoice.code)\nqed\n\nlemma genchoice_VisE [elim]:\n  assumes \"Vis H = genchoice \\<M> P Q\"\n  \"\\<And> F G. \\<lbrakk> P = Vis F; Q = Vis G; H = (\\<M> F G) \\<rbrakk> \\<Longrightarrow> R\"\n  \"\\<And> x y. \\<lbrakk> P = Ret x; Q = Ret y; x \\<noteq> y; H = {}\\<^sub>p \\<rbrakk> \\<Longrightarrow> R\"\n  shows R\n  by (metis assms(1) assms(2) assms(3) genchoice_Vis_iff)\n\nlemma genchoice_Sils: \"genchoice \\<M> (Sils m P) Q = Sils m (genchoice \\<M> P Q)\"\n  by (induct m, simp_all add: genchoice.code)\n\nlemma genchoice_Sil_stable: \"stable P \\<Longrightarrow> genchoice \\<M> P (Sil Q) = Sil (genchoice \\<M> P  Q)\"\n  by (cases P, simp_all add: genchoice.code)\n\nlemma genchoice_Sils_stable: \"stable P \\<Longrightarrow> genchoice \\<M> P (Sils m Q) = Sils m (genchoice \\<M> P Q)\"\n  by (induct m, simp_all add: genchoice_Sil_stable)\n\nlemma genchoice_Sils': \"genchoice \\<M> P (Sils m Q) = Sils m (genchoice \\<M> P Q)\"\nproof (cases \"divergent P\")\n  case True\n  then show ?thesis\n    by (metis Sils_diverge genchoice_diverge diverges_then_diverge) \nnext\n  case False\n  then obtain n P' where \"Sils n P' = P\" \"stable P'\"\n    using stabilises_def by blast\n  then show ?thesis\n    by (metis Sils_Sils add.commute genchoice_Sils genchoice_Sils_stable)\nqed\n\nlemma genchoice_deadlock_left [simp]: \n  assumes \"\\<And> F. \\<M> {}\\<^sub>p F = F\"\n  shows \"genchoice \\<M> deadlock P = P\"\nproof (coinduction arbitrary: P rule: itree_strong_coind)\n  case wform\nthen show ?case\n  by (simp add: deadlock_def) \nnext\n  case (Ret x y)\n  then show ?case\n    by (metis (no_types, lifting) deadlock_def genchoice.ctr(1) itree.collapse(1) itree.disc(9) itree.discI(1) itree.inject(1) itree.simps(12) prod.sel(1) prod.sel(2)) \nnext\n  case (Sil P' Q' P)\n  then show ?case\n    by (metis genchoice_Sil_stable itree.inject(2) stable_deadlock)\nnext\n  case Vis\n  then show ?case\n    by (metis assms deadlock_def genchoice_Vis_Vis itree.inject(3)) \nqed\n\nlemma genchoice_deadlock_right [simp]: \n  assumes \"\\<And> F. \\<M> F {}\\<^sub>p = F\"\n  shows \"genchoice \\<M> P deadlock = P\"\nproof (coinduction arbitrary: P rule: itree_strong_coind)\n  case wform\n  then show ?case\n  by (simp add: deadlock_def) \nnext\n  case Ret\n  then show ?case\n    by (metis (no_types, lifting) deadlock_def genchoice.ctr(1) itree.case_eq_if itree.collapse(1) itree.disc(9) itree.discI(1) itree.inject(1) itree.simps(12) prod.sel(1) prod.sel(2)) \nnext\n  case Sil\n  then show ?case\n    by (metis genchoice.sel(2) itree.case(2) itree.disc(5) itree.sel(2) prod.sel(1))\nnext\n  case Vis\n  then show ?case\n    by (metis assms deadlock_def genchoice_Vis_Vis itree.inject(3))\nqed\n\nlemma genchoice_Sil': \"genchoice \\<M> P (Sil Q) = genchoice \\<M> (Sil P) Q\"\nproof (coinduction arbitrary: P Q rule: itree_strong_coind)\ncase wform\n  then show ?case\n    by (meson is_Sil_genchoice itree.disc(2) itree.disc(8) itree.distinct_disc(1) itree.distinct_disc(6) itree.exhaust_disc)\nnext\n  case Ret\n  then show ?case\n    by (metis is_Sil_genchoice itree.disc(4) itree.disc(5)) \nnext\n  case (Sil P Q P' Q')\n  then show ?case\n    by (metis Sils.simps(1) Sils.simps(2) genchoice_Sils genchoice_Sils' itree.sel(2))    \nnext\n  case Vis\n  then show ?case\n    by (metis is_Sil_genchoice itree.disc(5) itree.disc(6)) \nqed\n\nlemma genchoice_unstable: \"unstable P \\<Longrightarrow> genchoice \\<M> P Q = Sil (genchoice \\<M> (un_Sil P) Q)\"\n  by (metis (no_types, lifting) genchoice.ctr(2) itree.case(2) itree.collapse(2) prod.sel(1))\n\nlemma genchoice_unstable': \"unstable Q \\<Longrightarrow> genchoice \\<M> P Q = Sil (genchoice \\<M> P (un_Sil Q))\"\n  by (metis genchoice_Sil' genchoice_Sil_stable genchoice_unstable itree.collapse(2))\n\nlemma genchoice_commute:\n  fixes P Q :: \"('e, 's) itree\"\n  assumes \"\\<And> F. \\<M> F {}\\<^sub>p = F\" \"\\<And> F. \\<M> {}\\<^sub>p F = F\"\n  shows \"genchoice \\<M> P Q = genchoice (\\<lambda> F G. \\<M> G F) Q P\"\nproof (coinduction arbitrary: P Q rule: itree_coind)\n  case wform\n  then show ?case\n    by (metis genchoice.disc_iff(1) genchoice.disc_iff(3) itree.distinct_disc(1) itree.distinct_disc(6) itree.exhaust_disc prod.sel(1) prod.sel(2))\nnext\n  case Ret\n  then show ?case\n    by (smt genchoice.disc_iff(1) genchoice.simps(3) genchoice.simps(4) itree.case_eq_if itree.disc(7) itree.sel(1) prod.sel(1) snd_conv un_Ret_def)\nnext\n  case (Sil P Q P' Q')\n  then show ?case\n  proof (cases \"unstable P'\")\n    case True\n    with Sil have \"P = genchoice \\<M> (un_Sil P') Q'\" \"Q = genchoice (\\<lambda> F G. \\<M> G F) Q' (un_Sil P')\"\n      by (simp_all add: genchoice_unstable genchoice_unstable')\n    thus ?thesis\n      by blast\n  next\n    case False\n      then show ?thesis\n        by (metis Sil(1) Sil(2) genchoice_Sil' genchoice_unstable' is_Sil_genchoice itree.disc(5) itree.sel(2) unstableE)\n  qed\nnext\n  case Vis\n  then show ?case\n    using assms by (auto elim!: genchoice_VisE, metis genchoice_deadlock_left genchoice_deadlock_right)\nqed\n\nlemma genchoice_commutative:\n  fixes P Q :: \"('e, 's) itree\"\n  assumes \"\\<And> F. \\<M> F {}\\<^sub>p = F\" \"\\<And> F. \\<M> {}\\<^sub>p F = F\" \"\\<And> F G. \\<M> F G = \\<M> G F\"\n  shows \"genchoice \\<M> P Q = genchoice \\<M> Q P\"\n  by (subst genchoice_commute, simp_all add: assms)\n\nlemma skip_stable_genchoice_left: \n  assumes \"stable P\"\n  shows \"genchoice \\<M> skip P = skip\"\n  by (metis (mono_tags, opaque_lifting) assms genchoice.disc_iff(1) is_Ret_def itree.exhaust_disc old.unit.exhaust prod.sel(1) prod.sel(2) skip_def)\n\nlemma skip_stable_genchoice_right:\n  assumes \"stable P\"\n  shows \"genchoice \\<M> P skip = skip\"\n  by (metis (mono_tags, opaque_lifting) assms genchoice.disc_iff(1) is_Ret_def itree.exhaust_disc old.unit.exhaust prod.sel(1) prod.sel(2) skip_def)\n\nlemma genchoice_RetE [elim]:\n  assumes \"genchoice \\<M> P Q = \\<checkmark> x\" \n    \"\\<lbrakk> P = Ret x; Q = Ret x\\<rbrakk> \\<Longrightarrow> R\"\n    \"\\<lbrakk> P = Ret x; is_Vis Q \\<rbrakk> \\<Longrightarrow> R\"\n    \"\\<lbrakk> Q = Ret x; is_Vis P \\<rbrakk> \\<Longrightarrow> R\"\n  shows R\n  using assms apply (cases P)\n  apply (auto simp add: genchoice.code)\n  apply (smt (z3) assms(1) genchoice.disc_iff(1) is_Sil_genchoice itree.case_eq_if itree.disc(4) itree.discI(1) itree.distinct(3) itree.expand itree.sel(1) snd_conv)\n  apply (metis (no_types, lifting) assms(1) is_Sil_genchoice itree.case_eq_if itree.collapse(1) itree.disc(4) itree.disc(7) itree.disc(9))\n  done\n\n\nsubsection \\<open> External Choice \\<close>\n\ndefinition map_prod :: \"('a \\<Zpfun> 'b) \\<Rightarrow> ('a \\<Zpfun> 'b) \\<Rightarrow> ('a \\<Zpfun> 'b)\" (infixl \"\\<odot>\" 100) where\n\"map_prod f g = (pdom(g) \\<Zndres> f) \\<oplus> (pdom(f) \\<Zndres> g)\"\n\nlemma map_prod_commute: \"x \\<odot> y = y \\<odot> x\"\n  apply (auto simp add: fun_eq_iff map_prod_def option.case_eq_if)\n  apply (metis Compl_iff IntD1 IntD2 pdom_pdom_res pfun_override_commute_weak)\n  done\n\nlemma map_prod_empty [simp]: \"x \\<odot> {}\\<^sub>p = x\" \"{}\\<^sub>p \\<odot> x = x\"\n  by (simp_all add: map_prod_def)\n\nlemma map_prod_merge: \n  \"f(x \\<mapsto> v)\\<^sub>p \\<odot> g = \n  (if (x \\<notin> pdom(g)) then (f \\<odot> g)(x \\<mapsto> v)\\<^sub>p else {x} \\<Zndres> (f \\<odot> g))\"\n  by (auto simp add: map_prod_def)\n     (metis (no_types, opaque_lifting) Compl_Un insert_absorb insert_is_Un)\n\nlemma map_prod_as_ovrd:\n  assumes \"pdom(f) \\<inter> pdom(g) = {}\"\n  shows \"f \\<odot> g = f \\<oplus> g\"\n  by (simp add: map_prod_def assms inf.commute pdom_nres_disjoint)\n\nlemma map_prod_pfun_of_map [code]:\n  \"map_prod (pfun_of_map f) (pfun_of_map g) = \n     pfun_of_map (\\<lambda> x. case (f x, g x) of\n                       (Some _, Some _) \\<Rightarrow> None |\n                       (Some y, None) \\<Rightarrow> Some y |\n                       (None, Some y) \\<Rightarrow> Some y |\n                       (None, None) \\<Rightarrow> None)\"\n  by (auto simp add: map_prod_def pdom_def pdom_res_def restrict_map_def oplus_pfun_def map_add_def \n      pfun_of_map_inject fun_eq_iff option.case_eq_if)\n\nlemma map_prod_pfun_of_alist [code]:\n  \"map_prod (pfun_of_alist xs) (pfun_of_alist ys) =\n    pfun_of_alist (AList.restrict (- fst ` set xs) ys @ AList.restrict (- fst ` set ys) xs)\"\n  by (simp add: map_prod_def pdom_res_alist plus_pfun_alist)\n\nlemma map_prod_pfun_of_map_alist [code]: \"(pfun_of_map f) \\<odot> (pfun_of_alist xs) \n  = pfun_of_map\n     (\\<lambda>x. case f x of None \\<Rightarrow> (case map_of xs x of None \\<Rightarrow> None | Some x \\<Rightarrow> Some x) \n        | Some xa \\<Rightarrow> (case map_of xs x of None \\<Rightarrow> Some xa | Some x \\<Rightarrow> Map.empty x))\"\n  by (simp add: pfun_of_alist.abs_eq map_prod_pfun_of_map)\n\nlemma map_prod_pfun_of_alist_map [code]: \"(pfun_of_alist xs) \\<odot> (pfun_of_map p)\n  = pfun_of_map\n     (\\<lambda>x. case map_of xs x of None \\<Rightarrow> (case p x of None \\<Rightarrow> None | Some x \\<Rightarrow> Some x)\n        | Some xa \\<Rightarrow> (case p x of None \\<Rightarrow> Some xa | Some x \\<Rightarrow> Map.empty x))\"\n  by (simp add: pfun_of_alist.abs_eq map_prod_pfun_of_map)\n\nlemma map_prod_Nil_alist [code]: \n  \"(pfun_of_alist []) \\<odot> P = P\"\n  \"P \\<odot> (pfun_of_alist []) = P\"\n  by simp_all\n\ntext \\<open> This is like race-free behaviour \\<close>\n\nclass extchoice = \n  fixes extchoice :: \"'a \\<Rightarrow> 'a \\<Rightarrow> 'a\" (infixl \"\\<box>\" 59)\n\ntext \\<open> This is an completion of Hoare's bar operator. \\<close>\n\ninstantiation itree :: (type, type) extchoice \nbegin\n\ntext \\<open> cf. RAISE language \"interlock\" operator -- basic operators of CCS vs. CSP operators. Can\n  this be expressed in terms of operators? \\<close>\n\ndefinition extchoice_itree :: \"('e, 'a) itree \\<Rightarrow> ('e, 'a) itree \\<Rightarrow> ('e, 'a) itree\"  where\n\"extchoice_itree = genchoice (\\<odot>)\"\n\ninstance ..\n\nend\n\nlemma choice_Vis_Vis [simp]: \"(Vis F) \\<box> (Vis G) = Vis (F \\<odot> G)\"\n  by (simp add: extchoice_itree_def)\n\nlemma choice_diverge: \"diverge \\<box> P = diverge\"\n  by (simp add: extchoice_itree_def genchoice_diverge)\n\nlemma is_Sil_choice: \"is_Sil (P \\<box> Q) = (is_Sil P \\<or> is_Sil Q)\"\n  by (metis extchoice_itree_def is_Sil_genchoice)\n  \nlemma choice_Vis_iff: \n  \"P \\<box> Q = Vis H \\<longleftrightarrow> ((\\<exists> F G. P = Vis F \\<and> Q = Vis G \\<and> H = (F \\<odot> G)) \\<or> (\\<exists> x y. P = Ret x \\<and> Q = Ret y \\<and> x \\<noteq> y \\<and> H = {}\\<^sub>p))\"\n  by (simp add: extchoice_itree_def genchoice_Vis_iff)\n  \nlemma choice_VisE [elim]:\n  assumes \"Vis H = P \\<box> Q\"\n  \"\\<And> F G. \\<lbrakk> P = Vis F; Q = Vis G; H = (F \\<odot> G) \\<rbrakk> \\<Longrightarrow> R\"\n  \"\\<And> x y. \\<lbrakk> P = Ret x; Q = Ret y; x \\<noteq> y; H = {}\\<^sub>p \\<rbrakk> \\<Longrightarrow> R\"\n  shows R\n  by (metis assms(1) assms(2) assms(3) choice_Vis_iff)\n\nlemma choice_Sils: \"(Sils m P) \\<box> Q = Sils m (P \\<box> Q)\"\n  by (simp add: extchoice_itree_def genchoice_Sils)\n\nlemma choice_Sil_stable: \"stable P \\<Longrightarrow> P \\<box> (Sil Q) = Sil (P \\<box> Q)\"\n  by (simp add: extchoice_itree_def genchoice_Sil_stable)\n\nlemma choice_Sils_stable: \"stable P \\<Longrightarrow> P \\<box> (Sils m Q) = Sils m (P \\<box> Q)\"\n  by (simp add: extchoice_itree_def genchoice_Sils_stable)\n\nlemma choice_Sils': \"P \\<box> (Sils m Q) = Sils m (P \\<box> Q)\"\n  by (simp add: extchoice_itree_def genchoice_Sils')\n\ntext \\<open> External Choice test cases \\<close>\n\nlemma \"X \\<noteq> Y \\<Longrightarrow> (Vis {X \\<mapsto> Ret a}\\<^sub>p) \\<box> (Vis {Y \\<mapsto> Ret b}\\<^sub>p) = \n       Vis {X \\<mapsto> Ret a, Y \\<mapsto> Ret b}\\<^sub>p\"\n  by (auto simp add: genchoice.code map_prod_merge pfun_upd_comm)\n\nlemma \"(Vis {X \\<mapsto> Ret a}\\<^sub>p) \\<box> (Vis {X \\<mapsto> Ret b}\\<^sub>p) = \n       deadlock\"\n  by (simp add: deadlock_def map_prod_merge)\n\nlemma \"X \\<noteq> Y \\<Longrightarrow> (Sil (Vis {X \\<mapsto> Ret a}\\<^sub>p)) \\<box> (Sil (Vis {Y \\<mapsto> Ret b}\\<^sub>p)) = \n       Sil (Sil (Vis {X \\<mapsto> Ret a, Y \\<mapsto> Ret b}\\<^sub>p))\"\n  by (simp add: genchoice.code extchoice_itree_def map_prod_merge pfun_upd_comm)\n\ntext \\<open> This requires weak bisimulation \\<close>\n\nlemma \"\\<And> P. (X = (P :: ('e, 's) itree) \\<box> P \\<and> Y = P) \\<or> (X = Y) \\<Longrightarrow> X = Y\"\n  apply (coinduction arbitrary: X Y)\n  apply (auto simp add: itree.case_eq_if itree.distinct_disc(1))\n  oops\n\nlemma choice_deadlock [simp]: \"deadlock \\<box> P = P\"\n  by (simp add: extchoice_itree_def)\n\nlemma choice_deadlock' [simp]: \"P \\<box> deadlock = P\"\n  by (simp add: extchoice_itree_def)\n\nlemma choice_unstable: \"unstable P \\<Longrightarrow> P \\<box> Q = Sil ((un_Sil P) \\<box> Q)\"\n  by (simp add: extchoice_itree_def genchoice_unstable)\n\nlemma choice_unstable': \"unstable Q \\<Longrightarrow> P \\<box> Q = Sil (P \\<box> (un_Sil Q))\"\n  by (simp add: extchoice_itree_def genchoice_unstable')\n\nlemma choice_commutative:\n  fixes P Q :: \"('e, 's) itree\"\n  shows \"P \\<box> Q = Q \\<box> P\"\n  by (simp add: extchoice_itree_def genchoice_commutative map_prod_commute)\n\ntext \\<open> External choice is commutative, but currently not associative. This is because when we\n  have two competing return values, external choice deadlocks. However, since a return takes \n  priority over a visible event, that means the order in which deadlocks are produced and \n  returns occur is significant. Perhaps competing returns should lead to a divergence, which\n  would then take priority over a return. \\<close>\n\nlemma skip_stable_choice: \n  assumes \"stable P\"\n  shows \"skip \\<box> P = skip\"\n  by (simp add: assms extchoice_itree_def skip_stable_genchoice_left)\n\nlemma choice_RetE [elim]:\n  assumes \"P \\<box> Q = \\<checkmark> x\" \n    \"\\<lbrakk> P = Ret x; Q = Ret x\\<rbrakk> \\<Longrightarrow> R\"\n    \"\\<lbrakk> P = Ret x; is_Vis Q \\<rbrakk> \\<Longrightarrow> R\"\n    \"\\<lbrakk> Q = Ret x; is_Vis P \\<rbrakk> \\<Longrightarrow> R\"\n  shows R\n  by (metis (no_types, lifting) assms(1) assms(2) assms(3) assms(4) extchoice_itree_def genchoice_RetE)\n\nlemma extchoice_Vis_bind:\n  \"(Vis F \\<box> Vis G) \\<bind> R = (Vis F \\<bind> R) \\<box> (Vis G \\<bind> R)\"\n  by (simp add: map_prod_def)\n\nlemma \n  assumes \"is_Vis P\" \"is_Vis Q\" \"\\<^bold>I(P) \\<inter> \\<^bold>I(Q) = {}\"\n  shows \"\\<^bold>R(P \\<box> Q) = \\<^bold>R(P) \\<union> \\<^bold>R(Q)\"\nproof -\n  obtain F G where P: \"P = Vis F\" and Q: \"Q = Vis G\"\n    by (meson assms(1) assms(2) is_VisE)\n  hence \"pdom(F) \\<inter> pdom(G) = {}\"\n    using assms(3) by force\n  thus ?thesis\n    by (simp add: P Q map_prod_as_ovrd Un_commute pdom_nres_disjoint)\nqed\n\nlemma trace_to_Nil_extchoice: \"P \\<midarrow>[]\\<leadsto> P' \\<Longrightarrow> P \\<box> Q \\<midarrow>[]\\<leadsto> P' \\<box> Q\"\n  using choice_Sils trace_to_Nil_iff by blast\n\nlemma choice_Ret_Ret: \"\\<checkmark> x \\<box> \\<checkmark> y = (if x = y then \\<checkmark> x else deadlock)\"\n  by (auto simp add: extchoice_itree_def genchoice.ctr(1) deadlock_def genchoice_Vis_iff)\n\nlemma choice_Ret_Vis: \"\\<checkmark> x \\<box> Vis G = \\<checkmark> x\"\n  by (simp add: extchoice_itree_def genchoice.ctr(1))\n\nlemma pran_map_prod: \"pran (F \\<odot> G) \\<subseteq> pran F \\<union> pran G\"\n  by (auto simp add: map_prod_def)\n     (metis Un_iff pfun_split_domain pran_override)+\n\nlemma stabilises_retvals_extchoice:\n  assumes \"stabilises P\" \"stabilises Q\"\n  shows \"\\<^bold>R(P \\<box> Q) \\<subseteq> \\<^bold>R(P) \\<union> \\<^bold>R(Q)\"\nproof -\n  obtain m n P' Q' where PQ: \"P = Sils m P'\" \"stable P'\" \"Q = Sils n Q'\" \"stable Q'\"\n    by (metis assms(1) assms(2) stabilises_def)\n  show ?thesis\n  proof (cases \"P'\")\n    case (Ret x)\n    note Ret_P' = this\n    then show ?thesis\n    proof (cases Q')\n      case (Ret y)\n      with Ret_P' PQ show ?thesis\n        by (simp add: choice_Sils choice_Sils' choice_Ret_Ret)\n    next\n      case (Sil _)\n      then show ?thesis\n        using PQ(4) by auto\n    next\n      case (Vis G)\n      with Ret_P' PQ show ?thesis\n        by (simp add: choice_Sils choice_Sils')\n           (metis choice_Ret_Vis insertCI retvals_Ret singletonD subsetI)\n    qed\n  next\n    case (Sil _)\n    then show ?thesis\n      using PQ(2) by auto\n  next\n    case (Vis F)\n    note Vis_P' = this\n    then show ?thesis\n    proof (cases Q')\n      case (Ret y)\n      then show ?thesis\n        by (metis PQ(1) PQ(3) Vis_P' choice_Ret_Vis choice_commutative extchoice_itree_def genchoice_Sils' le_supI2 retvals_Sils set_eq_subset)\n    next\n      case (Sil _)\n      then show ?thesis\n        using PQ(4) by auto\n    next\n      case (Vis G)\n      with Vis_P' PQ show ?thesis\n        by (auto simp add: choice_Sils choice_Sils')\n           (meson Un_iff in_mono pran_map_prod)\n    qed\n  qed\nqed\n\nlemma retvals_extchoice: \"\\<^bold>R(P \\<box> Q) \\<subseteq> \\<^bold>R(P) \\<union> \\<^bold>R(Q)\"\n  by (metis Un_upper1 choice_commutative choice_diverge diverges_then_diverge le_supE retvals_diverge stabilises_retvals_extchoice sup_bot.right_neutral)\n\nsubsection \\<open> Generalised Parallel Composition \\<close>\n\ntext \\<open> This parallel composition operator follows a similar approach to the UTP \"parallel-by-merge\" scheme. \\<close>\n\ndatatype (discs_sels) ('a, 'b) andor = Left 'a | Right 'b | Both \"'a \\<times> 'b\"\n\ntype_synonym ('e, 'a, 'b) pmerge = \n  \"(('e \\<Zpfun> ('e, 'a) itree) \\<Rightarrow> 'e set \\<Rightarrow> ('e \\<Zpfun> ('e, 'b) itree) \\<Rightarrow> 'e \\<Zpfun> (('e, 'a) itree, ('e, 'b) itree) andor)\"\n\nprimcorec genpar :: \"('e, 'a, 'b) pmerge \\<Rightarrow> ('e, 'a) itree \\<Rightarrow> 'e set \\<Rightarrow> ('e, 'b) itree \\<Rightarrow> ('e, 'a \\<times> 'b) itree\" where\n\"genpar \\<M> P A Q =\n   (case (P, Q) of \n      \\<comment> \\<open> Silent events happen independently and have priority \\<close>\n      (Sil P', _) \\<Rightarrow> Sil (genpar \\<M> P' A Q) |\n      (_, Sil Q') \\<Rightarrow> Sil (genpar \\<M> P A Q') |\n      \\<comment> \\<open> Visible events are subject to synchronisation constraints \\<close>\n      (Vis F, Vis G) \\<Rightarrow>\n        Vis (map_pfun \n              (\\<lambda>x. case x of \n                     Left P' \\<Rightarrow> genpar \\<M> P' A Q \\<comment> \\<open> Left side acts independently \\<close>\n                   | Right Q' \\<Rightarrow> genpar \\<M> P A Q' \\<comment> \\<open> Right side acts independently \\<close> \n                   | Both (P', Q') \\<Rightarrow> genpar \\<M> P' A Q') \\<comment> \\<open> Both sides synchronise \\<close>\n              (\\<M> F A G)) |\n      \\<comment> \\<open> If both sides terminate, then they must agree on the returned value. This could be\n           generalised using a merge function. \\<close>\n      (Ret x, Ret y) \\<Rightarrow> Ret (x, y) |\n      \\<comment> \\<open> A termination occurring on one side is pushed forward. Only events not requiring\n           synchronisation can occur on the other side. \\<close>\n      (Ret v, Vis G)   \\<Rightarrow> Vis (map_pfun (\\<lambda> P. (genpar \\<M> (Ret v) A P)) (A \\<Zndres> G)) |\n      (Vis F, Ret v)   \\<Rightarrow> Vis (map_pfun (\\<lambda> P. (genpar \\<M> P A (Ret v))) (A \\<Zndres> F))\n   )\" \n\nlemma genpar_Sil_left [simp]:\n  \"genpar \\<M> (Sil P') E Q = Sil (genpar \\<M> P' E Q)\"\n  by (simp add: genpar.code)\n\nlemma genpar_Sil_stable_right:\n  \"stable P \\<Longrightarrow> genpar \\<M> P E (Sil Q') = Sil (genpar \\<M> P E Q')\"\n  by (auto elim!: stableE simp add: genpar.code)\n\nlemma unstable_genpar [simp]: \"unstable (genpar \\<M> P E Q) = (unstable P \\<or> unstable Q)\"\n  by (auto elim!: stableE)\n\nlemma genpar_Ret_iff: \"Ret x = genpar \\<M> P E Q \\<longleftrightarrow> (\\<exists> a b. P = Ret a \\<and> Q = Ret b \\<and> x = (a, b))\"\n  (is \"?lhs \\<longleftrightarrow> ?rhs\")\nproof\n  assume a:?lhs\n  hence \"is_Ret (genpar \\<M> P E Q)\"\n    by (metis itree.disc(1))\n  then obtain a b where \"P = Ret a\" \"Q = Ret b\"\n    by force\n  with a show ?rhs\n    by (simp add: genpar.code)\nnext\n  show \"?rhs \\<Longrightarrow> ?lhs\"\n    by (auto simp add: genpar.code)\nqed\n\nlemma genpar_Sil_iff: \"Sil R = genpar \\<M> P E Q \\<longleftrightarrow> ((\\<exists> P'. P = Sil P' \\<and> R = genpar \\<M> P' E Q) \\<or> (\\<exists> Q'. stable P \\<and> Q = Sil Q' \\<and> R = genpar \\<M> P E Q'))\"\n  (is \"?lhs \\<longleftrightarrow> ?rhs\")\nproof\n  assume a:?lhs\n  hence sil: \"is_Sil (genpar \\<M> P E Q)\"\n    by (metis (no_types, opaque_lifting) itree.disc(5))\n  show ?rhs\n  proof (cases \"unstable P\")\n    case True\n    with a show ?thesis\n      by (auto elim!: unstableE simp add: genpar.code)\n  next\n    case False\n    hence \"unstable Q\"\n      by (metis sil unstable_genpar)\n    with a False show ?thesis by (auto simp add: genpar_Sil_stable_right elim!: unstableE)\n  qed\nnext\n  show \"?rhs \\<Longrightarrow> ?lhs\"\n    by (auto simp add: genpar_Sil_stable_right)\nqed\n  \nlemma genpar_SilE [elim!]:\n  assumes \"Sil R = genpar \\<M> P E Q\"\n  \"\\<And> P'. \\<lbrakk> P = Sil P'; R = genpar \\<M> P' E Q \\<rbrakk> \\<Longrightarrow> S\"\n  \"\\<And> Q'. \\<lbrakk> stable P; Q = Sil Q'; R = genpar \\<M> P E Q' \\<rbrakk> \\<Longrightarrow> S\"\n  shows S\n  by (metis (full_types) assms(1) assms(2) assms(3) genpar_Sil_iff)\n\nlemma genpar_Sil_shift [simp]: \"genpar \\<M> P E (Sil Q) = genpar \\<M> (Sil P) E Q\"\n  by (coinduction arbitrary: P Q rule: itree_strong_coind, auto elim!: stableE, metis)\n\nlemma genpar_Sils_left [simp]: \"genpar \\<M> (Sils n P) E Q = Sils n (genpar \\<M> P E Q)\"\n  by (induct n, simp_all)\n\nlemma genpar_Sils_right [simp]: \"genpar \\<M> P E (Sils n Q) = Sils n (genpar \\<M> P E Q)\"\n  by (induct n, simp_all)\n\nlemma genpar_Ret_Ret [simp]:\n  \"genpar \\<M> (Ret x) E (Ret y) = Ret (x, y)\"\n  by (simp add: genpar.code)\n\ndefinition \"pmerge_Vis \\<M> F A G \\<equiv> \n  map_pfun \n    (\\<lambda>x. case x of \n           Left P' \\<Rightarrow> genpar \\<M> P' A (Vis G) \\<comment> \\<open> Left side acts independently \\<close>\n         | Right Q' \\<Rightarrow> genpar \\<M> (Vis F) A Q' \\<comment> \\<open> Right side acts independently \\<close> \n         | Both (P', Q') \\<Rightarrow> genpar \\<M> P' A Q') \\<comment> \\<open> Both sides synchronise \\<close>\n    (\\<M> F A G)\"\n\nlemma pdom_pmerge_Vis [simp]: \"pdom (pmerge_Vis \\<M> F A G) = pdom (\\<M> F A G)\"\n  by (simp add: pmerge_Vis_def)\n\nlemma genpar_Vis_Vis [simp]:\n  \"genpar \\<M> (Vis F) E (Vis G) = Vis (pmerge_Vis \\<M> F E G)\"\n  by (auto simp add: genpar.code pmerge_Vis_def)\n\nlemma genpar_Ret_Vis [simp]:\n  \"genpar \\<M> (Ret v) A (Vis G) = Vis (map_pfun (\\<lambda> P. (genpar \\<M> (Ret v) A P)) (A \\<Zndres> G))\"\n  by (subst genpar.code, simp)\n\nlemma genpar_Vis_Ret [simp]:\n  \"genpar \\<M> (Vis F) A (Ret v) = Vis (map_pfun (\\<lambda> P. (genpar \\<M> P A (Ret v))) (A \\<Zndres> F))\"\n  by (subst genpar.code, simp)\n\nlemma genpar_Vis_iff: \n  \"Vis H = genpar \\<M> P E Q \\<longleftrightarrow> ((\\<exists> F G. P = Vis F \\<and> Q = Vis G \\<and> H = pmerge_Vis \\<M> F E G) \n                         \\<or> (\\<exists> x G. P = Ret x \\<and> Q = Vis G \\<and> H = map_pfun (\\<lambda> P. (genpar \\<M> (Ret x) E P)) (E \\<Zndres> G))\n                         \\<or> (\\<exists> x F. P = Vis F \\<and> Q = Ret x \\<and> H = map_pfun (\\<lambda> P. (genpar \\<M> P E (Ret x))) (E \\<Zndres> F)))\"\n  (is \"?lhs \\<longleftrightarrow> ?rhs\")\nproof\n  assume a: \"?lhs\"\n  hence \"is_Vis (genpar \\<M> P E Q)\"\n    by (metis itree.disc(9))\n  thus ?rhs\n    apply (auto elim!: is_RetE is_VisE)\n    using a apply (simp_all)\n    done\nnext\n  show \"?rhs \\<Longrightarrow> ?lhs\" by (auto)\nqed\n\nlemma genpar_VisE [elim!]:\n  assumes \"Vis H = genpar \\<M> P E Q\"\n  \"\\<And> F G. \\<lbrakk> P = Vis F; Q = Vis G; H = pmerge_Vis \\<M> F E G \\<rbrakk> \\<Longrightarrow> R\"\n  \"\\<And> x G. \\<lbrakk> P = Ret x; Q = Vis G; H = map_pfun (\\<lambda> P. (genpar \\<M> (Ret x) E P)) (E \\<Zndres> G) \\<rbrakk> \\<Longrightarrow> R\"\n  \"\\<And> x F. \\<lbrakk> P = Vis F; Q = Ret x; H = map_pfun (\\<lambda> P. (genpar \\<M> P E (Ret x))) (E \\<Zndres> F) \\<rbrakk> \\<Longrightarrow> R\"\n  shows R\n  using assms by (auto simp add: genpar_Vis_iff)\n\nlemma genpar_diverge: \"genpar \\<M> diverge E P = diverge\"\nproof (coinduction arbitrary: P rule: itree_coind)\ncase wform\nthen show ?case by (auto)\nnext\n  case Ret\n  then show ?case\n    by (metis diverge_not_Ret) \nnext\n  case Sil\n  then show ?case \n    by (auto, metis diverge.sel itree.sel(2))+\nnext\n  case Vis\n  then show ?case\n    by (metis diverge_not_Vis) \nqed\n\nsubsection \\<open> Parallel Composition \\<close>\n\ntext \\<open> The following function combines two choice functions for parallel composition. \\<close>\n\ndefinition emerge :: \"('a \\<Zpfun> 'b) \\<Rightarrow> 'a set \\<Rightarrow> ('a \\<Zpfun> 'c) \\<Rightarrow> ('a \\<Zpfun> ('b, 'c) andor)\" where\n\"emerge f A g = \n  map_pfun Both (A \\<Zdres> pfuse f g) \\<oplus> map_pfun Left ((A \\<union> pdom(g)) \\<Zndres> f) \\<oplus> map_pfun Right ((A \\<union> pdom(f)) \\<Zndres> g)\"\n\nlemma emerge_alt_def:\n  \"emerge F E G =\n     (\\<lambda> e \\<in> pdom(F) \\<inter> pdom(G) \\<inter> E \\<bullet> Both(F(e), G(e)))\n     \\<oplus> (\\<lambda> x \\<in> pdom(F) - (E \\<union> pdom(G)) \\<bullet> Left(F x))\n     \\<oplus> (\\<lambda> x \\<in> pdom(G) - (E \\<union> pdom(F)) \\<bullet> Right(G x))\"\nproof -\n  have 1: \"map_pfun Both (E \\<Zdres> pfuse F G) = (\\<lambda> e \\<in> pdom(F) \\<inter> pdom(G) \\<inter> E \\<bullet> Both(F(e), G(e)))\"\n    by (auto intro!: pabs_cong simp add: map_pfun_as_pabs pfuse_def)\n  have 2: \"map_pfun Left ((E \\<union> pdom(G)) \\<Zndres> F) = (\\<lambda> x \\<in> pdom(F) - (E \\<union> pdom(G)) \\<bullet> Left(F x))\"\n    by (auto intro: pabs_cong simp add: map_pfun_as_pabs)\n  have 3: \"map_pfun Right ((E \\<union> pdom(F)) \\<Zndres> G) = (\\<lambda> x \\<in> pdom(G) - (E \\<union> pdom(F)) \\<bullet> Right(G x))\"\n    by (auto intro: pabs_cong simp add: map_pfun_as_pabs)\n  show ?thesis\n    by (simp only: emerge_def 1 2 3)\nqed\n\nlemma pdom_emerge_commute: \"pdom (emerge f A g) = pdom (emerge g A f)\"\n  by (auto simp add: emerge_def)\n\ntext \\<open> Remove merge function; it can be done otherwise. \\<close>\n\nabbreviation \"par \\<equiv> genpar emerge\"\n\nabbreviation \"merge_Vis \\<equiv> pmerge_Vis emerge\"\n\nlemma merge_Vis_both [simp]: \"\\<lbrakk> e \\<in> E; e \\<in> pdom F; e \\<in> pdom G \\<rbrakk> \\<Longrightarrow> merge_Vis F E G(e)\\<^sub>p = par (F(e)\\<^sub>p) E (G(e)\\<^sub>p)\"\n  by (simp add: pmerge_Vis_def emerge_def)\n\nlemma merge_Vis_left [simp]: \"\\<lbrakk> e \\<notin> E; e \\<in> pdom F; e \\<notin> pdom G \\<rbrakk> \\<Longrightarrow> merge_Vis F E G(e)\\<^sub>p = par (F(e)\\<^sub>p) E (Vis G)\"\n  by (simp add: pmerge_Vis_def emerge_def)\n\nlemma merge_Vis_right [simp]: \"\\<lbrakk> e \\<notin> E; e \\<notin> pdom F; e \\<in> pdom G \\<rbrakk> \\<Longrightarrow> merge_Vis F E G(e)\\<^sub>p = par (Vis F) E (G(e)\\<^sub>p)\"\n  by (simp add: pmerge_Vis_def emerge_def)\n\nlemma par_commute: \"par P E Q = (par Q E P) \\<bind> (\\<lambda> (a, b). Ret (b, a))\"\n  apply (coinduction arbitrary: P Q rule: itree_strong_coind)\n     apply (auto elim!: is_RetE unstableE bind_RetE' bind_SilE' stableE simp add: genpar_Ret_iff)\n         apply metis\n        apply metis\n       apply metis\n      apply (metis pdom_emerge_commute)\n     apply (metis pdom_emerge_commute)\n    apply (simp add: emerge_def)\n    apply (auto)\n    apply (rename_tac e F G)\n    apply (rule_tac x=\"F e\" in exI)\n    apply (rule_tac x=\"G e\" in exI)\n    apply (simp)\n    apply (smt (verit, ccfv_threshold) map_pfun_apply merge_Vis_both pdom.rep_eq pdom_emerge_commute pdom_map_pfun pdom_pmerge_Vis pfun_app.rep_eq)\n   apply (metis (no_types, lifting) map_pfun_apply merge_Vis_left merge_Vis_right pdom.rep_eq pdom_emerge_commute pdom_map_pfun pdom_pmerge_Vis pfun_app.rep_eq)\n  apply (metis (no_types, lifting) map_pfun_apply merge_Vis_left merge_Vis_right pdom.rep_eq pdom_emerge_commute pdom_map_pfun pdom_pmerge_Vis pfun_app.rep_eq)\n  done  \n\nconsts \n  interleave :: \"'a \\<Rightarrow> 'a \\<Rightarrow> 'a\" (infixl \"\\<interleave>\" 55)\n  gparallel :: \"'a \\<Rightarrow> 'e set \\<Rightarrow> 'a \\<Rightarrow> 'a\" (\"_ \\<parallel>\\<^bsub>_\\<^esub> _\" [55, 0, 56] 56)\n\ndefinition \"gpar_csp P cs Q \\<equiv> par P cs Q \\<bind> (\\<lambda> (x, y). Ret ())\"\n\nabbreviation inter_csp :: \"('e, unit) itree \\<Rightarrow> ('e, unit) itree \\<Rightarrow> ('e, unit) itree\" where\n\"inter_csp P Q \\<equiv> gpar_csp P {} Q\"\n\nadhoc_overloading gparallel gpar_csp and interleave inter_csp\n\nlemma gpar_csp_commute: \"P \\<parallel>\\<^bsub>E\\<^esub> Q = Q \\<parallel>\\<^bsub>E\\<^esub> P\"\nproof -\n  have \"P \\<parallel>\\<^bsub>E\\<^esub> Q = (par P E Q \\<bind> (\\<lambda>(x, y). Ret ()))\"\n    by (simp add: gpar_csp_def)\n  also have \"... = (par Q E P \\<bind> (\\<lambda>(x, y). Ret (y, x))) \\<bind> (\\<lambda>(x, y). Ret ())\"\n    by (metis par_commute)\n  also have \"... = par Q E P \\<bind> (\\<lambda>(x, y). Ret ())\"\n    by (simp add: bind_itree_assoc[THEN sym])\n       (metis (full_types) case_prod_beta' old.unit.exhaust)\n  also have \"... = Q \\<parallel>\\<^bsub>E\\<^esub> P\"\n    by (simp add: gpar_csp_def)\n  finally show ?thesis .\nqed\n\nlemma gpar_csp_diverge: \"diverge \\<parallel>\\<^bsub>E\\<^esub> P = diverge\"\n  by (metis bind_diverge gpar_csp_def genpar_diverge)\n\nlemma interleave_commute:\n  fixes P :: \"('e, unit) itree\"\n  shows \"P \\<interleave> Q = Q \\<interleave> P\"\n  by (simp add: gpar_csp_commute)\n\nlemma skip_interleave: \"skip \\<interleave> P = P\"\nproof (coinduction arbitrary: P rule: itree_coind)\n  case wform\n  then show ?case by (auto simp add: gpar_csp_def skip_def)\nnext\n  case Ret\n  then show ?case\n    by (auto simp add: gpar_csp_def skip_def)\nnext\n  case Sil\n  then show ?case \n    by (auto simp add: gpar_csp_def skip_def)\nnext\n  case Vis\n  then show ?case\n    by (auto simp add: gpar_csp_def skip_def)\nqed\n\ndefinition Interleave :: \"'i set \\<Rightarrow> ('i \\<Rightarrow> ('e, unit) itree) \\<Rightarrow> ('e, unit) itree\" where\n\"Interleave I P = Finite_Set.fold (\\<interleave>) skip (P ` I)\"\n\nsubsection \\<open> Hiding \\<close>\n\ntext \\<open> Could we prioritise events to keep determinism? \\<close>\n\ncorec hide :: \"('e, 'a) itree \\<Rightarrow> 'e set \\<Rightarrow> ('e, 'a) itree\" (infixl \"\\<setminus>\" 90) where\n\"hide P A = \n  (case P of\n    Vis F \\<Rightarrow> \n      \\<comment> \\<open> If precisely one event in the hidden set is enabled, this becomes a silent event \\<close>\n      if (card (A \\<inter> pdom(F)) = 1) then Sil (hide (F (the_elem (A \\<inter> pdom(F)))) A)\n      \\<comment> \\<open> If no event is in the hidden set, then the process continues as normal \\<close>\n      else if (A \\<inter> pdom(F)) = {} then Vis (map_pfun (\\<lambda> X. hide X A) F)\n      \\<comment> \\<open> Otherwise, there are multiple hidden events present and we deadlock \\<close>\n      else deadlock |\n    Sil P \\<Rightarrow> Sil (hide P A) |\n    Ret x \\<Rightarrow> Ret x)\"\n\nlemma is_Ret_loop [simp]: \"is_Ret (loop F s) = False\"\n  by (metis bind_itree.disc_iff(1) comp_apply itree.disc(2) iterate.code)\n\nlemma is_Ret_hide [simp]: \"is_Ret (P \\<setminus> A) = is_Ret P\"\n  by (auto simp add: hide.code deadlock_def itree.case_eq_if)\n\nlemma is_Sil_hide [simp]: \"is_Sil (hide P E) = (is_Sil P \\<or> (is_Vis P \\<and> card (E \\<inter> pdom(un_Vis P)) = 1))\"\n  by (auto elim!: stableE simp add: hide.code deadlock_def itree.case_eq_if)\n\nlemma is_Vis_hide [simp]: \"is_Vis (hide P E) = (is_Vis P \\<and> (card (E \\<inter> pdom(un_Vis P)) \\<noteq> 1 \\<or> E \\<inter> pdom(un_Vis P) = {}))\"\n  by (auto elim!: stableE simp add: hide.code itree.case_eq_if deadlock_def)\n\nlemma hide_Sil [simp]: \"(\\<tau> P) \\<setminus> A = \\<tau> (P \\<setminus> A)\"\n  by (metis (no_types, lifting) hide.code itree.simps(11))\n\nlemma hide_sync: \"(sync a \\<bind> P) \\<setminus> {build\\<^bsub>a\\<^esub> ()} = \\<tau> (P ()) \\<setminus> {build\\<^bsub>a\\<^esub> ()}\"\n  by (simp add: sync_def hide.code)\n\nlemma hide_sync_loop_diverge: \"hide (iter (sync a)) {build\\<^bsub>a\\<^esub> ()} = diverge\"\n  apply (coinduction rule:itree_coind, auto)\n  apply (simp add: iterate.code, simp add: sync_def)\n  apply (metis One_nat_def hide_sync is_Sil_hide itree.disc(5) iterate.code)\n  apply (metis One_nat_def hide_sync is_Sil_hide itree.disc(5) itree.distinct_disc(6) iterate.code)\n  apply (smt (z3) disjoint_iff empty_iff hide_sync insert_iff is_Vis_hide itree.disc(8) iterate.code)\n  apply (smt (z3) Sil_Sil_drop comp_apply hide_Sil hide_sync itree.inject(2) iterate.code)\n  apply (metis diverge.code itree.inject(2))\n  done\n\nlemma hide_empty: \"hide P {} = P\"\n  apply (coinduction arbitrary: P rule: itree_coind)\n     apply (auto)\n      apply (simp add: hide.code)\n     apply (simp add: hide.code)\n    apply (simp add: hide.code)\n   apply (simp add: hide.code)\n  apply (auto simp add: itree.case_eq_if)\n  apply (metis (no_types, lifting) hide.code itree.case_eq_if)\n  oops\n\nsubsection \\<open> Interruption \\<close>\n\nprimcorec interrupt :: \"('e, 'a) itree \\<Rightarrow> ('e, 'a) itree \\<Rightarrow> ('e, 'a) itree\" (infixl \"\\<triangle>\" 59) where\n\"interrupt P Q =\n   (case (P, Q) of\n     (Sil P, _) \\<Rightarrow> Sil (interrupt P Q) |\n     (_, Sil Q) \\<Rightarrow> Sil (interrupt P Q) |\n     (Ret x, _) \\<Rightarrow> Ret x |\n     (_, Ret y) \\<Rightarrow> Ret y |\n     (Vis F, Vis G) \\<Rightarrow> \n        Vis (map_pfun \n              (\\<lambda>x. case x of \n                     Left P' \\<Rightarrow> interrupt P' Q \\<comment> \\<open> Left side acts independently \\<close>\n                   | Right Q' \\<Rightarrow> Q' \\<comment> \\<open> Right side acts independently \\<close>)\n              (emerge (pdom(G) \\<Zndres> F) {} G)))\"\n\nlemma diverge_interrupt_left [simp]: \"diverge \\<triangle> P = diverge\"\n  by (coinduction arbitrary: P, auto, metis diverge.ctr itree.case(2))\n\nlemma diverge_interrupt_right [simp]: \"P \\<triangle> diverge = diverge\"\n  by (coinduction arbitrary: P, auto simp add: itree.case_eq_if, meson itree.exhaust_disc)\n\nlemma Sils_interrupt_left [simp]: \"Sils n P \\<triangle> Q = Sils n (P \\<triangle> Q)\"\n  by (induct n, simp_all add: interrupt.code)\n\nlemma Sil_interrupt_right_stable [simp]: \"stable P \\<Longrightarrow> P \\<triangle> Sil Q = Sil (P \\<triangle> Q)\"\n  by (cases P, simp_all, auto simp add: interrupt.code)\n\nlemma Sils_interrupt_right_stable [simp]: \"stable P \\<Longrightarrow> P \\<triangle> Sils n Q = Sils n (P \\<triangle> Q)\"\n  by (induct n, auto)\n\nlemma Sils_interrupt_right [simp]: \"P \\<triangle> Sils n Q = Sils n (P \\<triangle> Q)\"\nproof (cases \"stabilises P\")\n  case True\n  then obtain m P' where P: \"P = Sils m P'\" \"stable P'\"\n    by (metis stabilises_def)\n  then have \"Sils m P' \\<triangle> Sils n Q = Sils (m + n) (P' \\<triangle> Q)\"\n    by (simp)\n  then show ?thesis\n    by (simp add: P(1) add.commute)\nnext\n  case False\n  then show ?thesis\n    by (metis Sils_diverge diverge_interrupt_left diverges_then_diverge)\nqed\n\nlemma deadlock_interrupt_stable: \"stable P \\<Longrightarrow> deadlock \\<triangle> P = P\"\n  by (cases P, simp_all add: deadlock_def interrupt.code emerge_def pfun_eq_iff)\n\nlemma deadlock_interrupt: \"deadlock \\<triangle> P = P\"\nproof (cases \"stabilises P\")\n  case True\n  then show ?thesis\n    by (metis Sils_interrupt_right deadlock_interrupt_stable stabilises_def)\nnext\n  case False\n  then show ?thesis\n    by (metis diverge_interrupt_right diverges_then_diverge)\nqed\n\nsubsection \\<open> Exception \\<close>\n\nprimcorec exception :: \"('e, 'a) itree \\<Rightarrow> 'e set \\<Rightarrow> ('e, 'a) itree \\<Rightarrow> ('e, 'a) itree\" (infixl \"\\<lbrakk>_\\<Zrres>\" 65) where\n\"exception P A Q =\n  (case P of\n    Ret x  \\<Rightarrow> Ret x |\n    Sil P' \\<Rightarrow> Sil (exception P' A Q) |\n    Vis F  \\<Rightarrow> \n      Vis (map_pfun \n              (\\<lambda>x. case x of \n                     Left P' \\<Rightarrow> exception P' A Q \\<comment> \\<open> Left side acts independently \\<close>\n                   | Right Q' \\<Rightarrow> Q' \\<comment> \\<open> Right side acts independently \\<close>)\n              (emerge \n                \\<comment> \\<open> Non-exceptional behaviours from @{term P}\\<close>\n                (A \\<Zndres> F)\n                \\<comment> \\<open> No synchronisation\\<close> \n                {} \n                \\<comment> \\<open> Exceptional behaviours: events in @{term A} enables by @{term P}, leading to @{term Q}\\<close>\n                (pfun_entries (A \\<inter> pdom(F)) ((\\<lambda> _. Q))))))\"\n\nsubsection \\<open> Renaming \\<close>\n\ntext \\<open> We define notation for writing renaming relations \\<close>\n\ndefinition rncollect :: \"('a \\<Longrightarrow>\\<^sub>\\<triangle> 'e\\<^sub>1) \\<Rightarrow> ('b \\<Longrightarrow>\\<^sub>\\<triangle> 'e\\<^sub>2) \\<Rightarrow> 'c set \\<Rightarrow> ('c \\<Rightarrow> ('a \\<times> 'b) \\<times> bool) \\<Rightarrow> 'e\\<^sub>1 \\<leftrightarrow> 'e\\<^sub>2\" where\n\"rncollect c\\<^sub>1 c\\<^sub>2 A f = {(build\\<^bsub>c\\<^sub>1\\<^esub> (fst (fst (f x))), build\\<^bsub>c\\<^sub>2\\<^esub> (snd (fst (f x)))) | x. x \\<in> A \\<and> snd (f x)}\"\n \nsyntax \n  \"_rncollect\"    :: \"evt \\<Rightarrow> evt \\<Rightarrow> pttrn \\<Rightarrow> logic \\<Rightarrow> logic \\<Rightarrow> logic\" (\"\\<lbrace>_ \\<mapsto> _ | _ \\<in> _./ _\\<rbrace>\")\n  \"_rncollect_ns\" :: \"evt \\<Rightarrow> evt \\<Rightarrow> pttrn \\<Rightarrow> logic \\<Rightarrow> logic\" (\"\\<lbrace>_ \\<mapsto> _ | _./ _\\<rbrace>\")\n\ntranslations \n  \"_rncollect (_evt_param c\\<^sub>1 v\\<^sub>1) (_evt_param c\\<^sub>2 v\\<^sub>2) x A P\" == \"CONST rncollect c\\<^sub>1 c\\<^sub>2 A (\\<lambda> x. ((v\\<^sub>1, v\\<^sub>2), P))\"\n  \"_rncollect (_evt_id c\\<^sub>1) (_evt_param c\\<^sub>2 v\\<^sub>2) x A P\" == \"CONST rncollect c\\<^sub>1 c\\<^sub>2 A (\\<lambda> x. (((), v\\<^sub>2), P))\"\n  \"_rncollect (_evt_param c\\<^sub>1 v\\<^sub>1) (_evt_id c\\<^sub>2) x A P\" == \"CONST rncollect c\\<^sub>1 c\\<^sub>2 A (\\<lambda> x. ((v\\<^sub>1, ()), P))\"\n  \"_rncollect (_evt_id c\\<^sub>1) (_evt_id c\\<^sub>2) x A P\" == \"CONST rncollect c\\<^sub>1 c\\<^sub>2 A (\\<lambda> x. (((), ()), P))\"\n  \"_rncollect_ns e\\<^sub>1 e\\<^sub>2 x P\" == \"_rncollect e\\<^sub>1 e\\<^sub>2 x (CONST UNIV) P\"\n\nprimcorec rename :: \"('e\\<^sub>1 \\<leftrightarrow> 'e\\<^sub>2) \\<Rightarrow> ('e\\<^sub>1, 'a) itree \\<Rightarrow> ('e\\<^sub>2, 'a) itree\" where\n\"rename \\<rho> P = \n  (case P of\n    Ret x \\<Rightarrow> Ret x |\n    Sil P \\<Rightarrow> Sil (rename \\<rho> P) |\n    Vis F \\<Rightarrow> Vis (map_pfun (rename \\<rho>) (F \\<circ>\\<^sub>p graph_pfun ((pdom F \\<lhd>\\<^sub>r \\<rho>)\\<inverse>))))\"\n\nabbreviation rename':: \"('e\\<^sub>1, 'a) itree \\<Rightarrow> ('e\\<^sub>1 \\<leftrightarrow> 'e\\<^sub>2) \\<Rightarrow> ('e\\<^sub>2, 'a) itree\" (\"_\\<lbrace>_\\<rbrace>\" 59) where\n\"rename' P \\<rho> \\<equiv> rename \\<rho> P\"\n\nlemma rename_deadlock [simp]: \"rename \\<rho> deadlock = deadlock\"\n  by (simp add: deadlock_def rename.code)\n\nsubsection \\<open> Restriction \\<close>\n\ntext \\<open> Restrict the events that an ITree can perform to a subset \\<close>\n\nprimcorec evres :: \"'e set \\<Rightarrow> ('e, 's) itree \\<Rightarrow> ('e, 's) itree\" where\n\"evres E P = \n  (case P of\n     Ret x \\<Rightarrow> Ret x | Sil P' \\<Rightarrow> Sil (evres E P') | Vis F \\<Rightarrow> Vis (map_pfun (evres E) (E \\<Zdres> F)))\"\n\nend", "meta": {"author": "isabelle-utp", "repo": "interaction-trees", "sha": "90510d119364f534d2ab61daf2f274060f0a040e", "save_path": "github-repos/isabelle/isabelle-utp-interaction-trees", "path": "github-repos/isabelle/isabelle-utp-interaction-trees/interaction-trees-90510d119364f534d2ab61daf2f274060f0a040e/UTP/ITree_CSP.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5851011542032312, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.2811286290958731}}
{"text": "subsection \\<open>Strong Convergence\\<close>\n\ntheory StrongConvergence\n  imports IntegrateInsertCommute CreateConsistent HOL.Finite_Set DistributedExecution\nbegin\n\nlemma  (in dist_execution) happened_before_same:\n  assumes \"i < j\"\n  assumes \"j < length (events k)\"\n  shows \"(happened_immediately_before)\\<^sup>+\\<^sup>+ (k,i) (k,j)\" \nproof -\n  obtain v where v_def: \"j = Suc i + v\" using assms(1) less_iff_Suc_add by auto\n  have \"is_valid_event_id (k, Suc i + v) \\<longrightarrow> (happened_immediately_before)\\<^sup>+\\<^sup>+ (k,i) (k, Suc i + v)\"\n    apply (induction v, simp add: tranclp.r_into_trancl)\n    by (metis Suc_lessD add_Suc_right fst_conv happened_immediately_before.elims(3) \n        is_valid_event_id.simps snd_conv tranclp.simps)\n  then show ?thesis\n    using is_valid_event_id.simps v_def assms by blast\nqed\n\ndefinition make_set where \"make_set (k :: nat) p = {x. \\<exists>j. p j x \\<and> j < k}\"\n\nlemma make_set_nil [simp]: \"make_set 0 p = {}\" by (simp add:make_set_def)\n\nlemma make_set_suc [simp]: \"make_set (Suc k) p = make_set k p \\<union> {x. p k x}\"\n  using less_Suc_eq by (simp add:make_set_def, blast)\n\nlemma (in dist_execution) received_messages_eff:\n  assumes \"is_valid_state_id (i,j)\"\n  shows \"set (received_messages (i,j)) = make_set j (\\<lambda>k x. (\\<exists>s. event_at (i, k) (Receive s x)))\" \n  using assms by (induction j, simp add:make_set_def, simp add: take_Suc_conv_app_nth)\n\nlemma (in dist_execution) finite_valid_event_ids:\n  \"finite {i. is_valid_event_id i}\"\nproof -\n  define X where \"X = {p. events p = events p}\"\n  have \"finite X \\<Longrightarrow> \\<exists>m. (\\<forall>p \\<in> X. (length (events p)) < m)\" \n    apply (induction rule:finite_induct, simp)\n    by (metis gt_ex insert_iff le_less_trans less_imp_not_less not_le_imp_less)\n  then obtain m where m_def: \"\\<And>p. length (events p) < m\" using X_def fin_peers by auto\n  have \"{(i,j). is_valid_event_id (i,j)} \\<subseteq> {(i,j). j < m}\" \n    using m_def by (simp add: Collect_mono_iff less_trans)\n  also have \"... \\<subseteq> X \\<times> {j. j < m}\" using X_def by blast\n  finally have \"{i. is_valid_event_id i} \\<subseteq> X \\<times> {j. j < m}\" \n    by (simp add: subset_iff)\n  thus ?thesis\n    using fin_peers finite_Collect_less_nat finite_cartesian_product\n        infinite_super subset_eq\n    by (metis UNIV_I)\nqed\n\nlemma (in dist_execution) send_insert_id_1:\n  \"state i \\<bind> (\\<lambda>s. create_insert s n \\<sigma> i) = Inr (Insert m) \\<Longrightarrow> I m = i\"\n  by fastforce\n\nlemma (in dist_execution) send_insert_id_2:\n  \"state i \\<bind> (\\<lambda>s. create_delete s n) = Inr (Insert m) \\<Longrightarrow> False\"\n  by fastforce\n\nlemma (in dist_execution) send_insert_id:\n  \"event_at i (Send (Insert m)) \\<Longrightarrow> I m = i\" \n  using send_correct send_insert_id_1 send_insert_id_2 by metis\n\nlemma (in dist_execution) recv_insert_once:\n  \"event_at (i,j) (Receive s (Insert m)) \\<Longrightarrow> event_at (i,k) (Receive t (Insert m)) \\<Longrightarrow> j = k\"\n  using no_data_corruption send_insert_id at_most_once\n  by (simp, metis (mono_tags) Pair_inject event_pred.simps fst_conv is_valid_event_id.simps)\n\nproposition integrate_insert_commute':\n  fixes M m s\n  assumes \"consistent M\"\n  assumes \"is_delete m \\<or> m \\<notin> T\"\n  assumes \"m \\<in> M\"\n  assumes \"T \\<subseteq> M\"\n  assumes \"deps m \\<subseteq> I ` insert_messages T\" \n  assumes \"is_certified_associated_string T s\"\n  shows \"is_certified_associated_string (T \\<union> {m}) (s \\<bind> (\\<lambda>t. integrate t m))\" \nproof (cases s)\n  case (Inl a)\n  then show ?thesis using assms by simp\nnext\n  case (Inr b)\n  have \"T \\<union> {m} \\<subseteq> M\" using assms(3) assms(4) by simp \n  moreover have \"\\<Union> (deps ` (T \\<union> {m})) \\<subseteq> I ` insert_messages (T \\<union> {m})\" \n    using assms(5) assms(6) Inr apply (simp add:is_associated_string_def consistent_def)\n    by (meson dual_order.trans subset_insertI subset_mono)\n  ultimately have \"consistent (T \\<union> {m})\"\n    using assms consistent_subset by force \n  then show ?thesis using integrate_insert_commute assms(2) assms(6) Inr by auto\nqed\n\nlemma foldM_rev: \"foldM f s (li@[ll]) = foldM f s li \\<bind> (\\<lambda>t. f t ll)\"\n  by (induction li arbitrary:s, simp+)\n\nlemma  (in dist_execution) state_is_associated_string':\n  fixes i M\n  assumes \"j \\<le> length (events i)\"\n  assumes \"consistent M\"\n  assumes \"make_set j (\\<lambda>k m. \\<exists>s. event_at (i,k) (Receive s m)) \\<subseteq> M\"\n  shows \"is_certified_associated_string (make_set j (\\<lambda>k m. \\<exists>s. event_at (i,k) (Receive s m))) (state (i,j))\"\n  using assms\nproof (induction j)\n  case 0\n  then show ?case by (simp add: empty_associated)\nnext\n  case (Suc j)\n  have b:\"j < length (events i)\" using Suc by auto\n  show ?case\n  proof (cases \"events i ! j\")\n    case (Send m)\n    then show ?thesis using Suc by (simp add: take_Suc_conv_app_nth) \n  next\n    case (Receive s m)\n    moreover have \"is_delete m \\<or> m \\<notin> (make_set j (\\<lambda>k m. \\<exists>s. event_at (i,k) (Receive s m)))\"\n      apply (cases m) using recv_insert_once Receive b apply (simp add: make_set_def) \n      apply (metis nat_neq_iff)\n      by (simp)\n    moreover have \"deps m \\<subseteq> I ` insert_messages (make_set j (\\<lambda>k m. \\<exists>s. event_at (i,k) (Receive s m)))\"\n      apply (rule subsetI)\n      using semantic_causal_delivery Receive b apply (simp add:insert_messages_def image_iff make_set_def) by metis\n    ultimately show ?thesis \n      using Suc apply (cases s, simp add:take_Suc_conv_app_nth foldM_rev)\n      using integrate_insert_commute' by fastforce\n  qed  \nqed\n\nlemma  (in dist_execution) sent_before_recv:\n  assumes \"event_at (i,k) (Receive s m)\"\n  assumes \"j < length (events i)\"\n  assumes \"k < j\" \n  shows \"event_at s (Send m) \\<and> happened_immediately_before\\<^sup>+\\<^sup>+ s (i,j)\"\nproof -\n  have a:\"event_at s (Send m)\"\n    using assms no_data_corruption by blast\n  hence \"happened_immediately_before s (i,k)\" \n    using assms by (cases s, simp, metis (mono_tags, lifting) event.simps(6))\n  hence \"(happened_immediately_before)\\<^sup>+\\<^sup>+ s (i,j)\" using happened_before_same \n    by (meson assms(2) assms(3) tranclp_into_tranclp2)\n  thus ?thesis using a by blast\nqed\n\nlemma (in dist_execution) irrefl_p: \"irreflp (happened_immediately_before\\<^sup>+\\<^sup>+)\" \n  by (meson acyclic_def dist_execution.acyclic_happened_before\n      dist_execution_axioms irreflpI tranclp_unfold)\n\n\n\nlemma (in dist_execution) sent_messages_consistent:\n  \"consistent {m. (\\<exists>i. event_at i (Send m))}\"\nproof -\n  obtain ids where ids_def: \"set ids = {i. is_valid_event_id i} \\<and> \n    sorted_wrt (to_ord (happened_immediately_before)) ids \\<and> distinct ids\"\n    using top_sort finite_valid_event_ids  by (metis acyclic_happened_before)\n  have \"\\<And>x y. happened_immediately_before\\<^sup>+\\<^sup>+ x y \\<Longrightarrow> x \\<in> set ids \\<and> y \\<in> set ids\"\n    using converse_tranclpE ids_def tranclp.cases by fastforce\n  hence a:\"\\<And>x y. happened_immediately_before\\<^sup>+\\<^sup>+ x y \\<Longrightarrow>\n    (\\<exists>i j. i < j \\<and> j < length ids \\<and> ids ! i = x \\<and> ids ! j = y)\"\n    by (metis top_sort_eff ids_def  distinct_Ex1 irrefl_p)\n  define n where \"n = length ids\"\n  have \"n \\<le> length ids \\<Longrightarrow> consistent (make_set n (\\<lambda>k x. event_at (ids ! k) (Send x)))\"\n  proof (induction n)\n    case 0\n    then show ?case using empty_consistent by simp\n  next\n    case (Suc n)\n    moreover obtain i j where ij_def: \n      \"ids ! n = (i,j)\" \"n < length ids\"\n      \"is_valid_event_id (i,j)\" \"is_valid_state_id (i,j)\"\n      by (metis Suc.prems Suc_le_lessD ids_def is_valid_event_id.elims(2) is_valid_state_id.simps\n          le_eq_less_or_eq mem_Collect_eq nth_mem)\n    moreover have \"set (received_messages (i,j)) \\<subseteq> make_set n (\\<lambda>k x. event_at (ids ! k) (Send x))\"\n      using ij_def apply (simp add:received_messages_eff del:received_messages.simps, rule_tac subsetI)\n      using sent_before_recv a apply (simp add:make_set_def) \n      by (metis (no_types, hide_lams) distinct_Ex1 ids_def in_set_conv_nth)\n    moreover have \"(i,j) \\<notin> I ` insert_messages (make_set n (\\<lambda>k x. event_at (ids ! k) (Send x)))\"\n        apply (simp add:insert_messages_def image_iff make_set_def del:event_at.simps)  \n        using ids_def le_eq_less_or_eq nth_eq_iff_index_eq send_insert_id  \n        by (metis dual_order.strict_trans1 ij_def(1) ij_def(2) less_not_refl)\n    ultimately show ?case using Suc\n      apply (cases \"events i ! j\")\n      using new_messages_keep_consistency [where i = \"(i,j)\"] by simp+\n  qed\n  moreover have \"make_set n (\\<lambda>k x. event_at (ids ! k) (Send x)) = {x. (\\<exists>i. event_at i (Send x))}\" \n    apply (simp add:make_set_def n_def, rule set_eqI, subst surjective_pairing, simp only:event_pred.simps)\n    using ids_def apply simp \n    by (metis fst_conv in_set_conv_nth is_valid_event_id.simps mem_Collect_eq prod.exhaust_sel snd_conv) \n  ultimately show ?thesis using ids_def n_def by simp\nqed\n\nlemma (in dist_execution) received_messages_were_sent:\n  assumes \"is_valid_state_id (i,j)\"\n  shows \"make_set j (\\<lambda>k m. (\\<exists>s. event_at (i, k) (Receive s m))) \\<subseteq> {m. \\<exists>i. event_at i (Send m)}\"\n  using no_data_corruption by (simp add:make_set_def, rule_tac subsetI, fastforce)\n\nlemma (in dist_execution) state_is_associated_string:\n  assumes \"is_valid_state_id i\"\n  shows \"is_certified_associated_string (set (received_messages i)) (state i)\"\n  using state_is_associated_string' received_messages_eff\n    sent_messages_consistent received_messages_were_sent assms by (cases i, simp)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/WOOT_Strong_Eventual_Consistency/StrongConvergence.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621765008857982, "lm_q2_score": 0.5, "lm_q1q2_score": 0.2810882504428991}}
{"text": "theory Trace_Subset\n\nimports\n  \"Sail.Sail2_state_lemmas\"\n  \"HOL-Eisbach.Eisbach_Tools\"\n  \"Bound_UntilM\"\n\nbegin\n\ntext \\<open>\nShow that an action in the monad can only create trace events\nwithin some set. This tends to be a coarse overapproximation,\nwith no contextual dependency information, but it is useful for\nquickly showing that an action depends on some registers and not\nothers, for instance.\n\nComes with a gadget for proving lots of such theorems with little\nsupervision.\n\\<close>\ndefinition\n  monad_trace_subset :: \"'regv event set \\<Rightarrow> ('regv, 'a, 'e) monad \\<Rightarrow> bool\"\n  where\n  \"monad_trace_subset S m = (\\<forall>t res. (m, t, res) \\<in> Traces \\<longrightarrow> set t \\<subseteq> S)\"\n\nlemmas monad_trace_subsetD = monad_trace_subset_def[THEN iffD1, rule_format]\n\nlemma monad_trace_subset_weaken:\n  \"monad_trace_subset S f \\<Longrightarrow> S \\<subseteq> S' \\<Longrightarrow>\n    monad_trace_subset S' f\"\n  by (auto simp: monad_trace_subset_def)\n\nlemma monad_trace_subset_bind:\n  \"monad_trace_subset S f \\<Longrightarrow>\n    (\\<forall>x t. Run f t x \\<longrightarrow> monad_trace_subset S' (g x)) \\<Longrightarrow>\n    monad_trace_subset (S \\<union> S') (bind f (\\<lambda>x. g x))\"\n  apply (subst monad_trace_subset_def, clarsimp)\n  apply (erule bind_Traces_cases)\n   apply (drule(1) monad_trace_subsetD)\n   apply blast\n  apply (drule spec, drule mp, erule exI)\n  apply (drule(1) monad_trace_subsetD)+\n  apply auto\n  done\n\nlemma monad_trace_subset_bind_simple:\n  \"monad_trace_subset S f \\<Longrightarrow>\n    (\\<And>x. monad_trace_subset S (g x)) \\<Longrightarrow>\n    monad_trace_subset S (bind f (\\<lambda>x. g x))\"\n  by (drule monad_trace_subset_bind, auto)\n\nlemmas monad_trace_subset_bind_backward =\n  monad_trace_subset_bind[where S=S and S'=S for S, simplified]\n\nlemma try_catch_monad_trace_subset:\n  \"monad_trace_subset S f \\<Longrightarrow>\n    (\\<forall>x t. (f, t, Exception x) \\<in> Traces \\<longrightarrow> monad_trace_subset S (g x)) \\<Longrightarrow>\n    monad_trace_subset S (try_catch f (\\<lambda>x. g x))\"\n  apply (subst monad_trace_subset_def, clarsimp)\n  apply (erule try_catch_Traces_cases)\n   apply (drule(1) monad_trace_subsetD)\n   apply blast\n  apply (drule spec, drule mp, erule exI)\n  apply (drule(1) monad_trace_subsetD)+\n  apply auto\n  done\n\nnamed_theorems monad_trace_subset\n\nlemma monad_trace_subset_return[monad_trace_subset]:\n  \"monad_trace_subset {} (return x)\"\n  by (simp add: monad_trace_subset_def return_def)\n\nlemma monad_trace_subset_throw[monad_trace_subset]:\n  \"monad_trace_subset {} (throw x)\"\n  by (simp add: monad_trace_subset_def throw_def)\n\nlemma monad_trace_subset_Fail[monad_trace_subset]:\n  \"monad_trace_subset {} (Fail s)\"\n  by (simp add: monad_trace_subset_def)\n\nlemma monad_trace_subset_Done[monad_trace_subset]:\n  \"monad_trace_subset {} (Done x)\"\n  by (simp add: monad_trace_subset_def)\n\nlemma monad_trace_subset_maybe_fail[monad_trace_subset]:\n  \"monad_trace_subset {} (maybe_fail s x)\"\n  by (simp add: maybe_fail_def monad_trace_subset split: option.split)\n\nlemma read_reg_traces[monad_trace_subset]:\n  \"monad_trace_subset (range (E_read_reg (name r))) (read_reg r)\"\n  apply (clarsimp simp add: monad_trace_subset_def read_reg_def)\n  apply (erule Traces.cases)\n   apply simp\n  apply clarsimp\n  apply (erule T.cases; clarsimp split: option.split_asm)\n  done\n\nlemma write_reg_traces[monad_trace_subset]:\n  \"monad_trace_subset (range (E_write_reg (name r))) (write_reg r x)\"\n  apply (clarsimp simp add: monad_trace_subset_def write_reg_def)\n  apply (erule Traces.cases)\n   apply simp\n  apply clarsimp\n  apply (erule T.cases; clarsimp split: option.split_asm)\n  done\n\nmethod monad_trace_subsetI uses rules = (determ \\<open>\n    intro allI conjI impI monad_trace_subset_bind_simple\n        monad_trace_subset empty_subsetI\n  | rule rules monad_trace_subset\n  | (rule monad_trace_subset_weaken, rule rules monad_trace_subset)\\<close>)+\n\nlemma Read_mem_monad_trace_subset:\n  \"(\\<forall>x. monad_trace_subset {} (f x)) \\<Longrightarrow>\n    monad_trace_subset (range (\\<lambda>(rk, addr, val, sz). E_read_mem rk addr sz val))\n        (Read_mem rk x sz f)\"\n  apply (clarsimp simp: monad_trace_subset_def)\n  apply (erule Traces.cases; clarsimp)\n  apply (erule T.cases; clarsimp)\n  apply fastforce\n  done\n\nlemma read_mem_monad_trace_subset[monad_trace_subset]:\n  \"monad_trace_subset (range (\\<lambda>(rk, addr, val, sz). E_read_mem rk addr sz val))\n    (read_mem dict_Sail2_values_Bitvector_a dict_Sail2_values_Bitvector_b rk addr_sz addr sz)\"\n  apply (simp add: read_mem_def read_mem_bytes_def maybe_fail_def[symmetric])\n  apply (monad_trace_subsetI rules: Read_mem_monad_trace_subset)\n  done\n\nlemma Write_mem_monad_trace_subset:\n  \"(\\<forall>x. monad_trace_subset {} (f x)) \\<Longrightarrow>\n    monad_trace_subset (range (\\<lambda>(wk, addr, val, sz, k). E_write_mem wk addr sz val k))\n        (Write_mem wk x sz v f)\"\n  apply (clarsimp simp: monad_trace_subset_def)\n  apply (erule Traces.cases; clarsimp)\n  apply (erule T.cases; clarsimp)\n  apply fastforce\n  done\nlemma write_mem_monad_trace_subset[monad_trace_subset]:\n  \"monad_trace_subset (range (\\<lambda>(wk, addr, val, sz, k). E_write_mem wk addr sz val k))\n    (write_mem class_a class_b wk addr_sz addr sz v)\"\n  apply (simp add: write_mem_def read_mem_bytes_def maybe_fail_def split: option.split)\n  apply (monad_trace_subsetI rules: Write_mem_monad_trace_subset)\n  done\n\nlemma catch_early_return_trace_subset:\n  \"monad_trace_subset S m \\<Longrightarrow>\n    monad_trace_subset S (catch_early_return m)\"\n  apply (simp add: catch_early_return_def)\n  apply (rule try_catch_monad_trace_subset; clarsimp split: sum.split)\n  apply monad_trace_subsetI\n  done\n\nlemma or_boolM_trace_subset:\n  \"monad_trace_subset S m \\<Longrightarrow> monad_trace_subset S m' \\<Longrightarrow>\n    monad_trace_subset S (or_boolM m m')\"\n  apply (simp add: or_boolM_def)\n  apply (monad_trace_subsetI | simp)+\n  done\n\nlemma and_boolM_trace_subset:\n  \"monad_trace_subset S m \\<Longrightarrow> monad_trace_subset S m' \\<Longrightarrow>\n    monad_trace_subset S (and_boolM m m')\"\n  apply (simp add: and_boolM_def)\n  apply (monad_trace_subsetI | simp)+\n  done\n\nlemma let_trace_subset:\n  \"monad_trace_subset S (f s) \\<Longrightarrow>\n    monad_trace_subset S (Let s f)\"\n  by simp\n\nlemma bound_untilM_trace_subset:\n  \"(\\<forall>vars. monad_trace_subset S (cond vars)) \\<Longrightarrow>\n    (\\<forall>vars. monad_trace_subset S (body vars)) \\<Longrightarrow>\n    monad_trace_subset S (bound_untilM bound vars cond body)\"\n  apply (induct bound vars cond body rule: bound_untilM.induct)\n  apply (subst bound_untilM.simps)\n  apply (intro monad_trace_subset_bind_backward allI impI)\n    apply (monad_trace_subsetI | clarsimp)+\n  done\n\nlemma liftR_trace_subset:\n  \"monad_trace_subset S f \\<Longrightarrow>\n    monad_trace_subset S (liftR f)\"\n  apply (simp add: liftR_def)\n  apply (intro try_catch_monad_trace_subset,\n        (monad_trace_subsetI | simp)+)\n  done\n\nlemma foreachM_monad_trace_subset:\n  \"(\\<And>x vs tr e. x \\<in> set xs \\<Longrightarrow> monad_trace_subset S (body x vs)) \\<Longrightarrow>\n   monad_trace_subset S (foreachM xs vs body)\"\n  by (induct xs arbitrary: vs, (monad_trace_subsetI | simp)+)\n\nlemma genlistM_monad_trace_subset:\n  \"(\\<And>i. i < n \\<Longrightarrow> monad_trace_subset S (f i)) \\<Longrightarrow> monad_trace_subset S (genlistM f n)\"\n  apply (clarsimp simp add: genlistM_def genlist_def)\n  apply (monad_trace_subsetI rules: foreachM_monad_trace_subset | simp)+\n  done\n\nlemma monad_trace_subset_Choose:\n  \"(\\<forall>b. monad_trace_subset S (cont b)) \\<Longrightarrow>\n    monad_trace_subset (range (E_choose nm) \\<union> S) (Choose nm cont)\"\n  apply (clarsimp simp: monad_trace_subset_def)\n  apply (erule Traces.cases; clarsimp)\n  apply (auto elim!: T.cases)\n  done\n\nnamed_theorems monad_trace_subset_intro\n\nlemmas monad_trace_subset_intro_init[monad_trace_subset_intro] =\n    conjI impI allI Un_least monad_trace_subset_bind_simple\n    or_boolM_trace_subset and_boolM_trace_subset\n    catch_early_return_trace_subset let_trace_subset\n    liftR_trace_subset monad_trace_subset_Choose\n    foreachM_monad_trace_subset genlistM_monad_trace_subset\n    bound_untilM_trace_subset\n    if_split[where P=\"monad_trace_subset _\", THEN iffD2]\n    prod.split[where P=\"monad_trace_subset _\", THEN iffD2]\n    option.split[where P=\"monad_trace_subset _\", THEN iffD2]\n    bitU.split[where P=\"monad_trace_subset _\", THEN iffD2]\n\nlemmas monad_trace_subset_Choose_return =\n    monad_trace_subset_Choose[rule_format, OF monad_trace_subset_return, simplified]\n\nML \\<open>\nstructure Monad_Trace_Subset_Exploration = struct\n\nval triv = Thm.trivial @{cprop \"monad_trace_subset S m\"}\n  |> Drule.generalize ([\"'a\", \"'b\", \"'c\"], [\"S\", \"m\"])\n\nfun dest_eq2 t = Logic.dest_equals t\n  handle TERM _ => HOLogic.dest_eq (HOLogic.dest_Trueprop t)\n\nfun is_monadT (Type (@{type_name monad}, _)) = true\n  | is_monadT _ = false\n\nval is_meta_monadT = is_monadT o snd o strip_type\n\nfun is_monad_const t = let\n    val (f, xs) = strip_comb t\n  in is_Const f andalso is_monadT (fastype_of t)\n    andalso not (exists (is_meta_monadT o fastype_of) xs) end\n\nfun add_monad_consts [] xs = xs\n  | add_monad_consts ((f $ x) :: ts) xs = add_monad_consts (f :: x :: ts)\n    ((if is_monad_const (f $ x) then [f $ x] else []) @ xs)\n  | add_monad_consts (Abs (nm, ty, t) :: ts) xs = let\n    val t' = betapply (Abs (nm, ty, t), Var ((suffix \"_bv\" nm, 0), ty))\n  in add_monad_consts (t' :: ts) xs end\n  | add_monad_consts (_ :: ts) xs = add_monad_consts ts xs\n\nfun fetch_by_term ctxt extras term = let\n    val inst = Drule.infer_instantiate ctxt\n        [((\"m\", 0), Thm.cterm_of ctxt term)] triv\n    val thms = Named_Theorems.get ctxt @{named_theorems \"monad_trace_subset\"}\n    val resn = (extras @ thms) RL [inst]\n  in case resn of [] => raise TERM (\"fetch_by_term\", [term])\n    | (t :: _) => t\n  end\n\nfun dest (Const (@{const_name monad_trace_subset}, _) $ S $ m) = (S, m)\n  | dest t = raise TERM (\"monad_trace_subset dest\", [t])\n\nfun strip_un (Const (@{const_name \"Lattices.sup\"}, _) $ x $ y) = maps strip_un [x, y]\n  | strip_un t = [t]\n\nfun mk_un [] = raise TERM (\"monad_trace_subset mk_un: empty\", [])\n  | mk_un (x :: xs) = let\n    val ty = fastype_of x\n    val c = Const (@{const_name \"Lattices.sup\"}, ty --> ty --> ty)\n  in foldr1 (fn (x, y) => c $ x $ y) (x :: xs) end\n\nfun prove ctxt extras defn = let\n    val freeze_defn = Variable.import_vars ctxt defn\n    val prop = Thm.concl_of freeze_defn\n    val (term, expanded) = dest_eq2 prop\n    val sub_fs = add_monad_consts [expanded] []\n        |> sort_distinct Term_Ord.fast_term_ord\n    val sub_thms = map (fetch_by_term ctxt extras) sub_fs\n    val ss = map (Thm.concl_of #> HOLogic.dest_Trueprop #> dest #> fst) sub_thms\n        |> maps strip_un\n        |> sort_distinct Term_Ord.fast_term_ord\n    val ss_frees = fold Term.add_vars ss []\n    val _ = null ss_frees orelse raise TERM (\"monad_trace_subset prove\", ss)\n    val _ = not (null ss) orelse raise THM (\"monad_trace_subset prove: subthms\", 1, sub_thms)\n    val st = mk_un ss\n    val sub_thm_insts = sub_thms RL @{thms monad_trace_subset_weaken}\n    val inst = Drule.infer_instantiate ctxt\n        [((\"m\", 0), Thm.cterm_of ctxt term), ((\"S\", 0), Thm.cterm_of ctxt st)] triv\n    val subset_ss = put_simpset HOL_ss ctxt addsimps @{thms subset_iff mem_simps}\n    val intros = Named_Theorems.get ctxt @{named_theorems monad_trace_subset_intro}\n    val tac = simp_tac (put_simpset HOL_basic_ss ctxt addsimps [defn])\n        THEN_ALL_NEW REPEAT_ALL_NEW (match_tac ctxt\n            (intros @ sub_thm_insts))\n        THEN_ALL_NEW simp_tac subset_ss\n        THEN_ALL_NEW simp_tac ctxt\n    val nms = Term.add_frees (Thm.concl_of inst) [] |> map fst\n    fun tr ctxt = Syntax.pretty_term ctxt term\n      |> (fn p => Pretty.block [Pretty.str \"proving monad_trace_subset for: \", p])\n      |> Pretty.writeln\n  in Goal.prove ctxt nms [] (Thm.concl_of inst) (fn r => (tr (#context r); tac 1))\n  end\n\nfun defn_name defn = Term.term_name (head_of (fst (dest_eq2 (Thm.concl_of defn))))\n\nfun prove_rec thys ctxt extras nm defn = let\n    val thm = prove ctxt extras defn\n  in thm :: extras end\n  handle TERM (\"fetch_by_term\", [tm]) => let\n      val f = head_of tm\n      val _ = is_Const f orelse raise TERM (\"prove_rec: stuck\", [tm])\n      val f_nm = fst (dest_Const f)\n      val q = Long_Name.qualifier f_nm\n      val _ = member (op =) thys q orelse raise TERM (\"prove_rec: not in thys\", [tm])\n      val def2 = Proof_Context.get_thm ctxt (suffix \"_def\" f_nm)\n      val _ = tracing (\"recursing \" ^ nm ^ \" --> \"  ^ f_nm)\n      val extras2 = prove_rec thys ctxt extras f_nm def2\n    in prove_rec thys ctxt extras2 nm defn end\n\nfun install_rec thys defn thy = let\n    val ctxt = Proof_Context.init_global thy\n    val thms = prove_rec thys ctxt [] \"toplevel\" defn\n  in Context.theory_map\n    (fold (Named_Theorems.add_thm @{named_theorems \"monad_trace_subset\"}) thms)\n    thy\n  end\n\nfun install_recs thys = fold (install_rec thys)\n\nend\n\\<close>\n\nlemma choose_bool_monad_trace_subset[monad_trace_subset]:\n  \"monad_trace_subset (range (E_choose s)) (choose_bool s)\"\n  apply (simp add: choose_bool_def)\n  apply (rule monad_trace_subset_Choose_return)\n  done\n\nlemma bool_of_bitU_nondet_monad_trace_subset[monad_trace_subset]:\n  \"monad_trace_subset (range (E_choose ''bool_of_bitU'')) (bool_of_bitU_nondet bitU)\"\n  by (cases bitU, simp_all add: bool_of_bitU_nondet_def, monad_trace_subsetI)\n\nsetup \\<open>Monad_Trace_Subset_Exploration.install_recs\n  [\"Sail2_prompt_monad\", \"Sail2_prompt\"]\n  @{thms early_return_def exit0_def assert_exp_def\n    undefined_bool_def internal_pick_def\n    of_bits_nondet_def}\n\\<close>\n\nend\n", "meta": {"author": "CTSRD-CHERI", "repo": "t-cheri", "sha": "f1874cef52245e1de1654c2a3e2da9b8d10e066c", "save_path": "github-repos/isabelle/CTSRD-CHERI-t-cheri", "path": "github-repos/isabelle/CTSRD-CHERI-t-cheri/t-cheri-f1874cef52245e1de1654c2a3e2da9b8d10e066c/model/isabelle/Trace_Subset.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185351961015, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.2807983026769544}}
{"text": "(*******************************************************************************\n\n  Project: Refining Authenticated Key Agreement with Strong Adversaries\n\n  Module:  Runs.thy (Isabelle/HOL 2016-1)\n  ID:      $Id: Runs.thy 132861 2016-12-21 10:34:41Z csprenge $\n  Author:  Joseph Lallemand, INRIA Nancy <joseph.lallemand@loria.fr>\n           Christoph Sprenger, ETH Zurich <sprenger@inf.ethz.ch>\n  \n  Defines types protocol runs: a run is described by a protocol role, the owner \n  and partner agents, and frame, which maps variables to messages. \n\n  Copyright (c) 2015-2016 Joseph Lallemand and Christoph Sprenger\n  Licence: LGPL\n\n*******************************************************************************)\n\nsection \\<open>Runs\\<close>\n\ntheory Runs imports Messages\nbegin\n\nsubsection \\<open>Type definitions\\<close>\n\n\ndatatype role_t = Init | Resp \n\ndatatype var = Var nat\n\ntype_synonym \n  rid_t = \"fid_t\"\n\ntype_synonym \n  frame = \"var \\<rightharpoonup> msg\" \n\nrecord run_t = \n  role :: role_t\n  owner :: agent\n  partner :: agent\n\ntype_synonym\n  progress_t = \"rid_t \\<rightharpoonup> var set\" \n\n\nfun\n  in_progress :: \"var set option \\<Rightarrow> var \\<Rightarrow> bool\"\nwhere\n  \"in_progress (Some S) x = (x \\<in> S)\"\n |\"in_progress None x = False\"\n\nfun\n  in_progressS :: \"var set option \\<Rightarrow> var set \\<Rightarrow> bool\"\nwhere\n  \"in_progressS (Some S) S' = (S' \\<subseteq> S)\"\n |\"in_progressS None S' = False\"\n\nlemma in_progress_dom [elim]: \"in_progress (r R) x \\<Longrightarrow> R \\<in> dom r\"\nby (cases \"r R\", auto)\n\nlemma in_progress_Some [elim]: \"in_progress r x \\<Longrightarrow> \\<exists> x. r = Some x\"\nby (cases \"r\", auto)\n\nlemma in_progressS_elt [elim]: \"in_progressS r S \\<Longrightarrow> x \\<in> S \\<Longrightarrow> in_progress r x\"\nby (cases r, auto)\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Key_Agreement_Strong_Adversaries/Runs.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6584175139669997, "lm_q2_score": 0.42632159254749025, "lm_q1q2_score": 0.2806976031155707}}
{"text": "theory RB_Relaxed_mike imports RCU_Lems \nbegin\n\ndatatype F = B | W | Q | R \ndatatype Pointer = Head | Tail\n\nconsts n :: nat   (*size of buffer, input*)\nconsts N :: nat   (*number of Arr\\<^sub>W entries*)\n\n(*(Wr T u t b \\<sigma>)*)\n(*\nlemma pval_val:\n  assumes \"wfs \\<sigma>\"\n  and \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  and \"u \\<noteq> v\"\n  and \"var w = x\"\n  and \"ts = getTS \\<sigma> w\"\nshows \"\\<not> [x \\<approx>\\<^sub>t u] (write_trans t b w v \\<sigma> ts) \"\n  sorry\n*)\n\n\nlemma pval_val_same:\n  assumes \"wfs \\<sigma>\"\n  and \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  and \"u \\<noteq> v\"\n  and \"var w = x\"\nshows \"\\<not> [x \\<approx>\\<^sub>t u] (Wr x v t b \\<sigma>)\"\n  using assms\n  apply (simp add: p_obs_def visible_writes_def value_def write_trans_def)\n  apply(simp add: rev_app_def update_modView_def update_mods_def update_thrView_def update_wa_def)\n  apply safe  \n  using w_in_writes_on_var apply blast\n  defer  \n  apply (simp add: getVWNC_var)\n   apply (simp add: getVWNC_var)\n  apply(case_tac \"(a, ba)\n       \\<in> writes_on \\<sigma> x\")\n  apply (smt dual_order.strict_trans getTS_w_greater_tst_w getVWNC_in_visible_writes le_neq_trans less_le_not_le mem_Collect_eq visible_writes_def)\nproof -\nfix a :: nat and ba :: rat\n  assume a1: \"(a, ba) \\<in> writes_on (\\<sigma> \\<lparr>thrView := (thrView \\<sigma>) (t := (thrView \\<sigma> t) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))))), modView := (modView \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))) := (thrView \\<sigma> t) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))))), mods := (mods \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))) := \\<lparr>val = v, is_releasing = b\\<rparr>), writes := insert (var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))) (surrey_state.writes \\<sigma>), write_available := (write_available \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))) := True)\\<rparr>) (var w)\"\n  assume a2: \"x = var w\"\n  assume a3: \"(a, ba) \\<notin> writes_on \\<sigma> x\"\n  assume a4: \"ba \\<noteq> getTS \\<sigma> (getVWNC \\<sigma> t (var w))\"\n  have f5: \"\\<forall>s n p. var p = n \\<and> p \\<in> surrey_state.writes (s::surrey_state) \\<or> p \\<notin> writes_on s n\"\n    using writes_on_def by force\n  have \"\\<forall>s n p. writes_on (write_available_update p (s::surrey_state)) n = writes_on s n\"\n    by (metis (no_types) surrey_state.select_convs(1) surrey_state.surjective surrey_state.update_convs(5) writes_on_def)\n  then have f6: \"(a, ba) \\<in> writes_on (\\<sigma> \\<lparr>thrView := (thrView \\<sigma>) (t := (thrView \\<sigma> t) (x := (x, getTS \\<sigma> (getVWNC \\<sigma> t x)))), modView := (modView \\<sigma>) ((x, getTS \\<sigma> (getVWNC \\<sigma> t x)) := (thrView \\<sigma> t) (x := (x, getTS \\<sigma> (getVWNC \\<sigma> t x)))), mods := (mods \\<sigma>) ((x, getTS \\<sigma> (getVWNC \\<sigma> t x)) := \\<lparr>val = v, is_releasing = b\\<rparr>), writes := insert (x, getTS \\<sigma> (getVWNC \\<sigma> t x)) (surrey_state.writes \\<sigma>)\\<rparr>) x\"\n    using a2 a1 by blast\n  have f7: \"\\<forall>s f. surrey_state.writes (writes_update f (s::surrey_state)) = f (surrey_state.writes s)\"\n    by auto\n  have f8: \"var (a, ba) = x\"\n    using f6 f5 by meson\n  have \"(a, ba) \\<in> surrey_state.writes \\<sigma>\"\n    using f7 f6 f5 a4 a2 by (metis insert_iff snd_conv)\n  then show False\n    using f8 a3 writes_on_def by force\nqed\n\n\n\nlemma pval_val_other:\n  assumes \"wfs \\<sigma>\"\n  and \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  and \"u \\<noteq> v\"\n  and \"var w = x\"\n  and \"t\\<noteq>s\"\nshows \"\\<not> [x \\<approx>\\<^sub>t u] (Wr x v s b \\<sigma>)\"\n  using assms apply simp\n  apply (simp add: p_obs_def visible_writes_def value_def write_trans_def)\n    apply(simp add: rev_app_def update_modView_def update_mods_def update_thrView_def update_wa_def)\n  apply safe  \n  using w_in_writes_on_var\n  apply (simp add: w_in_writes_on_var getVWNC_var) \n  apply (simp add: getVWNC_var)\n\n  apply(case_tac \"(a, ba)\n       \\<in> writes_on \\<sigma> x\")\n  apply (smt dual_order.strict_trans getTS_w_greater_tst_w getVWNC_in_visible_writes le_neq_trans less_le_not_le mem_Collect_eq visible_writes_def)\nproof -\n  fix a :: nat and ba :: rat\n  assume a1: \"ba \\<noteq> getTS \\<sigma> (getVWNC \\<sigma> s (var w))\"\n  assume a2: \"(a, ba) \\<in> writes_on (\\<sigma> \\<lparr>thrView := (thrView \\<sigma>) (s := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), modView := (modView \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), mods := (mods \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := \\<lparr>val = v, is_releasing = b\\<rparr>), writes := insert (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) (surrey_state.writes \\<sigma>), write_available := (write_available \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := True)\\<rparr>) (var w)\"\n  assume a3: \"(a, ba) \\<notin> writes_on \\<sigma> x\"\n  assume a4: \"x = var w\"\n  have \"(a, ba) \\<in> \\<lbrace>\\<acute>var = var w \\<and> \\<acute>(\\<in>) (surrey_state.writes (\\<sigma> \\<lparr>thrView := (thrView \\<sigma>) (s := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), modView := (modView \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), mods := (mods \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := \\<lparr>val = v, is_releasing = b\\<rparr>), writes := insert (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) (surrey_state.writes \\<sigma>), write_available := (write_available \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := True)\\<rparr>))\\<rbrace>\"\n    using a2 writes_on_def by blast\n  then have f5: \"var (a, ba) = var w \\<and> (a, ba) \\<in> surrey_state.writes (\\<sigma> \\<lparr>thrView := (thrView \\<sigma>) (s := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), modView := (modView \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), mods := (mods \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := \\<lparr>val = v, is_releasing = b\\<rparr>), writes := insert (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) (surrey_state.writes \\<sigma>), write_available := (write_available \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := True)\\<rparr>)\"\n    by blast\n  then have \"(a, ba) \\<notin> surrey_state.writes \\<sigma>\"\n    using a4 a3 writes_on_def by fastforce\n  then show False\n    using f5 a1 by simp\nqed\n\n\n\nlemma pval_val:\n  assumes \"wfs \\<sigma>\"\n  and \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  and \"u \\<noteq> v\"\n  and \"var w = x\"\nshows \"\\<not> [x \\<approx>\\<^sub>t u] (Wr x v t' b \\<sigma>)\"\n  using assms apply (cases \"t=t'\")\n  using pval_val_same apply blast\n  using pval_val_other by blast\n\n\n\n\nlemma pval_val_outside:\n  assumes \"wfs \\<sigma>\"\n  and \"N\\<in> \\<nat>\"\n  and \"\\<forall>j.[x \\<approx>\\<^sub>t j] \\<sigma> \\<longrightarrow> j<N\"\n  and \"\\<forall>k. k<N \\<longrightarrow> [x \\<approx>\\<^sub>t k] \\<sigma>\"\n  and \"u\\<in>\\<nat> \\<and> u<N\"\nshows \"\\<forall>z.(z>N\\<longrightarrow>\\<not>[x \\<approx>\\<^sub>t z] (Wr x u t' b \\<sigma>))\"\n  using assms apply (cases \"t=t'\")\n  apply (metis fst_conv not_less_iff_gr_or_eq pval_val)\n  by (metis fst_conv not_less_iff_gr_or_eq pval_val)\n\n\nlemma pval_val_outside_2:\n  assumes \"wfs \\<sigma>\"\n  and \"N \\<in> \\<nat>\"\n  and \"[x =\\<^sub>t 0] \\<sigma>\"\n  and \"u \\<noteq> 0\"\nshows \"\\<exists>i.(([x =\\<^sub>t i] (Wr x u t b \\<sigma>))\\<or>([x =\\<^sub>t i] (Wr x 0 t' b \\<sigma>)))\" \n  using assms apply (cases \"t=t'\")\n  using OpSem_ProofRules.ext_d_obs_d_obs apply blast\n  using OpSem_ProofRules.ext_d_obs_d_obs by blast\n\n\n\n\n\n\n(*\n  assumes \"wfs \\<sigma>\"\n  and \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  and \"u \\<noteq> v\"\n  and \"var w = x\"\nshows \"\\<not> [x \\<approx>\\<^sub>t u] (Wr x v t b \\<sigma>)\"\n\n\nlemma pval_val_all: \n  assumes \"wfs \\<sigma>\"\n  and \"\\<forall>i. i > k \\<longrightarrow> \\<not> [x \\<approx>\\<^sub>t i] \\<sigma>\"\n  and \"k < j\" \n  and \"u \\<le> k\"\n  and \"var w = x\"\nshows \"\\<not> [x \\<approx>\\<^sub>t j] (Wr x v t b \\<sigma>) \"\n  using assms\n  \n  using pval_val sledgehammer\n*)\n\nconsts   \n  H :: L\n  T :: L\n\n\nrecord LB =\n  hW ::  V               (*local copy of W*)\n  tW ::  V               (*local copy of W*)\n  q :: \"(nat \\<times> nat) list\" (*for now assume well synchronised, need to think about weak memory *)\n  tempR :: \"(nat \\<times> nat)\"          (*local copy of word by R*)\n\n  tloc :: V\n  Data:: \"nat  \\<Rightarrow> nat\"     (*returns a word Data_i*)\n  countW :: nat  (* the index of the next element of Data to be written  *)\n  countR :: nat  (* how many words from Data the read has read or reading (i.e., retrieved)  *)\n\n  ownD :: \"nat \\<Rightarrow> F\" (* ownership of data indices *)\n  ownB :: \"nat \\<Rightarrow> F\" (* ownership of bytes in buffer *)\n  (* tries :: nat *)\n  oom :: bool       (*signals W that it was OOM*)\n  \\<sigma> :: surrey_state\n\ndefinition \"global s \\<equiv> wfs s \\<and> H \\<noteq> T\"\n\n\n\n\nlemmas opsemsyntax [simp] =  global_def\nlemmas defs_del [simp del] =  Rd_def Let_def Wr_def Upd_def st_rd_def val_rd_def\n\n(* thread 2 is the writer *)\n(* thread 3 is the reader *)\n\n(* Omit tries *)\n(* Finish queueu + reader *)\n\n(* We need this one to hold at minimum *)\ndefinition \"arrayInv s \\<equiv> \\<forall>i. (i<countR s \\<longrightarrow> ownD s i = R)\\<and> (countR s \\<le> i \\<and> i < countW s \\<longrightarrow> ownD s i = B) \\<and> (countW s \\<le> i \\<and> i < n \\<longrightarrow> ownD s i = W) \"\n\n\ndefinition \"q_entries_bounded s \\<equiv> (\\<forall>i. i < length(q s) \\<longrightarrow> (fst(q s!i)+snd(q s!i)\\<le>N)\\<and>snd(q s!i)>0)\"\ndefinition \"tempR_bounded s \\<equiv> fst (tempR s) + snd (tempR s) \\<le> N\"\ndefinition \"counter_q_rel s \\<equiv> (countW s-countR s=length(q s))\"\ndefinition \"con_assms s  \\<equiv>   0 < N \\<and> 0<n \\<and> (countR s\\<le>countW s) \\<and> (countW s\\<le>n)\n                             \\<and> (\\<forall>i.(i<n)\\<longrightarrow>Data s i\\<le>N \\<and> Data s i>0)\"\n(*new\n(typically)\n\\forall x . P(x) \\<longrightarrow> Q(x)\n\\exists x . P(x) \\<and> Q(x)\n\n[H =\\<^sub>2 i] means thread 2 sees the last write to H and this has value i.\n[H \\<approx>\\<^sub>2 i] means that thread 2 can see the value i.\n*)\ndefinition \"bounded_pointers s \\<equiv> ((\\<forall>i. i > N \\<longrightarrow> \\<not>[H \\<approx>\\<^sub>2 i] (\\<sigma> s)))\\<and>\n                                 ((\\<forall>j. j > N \\<longrightarrow> \\<not>[T \\<approx>\\<^sub>2 j] (\\<sigma> s)))\"\n\ndefinition \"basic_pointer_movement s \\<equiv> 0\\<le>hW s\\<and> hW s\\<le>N \\<and> 0\\<le>tW s\\<and> tW s\\<le>N\"\n\n\n \n\n\ndefinition \"collection s \\<equiv> arrayInv s \\<and> q_entries_bounded s\n                          \\<and>tempR_bounded s \\<and>counter_q_rel s \\<and> con_assms s\n                          \\<and> bounded_pointers s \\<and> basic_pointer_movement s\"\n\n\ndefinition \"init s \\<equiv>\n                     [T =\\<^sub>2 0] (\\<sigma> s) \\<and> [H =\\<^sub>2 0] (\\<sigma> s) \\<and> [T =\\<^sub>3 0] (\\<sigma> s) \\<and> (q s = []) \\<and> (hW s = 0) \\<and> (tW s = 0)\n                        \\<and> (\\<forall>l. (l<n) \\<longrightarrow>  ((Data s l > 0)\\<and>(Data s l \\<le> N)))\n                        \\<and> (\\<forall>i. (i<n) \\<longrightarrow>  ownD s i = W)\n                        \\<and> (\\<forall>i. (i\\<le>N) \\<longrightarrow>  ownB s i = B)\n                        \\<and> (countW s = 0) \\<and> (countR s = 0)\n                        \\<and> (tempR s = (0,0)) \\<and> \\<not> oom s \"\n\ndefinition \"grd1 s \\<equiv> (tW s = hW s) \\<and> (Data s (countW s) \\<le> N) \"\ndefinition \"grd2 s \\<equiv> (tW s > hW s) \\<and> (Data s (countW s) < (tW s - hW s)) \"\ndefinition \"grd3 s \\<equiv> tW s < hW s \"\ndefinition \"grd4 s \\<equiv> Data s (countW s) \\<le> N - hW s \"\ndefinition \"grd5 s \\<equiv> Data s (countW s) < tW s \"\ndefinition \"no_space_for_word s \\<equiv> (grd1 s \\<longrightarrow> \\<not>(Data s (countW s) \\<le> N))\\<and>\n                                  (grd2 s \\<longrightarrow> \\<not>(Data s (countW s) < (tW s - hW s)))\\<and>\n                                  (grd3 s \\<longrightarrow> \\<not>(Data s (countW s) \\<le> N - hW s \\<or> Data s (countW s) < tW s))\"\n\n\n\nlemmas main_invariant_lemmas = collection_def arrayInv_def q_entries_bounded_def \n                                      counter_q_rel_def tempR_bounded_def con_assms_def\n                                      init_def bounded_pointers_def basic_pointer_movement_def\n                                      pval_val_same pval_val_other pval_val\nlemmas guards = grd1_def grd2_def grd3_def grd4_def grd5_def no_space_for_word_def\n\n\nlemma LoadBuffering:\n \"\\<parallel>-   \\<lbrace> global \\<acute>\\<sigma>  \\<and> \\<acute>collection  \\<and> \\<acute>init \\<rbrace>\nCOBEGIN\n\\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection  \\<and> \\<not> \\<acute>oom \\<and> \\<acute>init\\<rbrace>\n  WHILE \\<acute>countW < n \n   INV \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> (\\<exists> i. [H =\\<^sub>2 i]\\<acute>\\<sigma>)\\<rbrace>\n   DO\n    \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> (\\<exists> i. [H =\\<^sub>2 i]\\<acute>\\<sigma>) \\<and> \\<acute>countW < n\\<rbrace> \\<comment> \\<open>A1\\<close>\n      <\\<acute>hW \\<leftarrow>\\<^sub>2 H\\<acute>\\<sigma>> ;;  \n    \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection  \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n\\<rbrace>\n      <\\<acute>tW \\<leftarrow>\\<^sub>2 T\\<acute>\\<sigma>> ;;\n    \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection  \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n\\<rbrace>\n      IF \\<acute>grd1 \\<comment> \\<open>A2\\<close>\n      THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd1 \\<rbrace> \\<comment> \\<open>A3\\<close>\n            <T :=\\<^sub>2 0 \\<acute>\\<sigma>> ;; \\<comment> \\<open>This might not need to be releasing\\<close>  \n            \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd1 \\<rbrace>\n            \\<langle><H :=\\<^sub>2 (\\<acute>Data \\<acute>countW) \\<acute>\\<sigma>> ,, \\<acute>hW := 0 ,, \\<acute>oom := False ,,\n              (\\<acute>ownB := ( \\<lambda> x. if 0\\<le> x \\<and> x < (\\<acute>Data \\<acute>countW) then W else \\<acute>ownB x ))\\<rangle>\n      ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<not>\\<acute>grd1 \\<rbrace> \n            IF \\<acute>grd2\n            THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd2\\<rbrace> \\<comment> \\<open>A4\\<close>\n                \\<langle><H :=\\<^sub>2 \\<acute>hW + (\\<acute>Data \\<acute>countW) \\<acute>\\<sigma>> ,, \\<acute>oom := False ,,\n                  (\\<acute>ownB := ( \\<lambda> x. if \\<acute>hW \\<le> x \\<and> x < (\\<acute>hW + (\\<acute>Data \\<acute>countW)) then W else \\<acute>ownB x ))\\<rangle>\n            ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<not>\\<acute>grd1 \\<and> \\<not>\\<acute>grd2\\<rbrace>\n                 IF \\<acute>grd3\n                 THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd3 \\<rbrace> \\<comment> \\<open>A5\\<close>\n                      IF \\<acute>grd4\n                      THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd3 \\<and> \\<acute>grd4 \\<rbrace> \\<comment> \\<open>A6\\<close>\n                      \\<langle><H :=\\<^sub>2 \\<acute>hW + (\\<acute>Data \\<acute>countW) \\<acute>\\<sigma>> ,, \\<acute>oom := False ,,\n                         (\\<acute>ownB := ( \\<lambda> x. if \\<acute>hW \\<le> x \\<and> x < (\\<acute>hW + (\\<acute>Data \\<acute>countW)) then W else \\<acute>ownB x ))\\<rangle>\n                      ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd3 \\<and> \\<not>\\<acute>grd4 \\<rbrace>\n                            IF \\<acute>grd5\n                            THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd3 \\<and> \\<acute>grd5 \\<rbrace> \\<comment> \\<open>A7\\<close>\n                              \\<langle><H :=\\<^sub>2 (\\<acute>Data \\<acute>countW) \\<acute>\\<sigma>> ,, \\<acute>hW := 0 ,, \\<acute>oom := False ,,\n                                (\\<acute>ownB := ( \\<lambda> x. if ((0 \\<le> x \\<and> x < (\\<acute>Data \\<acute>countW))\\<or> x\\<ge>T)\\<and>x\\<noteq>N then W else \\<acute>ownB x ))\\<rangle>\n                            ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>no_space_for_word\\<rbrace> \\<comment> \\<open>A8\\<close>\n                                \\<langle>\\<acute>oom := True\\<rangle>\n                                  \\<comment> \\<open>OOM\\<close>\n                            FI\n                      FI\n                 ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>no_space_for_word\\<rbrace>\n                      \\<langle>\\<acute>oom := True\\<rangle>\n                      \\<comment> \\<open>OOM\\<close>\n                 FI\n           FI\n     FI;;\n     \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection  \n        \\<and> ((\\<acute>oom=False \\<and> [H =\\<^sub>2 (\\<acute>hW+(\\<acute>Data \\<acute>countW))]\\<acute>\\<sigma> ) \\<comment> \\<open>\\<and> \\<acute>hW  + \\<acute>Data (\\<acute>countW) \\<le> N\\<close> \n             \\<or> (\\<acute>oom=True \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>no_space_for_word)) \\<and> \\<acute>countW < n\\<rbrace>\n     IF \\<acute>oom=True\n     THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>no_space_for_word \\<and> \\<acute>countW < n\\<rbrace> \\<comment> \\<open>OK\\<close>\n          SKIP\n     ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection  \\<and> \\<acute>countW < n \\<and> [H =\\<^sub>2 (\\<acute>hW+(\\<acute>Data \\<acute>countW))]\\<acute>\\<sigma>\\<rbrace>\n          \\<langle>\\<acute>q := \\<acute>q @ [(\\<acute>hW, (\\<acute>Data \\<acute>countW))],,  \n           \\<acute>ownD := (\\<lambda> x. if x = \\<acute>countW then B else \\<acute>ownD x),, \n           \\<acute>ownB := (\\<lambda> x. if (\\<acute>ownB x = W) then Q else \\<acute>ownB x),,  \n           \\<acute>countW := (\\<acute>countW+1)\\<rangle> \n     FI\n   OD \n    \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>countW = n\\<rbrace>\n\n\\<parallel>\n \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>tempR = (0, 0) \\<rbrace>\n  WHILE \\<acute>countR < n\n  INV \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>tempR=(0,0) \\<rbrace>\n  DO  \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>countR < n \\<and> \\<acute>tempR=(0,0) \\<rbrace>\n      IF \\<acute>countR < \\<acute>countW THEN\n                \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>countR < \\<acute>countW \\<and> \\<acute>tempR=(0,0) \\<rbrace> \\<comment> \\<open>retrieve from Q, dequeue\\<close>\n                \\<langle> \\<acute>tempR  := (fst(hd \\<acute>q),(snd(hd \\<acute>q))) ,,  \n                    \\<acute>ownD := (\\<lambda> x. if x = \\<acute>countR then R else \\<acute>ownD x),, \n                    \\<acute>countR := \\<acute>countR+1,, \n                    ( IF \\<exists>i.(i<(fst(hd \\<acute>q)+snd(hd \\<acute>q)) \\<and> [T =\\<^sub>3 i] \\<acute>\\<sigma>) THEN (\\<acute>ownB := ( \\<lambda> x. if i \\<le> x \\<and> x < (fst(hd \\<acute>q)+(snd(hd \\<acute>q))) then R else \\<acute>ownB x ))\n                      ELSE (\\<acute>ownB := ( \\<lambda> x. if i > x \\<and> x \\<le> (fst(hd \\<acute>q)+(snd(hd \\<acute>q)))\\<or>(x=N) then \\<acute>ownB x else R ))FI),, \n                     \\<acute>q := (tl \\<acute>q) \\<rangle>;;\n                    \\<lbrace> global \\<acute>\\<sigma> \\<and>\\<acute>collection \\<and> \\<acute>countR \\<le> \\<acute>countW  \\<and> \\<acute>tempR\\<noteq>(0,0)\\<rbrace> \\<comment> \\<open>Push T\\<close>\n                    \\<langle><T :=\\<^sub>3 (fst \\<acute>tempR + snd \\<acute>tempR) \\<acute>\\<sigma> > \n                    ,, \\<acute> tempR := (0,0),, \n                   \\<acute>ownB := (\\<lambda> x. if \\<acute>ownB x = R then B else \\<acute>ownD x) \\<rangle>\n      ELSE\n      \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>tempR=(0,0) \\<and> \\<acute>countR < n\\<rbrace>\n      SKIP\n      FI\n  OD\n\\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>countR = n\\<rbrace>\n\n\n\nCOEND\n  \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>countW = n \\<and> \\<acute>countR = n\\<rbrace>\n  \n\n\"\n  apply (oghoare)\n  apply ((simp add: main_invariant_lemmas Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff; force)+)[4]\n  apply ((simp add: guards main_invariant_lemmas Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)[1]\n  apply (metis OpSem_ProofRules.d_obs_read_value OpSem_ProofRules.ext_d_obs_rd_pres d_obs_implies_p_obs le_less_linear)\n  apply auto[1]\n  apply ((simp add: guards main_invariant_lemmas Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)[1]\n  apply clarsimp\n  apply (meson not_less not_pobs_contradiction)\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  using pval_val apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply auto[3]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply auto[3]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply auto[1]\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply auto[1]\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis (no_types, lifting) Suc_diff_le d_obs_implies_p_obs fst_eqD le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply clarsimp\n  apply (simp_all add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)\n          (*129*)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred hd_conv_nth length_0_conv length_tl less_numeral_extra(3) nat.inject nth_tl snd_conv zero_less_diff)\n  apply clarify\n  using pval_val apply auto[1]\n  using OpSem_ProofRules.p_obs_contradiction apply blast\n  apply clarify\n  apply linarith\n  apply (metis (no_types, lifting) less_numeral_extra(3) )\n  using pval_val apply auto[1]\n  apply clarify\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply clarify\n  apply (intro conjI impI)\n  apply (metis getVWNC_var leD pval_val)\n  apply (metis OpSem_ProofRules.ext_write_other_pres_d_obs)\n  apply clarify\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply clarify\n  apply (intro conjI impI)\n  apply (metis getVWNC_var leD pval_val)\n  apply (metis OpSem_ProofRules.ext_write_other_pres_d_obs)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply clarify\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply blast\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply clarify\n  apply (intro conjI impI)\n  apply (metis getVWNC_var leD pval_val)\n  apply (metis OpSem_ProofRules.ext_write_other_pres_d_obs)\n  apply clarify\n  apply blast\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply clarify\n  apply (meson not_less not_pobs_contradiction)\n  apply (meson not_less not_pobs_contradiction)\n  apply (metis fst_conv not_less_iff_gr_or_eq pval_val)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply clarify\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis fst_conv not_less_iff_gr_or_eq pval_val)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply clarify\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis fst_conv not_less_iff_gr_or_eq pval_val)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply clarify\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis fst_conv not_less_iff_gr_or_eq pval_val)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply clarify\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis fst_conv not_less_iff_gr_or_eq pval_val)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply clarify\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis fst_conv not_less_iff_gr_or_eq pval_val)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply clarify\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  by simp\n\n\n\n\n\n\n\n\n(*(simp add: Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff )?)*)", "meta": {"author": "MSemenyuk", "repo": "PhD_Isabelle", "sha": "179f5d346a721b15940a271323e3487f4ea51338", "save_path": "github-repos/isabelle/MSemenyuk-PhD_Isabelle", "path": "github-repos/isabelle/MSemenyuk-PhD_Isabelle/PhD_Isabelle-179f5d346a721b15940a271323e3487f4ea51338/Amazon Ring Buffer/RB_Relaxed_mike.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.658417500561683, "lm_q2_score": 0.4263215925474903, "lm_q1q2_score": 0.2806975974005948}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: GPL-2.0-only\n *)\n\ntheory Lookups_D\nimports\n  \"DSpec.Syscall_D\"\n  \"Lib.OptionMonadND\"\nbegin\n\ntype_synonym 'a lookup = \"cdl_state \\<Rightarrow> 'a option\"\n\ndefinition\n  opt_cnode :: \"cdl_object_id \\<Rightarrow> cdl_cnode lookup\"\nwhere\n  \"opt_cnode p \\<equiv> DO\n      t \\<leftarrow> \\<lambda>s. cdl_objects s p;\n      case t of\n        CNode cnode \\<Rightarrow> oreturn cnode\n      | _ \\<Rightarrow> ofail\n   OD\"\n\nfunction resolve_cap ::\n  \"cdl_cap \\<Rightarrow> cdl_cptr \\<Rightarrow> nat \\<Rightarrow> (cdl_fault_error + cdl_cap_ref \\<times> nat) lookup\"\nwhere\n  \"resolve_cap cnode_cap cap_ptr remaining_size =\n  (if is_cnode_cap cnode_cap\n  then DO\n    \\<comment> \\<open>Fetch the next level CNode.\\<close>\n    cnode \\<leftarrow> opt_cnode $ cap_object cnode_cap;\n    radix_size \\<leftarrow> oreturn $ cdl_cnode_size_bits cnode;\n    guard_size \\<leftarrow> oreturn $ cap_guard_size cnode_cap;\n    cap_guard  \\<leftarrow> oreturn $ cap_guard cnode_cap;\n    level_size \\<leftarrow> oreturn (radix_size + guard_size);\n    oassert (level_size \\<noteq> 0);\n\n    \\<comment> \\<open>Ensure the guard matches up.\\<close>\n    guard \\<leftarrow> oreturn $ (cap_ptr >> (remaining_size-guard_size)) && (mask guard_size);\n    if \\<not>(guard_size \\<le> remaining_size \\<and> guard = cap_guard) \\<or>\n       level_size > remaining_size\n    then othrow FaultError\n    else DO\n      \\<comment> \\<open>Find the next slot.\\<close>\n      offset \\<leftarrow> oreturn $ (cap_ptr >> (remaining_size-level_size)) && (mask radix_size);\n      slot \\<leftarrow> oreturn (cap_object cnode_cap, unat offset);\n      size_left \\<leftarrow> oreturn (remaining_size - level_size);\n      if size_left = 0 then\n        oreturnOk (slot, 0)\n      else DO\n        next_cap \\<leftarrow> opt_cap slot;\n        if is_cnode_cap next_cap then\n          resolve_cap next_cap cap_ptr size_left\n        else\n          oreturnOk (slot, size_left)\n      OD\n    OD\n  OD\n  else othrow FaultError)\"\n  by auto\n\ntermination\n  by (relation \"measure (\\<lambda>(a,b,c). c)\") auto\n\ndeclare resolve_cap.simps [simp del]\n\ndeclare resolve_address_bits.simps [simp del]\n\nlemma throwError_FaultError [simp]:\n  \"throwError FaultError = throw\"\n  apply (cases \"undefined::cdl_fault_error\")\n  apply simp\n  done\n\nlemma gets_the_get_cnode:\n  \"gets_the (opt_cnode r) = get_cnode r\"\n  apply (simp add: get_cnode_def opt_cnode_def)\n  apply (rule bind_cong, rule refl)\n  apply (clarsimp split: cdl_object.splits)\n  done\n\nlemma gets_the_resolve_cap:\n  \"gets_the (resolve_cap cnode_cap cap_ptr remaining_size) =\n   resolve_address_bits cnode_cap cap_ptr remaining_size\"\n  apply (induct cnode_cap cap_ptr remaining_size rule: resolve_cap.induct [simplified])\n  apply (subst resolve_cap.simps)\n  apply (subst resolve_address_bits.simps)\n  apply (clarsimp simp: unlessE_def liftE_bindE assertE_liftE gets_the_get_cnode)\n  apply (rule bind_cong, rule refl)\n  apply (rule bind_apply_cong, rule refl)\n  apply (clarsimp simp: liftE_bindE)\n  apply (rule bind_apply_cong, rule refl)\n  apply (clarsimp simp: in_monad gets_the_get_cnode [symmetric])\n  done\n\ndefinition resolve_address_bits' ::\n  \"cdl_cap \\<Rightarrow> cdl_cptr \\<Rightarrow> nat \\<Rightarrow> (cdl_cap_ref \\<times> nat) lookup\"\nwhere\n  \"resolve_address_bits' cap cptr n \\<equiv> odrop $  resolve_cap cap cptr n\"\n\n\n\ndefinition\n  lookup_slot' :: \"cdl_object_id \\<Rightarrow> cdl_cptr \\<Rightarrow> cdl_cap_ref lookup\"\nwhere\n  \"lookup_slot' thread cptr \\<equiv>\n    DO\n      cspace_root \\<leftarrow> opt_cap (thread, tcb_cspace_slot);\n      (slot, _) \\<leftarrow> resolve_address_bits' cspace_root cptr word_bits;\n      oreturn slot\n    OD\"\n\ndefinition\n  lookup_cap' :: \"cdl_object_id \\<Rightarrow> cdl_cptr \\<Rightarrow> cdl_cap lookup\"\nwhere\n  \"lookup_cap' thread cptr \\<equiv>\n    DO\n      slot \\<leftarrow> lookup_slot' thread cptr;\n      opt_cap slot\n    OD\"\n\ndefinition\n  lookup_cap_and_slot' :: \"cdl_object_id \\<Rightarrow> cdl_cptr \\<Rightarrow> (cdl_cap \\<times> cdl_cap_ref) lookup\"\nwhere\n  \"lookup_cap_and_slot' thread cptr \\<equiv>\n    DO\n      slot \\<leftarrow> lookup_slot' thread cptr;\n      cap \\<leftarrow> opt_cap slot;\n      oreturn (cap, slot)\n    OD\"\n\ndefinition\n  lookup_object :: \"cdl_object_id \\<Rightarrow> cdl_cptr \\<Rightarrow> cdl_object_id lookup\"\nwhere\n  \"lookup_object thread cptr \\<equiv>\n    DO\n      cap \\<leftarrow> lookup_cap' thread cptr;\n      oreturn $ cap_object cap\n    OD\"\n\ndefinition\n  lookup_extra_caps' :: \"cdl_object_id \\<Rightarrow> cdl_cptr list \\<Rightarrow> (cdl_cap \\<times> cdl_cap_ref) list lookup\"\nwhere\n  \"lookup_extra_caps' thread cptrs \\<equiv>\n     omap (\\<lambda>cptr. lookup_cap_and_slot' thread cptr) cptrs\"\n\nend\n", "meta": {"author": "NICTA", "repo": "l4v", "sha": "3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b", "save_path": "github-repos/isabelle/NICTA-l4v", "path": "github-repos/isabelle/NICTA-l4v/l4v-3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b/proof/sep-capDL/Lookups_D.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.476579651063676, "lm_q1q2_score": 0.28065257645652486}}
{"text": "theory \"FMap-Utils\"\nimports \"FMap-Nominal-HOLCF\" \"HOLCF-Fix-Join-Nominal\" \"DistinctVars\"\nbegin\n\ndefault_sort type\n\ntext {* Lemmas relating @{theory FMap} to the other auxiliary theories. *}\n\nlemma fdom_fix_join_compat:\n  assumes \"fix_on_cond S (bottom_of S) (\\<lambda>\\<rho>'. \\<rho> \\<squnion> F \\<rho>')\"\n  assumes \"\\<rho>' \\<in> fix_join_compat \\<rho> F\"\n  shows \"fdom \\<rho>' = fdom \\<rho>\"\n  by (metis assms(2) bottom_of_fjc fmap_below_dom subpcpo.bottom_of_minimal subpcpo_fjc to_bot_minimal)\n\nlemma sharp_star_Env': \"atom ` heapVars \\<Gamma> \\<sharp>* (\\<rho> :: 'var::{cont_pt,at_base} f\\<rightharpoonup> 'value::{pure_cpo,Nonempty_Meet_cpo,pcpo}) \\<longleftrightarrow> heapVars \\<Gamma> \\<inter> fdom \\<rho> = {}\"\n  by(induct \\<Gamma>, auto simp add: fresh_star_def sharp_Env)\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Launchbury/FMap-Utils.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.640635854839898, "lm_q2_score": 0.43782349911420193, "lm_q1q2_score": 0.2804854316240221}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\nsection \"64-Bit Machine Word Setup\"\n\ntheory Machine_Word_64\nimports Machine_Word_64_Basics More_Word Bit_Shifts_Infix_Syntax Rsplit\nbegin\n\ncontext\n  includes bit_operations_syntax\nbegin\n\ntype_synonym machine_word = \\<open>machine_word_len word\\<close>\n\nlemma word_bits_len_of:\n  \\<open>LENGTH(machine_word_len) = word_bits\\<close>\n  by (simp add: word_bits_conv)\n\nlemma word_bits_size:\n  \"size (w :: machine_word) = word_bits\"\n  by (simp add: word_bits_def word_size)\n\nlemma word_bits_word_size_conv:\n  \\<open>word_bits = word_size * 8\\<close>\n  by (simp add: word_bits_def word_size_def)\n\nlemma word_size_word_size_bits:\n  \\<open>word_size = (2 :: 'a :: semiring_1) ^ word_size_bits\\<close>\n  by (simp add: word_size_def word_size_bits_def)\n\nlemma lt_word_bits_lt_pow:\n  \"sz < word_bits \\<Longrightarrow> sz < 2 ^ word_bits\"\n  by (simp add: word_bits_conv)\n\nlemma if_then_1_else_0:\n  \"((if P then 1 else 0) = (0 :: machine_word)) = (\\<not> P)\"\n  by simp\n\nlemma if_then_0_else_1:\n  \"((if P then 0 else 1) = (0 :: machine_word)) = (P)\"\n  by simp\n\nlemmas if_then_simps = if_then_0_else_1 if_then_1_else_0\n\nlemma bool_mask [simp]:\n  \\<open>0 < x AND 1 \\<longleftrightarrow> x AND 1 = 1\\<close> for x :: machine_word\n  by (rule bool_mask') auto\n\nlemma in_16_range:\n  \"0 \\<in> S \\<Longrightarrow> r \\<in> (\\<lambda>x. r + x * (16 :: machine_word)) ` S\"\n  \"n - 1 \\<in> S \\<Longrightarrow> (r + (16 * n - 16)) \\<in> (\\<lambda>x :: machine_word. r + x * 16) ` S\"\n  by (clarsimp simp: image_def elim!: bexI[rotated])+\n\nlemma le_step_down_word_3:\n  fixes x :: machine_word\n  shows \"\\<lbrakk>x \\<le> y; x \\<noteq> y\\<rbrakk> \\<Longrightarrow> x \\<le> y - 1\"\n  by (fact le_step_down_word_2)\n\nlemma shiftr_1:\n  \"(x::machine_word) >> 1 = 0 \\<Longrightarrow> x < 2\"\n  apply transfer\n  apply (simp add: take_bit_drop_bit)\n  apply (simp add: drop_bit_Suc)\n  done\n\nlemma Suc_unat_mask_div:\n  \"Suc (unat (mask sz div word_size :: machine_word)) = 2 ^ (min sz word_bits - word_size_bits)\"\n  by (simp add: word_size_word_size_bits unat_drop_bit_eq unat_mask_eq drop_bit_mask_eq Suc_mask_eq_exp\n    flip: drop_bit_eq_div word_bits_conv)\n\nlemma ucast_not_helper:\n  fixes a::\"8 word\"\n  assumes a: \"a \\<noteq> 0xFF\"\n  shows \"ucast a \\<noteq> (0xFF::machine_word)\"\nproof\n  assume \"ucast a = (0xFF::machine_word)\"\n  also\n  have \"(0xFF::machine_word) = ucast (0xFF::8 word)\" by simp\n  finally\n  show False using a\n    apply -\n    apply (drule up_ucast_inj, simp)\n    apply simp\n    done\nqed\n\nlemma unat_less_2p_word_bits:\n  \"unat (x :: machine_word) < 2 ^ word_bits\"\n  apply (simp only: word_bits_def)\n  apply (rule unat_lt2p)\n  done\n\nlemma unat_less_word_bits:\n  fixes y :: machine_word\n  shows \"x < unat y \\<Longrightarrow> x < 2 ^ word_bits\"\n  unfolding word_bits_def\n  by (rule order_less_trans [OF _ unat_lt2p])\n\nlemma unat_mask_2_less_4:\n  \"unat (p AND mask 2 :: machine_word) < 4\"\n  by (rule unat_less_helper) (simp only: take_bit_eq_mod word_mod_less_divisor flip: take_bit_eq_mask, simp add: word_mod_less_divisor)\n\nlemma unat_mult_simple:\n  \\<open>unat (x * y) = unat x * unat y\\<close>\n    if \\<open>unat x * unat y < 2 ^ LENGTH(machine_word_len)\\<close>\n    for x y :: machine_word\n  using that by (simp flip: unat_mult_lem)\n\nlemma upto_2_helper:\n  \"{0..<2 :: machine_word} = {0, 1}\"\n  by (safe; simp) unat_arith\n\nlemma word_ge_min:\n  \\<open>- (2 ^ (word_bits - 1)) \\<le> sint x\\<close> for x :: machine_word\n  using sint_ge [of x] by (simp add: word_bits_def)\n\nlemma word_rsplit_0:\n  \"word_rsplit (0 :: machine_word) = replicate (word_bits div 8) (0 :: 8 word)\"\n  by (simp add: word_rsplit_def bin_rsplit_def word_bits_def word_size_def Cons_replicate_eq)\n\nlemma x_less_2_0_1:\n  fixes x :: machine_word\n  shows \"x < 2 \\<Longrightarrow> x = 0 \\<or> x = 1\"\n  by (rule x_less_2_0_1') auto\n\nend\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Word_Lib/Machine_Word_64.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6406358411176238, "lm_q2_score": 0.43782349911420193, "lm_q1q2_score": 0.28048542561608797}}
{"text": "(*  Title:      HOL/Auth/Guard/Guard_Yahalom.thy\n    Author:     Frederic Blanqui, University of Cambridge Computer Laboratory\n    Copyright   2002  University of Cambridge\n*)\n\nsection\\<open>Yahalom Protocol\\<close>\n\ntheory Guard_Yahalom imports \"../Shared\" Guard_Shared begin\n\nsubsection\\<open>messages used in the protocol\\<close>\n\nabbreviation (input)\n  ya1 :: \"agent => agent => nat => event\" where\n  \"ya1 A B NA == Says A B \\<lbrace>Agent A, Nonce NA\\<rbrace>\"\n\nabbreviation (input)\n  ya1' :: \"agent => agent => agent => nat => event\" where\n  \"ya1' A' A B NA == Says A' B \\<lbrace>Agent A, Nonce NA\\<rbrace>\"\n\nabbreviation (input)\n  ya2 :: \"agent => agent => nat => nat => event\" where\n  \"ya2 A B NA NB == Says B Server \\<lbrace>Agent B, Ciph B \\<lbrace>Agent A, Nonce NA, Nonce NB\\<rbrace>\\<rbrace>\"\n\nabbreviation (input)\n  ya2' :: \"agent => agent => agent => nat => nat => event\" where\n  \"ya2' B' A B NA NB == Says B' Server \\<lbrace>Agent B, Ciph B \\<lbrace>Agent A, Nonce NA, Nonce NB\\<rbrace>\\<rbrace>\"\n\nabbreviation (input)\n  ya3 :: \"agent => agent => nat => nat => key => event\" where\n  \"ya3 A B NA NB K ==\n    Says Server A \\<lbrace>Ciph A \\<lbrace>Agent B, Key K, Nonce NA, Nonce NB\\<rbrace>,\n                    Ciph B \\<lbrace>Agent A, Key K\\<rbrace>\\<rbrace>\"\n\nabbreviation (input)\n  ya3':: \"agent => msg => agent => agent => nat => nat => key => event\" where\n  \"ya3' S Y A B NA NB K ==\n    Says S A \\<lbrace>Ciph A \\<lbrace>Agent B, Key K, Nonce NA, Nonce NB\\<rbrace>, Y\\<rbrace>\"\n\nabbreviation (input)\n  ya4 :: \"agent => agent => nat => nat => msg => event\" where\n  \"ya4 A B K NB Y == Says A B \\<lbrace>Y, Crypt K (Nonce NB)\\<rbrace>\"\n\nabbreviation (input)\n  ya4' :: \"agent => agent => nat => nat => msg => event\" where\n  \"ya4' A' B K NB Y == Says A' B \\<lbrace>Y, Crypt K (Nonce NB)\\<rbrace>\"\n\n\nsubsection\\<open>definition of the protocol\\<close>\n\ninductive_set ya :: \"event list set\"\nwhere\n\n  Nil: \"[]:ya\"\n\n| Fake: \"[| evs:ya; X:synth (analz (spies evs)) |] ==> Says Spy B X # evs:ya\"\n\n| YA1: \"[| evs1:ya; Nonce NA ~:used evs1 |] ==> ya1 A B NA # evs1:ya\"\n\n| YA2: \"[| evs2:ya; ya1' A' A B NA:set evs2; Nonce NB ~:used evs2 |]\n  ==> ya2 A B NA NB # evs2:ya\"\n\n| YA3: \"[| evs3:ya; ya2' B' A B NA NB:set evs3; Key K ~:used evs3 |]\n  ==> ya3 A B NA NB K # evs3:ya\"\n\n| YA4: \"[| evs4:ya; ya1 A B NA:set evs4; ya3' S Y A B NA NB K:set evs4 |]\n  ==> ya4 A B K NB Y # evs4:ya\"\n\nsubsection\\<open>declarations for tactics\\<close>\n\ndeclare knows_Spy_partsEs [elim]\ndeclare Fake_parts_insert [THEN subsetD, dest]\ndeclare initState.simps [simp del]\n\nsubsection\\<open>general properties of ya\\<close>\n\nlemma ya_has_no_Gets: \"evs:ya ==> ALL A X. Gets A X ~:set evs\"\nby (erule ya.induct, auto)\n\nlemma ya_is_Gets_correct [iff]: \"Gets_correct ya\"\nby (auto simp: Gets_correct_def dest: ya_has_no_Gets)\n\nlemma ya_is_one_step [iff]: \"one_step ya\"\nby (unfold one_step_def, clarify, ind_cases \"ev#evs:ya\" for ev evs, auto)\n\nlemma ya_has_only_Says' [rule_format]: \"evs:ya ==>\nev:set evs --> (EX A B X. ev=Says A B X)\"\nby (erule ya.induct, auto)\n\nlemma ya_has_only_Says [iff]: \"has_only_Says ya\"\nby (auto simp: has_only_Says_def dest: ya_has_only_Says')\n\nlemma ya_is_regular [iff]: \"regular ya\"\napply (simp only: regular_def, clarify)\napply (erule ya.induct, simp_all add: initState.simps knows.simps)\nby (auto dest: parts_sub)\n\nsubsection\\<open>guardedness of KAB\\<close>\n\nlemma Guard_KAB [rule_format]: \"[| evs:ya; A ~:bad; B ~:bad |] ==>\nya3 A B NA NB K:set evs --> GuardK K {shrK A,shrK B} (spies evs)\" \napply (erule ya.induct)\n(* Nil *)\napply simp_all\n(* Fake *)\napply (clarify, erule in_synth_GuardK, erule GuardK_analz, simp)\n(* YA1 *)\n(* YA2 *)\napply safe\napply (blast dest: Says_imp_spies)\n(* YA3 *)\napply blast\napply (drule_tac A=Server in Key_neq, simp+, rule No_Key, simp)\napply (drule_tac A=Server in Key_neq, simp+, rule No_Key, simp)\n(* YA4 *)\napply (blast dest: Says_imp_spies in_GuardK_kparts)\nby blast\n\nsubsection\\<open>session keys are not symmetric keys\\<close>\n\nlemma KAB_isnt_shrK [rule_format]: \"evs:ya ==>\nya3 A B NA NB K:set evs --> K ~:range shrK\"\nby (erule ya.induct, auto)\n\nlemma ya3_shrK: \"evs:ya ==> ya3 A B NA NB (shrK C) ~:set evs\"\nby (blast dest: KAB_isnt_shrK)\n\nsubsection\\<open>ya2' implies ya1'\\<close>\n\nlemma ya2'_parts_imp_ya1'_parts [rule_format]:\n     \"[| evs:ya; B ~:bad |] ==>\n      Ciph B \\<lbrace>Agent A, Nonce NA, Nonce NB\\<rbrace>:parts (spies evs) -->\n      \\<lbrace>Agent A, Nonce NA\\<rbrace>:spies evs\"\nby (erule ya.induct, auto dest: Says_imp_spies intro: parts_parts)\n\nlemma ya2'_imp_ya1'_parts: \"[| ya2' B' A B NA NB:set evs; evs:ya; B ~:bad |]\n==> \\<lbrace>Agent A, Nonce NA\\<rbrace>:spies evs\"\nby (blast dest: Says_imp_spies ya2'_parts_imp_ya1'_parts)\n\nsubsection\\<open>uniqueness of NB\\<close>\n\nlemma NB_is_uniq_in_ya2'_parts [rule_format]: \"[| evs:ya; B ~:bad; B' ~:bad |] ==>\nCiph B \\<lbrace>Agent A, Nonce NA, Nonce NB\\<rbrace>:parts (spies evs) -->\nCiph B' \\<lbrace>Agent A', Nonce NA', Nonce NB\\<rbrace>:parts (spies evs) -->\nA=A' & B=B' & NA=NA'\"\napply (erule ya.induct, simp_all, clarify)\napply (drule Crypt_synth_insert, simp+)\napply (drule Crypt_synth_insert, simp+, safe)\napply (drule not_used_parts_false, simp+)+\nby (drule Says_not_parts, simp+)+\n\nlemma NB_is_uniq_in_ya2': \"[| ya2' C A B NA NB:set evs;\nya2' C' A' B' NA' NB:set evs; evs:ya; B ~:bad; B' ~:bad |]\n==> A=A' & B=B' & NA=NA'\"\nby (drule NB_is_uniq_in_ya2'_parts, auto dest: Says_imp_spies)\n\nsubsection\\<open>ya3' implies ya2'\\<close>\n\nlemma ya3'_parts_imp_ya2'_parts [rule_format]: \"[| evs:ya; A ~:bad |] ==>\nCiph A \\<lbrace>Agent B, Key K, Nonce NA, Nonce NB\\<rbrace>:parts (spies evs)\n--> Ciph B \\<lbrace>Agent A, Nonce NA, Nonce NB\\<rbrace>:parts (spies evs)\"\napply (erule ya.induct, simp_all)\napply (clarify, drule Crypt_synth_insert, simp+)\napply (blast intro: parts_sub, blast)\nby (auto dest: Says_imp_spies parts_parts)\n\nlemma ya3'_parts_imp_ya2' [rule_format]: \"[| evs:ya; A ~:bad |] ==>\nCiph A \\<lbrace>Agent B, Key K, Nonce NA, Nonce NB\\<rbrace>:parts (spies evs)\n--> (EX B'. ya2' B' A B NA NB:set evs)\"\napply (erule ya.induct, simp_all, safe)\napply (drule Crypt_synth_insert, simp+)\napply (drule Crypt_synth_insert, simp+, blast)\napply blast\napply blast\nby (auto dest: Says_imp_spies2 parts_parts)\n\nlemma ya3'_imp_ya2': \"[| ya3' S Y A B NA NB K:set evs; evs:ya; A ~:bad |]\n==> (EX B'. ya2' B' A B NA NB:set evs)\"\nby (drule ya3'_parts_imp_ya2', auto dest: Says_imp_spies)\n\nsubsection\\<open>ya3' implies ya3\\<close>\n\nlemma ya3'_parts_imp_ya3 [rule_format]: \"[| evs:ya; A ~:bad |] ==>\nCiph A \\<lbrace>Agent B, Key K, Nonce NA, Nonce NB\\<rbrace>:parts(spies evs)\n--> ya3 A B NA NB K:set evs\"\napply (erule ya.induct, simp_all, safe)\napply (drule Crypt_synth_insert, simp+)\nby (blast dest: Says_imp_spies2 parts_parts)\n\nlemma ya3'_imp_ya3: \"[| ya3' S Y A B NA NB K:set evs; evs:ya; A ~:bad |]\n==> ya3 A B NA NB K:set evs\"\nby (blast dest: Says_imp_spies ya3'_parts_imp_ya3)\n\nsubsection\\<open>guardedness of NB\\<close>\n\ndefinition ya_keys :: \"agent => agent => nat => nat => event list => key set\" where\n\"ya_keys A B NA NB evs == {shrK A,shrK B} Un {K. ya3 A B NA NB K:set evs}\"\n\nlemma Guard_NB [rule_format]: \"[| evs:ya; A ~:bad; B ~:bad |] ==>\nya2 A B NA NB:set evs --> Guard NB (ya_keys A B NA NB evs) (spies evs)\"\napply (erule ya.induct)\n(* Nil *)\napply (simp_all add: ya_keys_def)\n(* Fake *)\napply safe\napply (erule in_synth_Guard, erule Guard_analz, simp, clarify)\napply (frule_tac B=B in Guard_KAB, simp+)\napply (drule_tac p=ya in GuardK_Key_analz, simp+)\napply (blast dest: KAB_isnt_shrK, simp)\n(* YA1 *)\napply (drule_tac n=NB in Nonce_neq, simp+, rule No_Nonce, simp)\n(* YA2 *)\napply blast\napply (drule Says_imp_spies)\napply (drule_tac n=NB in Nonce_neq, simp+)\napply (drule_tac n'=NAa in in_Guard_kparts_neq, simp+)\napply (rule No_Nonce, simp)\n(* YA3 *)\napply (rule Guard_extand, simp, blast)\napply (case_tac \"NAa=NB\", clarify)\napply (frule Says_imp_spies)\napply (frule in_Guard_kparts_Crypt, simp+)\napply (frule_tac A=A and B=B and NA=NA and NB=NB and C=Ba in ya3_shrK, simp)\napply (drule ya2'_imp_ya1'_parts, simp, blast, blast)\napply (case_tac \"NBa=NB\", clarify)\napply (frule Says_imp_spies)\napply (frule in_Guard_kparts_Crypt, simp+)\napply (frule_tac A=A and B=B and NA=NA and NB=NB and C=Ba in ya3_shrK, simp)\napply (drule NB_is_uniq_in_ya2', simp+, blast, simp+)\napply (simp add: No_Nonce, blast)\n(* YA4 *)\napply (blast dest: Says_imp_spies)\napply (case_tac \"NBa=NB\", clarify)\napply (frule_tac A=S in Says_imp_spies)\napply (frule in_Guard_kparts_Crypt, simp+)\napply (blast dest: Says_imp_spies)\napply (case_tac \"NBa=NB\", clarify)\napply (frule_tac A=S in Says_imp_spies)\napply (frule in_Guard_kparts_Crypt, simp+, blast, simp+)\napply (frule_tac A=A and B=B and NA=NA and NB=NB and C=Aa in ya3_shrK, simp)\napply (frule ya3'_imp_ya2', simp+, blast, clarify)\napply (frule_tac A=B' in Says_imp_spies)\napply (rotate_tac -1, frule in_Guard_kparts_Crypt, simp+)\napply (frule_tac A=A and B=B and NA=NA and NB=NB and C=Ba in ya3_shrK, simp)\napply (drule NB_is_uniq_in_ya2', simp+, blast, clarify)\napply (drule ya3'_imp_ya3, simp+)\napply (simp add: Guard_Nonce)\napply (simp add: No_Nonce)\ndone\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/HOL/Auth/Guard/Guard_Yahalom.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526368038304, "lm_q2_score": 0.4921881357207956, "lm_q1q2_score": 0.2804747069440569}}
{"text": "theory Memory_Allocation_Security\nimports Memory_Allocation_Model Memory_Allocation_Invariant SK_SecurityModel\nbegin\n\nsubsection \\<open>Memory Execution Model\\<close>\n\ntype_synonym partition_id = nat\ntype_synonym partition_name = string\ndatatype Partition_Conf = PartConf partition_id partition_name\ntype_synonym Partitions = \"partition_id \\<rightharpoonup> Partition_Conf\"\n\ntype_synonym domain_id = nat\ntype_synonym Mem_Add = \"ID set\"\ntype_synonym Partition_Mem = \"partition_id \\<rightharpoonup> Mem_Add\"\n\nrecord Sys_Config = partconf :: Partitions\n                    scheduler :: domain_id\n\nrecord State = current :: domain_id \n               partitionmem :: Partition_Mem\n               mempools :: \"Pool set\"\n               memids :: \"ID set\"\n\ndatatype Hypercall = Buddy_Memory_Alloc Pool nat |\n                     Buddy_Memory_Free Pool Block\ndatatype System_Event = Schedule\ndatatype Event = hyperc Hypercall | sys System_Event\n\nprimrec get_partname_by_type :: \"Partition_Conf \\<Rightarrow> partition_name\"\n  where \"get_partname_by_type (PartConf _ pn) = pn\"\n                                                                           \nprimrec get_partid_by_type :: \"Partition_Conf \\<Rightarrow> partition_id\"\n  where \"get_partid_by_type (PartConf pid _) = pid\"\n\ndefinition is_a_partition :: \"Sys_Config \\<Rightarrow> domain_id \\<Rightarrow> bool\"\n  where \"is_a_partition sc nid \\<equiv> (partconf sc) nid \\<noteq> None\"\n\ndefinition is_a_scheduler :: \"Sys_Config \\<Rightarrow> domain_id \\<Rightarrow> bool\"\n  where \"is_a_scheduler sc nid \\<equiv> (scheduler sc) = nid\"\n\ndefinition get_partconf_byid :: \"Sys_Config \\<Rightarrow> partition_id \\<Rightarrow> Partition_Conf option\"\n  where \"get_partconf_byid sc pid \\<equiv> (partconf sc) pid\"\n\ndefinition get_partmem_byid :: \"State \\<Rightarrow> partition_id \\<Rightarrow> Mem_Add option\"\n  where \"get_partmem_byid s pid \\<equiv> (partitionmem s) pid\"\n\ndefinition alloc_memory :: \"Sys_Config \\<Rightarrow> State \\<Rightarrow> Pool \\<Rightarrow> nat \\<Rightarrow> State\"\n  where \"alloc_memory sc s po lv \\<equiv>\n           (if get_partconf_byid sc (current s) \\<noteq> None then\n               (let partmem = get_partmem_byid s (current s);\n                    re = alloc (zerolevelblocks po) lv (memids s) in\n                    (if fst (snd (snd re)) = True then\n                        s\\<lparr>partitionmem := (partitionmem s)(current s := Some (the partmem \\<union> (snd (snd (snd re))))),\n                          mempools := (mempools s - {po}) \\<union> {po\\<lparr>zerolevelblocks := fst re\\<rparr>},\n                          memids := fst (snd re)\\<rparr>\n                     else s))\n            else s)\"\n\ndefinition free_memory :: \"Sys_Config \\<Rightarrow> State \\<Rightarrow> Pool \\<Rightarrow> Block \\<Rightarrow> State\"\n  where \"free_memory sc s po b \\<equiv>\n           let partmem = get_partmem_byid s (current s) in\n             (if get_partconf_byid sc (current s) \\<noteq> None \\<and> partmem \\<noteq> None then\n                 (let re = free (zerolevelblocks po) b (memids s) in\n                      (if snd (snd re) = True then\n                          s\\<lparr>partitionmem := (partitionmem s)(current s := Some (the partmem - {snd (L b)}  )),\n                            mempools := (mempools s - {po}) \\<union> {po\\<lparr>zerolevelblocks := fst re\\<rparr>},\n                            memids := fst (snd re)\\<rparr>\n                       else s))\n              else s)\"\n\ndefinition schedule :: \"Sys_Config \\<Rightarrow> State \\<Rightarrow> State set\" where\n  \"schedule sc s \\<equiv> {s\\<lparr>current:= SOME p. p\\<in>{x. (partconf sc) x \\<noteq> None}\\<rparr>}\"\n\ndefinition sys_config_witness :: Sys_Config \n  where \"sys_config_witness \\<equiv> \\<lparr>partconf = Map.empty,\n                               scheduler = 0\\<rparr>\"\n\nconsts sysconf :: \"Sys_Config\"\nspecification(sysconf)\n  part_id_conf: \"\\<forall>p. (partconf sysconf) p \\<noteq> None \\<longrightarrow> get_partid_by_type (the ((partconf sysconf) p)) = p\"\n  part_not_sch: \"(partconf sysconf) x \\<noteq> None \\<longrightarrow> x \\<noteq> scheduler sysconf\"\n  sch_not_part: \"scheduler sysconf = x \\<longrightarrow> (partconf sysconf) x = None\"\n  by (metis Sys_Config.select_convs(1) sys_config_witness_def)\n\ndefinition state_witness :: State\n  where \"state_witness \\<equiv> \\<lparr>current = (SOME x. (partconf sysconf) x \\<noteq> None),\n                          partitionmem = (\\<lambda> p. (case ((partconf sysconf) p) of None \\<Rightarrow> None\n                                                                             | Some (PartConf _ _) \\<Rightarrow> Some {})),\n                          mempools = {},\n                          memids = {}\\<rparr>\"\n\nconsts s0t :: State\nspecification(s0t)\n  s0t_init: \"s0t = state_witness\"\n  by simp\n\nprimrec event_enabled :: \"State \\<Rightarrow> Event \\<Rightarrow> bool\"\n  where \"event_enabled s (hyperc h) = (is_a_partition sysconf (current s))\" |\n        \"event_enabled s (sys h) =  (case h of Schedule \\<Rightarrow> True)\" \n\ndefinition exec_event :: \"Event \\<Rightarrow> (State \\<times> State) set\"\n  where \"exec_event e = {(s, s'). s' \\<in> (if event_enabled s e then\n                                           (case e of hyperc (Buddy_Memory_Alloc po lv) \\<Rightarrow> {(alloc_memory sysconf s po lv)} |\n                                                      hyperc (Buddy_Memory_Free po b) \\<Rightarrow> {(free_memory sysconf s po b)} |\n                                                      sys Schedule \\<Rightarrow> schedule sysconf s)\n                                        else {s})}\"\n\nprimrec domain_of_event :: \"State \\<Rightarrow> Event \\<Rightarrow> domain_id option\"\nwhere \"domain_of_event s (hyperc h) = Some (current s)\" |\n      \"domain_of_event s (sys h) = Some (scheduler sysconf)\"\n\ndefinition interference1 :: \"domain_id \\<Rightarrow> domain_id \\<Rightarrow> bool\" (\"(_ \\<leadsto> _)\")\n  where \"interference1 d1 d2 \\<equiv>\n            if d1 = d2 then True\n            else if is_a_scheduler sysconf d1 then True\n            else False\"\n\ndefinition non_interference1 :: \"domain_id \\<Rightarrow> domain_id \\<Rightarrow> bool\" (\"(_ \\<setminus>\\<leadsto> _)\")\n      where \"(u \\<setminus>\\<leadsto>  v) \\<equiv> \\<not> (u \\<leadsto> v)\"\n\ndeclare non_interference1_def [cong] and interference1_def [cong] and domain_of_event_def[cong] and\n       event_enabled_def[cong] and is_a_partition_def[cong] and is_a_scheduler_def[cong]\n\nlemma nintf_neq: \"u \\<setminus>\\<leadsto>  v \\<Longrightarrow> u \\<noteq> v\"  by auto\n\nlemma nintf_reflx: \"interference1 u u\" by auto\n\ndefinition vpeq_part :: \"State \\<Rightarrow> partition_id \\<Rightarrow> State \\<Rightarrow> bool\"\n  where \"vpeq_part s d t \\<equiv> (partitionmem s) d = (partitionmem t) d\"\n\ndefinition vpeq_sched :: \"State \\<Rightarrow> domain_id \\<Rightarrow> State \\<Rightarrow> bool\"\n  where \"vpeq_sched s d t \\<equiv> current s = current t\"\n\ndefinition vpeq1  :: \"State \\<Rightarrow> domain_id \\<Rightarrow> State \\<Rightarrow> bool\" (\"(_ \\<sim> _ \\<sim> _)\") \n  where \"vpeq1 s d t \\<equiv>  \n         (if d = scheduler sysconf then \n            (vpeq_sched s d t)\n          else if is_a_partition sysconf d then \n            (vpeq_part s d t)\n          else True)\"\n\ndeclare vpeq_part_def [cong] and vpeq_sched_def[cong] and vpeq1_def[cong] \n\nlemma vpeq_part_transitive_lemma : \"\\<forall> s t r d. vpeq_part s d t \\<and> vpeq_part t d r \\<longrightarrow> vpeq_part s d r\"\n  by auto\n\nlemma vpeq_part_symmetric_lemma:\"\\<forall> s t d. vpeq_part s d t \\<longrightarrow> vpeq_part t d s\"\n  by auto\n\nlemma vpeq_part_reflexive_lemma:\"\\<forall> s d. vpeq_part s d s\"\n  by auto\n\nlemma vpeq_scheduler_transitive_lemma : \"\\<forall> s t r d. vpeq_sched s d t \\<and> vpeq_sched t d r \\<longrightarrow> vpeq_sched s d r\"\n by simp\n\nlemma vpeq_scheduler_symmetric_lemma:\"\\<forall> s t d. vpeq_sched s d t \\<longrightarrow> vpeq_sched t d s\"\n  by simp\n\nlemma vpeq_scheduler_reflexive_lemma:\"\\<forall> s d. vpeq_sched s d s\"\n  by simp\n\nlemma vpeq1_transitive_lemma : \"\\<forall> s t r d. (vpeq1 s d t) \\<and> (vpeq1 t d r) \\<longrightarrow> (vpeq1 s d r)\"\n  by auto\n\nlemma vpeq1_symmetric_lemma : \"\\<forall> s t d. (vpeq1 s d t) \\<longrightarrow> (vpeq1 t d s)\"\n  by auto\n\nlemma vpeq1_reflexive_lemma : \"\\<forall> s d. (vpeq1 s d s)\"\n  by auto\n\nlemma sched_current_lemma : \"\\<forall>s t a. vpeq1 s (scheduler sysconf) t \\<longrightarrow> (domain_of_event s a) = (domain_of_event t a)\"\n  by (metis (no_types) Event.exhaust domain_of_event.simps(1) domain_of_event.simps(2) vpeq1_def vpeq_sched_def)\n  \nlemma schedeler_intf_all_help : \"\\<forall>d. interference1 (scheduler sysconf) d\"\n  by (meson interference1_def is_a_scheduler_def)\n\nlemma no_intf_sched_help : \"\\<forall>d. interference1 d (scheduler sysconf) \\<longrightarrow> d = (scheduler sysconf)\"\n  by (simp add: interference1_def is_a_scheduler_def)\n\nlemma reachable_top: \"\\<forall>s a. (SM.reachable0 s0t exec_event) s \\<longrightarrow> (\\<exists>s'. (s, s') \\<in> exec_event a)\"\n  proof -\n  {\n    fix s a\n    assume p0: \"(SM.reachable0 s0t exec_event) s\"\n    have \"\\<exists>s'. (s, s') \\<in> exec_event a\"\n      proof(induct a)\n        case (hyperc x) show ?case \n          apply (induct x)\n          by (simp add:exec_event_def)+\n        next\n        case (sys x) then show ?case\n          apply (induct x)\n          by (simp add:exec_event_def schedule_def)+\n      qed        \n  }\n  then show ?thesis by auto\n  qed\n\ninterpretation SM_enabled\n    s0t exec_event domain_of_event \"scheduler sysconf\" vpeq1 interference1 \n  using vpeq1_transitive_lemma vpeq1_symmetric_lemma vpeq1_reflexive_lemma sched_current_lemma\n        schedeler_intf_all_help no_intf_sched_help reachable_top nintf_reflx\n        SM.intro[of vpeq1 \"scheduler sysconf\" domain_of_event interference1]\n        SM_enabled_axioms.intro [of s0t exec_event] \n        SM_enabled.intro[of domain_of_event \"scheduler sysconf\" vpeq1 interference1 s0t exec_event] by blast\n\nsubsection \\<open>Some lemmas of security proofs\\<close>\n\nlemma sche_imp_not_part:\n  \"is_a_scheduler sysconf d \\<Longrightarrow> \\<not> (is_a_partition sysconf d)\"      \n  using sch_not_part by auto\n\nlemma part_imp_not_sch:\n  \"is_a_partition sysconf d \\<Longrightarrow> \\<not> (is_a_scheduler sysconf d)\"\n  by (auto simp add: sch_not_part)\n\nsubsection \\<open>proving \"allocate memory\" satisfying the \"local respect\" property\\<close>\nlemma alloc_memory_notchg_current:\n  \"\\<lbrakk>is_a_partition sysconf (current s);\n  s' = alloc_memory sysconf s po lv\\<rbrakk>\n  \\<Longrightarrow> current s = current s'\"\n  by(clarsimp simp: alloc_memory_def get_partconf_byid_def get_partmem_byid_def Let_def)\n\nlemma alloc_memory_sm_sche:\n  \"\\<lbrakk>is_a_partition sysconf (current s);\n  s' = alloc_memory sysconf s po lv\\<rbrakk>\n  \\<Longrightarrow> (s\\<sim>(scheduler sysconf)\\<sim>s')\"\n  using alloc_memory_notchg_current part_imp_not_sch\n  by(meson vpeq1_def vpeq_sched_def)\n\nlemma alloc_memory_notchg_partstate:\n  \"\\<lbrakk>is_a_partition sysconf (current s);\n  is_a_partition sysconf d;\n  d \\<noteq> current s;\n  s' = alloc_memory sysconf s po lv\\<rbrakk>\n  \\<Longrightarrow> (partitionmem s) d = (partitionmem s') d\"\n  by(clarsimp simp: alloc_memory_def get_partconf_byid_def get_partmem_byid_def Let_def)\n\nlemma alloc_memory_sm_nitfpart:\n  \"\\<lbrakk>reachable0 s;\n  is_a_partition sysconf (current s);\n  is_a_partition sysconf d;\n  ((current s) \\<setminus>\\<leadsto> d);\n  s' = alloc_memory sysconf s po lv\\<rbrakk>\n  \\<Longrightarrow> (s \\<sim> d \\<sim> s')\"\n  using sche_imp_not_part \n  apply(clarsimp cong del: is_a_partition_def interference1_def non_interference1_def)\n  using nintf_neq alloc_memory_notchg_partstate by blast\n\nlemma alloc_memory_presrv_lcrsp:\n  assumes p0:\"reachable0 s\"\n    and   p1:\"is_a_partition sysconf (current s)\"\n    and   p2:\"(current s) \\<setminus>\\<leadsto> d\"\n    and   p3:\"s' = alloc_memory sysconf s po lv\"\n  shows   \"s \\<sim> d \\<sim> s'\"\nproof(cases \"is_a_scheduler sysconf d\")\n  assume a0:\"is_a_scheduler sysconf d\"\n  then show ?thesis using is_a_scheduler_def alloc_memory_sm_sche[OF p1 p3] by auto\nnext\n  assume a1:\"\\<not> is_a_scheduler sysconf d\"\n  show ?thesis\n  proof(cases \"is_a_partition sysconf d\")\n    assume b0:\"is_a_partition sysconf d\"\n    show ?thesis using b0 alloc_memory_sm_nitfpart p0 p1 p2 p3 by blast\n  next\n    assume b1:\"\\<not> is_a_partition sysconf d\"\n    show ?thesis using a1 b1 by auto\n  qed\nqed\n\nlemma alloc_memory_presrv_lcrsp_e:\n  \"local_respect_e (hyperc (Buddy_Memory_Alloc po lv))\"\n  using alloc_memory_presrv_lcrsp exec_event_def\n        prod.simps(2) vpeq_reflexive_lemma\n  by(auto cong del: vpeq1_def)\n\nsubsection \\<open>proving \"free memory\" satisfying the \"local respect\" property\\<close>\nlemma free_memory_notchg_current:\n  \"\\<lbrakk>is_a_partition sysconf (current s);\n  s' = free_memory sysconf s po b\\<rbrakk>\n  \\<Longrightarrow> current s = current s'\"\n  by(clarsimp simp: free_memory_def get_partconf_byid_def get_partmem_byid_def Let_def)\n\nlemma free_memory_sm_sche:\n  \"\\<lbrakk>is_a_partition sysconf (current s);\n  s' = free_memory sysconf s po b\\<rbrakk>\n  \\<Longrightarrow> (s\\<sim>(scheduler sysconf)\\<sim>s')\"\n  using free_memory_notchg_current part_imp_not_sch\n  by(meson vpeq1_def vpeq_sched_def)\n\nlemma free_memory_notchg_partstate:\n  \"\\<lbrakk>is_a_partition sysconf (current s);\n  is_a_partition sysconf d;\n  d \\<noteq> current s;\n  s' = free_memory sysconf s po b\\<rbrakk>\n  \\<Longrightarrow> (partitionmem s) d = (partitionmem s') d\"\n  by(clarsimp simp: free_memory_def get_partconf_byid_def get_partmem_byid_def Let_def)\n\nlemma free_memory_sm_nitfpart:\n  \"\\<lbrakk>reachable0 s;\n  is_a_partition sysconf (current s);\n  is_a_partition sysconf d;\n  ((current s) \\<setminus>\\<leadsto> d);\n  s' = free_memory sysconf s po b\\<rbrakk>\n  \\<Longrightarrow> (s \\<sim> d \\<sim> s')\"\n  using sche_imp_not_part \n  apply(clarsimp cong del: is_a_partition_def interference1_def non_interference1_def)\n  using nintf_neq free_memory_notchg_partstate by blast\n\nlemma free_memory_presrv_lcrsp:\n  assumes p0:\"reachable0 s\"\n    and   p1:\"is_a_partition sysconf (current s)\"\n    and   p2:\"(current s) \\<setminus>\\<leadsto> d\"\n    and   p3:\"s' = free_memory sysconf s po b\"\n  shows   \"s \\<sim> d \\<sim> s'\"\nproof(cases \"is_a_scheduler sysconf d\")\n  assume a0:\"is_a_scheduler sysconf d\"\n  then show ?thesis using is_a_scheduler_def free_memory_sm_sche[OF p1 p3] by auto\nnext\n  assume a1:\"\\<not> is_a_scheduler sysconf d\"\n  show ?thesis\n  proof(cases \"is_a_partition sysconf d\")\n    assume b0:\"is_a_partition sysconf d\"\n    show ?thesis using b0 free_memory_sm_nitfpart p0 p1 p2 p3 by blast\n  next\n    assume b1:\"\\<not> is_a_partition sysconf d\"\n    show ?thesis using a1 b1 by auto\n  qed\nqed\n\nlemma free_memory_presrv_lcrsp_e:\n  \"local_respect_e (hyperc (Buddy_Memory_Free po b))\"\n  using free_memory_presrv_lcrsp exec_event_def\n        prod.simps(2) vpeq_reflexive_lemma\n  by(auto cong del: vpeq1_def)\n\nsubsection \\<open>proving \"schedule\" satisfying the \"local respect\" property\\<close>\nlemma schedule_presrv_lcrsp:\n  assumes p0:\"(scheduler sysconf) \\<setminus>\\<leadsto> d\"        \n  shows   \"s \\<sim> d \\<sim> s'\"\n  using p0 by auto\n\nlemma schedule_presrv_lcrsp_e: \"local_respect_e (sys Schedule)\"\n  using schedule_presrv_lcrsp exec_event_def prod.simps(2) vpeq_reflexive_lemma by auto\n\nsubsection \\<open>proving the \"local respect\" property\\<close>\ntheorem local_respect:local_respect\n  proof -\n    {\n      fix e\n      have \"local_respect_e e\"\n        apply(induct e)\n        using alloc_memory_presrv_lcrsp_e free_memory_presrv_lcrsp_e\n        apply (rule Hypercall.induct)\n        using schedule_presrv_lcrsp_e\n        by (rule System_Event.induct)\n    }\n    then show ?thesis using local_respect_all_evt by blast\n  qed\n\nend", "meta": {"author": "johnakeke", "repo": "Buddy-Memory-Verification", "sha": "bc6ea9213f93938d51dc7a9e225ce9ce14cdfb27", "save_path": "github-repos/isabelle/johnakeke-Buddy-Memory-Verification", "path": "github-repos/isabelle/johnakeke-Buddy-Memory-Verification/Buddy-Memory-Verification-bc6ea9213f93938d51dc7a9e225ce9ce14cdfb27/Memory_Allocation_Security.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6757646010190476, "lm_q2_score": 0.41489884579676883, "lm_q1q2_score": 0.28037395299311685}}
{"text": "theory SimpleNetwork\nimports NetworkAnalysis\nbegin\n\ndefinition \"router   = ipv4addr_of_dotteddecimal (1,0,1,1)\"\ndefinition \"normal   = ipv4addr_of_dotteddecimal (1,0,1,2)\"\ndefinition \"weird    = ipv4addr_of_dotteddecimal (1,0,2,3)\"\ndefinition \"daisy    = ipv4addr_of_dotteddecimal (1,0,3,4)\"\ndefinition \"wlan1    = ipv4addr_of_dotteddecimal (1,0,4,5)\"\ndefinition \"wlan2    = ipv4addr_of_dotteddecimal (1,0,4,6)\"\ndefinition \"internet = ipv4addr_of_dotteddecimal (2,0,0,7)\"\nlemmas entity_defs = router_def normal_def daisy_def weird_def wlan1_def wlan2_def internet_def\n\ndefinition \"simple_links = add_backlinks {\n  (\\<lparr> entity = NetworkBox router, port = Port 11 \\<rparr>, \\<lparr> entity = Host normal, port = Port 12 \\<rparr>),\n  (\\<lparr> entity = NetworkBox router, port = Port 21 \\<rparr>, \\<lparr> entity = NetworkBox weird, port = Port 23 \\<rparr>),\n  (\\<lparr> entity = NetworkBox weird, port = Port 33 \\<rparr>,  \\<lparr> entity = Host daisy, port = Port 34 \\<rparr>),\n  (\\<lparr> entity = NetworkBox router, port = Port 41 \\<rparr>, \\<lparr> entity = Host wlan1, port = Port 45 \\<rparr>),\n  (\\<lparr> entity = NetworkBox router, port = Port 41 \\<rparr>, \\<lparr> entity = Host wlan2, port = Port 46 \\<rparr>),\n  (\\<lparr> entity = Host wlan1, port = Port 45 \\<rparr>,        \\<lparr> entity = Host wlan2, port = Port 46 \\<rparr>),\n  (\\<lparr> entity = NetworkBox router, port = Port 1 \\<rparr>,  \\<lparr> entity = Host internet, port = Port 7 \\<rparr>)\n}\"\n\ndefinition \"router_fwd_table = [\n\t\\<lparr> routing_match = \\<lparr> pfxm_prefix = ipv4addr_of_dotteddecimal (1,0,1,1),pfxm_length = 32 \\<rparr>, routing_action = {} \\<rparr>,\n\t\\<lparr> routing_match = \\<lparr> pfxm_prefix = ipv4addr_of_dotteddecimal (1,0,2,1),pfxm_length = 32 \\<rparr>, routing_action = {} \\<rparr>,\n\t\\<lparr> routing_match = \\<lparr> pfxm_prefix = ipv4addr_of_dotteddecimal (1,0,4,1),pfxm_length = 32 \\<rparr>, routing_action = {} \\<rparr>,\n\t\\<lparr> routing_match = \\<lparr> pfxm_prefix = ipv4addr_of_dotteddecimal (2,0,0,1),pfxm_length = 32 \\<rparr>, routing_action = {} \\<rparr>,\n\t\\<lparr> routing_match = \\<lparr> pfxm_prefix = ipv4addr_of_dotteddecimal (1,0,1,0), pfxm_length = 24 \\<rparr>, routing_action = Port ` {11} \\<rparr>,\n\t\\<lparr> routing_match = \\<lparr> pfxm_prefix = ipv4addr_of_dotteddecimal (1,0,4,0), pfxm_length = 24 \\<rparr>, routing_action = Port ` {41} \\<rparr>,\n\t\\<lparr> routing_match = \\<lparr> pfxm_prefix = ipv4addr_of_dotteddecimal (1,0,2,0), pfxm_length = 23 \\<rparr>, routing_action = Port ` {21} \\<rparr>,\n\t\\<lparr> routing_match = \\<lparr> pfxm_prefix = 0, pfxm_length = 0 \\<rparr>, routing_action = Port ` {1} \\<rparr>\n]\"\nlemma \"correct_routing router_fwd_table\" by eval\n\ndefinition \"weirdbox_fwd_table = [\n\t\\<lparr> routing_match = \\<lparr> pfxm_prefix = ipv4addr_of_dotteddecimal (1,0,2,3),pfxm_length = 32 \\<rparr>, routing_action = {} \\<rparr>,\n\t\\<lparr> routing_match = \\<lparr> pfxm_prefix = ipv4addr_of_dotteddecimal (1,0,3,3),pfxm_length = 32 \\<rparr>, routing_action = {} \\<rparr>,\n\t\\<lparr> routing_match = \\<lparr> pfxm_prefix = ipv4addr_of_dotteddecimal (1,0,3,0),pfxm_length = 24 \\<rparr>, routing_action = Port ` {33} \\<rparr>,\n\t\\<lparr> routing_match = \\<lparr> pfxm_prefix = 0,pfxm_length = 0 \\<rparr>, routing_action = Port ` {23} \\<rparr>\n]\"\nlemma \"correct_routing weirdbox_fwd_table\" by eval\n\ndefinition \"default_only own_addr default_port = [\n\t\\<lparr> routing_match = \\<lparr> pfxm_prefix = own_addr,pfxm_length = 32 \\<rparr>, routing_action = {} \\<rparr>,\n\t\\<lparr> routing_match = \\<lparr> pfxm_prefix = 0,pfxm_length = 0 \\<rparr>, routing_action = Port ` {default_port} \\<rparr>\n]\"\nlemma \"correct_routing (default_only addr defport)\"\n  unfolding default_only_def correct_routing_def valid_prefix_def valid_prefixes_def by simp\n\ndefinition \"forwarding_table_map = [\n  (NetworkBox router, router_fwd_table),\n  (NetworkBox weird, weirdbox_fwd_table),\n  (Host daisy, default_only daisy 34),\n  (Host wlan1, default_only wlan1 45),\n  (Host wlan2, default_only wlan2 46),\n  (Host normal, default_only normal 12),\n  (Host internet, default_only normal 7)\n]\"\n\ndefinition \"to_fun m = (the \\<circ> map_of m)\"\n\ndefinition \"simple_interfaces \\<equiv> fst ` simple_links \\<union> snd ` simple_links\"\n\nlemma simple_valid_formed: \"valid_network_formers simple_interfaces simple_links forwarding_table_map\"\nproof -\n  have \"(\\<forall>tbl\\<in>snd ` set forwarding_table_map. correct_routing tbl)\" by eval\n  moreover\n  have \"wellformed_network (network_of simple_interfaces simple_links forwarding_table_map)\"\n  proof(unfold_locales)\n    case goal1 thus ?case by eval\n  next\n    case goal2 thus ?case by eval\n  next\n    case goal3 thus ?case by(simp add: simple_links_def simple_interfaces_def network_of_def)\n  next\n    case goal4 thus ?case\n      unfolding network_of_def simple_links_def entity_defs simple_interfaces_def fst_add_backlinks snd_add_backlinks\n      by(auto, (fastforce dest: ipv4addr_of_dotteddecimal_eqE)+)\n  qed\n  moreover\n  have \"entity ` simple_interfaces \\<subseteq> fst ` set forwarding_table_map\" by eval\n  moreover\n  have \"single_valued (set forwarding_table_map)\" \n    unfolding forwarding_table_map_def single_valued_def entity_defs \n    by(auto, (fastforce dest: ipv4addr_of_dotteddecimal_eqE)+)\n  ultimately\n  show ?thesis unfolding valid_network_formers_def by simp\nqed\n\ndefinition \"simple_network \\<equiv> network_of simple_interfaces simple_links forwarding_table_map\"\n\ninterpretation simple_wellformed: wellformed_network simple_network\n  unfolding simple_network_def using conjunct1[OF simple_valid_formed[unfolded valid_network_formers_def]] .\n\nvalue \"reduced_range_destination ((to_fun forwarding_table_map) (NetworkBox router)) ipv4rq_UNIV\"\nvalue \"range_destination ((to_fun forwarding_table_map) (NetworkBox weird)) ipv4rq_UNIV\"\nvalue[code] \"reachable_code simple_network (Host wlan1, Host wlan2)  \\<lparr> entity = Host wlan1, port = Port 45 \\<rparr>\"\nvalue[code] \"reachable_code simple_network (Host normal, Host daisy)  \\<lparr> entity = Host normal, port = Port 12 \\<rparr>\"\nvalue[code] \"reachable_code simple_network (Host internet, Host (daisy + 1))  \\<lparr> entity = Host normal, port = Port 12 \\<rparr>\"\nvalue[code] \"reachable_code simple_network (Host daisy, Host internet)  \\<lparr> entity = Host daisy, port = Port 34 \\<rparr>\"\n\nlemma [code_unfold]:\n  \"all_views simple_interfaces simple_links forwarding_table_map = \n   all_views_code simple_interfaces simple_links forwarding_table_map\"\n  using all_views_code_correct[OF conjunct1[OF simple_valid_formed[unfolded valid_network_formers_def]]] .\n\nvalue \"covering_iplist (map snd forwarding_table_map)\"\nvalue \"(map (\\<lambda>cdst. (cdst, view_code (network_of simple_interfaces simple_links forwarding_table_map) (Host 0, Host cdst)))\n   (covering_iplist (map snd forwarding_table_map)))\"\nvalue \"(\\<lambda>l. (length (remdups l), length l)) ((map (\\<lambda>cdst. view_code (network_of simple_interfaces simple_links forwarding_table_map) (Host 0, Host cdst))\n   (covering_iplist (map snd forwarding_table_map))))\"\n\n(* \nWhat you get if you don't block the reoutput:\n\"\"[{(\\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>, \\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>, \\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>, \\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>, \\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>),\n   (\\<lparr>entity = Host 0x1000304, port = Port 34\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>),\n   (\\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>),\n   (\\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>)},\n  {(\\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>),\n   (\\<lparr>entity = Host 0x1000304, port = Port 34\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>),\n   (\\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>),\n   (\\<lparr>entity = Host 0x2000007, port = Port 7\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>)},\n  {(\\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>),\n   (\\<lparr>entity = Host 0x1000304, port = Port 34\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>),\n   (\\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>),\n   (\\<lparr>entity = Host 0x2000007, port = Port 7\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>)},\n  {(\\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>, \\<lparr>entity = Host 0x1000304, port = Port 34\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>, \\<lparr>entity = Host 0x1000304, port = Port 34\\<rparr>),\n   (\\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>),\n   (\\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>),\n   (\\<lparr>entity = Host 0x2000007, port = Port 7\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>)},\n  {(\\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>),\n   (\\<lparr>entity = Host 0x1000304, port = Port 34\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>),\n   (\\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>),\n   (\\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>),\n   (\\<lparr>entity = Host 0x2000007, port = Port 7\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>)},\n  {(\\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>, \\<lparr>entity = Host 0x1000304, port = Port 34\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>, \\<lparr>entity = Host 0x1000304, port = Port 34\\<rparr>),\n   (\\<lparr>entity = Host 0x1000304, port = Port 34\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>),\n   (\\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>),\n   (\\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>),\n   (\\<lparr>entity = Host 0x2000007, port = Port 7\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>)},\n  {(\\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>),\n   (\\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>),\n   (\\<lparr>entity = Host 0x1000304, port = Port 34\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>),\n   (\\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>),\n   (\\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>),\n   (\\<lparr>entity = Host 0x2000007, port = Port 7\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>)},\n  {(\\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>, \\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>, \\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>, \\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>, \\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>),\n   (\\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>),\n   (\\<lparr>entity = Host 0x1000304, port = Port 34\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>),\n   (\\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>),\n   (\\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>),\n   (\\<lparr>entity = Host 0x2000007, port = Port 7\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>)},\n  {(\\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>),\n   (\\<lparr>entity = Host 0x1000304, port = Port 34\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>),\n   (\\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>),\n   (\\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>),\n   (\\<lparr>entity = Host 0x2000007, port = Port 7\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>)},\n  {(\\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>),\n   (\\<lparr>entity = Host 0x1000304, port = Port 34\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>),\n   (\\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>),\n   (\\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>),\n   (\\<lparr>entity = Host 0x2000007, port = Port 7\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>)},\n  {(\\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>, \\<lparr>entity = Host 0x2000007, port = Port 7\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>, \\<lparr>entity = Host 0x2000007, port = Port 7\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>, \\<lparr>entity = Host 0x2000007, port = Port 7\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>, \\<lparr>entity = Host 0x2000007, port = Port 7\\<rparr>),\n   (\\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>),\n   (\\<lparr>entity = Host 0x1000304, port = Port 34\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>),\n   (\\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>),\n   (\\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>),\n   (\\<lparr>entity = Host 0x2000007, port = Port 7\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>)}]\"\n  :: \"(32 word interface \\<times> 32 word interface) set list\"\n\nOtherwise:\n\"[{(\\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>)},\n  {(\\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>, \\<lparr>entity = Host 0x1000304, port = Port 34\\<rparr>)},\n  {(\\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>)},\n  {(\\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>, \\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>, \\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>, \\<lparr>entity = Host 0x1000102, port = Port 12\\<rparr>)},\n  {(\\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>, \\<lparr>entity = Host 0x1000406, port = Port 46\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>, \\<lparr>entity = Host 0x1000405, port = Port 45\\<rparr>)},\n  {(\\<lparr>entity = NetworkBox 0x1000101, port = Port 1\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>, \\<lparr>entity = NetworkBox 0x1000203, port = Port 23\\<rparr>)},\n  {(\\<lparr>entity = NetworkBox 0x1000101, port = Port 41\\<rparr>, \\<lparr>entity = Host 0x2000007, port = Port 7\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000203, port = Port 33\\<rparr>, \\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 21\\<rparr>, \\<lparr>entity = Host 0x2000007, port = Port 7\\<rparr>),\n   (\\<lparr>entity = NetworkBox 0x1000101, port = Port 11\\<rparr>, \\<lparr>entity = Host 0x2000007, port = Port 7\\<rparr>)}]\"\n*)\n\nend\n", "meta": {"author": "jcaesar", "repo": "fixed-topos-header-space-analysis", "sha": "2da808ab41e5924d616ad1af15e8f50cb986c803", "save_path": "github-repos/isabelle/jcaesar-fixed-topos-header-space-analysis", "path": "github-repos/isabelle/jcaesar-fixed-topos-header-space-analysis/fixed-topos-header-space-analysis-2da808ab41e5924d616ad1af15e8f50cb986c803/thy/SimpleNetwork.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6513548646660542, "lm_q2_score": 0.43014734858584286, "lm_q1q2_score": 0.28017856802459373}}
{"text": "theory RB_Relaxed_mike_bd imports RCU_Lems \nbegin\n\ndatatype F = B | W | Q | R\ndatatype Pointer = Head | Tail\n\nconsts n :: nat   (*size of buffer, input*)\nconsts N :: nat   (*number of Arr\\<^sub>W entries*)\n\n(*(Wr T u t b \\<sigma>)*)\n(*\nlemma pval_val:\n  assumes \"wfs \\<sigma>\"\n  and \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  and \"u \\<noteq> v\"\n  and \"var w = x\"\n  and \"ts = getTS \\<sigma> w\"\nshows \"\\<not> [x \\<approx>\\<^sub>t u] (write_trans t b w v \\<sigma> ts) \"\n  sorry\n*)\n\n\nlemma pval_val_same:\n  assumes \"wfs \\<sigma>\"\n  and \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  and \"u \\<noteq> v\"\n  and \"var w = x\"\nshows \"\\<not> [x \\<approx>\\<^sub>t u] (Wr x v t b \\<sigma>)\"\n  using assms\n  apply (simp add: p_obs_def visible_writes_def value_def write_trans_def)\n  apply(simp add: rev_app_def update_modView_def update_mods_def update_thrView_def update_wa_def)\n  apply safe  \n  using w_in_writes_on_var apply blast\n  defer  \n  apply (simp add: getVWNC_var)\n   apply (simp add: getVWNC_var)\n  apply(case_tac \"(a, ba)\n       \\<in> writes_on \\<sigma> x\")\n  apply (smt dual_order.strict_trans getTS_w_greater_tst_w getVWNC_in_visible_writes le_neq_trans less_le_not_le mem_Collect_eq visible_writes_def)\nproof -\nfix a :: nat and ba :: rat\n  assume a1: \"(a, ba) \\<in> writes_on (\\<sigma> \\<lparr>thrView := (thrView \\<sigma>) (t := (thrView \\<sigma> t) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))))), modView := (modView \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))) := (thrView \\<sigma> t) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))))), mods := (mods \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))) := \\<lparr>val = v, is_releasing = b\\<rparr>), writes := insert (var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))) (surrey_state.writes \\<sigma>), write_available := (write_available \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))) := True)\\<rparr>) (var w)\"\n  assume a2: \"x = var w\"\n  assume a3: \"(a, ba) \\<notin> writes_on \\<sigma> x\"\n  assume a4: \"ba \\<noteq> getTS \\<sigma> (getVWNC \\<sigma> t (var w))\"\n  have f5: \"\\<forall>s n p. var p = n \\<and> p \\<in> surrey_state.writes (s::surrey_state) \\<or> p \\<notin> writes_on s n\"\n    using writes_on_def by force\n  have \"\\<forall>s n p. writes_on (write_available_update p (s::surrey_state)) n = writes_on s n\"\n    by (metis (no_types) surrey_state.select_convs(1) surrey_state.surjective surrey_state.update_convs(5) writes_on_def)\n  then have f6: \"(a, ba) \\<in> writes_on (\\<sigma> \\<lparr>thrView := (thrView \\<sigma>) (t := (thrView \\<sigma> t) (x := (x, getTS \\<sigma> (getVWNC \\<sigma> t x)))), modView := (modView \\<sigma>) ((x, getTS \\<sigma> (getVWNC \\<sigma> t x)) := (thrView \\<sigma> t) (x := (x, getTS \\<sigma> (getVWNC \\<sigma> t x)))), mods := (mods \\<sigma>) ((x, getTS \\<sigma> (getVWNC \\<sigma> t x)) := \\<lparr>val = v, is_releasing = b\\<rparr>), writes := insert (x, getTS \\<sigma> (getVWNC \\<sigma> t x)) (surrey_state.writes \\<sigma>)\\<rparr>) x\"\n    using a2 a1 by blast\n  have f7: \"\\<forall>s f. surrey_state.writes (writes_update f (s::surrey_state)) = f (surrey_state.writes s)\"\n    by auto\n  have f8: \"var (a, ba) = x\"\n    using f6 f5 by meson\n  have \"(a, ba) \\<in> surrey_state.writes \\<sigma>\"\n    using f7 f6 f5 a4 a2 by (metis insert_iff snd_conv)\n  then show False\n    using f8 a3 writes_on_def by force\nqed\n\n\n\nlemma pval_val_other:\n  assumes \"wfs \\<sigma>\"\n  and \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  and \"u \\<noteq> v\"\n  and \"var w = x\"\n  and \"t\\<noteq>s\"\nshows \"\\<not> [x \\<approx>\\<^sub>t u] (Wr x v s b \\<sigma>)\"\n  using assms apply simp\n  apply (simp add: p_obs_def visible_writes_def value_def write_trans_def)\n    apply(simp add: rev_app_def update_modView_def update_mods_def update_thrView_def update_wa_def)\n  apply safe  \n  using w_in_writes_on_var\n  apply (simp add: w_in_writes_on_var getVWNC_var) \n  apply (simp add: getVWNC_var)\n\n  apply(case_tac \"(a, ba)\n       \\<in> writes_on \\<sigma> x\")\n  apply (smt dual_order.strict_trans getTS_w_greater_tst_w getVWNC_in_visible_writes le_neq_trans less_le_not_le mem_Collect_eq visible_writes_def)\nproof -\n  fix a :: nat and ba :: rat\n  assume a1: \"ba \\<noteq> getTS \\<sigma> (getVWNC \\<sigma> s (var w))\"\n  assume a2: \"(a, ba) \\<in> writes_on (\\<sigma> \\<lparr>thrView := (thrView \\<sigma>) (s := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), modView := (modView \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), mods := (mods \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := \\<lparr>val = v, is_releasing = b\\<rparr>), writes := insert (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) (surrey_state.writes \\<sigma>), write_available := (write_available \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := True)\\<rparr>) (var w)\"\n  assume a3: \"(a, ba) \\<notin> writes_on \\<sigma> x\"\n  assume a4: \"x = var w\"\n  have \"(a, ba) \\<in> \\<lbrace>\\<acute>var = var w \\<and> \\<acute>(\\<in>) (surrey_state.writes (\\<sigma> \\<lparr>thrView := (thrView \\<sigma>) (s := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), modView := (modView \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), mods := (mods \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := \\<lparr>val = v, is_releasing = b\\<rparr>), writes := insert (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) (surrey_state.writes \\<sigma>), write_available := (write_available \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := True)\\<rparr>))\\<rbrace>\"\n    using a2 writes_on_def by blast\n  then have f5: \"var (a, ba) = var w \\<and> (a, ba) \\<in> surrey_state.writes (\\<sigma> \\<lparr>thrView := (thrView \\<sigma>) (s := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), modView := (modView \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), mods := (mods \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := \\<lparr>val = v, is_releasing = b\\<rparr>), writes := insert (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) (surrey_state.writes \\<sigma>), write_available := (write_available \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := True)\\<rparr>)\"\n    by blast\n  then have \"(a, ba) \\<notin> surrey_state.writes \\<sigma>\"\n    using a4 a3 writes_on_def by fastforce\n  then show False\n    using f5 a1 by simp\nqed\n\n\n\nlemma pval_val:\n  assumes \"wfs \\<sigma>\"\n  and \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  and \"u \\<noteq> v\"\n  and \"var w = x\"\nshows \"\\<not> [x \\<approx>\\<^sub>t u] (Wr x v t' b \\<sigma>)\"\n  using assms apply (cases \"t=t'\")\n  using pval_val_same apply blast\n  using pval_val_other by blast\n\n\n\n\nlemma pval_val_outside:\n  assumes \"wfs \\<sigma>\"\n  and \"N\\<in> \\<nat>\"\n  and \"\\<forall>j.[x \\<approx>\\<^sub>t j] \\<sigma> \\<longrightarrow> j<N\"\n  and \"\\<forall>k. k<N \\<longrightarrow> [x \\<approx>\\<^sub>t k] \\<sigma>\"\n  and \"u\\<in>\\<nat> \\<and> u<N\"\nshows \"\\<forall>z.(z>N\\<longrightarrow>\\<not>[x \\<approx>\\<^sub>t z] (Wr x u t' b \\<sigma>))\"\n  using assms apply (cases \"t=t'\")\n  apply (metis fst_conv not_less_iff_gr_or_eq pval_val)\n  by (metis fst_conv not_less_iff_gr_or_eq pval_val)\n\n\nlemma pval_val_outside_2:\n  assumes \"wfs \\<sigma>\"\n  and \"N \\<in> \\<nat>\"\n  and \"[x =\\<^sub>t 0] \\<sigma>\"\n  and \"u \\<noteq> 0\"\nshows \"\\<exists>i.(([x =\\<^sub>t i] (Wr x u t b \\<sigma>))\\<or>([x =\\<^sub>t i] (Wr x 0 t' b \\<sigma>)))\" \n  using assms apply (cases \"t=t'\")\n  using OpSem_ProofRules.ext_d_obs_d_obs apply blast\n  using OpSem_ProofRules.ext_d_obs_d_obs by blast\n\n\n\nlemma pval_val_outside_3:\n  assumes \"wfs \\<sigma>\"\n  and \"N \\<in> \\<nat>\"\n  and \"u \\<in> \\<nat> \\<and> u<N\"\n  and \"[x =\\<^sub>t u]\\<sigma>\"\n  and \"t\\<noteq>y\"\n  and \"if \\<sigma>'=(Wr x u y False \\<sigma>) then [x =\\<^sub>t u]\\<sigma>' else [x =\\<^sub>t u]\\<sigma>'\"\nshows \"[x =\\<^sub>t u]\\<sigma>'\" \n  by (meson assms(6))\n\n\n\n\n\n(*Ex (d_obs_t (Wr T 0 2 False (\\<sigma> x)) 3 T)*)\n\n\n(*\n  assumes \"wfs \\<sigma>\"\n  and \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  and \"u \\<noteq> v\"\n  and \"var w = x\"\nshows \"\\<not> [x \\<approx>\\<^sub>t u] (Wr x v t b \\<sigma>)\"\n\n\nlemma pval_val_all: \n  assumes \"wfs \\<sigma>\"\n  and \"\\<forall>i. i > k \\<longrightarrow> \\<not> [x \\<approx>\\<^sub>t i] \\<sigma>\"\n  and \"k < j\" \n  and \"u \\<le> k\"\n  and \"var w = x\"\nshows \"\\<not> [x \\<approx>\\<^sub>t j] (Wr x v t b \\<sigma>) \"\n  using assms\n  \n  using pval_val sledgehammer\n*)\n\nconsts   \n  H :: L\n  T :: L\n\n\nrecord LB =\n  hW ::  V               (*local copy of W*)\n  tW ::  V               (*local copy of W*)\n  q :: \"(nat \\<times> nat) list\" (*for now assume well synchronised, need to think about weak memory *)\n  tempR :: \"(nat \\<times> nat)\"          (*local copy of word by R*)\n\n  tloc :: V\n  Data:: \"nat  \\<Rightarrow> nat\"     (*returns a word Data_i*)\n  countW :: nat  (* the index of the next element of Data to be written  *)\n  countR :: nat  (* how many words from Data the read has read or reading (i.e., retrieved)  *)\n\n  ownD :: \"nat \\<Rightarrow> F\" (* ownership of data indices *)\n  ownB :: \"nat \\<Rightarrow> F\" (* ownership of bytes in buffer *)\n  (* tries :: nat *)\n  oom :: bool       (*signals W that it was OOM*)\n  \\<sigma> :: surrey_state\n\ndefinition \"global s \\<equiv> wfs s \\<and> H \\<noteq> T\"\n\n\n\n\nlemmas opsemsyntax [simp] =  global_def\nlemmas defs_del [simp del] =  Rd_def Let_def Wr_def Upd_def st_rd_def val_rd_def\n\n(* thread 2 is the writer *)\n(* thread 3 is the reader *)\n\n(* Omit tries *)\n(* Finish queueu + reader *)\n\n(* We need this one to hold at minimum *)\ndefinition \"arrayInv s \\<equiv> \\<forall>i. (i<countR s \\<longrightarrow> ownD s i = R)\\<and> (countR s \\<le> i \\<and> i < countW s \\<longrightarrow> ownD s i = B) \\<and> (countW s \\<le> i \\<and> i < n \\<longrightarrow> ownD s i = W) \"\n\n\ndefinition \"q_entries_bounded s \\<equiv> (\\<forall>i. i < length(q s) \\<longrightarrow> (fst(q s!i)+snd(q s!i)\\<le>N)\\<and>snd(q s!i)>0)\"\ndefinition \"tempR_bounded s \\<equiv> fst (tempR s) + snd (tempR s) \\<le> N\"\ndefinition \"counter_q_rel s \\<equiv> (countW s-countR s=length(q s))\"\ndefinition \"con_assms s  \\<equiv>   0 < N \\<and> 0<n \\<and> (countR s\\<le>countW s) \\<and> (countW s\\<le>n)\n                             \\<and> (\\<forall>i.(i<n)\\<longrightarrow>Data s i\\<le>N \\<and> Data s i>0)\"\n(*new\n(typically)\n\\forall x . P(x) \\<longrightarrow> Q(x)\n\\exists x . P(x) \\<and> Q(x)\n\n[H =\\<^sub>2 i] means thread 2 sees the last write to H and this has value i.\n[H \\<approx>\\<^sub>2 i] means that thread 2 can see the value i.\n*)\ndefinition \"bounded_pointers s \\<equiv> ((\\<forall>i. i > N \\<longrightarrow> \\<not>[H \\<approx>\\<^sub>2 i] (\\<sigma> s)))\\<and>\n                                 ((\\<forall>j. j > N \\<longrightarrow> \\<not>[T \\<approx>\\<^sub>2 j] (\\<sigma> s)))\"\n\ndefinition \"basic_pointer_movement s \\<equiv> 0\\<le>hW s\\<and> hW s\\<le>N \\<and> 0\\<le>tW s\\<and> tW s\\<le>N\"\n\n\n\ndefinition \"collection s \\<equiv> arrayInv s \\<and> q_entries_bounded s\n                          \\<and>tempR_bounded s \\<and>counter_q_rel s \\<and> con_assms s\n                          \\<and> bounded_pointers s \\<and> basic_pointer_movement s\n                          \"\n\n\ndefinition \"init s \\<equiv>\n                     [T =\\<^sub>2 0] (\\<sigma> s) \\<and> [H =\\<^sub>2 0] (\\<sigma> s) \\<and> (q s = []) \\<and> (hW s = 0) \\<and> (tW s = 0)\n                        \\<and> (\\<forall>l. (l<n) \\<longrightarrow>  ((Data s l > 0)\\<and>(Data s l \\<le> N)))\n                        \\<and> (\\<forall>i. (i<n) \\<longrightarrow>  ownD s i = W)\n                        \\<and> (\\<forall>i. (i\\<le>N) \\<longrightarrow>  ownB s i = B)\n                        \\<and> (countW s = 0) \\<and> (countR s = 0)\n                        \\<and> (tempR s = (0,0)) \\<and> \\<not> oom s \"\n\ndefinition \"grd1 s \\<equiv> (tW s = hW s) \\<and> (Data s (countW s) \\<le> N) \"\ndefinition \"grd2 s \\<equiv> (tW s > hW s) \\<and> (Data s (countW s) < (tW s - hW s)) \"\ndefinition \"grd3 s \\<equiv> tW s < hW s \"\ndefinition \"grd4 s \\<equiv> Data s (countW s) \\<le> N - hW s \"\ndefinition \"grd5 s \\<equiv> Data s (countW s) < tW s \"\ndefinition \"no_space_for_word s \\<equiv> (grd1 s \\<longrightarrow> \\<not>(Data s (countW s) \\<le> N))\\<and>\n                                  (grd2 s \\<longrightarrow> \\<not>(Data s (countW s) < (tW s - hW s)))\\<and>\n                                  (grd3 s \\<longrightarrow> \\<not>(Data s (countW s) \\<le> N - hW s \\<or> Data s (countW s) < tW s))\"\n\n\n\nlemmas main_invariant_lemmas = collection_def arrayInv_def q_entries_bounded_def \n                                      counter_q_rel_def tempR_bounded_def con_assms_def\n                                      init_def bounded_pointers_def basic_pointer_movement_def\n                                      pval_val_same pval_val_other pval_val \nlemmas guards = grd1_def grd2_def grd3_def grd4_def grd5_def no_space_for_word_def\n\n\nlemma LoadBuffering:\n \"\\<parallel>-   \\<lbrace> global \\<acute>\\<sigma>  \\<and> \\<acute>collection  \\<and> \\<acute>init \\<rbrace>\nCOBEGIN\n\\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection  \\<and> \\<not> \\<acute>oom \\<and> \\<acute>init\\<rbrace>\n  WHILE \\<acute>countW < n \n   INV \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> (\\<exists> i. [H =\\<^sub>2 i]\\<acute>\\<sigma>)\\<rbrace>\n   DO\n    \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> (\\<exists> i. [H =\\<^sub>2 i]\\<acute>\\<sigma>) \\<and> \\<acute>countW < n\\<rbrace> \\<comment> \\<open>A1\\<close>\n      <\\<acute>hW \\<leftarrow>\\<^sub>2 H\\<acute>\\<sigma>> ;;  \n    \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection  \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n\\<rbrace>\n      <\\<acute>tW \\<leftarrow>\\<^sub>2 T\\<acute>\\<sigma>> ;;\n    \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection  \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n\\<rbrace>\n      IF \\<acute>grd1 \\<comment> \\<open>A2\\<close>\n      THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd1 \\<rbrace> \\<comment> \\<open>A3\\<close>\n            <T :=\\<^sup>R\\<^sub>2 0 \\<acute>\\<sigma>> ;; \\<comment> \\<open>This might not need to be releasing\\<close>  \n            \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd1 \\<rbrace>\n            \\<langle><H :=\\<^sub>2 (\\<acute>Data \\<acute>countW) \\<acute>\\<sigma>> ,, \\<acute>hW := 0 ,, \\<acute>oom := False ,,\n              (\\<acute>ownB := ( \\<lambda> x. if 0\\<le> x \\<and> x < (\\<acute>Data \\<acute>countW) then W else \\<acute>ownB x ))\\<rangle>\n      ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<not>\\<acute>grd1 \\<rbrace> \n            IF \\<acute>grd2\n            THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd2\\<rbrace> \\<comment> \\<open>A4\\<close>\n                \\<langle><H :=\\<^sub>2 \\<acute>hW + (\\<acute>Data \\<acute>countW) \\<acute>\\<sigma>> ,, \\<acute>oom := False ,,\n                  (\\<acute>ownB := ( \\<lambda> x. if \\<acute>hW \\<le> x \\<and> x < (\\<acute>hW + (\\<acute>Data \\<acute>countW)) then W else \\<acute>ownB x ))\\<rangle>\n            ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<not>\\<acute>grd1 \\<and> \\<not>\\<acute>grd2\\<rbrace>\n                 IF \\<acute>grd3\n                 THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd3 \\<rbrace> \\<comment> \\<open>A5\\<close>\n                      IF \\<acute>grd4\n                      THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd3 \\<and> \\<acute>grd4 \\<rbrace> \\<comment> \\<open>A6\\<close>\n                      \\<langle><H :=\\<^sub>2 \\<acute>hW + (\\<acute>Data \\<acute>countW) \\<acute>\\<sigma>> ,, \\<acute>oom := False ,,\n                         (\\<acute>ownB := ( \\<lambda> x. if \\<acute>hW \\<le> x \\<and> x < (\\<acute>hW + (\\<acute>Data \\<acute>countW)) then W else \\<acute>ownB x ))\\<rangle>\n                      ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd3 \\<and> \\<not>\\<acute>grd4 \\<rbrace>\n                            IF \\<acute>grd5\n                            THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd3 \\<and> \\<acute>grd5 \\<rbrace> \\<comment> \\<open>A7\\<close>\n                              \\<langle><H :=\\<^sub>2 (\\<acute>Data \\<acute>countW) \\<acute>\\<sigma>> ,, \\<acute>hW := 0 ,, \\<acute>oom := False ,,\n                                (\\<acute>ownB := ( \\<lambda> x. if ((0 \\<le> x \\<and> x < (\\<acute>Data \\<acute>countW))\\<or> x\\<ge>T)\\<and>x\\<noteq>N then W else \\<acute>ownB x ))\\<rangle>\n                            ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>no_space_for_word\\<rbrace> \\<comment> \\<open>A8\\<close>\n                                \\<langle>\\<acute>oom := True\\<rangle>\n                                  \\<comment> \\<open>OOM\\<close>\n                            FI\n                      FI\n                 ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>no_space_for_word\\<rbrace>\n                      \\<langle>\\<acute>oom := True\\<rangle>\n                      \\<comment> \\<open>OOM\\<close>\n                 FI\n           FI\n     FI;;\n     \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection  \n        \\<and> ((\\<acute>oom=False \\<and> [H =\\<^sub>2 (\\<acute>hW+(\\<acute>Data \\<acute>countW))]\\<acute>\\<sigma> ) \\<comment> \\<open>\\<and> \\<acute>hW  + \\<acute>Data (\\<acute>countW) \\<le> N\\<close> \n             \\<or> (\\<acute>oom=True \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>no_space_for_word)) \\<and> \\<acute>countW < n\\<rbrace>\n     IF \\<acute>oom=True\n     THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>no_space_for_word \\<and> \\<acute>countW < n\\<rbrace> \\<comment> \\<open>OK\\<close>\n          SKIP\n     ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection  \\<and> \\<acute>countW < n \\<and> [H =\\<^sub>2 (\\<acute>hW+(\\<acute>Data \\<acute>countW))]\\<acute>\\<sigma>\\<rbrace>\n          \\<langle>\\<acute>q := \\<acute>q @ [(\\<acute>hW, (\\<acute>Data \\<acute>countW))],,  \n           \\<acute>ownD := (\\<lambda> x. if x = \\<acute>countW then B else \\<acute>ownD x),, \n           \\<acute>ownB := (\\<lambda> x. if (\\<acute>ownB x = W) then Q else \\<acute>ownB x),,  \n           \\<acute>countW := (\\<acute>countW+1)\\<rangle> \n     FI\n   OD \n    \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>countW = n\\<rbrace>\n\n\\<parallel>\n \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>tempR = (0, 0)  \\<rbrace>\n  WHILE \\<acute>countR < n\n  INV \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>tempR=(0,0)  \\<rbrace>\n  DO  \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>countR < n \\<and> \\<acute>tempR=(0,0)  \\<rbrace>\n      IF \\<acute>countR < \\<acute>countW THEN\n                \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>countR < \\<acute>countW \\<and> \\<acute>tempR=(0,0)  \\<rbrace> \\<comment> \\<open>retrieve from Q, dequeue\\<close>\n                \\<langle> \\<acute>tempR  := (fst(hd \\<acute>q),(snd(hd \\<acute>q))) ,,  \n                    \\<acute>ownD := (\\<lambda> x. if x = \\<acute>countR then R else \\<acute>ownD x),, \n                    \\<acute>countR := \\<acute>countR+1,, \n                    ( IF fst(hd \\<acute>q)\\<noteq>0 THEN (\\<acute>ownB := ( \\<lambda> x. if fst(hd \\<acute>q)  \\<le> x \\<and> x < (fst(hd \\<acute>q)+(snd(hd \\<acute>q))) then R else \\<acute>ownB x ))\n                      ELSE (\\<acute>ownB := ( \\<lambda> x. if (0 \\<le> x \\<and> x < (fst(hd \\<acute>q)+(snd(hd \\<acute>q))))\\<or>(\\<forall>i.(x+i<N\\<longrightarrow>\\<acute>ownB x=Q)) then R else \\<acute>ownB x )) FI),, \n                     \\<acute>q := (tl \\<acute>q) \\<rangle>;;\n                    \\<lbrace> global \\<acute>\\<sigma> \\<and>\\<acute>collection \\<and> \\<acute>countR \\<le> \\<acute>countW  \\<and> \\<acute>tempR\\<noteq>(0,0)\\<rbrace> \\<comment> \\<open>Push T\\<close>\n                    \\<langle><T :=\\<^sub>3 (fst \\<acute>tempR + snd \\<acute>tempR) \\<acute>\\<sigma> > \n                    ,, \\<acute> tempR := (0,0),, \n                   \\<acute>ownB := (\\<lambda> x. if \\<acute>ownB x = R then B else \\<acute>ownD x) \\<rangle>\n      ELSE\n      \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>tempR=(0,0) \\<and> \\<acute>countR < n \\<rbrace>\n      SKIP\n      FI\n  OD\n\\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>countR = n\\<rbrace>\n\n\n\nCOEND\n  \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>countW = n \\<and> \\<acute>countR = n\\<rbrace>\n  \n\n\"\n  apply (oghoare)\n  apply ((simp add: main_invariant_lemmas Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff; force)+)[4]\n  apply ((simp add: guards main_invariant_lemmas Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)[1]\n  apply (clarify)\n  apply (intro conjI impI)\n  apply (metis OpSem_ProofRules.d_obs_read_value d_obs_implies_p_obs le_less_linear)\n  apply (metis OpSem_ProofRules.d_obs_read_value OpSem_ProofRules.ext_d_obs_rd_pres)\n  apply auto[1]\n  apply ((simp add: guards main_invariant_lemmas Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)[1]\n  apply clarsimp\n  apply (meson not_less not_pobs_contradiction)\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  using pval_val apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply auto[3]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply auto[3]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply auto[1]\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply auto[1]\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis (no_types, lifting) Suc_diff_le d_obs_implies_p_obs fst_eqD le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply clarsimp\n  apply (simp_all add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)\n          (*129*)\n                      apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis (full_types) diff_is_0_eq hd_conv_nth length_0_conv length_greater_0_conv not_less)\n  apply linarith\n  apply auto[1]\n  apply (simp add: nth_tl)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth length_0_conv not_less0 zero_less_diff)\n  apply linarith\n  apply (metis (full_types) hd_conv_nth length_0_conv not_less0 snd_conv zero_less_diff)\n  using main_invariant_lemmas(12) apply auto[1]\n  using OpSem_ProofRules.ext_d_obs_d_obs apply blast\n  apply clarify\n  apply linarith\n  using OpSem_ProofRules.p_obs_contradiction apply blast\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply clarify\n  apply (intro conjI impI)\n  apply (metis One_nat_def Suc_eq_plus1 length_tl less_diff_conv nth_tl)\n  apply (metis One_nat_def Suc_eq_plus1 length_tl less_diff_conv nth_tl)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply clarify\n  apply (intro conjI impI)\n  apply (metis getVWNC_var leD pval_val)\n  apply (metis OpSem_ProofRules.ext_write_other_pres_d_obs)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (metis getVWNC_var leD pval_val)\n  apply (metis OpSem_ProofRules.ext_write_other_pres_d_obs)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply clarify                   \n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis getVWNC_var le_less_trans main_invariant_lemmas(12) nat_neq_iff)\n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply clarify\n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis getVWNC_var leD pval_val)    \n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (simp add: nth_tl)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth length_greater_0_conv zero_less_diff)\n  apply linarith\n  apply blast\n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply blast\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (simp add: nth_tl)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth length_greater_0_conv zero_less_diff)\n  apply linarith\n  apply blast\n  apply (metis getVWNC_var leD pval_val)\n  apply blast\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (simp add: nth_tl)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff) \n  apply linarith\n  apply blast\n  apply clarify\n  apply (metis getVWNC_var leD pval_val)\n  apply blast\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (simp add: nth_tl)    \n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)                \n  apply linarith\n  apply blast\n  apply clarify\n  apply (metis getVWNC_var leD pval_val)     \n  apply blast\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (simp add: nth_tl)    \n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)                \n  apply linarith\n  apply blast\n  apply clarify\n  apply (intro conjI impI)\n  apply (metis getVWNC_var leD pval_val)\n  apply (metis OpSem_ProofRules.ext_write_other_pres_d_obs)\n  apply clarify\n  apply (intro conjI impI)\n  apply blast\n  apply blast\n  apply blast\n  apply blast\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (simp add: nth_tl)    \n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)                \n  apply linarith\n  apply blast\n  apply clarify\n  apply (metis getVWNC_var leD pval_val)     \n  apply blast\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply (intro conjI impI)\n  apply (simp add: nth_tl)\n  apply (metis hd_conv_nth length_greater_0_conv zero_less_diff)        \n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis (full_types) Nat.add_0_right add.commute hd_conv_nth my_simp_list(1) not_less0 zero_less_diff)          \n  apply linarith                   \n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis (full_types) fst_conv not_less0 pval_val)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis (full_types) fst_conv not_less0 pval_val)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis (full_types) fst_conv not_less0 pval_val)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis (full_types) fst_conv not_less0 pval_val)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis (full_types) fst_conv not_less0 pval_val)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis (full_types) fst_conv not_less0 pval_val)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  by simp\n  \n\n\n\n\n\n(*(simp add: Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff )?)*)", "meta": {"author": "MSemenyuk", "repo": "PhD_Isabelle", "sha": "179f5d346a721b15940a271323e3487f4ea51338", "save_path": "github-repos/isabelle/MSemenyuk-PhD_Isabelle", "path": "github-repos/isabelle/MSemenyuk-PhD_Isabelle/PhD_Isabelle-179f5d346a721b15940a271323e3487f4ea51338/Amazon Ring Buffer/RB_Relaxed_mike_bd.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6513548511303336, "lm_q2_score": 0.4301473485858429, "lm_q1q2_score": 0.28017856220223947}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory IndirectCalls\n\nimports\n  \"PrettyProgs\"\n\nbegin\n\ndefinition\n  lookup_proc :: \"(string \\<Rightarrow> 'proc_addr) \\<Rightarrow> ('proc_id \\<rightharpoonup> string)\n    \\<Rightarrow> 'proc_addr \\<Rightarrow> 'proc_id\"\nwhere\n  \"lookup_proc symtab naming x\n    = (THE pid. naming pid \\<noteq> None \\<and> symtab (the (naming pid)) = x)\"\n\ndefinition\n  lookup_proc_safe :: \"(string \\<Rightarrow> 'proc_addr) \\<Rightarrow> ('proc_id \\<rightharpoonup> string)\n    \\<Rightarrow> 'proc_addr \\<Rightarrow> bool\"\nwhere\n  \"lookup_proc_safe symtab naming x\n    = (card {pid. naming pid \\<noteq> None \\<and> symtab (the (naming pid)) = x} = 1)\"\n\ndefinition\n  procs_consistent :: \"(string \\<Rightarrow> 'proc_addr) \\<Rightarrow> ('proc_nm \\<rightharpoonup> string)\n    \\<Rightarrow> bool\"\nwhere\n  \"procs_consistent symtab naming\n    = (finite (dom naming)\n        \\<and> (\\<forall>x y nm nm'. naming x = Some nm \\<and> naming y = Some nm'\n            \\<and> symtab nm = symtab nm'\n                \\<longrightarrow> x = y))\"\n\nlemma procs_consistent_eq:\n  \"\\<lbrakk> naming proc = Some nm; procs_consistent symtab naming; addr = symtab nm \\<rbrakk>\n    \\<Longrightarrow> lookup_proc symtab naming addr = proc\"\n  apply (clarsimp simp: procs_consistent_def lookup_proc_def)\n  apply (rule the_equality)\n   apply clarsimp\n  apply clarsimp\n  done\n\nlemma procs_consistent_safe:\n  \"\\<lbrakk> naming proc = Some nm; procs_consistent symtab naming; addr = symtab nm \\<rbrakk>\n    \\<Longrightarrow> lookup_proc_safe symtab naming addr\"\n  apply (clarsimp simp: procs_consistent_def lookup_proc_safe_def)\n  apply (rule trans, rule arg_cong[where f=card and y=\"{proc}\"])\n   apply auto\n  done\n\nlemma hoare_indirect_call_procs_consistent:\n  \"\\<lbrakk> naming proc = Some nm;\n        \\<Gamma> \\<turnstile> P (call initf proc ret c) Q, A \\<rbrakk>\n    \\<Longrightarrow> \\<Gamma> \\<turnstile> ({s. procs_consistent symtab naming \\<and> x_fn s = symtab nm} \\<inter> P)\n            (dynCall initf (\\<lambda>s. lookup_proc symtab naming (x_fn s))\n                    ret c) Q, A\"\n  apply (rule hoare_complete, drule hoare_sound)\n  apply (clarsimp simp: cvalid_def HoarePartialDef.valid_def)\n  apply (erule exec_dynCall_Normal_elim)\n  apply (simp add: procs_consistent_eq)\n  apply blast\n  done\n\nend\n\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/c-parser/IndirectCalls.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926665999540698, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.2801437089431009}}
{"text": "theory PartialEvaluation\nimports BananasBigStepDynamics\nbegin\n\nfun partial_evaluation :: \"dynamic_environment \\<Rightarrow> nat \\<Rightarrow> expr \\<Rightarrow> val \\<Rightarrow> val option\" where\n  \"partial_evaluation \\<Lambda> n \\<epsilon> v = Some v\"\n| \"partial_evaluation \\<Lambda> n (\\<kappa> v\\<^sub>1) v\\<^sub>2 = Some v\\<^sub>1\"\n| \"partial_evaluation \\<Lambda> n (f \\<cdot> g) v = (case partial_evaluation \\<Lambda> n g v of \n      Some v' \\<Rightarrow> partial_evaluation \\<Lambda> n f v'\n    | None \\<Rightarrow> None)\"\n| \"partial_evaluation \\<Lambda> n \\<pi>\\<^sub>1 (PairV v\\<^sub>1 v\\<^sub>2) = Some v\\<^sub>1\"\n| \"partial_evaluation \\<Lambda> n \\<pi>\\<^sub>1 _ = None\"\n| \"partial_evaluation \\<Lambda> n \\<pi>\\<^sub>2 (PairV v\\<^sub>1 v\\<^sub>2) = Some v\\<^sub>2\"\n| \"partial_evaluation \\<Lambda> n \\<pi>\\<^sub>2 _ = None\"\n| \"partial_evaluation \\<Lambda> n (f\\<^sub>1 \\<parallel> f\\<^sub>2) (PairV v\\<^sub>1 v\\<^sub>2) = (case partial_evaluation \\<Lambda> n f\\<^sub>1 v\\<^sub>1 of \n      Some v\\<^sub>1' \\<Rightarrow> (case partial_evaluation \\<Lambda> n f\\<^sub>2 v\\<^sub>2 of \n          Some v\\<^sub>2' \\<Rightarrow> Some (PairV v\\<^sub>1' v\\<^sub>2')\n        | None \\<Rightarrow> None)\n    | None \\<Rightarrow> None)\"\n| \"partial_evaluation \\<Lambda> n (f\\<^sub>1 \\<parallel> f\\<^sub>2) _ = None\"\n| \"partial_evaluation \\<Lambda> n \\<Theta> v = Some (PairV v v)\"\n| \"partial_evaluation \\<Lambda> n \\<iota>\\<^sub>l v = Some (InlV v)\"\n| \"partial_evaluation \\<Lambda> n \\<iota>\\<^sub>r v = Some (InrV v)\"\n| \"partial_evaluation \\<Lambda> n \\<Xi> (InlV v) = Some v\"\n| \"partial_evaluation \\<Lambda> n \\<Xi> (InrV v) = Some v\"\n| \"partial_evaluation \\<Lambda> n \\<Xi> _ = None\"\n| \"partial_evaluation \\<Lambda> n (f\\<^sub>l \\<bar> f\\<^sub>r) (InlV v) = partial_evaluation \\<Lambda> n (\\<iota>\\<^sub>l \\<cdot> f\\<^sub>l) v\"\n| \"partial_evaluation \\<Lambda> n (f\\<^sub>l \\<bar> f\\<^sub>r) (InrV v) = partial_evaluation \\<Lambda> n (\\<iota>\\<^sub>r \\<cdot> f\\<^sub>r) v\"\n| \"partial_evaluation \\<Lambda> n (f\\<^sub>l \\<bar> f\\<^sub>r) _ = None\"\n| \"partial_evaluation \\<Lambda> n \\<rhd> (PairV (InlV v\\<^sub>1) v\\<^sub>2) = Some (InlV (PairV v\\<^sub>1 v\\<^sub>2))\"\n| \"partial_evaluation \\<Lambda> n \\<rhd> (PairV (InrV v\\<^sub>1) v\\<^sub>2) = Some (InrV (PairV v\\<^sub>1 v\\<^sub>2))\"\n| \"partial_evaluation \\<Lambda> n \\<rhd> _ = None\"\n| \"partial_evaluation \\<Lambda> (Suc n) $ (PairV (FunV e) v) = partial_evaluation \\<Lambda> n e v\"\n| \"partial_evaluation \\<Lambda> n $ _ = None\"\n| \"partial_evaluation \\<Lambda> n (g \\<leftarrow> f) (FunV e) = Some (FunV (g \\<cdot> e \\<cdot> f))\"\n| \"partial_evaluation \\<Lambda> n (g \\<leftarrow> f) _ = None\"\n| \"partial_evaluation \\<Lambda> n \\<succ>\\<^bsub>x\\<^esub> v = Some (InjV x v)\"\n| \"partial_evaluation \\<Lambda> n \\<prec>\\<^bsub>x\\<^esub> (InjV y v) = Some v\"\n| \"partial_evaluation \\<Lambda> n \\<prec>\\<^bsub>x\\<^esub> _ = None\"\n| \"partial_evaluation \\<Lambda> (Suc n) \\<lparr> f \\<rparr>\\<^bsub>x\\<^esub> v = (case var\\<^sub>t_bind \\<Lambda> x of \n      Some F \\<Rightarrow> partial_evaluation \\<Lambda> n (f \\<cdot> \\<lparr> f \\<rparr>\\<^bsub>x\\<^esub> \\<bullet> F \\<cdot> \\<prec>\\<^bsub>x\\<^esub>) v\n    | None \\<Rightarrow> None)\"\n| \"partial_evaluation \\<Lambda> 0 \\<lparr> f \\<rparr>\\<^bsub>x\\<^esub> _ = None\"\n| \"partial_evaluation \\<Lambda> (Suc n) \\<lbrakk> f \\<rbrakk>\\<^bsub>x\\<^esub> v = (case var\\<^sub>t_bind \\<Lambda> x of \n      Some F \\<Rightarrow> partial_evaluation \\<Lambda> n (\\<succ>\\<^bsub>x\\<^esub> \\<cdot> \\<lbrakk> f \\<rbrakk>\\<^bsub>x\\<^esub> \\<bullet> F \\<cdot> f) v\n    | None \\<Rightarrow> None)\"\n| \"partial_evaluation \\<Lambda> 0 \\<lbrakk> f \\<rbrakk>\\<^bsub>x\\<^esub> _ = None\"\n| \"partial_evaluation \\<Lambda> 0 (Var x) _ = None\"\n| \"partial_evaluation \\<Lambda> (Suc n) (Var x) v = (case var\\<^sub>e_bind \\<Lambda> x of \n      Some e \\<Rightarrow> partial_evaluation \\<Lambda> n e v \n    | None \\<Rightarrow> None )\"\n\nprimrec algorithmic_assemble_context :: \"decl list \\<Rightarrow> dynamic_environment\" where\n  \"algorithmic_assemble_context [] = empty_dynamic\"\n| \"algorithmic_assemble_context (\\<delta> # \\<Lambda>) = \n    combine\\<^sub>d (assemble_context' something \\<delta>) (assemble_context \\<Lambda>)\"\n\nprimrec partial_eval_prog :: \"nat \\<Rightarrow> prog \\<Rightarrow> val option\" where\n  \"partial_eval_prog n (Prog \\<Lambda> e v) = partial_evaluation (algorithmic_assemble_context \\<Lambda>) n e v\"\n\n(* correctness *)\n\nlemma soundness': \"partial_evaluation \\<Lambda> n e v = Some v' \\<Longrightarrow> \\<Lambda> \\<turnstile> e \\<cdot> v \\<Down> v'\"\n  proof (induction \\<Lambda> n e v arbitrary: v' rule: partial_evaluation.induct)\n  case 3\n    thus ?case by (simp split: option.splits) fastforce\n  next case 8\n    thus ?case by (auto split: option.splits)\n  next case (16 \\<Lambda> n f\\<^sub>l f\\<^sub>r v)\n    hence \"\\<Lambda> \\<turnstile> (\\<iota>\\<^sub>l \\<cdot> f\\<^sub>l) \\<cdot> v \\<Down> v'\" by simp\n    moreover have \"\\<Lambda> \\<turnstile> f\\<^sub>l \\<bar> f\\<^sub>r \\<cdot> InlV v \\<leadsto> (\\<iota>\\<^sub>l \\<cdot> f\\<^sub>l) \\<cdot> v\" by simp\n    ultimately show ?case by (metis tev_step)\n  next case (17 \\<Lambda> n f\\<^sub>l f\\<^sub>r v)\n    hence \"\\<Lambda> \\<turnstile> (\\<iota>\\<^sub>r \\<cdot> f\\<^sub>r) \\<cdot> v \\<Down> v'\" by simp\n    moreover have \"\\<Lambda> \\<turnstile> f\\<^sub>l \\<bar> f\\<^sub>r \\<cdot> InrV v \\<leadsto> (\\<iota>\\<^sub>r \\<cdot> f\\<^sub>r) \\<cdot> v\" by simp\n    ultimately show ?case by (metis tev_step)\n  next case (22 \\<Lambda> n e v)\n    hence \"\\<Lambda> \\<turnstile> e \\<cdot> v \\<Down> v'\" by simp\n    moreover have \"\\<Lambda> \\<turnstile> $ \\<cdot> PairV (FunV e) v \\<leadsto> e \\<cdot> v\" by simp\n    ultimately show ?case by (metis tev_step)\n  next case 27\n    thus ?case by (simp split: if_splits)\n  next case (29 \\<Lambda> n f x v)\n    moreover then obtain F where \"var\\<^sub>t_bind \\<Lambda> x = Some F \\<and> \n      partial_evaluation \\<Lambda> n (f \\<cdot> \\<lparr> f \\<rparr>\\<^bsub>x\\<^esub> \\<bullet> F \\<cdot> \\<prec>\\<^bsub>x\\<^esub>) v = Some v'\" by (auto split: option.splits)\n    moreover hence \"\\<Lambda> \\<turnstile> \\<lparr> f \\<rparr>\\<^bsub>x\\<^esub> \\<cdot> v \\<leadsto> (f \\<cdot> \\<lparr> f \\<rparr>\\<^bsub>x\\<^esub> \\<bullet> F \\<cdot> \\<prec>\\<^bsub>x\\<^esub>) \\<cdot> v\" by simp\n    ultimately show ?case by (metis tev_step)\n  next case (31 \\<Lambda> n f x v)\n    moreover then obtain F where \"var\\<^sub>t_bind \\<Lambda> x = Some F \\<and> \n      partial_evaluation \\<Lambda> n (\\<succ>\\<^bsub>x\\<^esub> \\<cdot> \\<lbrakk> f \\<rbrakk>\\<^bsub>x\\<^esub> \\<bullet> F \\<cdot> f) v = Some v'\" by (auto split: option.splits)\n    moreover hence \"\\<Lambda> \\<turnstile> \\<lbrakk> f \\<rbrakk>\\<^bsub>x\\<^esub> \\<cdot> v \\<leadsto> (\\<succ>\\<^bsub>x\\<^esub> \\<cdot> \\<lbrakk> f \\<rbrakk>\\<^bsub>x\\<^esub> \\<bullet> F \\<cdot> f) \\<cdot> v\" by simp\n    ultimately show ?case by (metis tev_step)\n  next case (34 \\<Lambda> n x v)\n    moreover then obtain e where E: \"var\\<^sub>e_bind \\<Lambda> x = Some e \\<and> partial_evaluation \\<Lambda> n e v = Some v'\" \n      by (auto split: option.splits)\n    ultimately have \"\\<Lambda> \\<turnstile> e \\<cdot> v \\<Down> v'\" by simp\n    moreover from E have \"\\<Lambda> \\<turnstile> Var x \\<cdot> v \\<leadsto> e \\<cdot> v\" by simp\n    ultimately show ?case by (metis tev_step)\n  qed auto\n\nlemma pev_larger [elim]: \"partial_evaluation \\<Lambda> n e v = Some v' \\<Longrightarrow> n \\<le> m \\<Longrightarrow> \n    partial_evaluation \\<Lambda> m e v = Some v'\"\n  proof (induction \\<Lambda> n e v arbitrary: v' m rule: partial_evaluation.induct)\n  case (3 \\<Lambda> n f g v)\n    from 3(3) obtain v\\<^sub>1 where V: \"partial_evaluation \\<Lambda> n g v = Some v\\<^sub>1 \\<and> \n      partial_evaluation \\<Lambda> n f v\\<^sub>1 = Some v'\" by (auto split: option.splits)\n    with 3 have \"partial_evaluation \\<Lambda> m g v = Some v\\<^sub>1\" by blast\n    moreover from 3 V have \"partial_evaluation \\<Lambda> m f v\\<^sub>1 = Some v'\" by blast\n    ultimately show ?case by simp\n  next case (8 \\<Lambda> n f\\<^sub>1 f\\<^sub>2 v\\<^sub>1 v\\<^sub>2)\n    moreover from 8(3) obtain v\\<^sub>1' v\\<^sub>2' where V: \"partial_evaluation \\<Lambda> n f\\<^sub>1 v\\<^sub>1 = Some v\\<^sub>1' \\<and> \n      partial_evaluation \\<Lambda> n f\\<^sub>2 v\\<^sub>2 = Some v\\<^sub>2' \\<and> v' = PairV v\\<^sub>1' v\\<^sub>2'\" by (auto split: option.splits)\n    ultimately show ?case by simp\n  next case (16 \\<Lambda> n f\\<^sub>l f\\<^sub>r v)\n    moreover from 16(2) obtain v\\<^sub>1 where \"partial_evaluation \\<Lambda> n f\\<^sub>l v = Some v\\<^sub>1 \\<and> \n      partial_evaluation \\<Lambda> n \\<iota>\\<^sub>l v\\<^sub>1 = Some v'\" by (auto split: option.splits)\n    ultimately show ?case by simp\n  next case (17 \\<Lambda> n f\\<^sub>l f\\<^sub>r v)\n    moreover from 17(2) obtain v\\<^sub>1 where \"partial_evaluation \\<Lambda> n f\\<^sub>r v = Some v\\<^sub>1 \\<and> \n      partial_evaluation \\<Lambda> n \\<iota>\\<^sub>r v\\<^sub>1 = Some v'\" by (auto split: option.splits)\n    ultimately show ?case by simp\n  next case (22 \\<Lambda> n e v)\n    thus ?case\n      proof (induction m)\n      case (Suc m)\n        moreover from Suc(3) have \"partial_evaluation \\<Lambda> n e v = Some v'\" by simp\n        ultimately have \"partial_evaluation \\<Lambda> m e v = Some v'\" by blast\n        thus ?case by simp\n      qed simp_all\n  next case (29 \\<Lambda> n f x v)\n    thus ?case\n      proof (induction m)\n      case (Suc m)\n        moreover from Suc(3) obtain v\\<^sub>1 v\\<^sub>2 F where F: \"var\\<^sub>t_bind \\<Lambda> x = Some F \\<and> \n          partial_evaluation \\<Lambda> n \\<prec>\\<^bsub>x\\<^esub> v = Some v\\<^sub>1 \\<and> \n            partial_evaluation \\<Lambda> n (\\<lparr> f \\<rparr>\\<^bsub>x\\<^esub> \\<bullet> F) v\\<^sub>1 = Some v\\<^sub>2 \\<and> \n              partial_evaluation \\<Lambda> n f v\\<^sub>2 = Some v'\" by (auto split: option.splits)\n        moreover hence \"partial_evaluation \\<Lambda> n (f \\<cdot> \\<lparr> f \\<rparr>\\<^bsub>x\\<^esub> \\<bullet> F \\<cdot> \\<prec>\\<^bsub>x\\<^esub>) v = Some v'\" by simp\n        ultimately have \"partial_evaluation \\<Lambda> m (f \\<cdot> \\<lparr> f \\<rparr>\\<^bsub>x\\<^esub> \\<bullet> F \\<cdot> \\<prec>\\<^bsub>x\\<^esub>) v = Some v'\" by blast\n        with F show ?case by simp\n      qed simp_all\n  next case (31 \\<Lambda> n f x v)\n    thus ?case\n      proof (induction m)\n      case (Suc m)\n        moreover from Suc(3) obtain v\\<^sub>1 v\\<^sub>2 F where F: \"var\\<^sub>t_bind \\<Lambda> x = Some F \\<and> \n          partial_evaluation \\<Lambda> n f v = Some v\\<^sub>1 \\<and>\n            partial_evaluation \\<Lambda> n (\\<lbrakk> f \\<rbrakk>\\<^bsub>x\\<^esub> \\<bullet> F) v\\<^sub>1 = Some v\\<^sub>2 \\<and> \n              partial_evaluation \\<Lambda> n \\<succ>\\<^bsub>x\\<^esub> v\\<^sub>2 = Some v'\" by (auto split: option.splits)\n        moreover hence \"partial_evaluation \\<Lambda> n (\\<succ>\\<^bsub>x\\<^esub> \\<cdot> \\<lbrakk> f \\<rbrakk>\\<^bsub>x\\<^esub> \\<bullet> F \\<cdot> f) v = Some v'\" by simp\n        ultimately have \"partial_evaluation \\<Lambda> m (\\<succ>\\<^bsub>x\\<^esub> \\<cdot> \\<lbrakk> f \\<rbrakk>\\<^bsub>x\\<^esub> \\<bullet> F \\<cdot> f) v = Some v'\" by blast\n        with F show ?case by simp\n      qed simp_all\n  next case (34 \\<Lambda> n x v)\n    thus ?case\n      proof (induction m)\n      case (Suc m)\n        from Suc(3) obtain e where \"var\\<^sub>e_bind \\<Lambda> x = Some e \\<and> partial_evaluation \\<Lambda> n e v = Some v'\" \n          by (auto split: option.splits)\n        moreover with Suc have \"partial_evaluation \\<Lambda> m e v = Some v'\" by blast\n        ultimately show ?case by simp\n      qed simp_all\n  qed simp_all\n\nlemma completeness': \"\\<Lambda> \\<turnstile> e \\<cdot> v \\<Down> v' \\<Longrightarrow> \\<exists>n. partial_evaluation \\<Lambda> n e v = Some v'\"\n  proof (induction \\<Lambda> e v v' rule: total_eval.induct)\n  case (tev_step \\<Lambda> e v e' v' v'')\n    thus ?case\n      proof (induction \\<Lambda> e v e' v' arbitrary: v'' rule: evaluate.induct)\n      case (ev_comp1 \\<Lambda> g v g' v' f)\n        moreover then obtain n v\\<^sub>1 where N: \"partial_evaluation \\<Lambda> n g' v' = Some v\\<^sub>1 \\<and> \n          partial_evaluation \\<Lambda> n f v\\<^sub>1 = Some v''\" by (auto split: option.splits)\n        moreover hence \"\\<Lambda> \\<turnstile> g' \\<cdot> v' \\<Down> v\\<^sub>1\" by (metis soundness')\n        ultimately obtain m where M: \"partial_evaluation \\<Lambda> m g v = Some v\\<^sub>1\" by auto\n        have \"max n m \\<ge> m \\<and> max n m \\<ge> n\" by simp\n        with M N have \"partial_evaluation \\<Lambda> (max n m) f v\\<^sub>1 = Some v'' \\<and> \n          partial_evaluation \\<Lambda> (max n m) g v = Some v\\<^sub>1\" by (metis pev_larger)\n        hence \"partial_evaluation \\<Lambda> (max n m) (f \\<cdot> g) v = Some v''\" by simp\n        thus ?case by fastforce\n      next case (ev_pair1 \\<Lambda> f\\<^sub>1 v\\<^sub>1 f\\<^sub>1' v\\<^sub>1' f\\<^sub>2 v\\<^sub>2)\n        then obtain n v\\<^sub>1'' v\\<^sub>2' where N: \"partial_evaluation \\<Lambda> n f\\<^sub>1' v\\<^sub>1' = Some v\\<^sub>1'' \\<and> \n          partial_evaluation \\<Lambda> n f\\<^sub>2 v\\<^sub>2 = Some v\\<^sub>2' \\<and> v'' = PairV v\\<^sub>1'' v\\<^sub>2'\" \n            by (auto split: option.splits) fastforce\n        with ev_pair1 have \"\\<Lambda> \\<turnstile> f\\<^sub>1' \\<parallel> f\\<^sub>2 \\<cdot> PairV v\\<^sub>1' v\\<^sub>2 \\<Down> PairV v\\<^sub>1'' v\\<^sub>2'\" by simp\n        hence \"(\\<Lambda> \\<turnstile> f\\<^sub>1' \\<cdot> v\\<^sub>1' \\<Down> v\\<^sub>1'') \\<and> \\<Lambda> \\<turnstile> f\\<^sub>2 \\<cdot> v\\<^sub>2 \\<Down> v\\<^sub>2'\" by (metis pair_big_eval)\n        with ev_pair1 N obtain m where M: \"partial_evaluation \\<Lambda> m f\\<^sub>1 v\\<^sub>1 = Some v\\<^sub>1''\" by auto\n        have \"max n m \\<ge> m \\<and> max n m \\<ge> n\" by simp\n        with M N have \"partial_evaluation \\<Lambda> (max n m) f\\<^sub>1 v\\<^sub>1 = Some v\\<^sub>1'' \\<and> \n          partial_evaluation \\<Lambda> (max n m) f\\<^sub>2 v\\<^sub>2 = Some v\\<^sub>2'\" by (metis pev_larger)\n        with N have \"partial_evaluation \\<Lambda> (max n m) (f\\<^sub>1 \\<parallel> f\\<^sub>2) (PairV v\\<^sub>1 v\\<^sub>2) = Some v''\" by simp\n        thus ?case by fastforce\n      next case (ev_pair2 \\<Lambda> f\\<^sub>2 v\\<^sub>2 f\\<^sub>2' v\\<^sub>2' v\\<^sub>1)\n        then obtain n v\\<^sub>2'' where V: \"partial_evaluation \\<Lambda> n f\\<^sub>2' v\\<^sub>2' = Some v\\<^sub>2'' \\<and> v'' = PairV v\\<^sub>1 v\\<^sub>2''\" \n          by (auto split: option.splits)\n        with ev_pair2 have \"\\<Lambda> \\<turnstile> \\<epsilon> \\<parallel> f\\<^sub>2' \\<cdot> PairV v\\<^sub>1 v\\<^sub>2' \\<Down> PairV v\\<^sub>1 v\\<^sub>2''\" by simp\n        hence \"\\<Lambda> \\<turnstile> f\\<^sub>2' \\<cdot> v\\<^sub>2' \\<Down> v\\<^sub>2''\" by (metis pair_big_eval)\n        with ev_pair2 V obtain m where \"partial_evaluation \\<Lambda> m f\\<^sub>2 v\\<^sub>2 = Some v\\<^sub>2''\" by auto\n        with V have \"partial_evaluation \\<Lambda> m (\\<epsilon> \\<parallel> f\\<^sub>2) (PairV v\\<^sub>1 v\\<^sub>2) = Some v''\" by simp\n        thus ?case by fastforce\n      next case (ev_app \\<Lambda> e v)\n        then obtain n where \"partial_evaluation \\<Lambda> n e v = Some v''\" by blast\n        hence \"partial_evaluation \\<Lambda> (Suc n) $ (PairV (FunV e) v) = Some v''\" by simp\n        thus ?case by fastforce\n      next case ev_outj\n        thus ?case by simp\n      next case (ev_cata \\<Lambda> x F f v)\n        moreover then obtain n where \"partial_evaluation \\<Lambda> n (f \\<cdot> \\<lparr> f \\<rparr>\\<^bsub>x\\<^esub> \\<bullet> F \\<cdot> \\<prec>\\<^bsub>x\\<^esub>) v = Some v''\" \n          by blast\n        ultimately have \"partial_evaluation \\<Lambda> (Suc n) \\<lparr> f \\<rparr>\\<^bsub>x\\<^esub> v = Some v''\" by simp\n        thus ?case by fastforce\n      next case (ev_ana \\<Lambda> x F f v)\n        moreover then obtain n where \"partial_evaluation \\<Lambda> n (\\<succ>\\<^bsub>x\\<^esub> \\<cdot> \\<lbrakk> f \\<rbrakk>\\<^bsub>x\\<^esub> \\<bullet> F \\<cdot> f) v = Some v''\" \n          by blast\n        ultimately have \"partial_evaluation \\<Lambda> (Suc n) \\<lbrakk> f \\<rbrakk>\\<^bsub>x\\<^esub> v = Some v''\" by simp\n        thus ?case by fastforce\n      next case (ev_var \\<Lambda> x e v)\n        moreover then obtain n where \"partial_evaluation \\<Lambda> n e v = Some v''\" by blast\n        ultimately have \"partial_evaluation \\<Lambda> (Suc n) (Var x) v = Some v''\" by simp\n        thus ?case by fastforce\n      qed auto \n  qed simp_all\n\ntheorem soundness: \"partial_eval_prog n \\<Pi> = Some v \\<Longrightarrow> \\<Pi> \\<Down> v\"\n  by (induction \\<Pi>) (simp add: soundness')\n\ntheorem completeness: \"\\<Pi> \\<Down> v \\<Longrightarrow> \\<exists>n. partial_eval_prog n \\<Pi> = Some v\"\n  by (simp, induction \\<Pi> v rule: total_evaluate_prog'.induct) (simp add: completeness')\n\nend", "meta": {"author": "xtreme-james-cooper", "repo": "Bananas", "sha": "aeecb3ef1e7994d6c080c8f4800f7aabcde30e15", "save_path": "github-repos/isabelle/xtreme-james-cooper-Bananas", "path": "github-repos/isabelle/xtreme-james-cooper-Bananas/Bananas-aeecb3ef1e7994d6c080c8f4800f7aabcde30e15/PartialEvaluation.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631698328916, "lm_q2_score": 0.46101677931231594, "lm_q1q2_score": 0.2801429174630725}}
{"text": "(*  Title:      JinjaThreads/Execute/TypeRelRefine.thy\n    Author:     Andreas Lochbihler\n\n    Tabulation for lookup functions\n*)\n\nheader {* \\isaheader{Tabulation for lookup functions} *}\n\ntheory TypeRelRefine\nimports\n  \"../Common/TypeRel\"\n  \"~~/src/HOL/Library/AList_Mapping\"\nbegin\n\nsubsection {* Auxiliary lemmata *}\n\n\n\nlemma map_of_map2: \"map_of (map (\\<lambda>(k, v). (k, f k v)) xs) k = map_option (f k) (map_of xs k)\"\nby(induct xs) auto\n\nlemma map_of_map_K: \"map_of (map (\\<lambda>k. (k, c)) xs) k = (if k \\<in> set xs then Some c else None)\"\nby(induct xs) auto\n\nlift_definition map_values :: \"('a \\<Rightarrow> 'b \\<Rightarrow> 'c) \\<Rightarrow> ('a, 'b) mapping \\<Rightarrow> ('a, 'c) mapping\"\nis \"\\<lambda>f m k. map_option (f k) (m k)\" .\n\n\n\nlemma map_Mapping: \"Mapping.map f g (Mapping.Mapping m) = Mapping.Mapping (map_option g \\<circ> m \\<circ> f)\"\nby(rule map.abs_eq)\n\nabbreviation subclst :: \"'m prog \\<Rightarrow> cname \\<Rightarrow> cname \\<Rightarrow> bool\"\nwhere \"subclst P \\<equiv> (subcls1 P)^++\"\n\nsubsection {* Representation type for tabulated lookup functions *}\n\ntype_synonym\n  'm prog_impl' = \n  \"'m cdecl list \\<times>\n   (cname, 'm class) mapping \\<times>\n   (cname, cname set) mapping \\<times> \n   (cname, (vname, cname \\<times> ty \\<times> fmod) mapping) mapping \\<times> \n   (cname, (mname, cname \\<times> ty list \\<times> ty \\<times> 'm option) mapping) mapping\"\n\nlift_definition tabulate_class :: \"'m cdecl list \\<Rightarrow> (cname, 'm class) mapping\"\nis \"class \\<circ> Program\" .\n\nlift_definition tabulate_subcls :: \"'m cdecl list \\<Rightarrow> (cname, cname set) mapping\"\nis \"\\<lambda>P C. if is_class (Program P) C then Some {D. Program P \\<turnstile> C \\<preceq>\\<^sup>* D} else None\" .\n\nlift_definition tabulate_sees_field :: \"'m cdecl list \\<Rightarrow> (cname, (vname, cname \\<times> ty \\<times> fmod) mapping) mapping\"\nis \"\\<lambda>P C. if is_class (Program P) C then\n        Some (\\<lambda>F. if \\<exists>T fm D. Program P \\<turnstile> C sees F:T (fm) in D then Some (field (Program P) C F) else None)\n      else None\" .\n\nlift_definition tabulate_Method :: \"'m cdecl list \\<Rightarrow> (cname, (mname, cname \\<times> ty list \\<times> ty \\<times> 'm option) mapping) mapping\"\nis \"\\<lambda>P C. if is_class (Program P) C then\n         Some (\\<lambda>M. if \\<exists>Ts T mthd D. Program P \\<turnstile> C sees M:Ts\\<rightarrow>T=mthd in D then Some (method (Program P) C M) else None)\n      else None\" .\n\nfun wf_prog_impl' :: \"'m prog_impl' \\<Rightarrow> bool\"\nwhere\n  \"wf_prog_impl' (P, c, s, f, m) \\<longleftrightarrow>\n  c = tabulate_class P \\<and>\n  s = tabulate_subcls P \\<and>\n  f = tabulate_sees_field P \\<and>\n  m = tabulate_Method P\"\n\nsubsection {* Implementation type for tabulated lookup functions *}\n\ntypedef 'm prog_impl = \"{P :: 'm prog_impl'. wf_prog_impl' P}\"\n  morphisms impl_of ProgRefine \nproof\n  show \"([], Mapping.empty, Mapping.empty, Mapping.empty, Mapping.empty) \\<in> ?prog_impl\"\n    apply clarsimp\n    by transfer (simp_all add: fun_eq_iff is_class_def rel_funI)\nqed\n\nlemma impl_of_ProgImpl [simp]:\n  \"wf_prog_impl' Pfsm \\<Longrightarrow> impl_of (ProgRefine Pfsm) = Pfsm\"\nby(simp add: ProgRefine_inverse)\n\ndefinition program :: \"'m prog_impl \\<Rightarrow> 'm prog\"\nwhere \"program = Program \\<circ> fst \\<circ> impl_of\"\n\ncode_datatype program\n\nlemma prog_impl_eq_iff:\n  \"Pi = Pi' \\<longleftrightarrow> program Pi = program Pi'\"\napply(cases Pi)\napply(cases Pi')\napply(auto simp add: ProgRefine_inverse program_def ProgRefine_inject)\ndone\n\nlemma wf_prog_impl'_impl_of [simp, intro!]:\n  \"wf_prog_impl' (impl_of Pi)\"\nusing impl_of[of Pi] by simp\n\nlemma ProgImpl_impl_of [simp, code abstype]:\n  \"ProgRefine (impl_of Pi) = Pi\"\nby(rule impl_of_inverse)\n\nlemma program_ProgRefine [simp]: \"wf_prog_impl' Psfm \\<Longrightarrow> program (ProgRefine Psfm) = Program (fst Psfm)\"\nby(simp add: program_def)\n\nlemma classes_program [code]: \"classes (program P) = fst (impl_of P)\"\nby(simp add: program_def)\n\nlemma class_program [code]: \"class (program Pi) = Mapping.lookup (fst (snd (impl_of Pi)))\"\nby(cases Pi)(clarsimp simp add: tabulate_class_def lookup.rep_eq Mapping_inverse)\n\nsubsection {* Refining sub class and lookup functions to use precomputed mappings *}\n\ndeclare subcls'.equation [code del]\n\nlemma subcls'_program [code]: \n  \"subcls' (program Pi) C D \\<longleftrightarrow> \n  C = D \\<or>\n  (case Mapping.lookup (fst (snd (snd (impl_of Pi)))) C of None \\<Rightarrow> False\n   | Some m \\<Rightarrow> D \\<in> m)\"\napply(cases Pi)\napply(clarsimp simp add: subcls'_def tabulate_subcls_def lookup.rep_eq Mapping_inverse)\napply(auto elim!: rtranclp_tranclpE dest: subcls_is_class intro: tranclp_into_rtranclp)\ndone\n\nlemma subcls'_i_i_i_program [code]:\n  \"subcls'_i_i_i P C D = (if subcls' P C D then Predicate.single () else bot)\"\nby(rule pred_eqI)(auto elim: subcls'_i_i_iE intro: subcls'_i_i_iI)\n\nlemma subcls'_i_i_o_program [code]:\n  \"subcls'_i_i_o (program Pi) C = \n  sup (Predicate.single C) (case Mapping.lookup (fst (snd (snd (impl_of Pi)))) C of None \\<Rightarrow> bot | Some m \\<Rightarrow> pred_of_set m)\"\nby(cases Pi)(fastforce simp add: subcls'_i_i_o_def subcls'_def tabulate_subcls_def lookup.rep_eq Mapping_inverse intro!: pred_eqI split: split_if_asm elim: rtranclp_tranclpE dest: subcls_is_class intro: tranclp_into_rtranclp)\n\nlemma rtranclp_FioB_i_i_subcls1_i_i_o_code [code_unfold]:\n  \"rtranclp_FioB_i_i (subcls1_i_i_o P) = subcls'_i_i_i P\"\nby(auto simp add: fun_eq_iff subcls1_i_i_o_def subcls'_def rtranclp_FioB_i_i_def subcls'_i_i_i_def)\n\ndeclare Method.equation[code del]\nlemma Method_program [code]:\n  \"program Pi \\<turnstile> C sees M:Ts\\<rightarrow>T=meth in D \\<longleftrightarrow> \n  (case Mapping.lookup (snd (snd (snd (snd (impl_of Pi))))) C of \n    None \\<Rightarrow> False\n  | Some m \\<Rightarrow> \n    (case Mapping.lookup m M of \n       None \\<Rightarrow> False\n     | Some (D', Ts', T', meth') \\<Rightarrow> Ts = Ts' \\<and> T = T' \\<and> meth = meth' \\<and> D = D'))\"\nby(cases Pi)(auto split: split_if_asm dest: sees_method_is_class simp add: tabulate_Method_def lookup.rep_eq Mapping_inverse)\n\nlemma Method_i_i_i_o_o_o_o_program [code]:\n  \"Method_i_i_i_o_o_o_o (program Pi) C M = \n  (case Mapping.lookup (snd (snd (snd (snd (impl_of Pi))))) C of\n    None \\<Rightarrow> bot\n  | Some m \\<Rightarrow>\n    (case Mapping.lookup m M of\n      None \\<Rightarrow> bot\n    | Some (D, Ts, T, meth) \\<Rightarrow> Predicate.single (Ts, T, meth, D)))\"\nby(auto simp add: Method_i_i_i_o_o_o_o_def Method_program intro!: pred_eqI)\n\nlemma Method_i_i_i_o_o_o_i_program [code]:\n  \"Method_i_i_i_o_o_o_i (program Pi) C M D = \n  (case Mapping.lookup (snd (snd (snd (snd (impl_of Pi))))) C of\n    None \\<Rightarrow> bot\n  | Some m \\<Rightarrow>\n    (case Mapping.lookup m M of\n      None \\<Rightarrow> bot\n    | Some (D', Ts, T, meth) \\<Rightarrow> if D = D' then Predicate.single (Ts, T, meth) else bot))\"\nby(auto simp add: Method_i_i_i_o_o_o_i_def Method_program intro!: pred_eqI)\n\ndeclare sees_field.equation[code del]\n\nlemma sees_field_program [code]:\n  \"program Pi \\<turnstile> C sees F:T (fd) in D \\<longleftrightarrow>\n  (case Mapping.lookup (fst (snd (snd (snd (impl_of Pi))))) C of\n    None \\<Rightarrow> False\n  | Some m \\<Rightarrow> \n    (case Mapping.lookup m F of \n       None \\<Rightarrow> False\n     | Some (D', T', fd') \\<Rightarrow> T = T' \\<and> fd = fd' \\<and> D = D'))\"\nby(cases Pi)(auto split: split_if_asm dest: has_visible_field[THEN has_field_is_class] simp add: tabulate_sees_field_def lookup.rep_eq Mapping_inverse)\n\nlemma sees_field_i_i_i_o_o_o_program [code]:\n  \"sees_field_i_i_i_o_o_o (program Pi) C F =\n  (case Mapping.lookup (fst (snd (snd (snd (impl_of Pi))))) C of\n    None \\<Rightarrow> bot\n  | Some m \\<Rightarrow>\n    (case Mapping.lookup m F of\n       None \\<Rightarrow> bot\n    | Some (D, T, fd) \\<Rightarrow> Predicate.single(T, fd, D)))\"\nby(auto simp add: sees_field_program sees_field_i_i_i_o_o_o_def intro: pred_eqI)\n\nlemma sees_field_i_i_i_o_o_i_program [code]:\n  \"sees_field_i_i_i_o_o_i (program Pi) C F D =\n  (case Mapping.lookup (fst (snd (snd (snd (impl_of Pi))))) C of\n    None \\<Rightarrow> bot\n  | Some m \\<Rightarrow>\n    (case Mapping.lookup m F of\n       None \\<Rightarrow> bot\n    | Some (D', T, fd) \\<Rightarrow> if D = D' then Predicate.single(T, fd) else bot))\"\nby(auto simp add: sees_field_program sees_field_i_i_i_o_o_i_def intro: pred_eqI)\n\nlemma field_program [code]:\n  \"field (program Pi) C F = \n  (case Mapping.lookup (fst (snd (snd (snd (impl_of Pi))))) C of \n    None \\<Rightarrow> Code.abort (STR ''not_unique'') (\\<lambda>_. Predicate.the bot)\n  | Some m \\<Rightarrow> \n    (case Mapping.lookup m F of\n       None \\<Rightarrow> Code.abort (STR ''not_unique'') (\\<lambda>_. Predicate.the bot)\n     | Some (D', T, fd) \\<Rightarrow> (D', T, fd)))\"\nunfolding field_def\nby(cases Pi)(fastforce simp add: Predicate.the_def tabulate_sees_field_def lookup.rep_eq Mapping_inverse split: split_if_asm intro: arg_cong[where f=The] dest: has_visible_field[THEN has_field_is_class] sees_field_fun)\n\nsubsection {* Implementation for precomputing mappings *}\n\ndefinition tabulate_program :: \"'m cdecl list \\<Rightarrow> 'm prog_impl\"\nwhere \"tabulate_program P = ProgRefine (P, tabulate_class P, tabulate_subcls P, tabulate_sees_field P, tabulate_Method P)\"\n\nlemma impl_of_tabulate_program [code abstract]:\n  \"impl_of (tabulate_program P) = (P, tabulate_class P, tabulate_subcls P, tabulate_sees_field P, tabulate_Method P)\"\nby(simp add: tabulate_program_def)\n\nlemma Program_code [code]:\n  \"Program = program \\<circ> tabulate_program\"\nby(simp add: program_def fun_eq_iff tabulate_program_def)\n\nsubsubsection {* @{term \"class\" } *}\n\nlemma tabulate_class_code [code]:\n  \"tabulate_class = Mapping.of_alist\"\n  by transfer (simp add: fun_eq_iff)\n\nsubsubsection {* @{term \"subcls\" } *}\n\ninductive subcls1' :: \"'m cdecl list \\<Rightarrow> cname \\<Rightarrow> cname \\<Rightarrow> bool\"\nwhere \n  find: \"C \\<noteq> Object \\<Longrightarrow> subcls1' ((C, D, rest) # P) C D\"\n| step: \"\\<lbrakk> C \\<noteq> Object; C \\<noteq> C'; subcls1' P C D  \\<rbrakk> \\<Longrightarrow> subcls1' ((C', D', rest) # P) C D\"\n\ncode_pred\n  (modes: i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool)\n  subcls1' .\n\nlemma subcls1_into_subcls1':\n  assumes \"subcls1 (Program P) C D\"\n  shows \"subcls1' P C D\"\nproof -\n  from assms obtain rest where \"map_of P C = \\<lfloor>(D, rest)\\<rfloor>\" \"C \\<noteq> Object\" by cases simp\n  thus ?thesis by(induct P)(auto split: split_if_asm intro: subcls1'.intros)\nqed\n\nlemma subcls1'_into_subcls1:\n  assumes \"subcls1' P C D\"\n  shows \"subcls1 (Program P) C D\"\nusing assms\nproof(induct)\n  case find thus ?case by(auto intro: subcls1.intros)\nnext\n  case step thus ?case by(auto elim!: subcls1.cases intro: subcls1.intros)\nqed\n\nlemma subcls1_eq_subcls1':\n  \"subcls1 (Program P) = subcls1' P\"\nby(auto simp add: fun_eq_iff intro: subcls1_into_subcls1' subcls1'_into_subcls1)\n\ndefinition subcls'' :: \"'m cdecl list \\<Rightarrow> cname \\<Rightarrow> cname \\<Rightarrow> bool\"\nwhere \"subcls'' P = (subcls1' P)^**\"\n\ncode_pred\n  (modes: i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool)\n  [inductify] \n  subcls'' .\n\nlemma subcls''_eq_subcls: \"subcls'' P = subcls (Program P)\"\nby(simp add: subcls''_def subcls1_eq_subcls1')\n\nlemma subclst_snd_classD: \n  assumes \"subclst (Program P) C D\"\n  shows \"D \\<in> fst ` snd ` set P\"\nusing assms\nby(induct)(fastforce elim!: subcls1.cases dest!: map_of_SomeD intro: rev_image_eqI)+\n\ndefinition check_acyclicity :: \"(cname, cname set) mapping \\<Rightarrow> 'm cdecl list \\<Rightarrow> unit\"\nwhere \"check_acyclicity _ _ = ()\"\n\ndefinition cyclic_class_hierarchy :: unit \nwhere [code del]: \"cyclic_class_hierarchy = ()\"\n\ndeclare [[code abort: cyclic_class_hierarchy]]\n\nlemma check_acyclicity_code:\n  \"check_acyclicity mapping P =\n   (let _ = \n     map (\\<lambda>(C, D, _).\n       if C = Object then () \n       else\n         (case Mapping.lookup mapping D of \n            None \\<Rightarrow> ()\n          | Some Cs \\<Rightarrow> if C \\<in> Cs then cyclic_class_hierarchy else ()))\n       P\n    in ())\"\nby simp\n\nlemma tablulate_subcls_code [code]:\n  \"tabulate_subcls P = \n  (let cnames = map fst P;\n       cnames' = map (fst \\<circ> snd) P;\n       mapping = Mapping.tabulate cnames (\\<lambda>C. set (C # [D \\<leftarrow> cnames'. subcls'' P C D]));\n       _ = check_acyclicity mapping P\n   in mapping\n  )\"\napply(auto simp add: tabulate_subcls_def Mapping.tabulate_def fun_eq_iff is_class_def o_def map_of_map2[simplified split_def] Mapping_inject)\n apply(subst map_of_map2[simplified split_def])\n apply(auto simp add: fun_eq_iff subcls''_eq_subcls map_of_map_K dest: subclst_snd_classD elim: rtranclp_tranclpE)[1]\napply(subst map_of_map2[simplified split_def])\napply(rule sym)\napply simp\napply(case_tac \"map_of P x\")\napply auto\ndone\n\nsubsubsection {* @{term Fields} *}\n\ntext {* \n  Problem: Does not terminate for cyclic class hierarchies!\n  This problem already occurs in Jinja's well-formedness checker: \n  @{text wf_cdecl} calls @{text wf_mdecl} before checking for acyclicity, \n  but @{text wf_J_mdecl} involves the type judgements, \n  which in turn requires @{term \"Fields\"} (via @{term sees_field}).\n  Checking acyclicity before executing @{term \"Fields'\"} for tabulation is difficult\n  because we would have to intertwine tabulation and well-formedness checking.\n  Possible (local) solution:\n  additional termination parameter (like memoisation for @{term \"rtranclp\"}) \n  and list option as error return parameter.\n*}\ninductive\n  Fields' :: \"'m cdecl list \\<Rightarrow> cname \\<Rightarrow> ((vname \\<times> cname) \\<times> (ty \\<times> fmod)) list \\<Rightarrow> bool\"\nfor P :: \"'m cdecl list\"\nwhere \n  rec:\n  \"\\<lbrakk> map_of P C = Some(D,fs,ms); C \\<noteq> Object; Fields' P D FDTs;\n     FDTs' = map (\\<lambda>(F,Tm). ((F,C),Tm)) fs @ FDTs \\<rbrakk>\n  \\<Longrightarrow> Fields' P C FDTs'\"\n| Object:\n  \"\\<lbrakk> map_of P Object = Some(D,fs,ms); FDTs = map (\\<lambda>(F,T). ((F,Object),T)) fs \\<rbrakk>\n  \\<Longrightarrow> Fields' P Object FDTs\"\n\nlemma Fields'_into_Fields:\n  assumes \"Fields' P C FDTs\"\n  shows \"Program P \\<turnstile> C has_fields FDTs\"\nusing assms\nby induct(auto intro: Fields.intros)\n\nlemma Fields_into_Fields':\n  assumes \"Program P \\<turnstile> C has_fields FDTs\"\n  shows \"Fields' P C FDTs\"\nusing assms\nby induct(auto intro: Fields'.intros)\n\nlemma Fields'_eq_Fields:\n  \"Fields' P = Fields (Program P)\"\nby(auto simp add: fun_eq_iff intro: Fields'_into_Fields Fields_into_Fields')\n\ncode_pred \n  (modes: i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool)\n  Fields' .\n\ndefinition fields' :: \"'m cdecl list \\<Rightarrow> cname \\<Rightarrow> ((vname \\<times> cname) \\<times> (ty \\<times> fmod)) list\"\nwhere \"fields' P C = (if \\<exists>FDTs. Fields' P C FDTs then THE FDTs. Fields' P C FDTs else [])\"\n\nlemma eval_Fields'_conv:\n  \"Predicate.eval (Fields'_i_i_o P C) = Fields' P C\"\nby(auto intro: Fields'_i_i_oI elim: Fields'_i_i_oE intro!: ext)\n\nlemma fields'_code [code]:\n  \"fields' P C = \n  (let FDTs = Fields'_i_i_o P C in if Predicate.holds (FDTs \\<guillemotright>= (\\<lambda>_. Predicate.single ())) then Predicate.the FDTs else [])\"\nby(auto simp add: fields'_def holds_eq Fields'_i_i_o_def intro: Fields'_i_i_oI Predicate.the_eqI[THEN sym])\n\nlemma The_Fields [simp]:\n  \"P \\<turnstile> C has_fields FDTs \\<Longrightarrow> The (Fields P C) = FDTs\"\nby(auto dest: has_fields_fun)\n\nlemma tabulate_sees_field_code [code]:\n  \"tabulate_sees_field P =\n   Mapping.tabulate (map fst P) (\\<lambda>C. Mapping.of_alist (map (\\<lambda>((F, D), Tfm). (F, (D, Tfm))) (fields' P C)))\"\napply(simp add: tabulate_sees_field_def tabulate_def is_class_def fields'_def Fields'_eq_Fields Mapping_inject)\napply(rule ext)\napply clarsimp\napply(rule conjI)\n apply(clarsimp simp add: o_def)\n apply(subst map_of_map2[unfolded split_def])\n apply simp\n apply transfer\n apply(rule conjI)\n  apply clarsimp\n  apply(rule ext)\n  apply clarsimp\n  apply(rule conjI)\n   apply(clarsimp simp add: sees_field_def Fields'_eq_Fields)\n   apply(drule (1) has_fields_fun, clarsimp)\n  apply clarify\n  apply(rule sym)\n  apply(rule ccontr)\n  apply(clarsimp simp add: sees_field_def Fields'_eq_Fields)\n apply clarsimp\n apply(rule ext)\n apply(clarsimp simp add: sees_field_def)\napply(clarsimp simp add: o_def)\napply(subst map_of_map2[simplified split_def])\napply(rule sym)\napply(clarsimp)\napply(rule ccontr)\napply simp\ndone\n\nsubsubsection {* @{term \"Methods\" } *}\n\ntext {* Same termination problem as for @{term Fields'} *}\ninductive Methods' :: \"'m cdecl list \\<Rightarrow> cname \\<Rightarrow> (mname \\<times> (ty list \\<times> ty \\<times> 'm option) \\<times> cname) list \\<Rightarrow> bool\"\n  for P :: \"'m cdecl list\"\nwhere \n  \"\\<lbrakk> map_of P Object = Some(D,fs,ms); Mm = map (\\<lambda>(M, rest). (M, (rest, Object))) ms \\<rbrakk>\n   \\<Longrightarrow> Methods' P Object Mm\"\n| \"\\<lbrakk> map_of P C = Some(D,fs,ms); C \\<noteq> Object; Methods' P D Mm;\n     Mm' = map (\\<lambda>(M, rest). (M, (rest, C))) ms @ Mm \\<rbrakk>\n   \\<Longrightarrow> Methods' P C Mm'\"\n\nlemma Methods'_into_Methods:\n  assumes \"Methods' P C Mm\"\n  shows \"Program P \\<turnstile> C sees_methods (map_of Mm)\"\nusing assms\napply induct\n apply(clarsimp simp add: o_def split_def)\n apply(rule sees_methods_Object)\n  apply fastforce\n apply(rule ext)\n apply(subst map_of_map2[unfolded split_def])\n apply(simp add: o_def)\n\napply(rule sees_methods_rec)\n   apply fastforce\n  apply simp\n apply assumption\napply(clarsimp simp add: map_add_def map_of_map2)\ndone\n\nlemma Methods_into_Methods':\n  assumes \"Program P \\<turnstile> C sees_methods Mm\"\n  shows \"\\<exists>Mm'. Methods' P C Mm' \\<and> Mm = map_of Mm'\"\nusing assms\nby induct(auto intro: Methods'.intros simp add: map_of_map2 map_add_def)\n\ncode_pred \n  (modes: i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool)\n  Methods'\n.\n\ndefinition methods' :: \"'m cdecl list \\<Rightarrow> cname \\<Rightarrow> (mname \\<times> (ty list \\<times> ty \\<times> 'm option) \\<times> cname) list\"\nwhere \"methods' P C = (if \\<exists>Mm. Methods' P C Mm then THE Mm. Methods' P C Mm else [])\"\n\nlemma methods'_code [code]:\n  \"methods' P C =\n  (let Mm = Methods'_i_i_o P C\n   in if Predicate.holds (Mm \\<guillemotright>= (\\<lambda>_. Predicate.single ())) then Predicate.the Mm else [])\"\nunfolding methods'_def\nby(auto simp add: holds_eq Methods'_i_i_o_def Predicate.the_def)\n\nlemma Methods'_fun:\n  assumes \"Methods' P C Mm\"\n  shows \"Methods' P C Mm' \\<Longrightarrow> Mm = Mm'\"\nusing assms\napply(induct arbitrary: Mm')\n apply(fastforce elim: Methods'.cases)\napply(rotate_tac -1)\napply(erule Methods'.cases)\n apply(fastforce)\napply clarify\napply(simp)\ndone\n\nlemma The_Methods' [simp]: \"Methods' P C Mm \\<Longrightarrow> The (Methods' P C) = Mm\"\nby(auto dest: Methods'_fun)\n\nlemma methods_def2 [simp]: \"Methods' P C Mm \\<Longrightarrow> methods' P C = Mm\"\nby(auto simp add: methods'_def)\n\nlemma tabulate_Method_code [code]:\n  \"tabulate_Method P =\n   Mapping.tabulate (map fst P) (\\<lambda>C. Mapping.of_alist (map (\\<lambda>(M, (rest, D)). (M, D, rest)) (methods' P C)))\"\napply(simp add: tabulate_Method_def tabulate_def o_def lookup.rep_eq Mapping_inject)\napply(rule ext)\napply clarsimp\napply(rule conjI)\n apply clarify\n apply(rule sym)\n apply(subst map_of_map2[unfolded split_def])\n apply(simp add: is_class_def)\n apply transfer\n apply(rule ext)\n apply(simp add: map_of_map2)\n apply(rule conjI)\n  apply(clarsimp simp add: map_of_map2 Method_def)\n  apply(drule Methods_into_Methods')\n  apply clarsimp\n  apply(simp add: split_def)\n  apply(subst map_of_map2[unfolded split_def])\n  apply simp\n apply clarify\n apply(clarsimp simp add: methods'_def)\n apply(frule Methods'_into_Methods)\n apply(clarsimp simp add: Method_def)\n apply(simp add: split_def)\n apply(subst map_of_map2[unfolded split_def])\n apply(fastforce intro: ccontr)\napply clarify\napply(rule sym)\napply(simp add: map_of_eq_None_iff is_class_def)\napply(simp only: set_map[symmetric] map_map o_def fst_conv)\napply simp\ndone\n\ntext {* Merge modules TypeRel, Decl and TypeRelRefine to avoid cyclic modules *}\n\ncode_identifier\n  code_module TypeRel \\<rightharpoonup>\n    (SML) TypeRel and (Haskell) TypeRel and (OCaml) TypeRel\n| code_module TypeRelRefine \\<rightharpoonup>\n    (SML) TypeRel and (Haskell) TypeRel and (OCaml) TypeRel\n| code_module Decl \\<rightharpoonup>\n    (SML) TypeRel and (Haskell) TypeRel and (OCaml) TypeRel\n\nML_val {* @{code Program} *}\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/JinjaThreads/Execute/TypeRelRefine.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631556226291, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.2801429109119031}}
{"text": "(*******************************************************************************\n\n  Project: Development of Security Protocols by Refinement\n\n  Module:  Key_establish/m3_kerberos5.thy (Isabelle/HOL 2016-1)\n  ID:      $Id: m3_kerberos5.thy 132890 2016-12-24 10:25:57Z csprenge $\n  Authors: Ivano Somaini, ETH Zurich <somainii@student.ethz.ch>\n           Christoph Sprenger, ETH Zurich <sprenger@inf.ethz.ch>\n\n  Key distribution protocols\n  Third refinement: core Kerberos V\n\n  Copyright (c) 2009-2016 Ivano Somaini, Christoph Sprenger\n  Licence: LGPL\n\n*******************************************************************************)\n\nsection \\<open>Core Kerberos 5 (L3)\\<close>\n\ntheory m3_kerberos5 imports m2_kerberos \"../Refinement/Message\"\nbegin\n\ntext \\<open>\nWe model the core Kerberos 5 protocol:\n\\[\n\\begin{array}{lll}\n  \\mathrm{M1.} & A \\rightarrow S: & A, B, Na \\\\ \n  \\mathrm{M2.} & S \\rightarrow A: & \\{Kab, B, Ts, Na\\}_{Kas}, \\{Kab, A, Ts\\}_{Kbs} \\\\\n  \\mathrm{M3.} & A \\rightarrow B: & \\{A, Ta\\}_{Kab}, \\{Kab, A, Ts\\}_{Kbs} \\\\\n  \\mathrm{M4.} & B \\rightarrow A: & \\{Ta\\}_{Kab} \\\\\n\\end{array}\n\\]\n\\<close>\n\ntext \\<open>Proof tool configuration. Avoid annoying automatic unfolding of\n\\<open>dom\\<close>.\\<close>\n\ndeclare domIff [simp, iff del]\n\n\n(******************************************************************************)\nsubsection \\<open>Setup\\<close>\n(******************************************************************************)\n\ntext \\<open>Now we can define the initial key knowledge.\\<close>\n\noverloading ltkeySetup' \\<equiv> ltkeySetup begin\ndefinition ltkeySetup_def: \"ltkeySetup' \\<equiv> {(sharK C, A) | C A. A = C \\<or> A = Sv}\"\nend\n\nlemma corrKey_shrK_bad [simp]: \"corrKey = shrK`bad\"\nby (auto simp add: keySetup_def ltkeySetup_def corrKey_def)\n\n\n(******************************************************************************)\nsubsection \\<open>State\\<close>\n(******************************************************************************)\n\ntext \\<open>The secure channels are star-shaped to/from the server.  Therefore,\nwe have only one agent in the relation.\\<close>\n\nrecord m3_state = \"m1_state\" +\n  IK :: \"msg set\"                                \\<comment> \\<open>intruder knowledge\\<close>\n\n\ntext \\<open>Observable state:\n@{term \"runs\"}, @{term \"leak\"}, @{term \"clk\"}, and @{term \"cache\"}.\\<close>\n\ntype_synonym\n  m3_obs = \"m2_obs\"\n\ndefinition\n  m3_obs :: \"m3_state \\<Rightarrow> m3_obs\" where\n  \"m3_obs s \\<equiv> \\<lparr> runs = runs s, leak = leak s, clk = clk s, cache = cache s \\<rparr>\"\n\ntype_synonym\n  m3_pred = \"m3_state set\"\n\ntype_synonym\n  m3_trans = \"(m3_state \\<times> m3_state) set\"\n\n\n(******************************************************************************)\nsubsection \\<open>Events\\<close>\n(******************************************************************************)\n\ntext \\<open>Protocol events.\\<close>\n\ndefinition     \\<comment> \\<open>by @{term \"A\"}, refines @{term \"m2_step1\"}\\<close>\n  m3_step1 :: \"[rid_t, agent, agent, nonce] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step1 Ra A B Na \\<equiv> {(s, s1).\n    \\<comment> \\<open>guards:\\<close>\n    Ra \\<notin> dom (runs s) \\<and>                  \\<comment> \\<open>\\<open>Ra\\<close> is fresh\\<close>\n    Na = Ra$na \\<and>                         \\<comment> \\<open>generated nonce\\<close>\n\n    \\<comment> \\<open>actions:\\<close>\n    s1 = s\\<lparr>\n      runs := (runs s)(Ra \\<mapsto> (Init, [A, B], [])),\n      IK := insert \\<lbrace>Agent A, Agent B, Nonce Na\\<rbrace> (IK s)   \\<comment> \\<open>send M1\\<close>\n    \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by @{term \"B\"}, refines @{term \"m2_step2\"}\\<close>\n  m3_step2 :: \"[rid_t, agent, agent] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step2 \\<equiv> m1_step2\"\n\ndefinition     \\<comment> \\<open>by @{text \"Server\"}, refines @{term m2_step3}\\<close>\n  m3_step3 :: \"[rid_t, agent, agent, key, nonce, time] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step3 Rs A B Kab Na Ts \\<equiv> {(s, s1).\n    \\<comment> \\<open>guards:\\<close>\n    Rs \\<notin> dom (runs s) \\<and>                          \\<comment> \\<open>fresh server run\\<close>\n    Kab = sesK (Rs$sk) \\<and>                          \\<comment> \\<open>fresh session key\\<close>\n\n    \\<lbrace>Agent A, Agent B, Nonce Na\\<rbrace> \\<in> IK s \\<and>    \\<comment> \\<open>recv \\<open>M1\\<close>\\<close>\n    Ts = clk s \\<and>                                 \\<comment> \\<open>fresh timestamp\\<close>\n\n    \\<comment> \\<open>actions:\\<close>\n    \\<comment> \\<open>record session key and send \\<open>M2\\<close>\\<close>\n    s1 = s\\<lparr>\n      runs := (runs s)(Rs \\<mapsto> (Serv, [A, B], [aNon Na, aNum Ts])),\n      IK := insert \\<lbrace>Crypt (shrK A) \\<lbrace>Key Kab, Agent B, Number Ts, Nonce Na\\<rbrace>,\n                      Crypt (shrK B) \\<lbrace>Key Kab, Agent A, Number Ts\\<rbrace>\\<rbrace>\n               (IK s)\n    \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by @{term \"A\"}, refines @{term m2_step4}\\<close>\n  m3_step4 :: \"[rid_t, agent, agent, nonce, key, time, time, msg] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step4 Ra A B Na Kab Ts Ta X \\<equiv> {(s, s1).\n\n     \\<comment> \\<open>guards:\\<close>\n     runs s Ra = Some (Init, [A, B], []) \\<and>           \\<comment> \\<open>key not yet recv'd\\<close>\n     Na = Ra$na \\<and>                                    \\<comment> \\<open>generated nonce\\<close>\n\n     \\<lbrace>Crypt (shrK A)                               \\<comment> \\<open>recv \\<open>M2\\<close>\\<close>\n          \\<lbrace>Key Kab, Agent B, Number Ts, Nonce Na\\<rbrace>, X\\<rbrace> \\<in> IK s \\<and>\n\n     \\<comment> \\<open>read current time\\<close>\n     Ta = clk s \\<and>\n\n     \\<comment> \\<open>check freshness of session key\\<close>\n     clk s < Ts + Ls \\<and>\n\n     \\<comment> \\<open>actions:\\<close>\n     \\<comment> \\<open>record session key and send \\<open>M3\\<close>\\<close>\n     s1 = s\\<lparr>\n       runs := (runs s)(Ra \\<mapsto> (Init, [A, B], [aKey Kab, aNum Ts, aNum Ta])),\n       IK := insert \\<lbrace>Crypt Kab \\<lbrace>Agent A, Number Ta\\<rbrace>, X\\<rbrace> (IK s)  \\<comment> \\<open>\\<open>M3\\<close>\\<close>\n     \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by @{term \"B\"}, refines @{term m2_step5}\\<close>\n  m3_step5 :: \"[rid_t, agent, agent, key, time, time] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step5 Rb A B Kab Ts Ta \\<equiv> {(s, s1).\n     \\<comment> \\<open>guards:\\<close>\n     runs s Rb = Some (Resp, [A, B], []) \\<and>             \\<comment> \\<open>key not yet recv'd\\<close>\n\n     \\<lbrace>Crypt Kab \\<lbrace>Agent A, Number Ta\\<rbrace>,            \\<comment> \\<open>recv \\<open>M3\\<close>\\<close>\n        Crypt (shrK B) \\<lbrace>Key Kab, Agent A, Number Ts\\<rbrace>\\<rbrace> \\<in> IK s \\<and>\n\n     \\<comment> \\<open>ensure freshness of session key\\<close>\n     clk s < Ts + Ls \\<and>\n\n     \\<comment> \\<open>check authenticator's validity and replay; 'replays' with fresh authenticator ok!\\<close>\n     clk s < Ta + La \\<and>\n     (B, Kab, Ta) \\<notin> cache s \\<and>\n\n     \\<comment> \\<open>actions:\\<close>\n     \\<comment> \\<open>record session key\\<close>\n     s1 = s\\<lparr>\n       runs := (runs s)(Rb \\<mapsto> (Resp, [A, B], [aKey Kab, aNum Ts, aNum Ta])),\n       cache := insert (B, Kab, Ta) (cache s),\n       IK := insert (Crypt Kab (Number Ta)) (IK s)              \\<comment> \\<open>send \\<open>M4\\<close>\\<close>\n     \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by @{term \"A\"}, refines @{term m2_step6}\\<close>\n  m3_step6 :: \"[rid_t, agent, agent, nonce, key, time, time] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step6 Ra A B Na Kab Ts Ta \\<equiv> {(s, s').\n     \\<comment> \\<open>guards:\\<close>\n     runs s Ra = Some (Init, [A, B], [aKey Kab, aNum Ts, aNum Ta]) \\<and>  \\<comment> \\<open>knows key\\<close>\n     Na = Ra$na \\<and>                                    \\<comment> \\<open>generated nonce\\<close>\n     clk s < Ts + Ls \\<and>                               \\<comment> \\<open>check session key's recentness\\<close>\n\n     Crypt Kab (Number Ta) \\<in> IK s \\<and>                  \\<comment> \\<open>recv \\<open>M4\\<close>\\<close>\n\n     \\<comment> \\<open>actions:\\<close>\n     s' = s\\<lparr>\n       runs := (runs s)(Ra \\<mapsto> (Init, [A, B], [aKey Kab, aNum Ts, aNum Ta, END]))\n     \\<rparr>\n  }\"\n\ntext \\<open>Clock tick event\\<close>\n\ndefinition   \\<comment> \\<open>refines @{term \"m2_tick\"}\\<close>\n  m3_tick :: \"time \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_tick \\<equiv> m1_tick\"\n\n\ntext \\<open>Purge event: purge cache of expired timestamps\\<close>\n\ndefinition     \\<comment> \\<open>refines @{term \"m2_purge\"}\\<close>\n  m3_purge :: \"agent \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_purge \\<equiv> m1_purge\"\n\n\ntext \\<open>Session key compromise.\\<close>\n\ndefinition     \\<comment> \\<open>refines @{term m2_leak}\\<close>\n  m3_leak :: \"[rid_t, agent, agent, nonce, time] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_leak Rs A B Na Ts \\<equiv> {(s, s1).\n    \\<comment> \\<open>guards:\\<close>\n    runs s Rs = Some (Serv, [A, B], [aNon Na, aNum Ts]) \\<and>\n    (clk s \\<ge> Ts + Ls) \\<and>             \\<comment> \\<open>only compromise 'old' session keys\\<close>\n\n    \\<comment> \\<open>actions:\\<close>\n    \\<comment> \\<open>record session key as leaked and add it to intruder knowledge\\<close>\n    s1 = s\\<lparr> leak := insert (sesK (Rs$sk), A, B, Na, Ts) (leak s),\n            IK := insert (Key (sesK (Rs$sk))) (IK s) \\<rparr>\n  }\"\n\ntext \\<open>Intruder fake event. The following \"Dolev-Yao\" event generates all\nintruder-derivable messages.\\<close>\n\ndefinition     \\<comment> \\<open>refines @{term \"m2_fake\"}\\<close>\n  m3_DY_fake :: \"m3_trans\"\nwhere\n  \"m3_DY_fake \\<equiv> {(s, s1).\n\n     \\<comment> \\<open>actions:\\<close>\n     s1 = s(| IK := synth (analz (IK s)) |)       \\<comment> \\<open>take DY closure\\<close>\n  }\"\n\n\n(******************************************************************************)\nsubsection \\<open>Transition system\\<close>\n(******************************************************************************)\n\ndefinition\n  m3_init :: \"m3_pred\"\nwhere\n  \"m3_init \\<equiv> { \\<lparr>\n     runs = Map.empty,\n     leak = shrK`bad \\<times> {undefined},\n     clk = 0,\n     cache = {},\n     IK = Key`shrK`bad\n  \\<rparr> }\"\n\ndefinition\n  m3_trans :: \"m3_trans\" where\n  \"m3_trans \\<equiv> (\\<Union>A B Ra Rb Rs Na Kab Ts Ta T X.\n     m3_step1 Ra A B Na \\<union>\n     m3_step2 Rb A B \\<union>\n     m3_step3 Rs A B Kab Na Ts \\<union>\n     m3_step4 Ra A B Na Kab Ts Ta X \\<union>\n     m3_step5 Rb A B Kab Ts Ta \\<union>\n     m3_step6 Ra A B Na Kab Ts Ta \\<union>\n     m3_tick T \\<union>\n     m3_purge A \\<union>\n     m3_leak Rs A B Na Ts \\<union>\n     m3_DY_fake \\<union>\n     Id\n  )\"\n\ndefinition\n  m3 :: \"(m3_state, m3_obs) spec\" where\n  \"m3 \\<equiv> \\<lparr>\n    init = m3_init,\n    trans = m3_trans,\n    obs = m3_obs\n  \\<rparr>\"\n\nlemmas m3_loc_defs =\n  m3_def m3_init_def m3_trans_def m3_obs_def\n  m3_step1_def m3_step2_def m3_step3_def m3_step4_def m3_step5_def\n  m3_step6_def m3_tick_def m3_purge_def m3_leak_def m3_DY_fake_def\n\nlemmas m3_defs = m3_loc_defs m2_defs\n\n\n(******************************************************************************)\nsubsection \\<open>Invariants\\<close>\n(******************************************************************************)\n\ntext \\<open>Specialized injection that we can apply more aggressively.\\<close>\n\nlemmas analz_Inj_IK = analz.Inj [where H=\"IK s\" for s]\nlemmas parts_Inj_IK = parts.Inj [where H=\"IK s\" for s]\n\ndeclare parts_Inj_IK [dest!]\n\ndeclare analz_into_parts [dest]\n\n\nsubsubsection \\<open>inv1: Secrecy of pre-distributed shared keys\\<close>\n(*inv*************************************************************************)\n\ndefinition\n  m3_inv1_lkeysec :: \"m3_pred\"\nwhere\n  \"m3_inv1_lkeysec \\<equiv> {s. \\<forall>C.\n     (Key (shrK C) \\<in> parts (IK s) \\<longrightarrow> C \\<in> bad) \\<and>\n     (C \\<in> bad \\<longrightarrow> Key (shrK C) \\<in> IK s)\n  }\"\n\nlemmas m3_inv1_lkeysecI = m3_inv1_lkeysec_def [THEN setc_def_to_intro, rule_format]\nlemmas m3_inv1_lkeysecE [elim] = m3_inv1_lkeysec_def [THEN setc_def_to_elim, rule_format]\nlemmas m3_inv1_lkeysecD = m3_inv1_lkeysec_def [THEN setc_def_to_dest, rule_format]\n\n\ntext \\<open>Invariance proof.\\<close>\n\nlemma PO_m3_inv1_lkeysec_init [iff]:\n  \"init m3 \\<subseteq> m3_inv1_lkeysec\"\nby (auto simp add: m3_defs intro!: m3_inv1_lkeysecI)\n\nlemma PO_m3_inv1_lkeysec_trans [iff]:\n  \"{m3_inv1_lkeysec} trans m3 {> m3_inv1_lkeysec}\"\nby (fastforce simp add: PO_hoare_defs m3_defs intro!: m3_inv1_lkeysecI)\n\nlemma PO_m3_inv1_lkeysec [iff]: \"reach m3 \\<subseteq> m3_inv1_lkeysec\"\nby (rule inv_rule_basic) (fast+)\n\n\ntext \\<open>Useful simplifier lemmas\\<close>\n\nlemma m3_inv1_lkeysec_for_parts [simp]:\n  \"\\<lbrakk> s \\<in> m3_inv1_lkeysec \\<rbrakk> \\<Longrightarrow> Key (shrK C) \\<in> parts (IK s) \\<longleftrightarrow> C \\<in> bad\"\nby auto\n\nlemma m3_inv1_lkeysec_for_analz [simp]:\n  \"\\<lbrakk> s \\<in> m3_inv1_lkeysec \\<rbrakk> \\<Longrightarrow> Key (shrK C) \\<in> analz (IK s) \\<longleftrightarrow> C \\<in> bad\"\nby auto\n\n\nsubsubsection \\<open>inv2: Session keys not used to encrypt other session keys\\<close>\n(*invh*************************************************************************)\n\ntext \\<open>Session keys are not used to encrypt other keys. Proof requires\ngeneralization to sets of session keys.\n\nNOTE: This invariant will be inherted from the corresponding L2 invariant\nusing the simulation relation.\n\\<close>\n\ndefinition\n  m3_inv2_sesK_compr :: \"m3_pred\"\nwhere\n  \"m3_inv2_sesK_compr \\<equiv> {s. \\<forall>K KK.\n     KK \\<subseteq> range sesK \\<longrightarrow>\n     (Key K \\<in> analz (Key`KK \\<union> (IK s))) = (K \\<in> KK \\<or> Key K \\<in> analz (IK s))\n  }\"\n\nlemmas m3_inv2_sesK_comprI = m3_inv2_sesK_compr_def [THEN setc_def_to_intro, rule_format]\nlemmas m3_inv2_sesK_comprE = m3_inv2_sesK_compr_def [THEN setc_def_to_elim, rule_format]\nlemmas m3_inv2_sesK_comprD = m3_inv2_sesK_compr_def [THEN setc_def_to_dest, rule_format]\n\ntext \\<open>Additional lemma\\<close>\nlemmas insert_commute_Key = insert_commute [where x=\"Key K\" for K]\n\nlemmas m3_inv2_sesK_compr_simps =\n  m3_inv2_sesK_comprD\n  m3_inv2_sesK_comprD [where KK=\"insert Kab KK\" for Kab KK, simplified]\n  m3_inv2_sesK_comprD [where KK=\"{Kab}\" for Kab, simplified]\n  insert_commute_Key\n\n\n(******************************************************************************)\nsubsection \\<open>Refinement\\<close>\n(******************************************************************************)\n\nsubsubsection \\<open>Message abstraction and simulation relation\\<close>\n(******************************************************************************)\n\ntext \\<open>Abstraction function on sets of messages.\\<close>\n\ninductive_set\n  abs_msg :: \"msg set \\<Rightarrow> chmsg set\"\n  for H :: \"msg set\"\nwhere\n  am_M1:\n    \"\\<lbrace>Agent A, Agent B, Nonce N\\<rbrace> \\<in> H\n  \\<Longrightarrow> Insec A B (Msg [aNon N]) \\<in> abs_msg H\"\n| am_M2a:\n    \"Crypt (shrK C) \\<lbrace>Key K, Agent B, Number T, Nonce N\\<rbrace> \\<in> H\n  \\<Longrightarrow> Secure Sv C (Msg [aKey K, aAgt B, aNum T, aNon N]) \\<in> abs_msg H\"\n| am_M2b:\n    \"Crypt (shrK C) \\<lbrace>Key K,  Agent A, Number T\\<rbrace> \\<in> H\n  \\<Longrightarrow> Secure Sv C (Msg [aKey K, aAgt A, aNum T]) \\<in> abs_msg H\"\n| am_M3:\n    \"Crypt K \\<lbrace>Agent A, Number T\\<rbrace> \\<in> H\n  \\<Longrightarrow> dAuth K (Msg [aAgt A, aNum T]) \\<in> abs_msg H\"\n| am_M4:\n    \"Crypt K (Number T) \\<in> H\n  \\<Longrightarrow> dAuth K (Msg [aNum T]) \\<in> abs_msg H\"\n\n\ntext \\<open>R23: The simulation relation. This is a data refinement of\nthe insecure and secure channels of refinement 2.\\<close>\n\ndefinition\n  R23_msgs :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23_msgs \\<equiv> {(s, t). abs_msg (parts (IK t)) \\<subseteq> chan s }\"\n\ndefinition\n  R23_keys :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23_keys \\<equiv> {(s, t). \\<forall>KK K. KK \\<subseteq> range sesK \\<longrightarrow>\n     Key K \\<in> analz (Key`KK \\<union> (IK t)) \\<longleftrightarrow> aKey K \\<in> extr (aKey`KK \\<union> ik0) (chan s)\n  }\"\n\ndefinition\n  R23_non :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23_non \\<equiv> {(s, t). \\<forall>KK N. KK \\<subseteq> range sesK \\<longrightarrow>\n     Nonce N \\<in> analz (Key`KK \\<union> (IK t)) \\<longleftrightarrow> aNon N \\<in> extr (aKey`KK \\<union> ik0) (chan s)\n  }\"\n\ndefinition\n  R23_pres :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23_pres \\<equiv> {(s, t). runs s = runs t \\<and> leak s = leak t \\<and> clk s = clk t \\<and> cache s = cache t}\"\n\ndefinition\n  R23 :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23 \\<equiv> R23_msgs \\<inter> R23_keys \\<inter> R23_non \\<inter> R23_pres\"\n\nlemmas R23_defs =\n  R23_def R23_msgs_def R23_keys_def R23_non_def R23_pres_def\n\n\ntext \\<open>The mediator function is the identity here.\\<close>\n\ndefinition\n  med32 :: \"m3_obs \\<Rightarrow> m2_obs\" where\n  \"med32 \\<equiv> id\"\n\n\nlemmas R23_msgsI = R23_msgs_def [THEN rel_def_to_intro, simplified, rule_format]\nlemmas R23_msgsE [elim] = R23_msgs_def [THEN rel_def_to_elim, simplified, rule_format]\nlemmas R23_msgsE' [elim] = R23_msgs_def [THEN rel_def_to_dest, simplified, rule_format, THEN subsetD]\n\nlemmas R23_keysI = R23_keys_def [THEN rel_def_to_intro, simplified, rule_format]\nlemmas R23_keysE [elim] = R23_keys_def [THEN rel_def_to_elim, simplified, rule_format]\n\nlemmas R23_nonI = R23_non_def [THEN rel_def_to_intro, simplified, rule_format]\nlemmas R23_nonE [elim] = R23_non_def [THEN rel_def_to_elim, simplified, rule_format]\n\nlemmas R23_presI = R23_pres_def [THEN rel_def_to_intro, simplified, rule_format]\nlemmas R23_presE [elim] = R23_pres_def [THEN rel_def_to_elim, simplified, rule_format]\n\nlemmas R23_intros = R23_msgsI R23_keysI R23_nonI R23_presI\n\n\ntext \\<open>Simplifier lemmas for various instantiations (keys and nonces).\\<close>\n\nlemmas R23_keys_simp = R23_keys_def [THEN rel_def_to_dest, simplified, rule_format]\nlemmas R23_keys_simps =\n  R23_keys_simp\n  R23_keys_simp [where KK=\"{}\", simplified]\n  R23_keys_simp [where KK=\"{K'}\" for K', simplified]\n  R23_keys_simp [where KK=\"insert K' KK\" for K' KK, simplified, OF _ conjI]\n\nlemmas R23_non_simp = R23_non_def [THEN rel_def_to_dest, simplified, rule_format]\nlemmas R23_non_simps =\n  R23_non_simp\n  R23_non_simp [where KK=\"{}\", simplified]\n  R23_non_simp [where KK=\"{K}\" for K, simplified]\n  R23_non_simp [where KK=\"insert K KK\" for K KK, simplified, OF _ conjI]\n\nlemmas R23_simps = R23_keys_simps R23_non_simps\n\n\nsubsubsection \\<open>General lemmas\\<close>\n(******************************************************************************)\n\ntext \\<open>General facts about @{term \"abs_msg\"}\\<close>\n\ndeclare abs_msg.intros [intro!]\ndeclare abs_msg.cases [elim!]\n\nlemma abs_msg_empty: \"abs_msg {} = {}\"\nby (auto)\n\nlemma abs_msg_Un [simp]:\n  \"abs_msg (G \\<union> H) = abs_msg G \\<union> abs_msg H\"\nby (auto)\n\nlemma abs_msg_mono [elim]:\n  \"\\<lbrakk> m \\<in> abs_msg G; G \\<subseteq> H \\<rbrakk> \\<Longrightarrow> m \\<in> abs_msg H\"\nby (auto)\n\nlemma abs_msg_insert_mono [intro]:\n  \"\\<lbrakk> m \\<in> abs_msg H \\<rbrakk> \\<Longrightarrow> m \\<in> abs_msg (insert m' H)\"\nby (auto)\n\n\ntext \\<open>Facts about @{term \"abs_msg\"} concerning abstraction of fakeable\nmessages. This is crucial for proving the refinement of the intruder event.\\<close>\n\nlemma abs_msg_DY_subset_fakeable:\n  \"\\<lbrakk> (s, t) \\<in> R23_msgs; (s, t) \\<in> R23_keys; (s, t) \\<in> R23_non; t \\<in> m3_inv1_lkeysec \\<rbrakk>\n  \\<Longrightarrow> abs_msg (synth (analz (IK t))) \\<subseteq> fake ik0 (dom (runs s)) (chan s)\"\napply (auto)\n\\<comment> \\<open>9 subgoals, deal with replays first\\<close>\nprefer 2 apply (blast)\nprefer 3 apply (blast)\nprefer 4 apply (blast)\nprefer 5 apply (blast)\n\\<comment> \\<open>remaining 5 subgoals are real fakes\\<close>\napply (intro fake_StatCh fake_DynCh, auto simp add: R23_simps)+\ndone\n\n\nsubsubsection \\<open>Refinement proof\\<close>\n(******************************************************************************)\n\ntext \\<open>Pair decomposition. These were set to \\texttt{elim!}, which is too\nagressive here.\\<close>\n\ndeclare MPair_analz [rule del, elim]\ndeclare MPair_parts [rule del, elim]\n\n\ntext \\<open>Protocol events.\\<close>\n\nlemma PO_m3_step1_refines_m2_step1:\n  \"{R23}\n     (m2_step1 Ra A B Na), (m3_step1 Ra A B Na)\n   {> R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros) (auto)\n\nlemma PO_m3_step2_refines_m2_step2:\n  \"{R23}\n     (m2_step2 Rb A B), (m3_step2 Rb A B)\n   {> R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n\nlemma PO_m3_step3_refines_m2_step3:\n  \"{R23 \\<inter> (m2_inv3a_sesK_compr) \\<times> (m3_inv2_sesK_compr \\<inter> m3_inv1_lkeysec)}\n     (m2_step3 Rs A B Kab Na Ts), (m3_step3 Rs A B Kab Na Ts)\n   {> R23}\"\nproof -\n  { fix s t\n    assume H:\n      \"(s, t) \\<in> R23_msgs\" \"(s, t) \\<in> R23_keys\" \"(s, t) \\<in> R23_non\"\n      \"(s, t) \\<in> R23_pres\"\n      \"s \\<in> m2_inv3a_sesK_compr\"\n      \"t \\<in> m3_inv2_sesK_compr\" \"t \\<in> m3_inv1_lkeysec\"\n      \"Kab = sesK (Rs$sk)\" \"Rs \\<notin> dom (runs t)\"\n      \"\\<lbrace> Agent A, Agent B, Nonce Na \\<rbrace> \\<in> parts (IK t)\"\n    let ?s'=\n      \"s\\<lparr> runs := runs s(Rs \\<mapsto> (Serv, [A, B], [aNon Na, aNum (clk t)])),\n          chan := insert (Secure Sv A (Msg [aKey Kab, aAgt B, aNum (clk t), aNon Na]))\n                 (insert (Secure Sv B (Msg [aKey Kab, aAgt A, aNum (clk t)])) (chan s)) \\<rparr>\"\n    let ?t'=\n      \"t\\<lparr> runs := runs t(Rs \\<mapsto> (Serv, [A, B], [aNon Na, aNum (clk t)])),\n          IK := insert\n                  \\<lbrace> Crypt (shrK A) \\<lbrace> Key Kab, Agent B, Number (clk t), Nonce Na \\<rbrace>,\n                    Crypt (shrK B) \\<lbrace> Key Kab, Agent A, Number (clk t) \\<rbrace> \\<rbrace>\n                  (IK t) \\<rparr>\"\n  \\<comment> \\<open>here we go\\<close>\n    have \"(?s', ?t') \\<in> R23_msgs\" using H\n    by (-) (rule R23_intros, auto)\n  moreover\n    have \"(?s', ?t') \\<in> R23_keys\" using H\n    by (-) (rule R23_intros,\n            auto simp add: m2_inv3a_sesK_compr_simps m3_inv2_sesK_compr_simps,\n            auto simp add: R23_keys_simps)\n  moreover\n    have \"(?s', ?t') \\<in> R23_non\" using H\n    by (-)\n       (rule R23_intros,\n        auto simp add: m2_inv3a_sesK_compr_simps m3_inv2_sesK_compr_simps R23_non_simps)\n  moreover\n    have \"(?s', ?t') \\<in> R23_pres\" using H\n    by (-) (rule R23_intros, auto)\n  moreover\n    note calculation\n  }\n  thus ?thesis\n  by (auto simp add: PO_rhoare_defs R23_def m3_defs)\nqed\n\nlemma PO_m3_step4_refines_m2_step4:\n  \"{R23 \\<inter> UNIV \\<times> m3_inv1_lkeysec}\n     (m2_step4 Ra A B Na Kab Ts Ta), (m3_step4 Ra A B Na Kab Ts Ta X)\n   {> R23}\"\nproof -\n  { fix s t\n    assume H:\n      \"(s, t) \\<in> R23_msgs\" \"(s, t) \\<in> R23_keys\" \"(s, t) \\<in> R23_non\"\n      \"(s, t) \\<in> R23_pres\"  \"t \\<in> m3_inv1_lkeysec\"\n      \"runs t Ra = Some (Init, [A, B], [])\" \"Na = Ra$na\"\n      \"\\<lbrace> Crypt (shrK A) \\<lbrace>Key Kab, Agent B, Number Ts, Nonce Na\\<rbrace>, X\\<rbrace>  \\<in> analz (IK t)\"\n    let ?s' = \"s\\<lparr> runs := runs s(Ra \\<mapsto> (Init, [A, B], [aKey Kab, aNum Ts, aNum (clk t)])),\n                 chan := insert (dAuth Kab (Msg [aAgt A, aNum (clk t)])) (chan s) \\<rparr>\"\n    and ?t' = \"t\\<lparr> runs := runs t(Ra \\<mapsto> (Init, [A, B], [aKey Kab, aNum Ts, aNum (clk t)])),\n                 IK := insert \\<lbrace>Crypt Kab \\<lbrace>Agent A, Number (clk t)\\<rbrace>, X\\<rbrace> (IK t) \\<rparr>\"\n    from H have\n      \"Secure Sv A (Msg [aKey Kab, aAgt B, aNum Ts, aNon Na]) \\<in> chan s\"\n    by (auto dest!: analz_into_parts elim!: MPair_parts)\n  moreover\n    from H have \"X \\<in> parts (IK t)\" by (auto)\n    with H have \"(?s', ?t') \\<in> R23_msgs\" by (auto intro!: R23_intros) (auto)\n  moreover\n    from H have \"X \\<in> analz (IK t)\" by (auto)\n    with H have \"(?s', ?t') \\<in> R23_keys\"\n    by (auto intro!: R23_intros) (auto dest!: analz_cut intro: analz_monotonic)\n  moreover\n    from H have \"X \\<in> analz (IK t)\" by (auto)\n    with H have \"(?s', ?t') \\<in> R23_non\"\n    by (auto intro!: R23_intros) (auto dest!: analz_cut intro: analz_monotonic)\n  moreover\n    have \"(?s', ?t') \\<in> R23_pres\" using H\n    by (auto intro!: R23_intros)\n  moreover\n    note calculation\n  }\n  thus ?thesis\n  by (auto simp add: PO_rhoare_defs R23_def m3_defs dest!: analz_Inj_IK)\nqed\n\nlemma PO_m3_step5_refines_m2_step5:\n  \"{R23}\n     (m2_step5 Rb A B Kab Ts Ta), (m3_step5 Rb A B Kab Ts Ta)\n   {> R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n   (auto)\n\nlemma PO_m3_step6_refines_m2_step6:\n  \"{R23}\n     (m2_step6 Ra A B Na Kab Ts Ta), (m3_step6 Ra A B Na Kab Ts Ta)\n   {> R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n\nlemma PO_m3_tick_refines_m2_tick:\n  \"{R23}\n    (m2_tick T), (m3_tick T)\n   {>R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n\nlemma PO_m3_purge_refines_m2_purge:\n  \"{R23}\n     (m2_purge A), (m3_purge A)\n   {>R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n\n\ntext \\<open>Intruder events.\\<close>\n\nlemma PO_m3_leak_refines_m2_leak:\n  \"{R23}\n     (m2_leak Rs A B Na Ts), (m3_leak Rs A B Na Ts)\n   {>R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs R23_simps intro!: R23_intros)\n\nlemma PO_m3_DY_fake_refines_m2_fake:\n  \"{R23 \\<inter> m2_inv3a_sesK_compr \\<times> (m3_inv2_sesK_compr \\<inter> m3_inv1_lkeysec)}\n     m2_fake, m3_DY_fake\n   {> R23}\"\napply (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros\n            del: abs_msg.cases)\napply (auto intro: abs_msg_DY_subset_fakeable [THEN subsetD]\n            del: abs_msg.cases)\napply (auto simp add: R23_simps)\ndone\n\n\ntext \\<open>All together now...\\<close>\n\nlemmas PO_m3_trans_refines_m2_trans =\n  PO_m3_step1_refines_m2_step1 PO_m3_step2_refines_m2_step2\n  PO_m3_step3_refines_m2_step3 PO_m3_step4_refines_m2_step4\n  PO_m3_step5_refines_m2_step5 PO_m3_step6_refines_m2_step6\n  PO_m3_tick_refines_m2_tick PO_m3_purge_refines_m2_purge\n  PO_m3_leak_refines_m2_leak PO_m3_DY_fake_refines_m2_fake\n\n\nlemma PO_m3_refines_init_m2 [iff]:\n  \"init m3 \\<subseteq> R23``(init m2)\"\nby (auto simp add: R23_def m3_defs intro!: R23_intros)\n\nlemma PO_m3_refines_trans_m2 [iff]:\n  \"{R23 \\<inter> (m2_inv3a_sesK_compr) \\<times> (m3_inv2_sesK_compr \\<inter> m3_inv1_lkeysec)}\n     (trans m2), (trans m3)\n   {> R23}\"\nby (auto simp add: m3_def m3_trans_def m2_def m2_trans_def)\n   (blast intro!: PO_m3_trans_refines_m2_trans)+\n\nlemma PO_m3_observation_consistent [iff]:\n  \"obs_consistent R23 med32 m2 m3\"\nby (auto simp add: obs_consistent_def R23_def med32_def m3_defs)\n\n\ntext \\<open>Refinement result.\\<close>\n\nlemma m3_refines_m2 [iff]:\n  \"refines\n     (R23 \\<inter> (m2_inv3a_sesK_compr) \\<times> (m3_inv1_lkeysec))\n     med32 m2 m3\"\nproof -\n  have \"R23 \\<inter> m2_inv3a_sesK_compr \\<times> UNIV \\<subseteq> UNIV \\<times> m3_inv2_sesK_compr\"\n    by (auto simp add: R23_def R23_keys_simps intro!: m3_inv2_sesK_comprI)\n  thus ?thesis\n    by (-) (rule Refinement_using_invariants, auto)\nqed\n\nlemma m3_implements_m2 [iff]:\n  \"implements med32 m2 m3\"\nby (rule refinement_soundness) (auto)\n\n\nsubsection \\<open>Inherited invariants\\<close>\n(******************************************************************************)\n\nsubsubsection \\<open>inv3 (derived): Key secrecy for initiator\\<close>\n(*invh*************************************************************************)\n\ndefinition\n  m3_inv3_ikk_init :: \"m3_state set\"\nwhere\n  \"m3_inv3_ikk_init \\<equiv> {s. \\<forall>A B Ra K Ts nl.\n     runs s Ra = Some (Init, [A, B], aKey K # aNum Ts # nl) \\<longrightarrow> A \\<in> good \\<longrightarrow> B \\<in> good \\<longrightarrow>\n     Key K \\<in> analz (IK s) \\<longrightarrow>\n       (K, A, B, Ra$na, Ts) \\<in> leak s\n  }\"\n\nlemmas m3_inv3_ikk_initI = m3_inv3_ikk_init_def [THEN setc_def_to_intro, rule_format]\nlemmas m3_inv3_ikk_initE [elim] = m3_inv3_ikk_init_def [THEN setc_def_to_elim, rule_format]\nlemmas m3_inv3_ikk_initD = m3_inv3_ikk_init_def [THEN setc_def_to_dest, rule_format, rotated 1]\n\nlemma PO_m3_inv3_ikk_init: \"reach m3 \\<subseteq> m3_inv3_ikk_init\"\nproof (rule INV_from_Refinement_using_invariants [OF m3_refines_m2])\n  show \"Range (R23 \\<inter> m2_inv3a_sesK_compr \\<times> m3_inv1_lkeysec \\<inter> m2_inv6_ikk_init \\<times> UNIV)\n      \\<subseteq> m3_inv3_ikk_init\"\n    by (fastforce simp add: R23_def R23_keys_simps intro!: m3_inv3_ikk_initI)\nqed auto\n\n\nsubsubsection \\<open>inv4 (derived): Key secrecy for responder\\<close>\n(*invh*************************************************************************)\n\ndefinition\n  m3_inv4_ikk_resp :: \"m3_state set\"\nwhere\n  \"m3_inv4_ikk_resp \\<equiv> {s. \\<forall>A B Rb K Ts nl.\n     runs s Rb = Some (Resp, [A, B], aKey K # aNum Ts # nl) \\<longrightarrow> A \\<in> good \\<longrightarrow> B \\<in> good \\<longrightarrow>\n     Key K \\<in> analz (IK s) \\<longrightarrow>\n       (\\<exists>Na. (K, A, B, Na, Ts) \\<in> leak s)\n  }\"\n\nlemmas m3_inv4_ikk_respI = m3_inv4_ikk_resp_def [THEN setc_def_to_intro, rule_format]\nlemmas m3_inv4_ikk_respE [elim] = m3_inv4_ikk_resp_def [THEN setc_def_to_elim, rule_format]\nlemmas m3_inv4_ikk_respD = m3_inv4_ikk_resp_def [THEN setc_def_to_dest, rule_format, rotated 1]\n\nlemma PO_m3_inv4_ikk_resp: \"reach m3 \\<subseteq> m3_inv4_ikk_resp\"\nproof (rule INV_from_Refinement_using_invariants [OF m3_refines_m2])\n  show \"Range (R23 \\<inter> m2_inv3a_sesK_compr \\<times> m3_inv1_lkeysec \\<inter> m2_inv7_ikk_resp \\<times> UNIV)\n      \\<subseteq> m3_inv4_ikk_resp\"\n    by (auto simp add: R23_def R23_keys_simps intro!: m3_inv4_ikk_respI)\n       (elim m2_inv7_ikk_respE, auto)\nqed auto\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Security_Protocol_Refinement/Key_establish/m3_kerberos5.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631556226291, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.2801429109119031}}
{"text": "theory \"BrandsChaum_cert_auto\"\nimports\n  \"ESPLogic\"\nbegin\n\n(* section:  Distance bounding following Brands, Chaum  *)\n\n(* text: \n\nWe model the distance bounding protocol following Brands and Chaum\n\n  Stefan Brands and David Chaum. Distance-Bounding Protocols. EUROCRYPT '93     \n  Lecture Notes in Computer Science 765, pp. 344--359, Springer, 1993.\n\nSince the Dolev-Yao model has no notion of time, we can only show that\nthe challenge-response steps have to happen in the right order.\n\n *)\n\nrole P\nwhere \"P =\n  [ Send ''1'' <| sAV ''P'', PEnc ( sN ''m'' ) ( sN ''k'' ) |>\n  , Recv ''2'' ( sMV ''a'' )\n  , Send ''3'' ( PHash <| sMV ''a'', sN ''m'' |> )\n  , Send ''4'' <| sN ''m'', sN ''k'',\n                  PEnc <| sMV ''a'', PHash <| sMV ''a'', sN ''m'' |> |> ( sSK ''P'' )\n               |>\n  ]\"\n\nrole V\nwhere \"V =\n  [ Recv ''1'' <| sMV ''P'', sMV ''c'' |>\n  , Send ''2'' ( sN ''a'' )\n  , Recv ''3'' ( sMV ''b'' )\n  , Recv ''4'' <| sMV ''m'', sMV ''k'',\n                  PEnc <| sN ''a'', sMV ''b'' |> ( PAsymSK ( sMV ''P'' ) )\n               |>\n  , MatchEq ''5'' ( MVar ''c'' ) ( PEnc ( sMV ''m'' ) ( sMV ''k'' ) )\n  , MatchEq ''6'' ( MVar ''b'' ) ( PHash <| sN ''a'', sMV ''m'' |> )\n  ]\"\n\nprotocol BrandsChaum\nwhere \"BrandsChaum = { P, V }\"\n\nlocale restricted_BrandsChaum_state = BrandsChaum_state\n\ntype_invariant BrandsChaum_msc_typing for BrandsChaum\nwhere \"BrandsChaum_msc_typing = mk_typing\n  [ ((V, ''P''), (KnownT V_1))\n  , ((P, ''a''), (KnownT P_2))\n  , ((V, ''b''), (KnownT V_3))\n  , ((V, ''c''), (KnownT V_1))\n  , ((V, ''k''), (KnownT V_4))\n  , ((V, ''m''), (KnownT V_4))\n  ]\"\n\nsublocale BrandsChaum_state < BrandsChaum_msc_typing_state\nproof -\n  have \"(t,r,s) : approx BrandsChaum_msc_typing\"\n  proof(cases rule: reachable_in_approxI_ext\n        [OF BrandsChaum_msc_typing.monoTyp, completeness_cases_rule])\n    case (V_1_P t r s tid0)\n    then interpret state: BrandsChaum_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = V_1_P\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (V_1_c t r s tid0)\n    then interpret state: BrandsChaum_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = V_1_c\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (V_4_k t r s tid0)\n    then interpret state: BrandsChaum_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = V_4_k\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (V_4_m t r s tid0)\n    then interpret state: BrandsChaum_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = V_4_m\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  qed\n  thus \"BrandsChaum_msc_typing_state t r s\" by unfold_locales auto\nqed\n\ntext{* Prove secrecy of long-term keys. *}\ncontext BrandsChaum_state begin\n\n  (* This rule is unsafe in general, but OK here, \n     as we are only reasoning about static compromise. \n  *)\n  lemma static_longterm_key_reveal[dest!]:\n    \"predOrd t (LKR a) e ==> RLKR a : reveals t\"\n    by (auto intro: compr_predOrdI)\n\n  lemma longterm_private_key_secrecy:\n    assumes facts:\n      \"SK m : knows t\"\n      \"RLKR m ~: reveals t\"\n    shows \"False\"\n  using facts by (sources \"SK m\")\n\n  lemma longterm_sym_ud_key_secrecy:\n    assumes facts:\n      \"K m1 m2 : knows t\"\n      \"RLKR m1 ~: reveals t\"\n      \"RLKR m2 ~: reveals t\"\n    shows \"False\"\n  using facts by (sources \"K m1 m2\")\n\n  lemma longterm_sym_bd_key_secrecy:\n    assumes facts:\n      \"Kbd m1 m2 : knows t\"\n      \"RLKR m1 ~: reveals t\"\n      \"RLKR m2 ~: reveals t\"\n      \"m1 : Agent\"\n      \"m2 : Agent\"\n    shows \"False\"\n  proof -\n    from facts \n    have \"KShr (agents {m1, m2}) : knows t\"\n      by (auto simp: Kbd_def)\n    thus ?thesis using facts\n    proof (sources \"KShr (agents {m1, m2})\")\n    qed (auto simp: agents_def Agent_def)\n  qed\n\n  lemmas ltk_secrecy =\n    longterm_sym_ud_key_secrecy\n    longterm_sym_ud_key_secrecy[OF in_knows_predOrd1]\n    longterm_sym_bd_key_secrecy\n    longterm_sym_bd_key_secrecy[OF in_knows_predOrd1]\n    longterm_private_key_secrecy\n    longterm_private_key_secrecy[OF in_knows_predOrd1]\n\nend\n\nlemma (in restricted_BrandsChaum_state) prover_recent:\n  \"let\n     prems =\n       (% tid0.\n          roleMap r tid0 = Some V &\n          RLKR(s(MV ''P'' tid0)) ~: reveals t & ( tid0, V_6 ) : steps t);\n     concs =\n       (% tid0 tid1.\n          roleMap r tid1 = Some P &\n          s(MV ''P'' tid0) = s(AV ''P'' tid1) &\n          s(MV ''m'' tid0) = LN ''m'' tid1 &\n          s(MV ''k'' tid0) = LN ''k'' tid1 &\n          LN ''a'' tid0 = s(MV ''a'' tid1) &\n          predOrd t (St( tid1, P_1 )) (St( tid0, V_2 )) &\n          predOrd t (St( tid0, V_2 )) (St( tid1, P_3 )) &\n          predOrd t (St( tid1, P_3 )) (St( tid0, V_3 )))\n   in ? f. inj_on f (Collect prems) & (! i. prems i --> concs i (f i))\"\n  (is \"let prems = ?prems; concs = ?concs in ?P prems concs\")\nproof -\n  { fix tid0 tid1\n    assume facts: \"?prems tid0\"\n    have \" ? tid1. ?concs tid0 tid1\"\n    proof -\n      note_unified facts = facts\n      note_prefix_closed facts = facts\n      thus ?thesis proof(sources! \"\n                       Enc {| LN ''a'' tid0, Hash {| LN ''a'' tid0, s(MV ''m'' tid0) |} |}\n                           ( SK ( s(MV ''P'' tid0) ) ) \")\n        case fake note_unified facts = this facts\n        thus ?thesis by (auto dest!: ltk_secrecy)\n      next\n        case (P_4_enc tid1) note_unified facts = this facts\n        thus ?thesis proof(sources! \" LN ''a'' tid0 \")\n          case V_2_a note_unified facts = this facts\n          thus ?thesis proof(sources! \" LN ''m'' tid1 \")\n            case P_1_m note_unified facts = this facts\n            thus ?thesis proof(sources! \" LN ''k'' tid1 \")\n              case P_4_k note_unified facts = this facts\n              thus ?thesis proof(sources! \"\n                               Enc ( LN ''m'' tid1 ) ( s(MV ''k'' tid0) ) \")\n                case (P_1_enc tid2) note_unified facts = this facts\n                thus ?thesis proof(sources! \" Hash {| LN ''a'' tid0, LN ''m'' tid1 |} \")\n                  case fake note_unified facts = this facts\n                  thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\n                next\n                  case (P_3_hash tid2) note_unified facts = this facts\n                  thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\n                next\n                  case (P_4_hash tid2) note_unified facts = this facts\n                  thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\n                qed (safe?, simp_all?, insert facts, (fastforce+)?)\n              qed (safe?, simp_all?, insert facts, ((((clarsimp, order?) | order | fast))+)?)\n            qed (safe?, simp_all?, insert facts, (fastforce+)?)\n          next\n            case P_4_m note_unified facts = this facts\n            thus ?thesis proof(sources! \"\n                             Enc ( LN ''m'' tid1 ) ( s(MV ''k'' tid0) ) \")\n              case (P_1_enc tid2) note_unified facts = this facts\n              thus ?thesis proof(sources! \" Hash {| LN ''a'' tid0, LN ''m'' tid1 |} \")\n                case fake note_unified facts = this facts\n                thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\n              next\n                case (P_3_hash tid2) note_unified facts = this facts\n                thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\n              next\n                case (P_4_hash tid2) note_unified facts = this facts\n                thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\n              qed (safe?, simp_all?, insert facts, (fastforce+)?)\n            qed (safe?, simp_all?, insert facts, ((((clarsimp, order?) | order | fast))+)?)\n          qed (safe?, simp_all?, insert facts, (fastforce+)?)\n        qed (safe?, simp_all?, insert facts, (fastforce+)?)\n      qed (safe?, simp_all?, insert facts, (fastforce+)?)\n    qed\n  }\n  note niagree = this\n  { fix i1 i2 j\n    assume \"?concs i1 j & ?concs i2 j\"\n    note_unified facts = this\n    have \"i1 = i2\" using facts by simp\n  }\n  note conc_inj = this\n  show ?thesis\n    by (fast intro!: iagree_to_niagree elim!: niagree conc_inj)\nqed\n\nend", "meta": {"author": "meiersi", "repo": "scyther-proof", "sha": "84e42366a46f66f1b090651be3bfaa3497696280", "save_path": "github-repos/isabelle/meiersi-scyther-proof", "path": "github-repos/isabelle/meiersi-scyther-proof/scyther-proof-84e42366a46f66f1b090651be3bfaa3497696280/examples/classic/isabelle-proofs/BrandsChaum_cert_auto.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.2801154799540876}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |               December 2004               |\n            |                 August 2005  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |                October 2005  (modified)   |\n            |                  April 2006  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2009-2       |\n            |                October 2010  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2016         |\n            |                    May 2016  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2017         |\n            |                  April 2018  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory Domain_F_cpo\nimports Domain_F CSP_T.Domain_T_cpo Set_F_cpo \n        CSP.CPO_pair CSP_T.CSP_T_continuous\nbegin\n\n(*****************************************************************\n\n         1. \n         2. \n         3. \n         4. \n\n *****************************************************************)\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite UnionT and InterT.                 *)\n(*                  Union (B ` A) = (UN x:A. B x)                      *)\n(*                  Inter (B ` A) = (INT x:A. B x)                     *)\n(*\ndeclare Union_image_eq [simp del]\ndeclare Inter_image_eq [simp del]\n*)\n(* no simp rules in Isabelle 2017 \ndeclare Sup_image_eq [simp del]\ndeclare Inf_image_eq [simp del]\n*)\n\n(*********************************************************\n                      Bottom in Dom_F\n *********************************************************)\n(*\ninstance domF :: (type) bot0\nby (intro_classes)\n*)\n\n\ninstantiation domF :: (type) bot0\nbegin\ndefinition\n  bottom_domF_def : \"Bot == ({<>}t ,, {}f)\"\ninstance ..\nend\n\n(*\ndefs (overloaded)\n  bottom_domF_def : \"Bot == ({<>}t ,, {}f)\"\n*)\n\nlemma bottom_domF: \"Bot <= (F::'a domF)\"\napply (simp add: bottom_domF_def pairF_def)\napply (simp add: subdomF_def Abs_domF_inverse)\ndone\n\ninstance domF :: (type) bot\napply (intro_classes)\nby (simp add: bottom_domF)\n\n(*** fstF and sndF ***)\n\nlemma fstF_bottom_domF[simp]: \"(fstF o Bot) = Bot\"\napply (simp add: prod_Bot_def)\napply (simp add: bottom_domF_def)\napply (simp add: bottom_domT_def)\napply (simp add: comp_def pairF)\ndone\n\nlemma sndF_bottom_domF[simp]: \"(sndF o Bot) = Bot\"\napply (simp add: prod_Bot_def)\napply (simp add: bottom_domF_def)\napply (simp add: bottom_setF_def)\napply (simp add: comp_def pairF)\ndone\n\n(********************************************************** \n      lemmas used in a proof that domain_F is a cpo.\n **********************************************************)\n\n(* LUB_TF TFs is an upper bound of TFs *)\n\ndefinition\n  LUB_TF :: \"'a domTsetF set => 'a domTsetF\"\n  where\n  LUB_TF_def : \"LUB_TF TFs == (UnionT (fst ` TFs), UnionF (snd ` TFs))\"\n  \ndefinition  \n  LUB_domF :: \"'a domF set => 'a domF\"\n  where\n  LUB_domF_def : \"LUB_domF Fs == Abs_domF (LUB_TF (Rep_domF ` Fs))\"\n\n(************* LUB_TF *************)\n\n(*** LUB_TF --> LUB ***)\n\nlemma LUB_TF_isLUB:\n  \"TFs ~= {} ==> LUB_TF TFs isLUB TFs\"\napply (simp add: pair_LUB_decompo)\napply (simp add: LUB_TF_def)\napply (simp add: isLUB_UnionT isLUB_UnionF)\ndone\n\n(*** LUB --> LUB_TF ***)\n\nlemma isLUB_LUB_TF_only_if:\n  \"[| TFs ~= {} ; TF isLUB TFs |] ==> TF = LUB_TF TFs\"\napply (insert LUB_TF_isLUB[of TFs])\nby (simp add: LUB_unique)\n\n(* iff *)\n\nlemma isLUB_LUB_TF : \"TFs ~= {} ==> TF isLUB TFs = (TF = LUB_TF TFs)\"\napply (rule iffI)\napply (simp add: isLUB_LUB_TF_only_if)\napply (simp add: LUB_TF_isLUB)\ndone\n\n(*** LUB TF = LUB_TF ***)\n\nlemma LUB_LUB_TF:\n  \"TFs ~= {} ==> LUB TFs = LUB_TF TFs\"\nby (simp add: isLUB_LUB LUB_TF_isLUB)\n\n(****** LUB_TF TFs in domF ******)\n\n(* T3_F4 *)\n\nlemma LUB_TF_in_T3_F4: \n  \"[| TFs ~= {} ; ALL TF:TFs. TF:domF |] ==> HC_T3_F4 (LUB_TF TFs)\"\napply (simp add: LUB_TF_def HC_T3_F4_def)\napply (intro allI impI)\napply (elim bexE conjE)\napply (drule_tac x=\"x\" in bspec, simp)\n\napply (simp add: domF_iff HC_T3_F4_def)\nby (auto)\n\n(* F3 *)\n\nlemma LUB_TF_in_F3: \n  \"[| TFs ~= {} ; ALL TF:TFs. TF:domF |] ==> HC_F3 (LUB_TF TFs)\"\napply (simp add: LUB_TF_def HC_F3_def)\napply (intro allI impI)\n\napply (elim bexE conjE)\napply (drule_tac x=\"x\" in bspec, simp)\n\napply (simp add: domF_def HC_F3_def)\napply (elim conjE)\napply (drule_tac x=\"s\" in spec)\napply (drule_tac x=\"X\" in spec)\napply (drule_tac x=\"Y\" in spec)\nby (auto)\n\n(* T2 *)\n\nlemma LUB_TF_in_T2: \n  \"[| TFs ~= {} ; ALL TF:TFs. TF:domF |] ==> HC_T2 (LUB_TF TFs)\"\napply (simp add: LUB_TF_def HC_T2_def)\napply (intro allI impI)\n\napply (elim exE bexE)\napply (drule_tac x=\"x\" in bspec, simp)\n\napply (simp add: domF_def HC_T2_def)\napply (elim conjE)\napply (drule_tac x=\"s\" in spec)\nby (auto)\n\n(*** LUB_TF TFs in domF ***)\n\nlemma LUB_TF_in: \n  \"[| TFs ~= {} ; ALL TF:TFs. TF:domF |] ==> (LUB_TF TFs): domF\"\napply (simp (no_asm) add: domF_iff)\napply (simp add: LUB_TF_in_T2)\napply (simp add: LUB_TF_in_F3)\napply (simp add: LUB_TF_in_T3_F4)\ndone\n\nlemma LUB_TF_in_Rep: \n  \"Fs ~= {} ==> (LUB_TF (Rep_domF ` Fs)): domF\"\napply (rule LUB_TF_in)\napply (auto)\ndone\n\n(************* LUB_domF *************)\n\n(* isLUB lemma *)\n\nlemma TF_isLUB_domFs:\n  \"[| TF:domF ; TF isLUB Rep_domF ` Fs |] ==> Abs_domF TF isLUB Fs\"\napply (simp add: isUB_def isLUB_def)\napply (rule conjI)\n\n(* ub *)\napply (intro allI impI)\napply (elim bexE conjE)\napply (drule_tac x=\"fst (Rep_domF y)\" in spec)\napply (drule_tac x=\"snd (Rep_domF y)\" in spec)\napply (simp add: subdomF_def Abs_domF_inverse)\n\n(* lub *)\napply (intro allI impI)\napply (elim bexE conjE)\napply (rotate_tac -1)\napply (drule_tac x=\"fst (Rep_domF y)\" in spec)\napply (rotate_tac -1)\napply (drule_tac x=\"snd (Rep_domF y)\" in spec)\napply (simp)\napply (drule mp)\n apply (intro allI impI)\n apply (simp add: image_def)\n apply (elim bexE conjE)\n apply (drule_tac x=\"x\" in spec)\n apply (simp)\n apply (simp add: subdomF_def)\napply (simp add: subdomF_def Abs_domF_inverse)\ndone\n\n(*** LUB_domF --> LUB ***)\n\nlemma LUB_domF_isLUB:\n  \"Fs ~= {} ==> LUB_domF Fs isLUB Fs\"\napply (simp add: LUB_domF_def)\napply (rule TF_isLUB_domFs)\napply (simp add: LUB_TF_in)\napply (simp add: LUB_TF_isLUB)\ndone\n\nlemma LUB_domF_isLUB_I:\n  \"[| Fs ~= {} ; F = LUB_domF Fs |] ==> F isLUB Fs\"\nby (simp add: LUB_domF_isLUB)\n\n(*** LUB --> LUB_domF ***)\n\nlemma isLUB_LUB_domF_only_if:\n  \"[| Fs ~= {} ; F isLUB Fs |] ==> F = LUB_domF Fs\"\napply (insert LUB_domF_isLUB[of Fs])\nby (simp add: LUB_unique)\n\n(* iff *)\n\nlemma isLUB_LUB_domF : \"Fs ~= {} ==> F isLUB Fs = (F = LUB_domF Fs)\"\napply (rule iffI)\napply (simp add: isLUB_LUB_domF_only_if)\napply (simp add: LUB_domF_isLUB)\ndone\n\n(********************************************************** \n                ( domF, <= ) is a CPO\n **********************************************************)\n\ninstance domF :: (type) cpo\napply (intro_classes)\napply (simp add: hasLUB_def)\napply (rule_tac x=\"LUB_domF X\" in exI)\nby (simp add: directed_def LUB_domF_isLUB)\n\n(********************************************************** \n             ( domF, <= ) is a pointed CPO\n **********************************************************)\n\ninstance domF :: (type) cpo_bot\nby (intro_classes)\n\n(********************************************************** \n                 continuity of Abs_domF\n **********************************************************)\n\n(*** Abs_domF ***)\n\nlemma continuous_Abs_domF:\n \"[| ALL x. f x: domF ; continuous f |] ==> continuous (Abs_domF o f)\"\napply (simp add: continuous_iff)\napply (intro allI impI)\napply (drule_tac x=\"X\" in spec, simp)\napply (elim conjE exE)\napply (rule_tac x=\"x\" in exI, simp)\napply (rule TF_isLUB_domFs)\napply (simp)\n\napply (subgoal_tac \"Rep_domF ` (Abs_domF o f) ` X = f ` X\")\nby (auto simp add: image_def Abs_domF_inverse)\n\n(*** Rep_domF ***)\n\nlemma cont_Rep_domF: \"continuous Rep_domF\"\napply (simp add: continuous_iff)\napply (intro allI impI)\napply (rule_tac x=\"LUB_domF X\" in exI)\n\napply (simp add: directed_def LUB_domF_isLUB)\napply (simp add: isLUB_LUB_TF)\napply (simp add: LUB_domF_def)\napply (simp add: LUB_TF_in Abs_domF_inverse)\ndone\n\n(*** fstF and sndF ***)\n\nlemma fstF_continuous: \"continuous fstF\"\napply (simp add: fstF_def)\napply (rule compo_continuous)\napply (simp add: cont_Rep_domF)\napply (simp add: fst_continuous)\ndone\n\nlemma sndF_continuous: \"continuous sndF\"\napply (simp add: sndF_def)\napply (rule compo_continuous)\napply (simp add: cont_Rep_domF)\napply (simp add: snd_continuous)\ndone\n\n(********************************************************** \n                continuity decomposition\n **********************************************************)\n\n(*** if ***)\n\nlemma continuous_domF:\n \"[| ALL x. (f x, g x): domF ; continuous f ; continuous g |]\n  ==> continuous (%x. (f x ,, g x))\"\napply (simp add: pairF_def)\napply (subgoal_tac \"(%x. Abs_domF (f x, g x)) = Abs_domF o (%x. (f x, g x))\")\napply (simp)\napply (rule continuous_Abs_domF)\napply (simp)\napply (simp add: pair_continuous)\napply (simp add: comp_def)\napply (simp add: fun_eq_iff)\ndone\n\nlemmas continuous_domF_decompo_if = continuous_domF\n\n(*** only if ***)\n\nlemma continuous_domF_decompo_only_if_lm:\n  \"[| ALL x. (f x, g x) : domF; continuous (%x. (f x , g x)) |]\n       ==> continuous f & continuous g\"\napply (simp add: pair_continuous)\napply (simp add: comp_def)\ndone\n\nlemma continuous_domF_decompo_only_if:\n  \"[| ALL x. (f x, g x) : domF; continuous (%x. (f x ,, g x)) |]\n   ==> continuous f & continuous g\"\napply (rule continuous_domF_decompo_only_if_lm)\napply (simp)\napply (simp add: pairF_def)\napply (insert compo_continuous\n       [of \"(%x. Abs_domF (f x, g x))\" \"Rep_domF\" ])\napply (simp add: comp_def)\napply (simp add: cont_Rep_domF)\napply (simp add: Abs_domF_inverse)\ndone\n\nlemma continuous_domF_decompo:\n  \"ALL x. (f x, g x) : domF\n   ==> continuous (%x. (f x ,, g x)) = (continuous f & continuous g)\"\napply (rule)\napply (simp add: continuous_domF_decompo_only_if)\napply (simp add: continuous_domF_decompo_if)\ndone\n\n(********************************************************** \n                continuity of (op o fstF)\n **********************************************************)\n\n(* lemma continuous_op_fstF: \"continuous (op o fstF)\" *)\nlemma continuous_op_fstF: \"continuous ((o) fstF)\"\napply (simp add: continuous_iff)\napply (intro allI impI)\napply (insert complete_cpo_lm)\napply (drule_tac x=\"X\" in spec)\napply (simp add: hasLUB_def)\n\napply (elim exE)\napply (rule_tac x=\"x\" in exI)\napply (simp)\napply (simp add: image_def)\napply (simp add: isLUB_def)\napply (simp add: isUB_def)\napply (rule)\n\n (* UB *)\n apply (intro allI impI)\n apply (elim conjE bexE) \n apply (simp)\n apply (drule_tac x=\"xa\" in spec)\n apply (simp add: order_prod_def)\n apply (simp add: mono_fstF[simplified mono_def])\n\n (* LUB *)\n apply (intro allI impI)\n apply (elim conjE)\n\n apply (rotate_tac -1)\n apply (drule_tac x=\"(%pn. (y pn ,, maxFof (y pn)))\" in spec)\n apply (drule mp)\n\n  apply (intro allI impI)\n  apply (drule_tac x=\"fstF o ya\" in spec)\n  apply (drule mp, fast)\n  apply (simp add: order_prod_def)\n  apply (intro allI impI)\n  apply (drule_tac x=\"xa\" in spec)\n  apply (simp add: subdomF_decompo)\n  apply (simp add: pairF maxFof_domF)\n  apply (rule)\n  apply (simp add: subdomT_iff)\n  apply (drule_tac x=\"s\" in spec)\n  apply (simp add: pairF_domF_T2)\n  apply (simp add: maxFof_max)\n\n apply (simp add: order_prod_def)\n apply (simp add: subdomF_decompo)\n apply (simp add: pairF maxFof_domF)\ndone\n\n(********************************************************** \n              fstF-distribution over LUB\n **********************************************************)\n\nlemma dist_fstF_LUB:\n  \"X ~= {} ==> fstF o LUB X = LUB (((o) fstF) ` X)\"\n(*  \"X ~= {} ==> fstF o LUB X = LUB ((op o fstF) ` X)\" *)\napply (subgoal_tac \"X hasLUB\")\napply (rule sym)\napply (rule isLUB_LUB)\napply (simp add: isLUB_def isUB_def)\napply (rule)\n\n(* UB *)\n apply (intro allI impI)\n apply (simp add: image_iff)\n apply (simp add: comp_def)\n apply (elim bexE)\n apply (simp add: order_prod_def)\n apply (intro allI)\n apply (subgoal_tac \"x <= LUB X\")\n\n  apply (simp add: order_prod_def)\n  apply (simp add: mono_fstF[simplified mono_def])\n  apply (subgoal_tac \"LUB X isLUB X\")\n  apply (simp add: isLUB_def isUB_def)\n  apply (simp add: LUB_is)\n\n(* LUB *)\n apply (intro allI impI)\n apply (simp add: order_prod_def)\n apply (intro allI impI)\n apply (subgoal_tac \"(LUB X) isLUB X\")\n\n  apply (simp add: prod_LUB_decompo)\n  apply (simp add: proj_fun_def)\n  apply (drule_tac x=\"x\" in spec)\n  apply (subgoal_tac \"(%xa. xa x) ` X ~= {}\")\n\n   apply (simp add: isLUB_LUB_domF)\n   apply (simp add: LUB_domF_def)\n   apply (simp add: fstF_def)\n   apply (simp add: LUB_TF_in_Rep Abs_domF_inverse)\n   apply (simp add: LUB_TF_def)\n   apply (rule subdomTI)\n   apply (simp)\n   apply (elim conjE bexE)\n   apply (drule_tac x=\"fstF o xa\" in spec)\n   apply (drule mp)\n    apply (simp add: image_iff)\n    apply (rule_tac x=\"xa\" in bexI)\n    apply (simp add: fstF_def)\n    apply (simp)\n   apply (drule_tac x=\"x\" in spec)\n   apply (simp add: subdomT_iff)\n   apply (drule_tac x=\"t\" in spec)\n   apply (simp add: fstF_def)\n\n  apply (force)\n apply (rule LUB_is)\n apply (simp)\n\napply (simp add: hasLUB_def)\napply (simp add: prod_LUB_decompo)\napply (simp add: proj_fun_def)\napply (rule_tac x=\"(%i. LUB_domF ((%x. x i) ` X))\" in exI)\napply (simp add: isLUB_LUB_domF)\ndone\n\n(****************** to add them again ******************)\n(*\ndeclare Union_image_eq [simp]\ndeclare Inter_image_eq [simp]\n*)\n(*\ndeclare Sup_image_eq [simp]\ndeclare Inf_image_eq [simp]\n*)\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/CSP_F/Domain_F_cpo.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5312093733737563, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.2801154799540876}}
{"text": "(*  Title:       Isabelle Collections Library\n    Author:      Peter Lammich <peter dot lammich at uni-muenster.de>\n    Maintainer:  Peter Lammich <peter dot lammich at uni-muenster.de>\n*)\nsection \\<open>\\isaheader{Hash Set}\\<close>\ntheory HashSet\n  imports \n  \"../spec/SetSpec\" \n  HashMap \n  \"../gen_algo/SetByMap\" \n  \"../gen_algo/SetGA\"\nbegin\ntext_raw \\<open>\\label{thy:HashSet}\\<close>\n(*@impl Set\n  @type 'a::hashable hs\n  @abbrv hs,h\n  Hash sets based on red-black trees.\n*)\n\nsubsection \"Definitions\"\ntype_synonym\n  'a hs = \"('a::hashable,unit) hm\"\n\nsetup Locale_Code.open_block\ninterpretation hs_sbm: SetByMap hm_basic_ops by unfold_locales\nsetup Locale_Code.close_block\n\ndefinition hs_ops :: \"('a::hashable,'a hs) set_ops\"\n  where [icf_rec_def]:\n  \"hs_ops \\<equiv> hs_sbm.basic.dflt_ops\"\n\nsetup Locale_Code.open_block\ninterpretation hs: StdSet hs_ops\n  unfolding hs_ops_def by (rule hs_sbm.basic.dflt_ops_impl)\ninterpretation hs: StdSet_no_invar hs_ops\n  by unfold_locales (simp add: icf_rec_unf SetByMapDefs.invar_def)\nsetup Locale_Code.close_block\n\nsetup \\<open>ICF_Tools.revert_abbrevs \"hs\"\\<close>\n\nlemmas hs_it_to_it_map_code_unfold[code_unfold] = \n  it_to_it_map_fold'[OF pi_hm]\n\nlemma pi_hs[proper_it]: \"proper_it' hs.iteratei hs.iteratei\"\n  unfolding hs.iteratei_def[abs_def]\n  by (rule proper_it'I icf_proper_iteratorI)+\n\ninterpretation pi_hs: proper_it_loc hs.iteratei hs.iteratei\n  by unfold_locales (rule pi_hs)\n\ndefinition test_codegen where \"test_codegen \\<equiv> (\n  hs.empty,\n  hs.memb,\n  hs.ins,\n  hs.delete,\n  hs.list_it,\n  hs.sng,\n  hs.isEmpty,\n  hs.isSng,\n  hs.ball,\n  hs.bex,\n  hs.size,\n  hs.size_abort,\n  hs.union,\n  hs.union_dj,\n  hs.diff,\n  hs.filter,\n  hs.inter,\n  hs.subset,\n  hs.equal,\n  hs.disjoint,\n  hs.disjoint_witness,\n  hs.sel,\n  hs.to_list,\n  hs.from_list\n)\"\n\nexport_code test_codegen checking SML\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Evaluation/Collections/ICF/impl/HashSet.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.5312093733737562, "lm_q1q2_score": 0.28011547995408753}}
{"text": "(* @TAG(OTHER_LGPL) *)\n\n(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      ProcParEx.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2006-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection \"Examples for Procedures as Parameters\"\n\ntheory ProcParEx imports \"../Vcg\" begin\n\n\n\n\n\nlemma conseq_exploit_pre':\n             \"\\<lbrakk>\\<forall>s \\<in> S. \\<Gamma>,\\<Theta> \\<turnstile> ({s} \\<inter> P) c Q,A\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile> (P \\<inter> S)c Q,A\"\n  apply (rule HoarePartialDef.Conseq)\n  apply clarify\n  by (metis IntI insertI1 subset_refl)\n\n\nlemma conseq_exploit_pre'':\n             \"\\<lbrakk>\\<forall>Z. \\<forall>s \\<in> S Z.  \\<Gamma>,\\<Theta> \\<turnstile> ({s} \\<inter> P Z) c (Q Z),(A Z)\\<rbrakk>\n              \\<Longrightarrow>\n              \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile> (P Z \\<inter> S Z)c (Q Z),(A Z)\"\n  apply (rule allI)\n  apply (rule conseq_exploit_pre')\n  apply blast\n  done\n\nlemma conseq_exploit_pre''':\n             \"\\<lbrakk>\\<forall>s \\<in> S. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile> ({s} \\<inter> P Z) c (Q Z),(A Z)\\<rbrakk>\n              \\<Longrightarrow>\n              \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile> (P Z \\<inter> S)c (Q Z),(A Z)\"\n  apply (rule allI)\n  apply (rule conseq_exploit_pre')\n  apply blast\n  done\n\n\n  \nrecord 'g vars = \"'g state\" +\n  compare_' :: string\n  n_'   :: nat\n  m_'   :: nat\n  b_'   :: bool\n  k_'  :: nat\n \n\n\nprocedures compare(n,m|b) = \"NoBody\"\nprint_locale! compare_signature\n\n\ncontext compare_signature\nbegin\ndeclare [[hoare_use_call_tr' = false]]\nterm \"\\<acute>b :== CALL compare(\\<acute>n,\\<acute>m)\"\nterm \"\\<acute>b :== DYNCALL \\<acute>compare(\\<acute>n,\\<acute>m)\"\ndeclare [[hoare_use_call_tr' = true]]\nterm \"\\<acute>b :== DYNCALL \\<acute>compare(\\<acute>n,\\<acute>m)\"\nend\n\n\nprocedures\n  LEQ (n,m | b) = \"\\<acute>b :== \\<acute>n \\<le> \\<acute>m\"\n  LEQ_spec: \"\\<forall>\\<sigma>. \\<Gamma>\\<turnstile> {\\<sigma>}  PROC LEQ(\\<acute>n,\\<acute>m,\\<acute>b) \\<lbrace>\\<acute>b = (\\<^bsup>\\<sigma>\\<^esup>n \\<le> \\<^bsup>\\<sigma>\\<^esup>m)\\<rbrace>\"\n  LEQ_modifies: \"\\<forall>\\<sigma>. \\<Gamma>\\<turnstile> {\\<sigma>} PROC LEQ(\\<acute>n,\\<acute>m,\\<acute>b) {t. t may_only_modify_globals \\<sigma> in []}\"\n\n\n\ndefinition mx:: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool) \\<Rightarrow> 'a \\<Rightarrow> 'a \\<Rightarrow> 'a\"\n  where \"mx leq a b = (if leq a b then a else b)\"\n\nprocedures\n  Max (compare, n, m | k) = \n  \"\\<acute>b :== DYNCALL \\<acute>compare(\\<acute>n,\\<acute>m);;\n   IF \\<acute>b THEN \\<acute>k :== \\<acute>n ELSE \\<acute>k :== \\<acute>m FI\"\n\n  Max_spec: \"\\<And>leq. \\<forall>\\<sigma>. \\<Gamma>\\<turnstile> \n  ({\\<sigma>} \\<inter> {s. (\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>b :== PROC \\<^bsup>s\\<^esup>compare(\\<acute>n,\\<acute>m) \\<lbrace>\\<acute>b = (leq \\<^bsup>\\<tau>\\<^esup>n \\<^bsup>\\<tau>\\<^esup>m)\\<rbrace>) \\<and> \n              (\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>b :== PROC \\<^bsup>s\\<^esup>compare(\\<acute>n,\\<acute>m) {t. t may_only_modify_globals \\<tau> in []})})\n    PROC Max(\\<acute>compare,\\<acute>n,\\<acute>m,\\<acute>k)\n  \\<lbrace>\\<acute>k = mx leq \\<^bsup>\\<sigma>\\<^esup>n \\<^bsup>\\<sigma>\\<^esup>m\\<rbrace>\"\n\n\nlemma (in Max_impl ) Max_spec1: \nshows\n\"\\<forall>\\<sigma> leq. \\<Gamma>\\<turnstile> \n  ({\\<sigma>} \\<inter> \\<lbrace> (\\<forall>\\<tau>. \\<Gamma>\\<turnstile>{\\<tau>} \\<acute>b :== PROC \\<acute>compare(\\<acute>n,\\<acute>m) \\<lbrace>\\<acute>b = (leq \\<^bsup>\\<tau>\\<^esup>n \\<^bsup>\\<tau>\\<^esup>m)\\<rbrace>) \\<and> \n      (\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>b :== PROC \\<acute>compare(\\<acute>n,\\<acute>m) {t. t may_only_modify_globals \\<tau> in []})\\<rbrace>)\n    \\<acute>k :== PROC Max(\\<acute>compare,\\<acute>n,\\<acute>m)\n  \\<lbrace>\\<acute>k = mx leq \\<^bsup>\\<sigma>\\<^esup>n \\<^bsup>\\<sigma>\\<^esup>m\\<rbrace>\"\napply (hoare_rule HoarePartial.ProcNoRec1)\napply (intro allI)\napply (rule conseq_exploit_pre')\napply (rule)\napply clarify\nproof -\n  fix \\<sigma>:: \"('a,'b) vars_scheme\" and s::\"('a,'b) vars_scheme\" and leq\n   assume compare_spec: \n       \"\\<forall>\\<tau>. \\<Gamma>\\<turnstile>{\\<tau>} \\<acute>b :== PROC \\<^bsup>s\\<^esup>compare(\\<acute>n,\\<acute>m) \\<lbrace>\\<acute>b = leq \\<^bsup>\\<tau>\\<^esup>n \\<^bsup>\\<tau>\\<^esup>m\\<rbrace>\"\n \n  assume compare_modifies:\n        \"\\<forall>\\<tau>. \\<Gamma>\\<turnstile>{\\<tau>} \\<acute>b :== PROC \\<^bsup>s\\<^esup>compare(\\<acute>n,\\<acute>m) \n                {t. t may_only_modify_globals \\<tau> in []}\"\n\n   show \"\\<Gamma>\\<turnstile>({s} \\<inter> {\\<sigma>})\n            \\<acute>b :== DYNCALL \\<acute>compare (\\<acute>n,\\<acute>m);;\n            IF \\<acute>b THEN \\<acute>k :== \\<acute>n ELSE \\<acute>k :== \\<acute>m FI\n            \\<lbrace>\\<acute>k = mx leq \\<^bsup>\\<sigma>\\<^esup>n \\<^bsup>\\<sigma>\\<^esup>m\\<rbrace>\"\n     apply vcg\n     apply (clarsimp simp add: mx_def)\n     done\n qed\n\n\nlemma (in Max_impl) Max_spec2: \nshows\n\"\\<forall>\\<sigma> leq. \\<Gamma>\\<turnstile> \n  ({\\<sigma>} \\<inter> \\<lbrace>(\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>b :== PROC \\<acute>compare(\\<acute>n,\\<acute>m) \\<lbrace>\\<acute>b = (leq \\<^bsup>\\<tau>\\<^esup>n \\<^bsup>\\<tau>\\<^esup>m)\\<rbrace>) \\<and> \n      (\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>b :== PROC \\<acute>compare(\\<acute>n,\\<acute>m) {t. t may_only_modify_globals \\<tau> in []})\\<rbrace>)\n    \\<acute>k :== PROC Max(\\<acute>compare,\\<acute>n,\\<acute>m)\n  \\<lbrace>\\<acute>k = mx leq \\<^bsup>\\<sigma>\\<^esup>n \\<^bsup>\\<sigma>\\<^esup>m\\<rbrace>\"\napply (hoare_rule HoarePartial.ProcNoRec1)\napply (intro allI)\napply (rule conseq_exploit_pre')\napply (rule)\napply clarify\napply vcg\napply (clarsimp simp add: mx_def)\ndone\n\nlemma (in Max_impl) Max_spec3: \nshows\n\"\\<forall>n m leq. \\<Gamma>\\<turnstile> \n  (\\<lbrace>\\<acute>n=n \\<and> \\<acute>m=m\\<rbrace>  \\<inter> \n   \\<lbrace>(\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>b :== PROC \\<acute>compare(\\<acute>n,\\<acute>m) \\<lbrace>\\<acute>b = (leq \\<^bsup>\\<tau>\\<^esup>n \\<^bsup>\\<tau>\\<^esup>m)\\<rbrace>) \\<and> \n     (\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>b :== PROC \\<acute>compare(\\<acute>n,\\<acute>m) {t. t may_only_modify_globals \\<tau> in []})\\<rbrace>)\n    \\<acute>k :== PROC Max(\\<acute>compare,\\<acute>n,\\<acute>m)\n  \\<lbrace>\\<acute>k = mx leq n m\\<rbrace>\"\napply (hoare_rule HoarePartial.ProcNoRec1)\napply (intro allI)\napply (rule conseq_exploit_pre')\napply (rule)\napply clarify\napply vcg\napply (clarsimp simp add: mx_def)\ndone\n\n\n\nlocale Max_test = Max_spec + LEQ_spec + LEQ_modifies \nlemma (in Max_test) \n\n  shows\n  \"\\<Gamma>\\<turnstile> {\\<sigma>} \\<acute>k :== CALL Max(LEQ_'proc,\\<acute>n,\\<acute>m) \\<lbrace>\\<acute>k = mx (op \\<le>) \\<^bsup>\\<sigma>\\<^esup>n \\<^bsup>\\<sigma>\\<^esup>m\\<rbrace>\"\nproof -\n  note Max_spec = Max_spec [where leq=\"(op \\<le>)\"]\n  show ?thesis\n    apply vcg\n    apply (clarsimp)\n    apply (rule conjI)\n    apply (rule LEQ_spec [simplified])\n    apply (rule LEQ_modifies [simplified])\n    done\nqed\n\n\nlemma (in Max_impl) Max_spec5:\nshows\n\"\\<forall>n m leq. \\<Gamma>\\<turnstile> \n  (\\<lbrace>\\<acute>n=n \\<and> \\<acute>m=m\\<rbrace> \\<inter> \\<lbrace>\\<forall>n' m'. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>n=n' \\<and> \\<acute>m=m'\\<rbrace> \\<acute>b :== PROC \\<acute>compare(\\<acute>n,\\<acute>m) \\<lbrace>\\<acute>b = (leq n' m')\\<rbrace>\\<rbrace>)\n    \\<acute>k :== PROC Max(\\<acute>compare,\\<acute>n,\\<acute>m)\n  \\<lbrace>\\<acute>k = mx leq n m\\<rbrace>\"\nterm \"\\<lbrace>{s. \\<^bsup>s\\<^esup>n = n' \\<and> \\<^bsup>s\\<^esup>m = m'} = X\\<rbrace>\"\napply (hoare_rule HoarePartial.ProcNoRec1)\napply (intro allI)\napply (rule conseq_exploit_pre')\napply (rule)\napply clarify\napply vcg\napply clarsimp\napply (clarsimp simp add: mx_def)\ndone\n\nlemma (in LEQ_impl)\n LEQ_spec: \"\\<forall>n m. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>n=n \\<and> \\<acute>m=m\\<rbrace>  PROC LEQ(\\<acute>n,\\<acute>m,\\<acute>b) \\<lbrace>\\<acute>b = (n \\<le> m)\\<rbrace>\"\n  apply vcg\n  done\n\n\nlocale Max_test' = Max_impl + LEQ_impl\nlemma (in Max_test') \n  shows\n  \"\\<forall>n m. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>n=n \\<and> \\<acute>m=m\\<rbrace> \\<acute>k :== CALL Max(LEQ_'proc,\\<acute>n,\\<acute>m) \\<lbrace>\\<acute>k = mx (op \\<le>) n m\\<rbrace>\"\nproof -\n  note Max_spec = Max_spec5\n  show ?thesis\n    apply vcg\n    apply (rule_tac x=\"op \\<le>\" in exI)\n    apply clarsimp\n    apply (rule LEQ_spec [rule_format])\n    done\nqed\n\nend\n", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/c-parser/Simpl/ex/ProcParEx.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5156199157230156, "lm_q2_score": 0.5428632831725053, "lm_q1q2_score": 0.2799111203185267}}
{"text": "theory PermEnvMisc\n  imports PermEnvLeq\nbegin\n  \n    (* \n      ####################################\n        P2. weak disjointness lemmas\n      ####################################\n    *)  \n\nlemma mini_disj_leq_use_env1: \"\\<lbrakk> mini_disj_use_env r_s r_ex; leq_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> mini_disj_use_env r_x r_ex\"    \n  apply (simp add: leq_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (rule_tac allI)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (case_tac \"r_s x\")\n     apply (auto)\n  done\n\nlemma mini_disj_leq_use_env2: \"\\<lbrakk> mini_disj_use_env r_ex r_s; leq_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> mini_disj_use_env r_ex r_x\"        \n  apply (simp add: leq_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (rule_tac allI)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)  \n  apply (case_tac \"r_x x\")\n    apply (auto)\n  done   \n\nlemma mini_disj_comp_use_env: \"\\<lbrakk> mini_disj_use_env r_x r_ex; mini_disj_use_env r_s r_ex \\<rbrakk> \\<Longrightarrow> mini_disj_use_env (comp_use_env r_x r_s) r_ex\"    \n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: comp_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)  \n  apply (case_tac \"r_x x\")\n    apply (auto)\n   apply (case_tac \"r_s x\")\n     apply (auto)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n  done\n \nlemma mini_disj_comp_use_env_alt: \"\\<lbrakk> mini_disj_use_env r_ex r_x; mini_disj_use_env r_ex r_s \\<rbrakk> \\<Longrightarrow> mini_disj_use_env r_ex (comp_use_env r_x r_s)\"       \n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: comp_use_env_def)\n  done    \n\nlemma mini_disj_diff_use_env: \"mini_disj_use_env r_x (diff_use_env r_s r_x)\"\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: diff_use_env_def)\n  done     \n\nlemma swp_mini_disj_use_env: \"\\<lbrakk> leq_use_env rx_p (diff_use_env r_s r_ex) \\<rbrakk> \\<Longrightarrow> mini_disj_use_env r_ex rx_p\"    \n  apply (simp add: mini_disj_use_env_def)\n  apply (auto)\n  apply (rule_tac r_s=\"diff_use_env r_s r_ex\" in leq_use_none)\n   apply (auto)\n  apply (rule_tac diff_use_none_ex)\n  apply (auto)\n  done    \n    \nlemma mini_disj_empty_use_env: \"mini_disj_use_env empty_use_env r_s\"\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: empty_use_env_def)\n  done\n  \n    \n    (* \n      ####################################\n        P3. main disjointness lemmas\n      ####################################\n    *)    \n\nlemma comm_disj_use_env: \"\\<lbrakk> disj_use_env r_s r_x \\<rbrakk> \\<Longrightarrow> disj_use_env r_x r_s\"\n  apply (simp add: disj_use_env_def)\n  done        \n    \n    (* - ordering lemmas *)\n    \nlemma disj_leq_use_env1: \"\\<lbrakk> disj_use_env r_s r_ex; leq_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> disj_use_env r_x r_ex\"\n  apply (simp add: disj_use_env_def)\n  apply (auto)\n   apply (rule_tac mini_disj_leq_use_env1)\n    apply (auto)\n  apply (rule_tac mini_disj_leq_use_env2)\n   apply (auto)\n  done\n\nlemma disj_leq_use_env2: \"\\<lbrakk> disj_use_env r_ex r_s; leq_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> disj_use_env r_ex r_x\"\n  apply (simp add: disj_use_env_def)\n  apply (auto)\n   apply (rule_tac mini_disj_leq_use_env2)\n    apply (auto)\n  apply (rule_tac mini_disj_leq_use_env1)\n   apply (auto)\n  done     \n    \n    (* - comp lemmas *)\n    \nlemma disj_comp_use_env1: \"\\<lbrakk> disj_use_env r_s1 r_ex; disj_use_env r_s2 r_ex \\<rbrakk> \\<Longrightarrow> disj_use_env (comp_use_env r_s1 r_s2) r_ex\"\n  apply (simp add: disj_use_env_def)\n  apply (auto)\n   apply (rule_tac mini_disj_comp_use_env)\n    apply (auto)\n  apply (rule_tac mini_disj_comp_use_env_alt)\n   apply (auto)\n  done\n\nlemma disj_comp_use_env2: \"\\<lbrakk> disj_use_env r_ex r_s1; disj_use_env r_ex r_s2 \\<rbrakk> \\<Longrightarrow> disj_use_env r_ex (comp_use_env r_s1 r_s2)\"    \n  apply (simp add: disj_use_env_def)\n  apply (auto)\n   apply (rule_tac mini_disj_comp_use_env_alt)\n    apply (auto)\n  apply (rule_tac mini_disj_comp_use_env)\n   apply (auto)\n  done\n\n    (* - lemmas TO BE SORTED *)    \n\nlemma gen_mini_disj_use_env1: \"\\<lbrakk> disj_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> mini_disj_use_env r_x r_s\"    \n  apply (simp add: disj_use_env_def)\n  done\n    \nlemma gen_mini_disj_use_env2: \"\\<lbrakk> disj_use_env r_s r_x \\<rbrakk> \\<Longrightarrow> mini_disj_use_env r_x r_s\"    \n  apply (simp add: disj_use_env_def)\n  done\n    \nlemma disj_add_use_env: \"\\<lbrakk> r_x x = NoPerm; disj_use_env r_s r_x \\<rbrakk> \\<Longrightarrow> disj_use_env (add_use_env r_s x r) r_x\"    \n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: add_use_env_def)\n  done    \n    \nlemma disj_rem_use_env1: \"\\<lbrakk> disj_use_env r_s r_x \\<rbrakk> \\<Longrightarrow> disj_use_env r_s (rem_use_env r_x x)\"      \n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: rem_use_env_def)\n  done\n    \nlemma disj_rem_use_envx: \"\\<lbrakk> disj_use_env r_s r_x \\<rbrakk> \\<Longrightarrow> disj_use_env  (rem_use_env r_s x) r_x\"      \n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: rem_use_env_def)\n  done    \n  \nlemma disj_rem_use_env2: \"\\<lbrakk> r_s x = NoPerm; disj_use_env r_s (rem_use_env r_x x) \\<rbrakk> \\<Longrightarrow> disj_use_env r_s r_x\"    \n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: rem_use_env_def)\n  apply (auto)\n   apply (erule_tac x=\"xa\" in allE)\n   apply (auto)\n   apply (case_tac \"x = xa\")\n    apply (auto)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (auto)\n   apply (case_tac \"x = xa\")\n    apply (auto)\n  apply (case_tac \"x = xa\")\n   apply (auto)\n  done\n\nlemma disj_add_rem_use_env: \"\\<lbrakk> r_s x = NoPerm; disj_use_env r_s r_x \\<rbrakk> \\<Longrightarrow> disj_use_env (add_use_env r_s x r) (rem_use_env r_x x)\"\n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: add_use_env_def)\n  apply (simp add: rem_use_env_def)\n  done\n\nlemma double_weak_disj_use_env: \"\\<lbrakk> weak_use_env r_x; weak_use_env r_s \\<rbrakk> \\<Longrightarrow> disj_use_env r_x r_s\"\n  apply (simp add: weak_use_env_def)\n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  done\nlemma lease_mini_disj_use_env: \"\\<lbrakk> mini_disj_use_env r_s (diff_use_env r_x r_ex); mini_disj_use_env r_ex r_s \\<rbrakk> \\<Longrightarrow> mini_disj_use_env r_s r_x\"    \n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: diff_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (case_tac \"r_ex x\")\n    apply (auto)\n  done  \n  \nlemma lease_disj_use_env1: \"\\<lbrakk> disj_use_env r_s (diff_use_env r_x r_ex); mini_disj_use_env r_ex r_s \\<rbrakk> \\<Longrightarrow> disj_use_env r_s r_x\"    \n  apply (simp add: disj_use_env_def)\n  apply (auto)\n   apply (rule_tac lease_mini_disj_use_env)\n    apply (auto)\n    (* we expect a similar formulation to exist using this logic\n      rx2a | rx2 + [infl r_s2a - r_s3], rx2a |> rx2 + [infl r_s2a - r_s3], rx2a |> r_s3 - EX, EX |> r_s3 - EX\n      rx2 + [infl r_s2a - r_s3] |> rx2a - EX\n          apply (rule_tac r_s=\"diff_use_env r_s r_ex\" in mini_disj_leq_use_env2)\n    *)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: diff_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n   apply (case_tac \"r_ex x\")\n     apply (auto)\n  apply (case_tac \"r_ex x\")\n    apply (auto)\n  done\n \nlemma lease_disj_use_env2: \"\\<lbrakk> disj_use_env (diff_use_env r_x r_ex) r_s; mini_disj_use_env r_ex r_s \\<rbrakk> \\<Longrightarrow> disj_use_env r_x r_s\"\n  apply (rule_tac comm_disj_use_env)\n  apply (rule_tac r_ex=\"r_ex\" in lease_disj_use_env1)\n   apply (rule_tac comm_disj_use_env)\n   apply (auto)\n  done    \n    \n    (* - empty lemmas *)\n    \nlemma disj_empty_use_env1: \"disj_use_env r_s empty_use_env\"\n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: empty_use_env_def)\n  done\n\nlemma disj_empty_use_env2: \"disj_use_env empty_use_env r_s\"\n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: empty_use_env_def)\n  done\n    \n    (* - singleton lemmas *)\n    \nlemma disj_one_use_env: \"\\<lbrakk> r_s x = NoPerm \\<rbrakk> \\<Longrightarrow> disj_use_env r_s (one_use_env x OwnPerm)\"    \n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: one_use_env_def)\n  done  \n    \n    (* \n      ####################################\n        P3. weakness lemmas\n      ####################################\n    *)        \n  \nlemma leq_weak_use_env: \"\\<lbrakk> weak_use_env r_s; leq_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> weak_use_env r_x\"    \n  apply (simp add: weak_use_env_def)\n  apply (simp add: leq_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n  done    \n    \nlemma weak_comp_use_env1: \"\\<lbrakk> weak_use_env (comp_use_env r_sa r_sb) \\<rbrakk> \\<Longrightarrow> weak_use_env r_sa\"    \n  apply (simp add: weak_use_env_def)\n  apply (simp add: comp_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_sb x\")\n    apply (auto)\n  done\n \nlemma weak_comp_use_env2: \"\\<lbrakk> weak_use_env (comp_use_env r_sa r_sb) \\<rbrakk> \\<Longrightarrow> weak_use_env r_sb\"    \n  apply (simp add: weak_use_env_def)\n  apply (simp add: comp_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_sa x\")\n    apply (auto)\n  done    \n \nlemma dist_weak_comp_use_env: \"\\<lbrakk> weak_use_env r_sa; weak_use_env r_sb \\<rbrakk> \\<Longrightarrow> weak_use_env (comp_use_env r_sa r_sb)\"    \n  apply (simp add: weak_use_env_def)\n  apply (simp add: comp_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_sa x\")\n    apply (auto)\n   apply (case_tac \"r_sb x\")\n     apply (auto)\n  apply (case_tac \"r_sb x\")\n    apply (auto)\n  done       \n    \nlemma weak_diff_use_env: \"\\<lbrakk> weak_use_env r_s \\<rbrakk> \\<Longrightarrow> weak_use_env (diff_use_env r_s r_x)\"     \n  apply (simp add: weak_use_env_def)\n  apply (simp add: diff_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n   apply (case_tac \"r_x x\")\n     apply (auto)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n  done        \n\n    \nend", "meta": {"author": "anon-ef", "repo": "perm_lang_ef2", "sha": "0fcb6e4c175193cc7b94f297a8aaa605f502d711", "save_path": "github-repos/isabelle/anon-ef-perm_lang_ef2", "path": "github-repos/isabelle/anon-ef-perm_lang_ef2/perm_lang_ef2-0fcb6e4c175193cc7b94f297a8aaa605f502d711/perm_ref/PermEnvMisc.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.5156199157230156, "lm_q1q2_score": 0.27991112031852666}}
{"text": "section \\<open>Utilities for Interface Specifications and Implementations\\<close>\ntheory Sepref_Intf_Util\nimports Sepref_Rules Sepref_Translate \"Lib/Term_Synth\" Sepref_Combinator_Setup\n  \"Lib/Concl_Pres_Clarification\"\nkeywords \"sepref_decl_op\" :: thy_goal\n     and \"sepref_decl_impl\" :: thy_goal\nbegin\n\nsubsection \\<open>Relation Interface Binding\\<close>\n  definition INTF_OF_REL :: \"('a\\<times>'b) set \\<Rightarrow> 'c itself \\<Rightarrow> bool\"\n    where [simp]: \"INTF_OF_REL R I \\<equiv> True\"\n\n  lemma intf_of_relI: \"INTF_OF_REL (R::(_\\<times>'a) set) TYPE('a)\" by simp\n  declare intf_of_relI[synth_rules] \\<comment> \\<open>Declare as fallback rule\\<close>\n\n  lemma standard_intf_of_rel_rules[synth_rules]:\n    \"INTF_OF_REL unit_rel TYPE(unit)\"\n    \"INTF_OF_REL bool_rel TYPE(bool)\"\n\n    \"INTF_OF_REL R TYPE('a) \\<Longrightarrow> INTF_OF_REL (\\<langle>R\\<rangle>option_rel) TYPE('a option)\"\n    \"INTF_OF_REL R TYPE('a) \\<Longrightarrow> INTF_OF_REL (\\<langle>R\\<rangle>list_rel) TYPE('a list)\"\n    \"INTF_OF_REL R TYPE('a) \\<Longrightarrow> INTF_OF_REL (\\<langle>R\\<rangle>nres_rel) TYPE('a nres)\"\n    \"\\<lbrakk>INTF_OF_REL R TYPE('a); INTF_OF_REL S TYPE('b)\\<rbrakk> \\<Longrightarrow> INTF_OF_REL (R\\<times>\\<^sub>rS) TYPE('a\\<times>'b)\"\n    \"\\<lbrakk>INTF_OF_REL R TYPE('a); INTF_OF_REL S TYPE('b)\\<rbrakk> \\<Longrightarrow> INTF_OF_REL (\\<langle>R,S\\<rangle>sum_rel) TYPE('a+'b)\"\n    \"\\<lbrakk>INTF_OF_REL R TYPE('a); INTF_OF_REL S TYPE('b)\\<rbrakk> \\<Longrightarrow> INTF_OF_REL (R\\<rightarrow>S) TYPE('a\\<Rightarrow>'b)\"\n    \"\\<lbrakk>INTF_OF_REL (R\\<rightarrow>Sx undefined) TYPE('a)\\<rbrakk> \\<Longrightarrow> INTF_OF_REL (fref P R Sx) TYPE('a)\"\n    by simp_all\n\n  lemma synth_intf_of_relI: \n    \"INTF_OF_REL R I \\<Longrightarrow> SYNTH_TERM R I\" \n    \"INTF_OF_REL (Rx undefined) I \\<Longrightarrow> SYNTH_TERM Rx I\" \n    by simp_all\n\n\nsubsection \\<open>Operations with Precondition\\<close>\n  definition mop :: \"('a\\<Rightarrow>bool) \\<Rightarrow> ('a\\<Rightarrow>'b nres) \\<Rightarrow> 'a \\<Rightarrow> 'b nres\"\n    \\<comment> \\<open>Package operation with precondition\\<close>\n    where [simp]: \"mop P f \\<equiv> \\<lambda>x. doN {ASSERT (P x); f x}\"\n  \n  lemma param_op_mop_iff:\n    assumes \"(Q,P)\\<in>R\\<rightarrow>bool_rel\"\n    shows \n    \"(f, g) \\<in> [P]\\<^sub>f R \\<rightarrow> \\<langle>S\\<rangle>nres_rel\n    \\<longleftrightarrow> \n    (mop Q f, mop P g) \\<in> R \\<rightarrow>\\<^sub>f \\<langle>S\\<rangle>nres_rel\n    \"\n    using assms\n    by (auto \n      simp: mop_def fref_def pw_nres_rel_iff refine_pw_simps\n      dest: fun_relD)\n\n  lemma param_mopI:\n    assumes \"(f,g) \\<in> [P]\\<^sub>f R \\<rightarrow> \\<langle>S\\<rangle>nres_rel\"  \n    assumes \"(Q,P) \\<in> R \\<rightarrow> bool_rel\"\n    shows \"(mop Q f, mop P g) \\<in> R \\<rightarrow>\\<^sub>f \\<langle>S\\<rangle>nres_rel\"\n    using assms by (simp add: param_op_mop_iff)\n\n  lemma mop_spec_rl: \"P x \\<Longrightarrow> mop P f x \\<le> f x\" by simp\n\n  lemma mop_spec_rl_from_def:  \n    assumes \"f \\<equiv> mop P g\"\n    assumes \"P x\"\n    assumes \"g x \\<le> z\"\n    shows \"f x \\<le> z\"\n    using assms mop_spec_rl by simp\n\n  lemma mop_leof_rl_from_def:  \n    assumes \"f \\<equiv> mop P g\"\n    assumes \"P x \\<Longrightarrow> g x \\<le>\\<^sub>n z\"\n    shows \"f x \\<le>\\<^sub>n z\"\n    using assms \n    by (simp add: pw_leof_iff refine_pw_simps)\n\n\n  lemma assert_true_bind_conv: \"doN {ASSERT True; m} = m\" by simp \n\n  lemmas mop_alt_unfolds = curry_def curry0_def mop_def uncurry_apply uncurry0_apply o_apply assert_true_bind_conv\n\nsubsection \\<open>Constraints\\<close>\nlemma add_is_pure_constraint: \"\\<lbrakk>PROP P; CONSTRAINT is_pure A\\<rbrakk> \\<Longrightarrow> PROP P\" .\nlemma sepref_relpropI: \"P R = CONSTRAINT P R\" by simp\n\nsubsubsection \\<open>Purity\\<close>\nlemmas [constraint_simps] = the_pure_pure\ndefinition [constraint_abbrevs]: \"IS_PURE P R \\<equiv> is_pure R \\<and> P (the_pure R)\"\nlemma IS_PURE_pureI: \n  \"P R \\<Longrightarrow> IS_PURE P (pure R)\"\n  by (auto simp: IS_PURE_def)\n\nlemma [fcomp_norm_simps]: \"CONSTRAINT (IS_PURE \\<Phi>) P \\<Longrightarrow> pure (the_pure P) = P\" \n  by (simp add: IS_PURE_def)\n \nlemma [fcomp_norm_simps]: \"CONSTRAINT (IS_PURE P) A \\<Longrightarrow> P (the_pure A)\"\n  by (auto simp: IS_PURE_def)\n\nlemma handle_purity1: \n  \"CONSTRAINT (IS_PURE \\<Phi>) A \\<Longrightarrow> CONSTRAINT \\<Phi> (the_pure A)\"\n  by (auto simp: IS_PURE_def)\n\nlemma handle_purity2:\n  \"CONSTRAINT (IS_PURE \\<Phi>) A \\<Longrightarrow> CONSTRAINT is_pure A\"\n  by (auto simp: IS_PURE_def)\n\n\n\n\nsubsection \\<open>Composition\\<close>\n(* TODO/FIXME: Overlaps with FCOMP! *)\n\n  subsubsection \\<open>Preconditions\\<close>\n  definition [simp]: \"tcomp_pre Q T P \\<equiv> \\<lambda>a. Q a \\<and> (\\<forall>a'. (a', a) \\<in> T \\<longrightarrow> P a')\"\n  definition \"and_pre P1 P2 \\<equiv> \\<lambda>x. P1 x \\<and> P2 x\"\n  definition \"imp_pre P1 P2 \\<equiv> \\<lambda>x. P1 x \\<longrightarrow> P2 x\"\n\n  lemma and_pre_beta: \"PP \\<longrightarrow> P x \\<and> Q x \\<Longrightarrow> PP \\<longrightarrow> and_pre P Q x\" by (auto simp: and_pre_def)\n  lemma imp_pre_beta: \"PP \\<longrightarrow> P x \\<longrightarrow> Q x \\<Longrightarrow> PP \\<longrightarrow> imp_pre P Q x\" by (auto simp: imp_pre_def)\n\n\n\n  definition \"IMP_PRE P1 P2 \\<equiv> \\<forall>x. P1 x \\<longrightarrow> P2 x\"\n  lemma IMP_PRED: \"IMP_PRE P1 P2 \\<Longrightarrow> P1 x \\<Longrightarrow> P2 x\" unfolding IMP_PRE_def by auto\n  lemma IMP_PRE_refl: \"IMP_PRE P P\" unfolding IMP_PRE_def by auto\n\n  definition \"IMP_PRE_CUSTOM \\<equiv> IMP_PRE\"\n  lemma IMP_PRE_CUSTOMD: \"IMP_PRE_CUSTOM P1 P2 \\<Longrightarrow> IMP_PRE P1 P2\" by (simp add: IMP_PRE_CUSTOM_def)\n  lemma IMP_PRE_CUSTOMI: \"\\<lbrakk>\\<And>x. P1 x \\<Longrightarrow> P2 x\\<rbrakk> \\<Longrightarrow> IMP_PRE_CUSTOM P1 P2\" \n    by (simp add: IMP_PRE_CUSTOM_def IMP_PRE_def)\n\n\n  lemma imp_and_triv_pre: \"IMP_PRE P (and_pre (\\<lambda>_. True) P)\"\n    unfolding IMP_PRE_def and_pre_def by auto\n\n\nsubsubsection \\<open>Premises\\<close>    \n  definition \"ALL_LIST A \\<equiv> (\\<forall>x\\<in>set A. x)\"  \n  definition \"IMP_LIST A B \\<equiv> ALL_LIST A \\<longrightarrow> B\"\n\n  lemma to_IMP_LISTI:\n    \"P \\<Longrightarrow> IMP_LIST [] P\" \n    by (auto simp: IMP_LIST_def)\n\n  lemma to_IMP_LIST: \"(P \\<Longrightarrow> IMP_LIST Ps Q) \\<equiv> Trueprop (IMP_LIST (P#Ps) Q)\"\n    by (auto simp: IMP_LIST_def ALL_LIST_def intro!: equal_intr_rule)\n    \n  lemma from_IMP_LIST:\n    \"Trueprop (IMP_LIST As B) \\<equiv> (ALL_LIST As \\<Longrightarrow> B)\"\n    \"(ALL_LIST [] \\<Longrightarrow> B) \\<equiv> Trueprop B\"\n    \"(ALL_LIST (A#As) \\<Longrightarrow> B) \\<equiv> (A \\<Longrightarrow> ALL_LIST As \\<Longrightarrow> B)\"\n    by (auto simp: IMP_LIST_def ALL_LIST_def intro!: equal_intr_rule)\n    \n  lemma IMP_LIST_trivial: \"IMP_LIST A B \\<Longrightarrow> IMP_LIST A B\" .\n\n\n\nsubsubsection \\<open>Composition Rules\\<close>\n  lemma hfcomp_tcomp_pre:\n    assumes B: \"(g,h) \\<in> [Q]\\<^sub>f\\<^sub>d T \\<rightarrow> (\\<lambda>x. \\<langle>U x\\<rangle>nres_rel)\"\n    assumes A: \"(f,g) \\<in> [P]\\<^sub>a\\<^sub>d RR' \\<rightarrow> S\"\n    shows \"(f,h) \\<in> [tcomp_pre Q T P]\\<^sub>a\\<^sub>d hrp_comp RR' T \\<rightarrow> hrr_comp T S U\"\n    using hfcomp[OF A B] by simp\n\n  lemma transform_pre_param:\n    assumes A: \"IMP_LIST Cns ((f, h) \\<in> [tcomp_pre Q T P]\\<^sub>a\\<^sub>d hrp_comp RR' T \\<rightarrow> hrr_comp T S U)\"\n    assumes P: \"IMP_LIST Cns ((P,P') \\<in> T \\<rightarrow> bool_rel)\"\n    assumes C: \"IMP_PRE PP' (and_pre P' Q)\"\n    (*assumes D: \"IMP_LIST Cns (\\<forall>a c x y. (c,a)\\<in>T \\<longrightarrow> S c x y \\<turnstile> S' a x y)\"*)\n    shows \"IMP_LIST Cns ((f,h) \\<in> [PP']\\<^sub>a\\<^sub>d hrp_comp RR' T \\<rightarrow> hrr_comp T S U)\"\n    unfolding from_IMP_LIST\n    apply (rule hfref_cons) \n    apply (rule A[unfolded from_IMP_LIST])\n    apply assumption\n    apply (drule IMP_PRED[OF C])\n    using P[unfolded from_IMP_LIST] unfolding and_pre_def\n    apply (auto dest: fun_relD) []\n    apply simp_all\n    done\n    \n \n  lemma hfref_mop_conv: \"((g,mop P f) \\<in> [Q]\\<^sub>a\\<^sub>d R \\<rightarrow> S) \\<longleftrightarrow> (g,f) \\<in> [\\<lambda>x. P x \\<and> Q x]\\<^sub>a\\<^sub>d R \\<rightarrow> S\"\n    apply (simp add: hfref_to_ASSERT_conv)\n    apply (fo_rule arg_cong fun_cong)+\n    by (auto intro!: ext simp: pw_eq_iff refine_pw_simps)\n  \n  lemma hfref_op_to_mop:\n    assumes R: \"(impl,f) \\<in> [Q]\\<^sub>a\\<^sub>d R \\<rightarrow> S\"\n    assumes DEF: \"mf \\<equiv> mop P f\"\n    assumes C: \"IMP_PRE PP' (imp_pre P Q)\"\n    shows \"(impl,mf) \\<in> [PP']\\<^sub>a\\<^sub>d R \\<rightarrow> S\"\n    unfolding DEF hfref_mop_conv\n    apply (rule hfref_cons[OF R])\n    using C\n    by (auto simp: IMP_PRE_def imp_pre_def)\n  \n  lemma hfref_mop_to_op:\n    assumes R: \"(impl,mf) \\<in> [Q]\\<^sub>a\\<^sub>d R \\<rightarrow> S\"\n    assumes DEF: \"mf \\<equiv> mop P f\"\n    assumes C: \"IMP_PRE PP' (and_pre Q P)\"\n    shows \"(impl,f) \\<in> [PP']\\<^sub>a\\<^sub>d R \\<rightarrow> S\"\n    using R unfolding DEF hfref_mop_conv \n    apply (rule hfref_cons)\n    using C\n    apply (auto simp: and_pre_def IMP_PRE_def)\n    done\n\n  subsubsection \\<open>Precondition Simplification\\<close>\n\n  lemma IMP_PRE_eqI:\n    assumes \"\\<And>x. P x \\<longrightarrow> Q x\"\n    assumes \"CNV P P'\"\n    shows \"IMP_PRE P' Q\"\n    using assms by (auto simp: IMP_PRE_def)\n\n  lemma simp_and1:\n    assumes \"Q \\<Longrightarrow> CNV P P'\"\n    assumes \"PP \\<longrightarrow> P' \\<and> Q\"\n    shows \"PP \\<longrightarrow> P \\<and> Q\"  \n    using assms by auto\n\n  lemma simp_and2:\n    assumes \"P \\<Longrightarrow> CNV Q Q'\"\n    assumes \"PP \\<longrightarrow> P \\<and> Q'\"\n    shows \"PP \\<longrightarrow> P \\<and> Q\"  \n    using assms by auto\n\n  lemma triv_and1: \"Q \\<longrightarrow> True \\<and> Q\" by blast\n\n  lemma simp_imp:\n    assumes \"P \\<Longrightarrow> CNV Q Q'\"\n    assumes \"PP \\<longrightarrow> Q'\"\n    shows \"PP \\<longrightarrow> (P \\<longrightarrow> Q)\"\n    using assms by auto\n\n  lemma CNV_split:\n    assumes \"CNV A A'\"\n    assumes \"CNV B B'\"\n    shows \"CNV (A \\<and> B) (A' \\<and> B')\"  \n    using assms by auto\n\n  lemma CNV_prove:\n    assumes \"P\"  \n    shows \"CNV P True\"\n    using assms by auto\n\n  lemma simp_pre_final_simp:   \n    assumes \"CNV P P'\"\n    shows \"P' \\<longrightarrow> P\"\n    using assms by auto\n\n  lemma auto_weaken_pre_uncurry_step':\n    assumes \"PROTECT f a \\<equiv> f'\"\n    shows \"PROTECT (uncurry f) (a,b) \\<equiv> f' b\" \n    using assms\n    by (auto simp: curry_def dest!: meta_eq_to_obj_eq intro!: eq_reflection)\n\n\nsubsection \\<open>Protected Constants\\<close>\nlemma add_PR_CONST_to_def: \"x\\<equiv>y \\<Longrightarrow> PR_CONST x \\<equiv> y\" by simp\n\nsubsection \\<open>Rule Collections\\<close>\nnamed_theorems_rev sepref_mop_def_thms \\<open>Sepref: mop - definition theorems\\<close>\n\nnamed_theorems_rev sepref_fref_thms \\<open>Sepref: fref-theorems\\<close>\n\nnamed_theorems sepref_relprops_transform \\<open>Sepref: Simp-rules to transform relator properties\\<close>\nnamed_theorems sepref_relprops \\<open>Sepref: Simp-rules to add CONSTRAINT-tags to relator properties\\<close>\nnamed_theorems sepref_relprops_simps \\<open>Sepref: Simp-rules to simplify relator properties\\<close>\n\nsubsubsection \\<open>Default Setup\\<close>\n\n\n\nsubsection \\<open>ML-Level Declarations\\<close>\n\n  ML \\<open>\n    signature SEPREF_INTF_UTIL = sig\n      (* Miscellaneous*)\n      val list_filtered_subterms: (term -> 'a option) -> term -> 'a list\n\n\n      (* Interface types for relations *)\n      val get_intf_of_rel: Proof.context -> term -> typ\n\n      (* Constraints *)\n      (* Convert relations to pure assertions *)\n      val to_assns_rl: bool -> Proof.context -> thm -> thm\n      (* Recognize, summarize and simplify CONSTRAINT - premises *)\n      val cleanup_constraints: Proof.context -> thm -> thm\n\n      (* Preconditions *)\n      (* Simplify precondition. Goal must be in IMP_PRE or IMP_PRE_CUSTOM form. *)\n      val simp_precond_tac: Proof.context -> tactic'\n\n\n      (* Configuration options *)\n      val cfg_def: bool Config.T       (* decl_op: Define constant *)\n      val cfg_ismop: bool Config.T     (* decl_op: Specified term is mop *)\n      val cfg_mop: bool Config.T       (* decl_op, decl_impl: Derive mop *) \n      val cfg_rawgoals: bool Config.T  (* decl_op, decl_impl: Do not pre-process/solve goals *)\n\n\n      (* TODO: Make do_cmd usable from ML-level! *)\n\n    end\n\n    structure Sepref_Intf_Util: SEPREF_INTF_UTIL = struct\n  \n      val cfg_debug = \n        Attrib.setup_config_bool @{binding sepref_debug_intf_util} (K false)\n      \n      val dbg_trace = Sepref_Debugging.dbg_trace_msg cfg_debug  \n      val dbg_msg_tac = Sepref_Debugging.dbg_msg_tac cfg_debug  \n      fun dbg_trace_thm ctxt msg thm = \n        Sepref_Debugging.dbg_trace cfg_debug ctxt (fn ctxt => \n          Pretty.block [Pretty.str msg, Pretty.brk 1, Thm.pretty_thm ctxt thm] |> Pretty.string_of)\n      fun dbg_trace_term ctxt msg t = \n        Sepref_Debugging.dbg_trace cfg_debug ctxt (fn ctxt => \n          Pretty.block [Pretty.str msg, Pretty.brk 1, Syntax.pretty_term ctxt t] |> Pretty.string_of)\n\n      fun list_filtered_subterms f t = let\n        fun r t = case f t of \n          SOME a => [a]\n        | NONE => (\n            case t of \n              t1$t2 => r t1 @ r t2\n            | Abs (_,_,t) => r t\n            | _ => []\n          )\n      in\n        r t\n      end\n  \n      fun get_intf_of_rel ctxt R = \n        Term_Synth.synth_term @{thms synth_intf_of_relI} ctxt R\n          |> fastype_of \n          |> Refine_Util.dest_itselfT\n  \n      local\n        fun add_is_pure_constraint ctxt v thm = let\n          val v = Thm.cterm_of ctxt v\n          val rl = Drule.infer_instantiate' ctxt [NONE, SOME v] @{thm add_is_pure_constraint}\n        in\n          thm RS rl\n        end\n      in  \n        fun to_assns_rl add_pure_constr ctxt thm = let\n          val orig_ctxt = ctxt\n      \n          val (thm,ctxt) = yield_singleton (apfst snd oo Variable.importT) thm ctxt\n      \n          val (R,S) = case Thm.concl_of thm of @{mpat \"Trueprop (_\\<in>fref _ ?R ?S)\"} => (R,S)\n            | _ => raise THM(\"to_assns_rl: expected fref-thm\",~1,[thm])\n      \n          fun mk_cn_subst (fname,(iname,C,A)) = \n            let\n              val T' = A --> C --> @{typ assn}\n              val v' = Free (fname,T')\n              val ct' = @{mk_term \"the_pure ?v'\"} |> Thm.cterm_of ctxt\n            in\n              (v',(iname,ct'))\n            end\n      \n          fun relation_flt (name,Type (@{type_name set},[Type (@{type_name prod},[C,A])])) = SOME (name,C,A)\n            | relation_flt _ = NONE  \n      \n            \n          val vars = []\n            |> Term.add_vars R \n            |> Term.add_vars S\n            |> map_filter (relation_flt) \n          val (names,ctxt) = Variable.variant_fixes (map (#1 #> fst) vars) ctxt\n          \n          val cn_substs = map mk_cn_subst (names ~~ vars)\n      \n      \n          val thm = Drule.infer_instantiate ctxt (map snd cn_substs) thm\n      \n          val thm = thm |> add_pure_constr ? fold (fn (v,_) => fn thm => add_is_pure_constraint ctxt v thm) cn_substs\n      \n          val thm = singleton (Variable.export ctxt orig_ctxt) thm\n        in\n          thm\n        end\n      \n        fun cleanup_constraints ctxt thm = let\n          val orig_ctxt = ctxt\n      \n          val (thm, ctxt) = yield_singleton (apfst snd oo Variable.import true) thm ctxt\n      \n          val xform_thms = Named_Theorems.get ctxt @{named_theorems sepref_relprops_transform}\n          val rprops_thms = Named_Theorems.get ctxt @{named_theorems sepref_relprops}\n          val simp_thms = Named_Theorems.get ctxt @{named_theorems sepref_relprops_simps}\n      \n          fun simp thms = Conv.fconv_rule (\n                  Simplifier.asm_full_rewrite \n                    (put_simpset HOL_basic_ss ctxt addsimps thms))\n      \n          (* Check for pure (the_pure R) - patterns *)\n      \n          local\n            val (_,R,S) = case Thm.concl_of thm of\n              @{mpat \"Trueprop (_\\<in>hfref ?P ?R ?S)\"} => (P,R,S)\n            | @{mpat \"Trueprop (_\\<in>fref ?P ?R ?S)\"} => (P,R,S)\n            | _ => raise THM(\"cleanup_constraints: Expected hfref or fref-theorem\",~1,[thm])  \n      \n      \n            fun flt_pat @{mpat \"pure (the_pure ?A)\"} = SOME A | flt_pat _ = NONE\n      \n            val purify_terms = \n              (list_filtered_subterms flt_pat R @ list_filtered_subterms flt_pat S)\n              |> distinct op aconv\n       \n            val thm = fold (add_is_pure_constraint ctxt) purify_terms thm\n          in\n            val thm = thm\n          end\n      \n          val thm = thm\n            |> Local_Defs.unfold0 ctxt xform_thms\n            |> Local_Defs.unfold0 ctxt rprops_thms\n      \n          val insts = map (fn \n              @{mpat \"Trueprop (CONSTRAINT _ (the_pure _))\"} => @{thm handle_purity1}\n            | _ => asm_rl  \n            ) (Thm.prems_of thm)  \n      \n          val thm = (thm OF insts)\n            |> Conv.fconv_rule Thm.eta_conversion\n            |> simp @{thms handle_purity2}\n            |> simp simp_thms\n      \n          val thm = singleton (Variable.export ctxt orig_ctxt) thm  \n      \n        in\n          thm\n        end\n      end  \n  \n      fun simp_precond_tac ctxt = let\n        fun simp_only thms = asm_full_simp_tac (put_simpset HOL_basic_ss ctxt addsimps thms)\n        val rtac = resolve_tac ctxt\n    \n        val cnv_ss = ctxt delsimps @{thms CNV_def}\n    \n        (*val uncurry_tac = SELECT_GOAL (ALLGOALS (DETERM o SOLVED' (\n          REPEAT' (rtac @{thms auto_weaken_pre_uncurry_step'}) \n          THEN' rtac @{thms auto_weaken_pre_uncurry_finish}\n        )))*)\n    \n        val prove_cnv_tac = SOLVED' (rtac @{thms CNV_prove} THEN' SELECT_GOAL (auto_tac ctxt))\n    \n        val do_cnv_tac = \n          (cp_clarsimp_tac cnv_ss) THEN_ALL_NEW\n          (TRY o REPEAT_ALL_NEW (match_tac ctxt @{thms CNV_split}))\n          THEN_ALL_NEW (prove_cnv_tac ORELSE' rtac @{thms CNV_I})\n    \n        val final_simp_tac = \n          rtac @{thms simp_pre_final_simp} \n          THEN' cp_clarsimp_tac cnv_ss\n          THEN' dbg_msg_tac (Sepref_Debugging.msg_subgoal \"final_simp_tac: Before CNV_I\") ctxt\n          THEN' rtac @{thms CNV_I}\n          THEN' dbg_msg_tac (Sepref_Debugging.msg_text \"Final-Simp done\") ctxt\n    \n        (*val curry_tac = let open Conv in\n          CONVERSION (Refine_Util.HOL_concl_conv (fn ctxt => arg1_conv (\n            top_conv ( fn _ => try_conv (rewr_conv @{thm uncurry_def})) ctxt)) ctxt)\n          THEN' REPEAT' (EqSubst.eqsubst_tac ctxt [1] @{thms case_prod_eta})\n          THEN' rtac @{thms CNV_I}\n          end*)\n\n        val simp_tupled_pre_tac = \n          SELECT_GOAL (Local_Defs.unfold0_tac ctxt @{thms prod_casesK uncurry0_hfref_post})\n          THEN' REPEAT' (EqSubst.eqsubst_tac ctxt [1] @{thms case_prod_eta})\n          THEN' rtac @{thms CNV_I}\n\n        val unfold_and_tac = rtac @{thms and_pre_beta} THEN_ALL_NEW simp_only @{thms split}\n    \n        val simp_and1_tac =  \n          rtac @{thms simp_and1} THEN' do_cnv_tac\n    \n        val simp_and2_tac =  \n          rtac @{thms simp_and2} THEN' do_cnv_tac\n    \n        val and_plan_tac =   \n          simp_and1_tac \n          THEN' dbg_msg_tac (Sepref_Debugging.msg_subgoal \"State after and1\") ctxt\n          THEN' (\n            rtac @{thms triv_and1}\n            ORELSE' \n            dbg_msg_tac (Sepref_Debugging.msg_subgoal \"Invoking and2 on\") ctxt\n            THEN' simp_and2_tac \n            THEN' dbg_msg_tac (Sepref_Debugging.msg_subgoal \"State before final_simp_tac\") ctxt\n            THEN' final_simp_tac\n          )\n    \n        val unfold_imp_tac = rtac @{thms imp_pre_beta} THEN_ALL_NEW simp_only @{thms split}\n        val simp_imp1_tac =  \n          rtac @{thms simp_imp} THEN' do_cnv_tac\n    \n        val imp_plan_tac = simp_imp1_tac THEN' final_simp_tac \n    \n        val imp_pre_tac = APPLY_LIST [\n            simp_only @{thms split_tupled_all}\n            THEN' Refine_Util.instantiate_tuples_subgoal_tac ctxt\n            THEN' CASES' [\n              (unfold_and_tac, ALLGOALS and_plan_tac),\n              (unfold_imp_tac, ALLGOALS imp_plan_tac)\n            ]\n          ,\n            simp_tupled_pre_tac\n          ]  \n    \n        val imp_pre_custom_tac = \n          SELECT_GOAL (Local_Defs.unfold0_tac ctxt @{thms and_pre_def}) THEN'\n          TRY o SOLVED' (SELECT_GOAL (auto_tac ctxt))\n    \n      in\n        CASES' [\n          (rtac @{thms IMP_PRE_eqI}, imp_pre_tac 1),\n          (rtac @{thms IMP_PRE_CUSTOMI}, ALLGOALS imp_pre_custom_tac)\n        ]\n      end\n\n\n\n\n      local\n        fun inf_bn_aux name = \n          case String.tokens (fn c => c = #\".\") name of\n            [] => NONE\n          | l => rev l |> hd |> Binding.name |> SOME\n      in\n        fun infer_basename (Const (\"_type_constraint_\",_)$t) = infer_basename t\n          | infer_basename (Const (name,_)) = inf_bn_aux name\n          | infer_basename (Free (name,_)) = inf_bn_aux name\n          | infer_basename _ = NONE\n      end    \n  \n      val cfg_mop = Attrib.setup_config_bool @{binding sepref_register_mop} (K true)\n      val cfg_ismop = Attrib.setup_config_bool @{binding sepref_register_ismop} (K false)\n      val cfg_rawgoals = Attrib.setup_config_bool @{binding sepref_register_rawgoals} (K false)\n      val cfg_transfer = Attrib.setup_config_bool @{binding sepref_decl_impl_transfer} (K true)\n      val cfg_def = Attrib.setup_config_bool @{binding sepref_register_def} (K true)\n      val cfg_register = Attrib.setup_config_bool @{binding sepref_decl_impl_register} (K true)\n  \n      local \n        open Refine_Util\n        val flags = \n             parse_bool_config' \"mop\" cfg_mop\n          || parse_bool_config' \"ismop\" cfg_ismop\n          || parse_bool_config' \"rawgoals\" cfg_rawgoals\n          || parse_bool_config' \"def\" cfg_def\n        val parse_flags = parse_paren_list' flags  \n\n        val parse_name = Scan.option (Parse.binding --| @{keyword \":\"})\n        val parse_relconds = Scan.optional (@{keyword \"where\"} |-- Parse.and_list1 (Scan.repeat1 Parse.prop) >> flat) []\n      in\n\n        val do_parser = parse_flags -- parse_name -- Parse.term --| @{keyword \"::\"} -- Parse.term -- parse_relconds\n      end  \n  \n  \n      fun do_cmd ((((flags,name),opt_raw), relt_raw),relconds_raw) lthy = let\n        local\n          val ctxt = Refine_Util.apply_configs flags lthy\n        in\n          val flag_ismop = Config.get ctxt cfg_ismop\n          val flag_mop = Config.get ctxt cfg_mop andalso not flag_ismop\n          val flag_rawgoals = Config.get ctxt cfg_rawgoals\n          val flag_def = Config.get ctxt cfg_def\n        end\n  \n        open Sepref_Basic Sepref_Rules\n\n        val relt = Syntax.parse_term lthy relt_raw\n        val relconds = map (Syntax.parse_prop lthy) relconds_raw \n\n        val _ = dbg_trace lthy \"Parse relation and relation conditions together\"\n        val relt = Const (@{const_name \"Pure.term\"}, dummyT) $ relt\n        local\n          val l = Syntax.check_props lthy (relt::relconds)\n        in\n          val (relt, relconds) = (hd l, tl l) \n        end\n        val relt = Logic.dest_term relt\n\n        val opt_pre = Syntax.parse_term lthy opt_raw\n  \n\n        val _ = dbg_trace lthy \"Infer basename\"\n        val name = case name of \n          SOME name => name\n        | NONE => (\n            case infer_basename opt_pre of \n              NONE => (error \"Could not infer basename: You have to specify a basename\"; Binding.empty)\n            | SOME name => name\n          )\n          \n  \n        fun qname s n = Binding.qualify true (Binding.name_of n) (Binding.name s)\n        fun def name t_pre attribs lthy = let\n          val t = Syntax.check_term lthy t_pre\n            (*|> Thm.cterm_of lthy\n            |> Drule.mk_term\n            |> Local_Defs.unfold0 lthy @{thms PR_CONST_def}\n            |> Drule.dest_term\n            |> Thm.term_of*)\n  \n          val (_,lthy) = Local_Theory.begin_nested lthy \n          val ((dt,(_,thm)),lthy) = Local_Theory.define \n            ((name,Mixfix.NoSyn),((Thm.def_binding name,@{attributes [code]}@attribs),t)) lthy;\n          val (lthy, lthy_old) = `Local_Theory.end_nested lthy\n          val phi = Proof_Context.export_morphism lthy_old lthy\n          val thm = Morphism.thm phi thm\n          val dt = Morphism.term phi dt\n  \n        in\n          ((dt,thm),lthy)\n        end\n  \n        val _ = dbg_trace lthy \"Analyze Relation\"\n        val (pre,args,res) = analyze_rel relt\n        val specified_pre = is_some pre\n        val pre = the_default (mk_triv_precond args) pre\n  \n        val def_thms = @{thms PR_CONST_def}\n  \n        val _ = dbg_trace lthy \"Define op\"\n        val op_name = Binding.prefix_name (if flag_ismop then \"mop_\" else \"op_\") name\n        val (def_thms,opc,lthy) = \n          if flag_def then let\n              val ((opc,op_def_thm),lthy) = def op_name opt_pre @{attributes [simp]} lthy\n              val opc = Refine_Util.dummify_tvars opc\n              val def_thms = op_def_thm::def_thms\n            in\n              (def_thms,opc,lthy)\n            end\n          else let\n              val _ = dbg_trace lthy \"Refine type of opt_pre to get opc\"\n              val opc = Syntax.check_term lthy opt_pre\n              val new_ctxt = Variable.declare_term opc lthy\n              val opc = singleton (Variable.export_terms new_ctxt lthy) opc\n                |> Refine_Util.dummify_tvars\n            in \n              (def_thms,opc,lthy)\n            end\n  \n            \n        (* PR_CONST Heuristics *)    \n        fun pr_const_heuristics basename c_pre lthy = let\n          val _ = dbg_trace lthy (\"PR_CONST heuristics \" ^ @{make_string} c_pre)\n\n          val c = Syntax.check_term lthy c_pre\n        in\n          case c of\n            @{mpat \"PR_CONST _\"} => ((c_pre,false),lthy)\n          | Const _ => ((c_pre,false),lthy)\n          | _ => let\n              val (f,args) = strip_comb c\n  \n              val lthy = case f of Const _ => let\n                  val ctxt = Variable.declare_term c lthy\n                  val lhs = Autoref_Tagging.list_APP (f,args)\n                  val rhs = @{mk_term \"UNPROTECT ?c\"}\n                  val goal = Logic.mk_equals (lhs,rhs) |> Thm.cterm_of ctxt\n                  val tac = \n                    Local_Defs.unfold0_tac ctxt @{thms APP_def UNPROTECT_def}\n                    THEN ALLGOALS (simp_tac (put_simpset HOL_basic_ss ctxt))\n                  val thm = Goal.prove_internal ctxt [] goal (K tac)\n                    |> singleton (Variable.export ctxt lthy)\n  \n                  val (_,lthy) = Local_Theory.note \n                    ((Binding.suffix_name \"_def_pat\" basename,@{attributes [def_pat_rules]}),[thm]) lthy\n  \n                  val _ = Thm.pretty_thm lthy thm |> Pretty.string_of |> writeln\n                in\n                  lthy\n                end\n              | _ => (\n                Pretty.block [\n                  Pretty.str \"Complex operation pattern. Added PR_CONST but no pattern rules:\",\n                  Pretty.brk 1,Syntax.pretty_term lthy c]\n                |> Pretty.string_of |> warning  \n                ; lthy)\n  \n              val c_pre = Const(@{const_name PR_CONST},dummyT)$c_pre\n            in\n              ((c_pre,true),lthy)\n            end\n        end  \n\n        val ((opc,_),lthy) = pr_const_heuristics op_name opc lthy\n\n        (* Register *)\n        val arg_intfs = map (get_intf_of_rel lthy) args\n        val res_intf = get_intf_of_rel lthy res\n  \n\n        fun register basename c lthy = let\n          val _ = dbg_trace lthy \"Register\"\n          open Sepref_Basic\n          val c = Syntax.check_term lthy c\n  \n          val ri = case (is_nresT (body_type (fastype_of c)), is_nresT res_intf) of\n            (true,false) => mk_nresT res_intf\n          | (false,true) => dest_nresT res_intf\n          | _ => res_intf\n  \n          val iT = arg_intfs ---> ri\n  \n          val ((_,itype_thm),lthy) = Sepref_Combinator_Setup.sepref_register_single (Binding.name_of basename) c iT lthy\n          val _ = Thy_Output.pretty_thm lthy itype_thm |> Pretty.string_of |> writeln\n  \n        in\n          lthy\n        end\n  \n        val lthy = register op_name opc lthy\n  \n        val _ = dbg_trace lthy \"Define pre\"\n        val pre_name = Binding.prefix_name \"pre_\" name\n        val ((prec,pre_def_thm),lthy) = def pre_name pre @{attributes [simp]} lthy\n        val prec = Refine_Util.dummify_tvars prec\n        val def_thms = pre_def_thm::def_thms\n  \n        (* Re-integrate pre-constant into type-context of relation. TODO: This is probably not clean/robust *)\n        val pre = constrain_type_pre (fastype_of pre) prec |> Syntax.check_term lthy\n\n  \n        val _ = dbg_trace lthy \"Convert both, relation and operation to uncurried form, and add nres\"\n        val _ = dbg_trace lthy \"Convert relation (arguments have already been separated by analyze-rel)\"\n        val res = case res of \n          @{mpat \"\\<lambda>_. \\<langle>_\\<rangle>nres_rel\"} => res\n        | _ => @{mk_term \"\\<lambda>x. \\<langle>?res x\\<rangle>nres_rel\"}\n        val relt = mk_rel (SOME pre,args,res)\n        \n        val _ = dbg_trace_term lthy \"Converted relation\" relt\n        val _ = Syntax.check_term lthy relt\n          |> dbg_trace_term lthy \"Converted relation (checked)\"\n  \n        val _ = dbg_trace lthy \"Convert operation\"\n        val opcT = fastype_of (Syntax.check_term lthy opc)\n        val op_is_nres = Sepref_Basic.is_nresT (body_type opcT)\n        val (opcu, op_ar) = let\n          val arity = binder_types #> length\n          (* Arity of operation is number of arguments before result (which may be a fun-type! )*)\n          val rel_absT = fastype_of #> body_type #> HOLogic.dest_setT #> HOLogic.dest_prodT #> snd (* TODO: Generalization of with Realtors.rel_absT. Maybe move? *)\n          val res_ar = arity (rel_absT res |> not op_is_nres ? dest_nresT)\n\n          val op_ar = arity opcT - res_ar\n          \n          val _ = op_ar = length args orelse \n            raise TERM(\"Operation/relation arity mismatch: \" ^ string_of_int op_ar ^ \" vs \" ^ string_of_int (length args),[opc,relt])\n  \n          (* Add RETURN o...o if necessary*)\n          val opc = \n            if op_is_nres then opc\n            else mk_compN_pre op_ar (Const(@{const_name Refine_Basic.RETURN},dummyT)) opc\n  \n          (* Add uncurry if necessary *)  \n          val opc = mk_uncurryN_pre op_ar opc\n        in \n          (opc, op_ar)\n        end\n  \n        (* Build mop-variant *)\n        val declare_mop = (specified_pre orelse not op_is_nres) andalso flag_mop\n  \n        val (mop_data,lthy) = if declare_mop then let\n            val _ = dbg_trace lthy \"mop definition\"\n            val mop_rhs = Const(@{const_name mop},dummyT) $ prec $ opcu\n              |> mk_curryN_pre op_ar\n            val mop_name = Binding.prefix_name \"mop_\" name\n            val ((mopc,mop_def_thm),lthy) = def mop_name mop_rhs [] lthy\n            val mopc = Refine_Util.dummify_tvars mopc\n  \n            val ((mopc,added_pr_const),lthy) = pr_const_heuristics mop_name mopc lthy\n\n            val mop_def_thm' = if added_pr_const then \n                mop_def_thm RS @{thm add_PR_CONST_to_def}\n              else mop_def_thm\n\n            val (_,lthy) = Local_Theory.note ((Binding.empty, @{attributes [sepref_mop_def_thms]}),[mop_def_thm']) lthy\n\n            val _ = dbg_trace lthy \"mop alternative definition\"\n            val alt_unfolds = @{thms mop_alt_unfolds}\n              |> not specified_pre ? curry op :: pre_def_thm\n\n            val mop_alt_thm = Local_Defs.unfold0 lthy alt_unfolds mop_def_thm\n              |> Refine_Util.shift_lambda_leftN op_ar\n            val (_,lthy) = Local_Theory.note ((Binding.suffix_name \"_alt\" mop_name,@{attributes [simp]}),[mop_alt_thm]) lthy\n  \n            val _ = dbg_trace lthy \"mop: register\"\n            val lthy = register mop_name mopc lthy\n  \n            val _ = dbg_trace lthy \"mop: vcg theorem\"\n            local\n              val Ts = map Relators.rel_absT args\n              val ctxt = Variable.declare_thm mop_def_thm lthy\n              val ctxt = fold Variable.declare_typ Ts ctxt\n              val (x,ctxt) = Refine_Util.fix_left_tuple_from_Ts \"x\" Ts ctxt\n              \n              val mop_def_thm = mop_def_thm\n                |> Local_Defs.unfold0 ctxt @{thms curry_shl}\n              \n              fun prep_thm thm = (thm OF [mop_def_thm])\n                |> Drule.infer_instantiate' ctxt [SOME (Thm.cterm_of ctxt x)]\n                |> Local_Defs.unfold0 ctxt @{thms uncurry_apply uncurry0_apply o_apply}\n                |> Local_Defs.unfold0 ctxt (def_thms @\n                    @{thms Product_Type.split HOL.True_implies_equals})\n                |> singleton (Variable.export ctxt lthy)\n\n              val thms = map prep_thm @{thms mop_spec_rl_from_def mop_leof_rl_from_def}  \n\n            in\n              val (_,lthy) = Local_Theory.note ((qname \"vcg\" mop_name,@{attributes [refine_vcg]}),thms) lthy\n            end\n  \n          in \n            (SOME (mop_name,mopc,mop_def_thm),lthy)\n          end\n        else (NONE,lthy)\n  \n  \n        val _ = dbg_trace lthy \"Build Parametricity Theorem\"\n        val param_t = mk_pair_in_pre opcu opcu relt \n        \n        val _ = dbg_trace_term lthy \"Param Term\" param_t\n        \n        val param_t = param_t |> Syntax.check_term lthy \n          |> HOLogic.mk_Trueprop\n          |> curry Logic.list_implies relconds\n        \n        val _ = dbg_trace lthy \"Build Parametricity Theorem for Precondition\"\n        val param_pre_t = \n          let\n            val pre_relt = Relators.mk_fun_rel (Relators.list_prodrel_left args) @{term bool_rel}\n  \n            val param_pre_t = mk_pair_in_pre prec prec pre_relt \n              |> Syntax.check_term lthy\n              |> HOLogic.mk_Trueprop\n              |> curry Logic.list_implies relconds\n          in\n            param_pre_t\n          end\n        \n        \n        val _ = dbg_trace lthy \"Build goals\"\n        val goals = [[ (param_t, []), (param_pre_t, []) ]]\n  \n        fun after_qed [[p_thm, pp_thm]] _ (*ctxt*) = \n          let\n            val _ = dbg_trace lthy \"after_qed\"\n            val p_thm' = p_thm |> not specified_pre ? Local_Defs.unfold0 lthy [pre_def_thm]\n\n            val (_,lthy) = Local_Theory.note ((qname \"fref\" op_name,@{attributes [sepref_fref_thms]}), [p_thm']) lthy\n            val (_,lthy) = Local_Theory.note ((qname \"param\" pre_name,@{attributes [param]}), [pp_thm]) lthy\n\n            val p'_unfolds = pre_def_thm :: @{thms True_implies_equals}\n            val (_,lthy) = Local_Theory.note ((qname \"fref'\" op_name,[]), [Local_Defs.unfold0 lthy p'_unfolds p_thm]) lthy\n\n  \n            val lthy = case mop_data of NONE => lthy | \n              SOME (mop_name,mopc,mop_def_thm) => let\n                val _ = dbg_trace lthy \"Build and prove mop-stuff\"\n                (* mop - parametricity theorem: (uncurry\\<^sup>n mopc,uncurry\\<^sup>n mopc) \\<in> args \\<rightarrow>\\<^sub>f res *)\n                val mopcu = mk_uncurryN_pre op_ar mopc\n                val param_mop_t = mk_pair_in_pre mopcu mopcu (mk_rel (NONE,args,res))\n                  |> Syntax.check_term lthy\n                  |> HOLogic.mk_Trueprop\n                  |> curry Logic.list_implies relconds\n  \n                val ctxt = Proof_Context.augment param_mop_t lthy \n                \n                val tac = let\n                  val p_thm = Local_Defs.unfold0 ctxt @{thms PR_CONST_def} p_thm\n                in\n                  Local_Defs.unfold0_tac ctxt (mop_def_thm :: @{thms PR_CONST_def uncurry_curry_id uncurry_curry0_id})\n                  THEN FIRSTGOAL (\n                    dbg_msg_tac (Sepref_Debugging.msg_subgoal \"Mop-param thm goal after unfolding\") ctxt THEN'\n                    resolve_tac ctxt @{thms param_mopI}\n                      THEN' SOLVED' (resolve_tac ctxt [p_thm] THEN_ALL_NEW assume_tac ctxt)\n                      THEN' SOLVED' (resolve_tac ctxt [pp_thm] THEN_ALL_NEW assume_tac ctxt)\n                  )\n                end\n  \n                val pm_thm = Goal.prove_internal lthy [] (Thm.cterm_of ctxt param_mop_t) (K tac)\n                  |> singleton (Variable.export ctxt lthy)\n  \n                val (_,lthy) = Local_Theory.note ((qname \"fref\" mop_name,@{attributes [sepref_fref_thms]}), [pm_thm]) lthy\n                val (_,lthy) = Local_Theory.note ((qname \"fref'\" mop_name,[]), [Local_Defs.unfold0 lthy p'_unfolds pm_thm]) lthy\n  \n  \n              in\n                lthy\n              end\n  \n  \n          in\n            lthy\n          end\n          | after_qed thmss _ = raise THM (\"After-qed: Wrong thmss structure\",~1,flat thmss)    \n          \n        fun std_tac ctxt = let\n          val ptac = REPEAT_ALL_NEW_FWD (Parametricity.net_tac (Parametricity.get_dflt ctxt) ctxt)\n  \n          (* Massage simpset a bit *)\n          val ctxt = ctxt\n            |> Context_Position.set_visible false\n            |> Context.proof_map (Thm.attribute_declaration Clasimp.iff_del @{thm pair_in_Id_conv})\n\n        in\n          if flag_rawgoals then\n            all_tac\n          else\n            Local_Defs.unfold0_tac ctxt def_thms THEN ALLGOALS (\n              TRY o SOLVED' (\n                TRY o resolve_tac ctxt @{thms frefI}\n                THEN' TRY o REPEAT_ALL_NEW (ematch_tac ctxt @{thms prod_relE})\n                THEN' simp_tac (put_simpset HOL_basic_ss ctxt addsimps @{thms split uncurry_apply uncurry0_apply})\n                THEN' (\n                  SOLVED' (ptac THEN_ALL_NEW asm_full_simp_tac ctxt)\n                  ORELSE' SOLVED' (cp_clarsimp_tac ctxt THEN_ALL_NEW_FWD ptac THEN_ALL_NEW SELECT_GOAL (auto_tac ctxt))\n                )\n              )\n            )\n  \n        end  \n  \n        val rf_std = Proof.refine (Method.Basic (fn ctxt => SIMPLE_METHOD (std_tac ctxt)))\n          #> Seq.the_result \"do_cmd: Standard proof tactic returned empty result sequence\"\n\n      in\n        Proof.theorem NONE after_qed goals lthy\n        |> rf_std\n      end\n\n      val _ = Outer_Syntax.local_theory_to_proof @{command_keyword \"sepref_decl_op\"}\n        \"\" (do_parser >> do_cmd)\n  \n\n\n\n      local\n      \n        fun unfold_PR_CONST_tac ctxt = SELECT_GOAL (Local_Defs.unfold0_tac ctxt @{thms PR_CONST_def})\n\n        fun transfer_precond_rl fixedTs ctxt t R = let\n          (*val tfrees = Term.add_tfreesT (fastype_of t) [] \n          val t' = map_types (map_type_tfree (fn x => if member op= tfrees x then dummyT else TFree x)) t\n          *) (* TODO: Brute force approach, that may generalize too much! *)\n\n          (* Subtypes that contain fixed TFrees are mapped structurally, preserving the fixed types, \n              all other types just become dummyT *)          \n              \n          fun mapT (T as TFree (n,_)) = if member op = fixedTs n then (T, true) else (dummyT, false)\n            | mapT (Type (name,Ts)) = let \n                val Ts = map mapT Ts \n              in \n                if exists I (map snd Ts) then (Type (name,map fst Ts),true) else (dummyT,false) \n              end\n            | mapT (TVar _) = (dummyT,false)\n              \n              \n          (*fun is_declared_TFree (TFree (n,_)) = Variable.is_declared ctxt n\n            | is_declared_TFree _ = false\n          fun mpaT T = if is_declared_TFree T then T else dummyT\n          fun mpT T = if exists_subtype is_declared_TFree T then map_atyps mpaT T else dummyT\n          *)\n          val t' = map_types (fst o mapT) t\n        \n          val goal = Sepref_Basic.mk_pair_in_pre t t' R \n            |> tap (dbg_trace_term ctxt \"Precond transfer term before checking\")\n            |> Syntax.check_term ctxt\n            |> Thm.cterm_of ctxt\n                                    \n          val thm = Drule.infer_instantiate' ctxt [NONE,SOME goal] @{thm IMP_LIST_trivial}\n\n        in\n          thm\n        end\n      \n      \n        (* Generate a hnr-thm for mop given one for op *)\n        fun generate_mop_thm ctxt op_thm = let\n          val orig_ctxt = ctxt\n      \n          val (op_thm, ctxt) = yield_singleton (apfst snd oo Variable.import true) op_thm ctxt\n      \n          (* Convert mop_def_thms to form uncurry^n f \\<equiv> mop P g *)\n          val mop_def_thms = Named_Theorems_Rev.get ctxt @{named_theorems_rev sepref_mop_def_thms}\n            |> map (Local_Defs.unfold0 ctxt @{thms curry_shl})\n      \n          fun fail_hnr_tac _ _ = raise THM(\"Invalid hnr-theorem\",~1,[op_thm]) \n          fun fail_mop_def_tac i st = let\n            val g = nth (Thm.prems_of st) (i-1)\n          in\n            raise TERM(\"Found no matching mop-definition\",[g])\n          end\n      \n          (* Tactic to solve preconditions of hfref_op_to_mop *)\n          val tac = APPLY_LIST [\n            resolve_tac ctxt [op_thm] ORELSE' fail_hnr_tac,\n            ((*unfold_PR_CONST_tac ctxt THEN'*) resolve_tac ctxt mop_def_thms) ORELSE' fail_mop_def_tac,\n            simp_precond_tac ctxt ORELSE' Sepref_Debugging.error_tac' \"precond simplification failed\" ctxt\n          ] 1\n      \n          (* Do synthesis *)\n          val st = @{thm hfref_op_to_mop}\n          val st = Goal.protect (Thm.nprems_of st) st\n          val mop_thm = tac st |> Seq.hd |> Goal.conclude\n      \n          val mop_thm = singleton (Variable.export ctxt orig_ctxt) mop_thm\n            |> Sepref_Rules.norm_fcomp_rule orig_ctxt\n        in mop_thm end  \n      \n        (* Generate a hnr-thm for op given one for mop *)\n        fun generate_op_thm ctxt mop_thm = let (* TODO: Almost-clone of generate_mop_thm *)\n          val orig_ctxt = ctxt\n      \n          val (mop_thm, ctxt) = yield_singleton (apfst snd oo Variable.import true) mop_thm ctxt\n      \n          (* Convert mop_def_thms to form uncurry^n f \\<equiv> mop P g *)\n          val mop_def_thms = Named_Theorems_Rev.get ctxt @{named_theorems_rev sepref_mop_def_thms}\n            |> map (Local_Defs.unfold0 ctxt @{thms curry_shl})\n      \n          fun fail_hnr_tac _ _ = raise THM(\"Invalid hnr-theorem\",~1,[mop_thm]) \n          fun fail_mop_def_tac i st = let\n            val g = nth (Thm.prems_of st) (i-1)\n          in\n            raise TERM(\"Found no matching mop-definition\",[g])\n          end\n      \n          (* Tactic to solve preconditions of hfref_mop_to_op *)\n          val tac = APPLY_LIST [\n            resolve_tac ctxt [mop_thm] ORELSE' fail_hnr_tac,\n            ((*unfold_PR_CONST_tac ctxt THEN'*) resolve_tac ctxt mop_def_thms) ORELSE' fail_mop_def_tac,\n            simp_precond_tac ctxt ORELSE' Sepref_Debugging.error_tac' \"precond simplification failed\" ctxt\n          ] 1\n      \n          (* Do synthesis *)\n          val st = @{thm hfref_mop_to_op}\n          val st = Goal.protect (Thm.nprems_of st) st\n          val op_thm = tac st |> Seq.hd |> Goal.conclude\n      \n          val op_thm = singleton (Variable.export ctxt orig_ctxt) op_thm\n            |> Sepref_Rules.norm_fcomp_rule orig_ctxt\n        in op_thm end  \n\n\n      \n        fun chk_result ctxt thm = let\n          val (_,R,S) = case Thm.concl_of thm of\n            @{mpat \"Trueprop (_\\<in>hfref ?P ?R ?S)\"} => (P,R,S)\n          | _ => raise THM(\"chk_result: Expected hfref-theorem\",~1,[thm])  \n      \n          fun err t = let\n            val ts = Syntax.pretty_term ctxt t |> Pretty.string_of\n          in\n            raise THM (\"chk_result: Invalid pattern left in assertions: \" ^ ts,~1,[thm])\n          end  \n          fun check_invalid (t as @{mpat \"hr_comp _ _\"}) = err t \n            | check_invalid (t as @{mpat \"hrp_comp _ _\"}) = err t\n            | check_invalid (t as @{mpat \"hrr_comp _ _ _\"}) = err t\n            | check_invalid (t as @{mpat \"pure (the_pure _)\"}) = err t\n            | check_invalid (t as @{mpat \"_ O _\"}) = err t\n            | check_invalid _ = false\n            \n      \n          val _ = exists_subterm check_invalid R \n          val _ = exists_subterm check_invalid S\n        in\n          ()\n        end\n\n        fun to_IMP_LIST ctxt thm =    \n          (thm RS @{thm to_IMP_LISTI}) |> Local_Defs.unfold0 ctxt @{thms to_IMP_LIST}\n  \n        fun from_IMP_LIST ctxt thm = thm |> Local_Defs.unfold0 ctxt @{thms from_IMP_LIST}  \n\n      in\n    \n        local\n          open Refine_Util\n          val flags = \n               parse_bool_config' \"mop\" cfg_mop\n            || parse_bool_config' \"ismop\" cfg_ismop\n            || parse_bool_config' \"transfer\" cfg_transfer\n            || parse_bool_config' \"rawgoals\" cfg_rawgoals\n            || parse_bool_config' \"register\" cfg_register\n          val parse_flags = parse_paren_list' flags  \n      \n          val parse_precond = Scan.option (@{keyword \"[\"} |-- Parse.term --| @{keyword \"]\"})\n      \n          val parse_fref_thm = Scan.option (@{keyword \"uses\"} |-- Parse.thm)\n          val parse_fixed_types = Scan.optional (@{keyword \"fixes\"} |-- Scan.repeat1 Parse.typ) []\n      \n        in\n          val di_parser = \n              parse_flags \n           -- Scan.optional (Parse.binding --| @{keyword \":\"}) Binding.empty \n           -- parse_precond \n           -- Parse.thm \n           -- parse_fref_thm\n           -- parse_fixed_types\n        end  \n      \n        fun di_cmd (((((flags,name), precond_raw), i_thm_raw), p_thm_raw), fixedTs_raw) lthy = let\n          val i_thm = singleton (Attrib.eval_thms lthy) i_thm_raw\n          val p_thm = map_option (singleton (Attrib.eval_thms lthy)) p_thm_raw\n      \n          fun map_fixed_Ts (T as TFree (n,_)) = if Variable.is_declared lthy n then n else raise TYPE (\"Fixed type must be declared\",[T],[]) \n            | map_fixed_Ts T = raise TYPE (\"Only TFrees can be fixed\",[T],[])\n          \n          val fixedTs = map (map_fixed_Ts o Syntax.parse_typ lthy) fixedTs_raw \n          \n          local\n            val ctxt = Refine_Util.apply_configs flags lthy\n          in\n            val flag_mop = Config.get ctxt cfg_mop\n            val flag_ismop = Config.get ctxt cfg_ismop\n            val flag_rawgoals = Config.get ctxt cfg_rawgoals\n            val flag_transfer = Config.get ctxt cfg_transfer\n            val flag_register = Config.get ctxt cfg_register\n          end\n      \n          val fr_attribs = if flag_register then @{attributes [sepref_fr_rules]} else []\n\n\n          val ctxt = lthy\n      \n          (* Compose with fref-theorem *)\n          val _ = dbg_trace lthy \"Compose with fref\"\n\n          local\n            val hf_tcomp_pre = @{thm hfcomp_tcomp_pre} OF [asm_rl,i_thm]\n            fun compose p_thm = let\n              val p_thm = p_thm |> to_assns_rl false lthy \n            in\n              hf_tcomp_pre OF [p_thm]\n            end\n      \n          in  \n            val thm = case p_thm of\n              SOME p_thm => compose p_thm\n            | NONE => let\n                val p_thms = Named_Theorems_Rev.get ctxt @{named_theorems_rev sepref_fref_thms}\n        \n                fun err () = let\n                  val prem_s = nth (Thm.prems_of hf_tcomp_pre) 0 |> Syntax.pretty_term ctxt |> Pretty.string_of\n                in\n                  error (\"Found no fref-theorem matching \" ^ prem_s)\n                end\n        \n              in\n                case get_first (try compose) p_thms of\n                  NONE => err ()\n                | SOME thm => thm  \n        \n              end\n          end  \n      \n          val (thm,ctxt) = yield_singleton (apfst snd oo Variable.import true) thm ctxt\n\n          val _ = dbg_trace_thm lthy \"Theorem before transfer\" thm\n          \n          val _ = dbg_trace lthy \"Transfer Precond\"\n          val thm = to_IMP_LIST ctxt thm\n          val thm = thm RS @{thm transform_pre_param}\n      \n          local\n            val (pre,R,pp_name,pp_type) = case Thm.prems_of thm of\n              [@{mpat \"Trueprop (IMP_LIST _ ((?pre,_)\\<in>?R))\"}, @{mpat \"Trueprop (IMP_PRE (mpaq_STRUCT (mpaq_Var ?pp_name ?pp_type)) _)\"}] => (pre,R,pp_name,pp_type)\n            | _ => raise THM(\"di_cmd: Cannot recognize first prems of transform_pre_param: \", ~1,[thm])\n      \n          in\n            val thm = if flag_transfer then thm OF [transfer_precond_rl fixedTs ctxt pre R] else thm\n      \n            val thm = case precond_raw of \n              NONE => thm\n            | SOME precond_raw => let\n                val precond = Syntax.parse_term ctxt precond_raw\n                  |> Sepref_Basic.constrain_type_pre pp_type\n                  |> Syntax.check_term ctxt\n                  |> Thm.cterm_of ctxt\n      \n                val thm = Drule.infer_instantiate ctxt [(pp_name,precond)] thm\n                val thm = thm OF [asm_rl,@{thm IMP_PRE_CUSTOMD}]\n              in\n                thm\n              end\n      \n          end\n\n          val _ = dbg_trace_thm lthy \"Transferred theorem\" thm\n          \n          val _ = dbg_trace lthy \"Build goals\"\n          val goals = [map (fn x => (x,[])) (Thm.prems_of thm)]\n\n          fun after_qed thmss _ = let\n            val _ = dbg_trace lthy \"After QED\"\n            val prems_thms = hd thmss\n      \n            val thm = thm OF prems_thms\n\n            val thm = from_IMP_LIST ctxt thm\n\n            (* Two rounds of cleanup-constraints, norm_fcomp *)\n            val _ = dbg_trace lthy \"Cleanup\"\n            val thm = thm\n              |> cleanup_constraints ctxt\n              |> Sepref_Rules.norm_fcomp_rule ctxt\n              |> cleanup_constraints ctxt\n              |> Sepref_Rules.norm_fcomp_rule ctxt\n      \n            val thm = thm  \n              |> singleton (Variable.export ctxt lthy)\n              |> zero_var_indexes\n      \n            val _ = dbg_trace lthy \"Check Result\"\n            val _ = chk_result lthy thm  \n      \n      \n            fun qname suffix = if Binding.is_empty name then name else Binding.suffix_name suffix name \n      \n            val thm_name = if flag_ismop then qname \"_hnr_mop\" else qname \"_hnr\"\n            val (_,lthy) = Local_Theory.note ((thm_name,fr_attribs),[thm]) lthy\n\n            val _ = Thm.pretty_thm lthy thm |> Pretty.string_of |> writeln\n\n            (* Create mop theorem from op-theorem *)\n            val cr_mop_thm = flag_mop andalso not flag_ismop\n            val lthy = \n              if cr_mop_thm then \n                let \n                  val _ = dbg_trace lthy \"Create mop-thm\"\n                  val mop_thm = thm\n                    |> generate_mop_thm lthy\n                    |> zero_var_indexes\n\n                  val (_,lthy) = Local_Theory.note ((qname \"_hnr_mop\",fr_attribs),[mop_thm]) lthy\n                  val _ = Thm.pretty_thm lthy mop_thm |> Pretty.string_of |> writeln\n                in lthy end \n              else lthy\n\n            (* Create op theorem from mop-theorem *)\n            val cr_op_thm = flag_ismop\n            val lthy = \n              if cr_op_thm then \n                let \n                  val _ = dbg_trace lthy \"Create op-thm\"\n                  val op_thm = thm\n                    |> generate_op_thm lthy\n                    |> zero_var_indexes\n\n                  val (_,lthy) = Local_Theory.note ((qname \"_hnr\",fr_attribs),[op_thm]) lthy\n                  val _ = Thm.pretty_thm lthy op_thm |> Pretty.string_of |> writeln\n                in lthy end \n              else lthy\n\n      \n          in \n            lthy \n          end\n      \n          fun std_tac ctxt = let \n            val ptac = REPEAT_ALL_NEW_FWD ( \n              Parametricity.net_tac (Parametricity.get_dflt ctxt) ctxt ORELSE' assume_tac ctxt\n              )\n          in\n            if flag_rawgoals orelse not flag_transfer then\n              all_tac\n            else\n              APPLY_LIST [\n                SELECT_GOAL (Local_Defs.unfold0_tac ctxt @{thms from_IMP_LIST}) THEN' TRY o SOLVED' ptac,\n                simp_precond_tac ctxt\n              ] 1\n            \n          end\n      \n          val rf_std = Proof.refine (Method.Basic (fn ctxt => SIMPLE_METHOD (std_tac ctxt)))\n            #> Seq.the_result \"di_cmd: Standard proof tactic returned empty result sequence\"\n\n        in\n          Proof.theorem NONE after_qed goals ctxt\n          |> rf_std\n      \n        end\n      \n        val _ = Outer_Syntax.local_theory_to_proof @{command_keyword \"sepref_decl_impl\"}\n          \"\" (di_parser >> di_cmd)\n      end\n\n    end  \n  \\<close>  \n\nsubsection \\<open>Obsolete Manual Specification Helpers\\<close>\n\n  (* Generate VCG-rules for operations *)\n  lemma vcg_of_RETURN_np:  \n    assumes \"f \\<equiv> RETURN r\"\n    shows \"SPEC (\\<lambda>x. x=r) \\<le> m \\<Longrightarrow> f \\<le> m\"\n      and \"SPEC (\\<lambda>x. x=r) \\<le>\\<^sub>n m \\<Longrightarrow> f \\<le>\\<^sub>n m\"\n    using assms\n    by (auto simp: pw_le_iff pw_leof_iff)\n\n  lemma vcg_of_RETURN:\n    assumes \"f \\<equiv> do { ASSERT \\<Phi>; RETURN r }\"\n    shows \"\\<lbrakk>\\<Phi>; SPEC (\\<lambda>x. x=r) \\<le> m\\<rbrakk> \\<Longrightarrow> f \\<le> m\"\n      and \"\\<lbrakk>\\<Phi> \\<Longrightarrow> SPEC (\\<lambda>x. x=r) \\<le>\\<^sub>n m\\<rbrakk> \\<Longrightarrow> f \\<le>\\<^sub>n m\"\n    using assms\n    by (auto simp: pw_le_iff pw_leof_iff refine_pw_simps)\n\n  \n\n  lemma vcg_of_SPEC_np:  \n    assumes \"f \\<equiv> SPEC post\"\n    shows \"SPEC post \\<le> m \\<Longrightarrow> f \\<le> m\"\n      and \"SPEC post \\<le>\\<^sub>n m \\<Longrightarrow> f \\<le>\\<^sub>n m\"\n    using assms\n    by auto \n\n\n\n\n  (* Generate parametricity rules to generalize \n    plain operations to monadic ones. Use with FCOMP.\n  *)  \n  lemma mk_mop_rl1:\n    assumes \"\\<And>x. mf x \\<equiv> doN {ASSERT (P x); RETURN (f x)}\"\n    shows \"(RETURN o f, mf) \\<in> Id \\<rightarrow> \\<langle>Id\\<rangle>nres_rel\"\n    unfolding assms[abs_def]\n    by (auto intro!: nres_relI simp: pw_le_iff refine_pw_simps)\n\n  lemma mk_mop_rl2:\n    assumes \"\\<And>x y. mf x y \\<equiv> doN {ASSERT (P x y); RETURN (f x y)}\"\n    shows \"(RETURN oo f, mf) \\<in> Id \\<rightarrow> Id \\<rightarrow> \\<langle>Id\\<rangle>nres_rel\"\n    unfolding assms[abs_def]\n    by (auto intro!: nres_relI simp: pw_le_iff refine_pw_simps)\n\n  lemma mk_mop_rl3:\n    assumes \"\\<And>x y z. mf x y z \\<equiv> doN {ASSERT (P x y z); RETURN (f x y z)}\"\n    shows \"(RETURN ooo f, mf) \\<in> Id \\<rightarrow> Id \\<rightarrow> Id \\<rightarrow> \\<langle>Id\\<rangle>nres_rel\"\n    unfolding assms[abs_def]\n    by (auto intro!: nres_relI simp: pw_le_iff refine_pw_simps)\n\n  lemma mk_mop_rl0_np:\n    assumes \"mf \\<equiv> RETURN f\"\n    shows \"(RETURN f, mf) \\<in> \\<langle>Id\\<rangle>nres_rel\"\n    unfolding assms[abs_def]\n    by (auto intro!: nres_relI simp: pw_le_iff refine_pw_simps)\n\n  lemma mk_mop_rl1_np:\n    assumes \"\\<And>x. mf x \\<equiv> RETURN (f x)\"\n    shows \"(RETURN o f, mf) \\<in> Id \\<rightarrow> \\<langle>Id\\<rangle>nres_rel\"\n    unfolding assms[abs_def]\n    by (auto intro!: nres_relI simp: pw_le_iff refine_pw_simps)\n\n  lemma mk_mop_rl2_np:\n    assumes \"\\<And>x y. mf x y \\<equiv> RETURN (f x y)\"\n    shows \"(RETURN oo f, mf) \\<in> Id \\<rightarrow> Id \\<rightarrow> \\<langle>Id\\<rangle>nres_rel\"\n    unfolding assms[abs_def]\n    by (auto intro!: nres_relI simp: pw_le_iff refine_pw_simps)\n\n  lemma mk_mop_rl3_np:\n    assumes \"\\<And>x y z. mf x y z \\<equiv> RETURN (f x y z)\"\n    shows \"(RETURN ooo f, mf) \\<in> Id \\<rightarrow> Id \\<rightarrow> Id \\<rightarrow> \\<langle>Id\\<rangle>nres_rel\"\n    unfolding assms[abs_def]\n    by (auto intro!: nres_relI simp: pw_le_iff refine_pw_simps)\n\n\n\n  lemma mk_op_rl0_np:\n    assumes \"mf \\<equiv> RETURN f\"\n    shows \"(uncurry0 mf, uncurry0 (RETURN f)) \\<in> unit_rel \\<rightarrow>\\<^sub>f \\<langle>Id\\<rangle>nres_rel\"\n    apply (intro frefI nres_relI)\n    apply (auto simp: assms)\n    done\n\n  lemma mk_op_rl1:\n    assumes \"\\<And>x. mf x \\<equiv> doN {ASSERT (P x); RETURN (f x)}\"\n    shows \"(mf, RETURN o f) \\<in> [P]\\<^sub>f Id \\<rightarrow> \\<langle>Id\\<rangle>nres_rel\"\n    apply (intro frefI nres_relI)\n    apply (auto simp: assms)\n    done\n\n  lemma mk_op_rl1_np:\n    assumes \"\\<And>x. mf x \\<equiv> RETURN (f x)\"\n    shows \"(mf, (RETURN o f)) \\<in> Id \\<rightarrow>\\<^sub>f \\<langle>Id\\<rangle>nres_rel\"\n    apply (intro frefI nres_relI)\n    apply (auto simp: assms)\n    done\n\n  lemma mk_op_rl2:\n    assumes \"\\<And>x y. mf x y \\<equiv> doN {ASSERT (P x y); RETURN (f x y)}\"\n    shows \"(uncurry mf, uncurry (RETURN oo f)) \\<in> [uncurry P]\\<^sub>f Id\\<times>\\<^sub>rId \\<rightarrow> \\<langle>Id\\<rangle>nres_rel\"\n    apply (intro frefI nres_relI)\n    apply (auto simp: assms)\n    done\n\n  lemma mk_op_rl2_np:\n    assumes \"\\<And>x y. mf x y \\<equiv> RETURN (f x y)\"\n    shows \"(uncurry mf, uncurry (RETURN oo f)) \\<in> Id\\<times>\\<^sub>rId \\<rightarrow>\\<^sub>f \\<langle>Id\\<rangle>nres_rel\"\n    apply (intro frefI nres_relI)\n    apply (auto simp: assms)\n    done\n\n  lemma mk_op_rl3:\n    assumes \"\\<And>x y z. mf x y z \\<equiv> doN {ASSERT (P x y z); RETURN (f x y z)}\"\n    shows \"(uncurry2 mf, uncurry2 (RETURN ooo f)) \\<in> [uncurry2 P]\\<^sub>f (Id\\<times>\\<^sub>rId)\\<times>\\<^sub>rId \\<rightarrow> \\<langle>Id\\<rangle>nres_rel\"\n    apply (intro frefI nres_relI)\n    apply (auto simp: assms)\n    done\n\n  lemma mk_op_rl3_np:\n    assumes \"\\<And>x y z. mf x y z \\<equiv> RETURN (f x y z)\"\n    shows \"(uncurry2 mf, uncurry2 (RETURN ooo f)) \\<in> (Id\\<times>\\<^sub>rId)\\<times>\\<^sub>rId \\<rightarrow>\\<^sub>f \\<langle>Id\\<rangle>nres_rel\"\n    apply (intro frefI nres_relI)\n    apply (auto simp: assms)\n    done\n\n\n\n\n\n\n\n\nend\n", "meta": {"author": "lammich", "repo": "isabelle_llvm", "sha": "6be37a9c3cae74a1134dbef2979e312abb5f7f42", "save_path": "github-repos/isabelle/lammich-isabelle_llvm", "path": "github-repos/isabelle/lammich-isabelle_llvm/isabelle_llvm-6be37a9c3cae74a1134dbef2979e312abb5f7f42/thys/sepref/Sepref_Intf_Util.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5428632683808533, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.2799111126916564}}
{"text": "(* \n   Title: The pi-calculus   \n   Author/Maintainer: Jesper Bengtson (jebe.dk), 2012\n*)\ntheory Weak_Early_Semantics\n  imports Weak_Early_Step_Semantics\nbegin\n\ndefinition weakFreeTransition :: \"pi \\<Rightarrow> freeRes \\<Rightarrow> pi \\<Rightarrow> bool\" (\"_ \\<Longrightarrow>\\<^sup>^_ \\<prec> _\" [80, 80, 80] 80) \n  where \"P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P' \\<equiv> P \\<Longrightarrow>\\<alpha> \\<prec> P' \\<or> (\\<alpha> = \\<tau> \\<and> P = P')\"\n\nlemma weakTransitionI:\n  fixes P  :: pi\n  and   \\<alpha>  :: freeRes\n  and   P' :: pi\n\n  shows \"P \\<Longrightarrow>\\<alpha> \\<prec> P' \\<Longrightarrow> P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P'\"\n  and   \"P \\<Longrightarrow>\\<^sup>^\\<tau> \\<prec> P\"\nby(auto simp add: weakFreeTransition_def)\n\nlemma transitionCases[consumes 1, case_names Step Stay]:\n  fixes P  :: pi\n  and   \\<alpha>  :: freeRes\n  and   P' :: pi\n\n  assumes \"P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P'\"\n  and     \"P \\<Longrightarrow>\\<alpha> \\<prec> P' \\<Longrightarrow> F \\<alpha> P'\"\n  and     \"F (\\<tau>) P\"\n\n  shows \"F \\<alpha> P'\"\nusing assms\nby(auto simp add: weakFreeTransition_def)\n\nlemma singleActionChain:\n  fixes P  :: pi\n  and   \\<alpha>  :: freeRes\n  and   P' :: pi\n\n  assumes \"P \\<longmapsto>\\<alpha> \\<prec> P'\"\n\n  shows \"P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P'\"\nusing assms\nby(auto dest: singleActionChain intro: weakTransitionI)\n\nlemma Tau:\n  fixes P :: pi\n\n  shows \"\\<tau>.(P) \\<Longrightarrow>\\<^sup>^ \\<tau> \\<prec>  P\"\nby(auto intro: Weak_Early_Step_Semantics.Tau\n   simp add: weakFreeTransition_def)\n\nlemma Input:\n  fixes a :: name\n  and   x :: name\n  and   u :: name\n  and   P :: pi\n\n  shows \"a<x>.P \\<Longrightarrow>\\<^sup>^ a<u> \\<prec> P[x::=u]\"\nby(auto intro: Weak_Early_Step_Semantics.Input\n   simp add: weakFreeTransition_def)\n  \nlemma Output:\n  fixes a :: name\n  and   b :: name\n  and   P :: pi\n\n  shows \"a{b}.P \\<Longrightarrow>\\<^sup>^a[b] \\<prec> P\"\nby(auto intro: Weak_Early_Step_Semantics.Output\n   simp add: weakFreeTransition_def)\n\nlemma Par1F:\n  fixes P  :: pi\n  and   \\<alpha>  :: freeRes\n  and   P' :: pi\n  and   Q  :: pi\n\n  assumes \"P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P'\"\n\n  shows \"P \\<parallel> Q \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> (P' \\<parallel> Q)\"\nusing assms\nby(auto intro: Weak_Early_Step_Semantics.Par1F\n   simp add: weakFreeTransition_def residual.inject)\n\nlemma Par2F:\n  fixes Q :: pi\n  and   \\<alpha>  :: freeRes\n  and   Q' :: pi\n  and   P  :: pi\n\n  assumes QTrans: \"Q \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> Q'\"\n\n  shows \"P \\<parallel> Q \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> (P \\<parallel> Q')\"\nusing assms\nby(auto intro: Weak_Early_Step_Semantics.Par2F\n   simp add: weakFreeTransition_def residual.inject)\n\n\nlemma ResF:\n  fixes P  :: pi\n  and   \\<alpha>  :: freeRes\n  and   P' :: pi\n  and   x  :: name\n\n  assumes \"P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P'\"\n  and     \"x \\<sharp> \\<alpha>\"\n\n  shows \"<\\<nu>x>P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> <\\<nu>x>P'\"\nusing assms\nby(auto intro: Weak_Early_Step_Semantics.ResF\n   simp add: weakFreeTransition_def residual.inject)\n\nlemma Bang:\n  fixes P  :: pi\n  and   Rs :: residual\n\n  assumes \"P \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P'\"\n  and     \"P' \\<noteq> P \\<parallel> !P\"\n  \n  shows \"!P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P'\"\nusing assms\nby(auto intro: Weak_Early_Step_Semantics.Bang\n   simp add: weakFreeTransition_def residual.inject)\n\nlemma tauTransitionChain[simp]:\n  fixes P  :: pi\n  and   P' :: pi\n\n  shows \"P \\<Longrightarrow>\\<^sup>^\\<tau> \\<prec> P' = P \\<Longrightarrow>\\<^sub>\\<tau> P'\"\napply(auto dest: Weak_Early_Step_Semantics.tauTransitionChain\n      simp add: weakFreeTransition_def)\nby(erule rtrancl.cases) (auto intro: transitionI)\n\nlemma tauStepTransitionChain[simp]:\n  fixes P  :: pi\n  and   P' :: pi\n\n  assumes \"P \\<noteq> P'\"\n\n  shows \"P \\<Longrightarrow>\\<tau> \\<prec> P' = P \\<Longrightarrow>\\<^sub>\\<tau> P'\"\nusing assms\napply(auto dest: Weak_Early_Step_Semantics.tauTransitionChain\n      simp add: weakFreeTransition_def)\nby(erule rtrancl.cases) (auto intro: transitionI)\n\nlemma chainTransitionAppend:\n  fixes P   :: pi\n  and   P'  :: pi\n  and   Rs  :: residual\n  and   a   :: name\n  and   x   :: name\n  and   P'' :: pi\n  and   \\<alpha>   :: freeRes\n\n  shows \"P \\<Longrightarrow>\\<^sub>\\<tau> P'' \\<Longrightarrow> P'' \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P'  \\<Longrightarrow> P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P'\"\n  and   \"P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P'' \\<Longrightarrow> P'' \\<Longrightarrow>\\<^sub>\\<tau> P' \\<Longrightarrow> P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P'\"\nby(auto intro: chainTransitionAppend simp add: weakFreeTransition_def dest: Weak_Early_Step_Semantics.tauTransitionChain)\n\nlemma freshTauTransition:\n  fixes P :: pi\n  and   c :: name\n\n  assumes \"P \\<Longrightarrow>\\<^sup>^\\<tau> \\<prec> P'\"\n  and     \"c \\<sharp> P\"\n\n  shows \"c \\<sharp> P'\"\nusing assms\nby(auto intro: Weak_Early_Step_Semantics.freshTauTransition\n   simp add: weakFreeTransition_def residual.inject)\n\nlemma freshOutputTransition:\n  fixes P  :: pi\n  and   a  :: name\n  and   b  :: name\n  and   P' :: pi\n  and   c  :: name\n\n  assumes \"P \\<Longrightarrow>\\<^sup>^a[b] \\<prec> P'\"\n  and     \"c \\<sharp> P\"\n\n  shows \"c \\<sharp> P'\"\nusing assms\nby(auto intro: Weak_Early_Step_Semantics.freshOutputTransition\n   simp add: weakFreeTransition_def residual.inject)\n\nlemma eqvtI:\n  fixes P  :: pi\n  and   \\<alpha>  :: freeRes\n  and   P' :: pi\n  and   p  :: \"name prm\"\n\n  assumes \"P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P'\"\n\n  shows \"(p \\<bullet> P) \\<Longrightarrow>\\<^sup>^(p \\<bullet> \\<alpha>) \\<prec> (p \\<bullet> P')\"\nusing assms\nby(auto intro: Weak_Early_Step_Semantics.eqvtI\n   simp add: weakFreeTransition_def residual.inject)\n\nlemma freshInputTransition:\n  fixes P  :: pi\n  and   a  :: name\n  and   b  :: name\n  and   P' :: pi\n  and   c  :: name\n\n  assumes \"P \\<Longrightarrow>\\<^sup>^a<b> \\<prec> P'\"\n  and     \"c \\<sharp> P\"\n  and     \"c \\<noteq> b\"\n\n  shows \"c \\<sharp> P'\"\nusing assms\nby(auto intro: Weak_Early_Step_Semantics.freshInputTransition\n   simp add: weakFreeTransition_def residual.inject)\n\nlemmas freshTransition = freshBoundOutputTransition freshOutputTransition\n                         freshInputTransition freshTauTransition\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Pi_Calculus/Weak_Early_Semantics.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5467381667555713, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.2797749983543407}}
{"text": "theory UserDataTypeInstance\n  imports\n    Main\n    \"Ecore-GROOVE-Mapping.Instance_Model_Graph_Mapping\"\n    UserDataTypeType\nbegin\n\nsection \"Definition of an instance model belonging to the introduction of an user defined data type\"\n\ndefinition imod_userdatatype :: \"'t Id \\<Rightarrow> ('o, 't) instance_model\" where\n  \"imod_userdatatype name = \\<lparr>\n    Tm = tmod_userdatatype name,\n    Object = {},\n    ObjectClass = (\\<lambda>x. undefined),\n    ObjectId = (\\<lambda>x. undefined),\n    FieldValue = (\\<lambda>x. undefined),\n    DefaultValue = (\\<lambda>x. undefined)\n  \\<rparr>\"\n\nlemma imod_userdatatype_correct: \"instance_model (imod_userdatatype name)\"\nproof (intro imod_empty_any_type_model_correct)\n  show \"type_model (Tm (imod_userdatatype name))\"\n    unfolding imod_userdatatype_def\n    using tmod_userdatatype_correct\n    by simp\nqed (simp_all add: imod_userdatatype_def tmod_userdatatype_def)\n\nlemma imod_userdatatype_combine_correct:\n  assumes \"instance_model Imod\"\n  assumes new_userdatatype: \"name \\<notin> Class (Tm Imod) \\<union> Enum (Tm Imod) \\<union> UserDataType (Tm Imod)\"\n  assumes valid_identifier: \"\\<And>x. x \\<in> Class (Tm Imod) \\<union> Enum (Tm Imod) \\<union> UserDataType (Tm Imod) \\<Longrightarrow> \\<not>id_in_ns name (Identifier x) \\<and> \\<not>id_in_ns x (Identifier name)\"\n  shows \"instance_model (imod_combine Imod (imod_userdatatype name))\"\nproof (intro imod_combine_distinct_correct)\n  show \"instance_model (imod_userdatatype name)\"\n    by (fact imod_userdatatype_correct)\nnext\n  show \"type_model (tmod_combine (Tm Imod) (Tm (imod_userdatatype name)))\"\n    unfolding imod_userdatatype_def\n    using assms instance_model.select_convs(1) instance_model.validity_type_model_consistent tmod_userdatatype_combine_correct\n    by metis\nnext\n  show \"UserDataType (Tm Imod) \\<inter> UserDataType (Tm (imod_userdatatype name)) = {}\"\n    unfolding imod_userdatatype_def tmod_userdatatype_def\n    using new_userdatatype\n    by simp\nqed (simp_all add: assms imod_userdatatype_def tmod_userdatatype_def)\n\n\n\nsection \"Encoding of an user defined data type as Node Type in GROOVE\"\n\ndefinition ig_userdatatype_as_node_type :: \"'t Id \\<Rightarrow> 't \\<Rightarrow> ('o, 't list, 't) instance_graph\" where\n  \"ig_userdatatype_as_node_type name data_edge = \\<lparr>\n    TG = tg_userdatatype_as_node_type name data_edge,\n    Id = {},\n    N = {},\n    E = {},\n    ident = (\\<lambda>x. undefined)\n  \\<rparr>\"\n\nlemma ig_userdatatype_as_node_type_correct: \"instance_graph (ig_userdatatype_as_node_type name data_edge)\"\nproof (intro ig_empty_any_type_graph_correct)\n  show \"type_graph (TG (ig_userdatatype_as_node_type name data_edge))\"\n    unfolding ig_userdatatype_as_node_type_def\n    using tg_userdatatype_as_node_type_correct\n    by simp\nqed (simp_all add: ig_userdatatype_as_node_type_def tg_userdatatype_as_node_type_def)\n\nlemma ig_userdatatype_as_node_type_combine_correct:\n  assumes \"instance_graph IG\"\n  assumes combined_node_types: \"NT (TG IG) \\<inter> {type (id_to_list name), LabDef.string} \\<subseteq> {LabDef.string}\"\n  shows \"instance_graph (ig_combine IG (ig_userdatatype_as_node_type name data_edge))\"\nproof (intro ig_combine_merge_no_containment_imod2_correct)\n  show \"instance_graph (ig_userdatatype_as_node_type name data_edge)\"\n    by (fact ig_userdatatype_as_node_type_correct)\nnext\n  show \"ET (TG IG) \\<inter> ET (TG (ig_userdatatype_as_node_type name data_edge)) = {}\"\n    unfolding ig_userdatatype_as_node_type_def tg_userdatatype_as_node_type_def\n    using assms instance_graph.validity_type_graph type_graph.structure_edges_wellformed_src_node\n    by fastforce\nnext\n  have \"type_graph (tg_combine (TG IG) (tg_userdatatype_as_node_type name data_edge))\"\n    using assms\n    by (simp add: tg_userdatatype_as_node_type_combine_correct instance_graph.validity_type_graph)\n  then show \"type_graph (tg_combine (TG IG) (TG (ig_userdatatype_as_node_type name data_edge)))\"\n    unfolding ig_userdatatype_as_node_type_def\n    by simp\nnext\n  fix et n\n  assume et_def: \"et \\<in> ET (TG IG)\"\n  assume \"n \\<in> N IG \\<union> N (ig_userdatatype_as_node_type name data_edge)\"\n  then have n_def: \"n \\<in> N IG\"\n    unfolding ig_userdatatype_as_node_type_def\n    by simp\n  then have type_n_def: \"type\\<^sub>n n \\<in> NT (TG IG)\"\n    using assms(1) instance_graph.validity_node_typed\n    by blast\n  then have type_n_not_name: \"type\\<^sub>n n \\<noteq> type (id_to_list name)\"\n    using combined_node_types\n    by fastforce\n  assume \"(type\\<^sub>n n, src et) \\<in> (inh (TG IG) \\<union> inh (TG (ig_userdatatype_as_node_type name data_edge)))\\<^sup>+\"\n  then have inh_unfold_def: \"(type\\<^sub>n n, src et) \\<in> (inh (TG IG) \\<union> {(type (id_to_list name), type (id_to_list name)), (LabDef.string, LabDef.string)})\\<^sup>+\"\n    unfolding ig_userdatatype_as_node_type_def tg_userdatatype_as_node_type_def\n    by simp\n  show \"card {e \\<in> E IG. src e = n \\<and> type\\<^sub>e e = et} in m_out (mult (TG IG) et)\"\n  proof (induct \"LabDef.string \\<in> NT (TG IG)\")\n    case True\n    then have \"(type\\<^sub>n n, src et) \\<in> (inh (TG IG) \\<union> {(type (id_to_list name), type (id_to_list name))})\\<^sup>+\"\n      using IntD2 Un_insert_right inf_sup_absorb insert_absorb\n      using inh_unfold_def assms(1) instance_graph.validity_type_graph type_graph.validity_inh_node\n      by metis\n    then have \"(type\\<^sub>n n, src et) \\<in> (inh (TG IG))\\<^sup>+\"\n    proof (induct)\n      case (base y)\n      then show ?case\n        using type_n_not_name\n        by blast\n    next\n      case (step y z)\n      then have \"y \\<in> NT (TG IG)\"\n        by (simp add: assms(1) instance_graph.validity_type_graph type_graph.structure_inheritance_wellformed_second_node type_graph.validity_inh_trans)\n      then have \"y \\<noteq> type (id_to_list name)\"\n        using combined_node_types\n        by blast\n      then have \"(y, z) \\<in> inh (TG IG)\"\n        using step.hyps(2)\n        by blast\n      then show ?case\n        using step.hyps(3)\n        by simp\n    qed\n    then have \"(type\\<^sub>n n, src et) \\<in> inh (TG IG)\"\n      by (simp add: assms(1) instance_graph.validity_type_graph type_graph.validity_inh_trans)\n    then show ?case\n      using assms(1) instance_graph.validity_outgoing_mult et_def n_def\n      by blast\n  next\n    case False\n    then have combined_node_types_empty: \"NT (TG IG) \\<inter> {type (id_to_list name), LabDef.string} = {}\"\n      using combined_node_types\n      by blast\n    then have type_n_not_string: \"type\\<^sub>n n \\<noteq> LabDef.string\"\n      using type_n_def\n      by blast\n    have \"(type\\<^sub>n n, src et) \\<in> (inh (TG IG))\\<^sup>+\"\n      using inh_unfold_def\n    proof (induct)\n      case (base y)\n      then show ?case\n        using type_n_not_name type_n_not_string\n        by blast\n    next\n      case (step y z)\n      then have \"y \\<in> NT (TG IG)\"\n        by (simp add: assms(1) instance_graph.validity_type_graph type_graph.structure_inheritance_wellformed_second_node type_graph.validity_inh_trans)\n      then have \"y \\<noteq> type (id_to_list name) \\<and> y \\<noteq> LabDef.string\"\n        using combined_node_types_empty\n        by blast\n      then have \"(y, z) \\<in> inh (TG IG)\"\n        using step.hyps(2)\n        by blast\n      then show ?case\n        using step.hyps(3)\n        by simp\n    qed\n    then have \"(type\\<^sub>n n, src et) \\<in> inh (TG IG)\"\n      by (simp add: assms(1) instance_graph.validity_type_graph type_graph.validity_inh_trans)\n    then show ?case\n      using assms(1) instance_graph.validity_outgoing_mult et_def n_def\n      by blast\n  qed\nnext\n  fix et n\n  assume \"et \\<in> ET (TG (ig_userdatatype_as_node_type name data_edge))\"\n  then have et_def: \"et = (type (id_to_list name), LabDef.edge [data_edge], LabDef.string)\"\n    unfolding ig_userdatatype_as_node_type_def tg_userdatatype_as_node_type_def\n    by simp\n  then have src_et_def: \"src et = type (id_to_list name)\"\n    by simp\n  assume \"n \\<in> N IG \\<union> N (ig_userdatatype_as_node_type name data_edge)\"\n  then have n_def: \"n \\<in> N IG\"\n    unfolding ig_userdatatype_as_node_type_def\n    by simp\n  then have type_n_def: \"type\\<^sub>n n \\<in> NT (TG IG)\"\n    using assms(1) instance_graph.validity_node_typed\n    by blast\n  then have type_n_not_name: \"type\\<^sub>n n \\<noteq> type (id_to_list name)\"\n    using combined_node_types\n    by fastforce\n  have no_inh: \"(type\\<^sub>n n, src et) \\<notin> (inh (TG IG) \\<union> {(type (id_to_list name), type (id_to_list name)), (LabDef.string, LabDef.string)})\\<^sup>+\"\n  proof\n    assume \"(type\\<^sub>n n, src et) \\<in> (inh (TG IG) \\<union> {(LabDef.type (id_to_list name), LabDef.type (id_to_list name)), (LabDef.string, LabDef.string)})\\<^sup>+\"\n    then show \"False\"\n    proof (cases)\n      case base\n      then have \"(type\\<^sub>n n, src et) = (type (id_to_list name), type (id_to_list name))\"\n        using src_et_def assms(1) instance_graph.validity_type_graph type_graph.structure_inheritance_wellformed_second_node_alt combined_node_types\n        by fastforce\n      then show ?thesis\n        using type_n_not_name\n        by blast\n    next\n      case (step c)\n      then have \"(c, src et) = (type (id_to_list name), type (id_to_list name))\"\n        using src_et_def assms(1) instance_graph.validity_type_graph type_graph.structure_inheritance_wellformed_second_node_alt combined_node_types\n        by fastforce\n      then have c_def: \"c = type (id_to_list name)\"\n        by simp\n      have \"(inh (TG IG) \\<union> {(LabDef.type (id_to_list name), LabDef.type (id_to_list name)), (LabDef.string, LabDef.string)})\\<^sup>+ = \n        inh (TG IG) \\<union> {(LabDef.type (id_to_list name), LabDef.type (id_to_list name)), (LabDef.string, LabDef.string)}\"\n        using assms(1) instance_graph.validity_type_graph tg_userdatatype_as_node_type_combine_inh tg_userdatatype_as_node_type_def type_graph.select_convs(3)\n        by metis\n      then have \"(type\\<^sub>n n, c) = (LabDef.type (id_to_list name), LabDef.type (id_to_list name))\"\n        using step(1) c_def assms(1) instance_graph.validity_type_graph type_graph.structure_inheritance_wellformed_second_node_alt combined_node_types\n        by fastforce\n      then show ?thesis\n        using type_n_not_name\n        by blast\n    qed\n  qed\n  assume \"(type\\<^sub>n n, src et) \\<in> (inh (TG IG) \\<union> inh (TG (ig_userdatatype_as_node_type name data_edge)))\\<^sup>+\"\n  then have \"(type\\<^sub>n n, src et) \\<in> (inh (TG IG) \\<union> {(type (id_to_list name), type (id_to_list name)), (LabDef.string, LabDef.string)})\\<^sup>+\"\n    unfolding ig_userdatatype_as_node_type_def tg_userdatatype_as_node_type_def\n    by simp\n  then show \"card {e \\<in> E (ig_userdatatype_as_node_type name data_edge). src e = n \\<and> type\\<^sub>e e = et} in m_out (mult (TG (ig_userdatatype_as_node_type name data_edge)) et)\"\n    using no_inh\n    by blast\nnext\n  fix et n\n  assume et_def: \"et \\<in> ET (TG IG)\"\n  assume \"n \\<in> N IG \\<union> N (ig_userdatatype_as_node_type name data_edge)\"\n  then have n_def: \"n \\<in> N IG\"\n    unfolding ig_userdatatype_as_node_type_def\n    by simp\n  then have type_n_def: \"type\\<^sub>n n \\<in> NT (TG IG)\"\n    using assms(1) instance_graph.validity_node_typed\n    by blast\n  then have type_n_not_name: \"type\\<^sub>n n \\<noteq> type (id_to_list name)\"\n    using combined_node_types\n    by fastforce\n  assume \"(type\\<^sub>n n, tgt et) \\<in> (inh (TG IG) \\<union> inh (TG (ig_userdatatype_as_node_type name data_edge)))\\<^sup>+\"\n  then have inh_unfold_def: \"(type\\<^sub>n n, tgt et) \\<in> (inh (TG IG) \\<union> {(type (id_to_list name), type (id_to_list name)), (LabDef.string, LabDef.string)})\\<^sup>+\"\n    unfolding ig_userdatatype_as_node_type_def tg_userdatatype_as_node_type_def\n    by simp\n  show \"card {e \\<in> E IG. tgt e = n \\<and> type\\<^sub>e e = et} in m_in (mult (TG IG) et)\"\n  proof (induct \"LabDef.string \\<in> NT (TG IG)\")\n    case True\n    then have \"(type\\<^sub>n n, tgt et) \\<in> (inh (TG IG) \\<union> {(type (id_to_list name), type (id_to_list name))})\\<^sup>+\"\n      using IntD2 Un_insert_right inf_sup_absorb insert_absorb\n      using inh_unfold_def assms(1) instance_graph.validity_type_graph type_graph.validity_inh_node\n      by metis\n    then have \"(type\\<^sub>n n, tgt et) \\<in> (inh (TG IG))\\<^sup>+\"\n    proof (induct)\n      case (base y)\n      then show ?case\n        using type_n_not_name\n        by blast\n    next\n      case (step y z)\n      then have \"y \\<in> NT (TG IG)\"\n        by (simp add: assms(1) instance_graph.validity_type_graph type_graph.structure_inheritance_wellformed_second_node type_graph.validity_inh_trans)\n      then have \"y \\<noteq> type (id_to_list name)\"\n        using combined_node_types\n        by blast\n      then have \"(y, z) \\<in> inh (TG IG)\"\n        using step.hyps(2)\n        by blast\n      then show ?case\n        using step.hyps(3)\n        by simp\n    qed\n    then have \"(type\\<^sub>n n, tgt et) \\<in> inh (TG IG)\"\n      by (simp add: assms(1) instance_graph.validity_type_graph type_graph.validity_inh_trans)\n    then show ?case\n      using assms(1) instance_graph.validity_ingoing_mult et_def n_def\n      by blast\n  next\n    case False\n    then have combined_node_types_empty: \"NT (TG IG) \\<inter> {type (id_to_list name), LabDef.string} = {}\"\n      using combined_node_types\n      by blast\n    then have type_n_not_string: \"type\\<^sub>n n \\<noteq> LabDef.string\"\n      using type_n_def\n      by blast\n    have \"(type\\<^sub>n n, tgt et) \\<in> (inh (TG IG))\\<^sup>+\"\n      using inh_unfold_def\n    proof (induct)\n      case (base y)\n      then show ?case\n        using type_n_not_name type_n_not_string\n        by blast\n    next\n      case (step y z)\n      then have \"y \\<in> NT (TG IG)\"\n        by (simp add: assms(1) instance_graph.validity_type_graph type_graph.structure_inheritance_wellformed_second_node type_graph.validity_inh_trans)\n      then have \"y \\<noteq> type (id_to_list name) \\<and> y \\<noteq> LabDef.string\"\n        using combined_node_types_empty\n        by blast\n      then have \"(y, z) \\<in> inh (TG IG)\"\n        using step.hyps(2)\n        by blast\n      then show ?case\n        using step.hyps(3)\n        by simp\n    qed\n    then have \"(type\\<^sub>n n, tgt et) \\<in> inh (TG IG)\"\n      by (simp add: assms(1) instance_graph.validity_type_graph type_graph.validity_inh_trans)\n    then show ?case\n      using assms(1) instance_graph.validity_ingoing_mult et_def n_def\n      by blast\n  qed\nqed (simp_all add: ig_userdatatype_as_node_type_def tg_userdatatype_as_node_type_def assms)\n\n\nsubsection \"Transformation functions\"\n\ndefinition imod_userdatatype_to_ig_userdatatype_as_node_type :: \"'t Id \\<Rightarrow> 't \\<Rightarrow> ('o, 't) instance_model \\<Rightarrow> ('o, 't list, 't) instance_graph\" where\n  \"imod_userdatatype_to_ig_userdatatype_as_node_type name data_edge Imod = \\<lparr>\n    TG = tg_userdatatype_as_node_type name data_edge,\n    Id = {},\n    N = {},\n    E = {},\n    ident = (\\<lambda>x. undefined)\n  \\<rparr>\"\n\nlemma imod_userdatatype_to_ig_userdatatype_as_node_type_proj:\n  shows \"imod_userdatatype_to_ig_userdatatype_as_node_type name data_edge (imod_userdatatype name) = ig_userdatatype_as_node_type name data_edge\"\n  unfolding imod_userdatatype_to_ig_userdatatype_as_node_type_def ig_userdatatype_as_node_type_def imod_userdatatype_def\n  by simp\n\nlemma imod_userdatatype_to_ig_userdatatype_as_node_type_func:\n  shows \"ig_combine_mapping_function (imod_userdatatype_to_ig_userdatatype_as_node_type name data_edge) (imod_userdatatype name) (ig_userdatatype_as_node_type name data_edge)\"\n  by (intro ig_combine_mapping_function.intro)\n    (simp_all add: imod_userdatatype_to_ig_userdatatype_as_node_type_def imod_userdatatype_def ig_userdatatype_as_node_type_def imod_combine_def)\n\ndefinition ig_userdatatype_as_node_type_to_imod_userdatatype :: \"'t Id \\<Rightarrow> ('o, 't list, 't) instance_graph \\<Rightarrow> ('o, 't) instance_model\" where\n  \"ig_userdatatype_as_node_type_to_imod_userdatatype name IG = \\<lparr>\n    Tm = tmod_userdatatype name,\n    Object = {},\n    ObjectClass = (\\<lambda>x. undefined),\n    ObjectId = (\\<lambda>x. undefined),\n    FieldValue = (\\<lambda>x. undefined),\n    DefaultValue = (\\<lambda>x. undefined)\n  \\<rparr>\"\n\nlemma ig_userdatatype_as_node_type_to_imod_userdatatype_proj:\n  shows \"ig_userdatatype_as_node_type_to_imod_userdatatype name (ig_userdatatype_as_node_type name data_edge) = imod_userdatatype name\"\n  unfolding ig_userdatatype_as_node_type_to_imod_userdatatype_def imod_userdatatype_def ig_userdatatype_as_node_type_def\n  by simp\n\nlemma ig_userdatatype_as_node_type_to_imod_userdatatype_func:\n  shows \"imod_combine_mapping_function (ig_userdatatype_as_node_type_to_imod_userdatatype name) (ig_userdatatype_as_node_type name data_edge) (imod_userdatatype name)\"\n  by (intro imod_combine_mapping_function.intro)\n      (simp_all add: ig_userdatatype_as_node_type_to_imod_userdatatype_def imod_userdatatype_def ig_userdatatype_as_node_type_def ig_combine_def)\n\nend", "meta": {"author": "RemcodM", "repo": "thesis-ecore-groove-formalisation", "sha": "a0e860c4b60deb2f3798ae2ffc09f18a98cf42ca", "save_path": "github-repos/isabelle/RemcodM-thesis-ecore-groove-formalisation", "path": "github-repos/isabelle/RemcodM-thesis-ecore-groove-formalisation/thesis-ecore-groove-formalisation-a0e860c4b60deb2f3798ae2ffc09f18a98cf42ca/isabelle/Ecore-GROOVE-Mapping-Library/UserDataTypeInstance.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.63341024983754, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.27976020886452774}}
{"text": "theory ArityAnalysisPreImpl\nimports ArityAnalysisSig \"Env-Nominal\"\nbegin\n\ndefinition thunks_AE  :: \"heap \\<Rightarrow> AEnv\" where\n  \"thunks_AE \\<Gamma> = (\\<lambda> x . (if x \\<in> thunks \\<Gamma> then up\\<cdot>0 else \\<bottom>))\"\n\nlemma edom_thunks_AE: \"edom (thunks_AE \\<Gamma>) \\<subseteq> domA \\<Gamma>\"\n  unfolding edom_def thunks_AE_def by (auto dest: set_mp[OF thunks_domA])\n\nlemma thunks_AE_eqvt[eqvt]:\n  \"\\<pi> \\<bullet> thunks_AE \\<Gamma> = thunks_AE (\\<pi> \\<bullet> \\<Gamma>)\"\n  unfolding thunks_AE_def\n  by perm_simp rule\n\nlemma thunks_AE_subst[simp]:\n  \"thunks_AE \\<Gamma>[y::h=x] = thunks_AE \\<Gamma>\"\n  unfolding thunks_AE_def by simp\n\nlemma thunks_AE_subst_approx:\n  \"y \\<notin> domA \\<Gamma> \\<Longrightarrow> thunks_AE \\<Gamma>[y::h=x] \\<sqsubseteq> (thunks_AE \\<Gamma>)(y := \\<bottom>, x := up\\<cdot>0)\"\n  by (auto intro!: fun_belowI dest!: contra_subsetD[OF edom_thunks_AE] simp add: edomIff)\n\nlocale ArityAnalysisPreImpl =\n  fixes Afix ::  \"(exp \\<Rightarrow> (Arity \\<rightarrow> AEnv)) \\<Rightarrow> heap \\<Rightarrow> AEnv \\<rightarrow> AEnv\"\n  assumes Afix_eqvt: \"p \\<bullet> Afix = Afix\"\n  assumes Afix_cong[fundef_cong]:\n    \"\\<lbrakk> (\\<And> e. size e \\<le> size_list (\\<lambda>p. size (snd p)) heap1 \\<Longrightarrow> aexp1 e = aexp2 e); heap1 = heap2 \\<rbrakk>\n        \\<Longrightarrow> Afix aexp1 heap1 = Afix aexp2 heap2\"\nbegin\n  \nnominal_function\n  Aexp :: \"exp \\<Rightarrow> (Arity \\<rightarrow> AEnv)\"\nwhere\n  \"Aexp (Var x) = (\\<Lambda> n . esing x\\<cdot>(up\\<cdot>n))\"\n| \"Aexp (Lam [x]. e) = (\\<Lambda> n . (Aexp e \\<cdot> (pred \\<cdot> n)  f|` (fv (Lam [x]. e))))\"\n| \"Aexp (App e x) = (\\<Lambda> n . Aexp e  \\<cdot> (inc \\<cdot> n) \\<squnion> (esing x \\<cdot> (up \\<cdot> 0)))\"\n| \"Aexp (Terms.Let as e) = (\\<Lambda> n . (Afix Aexp as \\<cdot> (Aexp e \\<cdot> n \\<squnion> thunks_AE as)) f|` (fv (Terms.Let as e)))\"\n| \"Aexp (Bool b) = \\<bottom>\"\n| \"Aexp (scrut ? e1 : e2) = (\\<Lambda> n. Aexp scrut\\<cdot>0 \\<squnion> Aexp e1\\<cdot>n \\<squnion> Aexp e2\\<cdot>n)\"\nproof-\ncase goal1\n    note Afix_eqvt[eqvt]\n    show ?case\n    unfolding eqvt_def Aexp_graph_aux_def\n    apply rule\n    apply (perm_simp)\n    apply (simp add: Abs_cfun_eqvt)\n    done\nnext\ncase goal3 thus ?case by (metis Terms.exp_strong_exhaust)\nnext\ncase (goal10 x e x' e')\n  from goal10(5)\n  show ?case\n  proof(rule eqvt_lam_case)\n    fix \\<pi> :: perm\n    assume *: \"supp (-\\<pi>) \\<sharp>* (fv (Lam [x]. e) :: var set)\" \n    {\n    fix n\n    have \"Aexp_sumC (\\<pi> \\<bullet> e)\\<cdot>(pred\\<cdot>n)  f|` fv  (Lam [x]. e) = (-\\<pi> \\<bullet> Aexp_sumC (\\<pi> \\<bullet> e)\\<cdot>(pred\\<cdot>n)) f|` fv  (Lam [x]. e)\"\n      by (rule env_restr_perm[symmetric, OF *]) simp\n    also have \"\\<dots> = ((Aexp_sumC e)\\<cdot>(pred\\<cdot>n)) f|` fv  (Lam [x]. e)\"\n      by (simp add: eqvt_at_apply[OF goal10(1)] pemute_minus_self)\n    also note calculation\n    }\n    thus \"(\\<Lambda> n. Aexp_sumC (\\<pi> \\<bullet> e)\\<cdot>(pred\\<cdot>n) f|` fv (Lam [x]. e)) = (\\<Lambda> n. Aexp_sumC e\\<cdot>(pred\\<cdot>n) f|` fv (Lam [x]. e))\" by simp\n  qed\nnext\ncase (goal19 as body as' body')\n  note Afix_eqvt[eqvt]\n\n  from goal19(9)\n  show ?case\n  proof (rule eqvt_let_case)\n    fix \\<pi> :: perm\n    assume *: \"supp (-\\<pi>) \\<sharp>* (fv (Terms.Let as body) :: var set)\"\n    \n    { fix n\n      have \"Afix Aexp_sumC (\\<pi> \\<bullet> as)\\<cdot>(Aexp_sumC (\\<pi> \\<bullet> body)\\<cdot>n \\<squnion> thunks_AE (\\<pi> \\<bullet> as)) f|` fv (Terms.Let as body)\n      =  (- \\<pi> \\<bullet> Afix Aexp_sumC (\\<pi> \\<bullet> as)\\<cdot>(Aexp_sumC (\\<pi> \\<bullet> body)\\<cdot>n \\<squnion> thunks_AE (\\<pi> \\<bullet> as))) f|` fv (Terms.Let as body)\"\n        by (rule env_restr_perm[OF *, symmetric]) simp\n      also have \"- \\<pi> \\<bullet> Afix Aexp_sumC (\\<pi> \\<bullet> as)\\<cdot>(Aexp_sumC (\\<pi> \\<bullet> body)\\<cdot>n \\<squnion> thunks_AE (\\<pi> \\<bullet> as)) = \n                       Afix (- \\<pi> \\<bullet> Aexp_sumC) as\\<cdot>((- \\<pi> \\<bullet> Aexp_sumC) body\\<cdot>n \\<squnion> thunks_AE as)\"\n        by (simp add: pemute_minus_self)\n      also have \"Afix (- \\<pi> \\<bullet> Aexp_sumC) as = Afix Aexp_sumC as\"\n        by (rule Afix_cong[OF eqvt_at_apply[OF goal19(1)] refl])\n      also have \"(- \\<pi> \\<bullet> Aexp_sumC) body = Aexp_sumC body\"\n        by (rule eqvt_at_apply[OF goal19(2)])\n      also note calculation\n    }\n    thus \"(\\<Lambda> n. Afix Aexp_sumC (\\<pi> \\<bullet> as)\\<cdot>(Aexp_sumC (\\<pi> \\<bullet> body)\\<cdot>n \\<squnion> thunks_AE (\\<pi> \\<bullet> as)) f|` fv (Terms.Let as body)) =\n         (\\<Lambda> n. Afix Aexp_sumC as\\<cdot>(Aexp_sumC body\\<cdot>n \\<squnion> thunks_AE as) f|` fv (Terms.Let as body))\" by (simp only:)\n  qed\nqed auto\n\nnominal_termination (eqvt) by lexicographic_order\nend\n\n\nend\n", "meta": {"author": "nomeata", "repo": "isa-launchbury", "sha": "2caa8d7d588e218aef1c49f2f327597af06d116e", "save_path": "github-repos/isabelle/nomeata-isa-launchbury", "path": "github-repos/isabelle/nomeata-isa-launchbury/isa-launchbury-2caa8d7d588e218aef1c49f2f327597af06d116e/Scratchpad/ArityAnalysisPreImpl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953651858118, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.2797272536582714}}
{"text": "theory Globalenvs\n  imports Main\n    Maps AST\n    Integers Floats Values Memory\nbegin\n\n(** Global environments are a component of the dynamic semantics of\n  all languages involved in the compiler.  A global environment\n  maps symbol names (names of functions and of global variables)\n  to the corresponding memory addresses.  It also maps memory addresses\n  of functions to the corresponding function descriptions.\n\n  Global environments, along with the initial memory state at the beginning\n  of program execution, are built from the program of interest, as follows:\n- A distinct memory address is assigned to each function of the program.\n  These function addresses use negative numbers to distinguish them from\n  addresses of memory blocks.  The associations of function name to function\n  address and function address to function description are recorded in\n  the global environment.\n- For each global variable, a memory block is allocated and associated to\n  the name of the variable.\n\n  These operations reflect (at a high level of abstraction) what takes\n  place during program linking and program loading in a real operating\n  system. *)\n\n(** Auxiliary function for initialization of global variables. *)\n\nfun store_zeros :: \"mem \\<Rightarrow> block \\<Rightarrow> Z \\<Rightarrow> Z \\<Rightarrow> (mem option)\" where\n  \"store_zeros m b p n =\n  (if n \\<le> 0 then Some m else\n    (case Mem.store Mint8unsigned m b p (Vint 0) of\n      Some m' \\<Rightarrow> store_zeros m' b (p + 1) (n - 1)\n    | None \\<Rightarrow> None\n    ))\"\n\nsection \\<open>Symbol environments\\<close>\n\n(** Symbol environments are a restricted view of global environments,\n  focusing on symbol names and their associated blocks.  They do not\n  contain mappings from blocks to function or variable definitions. *)\n\nrecord Senv_t =\n  senv_find_symbol :: \"ident \\<Rightarrow> block option\"\n  senv_public_symbol :: \"ident \\<Rightarrow> bool\"\n  senv_invert_symbol :: \"block \\<Rightarrow> ident option\"\n  senv_block_is_volatile :: \"block \\<Rightarrow> bool\"\n  senv_nextblock :: block\n\nlocale Senv'\nbegin\n\n(** Operations *)\nabbreviation \"find_symbol \\<equiv> senv_find_symbol\"\nabbreviation \"public_symbol \\<equiv> senv_public_symbol\"\nabbreviation \"invert_symbol \\<equiv> senv_invert_symbol\"\nabbreviation \"block_is_volatile \\<equiv> senv_block_is_volatile\"\nabbreviation \"nextblock \\<equiv> senv_nextblock\"\n\n(** Properties *)\n\nnamed_theorems inv_defs'\n\ndefinition [inv_defs']: \"find_symbol_injective se \\<equiv>\n  \\<forall>id1 id2 b. find_symbol se id1 = Some b \\<longrightarrow> find_symbol se id2 = Some b \\<longrightarrow> id1 = id2\"\n\ndefinition [inv_defs']: \"invert_find_symbol se \\<equiv>\n  \\<forall>id b. invert_symbol se b = Some id \\<longrightarrow> find_symbol se id = Some b\"\n\ndefinition [inv_defs']: \"find_invert_symbol se \\<equiv>\n  \\<forall>id b. find_symbol se id = Some b \\<longrightarrow> invert_symbol se b = Some id\"\n\ndefinition [inv_defs']: \"public_symbol_exists se \\<equiv>\n  \\<forall>id. public_symbol se id \\<longrightarrow> (\\<exists> b. find_symbol se id = Some b)\"\n\ndefinition [inv_defs']: \"find_symbol_below se \\<equiv>\n  \\<forall>id b. find_symbol se id = Some b \\<longrightarrow> b < nextblock se\"\n\ndefinition [inv_defs']: \"block_is_volatile_below se \\<equiv>\n  \\<forall>b. block_is_volatile se b \\<longrightarrow> b < nextblock se\"\n\ninductive invariants where\n  \"\\<lbrakk> find_symbol_injective se;\n     invert_find_symbol se;\n     find_invert_symbol se;\n     public_symbol_exists se;\n     find_symbol_below se;\n     block_is_volatile_below se \\<rbrakk> \\<Longrightarrow>\n  invariants se\"\n\nlemmas inv_def = inv_defs' invariants.simps[simplified]\n\ndefinition equiv :: \"Senv_t \\<Rightarrow> Senv_t \\<Rightarrow> bool\" where\n  \"equiv se1 se2 =\n     ((\\<forall> ident. find_symbol se2 ident = find_symbol se1 ident)\n  \\<and> (\\<forall> ident. public_symbol se2 ident = public_symbol se1 ident)\n  \\<and> (\\<forall> b. block_is_volatile se2 b = block_is_volatile se1 b))\"\nend\n\ninterpretation Senv: Senv' .\n\nsection \\<open>Global Environments\\<close>\n\nrecord ('f, 'v) Genv_t =\n  genv_public :: \"ident list\" (* which symbol names are public *)\n  genv_symb :: \"block ITree\" (* mapping symbol -> block *)\n  genv_defs :: \"(('f, 'v) globdef) PTree\" (* mapping block -> definition *)\n  genv_next :: block (* next symbol pointer *)\n\nlocale Genv' =\n  fixes ft :: \"'f itself\"\n  fixes vt :: \"'v itself\"\nbegin\n\nnamed_theorems inv_defs'\n\ndefinition [inv_defs']: \"genv_symb_range ge \\<equiv>\n  \\<forall>id b. ITree.get id (genv_symb ge) = Some b \\<longrightarrow> b < (genv_next ge)\"\n\ndefinition [inv_defs']: \"genv_defs_range ge \\<equiv>\n  \\<forall>b g. PTree.get b (genv_defs ge) = Some g \\<longrightarrow> b < (genv_next ge)\"\n\ndefinition [inv_defs']: \"genv_vars_inj ge \\<equiv>\n  \\<forall>id1 id2 b.\n  ITree.get id1 (genv_symb ge) = Some b \\<longrightarrow> ITree.get id2 (genv_symb ge) = Some b \\<longrightarrow> id1 = id2\"\n\ninductive invariants where\n  \"\\<lbrakk>genv_symb_range ge;\n    genv_defs_range ge;\n    genv_vars_inj ge\\<rbrakk> \\<Longrightarrow>\n  invariants ge\"\n\nlemmas inv_def = inv_defs' invariants.simps[simplified]\n\nsubsection \\<open>Lookup functions\\<close>\n\ncontext\n  fixes ge :: \"('f, 'v) Genv_t\"\nbegin\n\n(** [find_symbol ge id] returns the block associated with the given name, if any *)\n\nfun find_symbol :: \"ident \\<Rightarrow> (block option)\" where\n  \"find_symbol ident = ITree.get ident (genv_symb ge)\"\n\n(** [symbol_address ge id ofs] returns a pointer into the block associated\n  with [id], at byte offset [ofs].  [Vundef] is returned if no block is associated\n  to [id]. *)\n\nfun symbol_address :: \"ident \\<Rightarrow> m_ptrofs \\<Rightarrow> val\" where\n  \"symbol_address ident ofs =\n  (case find_symbol ident of\n    Some b \\<Rightarrow> Vptr b ofs\n  | None \\<Rightarrow> Vundef\n  )\"\n\n(** [public_symbol ge id] says whether the name [id] is public and defined. *)\n\nfun public_symbol :: \"ident \\<Rightarrow> bool\" where\n  \"public_symbol ident =\n  (case find_symbol ident of\n    None \\<Rightarrow> False\n  | Some _ \\<Rightarrow> ident \\<in> set (genv_public ge)\n  )\"\n\n(** [find_def ge b] returns the global definition associated with the given address. *)\n\nfun find_def :: \"block \\<Rightarrow> (('f, 'v) globdef) option\" where\n  \"find_def b = PTree.get b (genv_defs ge)\"\n\n(** [find_funct_ptr ge b] returns the function description associated with\n    the given address. *)\n\nfun find_funct_ptr :: \"block \\<Rightarrow> ('f option)\" where\n  \"find_funct_ptr b = (case find_def b of Some (Gfun f) \\<Rightarrow> Some f | _ \\<Rightarrow> None )\"\n\n(** [find_funct] is similar to [find_funct_ptr], but the function address\n    is given as a value, which must be a pointer with offset 0. *)\n\nfun find_funct :: \"val \\<Rightarrow> ('f option)\" where\n  \"find_funct v =\n  (case v of\n    Vptr b ofs \\<Rightarrow> if ofs = 0 then find_funct_ptr b else None\n  | _ \\<Rightarrow> None\n  )\"\n\n(** [invert_symbol ge b] returns the name associated with the given block, if any *)\n\n(* CompCert uses 'PTree.fold' here, which we can't because our tree doesn't have a structure *)\nfun invert_symbol :: \"block \\<Rightarrow> (ident option)\" where\n  \"invert_symbol b =\n    (if \\<exists>id. (genv_symb ge) id = Some b\n      then Some (THE id. (genv_symb ge) id = Some b)\n      else None)\"\n\n(** [find_var_info ge b] returns the information attached to the variable\n   at address [b]. *)\n\nfun find_var_info :: \"block \\<Rightarrow> (('v globvar) option)\" where\n  \"find_var_info b =\n  (case find_def b of Some (Gvar v) \\<Rightarrow> Some v | _ \\<Rightarrow> None )\"\n\n(** [block_is_volatile ge b] returns [true] if [b] points to a global variable\n  of volatile type, [false] otherwise. *)\n\nfun block_is_volatile :: \"block \\<Rightarrow> bool\" where\n  \"block_is_volatile b =\n  (case find_var_info b of\n    None \\<Rightarrow> False\n  | Some gv \\<Rightarrow> (gvar_volatile gv)\n  )\"\n\nsubsection \\<open>Constructing the global environment\\<close>\n\nfun add_global :: \"(ident * ('f, 'v) globdef) \\<Rightarrow> ('f, 'v) Genv_t\" where\n  \"add_global (ident, gdef) =\n  Genv_t.make\n    (genv_public ge)\n    (ITree.set ident (genv_next ge) (genv_symb ge))\n    (PTree.set (genv_next ge) gdef (genv_defs ge))\n    ((genv_next ge) + 1)\"\n\nend\n\nfun add_globals :: \"('f, 'v) Genv_t \\<Rightarrow> ((ident * ('f, 'v) globdef) list) \\<Rightarrow> ('f, 'v) Genv_t\" where\n  \"add_globals ge gl = List.foldl add_global ge gl\"\n\nfun empty_genv :: \"ident list \\<Rightarrow> ('f, 'v) Genv_t\" where\n  \"empty_genv pub = Genv_t.make pub ITree.empty PTree.empty 1\"\n\nfun globalenv :: \"('f, 'v) program \\<Rightarrow> ('f, 'v) Genv_t\" where\n  \"globalenv p = add_globals (empty_genv (prog_public p)) (prog_defs p)\"\n\nsubsection \\<open>Coercing a global environment into a symbol environment\\<close>\n\nfun to_senv :: \"('f, 'v) Genv_t \\<Rightarrow> Senv_t\" where\n  \"to_senv ge =\n    Senv_t.make\n    (Genv'.find_symbol ge)\n    (Genv'.public_symbol ge)\n    (Genv'.invert_symbol ge)\n    (Genv'.block_is_volatile ge)\n    (genv_next ge)\"\n\nlemma to_senv_invars:\n  assumes \"Genv'.invariants ge\"\n  shows \"Senv.invariants (to_senv ge)\"\n  using assms\n  unfolding Genv'.inv_def Senv.inv_def\n  by (auto simp add: Senv_t.defs the_equality split: option.split)\n\nsection \\<open>Construction of the initial memory state\\<close>\n\ncontext\n  fixes ge :: \"('f, 'v) Genv_t\"\nbegin\n\nfun store_init_data :: \"mem \\<Rightarrow> block \\<Rightarrow> Z \\<Rightarrow> init_data \\<Rightarrow> (mem option)\" where\n  \"store_init_data m b p ident =\n  (case ident of\n    Init_int8 n \\<Rightarrow> Mem.store Mint8unsigned m b p (Vint n)\n  | Init_int16 n \\<Rightarrow> Mem.store Mint16unsigned m b p (Vint n)\n  | Init_int32 n \\<Rightarrow> Mem.store Mint32 m b p (Vint n)\n  | Init_int64 n \\<Rightarrow> Mem.store Mint64 m b p (Vlong n)\n  | Init_float32 n \\<Rightarrow> Mem.store Mfloat32 m b p (Vsingle n)\n  | Init_float64 n \\<Rightarrow> Mem.store Mfloat64 m b p (Vfloat n)\n  | Init_addrof symb ofs \\<Rightarrow>\n      (case Genv'.find_symbol ge symb of\n        None \\<Rightarrow> None\n      | Some b' \\<Rightarrow> Mem.store Mptr m b p (Vptr b' ofs)\n      )\n  | Init_space n \\<Rightarrow> Some m\n  )\"\n\nfun store_init_data_list :: \"mem \\<Rightarrow> block \\<Rightarrow> Z \\<Rightarrow> (init_data list) \\<Rightarrow> (mem option)\" where\n  \"store_init_data_list m b p idl =\n  (case idl of\n    [] \\<Rightarrow> Some m\n  | ident # idl' \\<Rightarrow>\n      (case store_init_data m b p ident of\n        None \\<Rightarrow> None\n      | Some m' \\<Rightarrow> store_init_data_list m' b (p + init_data_size ident) idl'\n      )\n  )\"\n\nfun perm_globvar :: \"('v globvar) \\<Rightarrow> permission\" where\n  \"perm_globvar gv =\n  (if (gvar_volatile gv) then Nonempty\n  else if (gvar_readonly gv) then Readable\n  else Writable)\"\n\nfun alloc_global :: \"mem \\<Rightarrow> (ident * ('f, 'v) globdef) \\<Rightarrow> (mem option)\" where\n  \"alloc_global m idg =\n  (case idg of\n    (ident, Gfun f) \\<Rightarrow>\n      let (m1, b) = Mem.alloc m 0 1 in\n      Mem.drop_perm m1 b 0 1 Nonempty\n  | (ident, Gvar v) \\<Rightarrow>\n      let init = (gvar_init v) in\n      let sz = init_data_list_size init in\n      let (m1, b) = Mem.alloc m 0 sz in\n      (case store_zeros m1 b 0 sz of\n        None \\<Rightarrow> None\n      | Some m2 \\<Rightarrow>\n          (case store_init_data_list m2 b 0 init of\n            None \\<Rightarrow> None\n          | Some m3 \\<Rightarrow> Mem.drop_perm m3 b 0 sz (perm_globvar v)\n          )\n      )\n  )\"\n\nfun alloc_globals :: \"mem \\<Rightarrow> ((ident * ('f, 'v) globdef) list) \\<Rightarrow> (mem option)\" where\n  \"alloc_globals m gl =\n  (case gl of\n    [] \\<Rightarrow> Some m\n  | g # gl' \\<Rightarrow>\n      (case alloc_global m g of\n        None \\<Rightarrow> None\n      | Some m' \\<Rightarrow> alloc_globals m' gl'\n      )\n  )\"\nend\n\nfun init_mem :: \"('f, 'v) program \\<Rightarrow> (mem option)\" where\n  \"init_mem p = alloc_globals (Genv'.globalenv p) Mem.empty (prog_defs p)\"\n\nlemmas simps = find_symbol.simps symbol_address.simps public_symbol.simps find_def.simps\n  find_funct_ptr.simps find_funct.simps invert_symbol.simps find_var_info.simps\n  block_is_volatile.simps add_global.simps add_globals.simps empty_genv.simps globalenv.simps\n  to_senv.simps store_init_data.simps store_init_data_list.simps perm_globvar.simps\n  alloc_global.simps alloc_globals.simps init_mem.simps\n\nsection \\<open>Check invariants\\<close>\n\ncontext\n  notes [simp] = Genv'.inv_def Genv_t.defs\nbegin\n\nlemma empty_inv: \"invariants (empty_genv pub)\"\n  by auto\n\nlemma add_global_inv:\n  \"invariants ge \\<Longrightarrow> add_global ge (ident, gdef) = ge' \\<Longrightarrow> invariants ge'\"\nproof (goal_cases)\n  case 1\n\n  let ?nb = \"genv_next ge\"\n\n  {\n    fix id b\n\n    have \"ITree.get id (genv_symb ge') = Some b \\<longrightarrow> b < (genv_next ge')\"\n      apply (cases \"id = ident\")\n      using 1 pos_less_trans\n      by auto\n  }\n\n  note all = this\n\n  {\n    fix b g\n\n    have \"PTree.get b (genv_defs ge') = Some g \\<longrightarrow> b < (genv_next ge')\"\n      apply (cases \"b = ?nb\")\n      using 1 pos_less_trans\n      by auto\n  }\n\n  note all = all this\n\n  {\n    fix id1 id2 b\n\n    have \"ITree.get id1 (genv_symb ge') = Some b \\<longrightarrow> ITree.get id2 (genv_symb ge') = Some b \\<longrightarrow> id1 = id2\"\n      apply (cases \"id1 = ident\"; cases \"id2 = ident\")\n      using 1 apply auto\n      by blast+\n  }\n\n  note all = all this\n\n  then show ?case\n    by simp\nqed\n\nlemma add_globals_inv:\n  \"invariants ge \\<Longrightarrow> add_globals ge gl = ge' \\<Longrightarrow> invariants ge'\"\n  apply (induction gl arbitrary: ge ge')\n  apply simp\n  using add_global_inv\n  by (metis add_global.cases add_globals.simps foldl_Cons)\n\nlemma globalenv_inv:\n  \"invariants ge \\<Longrightarrow> globalenv p = ge' \\<Longrightarrow> invariants ge'\"\n  by (metis empty_inv add_globals_inv globalenv.simps)\n\nend\nend\n\nend", "meta": {"author": "mckirk", "repo": "Isabelle_Cminor", "sha": "76ae3d8bb8f84fefdf67f028f2db08020a79ceb1", "save_path": "github-repos/isabelle/mckirk-Isabelle_Cminor", "path": "github-repos/isabelle/mckirk-Isabelle_Cminor/Isabelle_Cminor-76ae3d8bb8f84fefdf67f028f2db08020a79ceb1/theory/compcert/Globalenvs.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5506073655352404, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.27960495277831177}}
{"text": "section \\<open>Binary compositionality theorem\\<close>\n\ntext \\<open>This theory provides the binary version of\nthe compositionality theorem for BD security.\nIt corresponds to Theorem 1 from \\<^cite>\\<open>\"cosmedis-SandP2017\"\\<close>\nand to Theorem 5 (the System Compositionality Theorem) from\n\\<^cite>\\<open>\"BDsecurity-ITP2021\"\\<close>.\n\\<close>\n\ntheory Composing_Security\n  imports Bounded_Deducibility_Security.BD_Security_TS\nbegin\n\n(* Preliminaries *)\n\n\nlemma list2_induct[case_names NilNil Cons1 Cons2]:\nassumes NN: \"P [] []\"\nand CN: \"\\<And>x xs ys. P xs ys \\<Longrightarrow> P (x # xs) ys\"\nand NC: \"\\<And>xs y ys. P xs ys \\<Longrightarrow> P xs (y # ys)\"\nshows \"P xs ys\"\nproof (induction xs)\n  case Nil show ?case using NN NC by (induction ys) auto next\n  case (Cons x xs) then show ?case using CN by auto\nqed\n\nlemma list22_induct[case_names NilNil ConsNil NilCons ConsCons]:\nassumes NN: \"P [] []\"\nand CN: \"\\<And>x xs. P xs [] \\<Longrightarrow> P (x # xs) []\"\nand NC: \"\\<And>y ys. P [] ys \\<Longrightarrow> P [] (y # ys)\"\nand CC: \"\\<And>x xs y ys.\n   P xs ys \\<Longrightarrow>\n   (\\<And> ys'. length ys' \\<le> Suc (length ys) \\<Longrightarrow> P xs ys') \\<Longrightarrow>\n   (\\<And> xs'. length xs' \\<le> Suc (length xs) \\<Longrightarrow> P xs' ys) \\<Longrightarrow>\n   P (x # xs) (y # ys)\"\nshows \"P xs ys\"\nproof (induction rule: measure_induct2[of \"\\<lambda>xs ys. length xs + length ys\", case_names IH])\n  case (IH xs ys) with assms show ?case by (cases xs; cases ys) auto\nqed\n\n\ncontext BD_Security_TS begin\n\ndeclare O_append[simp]\ndeclare V_append[simp]\ndeclare validFrom_Cons[simp]\ndeclare validFrom_append[simp]\n\ndeclare list_all_O_map[simp]\ndeclare never_O_Nil[simp]\ndeclare list_all_V_map[simp]\ndeclare never_V_Nil[simp]\n\nend (* BD_Security_NIO_Aut *)\n\n\nlocale Abstract_BD_Security_Comp =\n  One: Abstract_BD_Security validSystemTraces1 V1 O1 B1 TT1 +\n  Two: Abstract_BD_Security validSystemTraces2 V2 O2 B2 TT2 +\n  Comp?: Abstract_BD_Security validSystemTraces V O B TT (* Note: the \"Comp\" prefix will be optional *)\nfor\n   validSystemTraces1 :: \"'traces1 \\<Rightarrow> bool\"\n and\n   V1 :: \"'traces1 \\<Rightarrow> 'values1\" and O1 :: \"'traces1 \\<Rightarrow> 'observations1\"\n and\n   TT1 :: \"'traces1 \\<Rightarrow> bool\"\n and\n   B1 :: \"'values1 \\<Rightarrow> 'values1 \\<Rightarrow> bool\"\n and\n(*  *)\n   validSystemTraces2 :: \"'traces2 \\<Rightarrow> bool\"\n and\n   V2 :: \"'traces2 \\<Rightarrow> 'values2\" and O2 :: \"'traces2 \\<Rightarrow> 'observations2\"\n and\n   TT2 :: \"'traces2 \\<Rightarrow> bool\"\n and\n   B2 :: \"'values2 \\<Rightarrow> 'values2 \\<Rightarrow> bool\"\n and\n (*  *)\n   validSystemTraces :: \"'traces \\<Rightarrow> bool\"\n and\n   V :: \"'traces \\<Rightarrow> 'values\" and O :: \"'traces \\<Rightarrow> 'observations\"\n and\n   TT :: \"'traces \\<Rightarrow> bool\"\n and\n   B :: \"'values \\<Rightarrow> 'values \\<Rightarrow> bool\"\n+\nfixes\n   comp :: \"'traces1 \\<Rightarrow> 'traces2 \\<Rightarrow> 'traces \\<Rightarrow> bool\"\n and\n   compO :: \"'observations1 \\<Rightarrow> 'observations2 \\<Rightarrow> 'observations \\<Rightarrow> bool\"\n and\n   compV :: \"'values1 \\<Rightarrow> 'values2 \\<Rightarrow> 'values \\<Rightarrow> bool\"\nassumes\nvalidSystemTraces:\n\"\\<And> tr. validSystemTraces tr \\<Longrightarrow>\n (\\<exists> tr1 tr2. validSystemTraces1 tr1 \\<and> validSystemTraces2 tr2 \\<and> comp tr1 tr2 tr)\"\nand\nV_comp:\n\"\\<And> tr1 tr2 tr.\n   validSystemTraces1 tr1 \\<Longrightarrow> validSystemTraces2 tr2 \\<Longrightarrow> comp tr1 tr2 tr\n   \\<Longrightarrow> compV (V1 tr1) (V2 tr2) (V tr)\"\nand\nO_comp:\n\"\\<And> tr1 tr2 tr.\n   validSystemTraces1 tr1 \\<Longrightarrow> validSystemTraces2 tr2 \\<Longrightarrow> comp tr1 tr2 tr\n   \\<Longrightarrow> compO (O1 tr1) (O2 tr2) (O tr)\"\nand\nTT_comp:\n\"\\<And> tr1 tr2 tr.\n   validSystemTraces1 tr1 \\<Longrightarrow> validSystemTraces2 tr2 \\<Longrightarrow> comp tr1 tr2 tr\n   \\<Longrightarrow> TT tr \\<Longrightarrow> TT1 tr1 \\<and> TT2 tr2\"\nand\nB_comp:\n\"\\<And> vl1 vl2 vl vl'.\n   compV vl1 vl2 vl \\<Longrightarrow> B vl vl'\n   \\<Longrightarrow> \\<exists> vl1' vl2'. compV vl1' vl2' vl' \\<and> B1 vl1 vl1' \\<and> B2 vl2 vl2'\"\nand\nO_V_comp:\n\"\\<And> tr1 tr2 vl ol.\n   validSystemTraces1 tr1 \\<Longrightarrow> validSystemTraces2 tr2 \\<Longrightarrow>\n   compV (V1 tr1) (V2 tr2) vl \\<Longrightarrow> compO (O1 tr1) (O2 tr2) ol\n   \\<Longrightarrow> \\<exists> tr. validSystemTraces tr \\<and> O tr = ol \\<and> V tr = vl\"\nbegin\n\nabbreviation secure where \"secure \\<equiv> Comp.secure\"\nabbreviation secure1 where \"secure1 \\<equiv> One.secure\"\nabbreviation secure2 where \"secure2 \\<equiv> Two.secure\"\n\ntheorem secure1_secure2_secure:\nassumes s1: secure1 and s2: secure2\nshows secure\nunfolding secure_def proof clarify\n  fix tr vl vl'\n  assume v: \"validSystemTraces tr\" and T: \"TT tr\" and B: \"B (V tr) vl'\"\n  then obtain tr1 tr2 where v1: \"validSystemTraces1 tr1\" and v2: \"validSystemTraces2 tr2\"\n  and tr: \"comp tr1 tr2 tr\" using validSystemTraces by blast\n  have T1: \"TT1 tr1\" and T2: \"TT2 tr2\" using TT_comp[OF v1 v2 tr T] by auto\n  have Vtr: \"compV (V1 tr1) (V2 tr2) (V tr)\" using V_comp[OF v1 v2 tr] .\n  have Otr: \"compO (O1 tr1) (O2 tr2) (O tr)\" using O_comp[OF v1 v2 tr] .\n  obtain vl1' vl2' where vl': \"compV vl1' vl2' vl'\" and\n  B1: \"B1 (V1 tr1) vl1'\" and B2: \"B2 (V2 tr2) vl2'\" using B_comp[OF Vtr B] by auto\n  obtain tr1' where v1': \"validSystemTraces1 tr1'\" and O1: \"O1 tr1 = O1 tr1'\" and vl1': \"vl1' = V1 tr1'\"\n  using s1 v1 T1 B1 unfolding One.secure_def by fastforce\n  obtain tr2' where v2': \"validSystemTraces2 tr2'\" and O2: \"O2 tr2 = O2 tr2'\" and vl2': \"vl2' = V2 tr2'\"\n  using s2 v2 T2 B2 unfolding Two.secure_def by fastforce\n  obtain tr' where \"validSystemTraces tr' \\<and> O tr' = O tr \\<and> V tr' = vl'\"\n  using O_V_comp[OF v1' v2' vl'[unfolded vl1' vl2'] Otr[unfolded O1 O2]] by auto\n  thus \"\\<exists>tr'. validSystemTraces tr' \\<and> O tr' = O tr \\<and> V tr' = vl'\" by auto\nqed\n\nend (* context BD_Security_Comp *)\n\n\ntype_synonym ('state1,'state2) cstate = \"'state1 \\<times> 'state2\"\ndatatype ('state1,'trans1,'state2,'trans2) ctrans = Trans1 'state2 'trans1 | Trans2 'state1 'trans2 | CTrans 'trans1 'trans2\ndatatype ('obs1,'obs2) cobs = Obs1 'obs1 | Obs2 'obs2 | CObs 'obs1 'obs2\ndatatype ('value1,'value2) \"cvalue\" = isValue1: Value1 'value1 | isValue2: Value2 'value2 | isCValue: CValue 'value1 'value2\n\n\nlocale BD_Security_TS_Comp =\n  One: BD_Security_TS istate1 validTrans1 srcOf1 tgtOf1 \\<phi>1 f1 \\<gamma>1 g1 T1 B1 +\n  Two: BD_Security_TS istate2 validTrans2 srcOf2 tgtOf2 \\<phi>2 f2 \\<gamma>2 g2 T2 B2\nfor\n   istate1 :: \"'state1\" and validTrans1 :: \"'trans1 \\<Rightarrow> bool\"\n and\n   srcOf1 :: \"'trans1 \\<Rightarrow> 'state1\" and tgtOf1 :: \"'trans1 \\<Rightarrow> 'state1\"\n and\n   \\<phi>1 :: \"'trans1 \\<Rightarrow> bool\" and f1 :: \"'trans1 \\<Rightarrow> 'value1\"\n and\n   \\<gamma>1 :: \"'trans1 \\<Rightarrow> bool\" and g1 :: \"'trans1 \\<Rightarrow> 'obs1\"\n and\n   T1 :: \"'trans1 \\<Rightarrow> bool\" and B1 :: \"'value1 list \\<Rightarrow> 'value1 list \\<Rightarrow> bool\"\n and\n (*  *)\n   istate2 :: \"'state2\" and validTrans2 :: \"'trans2 \\<Rightarrow> bool\"\n and\n   srcOf2 :: \"'trans2 \\<Rightarrow> 'state2\" and tgtOf2 :: \"'trans2 \\<Rightarrow> 'state2\"\n and\n   \\<phi>2 :: \"'trans2 \\<Rightarrow> bool\" and f2 :: \"'trans2 \\<Rightarrow> 'value2\"\n and\n   \\<gamma>2 :: \"'trans2 \\<Rightarrow> bool\" and g2 :: \"'trans2 \\<Rightarrow> 'obs2\"\n and\n   T2 :: \"'trans2 \\<Rightarrow> bool\" and B2 :: \"'value2 list \\<Rightarrow> 'value2 list \\<Rightarrow> bool\"\n+\nfixes (* An identification of the communication transitions and of the synchronization predicate:  *)\n  isCom1 :: \"'trans1 \\<Rightarrow> bool\" and isCom2 :: \"'trans2 \\<Rightarrow> bool\"\nand\n  sync :: \"'trans1 \\<Rightarrow> 'trans2 \\<Rightarrow> bool\"\nand\n  isComV1 :: \"'value1 \\<Rightarrow> bool\" and isComV2 :: \"'value2 \\<Rightarrow> bool\"\nand\n  syncV :: \"'value1 \\<Rightarrow> 'value2 \\<Rightarrow> bool\"\nand\n  isComO1 :: \"'obs1 \\<Rightarrow> bool\" and isComO2 :: \"'obs2 \\<Rightarrow> bool\"\nand\n  syncO :: \"'obs1 \\<Rightarrow> 'obs2 \\<Rightarrow> bool\"\n(*  *)\nassumes\n  isCom1_isComV1: \"\\<And> trn1. validTrans1 trn1 \\<Longrightarrow> One.reach (srcOf1 trn1) \\<Longrightarrow> \\<phi>1 trn1 \\<Longrightarrow> isCom1 trn1 \\<longleftrightarrow> isComV1 (f1 trn1)\"\nand\n  isCom1_isComO1: \"\\<And> trn1. validTrans1 trn1 \\<Longrightarrow> One.reach (srcOf1 trn1) \\<Longrightarrow> \\<gamma>1 trn1 \\<Longrightarrow> isCom1 trn1 \\<longleftrightarrow> isComO1 (g1 trn1)\"\nand\n  isCom2_isComV2: \"\\<And> trn2. validTrans2 trn2 \\<Longrightarrow> Two.reach (srcOf2 trn2) \\<Longrightarrow> \\<phi>2 trn2 \\<Longrightarrow> isCom2 trn2 \\<longleftrightarrow> isComV2 (f2 trn2)\"\nand\n  isCom2_isComO2: \"\\<And> trn2. validTrans2 trn2 \\<Longrightarrow> Two.reach (srcOf2 trn2) \\<Longrightarrow> \\<gamma>2 trn2 \\<Longrightarrow> isCom2 trn2 \\<longleftrightarrow> isComO2 (g2 trn2)\"\nand\n  sync_syncV:\n  \"\\<And> trn1 trn2.\n       validTrans1 trn1 \\<Longrightarrow> One.reach (srcOf1 trn1) \\<Longrightarrow>\n       validTrans2 trn2 \\<Longrightarrow> Two.reach (srcOf2 trn2) \\<Longrightarrow>\n       isCom1 trn1 \\<Longrightarrow> isCom2 trn2 \\<Longrightarrow> \\<phi>1 trn1 \\<Longrightarrow> \\<phi>2 trn2 \\<Longrightarrow>\n       sync trn1 trn2 \\<Longrightarrow> syncV (f1 trn1) (f2 trn2)\"\nand\n  sync_syncO:\n  \"\\<And> trn1 trn2.\n       validTrans1 trn1 \\<Longrightarrow> One.reach (srcOf1 trn1) \\<Longrightarrow>\n       validTrans2 trn2 \\<Longrightarrow> Two.reach (srcOf2 trn2) \\<Longrightarrow>\n       isCom1 trn1 \\<Longrightarrow> isCom2 trn2 \\<Longrightarrow> \\<gamma>1 trn1 \\<Longrightarrow> \\<gamma>2 trn2 \\<Longrightarrow>\n       sync trn1 trn2 \\<Longrightarrow> syncO (g1 trn1) (g2 trn2)\"\nand\n  sync_\\<phi>1_\\<phi>2:\n  \"\\<And> trn1 trn2.\n       validTrans1 trn1 \\<Longrightarrow> One.reach (srcOf1 trn1) \\<Longrightarrow>\n       validTrans2 trn2 \\<Longrightarrow> Two.reach (srcOf2 trn2) \\<Longrightarrow>\n       isCom1 trn1 \\<Longrightarrow> isCom2 trn2 \\<Longrightarrow>\n       sync trn1 trn2 \\<Longrightarrow> \\<phi>1 trn1 \\<longleftrightarrow> \\<phi>2 trn2\"\nand\n  sync_\\<phi>_\\<gamma>:\n\"\\<And> trn1 trn2.\n     validTrans1 trn1 \\<Longrightarrow> One.reach (srcOf1 trn1) \\<Longrightarrow>\n     validTrans2 trn2 \\<Longrightarrow> Two.reach (srcOf2 trn2) \\<Longrightarrow>\n     isCom1 trn1 \\<Longrightarrow> isCom2 trn2 \\<Longrightarrow>\n     \\<gamma>1 trn1 \\<Longrightarrow> \\<gamma>2 trn2 \\<Longrightarrow>\n     syncO (g1 trn1) (g2 trn2) \\<Longrightarrow>\n     (\\<phi>1 trn1 \\<Longrightarrow> \\<phi>2 trn2 \\<Longrightarrow> syncV (f1 trn1) (f2 trn2))\n     \\<Longrightarrow>\n     sync trn1 trn2\"\nand  (* Every communication is observable (which does not mean that everything in\n       a communication is observable!): *)\n  isCom1_\\<gamma>1: \"\\<And> trn1. validTrans1 trn1 \\<Longrightarrow> One.reach (srcOf1 trn1) \\<Longrightarrow> isCom1 trn1 \\<Longrightarrow> \\<gamma>1 trn1\"\nand\n  isCom2_\\<gamma>2: \"\\<And> trn2. validTrans2 trn2 \\<Longrightarrow> Two.reach (srcOf2 trn2) \\<Longrightarrow> isCom2 trn2 \\<Longrightarrow> \\<gamma>2 trn2\"\nand (* Lack of symmetry here: all the value-producing transitions of the second component\n       need to be \"communicating\" (and hence proceed only synchronously) -- Technically, this tames shuffling...\n       This restriction means that the only component that produces secrets is the first component -- the\n       second component only receives secrets. *)\n  isCom2_V2: \"\\<And> trn2. validTrans2 trn2 \\<Longrightarrow> Two.reach (srcOf2 trn2) \\<Longrightarrow> \\<phi>2 trn2 \\<Longrightarrow> isCom2 trn2\"\nand (* Added dummy assumption about the locale data not involved in any assumption: *)\n  Dummy: \"istate1 = istate1 \\<and> srcOf1 = srcOf1 \\<and> tgtOf1 = tgtOf1 \\<and> T1 = T1 \\<and> B1 = B1 \\<and>\n          istate2 = istate2 \\<and> srcOf2 = srcOf2 \\<and> tgtOf2 = tgtOf2 \\<and> T2 = T2 \\<and> B2 = B2\"\nbegin\n\nlemma sync_\\<gamma>1_\\<gamma>2:\n \"\\<And> trn1 trn2.\n      validTrans1 trn1 \\<Longrightarrow> One.reach (srcOf1 trn1) \\<Longrightarrow>\n      validTrans2 trn2 \\<Longrightarrow> Two.reach (srcOf2 trn2) \\<Longrightarrow>\n      isCom1 trn1 \\<Longrightarrow> isCom2 trn2 \\<Longrightarrow>\n      sync trn1 trn2 \\<Longrightarrow> \\<gamma>1 trn1 \\<longleftrightarrow> \\<gamma>2 trn2\"\nusing isCom1_\\<gamma>1 isCom2_\\<gamma>2\nby auto\n\n\ndefinition icstate where \"icstate = (istate1,istate2)\"\n\nfun validTrans :: \"('state1, 'trans1, 'state2, 'trans2) ctrans \\<Rightarrow> bool\" where\n \"validTrans(Trans1 s2 trn1) = (validTrans1 trn1 \\<and> \\<not> isCom1 trn1)\"\n|\"validTrans (Trans2 s1 trn2) = (validTrans2 trn2 \\<and> \\<not> isCom2 trn2)\"\n|\"validTrans (CTrans trn1 trn2) =\n   (validTrans1 trn1 \\<and> validTrans2 trn2 \\<and> isCom1 trn1 \\<and> isCom2 trn2 \\<and> sync trn1 trn2)\"\n\nfun srcOf :: \"('state1, 'trans1, 'state2, 'trans2) ctrans \\<Rightarrow> 'state1 \\<times> 'state2\" where\n \"srcOf (Trans1 s2 trn1) = (srcOf1 trn1, s2)\"\n|\"srcOf (Trans2 s1 trn2) = (s1, srcOf2 trn2)\"\n|\"srcOf (CTrans trn1 trn2) = (srcOf1 trn1, srcOf2 trn2)\"\n\nfun tgtOf :: \"('state1, 'trans1, 'state2, 'trans2) ctrans \\<Rightarrow> 'state1 \\<times> 'state2\" where\n \"tgtOf (Trans1 s2 trn1) = (tgtOf1 trn1, s2)\"\n|\"tgtOf (Trans2 s1 trn2) = (s1, tgtOf2 trn2)\"\n|\"tgtOf (CTrans trn1 trn2) = (tgtOf1 trn1, tgtOf2 trn2)\"\n\nfun \\<phi> :: \"('state1, 'trans1, 'state2, 'trans2) ctrans \\<Rightarrow> bool\" where\n \"\\<phi> (Trans1 s2 trn1) = \\<phi>1 trn1\"\n|\"\\<phi> (Trans2 s1 trn2) = \\<phi>2 trn2\"\n|\"\\<phi> (CTrans trn1 trn2) = (\\<phi>1 trn1 \\<or> \\<phi>2 trn2)\"\n\nfun f :: \"('state1, 'trans1, 'state2, 'trans2) ctrans \\<Rightarrow> ('value1,'value2) cvalue\" where\n \"f (Trans1 s2 trn1) = Value1 (f1 trn1)\"\n|\"f (Trans2 s1 trn2) = Value2 (f2 trn2)\"\n|\"f (CTrans trn1 trn2) = CValue (f1 trn1) (f2 trn2)\"\n\nfun \\<gamma> :: \"('state1, 'trans1, 'state2, 'trans2) ctrans \\<Rightarrow> bool\" where\n \"\\<gamma> (Trans1 s2 trn1) = \\<gamma>1 trn1\"\n|\"\\<gamma> (Trans2 s1 trn2) = \\<gamma>2 trn2\"\n|\"\\<gamma> (CTrans trn1 trn2) = (\\<gamma>1 trn1 \\<or> \\<gamma>2 trn2)\"\n\nfun g :: \"('state1, 'trans1, 'state2, 'trans2) ctrans \\<Rightarrow> ('obs1,'obs2) cobs\" where\n \"g (Trans1 s2 trn1) = Obs1 (g1 trn1)\"\n|\"g (Trans2 s1 trn2) = Obs2 (g2 trn2)\"\n|\"g (CTrans trn1 trn2) = CObs (g1 trn1) (g2 trn2)\"\n\nfun T :: \"('state1, 'trans1, 'state2, 'trans2) ctrans \\<Rightarrow> bool\"\nwhere\n\"T (Trans1 s2 trn1) = T1 trn1\"\n|\n\"T (Trans2 s1 trn2) = T2 trn2\"\n|\n\"T (CTrans trn1 trn2) = (T1 trn1 \\<or> T2 trn2)\"\n\ninductive compV :: \"'value1 list \\<Rightarrow> 'value2 list \\<Rightarrow> ('value1, 'value2) cvalue list \\<Rightarrow> bool\"\nwhere\n Nil[intro!,simp]: \"compV [] [] []\"\n|Step1[intro]:\n\"compV vl1 vl2 vl \\<Longrightarrow> \\<not> isComV1 v1\n \\<Longrightarrow> compV (v1 # vl1) vl2 (Value1 v1 # vl)\"\n|Step2[intro]:\n\"compV vl1 vl2 vl \\<Longrightarrow> \\<not> isComV2 v2\n \\<Longrightarrow> compV vl1 (v2 # vl2) (Value2 v2 # vl)\"\n|Com[intro]:\n\"compV vl1 vl2 vl \\<Longrightarrow> isComV1 v1 \\<Longrightarrow> isComV2 v2 \\<Longrightarrow> syncV v1 v2\n \\<Longrightarrow> compV (v1 # vl1) (v2 # vl2) (CValue v1 v2 # vl)\"\n\nlemma compV_cases_V[consumes 3, case_names Nil Step1 Com]:\nassumes v: \"Two.validFrom s2 tr2\"\nand c: \"compV vl1 (Two.V tr2) vl\"\nand rs2: \"Two.reach s2\"\nand Nil: \"vl1 = [] \\<Longrightarrow> Two.V tr2 = [] \\<Longrightarrow> vl = [] \\<Longrightarrow> P\"\nand Step1:\n\"\\<And>vll1 vll2 vll v1.\n    vl1 = v1 # vll1 \\<Longrightarrow>\n    Two.V tr2 = vll2 \\<Longrightarrow>\n    vl = Value1 v1 # vll \\<Longrightarrow>\n    compV vll1 vll2 vll \\<Longrightarrow> \\<not> isComV1 v1 \\<Longrightarrow> P\"\nand Com:\n\"\\<And>vll1 vll2 vll v1 v2.\n    vl1 = v1 # vll1 \\<Longrightarrow>\n    Two.V tr2 = v2 # vll2 \\<Longrightarrow>\n    vl = CValue v1 v2 # vll \\<Longrightarrow>\n    compV vll1 vll2 vll \\<Longrightarrow>\n    isComV1 v1 \\<Longrightarrow> isComV2 v2 \\<Longrightarrow> syncV v1 v2 \\<Longrightarrow> P\"\nshows P\nusing c proof cases\n  case (Step2 vll2 vll1 v2)\n  obtain tr2a trn2 tr2b where tr2: \"tr2 = tr2a @ trn2 # tr2b\" and\n  \\<phi>2: \"\\<phi>2 trn2\" and f2: \"f2 trn2 = v2\"\n  using \\<open>Two.V tr2 = v2 # vll2\\<close> by (metis Two.V_eq_Cons append_Cons)\n  have v2: \"validTrans2 trn2\" using tr2 v\n  by (metis Nil_is_append_conv Two.validFrom_def Two.valid_ConsE\n          Two.valid_append list.distinct(2) self_append_conv2)\n  have rs2': \"Two.reach (srcOf2 trn2)\" using v rs2 unfolding tr2\n    by (induction tr2a arbitrary: s2) (auto intro: Two.reach.Step)\n  then have False using isCom2_V2[OF v2 rs2' \\<phi>2] \\<open>\\<not> isComV2 v2\\<close>\n  using \\<phi>2 f2 isCom2_isComV2 v2 by blast\n  thus ?thesis by simp\nqed (insert assms, auto)\n\n\ninductive compO :: \"'obs1 list \\<Rightarrow> 'obs2 list \\<Rightarrow> ('obs1, 'obs2) cobs list \\<Rightarrow> bool\"\nwhere\n Nil[intro!,simp]: \"compO [] [] []\"\n|Step1[intro]:\n\"compO ol1 ol2 ol \\<Longrightarrow> \\<not> isComO1 o1\n \\<Longrightarrow> compO (o1 # ol1) ol2 (Obs1 o1 # ol)\"\n|Step2[intro]:\n\"compO ol1 ol2 ol \\<Longrightarrow> \\<not> isComO2 o2\n \\<Longrightarrow> compO ol1 (o2 # ol2) (Obs2 o2 # ol)\"\n|Com[intro]:\n\"compO ol1 ol2 ol \\<Longrightarrow> isComO1 o1 \\<Longrightarrow> isComO2 o2 \\<Longrightarrow> syncO o1 o2\n \\<Longrightarrow> compO (o1 # ol1) (o2 # ol2) (CObs o1 o2 # ol)\"\n\ndefinition B :: \"('value1,'value2) cvalue list \\<Rightarrow> ('value1,'value2) cvalue list \\<Rightarrow> bool\" where\n\"B vl vl' \\<equiv> \\<forall> vl1 vl2. compV vl1 vl2 vl \\<longrightarrow>\n  (\\<exists> vl1' vl2'. compV vl1' vl2' vl' \\<and> B1 vl1 vl1' \\<and> B2 vl2 vl2')\"\n\ninductive ccomp ::\n\"'state1 \\<Rightarrow> 'state2 \\<Rightarrow> 'trans1 trace \\<Rightarrow> 'trans2 trace \\<Rightarrow>\n ('state1, 'trans1, 'state2, 'trans2) ctrans trace \\<Rightarrow> bool\"\nwhere\nNil[simp,intro!]: \"ccomp s1 s2 [] [] []\"\n|\nStep1[intro]:\n\"ccomp (tgtOf1 trn1) s2 tr1 tr2 tr \\<Longrightarrow> \\<not> isCom1 trn1 \\<Longrightarrow>\n ccomp (srcOf1 trn1) s2 (trn1 # tr1) tr2 (Trans1 s2 trn1 # tr)\"\n|\nStep2[intro]:\n\"ccomp s1 (tgtOf2 trn2) tr1 tr2 tr \\<Longrightarrow> \\<not> isCom2 trn2 \\<Longrightarrow>\n ccomp s1 (srcOf2 trn2) tr1 (trn2 # tr2) (Trans2 s1 trn2 # tr)\"\n|\nCom[intro]:\n\"ccomp (tgtOf1 trn1) (tgtOf2 trn2) tr1 tr2 tr \\<Longrightarrow>\n isCom1 trn1 \\<Longrightarrow> isCom2 trn2 \\<Longrightarrow> sync trn1 trn2 \\<Longrightarrow>\n ccomp (srcOf1 trn1) s2 (trn1 # tr1) (trn2 # tr2) (CTrans trn1 trn2 # tr)\"\n\n\ndefinition comp where \"comp \\<equiv> ccomp istate1 istate2\"\n\nend (* context BD_Security_TS_Comp *)\n\nsublocale BD_Security_TS_Comp \\<subseteq> BD_Security_TS icstate validTrans srcOf tgtOf \\<phi> f \\<gamma> g T B .\n\ncontext BD_Security_TS_Comp\nbegin\n\nlemma valid:\nassumes \"valid tr\" and \"srcOf (hd tr) = (s1,s2)\"\nshows\n\"\\<exists>tr1 tr2.\n   One.validFrom s1 tr1 \\<and> Two.validFrom s2 tr2 \\<and>\n   ccomp s1 s2 tr1 tr2 tr\"\nusing assms proof(induction arbitrary: s1 s2)\n  case (Singl trn)\n  show ?case proof(cases trn)\n    case (Trans1 s22 trn1)\n    show ?thesis using Singl unfolding Trans1\n    by (intro exI[of _ \"[trn1]\"] exI[of _ \"[]\"]) auto\n  next\n    case (Trans2 s11 trn2)\n    show ?thesis using Singl unfolding Trans2\n    by (intro exI[of _ \"[]::'trans1 trace\"] exI[of _ \"[trn2]\"]) auto\n  next\n    case (CTrans trn1 trn2)\n    show ?thesis using Singl unfolding CTrans\n    by (intro exI[of _ \"[trn1]\"] exI[of _ \"[trn2]\"]) auto\n  qed\nnext\n  case (Cons trn tr)\n  show ?case proof(cases trn)\n    case (Trans1 s22 trn1)\n    let ?s1 = \"tgtOf1 trn1\"\n    have s22[simp]: \"s22 = s2\" using \\<open>srcOf (hd (trn # tr)) = (s1, s2)\\<close>\n    unfolding Trans1 by simp\n    hence \"tgtOf trn = (?s1, s2)\" unfolding Trans1 by simp\n    hence \"srcOf (hd tr) = (?s1, s2)\" using Cons.hyps(2) by auto\n    from Cons.IH[OF this] obtain tr1 tr2 where\n    1: \"One.validFrom ?s1 tr1 \\<and> Two.validFrom s2 tr2 \\<and>\n        ccomp ?s1 s2 tr1 tr2 tr\" by auto\n    show ?thesis using Cons.prems Cons.hyps 1 unfolding Trans1\n    by (intro exI[of _ \"trn1 # tr1\"] exI[of _ \"tr2\"], cases tr2) auto\n  next\n    case (Trans2 s11 trn2)\n    let ?s2 = \"tgtOf2 trn2\"\n    have s11[simp]: \"s11 = s1\" using \\<open>srcOf (hd (trn # tr)) = (s1, s2)\\<close>\n    unfolding Trans2 by simp\n    hence \"tgtOf trn = (s1, ?s2)\" unfolding Trans2 by simp\n    hence \"srcOf (hd tr) = (s1, ?s2)\" using Cons.hyps(2) by auto\n    from Cons.IH[OF this] obtain tr1 tr2 where\n    1: \"One.validFrom s1 tr1 \\<and> Two.validFrom ?s2 tr2 \\<and>\n        ccomp s1 ?s2 tr1 tr2 tr\" by auto\n    show ?thesis using Cons.prems Cons.hyps 1 unfolding Trans2\n    by (intro exI[of _ \"tr1\"] exI[of _ \"trn2 # tr2\"], cases tr1) auto\n  next\n    case (CTrans trn1 trn2)\n    let ?s1 = \"tgtOf1 trn1\" let ?s2 = \"tgtOf2 trn2\"\n    have \"tgtOf trn = (?s1, ?s2)\" unfolding CTrans by simp\n    hence \"srcOf (hd tr) = (?s1, ?s2)\" using Cons.hyps(2) by auto\n    from Cons.IH[OF this] obtain tr1 tr2 where\n    1: \"One.validFrom ?s1 tr1 \\<and> Two.validFrom ?s2 tr2 \\<and>\n        ccomp ?s1 ?s2 tr1 tr2 tr\" by auto\n    show ?thesis using Cons.prems Cons.hyps 1 unfolding CTrans\n    by (intro exI[of _ \"trn1 # tr1\"] exI[of _ \"trn2 # tr2\"], cases tr2) auto\n  qed\nqed\n\nlemma validFrom:\nassumes \"validFrom icstate tr\"\nshows \"\\<exists>tr1 tr2. One.validFrom istate1 tr1 \\<and> Two.validFrom istate2 tr2 \\<and> comp tr1 tr2 tr\"\nusing assms valid unfolding comp_def icstate_def validFrom_def by(cases tr) fastforce+\n\nlemma reach_reach12:\nassumes \"reach s\"\nobtains \"One.reach (fst s)\" and \"Two.reach (snd s)\"\nusing assms proof (induction rule: reach.induct)\n  case Istate\n    then show thesis using One.reach.Istate Two.reach.Istate unfolding icstate_def by auto\nnext\n  case (Step s trn s')\n    then show thesis\n      using One.reach.Step[of \"fst s\" _ \"fst s'\"] Two.reach.Step[of \"snd s\" _ \"snd s'\"]\n      by (auto elim: validTrans.elims)\nqed\n\nlemma compV_ccomp:\nassumes v: \"One.validFrom s1 tr1\" \"Two.validFrom s2 tr2\"\nand c: \"ccomp s1 s2 tr1 tr2 tr\"\nand rs1: \"One.reach s1\" and rs2: \"Two.reach s2\"\nshows \"compV (One.V tr1) (Two.V tr2) (V tr)\"\nusing c v rs1 rs2 proof(induction)\n  case (Step1 trn1 s2 tr1 tr2 tr)\n  moreover then have \"One.reach (tgtOf1 trn1)\"\n    using One.reach.Step[of \"srcOf1 trn1\" trn1 \"tgtOf1 trn1\"] by auto\n  ultimately show ?case by (cases \"\\<phi>1 trn1\") (auto simp: isCom1_isComV1)\nnext\n  case (Step2 s1 trn2 tr1 tr2 tr)\n  moreover then have \"Two.reach (tgtOf2 trn2)\"\n    using Two.reach.Step[of \"srcOf2 trn2\" trn2 \"tgtOf2 trn2\"] by auto\n  ultimately show ?case by (cases \"\\<phi>2 trn2\") (auto simp: isCom2_isComV2)\nnext\n  case (Com trn1 trn2 tr1 tr2 tr s2)\n  moreover then have \"One.reach (tgtOf1 trn1)\" \"Two.reach (tgtOf2 trn2)\"\n    using One.reach.Step[of \"srcOf1 trn1\" trn1 \"tgtOf1 trn1\"]\n          Two.reach.Step[of \"srcOf2 trn2\" trn2 \"tgtOf2 trn2\"]\n    by auto\n  ultimately show ?case\n    by (cases \"\\<phi>1 trn1\"; cases \"\\<phi>2 trn2\"; simp add: isCom1_isComV1 isCom2_isComV2)\n       (use sync_\\<phi>1_\\<phi>2 sync_syncV Com in auto)\nqed auto\n\nlemma compV:\nassumes \"One.validFrom istate1 tr1\" and \"Two.validFrom istate2 tr2\"\nand \"comp tr1 tr2 tr\"\nshows \"compV (One.V tr1) (Two.V tr2) (V tr)\"\nusing compV_ccomp assms One.reach.Istate Two.reach.Istate unfolding comp_def by auto\n\nlemma compO_ccomp:\nassumes v: \"One.validFrom s1 tr1\" \"Two.validFrom s2 tr2\"\nand c: \"ccomp s1 s2 tr1 tr2 tr\"\nand rs1: \"One.reach s1\" and rs2: \"Two.reach s2\"\nshows \"compO (One.O tr1) (Two.O tr2) (O tr)\"\nusing c v rs1 rs2 proof(induction)\n  case (Step1 trn1 s2 tr1 tr2 tr)\n  moreover then have \"One.reach (tgtOf1 trn1)\"\n    using One.reach.Step[of \"srcOf1 trn1\" trn1 \"tgtOf1 trn1\"] by auto\n  ultimately show ?case by (cases \"\\<gamma>1 trn1\") (auto simp: isCom1_isComO1)\nnext\n  case (Step2 s1 trn2 tr1 tr2 tr)\n  moreover then have \"Two.reach (tgtOf2 trn2)\"\n    using Two.reach.Step[of \"srcOf2 trn2\" trn2 \"tgtOf2 trn2\"] by auto\n  ultimately show ?case by (cases \"\\<gamma>2 trn2\") (auto simp: isCom2_isComO2)\nnext\n  case (Com trn1 trn2 tr1 tr2 tr s2)\n  moreover then have \"One.reach (tgtOf1 trn1)\" \"Two.reach (tgtOf2 trn2)\"\n    using One.reach.Step[of \"srcOf1 trn1\" trn1 \"tgtOf1 trn1\"]\n          Two.reach.Step[of \"srcOf2 trn2\" trn2 \"tgtOf2 trn2\"]\n    by auto\n  ultimately show ?case\n    by (cases \"\\<gamma>1 trn1\"; cases \"\\<gamma>2 trn2\"; simp add: isCom1_isComO1 isCom2_isComO2)\n       (use sync_\\<gamma>1_\\<gamma>2 sync_syncO Com in auto)\nqed auto\n\nlemma compO:\nassumes \"One.validFrom istate1 tr1\" and \"Two.validFrom istate2 tr2\"\nand \"comp tr1 tr2 tr\"\nshows \"compO (One.O tr1) (Two.O tr2) (O tr)\"\nusing compO_ccomp assms One.reach.Istate Two.reach.Istate unfolding comp_def by auto\n\nlemma T_ccomp:\nassumes v: \"One.validFrom s1 tr1\" \"Two.validFrom s2 tr2\"\nand c: \"ccomp s1 s2 tr1 tr2 tr\" and n: \"never T tr\"\nshows \"never T1 tr1 \\<and> never T2 tr2\"\nusing c n v by (induction) auto\n\nlemma T:\nassumes \"One.validFrom istate1 tr1\" and \"Two.validFrom istate2 tr2\"\nand \"comp tr1 tr2 tr\" and \"never T tr\"\nshows \"never T1 tr1 \\<and> never T2 tr2\"\nusing T_ccomp assms unfolding comp_def by auto\n\nlemma B:\nassumes \"compV vl1 vl2 vl\" and \"B vl vl'\"\nshows \"\\<exists>vl1' vl2'. compV vl1' vl2' vl' \\<and> B1 vl1 vl1' \\<and> B2 vl2 vl2'\"\nusing assms unfolding B_def by auto\n\nlemma pullback_O_V_aux:\nassumes \"One.validFrom s1 tr1\" \"Two.validFrom s2 tr2\"\nand \"One.reach s1\" \"Two.reach s2\"\nand \"compV (One.V tr1) (Two.V tr2) vl\"\nand \"compO (One.O tr1) (Two.O tr2) obl\"\nshows \"\\<exists>tr. validFrom (s1,s2) tr \\<and> O tr = obl \\<and> V tr = vl\"\nusing assms proof(induction tr1 tr2 arbitrary: s1 s2 vl obl rule: list22_induct)\n  case (NilNil s1 s2 vl obl)\n  thus ?case by (intro exI[of _ \"[]\"]) (auto elim: compV.cases compO.cases)\nnext\n  case (ConsNil trn1 tr1 s1 s2 vl obl)\n  let ?s1 = \"tgtOf1 trn1\"\n  have trn1: \"validTrans1 trn1\" and tr1: \"One.validFrom ?s1 tr1\"\n  and s1: \"srcOf1 trn1 = s1\" \"One.reach s1\" and rs2: \"Two.reach s2\" using ConsNil.prems by auto\n  then have rs1': \"One.reach ?s1\" by (intro One.reach.Step[of s1 trn1 ?s1]) auto\n  show ?case proof(cases \"isCom1 trn1\")\n    case True note com1 = True\n    hence \\<gamma>1: \"\\<gamma>1 trn1\" using trn1 isCom1_\\<gamma>1 s1 by auto\n    hence \"isComO1 (g1 trn1)\" using \\<gamma>1 com1 s1 isCom1_isComO1 trn1 by blast\n    hence False using \\<open>compO (One.O (trn1 # tr1)) (Two.O []) obl\\<close>\n    using \\<gamma>1 by (auto elim: compO.cases)\n    thus ?thesis by simp\n  next\n    case False note com1 = False\n    show ?thesis proof(cases \"\\<phi>1 trn1\")\n      case True note \\<phi>1 = True\n      hence comv1: \"\\<not> isComV1 (f1 trn1)\" using \\<phi>1 com1 isCom1_isComV1 trn1 s1 by blast\n      with \\<open>compV (One.V (trn1 # tr1)) (Two.V []) vl\\<close> \\<phi>1\n      obtain vll where vl: \"vl = Value1 (f1 trn1) # vll\"\n      and vll: \"compV (One.V tr1) (Two.V []) vll\" by (auto elim: compV.cases)\n      show ?thesis proof(cases \"\\<gamma>1 trn1\")\n        case True note \\<gamma>1 = True\n        hence \"\\<not> isComO1 (g1 trn1)\" using \\<gamma>1 com1 isCom1_isComO1 trn1 s1 by blast\n        with \\<open>compO (One.O (trn1 # tr1)) (Two.O []) obl\\<close> \\<gamma>1\n        obtain obll where obl: \"obl = Obs1 (g1 trn1) # obll\"\n        and obll: \"compO (One.O tr1) (Two.O []) obll\" by (auto elim: compO.cases)\n        from ConsNil.IH[OF tr1 _ rs1' rs2 vll obll] obtain trr where\n        \"validFrom (?s1, s2) trr\" and \"O trr = obll \\<and> V trr = vll\" by auto\n        thus ?thesis\n        unfolding obl vl using trn1 com1 s1 \\<phi>1 \\<gamma>1\n        by (intro exI[of _ \"Trans1 s2 trn1 # trr\"]) auto\n      next\n        case False note \\<gamma>1 = False\n        note obl = \\<open>compO (One.O (trn1 # tr1)) (Two.O []) obl\\<close>\n        from ConsNil.IH[OF tr1 _ rs1' rs2 vll] obl \\<gamma>1 obtain trr where\n        \"validFrom (?s1, s2) trr\" and \"O trr = obl \\<and> V trr = vll\" by auto\n        thus ?thesis\n        unfolding obl vl using trn1 com1 s1 \\<phi>1 \\<gamma>1\n        by (intro exI[of _ \"Trans1 s2 trn1 # trr\"]) auto\n      qed\n    next\n      case False note \\<phi>1 = False\n      note vl = \\<open>compV (One.V (trn1 # tr1)) (Two.V []) vl\\<close>\n      show ?thesis proof(cases \"\\<gamma>1 trn1\")\n        case True note \\<gamma>1 = True\n        hence \"\\<not> isComO1 (g1 trn1)\" using \\<gamma>1 com1 isCom1_isComO1 trn1 s1 by blast\n        with \\<open>compO (One.O (trn1 # tr1)) (Two.O []) obl\\<close> \\<gamma>1\n        obtain obll where obl: \"obl = Obs1 (g1 trn1) # obll\"\n        and obll: \"compO (One.O tr1) (Two.O []) obll\" by (auto elim: compO.cases)\n        from ConsNil.IH[OF tr1 _ rs1' rs2 _ obll] vl \\<phi>1 obtain trr where\n        \"validFrom (?s1, s2) trr\" and \"O trr = obll \\<and> V trr = vl\" by auto\n        thus ?thesis\n        unfolding obl vl using trn1 com1 s1 \\<phi>1 \\<gamma>1\n        by (intro exI[of _ \"Trans1 s2 trn1 # trr\"]) auto\n      next\n        case False note \\<gamma>1 = False\n        note obl = \\<open>compO (One.O (trn1 # tr1)) (Two.O []) obl\\<close>\n        from ConsNil.IH[OF tr1 _ rs1' rs2 _] vl \\<phi>1 obl \\<gamma>1 obtain trr where\n        \"validFrom (?s1, s2) trr\" and \"O trr = obl \\<and> V trr = vl\" by fastforce\n        thus ?thesis\n        unfolding obl vl using trn1 com1 s1 \\<phi>1 \\<gamma>1\n        by (intro exI[of _ \"Trans1 s2 trn1 # trr\"]) auto\n      qed\n    qed\n  qed\nnext\n  case (NilCons trn2 tr2 s1 s2 vl obl)\n  let ?s2 = \"tgtOf2 trn2\"\n  have trn2: \"validTrans2 trn2\" and tr2: \"Two.validFrom ?s2 tr2\"\n  and s2: \"srcOf2 trn2 = s2\" \"Two.reach s2\" and rs1: \"One.reach s1\" using NilCons.prems by auto\n  then have rs2': \"Two.reach ?s2\" by (intro Two.reach.Step[of s2 trn2 ?s2]) auto\n  show ?case proof(cases \"isCom2 trn2\")\n    case True note com2 = True\n    hence \\<gamma>2: \"\\<gamma>2 trn2\" using trn2 isCom2_\\<gamma>2 s2 by auto\n    hence \"isComO2 (g2 trn2)\" using \\<gamma>2 com2 isCom2_isComO2 trn2 s2 by blast\n    hence False using \\<open>compO (One.O []) (Two.O (trn2 # tr2)) obl\\<close>\n    using \\<gamma>2 by (auto elim: compO.cases)\n    thus ?thesis by simp\n  next\n    case False note com2 = False\n    show ?thesis proof(cases \"\\<phi>2 trn2\")\n      case True note \\<phi>2 = True\n      hence comv1: \"\\<not> isComV2 (f2 trn2)\" using \\<phi>2 com2 isCom2_isComV2 trn2 s2 by blast\n      with \\<open>compV (One.V []) (Two.V (trn2 # tr2)) vl\\<close> \\<phi>2\n      obtain vll where vl: \"vl = Value2 (f2 trn2) # vll\"\n      and vll: \"compV (One.V []) (Two.V tr2) vll\" by (auto elim: compV.cases)\n      show ?thesis proof(cases \"\\<gamma>2 trn2\")\n        case True note \\<gamma>2 = True\n        hence \"\\<not> isComO2 (g2 trn2)\" using \\<gamma>2 com2 isCom2_isComO2 trn2 s2 by blast\n        with \\<open>compO (One.O []) (Two.O (trn2 # tr2)) obl\\<close> \\<gamma>2\n        obtain obll where obl: \"obl = Obs2 (g2 trn2) # obll\"\n        and obll: \"compO (One.O []) (Two.O tr2) obll\" by (auto elim: compO.cases)\n        from NilCons.IH[OF _ tr2 rs1 rs2' vll obll] obtain trr where\n        \"validFrom (s1, ?s2) trr\" and \"O trr = obll \\<and> V trr = vll\" by auto\n        thus ?thesis\n        unfolding obl vl using trn2 com2 s2 \\<phi>2 \\<gamma>2\n        by (intro exI[of _ \"Trans2 s1 trn2 # trr\"]) auto\n      next\n        case False note \\<gamma>2 = False\n        note obl = \\<open>compO (One.O []) (Two.O (trn2 # tr2)) obl\\<close>\n        from NilCons.IH[OF _ tr2 rs1 rs2' vll] obl \\<gamma>2 obtain trr where\n        \"validFrom (s1, ?s2) trr\" and \"O trr = obl \\<and> V trr = vll\" by auto\n        thus ?thesis\n        unfolding obl vl using trn2 com2 s2 \\<phi>2 \\<gamma>2\n        by (intro exI[of _ \"Trans2 s1 trn2 # trr\"]) auto\n      qed\n    next\n      case False note \\<phi>2 = False\n      note vl = \\<open>compV (One.V []) (Two.V (trn2 # tr2)) vl\\<close>\n      show ?thesis proof(cases \"\\<gamma>2 trn2\")\n        case True note \\<gamma>2 = True\n        hence \"\\<not> isComO2 (g2 trn2)\" using \\<gamma>2 com2 isCom2_isComO2 trn2 s2 by blast\n        with \\<open>compO (One.O []) (Two.O (trn2 # tr2)) obl\\<close> \\<gamma>2\n        obtain obll where obl: \"obl = Obs2 (g2 trn2) # obll\"\n        and obll: \"compO (One.O []) (Two.O tr2) obll\" by (auto elim: compO.cases)\n        from NilCons.IH[OF _ tr2 rs1 rs2' _ obll] vl \\<phi>2 obtain trr where\n        \"validFrom (s1, ?s2) trr\" and \"O trr = obll \\<and> V trr = vl\" by auto\n        thus ?thesis\n        unfolding obl vl using trn2 com2 s2 \\<phi>2 \\<gamma>2\n        by (intro exI[of _ \"Trans2 s1 trn2 # trr\"]) auto\n      next\n        case False note \\<gamma>2 = False\n        note obl = \\<open>compO (One.O []) (Two.O (trn2 # tr2)) obl\\<close>\n        from NilCons.IH[OF _ tr2 rs1 rs2' _] vl \\<phi>2 obl \\<gamma>2 obtain trr where\n        \"validFrom (s1, ?s2) trr\" and \"O trr = obl \\<and> V trr = vl\" by fastforce\n        thus ?thesis\n        unfolding obl vl using trn2 com2 s2 \\<phi>2 \\<gamma>2\n        by (intro exI[of _ \"Trans2 s1 trn2 # trr\"]) auto\n      qed\n    qed\n  qed\nnext\n  case (ConsCons trn1 tr1 trn2 tr2 s1 s2 vl obl)\n  let ?s1 = \"tgtOf1 trn1\"  let ?s2 = \"tgtOf2 trn2\"\n  let ?tr1 = \"trn1 # tr1\" let ?tr2 = \"trn2 # tr2\"\n  have trn1: \"validTrans1 trn1\" and tr1: \"One.validFrom ?s1 tr1\" and s1: \"srcOf1 trn1 = s1\" \"One.reach s1\"\n  and trn2: \"validTrans2 trn2\" and tr2: \"Two.validFrom ?s2 tr2\" and s2: \"srcOf2 trn2 = s2\" \"Two.reach s2\"\n  using ConsCons.prems by auto\n  then have rs1': \"One.reach ?s1\" and rs2': \"Two.reach ?s2\"\n    using One.reach.Step[of s1 trn1 ?s1] Two.reach.Step[of s2 trn2 ?s2] by auto\n  note vl = \\<open>compV (One.V ?tr1) (Two.V ?tr2) vl\\<close>\n  note obl = \\<open>compO (One.O ?tr1) (Two.O ?tr2) obl\\<close>\n  note trr1 = \\<open>One.validFrom s1 ?tr1\\<close> note trr2 = \\<open>Two.validFrom s2 ?tr2\\<close>\n  show ?case proof(cases \"\\<phi>1 trn1 \\<or> \\<gamma>1 trn1\")\n    case False note \\<phi>\\<gamma>1 = False\n    hence com1: \"\\<not> isCom1 trn1\" using isCom1_\\<gamma>1 trn1 s1 by blast\n    from ConsCons.IH(2)[of ?tr2, OF _ tr1 trr2 rs1' s2(2)] vl obl \\<phi>\\<gamma>1\n    obtain trr where \"validFrom (?s1, s2) trr\" and \"O trr = obl \\<and> V trr = vl\"\n    by fastforce\n    thus ?thesis\n    unfolding obl vl using trn1 com1 s1 \\<phi>\\<gamma>1\n    by (intro exI[of _ \"Trans1 s2 trn1 # trr\"]) auto\n  next\n    case True note \\<phi>\\<gamma>1 = True\n    show ?thesis proof(cases \"\\<phi>2 trn2 \\<or> \\<gamma>2 trn2\")\n      case False note \\<phi>\\<gamma>2 = False\n      hence com2: \"\\<not> isCom2 trn2\" using isCom2_\\<gamma>2 trn2 s2 by blast\n      from ConsCons.IH(3)[of ?tr1, OF _ trr1 tr2 s1(2) rs2'] vl obl \\<phi>\\<gamma>2\n      obtain trr where \"validFrom (s1, ?s2) trr\" and \"O trr = obl \\<and> V trr = vl\"\n      by fastforce\n      thus ?thesis\n      unfolding obl vl using trn2 com2 s2 \\<phi>\\<gamma>2\n      by (intro exI[of _ \"Trans2 s1 trn2 # trr\"]) auto\n    next\n      case True note \\<phi>\\<gamma>2 = True\n      show ?thesis using obl ConsCons proof cases\n        case Nil hence \\<gamma>12: \"\\<not> \\<gamma>1 trn1 \\<and> \\<not> \\<gamma>2 trn2\" by auto\n        hence obl: \"compO (One.O tr1) (Two.O ?tr2) obl\"\n                   \"compO (One.O tr1) (Two.O tr2) obl\"\n        using obl by auto\n        have \\<phi>12: \"\\<phi>1 trn1 \\<and> \\<phi>2 trn2\" using \\<phi>\\<gamma>1 \\<phi>\\<gamma>2 \\<gamma>12 by auto\n        show ?thesis using trr2 vl s2(2) proof(cases rule: compV_cases_V)\n          case Nil hence False using \\<phi>12 by auto\n          thus ?thesis by simp\n        next\n          case (Step1 vll1 vll2 vll v1)\n          hence f1: \"f1 trn1 = v1\" and vll1: \"One.V tr1 = vll1\" using \\<phi>12 by auto\n          hence vll: \"compV (One.V tr1) (Two.V ?tr2) vll\" using Step1 by auto\n          from ConsCons.IH(2)[OF _ tr1 trr2 rs1' s2(2) vll obl(1)]\n          obtain trr where \"validFrom (?s1, s2) trr\" and \"O trr = obl \\<and> V trr = vll\"\n          by auto\n          thus ?thesis using trn1 Step1 f1 \\<phi>12 \\<gamma>12 isCom2_V2 isCom2_\\<gamma>2 trn2 s2\n          by (intro exI[of _ \"Trans1 s2 trn1 # trr\"]) auto\n        next\n          case (Com vll1 vll2 vll v1 v2)\n          hence f1: \"f1 trn1 = v1\" and vll1: \"One.V tr1 = vll1\"\n          and f2: \"f2 trn2 = v2\" and vll2: \"Two.V tr2 = vll2\"\n          using \\<phi>12 by auto\n          hence vll: \"compV (One.V tr1) (Two.V tr2) vll\" using Com by auto\n          from ConsCons.IH(1)[OF tr1 tr2 rs1' rs2' vll obl(2)]\n          obtain trr where \"validFrom (?s1, ?s2) trr\" and \"O trr = obl \\<and> V trr = vll\"\n          by auto\n          thus ?thesis using trn1 Step1 f1 \\<phi>12 \\<gamma>12 isCom2_V2 isCom2_\\<gamma>2 trn2 s2\n          by (intro exI[of _ \"Trans1 s2 trn1 # trr\"]) auto\n        qed\n      next\n        case (Step1 obll1 obll ob1) note Step1O = Step1\n        show ?thesis proof(cases \"\\<gamma>1 trn1\")\n          case True note \\<gamma>1 = True\n          hence g1: \"g1 trn1 = ob1\" and \"obll1 = One.O tr1\" using Step1 by auto\n          hence obll: \"compO (One.O tr1) (Two.O ?tr2) obll\" using Step1 by auto\n          have com1: \"\\<not> isCom1 trn1\" using Step1O \\<gamma>1 g1 isCom1_isComO1 trn1 s1 by blast\n          show ?thesis using trr2 vl s2(2) proof(cases rule: compV_cases_V)\n            case Nil\n            hence \\<phi>12: \"\\<not> \\<phi>1 trn1 \\<and> \\<not> \\<phi>2 trn2\" by auto\n            hence vl: \"compV (One.V tr1) (Two.V ?tr2) vl\" using vl by auto\n            from ConsCons.IH(2)[OF _ tr1 trr2 rs1' s2(2) vl obll]\n            obtain trr where \"validFrom (?s1, s2) trr\" and \"O trr = obll \\<and> V trr = vl\"\n            by auto\n            thus ?thesis using trn1 Step1O g1 \\<phi>12 \\<gamma>1 trn1 s1 isCom1_isComO1\n            by (intro exI[of _ \"Trans1 s2 trn1 # trr\"]) auto\n          next\n            case (Step1 vll1 vll2 vll v1) note Step1V = Step1\n            show ?thesis proof(cases \"\\<phi>1 trn1\")\n              case False note \\<phi>1 = False\n              hence vl: \"compV (One.V tr1) (Two.V ?tr2) vl\" using vl by auto\n              from ConsCons.IH(2)[OF _ tr1 trr2 rs1' s2(2) vl obll]\n              obtain trr where \"validFrom (?s1, s2) trr\" and \"O trr = obll \\<and> V trr = vl\"\n              by auto\n              thus ?thesis using trn1 Step1O g1 \\<phi>1 \\<gamma>1 trn1 s1 isCom1_isComO1\n              by (intro exI[of _ \"Trans1 s2 trn1 # trr\"]) auto\n            next\n              case True note \\<phi>1 = True\n              hence f1: \"f1 trn1 = v1\" and \"vll1 = One.V tr1\" using Step1V by auto\n              hence vll: \"compV (One.V tr1) (Two.V ?tr2) vll\" using Step1V com1 by auto\n              from ConsCons.IH(2)[OF _ tr1 trr2 rs1' s2(2) vll obll]\n              obtain trr where \"validFrom (?s1, s2) trr\" and \"O trr = obll \\<and> V trr = vll\"\n              by auto\n              thus ?thesis using trn1 Step1O Step1V f1 \\<phi>1 g1 \\<phi>1 \\<gamma>1 trn1 s1 isCom1_isComO1\n              by (intro exI[of _ \"Trans1 s2 trn1 # trr\"]) auto\n            qed\n          next\n            case (Com vll1 vll2 vll v1 v2)\n            hence \\<phi>1: \"\\<not> \\<phi>1 trn1\" using com1 isCom1_isComV1[OF trn1] s1 by auto\n            hence vl: \"compV (One.V tr1) (Two.V ?tr2) vl\" using vl by auto\n            from ConsCons.IH(2)[OF _ tr1 trr2 rs1' s2(2) vl obll]\n            obtain trr where \"validFrom (?s1, s2) trr\" and \"O trr = obll \\<and> V trr = vl\"\n            by auto\n            thus ?thesis using trn1 Step1O g1 \\<phi>1 \\<gamma>1 trn1 s1 isCom1_isComO1\n            by (intro exI[of _ \"Trans1 s2 trn1 # trr\"]) auto\n          qed\n        next\n          case False note \\<gamma>1 = False\n          hence obl: \"compO (One.O tr1) (Two.O ?tr2) obl\" using obl by simp\n          hence \\<phi>1: \"\\<phi>1 trn1\" and com1: \"\\<not> isCom1 trn1\" using \\<phi>\\<gamma>1 \\<gamma>1 isCom1_\\<gamma>1 trn1 s1 by auto\n          show ?thesis using trr2 vl s2(2) proof(cases rule: compV_cases_V)\n            case Nil hence False using \\<phi>1 by auto\n            thus ?thesis by simp\n          next\n            case Com hence False using \\<phi>1 com1 trn1 using isCom1_isComV1 s1 by auto\n            thus ?thesis by simp\n          next\n            case (Step1 vll1 vll2 vll v1) note Step1V = Step1\n            hence f1: \"f1 trn1 = v1\" and \"vll1 = One.V tr1\" using \\<phi>1 by auto\n            hence vll: \"compV (One.V tr1) (Two.V ?tr2) vll\" using Step1V com1 by auto\n            from ConsCons.IH(2)[OF _ tr1 trr2 rs1' s2(2) vll obl]\n            obtain trr where \"validFrom (?s1, s2) trr\" and \"O trr = obl \\<and> V trr = vll\"\n            by auto\n            thus ?thesis using trn1 Step1O Step1V f1 \\<phi>1 \\<phi>1 \\<gamma>1 trn1 s1 isCom1_isComV1\n            by(intro exI[of _ \"Trans1 s2 trn1 # trr\"]) auto\n          qed\n        qed\n      next\n        case (Step2 obl2 obll ob2) note Step2O = Step2\n        hence com2: \"\\<not> isCom2 trn2\" using isCom2_\\<gamma>2[OF trn2] isCom2_isComO2[OF trn2] s2 by auto\n        hence \\<phi>2: \"\\<not> \\<phi>2 trn2\" using isCom2_V2[OF trn2] s2 by auto\n        hence vl: \"compV (One.V ?tr1) (Two.V tr2) vl\" using vl by simp\n        have \\<gamma>2: \"\\<gamma>2 trn2\" using \\<phi>\\<gamma>2 \\<phi>2 by simp\n        hence g2: \"g2 trn2 = ob2\" and \"obl2 = Two.O tr2\" using Step2 by auto\n        hence obll: \"compO (One.O ?tr1) (Two.O tr2) obll\" using Step2 by auto\n        from ConsCons.IH(3)[OF _ trr1 tr2 s1(2) rs2' vl obll]\n        obtain trr where \"validFrom (s1, ?s2) trr\" and \"O trr = obll \\<and> V trr = vl\" by auto\n        thus ?thesis using trn1 Step2O g2 \\<phi>2 \\<gamma>2 trn2 s2 isCom2_isComO2\n        by (intro exI[of _ \"Trans2 s1 trn2 # trr\"]) auto\n      next\n        case (Com obll1 obll2 obll ob1 ob2) note ComO = Com\n        show ?thesis\n        proof(cases \"\\<gamma>1 trn1\")\n          case True note \\<gamma>1 = True\n          hence com1: \"isCom1 trn1\" using isCom1_isComO1[OF trn1] s1 ComO by auto\n          show ?thesis proof(cases \"\\<gamma>2 trn2\")\n            case True note \\<gamma>2 = True\n            hence com2: \"isCom2 trn2\" using isCom2_isComO2[OF trn2] s2 ComO by auto\n            have obll: \"compO (One.O tr1) (Two.O tr2) obll\" using obl ComO \\<gamma>1 \\<gamma>2 by auto\n            have g1: \"g1 trn1 = ob1\" and \"obll1 = One.O tr1\" and\n                 g2: \"g2 trn2 = ob2\" and \"obll2 = Two.O tr2\"\n            using \\<gamma>1 \\<gamma>2 ComO by auto\n            have rs1: \"One.reach (srcOf1 trn1)\" and rs2: \"Two.reach (srcOf2 trn2)\"\n              using s1 s2 by auto\n            have sync: \"sync trn1 trn2\" proof(rule sync_\\<phi>_\\<gamma>[OF trn1 rs1 trn2 rs2 com1 com2])\n              show \"syncO (g1 trn1) (g2 trn2)\" using Com \\<gamma>1 \\<gamma>2 by auto\n            next\n              assume \\<phi>12: \"\\<phi>1 trn1\" \"\\<phi>2 trn2\"\n              hence comV: \"isComV1 (f1 trn1) \\<and> isComV2 (f2 trn2)\"\n              using com1 com2 isCom1_isComV1 isCom2_isComV2 trn1 trn2 rs1 rs2 by blast\n              show \"syncV (f1 trn1) (f2 trn2)\" using vl \\<phi>12 comV by cases auto\n            qed(insert \\<gamma>1 \\<gamma>2, auto)\n            show ?thesis\n            proof(cases \"\\<phi>1 trn1\")\n              case True\n              hence \\<phi>12: \"\\<phi>1 trn1 \\<and> \\<phi>2 trn2\" using sync_\\<phi>1_\\<phi>2[OF trn1 rs1 trn2 rs2 com1 com2 sync] by simp\n              show ?thesis using trr2 vl s2(2) proof(cases rule: compV_cases_V)\n                case Nil hence False using \\<phi>12 by auto\n                thus ?thesis by simp\n              next\n                case Step1 hence False using \\<phi>12 com1 isCom1_isComV1[OF trn1] s1 by auto\n                thus ?thesis by simp\n              next\n                case (Com vll1 vll2 vll v1 v2) note ComV = Com\n                hence f1: \"f1 trn1 = v1\" and \"vll1 = One.V tr1\" and\n                      f2: \"f2 trn2 = v2\" and \"vll2 = Two.V tr2\"\n                using \\<phi>12 by auto\n                hence vll: \"compV (One.V tr1) (Two.V tr2) vll\" using ComV com1 com2 \\<phi>12 by auto\n                from ConsCons.IH(1)[OF tr1 tr2 rs1' rs2' vll obll]\n                obtain trr where \"validFrom (?s1, ?s2) trr\" and \"O trr = obll \\<and> V trr = vll\"\n                by auto\n                thus ?thesis using trn1 trn2 ComO ComV f1 f2 \\<phi>12 g1 g2 \\<gamma>1 \\<gamma>2 com1 com2 sync s1 s2\n                by (intro exI[of _ \"CTrans trn1 trn2 # trr\"]) auto\n              qed\n            next\n              case False\n              hence \\<phi>12: \"\\<not> \\<phi>1 trn1 \\<and> \\<not> \\<phi>2 trn2\" using sync_\\<phi>1_\\<phi>2[OF trn1 rs1 trn2 rs2 com1 com2 sync] by simp\n              hence vl: \"compV (One.V tr1) (Two.V tr2) vl\" using vl by simp\n              from ConsCons.IH(1)[OF tr1 tr2 rs1' rs2' vl obll]\n              obtain trr where \"validFrom (?s1, ?s2) trr\" and \"O trr = obll \\<and> V trr = vl\" by auto\n              thus ?thesis using trn1 trn2 ComO \\<phi>12 g1 g2 \\<gamma>1 \\<gamma>2 com1 com2 sync s1 s2\n              by (intro exI[of _ \"CTrans trn1 trn2 # trr\"]) auto\n            qed\n          next\n            case False\n            hence \\<phi>2: \"\\<phi>2 trn2\" and com2: \"\\<not> isCom2 trn2\" using \\<phi>\\<gamma>2 isCom2_\\<gamma>2 trn2 s2 by auto\n            have False using trr2 vl s2(2) \\<phi>2 com2 isCom2_V2[OF trn2] s2 by (cases rule: compV_cases_V) auto\n            thus ?thesis by simp\n          qed\n        next\n          case False note \\<gamma>1 = False\n          hence obl: \"compO (One.O tr1) (Two.O ?tr2) obl\" using obl by simp\n          have \\<phi>1: \"\\<phi>1 trn1\" and com1: \"\\<not> isCom1 trn1\" using \\<gamma>1 \\<phi>\\<gamma>1 isCom1_\\<gamma>1 trn1 s1 by auto\n          show ?thesis using trr2 vl s2(2) proof(cases rule: compV_cases_V)\n            case Nil hence False using \\<phi>1 by auto\n            thus ?thesis by simp\n          next\n            case Com hence False using com1 \\<phi>1 isCom1_isComV1[OF trn1] s1 by auto\n            thus ?thesis by simp\n          next\n            case (Step1 vll1 vll2 vll v1) note Step1V = Step1\n            hence f1: \"f1 trn1 = v1\" and \"vll1 = One.V tr1\" using \\<phi>1 by auto\n            hence vll: \"compV (One.V tr1) (Two.V ?tr2) vll\" using Step1V com1 by auto\n            from ConsCons.IH(2)[OF _ tr1 trr2 rs1' s2(2) vll obl]\n            obtain trr where \"validFrom (?s1, s2) trr\" and \"O trr = obl \\<and> V trr = vll\"\n            by auto\n            thus ?thesis using trn1 Step1V f1 \\<phi>1 \\<gamma>1 trn1 s1 isCom1_isComO1 com1\n            by (intro exI[of _ \"Trans1 s2 trn1 # trr\"]) auto\n          qed\n        qed\n      qed\n    qed\n  qed\nqed\n\n\n\n\nlemma pullback_O_V:\nassumes \"One.validFrom istate1 tr1\" and \"Two.validFrom istate2 tr2\"\nand \"compV (One.V tr1) (Two.V tr2) vl\"\nand \"compO (One.O tr1) (Two.O tr2) ol\"\nshows \"\\<exists>tr. validFrom icstate tr \\<and> O tr = ol \\<and> V tr = vl\"\nusing assms pullback_O_V_aux One.reach.Istate Two.reach.Istate unfolding icstate_def by auto\n\nend (* context BD_Security_TS_Comp *)\n\n\nsublocale BD_Security_TS_Comp \\<subseteq> K? : Abstract_BD_Security_Comp where\n  validSystemTraces1 = \"One.validFrom istate1\" and V1 = One.V and O1 = One.O\n   and TT1 = \"never T1\" and B1 = B1 and\n  validSystemTraces2 = \"Two.validFrom istate2\" and V2 = Two.V and O2 = Two.O\n   and TT2 = \"never T2\" and B2 = B2 and\n  validSystemTraces = \"validFrom icstate\" and V = V and O = O\n   and TT = \"never T\" and B = B and\n   comp = comp and compO = compO and compV = compV\n  apply standard\n  subgoal using validFrom by fastforce\n  subgoal using compV by fastforce\n  subgoal using compO by fastforce\n  subgoal using T by fastforce\n  subgoal using B by fastforce\n  subgoal using pullback_O_V by fastforce\n  done\n\n\ncontext BD_Security_TS_Comp begin\n\n(* Just contemplating the theorem provided as a\nconsequence of the sublocale inclusion: *)\ntheorem \"secure1 \\<Longrightarrow> secure2 \\<Longrightarrow> secure\"\nusing secure1_secure2_secure .\n\nend (* context BD_Security_TS_Comp *)\n\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/BD_Security_Compositional/Composing_Security.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5506073655352403, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.2796049527783117}}
{"text": "theory MP_AbstractLock\n  imports Main AbstractLock_Proof_Rules OpSem_Proof_Rules\nbegin\ndatatype PC =\n  L1\n| L2\n| L3\n| L4\n| L5\n\n\n\nconsts t1 :: T \nconsts t2 :: T\nconsts d1 :: L\nconsts d2 :: L\nconsts l :: L\n\n\ndefinition \"thrdsvars \\<equiv>  t1 \\<noteq> t2 \\<and> d1 \\<noteq> d2\"\n\n\nrecord prog_state =\n  pc :: \"T \\<Rightarrow> PC\"\n  state :: surrey_state\n  lstate :: lib_state\n  r :: V\n  r2 :: V\n  loc1 :: bool\n  loc2 :: bool\n  rel1 :: bool\n  rel2 :: bool\n  ver1 :: V\n  ver2 :: V\n\ndefinition \n  \"update_pc t nv pcf \\<equiv> pcf (t := nv)\"\n\n\ndefinition prog :: \"T \\<Rightarrow> prog_state \\<Rightarrow> prog_state  \\<Rightarrow> bool \" where\n\"prog t s s' \\<equiv> \n(\nif t = t1\nthen\nif (pc s) t = L1\nthen\n     [(state s) (lstate s) t LOCKACQ(l) (state s') (lstate s') (loc1 s') (ver1 s')]\n     \\<and> (loc1 s' \\<longrightarrow> pc s' = update_pc t L2 (pc s))\n     \\<and> (\\<not> loc1 s' \\<longrightarrow> pc s' = pc s)  \n     \\<and> (r s' = r s)\n     \\<and> (r2 s' = r2 s)\n     \\<and> (rel1 s' = rel1 s)  \n     \\<and> (rel2 s' = rel2 s) \n     \\<and> (loc2 s' = loc2 s)\n     \\<and> (ver2 s' = ver2 s)\nelse\nif (pc s) t = L2\nthen \n    (state s) [d1 := 5]\\<^sub>t (state s')\n    \\<and> pc s' = update_pc t L3 (pc s)\n    \\<and> (lstate s = lstate s')\n    \\<and> (r s = r s')\n    \\<and> (rel1 s' = rel1 s)\n    \\<and> (rel2 s' = rel2 s) \n    \\<and> (loc2 s' = loc2 s)\n    \\<and> (loc1 s' = loc1 s)\n    \\<and> (ver2 s' = ver2 s)\nelse\nif (pc s) t = L3\nthen \n    (state s) [d2 := 5]\\<^sub>t (state s')\n    \\<and> pc s' = update_pc t L4 (pc s)\n    \\<and> (lstate s = lstate s')\n    \\<and> (r s = r s')\n    \\<and> (rel1 s' = rel1 s)\n    \\<and> (rel2 s' = rel2 s) \n    \\<and> (loc2 s' = loc2 s)\n    \\<and> (loc1 s' = loc1 s)\n    \\<and> (ver2 s' = ver2 s)\nelse\nif (pc s) t = L4\nthen \n    [(state s) (lstate s) t LOCKREL(l) (lstate s') (state s')] \n     \\<and> pc s' =  update_pc t L5 (pc s)\n     \\<and> (state s = state s')\n     \\<and> (r s = r s')\n     \\<and> (loc1 s' = loc1 s) \n     \\<and> (loc2 s' = loc2 s)\n     \\<and> (rel2 s' = rel2 s)\n     \\<and> (rel1 s' = True)\n     \\<and> (ver2 s' = ver2 s)\nelse\nFalse\nelse\n\nif t = t2\nthen\nif (pc s) t = L1\nthen\n     [(state s) (lstate s) t LOCKACQ(l) (state s') (lstate s') (loc2 s')  (ver2 s')]\n     \\<and> (loc2 s' = True \\<longrightarrow> pc s' = update_pc t L2 (pc s))\n     \\<and> (loc2 s' = False \\<longrightarrow> pc s' = pc s) \\<and> (r s = r s') \\<and> (r2 s = r2 s')\n     \\<and> (rel1 s' = rel1 s)  \\<and> (rel2 s' = rel2 s) \\<and> (loc1 s = loc1 s')\nelse\nif (pc s) t = L2\nthen \n    (state s) [r s' \\<leftarrow> d1]\\<^sub>t (state s')\n    \\<and> pc s' = update_pc t L3 (pc s)\n    \\<and> (lstate s = lstate s')\n    \\<and> (rel1 s' = rel1 s)  \\<and> (rel2 s' = rel2 s)\n    \\<and> (loc2 s = loc2 s') \\<and>  (loc1 s = loc1 s')\n    \\<and> (ver2 s' = ver2 s)\nelse\nif (pc s) t = L3\nthen \n    (state s) [r2 s' \\<leftarrow> d2]\\<^sub>t (state s')\n    \\<and> pc s' = update_pc t L4 (pc s)\n    \\<and> (lstate s = lstate s')\n    \\<and> (rel1 s' = rel1 s)  \\<and> (rel2 s' = rel2 s)\n    \\<and> (loc2 s = loc2 s') \\<and>  (loc1 s = loc1 s') \\<and> (r s = r s')\n    \\<and> (ver2 s' = ver2 s)\nelse\nif (pc s) t = L4\nthen \n    [(state s) (lstate s) t LOCKREL(l) (lstate s') (state s')] \n     \\<and> pc s' =   update_pc t L5 (pc s) \\<and>\n    (state s = state s') \\<and> (r s = r s')\n    \\<and> (loc2 s' = loc2 s) \\<and> (loc1 s' = loc1 s) \n    \\<and> (rel1 s' = rel1 s)  \\<and> (rel2 s' = True) \\<and> (r s = r s')\n    \\<and> (ver2 s' = ver2 s)\nelse\nFalse\nelse\nFalse\n)\n\"\n\ndefinition \"mutex s \\<equiv> (rel1 s \\<longrightarrow> loc1 s) \\<and>\n                      (rel2 s \\<longrightarrow> loc2 s) \\<and>\n                      \\<not> ((loc1 s \\<and> \\<not>rel1 s) \\<and> (loc2 s \\<and> \\<not>rel2 s))\"\n\n(* need to add that ver2 s = 0 \\<or> ver2 s = 2 *)\ndefinition \"global_inv s \\<equiv> (wfs (state s)) \\<and> (lib_wfs (lstate s) (state s)) \\<and> thrdsvars \\<and> mutex s \"\n\ndefinition \"init_state s \\<equiv> thrdsvars \\<and> (wfs (state s)) \\<and>  (lib_wfs (lstate s) (state s)) \\<and> ([lib(l) =\\<^sub>t1 0] (lstate s)) \\<and> ([lib(l) =\\<^sub>t2 0] (lstate s))\n                  \\<and> ([d1 =\\<^sub>t1 0] (state s)) \\<and> ([d1 =\\<^sub>t2 0] (state s))  \n                  \\<and> ([d2 =\\<^sub>t1 0] (state s)) \\<and> ([d2 =\\<^sub>t2 0] (state s))  \n                  \\<and> (loc1 s = False) \\<and> (loc2 s = False) \n                  \\<and> (rel1 s = False) \\<and> (rel2 s = False) \\<and> (r s = 0)\n                  \\<and>  cvd[lib(l), 0] (lstate s)\"\n\n\ndefinition \"prog_inv t p s \\<equiv> \n  global_inv s \\<and>\n  (if t = t1 \n  then\n    let t' = t2 in \n    (case p of\n          L1 \\<Rightarrow>  (\\<not>rel1 s)  \\<and> (\\<not>loc1 s) \n                \\<and> ([d1 =\\<^sub>t 0] (state s))\n                \\<and> ([d2 =\\<^sub>t 0] (state s))\n                \\<and> (\\<not>loc2 s \\<longrightarrow> ([lib(l) =\\<^sub>t 0] (lstate s)) \\<and> (\\<not>[lib(l) \\<approx>\\<^sub>t' 2] (lstate s)))\n                \\<and> (\\<not>loc2 s \\<longrightarrow> ([lib(l) =\\<^sub>t' 0] (lstate s)) \\<and> (cvd[lib(l), 0] (lstate s)))\n                \\<and> (loc2 s \\<and> \\<not>rel2 s \\<longrightarrow> cvd[lib(l), 1] (lstate s)) \n                \\<and> (loc2 s \\<and> rel2 s \\<longrightarrow> (cvv[lib(l), 0] (lstate s)))\n        | L2 \\<Rightarrow>  (loc1 s) \\<and> (\\<not>rel1 s)\n                \\<and> ([d1 =\\<^sub>t 0] (state s))\n                \\<and> ([d2 =\\<^sub>t 0] (state s))\n                \\<and> (\\<not>loc2 s \\<longrightarrow>  \\<not>[lib(l) \\<approx>\\<^sub>t' 2] (lstate s))\n                \\<and> cvv[lib(l),0] (lstate s) \n        | L3 \\<Rightarrow>  (loc1 s) \\<and> (\\<not>rel1 s) \n                \\<and> ([d1 =\\<^sub>t 5] (state s))\n                \\<and> ([d2 =\\<^sub>t 0] (state s))\n                \\<and> (\\<not>loc2 s \\<longrightarrow>  \\<not>[lib(l) \\<approx>\\<^sub>t' 2] (lstate s))\n                \\<and> cvv[lib(l),0] (lstate s) \n        | L4 \\<Rightarrow>  (loc1 s) \\<and> (\\<not>rel1 s)\n                \\<and> (\\<not>loc2 s \\<longrightarrow>  \\<not>[lib(l) \\<approx>\\<^sub>t' 2] (lstate s))\n                \\<and> ([d1 =\\<^sub>t 5] (state s))\n                \\<and> ([d2 =\\<^sub>t 5] (state s))\n                \\<and> cvv[lib(l),0] (lstate s) \n        | L5 \\<Rightarrow> (rel1 s) \\<and> (loc1 s)\n    )\n  else\n    if t = t2 then\n      let t' = t1 in \n      (case p of\n          L1 \\<Rightarrow>  \\<not>rel2 s \\<and> \\<not>loc2 s \n                \\<and> (\n                    (rel1 s \\<and> ([lib(l) = 2]\\<lparr>d1 =\\<^sub>t 5\\<rparr> (lstate s) (state s))\n                     \\<and> ([lib(l) = 2]\\<lparr>d2 =\\<^sub>t 5\\<rparr> (lstate s) (state s)))                    \n                  \\<or> (  ([lib(l) =\\<^sub>t 0] (lstate s)) \\<and> [d1 =\\<^sub>t 0] (state s)\n                     \\<and> [d2 =\\<^sub>t 0] (state s))\n                  \\<or> (loc1 s \\<and> \\<not> rel1 s))\n                \\<and> (\\<not>loc1 s \\<longrightarrow> ([lib(l) =\\<^sub>t' 0] (lstate s)) \\<and> (cvd[lib(l), 0] (lstate s)))\n                \\<and> (loc1 s \\<and> \\<not>rel1 s \\<longrightarrow> cvd[lib(l), 1] (lstate s))  \n                \\<and> (rel1 s \\<longrightarrow> cvv[lib(l), 0] (lstate s))\n        | L2 \\<Rightarrow>   \\<not>rel2 s \\<and> loc2 s  \\<and> (cvv[lib(l), 0] (lstate s))\n                \\<and> (ver2 s = 2 \\<longrightarrow> [d1 =\\<^sub>t 5] (state s) \\<and> [d2 =\\<^sub>t 5] (state s))   \n                \\<and> (ver2 s = 0 \\<longrightarrow> [d1 =\\<^sub>t 0] (state s) \\<and> [d2 =\\<^sub>t 0] (state s))\n        | L3 \\<Rightarrow>  \\<not>rel2 s \\<and> loc2 s  \\<and> (cvv[lib(l), 0] (lstate s))\n                \\<and> (ver2 s = 2 \\<longrightarrow> r s = 5 \\<and> [d2 =\\<^sub>t 5] (state s))   \n                \\<and> (ver2 s = 0 \\<longrightarrow> r s = 0 \\<and> [d2 =\\<^sub>t 0] (state s))\n        | L4 \\<Rightarrow>  loc2 s \\<and> \\<not>rel2 s \\<and> (cvv[lib(l), 0] (lstate s))\n                \\<and> (ver2 s = 2 \\<longrightarrow> r s = 5 \\<and> r2 s = 5) \n                \\<and> (ver2 s = 0 \\<longrightarrow> r s = 0 \\<and> r2 s = 0)\n        | L5 \\<Rightarrow> loc2 s \\<and> rel2 s\n      )\n\n  else\n    False)\n\"\n\n(* r s = 5 \\<and> r1 s = 5 \\<or> r s = 0 \\<and> r s = 0 *)\n\nlemmas autos = mutex_def global_inv_def update_pc_def prog_def prog_inv_def thrdsvars_def\n\nlemma init_inv:\n  assumes  \"init_state s\"\n    and \"global_inv s\"\n      and \"t\\<in>{t1,t2}\"\n    shows \"prog_inv t L1 s\"\n  using assms\n  apply (simp add: autos  init_state_def)\n  apply(intro conjI impI; elim disjE)\n  using lib_d_obs_not_p_obs zero_neq_numeral apply blast\n  apply blast\n  apply blast\n  by blast\n\nlemma global_inv_init:\n  assumes \"init_state s\"\n  shows \"global_inv s\"\n  using assms\n  apply (simp add: init_state_def autos)\n  done\n\n\n\n\nlemma t1_local:\n  assumes \"prog_inv t1 ((pc s) t1) s\" \n      and \"prog t1 s s'\"\n    shows \"prog_inv t1 ((pc s') t1) s'\"\n  using assms \n  apply(case_tac \"pc s t1\", simp_all)\n     apply(case_tac \"pc s' t1\", simp_all)\n            apply (simp_all add: prog_inv_def prog_def global_inv_def thrdsvars_def update_pc_def)\n         apply(unfold mutex_def, elim conjE)\n  apply (smt PC.distinct(1) fun_upd_same lock_acquire_def lock_acquire_step_def prod.sel(1) prod.sel(2))\n  apply(intro conjI)\n  using lock_acqure_wfs_pres apply blast\n  using lock_acqure_lib_wfs_pres apply blast\n  using lock_acquire_cvd_odd_false apply force\n            apply blast+\n  using lock_acquire_cvd_odd_false apply force\n            apply (metis PC.distinct(1))\n  \n           apply (metis (full_types) PC.distinct(1) lock_acqure_successfulib_client_pres_d_obs)\n  apply (metis (full_types) PC.distinct(1) lock_acqure_successfulib_client_pres_d_obs)\n\n      apply (smt PC.distinct(1) add_le_same_cancel2 lock_acquire_successful_p_obs of_nat_0 of_nat_le_0_iff) \n         defer \n  apply (metis PC.distinct(4) PC.simps(10) fun_upd_same)\n  apply (metis PC.distinct(11) PC.distinct(5) fun_upd_same)\n  apply (metis PC.distinct(13) PC.distinct(7) fun_upd_same)                       \n  apply (metis d_obs_WrX_other d_obs_WrX_set step_pres_lib_wfs wfs_preserved)\n  apply (meson d_obs_WrX_other d_obs_WrX_set step_pres_lib_wfs wfs_preserved)\n   apply (metis lock_release_lib_wfs_pres)\n  apply(elim conjE)\n  apply simp\n  apply(cases \"loc2 s\", simp_all)\n  apply(cases \"rel2 s\", simp_all)\n  defer\n    apply (metis PC.distinct(1) even_Suc even_zero lock_acquire_cvd_odd_false)\n   apply(cases \"loc1 s'\", simp_all)\n  apply(elim conjE)\n  using cvd_cvv_val apply blast\n  using cvv_lock_acquire_pres by blast\n\nlemma t2_local:\n  assumes \"prog_inv t2 ((pc s) t2) s\" \n      and \"prog t2 s s'\"\n    shows \"prog_inv t2 ((pc s') t2) s'\"\n  using assms \n  apply(case_tac \"t1 \\<noteq> t2\")\n  apply(case_tac \"pc s t2\", simp_all)\n     apply(case_tac \"pc s' t2\", simp_all)\n            apply (simp_all add: prog_inv_def prog_def global_inv_def thrdsvars_def update_pc_def)\n        apply(unfold mutex_def)\n          apply simp_all\n  apply (smt PC.distinct(1) fun_upd_same lock_acquire_def lock_acquire_step_def prod.sel(1) prod.sel(2))\n       apply(elim conjE, intro conjI)  \n  using lock_acqure_wfs_pres apply blast\n  using lock_acqure_lib_wfs_pres apply blast\n         apply (metis One_nat_def lock_acquire_cvd_odd_false odd_one)\n      apply auto[1]\n          apply (elim disjE conjE)\n  using cvv_lock_acquire_pres apply blast\n  apply (metis (full_types) PC.distinct(1) cvd_cvv_val cvv_lock_acquire_pres even_Suc even_zero lock_acquire_cvd_odd_false)\n  apply (metis PC.distinct(1) even_Suc even_zero lock_acquire_cvd_odd_false)\n         apply (intro conjI impI)\n         apply (metis (full_types) PC.distinct(1) lock_acquire_cvd_odd_false lock_acquire_successful_c_o_s lock_acquire_successful_rv numeral_1_eq_Suc_0 numeral_One odd_one zero_neq_numeral)\n  apply (metis (full_types) PC.distinct(1) lock_acquire_cvd_odd_false lock_acquire_successful_c_o_s lock_acquire_successful_rv numeral_1_eq_Suc_0 numeral_One odd_one zero_neq_numeral)\n        defer\n  apply (metis PC.distinct(3) PC.distinct(9) fun_upd_same)\n  apply (metis PC.distinct(11) PC.distinct(5) fun_upd_same)\n  apply (metis PC.distinct(13) PC.distinct(7) fun_upd_same)\n     apply (metis d_obs_RdX_other d_obs_read_value step_pres_lib_wfs wfs_preserved)\n  using d_obs_read_value step_pres_lib_wfs wfs_preserved apply blast\n   apply (metis lock_release_lib_wfs_pres)\n  apply (elim disjE)\n    defer\n    apply (metis (full_types) PC.distinct(1) lock_acqure_successfulib_client_pres_d_obs)\n  apply (metis PC.distinct(1) even_Suc even_zero lock_acquire_cvd_odd_false)\n  by (metis (full_types)  PC.distinct(1) cvv_val)\n\nlemma t1_global:\n  assumes \"prog_inv t1 ((pc s) t1) s\" \n      and \"prog_inv t2 ((pc s) t2) s\" \n      and \"prog t2 s s'\"\n    shows \"prog_inv t1 ((pc s') t1) s'\"\n  using assms \n  apply(case_tac \"pc s t1\")\n     apply(case_tac \"pc s t2\")\n  apply(case_tac \"pc s' t1\")\n           apply(simp_all add: prog_inv_def prog_def global_inv_def mutex_def thrdsvars_def update_pc_def)\n          apply(intro conjI)\n  using lock_acqure_wfs_pres apply blast\n  using lock_acqure_lib_wfs_pres apply blast\n  apply (metis (full_types) lock_acquire_successfulib_diff_t_d_p_obs_pres lock_acquire_unsuccessful_diff_t_d_p_obs_pres)\n  \n  apply (metis (full_types) lock_acquire_successfulib_diff_t_d_p_obs_pres lock_acquire_unsuccessful_diff_t_d_p_obs_pres)\n\n  apply (metis (full_types) OpSem.null_def lock_acquire_successful_not_p_obs_pres lock_acquire_unsuccessful_d_obs_pres)  \n   \n  apply (metis (full_types) lock_acquire_unsuccessful_d_obs_pres lock_acquire_unsuccessfulib_cvd_pres)\n\n  apply (elim conjE, intro impI, simp)  \n  \n  using lock_acquire_successfulib_cvd apply fastforce\n   apply fastforce \n            apply auto[3]\n  using dobs_RdX_pres step_pres_lib_wfs wfs_preserved apply blast\n  using dobs_RdX_pres step_pres_lib_wfs wfs_preserved apply blast\n  apply(intro conjI)\n  apply (metis lock_release_lib_wfs_pres)\n  apply(case_tac \"pc s t2\"; simp)\n      apply(case_tac \"pc s' t1\"; simp)\n      apply (metis cvv_release)\n  apply(case_tac \"pc s t2\"; simp)\n      apply(case_tac \"pc s' t1\"; simp)\n  using lock_acquire_cvd_odd_false apply fastforce\n  apply (smt One_nat_def lock_acquire_cvd_odd_false lock_acquire_def lock_acquire_step_def odd_one prod.sel(1) prod.sel(2))\n  apply (metis PC.distinct(9) even_Suc even_zero lock_acquire_cvd_odd_false)\n  apply (metis One_nat_def PC.distinct(11) lock_acquire_cvd_odd_false odd_one)\n  apply (metis PC.distinct(14) autos(3) fun_upd_def)\n  apply(case_tac \"pc s t2\"; simp)\n  apply(case_tac \"pc s' t1\"; simp)\n  apply (metis)\n  apply (metis)\n  apply (smt One_nat_def lock_acquire_cvd_odd_false lock_acquire_def lock_acquire_step_def odd_one prod.sel(1) prod.sel(2))\n  apply (metis)  \n  apply (metis)\n  apply(case_tac \"pc s t2\"; simp)\n  apply(case_tac \"pc s' t1\"; simp)\n  apply (metis)\n  apply (metis)\n  apply (metis)  \n  apply (smt One_nat_def lock_acquire_cvd_odd_false lock_acquire_def lock_acquire_step_def odd_one prod.sel(1) prod.sel(2))\n  apply (metis)\n  apply blast+\n  apply(case_tac \"pc s t2\"; simp)\n       apply(case_tac \"pc s' t1\"; simp) \n  using lock_acquire_cvd_odd_false apply fastforce\n  apply (metis PC.simps(10) autos(3) fun_upd_def)\n  apply (smt One_nat_def lock_acquire_cvd_odd_false lock_acquire_def lock_acquire_step_def odd_one prod.sel(1) prod.sel(2))\n  apply (metis PC.distinct(15) autos(3) fun_upd_def)\n  apply (metis PC.distinct(17) autos(3) fun_upd_other)\n  apply (metis)\n  apply (metis)\n  apply (metis)\n  apply(case_tac \"pc s t2\"; simp)\n       apply(case_tac \"pc s' t1\"; simp) \n  apply (metis PC.distinct(5) autos(3) fun_upd_apply)\n  apply (metis PC.distinct(11) autos(3) fun_upd_other)\n  apply (metis PC.distinct(15) autos(3) fun_upd_apply)\n  apply (smt One_nat_def lock_acquire_cvd_odd_false lock_acquire_def lock_acquire_step_def odd_one prod.sel(1) prod.sel(2))\n  apply (metis PC.simps(20) autos(3) fun_upd_apply)\n  apply blast+\n  apply(case_tac \"pc s t2\"; simp)\n       apply(case_tac \"pc s' t1\"; simp) \n  apply (metis PC.distinct(7) autos(3) fun_upd_other)\n  apply (metis PC.distinct(13) autos(3) fun_upd_other)\n  apply (metis PC.distinct(17) autos(3) fun_upd_other)\n  apply (metis PC.distinct(19) autos(3) fun_upd_other) \n  using lock_acqure_lib_wfs_pres lock_acqure_wfs_pres apply blast\n  apply (smt PC.simps(25) autos(3) fun_upd_other step_pres_lib_wfs wfs_preserved)\n    apply (smt PC.simps(25) autos(3) fun_upd_other step_pres_lib_wfs wfs_preserved)\n  apply (smt PC.simps(25) autos(3) fun_upd_other lock_release_lib_wfs_pres)\n  done\n\nlemma t2_global:\n  assumes \"prog_inv t1 ((pc s) t1) s\" \n      and \"prog_inv t2 ((pc s) t2) s\" \n      and \"prog t1 s s'\"\n    shows \"prog_inv t2 ((pc s') t2) s'\"\n  using assms \n  apply(subgoal_tac \"t1 \\<noteq> t2\")\n  apply(simp add: prog_def)\n  apply(case_tac \"pc s t1\", simp_all)\n    apply(case_tac \"pc s t2\", simp_all)\n       apply(case_tac \"pc s' t2\", simp_all)\n           apply(simp_all add: prog_inv_def global_inv_def thrdsvars_def update_pc_def)\n           apply(unfold  mutex_def, elim conjE)\n           apply simp\n  apply(intro conjI)  \n  using lock_acqure_wfs_pres apply blast\n  using lock_acqure_lib_wfs_pres apply blast\n               apply (metis (full_types)  lock_acquire_unsuccessful_d_obs_pres lock_acquire_unsuccessful_diff_t_d_p_obs_pres)\n  \n  apply (metis (full_types) lock_acquire_unsuccessful_d_obs_pres lock_acquire_unsuccessfulib_cvd_pres)\n  using lock_acquire_successfulib_cvd apply force\n apply force\n           apply auto[1]\n\n          apply auto[1]\n  \n  apply auto[1]\n\n  apply (intro conjI)\n  apply (smt One_nat_def PC.simps(22) global_inv_def lock_acquire_cvd_odd_false lock_acquire_unsuccessful_diff_t_d_p_obs_pres lock_acqure_lib_wfs_pres lock_acqure_wfs_pres mutex_def odd_one thrdsvars_def)\n  apply (smt One_nat_def PC.simps(23) global_inv_def lock_acquire_cvd_odd_false lock_acquire_unsuccessful_diff_t_d_p_obs_pres lock_acqure_lib_wfs_pres lock_acqure_wfs_pres mutex_def odd_one thrdsvars_def)\n  apply (smt One_nat_def PC.simps(24) global_inv_def lock_acquire_cvd_odd_false lock_acqure_lib_wfs_pres lock_acqure_wfs_pres mutex_def odd_one thrdsvars_def)\n  apply (smt PC.simps(25) fun_upd_other global_inv_def lock_acqure_lib_wfs_pres lock_acqure_wfs_pres mutex_def thrdsvars_def)\n     defer defer defer\n  apply (case_tac \"pc s t1\"; simp add: thrdsvars_def prog_def global_inv_def)\n    apply (case_tac \"pc s t2\"; simp)\n         apply (intro conjI)\n  using lock_acqure_wfs_pres apply blast\n  \n  using lock_acqure_lib_wfs_pres apply blast\n  apply (metis lock_acquire_cvd_odd_false numeral_1_eq_Suc_0 numeral_One odd_one)\n    apply (case_tac \"pc s' t2\"; simp)\n  apply auto[1]\n  apply (metis PC.distinct(11) fun_upd_apply)\n  apply (metis PC.distinct(15) fun_upd_other)\n  using cvv_lock_acquire_pres apply blast\n  apply auto[1]\n         apply (intro conjI)\n  using lock_acqure_wfs_pres apply blast\n  using lock_acqure_lib_wfs_pres apply blast\n  apply blast+\n  apply auto[1]\n    apply (case_tac \"pc s t2\"; simp)\n  using step_pres_lib_wfs wfs_preserved apply blast\n  using step_pres_lib_wfs wfs_preserved apply blast\n    apply (case_tac \"pc s t2\"; simp)\n  using step_pres_lib_wfs wfs_preserved apply blast\n  using step_pres_lib_wfs wfs_preserved apply blast\n  apply (case_tac \"pc s t2\"; simp)\n  using step_pres_lib_wfs wfs_preserved apply blast\n  apply (case_tac \"pc s t2\"; simp)\n  using step_pres_lib_wfs wfs_preserved apply blast+\n  apply (case_tac \"pc s t2\"; simp)\n  apply (metis cvv_release lock_rel_c_obs_intro lock_release_lib_wfs_pres)\n        apply blast+\n  using lock_release_lib_wfs_pres apply force \n  apply (metis lock_acquire_cvd_odd_false numeral_1_eq_Suc_0 numeral_One odd_one)\n  apply (case_tac \"pc s' t2\"; simp)\n       apply auto[1]\n  apply (smt cvv_lock_acquire_pres lock_acquire_successfulib_diff_t_d_p_obs_pres lock_acquire_unsuccessful_diff_t_d_p_obs_pres)\n  apply (metis PC.distinct(9) fun_upd_apply)\n  apply (metis PC.distinct(11) fun_upd_other)\n  apply auto[1]\n  by (smt PC.simps(23) cvv_lock_acquire_pres lock_acquire_cvd_odd_false lock_acquire_unsuccessful_diff_t_d_p_obs_pres lock_acqure_lib_wfs_pres lock_acqure_wfs_pres numeral_1_eq_Suc_0 numeral_One odd_one)\n\nend\n", "meta": {"author": "MSemenyuk", "repo": "PhD_Isabelle", "sha": "179f5d346a721b15940a271323e3487f4ea51338", "save_path": "github-repos/isabelle/MSemenyuk-PhD_Isabelle", "path": "github-repos/isabelle/MSemenyuk-PhD_Isabelle/PhD_Isabelle-179f5d346a721b15940a271323e3487f4ea51338/Treiber Stack C11/MP_AbstractLock.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331462646255, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.27960226837805585}}
{"text": "(*******************************************************************************\n \n  Project: IsaNet\n\n  Author:  Tobias Klenze, ETH Zurich <tobias.klenze@inf.ethz.ch>\n  Version: JCSPaper.1.0\n  Isabelle Version: Isabelle2021-1\n\n  Copyright (c) 2022 Tobias Klenze\n  Licence: Mozilla Public License 2.0 (MPL) / BSD-3-Clause (dual license)\n\n*******************************************************************************)\n\nsection \\<open>ICING variant\\<close>\ntext\\<open>We abstract and simplify from the protocol ICING in several ways. First, we only consider \nProofs of Consent (PoC), not Proofs of Provenance (PoP). Our framework does not support proving the\npath validation properties that PoPs provide, and it also currently does not support XOR, and \ndynamically changing hop fields.\nThus, instead of embedding $A_i \\oplus PoP_{0,1}$, we embed $A_i$ directly.\nWe also remove the payload from the Hash that is included in each packet.\n\nWe offer three versions of this protocol:\n\\begin{itemize}\n\\item @{text \"ICING\"}, which contains our best effort at modeling the protocol as accurately as \npossible.\n\\item @{text \"ICING_variant\"}, in which we strip down the protocol to what is required to obtain the\nsecurity guarantees and remove unnecessary fields.\n\\item @{text \"ICING_variant2\"}, in which we furthermore simplify the protocol. The key of the MAC in\nthis protocol is only the key of the AS, as opposed to a key derived specifically for this hop field.\nIn order to prove that this scheme is secure, we have to assume that ASes only occur once on an\nauthorized path, since otherwise the MAC for two different hop fields (by the same AS) would be the\nsame, and the AS could not distinguish the hop fields based on the MAC.\n\\end{itemize}\\<close>\ntheory ICING_variant2\n  imports\n    \"../Parametrized_Dataplane_3_undirected\"\nbegin\n\nlocale icing_defs = network_assums_undirect _ _ _ auth_seg0 \n  for auth_seg0 :: \"(msgterm \\<times> ahi list) set\"\n+ assumes auth_seg0_no_dups: \n  \"\\<lbrakk>(ainfo, hfs) \\<in> auth_seg0; hf \\<in> set hfs; hf' \\<in> set hfs; ASID hf' = ASID hf\\<rbrakk> \\<Longrightarrow> hf' = hf\"\nbegin\n\n(******************************************************************************)\nsubsection \\<open>Hop validation check and extract functions\\<close>\n(******************************************************************************)\ntype_synonym ICING_HF = \"(unit, unit) HF\"\n\ntext\\<open>The term @{term \"sntag\"} simply is the AS key. We use it in the computation of @{term \"hf_valid\"}.\\<close>\n\nfun sntag :: \"ahi \\<Rightarrow> msgterm\" where\n  \"sntag \\<lparr>UpIF = upif, DownIF = downif, ASID = asid\\<rparr> = macKey asid\"\n\ntext\\<open>The predicate @{term \"hf_valid\"} is given to the concrete parametrized model as a parameter.\nIt ensures the authenticity of the hop authenticator in the hop field. The predicate takes an \nexpiration timestamp (in this model always a numeric value, hence the matching on \n@{term \"Num PoC_i_expire\"}), the entire segment and the hop field to be validated.\\<close>\nfun hf_valid :: \"msgterm \\<Rightarrow> msgterm\n    \\<Rightarrow> ICING_HF list\n    \\<Rightarrow> ICING_HF \n    \\<Rightarrow> bool\" where \n  \"hf_valid (Num PoC_i_expire) uinfo hfs \\<lparr>AHI = ahi, UHI = uhi, HVF = x\\<rparr> \\<longleftrightarrow> uhi = () \\<and> \n    x = Mac[sntag ahi] (L ((Num PoC_i_expire)#(map (hf2term o AHI) hfs))) \\<and> uinfo = \\<epsilon>\"\n| \"hf_valid _ _ _ _ = False\"\n\ntext\\<open>We can extract the entire path (past and future) from the hvf field.\\<close>\nfun extr :: \"msgterm \\<Rightarrow> ahi list\" where\n  \"extr (Mac[_] (L hfs))\n = map term2hf (tl hfs)\"\n| \"extr _ = []\"\n\ntext\\<open>Extract the authenticated info field from a hop validation field.\\<close>\nfun extr_ainfo :: \"msgterm \\<Rightarrow> msgterm\" where \n  \"extr_ainfo (Mac[_] (L (Num ts # xs))) = Num ts\"\n| \"extr_ainfo _ = \\<epsilon>\"\n\nabbreviation term_ainfo :: \"msgterm \\<Rightarrow> msgterm\" where\n  \"term_ainfo \\<equiv> id\"\n\ntext\\<open>An authenticated info field is always a number (corresponding to a timestamp). The \n     unauthenticated info field is set to the empty term @{term \"\\<epsilon>\"}.\\<close>\ndefinition auth_restrict where \n  \"auth_restrict ainfo uinfo l \\<equiv> (\\<exists>ts. ainfo = Num ts) \\<and> (uinfo = \\<epsilon>)\"\n\ntext\\<open>When observing a hop field, an attacker learns the HVF. UHI is empty and the AHI only contains \npublic information that are not terms.\\<close>\nfun terms_hf :: \"ICING_HF \\<Rightarrow> msgterm set\" where \n  \"terms_hf hf = {HVF hf}\"\n\nabbreviation terms_uinfo :: \"msgterm \\<Rightarrow> msgterm set\" where \n  \"terms_uinfo x \\<equiv> {x}\"\n\nabbreviation no_oracle where \"no_oracle \\<equiv> (\\<lambda> _ _. True)\"\n\ntext\\<open>We now define useful properties of the above definition.\\<close>\nlemma hf_valid_invert:\n  \"hf_valid tsn uinfo hfs hf \\<longleftrightarrow>\n(\\<exists> ts ahi. tsn = Num ts \\<and> ahi = AHI hf \\<and>\nUHI hf = () \\<and>\nHVF hf = Mac[sntag ahi] (L ((Num ts)#(map (hf2term o AHI) hfs))) \\<and> uinfo = \\<epsilon>)\"\n  apply(cases hf) by(auto elim!: hf_valid.elims)\n\nlemma hf_valid_auth_restrict[dest]: \"hf_valid ainfo uinfo hfs hf \\<Longrightarrow> auth_restrict ainfo uinfo l\"\n  by(auto simp add: hf_valid_invert auth_restrict_def)\n\nlemma auth_restrict_ainfo[dest]: \"auth_restrict ainfo uinfo l \\<Longrightarrow> \\<exists>ts. ainfo = Num ts\"\n  by(auto simp add: auth_restrict_def)\nlemma auth_restrict_uinfo[dest]: \"auth_restrict ainfo uinfo l \\<Longrightarrow> uinfo = \\<epsilon>\"\n  by(auto simp add: auth_restrict_def)\n\n(******************************************************************************)\nsubsection\\<open>Definitions and properties of the added intruder knowledge\\<close>\n(******************************************************************************)\ntext\\<open>Here we define a @{text \"ik_add\"} and @{text \"ik_oracle\"} as being empty, as these features are\nnot used in this instance model.\\<close>\nprint_locale dataplane_3_undirected_defs\nsublocale dataplane_3_undirected_defs _ _ _ auth_seg0 hf_valid auth_restrict extr extr_ainfo \n  term_ainfo terms_hf terms_uinfo no_oracle\n  by unfold_locales\n\ndeclare parts_singleton[dest]\n\nabbreviation ik_add :: \"msgterm set\" where \"ik_add \\<equiv> {}\"\n\nabbreviation ik_oracle :: \"msgterm set\" where \"ik_oracle \\<equiv> {}\"\n\nlemma uinfo_empty[dest]: \"(ainfo, hfs) \\<in> auth_seg2 uinfo \\<Longrightarrow> uinfo = \\<epsilon>\"\n  by(auto simp add: auth_seg2_def auth_restrict_def)\n\n(******************************************************************************)\nsubsection\\<open>Properties of the intruder knowledge, including @{text \"ik_add\"} and  @{text \"ik_oracle\"}\\<close>\n  (******************************************************************************)\ntext\\<open>We now instantiate the parametrized model's definition of the intruder knowledge, using the\ndefinitions of @{text \"ik_add\"} and  @{text \"ik_oracle\"} from above. We then prove the properties \nthat we need to instantiate the @{text \"dataplane_3_undirected\"} locale.\\<close>\nprint_locale dataplane_3_undirected_ik_defs\nsublocale\n  dataplane_3_undirected_ik_defs _ _ _ auth_seg0 terms_uinfo no_oracle hf_valid auth_restrict extr \n    extr_ainfo term_ainfo terms_hf ik_add ik_oracle\n  by unfold_locales\n\nlemma ik_hfs_form: \"t \\<in> parts ik_hfs \\<Longrightarrow> \\<exists> t' . t = Hash t'\"\n  apply auto apply(drule parts_singleton)\n  by(auto simp add: auth_seg2_def hf_valid_invert)\n\ndeclare ik_hfs_def[simp del]\n\nlemma parts_ik_hfs[simp]: \"parts ik_hfs = ik_hfs\"\n  by (auto intro!: parts_Hash ik_hfs_form)\n\ntext\\<open>This lemma allows us not only to expand the definition of @{term \"ik_hfs\"}, but also \nto obtain useful properties, such as a term being a Hash, and it being part of a valid hop field.\\<close>\nlemma ik_hfs_simp: \n  \"t \\<in> ik_hfs \\<longleftrightarrow> (\\<exists>t' . t = Hash t') \\<and> (\\<exists>hf . t = HVF hf\n                    \\<and> (\\<exists>hfs uinfo. hf \\<in> set hfs \\<and> (\\<exists>ainfo . (ainfo, hfs) \\<in> auth_seg2 uinfo\n                    \\<and> hf_valid ainfo uinfo hfs hf)))\" (is \"?lhs \\<longleftrightarrow> ?rhs\")\nproof \n  assume asm: \"?lhs\" \n  then obtain ainfo uinfo hf hfs where \n    dfs: \"hf \\<in> set hfs\" \"(ainfo, hfs) \\<in> auth_seg2 uinfo\" \"t = HVF hf\"\n    by(auto simp add: ik_hfs_def)\n  then obtain uinfo where \"hfs_valid_prefix ainfo uinfo [] hfs = hfs\"  \"(ainfo, AHIS hfs) \\<in> auth_seg0\"\n    by(auto simp add: auth_seg2_def)\n  then show \"?rhs\" using asm dfs\n    by (auto 3 4 simp add: auth_seg2_def intro!: ik_hfs_form exI[of _ hf]) \nqed(auto simp add: ik_hfs_def)\n\nlemma ik_uinfo_empty[simp]: \"ik_uinfo = {\\<epsilon>}\" \n  by(auto simp add: ik_uinfo_def auth_seg2_def auth_restrict_def intro!: exI[of _ \"[]\"])\ndeclare ik_uinfo_def[simp del]\n\n(******************************************************************************)\nsubsubsection \\<open>Properties of Intruder Knowledge\\<close>\n(******************************************************************************)\nlemma auth_ainfo[dest]: \"\\<lbrakk>(ainfo, hfs) \\<in> auth_seg2 uinfo\\<rbrakk> \\<Longrightarrow> \\<exists> ts . ainfo = Num ts\"\n  by(auto simp add: auth_seg2_def)\n\nlemma Num_ik[intro]: \"Num ts \\<in> ik\"\n  by(auto simp add: ik_def auth_seg2_def auth_restrict_def intro!: exI[of _ \"[]\"])\n\ntext \\<open>There are no ciphertexts (or signatures) in @{term \"parts ik\"}. Thus, @{term \"analz ik\"}\nand @{term \"parts ik\"} are identical.\\<close>\nlemma analz_parts_ik[simp]: \"analz ik = parts ik\"\n  by(rule no_crypt_analz_is_parts)\n    (auto simp add: ik_def auth_seg2_def ik_hfs_simp auth_restrict_def)\n\nlemma parts_ik[simp]: \"parts ik = ik\"\n  by(auto 3 4 simp add: ik_def auth_seg2_def auth_restrict_def dest!: parts_singleton_set)\n\nlemma sntag_synth_bad: \"sntag ahi \\<in> synth ik \\<Longrightarrow> ASID ahi \\<in> bad\"\n  apply(cases ahi)\n  by(auto simp add: ik_def ik_hfs_simp)\n\nlemma back_subst_set_member: \"\\<lbrakk>hf' \\<in> set hfs; hf' = hf\\<rbrakk> \\<Longrightarrow> hf \\<in> set hfs\" by simp\n\nlemma sntag_asid: \"sntag hf = sntag hf' \\<Longrightarrow> ASID hf' = ASID hf\" apply(cases hf, cases hf') by auto\n\nlemma map_hf2term_eq: \"map (\\<lambda>x. hf2term (AHI x)) hfs = map (\\<lambda>x. hf2term (AHI x)) hfs'\n\\<Longrightarrow> AHIS hfs' = AHIS hfs\" apply(induction hfs hfs' rule: list_induct2', auto)  \n  using term2hf_hf2term by (metis)\n(******************************************************************************)\nsubsection\\<open>Direct proof goals for interpretation of @{text \"dataplane_3_undirected\"}\\<close>\n(******************************************************************************)\n\nlemma COND_honest_hf_analz:\n  assumes \"ASID (AHI hf) \\<notin> bad\" \"hf_valid ainfo uinfo hfs hf\" \"terms_hf hf \\<subseteq> synth (analz ik)\"\n    \"no_oracle ainfo uinfo\" \"hf \\<in> set hfs\"\n    shows \"terms_hf hf \\<subseteq> analz ik\"\nproof-\n  from assms(3) have hf_synth_ik: \"HVF hf \\<in> synth ik\" by auto\n  then have \"\\<exists>hfs uinfo. hf \\<in> set hfs \\<and> (ainfo, hfs) \\<in> auth_seg2 uinfo\"\n    using assms(1,2,4,5) \n    apply(auto simp add: ik_def hf_valid_invert ik_hfs_simp)\n    subgoal for ts' hf' hfs'\n      apply (auto intro!: exI[of _ hfs'])\n      apply(frule back_subst_set_member[where hfs=\"hfs'\"])\n      apply(rule HF.equality)\n          apply auto\n      apply(drule sntag_asid)\n      apply(drule map_hf2term_eq)\n      using auth_seg0_no_dups  \n      by (metis (mono_tags, lifting) AHIS_set_rev HF.surjective auth_seg20 old.unit.exhaust)\n    by(auto simp add: ik_hfs_simp ik_def hf_valid_invert sntag_synth_bad)\n  then have \"HVF hf \\<in> ik\"\n    using assms(2)\n    by(auto simp add: ik_hfs_def intro!: ik_ik_hfs intro!: exI) \n  then show ?thesis by auto\nqed\n\nlemma COND_terms_hf: \n  assumes \"hf_valid ainfo uinfo hfs hf\" and \"HVF hf \\<in> ik\" and \"no_oracle ainfo uinfo\" and \"hf \\<in> set hfs\"\n  shows \"\\<exists>hfs. hf \\<in> set hfs \\<and> (\\<exists>uinfo' . (ainfo, hfs) \\<in> auth_seg2 uinfo')\"\n  using assms apply(auto 3 4 simp add: hf_valid_invert ik_hfs_simp ik_def dest: ahi_eq)\n  subgoal for ts' hf' hfs'\n      apply (auto intro!: exI[of _ hfs'])\n    apply(frule back_subst_set_member[where hfs=\"hfs'\"])\n    apply auto\n      apply(rule HF.equality)\n          apply auto\n      apply(drule sntag_asid)\n      apply(drule map_hf2term_eq)\n      using auth_seg0_no_dups \n      by (metis (mono_tags, lifting) AHIS_set_rev HF.surjective auth_seg20 old.unit.exhaust)\n    done\n\nlemma COND_extr:\n    \"\\<lbrakk>hf_valid ainfo uinfo l hf\\<rbrakk> \\<Longrightarrow> extr (HVF hf) = AHIS l\"\n  by(auto simp add: hf_valid_invert)\n\nlemma COND_hf_valid_uinfo:\n    \"\\<lbrakk>hf_valid ainfo uinfo l hf; hf_valid ainfo' uinfo' l' hf\\<rbrakk> \n    \\<Longrightarrow> uinfo' = uinfo\"\n  by(auto simp add: hf_valid_invert)\n\n(******************************************************************************)\nsubsection\\<open>Instantiation of @{text \"dataplane_3_undirected\"} locale\\<close>\n(******************************************************************************)\nprint_locale dataplane_3_undirected\nsublocale\n  dataplane_3_undirected _ _ _ auth_seg0 hf_valid auth_restrict extr extr_ainfo term_ainfo terms_uinfo ik_add terms_hf \n            ik_oracle  no_oracle\n  apply unfold_locales\n  using COND_terms_hf COND_honest_hf_analz COND_extr COND_hf_valid_uinfo by auto\n\nend\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/IsaNet/instances/ICING_variant2.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331462646254, "lm_q2_score": 0.4687906266262438, "lm_q1q2_score": 0.27960226837805585}}
{"text": "theory Scratch\n  imports Main \"HOL-Library.Mapping\"\nbegin\n\nfun reverse :: \"'a list => 'a list\" where\n  \"reverse [] = []\" |\n  \"reverse (x # xs) = reverse xs @ [x]\"\n\nvalue \"reverse [1::nat, 2, 3]\"\n\nvalue \"reverse (a # xs)\"\n\nlemma rev1: \"reverse (xs @ [a]) = a # reverse xs\"\n  apply(induct xs)\n  apply auto\n  done\n\ntheorem \"reverse (reverse xs) = xs\"\n  apply(induct xs)\n  apply auto\n  by (simp add:rev1)\n\ntype_synonym word = nat\ntype_synonym addr = nat\ntype_synonym buffer = \"nat list\"\ntype_synonym contract = buffer\n\nrecord frameState =\n   contract     :: addr\n   codeContract :: addr\n   code         :: buffer\n   pc           :: nat\n   stack        :: \"nat list\"\n   memory       :: buffer\n   memorySize   :: nat\n   calldata     :: buffer\n   callvalue    :: nat\n   caller       :: addr\n   gas          :: nat\n   returndata   :: buffer\n   static       :: bool\n\nrecord subState =\n  selfdestructs   :: \"addr list\"\n  touchedAccounts :: \"addr list\"\n\n(*  refunds         :: \"(addr, word) list\" *)\n\n\nrecord creationContext =\n    creationContextCodehash  :: word\n    creationContextReversion :: \"(addr, buffer) mapping\"\n    creationContextSubstate  :: subState\n\nrecord callContext =\n    callContextTarget    :: addr\n    callContextContext   :: addr\n    callContextOffset    :: word\n    callContextSize      :: word\n    callContextCodehash  :: word\n    callContextAbi       :: \"word option\"\n    callContextData      :: buffer\n    callContextReversion :: \"(addr, contract) mapping\"\n    callContextSubState  :: subState\n\ndatatype frameContext =\n    CallContext \"callContext\"\n  | CreationContext \"creationContext\"\n\n\nrecord frame =\n  frameContext   :: frameContext\n  frameState     :: frameState\n\ndatatype storageModel = ConcreteS | SymbolicS | InitialS\n\nrecord env =\n  contracts    :: \"(addr, contract) mapping\"\n  chainId      :: word\n  storageModel :: storageModel\n  sha3Crack    :: \"(word, buffer) mapping\"\n\n(*  keccakUsed   :: [([SWord 8], SWord 256)] *)\n\n\nrecord block =\n  coinbase    :: addr\n  timestamp   :: word\n  number      :: word\n  difficulty  :: word\n  gaslimit    :: word\n  maxCodeSize :: word\n(*  schedule    :: feeSchedule word*)\n\n\nrecord txState =\n  gasprice        :: word\n  txgaslimit      :: word\n  origin          :: addr\n  toAddr          :: addr\n  val             :: word\n  substate        :: subState\n  isCreate        :: bool\n  txReversion     :: \"(addr, contract) mapping\"\n\n\ndatatype error\n  = BalanceTooLow word word\n  | UnrecognizedOpcode word\n  | SelfDestruction\n  | StackUnderrun\n  | BadJumpDestination\n  | Revert buffer\n  | NoSuchContract addr\n  | OutOfGas word word\n  | BadCheatCode \"word option\"\n  | StackLimitExceeded\n  | IllegalOverflow\n  | StateChangeWhileStatic\n  | InvalidMemoryAccess\n  | CallDepthLimitReached\n  | MaxCodeSizeExceeded word word\n  | PrecompileFailure\n  | UnexpectedSymbolicArg\n  | DeadPath\n\ndatatype vmResult\n  = VMFailure error\n  | VMSuccess buffer\n\ndatatype log = Log addr buffer \"word list\"\n\nrecord vm =\n  result         :: \"vmResult option\"\n  state          :: frameState\n  env            :: env\n  block          :: block\n  tx             :: txState\n  logs           :: \"log list\"\n  burned         :: word\n\n\nend\n", "meta": {"author": "mhhf", "repo": "isabelle-test", "sha": "d93fe0fb0be099f04296d9c3377c07bf25636d88", "save_path": "github-repos/isabelle/mhhf-isabelle-test", "path": "github-repos/isabelle/mhhf-isabelle-test/isabelle-test-d93fe0fb0be099f04296d9c3377c07bf25636d88/test01/Scratch.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6992544335934766, "lm_q2_score": 0.399811640739795, "lm_q1q2_score": 0.27957006238958393}}
{"text": "theory Example_NetModel\nimports \"../TopoS_Interface\" \"../TopoS_Helper\"\nbegin\n\ntext{* A toy example that defines a valid network security requirement model *}\n\ndefinition default_node_properties :: \"bool\"\n  where  \"default_node_properties \\<equiv> False\"\n\nfun sinvar :: \"'v graph \\<Rightarrow> ('v \\<Rightarrow> bool) \\<Rightarrow> bool\" where\n  \"sinvar G nP = (\\<forall> (e1,e2) \\<in> (edges G). (nP e1) \\<and> (nP e2))\"\n\nfun verify_globals :: \"'v graph \\<Rightarrow> ('v \\<Rightarrow> bool) \\<Rightarrow> 'b \\<Rightarrow> bool\" where\n  \"verify_globals _ _ _ = True\"\n\n(* we will not define receiver_violation!! Works for both! *)\n\n\n\n\n \n-- \"The preliminaries: mostly, sinvar is monotonic\"\ninterpretation SecurityInvariant_preliminaries\nwhere sinvar = sinvar\nand verify_globals = verify_globals\n  apply unfold_locales\n  apply(frule_tac finite_distinct_list[OF valid_graph.finiteE])\n  apply(erule_tac exE)\n  apply(rename_tac list_edges)\n  apply(rule_tac ff=\"list_edges\" in SecurityInvariant_withOffendingFlows.mono_imp_set_offending_flows_not_empty[OF sinvar_mono])\n  apply(auto)[6]\n  apply(auto simp add: SecurityInvariant_withOffendingFlows.is_offending_flows_def graph_ops)[2]\n  apply(fact SecurityInvariant_withOffendingFlows.sinvar_mono_imp_is_offending_flows_mono[OF sinvar_mono])\ndone\n\n\n-- \"With generic target focus\"\ninterpretation Example_NetModel: SecurityInvariant\nwhere default_node_properties = default_node_properties\nand sinvar = sinvar\nand verify_globals = verify_globals\nand receiver_violation = receiver_violation (*yep, that's a variable*)\n  unfolding default_node_properties_def\n  apply unfold_locales\n\n  -- \"Secure bydefault\"\n  apply(simp)\n  apply (simp add: SecurityInvariant_withOffendingFlows.set_offending_flows_def\n      SecurityInvariant_withOffendingFlows.is_offending_flows_min_set_def\n      SecurityInvariant_withOffendingFlows.is_offending_flows_def)\n  apply (simp add: graph_ops)\n  apply (simp split: split_split_asm split_split)\n    apply blast\n\n -- \"Uniqueness\"\n apply(simp add:default_node_properties_def)\n  apply (simp add: SecurityInvariant_withOffendingFlows.set_offending_flows_def\n      SecurityInvariant_withOffendingFlows.is_offending_flows_min_set_def\n      SecurityInvariant_withOffendingFlows.is_offending_flows_def)\n  apply (simp add: graph_ops)\n  apply (simp split: split_split_asm split_split)\n  -- \"proof by counter example: assume False is not the unique default parameter\"\n  apply(rule_tac x=\"\\<lparr> nodes={vertex_1}, edges = {(vertex_1,vertex_1)} \\<rparr>\" in exI, simp)\n  apply(rule conjI)\n  apply(simp add: valid_graph_def)\n  apply(rule_tac x=\"(\\<lambda> x. default_node_properties)(vertex_1 := False)\" in exI, simp add:default_node_properties_def)\n  apply(case_tac receiver_violation)\n    apply(simp_all)\n    apply(rule_tac x=\"{(vertex_1,vertex_1)}\" in exI, simp)+\ndone\n\n\ntext{*And we end up with a totally useless network security requirement model. I hope this was instructive.*}\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Network_Security_Policy_Verification/Examples/Example_NetModel.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6992544085240401, "lm_q2_score": 0.399811640739795, "lm_q1q2_score": 0.2795700523665314}}
{"text": "(*  Title:      ZF/UNITY/SubstAx.thy\n    Author:     Sidi O Ehmety, Computer Laboratory\n    Copyright   2001  University of Cambridge\n\nTheory ported from HOL.\n*)\n\nsection\\<open>Weak LeadsTo relation (restricted to the set of reachable states)\\<close>\n\ntheory SubstAx\nimports WFair Constrains\nbegin\n\ndefinition\n  (* The definitions below are not `conventional', but yield simpler rules *)\n  Ensures :: \"[i,i] => i\"            (infixl \\<open>Ensures\\<close> 60)  where\n  \"A Ensures B == {F \\<in> program. F \\<in> (reachable(F) \\<inter> A) ensures (reachable(F) \\<inter> B) }\"\n\ndefinition\n  LeadsTo :: \"[i, i] => i\"            (infixl \\<open>\\<longmapsto>w\\<close> 60)  where\n  \"A \\<longmapsto>w B == {F \\<in> program. F:(reachable(F) \\<inter> A) \\<longmapsto> (reachable(F) \\<inter> B)}\"\n\n\n(*Resembles the previous definition of LeadsTo*)\n\n(* Equivalence with the HOL-like definition *)\nlemma LeadsTo_eq:\n\"st_set(B)==> A \\<longmapsto>w B = {F \\<in> program. F:(reachable(F) \\<inter> A) \\<longmapsto> B}\"\napply (unfold LeadsTo_def)\napply (blast dest: psp_stable2 leadsToD2 constrainsD2 intro: leadsTo_weaken)\ndone\n\nlemma LeadsTo_type: \"A \\<longmapsto>w B <=program\"\nby (unfold LeadsTo_def, auto)\n\n(*** Specialized laws for handling invariants ***)\n\n(** Conjoining an Always property **)\nlemma Always_LeadsTo_pre: \"F \\<in> Always(I) ==> (F:(I \\<inter> A) \\<longmapsto>w A') \\<longleftrightarrow> (F \\<in> A \\<longmapsto>w A')\"\nby (simp add: LeadsTo_def Always_eq_includes_reachable Int_absorb2 Int_assoc [symmetric] leadsToD2)\n\nlemma Always_LeadsTo_post: \"F \\<in> Always(I) ==> (F \\<in> A \\<longmapsto>w (I \\<inter> A')) \\<longleftrightarrow> (F \\<in> A \\<longmapsto>w A')\"\napply (unfold LeadsTo_def)\napply (simp add: Always_eq_includes_reachable Int_absorb2 Int_assoc [symmetric] leadsToD2)\ndone\n\n(* Like 'Always_LeadsTo_pre RS iffD1', but with premises in the good order *)\nlemma Always_LeadsToI: \"[| F \\<in> Always(C); F \\<in> (C \\<inter> A) \\<longmapsto>w A' |] ==> F \\<in> A \\<longmapsto>w A'\"\nby (blast intro: Always_LeadsTo_pre [THEN iffD1])\n\n(* Like 'Always_LeadsTo_post RS iffD2', but with premises in the good order *)\nlemma Always_LeadsToD: \"[| F \\<in> Always(C);  F \\<in> A \\<longmapsto>w A' |] ==> F \\<in> A \\<longmapsto>w (C \\<inter> A')\"\nby (blast intro: Always_LeadsTo_post [THEN iffD2])\n\n(*** Introduction rules \\<in> Basis, Trans, Union ***)\n\nlemma LeadsTo_Basis: \"F \\<in> A Ensures B ==> F \\<in> A \\<longmapsto>w B\"\nby (auto simp add: Ensures_def LeadsTo_def)\n\nlemma LeadsTo_Trans:\n     \"[| F \\<in> A \\<longmapsto>w B;  F \\<in> B \\<longmapsto>w C |] ==> F \\<in> A \\<longmapsto>w C\"\napply (simp (no_asm_use) add: LeadsTo_def)\napply (blast intro: leadsTo_Trans)\ndone\n\nlemma LeadsTo_Union:\n\"[|(!!A. A \\<in> S ==> F \\<in> A \\<longmapsto>w B); F \\<in> program|]==>F \\<in> \\<Union>(S) \\<longmapsto>w B\"\napply (simp add: LeadsTo_def)\napply (subst Int_Union_Union2)\napply (rule leadsTo_UN, auto)\ndone\n\n(*** Derived rules ***)\n\nlemma leadsTo_imp_LeadsTo: \"F \\<in> A \\<longmapsto> B ==> F \\<in> A \\<longmapsto>w B\"\napply (frule leadsToD2, clarify)\napply (simp (no_asm_simp) add: LeadsTo_eq)\napply (blast intro: leadsTo_weaken_L)\ndone\n\n(*Useful with cancellation, disjunction*)\nlemma LeadsTo_Un_duplicate: \"F \\<in> A \\<longmapsto>w (A' \\<union> A') ==> F \\<in> A \\<longmapsto>w A'\"\nby (simp add: Un_ac)\n\nlemma LeadsTo_Un_duplicate2:\n     \"F \\<in> A \\<longmapsto>w (A' \\<union> C \\<union> C) ==> F \\<in> A \\<longmapsto>w (A' \\<union> C)\"\nby (simp add: Un_ac)\n\nlemma LeadsTo_UN:\n    \"[|(!!i. i \\<in> I ==> F \\<in> A(i) \\<longmapsto>w B); F \\<in> program|]\n     ==>F:(\\<Union>i \\<in> I. A(i)) \\<longmapsto>w B\"\napply (simp add: LeadsTo_def)\napply (simp (no_asm_simp) del: UN_simps add: Int_UN_distrib)\napply (rule leadsTo_UN, auto)\ndone\n\n(*Binary union introduction rule*)\nlemma LeadsTo_Un:\n     \"[| F \\<in> A \\<longmapsto>w C; F \\<in> B \\<longmapsto>w C |] ==> F \\<in> (A \\<union> B) \\<longmapsto>w C\"\napply (subst Un_eq_Union)\napply (rule LeadsTo_Union)\napply (auto dest: LeadsTo_type [THEN subsetD])\ndone\n\n(*Lets us look at the starting state*)\nlemma single_LeadsTo_I:\n    \"[|(!!s. s \\<in> A ==> F:{s} \\<longmapsto>w B); F \\<in> program|]==>F \\<in> A \\<longmapsto>w B\"\napply (subst UN_singleton [symmetric], rule LeadsTo_UN, auto)\ndone\n\nlemma subset_imp_LeadsTo: \"[| A \\<subseteq> B; F \\<in> program |] ==> F \\<in> A \\<longmapsto>w B\"\napply (simp (no_asm_simp) add: LeadsTo_def)\napply (blast intro: subset_imp_leadsTo)\ndone\n\nlemma empty_LeadsTo: \"F \\<in> 0 \\<longmapsto>w A \\<longleftrightarrow> F \\<in> program\"\nby (auto dest: LeadsTo_type [THEN subsetD]\n            intro: empty_subsetI [THEN subset_imp_LeadsTo])\ndeclare empty_LeadsTo [iff]\n\nlemma LeadsTo_state: \"F \\<in> A \\<longmapsto>w state \\<longleftrightarrow> F \\<in> program\"\nby (auto dest: LeadsTo_type [THEN subsetD] simp add: LeadsTo_eq)\ndeclare LeadsTo_state [iff]\n\nlemma LeadsTo_weaken_R: \"[| F \\<in> A \\<longmapsto>w A';  A'<=B'|] ==> F \\<in> A \\<longmapsto>w B'\"\napply (unfold LeadsTo_def)\napply (auto intro: leadsTo_weaken_R)\ndone\n\nlemma LeadsTo_weaken_L: \"[| F \\<in> A \\<longmapsto>w A'; B \\<subseteq> A |] ==> F \\<in> B \\<longmapsto>w A'\"\napply (unfold LeadsTo_def)\napply (auto intro: leadsTo_weaken_L)\ndone\n\nlemma LeadsTo_weaken: \"[| F \\<in> A \\<longmapsto>w A'; B<=A; A'<=B' |] ==> F \\<in> B \\<longmapsto>w B'\"\nby (blast intro: LeadsTo_weaken_R LeadsTo_weaken_L LeadsTo_Trans)\n\nlemma Always_LeadsTo_weaken:\n\"[| F \\<in> Always(C);  F \\<in> A \\<longmapsto>w A'; C \\<inter> B \\<subseteq> A;   C \\<inter> A' \\<subseteq> B' |]\n      ==> F \\<in> B \\<longmapsto>w B'\"\napply (blast dest: Always_LeadsToI intro: LeadsTo_weaken Always_LeadsToD)\ndone\n\n(** Two theorems for \"proof lattices\" **)\n\nlemma LeadsTo_Un_post: \"F \\<in> A \\<longmapsto>w B ==> F:(A \\<union> B) \\<longmapsto>w B\"\nby (blast dest: LeadsTo_type [THEN subsetD]\n             intro: LeadsTo_Un subset_imp_LeadsTo)\n\nlemma LeadsTo_Trans_Un: \"[| F \\<in> A \\<longmapsto>w B;  F \\<in> B \\<longmapsto>w C |]\n      ==> F \\<in> (A \\<union> B) \\<longmapsto>w C\"\napply (blast intro: LeadsTo_Un subset_imp_LeadsTo LeadsTo_weaken_L LeadsTo_Trans dest: LeadsTo_type [THEN subsetD])\ndone\n\n(** Distributive laws **)\nlemma LeadsTo_Un_distrib: \"(F \\<in> (A \\<union> B) \\<longmapsto>w C)  \\<longleftrightarrow> (F \\<in> A \\<longmapsto>w C & F \\<in> B \\<longmapsto>w C)\"\nby (blast intro: LeadsTo_Un LeadsTo_weaken_L)\n\nlemma LeadsTo_UN_distrib: \"(F \\<in> (\\<Union>i \\<in> I. A(i)) \\<longmapsto>w B) \\<longleftrightarrow>  (\\<forall>i \\<in> I. F \\<in> A(i) \\<longmapsto>w B) & F \\<in> program\"\nby (blast dest: LeadsTo_type [THEN subsetD]\n             intro: LeadsTo_UN LeadsTo_weaken_L)\n\nlemma LeadsTo_Union_distrib: \"(F \\<in> \\<Union>(S) \\<longmapsto>w B)  \\<longleftrightarrow>  (\\<forall>A \\<in> S. F \\<in> A \\<longmapsto>w B) & F \\<in> program\"\nby (blast dest: LeadsTo_type [THEN subsetD]\n             intro: LeadsTo_Union LeadsTo_weaken_L)\n\n(** More rules using the premise \"Always(I)\" **)\n\nlemma EnsuresI: \"[| F:(A-B) Co (A \\<union> B);  F \\<in> transient (A-B) |] ==> F \\<in> A Ensures B\"\napply (simp add: Ensures_def Constrains_eq_constrains)\napply (blast intro: ensuresI constrains_weaken transient_strengthen dest: constrainsD2)\ndone\n\nlemma Always_LeadsTo_Basis: \"[| F \\<in> Always(I); F \\<in> (I \\<inter> (A-A')) Co (A \\<union> A');\n         F \\<in> transient (I \\<inter> (A-A')) |]\n  ==> F \\<in> A \\<longmapsto>w A'\"\napply (rule Always_LeadsToI, assumption)\napply (blast intro: EnsuresI LeadsTo_Basis Always_ConstrainsD [THEN Constrains_weaken] transient_strengthen)\ndone\n\n(*Set difference: maybe combine with leadsTo_weaken_L??\n  This is the most useful form of the \"disjunction\" rule*)\nlemma LeadsTo_Diff:\n     \"[| F \\<in> (A-B) \\<longmapsto>w C;  F \\<in> (A \\<inter> B) \\<longmapsto>w C |] ==> F \\<in> A \\<longmapsto>w C\"\nby (blast intro: LeadsTo_Un LeadsTo_weaken)\n\nlemma LeadsTo_UN_UN:\n     \"[|(!!i. i \\<in> I ==> F \\<in> A(i) \\<longmapsto>w A'(i)); F \\<in> program |]\n      ==> F \\<in> (\\<Union>i \\<in> I. A(i)) \\<longmapsto>w (\\<Union>i \\<in> I. A'(i))\"\napply (rule LeadsTo_Union, auto)\napply (blast intro: LeadsTo_weaken_R)\ndone\n\n(*Binary union version*)\nlemma LeadsTo_Un_Un:\n  \"[| F \\<in> A \\<longmapsto>w A'; F \\<in> B \\<longmapsto>w B' |] ==> F:(A \\<union> B) \\<longmapsto>w (A' \\<union> B')\"\nby (blast intro: LeadsTo_Un LeadsTo_weaken_R)\n\n(** The cancellation law **)\n\nlemma LeadsTo_cancel2: \"[| F \\<in> A \\<longmapsto>w(A' \\<union> B); F \\<in> B \\<longmapsto>w B' |] ==> F \\<in> A \\<longmapsto>w (A' \\<union> B')\"\nby (blast intro: LeadsTo_Un_Un subset_imp_LeadsTo LeadsTo_Trans dest: LeadsTo_type [THEN subsetD])\n\nlemma Un_Diff: \"A \\<union> (B - A) = A \\<union> B\"\nby auto\n\nlemma LeadsTo_cancel_Diff2: \"[| F \\<in> A \\<longmapsto>w (A' \\<union> B); F \\<in> (B-A') \\<longmapsto>w B' |] ==> F \\<in> A \\<longmapsto>w (A' \\<union> B')\"\napply (rule LeadsTo_cancel2)\nprefer 2 apply assumption\napply (simp (no_asm_simp) add: Un_Diff)\ndone\n\nlemma LeadsTo_cancel1: \"[| F \\<in> A \\<longmapsto>w (B \\<union> A'); F \\<in> B \\<longmapsto>w B' |] ==> F \\<in> A \\<longmapsto>w (B' \\<union> A')\"\napply (simp add: Un_commute)\napply (blast intro!: LeadsTo_cancel2)\ndone\n\nlemma Diff_Un2: \"(B - A) \\<union> A = B \\<union> A\"\nby auto\n\nlemma LeadsTo_cancel_Diff1: \"[| F \\<in> A \\<longmapsto>w (B \\<union> A'); F \\<in> (B-A') \\<longmapsto>w B' |] ==> F \\<in> A \\<longmapsto>w (B' \\<union> A')\"\napply (rule LeadsTo_cancel1)\nprefer 2 apply assumption\napply (simp (no_asm_simp) add: Diff_Un2)\ndone\n\n(** The impossibility law **)\n\n(*The set \"A\" may be non-empty, but it contains no reachable states*)\nlemma LeadsTo_empty: \"F \\<in> A \\<longmapsto>w 0 ==> F \\<in> Always (state -A)\"\napply (simp (no_asm_use) add: LeadsTo_def Always_eq_includes_reachable)\napply (cut_tac reachable_type)\napply (auto dest!: leadsTo_empty)\ndone\n\n(** PSP \\<in> Progress-Safety-Progress **)\n\n(*Special case of PSP \\<in> Misra's \"stable conjunction\"*)\nlemma PSP_Stable: \"[| F \\<in> A \\<longmapsto>w A';  F \\<in> Stable(B) |]==> F:(A \\<inter> B) \\<longmapsto>w (A' \\<inter> B)\"\napply (simp add: LeadsTo_def Stable_eq_stable, clarify)\napply (drule psp_stable, assumption)\napply (simp add: Int_ac)\ndone\n\nlemma PSP_Stable2: \"[| F \\<in> A \\<longmapsto>w A'; F \\<in> Stable(B) |] ==> F \\<in> (B \\<inter> A) \\<longmapsto>w (B \\<inter> A')\"\napply (simp (no_asm_simp) add: PSP_Stable Int_ac)\ndone\n\nlemma PSP: \"[| F \\<in> A \\<longmapsto>w A'; F \\<in> B Co B'|]==> F \\<in> (A \\<inter> B') \\<longmapsto>w ((A' \\<inter> B) \\<union> (B' - B))\"\napply (simp (no_asm_use) add: LeadsTo_def Constrains_eq_constrains)\napply (blast dest: psp intro: leadsTo_weaken)\ndone\n\nlemma PSP2: \"[| F \\<in> A \\<longmapsto>w A'; F \\<in> B Co B' |]==> F:(B' \\<inter> A) \\<longmapsto>w ((B \\<inter> A') \\<union> (B' - B))\"\nby (simp (no_asm_simp) add: PSP Int_ac)\n\nlemma PSP_Unless:\n\"[| F \\<in> A \\<longmapsto>w A'; F \\<in> B Unless B'|]==> F:(A \\<inter> B) \\<longmapsto>w ((A' \\<inter> B) \\<union> B')\"\napply (unfold op_Unless_def)\napply (drule PSP, assumption)\napply (blast intro: LeadsTo_Diff LeadsTo_weaken subset_imp_LeadsTo)\ndone\n\n(*** Induction rules ***)\n\n(** Meta or object quantifier ????? **)\nlemma LeadsTo_wf_induct: \"[| wf(r);\n         \\<forall>m \\<in> I. F \\<in> (A \\<inter> f-``{m}) \\<longmapsto>w\n                            ((A \\<inter> f-``(converse(r) `` {m})) \\<union> B);\n         field(r)<=I; A<=f-``I; F \\<in> program |]\n      ==> F \\<in> A \\<longmapsto>w B\"\napply (simp (no_asm_use) add: LeadsTo_def)\napply auto\napply (erule_tac I = I and f = f in leadsTo_wf_induct, safe)\napply (drule_tac [2] x = m in bspec, safe)\napply (rule_tac [2] A' = \"reachable (F) \\<inter> (A \\<inter> f -`` (converse (r) ``{m}) \\<union> B) \" in leadsTo_weaken_R)\napply (auto simp add: Int_assoc)\ndone\n\n\nlemma LessThan_induct: \"[| \\<forall>m \\<in> nat. F:(A \\<inter> f-``{m}) \\<longmapsto>w ((A \\<inter> f-``m) \\<union> B);\n      A<=f-``nat; F \\<in> program |] ==> F \\<in> A \\<longmapsto>w B\"\napply (rule_tac A1 = nat and f1 = \"%x. x\" in wf_measure [THEN LeadsTo_wf_induct])\napply (simp_all add: nat_measure_field)\napply (simp add: ltI Image_inverse_lessThan vimage_def [symmetric])\ndone\n\n\n(******\n To be ported ??? I am not sure.\n\n  integ_0_le_induct\n  LessThan_bounded_induct\n  GreaterThan_bounded_induct\n\n*****)\n\n(*** Completion \\<in> Binary and General Finite versions ***)\n\nlemma Completion: \"[| F \\<in> A \\<longmapsto>w (A' \\<union> C);  F \\<in> A' Co (A' \\<union> C);\n         F \\<in> B \\<longmapsto>w (B' \\<union> C);  F \\<in> B' Co (B' \\<union> C) |]\n      ==> F \\<in> (A \\<inter> B) \\<longmapsto>w ((A' \\<inter> B') \\<union> C)\"\napply (simp (no_asm_use) add: LeadsTo_def Constrains_eq_constrains Int_Un_distrib)\napply (blast intro: completion leadsTo_weaken)\ndone\n\nlemma Finite_completion_aux:\n     \"[| I \\<in> Fin(X);F \\<in> program |]\n      ==> (\\<forall>i \\<in> I. F \\<in> (A(i)) \\<longmapsto>w (A'(i) \\<union> C)) \\<longrightarrow>\n          (\\<forall>i \\<in> I. F \\<in> (A'(i)) Co (A'(i) \\<union> C)) \\<longrightarrow>\n          F \\<in> (\\<Inter>i \\<in> I. A(i)) \\<longmapsto>w ((\\<Inter>i \\<in> I. A'(i)) \\<union> C)\"\napply (erule Fin_induct)\napply (auto simp del: INT_simps simp add: Inter_0)\napply (rule Completion, auto)\napply (simp del: INT_simps add: INT_extend_simps)\napply (blast intro: Constrains_INT)\ndone\n\nlemma Finite_completion:\n     \"[| I \\<in> Fin(X); !!i. i \\<in> I ==> F \\<in> A(i) \\<longmapsto>w (A'(i) \\<union> C);\n         !!i. i \\<in> I ==> F \\<in> A'(i) Co (A'(i) \\<union> C);\n         F \\<in> program |]\n      ==> F \\<in> (\\<Inter>i \\<in> I. A(i)) \\<longmapsto>w ((\\<Inter>i \\<in> I. A'(i)) \\<union> C)\"\nby (blast intro: Finite_completion_aux [THEN mp, THEN mp])\n\nlemma Stable_completion:\n     \"[| F \\<in> A \\<longmapsto>w A';  F \\<in> Stable(A');\n         F \\<in> B \\<longmapsto>w B';  F \\<in> Stable(B') |]\n    ==> F \\<in> (A \\<inter> B) \\<longmapsto>w (A' \\<inter> B')\"\napply (unfold Stable_def)\napply (rule_tac C1 = 0 in Completion [THEN LeadsTo_weaken_R])\n    prefer 5\n    apply blast\napply auto\ndone\n\nlemma Finite_stable_completion:\n     \"[| I \\<in> Fin(X);\n         (!!i. i \\<in> I ==> F \\<in> A(i) \\<longmapsto>w A'(i));\n         (!!i. i \\<in> I ==>F \\<in> Stable(A'(i)));   F \\<in> program  |]\n      ==> F \\<in> (\\<Inter>i \\<in> I. A(i)) \\<longmapsto>w (\\<Inter>i \\<in> I. A'(i))\"\napply (unfold Stable_def)\napply (rule_tac C1 = 0 in Finite_completion [THEN LeadsTo_weaken_R], simp_all)\napply (rule_tac [3] subset_refl, auto)\ndone\n\nML \\<open>\n(*proves \"ensures/leadsTo\" properties when the program is specified*)\nfun ensures_tac ctxt sact =\n  SELECT_GOAL\n    (EVERY [REPEAT (Always_Int_tac ctxt 1),\n            eresolve_tac ctxt @{thms Always_LeadsTo_Basis} 1\n                ORELSE   (*subgoal may involve LeadsTo, leadsTo or ensures*)\n                REPEAT (ares_tac ctxt [@{thm LeadsTo_Basis}, @{thm leadsTo_Basis},\n                                  @{thm EnsuresI}, @{thm ensuresI}] 1),\n            (*now there are two subgoals: co & transient*)\n            simp_tac (ctxt addsimps (Named_Theorems.get ctxt \\<^named_theorems>\\<open>program\\<close>)) 2,\n            Rule_Insts.res_inst_tac ctxt\n              [(((\"act\", 0), Position.none), sact)] [] @{thm transientI} 2,\n               (*simplify the command's domain*)\n            simp_tac (ctxt addsimps [@{thm domain_def}]) 3,\n            (* proving the domain part *)\n           clarify_tac ctxt 3,\n           dresolve_tac ctxt @{thms swap} 3, force_tac ctxt 4,\n           resolve_tac ctxt @{thms ReplaceI} 3, force_tac ctxt 3, force_tac ctxt 4,\n           asm_full_simp_tac ctxt 3, resolve_tac ctxt @{thms conjI} 3, simp_tac ctxt 4,\n           REPEAT (resolve_tac ctxt @{thms state_update_type} 3),\n           constrains_tac ctxt 1,\n           ALLGOALS (clarify_tac ctxt),\n           ALLGOALS (asm_full_simp_tac (ctxt addsimps [@{thm st_set_def}])),\n                      ALLGOALS (clarify_tac ctxt),\n          ALLGOALS (asm_lr_simp_tac ctxt)]);\n\\<close>\n\nmethod_setup ensures = \\<open>\n    Args.goal_spec -- Scan.lift Args.embedded_inner_syntax >>\n    (fn (quant, s) => fn ctxt => SIMPLE_METHOD'' quant (ensures_tac ctxt s))\n\\<close> \"for proving progress properties\"\n\nend\n", "meta": {"author": "landonf", "repo": "isabelle-legacy", "sha": "e40f3ca7e9a42bb91e57fd15f969388e6e83f692", "save_path": "github-repos/isabelle/landonf-isabelle-legacy", "path": "github-repos/isabelle/landonf-isabelle-legacy/isabelle-legacy-e40f3ca7e9a42bb91e57fd15f969388e6e83f692/src/ZF/UNITY/SubstAx.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5813031051514762, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.2793037475083248}}
{"text": "theory Channel\n  imports\n    \"../Fused_Resource\"\nbegin\n\nsection \\<open>Channel specification\\<close>\n\nlocale ideal_channel =\n  fixes \n  (*TODO: decide to either include or exlude this fixation,\n    - if it is not included, then the types must be manually stated whenever channel locale is imported (c.f. OTP and DH)\n    - also, the WT_intro rules for channel will have an unspecified valid_messages*)\n  (*  valid_messages :: \"'msg set\" and*)\n    leak :: \"'msg \\<Rightarrow> 'leak\" and\n    editable :: bool\nbegin\n\n\nsubsection \\<open>Data-types for Parties, State, Events, Input, and Output\\<close>\n\ndatatype party = Alice | Bob\n\ntype_synonym s_shell = \"party set\"\ndatatype 'msg' s_kernel =  State_Void | State_Store 'msg' | State_Collect 'msg' | State_Collected\ntype_synonym 'msg' state = \"'msg' s_kernel \\<times> s_shell\"\n\ndatatype event = Event_Shell party\n\ndatatype iadv_drop = Inp_Drop\ndatatype iadv_look = Inp_Look\ndatatype 'msg' iadv_fedit = Inp_Fedit 'msg'\ntype_synonym 'msg' iadv = \"iadv_drop + iadv_look + 'msg' iadv_fedit\"\n\ndatatype 'msg' iusr_alice = Inp_Send 'msg'\ndatatype iusr_bob = Inp_Recv\ntype_synonym 'msg' iusr = \"'msg' iusr_alice + iusr_bob\"\n\ndatatype oadv_drop = Out_Drop\ndatatype 'leak' oadv_look = Out_Look 'leak'\ndatatype oadv_fedit = Out_Fedit\ntype_synonym 'leak' oadv = \"oadv_drop + 'leak' oadv_look + oadv_fedit\"\n\ndatatype ousr_alice = Out_Send\ndatatype 'msg' ousr_bob = Out_Recv 'msg'\ntype_synonym 'msg' ousr = \"ousr_alice + 'msg' ousr_bob\"\n\n\nsubsubsection \\<open>Basic lemmas for automated handling of party sets (i.e. @{text s_shell})\\<close>\n\nlemma Alice_neq_iff [simp]: \"Alice \\<noteq> x \\<longleftrightarrow> x = Bob\"\n  by(cases x) simp_all\n\nlemma neq_Alice_iff [simp]: \"x \\<noteq> Alice \\<longleftrightarrow> x = Bob\"\n  by(cases x) simp_all\n\nlemma Bob_neq_iff [simp]: \"Bob \\<noteq> x \\<longleftrightarrow> x = Alice\"\n  by(cases x) simp_all\n\nlemma neq_Bob_iff [simp]: \"x \\<noteq> Bob \\<longleftrightarrow> x = Alice\"\n  by(cases x) simp_all\n\nlemma Alice_in_iff_nonempty: \"Alice \\<in> A \\<longleftrightarrow> A \\<noteq> {}\" if \"Bob \\<notin> A\"\n  using that by(auto)(metis (full_types) party.exhaust)\n\nlemma Bob_in_iff_nonempty: \"Bob \\<in> A \\<longleftrightarrow> A \\<noteq> {}\" if \"Alice \\<notin> A\"\n  using that by(auto)(metis (full_types) party.exhaust)\n\n\nsubsection \\<open>Defining the event handler\\<close>\n\nfun poke :: \"('msg state, event) handler\"\n  where\n    \"poke (s_kernel, parties) (Event_Shell party) =\n      (if party \\<in> parties then \n        return_pmf None \n      else \n        return_spmf (s_kernel, insert party parties))\"\n\nlemma poke_alt_def:\n  \"poke = (\\<lambda>(s, ps) e. map_spmf (Pair s) (case e of Event_Shell party \\<Rightarrow> if party \\<in> ps then return_pmf None else return_spmf (insert party ps)))\"\n  by(simp add: fun_eq_iff split: event.split)\n\nsubsection \\<open>Defining the adversary interfaces\\<close>\n\nfun iface_drop :: \"('msg state, iadv_drop, oadv_drop) oracle'\"\n  where\n    \"iface_drop _ _ = return_pmf None\"\n\nfun iface_look :: \"('msg state, iadv_look, 'leak oadv_look) oracle'\"\n  where\n    \"iface_look (State_Store msg, parties) _ =\n      return_spmf (Out_Look (leak msg), State_Store msg, parties)\"\n  | \"iface_look _ _ = return_pmf None\"\n\nfun iface_fedit :: \"('msg state, 'msg iadv_fedit, oadv_fedit) oracle'\"\n  where\n    \"iface_fedit (State_Store msg, parties) (Inp_Fedit msg') = \n      (if editable then\n        return_spmf (Out_Fedit, State_Collect msg', parties)\n      else\n        return_spmf (Out_Fedit, State_Collect msg, parties))\"\n  | \"iface_fedit _ _ = return_pmf None\"\n\nabbreviation iface_adv :: \"('msg state, 'msg iadv, 'leak oadv) oracle'\"\n  where\n    \"iface_adv \\<equiv> plus_oracle iface_drop (plus_oracle iface_look iface_fedit)\"\n\nlemma in_set_spmf_iface_drop: \"ys' \\<in> set_spmf (iface_drop s x) \\<longleftrightarrow> False\"\n  by simp\n\nlemma in_set_spmf_iface_look: \"ys' \\<in> set_spmf (iface_look s x) \\<longleftrightarrow>\n  (\\<exists>msg parties. s = (State_Store msg, parties) \\<and> ys' = (Out_Look (leak msg), State_Store msg, parties))\"\n  by(cases \"(s, x)\" rule: iface_look.cases) simp_all\n\nlemma in_set_spmf_iface_fedit: \"ys' \\<in> set_spmf (iface_fedit s x) \\<longleftrightarrow>\n  (\\<exists>msg parties msg'. s = (State_Store msg, parties) \\<and> x = (Inp_Fedit msg') \\<and>\n      ys' = (if editable then (Out_Fedit, State_Collect msg', parties) else (Out_Fedit, State_Collect msg, parties)))\"\n  by(cases \"(s, x)\" rule: iface_fedit.cases) simp_all\n\nsubsection \\<open>Defining the user interfaces\\<close>\n\nfun iface_alice :: \"('msg state, 'msg iusr_alice, ousr_alice) oracle'\"\n  where\n    \"iface_alice (State_Void, parties) (Inp_Send msg) = \n      (if Alice \\<in> parties then\n        return_spmf (Out_Send, State_Store msg, parties)\n      else\n        return_pmf None)\"\n  | \"iface_alice _ _ = return_pmf None\"\n\nfun iface_bob :: \"('msg state, iusr_bob, 'msg ousr_bob) oracle'\"\n  where\n    \"iface_bob (State_Collect msg, parties) _ = \n      (if Bob \\<in> parties then\n        return_spmf (Out_Recv msg, State_Collected, parties)\n      else\n        return_pmf None)\"\n  | \"iface_bob _ _ = return_pmf None\"\n\nabbreviation iface_usr :: \"('msg state, 'msg iusr, 'msg ousr) oracle'\"\n  where\n    \"iface_usr \\<equiv> plus_oracle iface_alice iface_bob\"\n\nlemma in_set_spmf_iface_alice: \"ys' \\<in> set_spmf (iface_alice s x) \\<longleftrightarrow>\n  (\\<exists>parties msg. s = (State_Void, parties) \\<and> x = Inp_Send msg \\<and> Alice \\<in> parties \\<and> ys' = (Out_Send, State_Store msg, parties))\"\n  by(cases \"(s, x)\" rule: iface_alice.cases) simp_all\n\nlemma in_set_spmf_iface_bob: \"ys' \\<in> set_spmf (iface_bob s x) \\<longleftrightarrow>\n  (\\<exists>msg parties. s = (State_Collect msg, parties) \\<and> Bob \\<in> parties \\<and> ys' = (Out_Recv msg, State_Collected, parties))\"\n  by(cases \"(s, x)\" rule: iface_bob.cases) simp_all\n\nsubsection \\<open>Defining the Fused Resource\\<close>\n\nprimcorec core :: \"('msg state, event, 'msg iadv, 'msg iusr, 'leak oadv, 'msg ousr) core\" \n  where\n    \"cpoke core = poke\"\n  | \"cfunc_adv core = iface_adv\"\n  | \"cfunc_usr core = iface_usr\"\n\nsublocale fused_resource core \"(State_Void, {})\" .\n\n\nsubsubsection \\<open>Lemma showing that the resulting resource is well-typed\\<close>\n\nlemma WT_core [WT_intro]:\n  \"WT_core (\\<I>_full \\<oplus>\\<^sub>\\<I> (\\<I>_full \\<oplus>\\<^sub>\\<I> \\<I>_uniform (Inp_Fedit ` valid_messages) UNIV)) (\\<I>_uniform (Inp_Send ` valid_messages) UNIV \\<oplus>\\<^sub>\\<I> (\\<I>_uniform UNIV (Out_Recv ` valid_messages)))\n     (pred_prod (pred_s_kernel (\\<lambda>msg. msg \\<in> valid_messages)) (\\<lambda>_. True)) core\"\n  apply(rule WT_core.intros)\n  subgoal for s e s' by(cases \"(s, e)\" rule: poke.cases)(auto split: if_split_asm)\n  subgoal for s x y s' by(cases \"(s, projl (projr x))\" rule: iface_look.cases)(auto split: if_split_asm)\n  subgoal for s x y s' by(cases \"(s, projl x)\" rule: iface_alice.cases)(auto split: if_split_asm)\n  done\n\nlemma WT_fuse [WT_intro]: \n  assumes [WT_intro]: \"WT_rest \\<I>_adv_rest \\<I>_usr_rest I_rest rest\"\n    shows  \"((\\<I>_full \\<oplus>\\<^sub>\\<I> (\\<I>_full \\<oplus>\\<^sub>\\<I> \\<I>_uniform (Inp_Fedit ` valid_messages) UNIV)) \\<oplus>\\<^sub>\\<I> \\<I>_adv_rest) \\<oplus>\\<^sub>\\<I> \n      ((\\<I>_uniform (Inp_Send ` valid_messages) UNIV \\<oplus>\\<^sub>\\<I> \\<I>_uniform UNIV (Out_Recv ` valid_messages)) \\<oplus>\\<^sub>\\<I> \\<I>_usr_rest) \\<turnstile>res resource rest \\<surd>\"\n  by(rule WT_intro)+ simp\n\n\nend\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Constructive_Cryptography_CM/Specifications/Channel.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5813030761371503, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.27930373356755983}}
{"text": "theory Common_Primitive_Matcher\nimports Common_Primitive_Matcher_Generic\nbegin\n\n\nsubsection\\<open>Primitive Matchers: IP Port Iface Matcher\\<close>\n\n(*IPv4 matcher*)\nfun common_matcher :: \"('i::len common_primitive, ('i, 'a) tagged_packet_scheme) exact_match_tac\" where\n  \"common_matcher (IIface i) p = bool_to_ternary (match_iface i (p_iiface p))\" |\n  \"common_matcher (OIface i) p = bool_to_ternary (match_iface i (p_oiface p))\" |\n\n  \"common_matcher (Src ip) p = bool_to_ternary (p_src p \\<in> ipt_iprange_to_set ip)\" |\n  \"common_matcher (Dst ip) p = bool_to_ternary (p_dst p \\<in> ipt_iprange_to_set ip)\" |\n\n  \"common_matcher (Prot proto) p = bool_to_ternary (match_proto proto (p_proto p))\" |\n\n  \"common_matcher (Src_Ports (L4Ports proto ps)) p = bool_to_ternary (proto = p_proto p \\<and> p_sport p \\<in> ports_to_set ps)\" |\n  \"common_matcher (Dst_Ports (L4Ports proto ps)) p = bool_to_ternary (proto = p_proto p \\<and> p_dport p \\<in> ports_to_set ps)\" |\n\n  \"common_matcher (MultiportPorts (L4Ports proto ps)) p = bool_to_ternary (proto = p_proto p \\<and> (p_sport p \\<in> ports_to_set ps \\<or> p_dport p \\<in> ports_to_set ps))\" |\n\n  \"common_matcher (L4_Flags flags) p = bool_to_ternary (match_tcp_flags flags (p_tcp_flags p))\" |\n\n  \"common_matcher (CT_State S) p = bool_to_ternary (match_ctstate S (p_tag_ctstate p))\" |\n\n  \"common_matcher (Extra _) p = TernaryUnknown\"\n\n\n\nlemma packet_independent_\\<beta>_unknown_common_matcher: \"packet_independent_\\<beta>_unknown common_matcher\"\n  apply(simp add: packet_independent_\\<beta>_unknown_def)\n  apply(clarify)\n  apply(rename_tac a p1 p2)\n  apply(case_tac a)\n             apply(simp_all add: bool_to_ternary_Unknown)\n     apply(rename_tac l4ports, case_tac l4ports; simp add: bool_to_ternary_Unknown; fail)+\n  done\n\nlemma primitive_matcher_generic_common_matcher: \"primitive_matcher_generic common_matcher\"\n  by unfold_locales  simp_all\n\n  (* What if we specify a port range where the start port is greater than the end port?\n    For example, mathematically, {3 .. 2} = {}. Does iptables have the same behavior?\n    For example, --source-port 1:0 raises an error on my system. For normal port specification, -m tcp, and -m multiport.\n    There is also a manpage which states \"if the first port is greater than the second one they will be swapped.\"\n    I also saw a system where such an empty port range (--source-port 1:0) was really this impossible range and caused a rule that could never match.\n    Because \\<nexists> port. port \\<in> {}.\n    The behaviour if the end of the port range is smaller than the start is not 100% consistent among iptables versions and different modules.\n    In general, it would be best to raise an error if such a range occurs.\n    *)\n\n  text\\<open>Warning: beware of the sloppy term `empty' portrange\\<close>\n  text\\<open>An `empty' port range means it can never match! Basically, @{term \"MatchNot (Match (Src_Ports (L4Ports proto [(0,65535)])))\"} is False\\<close>\n  lemma \"\\<not> matches (common_matcher, \\<alpha>) (MatchNot (Match (Src_Ports (L4Ports TCP [(0,65535)])))) a \n          \\<lparr>p_iiface = ''eth0'', p_oiface = ''eth1'',\n           p_src = ipv4addr_of_dotdecimal (192,168,2,45), p_dst= ipv4addr_of_dotdecimal (173,194,112,111),\n           p_proto=TCP, p_sport=2065, p_dport=80, p_tcp_flags = {},\n           p_payload = '''', p_tag_ctstate = CT_New\\<rparr>\"\n       by(simp add: primitive_matcher_generic_common_matcher primitive_matcher_generic.Ports_single_not)\n  text\\<open>An `empty' port range means it always matches! Basically, @{term \"(MatchNot (Match (Src_Ports (L4Ports any []))))\"} is True.\n        This corresponds to firewall behavior, but usually you cannot specify an empty portrange in firewalls, but omission of portrange means no-port-restrictions, \n        i.e. every port matches.\\<close>\n  lemma \"matches (common_matcher, \\<alpha>) (MatchNot (Match (Src_Ports (L4Ports any [])))) a \n          \\<lparr>p_iiface = ''eth0'', p_oiface = ''eth1'',\n           p_src = ipv4addr_of_dotdecimal (192,168,2,45), p_dst= ipv4addr_of_dotdecimal (173,194,112,111),\n           p_proto=TCP, p_sport=2065, p_dport=80, p_tcp_flags = {},\n           p_payload = '''', p_tag_ctstate = CT_New\\<rparr>\"\n       by(simp add: primitive_matcher_generic_common_matcher primitive_matcher_generic.Ports_single_not)\n  text\\<open>If not a corner case, portrange matching is straight forward.\\<close>\n  lemma \"matches (common_matcher, \\<alpha>) (Match (Src_Ports (L4Ports TCP [(1024,4096), (9999, 65535)]))) a \n          \\<lparr>p_iiface = ''eth0'', p_oiface = ''eth1'',\n           p_src = ipv4addr_of_dotdecimal (192,168,2,45), p_dst= ipv4addr_of_dotdecimal (173,194,112,111),\n           p_proto=TCP, p_sport=2065, p_dport=80, p_tcp_flags = {},\n           p_payload = '''', p_tag_ctstate = CT_New\\<rparr>\"\n        \"\\<not> matches (common_matcher, \\<alpha>) (Match (Src_Ports (L4Ports TCP [(1024,4096), (9999, 65535)]))) a \n          \\<lparr>p_iiface = ''eth0'', p_oiface = ''eth1'',\n           p_src = ipv4addr_of_dotdecimal (192,168,2,45), p_dst= ipv4addr_of_dotdecimal (173,194,112,111),\n           p_proto=TCP, p_sport=5000, p_dport=80, p_tcp_flags = {},\n           p_payload = '''', p_tag_ctstate = CT_New\\<rparr>\"\n        \"\\<not>matches (common_matcher, \\<alpha>) (MatchNot (Match (Src_Ports (L4Ports TCP [(1024,4096), (9999, 65535)])))) a \n          \\<lparr>p_iiface = ''eth0'', p_oiface = ''eth1'',\n           p_src = ipv4addr_of_dotdecimal (192,168,2,45), p_dst= ipv4addr_of_dotdecimal (173,194,112,111),\n           p_proto=TCP, p_sport=2065, p_dport=80, p_tcp_flags = {},\n           p_payload = '''', p_tag_ctstate = CT_New\\<rparr>\"\n       by(simp_all add: primitive_matcher_generic_common_matcher primitive_matcher_generic.Ports_single_not primitive_matcher_generic.Ports_single)\n  \n\n\n\ntext\\<open>Lemmas when matching on @{term Src} or @{term Dst}\\<close>\nlemma common_matcher_SrcDst_defined:\n  \"common_matcher (Src m) p \\<noteq> TernaryUnknown\"\n  \"common_matcher (Dst m) p \\<noteq> TernaryUnknown\"\n  \"common_matcher (Src_Ports ps) p \\<noteq> TernaryUnknown\"\n  \"common_matcher (Dst_Ports ps) p \\<noteq> TernaryUnknown\"\n  \"common_matcher (MultiportPorts ps) p \\<noteq> TernaryUnknown\"\n  apply(case_tac [!] m, case_tac [!] ps)\n  apply(simp_all add: bool_to_ternary_Unknown)\n  done\nlemma common_matcher_SrcDst_defined_simp:\n  \"common_matcher (Src x) p \\<noteq> TernaryFalse \\<longleftrightarrow> common_matcher (Src x) p = TernaryTrue\"\n  \"common_matcher (Dst x) p \\<noteq> TernaryFalse \\<longleftrightarrow> common_matcher (Dst x) p = TernaryTrue\"\napply (metis eval_ternary_Not.cases common_matcher_SrcDst_defined(1) ternaryvalue.distinct(1))\napply (metis eval_ternary_Not.cases common_matcher_SrcDst_defined(2) ternaryvalue.distinct(1))\ndone\n\n(*The primitive_matcher_generic does not know anything about IP addresses*)\nlemma match_simplematcher_SrcDst:\n  \"matches (common_matcher, \\<alpha>) (Match (Src X)) a p \\<longleftrightarrow> p_src  p \\<in> ipt_iprange_to_set X\"\n  \"matches (common_matcher, \\<alpha>) (Match (Dst X)) a p \\<longleftrightarrow> p_dst  p \\<in> ipt_iprange_to_set X\"\n   by(simp_all add: match_raw_ternary bool_to_ternary_simps split: ternaryvalue.split)\nlemma match_simplematcher_SrcDst_not:\n  \"matches (common_matcher, \\<alpha>) (MatchNot (Match (Src X))) a p \\<longleftrightarrow> p_src  p \\<notin> ipt_iprange_to_set X\"\n  \"matches (common_matcher, \\<alpha>) (MatchNot (Match (Dst X))) a p \\<longleftrightarrow> p_dst  p \\<notin> ipt_iprange_to_set X\"\n   apply(simp_all add: matches_case_ternaryvalue_tuple split: ternaryvalue.split)\n   apply(case_tac [!] X)\n   apply(simp_all add: bool_to_ternary_simps)\n   done\nlemma common_matcher_SrcDst_Inter:\n  \"(\\<forall>m\\<in>set X. matches (common_matcher, \\<alpha>) (Match (Src m)) a p) \\<longleftrightarrow> p_src p \\<in> (\\<Inter>x\\<in>set X. ipt_iprange_to_set x)\"\n  \"(\\<forall>m\\<in>set X. matches (common_matcher, \\<alpha>) (Match (Dst m)) a p) \\<longleftrightarrow> p_dst p \\<in> (\\<Inter>x\\<in>set X. ipt_iprange_to_set x)\"\n  by(simp_all add: match_raw_ternary bool_to_ternary_simps split: ternaryvalue.split)\n\n\n\n\n\nsubsection\\<open>Basic optimisations\\<close>\n  text\\<open>Perform very basic optimization. Remove matches to primitives which are essentially @{const MatchAny}\\<close>\n  fun optimize_primitive_univ :: \"'i::len common_primitive match_expr \\<Rightarrow> 'i common_primitive match_expr\" where\n    \"optimize_primitive_univ (Match (Src (IpAddrNetmask _ 0))) = MatchAny\" |\n    \"optimize_primitive_univ (Match (Dst (IpAddrNetmask _ 0))) = MatchAny\" |\n    (*missing: the other IPs ...*)\n    \"optimize_primitive_univ (Match (IIface iface)) = (if iface = ifaceAny then MatchAny else (Match (IIface iface)))\" |\n    \"optimize_primitive_univ (Match (OIface iface)) = (if iface = ifaceAny then MatchAny else (Match (OIface iface)))\" |\n    (*missing: L4Ports. But this introduces a new match, which causes problems.\n    \"optimize_primitive_univ (Match (Src_Ports (L4Ports proto [(s, e)]))) = (if s = 0 \\<and> e = 0xFFFF then (Match (Prot (Proto proto))) else (Match (Src_Ports (L4Ports proto [(s, e)]))))\" |\n    \"optimize_primitive_univ (Match (Dst_Ports (L4Ports proto [(s, e)]))) = (if s = 0 \\<and> e = 0xFFFF then (Match (Prot (Proto proto))) else (Match (Dst_Ports (L4Ports proto [(s, e)]))))\" |*)\n    \"optimize_primitive_univ (Match (Prot ProtoAny)) = MatchAny\" |\n    \"optimize_primitive_univ (Match (L4_Flags (TCP_Flags m c))) = (if m = {} \\<and> c = {} then MatchAny else (Match (L4_Flags (TCP_Flags m c))))\" |\n    \"optimize_primitive_univ (Match (CT_State ctstate)) = (if ctstate_is_UNIV ctstate then MatchAny else Match (CT_State ctstate))\" |\n    \"optimize_primitive_univ (Match m) = Match m\" |\n    (*\"optimize_primitive_univ (MatchNot (MatchNot m)) = (optimize_primitive_univ m)\" | --\"needed to preserve normalized condition\"*)\n    \"optimize_primitive_univ (MatchNot m) = (MatchNot (optimize_primitive_univ m))\" |\n    (*\"optimize_primitive_univ (MatchAnd (Match (Extra e1)) (Match (Extra e2))) = optimize_primitive_univ (Match (Extra (e1@'' ''@e2)))\" |\n      -- \"can be done but normalization does not work afterwards\"*)\n    \"optimize_primitive_univ (MatchAnd m1 m2) = MatchAnd (optimize_primitive_univ m1) (optimize_primitive_univ m2)\" |\n    \"optimize_primitive_univ MatchAny = MatchAny\"\n\n    lemma optimize_primitive_univ_unchanged_primitives:\n    \"optimize_primitive_univ (Match a) = (Match a) \\<or> optimize_primitive_univ (Match a) = MatchAny\"\n      by (induction \"(Match a)\" rule: optimize_primitive_univ.induct)\n         (auto split: if_split_asm)\n    \n  \n  lemma optimize_primitive_univ_correct_matchexpr: fixes m::\"'i::len common_primitive match_expr\"\n    shows \"matches (common_matcher, \\<alpha>) m = matches (common_matcher, \\<alpha>) (optimize_primitive_univ m)\"\n    proof(simp add: fun_eq_iff, clarify, rename_tac a p)\n      fix a and p :: \"('i::len, 'a) tagged_packet_scheme\"\n      have \"(max_word::16 word) =  65535\" by(simp add: max_word_def)\n      hence port_range: \"\\<And>s e port. s = 0 \\<and> e = 0xFFFF \\<longrightarrow> (port::16 word) \\<le> 0xFFFF\" by simp\n      have \"ternary_ternary_eval (map_match_tac common_matcher p m) = ternary_ternary_eval (map_match_tac common_matcher p (optimize_primitive_univ m))\"\n        apply(induction m rule: optimize_primitive_univ.induct)\n                               by(simp_all add: port_range match_ifaceAny ipset_from_cidr_0 ctstate_is_UNIV)\n         (*by(fastforce intro: arg_cong[where f=bool_to_ternary])+ if we add pots again*)\n      thus \"matches (common_matcher, \\<alpha>) m a p = matches (common_matcher, \\<alpha>) (optimize_primitive_univ m) a p\"\n        by(rule matches_iff_apply_f)\n      qed\n  \n  corollary optimize_primitive_univ_correct: \"approximating_bigstep_fun (common_matcher, \\<alpha>) p (optimize_matches optimize_primitive_univ rs) s = \n                                              approximating_bigstep_fun (common_matcher, \\<alpha>) p rs s\"\n  using optimize_matches optimize_primitive_univ_correct_matchexpr by metis\n  \n  \nsubsection\\<open>Abstracting over unknowns\\<close>\n  text\\<open>remove @{const Extra} (i.e. @{const TernaryUnknown}) match expressions\\<close>\n  fun upper_closure_matchexpr :: \"action \\<Rightarrow> 'i::len common_primitive match_expr \\<Rightarrow> 'i common_primitive match_expr\" where\n    \"upper_closure_matchexpr _ MatchAny = MatchAny\" |\n    \"upper_closure_matchexpr Accept (Match (Extra _)) = MatchAny\" |\n    \"upper_closure_matchexpr Reject (Match (Extra _)) = MatchNot MatchAny\" |\n    \"upper_closure_matchexpr Drop (Match (Extra _)) = MatchNot MatchAny\" |\n    \"upper_closure_matchexpr _ (Match m) = Match m\" |\n    \"upper_closure_matchexpr Accept (MatchNot (Match (Extra _))) = MatchAny\" |\n    \"upper_closure_matchexpr Drop (MatchNot (Match (Extra _))) = MatchNot MatchAny\" |\n    \"upper_closure_matchexpr Reject (MatchNot (Match (Extra _))) = MatchNot MatchAny\" |\n    \"upper_closure_matchexpr a (MatchNot (MatchNot m)) = upper_closure_matchexpr a m\" |\n    \"upper_closure_matchexpr a (MatchNot (MatchAnd m1 m2)) = \n      (let m1' = upper_closure_matchexpr a (MatchNot m1); m2' = upper_closure_matchexpr a (MatchNot m2) in\n      (if m1' = MatchAny \\<or> m2' = MatchAny\n       then MatchAny\n       else \n          if m1' = MatchNot MatchAny then m2' else\n          if m2' = MatchNot MatchAny then m1'\n       else\n          MatchNot (MatchAnd (MatchNot m1') (MatchNot m2')))\n         )\" |\n    \"upper_closure_matchexpr _ (MatchNot m) = MatchNot m\" | \n    \"upper_closure_matchexpr a (MatchAnd m1 m2) = MatchAnd (upper_closure_matchexpr a m1) (upper_closure_matchexpr a m2)\"\n  \n  lemma upper_closure_matchexpr_generic: \n    \"a = Accept \\<or> a = Drop \\<Longrightarrow> remove_unknowns_generic (common_matcher, in_doubt_allow) a m = upper_closure_matchexpr a m\"\n    by(induction a m rule: upper_closure_matchexpr.induct)\n      (simp_all add: remove_unknowns_generic_simps2 bool_to_ternary_Unknown common_matcher_SrcDst_defined)\n  \n  fun lower_closure_matchexpr :: \"action \\<Rightarrow> 'i::len common_primitive match_expr \\<Rightarrow> 'i common_primitive match_expr\" where\n    \"lower_closure_matchexpr _ MatchAny = MatchAny\" |\n    \"lower_closure_matchexpr Accept (Match (Extra _)) = MatchNot MatchAny\" |\n    \"lower_closure_matchexpr Reject (Match (Extra _)) = MatchAny\" |\n    \"lower_closure_matchexpr Drop (Match (Extra _)) = MatchAny\" |\n    \"lower_closure_matchexpr _ (Match m) = Match m\" |\n    \"lower_closure_matchexpr Accept (MatchNot (Match (Extra _))) = MatchNot MatchAny\" |\n    \"lower_closure_matchexpr Drop (MatchNot (Match (Extra _))) = MatchAny\" |\n    \"lower_closure_matchexpr Reject (MatchNot (Match (Extra _))) = MatchAny\" |\n    \"lower_closure_matchexpr a (MatchNot (MatchNot m)) = lower_closure_matchexpr a m\" |\n    \"lower_closure_matchexpr a (MatchNot (MatchAnd m1 m2)) = \n      (let m1' = lower_closure_matchexpr a (MatchNot m1); m2' = lower_closure_matchexpr a (MatchNot m2) in\n      (if m1' = MatchAny \\<or> m2' = MatchAny\n       then MatchAny\n       else \n          if m1' = MatchNot MatchAny then m2' else\n          if m2' = MatchNot MatchAny then m1'\n       else\n          MatchNot (MatchAnd (MatchNot m1') (MatchNot m2')))\n         )\" |\n    \"lower_closure_matchexpr _ (MatchNot m) = MatchNot m\" | \n    \"lower_closure_matchexpr a (MatchAnd m1 m2) = MatchAnd (lower_closure_matchexpr a m1) (lower_closure_matchexpr a m2)\"\n  \n  lemma lower_closure_matchexpr_generic: \n    \"a = Accept \\<or> a = Drop \\<Longrightarrow> remove_unknowns_generic (common_matcher, in_doubt_deny) a m = lower_closure_matchexpr a m\"\n    by(induction a m rule: lower_closure_matchexpr.induct)\n    (simp_all add: remove_unknowns_generic_simps2 bool_to_ternary_Unknown common_matcher_SrcDst_defined)\n\n\n\nend\n", "meta": {"author": "diekmann", "repo": "Iptables_Semantics", "sha": "e0a2516bd885708fce875023b474ae341cbdee29", "save_path": "github-repos/isabelle/diekmann-Iptables_Semantics", "path": "github-repos/isabelle/diekmann-Iptables_Semantics/Iptables_Semantics-e0a2516bd885708fce875023b474ae341cbdee29/thy/Iptables_Semantics/Primitive_Matchers/Common_Primitive_Matcher.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6791787121629466, "lm_q2_score": 0.411110869232168, "lm_q1q2_score": 0.2792177507212934}}
{"text": "subsection \\<open>CISK (Controlled Interruptible Separation Kernel)\\<close>\n\ntheory CISK\n  imports ISK\nbegin\n\ntext \\<open>\n  This section presents a generic model of a Controlled Interruptible Separation Kernel (CISK).\n  It formulates security, i.e., intransitive noninterference.\n  For a presentation of this model, see Section 2 of~\\<^cite>\\<open>\"Verbeek2013\"\\<close>.\n\\<close>\n\ntext \\<open>\n  First, a locale is defined that defines all generic functions and all proof obligations (see Section 2.3 of ~\\<^cite>\\<open>\"Verbeek2013\"\\<close>).\n\\<close>\nlocale Controllable_Interruptible_Separation_Kernel = \\<comment> \\<open>CISK\\<close>\nfixes kstep :: \"'state_t \\<Rightarrow> 'action_t \\<Rightarrow> 'state_t\" \\<comment> \\<open>Executes one atomic kernel action\\<close>\n  and output_f :: \"'state_t \\<Rightarrow> 'action_t \\<Rightarrow> 'output_t\" \\<comment> \\<open>Returns the observable behavior\\<close>\n  and s0 :: \"'state_t\" \\<comment> \\<open>The initial state\\<close>\n  and current :: \"'state_t => 'dom_t\" \\<comment> \\<open>Returns the currently active domain\\<close>\n  and cswitch :: \"time_t \\<Rightarrow> 'state_t \\<Rightarrow> 'state_t\" \\<comment> \\<open>Performs a context switch\\<close>\n  and interrupt :: \"time_t \\<Rightarrow> bool\" \\<comment> \\<open>Returns t iff an interrupt occurs in the given state at the given time\\<close>\n  and kinvolved :: \"'action_t \\<Rightarrow> 'dom_t set\" \\<comment> \\<open>Returns the set of domains that are involved in the given action\\<close>\n  and ifp :: \"'dom_t \\<Rightarrow> 'dom_t \\<Rightarrow> bool\" \\<comment> \\<open>The security policy.\\<close>\n  and vpeq :: \"'dom_t \\<Rightarrow> 'state_t \\<Rightarrow> 'state_t \\<Rightarrow> bool\" \\<comment> \\<open>View partitioning equivalence\\<close>\n  and AS_set :: \"('action_t list) set\" \\<comment> \\<open>Returns a set of valid action sequences, i.e., the attack surface\\<close>\n  and invariant :: \"'state_t \\<Rightarrow> bool\" \\<comment> \\<open>Returns an inductive state-invariant\\<close>\n  and AS_precondition :: \"'state_t \\<Rightarrow> 'dom_t \\<Rightarrow> 'action_t \\<Rightarrow> bool\" \\<comment> \\<open>Returns the preconditions under which the given action can be executed.\\<close>  \n  and aborting :: \"'state_t \\<Rightarrow> 'dom_t \\<Rightarrow> 'action_t \\<Rightarrow> bool\" \\<comment> \\<open>Returns true iff the action is aborted.\\<close>\n  and waiting :: \"'state_t \\<Rightarrow> 'dom_t \\<Rightarrow> 'action_t \\<Rightarrow> bool\" \\<comment> \\<open>Returns true iff execution of the given action is delayed.\\<close>\n  and set_error_code :: \"'state_t \\<Rightarrow> 'action_t \\<Rightarrow> 'state_t\" \\<comment> \\<open>Sets an error code when actions are aborted.\\<close>\nassumes vpeq_transitive: \" \\<forall> a b c u. (vpeq u a b \\<and> vpeq u b c) \\<longrightarrow> vpeq u a c\"\n    and vpeq_symmetric: \"\\<forall> a b u. vpeq u a b \\<longrightarrow> vpeq u b a\"\n    and vpeq_reflexive: \"\\<forall> a u. vpeq u a a\"\n    and ifp_reflexive: \"\\<forall> u . ifp u u\"     \n    and weakly_step_consistent: \"\\<forall> s t u a. vpeq u s t \\<and> vpeq (current s) s t \\<and> invariant s \\<and> AS_precondition s (current s) a \\<and> invariant t \\<and> AS_precondition t (current t) a \\<and> current s = current t  \\<longrightarrow> vpeq u (kstep s a) (kstep t a)\"\n    and locally_respects: \"\\<forall> a s u. \\<not>ifp (current s) u  \\<and> invariant s \\<and> AS_precondition s (current s) a \\<longrightarrow> vpeq u s (kstep s a)\"\n    and output_consistent: \"\\<forall> a s t. vpeq (current s) s t \\<and> current s = current t \\<longrightarrow> (output_f s a) = (output_f t a)\"\n    and step_atomicity: \"\\<forall> s a . current (kstep s a) = current s\"\n    and cswitch_independent_of_state: \"\\<forall> n s t . current s = current t \\<longrightarrow> current (cswitch n s) = current (cswitch n t)\"\n    and cswitch_consistency: \"\\<forall> u s t n . vpeq u s t \\<longrightarrow> vpeq u (cswitch n s) (cswitch n t)\"\n    and empty_in_AS_set: \"[] \\<in> AS_set\"\n    and invariant_s0: \"invariant s0\"\n    and invariant_after_cswitch: \"\\<forall> s n . invariant s \\<longrightarrow> invariant (cswitch n s)\"\n    and precondition_after_cswitch: \"\\<forall> s d n a. AS_precondition s d a \\<longrightarrow> AS_precondition (cswitch n s) d a\"\n    and AS_prec_first_action: \"\\<forall> s d aseq . invariant s \\<and> aseq \\<in> AS_set \\<and> aseq \\<noteq> [] \\<longrightarrow> AS_precondition s d (hd aseq)\"\n    and AS_prec_after_step: \"\\<forall> s a a' . (\\<exists> aseq \\<in> AS_set . is_sub_seq a a' aseq) \\<and> invariant s \\<and> AS_precondition s (current s) a \\<and> \\<not>aborting s (current s) a \\<and> \\<not> waiting s (current s) a\\<longrightarrow> AS_precondition (kstep s a) (current s) a'\"\n    and AS_prec_dom_independent: \"\\<forall> s d a a' . current s \\<noteq> d \\<and> AS_precondition s d a \\<longrightarrow> AS_precondition (kstep s a') d a\"\n    and spec_of_invariant: \"\\<forall> s a . invariant s \\<longrightarrow> invariant (kstep s a)\"\n    and aborting_switch_independent: \"\\<forall> n s . aborting (cswitch n s) = aborting s\"\n    and aborting_error_update: \"\\<forall> s d a' a . current s \\<noteq> d \\<and> aborting s d a \\<longrightarrow> aborting (set_error_code s a') d a\"\n    and aborting_after_step: \"\\<forall> s a d . current s \\<noteq> d \\<longrightarrow> aborting (kstep s a) d = aborting s d\" (* TODO: I think this PO can be removed *)\n    and aborting_consistent: \"\\<forall> s t u . vpeq u s t \\<longrightarrow> aborting s u = aborting t u\"\n    and waiting_switch_independent: \"\\<forall> n s . waiting (cswitch n s) = waiting s\"\n    and waiting_error_update: \"\\<forall> s d a' a . current s \\<noteq> d \\<and> waiting s d a \\<longrightarrow> waiting (set_error_code s a') d a\"\n    and waiting_consistent: \"\\<forall>s t u a . vpeq (current s) s t \\<and> (\\<forall> d \\<in> kinvolved a . vpeq d s t) \\<and> vpeq u s t \\<longrightarrow> waiting s u a = waiting t u a\"\n    and spec_of_waiting: \"\\<forall> s a . waiting s (current s) a \\<longrightarrow> kstep s a = s\"\n    and set_error_consistent: \"\\<forall> s t u a . vpeq u s t \\<longrightarrow> vpeq u (set_error_code s a) (set_error_code t a)\"\n    and set_error_locally_respects: \"\\<forall> s u a . \\<not>ifp (current s) u \\<longrightarrow> vpeq u s (set_error_code s a)\"\n    and current_set_error_code: \"\\<forall> s a . current (set_error_code s a) = current s\"\n    and precondition_after_set_error_code: \"\\<forall> s d a a'. AS_precondition s d a \\<and> aborting s (current s) a' \\<longrightarrow> AS_precondition (set_error_code s a') d a\"\n    and invariant_after_set_error_code: \"\\<forall> s a . invariant s \\<longrightarrow> invariant (set_error_code s a)\"\n    and involved_ifp: \"\\<forall> s a . \\<forall> d \\<in> (kinvolved a) . AS_precondition s (current s) a \\<longrightarrow> ifp d (current s)\"  \nbegin  \n\nsubsubsection\\<open>Execution semantics\\<close>\n\ntext\\<open>\n  Control is based on generic functions \\emph{aborting}, \\emph{waiting} and \\emph{set\\_error\\_code}.\n  Function \\emph{aborting} decides whether a certain action is aborting, given its domain and the state.\n  If so, then function set\\_error\\_code will be used to update the state, possibly communicating to other domains that an action has been aborted.\n  Function \\emph{waiting} can delay the execution of an action.\n  This behavior is implemented in function CISK\\_control.\n\\<close>\nfunction CISK_control :: \"'state_t \\<Rightarrow> 'dom_t \\<Rightarrow> 'action_t execution \\<Rightarrow> ('action_t option \\<times> 'action_t execution \\<times> 'state_t)\"\nwhere \"CISK_control s d []                = (None,[],s)\" \\<comment> \\<open>The thread is empty\\<close>\n    | \"CISK_control s d ([]#[])           = (None,[],s)\" \\<comment> \\<open>The current action sequence has been finished and the thread has no next action sequences to execute\\<close>\n    | \"CISK_control s d ([]#(as'#execs')) = (None,as'#execs',s)\" \\<comment> \\<open>The current action sequence has been finished. Skip to the next sequence\\<close>\n    | \"CISK_control s d ((a#as)#execs')   = (if aborting s d a then \n                                                  (None, execs',set_error_code s a)\n                                               else if waiting s d a then\n                                                  (Some a, (a#as)#execs',s)\n                                               else\n                                                  (Some a, as#execs',s))\" \\<comment> \\<open>Executing an action sequence\\<close>\nby pat_completeness auto\ntermination by lexicographic_order\n\ntext\\<open>\n  Function \\emph{run} defines the execution semantics.\n  This function is presented in ~\\<^cite>\\<open>\"Verbeek2013\"\\<close> by pseudo code (see Algorithm 1).\n  Before defining the run function, we define accessor functions for the control mechanism.\n  Functions next\\_action, next\\_execs and next\\_state correspond to ``control.a'', ``control.x'' and ``control.s'' in ~\\<^cite>\\<open>\"Verbeek2013\"\\<close>.\n\\<close>\nabbreviation next_action::\"'state_t \\<Rightarrow> ('dom_t \\<Rightarrow> 'action_t execution) \\<Rightarrow> 'action_t option\"\nwhere \"next_action \\<equiv> Kernel.next_action current CISK_control\"\nabbreviation next_execs::\"'state_t \\<Rightarrow> ('dom_t \\<Rightarrow> 'action_t execution) \\<Rightarrow> ('dom_t \\<Rightarrow> 'action_t execution)\"\nwhere \"next_execs  \\<equiv> Kernel.next_execs current CISK_control\"\nabbreviation next_state::\"'state_t \\<Rightarrow> ('dom_t \\<Rightarrow> 'action_t execution) \\<Rightarrow> 'state_t\"\nwhere \"next_state  \\<equiv> Kernel.next_state current CISK_control\"\ntext \\<open>\n\\<close>\ntext \\<open>\n  A thread is empty iff either it has no further action sequences to execute, or when the current action sequence is finished and there are no further action sequences to execute.\n\\<close>\nabbreviation thread_empty::\"'action_t execution \\<Rightarrow> bool\"\nwhere \"thread_empty exec \\<equiv> exec = [] \\<or> exec = [[]]\"\n\ntext\\<open>\n  The following function defines the execution semantics of CISK, using function CISK\\_control.\n\\<close>\nfunction run :: \"time_t \\<Rightarrow> 'state_t \\<Rightarrow> ('dom_t \\<Rightarrow> 'action_t execution) \\<Rightarrow> 'state_t\"\nwhere \"run 0 s execs = s\"\n| \"interrupt (Suc n) \\<Longrightarrow> run (Suc n) s execs = run n (cswitch (Suc n) s) execs\"\n| \"\\<not>interrupt (Suc n) \\<Longrightarrow> thread_empty(execs (current s)) \\<Longrightarrow> run (Suc n) s execs = run n s execs\"\n| \"\\<not>interrupt (Suc n) \\<Longrightarrow> \\<not>thread_empty(execs (current s)) \\<Longrightarrow>\n      run (Suc n) s execs = (let control_a = next_action s execs;\n                                 control_s = next_state s execs;\n                                 control_x = next_execs s execs in\n                             case control_a of None \\<Rightarrow> run n control_s control_x\n                                         | (Some a) \\<Rightarrow> run n (kstep control_s a) control_x)\"\nusing not0_implies_Suc by (metis prod_cases3,auto)\ntermination by lexicographic_order\n\nsubsubsection \\<open>Formulations of security\\<close>\n\ntext\\<open>\n  The definitions of security as presented in Section 2.2 of~\\<^cite>\\<open>\"Verbeek2013\"\\<close>.\n\\<close>\n\nabbreviation kprecondition\n  where \"kprecondition s a \\<equiv> invariant s \\<and> AS_precondition s (current s) a\"\ndefinition realistic_execution\nwhere \"realistic_execution aseq \\<equiv> set aseq \\<subseteq> AS_set\"\ndefinition realistic_executions :: \"('dom_t \\<Rightarrow> 'action_t execution) \\<Rightarrow> bool\"\nwhere \"realistic_executions execs \\<equiv> \\<forall>d. realistic_execution (execs d)\"\nabbreviation involved where \"involved \\<equiv> Kernel.involved kinvolved\"\nabbreviation step where \"step \\<equiv> Kernel.step kstep\"\nabbreviation purge where \"purge \\<equiv> Separation_Kernel.purge realistic_execution ifp\"\nabbreviation ipurge_l where \"ipurge_l \\<equiv> Separation_Kernel.ipurge_l kinvolved ifp\"\nabbreviation ipurge_r where \"ipurge_r \\<equiv> Separation_Kernel.ipurge_r realistic_execution kinvolved ifp\"\n\ndefinition NI_unrelated::bool\nwhere \"NI_unrelated\n  \\<equiv> \\<forall> execs a n . realistic_executions execs \\<longrightarrow>\n                      (let s_f = run n s0 execs in\n                         output_f s_f a = output_f (run n s0 (purge execs (current s_f))) a)\"\ndefinition NI_indirect_sources::bool\nwhere \"NI_indirect_sources\n  \\<equiv> \\<forall> execs a n. realistic_executions execs \\<longrightarrow>\n                    (let s_f = run n s0 execs in\n                      output_f (run n s0 (ipurge_l execs (current s_f))) a =\n                      output_f (run n s0 (ipurge_r execs (current s_f))) a)\"\ndefinition isecure::bool\nwhere \"isecure \\<equiv> NI_unrelated \\<and> NI_indirect_sources\"\n\n\nsubsubsection \\<open>Proofs\\<close>\ntext\\<open>\n  The final theorem is unwinding\\_implies\\_isecure\\_CISK.\n  This theorem shows that any interpretation of locale CISK is secure.\n\n  To prove this theorem, the refinement framework is used.\n  CISK is a refinement of ISK, as the only idfference is the control function.\n  In ISK, this function is a generic function called \\emph{control}, in CISK it is interpreted in function \\emph{CISK\\_control}.\n  It is proven that function \\emph{CISK\\_control} satisfies all the proof obligations concerning generic function \\emph{control}.\n  In other words, \\emph{CISK\\_control} is proven to be an interpretation of control.\n  Therefore, all theorems on run\\_total apply to the run function of CISK as well.\n\\<close>\n\nlemma next_action_consistent: \nshows \"\\<forall> s t execs . vpeq (current s) s t \\<and> (\\<forall> d \\<in>  involved (next_action s execs) . vpeq d s t) \\<and> current s = current t  \\<longrightarrow> next_action s execs = next_action t execs\"\nproof-\n{\n  fix s t execs\n  assume vpeq: \"vpeq (current s) s t\"\n  assume vpeq_involved: \"\\<forall> d \\<in>  involved (next_action s execs) . vpeq d s t\"\n  assume current_s_t: \"current s = current t\"\n  from aborting_consistent current_s_t vpeq\n   have \"aborting t (current s) = aborting s (current s)\" by auto\n  from current_s_t this waiting_consistent vpeq_involved\n    have \"next_action s execs = next_action t execs\"\n    unfolding Kernel.next_action_def \n    by(cases \"(s,(current s),execs (current s))\" rule: CISK_control.cases,auto)\n}\nthus ?thesis by auto\nqed\n\nlemma next_execs_consistent:\nshows \"\\<forall> s t execs . vpeq (current s) s t \\<and> (\\<forall> d \\<in> involved (next_action s execs) . vpeq d s t) \\<and> current s = current t \\<longrightarrow> fst (snd (CISK_control s (current s) (execs (current s)))) = fst (snd (CISK_control t (current s) (execs (current s))))\"\nproof-\n{\n  fix s t execs\n  assume vpeq: \"vpeq (current s) s t\"\n  assume vpeq_involved: \"\\<forall> d \\<in> involved (next_action s execs) . vpeq d s t\"\n  assume current_s_t: \"current s = current t\"\n  from aborting_consistent current_s_t vpeq\n     have 1: \"aborting t (current s) = aborting s (current s)\" by auto\n  from 1 vpeq current_s_t vpeq_involved waiting_consistent[THEN spec,THEN spec,THEN spec,THEN spec,where x3=s and x2=t and x1=\"current s\" and x=\"the (next_action s execs)\"]\n    have \"fst (snd (CISK_control s (current s) (execs (current s)))) = fst (snd (CISK_control t (current s) (execs (current s))))\"\n    unfolding Kernel.next_action_def Kernel.involved_def\n    by(cases \"(s,(current s),execs (current s))\" rule: CISK_control.cases,auto split: if_split_asm)\n}\nthus ?thesis by auto\nqed\n\nlemma next_state_consistent:\nshows \"\\<forall> s t u execs . vpeq (current s) s t \\<and> vpeq u s t \\<and> current s = current t \\<longrightarrow> vpeq u (next_state s execs) (next_state t execs)\"\nproof-\n{\n  fix s t u execs\n  assume vpeq_s_t: \"vpeq (current s) s t \\<and> vpeq u s t\"\n  assume current_s_t: \"current s = current t\"\n  from vpeq_s_t current_s_t\n    have \"vpeq u (next_state s execs) (next_state t execs)\"\n    unfolding Kernel.next_state_def\n    using aborting_consistent set_error_consistent\n    by(cases \"(s,(current s),execs (current s))\" rule: CISK_control.cases,auto)\n}\nthus ?thesis by auto\nqed\n\nlemma current_next_state:\nshows \"\\<forall> s execs . current (next_state s execs) = current s\" \nproof-\n{\n  fix s execs\n  have \"current (next_state s execs) = current s\"\n    unfolding Kernel.next_state_def\n    using current_set_error_code\n    by(cases \"(s,(current s),execs (current s))\" rule: CISK_control.cases,auto)\n}\nthus ?thesis by auto\nqed\n\nlemma locally_respects_next_state:\nshows \"\\<forall> s u execs. \\<not>ifp (current s) u \\<longrightarrow> vpeq u s (next_state s execs)\"\nproof-\n{\n  fix s u execs\n  assume \"\\<not>ifp (current s) u\"\n  hence \"vpeq u s (next_state s execs)\"\n    unfolding Kernel.next_state_def\n    using vpeq_reflexive set_error_locally_respects\n    by(cases \"(s,(current s),execs (current s))\" rule: CISK_control.cases,auto)\n}\nthus ?thesis by auto\nqed\n\nlemma CISK_control_spec:\nshows \"\\<forall>s d aseqs.\n       case CISK_control s d aseqs of\n       (a, aseqs', s') \\<Rightarrow>\n         thread_empty aseqs \\<and> (a, aseqs') = (None, []) \\<or>\n         aseqs \\<noteq> [] \\<and> hd aseqs \\<noteq> [] \\<and> \\<not> aborting s' d (the a) \\<and> \\<not> waiting s' d (the a) \\<and> (a, aseqs') = (Some (hd (hd aseqs)), tl (hd aseqs) # tl aseqs) \\<or>\n         aseqs \\<noteq> [] \\<and> hd aseqs \\<noteq> [] \\<and> waiting s' d (the a) \\<and> (a, aseqs', s') = (Some (hd (hd aseqs)), aseqs, s) \\<or> (a, aseqs') = (None, tl aseqs)\"\nproof-\n{\n  fix s d aseqs\n  have \"case CISK_control s d aseqs of\n       (a, aseqs', s') \\<Rightarrow>\n         thread_empty aseqs \\<and> (a, aseqs') = (None, []) \\<or>\n         aseqs \\<noteq> [] \\<and> hd aseqs \\<noteq> [] \\<and> \\<not> aborting s' d (the a) \\<and> \\<not> waiting s' d (the a) \\<and> (a, aseqs') = (Some (hd (hd aseqs)), tl (hd aseqs) # tl aseqs) \\<or>\n         aseqs \\<noteq> [] \\<and> hd aseqs \\<noteq> [] \\<and> waiting s' d (the a) \\<and> (a, aseqs', s') = (Some (hd (hd aseqs)), aseqs, s) \\<or> (a, aseqs') = (None, tl aseqs)\"\n  by(cases \"(s,d,aseqs)\" rule: CISK_control.cases,auto)\n}\nthus ?thesis by auto\nqed\n\nlemma next_action_after_cswitch:\nshows \"\\<forall> s n d aseqs . fst (CISK_control (cswitch n s) d aseqs) = fst (CISK_control s d aseqs)\"\nproof-\n{\n  fix s n d aseqs\n  have \"fst (CISK_control (cswitch n s) d aseqs) = fst (CISK_control s d aseqs)\"\n  using aborting_switch_independent waiting_switch_independent\n  by(cases \"(s,d,aseqs)\" rule: CISK_control.cases,auto)\n}\nthus ?thesis by auto\nqed\n\n\nlemma next_action_after_next_state:\nshows \"\\<forall> s execs d . current s \\<noteq> d \\<longrightarrow> fst (CISK_control (next_state s execs) d (execs d)) = None \\<or> fst (CISK_control (next_state s execs) d (execs d)) = fst (CISK_control s d (execs d))\"\nproof-\n{\n  fix s execs d aseqs\n  assume 1: \"current s \\<noteq> d\"\n  have \"fst (CISK_control (next_state s execs) d aseqs) = None \\<or> fst (CISK_control (next_state s execs) d aseqs) = fst (CISK_control s d aseqs)\"\n    proof(cases \"(s,d,aseqs)\" rule: CISK_control.cases,simp,simp,simp)\n    case (4 sa da a as execs')\n      thus ?thesis\n          unfolding Kernel.next_state_def\n          using aborting_error_update waiting_error_update 1\n          by(cases \"(sa,current sa,execs (current sa))\" rule: CISK_control.cases,auto split: if_split_asm)\n    qed\n}\nthus ?thesis by auto\nqed\n\nlemma next_action_after_step:\nshows \"\\<forall> s a d aseqs . current s \\<noteq> d \\<longrightarrow> fst (CISK_control (step s a) d aseqs) = fst (CISK_control s d aseqs)\"\nproof-\n{\n  fix s a d aseqs\n  assume 1: \"current s \\<noteq> d\"\n  from this aborting_after_step \n    have  \"fst (CISK_control (step s a) d aseqs) = fst (CISK_control s d aseqs)\"\n    unfolding Kernel.step_def \n    by(cases \"(s,d,aseqs)\" rule: CISK_control.cases,simp,simp,simp,cases a,auto)\n}\nthus ?thesis by auto\nqed\n\nlemma next_state_precondition:\nshows \"\\<forall>s d a execs. AS_precondition s d a \\<longrightarrow> AS_precondition (next_state s execs) d a\"\nproof-\n{\n  fix s a d execs\n  assume \"AS_precondition s d a\"\n  hence \"AS_precondition (next_state s execs) d a\"\n    unfolding Kernel.next_state_def\n    using precondition_after_set_error_code\n    by(cases \"(s,(current s),execs (current s))\" rule: CISK_control.cases,auto)\n}\nthus ?thesis by auto\nqed\n\nlemma next_state_invariant:\nshows \"\\<forall>s execs. invariant s \\<longrightarrow> invariant (next_state s execs)\"\nproof-\n{\n  fix s execs\n  assume \"invariant s\"\n  hence \"invariant (next_state s execs)\"\n    unfolding Kernel.next_state_def\n    using invariant_after_set_error_code\n    by(cases \"(s,(current s),execs (current s))\" rule: CISK_control.cases,auto)\n}\nthus ?thesis by auto\nqed\n\nlemma next_action_from_execs:\nshows \"\\<forall> s execs . next_action s execs \\<rightharpoonup> (\\<lambda> a . a \\<in> actions_in_execution (execs (current s)))\"\nproof-\n{\n  fix s execs\n  {\n    fix a\n    assume 1: \"next_action s execs = Some a\"\n    from 1 have \"a \\<in> actions_in_execution (execs (current s))\"\n      unfolding Kernel.next_action_def actions_in_execution_def\n      by (cases \"(s,(current s),execs (current s))\" rule: CISK_control.cases,auto split: if_split_asm)\n  }\n  hence \"next_action s execs \\<rightharpoonup> (\\<lambda> a . a \\<in> actions_in_execution (execs (current s)))\"\n    unfolding B_def\n    by (cases \"next_action s execs\",auto)\n}\nthus ?thesis unfolding B_def by (auto)\nqed\n\nlemma next_execs_subset:\nshows \"\\<forall>s execs u . actions_in_execution (next_execs s execs u) \\<subseteq> actions_in_execution (execs u)\"\nproof-\n{\n  fix s execs u\n  have \"actions_in_execution (next_execs s execs u) \\<subseteq> actions_in_execution (execs u)\"\n    unfolding Kernel.next_execs_def actions_in_execution_def\n    by (cases \"(s,(current s),execs (current s))\" rule: CISK_control.cases,auto split: if_split_asm)\n}\nthus ?thesis by auto\nqed\n\n\ntheorem unwinding_implies_isecure_CISK:\nshows isecure\nproof-\n  interpret int: Interruptible_Separation_Kernel kstep output_f s0 current cswitch interrupt kprecondition realistic_execution CISK_control kinvolved ifp vpeq AS_set invariant AS_precondition aborting waiting\n    proof (unfold_locales)\n      show \"\\<forall>a b c u. vpeq u a b \\<and> vpeq u b c \\<longrightarrow> vpeq u a c\"\n        using vpeq_transitive by blast\n      show \"\\<forall>a b u. vpeq u a b \\<longrightarrow> vpeq u b a\"\n        using vpeq_symmetric by blast\n      show \"\\<forall>a u. vpeq u a a\"\n        using vpeq_reflexive by blast\n      show \"\\<forall>u. ifp u u\"\n        using ifp_reflexive by blast\n      show \"\\<forall> s t u a. vpeq u s t \\<and> vpeq (current s) s t \\<and> kprecondition s a \\<and> kprecondition t a \\<and> current s = current t  \\<longrightarrow> vpeq u (kstep s a) (kstep t a)\"\n        using weakly_step_consistent by blast\n      show \"\\<forall> a s u. \\<not>ifp (current s) u  \\<and> kprecondition s a \\<longrightarrow> vpeq u s (kstep s a)\"\n        using locally_respects by blast\n      show \"\\<forall> a s t. vpeq (current s) s t \\<and> current s = current t \\<longrightarrow> (output_f s a) = (output_f t a)\"\n        using output_consistent by blast        \n      show \"\\<forall> s a . current (kstep s a) = current s\"\n        using step_atomicity by blast        \n      show \"\\<forall> n s t . current s = current t \\<longrightarrow> current (cswitch n s) = current (cswitch n t)\"\n        using cswitch_independent_of_state by blast                                                    \n      show \"\\<forall> u s t n . vpeq u s t \\<longrightarrow> vpeq u (cswitch n s) (cswitch n t)\"\n        using cswitch_consistency by blast\n      show \"\\<forall>s t execs. vpeq (current s) s t \\<and> (\\<forall> d \\<in> involved (next_action s execs) . vpeq d s t) \\<and> current s = current t \\<longrightarrow> next_action s execs = next_action t execs\"\n        using next_action_consistent by blast\n      show \"\\<forall>s t execs.\n        vpeq (current s) s t \\<and> (\\<forall> d \\<in> involved (next_action s execs) . vpeq d s t) \\<and> current s = current t \\<longrightarrow>\n        fst (snd (CISK_control s (current s) (execs (current s)))) = fst (snd (CISK_control t (current s) (execs (current s))))\"\n        using next_execs_consistent by blast\n      show \" \\<forall>s t u execs. vpeq (current s) s t \\<and> vpeq u s t \\<and> current s = current t \\<longrightarrow> vpeq u (next_state s execs) (next_state t execs)\"\n        using next_state_consistent by auto\n      show \" \\<forall>s execs. current (next_state s execs) = current s\"\n        using current_next_state by auto\n      show \"\\<forall>s u execs. \\<not> ifp (current s) u \\<longrightarrow> vpeq u s (next_state s execs)\"\n        using locally_respects_next_state by auto\n      show \"[] \\<in> AS_set\"\n        using empty_in_AS_set by blast\n      show \"\\<forall> s n . invariant s \\<longrightarrow> invariant (cswitch n s)\"\n        using invariant_after_cswitch by blast\n      show \"\\<forall> s d n a. AS_precondition s d a \\<longrightarrow> AS_precondition (cswitch n s) d a\"\n        using precondition_after_cswitch by blast\n      show \"invariant s0\"\n        using invariant_s0 by blast\n      show \"\\<forall> s d aseq . invariant s \\<and> aseq \\<in> AS_set \\<and> aseq \\<noteq> [] \\<longrightarrow> AS_precondition s d (hd aseq)\"\n        using AS_prec_first_action by blast\n      show \"\\<forall>s a a'. (\\<exists>aseq\\<in>AS_set. is_sub_seq a a' aseq) \\<and> invariant s \\<and> AS_precondition s (current s) a \\<and> \\<not> aborting s (current s) a \\<and> \\<not> waiting s (current s) a \\<longrightarrow>\n             AS_precondition (kstep s a) (current s) a'\"\n        using AS_prec_after_step by blast       \n      show \"\\<forall> s d a a' . current s \\<noteq> d \\<and> AS_precondition s d a \\<longrightarrow> AS_precondition (kstep s a') d a\"\n        using AS_prec_dom_independent by blast  \n      show \"\\<forall> s a . invariant s \\<longrightarrow> invariant (kstep s a)\"\n        using spec_of_invariant by blast\n      show \"\\<And>s a. kprecondition s a \\<equiv> kprecondition s a\"\n        by auto         \n      show \"\\<And>aseq. realistic_execution aseq \\<equiv> set aseq \\<subseteq> AS_set\"\n        unfolding realistic_execution_def\n        by auto\n      show \"\\<forall>s a. \\<forall> d \\<in> involved a. kprecondition s (the a) \\<longrightarrow> ifp d (current s)\"\n        using involved_ifp unfolding Kernel.involved_def by (auto split: option.splits)\n      show \"\\<forall>s execs. next_action s execs \\<rightharpoonup> (\\<lambda>a. a \\<in> actions_in_execution (execs (current s)))\"\n        using next_action_from_execs by blast \n      show \"\\<forall>s execs u. actions_in_execution (next_execs s execs u) \\<subseteq> actions_in_execution (execs u)\"\n        using next_execs_subset by blast        \n      show \"\\<forall>s d aseqs.\n       case CISK_control s d aseqs of\n       (a, aseqs', s') \\<Rightarrow>\n         thread_empty aseqs \\<and> (a, aseqs') = (None, []) \\<or>\n         aseqs \\<noteq> [] \\<and> hd aseqs \\<noteq> [] \\<and> \\<not> aborting s' d (the a) \\<and> \\<not> waiting s' d (the a) \\<and> (a, aseqs') = (Some (hd (hd aseqs)), tl (hd aseqs) # tl aseqs) \\<or>\n         aseqs \\<noteq> [] \\<and> hd aseqs \\<noteq> [] \\<and> waiting s' d (the a) \\<and> (a, aseqs', s') = (Some (hd (hd aseqs)), aseqs, s) \\<or> (a, aseqs') = (None, tl aseqs)\"\n        using CISK_control_spec by blast\n      show \"\\<forall>s n d aseqs. fst (CISK_control (cswitch n s) d aseqs) = fst (CISK_control s d aseqs)\"\n        using next_action_after_cswitch by auto\n      show \"\\<forall>s execs d.\n       current s \\<noteq> d \\<longrightarrow>\n       fst (CISK_control (next_state s execs) d (execs d)) = None \\<or> fst (CISK_control (next_state s execs) d (execs d)) = fst (CISK_control s d (execs d))\"\n        using next_action_after_next_state by auto\n      show \"\\<forall>s a d aseqs. current s \\<noteq> d \\<longrightarrow> fst (CISK_control (step s a) d aseqs) = fst (CISK_control s d aseqs)\"\n        using next_action_after_step by auto\n      show \"\\<forall>s d a execs. AS_precondition s d a \\<longrightarrow> AS_precondition (next_state s execs) d a\"\n        using next_state_precondition by auto\n      show \"\\<forall>s execs. invariant s \\<longrightarrow> invariant (next_state s execs)\"\n        using next_state_invariant by auto\n      show \"\\<forall>s a. waiting s (current s) a \\<longrightarrow> kstep s a = s\"\n        using spec_of_waiting by blast\n  qed\n  \n  note interpreted = int.Interruptible_Separation_Kernel_axioms\n  note run_total_induct = Interruptible_Separation_Kernel.run_total.induct[of kstep output_f s0 current cswitch kprecondition realistic_execution\n                                                                             CISK_control kinvolved ifp vpeq AS_set invariant AS_precondition aborting waiting _ interrupt]\n  have run_equals_run_total:\n     \"\\<And> n s execs . run n s execs \\<equiv> Interruptible_Separation_Kernel.run_total kstep current cswitch interrupt CISK_control n s execs\"\n     proof-\n        fix n s execs\n        show \"run n s execs \\<equiv> Interruptible_Separation_Kernel.run_total kstep current cswitch interrupt CISK_control n s execs\"\n          using interpreted int.step_def\n          by(induct n s execs rule: run_total_induct,auto split: option.splits)\n     qed\n  from interpreted\n    have 0: \"Interruptible_Separation_Kernel.isecure_total kstep output_f s0 current cswitch interrupt realistic_execution CISK_control kinvolved ifp\"\n    by (metis int.unwinding_implies_isecure_total)\n  from 0 run_equals_run_total\n    have 1: \"NI_unrelated\"\n    by (metis realistic_executions_def int.isecure_total_def int.realistic_executions_def int.NI_unrelated_total_def NI_unrelated_def)\n  from 0 run_equals_run_total\n    have 2: \"NI_indirect_sources\"\n    by (metis realistic_executions_def int.NI_indirect_sources_total_def int.isecure_total_def int.realistic_executions_def NI_indirect_sources_def)\n  from 1 2 show ?thesis unfolding isecure_def by auto\nqed\n\nend\nend\n\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/CISC-Kernel/trace/Rushby-with-Control/CISK.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6548947290421275, "lm_q2_score": 0.4263215925474903, "lm_q1q2_score": 0.27919576383619693}}
{"text": "(*  Title:      HOL/Auth/n_germanish_lemma_inv__1_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_germanish Protocol Case Study*} \n\ntheory n_germanish_lemma_inv__1_on_rules imports n_germanish_lemma_on_inv__1\nbegin\nsection{*All lemmas on causal relation between inv__1*}\nlemma lemma_inv__1_on_rules:\n  assumes b1: \"r \\<in> rules N\" and b2: \"(\\<exists> p__Inv0 p__Inv2. p__Inv0\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv0~=p__Inv2\\<and>f=inv__1  p__Inv0 p__Inv2)\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have c1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t1  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_t2  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_t3  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_t4  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_t5  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_t6 N i)\"\n  apply (cut_tac b1, auto) done\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t1  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_t1Vsinv__1) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t2  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_t2Vsinv__1) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t3  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_t3Vsinv__1) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t4  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_t4Vsinv__1) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t5  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_t5Vsinv__1) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t6 N i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_t6Vsinv__1) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "paraVerifier", "repo": "paraVerifier", "sha": "5de62b433a160bf8d714e0a5085a38b9dd8899f0", "save_path": "github-repos/isabelle/paraVerifier-paraVerifier", "path": "github-repos/isabelle/paraVerifier-paraVerifier/paraVerifier-5de62b433a160bf8d714e0a5085a38b9dd8899f0/proof_scripts/germanish/n_germanish_lemma_inv__1_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6548947155710234, "lm_q2_score": 0.4263215925474903, "lm_q1q2_score": 0.2791957580931744}}
{"text": "theory Incredible_Completeness\nimports Natural_Deduction Incredible_Deduction Build_Incredible_Tree\nbegin\n\ntext \\<open>\nThis theory takes the tree produced in @{theory Build_Incredible_Tree}, globalizes it using\n@{term globalize}, and then builds the incredible proof graph out of it.\n\\<close>\n\ntype_synonym 'form vertex = \"('form \\<times> nat list)\"\ntype_synonym ('form, 'var) edge'' = \"('form vertex, 'form, 'var) edge'\"\n\nlocale Solved_Task =\n  Abstract_Task  freshenLC renameLCs lconsts closed subst subst_lconsts subst_renameLCs anyP antecedent consequent rules assumptions conclusions\n   for freshenLC :: \"nat \\<Rightarrow> 'var \\<Rightarrow> 'var\" \n    and renameLCs :: \"('var \\<Rightarrow> 'var) \\<Rightarrow> 'form \\<Rightarrow> 'form\" \n    and lconsts :: \"'form \\<Rightarrow> 'var set\" \n    and closed :: \"'form \\<Rightarrow> bool\"\n    and subst :: \"'subst \\<Rightarrow> 'form \\<Rightarrow> 'form\" \n    and subst_lconsts :: \"'subst \\<Rightarrow> 'var set\" \n    and subst_renameLCs :: \"('var \\<Rightarrow> 'var) \\<Rightarrow> ('subst \\<Rightarrow> 'subst)\"\n    and anyP :: \"'form\"\n    and antecedent :: \"'rule \\<Rightarrow> ('form, 'var) antecedent list\" \n    and consequent :: \"'rule \\<Rightarrow> 'form list\" \n    and rules :: \"'rule stream\" \n    and assumptions :: \"'form list\" \n    and conclusions :: \"'form list\" +\n  assumes solved: solved\nbegin\n\ntext \\<open>Let us get our hand on concrete trees.\\<close>\n\ndefinition ts :: \"'form \\<Rightarrow> (('form entailment) \\<times> ('rule \\<times> 'form) NatRule) tree\" where\n  \"ts c = (SOME t. snd (fst (root t)) = c \\<and> fst (fst (root t)) |\\<subseteq>| ass_forms \\<and> wf t \\<and> tfinite t)\"\n\nlemma\n  assumes \"c |\\<in>| conc_forms\"\n  shows ts_conc: \"snd (fst (root (ts c))) = c\"\n  and   ts_context: \"fst (fst (root (ts c))) |\\<subseteq>| ass_forms\"\n  and   ts_wf: \"wf (ts c)\"\n  and   ts_finite[simp]: \"tfinite (ts c)\"\n  unfolding atomize_conj conj_assoc ts_def\n  apply (rule someI_ex)\n  using solved assms\n  by (force simp add: solved_def)\n\nabbreviation it' where\n  \"it' c \\<equiv> globalize [fidx conc_forms c, 0] (freshenLC v_away) (to_it (ts c))\"\n\n\n\ndefinition vertices :: \"'form vertex fset\"  where\n  \"vertices = Abs_fset (Union ( set (map (\\<lambda> c. insert (c, []) ((\\<lambda> p. (c, 0 # p)) ` (it_paths (it' c))))  conclusions)))\"\n\nlemma mem_vertices: \"v |\\<in>| vertices \\<longleftrightarrow>  (fst v \\<in> set conclusions \\<and> (snd v = [] \\<or> snd v \\<in> (op # 0) ` it_paths (it' (fst v))))\"\n  unfolding vertices_def fmember.rep_eq ffUnion.rep_eq \n  by (cases v)(auto simp add: Abs_fset_inverse Bex_def )\n\nlemma prefixeq_vertices: \"(c,is) |\\<in>| vertices \\<Longrightarrow> prefixeq is' is \\<Longrightarrow> (c, is') |\\<in>| vertices\"\n  by (cases is') (auto simp add: mem_vertices intro!: imageI elim: it_paths_prefixeq)\n\nlemma none_vertices[simp]: \"(c, []) |\\<in>| vertices \\<longleftrightarrow> c \\<in> set conclusions\"\n  by (simp add: mem_vertices)\n\nlemma some_vertices[simp]: \"(c, i#is) |\\<in>| vertices \\<longleftrightarrow> c \\<in> set conclusions \\<and> i = 0 \\<and> is \\<in> it_paths (it' c)\"\n  by (auto simp add: mem_vertices)\n\nlemma vertices_cases[consumes 1, case_names None Some]:\n  assumes \"v |\\<in>| vertices\"\n  obtains c where \"c \\<in> set conclusions\" and \"v = (c, [])\"\n      |   c \"is\" where \"c \\<in> set conclusions\" and \"is \\<in> it_paths (it' c)\" and \"v = (c, 0#is)\"\nusing assms by (cases v; rename_tac \"is\"; case_tac \"is\"; auto)\n\nlemma vertices_induct[consumes 1, case_names None Some]:\n  assumes \"v |\\<in>| vertices\"\n  assumes \"\\<And> c. c \\<in> set conclusions \\<Longrightarrow> P (c, [])\"\n  assumes \"\\<And> c is . c \\<in> set conclusions \\<Longrightarrow> is \\<in> it_paths (it' c) \\<Longrightarrow> P (c, 0#is)\"\n  shows \"P v\"\nusing assms by (cases v; rename_tac \"is\"; case_tac \"is\"; auto)\n\nfun nodeOf :: \"'form vertex \\<Rightarrow> ('form, 'rule) graph_node\" where\n  \"nodeOf (pf, []) = Conclusion pf\"\n| \"nodeOf (pf, i#is) = iNodeOf (tree_at (it' pf) is)\"\n\nfun inst where\n  \"inst (c,[]) = empty_subst\"\n |\"inst (c, i#is) = iSubst (tree_at (it' c) is)\" \n\nlemma terminal_is_nil[simp]: \"v |\\<in>| vertices \\<Longrightarrow> outPorts (nodeOf v) = {||} \\<longleftrightarrow> snd v = []\"\n by (induction v rule: nodeOf.induct)\n    (auto elim: iNodeOf_outPorts[rotated] iwf_it)\n\nsublocale Vertex_Graph nodes inPorts outPorts vertices nodeOf.\n\ndefinition edge_from :: \"'form \\<Rightarrow> nat list => ('form vertex \\<times> ('form,'var) out_port)\" where \n  \"edge_from c is = ((c, 0 # is),  Reg (iOutPort (tree_at (it' c) is)))\"\n\nlemma fst_edge_from[simp]: \"fst (edge_from c is) = (c, 0 # is)\"\n  by (simp add: edge_from_def)\n\nfun in_port_at :: \"('form \\<times> nat list) \\<Rightarrow> nat \\<Rightarrow> ('form,'var) in_port\" where\n    \"in_port_at (c, [])  _  = plain_ant c\"\n  | \"in_port_at (c, _#is) i = inPorts' (iNodeOf (tree_at (it' c) is)) ! i\"\n\ndefinition edge_to :: \"'form \\<Rightarrow> nat list => ('form vertex \\<times> ('form,'var) in_port)\"  where\n \"edge_to c is =\n    (case rev is of   []   \\<Rightarrow> ((c, []),           in_port_at (c, []) 0)\n                    | i#is \\<Rightarrow> ((c, 0 # (rev is)), in_port_at (c, (0#rev is)) i))\"\n\nlemma edge_to_Nil[simp]: \"edge_to c [] = ((c, []), plain_ant c)\"\n  by (simp add: edge_to_def)\n\nlemma edge_to_Snoc[simp]: \"edge_to c (is@[i]) = ((c, 0 # is), in_port_at ((c, 0 # is)) i)\"\n  by (simp add: edge_to_def)\n\ndefinition edge_at :: \"'form \\<Rightarrow> nat list => ('form, 'var) edge''\"  where\n   \"edge_at c is = (edge_from c is, edge_to c is)\"\n\nlemma fst_edge_at[simp]: \"fst (edge_at c is) = edge_from c is\" by (simp add: edge_at_def)\nlemma snd_edge_at[simp]: \"snd (edge_at c is) = edge_to c is\" by (simp add: edge_at_def)\n\n\nlemma hyps_exist':\n  assumes \"c \\<in> set conclusions\"\n  assumes \"is \\<in> it_paths (it' c)\"\n  assumes \"tree_at (it' c) is = (HNode i s ants)\"\n  shows \"subst s (freshen i anyP) \\<in> hyps_along (it' c) is\"\nproof-\n  from assms(1)\n  have \"plain_iwf (it' c) (fst (root (ts c)))\" by (rule iwf_it)\n  moreover\n  note assms(2,3)\n  moreover\n  have \"fst (fst (root (ts c))) |\\<subseteq>| ass_forms\"\n    by (simp add: assms(1) ts_context)\n  ultimately\n  show ?thesis by (rule iwf_hyps_exist)\nqed\n\n\ndefinition hyp_edge_to :: \"'form \\<Rightarrow> nat list => ('form vertex \\<times> ('form,'var) in_port)\" where\n  \"hyp_edge_to c is = ((c, 0 # is),  plain_ant anyP)\"\n\n(* TODO: Replace n and s by \"subst s (freshen n anyP)\" *)\ndefinition hyp_edge_from :: \"'form \\<Rightarrow> nat list => nat \\<Rightarrow> 'subst \\<Rightarrow> ('form vertex \\<times> ('form,'var) out_port)\" where\n  \"hyp_edge_from c is n s = \n    ((c, 0 # hyp_port_path_for (it' c) is (subst s (freshen n anyP))),\n     hyp_port_h_for (it' c) is (subst s (freshen n anyP)))\"\n\ndefinition hyp_edge_at  :: \"'form \\<Rightarrow> nat list => nat \\<Rightarrow> 'subst \\<Rightarrow> ('form, 'var) edge''\" where\n  \"hyp_edge_at c is n s = (hyp_edge_from c is n s, hyp_edge_to c is)\"\n\nlemma fst_hyp_edge_at[simp]:\n  \"fst (hyp_edge_at c is n s) = hyp_edge_from c is n s\" by (simp add:hyp_edge_at_def) \nlemma snd_hyp_edge_at[simp]:\n  \"snd (hyp_edge_at c is n s) = hyp_edge_to c is\" by (simp add:hyp_edge_at_def)\n\ninductive_set edges where\n  regular_edge: \"c \\<in> set conclusions \\<Longrightarrow> is \\<in> it_paths (it' c) \\<Longrightarrow> edge_at c is \\<in> edges\"\n  | hyp_edge: \"c \\<in> set conclusions \\<Longrightarrow> is \\<in> it_paths (it' c) \\<Longrightarrow> tree_at (it' c) is = HNode n s ants \\<Longrightarrow> hyp_edge_at c is n s \\<in> edges\"\n\nsublocale Pre_Port_Graph nodes inPorts outPorts vertices nodeOf edges.\n\nlemma edge_from_valid_out_port:\n  assumes \"p \\<in> it_paths (it' c)\"\n  assumes \"c \\<in> set conclusions\"\n  shows \"valid_out_port (edge_from c p)\"\nusing assms\nby (auto simp add: edge_from_def intro: iwf_outPort iwf_it)\n\nlemma edge_to_valid_in_port:\n  assumes \"p \\<in> it_paths (it' c)\"\n  assumes \"c \\<in> set conclusions\"\n  shows \"valid_in_port (edge_to c p)\"\n  using assms\n  apply (auto simp add: edge_to_def inPorts_fset_of split: list.split elim!: it_paths_SnocE)\n  apply (rule nth_mem)\n  apply (drule (1) iwf_length_inPorts[OF iwf_it])\n  apply auto\n  done\n\nlemma hyp_edge_from_valid_out_port:\n  assumes \"is \\<in> it_paths (it' c)\"\n  assumes \"c \\<in> set conclusions\"\n  assumes \"tree_at (it' c) is = HNode n s ants\"\n  shows \"valid_out_port (hyp_edge_from c is n s)\"\nusing assms\nby(auto simp add: hyp_edge_from_def intro: hyp_port_outPort it_paths_prefix hyp_port_prefix  hyps_exist')\n\nlemma hyp_edge_to_valid_in_port:\n  assumes \"is \\<in> it_paths (it' c)\"\n  assumes \"c \\<in> set conclusions\"\n  assumes \"tree_at (it' c) is = HNode n s ants\"\n  shows \"valid_in_port (hyp_edge_to c is)\"\nusing assms by (auto simp add: hyp_edge_to_def)\n\n\ninductive scope' :: \"'form vertex \\<Rightarrow> ('form,'var) in_port \\<Rightarrow> 'form \\<times> nat list \\<Rightarrow> bool\" where\n  \"c \\<in> set conclusions \\<Longrightarrow>\n   is' \\<in> (op # 0) ` it_paths (it' c) \\<Longrightarrow>\n   prefixeq (is@[i]) is' \\<Longrightarrow> \n   ip = in_port_at (c,is) i \\<Longrightarrow>\n   scope' (c, is) ip (c, is')\"\n\ninductive_simps scope_simp: \"scope' v i v'\"\ninductive_cases scope_cases: \"scope' v i v'\"\n\nlemma scope_valid:\n  \"scope' v i v' \\<Longrightarrow> v' |\\<in>| vertices\"\nby (auto elim: scope_cases)\n\nlemma scope_valid_inport:\n  \"v' |\\<in>| vertices \\<Longrightarrow> scope' v ip  v' \\<longleftrightarrow> (\\<exists> i. fst v = fst v' \\<and> prefixeq (snd v@[i]) (snd v') \\<and> ip = in_port_at v i)\"\nby (cases v; cases v')  (auto simp add: scope'.simps mem_vertices)\n\ndefinition terminal_path_from :: \"'form \\<Rightarrow> nat list => ('form, 'var) edge'' list\" where\n   \"terminal_path_from c is = map (edge_at c) (rev (inits is))\"\n\nlemma terminal_path_from_Nil[simp]:\n  \"terminal_path_from c [] = [edge_at c []]\"\n  by (simp add: terminal_path_from_def)\n\nlemma terminal_path_from_Snoc[simp]:\n  \"terminal_path_from c (is @ [i]) = edge_at  c (is@[i]) # terminal_path_from c is\"\n  by (simp add: terminal_path_from_def)\n\nlemma path_terminal_path_from:\n  \"c \\<in> set conclusions \\<Longrightarrow>\n  is \\<in> it_paths (it' c) \\<Longrightarrow>\n  path (c, 0 # is) (c, []) (terminal_path_from c is)\"\nby (induction \"is\" rule: rev_induct)\n   (auto simp add: path_cons_simp intro!: regular_edge elim: it_paths_SnocE)\n\nlemma edge_step:\n  assumes \"(((a, b), ba), ((aa, bb), bc)) \\<in> edges\"\n  obtains \n    i where \"a = aa\" and \"b = bb@[i]\" and \"bc = in_port_at (aa,bb) i\"  and \"hyps (nodeOf (a, b)) ba = None\"\n  | i where \"a = aa\" and \"prefixeq (b@[i]) bb\" and \"hyps (nodeOf (a, b)) ba = Some (in_port_at (a,b) i)\"\nusing assms\nproof(cases rule: edges.cases[consumes 1, case_names Reg Hyp])\n  case (Reg c \"is\")\n  then obtain i where  \"a = aa\" and \"b = bb@[i]\" and \"bc = in_port_at (aa,bb) i\"  and \"hyps (nodeOf (a, b)) ba = None\"\n    by (auto elim!: edges.cases simp add: edge_at_def edge_from_def edge_to_def split: list.split list.split_asm)\n  thus thesis by (rule that)\nnext\n  case (Hyp c \"is\" n s)\n  let ?i = \"hyp_port_i_for (it' c) is (subst s (freshen n anyP))\"\n  from Hyp have \"a = aa\" and \"prefixeq (b@[?i]) bb\" and\n    \"hyps (nodeOf (a, b)) ba = Some (in_port_at (a,b) ?i)\"\n  by (auto simp add: edge_at_def edge_from_def edge_to_def hyp_edge_at_def hyp_edge_to_def hyp_edge_from_def\n      intro: hyp_port_prefixeq hyps_exist' hyp_port_hyps)\n  thus thesis by (rule that)\nqed\n\nlemma path_has_prefixes:\n  assumes \"path v v' pth\"\n  assumes \"snd v' = []\"\n  assumes \"prefixeq (is' @ [i]) (snd v)\"\n  shows \"((fst v, is'), (in_port_at (fst v, is') i)) \\<in> snd ` set pth\"\n  using assms\n  by (induction rule: path.induct)(auto elim!: edge_step dest: prefixeq_snocD)\n  \nlemma in_scope: \"valid_in_port (v', p') \\<Longrightarrow> v \\<in> scope (v', p') \\<longleftrightarrow> scope' v' p' v\"\nproof\n  assume \"v \\<in> scope (v', p')\"\n  hence \"v |\\<in>| vertices\" and \"\\<And> pth t.  path v t pth \\<Longrightarrow> terminal_vertex t \\<Longrightarrow> (v', p') \\<in> snd ` set pth\"\n    by (auto simp add: scope.simps)\n  from this\n  show \"scope' v' p' v\"\n  proof (induction  rule: vertices_induct)\n    case (None c)\n    from None(2)[of \"(c, [])\" \"[]\", simplified, OF None(1)]\n    have False.\n    thus \"scope' v' p' (c, [])\"..\n  next\n    case (Some c \"is\")\n\n    from `c \\<in> set conclusions` `is \\<in> it_paths (it' c)`\n    have \"path (c, 0#is) (c, []) (terminal_path_from c is)\"\n      by (rule path_terminal_path_from)\n    moreover\n    from `c \\<in> set conclusions`\n    have \"terminal_vertex (c, [])\" by simp\n    ultimately\n    have \"(v', p') \\<in> snd ` set (terminal_path_from c is)\"\n      by (rule Some(3))\n    hence \"(v',p') \\<in> set (map (edge_to c) (inits is))\"\n      unfolding terminal_path_from_def by auto\n    then obtain is' where \"prefixeq is' is\" and \"(v',p') = edge_to c is'\"\n      by auto\n    show \"scope' v' p' (c, 0#is)\"\n    proof(cases \"is'\" rule: rev_cases)\n      case Nil\n      with `(v',p') = edge_to c is'`\n      have \"v' = (c, [])\" and \"p' = plain_ant c\"\n        by (auto simp add: edge_to_def)\n      with `c \\<in> set conclusions` `is \\<in> it_paths (it' c)`\n      show ?thesis  by (auto intro!: scope'.intros)\n    next\n      case (snoc is'' i)\n      with `(v',p') = edge_to c is'`\n      have \"v' = (c, 0 # is'')\" and \"p' = in_port_at v' i\"\n        by (auto simp add: edge_to_def)\n      with `c \\<in> set conclusions` `is \\<in> it_paths (it' c)` `prefixeq is' is`[unfolded snoc]\n      show ?thesis\n        by (auto intro!: scope'.intros)\n    qed\n  qed\nnext\n  assume \"valid_in_port (v', p')\"\n  assume \"scope' v' p' v\"\n  then obtain c is' i \"is\" where\n    \"v' = (c, is')\" and \"v = (c, is)\" and \"c \\<in> set conclusions\" and\n    \"p' = in_port_at v' i\" and\n    \"is \\<in> op # 0 ` it_paths (it' c)\" and  \"prefixeq (is' @ [i]) is\"\n    by (auto simp add: scope'.simps)\n\n  from `scope' v' p' v`\n  have \"(c, is) |\\<in>| vertices\" unfolding `v = _` by (rule scope_valid)\n  hence \"(c, is) \\<in> scope ((c, is'), p')\"\n  proof(rule scope.intros)\n    fix pth t\n    assume \"path (c,is) t pth\"\n    \n    assume \"terminal_vertex t\"\n    hence \"snd t = []\" by auto\n\n    from path_has_prefixes[OF `path (c,is) t pth` `snd t = []`, simplified, OF `prefixeq (is' @ [i]) is`]\n    show \"((c, is'), p') \\<in> snd ` set pth\" unfolding `p' = _ ` `v' = _ `.\n  qed\n  thus \"v \\<in> scope (v', p')\" using `v =_` `v' = _` by simp\nqed\n\nsublocale Port_Graph nodes inPorts outPorts vertices nodeOf edges\nproof\n  show \"nodeOf ` fset vertices \\<subseteq> sset nodes\"\n    apply (auto simp add: fmember.rep_eq[symmetric] mem_vertices)\n    apply (auto simp add: stream.set_map dest: iNodeOf_tree_at[OF iwf_it])\n    done\n  next\n\n  have \"\\<forall> e \\<in> edges. valid_out_port (fst e) \\<and> valid_in_port (snd e)\"\n    by (auto elim!: edges.cases simp add: edge_at_def\n        dest: edge_from_valid_out_port edge_to_valid_in_port\n        dest: hyp_edge_from_valid_out_port hyp_edge_to_valid_in_port)\n    \n  thus \"\\<forall>(ps1, ps2)\\<in>edges. valid_out_port ps1 \\<and> valid_in_port ps2\" by auto\nqed\n  \n\nsublocale Scoped_Graph nodes inPorts outPorts vertices nodeOf edges hyps..\n\nlemma hyps_free_path_length:\n  assumes \"path v v' pth\"\n  assumes \"hyps_free pth\"\n  shows \"length pth + length (snd v') = length (snd v)\"\nusing assms by induction (auto elim!: edge_step )\n\nfun vidx :: \"'form vertex \\<Rightarrow> nat\" where\n   \"vidx (c, [])   = isidx [fidx conc_forms c]\"\n  |\"vidx (c, _#is) = iAnnot (tree_at (it' c) is)\"\n\nlemma my_vidx_inj: \"inj_on vidx (fset vertices)\"\n  by (rule inj_onI)\n     (auto simp add:  mem_vertices[unfolded fmember.rep_eq] iAnnot_globalize simp del: iAnnot.simps)\n\nlemma vidx_not_v_away[simp]: \"v |\\<in>| vertices \\<Longrightarrow> vidx v \\<noteq> v_away\"\n  by (cases v rule:vidx.cases) (auto simp add: iAnnot_globalize  simp del: iAnnot.simps)\n\nsublocale Instantiation inPorts outPorts nodeOf hyps  nodes edges vertices labelsIn labelsOut freshenLC renameLCs lconsts closed subst subst_lconsts subst_renameLCs anyP vidx inst\nproof\n  show \"inj_on vidx (fset vertices)\" by (rule my_vidx_inj)\nqed\n\nsublocale  Well_Scoped_Graph nodes inPorts outPorts vertices nodeOf edges hyps\nproof\n  fix v\\<^sub>1 p\\<^sub>1 v\\<^sub>2 p\\<^sub>2 p'\n  assume assms: \"((v\\<^sub>1, p\\<^sub>1), (v\\<^sub>2, p\\<^sub>2)) \\<in> edges\" \"hyps (nodeOf v\\<^sub>1) p\\<^sub>1 = Some p'\"\n  from assms(1) hyps_correct[OF assms(2)]\n  have \"valid_out_port (v\\<^sub>1, p\\<^sub>1)\" and \"valid_in_port (v\\<^sub>2, p\\<^sub>2)\" and \"valid_in_port (v\\<^sub>1, p')\" and \"v\\<^sub>2 |\\<in>| vertices\"\n    using valid_edges by auto\n\n  from assms\n  have \"\\<exists> i. fst v\\<^sub>1 = fst v\\<^sub>2 \\<and> prefixeq (snd v\\<^sub>1@[i]) (snd v\\<^sub>2) \\<and> p' = in_port_at v\\<^sub>1 i\"\n    by (cases v\\<^sub>1; cases v\\<^sub>2; auto elim!: edge_step)\n  hence \"scope' v\\<^sub>1 p' v\\<^sub>2\"\n    unfolding scope_valid_inport[OF `v\\<^sub>2 |\\<in>| vertices`].\n  hence \"v\\<^sub>2 \\<in> scope (v\\<^sub>1, p')\"\n    unfolding in_scope[OF `valid_in_port (v\\<^sub>1, p')`].\n  thus \"(v\\<^sub>2, p\\<^sub>2) = (v\\<^sub>1, p') \\<or> v\\<^sub>2 \\<in> scope (v\\<^sub>1, p')\" ..\nqed\n\nsublocale Acyclic_Graph nodes inPorts outPorts vertices nodeOf edges hyps \nproof\n  fix v pth\n  assume \"path v v pth\" and \"hyps_free pth\"\n  from hyps_free_path_length[OF this]\n  show \"pth = []\" by simp\nqed\n\nsublocale Saturated_Graph nodes inPorts outPorts vertices nodeOf edges\nproof\n  fix v p\n  assume \"valid_in_port (v, p)\"\n  thus \"\\<exists>e\\<in>edges. snd e = (v, p)\"\n  proof(induction v)\n    fix c cis\n    assume \"valid_in_port ((c, cis), p)\"\n    hence \"c \\<in> set conclusions\" by (auto simp add: mem_vertices)\n\n    show \"\\<exists>e\\<in>edges. snd e = ((c, cis), p)\"\n    proof(cases cis)\n      case Nil\n      with `valid_in_port ((c, cis), p)`\n      have [simp]: \"p = plain_ant c\" by simp\n\n      have \"[] \\<in> it_paths (it' c)\" by simp\n      with `c \\<in> set conclusions`\n      have \"edge_at c [] \\<in> edges\" by (rule regular_edge)\n      moreover\n      have \"snd (edge_at c []) = ((c, []), plain_ant c)\"\n        by (simp add: edge_to_def)\n      ultimately\n      show ?thesis by (auto simp add: Nil simp del: snd_edge_at)\n    next\n      case (Cons c' \"is\")\n      with `valid_in_port ((c, cis), p)`\n      have [simp]: \"c' = 0\" and \"is \\<in> it_paths (it' c)\"\n        and \"p |\\<in>| inPorts (iNodeOf (tree_at (it' c) is))\" by auto\n       \n      from this(3) obtain i where\n        \"i < length (inPorts' (iNodeOf (tree_at (it' c) is)))\" and\n        \"p = inPorts' (iNodeOf (tree_at (it' c) is)) ! i\"\n          by (auto simp add: inPorts_fset_of in_set_conv_nth)\n\n      show ?thesis\n      proof (cases \"tree_at (it' c) is\")\n        case [simp]: (RNode r ants)\n        show ?thesis\n        proof(cases r)\n          case I\n          hence \"\\<not> isHNode (tree_at (it' c) is)\" by simp\n          from iwf_length_inPorts_not_HNode[OF iwf_it[OF `c \\<in> set conclusions`]  `is \\<in> it_paths (it' c)` this]\n               `i < length (inPorts' (iNodeOf (tree_at (it' c) is)))`\n          have \"i < length (children (tree_at (it' c) is))\" by simp\n          with `is \\<in> it_paths (it' c)`\n          have \"is@[i] \\<in> it_paths (it' c)\" by (rule it_path_SnocI)\n          from `c \\<in> set conclusions` this\n          have \"edge_at c (is@[i]) \\<in> edges\" by (rule regular_edge)\n          moreover\n          have \"snd (edge_at c (is@[i])) = ((c, 0 # is),  inPorts' (iNodeOf (tree_at (it' c) is)) ! i)\"\n            by (simp add: edge_to_def)\n          ultimately\n          show ?thesis by (auto simp add: Cons `p = _` simp del: snd_edge_at)\n        next\n          case (H n s)\n          hence \"tree_at (it' c) is = HNode n s ants\" by simp\n          from `c \\<in> set conclusions` `is \\<in> it_paths (it' c)`  this\n          have \"hyp_edge_at c is n s \\<in> edges\"..\n          moreover\n          from H `p |\\<in>| inPorts (iNodeOf (tree_at (it' c) is))`\n          have [simp]: \"p = plain_ant anyP\" by simp\n  \n          have \"snd (hyp_edge_at c is n s) = ((c, 0 # is), p)\"\n            by (simp add: hyp_edge_to_def)\n          ultimately\n          show ?thesis by (auto simp add: Cons simp del: snd_hyp_edge_at)\n        qed\n      qed\n     qed\n   qed\nqed\n\nsublocale Pruned_Port_Graph nodes inPorts outPorts vertices nodeOf edges\nproof\n  fix v \n  assume \"v |\\<in>| vertices\"\n  thus \"\\<exists>pth v'. path v v' pth \\<and> terminal_vertex v'\"\n  proof(induct rule: vertices_induct)\n    case (None c)\n    hence \"terminal_vertex (c,[])\" by simp\n    with path.intros(1)\n    show ?case by blast\n  next\n    case (Some c \"is\")\n    hence \"path (c, 0 # is) (c, []) (terminal_path_from c is)\"\n      by (rule path_terminal_path_from)\n    moreover\n    have \"terminal_vertex (c,[])\" using Some(1) by simp\n    ultimately\n    show ?case by blast\n  qed\nqed\n\nsublocale Well_Shaped_Graph  nodes inPorts outPorts vertices nodeOf edges hyps..\n\nsublocale sol:Solution inPorts outPorts nodeOf hyps nodes vertices  labelsIn labelsOut freshenLC renameLCs lconsts closed subst subst_lconsts subst_renameLCs anyP vidx inst edges\nproof\n  fix v\\<^sub>1 p\\<^sub>1 v\\<^sub>2 p\\<^sub>2\n  assume \"((v\\<^sub>1, p\\<^sub>1), (v\\<^sub>2, p\\<^sub>2)) \\<in> edges\"\n  thus \"labelAtOut v\\<^sub>1 p\\<^sub>1 = labelAtIn v\\<^sub>2 p\\<^sub>2\"\n  proof(cases rule:edges.cases)\n    case (regular_edge c \"is\")\n   \n    from `((v\\<^sub>1, p\\<^sub>1), v\\<^sub>2, p\\<^sub>2) = edge_at c is`\n    have \"(v\\<^sub>1,p\\<^sub>1) = edge_from c is\" using fst_edge_at by (metis fst_conv)\n    hence [simp]: \"v\\<^sub>1 = (c, 0 # is)\" by (simp add: edge_from_def)\n\n    show ?thesis\n    proof(cases \"is\" rule:rev_cases)\n      case Nil\n      let \"?t'\" = \"it' c\"\n      have \"labelAtOut v\\<^sub>1 p\\<^sub>1 = subst (iSubst ?t') (freshen (vidx v\\<^sub>1) (iOutPort ?t'))\"\n        using regular_edge Nil by (simp add: labelAtOut_def edge_at_def edge_from_def)\n      also have \"vidx v\\<^sub>1 = iAnnot ?t'\" by (simp add:  Nil)\n      also have \"subst (iSubst ?t') (freshen (iAnnot ?t') (iOutPort ?t')) = snd (fst (root (ts c)))\"\n        unfolding iwf_subst_freshen_outPort[OF iwf_it[OF `c \\<in> set conclusions`]]..\n      also have \"\\<dots> = c\" using `c \\<in> set conclusions` by (simp add: ts_conc)\n      also have \"\\<dots> = labelAtIn v\\<^sub>2 p\\<^sub>2\"\n        using  `c \\<in> set conclusions`  regular_edge Nil\n        by (simp add: labelAtIn_def edge_at_def freshen_closed conclusions_closed closed_no_lconsts)\n      finally show ?thesis.\n    next\n      case (snoc is' i)\n      let \"?t1\" = \"tree_at (it' c) (is'@[i])\"\n      let \"?t2\" = \"tree_at (it' c) is'\"\n      have \"labelAtOut v\\<^sub>1 p\\<^sub>1 = subst (iSubst ?t1) (freshen (vidx v\\<^sub>1) (iOutPort ?t1))\"\n        using regular_edge snoc by (simp add: labelAtOut_def edge_at_def edge_from_def)\n      also have \"vidx v\\<^sub>1 = iAnnot ?t1\" using snoc regular_edge(3) by simp\n      also have \"subst (iSubst ?t1) (freshen (iAnnot ?t1) (iOutPort ?t1))\n          = subst (iSubst ?t2) (freshen (iAnnot ?t2) (a_conc (inPorts' (iNodeOf ?t2) ! i)))\"\n        by (rule iwf_edge_match[OF iwf_it[OF `c \\<in> set conclusions`] `is \\<in> it_paths (it' c)`[unfolded snoc]])\n      also have \"iAnnot ?t2 = vidx (c, 0 # is')\" by simp\n      also have \"subst (iSubst ?t2) (freshen (vidx (c, 0 # is')) (a_conc (inPorts' (iNodeOf ?t2) ! i))) = labelAtIn v\\<^sub>2 p\\<^sub>2\"\n        using regular_edge snoc by (simp add: labelAtIn_def edge_at_def)\n      finally show ?thesis.\n  qed\n  next\n    case (hyp_edge c \"is\" n s ants)\n    let ?f = \"subst s (freshen n anyP)\"\n    let ?h = \"hyp_port_h_for (it' c) is ?f\"\n    let ?his = \"hyp_port_path_for (it' c) is ?f\"\n    let \"?t1\" = \"tree_at (it' c) ?his\"\n    let \"?t2\" = \"tree_at (it' c) is\"\n\n    from `c \\<in> set conclusions` `is \\<in> it_paths (it' c)` `tree_at (it' c) is = HNode n s ants`\n    have \"?f \\<in> hyps_along (it' c) is\"\n      by (rule hyps_exist')\n\n    from `((v\\<^sub>1, p\\<^sub>1), v\\<^sub>2, p\\<^sub>2) = hyp_edge_at c is n s`\n    have \"(v\\<^sub>1,p\\<^sub>1) = hyp_edge_from c is n s\" using fst_hyp_edge_at by (metis fst_conv)\n    hence [simp]: \"v\\<^sub>1 = (c, 0 # ?his)\" by (simp add: hyp_edge_from_def)\n\n\n    have \"labelAtOut v\\<^sub>1 p\\<^sub>1 = subst (iSubst ?t1) (freshen (vidx v\\<^sub>1) (labelsOut (iNodeOf ?t1) ?h))\"\n      using hyp_edge by (simp add: hyp_edge_at_def hyp_edge_from_def labelAtOut_def)\n    also have \"vidx v\\<^sub>1 = iAnnot ?t1\" by simp\n    also have \"subst (iSubst ?t1) (freshen (iAnnot ?t1) (labelsOut (iNodeOf ?t1) ?h)) = ?f\" using `?f \\<in> hyps_along (it' c) is` by (rule local.hyp_port_eq[symmetric])\n    also have \"\\<dots> = subst (iSubst ?t2) (freshen (iAnnot ?t2) anyP)\"  using hyp_edge by simp\n    also have \"subst (iSubst ?t2) (freshen (iAnnot ?t2) anyP) = labelAtIn v\\<^sub>2 p\\<^sub>2\"\n        using hyp_edge by (simp add: labelAtIn_def  hyp_edge_at_def hyp_edge_to_def)\n    finally show ?thesis.\n  qed\nqed\n\n\nlemma node_disjoint_fresh_vars:\n  assumes \"n \\<in> sset nodes\"\n  assumes \"i < length (inPorts' n)\"\n  assumes \"i' < length (inPorts' n)\"\n  shows \"a_fresh (inPorts' n ! i) \\<inter> a_fresh (inPorts' n ! i') = {} \\<or> i = i'\"\n  using assms no_multiple_local_consts\n  by (fastforce simp add: nodes_def stream.set_map)\n\nsublocale Well_Scoped_Instantiation  freshenLC renameLCs lconsts closed subst subst_lconsts subst_renameLCs anyP inPorts outPorts nodeOf hyps  nodes vertices labelsIn labelsOut vidx inst edges local_vars\nproof\n  fix v p var v'\n  assume \"valid_in_port (v, p)\"\n  hence \"v |\\<in>| vertices\" by simp\n  \n  obtain c \"is\" where \"v = (c,is)\"  by (cases v, auto)\n\n  from `valid_in_port (v, p)` `v= _`\n  have \"(c,is) |\\<in>| vertices\"  and \"p |\\<in>| inPorts (nodeOf (c, is))\"  by simp_all\n  hence \"c \\<in> set conclusions\" by (simp add: mem_vertices)\n  \n  from `p |\\<in>| _` obtain i where\n    \"i < length (inPorts' (nodeOf (c, is)))\" and\n    \"p = inPorts' (nodeOf (c, is)) ! i\" by (auto simp add: inPorts_fset_of in_set_conv_nth)\n  hence \"p = in_port_at (c, is) i\" by (cases \"is\") auto\n\n  assume \"v' |\\<in>| vertices\"\n  then obtain c' is' where \"v' = (c',is')\" by (cases v', auto)\n\n  assume \"var \\<in> local_vars (nodeOf v) p\"\n  hence \"var \\<in> a_fresh p\" by simp\n\n  assume \"freshenLC (vidx v) var \\<in> subst_lconsts (inst v')\"\n  then obtain is'' where \"is' = 0#is''\" and \"is'' \\<in> it_paths (it' c')\"\n    using `v' |\\<in>| vertices`\n    by (cases is') (auto simp add: `v'=_`)\n\n  note `freshenLC (vidx v) var \\<in> subst_lconsts (inst v')`\n  also\n  have \"subst_lconsts (inst v') = subst_lconsts (iSubst (tree_at (it' c') is''))\"\n    by (simp add: `v'=_` `is'=_`)\n  also\n  from `is'' \\<in> it_paths (it' c')`\n  have \"\\<dots> \\<subseteq> fresh_at_path (it' c') is'' \\<union> range (freshenLC v_away)\"\n    by (rule globalize_local_consts)\n  finally\n  have \"freshenLC (vidx v) var \\<in> fresh_at_path (it' c') is''\"\n    using `v |\\<in>| vertices` by auto\n  then obtain is''' where \"prefixeq is''' is''\"  and \"freshenLC (vidx v) var \\<in> fresh_at (it' c') is'''\"\n    unfolding fresh_at_path_def by auto\n  then obtain i' is'''' where \"prefixeq (is''''@[i']) is''\" \n      and \"freshenLC (vidx v) var \\<in> fresh_at (it' c') (is''''@[i'])\"\n    using append_butlast_last_id[where xs = is''', symmetric]\n    apply (cases \"is''' = []\")\n    apply (auto simp del: fresh_at_snoc append_butlast_last_id)\n    apply metis\n    done\n\n  from  `is'' \\<in> it_paths (it' c')` `prefixeq (is''''@[i']) is''`\n  have \"(is''''@[i']) \\<in> it_paths (it' c')\" by (rule it_paths_prefixeq)\n  hence \"is'''' \\<in> it_paths (it' c')\" using append_prefixeqD it_paths_prefixeq by blast\n\n  from this `freshenLC (vidx v) var \\<in> fresh_at (it' c') (is''''@[i'])`\n  have \"c = c' \\<and> is = 0 # is'''' \\<and> var \\<in> a_fresh (inPorts' (iNodeOf (tree_at (it' c') is'''')) ! i')\"\n    unfolding fresh_at_def' using `v |\\<in>| vertices`  `v' |\\<in>| vertices`\n    apply (cases \"is\")\n    apply (auto split: if_splits simp add:  iAnnot_globalize it_paths_butlast `v=_` `v'=_` `is'=_` simp del: iAnnot.simps)\n    done\n  hence \"c' = c\" and \"is = 0 # is''''\" and \"var \\<in> a_fresh (inPorts' (iNodeOf (tree_at (it' c') is'''')) ! i')\" by simp_all\n\n  from `(is''''@[i']) \\<in> it_paths (it' c')`\n  have \"i' < length (inPorts' (nodeOf (c, is)))\"\n    using iwf_length_inPorts[OF iwf_it[OF `c \\<in> set conclusions`]]\n    by (auto elim!: it_paths_SnocE simp add: `is=_` `c' = _` order.strict_trans2)\n\n  have \"nodeOf (c, is) \\<in> sset nodes\"\n    unfolding `is = _` `c' = _` nodeOf.simps\n    by (rule iNodeOf_tree_at[OF iwf_it[OF `c \\<in> set conclusions`]  `is'''' \\<in> it_paths (it' c')`[unfolded `c' = _`]])\n    \n  from `var \\<in> a_fresh (inPorts' (iNodeOf (tree_at (it' c') is'''')) ! i')`\n       `var \\<in> a_fresh p` `p = inPorts' (nodeOf (c, is)) ! i`\n       node_disjoint_fresh_vars[OF\n          `nodeOf (c, is) \\<in> sset nodes`\n          `i < length (inPorts' (nodeOf (c, is)))` `i' < length (inPorts' (nodeOf (c, is)))`]\n  have \"i' = i\" by (auto simp add: `is=_` `c'=c`)\n   \n  from  `prefixeq (is''''@[i']) is''`\n  have \"prefixeq (is @ [i']) is'\" by (simp add: `is'=_` `is=_`)\n\n \n  from `c \\<in> set conclusions`  `is'' \\<in> it_paths (it' c')` `prefixeq (is @ [i']) is'`\n      `p = in_port_at (c, is) i`\n  have \"scope' v p v'\"\n  unfolding `v=_` `v'=_` `c' = _` `is' = _`  `i'=_` by (auto intro: scope'.intros)\n  thus \"v' \\<in> scope (v, p)\" using `valid_in_port (v, p)` by (simp add: in_scope)\nqed\n\nsublocale Scoped_Proof_Graph freshenLC renameLCs lconsts closed subst subst_lconsts subst_renameLCs anyP  inPorts outPorts nodeOf hyps nodes vertices labelsIn labelsOut vidx inst edges local_vars..\n\n(* interpretation of @{term Tasked_Proof_Graph} has to be named to avoid name clashes in @{term Abstract_Task}. *)\nsublocale tpg:Tasked_Proof_Graph freshenLC renameLCs lconsts closed subst subst_lconsts subst_renameLCs anyP antecedent consequent rules assumptions conclusions\n  vertices nodeOf edges vidx inst\nproof\n  show \"set (map Conclusion conclusions) \\<subseteq> nodeOf ` fset vertices\"\n  proof-\n  {\n    fix c\n    assume \"c \\<in> set conclusions\"\n    hence \"(c, []) |\\<in>| vertices\" by simp\n    hence \"nodeOf (c, []) \\<in> nodeOf ` fset vertices\"\n      unfolding fmember.rep_eq by (rule imageI)\n    hence \"Conclusion c \\<in> nodeOf ` fset vertices\"  by simp\n  } thus ?thesis by auto\n  qed\nqed  \n\nend\n\nend", "meta": {"author": "nomeata", "repo": "isa-incredible", "sha": "10eb1d938879778196cc69bf86b1ed0d979512cc", "save_path": "github-repos/isabelle/nomeata-isa-incredible", "path": "github-repos/isabelle/nomeata-isa-incredible/isa-incredible-10eb1d938879778196cc69bf86b1ed0d979512cc/Incredible_Completeness.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5583269943353744, "lm_q2_score": 0.5, "lm_q1q2_score": 0.2791634971676872}}
{"text": "section \\<open>Implementation of Nondeterministic Generalized Büchi Automata\\<close>\n\ntheory NGBA_Implement\nimports\n  \"NGBA_Refine\"\n  \"../../Basic/Implement\"\nbegin\n\n  consts i_ngba_scheme :: \"interface \\<Rightarrow> interface \\<Rightarrow> interface\"\n\n  context\n  begin\n\n    interpretation autoref_syn by this\n\n    lemma ngba_scheme_itype[autoref_itype]:\n      \"ngba ::\\<^sub>i \\<langle>L\\<rangle>\\<^sub>i i_set \\<rightarrow>\\<^sub>i \\<langle>S\\<rangle>\\<^sub>i i_set \\<rightarrow>\\<^sub>i (L \\<rightarrow>\\<^sub>i S \\<rightarrow>\\<^sub>i \\<langle>S\\<rangle>\\<^sub>i i_set) \\<rightarrow>\\<^sub>i \\<langle>\\<langle>S\\<rangle>\\<^sub>i i_set\\<rangle>\\<^sub>i i_list \\<rightarrow>\\<^sub>i\n        \\<langle>L, S\\<rangle>\\<^sub>i i_ngba_scheme\"\n      \"alphabet ::\\<^sub>i \\<langle>L, S\\<rangle>\\<^sub>i i_ngba_scheme \\<rightarrow>\\<^sub>i \\<langle>L\\<rangle>\\<^sub>i i_set\"\n      \"initial ::\\<^sub>i \\<langle>L, S\\<rangle>\\<^sub>i i_ngba_scheme \\<rightarrow>\\<^sub>i \\<langle>S\\<rangle>\\<^sub>i i_set\"\n      \"transition ::\\<^sub>i \\<langle>L, S\\<rangle>\\<^sub>i i_ngba_scheme \\<rightarrow>\\<^sub>i L \\<rightarrow>\\<^sub>i S \\<rightarrow>\\<^sub>i \\<langle>S\\<rangle>\\<^sub>i i_set\"\n      \"accepting ::\\<^sub>i \\<langle>L, S\\<rangle>\\<^sub>i i_ngba_scheme \\<rightarrow>\\<^sub>i \\<langle>\\<langle>S\\<rangle>\\<^sub>i i_set\\<rangle>\\<^sub>i i_list\"\n      by auto\n\n  end\n\n  datatype ('label, 'state) ngbai = ngbai\n    (alphabeti: \"'label list\")\n    (initiali: \"'state list\")\n    (transitioni: \"'label \\<Rightarrow> 'state \\<Rightarrow> 'state list\")\n    (acceptingi: \"('state \\<Rightarrow> bool) list\")\n\n  definition ngbai_rel :: \"('label\\<^sub>1 \\<times> 'label\\<^sub>2) set \\<Rightarrow> ('state\\<^sub>1 \\<times> 'state\\<^sub>2) set \\<Rightarrow>\n    (('label\\<^sub>1, 'state\\<^sub>1) ngbai \\<times> ('label\\<^sub>2, 'state\\<^sub>2) ngbai) set\" where\n    [to_relAPP]: \"ngbai_rel L S \\<equiv> {(A\\<^sub>1, A\\<^sub>2).\n      (alphabeti A\\<^sub>1, alphabeti A\\<^sub>2) \\<in> \\<langle>L\\<rangle> list_rel \\<and>\n      (initiali A\\<^sub>1, initiali A\\<^sub>2) \\<in> \\<langle>S\\<rangle> list_rel \\<and>\n      (transitioni A\\<^sub>1, transitioni A\\<^sub>2) \\<in> L \\<rightarrow> S \\<rightarrow> \\<langle>S\\<rangle> list_rel \\<and>\n      (acceptingi A\\<^sub>1, acceptingi A\\<^sub>2) \\<in> \\<langle>S \\<rightarrow> bool_rel\\<rangle> list_rel}\"\n\n  lemma ngbai_param[param]:\n    \"(ngbai, ngbai) \\<in> \\<langle>L\\<rangle> list_rel \\<rightarrow> \\<langle>S\\<rangle> list_rel \\<rightarrow> (L \\<rightarrow> S \\<rightarrow> \\<langle>S\\<rangle> list_rel) \\<rightarrow>\n      \\<langle>S \\<rightarrow> bool_rel\\<rangle> list_rel \\<rightarrow> \\<langle>L, S\\<rangle> ngbai_rel\"\n    \"(alphabeti, alphabeti) \\<in> \\<langle>L, S\\<rangle> ngbai_rel \\<rightarrow> \\<langle>L\\<rangle> list_rel\"\n    \"(initiali, initiali) \\<in> \\<langle>L, S\\<rangle> ngbai_rel \\<rightarrow> \\<langle>S\\<rangle> list_rel\"\n    \"(transitioni, transitioni) \\<in> \\<langle>L, S\\<rangle> ngbai_rel \\<rightarrow> L \\<rightarrow> S \\<rightarrow> \\<langle>S\\<rangle> list_rel\"\n    \"(acceptingi, acceptingi) \\<in> \\<langle>L, S\\<rangle> ngbai_rel \\<rightarrow> \\<langle>S \\<rightarrow> bool_rel\\<rangle> list_rel\"\n    unfolding ngbai_rel_def fun_rel_def by auto\n\n  definition ngbai_ngba_rel :: \"('label\\<^sub>1 \\<times> 'label\\<^sub>2) set \\<Rightarrow> ('state\\<^sub>1 \\<times> 'state\\<^sub>2) set \\<Rightarrow>\n    (('label\\<^sub>1, 'state\\<^sub>1) ngbai \\<times> ('label\\<^sub>2, 'state\\<^sub>2) ngba) set\" where\n    [to_relAPP]: \"ngbai_ngba_rel L S \\<equiv> {(A\\<^sub>1, A\\<^sub>2).\n      (alphabeti A\\<^sub>1, alphabet A\\<^sub>2) \\<in> \\<langle>L\\<rangle> list_set_rel \\<and>\n      (initiali A\\<^sub>1, initial A\\<^sub>2) \\<in> \\<langle>S\\<rangle> list_set_rel \\<and>\n      (transitioni A\\<^sub>1, transition A\\<^sub>2) \\<in> L \\<rightarrow> S \\<rightarrow> \\<langle>S\\<rangle> list_set_rel \\<and>\n      (acceptingi A\\<^sub>1, accepting A\\<^sub>2) \\<in> \\<langle>S \\<rightarrow> bool_rel\\<rangle> list_rel}\"\n\n  lemmas [autoref_rel_intf] = REL_INTFI[of ngbai_ngba_rel i_ngba_scheme]\n\n  lemma ngbai_ngba_param[param, autoref_rules]:\n    \"(ngbai, ngba) \\<in> \\<langle>L\\<rangle> list_set_rel \\<rightarrow> \\<langle>S\\<rangle> list_set_rel \\<rightarrow> (L \\<rightarrow> S \\<rightarrow> \\<langle>S\\<rangle> list_set_rel) \\<rightarrow>\n      \\<langle>S \\<rightarrow> bool_rel\\<rangle> list_rel \\<rightarrow> \\<langle>L, S\\<rangle> ngbai_ngba_rel\"\n    \"(alphabeti, alphabet) \\<in> \\<langle>L, S\\<rangle> ngbai_ngba_rel \\<rightarrow> \\<langle>L\\<rangle> list_set_rel\"\n    \"(initiali, initial) \\<in> \\<langle>L, S\\<rangle> ngbai_ngba_rel \\<rightarrow> \\<langle>S\\<rangle> list_set_rel\"\n    \"(transitioni, transition) \\<in> \\<langle>L, S\\<rangle> ngbai_ngba_rel \\<rightarrow> L \\<rightarrow> S \\<rightarrow> \\<langle>S\\<rangle> list_set_rel\"\n    \"(acceptingi, accepting) \\<in> \\<langle>L, S\\<rangle> ngbai_ngba_rel \\<rightarrow> \\<langle>S \\<rightarrow> bool_rel\\<rangle> list_rel\"\n    unfolding ngbai_ngba_rel_def fun_rel_def by auto\n\n  definition ngbai_ngba :: \"('label, 'state) ngbai \\<Rightarrow> ('label, 'state) ngba\" where\n    \"ngbai_ngba A \\<equiv> ngba (set (alphabeti A)) (set (initiali A)) (\\<lambda> a p. set (transitioni A a p)) (acceptingi A)\"\n  definition ngbai_invar :: \"('label, 'state) ngbai \\<Rightarrow> bool\" where\n    \"ngbai_invar A \\<equiv> distinct (alphabeti A) \\<and> distinct (initiali A) \\<and> (\\<forall> a p. distinct (transitioni A a p))\"\n\n  lemma ngbai_ngba_id_param[param]: \"(ngbai_ngba, id) \\<in> \\<langle>L, S\\<rangle> ngbai_ngba_rel \\<rightarrow> \\<langle>L, S\\<rangle> ngba_rel\"\n  proof\n    fix Ai A\n    assume 1: \"(Ai, A) \\<in> \\<langle>L, S\\<rangle> ngbai_ngba_rel\"\n    have 2: \"ngbai_ngba Ai = ngba (set (alphabeti Ai)) (set (initiali Ai))\n      (\\<lambda> a p. set (transitioni Ai a p)) (acceptingi Ai)\" unfolding ngbai_ngba_def by rule\n    have 3: \"id A = ngba (id (alphabet A)) (id (initial A))\n      (\\<lambda> a p. id (transition A a p)) (accepting A)\" by simp\n    show \"(ngbai_ngba Ai, id A) \\<in> \\<langle>L, S\\<rangle> ngba_rel\" unfolding 2 3 using 1 by parametricity\n  qed\n\n  lemma ngbai_ngba_br: \"\\<langle>Id, Id\\<rangle> ngbai_ngba_rel = br ngbai_ngba ngbai_invar\"\n  proof safe\n    show \"(A, B) \\<in> \\<langle>Id, Id\\<rangle> ngbai_ngba_rel\" if \"(A, B) \\<in> br ngbai_ngba ngbai_invar\"\n      for A and B :: \"('a, 'b) ngba\"\n      using that unfolding ngbai_ngba_rel_def ngbai_ngba_def ngbai_invar_def\n      by (auto simp: in_br_conv list_set_rel_def)\n    show \"(A, B) \\<in> br ngbai_ngba ngbai_invar\" if \"(A, B) \\<in> \\<langle>Id, Id\\<rangle> ngbai_ngba_rel\"\n      for A and B :: \"('a, 'b) ngba\"\n    proof -\n      have 1: \"(ngbai_ngba A, id B) \\<in> \\<langle>Id, Id\\<rangle> ngba_rel\" using that by parametricity\n      have 2: \"ngbai_invar A\"\n        using ngbai_ngba_param(2 - 5)[param_fo, OF that]\n        by (auto simp: in_br_conv list_set_rel_def ngbai_invar_def)\n      show ?thesis using 1 2 unfolding in_br_conv by auto\n    qed\n  qed\n\nend", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Transition_Systems_and_Automata/Automata/NBA/NGBA_Implement.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5583269796369905, "lm_q2_score": 0.5, "lm_q1q2_score": 0.27916348981849526}}
{"text": "theory CFGExit imports CFG begin\n\nsubsection \\<open>Adds an exit node to the abstract CFG\\<close>\n\nlocale CFGExit = CFG sourcenode targetnode kind valid_edge Entry \n    get_proc get_return_edges procs Main\n  for sourcenode :: \"'edge \\<Rightarrow> 'node\" and targetnode :: \"'edge \\<Rightarrow> 'node\"\n  and kind :: \"'edge \\<Rightarrow> ('var,'val,'ret,'pname) edge_kind\" \n  and valid_edge :: \"'edge \\<Rightarrow> bool\"\n  and Entry :: \"'node\" (\"'('_Entry'_')\")  and get_proc :: \"'node \\<Rightarrow> 'pname\"\n  and get_return_edges :: \"'edge \\<Rightarrow> 'edge set\"\n  and procs :: \"('pname \\<times> 'var list \\<times> 'var list) list\" and Main :: \"'pname\" +\n  fixes Exit::\"'node\"  (\"'('_Exit'_')\")\n  assumes Exit_source [dest]: \"\\<lbrakk>valid_edge a; sourcenode a = (_Exit_)\\<rbrakk> \\<Longrightarrow> False\"\n  and get_proc_Exit:\"get_proc (_Exit_) = Main\"\n  and Exit_no_return_target:\n    \"\\<lbrakk>valid_edge a; kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f; targetnode a = (_Exit_)\\<rbrakk> \\<Longrightarrow> False\"\n  and Entry_Exit_edge: \"\\<exists>a. valid_edge a \\<and> sourcenode a = (_Entry_) \\<and>\n    targetnode a = (_Exit_) \\<and> kind a = (\\<lambda>s. False)\\<^sub>\\<surd>\"\n  \n\nbegin\n\nlemma Entry_noteq_Exit [dest]:\n  assumes eq:\"(_Entry_) = (_Exit_)\" shows \"False\"\nproof -\n  from Entry_Exit_edge obtain a where \"sourcenode a = (_Entry_)\" \n    and \"valid_edge a\" by blast\n  with eq show False by simp(erule Exit_source)\nqed\n\nlemma Exit_noteq_Entry [dest]:\"(_Exit_) = (_Entry_) \\<Longrightarrow> False\"\n  by(rule Entry_noteq_Exit[OF sym],simp)\n\n\n\n\nlemma [simp]: \"valid_node (_Exit_)\"\nproof -\n  from Entry_Exit_edge obtain a where \"targetnode a = (_Exit_)\"\n    and \"valid_edge a\" by blast\n  thus ?thesis by(fastforce simp:valid_node_def)\nqed\n\n\nsubsubsection \\<open>Definition of \\<open>method_exit\\<close>\\<close>\n\ndefinition method_exit :: \"'node \\<Rightarrow> bool\"\n  where \"method_exit n \\<equiv> n = (_Exit_) \\<or> \n  (\\<exists>a Q p f. n = sourcenode a \\<and> valid_edge a \\<and> kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f)\"\n\n\nlemma method_exit_cases:\n  \"\\<lbrakk>method_exit n; n = (_Exit_) \\<Longrightarrow> P;\n    \\<And>a Q f p. \\<lbrakk>n = sourcenode a; valid_edge a; kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\\<rbrakk> \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\nby(fastforce simp:method_exit_def)\n\n\nlemma method_exit_inner_path:\n  assumes \"method_exit n\" and \"n -as\\<rightarrow>\\<^sub>\\<iota>* n'\" shows \"as = []\"\n  using \\<open>method_exit n\\<close>\nproof(rule method_exit_cases)\n  assume \"n = (_Exit_)\"\n  show ?thesis\n  proof(cases as)\n    case (Cons a' as')\n    with \\<open>n -as\\<rightarrow>\\<^sub>\\<iota>* n'\\<close> have \"n = sourcenode a'\" and \"valid_edge a'\"\n      by(auto elim:path_split_Cons simp:intra_path_def)\n    with \\<open>n = (_Exit_)\\<close> have \"sourcenode a' = (_Exit_)\" by simp\n    with \\<open>valid_edge a'\\<close> have False by(rule Exit_source)\n    thus ?thesis by simp\n  qed simp\nnext\n  fix a Q f p\n  assume \"n = sourcenode a\" and \"valid_edge a\" and \"kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\"\n  show ?thesis\n  proof(cases as)\n    case (Cons a' as')\n    with \\<open>n -as\\<rightarrow>\\<^sub>\\<iota>* n'\\<close> have \"n = sourcenode a'\" and \"valid_edge a'\" \n      and \"intra_kind (kind a')\"\n      by(auto elim:path_split_Cons simp:intra_path_def)\n    from \\<open>valid_edge a\\<close> \\<open>kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\\<close> \\<open>valid_edge a'\\<close> \\<open>n = sourcenode a\\<close> \n      \\<open>n = sourcenode a'\\<close> \\<open>intra_kind (kind a')\\<close>\n    have False by(fastforce dest:return_edges_only simp:intra_kind_def)\n    thus ?thesis by simp\n  qed simp\nqed\n\n\nsubsubsection \\<open>Definition of \\<open>inner_node\\<close>\\<close>\n\ndefinition inner_node :: \"'node \\<Rightarrow> bool\"\n  where inner_node_def: \n  \"inner_node n \\<equiv> valid_node n \\<and> n \\<noteq> (_Entry_) \\<and> n \\<noteq> (_Exit_)\"\n\n\nlemma inner_is_valid:\n  \"inner_node n \\<Longrightarrow> valid_node n\"\nby(simp add:inner_node_def valid_node_def)\n\nlemma [dest]:\n  \"inner_node (_Entry_) \\<Longrightarrow> False\"\nby(simp add:inner_node_def)\n\nlemma [dest]:\n  \"inner_node (_Exit_) \\<Longrightarrow> False\" \nby(simp add:inner_node_def)\n\nlemma [simp]:\"\\<lbrakk>valid_edge a; targetnode a \\<noteq> (_Exit_)\\<rbrakk> \n  \\<Longrightarrow> inner_node (targetnode a)\"\n  by(simp add:inner_node_def,rule ccontr,simp,erule Entry_target)\n\nlemma [simp]:\"\\<lbrakk>valid_edge a; sourcenode a \\<noteq> (_Entry_)\\<rbrakk>\n  \\<Longrightarrow> inner_node (sourcenode a)\"\n  by(simp add:inner_node_def,rule ccontr,simp,erule Exit_source)\n\nlemma valid_node_cases [consumes 1, case_names \"Entry\" \"Exit\" \"inner\"]:\n  \"\\<lbrakk>valid_node n; n = (_Entry_) \\<Longrightarrow> Q; n = (_Exit_) \\<Longrightarrow> Q;\n    inner_node n \\<Longrightarrow> Q\\<rbrakk> \\<Longrightarrow> Q\"\napply(auto simp:valid_node_def)\n apply(case_tac \"sourcenode a = (_Entry_)\") apply auto\napply(case_tac \"targetnode a = (_Exit_)\") apply auto\ndone\n\n\nsubsubsection \\<open>Lemmas on paths with \\<open>(_Exit_)\\<close>\\<close>\n\nlemma path_Exit_source:\n  \"\\<lbrakk>n -as\\<rightarrow>* n'; n = (_Exit_)\\<rbrakk> \\<Longrightarrow> n' = (_Exit_) \\<and> as = []\"\nproof(induct rule:path.induct)\n  case (Cons_path n'' as n' a n)\n  from \\<open>n = (_Exit_)\\<close> \\<open>sourcenode a = n\\<close> \\<open>valid_edge a\\<close> have False \n    by -(rule Exit_source,simp_all)\n  thus ?case by simp\nqed simp\n\nlemma [dest]:\"(_Exit_) -as\\<rightarrow>* n' \\<Longrightarrow> n' = (_Exit_) \\<and> as = []\"\n  by(fastforce elim!:path_Exit_source)\n\nlemma Exit_no_sourcenode[dest]:\n  assumes isin:\"(_Exit_) \\<in> set (sourcenodes as)\" and path:\"n -as\\<rightarrow>* n'\"\n  shows False\nproof -\n  from isin obtain ns' ns'' where \"sourcenodes as = ns'@(_Exit_)#ns''\"\n    by(auto dest:split_list simp:sourcenodes_def)\n  then obtain as' as'' a where \"as = as'@a#as''\"\n    and source:\"sourcenode a = (_Exit_)\"\n    by(fastforce elim:map_append_append_maps simp:sourcenodes_def)\n  with path have \"valid_edge a\" by(fastforce dest:path_split)\n  with source show ?thesis by -(erule Exit_source)\nqed\n\n\n\nlemma vpa_no_slpa:\n  \"\\<lbrakk>valid_path_aux cs as; n -as\\<rightarrow>* n'; valid_call_list cs n; cs \\<noteq> [];\n    \\<forall>xs ys. as = xs@ys \\<longrightarrow> (\\<not> same_level_path_aux cs xs \\<or> upd_cs cs xs \\<noteq> [])\\<rbrakk>\n  \\<Longrightarrow> \\<exists>a Q r fs. valid_edge a \\<and> kind a = Q:r\\<hookrightarrow>\\<^bsub>get_proc n'\\<^esub>fs\"\nproof(induct arbitrary:n rule:vpa_induct)\n  case (vpa_empty cs)\n  from \\<open>valid_call_list cs n\\<close> \\<open>cs \\<noteq> []\\<close> obtain Q r fs where \"valid_edge (hd cs)\"\n    and \"kind (hd cs) = Q:r\\<hookrightarrow>\\<^bsub>get_proc n\\<^esub>fs\"\n    apply(unfold valid_call_list_def)\n    apply(drule hd_Cons_tl[THEN sym])\n    apply(erule_tac x=\"[]\" in allE) \n    apply(erule_tac x=\"hd cs\" in allE)\n    by auto\n  from \\<open>n -[]\\<rightarrow>* n'\\<close> have \"n = n'\" by fastforce\n  with \\<open>valid_edge (hd cs)\\<close> \\<open>kind (hd cs) = Q:r\\<hookrightarrow>\\<^bsub>get_proc n\\<^esub>fs\\<close> show ?case by blast\nnext\n  case (vpa_intra cs a as)\n  note IH = \\<open>\\<And>n. \\<lbrakk>n -as\\<rightarrow>* n'; valid_call_list cs n; cs \\<noteq> [];\n    \\<forall>xs ys. as = xs@ys \\<longrightarrow> \\<not> same_level_path_aux cs xs \\<or> upd_cs cs xs \\<noteq> []\\<rbrakk>\n    \\<Longrightarrow> \\<exists>a' Q' r' fs'. valid_edge a' \\<and> kind a' = Q':r'\\<hookrightarrow>\\<^bsub>get_proc n'\\<^esub>fs'\\<close>\n  note all = \\<open>\\<forall>xs ys. a#as = xs@ys \n    \\<longrightarrow> \\<not> same_level_path_aux cs xs \\<or> upd_cs cs xs \\<noteq> []\\<close>\n  from \\<open>n -a#as\\<rightarrow>* n'\\<close> have \"sourcenode a = n\" and \"valid_edge a\" \n    and \"targetnode a -as\\<rightarrow>* n'\"\n    by(auto intro:path_split_Cons)\n  from \\<open>valid_call_list cs n\\<close> \\<open>cs \\<noteq> []\\<close> obtain Q r fs where \"valid_edge (hd cs)\"\n    and \"kind (hd cs) = Q:r\\<hookrightarrow>\\<^bsub>get_proc n\\<^esub>fs\"\n    apply(unfold valid_call_list_def)\n    apply(drule hd_Cons_tl[THEN sym])\n    apply(erule_tac x=\"[]\" in allE) \n    apply(erule_tac x=\"hd cs\" in allE)\n    by auto\n  from \\<open>valid_edge a\\<close> \\<open>intra_kind (kind a)\\<close>\n  have \"get_proc (sourcenode a) = get_proc (targetnode a)\" by(rule get_proc_intra)\n  with \\<open>kind (hd cs) = Q:r\\<hookrightarrow>\\<^bsub>get_proc n\\<^esub>fs\\<close> \\<open>sourcenode a = n\\<close>\n  have \"kind (hd cs) = Q:r\\<hookrightarrow>\\<^bsub>get_proc (targetnode a)\\<^esub>fs\" by simp\n  from \\<open>valid_call_list cs n\\<close> \\<open>sourcenode a = n\\<close>\n    \\<open>get_proc (sourcenode a) = get_proc (targetnode a)\\<close>\n  have \"valid_call_list cs (targetnode a)\"\n    apply(clarsimp simp:valid_call_list_def)\n    apply(erule_tac x=\"cs'\" in allE)\n    apply(erule_tac x=\"c\" in allE)\n    by(auto split:list.split)\n  from all \\<open>intra_kind (kind a)\\<close>\n  have \"\\<forall>xs ys. as = xs@ys \\<longrightarrow> \\<not> same_level_path_aux cs xs \\<or> upd_cs cs xs \\<noteq> []\"\n    apply clarsimp apply(erule_tac x=\"a#xs\" in allE)\n    by(auto simp:intra_kind_def)\n  from IH[OF \\<open>targetnode a -as\\<rightarrow>* n'\\<close> \\<open>valid_call_list cs (targetnode a)\\<close>\n    \\<open>cs \\<noteq> []\\<close> this] show ?case .\nnext\n  case (vpa_Call cs a as Q r p fs)\n  note IH = \\<open>\\<And>n. \\<lbrakk>n -as\\<rightarrow>* n'; valid_call_list (a#cs) n; a#cs \\<noteq> [];\n    \\<forall>xs ys. as = xs@ys \\<longrightarrow> \\<not> same_level_path_aux (a#cs) xs \\<or> upd_cs (a#cs) xs \\<noteq> []\\<rbrakk>\n    \\<Longrightarrow> \\<exists>a' Q' r' fs'. valid_edge a' \\<and> kind a' = Q':r'\\<hookrightarrow>\\<^bsub>get_proc n'\\<^esub>fs'\\<close>\n  note all = \\<open>\\<forall>xs ys.\n    a#as = xs@ys \\<longrightarrow> \\<not> same_level_path_aux cs xs \\<or> upd_cs cs xs \\<noteq> []\\<close>\n  from \\<open>n -a#as\\<rightarrow>* n'\\<close> have \"sourcenode a = n\" and \"valid_edge a\" \n    and \"targetnode a -as\\<rightarrow>* n'\"\n    by(auto intro:path_split_Cons)\n  from \\<open>valid_edge a\\<close> \\<open>kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\\<close> have \"get_proc (targetnode a) = p\"\n    by(rule get_proc_call)\n  with \\<open>kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\\<close> have \"kind a = Q:r\\<hookrightarrow>\\<^bsub>get_proc (targetnode a)\\<^esub>fs\" by simp\n  with \\<open>valid_call_list cs n\\<close> \\<open>valid_edge a\\<close> \\<open>sourcenode a = n\\<close>\n  have \"valid_call_list (a#cs) (targetnode a)\"\n    apply(clarsimp simp:valid_call_list_def)\n    apply(case_tac cs') apply auto\n    apply(erule_tac x=\"list\" in allE)\n    apply(erule_tac x=\"c\" in allE)\n    by(auto split:list.split simp:sourcenodes_def)\n  from all \\<open>kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\\<close>\n  have \"\\<forall>xs ys. as = xs@ys \n    \\<longrightarrow> \\<not> same_level_path_aux (a#cs) xs \\<or> upd_cs (a#cs) xs \\<noteq> []\"\n    apply clarsimp apply(erule_tac x=\"a#xs\" in allE)\n    by auto\n  from IH[OF \\<open>targetnode a -as\\<rightarrow>* n'\\<close> \\<open>valid_call_list (a#cs) (targetnode a)\\<close>\n    _ this] show ?case by simp\nnext\n  case (vpa_ReturnEmpty cs a as Q p fx)\n  from \\<open>cs \\<noteq> []\\<close> \\<open>cs = []\\<close> have False by simp\n  thus ?case by simp\nnext\n  case (vpa_ReturnCons cs a as Q p f c' cs')\n  note IH = \\<open>\\<And>n. \\<lbrakk>n -as\\<rightarrow>* n'; valid_call_list cs' n; cs' \\<noteq> [];\n    \\<forall>xs ys. as = xs@ys \\<longrightarrow> \\<not> same_level_path_aux cs' xs \\<or> upd_cs cs' xs \\<noteq> []\\<rbrakk>\n    \\<Longrightarrow> \\<exists>a' Q' r' fs'. valid_edge a' \\<and> kind a' = Q':r'\\<hookrightarrow>\\<^bsub>get_proc n'\\<^esub>fs'\\<close>\n  note all = \\<open>\\<forall>xs ys. a#as = xs@ys \n    \\<longrightarrow> \\<not> same_level_path_aux cs xs \\<or> upd_cs cs xs \\<noteq> []\\<close>\n  from \\<open>n -a#as\\<rightarrow>* n'\\<close> have \"sourcenode a = n\" and \"valid_edge a\" \n    and \"targetnode a -as\\<rightarrow>* n'\"\n    by(auto intro:path_split_Cons)\n  from \\<open>valid_call_list cs n\\<close> \\<open>cs = c'#cs'\\<close> have \"valid_edge c'\"\n    apply(clarsimp simp:valid_call_list_def)\n    apply(erule_tac x=\"[]\" in allE)\n    by auto\n  show ?case\n  proof(cases \"cs' = []\")\n    case True\n    with all \\<open>cs = c'#cs'\\<close> \\<open>kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\\<close> \\<open>a \\<in> get_return_edges c'\\<close> have False\n      by(erule_tac x=\"[a]\" in allE,fastforce)\n    thus ?thesis by simp\n  next\n    case False\n    with \\<open>valid_call_list cs n\\<close> \\<open>cs = c'#cs'\\<close>\n    have \"valid_call_list cs' (sourcenode c')\"\n      apply(clarsimp simp:valid_call_list_def)\n      apply(hypsubst_thin)\n      apply(erule_tac x=\"c'#cs'\" in allE)\n      apply(auto simp:sourcenodes_def)\n       apply(case_tac cs') apply auto\n      apply(case_tac list) apply(auto simp:sourcenodes_def)\n      done\n    from \\<open>valid_edge c'\\<close> \\<open>a \\<in> get_return_edges c'\\<close>\n    have \"get_proc (sourcenode c') = get_proc (targetnode a)\"\n      by(rule get_proc_get_return_edge)\n    with \\<open>valid_call_list cs' (sourcenode c')\\<close>\n    have \"valid_call_list cs' (targetnode a)\"\n      apply(clarsimp simp:valid_call_list_def)\n      apply(hypsubst_thin)\n    apply(erule_tac x=\"cs'\" in allE)\n    apply(erule_tac x=\"c\" in allE)\n    by(auto split:list.split)\n    from all \\<open>kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\\<close> \\<open>cs = c'#cs'\\<close> \\<open>a \\<in> get_return_edges c'\\<close>\n    have \"\\<forall>xs ys. as = xs@ys \\<longrightarrow> \\<not> same_level_path_aux cs' xs \\<or> upd_cs cs' xs \\<noteq> []\"\n      apply clarsimp apply(erule_tac x=\"a#xs\" in allE)\n      by auto  \n    from IH[OF \\<open>targetnode a -as\\<rightarrow>* n'\\<close> \\<open>valid_call_list cs' (targetnode a)\\<close>\n      False this] show ?thesis .\n  qed\nqed\n\n\nlemma valid_Exit_path_cases:\n  assumes \"n -as\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\" and \"as \\<noteq> []\"\n  shows \"(\\<exists>a' as'. as = a'#as' \\<and> intra_kind(kind a')) \\<or>\n         (\\<exists>a' as' Q p f. as = a'#as' \\<and> kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f) \\<or>\n         (\\<exists>as' as'' n'. as = as'@as'' \\<and> as' \\<noteq> [] \\<and> n -as'\\<rightarrow>\\<^bsub>sl\\<^esub>* n')\"\nproof -\n  from \\<open>as \\<noteq> []\\<close> obtain a' as' where \"as = a'#as'\" by(cases as) auto\n  thus ?thesis\n  proof(cases \"kind a'\" rule:edge_kind_cases)\n    case Intra with \\<open>as = a'#as'\\<close> show ?thesis by simp\n  next\n    case Return with \\<open>as = a'#as'\\<close> show ?thesis by simp\n  next\n    case (Call Q r p f)\n    from \\<open>n -as\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\\<close> have \"n -as\\<rightarrow>* (_Exit_)\" and \"valid_path_aux [] as\"\n      by(simp_all add:vp_def valid_path_def)\n    from \\<open>n -as\\<rightarrow>* (_Exit_)\\<close> \\<open>as = a'#as'\\<close>\n    have \"sourcenode a' = n\" and \"valid_edge a'\" and \"targetnode a' -as'\\<rightarrow>* (_Exit_)\"\n      by(auto intro:path_split_Cons)\n    from \\<open>valid_path_aux [] as\\<close> \\<open>as = a'#as'\\<close> Call\n    have \"valid_path_aux [a'] as'\" by simp\n    from \\<open>valid_edge a'\\<close> Call\n    have \"valid_call_list [a'] (targetnode a')\"\n      apply(clarsimp simp:valid_call_list_def)\n      apply(case_tac cs') \n      by(auto intro:get_proc_call[THEN sym])\n    show ?thesis\n    proof(cases \"\\<forall>xs ys. as' = xs@ys \\<longrightarrow> \n        (\\<not> same_level_path_aux [a'] xs \\<or> upd_cs [a'] xs \\<noteq> [])\")\n      case True\n      with \\<open>valid_path_aux [a'] as'\\<close> \\<open>targetnode a' -as'\\<rightarrow>* (_Exit_)\\<close>\n        \\<open>valid_call_list [a'] (targetnode a')\\<close>\n      obtain ax Qx rx fsx where \"valid_edge ax\" and \"kind ax = Qx:rx\\<hookrightarrow>\\<^bsub>get_proc (_Exit_)\\<^esub>fsx\"\n        by(fastforce dest!:vpa_no_slpa)\n      hence False by(fastforce intro:Main_no_call_target simp:get_proc_Exit)\n      thus ?thesis by simp\n    next\n      case False\n      then obtain xs ys where \"as' = xs@ys\" and \"same_level_path_aux [a'] xs\"\n        and \"upd_cs [a'] xs = []\" by auto\n      with Call have \"same_level_path (a'#xs)\" by(simp add:same_level_path_def)\n      from \\<open>upd_cs [a'] xs = []\\<close> have \"xs \\<noteq> []\" by auto\n      with \\<open>targetnode a' -as'\\<rightarrow>* (_Exit_)\\<close> \\<open>as' = xs@ys\\<close>\n      have \"targetnode a' -xs\\<rightarrow>* last(targetnodes xs)\"\n        apply(cases xs rule:rev_cases)\n        by(auto intro:path_Append path_split path_edge simp:targetnodes_def)\n      with \\<open>sourcenode a' = n\\<close> \\<open>valid_edge a'\\<close> \\<open>same_level_path (a'#xs)\\<close>\n      have \"n -a'#xs\\<rightarrow>\\<^bsub>sl\\<^esub>* last(targetnodes xs)\"\n        by(fastforce intro:Cons_path simp:slp_def)\n      with \\<open>as = a'#as'\\<close> \\<open>as' = xs@ys\\<close> Call \n      have \"\\<exists>as' as'' n'. as = as'@as'' \\<and> as' \\<noteq> [] \\<and> n -as'\\<rightarrow>\\<^bsub>sl\\<^esub>* n'\"\n        by(rule_tac x=\"a'#xs\" in exI) auto\n      thus ?thesis by simp\n    qed\n  qed\nqed\n\n\nlemma valid_Exit_path_descending_path:\n  assumes \"n -as\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\"\n  obtains as' where \"n -as'\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\" \n  and \"set(sourcenodes as') \\<subseteq> set(sourcenodes as)\"\n  and \"\\<forall>a' \\<in> set as'. intra_kind(kind a') \\<or> (\\<exists>Q f p. kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f)\"\nproof(atomize_elim)\n  from \\<open>n -as\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\\<close>\n  show \"\\<exists>as'. n -as'\\<rightarrow>\\<^sub>\\<surd>* (_Exit_) \\<and> set(sourcenodes as') \\<subseteq> set(sourcenodes as)\\<and>\n              (\\<forall>a' \\<in> set as'. intra_kind(kind a') \\<or> (\\<exists>Q f p. kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f))\"\n  proof(induct as arbitrary:n rule:length_induct)\n    fix as n\n    assume IH:\"\\<forall>as''. length as'' < length as \\<longrightarrow>\n      (\\<forall>n'. n' -as''\\<rightarrow>\\<^sub>\\<surd>* (_Exit_) \\<longrightarrow>\n       (\\<exists>as'. n' -as'\\<rightarrow>\\<^sub>\\<surd>* (_Exit_) \\<and> set (sourcenodes as') \\<subseteq> set (sourcenodes as'') \\<and>\n              (\\<forall>a'\\<in>set as'. intra_kind (kind a') \\<or> (\\<exists>Q f p. kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f))))\"\n      and \"n -as\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\"\n    show \"\\<exists>as'. n -as'\\<rightarrow>\\<^sub>\\<surd>* (_Exit_) \\<and> set(sourcenodes as') \\<subseteq> set(sourcenodes as)\\<and>\n              (\\<forall>a' \\<in> set as'. intra_kind(kind a') \\<or> (\\<exists>Q f p. kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f))\"\n    proof(cases \"as = []\")\n      case True\n      with \\<open>n -as\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\\<close> show ?thesis by(fastforce simp:sourcenodes_def vp_def)\n    next\n      case False\n      with \\<open>n -as\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\\<close>\n      have \"((\\<exists>a' as'. as = a'#as' \\<and> intra_kind(kind a')) \\<or>\n         (\\<exists>a' as' Q p f. as = a'#as' \\<and> kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f)) \\<or>\n         (\\<exists>as' as'' n'. as = as'@as'' \\<and> as' \\<noteq> [] \\<and> n -as'\\<rightarrow>\\<^bsub>sl\\<^esub>* n')\"\n        by(auto dest!:valid_Exit_path_cases)\n      thus ?thesis apply -\n      proof(erule disjE)+\n        assume \"\\<exists>a' as'. as = a'#as' \\<and> intra_kind(kind a')\"\n        then obtain a' as' where \"as = a'#as'\" and \"intra_kind(kind a')\" by blast\n        from \\<open>n -as\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\\<close> \\<open>as = a'#as'\\<close>\n        have \"sourcenode a' = n\" and \"valid_edge a'\" \n          and \"targetnode a' -as'\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\"\n          by(auto intro:vp_split_Cons)\n        from \\<open>valid_edge a'\\<close> \\<open>intra_kind(kind a')\\<close>\n        have \"sourcenode a' -[a']\\<rightarrow>\\<^bsub>sl\\<^esub>* targetnode a'\"\n          by(fastforce intro:path_edge intras_same_level_path simp:slp_def)\n        from IH \\<open>targetnode a' -as'\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\\<close> \\<open>as = a'#as'\\<close>\n        obtain xs where \"targetnode a' -xs\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\" \n          and \"set (sourcenodes xs) \\<subseteq> set (sourcenodes as')\"\n          and \"\\<forall>a'\\<in>set xs. intra_kind (kind a') \\<or> (\\<exists>Q f p. kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f)\"\n          apply(erule_tac x=\"as'\" in allE) by auto\n        from \\<open>sourcenode a' -[a']\\<rightarrow>\\<^bsub>sl\\<^esub>* targetnode a'\\<close> \\<open>targetnode a' -xs\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\\<close>\n        have \"sourcenode a' -[a']@xs\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\" by(rule slp_vp_Append)\n        with \\<open>sourcenode a' = n\\<close> have \"n -a'#xs\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\" by simp\n        moreover\n        from \\<open>set (sourcenodes xs) \\<subseteq> set (sourcenodes as')\\<close> \\<open>as = a'#as'\\<close>\n        have \"set (sourcenodes (a'#xs)) \\<subseteq> set (sourcenodes as)\"\n          by(auto simp:sourcenodes_def)\n        moreover\n        from \\<open>\\<forall>a'\\<in>set xs. intra_kind (kind a') \\<or> (\\<exists>Q f p. kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f)\\<close> \n          \\<open>intra_kind(kind a')\\<close>\n        have \"\\<forall>a'\\<in>set (a'#xs). intra_kind (kind a') \\<or> (\\<exists>Q f p. kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f)\"\n          by fastforce\n        ultimately show ?thesis by blast\n      next\n        assume \"\\<exists>a' as' Q p f. as = a'#as' \\<and> kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\"\n        then obtain a' as' Q p f where \"as = a'#as'\" and \"kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\" by blast\n        from \\<open>n -as\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\\<close> \\<open>as = a'#as'\\<close>\n        have \"sourcenode a' = n\" and \"valid_edge a'\" \n          and \"targetnode a' -as'\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\"\n          by(auto intro:vp_split_Cons)\n        from IH \\<open>targetnode a' -as'\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\\<close> \\<open>as = a'#as'\\<close>\n        obtain xs where \"targetnode a' -xs\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\" \n          and \"set (sourcenodes xs) \\<subseteq> set (sourcenodes as')\"\n          and \"\\<forall>a'\\<in>set xs. intra_kind (kind a') \\<or> (\\<exists>Q f p. kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f)\"\n          apply(erule_tac x=\"as'\" in allE) by auto\n        from \\<open>sourcenode a' = n\\<close> \\<open>valid_edge a'\\<close> \\<open>kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\\<close>\n          \\<open>targetnode a' -xs\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\\<close>\n        have \"n -a'#xs\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\"\n          by(fastforce intro:Cons_path simp:vp_def valid_path_def)\n        moreover\n        from \\<open>set (sourcenodes xs) \\<subseteq> set (sourcenodes as')\\<close> \\<open>as = a'#as'\\<close>\n        have \"set (sourcenodes (a'#xs)) \\<subseteq> set (sourcenodes as)\"\n          by(auto simp:sourcenodes_def)\n        moreover\n        from \\<open>\\<forall>a'\\<in>set xs. intra_kind (kind a') \\<or> (\\<exists>Q f p. kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f)\\<close> \n          \\<open>kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\\<close>\n        have \"\\<forall>a'\\<in>set (a'#xs). intra_kind (kind a') \\<or> (\\<exists>Q f p. kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f)\"\n          by fastforce\n        ultimately show ?thesis by blast\n      next\n        assume \"\\<exists>as' as'' n'. as = as'@as'' \\<and> as' \\<noteq> [] \\<and> n -as'\\<rightarrow>\\<^bsub>sl\\<^esub>* n'\"\n        then obtain as' as'' n' where \"as = as'@as''\" and \"as' \\<noteq> []\"\n          and \"n -as'\\<rightarrow>\\<^bsub>sl\\<^esub>* n'\" by blast\n        from \\<open>n -as\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\\<close> \\<open>as = as'@as''\\<close> \\<open>as' \\<noteq> []\\<close>\n        have \"last(targetnodes as') -as''\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\"\n          by(cases as' rule:rev_cases,auto intro:vp_split simp:targetnodes_def)\n        from \\<open>n -as'\\<rightarrow>\\<^bsub>sl\\<^esub>* n'\\<close> \\<open>as' \\<noteq> []\\<close> have \"last(targetnodes as') = n'\"\n          by(fastforce intro:path_targetnode simp:slp_def)\n        from \\<open>as = as'@as''\\<close> \\<open>as' \\<noteq> []\\<close> have \"length as'' < length as\" by simp\n        with IH \\<open>last(targetnodes as') -as''\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\\<close>\n          \\<open>last(targetnodes as') = n'\\<close>\n        obtain xs where \"n' -xs\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\" \n          and \"set (sourcenodes xs) \\<subseteq> set (sourcenodes as'')\"\n          and \"\\<forall>a'\\<in>set xs. intra_kind (kind a') \\<or> (\\<exists>Q f p. kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f)\"\n          apply(erule_tac x=\"as''\" in allE) by auto\n        from \\<open>n -as'\\<rightarrow>\\<^bsub>sl\\<^esub>* n'\\<close> obtain ys where \"n -ys\\<rightarrow>\\<^sub>\\<iota>* n'\"\n          and \"set(sourcenodes ys) \\<subseteq> set(sourcenodes as')\"\n          by(erule same_level_path_inner_path)\n        from \\<open>n -ys\\<rightarrow>\\<^sub>\\<iota>* n'\\<close> \\<open>n' -xs\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\\<close> have \"n -ys@xs\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\"\n          by(fastforce intro:slp_vp_Append intra_path_slp)\n        moreover\n        from \\<open>set (sourcenodes xs) \\<subseteq> set (sourcenodes as'')\\<close>\n          \\<open>set(sourcenodes ys) \\<subseteq> set(sourcenodes as')\\<close> \\<open>as = as'@as''\\<close>\n        have \"set (sourcenodes (ys@xs)) \\<subseteq> set(sourcenodes as)\"\n          by(auto simp:sourcenodes_def)\n        moreover\n        from \\<open>\\<forall>a'\\<in>set xs. intra_kind (kind a') \\<or> (\\<exists>Q f p. kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f)\\<close>\n          \\<open>n -ys\\<rightarrow>\\<^sub>\\<iota>* n'\\<close>\n        have \"\\<forall>a'\\<in>set (ys@xs). intra_kind (kind a') \\<or> (\\<exists>Q f p. kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f)\"\n          by(fastforce simp:intra_path_def)\n        ultimately show ?thesis by blast\n      qed\n    qed\n  qed\nqed\n\n\nlemma valid_Exit_path_intra_path:\n  assumes \"n -as\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\" \n  obtains as' pex where \"n -as'\\<rightarrow>\\<^sub>\\<iota>* pex\" and \"method_exit pex\" \n  and \"set(sourcenodes as') \\<subseteq> set(sourcenodes as)\"\nproof(atomize_elim)\n  from \\<open>n -as\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\\<close>\n  obtain as' where \"n -as'\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\" \n    and \"set(sourcenodes as') \\<subseteq> set(sourcenodes as)\"\n    and all:\"\\<forall>a' \\<in> set as'. intra_kind(kind a') \\<or> (\\<exists>Q f p. kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f)\"\n    by(erule valid_Exit_path_descending_path)\n  show \"\\<exists>as' pex. n -as'\\<rightarrow>\\<^sub>\\<iota>* pex \\<and> method_exit pex \\<and> \n                  set(sourcenodes as') \\<subseteq> set(sourcenodes as)\"\n  proof(cases \"\\<exists>a' \\<in> set as'. \\<exists>Q f p. kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\")\n    case True\n    then obtain asx ax asx' where [simp]:\"as' = asx@ax#asx'\" \n      and \"\\<exists>Q f p. kind ax = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\" and \"\\<forall>a' \\<in> set asx. \\<not> (\\<exists>Q f p. kind a' = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f)\"\n      by(erule split_list_first_propE)\n    with all have \"\\<forall>a' \\<in> set asx. intra_kind(kind a')\" by auto\n    from \\<open>n -as'\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\\<close> have \"n -asx\\<rightarrow>* sourcenode ax\"\n      and \"valid_edge ax\" by(auto elim:path_split simp:vp_def)\n    from \\<open>n -asx\\<rightarrow>* sourcenode ax\\<close> \\<open>\\<forall>a' \\<in> set asx. intra_kind(kind a')\\<close>\n    have \"n -asx\\<rightarrow>\\<^sub>\\<iota>* sourcenode ax\" by(simp add:intra_path_def)\n    moreover\n    from \\<open>valid_edge ax\\<close> \\<open>\\<exists>Q f p. kind ax = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\\<close>\n    have \"method_exit (sourcenode ax)\" by(fastforce simp:method_exit_def)\n    moreover\n    from \\<open>set(sourcenodes as') \\<subseteq> set(sourcenodes as)\\<close>\n    have \"set(sourcenodes asx) \\<subseteq> set(sourcenodes as)\" by(simp add:sourcenodes_def)\n    ultimately show ?thesis by blast\n  next\n    case False\n    with all \\<open>n -as'\\<rightarrow>\\<^sub>\\<surd>* (_Exit_)\\<close> have \"n -as'\\<rightarrow>\\<^sub>\\<iota>* (_Exit_)\" \n      by(fastforce simp:vp_def intra_path_def)\n    moreover have \"method_exit (_Exit_)\" by(simp add:method_exit_def)\n    ultimately show ?thesis using \\<open>set(sourcenodes as') \\<subseteq> set(sourcenodes as)\\<close>\n      by blast\n  qed\nqed\n\n\n\nend \n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/HRB-Slicing/StaticInter/CFGExit.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.600188359260205, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.2790285113400851}}
{"text": "(*\n * Copyright 2014, General Dynamics C4 Systems\n *\n * SPDX-License-Identifier: GPL-2.0-only\n *)\n\ntheory Recycle_C\nimports Delete_C Retype_C\nbegin\n\ncontext kernel_m\nbegin\n\ndefinition\n  \"replicateHider \\<equiv> replicate\"\n\nlemma collapse_foldl_replicate:\n  \"replicate (length xs) v = xs \\<Longrightarrow>\n   foldl (@) [] (map (\\<lambda>_. xs) ys)\n        = replicateHider (length xs * length ys) v\"\n  apply (induct ys rule: rev_induct)\n   apply (simp add: replicateHider_def)\n  apply (simp add: replicateHider_def)\n  apply (subst add.commute, simp add: replicate_add)\n  done\n\nlemma coerce_memset_to_heap_update_user_data:\n  \"heap_update_list x (replicateHider 4096 0)\n      = heap_update (Ptr x :: user_data_C ptr)\n             (user_data_C (FCP (\\<lambda>_. 0)))\"\n  apply (intro ext, simp add: heap_update_def)\n  apply (rule_tac f=\"\\<lambda>xs. heap_update_list x xs a b\" for a b in arg_cong)\n  apply (simp add: to_bytes_def size_of_def typ_info_simps user_data_C_tag_def)\n  apply (simp add: ti_typ_pad_combine_empty_ti ti_typ_pad_combine_td align_of_def padup_def\n                   final_pad_def size_td_lt_ti_typ_pad_combine Let_def size_of_def)\n  apply (simp add: typ_info_simps\n                   user_context_C_tag_def thread_state_C_tag_def seL4_Fault_C_tag_def\n                   lookup_fault_C_tag_def update_ti_t_ptr_0s\n                   ti_typ_pad_combine_empty_ti ti_typ_pad_combine_td\n                   align_of_def padup_def\n                   final_pad_def size_td_lt_ti_typ_pad_combine Let_def size_of_def\n                   align_td_array' size_td_array)\n  apply (simp add: typ_info_array')\n  apply (subst access_ti_list_array)\n     apply simp\n    apply simp\n   apply (simp add: fcp_beta typ_info_word typ_info_ptr word_rsplit_0)\n   apply fastforce\n  apply (simp add: collapse_foldl_replicate)\n  done\n\nlemma clift_foldl_hrs_mem_update:\n  \"\\<lbrakk> \\<forall>x \\<in> set xs. hrs_htd s \\<Turnstile>\\<^sub>t f x;\n     \\<And>x s. hrs_htd s \\<Turnstile>\\<^sub>t f x \\<Longrightarrow> clift (hrs_mem_update (heap_update (f x) v) s)\n                                  = g (clift s :: ('a :: c_type) ptr \\<rightharpoonup> 'a) x \\<rbrakk>\n   \\<Longrightarrow>\n   clift (hrs_mem_update (\\<lambda>s. foldl (\\<lambda>s x. heap_update (f x) v s) s xs) s)\n       = foldl g (clift s :: 'a ptr \\<rightharpoonup> 'a) xs\"\n  using [[hypsubst_thin]]\n  apply (cases s, clarsimp)\n  apply (induct xs arbitrary: a b)\n   apply (simp add: hrs_mem_update_def)\n  apply (clarsimp simp add: hrs_mem_update_def split_def hrs_htd_def)\n  done\n\nlemma map_to_user_data_aligned:\n  \"\\<lbrakk> map_to_user_data (ksPSpace s) x = Some y; pspace_aligned' s \\<rbrakk>\n        \\<Longrightarrow> is_aligned x pageBits\"\n  apply (clarsimp simp: map_comp_eq projectKOs split: option.split_asm)\n  apply (drule(1) pspace_alignedD')\n  apply (simp add: objBits_simps)\n  done\n\nlemma help_force_intvl_range_conv:\n  \"\\<lbrakk> is_aligned (p::word32) n; v = 2 ^ n; n < word_bits \\<rbrakk>\n    \\<Longrightarrow> {p ..+ v} = {p .. p + 2 ^ n - 1}\"\n  by (simp add: intvl_range_conv word_bits_def)\n\nlemma cmap_relation_If_upd:\n  \"\\<lbrakk> cmap_relation f g ptrfun rel; rel v v'; ptrfun ` S = S'; inj ptrfun \\<rbrakk>\n   \\<Longrightarrow> cmap_relation (\\<lambda>x. if x \\<in> S then Some v else f x)\n                     (\\<lambda>y. if y \\<in> S' then Some v' else g y)\n        ptrfun rel\"\n  apply (simp add: cmap_relation_def dom_If_Some)\n  apply (rule context_conjI)\n   apply blast\n  apply clarsimp\n  apply (case_tac \"x \\<in> S\")\n   apply simp\n  apply clarsimp\n  apply (subst if_not_P)\n   apply (clarsimp simp: inj_eq)\n  apply (drule bspec, erule domI)\n  apply simp\n  done\n\nlemma length_replicateHider [simp]:\n  \"length (replicateHider n x) = n\"\n  by (simp add: replicateHider_def)\n\nlemma coerce_heap_update_to_heap_updates':\n  \"n = chunk * m \\<Longrightarrow>\n  heap_update_list x (replicateHider n 0)\n  = (\\<lambda>s. foldl (\\<lambda>s x. heap_update_list x (replicateHider chunk 0) s) s\n    (map (\\<lambda>n. x + (of_nat n * of_nat chunk)) [0 ..< m]))\"\n  using [[hypsubst_thin]]\n  apply clarsimp\n  apply (induct m arbitrary: x)\n   apply (rule ext, simp)\n   apply (simp add: replicateHider_def)\n  apply (rule ext)\n  apply (simp only: map_upt_unfold map_Suc_upt[symmetric])\n  apply (simp add: replicate_add[folded replicateHider_def]\n                   heap_update_list_concat_unfold\n                   o_def field_simps\n                   length_replicate[folded replicateHider_def])\n  done\n\nlemma h_t_valid_dom_s:\n  \"\\<lbrakk> h_t_valid htd c_guard p; x = ptr_val (p :: ('a :: mem_type) ptr);\n              n = size_of TYPE ('a) \\<rbrakk>\n    \\<Longrightarrow> {x ..+ n} \\<times> {SIndexVal, SIndexTyp 0} \\<subseteq> dom_s htd\"\n  apply (clarsimp simp: h_t_valid_def valid_footprint_def Let_def\n                        intvl_def)\n  apply (drule_tac x=k in spec, simp add: size_of_def)\n  apply (clarsimp simp: dom_s_def)\n  apply (drule_tac x=0 in map_leD, simp_all)\n  done\n\nlemma user_data_at_rf_sr_dom_s:\n  \"\\<lbrakk> typ_at' UserDataT x s; (s, s') \\<in> rf_sr \\<rbrakk>\n    \\<Longrightarrow> {x ..+ 2 ^ pageBits} \\<times> {SIndexVal, SIndexTyp 0}\n    \\<subseteq> dom_s (hrs_htd (t_hrs_' (globals s')))\"\n  apply (drule rf_sr_heap_user_data_relation)\n  apply (drule user_data_at_ko)\n  apply (erule_tac x=x in cmap_relationE1)\n   apply (simp only: heap_to_user_data_def Let_def ko_at_projectKO_opt)\n   apply simp\n  apply (drule h_t_valid_clift)\n  apply (simp add: h_t_valid_dom_s pageBits_def)\n  done\n\nlemma intvl_2_power_times_decomp:\n  \"\\<forall>y < 2 ^ (n - m). {x + y * 2 ^ m ..+ 2 ^ m} \\<times> S \\<subseteq> T\n    \\<Longrightarrow> m \\<le> n \\<Longrightarrow> n < word_bits\n    \\<Longrightarrow> {(x :: word32) ..+ 2 ^ n} \\<times> S \\<subseteq> T\"\n  apply (clarsimp simp: intvl_def)\n  apply (drule_tac x=\"of_nat k >> m\" in spec)\n  apply (drule mp)\n   apply (rule shiftr_less_t2n)\n   apply (rule word_of_nat_less)\n   apply (simp add: word_of_nat_less)\n  apply (erule subsetD)\n  apply (clarsimp simp: shiftl_t2n[simplified mult.commute mult.left_commute, symmetric]\n                        shiftr_shiftl1)\n  apply (rule_tac x=\"unat (of_nat k && mask m :: word32)\" in exI)\n  apply (simp add: field_simps word_plus_and_or_coroll2)\n  apply (simp add: word_bits_def unat_less_power and_mask_less')\n  done\n\nlemma flex_user_data_at_rf_sr_dom_s:\n  \"\\<lbrakk> (\\<forall>p<2 ^ (pageBitsForSize sz - pageBits).\n         typ_at' UserDataT (x + p * 2 ^ pageBits) s); (s, s') \\<in> rf_sr \\<rbrakk>\n    \\<Longrightarrow> {x ..+ 2 ^ pageBitsForSize sz} \\<times> {SIndexVal, SIndexTyp 0}\n    \\<subseteq> dom_s (hrs_htd (t_hrs_' (globals s')))\"\n  apply (rule_tac m=pageBits in intvl_2_power_times_decomp,\n         simp_all add: pbfs_atleast_pageBits pbfs_less_wb')\n  apply (erule allEI, clarsimp)\n  apply (drule(1) user_data_at_rf_sr_dom_s)\n  apply (erule subsetD)\n  apply simp\n  done\n\nlemma hrs_mem_update_fold_eq:\n  \"hrs_mem_update (fold f xs)\n    = fold (hrs_mem_update o f) xs\"\n  apply (rule sym, induct xs)\n   apply (simp add: hrs_mem_update_def)\n  apply (simp add: hrs_mem_update_def fun_eq_iff)\n  done\n\nlemma power_user_page_foldl_zero_ranges:\n  \" \\<forall>p<2 ^ (pageBitsForSize sz - pageBits).\n      hrs_htd hrs \\<Turnstile>\\<^sub>t (Ptr (ptr + of_nat p * 0x1000) :: user_data_C ptr)\n    \\<Longrightarrow> zero_ranges_are_zero rngs hrs\n    \\<Longrightarrow> zero_ranges_are_zero rngs\n        (hrs_mem_update (\\<lambda>s. foldl (\\<lambda>s x. heap_update (Ptr x) (user_data_C (arr x)) s) s\n            (map (\\<lambda>n. ptr + of_nat n * 0x1000) [0..<2 ^ (pageBitsForSize sz - pageBits)]))\n            hrs)\"\n  apply (simp add: foldl_conv_fold hrs_mem_update_fold_eq)\n  apply (rule conjunct1)\n  apply (rule fold_invariant[where P=\"\\<lambda>hrs'. zero_ranges_are_zero rngs hrs'\n          \\<and> hrs_htd hrs' = hrs_htd hrs\"\n      and xs=xs and Q=\"\\<lambda>x. x \\<in> set xs\" for xs], simp_all)\n  apply (subst zero_ranges_are_zero_update, simp_all)\n  apply clarsimp\n  done\n\ndeclare replicate_numeral [simp]\n\nlemma coerce_memset_to_heap_update_pte:\n  \"heap_update_list x (replicateHider 4 0)\n      = heap_update (Ptr x :: pte_C ptr)\n             (pte_C.pte_C (FCP (\\<lambda>x. 0)))\"\n  apply (intro ext, simp add: heap_update_def)\n  apply (rule_tac f=\"\\<lambda>xs. heap_update_list x xs a b\" for a b in arg_cong)\n  apply (simp add: to_bytes_def size_of_def typ_info_simps pte_C_tag_def)\n  apply (simp add: ti_typ_pad_combine_empty_ti ti_typ_pad_combine_td align_of_def padup_def\n                   final_pad_def size_td_lt_ti_typ_pad_combine Let_def size_of_def)\n  apply (simp add: typ_info_simps align_td_array' size_td_array)\n  apply (simp add: typ_info_array' typ_info_word word_rsplit_0)\n  apply (simp add: replicateHider_def)\n  done\n\nlemma objBits_eq_by_type:\n  fixes x :: \"'a :: pspace_storable\" and y :: 'a\n  shows \"objBits x = objBits y\"\n  apply (simp add: objBits_def)\n  apply (rule objBits_type)\n  apply (simp add: koTypeOf_injectKO)\n  done\n\nlemma mapM_x_store_memset_ccorres_assist:\n  fixes val :: \"'a :: pspace_storable\"\n  assumes nofail: \"\\<not> snd (mapM_x (\\<lambda>slot. setObject slot val) slots \\<sigma>)\"\n  assumes slots1: \"\\<forall>n < length slots. slots ! n = hd slots + (of_nat n << objBits val)\"\n  assumes slots2: \"n = length slots * (2 ^ objBits val)\"\n  assumes ptr: \"ptr = hd slots\"\n  assumes ko: \"\\<And>ko :: 'a. updateObject ko = updateObject_default ko\"\n              \"\\<And>ko :: 'a. (1 :: word32) < 2 ^ objBits ko\"\n  assumes restr: \"set slots \\<subseteq> S\"\n  assumes worker: \"\\<And>ptr s s' (ko :: 'a). \\<lbrakk> (s, s') \\<in> rf_sr; ko_at' ko ptr s; ptr \\<in> S \\<rbrakk>\n                                \\<Longrightarrow> (s \\<lparr> ksPSpace := ksPSpace s (ptr \\<mapsto> injectKO val)\\<rparr>,\n                                     globals_update (t_hrs_'_update (hrs_mem_update\n                                                    (heap_update_list ptr\n                                                    (replicateHider (2 ^ objBits val) (ucast c))))) s') \\<in> rf_sr\"\n  assumes rf_sr: \"(\\<sigma>, s) \\<in> rf_sr\"\n  shows\n  \"\\<exists>(rv, \\<sigma>') \\<in> fst (mapM_x (\\<lambda>slot. setObject slot val) slots \\<sigma>).\n      (\\<sigma>', globals_update (t_hrs_'_update (hrs_mem_update\n                          (heap_update_list ptr (replicateHider n c)))) s) \\<in> rf_sr\"\n  unfolding slots2 ptr using rf_sr slots1 nofail restr\nproof (induct slots arbitrary: s \\<sigma>)\n  case Nil\n  show ?case\n    using Nil.prems\n    apply (simp add: mapM_x_def sequence_x_def return_def replicateHider_def)\n    apply (simp add: rf_sr_def hrs_mem_update_def cstate_relation_def Let_def\n                     carch_state_relation_def cmachine_state_relation_def\n                     h_t_valid_clift_Some_iff)\n    done\nnext\n  case (Cons x xs tPre sPre)\n\n  note nofail_bind = Cons.prems(3)[unfolded mapM_x_Cons K_bind_def]\n\n  have obj_at: \"obj_at' (\\<lambda>x :: 'a. True) x sPre\"\n    using not_snd_bindI1[OF nofail_bind]\n    apply (subst(asm) setObject_obj_at_pre, simp_all add: ko snd_bind)\n    apply (clarsimp simp: stateAssert_def exec_get return_def)\n    apply (simp add: koTypeOf_injectKO typ_at_to_obj_at')\n    done\n\n  note in_setObject = setObject_eq[OF _ _ objBits_eq_by_type obj_at,\n                                   where ko=val, simplified ko, simplified]\n\n  note nofail_mapM = not_snd_bindI2[OF nofail_bind, OF in_setObject]\n\n  have hd_xs: \"xs \\<noteq> [] \\<Longrightarrow> hd xs = x + (2 ^ objBits val)\"\n    using Cons.prems(2)[rule_format, where n=1]\n    by (simp add: hd_conv_nth)\n\n  show ?case\n    using obj_at_ko_at'[OF obj_at] Cons.prems(4)\n    apply (clarsimp simp add: mapM_x_Cons bind_def split_def)\n    apply (rule rev_bexI, rule in_setObject)\n    apply (cut_tac Cons.hyps[OF _ _ nofail_mapM])\n       defer\n       apply (rule worker, rule Cons.prems, assumption+)\n      apply clarsimp\n      apply (case_tac \"xs = []\", simp_all)[1]\n      apply (insert Cons.prems, simp)[1]\n      apply (frule_tac x=\"Suc n\" in spec)\n      apply (simp add: hd_xs shiftl_t2n field_simps)\n     apply assumption\n    apply clarsimp\n    apply (rule rev_bexI, assumption)\n    apply (simp add: o_def)\n    apply (case_tac \"xs = []\")\n     apply (simp add: hrs_mem_update_def split_def replicateHider_def)\n    apply (subst(asm) heap_update_list_concat_fold_hrs_mem)\n     apply (simp add: hd_xs replicateHider_def)\n    apply (simp add: replicateHider_def replicate_add)\n    done\nqed\n\nlemma invalidateTLBByASID_ccorres:\n  \"ccorres dc xfdc (valid_pde_mappings' and (\\<lambda>_. asid \\<le> mask asid_bits))\n                   (UNIV \\<inter> {s. asid_' s = asid}) []\n       (invalidateTLBByASID asid) (Call invalidateTLBByASID_'proc)\"\n  apply (cinit lift: asid_')\n   apply (ctac(no_vcg) add: loadHWASID_ccorres)\n    apply csymbr\n    apply (simp add: case_option_If2 del: Collect_const)\n    apply (rule ccorres_if_cond_throws2[where Q=\\<top> and Q'=\\<top>])\n       apply (clarsimp simp: pde_stored_asid_def to_bool_def split: if_split)\n      apply (rule ccorres_return_void_C[unfolded dc_def])\n     apply (simp add: dc_def[symmetric])\n     apply csymbr\n     apply (ctac add: invalidateTranslationASID_ccorres)\n    apply vcg\n   apply (wp hoare_drop_imps)\n  apply (clarsimp simp: pde_stored_asid_def to_bool_def)\n  done\n\nend\n\nlemma option_to_0_user_mem':\n  \"option_to_0 \\<circ> user_mem' as =(\\<lambda>x. if x \\<in> {y. \\<not> pointerInUserData y as} then 0\n  else underlying_memory (ksMachineState as) x) \"\n  apply (rule ext)\n  apply (simp add:user_mem'_def option_to_0_def split:if_splits)\n  done\n\nlemma heap_to_user_data_in_user_mem'[simp]:\n  \"\\<lbrakk>pspace_aligned' as;pspace_distinct' as\\<rbrakk> \\<Longrightarrow> heap_to_user_data (ksPSpace as) (option_to_0 \\<circ> user_mem' as) =\n  heap_to_user_data (ksPSpace as)(underlying_memory (ksMachineState as))\"\n  apply (rule ext)+\n  apply (clarsimp simp: heap_to_user_data_def option_map_def\n                 split: option.splits)\n  apply (subst option_to_0_user_mem')\n  apply (subst map_option_byte_to_word_heap)\n   apply (clarsimp simp: projectKO_opt_user_data map_comp_def\n                  split: option.split_asm kernel_object.split_asm)\n   apply (frule(1) pspace_alignedD')\n   apply (frule(1) pspace_distinctD')\n   apply (subgoal_tac \"x + ucast off * 4 + xa  && ~~ mask pageBits = x\" )\n    apply (clarsimp simp: pointerInUserData_def typ_at'_def ko_wp_at'_def)\n   apply (simp add: ARM.pageBits_def)\n   apply (subst mask_lower_twice2[where n = 2 and m = 12,simplified,symmetric])\n   apply (subst is_aligned_add_helper[THEN conjunct2,where n1 = 2])\n     apply (erule aligned_add_aligned)\n      apply (simp add: is_aligned_mult_triv2[where n = 2,simplified])\n     apply  (clarsimp simp: objBits_simps ARM.pageBits_def)\n    apply simp\n   apply (rule is_aligned_add_helper[THEN conjunct2])\n    apply (simp add: ARM.pageBits_def objBits_simps)\n   apply (rule word_less_power_trans2[where k = 2,simplified])\n     apply (rule less_le_trans[OF ucast_less])\n      apply simp+\n  done\n\ncontext begin interpretation Arch . (*FIXME: arch_split*)\n\ncrunch pde_mappings'[wp]: invalidateTLBByASID \"valid_pde_mappings'\"\ncrunch ksArchState[wp]: invalidateTLBByASID \"\\<lambda>s. P (ksArchState s)\"\n\ncrunch gsMaxObjectSize[wp]: invalidateTLBByASID \"\\<lambda>s. P (gsMaxObjectSize s)\"\ncrunch gsMaxObjectSize[wp]: deleteASIDPool \"\\<lambda>s. P (gsMaxObjectSize s)\"\n  (wp: crunch_wps getObject_inv loadObject_default_inv\n   simp: crunch_simps)\nend\n\ncontext kernel_m begin\n\nlemma page_table_at_rf_sr_dom_s:\n  \"\\<lbrakk> page_table_at' x s; (s, s') \\<in> rf_sr \\<rbrakk>\n    \\<Longrightarrow> {x ..+ 2 ^ ptBits} \\<times> {SIndexVal, SIndexTyp 0}\n    \\<subseteq> dom_s (hrs_htd (t_hrs_' (globals s')))\"\n  apply (rule_tac m=2 in intvl_2_power_times_decomp,\n         simp_all add: shiftl_t2n field_simps ptBits_def pageBits_def\n                       word_bits_def pteBits_def)\n  apply (clarsimp simp: page_table_at'_def intvl_def)\n  apply (drule spec, drule(1) mp)\n  apply (simp add: typ_at_to_obj_at_arches)\n  apply (drule obj_at_ko_at', clarsimp)\n  apply (erule cmap_relationE1[OF rf_sr_cpte_relation])\n   apply (erule ko_at_projectKO_opt)\n  apply (drule h_t_valid_clift)\n  apply (drule h_t_valid_dom_s[OF _ refl refl])\n  apply (erule subsetD)\n  apply (auto simp add: intvl_def shiftl_t2n)[1]\n  done\n\nlemma clearMemory_setObject_PTE_ccorres:\n  \"ccorres dc xfdc (page_table_at' ptr\n                and (\\<lambda>s. 2 ^ ptBits \\<le> gsMaxObjectSize s)\n                and (\\<lambda>_. is_aligned ptr ptBits \\<and> ptr \\<noteq> 0 \\<and> pstart = addrFromPPtr ptr))\n            (UNIV \\<inter> {s. ptr___ptr_to_unsigned_long_' s = Ptr ptr} \\<inter> {s. bits_' s = of_nat ptBits}) []\n       (do x \\<leftarrow> mapM_x (\\<lambda>a. setObject a ARM_H.InvalidPTE)\n                       [ptr , ptr + 2 ^ pteBits .e. ptr + 2 ^ ptBits - 1];\n           doMachineOp (cleanCacheRange_PoU ptr (ptr + 2 ^ ptBits - 1) pstart)\n        od)\n       (Call clearMemory_'proc)\"\n  apply (rule ccorres_gen_asm)+\n  apply (cinit' lift: ptr___ptr_to_unsigned_long_' bits_')\n   apply (rule ccorres_Guard_Seq)\n   apply (rule ccorres_split_nothrow_novcg_dc)\n      apply (rule_tac P=\"page_table_at' ptr and (\\<lambda>s. 2 ^ ptBits \\<le> gsMaxObjectSize s)\"\n               in ccorres_from_vcg_nofail[where P'=UNIV])\n      apply (rule allI, rule conseqPre, vcg)\n      apply clarsimp\n      apply (subst ghost_assertion_size_logic[unfolded o_def])\n        apply (simp add: ptBits_def pageBits_def pteBits_def)\n       apply simp\n      apply (clarsimp simp: replicateHider_def[symmetric])\n      apply (frule is_aligned_no_overflow')\n      apply (intro conjI)\n          apply (clarsimp simp add: ptBits_def pageBits_def pteBits_def\n                          cong: StateSpace.state.fold_congs globals.fold_congs)\n         apply (erule is_aligned_weaken, simp add: ptBits_def pageBits_def)\n        apply (clarsimp simp: is_aligned_def ptBits_def pageBits_def pteBits_def)\n       apply (simp add: unat_of_nat32 order_less_le_trans[OF pt_bits_stuff(2)]\n                        word_bits_def page_table_at_rf_sr_dom_s)\n      apply (clarsimp simp add: ptBits_def pageBits_def pteBits_def\n                      cong: StateSpace.state.fold_congs globals.fold_congs)\n      apply (simp add: upto_enum_step_def objBits_simps ptBits_def pageBits_def\n                       field_simps linorder_not_less[symmetric] archObjSize_def\n                       upto_enum_word split_def pteBits_def)\n      apply (erule mapM_x_store_memset_ccorres_assist\n                      [unfolded split_def, OF _ _ _ _ _ _ subset_refl],\n             simp_all add: shiftl_t2n hd_map objBits_simps archObjSize_def pteBits_def)[1]\n      apply (rule cmap_relationE1, erule rf_sr_cpte_relation, erule ko_at_projectKO_opt)\n      apply (subst coerce_memset_to_heap_update_pte)\n      apply (clarsimp simp: rf_sr_def Let_def cstate_relation_def typ_heap_simps)\n      apply (rule conjI)\n       apply (simp add: cpspace_relation_def typ_heap_simps update_pte_map_tos\n                        update_pte_map_to_ptes carray_map_relation_upd_triv)\n       apply (rule cmap_relation_updI, simp_all)[1]\n       apply (simp add: cpte_relation_def Let_def pte_lift_def\n                        fcp_beta pte_get_tag_def pte_tag_defs)\n       apply (simp add: carch_state_relation_def cmachine_state_relation_def\n                        typ_heap_simps update_pte_map_tos)\n      apply csymbr\n     apply (rule ccorres_Guard)\n     apply (ctac add: cleanCacheRange_PoU_ccorres)\n    apply (wp mapM_x_wp' setObject_ksPSpace_only updateObject_default_inv | simp)+\n   apply (clarsimp simp: guard_is_UNIV_def ptBits_def pageBits_def pteBits_def)\n  apply (clarsimp simp: ptBits_def pageBits_def pteBits_def)\n  apply (frule is_aligned_addrFromPPtr_n, simp)\n  apply (clarsimp simp: is_aligned_no_overflow'[where n=10, simplified] pageBits_def\n                        field_simps is_aligned_mask[symmetric] mask_AND_less_0)\n  done\n\nlemma modify_gets_helper:\n  \"do y \\<leftarrow> modify (ksPSpace_update (\\<lambda>_. ps)); ps' \\<leftarrow> gets ksPSpace; f ps' od\n      = do y \\<leftarrow> modify (ksPSpace_update (\\<lambda>_. ps)); f ps od\"\n  by (simp add: bind_def simpler_modify_def simpler_gets_def)\n\nlemma snd_lookupAround2_update:\n  \"ps y \\<noteq> None \\<Longrightarrow>\n    snd (lookupAround2 x (ps (y \\<mapsto> v'))) = snd (lookupAround2 x ps)\"\n  apply (clarsimp simp: lookupAround2_def lookupAround_def Let_def\n                        dom_fun_upd2\n              simp del: dom_fun_upd cong: if_cong option.case_cong)\n  apply (clarsimp split: option.split if_split  cong: if_cong)\n  apply auto\n  done\n\nlemma double_setEndpoint:\n  \"do y \\<leftarrow> setEndpoint epptr v1; setEndpoint epptr v2 od\n       = setEndpoint epptr v2\"\n  apply (simp add: setEndpoint_def setObject_def bind_assoc split_def\n                   modify_gets_helper)\n  apply (simp add: updateObject_default_def bind_assoc objBits_simps)\n  apply (rule ext)\n  apply (rule bind_apply_cong, rule refl)+\n  apply (clarsimp simp add: in_monad projectKOs magnitudeCheck_assert\n                            snd_lookupAround2_update)\n  apply (simp add: lookupAround2_known1 assert_opt_def projectKO_def projectKO_opt_ep\n                    alignCheck_assert)\n  apply (simp add: bind_def simpler_modify_def)\n  done\n\nlemma ccorres_inst_voodoo:\n  \"\\<forall>x. ccorres r xf (P x) (P' x) hs (h x) (c x)\n     \\<Longrightarrow> \\<forall>x. ccorres r xf (P x) (P' x) hs (h x) (c x)\"\n  by simp\n\nlemma cpspace_relation_ep_update_ep2:\n  \"\\<lbrakk> ko_at' (ep :: endpoint) epptr s;\n      cmap_relation (map_to_eps (ksPSpace s))\n           (cslift t) ep_Ptr (cendpoint_relation (cslift t));\n      cendpoint_relation (cslift t') ep' endpoint;\n      (cslift t' :: tcb_C ptr \\<rightharpoonup> tcb_C) = cslift t \\<rbrakk>\n     \\<Longrightarrow> cmap_relation (map_to_eps (ksPSpace s(epptr \\<mapsto> KOEndpoint ep')))\n          (cslift t(ep_Ptr epptr \\<mapsto> endpoint))\n          ep_Ptr (cendpoint_relation (cslift t'))\"\n  apply (rule cmap_relationE1, assumption, erule ko_at_projectKO_opt)\n  apply (rule_tac P=\"\\<lambda>a. cmap_relation a b c d\" for b c d in rsubst,\n                   erule cmap_relation_upd_relI, assumption+)\n    apply simp+\n  apply (rule ext, simp add: map_comp_def projectKO_opt_ep split: if_split)\n  done\n\nend\n\ncontext kernel_m begin\n\nlemma ccorres_subst_basic_helper:\n  \"\\<lbrakk> \\<And>s s'. \\<lbrakk> P s; s' \\<in> P'; (s, s') \\<in> rf_sr \\<rbrakk> \\<Longrightarrow> f s' = f' s';\n     \\<And>s s'. \\<lbrakk> P s; s' \\<in> P'; (s, s') \\<in> rf_sr \\<rbrakk> \\<Longrightarrow> (s, f' s') \\<in> rf_sr;\n     \\<And>s'. xf' (f' s') = v; \\<And>rv' t t'. ceqv \\<Gamma> xf' rv' t t' c (c' rv');\n        ccorres rrel xf Q Q' hs a (c' v) \\<rbrakk>\n       \\<Longrightarrow> ccorres rrel xf (P and Q) {s. s \\<in> P' \\<and> f' s \\<in> Q'} hs a (Basic f ;; c)\"\n  apply (rule ccorres_guard_imp2)\n   apply (rule ccorres_add_return)\n   apply (rule ccorres_split_nothrow[where xf'=xf' and r'=\"\\<lambda>rv rv'. rv' = v\"])\n       apply (rule ccorres_from_vcg[where P=P and P'=P'])\n       apply (rule allI, rule conseqPre, vcg)\n       apply (clarsimp simp: return_def)\n      apply assumption\n     apply simp\n    apply wp\n   apply vcg\n  apply clarsimp\n  done\n\nlemma ctcb_relation_blocking_ipc_badge:\n  \"\\<lbrakk> ctcb_relation tcb ctcb; isBlockedOnSend (tcbState tcb) \\<rbrakk> \\<Longrightarrow>\n      tsType_CL (thread_state_lift (tcbState_C ctcb)) = scast ThreadState_BlockedOnSend\"\n  \"\\<lbrakk> ctcb_relation tcb ctcb;\n        tsType_CL (thread_state_lift (tcbState_C ctcb)) = scast ThreadState_BlockedOnSend \\<rbrakk>\n      \\<Longrightarrow> blockingIPCBadge (tcbState tcb)\n             = blockingIPCBadge_CL (thread_state_lift (tcbState_C ctcb))\"\n   apply (clarsimp simp add: ctcb_relation_def)\n   apply (simp add: isBlockedOnSend_def split: Structures_H.thread_state.split_asm)\n   apply (clarsimp simp: cthread_state_relation_def)\n  apply (clarsimp simp add: ctcb_relation_def cthread_state_relation_def)\n  apply (cases \"tcbState tcb\", simp_all add: \"StrictC'_thread_state_defs\")\n  done\n\nlemma cendpoint_relation_q_cong:\n  \"\\<lbrakk> \\<And>t rf. (t, rf) \\<in> ep_q_refs_of' ep \\<Longrightarrow> hp (tcb_ptr_to_ctcb_ptr t) = hp' (tcb_ptr_to_ctcb_ptr t) \\<rbrakk>\n      \\<Longrightarrow> cendpoint_relation hp ep ep' = cendpoint_relation hp' ep ep'\"\n  apply (cases ep, simp_all add: cendpoint_relation_def Let_def)\n   apply (rule conj_cong [OF refl])\n   apply (rule tcb_queue_relation'_cong[OF refl refl refl])\n   apply clarsimp\n  apply (rule conj_cong [OF refl])\n  apply (rule tcb_queue_relation'_cong[OF refl refl refl])\n  apply clarsimp\n  done\n\nlemma cnotification_relation_q_cong:\n  \"\\<lbrakk>\\<And>t rf. (t, rf) \\<in> ntfn_q_refs_of' (ntfnObj ntfn) \\<Longrightarrow>  hp (tcb_ptr_to_ctcb_ptr t) = hp' (tcb_ptr_to_ctcb_ptr t)\\<rbrakk>\n      \\<Longrightarrow>  cnotification_relation hp ntfn ntfn' = cnotification_relation hp' ntfn ntfn'\"\n  apply (cases \"ntfnObj ntfn\", simp_all add: cnotification_relation_def Let_def)\n  apply (auto intro: iffD1[OF tcb_queue_relation'_cong[OF refl refl refl]])\n  done\n\nlemma tcbSchedEnqueue_ep_at:\n  \"\\<lbrace>obj_at' (P :: endpoint \\<Rightarrow> bool) ep\\<rbrace>\n      tcbSchedEnqueue t\n   \\<lbrace>\\<lambda>rv. obj_at' P ep\\<rbrace>\"\n  including no_pre\n  apply (simp add: tcbSchedEnqueue_def unless_def null_def)\n  apply (wp threadGet_wp, clarsimp, wp+)\n  apply (clarsimp split: if_split, wp)\n  done\n\nlemma ccorres_duplicate_guard:\n  \"ccorres r xf (P and P) Q hs f f' \\<Longrightarrow> ccorres r xf P Q hs f f'\"\n  by (erule ccorres_guard_imp, auto)\n\n\nlemma ep_q_refs'_no_NTFNBound[simp]:\n  \"(x, NTFNBound) \\<notin> ep_q_refs_of' ep\"\n  by (auto simp: ep_q_refs_of'_def split: endpoint.splits)\n\n\nlemma ntfn_q_refs'_no_NTFNBound[simp]:\n  \"(x, NTFNBound) \\<notin> ntfn_q_refs_of' ntfn\"\n  by (auto simp: ntfn_q_refs_of'_def split: ntfn.splits)\n\nlemma cancelBadgedSends_ccorres:\n  \"ccorres dc xfdc (invs' and ep_at' ptr)\n              (UNIV \\<inter> {s. epptr_' s = Ptr ptr} \\<inter> {s. badge_' s = bdg}) []\n       (cancelBadgedSends ptr bdg) (Call cancelBadgedSends_'proc)\"\n  apply (cinit lift: epptr_' badge_' simp: whileAnno_def)\n   apply (simp add: list_case_return2\n              cong: list.case_cong Structures_H.endpoint.case_cong call_ignore_cong\n               del: Collect_const)\n   apply (rule ccorres_pre_getEndpoint)\n   apply (rule_tac R=\"ko_at' rv ptr\" and xf'=\"ret__unsigned_'\"\n               and val=\"case rv of RecvEP q \\<Rightarrow> scast EPState_Recv | IdleEP \\<Rightarrow> scast EPState_Idle\n                                | SendEP q \\<Rightarrow> scast EPState_Send\"\n               in ccorres_symb_exec_r_known_rv_UNIV[where R'=UNIV])\n      apply vcg\n      apply clarsimp\n      apply (erule cmap_relationE1 [OF cmap_relation_ep], erule ko_at_projectKO_opt)\n      apply (clarsimp simp: typ_heap_simps cendpoint_relation_def Let_def\n                     split: Structures_H.endpoint.split_asm)\n     apply ceqv\n    apply wpc\n      apply (simp add: dc_def[symmetric] ccorres_cond_iffs)\n      apply (rule ccorres_return_Skip)\n     apply (simp add: dc_def[symmetric] ccorres_cond_iffs)\n     apply (rule ccorres_return_Skip)\n    apply (rename_tac list)\n    apply (simp add: Collect_True Collect_False endpoint_state_defs\n                     ccorres_cond_iffs dc_def[symmetric]\n                del: Collect_const cong: call_ignore_cong)\n    apply (rule ccorres_rhs_assoc)+\n    apply (csymbr, csymbr)\n    apply (drule_tac s = rv in sym, simp only:)\n    apply (rule_tac P=\"ko_at' rv ptr and invs'\" in ccorres_cross_over_guard)\n    apply (rule ccorres_symb_exec_r)\n      apply (rule ccorres_rhs_assoc2, rule ccorres_rhs_assoc2)\n      apply (rule ccorres_split_nothrow[where r'=dc and xf'=xfdc, OF _ ceqv_refl])\n         apply (rule_tac P=\"ko_at' rv ptr\"\n                    in ccorres_from_vcg[where P'=UNIV])\n         apply (rule allI, rule conseqPre, vcg)\n         apply clarsimp\n         apply (rule cmap_relationE1[OF cmap_relation_ep], assumption)\n          apply (erule ko_at_projectKO_opt)\n         apply (clarsimp simp: typ_heap_simps setEndpoint_def)\n         apply (rule rev_bexI)\n          apply (rule setObject_eq; simp add: objBits_simps')[1]\n         apply (clarsimp simp: rf_sr_def cstate_relation_def\n                               Let_def carch_state_relation_def\n                               cmachine_state_relation_def\n                               )\n         apply (clarsimp simp: cpspace_relation_def\n                               update_ep_map_tos\n                               typ_heap_simps')\n         apply (erule(1) cpspace_relation_ep_update_ep2)\n          apply (simp add: cendpoint_relation_def endpoint_state_defs)\n         subgoal by simp\n        apply (rule ccorres_symb_exec_r)\n          apply (rule_tac xs=list in filterM_voodoo)\n          apply (rule_tac P=\"\\<lambda>xs s. (\\<forall>x \\<in> set xs \\<union> set list.\n                   st_tcb_at' (\\<lambda>st. isBlockedOnSend st \\<and> blockingObject st = ptr) x s)\n                              \\<and> distinct (xs @ list) \\<and> ko_at' IdleEP ptr s\n                              \\<and> (\\<forall>p. \\<forall>x \\<in> set (xs @ list). \\<forall>rf. (x, rf) \\<notin> {r \\<in> state_refs_of' s p. snd r \\<noteq> NTFNBound})\n                              \\<and> valid_queues s \\<and> pspace_aligned' s \\<and> pspace_distinct' s\n                              \\<and> sch_act_wf (ksSchedulerAction s) s \\<and> valid_objs' s\"\n                     and P'=\"\\<lambda>xs. {s. ep_queue_relation' (cslift s) (xs @ list)\n                                         (head_C (queue_' s)) (end_C (queue_' s))}\n                                \\<inter> {s. thread_' s = (case list of [] \\<Rightarrow> tcb_Ptr 0\n                                                       | x # xs \\<Rightarrow> tcb_ptr_to_ctcb_ptr x)}\"\n                      in ccorres_inst_voodoo)\n          apply (induct_tac list)\n           apply (rule allI)\n           apply (rule iffD1 [OF ccorres_expand_while_iff_Seq])\n           apply (rule ccorres_tmp_lift2 [OF _ _ refl])\n            apply ceqv\n           apply (simp add: ccorres_cond_iffs)\n           apply (rule ccorres_rhs_assoc2)\n           apply (rule ccorres_duplicate_guard, rule ccorres_split_nothrow_novcg_dc)\n              apply (rule ccorres_from_vcg, rule allI, rule conseqPre, vcg)\n              apply clarsimp\n              apply (drule obj_at_ko_at', clarsimp)\n              apply (rule cmap_relationE1[OF cmap_relation_ep], assumption)\n               apply (erule ko_at_projectKO_opt)\n              apply (clarsimp simp: typ_heap_simps tcb_queue_relation'_def)\n              apply (case_tac x)\n               apply (clarsimp simp: setEndpoint_def)\n               apply (rule rev_bexI, rule setObject_eq,\n                      (simp add: objBits_simps')+)\n               apply (clarsimp simp: rf_sr_def cstate_relation_def Let_def\n                 carch_state_relation_def\n                 cmachine_state_relation_def\n                 cpspace_relation_def typ_heap_simps'\n                 update_ep_map_tos)\n               apply (erule(1) cpspace_relation_ep_update_ep2)\n                subgoal by (simp add: cendpoint_relation_def Let_def)\n               subgoal by simp\n              apply (clarsimp simp: tcb_at_not_NULL[OF pred_tcb_at']\n                                    setEndpoint_def)\n              apply (rule rev_bexI, rule setObject_eq,\n                      (simp add: objBits_simps')+)\n              apply (clarsimp simp: rf_sr_def cstate_relation_def Let_def\n                                     carch_state_relation_def\n                                     cmachine_state_relation_def\n                                     cpspace_relation_def typ_heap_simps'\n                                     update_ep_map_tos)\n              apply (erule(1) cpspace_relation_ep_update_ep2)\n               apply (simp add: cendpoint_relation_def Let_def)\n               apply (subgoal_tac \"tcb_at' (last (a # list)) \\<sigma> \\<and> tcb_at' a \\<sigma>\")\n                apply (clarsimp simp: is_aligned_neg_mask_weaken[\n                                        OF is_aligned_tcb_ptr_to_ctcb_ptr[where P=\\<top>]])\n                subgoal by (simp add: tcb_queue_relation'_def EPState_Send_def mask_def)\n               subgoal by (auto split: if_split)\n              subgoal by simp\n             apply (ctac add: rescheduleRequired_ccorres[unfolded dc_def])\n            apply (rule hoare_pre, wp weak_sch_act_wf_lift_linear set_ep_valid_objs')\n            apply (clarsimp simp: weak_sch_act_wf_def sch_act_wf_def)\n            apply (fastforce simp: valid_ep'_def pred_tcb_at' split: list.splits)\n           apply (simp add: guard_is_UNIV_def)\n          apply (rule allI)\n          apply (rename_tac a lista x)\n          apply (rule iffD1 [OF ccorres_expand_while_iff_Seq])\n          apply (rule ccorres_init_tmp_lift2, ceqv)\n          apply (rule ccorres_guard_imp2)\n           apply (simp add: bind_assoc dc_def[symmetric]\n                       del: Collect_const)\n           apply (rule ccorres_cond_true)\n           apply (rule ccorres_rhs_assoc)+\n           apply (rule ccorres_pre_threadGet[where f=tcbState, folded getThreadState_def])\n           apply (rule ccorres_move_c_guard_tcb)\n           apply csymbr\n           apply (rule ccorres_abstract_cleanup)\n           apply csymbr\n           apply (rule ccorres_move_c_guard_tcb)\n           apply (rule_tac P=\\<top>\n                      and P'=\"{s. ep_queue_relation' (cslift s) (x @ a # lista)\n                                        (head_C (queue_' s)) (end_C (queue_' s))}\"\n                      and f'=\"\\<lambda>s. s \\<lparr> next___ptr_to_struct_tcb_C_' := (case lista of [] \\<Rightarrow> tcb_Ptr 0\n                                              | v # vs \\<Rightarrow> tcb_ptr_to_ctcb_ptr v) \\<rparr>\"\n                      and xf'=\"next___ptr_to_struct_tcb_C_'\"\n                           in ccorres_subst_basic_helper)\n               apply (thin_tac \"\\<forall>x. P x\" for P)\n               apply (rule myvars.fold_congs, (rule refl)+)\n               apply (clarsimp simp: tcb_queue_relation'_def use_tcb_queue_relation2\n                                     tcb_queue_relation2_concat)\n               apply (clarsimp simp: typ_heap_simps split: list.split)\n              subgoal by (simp add: rf_sr_def)\n             apply simp\n            apply ceqv\n           apply (rule_tac P=\"ret__unsigned=blockingIPCBadge rva\" in ccorres_gen_asm2)\n           apply (rule ccorres_if_bind, rule ccorres_if_lhs)\n            apply (simp add: bind_assoc dc_def[symmetric])\n            apply (rule ccorres_rhs_assoc)+\n            apply (ctac add: setThreadState_ccorres)\n              apply (ctac add: tcbSchedEnqueue_ccorres)\n                apply (rule_tac P=\"\\<lambda>s. \\<forall>t \\<in> set (x @ a # lista). tcb_at' t s\"\n                             in ccorres_cross_over_guard)\n                apply (rule ccorres_add_return, rule ccorres_split_nothrow[OF _ ceqv_refl])\n                   apply (rule_tac rrel=dc and xf=xfdc\n                               and P=\"\\<lambda>s. (\\<forall>t \\<in> set (x @ a # lista). tcb_at' t s)\n                                          \\<and> (\\<forall>p. \\<forall>t \\<in> set (x @ a # lista). \\<forall>rf. (t, rf) \\<notin> {r \\<in> state_refs_of' s p. snd r \\<noteq> NTFNBound})\n                                          \\<and> valid_queues s \\<and> distinct (x @ a # lista)\n                                          \\<and> pspace_aligned' s \\<and> pspace_distinct' s\"\n                              and P'=\"{s. ep_queue_relation' (cslift s) (x @ a # lista)\n                                           (head_C (queue_' s)) (end_C (queue_' s))}\"\n                               in ccorres_from_vcg)\n                   apply (thin_tac \"\\<forall>x. P x\" for P)\n                   apply (rule allI, rule conseqPre, vcg)\n                   apply (clarsimp simp: ball_Un)\n                   apply (rule exI, rule conjI)\n                    apply (rule exI, erule conjI)\n                    apply (intro conjI[rotated])\n                    apply (assumption)\n                    apply (fold_subgoals (prefix))[3]\n                    subgoal premises prems using prems by (fastforce intro: pred_tcb_at')+\n                   apply (clarsimp simp: return_def rf_sr_def cstate_relation_def Let_def)\n                   apply (rule conjI)\n                    apply (clarsimp simp: cpspace_relation_def)\n                    apply (rule conjI, erule ctcb_relation_null_queue_ptrs)\n                     apply (rule null_ep_queue)\n                     subgoal by (simp add: o_def)\n                    apply (rule conjI)\n                     apply (erule iffD1 [OF cmap_relation_cong, OF refl refl, rotated -1])\n                     apply clarsimp\n                     apply (rule cendpoint_relation_q_cong)\n                     apply (rule sym, erule restrict_map_eqI)\n                     apply (clarsimp simp: image_iff)\n                     apply (drule(2) map_to_ko_atI2)\n                     apply (drule ko_at_state_refs_ofD')\n                     apply clarsimp\n                     apply (drule_tac x=p in spec)\n                     subgoal by fastforce\n                    apply (erule iffD1 [OF cmap_relation_cong, OF refl refl, rotated -1])\n                    apply clarsimp\n                    apply (drule(2) map_to_ko_atI2, drule ko_at_state_refs_ofD')\n\n                    apply (rule cnotification_relation_q_cong)\n                    apply (rule sym, erule restrict_map_eqI)\n                    apply (clarsimp simp: image_iff)\n                    apply (drule_tac x=p in spec)\n                    subgoal by fastforce\n                   apply (rule conjI)\n                    apply (erule cready_queues_relation_not_queue_ptrs,\n                           auto dest: null_ep_schedD[unfolded o_def] simp: o_def)[1]\n                   apply (simp add: carch_state_relation_def\n                                    cmachine_state_relation_def\n                                    h_t_valid_clift_Some_iff)\n                  apply (rule ccorres_symb_exec_r2)\n                    apply (erule spec)\n                   apply vcg\n                  apply (vcg spec=modifies)\n                 apply wp\n                apply simp\n                apply vcg\n               apply (wp hoare_vcg_const_Ball_lift tcbSchedEnqueue_ep_at\n                         sch_act_wf_lift)\n              apply simp\n              apply (vcg exspec=tcbSchedEnqueue_cslift_spec)\n             apply (wp hoare_vcg_const_Ball_lift sts_st_tcb_at'_cases\n                       sts_sch_act sts_valid_queues setThreadState_oa_queued)\n            apply (vcg exspec=setThreadState_cslift_spec)\n           apply (simp add: ccorres_cond_iffs dc_def[symmetric])\n           apply (rule ccorres_symb_exec_r2)\n             apply (drule_tac x=\"x @ [a]\" in spec, simp add: dc_def[symmetric])\n            apply vcg\n           apply (vcg spec=modifies)\n          apply (thin_tac \"\\<forall>x. P x\" for P)\n          apply (clarsimp simp: pred_tcb_at' ball_Un)\n          apply (rule conjI)\n           apply (clarsimp split: if_split)\n           subgoal by (fastforce simp: valid_tcb_state'_def valid_objs'_maxDomain\n                                  valid_objs'_maxPriority dest: pred_tcb_at')\n          apply (clarsimp simp: tcb_at_not_NULL [OF pred_tcb_at'])\n          apply (clarsimp simp: typ_heap_simps st_tcb_at'_def)\n          apply (drule(1) obj_at_cslift_tcb)\n          apply (clarsimp simp: ctcb_relation_blocking_ipc_badge)\n          apply (rule conjI, simp add: \"StrictC'_thread_state_defs\" mask_def)\n          apply (rule conjI)\n           apply clarsimp\n           apply (frule rf_sr_cscheduler_relation)\n           apply (clarsimp simp: cscheduler_action_relation_def st_tcb_at'_def\n                          split: scheduler_action.split_asm)\n           apply (rename_tac word)\n           apply (frule_tac x=word in tcbSchedEnqueue_cslift_precond_discharge)\n              apply simp\n             subgoal by clarsimp\n            subgoal by clarsimp\n           subgoal by clarsimp\n          apply clarsimp\n          apply (rule conjI)\n           apply (frule(3) tcbSchedEnqueue_cslift_precond_discharge)\n           subgoal by clarsimp\n          apply clarsimp\n          apply (rule context_conjI)\n           apply (clarsimp simp: tcb_queue_relation'_def)\n           apply (erule iffD2[OF ep_queue_relation_shift[rule_format], rotated -1])\n           subgoal by simp\n          apply (rule_tac x=\"x @ a # lista\" in exI)\n          apply (clarsimp simp: ball_Un)\n          apply (rule conjI, fastforce)\n          subgoal by (clarsimp simp: remove1_append)\n         apply vcg\n        apply (rule conseqPre, vcg)\n        apply clarsimp\n       apply (wp hoare_vcg_const_Ball_lift)\n       apply (wp obj_at_setObject3[where 'a=endpoint, folded setEndpoint_def])\n         apply (simp add: objBits_simps')+\n       apply (wp set_ep_valid_objs')\n      apply vcg\n     apply vcg\n    apply (rule conseqPre, vcg)\n    apply clarsimp\n   apply (clarsimp simp: guard_is_UNIV_def)\n   apply (erule cmap_relationE1[OF cmap_relation_ep], erule ko_at_projectKO_opt)\n   apply (clarsimp simp: typ_heap_simps)\n   apply (clarsimp simp: cendpoint_relation_def Let_def)\n   subgoal by (clarsimp simp: tcb_queue_relation'_def neq_Nil_conv\n                  split: if_split_asm)\n  apply clarsimp\n  apply (frule ko_at_valid_objs', clarsimp)\n   apply (simp add: projectKOs)\n  apply (clarsimp simp: valid_obj'_def valid_ep'_def)\n  apply (frule sym_refs_ko_atD', clarsimp)\n  apply (clarsimp simp: st_tcb_at_refs_of_rev')\n  apply (rule conjI)\n   subgoal by (auto simp: isBlockedOnSend_def elim!: pred_tcb'_weakenE)\n  apply (rule conjI)\n   apply (clarsimp split: if_split)\n   apply (drule sym_refsD, clarsimp)\n   apply (drule(1) bspec)+\n   by (auto simp: obj_at'_def projectKOs state_refs_of'_def pred_tcb_at'_def tcb_bound_refs'_def\n              dest!: symreftype_inverse')\n\ndeclare Kernel_C.tcb_C_size [simp del]\n\nlemma cte_lift_ccte_relation:\n  \"cte_lift cte' = Some ctel'\n    \\<Longrightarrow> c_valid_cte cte'\n    \\<Longrightarrow> ccte_relation (cte_to_H ctel') cte'\"\n  by (simp add: ccte_relation_def)\n\nlemma updateFreeIndex_ccorres:\n  \"\\<forall>s. \\<Gamma> \\<turnstile> ({s} \\<inter> {s. \\<exists>cte cte'. cslift s (cte_Ptr srcSlot) = Some cte'\n               \\<and> cteCap cte = cap' \\<and> ccte_relation cte cte'})\n          c\n        {t. \\<exists>cap. cap_untyped_cap_lift cap = (cap_untyped_cap_lift\n                    (cte_C.cap_C (the (cslift s (cte_Ptr srcSlot)))))\n                        \\<lparr> cap_untyped_cap_CL.capFreeIndex_CL := ((of_nat idx') >> 4) \\<rparr>\n                \\<and> cap_get_tag cap = scast cap_untyped_cap\n                \\<and> t_hrs_' (globals t) = hrs_mem_update (heap_update (cte_Ptr srcSlot)\n                    (cte_C.cap_C_update (\\<lambda>_. cap) (the (cslift s (cte_Ptr srcSlot)))))\n                    (t_hrs_' (globals s))\n                \\<and> t may_only_modify_globals s in [t_hrs]\n        }\n    \\<Longrightarrow> ccorres dc xfdc\n           (valid_objs' and cte_wp_at' (\\<lambda>cte. isUntypedCap (cteCap cte)\n               \\<and> cap' = (cteCap cte)) srcSlot\n           and untyped_ranges_zero'\n           and (\\<lambda>_. is_aligned (of_nat idx' :: word32) 4 \\<and> idx' \\<le> 2 ^ (capBlockSize cap')))\n           {s. \\<not> capIsDevice cap'\n               \\<longrightarrow> region_actually_is_zero_bytes (capPtr cap' + of_nat idx') (capFreeIndex cap' - idx') s} hs\n           (updateFreeIndex srcSlot idx') c\"\n  (is \"_ \\<Longrightarrow> ccorres dc xfdc (valid_objs' and ?cte_wp_at' and _ and _) ?P' hs ?a c\")\n  apply (rule ccorres_gen_asm)\n  apply (simp add: updateFreeIndex_def getSlotCap_def updateCap_def)\n  apply (rule ccorres_guard_imp2)\n   apply (rule ccorres_split_noop_lhs, rule_tac cap'=cap' in updateTrackedFreeIndex_noop_ccorres)\n    apply (rule ccorres_pre_getCTE)+\n    apply (rename_tac cte cte2)\n    apply (rule_tac P = \"\\<lambda>s. ?cte_wp_at' s \\<and> cte2 = cte \\<and> cte_wp_at' ((=) cte) srcSlot s\"\n              and P'=\"{s. \\<exists>cte cte'. cslift s (cte_Ptr srcSlot) = Some cte'\n               \\<and> cteCap cte = cap' \\<and> ccte_relation cte cte'} \\<inter> ?P'\" in ccorres_from_vcg)\n    apply (rule allI, rule HoarePartial.conseq_exploit_pre, clarify)\n    apply (drule_tac x=s in spec, rule conseqPre, erule conseqPost)\n      defer\n      apply clarsimp\n     apply clarsimp\n    apply (simp add: cte_wp_at_ctes_of)\n    apply wp\n   apply (clarsimp simp: isCap_simps cte_wp_at_ctes_of)\n   apply (frule(1) rf_sr_ctes_of_clift)\n   apply clarsimp\n   apply (frule(1) cte_lift_ccte_relation)\n   apply (rule exI, intro conjI[rotated], assumption, simp_all)[1]\n  apply (clarsimp simp: cte_wp_at_ctes_of)\n  apply (erule(1) rf_sr_ctes_of_cliftE)\n  apply (frule(1) rf_sr_ctes_of_clift)\n  apply clarsimp\n  apply (subgoal_tac \"ccap_relation (capFreeIndex_update (\\<lambda>_. idx')\n        (cteCap (the (ctes_of \\<sigma> srcSlot)))) cap\")\n   apply (rule fst_setCTE [OF ctes_of_cte_at], assumption)\n   apply (erule bexI [rotated])\n   apply (clarsimp simp add: rf_sr_def cstate_relation_def Let_def\n      cvariable_array_map_const_add_map_option[where f=\"tcb_no_ctes_proj\"]\n      isCap_simps)\n   apply (simp add:cpspace_relation_def)\n   apply (clarsimp simp:typ_heap_simps' modify_map_def mex_def meq_def)\n   apply (rule conjI)\n    apply (rule cpspace_cte_relation_upd_capI, assumption+)\n   apply (rule conjI)\n    apply (rule setCTE_tcb_case, assumption+)\n   apply (case_tac s', clarsimp)\n   subgoal by (simp add: carch_state_relation_def cmachine_state_relation_def\n                   typ_heap_simps')\n\n  apply (clarsimp simp: isCap_simps)\n  apply (drule(1) cte_lift_ccte_relation,\n    drule ccte_relation_ccap_relation)\n  apply (simp add: cte_to_H_def)\n  apply (frule cap_get_tag_isCap_unfolded_H_cap)\n  apply (clarsimp simp: ccap_relation_def cap_lift_untyped_cap\n                        cap_to_H_simps cap_untyped_cap_lift_def\n                        is_aligned_shiftr_shiftl\n                 dest!: ccte_relation_ccap_relation)\n  apply (rule unat_of_nat_eq unat_of_nat_eq[symmetric],\n    erule order_le_less_trans,\n    rule power_strict_increasing, simp_all)\n  apply (rule unat_less_helper, rule order_le_less_trans[OF word_and_le1], simp add: mask_def)\n  done\n\nend\n\nlemma ccap_relation_isDeviceCap2:\n \"\\<lbrakk>ccap_relation cp cap; isUntypedCap cp\n  \\<rbrakk> \\<Longrightarrow> (capIsDevice_CL (cap_untyped_cap_lift cap) = 0) = (\\<not> (capIsDevice cp))\"\n  apply (frule cap_get_tag_UntypedCap)\n  apply (simp add:cap_get_tag_isCap to_bool_def)\n  done\nend\n", "meta": {"author": "NICTA", "repo": "l4v", "sha": "3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b", "save_path": "github-repos/isabelle/NICTA-l4v", "path": "github-repos/isabelle/NICTA-l4v/l4v-3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b/proof/crefine/ARM/Recycle_C.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6261241772283034, "lm_q2_score": 0.44552953503957277, "lm_q1q2_score": 0.2789568135575611}}
{"text": "theory \"WMF_cert_auto\"\nimports\n  \"../ESPLogic\"\nbegin\n\n(* section:  Wide Mouthed Frog  *)\n\n(* text: \n  The protocol is modeled after the description in the SPORE library:\n\n    http://www.lsv.ens-cachan.fr/Software/spore/wideMouthedFrog.html\n\n  Note that we cannot reason about the timestamps in our current model.\n  Furthermore, our current calculus for backwards reasoning is too weak\n  to reason about the original protocol\n\n    1: I -> S: I, {TimeI, R, kIR}k(I,S)\n    2: R <- S:    {TimeS, I, kIR}k(R,S)\n\n  because the server S could receive the message {TimeI, R, kIR}k(I,S)\n  arbitrarily many times from himself. Therefore, we added global constants\n  identifying the different steps.\n *)\n\nrole I\nwhere \"I =\n  [ Send ''1'' <| sAV ''I'', sAV ''R'',\n                  PEnc <| sC ''step1'', sN ''TimeI'', sAV ''R'', sN ''kIR'' |>\n                       ( sK ''I'' ''S'' )\n               |>\n  ]\"\n\nrole R\nwhere \"R =\n  [ Recv ''2'' <| sMV ''S'', sMV ''I'',\n                  PEnc <| sC ''step2'', sMV ''TimeS'', sMV ''I'', sMV ''kIR'' |>\n                       ( PSymK ( sAV ''R'' ) ( sMV ''S'' ) )\n               |>\n  ]\"\n\nrole S\nwhere \"S =\n  [ Recv ''1'' <| sMV ''I'', sMV ''R'',\n                  PEnc <| sC ''step1'', sMV ''TimeI'', sMV ''R'', sMV ''kIR'' |>\n                       ( PSymK ( sMV ''I'' ) ( sAV ''S'' ) )\n               |>\n  , Send ''2'' <| sAV ''S'', sMV ''I'',\n                  PEnc <| sC ''step2'', sN ''TimeS'', sMV ''I'', sMV ''kIR'' |>\n                       ( PSymK ( sMV ''R'' ) ( sAV ''S'' ) )\n               |>\n  ]\"\n\nprotocol WMF\nwhere \"WMF = { I, R, S }\"\n\nlocale restricted_WMF_state = WMF_state\n\ntype_invariant WMF_msc_typing for WMF\nwhere \"WMF_msc_typing = mk_typing\n  [ ((R, ''I''), (KnownT R_2))\n  , ((S, ''I''), (KnownT S_1))\n  , ((S, ''R''), (KnownT S_1))\n  , ((R, ''S''), (KnownT R_2))\n  , ((S, ''TimeI''), (SumT (KnownT S_1) (NonceT I ''TimeI'')))\n  , ((R, ''TimeS''), (SumT (KnownT R_2) (NonceT S ''TimeS'')))\n  , ((R, ''kIR''), (SumT (KnownT R_2) (NonceT I ''kIR'')))\n  , ((S, ''kIR''), (SumT (KnownT S_1) (NonceT I ''kIR'')))\n  ]\"\n\nsublocale WMF_state < WMF_msc_typing_state\nproof -\n  have \"(t,r,s) : approx WMF_msc_typing\"\n  proof(cases rule: reachable_in_approxI_ext\n        [OF WMF_msc_typing.monoTyp, completeness_cases_rule])\n    case (R_2_I t r s tid0) note facts = this\n    then interpret state: WMF_msc_typing_state t r s\n      by unfold_locales auto\n    show ?case using facts\n    by (fastsimp intro: event_predOrdI split: if_splits)\n  next\n    case (R_2_S t r s tid0) note facts = this\n    then interpret state: WMF_msc_typing_state t r s\n      by unfold_locales auto\n    show ?case using facts\n    by (fastsimp intro: event_predOrdI split: if_splits)\n  next\n    case (R_2_TimeS t r s tid0) note facts = this\n    then interpret state: WMF_msc_typing_state t r s\n      by unfold_locales auto\n    show ?case using facts\n    proof(sources! \"\n        Enc {| LC ''step2'', s(MV ''TimeS'' tid0), s(MV ''I'' tid0),\n               s(MV ''kIR'' tid0)\n            |}\n            ( K ( s(AV ''R'' tid0) ) ( s(MV ''S'' tid0) ) ) \")\n    qed (insert facts, ((fastsimp intro: event_predOrdI split: if_splits))+)?\n  next\n    case (R_2_kIR t r s tid0) note facts = this\n    then interpret state: WMF_msc_typing_state t r s\n      by unfold_locales auto\n    show ?case using facts\n    proof(sources! \"\n        Enc {| LC ''step2'', s(MV ''TimeS'' tid0), s(MV ''I'' tid0),\n               s(MV ''kIR'' tid0)\n            |}\n            ( K ( s(AV ''R'' tid0) ) ( s(MV ''S'' tid0) ) ) \")\n      case (S_2_enc tid1) note_unified facts = this facts\n      thus ?thesis proof(sources! \"\n                       Enc {| LC ''step1'', s(MV ''TimeI'' tid1), s(AV ''R'' tid0),\n                              s(MV ''kIR'' tid0)\n                           |}\n                           ( K ( s(MV ''I'' tid0) ) ( s(AV ''S'' tid1) ) ) \")\n      qed (insert facts, ((fastsimp intro: event_predOrdI split: if_splits))+)?\n    qed (insert facts, ((fastsimp intro: event_predOrdI split: if_splits))+)?\n  next\n    case (S_1_I t r s tid0) note facts = this\n    then interpret state: WMF_msc_typing_state t r s\n      by unfold_locales auto\n    show ?case using facts\n    by (fastsimp intro: event_predOrdI split: if_splits)\n  next\n    case (S_1_R t r s tid0) note facts = this\n    then interpret state: WMF_msc_typing_state t r s\n      by unfold_locales auto\n    show ?case using facts\n    by (fastsimp intro: event_predOrdI split: if_splits)\n  next\n    case (S_1_TimeI t r s tid0) note facts = this\n    then interpret state: WMF_msc_typing_state t r s\n      by unfold_locales auto\n    show ?case using facts\n    proof(sources! \"\n        Enc {| LC ''step1'', s(MV ''TimeI'' tid0), s(MV ''R'' tid0),\n               s(MV ''kIR'' tid0)\n            |}\n            ( K ( s(MV ''I'' tid0) ) ( s(AV ''S'' tid0) ) ) \")\n    qed (insert facts, ((fastsimp intro: event_predOrdI split: if_splits))+)?\n  next\n    case (S_1_kIR t r s tid0) note facts = this\n    then interpret state: WMF_msc_typing_state t r s\n      by unfold_locales auto\n    show ?case using facts\n    proof(sources! \"\n        Enc {| LC ''step1'', s(MV ''TimeI'' tid0), s(MV ''R'' tid0),\n               s(MV ''kIR'' tid0)\n            |}\n            ( K ( s(MV ''I'' tid0) ) ( s(AV ''S'' tid0) ) ) \")\n    qed (insert facts, ((fastsimp intro: event_predOrdI split: if_splits))+)?\n  qed\n  thus \"WMF_msc_typing_state t r s\" by unfold_locales auto\nqed\n\ntext{* Prove secrecy of long-term keys. *}\ncontext WMF_state begin\n\n  (* This rule is unsafe in general, but OK here, \n     as we are only reasoning about static compromise. \n  *)\n  lemma static_longterm_key_reveal[dest!]:\n    \"predOrd t (LKR a) e ==> RLKR a : reveals t\"\n    by (auto intro: compr_predOrdI)\n\n  lemma longterm_private_key_secrecy:\n    assumes facts:\n      \"SK m : knows t\"\n      \"RLKR m ~: reveals t\"\n    shows \"False\"\n  using facts by (sources \"SK m\")\n\n  lemma longterm_sym_ud_key_secrecy:\n    assumes facts:\n      \"K m1 m2 : knows t\"\n      \"RLKR m1 ~: reveals t\"\n      \"RLKR m2 ~: reveals t\"\n    shows \"False\"\n  using facts by (sources \"K m1 m2\")\n\n  lemma longterm_sym_bd_key_secrecy:\n    assumes facts:\n      \"Kbd m1 m2 : knows t\"\n      \"RLKR m1 ~: reveals t\"\n      \"RLKR m2 ~: reveals t\"\n      \"m1 : Agent\"\n      \"m2 : Agent\"\n    shows \"False\"\n  proof -\n    from facts \n    have \"KShr (agents {m1, m2}) : knows t\"\n      by (auto simp: Kbd_def)\n    thus ?thesis using facts\n    proof (sources \"KShr (agents {m1, m2})\")\n    qed (auto simp: agents_def Agent_def)\n  qed\n\n  lemmas ltk_secrecy =\n    longterm_sym_ud_key_secrecy\n    longterm_sym_ud_key_secrecy[OF in_knows_predOrd1]\n    longterm_sym_bd_key_secrecy\n    longterm_sym_bd_key_secrecy[OF in_knows_predOrd1]\n    longterm_private_key_secrecy\n    longterm_private_key_secrecy[OF in_knows_predOrd1]\n\nend\n\n(* subsection:  Secrecy Properties  *)\n\nlemma (in restricted_WMF_state) I_kIR_sec:\n  assumes facts:\n    \"roleMap r tid0 = Some I\"\n    \"RLKR(s(AV ''I'' tid0)) ~: reveals t\"\n    \"RLKR(s(AV ''R'' tid0)) ~: reveals t\"\n    \"RLKR(s(AV ''S'' tid0)) ~: reveals t\"\n    \"LN ''kIR'' tid0 : knows t\"\n  shows \"False\"\nusing facts proof(sources! \" LN ''kIR'' tid0 \")\n  case I_1_kIR note_unified facts = this facts\n  thus ?thesis by (fastsimp dest!: ltk_secrecy)\nnext\n  case (S_2_kIR tid1) note_unified facts = this facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''step1'', s(MV ''TimeI'' tid1), s(MV ''R'' tid1),\n                          LN ''kIR'' tid0\n                       |}\n                       ( K ( s(MV ''I'' tid1) ) ( s(AV ''S'' tid1) ) ) \")\n    case (I_1_enc tid2) note_unified facts = this facts\n    thus ?thesis by (fastsimp dest!: ltk_secrecy)\n  qed (insert facts, (((clarsimp, order?) | order))+)?\nqed (insert facts, fastsimp+)?\n\nlemma (in restricted_WMF_state) S_kIR_sec:\n  assumes facts:\n    \"roleMap r tid0 = Some S\"\n    \"RLKR(s(AV ''S'' tid0)) ~: reveals t\"\n    \"RLKR(s(MV ''I'' tid0)) ~: reveals t\"\n    \"RLKR(s(MV ''R'' tid0)) ~: reveals t\"\n    \"( tid0, S_1 ) : steps t\"\n    \"s(MV ''kIR'' tid0) : knows t\"\n  shows \"False\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''step1'', s(MV ''TimeI'' tid0), s(MV ''R'' tid0),\n                          s(MV ''kIR'' tid0)\n                       |}\n                       ( K ( s(MV ''I'' tid0) ) ( s(AV ''S'' tid0) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (fastsimp dest!: ltk_secrecy)\n  next\n    case (I_1_enc tid1) note_unified facts = this facts\n    thus ?thesis by (fastsimp dest: I_kIR_sec intro: event_predOrdI)\n  qed (insert facts, fastsimp+)?\nqed\n\nlemma (in restricted_WMF_state) R_kIR_sec:\n  assumes facts:\n    \"roleMap r tid0 = Some R\"\n    \"RLKR(s(AV ''R'' tid0)) ~: reveals t\"\n    \"RLKR(s(MV ''I'' tid0)) ~: reveals t\"\n    \"RLKR(s(MV ''S'' tid0)) ~: reveals t\"\n    \"( tid0, R_2 ) : steps t\"\n    \"s(MV ''kIR'' tid0) : knows t\"\n  shows \"False\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''step2'', s(MV ''TimeS'' tid0), s(MV ''I'' tid0),\n                          s(MV ''kIR'' tid0)\n                       |}\n                       ( K ( s(AV ''R'' tid0) ) ( s(MV ''S'' tid0) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (fastsimp dest!: ltk_secrecy)\n  next\n    case (S_2_enc tid1) note_unified facts = this facts\n    thus ?thesis by (fastsimp dest: S_kIR_sec intro: event_predOrdI)\n  qed (insert facts, fastsimp+)?\nqed\n\n(* subsection:  Authentication Properties  *)\n\n(* text: \n  The authentication guarantee for the initiator is trivial because it does not\n  receive any confirmation that the responder received the new session-key.\n *)\n\nlemma (in restricted_WMF_state) S_ni_synch:\n  assumes facts:\n    \"roleMap r tid3 = Some S\"\n    \"RLKR(s(AV ''S'' tid3)) ~: reveals t\"\n    \"RLKR(s(MV ''I'' tid3)) ~: reveals t\"\n    \"( tid3, S_1 ) : steps t\"\n  shows\n    \"(?  tid1.\n        roleMap r tid1 = Some I &\n        s(AV ''I'' tid1) = s(MV ''I'' tid3) &\n        s(AV ''R'' tid1) = s(MV ''R'' tid3) &\n        s(AV ''S'' tid1) = s(AV ''S'' tid3) &\n        LN ''TimeI'' tid1 = s(MV ''TimeI'' tid3) &\n        LN ''kIR'' tid1 = s(MV ''kIR'' tid3) &\n        predOrd t (St( tid1, I_1 )) (St( tid3, S_1 )))\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''step1'', s(MV ''TimeI'' tid3), s(MV ''R'' tid3),\n                          s(MV ''kIR'' tid3)\n                       |}\n                       ( K ( s(MV ''I'' tid3) ) ( s(AV ''S'' tid3) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (fastsimp dest!: ltk_secrecy)\n  next\n    case (I_1_enc tid4) note_unified facts = this facts\n    thus ?thesis by (fastsimp intro: event_predOrdI split: if_splits)\n  qed (insert facts, fastsimp+)?\nqed\n\nlemma (in restricted_WMF_state) R_ni_synch:\n  assumes facts:\n    \"roleMap r tid2 = Some R\"\n    \"RLKR(s(AV ''R'' tid2)) ~: reveals t\"\n    \"RLKR(s(MV ''I'' tid2)) ~: reveals t\"\n    \"RLKR(s(MV ''S'' tid2)) ~: reveals t\"\n    \"( tid2, R_2 ) : steps t\"\n  shows\n    \"(?  tid1.\n        (?  tid3.\n           roleMap r tid1 = Some I &\n           roleMap r tid3 = Some S &\n           s(AV ''I'' tid1) = s(MV ''I'' tid2) &\n           s(MV ''I'' tid2) = s(MV ''I'' tid3) &\n           s(AV ''R'' tid1) = s(AV ''R'' tid2) &\n           s(AV ''R'' tid2) = s(MV ''R'' tid3) &\n           s(AV ''S'' tid1) = s(MV ''S'' tid2) &\n           s(MV ''S'' tid2) = s(AV ''S'' tid3) &\n           LN ''TimeI'' tid1 = s(MV ''TimeI'' tid3) &\n           s(MV ''TimeS'' tid2) = LN ''TimeS'' tid3 &\n           LN ''kIR'' tid1 = s(MV ''kIR'' tid2) &\n           s(MV ''kIR'' tid2) = s(MV ''kIR'' tid3) &\n           predOrd t (St( tid1, I_1 )) (St( tid3, S_1 )) &\n           predOrd t (St( tid3, S_1 )) (St( tid3, S_2 )) &\n           predOrd t (St( tid3, S_2 )) (St( tid2, R_2 ))))\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''step2'', s(MV ''TimeS'' tid2), s(MV ''I'' tid2),\n                          s(MV ''kIR'' tid2)\n                       |}\n                       ( K ( s(AV ''R'' tid2) ) ( s(MV ''S'' tid2) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (fastsimp dest!: ltk_secrecy)\n  next\n    case (S_2_enc tid3) note_unified facts = this facts\n    thus ?thesis proof(sources! \"\n                     Enc {| LC ''step1'', s(MV ''TimeI'' tid3), s(AV ''R'' tid2),\n                            s(MV ''kIR'' tid2)\n                         |}\n                         ( K ( s(MV ''I'' tid2) ) ( s(AV ''S'' tid3) ) ) \")\n      case fake note_unified facts = this facts\n      thus ?thesis by (fastsimp dest!: ltk_secrecy)\n    next\n      case (I_1_enc tid4) note_unified facts = this facts\n      thus ?thesis by (fastsimp intro: event_predOrdI split: if_splits)\n    qed (insert facts, fastsimp+)?\n  qed (insert facts, fastsimp+)?\nqed\n\nend", "meta": {"author": "meiersi", "repo": "scyther-proof", "sha": "84e42366a46f66f1b090651be3bfaa3497696280", "save_path": "github-repos/isabelle/meiersi-scyther-proof", "path": "github-repos/isabelle/meiersi-scyther-proof/scyther-proof-84e42366a46f66f1b090651be3bfaa3497696280/examples/classic/isabelle-proofs/WMF_cert_auto.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621765155565326, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.2788923004410582}}
{"text": "section {* Correctness of Type Checker *}\n\ntheory Wasm_Checker_Properties imports Wasm_Checker Wasm_Properties begin\n\nsubsection {* Soundness *}\n\nlemma b_e_check_single_type_sound:\n  assumes \"type_update (Type x1) (to_ct_list t_in) (Type t_out) = Type x2\"\n          \"c_types_agree (Type x2) tm\"\n          \"\\<C> \\<turnstile> [e] : (t_in _> t_out)\"\n  shows \"\\<exists>tn. c_types_agree (Type x1) tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\n  using assms(2) b_e_typing.weakening[OF assms(3)] type_update_type[OF assms(1)]\n  by auto\n\nlemma b_e_check_single_top_sound:\n  assumes \"type_update (TopType x1) (to_ct_list t_in) (Type t_out) = TopType x2\"\n          \"c_types_agree (TopType x2) tm\"\n          \"\\<C> \\<turnstile> [e] : (t_in _> t_out)\"\n  shows \"\\<exists>tn. c_types_agree (TopType x1) tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\nproof -\n  obtain t_ag where t_ag_def:\"ct_suffix (to_ct_list t_out) x2\"\n                             \"tm = t_ag @ t_out\"\n                             \"c_types_agree (TopType x1) (t_ag @ t_in)\"\n    using type_update_top_top[OF assms(1,2)]\n    by fastforce\n  hence \"\\<C> \\<turnstile> [e] : (t_ag@t_in _> t_ag@t_out)\"\n    using b_e_typing.weakening[OF assms(3)]\n    by fastforce\n  thus ?thesis\n    using t_ag_def\n    by fastforce\nqed\n\nlemma b_e_check_single_top_not_bot_sound:\n  assumes \"type_update ts (to_ct_list t_in) (TopType []) = ts'\"\n          \"ts \\<noteq> Bot\"\n          \"ts' \\<noteq> Bot\"\n  shows \"\\<exists>tn. c_types_agree ts tn \\<and> suffix t_in tn\"\nproof (cases ts)\n  case (TopType x1)\n  then obtain t_int where \"consume (TopType x1) (to_ct_list t_in) = t_int\" \"t_int \\<noteq> Bot\"\n    using assms(1,2,3)\n    by fastforce\n  thus ?thesis\n    using TopType ct_suffix_ct_list_eq_exists ct_suffix_ts_conv_suffix\n    unfolding consume.simps\n    by (metis append_Nil c_types_agree.simps(2) ct_suffix_def)\nnext\n  case (Type x2)\n  then obtain t_int where \"consume (Type x2) (to_ct_list t_in) = t_int\" \"t_int \\<noteq> Bot\"\n    using assms(1,2,3)\n    by fastforce\n  thus ?thesis\n    using c_types_agree_id Type consume_type suffixI ct_suffix_ts_conv_suffix\n    by fastforce\nnext\n  case Bot\n  thus ?thesis\n    using assms(2)\n    by simp\nqed\n\nlemma b_e_check_single_type_not_bot_sound:\n  assumes \"type_update ts (to_ct_list t_in) (Type t_out) = ts'\"\n          \"ts \\<noteq> Bot\"\n          \"ts' \\<noteq> Bot\"\n          \"c_types_agree ts' tm\"\n          \"\\<C> \\<turnstile> [e] : (t_in _> t_out)\"\n  shows \"\\<exists>tn. c_types_agree ts tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\n  using assms b_e_check_single_type_sound \nproof (cases ts)\n  case (TopType x1)\n  then obtain x1' where x_def:\"TopType x1' = ts'\"\n    using assms\n    by (simp, metis (full_types) produce.simps(1) produce.simps(6))\n  thus ?thesis\n    using assms b_e_check_single_top_sound TopType\n    by fastforce\nnext\n  case (Type x2)\n  then obtain x2' where x_def:\"Type x2' = ts'\"\n    using assms\n    by (simp, metis (full_types) produce.simps(2) produce.simps(6))\n  thus ?thesis\n    using assms b_e_check_single_type_sound Type\n    by fastforce\nnext\n  case Bot\n  thus ?thesis\n    using assms(2)\n    by simp\nqed\n\nlemma b_e_check_single_sound_unop_testop_cvtop:\n  assumes \"check_single \\<C> e tn' = tm'\"\n          \"(e = (Unop t uw) \\<and> unop_t_agree op t)\n           \\<or> (e = (Testop t uv) \\<and> is_int_t t)\n           \\<or> (e = (Cvtop t1 Convert t sx) \\<and> convert_cond t1 t sx)\n           \\<or> (e = (Cvtop t1 Reinterpret t sx) \\<and> ((t1 \\<noteq> t) \\<and> t_length t1 = t_length t \\<and> sx = None))\"\n          \"c_types_agree tm' tm\"\n          \"tn' \\<noteq> Bot\"\n          \"tm' \\<noteq> Bot\"\n shows \"\\<exists>tn. c_types_agree tn' tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\nproof -\n  have \"(e = (Cvtop t1 Convert t sx) \\<Longrightarrow> convert_cond t1 t sx)\"\n    using assms(2)\n    by simp\n  hence temp0:\"(e = (Cvtop t1 Convert t sx)) \\<Longrightarrow> (type_update tn' [TSome t] (Type [arity_1_result e]) = tm')\"\n    using assms(1,5) arity_1_result_def\n    by (simp del: convert_cond.simps)\n  have temp1:\"(e = (Cvtop t1 Reinterpret t sx)) \\<Longrightarrow> (type_update tn' [TSome t] (Type [arity_1_result e]) = tm')\"\n    using assms(1,2,5) arity_1_result_def\n    by simp\n  have 1:\"type_update tn' (to_ct_list [t]) (Type [arity_1_result e]) = tm'\"\n    using assms arity_1_result_def\n    unfolding to_ct_list_def\n    apply (simp del: convert_cond.simps)\n    apply fastforce\n    done\n  have \"\\<C> \\<turnstile> [e] : ([t] _> [arity_1_result e])\"\n    using assms(2) b_e_typing.intros(2,3,6,9,10)\n    unfolding arity_1_result_def\n    apply simp\n    apply (metis (no_types, lifting) assms(1,5) b_e.simps(801,803,805) b_e_typing.reinterpret b_e_typing.testop check_single.simps(2))\n    done\n  thus ?thesis\n    using b_e_check_single_type_not_bot_sound[OF 1 assms(4,5,3)]\n    by fastforce\nqed\n\nlemma b_e_check_single_sound_binop_relop:\n  assumes \"check_single \\<C> e tn' = tm'\"\n          \"((e = Binop t iop \\<and> binop_t_agree op t)\n            \\<or> (e = Relop t irop \\<and> relop_t_agree irop t))\"\n          \"c_types_agree tm' tm\"\n          \"tn' \\<noteq> Bot\"\n          \"tm' \\<noteq> Bot\"\n shows \"\\<exists>tn. c_types_agree tn' tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\nproof -\n  have \"type_update tn' (to_ct_list [t,t]) (Type [arity_2_result e]) = tm'\"\n    using assms arity_2_result_def\n    unfolding to_ct_list_def\n    by auto\n  moreover\n  have \"\\<C> \\<turnstile> [e] : ([t,t] _> [arity_2_result e])\"\n    using assms(2) b_e_typing.intros(4,5,7,8)\n    unfolding arity_2_result_def\n    by (metis (no_types) assms(1,2,5) b_e.simps(802,804) b_e_typing.relop binop check_single.simps(3))\n  ultimately\n  show ?thesis\n    using b_e_check_single_type_not_bot_sound[OF _ assms(4,5,3)]\n    by fastforce\nqed\n\nlemma b_e_type_checker_sound:\n  assumes \"b_e_type_checker \\<C> es (tn _> tm)\"\n  shows \"\\<C> \\<turnstile> es : (tn _> tm)\"\nproof -\n  fix e tn'\n  have \"b_e_type_checker \\<C> es (tn _> tm) \\<Longrightarrow>\n          \\<C> \\<turnstile> es : (tn _> tm)\"\n  and \"\\<And>tm' tm.\n       check \\<C> es tn' = tm' \\<Longrightarrow>\n       c_types_agree tm' tm \\<Longrightarrow>\n         \\<exists>tn. c_types_agree tn' tn \\<and> \\<C> \\<turnstile> es : (tn _> tm)\"\n  and \"\\<And>tm' tm.\n       check_single \\<C> e tn' = tm' \\<Longrightarrow>\n       c_types_agree tm' tm \\<Longrightarrow>\n       tn' \\<noteq> Bot \\<Longrightarrow>\n       tm' \\<noteq> Bot \\<Longrightarrow>\n         \\<exists>tn. c_types_agree tn' tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\n  proof (induction rule: b_e_type_checker_check_check_single.induct)\n    case (1 \\<C> es tn' tm)\n    thus ?case\n      by simp\n  next\n    case (2 \\<C> es' ts)\n    show ?case\n    proof (cases es')\n      case Nil\n      thus ?thesis\n        using 2(5,6)\n        by (simp add: b_e_type_empty)\n    next\n      case (Cons e es)\n        thus ?thesis\n        proof (cases ts)\n        case (TopType x1)\n        have check_expand:\"check \\<C> es (check_single \\<C> e ts) = tm'\"\n          using 2(5,6) TopType Cons\n          by simp\n        obtain ts' where ts'_def:\"check_single \\<C> e ts = ts'\"\n          by blast\n        obtain t_int where t_int_def:\"\\<C> \\<turnstile> es : (t_int _> tm)\"\n                                     \"c_types_agree ts' t_int\"\n          using 2(2)[OF Cons TopType check_expand 2(6)] ts'_def\n          by blast\n        obtain t_int' where \"c_types_agree ts t_int'\" \"\\<C> \\<turnstile> [e] : (t_int' _> t_int)\"\n          using 2(1)[OF Cons _ ts'_def] TopType c_types_agree.simps(3) t_int_def(2)\n          by blast\n        thus ?thesis\n          using t_int_def(1) b_e_type_comp_conc Cons\n          by fastforce\n      next\n        case (Type x2)\n        have check_expand:\"check \\<C> es (check_single \\<C> e ts) = tm'\"\n          using 2(5,6) Type Cons\n          by simp\n        obtain ts' where ts'_def:\"check_single \\<C> e ts = ts'\"\n          by blast\n        obtain t_int where t_int_def:\"\\<C> \\<turnstile> es : (t_int _> tm)\"\n                                     \"c_types_agree ts' t_int\"\n          using 2(4)[OF Cons Type check_expand 2(6)] ts'_def\n          by blast\n        obtain t_int' where \"c_types_agree ts t_int'\" \"\\<C> \\<turnstile> [e] : (t_int' _> t_int)\"\n          using 2(3)[OF Cons _ ts'_def] Type c_types_agree.simps(3) t_int_def(2)\n          by blast\n        thus ?thesis\n          using t_int_def(1) b_e_type_comp_conc Cons\n          by fastforce\n      next\n        case Bot\n        then show ?thesis\n          using 2(5,6) Cons\n          by auto\n      qed\n    qed\n  next\n    case (3 \\<C> v ts)\n    hence \"type_update ts [] (Type [typeof v]) = tm'\"\n      by simp\n    moreover\n    have \"\\<C> \\<turnstile> [C v] : ([] _> [typeof v])\"\n      using b_e_typing.intros(1)\n      by blast\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 3(3,4,2)]\n      by (metis list.simps(8) to_ct_list_def)\n  next\n    case (4 \\<C> t op ts)\n    hence \"unop_t_agree op t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_unop_testop_cvtop 4\n      by fastforce\n  next\n    case (5 \\<C> t op ts)\n    hence \"binop_t_agree op t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_binop_relop 5\n      by fastforce\n  next\n    case (6 \\<C> t op ts)\n    hence \"is_int_t t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_unop_testop_cvtop 6\n      by fastforce\n  next\n    case (7 \\<C> t op ts)\n    hence \"relop_t_agree op t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_binop_relop 7\n      by fastforce\n  next\n    case (8 \\<C> t1 t2 sx ts)\n    hence \"convert_cond t1 t2 sx\"\n      by (simp del: convert_cond.simps, meson)\n    thus ?case\n      using b_e_check_single_sound_unop_testop_cvtop 8\n      by fastforce\n  next\n    case (9 \\<C> t1 t2 sx ts)\n    hence \"t1 \\<noteq> t2 \\<and>  t_length t1 = t_length t2 \\<and> sx = None\"\n      by (simp, presburger)\n    thus ?case\n      using b_e_check_single_sound_unop_testop_cvtop 9\n      by fastforce\n  next\n    case (10 \\<C> ts)\n    thus ?case\n      using b_e_typing.intros(8) c_types_agree_not_bot_exists\n      by blast\n  next\n    case (11 \\<C> ts)\n    thus ?case\n      using b_e_typing.intros(9,32)\n      by fastforce\n  next\n    case (12 \\<C> ts)\n    thus ?case\n    proof (cases ts)\n      case (TopType x1)\n      thus ?thesis\n        proof (cases x1 rule: List.rev_cases)\n          case Nil\n          have \"\\<C> \\<turnstile> [Drop] : (tm@[T_i32] _> tm)\"\n            using b_e_typing.intros(10,32)\n            by fastforce\n          thus ?thesis\n            using c_types_agree_top1 Nil TopType\n            by fastforce\n        next\n          case (snoc ys y)\n            hence temp1:\"(consume (TopType (ys@[y])) [TAny]) = tm'\"\n              using 12 TopType type_update_empty\n              by (metis check_single.simps(10))\n            hence temp2:\"c_types_agree (TopType ys) tm\"\n              using consume_top_geq[OF temp1] 12(2,3,4)\n              by (metis Suc_leI add_diff_cancel_right' append_eq_conv_conj consume.simps(2)\n                        ct_suffix_def length_Cons length_append list.size(3) trans_le_add2\n                        zero_less_Suc)\n            obtain t where \"ct_list_eq [y] (to_ct_list [t])\"\n              using ct_list_eq_exists\n              unfolding ct_list_eq_def to_ct_list_def list_all2_map2\n              by (metis list_all2_Cons1 list_all2_Nil)\n            hence \"c_types_agree ts (tm@[t])\"\n              using temp2 ct_suffix_extend_ct_list_eq snoc TopType\n              by (simp add: to_ct_list_def)\n            thus ?thesis\n              using b_e_typing.intros(10,32)\n              by fastforce\n        qed\n    next\n      case (Type x2)\n      thus ?thesis\n      proof (cases x2 rule: List.rev_cases)\n        case Nil\n        hence \"(consume (Type []) [TAny]) = tm'\"\n          using 12 Type type_update_empty\n          by fastforce\n        thus ?thesis\n          using 12(4) ct_list_eq_def ct_suffix_def to_ct_list_def\n          by simp\n      next\n        case (snoc ys y)\n            hence temp1:\"(consume (Type (ys@[y])) [TAny]) = tm'\"\n              using 12 Type type_update_empty\n              by (metis check_single.simps(10))\n            hence temp2:\"c_types_agree (Type ys) tm\"\n              using 12(2,3,4) ct_suffix_def\n              by (simp, metis One_nat_def butlast_conv_take butlast_snoc c_types_agree.simps(1)\n                              length_Cons list.size(3))\n            obtain t where \"ct_list_eq [TSome y] (to_ct_list [t])\"\n              using ct_list_eq_exists\n              unfolding ct_list_eq_def to_ct_list_def list_all2_map2\n              by (metis list_all2_Cons1 list_all2_Nil)\n            hence \"c_types_agree ts (tm@[t])\"\n              using temp2 ct_suffix_extend_ct_list_eq snoc Type\n              by (simp add: ct_list_eq_def to_ct_list_def)\n            thus ?thesis\n              using b_e_typing.intros(10,32)\n              by fastforce\n      qed\n    qed simp\n  next\n    case (13 \\<C> ts)\n    thus ?case\n    proof (cases ts)\n      case (TopType x1)\n      consider\n          (1) \"length x1 = 0\"\n        | (2) \"length x1 = 1\"\n        | (3) \"length x1 = 2\"\n        | (4) \"length x1 \\<ge> 3\"\n        by linarith\n      thus ?thesis\n      proof (cases)\n        case 1\n        hence \"tm' = TopType [TAny]\"\n          using TopType 13\n          by simp\n        then obtain t'' tm'' where tm_def:\"tm = tm''@[t'']\"\n          using 13(2) ct_suffix_def\n          by (simp, metis Nil_is_append_conv append_butlast_last_id checker_type.inject(1)\n                          ct_prefixI ct_prefix_nil(2) produce.simps(1) produce_nil)\n        have \"\\<C> \\<turnstile> [Select] : ([t'',t'',T_i32] _> [t''])\"\n          using b_e_typing.intros(11)\n          by blast\n        thus ?thesis\n          using TopType 13 1 tm_def b_e_typing.intros(32) c_types_agree.simps(2) c_types_agree_top1\n          by fastforce\n      next\n        case 2\n        have \"type_update_select (TopType x1) = tm'\"\n          using 13 TopType\n          unfolding check_single.simps\n          by simp\n        hence x1_def:\"ct_list_eq x1 [TSome T_i32]\" \"tm' = TopType [TAny]\"\n          using type_update_select_length1[OF _ 2 13(4)]\n          by simp_all\n        then obtain t'' tm'' where tm_def:\"tm = tm''@[t'']\"\n          using 13(2) ct_suffix_def\n          by (metis Nil_is_append_conv append_butlast_last_id c_types_agree.simps(2) ct_prefixI\n                    ct_prefix_nil(2) list.simps(8) to_ct_list_def)\n        have \"c_types_agree (TopType x1) ((tm''@[t'',t''])@[T_i32])\"\n          using x1_def(1)\n          by (metis c_types_agree_top2 list.simps(8,9) to_ct_list_def)\n        thus ?thesis\n          using TopType b_e_typing.intros(11,32) tm_def\n          by auto\n      next\n        case 3\n        have \"type_update_select (TopType x1) = tm'\"\n          using 13 TopType\n          unfolding check_single.simps\n          by simp\n        then obtain ct1 ct2 where x1_def:\"x1 = [ct1, ct2]\"\n                                         \"ct_eq ct2 (TSome T_i32)\"\n                                         \"tm' = TopType [ct1]\"\n          using type_update_select_length2[OF _ 3 13(4)]\n          by blast\n        then obtain t'' tm'' where tm_def:\"tm = tm''@[t'']\"\n                                          \"ct_list_eq [ct1] [(TSome t'')]\"\n          using 13(2) c_types_agree_imp_ct_list_eq[of \"[ct1]\" tm]\n          by (metis append_Nil2 append_butlast_last_id append_eq_append_conv_if append_eq_conv_conj\n                    ct_list_eq_length diff_Suc_1 length_Cons length_butlast length_map\n                    list.simps(8,9) list.size(3) nat.distinct(2) to_ct_list_def)\n        hence \"ct_list_eq x1 (to_ct_list [ t'', T_i32])\"\n          using x1_def(1,2)\n          unfolding ct_list_eq_def to_ct_list_def\n          by fastforce\n        hence \"c_types_agree (TopType x1) ((tm''@[t''])@[t'',T_i32])\"\n          using c_types_agree_top2\n          by blast\n        thus ?thesis\n          using TopType b_e_typing.intros(11,32) tm_def\n          by auto\n      next\n        case 4\n        then obtain nat where nat_def:\"length x1 = Suc (Suc (Suc nat))\"\n          by (metis add_eq_if diff_Suc_1 le_Suc_ex numeral_3_eq_3 nat.distinct(2))\n        hence tm'_def:\"type_update_select (TopType x1) = tm'\"\n          using 13 TopType\n          by simp\n        then obtain tm_int where \"(select_return_top x1\n                                    (x1 ! (length x1 - 2))\n                                    (x1 ! (length x1 - 3))) = tm_int\"\n                                 \"tm_int \\<noteq> Bot\"\n          using nat_def 13(4)\n          unfolding type_update_select.simps\n          by fastforce\n        then obtain x2 where x2_def:\"(select_return_top x1\n                                       (x1 ! (length x1 - 2))\n                                       (x1 ! (length x1 - 3))) = TopType x2\"\n          using select_return_top_exists\n          by fastforce\n        have \"ct_suffix x1 [TAny, TAny, TSome T_i32] \\<or> ct_suffix [TAny, TAny, TSome T_i32] x1\"\n          using tm'_def nat_def 13(4)\n          by (simp, metis (full_types) produce.simps(6))\n        hence tm'_eq:\"tm' = TopType x2\"\n          using tm'_def nat_def 13(4) x2_def\n          by force\n        then obtain cts' ct1 ct2 ct3 where cts'_def:\"x1 = cts'@[ct1, ct2, ct3]\"\n                                                    \"ct_eq ct3 (TSome T_i32)\"\n          using type_update_select_length3 tm'_def 4\n          by blast\n        then obtain c' cm' where tm_def:\"tm = cm'@[c']\"\n                                        \"ct_suffix cts' (to_ct_list cm')\"\n                                        \"ct_eq (x1 ! (length x1 - 2)) (TSome c')\"\n                                        \"ct_eq (x1 ! (length x1 - 3)) (TSome c')\"\n          using select_return_top_ct_eq[OF x2_def 4] tm'_eq 4 13(2)\n          by fastforce\n        then obtain as bs where cm'_def:\"cm' = as@bs\"\n                                        \"ct_list_eq (to_ct_list bs) cts'\"\n          using ct_list_eq_cons_ct_list1 ct_list_eq_ts_conv_eq\n          by (metis ct_suffix_def to_ct_list_append(2))\n        hence \"ct_eq ct1 (TSome c')\"\n              \"ct_eq ct2 (TSome c')\"\n          using cts'_def tm_def\n          apply simp_all\n          apply (metis append.assoc append_Cons append_Nil length_append_singleton nth_append_length)\n          done\n        hence \"c_types_agree ts (cm'@[c',c',T_i32])\"\n          using c_types_agree_top2[of _ _ as] cm'_def(1) TopType\n                ct_list_eq_concat[OF ct_list_eq_commute[OF cm'_def(2)]] cts'_def\n          unfolding to_ct_list_def ct_list_eq_def\n          by fastforce\n        thus ?thesis\n          using b_e_typing.intros(11,32) tm_def\n          by auto\n      qed\n    next\n      (* TODO: refactor *)\n      case (Type x2)\n      hence x2_cond:\"(length x2 \\<ge> 3 \\<and> (x2!(length x2-2)) = (x2!(length x2-3)))\"\n        using 13\n        by (simp, meson)\n      hence tm'_def:\"consume (Type x2) [TAny, TSome T_i32] = tm'\"\n        using 13 Type\n        by simp\n      obtain ts' ts'' where cts_def:\"x2 = ts'@ ts''\" \"length ts'' = 3\"\n        using x2_cond\n        by (metis append_take_drop_id diff_diff_cancel length_drop)\n      then obtain t1 ts''2 where \"ts'' = t1#ts''2\" \"length ts''2 = Suc (Suc 0)\"\n        using List.length_Suc_conv[of ts' \"Suc (Suc 0)\"]\n        by (metis length_Suc_conv numeral_3_eq_3)\n      then obtain t2 t3 where \"ts'' = [t1,t2,t3]\"\n        using List.length_Suc_conv[of ts''2 \"Suc 0\"]\n        by (metis length_0_conv length_Suc_conv)\n      hence cts_def2:\"x2 = ts'@ [t1,t2,t3]\"\n        using cts_def\n        by simp\n      have ts'_suffix:\"ct_suffix [TAny, TSome T_i32] (to_ct_list (ts' @ [t1, t2, t3]))\"\n        using tm'_def 13(4)\n        by (simp, metis cts_def2)\n      hence tm'_def:\"tm' = Type (ts'@[t1])\"\n        using tm'_def 13(4) cts_def2\n        by simp\n      obtain as bs where \"(to_ct_list (ts' @ [t1])) @ (to_ct_list ([t2, t3])) = as@bs\"\n                         \"ct_list_eq bs [TAny, TSome T_i32]\"\n        using ts'_suffix\n        unfolding ct_suffix_def to_ct_list_def\n        by fastforce\n      hence \"t3 = T_i32\"\n        unfolding to_ct_list_def ct_list_eq_def\n        by (metis (no_types, lifting) Nil_is_map_conv append_eq_append_conv ct_eq.simps(1)\n                  length_Cons list.sel(1,3) list.simps(9) list_all2_Cons2 list_all2_lengthD)\n      moreover\n      have \"t1 = t2\"\n        using x2_cond cts_def2\n        by (simp, metis append.left_neutral append_Cons append_assoc length_append_singleton\n                        nth_append_length)\n      ultimately\n      have \"c_types_agree (Type x2) ((ts'@[t1,t1])@[T_i32])\"\n        using cts_def2\n        by simp\n      thus ?thesis\n        using b_e_typing.intros(11,32) Type tm'_def 13(2)\n        by fastforce\n    qed simp\n  next\n    case (14 \\<C> tn'' tm'' es ts)\n    hence \"type_update ts (to_ct_list tn'') (Type tm'') = tm'\"\n      by auto\n    moreover\n    have \"(b_e_type_checker (\\<C>\\<lparr>label := ([tm''] @ (label \\<C>))\\<rparr>) es (tn'' _> tm''))\"\n      using 14\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Block (tn'' _> tm'') es] : (tn'' _> tm'')\"\n      using b_e_typing.intros(12)[OF _ 14(1)]\n      by blast\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 14(4,5,3)]\n      by blast\n  next\n    case (15 \\<C> tn'' tm'' es ts)\n    hence \"type_update ts (to_ct_list tn'') (Type tm'') = tm'\"\n      by auto\n    moreover\n    have \"(b_e_type_checker (\\<C>\\<lparr>label := ([tn''] @ (label \\<C>))\\<rparr>) es (tn'' _> tm''))\"\n      using 15\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Loop (tn'' _> tm'') es] : (tn'' _> tm'')\"\n      using b_e_typing.intros(13)[OF _ 15(1)]\n      by blast\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 15(4,5,3)]\n      by blast\n  next\n    case (16 \\<C> tn'' tm'' es1 es2 ts)\n    hence \"type_update ts (to_ct_list (tn''@[T_i32])) (Type tm'') = tm'\"\n      by auto\n    moreover\n    have \"(b_e_type_checker (\\<C>\\<lparr>label := ([tm''] @ (label \\<C>))\\<rparr>) es1 (tn'' _> tm''))\"\n         \"(b_e_type_checker (\\<C>\\<lparr>label := ([tm''] @ (label \\<C>))\\<rparr>) es2 (tn'' _> tm''))\"\n      using 16\n      by (simp, meson)+\n    hence \"\\<C> \\<turnstile> [If (tn'' _> tm'') es1 es2] : (tn''@[T_i32] _> tm'')\"\n      using b_e_typing.intros(14)[OF _ 16(1,2)]\n      by blast\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 16(5,6,4)]\n      by blast\n  next\n    case (17 \\<C> i ts)\n    hence \"type_update ts (to_ct_list ((label \\<C>)!i)) (TopType []) = tm'\"\n      by auto\n    moreover\n    have \"i < length (label \\<C>)\"\n      using 17\n      by (simp, meson)\n    ultimately\n    show ?case\n      using b_e_check_single_top_not_bot_sound[OF _ 17(3,4)]\n            b_e_typing.intros(15)\n            b_e_typing.intros(32)\n      by (metis suffix_def)\n  next\n    case (18 \\<C> i ts)\n    hence \"type_update ts (to_ct_list ((label \\<C>)!i @ [T_i32])) (Type ((label \\<C>)!i)) = tm'\"\n      by auto\n    moreover\n    have \"i < length (label \\<C>)\"\n      using 18\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Br_if i] : ((label \\<C>)!i @ [T_i32] _> (label \\<C>)!i)\"\n      using b_e_typing.intros(16)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 18(3,4,2)]\n      by fastforce\n  next\n    case (19 \\<C> \"is\" i ts)\n    then obtain tls where tls_def:\"(same_lab (is@[i]) (label \\<C>)) = Some tls\"\n      by fastforce\n    hence \"type_update ts (to_ct_list (tls @ [T_i32])) (TopType []) = tm'\"\n      using 19\n      by simp\n    thus ?case\n      using b_e_check_single_top_not_bot_sound[OF _ 19(3,4)]\n            b_e_typing.intros(17)[OF same_lab_conv_list_all[OF tls_def]]\n            b_e_typing.intros(32)\n      by (metis suffix_def)\n  next\n    case (20 \\<C> ts)\n    then obtain ts_r where \"(return \\<C>) = Some ts_r\"\n      by fastforce\n    moreover\n    hence \"type_update ts (to_ct_list ts_r) (TopType []) = tm'\"\n      using 20\n      by simp\n    ultimately\n    show ?case\n      using b_e_check_single_top_not_bot_sound[OF _ 20(3,4)]\n            b_e_typing.intros(18,32)\n      by (metis suffix_def)\n  next\n    case (21 \\<C> i ts)\n    obtain tn'' tm'' where func_def:\"(func_t \\<C>)!i = (tn'' _> tm'')\"\n      using tf.exhaust\n      by blast\n    hence \"type_update ts (to_ct_list tn'') (Type tm'') = tm'\"\n      using 21\n      by auto\n    moreover\n    have \"i < length (func_t \\<C>)\"\n      using 21\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Call i] : (tn'' _> tm'')\"\n      using b_e_typing.intros(19) func_def\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 21(3,4,2)]\n      by fastforce\n  next\n    case (22 \\<C> i ts)\n    obtain tn'' tm'' where type_def:\"(types_t \\<C>)!i = (tn'' _> tm'')\"\n      using tf.exhaust\n      by blast\n    hence \"type_update ts (to_ct_list (tn''@[T_i32])) (Type tm'') = tm'\"\n      using 22\n      by auto\n    moreover\n    have \"length (table \\<C>) \\<ge> 1  \\<and> i < length (types_t \\<C>)\"\n      using 22\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Call_indirect i] : (tn''@[T_i32] _> tm'')\"\n      using b_e_typing.intros(20) type_def\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 22(3,4,2)]\n      by fastforce\n  next\n    case (23 \\<C> i ts)\n    hence \"type_update ts [] (Type [(local \\<C>)!i]) = tm'\"\n      by auto\n    moreover\n    have \"i < length (local \\<C>)\"\n      using 23\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Get_local i] : ([] _> [(local \\<C>)!i])\"\n      using b_e_typing.intros(21)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 23(3,4,2)]\n      unfolding to_ct_list_def\n      by (metis list.map_disc_iff)\n  next\n    case (24 \\<C> i ts)\n    hence \"type_update ts (to_ct_list [(local \\<C>)!i]) (Type []) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"i < length (local \\<C>)\"\n      using 24\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Set_local i] : ([(local \\<C>)!i] _> [])\"\n      using b_e_typing.intros(22)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 24(3,4,2)]\n      by fastforce\n  next\n    case (25 \\<C> i ts)\n    hence \"type_update ts (to_ct_list [(local \\<C>)!i]) (Type [(local \\<C>)!i]) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"i < length (local \\<C>)\"\n      using 25\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Tee_local i] : ([(local \\<C>)!i] _> [(local \\<C>)!i])\"\n      using b_e_typing.intros(23)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 25(3,4,2)]\n      by fastforce\n  next\n    case (26 \\<C> i ts)\n    hence \"type_update ts [] (Type [tg_t ((global \\<C>)!i)]) = tm'\"\n      by auto\n    moreover\n    have \"i < length (global \\<C>)\"\n      using 26\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Get_global i] : ([] _> [tg_t ((global \\<C>)!i)])\"\n      using b_e_typing.intros(24)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 26(3,4,2)]\n      unfolding to_ct_list_def\n      by (metis list.map_disc_iff)\n  next\n    case (27 \\<C> i ts)\n    hence \"type_update ts (to_ct_list [tg_t ((global \\<C>)!i)]) (Type []) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"i < length (global \\<C>) \\<and> is_mut (global \\<C> ! i)\"\n      using 27\n      by (simp, meson)\n    then obtain t where \"(global \\<C> ! i) = \\<lparr>tg_mut = T_mut, tg_t = t\\<rparr>\" \"i < length (global \\<C>)\"\n      unfolding is_mut_def\n      by (cases \"global \\<C> ! i\", auto)\n    hence \"\\<C> \\<turnstile> [Set_global i] : ([tg_t (global \\<C> ! i)] _> [])\"\n      using b_e_typing.intros(25)[of i \\<C> \"tg_t (global \\<C> ! i)\"]\n      unfolding is_mut_def tg_t_def\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 27(3,4,2)]\n      by fastforce\n  next\n    case (28 \\<C> t tp_sx a off ts)\n    hence \"type_update ts (to_ct_list [T_i32]) (Type [t]) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"length (memory \\<C>) \\<ge> 1  \\<and> load_store_t_bounds a (option_projl tp_sx) t\"\n      using 28\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Load t tp_sx a off] : ([T_i32] _> [t])\"\n      using b_e_typing.intros(26)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 28(3,4,2)]\n      by fastforce\n  next\n    case (29 \\<C> t tp a off ts)\n    hence \"type_update ts (to_ct_list [T_i32,t]) (Type []) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"length (memory \\<C>) \\<ge> 1  \\<and> load_store_t_bounds a tp t\"\n      using 29\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Store t tp a off] : ([T_i32,t] _> [])\"\n      using b_e_typing.intros(27)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 29(3,4,2)]\n      by fastforce\n  next\n    case (30 \\<C> ts)\n    hence \"type_update ts [] (Type [T_i32]) = tm'\"\n      by auto\n    moreover\n    have \"length (memory \\<C>) \\<ge> 1 \" \n      using 30\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Current_memory] : ([] _> [T_i32])\"\n      using b_e_typing.intros(28)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 30(3,4,2)]\n      unfolding to_ct_list_def\n      by (metis list.map_disc_iff)\n  next\n    case (31 \\<C> ts)\n    hence \"type_update ts (to_ct_list [T_i32]) (Type [T_i32]) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"length (memory \\<C>) \\<ge> 1 \" \n      using 31\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Grow_memory] : ([T_i32] _> [T_i32])\"\n      using b_e_typing.intros(29)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 31(3,4,2)]\n      by fastforce\n  qed\n  thus ?thesis\n    using assms\n    by simp\nqed\n\nsubsection {* Completeness *}\n\nlemma check_single_imp:\n  assumes \"check_single \\<C> e ctn = ctm\"\n          \"ctm \\<noteq> Bot\"\n  shows \"check_single \\<C> e = id\n         \\<or> check_single \\<C> e = (\\<lambda>ctn. type_update_select ctn)\n         \\<or> (\\<exists>cons prods. (check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)))\"\nproof -\n  have True\n  and True\n  and \"check_single \\<C> e ctn = ctm \\<Longrightarrow>\n       ctm \\<noteq> Bot \\<Longrightarrow>\n         ?thesis\"\n  proof (induction rule: b_e_type_checker_check_check_single.induct)\n    case (1 \\<C> es tn tm)\n    thus ?case\n      by simp\n  next\n    case (2 \\<C> es ts)\n    thus ?case\n      by simp\n  next\n    case (3 \\<C> v ts)\n    thus ?case\n      by fastforce\n  next\n    case (4 \\<C> t uu ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (5 \\<C> t uv ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (6 \\<C> t uw ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (7 \\<C> t ux ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (8 \\<C> t1 t2 sx ts)\n    thus ?case\n      by (simp del: convert_cond.simps, meson assms(2) type_update.simps)\n  next\n    case (9 \\<C> t1 t2 sx ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (10 \\<C> ts)\n    thus ?case\n      by fastforce\n  next\n    case (11 \\<C> ts)\n    thus ?case\n      by fastforce\n  next\n    case (12 \\<C> ts)\n    thus ?case\n      by fastforce\n  next\n    case (13 \\<C> ts)\n    thus ?case\n      by fastforce\n  next\n    case (14 \\<C> tn tm es ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (15 \\<C> tn tm es ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (16 \\<C> tn tm es1 es2 ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (17 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (18 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (19 \\<C> \"is\" ts)\n    thus ?case\n      by (simp, metis assms(2) option.case_eq_if type_update.simps)\n  next\n    case (20 \\<C> ts)\n    thus ?case\n      by (simp, metis assms(2) option.case_eq_if type_update.simps)\n  next\n    case (21 \\<C> i ts)\n    then show ?case\n      by (simp, metis (no_types, lifting) assms(2) tf.case tf.exhaust type_update.simps)\n  next\n    case (22 \\<C> i ts)\n    thus ?case\n      by (simp, metis (no_types, lifting) assms(2) tf.case tf.exhaust type_update.simps)\n  next\n    case (23 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (24 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (25 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (26 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (27 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (28 \\<C> t tp_sx a off ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (29 \\<C> t tp a off ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (30 \\<C> ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (31 \\<C> ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  qed\n  thus ?thesis\n    using assms\n    by simp\nqed\n\nlemma check_equiv_fold:\n  \"check \\<C> es ts = foldl (\\<lambda> ts e. (case ts of Bot \\<Rightarrow> Bot | _ \\<Rightarrow> check_single \\<C> e ts)) ts es\"\nproof (induction es arbitrary: ts)\n  case Nil\n  thus ?case\n    by simp\nnext\n  case (Cons e es)\n  obtain ts' where ts'_def:\"check \\<C> (e # es) ts = ts'\"\n    by blast\n  show ?case\n  proof (cases \"ts = Bot\")\n    case True\n    thus ?thesis\n      using ts'_def\n      by (induction es, simp_all)\n  next\n    case False\n    thus ?thesis\n      using ts'_def Cons\n      by (cases ts, simp_all)\n  qed\nqed\n\nlemma check_neq_bot_snoc:\n  assumes \"check \\<C> (es@[e]) ts \\<noteq> Bot\"\n  shows \"check \\<C> es ts \\<noteq> Bot\"\n  using assms\nproof (induction es arbitrary: ts)\n  case Nil\n  thus ?case\n    by (cases ts, simp_all)\nnext\n  case (Cons a es)\n  thus ?case\n    by (cases ts, simp_all)\nqed\n\nlemma check_unfold_snoc:\n  assumes \"check \\<C> es ts \\<noteq> Bot\"\n  shows \"check \\<C> (es@[e]) ts = check_single \\<C> e (check \\<C> es ts)\"\nproof -\n  obtain f where f_def:\"f = (\\<lambda> e ts. (case ts of Bot \\<Rightarrow> Bot | _ \\<Rightarrow> check_single \\<C> e ts))\"\n    by blast\n  have f_simp:\"\\<And>ts. ts \\<noteq> Bot \\<Longrightarrow> (f e ts = check_single \\<C> e ts)\"\n  proof -\n    fix ts\n    show \"ts \\<noteq> Bot \\<Longrightarrow> (f e ts = check_single \\<C> e ts)\"\n      using f_def\n      by (cases ts, simp_all)\n  qed\n  have \"check \\<C> (es@[e]) ts = foldl (\\<lambda> ts e. (case ts of Bot \\<Rightarrow> Bot | _ \\<Rightarrow> check_single \\<C> e ts)) ts (es@[e])\"\n    using check_equiv_fold\n    by simp\n  also\n  have \"... = foldr (\\<lambda> e ts. (case ts of Bot \\<Rightarrow> Bot | _ \\<Rightarrow> check_single \\<C> e ts)) (rev (es@[e])) ts\"\n    using foldl_conv_foldr\n    by fastforce\n  also\n  have \"... = f e (foldr (\\<lambda> e ts. (case ts of Bot \\<Rightarrow> Bot | _ \\<Rightarrow> check_single \\<C> e ts)) (rev es) ts)\"\n    using f_def\n    by simp\n  also\n  have \"... = f e (check \\<C> es ts)\"\n    using foldr_conv_foldl[of _ \"(rev es)\" ts] rev_rev_ident[of es] check_equiv_fold\n    by simp\n  also\n  have \"... = check_single \\<C> e (check \\<C> es ts)\"\n    using assms f_simp\n    by simp\n  finally\n  show ?thesis .\nqed\n\nlemma check_single_imp_weakening:\n  assumes \"check_single \\<C> e (Type t1s) = ctm\"\n          \"ctm \\<noteq> Bot\"\n          \"c_types_agree ctn t1s\"\n          \"c_types_agree ctm t2s\"\n  shows \"\\<exists>ctm'. check_single \\<C> e ctn = ctm' \\<and> c_types_agree ctm' t2s\"\nproof -\n  consider (1) \"check_single \\<C> e = id\" \n         | (2) \"check_single \\<C> e = (\\<lambda>ctn. type_update_select ctn)\"\n         | (3) \"(\\<exists>cons prods. (check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)))\"\n    using check_single_imp assms\n    by blast\n  thus ?thesis\n  proof (cases)\n    case 1\n    thus ?thesis\n      using assms(1,3,4)\n      by fastforce\n  next\n    (* TODO: better proof *)\n    case 2\n    note outer_2 = 2\n    hence t1s_cond:\"(length t1s \\<ge> 3 \\<and> (t1s!(length t1s-2)) = (t1s!(length t1s-3)))\"\n      using assms(1,2)\n      by (simp, meson)\n    hence ctm_def:\"ctm = consume (Type t1s) [TAny, TSome T_i32]\"\n      using assms(1,2) 2\n      by simp\n    then obtain c_t where c_t_def:\"ctm = Type c_t\"\n      using assms(2)\n      by (meson consume.simps(1))\n    hence t2s_eq:\"t2s = c_t\"\n      using assms(4)\n      by simp\n    hence t2s_len:\"length t2s > 0\"\n      using t1s_cond ctm_def c_t_def assms(2)\n      by (metis Suc_leI Suc_n_not_le_n checker_type.inject(2) consume.simps(1)\n                diff_is_0_eq dual_order.trans length_0_conv length_Cons length_greater_0_conv\n                nat.simps(3) numeral_3_eq_3 take_eq_Nil)\n    have t1s_suffix_full:\"ct_suffix [TAny, TSome T_i32] (to_ct_list t1s)\"\n      using assms(2) ctm_def ct_suffix_less\n      by (metis consume.simps(1))\n    hence t1s_suffix:\"ct_suffix [TSome T_i32] (to_ct_list t1s)\"\n      using assms(2) ctm_def ct_suffix_less\n      by (metis append_butlast_last_id last.simps list.distinct(1))\n    obtain t t1s' where t1s_suffix2:\"t1s = t1s'@[t,t,T_i32]\"\n      using type_update_select_type_length3 assms(1) c_t_def outer_2\n      by fastforce\n    hence t2s_def:\"t2s = t1s'@[t]\"\n      using ctm_def c_t_def t2s_eq t1s_suffix assms(2) t1s_suffix_full\n      by simp\n    show ?thesis\n      using assms(1,3,4)\n    proof (cases ctn)\n      case (TopType x1)\n      consider\n          (1) \"length x1 = 0\"\n        | (2) \"length x1 = 1\"\n        | (3) \"length x1 = 2\"\n        | (4) \"length x1 \\<ge> 3\"\n        by linarith\n      thus ?thesis\n      proof (cases)\n        case 1\n        hence \"check_single \\<C> e ctn = TopType [TAny]\"\n          using 2 TopType\n          by simp\n        thus ?thesis\n          using ct_suffix_singleton to_ct_list_def t2s_len\n          by auto\n      next\n        case 2\n        hence \"ct_suffix [TSome T_i32] x1\"\n          using assms(3) TopType ct_suffix_imp_ct_list_eq ct_suffix_shared t1s_suffix\n          by (metis One_nat_def append_Nil c_types_agree.simps(2) ct_list_eq_commute ct_suffix_def\n                    diff_self_eq_0 drop_0 length_Cons list.size(3))\n        hence \"check_single \\<C> e ctn = TopType [TAny]\"\n          using outer_2 TopType 2\n          by simp\n        thus ?thesis\n          using t2s_len ct_suffix_singleton\n          by (simp add: to_ct_list_def)\n      next\n        case 3\n        have \"ct_list_eq (to_ct_list t1s) (to_ct_list (t1s' @ [t, t, T_i32]))\"\n          using t1s_suffix2\n          by (simp add: ct_list_eq_ts_conv_eq)\n        hence temp1:\"to_ct_list t1s = (to_ct_list (t1s' @ [t])) @ (to_ct_list [t, T_i32])\"\n          using t1s_suffix2 to_ct_list_def\n          by simp\n        hence \"ct_suffix (to_ct_list [t, T_i32]) (to_ct_list t1s)\"\n          using ct_suffix_def[of \"(to_ct_list [t, T_i32])\" \"(to_ct_list t1s)\"]\n          by (simp add: ct_suffix_cons_it)\n        hence \"ct_suffix (to_ct_list [t, T_i32]) x1\"\n          using assms(3) TopType 3\n          by (simp, metis temp1 append_Nil ct_suffix_cons2 ct_suffix_def length_Cons length_map\n                          list.size(3) numeral_2_eq_2 to_ct_list_def)\n        hence temp3:\"ct_list_eq (to_ct_list [t, T_i32]) x1\"\n          using 3 ct_suffix_imp_ct_list_eq\n          unfolding to_ct_list_def\n          by (metis Suc_leI ct_list_eq_commute diff_is_0_eq drop_0 length_Cons length_map lessI\n                    list.size(3) numeral_2_eq_2)\n        hence temp4:\"ct_suffix [TSome T_i32] x1\" \n          using ct_suffix_less[of \"[TSome t]\" \"[TSome T_i32]\" x1]\n                ct_suffix_extend_ct_list_eq[of \"[]\" \"[]\"] ct_suffix_nil\n          unfolding to_ct_list_def\n          by fastforce\n        hence \"ct_suffix (take 1 x1) (to_ct_list [t])\"\n          using temp3 ct_suffix_nil ct_list_eq_commute ct_suffix_extend_ct_list_eq[of \"[]\" \"[]\" \"(take 1 x1)\" \"(to_ct_list [t])\"]\n          unfolding to_ct_list_def\n          by (simp, metis butlast.simps(2) butlast_conv_take ct_list_eq_take diff_Suc_1 length_Cons\n                          list.distinct(1) list.size(3))\n        thus ?thesis\n          using TopType 2 3 ct_suffix_nil temp3 temp4 t2s_def to_ct_list_def\n          apply (simp, safe)\n          apply (metis append.assoc ct_suffix_def)\n          done\n      next\n        case 4\n        then obtain nat where nat_def:\"length x1 = Suc (Suc (Suc nat))\"\n          by (metis add_eq_if diff_Suc_1 le_Suc_ex numeral_3_eq_3 nat.distinct(2))\n        obtain x1' x x' x'' where x1_split:\"x1 = x1'@[x,x',x'']\"\n        proof -\n          assume local_assms:\"(\\<And>x1' x x' x''. x1 = x1' @ [x, x', x''] \\<Longrightarrow> thesis)\"\n          obtain x1' x1'' where tn_split:\"x1 = x1'@x1''\"\n                               \"length x1'' = 3\"\n            using 4\n            by (metis append_take_drop_id diff_diff_cancel length_drop)\n          then obtain x x1''2 where \"x1'' = x#x1''2\" \"length x1''2 = Suc (Suc 0)\"\n            by (metis length_Suc_conv numeral_3_eq_3)\n          then obtain x' x'' where tn''_def:\"x1''= [x,x',x'']\"\n            using List.length_Suc_conv[of x1''2 \"Suc 0\"]\n            by (metis length_0_conv length_Suc_conv)\n          thus ?thesis\n            using tn_split local_assms\n            by simp\n        qed\n        hence a:\"ct_suffix (x1'@[x,x',x'']) (to_ct_list (t1s' @ [t, t, T_i32]))\"\n          using t1s_suffix2 assms(3) TopType\n          by simp\n        hence b:\"ct_suffix (x1'@[x,x']) (to_ct_list (t1s' @ [t, t])) \\<and> (ct_eq x'' (TSome T_i32))\"\n          using to_ct_list_def ct_suffix_unfold_one[of \"(x1'@[x,x'])\" \"x''\" \"to_ct_list (t1s' @ [t, t])\"]\n          by fastforce\n        hence c:\"ct_suffix (x1'@[x]) (to_ct_list (t1s' @ [t])) \\<and> (ct_eq x' (TSome t))\"\n          using to_ct_list_def ct_suffix_unfold_one[of \"(x1'@[x])\" \"x'\" \"to_ct_list (t1s' @ [t])\"]\n          by fastforce\n        hence d:\"ct_suffix x1' (to_ct_list t1s') \\<and> (ct_eq x (TSome t))\"\n          using to_ct_list_def ct_suffix_unfold_one[of \"(x1')\" \"x\" \"to_ct_list (t1s')\"]\n          by fastforce\n        have \"(take (length x1 - 3) x1) = x1'\"\n          using x1_split\n          by simp\n        have x'_ind:\"(x1!(length x1-2)) = x'\"\n          using x1_split List.nth_append_length[of \"x1' @ [x]\"]\n          by simp\n        have x_ind:\"(x1!(length x1-3)) = x\"\n          using x1_split\n          by simp\n        have \"ct_suffix [TSome T_i32] x1\"\n          using b x1_split ct_suffix_def ct_list_eq_def ct_suffixI[of x1 \"x1' @ [x, x']\"]\n          by simp\n        hence \"check_single \\<C> e (TopType x1) = (select_return_top x1 (x1!(length x1-2)) (x1!(length x1-3)))\"\n          using type_update_select_conv_select_return_top[OF _ 4]\n          unfolding 2\n          by blast\n        moreover\n        have \"... = (TopType (x1'@[x])) \\<or> ... = (TopType (x1'@[x']))\"\n          apply (cases x; cases x')\n          using x1_split 4 nat_def 2 x_ind x'_ind c d\n          by simp_all\n        moreover\n        have \"ct_suffix (x1'@[x]) (to_ct_list t2s)\"\n          by (simp add: c t2s_def)\n        moreover\n        have \"ct_suffix (x1'@[x']) (to_ct_list t2s)\"\n          using ct_suffix_unfold_one[symmetric, of x' \"(TSome t)\" x1' \"(to_ct_list t1s')\"] c d\n                t2s_def\n          unfolding to_ct_list_def\n          by fastforce\n        ultimately\n        show ?thesis\n          using TopType\n          by auto\n      qed\n    qed simp_all\n  next\n    case 3\n    then obtain cons prods where c_s_def:\"check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)\"\n      by blast\n    hence ctm_def:\"ctm = type_update (Type t1s) cons prods\"\n      using assms(1)\n      by fastforce\n    hence cons_suffix:\"ct_suffix cons (to_ct_list t1s)\"\n      using assms\n      by (simp, metis (full_types) produce.simps(6))\n    hence t_int_def:\"consume (Type t1s) cons = (Type (take (length t1s - length cons) t1s))\"\n      using ctm_def\n      by simp\n    hence ctm_def2:\"ctm = produce (Type (take (length t1s - length cons) t1s)) prods\"\n      using ctm_def\n      by simp\n    show ?thesis\n    proof (cases ctn)\n      case (TopType x1)\n      hence \"ct_suffix x1 (to_ct_list t1s)\"\n        using assms(3)\n        by simp\n      thus ?thesis\n        using assms(2) ctm_def2\n      proof (cases prods)\n        case (TopType x1)\n        thus ?thesis\n          using consume_c_types_agree[OF t_int_def assms(3)] ctm_def2 assms(4) c_s_def\n          by (metis c_types_agree.elims(2) produce.simps(3,4) type_update.simps)\n      next\n        case (Type x2)\n        hence ctm_def3:\"ctm = Type ((take (length t1s - length cons) t1s)@ x2)\"\n          using ctm_def2\n          by simp\n        have \"ct_suffix x1 cons \\<or> ct_suffix cons x1\"\n          using ct_suffix_shared assms(3) TopType cons_suffix\n          by auto\n        thus ?thesis\n        proof (rule disjE)\n          assume \"ct_suffix x1 cons\"\n          hence \"consume (TopType x1) cons = TopType []\"\n            by (simp add: ct_suffix_length)\n          hence \"check_single \\<C> e ctn = TopType (to_ct_list x2)\"\n            using c_s_def TopType Type\n            by simp\n          thus ?thesis\n            using TopType ctm_def3 assms(4) c_types_agree_top2 ct_list_eq_refl\n            by auto\n        next\n          assume \"ct_suffix cons x1\"\n          hence 4:\"consume (TopType x1) cons = TopType (take (length x1 - length cons ) x1)\"\n            by (simp add: ct_suffix_length)\n          hence 3:\"check_single \\<C> e ctn = TopType ((take (length x1 - length cons ) x1) @ to_ct_list x2)\"\n            using c_s_def TopType Type\n            by simp\n          have \"((take (length t1s - length cons ) t1s) @  x2) = t2s\"\n            using assms(4) ctm_def3\n            by simp\n          have \"c_types_agree (TopType (take (length x1 - length cons ) x1)) (take (length t1s - length cons) t1s)\"\n            using consume_c_types_agree[OF t_int_def assms(3)] 4 TopType\n            by simp\n          hence \"c_types_agree (TopType (take (length x1 - length cons ) x1 @ to_ct_list x2)) (take (length t1s - length cons) t1s @ x2)\"\n            unfolding c_types_agree.simps to_ct_list_def\n            by (simp add: ct_suffix_cons2 ct_suffix_cons_it ct_suffix_extend_ct_list_eq)\n          thus ?thesis\n            using ctm_def3 assms 3\n            by simp\n        qed\n      qed simp\n    next\n      case (Type x2)\n      thus ?thesis\n        using assms\n        by simp\n    next\n      case Bot\n      thus ?thesis\n        using assms\n        by simp\n    qed\n  qed\nqed\n\nlemma b_e_type_checker_compose:\n  assumes \"b_e_type_checker \\<C> es (t1s _> t2s)\"\n          \"b_e_type_checker \\<C> [e] (t2s _> t3s)\"\n  shows \"b_e_type_checker \\<C> (es @ [e]) (t1s _> t3s)\"\nproof -\n  have \"c_types_agree (check_single \\<C> e (Type t2s)) t3s\"\n    using assms(2)\n    by simp\n  then obtain ctm where ctm_def:\"check_single \\<C> e (Type t2s) = ctm\"\n                                \"c_types_agree ctm t3s\"\n                                \"ctm \\<noteq> Bot\"\n    by fastforce\n  have \"c_types_agree (check \\<C> es (Type t1s)) t2s\"\n    using assms(1)\n    by simp\n  then obtain ctn where ctn_def:\"check \\<C> es (Type t1s) = ctn\"\n                                \"c_types_agree ctn t2s\"\n                                \"ctn \\<noteq> Bot\"\n    by fastforce\n  thus ?thesis\n    using check_single_imp_weakening[OF ctm_def(1,3) ctn_def(2) ctm_def(2)]\n          check_unfold_snoc[of \\<C> es \"(Type t1s)\" e]\n    by simp\nqed\n\nlemma b_e_check_single_type_type:\n  assumes \"check_single \\<C> e xs = (Type tm)\"\n  shows \"\\<exists>tn. xs = (Type tn)\"\nproof -\n  consider (1) \"check_single \\<C> e = id\" \n         | (2) \"check_single \\<C> e = (\\<lambda>ctn. type_update_select ctn)\"\n         | (3) \"(\\<exists>cons prods. (check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)))\"\n    using check_single_imp assms\n    by blast\n  thus ?thesis\n  proof (cases)\n    case 1\n    thus ?thesis\n      using assms\n      by simp\n  next\n    case 2\n    note outer_2 = 2\n    thus ?thesis\n      using assms\n    proof (cases xs)\n      case (TopType x1)\n      consider\n          (1) \"length x1 = 0\"\n        | (2) \"length x1 = Suc 0\"\n        | (3) \"length x1 = Suc (Suc 0)\"\n        | (4) \"length x1 \\<ge> 3\"\n        by linarith\n      thus ?thesis\n      proof cases\n        case 1\n        thus ?thesis\n          using assms 2 TopType\n          by simp\n      next\n        case 2\n        thus ?thesis\n          using assms outer_2 TopType produce_type_type\n          by fastforce\n      next\n        case 3\n        thus ?thesis\n          using assms 2 TopType\n          by (simp, metis checker_type.distinct(1) checker_type.distinct(5))\n      next\n        case 4\n        then obtain nat where nat_def:\"length x1 = Suc (Suc (Suc nat))\"\n          by (metis add_eq_if diff_Suc_1 le_Suc_ex numeral_3_eq_3 nat.distinct(2))\n        thus ?thesis\n          using assms 2 TopType\n        proof -\n          {\n            assume a1: \"produce (if ct_suffix [TAny, TAny, TSome T_i32] x1 then TopType (take (length x1 - length [TAny, TAny, TSome T_i32]) x1) else if ct_suffix x1 [TAny, TAny, TSome T_i32] then TopType [] else Bot) (select_return_top x1 (x1 ! Suc nat) (x1 ! nat)) = Type tm\"\n            obtain tts :: \"checker_type \\<Rightarrow> t list\" where\n              f2: \"\\<forall>c. (\\<forall>ca ts. produce c ca \\<noteq> Type ts) \\<or> c = Type (tts c)\"\n              using produce_type_type by moura\n            then have f3: \"\\<And>ts. \\<not> ct_suffix [TAny, TAny, TSome T_i32] x1 \\<or> Type tm \\<noteq> Type ts\"\n              using a1 by fastforce\n            then have \"\\<And>ts. \\<not> ct_suffix x1 [TAny, TAny, TSome T_i32] \\<or> Type tm \\<noteq> Type ts\"\n              using f2 a1 by fastforce\n            then have False\n              using f3 a1 by fastforce\n          }\n          thus ?thesis\n            using assms 2 TopType nat_def\n            by simp\n        qed\n      qed\n    qed simp_all\n  next\n    case 3\n    then obtain cons prods where check_def:\"check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)\"\n      by blast\n    hence \"produce (consume xs cons) prods = (Type tm)\"\n      using assms(1)\n      by simp\n    thus ?thesis\n      using assms check_def consume_type_type produce_type_type\n      by blast\n  qed\nqed\n\nlemma b_e_check_single_weaken_type:\n  assumes \"check_single \\<C> e (Type tn) = (Type tm)\"\n  shows \"check_single \\<C> e (Type (ts@tn)) = Type (ts@tm)\"\nproof -\n  consider (1) \"check_single \\<C> e = id\" \n         | (2) \"check_single \\<C> e = (\\<lambda>ctn. type_update_select ctn)\"\n         | (3) \"(\\<exists>cons prods. (check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)))\"\n    using check_single_imp assms\n    by blast\n  thus ?thesis\n  proof (cases)\n    case 1\n    thus ?thesis\n      using assms(1)\n      by simp\n  next\n    case 2\n    hence cond:\"(length tn \\<ge> 3 \\<and> (tn!(length tn-2)) = (tn!(length tn-3)))\"\n      using assms\n      by (simp, metis checker_type.distinct(5))\n    hence \"consume (Type tn) [TAny, TSome T_i32] = (Type tm)\"\n      using assms 2\n      by simp\n    hence \"consume (Type (ts@tn)) [TAny, TSome T_i32] = (Type (ts@tm))\"\n      using consume_weaken_type\n      by blast\n    moreover\n    have \"(length (ts@tn) \\<ge> 3 \\<and> ((ts@tn)!(length (ts@tn)-2)) = ((ts@tn)!(length (ts@tn)-3)))\"\n      using cond\n      by (simp, metis add.commute add_leE nth_append_length_plus numeral_Bit1 numeral_One\n                      one_add_one ordered_cancel_comm_monoid_diff_class.diff_add_assoc2)\n    ultimately\n    show ?thesis\n      using 2\n      by simp\n  next\n    case 3\n    then obtain cons prods where check_def:\"check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)\"\n      by blast\n    hence \"produce (consume (Type tn) cons) prods = (Type tm)\"\n      using assms(1)\n      by simp\n    then obtain t_int where t_int_def:\"consume (Type tn) cons = (Type t_int)\"\n      by (metis consume.simps(1) produce.simps(6))\n    thus ?thesis\n      using assms(1) check_def\n            consume_weaken_type[OF t_int_def, of ts]\n            produce_weaken_type[of t_int prods tm ts]\n      by simp\n  qed\nqed\n\nlemma b_e_check_single_weaken_top:\n  assumes \"check_single \\<C> e (Type tn) = TopType tm\"\n  shows \"check_single \\<C> e (Type (ts@tn)) = TopType tm\"\nproof -\n  consider (1) \"check_single \\<C> e = id\" \n         | (2) \"check_single \\<C> e = (\\<lambda>ctn. type_update_select ctn)\"\n         | (3) \"(\\<exists>cons prods. (check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)))\"\n    using check_single_imp assms\n    by blast\n  thus ?thesis\n  proof (cases)\n    case 1\n    thus ?thesis\n      using assms\n      by simp\n  next\n    case 2\n    thus ?thesis\n      using assms\n      by (simp, metis checker_type.distinct(1) checker_type.distinct(3) consume.simps(1))\n  next\n    case 3\n    then obtain cons prods where check_def:\"check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)\"\n      by blast\n    hence \"produce (consume (Type tn) cons) prods = (TopType tm)\"\n      using assms(1)\n      by simp\n    moreover\n    then obtain t_int where t_int_def:\"consume (Type tn) cons = (Type t_int)\"\n      by (metis checker_type.distinct(3) consume.simps(1) produce.simps(6))\n    ultimately\n    show ?thesis\n      using check_def consume_weaken_type\n      by (cases prods, auto)\n  qed\nqed\n\nlemma b_e_check_weaken_type:\n  assumes \"check \\<C> es (Type tn) = (Type tm)\"\n  shows \"check \\<C> es (Type (ts@tn)) = (Type (ts@tm))\"\n  using assms\nproof (induction es arbitrary: tn tm rule: List.rev_induct)\n  case Nil\n  thus ?case\n    by simp\nnext\n  case (snoc e es)\n  hence \"check_single \\<C> e (check \\<C> es (Type tn)) = Type tm\"\n    using check_unfold_snoc[OF check_neq_bot_snoc]\n    by (metis checker_type.distinct(5))\n  thus ?case\n    using b_e_check_single_weaken_type b_e_check_single_type_type snoc\n    by (metis check_unfold_snoc checker_type.distinct(5))\nqed\n\nlemma check_bot: \"check \\<C> es Bot = Bot\"\n  by (simp add: list.case_eq_if)\n\nlemma b_e_check_weaken_top:\n  assumes \"check \\<C> es (Type tn) = (TopType tm)\"\n  shows \"check \\<C> es (Type (ts@tn)) = (TopType tm)\"\n  using assms\nproof (induction es arbitrary: tn tm)\n  case Nil\n  thus ?case\n    by simp\nnext\n  case (Cons e es)\n  show ?case\n  proof (cases \"(check_single \\<C> e (Type tn))\")\n    case (TopType x1)\n    hence \"check_single \\<C> e (Type (ts@tn)) = TopType x1\"\n      using b_e_check_single_weaken_top\n      by blast\n    thus ?thesis\n      using TopType Cons\n      by simp\n  next\n    case (Type x2)\n    hence \"check_single \\<C> e (Type (ts@tn)) = Type (ts@x2)\"\n      using b_e_check_single_weaken_type\n      by blast\n    thus ?thesis\n      using Cons Type\n      by fastforce\n  next\n    case Bot\n    thus ?thesis\n      using check_bot Cons\n      by simp\n  qed\n  \nqed\n\nlemma b_e_type_checker_weaken:\n  assumes \"b_e_type_checker \\<C> es (t1s _> t2s)\"\n  shows \"b_e_type_checker \\<C> es (ts@t1s _> ts@t2s)\"\nproof -\n  have \"c_types_agree (check \\<C> es (Type t1s)) t2s\"\n    using assms(1)\n    by simp\n  then obtain ctn where ctn_def:\"check \\<C> es (Type t1s) = ctn\"\n                                \"c_types_agree ctn t2s\"\n                                \"ctn \\<noteq> Bot\"\n    by fastforce\n  show ?thesis\n  proof (cases ctn)\n    case (TopType x1)\n    thus ?thesis\n      using ctn_def(1,2) b_e_check_weaken_top[of \\<C> es t1s x1 ts]\n      by (metis append_assoc b_e_type_checker.simps c_types_agree_imp_ct_list_eq c_types_agree_top2)\n  next\n    case (Type x2)\n    thus ?thesis\n      using ctn_def(1,2) b_e_check_weaken_type[of \\<C> es t1s x2 ts]\n      by simp\n  next\n    case Bot\n    thus ?thesis\n      using ctn_def(3)\n      by simp\n  qed\nqed\n\nlemma b_e_type_checker_complete:\n  assumes \"\\<C> \\<turnstile> es : (tn _> tm)\"\n  shows \"b_e_type_checker \\<C> es (tn _> tm)\"\n  using assms\nproof (induction es \"(tn _> tm)\" arbitrary: tn tm rule: b_e_typing.induct)\n  case (select \\<C> t)\n  have \"ct_list_eq [TAny, TSome T_i32] [TSome t, TSome T_i32]\"\n    by (simp add: to_ct_list_def ct_list_eq_def)\n  thus ?case\n    using ct_suffix_extend_ct_list_eq[OF ct_suffix_nil[of \"[TSome t]\"]] to_ct_list_def\n    by auto\nnext\n  case (br_table \\<C> ts \"is\" i t1s t2s)\n  show ?case\n    using list_all_conv_same_lab[OF br_table]\n    by (auto simp add: to_ct_list_def ct_suffix_nil ct_suffix_cons_it)\nnext\n  case (set_global i \\<C> t)\n  thus ?case\n    using to_ct_list_def ct_suffix_refl is_mut_def tg_t_def\n    by auto\nnext\n  case (composition \\<C> es t1s t2s e t3s)\n  thus ?case\n    using b_e_type_checker_compose\n    by simp\nnext\n  case (weakening \\<C> es t1s t2s ts)\n  thus ?case\n    using b_e_type_checker_weaken\n    by simp\nqed (auto simp add: to_ct_list_def ct_suffix_refl ct_suffix_nil ct_suffix_cons_it\n                    ct_suffix_singleton_any)\n\ntheorem b_e_typing_equiv_b_e_type_checker:\n  shows \"(\\<C> \\<turnstile> es : tf) = (b_e_type_checker \\<C> es tf)\"\n  using b_e_type_checker_sound b_e_type_checker_complete\n  by (metis tf.exhaust)\n\nend\n", "meta": {"author": "conrad-watt", "repo": "wasm-pl-isabelle", "sha": "265f292250c01770d50d4ecda998ed5961c6719e", "save_path": "github-repos/isabelle/conrad-watt-wasm-pl-isabelle", "path": "github-repos/isabelle/conrad-watt-wasm-pl-isabelle/wasm-pl-isabelle-265f292250c01770d50d4ecda998ed5961c6719e/WebAssembly/Wasm_Checker_Properties.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621765008857982, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.2788922931629974}}
{"text": "\ntext\\<open>Facts about eta normalization involving theories\\<close>\n\ntheory EtaNormProof\n  imports EtaNorm Theory\n  (* This means I need to restructure *)\n  BetaNormProof\nbegin\n\nlemma term_ok'_decr: \"term_ok' \\<Sigma> t \\<Longrightarrow> term_ok' \\<Sigma> (decr i t)\"\n  by (induction i t rule: decr.induct) auto\n\nlemma eta_preserves_term_ok': \"term_ok' \\<Sigma> r \\<Longrightarrow> r \\<rightarrow>\\<^sub>\\<eta> s \\<Longrightarrow> term_ok' \\<Sigma> s\"\nproof (induction r arbitrary: s)\n  case (Ct n T)\n  then show ?case \n    apply (simp add: tinstT_def split: option.splits)\n    (* Seems like I miss a simp rule for Ct*)\n    using eta_reducible.simps(12) eta_step_imp_eta_reducible by blast\nnext\n  case (Fv n T)\n  then show ?case\n    using eta.cases \n    by blast\nnext\n  case (Bv n)\n  then show ?case \n    by auto\nnext\n  case (Abs R r)\n  then show ?case \n    using eta.cases \n    by (fastforce simp add: term_ok'_decr)\nnext\n  case (App f u)\n  then show ?case \n    apply - \n    apply (erule eta_cases(2)) \n    using term_ok'.simps(4) by blast+\nqed\n\nlemma eta_preserves_term_ok: \"term_ok \\<Theta> r \\<Longrightarrow> r \\<rightarrow>\\<^sub>\\<eta> s \\<Longrightarrow> term_ok \\<Theta> s\"\nproof -\n  assume a1: \"term_ok \\<Theta> r\"\n  assume a2: \"r \\<rightarrow>\\<^sub>\\<eta> s\"\n  then have \"None \\<noteq> typ_of1 [] s\"\n    using a1 eta_preserves_typ_of1 option.collapse wt_term_def typ_of_def \n    by auto\n  then show ?thesis\n    using a2 a1 eta_preserves_term_ok' wt_term_def typ_of_def wf_term_iff_term_ok' term_ok_def\n    by (meson eta_preserves_typ_of has_typ_iff_typ_of)\nqed\n\nlemma eta_star_preserves_term_ok': \"r \\<rightarrow>\\<^sub>\\<eta>\\<^sup>* s \\<Longrightarrow> term_ok' \\<Sigma> r  \\<Longrightarrow> term_ok' \\<Sigma> s\"\n  by (induction rule: rtranclp.induct) (auto simp add: eta_preserves_term_ok')\n\ncorollary eta_star_preserves_term_ok: \"r \\<rightarrow>\\<^sub>\\<eta>\\<^sup>* s \\<Longrightarrow> term_ok thy r  \\<Longrightarrow> term_ok thy s\"\n  using eta_star_preserves_term_ok' eta_star_preserves_typ_of1 wt_term_def typ_of_def by auto\n                     \ncorollary term_ok_eta_norm: \"term_ok thy t \\<Longrightarrow> eta_norm t = t'\\<Longrightarrow> term_ok thy t'\"\n  using eta_norm_imp_eta_reds eta_star_preserves_term_ok by blast\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Metalogic_ProofChecker/EtaNormProof.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185351961015, "lm_q2_score": 0.4921881357207955, "lm_q1q2_score": 0.27858760762158463}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      ClosureEx.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2006-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\ntheory ClosureEx\nimports \"../Vcg\" \"../Simpl_Heap\" Closure\nbegin\n\n\nrecord globals = \n cnt_' :: \"ref \\<Rightarrow> nat\"\n alloc_' :: \"ref list\"\n free_' :: \"nat\"\nrecord 'g vars = \"'g state\" +\n p_':: ref\n r_':: nat\n n_':: nat\n m_':: nat\n c_':: \"(string \\<times> ref) list \\<times> string\"\n d_':: \"(string \\<times> ref) list \\<times> string\"\n e_':: \"(string \\<times> nat) list \\<times> string\"\n\n\ndefinition \"var\\<^sub>n = [''n''\\<mapsto> (\\<lambda>x. n_'_update (\\<lambda>_. x)),\n                    ''m''\\<mapsto> (\\<lambda>x. m_'_update (\\<lambda>_. x))]\"\ndefinition \"upd\\<^sub>n = gen_upd var\\<^sub>n\"\n\nlemma upd\\<^sub>n_ap: \"upd\\<^sub>n (fst (ap es (es',p))) = upd\\<^sub>n es' \\<circ> upd\\<^sub>n es\"\n  by (simp add: upd\\<^sub>n_def gen_upd_ap)\n\n\nlemma\n\"\\<Gamma>\\<turnstile>\\<lbrace>\\<acute>n=n\\<^sub>0 \\<and> (\\<forall>i j. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>n=i \\<and> \\<acute>m=j\\<rbrace> callClosure upd\\<^sub>n \\<acute>e \\<lbrace>\\<acute>r=i + j\\<rbrace>)\\<rbrace> \n      \\<acute>e :== (ap [(''n'',\\<acute>n)] \\<acute>e) \n   \\<lbrace>\\<forall>j. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>m=j\\<rbrace> callClosure upd\\<^sub>n \\<acute>e \\<lbrace>\\<acute>r=n\\<^sub>0 + j\\<rbrace>\\<rbrace>\"\napply vcg_step\napply clarify\napply (rule ap_closure [where var=var\\<^sub>n, folded upd\\<^sub>n_def])\napply clarsimp\napply (rename_tac s s')\napply (erule_tac x=\"n_' s\" in allE) \napply (erule_tac x=\"m_' s'\" in allE) \napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply (assumption)\napply (simp add: upd\\<^sub>n_def gen_upd_def var\\<^sub>n_def)\ndone\n\n\ndefinition \"var = [''p''\\<mapsto> (\\<lambda>x. p_'_update (\\<lambda>_. x))]\"\ndefinition \"upd = gen_upd var\"\n\nprocedures Inc(p|r) =\n \"\\<acute>p\\<rightarrow>\\<acute>cnt :== \\<acute>p\\<rightarrow>\\<acute>cnt + 1;;\n  \\<acute>r :== \\<acute>p\\<rightarrow>\\<acute>cnt\"\n\nlemma (in Inc_impl)\n \"\\<forall>i p. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>p\\<rightarrow>\\<acute>cnt = i\\<rbrace> \\<acute>r :== PROC Inc(\\<acute>p) \\<lbrace>\\<acute>r=i+1 \\<and> \\<acute>p\\<rightarrow>\\<acute>cnt = i+1\\<rbrace>\"\n  apply vcg\n  apply simp\n  done\n  \nprocedures (imports Inc_signature) NewCounter(|c) =\n\"\\<acute>p :== NEW 1 [\\<acute>cnt :== 0];;\n \\<acute>c :== ([(''p'',\\<acute>p)],Inc_'proc)\" \n\n\nlocale NewCounter_impl' = NewCounter_impl + Inc_impl\nlemma (in NewCounter_impl')\nshows \n  \"\\<forall>alloc. \\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free\\<rbrace> \\<acute>c :== PROC NewCounter() \n          \\<lbrace>\\<exists>p. p\\<rightarrow>\\<acute>cnt = 0 \\<and>\n               (\\<forall>i. \\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = i\\<rbrace> callClosure upd \\<acute>c \\<lbrace>\\<acute>r=i+1 \\<and> p\\<rightarrow>\\<acute>cnt = i+1\\<rbrace>)\\<rbrace>\"\napply vcg\napply simp\napply (rule_tac x=\"new (set alloc)\" in exI)\napply simp\napply (simp add: callClosure_def)\napply vcg_step\napply vcg_step\napply vcg_step\napply vcg_step\napply (simp add: upd_def var_def gen_upd_def)\ndone\n\nlemma (in NewCounter_impl')\n\nshows \n  \"\\<forall>alloc. \\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free\\<rbrace> \\<acute>c :== PROC NewCounter() \n          \\<lbrace>\\<exists>p. p\\<rightarrow>\\<acute>cnt = 0 \\<and>\n               (\\<forall>i. \\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = i\\<rbrace> callClosure upd \\<acute>c \\<lbrace>\\<acute>r=i+1 \\<and> p\\<rightarrow>\\<acute>cnt = i+1\\<rbrace>)\\<rbrace>\"\napply vcg\napply simp\napply (rule_tac x=\"new (set alloc)\" in exI)\napply simp\napply (simp add: callClosure_def)\napply vcg_step\napply vcg_step\napply vcg_step\napply vcg_step\napply (simp add: upd_def var_def gen_upd_def)\ndone\n\nlemma (in NewCounter_impl')\nshows NewCounter_spec:\n  \"\\<forall>alloc. \\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free \\<and> \\<acute>alloc=alloc\\<rbrace> \\<acute>c :== PROC NewCounter() \n          \\<lbrace>\\<exists>p. p \\<notin> set alloc \\<and> p \\<in> set \\<acute>alloc \\<and> p \\<noteq> Null \\<and> p\\<rightarrow>\\<acute>cnt = 0 \\<and>\n               (\\<forall>i. \\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = i\\<rbrace> callClosure upd \\<acute>c \\<lbrace>\\<acute>r=i+1 \\<and> p\\<rightarrow>\\<acute>cnt = i+1\\<rbrace>)\\<rbrace>\"\napply vcg\napply clarsimp\napply (rule_tac x=\"new (set alloc)\" in exI)\napply simp\napply (simp add: callClosure_def)\napply vcg_step\napply vcg_step\napply vcg_step\napply vcg_step\napply (simp add: upd_def var_def gen_upd_def)\ndone\n\n\n\nlemma \"\\<Gamma>\\<turnstile>\\<lbrace>\\<exists>p. p \\<noteq> Null \\<and> p\\<rightarrow>\\<acute>cnt = i \\<and>\n              (\\<forall>i. \\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = i\\<rbrace> callClosure upd \\<acute>c \\<lbrace>\\<acute>r=i+1 \\<and> p\\<rightarrow>\\<acute>cnt = i+1\\<rbrace>)\\<rbrace>\n           dynCallClosure (\\<lambda>s. s) upd c_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>) \n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>r_' := r_' t\\<rparr>))\n           \\<lbrace>\\<acute>r=i+1\\<rbrace>\"\napply (rule conseq_extract_pre)\napply clarify\napply (rule dynCallClosureFix)\napply (simp only: Ball_def)\nprefer 3\napply (assumption)\nprefer 2\napply vcg_step\napply vcg_step\napply (simp only: simp_thms)\napply clarsimp\ndone\n\nlemma (in NewCounter_impl')\n shows \"\\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free\\<rbrace> \n             \\<acute>c :== CALL NewCounter ();;\n             dynCallClosure (\\<lambda>s. s) upd c_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>) \n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>r_' := r_' t\\<rparr>))\n           \\<lbrace>\\<acute>r=1\\<rbrace>\"\napply vcg_step\napply (rule dynCallClosure)\nprefer 2\napply vcg_step\napply vcg_step\napply vcg_step\napply clarsimp\napply (erule_tac x=0 in allE)\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply (assumption)\napply simp\ndone\n\n\nlemma (in NewCounter_impl')\n shows \"\\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free\\<rbrace> \n             \\<acute>c :== CALL NewCounter ();;\n             dynCallClosure (\\<lambda>s. s) upd c_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>) \n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>r_' := r_' t\\<rparr>));;\n             dynCallClosure (\\<lambda>s. s) upd c_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>) \n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>r_' := r_' t\\<rparr>))\n           \\<lbrace>\\<acute>r=2\\<rbrace>\"\napply vcg_step\napply (rule dynCallClosure)\nprefer 2\napply vcg_step\napply vcg_step\napply vcg_step\napply (rule dynCallClosure)\napply vcg_step\napply vcg_step\napply vcg_step\n\napply clarsimp\napply (subgoal_tac \"\\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = 0\\<rbrace> callClosure upd (c_' t) \\<lbrace>\\<acute>r = Suc 0 \\<and> p\\<rightarrow>\\<acute>cnt = Suc 0\\<rbrace>\")\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply assumption\napply clarsimp\napply (erule_tac x=1 in allE)\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply assumption\napply clarsimp\napply (erule allE)\napply assumption\ndone\n\n\nlemma (in NewCounter_impl')\n shows \"\\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free\\<rbrace> \n             \\<acute>c :== CALL NewCounter ();;\n             \\<acute>d :== \\<acute>c;;\n             dynCallClosure (\\<lambda>s. s) upd c_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>) \n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>n_' := r_' t\\<rparr>));;\n             dynCallClosure (\\<lambda>s. s) upd d_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>) \n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>m_' := r_' t\\<rparr>));;\n             \\<acute>r :== \\<acute>n + \\<acute>m\n           \\<lbrace>\\<acute>r=3\\<rbrace>\"\n\napply vcg_step\napply vcg_step\napply (rule dynCallClosure)\nprefer 2\napply vcg_step\napply vcg_step\napply vcg_step\napply (rule dynCallClosure)\napply vcg_step\napply vcg_step\napply vcg_step\napply vcg_step\napply clarsimp\napply (subgoal_tac \"\\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = 0\\<rbrace> callClosure upd (c_' t) \\<lbrace>\\<acute>r = Suc 0 \\<and> p\\<rightarrow>\\<acute>cnt = Suc 0\\<rbrace>\")\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply assumption\napply clarsimp\napply (erule_tac x=1 in allE)\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply assumption\napply clarsimp\napply (erule allE)\napply assumption\ndone\n\nend\n", "meta": {"author": "LVPGroup", "repo": "TimSort", "sha": "16437b6b6e2df9f6d32b2a32be7d0d650d83f980", "save_path": "github-repos/isabelle/LVPGroup-TimSort", "path": "github-repos/isabelle/LVPGroup-TimSort/TimSort-16437b6b6e2df9f6d32b2a32be7d0d650d83f980/Simpl/ex/ClosureEx.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185205547239, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.27858760041527236}}
{"text": "(*  Title:      JinjaThreads/Common/Value.thy\n    Author:     David von Oheimb, Tobias Nipkow, Andreas Lochbihler\n\n    Based on the Jinja theory Common/Value.thy by David von Oheimb and Tobias Nipkow\n\n*)\n\nheader {* \\isaheader{Jinja Values} *}\n\ntheory Value\nimports\n  TypeRel\n  \"~~/src/HOL/Word/Word\"\nbegin\n\ntype_synonym word32 = \"32 word\"\n\ndatatype 'addr val\n  = Unit          -- \"dummy result value of void expressions\"\n  | Null          -- \"null reference\"\n  | Bool bool     -- \"Boolean value\"\n  | Intg word32   -- \"integer value\" \n  | Addr 'addr    -- \"addresses of objects, arrays and threads in the heap\"\n\nprimrec default_val :: \"ty \\<Rightarrow> 'addr val\"   -- \"default value for all types\"\nwhere\n  \"default_val Void      = Unit\"\n| \"default_val Boolean   = Bool False\"\n| \"default_val Integer   = Intg 0\"\n| \"default_val NT        = Null\"\n| \"default_val (Class C) = Null\"\n| \"default_val (Array A) = Null\"\n\nlemma default_val_not_Addr: \"default_val T \\<noteq> Addr a\"\nby(cases T)(simp_all)\n\nlemma Addr_not_default_val: \"Addr a \\<noteq> default_val T\"\nby(cases T)(simp_all)\n\nprimrec the_Intg :: \"'addr val \\<Rightarrow> word32\"\nwhere\n  \"the_Intg (Intg i) = i\"\n\nprimrec the_Addr :: \"'addr val \\<Rightarrow> 'addr\"\nwhere\n  \"the_Addr (Addr a) = a\"\n\nfun is_Addr :: \"'addr val \\<Rightarrow> bool\"\nwhere\n  \"is_Addr (Addr a) = True\"\n| \"is_Addr _        = False\"\n\nlemma is_AddrE [elim!]:\n  \"\\<lbrakk> is_Addr v; \\<And>a. v = Addr a \\<Longrightarrow> thesis \\<rbrakk> \\<Longrightarrow> thesis\"\nby(cases v, auto)\n\nfun is_Intg :: \"'addr val \\<Rightarrow> bool\"\nwhere\n  \"is_Intg (Intg i) = True\"\n| \"is_Intg _        = False\"\n\nlemma is_IntgE [elim!]:\n  \"\\<lbrakk> is_Intg v; \\<And>i. v = Intg i \\<Longrightarrow> thesis \\<rbrakk> \\<Longrightarrow> thesis\"\nby(cases v, auto)\n\nfun is_Bool :: \"'addr val \\<Rightarrow> bool\"\nwhere\n  \"is_Bool (Bool b) = True\"\n| \"is_Bool _        = False\"\n\nlemma is_BoolE [elim!]:\n  \"\\<lbrakk> is_Bool v; \\<And>a. v = Bool a \\<Longrightarrow> thesis \\<rbrakk> \\<Longrightarrow> thesis\"\nby(cases v, auto)\n\ndefinition is_Ref :: \"'addr val \\<Rightarrow> bool\"\nwhere \"is_Ref v \\<equiv> v = Null \\<or> is_Addr v\"\n\nlemma is_Ref_def2:\n  \"is_Ref v = (v = Null \\<or> (\\<exists>a. v = Addr a))\"\n  by (cases v) (auto simp add: is_Ref_def)\n\n\n\ndefinition undefined_value :: \"'addr val\" where \"undefined_value = Unit\"\n\nlemma undefined_value_not_Addr: \n  \"undefined_value \\<noteq> Addr a\" \"Addr a \\<noteq> undefined_value\"\nby(simp_all add: undefined_value_def)\n\nclass addr =\n  fixes hash_addr :: \"'a \\<Rightarrow> int\"\n  and monitor_finfun_to_list :: \"('a \\<Rightarrow>f nat) \\<Rightarrow> 'a list\"\n  assumes \"set (monitor_finfun_to_list f) = Collect (op $ (finfun_dom f))\"\n\nlocale addr_base =\n  fixes addr2thread_id :: \"'addr \\<Rightarrow> 'thread_id\"\n  and thread_id2addr :: \"'thread_id \\<Rightarrow> 'addr\"\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/JinjaThreads/Common/Value.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318479832804, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.2784227154813871}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory PackedTypes\nimports \"../../lib/$L4V_ARCH/WordSetup\" CProof\nbegin\n\nsection {* Underlying definitions for the class axioms *}\n\ntext {* field_access / field_update is the identity for packed types *}\n\ndefinition\n  \"fa_fu_idem fd n \\<equiv>\n  \\<forall>bs bs' v. length bs = n \\<longrightarrow> length bs' = n \\<longrightarrow> field_access fd (field_update fd bs v) bs' = bs\"\n\n(* Is it better to do this or to use a fold over td?  This seems easier to use *)\nprimrec\n  td_fafu_idem :: \"'a field_desc typ_desc \\<Rightarrow> bool\" and\n  td_fafu_idem_struct :: \"'a field_desc typ_struct \\<Rightarrow> bool\" and\n  td_fafu_idem_list :: \" ('a field_desc typ_desc, char list) dt_pair list \\<Rightarrow> bool\" and\n  td_fafu_idem_pair :: \"('a field_desc typ_desc, char list) dt_pair \\<Rightarrow> bool\"\nwhere\n  fai0: \"td_fafu_idem (TypDesc ts n) = td_fafu_idem_struct ts\"\n\n| fai1: \"td_fafu_idem_struct (TypScalar n algn d) = fa_fu_idem d n\"\n| fai2: \"td_fafu_idem_struct (TypAggregate ts) = td_fafu_idem_list ts\"\n\n| fai3: \"td_fafu_idem_list [] = True\"\n| fai4: \"td_fafu_idem_list (x#xs) = (td_fafu_idem_pair x \\<and> td_fafu_idem_list xs)\"\n\n| fai5: \"td_fafu_idem_pair (DTPair x n) = td_fafu_idem x\"\n\nlemmas td_fafu_idem_simps = fai0 fai1 fai2 fai3 fai4 fai5\n\ntext {* field_access is independent of the underlying bytes *}\n\ndefinition\n  \"fa_heap_indep fd n \\<equiv>\n  \\<forall>bs bs' v. length bs = n \\<longrightarrow> length bs' = n \\<longrightarrow> field_access fd v bs = field_access fd v bs'\"\n\n\nprimrec\n  td_fa_hi :: \"'a field_desc typ_desc \\<Rightarrow> bool\" and\n  td_fa_hi_struct :: \"'a field_desc typ_struct \\<Rightarrow> bool\" and\n  td_fa_hi_list :: \"('a field_desc typ_desc, char list) dt_pair list \\<Rightarrow> bool\" and\n  td_fa_hi_pair :: \"('a field_desc typ_desc, char list) dt_pair \\<Rightarrow> bool\"\nwhere\n  fahi0: \"td_fa_hi (TypDesc ts n) = td_fa_hi_struct ts\"\n\n| fahi1: \"td_fa_hi_struct (TypScalar n algn d) = fa_heap_indep d n\"\n| fahi2: \"td_fa_hi_struct (TypAggregate ts) = td_fa_hi_list ts\"\n\n| fahi3: \"td_fa_hi_list [] = True\"\n| fahi4: \"td_fa_hi_list (x#xs) = (td_fa_hi_pair x \\<and> td_fa_hi_list xs)\"\n\n| fahi5: \"td_fa_hi_pair (DTPair x n) = td_fa_hi x\"\n\nlemmas td_fa_hi_simps = fahi0 fahi1 fahi2 fahi3 fahi4 fahi5\n\nsection {* Lemmas about td_fafu_idem *}\n\nlemma field_lookup_td_fafu_idem:\n  shows \"\\<And>(s :: 'a field_desc typ_desc) f m n. \\<lbrakk> field_lookup t f m = Some (s, n); td_fafu_idem t \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  and   \"\\<And>(s :: 'a field_desc typ_desc) f m n. \\<lbrakk> field_lookup_struct st f m = Some (s, n); td_fafu_idem_struct st \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  and   \"\\<And>(s :: 'a field_desc typ_desc) f m n. \\<lbrakk> field_lookup_list ts f m = Some (s, n); td_fafu_idem_list ts \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  and   \"\\<And>(s :: 'a field_desc typ_desc) f m n. \\<lbrakk> field_lookup_pair p f m = Some (s, n); td_fafu_idem_pair p \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  by (induct t and st and ts and p) (auto split: if_split_asm option.splits)\n\nlemma field_access_update_same:\n  fixes t :: \"'a :: mem_type field_desc typ_desc\" and st :: \"'a field_desc typ_struct\"\n  shows \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem t; wf_fd t; length bs = size_td t; length bs' = size_td t\\<rbrakk>\n  \\<Longrightarrow> access_ti t (update_ti t bs v) bs' = bs\"\n  and \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem_struct st; wf_fd_struct st; length bs = size_td_struct st; length bs' = size_td_struct st \\<rbrakk>\n  \\<Longrightarrow> access_ti_struct st (update_ti_struct st bs v) bs' = bs\"\n  and \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem_list ts; wf_fd_list ts; length bs = size_td_list ts; length bs' = size_td_list ts\\<rbrakk>\n  \\<Longrightarrow> access_ti_list ts (update_ti_list ts bs v) bs' = bs\"\n  and \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem_pair p; wf_fd_pair p; length bs = size_td_pair p; length bs' = size_td_pair p\\<rbrakk>\n  \\<Longrightarrow> access_ti_pair p (update_ti_pair p bs v) bs' = bs\"\nproof (induct t and st and ts and p)\n  case TypScalar thus ?case by (clarsimp simp: fa_fu_idem_def)\nnext\n  case (Cons_typ_desc p' ts' v bs bs')\n  hence \"fu_commutes (update_ti_pair_t p') (update_ti_list_t ts')\" by clarsimp\n  moreover have \"update_ti_pair p' (take (size_td_pair p') bs) = update_ti_pair_t p' (take (size_td_pair p') bs)\"\n    using Cons_typ_desc.prems by (simp add: update_ti_pair_t_def min_ll)\n  moreover have \"update_ti_list ts' (drop (size_td_pair p') bs) = update_ti_list_t ts' (drop (size_td_pair p') bs)\"\n    using Cons_typ_desc.prems by (simp add: update_ti_list_t_def)\n  ultimately have\n    updeq: \"(update_ti_pair p' (take (size_td_pair p') bs) (update_ti_list ts' (drop (size_td_pair p') bs) v))\n    = (update_ti_list ts' (drop (size_td_pair p') bs) (update_ti_pair p' (take (size_td_pair p') bs) v))\"\n    unfolding fu_commutes_def by simp\n\n  show ?case using Cons_typ_desc.prems\n    by (clarsimp simp add: Cons_typ_desc.hyps) (simp add: updeq  Cons_typ_desc.hyps)\nqed simp+\n\nlemma access_ti_pair_dt_fst:\n  \"access_ti_pair p v bs = access_ti (dt_fst p) v bs\"\n  by (cases p, simp)\n\nlemma size_td_pair_dt_fst:\n  \"size_td_pair p = size_td (dt_fst p)\"\n  by (cases p, simp)\n\nlemma wf_fd_pair_dt_fst:\n  \"wf_fd_pair p = wf_fd (dt_fst p)\"\n  by (cases p, simp)\n\nlemma field_lookup_offset2:\n  assumes fl: \"(field_lookup t f (m + n) = Some (s, q))\"\n  shows   \"field_lookup t f m = Some (s, q - n)\"\nproof -\n  from fl have le: \"m + n \\<le> q\"\n    by (rule field_lookup_offset_le)\n\n  hence \"q = (m + n) + (q - (m + n))\"\n    by simp\n\n  hence \"field_lookup t f (m + n) = Some (s, (m + n) + (q - (m + n)))\" using fl by simp\n\n  hence \"field_lookup t f m = Some (s, m + (q - (m + n)))\"\n    by (rule iffD1 [OF field_lookup_offset'(1)])\n\n  thus ?thesis using le by simp\nqed\n\nlemma field_lookup_offset2_list:\n  assumes fl: \"(field_lookup_list ts f (m + n) = Some (s, q))\"\n  shows   \"field_lookup_list ts f m = Some (s, q - n)\"\nproof -\n  from fl have le: \"m + n \\<le> q\"\n    by (rule field_lookup_offset_le)\n\n  hence \"q = (m + n) + (q - (m + n))\"\n    by simp\n\n  hence \"field_lookup_list ts f (m + n) = Some (s, (m + n) + (q - (m + n)))\" using fl by simp\n\n  hence \"field_lookup_list ts f m = Some (s, m + (q - (m + n)))\"\n    by (rule iffD1 [OF field_lookup_offset'(3)])\n\n  thus ?thesis using le by simp\nqed\n\nlemma field_lookup_offset2_pair:\n  assumes fl: \"(field_lookup_pair p f (m + n) = Some (s, q))\"\n  shows   \"field_lookup_pair p f m = Some (s, q - n)\"\nproof -\n  from fl have le: \"m + n \\<le> q\"\n    by (rule field_lookup_offset_le)\n\n  hence \"q = (m + n) + (q - (m + n))\"\n    by simp\n\n  hence \"field_lookup_pair p f (m + n) = Some (s, (m + n) + (q - (m + n)))\" using fl by simp\n\n  hence \"field_lookup_pair p f m = Some (s, m + (q - (m + n)))\"\n    by (rule iffD1 [OF field_lookup_offset'(4)])\n\n  thus ?thesis using le by simp\nqed\n\nlemma field_lookup_offset_size':\n  shows \"field_lookup t f 0 = Some (t',n) \\<Longrightarrow> size_td t' + n \\<le> size_td t\"\n  apply(drule td_set_field_lookupD)\n  apply(erule td_set_offset_size)\ndone\n\nlemma field_access_update_nth_inner:\n  shows \"\\<And>f (s :: 'a :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk> field_lookup t f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd t;\n  length bs = size_td s; length bs' = size_td t \\<rbrakk>\n  \\<Longrightarrow> access_ti t (update_ti s bs v) bs' ! x = bs ! (x - n)\"\n\n  and \"\\<And>f (s :: 'a  :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk>field_lookup_struct st f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd_struct st;\n  length bs = size_td s; length bs' = size_td_struct st \\<rbrakk>\n  \\<Longrightarrow> access_ti_struct st (update_ti s bs v) bs' ! x = bs ! (x - n)\"\n\n  and \"\\<And>f (s :: 'a  :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk>field_lookup_list ts f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd_list ts;\n  length bs = size_td s; length bs' = size_td_list ts\\<rbrakk>\n  \\<Longrightarrow> access_ti_list ts (update_ti s bs v) bs' ! x = bs ! (x - n)\"\n\n  and \"\\<And>f (s :: 'a  :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk>field_lookup_pair p f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd_pair p;\n  length bs = size_td s; length bs' = size_td_pair p\\<rbrakk>\n  \\<Longrightarrow> access_ti_pair p (update_ti s bs v) bs' ! x = bs ! (x - n)\"\nproof (induct t and st and ts and p)\n  case (TypDesc typ_struct ls f s n x v bs bs')\n\n  show ?case\n  proof (cases \"f = []\")\n    case False thus ?thesis using TypDesc by clarsimp\n  next\n    case True\n    thus ?thesis using TypDesc.prems\n      by (simp add: field_access_update_same)\n  qed\nnext\n  case (Cons_typ_desc p' ts' f s n x v bs bs')\n  have nlex: \"n \\<le> x\" and xln: \"x < n + size_td s\"\n    and lbs: \"length bs = size_td s\" and lbs': \"length bs' = size_td_list (p' # ts')\" by fact+\n  from Cons_typ_desc have wf: \"wf_fd (dt_fst p')\" and wfts: \"wf_fd_list ts'\" by (cases p', auto)\n\n  {\n    assume fl: \"field_lookup_list ts' f (size_td (dt_fst p')) = Some (s, n)\"\n\n    hence mlt: \"size_td (dt_fst p') \\<le> n\"\n      by (rule field_lookup_offset_le)\n\n    hence \"size_td (dt_fst p') \\<le> x\"\n      by (rule order_trans) fact\n\n    hence ?case using wf lbs lbs'\n    proof (simp add: nth_append length_fa_ti access_ti_pair_dt_fst size_td_pair_dt_fst)\n      from fl have fl': \"field_lookup_list ts' f 0 = Some (s, n - size_td (dt_fst p'))\"\n\tby (rule field_lookup_offset2_list [where m = 0, simplified])\n\n      show \"access_ti_list ts' (update_ti s bs v) (drop (size_td (dt_fst p')) bs') ! (x - size_td (dt_fst p')) = bs ! (x - n)\"\n\tusing mlt nlex xln lbs lbs' wf wfts `td_fafu_idem s` `wf_fd s`\n\tby (simp add: Cons_typ_desc.hyps(2) [OF fl'] size_td_pair_dt_fst)\n    qed\n  }\n  moreover\n  {\n    note ih = Cons_typ_desc.hyps(1)[simplified access_ti_pair_dt_fst wf_fd_pair_dt_fst]\n\n    assume fl: \"field_lookup_pair p' f 0 = Some (s, n)\"\n\n    hence \"x < size_td (dt_fst p')\"\n      apply -\n      apply (cases p')\n      apply (simp split: if_split_asm)\n      apply (drule field_lookup_offset_size')\n      apply (rule order_less_le_trans [OF xln])\n      apply simp\n      done\n\n    hence ?case using wf lbs lbs' nlex xln wf wfts `td_fafu_idem s` `wf_fd s`\n      by (simp add: nth_append length_fa_ti access_ti_pair_dt_fst size_td_pair_dt_fst ih[OF fl])\n  }\n  ultimately show ?case using `field_lookup_list (p' # ts') f 0 = Some (s, n)` by (simp split: option.splits)\nqed (clarsimp split: if_split_asm)+\n\nsubsection {* td_fa_hi *}\n\n(* \\<lbrakk> size_of TYPE('a::mem_type) \\<le> length h; size_of TYPE('a) \\<le> length h' \\<rbrakk> \\<Longrightarrow> *)\n\nlemma fa_heap_indepD:\n  \"\\<lbrakk> fa_heap_indep fd n; length bs = n; length bs' = n \\<rbrakk> \\<Longrightarrow>\n  field_access fd v bs = field_access fd v bs'\"\n  unfolding fa_heap_indep_def\n  apply (drule spec, drule spec, drule spec)\n  apply (drule (1) mp)\n  apply (erule (1) mp)\n  done\n\n(* The simplifier spins on the IHs here, hence the proofs for each case *)\nlemma td_fa_hi_heap_independence:\n  shows \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi t; length h = size_td t; length h' = size_td t \\<rbrakk>\n  \\<Longrightarrow> access_ti t v h = access_ti t v h'\"\n  and   \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi_struct st; length h = size_td_struct st; length h' = size_td_struct st\\<rbrakk>\n  \\<Longrightarrow> access_ti_struct st v h = access_ti_struct st v h'\"\n  and   \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi_list ts;  length h = size_td_list ts; length h' = size_td_list ts \\<rbrakk>\n  \\<Longrightarrow> access_ti_list ts v h = access_ti_list ts v h'\"\n  and   \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi_pair p;  length h = size_td_pair p; length h' = size_td_pair p \\<rbrakk>\n  \\<Longrightarrow> access_ti_pair p v h = access_ti_pair p v h'\"\nproof (induct t and st and ts and p)\n  case TypDesc\n  from TypDesc.prems show ?case\n    by (simp) (erule (2) TypDesc.hyps)\nnext\n  case TypScalar\n  from TypScalar.prems show ?case\n    by simp (erule (2) fa_heap_indepD)\nnext\n  case TypAggregate\n  from TypAggregate.prems show ?case\n    by (simp) (erule (2) TypAggregate.hyps)\nnext\n  case Nil_typ_desc thus ?case by simp\nnext\n  case Cons_typ_desc\n  from Cons_typ_desc.prems show ?case\n    apply simp\n    apply (erule conjE)\n    apply (rule arg_cong2 [where f = \"op @\"])\n    apply (erule Cons_typ_desc.hyps, simp, simp)\n    apply (erule Cons_typ_desc.hyps, simp, simp)\n    done\nnext\n  case DTPair_typ_desc\n  from DTPair_typ_desc.prems show ?case\n    by simp (erule (2) DTPair_typ_desc.hyps)\nqed\n\nsection {* Simp rules for deriving packed props from the type combinators *}\n\nsubsection {* td_fafu_idem *}\n\nlemma td_fafu_idem_final_pad:\n  \"padup (2 ^ align_td t) (size_td t) = 0\n  \\<Longrightarrow> td_fafu_idem (final_pad t) = td_fafu_idem t\"\n  unfolding final_pad_def\n  by (clarsimp simp add: padup_def Let_def)\n\nlemma td_fafu_idem_ti_typ_pad_combine:\n  fixes t :: \"'a :: c_type itself\" and s :: \"'b :: c_type field_desc typ_desc\"\n  assumes pad: \"padup (align_of TYPE('a)) (size_td s) = 0\"\n  shows \"td_fafu_idem (ti_typ_pad_combine t xf xfu nm s) = td_fafu_idem (ti_typ_combine t xf xfu nm s)\"\n  unfolding ti_typ_pad_combine_def using pad\n  by (clarsimp simp: Let_def)\n\nlemma td_fafu_idem_list_append:\n  fixes xs :: \"'a :: c_type field_desc typ_pair list\"\n  shows \"td_fafu_idem_list (xs @ ys) = (td_fafu_idem_list xs \\<and> td_fafu_idem_list ys)\"\n  by (induct xs) simp+\n\nlemma td_fafu_idem_extend_ti:\n  fixes t :: \"'a :: c_type field_desc typ_desc\"\n  assumes as: \"td_fafu_idem s\"\n  and     at: \"td_fafu_idem t\"\n  shows \"td_fafu_idem (extend_ti s t nm)\" using as at\n  apply (cases s)\n  apply (rename_tac typ_struct xs)\n  apply (case_tac typ_struct)\n   apply simp\n  apply (simp add: td_fafu_idem_list_append)\n  done\n\nlemma fd_cons_access_updateD:\n  \"\\<lbrakk> fd_cons_access_update d n; length bs = n; length bs' = n\\<rbrakk> \\<Longrightarrow> field_access d (field_update d bs v) bs' = field_access d (field_update d bs v') bs'\"\n  unfolding fd_cons_access_update_def by clarsimp\n\n(* Beer crime? *)\nlemma fa_fu_idem_update_desc:\n  fixes a :: \"'a field_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and     fd: \"fd_cons_struct (TypScalar n n' a)\"\n  shows   \"fa_fu_idem (update_desc xf xfu a) n = fa_fu_idem a n\"\nproof\n  assume asm: \"fa_fu_idem (update_desc xf xfu a) n\"\n\n  let ?fu = \"\\<lambda>bs. if length bs = n then field_update a bs else id\"\n  let ?a' = \"\\<lparr> field_access = field_access a, field_update = ?fu \\<rparr>\"\n\n  show \"fa_fu_idem a n\"\n    unfolding fa_fu_idem_def\n  proof (intro impI conjI allI)\n    fix bs :: \"byte list\" and bs' :: \"byte list\" and v\n    assume l: \"length bs = n\" and l': \"length bs' = n\"\n\n    hence \"(\\<forall>v. field_access a (field_update a bs (xf v)) bs' = bs)\n      = (\\<forall>v. field_access a (?fu bs (xf v)) bs' = bs)\" by simp\n\n    also have \"\\<dots> = (\\<forall>v. field_access a (field_update a bs v) bs' = bs)\" using fd\n      apply -\n      apply rule\n      apply (rule allI)\n      apply (subst (asm) fd_cons_access_updateD [OF _ l l', where d = ?a', simplified])\n      apply (simp add: fd_cons_struct_def fd_cons_desc_def)\n      apply (fastforce simp: l l')\n      apply (fastforce simp: l l')\n      done\n\n    finally show \"field_access a (field_update a bs v) bs' = bs\" using asm fg l l'\n      by (clarsimp simp add: update_desc_def fa_fu_idem_def fg_cons_def)\n  qed\nnext\n  assume \"fa_fu_idem a n\"\n  thus \"fa_fu_idem (update_desc xf xfu a) n\"\n    unfolding fa_fu_idem_def update_desc_def using fg\n    by (clarsimp simp add: update_desc_def fa_fu_idem_def fg_cons_def)\nqed\n\nlemma td_fafu_idem_map_td_update_desc:\n  assumes fg: \"fg_cons xf xfu\"\n  shows  \"wf_fd t \\<Longrightarrow> td_fafu_idem (map_td (\\<lambda>_ _. update_desc xf xfu) t) = td_fafu_idem t\"\n  and    \"wf_fd_struct st \\<Longrightarrow> td_fafu_idem_struct (map_td_struct (\\<lambda>_ _. update_desc xf xfu) st) = td_fafu_idem_struct st\"\n  and    \"wf_fd_list ts \\<Longrightarrow> td_fafu_idem_list (map_td_list (\\<lambda>_ _. update_desc xf xfu) ts) = td_fafu_idem_list ts\"\n  and    \"wf_fd_pair p \\<Longrightarrow> td_fafu_idem_pair (map_td_pair (\\<lambda>_ _. update_desc xf xfu) p) = td_fafu_idem_pair p\"\n  by (induct t and st and ts and p) (auto elim!: fa_fu_idem_update_desc [OF fg])\n\nlemmas td_fafu_idem_adjust_ti = td_fafu_idem_map_td_update_desc(1)[folded adjust_ti_def]\n\nlemma td_fafu_idem_ti_typ_combine:\n  fixes s :: \"'b :: c_type field_desc typ_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and    tda: \"td_fafu_idem (typ_info_t TYPE('a :: mem_type))\"\n  and    tds: \"td_fafu_idem s\"\n  shows \"td_fafu_idem (ti_typ_combine TYPE('a :: mem_type) xf xfu nm s)\"\n  unfolding ti_typ_combine_def using tda tds\n  apply (clarsimp simp: Let_def)\n  apply (cases s)\n  apply (rename_tac typ_struct xs)\n  apply (case_tac typ_struct)\n   apply simp\n   apply (subst td_fafu_idem_adjust_ti [OF fg wf_fd], assumption)\n  apply (simp add: td_fafu_idem_list_append)\n  apply (subst td_fafu_idem_adjust_ti [OF fg wf_fd], assumption)\n  done\n\nlemma td_fafu_idem_ptr:\n   \"td_fafu_idem (typ_info_t TYPE('a :: c_type ptr))\"\n  apply (clarsimp simp add: fa_fu_idem_def)\n  apply (subst word_rsplit_rcat_size)\n   apply (clarsimp simp add: size_of_def word_size)\n  apply simp\n  done\n\nlemma td_fafu_idem_word:\n   \"td_fafu_idem (typ_info_t TYPE('a :: len8 word))\"\n  apply(clarsimp simp add: fa_fu_idem_def)\n  apply (subst word_rsplit_rcat_size)\n   apply (insert len8_dv8)\n   apply (clarsimp simp add: size_of_def word_size)\n   apply (subst dvd_div_mult_self)\n    apply simp\n   apply simp\n  apply simp\n  done\n\nlemma fg_cons_array [simp]:\n  \"n < card (UNIV :: 'b :: finite set) \\<Longrightarrow> fg_cons (\\<lambda>x. index x n) (\\<lambda>x f. Arrays.update (f :: 'a['b]) n x)\"\n  unfolding fg_cons_def by simp\n\nlemma td_fafu_idem_array_n:\n  \"\\<lbrakk>td_fafu_idem (typ_info_t TYPE('a)); n \\<le> card (UNIV :: 'b set) \\<rbrakk> \\<Longrightarrow> td_fafu_idem (array_tag_n n :: ('a :: mem_type ['b :: finite]) field_desc typ_desc)\"\n  apply (induct n)\n   apply (simp add: array_tag_n.simps empty_typ_info_def)\n  apply (simp add: array_tag_n.simps)\n  apply (rule td_fafu_idem_ti_typ_combine)\n    apply simp\n   apply simp\n  apply simp\n  done\n\nlemma td_fafu_idem_array:\n  \"td_fafu_idem (typ_info_t TYPE('a)) \\<Longrightarrow> td_fafu_idem (typ_info_t TYPE('a :: mem_type ['b :: finite]))\"\n  apply (clarsimp simp add: typ_info_array array_tag_def fa_fu_idem_def)\n  apply (erule td_fafu_idem_array_n)\n  apply simp\n  done\n\nlemma td_fafu_idem_empty_typ_info:\n  \"td_fafu_idem (empty_typ_info t)\"\n  unfolding empty_typ_info_def\n  by simp\n\nsubsection {* td_fa_hi *}\n\n(* These are mostly identical to the above --- surely there is something which implies both? *)\n\nlemma td_fa_hi_final_pad:\n  \"padup (2 ^ align_td t) (size_td t) = 0\n  \\<Longrightarrow> td_fa_hi (final_pad t) = td_fa_hi t\"\n  unfolding final_pad_def\n  by (clarsimp simp add: padup_def Let_def)\n\nlemma td_fa_hi_ti_typ_pad_combine:\n  fixes t :: \"'a :: c_type itself\" and s :: \"'b :: c_type field_desc typ_desc\"\n  assumes pad: \"padup (align_of TYPE('a)) (size_td s) = 0\"\n  shows \"td_fa_hi (ti_typ_pad_combine t xf xfu nm s) = td_fa_hi (ti_typ_combine t xf xfu nm s)\"\n  unfolding ti_typ_pad_combine_def using pad\n  by (clarsimp simp: Let_def)\n\nlemma td_fa_hi_list_append:\n  fixes xs :: \"'a :: c_type field_desc typ_pair list\"\n  shows \"td_fa_hi_list (xs @ ys) = (td_fa_hi_list xs \\<and> td_fa_hi_list ys)\"\n  by (induct xs) simp+\n\nlemma td_fa_hi_extend_ti:\n  fixes t :: \"'a :: c_type field_desc typ_desc\"\n  assumes as: \"td_fa_hi s\"\n  and     at: \"td_fa_hi t\"\n  shows \"td_fa_hi (extend_ti s t nm)\" using as at\n  apply (cases s)\n  apply (rename_tac typ_struct xs)\n  apply (case_tac typ_struct)\n   apply simp\n  apply (simp add: td_fa_hi_list_append)\n  done\n\n(* Beer crime? *)\nlemma fa_heap_indep_update_desc:\n  fixes a :: \"'a field_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and     fd: \"fd_cons_struct (TypScalar n n' a)\"\n  shows   \"fa_heap_indep (update_desc xf xfu a) n = fa_heap_indep a n\"\nproof\n  assume asm: \"fa_heap_indep (update_desc xf xfu a) n\"\n\n  have xf_xfu: \"\\<And>v v'. xf (xfu v v') = v\" using fg\n    unfolding fg_cons_def\n    by simp\n\n  show \"fa_heap_indep a n\"\n    unfolding fa_heap_indep_def\n  proof (intro impI conjI allI)\n    fix bs :: \"byte list\" and bs' :: \"byte list\" and v\n    assume l: \"length bs = n\" and l': \"length bs' = n\"\n    with asm have \"field_access (update_desc xf xfu a) (xfu v undefined) bs =\n      field_access (update_desc xf xfu a) (xfu v undefined) bs'\"\n      by (rule fa_heap_indepD)\n\n    thus \"field_access a v bs = field_access a v bs'\"\n      unfolding update_desc_def\n      by (simp add: xf_xfu)\n  qed\nnext\n  assume asm: \"fa_heap_indep a n\"\n  show \"fa_heap_indep (update_desc xf xfu a) n\"\n    unfolding fa_heap_indep_def update_desc_def\n  proof (simp, intro impI conjI allI)\n    fix bs :: \"byte list\" and bs' :: \"byte list\" and v\n    assume l: \"length bs = n\" and l': \"length bs' = n\"\n\n    with asm show \"field_access a (xf v) bs = field_access a (xf v) bs'\"\n      by (rule fa_heap_indepD)\n  qed\nqed\n\nlemma td_fa_hi_map_td_update_desc:\n  assumes fg: \"fg_cons xf xfu\"\n  shows  \"wf_fd t \\<Longrightarrow> td_fa_hi (map_td (\\<lambda>_ _. update_desc xf xfu) t) = td_fa_hi t\"\n  and    \"wf_fd_struct st \\<Longrightarrow> td_fa_hi_struct (map_td_struct (\\<lambda>_ _. update_desc xf xfu) st) = td_fa_hi_struct st\"\n  and    \"wf_fd_list ts \\<Longrightarrow> td_fa_hi_list (map_td_list (\\<lambda>_ _. update_desc xf xfu) ts) = td_fa_hi_list ts\"\n  and    \"wf_fd_pair p \\<Longrightarrow> td_fa_hi_pair (map_td_pair (\\<lambda>_ _. update_desc xf xfu) p) = td_fa_hi_pair p\"\n  by (induct t and st and ts and p) (auto elim!: fa_heap_indep_update_desc [OF fg])\n\nlemmas td_fa_hi_adjust_ti = td_fa_hi_map_td_update_desc(1)[folded adjust_ti_def]\n\nlemma td_fa_hi_ti_typ_combine:\n  fixes s :: \"'b :: c_type field_desc typ_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and    tda: \"td_fa_hi (typ_info_t TYPE('a :: mem_type))\"\n  and    tds: \"td_fa_hi s\"\n  shows \"td_fa_hi (ti_typ_combine TYPE('a :: mem_type) xf xfu nm s)\"\n  unfolding ti_typ_combine_def using tda tds\n  apply (clarsimp simp: Let_def)\n  apply (cases s)\n  apply (rename_tac typ_struct xs)\n  apply (case_tac typ_struct)\n   apply simp\n   apply (subst td_fa_hi_adjust_ti [OF fg wf_fd], assumption)\n  apply (simp add: td_fa_hi_list_append)\n  apply (subst td_fa_hi_adjust_ti [OF fg wf_fd], assumption)\n  done\n\nlemma td_fa_hi_ptr:\n   \"td_fa_hi (typ_info_t TYPE('a :: c_type ptr))\"\n  by (clarsimp simp add: fa_heap_indep_def)\n\nlemma td_fa_hi_word:\n   \"td_fa_hi (typ_info_t TYPE('a :: len8 word))\"\n  by (clarsimp simp add: fa_heap_indep_def)\n\nlemma td_fa_hi_array_n:\n  \"\\<lbrakk>td_fa_hi (typ_info_t TYPE('a)); n \\<le> card (UNIV :: 'b set) \\<rbrakk> \\<Longrightarrow> td_fa_hi (array_tag_n n :: ('a :: mem_type ['b :: finite]) field_desc typ_desc)\"\n  apply (induct n)\n   apply (simp add: array_tag_n.simps empty_typ_info_def)\n  apply (simp add: array_tag_n.simps)\n  apply (rule td_fa_hi_ti_typ_combine)\n    apply simp\n   apply simp\n  apply simp\n  done\n\nlemma td_fa_hi_array:\n  \"td_fa_hi (typ_info_t TYPE('a)) \\<Longrightarrow> td_fa_hi (typ_info_t TYPE('a :: mem_type ['b :: finite]))\"\n  apply (clarsimp simp add: typ_info_array array_tag_def fa_fu_idem_def)\n  apply (erule td_fa_hi_array_n)\n  apply simp\n  done\n\nlemma td_fa_hi_empty_typ_info:\n  \"td_fa_hi (empty_typ_info t)\"\n  unfolding empty_typ_info_def\n  by simp\n\nsection {* The type class and simp sets *}\n\ntext {* Packed types, with no padding, have the defining property that\n        access is invariant under substitution of the underlying heap and\n        access/update is the identity *}\n\nclass packed_type = mem_type +\n  assumes td_fafu_idem: \"td_fafu_idem (typ_info_t TYPE('a::c_type))\"\n  assumes td_fa_hi:     \"td_fa_hi (typ_info_t TYPE('a::c_type))\"\n\nlemmas td_fafu_idem_intro_simps =\n  -- \"Axioms\"\n  td_fafu_idem\n  -- \"Combinators\"\n  td_fafu_idem_final_pad td_fafu_idem_ti_typ_pad_combine td_fafu_idem_ti_typ_combine td_fafu_idem_empty_typ_info\n  -- \"Constructors\"\n  td_fafu_idem_ptr td_fafu_idem_word td_fafu_idem_array\n\nlemmas td_fa_hi_intro_simps =\n  -- \"Axioms\"\n  td_fa_hi\n  -- \"Combinators\"\n  td_fa_hi_final_pad td_fa_hi_ti_typ_pad_combine td_fa_hi_ti_typ_combine td_fa_hi_empty_typ_info\n  -- \"Constructors\"\n  td_fa_hi_ptr td_fa_hi_word td_fa_hi_array\n\nlemma align_td_array':\n  \"align_td (typ_info_t TYPE('a :: c_type['b :: finite])) = align_td (typ_info_t TYPE('a))\"\n  by (simp add: typ_info_array array_tag_def align_td_array_tag)\n\nlemmas packed_type_intro_simps =\n  td_fafu_idem_intro_simps td_fa_hi_intro_simps align_td_array' size_td_simps size_td_array\n\nlemma access_ti_append':\n  \"\\<And>list.\n   access_ti_list (xs @ ys) t list =\n     access_ti_list xs t (take (size_td_list xs) list) @\n     access_ti_list ys t (drop (size_td_list xs) list)\"\nproof(induct xs)\n  case Nil show ?case by simp\nnext\n  case (Cons x xs) thus ?case by (simp add: min_def ac_simps drop_take)\nqed\n\nsection {* Instances *}\n\ntext {* Words (of multiple of 8 size) are packed *}\n\ninstantiation word :: (len8) packed_type\nbegin\ninstance\n apply(intro_classes)\n   apply (rule td_fafu_idem_word)\n  apply (rule td_fa_hi_word)\n  done\nend\n\ntext {* Pointers are always packed *}\n\ninstantiation ptr :: (c_type)packed_type\nbegin\ninstance\n  apply intro_classes\n   apply (simp add: fa_fu_idem_def word_rsplit_rcat_size word_size)\n  apply (simp add: fa_heap_indep_def)\n  done\nend\n\ntext {* Arrays of packed types are in turn packed *}\n\nclass oneMB_packed = packed_type + oneMB_size\nclass twoToSix_packed = oneMB_packed + twoToSix_size\n\ninstance word :: (len8)oneMB_packed ..\ninstance word :: (len8)twoToSix_packed ..\n\ninstantiation array :: (oneMB_packed, fourthousand_count) packed_type\nbegin\ninstance\n apply(intro_classes)\n   apply (simp add: td_fafu_idem_intro_simps)\n  apply (simp add: td_fa_hi_intro_simps)\n  done\nend\n\ninstance array :: (twoToSix_packed, fourthousand_count) oneMB_packed ..\n\nsection {* Theorems about packed types *}\n\nsubsection {* td_fa_hi *}\n\nlemma heap_independence:\n  \"\\<lbrakk>length h = size_of TYPE('a :: packed_type); length h' = size_of TYPE('a) \\<rbrakk>\n  \\<Longrightarrow> access_ti (typ_info_t TYPE('a)) v h = access_ti (typ_info_t TYPE('a)) v h'\"\n  by (rule td_fa_hi_heap_independence(1)[OF td_fa_hi], simp_all add: size_of_def)\n\ntheorem packed_heap_update_collapse:\n fixes u::\"'a::packed_type\"\n fixes v::\"'a\"\n shows\n  \"heap_update p v (heap_update p u h) = heap_update p v h\"\n apply(simp add:heap_update_def)\n apply(rule ext)\n apply(case_tac \"x \\<in> {ptr_val p..+size_of TYPE('a)}\")\n  apply((subst heap_update_mem_same_point, simp, simp)+)\n  apply(simp add:to_bytes_def)\n  apply(subst heap_independence)\n    apply(simp)\n   prefer 2\n   apply(force)\n  apply(simp)\n apply((subst heap_update_nmem_same, simp)+)\n apply(rule refl)\ndone\n\nlemma packed_heap_update_collapse_hrs:\n  fixes p :: \"'a :: packed_type ptr\"\n  shows \"(hrs_mem_update (heap_update p v) (hrs_mem_update (heap_update p v') hp)) =\n  (hrs_mem_update (heap_update p v) hp)\"\n  unfolding hrs_mem_update_def\n  by (simp add: split_def packed_heap_update_collapse)\n\nsubsection {* td_fafu_idem *}\n\nlemma order_leE:\n  fixes x :: \"'a :: order\"\n  shows \"\\<lbrakk> x \\<le> y; x = y \\<Longrightarrow> P; x < y \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P\"\n  by (auto simp: order_le_less)\n\nlemma of_nat_mono_maybe_le:\n  shows \"\\<lbrakk>X < 2 ^ len_of TYPE('a); Y \\<le> X\\<rbrakk> \\<Longrightarrow> (of_nat Y :: 'a :: len word) \\<le> of_nat X\"\n  apply (erule order_leE)\n   apply simp\n  apply (rule order_less_imp_le)\n  apply (erule (1) of_nat_mono_maybe)\n  done\n\nlemma intvl_le_lower:\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk> x \\<in> {y..+n}; y \\<le> y + of_nat (n - 1); n < 2 ^ len_of TYPE('a) \\<rbrakk> \\<Longrightarrow> y \\<le> x\"\n  apply (drule intvlD)\n  apply (elim conjE exE)\n  apply (erule ssubst)\n  apply (erule word_plus_mono_right2)\n  apply (rule of_nat_mono_maybe_le)\n   apply simp\n  apply simp\n  done\n\nlemma intvl_less_upper:\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk> x \\<in> {y..+n}; y \\<le> y + of_nat (n - 1); n < 2 ^ len_of TYPE('a) \\<rbrakk> \\<Longrightarrow> x \\<le> y + of_nat (n - 1)\"\n  apply (drule intvlD)\n  apply (elim conjE exE)\n  apply (erule ssubst)\n  apply (rule word_plus_mono_right)\n   apply (rule of_nat_mono_maybe_le)\n    apply simp\n   apply simp\n  apply assumption\n  done\n\nlemma packed_type_access_ti:\n  fixes v :: \"'a :: packed_type\"\n  assumes lbs: \"length bs = size_of TYPE('a)\"\n  shows \"access_ti (typ_info_t TYPE('a)) v bs = access_ti\\<^sub>0 (typ_info_t TYPE('a)) v\"\n  unfolding access_ti\\<^sub>0_def using lbs\n  apply -\n  apply (rule heap_independence)\n   apply simp\n  apply (simp add: size_of_def)\n  done\n\nlemma update_ti_update_ti_t:\n  \"length bs = size_td s \\<Longrightarrow> update_ti s bs v = update_ti_t s bs v\"\n  unfolding update_ti_t_def by simp\n\nlemma heap_list_nth:\n  \"m < n \\<Longrightarrow> heap_list hp n p ! m = hp (p + of_nat m)\"\nproof (induct m arbitrary: n p)\n  case (0 n' p')\n\n  thus ?case by (cases n', simp_all)\nnext\n  case (Suc m' n' p')\n\n  show ?case\n  proof (cases n')\n    case 0 thus ?thesis using `Suc m' < n'` by simp\n  next\n    case (Suc n'')\n    hence \"m' < n''\" using `Suc m' < n'` by simp\n    thus ?thesis using Suc\n      by (simp add: Suc.hyps ac_simps)\n  qed\nqed\n\nlemma c_guard_field_lvalue:\n  fixes p :: \"'a :: mem_type ptr\"\n  assumes cg: \"c_guard p\"\n  and     fl: \"field_lookup (typ_info_t TYPE('a)) f 0 = Some (t, n)\"\n  and     eu: \"export_uinfo t = typ_uinfo_t TYPE('b :: mem_type)\"\n  shows   \"c_guard (Ptr &(p\\<rightarrow>f) :: 'b :: mem_type ptr)\"\n  unfolding c_guard_def\nproof (rule conjI)\n  from cg fl eu show \"ptr_aligned (Ptr &(p\\<rightarrow>f) :: 'b ptr)\"\n    by (rule c_guard_ptr_aligned_fl)\nnext\n  from eu have std: \"size_td t = size_of TYPE('b)\" using fl\n    by (simp add: export_size_of)\n\n  from cg have \"c_null_guard p\" unfolding c_guard_def ..\n  thus \"c_null_guard (Ptr &(p\\<rightarrow>f)  :: 'b ptr)\" unfolding c_null_guard_def\n    apply (rule contrapos_nn)\n    apply (rule subsetD [OF field_tag_sub, OF fl])\n    apply (simp add: std)\n    done\nqed\n\n(* Similar in TypHeap, but for w32 *)\nlemma unat_minus':\n  fixes x :: \"'a :: len word\"\n  shows \"x \\<noteq> 0 \\<Longrightarrow> unat (-x) = 2 ^ len_of TYPE('a) - unat x\"\n  apply (simp add: unat_def word_minus_def)\n  apply (simp add: int_word_uint zmod_zminus1_eq_if uint_0_iff)\n  apply (subst nat_diff_distrib)\n    apply simp\n   apply (rule order_less_imp_le [OF uint_lt2p])\n   apply (clarsimp simp: nat_power_eq)\n   done\n\nlemma word_wrap_of_natD:\n  fixes x :: \"'a :: len word\"\n  assumes wraps: \"\\<not> x \\<le> x + of_nat n\"\n  shows   \"\\<exists>k. x + of_nat k = 0 \\<and> k \\<le> n\"\nproof -\n  show ?thesis\n  proof (rule exI [where x = \"unat (- x)\"], intro conjI)\n    show \"x + of_nat (unat (-x)) = 0\"\n      by simp\n  next\n    show \"unat (-x) \\<le> n\"\n    proof (subst unat_minus')\n      from wraps show \"x \\<noteq> 0\"\n\tby (rule contrapos_pn, simp add: not_le)\n    next\n      show \"2 ^ len_of TYPE('a) - unat x \\<le> n\" using wraps\n\tapply (simp add: no_olen_add_nat le_diff_conv not_less)\n\tapply (erule order_trans)\n\tapply (simp add: unat_of_nat)\n\tdone\n    qed\n  qed\nqed\n\nlemma nat_le_Suc_less:\n  \"0 < y \\<Longrightarrow> (x \\<le> y - Suc 0) = (x < y)\"\n  by arith\n\nlemma c_guard_no_wrap:\n  fixes p :: \"'a :: mem_type ptr\"\n  assumes cgrd: \"c_guard p\"\n  shows   \"ptr_val p \\<le> ptr_val p + of_nat (size_of TYPE('a) - 1)\"\n  using cgrd unfolding c_guard_def c_null_guard_def\n  apply -\n  apply (erule conjE)\n  apply (erule contrapos_np)\n  apply (simp add: intvl_def)\n  apply (drule word_wrap_of_natD)\n  apply (erule exE)\n  apply (rule exI)\n  apply (simp add: nat_le_Suc_less)\n  done\n\ntheorem packed_heap_super_field_update:\n  fixes v :: \"'a :: packed_type\" and p :: \"'b :: packed_type ptr\"\n  assumes fl: \"field_lookup (typ_info_t TYPE('b)) f 0 = Some (t, n)\"\n  and   cgrd: \"c_guard p\"\n  and     eu: \"export_uinfo t = typ_uinfo_t TYPE('a)\"\n  shows   \"heap_update (Ptr &(p\\<rightarrow>f)) v hp = heap_update p (update_ti t (to_bytes_p v) (h_val hp p)) hp\"\n  unfolding heap_update_def to_bytes_def\nproof (simp add: packed_type_access_ti, rule ext)\n  fix x\n  let ?LHS = \"heap_update_list &(p\\<rightarrow>f) (to_bytes_p v) hp x\"\n  let ?RHS = \"heap_update_list (ptr_val p) (to_bytes_p (update_ti t (to_bytes_p v) (h_val hp p))) hp x\"\n\n  from cgrd have al: \"ptr_val p \\<le> ptr_val p + of_nat (size_of TYPE('b) - 1)\" by (rule c_guard_no_wrap)\n\n  have szb: \"size_of TYPE('b) < 2 ^ len_of TYPE(addr_bitsize)\"\n    apply (fold card_word)\n    apply (fold addr_card_def)\n    apply (rule max_size)\n    done\n\n  have szt: \"n + size_td t \\<le> size_of TYPE('b)\"\n    unfolding size_of_def\n    by (subst add.commute, rule field_lookup_offset_size [OF fl])\n  moreover have t0: \"0 < size_td t\" using fl wf_size_desc\n    by (rule field_lookup_wf_size_desc_gt)\n  ultimately have szn: \"n < size_of TYPE('b)\" by simp\n  from szt have szt1: \"n + (size_td t - 1) \\<le> size_of TYPE('b)\"\n    by simp\n\n  have b0: \"0 < size_of (TYPE ('b))\" using wf_size_desc\n    unfolding size_of_def\n    by (rule wf_size_desc_gt)\n\n  have uofn: \"unat (of_nat n :: addr_bitsize word) = n\" using szn szb\n    by (simp add: unat_simps)\n\n  from eu have std: \"size_td t = size_of TYPE('a)\" using fl\n    by (simp add: export_size_of)\n\n  hence \"?LHS = (if x \\<in> {&(p\\<rightarrow>f)..+size_td t} then (to_bytes_p v) ! unat (x - &(p\\<rightarrow>f)) else hp x)\"\n    by (simp add: heap_update_mem_same_point heap_update_nmem_same)\n  also have \"... = ?RHS\"\n  proof (simp, intro impI conjI)\n    assume xin: \"x \\<in> {&(p\\<rightarrow>f)..+size_td t}\"\n    have \"to_bytes_p v ! unat (x - &(p\\<rightarrow>f)) = to_bytes_p (update_ti t (to_bytes_p v) (h_val hp p)) ! unat (x - ptr_val p)\"\n    proof (simp add: to_bytes_p_def to_bytes_def, subst field_access_update_nth_inner(1)[OF fl, simplified])\n\n      have \"c_guard (Ptr &(p\\<rightarrow>f) :: 'a ptr)\" using cgrd fl eu\n\tby (rule c_guard_field_lvalue)\n      hence pft: \"&(p\\<rightarrow>f) \\<le> &(p\\<rightarrow>f) + of_nat (size_td t - 1)\"\n\tapply -\n\tapply (drule c_guard_no_wrap)\n\tapply (simp add: std)\n\tdone\n\n      have szt': \"size_td t < 2 ^ len_of TYPE(addr_bitsize)\"\n\tapply (subst std)\n\tapply (fold card_word)\n\tapply (fold addr_card_def)\n\tapply (rule max_size)\n\tdone\n\n      have ofn: \"of_nat n \\<le> x - ptr_val p\"\n      proof (rule le_minus')\n\tfrom xin show \"ptr_val p + of_nat n \\<le> x\" using pft szt'\n\t  unfolding field_lvalue_def field_lookup_offset_eq [OF fl]\n\t  by (rule intvl_le_lower)\n      next\n\tfrom szb szn have \"of_nat n \\<le> (of_nat (size_of TYPE('b) - 1) :: addr_bitsize word)\"\n\t  apply -\n\t  apply (rule of_nat_mono_maybe_le)\n\t  apply simp_all\n\t  done\n\twith al show \"ptr_val p \\<le> ptr_val p + of_nat n\"\n\t  by (rule word_plus_mono_right2)\n      qed\n\n      thus nlt: \"n \\<le> unat (x - ptr_val p)\"\n\tby (simp add: word_le_nat_alt uofn)\n      have \"x \\<le> ptr_val p + (of_nat n + of_nat (size_td t - 1))\" using xin pft szt' t0\n\tunfolding field_lvalue_def field_lookup_offset_eq [OF fl]\n\tapply -\n\tapply (drule (2) intvl_less_upper)\n\tapply (simp add: add.assoc)\n\tdone\n      moreover have \"x \\<in> {ptr_val p..+size_of TYPE('b)}\" using fl xin\n\tby (rule subsetD [OF field_tag_sub])\n      ultimately have \"x - ptr_val p \\<le> (of_nat n + of_nat (size_td t - 1))\" using al szb\n\tapply -\n\tapply (rule word_diff_ls(4)[where xa=x and x=x for x, simplified])\n     apply (metis (hide_lams, mono_tags) add.commute of_nat_add)\n\tapply (erule (2) intvl_le_lower)\n\tdone\n      moreover have \"unat (of_nat n + of_nat (size_td t - 1) :: addr_bitsize word) = n + size_td t - 1\"\n\tusing t0 order_le_less_trans [OF szt1 szb]\n\tapply (subst Abs_fnat_homs(1))\n\tapply (subst unat_of_nat)\n\tapply simp\n\tdone\n      ultimately have \"unat (x - ptr_val p) \\<le> n + size_td t - 1\"\n\tby (simp add: word_le_nat_alt)\n      thus \"unat (x - ptr_val p) < n + size_td t\" using t0\n\tby simp\n\n      show \"td_fafu_idem t\"\n\tby (rule field_lookup_td_fafu_idem(1)[OF fl td_fafu_idem])\n\n      show \"wf_fd t\"\n\tby (rule wf_fd_field_lookupD [OF fl wf_fd])\n\n      show \"length (access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0)) = size_td t\"\n\tusing wf_fd [where 'a = 'a]\n\tby (simp add: length_fa_ti size_of_def std)\n\n      show \"length (replicate (size_of TYPE('b)) 0) = size_td (typ_info_t TYPE('b))\"\n\tby (simp add: size_of_def)\n\n      have \"unat (x - &(p\\<rightarrow>f)) = unat ((x - ptr_val p) - of_nat n)\"\n  \tby (simp add: field_lvalue_def field_lookup_offset_eq [OF fl])\n      also have \"\\<dots> = unat (x - ptr_val p) - n\"\n\tby (simp add: unat_sub [OF ofn] uofn)\n      finally have \"unat (x - &(p\\<rightarrow>f)) = unat (x - ptr_val p) - n\" .\n\n      thus \"access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0) ! unat (x - &(p\\<rightarrow>f)) =\n\taccess_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0) ! (unat (x - ptr_val p) - n)\"\n\tby simp\n    qed\n\n    thus \"to_bytes_p v ! unat (x - &(p\\<rightarrow>f)) = ?RHS\"\n    proof (subst heap_update_mem_same_point, simp_all)\n      show \"x \\<in> {ptr_val p..+size_of TYPE('b)}\" using fl xin\n\tby (rule subsetD [OF field_tag_sub])\n    qed\n  next\n    assume xni: \"x \\<notin> {&(p\\<rightarrow>f)..+size_td t}\"\n    have \"?RHS = (if x \\<in> {ptr_val p..+size_of TYPE('b)}\n          then (to_bytes_p (update_ti t (to_bytes_p v) (h_val hp p))) ! unat (x - ptr_val p) else hp x)\"\n      by (simp add: heap_update_mem_same_point heap_update_nmem_same)\n\n    also\n    {\n      assume xin: \"x \\<in> {ptr_val p..+size_of TYPE('b)}\"\n\n      hence \"access_ti (typ_info_t TYPE('b))\n\t(update_ti_t t (access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0)) (h_val hp p))\n\t(replicate (size_of TYPE('b)) 0) ! unat (x - ptr_val p) = hp x\"\n      proof (subst field_access_update_nth_disjD [OF fl])\n\thave \"x - ptr_val p \\<le> of_nat (size_of TYPE('b) - 1)\"\n\tproof (rule word_diff_ls(4)[where xa=x and x=x for x, simplified])\n      \t  from xin show \"x \\<le> of_nat (size_of TYPE('b) - 1) + ptr_val p\" using al szb\n\t    by (subst add.commute, rule intvl_less_upper)\n\t  show \"ptr_val p \\<le> x\" using xin al szb\n\t    by (rule intvl_le_lower)\n\tqed\n\tthus unx: \"unat (x - ptr_val p) < size_td (typ_info_t TYPE('b))\" using szb b0\n\t  by (simp add: word_le_nat_alt size_of_def unat_of_nat)\n\n\tshow \"unat (x - ptr_val p) < n - 0 \\<or> n - 0 + size_td t \\<le> unat (x - ptr_val p)\" using xin xni\n  \t  unfolding field_lvalue_def field_lookup_offset_eq [OF fl]\n\t  apply -\n\t  apply (erule intvl_cut)\n\t  apply simp\n\t  apply (rule max_size)\n\t  done\n\n\tshow \"wf_fd (typ_info_t TYPE('b))\" by (rule wf_fd)\n\t(* clag *)\n\tshow \"length (access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0)) = size_td t\"\n\t  using wf_fd [where 'a = 'a]\n\t  by (simp add: length_fa_ti size_of_def std)\n\n\tshow \"length (replicate (size_of TYPE('b)) 0) = size_td (typ_info_t TYPE('b))\"\n\t  by (simp add: size_of_def)\n\n\thave \"heap_list hp (size_td (typ_info_t TYPE('b))) (ptr_val p) ! unat (x - ptr_val p) = hp x\"\n\t  apply (subst heap_list_nth)\n\t  apply (rule unx)\n\t  apply simp\n\t  done\n\n\tthus \"access_ti (typ_info_t TYPE('b)) (h_val hp p) (replicate (size_of TYPE('b)) 0) ! unat (x - ptr_val p) = hp x\"\n\t  unfolding h_val_def\n\t  by (simp add: from_bytes_def update_ti_t_def size_of_def field_access_update_same(1)[OF td_fafu_idem wf_fd])\n      qed\n     }\n    hence \"\\<dots> = hp x\"\n      by (simp add: to_bytes_p_def to_bytes_def update_ti_update_ti_t length_fa_ti [OF wf_fd] std size_of_def)\n    finally show \"hp x = ?RHS\" by simp\n  qed\n  finally show \"?LHS = ?RHS\" .\nqed\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/l4v/tools/c-parser/PackedTypes.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318337259583, "lm_q2_score": 0.46101677931231594, "lm_q1q2_score": 0.2784227089085224}}
{"text": "(*\n * Copyright 2014, General Dynamics C4 Systems\n *\n * SPDX-License-Identifier: GPL-2.0-only\n *)\n\n(* Title:   Confinement_S\n * Description: Rephrasing of the confinement proof using the concept of islands.\n *)\n\ntheory Islands_S\nimports Confine_S\nbegin\n\ndefinition\n  island :: \"state \\<Rightarrow> entity_id \\<Rightarrow> entity_id set\" where\n  \"island s x \\<equiv> {e\\<^sub>i. s \\<turnstile> x \\<leftrightarrow>* e\\<^sub>i}\"\n\ndefinition\n  island_caps :: \"state \\<Rightarrow> entity_id \\<Rightarrow> cap set\" where\n  \"island_caps s x \\<equiv> \\<Union>(caps_of s ` island s x)\"\n\nlemma island_caps_def2:\n  \"island_caps s x \\<equiv> \\<Union> e \\<in> island s x. caps_of s e\"\n  by(simp add: island_caps_def)\n\nlemma island_caps_def3:\n  \"island_caps s x =  \\<Union>(direct_caps_of s ` island s x)\"\n  apply (clarsimp simp: island_caps_def)\n  apply rule\n   apply (clarsimp simp: island_def caps_of_def)\n   apply (drule store_connected_directly_tgs_connected)\n   apply (metis directly_tgs_connected_rtrancl_into_rtrancl)\n  apply (fastforce simp: caps_of_def store_connected_def)\n  done\n\nlemma island_caps_dom:\n  \"island_caps s e\\<^sub>x \\<le>cap c =\n  (\\<forall>e\\<^sub>i. (e\\<^sub>x, e\\<^sub>i) \\<in> tgs_connected s \\<longrightarrow> caps_of s e\\<^sub>i \\<le>cap c)\"\n  by (auto simp add: island_caps_def caps_dominated_by_def island_def)\n\nlemma authority_confinement_islands:\n  \"\\<lbrakk>s' \\<in> execute cmds s;\n    island_caps s x \\<le>cap c\\<rbrakk>\n  \\<Longrightarrow> island_caps s' x \\<le>cap c\"\n  apply (simp add: island_caps_dom)\n  apply clarsimp\n  apply (frule (1) tgs_connected_preserved)\n  apply (subst (asm) tgs_connected_comm_eq)\n  apply (erule authority_confinement)\n  apply clarsimp\n  apply (erule_tac x=e\\<^sub>i' in allE)\n  apply (erule impE)\n  apply (metis (hide_lams, no_types) tgs_connected_comm_eq tgs_connected_def rtrancl_trans)\n  apply clarsimp\n  done\n\nend\n", "meta": {"author": "NICTA", "repo": "l4v", "sha": "3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b", "save_path": "github-repos/isabelle/NICTA-l4v", "path": "github-repos/isabelle/NICTA-l4v/l4v-3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b/spec/take-grant/Islands_S.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5888891451980403, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.27835816849624456}}
{"text": "theory flash54Rev imports flashPub\nbegin\nsection{*Main defintions*}\n     \n\nlemma lemmaOnPtrAtGetX[intro]:\n  assumes  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n    and a5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_GetX )) s\" and\n    a6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2)) s \" and\n    a7:\"\\<forall>f. f \\<in> (invariants   N) \\<longrightarrow> formEval f s \"\n shows  \"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n proof(rule ccontr)\n  assume b0:\"\\<not>formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n  have b1:\"formEval (inv2 iInv1 iInv2) s\"\n    apply(cut_tac a7)\n    \n    apply(drule_tac x=\"inv2  iInv1 iInv2\" in spec)\n    apply(cut_tac a7 a2 a3 a4,simp)\n    done\n with b0 a5 a6 show False\n  by auto\nqed  \n\n\n\nlemma lemmaOnPtrAtGet[intro]:\n  assumes  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n    and a5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get )) s\" and\n    a6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2)) s \" and\n    a7:\"\\<forall>f. f \\<in> (invariants   N) \\<longrightarrow> formEval f s \"\n shows  \"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n proof(rule ccontr)\n  assume b0:\"\\<not>formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n  have b1:\"formEval (inv3 iInv1 iInv2) s\"\n    apply(cut_tac a7)\n    \n    apply(drule_tac x=\"inv3  iInv1 iInv2\" in spec)\n    apply(cut_tac a7 a2 a3 a4,simp)\n    done\n with b0 a5 a6 show False\n  by auto\nqed  \n\nlemma lemmaOnPtr1[intro]:\n  assumes  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n    and a5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get )) s\" and\n    a6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2)) s \" and\n    a7:\"\\<forall>f. f \\<in> (invariants   N) \\<longrightarrow> formEval f s \" and\n    b2:\"iInv1' \\<le> N\" and  b3:\"iInv2' \\<le> N\" and  b4:\"iInv1'~=iInv2'  \" \n    and b5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1') )  ( Const UNI_Get )) s\" and\n    b6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1') )   (Const iInv2')) s \" and\n    b7:\"iInv2\\<noteq>iInv2'\"\n shows False\n proof -\n  have c1:\"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n    by(metis a2 a3 a4 a5 a6 a7 lemmaOnPtrAtGet)\n  have c2:\"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2') )  s\"\n    by(metis b2 b3 b4 b5 b6 a7 lemmaOnPtrAtGet)\n with c1 b7  show False\n  by auto\nqed  \n\n\nlemma lemmaOnPtr2[intro]:\n  assumes  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n    and a5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_GetX )) s\" and\n    a6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2)) s \" and\n    a7:\"\\<forall>f. f \\<in> (invariants   N) \\<longrightarrow> formEval f s \" and\n    b2:\"iInv1' \\<le> N\" and  b3:\"iInv2' \\<le> N\" and  b4:\"iInv1'~=iInv2'  \" \n    and b5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1') )  ( Const UNI_GetX )) s\" and\n    b6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1') )   (Const iInv2')) s \" and\n    b7:\"iInv2\\<noteq>iInv2'\"\n shows False\n proof -\n  have c1:\"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n    by(metis a2 a3 a4 a5 a6 a7 lemmaOnPtrAtGetX)\n  have c2:\"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2') )  s\"\n    by(metis b2 b3 b4 b5 b6 a7 lemmaOnPtrAtGetX)\n with c1 b7  show False\n  by auto\nqed \n\n\nlemma lemmaOnPtr3[intro]:\n  assumes  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n    and a5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get )) s\" and\n    a6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2)) s \" and\n    a7:\"\\<forall>f. f \\<in> (invariants   N) \\<longrightarrow> formEval f s \" and\n    b2:\"iInv1' \\<le> N\" and  b3:\"iInv2' \\<le> N\" and  b4:\"iInv1'~=iInv2'  \" \n    and b5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1') )  ( Const UNI_GetX )) s\" and\n    b6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1') )   (Const iInv2')) s \" and\n    b7:\"iInv2\\<noteq>iInv2'\"\n shows False\n proof -\n  have c1:\"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n    by(metis a2 a3 a4 a5 a6 a7 lemmaOnPtrAtGet)\n  have c2:\"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2') )  s\"\n    by(metis b2 b3 b4 b5 b6 a7 lemmaOnPtrAtGetX)\n with c1 b7  show False\n  by auto\nqed      \n     \n\nabbreviation N::\"nat\"   where   \"N\\<equiv> M\"\nlemma NI_FAckVsInv54:  \n    (*Rule0VsPInv3*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv3 \\<le> N\" and  a4:\"iInv1~=iInv2  \" and  a5:\"iInv1~=iInv3  \" and  a6:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     \n     by (cut_tac a1 a2 a3 a4 a5, auto  ) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvVsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1VsInv54:  \n    (*newRule2VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv3 \\<le> N\" and  a6:\"iInv1~=iInv2  \" and  a7:\"iInv1~=iInv3  \" and  a8:\"iInv2~=iInv3  \" and  a9:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>iRule2=iInv3)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>iRule2=iInv3)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1=iInv3\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv3\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv3\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 )   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv3)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv3)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 )\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_InvAck_1_HomeVsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_2VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_GetXVsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak1VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak2VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak3VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX1VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv54:  \n    (*newRule2VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv3 \\<le> N\" and  a6:\"iInv1~=iInv2  \" and  a7:\"iInv1~=iInv3  \" and  a8:\"iInv2~=iInv3  \" and  a9:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>iRule2=iInv3)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>iRule2=iInv3)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1=iInv3\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv3\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv3\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 )   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv3)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 )\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10VsInv54:  \n    (*newRule2VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv3 \\<le> N\" and  a6:\"iInv1~=iInv2  \" and  a7:\"iInv1~=iInv3  \" and  a8:\"iInv2~=iInv3  \" and  a9:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>iRule2=iInv3)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>iRule2=iInv3)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1=iInv3\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv3\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv3\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 )   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv3)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 )\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10_homeVsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX11VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_GetVsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv3) )  ( Const UNI_PutX ))  )    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak1VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak2VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak3VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put1VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put2VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put3VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_PutVsInv54:  \n    (*Rule0VsPInv3*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv3 \\<le> N\" and  a4:\"iInv1~=iInv2  \" and  a5:\"iInv1~=iInv3  \" and  a6:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     \n     by (cut_tac a1 a2 a3 a4 a5, auto  ) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_PutXAcksDoneVsInv54:  \n    (*Rule0VsPInv3*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv3 \\<le> N\" and  a4:\"iInv1~=iInv2  \" and  a5:\"iInv1~=iInv3  \" and  a6:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     \n     by (cut_tac a1 a2 a3 a4 a5, auto  ) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_NakVsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Nak_ClearVsInv54:  \n    (*Rule0VsPInv3*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv3 \\<le> N\" and  a4:\"iInv1~=iInv2  \" and  a5:\"iInv1~=iInv3  \" and  a6:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     \n     by (cut_tac a1 a2 a3 a4 a5, auto  ) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Nak_HomeVsInv54:  \n    (*Rule0VsPInv3*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv3 \\<le> N\" and  a4:\"iInv1~=iInv2  \" and  a5:\"iInv1~=iInv3  \" and  a6:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     \n     by (cut_tac a1 a2 a3 a4 a5, auto  ) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_NakVsInv54:  \n    (*newRule2VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv3 \\<le> N\" and  a6:\"iInv1~=iInv2  \" and  a7:\"iInv1~=iInv3  \" and  a8:\"iInv2~=iInv3  \" and  a9:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>iRule2=iInv3)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>iRule2=iInv3)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1=iInv3\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv3\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv3\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 )   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv3)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 )\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_Nak_HomeVsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_PutXVsInv54Aux:  \n    (*newRule2VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv3 \\<le> N\" and  a6:\"iInv1~=iInv2  \" and  a7:\"iInv1~=iInv3  \" and  a8:\"iInv2~=iInv3  \" and  a9:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule'' s (inv54  iInv1  iInv2  iInv3 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>iRule2=iInv3)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>iRule2=iInv3)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1=iInv3\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv3\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv3\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 )   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv3)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>iRule2=iInv1)\"\n\n                  \n     have \"invHoldForRule3' s (inv54  iInv1  iInv2  iInv3 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" \n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n\n      then  have \"?P3 s\"  by(rule weak3)\n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>iRule2=iInv2)\"\n\n     have \"invHoldForRule3' s (inv54  iInv1  iInv2  iInv3 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\"              \n    \n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))  \n          ( eqn ( IVar ( Para ''UniMsg_proc'' iInv3) )   (Const iInv2))  )    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv3) )  ( Const UNI_GetX ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n      then  have \"?P3 s\"  by(rule weak3)\n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n\t              \n\t\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  \n     have \"?P3 s\"\n                  proof( unfold invHoldForRule3''_def,simp only:Let_def,( rule impI)+,                   rule ccontr)\n                    assume c1:\"\\<forall>f'. f' \\<in> invariants N \\<longrightarrow> formEval f' s\" and c2:\"formEval (pre (NI_Remote_GetX_PutX iRule1 iRule2)) s \"\n                    and c3:\"\\<not> formEval (substFormByStatement (inv54 iInv1 iInv2 iInv3) (act (NI_Remote_GetX_PutX iRule1 iRule2))) s\"\n                   have d1:\" formEval (eqn (IVar (Para ''UniMsg_Cmd'' iInv1)) (Const UNI_Get)) s\" by(cut_tac a7 b1 c2 c3, auto)\n                   have d2:\"formEval (eqn (IVar (Para ''UniMsg_Cmd'' iRule1)) (Const UNI_GetX)) s\" by(cut_tac b1 c2 c3, auto)\n                   have d3:\"formEval (eqn (IVar (Para ''UniMsg_proc'' iInv1)) (Const iInv2)) s\"  by(cut_tac b1 c2 c3, auto)\n                   have d4:\"formEval (eqn (IVar (Para ''UniMsg_proc'' iRule1)) (Const iRule2)) s\"  by(cut_tac b1 c2 c3, auto)\n                    show False thm lemmaOnPtr2\n                    apply(cut_tac a1 a2 a3 a4 a5 a6 b1 c1 c2 c3 d1 d2 d3 d4,blast )\n                    done\n                   qed\n         \n      \n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }              \n\t              \n\nmoreover\n                {assume b1:\"(iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 )\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\n\nlemma NI_Remote_GetX_PutXVsInv54:  \n    (*newRule2VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv3 \\<le> N\" and  a6:\"iInv1~=iInv2  \" and  a7:\"iInv1~=iInv3  \" and  a8:\"iInv2~=iInv3  \" and  a9:\"iRule1~=iRule2  \" \n   shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n  by (metis NI_Remote_GetX_PutXVsInv54Aux a2 a3 a4 a5 a6 a7 a8  a9 local.a1  strengthEn)\n  \nlemma NI_Remote_GetX_PutX_HomeVsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Nak1VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Nak2VsInv54:  \n    (*newRule2VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv3 \\<le> N\" and  a6:\"iInv1~=iInv2  \" and  a7:\"iInv1~=iInv3  \" and  a8:\"iInv2~=iInv3  \" and  a9:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>iRule2=iInv3)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>iRule2=iInv3)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1=iInv3\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv3\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv3\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 )   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv3)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 )\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Put1VsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Put2VsInv54:  \n    (*newRule2VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv3 \\<le> N\" and  a6:\"iInv1~=iInv2  \" and  a7:\"iInv1~=iInv3  \" and  a8:\"iInv2~=iInv3  \" and  a9:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>iRule2=iInv3)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>iRule2=iInv3)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1=iInv3\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv3\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv3\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))   \\<or>(iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 )   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv3)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 \\<and>iRule2~=iInv3 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 )\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  a8  a9  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutVsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutXVsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_ReplaceVsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceHomeVsInv54:  \n    (*Rule0VsPInv3*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv3 \\<le> N\" and  a4:\"iInv1~=iInv2  \" and  a5:\"iInv1~=iInv3  \" and  a6:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     \n     by (cut_tac a1 a2 a3 a4 a5, auto  ) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceHomeShrVldVsInv54:  \n    (*Rule0VsPInv3*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv3 \\<le> N\" and  a4:\"iInv1~=iInv2  \" and  a5:\"iInv1~=iInv3  \" and  a6:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     \n     by (cut_tac a1 a2 a3 a4 a5, auto  ) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceShrVldVsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ShWbVsInv54:  \n    (*Rule0VsPInv3*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv3 \\<le> N\" and  a4:\"iInv1~=iInv2  \" and  a5:\"iInv1~=iInv3  \" and  a6:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     \n     by (cut_tac a1 a2 a3 a4 a5, auto  ) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_WbVsInv54:  \n    (*Rule0VsPInv3*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv3 \\<le> N\" and  a4:\"iInv1~=iInv2  \" and  a5:\"iInv1~=iInv3  \" and  a6:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     \n     by (cut_tac a1 a2 a3 a4 a5, auto  ) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_GetX1VsInv54:  \n    (*Rule0VsPInv3*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv3 \\<le> N\" and  a4:\"iInv1~=iInv2  \" and  a5:\"iInv1~=iInv3  \" and  a6:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     \n     by (cut_tac a1 a2 a3 a4 a5, auto  ) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_GetX2VsInv54:  \n    (*Rule0VsPInv3*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv3 \\<le> N\" and  a4:\"iInv1~=iInv2  \" and  a5:\"iInv1~=iInv3  \" and  a6:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     \n     by (cut_tac a1 a2 a3 a4 a5, auto  ) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX1VsInv54:  \n    (*Rule0VsPInv3*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv3 \\<le> N\" and  a4:\"iInv1~=iInv2  \" and  a5:\"iInv1~=iInv3  \" and  a6:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     \n     by (cut_tac a1 a2 a3 a4 a5, auto  ) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX2VsInv54:  \n    (*Rule0VsPInv3*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv3 \\<le> N\" and  a4:\"iInv1~=iInv2  \" and  a5:\"iInv1~=iInv3  \" and  a6:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     \n     by (cut_tac a1 a2 a3 a4 a5, auto  ) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX3VsInv54:  \n    (*Rule0VsPInv3*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv3 \\<le> N\" and  a4:\"iInv1~=iInv2  \" and  a5:\"iInv1~=iInv3  \" and  a6:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     \n     by (cut_tac a1 a2 a3 a4 a5, auto  ) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX4VsInv54:  \n    (*Rule0VsPInv3*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv3 \\<le> N\" and  a4:\"iInv1~=iInv2  \" and  a5:\"iInv1~=iInv3  \" and  a6:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     \n     by (cut_tac a1 a2 a3 a4 a5, auto  ) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_Get_GetVsInv54:  \n    (*Rule0VsPInv3*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv3 \\<le> N\" and  a4:\"iInv1~=iInv2  \" and  a5:\"iInv1~=iInv3  \" and  a6:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     \n     by (cut_tac a1 a2 a3 a4 a5, auto  ) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_Get_PutVsInv54:  \n    (*Rule0VsPInv3*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv3 \\<le> N\" and  a4:\"iInv1~=iInv2  \" and  a5:\"iInv1~=iInv3  \" and  a6:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     \n     by (cut_tac a1 a2 a3 a4 a5, auto  ) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_PutXVsInv54:  \n    (*Rule0VsPInv3*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv3 \\<le> N\" and  a4:\"iInv1~=iInv2  \" and  a5:\"iInv1~=iInv3  \" and  a6:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     \n     by (cut_tac a1 a2 a3 a4 a5, auto  ) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_ReplaceVsInv54:  \n    (*Rule0VsPInv3*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv3 \\<le> N\" and  a4:\"iInv1~=iInv2  \" and  a5:\"iInv1~=iInv3  \" and  a6:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     \n     by (cut_tac a1 a2 a3 a4 a5, auto  ) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_GetVsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_GetXVsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>(iRule1=iInv3)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  a7  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv3)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 \\<and>iRule1~=iInv3 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  a7  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_PutXVsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_ReplaceVsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma StoreVsInv54:  \n    (*Rule1VsPInv3*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv3 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iInv1~=iInv3  \" and  a7:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma StoreHomeVsInv54:  \n    (*Rule0VsPInv3*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv3 \\<le> N\" and  a4:\"iInv1~=iInv2  \" and  a5:\"iInv1~=iInv3  \" and  a6:\"iInv2~=iInv3  \" \n\n  shows  \"invHoldForRule' s (inv54  iInv1  iInv2  iInv3 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     \n     by (cut_tac a1 a2 a3 a4 a5, auto  ) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash54Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5888891163376235, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.2783581548544024}}
{"text": "section \"Program Proof Rules\"\n\ntheory program_proof_rules\n  imports \n    invariant_simps \n    unique_ids2\n    single_invocation_correctness2\n    \"Case_Labeling.Case_Labeling\"\n    execution_invariants2\n    execution_invariants_s\n    execution_invariants_unused\n    impl_language\n    topological_sort\n    program_verification_tactics\nbegin\n\ntext \"We define some proof rules for our implementation languages, so that \nwe can automate the generation of verification conditions.\n\nThe proof rules can simulate symbolic execution of a procedure.\nWe add some additional state compared to the system state in the semantics, so that we can derive\nadditional assumptions for the verification conditions.\"\n\ndefinition execution_s_check where\n  \"execution_s_check \n  progr \n  i\n  s_calls \n  s_happensBefore \n  s_callOrigin \n  s_txOrigin \n  s_knownIds \n  s_invocOp\n  s_invocRes\n  generatedLocal\n  generatedLocalPrivate\n  vis\n  localCalls\n  tx\n  firstTx\n  ls\n \\<equiv>  (\\<forall>trace S1 S'. \n           (S1 ~~ (i, trace) \\<leadsto>\\<^sub>S* S')\n       \\<longrightarrow> (\\<forall>p t. (AInvoc p, t) \\<notin> set trace)\n       \\<longrightarrow> state_wellFormed S1\n       \\<longrightarrow> calls S1 = s_calls\n       \\<longrightarrow> happensBefore S1 = updateHb s_happensBefore vis localCalls\n       \\<longrightarrow> callOrigin S1 = map_update_all s_callOrigin localCalls (the tx)\n       \\<longrightarrow> txOrigin S1 = s_txOrigin\n       \\<longrightarrow> knownIds S1 = s_knownIds\n       \\<longrightarrow> invocOp S1 = s_invocOp\n       \\<longrightarrow> invocRes S1 = s_invocRes\n       \\<longrightarrow> prog S1 = progr\n       \\<longrightarrow> generatedLocal = {x. generatedIds S1 x \\<triangleq> i}\n       \\<longrightarrow> localState S1 i \\<triangleq> ls\n       \\<longrightarrow> currentProc S1 i \\<triangleq> toImpl\n       \\<longrightarrow> visibleCalls S1 i \\<triangleq>  (vis \\<union> set localCalls)\n       \\<longrightarrow> currentTx S1 i = tx\n       \\<longrightarrow> (\\<forall>tx'. tx \\<noteq> Some tx' \\<longrightarrow> txStatus S1 tx' \\<noteq> Some Uncommitted)\n       \\<longrightarrow> (case tx of Some tx' \\<Rightarrow> set localCalls =  {c. callOrigin S1 c \\<triangleq> tx'} | None \\<Rightarrow> localCalls = [])\n       \\<longrightarrow> (sorted_by (happensBefore S1) localCalls)\n       \\<longrightarrow> (vis \\<inter> set localCalls = {})\n       \\<longrightarrow> (dom s_callOrigin \\<inter> set localCalls = {})\n       \\<longrightarrow> (Field s_happensBefore \\<inter> set localCalls = {})\n       \\<longrightarrow> distinct localCalls\n       \\<longrightarrow> (firstTx \\<longleftrightarrow> (\\<nexists>c tx . callOrigin S1 c \\<triangleq> tx \\<and> txOrigin S1 tx \\<triangleq> i \\<and> txStatus S1 tx \\<triangleq> Committed ))\n       \\<longrightarrow> (\\<forall>c. i_callOriginI_h s_callOrigin s_txOrigin c \\<triangleq> i \\<longrightarrow> c \\<in> vis)\n       \\<longrightarrow> (generatedLocalPrivate \\<subseteq> generatedLocal)\n       \\<longrightarrow> (\\<forall>v\\<in>generatedLocalPrivate. uid_is_private i S1 v)\n       \\<longrightarrow> traceCorrect_s  trace)\"\n\nlemmas use_execution_s_check = execution_s_check_def[THEN meta_eq_to_obj_eq, THEN iffD1, rule_format, rotated]\n\nlemma beforeInvoc_execution_s_check: \n  assumes \"s_invocOp i = None\"\n  shows \"\nexecution_s_check   progr   i  s_calls   s_happensBefore   s_callOrigin   s_txOrigin   s_knownIds   s_invocOp  s_invocRes  generatedLocal generatedLocalPrivate  vis localCalls  tx firstTx ls\n\"\n  using assms \n  by (auto simp add: execution_s_check_def steps_s_cons_simp Let_def wf_localState_to_invocOp)\n\n\n\n\n\ntext \"It is sufficient to check with @{term execution_s_check} to ensure that the procedure is correct:\"\n\n\n\nlemma execution_s_check_sound:\n  assumes ls_def: \"localState S i \\<triangleq> ls\"\n    and vis_def: \"visibleCalls S i \\<triangleq> vis\"\n    and progr_def: \"prog S = progr\"\n    and toImpl: \"currentProc S i \\<triangleq> toImpl\"\n    and generatedLocal: \"generatedLocal = {x. generatedIds S x \\<triangleq> i}\"\n    and generatedLocalPrivate1: \"generatedLocalPrivate \\<subseteq> generatedLocal\"\n    and generatedLocalPrivate2: \"\\<forall>v\\<in>generatedLocalPrivate. uid_is_private i S v\"\n    and S_wf: \"state_wellFormed S\"\n    and no_uncommitted: \"\\<And>tx'. currentTx S i \\<noteq> Some tx' \\<longrightarrow> txStatus S tx' \\<noteq> Some Uncommitted\"\n    and no_currentTxn: \"currentTx S i = None\"\n    and firstTx_def: \"(firstTx \\<longleftrightarrow> (\\<nexists>c tx . callOrigin S c \\<triangleq> tx \\<and> txOrigin S tx \\<triangleq> i \\<and> txStatus S tx \\<triangleq> Committed ))\"\n    and c: \"execution_s_check \n  progr \n  i\n  (calls S)\n  (happensBefore S)\n  (callOrigin S)\n  (txOrigin S)\n  (knownIds S)\n  (invocOp S)\n  (invocRes S)\n  generatedLocal\n  generatedLocalPrivate\n  vis\n  []\n  (currentTx S i)\n  firstTx\n  ls\"\n  shows \"execution_s_correct S i\"\nproof (auto simp add:  execution_s_correct_def)\n  fix trace S'\n  assume a0: \"S ~~ (i, trace) \\<leadsto>\\<^sub>S* S'\"\n\n\n  from a0\n  show \"traceCorrect_s  trace\"\n  proof (rule c[simplified execution_s_check_def, rule_format]; force?)\n    show \"state_wellFormed S\"\n      by (simp add: assms)\n\n    show \"\\<And>p t. (AInvoc p, t) \\<notin> set trace\"\n      using a0 assms no_more_invoc by blast\n\n\n    show \"prog S = progr\"\n      by (simp add: assms)\n\n    show \" generatedLocal = {x. generatedIds S x \\<triangleq> i}\"\n      by (auto simp add: assms)\n\n    show \"localState S i \\<triangleq> ls\"\n      by (simp add: assms(1))\n\n    show \"currentProc S i \\<triangleq> toImpl\"\n      by (simp add: assms)\n\n    show \"currentTx S i \\<noteq> Some tx' \\<Longrightarrow> txStatus S tx' \\<noteq> Some Uncommitted\" for tx'\n      by (simp add: assms)\n\n    show \"visibleCalls S i \\<triangleq> (vis \\<union> set [])\"\n      by (simp add: assms)\n\n    show \"case currentTx S i of None \\<Rightarrow> [] = [] | Some tx' \\<Rightarrow> set [] = {c. callOrigin S c \\<triangleq> tx'}\"\n      by (simp add: no_currentTxn)\n\n    show \"sorted_by (happensBefore S) []\"\n      by (simp add: sorted_by_empty)\n    show \"firstTx = (\\<nexists>c tx. callOrigin S c \\<triangleq> tx \\<and> txOrigin S tx \\<triangleq> i \\<and> txStatus S tx \\<triangleq> Committed)\"\n      using firstTx_def by auto\n\n    show \"\\<And>c. i_callOriginI S c \\<triangleq> i \\<Longrightarrow> c \\<in> vis\"\n      apply (auto simp add: i_callOriginI_h_def split: option.splits)\n      using S_wf state_wellFormed_ls_visibleCalls_callOrigin vis_def by blast\n\n    show \"generatedLocalPrivate \\<subseteq> generatedLocal\"\n      by (simp add: generatedLocalPrivate1)\n\n    show \"\\<And>x. x \\<in> generatedLocalPrivate \\<Longrightarrow>\n         uid_is_private i S x\"\n      by (simp add: generatedLocalPrivate2)\n\n\n  qed\nqed\n\n\nlemma execution_s_check_sound2:\n  assumes a1: \"localState S i \\<triangleq> ls\"\n    and a2': \"S \\<in> initialStates' progr i\"\n    and a3: \"currentProc S i \\<triangleq> toImpl\"\n    and c: \"\\<And>s_calls s_happensBefore s_callOrigin s_txOrigin s_knownIds s_invocOp s_invocRes.\n\\<lbrakk>\ns_invocOp i = invocOp S i;\ns_invocRes i = None;\n\\<And>tx. s_txOrigin tx \\<noteq> Some i\n\\<rbrakk> \\<Longrightarrow>\n  execution_s_check \n  progr \n  i\n  s_calls\n  s_happensBefore\n  s_callOrigin\n  s_txOrigin\n  s_knownIds\n  s_invocOp\n  s_invocRes\n  {}\n  {}\n  {}\n  []\n  None\n  True\n  ls\"\n  shows \"execution_s_correct S i\"\n  using a1\nproof (rule execution_s_check_sound)\n\n  have a2: \"S \\<in> initialStates progr i\"\n    using a2' by (simp add: initialStates'_same) \n\n  show \"visibleCalls S i \\<triangleq> {}\"\n    using a2 by (auto simp add: initialStates_def)\n\n  show \"prog S = progr\"\n    using a2 by (auto simp add: initialStates_def)\n\n  show \"currentProc S i \\<triangleq> toImpl\"\n    using a3 by simp\n\n  show wf: \"state_wellFormed S\"\n\n    using a2 initialStates_wellFormed by blast\n\n  show \"{} = {x. generatedIds S x \\<triangleq> i}\"\n    using a2 wf_generated_ids_invocation_exists by (auto simp add: initialStates_def, blast)\n\n  show currentTx: \"currentTx S i = None\"\n    using a2 initialState_noTxns2 by blast\n\n\n  show \"execution_s_check progr i (calls S) (happensBefore S) (callOrigin S) (txOrigin S) (knownIds S) (invocOp S)\n     (invocRes S) {} {} {} [] (currentTx S i) True ls \"\n    unfolding currentTx\n  proof (rule c)\n    show \"invocOp S i = invocOp S i\" by simp\n    show \"invocRes S i = None\"\n      by (simp add: a1 local.wf state_wellFormed_no_result_when_running)\n    show \"\\<And>tx. txOrigin S tx \\<noteq> Some i\"\n      using a2 by (auto simp add: initialStates_def)\n\n  qed\n\n  show \"\\<And>tx'. currentTx S i \\<noteq> Some tx' \\<longrightarrow> txStatus S tx' \\<noteq> Some Uncommitted\"\n    using a2 initialState_noTxns1 by blast\n\n  show \"True = (\\<nexists>c tx. callOrigin S c \\<triangleq> tx \\<and> txOrigin S tx \\<triangleq> i \\<and> txStatus S tx \\<triangleq> Committed)\"\n    by (meson \\<open>visibleCalls S i \\<triangleq> {}\\<close> empty_iff local.wf state_wellFormed_ls_visibleCalls_callOrigin)\n\n\nqed simp+\n\n\nlemma execution_s_check_sound3:\n  assumes a1: \"localState S i \\<triangleq> ls\"\n    and a2: \"S \\<in> initialStates' progr i\"\n    and a3: \"currentProc S i \\<triangleq> toImpl\"\n    and a4: \"invocOp S i \\<triangleq> op\"\n    and c: \"\\<And>s_calls s_happensBefore s_callOrigin s_txOrigin s_knownIds s_invocOp s_invocRes.\n\\<lbrakk>\n\\<And>tx. s_txOrigin tx \\<noteq> Some i\n\\<rbrakk> \\<Longrightarrow>\n  execution_s_check \n  progr \n  i\n  s_calls\n  s_happensBefore\n  s_callOrigin\n  s_txOrigin\n  s_knownIds\n  (s_invocOp(i\\<mapsto>op))\n  (s_invocRes(i:=None))\n  {}\n  {}\n  {}\n  []\n  None\n  True\n  ls\"\n  shows \"execution_s_correct S i\"\n  by (smt a1 a2 a3 a4 c execution_s_check_sound2 fun_upd_triv)\n\nlemma traceCorrect_s_empty: \"traceCorrect_s  [] \"\n  by (simp add: traceCorrect_s_def) \n\nlemma case_trace_not_empty:\n  assumes  \"\\<And>a trace'. trace = a#trace' \\<Longrightarrow> traceCorrect_s  (a#trace')\"\n  shows \"traceCorrect_s  trace\"\n  using assms by (cases trace, auto simp add: traceCorrect_s_empty)\n\nlemma case_trace_not_empty2:\n  assumes  \"\\<And>action Inv trace'. trace = (action, Inv)#trace' \\<Longrightarrow> traceCorrect_s  ((action, Inv)#trace')\"\n  shows \"traceCorrect_s  trace\"\n  using assms by (cases trace, auto simp add: traceCorrect_s_empty)\n\nlemma case_trace_not_empty3:\n  assumes \"S ~~ (i,trace) \\<leadsto>\\<^sub>S* S''\"\n    and \"\\<And>action S' Inv trace'. \\<lbrakk>\n      trace = (action, Inv)#trace'; \n      S ~~ (i,action,Inv) \\<leadsto>\\<^sub>S S'; \n      S' ~~ (i,trace') \\<leadsto>\\<^sub>S* S''\\<rbrakk> \\<Longrightarrow> Inv \\<and> traceCorrect_s (trace')\"\n  shows \"traceCorrect_s  trace\"\n  by (metis assms(1) assms(2) case_trace_not_empty2 sndI steps_s_cons_simp traceCorrect_s_split)\n\n\nlemma sorted_by_updateHb:\n  assumes \"set cs \\<inter> vis = {}\"\n    and \"set cs \\<inter> Field hb = {}\"\n    and \"distinct cs\"\n  shows \"sorted_by (updateHb hb vis cs) cs\"\n  using assms proof (induct cs arbitrary: hb vis)\ncase Nil\n  then show ?case \n    by (simp add: sorted_by_empty)\n\nnext\n  case (Cons x xs)\n\n  have \"distinct xs\"\n    using Cons.prems(3) by auto\n\n\n  from this\n  have IH: \"sorted_by (updateHb (hb \\<union> vis \\<times> {x}) (insert x vis) xs) xs\"\n  proof (fuzzy_rule Cons)\n\n    show \" set xs \\<inter> insert x vis = {}\"\n      using Cons by auto\n    show \" set xs \\<inter> Field (hb \\<union> vis \\<times> {x}) = {}\"\n      using Cons by (auto simp add: Field_def)\n  qed\n\n  show ?case \n  proof (auto simp add: updateHb.simps)\n    show \"sorted_by (updateHb (hb \\<union> vis \\<times> {x}) (insert x vis) xs) (x # xs)\"\n      apply (auto simp add: sorted_by_cons_iff IH)\n      using Cons.prems(1) Cons.prems(2) Cons.prems(3) FieldI1 updateHb_simp2 by fastforce\n  qed\nqed\n\nlemma no_ainvoc:\n  assumes \"\\<forall>p t. (AInvoc p, t) \\<notin> set trace\"\n    and \"trace = (action, Inv) # trace'\"\nand \"\\<lbrakk>\\<forall>p t. (AInvoc p, t) \\<notin> set trace; \\<And>proc. action \\<noteq> AInvoc proc\\<rbrakk> \\<Longrightarrow> P\"\nshows \"P\"\n  using assms by auto\n\nmethod show_proof_rule = \n  (subst  execution_s_check_def, intro allI impI, erule case_trace_not_empty3, erule(1) no_ainvoc, fuzzy_goal_cases Step)\n\ninductive_cases step_s_NewId: \"S ~~ (i, ANewId uidv, Inv) \\<leadsto>\\<^sub>S S'\"\n\nlemma execution_s_check_newId:\n  assumes \"infinite (Collect P)\"\n    and \"program_wellFormed progr\"\n    and cont: \"\\<And>v. \\<lbrakk>P v; \nto_nat v \\<notin> s_knownIds;\nto_nat v \\<notin> generatedLocal;\nuniqueIds v = {to_nat v};\nuid_is_private' i s_calls s_invocOp s_invocRes s_knownIds (to_nat v)\n\\<rbrakk> \\<Longrightarrow> execution_s_check\n  progr \n  i\n  s_calls \n  s_happensBefore \n  s_callOrigin \n  s_txOrigin \n  s_knownIds \n  s_invocOp\n  s_invocRes\n  (generatedLocal \\<union> {to_nat v})\n  (generatedLocalPrivate \\<union> {to_nat v})\n  vis\n  localCalls\n  tx\n  firstTx\n  (cont v)\"\n\nshows\"execution_s_check\n  progr \n  i\n  s_calls \n  s_happensBefore \n  s_callOrigin \n  s_txOrigin \n  s_knownIds \n  s_invocOp\n  s_invocRes\n  generatedLocal\n  generatedLocalPrivate\n  vis\n  localCalls\n  tx\n  firstTx\n  (newId P \\<bind> cont)\n\"\nproof show_proof_rule\n  case (Step trace S1 S' action S'a Inv trace')\n\n\n  from ` S1 ~~ (i, action, Inv) \\<leadsto>\\<^sub>S S'a`\n    `localState S1 i \\<triangleq> (newId P \\<bind> cont)`\n    `currentProc S1 i \\<triangleq> toImpl`\n    `\\<And>proc. action \\<noteq> AInvoc proc`\n  obtain uidv\n    where c0: \"localState S1 i \\<triangleq> (newId P \\<bind> cont)\"\n      and c1: \"currentProc S1 i \\<triangleq> toImpl\"\n      and c2: \"action = ANewId uidv\"\n      and c3: \"Inv\"\n      and S'a_def: \"S'a = S1\\<lparr>localState := localState S1(i \\<mapsto> cont uidv), generatedIds := generatedIds S1(to_nat uidv \\<mapsto> i)\\<rparr>\"\n      and c5: \"generatedIds S1 (to_nat uidv) = None\"\n      and c6: \"uniqueIds uidv = {to_nat uidv}\"\n      and c7: \"P uidv\"\n    by (auto simp add: step_s.simps split:if_splits)\n\n  show \"Inv \\<and> traceCorrect_s trace'\"\n  proof (intro conjI)\n    show \"Inv\" using `Inv` .\n\n    from `S'a ~~ (i, trace') \\<leadsto>\\<^sub>S* S'`\n    show \"traceCorrect_s trace'\"\n    proof (rule use_execution_s_check)\n\n\n      have h1: \"new_unique_not_in_calls s_calls (to_nat uidv)\"\n        using Step.calls_eq Step.prog_eq Step.state_wellFormed assms(2) c5 new_unique_not_in_calls_def wf_onlyGeneratedIdsInCalls by blast\n\n\n      have h2: \"new_unique_not_in_calls_result s_calls (to_nat uidv)\"\n        using Step.calls_eq Step.prog_eq Step.state_wellFormed assms(2) c5 new_unique_not_in_calls_result_def wf_onlyGeneratedIdsInCallResults by blast\n\n      have h3: \"new_unique_not_in_invocOp s_invocOp (to_nat uidv)\"\n        using Step.invocOp_eq Step.prog_eq Step.state_wellFormed assms(2) c5 new_unique_not_in_invocOp_def wf_onlyGeneratedIdsInInvocationOps by blast\n\n      have h4: \"new_unique_not_in_invocRes s_invocRes (to_nat uidv)\"\n        using Step.invocRes_eq Step.prog_eq Step.state_wellFormed assms(2) c5 new_unique_not_in_invocRes_def wf_onlyGeneratedIdsInInvocationRes by blast\n\n\n      have h5: \"new_unique_not_in_other_invocations i S'a (to_nat uidv)\"\n        unfolding new_unique_not_in_other_invocations_def\n      proof (intro allI impI)\n        fix i'\n        assume a0: \"i' \\<noteq> i\"\n\n        have \"program_wellFormed (prog S1)\"\n          by (simp add: Step.prog_eq assms(2))\n\n\n        obtain uids \n          where \"uids\\<subseteq>dom (generatedIds S1)\" and \"invocation_cannot_guess_ids uids i' S1\"\n          using wf_knownIds_subset_generatedIds_h(1)[OF `state_wellFormed S1` `program_wellFormed (prog S1)`]\n          by auto\n\n\n        from `uids\\<subseteq>dom (generatedIds S1)`\n          and `generatedIds S1 (to_nat uidv) = None`\n        have \" to_nat uidv \\<notin> uids\"\n          by auto\n\n\n        show \"\\<exists>uids. to_nat uidv \\<notin> uids \\<and> invocation_cannot_guess_ids uids i' S'a\"\n          using Step.step_s \\<open>invocation_cannot_guess_ids uids i' S1\\<close> \\<open>to_nat uidv \\<notin> uids\\<close> a0 c2 show_invocation_cannot_guess_ids_step_other step_s_to_step  by fastforce\n      qed\n\n\n\n      have h6: \"to_nat uidv \\<notin> s_knownIds\"\n        using Step.knownIds_eq Step.prog_eq Step.state_wellFormed assms(2) c5 wf_onlyGeneratedIdsInKnownIds by blast\n\n\n      show \"execution_s_check\n            progr \n            i\n            s_calls \n            s_happensBefore \n            s_callOrigin \n            s_txOrigin \n            s_knownIds \n            s_invocOp\n            s_invocRes\n            (generatedLocal \\<union> {to_nat uidv})\n            (generatedLocalPrivate \\<union> {to_nat uidv})\n            vis\n            localCalls\n            tx\n            firstTx\n            (cont uidv)\"\n      proof (rule cont)\n        show \"P uidv\"\n          by (simp add: c7)\n\n        \n        show \"to_nat uidv \\<notin> s_knownIds\"\n          using h6 by auto\n\n        show \"to_nat uidv \\<notin> generatedLocal\"\n          by (simp add: Step.generatedLocal_def c5)\n\n        show \"uniqueIds uidv = {to_nat uidv}\"\n          by (simp add: c6)\n\n        show \"uid_is_private' i s_calls s_invocOp s_invocRes s_knownIds (to_nat uidv)\"\n          by (simp add: h1 h2 h3 h4 h6 uid_is_private'_def)\n\n\n      qed\n\n\n      show \"\\<And>p t. (AInvoc p, t) \\<notin> set trace'\"\n        using Step by auto\n\n      show \"state_wellFormed S'a\"\n        using Step state_wellFormed_combine_s1 by blast\n\n      show \"case tx of None \\<Rightarrow> localCalls = [] | Some tx' \\<Rightarrow> set localCalls = {c. callOrigin S'a c \\<triangleq> tx'}\"\n        using Step.case_option by  (auto simp add: S'a_def  split: option.splits)\n\n      show \"sorted_by (happensBefore S'a) localCalls\"\n        using Step by (auto simp add:S'a_def )\n\n      show \"generatedLocal \\<union> {to_nat uidv} = {x. generatedIds S'a x \\<triangleq> i}\"\n        by (auto simp add: S'a_def Step)\n\n      show \"generatedLocalPrivate \\<union> {to_nat uidv} \\<subseteq> generatedLocal \\<union> {to_nat uidv}\"\n        apply (auto simp add: S'a_def Step)\n        using Step.Ball uid_is_private_def by blast\n\n      \n\n      show \"uid_is_private i S'a v\" if \"v \\<in> generatedLocalPrivate \\<union> {to_nat uidv}\" for v\n        using that proof auto\n\n        show  \"uid_is_private i S'a (to_nat uidv)\"\n          using S'a_def h5 by (auto simp add: uid_is_private_def S'a_def Step h1 h2 h3 h4 h5 h6)\n\n          \n\n        show \"uid_is_private i S'a v\" if \"v \\<in> generatedLocalPrivate\"\n          unfolding uid_is_private_def\n        proof (intro conjI)\n\n          have pre: \"uid_is_private i S1 v\" \n            by (simp add: Step.Ball that)\n\n          show \"new_unique_not_in_invocOp (invocOp S'a) v\"\n            using pre by (auto simp add: uid_is_private_def S'a_def)\n\n\n          show \"new_unique_not_in_calls (calls S'a) v\"\n            using pre by (auto simp add: uid_is_private_def S'a_def)\n          show \"new_unique_not_in_calls_result (calls S'a) v\"\n            using pre by (auto simp add: uid_is_private_def S'a_def)\n          show \"new_unique_not_in_invocRes (invocRes S'a) v\"\n            using pre by (auto simp add: uid_is_private_def S'a_def)\n          show \"v \\<notin> knownIds S'a\"\n            using pre by (auto simp add: uid_is_private_def S'a_def)\n          show \"generatedIds S'a v \\<triangleq> i\"\n            using pre by (auto simp add: uid_is_private_def S'a_def)\n          show \"new_unique_not_in_other_invocations i S'a v\"\n            using pre proof (auto simp add: uid_is_private_def )\n\n            show \"new_unique_not_in_other_invocations i S'a v\"\n              if c0: \"new_unique_not_in_invocOp (invocOp S1) v\"\n                and c1: \"new_unique_not_in_calls (calls S1) v\"\n                and c2: \"new_unique_not_in_calls_result (calls S1) v\"\n                and c3: \"new_unique_not_in_invocRes (invocRes S1) v\"\n                and c4: \"v \\<notin> knownIds S1\"\n                and c5: \"generatedIds S1 v \\<triangleq> i\"\n                and c6: \"new_unique_not_in_other_invocations i S1 v\"\n             \n            using c6 proof (auto simp add: new_unique_not_in_other_invocations_def)\n            fix i'\n            assume a0: \"\\<forall>i'. i' \\<noteq> i \\<longrightarrow> (\\<exists>uids. v \\<notin> uids \\<and> invocation_cannot_guess_ids uids i' S1)\"\n              and a1: \"i' \\<noteq> i\"\n\n            obtain uids where \"v \\<notin> uids\" and \"invocation_cannot_guess_ids uids i' S1\"\n              using a0 a1 by auto\n\n            have \"i \\<noteq> i'\" using a1 by simp\n\n            have \"invocation_cannot_guess_ids uids i' S'a\"\n              using `invocation_cannot_guess_ids uids i' S1` `S1 ~~ (i, action, Inv) \\<leadsto>\\<^sub>S S'a`\n              by (rule show_invocation_cannot_guess_ids_step_s_other)\n                (auto simp add: `action = ANewId uidv` `i \\<noteq> i'`)\n\n\n            thus \"\\<exists>uids. v \\<notin> uids \\<and> invocation_cannot_guess_ids uids i' S'a\"\n              using \\<open>v \\<notin> uids\\<close> by blast\n\n          qed\n\n        qed\n      qed\n    qed\n        \n\n    qed (simp add: S'a_def Step; fail)+\n  qed\nqed\n\n\n\n\n\nlemma execution_s_check_beginAtomic:\n  assumes \"program_wellFormed progr\"\n    and cont: \"\\<And>tx s_calls' s_happensBefore' s_callOrigin' s_txOrigin' s_knownIds' vis'\n s_invocOp' s_invocRes' .\n\\<lbrakk>invariant progr\n     \\<lparr>calls = s_calls', \n      happensBefore = s_happensBefore',\n      callOrigin = s_callOrigin',\n      txOrigin = s_txOrigin', \n      knownIds = s_knownIds',\n      invocOp = (s_invocOp'(i := s_invocOp i)), \n      invocRes = s_invocRes'(i := None)\\<rparr>;\ns_txOrigin' tx = None;\n\\<And>i op. s_invocOp i \\<triangleq> op \\<Longrightarrow> s_invocOp' i \\<triangleq> op;\n\\<And>c. s_callOrigin' c \\<noteq> Some tx;\nvis \\<subseteq> vis';\nvis' \\<subseteq> dom s_calls';\nfirstTx \\<Longrightarrow> (\\<And>c tx. s_callOrigin' c \\<triangleq> tx \\<Longrightarrow> s_txOrigin' tx \\<noteq> Some i);\n\\<comment> \\<open>consistency: \\<close>\ncausallyConsistent s_happensBefore' vis';\ntransactionConsistent_atomic s_callOrigin' vis';\n\\<forall>v\\<in>generatedLocalPrivate. uid_is_private' i s_calls' s_invocOp' s_invocRes' s_knownIds' v;\n\\<comment> \\<open>generic wellFormed and growth predicates (this is more like a backup, the important facts should be above) : \\<close>\n\\<exists>some_generatedIds some_currentTx some_localState some_currentProc some_visibleCalls some_txStatus.\nstate_wellFormed \\<lparr>\n  calls = s_calls',\n  happensBefore = s_happensBefore',\n  callOrigin = s_callOrigin',\n  txOrigin = s_txOrigin',\n  knownIds = s_knownIds',\n  invocOp = s_invocOp',\n  invocRes = s_invocRes',\n  prog = progr,\n  txStatus = some_txStatus,\n  generatedIds =  some_generatedIds,\n  localState = some_localState,\n  currentProc = some_currentProc,\n  visibleCalls =  some_visibleCalls,\n  currentTx = some_currentTx\\<rparr>;\n \\<exists>some_generatedIds1 some_currentTx1 some_localState1 some_currentProc1 some_visibleCalls1 some_txStatus1\n  some_generatedIds2 some_currentTx2 some_localState2 some_currentProc2 some_visibleCalls2 some_txStatus2.\nstate_monotonicGrowth i \\<lparr>\n  calls = s_calls,\n  happensBefore = s_happensBefore,\n  callOrigin = s_callOrigin,\n  txOrigin = s_txOrigin,\n  knownIds = s_knownIds,\n  invocOp = s_invocOp,\n  invocRes = s_invocRes,\n  prog = progr,\n  txStatus = some_txStatus1,\n  generatedIds =  some_generatedIds1,\n  localState = some_localState1,\n  currentProc = some_currentProc1,\n  visibleCalls =  some_visibleCalls1,\n  currentTx = some_currentTx1\\<rparr> \n\\<lparr>\n  calls = s_calls',\n  happensBefore = s_happensBefore',\n  callOrigin = s_callOrigin',\n  txOrigin = s_txOrigin',\n  knownIds = s_knownIds',\n  invocOp = s_invocOp',\n  invocRes = s_invocRes',\n  prog = progr,\n  txStatus = some_txStatus2,\n  generatedIds =  some_generatedIds2,\n  localState = some_localState2,\n  currentProc = some_currentProc2,\n  visibleCalls =  some_visibleCalls2,\n  currentTx = some_currentTx2\\<rparr>\n\\<rbrakk> \\<Longrightarrow> execution_s_check\n  progr \n  i\n  s_calls' \n  s_happensBefore' \n  s_callOrigin' \n  (s_txOrigin'(tx \\<mapsto> i))\n  s_knownIds' \n  (s_invocOp'(i := s_invocOp i))\n  (s_invocRes'(i := None))\n  generatedLocal\n  generatedLocalPrivate\n  vis'\n  []\n  (Some tx)\n  firstTx\n  (cont ())\"\n\n\nshows\"execution_s_check\n  progr \n  i\n  s_calls\n  s_happensBefore \n  s_callOrigin\n  s_txOrigin \n  s_knownIds\n  s_invocOp\n  s_invocRes\n  generatedLocal\n  generatedLocalPrivate\n  vis\n  []\n  None\n  firstTx\n  (beginAtomic \\<bind> cont)\n\"\nproof show_proof_rule\n  case (Step trace S1 S_end action S'a Inv trace')\n\n\n  from ` S1 ~~ (i, action, Inv) \\<leadsto>\\<^sub>S S'a`\n    `localState S1 i \\<triangleq> (beginAtomic \\<bind> cont)`\n    `currentProc S1 i \\<triangleq> toImpl`\n    `\\<And>proc. action \\<noteq> AInvoc proc`\n  obtain t  S' vis' vis''\n    where c0: \"localState S1 i \\<triangleq> (beginAtomic \\<bind> cont)\"\n      and c1: \"currentProc S1 i \\<triangleq> toImpl\"\n      and c2: \"action = ABeginAtomic t vis''\"\n      and c3: \"Inv\"\n      and c4: \"currentTx S1 i = None\"\n      and c5: \"txStatus S1 t = None\"\n      and c6: \"prog S' = prog S1\"\n      and growth: \"state_monotonicGrowth i S1 S'\"\n      and c8: \"\\<forall>x. txOrigin S1 x \\<triangleq> i = txOrigin S' x \\<triangleq> i\"\n      and inv: \"invariant (prog S1) (invContext S')\"\n      and c10: \"\\<forall>x. txStatus S' x \\<noteq> Some Uncommitted\"\n      and wf_S': \"state_wellFormed S'\"\n      and c12: \"state_wellFormed (S'\\<lparr>txStatus := txStatus S'(t \\<mapsto> Uncommitted), txOrigin := txOrigin S'(t \\<mapsto> i), currentTx := currentTx S'(i \\<mapsto> t), localState := localState S'(i \\<mapsto> cont ()), visibleCalls := visibleCalls S'(i \\<mapsto> vis'')\\<rparr>)\"\n      and c13: \"localState S' i \\<triangleq> (beginAtomic \\<bind> cont)\"\n      and c14: \"currentProc S' i \\<triangleq> toImpl\"\n      and c15: \"currentTx S' i = None\"\n      and c16: \"visibleCalls S1 i \\<triangleq> vis'\"\n      and c17: \"visibleCalls S' i \\<triangleq> vis'\"\n      and c18: \"chooseSnapshot vis'' vis' S'\"\n      and c19: \"consistentSnapshot S' vis''\"\n      and c20: \"txStatus S' t = None\"\n      and c21: \"\\<forall>x. callOrigin S' x \\<noteq> Some t\"\n      and c22: \"txOrigin S' t = None\"\n      and S'a_def: \"S'a = S' \\<lparr>txStatus := txStatus S'(t \\<mapsto> Uncommitted), txOrigin := txOrigin S'(t \\<mapsto> i), currentTx := currentTx S'(i \\<mapsto> t), localState := localState S'(i \\<mapsto> cont ()), visibleCalls := visibleCalls S'(i \\<mapsto> vis'')\\<rparr>\"\n    by (auto simp add: step_s.simps)\n\n\n  show \"Inv \\<and> traceCorrect_s trace'\"\n  proof (intro conjI)\n    show \"Inv\" using `Inv` .\n\n    from `S'a ~~ (i, trace') \\<leadsto>\\<^sub>S* S_end`\n    show \"traceCorrect_s trace'\"\n    proof (rule use_execution_s_check)\n\n      show \"happensBefore S'a = updateHb (happensBefore S'a) vis'' []\"\n        by simp\n\n      show \"callOrigin S'a = map_update_all (callOrigin S'a) [] (the (Some t))\"\n        by simp\n\n      show \"\\<And>p t. (AInvoc p, t) \\<notin> set trace'\"\n        using Step by auto\n\n\n      show \" state_wellFormed S'a\"\n        using S'a_def c12 by blast\n\n      show \"currentProc S'a i \\<triangleq> toImpl\"\n        by (simp add: S'a_def c14)\n\n      show \"localState S'a i \\<triangleq> cont ()\"\n        by (simp add: S'a_def)\n\n      show \"visibleCalls S'a i \\<triangleq> (vis'' \\<union> set [])\"\n        by (simp add: S'a_def)\n\n      show \"currentTx S'a i \\<triangleq> t\"\n        by (simp add: S'a_def)\n\n      show \" \\<And>tx'. Some t \\<noteq> Some tx' \\<Longrightarrow> txStatus S'a tx' \\<noteq> Some Uncommitted\"\n        by (simp add: S'a_def c10)\n      show \"case Some t of None \\<Rightarrow> [] = [] | Some tx' \\<Rightarrow> set [] = {c. callOrigin S'a c \\<triangleq> tx'}\"\n        by (simp add: S'a_def c21)\n      show \"sorted_by (happensBefore S'a) []\"\n        by (simp add: S'a_def sorted_by_empty)\n      show \"vis'' \\<inter> set [] = {}\"\n        by simp\n      show \"dom (callOrigin S'a) \\<inter> set [] = {}\"\n        by simp\n      show \"Field (happensBefore S'a) \\<inter> set [] = {}\"\n        by simp\n\n      show \"execution_s_check (prog S'a) i (calls S'a) (happensBefore S'a) (callOrigin S'a) (txOrigin S'a) (knownIds S'a)\n     (invocOp S'a) (invocRes S'a) generatedLocal generatedLocalPrivate  vis'' [] (Some t) firstTx (cont ())\"\n      proof (fuzzy_rule cont)\n\n        show \"progr = prog S'a\"\n          by (simp add: S'a_def `prog S1 = progr` c6)\n\n        show \"txOrigin S'(t \\<mapsto> i) = txOrigin S'a\"\n          by (simp add: S'a_def)\n\n        show \"txOrigin S' t = None\"\n          by (simp add: c22)\n\n\n        show \" invariant progr\n     \\<lparr>calls = calls S'a, happensBefore = happensBefore S'a, callOrigin = callOrigin S'a,\n        txOrigin = txOrigin S', knownIds = knownIds S'a, invocOp = (invocOp S'a)(i := s_invocOp i),\n        invocRes = (invocRes S'a)(i := None)\\<rparr>\"\n        proof (fuzzy_rule inv)\n          show \"prog S1 = progr\"\n            by (simp add: Step)\n\n          have cCalls: \"committedCalls S' = dom (calls S')\"\n            by (simp add: c10 wf_S' committedCalls_allCommitted)\n\n          have allTransactionsCommitted: \"committedTransactions S' = dom (txOrigin S')\"\n            apply (auto simp add: dom_def)\n             apply (metis wf_S' domD domIff option.simps(3) wf_transaction_status_iff_origin)\n            by (metis c10 not_None_eq not_uncommitted_cases wf_S' wf_transaction_status_iff_origin)\n\n\n\n          show \"invContext S' =\n           \\<lparr>calls = calls S'a, happensBefore = happensBefore S'a, callOrigin = callOrigin S'a,\n            txOrigin = txOrigin S', knownIds = knownIds S'a, invocOp = (invocOp S'a)(i := s_invocOp i),\n           invocRes = (invocRes S'a)(i := None)\\<rparr>\"\n          proof (auto simp add: invContextH_def S'a_def cCalls allTransactionsCommitted)\n            show \"\\<And>a b. (a, b) \\<in> happensBefore S' |r dom (calls S') \\<Longrightarrow> (a, b) \\<in> happensBefore S'\"\n              by (simp add: restrict_relation_def)\n            show \"\\<And>a b. (a, b) \\<in> happensBefore S' \\<Longrightarrow> (a, b) \\<in> happensBefore S' |r dom (calls S')\"\n              by (simp add: wf_S' happensBefore_in_calls_left happensBefore_in_calls_right restrict_relation_def)\n            show \" callOrigin S' |` dom (calls S') = callOrigin S'\"\n              by (metis wf_S' restrict_map_noop2 wellFormed_callOrigin_dom)\n            show \"invocOp S' = (invocOp S')(i := s_invocOp i)\"\n              using Step.invocOp_eq growth state_monotonicGrowth_invocOp_i  by fastforce\n            show \"invocRes S' = (invocRes S')(i := None)\"\n              by (simp add: c13 fun_upd_idem wf_S' wf_localState_noReturn)\n          qed\n        qed\n\n        show \"\\<And>i op. s_invocOp i \\<triangleq> op \\<Longrightarrow> invocOp S'a i \\<triangleq> op\"\n          apply(simp add: S'a_def)\n          using Step.invocOp_eq growth state_monotonicGrowth_invocOp by blast\n\n        show \"\\<And>c. callOrigin S'a c \\<noteq> Some t\"\n          using \\<open>case Some t of None \\<Rightarrow> [] = [] | Some tx' \\<Rightarrow> set [] = {c. callOrigin S'a c \\<triangleq> tx'}\\<close> by auto\n        \n        from `chooseSnapshot vis'' vis' S'`\n        have \"vis' \\<subseteq> vis''\"\n          by (auto simp add: chooseSnapshot_def)\n\n        have \"vis \\<subseteq> vis'\"\n          using `visibleCalls S1 i \\<triangleq> (vis \\<union> set [])` c16 by auto\n\n        show \"vis \\<subseteq> vis''\"\n          using \\<open>vis \\<subseteq> vis'\\<close> \\<open>vis' \\<subseteq> vis''\\<close> by auto\n\n        \n        show \"vis'' \\<subseteq> dom (calls S'a)\"\n          using `consistentSnapshot S' vis''`\n          by (simp add: S'a_def consistentSnapshotH_def)\n\n        show \"causallyConsistent (happensBefore S'a) vis''\"\n          using `consistentSnapshot S' vis''`\n          by (simp add: S'a_def consistentSnapshotH_def)\n\n        show \"transactionConsistent_atomic (callOrigin S'a) vis''\"\n          using `consistentSnapshot S' vis''`\n          by (simp add: S'a_def consistentSnapshotH_def transactionConsistent_def)\n\n        from `state_wellFormed S'`\n        show \"\\<exists>some_generatedIds some_currentTx some_localState some_currentProc some_visibleCalls some_txStatus.\n       state_wellFormed\n        \\<lparr>calls = calls S'a, happensBefore = happensBefore S'a, callOrigin = callOrigin S'a,\n           txOrigin = txOrigin S', knownIds = knownIds S'a, invocOp = invocOp S'a,\n           invocRes = invocRes S'a, prog = progr, txStatus = some_txStatus,\n           generatedIds = some_generatedIds, localState = some_localState, currentProc = some_currentProc,\n           visibleCalls = some_visibleCalls, currentTx = some_currentTx\\<rparr>\"\n          apply (simp add: S'a_def `prog S1 = progr`[symmetric])\n          by (metis (full_types) c6 old.unit.exhaust state.surjective)\n\n        have smg: \"state_monotonicGrowth i\n         \\<lparr>calls = calls S1, happensBefore = happensBefore S1, callOrigin = callOrigin S1,\n            txOrigin = txOrigin S1, knownIds = knownIds S1, invocOp = invocOp S1,\n            invocRes = invocRes S1, prog = prog S1, txStatus = txStatus S1,\n            generatedIds = generatedIds S1, localState = localState S1, currentProc = currentProc S1,\n            visibleCalls = visibleCalls S1, currentTx = currentTx S1\\<rparr>\n         \\<lparr>calls = calls S', happensBefore = happensBefore S', callOrigin = callOrigin S',\n            txOrigin = txOrigin S', knownIds = knownIds S', invocOp = invocOp S',\n            invocRes = invocRes S', prog = prog S', txStatus = txStatus S',\n            generatedIds = generatedIds S', localState = localState S', currentProc = currentProc S',\n            visibleCalls = visibleCalls S', currentTx = currentTx S'\\<rparr>\"\n          by (fuzzy_rule `state_monotonicGrowth i S1 S'`, auto)\n\n\n\n        show \" \\<exists>some_generatedIds1 some_currentTx1 some_localState1 some_currentProc1 some_visibleCalls1\n         some_txStatus1 some_generatedIds2 some_currentTx2 some_localState2 some_currentProc2\n         some_visibleCalls2 some_txStatus2.\n         state_monotonicGrowth i\n          \\<lparr>calls = s_calls, happensBefore = s_happensBefore, callOrigin = s_callOrigin,\n             txOrigin = s_txOrigin, knownIds = s_knownIds, invocOp = s_invocOp,\n             invocRes = s_invocRes, prog = progr, txStatus = some_txStatus1,\n             generatedIds = some_generatedIds1, localState = some_localState1, currentProc = some_currentProc1,\n             visibleCalls = some_visibleCalls1, currentTx = some_currentTx1\\<rparr>\n          \\<lparr>calls = calls S'a, happensBefore = happensBefore S'a, callOrigin = callOrigin S'a,\n             txOrigin = txOrigin S', knownIds = knownIds S'a, invocOp = invocOp S'a,\n             invocRes = invocRes S'a, prog = progr, txStatus = some_txStatus2,\n             generatedIds = some_generatedIds2, localState = some_localState2, currentProc = some_currentProc2,\n             visibleCalls = some_visibleCalls2, currentTx = some_currentTx2\\<rparr>\"\n          apply (simp add: S'a_def)\n          apply (rule exI)+\n          apply (fuzzy_rule smg)\n          by (auto simp add: Step c6)\n\n\n        \n\n        show \"\\<forall>v\\<in>generatedLocalPrivate.\n         uid_is_private' i (calls S'a) (invocOp S'a) (invocRes S'a) (knownIds S'a) v\"\n        proof (auto simp add: S'a_def )\n          fix v::nat\n          assume \"v\\<in>generatedLocalPrivate\"\n          with `\\<forall>v\\<in>generatedLocalPrivate.\n                uid_is_private i S1 v`\n          have \"uid_is_private i S1 v\"\n            by auto\n          hence \"uid_is_private i S' v\"\n            using  Step.prog_eq assms(1) growth growth_still_hidden  by  blast\n\n          thus \"uid_is_private' i (calls S') (invocOp S') (invocRes S') (knownIds S') v\"\n            by (meson uid_is_private'_implies)\n        qed\n\n        show \"(invocOp S'a)(i := s_invocOp i) = invocOp S'a\"\n          apply (auto simp add: S'a_def)\n          apply (rule fun_upd_idem)\n          using Step.invocOp_eq growth state_monotonicGrowth_invocOp_i by  blast\n\n        show \"(invocRes S'a)(i := None) = invocRes S'a\"\n          apply (auto simp add: S'a_def)\n          apply (rule fun_upd_idem)\n          by (simp add: c13 state_wellFormed_no_result_when_running wf_S')\n\n\n        show \"txOrigin S' tx \\<noteq> Some i\"\n          if c0: \"firstTx\"\n            and c1: \"callOrigin S'a c \\<triangleq> tx\"\n          for  c tx\n          using `firstTx = (\\<nexists>c tx. callOrigin S1 c \\<triangleq> tx \\<and> txOrigin S1 tx \\<triangleq> i \\<and> txStatus S1 tx \\<triangleq> Committed)`\n            c0 c1\n          apply (auto simp add: S'a_def )\n          by (smt Step.All_implies_not_txStatus_eq Step.state_wellFormed c16 c17 c8 domD domIff growth state_monotonicGrowth_callOrigin state_wellFormed_ls_visibleCalls_callOrigin wellFormed_callOrigin_dom3 wellFormed_currentTx_unique_h(2) wellFormed_state_transaction_consistent(1) wellFormed_visibleCallsSubsetCalls2 wf_S')\n\n\n\n\n      qed\n      from `firstTx = (\\<nexists>c tx. callOrigin S1 c \\<triangleq> tx \\<and> txOrigin S1 tx \\<triangleq> i \\<and> txStatus S1 tx \\<triangleq> Committed)`\n      show \"firstTx = (\\<nexists>c tx. callOrigin S'a c \\<triangleq> tx \\<and> txOrigin S'a tx \\<triangleq> i \\<and> txStatus S'a tx \\<triangleq> Committed)\"\n        apply (auto simp add: S'a_def)\n        apply (smt Step.state_wellFormed c16 c17 c4 c8 domExists_simp domIff growth state_monotonicGrowth_callOrigin state_wellFormed_ls_visibleCalls_callOrigin transactionConsistent_Committed wellFormed_callOrigin_dom3 wellFormed_visibleCallsSubsetCalls2 wf_S' wf_transactionConsistent_noTx)\n        by (metis (mono_tags, lifting) Step.state_wellFormed c5 growth state_monotonicGrowth_callOrigin state_monotonicGrowth_txOrigin state_monotonicGrowth_txStatus2 wf_callOrigin_implies_txStatus_defined)\n\n      show \"\\<And>c. i_callOriginI S'a c \\<triangleq> i \\<Longrightarrow> c \\<in> vis''\"\n        apply (simp add: S'a_def i_callOriginI_h_def c21 split: option.splits if_splits)\n        using c17 c18 chooseSnapshot_def state_wellFormed_ls_visibleCalls_callOrigin wf_S' by fastforce\n\n      from `generatedLocal = {x. generatedIds S1 x \\<triangleq> i}`\n      show \"generatedLocal = {x. generatedIds S'a x \\<triangleq> i}\"\n        using growth state_monotonicGrowth_generatedIds_same1  by (simp add: S'a_def, fastforce)\n\n      show \"generatedLocalPrivate \\<subseteq> generatedLocal\"\n        using Step.less_eq by blast\n\n      show \"uid_is_private i S'a x\"\n        if c0: \"x \\<in> generatedLocalPrivate\"\n        for  x\n      proof -\n        from c0 have \"uid_is_private i S1 x\"\n          using Step by blast\n\n        hence \"uid_is_private i S' x\"\n          using Step.prog_eq assms(1) growth growth_still_hidden  by  blast\n\n        show \"uid_is_private i S'a x\"\n          unfolding uid_is_private_def\n        proof (intro conjI)\n\n          show \"new_unique_not_in_other_invocations i S'a x\"\n            unfolding new_unique_not_in_other_invocations_def\n          proof (intro allI impI)\n            fix i' \n            assume \"i' \\<noteq> i\"\n\n            obtain uids where \"x \\<notin> uids\" and \"invocation_cannot_guess_ids uids i' S'\"\n              by (meson \\<open>i' \\<noteq> i\\<close> \\<open>uid_is_private i S' x\\<close> new_unique_not_in_other_invocations_def uid_is_private_def)\n\n            from  ` S1 ~~ (i, action, Inv) \\<leadsto>\\<^sub>S S'a`\n            have \" S1 ~~ (i, ABeginAtomic t vis'', Inv) \\<leadsto>\\<^sub>S S'a\"\n              by (simp add:  `action = ABeginAtomic t vis''`)\n\n            thm step_s_beginAtomic_to_steps\n            from `state_monotonicGrowth i S1 S'`\n            obtain tr\n              where \"S1 ~~ tr \\<leadsto>* S'\"\n                and \"\\<forall>(i', a)\\<in>set tr. i' \\<noteq> i\"\n                and \"\\<forall>i. (i, ACrash) \\<notin> set tr\" \n              by (auto simp add: state_monotonicGrowth_def)\n\n\n            have \" S' ~~ (i, ABeginAtomic t vis'') \\<leadsto> S'a\"\n              using c13 c14 c15 c17 c18 c20 by (auto simp add: step.simps S'a_def state_ext)\n\n\n\n\n            have \"invocation_cannot_guess_ids uids i' S'a\"\n              using \\<open>S' ~~ (i, ABeginAtomic t vis'') \\<leadsto> S'a\\<close> \\<open>i' \\<noteq> i\\<close> \\<open>invocation_cannot_guess_ids uids i' S'\\<close> show_invocation_cannot_guess_ids_step_other by blast\n\n            show \"\\<exists>uids. x \\<notin> uids \\<and> invocation_cannot_guess_ids uids i' S'a\"\n              using \\<open>invocation_cannot_guess_ids uids i' S'a\\<close> \\<open>x \\<notin> uids\\<close> by auto\n\n          qed\n\n        qed (insert `uid_is_private i S' x`, simp add: S'a_def uid_is_private_def new_unique_not_in_other_invocations_def; fail)+\n\n\n      qed\n\n    qed (simp add: S'a_def Step; fail)+\n  qed\nqed\n\n\n\nlemma execution_s_check_endAtomic:\n  assumes \"program_wellFormed progr\"\n    and \"s_txOrigin tx = None\"\n    and tx_nonempty: \"localCalls \\<noteq> []\"\nand inv_cont: \"\n\\<lbrakk>\ndistinct localCalls;\n\\<And>c. c\\<in>set localCalls \\<Longrightarrow> s_callOrigin c = None;\n\\<And>c. c\\<in>set localCalls \\<Longrightarrow> c \\<notin> vis;\n\\<And>c c'. c\\<in>set localCalls \\<Longrightarrow> (c,c') \\<notin> s_happensBefore;\n\\<And>c c'. c\\<in>set localCalls \\<Longrightarrow> (c',c) \\<notin> s_happensBefore;\ninvocation_happensBeforeH\n    (i_callOriginI_h (map_update_all s_callOrigin localCalls tx) (s_txOrigin(tx \\<mapsto> i))) \n    (updateHb s_happensBefore vis localCalls)\n= \n(if firstTx then\ninvocation_happensBeforeH (i_callOriginI_h s_callOrigin s_txOrigin) s_happensBefore\n \\<union> {i' | i' c'. c' \\<in> vis \\<and> i_callOriginI_h s_callOrigin s_txOrigin c' \\<triangleq> i' \n   \\<and> (\\<forall>c''. i_callOriginI_h s_callOrigin s_txOrigin c'' \\<triangleq> i' \\<longrightarrow> c'' \\<in> vis ) } \\<times> {i}\nelse\ninvocation_happensBeforeH (i_callOriginI_h s_callOrigin s_txOrigin) s_happensBefore\n- {i} \\<times> {i'. (i,i') \\<in> invocation_happensBeforeH (i_callOriginI_h s_callOrigin s_txOrigin) s_happensBefore })\n\\<rbrakk>\n \\<Longrightarrow> invariant progr\n     \\<lparr>calls = s_calls, \n      happensBefore = updateHb s_happensBefore vis localCalls,\n      callOrigin = map_update_all s_callOrigin localCalls tx,\n      txOrigin = s_txOrigin(tx \\<mapsto> i), \n      knownIds = s_knownIds,\n      invocOp = s_invocOp, \n      invocRes = s_invocRes\\<rparr>\n\\<and> execution_s_check\n  progr \n  i\n  s_calls \n  (updateHb s_happensBefore vis localCalls) \n  (map_update_all s_callOrigin localCalls tx) \n  (s_txOrigin(tx \\<mapsto> i))\n  s_knownIds \n  s_invocOp\n  s_invocRes\n  generatedLocal\n  generatedLocalPrivate\n  (vis \\<union> set localCalls)\n  []\n  None\n  False\n  (cont ())\n\"\n\n\nshows\"execution_s_check\n  progr \n  i\n  s_calls\n  s_happensBefore \n  s_callOrigin\n  (s_txOrigin(tx \\<mapsto> i)) \n  s_knownIds\n  s_invocOp\n  s_invocRes\n  generatedLocal\n  generatedLocalPrivate\n  vis\n  localCalls\n  (Some tx)\n  firstTx\n  (endAtomic \\<bind> cont)\n\"\nproof show_proof_rule\n  case (Step trace S1 S_end action S'a Inv trace')\n\n\n  from ` S1 ~~ (i, action, Inv) \\<leadsto>\\<^sub>S S'a`\n    `localState S1 i \\<triangleq> (endAtomic \\<bind> cont)`\n    `currentProc S1 i \\<triangleq> toImpl`\n    `\\<And>proc. action \\<noteq> AInvoc proc`\n    `currentTx S1 i \\<triangleq> tx`\n  have action_def: \"action = AEndAtomic\"\n    and S'a_def: \"S'a = S1\n     \\<lparr>localState := localState S1(i \\<mapsto> cont ()), currentTx := (currentTx S1)(i := None),\n        txStatus := txStatus S1(tx \\<mapsto> Committed)\\<rparr>\"\n    and S'a_wf: \"state_wellFormed S'a\"\n    and Inv_def: \"Inv \\<longleftrightarrow> \n     invariant (prog S1)\n      (invContextH (callOrigin S1) (txOrigin S1) (txStatus S1(tx \\<mapsto> Committed)) (happensBefore S1)\n        (calls S1) (knownIds S1) (invocOp S1) (invocRes S1))\"\n    by (auto simp add: step_s.simps)\n\n  show \"Inv \\<and> traceCorrect_s trace'\"\n  proof\n\n    have allCommitted1: \n      \"txStatus S1 tx' \\<triangleq> Committed\" if \"tx' \\<noteq> tx\" and \"callOrigin S1 c \\<triangleq> tx'\" for c tx'\n      using that\n      by (metis (no_types, lifting) Step.All_implies_not_txStatus_eq Step.state_wellFormed not_uncommitted_cases option.exhaust option.sel wf_no_txStatus_origin_for_nothing)\n\n    have tx_uncommitted: \"txStatus S1 tx \\<triangleq> Uncommitted\"\n      using Step.currentTx_eq Step.state_wellFormed not_uncommitted_cases wellFormed_currentTx_unique_h(2)  by  blast\n\n    have allCommitted2: \"txStatus S1 t \\<triangleq> Committed \\<longleftrightarrow> t \\<noteq> tx \\<and> txStatus S1 t \\<noteq> None\" for t\n      apply (cases \"txStatus S1 t\", auto simp add: tx_uncommitted)\n      using Step.All_implies_not_txStatus_eq txStatus.exhaust  by  force\n\n\n\n    have committedCallsH_simp: \"committedCallsH (callOrigin S1) (txStatus S1(tx \\<mapsto> Committed))\n      = dom (calls S1)\"\n      using  wellFormed_callOrigin_dom[OF `state_wellFormed S1`]\n wf_callOrigin_and_calls[OF `state_wellFormed S1`]\n      apply (auto simp add: committedCallsH_def isCommittedH_def exists_cases1 allCommitted2 )\n      by (metis (mono_tags, lifting) allCommitted1 allCommitted2 domExists_simp)\n      \n    have h1: \"s_calls = calls S1\"\n        by (simp add: Step)\n\n      have h2: \"updateHb s_happensBefore vis localCalls = happensBefore S1 |r dom (calls S1)\"\n        apply (simp add: Step)\n        apply (subst restrict_relation_noop, auto simp add: Field_def)\n        using Step.happensBefore_eq Step.state_wellFormed h1 happensBefore_in_calls_left happensBefore_in_calls_right  by  fastforce+\n      \n\n      have h3: \"map_update_all s_callOrigin localCalls tx = callOrigin S1 |` dom (calls S1)\"\n        apply (simp add: Step)\n        apply (subst restrict_map_noop)\n         apply auto\n        using  Step.callOrigin_eq Step.state_wellFormed h1 wellFormed_callOrigin_dom  by  fastforce+\n\n\n\n      have h4: \"s_txOrigin(tx\\<mapsto>i) =\n        txOrigin S1 |` {t. t \\<noteq> tx \\<longrightarrow> txStatus S1 t \\<triangleq> Committed}\"\n        apply (simp add: Step )\n        apply (subst restrict_map_noop)\n         apply (auto simp add: `s_txOrigin tx = None`  allCommitted2 wf_transaction_status_iff_origin)\n        by (metis Step.state_wellFormed Step.txOrigin_eq fun_upd_apply option.distinct(1) option.exhaust wf_transaction_status_iff_origin)\n\n      have \"localCalls \\<noteq> []\"\n        by (simp add: tx_nonempty)\n      have \"distinct localCalls\"\n        by (simp add: Step.distinct)\n      have  co_tx_none: \"\\<forall>c\\<in>set localCalls. s_callOrigin c = None\"\n        using Step.inf_eq2 by blast\n      have to_tx_none: \" s_txOrigin tx = None\"\n        by (simp add: assms(2))\n      have co_not_tx: \"\\<And>c. s_callOrigin c \\<noteq> Some tx\"\n        using Step.callOrigin_eq Step.case_option co_tx_none map_update_all_Some_same by  fastforce\n\n      have hb_wf_l:\"\\<And>c c'. (c, c') \\<in> s_happensBefore \\<Longrightarrow> \\<exists>t. s_callOrigin c \\<triangleq> t\"\n        using FieldI1 FieldI2 Step.state_wellFormed (* TODO Step(20) *) (* TODO Step(3) *) (* TODO Step(4) *) disjoint_iff_not_equal domExists_simp domIff map_update_all_get updateHb_simp2 wellFormed_happensBefore_calls_l wf_callOrigin_and_calls\n        by (smt Step.callOrigin_eq Step.happensBefore_eq Step.inf_eq3 Step.state_wellFormed)\n      have hb_wf_r: \"\\<And>c c'. (c, c') \\<in> s_happensBefore \\<Longrightarrow> \\<exists>t. s_callOrigin c' \\<triangleq> t\"\n        by (metis FieldI2 Step.callOrigin_eq Step.happensBefore_eq Step.inf_eq3 Step.state_wellFormed disjoint_iff_not_equal map_update_all_get option.exhaust updateHb_simp2 wellFormed_happensBefore_calls_r wf_callOrigin_and_calls)\n\n      have  invocation_hb_simp:\n        \"invocation_happensBeforeH\n    (i_callOriginI_h (map_update_all s_callOrigin localCalls tx) (s_txOrigin(tx \\<mapsto> i))) \n    (updateHb s_happensBefore vis localCalls)\n= \n(if firstTx then\ninvocation_happensBeforeH (i_callOriginI_h s_callOrigin s_txOrigin) s_happensBefore\n \\<union> {i' | i' c'. c' \\<in> vis \\<and> i_callOriginI_h s_callOrigin s_txOrigin c' \\<triangleq> i' \n   \\<and> (\\<forall>c''. i_callOriginI_h s_callOrigin s_txOrigin c'' \\<triangleq> i' \\<longrightarrow> c'' \\<in> vis ) } \\<times> {i}\nelse\ninvocation_happensBeforeH (i_callOriginI_h s_callOrigin s_txOrigin) s_happensBefore\n- {i} \\<times> {i'. (i,i') \\<in> invocation_happensBeforeH (i_callOriginI_h s_callOrigin s_txOrigin) s_happensBefore })\"\n      proof (rule if_cases)\n        assume firstTx\n\n\n        show \"invocation_happensBeforeH (i_callOriginI_h (map_update_all s_callOrigin localCalls tx) (s_txOrigin(tx \\<mapsto> i)))\n           (updateHb s_happensBefore vis localCalls) =\n          invocation_happensBeforeH (i_callOriginI_h s_callOrigin s_txOrigin) s_happensBefore \\<union>\n          {i' |  i' c'.\n              c' \\<in> vis \\<and>\n              i_callOriginI_h s_callOrigin s_txOrigin c' \\<triangleq> i' \\<and>\n              (\\<forall>c''. i_callOriginI_h s_callOrigin s_txOrigin c'' \\<triangleq> i' \\<longrightarrow> c'' \\<in> vis)} \\<times>\n          {i}\"\n          using `localCalls \\<noteq> []` \n            `distinct localCalls` co_tx_none to_tx_none co_not_tx hb_wf_l hb_wf_r\n        proof (fuzzy_rule(noabs) invocation_happensBeforeH_one_transaction_simp2)\n\n          show \"s_txOrigin t \\<noteq> Some i\" if \"s_callOrigin c \\<triangleq> t\" for c t\n          proof -\n            from `s_callOrigin c \\<triangleq> t`\n            have \"c \\<notin> set localCalls\"\n              using co_tx_none by fastforce\n            then have \"c \\<notin> set localCalls \\<and> s_callOrigin c \\<triangleq> t\"\n              using that by blast\n            then have f1: \"t \\<noteq> tx \\<longrightarrow> callOrigin S1 c \\<triangleq> t\"\n              by (simp add: Step.callOrigin_eq map_update_all_get)\n            have \"s_callOrigin c \\<noteq> Some tx\"\n              using co_not_tx by blast\n            then have \"t \\<noteq> tx\"\n              using that by blast\n            then have \"s_txOrigin(t \\<mapsto> i) \\<noteq> s_txOrigin\"\n              using f1\n              by (metis Step.firstTx_def Step.txOrigin_eq \\<open>firstTx\\<close> allCommitted1 fun_upd_idem_iff fun_upd_other)\n            then show \"s_txOrigin t \\<noteq> Some i\"\n              by (metis (no_types) fun_upd_triv)\n          qed\n\n        qed auto\n      next\n        assume \"\\<not> firstTx\"\n        from this obtain old_c old_t \n          where \"s_callOrigin old_c \\<triangleq> old_t\"\n            and \"s_txOrigin old_t \\<triangleq> i\"\n            and \"txStatus S1 old_t \\<triangleq> Committed\"\n          using Step.callOrigin_eq Step.firstTx_def Step.txOrigin_eq fun_upd_apply option.sel allCommitted2 map_update_all_Some_other by  fastforce\n\n\n        show \" invocation_happensBeforeH (i_callOriginI_h (map_update_all s_callOrigin localCalls tx) (s_txOrigin(tx \\<mapsto> i)))\n     (updateHb s_happensBefore vis localCalls) =\n    invocation_happensBeforeH (i_callOriginI_h s_callOrigin s_txOrigin) s_happensBefore -\n    {i} \\<times> {i'. (i, i') \\<in> invocation_happensBeforeH (i_callOriginI_h s_callOrigin s_txOrigin) s_happensBefore}\"\n          using tx_nonempty `s_txOrigin old_t \\<triangleq> i` co_tx_none `s_callOrigin old_c \\<triangleq> old_t`\n                hb_wf_l co_not_tx\n        proof (fuzzy_rule invocation_happensBeforeH_more_transactions_simp2)\n\n          show \"\\<And>c c'. (c, c') \\<in> s_happensBefore \\<Longrightarrow> (c, c') \\<in> s_happensBefore\"\n            by simp\n\n          show \"Field s_happensBefore \\<inter> set localCalls = {}\"\n            by (simp add: Step.inf_eq3)\n\n          show \"\\<And>c. i_callOriginI_h s_callOrigin s_txOrigin c \\<triangleq> i \\<Longrightarrow> c \\<in> vis\"\n            by (simp add: Step.All_implies_member i_callOriginI_h_update_to2)\n\n          show \"\\<And>c c'. \\<lbrakk>c' \\<in> vis; (c, c') \\<in> s_happensBefore\\<rbrakk> \\<Longrightarrow> c \\<in> vis\"\n          proof -\n            fix c :: callId and c' :: callId\n            assume a1: \"c' \\<in> vis\"\n            assume a2: \"(c, c') \\<in> s_happensBefore\"\n            have f3: \"\\<forall>c. c \\<notin> Field s_happensBefore \\<or> (\\<forall>ca. ca \\<notin> set localCalls \\<or> c \\<noteq> ca)\"\n              using Step.inf_eq3 by  auto\n            have f4: \"c' \\<in> Field s_happensBefore\"\n              using a2 by (simp add: FieldI2)\n            have \"c \\<in> Field s_happensBefore\"\n              using a2 by (simp add: FieldI1)\n            then show \"c \\<in> vis\"\n              using f4 f3 a2 a1 \n              by (metis Step.happensBefore_eq Step.state_wellFormed Step.visibleCalls_eq Un_iff updateHb_simp2 wf_vis_downwards_closed2)\n          qed\n\n\n\n        qed\n      qed\n\n\n\n      \n\n      have inv_cont2: \"invariant progr\n       \\<lparr>calls = s_calls, happensBefore = updateHb s_happensBefore vis localCalls,\n          callOrigin = map_update_all s_callOrigin localCalls tx, txOrigin = s_txOrigin(tx \\<mapsto> i),\n          knownIds = s_knownIds, invocOp = s_invocOp, invocRes = s_invocRes\\<rparr> \\<and>\n      execution_s_check progr i s_calls (updateHb s_happensBefore vis localCalls)\n       (map_update_all s_callOrigin localCalls tx) (s_txOrigin(tx \\<mapsto> i)) s_knownIds s_invocOp s_invocRes\n     generatedLocal generatedLocalPrivate (vis \\<union> set localCalls) [] None False (cont ())\"\n        using  `distinct localCalls`\n      proof (rule inv_cont)\n        show h5: \"\\<And>c. c \\<in> set localCalls \\<Longrightarrow> s_callOrigin c = None\"\n          using co_tx_none by auto\n        show h6: \"\\<And>c c'. c \\<in> set localCalls \\<Longrightarrow> (c, c') \\<notin> s_happensBefore\"\n          using co_tx_none hb_wf_l by fastforce\n        show h7: \"\\<And>c c'. c \\<in> set localCalls \\<Longrightarrow> (c', c) \\<notin> s_happensBefore\"\n          using co_tx_none hb_wf_r by fastforce\n        show \"\\<And>c. c \\<in> set localCalls \\<Longrightarrow> c \\<notin> vis\"\n          using Step.inf_eq by  blast\n\n        show \"invocation_happensBeforeH (i_callOriginI_h (map_update_all s_callOrigin localCalls tx) (s_txOrigin(tx \\<mapsto> i)))\n         (updateHb s_happensBefore vis localCalls) =\n        (if firstTx\n         then invocation_happensBeforeH (i_callOriginI_h s_callOrigin s_txOrigin) s_happensBefore \\<union>\n              {i' | i' c'.\n                  c' \\<in> vis \\<and>\n                  i_callOriginI_h s_callOrigin s_txOrigin c' \\<triangleq> i' \\<and>\n                  (\\<forall>c''. i_callOriginI_h s_callOrigin s_txOrigin c'' \\<triangleq> i' \\<longrightarrow> c'' \\<in> vis)} \\<times>\n              {i}\n         else invocation_happensBeforeH (i_callOriginI_h s_callOrigin s_txOrigin) s_happensBefore -\n              {i} \\<times>\n              {i'. (i, i') \\<in> invocation_happensBeforeH (i_callOriginI_h s_callOrigin s_txOrigin) s_happensBefore})\"\n          by (auto simp add: committedCallsH_simp invocation_hb_simp)\n      qed\n\n\n\n      show \"Inv\"\n        unfolding Inv_def invContextH_def\n      proof (fuzzy_rule inv_cont2[THEN conjunct1])\n      qed (auto simp add:  committedCallsH_simp h1 h2 h3 h4, (auto simp add: Step))\n\n\n    show \"traceCorrect_s trace'\"\n      using `S'a ~~ (i, trace') \\<leadsto>\\<^sub>S* S_end`\n    proof (rule use_execution_s_check)\n      show \"\\<And>p t. (AInvoc p, t) \\<notin> set trace'\"\n        using Step by auto\n\n      show \"currentTx S'a i = None\"\n        by (simp add: S'a_def)\n\n      show \"state_wellFormed S'a\"\n        using S'a_wf by auto\n\n      show \"happensBefore S'a = updateHb (happensBefore S'a) (vis\\<union>set localCalls)  []\"\n        by simp\n\n      show \"callOrigin S'a = map_update_all (callOrigin S'a) [] (the None)\"\n        by simp\n\n      show \" localState S'a i \\<triangleq> cont ()\"\n        by (simp add: S'a_def Step)\n      \n      show \"currentProc S'a i \\<triangleq> toImpl\"\n        by (simp add: S'a_def Step)\n\n      show \"visibleCalls S'a i \\<triangleq> (vis \\<union> set localCalls \\<union> set [])\"\n        by (simp add: S'a_def Step)\n\n      show \"\\<And>tx'. None \\<noteq> Some tx' \\<Longrightarrow> txStatus S'a tx' \\<noteq> Some Uncommitted\"\n        by (simp add: S'a_def Step)\n\n      show \"sorted_by (happensBefore S'a) []\"\n        by (simp add: sorted_by_empty)\n\n      show \"execution_s_check (prog S'a) i (calls S'a) (happensBefore S'a) (callOrigin S'a)\n       (txOrigin S'a) (knownIds S'a) (invocOp S'a) (invocRes S'a)\n       {x. generatedIds S'a x \\<triangleq> i} generatedLocalPrivate (vis \\<union> set localCalls) [] None False (cont ())\"\n      proof (fuzzy_rule inv_cont2[THEN conjunct2])\n      qed (simp add: S'a_def Step)+\n\n      obtain c where \"c\\<in>set localCalls\"\n        using `localCalls \\<noteq> []` by fastforce\n\n\n      thm Step(4)\n      find_theorems name: Step\n\n\n      show \"False = (\\<nexists>c tx. callOrigin S'a c \\<triangleq> tx \\<and> txOrigin S'a tx \\<triangleq> i \\<and> txStatus S'a tx \\<triangleq> Committed)\"\n        using  \\<open>c \\<in> set localCalls\\<close>  by (auto simp add: S'a_def intro!: exI[where x=c] exI[where x=tx]\n            Step.state_wellFormed Step.currentTx_eq state_wellFormed_current_transaction_origin\n            Step.callOrigin_eq map_update_all_Some_same, simp add: Step.callOrigin_eq map_update_all_Some_same) \n\n      show \"\\<And>c. i_callOriginI S'a c \\<triangleq> i \\<Longrightarrow> c \\<in> vis \\<union> set localCalls\"\n        apply (auto simp add: S'a_def i_callOriginI_h_def split: option.splits)\n        using Step.state_wellFormed Step.visibleCalls_eq state_wellFormed_ls_visibleCalls_callOrigin by  fastforce\n\n      show \"generatedLocalPrivate \\<subseteq> {x. generatedIds S'a x \\<triangleq> i}\"\n        using Step by (simp add: S'a_def)\n\n      fix x\n      assume c0: \"x \\<in> generatedLocalPrivate\"\n\n      from c0\n      have \"uid_is_private i S1 x\"\n        by (simp add: Step.Ball)\n\n      show \"uid_is_private i S'a x\"\n        unfolding uid_is_private_def\n      proof (intro conjI)\n\n        show \" new_unique_not_in_other_invocations i S'a x\"\n          using  Step.step_s \\<open>uid_is_private i S1 x\\<close> action_def new_unique_not_in_other_invocations_maintained uid_is_private_def  by  blast\n\n      qed (insert `uid_is_private i S1 x`, auto simp add: S'a_def uid_is_private_def new_unique_not_in_other_invocations_def)\n\n\n\n\n    qed (simp add: S'a_def Step; fail)+\n  qed\nqed\n\n\n\n\nlemma execution_s_check_pause:\n  assumes cont: \"\n\\<comment> \\<open>\n\n\\<close>\n execution_s_check\n  progr \n  i\n  s_calls\n  s_happensBefore \n  s_callOrigin\n  s_txOrigin \n  s_knownIds\n  s_invocOp\n  s_invocRes\n  generatedLocal\n  generatedLocalPrivate\n  vis\n  localCalls\n  tx\n  firstTx\n  (cont ())\"\n\n\nshows\"execution_s_check\n  progr \n  i\n  s_calls\n  s_happensBefore \n  s_callOrigin\n  s_txOrigin \n  s_knownIds\n  s_invocOp\n  s_invocRes\n  generatedLocal\n  generatedLocalPrivate\n  vis\n  localCalls\n  tx\n  firstTx\n  (pause \\<bind> cont)\n\"\nproof show_proof_rule\n  case (Step trace S1 S_end action S'a Inv trace')\n\n\n  from ` S1 ~~ (i, action, Inv) \\<leadsto>\\<^sub>S S'a`\n    `localState S1 i \\<triangleq> (pause \\<bind> cont)`\n    `currentProc S1 i \\<triangleq> toImpl`\n    `\\<And>proc. action \\<noteq> AInvoc proc`\n  have \"action = ALocal True\"\n    and  Inv\n    and S'a_def: \"S'a = S1\\<lparr>localState := localState S1(i \\<mapsto> cont ())\\<rparr>\"\n    by (auto simp add: step_s.simps)\n\n\n  show \"Inv \\<and> traceCorrect_s trace'\"\n  proof\n\n    show \"Inv\" using `Inv` .\n\n    show \"traceCorrect_s trace'\"\n      using `S'a ~~ (i, trace') \\<leadsto>\\<^sub>S* S_end`\n    proof (rule use_execution_s_check)\n      show \"\\<And>p t. (AInvoc p, t) \\<notin> set trace'\"\n        using Step by auto\n\n      show \"state_wellFormed S'a\"\n        using Step state_wellFormed_combine_s1 by blast\n\n      from `case tx of None \\<Rightarrow> localCalls = [] | Some tx' \\<Rightarrow> set localCalls = {c. callOrigin S1 c \\<triangleq> tx'}`\n      show \"case tx of None \\<Rightarrow> localCalls = [] | Some tx' \\<Rightarrow> set localCalls = {c. callOrigin S'a c \\<triangleq> tx'}\"\n        by (auto simp add: S'a_def split: option.splits)\n\n      show \"sorted_by (happensBefore S'a) localCalls\"\n        using Step.sorted_by by  (simp add: S'a_def )\n\n\n\n      show \" execution_s_check progr i s_calls s_happensBefore s_callOrigin s_txOrigin s_knownIds\n     s_invocOp s_invocRes {x. generatedIds S1 x \\<triangleq> i} generatedLocalPrivate vis localCalls tx firstTx (cont ())\"\n      proof (fuzzy_rule cont)\n        show \"generatedLocal = {x. generatedIds S1 x \\<triangleq> i}\"\n          using Step.generatedLocal_def by blast\n      qed\n\n      show \"generatedLocalPrivate \\<subseteq> {x. generatedIds S1 x \\<triangleq> i}\"\n        using Step.Ball uid_is_private_def by auto\n      \n      fix x\n      assume a0: \"x \\<in> generatedLocalPrivate\"\n      hence \"uid_is_private i S1 x\"\n        by (simp add: Step.Ball)\n\n      show \"uid_is_private i S'a x\"\n        unfolding uid_is_private_def\n      proof (intro conjI)\n        show \"new_unique_not_in_other_invocations i S'a x\"\n          using Step.step_s \\<open>action = ALocal True\\<close> \\<open>uid_is_private i S1 x\\<close> new_unique_not_in_other_invocations_maintained uid_is_private_def by  blast\n      qed (insert `uid_is_private i S1 x`, auto simp add:S'a_def uid_is_private_def new_unique_not_in_other_invocations_def)\n\n\n    qed (simp add: S'a_def Step; fail)+\n  qed\nqed\n\n\nlemma updateHb_restrict:\n \" updateHb hb vis cs |r S =\n   updateHb (hb |r S) (vis \\<inter> S) (filter (\\<lambda>x. x \\<in> S) cs)\"\n  by (induct cs arbitrary: vis hb,\n   auto simp add: restrict_relation_def updateHb.simps,\n  (metis (no_types, lifting) Int_iff Un_iff mem_Sigma_iff singletonD updateHb_cases)+)\n\n\n\nlemma execution_s_check_dbop:\n  assumes progr_wf: \"program_wellFormed progr\"\n    (* might add this to ensure progress:  \n     and query_res_exists: \"True\"*)\nand cont: \"\\<And>c res. \\<lbrakk>\nquerySpec progr op \\<lparr>\n      calls = s_calls |` (vis \\<union> set localCalls), \n      happensBefore=updateHb (s_happensBefore |r vis) vis localCalls\\<rparr> res\n\\<comment> \\<open>\n\n\\<close>\n\\<rbrakk> \\<Longrightarrow> \n execution_s_check\n  progr \n  i\n  (s_calls(c \\<mapsto> Call op res))\n  s_happensBefore \n  s_callOrigin\n  s_txOrigin \n  s_knownIds\n  s_invocOp\n  s_invocRes\n  generatedLocal\n  (generatedLocalPrivate - uniqueIds op - uniqueIds res)\n  vis\n  (localCalls @ [c])\n  (Some tx)\n  firstTx\n  (cont res)\"\n\n\nshows\"execution_s_check\n  progr \n  i\n  s_calls\n  s_happensBefore \n  s_callOrigin\n  s_txOrigin \n  s_knownIds\n  s_invocOp\n  s_invocRes\n  generatedLocal\n  generatedLocalPrivate\n  vis\n  localCalls\n  (Some tx)\n  firstTx\n  (call op \\<bind> cont)\n\"\nproof show_proof_rule\n  case (Step trace S1 S_end action S'a Inv trace')\n\n\n  from ` S1 ~~ (i, action, Inv) \\<leadsto>\\<^sub>S S'a`\n    `localState S1 i \\<triangleq> (call op \\<bind> cont)`\n    `currentProc S1 i \\<triangleq> toImpl`\n    `\\<And>proc. action \\<noteq> AInvoc proc`\n    ` currentTx S1 i \\<triangleq> tx`\n`visibleCalls S1 i \\<triangleq> (vis \\<union> set localCalls)`\n  obtain c res\n    where c0: \"localState S1 i \\<triangleq> (call op \\<bind> cont)\"\n   and c1: \"currentProc S1 i \\<triangleq> toImpl\"\n   and c2: \"currentTx S1 i \\<triangleq> tx\"\n   and c3: \"visibleCalls S1 i \\<triangleq> (vis \\<union> set localCalls)\"\n   and c4: \"action = ADbOp c op res\"\n   and c5: \"Inv\"\n   and S'a_def: \"S'a = S1 \\<lparr>localState := localState S1(i \\<mapsto> cont res), calls := calls S1(c \\<mapsto> Call op res), callOrigin := callOrigin S1(c \\<mapsto> tx), visibleCalls := visibleCalls S1(i \\<mapsto> insert c (vis \\<union> set localCalls)), happensBefore := happensBefore S1 \\<union> (vis \\<union> set localCalls) \\<times> {c}\\<rparr>\"\n   and fresh_c: \"calls S1 c = None\"\n   and qry: \"querySpec (prog S1) op (getContextH (calls S1) (happensBefore S1) (Some (vis \\<union> set localCalls))) res\"\n    by (auto simp add: step_s.simps)\n\n\n  show \"Inv \\<and> traceCorrect_s trace'\"\n  proof\n\n    show \"Inv\" using `Inv` .\n\n    show \"traceCorrect_s trace'\"\n      using `S'a ~~ (i, trace') \\<leadsto>\\<^sub>S* S_end`\n    proof (rule use_execution_s_check)\n      show \"\\<And>p t. (AInvoc p, t) \\<notin> set trace'\"\n        using Step by auto\n\n      show \"state_wellFormed S'a\"\n        using Step state_wellFormed_combine_s1 by blast\n\n      show \"calls S'a = s_calls(c \\<mapsto> Call op res)\"\n        by (simp add: S'a_def Step)\n\n      show \"happensBefore S'a = updateHb s_happensBefore vis (localCalls@[c])\"\n        by (auto simp add: S'a_def Step\n          updateHb_chain[symmetric, where vis'=\"set localCalls \\<union> vis\"]\n          updateHb_single)\n\n      have s: \"map_of (map (\\<lambda>c. (c, tx)) localCalls) c = Some t\n        \\<longleftrightarrow> (c\\<in>set localCalls \\<and> t = tx) \" for c t\n        by (auto simp add:  map_of_Some comp_def Step)\n\n\n      show \"callOrigin S'a =  map_update_all s_callOrigin (localCalls@[c]) (the (Some tx))\"\n        by (auto simp add: map_update_all_get  S'a_def Step map_add_def intro!: ext dest!: map_of_SomeD split: option.splits)\n\n      show \"case Some tx of None \\<Rightarrow> localCalls @ [c] = []\n            | Some tx' \\<Rightarrow> set (localCalls @ [c]) = {c. callOrigin S'a c \\<triangleq> tx'}\"\n        using Step.case_option Step.callOrigin_eq by  (auto simp add: s S'a_def Step map_add_def map_of_None split: option.splits del: )\n\n\n      have \"c \\<notin> set localCalls\"\n        using Step.state_wellFormed c3 fresh_c wellFormed_visibleCallsSubsetCalls2 by auto\n\n      have \"c \\<notin> vis\"\n        by (meson Step.state_wellFormed UnCI c3 fresh_c wellFormed_visibleCallsSubsetCalls2)\n\n\n      have \"callOrigin S1 c = None\"\n        using wellFormed_callOrigin_dom[OF `state_wellFormed S1`] fresh_c by blast\n\n      hence \"s_callOrigin c = None\"\n        using `callOrigin S1 = map_update_all s_callOrigin localCalls (the (Some tx))`\n        by (auto simp add: map_update_all_get split: if_splits)\n\n\n      show \"sorted_by (happensBefore S'a) (localCalls @ [c])\"\n      proof (auto simp add: sorted_by_append_iff sorted_by_single)\n        from `sorted_by (happensBefore S1) localCalls`\n        show \"sorted_by (happensBefore S'a) localCalls\"\n          using \\<open>c \\<notin> set localCalls\\<close> by (auto simp add: S'a_def sorted_by_def)\n\n        thm Step(18)\n\n        show \"\\<And>x. \\<lbrakk>x \\<in> set localCalls; (c, x) \\<in> happensBefore S'a\\<rbrakk> \\<Longrightarrow> False\"\n          apply (auto simp add: S'a_def Step)\n          using Step.state_wellFormed Step.happensBefore_eq fresh_c wellFormed_happensBefore_calls_l apply blast\n          using \\<open>c \\<notin> vis\\<close> apply blast \n          using \\<open>c \\<notin> set localCalls\\<close> by auto\n      qed\n\n      from `vis \\<inter> set (localCalls) = {}`\n      show \"vis \\<inter> set (localCalls @ [c]) = {}\"\n        by (auto simp add: `c \\<notin> vis`)\n\n\n      show \"dom s_callOrigin \\<inter> set (localCalls @ [c]) = {}\"\n        apply (auto simp add: `s_callOrigin c = None`)\n        using Step.inf_eq2 by blast \n\n      have \"c \\<notin> Field s_happensBefore\"\n        by (metis Field_Un Step.happensBefore_eq Step.state_wellFormed UnI1 fresh_c updateHb_simp_split wellFormed_happensBefore_Field)\n\n      from this and `Field s_happensBefore \\<inter> set localCalls = {}`\n      show \"Field s_happensBefore \\<inter> set (localCalls @ [c]) = {}\"\n        by auto\n\n      from `distinct localCalls` and `c\\<notin>set localCalls`\n      show \"distinct (localCalls @ [c])\"\n        by auto\n\n      show \" execution_s_check progr i (s_calls(c \\<mapsto> Call op res)) s_happensBefore s_callOrigin\n       s_txOrigin s_knownIds s_invocOp s_invocRes {x. generatedIds S1 x \\<triangleq> i} (generatedLocalPrivate - uniqueIds op - uniqueIds res) vis\n       (localCalls @ [c]) (Some tx) firstTx (cont res)\"\n      proof (fuzzy_rule cont)\n        show \"querySpec progr op\n             \\<lparr>calls = s_calls |` (vis \\<union> set localCalls),\n              happensBefore = updateHb (s_happensBefore |r vis) vis localCalls\\<rparr>\n             res\"\n        proof (fuzzy_rule qry; auto simp add: Step getContextH_def del: equalityI)\n          have [simp]: \"s_happensBefore |r (vis \\<union> set localCalls) = (s_happensBefore |r vis)\"\n            using `Field s_happensBefore \\<inter> set localCalls = {}`\n            by (auto simp add: restrict_relation_def Field_def)\n\n\n          show \" updateHb s_happensBefore vis localCalls |r (vis \\<union> set localCalls) =\n            updateHb (s_happensBefore |r vis) vis localCalls\"\n            by (auto simp add: updateHb_restrict)\n        qed\n\n        from `generatedLocal = {x. generatedIds S1 x \\<triangleq> i}`\n        show \"generatedLocal = {x. generatedIds S1 x \\<triangleq> i}\" .\n      qed\n\n      from `firstTx = (\\<nexists>c tx. callOrigin S1 c \\<triangleq> tx \\<and> txOrigin S1 tx \\<triangleq> i \\<and> txStatus S1 tx \\<triangleq> Committed)`\n      show \"firstTx = (\\<nexists>c tx. callOrigin S'a c \\<triangleq> tx \\<and> txOrigin S'a tx \\<triangleq> i \\<and> txStatus S'a tx \\<triangleq> Committed)\"\n        apply auto\n         apply (auto simp add: S'a_def split: if_splits)\n        using c2 not_uncommitted_cases wellFormed_currentTx_unique_h(2) \n        apply (simp add: wellFormed_currentTx_unique_h(2) Step.state_wellFormed)\n        using \\<open>callOrigin S1 c = None\\<close> by force\n\n      show \"generatedLocalPrivate - uniqueIds op - uniqueIds res \\<subseteq> {x. generatedIds S1 x \\<triangleq> i}\"\n        using Step.Ball uid_is_private_def by auto\n\n      \n      fix x\n      assume a0: \"x \\<in> generatedLocalPrivate - uniqueIds op - uniqueIds res\"\n      hence \"uid_is_private i S1 x\"\n        using Step.Ball by auto\n\n\n      show \"uid_is_private i S'a x\"\n        unfolding uid_is_private_def\n      proof (intro conjI)\n\n        show \"new_unique_not_in_other_invocations i S'a x\"\n          using Step.step_s \\<open>uid_is_private i S1 x\\<close> c4 new_unique_not_in_other_invocations_maintained uid_is_private_def by  blast\n\n\n      qed (insert a0 `uid_is_private i S1 x`, auto simp add: S'a_def uid_is_private_def new_unique_not_in_calls_def new_unique_not_in_calls_result_def new_unique_not_in_other_invocations_def)\n\n\n      \n\n    qed (simp add: S'a_def Step; fail)+\n  qed\nqed\n\n\n\n\nlemma execution_s_check_return:\n  assumes progr_wf: \"program_wellFormed progr\"\n    and query_res_exists: \"True\"\nand inv: \"invariant progr\n  \\<lparr>\n        calls = s_calls, \n        happensBefore = s_happensBefore , \n        callOrigin  = s_callOrigin,\n        txOrigin = s_txOrigin,\n        knownIds = s_knownIds  \\<union> uniqueIds res,\n        invocOp = s_invocOp,\n        invocRes = s_invocRes(i \\<mapsto> res)\n      \\<rparr>\"\nshows\"execution_s_check\n  progr \n  i\n  s_calls\n  s_happensBefore \n  s_callOrigin\n  s_txOrigin \n  s_knownIds\n  s_invocOp\n  s_invocRes\n  generatedLocal\n  generatedLocalPriate\n  vis\n  []\n  None\n  firstTx\n  (return res)\n\"\nproof show_proof_rule\n  case (Step trace S1 S_end action S'a Inv trace')\n\n\n  from ` S1 ~~ (i, action, Inv) \\<leadsto>\\<^sub>S S'a`\n    `localState S1 i \\<triangleq> (return res)`\n    `currentProc S1 i \\<triangleq> toImpl`\n    `\\<And>proc. action \\<noteq> AInvoc proc`\n  have c2: \"action = AReturn res\"\n   and c3: \"currentTx S1 i = None\"\n   and S'a_def: \"S'a = S1 \\<lparr>localState := (localState S1)(i := None), currentProc := (currentProc S1)(i := None), visibleCalls := (visibleCalls S1)(i := None), invocRes := invocRes S1(i \\<mapsto> res), knownIds := knownIds S1 \\<union> uniqueIds res\\<rparr>\"\n   and Inv_def: \"Inv \\<longleftrightarrow> invariant (prog S1) (invContextH (callOrigin S1) (txOrigin S1) (txStatus S1) (happensBefore S1) (calls S1) (knownIds S1 \\<union> uniqueIds res) (invocOp S1) (invocRes S1(i \\<mapsto> res)))\"\n    by (auto simp add: step_s.simps)\n\n  show \"Inv \\<and> traceCorrect_s trace'\"\n  proof\n\n    from `\\<forall>tx'. None \\<noteq> Some tx' \\<longrightarrow> txStatus S1 tx' \\<noteq> Some Uncommitted`\n    have txStatus1: \"txStatus S1 tx' \\<noteq> Some Uncommitted\" for tx'\n      by auto\n\n    have txStatus2: \"txStatus S1 tx \\<triangleq> y\n      \\<longleftrightarrow> (txStatus S1 tx \\<triangleq> Committed \\<and> y = Committed)\" for tx y\n      apply auto\n      using txStatus.exhaust txStatus1 by auto\n\n\n\n    from `\\<forall>tx'. None \\<noteq> Some tx' \\<longrightarrow> txStatus S1 tx' \\<noteq> Some Uncommitted`\n    have txStatus3: \"txStatus S1 tx \\<triangleq> Committed\n      \\<longleftrightarrow>txStatus S1 tx \\<noteq> None\" for tx\n      using txStatus.exhaust by (auto, blast)\n\n\n    have commmitted: \"committedTransactions S1 = dom s_txOrigin\"\n      apply (auto simp add: `txOrigin S1 = s_txOrigin`[symmetric] txStatus1)\n       apply (simp add: Step.state_wellFormed txStatus3 wf_transaction_status_iff_origin)\n      by (simp add: Step.state_wellFormed state_wellFormed_txStatus_txOrigin txStatus3)\n\n    have committed2: \"committedCalls S1 = dom (calls S1)\"\n      using Step.state_wellFormed committedCalls_allCommitted txStatus1 by  blast \n\n    hence committed3: \"committedCallsH s_callOrigin (txStatus S1) =  dom s_calls\"\n      by (simp add: Step)\n\n\n    show \"Inv\" \n      unfolding Inv_def invContextH_def\n    proof (fuzzy_rule inv; (simp add: Step commmitted committed3))\n\n      show \"s_callOrigin = s_callOrigin |` dom s_calls\"\n      proof (rule restrict_map_noop[symmetric])\n        show \"dom s_callOrigin \\<subseteq> dom s_calls\"\n          using Step.state_wellFormed Step.callOrigin_eq Step.calls_eq wellFormed_callOrigin_dom  by  fastforce\n      qed\n\n      show \"s_happensBefore = s_happensBefore |r dom s_calls\"\n      proof (rule restrict_relation_noop[symmetric])\n        show \"Field s_happensBefore \\<subseteq> dom s_calls\"\n          apply (auto simp add: Field_def)\n          using Step.state_wellFormed Step.calls_eq Step.happensBefore_eq happensBefore_in_calls_left happensBefore_in_calls_right  by  fastforce+\n      qed\n    qed\n\n\n    show \"traceCorrect_s trace'\"\n    proof (cases trace')\n      case Nil\n      then show ?thesis\n        using traceCorrect_s_empty by auto \n    next\n      case (Cons a list)\n\n      obtain action' Inv' where a_def: \"a = (action', Inv')\"\n        by force\n\n      have no_invoc: \"\\<And>proc. action' \\<noteq> AInvoc proc\"\n        using `trace = (action, Inv) # trace'` `\\<forall>p t. (AInvoc p, t) \\<notin> set trace` a_def local.Cons by auto\n\n\n\n      from Cons `S'a ~~ (i, trace') \\<leadsto>\\<^sub>S* S_end`\n      obtain S'' where \"S'a ~~ (i, (action', Inv')) \\<leadsto>\\<^sub>S S''\"\n        using steps_s_cons_simp a_def by blast \n      hence False\n        using S'a_def no_invoc\n        by (auto simp add: step_s.simps)\n      thus \"traceCorrect_s trace'\" ..\n    qed\n  qed\nqed\n\nlemmas execution_s_check_endAtomic' = execution_s_check_endAtomic[rotated 3, OF context_conjI]\n  \n\nlemmas repliss_proof_rules = \n  execution_s_check_newId\n  execution_s_check_beginAtomic\n  execution_s_check_endAtomic'\n  execution_s_check_pause\n  execution_s_check_dbop\n  execution_s_check_return\n\nmethod repliss_vcg_step = (rule repliss_proof_rules; (intro impI conjI)?; simp?; (intro impI conjI)?;  repliss_vcg_step?)\n\nmethod repliss_vcg uses impl = ((simp add: impl)?, (unfold atomic_def skip_def)?, simp? , repliss_vcg_step)\n\n\ndeclare newId_def[language_construct_defs] \natomic_def[language_construct_defs]  \nbeginAtomic_def [language_construct_defs] \ncall_def [language_construct_defs] \nskip_def [language_construct_defs] \nendAtomic_def [language_construct_defs] \nreturn_def[language_construct_defs] \n\n\nend", "meta": {"author": "peterzeller", "repo": "repliss-isabelle", "sha": "f43744678cc9c5a4684e8bd0e9c83510bae1d9a4", "save_path": "github-repos/isabelle/peterzeller-repliss-isabelle", "path": "github-repos/isabelle/peterzeller-repliss-isabelle/repliss-isabelle-f43744678cc9c5a4684e8bd0e9c83510bae1d9a4/program_proof_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526514141572, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.2782495874508384}}
{"text": "theory regShiftFifo imports paraGste1\nbegin\nabbreviation rst::\"expType\" where\n\"rst \\<equiv> IVar (Ident ''rst'')\"\n\nabbreviation push::\"expType\" where\n\"push \\<equiv> IVar (Ident ''push'')\"\n\nabbreviation pop::\"expType\" where\n\"pop \\<equiv> IVar (Ident ''pop'')\"\n\nabbreviation dataIn::\"expType\" where\n\"dataIn \\<equiv> IVar (Ident ''dataIn'' )\"\n\n\n\nabbreviation LOW::\"expType\" where\n\"LOW \\<equiv> Const (boolV False)\"\nabbreviation HIGH::\"expType\" where\n\" HIGH \\<equiv> Const (boolV True)\"\n\nabbreviation emptyFifo::\"expType\" where\n\" emptyFifo \\<equiv> IVar (Ident ''empty'' ) \"\n\nabbreviation tail::\"expType\" where\n\" tail \\<equiv> IVar (Ident ''tail'' ) \"\n\nabbreviation head::\"expType\" where\n\" head \\<equiv> IVar (Ident ''head'' ) \"\n\n\nabbreviation full::\"expType\" where\n\" full \\<equiv> IVar (Ident ''full'' ) \"\n\ndefinition fullForm::\"nat\\<Rightarrow>formula\" where [simp]:\n\" fullForm DEPTH\\<equiv> eqn tail (Const (index DEPTH)) \"\n\nabbreviation mem::\"nat \\<Rightarrow> expType\" where\n\"mem i \\<equiv> IVar (Para (Ident ''mem'') i)\"\n\ntype_synonym paraExpType=\"nat \\<Rightarrow>expType\"\n\n \n\nabbreviation dataOut::\"nat\\<Rightarrow>expType\" where\n\"dataOut DEPTH \\<equiv> read (Ident ''mem'') DEPTH (IVar (Ident ''tail'' ))\"\n\n\nabbreviation rstForm::\"formula\" where\n\"rstForm  \\<equiv>  (eqn rst HIGH)\"\n\nabbreviation emptyForm::\"formula\" where\n\"emptyForm  \\<equiv>  (eqn emptyFifo HIGH)\"\n \nabbreviation pushForm::\"formula\" where\n\"pushForm \\<equiv> andForm (andForm (eqn rst LOW) (eqn push HIGH)) (eqn pop LOW)\"\n\nabbreviation popForm::\"formula\" where\n\"popForm \\<equiv> andForm (andForm (eqn rst LOW) (eqn push LOW)) (eqn pop HIGH)\"\n\nabbreviation nPushPopForm::\"formula\" where\n\"nPushPopForm \\<equiv> andForm (andForm (eqn rst LOW) (eqn push LOW)) (eqn pop LOW)\"\n\nabbreviation pushDataForm::\"nat \\<Rightarrow>formula\" where\n\" pushDataForm D \\<equiv>andForm pushForm  (eqn dataIn (Const (index D)))\"\n\nabbreviation popDataForm::\"nat\\<Rightarrow>nat \\<Rightarrow>formula\" where\n\" popDataForm DEPTH D \\<equiv>  (eqn (dataOut DEPTH) (Const (index D)))\"\n \nabbreviation nFullForm::\"nat \\<Rightarrow>formula\" where\n\"nFullForm  DEPTH\\<equiv>  neg (fullForm DEPTH)\"\n\nabbreviation nEmptyForm::\"formula\" where\n\"nEmptyForm \\<equiv> neg emptyForm \"\n\n\n\ndefinition  vertexI::\"node\" where [simp]:\n\"vertexI \\<equiv>Vertex  0\"\n\n(*DEPTH=LAST + 1*)\ndefinition  vertexL::\"nat \\<Rightarrow> node list\" where [simp]:\n\"vertexL LAST  \\<equiv>  vertexI # (map (%i. Vertex  i) (down LAST))\"\n\ndefinition edgeL::\"nat \\<Rightarrow> edge list\" where [simp]:\n \"edgeL LAST \\<equiv> [Edge vertexI ( Vertex 1)]\n    @ [Edge  ( Vertex 1) ( Vertex 3)]\t\t\n    @ [Edge  ( Vertex 1) ( Vertex 4)]\t\n    \n\t\t@(map (%i.  ( Edge (Vertex ( 2*i+1 ))  (Vertex (  2*i+1 ))) ) (upt 0  (LAST+2) ))  (* self-loop*)  \n\t  @(map (%i.  ( Edge (Vertex ( 2*i+2 ))  (Vertex (  2*i+2 ))) ) (upt 1  (LAST+2) ))  (* self-loop*)   \n\t  \n\t\t@(map (%i.   ( Edge (Vertex (2 * i + 1))  (Vertex (2 * i + 3))) ) ( upt 1 (LAST+1)))\n\t\t@(map (%i.   ( Edge (Vertex (2 * i + 1))  (Vertex (2 * i + 4))) ) ( upt 1 (LAST+1)))\n\t\t\n\t\t@(map (%i.   ( Edge (Vertex (2 * i + 3))  (Vertex (2 * i + 1))) ) (  upt 0 (LAST+1) )) \n\t\t@(map (%i.   ( Edge (Vertex (2 * i + 4))  (Vertex (2 * i + 2))) ) (  upt 1 (LAST+1) ))\n\t\t@[Edge  ( Vertex 4) ( Vertex 1)]\n\t \"\n\n\nprimrec node2Nat::\"node \\<Rightarrow> nat\" where\n\"node2Nat (Vertex n) = n\"\n\n\ndefinition antOfRbFifo::\"nat\\<Rightarrow>edge\\<Rightarrow>formula\" where [simp]:\n\"antOfRbFifo  D  edge\\<equiv>\n  (let from=node2Nat (source edge) in\n   let to=node2Nat (sink edge) in\n   if (from = 0) then rstForm\telse\n   if (from=to) then nPushPopForm else\n      (if ((from mod 2) =1) then\n        (\n          if ((from + 2)=to) then ( pushForm ) else\n          if (from=(to + 2)) then popForm else\n          pushDataForm D )   \n       else popForm))\"\n\n\n\ndefinition consOfRbFifo::\"nat\\<Rightarrow>nat\\<Rightarrow>edge \\<Rightarrow>formula\" where  [simp]:\n\"consOfRbFifo   D LAST edge \\<equiv>\n(let from=node2Nat (source edge) in\n let to=node2Nat (sink edge) in\n if \t(((from mod 2) = 1) \\<and> ((to mod 2) = 1)) then\n    (if  from =1 then (andForm  emptyForm (nFullForm LAST))\n     else if    (from = (2*LAST+3)) then (andForm nEmptyForm (fullForm LAST)) \n     else andForm nEmptyForm (nFullForm LAST))\n else if (from=4 \\<and> to = 1) then popDataForm LAST D\n else if (from = (2*LAST+4)) then (andForm nEmptyForm (fullForm LAST)) \n else if (from =1 )  then (andForm emptyForm (nFullForm LAST))\n else if (from \\<noteq>0)   then (andForm nEmptyForm (nFullForm LAST))\n else chaos)\"\n\ndefinition rbFifoGsteSpec::\" nat\\<Rightarrow>nat\\<Rightarrow>gsteSpec\" where  [simp]:\n\"rbFifoGsteSpec LAST  data\\<equiv>Graph  vertexI (edgeL  LAST ) (antOfRbFifo data )  (consOfRbFifo data  LAST)\"\n\nprimrec applyPlusN::\"expType\\<Rightarrow>nat \\<Rightarrow>expType\" where\n\"applyPlusN e 0=e\" |\n\"applyPlusN e (Suc N) = uif ''+'' [applyPlusN e N, Const (index 1)]\"\n\ndefinition tagFunOfRegShiftFifo:: \" nat\\<Rightarrow>nodeTagFuncList\" where [simp]:\n\"tagFunOfRegShiftFifo DATA  n \\<equiv> \n  (let x=node2Nat n in\n   let DataE=(Const (index DATA)) in\n   if (x = 0) then [] else\n    (if ((x mod 2) = 1) then \n      (if (x =1) then \n        [eqn tail (Const (index 0)), eqn  emptyFifo (Const (boolV True))]\n       else [eqn tail (Const (index (x div 2 - 1 ))), eqn  emptyFifo (Const (boolV False))] )\n    else \n    (if (x = 2) then [] else\n     [eqn tail (Const (index (x div 2 - 2 ))), eqn  emptyFifo (Const (boolV False)), \n     eqn (IVar (Para (Ident ''mem'') 0)) DataE ]) )\n     )\n   \n \"\n \n definition branch1::\"generalizeStatement\" where (*[simp]:*)\n\"branch1 \\<equiv> \n  (let S1=assign (Ident ''tail'',(Const (index 0))) in\n   let S2=assign (Ident ''empty'',HIGH) in\n   Parallel [S1,S2])\"\n   (*map (\\<lambda>i. assign ((Para (Ident ''mem'') i), \n    iteForm (eqn (Const (index i)) (Const (index 0))) dataIn \n    (read (Ident ''mem'')  LAST  (uif ''-'' [(Const (index i)), (Const (index 1))])))) (upt 1 (LAST +1) )*) \n\ndefinition  branch2::\"nat\\<Rightarrow>generalizeStatement\" where \n\"branch2 LAST \\<equiv> \n  (let S1=\n   map (\\<lambda>i. assign ((Para (Ident ''mem'') i), (IVar (Para (Ident ''mem'') i)))) (upt 1 (LAST +1)) in\n   let S4=assign ((Para (Ident ''mem'') 0), dataIn) in\n   let tailPlus=uif ''+'' [tail, (Const (index 1))] in\n   let S2=assign (Ident ''tail'',iteForm (neg (eqn  emptyFifo HIGH)) tailPlus tail) in\n   let S3=assign (Ident ''empty'',LOW) in\n   Parallel ([S4,S2,S3]@S1))\"   \n   \ndefinition  branch3::\"generalizeStatement\" where \n\"branch3 \\<equiv> \n  (let S1=Parallel [assign (Ident ''empty'',HIGH)] in\n   let S2=Parallel [ assign (Ident ''tail'', uif ''-'' [tail, (Const (index 1))])] in\n    If (eqn tail (Const (index 0))) S1 S2)\" \n\ndefinition tagFunOfRbfifio:: \"nat \\<Rightarrow> nat\\<Rightarrow>nodeTagFuncList\" where [simp]:\n\" tagFunOfRbfifio depth DATA  n \\<equiv> \n  (let x=node2Nat n in\n   let DataE=(Const (index DATA)) in\n   if (x = 0) then [] else\n    (if ((x mod 2) = 1) then \n      (if (x=1) then \n        [eqn tail (Const (index 0)), eqn  emptyFifo (Const (boolV True))]\n       else [eqn tail (applyPlusN head (x div 2 )), eqn  emptyFifo (Const (boolV False))] )\n   else \n   (if (x = (2)) then [] else\n   [eqn tail (applyPlusN head ((x div 2) - 1)), eqn ( read (Ident ''mem'') depth tail) DataE ]) ))\n \"\nabbreviation shiftRegfifo::\" nat\\<Rightarrow>generalizeStatement\" where\n\"shiftRegfifo  LAST\\<equiv> \n  caseStatement \n     [(eqn rst HIGH, branch1),\n      (andForm (eqn push HIGH) (neg (eqn tail (Const (index LAST)))), branch2 LAST),\n      (andForm (eqn pop HIGH) (eqn emptyFifo LOW), branch3)] \n   \"\n  \nconsts J::\" interpretFunType\"  \n  \naxiomatization where axiomOnIAdd [simp,intro]:\n\"  J  ''+'' [index m, index (Suc 0)] = index (m + 1)\" \n\naxiomatization where axiomOnISub [simp,intro ]: \"  J  ''-'' [index m, index 1] = index (m - 1)\"  \n\n\nlemma consistencyOfRbfifo:\n  assumes a:\"0 < LAST \"\n  shows \"consistent' (shiftRegfifo LAST ) (J ) (rbFifoGsteSpec LAST  data) (tagFunOfRegShiftFifo  data)\"\n  proof(unfold consistent'_def,rule allI,rule impI)\n    fix e\n    let ?G=\" (rbFifoGsteSpec LAST  data)\"\n    let ?M=\"( shiftRegfifo  LAST )\"\n    let ?tag=\"(tagFunOfRegShiftFifo  data)\"\n    let ?P =\"\\<lambda>e.   \n    (let f=andListForm (?tag (sink e)) in\n    let f'=andListForm (?tag (source e)) in\n    tautlogy (implyForm (andForm f' (antOf ?G e)) (preCond1  f  ( ?M))) (J ))\"\n    assume a1:\"e \\<in> edgesOf (rbFifoGsteSpec LAST  data)\"\n    \n    have \"e=Edge vertexI ( Vertex 1) | \n          e=Edge  ( Vertex 1) ( Vertex 3) |\n          e=Edge  ( Vertex 1) ( Vertex 4)|\n           (\\<exists>i. 0\\<le>i \\<and> i\\<le> LAST+1 \\<and>  e=( Edge (Vertex ( 2*i+1 ))  (Vertex (  2*i+1 ))) )   |\n            (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST +1\\<and>  e=( Edge (Vertex ( 2*i+2 ))  (Vertex (  2*i+2 ))) ) |\n            \n           (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST  \\<and> e=( Edge (Vertex (2 * i + 1))  (Vertex (2 * i + 3))) ) |\n           (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST  \\<and> e=( Edge (Vertex (2 * i + 1))  (Vertex (2 * i + 4))) )  |\n           \n           (\\<exists>i. 0\\<le>i \\<and> i\\<le> LAST  \\<and>  e= ( Edge (Vertex (2 * i + 3))  (Vertex (2 * i + 1))) ) |\n           (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST   \\<and> e=( Edge (Vertex(2 * i + 4))  (Vertex(2 * i+2)))) |\n            e=( Edge (Vertex 4) (Vertex 1))\"\n      apply(cut_tac  a1,auto)  done\n    \n    moreover\n    {assume b1:\"e=Edge vertexI ( Vertex 1)\"\n     have \"?P e\"\n     apply(cut_tac b1, simp add:antOfRbFifo_def branch1_def) done\n     }\n    moreover\n    {assume b1:\" (\\<exists>i. 0\\<le>i \\<and> i\\<le> LAST+1  \\<and>  e=( Edge (Vertex (2* i + 1))  (Vertex (  2*i + 1))) )  \" (is \"\\<exists>i. ?asm i\")\n     from b1 obtain i where b2:\"?asm i\" by auto\n      have \"?P e\"\n       apply(cut_tac b2, simp add:antOfRbFifo_def substNIl) done\n    }\n    moreover\n    {assume b1:\" (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST+1  \\<and>  e=( Edge (Vertex (2* i + 2))  (Vertex (  2*i + 2))) )  \" (is \"\\<exists>i. ?asm i\")\n     from b1 obtain i where b2:\"?asm i\" by auto\n      have \"?P e\"\n       apply(cut_tac b2, simp add:antOfRbFifo_def substNIl) done\n    }  \n     moreover\n    {assume b1:\" e=Edge  ( Vertex 1) ( Vertex 3) \"\n       have \"?P e\"\n        apply(cut_tac a b1,auto simp add:branch2_def ) done\n    }\n    \n     moreover\n    {assume b1:\" e=Edge  ( Vertex 1) ( Vertex 4) \"\n      let ?f=\"andForm (neg (eqn rst HIGH)) (andForm (eqn push HIGH) (neg (eqn tail (Const (index LAST )))) ) \"\n     \n       have \"?P e \"\n        apply(cut_tac a b1 ,auto simp add:simp add:branch2_def) done\n    }\n    \n    moreover\n    {assume b1:\" \\<exists>i. 1\\<le>i \\<and> i\\<le> LAST \\<and> e=Edge  ( Vertex (2*i + 1)) ( Vertex (2*i + 3))\"     (is \"\\<exists>i. ?Q i\")\n      from b1 obtain i where b1:\"?Q i\" by blast\n      have b2:\"i - 1 < LAST\" by(cut_tac a b1,auto)\n      have \"?P e \"\n        apply(cut_tac  a b1 b2 ,auto simp add: antOfRbFifo_def branch2_def assms ) done\n     }\n    \n    moreover\n    {assume b1:\" \\<exists>i. 1\\<le>i \\<and> i\\<le> LAST \\<and> e=Edge  ( Vertex (2*i + 1)) ( Vertex (2*i+4))    \"(is \"\\<exists>i. ?Q i\")\n      from b1 obtain i where b1:\"?Q i\" by blast\n      have b2:\"i - 1 < LAST\" by(cut_tac a b1,auto)\n      have \"?P e \"\n        by(cut_tac a b1 b2 ,auto simp add: antOfRbFifo_def branch2_def assms)\n     } \n    \n     moreover\n    {assume b1:\"\\<exists>i. 0\\<le>i \\<and> i\\<le> LAST \\<and>  e=Edge  ( Vertex (2*i + 3)) ( Vertex (2*i + 1))   \" (is \"\\<exists>i. ?Q i\")\n       from b1 obtain i where b1:\"?Q i\" by blast\n       have \"?P e \"\n       using  axiomOnISub  by(cut_tac  a b1 ,auto simp add: antOfRbFifo_def branch3_def assms )\n     }\n    \n     moreover\n    {assume b1:\"\\<exists>i.  1\\<le>i \\<and> i\\<le> LAST \\<and> e=Edge  ( Vertex (2*i + 4)) ( Vertex (2*i +2))   \" (is \"\\<exists>i. ?Q i\")\n      from b1 obtain i where b1:\"?Q i\" by blast\n     \n      have \"?P e \"\n       using  axiomOnISub   apply(cut_tac  a b1  ,auto simp add: antOfRbFifo_def branch3_def  assms )\n        done\n     }\n    moreover\n    {assume b1:\"e=Edge (Vertex 4) ( Vertex 1)\"\n     have \"?P e\"\n     apply(cut_tac a b1,auto simp add:antOfRbFifo_def Let_def  branch3_def) done\n     }\n    ultimately show \"?P e\" by satx\n  qed  \n\nlemma testAux[simp]:\n \nshows \"(expEval I e s =index i \\<longrightarrow>\ni \\<le> LAST\\<longrightarrow>expEval I (caseExp ((map (\\<lambda>i. (eqn e (Const (index i)), mem i)) (down LAST)@S))) s \n=expEval  I  (mem i) s) \\<and>\n(expEval I e s =index i \\<longrightarrow>\n LAST < i\\<longrightarrow>expEval I (caseExp ((map (\\<lambda>i. (eqn e (Const (index i)), mem i)) (down LAST)@S))) s \n=expEval  I  (caseExp S) s)\"  (is \"?P LAST\")\nproof(induct_tac LAST,auto )qed \n\nlemma testAux1[simp]:\nshows \"(expEval I e s =index i \\<longrightarrow>\ni \\<le> LAST\\<longrightarrow>expEval I (caseExp ((map (\\<lambda>i. (eqn e (Const (index i)), mem i)) (down LAST)))) s \n=expEval  I  (mem i) s)\"\nproof -\nhave a:\"(expEval I e s =index i \\<longrightarrow>\ni \\<le> LAST\\<longrightarrow>expEval I (caseExp ((map (\\<lambda>i. (eqn e (Const (index i)), mem i)) (down LAST)@[]))) s \n=expEval  I  (mem i) s)\"\napply(cut_tac testAux  [where S=\"[]\"],blast)done\nthen show ?thesis by auto\nqed\n\nlemma test[simp]:assumes a1: \"expEval I e s = (index i)\" and  \n  a2:\"i \\<le> LAST\"\n  shows \"expEval I (caseExp ((map (\\<lambda>i. (eqn e (Const (index i)), mem i)) (down LAST)))) s =\n  expEval I (mem i) s\"\nproof -\nhave a:\"(expEval I e s =index i \\<longrightarrow>\ni \\<le> LAST\\<longrightarrow>expEval I (caseExp ((map (\\<lambda>i. (eqn e (Const (index i)), mem i)) (down LAST)))) s \n=expEval  I  (mem i) s)\"\nby simp\n\nwith a1 a2  show ?thesis by blast\nqed\n\n(*lemma test'[simp]:assumes a1: \"eqn e (Const (index i))\" and  \n  a2:\"i \\<le> LAST\"\n  shows \"eqn (caseExp ((map (\\<lambda>i. (eqn e (Const (index i)), mem i)) (down LAST))))  \n   (mem i) \"\nproof -\nhave a:\"(expEval I e s =index i \\<longrightarrow>\ni \\<le> LAST\\<longrightarrow>expEval I (caseExp ((map (\\<lambda>i. (eqn e (Const (index i)), mem i)) (down LAST)))) s \n=expEval  I  (mem i) s)\"\nby simp\n\nwith a1 a2  show ?thesis by blast\nqed *)\n\nlemma instImply:\nassumes a:\"G=(rbFifoGsteSpec LAST  data)\" and b:\"0 < LAST \"  and c:\"tag=tagFunOfRegShiftFifo  data\"\nshows\n\"\\<forall> e. e \\<in>edgesOf G\\<longrightarrow> \ntautlogy (implyForm (andForm (antOf G e) (andListForm (tag (source e)))) (consOf G e)) I\"  \nproof(rule allI,rule impI,simp,rule allI,rule impI)\n  fix e s\n  assume a1:\"e \\<in> edgesOf G \" and a2:\"\n           formEval I (antOf G e) s \\<and> formEval I (andListForm (tag (source e))) s\" \n  let ?P =\"\\<lambda>e. formEval I (consOf G e) s\"           \n  have \"e=Edge vertexI ( Vertex 1) | \n          e=Edge  ( Vertex 1) ( Vertex 3) |\n          e=Edge  ( Vertex 1) ( Vertex 4)|\n           (\\<exists>i. 0\\<le>i \\<and> i\\<le> LAST+1 \\<and>  e=( Edge (Vertex ( 2*i+1 ))  (Vertex (  2*i+1 ))) )   |\n            (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST+1 \\<and>  e=( Edge (Vertex ( 2*i+2 ))  (Vertex (  2*i+2 ))) ) |\n            \n           (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST  \\<and> e=( Edge (Vertex (2 * i + 1))  (Vertex (2 * i + 3))) ) |\n           (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST  \\<and> e=( Edge (Vertex (2 * i + 1))  (Vertex (2 * i + 4))) )  |\n           \n           (\\<exists>i. 0\\<le>i \\<and> i\\<le> LAST  \\<and>  e= ( Edge (Vertex (2 * i + 3))  (Vertex (2 * i + 1))) ) |\n           (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST   \\<and> e=( Edge (Vertex(2 * i + 4))  (Vertex(2 * i+2)))) |\n            e=( Edge (Vertex 4) (Vertex 1))\"\n      apply(cut_tac a a1,auto)  done\n     \n    moreover\n    {assume b1:\"e=Edge vertexI ( Vertex 1)\"\n     have \"?P e\"\n     apply(cut_tac a b1, auto simp add:antOfRbFifo_def)\n done\n     }\n    moreover\n    {assume b1:\" (\\<exists>i. 0\\<le>i \\<and> i\\<le> LAST+1  \\<and>  e=( Edge (Vertex (2* i + 1))  (Vertex (  2*i + 1))) )  \" (is \"\\<exists>i. ?asm i\")\n     from b1 obtain i where b2:\"?asm i\" by auto\n      have \"?P e\"\n       apply(cut_tac a b c a2 b2, auto) done\n    }\n    moreover\n    {assume b1:\" (\\<exists>i. 1\\<le>i \\<and> i\\<le> LAST+1  \\<and>  e=( Edge (Vertex (2* i + 2))  (Vertex (  2*i + 2))) )  \" (is \"\\<exists>i. ?asm i\")\n     from b1 obtain i where b2:\"?asm i\" by auto\n      have \"?P e\"\n       apply(cut_tac  a b c a2 b2,auto) done\n    }  \n     moreover\n    {assume b1:\" e=Edge  ( Vertex 1) ( Vertex 3) \"\n     \n       have \"?P e\"\n        apply(cut_tac a b c a2 b1,auto ) done\n    }\n    \n     moreover\n    {assume b1:\" e=Edge  ( Vertex 1) ( Vertex 4) \"\n       have \"?P e \"\n        apply(cut_tac a b b1 c a2,auto simp add: antOfRbFifo_def ) done\n    }\n    \n    moreover\n    {assume b1:\" \\<exists>i. 1\\<le>i \\<and> i\\<le> LAST \\<and> e=Edge  ( Vertex (2*i + 1)) ( Vertex (2*i + 3))\"     (is \"\\<exists>i. ?Q i\")\n      from b1 obtain i where b1:\"?Q i\" by blast\n      have \"?P e \"\n        by(cut_tac  a b c a2 b1 ,auto simp add: antOfRbFifo_def assms )\n     }\n    \n    moreover\n    {assume b1:\" \\<exists>i. 1\\<le>i \\<and> i\\<le> LAST \\<and> e=Edge  ( Vertex (2*i + 1)) ( Vertex (2*i+4))    \"(is \"\\<exists>i. ?Q i\")\n      from b1 obtain i where b1:\"?Q i\" by blast\n      have \"?P e \"\n        by(cut_tac  a b c a2 b1 ,auto simp add: antOfRbFifo_def assms)\n     } \n    \n     moreover\n    {assume b1:\"\\<exists>i. 0\\<le>i \\<and> i\\<le> LAST \\<and>  e=Edge  ( Vertex (2*i + 3)) ( Vertex (2*i + 1))   \" (is \"\\<exists>i. ?Q i\")\n       from b1 obtain i where b1:\"?Q i\" by blast\n       have \"?P e \"\n        by(cut_tac   a b c a2 b1 ,auto simp add: antOfRbFifo_def assms )\n     }\n    \n     moreover\n    {assume b1:\"\\<exists>i.  1\\<le>i \\<and> i\\<le> LAST \\<and> e=Edge  ( Vertex (2*i + 4)) ( Vertex (2*i+2 ))   \" (is \"\\<exists>i. ?Q i\")\n      from b1 obtain i where b1:\"?Q i\" by blast\n      have \"?P e \"\n      by(cut_tac  a b c a2 b1 ,auto simp add: antOfRbFifo_def Let_def assms)\n       \n     }\n    moreover\n    {assume b1:\"e=Edge (Vertex 4) ( Vertex 1)\"\n     have \"?P e\"\n     apply(cut_tac  a b c a2 b1 ,auto) done\n     }\n    ultimately show \"?P e\" by satx\n qed      \n\nlemma main: \nassumes a:\"G=(rbFifoGsteSpec LAST  data)\" and b:\"0 < LAST \" \nand c:\"tag=tagFunOfRegShiftFifo  data\" and\nd:\"M=(shiftRegfifo LAST )\"\nshows \" circuitSatGsteSpec M G J \"  \nproof(rule mainLemma)\nhave a1:\"consistent' (shiftRegfifo LAST ) (J ) (rbFifoGsteSpec LAST  data) (tagFunOfRegShiftFifo  data)\" \n   using b by (rule   consistencyOfRbfifo)\nfrom a c d this show \"consistent' M   (J ) G tag\"\n  by simp   \nnext\nfrom a b c show \"\\<forall>e. e \\<in> edgesOf G \\<longrightarrow>\n        tautlogy (implyForm (andForm (antOf G e) (andListForm (tag (source e)))) (consOf G e)) (J )\"\napply(rule instImply) done\nnext\nfrom a c show \"tag (initOf G) = []\"\napply auto done\nqed\nend\n", "meta": {"author": "raphelIos", "repo": "parametricGste", "sha": "91f5c8acc43eee2f070819ce47f6d1a8ca0712f7", "save_path": "github-repos/isabelle/raphelIos-parametricGste", "path": "github-repos/isabelle/raphelIos-parametricGste/parametricGste-91f5c8acc43eee2f070819ce47f6d1a8ca0712f7/regShiftFifo.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5698526514141571, "lm_q2_score": 0.4882833952958347, "lm_q1q2_score": 0.2782495874508384}}
{"text": "(* \n   Title: Psi-calculi   \n   Author/Maintainer: Jesper Bengtson (jebe@itu.dk), 2012\n*)\ntheory Close_Subst\n  imports Agent\nbegin\n\ncontext substPsi\nbegin\n\ndefinition closeSubst :: \"('b::fs_name \\<times> ('a::fs_name, 'b, 'c::fs_name) psi \\<times> ('a, 'b, 'c) psi) set \\<Rightarrow> ('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\nwhere \"closeSubst Rel \\<equiv> {(\\<Psi>, P, Q) | \\<Psi> P Q. (\\<forall>\\<sigma>. wellFormedSubst \\<sigma> \\<longrightarrow> (\\<Psi>, P[<\\<sigma>>], Q[<\\<sigma>>]) \\<in> Rel)}\"\n\nlemma closeSubstI:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<And>\\<sigma>. wellFormedSubst \\<sigma> \\<Longrightarrow> (\\<Psi>, P[<\\<sigma>>], Q[<\\<sigma>>]) \\<in> Rel\"\n\n  shows \"(\\<Psi>, P, Q) \\<in> closeSubst Rel\"\nusing assms\nby(unfold closeSubst_def) auto\n\nlemma closeSubstE:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   \\<sigma> :: \"(name list \\<times> 'a list) list\"\n\n  assumes \"(\\<Psi>, P, Q) \\<in> closeSubst Rel\"\n  and     \"wellFormedSubst \\<sigma>\"\n\n  shows \"(\\<Psi>, P[<\\<sigma>>], Q[<\\<sigma>>]) \\<in> Rel\"\nusing assms\nby(unfold closeSubst_def) auto\n\nlemma closeSubstClosed:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   p :: \"name prm\"\n\n  assumes \"eqvt Rel\"\n  and     \"(\\<Psi>, P, Q) \\<in> closeSubst Rel\"\n\n  shows \"(p \\<bullet> \\<Psi>, p \\<bullet> P, p \\<bullet> Q) \\<in> closeSubst Rel\"\nproof(rule closeSubstI)\n  fix \\<sigma>\n  assume \"wellFormedSubst(\\<sigma>::(name list \\<times> 'a list) list)\"\n  with \\<open>(\\<Psi>, P, Q) \\<in> closeSubst Rel\\<close> \\<open>wellFormedSubst \\<sigma>\\<close>\n  have \"(\\<Psi>, P[<(rev p \\<bullet> \\<sigma>)>], Q[<(rev p \\<bullet> \\<sigma>)>]) \\<in> Rel\"\n    by(rule_tac closeSubstE) auto\n  hence \"(p \\<bullet> \\<Psi>, p \\<bullet> (P[<(rev p \\<bullet> \\<sigma>)>]), p \\<bullet> (Q[<(rev p \\<bullet> \\<sigma>)>])) \\<in> Rel\"\n    by(drule_tac p=p in eqvtI[OF \\<open>eqvt Rel\\<close>]) (simp add: eqvts)\n  thus \"(p \\<bullet> \\<Psi>, (p \\<bullet> P)[<\\<sigma>>], (p \\<bullet> Q)[<\\<sigma>>]) \\<in> Rel\"\n    by(simp del: seqSubs_def add: eqvts)\nqed\n\nlemma closeSubstEqvt:\n  assumes \"eqvt Rel\"\n\n  shows \"eqvt(closeSubst Rel)\"\nproof(auto simp add: eqvt_def)\n  fix \\<Psi> P Q p\n  assume \"(\\<Psi>, P, Q) \\<in> closeSubst Rel\"\n  thus \"((p::name prm) \\<bullet> \\<Psi>, p \\<bullet> P, p \\<bullet> Q) \\<in> closeSubst Rel\"\n    by(drule_tac p=p in closeSubstClosed[OF \\<open>eqvt Rel\\<close>]) (simp add: eqvts)\nqed\n\nlemma closeSubstUnfold:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   \\<sigma> :: \"(name list \\<times> 'a list) list\"\n\n  assumes \"(\\<Psi>, P, Q) \\<in> closeSubst Rel\"\n  and     \"wellFormedSubst \\<sigma>\"\n\n  shows \"(\\<Psi>, P[<\\<sigma>>], Q[<\\<sigma>>]) \\<in> closeSubst Rel\"\nproof(rule closeSubstI)\n  fix \\<sigma>'::\"(name list \\<times> 'a list) list\"\n  assume \"wellFormedSubst \\<sigma>'\"\n  with \\<open>wellFormedSubst \\<sigma>\\<close> have \"wellFormedSubst(\\<sigma>@\\<sigma>')\" by simp\n  with \\<open>(\\<Psi>, P, Q) \\<in> closeSubst Rel\\<close> have \"(\\<Psi>, P[<(\\<sigma>@\\<sigma>')>], Q[<(\\<sigma>@\\<sigma>')>]) \\<in> Rel\"\n    by(rule closeSubstE)\n  thus \"(\\<Psi>, P[<\\<sigma>>][<\\<sigma>'>], Q[<\\<sigma>>][<\\<sigma>'>]) \\<in> Rel\"\n    by simp\nqed\n\nend\n\nend\n  \n\n  \n\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Psi_Calculi/Close_Subst.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526368038304, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.27824958031685837}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory CustomWordAbs\nimports \"../../AutoCorres\"\nbegin\n\ninstall_C_file \"custom_word_abs.c\"\n\nlemma [word_abs]:\n  \"\\<lbrakk> abstract_val P x sint x'; abstract_val Q y sint y' \\<rbrakk> \\<Longrightarrow>\n        abstract_val (P \\<and> Q) (max x y)\n          sint (x' xor (x' xor y') && - (if x' <s y' then (1 :: sword32) else 0))\"\n  apply (clarsimp simp: max_def word_sless_def word_sle_def)\n  done\n\nlemma [word_abs]:\n  \"\\<lbrakk> abstract_val P x unat x'; abstract_val Q y unat y' \\<rbrakk> \\<Longrightarrow>\n         abstract_val (P \\<and> Q \\<and> y < 32) (x mod (2 ^ y)) unat (x' && 2 ^ unat y' - (1 :: word32))\"\n  apply (clarsimp simp del: shiftl_1 simp: shiftl_1 [symmetric])\n  apply (fold mask_def)\n  apply (subst word_mod_2p_is_mask [symmetric])\n  apply (subst p2_gt_0)\n  by (auto simp: unat_mod)\n\nlemma [word_abs]:\n  \"\\<lbrakk> abstract_val P x unat (x' :: word32);\n     abstract_val Q y unat y' \\<rbrakk> \\<Longrightarrow>\n      abstract_val (P \\<and> Q) (x + y > UINT_MAX) id (x' + y' < x')\"\n  apply (subst not_le [symmetric], subst no_plus_overflow_unat_size)\n  apply (clarsimp simp: not_less UINT_MAX_def word_size)\n  apply arith\n  done\n\nautocorres [unsigned_word_abs = b c] \"custom_word_abs.c\"\n\ncontext custom_word_abs begin\n\nlemma \"a' x y = max x y\"\n  by (unfold a'_def, rule refl)\n\nlemma \"b' x 4 s = Some (x mod 16)\"\n  by (unfold b'_def, simp)\n\nlemma \"c' x y = (if UINT_MAX < x + y then 1 else 0)\"\n  by (unfold c'_def, simp)\n\nend\n\nend\n", "meta": {"author": "z5146542", "repo": "TOR", "sha": "9a82d491288a6d013e0764f68e602a63e48f92cf", "save_path": "github-repos/isabelle/z5146542-TOR", "path": "github-repos/isabelle/z5146542-TOR/TOR-9a82d491288a6d013e0764f68e602a63e48f92cf/checker-verification/autocorres-1.4/autocorres/tests/proof-tests/CustomWordAbs.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.629774621301746, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.2781544498816435}}
{"text": "theory Memory\nimports Main \"~~/src/HOL/Library/AList\" \n  \"../Syntax/Type\" Int_Value \"../Syntax/Wf_Checker\"\nbegin\n\n\n\n\n\nsubsection \\<open>Lens for Valuations\\<close>\n  definition \"l_ffld e name \\<equiv> (\n    \\<lambda>a. case map_of a name of None \\<Rightarrow> EAssert e | Some b \\<Rightarrow> return b,\n    \\<lambda>b a. do { assert (map_of a name \\<noteq> None) e; return (AList.update name b a) }\n    )\"\n\n  lemma elens_ffld[simp]: \"elens (l_ffld e name)\"  \n    unfolding l_ffld_def\n    apply (unfold_locales) \n    apply (e_vcg simp: update_conv update_triv split: option.splits)+\n    done\n    \n  lemma l_ffld_get_spec[e_vcg]: \" \n    e_spec (\\<lambda>x. map_of a name = Some x) (\\<lambda>e'. e'=e \\<and> map_of a name = None) False (eget (l_ffld e name) a)\"  \n    unfolding l_ffld_def by e_vcg\n\n  lemma l_ffld_set_spec[e_vcg]: \" \n    e_spec (\\<lambda>a'. map_of a name \\<noteq> None \\<and> map_of a' = (map_of a)(name \\<mapsto> b)) (\\<lambda>_. map_of a name = None) False (eset (l_ffld e name) b a)\"  \n    unfolding l_ffld_def by (e_vcg simp: update_conv)\n\n\nsubsection \\<open>Address Values\\<close>\ntext \\<open>\n  An address holds a memory block, and a path into the value stored there, \n  which identifies the part of that value the pointer points to.\n\\<close>\n\ndatatype subscript = \n  is_Idx: Idx (the_Idx: nat) \n| is_Memb: Memb (the_Memb: mname)\ninterpretation Idx: l_C1 is_Idx the_Idx subscript.Idx \"EDynamic EPtr\"\n  by unfold_locales simp_all\ninterpretation Memb: l_C1 is_Memb the_Memb subscript.Memb \"EDynamic EPtr\"\n  by unfold_locales simp_all\n\nhide_const (open) Idx Memb\ntype_synonym subpath = \"subscript list\"\n\ntype_synonym block_idx = nat\n\ntype_synonym addr = \"block_idx \\<times> subpath\"\n\nsubsection \\<open>Values\\<close>\n\ndatatype val = \n  Null                                    -- \\<open>Null pointer\\<close>\n| is_I: I (the_I: int_val)                -- \\<open>Integer\\<close>\n| is_Addr: Addr (the_Addr: addr)          -- \\<open>Non-null pointer\\<close>  \n| is_Array: Array (the_Array: \"val list\") -- \\<open>Array (Block of consecutive values)\\<close>\n| is_Struct: Struct (the_Struct: \"(mname \\<times> val) list\")  -- \\<open>Struct (Name-value assignment)\\<close>\n| Uninit                                  -- \\<open>Uninitialized value\\<close>\n\ninterpretation I: l_C1 is_I the_I I \"EStatic EType\" by (unfold_locales) auto\ninterpretation Addr: l_C1 is_Addr the_Addr Addr \"EStatic EType\" by (unfold_locales) auto\ninterpretation Array: l_C1 is_Array the_Array Array \"EStatic EType\" by (unfold_locales) auto\ninterpretation Struct: l_C1 is_Struct the_Struct Struct \"EStatic EType\" by (unfold_locales) auto\n\n(*definition l_Struct :: \"(val,(mname\\<times>val) list,_) elens\" where \n  \"l_Struct \\<equiv> ( \\<lambda>(Struct _ ms) \\<Rightarrow> return ms | _ \\<Rightarrow> EAssert type_error,\n     \\<lambda>ms. \\<lambda>(Struct sn _) \\<Rightarrow> return (Struct sn ms) | _ \\<Rightarrow> EAssert type_error)\"\n \nlemma elens_Struct[simp]: \"elens (l_Struct)\"\n  apply unfold_locales\n  unfolding l_Struct_def\n  by (auto split: val.splits)\n\nlemma struct_get_spec[e_vcg]:\n  \"e_spec (\\<lambda>ms. is_Struct v \\<and> ms = the_Struct v) (\\<lambda>e. \\<not>is_Struct v \\<and> e=type_error) False (eget l_Struct v)\"\n  apply (cases v)\n  by (auto simp: l_Struct_def)\n\nlemma struct_set_spec[e_vcg]:\n  \"e_spec (\\<lambda>v'. \\<exists>n ms'. v=Struct n ms' \\<and> v'=Struct n ms) (\\<lambda>e. \\<not>is_Struct v \\<and> e=type_error) False (eset l_Struct ms v)\"\n  apply (cases v)\n  by (auto simp: l_Struct_def)\n\n\n\nsubsection \\<open>Paths into Values\\<close>\nprimrec l_subscript :: \"subscript \\<Rightarrow> (val,val,_) elens\" where\n  \"l_subscript (subscript.Idx i) = Array.l o\\<^sub>l l_nth (EDynamic EOverflow) i\"\n| \"l_subscript (subscript.Memb name) = Struct.l o\\<^sub>l l_ffld (EStatic EStructure) name\"\n\nlemma l_subscript_alt: \"l_subscript ss = (case ss of\n  (subscript.Idx i) \\<Rightarrow> Array.l o\\<^sub>l l_nth (EDynamic EOverflow) i\n| (subscript.Memb name) \\<Rightarrow> Struct.l o\\<^sub>l l_ffld (EStatic EStructure) name)\"\n  by (auto split: subscript.splits)\n\nprimrec l_subpath :: \"subpath \\<Rightarrow> (val,val,_) elens\" where\n  \"l_subpath [] = l_id\"\n| \"l_subpath (s#ss) = l_subscript s o\\<^sub>l l_subpath ss\"\n\nlemma elens_subscript[simp]: \"elens (l_subscript ss)\"\n  by (cases ss) simp_all\n\nlemma elens_subpath[simp]: \"elens (l_subpath p)\"\n  by (induction p) auto\n\nsubsection \\<open>Memory\\<close>\n\ndatatype mem_block = \n  is_Block: Block ty bool (the_Block: val) \n    -- \\<open>Allocated memory block. The flag indicates structural memory,\n        which is on stack or statically allocated, and thus cannot be \n        freed by the program. \\<close>\n| is_Freed: Freed ty\n    -- \\<open>Freed memory block. We retain its type, to be able to argue\n      about valid memory evolutions, where blocks can be freed, but \n      must not be re-allocated or change type. \\<close>\n\n(* TODO: Check again why we need the type of a freed block, and explain here! *)\nprimrec block_ty :: \"mem_block \\<Rightarrow> ty\" where\n  \"block_ty (Block ty _ _) = ty\" | \"block_ty (Freed ty) = ty\"\n\nprimrec is_dynamic_block :: \"mem_block \\<Rightarrow> bool\" where\n  \"is_dynamic_block (Block _ s _) \\<longleftrightarrow> \\<not>s\" | \"is_dynamic_block (Freed _) = False\"\n\ndefinition l_Block :: \"(mem_block,val,_) elens\" where\n  \"l_Block \\<equiv> (\n    \\<lambda>(Block _ _ v) \\<Rightarrow> return v | _ \\<Rightarrow> EAssert pointer_error,\n    \\<lambda>v. \\<lambda>(Block ty s _) \\<Rightarrow> return (Block ty s v) | _ \\<Rightarrow> EAssert pointer_error)\"\n\nlemma elens_Block[simp]: \"elens (l_Block)\"\n  apply unfold_locales\n  unfolding l_Block_def\n  by (auto split: mem_block.splits)\n\nlemma struct_get_spec[e_vcg]:\n  \"e_spec (\\<lambda>ms. is_Block v \\<and> ms = the_Block v) (\\<lambda>e. \\<not>is_Block v \\<and> e=pointer_error) False (eget l_Block v)\"\n  apply (cases v)\n  by (auto simp: l_Block_def)\n\nlemma struct_set_spec[e_vcg]:\n  \"e_spec (\\<lambda>v'. \\<exists>n s ms'. v=Block n s ms' \\<and> v'=Block n s ms) (\\<lambda>e. \\<not>is_Block v \\<and> e=pointer_error) False (eset l_Block ms v)\"\n  apply (cases v)\n  by (auto simp: l_Block_def)\n\nlemma [simp]: \n  \"\\<not>is_nonterm (eget l_Block a)\"\n  \"\\<not>is_nonterm (eset l_Block b a)\"\n  by (auto simp: l_Block_def split: mem_block.splits)\n\n\n(*interpretation Block!: l_C1 is_Block the_Block Block \"EDynamic EPtr\"\n  by (unfold_locales) auto\n*)\n\ntype_synonym memory = \"mem_block list\"\n\ndefinition is_valid_block :: \"memory \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"is_valid_block m bi \\<equiv> bi<length m \\<and> \\<not>is_Freed (m!bi)\"\n\nabbreviation assert_valid_block :: \"memory \\<Rightarrow> nat \\<hookrightarrow> unit\" where\n  \"assert_valid_block m bi \\<equiv> assert (is_valid_block m bi) (EDynamic EPtr)\"\n\ntext \\<open>Memory can only hold positive sized values\\<close>\nfun nonzerosize_val :: \"val \\<Rightarrow> bool\" where\n  \"nonzerosize_val val.Null \\<longleftrightarrow> True\"\n| \"nonzerosize_val (val.I _) \\<longleftrightarrow> True\"\n| \"nonzerosize_val (val.Addr _) \\<longleftrightarrow> True\"\n| \"nonzerosize_val (val.Array vs) \\<longleftrightarrow> (\\<exists>v\\<in>set vs. nonzerosize_val v)\"\n| \"nonzerosize_val (val.Struct ms) \\<longleftrightarrow> (\\<exists>(_,v)\\<in>set ms. nonzerosize_val v)\"\n| \"nonzerosize_val (val.Uninit) \\<longleftrightarrow> True\"\n\ndefinition raw_alloc :: \"ty \\<Rightarrow> bool \\<Rightarrow> val \\<Rightarrow> memory \\<hookrightarrow> (block_idx \\<times> memory)\" \n  -- \\<open>Allocate block initialized with value. \n    The Boolean is set if the block is to be flagged as static or stack memory.\\<close>\nwhere\n  \"raw_alloc ty s v m \\<equiv> do {\n    assert (nonzerosize_val v) type_error;\n    let idx = length m;\n    let m = m@[Block ty s v];\n    return (idx,m)\n  }\"\n\ndefinition raw_free :: \"bool \\<Rightarrow> block_idx \\<Rightarrow> memory \\<hookrightarrow> memory\"  where\n  \"raw_free allow_static bi m \\<equiv> do {\n    assert_valid_block m bi;\n    let blk = m!bi;\n    assert (allow_static \\<or> is_dynamic_block blk) pointer_error;\n    let ty = block_ty blk;\n    let m = m[bi:=Freed ty];\n    return m\n  }\"\n\ndefinition l_raw_mem :: \"block_idx \\<Rightarrow> (memory,val,_) elens\" where\n  \"l_raw_mem bi \\<equiv> l_nth (EDynamic EPtr) bi o\\<^sub>l l_Block\"\n\nlemma elens_raw_mem[simp]: \"elens (l_raw_mem bi)\"\n  unfolding l_raw_mem_def by simp\n\n\n\nsubsection \\<open>Types\\<close>\n\n\nfun new_val :: \"ty \\<Rightarrow> val\" where\n  \"new_val ty.Null = val.Uninit\"\n| \"new_val ty.I = val.Uninit\"\n| \"new_val (ty.Ptr _) = val.Uninit\"\n| \"new_val (ty.StructPtr _) = val.Uninit\"\n| \"new_val (ty.Array sz ty) = val.Array (replicate sz (new_val ty))\"\n| \"new_val (ty.Struct sn ms) = val.Struct (map (\\<lambda>(x,T). (x, new_val T)) ms)\"\n\ndefinition alloc :: \"ty \\<Rightarrow> bool \\<Rightarrow> memory \\<hookrightarrow> (addr\\<times>memory)\" \nwhere\n  \"alloc ty static \\<mu> \\<equiv> do {\n    (bi,\\<mu>) \\<leftarrow> raw_alloc ty static (new_val ty) \\<mu>;\n    return ((bi,[]),\\<mu>)\n  }\"\n\n\ndefinition calloc :: \"ty \\<Rightarrow> bool \\<Rightarrow> nat \\<Rightarrow> memory \\<hookrightarrow> (addr\\<times>memory)\" \n  -- \\<open>Allocate an array of memory objects. Array size must be greater 0,\n      as a zero size results in undefined behaviour. \\<close>\nwhere\n  \"calloc ty static n \\<mu> \\<equiv> do {\n    assert (n>0) overflow_error; \n    let ty = ty.Array n ty;\n    (bi,\\<mu>) \\<leftarrow> raw_alloc ty static (new_val ty) \\<mu>;\n    return ((bi,[subscript.Idx 0]),\\<mu>)\n  }\"\n\ndefinition cp_alloc :: \"ty \\<Rightarrow> bool \\<Rightarrow> val \\<Rightarrow> memory \\<hookrightarrow> (addr\\<times>memory)\" where\n  \"cp_alloc ty static v \\<mu> \\<equiv> do {\n    (bi,\\<mu>) \\<leftarrow> raw_alloc ty static v \\<mu>;\n    return ((bi,[]),\\<mu>)\n  }\"\n\ndefinition free :: \"bool \\<Rightarrow> addr \\<Rightarrow> memory \\<hookrightarrow> memory\" where\n  \"free allow_static \\<equiv> \\<lambda>(bi,p) \\<mu>. do {\n    (* Frees both, pointers created by cp_alloc and by calloc *)\n    assert (p=[] \\<or> p=[subscript.Idx 0]) pointer_error;\n    raw_free allow_static bi \\<mu>\n  }\"\n\ndefinition l_addr :: \"addr \\<Rightarrow> (memory,val,_) elens\" where\n  \"l_addr \\<equiv> \\<lambda>(bi,p). l_raw_mem bi o\\<^sub>l l_subpath p\"\n\nlemma elens_addr[simp]: \"elens (l_addr addr)\" by (simp add: l_addr_def split: prod.split)\n\ncontext \n  fixes SM :: struct_map\n  fixes \\<mu> :: memory\nbegin\n\ndefinition MT :: \"nat \\<rightharpoonup> ty\" where\n  \"MT i \\<equiv> if i<length \\<mu> then Some (block_ty (\\<mu>!i)) else None\"\n\ndefinition FREE :: \"nat set\" where\n  \"FREE \\<equiv> { i . i<length \\<mu> \\<and> is_Freed (\\<mu>!i) }\"\n\nfun nty_eq :: \"ty \\<Rightarrow> ty \\<Rightarrow> bool\" where\n  \"nty_eq (ty.StructPtr sn1) (ty.StructPtr sn2) \\<longleftrightarrow> sn1=sn2\"\n| \"nty_eq (ty.StructPtr sn1) (ty.Ptr (ty.Struct sn2 _)) \\<longleftrightarrow> sn1 = sn2\"\n| \"nty_eq (ty.Ptr (ty.Struct sn1 _)) (ty.StructPtr sn2) \\<longleftrightarrow> sn1 = sn2\"\n| \"nty_eq (ty.Ptr (ty.Struct sn1 _)) (ty.Ptr (ty.Struct sn2 _)) \\<longleftrightarrow> sn1 = sn2\"\n| \"nty_eq ty1 ty2 \\<longleftrightarrow> ty1=ty2\"\n\nlemma nty_eq_refl[simp]:\n  \"nty_eq ty ty\"\n  apply (cases \"(ty,ty)\" rule: nty_eq.cases)\n  apply (auto)\n  done\n\nlemma nty_eq_sym: \"nty_eq ty1 ty2 \\<longleftrightarrow> nty_eq ty2 ty1\"\n  apply (cases \"(ty1, ty2)\" rule: nty_eq.cases)\n  by auto\n\nlemma nty_eq_trans[trans]: \"\\<lbrakk>nty_eq ty1 ty2; nty_eq ty2 ty3\\<rbrakk> \\<Longrightarrow> nty_eq ty1 ty3\"\n  apply (cases \"(ty1, ty2)\" rule: nty_eq.cases)\n  apply simp_all\n  apply (cases \"(ty1, ty3)\" rule: nty_eq.cases)\n  apply simp_all\n  apply (cases \"(ty2, ty3)\" rule: nty_eq.cases)\n  apply simp_all\n  apply (cases \"(ty1, ty3)\" rule: nty_eq.cases)\n  apply simp_all\n  done  \n\n\nfun wt_path :: \"ty \\<Rightarrow> ty \\<Rightarrow> subpath \\<Rightarrow> bool\" where\n  \"wt_path T ty [] \\<longleftrightarrow> nty_eq ty T\"\n| \"wt_path T (ty.Array _ ty) (subscript.Idx _ # ss) \\<longleftrightarrow> wt_path T ty ss\"\n| \"wt_path T (ty.Struct _ ms) (subscript.Memb name # ss) \\<longleftrightarrow> (\n    case map_of ms name of\n      None \\<Rightarrow> False\n    | Some ty \\<Rightarrow> wt_path T ty ss  \n    )\"\n| \"wt_path _ _ _ \\<longleftrightarrow> False\"\n\nlemma nty_eq_nostruct_is_eq[simp]: \n  \"\\<lbrakk>\\<not>ty.is_StructPtr ty; \\<not>ty.is_Ptr ty\\<rbrakk> \\<Longrightarrow> nty_eq ty ty' \\<longleftrightarrow> ty=ty'\"\n  apply (cases ty; cases ty')\n  apply (auto split: Option.bind_splits)\n  done\n\nlemma nty_eq_ptr_cases:\n  assumes \"nty_eq (ty.Ptr ty1) ty2\"\n  obtains \n    ty2' where \"ty2 = ty.Ptr ty2'\" \"ty1=ty2'\"\n  | sn ms1 where \"ty1 = ty.Struct sn ms1\" \"ty2 = ty.StructPtr sn\"  \n  | sn ms1 ms2 where \"ty1 = ty.Struct sn ms1\" \"ty2 = ty.Ptr (ty.Struct sn ms2)\"\n  using assms\n  apply (cases \"(ty.Ptr ty1,ty2)\" rule: nty_eq.cases)\n  apply auto\n  done\n\nlemma nty_eq_struct_ptr_cases:\n  assumes \"nty_eq (ty.StructPtr sn) ty2\"\n  obtains \n    \"ty2 = ty.StructPtr sn\"\n  | ms2 where \"ty2 = ty.Ptr (ty.Struct sn ms2)\"  \n  using assms\n  apply (cases \"(ty.StructPtr sn,ty2)\" rule: nty_eq.cases)\n  apply auto\n  done\n\n\nlemma wt_path_cong: \"nty_eq ty ty' \\<Longrightarrow> wt_path T ty p \\<longleftrightarrow> wt_path T ty' p\"\n  apply (induction T ty p arbitrary: ty' rule: wt_path.induct)\n  apply (auto split: )\n  apply (metis nty_eq_trans nty_eq_sym)  \n  apply (metis nty_eq_trans)  \n  apply (auto elim!: nty_eq_ptr_cases) []\n  apply (auto elim!: nty_eq_struct_ptr_cases) []\n  apply (auto elim!: nty_eq_ptr_cases) []\n  apply (auto elim!: nty_eq_struct_ptr_cases) []\n  done\n\nlemma wt_path_cong2: \"nty_eq T T' \\<Longrightarrow> wt_path T ty p \\<longleftrightarrow> wt_path T' ty p\"\n  apply (induction T ty p arbitrary: T' rule: wt_path.induct)\n  apply (auto split: option.splits)\n  apply (metis nty_eq_trans)  \n  apply (metis nty_eq_trans nty_eq_sym)  \n  done\n\ninductive wt_addr:: \"ty \\<Rightarrow> addr \\<Rightarrow> bool\" where\n  \"\\<lbrakk> MT bi = Some bty; wt_path T bty p \\<rbrakk> \\<Longrightarrow> wt_addr T (bi,p)\"\n\ninductive wt_val:: \"ty \\<Rightarrow> val \\<Rightarrow> bool\" where\n  \"wt_val (ty.Null) (val.Null)\"\n| \"wt_val (ty.I) (val.I _)\"\n| \"wt_val (ty.Ptr ty) (val.Null)\"\n| \"\\<lbrakk> wt_addr ty addr \\<rbrakk> \\<Longrightarrow> wt_val (ty.Ptr ty) (val.Addr addr)\"\n| \"wt_val (ty.StructPtr ty) (val.Null)\"\n| \"\\<lbrakk> SM sname = Some mts; wt_addr (ty.Struct sname mts) addr \\<rbrakk> \n    \\<Longrightarrow> wt_val (ty.StructPtr sname) (val.Addr addr)\"\n| \"\\<lbrakk> length vs = sz; \\<forall>i < sz. wt_val ty (vs!i) \\<rbrakk> \\<Longrightarrow> wt_val (ty.Array sz ty) (val.Array vs)\"\n| \"\\<lbrakk> dom (map_of mts) = dom (map_of ms); \n      \\<forall>n T v. map_of mts n = Some T \\<and> map_of ms n = Some v \\<longrightarrow> wt_val T v \\<rbrakk> \n     \\<Longrightarrow> wt_val (ty.Struct sname mts) (val.Struct ms)\"\n| \"wt_val (ty.Null) (val.Uninit)\"\n| \"wt_val (ty.I) (val.Uninit)\"\n| \"wt_val (ty.Ptr _) (val.Uninit)\"\n| \"wt_val (ty.StructPtr _) (val.Uninit)\"\n\ndefinition wt_block :: \"mem_block \\<Rightarrow> bool\" where \n  \"wt_block \\<equiv> \\<lambda>\n    (Block ty _ v) \\<Rightarrow> wt_val ty v \\<and> wf_ty SM ty \\<and> nonzero_ty ty \\<and> nonzerosize_val v \n  | (Freed ty) \\<Rightarrow> nonzero_ty ty \\<and> wf_ty SM ty\"\n\ndefinition wt_mem :: \"bool\" where\n  \"wt_mem \\<equiv> \\<forall>blk\\<in>set \\<mu>. wt_block blk\"\n\ninductive_simps wt_val_ty_conv: \n  \"wt_val (ty.I) v\"\n  \"wt_val (ty.Ptr ty) v\"\n  \"wt_val (ty.StructPtr sn) v\"\n  \"wt_val (ty.Array n ty) v\"\n  \"wt_val (ty.Struct sn mts) v\"\n  \"wt_val (ty.Null) v\"\n\nend\n\nlemma wt_mem_empty[simp]: \"wt_mem SM []\"\n  by (auto simp: wt_mem_def)\n\n\nlemma MT_wf_ty:\n  assumes \"wt_mem SM \\<mu>\"\n  assumes \"MT \\<mu> bi = Some bty\"\n  shows \"wf_ty SM bty\"\n  using assms\n  apply (auto simp: MT_def wt_mem_def \n    split: split_if_asm)\n  apply (auto dest!: nth_mem[of bi \\<mu>] dest!: bspec)\n  apply (auto simp: wt_block_def split: mem_block.splits)\n  done\n\n\ncontext wf_program_loc begin\n\nlemma wt_path_append[simp]: \n  assumes \"wf_ty SM ty\"  \n  shows \"wt_path T ty (p1@p2) \\<longleftrightarrow> \n    (\\<exists>ty'. wf_ty SM ty' \\<and> wt_path ty' ty p1 \\<and> wt_path T ty' p2)\"\n  using assms  \n  apply (induction T ty p1 rule: wt_path.induct)\n  apply (auto split: option.splits)\n  using wt_path_cong apply blast\n  apply (auto simp: SM_mt_wf) []\n  apply (auto simp: SM_mt_wf) [] \n  done\n\nlemma wt_path_cons[simp]:\n  assumes \"NO_MATCH [] p2\"\n  assumes \"wf_ty SM ty\"  \n  shows \"wt_path T ty (s # p2) = (\\<exists>ty'. wf_ty SM ty' \\<and> wt_path ty' ty [s] \\<and> wt_path T ty' p2)\"\n  using wt_path_append[of ty T \"[s]\" p2, OF assms(2)] by simp\n\n  lemma wt_val_cong:\n    assumes \"nty_eq ty ty'\"\n    assumes \"wf_ty SM ty\" \"wf_ty SM ty'\"\n    shows \"wt_val SM \\<mu> ty b \\<longleftrightarrow> wt_val SM \\<mu> ty' b\"\n    using assms\n    apply (cases \"(ty,ty')\" rule: nty_eq.cases)\n    apply simp_all\n    apply (auto intro!: wt_val.intros elim!: wt_val.cases)\n    done\n  \n  lemma wt_addr_cong:\n    assumes \"nty_eq ty ty'\"\n    assumes \"wf_ty SM ty\" \"wf_ty SM ty'\"\n    shows \"wt_addr \\<mu> ty addr \\<longleftrightarrow> wt_addr \\<mu> ty' addr\"\n    using assms wt_path_cong2\n    by (auto simp: wt_addr.simps)  \n\nend\n\n(* TODO/FIXME: Also include constraint that static-flags remain unchanged *)\ndefinition mem_ord :: \"memory \\<Rightarrow> memory \\<Rightarrow> bool\" (infix \"\\<subseteq>\\<^sub>\\<mu>\" 50) where\n  \"\\<mu> \\<subseteq>\\<^sub>\\<mu> \\<mu>' \\<equiv> length \\<mu> \\<le> length \\<mu>' \n    \\<and> (\\<forall>i<length \\<mu>. block_ty (\\<mu>!i) = block_ty (\\<mu>'!i))\n    \\<and> (\\<forall>i<length \\<mu>. is_Freed (\\<mu>!i) \\<longrightarrow> is_Freed (\\<mu>'!i))\"\n\nlemma mem_ord_alt: \"\\<mu> \\<subseteq>\\<^sub>\\<mu> \\<mu>' \\<longleftrightarrow> MT \\<mu> \\<subseteq>\\<^sub>m MT \\<mu>' \\<and> FREE \\<mu> \\<subseteq> FREE \\<mu>'\"\n  apply rule\n  apply (auto simp: mem_ord_def map_le_def MT_def dom_def FREE_def) []\n  using leI apply (auto simp: mem_ord_def map_le_def MT_def dom_def FREE_def split: split_if_asm) []\n  done\n\ndefinition mem_eq :: \"memory \\<Rightarrow> memory \\<Rightarrow> bool\" (infix \"=\\<^sub>\\<mu>\" 50) where\n  \"\\<mu> =\\<^sub>\\<mu> \\<mu>' \\<equiv> \\<mu> \\<subseteq>\\<^sub>\\<mu> \\<mu>' \\<and> \\<mu>' \\<subseteq>\\<^sub>\\<mu> \\<mu>\"\n\nlemma mem_ord_refl[simp]: \"\\<mu> \\<subseteq>\\<^sub>\\<mu> \\<mu>\"\n  by (auto simp: mem_ord_def)\n\nlemma mem_ord_trans[trans]: \"\\<lbrakk>\\<mu>1 \\<subseteq>\\<^sub>\\<mu> \\<mu>2; \\<mu>2 \\<subseteq>\\<^sub>\\<mu> \\<mu>3\\<rbrakk> \\<Longrightarrow> \\<mu>1 \\<subseteq>\\<^sub>\\<mu> \\<mu>3\"\n  by (auto simp: mem_ord_def)\n\nlemma mem_ord_antisym: \"\\<lbrakk> \\<mu> \\<subseteq>\\<^sub>\\<mu> \\<mu>'; \\<mu>'\\<subseteq>\\<^sub>\\<mu> \\<mu> \\<rbrakk> \\<Longrightarrow> \\<mu> =\\<^sub>\\<mu> \\<mu>'\"\n  unfolding mem_eq_def by auto\n\nlemma mem_eq_refl[simp]: \"\\<mu> =\\<^sub>\\<mu> \\<mu>\"\n  unfolding mem_eq_def by auto\n\nlemma mem_eq_sym: \"\\<mu> =\\<^sub>\\<mu> \\<mu>' \\<Longrightarrow> \\<mu>' =\\<^sub>\\<mu> \\<mu>\"\n  unfolding mem_eq_def by auto\n\nlemma mem_eq_trans[trans]: \"\\<lbrakk>\\<mu>1 =\\<^sub>\\<mu> \\<mu>2; \\<mu>2 =\\<^sub>\\<mu> \\<mu>3\\<rbrakk> \\<Longrightarrow> \\<mu>1 =\\<^sub>\\<mu> \\<mu>3\"\n  by (auto simp: mem_eq_def dest: mem_ord_trans)\n\nlemma mem_eq_alt: \n  \"\\<mu> =\\<^sub>\\<mu> \\<mu>' \\<longleftrightarrow> MT \\<mu> = MT \\<mu>' \\<and> FREE \\<mu> = FREE \\<mu>'\"\n  unfolding mem_eq_def mem_ord_alt\n  by (auto intro: map_le_antisym)\n\nlemma mem_eqD1: \"\\<mu> =\\<^sub>\\<mu> \\<mu>' \\<Longrightarrow> \\<mu> \\<subseteq>\\<^sub>\\<mu> \\<mu>'\" by (auto simp: mem_eq_def)\nlemma mem_eqD2: \"\\<mu> =\\<^sub>\\<mu> \\<mu>' \\<Longrightarrow> \\<mu>' \\<subseteq>\\<^sub>\\<mu> \\<mu>\" by (auto simp: mem_eq_def)\n\n\nlemma wt_addr_mono:\n  assumes \"wt_addr \\<mu> T addr\"  \n  assumes \"mem_ord \\<mu> \\<mu>'\"   \n  shows \"wt_addr \\<mu>' T addr\"  \n  using assms\n  by (auto elim!: wt_addr.cases intro: wt_addr.intros simp: mem_ord_alt)\n\nlemma wt_val_mono:\n  assumes \"wt_val SM \\<mu> T v\"  \n  assumes \"\\<mu> \\<subseteq>\\<^sub>\\<mu> \\<mu>'\"   \n  shows \"wt_val SM \\<mu>' T v\"\n  using assms(1,2)\n  by induction (auto intro: wt_val.intros dest: wt_addr_mono)\n\nlemma wt_new_val[simp]: \"wt_val SM \\<mu> T (new_val T)\"\n  apply (induction T)\n  apply (auto intro: wt_val.intros)\n  apply (rule wt_val.intros)\n  apply (auto simp: map_of_map)\n  apply rprems\n  apply (erule map_of_SomeD)\n  by (simp add: snds.simps) (* TODO: This should be in default simpset! *)\n\n\nlemma nonzero_ty_imp_nonzerosize_val:\n  assumes \"wt_val SM \\<mu> ty v\"\n  assumes \"nonzero_ty ty\"\n  shows \"nonzerosize_val v\"\n  using assms\n  apply induction\n  apply auto\n  apply (auto simp: in_set_conv_nth Bex_def) []\n  apply (rename_tac mts ms)  \n  apply (case_tac mts; case_tac ms; simp)\n  apply (auto)\n  by (metis (full_types) case_prodI domD insert_iff map_of_SomeD snd_conv) \n\n\n \nlemma raw_alloc_spec[e_vcg]:\n  assumes \"wt_mem SM \\<mu>\"  \n  assumes \"wt_val SM \\<mu> ty v\"  \n  assumes \"nonzero_ty ty\" \"wf_ty SM ty\"\n  shows \"nd_spec (\\<lambda>(bi,\\<mu>'). \n    bi\\<ge>length \\<mu> \\<and> MT \\<mu>' bi = Some ty \\<and> \\<mu> \\<subseteq>\\<^sub>\\<mu> \\<mu>'\n  \\<and> wt_mem SM \\<mu>') (raw_alloc ty static v \\<mu>)\"\nproof -\n  have MTSS: \"\\<mu> \\<subseteq>\\<^sub>\\<mu> (\\<mu> @ [Block ty static v])\"\n    by (auto simp: mem_ord_def nth_append)\n\n  show ?thesis  \n    using assms MTSS\n    unfolding raw_alloc_def Let_def\n    by (fastforce \n      simp: wt_mem_def nth_append MT_def wt_block_def \n      simp: nonzero_ty_imp_nonzerosize_val\n      split: mem_block.splits intro: wt_val_mono[OF _ MTSS])\nqed    \n\n\nlemma alloc_spec[e_vcg]:\n  assumes \"wt_mem SM \\<mu>\"  \n  assumes \"nonzero_ty ty\" \"wf_ty SM ty\"\n  shows \"nd_spec (\\<lambda>(addr,\\<mu>'). \n    \\<mu> \\<subseteq>\\<^sub>\\<mu> \\<mu>' \\<and> wt_mem SM \\<mu>' \\<and> wt_addr \\<mu>' ty addr) (alloc ty static \\<mu>)\"\nproof -\n  show ?thesis  \n    using assms\n    unfolding alloc_def \n    apply (e_vcg \n      intro!: wt_new_val \n      simp: wt_addr.simps wt_val_ty_conv\n      split: prod.splits)\n    done\nqed    \n\n\nlemma calloc_spec[e_vcg]:\n  assumes \"wt_mem SM \\<mu>\"  \n  assumes \"nonzero_ty ty\" \"wf_ty SM ty\"\n  shows \"nd_spec (\\<lambda>(addr,\\<mu>'). \n    \\<mu> \\<subseteq>\\<^sub>\\<mu> \\<mu>' \\<and> wt_mem SM \\<mu>' \\<and> wt_addr \\<mu>' ty addr) (calloc ty static n \\<mu>)\"\nproof -\n  show ?thesis  \n    using assms\n    unfolding calloc_def \n    apply (e_vcg \n      intro!: wt_new_val \n      simp: wt_addr.simps wt_val_ty_conv\n      split: prod.splits)\n    done\nqed    \n\nlemma cp_alloc_spec[e_vcg]:\n  assumes \"wt_mem SM \\<mu>\"  \n  assumes \"wt_val SM \\<mu> ty v\"  \n  assumes \"nonzero_ty ty\" \"wf_ty SM ty\"\n  shows \"nd_spec (\\<lambda>(addr,\\<mu>'). \n    \\<mu> \\<subseteq>\\<^sub>\\<mu> \\<mu>' \\<and> wt_mem SM \\<mu>' \\<and> wt_addr \\<mu>' ty addr) (cp_alloc ty static v \\<mu>)\"\nproof -\n  show ?thesis  \n    using assms\n    unfolding cp_alloc_def \n    apply (e_vcg intro!: wt_new_val simp: wt_addr.simps split: prod.splits)\n    done\nqed    \n\nlemma raw_free_spec_aux:\n  assumes \"wt_mem SM \\<mu>\"\n  assumes \"i<length \\<mu>\" \"\\<mu>!i = Block ty static v\"\n  shows \"wt_mem SM (\\<mu>[i:=Freed ty])\" (is \"wt_mem SM ?\\<mu>'\")   \nproof -\n  from assms have LE: \"\\<mu> \\<subseteq>\\<^sub>\\<mu> ?\\<mu>'\"\n    by (auto simp: mem_ord_def nth_list_update)\n\n  show ?thesis  \n    using assms\n    apply (auto simp: wt_mem_def elim!: in_set_upd_cases)\n    apply (auto simp: wt_block_def split: mem_block.splits dest!: nth_mem) []\n    apply (auto simp: wt_block_def wt_val_mono[OF _ LE] split: mem_block.splits) []\n    done\nqed\n\nlemma raw_free_spec[e_vcg]:\n  assumes \"wt_mem SM \\<mu>\"  \n  shows \"nd_spec (\\<lambda>\\<mu>'. \\<mu> \\<subseteq>\\<^sub>\\<mu> \\<mu>' \\<and> wt_mem SM \\<mu>') (raw_free allow_static bi \\<mu>)\"\nproof -\n  have \"nd_spec (\\<lambda>\\<mu>'. \\<mu> \\<subseteq>\\<^sub>\\<mu> \\<mu>') (raw_free allow_static bi \\<mu>)\"\n    unfolding raw_free_def \n    by (e_vcg simp: is_valid_block_def mem_ord_def nth_list_update)\n  hence aux: \"\\<And>P. nd_spec (\\<lambda>\\<mu>'. \\<mu> \\<subseteq>\\<^sub>\\<mu> \\<mu>' \\<longrightarrow> P \\<mu>') (raw_free allow_static bi \\<mu>) \n    \\<Longrightarrow> nd_spec P (raw_free allow_static bi \\<mu>)\"\n    by (simp add: pw_espec_iff)\n\n  show ?thesis  \n    apply (rule aux)\n    using assms\n    unfolding raw_free_def \n    apply e_vcg'\n    apply (cases \"\\<mu>!bi\")\n    apply (simp_all add: raw_free_spec_aux is_valid_block_def)\n    done\nqed    \n\nlemma free_spec[e_vcg]:\n  assumes \"wt_mem SM \\<mu>\"\n  shows \"nd_spec (\\<lambda>\\<mu>'. \\<mu> \\<subseteq>\\<^sub>\\<mu> \\<mu>' \\<and> wt_mem SM \\<mu>') (free allow_static addr \\<mu>)\"\n  using assms unfolding free_def by (cases addr) e_vcg\n\nlemma is_BlockE: assumes \"is_Block b\" obtains ty static v where \"b = Block ty static v\"\n  using assms by (cases b) auto\n\nlemma raw_mem_get_spec[e_vcg]:\n  assumes \"wt_mem SM \\<mu>\"\n  assumes \"MT \\<mu> bi = Some T\"\n  shows \"nd_spec (wt_val SM \\<mu> T) (eget (l_raw_mem bi) \\<mu>)\"\n  using assms\n  unfolding l_raw_mem_def wt_mem_def\n  apply (e_vcg') \n  apply (auto elim!: is_BlockE simp: dom_def wt_block_def split: mem_block.splits)\n  using MT_def nth_mem by fastforce\n\n\nlemma raw_mem_set_spec[e_vcg]:\n  assumes \"wt_mem SM \\<mu>\"\n  assumes \"MT \\<mu> bi = Some T\"\n  assumes \"wt_val SM \\<mu> T v\"\n  shows \"nd_spec (\\<lambda>\\<mu>'. wt_mem SM \\<mu>' \\<and> \\<mu> =\\<^sub>\\<mu> \\<mu>') (eset (l_raw_mem bi) v \\<mu>)\"\nproof (cases \"is_Freed (\\<mu>!bi)\")\n  case True\n  thus ?thesis\n    by (e_vcg simp: l_raw_mem_def)\n\nnext\n  case False\n  with assms(2) obtain static vh where X1: \"\\<mu>!bi = Block T static vh\" \"bi<length \\<mu>\"\n    by (cases \"\\<mu>!bi\") (auto simp: MT_def split: split_if_asm)\n  hence X2: \"Block T static vh \\<in> set \\<mu>\"  \n    by (auto simp: in_set_conv_nth)\n\n  have MTEQ: \"\\<mu> =\\<^sub>\\<mu> \\<mu>[bi := Block T static v]\"\n    using assms(2) X1\n    by (auto simp: mem_eq_def mem_ord_def MT_def nth_list_update split: split_if_asm)\n  hence MTSS: \"\\<mu> \\<subseteq>\\<^sub>\\<mu> \\<mu>[bi := Block T static v]\"\n    by (auto simp: mem_eq_def)\n\n  from assms(1) have [simp]: \"nonzero_ty T\" \"wf_ty SM T\" \n    unfolding wt_mem_def MT_def wt_block_def\n    using X2 by auto\n\n  with assms(3) have [simp]: \"nonzerosize_val v\" \n    by (blast intro: nonzero_ty_imp_nonzerosize_val)\n\n  show ?thesis\n    using assms X1 MTEQ  \n    unfolding l_raw_mem_def wt_mem_def[abs_def]\n    apply (e_vcg' simp: in_set_conv_nth nth_list_update split: split_if_asm)\n    apply (auto \n      simp: wt_block_def  \n      split: mem_block.splits split_if_asm\n      elim!: in_set_upd_cases\n      intro: wt_val_mono[OF _ MTSS]\n      )\n    done    \nqed\n\ncontext wf_program_loc\nbegin\n\ncontext begin\n\nprivate lemma dom_eq_SomeE: \n  assumes \"dom a = dom b\"  \n  assumes \"a k = Some x\" \n  obtains y where \"dom a = dom b\" \"b k = Some y\"\n  using assms by auto\n\nlemma get_subpath_spec[e_vcg]:\n  assumes \"wt_path T bty p\" \n  assumes \"wt_val SM \\<mu> bty b\"\n  assumes \"wf_ty SM T\" \"wf_ty SM bty\"\n  shows \"nd_spec (wt_val SM \\<mu> T) (eget (l_subpath p) b)\"\n  using assms\n  apply (induction bty p arbitrary: b rule: wt_path.induct)\n  apply (simp_all)\n\n  apply (e_vcg dest: wt_val_cong)\n\n  apply (erule wt_val.cases; clarsimp)\n  apply e_vcg\n\n  apply (erule wt_val.cases; clarsimp split: option.splits)\n  apply (erule (1) dom_eq_SomeE)\n  apply (e_vcg simp: SM_mt_wf)\n  done\n\nlemma set_subpath_spec[e_vcg]:\n  assumes \"wt_path T bty p\" \n  assumes \"wt_val SM \\<mu> bty b\"\n  assumes \"wt_val SM \\<mu> T v\"\n  assumes \"wf_ty SM T\" \"wf_ty SM bty\"\n  shows \"nd_spec (wt_val SM \\<mu> bty) (eset (l_subpath p) v b)\"\n  using assms\n  apply (induction bty p arbitrary: b rule: wt_path.induct)\n  apply (simp_all)\n  \n  apply (e_vcg dest: wt_val_cong)\n\n  apply (erule wt_val.cases; clarsimp)\n  apply (e_vcg intro!: wt_val.intros simp: nth_list_update)\n\n  apply (erule wt_val.cases; clarsimp split: option.splits)\n  apply (erule (1) dom_eq_SomeE)\n  apply (e_vcg simp: SM_mt_wf\n      intro!: wt_val.intros elim: dom_eq_SomeE split: split_if_asm)\n  done\n\nend\n\nlemma get_addr_spec[e_vcg]:\n  assumes \"wt_mem SM \\<mu>\"\n  assumes \"wt_addr \\<mu> T addr\"\n  assumes \"wf_ty SM T\"\n  shows \"nd_spec (wt_val SM \\<mu> T) (eget (l_addr addr) \\<mu>)\"\n  using assms(1,2,3)\n  unfolding l_addr_def \n  apply (cases addr; clarsimp)\n  apply (erule wt_addr.cases; clarsimp)\n  apply (e_vcg simp: MT_wf_ty)\n  done\n\nlemma set_addr_spec[e_vcg]:\n  assumes \"wt_mem SM \\<mu>\"\n  assumes \"wt_addr \\<mu> T addr\"\n  assumes \"wt_val SM \\<mu> T v\"\n  assumes \"wf_ty SM T\"\n  shows \"nd_spec (\\<lambda>\\<mu>'. wt_mem SM \\<mu>' \\<and> \\<mu> =\\<^sub>\\<mu> \\<mu>') (eset (l_addr addr) v \\<mu>)\"\n  using assms\n  unfolding l_addr_def \n  apply (cases addr; clarsimp)\n  apply (erule wt_addr.cases; clarsimp)\n  apply (e_vcg simp: MT_wf_ty)\n  done\nend\n\nsubsection \\<open>Memory Related Operations\\<close>\n\ndefinition is_allocated_raw :: \"memory \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"is_allocated_raw \\<mu> bi \\<equiv> bi<length \\<mu> \\<and> is_Block (\\<mu>!bi)\"\n\ndefinition is_allocated :: \"memory \\<Rightarrow> addr \\<Rightarrow> bool\" where\n  \"is_allocated \\<mu> \\<equiv> \\<lambda>(bi,_). is_allocated_raw \\<mu> bi\"\n\ndefinition resolve_subpath_array :: \"val \\<Rightarrow> subpath \\<hookrightarrow> subpath \\<times> nat \\<times> nat\" \n  -- \\<open>Get index and array size for sub-path to array element.\n    Throws pointer-error if this is not a path to an array. \\<close>\nwhere\n  \"resolve_subpath_array v p \\<equiv> do {\n    j \\<leftarrow> eget (l_last pointer_error o\\<^sub>l Idx.l) p;\n    p' \\<leftarrow> eget (l_butlast pointer_error) p;\n    vs \\<leftarrow> eget (l_subpath p' o\\<^sub>l Array.l) v;\n    return (p',j,length vs)\n  }\"\n\n\ndefinition index_subpath :: \"val \\<Rightarrow> int \\<Rightarrow> subpath \\<hookrightarrow> subpath\" where\n  \"index_subpath v i p \\<equiv> do {\n    (_,j,len) \\<leftarrow> resolve_subpath_array v p;\n    let j = int j + i;\n    assert (j \\<ge> 0 \\<and> nat j\\<le>len) (EDynamic EPtr);\n    p \\<leftarrow> eset (l_last (EDynamic EPtr) o\\<^sub>l Idx.l) (nat j) p;\n    return p\n  }\"\n\ndefinition index_addr :: \"memory \\<Rightarrow> int \\<Rightarrow> addr \\<hookrightarrow> addr\" where\n  \"index_addr \\<equiv> \\<lambda>\\<mu> i (bi,p). do {\n    v \\<leftarrow> eget (l_raw_mem bi) \\<mu>;\n    p \\<leftarrow> index_subpath v i p;\n    return (bi,p)\n  }\"\n\ndefinition cnv_array_to_eptr :: \"memory \\<Rightarrow> addr \\<hookrightarrow> addr\" \n  -- \\<open>Convert address of array to address of its first element\\<close>\nwhere\n  \"cnv_array_to_eptr \\<mu> \\<equiv> \\<lambda>(bi,p). do {\n    eget (l_addr (bi,p) o\\<^sub>l Array.l) \\<mu>;\n    return (bi,p@[subscript.Idx 0])\n  }\"\n\n\n\nlemma norm_wt_subscript: \"NO_MATCH 0 n \\<Longrightarrow> \n  wt_path T ty [subscript.Idx n] \\<longleftrightarrow> wt_path T ty [subscript.Idx 0]\"\n  by (cases ty) auto\n\ncontext wf_program_loc begin\n\nlemma index_subpath_spec[e_vcg]:\n  assumes \"wt_val SM \\<mu> ty v\"\n  assumes \"wt_path T ty p\"  \n  assumes \"wf_ty SM T\" \"wf_ty SM ty\"\n  shows \"nd_spec (wt_path T ty) (index_subpath v i p)\"\n  using assms\n  unfolding index_subpath_def resolve_subpath_array_def\n  apply (cases p rule: rev_cases)\n  apply e_vcg\n  apply (e_vcg elim!: Idx.E Array.E elim: wt_val.cases simp: norm_wt_subscript)\n  done\n\nlemma index_addr_spec[e_vcg]:\n  assumes \"wt_mem SM \\<mu>\"\n  assumes \"wt_addr \\<mu> T addr\"\n  assumes \"wf_ty SM T\"\n  shows \"nd_spec (wt_addr \\<mu> T) (index_addr \\<mu> i addr)\"\n  using assms\n  unfolding index_addr_def\n  apply -\n  apply (erule wt_addr.cases)\n  apply (e_vcg intro: wt_addr.intros MT_wf_ty)\n  done\n\nlemma cnv_array_to_eptr_spec[e_vcg]:\n  assumes \"wt_mem SM \\<mu>\"\n  assumes \"wt_addr \\<mu> (ty.Array n T) addr\"\n  assumes \"wf_ty SM (ty.Array n T)\"\n  shows \"nd_spec (wt_addr \\<mu> T) (cnv_array_to_eptr \\<mu> addr)\"\n  using assms\n  unfolding cnv_array_to_eptr_def\n  apply -\n  apply (erule wt_addr.cases)\n  apply (e_vcg \n    intro!: wt_addr.intros exI[where x=\"ty.Array n T\"] \n    simp: MT_wf_ty wt_val_ty_conv)\n  done\n  \n\nend\n\ndefinition diff_subpath :: \"val \\<Rightarrow> subpath \\<Rightarrow> subpath \\<hookrightarrow> int\" where\n  \"diff_subpath v p1 p2 \\<equiv> do {\n    (p1',i1,l) \\<leftarrow> resolve_subpath_array v p1;\n    (p2',i2,_) \\<leftarrow> resolve_subpath_array v p2;\n    assert (p1'=p2') (EDynamic EPtr);\n    return (int i1 - int i2)\n  }\"\n\ndefinition diff_addr :: \"memory \\<Rightarrow> addr \\<Rightarrow> addr \\<hookrightarrow> int\" where\n  \"diff_addr \\<equiv> \\<lambda>\\<mu> (bi1,p1) (bi2,p2). do {\n    assert (is_allocated_raw \\<mu> bi1) pointer_error;\n    assert (is_allocated_raw \\<mu> bi2) pointer_error;\n    assert (bi1 = bi2) (EDynamic EPtr);\n    v \\<leftarrow> eget (l_raw_mem bi2) \\<mu>;\n    diff_subpath v p1 p2\n  }\"\n\n\ncontext wf_program_loc begin\nlemma diff_subpath_spec[e_vcg]:\n  assumes \"wt_val SM \\<mu> ty v\"\n  assumes \"wt_path T ty p1\"  \n  assumes \"wt_path T ty p2\"  \n  assumes \"wf_ty SM ty\"\n  shows \"nd_spec (\\<lambda>_. True) (diff_subpath v p1 p2)\"\n  using assms\n  unfolding diff_subpath_def resolve_subpath_array_def\n  apply (e_vcg elim!: Idx.E Array.E elim: wt_val.cases simp: norm_wt_subscript)\n  done\n\nlemma diff_addr_spec[e_vcg]:\n  assumes \"wt_mem SM \\<mu>\"\n  assumes \"wt_addr \\<mu> T addr1\"\n  assumes \"wt_addr \\<mu> T addr2\"\n  assumes \"wf_ty SM T\"\n  shows \"nd_spec (\\<lambda>_. True) (diff_addr \\<mu> addr1 addr2)\"\n  using assms\n  unfolding diff_addr_def\n  apply (cases addr1, cases addr2)\n  apply (e_vcg elim!: wt_addr.cases intro: MT_wf_ty)\n  done\nend\n\ndefinition memb_subpath :: \"val \\<Rightarrow> mname \\<Rightarrow> subpath \\<hookrightarrow> subpath\" where\n  \"memb_subpath v name p \\<equiv> do {\n    let p = p@[subscript.Memb name];\n    eget (l_subpath p) v;\n    return p\n  }\"\n\ndefinition memb_addr :: \"memory \\<Rightarrow> mname \\<Rightarrow> addr \\<hookrightarrow> addr\" where\n  \"memb_addr \\<equiv> \\<lambda>\\<mu> name (bi,p). do {\n    v \\<leftarrow> eget (l_raw_mem bi) \\<mu>;\n    p \\<leftarrow> memb_subpath v name p;\n    return (bi,p)\n  }\"\n\ncontext wf_program_loc begin\n\nlemma memb_subpath_spec[e_vcg]:\n  assumes \"wt_val SM \\<mu> ty v\"\n  assumes \"wt_path (ty.Struct sname ms) ty p\"  \n  assumes \"map_of ms name = Some T\"\n  assumes \"wf_ty SM ty\" \"wf_ty SM (ty.Struct sname ms)\"\n  shows \"nd_spec (wt_path T ty) (memb_subpath v name p)\"\n  using assms\n  unfolding memb_subpath_def\n  apply (clarsimp simp: Let_def)\n  apply (rule e_vcg)\n  apply clarsimp\n  apply (rule e_cons, rule e_vcg)\n  apply (subst wt_path_append)\n  apply (assumption)\n  defer\n  apply assumption\n  apply (erule (1) SM_mt_wf)\n  apply (auto intro!: exI[where x=\"(ty.Struct sname ms)\"])\n  done\n\nlemma memb_addr_spec[e_vcg]: \n  assumes \"wt_mem SM \\<mu>\"\n  assumes \"wt_addr \\<mu> (ty.Struct sname ms) addr\"\n  assumes \"map_of ms name = Some T\"\n  assumes \"wf_ty SM (ty.Struct sname ms)\"\n  shows \"nd_spec (wt_addr \\<mu> T) (memb_addr \\<mu> name addr)\"  \n  using assms\n  unfolding memb_addr_def\n  by (e_vcg elim!: wt_addr.cases intro: wt_addr.intros MT_wf_ty)\n\nend\n\nfun valid_subpath :: \"val \\<Rightarrow> subpath \\<Rightarrow> bool\" where\n  \"valid_subpath v [] \\<longleftrightarrow> True\"\n| \"valid_subpath (val.Array vs) ([subscript.Idx i]) \\<longleftrightarrow> i\\<le>length vs\"\n| \"valid_subpath (val.Array vs) (subscript.Idx i#p) \\<longleftrightarrow> i<length vs \\<and> valid_subpath (vs!i) p\"\n| \"valid_subpath (val.Struct ms) (subscript.Memb n#p) \\<longleftrightarrow> \n    (case map_of ms n of None \\<Rightarrow> False | Some v \\<Rightarrow> valid_subpath v p)\"\n| \"valid_subpath _ _ \\<longleftrightarrow> False\"\n\ndefinition valid_addr :: \"memory \\<Rightarrow> addr \\<Rightarrow> bool\" where\n  \"valid_addr \\<mu> \\<equiv> \\<lambda>(bi,p). bi<length \\<mu> \\<and> (\n    case \\<mu>!bi of\n      Freed ty \\<Rightarrow> False\n    | Block ty _ v \\<Rightarrow> valid_subpath v p  \n  )\"\n\nfun readable_subpath :: \"val \\<Rightarrow> subpath \\<Rightarrow> bool\" where\n  \"readable_subpath v [] \\<longleftrightarrow> True\"\n| \"readable_subpath (val.Array vs) (subscript.Idx i#p) \\<longleftrightarrow> i<length vs \\<and> readable_subpath (vs!i) p\"\n| \"readable_subpath (val.Struct ms) (subscript.Memb n#p) \\<longleftrightarrow> \n    (case map_of ms n of None \\<Rightarrow> False | Some v \\<Rightarrow> readable_subpath v p)\"\n| \"readable_subpath _ _ \\<longleftrightarrow> False\"\n\ndefinition readable_addr :: \"memory \\<Rightarrow> addr \\<Rightarrow> bool\" where\n  \"readable_addr \\<mu> \\<equiv> \\<lambda>(bi,p). bi<length \\<mu> \\<and> (\n    case \\<mu>!bi of\n      Freed ty \\<Rightarrow> False\n    | Block ty _ v \\<Rightarrow> readable_subpath v p  \n  )\"\n\n\ncontext wf_program_loc begin\n\nlemma l_subpath_iff_readable_spec: \"e_spec \n  (\\<lambda>_. readable_subpath v p) \n  (\\<lambda>_. \\<not>readable_subpath v p) \n  False \n  (eget (l_subpath p) v)\"\nproof -\n  note [e_vcg del] = get_subpath_spec\n\n  show ?thesis\n    apply (induction v p rule: readable_subpath.induct)\n    (* TODO: Why does splitting in e_vcg not work ?*)\n    apply (e_vcg simp: l_subscript_alt;auto split: subscript.splits; e_vcg)+\n    done\nqed\n\nlemma l_addr_iff_readable_spec: \"e_spec \n  (\\<lambda>_. readable_addr \\<mu> addr) \n  (\\<lambda>_. \\<not>readable_addr \\<mu> addr) \n  False \n  (eget (l_addr addr) \\<mu>)\"\nproof -\n  note [e_vcg del] = get_subpath_spec\n\n  show ?thesis\n    apply (cases addr)\n    apply (clarsimp simp: readable_addr_def l_addr_def l_raw_mem_def)\n    apply (e_vcg' vcg: l_subpath_iff_readable_spec)\n    apply (auto split: mem_block.splits)    \n    done\nqed\n\n\nlemma \"readable_subpath v p \\<Longrightarrow> valid_subpath v p\"\n  apply (induction v p rule: valid_subpath.induct)\n  apply (auto split: option.splits)\n  done\n\nlemma readable_addr_alt: \n  \"readable_addr \\<mu> addr \\<longleftrightarrow> (\\<exists>v. eget (l_addr addr) \\<mu> = return v)\"\n  using l_addr_iff_readable_spec[of \\<mu> addr] \n  apply (cases \"eget (l_addr addr) \\<mu>\")\n  apply (auto simp: pw_espec_iff)\n  done\n\nend  \n\ndatatype ptr_comp_res = PC_EQ | PC_NEQ | PC_LESS | PC_GREATER\n\n\ndefinition compare_addr :: \"memory \\<Rightarrow> addr \\<Rightarrow> addr \\<hookrightarrow> ptr_comp_res\" where\n  \"compare_addr \\<mu> addr1 addr2 \\<equiv> do {\n    assert (valid_addr \\<mu> addr1) pointer_error;\n    assert (valid_addr \\<mu> addr2) pointer_error;\n\n    let (bi1,p1) = addr1;\n    let (bi2,p2) = addr2;\n\n    if bi1\\<noteq>bi2 then do {\n      (* Force addresses to be in allocated range, otherwise\n        the result is undefined due to overlap effects *)\n      assert (readable_addr \\<mu> addr1) pointer_error;\n      assert (readable_addr \\<mu> addr2) pointer_error;\n      return PC_NEQ\n    } else do {\n      let (prf,r1,r2) = split_common_prefix p1 p2;\n  \n      case (r1,r2) of\n        ([],[]) \\<Rightarrow> return PC_EQ\n      | ([],_) \\<Rightarrow> EAssert pointer_error  \n      | (_,[]) \\<Rightarrow> EAssert pointer_error  \n      | (s1#rr1, s2#rr2) \\<Rightarrow> do {\n          (* Do not compare address with its prefix: They might be equal\n            due to zero-indexing --- however, we set it to undefined. *)\n          assert (rr1=[] \\<longleftrightarrow> rr2=[]) pointer_error;\n          (* If the path continues, force addresses to be in range, otherwise\n            the result is undefined due to overlap effects *)\n          assert (rr1\\<noteq>[] \\<longrightarrow> readable_addr \\<mu> addr1 \\<and> readable_addr \\<mu> addr2) pointer_error;\n          case (s1,s2) of\n            (subscript.Idx i1, subscript.Idx i2) \\<Rightarrow> \n              if i1<i2 then return PC_LESS else return PC_GREATER\n          | (subscript.Memb _, subscript.Memb _) \\<Rightarrow> return PC_NEQ\n          | _ \\<Rightarrow> EAssert pointer_error (* TODO: Might want type-error here?! *)\n        }\n    }\n  }\"\n\ndefinition \"addr_less \\<mu> addr1 addr2 \\<equiv> do {\n  pc \\<leftarrow> compare_addr \\<mu> addr1 addr2;\n  case pc of\n    PC_EQ \\<Rightarrow> return False\n  | PC_NEQ \\<Rightarrow> EAssert pointer_error\n  | PC_LESS \\<Rightarrow> return True\n  | PC_GREATER \\<Rightarrow> return False \n}\"\n\ndefinition \"addr_leq \\<mu> addr1 addr2 \\<equiv> do {\n  pc \\<leftarrow> compare_addr \\<mu> addr1 addr2;\n  case pc of\n    PC_EQ \\<Rightarrow> return True\n  | PC_NEQ \\<Rightarrow> EAssert pointer_error\n  | PC_LESS \\<Rightarrow> return True\n  | PC_GREATER \\<Rightarrow> return False \n}\"\n\ndefinition \"addr_eq \\<mu> addr1 addr2 \\<equiv> do {\n  pc \\<leftarrow> compare_addr \\<mu> addr1 addr2;\n  case pc of\n    PC_EQ \\<Rightarrow> return True\n  | PC_NEQ \\<Rightarrow> return False\n  | PC_LESS \\<Rightarrow> return False\n  | PC_GREATER \\<Rightarrow> return False \n}\"\n\nlemma is_allocated_rawE:\n  assumes \"is_allocated_raw \\<mu> bi\"\n  obtains ty static v where \"bi<length \\<mu>\" \"\\<mu>!bi = Block ty static v\"\n  using assms\n  apply (cases \"\\<mu>!bi\")\n  apply (auto simp: is_allocated_raw_def)\n  done\n\nlemma wt_mem_block_imp:\n  assumes \"\\<mu>!bi = Block ty static v\"\n  assumes \"bi < length \\<mu>\"\n  assumes \"wt_mem SM \\<mu>\" \n  shows \n    \"MT \\<mu> bi = Some ty\" \n    \"wt_val SM \\<mu> ty v\" \"wf_ty SM ty\" \"nonzero_ty ty\" \"nonzerosize_val v\"\n  using assms\n  unfolding wt_mem_def wt_block_def\n  by (auto simp: Ball_def in_set_conv_nth MT_def)  \n\nlemma wt_path_idx_conv: \"wt_path T ty (subscript.Idx i#p) \n  \\<longleftrightarrow> (\\<exists>n mty. ty=ty.Array n mty \\<and> wt_path T mty p)\"\n  apply (cases \"(T,ty,subscript.Idx i#p)\" rule: wt_path.cases)\n  apply auto\n  done\n\ncontext wf_program_loc begin\n\nlemma compare_addr_spec[e_vcg]:\n  (*assumes \"wt_mem SM \\<mu>\" \n  assumes \"wt_addr \\<mu> T addr1\"\n  assumes \"wt_addr \\<mu> T addr2\"\n  assumes \"wf_ty SM T\"*)\n  shows \"nd_spec (\\<lambda>_. True) (compare_addr \\<mu> addr1 addr2)\"\n  (*using assms(1-3)*)\n  unfolding compare_addr_def\n  apply (e_vcg')\n  apply (clarsimp split: prod.split list.split subscript.split; safe?; clarsimp)\n  apply e_vcg\n  apply e_vcg\n  apply e_vcg\n  apply e_vcg\n  apply e_vcg\n  done\n\nend\nend\n", "meta": {"author": "glimonta", "repo": "thesis", "sha": "1ef0e434ea7e98c4eb29ffe7bde668cb1951e4ed", "save_path": "github-repos/isabelle/glimonta-thesis", "path": "github-repos/isabelle/glimonta-thesis/thesis-1ef0e434ea7e98c4eb29ffe7bde668cb1951e4ed/src/Semantics/Memory.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297746213017459, "lm_q2_score": 0.44167300566462553, "lm_q1q2_score": 0.2781544498816434}}
{"text": "(*  Title:       variants/b_fwdrreps/Aodv_Loop_Freedom.thy\n    License:     BSD 2-Clause. See LICENSE.\n    Author:      Timothy Bourke, Inria\n*)\n\nsection \"Lift and transfer invariants to show loop freedom\"\n\ntheory B_Aodv_Loop_Freedom\nimports AWN.OClosed_Transfer AWN.Qmsg_Lifting B_Global_Invariants B_Loop_Freedom\nbegin\n\nsubsection \\<open>Lift to parallel processes with queues\\<close>\n\nlemma par_step_no_change_on_send_or_receive:\n    fixes \\<sigma> s a \\<sigma>' s'\n  assumes \"((\\<sigma>, s), a, (\\<sigma>', s')) \\<in> oparp_sos i (oseqp_sos \\<Gamma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V i) (seqp_sos \\<Gamma>\\<^sub>Q\\<^sub>M\\<^sub>S\\<^sub>G)\"\n      and \"a \\<noteq> \\<tau>\"\n    shows \"\\<sigma>' i = \\<sigma> i\"\n  using assms by (rule qmsg_no_change_on_send_or_receive)\n\nlemma par_nhop_quality_increases:\n  shows \"opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg \\<Turnstile> (otherwith ((=)) {i} (orecvmsg (\\<lambda>\\<sigma> m.\n                                    msg_fresh \\<sigma> m \\<and> msg_zhops m)),\n                                  other quality_increases {i} \\<rightarrow>)\n                        global (\\<lambda>\\<sigma>. \\<forall>dip. let nhip = the (nhop (rt (\\<sigma> i)) dip)\n                                          in dip \\<in> vD (rt (\\<sigma> i)) \\<inter> vD (rt (\\<sigma> nhip)) \\<and> nhip \\<noteq> dip\n                                             \\<longrightarrow> (rt (\\<sigma> i)) \\<sqsubset>\\<^bsub>dip\\<^esub> (rt (\\<sigma> nhip)))\"\n    proof (rule lift_into_qmsg [OF seq_nhop_quality_increases])\n    show \"opaodv i \\<Turnstile>\\<^sub>A (otherwith ((=)) {i}\n                         (orecvmsg (\\<lambda>\\<sigma> m. msg_fresh \\<sigma> m \\<and> msg_zhops m)),\n                        other quality_increases {i} \\<rightarrow>)\n                       globala (\\<lambda>(\\<sigma>, _, \\<sigma>'). quality_increases (\\<sigma> i) (\\<sigma>' i))\"\n    proof (rule ostep_invariant_weakenE [OF oquality_increases], simp_all)\n      fix t :: \"(((nat \\<Rightarrow> state) \\<times> (state, msg, pseqp, pseqp label) seqp), msg seq_action) transition\"\n      assume \"onll \\<Gamma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V (\\<lambda>((\\<sigma>, _), _, (\\<sigma>', _)). \\<forall>j. quality_increases (\\<sigma> j) (\\<sigma>' j)) t\"\n      thus \"quality_increases (fst (fst t) i) (fst (snd (snd t)) i)\"\n        by (cases t) (clarsimp dest!: onllD, metis aodv_ex_label)\n    next\n      fix \\<sigma> \\<sigma>' a\n      assume \"otherwith ((=)) {i}\n                (orecvmsg (\\<lambda>\\<sigma> m. msg_fresh \\<sigma> m \\<and> msg_zhops m)) \\<sigma> \\<sigma>' a\"\n      thus \"otherwith quality_increases {i} (orecvmsg (\\<lambda>_. rreq_rrep_sn)) \\<sigma> \\<sigma>' a\"\n        by - (erule weaken_otherwith, auto)\n    qed\n  qed auto\n\nlemma par_rreq_rrep_sn_quality_increases:\n  \"opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. orecvmsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                            globala (\\<lambda>(\\<sigma>, _, \\<sigma>'). quality_increases (\\<sigma> i) (\\<sigma>' i))\"\n  proof -\n    have \"opaodv i \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. orecvmsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                globala (\\<lambda>(\\<sigma>, _, \\<sigma>'). quality_increases (\\<sigma> i) (\\<sigma>' i))\"\n      by (rule ostep_invariant_weakenE [OF olocal_quality_increases])\n         (auto dest!: onllD seqllD elim!: aodv_ex_labelE)\n    hence \"opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. orecvmsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                                   globala (\\<lambda>(\\<sigma>, _, \\<sigma>'). quality_increases (\\<sigma> i) (\\<sigma>' i))\"\n      by (rule lift_step_into_qmsg_statelessassm) simp_all\n    thus ?thesis by rule auto\n  qed\n\nlemma par_rreq_rrep_nsqn_fresh_any_step:\n  shows \"opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. orecvmsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>,\n                                   other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                                  globala (\\<lambda>(\\<sigma>, a, \\<sigma>'). anycast (msg_fresh \\<sigma>) a)\"\n  proof -\n    have \"opaodv i \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. (orecvmsg (\\<lambda>_. rreq_rrep_sn)) \\<sigma>, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                       globala (\\<lambda>(\\<sigma>, a, \\<sigma>'). anycast (msg_fresh \\<sigma>) a)\"\n    proof (rule ostep_invariant_weakenE [OF rreq_rrep_nsqn_fresh_any_step_invariant])\n      fix t\n      assume \"onll \\<Gamma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V (\\<lambda>((\\<sigma>, _), a, _). anycast (msg_fresh \\<sigma>) a) t\"\n      thus \"globala (\\<lambda>(\\<sigma>, a, \\<sigma>'). anycast (msg_fresh \\<sigma>) a) t\"\n        by (cases t) (clarsimp dest!: onllD, metis aodv_ex_label)\n    qed auto\n    hence \"opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. (orecvmsg (\\<lambda>_. rreq_rrep_sn)) \\<sigma>, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                                    globala (\\<lambda>(\\<sigma>, a, \\<sigma>'). anycast (msg_fresh \\<sigma>) a)\"\n      by (rule lift_step_into_qmsg_statelessassm) simp_all\n    thus ?thesis by rule auto\n  qed\n\nlemma par_anycast_msg_zhops:\n  shows \"opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. orecvmsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                                  globala (\\<lambda>(_, a, _). anycast msg_zhops a)\"\n  proof -\n    from anycast_msg_zhops initiali_aodv oaodv_trans aodv_trans\n      have \"opaodv i \\<Turnstile>\\<^sub>A (act TT, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                         seqll i (onll \\<Gamma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V (\\<lambda>(_, a, _). anycast msg_zhops a))\"\n        by (rule open_seq_step_invariant)\n    hence \"opaodv i \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. orecvmsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                            globala (\\<lambda>(_, a, _). anycast msg_zhops a)\"\n    proof (rule ostep_invariant_weakenE)\n      fix t :: \"(((nat \\<Rightarrow> state) \\<times> (state, msg, pseqp, pseqp label) seqp), msg seq_action) transition\"\n      assume \"seqll i (onll \\<Gamma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V (\\<lambda>(_, a, _). anycast msg_zhops a)) t\"\n      thus \"globala (\\<lambda>(_, a, _). anycast msg_zhops a) t\"\n        by (cases t) (clarsimp dest!: seqllD onllD, metis aodv_ex_label)\n    qed simp_all\n    hence \"opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. orecvmsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                                     globala (\\<lambda>(_, a, _). anycast msg_zhops a)\"\n      by (rule lift_step_into_qmsg_statelessassm) simp_all\n    thus ?thesis by rule auto\n  qed\n\nsubsection \\<open>Lift to nodes\\<close>\n\nlemma node_step_no_change_on_send_or_receive:\n  assumes \"((\\<sigma>, NodeS i P R), a, (\\<sigma>', NodeS i' P' R')) \\<in> onode_sos\n                                      (oparp_sos i (oseqp_sos \\<Gamma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V i) (seqp_sos \\<Gamma>\\<^sub>Q\\<^sub>M\\<^sub>S\\<^sub>G))\"\n      and \"a \\<noteq> \\<tau>\"\n    shows \"\\<sigma>' i = \\<sigma> i\"\n  using assms\n  by (cases a) (auto elim!: par_step_no_change_on_send_or_receive)\n\nlemma node_nhop_quality_increases:\n  shows \"\\<langle> i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R \\<rangle>\\<^sub>o \\<Turnstile>\n           (otherwith ((=)) {i}\n              (oarrivemsg (\\<lambda>\\<sigma> m. msg_fresh \\<sigma> m \\<and> msg_zhops m)),\n              other quality_increases {i}\n            \\<rightarrow>) global (\\<lambda>\\<sigma>. \\<forall>dip. let nhip = the (nhop (rt (\\<sigma> i)) dip)\n                                  in dip \\<in> vD (rt (\\<sigma> i)) \\<inter> vD (rt (\\<sigma> nhip)) \\<and> nhip \\<noteq> dip\n                                     \\<longrightarrow> (rt (\\<sigma> i)) \\<sqsubset>\\<^bsub>dip\\<^esub> (rt (\\<sigma> nhip)))\"\n  by (rule node_lift [OF par_nhop_quality_increases]) auto\n\nlemma node_quality_increases:\n  \"\\<langle> i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R \\<rangle>\\<^sub>o \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. oarrivemsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>,\n                                         other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                            globala (\\<lambda>(\\<sigma>, _, \\<sigma>'). quality_increases (\\<sigma> i) (\\<sigma>' i))\"\n  by (rule node_lift_step_statelessassm [OF par_rreq_rrep_sn_quality_increases]) simp\n\nlemma node_rreq_rrep_nsqn_fresh_any_step:\n  shows \"\\<langle> i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R \\<rangle>\\<^sub>o \\<Turnstile>\\<^sub>A\n          (\\<lambda>\\<sigma> _. oarrivemsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n          globala (\\<lambda>(\\<sigma>, a, \\<sigma>'). castmsg (msg_fresh \\<sigma>) a)\"\n  by (rule node_lift_anycast_statelessassm [OF par_rreq_rrep_nsqn_fresh_any_step])\n\nlemma node_anycast_msg_zhops:\n  shows \"\\<langle> i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R \\<rangle>\\<^sub>o \\<Turnstile>\\<^sub>A\n          (\\<lambda>\\<sigma> _. oarrivemsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n          globala (\\<lambda>(_, a, _). castmsg msg_zhops a)\"\n  by (rule node_lift_anycast_statelessassm [OF par_anycast_msg_zhops])\n\nlemma node_silent_change_only:\n  shows \"\\<langle> i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R\\<^sub>i \\<rangle>\\<^sub>o \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. oarrivemsg (\\<lambda>_ _. True) \\<sigma>,\n                                               other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n          globala (\\<lambda>(\\<sigma>, a, \\<sigma>'). a \\<noteq> \\<tau> \\<longrightarrow> \\<sigma>' i = \\<sigma> i)\"\n  proof (rule ostep_invariantI, simp (no_asm), rule impI)\n    fix \\<sigma> \\<zeta> a \\<sigma>' \\<zeta>'\n    assume or: \"(\\<sigma>, \\<zeta>) \\<in> oreachable (\\<langle>i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R\\<^sub>i\\<rangle>\\<^sub>o)\n                                    (\\<lambda>\\<sigma> _. oarrivemsg (\\<lambda>_ _. True) \\<sigma>)\n                                    (other (\\<lambda>_ _. True) {i})\"\n      and tr: \"((\\<sigma>, \\<zeta>), a, (\\<sigma>', \\<zeta>')) \\<in> trans (\\<langle>i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R\\<^sub>i\\<rangle>\\<^sub>o)\"\n      and \"a \\<noteq> \\<tau>\\<^sub>n\"\n    from or obtain p R where \"\\<zeta> = NodeS i p R\"\n      by - (drule node_net_state, metis)\n    with tr have \"((\\<sigma>, NodeS i p R), a, (\\<sigma>', \\<zeta>'))\n                     \\<in> onode_sos (oparp_sos i (trans (opaodv i)) (trans qmsg))\"\n      by simp\n    thus \"\\<sigma>' i = \\<sigma> i\" using \\<open>a \\<noteq> \\<tau>\\<^sub>n\\<close> \n      by (cases rule: onode_sos.cases)\n         (auto elim: qmsg_no_change_on_send_or_receive)\n  qed\n\nsubsection \\<open>Lift to partial networks\\<close>\n\nlemma arrive_rreq_rrep_nsqn_fresh_inc_sn [simp]:\n  assumes \"oarrivemsg (\\<lambda>\\<sigma> m. msg_fresh \\<sigma> m \\<and> P \\<sigma> m) \\<sigma> m\"\n    shows \"oarrivemsg (\\<lambda>_. rreq_rrep_sn) \\<sigma> m\"\n  using assms by (cases m) auto\n\nlemma opnet_nhop_quality_increases:\n  shows \"opnet (\\<lambda>i. opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg) p \\<Turnstile>\n           (otherwith ((=)) (net_tree_ips p)\n              (oarrivemsg (\\<lambda>\\<sigma> m. msg_fresh \\<sigma> m \\<and> msg_zhops m)),\n               other quality_increases (net_tree_ips p) \\<rightarrow>)\n              global (\\<lambda>\\<sigma>. \\<forall>i\\<in>net_tree_ips p. \\<forall>dip.\n                          let nhip = the (nhop (rt (\\<sigma> i)) dip)\n                          in dip \\<in> vD (rt (\\<sigma> i)) \\<inter> vD (rt (\\<sigma> nhip)) \\<and> nhip \\<noteq> dip\n                             \\<longrightarrow> (rt (\\<sigma> i)) \\<sqsubset>\\<^bsub>dip\\<^esub> (rt (\\<sigma> nhip)))\"\n  proof (rule pnet_lift [OF node_nhop_quality_increases])\n    fix i R\n    have \"\\<langle>i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R\\<rangle>\\<^sub>o \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. oarrivemsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>,\n                                              other (\\<lambda>_ _. True) {i} \\<rightarrow>) globala (\\<lambda>(\\<sigma>, a, \\<sigma>').\n            castmsg (\\<lambda>m. msg_fresh \\<sigma> m \\<and> msg_zhops m) a)\"\n    proof (rule ostep_invariantI, simp (no_asm))\n      fix \\<sigma> s a \\<sigma>' s'\n      assume or: \"(\\<sigma>, s) \\<in> oreachable (\\<langle>i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R\\<rangle>\\<^sub>o)\n                                      (\\<lambda>\\<sigma> _. oarrivemsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>)\n                                      (other (\\<lambda>_ _. True) {i})\"\n         and tr: \"((\\<sigma>, s), a, (\\<sigma>', s')) \\<in> trans (\\<langle>i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R\\<rangle>\\<^sub>o)\"\n         and am: \"oarrivemsg (\\<lambda>_. rreq_rrep_sn) \\<sigma> a\"\n      from or tr am have \"castmsg (msg_fresh \\<sigma>) a\"\n        by (auto dest!: ostep_invariantD [OF node_rreq_rrep_nsqn_fresh_any_step])\n      moreover from or tr am have \"castmsg (msg_zhops) a\"\n        by (auto dest!: ostep_invariantD [OF node_anycast_msg_zhops])\n      ultimately show \"castmsg (\\<lambda>m. msg_fresh \\<sigma> m \\<and> msg_zhops m) a\"\n        by (case_tac a) auto\n    qed\n    thus \"\\<langle>i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R\\<rangle>\\<^sub>o \\<Turnstile>\\<^sub>A\n            (\\<lambda>\\<sigma> _. oarrivemsg (\\<lambda>\\<sigma> m. msg_fresh \\<sigma> m \\<and> msg_zhops m) \\<sigma>,\n             other quality_increases {i} \\<rightarrow>) globala (\\<lambda>(\\<sigma>, a, _).\n               castmsg (\\<lambda>m. msg_fresh \\<sigma> m \\<and> msg_zhops m) a)\"\n      by rule auto\n  next\n    fix i R\n    show \"\\<langle>i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R\\<rangle>\\<^sub>o \\<Turnstile>\\<^sub>A\n            (\\<lambda>\\<sigma> _. oarrivemsg (\\<lambda>\\<sigma> m. msg_fresh \\<sigma> m \\<and> msg_zhops m) \\<sigma>,\n             other quality_increases {i} \\<rightarrow>) globala (\\<lambda>(\\<sigma>, a, \\<sigma>').\n               a \\<noteq> \\<tau> \\<and> (\\<forall>d. a \\<noteq> i:deliver(d)) \\<longrightarrow> \\<sigma> i = \\<sigma>' i)\"\n      by (rule ostep_invariant_weakenE [OF node_silent_change_only]) auto\n  next\n    fix i R\n    show \"\\<langle>i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R\\<rangle>\\<^sub>o \\<Turnstile>\\<^sub>A\n            (\\<lambda>\\<sigma> _. oarrivemsg (\\<lambda>\\<sigma> m. msg_fresh \\<sigma> m \\<and> msg_zhops m) \\<sigma>,\n             other quality_increases {i} \\<rightarrow>) globala (\\<lambda>(\\<sigma>, a, \\<sigma>').\n               a = \\<tau> \\<or> (\\<exists>d. a = i:deliver(d)) \\<longrightarrow> quality_increases (\\<sigma> i) (\\<sigma>' i))\"\n      by (rule ostep_invariant_weakenE [OF node_quality_increases]) auto\n  qed simp_all\n\nsubsection \\<open>Lift to closed networks\\<close>\n\nlemma onet_nhop_quality_increases:\n  shows \"oclosed (opnet (\\<lambda>i. opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg) p)\n           \\<Turnstile> (\\<lambda>_ _ _. True, other quality_increases (net_tree_ips p) \\<rightarrow>)\n              global (\\<lambda>\\<sigma>. \\<forall>i\\<in>net_tree_ips p. \\<forall>dip.\n                          let nhip = the (nhop (rt (\\<sigma> i)) dip)\n                          in dip \\<in> vD (rt (\\<sigma> i)) \\<inter> vD (rt (\\<sigma> nhip)) \\<and> nhip \\<noteq> dip\n                             \\<longrightarrow> (rt (\\<sigma> i)) \\<sqsubset>\\<^bsub>dip\\<^esub> (rt (\\<sigma> nhip)))\"\n  (is \"_ \\<Turnstile> (_, ?U \\<rightarrow>) ?inv\")\n  proof (rule inclosed_closed)\n    from opnet_nhop_quality_increases\n      show \"opnet (\\<lambda>i. opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg) p\n               \\<Turnstile> (otherwith ((=)) (net_tree_ips p) inoclosed, ?U \\<rightarrow>) ?inv\"\n    proof (rule oinvariant_weakenE)\n      fix \\<sigma> \\<sigma>' :: \"ip \\<Rightarrow> state\" and a :: \"msg node_action\"\n      assume \"otherwith ((=)) (net_tree_ips p) inoclosed \\<sigma> \\<sigma>' a\"\n      thus \"otherwith ((=)) (net_tree_ips p)\n              (oarrivemsg (\\<lambda>\\<sigma> m. msg_fresh \\<sigma> m \\<and> msg_zhops m)) \\<sigma> \\<sigma>' a\"\n      proof (rule otherwithEI)\n        fix \\<sigma> :: \"ip \\<Rightarrow> state\" and a :: \"msg node_action\"\n        assume \"inoclosed \\<sigma> a\"\n        thus \"oarrivemsg (\\<lambda>\\<sigma> m. msg_fresh \\<sigma> m \\<and> msg_zhops m) \\<sigma> a\"\n        proof (cases a)\n          fix ii ni ms\n          assume \"a = ii\\<not>ni:arrive(ms)\"\n          moreover with \\<open>inoclosed \\<sigma> a\\<close> obtain d di where \"ms = newpkt(d, di)\"\n            by (cases ms) auto\n          ultimately show ?thesis by simp\n        qed simp_all\n      qed\n    qed\n  qed\n\nsubsection \\<open>Transfer into the standard model\\<close>\n\ninterpretation aodv_openproc: openproc paodv opaodv id\n  rewrites \"aodv_openproc.initmissing = initmissing\"\n  proof -\n    show \"openproc paodv opaodv id\"\n    proof unfold_locales\n      fix i :: ip\n      have \"{(\\<sigma>, \\<zeta>). (\\<sigma> i, \\<zeta>) \\<in> \\<sigma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V i \\<and> (\\<forall>j. j \\<noteq> i \\<longrightarrow> \\<sigma> j \\<in> fst ` \\<sigma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V j)} \\<subseteq> \\<sigma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V'\"\n        unfolding \\<sigma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V_def \\<sigma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V'_def\n        proof (rule equalityD1)\n          show \"\\<And>f p. {(\\<sigma>, \\<zeta>). (\\<sigma> i, \\<zeta>) \\<in> {(f i, p)} \\<and> (\\<forall>j. j \\<noteq> i\n                      \\<longrightarrow> \\<sigma> j \\<in> fst ` {(f j, p)})} = {(f, p)}\"\n            by (rule set_eqI) auto\n        qed\n      thus \"{ (\\<sigma>, \\<zeta>) |\\<sigma> \\<zeta> s. s \\<in> init (paodv i)\n                             \\<and> (\\<sigma> i, \\<zeta>) = id s\n                             \\<and> (\\<forall>j. j\\<noteq>i \\<longrightarrow> \\<sigma> j \\<in> (fst o id) ` init (paodv j)) } \\<subseteq> init (opaodv i)\"\n        by simp\n    next\n      show \"\\<forall>j. init (paodv j) \\<noteq> {}\"\n        unfolding \\<sigma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V_def by simp\n    next\n      fix i s a s' \\<sigma> \\<sigma>'\n      assume \"\\<sigma> i = fst (id s)\"\n         and \"\\<sigma>' i = fst (id s')\"\n         and \"(s, a, s') \\<in> trans (paodv i)\"\n      then obtain q q' where \"s = (\\<sigma> i, q)\"\n                         and \"s' = (\\<sigma>' i, q')\"\n                         and \"((\\<sigma> i, q), a, (\\<sigma>' i, q')) \\<in> trans (paodv i)\" \n         by (cases s, cases s') auto\n      from this(3) have \"((\\<sigma>, q), a, (\\<sigma>', q')) \\<in> trans (opaodv i)\"\n        by simp (rule open_seqp_action [OF aodv_wf])\n\n      with \\<open>s = (\\<sigma> i, q)\\<close> and \\<open>s' = (\\<sigma>' i, q')\\<close>\n        show \"((\\<sigma>, snd (id s)), a, (\\<sigma>', snd (id s'))) \\<in> trans (opaodv i)\"\n          by simp\n    qed\n    then interpret opn: openproc paodv opaodv id .\n    have [simp]: \"\\<And>i. (SOME x. x \\<in> (fst o id) ` init (paodv i)) = aodv_init i\"\n      unfolding \\<sigma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V_def by simp\n    hence \"\\<And>i. openproc.initmissing paodv id i = initmissing i\"\n      unfolding opn.initmissing_def opn.someinit_def initmissing_def\n      by (auto split: option.split)\n    thus \"openproc.initmissing paodv id = initmissing\" ..\n  qed\n\ninterpretation aodv_openproc_par_qmsg: openproc_parq paodv opaodv id qmsg\n  rewrites \"aodv_openproc_par_qmsg.netglobal = netglobal\"\n    and \"aodv_openproc_par_qmsg.initmissing = initmissing\"\n  proof -\n    show \"openproc_parq paodv opaodv id qmsg\"\n      by (unfold_locales) simp\n    then interpret opq: openproc_parq paodv opaodv id qmsg .\n\n    have im: \"\\<And>\\<sigma>. openproc.initmissing (\\<lambda>i. paodv i \\<langle>\\<langle> qmsg) (\\<lambda>(p, q). (fst (id p), snd (id p), q)) \\<sigma>\n                                                                                    = initmissing \\<sigma>\"\n      unfolding opq.initmissing_def opq.someinit_def initmissing_def\n      unfolding \\<sigma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V_def \\<sigma>\\<^sub>Q\\<^sub>M\\<^sub>S\\<^sub>G_def by (clarsimp cong: option.case_cong)\n    thus \"openproc.initmissing (\\<lambda>i. paodv i \\<langle>\\<langle> qmsg) (\\<lambda>(p, q). (fst (id p), snd (id p), q)) = initmissing\"\n      by (rule ext)\n    have \"\\<And>P \\<sigma>. openproc.netglobal (\\<lambda>i. paodv i \\<langle>\\<langle> qmsg) (\\<lambda>(p, q). (fst (id p), snd (id p), q)) P \\<sigma>\n                                                                                = netglobal P \\<sigma>\"\n      unfolding opq.netglobal_def netglobal_def opq.initmissing_def initmissing_def opq.someinit_def\n      unfolding \\<sigma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V_def \\<sigma>\\<^sub>Q\\<^sub>M\\<^sub>S\\<^sub>G_def\n      by (clarsimp cong: option.case_cong\n                   simp del: One_nat_def\n                   simp add: fst_initmissing_netgmap_default_aodv_init_netlift\n                                                  [symmetric, unfolded initmissing_def])\n    thus \"openproc.netglobal (\\<lambda>i. paodv i \\<langle>\\<langle> qmsg) (\\<lambda>(p, q). (fst (id p), snd (id p), q)) = netglobal\"\n      by auto\n  qed\n\nlemma net_nhop_quality_increases:\n  assumes \"wf_net_tree n\"\n  shows \"closed (pnet (\\<lambda>i. paodv i \\<langle>\\<langle> qmsg) n) \\<TTurnstile> netglobal\n                           (\\<lambda>\\<sigma>. \\<forall>i dip. let nhip = the (nhop (rt (\\<sigma> i)) dip)\n                                        in dip \\<in> vD (rt (\\<sigma> i)) \\<inter> vD (rt (\\<sigma> nhip)) \\<and> nhip \\<noteq> dip\n                                            \\<longrightarrow> (rt (\\<sigma> i)) \\<sqsubset>\\<^bsub>dip\\<^esub> (rt (\\<sigma> nhip)))\"\n        (is \"_ \\<TTurnstile> netglobal (\\<lambda>\\<sigma>. \\<forall>i. ?inv \\<sigma> i)\")\n  proof -\n    from \\<open>wf_net_tree n\\<close>\n      have proto: \"closed (pnet (\\<lambda>i. paodv i \\<langle>\\<langle> qmsg) n) \\<TTurnstile> netglobal (\\<lambda>\\<sigma>. \\<forall>i\\<in>net_tree_ips n. \\<forall>dip.\n                                            let nhip = the (nhop (rt (\\<sigma> i)) dip)\n                                            in dip \\<in> vD (rt (\\<sigma> i)) \\<inter> vD (rt (\\<sigma> nhip)) \\<and> nhip \\<noteq> dip\n                                                \\<longrightarrow> (rt (\\<sigma> i)) \\<sqsubset>\\<^bsub>dip\\<^esub> (rt (\\<sigma> nhip)))\"\n        by (rule aodv_openproc_par_qmsg.close_opnet [OF _ onet_nhop_quality_increases])\n    show ?thesis\n    unfolding invariant_def opnet_sos.opnet_tau1\n    proof (rule, simp only: aodv_openproc_par_qmsg.netglobalsimp\n                            fst_initmissing_netgmap_pair_fst, rule allI)\n      fix \\<sigma> i\n      assume sr: \"\\<sigma> \\<in> reachable (closed (pnet (\\<lambda>i. paodv i \\<langle>\\<langle> qmsg) n)) TT\"\n      hence \"\\<forall>i\\<in>net_tree_ips n. ?inv (fst (initmissing (netgmap fst \\<sigma>))) i\"\n        by - (drule invariantD [OF proto],\n              simp only: aodv_openproc_par_qmsg.netglobalsimp\n                         fst_initmissing_netgmap_pair_fst)\n      thus \"?inv (fst (initmissing (netgmap fst \\<sigma>))) i\"\n      proof (cases \"i\\<in>net_tree_ips n\")\n        assume \"i\\<notin>net_tree_ips n\"\n        from sr have \"\\<sigma> \\<in> reachable (pnet (\\<lambda>i. paodv i \\<langle>\\<langle> qmsg) n) TT\" ..\n        hence \"net_ips \\<sigma> = net_tree_ips n\" ..\n        with \\<open>i\\<notin>net_tree_ips n\\<close> have \"i\\<notin>net_ips \\<sigma>\" by simp\n        hence \"(fst (initmissing (netgmap fst \\<sigma>))) i = aodv_init i\"\n          by simp\n        thus ?thesis by simp\n      qed metis\n    qed\n  qed\n\nsubsection \\<open>Loop freedom of AODV\\<close>\n\ntheorem aodv_loop_freedom:\n  assumes \"wf_net_tree n\"\n  shows \"closed (pnet (\\<lambda>i. paodv i \\<langle>\\<langle> qmsg) n) \\<TTurnstile> netglobal (\\<lambda>\\<sigma>. \\<forall>dip. irrefl ((rt_graph \\<sigma> dip)\\<^sup>+))\"\n  using assms by (rule aodv_openproc_par_qmsg.netglobal_weakenE\n                          [OF net_nhop_quality_increases inv_to_loop_freedom])\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/AODV/variants/b_fwdrreps/B_Aodv_Loop_Freedom.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297746074044134, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.27815444374356685}}
{"text": "section\\<open>Temporal Properties\\<close>\ntext\\<open>This theory presents some examples of temporal properties over the simple drinks machine.\\<close>\n\ntheory Drinks_Machine_LTL\nimports \"Drinks_Machine\" \"Extended_Finite_State_Machines-devel.EFSM_LTL\"\nbegin\n\ndeclare One_nat_def [simp del]\n\nlemma P_ltl_step_0:\n  assumes invalid: \"P (None, [], <>)\"\n  assumes select: \"l = STR ''select'' \\<longrightarrow> P (Some 1, [], <1 $:= Some (hd i), 2 $:= Some (Num 0)>)\"\n  shows \"P (ltl_step drinks (Some 0) <> (l, i))\"\nproof-\n  have length_i: \"\\<exists>d. (l, i) = (STR ''select'', [d]) \\<Longrightarrow> length i = 1\"\n    by (induct i, auto)\n  have length_i_2: \"\\<forall>d. i \\<noteq> [d] \\<Longrightarrow> length i \\<noteq> 1\"\n    by (induct i, auto)\n  show ?thesis\n    apply (case_tac \"\\<exists>d. (l, i) = (STR ''select'', [d])\")\n     apply (simp add: possible_steps_0 length_i select_def apply_updates_def)\n    using select apply auto[1]\n    by (simp add: possible_steps_0_invalid length_i_2 invalid)\nqed\n\nlemma P_ltl_step_1:\n  assumes invalid: \"P (None, [], r)\"\n  assumes coin: \"l = STR ''coin'' \\<longrightarrow> P (Some 1, [value_plus (r $ 2) (Some (hd i))], r(2 $:= value_plus (r $ 2) (Some (i ! 0))))\"\n  assumes vend_fail: \"value_gt (Some (Num 100)) (r $ 2) = trilean.true \\<longrightarrow> P (Some 1, [],r)\"\n  assumes vend: \"\\<not>? value_gt (Some (Num 100)) (r $ 2) = trilean.true \\<longrightarrow> P (Some 2, [r$1], r)\"\n  shows \"P (ltl_step drinks (Some 1) r (l, i))\"\nproof-\n  have length_i: \"\\<And>s. \\<exists>d. (l, i) = (s, [d]) \\<Longrightarrow> length i = 1\"\n    by (induct i, auto)\n  have length_i_2: \"\\<forall>d. i \\<noteq> [d] \\<Longrightarrow> length i \\<noteq> 1\"\n    by (induct i, auto)\n  show ?thesis\n    apply (case_tac \"\\<exists>d. (l, i) = (STR ''coin'', [d])\")\n     apply (simp add: possible_steps_1_coin length_i coin_def apply_outputs_def apply_updates_def)\n    using coin apply auto[1]\n    apply (case_tac \"(l, i) = (STR ''vend'', [])\")\n     apply (case_tac \"\\<exists>n. r $ 2 = Some (Num n)\")\n      apply clarsimp\n    subgoal for n\n      apply (case_tac \"n \\<ge> 100\")\n       apply (simp add: drinks_vend_sufficient vend_def apply_updates_def apply_outputs_def)\n       apply (metis finfun_upd_triv possible_steps_2_vend vend vend_ge_100)\n      apply (simp add: drinks_vend_insufficient vend_fail_def apply_updates_def apply_outputs_def)\n      apply (metis MaybeBoolInt.simps(1) finfun_upd_triv not_less value_gt_def vend_fail)\n      done\n     apply (simp add: drinks_vend_invalid invalid)\n    by (simp add: drinks_no_possible_steps_1 length_i_2 invalid)\nqed\n\nlemma LTL_r2_not_always_gt_100: \"not (alw (check_exp (Gt (V (Rg 2)) (L (Num 100))))) (watch drinks i)\"\n  using value_gt_def by auto\n\nlemma drinks_step_2_none: \"ltl_step drinks (Some 2) r e = (None, [], r)\"\n  by (simp add: drinks_end ltl_step_none_2)\n\nlemma one_before_two_2:\n  \"alw (\\<lambda>x. statename (shd (stl x)) = Some 2 \\<longrightarrow> statename (shd x) = Some 1) (make_full_observation drinks (Some 2) r [r $ 1] x2a)\"\nproof(coinduction)\n  case alw\n  then show ?case\n    apply (simp add: drinks_step_2_none)\n    by (metis (mono_tags, lifting) alw_mono nxt.simps once_none_nxt_always_none option.distinct(1))\nqed\n\nlemma one_before_two_aux:\n  assumes \"\\<exists> p r i. j = nxt (make_full_observation drinks (Some 1) r p) i\"\n  shows \"alw (\\<lambda>x. nxt (state_eq (Some 2)) x \\<longrightarrow> state_eq (Some 1) x) j\"\n  using assms apply(coinduct)\n  apply simp\n  apply clarify\n  apply standard\n   apply simp\n  apply simp\n  subgoal for r i\n    apply (case_tac \"shd (stl i)\")\n    apply (simp del: ltl_step.simps)\n    apply (rule P_ltl_step_1)\n       apply (rule disjI2)\n       apply (rule alw_mono[of \"nxt (state_eq None)\"])\n        apply (simp add: once_none_nxt_always_none)\n       apply simp\n      apply auto[1]\n     apply auto[1]\n    apply simp\n    by (simp add: one_before_two_2)\n  done\n\nlemma LTL_nxt_2_means_vend:\n  \"alw (nxt (state_eq (Some 2)) impl (state_eq (Some 1))) (watch drinks i)\"\nproof(coinduction)\n  case alw\n  then show ?case\n    apply (case_tac \"shd i\")\n    apply (simp del: ltl_step.simps)\n    apply (rule P_ltl_step_0)\n     apply simp\n     apply (rule disjI2)\n     apply (rule alw_mono[of \"nxt (state_eq None)\"])\n      apply (simp add: once_none_nxt_always_none)\n    using one_before_two_aux by auto\nqed\n\nlemma costsMoney_aux:\n  assumes \"\\<exists>p r i. j = (nxt (make_full_observation drinks (Some 1) r p) i)\"\n  shows \"alw (\\<lambda>xs. nxt (state_eq (Some 2)) xs \\<longrightarrow> check_exp (Ge (V (Rg 2)) (L (Num 100))) xs) j\"\n  using assms apply coinduct\n  apply clarsimp\n  subgoal for r i\n    apply (case_tac \"shd (stl i)\")\n    apply (simp del: ltl_step.simps)\n    apply (rule P_ltl_step_1)\n       apply simp\n       apply (rule disjI2)\n       apply (rule alw_mono[of \"nxt (state_eq None)\"])\n        apply (simp add: once_none_nxt_always_none)\n       apply simp\n      apply auto[1]\n     apply auto[1]\n    apply simp\n    apply standard\n    apply (rule disjI2)\n    apply (rule alw_mono[of \"nxt (state_eq None)\"])\n     apply (metis (no_types, lifting) drinks_step_2_none fst_conv make_full_observation.sel(2) nxt.simps nxt_alw once_none_always_none_aux)\n    by simp\n  done\n\n(* costsMoney: THEOREM drinks |- G(X(cfstate=State_2) => gval(value_ge(r_2, Some(NUM(100))))); *)\nlemma LTL_costsMoney:\n  \"(alw (nxt (state_eq (Some 2)) impl (check_exp (Ge (V (Rg 2)) (L (Num 100)))))) (watch drinks i)\"\nproof(coinduction)\n  case alw\n  then show ?case\n    apply (cases \"shd i\")\n    subgoal for l ip\n      apply (case_tac \"l = STR ''select'' \\<and> length ip = 1\")\n       defer\n       apply (simp add: possible_steps_0_invalid)\n       apply (rule disjI2)\n       apply (rule alw_mono[of \"nxt (state_eq None)\"])\n        apply (simp add: once_none_nxt_always_none)\n       apply (simp add: )\n      apply (simp add: possible_steps_0 select_def)\n      apply (rule disjI2)\n      apply (simp only: nxt.simps[symmetric])\n      using costsMoney_aux by auto\n    done\nqed\n\nlemma LTL_costsMoney_aux:\n  \"(alw (not (check_exp (Ge (V (Rg 2)) (L (Num 100)))) impl (not (nxt (state_eq (Some 2)))))) (watch drinks i)\"\n  by (metis (no_types, lifting) LTL_costsMoney alw_mono)\n\nlemma implode_select: \"String.implode ''select'' = STR ''select''\"\n  by (metis Literal.rep_eq String.implode_explode_eq zero_literal.rep_eq)\n\nlemma implode_coin: \"String.implode ''coin'' = STR ''coin''\"\n  by (metis Literal.rep_eq String.implode_explode_eq zero_literal.rep_eq)\n\nlemma implode_vend: \"String.implode ''vend'' = STR ''vend''\"\n  by (metis Literal.rep_eq String.implode_explode_eq zero_literal.rep_eq)\n\nlemmas implode_labels = implode_select implode_coin implode_vend\n\nlemma LTL_neverReachS2:\"(((((action_eq (''select'', [Str ''coke''])))\n                    aand\n                    (nxt ((action_eq (''coin'', [Num 100])))))\n                    aand\n                    (nxt (nxt((label_eq ''vend'' aand (input_eq []))))))\n                    impl\n                    (nxt (nxt (nxt (state_eq (Some 2))))))\n                    (watch drinks i)\"\n  apply (simp add: implode_labels)\n  apply (cases i)\n  apply clarify  \n  apply simp\n  apply (simp add: possible_steps_0 select_def)\n  apply (case_tac \"shd x2\", clarify)\n  apply (simp add: possible_steps_1_coin coin_def value_plus_def finfun_update_twist apply_updates_def)\n  apply (case_tac \"shd (stl x2)\", clarify)\n  by (simp add: drinks_vend_sufficient )\n\nlemma ltl_step_not_select:\n  \"\\<nexists>i. e = (STR ''select'', [i]) \\<Longrightarrow>\n   ltl_step drinks (Some 0) r e = (None, [], r)\"\n  apply (cases e, clarify)\n  subgoal for a b\n    apply (rule ltl_step_none)\n    apply (simp add: possible_steps_empty drinks_def can_take_transition_def can_take_def select_def)\n    by (cases e, case_tac b, auto)\n  done\n\nlemma ltl_step_select:\n  \"ltl_step drinks (Some 0) <> (STR ''select'', [i]) = (Some 1, [], <1 $:= Some i, 2 $:= Some (Num 0)>)\"\n  apply (rule  ltl_step_some[of _ _ _ _ _ _ select])\n    apply (simp add: possible_steps_0)\n   apply (simp add: select_def)\n  by (simp add: select_def finfun_update_twist apply_updates_def)\n\nlemma ltl_step_not_coin_or_vend:\n  \"\\<nexists>i. e = (STR ''coin'', [i]) \\<Longrightarrow>\n    e \\<noteq> (STR ''vend'', []) \\<Longrightarrow>\n    ltl_step drinks (Some 1) r e = (None, [], r)\"\n  apply (cases e)\n  subgoal for a b\n    apply (simp del: ltl_step.simps)\n    apply (rule ltl_step_none)\n    apply (simp add: possible_steps_empty drinks_def can_take_transition_def can_take_def transitions)\n    by (case_tac e, case_tac b, auto)\n  done\n\nlemma ltl_step_coin:\n  \"\\<exists>p r'. ltl_step drinks (Some 1) r (STR ''coin'', [i]) = (Some 1, p, r')\"\n  by (simp add: possible_steps_1_coin)\n\nlemma alw_tl:\n  \"alw \\<phi> (make_full_observation e (Some 0) <> [] xs) \\<Longrightarrow>\n    alw \\<phi>\n     (make_full_observation e (fst (ltl_step e (Some 0) <> (shd xs))) (snd (snd (ltl_step e (Some 0) <> (shd xs))))\n       (fst (snd (ltl_step e (Some 0) <> (shd xs)))) (stl xs))\"\n  by auto\n\nlemma stop_at_none:\n  \"alw (\\<lambda>xs. output (shd (stl xs)) = [Some (EFSM.Str drink)] \\<longrightarrow> check_exp (Ge (V (Rg 2)) (L (Num 100))) xs)\n            (make_full_observation drinks None r p t)\"\n  apply (rule alw_mono[of \"nxt (output_eq [])\"])\n   apply (simp add: no_output_none_nxt)\n  by simp\n\nlemma drink_costs_money_aux:\n  assumes \"\\<exists>p r t. j = make_full_observation drinks (Some 1) r p t\"\n  shows \"alw (\\<lambda>xs. output (shd (stl xs)) = [Some (EFSM.Str drink)] \\<longrightarrow> check_exp (Ge (V (Rg 2)) (L (Num 100))) xs) j\"\n  using assms apply coinduct\n  apply clarsimp\n  apply (case_tac \"shd t\")\n  apply (simp del: ltl_step.simps)\n  apply (rule P_ltl_step_1)\n     apply simp\n     apply (rule disjI2)\n     apply (rule alw_mono[of \"nxt (output_eq [])\"])\n      apply (simp add: no_output_none_nxt)\n     apply simp\n    apply (simp add: Str_def value_plus_never_string)\n    apply auto[1]\n   apply auto[1]\n  apply simp\n  apply standard\n  apply (rule disjI2)\n  apply (rule alw_mono[of \"nxt (output_eq [])\"])\n   apply (simp add: drinks_step_2_none no_output_none_if_empty nxt_alw)\n  by simp\n\nlemma LTL_drinks_cost_money:\n  \"alw (nxt (output_eq [Some (Str drink)]) impl (check_exp (Ge (V (Rg 2)) (L (Num 100))))) (watch drinks t)\"\nproof(coinduction)\n  case alw\n  then show ?case\n    apply (case_tac \"shd t\")\n    apply (simp del: ltl_step.simps)\n    apply (rule P_ltl_step_0)\n     apply simp\n     apply (rule disjI2)\n     apply (rule alw_mono[of \"nxt (output_eq [])\"])\n      apply (simp add: no_output_none_nxt)\n     apply simp\n    apply simp\n    using drink_costs_money_aux\n    apply simp\n    by blast\nqed\n\nlemma steps_1_invalid:\n      \"\\<nexists>i. (a, b) = (STR ''coin'', [i]) \\<Longrightarrow>\n       \\<nexists>i. (a, b) = (STR ''vend'', []) \\<Longrightarrow>\n       possible_steps drinks 1 r a b = {||}\"\n  apply (simp add: possible_steps_empty drinks_def transitions can_take_transition_def can_take_def)\n  by (induct b, auto)\n\nlemma output_vend_aux:\n  assumes \"\\<exists>p r t. j = make_full_observation drinks (Some 1) r p t\"\n  shows \"alw (\\<lambda>xs. label_eq ''vend'' xs \\<and> output (shd (stl xs)) = [Some d] \\<longrightarrow> check_exp (Ge (V (Rg 2)) (L (Num 100))) xs) j\"\n  using assms apply coinduct\n  apply clarsimp\n  subgoal for r t\n    apply (case_tac \"shd t\")\n    apply (simp add: implode_vend del: ltl_step.simps)\n    apply (rule P_ltl_step_1)\n       apply simp\n       apply (rule disjI2)\n       apply (rule alw_mono[of \"nxt (output_eq [])\"])\n        apply (simp add: no_output_none_nxt)\n       apply simp\n      apply auto[1]\n     apply auto[1]\n    apply simp\n    apply standard\n    apply (rule disjI2)\n    apply (rule alw_mono[of \"nxt (output_eq [])\"])\n     apply (simp add: drinks_step_2_none no_output_none_if_empty nxt_alw)\n    by simp\n  done\n\ntext_raw\\<open>\\snip{outputVend}{1}{2}{%\\<close>\nlemma LTL_output_vend:\n  \"alw (((label_eq ''vend'') aand (nxt (output_eq [Some d]))) impl\n         (check_exp (Ge (V (Rg 2)) (L (Num 100))))) (watch drinks t)\"\ntext_raw\\<open>}%endsnip\\<close>\nproof(coinduction)\n  case alw\n  then show ?case\n    apply (simp add: implode_vend)\n    apply (case_tac \"shd t\")\n    apply (simp del: ltl_step.simps)\n    apply (rule P_ltl_step_0)\n     apply simp\n    apply (rule disjI2)\n     apply (rule alw_mono[of \"nxt (output_eq [])\"])\n      apply (simp add: no_output_none_nxt)\n     apply simp\n    apply simp\n    subgoal for a b\n      using output_vend_aux[of \"(make_full_observation drinks (Some 1)\n              <1 $:= Some (hd b), 2 $:= Some (Num 0)> [] (stl t))\" d]\n      using implode_vend by auto\n    done\nqed\n\ntext_raw\\<open>\\snip{outputVendUnfolded}{1}{2}{%\\<close>\nlemma LTL_output_vend_unfolded:\n  \"alw (\\<lambda>xs. (label (shd xs) = STR ''vend'' \\<and>\n             nxt (\\<lambda>s. output (shd s) = [Some d]) xs) \\<longrightarrow>\n              \\<not>? value_gt (Some (Num 100)) (datastate (shd xs) $ 2) = trilean.true)\n     (watch drinks t)\"\ntext_raw\\<open>}%endsnip\\<close>\n  apply (insert LTL_output_vend[of d t])\n  by (simp add: implode_vend)\n\nend\n", "meta": {"author": "logicalhacking", "repo": "Extended_Finite_State_Machines", "sha": "3a7a6daf2cfc4f155a2ce259c255cf8f322f6268", "save_path": "github-repos/isabelle/logicalhacking-Extended_Finite_State_Machines", "path": "github-repos/isabelle/logicalhacking-Extended_Finite_State_Machines/Extended_Finite_State_Machines-3a7a6daf2cfc4f155a2ce259c255cf8f322f6268/Extended_Finite_State_Machines/examples/Drinks_Machine_LTL.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.531209388216861, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.27804580333872064}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory StringOrd\nimports \"~~/src/HOL/Main\"\nbegin\n\ndatatype anotherBL =\n   BLNon\n | BLZer anotherBL\n | BLOne anotherBL\n | BLTwo anotherBL\n | BLThr anotherBL\n\nlemma twice_bound_meta_all:\n  \"(\\<And>a b. x = a \\<and> y = b \\<Longrightarrow> PROP Q a b) \\<equiv> (PROP Q x y)\"\n  apply (rule equal_intr_rule)\n   apply (erule meta_allE, erule meta_allE, erule meta_mp)\n   apply simp\n  apply clarsimp\n  done\n\nfunction(sequential) anotherBL_ord :: \"anotherBL \\<Rightarrow> anotherBL \\<Rightarrow> bool\"\nwhere\n   \"anotherBL_ord BLNon x = True\"\n | \"anotherBL_ord x BLNon = False\"\n | \"anotherBL_ord (BLZer x) (BLZer y) = anotherBL_ord x y\"\n | \"anotherBL_ord (BLZer x) y = True\"\n | \"anotherBL_ord x (BLZer y) = False\"\n | \"anotherBL_ord (BLOne x) (BLOne y) = anotherBL_ord x y\"\n | \"anotherBL_ord (BLOne x) y = True\"\n | \"anotherBL_ord x (BLOne y) = False\"\n | \"anotherBL_ord (BLTwo x) (BLTwo y) = anotherBL_ord x y\"\n | \"anotherBL_ord (BLTwo x) y = True\"\n | \"anotherBL_ord x (BLTwo y) = False\"\n | \"anotherBL_ord (BLThr x) (BLThr y) = anotherBL_ord x y\"\n  apply simp_all\n  apply (case_tac x, simp_all)\n  apply (case_tac a, simp_all)\n     apply (case_tac b, simp_all add: twice_bound_meta_all)[1]\n    apply (case_tac b, simp_all add: twice_bound_meta_all)[1]\n   apply (case_tac b, simp_all add: twice_bound_meta_all)[1]\n  apply (case_tac b, simp_all add: twice_bound_meta_all)[1]\n  done\n\ntermination anotherBL_ord\n  apply (rule anotherBL_ord.termination)\n      apply (rule wf_measure[where f=\"size_prod size size\"])\n     apply simp+\n  done\n\ninstantiation\n  anotherBL :: ord\nbegin\n  definition le_anotherBL: \"a \\<le> b \\<equiv> anotherBL_ord a b\"\n  definition less_anotherBL: \"a < b \\<equiv> (anotherBL_ord a b \\<and> a \\<noteq> b)\"\n\n  instance ..\nend\n\nlemma anotherBL_to_less_simps:\n  \"(anotherBL_ord a b = v) \\<Longrightarrow> (a < b = (v \\<and> a \\<noteq> b))\"\n  by (simp add: less_anotherBL)\n\nlemmas anotherBL_ords[simp] =\n  anotherBL_ord.simps[folded le_anotherBL, simplified]\n  anotherBL_ord.simps [THEN anotherBL_to_less_simps,\n                       simplified, folded less_anotherBL]\n\nlemma anotherBL_trans:\n  \"\\<lbrakk> x \\<le> (y :: anotherBL); y \\<le> z \\<rbrakk> \\<Longrightarrow> x \\<le> z\"\n  apply (rule ccontr)\n  apply (erule rev_mp)+\n  apply (induct y arbitrary: x z)\n      apply (case_tac x, simp_all)[1]\n     apply (case_tac x, simp_all(no_asm_simp))[1]\n     apply (case_tac z, simp_all)[1]\n    apply (case_tac x, simp_all(no_asm_simp))[1]\n     apply (case_tac z, simp_all)[1]\n    apply (case_tac z, simp_all)[1]\n   apply (case_tac z, simp_all(no_asm_simp))[1]\n    apply (case_tac x, simp_all)[1]\n   apply (case_tac x, simp_all)[1]\n  apply (case_tac z, simp_all(no_asm_simp))[1]\n  apply (case_tac x, simp_all)[1]\n  done\n\nlemma anotherBL_antisym:\n  \"\\<lbrakk> x \\<le> y; (y :: anotherBL) \\<le> x \\<rbrakk> \\<Longrightarrow> x = y\"\n  apply (erule rev_mp)+\n  apply (induct x arbitrary: y)\n      apply (case_tac y, simp_all)[1]\n     apply (case_tac y, simp_all)[1]\n    apply (case_tac y, simp_all)[1]\n   apply (case_tac y, simp_all)[1]\n  apply (case_tac y, simp_all)[1]\n  done\n\nlemma anotherBL_total_ord:\n  \"x \\<le> y \\<or> y \\<le> (x :: anotherBL)\"\n  apply (induct x arbitrary: y)\n      apply simp\n     apply (case_tac y, simp_all)[1]\n    apply (case_tac y, simp_all)[1]\n   apply (case_tac y, simp_all)[1]\n  apply (case_tac y, simp_all)[1]\n  done\n\nlemma less_eq_conj_anotherBL:\n  \"x < (y :: anotherBL) = (x \\<le> y \\<and> x \\<noteq> y)\"\n  by (simp add: less_anotherBL le_anotherBL)\n\ninstantiation anotherBL :: linorder\nbegin\n\ninstance\n  apply intro_classes\n      apply (simp add: less_eq_conj_anotherBL)\n      apply safe[1]\n      apply (drule(1) anotherBL_antisym)\n      apply simp\n     apply (induct_tac x, simp_all)[1]\n    apply (erule(1) anotherBL_trans)\n   apply (erule(1) anotherBL_antisym)\n  apply (rule anotherBL_total_ord)\n  done\n\nend\n\nprimrec\n  nibble_to_anbl :: \"nibble \\<Rightarrow> anotherBL \\<Rightarrow> anotherBL\"\nwhere\n  \"nibble_to_anbl Nibble0 anbl = BLZer (BLZer anbl)\"\n| \"nibble_to_anbl Nibble1 anbl = BLZer (BLOne anbl)\"\n| \"nibble_to_anbl Nibble2 anbl = BLZer (BLTwo anbl)\"\n| \"nibble_to_anbl Nibble3 anbl = BLZer (BLThr anbl)\"\n| \"nibble_to_anbl Nibble4 anbl = BLOne (BLZer anbl)\"\n| \"nibble_to_anbl Nibble5 anbl = BLOne (BLOne anbl)\"\n| \"nibble_to_anbl Nibble6 anbl = BLOne (BLTwo anbl)\"\n| \"nibble_to_anbl Nibble7 anbl = BLOne (BLThr anbl)\"\n| \"nibble_to_anbl Nibble8 anbl = BLTwo (BLZer anbl)\"\n| \"nibble_to_anbl Nibble9 anbl = BLTwo (BLOne anbl)\"\n| \"nibble_to_anbl NibbleA anbl = BLTwo (BLTwo anbl)\"\n| \"nibble_to_anbl NibbleB anbl = BLTwo (BLThr anbl)\"\n| \"nibble_to_anbl NibbleC anbl = BLThr (BLZer anbl)\"\n| \"nibble_to_anbl NibbleD anbl = BLThr (BLOne anbl)\"\n| \"nibble_to_anbl NibbleE anbl = BLThr (BLTwo anbl)\"\n| \"nibble_to_anbl NibbleF anbl = BLThr (BLThr anbl)\"\n\nprimrec\n  char_to_anbl :: \"char \\<Rightarrow> anotherBL \\<Rightarrow> anotherBL\"\nwhere\n \"char_to_anbl (Char nib nob) anbl = nibble_to_anbl nib (nibble_to_anbl nob anbl)\"\n\nprimrec\n  string_to_anbl :: \"string \\<Rightarrow> anotherBL\"\nwhere\n  \"string_to_anbl []          = BLNon\"\n| \"string_to_anbl (chr # str) = char_to_anbl chr (string_to_anbl str)\"\n\nlemmas string_ord_simps\n  = string_to_anbl.simps char_to_anbl.simps nibble_to_anbl.simps\n    anotherBL_ords anotherBL.simps\n\nend\n", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/lib/StringOrd.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5312093733737562, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.2780457955695375}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory MultByAdd\nimports\n  \"AutoCorres.AutoCorres\"\nbegin\n\n(* Parse the input file. *)\nexternal_file \"mult_by_add.c\"\ninstall_C_file \"mult_by_add.c\"\n\n(* Abstract the input file. *)\nautocorres [ ts_force nondet = mult_by_add ] \"mult_by_add.c\"\n\ncontext mult_by_add begin\n\n(*\n * Prove the function returns the correct result, and (simultaneously)\n * does not fail and terminates.\n *)\nlemma \"\\<lbrace> \\<lambda>s. True \\<rbrace> mult_by_add' a b \\<lbrace> \\<lambda>r s. r = a * b \\<rbrace>!\"\n  (* Unfold function definition. *)\n  apply (clarsimp simp: mult_by_add'_def)\n\n  (* Annotate while loop with an invariant and measure. *)\n  apply (subst whileLoop_add_inv\n    [where I=\"\\<lambda>(a', r) s. (a' * b) + r = (a * b)\"\n       and M=\"\\<lambda>((a', _), s). unat a'\"])\n\n  (* Run \"wp\" weakest precondition tactic, and solve verification *\n   * conditions generated by it. *)\n  apply wp\n     apply (simp add: field_simps)\n    apply unat_arith\n   apply (simp add: split_def word_neq_0_conv[symmetric])\n  apply (simp add: split_def | wp)+\n  done\n\n(*\n * Equivalent partial-correctness proof using Simpl framework.\n *)\nlemma \"\\<Gamma> \\<turnstile> {s. s = t} \\<acute>ret__unsigned :== CALL mult_by_add(\\<acute>a, \\<acute>b) \\<lbrace> (\\<acute>ret__unsigned = \\<^bsup>t\\<^esup>a * \\<^bsup>t\\<^esup>b) \\<rbrace>\"\n  (* Unfold the body. *)\n  apply vcg_step\n   defer\n\n   (* Annotate the while loop with an invariant and variant. *)\n   apply (subst whileAnno_def)\n   apply (subst whileAnno_def [symmetric,\n     where I=\" \\<lbrace> (\\<acute>a * \\<acute>b + \\<acute>result) = (\\<^bsup>t\\<^esup>a * \\<^bsup>t\\<^esup>b) \\<rbrace>\"\n     and V=\"measure (\\<lambda>s. unat (a_' s))\"])\n\n  (* Solve the remaining conditions. *)\n   apply vcg\n   apply (fastforce intro: unat_mono simp: gt0_iff_gem1 field_simps less_1_simp scast_id)+\n  done\n\nend\n\nend\n", "meta": {"author": "amblafont", "repo": "AutoCorres", "sha": "a8e96bff9fb22d633ff473401947ca84235d3b73", "save_path": "github-repos/isabelle/amblafont-AutoCorres", "path": "github-repos/isabelle/amblafont-AutoCorres/AutoCorres-a8e96bff9fb22d633ff473401947ca84235d3b73/autocorres/tests/examples/MultByAdd.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5234203340678567, "lm_q2_score": 0.5312093733737562, "lm_q1q2_score": 0.2780457876712683}}
{"text": "(*******************************************************************************\n\n  Project: Refining Authenticated Key Agreement with Strong Adversaries\n\n  Module:  Implem_lemmas.thy (Isabelle/HOL 2016-1)\n  ID:      $Id: Implem_lemmas.thy 132885 2016-12-23 18:41:32Z csprenge $\n  Author:  Joseph Lallemand, INRIA Nancy <joseph.lallemand@loria.fr>\n           Christoph Sprenger, ETH Zurich <sprenger@inf.ethz.ch>\n  \n  Auxiliary notions and lemmas for channel implementations.\n  - message abstraction = inverse of (valid) impl, lifted to sets\n  - extractable messages (those of non-confidential and \"broken\" channels)\n  - lemmas for proving L2-L3 intruder refinement\n\n  Copyright (c) 2015-2016 Joseph Lallemand and Christoph Sprenger\n  Licence: LGPL\n\n*******************************************************************************)\n\nsection \\<open>Lemmas Following from Channel Message Implementation Assumptions\\<close>\n\ntheory Implem_lemmas\nimports Implem\nbegin\n\ntext \\<open>These lemmas require the assumptions added in the @{locale \"valid_implem\"} locale.\\<close>\n\ncontext semivalid_implem\nbegin\n(**************************************************************************************************)\nsubsection \\<open>Message implementations and abstractions\\<close>\n(**************************************************************************************************)\n\ntext \\<open>Abstracting a set of messages into channel messages.\\<close>\n\ndefinition\n  abs :: \"msg set \\<Rightarrow> chan set\"\nwhere\n  \"abs S \\<equiv> {Chan x A B M | x A B M. M \\<in> payload \\<and> implem (Chan x A B M) \\<in> S}\"\n\nlemma absE [elim]: \n  \"\\<lbrakk> X \\<in> abs H;\n     \\<And> x A B M. X = Chan x A B M \\<Longrightarrow> M \\<in> payload \\<Longrightarrow> implem X \\<in> H \\<Longrightarrow> P \\<rbrakk>\n  \\<Longrightarrow> P\"\nby (auto simp add: abs_def)\n\nlemma absI [intro]: \"M \\<in> payload \\<Longrightarrow> implem (Chan x A B M) \\<in> H \\<Longrightarrow> Chan x A B M \\<in> abs H\"\nby (auto simp add: abs_def)\n\nlemma abs_mono: \"G \\<subseteq> H \\<Longrightarrow> abs G \\<subseteq> abs H\"\nby (auto simp add: abs_def)\n\nlemmas abs_monotone [simp] = abs_mono [THEN [2] rev_subsetD]\n\nlemma abs_empty [simp]: \"abs {} = {}\"\nby (auto simp add: abs_def)\n\nlemma abs_Un_eq: \"abs (G \\<union> H) = abs G \\<union> abs H\"\nby (auto simp add: abs_def)\n\ntext \\<open>General lemmas about implementations and @{term abs}.\\<close>\nlemma abs_insert_payload [simp]: \"M \\<in> payload \\<Longrightarrow> abs (insert M S) = abs S\"\nby (auto simp add: abs_def)\n\nlemma abs_insert_impl [simp]:\n  \"M \\<in> payload \\<Longrightarrow> abs (insert (implem (Chan x A B M)) S) = insert (Chan x A B M) (abs S)\"\nby (auto simp add: abs_def)\n\nlemma extr_payload [simp, intro]:\n  \"\\<lbrakk> X \\<in> extr Bad NI (abs I); NI \\<subseteq> payload \\<rbrakk> \\<Longrightarrow> X \\<in> payload\"\nby (erule extr.induct, blast, auto)\n\nlemma abs_Un_LtK:\n  \"K \\<subseteq> range LtK \\<Longrightarrow> abs (K \\<union> S) = abs S\"\nby (auto simp add: abs_Un_eq)\n\nlemma abs_Un_keys_of [simp]:\n  \"abs (keys_of A \\<union> S) = abs S\"\nby (auto intro!: abs_Un_LtK)\n\n\ntext \\<open>Lemmas about @{term valid} and @{term abs}\\<close>\n\nlemma abs_validSet: \"abs (S \\<inter> valid) = abs S\"\nby (auto elim: absE intro: validI)\n\nlemma valid_abs: \"M \\<in> valid \\<Longrightarrow> \\<exists> M'. M' \\<in> abs {M}\"\nby (auto elim: validE)\n\n\n(**************************************************************************************************)\nsubsection \\<open>Extractable messages\\<close>\n(**************************************************************************************************)\n\ntext \\<open>\\<open>extractable K I\\<close>: subset of messages in $I$ which are implementations \n(not necessarily valid since we do not require that they are payload) and can be extracted \nusing the keys in K. It corresponds to L2 @{term extr}.\\<close>\n\ndefinition\n  extractable :: \"msg set \\<Rightarrow> msg set \\<Rightarrow> msg set\"\nwhere\n  \"extractable K I \\<equiv>\n    {implInsec A B M | A B M. implInsec A B M \\<in> I} \\<union>\n    {implAuth A B M | A B M. implAuth A B M \\<in> I} \\<union>\n    {implConfid A B M | A B M. implConfid A B M \\<in> I \\<and> (A, B) \\<in> broken K} \\<union>\n    {implSecure A B M | A B M. implSecure A B M \\<in> I \\<and> (A, B) \\<in> broken K}\"\n\nlemma extractable_red: \"extractable K I \\<subseteq> I\"\nby (auto simp add: extractable_def)\n\n\n\nlemma extractableE:\n  \"X \\<in> extractable K I \\<Longrightarrow>\n   (\\<And>A B M. X = implInsec A B M \\<Longrightarrow> X \\<in> I \\<Longrightarrow> P) \\<Longrightarrow>\n   (\\<And>A B M. X = implAuth A B M \\<Longrightarrow> X \\<in> I \\<Longrightarrow> P) \\<Longrightarrow>\n   (\\<And>A B M. X = implConfid A B M \\<Longrightarrow> X \\<in> I \\<Longrightarrow> (A, B) \\<in> broken K \\<Longrightarrow> P) \\<Longrightarrow>\n   (\\<And>A B M. X = implSecure A B M \\<Longrightarrow> X \\<in> I \\<Longrightarrow> (A, B) \\<in> broken K \\<Longrightarrow> P) \\<Longrightarrow>\n  P\"\nby (auto simp add: extractable_def brokenI)\n\ntext \\<open>General lemmas about implementations and extractable.\\<close>\nlemma implem_extractable [simp]:\n  \"\\<lbrakk> Keys_bad K Bad; implem (Chan x A B M) \\<in> extractable K I; M \\<in> payload \\<rbrakk> \n \\<Longrightarrow> M \\<in> extr Bad NI (abs I)\"\nby (erule extractableE, auto)\n\n\ntext \\<open>Auxiliary lemmas about extractable messages: they are implementations.\\<close>\nlemma valid_extractable [simp]: \"I \\<subseteq> valid \\<Longrightarrow> extractable K I \\<subseteq> valid\"\nby (auto intro: subset_trans extractable_red del: subsetI)\n\nlemma LtKeys_parts_extractable:\n  \"I \\<subseteq> valid \\<Longrightarrow> parts (extractable K I) \\<inter> range LtK = {}\"\nby (auto dest: valid_extractable intro!: parts_valid_LtKeys_disjoint)\n\nlemma LtKeys_parts_extractable_elt [simp]:  \n  \"I \\<subseteq> valid \\<Longrightarrow> LtK ltk \\<notin> parts (extractable K I)\"\nby (blast dest: LtKeys_parts_extractable)\n\n\nlemma LtKeys_parts_implSecureSet:   (* FIX: possibly problematic: not in normal form *)\n  \"parts (implSecureSet Ag payload) \\<inter> range LtK = {}\"\nby (auto intro!: parts_valid_LtKeys_disjoint intro: validI)\n\nlemma LtKeys_parts_implSecureSet_elt: \n  \"LtK K \\<notin> parts (implSecureSet Ag payload)\"\nusing LtKeys_parts_implSecureSet\nby auto\n\nlemmas LtKeys_parts = LtKeys_parts_payload parts_valid_LtKeys_disjoint\n                      LtKeys_parts_extractable LtKeys_parts_implSecureSet \n                      LtKeys_parts_implSecureSet_elt\n\n\nsubsubsection\\<open>Partition $I$ to keep only the extractable messages\\<close>\n(**************************************************************************************************)\n\ntext \\<open>Partition the implementation set.\\<close>\n\nlemma impl_partition:\n  \"\\<lbrakk> NI \\<subseteq> payload; I \\<subseteq> valid \\<rbrakk> \\<Longrightarrow>\n  I \\<subseteq> extractable K I \\<union>\n      implConfidSet (UNIV - broken K) payload \\<union>\n      implSecureSet (UNIV - broken K) payload\"\nby (auto dest!: subsetD [where A=I] elim!: valid_cases intro:  extractableI)\n\n\nsubsubsection \\<open>Partition of @{term \"extractable\"}\\<close>\n(**************************************************************************************************)\n\ntext \\<open>We partition the @{term \"extractable\"} set into insecure, confidential, authentic \nimplementations.\\<close>\n\nlemma extractable_partition:\n  \"\\<lbrakk>Keys_bad K Bad; NI \\<subseteq> payload; I \\<subseteq> valid\\<rbrakk> \\<Longrightarrow>\n  extractable K I \\<subseteq> \n  implInsecSet (extr Bad NI (abs I)) \\<union>\n  implConfidSet UNIV (extr Bad NI (abs I)) \\<union>\n  implAuthSet (extr Bad NI (abs I)) \\<union>\n  implSecureSet UNIV (extr Bad NI (abs I))\"\napply (rule, frule valid_extractable, drule subsetD [where A=\"extractable K I\"], fast)\napply (erule valid_cases, auto)\ndone\n\n\n(**************************************************************************************************)\nsubsection \\<open>Lemmas for proving intruder refinement (L2-L3)\\<close>\n(**************************************************************************************************)\n\ntext \\<open>Chain of lemmas used to prove the refinement for \\<open>l3_dy\\<close>. \nThe ultimate goal is to show @{prop [display] \n  \"synth (analz (NI \\<union> I \\<union> K \\<union> Tags)) \\<subseteq> synth (analz (extr Bad NI (abs I))) \\<union> -payload\"\n}\\<close>\n\nsubsubsection \\<open>First: we only keep the extractable messages\\<close>\n\n\\<comment> \\<open>the \\<open>synth\\<close> is probably not needed\\<close>\nlemma analz_NI_I_K_analz_NI_EI:\nassumes HNI: \"NI \\<subseteq> payload\"\n    and HK: \"K \\<subseteq> range LtK\"\n    and HI: \"I \\<subseteq> valid\"\nshows \"analz (NI \\<union> I \\<union> K \\<union> Tags) \\<subseteq>\n       synth (analz (NI \\<union> extractable K I \\<union> K \\<union> Tags)) \\<union> -payload\"\nproof -\n  from HNI HI\n  have \"analz (NI \\<union> I \\<union> K \\<union> Tags) \\<subseteq> \n        analz (NI \\<union> (extractable K I \\<union>\n                     implConfidSet (UNIV - broken K) payload \\<union>\n                     implSecureSet (UNIV - broken K) payload)\n                \\<union> K \\<union> Tags)\"\n    by (intro analz_mono Un_mono impl_partition, simp_all)\n  also have \"... \\<subseteq> analz (implConfidSet (UNIV - broken K) payload \\<union>\n                    (implSecureSet (UNIV - broken K) payload \\<union>\n                    (extractable K I \\<union> NI \\<union> K \\<union> Tags)))\"\n    by (auto)\n  also have \"... \\<subseteq> synth (analz (implSecureSet (UNIV - broken K) payload \\<union>\n                  (extractable K I \\<union> NI \\<union> K \\<union> Tags))) \\<union> -payload\"\n    proof (rule analz_Un_implConfidSet_2)\n      show \"Enc_keys_clean (implSecureSet (UNIV - broken K) payload \n                              \\<union> (extractable K I \\<union> NI \\<union> K \\<union> Tags))\"\n        by (auto simp add: HNI HI HK intro: validI)\n    next\n      from HK HI HNI \n      show \"(UNIV - broken K) \\<inter> \n            broken (parts (\n              implSecureSet (UNIV - broken K) payload \\<union>\n              (extractable K I \\<union> NI \\<union> K \\<union> Tags)) \\<inter> range LtK)  = {}\"\n        by (auto simp add: LtKeys_parts \n               LtKeys_parts_implSecureSet_elt [where Ag=\"- broken K\", simplified])\n    qed (auto)\n  also have \"... \\<subseteq> synth (analz (extractable K I \\<union> NI \\<union> K \\<union> Tags)) \\<union> -payload\"\n    proof (rule Un_least, rule synth_idem_payload)\n      show \"analz (implSecureSet (UNIV - broken K) payload \\<union> \n                   (extractable K I \\<union> NI \\<union> K \\<union> Tags))\n            \\<subseteq> synth (analz (extractable K I \\<union> NI \\<union> K \\<union> Tags)) \\<union> -payload\"\n        proof (rule analz_Un_implSecureSet_2)\n          show \"Enc_keys_clean (extractable K I \\<union> NI \\<union> K \\<union> Tags)\"\n            using HNI HK HI by auto\n        next  \n          from HI HK HNI \n          show \"(UNIV - broken K) \\<inter> \n                broken (parts (extractable K I \\<union> NI \\<union> K \\<union> Tags) \\<inter> range LtK) = {}\"\n          by (auto simp add: LtKeys_parts)\n        qed (auto)\n    next\n      show \"-payload \\<subseteq> synth (analz (extractable K I \\<union> NI \\<union> K \\<union> Tags)) \\<union> -payload\"\n        by auto\n    qed\n  also have \"... \\<subseteq> synth (analz (NI \\<union> extractable K I \\<union> K \\<union> Tags)) \\<union> -payload\"\n    by (simp add: sup.left_commute sup_commute)\n  finally show ?thesis .\nqed\n\n\nsubsubsection \\<open>Only keep the extracted messages (instead of extractable)\\<close>\n(**************************************************************************************************)\n\nlemma analz_NI_EI_K_synth_analz_NI_E_K:\nassumes HNI: \"NI \\<subseteq> payload\"\n    and HK: \"K \\<subseteq> range LtK\"\n    and HI: \"I \\<subseteq> valid\"\n    and Hbad: \"Keys_bad K Bad\"\nshows \"analz (NI \\<union> extractable K I \\<union> K \\<union> Tags)\n    \\<subseteq> synth (analz (extr Bad NI (abs I) \\<union> K \\<union> Tags)) \\<union> -payload\"\nproof -\n  from HNI HI Hbad\n  have \"analz (NI \\<union> extractable K I \\<union> K \\<union> Tags) \\<subseteq> \n        analz (NI \\<union> (implInsecSet (extr Bad NI (abs I)) \\<union>\n                     implConfidSet UNIV (extr Bad NI (abs I)) \\<union>\n                     implAuthSet (extr Bad NI (abs I)) \\<union>\n                     implSecureSet UNIV (extr Bad NI (abs I))) \\<union>\n                    K \\<union> Tags)\"\n    by (intro analz_mono Un_mono extractable_partition) (auto)\n\n  also have \"... \\<subseteq> analz (implInsecSet (extr Bad NI (abs I)) \\<union>\n                     (implConfidSet UNIV (extr Bad NI (abs I)) \\<union>\n                     (implAuthSet (extr Bad NI (abs I)) \\<union>\n                     (implSecureSet UNIV (extr Bad NI (abs I)) \\<union>\n                     (NI \\<union> K \\<union> Tags)))))\"\n    by (auto)\n  also have \"... \\<subseteq> synth (analz (extr Bad NI (abs I) \\<union>\n                   (implConfidSet UNIV (extr Bad NI (abs I)) \\<union>\n                   (implAuthSet (extr Bad NI (abs I)) \\<union>\n                   (implSecureSet UNIV (extr Bad NI (abs I)) \\<union> (NI \\<union> K \\<union> Tags)))))) \n                 \\<union> -payload\"\n    by (rule analz_Un_implInsecSet)\n       (auto simp only: Un_commute [of \"extr _ _ _\" _] Un_assoc Un_absorb, \n        auto simp add: HNI HK HI intro!: validI)\n  also have \"... \\<subseteq> synth (analz (extr Bad NI (abs I) \\<union>\n                   (implAuthSet (extr Bad NI (abs I)) \\<union>\n                   (implSecureSet UNIV (extr Bad NI (abs I)) \\<union> (NI \\<union> K \\<union> Tags))))) \n                 \\<union> -payload\"\n    proof (rule Un_least, rule synth_idem_payload)\n      have \"analz (implConfidSet UNIV (extr Bad NI (abs I)) \\<union>\n                   (implAuthSet (extr Bad NI (abs I)) \\<union>\n                   (implSecureSet UNIV (extr Bad NI (abs I)) \\<union> \n                   (NI \\<union> (K \\<union> extr Bad NI (abs I) \\<union> Tags)))))\n            \\<subseteq> synth (analz (extr Bad NI (abs I) \\<union>\n                           (implAuthSet (extr Bad NI (abs I)) \\<union>\n                           (implSecureSet UNIV (extr Bad NI (abs I)) \\<union> \n                           (NI \\<union> (K \\<union> extr Bad NI (abs I) \\<union> Tags)))))) \n              \\<union> -payload\"\n        by (rule analz_Un_implConfidSet)\n           (auto simp only: Un_commute [of \"extr _ _ _\" _] Un_assoc Un_absorb,\n            auto simp add: HK HI HNI  intro!: validI)\n      then show \"analz (extr Bad NI (abs I) \\<union>\n                        (implConfidSet UNIV (extr Bad NI (abs I)) \\<union>\n                        (implAuthSet (extr Bad NI (abs I)) \\<union>\n                        (implSecureSet UNIV (extr Bad NI (abs I)) \\<union> (NI \\<union> K \\<union> Tags)))))\n                 \\<subseteq> synth (analz (extr Bad NI (abs I) \\<union>\n                         (implAuthSet (extr Bad NI (abs I)) \\<union>\n                         (implSecureSet UNIV (extr Bad NI (abs I)) \\<union> \n                         (NI \\<union> K \\<union> Tags))))) \n                   \\<union> -payload\"\n        by (simp add: inf_sup_aci(6) inf_sup_aci(7))\n    next\n      show \"-payload\n            \\<subseteq> synth (analz (extr Bad NI (abs I) \\<union>\n                           (implAuthSet (extr Bad NI (abs I)) \\<union>\n                           (implSecureSet UNIV (extr Bad NI (abs I)) \\<union> (NI \\<union> K \\<union> Tags))))) \n              \\<union> -payload\"\n        by blast\n    qed\n  also have \"... \\<subseteq> synth (analz (extr Bad NI (abs I) \\<union>\n                   (implSecureSet UNIV (extr Bad NI (abs I)) \\<union> (NI \\<union> K \\<union> Tags)))) \n                 \\<union> -payload\"\n    proof (rule Un_least, rule synth_idem_payload)\n      have \"analz (implAuthSet (extr Bad NI (abs I)) \\<union>\n                   (implSecureSet UNIV (extr Bad NI (abs I)) \\<union> \n                   (NI \\<union> (K \\<union> (extr Bad NI (abs I) \\<union> Tags)))))\n            \\<subseteq> synth (analz (extr Bad NI (abs I) \\<union>\n                           (implSecureSet UNIV (extr Bad NI (abs I)) \\<union> \n                           (NI \\<union> (K \\<union> (extr Bad NI (abs I) \\<union> Tags)))))) \n              \\<union> -payload\"\n        by (rule analz_Un_implAuthSet)\n           (auto simp only: Un_commute [of \"extr _ _ _\" _] Un_assoc Un_absorb,\n            auto simp add: HI HNI HK intro!: validI)\n      then show \"analz (extr Bad NI (abs I) \\<union>\n                        (implAuthSet (extr Bad NI (abs I)) \\<union>\n                        (implSecureSet UNIV (extr Bad NI (abs I)) \\<union> (NI \\<union> K \\<union> Tags))))\n                 \\<subseteq> synth (analz (extr Bad NI (abs I) \\<union>\n                         (implSecureSet UNIV (extr Bad NI (abs I)) \\<union> \n                         (NI \\<union> K \\<union> Tags)))) \n                   \\<union> -payload\"\n        by (simp add: inf_sup_aci(6) inf_sup_aci(7))\n    next\n      show \"-payload\n            \\<subseteq> synth (analz (extr Bad NI (abs I) \\<union>\n                           (implSecureSet UNIV (extr Bad NI (abs I)) \n                            \\<union> (NI \\<union> K \\<union> Tags))))  \n              \\<union> -payload\"\n        by blast\n    qed\n  also have \"... \\<subseteq> synth (analz (extr Bad NI (abs I) \\<union> (NI \\<union> K \\<union> Tags))) \n                 \\<union> -payload\"\n    proof (rule Un_least, rule synth_idem_payload)\n      have \"analz (implSecureSet UNIV (extr Bad NI (abs I)) \\<union> \n                   (NI \\<union> (K \\<union> (extr Bad NI (abs I) \\<union> Tags))))\n            \\<subseteq> synth (analz (extr Bad NI (abs I) \\<union>\n                           (NI \\<union> (K \\<union> (extr Bad NI (abs I) \\<union> Tags))))) \n               \\<union> -payload\"\n        by (rule analz_Un_implSecureSet)\n           (auto simp only: Un_commute [of \"extr _ _ _\" _] Un_assoc Un_absorb,\n            auto simp add: HI HNI HK intro!: validI)\n      then show \"analz (extr Bad NI (abs I) \\<union>\n                        (implSecureSet UNIV (extr Bad NI (abs I)) \\<union> (NI \\<union> K \\<union> Tags)))\n                 \\<subseteq> synth (analz (extr Bad NI (abs I) \\<union> (NI \\<union> K \\<union> Tags))) \n                   \\<union> -payload\"\n        by (simp add: inf_sup_aci(6) inf_sup_aci(7))\n    next\n      show \"-payload\n            \\<subseteq> synth (analz (extr Bad NI (abs I)\\<union> (NI \\<union> K \\<union> Tags))) \n              \\<union> -payload\"\n        by blast\n    qed\n  also have \"... \\<subseteq> synth (analz (extr Bad NI (abs I) \\<union> K \\<union> Tags)) \\<union> -payload\"\n    by (metis IK_subset_extr inf_sup_aci(6) set_eq_subset sup.absorb1)\n  finally show ?thesis .\nqed\n\n\nsubsubsection \\<open>Keys and Tags can be moved out of the @{term \"analz\"}\\<close>\n\nlemma analz_LtKeys_Tag:\nassumes \"NI \\<subseteq> payload\" and \"K \\<subseteq> range LtK\"\nshows \"analz (NI \\<union> K \\<union> Tags) \\<subseteq> analz NI \\<union> K \\<union> Tags\"\nproof \n  fix X\n  assume H: \"X \\<in> analz (NI \\<union> K \\<union> Tags) \"\n  thus \"X \\<in> analz NI \\<union> K \\<union> Tags\" \n  proof (induction X rule: analz.induct)\n    case (Dec X Y) \n    hence \"Enc X Y \\<in> payload\" using assms by auto\n    moreover\n    from Dec.IH(2) have \"Y \\<in> synth (analz NI \\<union> (K \\<union> Tags))\"\n      by (auto simp add: Collect_disj_eq dest!: synth_Int2 )\n    ultimately show ?case using Dec.IH(1) assms(2) \n      by (auto dest!: synth_payload [THEN [2] rev_subsetD])\n  next\n    case (Adec_lt X Y)\n    hence \"Aenc X (pubK Y) \\<in> payload \\<union> range LtK \\<union> Tags\" using assms\n      by auto\n    then show ?case by auto\n  next\n    case (Sign_getmsg X Y)\n    hence \"Sign X (priK Y) \\<in> payload \\<union> range LtK \\<union> Tags\" using assms by auto\n    then show ?case by auto\n  next\n    case (Adec_eph X Y)\n    then show ?case using assms by (auto dest!: EpriK_synth)\n  qed (insert assms, auto)\nqed\n\nlemma analz_NI_E_K_analz_NI_E:\n  \"\\<lbrakk> NI \\<subseteq> payload; K \\<subseteq> range LtK; I \\<subseteq> valid \\<rbrakk> \n \\<Longrightarrow> analz (extr Bad NI (abs I) \\<union> K \\<union> Tags) \\<subseteq> analz (extr Bad NI (abs I)) \\<union> K \\<union> Tags\"\nby (rule analz_LtKeys_Tag) auto\n\n\nsubsubsection \\<open>Final lemmas, using all the previous ones\\<close>\n(**************************************************************************************************)\n\nlemma analz_NI_I_K_synth_analz_NI_E:\nassumes\n  Hbad: \"Keys_bad K Bad\" and \n  HNI: \"NI \\<subseteq> payload\" and \n  HK:  \"K \\<subseteq> range LtK\" and \n  HI: \"I \\<subseteq> valid\"\nshows \n  \"analz (NI \\<union> I \\<union> K \\<union> Tags) \\<subseteq> synth (analz (extr Bad NI (abs I))) \\<union> -payload\"\nproof -\n  from HNI HK HI have \"analz (NI \\<union> I \\<union> K \\<union> Tags) \\<subseteq>\n        synth (analz (NI \\<union> extractable K I \\<union> K \\<union> Tags)) \\<union> -payload\"\n    by (rule analz_NI_I_K_analz_NI_EI)\n  also have \"... \\<subseteq> synth (analz (extr Bad NI (abs I) \\<union> K \\<union> Tags)) \\<union> -payload\"\n    proof (rule Un_least, simp_all)\n      from Hbad HNI HK HI have \"analz (NI \\<union> extractable K I \\<union> K \\<union> Tags) \\<subseteq>\n            synth (analz (extr Bad NI (abs I) \\<union> K \\<union> Tags)) \\<union> -payload\"\n        by (intro analz_NI_EI_K_synth_analz_NI_E_K)\n      then show \"synth (analz (NI \\<union> extractable K I \\<union> K \\<union> Tags)) \\<subseteq>\n                 synth (analz (extr Bad NI (abs I) \\<union> K \\<union> Tags)) \\<union> -payload\"\n        by (rule synth_idem_payload)\n    qed\n  also have \"... \\<subseteq> synth (analz (extr Bad NI (abs I))) \\<union> -payload\"\n    proof (rule Un_least, simp_all)\n      from HNI HK HI have \"analz (extr Bad NI (abs I) \\<union> K \\<union> Tags) \\<subseteq>\n                           analz (extr Bad NI (abs I)) \\<union> K \\<union> Tags\"\n        by (rule analz_NI_E_K_analz_NI_E)\n      also from HK have \"... \\<subseteq> analz (extr Bad NI (abs I)) \\<union> -payload\"\n        by auto\n      also have \"... \\<subseteq> synth (analz (extr Bad NI (abs I))) \\<union> -payload\"\n        by auto\n      finally show \"synth (analz (extr Bad NI (abs I) \\<union> K \\<union> Tags)) \\<subseteq>\n                  synth (analz (extr Bad NI (abs I))) \\<union> -payload\"\n        by (rule synth_idem_payload)\n    qed\n  finally show ?thesis .\nqed\n\n\ntext \\<open>Lemma actually used to prove the refinement.\\<close>\nlemma synth_analz_NI_I_K_synth_analz_NI_E:\n  \"\\<lbrakk> Keys_bad K Bad; NI \\<subseteq> payload; K \\<subseteq> range LtK; I \\<subseteq> valid\\<rbrakk>\n \\<Longrightarrow> synth (analz (NI \\<union> I \\<union> K \\<union> Tags)) \n   \\<subseteq> synth (analz (extr Bad NI (abs I))) \\<union> -payload\"\nby (intro synth_idem_payload analz_NI_I_K_synth_analz_NI_E) (assumption+)\n\n\nsubsubsection \\<open>Partitioning @{term \"analz (ik)\"}\\<close>\n(**************************************************************************************************)\ntext \\<open>Two lemmas useful for proving the invariant\n  @{term [display] \"analz ik \\<subseteq> synth (analz (ik \\<inter> payload \\<union> ik \\<inter> valid \\<union> ik \\<inter> range LtK \\<union> Tags))\"}\n\\<close>\n\nlemma analz_Un_partition:\n  \"analz S \\<subseteq> synth (analz ((S \\<inter> payload) \\<union> (S \\<inter> valid) \\<union> (S \\<inter> range LtK) \\<union> Tags)) \\<Longrightarrow>\n  H \\<subseteq> payload \\<union> valid \\<union> range LtK \\<Longrightarrow>\n  analz (H \\<union> S) \\<subseteq>\n    synth (analz (((H \\<union> S) \\<inter> payload) \\<union> ((H \\<union> S) \\<inter> valid) \\<union> ((H \\<union> S) \\<inter> range LtK) \\<union> Tags))\"\nproof -\n  assume \"H \\<subseteq> payload \\<union> valid \\<union> range LtK\"\n  then have HH:\"H = (H \\<inter> payload) \\<union> (H \\<inter> valid) \\<union> (H \\<inter> range LtK)\"\n    by auto\n  assume HA:\n    \"analz S \\<subseteq> synth (analz ((S \\<inter> payload) \\<union> (S \\<inter> valid) \\<union> (S \\<inter> range LtK) \\<union> Tags))\"\n  then have \n   \"analz (H \\<union> S) \\<subseteq> \n    synth (analz (H \\<union> ((S \\<inter> payload) \\<union> (S \\<inter> valid) \\<union> (S \\<inter> range LtK) \\<union> Tags)))\"\n    by (rule analz_synth_subset_Un2)\n  also with HH have \n    \"... \\<subseteq> synth (analz (((H \\<inter> payload) \\<union> (H \\<inter> valid) \\<union> (H \\<inter> range LtK)) \\<union> \n                         ((S \\<inter> payload) \\<union> (S \\<inter> valid) \\<union> (S \\<inter> range LtK) \\<union> Tags)))\"\n    by auto\n  also have \"... = synth (analz (((H \\<union> S) \\<inter> payload) \\<union> ((H \\<union> S) \\<inter> valid) \\<union> \n                                 ((H \\<union> S) \\<inter> range LtK) \\<union> Tags))\"\n    by (simp add: Un_left_commute sup.commute Int_Un_distrib2)\n  finally show ?thesis .\nqed\n\nlemma analz_insert_partition:\n  \"analz S \\<subseteq> synth (analz ((S \\<inter> payload) \\<union> (S \\<inter> valid) \\<union> (S \\<inter> range LtK) \\<union> Tags)) \\<Longrightarrow>\n  x \\<in> payload \\<union> valid \\<union> range LtK \\<Longrightarrow>\n  analz (insert x S) \\<subseteq>\n    synth (analz (((insert x S) \\<inter> payload) \\<union> ((insert x S) \\<inter> valid) \\<union> \n                  ((insert x S) \\<inter> range LtK) \\<union> Tags))\"\nby (simp only: insert_is_Un [of x S], erule analz_Un_partition, auto)\n\nend\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Key_Agreement_Strong_Adversaries/Implem_lemmas.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.640635841117624, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.27802408073410406}}
{"text": "section \\<open> LTS by Hashmaps \\<close>\ntheory RBT_DLTSImpl\nimports \"../../LTS_Impl\" \"../../DLTSByMap\"\nbegin\n\n\nsubsection \\<open>DLTS\\<close>\ninterpretation rs_dlts_defs: dltsbm_defs rm_ops rm_ops  \n  apply intro_locales\ndone\n\ntype_synonym ('V,'E) rs_dlts = \"('V, ('E, 'V) RBT.rbt) RBT.rbt\"\n\ndefinition rs_dlts_\\<alpha> :: \"('V::linorder,'E::linorder) rs_dlts \\<Rightarrow> ('V \\<times> 'E \\<times> 'V) set\" \n  where \"rs_dlts_\\<alpha> \\<equiv> rs_dlts_defs.dltsbm_\\<alpha>\"\n\ndefinition \"rs_dlts_invar \\<equiv> rs_dlts_defs.dltsbm_invar\"\ndefinition \"rs_dlts_empty \\<equiv> rs_dlts_defs.dltsbm_empty\"\ndefinition \"rs_dlts_memb \\<equiv> rs_dlts_defs.dltsbm_memb\"\ndefinition \"rs_dlts_add \\<equiv> rs_dlts_defs.dltsbm_add\"\ndefinition \"rs_dlts_succ \\<equiv> rs_dlts_defs.dltsbm_succ\"\ndefinition \"rs_dlts_add_succs \\<equiv> rs_dlts_defs.dltsbm_add_succs\"\ndefinition \"rs_dlts_delete \\<equiv> rs_dlts_defs.dltsbm_delete\"\n\ndefinition \"rs_dlts_it \\<equiv> rs_dlts_defs.dltsbm_it rm_iteratei rm_iteratei\"\ndefinition \"rs_dlts_filter_it \\<equiv> rs_dlts_defs.dltsbm_filter_it rm_iteratei rm_iteratei\"\ndefinition \"rs_dlts_succ_it \\<equiv> rs_dlts_defs.dltsbm_succ_it\"\ndefinition \"rs_dlts_succ_label_it \\<equiv> rs_dlts_defs.dltsbm_succ_label_it rm_iteratei\"\ndefinition \"rs_dlts_pre_it \\<equiv> rs_dlts_defs.dltsbm_pre_it rm_iteratei\"\ndefinition \"rs_dlts_pre_label_it \\<equiv> rs_dlts_defs.dltsbm_pre_label_it rm_iteratei rm_iteratei\"\n\ndefinition \"rs_dlts_from_list \\<equiv>  ltsga_from_list rs_dlts_empty rs_dlts_add\"\ndefinition \"rs_dlts_to_list \\<equiv> ltsga_to_list rs_dlts_it\"\ndefinition \"rs_dlts_from_collect_list \\<equiv>  ltsga_from_collect_list rs_dlts_empty rs_dlts_add\"\ndefinition \"rs_dlts_to_collect_list \\<equiv> ltsga_to_collect_list rs_dlts_to_list\"\ndefinition \"rs_dlts_succ_ball \\<equiv> ltsga_succ_ball rs_dlts_succ_it\"\ndefinition \"rs_dlts_succ_bex \\<equiv> ltsga_succ_bex rs_dlts_succ_it\"\ndefinition \"rs_dlts_pre_ball \\<equiv> ltsga_pre_ball rs_dlts_pre_it\"\ndefinition \"rs_dlts_pre_bex \\<equiv> ltsga_pre_bex rs_dlts_pre_it\"\ndefinition \"rs_dlts_image_filter \\<equiv> ltsga_image_filter rs_dlts_empty rs_dlts_add rs_dlts_filter_it\"\ndefinition \"rs_dlts_filter \\<equiv> ltsga_filter rs_dlts_empty rs_dlts_add rs_dlts_filter_it\"\ndefinition \"rs_dlts_image \\<equiv> ltsga_image rs_dlts_image_filter\"\n\nlemmas rs_dlts_defs_raw = \n  rs_dlts_defs.dltsbm_empty_def[abs_def]\n  rs_dlts_defs.dltsbm_succ_def[abs_def]\n  rs_dlts_defs.dltsbm_memb_def[abs_def]\n  rs_dlts_defs.dltsbm_add_def[abs_def]\n  rs_dlts_defs.dltsbm_add_succs_def[abs_def]\n  rs_dlts_defs.dltsbm_delete_def[abs_def]\n  rs_dlts_defs.dltsbm_it_alt_def\n  rs_dlts_defs.dltsbm_filter_it_alt_def\n  rs_dlts_defs.dltsbm_succ_it_def[abs_def]\n  rs_dlts_defs.dltsbm_succ_label_it_alt_def\n  rs_dlts_defs.dltsbm_pre_it_alt_def\n  rs_dlts_defs.dltsbm_pre_label_it_alt_def\n  ltsga_from_list_def[abs_def]\n  ltsga_to_list_def[abs_def]\n  ltsga_to_collect_list_def[abs_def]\n  ltsga_succ_ball_def[abs_def]\n  ltsga_succ_bex_def[abs_def]\n  ltsga_pre_ball_def[abs_def]\n  ltsga_pre_bex_def[abs_def]\n  ltsga_reverse_def[abs_def]\n  ltsga_image_filter_def[abs_def]\n  ltsga_filter_def[abs_def]\n  ltsga_image_def[abs_def]\n  iterate_to_list_def[abs_def] o_def\n  iterate_ball_def[abs_def] iterate_bex_def\n\nlemmas rs_dlts_defs = \n  rs_dlts_\\<alpha>_def\n  rs_dlts_invar_def\n  rs_dlts_empty_def\n  rs_dlts_succ_def\n  rs_dlts_memb_def\n  rs_dlts_add_def\n  rs_dlts_add_succs_def\n  rs_dlts_delete_def\n  rs_dlts_from_list_def\n  rs_dlts_to_list_def\n  rs_dlts_from_collect_list_def\n  rs_dlts_to_collect_list_def\n  rs_dlts_it_def\n  rs_dlts_filter_it_def\n  rs_dlts_succ_it_def\n  rs_dlts_succ_label_it_def\n  rs_dlts_pre_it_def\n  rs_dlts_pre_label_it_def\n  rs_dlts_succ_ball_def\n  rs_dlts_succ_bex_def\n  rs_dlts_pre_ball_def\n  rs_dlts_pre_bex_def\n  rs_dlts_image_filter_def\n  rs_dlts_filter_def\n  rs_dlts_image_def\n\nlemmas [code] = rs_dlts_defs[unfolded rs_dlts_defs_raw, simplified]\n\nlemmas rs_dlts_is_dlts_impl = rs_dlts_defs.dlts_correct[folded rs_dlts_defs]\ninterpretation rs_dlts: dlts rs_dlts_\\<alpha> rs_dlts_invar  \n  using rs_dlts_is_dlts_impl .\nlemmas rs_dlts_empty_impl = rs_dlts_defs.dltsbm_empty_correct[folded rs_dlts_defs]\ninterpretation rs_dlts: lts_empty rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_empty \n  using rs_dlts_empty_impl .\nlemmas rs_dlts_memb_impl = rs_dlts_defs.dltsbm_memb_correct[folded rs_dlts_defs]\ninterpretation rs_dlts: lts_memb rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_memb\n  using rs_dlts_memb_impl .\nlemmas rs_dlts_add_impl = rs_dlts_defs.dltsbm_add_correct[folded rs_dlts_defs]\ninterpretation rs_dlts: dlts_add rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_add\n  using rs_dlts_add_impl .\nlemmas rs_dlts_succ_impl = rs_dlts_defs.dltsbm_succ_correct[folded rs_dlts_defs]\ninterpretation rs_dlts: dlts_succ rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_succ\n  using rs_dlts_succ_impl .\nlemmas rs_dlts_add_succs_impl = rs_dlts_defs.dltsbm_add_succs_correct[folded rs_dlts_defs]\ninterpretation rs_dlts: dlts_add_succs rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_add_succs\n  using rs_dlts_add_succs_impl .\nlemmas rs_dlts_delete_impl = rs_dlts_defs.dltsbm_delete_correct[folded rs_dlts_defs]\ninterpretation rs_dlts: lts_delete rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_delete \n  using rs_dlts_delete_impl .\n\nlemmas rs_dlts_from_list_impl = \n  dltsga_from_list_correct [OF rs_dlts_empty_impl rs_dlts_add_impl, folded rs_dlts_defs]\ninterpretation rs_dlts: dlts_from_list rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_from_list \n  using rs_dlts_from_list_impl .\nlemmas rs_dlts_from_collect_list_impl = \n  dltsga_from_collect_list_correct [OF rs_dlts_empty_impl rs_dlts_add_impl, folded rs_dlts_defs]\ninterpretation rs_dlts: dlts_from_collect_list rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_from_collect_list \n  using rs_dlts_from_collect_list_impl .\n\nlemmas rs_dlts_it_impl = rs_dlts_defs.dltsbm_it_correct[folded rs_dlts_defs, \n  simplified, \n  OF rm.v1_iteratei_impl rm.v1_iteratei_impl,\n  folded rs_dlts_defs]\ninterpretation rs_dlts: lts_iterator rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_it \n  using rs_dlts_it_impl .\n\ninterpretation rs_dlts: finite_lts rs_dlts_\\<alpha> rs_dlts_invar  \n  using ltsga_it_implies_finite[OF rs_dlts_it_impl] .\n\nlemmas rs_dlts_filter_it_impl = rs_dlts_defs.dltsbm_filter_it_correct[folded rs_dlts_defs, \n  simplified, \n  OF rm.v1_iteratei_impl rm.v1_iteratei_impl,\n  folded rs_dlts_defs]\ninterpretation rs_dlts: lts_filter_it rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_filter_it \n  using rs_dlts_filter_it_impl .\n\nlemmas rs_dlts_succ_it_impl = rs_dlts_defs.dltsbm_succ_it_correct[folded rs_dlts_defs,\n  simplified, \n  folded rm_ops_def rs_ops_def rs_dlts_defs]\ninterpretation rs_dlts: lts_succ_it rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_succ_it \n  using rs_dlts_succ_it_impl .\n\nlemmas rs_dlts_succ_label_it_impl = rs_dlts_defs.dltsbm_succ_label_it_correct[folded rs_dlts_defs,\n  simplified, \n  OF rm.v1_iteratei_impl,\n  folded rm_ops_def rs_ops_def rs_dlts_defs]\ninterpretation rs_dlts: lts_succ_label_it rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_succ_label_it \n  using rs_dlts_succ_label_it_impl .\n\nlemmas rs_dlts_pre_it_impl = rs_dlts_defs.dltsbm_pre_it_correct[folded rs_dlts_defs,\n  simplified, \n  OF rm.v1_iteratei_impl,\n  folded rm_ops_def rs_ops_def rs_dlts_defs]\ninterpretation rs_dlts: lts_pre_it rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_pre_it \n  using rs_dlts_pre_it_impl .\n\nlemmas rs_dlts_pre_label_it_impl = rs_dlts_defs.dltsbm_pre_label_it_correct[folded rs_dlts_defs,\n  simplified, \n  OF rm.v1_iteratei_impl rm.v1_iteratei_impl,\n  folded rm_ops_def rs_ops_def rs_dlts_defs]\ninterpretation rs_dlts: lts_pre_label_it rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_pre_label_it \n  using rs_dlts_pre_label_it_impl .\n\nlemmas rs_dlts_to_list_impl = ltsga_to_list_correct [OF rs_dlts_it_impl, folded rs_dlts_defs]\ninterpretation rs_dlts: lts_to_list rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_to_list \n  using rs_dlts_to_list_impl .\n\nlemmas rs_dlts_to_collect_list_impl = ltsga_to_collect_list_correct \n  [OF rs_dlts_to_list_impl, folded rs_dlts_defs]\ninterpretation rs_dlts: lts_to_collect_list rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_to_collect_list \n  using rs_dlts_to_collect_list_impl .\n\nlemmas rs_dlts_succ_ball_impl = ltsga_succ_ball_correct [OF rs_dlts_succ_it_impl, folded rs_dlts_defs]\ninterpretation rs_dlts: lts_succ_ball rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_succ_ball \n  using rs_dlts_succ_ball_impl .\n\nlemmas rs_dlts_succ_bex_impl = ltsga_succ_bex_correct [OF rs_dlts_succ_it_impl, folded rs_dlts_defs]\ninterpretation rs_dlts: lts_succ_bex rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_succ_bex \n  using rs_dlts_succ_bex_impl .\n\nlemmas rs_dlts_pre_ball_impl = ltsga_pre_ball_correct [OF rs_dlts_pre_it_impl, folded rs_dlts_defs]\ninterpretation rs_dlts: lts_pre_ball rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_pre_ball \n  using rs_dlts_pre_ball_impl .\n\nlemmas rs_dlts_pre_bex_impl = ltsga_pre_bex_correct [OF rs_dlts_pre_it_impl, folded rs_dlts_defs]\ninterpretation rs_dlts: lts_pre_bex rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_pre_bex \n  using rs_dlts_pre_bex_impl .\n\nlemmas rs_dlts_image_filter_impl = dltsga_image_filter_correct [OF rs_dlts_empty_impl \n   rs_dlts_add_impl rs_dlts_filter_it_impl, folded rs_dlts_image_filter_def]\ninterpretation rs_dlts: dlts_image_filter rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_image_filter\n  using rs_dlts_image_filter_impl .\n\nlemmas rs_dlts_inj_image_filter_impl = dltsga_inj_image_filter_correct [OF rs_dlts_empty_impl \n   rs_dlts_add_impl rs_dlts_filter_it_impl rs_dlts_is_dlts_impl, folded rs_dlts_image_filter_def]\ninterpretation rs_dlts: lts_inj_image_filter rs_dlts_\\<alpha> rs_dlts_invar \n  rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_image_filter\n  using rs_dlts_inj_image_filter_impl .\n\nlemmas rs_dlts_filter_impl = dltsga_filter_correct [OF rs_dlts_empty_impl \n   rs_dlts_add_impl rs_dlts_filter_it_impl rs_dlts_is_dlts_impl, folded rs_dlts_filter_def]\ninterpretation rs_dlts: lts_filter rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_filter\n  using rs_dlts_filter_impl .\n\nlemmas rs_dlts_image_impl = dltsga_image_correct [OF rs_dlts_image_filter_impl, folded rs_dlts_image_def]\ninterpretation rs_dlts: dlts_image rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_\\<alpha> rs_dlts_invar rs_dlts_image\n  using rs_dlts_image_impl .\n\ndefinition rs_dlts_ops :: \"('V::{linorder},'E::{linorder},('V,'E) rs_dlts) lts_ops\" where\n   \"rs_dlts_ops \\<equiv> \\<lparr>\n    lts_op_\\<alpha> = rs_dlts_\\<alpha>,\n    lts_op_invar = rs_dlts_invar,\n    lts_op_empty = rs_dlts_empty,\n    lts_op_memb = rs_dlts_memb,\n    lts_op_iterator = rs_dlts_it,\n    lts_op_add = rs_dlts_add,\n    lts_op_add_succs = rs_dlts_add_succs,\n    lts_op_delete = rs_dlts_delete,\n    lts_op_succ_ball = rs_dlts_succ_ball,\n    lts_op_succ_bex = rs_dlts_succ_bex,\n    lts_op_pre_ball = rs_dlts_pre_ball,\n    lts_op_pre_bex = rs_dlts_pre_bex,\n    lts_op_to_list = rs_dlts_to_list,\n    lts_op_to_collect_list = rs_dlts_to_collect_list,\n    lts_op_from_list = rs_dlts_from_list,\n    lts_op_from_collect_list = rs_dlts_from_collect_list,\n    lts_op_image_filter = rs_dlts_image_filter,\n    lts_op_filter = rs_dlts_filter,\n    lts_op_image = rs_dlts_image,\n    lts_op_succ = rs_dlts_succ\\<rparr>\"\n\nlemma rs_dlts_ops_unfold[code_unfold] :\n    \"lts_op_\\<alpha> rs_dlts_ops = rs_dlts_\\<alpha>\"\n    \"lts_op_invar rs_dlts_ops = rs_dlts_invar\"\n    \"lts_op_empty rs_dlts_ops = rs_dlts_empty\"\n    \"lts_op_memb rs_dlts_ops = rs_dlts_memb\"\n    \"lts_op_iterator rs_dlts_ops = rs_dlts_it\"\n    \"lts_op_add rs_dlts_ops = rs_dlts_add\"\n    \"lts_op_succ rs_dlts_ops = rs_dlts_succ\"\n    \"lts_op_add_succs rs_dlts_ops = rs_dlts_add_succs\"\n    \"lts_op_delete rs_dlts_ops = rs_dlts_delete\"\n    \"lts_op_succ_ball rs_dlts_ops = rs_dlts_succ_ball\"\n    \"lts_op_succ_bex rs_dlts_ops = rs_dlts_succ_bex\"\n    \"lts_op_pre_ball rs_dlts_ops = rs_dlts_pre_ball\"\n    \"lts_op_pre_bex rs_dlts_ops = rs_dlts_pre_bex\"\n    \"lts_op_to_list rs_dlts_ops = rs_dlts_to_list\"\n    \"lts_op_to_collect_list rs_dlts_ops = rs_dlts_to_collect_list\"\n    \"lts_op_from_list rs_dlts_ops = rs_dlts_from_list\"\n    \"lts_op_from_collect_list rs_dlts_ops = rs_dlts_from_collect_list\"\n    \"lts_op_image_filter rs_dlts_ops = rs_dlts_image_filter\"\n    \"lts_op_filter rs_dlts_ops = rs_dlts_filter\"\n  by (simp_all add: rs_dlts_ops_def)\n\nlemma rs_dlts_impl: \"StdDLTS rs_dlts_ops\"\n  apply (rule StdDLTS.intro)\n  apply (simp_all add: rs_dlts_ops_def)\n  apply unfold_locales\ndone\n\ninterpretation rs_dltsr: StdDLTS rs_dlts_ops by (rule rs_dlts_impl)\n\nend\n", "meta": {"author": "VTrelat", "repo": "Hopcroft_verif", "sha": "ede77c3a2105fd6722cf96896a297db294edf269", "save_path": "github-repos/isabelle/VTrelat-Hopcroft_verif", "path": "github-repos/isabelle/VTrelat-Hopcroft_verif/Hopcroft_verif-ede77c3a2105fd6722cf96896a297db294edf269/Isabelle/Automata_Malik_Tuerk/implementation/instantiations/RBT/RBT_DLTSImpl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5350984286266116, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.27799504301458494}}
{"text": "section \\<open> Stateful-Failure Programs \\<close>\n\ntheory utp_sfrd_prog\n  imports\n    \"UTP1.utp_full\"\n    utp_sfrd_extchoice\nbegin\n\nsubsection \\<open> Conditionals \\<close>\n\nlemma NCSP_cond_srea [closure]:\n  assumes \"P is NCSP\" \"Q is NCSP\"\n  shows \"P \\<triangleleft> b \\<triangleright>\\<^sub>R Q is NCSP\"\n  by (rule NCSP_NSRD_intro, simp_all add: closure rdes assms unrest)\n\nsubsection \\<open> Guarded commands \\<close>\n\nlemma GuardedCommR_NCSP_closed [closure]: \n  assumes \"P is NCSP\"\n  shows \"g \\<rightarrow>\\<^sub>R P is NCSP\"\n  by (simp add: gcmd_def closure assms)\n\nsubsection \\<open> Alternation \\<close>\n\nlemma AlternateR_NCSP_closed [closure]:\n  assumes \"\\<And> i. i \\<in> A \\<Longrightarrow> P(i) is NCSP\" \"Q is NCSP\"\n  shows \"(if\\<^sub>R i\\<in>A \\<bullet> g(i) \\<rightarrow> P(i) else Q fi) is NCSP\"\nproof (cases \"A = {}\")\n  case True\n  then show ?thesis\n    by (simp add: assms)\nnext\n  case False\n  then show ?thesis\n    by (simp add: AlternateR_def closure assms)\nqed\n\nlemma AlternateR_list_NCSP_closed [closure]:\n  assumes \"\\<And> b P. (b, P) \\<in> set A \\<Longrightarrow> P is NCSP\" \"Q is NCSP\"\n  shows \"(AlternateR_list A Q) is NCSP\"\n  apply (simp add: AlternateR_list_def)\n  apply (rule AlternateR_NCSP_closed)\n  apply (auto simp add: assms)\n  apply (metis assms(1) eq_snd_iff nth_mem)\n  done\n\nsubsection \\<open> Specification Statement \\<close>\n\ndefinition SpecC :: \"('a \\<Longrightarrow> 's) \\<Rightarrow> 's upred \\<Rightarrow> 's upred \\<Rightarrow> ('s, 'e) action\" (\"_:[_,_]\\<^sub>C\" [999,0,0] 999) where\n[rdes_def]: \"SpecC frm pre post = \\<^bold>R\\<^sub>s([pre]\\<^sub>S\\<^sub>< \\<turnstile> false \\<diamondop> [frm:[post\\<^sup>>]]\\<^sub>S)\"\n\nlemma SpecC_is_NCSP [closure]: \"frm:[pre,post]\\<^sub>C is NCSP\"\n  apply (simp add: SpecC_def)\n  apply (rule NCSP_rdes_intro)\n      apply (simp_all add: closure unrest)\n   apply (rel_auto)+\n  done\n\nlemma SpecC_skip: \"{}\\<^sub>v:[true,true]\\<^sub>C = Skip\"\n  by (rdes_eq)\n\nlemma SpecC_false_pre: \"a:[false,q]\\<^sub>C = Chaos\"\n  by (rdes_eq)\n\nlemma SpecC_false_post: \"a:[true,false]\\<^sub>C = Miracle\"\n  by (rdes_eq)\n\nlemma SpecC_refine_seq:\n  \"vwb_lens a \\<Longrightarrow> a:[p,q]\\<^sub>C \\<sqsubseteq> a:[p,r]\\<^sub>C ;; a:[r,q]\\<^sub>C\"\n  by ((rdes_refine_split; rel_simp), metis vwb_lens.put_eq)\n\nsubsection \\<open> Assumptions \\<close>\n\ndefinition AssumeCircus (\"[_]\\<^sub>C\") where\n\"[b]\\<^sub>C = b \\<rightarrow>\\<^sub>R Skip\"\n\nlemma AssumeCircus_rdes_def [rdes_def]: \"[b]\\<^sub>C = \\<^bold>R\\<^sub>s(true\\<^sub>r \\<turnstile> false \\<diamondop> [b]\\<^sub>c)\"\n  unfolding AssumeCircus_def by rdes_eq\n\nlemma AssumeCircus_NCSP [closure]: \"[b]\\<^sub>C is NCSP\"\n  by (simp add: AssumeCircus_def GuardedCommR_NCSP_closed NCSP_Skip)\n\nlemma AssumeCircus_AssumeR: \"Skip ;; [b]\\<^sup>\\<top>\\<^sub>R = [b]\\<^sub>C\" \"[b]\\<^sup>\\<top>\\<^sub>R ;; Skip = [b]\\<^sub>C\"\n  by (rdes_eq)+\n\nlemma AssumeR_comp_AssumeCircus: \"P is NCSP \\<Longrightarrow> P ;; [b]\\<^sup>\\<top>\\<^sub>R = P ;; [b]\\<^sub>C\"\n  by (metis (no_types, opaque_lifting) AssumeCircus_AssumeR(1) RA1 Skip_right_unit)\n\nlemma gcmd_AssumeCircus: \n  \"P is NCSP \\<Longrightarrow> b \\<rightarrow>\\<^sub>R P = [b]\\<^sub>C ;; P\"\n  by (simp add: AssumeCircus_def NCSP_implies_NSRD Skip_left_unit gcmd_seq_distr)\n\nlemma rdes_assume_pre_refine:\n  assumes \"P is NCSP\"\n  shows \"P \\<sqsubseteq> [b]\\<^sub>C ;; P\"\n  by (rdes_refine cls: assms)\n\nsubsection \\<open> While Loops \\<close>\n\nlemma NSRD_coerce_NCSP:\n  \"P is NSRD \\<Longrightarrow> Skip ;; P ;; Skip is NCSP\"\n  by (metis (no_types, opaque_lifting) CSP3_Skip CSP3_def CSP4_def Healthy_def NCSP_Skip NCSP_implies_CSP NCSP_intro NSRD_is_SRD RA1 SRD_seqr_closure)\n\ndefinition WhileC :: \"'s upred \\<Rightarrow> ('s, 'e) action \\<Rightarrow> ('s, 'e) action\" (\"while\\<^sub>C _ do _ od\") where\n\"while\\<^sub>C b do P od = Skip ;; while\\<^sub>R b do P od ;; Skip\"\n\nlemma WhileC_NCSP_closed [closure]:\n  assumes \"P is NCSP\" \"P is Productive\"\n  shows \"while\\<^sub>C b do P od is NCSP\"\n  by (simp add: WhileC_def NSRD_coerce_NCSP assms closure)\n\ntheorem WhileC_iter_form:\n  assumes \"P is NCSP\" \"P is Productive\"\n  shows \"while\\<^sub>C b do P od = ([b]\\<^sub>C ;; P)\\<^sup>\\<star>\\<^sup>C ;; [\\<not> b]\\<^sub>C\"\n  by (simp add: WhileC_def WhileR_iter_form assms closure)\n     (metis (no_types, lifting) StarC_def AssumeCircus_AssumeR(2) AssumeCircus_NCSP RA1 assms(1) csp_theory.Healthy_Sequence csp_theory.Star_Healthy csp_theory.Unit_Left sfrd_star_as_rdes_star)\n\ntheorem WhileC_rdes_def [rdes_def]:\n  assumes \"P is CRC\" \"Q is CRR\" \"R is CRF\" \"$st\\<acute> \\<sharp> Q\" \"R is R4\"\n  shows \"while\\<^sub>C b do \\<^bold>R\\<^sub>s(P \\<turnstile> Q \\<diamondop> R) od = \n         \\<^bold>R\\<^sub>s (([b]\\<^sub>c ;; R)\\<^sup>\\<star>\\<^sup>c wp\\<^sub>r ([b]\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r P) \\<turnstile> (([b]\\<^sub>c ;; R)\\<^sup>\\<star>\\<^sup>c ;; [b]\\<^sub>c ;; Q) \\<diamondop> (([b]\\<^sub>c ;; R)\\<^sup>\\<star>\\<^sup>c ;; [\\<not> b]\\<^sub>c))\" \n  (is \"?lhs = ?rhs\")\nproof -\n  have \"?lhs = ([b]\\<^sub>C ;; \\<^bold>R\\<^sub>s (P \\<turnstile> Q \\<diamondop> R))\\<^sup>\\<star>\\<^sup>C ;; [\\<not> b]\\<^sub>C\"\n    by (simp add: WhileC_iter_form assms closure unrest Productive_rdes_RR_intro)\n  also have \"... = ?rhs\"\n    by (simp add: rdes_def assms closure unrest rpred wp del: rea_star_wp)\n  finally show ?thesis .\nqed\n\nlemma WhileC_false: \n  \"P is NCSP \\<Longrightarrow> WhileC false P = Skip\"\n  by (simp add: NCSP_implies_NSRD Skip_srdes_left_unit WhileC_def WhileR_false)\n\nlemma WhileC_unfold: \n  assumes \"P is NCSP\" \"P is Productive\"\n  shows \"WhileC b P = (P ;; WhileC b P) \\<triangleleft> b \\<triangleright>\\<^sub>R Skip\"\nproof -\n  have \"WhileC b P = (Skip \\<or> [b]\\<^sub>C ;; P ;; ([b]\\<^sub>C ;; P)\\<^sup>\\<star>\\<^sup>C) ;; [\\<not> b]\\<^sub>C\"\n    by (simp add: WhileC_iter_form assms closure)\n       (metis (no_types, lifting) AssumeCircus_NCSP RA1 StarC_unfold assms(1) csp_theory.Healthy_Sequence disj_upred_def)\n  also have \"... = ([\\<not> b]\\<^sub>C \\<or> [b]\\<^sub>C ;; P ;; ([b]\\<^sub>C ;; P)\\<^sup>\\<star>\\<^sup>C ;; [\\<not> b]\\<^sub>C)\"\n    by (metis (no_types, lifting) AssumeCircus_AssumeR(1) RA1 csp_theory.Unit_self seqr_or_distl)\n  also have \"... = (P ;; WhileC b P) \\<triangleleft> b \\<triangleright>\\<^sub>R Skip\"\n    by (metis (no_types, lifting) AssumeCircus_AssumeR(2) NCSP_implies_NSRD RA1 WhileC_NCSP_closed WhileC_iter_form assms(1) assms(2) cond_srea_AssumeR_form csp_theory.Healthy_Sequence csp_theory.Healthy_Unit csp_theory.Unit_Left uinf_or utp_pred_laws.sup_commute)\n  finally show ?thesis .\nqed\n\nsubsection \\<open> Iteration Construction \\<close>\n\ndefinition IterateC :: \"'a set \\<Rightarrow> ('a \\<Rightarrow> 's upred) \\<Rightarrow> ('a \\<Rightarrow> ('s, 'e) action) \\<Rightarrow> ('s, 'e) action\"\nwhere [upred_defs, ndes_simp]: \"IterateC A g P = while\\<^sub>C (\\<Or> i\\<in>A \\<bullet> g(i)) do (if\\<^sub>R i\\<in>A \\<bullet> g(i) \\<rightarrow> P(i) fi) od\"\n\nlemma IterateC_IterateR_def: \"IterateC A g P = Skip ;; IterateR A g P ;; Skip\"\n  by (simp add: IterateC_def IterateR_def WhileC_def)\n\ndefinition IterateC_list :: \"('s upred \\<times> ('s, 'e) action) list \\<Rightarrow> ('s, 'e) action\" where \n[upred_defs, ndes_simp]:\n  \"IterateC_list xs = IterateC {0..<length xs} (\\<lambda> i. map fst xs ! i) (\\<lambda> i. map snd xs ! i)\"\n\nsyntax\n  \"_iter_C\"    :: \"pttrn \\<Rightarrow> logic \\<Rightarrow> logic \\<Rightarrow> logic \\<Rightarrow> logic\" (\"do\\<^sub>C _\\<in>_ \\<bullet> _ \\<rightarrow> _ od\")\n  \"_iter_gcommC\" :: \"gcomms \\<Rightarrow> logic\" (\"do\\<^sub>C/ _ /od\")\n\ntranslations\n  \"_iter_C x A g P\" => \"CONST IterateC A (\\<lambda> x. g) (\\<lambda> x. P)\"\n  \"_iter_C x A g P\" <= \"CONST IterateC A (\\<lambda> x. g) (\\<lambda> x'. P)\"\n  \"_iter_gcommC cs\" \\<rightharpoonup> \"CONST IterateC_list cs\"\n  \"_iter_gcommC (_gcomm_show cs)\" \\<leftharpoondown> \"CONST IterateC_list cs\"\n\nlemma IterateC_NCSP_closed [closure]:\n  assumes \n    \"\\<And> i. i \\<in> I \\<Longrightarrow> P(i) is NCSP\" \n    \"\\<And> i. i \\<in> I \\<Longrightarrow> P(i) is Productive\"\n  shows \"do\\<^sub>C i\\<in>I \\<bullet> g(i) \\<rightarrow> P(i) od is NCSP\"\n  by (simp add: IterateC_IterateR_def IterateR_NSRD_closed NCSP_implies_NSRD NSRD_coerce_NCSP assms(1) assms(2))\n\nlemma IterateC_list_NCSP_closed [closure]:\n  assumes \n    \"\\<And> b P. (b, P) \\<in> set A \\<Longrightarrow> P is NCSP\"\n    \"\\<And> b P. (b, P) \\<in> set A \\<Longrightarrow> P is Productive\"\n  shows \"IterateC_list A is NCSP\"\n  apply (simp add: IterateC_list_def, rule IterateC_NCSP_closed)\n   apply (metis assms atLeastLessThan_iff nth_map nth_mem prod.collapse)+\n  done\n\nlemma IterateC_list_alt_def:\n  \"IterateC_list xs = while\\<^sub>C (\\<Or> b \\<in> set(map fst xs) \\<bullet> b) do AlternateR_list xs Chaos od\"\nproof -\n  have \"(\\<Or> i \\<in> {0..<length(xs)} \\<bullet> (map fst xs) ! i) = (\\<Or> b \\<in> set(map fst xs) \\<bullet> b)\"\n    by (rel_auto, metis fst_conv in_set_conv_nth nth_map)\n  thus ?thesis\n    by (simp add: IterateC_list_def IterateC_def AlternateR_list_def)\nqed\n\nlemma IterateC_empty: \n  \"do\\<^sub>C i\\<in>{} \\<bullet> g(i) \\<rightarrow> P(i) od = Skip\"\n  by (simp add: IterateC_IterateR_def IterateR_empty closure Skip_srdes_left_unit)\n\nlemma IterateC_singleton: \n  assumes \"P k is NCSP\" \"P k is Productive\"\n  shows \"do\\<^sub>C i\\<in>{k} \\<bullet> g(i) \\<rightarrow> P(i) od = while\\<^sub>C g(k) do P(k) od\" (is \"?lhs = ?rhs\")\n  by (simp add: IterateC_IterateR_def IterateR_singleton NCSP_implies_NSRD WhileC_def assms)\n\nlemma IterateC_outer_refine_intro:\n  assumes \"I \\<noteq> {}\" \"\\<And> i. i \\<in> I \\<Longrightarrow> P i is NCSP\" \"\\<And> i. i \\<in> I \\<Longrightarrow> P i is Productive\"\n    \"\\<And> i. i \\<in> I \\<Longrightarrow> S \\<sqsubseteq> (b i \\<rightarrow>\\<^sub>R P i ;; S)\" \"S is NCSP\"\n    \"S \\<sqsubseteq> [\\<not> (\\<Sqinter> i \\<in> I \\<bullet> b i)]\\<^sup>\\<top>\\<^sub>R\"\n  shows \"S \\<sqsubseteq> do\\<^sub>C i\\<in>I \\<bullet> b(i) \\<rightarrow> P(i) od\"\nproof -\n  have \"S \\<sqsubseteq> do\\<^sub>R i\\<in>I \\<bullet> b(i) \\<rightarrow> P(i) od\"\n    by (simp add: IterateR_outer_refine_intro NCSP_implies_NSRD assms)\n  thus ?thesis\n    unfolding IterateC_IterateR_def\n    by (metis (full_types) Skip_left_unit Skip_right_unit assms(5) urel_dioid.mult_isol urel_dioid.mult_isor)\nqed\n\nlemma IterateC_outer_refine_init_intro:\n  assumes \n    \"\\<And> i. i \\<in> A \\<Longrightarrow> P i is NCSP\" \n    \"\\<And> i. i \\<in> A \\<Longrightarrow> P i is Productive\" \n    \"S is NCSP\" \"I is NCSP\"\n    \"S \\<sqsubseteq> I ;; [\\<not> (\\<Sqinter> i \\<in> A \\<bullet> b i)]\\<^sup>\\<top>\\<^sub>R\"\n    \"\\<And> i. i \\<in> A \\<Longrightarrow> S \\<sqsubseteq> S ;; b i \\<rightarrow>\\<^sub>R P i\"\n    \"\\<And> i. i \\<in> A \\<Longrightarrow> S \\<sqsubseteq> I ;; b i \\<rightarrow>\\<^sub>R P i\"\n  shows \"S \\<sqsubseteq> I ;; do\\<^sub>C i\\<in>A \\<bullet> b(i) \\<rightarrow> P(i) od\"\nproof (cases \"A = {}\")\n  case True\n  with assms(5) show ?thesis \n    by (simp add: IterateC_empty assms closure Skip_right_unit AssumeR_true NSRD_right_unit)\nnext\n  case False\n  have \"S \\<sqsubseteq> I ;; do\\<^sub>R i\\<in>A \\<bullet> b(i) \\<rightarrow> P(i) od\"\n    by (simp add: IterateR_outer_refine_init_intro NCSP_implies_NSRD assms False)\n  thus ?thesis\n    unfolding IterateC_IterateR_def\n    by (metis (no_types, opaque_lifting) RA1 Skip_right_unit assms(3) assms(4) urel_dioid.mult_isor) \nqed\n\n\nlemma IterateC_list_outer_refine_intro:\n  assumes \n    \"A \\<noteq> []\" \"S is NCSP\"\n    \"\\<And> b P. (b, P) \\<in> set A \\<Longrightarrow> P is NCSP\"\n    \"\\<And> b P. (b, P) \\<in> set A \\<Longrightarrow> P is Productive\"\n    \"\\<And> b P. (b, P) \\<in> set A \\<Longrightarrow> S \\<sqsubseteq> (b \\<rightarrow>\\<^sub>R P ;; S)\"\n    \"S \\<sqsubseteq> [\\<not> (\\<Sqinter> (b, P) \\<in> set A \\<bullet> b)]\\<^sup>\\<top>\\<^sub>R\" \n  shows \"S \\<sqsubseteq> IterateC_list A\"\nproof -\n  have \"(\\<Sqinter> i \\<in> {0..<length(A)} \\<bullet> (map fst A) ! i) = (\\<Sqinter> (b, P) \\<in> set A \\<bullet> b)\"\n    by (rel_auto, metis nth_mem prod.exhaust_sel, metis fst_conv in_set_conv_nth nth_map)\n  thus ?thesis\n    apply (simp add: IterateC_list_def)\n    apply (rule IterateC_outer_refine_intro)\n     apply (simp_all add: closure assms)\n    apply (metis assms(3) nth_mem prod.collapse)\n    apply (metis assms(4) nth_mem prod.collapse)\n    done\nqed\n\nlemma IterateC_list_outer_refine_init_intro:\n  assumes \n    \"S is NCSP\" \"I is NCSP\"\n    \"\\<And> b P. (b, P) \\<in> set A \\<Longrightarrow> P is NCSP\"\n    \"\\<And> b P. (b, P) \\<in> set A \\<Longrightarrow> P is Productive\"\n    \"S \\<sqsubseteq> I ;; [\\<not> (\\<Sqinter> (b, P) \\<in> set A \\<bullet> b)]\\<^sup>\\<top>\\<^sub>R\"\n    \"\\<And> b P. (b, P) \\<in> set A \\<Longrightarrow> S \\<sqsubseteq> S ;; b \\<rightarrow>\\<^sub>R P\"\n    \"\\<And> b P. (b, P) \\<in> set A \\<Longrightarrow> S \\<sqsubseteq> I ;; b \\<rightarrow>\\<^sub>R P\" \n  shows \"S \\<sqsubseteq> I ;; IterateC_list A\"\nproof -\n  have \"(\\<Sqinter> i \\<in> {0..<length(A)} \\<bullet> (map fst A) ! i) = (\\<Sqinter> (b, P) \\<in> set A \\<bullet> b)\"\n    by (rel_auto, metis nth_mem prod.exhaust_sel, metis fst_conv in_set_conv_nth nth_map)\n  thus ?thesis\n    apply (simp add: IterateC_list_def)\n    apply (rule IterateC_outer_refine_init_intro)\n     apply (simp_all add: closure assms)\n    apply (metis assms(3) nth_mem prod.collapse)\n    apply (metis assms(4) nth_mem prod.collapse)\n    done\nqed\n\nsubsection \\<open> Assignment \\<close>\n\ndefinition AssignsCSP :: \"'\\<sigma> usubst \\<Rightarrow> ('\\<sigma>, '\\<phi>) action\" (\"\\<langle>_\\<rangle>\\<^sub>C\") where\n[upred_defs]: \"AssignsCSP \\<sigma> = \\<^bold>R\\<^sub>s(true \\<turnstile> false \\<diamondop> ($tr\\<acute> =\\<^sub>u $tr \\<and> \\<lceil>\\<langle>\\<sigma>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>S))\" \n\nabbreviation \"AssignCSP x v \\<equiv> \\<^bold>R\\<^sub>s([&\\<^bold>v \\<in>\\<^sub>u \\<guillemotleft>\\<S>\\<^bsub>x\\<^esub>\\<guillemotright>]\\<^sub>S\\<^sub>< \\<turnstile> false \\<diamondop> \\<Phi>(true,[x \\<mapsto>\\<^sub>s v], \\<guillemotleft>[]\\<guillemotright>))\"\n\nsyntax\n  \"_assigns_csp\" :: \"svids \\<Rightarrow> uexprs \\<Rightarrow> logic\"  (\"'(_') :=\\<^sub>C '(_')\")  \n  \"_assigns_csp\" :: \"svids \\<Rightarrow> uexprs \\<Rightarrow> logic\"  (infixr \":=\\<^sub>C\" 64)\n\ntranslations\n  \"_assigns_csp xs vs\" => \"CONST AssignsCSP (_mk_usubst id\\<^sub>s xs vs)\"\n  \"_assigns_csp x v\" <= \"CONST AssignsCSP (CONST subst_upd id\\<^sub>s x v)\"\n  \"_assigns_csp x v\" <= \"_assigns_csp (_spvar x) v\"\n  \"x,y :=\\<^sub>C u,v\" <= \"CONST AssignsCSP (CONST subst_upd (CONST subst_upd (id\\<^sub>s) (CONST pr_var x) u) (CONST pr_var y) v)\"\n\nlemma preR_AssignsCSP [rdes]: \"pre\\<^sub>R(\\<langle>\\<sigma>\\<rangle>\\<^sub>C) = true\\<^sub>r\"\n  by (rel_auto)\n\nlemma periR_AssignsCSP [rdes]: \"peri\\<^sub>R(\\<langle>\\<sigma>\\<rangle>\\<^sub>C) = false\"\n  by (rel_auto)\n\nlemma postR_AssignsCSP [rdes]: \"post\\<^sub>R(\\<langle>\\<sigma>\\<rangle>\\<^sub>C) = \\<Phi>(true,\\<sigma>,\\<guillemotleft>[]\\<guillemotright>)\"\n  by (rel_auto)\n\nlemma AssignsCSP_rdes_def [rdes_def] : \"\\<langle>\\<sigma>\\<rangle>\\<^sub>C = \\<^bold>R\\<^sub>s(true\\<^sub>r \\<turnstile> false \\<diamondop> \\<Phi>(true,\\<sigma>,\\<guillemotleft>[]\\<guillemotright>))\"\n  by (rel_auto)\n\nlemma AssignsCSP_CSP [closure]: \"\\<langle>\\<sigma>\\<rangle>\\<^sub>C is CSP\"\n  by (simp add: AssignsCSP_def RHS_tri_design_is_SRD unrest)\n\nlemma AssignsCSP_CSP3 [closure]: \"\\<langle>\\<sigma>\\<rangle>\\<^sub>C is CSP3\"\n  by (rule CSP3_intro, simp add: closure, rel_auto)\n\nlemma AssignsCSP_CSP4 [closure]: \"\\<langle>\\<sigma>\\<rangle>\\<^sub>C is CSP4\"\n  by (rule CSP4_intro, simp add: closure, rel_auto+)\n\nlemma AssignsCSP_NCSP [closure]: \"\\<langle>\\<sigma>\\<rangle>\\<^sub>C is NCSP\"\n  by (simp add: AssignsCSP_CSP AssignsCSP_CSP3 AssignsCSP_CSP4 NCSP_intro)\n\nlemma AssignsCSP_ICSP [closure]: \"\\<langle>\\<sigma>\\<rangle>\\<^sub>C is ICSP\"\n  apply (rule ICSP_intro, simp add: closure, simp add: rdes_def)\n  apply (rule ISRD1_rdes_intro)\n  apply (simp_all add: closure)\n  apply (rel_auto)\ndone\n\nlemma unproductive_AssignsCSP: \"\\<not> (\\<langle>\\<sigma>\\<rangle>\\<^sub>C is Productive)\"\n  unfolding rdes_def by (rule unproductive_form, simp_all add: closure, rel_auto+)\n\nlemma AssignsCSP_as_AssignsR: \"\\<langle>\\<sigma>\\<rangle>\\<^sub>R ;; Skip = \\<langle>\\<sigma>\\<rangle>\\<^sub>C\"\n  by (rdes_eq)\n\nlemma AssignC_init_refine_intro:\n  assumes \n    \"vwb_lens x\" \"$st:x \\<sharp> P\\<^sub>2\" \"$st:x \\<sharp> P\\<^sub>3\"\n    \"P\\<^sub>2 is RR\" \"P\\<^sub>3 is RR\" \"Q is NCSP\"\n    \"\\<^bold>R\\<^sub>s([&x =\\<^sub>u \\<guillemotleft>k\\<guillemotright>]\\<^sub>S\\<^sub>< \\<turnstile> P\\<^sub>2 \\<diamondop> P\\<^sub>3) \\<sqsubseteq> Q\"\n  shows \"\\<^bold>R\\<^sub>s(true\\<^sub>r \\<turnstile> P\\<^sub>2 \\<diamondop> P\\<^sub>3) \\<sqsubseteq> (x :=\\<^sub>C \\<guillemotleft>k\\<guillemotright>) ;; Q\"\n  by (simp add: AssignsCSP_as_AssignsR[THEN sym] assms seqr_assoc Skip_left_unit AssignR_init_refine_intro closure)\n\nlemma AssignsCSP_refines_sinv: \n  assumes \"`\\<sigma> \\<dagger> b`\"\n  shows \"sinv\\<^sub>R(b) \\<sqsubseteq> \\<langle>\\<sigma>\\<rangle>\\<^sub>C\"\n  apply (rdes_refine_split)\n  apply (simp_all)\n   apply (metis rea_st_cond_true st_cond_conj utp_pred_laws.inf.absorb_iff2 utp_pred_laws.inf_top_left)\n  using assms apply (rel_auto)\n  done\n\nsubsection \\<open> Assignment with update \\<close>\n\ntext \\<open> There are different collections that we would like to assign to, but they all have different\n  types and perhaps more importantly different conditions on the update being well defined. For example,\n  for a list well-definedness equates to the index being less than the length etc. Thus we here set\n  up a polymorphic constant for CSP assignment updates that can be specialised to different types. \\<close>\n    \ndefinition AssignCSP_update :: \n  \"('f \\<Rightarrow> 'k set) \\<Rightarrow> ('f \\<Rightarrow> 'k \\<Rightarrow> 'v \\<Rightarrow> 'f) \\<Rightarrow> ('f \\<Longrightarrow> '\\<sigma>) \\<Rightarrow> \n   ('k, '\\<sigma>) uexpr \\<Rightarrow> ('v, '\\<sigma>) uexpr \\<Rightarrow> ('\\<sigma>, '\\<phi>) action\" where\n[upred_defs,rdes_def]: \"AssignCSP_update domf updatef x k v = \n  \\<^bold>R\\<^sub>s([k \\<in>\\<^sub>u uop domf (&x)]\\<^sub>S\\<^sub>< \\<turnstile> false \\<diamondop> \\<Phi>(true,[x \\<mapsto>\\<^sub>s trop updatef (&x) k v], \\<guillemotleft>[]\\<guillemotright>))\"\n\ntext \\<open> All different assignment updates have the same syntax; the type resolves which implementation\n  to use. \\<close>\n  \nsyntax\n  \"_csp_assign_upd\" :: \"svid \\<Rightarrow> logic \\<Rightarrow> logic \\<Rightarrow> logic\" (\"_[_] :=\\<^sub>C _\" [61,0,62] 62)\n\ntranslations\n  \"_csp_assign_upd x k v\" == \"CONST AssignCSP_update (CONST Relation_Toolkit.dom) (CONST uupd) x k v\"\n\nlemma AssignCSP_update_CSP [closure]:\n  \"AssignCSP_update domf updatef x k v is CSP\"\n  by (simp add: AssignCSP_update_def RHS_tri_design_is_SRD unrest)\n    \nlemma preR_AssignCSP_update [rdes]: \n  \"pre\\<^sub>R(AssignCSP_update domf updatef x k v) = [k \\<in>\\<^sub>u uop domf (&x)]\\<^sub>S\\<^sub><\"\n  by (rel_auto)\n\nlemma periR_AssignCSP_update [rdes]:\n  \"peri\\<^sub>R(AssignCSP_update domf updatef x k v) = [k \\<notin>\\<^sub>u uop domf (&x)]\\<^sub>S\\<^sub><\"\n  by (rel_simp)\n\nlemma post_AssignCSP_update [rdes]:\n  \"post\\<^sub>R(AssignCSP_update domf updatef x k v) = \n    (\\<Phi>(true,[x \\<mapsto>\\<^sub>s trop updatef (&x) k v],\\<guillemotleft>[]\\<guillemotright>) \\<triangleleft> (k \\<in>\\<^sub>u uop domf (&x)) \\<triangleright>\\<^sub>R R1(true))\"\n  by (rel_auto) \n\nlemma AssignCSP_update_NCSP [closure]:\n  \"(AssignCSP_update domf updatef x k v) is NCSP\"\nproof (rule NCSP_intro)\n  show \"(AssignCSP_update domf updatef x k v) is CSP\"\n    by (simp add: closure)\n  show \"(AssignCSP_update domf updatef x k v) is CSP3\"\n    by (rule CSP3_SRD_intro, simp_all add: csp_do_def closure rdes unrest)\n  show \"(AssignCSP_update domf updatef x k v) is CSP4\"\n    by (rule CSP4_tri_intro, simp_all add: csp_do_def closure rdes unrest, rel_auto)\nqed\n\nsubsection \\<open> State abstraction \\<close>\n\nlemma ref_unrest_abs_st [unrest]:\n  \"$ref \\<sharp> P \\<Longrightarrow> $ref \\<sharp> \\<langle>P\\<rangle>\\<^sub>S\"\n  \"$ref\\<acute> \\<sharp> P \\<Longrightarrow> $ref\\<acute> \\<sharp> \\<langle>P\\<rangle>\\<^sub>S\"\n  by (rel_simp)+\n  \nlemma NCSP_state_srea [closure]: \"P is NCSP \\<Longrightarrow> state 'a \\<bullet> P is NCSP\"\n  apply (rule NCSP_NSRD_intro)\n  apply (simp_all add: closure rdes)\n  apply (simp_all add: state_srea_def unrest closure)\ndone\n\nsubsection \\<open> Guards \\<close>\n\ndefinition GuardCSP ::\n  \"'\\<sigma> cond \\<Rightarrow>\n   ('\\<sigma>, '\\<phi>) action \\<Rightarrow>\n   ('\\<sigma>, '\\<phi>) action\"  where\n[upred_defs]: \"GuardCSP g A = \\<^bold>R\\<^sub>s((\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r pre\\<^sub>R(A)) \\<turnstile> ((\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> cmt\\<^sub>R(A)) \\<or> (\\<lceil>\\<not> g\\<rceil>\\<^sub>S\\<^sub><) \\<and> $tr\\<acute> =\\<^sub>u $tr \\<and> $wait\\<acute>))\"\n\nsyntax\n  \"_GuardCSP\" :: \"logic \\<Rightarrow> logic \\<Rightarrow> logic\" (infixr \"&\\<^sub>C\" 60)\n\ntranslations\n  \"_GuardCSP b P\" == \"CONST GuardCSP b P\"\n\nlemma Guard_tri_design:\n  \"g &\\<^sub>C P = \\<^bold>R\\<^sub>s((\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r pre\\<^sub>R P) \\<turnstile> (peri\\<^sub>R(P) \\<triangleleft> \\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<triangleright> ($tr\\<acute> =\\<^sub>u $tr)) \\<diamondop> (\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> post\\<^sub>R(P)))\"\nproof -\n  have \"(\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> cmt\\<^sub>R P \\<or> \\<lceil>\\<not>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> $tr\\<acute> =\\<^sub>u $tr \\<and> $wait\\<acute>) = (peri\\<^sub>R(P) \\<triangleleft> \\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<triangleright> ($tr\\<acute> =\\<^sub>u $tr)) \\<diamondop> (\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> post\\<^sub>R(P))\"\n    by (rel_auto)\n  thus ?thesis by (simp add: GuardCSP_def)\nqed\n\nlemma csp_do_cond_conj:\n  assumes \"P is CRR\"\n  shows \"(\\<lceil>b\\<rceil>\\<^sub>S\\<^sub>< \\<and> P) = \\<Phi>(b, id\\<^sub>s, \\<guillemotleft>[]\\<guillemotright>) ;; P\"\nproof -\n  have \"(\\<lceil>b\\<rceil>\\<^sub>S\\<^sub>< \\<and> CRR(P)) = \\<Phi>(b, id\\<^sub>s, \\<guillemotleft>[]\\<guillemotright>) ;; CRR(P)\"\n    by (rel_auto)\n  thus ?thesis\n    by (simp add: Healthy_if assms)\nqed\n  \nlemma Guard_rdes_def [rdes_def]:\n  assumes \"P is RR\" \"Q is CRR\" \"R is CRR\"\n  shows \"g &\\<^sub>C \\<^bold>R\\<^sub>s(P \\<turnstile> Q \\<diamondop> R) = \\<^bold>R\\<^sub>s (([g]\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r P) \\<turnstile> ((\\<Phi>(g, id\\<^sub>s, \\<guillemotleft>[]\\<guillemotright>) ;; Q) \\<or> \\<E>(\\<not>g,\\<guillemotleft>[]\\<guillemotright>,{}\\<^sub>u)) \\<diamondop> (\\<Phi>(g, id\\<^sub>s, \\<guillemotleft>[]\\<guillemotright>) ;; R))\"\n  (is \"?lhs = ?rhs\")\nproof -\n  have \"?lhs = \\<^bold>R\\<^sub>s ((\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r P) \\<turnstile> ((P \\<Rightarrow>\\<^sub>r Q) \\<triangleleft> \\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<triangleright> ($tr\\<acute> =\\<^sub>u $tr)) \\<diamondop> (\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> (P \\<Rightarrow>\\<^sub>r R)))\"\n    by (simp add: Guard_tri_design rdes assms closure)\n  also have \"... = \\<^bold>R\\<^sub>s (([g]\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r P) \\<turnstile> ((\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> Q) \\<or> \\<E>(\\<not>g,\\<guillemotleft>[]\\<guillemotright>,{}\\<^sub>u)) \\<diamondop> (\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> R))\"\n    by (rel_auto)\n  also have \"... = \\<^bold>R\\<^sub>s (([g]\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r P) \\<turnstile> ((\\<Phi>(g, id\\<^sub>s, \\<guillemotleft>[]\\<guillemotright>) ;; Q) \\<or> \\<E>(\\<not>g,\\<guillemotleft>[]\\<guillemotright>,{}\\<^sub>u)) \\<diamondop> (\\<Phi>(g, id\\<^sub>s, \\<guillemotleft>[]\\<guillemotright>) ;; R))\"\n    by (simp add: assms(2) assms(3) csp_do_cond_conj)\n  finally show ?thesis .\nqed\n\nlemma Guard_rdes_def':\n  assumes \"$ok\\<acute> \\<sharp> P\"\n  shows \"g &\\<^sub>C (\\<^bold>R\\<^sub>s(P \\<turnstile> Q)) = \\<^bold>R\\<^sub>s((\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r P) \\<turnstile> (\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> Q \\<or> \\<lceil>\\<not>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> $tr\\<acute> =\\<^sub>u $tr \\<and> $wait\\<acute>))\"\nproof -\n  have \"g &\\<^sub>C (\\<^bold>R\\<^sub>s(P \\<turnstile> Q)) = \\<^bold>R\\<^sub>s((\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r pre\\<^sub>R (\\<^bold>R\\<^sub>s (P \\<turnstile> Q))) \\<turnstile> (\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> cmt\\<^sub>R (\\<^bold>R\\<^sub>s (P \\<turnstile> Q)) \\<or> \\<lceil>\\<not>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> $tr\\<acute> =\\<^sub>u $tr \\<and> $wait\\<acute>))\"\n    by (simp add: GuardCSP_def)\n  also have \"... = \\<^bold>R\\<^sub>s((\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r R1(R2c(pre\\<^sub>s \\<dagger> P))) \\<turnstile> (\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> R1(R2c(cmt\\<^sub>s \\<dagger> (P \\<Rightarrow> Q))) \\<or>  \\<lceil>\\<not>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> $tr\\<acute> =\\<^sub>u $tr \\<and> $wait\\<acute>))\"\n    by (simp add: rea_pre_RHS_design rea_cmt_RHS_design)\n  also have \"... = \\<^bold>R\\<^sub>s((\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r R1(R2c(pre\\<^sub>s \\<dagger> P))) \\<turnstile> R1(R2c(\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> R1(R2c(cmt\\<^sub>s \\<dagger> (P \\<Rightarrow> Q))) \\<or> \\<lceil>\\<not>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> $tr\\<acute> =\\<^sub>u $tr \\<and> $wait\\<acute>)))\"\n    by (metis (no_types, lifting) RHS_design_export_R1 RHS_design_export_R2c)\n   also have \"... = \\<^bold>R\\<^sub>s((\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r R1(R2c(pre\\<^sub>s \\<dagger> P))) \\<turnstile> R1(R2c(\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> (cmt\\<^sub>s \\<dagger> (P \\<Rightarrow> Q)) \\<or> \\<lceil>\\<not>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> $tr\\<acute> =\\<^sub>u $tr \\<and> $wait\\<acute>)))\"\n     by (simp add: R1_R2c_commute R1_disj R1_extend_conj' R1_idem R2c_and R2c_disj R2c_idem)\n   also have \"... = \\<^bold>R\\<^sub>s((\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r R1(R2c(pre\\<^sub>s \\<dagger> P))) \\<turnstile> (\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> (cmt\\<^sub>s \\<dagger> (P \\<Rightarrow> Q)) \\<or> \\<lceil>\\<not>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> $tr\\<acute> =\\<^sub>u $tr \\<and> $wait\\<acute>))\"\n     by (metis (no_types, lifting) RHS_design_export_R1 RHS_design_export_R2c)\n   also have \"... = \\<^bold>R\\<^sub>s((\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r R1(R2c(pre\\<^sub>s \\<dagger> P))) \\<turnstile> cmt\\<^sub>s \\<dagger> (\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> (cmt\\<^sub>s \\<dagger> (P \\<Rightarrow> Q)) \\<or> \\<lceil>\\<not>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> $tr\\<acute> =\\<^sub>u $tr \\<and> $wait\\<acute>))\"\n     by (simp add: rdes_export_cmt)\n   also have \"... = \\<^bold>R\\<^sub>s((\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r R1(R2c(pre\\<^sub>s \\<dagger> P))) \\<turnstile> cmt\\<^sub>s \\<dagger> (\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> (P \\<Rightarrow> Q) \\<or> \\<lceil>\\<not>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> $tr\\<acute> =\\<^sub>u $tr \\<and> $wait\\<acute>))\"\n     by (simp add: usubst)\n   also have \"... = \\<^bold>R\\<^sub>s((\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r R1(R2c(pre\\<^sub>s \\<dagger> P))) \\<turnstile> (\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> (P \\<Rightarrow> Q) \\<or> \\<lceil>\\<not>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> $tr\\<acute> =\\<^sub>u $tr \\<and> $wait\\<acute>))\"\n     by (simp add: rdes_export_cmt)\n   also from assms have \"... = \\<^bold>R\\<^sub>s((\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r (pre\\<^sub>s \\<dagger> P)) \\<turnstile> (\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> (P \\<Rightarrow> Q) \\<or> \\<lceil>\\<not>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> $tr\\<acute> =\\<^sub>u $tr \\<and> $wait\\<acute>))\"\n     by (rel_auto)\n   also have \"... = \\<^bold>R\\<^sub>s((\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r pre\\<^sub>s \\<dagger> P)\\<lbrakk>true,false/$ok,$wait\\<rbrakk> \\<turnstile> (\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> (P \\<Rightarrow> Q) \\<or> \\<lceil>\\<not>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> $tr\\<acute> =\\<^sub>u $tr \\<and> $wait\\<acute>))\"\n     by (simp add: rdes_export_pre)\n   also from assms have \"... = \\<^bold>R\\<^sub>s((\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r P)\\<lbrakk>true,false/$ok,$wait\\<rbrakk> \\<turnstile> (\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> (P \\<Rightarrow> Q) \\<or> \\<lceil>\\<not>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> $tr\\<acute> =\\<^sub>u $tr \\<and> $wait\\<acute>))\"\n     by (rel_auto)\n   also from assms have \"... = \\<^bold>R\\<^sub>s((\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r P) \\<turnstile> (\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> (P \\<Rightarrow> Q) \\<or> \\<lceil>\\<not>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> $tr\\<acute> =\\<^sub>u $tr \\<and> $wait\\<acute>))\"\n     by (simp add: rdes_export_pre)\n   also have \"... = \\<^bold>R\\<^sub>s((\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r P) \\<turnstile> (\\<lceil>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> Q \\<or> \\<lceil>\\<not>g\\<rceil>\\<^sub>S\\<^sub>< \\<and> $tr\\<acute> =\\<^sub>u $tr \\<and> $wait\\<acute>))\"\n     by (rule cong[of \"\\<^bold>R\\<^sub>s\" \"\\<^bold>R\\<^sub>s\"], simp, rel_auto)\n   finally show ?thesis .\nqed\n\nlemma CSP_Guard [closure]: \"b &\\<^sub>C P is CSP\"\n  by (simp add: GuardCSP_def, rule RHS_design_is_SRD, simp_all add: unrest)\n\nlemma preR_Guard [rdes]: \"P is CSP \\<Longrightarrow> pre\\<^sub>R(b &\\<^sub>C P) = ([b]\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r pre\\<^sub>R P)\"\n  by (simp add: Guard_tri_design rea_pre_RHS_design usubst unrest R2c_preR R2c_lift_state_pre\n      R2c_rea_impl R1_rea_impl R1_preR Healthy_if, rel_auto)\n\nlemma periR_Guard [rdes]:\n  assumes \"P is NCSP\"\n  shows \"peri\\<^sub>R(b &\\<^sub>C P) = (peri\\<^sub>R P \\<triangleleft> b \\<triangleright>\\<^sub>R \\<E>(true,\\<guillemotleft>[]\\<guillemotright>,{}\\<^sub>u))\"\nproof -\n  have \"peri\\<^sub>R(b &\\<^sub>C P) = ((\\<lceil>b\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r pre\\<^sub>R P) \\<Rightarrow>\\<^sub>r (peri\\<^sub>R P \\<triangleleft> \\<lceil>b\\<rceil>\\<^sub>S\\<^sub>< \\<triangleright> ($tr\\<acute> =\\<^sub>u $tr)))\"\n    by (simp add: assms Guard_tri_design rea_peri_RHS_design usubst unrest R1_rea_impl R2c_rea_not \n        R2c_rea_impl R2c_preR R2c_periR R2c_tr'_minus_tr R2c_lift_state_pre R2c_condr closure\n        Healthy_if R1_cond R1_tr'_eq_tr)\n  also have \"... = ((pre\\<^sub>R P \\<Rightarrow>\\<^sub>r peri\\<^sub>R P) \\<triangleleft> \\<lceil>b\\<rceil>\\<^sub>S\\<^sub>< \\<triangleright> ($tr\\<acute> =\\<^sub>u $tr))\"\n    by (rel_auto)\n  also have \"... = (peri\\<^sub>R P \\<triangleleft> \\<lceil>b\\<rceil>\\<^sub>S\\<^sub>< \\<triangleright> ($tr\\<acute> =\\<^sub>u $tr))\"      \n    by (simp add: SRD_peri_under_pre add: unrest closure assms)\n  finally show ?thesis\n    by rel_auto\nqed\n      \nlemma postR_Guard [rdes]:\n  assumes \"P is NCSP\"\n  shows \"post\\<^sub>R(b &\\<^sub>C P) = ([b]\\<^sub>S\\<^sub>< \\<and> post\\<^sub>R P)\"\nproof -\n  have \"post\\<^sub>R(b &\\<^sub>C P) = ((\\<lceil>b\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r pre\\<^sub>R P) \\<Rightarrow>\\<^sub>r (\\<lceil>b\\<rceil>\\<^sub>S\\<^sub>< \\<and> post\\<^sub>R P))\"\n    by (simp add: Guard_tri_design rea_post_RHS_design usubst unrest R2c_rea_not R2c_and R2c_rea_impl\n        R2c_preR R2c_postR R2c_tr'_minus_tr R2c_lift_state_pre R2c_condr R1_rea_impl R1_extend_conj'\n        R1_post_SRD closure assms)\n  also have \"... = (\\<lceil>b\\<rceil>\\<^sub>S\\<^sub>< \\<and> (pre\\<^sub>R P \\<Rightarrow>\\<^sub>r post\\<^sub>R P))\"\n    by (rel_auto)\n  also have \"... = (\\<lceil>b\\<rceil>\\<^sub>S\\<^sub>< \\<and> post\\<^sub>R P)\"\n    by (simp add: SRD_post_under_pre add: unrest closure assms)\n  also have \"... = ([b]\\<^sub>S\\<^sub>< \\<and> post\\<^sub>R P)\"\n    by (metis CSP_Guard R1_extend_conj R1_post_SRD calculation rea_st_cond_def)      \n  finally show ?thesis .\nqed\n        \nlemma CSP3_Guard [closure]:\n  assumes \"P is CSP\" \"P is CSP3\"\n  shows \"b &\\<^sub>C P is CSP3\"\nproof -\n  from assms have 1:\"$ref \\<sharp> P\\<lbrakk>false/$wait\\<rbrakk>\"\n    by (simp add: CSP_Guard CSP3_iff)\n  hence \"$ref \\<sharp> pre\\<^sub>R (P\\<lbrakk>0/$tr\\<rbrakk>)\" \"$ref \\<sharp> pre\\<^sub>R P\" \"$ref \\<sharp> cmt\\<^sub>R P\"\n    by (pred_blast)+\n  hence \"$ref \\<sharp> (b &\\<^sub>C P)\\<lbrakk>false/$wait\\<rbrakk>\"\n    by (simp add: CSP3_iff GuardCSP_def RHS_def R1_def R2c_def R2s_def R3h_def design_def unrest usubst)\n  thus ?thesis\n    by (metis CSP3_intro CSP_Guard)\nqed\n\nlemma CSP4_Guard [closure]:\n  assumes \"P is NCSP\"\n  shows \"b &\\<^sub>C P is CSP4\"\nproof (rule CSP4_tri_intro[OF CSP_Guard])\n  show \"(\\<not>\\<^sub>r pre\\<^sub>R (b &\\<^sub>C P)) ;; R1 true = (\\<not>\\<^sub>r pre\\<^sub>R (b &\\<^sub>C P))\"\n  proof -\n    have a:\"(\\<not>\\<^sub>r pre\\<^sub>R P) ;; R1 true = (\\<not>\\<^sub>r pre\\<^sub>R P)\"\n      by (simp add: CSP4_neg_pre_unit assms closure)\n    have \"(\\<not>\\<^sub>r ([b]\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r pre\\<^sub>R P)) ;; R1 true = (\\<not>\\<^sub>r ([b]\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r pre\\<^sub>R P))\"\n    proof -\n      have 1:\"(\\<not>\\<^sub>r ([b]\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r pre\\<^sub>R P)) = ([b]\\<^sub>S\\<^sub>< \\<and> (\\<not>\\<^sub>r pre\\<^sub>R P))\"\n        by (rel_auto)\n      also have 2:\"... = ([b]\\<^sub>S\\<^sub>< \\<and> ((\\<not>\\<^sub>r pre\\<^sub>R P) ;; R1 true))\"\n        by (simp add: a)\n      also have 3:\"... = (\\<not>\\<^sub>r ([b]\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r pre\\<^sub>R P)) ;; R1 true\"\n        by (rel_auto)\n      finally show ?thesis ..\n    qed\n    thus ?thesis\n      by (simp add: preR_Guard periR_Guard NSRD_CSP4_intro closure assms unrest)\n  qed\n  show \"$st\\<acute> \\<sharp> peri\\<^sub>R (b &\\<^sub>C P)\"\n    by (simp add: preR_Guard periR_Guard NSRD_CSP4_intro closure assms unrest)\n  show \"$ref\\<acute> \\<sharp> post\\<^sub>R (b &\\<^sub>C P)\"\n    by (simp add: preR_Guard postR_Guard NSRD_CSP4_intro closure assms unrest)\nqed\n\nlemma NCSP_Guard [closure]:\n  assumes \"P is NCSP\"\n  shows \"b &\\<^sub>C P is NCSP\"\nproof -\n  have \"P is CSP\"\n    using NCSP_implies_CSP assms by blast\n  then show ?thesis\n    by (metis (no_types) CSP3_Guard CSP3_commutes_CSP4 CSP4_Guard CSP4_Idempotent CSP_Guard Healthy_Idempotent Healthy_def NCSP_def assms comp_apply)\nqed\n\nlemma Productive_Guard [closure]:\n  assumes \"P is CSP\" \"P is Productive\" \"$wait\\<acute> \\<sharp> pre\\<^sub>R(P)\"\n  shows \"b &\\<^sub>C P is Productive\"\nproof -\n  have \"b &\\<^sub>C P = b &\\<^sub>C \\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> peri\\<^sub>R(P) \\<diamondop> (post\\<^sub>R(P) \\<and> $tr <\\<^sub>u $tr\\<acute>))\"\n    by (metis Healthy_def Productive_form assms(1) assms(2))\n  also have \"... =\n        \\<^bold>R\\<^sub>s ((\\<lceil>b\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r pre\\<^sub>R P) \\<turnstile>\n          ((pre\\<^sub>R P \\<Rightarrow>\\<^sub>r peri\\<^sub>R P) \\<triangleleft> \\<lceil>b\\<rceil>\\<^sub>S\\<^sub>< \\<triangleright> ($tr\\<acute> =\\<^sub>u $tr)) \\<diamondop> (\\<lceil>b\\<rceil>\\<^sub>S\\<^sub>< \\<and> (pre\\<^sub>R P \\<Rightarrow>\\<^sub>r post\\<^sub>R P \\<and> $tr\\<acute> >\\<^sub>u $tr)))\"\n    by (simp add: Guard_tri_design rea_pre_RHS_design rea_peri_RHS_design rea_post_RHS_design unrest assms\n        usubst R1_preR Healthy_if R1_rea_impl R1_peri_SRD R1_extend_conj' R2c_preR R2c_not R2c_rea_impl \n        R2c_periR R2c_postR R2c_and R2c_tr_less_tr' R1_tr_less_tr')             \n  also have \"... = \\<^bold>R\\<^sub>s ((\\<lceil>b\\<rceil>\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r pre\\<^sub>R P) \\<turnstile> (peri\\<^sub>R P \\<triangleleft> \\<lceil>b\\<rceil>\\<^sub>S\\<^sub>< \\<triangleright> ($tr\\<acute> =\\<^sub>u $tr)) \\<diamondop> ((\\<lceil>b\\<rceil>\\<^sub>S\\<^sub>< \\<and> post\\<^sub>R P) \\<and> $tr\\<acute> >\\<^sub>u $tr))\"\n    by (rel_auto)\n  also have \"... = Productive(b &\\<^sub>C P)\"\n    by (simp add: Productive_def Guard_tri_design RHS_tri_design_par unrest)\n  finally show ?thesis\n    by (simp add: Healthy_def')\nqed\n\nlemma Guard_refines_sinv: \n  assumes \"P is NCSP\" \"sinv\\<^sub>R(b) \\<sqsubseteq> P\"\n  shows \"sinv\\<^sub>R(b) \\<sqsubseteq> g &\\<^sub>C P\"\nproof -\n  from assms\n  have \"\\<^bold>R\\<^sub>s([b]\\<^sub>S\\<^sub>< \\<turnstile> R1 true \\<diamondop> [b]\\<^sub>S\\<^sub>>) \\<sqsubseteq> \\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> peri\\<^sub>R(P) \\<diamondop> post\\<^sub>R(P))\"\n    by (simp add: rdes_def NCSP_implies_CSP SRD_reactive_tri_design)\n  thus ?thesis\n    apply (simp add: RHS_tri_design_refine' closure unrest assms)\n    apply (safe)\n    apply (rdes_refine cls: assms(1))\n    done\nqed\n\nsubsection \\<open> Basic events\\<close>\n\ndefinition do\\<^sub>u ::\n  \"('\\<phi>, '\\<sigma>) uexpr \\<Rightarrow> ('\\<sigma>, '\\<phi>) action\" where\n[upred_defs]: \"do\\<^sub>u e = (($tr\\<acute> =\\<^sub>u $tr \\<and> \\<lceil>e\\<rceil>\\<^sub>S\\<^sub>< \\<notin>\\<^sub>u $ref\\<acute>) \\<triangleleft> $wait\\<acute> \\<triangleright> U($tr\\<acute> = $tr @ [\\<lceil>e\\<rceil>\\<^sub>S\\<^sub><] \\<and> $st\\<acute> = $st))\"\n\ndefinition DoCSP :: \"('\\<phi>, '\\<sigma>) uexpr \\<Rightarrow> ('\\<sigma>, '\\<phi>) action\" (\"do\\<^sub>C\") where\n[upred_defs]: \"DoCSP a = \\<^bold>R\\<^sub>s(true \\<turnstile> do\\<^sub>u a)\"\n\nlemma R1_DoAct: \"R1(do\\<^sub>u(a)) = do\\<^sub>u(a)\"\n  by (rel_auto)\n\nlemma R2c_DoAct: \"R2c(do\\<^sub>u(a)) = do\\<^sub>u(a)\"\n  by (rel_auto)\n\nlemma DoCSP_alt_def: \"do\\<^sub>C(a) = R3h(CSP1($ok\\<acute> \\<and> do\\<^sub>u(a)))\"\n  apply (simp add: DoCSP_def RHS_def design_def impl_alt_def  R1_R3h_commute R2c_R3h_commute R2c_disj\n                   R2c_not R2c_ok R2c_ok' R2c_and R2c_DoAct R1_disj R1_extend_conj' R1_DoAct)\n  apply (rel_auto)\ndone\n\nlemma DoAct_unrests [unrest]:\n  \"$ok \\<sharp> do\\<^sub>u(a)\" \"$wait \\<sharp> do\\<^sub>u(a)\"\n  by (pred_auto)+\n\nlemma DoCSP_RHS_tri [rdes_def]:\n  \"do\\<^sub>C(a) = \\<^bold>R\\<^sub>s(true\\<^sub>r \\<turnstile> (\\<E>(true,\\<guillemotleft>[]\\<guillemotright>,{a}\\<^sub>u) \\<diamondop> \\<Phi>(true,id\\<^sub>s,U([a]))))\"\n  by (simp add: DoCSP_def do\\<^sub>u_def wait'_cond_def, rel_auto)\n\nlemma CSP_DoCSP [closure]: \"do\\<^sub>C(a) is CSP\"\n  by (simp add: DoCSP_def do\\<^sub>u_def RHS_design_is_SRD unrest)\n\nlemma preR_DoCSP [rdes]: \"pre\\<^sub>R(do\\<^sub>C(a)) = true\\<^sub>r\"\n  by (simp add: DoCSP_def rea_pre_RHS_design unrest usubst R2c_true)\n\nlemma periR_DoCSP [rdes]: \"peri\\<^sub>R(do\\<^sub>C(a)) = \\<E>(true,\\<guillemotleft>[]\\<guillemotright>,{a}\\<^sub>u)\"\n  by (rel_auto) \n\nlemma postR_DoCSP [rdes]: \"post\\<^sub>R(do\\<^sub>C(a)) = \\<Phi>(true,id\\<^sub>s,U([a]))\"\n  by (rel_auto)\n\nlemma CSP3_DoCSP [closure]: \"do\\<^sub>C(a) is CSP3\"\n  by (rule CSP3_intro[OF CSP_DoCSP])\n     (simp add: DoCSP_def do\\<^sub>u_def RHS_def design_def R1_def R2c_def R2s_def R3h_def unrest usubst)\n\nlemma CSP4_DoCSP [closure]: \"do\\<^sub>C(a) is CSP4\"\n  by (rule CSP4_tri_intro[OF CSP_DoCSP], simp_all add: preR_DoCSP periR_DoCSP postR_DoCSP unrest)\n\nlemma NCSP_DoCSP [closure]: \"do\\<^sub>C(a) is NCSP\"\n  by (metis CSP3_DoCSP CSP4_DoCSP CSP_DoCSP Healthy_def NCSP_def comp_apply)\n\nlemma Productive_DoCSP [closure]:\n  \"(do\\<^sub>C a :: ('\\<sigma>, '\\<psi>) action) is Productive\"\nproof -\n  have \"((\\<Phi>(true,id\\<^sub>s,U([a])) \\<and> $tr\\<acute> >\\<^sub>u $tr) :: ('\\<sigma>, '\\<psi>) action)\n        = (\\<Phi>(true,id\\<^sub>s,U([a])))\"\n    by (rel_auto, simp add: Prefix_Order.strict_prefixI')\n  hence \"Productive(do\\<^sub>C a) = do\\<^sub>C a\"\n    by (simp add: Productive_RHS_design_form DoCSP_RHS_tri unrest)\n  thus ?thesis\n    by (simp add: Healthy_def)\nqed\n\nlemma PCSP_DoCSP [closure]:\n  \"(do\\<^sub>C a :: ('\\<sigma>, '\\<psi>) action) is PCSP\"\n  by (simp add: Healthy_comp NCSP_DoCSP Productive_DoCSP)\n\nlemma wp_rea_DoCSP_lemma:\n  fixes P :: \"('\\<sigma>, '\\<phi>) action\"\n  assumes \"$ok \\<sharp> P\" \"$wait \\<sharp> P\"\n  shows \"U($tr\\<acute> = $tr @ [\\<lceil>a\\<rceil>\\<^sub>S\\<^sub><] \\<and> $st\\<acute> = $st) ;; P = (\\<exists> $ref \\<bullet> P\\<lbrakk>U($tr @ [\\<lceil>a\\<rceil>\\<^sub>S\\<^sub><])/$tr\\<rbrakk>)\"\n  using assms\n  by (rel_auto, meson)\n\nlemma wp_rea_DoCSP:\n  assumes \"P is NCSP\"\n  shows \"U($tr\\<acute> = $tr @ [\\<lceil>a\\<rceil>\\<^sub>S\\<^sub><] \\<and> $st\\<acute> = $st) wp\\<^sub>r pre\\<^sub>R P = \n         (\\<not>\\<^sub>r (\\<not>\\<^sub>r pre\\<^sub>R P)\\<lbrakk>U($tr @ [\\<lceil>a\\<rceil>\\<^sub>S\\<^sub><])/$tr\\<rbrakk>)\"\n  by (simp add: wp_rea_def wp_rea_DoCSP_lemma unrest usubst ex_unrest assms closure)     \n\nlemma wp_rea_DoCSP_alt:\n  assumes \"P is NCSP\"\n  shows \"U($tr\\<acute> = $tr @ [\\<lceil>a\\<rceil>\\<^sub>S\\<^sub><] \\<and> $st\\<acute> = $st) wp\\<^sub>r pre\\<^sub>R P = \n         U($tr\\<acute> \\<ge> $tr @ [\\<lceil>a\\<rceil>\\<^sub>S\\<^sub><] \\<Rightarrow>\\<^sub>r (pre\\<^sub>R P)\\<lbrakk>$tr @ [\\<lceil>a\\<rceil>\\<^sub>S\\<^sub><]/$tr\\<rbrakk>)\"  \n  by (simp add: wp_rea_DoCSP assms rea_not_def R1_def usubst unrest, rel_auto)\n\nlemma DoCSP_refine_sinv: \"sinv\\<^sub>R(b) \\<sqsubseteq> do\\<^sub>C(a)\"\n  by (rdes_refine)\n\nsubsection \\<open> Event prefix \\<close>\n\ndefinition PrefixCSP ::\n  \"('\\<phi>, '\\<sigma>) uexpr \\<Rightarrow>\n  ('\\<sigma>, '\\<phi>) action \\<Rightarrow>\n  ('\\<sigma>, '\\<phi>) action\" (\"_ \\<rightarrow>\\<^sub>C _\" [81, 80] 80) where\n[upred_defs]: \"PrefixCSP a P = (do\\<^sub>C(a) ;; CSP(P))\"\n\nabbreviation \"OutputCSP c v P \\<equiv> PrefixCSP (c\\<cdot>v)\\<^sub>u P\"\n\nlemma CSP_PrefixCSP [closure]: \"PrefixCSP a P is CSP\"\n  by (simp add: PrefixCSP_def closure)\n\nlemma CSP3_PrefixCSP [closure]:\n  \"PrefixCSP a P is CSP3\"\n  by (metis (no_types, opaque_lifting) CSP3_DoCSP CSP3_def Healthy_def PrefixCSP_def seqr_assoc)\n\nlemma CSP4_PrefixCSP [closure]:\n  assumes \"P is CSP\" \"P is CSP4\"\n  shows \"PrefixCSP a P is CSP4\"\n  by (metis (no_types, opaque_lifting) CSP4_def Healthy_def PrefixCSP_def assms(1) assms(2) seqr_assoc)\n\nlemma NCSP_PrefixCSP [closure]:\n  assumes \"P is NCSP\"\n  shows \"PrefixCSP a P is NCSP\"\n  by (metis (no_types, opaque_lifting) CSP3_PrefixCSP CSP3_commutes_CSP4 CSP4_Idempotent CSP4_PrefixCSP\n            CSP_PrefixCSP Healthy_Idempotent Healthy_def NCSP_def NCSP_implies_CSP assms comp_apply)\n\nlemma Productive_PrefixCSP [closure]: \"P is NCSP \\<Longrightarrow> PrefixCSP a P is Productive\"\n  by (simp add: Healthy_if NCSP_DoCSP NCSP_implies_NSRD NSRD_is_SRD PrefixCSP_def Productive_DoCSP Productive_seq_1)\n\nlemma PCSP_PrefixCSP [closure]: \"P is NCSP \\<Longrightarrow> PrefixCSP a P is PCSP\"\n  by (simp add: Healthy_comp NCSP_PrefixCSP Productive_PrefixCSP)\n  \nlemma PrefixCSP_Guarded [closure]: \"Guarded (PrefixCSP a)\"\nproof -\n  have \"PrefixCSP a = (\\<lambda> X. do\\<^sub>C(a) ;; CSP(X))\"\n    by (simp add: fun_eq_iff PrefixCSP_def)\n  thus ?thesis\n    using Guarded_if_Productive NCSP_DoCSP NCSP_implies_NSRD Productive_DoCSP by auto\nqed\n\nlemma PrefixCSP_type [closure]: \"PrefixCSP a \\<in> \\<lbrakk>H\\<rbrakk>\\<^sub>H \\<rightarrow> \\<lbrakk>CSP\\<rbrakk>\\<^sub>H\"\n  using CSP_PrefixCSP by blast\n\nlemma PrefixCSP_Continuous [closure]: \"Continuous (PrefixCSP a)\"\n  by (simp add: Continuous_def PrefixCSP_def ContinuousD[OF SRD_Continuous] seq_Sup_distl)\n\nlemma PrefixCSP_RHS_tri_lemma1:\n  \"R1 (R2s (U($tr\\<acute> = $tr @ [\\<lceil>a\\<rceil>\\<^sub>S\\<^sub><]) \\<and> \\<lceil>II\\<rceil>\\<^sub>R)) = (U($tr\\<acute> = $tr @ [\\<lceil>a\\<rceil>\\<^sub>S\\<^sub><]) \\<and> \\<lceil>II\\<rceil>\\<^sub>R)\"\n  by (rel_auto)\n\nlemma PrefixCSP_RHS_tri_lemma2:\n  fixes P :: \"('\\<sigma>, '\\<phi>) action\"\n  assumes \"$ok \\<sharp> P\" \"$wait \\<sharp> P\"\n  shows \"(U($tr\\<acute> = $tr @ [\\<lceil>a\\<rceil>\\<^sub>S\\<^sub><] \\<and> $st\\<acute> = $st) \\<and> \\<not> $wait\\<acute>) ;; P = (\\<exists> $ref \\<bullet> P\\<lbrakk>U($tr @ [\\<lceil>a\\<rceil>\\<^sub>S\\<^sub><])/$tr\\<rbrakk>)\"\n  using assms\n  by (rel_auto, meson, fastforce)\n\nlemma tr_extend_seqr:\n  fixes P :: \"('\\<sigma>, '\\<phi>) action\"\n  assumes \"$ok \\<sharp> P\" \"$wait \\<sharp> P\" \"$ref \\<sharp> P\"\n  shows \"U($tr\\<acute> = $tr @ [\\<lceil>a\\<rceil>\\<^sub>S\\<^sub><] \\<and> $st\\<acute> = $st) ;; P = P\\<lbrakk>U($tr @ [\\<lceil>a\\<rceil>\\<^sub>S\\<^sub><])/$tr\\<rbrakk>\"\n  using assms by (simp add: wp_rea_DoCSP_lemma assms unrest ex_unrest)\n          \nlemma trace_ext_R1_closed [closure]: \"P is R1 \\<Longrightarrow> P\\<lbrakk>$tr ^\\<^sub>u e/$tr\\<rbrakk> is R1\"\n  by (rel_blast)\n    \nlemma preR_PrefixCSP_NCSP [rdes]:\n  assumes \"P is NCSP\"\n  shows \"pre\\<^sub>R(PrefixCSP a P) = (\\<Phi>(true,id\\<^sub>s,U([a])) wp\\<^sub>r pre\\<^sub>R P)\"\n  by (simp add: PrefixCSP_def assms closure rdes rpred Healthy_if wp usubst unrest)\n\n(*\nlemma periR_PrefixCSP [rdes]:\n  assumes \"P is NCSP\"\n  shows \"peri\\<^sub>R(PrefixCSP a P) = (\\<E>(true,\\<guillemotleft>[]\\<guillemotright>,{a}\\<^sub>u) \\<or> (peri\\<^sub>R P)\\<lbrakk>\\<langle>a\\<rangle>\\<rbrakk>\\<^sub>t)\"\nproof -\n  have \"peri\\<^sub>R(PrefixCSP a P) =  peri\\<^sub>R (do\\<^sub>C a ;; P)\"\n    by (simp add: PrefixCSP_def closure assms Healthy_if)\n  also have \"... = undefined\"\n    apply (simp add: rdes closure assms rpred)\n  also have \"... = ((\\<Phi>(true,id,\\<langle>a\\<rangle>) wp\\<^sub>r pre\\<^sub>R P) \\<Rightarrow>\\<^sub>r $tr\\<acute> =\\<^sub>u $tr \\<and> \\<lceil>a\\<rceil>\\<^sub>S\\<^sub>< \\<notin>\\<^sub>u $ref\\<acute> \\<or> peri\\<^sub>R P\\<lbrakk>\\<langle>a\\<rangle>\\<rbrakk>\\<^sub>t)\"\n    by (simp add: assms NSRD_CSP4_intro csp_enable_tr_empty closure rdes unrest ex_unrest usubst rpred csp_do_comp wp)\n  also have \"... = (\\<E>(true,\\<guillemotleft>[]\\<guillemotright>,{a}\\<^sub>u) \\<or> ((\\<Phi>(true,id,\\<langle>a\\<rangle>) wp\\<^sub>r pre\\<^sub>R P) \\<Rightarrow>\\<^sub>r peri\\<^sub>R P\\<lbrakk>\\<langle>a\\<rangle>\\<rbrakk>\\<^sub>t))\"\n    by (rel_auto)\n  also have \"... = (\\<E>(true,\\<guillemotleft>[]\\<guillemotright>,{a}\\<^sub>u) \\<or> ((pre\\<^sub>R(P) \\<Rightarrow>\\<^sub>r peri\\<^sub>R P)\\<lbrakk>\\<langle>a\\<rangle>\\<rbrakk>\\<^sub>t))\"\n    by (rel_auto)\n  also have \"... = (\\<E>(true,\\<guillemotleft>[]\\<guillemotright>,{a}\\<^sub>u) \\<or> (peri\\<^sub>R P)\\<lbrakk>\\<langle>a\\<rangle>\\<rbrakk>\\<^sub>t)\"      \n    by (simp add: SRD_peri_under_pre assms closure unrest)\n  finally show ?thesis .\nqed\n  \nlemma postR_PrefixCSP [rdes]:\n  assumes \"P is NCSP\"\n  shows \"post\\<^sub>R(PrefixCSP a P) = (post\\<^sub>R P)\\<lbrakk>\\<langle>a\\<rangle>\\<rbrakk>\\<^sub>t\"\nproof -\n  have \"post\\<^sub>R(PrefixCSP a P) = ((\\<I>(true,\\<langle>a\\<rangle>) \\<Rightarrow>\\<^sub>r (pre\\<^sub>R P)\\<lbrakk>\\<langle>a\\<rangle>\\<rbrakk>\\<^sub>t) \\<Rightarrow>\\<^sub>r (post\\<^sub>R P)\\<lbrakk>\\<langle>a\\<rangle>\\<rbrakk>\\<^sub>t)\"\n    by (simp add: PrefixCSP_def assms Healthy_if) \n       (simp add: assms Healthy_if wp closure rdes rpred wp_rea_DoCSP_lemma unrest  ex_unrest usubst)\n  also have \"... = (\\<I>(true,\\<langle>a\\<rangle>) \\<and> (pre\\<^sub>R P \\<Rightarrow>\\<^sub>r post\\<^sub>R P)\\<lbrakk>\\<langle>a\\<rangle>\\<rbrakk>\\<^sub>t)\"\n    by (rel_auto)\n  also have \"... = (\\<I>(true,\\<langle>a\\<rangle>) \\<and> (post\\<^sub>R P)\\<lbrakk>\\<langle>a\\<rangle>\\<rbrakk>\\<^sub>t)\"      \n    by (simp add: SRD_post_under_pre assms closure unrest)\n  also have \"... = (post\\<^sub>R P)\\<lbrakk>\\<langle>a\\<rangle>\\<rbrakk>\\<^sub>t\"\n    by (rel_auto)\n  finally show ?thesis .\nqed\n*)  \n    \nlemma PrefixCSP_RHS_tri:\n  assumes \"P is NCSP\"\n  shows \"PrefixCSP a P = \\<^bold>R\\<^sub>s (\\<Phi>(true,id\\<^sub>s,U([a])) wp\\<^sub>r pre\\<^sub>R P \\<turnstile> (\\<E>(true,\\<guillemotleft>[]\\<guillemotright>, {a}\\<^sub>u) \\<or> \\<Phi>(true,id\\<^sub>s,U([a])) ;; peri\\<^sub>R P) \\<diamondop> \\<Phi>(true,id\\<^sub>s,U([a])) ;; post\\<^sub>R P)\"\n  by (simp add: PrefixCSP_def Healthy_if unrest assms closure NSRD_composition_wp rdes rpred usubst wp)\n\ntext \\<open> For prefix, we can chose whether to propagate the assumptions or not, hence there\n  are two laws. \\<close>\n    \nlemma PrefixCSP_rdes_def_1 [rdes_def]:\n  assumes \"P is CRC\" \"Q is CRR\" \"R is CRR\"\n          \"$st\\<acute> \\<sharp> Q\" \"$ref\\<acute> \\<sharp> R\"\n        shows \"PrefixCSP a (\\<^bold>R\\<^sub>s(P \\<turnstile> Q \\<diamondop> R)) = \n               \\<^bold>R\\<^sub>s (\\<Phi>(true,id\\<^sub>s,U([a])) wp\\<^sub>r P \\<turnstile> (\\<E>(true,\\<guillemotleft>[]\\<guillemotright>, {a}\\<^sub>u) \\<or> \\<Phi>(true,id\\<^sub>s,U([a])) ;; Q) \\<diamondop> \\<Phi>(true,id\\<^sub>s,U([a])) ;; R)\"\n  by (simp add: PrefixCSP_def Healthy_if assms closure, rdes_simp cls: assms)\n\n(*\nlemma PrefixCSP_rdes_def_2:\n  assumes \"P is CRC\" \"Q is CRR\" \"R is CRR\"\n          \"$st\\<acute> \\<sharp> Q\" \"$ref\\<acute> \\<sharp> R\"\n  shows \"PrefixCSP a (\\<^bold>R\\<^sub>s(P \\<turnstile> Q \\<diamondop> R)) = \\<^bold>R\\<^sub>s((\\<I>(true,\\<langle>a\\<rangle>) \\<Rightarrow>\\<^sub>r P\\<lbrakk>\\<langle>a\\<rangle>\\<rbrakk>\\<^sub>t) \\<turnstile> (\\<E>(true,\\<guillemotleft>[]\\<guillemotright>, {a}\\<^sub>u) \\<or> (P\\<and>Q)\\<lbrakk>\\<langle>a\\<rangle>\\<rbrakk>\\<^sub>t) \\<diamondop> (P\\<and>R)\\<lbrakk>\\<langle>a\\<rangle>\\<rbrakk>\\<^sub>t)\"\n  apply (subst PrefixCSP_RHS_tri)\n   apply (rule NCSP_rdes_intro)\n       apply (simp_all add: assms rdes closure)\n  apply (rel_auto)\n  done\n*)\n\nsubsection \\<open> Guarded external choice \\<close>\n\nabbreviation GuardedChoiceCSP :: \"'\\<theta> set \\<Rightarrow> ('\\<theta> \\<Rightarrow> ('\\<sigma>, '\\<theta>) action) \\<Rightarrow> ('\\<sigma>, '\\<theta>) action\" where\n\"GuardedChoiceCSP A P \\<equiv> (\\<box> x\\<in>A \\<bullet> PrefixCSP \\<guillemotleft>x\\<guillemotright> (P(x)))\"\n\nsyntax\n  \"_GuardedChoiceCSP\" :: \"logic \\<Rightarrow> logic \\<Rightarrow> logic \\<Rightarrow> logic\" (\"\\<box> _ \\<in> _ \\<^bold>\\<rightarrow> _\" [0,0,85] 86)\n\ntranslations\n  \"\\<box> x\\<in>A \\<^bold>\\<rightarrow> P\" == \"CONST GuardedChoiceCSP A (\\<lambda> x. P)\"\n\nlemma GuardedChoiceCSP [rdes_def]:\n  assumes \"\\<And> x. P(x) is NCSP\" \"A \\<noteq> {}\"\n  shows \"(\\<box> x\\<in>A \\<^bold>\\<rightarrow> P(x)) =\n             \\<^bold>R\\<^sub>s ((\\<Squnion> x \\<in> A \\<bullet> \\<Phi>(true,id\\<^sub>s,\\<guillemotleft>[x]\\<guillemotright>) wp\\<^sub>r pre\\<^sub>R (P x)) \\<turnstile>\n                 ((\\<Squnion> x \\<in> A \\<bullet> \\<E>(true,\\<guillemotleft>[]\\<guillemotright>, {\\<guillemotleft>x\\<guillemotright>}\\<^sub>u)) \\<triangleleft> $tr\\<acute> =\\<^sub>u $tr \\<triangleright> (\\<Sqinter> x \\<in> A \\<bullet> \\<Phi>(true,id\\<^sub>s,\\<guillemotleft>[x]\\<guillemotright>) ;; peri\\<^sub>R (P x))) \\<diamondop>\n                  (\\<Sqinter> x \\<in> A \\<bullet> \\<Phi>(true,id\\<^sub>s,\\<guillemotleft>[x]\\<guillemotright>) ;; post\\<^sub>R (P x)))\"\n  by (simp add: PrefixCSP_RHS_tri assms ExtChoice_tri_rdes closure unrest, rel_auto)\n\nsubsection \\<open> Input prefix \\<close>\n\ndefinition InputCSP ::\n  \"('a, '\\<theta>) chan \\<Rightarrow> ('a \\<Rightarrow> '\\<sigma> upred) \\<Rightarrow> ('a \\<Rightarrow> ('\\<sigma>, '\\<theta>) action) \\<Rightarrow> ('\\<sigma>, '\\<theta>) action\" where\n[upred_defs]: \"InputCSP c A P = (\\<box> x\\<in>UNIV \\<bullet> A(x) &\\<^sub>C PrefixCSP (c\\<cdot>\\<guillemotleft>x\\<guillemotright>)\\<^sub>u (P x))\"\n\ndefinition InputVarCSP :: \"('a, '\\<theta>) chan \\<Rightarrow> ('a \\<Longrightarrow> '\\<sigma>) \\<Rightarrow> ('a \\<Rightarrow> '\\<sigma> upred) \\<Rightarrow> ('\\<sigma>, '\\<theta>) action\" where\n[upred_defs, rdes_def]: \"InputVarCSP c x A = InputCSP c A (\\<lambda> v. \\<langle>[x \\<mapsto>\\<^sub>s \\<guillemotleft>v\\<guillemotright>]\\<rangle>\\<^sub>C)\"\n\ndefinition do\\<^sub>I :: \"\n  ('a, '\\<theta>) chan \\<Rightarrow>\n  ('a \\<Longrightarrow> ('\\<sigma>, '\\<theta>) sfrd) \\<Rightarrow>\n  ('a \\<Rightarrow> ('\\<sigma>, '\\<theta>) action) \\<Rightarrow>\n  ('\\<sigma>, '\\<theta>) action\" where\n\"do\\<^sub>I c x P = (\n  ($tr\\<acute> =\\<^sub>u $tr \\<and> {e | P(e) \\<bullet> (c\\<cdot>\\<guillemotleft>e\\<guillemotright>)\\<^sub>u} \\<inter>\\<^sub>u $ref\\<acute> =\\<^sub>u {}\\<^sub>u)\n    \\<triangleleft> $wait\\<acute> \\<triangleright>\n  (($tr\\<acute> - $tr) \\<in>\\<^sub>u {e | P(e) \\<bullet> U([(c\\<cdot>\\<guillemotleft>e\\<guillemotright>)\\<^sub>u])} \\<and> (c\\<cdot>$x\\<acute>)\\<^sub>u =\\<^sub>u last\\<^sub>u($tr\\<acute>)))\"\n\nlemma InputCSP_CSP [closure]: \"InputCSP c A P is CSP\"\n  by (simp add: CSP_ExtChoice InputCSP_def)\n\nlemma InputCSP_NCSP [closure]: \"\\<lbrakk> \\<And> v. P(v) is NCSP \\<rbrakk> \\<Longrightarrow> InputCSP c A P is NCSP\"\n  apply (simp add: InputCSP_def)\n  apply (rule NCSP_ExtChoice)\n  apply (simp add: NCSP_Guard NCSP_PrefixCSP image_Collect_subsetI top_set_def)\n  done\n\nlemma InputVarCSP_NCSP [closure]: \"InputVarCSP c x A is NCSP\"\n  by (simp add: AssignsCSP_NCSP InputCSP_NCSP InputVarCSP_def)\n\nlemma Productive_InputCSP [closure]:\n  \"\\<lbrakk> \\<And> v. P(v) is NCSP \\<rbrakk> \\<Longrightarrow> InputCSP x A P is Productive\"\n  by (auto simp add: InputCSP_def unrest closure intro: Productive_ExtChoice)\n\nlemma Productive_InputVarCSP [closure]: \"InputVarCSP c x A is Productive\"\n  by (simp add: InputVarCSP_def closure)\n\n(*\nlemma preR_InputCSP [rdes]:\n  assumes \"\\<And> v. P(v) is NCSP\"\n  shows \"pre\\<^sub>R(InputCSP a A P) = (\\<Squnion> v \\<bullet> [A(v)]\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r \\<I>(true,\\<langle>(a\\<cdot>\\<guillemotleft>v\\<guillemotright>)\\<^sub>u\\<rangle>) \\<Rightarrow>\\<^sub>r (pre\\<^sub>R (P(v)))\\<lbrakk>\\<langle>(a\\<cdot>\\<guillemotleft>v\\<guillemotright>)\\<^sub>u\\<rangle>\\<rbrakk>\\<^sub>t)\"\n  by (simp add: InputCSP_def rdes closure assms alpha usubst unrest)\n    \nlemma periR_InputCSP [rdes]:\n  assumes \"\\<And> v. P(v) is NCSP\"\n  shows \"peri\\<^sub>R(InputCSP a A P) =\n           ((\\<Squnion> x \\<bullet> [A(x)]\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r \\<E>(true, \\<guillemotleft>[]\\<guillemotright>, {(a\\<cdot>\\<guillemotleft>x\\<guillemotright>)\\<^sub>u}\\<^sub>u))) \n              \\<triangleleft> $tr\\<acute> =\\<^sub>u $tr \\<triangleright>\n            (\\<Sqinter> x \\<bullet> [A(x)]\\<^sub>S\\<^sub>< \\<and> (peri\\<^sub>R (P x))\\<lbrakk>\\<langle>(a\\<cdot>\\<guillemotleft>x\\<guillemotright>)\\<^sub>u\\<rangle>\\<rbrakk>\\<^sub>t)\" \n  by (simp add: InputCSP_def rdes closure assms, rel_auto)\n\nlemma postR_InputCSP [rdes]:\n  assumes \"\\<And> v. P(v) is NCSP\"\n  shows \"post\\<^sub>R(InputCSP a A P) =\n          (\\<Sqinter> x \\<bullet> [A x]\\<^sub>S\\<^sub>< \\<and> post\\<^sub>R (P x)\\<lbrakk>\\<langle>(a\\<cdot>\\<guillemotleft>x\\<guillemotright>)\\<^sub>u\\<rangle>\\<rbrakk>\\<^sub>t)\"\n  using assms by (simp add: InputCSP_def rdes closure assms usubst unrest)\n*)\n\nlemma R4_st_pred_conj_do [rpred]:\n  \"((R4 [s\\<^sub>1]\\<^sub>S\\<^sub><) \\<and> \\<Phi>(s\\<^sub>2,\\<sigma>,t) ;; P) = R4(\\<Phi>(s\\<^sub>1 \\<and> s\\<^sub>2,\\<sigma>,t) ;; P) \"\n  by (rel_auto)\n\nlemma unrest_ref'_R4 [unrest]: \"$ref\\<acute> \\<sharp> P \\<Longrightarrow> $ref\\<acute> \\<sharp> R4(P)\"\n  by (simp add: R4_def unrest)\n\nlemma st_pred_conj_seq [rpred]:\n  \"\\<lbrakk> P is RR; Q is RR \\<rbrakk> \\<Longrightarrow> ([s]\\<^sub>S\\<^sub>< \\<and> P ;; Q) = (([s]\\<^sub>S\\<^sub>< \\<and> P) ;; Q)\"\n  by (metis (no_types, lifting) R1_seqr_closure RR_implies_R1 cond_st_distr cond_st_miracle seqr_left_zero)\n  \nlemma InputCSP_rdes_def [rdes_def]:\n  assumes \"\\<And> v. P(v) is CRC\" \"\\<And> v. Q(v) is CRR\" \"\\<And> v. R(v) is CRR\"\n          \"\\<And> v. $st\\<acute> \\<sharp> Q(v)\" \"\\<And> v. $ref\\<acute> \\<sharp> R(v)\"\n  shows \"InputCSP a A (\\<lambda> v. \\<^bold>R\\<^sub>s(P(v) \\<turnstile> Q(v) \\<diamondop> R(v))) = \n           \\<^bold>R\\<^sub>s((\\<Squnion> x \\<bullet> \\<Phi>(A x,id\\<^sub>s,U([(a\\<cdot>\\<guillemotleft>x\\<guillemotright>)\\<^sub>u])) wp\\<^sub>r P x) \\<turnstile>\n             ((\\<Squnion> x \\<bullet> \\<E>(A x,\\<guillemotleft>[]\\<guillemotright>, {(a\\<cdot>\\<guillemotleft>x\\<guillemotright>)\\<^sub>u}\\<^sub>u) \\<or> \\<E>(\\<not> A x,\\<guillemotleft>[]\\<guillemotright>, {}\\<^sub>u)) \\<or> (\\<Sqinter> x \\<bullet> \\<Phi>(A x,id\\<^sub>s,U([(a\\<cdot>\\<guillemotleft>x\\<guillemotright>)\\<^sub>u])) ;; Q x)) \\<diamondop> \n             (\\<Sqinter> x \\<bullet> \\<Phi>(A x,id\\<^sub>s,U([(a\\<cdot>\\<guillemotleft>x\\<guillemotright>)\\<^sub>u])) ;; R x))\"\n  by (simp add: InputCSP_def, rdes_simp cls: assms)\n\n(*\nlemma InputCSP_rdes_def [rdes_def]:\n  assumes \"\\<And> v. P(v) is CRC\" \"\\<And> v. Q(v) is CRR\" \"\\<And> v. R(v) is CRR\"\n          \"\\<And> v. $st\\<acute> \\<sharp> Q(v)\" \"\\<And> v. $ref\\<acute> \\<sharp> R(v)\"\n  shows \"InputCSP a A (\\<lambda> v. \\<^bold>R\\<^sub>s(P(v) \\<turnstile> Q(v) \\<diamondop> R(v))) = \n         \\<^bold>R\\<^sub>s( (\\<Squnion> v \\<bullet> ([A(v)]\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r \\<I>(true,\\<langle>(a\\<cdot>\\<guillemotleft>v\\<guillemotright>)\\<^sub>u\\<rangle>) \\<Rightarrow>\\<^sub>r (P v)\\<lbrakk>\\<langle>(a\\<cdot>\\<guillemotleft>v\\<guillemotright>)\\<^sub>u\\<rangle>\\<rbrakk>\\<^sub>t))\n           \\<turnstile> (((\\<Squnion> x \\<bullet> R5([A(x)]\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r \\<E>(true, \\<guillemotleft>[]\\<guillemotright>, {(a\\<cdot>\\<guillemotleft>x\\<guillemotright>)\\<^sub>u}\\<^sub>u)))) \n               \\<or>\n               (\\<Sqinter> x \\<bullet> [A(x)]\\<^sub>S\\<^sub>< \\<and> (P x \\<and> Q x)\\<lbrakk>\\<langle>(a\\<cdot>\\<guillemotleft>x\\<guillemotright>)\\<^sub>u\\<rangle>\\<rbrakk>\\<^sub>t))\n           \\<diamondop> (\\<Sqinter> x \\<bullet> [A x]\\<^sub>S\\<^sub>< \\<and> (P x \\<and> R x)\\<lbrakk>\\<langle>(a\\<cdot>\\<guillemotleft>x\\<guillemotright>)\\<^sub>u\\<rangle>\\<rbrakk>\\<^sub>t))\" (is \"?lhs = ?rhs\")\nproof -\n  have 1:\"pre\\<^sub>R(?lhs) = (\\<Squnion> v \\<bullet> [A v]\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r \\<I>(true,\\<langle>(a\\<cdot>\\<guillemotleft>v\\<guillemotright>)\\<^sub>u\\<rangle>) \\<Rightarrow>\\<^sub>r P v\\<lbrakk>\\<langle>(a\\<cdot>\\<guillemotleft>v\\<guillemotright>)\\<^sub>u\\<rangle>\\<rbrakk>\\<^sub>t)\" (is \"_ = ?A\")\n    by (simp add: rdes NCSP_rdes_intro assms conj_comm closure)\n  have 2:\"peri\\<^sub>R(?lhs) = (\\<Squnion> x \\<bullet> [A x]\\<^sub>S\\<^sub>< \\<Rightarrow>\\<^sub>r \\<E>(true,\\<guillemotleft>[]\\<guillemotright>, {(a\\<cdot>\\<guillemotleft>x\\<guillemotright>)\\<^sub>u}\\<^sub>u)) \\<triangleleft> $tr\\<acute> =\\<^sub>u $tr \\<triangleright> (\\<Sqinter> x \\<bullet> [A x]\\<^sub>S\\<^sub>< \\<and> (P x \\<Rightarrow>\\<^sub>r Q x)\\<lbrakk>\\<langle>(a\\<cdot>\\<guillemotleft>x\\<guillemotright>)\\<^sub>u\\<rangle>\\<rbrakk>\\<^sub>t)\"\n    (is \"_ = ?B\")\n    by (simp add: rdes NCSP_rdes_intro assms closure)\n  have 3:\"post\\<^sub>R(?lhs) = (\\<Sqinter> x \\<bullet> [A x]\\<^sub>S\\<^sub>< \\<and> (P x \\<Rightarrow>\\<^sub>r R x)\\<lbrakk>\\<langle>(a\\<cdot>\\<guillemotleft>x\\<guillemotright>)\\<^sub>u\\<rangle>\\<rbrakk>\\<^sub>t)\"\n    (is \"_ = ?C\")\n    by (simp add: rdes NCSP_rdes_intro assms closure)\n  have \"?lhs = \\<^bold>R\\<^sub>s(?A \\<turnstile> ?B \\<diamondop> ?C)\"\n    by (subst SRD_reactive_tri_design[THEN sym], simp_all add: closure 1 2 3)\n  also have \"... = ?rhs\"\n    by (rel_auto)\n  finally show ?thesis .\nqed\n*)\n\nsubsection \\<open> Renaming \\<close>\n\ndefinition RenameCSP :: \"('s, 'e) action \\<Rightarrow> ('e \\<Rightarrow> 'f) \\<Rightarrow> ('s, 'f) action\" (\"(_)\\<lparr>_\\<rparr>\\<^sub>C\" [999, 0] 999) where\n[upred_defs]: \"RenameCSP P f = \\<^bold>R\\<^sub>s((\\<not>\\<^sub>r (\\<not>\\<^sub>r pre\\<^sub>R(P))\\<lparr>f\\<rparr>\\<^sub>c ;; true\\<^sub>r) \\<turnstile> ((peri\\<^sub>R(P))\\<lparr>f\\<rparr>\\<^sub>c) \\<diamondop> ((post\\<^sub>R(P))\\<lparr>f\\<rparr>\\<^sub>c))\"\n\nlemma RenameCSP_rdes_def [rdes_def]: \n  assumes \"P is CRC\" \"Q is CRR\" \"R is CRR\"\n  shows \"(\\<^bold>R\\<^sub>s(P \\<turnstile> Q \\<diamondop> R))\\<lparr>f\\<rparr>\\<^sub>C = \\<^bold>R\\<^sub>s((\\<not>\\<^sub>r (\\<not>\\<^sub>r P)\\<lparr>f\\<rparr>\\<^sub>c ;; true\\<^sub>r) \\<turnstile> Q\\<lparr>f\\<rparr>\\<^sub>c \\<diamondop> R\\<lparr>f\\<rparr>\\<^sub>c)\" (is \"?lhs = ?rhs\")\nproof -\n  have \"?lhs =  \\<^bold>R\\<^sub>s ((\\<not>\\<^sub>r (\\<not>\\<^sub>r P)\\<lparr>f\\<rparr>\\<^sub>c ;; true\\<^sub>r) \\<turnstile> (P \\<Rightarrow>\\<^sub>r Q)\\<lparr>f\\<rparr>\\<^sub>c \\<diamondop> (P \\<Rightarrow>\\<^sub>r R)\\<lparr>f\\<rparr>\\<^sub>c)\"\n    by (simp add: RenameCSP_def rdes closure assms)\n  also have \"... = \\<^bold>R\\<^sub>s ((\\<not>\\<^sub>r (\\<not>\\<^sub>r CRC(P))\\<lparr>f\\<rparr>\\<^sub>c ;; true\\<^sub>r) \\<turnstile> (CRC(P) \\<Rightarrow>\\<^sub>r CRR(Q))\\<lparr>f\\<rparr>\\<^sub>c \\<diamondop> (CRC(P) \\<Rightarrow>\\<^sub>r CRR(R))\\<lparr>f\\<rparr>\\<^sub>c)\"\n    by (simp add: Healthy_if assms)\n  also have \"... = \\<^bold>R\\<^sub>s ((\\<not>\\<^sub>r (\\<not>\\<^sub>r CRC(P))\\<lparr>f\\<rparr>\\<^sub>c ;; true\\<^sub>r) \\<turnstile> (CRR(Q))\\<lparr>f\\<rparr>\\<^sub>c \\<diamondop> (CRR(R))\\<lparr>f\\<rparr>\\<^sub>c)\"\n    by (rel_auto, (metis order_refl)+)\n  also have \"... = ?rhs\"\n    by (simp add: Healthy_if assms)\n  finally show ?thesis .\nqed\n\nlemma RenameCSP_pre_CRC_closed:\n  assumes \"P is CRR\"\n  shows \"\\<not>\\<^sub>r (\\<not>\\<^sub>r P)\\<lparr>f\\<rparr>\\<^sub>c ;; R1 true is CRC\"\n  apply (rule CRC_intro'')\n   apply (simp add: unrest closure assms)\n  apply (simp add: Healthy_def, simp add: RC1_def rpred closure CRC_idem assms seqr_assoc) \n  done\n  \nlemma RenameCSP_NCSP_closed [closure]:\n  assumes \"P is NCSP\"\n  shows \"P\\<lparr>f\\<rparr>\\<^sub>C is NCSP\"\n  by (simp add: RenameCSP_def RenameCSP_pre_CRC_closed closure assms unrest)\n\nlemma csp_rename_false [rpred]: \n  \"false\\<lparr>f\\<rparr>\\<^sub>c = false\"\n  by (rel_auto)\n\nlemma umap_nil [simp]: \"map\\<^sub>u f \\<guillemotleft>[]\\<guillemotright> = \\<guillemotleft>[]\\<guillemotright>\"\n  by (rel_auto)\n\nlemma rename_Skip: \"Skip\\<lparr>f\\<rparr>\\<^sub>C = Skip\"\n  by (rdes_eq)\n\nlemma rename_Chaos: \"Chaos\\<lparr>f\\<rparr>\\<^sub>C = Chaos\"\n  by (rdes_eq_split; rel_simp; force)\n\nlemma rename_Miracle: \"Miracle\\<lparr>f\\<rparr>\\<^sub>C = Miracle\"\n  by (rdes_eq)\n\nlemma rename_DoCSP: \"(do\\<^sub>C(a))\\<lparr>f\\<rparr>\\<^sub>C = do\\<^sub>C(\\<guillemotleft>f\\<guillemotright>(a)\\<^sub>a)\"\n  by (rdes_eq)\n  \nsubsection \\<open> Algebraic laws \\<close>\n\nlemma AssignCSP_conditional:\n  assumes \"vwb_lens x\"\n  shows \"x :=\\<^sub>C e \\<triangleleft> b \\<triangleright>\\<^sub>R x :=\\<^sub>C f = x :=\\<^sub>C (e \\<triangleleft> b \\<triangleright> f)\" \n  by (rdes_eq cls: assms)\n\nlemma AssignsCSP_id: \"\\<langle>id\\<^sub>s\\<rangle>\\<^sub>C = Skip\"\n  by (rel_auto)\n\nlemma Guard_comp:\n  \"g &\\<^sub>C h &\\<^sub>C P = (g \\<and> h) &\\<^sub>C P\"\n  by (rule antisym, rel_blast, rel_blast)\n\nlemma Guard_false [simp]: \"false &\\<^sub>C P = Stop\"\n  by (simp add: GuardCSP_def Stop_def rpred closure alpha R1_design_R1_pre)\n\nlemma Guard_true [simp]:\n  \"P is CSP \\<Longrightarrow> true &\\<^sub>C P = P\"\n  by (simp add: GuardCSP_def alpha SRD_reactive_design_alt closure rpred)\n\nlemma Guard_conditional:\n  assumes \"P is NCSP\"\n  shows \"b &\\<^sub>C P = P \\<triangleleft> b \\<triangleright>\\<^sub>R Stop\"  \n  by (rdes_eq cls: assms)\n\nlemma Guard_expansion:\n  assumes \"P is NCSP\"\n  shows \"(g\\<^sub>1 \\<or> g\\<^sub>2) &\\<^sub>C P = (g\\<^sub>1 &\\<^sub>C P) \\<box> (g\\<^sub>2 &\\<^sub>C P)\"\n  apply (rdes_eq_split cls: assms) \n    apply (rel_simp', fastforce simp add: dual_order.order_iff_strict)\n   apply (rel_simp', simp add: dual_order.order_iff_strict, fastforce)\n  apply (rel_simp', simp add: dual_order.order_iff_strict, fastforce)\n  done\n\nlemma Conditional_as_Guard:\n  assumes \"P is NCSP\" \"Q is NCSP\"\n  shows \"P \\<triangleleft> b \\<triangleright>\\<^sub>R Q = b &\\<^sub>C P \\<box> (\\<not> b) &\\<^sub>C Q\"  \n  by (rdes_eq' cls: assms; simp add: le_less)\n\nlemma PrefixCSP_dist:\n  \"PrefixCSP a (P \\<sqinter> Q) = (PrefixCSP a P) \\<sqinter> (PrefixCSP a Q)\"\n  using Continuous_Disjunctous Disjunctuous_def PrefixCSP_Continuous by auto\n\nlemma DoCSP_is_Prefix:\n  \"do\\<^sub>C(a) = PrefixCSP a Skip\"\n  by (simp add: PrefixCSP_def Healthy_if closure, metis CSP4_DoCSP CSP4_def Healthy_def)\n\nlemma PrefixCSP_seq:\n  assumes \"P is CSP\" \"Q is CSP\"\n  shows \"(PrefixCSP a P) ;; Q = (PrefixCSP a (P ;; Q))\"\n  by (simp add: PrefixCSP_def seqr_assoc Healthy_if assms closure)\n\nlemma PrefixCSP_extChoice_dist:\n  assumes \"P is NCSP\" \"Q is NCSP\" \"R is NCSP\"\n  shows \"((a \\<rightarrow>\\<^sub>C P) \\<box> (b \\<rightarrow>\\<^sub>C Q)) ;; R  = (a \\<rightarrow>\\<^sub>C P ;; R) \\<box> (b \\<rightarrow>\\<^sub>C Q ;; R)\"\n  by (simp add: PCSP_PrefixCSP assms(1) assms(2) assms(3) extChoice_seq_distr)\n\nlemma GuardedChoiceCSP_dist: \n  assumes \"\\<And> i. i\\<in>A \\<Longrightarrow> P(i) is NCSP\" \"Q is NCSP\"\n  shows \"\\<box> x\\<in>A \\<^bold>\\<rightarrow> P(x) ;; Q = \\<box> x\\<in>A \\<^bold>\\<rightarrow> (P(x) ;; Q)\"\n  by (simp add: ExtChoice_seq_distr PrefixCSP_seq closure assms cong: ExtChoice_cong)\n\ntext \\<open> Alternation can be re-expressed as an external choice when the guards are disjoint \\<close>\n\ndeclare ExtChoice_tri_rdes [rdes_def]\ndeclare ExtChoice_tri_rdes' [rdes_def del]\n\ndeclare extChoice_rdes_def [rdes_def]\ndeclare extChoice_rdes_def' [rdes_def del]\n\nlemma AlternateR_as_ExtChoice:\n  assumes \n    \"\\<And> i. i \\<in> A \\<Longrightarrow> P(i) is NCSP\" \"Q is NCSP\"\n    \"\\<And> i j. \\<lbrakk> i \\<in> A; j \\<in> A; i \\<noteq> j \\<rbrakk> \\<Longrightarrow> (g i \\<and> g j) = false\" \n  shows \"(if\\<^sub>R i\\<in>A \\<bullet> g(i) \\<rightarrow> P(i) else Q fi) = \n         (\\<box> i\\<in>A \\<bullet> g(i) &\\<^sub>C P(i)) \\<box> (\\<And> i\\<in>A \\<bullet> \\<not> g(i)) &\\<^sub>C Q\"\nproof (cases \"A = {}\")\n  case True\n  then show ?thesis by (simp add: ExtChoice_empty extChoice_Stop closure assms)\nnext\n  case False\n  show ?thesis\n  \n  proof -\n    have 1:\"(\\<Sqinter> i \\<in> A \\<bullet> g i \\<rightarrow>\\<^sub>R P i) = (\\<Sqinter> i \\<in> A \\<bullet> g i \\<rightarrow>\\<^sub>R \\<^bold>R\\<^sub>s(pre\\<^sub>R(P i) \\<turnstile> peri\\<^sub>R(P i) \\<diamondop> post\\<^sub>R(P i)))\"\n      by (rule UINF_cong, simp add: NCSP_implies_CSP SRD_reactive_tri_design assms(1))\n    have 2:\"(\\<box> i\\<in>A \\<bullet> g(i) &\\<^sub>C P(i)) = (\\<box> i\\<in>A \\<bullet> g(i) &\\<^sub>C \\<^bold>R\\<^sub>s(pre\\<^sub>R(P i) \\<turnstile> peri\\<^sub>R(P i) \\<diamondop> post\\<^sub>R(P i)))\"\n      by (rule ExtChoice_cong, simp add: NCSP_implies_NSRD NSRD_is_SRD SRD_reactive_tri_design assms(1))\n    from assms(3) show ?thesis\n      by (simp add: AlternateR_def 1 2)\n         (rdes_eq' cls: assms(1-2) simps: False cong: UINF_cong USUP_cong ExtChoice_cong)\n  qed\nqed\n\ndeclare ExtChoice_tri_rdes [rdes_def del]\ndeclare ExtChoice_tri_rdes' [rdes_def]\n\ndeclare extChoice_rdes_def [rdes_def del]\ndeclare extChoice_rdes_def' [rdes_def]\n\nfind_theorems R4\n\nend", "meta": {"author": "isabelle-utp", "repo": "utp-main", "sha": "27bdf3aee6d4fc00c8fe4d53283d0101857e0d41", "save_path": "github-repos/isabelle/isabelle-utp-utp-main", "path": "github-repos/isabelle/isabelle-utp-utp-main/utp-main-27bdf3aee6d4fc00c8fe4d53283d0101857e0d41/theories/sf_rdes/utp_sfrd_prog.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.5195213219520929, "lm_q1q2_score": 0.27799504301458483}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      ProcParEx.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2007-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nheader \"Examples for Procedures as Parameters using Statespaces\"\ntheory ProcParExSP imports \"../Vcg\" begin\n\n\n\n\n\n\n\nlemma conseq_exploit_pre':\n             \"\\<lbrakk>\\<forall>s \\<in> S. \\<Gamma>,\\<Theta> \\<turnstile> ({s} \\<inter> P) c Q,A\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile> (P \\<inter> S)c Q,A\"\n  apply (rule HoarePartialDef.Conseq)\n  apply clarify\n  by (metis IntI insertI1 subset_refl)\n\nlemma conseq_exploit_pre'':\n             \"\\<lbrakk>\\<forall>Z. \\<forall>s \\<in> S Z.  \\<Gamma>,\\<Theta> \\<turnstile> ({s} \\<inter> P Z) c (Q Z),(A Z)\\<rbrakk>\n              \\<Longrightarrow>\n              \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile> (P Z \\<inter> S Z)c (Q Z),(A Z)\"\n  apply (rule allI)\n  apply (rule conseq_exploit_pre')\n  apply blast\n  done\n\nlemma conseq_exploit_pre''':\n             \"\\<lbrakk>\\<forall>s \\<in> S. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile> ({s} \\<inter> P Z) c (Q Z),(A Z)\\<rbrakk>\n              \\<Longrightarrow>\n              \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile> (P Z \\<inter> S)c (Q Z),(A Z)\"\n  apply (rule allI)\n  apply (rule conseq_exploit_pre')\n  apply blast\n  done\n\n\nprocedures compare(i::nat,j::nat|r::bool) \"NoBody\"\n  \n\nprint_locale! compare_signature\n\n\ncontext compare_impl\nbegin\ndeclare [[hoare_use_call_tr' = false]]\nterm \"\\<acute>r :== CALL compare(\\<acute>i,\\<acute>j)\"\ndeclare [[hoare_use_call_tr' = true]]\nend\n\n\n(* FIXME: typing issue with modifies locale*)\nprocedures\n  LEQ (i::nat,j::nat | r::bool) \"\\<acute>r :== \\<acute>i \\<le> \\<acute>j\"\n  LEQ_spec: \"\\<forall>\\<sigma>. \\<Gamma>\\<turnstile> {\\<sigma>}  PROC LEQ(\\<acute>i,\\<acute>j,\\<acute>r) \\<lbrace>\\<acute>r = (\\<^bsup>\\<sigma>\\<^esup>i \\<le> \\<^bsup>\\<sigma>\\<^esup>j)\\<rbrace>\"\n\n  LEQ_modifies: \"\\<forall>\\<sigma>. \\<Gamma>\\<turnstile> {\\<sigma>} PROC LEQ(\\<acute>i,\\<acute>j,\\<acute>r) {t. t may_only_modify_globals \\<sigma> in []}\"\n\n\n\ndefinition mx:: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool) \\<Rightarrow> 'a \\<Rightarrow> 'a \\<Rightarrow> 'a\"\n  where \"mx leq a b = (if leq a b then a else b)\"\n\nprocedures (imports compare_signature)\n  Max (compare::string, n::nat, m::nat | k::nat)  \n  where b::bool\n  in\n  \"\\<acute>b :== DYNCALL \\<acute>compare(\\<acute>n,\\<acute>m);;\n   IF \\<acute>b THEN \\<acute>k :== \\<acute>n ELSE \\<acute>k :== \\<acute>m FI\"\n\n  Max_spec: \"\\<And>leq. \\<forall>\\<sigma>. \\<Gamma>\\<turnstile> \n  ({\\<sigma>} \\<inter> {s. (\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<^bsup>s\\<^esup>compare(\\<acute>i,\\<acute>j) \\<lbrace>\\<acute>r = (leq \\<^bsup>\\<tau>\\<^esup>i \\<^bsup>\\<tau>\\<^esup>j)\\<rbrace>) \\<and> \n              (\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<^bsup>s\\<^esup>compare(\\<acute>i,\\<acute>j) {t. t may_only_modify_globals \\<tau> in []})})\n    PROC Max(\\<acute>compare,\\<acute>n,\\<acute>m,\\<acute>k)\n  \\<lbrace>\\<acute>k = mx leq \\<^bsup>\\<sigma>\\<^esup>n \\<^bsup>\\<sigma>\\<^esup>m\\<rbrace>\"\n\ncontext Max_spec\nbegin\nthm Max_spec\nend\ncontext Max_impl\nbegin\nterm \"\\<acute>b :== DYNCALL \\<acute>compare(\\<acute>n,\\<acute>m)\"\ndeclare [[hoare_use_call_tr' = false]]\nterm \"\\<acute>b :== DYNCALL \\<acute>compare(\\<acute>n,\\<acute>m)\"\ndeclare [[hoare_use_call_tr' = true]]\nend\n\n\n\nlemma (in Max_impl ) Max_spec1: \nshows\n\"\\<forall>\\<sigma> leq. \\<Gamma>\\<turnstile> \n  ({\\<sigma>} \\<inter> \\<lbrace> (\\<forall>\\<tau>. \\<Gamma>\\<turnstile>{\\<tau>} \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) \\<lbrace>\\<acute>r = (leq \\<^bsup>\\<tau>\\<^esup>i \\<^bsup>\\<tau>\\<^esup>j)\\<rbrace>) \\<and> \n      (\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) {t. t may_only_modify_globals \\<tau> in []})\\<rbrace>)\n    \\<acute>k :== PROC Max(\\<acute>compare,\\<acute>n,\\<acute>m)\n  \\<lbrace>\\<acute>k = mx leq \\<^bsup>\\<sigma>\\<^esup>n \\<^bsup>\\<sigma>\\<^esup>m\\<rbrace>\"\napply (hoare_rule HoarePartial.ProcNoRec1)\napply (intro allI)\napply (rule conseq_exploit_pre')\napply (rule)\napply clarify\nproof -\n  fix \\<sigma>:: \"('a, 'b, 'c, 'd) stateSP_scheme\" and s::\"('a, 'b, 'c, 'd) stateSP_scheme\" and leq\n   assume compare_spec: \n       \"\\<forall>\\<tau>. \\<Gamma>\\<turnstile>{\\<tau>} \\<acute>r :== PROC \\<^bsup>s\\<^esup>compare(\\<acute>i,\\<acute>j) \\<lbrace>\\<acute>r = leq \\<^bsup>\\<tau>\\<^esup>i \\<^bsup>\\<tau>\\<^esup>j\\<rbrace>\"\n \n  assume compare_modifies:\n        \"\\<forall>\\<tau>. \\<Gamma>\\<turnstile>{\\<tau>} \\<acute>r :== PROC \\<^bsup>s\\<^esup>compare(\\<acute>i,\\<acute>j) \n                {t. t may_only_modify_globals \\<tau> in []}\"\n\n   show \"\\<Gamma>\\<turnstile>({s} \\<inter> {\\<sigma>})\n            \\<acute>b :== DYNCALL \\<acute>compare (\\<acute>n,\\<acute>m);;\n            IF \\<acute>b THEN \\<acute>k :== \\<acute>n ELSE \\<acute>k :== \\<acute>m FI\n            \\<lbrace>\\<acute>k = mx leq \\<^bsup>\\<sigma>\\<^esup>n \\<^bsup>\\<sigma>\\<^esup>m\\<rbrace>\"\n     apply vcg\n     apply (clarsimp simp add: mx_def)\n     done\n qed\n\n\nlemma (in Max_impl) Max_spec2: \nshows\n\"\\<forall>\\<sigma> leq. \\<Gamma>\\<turnstile> \n  ({\\<sigma>} \\<inter> \\<lbrace>(\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) \\<lbrace>\\<acute>r = (leq \\<^bsup>\\<tau>\\<^esup>i \\<^bsup>\\<tau>\\<^esup>j)\\<rbrace>) \\<and> \n      (\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) {t. t may_only_modify_globals \\<tau> in []})\\<rbrace>)\n    \\<acute>k :== PROC Max(\\<acute>compare,\\<acute>n,\\<acute>m)\n  \\<lbrace>\\<acute>k = mx leq \\<^bsup>\\<sigma>\\<^esup>n \\<^bsup>\\<sigma>\\<^esup>m\\<rbrace>\"\napply (hoare_rule HoarePartial.ProcNoRec1)\napply (intro allI)\napply (rule conseq_exploit_pre')\napply (rule)\napply clarify\napply vcg\napply (clarsimp simp add: mx_def)\ndone\n\nlemma (in Max_impl) Max_spec3: \nshows\n\"\\<forall>n m leq. \\<Gamma>\\<turnstile> \n  (\\<lbrace>\\<acute>n=n \\<and> \\<acute>m=m\\<rbrace>  \\<inter> \n   \\<lbrace>(\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) \\<lbrace>\\<acute>r = (leq \\<^bsup>\\<tau>\\<^esup>i \\<^bsup>\\<tau>\\<^esup>j)\\<rbrace>) \\<and> \n     (\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) {t. t may_only_modify_globals \\<tau> in []})\\<rbrace>)\n    \\<acute>k :== PROC Max(\\<acute>compare,\\<acute>n,\\<acute>m)\n  \\<lbrace>\\<acute>k = mx leq n m\\<rbrace>\"\napply (hoare_rule HoarePartial.ProcNoRec1)\napply (intro allI)\napply (rule conseq_exploit_pre')\napply (rule)\napply clarify\napply vcg\napply (clarsimp simp add: mx_def)\ndone\n\n\n\nprint_locale Max_spec\n\n(* We have to rename the parameters of the compare procedure to match the LEQ procedure *)\nlocale Max_test = Max_spec where\n        i_'compare_' = i_'LEQ_' and\n        j_'compare_' = j_'LEQ_' and\n        r_'compare_' = r_'LEQ_'\n       + LEQ_spec + LEQ_modifies\n\nlemma (in Max_test) \n  shows\n  \"\\<Gamma>\\<turnstile> {\\<sigma>} \\<acute>k :== CALL Max(LEQ_'proc,\\<acute>n,\\<acute>m) \\<lbrace>\\<acute>k = mx (op \\<le>) \\<^bsup>\\<sigma>\\<^esup>n \\<^bsup>\\<sigma>\\<^esup>m\\<rbrace>\"\nproof -\n  note Max_spec = Max_spec [where leq=\"(op \\<le>)\"]\n  show ?thesis\n    apply vcg\n    apply (clarsimp)\n    apply (rule conjI)\n    apply (rule LEQ_spec)\n    apply (rule LEQ_modifies)\n    done\nqed\n\n\n\n\n\n\nlemma (in Max_impl) Max_spec5:\nshows\n\"\\<forall>n m leq. \\<Gamma>\\<turnstile> \n  (\\<lbrace>\\<acute>n=n \\<and> \\<acute>m=m\\<rbrace> \\<inter> \\<lbrace>\\<forall>n' m'. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>i=n' \\<and> \\<acute>j=m'\\<rbrace> \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) \\<lbrace>\\<acute>r = (leq n' m')\\<rbrace>\\<rbrace>)\n    \\<acute>k :== PROC Max(\\<acute>compare,\\<acute>n,\\<acute>m)\n  \\<lbrace>\\<acute>k = mx leq n m\\<rbrace>\"\napply (hoare_rule HoarePartial.ProcNoRec1)\napply (intro allI)\napply (rule conseq_exploit_pre')\napply (rule)\napply clarify\napply vcg\napply clarsimp\napply (clarsimp simp add: mx_def)\ndone\n\nlemma (in LEQ_impl)\n LEQ_spec: \"\\<forall>n m. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>i=n \\<and> \\<acute>j=m\\<rbrace>  PROC LEQ(\\<acute>i,\\<acute>j,\\<acute>r) \\<lbrace>\\<acute>r = (n \\<le> m)\\<rbrace>\"\n  apply vcg\n  apply simp\n  done\n\n\nprint_locale Max_impl\nlocale Max_test' = Max_impl where\n        i_'compare_' = i_'LEQ_' and\n        j_'compare_' = j_'LEQ_' and\n        r_'compare_' = r_'LEQ_'\n        + LEQ_impl\nlemma (in Max_test') \n  shows\n  \"\\<forall>n m. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>n=n \\<and> \\<acute>m=m\\<rbrace> \\<acute>k :== CALL Max(LEQ_'proc,\\<acute>n,\\<acute>m) \\<lbrace>\\<acute>k = mx (op \\<le>) n m\\<rbrace>\"\nproof -\n  note Max_spec = Max_spec5\n  show ?thesis\n    apply vcg\n    apply (rule_tac x=\"op \\<le>\" in exI)\n    apply clarsimp\n    apply (rule LEQ_spec [rule_format])\n    done\nqed\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Simpl/ex/ProcParExSP.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5350984137988773, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.27799503531126085}}
{"text": "(*\n *\n * Copyright 2017, Data61, CSIRO\n *\n * This software may be distributed and modified according to the terms of\n * the GNU General Public License version 2. Note that NO WARRANTY is provided.\n * See \"LICENSE_GPLv2.txt\" for details.\n *\n * @TAG(DATA61_GPL)\n *)\n\n(*\n   Test proofs for corres methods. Builds on AInvs image.\n*)\n\ntheory Corres_Test\nimports \"Refine.VSpace_R\" \"Lib.Corres_Method\"\nbegin\n\nchapter \\<open>The Corres Method\\<close>\n\nsection \\<open>Introduction\\<close>\n\ntext \\<open>The @{method corres} method tries to do for corres-style refinement proofs what\n@{method wp} did for hoare logic proofs. The intention is to automate the application\nof corres calculational rules, so that the bulk of the manual proof is now handling\na verification condition. In general refinement proofs are difficult to automate, so here we\nexploit the fact that in l4v the abstract and executable specifications tend to be structurally\nsimilar. Corres proofs are based on the @{const corres_underlying} constant, which takes a number\nof parameters that allow it to be specialized for different flavours of refinement.\n\nA corres statement has the following form: @{term \"corres_underlying sr nf nf' r P P' f f'\"}, where\n@{term sr} is a state-relation, @{term nf} and @{term nf'} refer to whether or not the left and\nright hand functions may fail, @{term r} is a return value relation between the functions, @{term P}\nand @{term P'} are preconditions for the functions @{term f} and @{term f'} respectively. Informally\nthe statement says that: under the given preconditions, for every execution of @{term f'} there exists\nan execution of @{term f} that is related by the given state relation @{term sr} and return-value\nrelation @{term r}.\n\nIf the left and right side of a corres statement share similar structure, we can \"unzip\" the function\ninto one corres obligation for each atomic function. This is done through the application of\n  @{thm corres_split}.\n\\<close>\n\nthm corres_split[no_vars]\n\ntext \\<open>Briefly this states that: given a corres goal proving refinement between @{term \"a >>= b\"} and\n  @{term \"c >>= d\"}, we can decompose this into a proof showing refinement between @{term a} and\n@{term c}, and between @{term a} and @{term c}. Additionally @{term a} and @{term c} must establish\nappropriate postconditions to satisfy the obligations of proving refinement between @{term b} and @{term d}.\n\nThe first subgoal that is produced has an important characteristic: the preconditions for each\nside may only discuss the return value of its respective side. This means that rules such as\n@{term \"corres_underlying sr nf nf' r (\\<lambda>s. x = x') (\\<lambda>_. True) (f x) (f' x')\"} will not apply to a goal\n if @{term x} and @{term x'} are variables generated by applying @{thm corres_split} (i.e. the\nreturn values of functions).\n\nThis means that any such conditions must instead be phrased as an assumption to the rule, and our rule must be\nrephrased as follows:\n  @{term \"x = x' \\<Longrightarrow> corres_underlying sr nf nf' r (\\<lambda>_. True) (\\<lambda>_. True) (f x) (f' x')\"}.\nThe result is that we must solve @{term \"x = x'\"} immediately after applying our rule. While this\nis not a major concern for a manual proof, it proves to be a significant obstacle if we're trying\nto focus on automating the \"corres\" part of the refinement.\n\\<close>\n\nsection \\<open>corres_underlyingK and corres_rv\\<close>\n\ntext \\<open>To remedy this situation, we augment the @{const corres_underlying} definition to include\nyet another flag: a single boolean. This new constant: @{const corres_underlyingK},\nwill form the basis of the calculus for our corres method.\\<close>\n\nthm corres_underlyingK_def[no_vars]\n\ntext \\<open>The boolean in @{const corres_underlyingK} can be thought of as a stateless precondition. It\nis used to propagate additional proof obligations for rules that either do not need to discuss\neither the left or right hand state, or must discuss bound variables from both sides.\\<close>\n\nthm corresK_split[no_vars]\n\ntext \\<open>In this split rule for @{const corres_underlyingK} we see that the additional precondition @{term F'}\nmay discuss both @{term rv} and @{term rv'}. To show that this condition is satisified, however,\nwe can't use hoare logic and instead need a new definition: @{const corres_rv}.\\<close>\n\nthm corres_rv_def_I_know_what_I'm_doing[no_vars]\n\ntext \\<open>This is a weaker form of @{const corres_underlying} that is only interested in the return value\nof the functions. In essence, it states the given functions will establish @{term Q} after executing,\nassuming the given return-value relation @{term r} holds, along with the given stateless precondition\n@{term F} and left/right preconditions @{term P} and @{term P'}.\n\nThe assumption in general is that corres_rv rules should never be written, instead corres_rv obligations\nshould be propagated into either the stateless precondition (@{term F} from @{term corres_underlyingK}),\nthe left precondition (@{term P}) or the right precondition @{term P'}. This is implicitly handled\nby @{method corres_rv} (called from @{method corres}) by applying one of the following rules to each conjunct:\\<close>\n\nthm corres_rv_defer\nthm corres_rv_wp_left\nthm corres_rv_wp_right\n\ntext \\<open>If none of these rules can be safely applied, then @{method corres_rv} will leave the\n  obligation untouched. The user can manually apply one of them if desired, but this is liable to\n  create unsolvable proof obligations. In the worst case, the user may manually solve the goal in-place.\\<close>\n\nthm corres_rv_proveT[no_vars]\n\nsection \\<open>The corres method\\<close>\n\ntext \\<open>The core algorithm of the corres method is simple:\n  1) start by applying any necessary weakening rules to ensure the goal has schematic preconditions\n  2) apply a known @{thm corres} or @{thm corresK} rule (see next section)\n  3) if unsuccessful, apply a split rule (i.e. @{thm corresK_split}) and go to 2\n\nImportantly, @{method corres} will not split a goal if it ultimately is not able to apply at least\none @{thm corres} or @{thm corresK} rule.\n\\<close>\n\nsubsection \\<open>The corres and corresK named_theorems\\<close>\n\ntext \\<open>To address the fact that existing refinement rules are phrased as @{const corres_underlying}\nand not @{const corres_underlyingK} there are two different named_theorems that are used for different\nkind of rules @{thm corres} and @{thm corresK}. A @{thm corres} rule is understood to be phrased\nwith @{const corres_underlying} and may have additional assumptions. These assumptions will be\npropagated through the additional @{term F} flag in @{const corres_underlyingK}, rather than presented\nas proof obligations immediately. A @{thm corresK} rule is understood to be phrased with\n@{const corres_underlyingK}, and is meant for calculational rules which may have proper assumptions that\nshould not be propagated.\n\\<close>\nthm corresK\nthm corres\n\nsubsection \\<open>The corresc method\\<close>\n\ntext \\<open>Similar to @{method wpc}, @{method corresc} can handle case statements in @{const corres_underlyingK}\nproof goals. Importantly, however, it is split into two sub-methods @{method corresc_left} and\n@{method corresc_right}, which perform case-splitting on each side respectively. The combined method\n@{method corresc}, however, attempts to discharge the contradictions that arise from the quadratic\nblowup of a case analysis on both the left and right sides.\\<close>\n\nsubsection \\<open>corres_concrete_r, corres_concrete_rE\\<close>\n\ntext \\<open>Some @{thm corresK} rules should only be applied if certain variables are concrete\n(i.e. not schematic) in the goal. These are classified separately with the named_theorems\n@{thm corres_concrete_r} and @{thm corres_concrete_rER}. The first\nindicates that the return value relation of the goal must be concrete, the second indicates that\nonly the left side of the error relation must be concrete.\\<close>\n\nthm corres_concrete_r\nthm corres_concrete_rER\n\nsubsection \\<open>The corres_search method\\<close>\n\ntext \\<open>The purpose of @{method corres_search} is to address cases where there is non-trivial control flow.\nIn particular: in the case where there is an \"if\" statement or either side needs to be symbolically\nexecuted. The core idea is that corres_search should be provided with a \"search\" rule that acts\nas an anchoring point. Symbolic execution and control flow is decomposed until either the given\nrule is successfully applied or all search branches are exhausted.\\<close>\n\nsubsubsection \\<open>Symbolic Execution\\<close>\n\ntext \\<open>Symbolic execution is handled by two named theorems:\n @{thm corres_symb_exec_ls} and @{thm corres_symb_exec_rs}, which perform symbolic execution on\nthe left and right hand sides of a corres goal.\\<close>\n\nthm corres_symb_exec_ls\nthm corres_symb_exec_rs\n\ntext \\<open>A function may be symbolically executed if it does not modify the state, i.e. its only purpose\nis to compute some value and return it. After being symbolically executed,\nthis value can only be discussed by the precondition of the associated side or the stateless\nprecondition of corresK. The resulting @{const corres_rv} goal has @{const corres_noop} as the\nfunction on the alternate side. This gives @{method corres_rv} a hint that the resulting obligation\nshould be aggressively re-written into a hoare triple over @{term m} if it can't be propagated\nback statelessly safely.\n\\<close>\n\n\nsection \\<open>Demo\\<close>\n\n\ncontext begin interpretation Arch .\n\n(* VSpace_R *)\n\n\nlemmas load_hw_asid_corres_args[corres] =\n  load_hw_asid_corres[@lift_corres_args]\n\nlemmas invalidate_asid_corres_args[corres] =\n  invalidate_asid_corres[@lift_corres_args]\n\nlemmas invalidate_hw_asid_entry_corres_args[corres] =\n  invalidate_hw_asid_entry_corres[@lift_corres_args]\n\nlemma invalidate_asid_entry_corres:\n  \"corres dc (valid_vspace_objs and valid_asid_map\n                and K (asid \\<le> mask asid_bits \\<and> asid \\<noteq> 0)\n                and vspace_at_asid asid pd and valid_vs_lookup\n                and unique_table_refs o caps_of_state\n                and valid_global_objs and valid_arch_state\n                and pspace_aligned and pspace_distinct)\n             (pspace_aligned' and pspace_distinct' and no_0_obj')\n             (invalidate_asid_entry asid) (invalidateASIDEntry asid)\"\n  apply (simp add: invalidate_asid_entry_def invalidateASIDEntry_def)\n  apply_debug (trace) (* apply_trace between steps *)\n   (tags \"corres\") (* break at breakpoints labelled \"corres\" *)\n   corres (* weaken precondition *)\n   continue (* split *)\n   continue (* solve load_hw_asid *)\n   continue (* split *)\n   continue (* apply corres_when *)\n   continue (* trivial simplification *)\n   continue (* invalidate _hw_asid_entry *)\n   finish (* invalidate_asid *)\n\n  apply (corressimp wp: load_hw_asid_wp)+\n  apply clarsimp\n  apply (fastforce simp: pd_at_asid_uniq)\n  done\n\n\ncrunch typ_at'[wp]: invalidateASIDEntry, flushSpace \"typ_at' T t\"\ncrunch ksCurThread[wp]: invalidateASIDEntry, flushSpace \"\\<lambda>s. P (ksCurThread s)\"\ncrunch obj_at'[wp]: invalidateASIDEntry, flushSpace \"obj_at' P p\"\n\nlemmas flush_space_corres_args[corres] =\n  flush_space_corres[@lift_corres_args]\n\nlemmas invalidate_asid_entry_corres_args[corres] =\n  invalidate_asid_entry_corres[@lift_corres_args]\n\n\nlemma corres_inst_eq_ext:\n  \"(\\<And>x. corres_inst_eq (f x) (f' x)) \\<Longrightarrow> corres_inst_eq f f'\"\n  by (auto simp add: corres_inst_eq_def)\n\nlemma delete_asid_corresb:\n  notes [corres] = corres_gets_asid gct_corres set_asid_pool_corres and\n    [@lift_corres_args, corres] =  get_asid_pool_corres_inv'\n    invalidate_asid_entry_corres\n    set_vm_root_corres\n  notes [wp] = set_asid_pool_asid_map_unmap set_asid_pool_vs_lookup_unmap'\n    set_asid_pool_vspace_objs_unmap'\n    invalidate_asid_entry_invalidates\n    getASID_wp\n  shows\n    \"corres dc\n          (invs and valid_etcbs and K (asid \\<le> mask asid_bits \\<and> asid \\<noteq> 0))\n          (pspace_aligned' and pspace_distinct' and no_0_obj'\n              and valid_arch_state' and cur_tcb')\n          (delete_asid asid pd) (deleteASID asid pd)\"\n  apply (simp add: delete_asid_def deleteASID_def)\n  apply_debug (trace) (* apply_trace between steps *)\n    (tags \"corres\") (* break at breakpoints labelled \"corres\" *)\n    corres (* weaken precondition *)\n   continue (* split *)\n       continue (* gets rule *)\n      continue (* corresc *)\n       continue (* return rule *)\n      continue (* split *)\n          continue (* function application *)\n          continue (* liftM rule *)\n          continue (* get_asid_pool_corres_inv' *)\n         continue (* function application *)\n         continue (* function application *)\n         continue (* corresK_when *)\n         continue (* split *)\n             continue (* flush_space_corres *)\n            continue (* K_bind *)\n            continue (* K_bind *)\n            continue (* split *)\n                continue (* invalidate_asid_entry_corres *)\n               continue (* K_bind *)\n               continue (* return bind *)\n               continue (* K_bind *)\n               continue (* split *)\n                   continue (* backtracking *)\n               continue (* split *)\n                   continue (* function application *)\n                   continue (* set_asid_pool_corres *)\n                  continue (* K_bind *)\n                  continue (* K_bind *)\n                  continue (* split *)\n                      continue (* gct_corres *)\n                     continue (* set_vm_root_corres *)\n                    finish (* backtracking? *)\n                    apply (corressimp simp: mask_asid_low_bits_ucast_ucast\n      | fold cur_tcb_def | wps)+\n  apply (frule arm_asid_table_related,clarsimp)\n  apply (rule conjI)\n   apply (intro impI allI)\n    apply (rule conjI)\n     apply (safe; assumption?)\n     apply (rule ext)\n     apply (fastforce simp: inv_def dest: ucast_ucast_eq)\n    apply (rule context_conjI)\n    apply (fastforce simp: o_def dest: valid_asid_tableD invs_valid_asid_table)\n   apply (intro allI impI)\n   apply (subgoal_tac \"vspace_at_asid asid pd s\")\n    prefer 2\n    apply (simp add: vspace_at_asid_def)\n    apply (rule vs_lookupI)\n     apply (simp add: vs_asid_refs_def)\n     apply (rule image_eqI[OF refl])\n     apply (rule graph_ofI)\n     apply fastforce\n    apply (rule r_into_rtrancl)\n    apply simp\n    apply (rule vs_lookup1I [OF _ _ refl], assumption)\n    apply (simp add: vs_refs_def)\n    apply (rule image_eqI[rotated], erule graph_ofI)\n    apply (simp add: mask_asid_low_bits_ucast_ucast)\n   prefer 2\n   apply (intro allI impI context_conjI; assumption?)\n    apply (rule aligned_distinct_relation_asid_pool_atI'; fastforce?)\n    apply (fastforce simp: o_def dest: valid_asid_tableD invs_valid_asid_table)\n    apply (simp add: cur_tcb'_def)\n    apply (safe; assumption?)\n    apply (erule ko_at_weakenE)\n    apply (clarsimp simp: graph_of_def)\n    apply (fastforce split: if_split_asm)\n   apply (frule invs_vspace_objs)\n   apply (drule (2) valid_vspace_objsD)\n   apply (erule ranE)\n   apply (fastforce split: if_split_asm)\n  apply (erule ko_at_weakenE)\n  apply (clarsimp simp: graph_of_def)\n  apply (fastforce split: if_split_asm)\n  done\n\nlemma cte_wp_at_ex:\n  \"cte_wp_at (\\<lambda>_. True) p s \\<Longrightarrow> (\\<exists>cap. cte_wp_at ((=) cap) p s)\"\n  by (simp add: cte_wp_at_def)\n\n(* Sadly broken:\nlemma set_vm_root_for_flush_corres:\n  notes [corres] = gct_corres getSlotCap_corres\n  shows\n  \"corres (=)\n          (cur_tcb and vspace_at_asid asid pd\n           and K (asid \\<noteq> 0 \\<and> asid \\<le> mask asid_bits)\n           and valid_asid_map and valid_vs_lookup\n           and valid_vspace_objs and valid_global_objs\n           and unique_table_refs o caps_of_state\n           and valid_arch_state\n           and pspace_aligned and pspace_distinct)\n          (pspace_aligned' and pspace_distinct' and no_0_obj')\n          (set_vm_root_for_flush pd asid)\n          (setVMRootForFlush pd asid)\"\n  apply (simp add: set_vm_root_for_flush_def setVMRootForFlush_def getThreadVSpaceRoot_def locateSlot_conv)\n  apply corres\n         apply_debug (trace) (tags \"corres_search\") (corres_search search: arm_context_switch_corres)\n  continue (* step left *)\n  continue (* if rule *)\n  continue (* failed corres on first subgoal, trying next *)\n  continue (* fail corres on last subgoal, trying reverse if rule *)\n  continue (* can't make corres progress here, trying other goal *)\n  finish (* successful goal discharged by corres *)\n\n  apply (corressimp wp: get_cap_wp getSlotCap_wp)+\n  apply (rule context_conjI)\n  subgoal by (simp add: cte_map_def objBits_simps tcb_cnode_index_def\n                        tcbVTableSlot_def to_bl_1 cte_level_bits_def)\n  apply (rule context_conjI)\n  subgoal by (fastforce simp: cur_tcb_def intro!: tcb_at_cte_at_1[simplified])\n  apply (rule conjI)\n   subgoal by (fastforce simp: isCap_simps)\n  apply (drule cte_wp_at_ex)\n  apply clarsimp\n  apply (drule (1) pspace_relation_cte_wp_at[rotated 1]; (assumption | clarsimp)?)\n  apply (drule cte_wp_at_norm')\n  apply clarsimp\n  apply (rule_tac x=\"cteCap cte\" in exI)\n  apply (auto elim: cte_wp_at_weakenE' dest!: curthread_relation)\n  done\n\ntext \\<open>Note we can wrap it all up in corressimp\\<close>\n\nlemma set_vm_root_for_flush_corres':\n  notes [corres] = gct_corres getSlotCap_corres\n  shows\n  \"corres (=)\n          (cur_tcb and vspace_at_asid asid pd\n           and K (asid \\<noteq> 0 \\<and> asid \\<le> mask asid_bits)\n           and valid_asid_map and valid_vs_lookup\n           and valid_vspace_objs and valid_global_objs\n           and unique_table_refs o caps_of_state\n           and valid_arch_state\n           and pspace_aligned and pspace_distinct)\n          (pspace_aligned' and pspace_distinct' and no_0_obj')\n          (set_vm_root_for_flush pd asid)\n          (setVMRootForFlush pd asid)\"\n  apply (simp add: set_vm_root_for_flush_def setVMRootForFlush_def getThreadVSpaceRoot_def locateSlot_conv)\n  apply (corressimp search: arm_context_switch_corres\n                        wp: get_cap_wp getSlotCap_wp\n                      simp: isCap_simps)\n  apply (rule context_conjI)\n  subgoal by (simp add: cte_map_def objBits_simps tcb_cnode_index_def\n                        tcbVTableSlot_def to_bl_1 cte_level_bits_def)\n  apply (rule context_conjI)\n  subgoal by (fastforce simp: cur_tcb_def intro!: tcb_at_cte_at_1[simplified])\n  apply (rule conjI)\n   subgoal by (fastforce)\n  apply (drule cte_wp_at_ex)\n  apply clarsimp\n  apply (drule (1) pspace_relation_cte_wp_at[rotated 1]; (assumption | clarsimp)?)\n  apply (drule cte_wp_at_norm')\n  apply clarsimp\n  apply (rule_tac x=\"cteCap cte\" in exI)\n  apply (auto elim: cte_wp_at_weakenE' dest!: curthread_relation)\n  done\n*)\n\nend\nend\n", "meta": {"author": "CompSoftVer", "repo": "CSim2", "sha": "b09a4d77ea089168b1805db5204ac151df2b9eff", "save_path": "github-repos/isabelle/CompSoftVer-CSim2", "path": "github-repos/isabelle/CompSoftVer-CSim2/CSim2-b09a4d77ea089168b1805db5204ac151df2b9eff/lib/Corres_Test.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.27791048282710323}}
{"text": "section \\<open> Hiding \\<close>\n\ntheory utp_circus_hiding\nimports utp_circus_parallel\nbegin\n\nsubsection \\<open> Hiding in peri- and postconditions \\<close>\n\ndefinition hide_rea (\"hide\\<^sub>r\") where\n[upred_defs]: \"hide\\<^sub>r P E = (\\<^bold>\\<exists> s \\<bullet> (P\\<lbrakk>$tr^\\<^sub>u\\<guillemotleft>s\\<guillemotright>,(\\<guillemotleft>E\\<guillemotright>\\<union>\\<^sub>u$ref\\<acute>)/$tr\\<acute>,$ref\\<acute>\\<rbrakk> \\<and> $tr\\<acute> =\\<^sub>u $tr^\\<^sub>u(\\<guillemotleft>s\\<guillemotright>\\<restriction>\\<^sub>u\\<guillemotleft>-E\\<guillemotright>)))\"\n\nlemma hide_rea_CRR_closed [closure]: \n  assumes \"P is CRR\"\n  shows \"hide\\<^sub>r P E is CRR\"\nproof -\n  have \"CRR(hide\\<^sub>r (CRR P) E) = hide\\<^sub>r (CRR P) E\"\n    by (rel_auto, fastforce+)\n  thus ?thesis\n    by (metis Healthy_def' assms)\nqed\n\nlemma hide_rea_CDC [closure]:\n  assumes \"P is CDC\"\n  shows \"hide\\<^sub>r P E is CDC\"\nproof -\n  have \"CDC(hide\\<^sub>r (CDC P) E) = hide\\<^sub>r (CDC P) E\"\n    by (rel_blast)\n  thus ?thesis\n    by (simp add: Healthy_if Healthy_intro assms)\nqed\n\nlemma hide_rea_false [rpred]: \"hide\\<^sub>r false E = false\"\n  by (rel_auto)\n\nlemma hide_rea_disj [rpred]: \"hide\\<^sub>r (P \\<or> Q) E = (hide\\<^sub>r P E \\<or> hide\\<^sub>r Q E)\"\n  by (rel_auto)\n\nlemma hide_rea_csp_enable [rpred]: \n  \"hide\\<^sub>r \\<E>(s, t, E) F = \\<E>(s \\<and> E - \\<guillemotleft>F\\<guillemotright> =\\<^sub>u E, t \\<restriction>\\<^sub>u \\<guillemotleft>-F\\<guillemotright>, E)\"\n  by (rel_auto)\n\nlemma hide_rea_csp_do [rpred]: \"hide\\<^sub>r \\<Phi>(s,\\<sigma>,t) E = \\<Phi>(s,\\<sigma>,t \\<restriction>\\<^sub>u \\<guillemotleft>-E\\<guillemotright>)\"\n  by (rel_auto)\n\nlemma filter_eval [simp]: \n  \"(bop Cons x xs) \\<restriction>\\<^sub>u E = (bop Cons x (xs \\<restriction>\\<^sub>u E) \\<triangleleft> x \\<in>\\<^sub>u E \\<triangleright> xs\\<restriction>\\<^sub>uE)\"\n  by (rel_simp)\n\nlemma hide_rea_seq [rpred]:\n  assumes \"P is CRR\" \"$ref\\<acute> \\<sharp> P\" \"Q is CRR\" \n  shows \"hide\\<^sub>r (P ;; Q) E = hide\\<^sub>r P E ;; hide\\<^sub>r Q E\"\nproof -\n  have\"hide\\<^sub>r (CRR(\\<exists> $ref\\<acute> \\<bullet> P) ;; CRR(Q)) E = hide\\<^sub>r (CRR(\\<exists> $ref\\<acute> \\<bullet> P)) E ;; hide\\<^sub>r (CRR Q) E\"\n    apply (simp add: hide_rea_def usubst unrest CRR_seqr_form)\n    apply (simp add: CRR_form)\n    apply (rel_auto)\n    using seq_filter_append apply fastforce\n    apply (metis seq_filter_append)\n    done\n  thus ?thesis\n    by (simp add: Healthy_if assms ex_unrest)\nqed\n\nlemma hide_rea_true_R1_true [rpred]: \n  \"hide\\<^sub>r (R1 true) A ;; R1 true = R1 true\"\n  by (rel_auto, metis append_Nil2 seq_filter_Nil)\n\nlemma hide_rea_shEx [rpred]: \"hide\\<^sub>r (\\<^bold>\\<exists> i \\<bullet> P(i)) cs = (\\<^bold>\\<exists> i \\<bullet> hide\\<^sub>r (P i) cs)\"\n  by (rel_auto)\n\nlemma hide_rea_empty [rpred]: \n  assumes \"P is RR\"\n  shows \"hide\\<^sub>r P {} = P\"\nproof -\n  have \"hide\\<^sub>r (RR P) {} = (RR P)\"\n    by (rel_auto; force)\n  thus ?thesis\n    by (simp add: Healthy_if assms)\nqed\n\nlemma hide_rea_twice [rpred]: \"hide\\<^sub>r (hide\\<^sub>r P A) B = hide\\<^sub>r P (A \\<union> B)\"\n  apply (rel_auto)\n  apply (metis (no_types, opaque_lifting) semilattice_sup_class.sup_assoc)\n  apply (metis (no_types, lifting) semilattice_sup_class.sup_assoc seq_filter_twice)\n  done\n\nlemma st'_unrest_hide_rea [unrest]: \"$st\\<acute> \\<sharp> P \\<Longrightarrow> $st\\<acute> \\<sharp> hide\\<^sub>r P E\"\n  by (simp add: hide_rea_def unrest)\n\nlemma ref'_unrest_hide_rea [unrest]: \"$ref\\<acute> \\<sharp> P \\<Longrightarrow> $ref\\<acute> \\<sharp> hide\\<^sub>r P E\"\n  by (simp add: hide_rea_def unrest usubst)\n\nsubsection \\<open> Hiding in preconditions \\<close>\n\ndefinition abs_rea :: \"('s, 'e) action \\<Rightarrow> 'e set \\<Rightarrow> ('s, 'e) action\" (\"abs\\<^sub>r\") where\n[upred_defs]: \"abs\\<^sub>r P E = (\\<not>\\<^sub>r (hide\\<^sub>r (\\<not>\\<^sub>r P) E ;; true\\<^sub>r))\"\n\nlemma abs_rea_false [rpred]: \"abs\\<^sub>r false E = false\"\n  by (rel_simp, metis append.right_neutral seq_filter_Nil)\n\nlemma abs_rea_conj [rpred]: \"abs\\<^sub>r (P \\<and> Q) E = (abs\\<^sub>r P E \\<and> abs\\<^sub>r Q E)\"\n  by (rel_blast)\n\nlemma abs_rea_true [rpred]: \"abs\\<^sub>r true\\<^sub>r E = true\\<^sub>r\"\n  by (rel_auto)\n\nlemma abs_rea_RC_closed [closure]:\n  assumes \"P is CRR\"\n  shows \"abs\\<^sub>r P E is CRC\"\nproof -\n  have \"RC1 (abs\\<^sub>r (CRR P) E) = abs\\<^sub>r (CRR P) E\"\n    apply (rel_auto)\n    apply (metis order_refl)\n    apply blast\n    done\n  hence \"abs\\<^sub>r P E is RC1\"\n    by (simp add: assms Healthy_if Healthy_intro closure)\n  thus ?thesis\n    by (rule_tac CRC_intro'', simp_all add: abs_rea_def closure assms unrest)\nqed\n\nlemma hide_rea_impl_under_abs:\n  assumes \"P is CRC\" \"Q is CRR\"\n  shows \"(abs\\<^sub>r P A \\<Rightarrow>\\<^sub>r hide\\<^sub>r (P \\<Rightarrow>\\<^sub>r Q) A) = (abs\\<^sub>r P A \\<Rightarrow>\\<^sub>r hide\\<^sub>r Q A)\"\n  by (simp add: RC1_def abs_rea_def rea_impl_def rpred closure assms unrest)\n     (rel_auto, metis order_refl )\n\nlemma abs_rea_not_CRR: \"P is CRR \\<Longrightarrow> abs\\<^sub>r (\\<not>\\<^sub>r P) E = (\\<not>\\<^sub>r hide\\<^sub>r P E ;; R1 true)\"\n  by (simp add: abs_rea_def rpred closure)\n\nlemma abs_rea_wpR [rpred]: \n  assumes \"P is CRR\" \"$ref\\<acute> \\<sharp> P\" \"Q is CRC\"\n  shows \"abs\\<^sub>r (P wp\\<^sub>r Q) A = (hide\\<^sub>r P A) wp\\<^sub>r (abs\\<^sub>r Q A)\"\n  by (simp add: wp_rea_def abs_rea_not_CRR hide_rea_seq assms closure)\n     (simp add: abs_rea_def rpred closure assms seqr_assoc)\n\nlemma abs_rea_empty [rpred]: \n  assumes \"P is RC\"\n  shows \"abs\\<^sub>r P {} = P\"\nproof -\n  have \"abs\\<^sub>r (RC P) {} = (RC P)\"\n    apply (rel_auto)\n    apply (metis diff_add_cancel_left' order_refl plus_list_def)\n    done\n  thus ?thesis\n    by (simp add: Healthy_if assms)\nqed\n\n\nlemma abs_rea_twice [rpred]: \n  assumes \"P is CRC\"\n  shows \"abs\\<^sub>r (abs\\<^sub>r P A) B = abs\\<^sub>r P (A \\<union> B)\" (is \"?lhs = ?rhs\")\nproof -\n  have \"?lhs = abs\\<^sub>r (\\<not>\\<^sub>r hide\\<^sub>r (\\<not>\\<^sub>r P) A ;; R1 true) B\"\n    by (simp add: abs_rea_def)\n  thus ?thesis\n    by (simp add: abs_rea_def rpred closure unrest seqr_assoc assms)\nqed\n\nsubsection \\<open> Hiding Operator \\<close>\n\ntext \\<open> In common with the UTP book definition of hiding, this definition does not introduce\n  divergence if there is an infinite sequence of events that are hidden. For this, we would\n  need a more complex precondition which is left for future work. \\<close>\n\ndefinition HideCSP  :: \"('s, 'e) action \\<Rightarrow> 'e set \\<Rightarrow> ('s, 'e) action\" (infixl \"\\\\\\<^sub>C\" 80) where \n  [upred_defs]: \n  \"HideCSP P E = \\<^bold>R\\<^sub>s(abs\\<^sub>r(pre\\<^sub>R(P)) E \\<turnstile> hide\\<^sub>r (peri\\<^sub>R(P)) E \\<diamondop> hide\\<^sub>r (post\\<^sub>R(P)) E)\"\n\nlemma HideCSP_rdes_def [rdes_def]:\n  assumes \"P is CRC\" \"Q is CRR\" \"R is CRR\"\n  shows \"\\<^bold>R\\<^sub>s(P \\<turnstile> Q \\<diamondop> R) \\\\\\<^sub>C A = \\<^bold>R\\<^sub>s(abs\\<^sub>r(P) A \\<turnstile> hide\\<^sub>r Q A \\<diamondop> hide\\<^sub>r R A)\" (is \"?lhs = ?rhs\")\nproof -\n  have \"?lhs = \\<^bold>R\\<^sub>s (abs\\<^sub>r P A \\<turnstile> hide\\<^sub>r (P \\<Rightarrow>\\<^sub>r Q) A \\<diamondop> hide\\<^sub>r (P \\<Rightarrow>\\<^sub>r R) A)\"\n    by (simp add: HideCSP_def rdes assms closure)\n  also have \"... = \\<^bold>R\\<^sub>s (abs\\<^sub>r P A \\<turnstile> (abs\\<^sub>r P A \\<Rightarrow>\\<^sub>r hide\\<^sub>r (P \\<Rightarrow>\\<^sub>r Q) A) \\<diamondop> (abs\\<^sub>r P A \\<Rightarrow>\\<^sub>r hide\\<^sub>r (P \\<Rightarrow>\\<^sub>r R) A))\"\n    by (metis RHS_tri_design_conj conj_idem utp_pred_laws.sup.idem)\n  also have \"... = ?rhs\"\n    by (metis RHS_tri_design_conj assms conj_idem hide_rea_impl_under_abs utp_pred_laws.sup.idem)\n  finally show ?thesis .\nqed\n\nlemma HideCSP_NCSP_closed [closure]: \"P is NCSP \\<Longrightarrow> P \\\\\\<^sub>C E is NCSP\"\n  by (simp add: HideCSP_def closure unrest)\n\nlemma HideCSP_C2_closed [closure]: \n  assumes \"P is NCSP\" \"P is C2\"\n  shows \"P \\\\\\<^sub>C E is C2\"\n  by (rdes_simp cls: assms, simp add: C2_rdes_intro closure unrest assms)\n\nlemma HideCSP_CACT_closed [closure]:\n  assumes \"P is CACT\"\n  shows \"P \\\\\\<^sub>C E is CACT\"\n  by (rule CACT_intro, simp_all add: closure assms)\n\nlemma HideCSP_Chaos: \"Chaos \\\\\\<^sub>C E = Chaos\"\n  by (rdes_simp)\n\nlemma HideCSP_Miracle: \"Miracle \\\\\\<^sub>C A = Miracle\"\n  by (rdes_eq)\n\nlemma HideCSP_AssignsCSP:\n  \"\\<langle>\\<sigma>\\<rangle>\\<^sub>C \\\\\\<^sub>C A = \\<langle>\\<sigma>\\<rangle>\\<^sub>C\"\n  by (rdes_eq)\n\nlemma HideCSP_cond:\n  assumes \"P is NCSP\" \"Q is NCSP\"\n  shows \"(P \\<triangleleft> b \\<triangleright>\\<^sub>R Q) \\\\\\<^sub>C A = (P \\\\\\<^sub>C A \\<triangleleft> b \\<triangleright>\\<^sub>R Q \\\\\\<^sub>C A) \"\n  by (rdes_eq cls: assms)\n\nlemma HideCSP_int_choice:\n  assumes \"P is NCSP\" \"Q is NCSP\"\n  shows \"(P \\<sqinter> Q) \\\\\\<^sub>C A = (P \\\\\\<^sub>C A \\<sqinter> Q \\\\\\<^sub>C A) \"\n  by (rdes_eq cls: assms)\n\nlemma HideCSP_guard:\n  assumes \"P is NCSP\"\n  shows \"(b &\\<^sub>C P) \\\\\\<^sub>C A = b &\\<^sub>C (P \\\\\\<^sub>C A)\"\n  by (rdes_eq cls: assms)\n\nlemma HideCSP_seq:\n  assumes \"P is NCSP\" \"Q is NCSP\"\n  shows \"(P ;; Q) \\\\\\<^sub>C A = (P \\\\\\<^sub>C A ;; Q \\\\\\<^sub>C A)\"\n  by (rdes_eq_split cls: assms)\n\nlemma HideCSP_DoCSP [rdes_def]: \n  \"do\\<^sub>C(a) \\\\\\<^sub>C A = (Skip \\<triangleleft> (a \\<in>\\<^sub>u \\<guillemotleft>A\\<guillemotright>) \\<triangleright>\\<^sub>R do\\<^sub>C(a))\"\n  by (rdes_eq)\n\nlemma HideCSP_PrefixCSP:\n  assumes \"P is NCSP\"\n  shows \"(a \\<rightarrow>\\<^sub>C P) \\\\\\<^sub>C A = ((P \\\\\\<^sub>C A) \\<triangleleft> (a \\<in>\\<^sub>u \\<guillemotleft>A\\<guillemotright>) \\<triangleright>\\<^sub>R (a \\<rightarrow>\\<^sub>C (P \\\\\\<^sub>C A)))\"\n  apply (simp add: PrefixCSP_def Healthy_if HideCSP_seq HideCSP_DoCSP closure assms rdes rpred)\n  apply (simp add: HideCSP_NCSP_closed Skip_left_unit assms cond_st_distr)\n  done\n\nlemma HideCSP_empty:\n  assumes \"P is NCSP\" \n  shows \"P \\\\\\<^sub>C {} = P\"\n  by (rdes_eq cls: assms)\n\nlemma HideCSP_twice:\n  assumes \"P is NCSP\" \n  shows \"P \\\\\\<^sub>C A \\\\\\<^sub>C B = P \\\\\\<^sub>C (A \\<union> B)\"\n  by (rdes_simp cls: assms)\n\nlemma HideCSP_Skip: \"Skip \\\\\\<^sub>C A = Skip\"\n  by (rdes_eq)\n\nlemma HideCSP_Stop: \"Stop \\\\\\<^sub>C A = Stop\"\n  by (rdes_eq)\n\nend", "meta": {"author": "isabelle-utp", "repo": "utp-main", "sha": "27bdf3aee6d4fc00c8fe4d53283d0101857e0d41", "save_path": "github-repos/isabelle/isabelle-utp-utp-main", "path": "github-repos/isabelle/isabelle-utp-utp-main/utp-main-27bdf3aee6d4fc00c8fe4d53283d0101857e0d41/theories/circus/utp_circus_hiding.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5156199157230157, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.27791048282710323}}
{"text": "(* module countermem(clk,rst,counter,d,addr,q);\n    parameter\t    MSBD = 63;\n    parameter\t    DEPTH = 31;\n    parameter\t    MSBA = 4;\n    input\t    clk;\n    input           rst;\n    input [MSBD:0]  d;\n    input [MSBA:0]  addr;\n    input\t    counter;\n    output [MSBD:0] q;\n\n\n    reg [MSBD:0]    mem[0:DEPTH];\n    reg [MSBA:0]    write_addr;\n     //wire [MSBA:0]  read_addr;\n\tinteger i;\n\n\tinitial begin\n\tfor (i = 0; i <= DEPTH; i = i + 1)\n\t    mem[i] = 0;\n \twrite_addr = 0;\n    end // initial begin\n\n\n    always @ (posedge clk) begin\n\tif (rst) write_addr = 0;\n\telse if (counter) begin\n\t\tmem[write_addr] = d;\n\t    write_addr = write_addr +1;\n\tend \n    end // always @ (posedge clock)\n\t\n    assign q = mem[write_addr-1-addr];\n\nendmodule // *)\ntheory counter imports paraGste1\nbegin\nabbreviation rst::\"varType\" where\n\"rst \\<equiv>  (Ident ''rst'')\"\n\nabbreviation last::\"varType\" where\n\"last \\<equiv>  (Ident ''last'')\"\n\n\n\ndefinition  vertexI::\"node\" where [simp]:\n\"vertexI \\<equiv>Vertex  0\"\n\n\ndefinition  vertexL::\"nat \\<Rightarrow> node list\" where [simp]:\n\"vertexL DEPTH  \\<equiv>  (map (%i. Vertex  i) (upt 0 ( DEPTH +2)))\"\n\nlemma testUpto: \"upt 0 2=[0,1]\"\n  by (simp add: upt_rec) \n\ndefinition edgeL::\"nat \\<Rightarrow> edge list\" where [simp]:\n \"edgeL DEPTH \\<equiv>   (Edge (Vertex (DEPTH +1)) (Vertex 1))#\n\t  (map (%i.  ( Edge (Vertex ( i ))  (Vertex (  i + 1 ))) ) (upt 0  (DEPTH +1) )) \"\n\nlemma testUpto1:\"upt 1 3=[Suc 0,2]\" \nby (simp add: upt_rec) \n\nprimrec node2Nat::\"node \\<Rightarrow> nat\" where\n\"node2Nat (Vertex n) = n\"\n\nabbreviation LOW::\"expType\" where\n\"LOW \\<equiv> Const (boolV False)\"\nabbreviation HIGH::\"expType\" where\n\"HIGH \\<equiv> Const (boolV True)\"\n\nabbreviation rstForm::\"formula\" where\n\"rstForm  \\<equiv>  (eqn (IVar rst) HIGH)\" \n\ndefinition antOfCounterMem::\"edge\\<Rightarrow>formula\" where [simp]:\n\"antOfCounterMem    edge\\<equiv>\n  (let from=node2Nat (source edge) in\n   let to=node2Nat (sink edge) in\n     if (\tfrom = 0) then rstForm\telse\n      (neg rstForm))\"\n\n\n\ndefinition consOfCounterMem::\" edge \\<Rightarrow>formula\" where  [simp]:\n\"consOfCounterMem     edge \\<equiv>\n(let from=node2Nat (source edge) in\n let to=node2Nat (sink edge) in\n if \t(from =0 ) then\n  chaos\n else \n  eqn (IVar last) (Const (index (from - 1)))\n \n  )\"\n\ndefinition counterGsteSpec::\" nat\\<Rightarrow>gsteSpec\" where  [simp]:\n\"counterGsteSpec DEPTH\\<equiv>Graph  vertexI (edgeL  DEPTH ) \n  (antOfCounterMem  )  (consOfCounterMem )\"\n\n\n\ndefinition tagFunOfCounterMem:: \" nat\\<Rightarrow>nodeTagFuncList\" where [simp]:\n\"tagFunOfCounterMem  DEPTH  n \\<equiv> \n  let x=node2Nat n in\n   if (x = 0) then [] else\n        [eqn (IVar last) (Const (index (x - 1)))]\n \"\n \n abbreviation branch1::\"generalizeStatement\" where \n\"branch1 \\<equiv> \n  let S1=assign (last,(Const (index 0))) in\n   Parallel [S1]\"\n   \nabbreviation branch2::\"nat\\<Rightarrow>generalizeStatement\" where \n\"branch2 DEPTH \\<equiv> \n  let S1= assign (last, \n    iteForm (eqn (IVar last) (Const (index DEPTH)))  (Const (index 0)) \n    (uif ''+'' [IVar last, (Const (index 1))])) in\n   Parallel [S1]\"   \n   \n\nabbreviation counterMem::\" nat\\<Rightarrow>generalizeStatement\" where\n\"counterMem  DEPTH\\<equiv> \n  caseStatement \n     [(eqn (IVar rst) HIGH, branch1),\n      (neg (eqn (IVar rst) HIGH ), branch2 DEPTH)] \n   \"\n   \n\nconsts J::\"  interpretFunType\"  \n  \n\naxiomatization where axiomOnIAdd [simp,intro]:\n\" J ''+'' [index m, index (Suc 0)] = index ((m + 1))\"  \n\nlemma consistencyOfcounterMem:\n  assumes a:\"0 < DEPTH \"\n  shows \"consistent' (counterMem DEPTH ) (J) (counterGsteSpec DEPTH ) \n  (tagFunOfCounterMem DEPTH)\"\n  proof(unfold consistent'_def,rule allI,rule impI)\n    fix e\n    let ?G=\" (counterGsteSpec DEPTH )\"\n    let ?M=\"(counterMem DEPTH   )\"\n    let ?tag=\"(tagFunOfCounterMem   DEPTH)\"\n    let ?P =\"\\<lambda>e.   \n    (let f=andListForm (?tag (sink e)) in\n    let f'=andListForm (?tag (source e)) in\n    tautlogy (implyForm (andForm f' (antOf ?G e)) (preCond1  f  ( ?M))) (J))\"\n    \n    assume a1:\"e \\<in> edgesOf (counterGsteSpec DEPTH )\"\n    \n    have \"e=Edge vertexI ( Vertex 1) | \n          e=Edge  ( Vertex (DEPTH+1)) ( Vertex 1)  |\n           (\\<exists>i. 1\\<le>i \\<and> i\\<le> DEPTH  \\<and>  e=( Edge (Vertex i)  (Vertex (  i+1 ))) )    \"\n      apply(cut_tac a a1,auto)  done\n    \n    moreover\n    {assume b1:\"e=Edge vertexI ( Vertex 1)\"\n     have \"?P e\"\n     apply(cut_tac a b1, simp  )\n     done\n     }\n     moreover\n    {assume b1:\"e=Edge  ( Vertex (DEPTH+1)) ( Vertex 1)\"\n     have \"?P e\"\n       apply(cut_tac a b1, simp )\n       done\n     \n     } \n    moreover\n    {assume b1:\" (\\<exists>i. 1\\<le>i \\<and> i\\<le> DEPTH  \\<and>  e=( Edge (Vertex i)  (Vertex (  i + 1 ))) )  \" (is \"\\<exists>i. ?asm i\")\n     from b1 obtain i where b2:\"?asm i\" by auto\n     \n      have \"?P e\"\n        apply(cut_tac a b2 , auto  simp add:   Let_def)\n        done\n    }\n    ultimately show \"?P e\" by satx\nqed\n    \n\nlemma instImply:\nassumes a:\"G=(counterGsteSpec DEPTH)\" and b:\"0 < DEPTH \"  and c:\"tag=tagFunOfCounterMem  DEPTH\"\nshows\n\"\\<forall> e. e \\<in>edgesOf G\\<longrightarrow> \ntautlogy (implyForm (andForm (antOf G e) (andListForm (tag (source e)))) (consOf G e)) (J)\"  \nproof(rule allI,rule impI,simp,rule allI,rule impI)\n  fix e s\n  assume a1:\"e \\<in> edgesOf G \" and a2:\"\n           formEval (J) (antOf G e) s \\<and> formEval (J) (andListForm (tag (source e))) s\" \n  let ?P =\"\\<lambda>e. formEval (J) (consOf G e) s\"           \n  have \"e=Edge vertexI ( Vertex 1) | \n          e=Edge  ( Vertex (DEPTH+1)) ( Vertex 1)  |\n           (\\<exists>i. 1\\<le>i \\<and> i\\<le> DEPTH  \\<and>  e=( Edge (Vertex i)  (Vertex (  i+1 ))) ) \"\n         apply(cut_tac  a a1,auto)   done\n    moreover\n    {assume b1:\"e=Edge vertexI ( Vertex 1)\"\n     have \"?P e\"\n     apply(cut_tac a b1, auto) done\n     }\n\n    moreover\n    {assume b1:\"e=Edge ( Vertex (DEPTH+1)) ( Vertex 1)\"\n     have \"?P e\"\n       apply(cut_tac a b c a1 a2 b1, auto) \n       done\n     }\n\n    moreover\n    {assume b1:\" (\\<exists>i. 1\\<le>i \\<and> i\\<le> DEPTH  \\<and>  e=( Edge (Vertex i)  (Vertex (  i+1 ))) )   \" (is \"\\<exists>i. ?asm i\")\n     from b1 obtain i where b2:\"?asm i\" by auto\n      \n      have \"?P e\"\n      proof(cut_tac a b c a2 b2, auto) qed\n     \n    }\n      \n    ultimately show \"?P e\" by satx\n  qed      \n\nlemma main: \nassumes a:\"G=(counterGsteSpec DEPTH  )\" and b:\"0 < DEPTH \" \nand c:\"tag=tagFunOfCounterMem   DEPTH\" and\nd:\"M=(counterMem DEPTH )\"\nshows \" circuitSatGsteSpec M G (J)\"  \nproof(rule mainLemma)\nhave a1:\"consistent' (counterMem DEPTH ) (J ) (counterGsteSpec DEPTH  ) (tagFunOfCounterMem   DEPTH)\" \n   using b by (rule   consistencyOfcounterMem)\nfrom a c d this show \"consistent' M   (J) G tag\"\n  by simp   \nnext\nfrom a b c show \"\\<forall>e. e \\<in> edgesOf G \\<longrightarrow>\n        tautlogy (implyForm (andForm (antOf G e) (andListForm (tag (source e)))) (consOf G e)) (J)\"\napply(rule instImply) done\nnext\nfrom a c show \"tag (initOf G) = []\"\napply auto done\nqed\nend\n", "meta": {"author": "lyj238Gmail", "repo": "gsteProof", "sha": "3070d08e1f31a93be6fde85ab6b65d489c05f99e", "save_path": "github-repos/isabelle/lyj238Gmail-gsteProof", "path": "github-repos/isabelle/lyj238Gmail-gsteProof/gsteProof-3070d08e1f31a93be6fde85ab6b65d489c05f99e/counter.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5156199157230156, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.2779104828271032}}
{"text": "\\<^marker>\\<open>creator Bernhard Pöttinger\\<close>\n\ntheory Effectively_Acyclic_Maintain\n  imports Effectively_Acyclic Effectively_Acyclic_Sourced_Path Effectively_Acyclic_Approximations\n    Effectively_Acyclic_Equal_Capacity\nbegin\n\nparagraph \\<open>Summary\\<close>\ntext \\<open>This theory proves @{cite \\<open>th. 3\\<close> krishna20} / @{cite \\<open>th. 3.38\\<close> krishna19a}.\n\nThe proof structure of theorem 3 is:\ntheorem 3 (@{term maintain_eff_acyclic_dom})\n- case @{term \"dom_fg h1 = dom_fg h1'\"} (@{term maintain_eff_acyclic_dom_eq})\n  - Effective Acyclicity (@{term maintain_eff_acyclic_dom_eq'})\n  - Subflowpreserving Extension (part of @{term maintain_eff_acyclic_dom})\n- case @{term \"dom_fg h1 \\<subset> dom_fg h1'\"} (@{term maintain_eff_acyclic_dom_ne})\n\\<close>\nsection \\<open>Proof of Theorem 3.38\\<close>\n\ntext \\<open>Auxiliary lemma\\<close>\n\nlemma alt_edge:\n  fixes h h1 h2 :: \"('n,'m :: cancel_comm_monoid_add) fg\"\n  assumes \"\\<forall>x y. edge_fg h2 x y \\<in> E\" \"\\<forall>x y. edge_fg h1 x y \\<in> E\" \"End_closed E\" \"xs \\<noteq> []\"\n  shows \"\\<And>x y. edge_fg (alt h1 h2 xs) x y \\<in> E\"\nproof (goal_cases)\n  case (1 x y)\n  have \"alt h1 h2 xs \\<in> {h1,h2}\" using alt_in[of xs h1 h2] assms by simp\n  then consider (a) \"alt h1 h2 xs = h1\" | (b) \"alt h1 h2 xs = h2\" by blast\n  then show ?case\n  proof cases\n    case a\n    with assms show ?thesis by simp\n  next\n    case b\n    with assms show ?thesis by simp\n  qed\nqed\n\ntext \\<open>Part on effective acyclicity of Case 1 (@{term \"h1 = dom_fg h1'\"}) of Theorem 3 in\n@{cite krishna20}, factored out to address symmetric cases\\<close>\n\nlemma maintain_eff_acyclic_dom_eq':\n  fixes E :: \"('a \\<Rightarrow> 'a :: pos_cancel_comm_monoid_add) set\"\n  assumes \"pointwise_reduced E\" \"h = h1 + h2\" \"h \\<noteq> bot\" \"h' = h1' + h2'\" \"h' \\<noteq> bot\" \"h1' \\<noteq> bot\"\n    \"h1 \\<lesssim>\\<^sub>S h1'\" \"dom_fg h1' \\<inter> dom_fg h2' = {}\"\n    \"\\<forall>n \\<in> dom_fg h1' - dom_fg h1. outf_fg h2 n = 0\"\n    \"\\<forall>x y. edge_fg h x y \\<in> E\"\n    \"eff_acyclic' h\" \"eff_acyclic' h1\" \"eff_acyclic' h1'\" \"eff_acyclic' h2\" \"eff_acyclic' h2'\"\n    \"dom_fg h1 = dom_fg h1'\" \"dom_fg h2 = dom_fg h2'\" \"End_closed E\" \"id \\<in> E\"\n    \"\\<forall>x y. edge_fg h2 x y \\<in> E\" \"\\<forall>x y. edge_fg h1 x y \\<in> E\" \"\\<forall>x y. edge_fg h1' x y \\<in> E\"\n    \"\\<forall>x y. edge_fg h2' x y \\<in> E\" \"\\<forall>x y. edge_fg (h1' + h2') x y \\<in> E\"\n    \"(\\<lambda>_. 0) \\<in> E\" \"id \\<in> E\"\n    \"\\<forall>n\\<in>dom_fg h1. \\<forall>n'\\<in>- dom_fg h1'. \\<forall>m\\<le>inf_fg h1 n. cap_fg h1 n n' m = cap_fg h1' n n' m\"\n    \"\\<forall>n\\<in>dom_fg h2. \\<forall>n'\\<in>- dom_fg h2'. \\<forall>m\\<le>inf_fg h2 n. cap_fg h2 n n' m = cap_fg h2' n n' m\"\n    \"\\<forall>x y. edge_fg (h1 + h2) x y \\<in> E\"\n    and nbot: \"h1' + h2' \\<noteq> bot\" \"int_fg (h1' + h2') = int_fg (h1 + h2)\"\n    and infeq: \"inf_fg (h1' + h2') = inf_fg (h1 + h2)\" \"int_fg h1' = int_fg h1\"\n    and False: \"\\<not> (set ns \\<subseteq> dom_fg h1' \\<or> set ns \\<subseteq> dom_fg h2')\"\n    and True: \"hd ns \\<in> dom_fg h1'\"\n    and nsdef:\n    \"chain (edge_fg (h1' + h2')) ns n (inf_fg (h1 + h2) (hd ns)) \\<noteq> 0\"\n    \"n \\<in> set ns\" \"set ns \\<subseteq> dom_fg (h1' + h2')\"\n  shows False\nproof -\n  have *: \"h1 \\<noteq> bot\" \"h2 \\<noteq> bot\" using assms plus_fg_ops_exist by metis+\n\n  let ?h' = \"h1' + h2'\"\n  let ?h = \"h1 + h2\"\n  let ?e' = \"edge_fg ?h'\"\n  let ?e1' = \"edge_fg h1'\"\n  let ?e2' = \"edge_fg h2'\"\n  let ?e = \"edge_fg h\" let ?e1 = \"edge_fg h1\" let ?e2 = \"edge_fg h2\"\n  let ?f' = \"flow_fg ?h'\"\n  let ?N' = \"dom_fg ?h'\"\n  let ?N1 = \"dom_fg h1\"\n  let ?N2 = \"dom_fg h2\"\n  let ?N1' = \"dom_fg h1'\"\n  let ?N = \"dom_fg h\" let ?Na = \"dom_fg h1\" let ?Nb = \"dom_fg h2\"\n  let ?i = \"inf_fg ?h\"\n  let ?i' = \"inf_fg ?h'\"\n  let ?i1 = \"inf_fg h1\"\n  let ?f = \"flow_fg (h1 + h2)\"\n  let ?f1 = \"flow_fg h1\"\n  let ?f1' = \"flow_fg h1'\"\n  let ?i1' = \"inf_fg h1'\"\n  let ?i2' = \"inf_fg h2'\"\n\n  let ?g1 = \"\\<lambda>xs y. if set xs \\<subseteq> ?Na then cap' (card ?Na) ?Na ?e' (hd (xs @ [y])) y else if set xs \\<subseteq> ?Nb then cap' (card ?Nb) ?Nb ?e' (hd (xs @ [y])) y else 0\"\n  let ?g2 = \"\\<lambda>xs y. if set xs \\<subseteq> ?Na then cap' (card ?Na) ?Na ?e1' (hd (xs @ [y])) y else if set xs \\<subseteq> ?Nb then cap' (card ?Nb) ?Nb ?e2' (hd (xs @ [y])) y else 0\"\n  let ?g3 = \"\\<lambda>xs y. if set xs \\<subseteq> ?Na then cap' (card ?Na) ?Na ?e1 (hd (xs @ [y])) y else if set xs \\<subseteq> ?Nb then cap' (card ?Nb) ?Nb ?e2 (hd (xs @ [y])) y else 0\"\n  let ?altg2 = \"\\<lambda>h1 h2 xs y. if set xs \\<subseteq> dom_fg h1 then cap' (card (dom_fg h1)) (dom_fg h1) (edge_fg h1) (hd (xs @ [y])) y else if set xs \\<subseteq> dom_fg h2 then cap' (card (dom_fg h2)) (dom_fg h2) (edge_fg h2) (hd (xs @ [y])) y else 0\"\n  let ?altg3 = \"\\<lambda>h1 h2 xs y. if set xs \\<subseteq> dom_fg h1 then cap' (card (dom_fg h1)) (dom_fg h1) (edge_fg h1) (hd (xs @ [y])) y else if set xs \\<subseteq> dom_fg h2 then cap' (card (dom_fg h2)) (dom_fg h2) (edge_fg h2) (hd (xs @ [y])) y else 0\"\n  let ?g4 = \"\\<lambda>xs y. cap' (card ?N) ?N ?e (hd (xs @ [y])) y\"\n  let ?P = \"\\<lambda>ys. set ys \\<subseteq> ?Na \\<and> ys \\<noteq> [] \\<and> length ys \\<le> card ?Na\"\n  let ?Q = \"\\<lambda>ys. set ys \\<subseteq> ?Nb \\<and> ys \\<noteq> [] \\<and> length ys \\<le> card ?Nb\"\n  let ?altP = \"\\<lambda>h ys. set ys \\<subseteq> dom_fg h \\<and> ys \\<noteq> [] \\<and> length ys \\<le> card (dom_fg h)\"\n  let ?altQ = \"\\<lambda>h ys. set ys \\<subseteq> dom_fg h \\<and> ys \\<noteq> [] \\<and> length ys \\<le> card (dom_fg h)\"\n  let ?alte = \"\\<lambda>xs. if set xs \\<subseteq> ?Na then ?e1 else ?e2\"\n\n  let ?k = \"length ns\"\n\n  have dom: \"dom_fg h1' \\<inter> dom_fg h2' = {}\" \"ns \\<noteq> []\" \"set ns \\<subseteq> dom_fg h1' \\<union> dom_fg h2'\"\n    \"dom_fg h1' \\<inter> dom_fg h2' = {}\" \"?N1 \\<inter> ?N2 = {}\" \"?N1 \\<union> ?N2 = ?N\"\n    using False nsdef ck_lists_props[of ns \"dom_fg (h1' + h2')\" ?k] nbot\n    using assms apply blast\n    using nsdef nbot \\<open>h = h1 + h2\\<close> \\<open>h \\<noteq> bot\\<close> by auto\n\n  with False obtain n1 n2 where ***: \"n1 \\<in> set ns\" \"n2 \\<in> set ns\" \"n1 \\<notin> dom_fg h1'\"\n    \"n2 \\<notin> dom_fg h2'\" \"n1 \\<noteq> n2\" \"n1 \\<in> dom_fg h2'\" \"n2 \\<in> dom_fg h1'\"\n    by blast\n  then have \"length ns \\<ge> 2\"\n    using assms dom by (meson length_ge_2)\n  then have \"butlast ns \\<noteq> []\"\n    by (cases ns, simp_all, case_tac list, simp_all)\n\n  have \"\\<exists>xss. concat xss = ns \\<and> xss \\<noteq> [] \\<and> (\\<forall>xs\\<in>set xss. xs \\<noteq> []) \\<and>\n    alternating (segment_fg h1') (segment_fg h2') xss\"\n    apply (rule split_segments[of ns \"dom_fg h1'\" \"dom_fg h2'\"])\n    using True dom by simp_all\n  then obtain xss where xssdef: \"concat xss = ns\" \"xss \\<noteq> []\" \"\\<forall>xs \\<in> set xss. xs \\<noteq> []\"\n    \"alternating (segment_fg h1') (segment_fg h2') xss\"\n    by blast\n\n  have \"chain ?e' ns n = chains ?e' xss n\"\n    apply (subst chain_chains[of ns xss ?e' n], simp_all add: list.set_sel)\n    using xssdef by (simp_all add: list.set_sel(2))\n  also have \"... = chains' (chain ?e') xss n\"\n    by (induction xss, simp, case_tac xss, auto)\n  finally have XXX: \"chain ?e' ns n = chains' (chain ?e') xss n\" .\n\n  have \"hd ns = hd (hd xss)\"\n    using hd_hd_concat_hd[of ns xss] xssdef nsdef by simp\n  then have \"0 < chains' (chain ?e') xss n (?i (hd (hd xss)))\"\n    using nsdef XXX xssdef apply simp\n    using gr_zeroI by blast\n  also have \"... \\<le> chains' (chain ?e') xss n (?i1' (hd (hd xss)))\"\n    apply (subst infeq[symmetric])\n    apply (rule pos_endo_mono'_closed[OF inf_fg_le_inf_fg, where E=E])\n    using assms nbot xssdef nsdef apply blast\n    using xssdef nsdef apply (metis True concat.simps(2) hd_Cons_tl hd_append2 hd_in_set)\n    using assms apply blast+\n    apply (rule endo_chains'[OF \\<open>End_closed E\\<close>], clarsimp)\n    apply (rule endo_chain_closed)\n    using assms by (simp_all (no_asm))\n  finally have GGG: \"chains' (chain ?e') xss n (?i1' (hd (hd xss))) \\<noteq> 0\"\n    by simp\n  have altpq: \"alternating ?P ?Q xss\"\n    apply (subst \\<open>?N1 = ?N1'\\<close>)+\n    apply (subst \\<open>?N2 = dom_fg h2'\\<close>)+\n    apply (rule eff_acyclic_chain_length_le_card')\n    using xssdef nsdef \\<open>?N1 = ?N1'\\<close> apply simp\n    using assms nbot apply blast+\n    using GGG by simp\n\n  have ne: \"length xss \\<ge> 2\"\n    using length_ge_2_alternating[of ?N1 ?N2 n2 n1 xss] xssdef assms *** by metis\n  then have bl_xss_ne: \"butlast xss \\<noteq> []\"\n    by (cases xss, simp_all, case_tac list, simp_all)\n\n  have hdns: \"hd ns = hd (hd (butlast xss))\"\n  proof -\n    have B: \"hd (butlast xss) \\<noteq> []\"\n      using xssdef by (simp add: bl_xss_ne in_set_butlastD)\n    have C: \"hd (concat (butlast xss @ [last xss])) = hd ns\"\n      using xssdef by simp\n    then have D: \"hd (concat (butlast xss)) = hd ns\"\n      by (metis bl_xss_ne B concat_append concat_eq_Nil_conv hd_append2 hd_in_set)\n    then show ?thesis\n      apply (cases \"butlast xss\")\n      using bl_xss_ne apply blast\n      using B by auto\n  qed\n\n  have sum: \"h = h2 + h1\"\n    using \\<open>h = h1 + h2\\<close> by (simp add: algebra_simps)\n\n  show False\n  proof (cases \"n \\<in> set (last xss)\")\n    case True\n    show ?thesis\n    proof (cases \"hd (last xss) \\<in> ?Na\")\n      case True\n      then have \"\\<not> ?Q (last xss)\"\n        using dom \\<open>?N1 = ?N1'\\<close>\n        by (metis disjoint_iff_not_equal hd_in_set subsetD)\n      then have altv: \"alt h1' h2' xss = h1'\" \"alt h1 h2 xss = h1\"\n        using alt_odd[OF altpq xssdef(2), of h1' h2'] alt_odd[OF altpq xssdef(2), of h1 h2]\n        by simp_all\n      then have altv': \"alt h2 h1 (butlast xss) = h1\" \"alt h2' h1' (butlast xss) = h1'\"\n        using alt_butlast[OF \\<open>xss \\<noteq> []\\<close>, of h1 h2] alt_butlast[OF \\<open>xss \\<noteq> []\\<close>, of h1' h2']\n        by auto\n\n      have \"set (last xss) \\<subseteq> ?N1'\"\n        using alternating_props[OF altpq] True dom \\<open>?N1 = ?N1'\\<close> \\<open>xss \\<noteq> []\\<close>\n        by (metis \\<open>\\<not> ?Q (last xss)\\<close> last_in_set)\n\n      have AUX: \"xs \\<in> set xss \\<Longrightarrow> chain (edge_fg (h1' + h2')) xs y = alt_chain h1' h2' xs y\" for xs y\n      proof (goal_cases)\n        case 1\n        have \"\\<not> set xs \\<subseteq> dom_fg h1' \\<Longrightarrow> set xs \\<subseteq> dom_fg h2'\"\n          using dom alternating_props[OF xssdef(4)] 1 by blast\n        with 1 show ?case\n          apply (clarsimp, intro conjI impI)\n          apply (rule chain_cong'[OF edge_fg_plus_fg_on1[OF nbot(1)]], simp)\n          by (rule chain_cong'[OF edge_fg_plus_fg_on2[OF nbot(1)]], simp)\n      qed\n\n      have \"chains' (chain ?e') (butlast xss) (hd (last xss)) (?i (hd ns)) =\n          chains' (alt_chain h1' h2') (butlast xss) (hd (last xss)) (?i (hd ns))\"\n        apply (rule chains'_cong[OF AUX])\n        by (simp add: in_set_butlastD)\n      also have \"... \\<le> chains' (alt_chain h1' h2') (butlast xss) (hd (last xss)) (?i1' (hd ns))\"\n        apply (subst infeq(1)[symmetric])\n        apply (rule pos_endo_mono'_closed[where f=\"chains' _ _ _\" and E=E, OF inf_fg_le_inf_fg])\n        using \\<open>hd ns \\<in> dom_fg h1'\\<close> \\<open>?N1 = ?N1'\\<close> nbot\n        by (auto intro!: endo_chains' endo_chain_closed simp: assms)\n      also have \"... \\<le> inf_fg (alt h2' h1' (butlast xss)) (hd (last xss))\"\n        using chains'_chain_inf_fg_le_inf_fg[of h1' h2' \"butlast xss\" \"last xss\"] hdns assms\n          bl_xss_ne nbot alternating_to_alternating'[where xs=xss] xssdef\n        by (metis (no_types, lifting))\n      finally have DDD: \"chains' (chain ?e') (butlast xss) (hd (last xss)) (?i (hd ns)) \\<le>\n        inf_fg (alt h2' h1' (butlast xss)) (hd (last xss))\" .\n\n      have \"0 < chain ?e' ns n (?i (hd ns))\"\n        using nsdef gr_zeroI by blast\n      also have \"... = chains' (chain ?e') xss n (?i (hd ns))\"\n        using XXX by simp\n      also have \"... =\n        chain ?e' (last xss) n (chains' (chain ?e') (butlast xss) (hd (last xss)) (?i (hd ns)))\"\n        by (rule chains'_append1, simp add: \\<open>xss \\<noteq> []\\<close>)\n      also have \"... \\<le> chain ?e' (last xss) n (inf_fg (alt h2' h1' (butlast xss)) (hd (last xss)))\"\n        apply (rule pos_endo_mono'_closed[where f=\"chain _ _ _\", where E=E])\n        by (auto intro!: endo_chain_closed simp: assms DDD)\n      finally have \"0 \\<noteq> chain ?e' (last xss) n (inf_fg (alt h2' h1' (butlast xss)) (hd (last xss)))\"\n        by simp\n      then have Y: \"0 \\<noteq> chain ?e1' (last xss) n (inf_fg (alt h2' h1' (butlast xss)) (hd (last xss)))\"\n        apply (subst (asm) chain_cong')\n        apply (rule edge_fg_plus_fg_on1)\n        using nbot apply blast\n        using \\<open>set (last xss) \\<subseteq> dom_fg h1'\\<close> apply blast\n        by simp\n\n      show ?thesis\n        using contradict_eff_acyclic[of h1' \"last xss\" n E] altv' altv infeq Y nbot assms\n          \\<open>set (last xss) \\<subseteq> ?N1'\\<close> \\<open>n \\<in> set (last xss)\\<close> by metis\n    next\n      case False (* symmetric case *)\n      then have \"\\<not> ?P (last xss)\"\n        using dom \\<open>?N1 = ?N1'\\<close>\n        by (metis hd_in_set subsetD)\n      then have altv: \"alt h1' h2' xss = h2'\" \"alt h1 h2 xss = h2\"\n        using alt_even[OF altpq xssdef(2), of h1' h2'] alt_even[OF altpq xssdef(2), of h1 h2]\n        by simp_all\n      then have altv': \"alt h2' h1' (butlast xss) = h2'\"\n        using alt_butlast[OF \\<open>xss \\<noteq> []\\<close>, of h1' h2'] by simp\n\n      have \"set (last xss) \\<subseteq> ?N2\"\n        using alternating_props[OF altpq] True dom \\<open>?N1 = ?N1'\\<close> \\<open>xss \\<noteq> []\\<close>\n        by (metis \\<open>\\<not> ?P (last xss)\\<close> last_in_set)\n\n      have AUX: \"xs \\<in> set (butlast xss)\n        \\<Longrightarrow> chain (edge_fg (h1' + h2')) xs y = alt_chain h2' h1' xs y\" for xs y\n      proof (goal_cases)\n        case 1\n        have \"\\<not> set xs \\<subseteq> dom_fg h2' \\<Longrightarrow> set xs \\<subseteq> dom_fg h1'\"\n          using dom alternating_props[OF xssdef(4)] 1 by (meson in_set_butlastD)\n        with 1 show ?case\n          apply (clarsimp, intro conjI impI)\n          apply (rule chain_cong'[OF edge_fg_plus_fg_on2[OF nbot(1)]], simp)\n          by (rule chain_cong'[OF edge_fg_plus_fg_on1[OF nbot(1)]], simp)\n      qed\n\n      have AUX2: \"xs \\<in> set xss \\<Longrightarrow> alt_chain h1' h2' xs y = alt_chain h2' h1' xs y\" for xs y\n        using dom by (smt alternating_props disjoint_iff_not_equal list.set_sel(1) subsetD xssdef(4))\n\n      have \"chains' (chain ?e') (butlast xss) (hd (last xss)) (?i (hd ns)) =\n          chains' (alt_chain h2' h1') (butlast xss) (hd (last xss)) (?i (hd ns))\"\n        apply (rule chains'_cong[OF AUX])\n        by (simp add: in_set_butlastD)\n      also have \"... \\<le> chains' (alt_chain h2' h1') (butlast xss) (hd (last xss)) (?i1' (hd ns))\"\n        apply (subst infeq(1)[symmetric])\n        apply (rule pos_endo_mono'_closed[where f=\"chains' _ _ _\" and E=E, OF inf_fg_le_inf_fg])\n        using \\<open>hd ns \\<in> dom_fg h1'\\<close> \\<open>?N1 = ?N1'\\<close> nbot\n        by (auto intro!: endo_chains' endo_chain_closed simp: assms)\n      also have \"... \\<le> inf_fg (alt h2' h1' (butlast xss)) (hd (last xss))\"\n        apply (subst chains'_cong[OF AUX2[symmetric]], simp add: in_set_butlastD)\n        using chains'_chain_inf_fg_le_inf_fg[of h1' h2' \"butlast xss\" \"last xss\"] hdns assms\n          bl_xss_ne nbot alternating_to_alternating'[where xs=xss] xssdef\n        by (metis (no_types, lifting))\n      finally have DDD: \"chains' (chain ?e') (butlast xss) (hd (last xss)) (?i (hd ns)) \\<le>\n        inf_fg (alt h2' h1' (butlast xss)) (hd (last xss))\" .\n\n      have \"0 < chain ?e' ns n (?i (hd ns))\"\n        using nsdef gr_zeroI by blast\n      also have \"... = chains' (chain ?e') xss n (?i (hd ns))\"\n        using XXX by simp\n      also have \"... =\n        chain ?e' (last xss) n (chains' (chain ?e') (butlast xss) (hd (last xss)) (?i (hd ns)))\"\n        by (rule chains'_append1, simp add: \\<open>xss \\<noteq> []\\<close>)\n      also have \"... \\<le> chain ?e' (last xss) n (inf_fg (alt h2' h1' (butlast xss)) (hd (last xss)))\"\n        apply (rule pos_endo_mono'_closed[where f=\"chain _ _ _\", where E=E])\n        by (auto intro!: endo_chain_closed simp: assms DDD)\n      finally have \"0 \\<noteq> chain ?e' (last xss) n (inf_fg (alt h2' h1' (butlast xss)) (hd (last xss)))\"\n        by simp\n      then have Y: \"0 \\<noteq> chain ?e2' (last xss) n (inf_fg (alt h2' h1' (butlast xss)) (hd (last xss)))\"\n        apply (subst (asm) chain_cong')\n        apply (rule edge_fg_plus_fg_on2[of h1' h2'])\n        using nbot apply blast\n        using \\<open>set (last xss) \\<subseteq> dom_fg h2\\<close> assms apply blast\n        by simp\n\n      have \"h2' \\<noteq> bot\" using assms\n        by (meson plus_fg_bot_bot(2))\n\n      then show ?thesis\n        using contradict_eff_acyclic[of h2' \"last xss\" n E] altv' altv infeq Y nbot assms\n          \\<open>set (last xss) \\<subseteq> dom_fg h2\\<close> \\<open>n \\<in> set (last xss)\\<close> * by metis\n    qed\n  next\n    case False\n\n    have X1: \"\\<And>xs y x x'. ?P xs \\<Longrightarrow> x \\<le> x' \\<Longrightarrow> chain ?e' xs y x \\<le> ?g1 xs y x'\"\n      apply (split if_split, intro conjI impI, rule chain_le_cap'[where E=E])\n      using assms dom_fg_finite[of h1] unfolding zero_fun_def by blast+\n\n    have X2: \"\\<And>xs y x x'. ?Q xs \\<Longrightarrow> x \\<le> x' \\<Longrightarrow> chain ?e' xs y x \\<le> ?g1 xs y x'\"\n      apply (split if_split, intro conjI impI)\n      subgoal using dom(1) \\<open>?N1 = ?N1'\\<close>\n        by (metis assms(17) disjoint_iff_not_equal list.set_sel(1) subset_iff)\n      apply (split if_splits, intro conjI impI)\n      apply (rule chain_le_cap'[where E=E])\n      using assms dom_fg_finite[of h2] unfolding zero_fun_def by blast+\n\n    have X3: \"alternating ?P ?Q (butlast xss)\"\n      using alternating_append1[of ?P ?Q \"butlast xss\" \"[last xss]\"] altpq xssdef\n      by simp\n\n    have X4: \"\\<And>xs y x x'. ?P xs \\<Longrightarrow> x \\<le> x' \\<Longrightarrow> ?g1 xs y x \\<le> ?g2 xs y x'\"\n      apply simp\n      apply (subst \\<open>dom_fg h1 = dom_fg h1'\\<close>)+\n      apply (subst cap'_cong_e[OF edge_fg_plus_fg_on1], simp_all add: nbot)\n      apply (rule pos_endo_mono'_closed[OF _ endo_cap', where E=E])\n      using assms dom_fg_finite[of h1'] unfolding zero_fun_def by blast+\n\n    have X5: \"\\<And>xs y x x'. ?Q xs \\<Longrightarrow> x \\<le> x' \\<Longrightarrow> ?g1 xs y x \\<le> ?g2 xs y x'\"\n      apply clarsimp\n      apply (intro conjI impI)\n      apply (subst \\<open>dom_fg h1 = dom_fg h1'\\<close>)+\n      using \\<open>?N1' \\<inter> dom_fg h2' = {}\\<close> \\<open>?N1 = ?N1'\\<close>\n      apply (metis Int_subset_iff assms(17) set_empty subset_empty)\n      apply (subst \\<open>dom_fg h2 = dom_fg h2'\\<close>)+\n      apply (subst cap'_cong_e[OF edge_fg_plus_fg_on2], simp_all add: nbot)+\n      apply (rule pos_endo_mono'_closed[OF _ endo_cap', where E=E])\n      using assms dom_fg_finite[of h2'] unfolding zero_fun_def by blast+\n\n    have \"\\<exists>xs \\<in> set xss. n \\<in> set xs\"\n      using xssdef nsdef by auto\n    then obtain nss1 ns1 ns2 nss2 where nss: \"concat xss = concat nss1 @ ns1 @ n # ns2 @ concat nss2\"\n      \"xss = nss1 @ (ns1 @ n # ns2) # nss2\"\n      using split_list_list[of xss n] by auto\n\n    have nss2_ne: \"nss2 \\<noteq> []\" \"hd nss2 \\<noteq> []\"\n      using False nss apply auto[1]\n      using xssdef nss \n      by (metis (no_types, lifting) False Un_iff insert_iff last.simps last_appendR list.distinct(1)\n          list.set(2) list.set_sel(1) set_append)\n    then have blub: \"hd (concat nss2) = hd (hd nss2)\"\n      by (metis concat.simps(2) hd_Cons_tl hd_append2)\n\n    let ?c = \"chain ?e' (n # ns2 @ concat nss2) n\"\n    have \"?c \\<in> E\"\n      apply (rule endo_chain_closed, rule endo_edge_fg_plus_fg)\n      using \\<open>?h' \\<noteq> bot\\<close> assms unfolding zero_fun_def by blast+\n    then have red: \"\\<And>x. ?c x \\<noteq> 0 \\<Longrightarrow> ?c (?c x) \\<noteq> 0\"\n      using \\<open>pointwise_reduced E\\<close> unfolding pointwise_reduced_def comp_def zero_fun_def by simp\n\n    have \"chain ?e' (concat nss1 @ ns1 @ n # ns2 @ concat nss2) n (?i (hd ns)) \\<noteq> 0\"\n      using nsdef nss xssdef by metis\n    then have \"chain ?e' (n # ns2 @ concat nss2) n (chain ?e' (concat nss1 @ ns1) n (?i (hd ns))) \\<noteq> 0\"\n      using chain_append_nonempty[of ?e' \"concat nss1 @ ns1\" \"n # ns1 @ concat nss2\" n]\n      by (metis append_assoc chain_append_nonempty hd_append2 list.distinct(1) list.sel(1))\n    then have \"chain ?e' (n # ns2 @ concat nss2) n (chain ?e' (n # ns2 @ concat nss2) n (chain ?e' (concat nss1 @ ns1) n (?i (hd ns)))) \\<noteq> 0\"\n      using red by simp\n    then have \"chain ?e' (n # ns2) (hd (hd nss2)) (chain ?e' (n # ns2 @ concat nss2) n (chain ?e' (concat nss1 @ ns1) n (?i (hd ns)))) \\<noteq> 0\"\n      using chain_append_not_zero(1)[of \"n # ns2 @ concat nss2\" \"n # ns2\" \"concat nss2\" \"edge_fg (h1' + h2')\" n\n          \"chain (edge_fg (h1' + h2')) (n # ns2 @ concat nss2) n (chain (edge_fg (h1' + h2')) (concat nss1 @ ns1) n (inf_fg (h1 + h2) (hd ns)))\" E]\n      using nss2_ne blub nss xssdef \\<open>\\<forall>x y. edge_fg (h1' + h2') x y \\<in> E\\<close> \\<open>End_closed E\\<close> by simp\n    then have \"chain ?e' (n # ns2) (hd (hd nss2)) (chain ?e' (n # ns2 @ concat nss2) (hd ((n # ns2) @ [hd (hd nss2)])) (chain ?e' (concat nss1 @ ns1) n (?i (hd ns)))) \\<noteq> 0\"\n      by simp\n    then have \"chain ?e' (n # ns2 @ concat nss2 @ n # ns2) (hd (hd nss2)) (chain ?e' (concat nss1 @ ns1) n (?i (hd ns))) \\<noteq> 0\"\n      by (subst (asm) chain_append_nonempty[symmetric], simp)\n    then have \"chain ?e' (n # ns2 @ concat nss2 @ n # ns2) (hd (hd nss2)) (chain ?e' (concat nss1 @ ns1) (hd ((n # ns2 @ concat nss2 @ n # ns2) @ [hd (hd nss2)])) (?i (hd ns))) \\<noteq> 0\"\n      by simp\n    then have ne0: \"chain ?e' (concat nss1 @ ns1 @ n # ns2 @ concat nss2 @ n # ns2) (hd (hd nss2)) (?i (hd ns)) \\<noteq> 0\"\n      by (subst (asm) chain_append_nonempty[symmetric], simp)\n    then have \"0 < chain ?e' (concat nss1 @ ns1 @ n # ns2 @ concat nss2 @ n # ns2) (hd (hd nss2)) (?i (hd ns))\"\n      using gr_zeroI by blast\n    also have \"... = chain ?e' (concat nss1 @ ns1 @ n # ns2 @ concat nss2 @ n # ns2) (hd (hd nss2)) (?i' (hd ns))\"\n      using infeq(1) by auto\n    also have \"... \\<le> chain ?e' (concat nss1 @ ns1 @ n # ns2 @ concat nss2 @ n # ns2) (hd (hd nss2)) (?i1' (hd ns))\"\n      apply (rule pos_endo_mono'_closed[OF inf_fg_le_inf_fg[of h1' h2' \"hd ns\" E]])\n      using nbot True assms apply blast\n      using nbot True assms apply blast\n      using nbot True assms apply blast\n      apply (rule endo_chain_closed)\n      using nbot True assms by blast+\n    finally have ne00: \"chain ?e' (concat nss1 @ ns1 @ n # ns2 @ concat nss2 @ n # ns2) (hd (hd nss2)) (?i1' (hd ns)) \\<noteq> 0\" by simp\n\n    let ?ns = \"concat nss1 @ ns1 @ n # ns2 @ concat nss2 @ n # ns2\"\n    let ?n = \"hd (hd nss2)\"\n    let ?xss = \"xss @ [n # ns2]\"\n\n    have \"ns1 @ n # ns2 \\<in> set xss\"\n      using nss by simp\n    then have \"?P (ns1 @ n # ns2) \\<or> ?Q (ns1 @ n # ns2)\"\n      using alternating_props[OF altpq] by blast\n\n    have Y1: \"?n \\<in> set (map hd xss)\"\n      using nss nss2_ne by simp\n\n    have Y2: \"?ns = concat ?xss\"\n      using nss by simp\n\n    have Y3: \"?n \\<in> set (map hd ?xss)\"\n      using Y1 Y2 by simp\n\n    have \"last nss2 = last xss\"\n      using xssdef nss nss2_ne by simp\n\n    have \"\\<exists>xss. concat xss = ?ns \\<and> xss \\<noteq> [] \\<and> (\\<forall>xs\\<in>set xss. xs \\<noteq> []) \\<and>\n                  alternating (segment_fg h1) (segment_fg h2) xss\"\n      apply (rule split_segments[of ?ns ?N1 ?N2])\n      apply simp\n      apply simp\n      apply (intro conjI)\n      using assms nbot nsdef apply (metis dom_fg_plus_fg_iff in_mono)\n      using assms dom nss xssdef subgoal\n        by (metis set_append set_concat sup.boundedE)\n      using \\<open>len_segment_fg h1 (ns1 @ n # ns2) \\<or> len_segment_fg h2 (ns1 @ n # ns2)\\<close> apply auto[1]\n      using \\<open>len_segment_fg h1 (ns1 @ n # ns2) \\<or> len_segment_fg h2 (ns1 @ n # ns2)\\<close> apply auto[1]\n      using assms(16) assms(17) dom(3) nss(1) xssdef(1) apply auto[1]\n      using \\<open>len_segment_fg h1 (ns1 @ n # ns2) \\<or> len_segment_fg h2 (ns1 @ n # ns2)\\<close> apply auto[1]\n      by (simp add: True Y2 assms(16) dom(2) xssdef(1))\n    then obtain yss where yssdef: \"concat yss = ?ns\" \"yss \\<noteq> []\" \"\\<forall>xs\\<in>set yss. xs \\<noteq> []\"\n      \"alternating (segment_fg h1) (segment_fg h2) yss\"\n      by auto\n\n    have some_rule: \"alternating (segment_fg h1') (segment_fg h2') xs \\<Longrightarrow> xs = xs1 @ x1 # x2 # xs2 \\<Longrightarrow>\n                       segment_fg h1' x1 \\<longleftrightarrow> segment_fg h2' x2\" for xs xs1 x1 x2 xs2\n    proof -\n      assume A: \"alternating (segment_fg h1') (segment_fg h2') xs\" \"xs = xs1 @ x1 # x2 # xs2\"\n      have \"alternating (segment_fg h1') (segment_fg h2') xs1\"\n        using alternating_append1 A by auto\n      then show ?thesis\n        using A dom(3,4)\n        apply (induction xs1 arbitrary: xs rule: alternating_induct'_symmetric[where a=h1' and b=h2'])\n        apply simp\n        apply simp\n        apply (metis Int_commute Int_left_commute inf_bot_right le_iff_inf set_empty)\n        apply simp\n        subgoal premises prems for a b x y zs xs\n        proof -\n          have A: \"segment_fg b x1 = segment_fg a x2\"\n            using prems by auto\n          show ?thesis\n          proof (cases \"segment_fg b x1\")\n            case True\n            then have B1: \"\\<not> segment_fg a x1\" using prems\n              by (metis Int_assoc inf_bot_right le_iff_inf set_empty)\n            from True have B2: \"\\<not>segment_fg b x2\"\n              by (metis Int_assoc Int_empty_right A le_iff_inf prems set_empty)\n            show ?thesis using B1 B2 by auto\n          next\n            case False\n            then have B1: \"segment_fg a x1\" using prems\n              by (metis (mono_tags, lifting) UnCI alternating_props list.set_intros(1) set_append)\n            from A False have \"\\<not> segment_fg a x2\" by blast\n            then have \"\\<not>segment_fg b x1\" using prems by auto\n            then have B2: \"segment_fg b x2\"\n              using A prems alternating_props[of \"segment_fg a\" \"segment_fg b\" \"zs @ x1 # x2 # xs2\"]\n              by auto\n            show ?thesis using B1 B2 by auto\n          qed\n        qed\n        done\n    qed\n\n    have some_result: \"segment_fg h1' (ns1 @ n # ns2) \\<longleftrightarrow> segment_fg h2' (hd nss2)\"\n      apply (rule some_rule[of xss nss1 \"ns1 @ n # ns2\" \"hd nss2\" \"tl nss2\"])\n      using xssdef apply simp\n      using nss nss2_ne by simp\n    then have \"segment_fg h1' (n # ns2) \\<longleftrightarrow> segment_fg h2' (hd nss2)\"\n      using nss2_ne apply auto\n      using \\<open>len_segment_fg h1 (ns1 @ n # ns2) \\<or> len_segment_fg h2 (ns1 @ n # ns2)\\<close>\n      using assms(16) assms(17) dom(1) by auto\n\n    have HHH: \"set (n # ns2) \\<subseteq> dom_fg h1 \\<or> set (n # ns2) \\<subseteq> dom_fg h2\"\n      using \\<open>len_segment_fg h1 (ns1 @ n # ns2) \\<or> len_segment_fg h2 (ns1 @ n # ns2)\\<close> by auto\n\n    have BRUMM: \"\\<forall>xs \\<in> set xss. set xs \\<subseteq> dom_fg h1' \\<longleftrightarrow> \\<not> set xs \\<subseteq> dom_fg h2'\"\n      using nss xssdef dom nss2_ne\n      by (metis (no_types, lifting) Int_assoc alternating_props inf_bot_right le_iff_inf set_empty)\n\n    have \"\\<exists>ys yss. alternating' (segment_fg h1) (segment_fg h2) (butlast xss @ [last xss @ ys] @ yss) (hd nss2) \\<and>\n               concat nss1 @ ns1 @ n # ns2 @ concat nss2 @ n # ns2 = concat (butlast xss @ [last xss @ ys] @ yss) \\<and>\n               (\\<forall>xs\\<in>set xss. xs \\<noteq> []) \\<and> last xss @ ys \\<noteq> [] \\<and> (\\<forall>xs\\<in>set yss. xs \\<noteq> []) \\<and> ys @ concat yss = n # ns2 \\<and> (ys = [] \\<or> yss = [])\"\n      apply (rule split_segments_extend[of \"dom_fg h1\" \"dom_fg h2\" xss ?ns \"n # ns2\" \"hd nss2\"])\n      using xssdef nss \\<open>?N1 = ?N1'\\<close> \\<open>?N2 = dom_fg h2'\\<close> dom nsdef nbot nss2_ne HHH apply simp_all\n      apply blast\n      apply (meson disjoint_iff_not_equal dom(1))\n      subgoal premises prems using BRUMM nss nss2_ne by simp\n      using \\<open>segment_fg h1' (n # ns2) = segment_fg h2' (hd nss2)\\<close> by auto\n    then obtain zs zss where zss:\n      \"alternating' (segment_fg h1) (segment_fg h2) (butlast xss @ [last xss @ zs] @ zss) (hd nss2)\"\n      \"concat nss1 @ ns1 @ n # ns2 @ concat nss2 @ n # ns2 = concat (butlast xss @ [last xss @ zs] @ zss)\"\n      \"\\<forall>xs\\<in>set xss. xs \\<noteq> []\" \"last xss @ zs \\<noteq> []\" \"\\<forall>xs\\<in>set zss. xs \\<noteq> []\"\n      \"zs @ concat zss = n # ns2\" \"zs = [] \\<or> zss = []\" \"n # ns2 = zs @ concat zss\"\n      by (metis (no_types, lifting))\n    have zss': \"alternating (segment_fg h1) (segment_fg h2) (butlast xss @ [last xss @ zs] @ zss)\"\n      apply (rule alternating'_to_alternating)\n      using zss by blast\n\n    let ?zss = \"butlast xss @ [last xss @ zs] @ zss\"\n\n    have \"last xss = last nss2\" using nss nss2_ne by simp\n    moreover have \"butlast xss = nss1 @ (ns1 @ n # ns2) # butlast nss2\"\n      using nss nss2_ne by (simp add: butlast_append)\n    ultimately have WWW: \"?zss = nss1 @ (ns1 @ n # ns2) # butlast nss2 @ [last nss2 @ zs] @ zss\"\n      by simp\n    have n_hd: \"?n = hd (hd (butlast nss2 @ [last nss2 @ zs] @ zss))\"\n      by (metis \\<open>last xss = last nss2\\<close> append_self_conv2 hd_append2 last_in_set\n          list.sel(1) nss2_ne(1) snoc_eq_iff_butlast xssdef)\n    then have MMM: \"?n = hd (concat (butlast nss2 @ [last nss2 @ zs] @ zss))\"\n      using nss nss2_ne yssdef apply simp by (cases nss2, simp, case_tac list, simp, simp)\n\n    let ?uss = \"butlast nss2 @ [last nss2 @ zs] @ zss\"\n\n    have \"set (map hd xss) = set (map hd (butlast xss @ [last xss @ zs]))\"\n      using \\<open>xss \\<noteq> []\\<close> nss2_ne \\<open>\\<forall>xs\\<in>set xss. xs \\<noteq> []\\<close>\n      by (induction xss rule: list_nonempty_induct, simp_all)\n    then have n_in_hd_zss: \"?n \\<in> set (map hd ?zss)\"\n      using Y1 by auto\n\n    have www: \"hd (hd (butlast xss @ (last xss @ zs) # zss)) = hd ns\"\n      by (simp add: bl_xss_ne hdns)\n\n    have mmm: \"inf_fg (h1 + h2) (hd ns) \\<le> inf_fg h1' (hd (hd (butlast xss @ (last xss @ zs) # zss)))\"\n      apply (subst www, subst infeq(1)[symmetric])\n      apply (rule inf_fg_le_inf_fg)\n      using nbot apply simp\n      apply (simp add: True)\n      using assms by blast\n\n    have ttt: \"hd (hd (nss1 @ (ns1 @ zs @ concat zss) # butlast nss2 @ (last nss2 @ zs) # zss)) = hd ns\"\n      using xssdef nss zss by (metis \\<open>hd ns = hd (hd xss)\\<close> append_self_conv2 hd_append2 list.sel(1))\n\n    have zss_alt: \"alternating (len_segment_fg h1) (len_segment_fg h2) ?zss\"\n      apply (subst \\<open>?N1 = ?N1'\\<close>)+\n      apply (subst \\<open>?N2 = dom_fg h2'\\<close>)+\n      apply (rule eff_acyclic_chain_length_le_card'[where E=E and n=\"hd (hd nss2)\"])\n      using zss' \\<open>?N1 = ?N1'\\<close> \\<open>?N2 = dom_fg h2'\\<close> apply simp\n      using nbot apply blast\n      using assms apply blast\n      using assms apply blast\n      using assms apply blast\n      using assms apply blast\n      using assms apply blast\n      using assms apply blast\n      using assms apply blast\n      using assms apply blast\n      apply (subst chains'_chain, simp)\n      using xssdef zss apply safe\n      apply (metis (mono_tags, lifting) alternating_props zss')\n      apply (metis (mono_tags, lifting) alternating_props zss')+\n      apply (metis (no_types, lifting) append_Nil append_Nil2 bl_xss_ne concat.simps(1) concat.simps(2) concat_append hd_append2 hdns ne00)\n      apply (metis (no_types, lifting) append_Nil2 bl_xss_ne concat.simps(1) concat.simps(2) concat_append hd_append2 hdns ne00)\n      by (metis (no_types, lifting) append_Nil2 bl_xss_ne concat.simps(1) concat.simps(2) concat_append hd_append2 hdns ne00)\n\n    let ?PP = \"alt (len_segment_fg h2) (len_segment_fg h1) (nss1 @ [ns1 @ n # ns2])\"\n    let ?QQ = \"alt (len_segment_fg h1) (len_segment_fg h2) (nss1 @ [ns1 @ n # ns2])\"\n\n    have \"alternating (len_segment_fg h1) (len_segment_fg h2) (butlast (nss1 @ (ns1 @ n # ns2) # nss2) @ [last (nss1 @ (ns1 @ n # ns2) # nss2) @ zs] @ zss)\"\n      using zss_alt nss by simp\n    then have blub': \"alternating (len_segment_fg h1) (len_segment_fg h2) ((nss1 @ [ns1 @ n # ns2]) @ ?uss)\"\n      using nss WWW by auto\n    have uss_alt: \"alternating ?PP ?QQ ?uss\"\n      by (fact alternating_append2[OF blub'])\n\n    have blub': \"alternating (segment_fg h1') (segment_fg h2') ((nss1 @ [ns1 @ n # ns2] @ [hd nss2]) @ (tl nss2))\"\n      using xssdef nss nss2_ne by simp\n    have \"alternating' (\\<lambda>xs. set xs \\<subseteq> dom_fg h1') (\\<lambda>xs. set xs \\<subseteq> dom_fg h2') (butlast (nss1 @ [ns1 @ n # ns2] @ [hd nss2])) (last (nss1 @ [ns1 @ n # ns2] @ [hd nss2]))\"\n      by (rule alternating_to_alternating'[OF alternating_consequence[OF alternating_append1[OF blub']]], simp_all)\n    then have prefix_alt: \"alternating' (\\<lambda>xs. set xs \\<subseteq> dom_fg h1') (\\<lambda>xs. set xs \\<subseteq> dom_fg h2') (nss1 @ [ns1 @ n # ns2]) (hd nss2)\"\n      by (simp add: butlast_append)\n\n    have \"hd (concat (nss1 @ [ns1 @ n # ns2])) = hd ns\"\n      using xssdef nss yssdef\n      by (metis (no_types, lifting) concat.simps(1) concat.simps(2) concat_append hd_append list.sel(1))\n    then have S1: \"hd (concat (nss1 @ [ns1 @ n # ns2]) @ [hd (concat (butlast nss2 @ [last nss2 @ zs] @ zss) @ [hd (hd nss2)])]) = hd ns\"\n      by (metis \\<open>len_segment_fg h1 (ns1 @ n # ns2) \\<or> len_segment_fg h2 (ns1 @ n # ns2)\\<close> append_is_Nil_conv concat.simps(2) concat_append hd_append2)\n\n    have S2: \"hd ns = hd (hd (butlast (nss1 @ (ns1 @ n # ns2) # nss2) @ (last nss2 @ zs) # zss))\"\n      using xssdef nss yssdef bl_xss_ne hdns by auto\n    have S3: \"hd ns = hd (hd (nss1 @ [ns1 @ n # ns2]))\"\n      by (metis \\<open>hd ns = hd (hd xss)\\<close> append_self_conv2 hd_append2 list.sel(1) nss(2))\n\n    have dom_subs: \"dom_fg h1 \\<subseteq> dom_fg h\" \"dom_fg h2 \\<subseteq> dom_fg h\"\n      using assms(2) assms(3) by auto\n\n    have hds: \"\\<forall>ys \\<in> set ?zss. hd ys \\<in> dom_fg h\"\n      apply (rule alternatingD[OF zss_alt])\n      using dom_subs by fastforce+\n\n    have \"\\<And>a list. butlast nss2 = a # list \\<Longrightarrow> set (hd (butlast nss2)) \\<subseteq> dom_fg (h1' + h2')\"\n      using xssdef nss alternating_props[of \"segment_fg h1'\" \"segment_fg h2'\" xss] nss2_ne nbot\n      apply simp\n      by (metis (no_types, lifting) Un_iff append_butlast_last_id empty_set hd_append2 hd_in_set\n          list.sel(1) list.set_intros(1) sup.coboundedI1 sup.coboundedI2 sup_bot.right_neutral)\n    then have TOE: \"\\<And>a list. butlast nss2 = a # list \\<Longrightarrow> hd (hd (butlast nss2)) \\<in> dom_fg (h1' + h2')\"\n      using nss2_ne by (metis append_butlast_last_id hd_append2 hd_in_set in_mono list.simps(3))\n\n    have hd_hd_uss_in_h1h2: \"hd (hd ?uss) \\<in> dom_fg (h1 + h2)\"\n      apply (cases \"butlast nss2\")\n      using xssdef yssdef nss assms nss2_ne nsdef \\<open>h1' + h2' \\<noteq> bot\\<close>\n       apply (metis (no_types, lifting) Un_iff \\<open>last xss = last nss2\\<close> append_is_Nil_conv\n             append_self_conv2 hds list.set_sel(1) list.simps(3) set_append)\n      by (metis TOE assms dom(6) hd_append list.simps(3) nbot(1) plus_fg_dom_un)\n\n    have all_tl: \"\\<forall>x \\<in> set xs. P x \\<Longrightarrow> \\<forall>x \\<in> set (tl xs). P x\" for xs P\n      by (induction xs, simp_all)\n\n    have \"chain ?e' ?ns (hd (hd nss2)) = chains ?e' ?zss (hd (hd nss2))\"\n      apply (subst chain_chains[of ?ns ?zss ?e' \"(hd (hd nss2))\"], simp_all add: list.set_sel)\n      using yssdef zss xssdef zss' concat_append\n      apply (metis (no_types, lifting) append.right_neutral append_self_conv2 concat.simps(2))\n      by (rule all_tl, metis zss Un_iff in_set_butlastD insert_iff list.set(2) set_append)\n    also have \"... = chains' (chain ?e') ?zss (hd (hd nss2))\"\n      using chains'_chains[symmetric, of ?e' ?zss ?n] by auto\n    finally have XXX: \"chain ?e' ?ns ?n = chains' (chain ?e') ?zss ?n\" .\n\n    have alt_cases: \"\\<not> P z \\<Longrightarrow> \\<not> Q z \\<Longrightarrow> \\<not> alt P Q xs z\" for P Q xs z\n      by (induction xs arbitrary: P Q, auto)\n\n    have blub: \"\\<And>xs y. xs \\<in> set (butlast nss2 @ [last nss2 @ zs] @ zss) \\<Longrightarrow>\n   (if set xs \\<subseteq> dom_fg (alt h2 h1 (nss1 @ [ns1 @ n # ns2])) then cap_fg (alt h2 h1 (nss1 @ [ns1 @ n # ns2])) (hd (xs @ [y])) y\n   else if set xs \\<subseteq> dom_fg (alt h1 h2 (nss1 @ [ns1 @ n # ns2])) then cap_fg (alt h1 h2 (nss1 @ [ns1 @ n # ns2])) (hd (xs @ [y])) y else 0) =\n   (if set xs \\<subseteq> dom_fg h1 then cap_fg h1 (hd (xs @ [y])) y else if set xs \\<subseteq> dom_fg h2 then cap_fg h2 (hd (xs @ [y])) y else 0)\"\n    proof (goal_cases)\n      case (1 xs y)\n      then have **: \"xs \\<noteq> []\"\n        apply auto\n        using \\<open>last nss2 = last xss\\<close> zss apply auto[1]\n         apply (metis Un_iff \\<open>butlast xss = nss1 @ (ns1 @ n # ns2) # butlast nss2\\<close>\n            in_set_butlastD insert_iff list.set(2) set_append zss(3))\n        using zss by blast\n      let ?zs = \"nss1 @ [ns1 @ n # ns2]\"\n      have \"alt h1 h2 ?zs \\<in> {h1,h2}\" using alt_in[of ?zs h1 h2] by simp\n      then consider (a) \"alt h1 h2 ?zs = h1\" | (b) \"alt h1 h2 ?zs = h2\" by blast\n      then show ?case\n      proof cases\n        case a\n        from a have \"alt h2 h1 ?zs = h2\" using alt_comm[of h1 h2 ?zs] by simp\n        then show ?thesis\n          using 1 a dom ** apply simp\n          by (meson disjoint_iff_not_equal hd_in_set in_mono)\n      next\n        case b\n        from b have \"alt h2 h1 ?zs = h1\" using alt_comm[of h1 h2 ?zs] by simp\n        then show ?thesis\n          using 1 b dom ** by simp\n      qed\n    qed\n\n    have BRUM: \"hd (hd nss2) = hd (concat (butlast nss2 @ [last nss2 @ zs] @ zss) @ [hd (hd nss2)])\"\n      using nss2_ne by (simp add: hd_append MMM)\n\n    have AUXAUX:\n      \"alternating' (segment_fg h1) (segment_fg h2) xss ys \\<Longrightarrow> hd ys \\<in> dom_fg (alt h2 h1 xss)\"\n      for xss ys\n      by (induction xss rule: alternating'_induct'[where a=h1 and aa=h1 and bb=h2 and b=h2], auto)\n\n    have \"0 < chain ?e' ?ns ?n (?i (hd ns))\"\n      using ne0 nss gr_zeroI by metis\n    also have \"... = chains' (chain ?e') ?zss ?n (?i (hd ns))\"\n      using XXX by simp\n    also have \"... \\<le> chains' ?g1 ?zss ?n (?i (hd ns))\"\n      by (rule alternating_chains'_mono[OF zss_alt X1 X2], simp_all)\n    also have \"... \\<le> chains' ?g2 ?zss ?n (?i (hd ns))\"\n      by (rule alternating_chains'_mono[OF zss_alt X4 X5], simp_all add: assms)\n    also have \"... = chains' ?g3 ?zss ?n (?i (hd ns))\"\n      apply (subst \\<open>dom_fg h1 = dom_fg h1'\\<close>)\n      apply (subst \\<open>dom_fg h1 = dom_fg h1'\\<close>)\n      apply (subst \\<open>dom_fg h1 = dom_fg h1'\\<close>)\n      apply (subst \\<open>dom_fg h2 = dom_fg h2'\\<close>)\n      apply (subst \\<open>dom_fg h2 = dom_fg h2'\\<close>)\n      apply (subst \\<open>dom_fg h2 = dom_fg h2'\\<close>)\n      apply (rule chains'_switch_world[of h1 h2 ?zss \"hd nss2\" h1' h2' E \"?i (hd ns)\"])\n      using nss xssdef yssdef apply simp_all\n      subgoal using nss2_ne zss apply safe using zss by simp_all\n      using \\<open>?N1 = ?N1'\\<close> apply simp\n      using assms nss2_ne apply (simp_all (no_asm_simp))\n          apply (metis Un_iff in_set_butlastD zss(3) zss(5))\n         apply presburger\n        apply presburger\n       apply blast\n      apply (subst S2, rule inf_fg_le_inf_fg)\n        apply blast\n      using S2 True by presburger\n    also have \"... \\<le> chains' ?g3 ?zss ?n (?i1 (hd ns))\"\n      apply (rule pos_endo_mono'_closed[OF inf_fg_le_inf_fg])\n      using assms apply blast\n      using True assms(16) apply blast\n        apply blast\n       apply (rule endo_chains')\n      using assms apply blast\n        apply auto[1]\n      by (auto simp: assms endo_cap')+\n    also have \"... = chains' ?g3 ?uss ?n (chains' ?g3 (nss1 @ [ns1 @ n # ns2]) (hd (concat ?uss @ [?n])) (?i1 (hd ns)))\"\n      apply (rule chains'_append) using WWW apply simp using zss by (smt alternating_props zss')\n    also have \"... = chains' ?g3 ?uss ?n (chains' ?g3 (nss1 @ [ns1 @ n # ns2]) (hd (concat ?uss @ [?n])) (?i1 (hd (hd (nss1 @ [ns1 @ n # ns2])))))\"\n      using S3 by simp\n    also have \"... = chains' ?g3 ?uss ?n (chains' ?g3 (nss1 @ [ns1 @ n # ns2]) (hd (hd nss2)) (?i1 (hd (hd (nss1 @ [ns1 @ n # ns2])))))\"\n      by (metis (no_types, lifting) append_self_conv2 hd_append2 list.sel(1) MMM)\n    also have \"... \\<le> chains' ?g3 ?uss ?n (inf_fg (alt h2 h1 (nss1 @ [ns1 @ n # ns2])) (hd (hd nss2)))\"\n      apply (rule pos_endo_mono'_closed[where E=E and f=\"chains' ?g3 ?uss ?n\", OF chains'_cap_fg_inf_fg_le_inf_fg'[of \"\\<lambda>h1' xs. set xs \\<subseteq> dom_fg h1'\" h1 h2 _ _ h E]])\n      apply (simp only: prefix_alt \\<open>?N1 = ?N1'\\<close> \\<open>?N2 = dom_fg h2'\\<close>)\n      using assms apply blast+\n      using assms apply (simp_all (no_asm) add: zero_fun_def)\n      apply (metis Un_iff \\<open>butlast xss = nss1 @ (ns1 @ n # ns2) # butlast nss2\\<close> in_set_butlastD set_append zss(3))\n      using  zss nss \n      subgoal premises prems proof -\n        have \"alternating (segment_fg h1) (segment_fg h2) ((nss1 @ [ns1 @ n # ns2]) @ butlast nss2 @ [last nss2 @ zs] @ zss)\"\n          using zss' WWW by simp\n        then have \"alt (segment_fg h2) (segment_fg h1) (nss1 @ [ns1 @ n # ns2]) (hd (butlast nss2 @ [last nss2 @ zs]))\"\n          using alternating_append_inner[of \"segment_fg h1\" \"segment_fg h2\" \"nss1 @ [ns1 @ n # ns2]\" \"butlast nss2 @ [last nss2 @ zs] @ zss\"] nss2_ne\n          by (metis (no_types, lifting) append_is_Nil_conv append_self_conv2 hd_append2 list.simps(3))\n        then have \"segment_fg (alt h2 h1 (nss1 @ [ns1 @ n # ns2])) (hd (butlast nss2 @ [last nss2 @ zs]))\"\n          by (subst (asm) alt_P_P_hom[of segment_fg h2 h1], simp)\n        then show ?thesis using nss2_ne zss(6)\n          by (metis (no_types, lifting) append_Nil2 append_butlast_last_id list.set_sel(1) n_hd subsetD zss(7))\n      qed\n      apply (rule endo_chains'[where E=E], simp_all (no_asm), intro allI conjI impI)\n      by (rule endo_cap'[where E=E], simp_all (no_asm) add: zero_fun_def)+\n    also have \"... \\<le> (\\<Sum>xs\\<in>l_lists' (dom_fg h) (card (dom_fg h) * length ?uss). chain (edge_fg h) (hd (hd ?uss) # xs) ?n (inf_fg (alt h2 h1 (nss1 @ [ns1 @ n # ns2])) (hd (hd nss2))))\"\n      apply (subst chains'_cong[OF blub[symmetric]], simp)\n      apply (rule chains'_cap_inf_le_chain_sum[where E=E])\n      apply (rule alternating_consequence[OF uss_alt])\n      apply (safe, induction nss1 arbitrary: h1 h2, simp)\n      apply auto[1]\n      apply simp\n      subgoal premises prems for x\n      proof -\n        have \"\\<not> (alt (len_segment_fg h2) (len_segment_fg h1) (nss1 @ [ns1 @ n # ns2]) [])\"\n          by (rule alt_cases, auto)\n        then show False using prems by auto\n      qed\n      apply (induction nss1 arbitrary: h1 h2)\n      apply auto[1]\n      apply simp\n      subgoal premises prems for x\n      proof -\n        have \"\\<not> (alt (len_segment_fg h1) (len_segment_fg h2) (nss1 @ [ns1 @ n # ns2]) [])\"\n          by (rule alt_cases, auto)\n        then show False using prems by auto\n      qed\n      using \\<open>h \\<noteq> bot\\<close> apply blast\n      using alt_sum[of h2 h1] \\<open>h = h1 + h2\\<close> apply (auto simp: algebra_simps)[1]\n      subgoal apply simp using zss nss xssdef nss2_ne\n        by (metis (no_types, lifting) Un_iff in_set_butlastD insert_iff last_in_set list.set(2) set_append)\n      subgoal apply (subst alt_alt_to_alt) using AUXAUX[OF zss(1)] WWW by simp\n      subgoal using nss xssdef zss' alternating_props[OF zss'] WWW nsdef \\<open>?N1 = ?N1'\\<close> \\<open>?N2 = dom_fg h2'\\<close> \\<open>h = h1 + h2\\<close> \\<open>h \\<noteq> bot\\<close>\n        by (smt UnCI plus_fg_dom_un set_append set_subset_Cons subsetD)\n      using \"***\"(7) assms dom_subs(1) apply blast\n      using assms apply blast\n      using alt_edge assms\n      apply (metis \\<open>len_segment_fg h1 (ns1 @ n # ns2) \\<or> len_segment_fg h2 (ns1 @ n # ns2)\\<close> append_is_Nil_conv concat.simps(1) concat.simps(2))\n      using alt_edge assms\n      apply (metis \\<open>len_segment_fg h1 (ns1 @ n # ns2) \\<or> len_segment_fg h2 (ns1 @ n # ns2)\\<close> append_is_Nil_conv concat.simps(1) concat.simps(2))\n      using assms apply simp_all\n      using nss2_ne apply (cases nss2, blast)\n      by (metis append_self_conv2 hd_append2 list.sel(1) list.simps(3) n_hd order_refl)\n    finally obtain ys where ys: \"ys \\<in> l_lists' (dom_fg h) (card (dom_fg h) * length (butlast nss2 @ [last nss2 @ zs] @ zss))\"\n      \"chain ?e (hd (hd ?uss) # ys) ?n (inf_fg (alt h2 h1 (nss1 @ [ns1 @ n # ns2])) (hd (concat ?uss @ [?n]))) \\<noteq> 0\"\n      by (smt gr_implies_not_zero sum.not_neutral_contains_not_neutral nss2_ne BRUM)\n\n    have alternating'_append1: \"alternating' P Q (xs @ ys) z \\<Longrightarrow> ys \\<noteq> [] \\<Longrightarrow> alternating' P Q xs (hd ys)\" for P Q xs ys z\n      by (induction xs arbitrary: P Q, auto, cases ys, auto)\n\n    show False\n      apply (rule contradict_eff_acyclic_flow[OF \\<open>eff_acyclic' h\\<close>, where E=E and ns=\"hd (hd ?uss) # ys\" and n=\"?n\"])\n      subgoal proof -\n        let ?zs = \"nss1 @ [ns1 @ n # ns2]\"\n\n        have ALT: \"alternating' (segment_fg h1) (segment_fg h2) (nss1 @ (ns1 @ n # ns2) # butlast nss2 @ [last nss2 @ zs] @ zss) (hd nss2)\"\n          using WWW zss by presburger\n\n        have \"alternating' (segment_fg h1) (segment_fg h2) ?zs (hd (butlast nss2 @ [last nss2 @ zs] @ zss))\"\n          apply (rule alternating'_append1[of _ _ ?zs \"butlast nss2 @ [last nss2 @ zs] @ zss\"])\n          using ALT by auto\n        then have ALT: \"alternating' (segment_fg h1) (segment_fg h2) ?zs (hd (butlast nss2 @ [last nss2 @ zs]))\"\n          using nss2_ne\n          by (metis (no_types, lifting) append_self_conv2 hd_append2 not_Cons_self2)\n\n        have S: \"hd (concat (butlast nss2 @ [last nss2 @ zs] @ zss) @ [hd (hd nss2)]) = hd (hd (hd (butlast nss2 @ [last nss2 @ zs] @ zss)) # ys)\"\n          using nss2_ne by (cases nss2, simp, simp)\n\n        have BRUM2: \"hd (hd (butlast nss2 @ [last nss2 @ zs])) = hd (concat (butlast nss2 @ [last nss2 @ zs] @ zss) @ [hd (hd nss2)])\"\n          using nss2_ne BRUM n_hd zss(7) by auto\n\n        have \"0 < chain ?e (hd (hd ?uss) # ys) ?n (inf_fg (alt h2 h1 ?zs) (hd (concat ?uss @ [?n])))\"\n          using ys gr_zeroI by auto\n        also have \"... \\<le> chain ?e (hd (hd ?uss) # ys) ?n (flow_fg h (hd (concat ?uss @ [?n])))\"\n          using alternating_inf_fg_flow_fg[OF _ _ _ zss(1)]\n          apply simp using n_hd[symmetric] BRUM2[symmetric] apply simp\n          apply (rule pos_endo_mono'_closed[where f=\"chain _ _ _\" and E=E, OF alternating_inf_fg_flow_fg[OF _ _ _ ALT]])\n          using assms apply blast\n          using assms apply blast\n            apply (metis \\<open>last xss = last nss2\\<close> append_Nil append_butlast_last_id hd_append2 list.sel(1) nss2_ne(1) nss2_ne(2) zss(4))\n           apply (simp add: assms(10) assms(18) endo_chain_closed_nonempty)\n          using assms by blast\n        finally show ?thesis \n          using S by simp\n      qed\n      subgoal using nss2_ne apply (cases nss2, simp, simp, intro conjI)\n        using assms(2) hd_hd_uss_in_h1h2 n_hd apply auto[1]\n        using ys unfolding l_lists'_def by simp\n      subgoal using nss2_ne by (cases nss2, simp, simp)\n      using assms by blast+\n  qed\nqed\n\n\ntext \\<open>Case 1 (@{term \"h1 = dom_fg h1'\"}) of Theorem 3 in @{cite krishna20}\\<close>\n\nlemma maintain_eff_acyclic_dom_eq:\n  fixes E :: \"('a \\<Rightarrow> 'a :: pos_cancel_comm_monoid_add) set\"\n  assumes \"pointwise_reduced E\" \"h = h1 + h2\" \"h \\<noteq> bot\" \"h1' \\<noteq> bot\" \"h1 \\<lesssim>\\<^sub>S h1'\" \"dom_fg h1' \\<inter> dom_fg h2 = {}\"\n    \"\\<forall>n \\<in> dom_fg h1' - dom_fg h1. outf_fg h2 n = 0\"\n    \"\\<forall>x y. edge_fg h x y \\<in> E\"\n    \"eff_acyclic' h\" \"eff_acyclic' h1\" \"eff_acyclic' h1'\" \"eff_acyclic' h2\"\n    \"dom_fg h1 = dom_fg h1'\" \"End_closed E\" \"id \\<in> E\"\n    \"\\<forall>x y. edge_fg h2 x y \\<in> E\" \"\\<forall>x y. edge_fg h1 x y \\<in> E\" \"\\<forall>x y. edge_fg h1' x y \\<in> E\" \"\\<forall>x y. edge_fg (h1' + h2) x y \\<in> E\"\n    \"(\\<lambda>_. 0) \\<in> E\" \"id \\<in> E\"\n    \"\\<forall>n\\<in>dom_fg h1. \\<forall>n'\\<in>- dom_fg h1'. \\<forall>m\\<le>inf_fg h1 n. cap_fg h1 n n' m = cap_fg h1' n n' m\"\n    \"\\<forall>n\\<in>dom_fg h2. \\<forall>n'\\<in>- dom_fg h2. \\<forall>m\\<le>inf_fg h2 n. cap_fg h2 n n' m = cap_fg h2 n n' m\" \"\\<forall>x y. edge_fg (h1 + h2) x y \\<in> E\"\n  shows \"\\<exists>h'. h' = h1' + h2 \\<and> h' \\<noteq> bot \\<and> eff_acyclic' h' \\<and> h \\<lesssim>\\<^sub>S h'\"\nproof -\n  have *: \"h1 \\<noteq> bot\" \"h2 \\<noteq> bot\" using assms plus_fg_ops_exist by auto\n  then have **: \"int_fg h1 = int_fg h1'\" \"\\<forall>n \\<in> dom_fg h1. \\<forall>n' \\<in> -dom_fg h1. \\<forall>m \\<le> inf_fg h1 n. cap_fg h1 n n' m = cap_fg h1' n n' m\"\n    using assms unfolding subflow_preserving_extension_def contextual_extension_def int_fg_def by (auto intro: fi_cong)\n\n  have nbot: \"h1' + h2 \\<noteq> bot\" \"int_fg (h1' + h2) = int_fg (h1 + h2)\"\n    using assms int_fg_fi_hom[of h1' h2] int_fg_fi_hom[of h1 h2] **\n    by (metis int_fg_bot_bot int_fg_bot_bot')+\n  then have infeq: \"inf_fg (h1' + h2) = inf_fg (h1 + h2)\" \"int_fg h1' = int_fg h1\"\n    using int_fg_to_inf_fg ** by auto\n\n  let ?h2' = \"h2\"\n  have ext2: \"\\<forall>n \\<in> dom_fg h2. \\<forall>n' \\<in> -dom_fg h2. \\<forall>m \\<le> inf_fg h2 n. cap_fg h2 n n' m = cap_fg ?h2' n n' m\"\n    by simp\n\n  have ea_h1'h2: \"eff_acyclic' (h1' + ?h2')\"\n  proof (rule ccontr)\n    let ?h' = \"h1' + h2\"\n    let ?h = \"h1 + h2\"\n    let ?e' = \"edge_fg ?h'\"\n    let ?e1' = \"edge_fg h1'\"\n    let ?e2' = \"edge_fg h2\"\n    let ?e = \"edge_fg h\" let ?e1 = \"edge_fg h1\" let ?e2 = \"edge_fg h2\"\n    let ?f' = \"flow_fg ?h'\"\n    let ?N' = \"dom_fg ?h'\"\n    let ?N1 = \"dom_fg h1\"\n    let ?N2 = \"dom_fg h2\"\n    let ?N1' = \"dom_fg h1'\"\n    let ?N = \"dom_fg h\" let ?Na = \"dom_fg h1\" let ?Nb = \"dom_fg h2\"\n    let ?i = \"inf_fg ?h\"\n    let ?i' = \"inf_fg ?h'\"\n    let ?i1 = \"inf_fg h1\"\n    let ?f = \"flow_fg (h1 + h2)\"\n    let ?f1 = \"flow_fg h1\"\n    let ?f1' = \"flow_fg h1'\"\n    let ?i1' = \"inf_fg h1'\"\n    let ?i2' = \"inf_fg ?h2'\"\n\n    assume \"\\<not> eff_acyclic' ?h'\"\n    then have \"\\<exists>xs y. chain (edge_fg (h1' + h2)) xs y (inf_fg (h1 + h2) (hd xs)) \\<noteq> 0 \\<and>\n                      y \\<in> set xs \\<and> set xs \\<subseteq> dom_fg (h1' + h2)\"\n      apply (rule eff_acyclic_sourced_path_in_bigraph[of h1' h2 h1 h2 E])\n      using assms nbot infeq apply blast+\n      using assms unfolding zero_fun_def apply simp\n      using infeq apply simp\n      using ** assms by blast+\n    then obtain ns n where nsdef:\n      \"chain (edge_fg (h1' + h2)) ns n (inf_fg (h1 + h2) (hd ns)) \\<noteq> 0\"\n      \"n \\<in> set ns\" \"set ns \\<subseteq> dom_fg (h1' + h2)\"\n      by blast\n\n    let ?k = \"length ns\"\n\n    show False\n    proof (cases \"set ns \\<subseteq> dom_fg h1' \\<or> set ns \\<subseteq> dom_fg h2\")\n      case True\n      then consider (a) \"set ns \\<subseteq> dom_fg h1'\" | (b) \"set ns \\<subseteq> dom_fg h2\"\n        by auto\n      then show ?thesis\n      proof (cases)\n        case a\n        have \"0 < chain ?e1' ns n (?i' (hd ns))\"\n          using nsdef assms a infeq chain_cong'[OF edge_fg_plus_fg_on1[of h1' h2], of \"ns\" n] nbot\n          by (metis gr_zeroI)\n        also have \"... \\<le> chain ?e1' ns n (?i1' (hd ns))\"\n          apply (rule chain_mono[OF inf_fg_le_inf_fg[of h1' h2, where E=E], where E=E])\n          using nbot assms apply blast\n             apply (metis a equals0D hd_in_set nsdef(2) set_empty subset_code(1))\n          using assms by blast+\n        finally have T: \"chain ?e1' ns n (?i1' (hd ns)) \\<noteq> 0\"\n          by simp\n        show ?thesis\n          using contradict_eff_acyclic[OF \\<open>eff_acyclic' h1'\\<close> T, where E=E] assms nsdef a \n          by metis\n      next\n        case b\n        have \"0 < chain ?e2' ns n (?i' (hd ns))\"\n          using nsdef assms b infeq chain_cong'[OF edge_fg_plus_fg_on2[of h1' h2], of \"ns\" n] nbot\n          by (metis gr_zeroI)\n        also have \"... \\<le> chain ?e2' ns n (?i2' (hd ns))\"\n          apply (rule chain_mono[OF inf_fg_le_inf_fg2[of h1' h2, where E=E], where E=E])\n          using assms nbot apply blast\n          apply (metis b empty_iff hd_in_set list.set(1) nsdef(2) subset_code(1))\n          using assms by blast+\n        finally have T: \"chain ?e2' ns n (?i2' (hd ns)) \\<noteq> 0\"\n          by simp\n        show ?thesis\n          using contradict_eff_acyclic[OF \\<open>eff_acyclic' h2\\<close> T, where E=E] assms nsdef b *\n          by metis\n      qed\n    next\n      case False\n      moreover have dom: \"dom_fg h1' \\<inter> dom_fg h2 = {}\" \"ns \\<noteq> []\"\n          \"set ns \\<subseteq> dom_fg h1' \\<union> dom_fg h2\" \"dom_fg h1' \\<inter> dom_fg h2 = {}\"\n          \"?N1 \\<inter> ?N2 = {}\" \"?N1 \\<union> ?N2 = ?N\"\n        using False nsdef ck_lists_props[of ns \"dom_fg (h1' + h2)\" ?k] nbot\n        using assms(6) apply blast\n        using nsdef nbot \\<open>h = h1 + h2\\<close> \\<open>h \\<noteq> bot\\<close> by auto\n      ultimately obtain n1 n2 where ***: \"n1 \\<in> set ns\" \"n2 \\<in> set ns\" \"n1 \\<notin> dom_fg h1'\"\n        \"n2 \\<notin> dom_fg h2\" \"n1 \\<noteq> n2\" \"n1 \\<in> dom_fg h2\" \"n2 \\<in> dom_fg h1'\"\n        by blast\n      then have \"length ns \\<ge> 2\"\n        using length_ge_2[of ?N1 ?N2 n2 n1 ns] assms dom by blast+\n      then have \"butlast ns \\<noteq> []\"\n        by (cases ns, simp_all, case_tac list, simp_all)\n\n      show ?thesis\n      proof (cases \"hd ns \\<in> dom_fg h1'\")\n        case True\n        show ?thesis\n          using maintain_eff_acyclic_dom_eq'[of E h h1 h2 \"h1' + h2\" h1' h2 ns n]\n          using assms nbot infeq False True nsdef by blast+\n      next\n        case False\n        then have blub: \"hd ns \\<in> dom_fg h2\"\n          using dom(2) list.set_sel(1) nbot(1) nsdef(3) by auto\n        have bla: \"h = h2 + h1\" \"h2 + h1' \\<noteq> bot\"\n          using assms(2) plus_fg_comm apply blast\n          by (simp add: nbot(1) plus_fg_comm)\n        show ?thesis\n          apply (rule maintain_eff_acyclic_dom_eq'[of E h h2 h1 \"h2 + h1'\" h2 h1' ns n])\n          using assms nbot infeq False False nsdef \\<open>\\<not> (set ns \\<subseteq> dom_fg h1' \\<or> set ns \\<subseteq> dom_fg h2)\\<close> *\n            subflow_preserving_extension_refl[of h2] blub bla assms nbot apply blast+\n          using nbot assms apply (simp (no_asm) add: algebra_simps)\n          using assms nbot infeq False False nsdef \\<open>\\<not> (set ns \\<subseteq> dom_fg h1' \\<or> set ns \\<subseteq> dom_fg h2)\\<close> *\n            subflow_preserving_extension_refl[of h2] blub bla assms nbot apply blast+\n          using nbot assms apply (simp (no_asm) add: algebra_simps)\n          using assms nbot infeq False False nsdef \\<open>\\<not> (set ns \\<subseteq> dom_fg h1' \\<or> set ns \\<subseteq> dom_fg h2)\\<close> * \n            subflow_preserving_extension_refl[of h2] blub bla assms nbot apply blast+\n          using nbot assms apply (simp (no_asm) add: algebra_simps)\n          using nbot assms infeq apply (simp (no_asm) add: algebra_simps)\n          using assms nbot infeq False False nsdef \\<open>\\<not> (set ns \\<subseteq> dom_fg h1' \\<or> set ns \\<subseteq> dom_fg h2)\\<close> *\n            subflow_preserving_extension_refl[of h2] blub bla assms nbot apply blast+\n          subgoal by (simp add: add.commute nsdef(1))\n           apply (simp add: nsdef(2))\n          by (simp add: add.commute dom(3) nbot(1))\n      qed\n    qed\n  qed\n\n  have ext': \"int_fg h \\<lesssim> int_fg (h1' + h2)\"\n    unfolding contextual_extension_def\n    using \\<open>h = h1 + h2\\<close> nbot \\<open>h \\<noteq> bot\\<close> \\<open>dom_fg h1 = dom_fg h1'\\<close>\n    by simp\n\n  have dom: \"dom_fg (h1 + h2) = dom_fg (h1' + h2)\"\n    by (metis dom_fi_int_fg nbot(2))\n\n  have cap1: \"\\<forall>n\\<in>dom_fg (h1 + h2). \\<forall>n'\\<in>- dom_fg (h1' + h2). \\<forall>m\\<le>inf_fg h n.\n    cap_fg (h1 + h2) n n' m = cap_fg (h1' + h2) n n' m\"\n    apply safe\n    subgoal for n n' m\n      apply (rule cap_fg_eq_cap_fg[of m \"h1 + h2\" n n' h1 h2 \"h1' + h2\" h1' h2 E])\n      using assms dom  apply blast\n      using assms apply blast\n      using dom apply blast\n      using assms apply blast\n      using assms apply blast\n      using assms apply blast\n      using nbot apply blast\n      using assms apply blast\n      using assms apply blast\n      using assms apply blast\n      using assms apply blast\n      using assms apply blast\n      using assms apply blast\n      using assms apply blast\n      apply (simp add: assms(2) infeq(1))\n      using assms apply blast\n      using assms apply blast\n      using assms apply blast\n      using dom apply blast\n      using assms apply blast\n      using assms apply blast\n      using ea_h1'h2 apply blast\n      using assms apply blast\n      using assms apply blast\n      using assms unfolding zero_fun_def apply blast\n      using assms apply blast\n      using assms apply blast\n      using assms apply blast\n      using assms apply blast\n      done\n    done\n\n  have ext: \"h \\<lesssim>\\<^sub>S (h1' + h2)\"\n    unfolding subflow_preserving_extension_def\n    using ext' assms cap1 \n    by (metis Diff_cancel dom empty_iff)\n\n  show ?thesis\n    apply (rule exI[where x=\"h1' + h2\"])\n    using ea_h1'h2 nbot ext by simp\nqed\n\ntext \\<open>@{cite \\<open>lem. 3.39\\<close> krishna19a}, required by @{term maintain_eff_acyclic_dom_ne}\\<close>\n\nlemma plus_fg_eff_acyclic:\n  fixes E :: \"('a \\<Rightarrow> 'a :: pos_cancel_comm_monoid_add) set\"\n  assumes \"h' = h0 + h\" \"h' \\<noteq> bot\" \"\\<forall>n n'. edge_fg h0 n n' = (\\<lambda>_. 0)\" \"eff_acyclic' h\"\n    \"\\<forall>x y. edge_fg h' x y \\<in> E\" \"End_closed E\" \"id \\<in> E\"\n  shows \"eff_acyclic' h'\"\n  unfolding eff_acyclic'_def eff_acyclic_def\nproof safe\n  fix k ns\n  show \"1 \\<le> k \\<Longrightarrow> ns \\<in> k_lists (dom_fg h') k\n        \\<Longrightarrow> chain (edge_fg h') ns (hd ns) (flow_fg h' (hd ns)) = 0\"\n  proof -\n    assume A: \"k \\<ge> 1\" \"ns \\<in> k_lists (dom_fg h') k\"\n  \n    show \"chain (edge_fg h') ns (hd ns) (flow_fg h' (hd ns)) = 0\"\n    proof (cases \"set ns \\<subseteq> dom_fg h\")\n      case True\n      then have X: \"ns \\<in> k_lists (dom_fg h) k\" \"edge_fg h' = edge_fg h on dom_fg h\"\n        \"flow_fg h' = flow_fg h on dom_fg h\"\n        using A edge_fg_plus_fg_on2 flow_fg_plus_fg_on2[of h0 h] assms\n        unfolding k_lists_def\n        by auto\n      moreover have B: \"ns \\<in> k_lists (dom_fg h) k\"\n        using True A unfolding k_lists_def by blast\n      ultimately show ?thesis\n        using A assms unfolding eff_acyclic'_def eff_acyclic_def\n        apply (subst chain_cong[of _ _ \"edge_fg h\"])\n        using on_eq_superset[OF True edge_fg_plus_fg_on2[of h0 h]] assms\n        apply (simp add: k_lists_nonempty(2))\n        apply (subst X(3))\n        using True A B set_hd_in[of ns \"dom_fg h\"]\n        unfolding k_lists_def\n        by auto\n    next\n      case False\n      then obtain n where B1: \"n \\<in> set ns\" \"n \\<in> -dom_fg h\" by auto\n      then obtain ns1 ns2 where B2: \"ns = ns1 @ n # ns2\" using split_list[of n ns] by auto\n\n      let ?e' = \"edge_fg h'\"\n\n      have C: \"n \\<in> dom_fg h0\"\n      proof -\n        have \"dom_fg h0 \\<inter> dom_fg h = {}\" \"dom_fg h0 \\<union> dom_fg h = dom_fg h'\"\n          using assms by auto\n        moreover have \"n \\<in> dom_fg h'\"\n          using A B1 unfolding k_lists_def by blast\n        ultimately show ?thesis\n          using B1 by auto\n      qed\n      then have \"edge_fg h0 n (hd (ns2 @ [hd ns])) = (\\<lambda>_. 0)\"\n        using assms by simp\n      then have C: \"?e' n (hd (ns2 @ [hd ns])) = (\\<lambda>_. 0)\"\n        using edge_fg_plus_fg_on1[of h0 h] assms C by simp\n      have D: \"chain ?e' ns (hd ns) =\n        chain ?e' (n # ns2) (hd ns) o chain ?e' ns1 (hd ((n # ns2) @ [hd ns]))\"\n        using B1 B2 chain_append_nonempty[of \"edge_fg h'\" ns1 \"n#ns2\" \"hd ns\"]\n        by auto\n      then have \"chain ?e' ns (hd ns) =\n        chain ?e' ns2 (hd ns) o ?e' n (hd (ns2 @ [hd ns])) o chain ?e' ns1 (hd ((n # ns2) @ [hd ns]))\"\n        using B2 by (cases ns2, auto)\n      then have \"chain ?e' ns (hd ns) = chain ?e' ns2 (hd ns) o 0 o chain (edge_fg h') ns1 n\"\n        using C by auto\n      then have \"chain ?e' ns (hd ns) = (\\<lambda>_. 0)\"\n        using endo_f_0_0_closed[of \"chain ?e' ns2 (hd ns)\" E] endo_chain_closed[of ?e' E] assms B2\n        by fastforce\n      then show ?thesis\n        by simp\n    qed\n  qed\nqed\n\ntext \\<open>@{cite \\<open>lem. 3.40\\<close> krishna19a}, required by @{term maintain_eff_acyclic_dom_ne}\\<close>\nlemma outf_eq_h0:\n  assumes \"h' = h0 + h\" \"h' \\<noteq> bot\" \"\\<forall>x y. edge_fg h0 = (\\<lambda>_ _ _. 0)\"\n  shows \"\\<forall>n' \\<in> -dom_fg h'. outf_fg h' n' = outf_fg h n'\"\nproof\n  fix x\n  assume A: \"x \\<in> -dom_fg h'\"\n\n  have \"outf_fg (h0 + h) x = outf_fg h0 x + outf_fg h x\"\n    using outf_fg_plus_fg[of h0 h] A assms by simp\n  also have \"... = (\\<Sum>x' \\<in> dom_fg h0. edge_fg h0 x' x (flow_fg h0 x')) + outf_fg h x\"\n    using outf_fg_unfold[of h0 x] A assms by fastforce\n  finally show \"outf_fg h' x = outf_fg h x\"\n    using assms by simp\nqed\n\ntext \\<open>@{cite \\<open>lem. 3.41\\<close> krishna19a}, required by @{term maintain_eff_acyclic_dom_ne}\\<close>\nlemma cap_outside_eq_h':\n  fixes E :: \"('a \\<Rightarrow> 'a :: pos_cancel_comm_monoid_add) set\"\n  assumes \"h' = h0 + h\" \"h' \\<noteq> bot\" \"\\<forall>x y. edge_fg h0 = (\\<lambda>_ _ _. 0)\" \"End_closed E\"\n    \"\\<forall>x y. edge_fg h' x y \\<in> E\" \"\\<forall>x y. edge_fg h x y \\<in> E\" \"eff_acyclic' h\" \"id \\<in> E\" \"(\\<lambda>_. 0) \\<in> E\"\n  shows \"\\<forall>n \\<in> dom_fg h'. \\<forall>n' \\<in> -dom_fg h'. \\<forall>m \\<le> inf_fg h' n.\n            cap_fg h' n n' m = (if n \\<in> dom_fg h then cap_fg h n n' m else 0)\"\nproof safe\n  fix n n' m\n  assume A: \"n \\<in> dom_fg h'\" \"n' \\<notin> dom_fg h'\" \"m \\<le> inf_fg h' n\"\n\n  let ?N' = \"dom_fg h'\" let ?e' = \"edge_fg h'\"\n  let ?N = \"dom_fg h\" let ?e = \"edge_fg h\"\n  let ?XS' = \"l_lists' ?N' (card ?N')\"\n  let ?XS = \"l_lists' ?N (card ?N)\"\n  let ?XS1' = \"{xs \\<in> ?XS'. set xs \\<subseteq> ?N}\"\n  let ?XS2' = \"{xs \\<in> ?XS'. \\<not> (set xs \\<subseteq> ?N)}\"\n  let ?XS1 = \"{xs \\<in> ?XS1'. length xs < card ?N}\"\n  let ?XS2 = \"{xs \\<in> ?XS1'. length xs \\<ge> card ?N}\"\n\n  show \"cap_fg h' n n' m = (if n \\<in> dom_fg h then cap_fg h n n' m else 0)\"\n  proof (cases \"n \\<in> dom_fg h\")\n    case True\n\n    have XS: \"?XS' = ?XS1' \\<union> ?XS2'\" \"?XS1' \\<inter> ?XS2' = {}\"\n      unfolding l_lists'_def by auto\n\n    have XS2: \"?XS1' = ?XS1 \\<union> ?XS2\" \"?XS1 \\<inter> ?XS2 = {}\"\n      unfolding l_lists'_def by auto\n\n    have F1: \"finite ?XS1'\"\n      by simp\n    have F2: \"finite ?XS2'\"\n      by simp\n    have F3: \"finite ?XS1\"\n      by simp\n    have F4: \"finite ?XS2\"\n      by simp\n\n    have Z: \"(\\<Sum>ns\\<in>?XS2'. chain2 ?e' n ns n' m) = 0\"\n      apply (rule sum.neutral)\n    proof\n      fix xs\n      assume A: \"xs \\<in> ?XS2'\"\n      then obtain x where B: \"x \\<notin> ?N\" \"x \\<in> set xs\" by auto\n      then have \"x \\<in> dom_fg h'\" using assms A unfolding l_lists'_def by auto\n      then have C: \"x \\<in> dom_fg h0\" using B assms by auto\n\n      have E: \"?e' x = (\\<lambda>_ _. 0)\"\n        using edge_fg_plus_fg_on1[of h0 h] assms C by simp\n\n      obtain xs1 xs2 where D: \"xs = xs1 @ x # xs2\"\n        using split_list[OF B(2)] by auto\n      have \"chain2 ?e' n xs n' m = chain ?e' (n # xs) n' m\"\n        using chain2_chain by metis\n      also have \"... = chain ?e' (x # xs2) n' (chain ?e' (n # xs1) (hd ((x # xs2) @ [n'])) m)\"\n        using D chain_append_nonempty[of ?e' \"n # xs1\" \"x #xs2\" n' m] by simp\n      also have \"... = chain ?e' (x # xs2) n' 0\"\n        by (cases xs2, simp_all add: E)\n      also have \"... = 0\"\n        apply (rule endo_f_0_0_closed)\n        apply (rule endo_chain_closed[where E=E], simp_all add: assms)\n        apply (rule endo_edge_fg_plus_fg)\n        using assms by simp_all\n      finally show \"chain2 ?e' n xs n' m = 0\" .\n    qed\n\n    have ZZ: \"(\\<Sum>ns\\<in>?XS2. chain2 ?e n ns n' m) = 0\"\n      apply (rule sum.neutral)\n    proof\n      fix xs\n      assume AA: \"xs \\<in> ?XS2\"\n\n      have \"chain2 ?e n xs n' m = chain ?e (n # xs) n' m\"\n        using chain2_chain by metis\n      also have \"... \\<le> chain ?e (n # xs) n' (inf_fg h' n)\"\n        by (rule chain_mono[OF A(3), where E=E], simp_all add: assms)\n      also have \"... \\<le> chain ?e (n # xs) n' (inf_fg h n)\"\n        apply (subst \\<open>h' = h0 + h\\<close>, rule chain_mono[OF inf_fg_le_inf_fg2[of h0 h]])\n        using assms True by simp_all\n      also have \"... \\<le> chain ?e (n # xs) n' (flow_fg h n)\"\n        apply (rule chain_mono[OF inf_fg_le_flow_fg])\n        using assms True by auto\n      also have \"... \\<le> chain ?e (n # xs) n' (flow_fg h (hd (n # xs)))\"\n        by simp\n      also have \"... = 0\"\n        apply (rule eff_acyclic'_chain_eq_0)\n        using assms True AA by auto\n      finally show \"chain2 ?e n xs n' m = 0\" by simp\n    qed\n\n    have S: \"?XS1 = l_lists' ?N (card ?N)\"\n      using assms unfolding l_lists'_def\n      apply auto\n      using plus_fg_dom_disj\n      by (metis add.right_neutral add_leD2 card_Un_Int card_empty dom_fg_finite not_le)\n      \n    have \"cap_fg h' n n' m = \\<delta> n n' m + (\\<Sum>ns\\<in>?XS'. chain2 ?e' n ns n' m)\"\n      apply (rule cap_unrolled_closed') using assms True by simp_all\n    also have \"... = \\<delta> n n' m + (\\<Sum>ns\\<in>?XS1' \\<union> ?XS2'. chain2 ?e' n ns n' m)\"\n      using XS by simp\n    also have \"... = \\<delta> n n' m + ((\\<Sum>ns\\<in>?XS1'. chain2 ?e' n ns n' m) +\n                                 (\\<Sum>ns\\<in>?XS2'. chain2 ?e' n ns n' m))\"\n      by (subst sum.union_disjoint[OF F1 F2 XS(2), symmetric], simp)\n    also have \"... = \\<delta> n n' m + (\\<Sum>ns\\<in>?XS1'. chain2 ?e' n ns n' m)\"\n      using Z by simp\n    also have \"... = \\<delta> n n' m + (\\<Sum>ns\\<in>?XS1 \\<union> ?XS2. chain2 ?e' n ns n' m)\"\n      using XS2 by presburger\n    also have \"... = \\<delta> n n' m + (\\<Sum>ns\\<in>?XS1 \\<union> ?XS2. chain2 ?e n ns n' m)\"\n      apply (simp, rule sum.cong[OF _ chain2_cong_e], simp)\n      using edge_fg_plus_fg_on2[of h0 h] assms True unfolding l_lists'_def by auto\n    also have \"... = \\<delta> n n' m + ((\\<Sum>ns\\<in>?XS1. chain2 ?e n ns n' m) +\n                                 (\\<Sum>ns\\<in>?XS2. chain2 ?e n ns n' m))\"\n      by (subst sum.union_disjoint[OF F3 F4 XS2(2), symmetric], simp)\n    also have \"... = \\<delta> n n' m + (\\<Sum>ns\\<in>?XS1. chain2 ?e n ns n' m)\"\n      using ZZ by simp\n    also have \"... = \\<delta> n n' m + (\\<Sum>ns\\<in>l_lists' ?N (card ?N). chain2 ?e n ns n' m)\"\n      using S by simp\n    also have \"... = cap_fg h n n' m\"\n      using cap_unrolled_closed'[of \"edge_fg h\" E \"dom_fg h\" n n'] assms True by auto\n    finally show ?thesis\n      using True\n      by simp\n  next\n    case False\n    then have D: \"n \\<in> dom_fg h0\"\n      using assms A by simp\n    then have \"edge_fg h0 n = (\\<lambda>_ _. 0)\"\n      using assms by simp\n    then have E: \"edge_fg h' n = (\\<lambda>_ _. 0)\"\n      using edge_fg_plus_fg_on1[of h0 h] assms D by simp\n\n    have \"cap_fg h' n n' m = \\<delta> n n' m + (\\<Sum>ns\\<in>?XS'. chain2 ?e' n ns n' m)\"\n      apply (rule cap_unrolled_closed') using assms False A by simp_all\n    also have \"... = (\\<Sum>ns\\<in>?XS'. chain2 ?e' n ns n' m)\"\n      using A unfolding \\<delta>_def by auto\n    also have \"... = (\\<Sum>ns\\<in>?XS'. chain ?e' (n # ns) n' m)\"\n      by (rule sum.cong, simp, rule chain2_chain)\n    also have \"... = 0\"\n      apply (rule sum.neutral, clarsimp)\n      apply (case_tac x, simp add: E)\n      apply (simp add: E)\n      apply (rule endo_f_0_0_closed[where E=E])\n       apply (rule endo_chain_closed, simp_all add: assms)\n      apply (rule endo_edge_fg_plus_fg)\n      using assms by simp_all\n    finally show ?thesis\n      using False by auto\n  qed\nqed\n\ntext \\<open>Case 2 @{term \"dom_fg h1 \\<subset> dom_fg h1'\"} of @{cite \\<open>th. 3\\<close> krishna20}\\<close>\n\nlemma maintain_eff_acyclic_dom_ne:\n  fixes E :: \"('a \\<Rightarrow> 'a :: pos_cancel_comm_monoid_add) set\"\n  assumes nbot: \"h = h1 + h2\" \"h \\<noteq> bot\" \"h1' \\<noteq> bot\"\n    and dom: \"dom_fg h1' \\<inter> dom_fg h2 = {}\" \"dom_fg h1 \\<subseteq> dom_fg h1'\"\n    and edge: \"\\<forall>n \\<in> dom_fg h1' - dom_fg h1. outf_fg h2 n = 0\" \"\\<forall>x y. edge_fg h x y \\<in> E\"\n        \"End_closed E\" \"id \\<in> E\" \"\\<forall>x y. edge_fg h2 x y \\<in> E\" \n        \"\\<forall>x y. edge_fg h1 x y \\<in> E\" \"\\<forall>x y. edge_fg h1' x y \\<in> E\" \"\\<forall>x y. edge_fg (h1' + h2) x y \\<in> E\"\n        \"(\\<lambda>_. 0) \\<in> E\" \"pointwise_reduced E\"\n    and ea: \"eff_acyclic' h\" \"eff_acyclic' h1\" \"eff_acyclic' h1'\" \"eff_acyclic' h2\"\n      \"h1 \\<lesssim>\\<^sub>S h1'\" \n    and cap: \"\\<forall>n\\<in>dom_fg h1. \\<forall>n'\\<in>- dom_fg h1'. \\<forall>m\\<le>inf_fg h1 n. cap_fg h1 n n' m = cap_fg h1' n n' m\"\n    \"\\<forall>n\\<in>dom_fg h2. \\<forall>n'\\<in>- dom_fg h2. \\<forall>m\\<le>inf_fg h2 n. cap_fg h2 n n' m = cap_fg h2 n n' m\"\n  shows \"\\<exists>h'. h' = h1' + h2 \\<and> h' \\<noteq> bot \\<and> eff_acyclic' h' \\<and> h \\<lesssim>\\<^sub>S h'\"\nproof -\n  let ?h' = \"h1' + h2\" let ?h = \"h1 + h2\"\n  let ?e' = \"edge_fg ?h'\" let ?e1' = \"edge_fg h1'\" let ?e2' = \"edge_fg h2\"\n  let ?e = \"edge_fg h\" let ?e1 = \"edge_fg h1\" let ?e2 = \"edge_fg h2\"\n  let ?f' = \"flow_fg ?h'\" let ?o1' = \"outf_fg h1'\"\n  let ?N' = \"dom_fg ?h'\" let ?N1 = \"dom_fg h1\" let ?N2 = \"dom_fg h2\" let ?N1' = \"dom_fg h1'\"\n  let ?N = \"dom_fg h\" let ?Na = \"dom_fg h1\" let ?Nb = \"dom_fg h2\"\n  let ?i = \"inf_fg ?h\" let ?i' = \"inf_fg ?h'\" let ?i1 = \"inf_fg h1\"\n  let ?f = \"flow_fg (h1 + h2)\" let ?f1 = \"flow_fg h1\" let ?f1' = \"flow_fg h1'\"\n  let ?i1' = \"inf_fg h1'\" let ?o1 = \"outf_fg h1\" let ?f2 = \"flow_fg h2\"\n\n  let ?Nc = \"?N1' - ?N1\" let ?ec = \"\\<lambda>n n'. (\\<lambda>_. 0)\" let ?fc = \"\\<lambda>n. ?i1' n + ?o1 n\"\n  let ?hc = \"fg ?Nc ?ec ?fc\"\n\n  let ?h1'' = \"?hc + h1\"\n\n  let ?N1'' = \"?Nc \\<union> ?N1\"\n  let ?e1'' = \"combined ?Nc ?N1 (\\<lambda>_ _. 0) ?ec ?e1\"\n  let ?f1'' = \"combined ?Nc ?N1 0 ?fc ?f1\"\n\n  have nbot_h1: \"h1 \\<noteq> bot\"\n    using nbot by auto\n\n  have E: \"?hc \\<noteq> bot\"\n    by (rule fgI, auto)\n\n  have I: \"?i1 = ?i1' on ?N1\" \"?N1 \\<subseteq> ?N1'\" \"?o1 = ?o1' on -?N1'\"\n    using ea nbot\n    unfolding subflow_preserving_extension_def contextual_extension_def\n      apply (auto simp: int_fg_def nbot_h1 subsetD)\n    by (meson Compl_iff in_mono)\n\n  have X1: \"?f1'' = \\<lambda>x. ?i1' x + (\\<Sum>x' \\<in> ?N1''. ?e1'' x' x (?f1'' x')) on ?N1''\"\n  proof\n    fix x\n    assume A: \"x \\<in> ?N1''\"\n    then show \"?f1'' x = ?i1' x + (\\<Sum>x' \\<in> ?N1''. ?e1'' x' x (?f1'' x'))\"\n    proof (cases \"x \\<in> ?Nc\")\n      case True\n      have \"?f1'' x = ?i1' x + (\\<Sum>x' \\<in> ?N1. ?e1'' x' x (?f1'' x')) +\n                               (\\<Sum>x' \\<in> ?Nc. ?e1'' x' x (?f1'' x'))\"\n        using True outf_fg_unfold[of h1 x] nbot_h1 unfolding combined_def by simp\n      then show ?thesis\n        by (smt Diff_partition Un_commute add.assoc add.commute dom(2) dom_fg_finite sum.subset_diff)\n    next\n      case False\n      then have A: \"x \\<in> ?N1\"\n        using A by blast\n      have \"?f1'' x = ?i1' x + (\\<Sum>x' \\<in> ?N1. ?e1'' x' x (?f1'' x')) +\n                               (\\<Sum>x' \\<in> ?Nc. ?e1'' x' x (?f1'' x'))\"\n        using flow_eq_ne_bot[OF nbot_h1] A I unfolding combined_def by simp\n      also have \"... = ?i1' x + (\\<Sum>x' \\<in> ?N1 \\<union> ?Nc. ?e1'' x' x (?f1'' x'))\"\n        using sum.union_disjoint[of ?N1 ?Nc]\n        by (smt Diff_partition add.assoc add.commute dom(2) dom_fg_finite sum.subset_diff)\n      finally show ?thesis\n        by (simp add: Un_commute)\n    qed\n  qed\n\n  have nbot'': \"fg ?N1'' ?e1'' ?f1'' \\<noteq> bot\"\n    using X1 fgI[of ?N1'' ?f1'' ?i1' ?e1''] unfolding combined_def by auto\n  have hch1_eq:  \"?hc + fg ?N1 ?e1 ?f1 = fg ?N1'' ?e1'' ?f1''\"\n    apply (rule plus_fg_fg)\n    using E nbot_h1 fg_components[of h1]\n    by auto\n  then have hch1_nbot: \"?hc + h1 \\<noteq> bot\"\n    using nbot_h1 fg_components[of h1] nbot''\n    by simp\n  have hch1_ea: \"eff_acyclic' (?hc + h1)\"\n    apply (rule plus_fg_eff_acyclic[of \"?hc + h1\" ?hc h1 E], simp_all add: assms hch1_nbot E)\n    using E apply auto[1]\n    using endo_edge_fg_plus_fg[of E ?hc h1] assms hch1_nbot\n    by simp\n\n  have ***: \"?hc + h1 = fg ?N1'' ?e1'' ?f1''\"\n    using fg_components[of h1]  hch1_eq \\<open>h1 \\<noteq> bot\\<close> by simp\n  then have *: \"inf_fg ?h1'' = restrict ?N1'' 0 ?i1'\"\n    using inf_fg_fg[of ?N1''] X1 dom_fg_finite \n    by simp\n\n  have **: \"outf_fg ?h1'' = outf_fg h1 on -?N1''\"\n    using outf_eq_h0[of ?h1'' ?hc h1] nbot'' E hch1_nbot\n    by auto\n\n  have extfi: \"int_fg (?h1'') \\<lesssim> int_fg h1'\"\n    unfolding contextual_extension_def\n    by (smt * ** *** Diff_cancel Diff_eq_empty_iff I(3) Un_Diff_cancel Un_commute\n        dom(2) dom_fg_fg dom_fi_int_fg inf_fg_int_fg nbot'' nbot(3) outf_fi_int_fg subset_Un_eq)\n\n  have hc_edge: \"\\<forall>x y. edge_fg ?hc x y \\<in> E\"\n    using E edge by simp\n\n  have cap: \"\\<forall>n \\<in> ?N1''. \\<forall>n' \\<in> -?N1'. \\<forall>m \\<le> inf_fg ?h1'' n. cap_fg ?h1'' n n' m = cap_fg h1' n n' m\"\n  proof (safe, goal_cases)\n    case (1 n n' m)\n    then have A: \"n \\<in> ?Nc\" by simp\n    then have \"cap_fg ?h1'' n n' m = 0\"\n      using cap_outside_eq_h'[of ?h1'' ?hc h1 E] 1 E \\<open>End_closed E\\<close>\n        endo_edge_fg_plus_fg[OF \\<open>End_closed E\\<close> hch1_nbot hc_edge]\n        \\<open>eff_acyclic' h1\\<close> \\<open>\\<forall>x y. edge_fg h1 x y \\<in> E\\<close> \\<open>id \\<in> E\\<close> \\<open>(\\<lambda>_. 0) \\<in> E\\<close> hch1_nbot dom\n      by (simp, metis (no_types, lifting) ComplI Un_absorb2 compl_sup)\n    moreover have \"cap_fg h1' n n' m = 0\"\n    proof -\n      have \"inf_fg ?h1'' n \\<le> inf_fg ?hc n\"\n        apply (rule inf_fg_le_inf_fg[of ?hc h1 n E])\n        using 1 hch1_nbot edge E by simp_all\n      then show ?thesis\n        using ea 1 * unfolding subflow_preserving_extension_def\n        by auto\n    qed\n    ultimately show ?case\n      by simp\n  next\n    case (2 n n' m)\n    then have \"cap_fg h1' n n' m = cap_fg h1 n n' m\"\n      using ea inf_fg_le_inf_fg2[of ?hc h1 n E] edge hch1_nbot\n      unfolding subflow_preserving_extension_def \n      by auto\n    moreover have \"cap_fg ?h1'' n n' m = cap_fg h1 n n' m\"\n      using cap_outside_eq_h'[of ?h1'' ?hc h1 E] 2 E \\<open>End_closed E\\<close>\n      using endo_edge_fg_plus_fg[OF \\<open>End_closed E\\<close> hch1_nbot hc_edge]\n        \\<open>eff_acyclic' h1\\<close> \\<open>\\<forall>x y. edge_fg h1 x y \\<in> E\\<close> \\<open>id \\<in> E\\<close> \\<open>(\\<lambda>_. 0) \\<in> E\\<close> hch1_nbot dom\n      apply auto by (smt ComplI Un_absorb2 compl_sup in_mono)\n    ultimately show ?case by simp\n  qed\n\n  have h1''_ext_h1': \"?h1'' \\<lesssim>\\<^sub>S h1'\"\n    unfolding subflow_preserving_extension_def\n    apply (intro conjI impI)\n    using extfi apply simp\n    using cap hch1_nbot E apply simp\n    using E hch1_nbot by auto\n\n  let ?N1'' = \"dom_fg ?h1''\"\n  let ?e1'' = \"edge_fg ?h1''\"\n  let ?f1'' = \"flow_fg ?h1''\"\n\n  let ?h'' = \"?h1'' + h2\"\n\n  let ?N'' = \"?N1'' \\<union> ?N2\"\n  let ?e'' = \"combined ?N1'' ?N2 (\\<lambda>_ _. 0) ?e1'' ?e2\"\n  let ?f'' = \"combined ?N1'' ?N2 0 ?f1'' ?f2\"\n  let ?i'' = \"\\<lambda>x. if x \\<in> ?N then ?i x else ?i1' x\"\n\n  have X2: \"?f'' = \\<lambda>x. ?i'' x + (\\<Sum>x' \\<in> ?N''. ?e'' x' x (?f'' x')) on ?N''\"\n  proof\n    fix x\n    assume \"x \\<in> ?N''\"\n    then have \"x \\<in> ?N1 \\<union> ?N2 \\<union> ?Nc\"\n      using hch1_nbot E by auto\n    then consider (a) \"x \\<in> ?N1\" | (b) \"x \\<in> ?N2\" | (c) \"x \\<in> ?Nc\"\n      using hch1_nbot plus_fg_dom_un[of ?hc h1] E nbot by blast\n    then show \"?f'' x = ?i'' x + (\\<Sum>x' \\<in> ?N''. ?e'' x' x (?f'' x'))\"\n    proof cases\n      case a\n      have \"?f'' x = ?f1 x\"\n        unfolding combined_def\n        using nbot hch1_nbot E a flow_fg_plus_fg_on2'[of ?hc h1] by auto\n      also have \"... = ?f x\"\n        using flow_fg_plus_fg_on1'[of h1 h2 x] \\<open>h = h1 + h2\\<close> \\<open>h \\<noteq> bot\\<close> a by simp\n      also have \"... = ?i x + (\\<Sum>x' \\<in> ?N. ?e x' x (?f x'))\"\n        using flow_eq_ne_bot[of \"h1 + h2\"] \\<open>h = h1 + h2\\<close> \\<open>h \\<noteq> bot\\<close> a by simp\n      also have \"... = ?i x + (\\<Sum>x' \\<in> ?N1. ?e x' x (?f x')) + (\\<Sum>x' \\<in> ?N2. ?e x' x (?f x'))\"\n        unfolding combined_def\n        using nbot hch1_nbot E a flow_fg_plus_fg_on2'[of ?hc h1] a \\<open>?N1 \\<subseteq> ?N1'\\<close> \\<open>?N1' \\<inter> ?N2 = {}\\<close>\n        apply auto\n        apply (subst sum.union_disjoint[OF dom_fg_finite dom_fg_finite])\n        using edge_fg_plus_fg_on1'[of ?hc h1] hch1_nbot a\n        by (auto simp: algebra_simps)\n      also have \"... = ?i x + (\\<Sum>x' \\<in> ?N1. ?e'' x' x (?f'' x')) + (\\<Sum>x' \\<in> ?N2. ?e x' x (?f x'))\"\n        unfolding combined_def\n        using nbot hch1_nbot E a edge_fg_plus_fg_on2'[of ?hc h1]\n        using flow_fg_plus_fg_on2'[of ?hc h1] a \\<open>?N1 \\<subseteq> ?N1'\\<close> \\<open>?N1' \\<inter> ?N2 = {}\\<close>\n          edge_fg_plus_fg_on1'[of h1 h2] flow_fg_plus_fg_on1'[of h1 h2]\n        by auto\n      also have \"... = ?i x + (\\<Sum>x' \\<in> ?N1. ?e'' x' x (?f'' x')) + (\\<Sum>x' \\<in> ?N2. ?e'' x' x (?f'' x'))\"\n        unfolding combined_def\n        using nbot hch1_nbot E a edge_fg_plus_fg_on2'[of h1 h2]\n        using flow_fg_plus_fg_on2'[of h1 h2] a \\<open>?N1 \\<subseteq> ?N1'\\<close> \\<open>?N1' \\<inter> ?N2 = {}\\<close>\n        apply auto\n        apply (subst (2) sum.cong[where h=\"\\<lambda>x'. edge_fg h2 x' x (flow_fg h2 x')\"])\n        using dom by auto\n      also have \"... = ?i x + (\\<Sum>x' \\<in> ?N1 \\<union> ?N2. ?e'' x' x (?f'' x'))\"\n        apply (subst sum.union_disjoint[OF dom_fg_finite dom_fg_finite])\n        using nbot(1) nbot(2) plus_fg_dom_disj apply blast\n        using add.assoc by blast\n      also have \"... = ?i x + ((\\<Sum>x' \\<in> ?N1 \\<union> ?N2. ?e'' x' x (?f'' x')) + (\\<Sum>x' \\<in> ?Nc. ?e'' x' x (?f'' x')))\"\n        unfolding combined_def\n        using nbot hch1_nbot E a edge_fg_plus_fg_on1'[of ?hc h1]\n        using flow_fg_plus_fg_on1'[of ?hc h1] a \\<open>?N1 \\<subseteq> ?N1'\\<close> \\<open>?N1' \\<inter> ?N2 = {}\\<close>\n        by auto\n      also have \"... = ?i x + (\\<Sum>x' \\<in> ?N1 \\<union> ?N2 \\<union> ?Nc. ?e'' x' x (?f'' x'))\"\n        apply (subst sum.union_disjoint[symmetric])\n        using dom by auto\n      finally show ?thesis\n        using a \\<open>h = h1 + h2\\<close> \\<open>h \\<noteq> bot\\<close> hch1_nbot E\n        apply simp\n        apply (rule sum.cong)\n        by auto\n    next\n      case b\n      have \"?f'' x = ?f2 x\"\n        unfolding combined_def\n        using b hch1_nbot E \\<open>?N1 \\<subseteq> ?N1'\\<close> \\<open>?N1' \\<inter> ?N2 = {}\\<close>\n        by auto\n      also have \"... = ?f x\"\n        using flow_fg_plus_fg_on2'[of h1 h2 x] \\<open>h = h1 + h2\\<close> \\<open>h \\<noteq> bot\\<close> b by simp\n      also have \"... = ?i x + (\\<Sum>x' \\<in> ?N. ?e x' x (?f x'))\"\n        using flow_eq_ne_bot[of \"h1 + h2\"] \\<open>h = h1 + h2\\<close> \\<open>h \\<noteq> bot\\<close> b by simp\n      also have \"... = ?i x + (\\<Sum>x' \\<in> ?N1. ?e x' x (?f x')) + (\\<Sum>x' \\<in> ?N2. ?e x' x (?f x'))\"\n        unfolding combined_def\n        using nbot hch1_nbot E b flow_fg_plus_fg_on2'[of ?hc h1] \\<open>?N1 \\<subseteq> ?N1'\\<close> \\<open>?N1' \\<inter> ?N2 = {}\\<close>\n        apply auto\n        apply (subst sum.union_disjoint[OF dom_fg_finite dom_fg_finite])\n        using edge_fg_plus_fg_on1'[of ?hc h1] hch1_nbot\n        by (auto simp: algebra_simps)\n      also have \"... = ?i x + (\\<Sum>x' \\<in> ?N1. ?e'' x' x (?f'' x')) + (\\<Sum>x' \\<in> ?N2. ?e x' x (?f x'))\"\n        unfolding combined_def\n        using nbot hch1_nbot E b edge_fg_plus_fg_on2'[of ?hc h1]\n        using flow_fg_plus_fg_on2'[of ?hc h1] \\<open>?N1 \\<subseteq> ?N1'\\<close> \\<open>?N1' \\<inter> ?N2 = {}\\<close>\n          edge_fg_plus_fg_on1'[of h1 h2] flow_fg_plus_fg_on1'[of h1 h2]\n        by auto\n      also have \"... = ?i x + (\\<Sum>x' \\<in> ?N1. ?e'' x' x (?f'' x')) + (\\<Sum>x' \\<in> ?N2. ?e'' x' x (?f'' x'))\"\n        unfolding combined_def\n        using nbot hch1_nbot E b edge_fg_plus_fg_on2'[of h1 h2]\n        using flow_fg_plus_fg_on2'[of h1 h2] \\<open>?N1 \\<subseteq> ?N1'\\<close> \\<open>?N1' \\<inter> ?N2 = {}\\<close>\n        apply auto\n        apply (subst (2) sum.cong[where h=\"\\<lambda>x'. edge_fg h2 x' x (flow_fg h2 x')\"])\n        using dom by auto\n      also have \"... = ?i x + (\\<Sum>x' \\<in> ?N1 \\<union> ?N2. ?e'' x' x (?f'' x'))\"\n        apply (subst sum.union_disjoint[OF dom_fg_finite dom_fg_finite])\n        using nbot(1) nbot(2) plus_fg_dom_disj apply blast\n        using add.assoc by blast\n      also have \"... = ?i x + ((\\<Sum>x' \\<in> ?N1 \\<union> ?N2. ?e'' x' x (?f'' x')) +\n                               (\\<Sum>x' \\<in> ?Nc. ?e'' x' x (?f'' x')))\"\n        unfolding combined_def\n        using nbot hch1_nbot E edge_fg_plus_fg_on1'[of ?hc h1]\n        using flow_fg_plus_fg_on1'[of ?hc h1] \\<open>?N1 \\<subseteq> ?N1'\\<close> \\<open>?N1' \\<inter> ?N2 = {}\\<close>\n        by auto\n      also have \"... = ?i x + (\\<Sum>x' \\<in> ?N1 \\<union> ?N2 \\<union> ?Nc. ?e'' x' x (?f'' x'))\"\n        apply (subst sum.union_disjoint[symmetric])\n        using dom by auto\n      finally show ?thesis\n        using b \\<open>h = h1 + h2\\<close> \\<open>h \\<noteq> bot\\<close> hch1_nbot E\n        apply simp\n        apply (rule sum.cong)\n        by auto\n    next\n      case c\n\n      have \"outf_fg h2 x = 0\"\n        using edge c by simp\n      then have \"(\\<Sum>x' \\<in> ?N2. ?e2 x' x (?f2 x')) = 0\"\n        using outf_fg_unfold[of h2 x]\n        by (metis Diff_iff c disjoint_iff_not_equal dom(1) nbot(1) nbot(2) plus_fg_ops_exist)\n      then have z: \"\\<And>x'. x' \\<in> ?N2 \\<Longrightarrow> ?e2 x' x (?f2 x') = 0\"\n        by simp\n\n      have \"?f'' x = ?i1' x + ?o1 x\"\n        unfolding combined_def\n        using nbot hch1_nbot E flow_fg_plus_fg_on1'[of ?hc h1] c by auto\n      also have \"... = ?i1' x + (\\<Sum>x' \\<in> ?N1. ?e1 x' x (?f1 x'))\"\n        apply (subst outf_fg_unfold)\n          apply (simp_all add: c nbot_h1)\n        using c by blast\n      also have \"... = ?i1' x + (\\<Sum>x' \\<in> ?N1. ?e'' x' x (?f'' x'))\"\n        unfolding combined_def\n        using nbot hch1_nbot E flow_fg_plus_fg_on2'[of ?hc h1] edge_fg_plus_fg_on2'[of ?hc h1] c\n        by auto\n      also have \"... = ?i1' x + ((\\<Sum>x' \\<in> ?N1. ?e'' x' x (?f'' x')) +\n                                 (\\<Sum>x' \\<in> ?Nc. ?e'' x' x (?f'' x')))\"\n        unfolding combined_def\n        using nbot hch1_nbot E edge_fg_plus_fg_on1'[of ?hc h1] c\n        by auto\n      also have \"... = ?i1' x + (\\<Sum>x' \\<in> ?N1 \\<union> ?Nc. ?e'' x' x (?f'' x'))\"\n        by (subst sum.union_disjoint, simp_all)\n      also have \"... = ?i1' x + ((\\<Sum>x' \\<in> ?N1 \\<union> ?Nc. ?e'' x' x (?f'' x')) +\n                                 (\\<Sum>x' \\<in> ?N2. ?e'' x' x (?f'' x')))\"\n        unfolding combined_def\n        using nbot hch1_nbot E edge_fg_plus_fg_on1'[of ?hc h1] c \\<open>?N1 \\<subseteq> ?N1'\\<close> \\<open>?N1' \\<inter> ?N2 = {}\\<close> z\n        by auto\n      also have \"... = ?i1' x + (\\<Sum>x' \\<in> ?N1 \\<union> ?Nc \\<union> ?N2. ?e'' x' x (?f'' x'))\"\n        apply (subst sum.union_disjoint[symmetric])\n        using dom by auto\n      finally show ?thesis\n        unfolding combined_def\n        using nbot hch1_nbot E flow_fg_plus_fg_on1'[of ?hc h1] c apply auto\n        using dom(1) apply blast\n        apply (rule sum.cong)\n        by auto\n    qed\n  qed\n\n  have \"finite ?N''\"\n    by simp\n  then have h''_nbot: \"fg ?N'' ?e'' ?f'' \\<noteq> bot\"\n    using X2 fgI[of ?N'' ?f'' ?i'' ?e''] unfolding combined_def \n    using nbot hch1_nbot by blast\n\n  have h1''h2_eq: \"?h1'' + h2 = fg ?N'' ?e'' ?f''\"\n    apply (subst fg_components[of \"?h1''\", symmetric], simp add: hch1_nbot)\n    apply (subst fg_components[of h2, symmetric])\n    using nbot(1) nbot(2) plus_fg_ops_exist apply blast\n    apply (rule plus_fg_fg)\n    using hch1_nbot fg_components[of \"?h1''\"] apply simp\n    using fg_components[of h2] nbot plus_fg_ops_exist[of h1 h2] apply simp\n    using hch1_nbot dom E by auto\n  then have h''_nbot: \"?h'' \\<noteq> bot\"\n    using hch1_nbot fg_components[of ?h1''] h''_nbot\n    by presburger\n  have h''_ea: \"eff_acyclic' (?h1'' + h2)\"\n    apply (rule plus_fg_eff_acyclic[of \"?h1'' + h2\" ?hc \"h1 + h2\" E])\n    apply (simp_all add: assms E algebra_simps)\n      apply (metis (no_types, lifting) add.commute add.left_commute h''_nbot)\n    using ea(1) nbot(1) apply blast\n    apply (rule endo_edge_fg_plus_fg[OF \\<open>End_closed E\\<close> h''_nbot, simplified algebra_simps])\n      apply (rule endo_edge_fg_plus_fg[OF \\<open>End_closed E\\<close> hch1_nbot, simplified algebra_simps])\n    subgoal using E assms by simp\n    using assms by blast+\n\n  have \"\\<exists>h'. h' = h1' + h2 \\<and> h' \\<noteq> bot \\<and> eff_acyclic' h' \\<and>\n        fg (dom_fg h1' - dom_fg h1) (\\<lambda>n n' _. 0) (\\<lambda>n. inf_fg h1' n + outf_fg h1 n) + h1 + h2 \\<lesssim>\\<^sub>S h'\"\n    apply (rule maintain_eff_acyclic_dom_eq[of E ?h'' ?h1'' h2 h1'])\n    using assms h''_nbot h''_ea h1''_ext_h1' hch1_ea apply (simp_all (no_asm))\n          apply (metis (no_types, lifting) DiffD1 DiffD2 DiffI UnI2 hch1_nbot plus_fg_dom_un)\n         apply (rule endo_edge_fg_plus_fg[of E \"?h1''\" h2], blast+)\n           apply (rule endo_edge_fg_plus_fg[of E \"?hc\" h1])\n    using hch1_nbot apply blast+\n    using E apply simp\n            apply blast+\n    using dom nbot hch1_nbot E apply auto[1]\n       apply (rule endo_edge_fg_plus_fg[of E \"?hc\" h1])\n    using hch1_nbot apply blast+\n    using E apply simp\n        apply blast+\n    using cap nbot hch1_nbot E apply simp\n         apply (rule endo_edge_fg_plus_fg[of E \"?h1''\" h2], blast+)\n           apply (rule endo_edge_fg_plus_fg[of E \"?hc\" h1])\n    using hch1_nbot apply blast+\n    using E apply simp\n            apply blast+\n    done\n  then obtain h' where les1: \"h' = h1' + h2\" \"h' \\<noteq> bot\" \"eff_acyclic' h'\"\n    \"fg (dom_fg h1' - dom_fg h1) (\\<lambda>n n' _. 0) (\\<lambda>n. inf_fg h1' n + outf_fg h1 n) + h1 + h2 \\<lesssim>\\<^sub>S h'\"\n    by auto\n\n  have AUX1: \"dom_fg ?h'' = dom_fg ?hc \\<union> dom_fg (h1 + h2)\"\n    using h''_nbot plus_fg_ops_exist(1)[of ?h1'' h2] nbot by auto\n\n  have inf'': \"\\<forall>x \\<in> ?N. inf_fg ?h'' x = ?i x\"\n  proof\n    fix x\n    assume A: \"x \\<in> ?N\"\n\n    have B: \"outf_fg ?hc x = 0\"\n      using outf_fg_unfold[of ?hc x] plus_fg_dom_disj[of ?hc \"h1 + h2\"] h''_nbot A nbot\n        plus_fg_ops_exist(1)[of ?hc \"h1 + h2\"] dom by (auto simp: algebra_simps)\n\n    have C: \"inf_fg (h1 + h2) x = inf_fg ?h'' x + outf_fg ?hc x\"\n      using flow_eq_to_sum[of \"h1 + h2\" ?hc] h''_nbot A dom nbot by (simp add: algebra_simps)\n\n    show \"inf_fg (?hc + h1 + h2) x = inf_fg (h1 + h2) x\"\n      using B C by simp\n  qed\n\n  have les2: \"h \\<lesssim>\\<^sub>S ?h''\"\n  proof -\n    have Y0: \"outf_fg ?h'' = outf_fg h on -dom_fg ?h''\"\n      apply (rule outf_eq_h0[of ?h'' ?hc h])\n      using \\<open>h = h1 + h2\\<close> apply (auto simp: algebra_simps)\n      using h''_nbot apply (simp add: algebra_simps)\n      using E by simp\n\n    have Y1: \"int_fg h \\<lesssim> int_fg ?h''\"\n    proof -\n      have WWW: \"outf_fg ?hc = (\\<lambda>_. 0)\"\n        using outf_fg_unfold'[OF E] E by auto\n      then have MMM: \"\\<forall>x \\<in> dom_fg (h1 + h2). inf_fg (h1 + h2) x = inf_fg ?h'' x\"\n        using flow_eq_to_sum[of \"h1 + h2\" ?hc] using \\<open>h = h1 + h2\\<close> \\<open>h \\<noteq> bot\\<close> h''_nbot\n        by (simp add: algebra_simps)\n\n      have \"?h'' = ?hc + (h1 + h2)\"\n        by (simp add: algebra_simps)\n\n      show ?thesis\n        unfolding contextual_extension_def\n        using h''_nbot I \\<open>h = h1 + h2\\<close> \\<open>h \\<noteq> bot\\<close> E I nbot hch1_nbot MMM WWW\n        apply auto\n        by (metis (no_types, lifting) Un_iff inf_fg_int_fg)+\n    qed\n\n    have Y2: \"\\<forall>n \\<in> ?N. \\<forall>n' \\<in> -?N''. \\<forall>m \\<le> ?i n. cap_fg h n n' m = cap_fg ?h'' n n' m\"\n    proof (safe, goal_cases)\n      case (1 n n' m)\n      then have \"n \\<in> dom_fg ?h''\" \"n' \\<in> -dom_fg ?h''\" \"m \\<le> inf_fg ?h'' n\"\n        using h''_nbot nbot hch1_nbot inf'' by simp_all\n      then show ?case\n        using cap_outside_eq_h'[of ?h'' ?hc h E] \\<open>h = h1 + h2\\<close> E edge h''_nbot\n          endo_edge_fg_plus_fg[of E \"h1 + h2\" ?hc] 1 \\<open>eff_acyclic' h\\<close> \\<open>\\<forall>x y. edge_fg h x y \\<in> E\\<close>\n          \\<open>id \\<in> E\\<close> \\<open>(\\<lambda>_. 0) \\<in> E\\<close>\n        by (simp add: algebra_simps)\n    qed\n\n    have Y3:\n      \"\\<forall>n \\<in> dom_fg ?h'' - ?N. \\<forall>n' \\<in> -(dom_fg ?h''). \\<forall>m \\<le> inf_fg ?h'' n. cap_fg ?h'' n n' m = 0\"\n    proof (safe, goal_cases)\n      case (1 n n' m)\n      then have \"n \\<in> dom_fg ?h''\" \"n' \\<in> -dom_fg ?h''\" \"m \\<le> inf_fg ?h'' n\"\n        using h''_nbot nbot hch1_nbot inf'' by simp_all\n      then show ?case\n        using cap_outside_eq_h'[of ?h'' ?hc h E] \\<open>h = h1 + h2\\<close> E edge h''_nbot\n          endo_edge_fg_plus_fg[of E \"h1 + h2\" ?hc] 1 \\<open>eff_acyclic' h\\<close> \\<open>\\<forall>x y. edge_fg h x y \\<in> E\\<close>\n          \\<open>id \\<in> E\\<close> \\<open>(\\<lambda>_. 0) \\<in> E\\<close>\n        by (simp add: algebra_simps)\n    qed\n\n    show ?thesis\n      unfolding subflow_preserving_extension_def\n      apply (intro conjI)\n      using Y1 apply simp\n      using Y2 nbot h''_nbot apply simp\n      using Y3 by simp\n  qed\n\n  show ?thesis\n    apply (rule exI[where x=\"h'\"])\n    using les1 les2 subflow_preserving_extension_trans[of h ?h'' h'] h''_nbot nbot\n    by simp\nqed\n\ntext \\<open>@{cite \\<open>th. 3\\<close> krishna20}\\<close>\n\nlemma maintain_eff_acyclic_dom:\n  fixes E :: \"('a \\<Rightarrow> 'a :: pos_cancel_comm_monoid_add) set\"\n  assumes nbot: \"h = h1 + h2\" \"h \\<noteq> bot\" \"h1' \\<noteq> bot\"\n    and dom: \"dom_fg h1' \\<inter> dom_fg h2 = {}\"\n    and edge: \"\\<forall>n \\<in> dom_fg h1' - dom_fg h1. outf_fg h2 n = 0\" \"\\<forall>x y. edge_fg h x y \\<in> E\"\n        \"End_closed E\" \"id \\<in> E\" \"\\<forall>x y. edge_fg h2 x y \\<in> E\" \n        \"\\<forall>x y. edge_fg h1 x y \\<in> E\" \"\\<forall>x y. edge_fg h1' x y \\<in> E\" \"\\<forall>x y. edge_fg (h1' + h2) x y \\<in> E\"\n        \"(\\<lambda>_. 0) \\<in> E\" \"pointwise_reduced E\"\n    and ea: \"eff_acyclic' h\" \"eff_acyclic' h1\" \"eff_acyclic' h1'\" \"eff_acyclic' h2\"\n      \"h1 \\<lesssim>\\<^sub>S h1'\"\n  shows \"\\<exists>h'. h' = h1' + h2 \\<and> h' \\<noteq> bot \\<and> eff_acyclic' h' \\<and> h \\<lesssim>\\<^sub>S h'\"\nproof (cases \"dom_fg h1 = dom_fg h1'\")\n  case True\n  show ?thesis\n    apply (rule maintain_eff_acyclic_dom_eq)\n    using True assms unfolding zero_fun_def subflow_preserving_extension_def by blast+\nnext\n  case False\n  then have False': \"dom_fg h1 \\<subseteq> dom_fg h1'\"\n    using ea unfolding subflow_preserving_extension_def contextual_extension_def by simp\n  show ?thesis\n    apply (rule maintain_eff_acyclic_dom_ne)\n    using False' assms unfolding subflow_preserving_extension_def by blast+\nqed\n\nend\n", "meta": {"author": "bpoettinger", "repo": "Flow", "sha": "c95ea5f88a0a3d39e44421e0cc36139a3c3687de", "save_path": "github-repos/isabelle/bpoettinger-Flow", "path": "github-repos/isabelle/bpoettinger-Flow/Flow-c95ea5f88a0a3d39e44421e0cc36139a3c3687de/Effectively_Acyclic_Maintain.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5156199157230156, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.2779104828271032}}
{"text": "theory Incredible_Correctness\nimports\n  Abstract_Rules_To_Incredible\n  Natural_Deduction\nbegin\n\ntext \\<open>\nIn this theory, we prove that if we have a graph that proves a given abstract task (which is\nrepresented as the context @{term Tasked_Proof_Graph}), then we can prove @{term solved}.\n\\<close>\n\ncontext Tasked_Proof_Graph\nbegin\n\ndefinition adjacentTo :: \"'vertex \\<Rightarrow> ('form, 'var) in_port \\<Rightarrow> ('vertex \\<times> ('form, 'var) out_port)\" where\n \"adjacentTo v p = (SOME ps. (ps, (v,p)) \\<in> edges)\"\n\nfun isReg where\n  \"isReg v p = (case p of Hyp h c \\<Rightarrow> False | Reg  c \\<Rightarrow>\n      (case nodeOf v of\n        Conclusion a \\<Rightarrow> False\n      | Assumption a \\<Rightarrow> False\n      | Rule r \\<Rightarrow> True\n      | Helper \\<Rightarrow> True\n      ))\"\n\nfun toNatRule  where\n  \"toNatRule v p = (case p of Hyp h c \\<Rightarrow> Axiom | Reg  c \\<Rightarrow>\n      (case nodeOf v of\n        Conclusion a \\<Rightarrow> Axiom \\<comment> \\<open>a lie\\<close>\n      | Assumption a \\<Rightarrow> Axiom\n      | Rule r \\<Rightarrow> NatRule (r,c)\n      | Helper \\<Rightarrow> Cut\n      ))\"\n\n\ninductive_set global_assms' :: \"'var itself \\<Rightarrow> 'form set\" for i  where\n  \"v |\\<in>| vertices \\<Longrightarrow> nodeOf v = Assumption p \\<Longrightarrow> labelAtOut v (Reg p) \\<in> global_assms' i\"\n\nlemma finite_global_assms': \"finite (global_assms' i)\"\nproof-\n  have \"finite (fset vertices)\" by (rule finite_fset)\n  moreover\n  have \"global_assms' i \\<subseteq> (\\<lambda> v. case nodeOf v of Assumption p \\<Rightarrow>  labelAtOut v (Reg p)) ` fset vertices\"\n    by (force simp add: global_assms'.simps fmember_iff_member_fset image_iff )\n  ultimately\n  show ?thesis by (rule finite_surj)\nqed\n\ncontext includes fset.lifting\nbegin\n  lift_definition global_assms :: \"'var itself \\<Rightarrow> 'form fset\" is global_assms' by (rule finite_global_assms')\n  lemmas global_assmsI = global_assms'.intros[Transfer.transferred]\n  lemmas global_assms_simps = global_assms'.simps[Transfer.transferred]\nend\n\nfun extra_assms :: \"('vertex \\<times> ('form, 'var) in_port) \\<Rightarrow> 'form fset\" where\n  \"extra_assms (v, p) = (\\<lambda> p. labelAtOut v p) |`| hyps_for (nodeOf v) p\"\n\nfun hyps_along :: \"('vertex, 'form, 'var) edge' list \\<Rightarrow> 'form fset\" where\n  \"hyps_along pth = ffUnion (extra_assms |`| snd |`| fset_from_list pth) |\\<union>| global_assms TYPE('var)\"\n\nlemma hyps_alongE[consumes 1, case_names Hyp Assumption]:\n  assumes \"f |\\<in>| hyps_along pth\"\n  obtains v p h where \"(v,p) \\<in> snd ` set pth\" and \"f = labelAtOut v h \" and \"h |\\<in>| hyps_for (nodeOf v) p\"\n  | v pf  where \"v |\\<in>| vertices\" and \"nodeOf v = Assumption pf\" \"f = labelAtOut v (Reg pf)\"\n  using assms\n  apply (auto simp add: fmember_iff_member_fset ffUnion.rep_eq  global_assms_simps[unfolded fmember_iff_member_fset])\n  apply (metis image_iff snd_conv)\n  done\n\ntext \\<open>Here we build the natural deduction tree, by walking the graph.\\<close>\n\nprimcorec tree :: \"'vertex \\<Rightarrow> ('form, 'var) in_port \\<Rightarrow> ('vertex, 'form, 'var) edge' list \\<Rightarrow>  (('form entailment), ('rule \\<times> 'form) NatRule) dtree\" where\n \"root (tree v p pth) =\n    ((hyps_along ((adjacentTo v p,(v,p))#pth) \\<turnstile> labelAtIn v p),\n    (case adjacentTo v p of (v', p') \\<Rightarrow> toNatRule v' p'\n    ))\"\n | \"cont (tree v p pth) =\n    (case adjacentTo v p of (v', p') \\<Rightarrow>\n    (if isReg v' p' then ((\\<lambda> p''. tree v' p'' ((adjacentTo v p,(v,p))#pth)) |`| inPorts (nodeOf v')) else {||}\n    ))\"\n\n\nlemma fst_root_tree[simp]: \"fst (root (tree v p pth)) = (hyps_along ((adjacentTo v p,(v,p))#pth) \\<turnstile> labelAtIn v p)\" by simp\n\nlemma out_port_cases[consumes 1, case_names Assumption Hyp Rule Helper]:\n  assumes \"p |\\<in>| outPorts n\"\n  obtains\n    a where \"n = Assumption a\" and \"p = Reg a\"\n    | r h c where \"n = Rule r\" and \"p = Hyp h c\"\n    | r f where \"n = Rule r\" and \"p = Reg f\"\n    | \"n = Helper\" and \"p = Reg anyP\"\n  using assms by (atomize_elim, cases p; cases n) auto\n\nlemma hyps_for_fimage: \"hyps_for (Rule r) x = (if x |\\<in>| f_antecedent r then (\\<lambda> f. Hyp f x) |`| (a_hyps x) else {||})\"\n  apply (rule fset_eqI)\n  apply (rename_tac p')\n  apply (case_tac p')\n  apply (auto simp add:  split: if_splits out_port.splits)\n  done\n\ntext \\<open>Now we prove that the thus produced tree is well-formed.\\<close>\n\ntheorem wf_tree:\n  assumes \"valid_in_port (v,p)\"\n  assumes \"terminal_path v t pth\"\n  shows \"wf (tree v p pth)\"\nusing assms\nproof (coinduction arbitrary: v p pth)\ncase (wf v p pth)\n  let ?t = \"tree v p pth\"\n  from saturated[OF wf(1)]\n  obtain v' p'\n  where e:\"((v',p'),(v,p)) \\<in> edges\" and [simp]: \"adjacentTo v p = (v',p')\"\n    by (auto simp add: adjacentTo_def, metis (no_types, lifting) eq_fst_iff tfl_some)\n\n  let ?e = \"((v',p'),(v,p))\"\n  let ?pth' = \"?e#pth\"\n  let ?\\<Gamma> = \"hyps_along ?pth'\"\n  let ?l = \"labelAtIn v p\"\n\n  from e valid_edges have \"v' |\\<in>| vertices\" and \"p' |\\<in>| outPorts (nodeOf v')\" by auto\n  hence \"nodeOf v' \\<in> sset nodes\" using valid_nodes by (meson image_eqI notin_fset subsetD)\n\n  from \\<open>?e \\<in> edges\\<close>\n  have s: \"labelAtOut v' p' = labelAtIn v p\"  by (rule solved)\n\n  from \\<open>p' |\\<in>| outPorts (nodeOf v')\\<close>\n  show ?case\n  proof (cases rule: out_port_cases)\n    case (Hyp r h c)\n\n    from Hyp \\<open>p' |\\<in>| outPorts (nodeOf v')\\<close>\n    have \"h |\\<in>| a_hyps c\" and \"c |\\<in>| f_antecedent r\" by auto\n    hence \"hyps (nodeOf v') (Hyp h c) = Some c\" using Hyp by simp\n\n    from well_scoped[OF \\<open> _ \\<in> edges\\<close>[unfolded Hyp] this]\n    have \"(v, p) = (v', c) \\<or> v \\<in> scope (v', c)\".\n    hence \"(v', c) \\<in> insert (v, p) (snd ` set pth)\"\n    proof\n      assume \"(v, p) = (v', c)\"\n      thus ?thesis by simp\n    next\n      assume \"v \\<in> scope (v', c)\"\n      from this terminal_path_end_is_terminal[OF wf(2)] terminal_path_is_path[OF wf(2)]\n      have \"(v', c) \\<in> snd ` set pth\" by (rule scope_find)\n      thus ?thesis by simp\n    qed\n    moreover\n\n\n    from \\<open>hyps (nodeOf v') (Hyp h c) = Some c\\<close>\n    have \"Hyp h c |\\<in>| hyps_for (nodeOf v') c\" by simp\n    hence \"labelAtOut v' (Hyp h c) |\\<in>| extra_assms (v',c)\" by auto\n    ultimately\n\n    have \"labelAtOut v' (Hyp h c) |\\<in>| ?\\<Gamma>\"\n      by (fastforce simp add: fmember_iff_member_fset ffUnion.rep_eq)\n\n    hence \"labelAtIn v p |\\<in>| ?\\<Gamma>\" by (simp add: s[symmetric] Hyp fmember_iff_member_fset)\n    thus ?thesis\n      using Hyp\n      apply (auto intro: exI[where x = ?t] simp add: eff.simps simp del: hyps_along.simps)\n      done\n  next\n    case (Assumption f)\n\n    from \\<open>v' |\\<in>| vertices\\<close> \\<open>nodeOf v' = Assumption f\\<close>\n    have \"labelAtOut v' (Reg f) |\\<in>| global_assms TYPE('var)\"\n      by (rule global_assmsI)\n    hence \"labelAtOut v' (Reg f) |\\<in>| ?\\<Gamma>\" by auto\n    hence \"labelAtIn v p |\\<in>| ?\\<Gamma>\" by (simp add: s[symmetric] Assumption fmember_iff_member_fset)\n    thus ?thesis using Assumption\n      by (auto intro: exI[where x = ?t] simp add: eff.simps)\n  next\n    case (Rule r f)\n    with \\<open>nodeOf v' \\<in> sset nodes\\<close>\n    have \"r \\<in> sset rules\"\n      by (auto simp add: nodes_def stream.set_map)\n\n    from Rule\n    have \"hyps (nodeOf v') p' = None\" by simp\n    with e \\<open>terminal_path v t pth\\<close>\n    have \"terminal_path v' t ?pth'\"..\n\n    from Rule  \\<open>p' |\\<in>| outPorts (nodeOf v')\\<close>\n    have \"f |\\<in>| f_consequent r\" by simp\n    hence \"f \\<in> set (consequent r)\" by (simp add: f_consequent_def)\n    with \\<open>r \\<in> sset rules\\<close>\n    have \"NatRule (r, f) \\<in> sset (smap NatRule n_rules)\"\n      by (auto simp add: stream.set_map n_rules_def no_empty_conclusions)\n    moreover\n\n    {\n    from \\<open>f |\\<in>| f_consequent r\\<close>\n    have \"f \\<in> set (consequent r)\" by (simp add: f_consequent_def)\n    hence \"natEff_Inst (r, f) f (f_antecedent r)\"\n      by (rule natEff_Inst.intros)\n    hence \"eff (NatRule (r, f)) (?\\<Gamma> \\<turnstile> subst (inst v') (freshen (vidx v') f))\n           ((\\<lambda>ant. ((\\<lambda>p. subst (inst v') (freshen (vidx v') p)) |`| a_hyps ant |\\<union>| ?\\<Gamma> \\<turnstile> subst (inst v') (freshen (vidx v') (a_conc ant)))) |`| f_antecedent r)\"\n           (is \"eff _ _ ?ants\")\n    proof (rule eff.intros)\n      fix ant f\n      assume \"ant |\\<in>| f_antecedent r\"\n      from  \\<open>v' |\\<in>| vertices\\<close> \\<open>ant |\\<in>| f_antecedent r\\<close>\n      have \"valid_in_port (v',ant)\" by (simp add: Rule)\n\n      assume \"f |\\<in>| ?\\<Gamma>\"\n      thus \"freshenLC (vidx v') ` a_fresh ant \\<inter> lconsts f = {}\"\n      proof(induct rule: hyps_alongE)\n        case (Hyp v'' p'' h'')\n\n        from Hyp(1) snd_set_path_verties[OF terminal_path_is_path[OF \\<open>terminal_path v' t ?pth'\\<close>]]\n        have \"v'' |\\<in>| vertices\" by (force simp add: fmember_iff_member_fset)\n\n        from \\<open>terminal_path v' t ?pth'\\<close> Hyp(1)\n        have \"v'' \\<notin> scope (v', ant)\" by (rule hyps_free_path_not_in_scope)\n        with \\<open>valid_in_port (v',ant)\\<close> \\<open>v'' |\\<in>| vertices\\<close>\n        have \"freshenLC (vidx v') ` local_vars (nodeOf v') ant \\<inter> subst_lconsts (inst v'') = {}\"\n         by (rule out_of_scope)\n        moreover\n        from hyps_free_vertices_distinct'[OF \\<open>terminal_path v' t ?pth'\\<close>] Hyp.hyps(1)\n        have \"v'' \\<noteq> v'\" by (metis distinct.simps(2) fst_conv image_eqI list.set_map)\n        hence \"vidx v'' \\<noteq> vidx v'\" using \\<open>v' |\\<in>| vertices\\<close> \\<open>v'' |\\<in>| vertices\\<close> by (meson vidx_inj inj_onD notin_fset)\n        hence \"freshenLC (vidx v') ` a_fresh ant \\<inter> freshenLC (vidx v'') ` lconsts (labelsOut (nodeOf v'') h'') = {}\"by auto\n        moreover\n        have \"lconsts f \\<subseteq> lconsts (freshen (vidx v'') (labelsOut (nodeOf v'') h'')) \\<union> subst_lconsts (inst v'') \" using \\<open>f = _\\<close>\n          by (simp add: labelAtOut_def fv_subst)\n        ultimately\n        show ?thesis\n          by (fastforce simp add:  lconsts_freshen)\n      next\n        case (Assumption v pf)\n        hence \"f = subst (inst v) (freshen (vidx v) pf)\" by (simp add: labelAtOut_def)\n        moreover\n        from Assumption have \"Assumption pf \\<in> sset nodes\" using valid_nodes by (auto simp add: fmember_iff_member_fset)\n        hence \"pf \\<in> set assumptions\" unfolding nodes_def by (auto simp add: stream.set_map)\n        hence \"closed pf\" by (rule assumptions_closed)\n        ultimately\n        have \"lconsts f = {}\" by (simp add: closed_no_lconsts lconsts_freshen subst_closed freshen_closed)\n        thus ?thesis by simp\n      qed\n    next\n      fix ant\n      assume \"ant |\\<in>| f_antecedent r\"\n      from  \\<open>v' |\\<in>| vertices\\<close> \\<open>ant |\\<in>| f_antecedent r\\<close>\n      have \"valid_in_port (v',ant)\" by (simp add: Rule)\n      moreover\n      note \\<open>v' |\\<in>| vertices\\<close>\n      moreover\n      hence \"v' \\<notin> scope (v', ant)\" by (rule scopes_not_refl)\n      ultimately\n      have \"freshenLC (vidx v') ` local_vars (nodeOf v') ant \\<inter> subst_lconsts (inst v') = {}\"\n        by (rule out_of_scope)\n      thus \"freshenLC (vidx v') ` a_fresh ant \\<inter> subst_lconsts (inst v') = {}\" by simp\n    qed\n    also\n    have \"subst (inst v') (freshen (vidx v') f) = labelAtOut v' p'\" using Rule by (simp add: labelAtOut_def)\n    also\n    note \\<open>labelAtOut v' p' = labelAtIn v p\\<close>\n    also\n    have \"?ants = ((\\<lambda>x. (extra_assms (v',x) |\\<union>| hyps_along ?pth' \\<turnstile> labelAtIn  v' x)) |`| f_antecedent r)\"\n      by (rule fimage_cong[OF refl])\n        (auto simp add: labelAtIn_def labelAtOut_def Rule hyps_for_fimage fmember_iff_member_fset ffUnion.rep_eq)\n    finally\n    have \"eff (NatRule (r, f))\n        (?\\<Gamma>, labelAtIn v p)\n        ((\\<lambda>x. extra_assms (v',x) |\\<union>| ?\\<Gamma> \\<turnstile> labelAtIn v' x) |`| f_antecedent r)\".\n    }\n    moreover\n\n    { fix x\n      assume \"x |\\<in>| cont ?t\"\n      then obtain a where \"x = tree v' a ?pth'\" and \"a |\\<in>| f_antecedent r\"\n        by (auto simp add: Rule)\n      note this(1)\n      moreover\n\n      from  \\<open>v' |\\<in>| vertices\\<close> \\<open>a |\\<in>| f_antecedent r\\<close>\n      have \"valid_in_port (v',a)\" by (simp add: Rule)\n      moreover\n\n      note \\<open>terminal_path v' t ?pth'\\<close>\n      ultimately\n\n      have \"\\<exists>v p pth. x = tree v p pth \\<and> valid_in_port (v,p) \\<and>  terminal_path v t pth\"\n        by blast\n    }\n    ultimately\n\n    show ?thesis using Rule\n      by (auto intro!: exI[where x = ?t]  simp add: comp_def funion_assoc)\n  next\n    case Helper\n    from Helper\n    have \"hyps (nodeOf v') p' = None\" by simp\n    with e \\<open>terminal_path v t pth\\<close>\n    have \"terminal_path v' t ?pth'\"..\n\n    have \"labelAtIn v' (plain_ant anyP) = labelAtIn v p\"\n      unfolding s[symmetric]\n      using Helper by (simp add: labelAtIn_def labelAtOut_def)\n    moreover\n    { fix x\n      assume \"x |\\<in>| cont ?t\"\n\n      hence \"x = tree v' (plain_ant anyP) ?pth'\"\n        by (auto simp add: Helper)\n      note this(1)\n      moreover\n\n      from  \\<open>v' |\\<in>| vertices\\<close>\n      have \"valid_in_port (v',plain_ant anyP)\" by (simp add: Helper)\n      moreover\n\n      note \\<open>terminal_path v' t ?pth'\\<close>\n      ultimately\n\n      have \"\\<exists>v p pth. x = tree v p pth \\<and> valid_in_port (v,p) \\<and>  terminal_path v t pth\"\n        by blast\n    }\n    ultimately\n\n    show ?thesis using Helper\n      by (auto intro!: exI[where x = ?t]  simp add: comp_def funion_assoc )\n  qed\nqed\n\nlemma global_in_ass: \"global_assms TYPE('var) |\\<subseteq>| ass_forms\"\nproof\n  fix x\n  assume \"x |\\<in>| global_assms TYPE('var)\"\n  then obtain v pf where \"v |\\<in>| vertices\" and \"nodeOf v = Assumption pf\" and \"x = labelAtOut v (Reg pf)\"\n    by (auto simp add: global_assms_simps)\n  from this (1,2) valid_nodes\n  have \"Assumption pf \\<in> sset nodes\" by (auto simp add: fmember_iff_member_fset)\n  hence \"pf \\<in> set assumptions\" by (auto simp add: nodes_def stream.set_map)\n  hence \"closed pf\" by (rule  assumptions_closed)\n  with \\<open>x = labelAtOut v (Reg pf)\\<close>\n  have \"x = pf\" by (auto simp add: labelAtOut_def lconsts_freshen closed_no_lconsts freshen_closed subst_closed)\n  thus \"x |\\<in>| ass_forms\" using \\<open>pf \\<in> set assumptions\\<close> by (auto simp add: ass_forms_def)\nqed\n\nprimcorec edge_tree :: \"'vertex \\<Rightarrow> ('form, 'var) in_port \\<Rightarrow> ('vertex, 'form, 'var) edge' tree\" where\n \"root (edge_tree v p) = (adjacentTo v p, (v,p))\"\n | \"cont (edge_tree v p) =\n    (case adjacentTo v p of (v', p') \\<Rightarrow>\n    (if isReg v' p' then ((\\<lambda> p. edge_tree  v' p) |`| inPorts (nodeOf v')) else {||}\n    ))\"\n\nlemma tfinite_map_tree: \"tfinite (map_tree f t) \\<longleftrightarrow> tfinite t\"\nproof\n  assume \"tfinite (map_tree f t)\"\n  thus \"tfinite t\"\n    by (induction \"map_tree f t\" arbitrary: t rule: tfinite.induct)\n       (fastforce intro:  tfinite.intros simp add:  tree.map_sel)\nnext\n  assume \"tfinite t\"\n  thus \"tfinite (map_tree f t)\"\n    by (induction t rule: tfinite.induct)\n       (fastforce intro:  tfinite.intros simp add:  tree.map_sel)\nqed\n\n\nlemma finite_tree_edge_tree:\n  \"tfinite (tree v p pth) \\<longleftrightarrow> tfinite (edge_tree v p)\"\nproof-\n  have \"map_tree (\\<lambda> _. ())  (tree v p pth) = map_tree (\\<lambda> _. ()) (edge_tree v p)\"\n   by(coinduction arbitrary: v p pth)\n     (fastforce simp add: tree.map_sel rel_fset_def rel_set_def split: prod.split out_port.split graph_node.split option.split)\n  thus ?thesis by (metis tfinite_map_tree)\nqed\n\ncoinductive forbidden_path :: \"'vertex \\<Rightarrow> ('vertex, 'form, 'var) edge' stream \\<Rightarrow> bool\"   where\n    forbidden_path: \"((v\\<^sub>1,p\\<^sub>1),(v\\<^sub>2,p\\<^sub>2)) \\<in> edges \\<Longrightarrow> hyps (nodeOf v\\<^sub>1) p\\<^sub>1 = None \\<Longrightarrow> forbidden_path v\\<^sub>1 pth \\<Longrightarrow> forbidden_path v\\<^sub>2 (((v\\<^sub>1,p\\<^sub>1),(v\\<^sub>2,p\\<^sub>2))##pth)\"\n\nlemma path_is_forbidden:\n  assumes \"valid_in_port (v,p)\"\n  assumes \"ipath (edge_tree v p) es\"\n  shows \"forbidden_path v es\"\nusing assms\nproof(coinduction arbitrary: v p es)\n  case forbidden_path\n\n  let ?es' = \"stl es\"\n\n  from forbidden_path(2)\n  obtain t' where \"root (edge_tree v p) = shd es\" and \"t' |\\<in>| cont (edge_tree v p)\" and \"ipath t' ?es'\"\n    by rule blast\n\n  from \\<open>root (edge_tree v p) = shd es\\<close>\n  have [simp]: \"shd es = (adjacentTo v p, (v,p))\" by simp\n\n  from saturated[OF \\<open>valid_in_port (v,p)\\<close>]\n  obtain v' p'\n  where e:\"((v',p'),(v,p)) \\<in> edges\" and [simp]: \"adjacentTo v p = (v',p')\"\n    by (auto simp add: adjacentTo_def, metis (no_types, lifting) eq_fst_iff tfl_some)\n  let ?e = \"((v',p'),(v,p))\"\n\n  from e have \"p' |\\<in>| outPorts (nodeOf v')\" using valid_edges by auto\n  thus ?case\n  proof(cases rule: out_port_cases)\n    case Hyp\n    with  \\<open>t' |\\<in>| cont (edge_tree v p)\\<close>\n    have False by auto\n    thus ?thesis..\n  next\n    case Assumption\n    with  \\<open>t' |\\<in>| cont (edge_tree v p)\\<close>\n    have False by auto\n    thus ?thesis..\n  next\n    case (Rule r f)\n    from \\<open>t' |\\<in>| cont (edge_tree v p)\\<close> Rule\n    obtain a where [simp]: \"t' = edge_tree v' a\" and \"a |\\<in>| f_antecedent r\"  by auto\n\n    have \"es = ?e ## ?es'\" by (cases es rule: stream.exhaust_sel) simp\n    moreover\n\n    have \"?e \\<in> edges\" using e by simp\n    moreover\n\n    from \\<open>p' = Reg f\\<close> \\<open>nodeOf v' = Rule r\\<close>\n    have \"hyps (nodeOf v') p' = None\" by simp\n    moreover\n\n    from e valid_edges have \"v' |\\<in>| vertices\"  by auto\n    with \\<open>nodeOf v' = Rule r\\<close> \\<open>a |\\<in>| f_antecedent r\\<close>\n    have \"valid_in_port (v', a)\" by simp\n    moreover\n\n    have \"ipath (edge_tree v' a) ?es'\" using \\<open>ipath t' _\\<close> by simp\n    ultimately\n\n    show ?thesis by metis\n  next\n    case Helper\n    from \\<open>t' |\\<in>| cont (edge_tree v p)\\<close> Helper\n    have [simp]: \"t' = edge_tree v' (plain_ant anyP)\" by simp\n\n    have \"es = ?e ## ?es'\" by (cases es rule: stream.exhaust_sel) simp\n    moreover\n\n    have \"?e \\<in> edges\" using e by simp\n    moreover\n\n    from \\<open>p' = Reg anyP\\<close> \\<open>nodeOf v' = Helper\\<close>\n    have \"hyps (nodeOf v') p' = None\" by simp\n    moreover\n\n    from e valid_edges have \"v' |\\<in>| vertices\"  by auto\n    with \\<open>nodeOf v' = Helper\\<close>\n    have \"valid_in_port (v', plain_ant anyP)\" by simp\n    moreover\n\n    have \"ipath (edge_tree v' (plain_ant anyP)) ?es'\" using \\<open>ipath t' _\\<close> by simp\n    ultimately\n\n    show ?thesis by metis\n  qed\nqed\n\nlemma forbidden_path_prefix_is_path:\n  assumes \"forbidden_path v es\"\n  obtains v' where  \"path v' v (rev (stake n es))\"\n  using assms\n  apply (atomize_elim)\n  apply (induction n arbitrary: v es)\n  apply simp\n  apply (simp add: path_snoc)\n  apply (subst (asm) (2) forbidden_path.simps)\n  apply auto\n  done\n\nlemma forbidden_path_prefix_is_hyp_free:\n  assumes \"forbidden_path v es\"\n  shows \"hyps_free (rev (stake n es))\"\n  using assms\n  apply (induction n arbitrary: v es)\n  apply (simp add: hyps_free_def)\n  apply (subst (asm) (2) forbidden_path.simps)\n  apply (force simp add: hyps_free_def)\n  done\n\n\ntext \\<open>And now we prove that the tree is finite, which requires the above notion of a\n@{term forbidden_path}, i.e.\\@ an infinite path.\\<close>\n\ntheorem finite_tree:\n  assumes \"valid_in_port (v,p)\"\n  assumes \"terminal_vertex v\"\n  shows \"tfinite (tree v p pth)\"\nproof(rule ccontr)\n  let ?n = \"Suc (fcard vertices)\"\n  assume \"\\<not> tfinite (tree v p pth)\"\n  hence \"\\<not> tfinite (edge_tree v p)\" unfolding finite_tree_edge_tree.\n  then obtain es  :: \"('vertex, 'form, 'var) edge' stream\"\n    where \"ipath (edge_tree v p) es\" using Konig by blast\n  with \\<open>valid_in_port (v,p)\\<close>\n  have \"forbidden_path v es\" by (rule path_is_forbidden)\n  from forbidden_path_prefix_is_path[OF this] forbidden_path_prefix_is_hyp_free[OF this]\n  obtain v' where \"path v' v (rev (stake ?n es))\" and \"hyps_free (rev (stake ?n es))\"\n    by blast\n  from this \\<open>terminal_vertex v\\<close>\n  have \"terminal_path  v' v (rev (stake ?n es))\" by (rule terminal_pathI)\n  hence \"length (rev (stake ?n es)) \\<le> fcard vertices\"\n    by (rule hyps_free_limited)\n  thus False by simp\nqed\n\ntext \\<open>The main result of this theory.\\<close>\n\ntheorem solved\nunfolding solved_def\nproof(intro ballI allI conjI impI)\n  fix c\n  assume \"c |\\<in>| conc_forms\"\n  hence \"c \\<in> set conclusions\"  by (auto simp add: conc_forms_def)\n  from this(1) conclusions_present\n  obtain v where \"v |\\<in>| vertices\" and \"nodeOf v = Conclusion c\"\n    by (auto, metis (no_types, lifting) image_iff image_subset_iff notin_fset)\n\n  have \"valid_in_port (v, (plain_ant c))\"\n    using \\<open>v |\\<in>| vertices\\<close> \\<open>nodeOf _ = _ \\<close>  by simp\n\n  have \"terminal_vertex v\" using \\<open>v |\\<in>| vertices\\<close> \\<open>nodeOf v = Conclusion c\\<close> by auto\n\n  let ?t = \"tree v (plain_ant c) []\"\n\n  have \"fst (root ?t) = (global_assms TYPE('var), c)\"\n    using \\<open>c \\<in> set conclusions\\<close> \\<open>nodeOf _ = _\\<close>\n    by (auto simp add: labelAtIn_def conclusions_closed closed_no_lconsts  freshen_def rename_closed subst_closed)\n  moreover\n\n  have \"global_assms TYPE('var) |\\<subseteq>| ass_forms\" by (rule global_in_ass)\n  moreover\n\n  from  \\<open>terminal_vertex v\\<close>\n  have \"terminal_path v v []\" by (rule terminal_path_empty)\n  with \\<open>valid_in_port (v, (plain_ant c))\\<close>\n  have \"wf ?t\" by (rule wf_tree)\n  moreover\n\n  from \\<open>valid_in_port (v, plain_ant c)\\<close> \\<open>terminal_vertex v\\<close>\n  have \"tfinite ?t\" by (rule finite_tree)\n  ultimately\n\n  show \"\\<exists>\\<Gamma> t. fst (root t) = (\\<Gamma> \\<turnstile> c) \\<and> \\<Gamma> |\\<subseteq>| ass_forms \\<and> wf t \\<and> tfinite t\" by blast\nqed\n\nend\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Incredible_Proof_Machine/Incredible_Correctness.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.2778783953497328}}
{"text": "(*  Title:      HOL/HOLCF/IOA/ShortExecutions.thy\n    Author:     Olaf Müller\n*)\n\ntheory ShortExecutions\nimports Traces\nbegin\n\ntext \\<open>\n  Some properties about \\<open>Cut ex\\<close>, defined as follows:\n\n  For every execution ex there is another shorter execution \\<open>Cut ex\\<close>\n  that has the same trace as ex, but its schedule ends with an external action.\n\\<close>\n\ndefinition oraclebuild :: \"('a \\<Rightarrow> bool) \\<Rightarrow> 'a Seq \\<rightarrow> 'a Seq \\<rightarrow> 'a Seq\"\n  where \"oraclebuild P =\n    (fix \\<cdot>\n      (LAM h s t.\n        case t of\n          nil \\<Rightarrow> nil\n        | x ## xs \\<Rightarrow>\n            (case x of\n              UU \\<Rightarrow> UU\n            | Def y \\<Rightarrow>\n                (Takewhile (\\<lambda>x. \\<not> P x) \\<cdot> s) @@\n                (y \\<leadsto> (h \\<cdot> (TL \\<cdot> (Dropwhile (\\<lambda>x. \\<not> P x) \\<cdot> s)) \\<cdot> xs)))))\"\n\ndefinition Cut :: \"('a \\<Rightarrow> bool) \\<Rightarrow> 'a Seq \\<Rightarrow> 'a Seq\"\n  where \"Cut P s = oraclebuild P \\<cdot> s \\<cdot> (Filter P \\<cdot> s)\"\n\ndefinition LastActExtsch :: \"('a,'s) ioa \\<Rightarrow> 'a Seq \\<Rightarrow> bool\"\n  where \"LastActExtsch A sch \\<longleftrightarrow> Cut (\\<lambda>x. x \\<in> ext A) sch = sch\"\n\naxiomatization where\n  Cut_prefixcl_Finite: \"Finite s \\<Longrightarrow> \\<exists>y. s = Cut P s @@ y\"\n\naxiomatization where\n  LastActExtsmall1: \"LastActExtsch A sch \\<Longrightarrow> LastActExtsch A (TL \\<cdot> (Dropwhile P \\<cdot> sch))\"\n\naxiomatization where\n  LastActExtsmall2: \"Finite sch1 \\<Longrightarrow> LastActExtsch A (sch1 @@ sch2) \\<Longrightarrow> LastActExtsch A sch2\"\n\nML \\<open>\nfun thin_tac' ctxt j =\n  rotate_tac (j - 1) THEN'\n  eresolve_tac ctxt [thin_rl] THEN'\n  rotate_tac (~ (j - 1))\n\\<close>\n\n\nsubsection \\<open>\\<open>oraclebuild\\<close> rewrite rules\\<close>\n\nlemma oraclebuild_unfold:\n  \"oraclebuild P =\n    (LAM s t.\n      case t of\n        nil \\<Rightarrow> nil\n      | x ## xs \\<Rightarrow>\n          (case x of\n            UU \\<Rightarrow> UU\n          | Def y \\<Rightarrow>\n            (Takewhile (\\<lambda>a. \\<not> P a) \\<cdot> s) @@\n            (y \\<leadsto> (oraclebuild P \\<cdot> (TL \\<cdot> (Dropwhile (\\<lambda>a. \\<not> P a) \\<cdot> s)) \\<cdot> xs))))\"\n  apply (rule trans)\n  apply (rule fix_eq2)\n  apply (simp only: oraclebuild_def)\n  apply (rule beta_cfun)\n  apply simp\n  done\n\nlemma oraclebuild_UU: \"oraclebuild P \\<cdot> sch \\<cdot> UU = UU\"\n  apply (subst oraclebuild_unfold)\n  apply simp\n  done\n\nlemma oraclebuild_nil: \"oraclebuild P \\<cdot> sch \\<cdot> nil = nil\"\n  apply (subst oraclebuild_unfold)\n  apply simp\n  done\n\nlemma oraclebuild_cons:\n  \"oraclebuild P \\<cdot> s \\<cdot> (x \\<leadsto> t) =\n    (Takewhile (\\<lambda>a. \\<not> P a) \\<cdot> s) @@\n    (x \\<leadsto> (oraclebuild P \\<cdot> (TL \\<cdot> (Dropwhile (\\<lambda>a. \\<not> P a) \\<cdot> s)) \\<cdot> t))\"\n  apply (rule trans)\n  apply (subst oraclebuild_unfold)\n  apply (simp add: Consq_def)\n  apply (simp add: Consq_def)\n  done\n\n\nsubsection \\<open>Cut rewrite rules\\<close>\n\nlemma Cut_nil: \"Forall (\\<lambda>a. \\<not> P a) s \\<Longrightarrow> Finite s \\<Longrightarrow> Cut P s = nil\"\n  apply (unfold Cut_def)\n  apply (subgoal_tac \"Filter P \\<cdot> s = nil\")\n  apply (simp add: oraclebuild_nil)\n  apply (rule ForallQFilterPnil)\n  apply assumption+\n  done\n\nlemma Cut_UU: \"Forall (\\<lambda>a. \\<not> P a) s \\<Longrightarrow> \\<not> Finite s \\<Longrightarrow> Cut P s = UU\"\n  apply (unfold Cut_def)\n  apply (subgoal_tac \"Filter P \\<cdot> s = UU\")\n  apply (simp add: oraclebuild_UU)\n  apply (rule ForallQFilterPUU)\n  apply assumption+\n  done\n\nlemma Cut_Cons:\n  \"P t \\<Longrightarrow> Forall (\\<lambda>x. \\<not> P x) ss \\<Longrightarrow> Finite ss \\<Longrightarrow>\n    Cut P (ss @@ (t \\<leadsto> rs)) = ss @@ (t \\<leadsto> Cut P rs)\"\n  apply (unfold Cut_def)\n  apply (simp add: ForallQFilterPnil oraclebuild_cons TakewhileConc DropwhileConc)\n  done\n\n\nsubsection \\<open>Cut lemmas for main theorem\\<close>\n\nlemma FilterCut: \"Filter P \\<cdot> s = Filter P \\<cdot> (Cut P s)\"\n  apply (rule_tac A1 = \"\\<lambda>x. True\" and Q1 = \"\\<lambda>x. \\<not> P x\" and x1 = \"s\" in take_lemma_induct [THEN mp])\n  prefer 3\n  apply fast\n  apply (case_tac \"Finite s\")\n  apply (simp add: Cut_nil ForallQFilterPnil)\n  apply (simp add: Cut_UU ForallQFilterPUU)\n  text \\<open>main case\\<close>\n  apply (simp add: Cut_Cons ForallQFilterPnil)\n  done\n\nlemma Cut_idemp: \"Cut P (Cut P s) = (Cut P s)\"\n  apply (rule_tac A1 = \"\\<lambda>x. True\" and Q1 = \"\\<lambda>x. \\<not> P x\" and x1 = \"s\" in\n    take_lemma_less_induct [THEN mp])\n  prefer 3\n  apply fast\n  apply (case_tac \"Finite s\")\n  apply (simp add: Cut_nil ForallQFilterPnil)\n  apply (simp add: Cut_UU ForallQFilterPUU)\n  text \\<open>main case\\<close>\n  apply (simp add: Cut_Cons ForallQFilterPnil)\n  apply (rule take_reduction)\n  apply auto\n  done\n\nlemma MapCut: \"Map f\\<cdot>(Cut (P \\<circ> f) s) = Cut P (Map f\\<cdot>s)\"\n  apply (rule_tac A1 = \"\\<lambda>x. True\" and Q1 = \"\\<lambda>x. \\<not> P (f x) \" and x1 = \"s\" in\n    take_lemma_less_induct [THEN mp])\n  prefer 3\n  apply fast\n  apply (case_tac \"Finite s\")\n  apply (simp add: Cut_nil)\n  apply (rule Cut_nil [symmetric])\n  apply (simp add: ForallMap o_def)\n  apply (simp add: Map2Finite)\n  text \\<open>case \\<open>\\<not> Finite s\\<close>\\<close>\n  apply (simp add: Cut_UU)\n  apply (rule Cut_UU)\n  apply (simp add: ForallMap o_def)\n  apply (simp add: Map2Finite)\n  text \\<open>main case\\<close>\n  apply (simp add: Cut_Cons MapConc ForallMap FiniteMap1 o_def)\n  apply (rule take_reduction)\n  apply auto\n  done\n\nlemma Cut_prefixcl_nFinite [rule_format]: \"\\<not> Finite s \\<longrightarrow> Cut P s \\<sqsubseteq> s\"\n  apply (intro strip)\n  apply (rule take_lemma_less [THEN iffD1])\n  apply (intro strip)\n  apply (rule mp)\n  prefer 2\n  apply assumption\n  apply (tactic \"thin_tac' \\<^context> 1 1\")\n  apply (rule_tac x = \"s\" in spec)\n  apply (rule nat_less_induct)\n  apply (intro strip)\n  apply (rename_tac na n s)\n  apply (case_tac \"Forall (\\<lambda>x. \\<not> P x) s\")\n  apply (rule take_lemma_less [THEN iffD2, THEN spec])\n  apply (simp add: Cut_UU)\n  text \\<open>main case\\<close>\n  apply (drule divide_Seq3)\n  apply (erule exE)+\n  apply (erule conjE)+\n  apply hypsubst\n  apply (simp add: Cut_Cons)\n  apply (rule take_reduction_less)\n  text \\<open>auto makes also reasoning about Finiteness of parts of \\<open>s\\<close>!\\<close>\n  apply auto\n  done\n\nlemma execThruCut: \"is_exec_frag A (s, ex) \\<Longrightarrow> is_exec_frag A (s, Cut P ex)\"\n  apply (case_tac \"Finite ex\")\n  apply (cut_tac s = \"ex\" and P = \"P\" in Cut_prefixcl_Finite)\n  apply assumption\n  apply (erule exE)\n  apply (rule exec_prefix2closed)\n  apply (erule_tac s = \"ex\" and t = \"Cut P ex @@ y\" in subst)\n  apply assumption\n  apply (erule exec_prefixclosed)\n  apply (erule Cut_prefixcl_nFinite)\n  done\n\n\nsubsection \\<open>Main Cut Theorem\\<close>\n\nlemma exists_LastActExtsch:\n  \"sch \\<in> schedules A \\<Longrightarrow> tr = Filter (\\<lambda>a. a \\<in> ext A) \\<cdot> sch \\<Longrightarrow>\n    \\<exists>sch. sch \\<in> schedules A \\<and> tr = Filter (\\<lambda>a. a \\<in> ext A) \\<cdot> sch \\<and> LastActExtsch A sch\"\n  apply (unfold schedules_def has_schedule_def [abs_def])\n  apply auto\n  apply (rule_tac x = \"filter_act \\<cdot> (Cut (\\<lambda>a. fst a \\<in> ext A) (snd ex))\" in exI)\n  apply (simp add: executions_def)\n  apply (pair ex)\n  apply auto\n  apply (rule_tac x = \"(x1, Cut (\\<lambda>a. fst a \\<in> ext A) x2)\" in exI)\n  apply simp\n\n  text \\<open>Subgoal 1: Lemma:  propagation of execution through \\<open>Cut\\<close>\\<close>\n  apply (simp add: execThruCut)\n\n  text \\<open>Subgoal 2:  Lemma:  \\<open>Filter P s = Filter P (Cut P s)\\<close>\\<close>\n  apply (simp add: filter_act_def)\n  apply (subgoal_tac \"Map fst \\<cdot> (Cut (\\<lambda>a. fst a \\<in> ext A) x2) = Cut (\\<lambda>a. a \\<in> ext A) (Map fst \\<cdot> x2)\")\n  apply (rule_tac [2] MapCut [unfolded o_def])\n  apply (simp add: FilterCut [symmetric])\n\n  text \\<open>Subgoal 3: Lemma: \\<open>Cut\\<close> idempotent\\<close>\n  apply (simp add: LastActExtsch_def filter_act_def)\n  apply (subgoal_tac \"Map fst \\<cdot> (Cut (\\<lambda>a. fst a \\<in> ext A) x2) = Cut (\\<lambda>a. a \\<in> ext A) (Map fst \\<cdot> x2)\")\n  apply (rule_tac [2] MapCut [unfolded o_def])\n  apply (simp add: Cut_idemp)\n  done\n\n\nsubsection \\<open>Further Cut lemmas\\<close>\n\nlemma LastActExtimplnil: \"LastActExtsch A sch \\<Longrightarrow> Filter (\\<lambda>x. x \\<in> ext A) \\<cdot> sch = nil \\<Longrightarrow> sch = nil\"\n  apply (unfold LastActExtsch_def)\n  apply (drule FilternPnilForallP)\n  apply (erule conjE)\n  apply (drule Cut_nil)\n  apply assumption\n  apply simp\n  done\n\nlemma LastActExtimplUU: \"LastActExtsch A sch \\<Longrightarrow> Filter (\\<lambda>x. x \\<in> ext A) \\<cdot> sch = UU \\<Longrightarrow> sch = UU\"\n  apply (unfold LastActExtsch_def)\n  apply (drule FilternPUUForallP)\n  apply (erule conjE)\n  apply (drule Cut_UU)\n  apply assumption\n  apply simp\n  done\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/HOLCF/IOA/ShortExecutions.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.2778783953497328}}
{"text": "\n\ntheory OperatorAmbiguity\n  imports \"LocalLexing2.Derivations\" Containers.Containers\n\nbegin\nlocale OperatorAmbiguity = CFG +\n  fixes Priority :: \"(('a, 'b) rule \\<times> ('a, 'b) rule) set\"\n  fixes Left :: \"(('a, 'b) rule \\<times> ('a, 'b) rule) set\"\n  fixes Right:: \"(('a, 'b) rule \\<times> ('a, 'b) rule) set\"\n  assumes Priority_between_alternates: \"\\<forall>((N1, r1), (N2, r2)) \\<in> Priority. (N1 = N2)\"\n  assumes Priority_valid: \"\\<forall>((N1, r1), (N2, r2)) \\<in> Priority.  ((N1 = hd r1 \\<and>hd r1 = last r2) \\<or> ((N1 = hd r1 \\<and> last r1 = hd r2)))\"\n  assumes Priority_is_strictpart: \"antisym Priority \\<and> trans Priority \\<and> irrefl Priority\"\n  assumes Left_between_alternates: \"\\<forall>((N1, r1), (N2, r2)) \\<in> Left. (N1 = N2)\"\n  assumes Left_valid: \"\\<forall>((N1, r1), (N2, r2)) \\<in> Left.  (N1 = hd r1\\<and>hd r2 = hd r1 \\<and>hd r1 = last r1  \\<and>hd r2 = last r2)\"\n  assumes Right_between_alternates: \"\\<forall>((N1, r1), (N2, r2)) \\<in> Right. (N1 = N2)\"\n  assumes Right_valid: \"\\<forall>((N1, r1), (N2, r2)) \\<in> Right.  (N1 = hd r1\\<and>hd r2 = hd r1 \\<and>hd r1 = last r1  \\<and>hd r2 = last r2)\"\n  assumes Relation_safety: \"(Left \\<inter> Right = {}) \\<and> (Priority \\<inter> Right = {}) \\<and> (Left \\<inter> Priority = {})\"\nbegin\n\n(*how to best define those kind of derivations? \\<longrightarrow> need derivation sequence*)\n(*how do I define a precedence left derivation?\n \n! !precedencederivations have to be defined on their subtrees specifically*)\n(*actual way it works is all subtrees are precedenceleft derivations and root does not have any of the other*)\n(*along right/left spine?*)\n\n\nfun \"derive\"::\"('a, 'b) sentence \\<Rightarrow> nat \\<Rightarrow> ('a, 'b) rule \\<Rightarrow> ('a, 'b)sentence\" where\n\"derive a n (N, r) = (take (n-1) a)@r@(drop n a) \"\n\nfun valid::\" ('a, 'b) sentence \\<Rightarrow> ('a, 'b) rule \\<Rightarrow> bool\" where\n\"valid s (N, r) =  ((last r = N) \\<and>(\\<exists>w . is_word w \\<and> s = w@[N]@r))\"\n\n(*one level for associativity, all others along, right/left spine*)\n\n(*this happens until \\<Longrightarrow> remember position of any other nonterminal and iterate all get applied to it*)\n(*splits derivation such that all children in leftmost expansion of leading rule are in left*)\nfun left_children::\"('a, 'b) rule \\<Rightarrow> ('a, 'b) derivation \\<Rightarrow> ('a, 'b) derivation \\<times> ('a, 'b) derivation\" where\n\"left_children (_, r) D = (if \\<not> is_nonterminal (hd r) then ([],  D) \n                      else \n                        snd (foldr \n    (\\<lambda>(n, S, R) (N, left, right). if (n \\<le> N) then (n+ length R,left@[(n,S, R)], right) else  (n ,left, right@[(n,S, R)])) D (0, [], [])))\"\n\n(*drop all until one derivation gets applied to the rightmost terminal*)\n(*potential bug length r*)\n(*splits derivatioin such that all children in rightmost expansion of leading rule are in right*)\nfun right_children::\"('a, 'b) rule \\<Rightarrow> ('a, 'b) derivation \\<Rightarrow> ('a, 'b) derivation \\<times> ('a, 'b) derivation\" where\n\"right_children (_, r) D = (if \\<not> is_nonterminal (last r) then ([],  D) \n                      else \n                        snd (foldr \n    (\\<lambda>(n, S, R) (N, left, right). if (n < N) then (n+ length R,left@[(n,S, R)], right) else  (n ,left, right@[(n,S, R)])) D (length r, [], [])))\"\n\nlemma left_children_safe: \"fst (left_children r D)@(snd (left_children r D)) = D\"\n  apply(induct D)\n   apply(auto)\n  sorry\n\nlemma right_children_safe: \"fst (right_children r D)@(snd (right_children r D)) = D\"\n  apply(induct D)\n   apply(auto)\n  sorry\n\n\nfun rightspine::\"('a, 'b) rule \\<Rightarrow> ('a, 'b) derivation \\<Rightarrow> ('a, 'b) rule set\" where \n\"rightspine (S, r) D = set (map snd (filter (\\<lambda>(_, N, _). N = S)(takeWhile (\\<lambda>(n, N, r). is_nonterminal (hd r)) (snd (right_children (S, r) D)))))\"\n\n(*\nfun leftspine::\"sentence \\<Rightarrow> rule \\<Rightarrow> derivation \\<Rightarrow> rule set\" where\n\"leftspine s (S, r) D = set (snd (foldr (\\<lambda>(n, rule) (a, d). let s = derive a n rule in (s, if valid s (S, r) then rule#d else d))  D (s@[S]@r ,[]))) \"\n*)\n\nfun rightexpansion::\"('a, 'b) derivation \\<Rightarrow> ('a, 'b) derivation\" where\n\"rightexpansion [] = []\" |\n\"rightexpansion ((n, H, r)#D) = (if \\<not> is_nonterminal (last r) then [] else \n      snd (foldr (\\<lambda>(n1, H1, r1) (N, s). if n1 = N then \n          (if  is_nonterminal (last r1) then ((N + length r1), (n1, H1, r1)#s) else (N -1, (n1, H1, r1)#s))\n          else (N, s)) D (n + length r, [])))\" \n\nfun leftspine::\"('a, 'b) rule \\<Rightarrow> ('a, 'b) derivation \\<Rightarrow> ('a, 'b) rule set\" where\n\"leftspine (S, r) D = (if \\<not> is_nonterminal (hd r) then {}  else set  (map snd (rightexpansion D)))\"\n\nfun PrecedenceLeftDerivation :: \"('a, 'b) sentence \\<Rightarrow> ('a, 'b) derivation \\<Rightarrow> ('a, 'b) sentence \\<Rightarrow> bool\"\nwhere\n  \"PrecedenceLeftDerivation a [] b = (a = b)\"\n| \"PrecedenceLeftDerivation a (d#D) b = (\\<exists> x. LeftDerives1 a (fst d) (snd d) x \\<and> PrecedenceLeftDerivation x D b \\<and> \n   (leftspine (snd d) D  \\<inter> ((Priority) `` {snd d}) = {}) \\<and>  (rightspine (snd d) D  \\<inter> ((Priority) `` {snd d}) = {}))\"\n(*rotations are not as easy \\<Longrightarrow> have to show that no new conflicts arise*)\n(*or can we prove safety in another way?*)\n(*E\\<alpha> > \\<beta>E*)\nfun ambiguous1::\"('a, 'b) symbol \\<Rightarrow> ('a, 'b) rule \\<Rightarrow>('a, 'b)  rule \\<Rightarrow> bool\" where\n\"ambiguous1 s (N1, r1) (N2, r2)  = ((s = N1) \\<and>(N1 = N2) \\<and> (N1 = hd r1 \\<and>hd r1 = last r2))\"\n(*\\<beta>E > E\\<alpha>*)\nfun ambiguous2::\"('a, 'b) symbol \\<Rightarrow> ('a, 'b) rule \\<Rightarrow> ('a, 'b) rule \\<Rightarrow> bool\" where\n\"ambiguous2 s (N1, r1) (N2, r2)  = ( (s = N1) \\<and>(N1 = N2) \\<and> (N1 = hd r2 \\<and>hd r2 = last r1))\"\n\n(*need additional lemma for derivation shift*)\n(*have to prove that left most holds*)\n(*direction of application should not *)\n(*keep a look at derivation_swap in derivation\n*)\n(*prove this by induction on D*)\n(*is_Word append*)\nlemma nth_append':\"(a@l) ! (n + length a) = l ! n  \"\n  apply(induct a, auto)\n  done\n\nlemma Derives1_append:\"is_sentence u \\<Longrightarrow> Derives1 a n r b \\<Longrightarrow> Derives1 (u@a) (n + length u) r (u@b)\"\n  apply(auto simp add: Derives1_def)\n  apply(rule_tac x=\"u@x\" in exI)\n  apply(rule_tac x=\"y\" in exI)\n  apply(auto simp add: is_sentence_concat)\n  done\nlemma LeftDerives1_append_word:\"LeftDerives1 a i r b \\<Longrightarrow> is_word u \\<Longrightarrow> LeftDerives1 (u@a) (i + (length u)) r (u@b)\"\n  apply(auto simp add: Derives1_append  LeftDerives1_def nth_append leftmost_def)\ndone\n(*possible take rules used: first subgoal is on shifting on operator*)\nlemma LeftDerivation_append_word:\"is_word u \\<Longrightarrow> LeftDerivation a D b \\<Longrightarrow> LeftDerivation (u@a) (derivation_shift D 0 (length u)) (u@b)\"\n  apply(auto simp add: derivation_shift_def Derivation_take)\n  apply(induct D arbitrary:u a b)\n  apply(auto )\n  apply(rule_tac x=\"u@x\" in exI)\n  apply(simp add:  LeftDerives1_append_word)\n  done\n\nlemma nth_take:\"n < n1 \\<Longrightarrow>  (take n1 l) ! n =  l ! n  \"\n  apply(induct l, auto)\n  done\n\nlemma nth_concat:\"n < length l \\<Longrightarrow>   (take (length l) (l@a)) ! n = (l@a) ! n\"\n  by(rule nth_take)\n \n \nlemma Derives1_concat:\"is_sentence d \\<Longrightarrow> Derives1 a i r b \\<Longrightarrow> Derives1 (a@d) i r (b@d)\"\n  apply(auto simp add: Derives1_def)\n  apply(rule_tac x=\"x\" in exI)\n  apply(rule_tac x=\"y@d\" in exI)\n  apply(auto simp add: is_sentence_concat)\n  done\n\nlemma LeftDerives1_concat:\"is_sentence d \\<Longrightarrow> LeftDerives1 a i r b \\<Longrightarrow> LeftDerives1 (a@d) i r (b@d)\"\n  apply(auto simp add: LeftDerives1_def leftmost_def Derives1_concat nth_append)\ndone\n\nlemma LeftDerivation_concat: \"is_sentence d \\<Longrightarrow> LeftDerivation a D b \\<Longrightarrow> LeftDerivation (a@d) D (b@d)\"\n  apply(induct D arbitrary: a b d)\n   apply(auto )\n  apply(rule_tac x=\"x@d\" in exI)\n  apply(simp add: LeftDerives1_concat)\n done\n\ntheorem type1_derivation:\n  assumes E:\"is_nonterminal E\" and \"(E, \\<alpha>@[E]) \\<in> \\<RR>\" and \"(E, E#\\<beta>)  \\<in> \\<RR>\"  \n    and v:\"is_word v\" and \nmu:\"is_word \\<mu>\" and root:\"LeftDerivation [E]  D1 (\\<mu>@[E])\" and first_word:\"LeftDerivation \\<alpha> D2 v\" and tail:\"LeftDerivation [E] D3 (E#\\<gamma>)\"\n  and gamma:\"is_sentence \\<gamma>\"\n  shows \"LeftDerivation [E]  (D1@[((length \\<mu>), (E, \\<alpha>@[E]))]@(derivation_shift D2 0 (length \\<mu>))@(derivation_shift D3 0 (length (\\<mu>@v)))@[((length (\\<mu>@v)), (E, E#\\<beta>))]) (\\<mu>@v@E#\\<beta>@\\<gamma>)\"\nproof -\n  from assms have alphaE:\"LeftDerives1 [E] (0) (E, \\<alpha>@[E]) (\\<alpha>@[E])\" by (simp add: LeftDerives1_def leftmost_def Derives1_def)\n  from assms have Ebeta:\"LeftDerives1 [E] (0) (E, E#\\<beta>) (E#\\<beta>)\" by (simp add: LeftDerives1_def leftmost_def Derives1_def)\n  from mu and v have muv:\"is_word (\\<mu>@v)\" by simp\n  from alphaE and mu have \"LeftDerives1 (\\<mu>@[E]) (length \\<mu>) (E, \\<alpha>@[E])  (\\<mu>@\\<alpha>@[E])\" using LeftDerives1_append_word by fastforce\n  from this and root have seq1: \"LeftDerivation [E] (D1@[((length \\<mu>), (E, \\<alpha>@[E]))])  (\\<mu>@\\<alpha>@[E])\" by (auto simp add: LeftDerivation_LeftDerives1 )\n  from first_word and mu have \"LeftDerivation  (\\<mu>@\\<alpha>) (derivation_shift D2 0 (length \\<mu>)) (\\<mu>@v)\" by (auto simp add: LeftDerivation_append_word)\n  from this and E have \"LeftDerivation  (\\<mu>@\\<alpha>@[E]) (derivation_shift D2 0 (length \\<mu>)) (\\<mu>@v@[E])\" using  LeftDerivation_concat apply(force simp: is_sentence_def is_symbol_def) done\n  from seq1 and this have seq2:\"LeftDerivation [E] (D1@[((length \\<mu>), (E, \\<alpha>@[E]))]@(derivation_shift D2 0 (length \\<mu>)))  (\\<mu>@v@[E])\" using LeftDerivation_implies_append apply(force) done\n  from tail and muv have \"LeftDerivation (\\<mu>@v@[E]) (derivation_shift D3 0 (length (\\<mu>@v))) (\\<mu>@v@(E#\\<gamma>))\" using LeftDerivation_append_word by fastforce\n  from this and seq2 have seq3:\"LeftDerivation [E]  (D1@[((length \\<mu>), (E, \\<alpha>@[E]))]@(derivation_shift D2 0 (length \\<mu>))@(derivation_shift D3 0 (length (\\<mu>@v))))(\\<mu>@v@(E#\\<gamma>))\" using LeftDerivation_append  by fastforce\n  from Ebeta and gamma have \"LeftDerives1 (E#\\<gamma>) 0 (E, E#\\<beta>)  (E#\\<beta>@\\<gamma>)\" using LeftDerives1_concat by fastforce\n  from this and muv have  \"LeftDerives1 (\\<mu>@v@E#\\<gamma>) (length (\\<mu>@v)) (E, E#\\<beta>)  (\\<mu>@v@E#\\<beta>@\\<gamma>)\" using LeftDerives1_append_word by fastforce\n  from this and seq3 have \"LeftDerivation [E]  (D1@[((length \\<mu>), (E, \\<alpha>@[E]))]@(derivation_shift D2 0 (length \\<mu>))@(derivation_shift D3 0 (length (\\<mu>@v)))@[((length (\\<mu>@v)), (E, E#\\<beta>))]) (\\<mu>@v@E#\\<beta>@\\<gamma>)\" using LeftDerivation_append by auto\n  from this show ?thesis by auto\nqed\n\n\ntheorem type2_derivation:\n  assumes E:\"is_nonterminal E\" and \"(E, \\<alpha>@[E]) \\<in> \\<RR>\" and beta:\"(E, E#\\<beta>)  \\<in> \\<RR>\"  \n    and v:\"is_word v\" and \nmu:\"is_word \\<mu>\" and root:\"LeftDerivation [E]  D1 (\\<mu>@[E])\" and first_word:\"LeftDerivation \\<alpha> D2 v\" and tail:\"LeftDerivation [E] D3 (E#\\<gamma>)\"\n  and gamma:\"is_sentence \\<gamma>\"\nshows  \"LeftDerivation [E] (D3@[(0, (E, E#\\<beta>))]@D1@[( (length \\<mu>),(E, \\<alpha>@[E]))]@(derivation_shift D2 0 (length \\<mu>)))  (\\<mu>@v@[E]@\\<beta>@\\<gamma>)\"\nproof -\n  from assms have alphaE:\"LeftDerives1 [E] (0) (E, \\<alpha>@[E]) (\\<alpha>@[E])\" by (simp add: LeftDerives1_def leftmost_def Derives1_def)\n  from assms have Ebeta:\"LeftDerives1 [E] (0) (E, E#\\<beta>) (E#\\<beta>)\" by (simp add: LeftDerives1_def leftmost_def Derives1_def)\n  from mu and v have muv:\"is_word (\\<mu>@v)\" by simp\n  from beta have \"is_sentence (E#\\<beta>)\" by (simp)\n  from this have \"is_sentence \\<beta>\" by (simp add: is_sentence_def)\n  from this and gamma have betagamma:\"is_sentence (\\<beta>@\\<gamma>)\" by (simp add: is_sentence_concat)\n  from betagamma and E have Ebetagamma:\"is_sentence ([E]@\\<beta>@\\<gamma>)\" by (simp add: is_sentence_def)\n  from Ebeta and gamma have \"LeftDerives1 (E#\\<gamma>) 0 (E, E#\\<beta>)  (E#\\<beta>@\\<gamma>)\" using LeftDerives1_concat by fastforce\n  from this and tail have  seq1:\"LeftDerivation [E] (D3@[(0, (E, E#\\<beta>))]) (E#\\<beta>@\\<gamma>)\" by (auto simp add: LeftDerivation_LeftDerives1)\n  from betagamma and root have \"LeftDerivation (E#\\<beta>@\\<gamma>) D1 (\\<mu>@E#\\<beta>@\\<gamma>)\" using LeftDerivation_concat by fastforce\n  from this and seq1 have seq2:\"LeftDerivation  [E] (D3@[(0, (E, E#\\<beta>))]@D1)  (\\<mu>@E#\\<beta>@\\<gamma>)\" using LeftDerivation_implies_append by fastforce\n  from mu and alphaE have \"LeftDerives1 (\\<mu>@[E]) (length \\<mu>) (E, \\<alpha>@[E]) (\\<mu>@\\<alpha>@[E])\" using LeftDerives1_append_word by fastforce\n  from betagamma and this  have \"LeftDerives1 (\\<mu>@[E]@\\<beta>@\\<gamma>) (length \\<mu>) (E, \\<alpha>@[E]) (\\<mu>@\\<alpha>@[E]@\\<beta>@\\<gamma>)\" using LeftDerives1_concat by fastforce\n  from this and seq2 have seq3:\"LeftDerivation  [E] (D3@[(0, (E, E#\\<beta>))]@D1@[( (length \\<mu>),(E, \\<alpha>@[E]))])  (\\<mu>@\\<alpha>@[E]@\\<beta>@\\<gamma>)\" using LeftDerivation_LeftDerives1 by fastforce\n  from first_word and mu have \"LeftDerivation (\\<mu>@\\<alpha>) (derivation_shift D2 0 (length \\<mu>)) (\\<mu>@v)\" using LeftDerivation_append_word by fastforce\n  from this and Ebetagamma have \"LeftDerivation (\\<mu>@\\<alpha>@[E]@\\<beta>@\\<gamma>) (derivation_shift D2 0 (length \\<mu>))  (\\<mu>@v@[E]@\\<beta>@\\<gamma>)\" using LeftDerivation_concat by fastforce\n  from this and seq3 have \"LeftDerivation [E] (D3@[(0, (E, E#\\<beta>))]@D1@[( (length \\<mu>),(E, \\<alpha>@[E]))]@(derivation_shift D2 0 (length \\<mu>)))  (\\<mu>@v@[E]@\\<beta>@\\<gamma>)\" using LeftDerivation_implies_append by fastforce\n  from this show ?thesis by auto\nqed\n\ndefinition leftrecursive::\"('a, 'b) symbol \\<Rightarrow> ('a, 'b) rule \\<Rightarrow> bool\" where\n\"leftrecursive s R =  (snd R \\<noteq> [] \\<and> is_nonterminal s \\<and> ((fst R) = s) \\<and> (last (snd R) = s))\"\n\n(*separation of sequence using LeftDerivation_append?*)\n(*imply existence of other rotation*)\n(*might have to fix E as start symbol \\<Longrightarrow> any other way to enable rotation(?)*)\n(*maybe not additional condition for splitting?*)\nfun split_derivation::\"('a, 'b) derivation \\<Rightarrow> (nat \\<times> ('a, 'b) rule) \\<Rightarrow> (('a, 'b)derivation \\<times>  ('a, 'b)derivation)\" where\n\"split_derivation D d = (takeWhile (\\<lambda> s. s \\<noteq> d) D , dropWhile (\\<lambda> s. s \\<noteq> d) D)\"\n\n\nlemma is_sentence_drop:\n  assumes \"is_sentence s\"\n  shows \"is_sentence (drop i s)\"\nproof -\n  have l:\"set (drop i s) \\<subseteq> set s\" using set_drop_subset by fast\n  from assms have \"\\<forall> x \\<in> set s . is_symbol x\" using list_all_def is_sentence_def by metis\n  with l have \"\\<forall> x \\<in> set (drop i s) . is_symbol x\" by blast\n  then  show ?thesis using list_all_def is_sentence_def by metis\nqed\n\nlemma takedrop1: \" take (i-j) (drop j n) = drop j (take i n)\"\n  apply(auto simp add: set_def drop_take )\n  done\n\nlemma list_all_tl:\"list_all a p \\<Longrightarrow> list_all a (tl p)\"\n  apply(induct p)\n   apply(auto simp: tl_def)\n  done\nlemma is_word_drop:\"is_word u \\<Longrightarrow>  is_word ( drop j u)\"\n  apply(auto simp add: is_word_def)\n  apply(induct j arbitrary: u)\n   apply(auto simp add: drop_0)\n  apply(auto simp add: drop_Suc )\n  apply(simp add: list_all_tl)\n  done\nlemma take_invar: \"take i u = take (i+j-j) u\"\n  apply(induct i)\n   apply(auto simp add:  take_Cons )\n  done\nlemma is_word_drop1: \"j \\<le> i \\<Longrightarrow>is_word (take i  u) \\<Longrightarrow>  is_word (take (i - j) (drop j u))\"\n  apply(auto simp: take_drop ) \n  using is_word_drop by simp\n\nlemma wordsmallerleftmost:\n  assumes  word:\"is_word (take i u)\"  and left:\" leftmost j u\"  and valid:\"i \\<le> length u\"\n  shows \"i \\<le> j\"\nproof (rule ccontr)\n  assume \"\\<not> i \\<le> j\"\n  from this have greater:\"j < i\" by auto\n  from left have nonterm:\"is_word (take j u) \\<and> is_nonterminal (u ! j) \\<and> (j < length u)\"apply(auto simp: leftmost_def) done\n  from this and greater have \"(take i u) ! j = u ! j\" by auto\n  from this and nonterm have non_terminal:\"is_nonterminal ((take i u) ! j)\" by auto\n  from greater and valid have \"(length (take i u)) > j\" by auto\n  from this and word and greater have terminal:\"is_terminal ((take i u) ! j)\" by (auto simp add: is_word_def list_all_length)\n  from this and non_terminal show \"False\"  using is_terminal_nonterminal by fastforce\nqed\nlemma LeftDerives1_take:\n  assumes \"LeftDerives1 u n r v \\<and> is_word (take j u) \\<and> j \\<le> length u \"\n  shows \"LeftDerives1 (drop j  u) (n-j) r (drop j v)\"\nproof -\n  from assms have leftmost:\"leftmost n u\" by (simp add: LeftDerives1_def)\n  from this and assms have less:\"j \\<le> n\" using wordsmallerleftmost by fastforce\n  from assms obtain x y N \\<alpha> where \n         deriv1:\"u = x @ [N] @ y \\<and> v = x @ \\<alpha> @ y \\<and> is_sentence x \\<and> is_sentence y \\<and>(N, \\<alpha>) \\<in> \\<RR> \\<and> r = (N, \\<alpha>) \\<and> n = length x\" apply(simp add:  LeftDerives1_def Derives1_def) by blast\n  from this and less have \"j \\<le> length x\" by auto\n  from  this and deriv1 have lem:\"Derives1 (drop j u) (n -j) r (drop j v)\" apply (simp add:Derives1_def leftmost_def) apply(rule_tac x=\"drop j x\" in exI)\n    apply(rule_tac x=\"y\" in exI) apply(auto) apply(simp add: is_sentence_drop) done\n  from leftmost have smallerlength:\"n < length u\" by (simp add: leftmost_def)\n  from deriv1 have c:\"length x <= length v\" by auto\n  from leftmost and less have \"leftmost (n -j) (drop j u)\" apply (auto simp add: leftmost_def is_word_drop)  using is_word_drop1 by fastforce\n  from lem  and this  have head:\"LeftDerives1 (drop j u) (n -j) r (drop j v)\" by (auto simp add: LeftDerives1_def)\n  from this show ?thesis by auto\n  qed\nlemma LeftDerivation_take:\n  shows \"LeftDerivation u D  v \\<Longrightarrow> is_word(take j u) \\<and> j \\<le> length u\\<Longrightarrow> LeftDerivation (drop j  u) (derivation_shift D j 0) (drop j v)\" \nproof (induction D arbitrary: u v)\n  case Nil \n  \n  with Nil have \" u = v\" by auto\n  with this show ?case by (auto simp add: derivation_shift_def)\nnext\n  case (Cons d D)\n  from Cons have \"(\\<exists> x. LeftDerives1 u (fst d) (snd d) x \\<and> LeftDerivation x D v)\" by auto\n  from this obtain c where first:\"LeftDerives1 u (fst d) (snd d) c\" and tail:\"LeftDerivation c D v\" by blast\n  from this have fst:\"leftmost (fst d) u\" by (simp add: LeftDerives1_def)\n  from fst and Cons have less:\"j \\<le> fst d\" using wordsmallerleftmost by fastforce \n  from first obtain x y N \\<alpha> where \n         deriv1:\"u = x @ [N] @ y \\<and> c = x @ \\<alpha> @ y \\<and> is_sentence x \\<and> is_sentence y \\<and>(N, \\<alpha>) \\<in> \\<RR> \\<and> (snd d) = (N, \\<alpha>) \\<and> (fst d) = length x\" apply(simp add:  LeftDerives1_def Derives1_def) by blast\n  from this and less have smaller_word:\"j \\<le> length x\" by auto\n  from  this and deriv1 have lem:\"Derives1 (drop j u) ((fst d) -j) (snd d) (drop j c)\" apply (simp add:Derives1_def leftmost_def) apply(rule_tac x=\"drop j x\" in exI)\n    apply(rule_tac x=\"y\" in exI) apply(auto) apply(simp add: is_sentence_drop) done\n  from fst have smallerlength:\"(fst d) < length u\" by (simp add: leftmost_def)\n  from deriv1 have c:\"length x <= length c\" by auto\n  from fst and less have \"leftmost ((fst d) -j) (drop j u)\" apply (auto simp add: leftmost_def is_word_drop)  using is_word_drop1 by fastforce\n  from lem  and this  have head:\"LeftDerives1 (drop j u) ((fst d) -j) (snd d) (drop j c)\" by (auto simp add: LeftDerives1_def) \n  from first and deriv1 have \"is_word x\" by (auto simp: LeftDerives1_def)\n  from smaller_word and deriv1 have \" take j  c = take j u\" by auto\n  from this  and smaller_word and Cons and c have \"is_word (take j c) \\<and> j \\<le> length c\" by auto\n  from this and tail and Cons have INH:\"LeftDerivation  (drop j c) (derivation_shift D j 0) (drop j v)\" by fastforce\n  from this and head show ?case by fastforce\nqed\n\nlemma split_preserves:\"(fst(split_derivation D d))@(snd(split_derivation D d)) = D\"\n  apply(auto)\n  done\n\n  \n(*s look to be leftrecursive anyways*)\n\nlemma rotatetype1_type2_0:\n  assumes valid:\"is_leftderivation s\" and s_deriv:\"s=\\<mu>@[E] \\<and> is_word \\<mu>\" and \n    leftrecursive:\"leftrecursive E (snd d)\" and deriv:\"LeftDerivation s (d#D) s1\" and \n    conflict:\"\\<exists>r1. r1 \\<in> rightspine (snd d) D \" \n  shows head:\"\\<exists> D1 .LeftDerivation [E]  D1 (\\<mu>@[E])\" and \"LeftDerivation \\<mu> D2 v \\<and> is_word v\" and tail:\"LeftDerivation [E] D3 (E#\\<gamma>)\" \nproof - \n  from valid have \"\\<exists> D0 . LeftDerivation [\\<SS>] D0 s\" apply (simp add: is_leftderivation_def) using  leftderives_implies_LeftDerivation by fastforce \n  from this obtain D0 where \"LeftDerivation [\\<SS>] D0 s\" by blast\n  from deriv have \" \\<exists> x.(LeftDerives1 s (fst d) (snd d) x \\<and> LeftDerivation x D s1)\" by auto\n  obtain \\<alpha> where \"\\<alpha> = (snd (snd d))\" by blast\n  from s_deriv have l1:\"drop (length \\<mu>) s = [E]\" by auto\n  from s_deriv have l2:\"is_word (take (length \\<mu>) s) \\<and> length \\<mu> < length s\" by auto\n  from l1 and l2 and deriv have lderiv:\"LeftDerivation (drop (length \\<mu>) s) (derivation_shift (d#D) (length \\<mu>) 0) (drop (length \\<mu>) s1)\" using LeftDerivation_take by fastforce\n  (*prove that we have a follow up derivation with \\<alpha>@[E]*)\n  from this have \"LeftDerivation (drop (length \\<mu>) s) ((fst d - (length \\<mu>), snd d)#(derivation_shift D (length \\<mu>) 0)) (drop (length \\<mu>) s1)\" by simp\n  from this have \" \\<exists> x.(LeftDerives1  (drop (length \\<mu>) s) (fst d - (length \\<mu>)) (snd d) x \\<and> LeftDerivation x  (derivation_shift (D) (length \\<mu>) 0) (drop (length \\<mu>)s1))\" by auto\n  then obtain x1 where x1':\"LeftDerives1 (drop (length \\<mu>) s) (fst d - (length \\<mu>)) (snd d) x1\" and x2':\"LeftDerivation x1  (derivation_shift (D) (length \\<mu>) 0) (drop (length \\<mu>) s1)\" by blast\n  from l1 and l2 and x1' have l3': \"LeftDerives1 [E] (fst d - (length \\<mu>)) (snd d) x1\" using LeftDerives1_take by fastforce\n  from x1' have \"snd d \\<in> \\<RR>\" by (auto simp: LeftDerives1_def)\n  from this and  leftrecursive have l4:\"LeftDerives1 [E] 0 (snd d) (snd (snd d))\" apply(auto simp add: LeftDerives1_def Derives1_def leftmost_def leftrecursive_def) apply(rule_tac x=\"[]\" in exI) apply(rule_tac x=\"[]\" in exI) apply(rule_tac x=\"fst (snd d)\" in exI)\n    apply(auto)    done\n  from l3' and l4 have \"0 = fst d- (length \\<mu>)\" apply (auto simp add: LeftDerives1_def) using leftmost_unique by fastforce\n  from this and l4 and l3' have eq:\"x1 = (snd (snd d))\" apply(auto simp: LeftDerives1_def) using Derives1_unique_dest by fastforce\n  obtain \\<alpha>E where aE:\"\\<alpha>E = (snd (snd d))\" by blast\n  from this and leftrecursive have last:\"last (\\<alpha>E)= E\" by (auto simp add: leftrecursive_def)\n  from aE and  leftrecursive have nonempty:\"\\<alpha>E \\<noteq> []\" by (auto simp add: leftrecursive_def last_def)\n  from aE  obtain \\<alpha> where \"\\<alpha>  = butlast \\<alpha>E\"  by blast\n  from this and last and nonempty  have \"\\<alpha>@[E] = \\<alpha>E\" by auto\n  from this and aE and eq have aE1:\"x1 = (\\<alpha>@[E])\" by auto\n  from this and l4 and eq have \"LeftDerives1 [E] 0 (snd d) (\\<alpha>@[E])\" by auto  \n  from aE1 and x2' have \"LeftDerivation (\\<alpha>@[E]) (derivation_shift D (length \\<mu>) 0) (drop (length \\<mu>) s1)\" by auto\n  obtain D' where \"D' = derivation_shift D (length \\<mu>) 0\" by blast\n\n  show  \"\\<exists>D1. LeftDerivation [E] D1 (\\<mu> @ [E])\" sorry\n  show \"LeftDerivation \\<mu> D2 v \\<and> is_word v\" sorry\n  show \"LeftDerivation [E] D3 (E # \\<gamma>)\" sorry\nqed\n\n\nlemma rotatetype1_type2:\n  assumes valid:\"is_leftderivation s\" and s_deriv:\"is_word (take (length s -1) s) \\<and> is_nonterminal (last s)  \"and leftrecursive:\"leftrecursive E (snd d)\" and deriv:\"LeftDerivation s (d#D) s1\" and \" \\<exists>r1. r1 \\<in> leftspine (snd d) D \" \n  shows \"\\<exists> D1 .LeftDerivation [E]  D1 (\\<mu>@[E]) \\<and> is_word \\<mu>\" and \"LeftDerivation \\<alpha> D2 v\" and tail':\"LeftDerivation [E] D3 (E#\\<gamma>)\" \nproof - \n\n  show  \"\\<exists>D1. LeftDerivation [E] D1 (\\<mu> @ [E]) \\<and> is_word \\<mu>\" sorry\n  show \"LeftDerivation \\<alpha> D2 v\" sorry\n  show \"LeftDerivation [E] D3 (E # \\<gamma>)\" sorry\nqed\n(*prove theorems that enable a swap given an ambiguous rule pairing \\<Longrightarrow> i.e. this left spine, right spine thing*)\n(*transitivity *)\ntheorem soundness: \n  shows  \"LeftDerivation s D s1 \\<Longrightarrow>\\<exists> D1. PrecedenceLeftDerivation s D1  s1\"\nproof (induction D arbitrary: s s1)\n  case Nil\n  from Nil  have \"s = s1\" by auto\n  with this show ?case apply (rule_tac x=\"[]\" in exI) by auto\nnext\n  case (Cons d D)\n  then show ?case sorry\nqed\n(*alternative formulation of safety, formalize removal scheme*)\n\n(*theorem safety:\n  sorry\n  *)\n(*by induction on length of derivation sequences*)\n\n(*completeness relies on total order though*)\ntheorem completeness:\"PrecedenceLeftDerivation s D1 s1 \\<Longrightarrow> PrecedenceLeftDerivation s D2 s2 \\<Longrightarrow> D1 = D2\" \n  sorry\nend\n\nend", "meta": {"author": "LocalLexingParser", "repo": "LocalLexingParser", "sha": "243c0257ba20c9f9ec389a1883c640ace77d1bbc", "save_path": "github-repos/isabelle/LocalLexingParser-LocalLexingParser", "path": "github-repos/isabelle/LocalLexingParser-LocalLexingParser/LocalLexingParser-243c0257ba20c9f9ec389a1883c640ace77d1bbc/thys/OperatorAmbiguity.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.4843800842769843, "lm_q1q2_score": 0.27787839534973274}}
{"text": "(*<*)\n\\<comment>\\<open> ********************************************************************\n * Project         : CSP-RefTK - A Refinement Toolkit for HOL-CSP\n * Version         : 1.0\n *\n * Author          : Burkhart Wolff, Safouan Taha, Lina Ye.\n *\n * This file       : A Normalization Theory\n *\n * Copyright (c) 2020 Université Paris-Saclay, France\n *\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are\n * met:\n *\n *     * Redistributions of source code must retain the above copyright\n *       notice, this list of conditions and the following disclaimer.\n *\n *     * Redistributions in binary form must reproduce the above\n *       copyright notice, this list of conditions and the following\n *       disclaimer in the documentation and/or other materials provided\n *       with the distribution.\n *\n *     * Neither the name of the copyright holders nor the names of its\n *       contributors may be used to endorse or promote products derived\n *       from this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n ******************************************************************************\\<close>\n(*>*)\n\nchapter\\<open> Normalisation of Deterministic CSP Processes \\<close>\n\ntheory Process_norm\n\nimports \"Properties\" \"Fix_ind_ext\"\n\nbegin\n\nsection\\<open>Deterministic normal-forms with explicit state\\<close>\n\nabbreviation \"P_dnorm Tr Up \\<equiv> (\\<mu> X. (\\<lambda> s. \\<box> e \\<in> (Tr s) \\<rightarrow> X (Up s e)))\"\n\nnotation P_dnorm (\"P\\<^sub>n\\<^sub>o\\<^sub>r\\<^sub>m\\<lbrakk>_,_\\<rbrakk>\" 60)\n\nlemma dnorm_cont[simp]:\n  fixes Tr::\"'state::type \\<Rightarrow> 'event::type set\" and Up::\"'state \\<Rightarrow> 'event \\<Rightarrow> 'state\"\n  shows \"cont (\\<lambda>X. (\\<lambda>s. \\<box> e \\<in> (Tr s) \\<rightarrow> X (Ur s e)))\" (is \"cont ?f\")\nproof -\n  have  \"cont (\\<lambda>X. ?f X s)\" for s by (simp add:cont_fun) \n  then show ?thesis by simp\nqed\n\nsection\\<open>Interleaving product lemma\\<close>\n\nlemma dnorm_inter:  \n  fixes Tr\\<^sub>1 ::\"'state\\<^sub>1::type \\<Rightarrow> 'event::type set\" and Tr\\<^sub>2::\"'state\\<^sub>2::type \\<Rightarrow> 'event set\" \n    and Up\\<^sub>1 ::\"'state\\<^sub>1 \\<Rightarrow> 'event \\<Rightarrow> 'state\\<^sub>1\" and Up\\<^sub>2::\"'state\\<^sub>2 \\<Rightarrow> 'event \\<Rightarrow> 'state\\<^sub>2\"\n  defines P: \"P \\<equiv> P\\<^sub>n\\<^sub>o\\<^sub>r\\<^sub>m\\<lbrakk>Tr\\<^sub>1,Up\\<^sub>1\\<rbrakk>\" (is \"P \\<equiv> fix\\<cdot>(\\<Lambda> X. ?P X)\")\n  defines Q: \"Q \\<equiv> P\\<^sub>n\\<^sub>o\\<^sub>r\\<^sub>m\\<lbrakk>Tr\\<^sub>2,Up\\<^sub>2\\<rbrakk>\" (is \"Q \\<equiv> fix\\<cdot>(\\<Lambda> X. ?Q X)\")\n\n  assumes indep: \\<open>\\<forall>s\\<^sub>1 s\\<^sub>2. Tr\\<^sub>1 s\\<^sub>1 \\<inter> Tr\\<^sub>2 s\\<^sub>2 = {}\\<close>\n\n  defines Tr: \"Tr \\<equiv> (\\<lambda>(s\\<^sub>1,s\\<^sub>2). Tr\\<^sub>1 s\\<^sub>1 \\<union> Tr\\<^sub>2 s\\<^sub>2)\"\n  defines Up: \"Up \\<equiv> (\\<lambda>(s\\<^sub>1,s\\<^sub>2) e. if e \\<in> Tr\\<^sub>1 s\\<^sub>1 then (Up\\<^sub>1 s\\<^sub>1 e,s\\<^sub>2)\n                                else if e \\<in> Tr\\<^sub>2 s\\<^sub>2 then (s\\<^sub>1, Up\\<^sub>2 s\\<^sub>2 e)\n                                else (s\\<^sub>1,s\\<^sub>2))\"  \n  defines S: \"S \\<equiv> P\\<^sub>n\\<^sub>o\\<^sub>r\\<^sub>m\\<lbrakk>Tr,Up\\<rbrakk>\" (is \"S \\<equiv> fix\\<cdot>(\\<Lambda> X. ?S X)\")\n  \n  shows \"(P s\\<^sub>1 ||| Q s\\<^sub>2) = S (s\\<^sub>1,s\\<^sub>2)\"\nproof -\n  have P_rec: \"P = ?P P\" using fix_eq[of \"(\\<Lambda> X. ?P X)\"] P by simp \n  have Q_rec: \"Q = ?Q Q\" using fix_eq[of \"(\\<Lambda> X. ?Q X)\"] Q by simp \n  have S_rec: \"S = ?S S\" using fix_eq[of \"(\\<Lambda> X. ?S X)\"] S by simp\n  have dir1: \"\\<forall> s\\<^sub>1 s\\<^sub>2. (P s\\<^sub>1 ||| Q s\\<^sub>2) \\<sqsubseteq> S (s\\<^sub>1, s\\<^sub>2)\"\n  proof(subst P, subst Q, \n        induct rule:parallel_fix_ind_inc[of \"\\<lambda>x y. \\<forall> s\\<^sub>1 s\\<^sub>2. (x s\\<^sub>1 ||| y s\\<^sub>2) \\<sqsubseteq> S (s\\<^sub>1,s\\<^sub>2)\"])\n      case adm:1                                       \n      then show ?case\n        by (intro adm_all adm_below) (simp_all add: cont2cont_fun)\n    next\n      case base_fst:(2 y)\n      then show ?case by (metis Inter_commute app_strict minimal par_Int_bot) \n    next\n      case base_snd:(3 x)\n      then show ?case by (simp add: par_Int_bot)\n    next\n      case step:(4 x y)\n      then show ?case (is \"\\<forall> s\\<^sub>1 s\\<^sub>2. ?C s\\<^sub>1 s\\<^sub>2\")\n      proof(intro allI)\n        fix s\\<^sub>1 s\\<^sub>2\n        show \"?C s\\<^sub>1 s\\<^sub>2\"\n          apply(simp)\n          apply(subst mprefix_Par_Int[where C=\"{}\", simplified])\n          apply(subst S_rec, simp add: Tr Up mprefix_Un_distr)\n          apply(intro mono_det_ref mono_mprefix_ref)\n          using step(3)[simplified] indep apply simp\n          using step(2)[simplified] indep by fastforce\n      qed\n    qed     \n  have dir2: \"\\<forall> s\\<^sub>1 s\\<^sub>2.  S (s\\<^sub>1, s\\<^sub>2) \\<sqsubseteq> (P s\\<^sub>1 ||| Q s\\<^sub>2)\"\n    proof(subst S, induct rule:fix_ind_k[of \"\\<lambda>x. \\<forall> s\\<^sub>1 s\\<^sub>2. x (s\\<^sub>1,s\\<^sub>2) \\<sqsubseteq> (P s\\<^sub>1 ||| Q s\\<^sub>2)\" 1])\n      case adm:1\n      show ?case  by (intro adm_all adm_below) (simp_all add: cont_fun) \n    next\n      case base_k_steps:2\n      then show ?case by simp\n    next\n      case step:(3 x)\n      then show ?case (is \"\\<forall> s\\<^sub>1 s\\<^sub>2. ?C s\\<^sub>1 s\\<^sub>2\")\n      proof(intro allI)\n        fix s\\<^sub>1 s\\<^sub>2\n        have P_rec_sym:\"Mprefix (Tr\\<^sub>1 s\\<^sub>1) (\\<lambda>e. P (Up\\<^sub>1 s\\<^sub>1 e)) = P s\\<^sub>1\" using P_rec by metis\n        have Q_rec_sym:\"Mprefix (Tr\\<^sub>2 s\\<^sub>2) (\\<lambda>e. Q (Up\\<^sub>2 s\\<^sub>2 e)) = Q s\\<^sub>2\" using Q_rec by metis\n        show \"?C s\\<^sub>1 s\\<^sub>2\"\n          apply(simp add: Tr Up mprefix_Un_distr)\n          apply(subst P_rec, subst Q_rec, subst mprefix_Par_Int[where C=\"{}\", simplified])\n          apply(intro mono_det_ref mono_mprefix_ref)\n          apply(subst Q_rec_sym, simp add:step[simplified])\n          apply(subst P_rec_sym) using step[simplified] indep by fastforce\n      qed\n    qed\n  from dir1 dir2 show ?thesis using below_antisym by blast\nqed\n\nsection \\<open>Synchronous product lemma\\<close>\nlemma dnorm_par:  \n  fixes Tr\\<^sub>1 ::\"'state\\<^sub>1::type \\<Rightarrow> 'event::type set\" and Tr\\<^sub>2::\"'state\\<^sub>2::type \\<Rightarrow> 'event set\" \n    and Up\\<^sub>1 ::\"'state\\<^sub>1 \\<Rightarrow> 'event \\<Rightarrow> 'state\\<^sub>1\" and Up\\<^sub>2::\"'state\\<^sub>2 \\<Rightarrow> 'event \\<Rightarrow> 'state\\<^sub>2\"\n  defines P: \"P \\<equiv> P\\<^sub>n\\<^sub>o\\<^sub>r\\<^sub>m\\<lbrakk>Tr\\<^sub>1,Up\\<^sub>1\\<rbrakk>\" (is \"P \\<equiv> fix\\<cdot>(\\<Lambda> X. ?P X)\")\n  defines Q: \"Q \\<equiv> P\\<^sub>n\\<^sub>o\\<^sub>r\\<^sub>m\\<lbrakk>Tr\\<^sub>2,Up\\<^sub>2\\<rbrakk>\" (is \"Q \\<equiv> fix\\<cdot>(\\<Lambda> X. ?Q X)\")\n\n  defines Tr: \"Tr \\<equiv> (\\<lambda>(s\\<^sub>1,s\\<^sub>2). Tr\\<^sub>1 s\\<^sub>1 \\<inter> Tr\\<^sub>2 s\\<^sub>2)\"\n  defines Up: \"Up \\<equiv> (\\<lambda>(s\\<^sub>1,s\\<^sub>2) e. (Up\\<^sub>1 s\\<^sub>1 e, Up\\<^sub>2 s\\<^sub>2 e))\"  \n  defines S: \"S \\<equiv> P\\<^sub>n\\<^sub>o\\<^sub>r\\<^sub>m\\<lbrakk>Tr,Up\\<rbrakk>\" (is \"S \\<equiv> fix\\<cdot>(\\<Lambda> X. ?S X)\")\n  \n  shows \"(P s\\<^sub>1 || Q s\\<^sub>2) = S (s\\<^sub>1,s\\<^sub>2)\"\nproof -\n  have P_rec: \"P = ?P P\" using fix_eq[of \"(\\<Lambda> X. ?P X)\"] P by simp \n  have Q_rec: \"Q = ?Q Q\" using fix_eq[of \"(\\<Lambda> X. ?Q X)\"] Q by simp \n  have S_rec: \"S = ?S S\" using fix_eq[of \"(\\<Lambda> X. ?S X)\"] S by simp\n  have dir1: \"\\<forall> s\\<^sub>1 s\\<^sub>2. (P s\\<^sub>1 || Q s\\<^sub>2) \\<sqsubseteq> S (s\\<^sub>1, s\\<^sub>2)\"\n  proof(subst P, subst Q, \n        induct rule:parallel_fix_ind[of \"\\<lambda>x y. \\<forall> s\\<^sub>1 s\\<^sub>2. (x s\\<^sub>1 || y s\\<^sub>2) \\<sqsubseteq> S (s\\<^sub>1,s\\<^sub>2)\"])\n      case adm:1\n      then show ?case\n        by (intro adm_all adm_below) (simp_all add: cont2cont_fun)\n    next\n      case base:2\n      then show ?case by (simp add: par_Int_bot)\n    next\n      case step:(3 x y)\n      then show ?case (is \"\\<forall> s\\<^sub>1 s\\<^sub>2. ?C s\\<^sub>1 s\\<^sub>2\")\n      proof(intro allI)\n        fix s\\<^sub>1 s\\<^sub>2\n        show \"?C s\\<^sub>1 s\\<^sub>2\"\n          apply(simp)\n          apply(subst mprefix_Par_distr[where C=\"UNIV\", simplified])\n          apply(subst S_rec, simp add: Tr Up mprefix_Un_distr)\n          by (simp add:step mono_mprefix_ref)\n      qed\n    qed     \n  have dir2: \"\\<forall> s\\<^sub>1 s\\<^sub>2.  S (s\\<^sub>1, s\\<^sub>2) \\<sqsubseteq> (P s\\<^sub>1 || Q s\\<^sub>2)\"\n    proof(subst S, induct rule:fix_ind_k[of \"\\<lambda>x. \\<forall> s\\<^sub>1 s\\<^sub>2. x (s\\<^sub>1,s\\<^sub>2) \\<sqsubseteq> (P s\\<^sub>1 || Q s\\<^sub>2)\" 1])\n      case adm:1\n      show ?case  by (intro adm_all adm_below) (simp_all add: cont_fun) \n    next\n      case base_k_steps:2\n      then show ?case by simp\n    next\n      case step:(3 x)\n      then show ?case (is \"\\<forall> s\\<^sub>1 s\\<^sub>2. ?C s\\<^sub>1 s\\<^sub>2\")\n      proof(intro allI)\n        fix s\\<^sub>1 s\\<^sub>2\n        have P_rec_sym:\"Mprefix (Tr\\<^sub>1 s\\<^sub>1) (\\<lambda>e. P (Up\\<^sub>1 s\\<^sub>1 e)) = P s\\<^sub>1\" using P_rec by metis\n        have Q_rec_sym:\"Mprefix (Tr\\<^sub>2 s\\<^sub>2) (\\<lambda>e. Q (Up\\<^sub>2 s\\<^sub>2 e)) = Q s\\<^sub>2\" using Q_rec by metis\n        show \"?C s\\<^sub>1 s\\<^sub>2\"\n          apply(simp add: Tr Up)\n          apply(subst P_rec, subst Q_rec, subst mprefix_Par_distr[where C=\"UNIV\", simplified])\n          apply(rule mono_mprefix_ref) \n          using step by auto\n      qed\n    qed\n  from dir1 dir2 show ?thesis using below_antisym by blast\nqed\n\nsection\\<open>Consequences\\<close>\n\\<comment>\\<open>reachable states from one starting state\\<close>\ninductive_set \\<RR> for Tr ::\"'state::type \\<Rightarrow> 'event::type set\" \n                and Up::\"'state \\<Rightarrow> 'event \\<Rightarrow> 'state\" \n                and s\\<^sub>0::'state \n  where rbase: \"s\\<^sub>0 \\<in> \\<RR> Tr Up s\\<^sub>0\"\n      | rstep: \"s \\<in> \\<RR> Tr Up s\\<^sub>0 \\<Longrightarrow> e \\<in> Tr s  \\<Longrightarrow> Up s e \\<in> \\<RR> Tr Up s\\<^sub>0\"\n\n\n\n\\<comment>\\<open>Deadlock freeness\\<close>\nlemma deadlock_free_dnorm_ :\n  fixes Tr ::\"'state::type \\<Rightarrow> 'event::type set\" \n    and Up ::\"'state \\<Rightarrow> 'event \\<Rightarrow> 'state\" \n    and s\\<^sub>0::'state \n  assumes non_reachable_sink: \"\\<forall>s \\<in> \\<RR> Tr Up s\\<^sub>0. Tr s \\<noteq> {}\"\n  defines P: \"P \\<equiv> P\\<^sub>n\\<^sub>o\\<^sub>r\\<^sub>m\\<lbrakk>Tr,Up\\<rbrakk>\" (is \"P \\<equiv> fix\\<cdot>(\\<Lambda> X. ?P X)\")\n  shows  \"s \\<in> \\<RR> Tr Up s\\<^sub>0 \\<Longrightarrow> deadlock_free_v2 (P s)\"\nproof(unfold deadlock_free_v2_FD DF\\<^sub>S\\<^sub>K\\<^sub>I\\<^sub>P_def, induct arbitrary:s rule:fix_ind)\n  show \"adm (\\<lambda>a. \\<forall>x. x \\<in> \\<RR> Tr Up s\\<^sub>0 \\<longrightarrow> a \\<sqsubseteq>\\<^sub>F\\<^sub>D P x)\" by (simp add: le_FD_adm monofun_def) \nnext\n  fix s :: \"'state\" \n  show \"s \\<in> \\<RR> Tr Up s\\<^sub>0 \\<Longrightarrow> \\<bottom> \\<sqsubseteq>\\<^sub>F\\<^sub>D P s\" by simp\nnext\n  fix s :: \"'state\"  and x :: \"'event process\"\n  have P_rec: \"P = ?P P\" using fix_eq[of \"(\\<Lambda> X. ?P X)\"] P by simp \n  assume 1 : \"\\<And>s. s \\<in> \\<RR> Tr Up s\\<^sub>0 \\<Longrightarrow> x \\<sqsubseteq>\\<^sub>F\\<^sub>D P s\" \n   and   2 : \"s \\<in> \\<RR> Tr Up s\\<^sub>0 \"\n  from   1 2 show \"(\\<Lambda> x. (\\<sqinter>xa\\<in>UNIV \\<rightarrow>  x) \\<sqinter> SKIP)\\<cdot>x \\<sqsubseteq>\\<^sub>F\\<^sub>D P s\"\n    apply(simp add:failure_divergence_refine_def)\n    apply(subst P_rec, rule_tac trans_FD[simplified failure_divergence_refine_def, \n                       rotated, OF Mprefix_refines_Mndet])\n    apply(rule_tac CSP.mono_ndet_FD_left)      \n    by (metis CSP.mono_ndet_FD_right rstep empty_not_UNIV mndet_distrib mono_mndet_FD \n              non_reachable_sink sup_top_left)\nqed\n\n\n\nlemmas deadlock_free_dnorm = deadlock_free_dnorm_[rotated, OF rbase, rule_format]\n\nend\n\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/CSP_RefTK/Process_norm.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736783928749127, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.2778783882886352}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory AbstractArrays\nimports\n  \"CLib.TypHeapLib\"\n  \"Word_Lib.WordSetup\"\nbegin\n\n(*\n * Return a list of addresses that contain an element for an array at location\n * \"p\" of length \"n\".\n *)\nprimrec\n  array_addrs :: \"('a::mem_type) ptr \\<Rightarrow> nat \\<Rightarrow> 'a ptr list\"\nwhere\n  \"array_addrs _ 0 = []\"\n| \"array_addrs p (Suc n) = p # (array_addrs (p +\\<^sub>p 1) n)\"\n\ndeclare array_addrs.simps(2) [simp del]\n\n(* The first element is in the array if the array has non-zero length. *)\nlemma hd_in_array_addrs [simp]:\n  \"(x \\<in> set (array_addrs x n)) = (n > 0)\"\n  by (case_tac n, auto simp: array_addrs.simps(2))\n\nlemma array_addrs_1 [simp]:\n  \"array_addrs p (Suc 0) = [p]\"\n  \"array_addrs p 1 = [p]\"\n  by (auto simp: array_addrs.simps(2))\n\n(* All array elements are aligned if the array itself is aligned. *)\nlemma array_addrs_ptr_aligned:\n     \"\\<lbrakk> x \\<in> set (array_addrs p n); ptr_aligned p \\<rbrakk> \\<Longrightarrow> ptr_aligned x\"\n  apply (induct n arbitrary: x p)\n   apply clarsimp\n  apply (clarsimp simp: array_addrs.simps(2))\n  apply (erule disjE)\n   apply clarsimp\n  apply atomize\n  apply (drule_tac x=x in spec)\n  apply (drule_tac x=\"p +\\<^sub>p 1\" in spec)\n  apply (clarsimp simp: ptr_aligned_plus)\n  done\n\n(* Split off the last element in an array. *)\nlemma set_array_addrs_unfold_last:\n  shows \"set (array_addrs a (Suc n)) = set (array_addrs a n) \\<union> {(a :: ('a::mem_type) ptr) +\\<^sub>p int n}\"\n    (is \"?LHS a n = ?RHS a n\")\nproof (induct n arbitrary: a)\n  fix a\n  show \"?LHS a 0 = ?RHS a 0\"\n    by clarsimp\nnext\n  fix a n\n  assume induct: \"\\<And>a. ?LHS a n = ?RHS a n\"\n  show \"?LHS a (Suc n) = ?RHS a (Suc n)\"\n  apply (subst array_addrs.simps(2))\n  apply (subst set_simps)\n  apply (subst induct [where a=\"a +\\<^sub>p 1\"])\n  apply (subst array_addrs.simps(2))\n  apply (subst set_simps)\n  apply (clarsimp simp: CTypesDefs.ptr_add_def field_simps insert_commute)\n  done\nqed\n\n(* Alternative representation of the set of array elements. *)\nlemma set_array_addrs:\n  \"set (array_addrs (p :: ('a::mem_type) ptr) n)\n           = {x. \\<exists>k. x = p +\\<^sub>p int k \\<and> k < n }\"\n  apply (induct n arbitrary: p)\n   apply (clarsimp simp: not_less)\n  apply (subst set_array_addrs_unfold_last)\n  apply atomize\n  apply (drule_tac x=p in spec)\n  apply (erule ssubst)\n  apply (rule set_eqI)\n  apply (rule iffI)\n   apply clarsimp\n   apply (erule disjE)\n    apply clarsimp\n    apply force\n   apply force\n  apply clarsimp\n  apply (drule_tac x=k in spec)\n  apply (clarsimp simp: not_less)\n  apply (subgoal_tac \"k = n\")\n   apply clarsimp\n  apply clarsimp\n  done\n\nend\n", "meta": {"author": "NICTA", "repo": "l4v", "sha": "3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b", "save_path": "github-repos/isabelle/NICTA-l4v", "path": "github-repos/isabelle/NICTA-l4v/l4v-3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b/tools/autocorres/AbstractArrays.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926665999540698, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.2778365467729137}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      HoarePartial.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nheader {* Derived Hoare Rules for Partial Correctness *}\n\ntheory HoarePartial imports HoarePartialProps begin\n\nlemma conseq_no_aux:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' c Q',A';\n    \\<forall>s. s \\<in> P \\<longrightarrow> (s\\<in>P' \\<and> (Q' \\<subseteq> Q) \\<and> (A' \\<subseteq> A))\\<rbrakk>\n  \\<Longrightarrow>\n  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule conseq [where P'=\"\\<lambda>Z. P'\" and Q'=\"\\<lambda>Z. Q'\" and A'=\"\\<lambda>Z. A'\"]) auto\n\n\nlemma conseq_exploit_pre:\n             \"\\<lbrakk>\\<forall>s \\<in> P. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s} \\<inter> P) c Q,A\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule Conseq)\n  apply clarify\n  apply (rule_tac x=\"{s} \\<inter> P\" in exI)  \n  apply (rule_tac x=\"Q\" in exI)  \n  apply (rule_tac x=\"A\" in exI)  \n  by simp\n\n\nlemma conseq:\"\\<lbrakk>\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z);\n              \\<forall>s. s \\<in> P \\<longrightarrow> (\\<exists> Z. s\\<in>P' Z \\<and> (Q' Z \\<subseteq> Q) \\<and> (A' Z \\<subseteq> A))\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule Conseq') blast\n\nlemma Lem: \"\\<lbrakk>\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z);\n             P \\<subseteq> {s. \\<exists> Z. s\\<in>P' Z \\<and> (Q' Z \\<subseteq> Q) \\<and> (A' Z \\<subseteq> A)}\\<rbrakk>\n             \\<Longrightarrow>\n             \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (lem x c) Q,A\"\n  apply (unfold lem_def) \n  apply (erule conseq)\n  apply blast\n  done\n\nlemma LemAnno:\nassumes conseq:  \"P \\<subseteq> {s. \\<exists>Z. s\\<in>P' Z \\<and> \n                     (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> t \\<in> Q) \\<and> (\\<forall>t. t \\<in> A' Z \\<longrightarrow> t \\<in> A)}\"\nassumes lem: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (lem x c) Q,A\"\n  apply (rule Lem [OF lem])\n  using conseq\n  by blast\n\nlemma LemAnnoNoAbrupt:\nassumes conseq:  \"P \\<subseteq>  {s. \\<exists>Z. s\\<in>P' Z \\<and> (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> t \\<in> Q)}\"\nassumes lem: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),{}\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (lem x c) Q,{}\"\n  apply (rule Lem [OF lem])\n  using conseq\n  by blast\n\nlemma TrivPost: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z)\n                 \\<Longrightarrow>\n                 \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c UNIV,UNIV\"\napply (rule allI)\napply (erule conseq)\napply auto\ndone\n\nlemma TrivPostNoAbr: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),{}\n                 \\<Longrightarrow>\n                 \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c UNIV,{}\"\napply (rule allI)\napply (erule conseq)\napply auto\ndone\n\nlemma conseq_under_new_pre:\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P' c Q',A';\n        \\<forall>s \\<in> P. s \\<in> P' \\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A\\<rbrakk>\n\\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P c Q,A\"\napply (rule conseq)\napply (rule allI)\napply assumption\napply auto\ndone\n\n\n\nlemma DynComConseq:\n  assumes \"P \\<subseteq> {s. \\<exists>P' Q' A'.  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P' (c s) Q',A' \\<and> P \\<subseteq> P' \\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A}\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P DynCom c Q,A\"\n  using assms\n  apply -\n  apply (rule DynCom)\n  apply clarsimp\n  apply (rule Conseq)\n  apply clarsimp\n  apply blast\n  done\n\nlemma SpecAnno: \n assumes consequence: \"P \\<subseteq> {s. (\\<exists> Z. s\\<in>P' Z \\<and> (Q' Z \\<subseteq> Q) \\<and> (A' Z \\<subseteq> A))}\"\n assumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) (c Z) (Q' Z),(A' Z)\"\n assumes bdy_constant:  \"\\<forall>Z. c Z = c undefined\"\n shows   \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (specAnno P' c Q' A') Q,A\"\nproof -\n  from spec bdy_constant\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ((P' Z)) (c undefined) (Q' Z),(A' Z)\"\n    apply - \n    apply (rule allI)\n    apply (erule_tac x=Z in allE)\n    apply (erule_tac x=Z in allE)\n    apply simp\n    done\n  with consequence show ?thesis\n    apply (simp add: specAnno_def)\n    apply (erule conseq)\n    apply blast\n    done\nqed\n\nlemma SpecAnno': \n \"\\<lbrakk>P \\<subseteq> {s.  \\<exists> Z. s\\<in>P' Z \\<and> \n            (\\<forall>t. t \\<in> Q' Z \\<longrightarrow>  t \\<in> Q) \\<and> (\\<forall>t. t \\<in> A' Z \\<longrightarrow> t \\<in>  A)};\n   \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) (c Z) (Q' Z),(A' Z);\n   \\<forall>Z. c Z = c undefined\n  \\<rbrakk> \\<Longrightarrow>\n    \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (specAnno P' c Q' A') Q,A\"\napply (simp only: subset_iff [THEN sym])\napply (erule (1) SpecAnno)\napply assumption\ndone\n\n\nlemma SpecAnnoNoAbrupt: \n \"\\<lbrakk>P \\<subseteq> {s.  \\<exists> Z. s\\<in>P' Z \\<and> \n            (\\<forall>t. t \\<in> Q' Z \\<longrightarrow>  t \\<in> Q)};\n   \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) (c Z) (Q' Z),{};\n   \\<forall>Z. c Z = c undefined\n  \\<rbrakk> \\<Longrightarrow>\n    \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (specAnno P' c Q' (\\<lambda>s. {})) Q,A\"\napply (rule SpecAnno')\napply auto\ndone\n\nlemma Skip: \"P \\<subseteq> Q \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Skip Q,A\"\n  by (rule hoarep.Skip [THEN conseqPre],simp)\n\nlemma Basic: \"P \\<subseteq> {s. (f s) \\<in> Q} \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Basic f) Q,A\"\n  by (rule hoarep.Basic [THEN conseqPre])\n\nlemma BasicCond: \n  \"\\<lbrakk>P \\<subseteq> {s. (b s \\<longrightarrow> f s\\<in>Q) \\<and> (\\<not> b s \\<longrightarrow> g s\\<in>Q)}\\<rbrakk> \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Basic (\\<lambda>s. if b s then f s else g s) Q,A\"\n  apply (rule Basic)\n  apply auto\n  done\n\nlemma Spec: \"P \\<subseteq> {s. (\\<forall>t. (s,t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s,t) \\<in> r)} \n            \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Spec r) Q,A\"\nby (rule hoarep.Spec [THEN conseqPre])\n\nlemma SpecIf: \n  \"\\<lbrakk>P \\<subseteq> {s. (b s \\<longrightarrow> f s \\<in> Q) \\<and> (\\<not> b s \\<longrightarrow> g s \\<in> Q \\<and> h s \\<in> Q)}\\<rbrakk> \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Spec (if_rel b f g h) Q,A\"\n  apply (rule Spec)\n  apply (auto simp add: if_rel_def)\n  done\n\n\nlemma Seq [trans, intro?]: \n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>1 R,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Seq c\\<^sub>1 c\\<^sub>2) Q,A\"\n  by (rule hoarep.Seq)\n\nlemma SeqSwap: \n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c2 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c1 R,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Seq c1 c2) Q,A\"\n  by (rule Seq)\n\nlemma BSeq:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>1 R,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (bseq c\\<^sub>1 c\\<^sub>2) Q,A\"\n  by (unfold bseq_def) (rule Seq)\n\n\nlemma Cond: \n  assumes wp: \"P \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\" \n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P\\<^sub>1 c\\<^sub>1 Q,A\" \n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P\\<^sub>2 c\\<^sub>2 Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) Q,A\"\nproof (rule hoarep.Cond [THEN conseqPre])\n  from deriv_c1 \n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. (s \\<in> b \\<longrightarrow> s \\<in> P\\<^sub>1) \\<and> (s \\<notin> b \\<longrightarrow> s \\<in> P\\<^sub>2)} \\<inter> b) c\\<^sub>1 Q,A\"\n    by (rule conseqPre) blast\nnext\n  from deriv_c2 \n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. (s \\<in> b \\<longrightarrow> s \\<in> P\\<^sub>1) \\<and> (s \\<notin> b \\<longrightarrow> s \\<in> P\\<^sub>2)} \\<inter> - b) c\\<^sub>2 Q,A\"\n    by (rule conseqPre) blast\nnext\n  show \"P \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\" by (rule wp)\nqed \n\n\nlemma CondSwap: \n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P1 c1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P2 c2 Q,A; P \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P2)}\\<rbrakk>\n   \\<Longrightarrow> \n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c1 c2) Q,A\"\n  by (rule Cond)\n\nlemma Cond': \n  \"\\<lbrakk>P \\<subseteq> {s. (b \\<subseteq> P1) \\<and> (- b \\<subseteq> P2)};\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P1 c1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P2 c2 Q,A\\<rbrakk>\n   \\<Longrightarrow> \n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c1 c2) Q,A\"\n  by (rule CondSwap) blast+\n\nlemma CondInv: \n  assumes wp: \"P \\<subseteq> Q\" \n  assumes inv: \"Q \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\" \n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P\\<^sub>1 c\\<^sub>1 Q,A\" \n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P\\<^sub>2 c\\<^sub>2 Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) Q,A\"\nproof -\n  from wp inv\n  have \"P \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\"\n    by blast\n  from Cond [OF this deriv_c1 deriv_c2]\n  show ?thesis .\nqed\n\nlemma CondInv': \n  assumes wp: \"P \\<subseteq> I\" \n  assumes inv: \"I \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\" \n  assumes wp': \"I \\<subseteq> Q\" \n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P\\<^sub>1 c\\<^sub>1 I,A\" \n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P\\<^sub>2 c\\<^sub>2 I,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) Q,A\"\nproof -\n  from CondInv [OF wp inv deriv_c1 deriv_c2]\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) I,A\".\n  from conseqPost [OF this wp' subset_refl]\n  show ?thesis .\nqed\n    \n\nlemma switchNil:\n  \"P \\<subseteq> Q \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P (switch v []) Q,A\"\n  by (simp add: Skip)\n \nlemma switchCons:\n  \"\\<lbrakk>P \\<subseteq> {s. (v s \\<in> V \\<longrightarrow> s \\<in> P\\<^sub>1) \\<and> (v s \\<notin> V \\<longrightarrow> s \\<in> P\\<^sub>2)}; \n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P\\<^sub>1 c Q,A;\n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P\\<^sub>2 (switch v vs) Q,A\\<rbrakk>\n\\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P (switch v ((V,c)#vs)) Q,A\"\n  by (simp add: Cond)\n\nlemma Guard:\n \"\\<lbrakk>P \\<subseteq> g \\<inter> R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\napply (rule Guard [THEN conseqPre, of _ _ _ _ R])\napply (erule conseqPre)\napply auto\ndone\n\nlemma GuardSwap:\n \"\\<lbrakk> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> g \\<inter> R\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\n  by (rule Guard)\n\nlemma Guarantee:\n \"\\<lbrakk>P \\<subseteq> {s. s \\<in> g \\<longrightarrow> s \\<in> R}; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; f \\<in> F\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\napply (rule Guarantee [THEN conseqPre, of _ _ _ _ _ \"{s. s \\<in> g \\<longrightarrow> s \\<in> R}\"])\napply   assumption\napply  (erule conseqPre)\napply auto\ndone\n\nlemma GuaranteeSwap:\n \"\\<lbrakk> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> {s. s \\<in> g \\<longrightarrow> s \\<in> R}; f \\<in> F\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\n  by (rule Guarantee)\n\nlemma GuardStrip:\n \"\\<lbrakk>P \\<subseteq> R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; f \\<in> F\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\napply (rule Guarantee [THEN conseqPre])\napply auto\ndone\n\nlemma GuardStripSwap:\n \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> R; f \\<in> F\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\n  by (rule GuardStrip)\n\nlemma GuaranteeStrip:\n \"\\<lbrakk>P \\<subseteq> R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; f \\<in> F\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guaranteeStrip f g c) Q,A\"\n  by (unfold guaranteeStrip_def) (rule GuardStrip)\n\nlemma GuaranteeStripSwap:\n \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> R; f \\<in> F\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guaranteeStrip f g c) Q,A\"\n  by (unfold guaranteeStrip_def) (rule GuardStrip)\n\nlemma GuaranteeAsGuard:\n \"\\<lbrakk>P \\<subseteq> g \\<inter> R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guaranteeStrip f g c) Q,A\"\n  by (unfold guaranteeStrip_def) (rule Guard)\n\n\nlemma GuaranteeAsGuardSwap:\n \"\\<lbrakk> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> g \\<inter> R\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guaranteeStrip f g c) Q,A\"\n  by (rule GuaranteeAsGuard)\n\nlemma GuardsNil:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guards [] c) Q,A\"\n  by simp\n\n\n\nlemma GuardsConsGuaranteeStrip:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P guaranteeStrip f g (guards gs c) Q,A \\<Longrightarrow> \n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guards (guaranteeStripPair f g#gs) c) Q,A\"\n  by (simp add: guaranteeStripPair_def guaranteeStrip_def)\n\nlemma While: \n  assumes P_I: \"P \\<subseteq> I\" \n  assumes deriv_body: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (I \\<inter> b) c I,A\"\n  assumes I_Q: \"I \\<inter> -b \\<subseteq> Q\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnno b I V c) Q,A\"\nproof -\n  from deriv_body P_I I_Q\n  show ?thesis\n    apply (simp add: whileAnno_def)\n    apply (erule conseqPrePost [OF HoarePartialDef.While]) \n    apply simp_all\n    done\nqed\n\ntext {* @{term \"J\"} will be instantiated by tactic with @{term \"gs' \\<inter> I\"} for\n  those guards that are not stripped.*} \nlemma  WhileAnnoG:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guards gs \n                    (whileAnno  b J V (Seq c (guards gs Skip)))) Q,A \n        \\<Longrightarrow> \n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnnoG gs b I V c) Q,A\"\n  by (simp add: whileAnnoG_def whileAnno_def while_def)\n\n\ntext {* This form stems from @{term \"strip_guards F (whileAnnoG gs b I V c)\"} *}\n\n\n\n\n\nlemma WhileAnnoGFix:\nassumes whileAnnoFix:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guards gs \n                (whileAnnoFix  b J V (\\<lambda>Z. (Seq (c Z) (guards gs Skip))))) Q,A\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnnoGFix gs b I V c) Q,A\"\n  using whileAnnoFix\n  by (simp add: whileAnnoGFix_def whileAnnoFix_def while_def)\n\nlemma Bind:\n  assumes adapt: \"P \\<subseteq> {s. s \\<in> P' s}\" \n  assumes c: \"\\<forall>s. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' s) (c (e s)) Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (bind e c) Q,A\" \napply (rule conseq [where P'=\"\\<lambda>Z. {s. s=Z \\<and> s \\<in> P' Z}\" and Q'=\"\\<lambda>Z. Q\" and \nA'=\"\\<lambda>Z. A\"])\napply  (rule allI)\napply  (unfold bind_def)\napply  (rule DynCom)\napply  (rule ballI)\napply  simp\napply  (rule conseqPre)\napply   (rule c [rule_format])\napply  blast\nusing adapt\napply blast\ndone\n\nlemma Block:\nassumes adapt: \"P \\<subseteq> {s. init s \\<in> P' s}\"\nassumes bdy: \"\\<forall>s. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' s) bdy {t. return s t \\<in> R s t},{t. return s t \\<in> A}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (block init bdy return c) Q,A\" \napply (rule conseq [where P'=\"\\<lambda>Z. {s. s=Z \\<and> init s \\<in> P' Z}\" and Q'=\"\\<lambda>Z. Q\" and \nA'=\"\\<lambda>Z. A\"])\nprefer 2\nusing adapt\napply  blast\napply (rule allI)\napply (unfold block_def)\napply (rule DynCom)\napply (rule ballI)\napply clarsimp\napply (rule_tac R=\"{t. return Z t \\<in> R Z t}\" in SeqSwap )\napply  (rule_tac  P'=\"\\<lambda>Z'. {t. t=Z' \\<and> return Z t \\<in> R Z t}\" and \n          Q'=\"\\<lambda>Z'. Q\" and A'=\"\\<lambda>Z'. A\" in conseq)\nprefer 2 apply simp\napply  (rule allI)\napply  (rule DynCom)\napply  (clarsimp)\napply  (rule SeqSwap)\napply   (rule c [rule_format])\napply  (rule Basic)\napply  clarsimp\napply (rule_tac R=\"{t. return Z t \\<in> A}\" in Catch)\napply  (rule_tac R=\"{i. i \\<in> P' Z}\" in Seq)\napply   (rule Basic)\napply   clarsimp\napply  simp\napply  (rule bdy [rule_format])\napply (rule SeqSwap)\napply  (rule Throw)\napply (rule Basic)\napply simp\ndone\n\n\nlemma BlockSwap:\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes bdy: \"\\<forall>s. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' s) bdy {t. return s t \\<in> R s t},{t. return s t \\<in> A}\"\nassumes adapt: \"P \\<subseteq> {s. init s \\<in> P' s}\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (block init bdy return c) Q,A\"\nusing adapt bdy c  \n  by (rule Block)\n\n\nlemma BlockSpec:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' Z \\<and> \n                             (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t) \\<and>\n                             (\\<forall>t. t \\<in> A' Z \\<longrightarrow> return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes bdy: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) bdy (Q' Z),(A' Z)\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (block init bdy return c) Q,A\" \napply (rule conseq [where P'=\"\\<lambda>Z. {s. init s \\<in> P' Z \\<and> \n                             (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t) \\<and>\n                             (\\<forall>t. t \\<in> A' Z \\<longrightarrow> return s t \\<in> A)}\" and Q'=\"\\<lambda>Z. Q\" and \nA'=\"\\<lambda>Z. A\"])\nprefer 2\nusing adapt\napply  blast\napply (rule allI)\napply (unfold block_def)\napply (rule DynCom)\napply (rule ballI)\napply clarsimp\napply (rule_tac R=\"{t. return s t \\<in> R s t}\" in SeqSwap )\napply  (rule_tac  P'=\"\\<lambda>Z'. {t. t=Z' \\<and> return s t \\<in> R s t}\" and \n          Q'=\"\\<lambda>Z'. Q\" and A'=\"\\<lambda>Z'. A\" in conseq)\nprefer 2 apply simp\napply  (rule allI)\napply  (rule DynCom)\napply  (clarsimp)\napply  (rule SeqSwap)\napply   (rule c [rule_format])\napply  (rule Basic)\napply  clarsimp\napply (rule_tac R=\"{t. return s t \\<in> A}\" in Catch)\napply  (rule_tac R=\"{i. i \\<in> P' Z}\" in Seq)\napply   (rule Basic)\napply   clarsimp\napply  simp\napply  (rule conseq [OF bdy])\napply  clarsimp\napply  blast\napply (rule SeqSwap)\napply  (rule Throw)\napply (rule Basic)\napply simp\ndone\n\nlemma Throw: \"P \\<subseteq> A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Throw Q,A\"\n  by (rule hoarep.Throw [THEN conseqPre])\n\nlemmas Catch = hoarep.Catch\nlemma CatchSwap: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,R\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Catch c\\<^sub>1 c\\<^sub>2 Q,A\"\n  by (rule hoarep.Catch)\n\nlemma raise: \"P \\<subseteq> {s. f s \\<in> A} \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P raise f Q,A\"\n  apply (simp add: raise_def)\n  apply (rule Seq)\n  apply  (rule Basic)\n  apply  (assumption)\n  apply (rule Throw)\n  apply (rule subset_refl)\n  done\n\nlemma condCatch: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,((b \\<inter> R) \\<union> (-b \\<inter> A));\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk> \n                  \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P condCatch c\\<^sub>1 b c\\<^sub>2 Q,A\"\n  apply (simp add: condCatch_def)\n  apply (rule Catch)\n  apply  assumption\n  apply (rule CondSwap)\n  apply   (assumption)\n  apply  (rule hoarep.Throw)\n  apply blast\n  done\n\nlemma condCatchSwap: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A;\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,((b \\<inter> R) \\<union> (-b \\<inter> A))\\<rbrakk> \n                  \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P condCatch c\\<^sub>1 b c\\<^sub>2 Q,A\"\n  by (rule condCatch)\n\n\nlemma ProcSpec:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' Z \\<and> \n                             (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t) \\<and>\n                             (\\<forall>t. t \\<in> A' Z \\<longrightarrow> return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) Call p (Q' Z),(A' Z)\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nusing adapt c p\napply (unfold call_def) \nby (rule BlockSpec)\n\nlemma ProcSpec':\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' Z \\<and> \n                             (\\<forall>t \\<in> Q' Z. return s t \\<in> R s t) \\<and>\n                             (\\<forall>t \\<in> A' Z. return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) Call p (Q' Z),(A' Z)\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule ProcSpec [OF _ c p])\napply (insert adapt)\napply clarsimp\napply (drule (1) subsetD)\napply (clarsimp)\napply (rule_tac x=Z in exI)\napply blast\ndone\n\nlemma ProcSpecNoAbrupt:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' Z \\<and> \n                             (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) Call p (Q' Z),{}\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule ProcSpec [OF _ c p])\nusing adapt\napply simp\ndone\n\nlemma FCall:  \n\"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return (\\<lambda>s t. c (result t))) Q,A\n\\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (fcall init p return result c) Q,A\"\n  by (simp add: fcall_def)\n\n\nlemma ProcRec:\n  assumes deriv_bodies:  \n   \"\\<forall>p\\<in>Procs. \n    \\<forall>Z. \\<Gamma>,\\<Theta>\\<union>(\\<Union>p\\<in>Procs. \\<Union>Z. {(P p Z,p,Q p Z,A p Z)})\n        \\<turnstile>\\<^bsub>/F\\<^esub> (P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n  assumes Procs_defined: \"Procs \\<subseteq> dom \\<Gamma>\"\n  shows \"\\<forall>p\\<in>Procs. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>(P p Z) Call p (Q p Z),(A p Z)\"\n  by (intro strip)\n     (rule CallRec' \n     [OF _   Procs_defined deriv_bodies],\n     simp_all)\n\nlemma ProcRec':\n  assumes ctxt: \"\\<Theta>' = \\<Theta>\\<union>(\\<Union>p\\<in>Procs. \\<Union>Z. {(P p Z,p,Q p Z,A p Z)})\"\n  assumes deriv_bodies:  \n   \"\\<forall>p\\<in>Procs. \\<forall>Z. \\<Gamma>,\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> (P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n  assumes Procs_defined: \"Procs \\<subseteq> dom \\<Gamma>\"\n  shows \"\\<forall>p\\<in>Procs. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>(P p Z) Call p (Q p Z),(A p Z)\"\n  using ctxt deriv_bodies\n  apply simp\n  apply (erule ProcRec [OF _ Procs_defined])\n  done\n\n\nlemma ProcRecList:\n  assumes deriv_bodies:  \n   \"\\<forall>p\\<in>set Procs. \n    \\<forall>Z. \\<Gamma>,\\<Theta>\\<union>(\\<Union>p\\<in>set Procs. \\<Union>Z. {(P p Z,p,Q p Z,A p Z)})\n        \\<turnstile>\\<^bsub>/F\\<^esub> (P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n  assumes dist: \"distinct Procs\"\n  assumes Procs_defined: \"set Procs \\<subseteq> dom \\<Gamma>\"\n  shows \"\\<forall>p\\<in>set Procs. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>(P p Z) Call p (Q p Z),(A p Z)\"\n  using deriv_bodies Procs_defined\n  by (rule ProcRec)\n\nlemma  ProcRecSpecs:\n  \"\\<lbrakk>\\<forall>(P,p,Q,A) \\<in> Specs. \\<Gamma>,\\<Theta>\\<union>Specs\\<turnstile>\\<^bsub>/F\\<^esub> P (the (\\<Gamma> p)) Q,A;\n    \\<forall>(P,p,Q,A) \\<in> Specs. p \\<in> dom \\<Gamma>\\<rbrakk>\n  \\<Longrightarrow> \\<forall>(P,p,Q,A) \\<in> Specs. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\napply (auto intro: CallRec)\ndone\n\n\nlemma ProcRec1:\n  assumes deriv_body:  \n   \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<union>(\\<Union>Z. {(P Z,p,Q Z,A Z)})\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) (the (\\<Gamma> p)) (Q Z),(A Z)\"\n  assumes p_defined: \"p \\<in> dom \\<Gamma>\"\n  shows \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) Call p (Q Z),(A Z)\"\nproof -\n  from deriv_body p_defined\n  have \"\\<forall>p\\<in>{p}. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) Call p (Q Z),(A Z)\"\n    by - (rule ProcRec [where A=\"\\<lambda>p. A\" and P=\"\\<lambda>p. P\" and Q=\"\\<lambda>p. Q\"],\n          simp_all)\n  thus ?thesis\n    by simp\nqed\n\nlemma ProcNoRec1:\n  assumes deriv_body:  \n   \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) (the (\\<Gamma> p)) (Q Z),(A Z)\"\n  assumes p_def: \"p \\<in> dom \\<Gamma>\"\n  shows \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) Call p (Q Z),(A Z)\"\nproof -\nfrom deriv_body\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<union>(\\<Union>Z. {(P Z,p,Q Z,A Z)})\n             \\<turnstile>\\<^bsub>/F\\<^esub> (P Z) (the (\\<Gamma> p)) (Q Z),(A Z)\"\n    by (blast intro: hoare_augment_context)\n  from this p_def\n  show ?thesis \n    by (rule ProcRec1)\nqed\n\nlemma ProcBody:\n assumes WP: \"P \\<subseteq> P'\"\n assumes deriv_body: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' body Q,A\" \n assumes body: \"\\<Gamma> p = Some body\"\n shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Call p Q,A\"\napply (rule conseqPre [OF _ WP])\napply (rule ProcNoRec1 [rule_format, where P=\"\\<lambda>Z. P'\" and Q=\"\\<lambda>Z. Q\" and A=\"\\<lambda>Z. A\"]) \napply  (insert body)\napply  simp\napply  (rule hoare_augment_context [OF deriv_body])\napply  blast\napply fastforce\ndone\n\nlemma CallBody:\nassumes adapt: \"P \\<subseteq> {s. init s \\<in> P' s}\"\nassumes bdy: \"\\<forall>s. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' s) body {t. return s t \\<in> R s t},{t. return s t \\<in> A}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes body: \"\\<Gamma> p = Some body\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (unfold call_def)\napply (rule Block [OF adapt _ c])\napply (rule allI)\napply (rule ProcBody [where \\<Gamma>=\\<Gamma>, OF _ bdy [rule_format] body])\napply simp\ndone\n\nlemmas ProcModifyReturn = HoarePartialProps.ProcModifyReturn \nlemmas ProcModifyReturnSameFaults = HoarePartialProps.ProcModifyReturnSameFaults\n\nlemma ProcModifyReturnNoAbr:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes result_conform:\n      \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:  \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} Call p (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nby (rule ProcModifyReturn [OF spec result_conform _ modifies_spec]) simp\n\nlemma ProcModifyReturnNoAbrSameFaults:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes result_conform:\n      \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:  \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call p (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nby (rule ProcModifyReturnSameFaults [OF spec result_conform _ modifies_spec]) simp\n\n\nlemma DynProc: \n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' s Z \\<and>\n                          (\\<forall>t. t \\<in> Q' s Z \\<longrightarrow>  return s t \\<in> R s t) \\<and>\n                          (\\<forall>t. t \\<in> A' s Z \\<longrightarrow> return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>s\\<in> P. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' s Z) Call (p s) (Q' s Z),(A' s Z)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P dynCall init p return c Q,A\"\napply (rule conseq [where P'=\"\\<lambda>Z. {s. s=Z \\<and> s \\<in> P}\"\n  and Q'=\"\\<lambda>Z. Q\" and A'=\"\\<lambda>Z. A\"])\nprefer 2\nusing adapt\napply  blast\napply (rule allI)\napply (unfold dynCall_def call_def block_def)\napply (rule DynCom)\napply clarsimp\napply (rule DynCom)\napply clarsimp\napply (frule in_mono [rule_format, OF adapt])\napply clarsimp\napply (rename_tac Z')\napply (rule_tac R=\"Q' Z Z'\" in Seq)\napply  (rule CatchSwap)\napply   (rule SeqSwap)\napply    (rule Throw) \napply    (rule subset_refl)\napply   (rule Basic)\napply   (rule subset_refl)\napply  (rule_tac R=\"{i. i \\<in> P' Z Z'}\" in Seq)\napply   (rule Basic) \napply   clarsimp\napply  simp\napply  (rule_tac Q'=\"Q' Z Z'\" and A'=\"A' Z Z'\" in conseqPost)\nusing p\napply    clarsimp\napply   simp\napply  clarsimp\napply  (rule_tac  P'=\"\\<lambda>Z''. {t. t=Z'' \\<and> return Z t \\<in> R Z t}\" and \n          Q'=\"\\<lambda>Z''. Q\" and A'=\"\\<lambda>Z''. A\" in conseq)\nprefer 2 apply simp\napply (rule allI)\napply (rule DynCom)\napply clarsimp\napply (rule SeqSwap)\napply  (rule c [rule_format])\napply (rule Basic)\napply clarsimp\ndone\n\nlemma DynProc': \n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' s Z \\<and>\n                          (\\<forall>t \\<in> Q' s Z. return s t \\<in> R s t) \\<and>\n                          (\\<forall>t \\<in> A' s Z. return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>s\\<in> P. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' s Z) Call (p s) (Q' s Z),(A' s Z)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P dynCall init p return c Q,A\"\nproof -\n  from adapt have \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' s Z \\<and>\n                          (\\<forall>t. t \\<in> Q' s Z \\<longrightarrow>  return s t \\<in> R s t) \\<and>\n                          (\\<forall>t. t \\<in> A' s Z \\<longrightarrow> return s t \\<in> A)}\"\n    by blast\n  from this c p show ?thesis\n    by (rule DynProc)\nqed\n\n\nlemma DynProcStaticSpec: \nassumes adapt: \"P \\<subseteq> {s. s \\<in> S \\<and> (\\<exists>Z. init s \\<in> P' Z  \\<and> \n                            (\\<forall>\\<tau>. \\<tau> \\<in> Q' Z \\<longrightarrow> return s \\<tau> \\<in> R s \\<tau>) \\<and>\n                            (\\<forall>\\<tau>. \\<tau> \\<in> A' Z \\<longrightarrow> return s \\<tau> \\<in> A))}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes spec: \"\\<forall>s\\<in>S. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) Call (p s) (Q' Z),(A' Z)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from adapt have P_S: \"P \\<subseteq> S\"\n    by blast\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> S) (dynCall init p return c) Q,A\"\n    apply (rule DynProc [where P'=\"\\<lambda>s Z. P' Z\" and Q'=\"\\<lambda>s Z. Q' Z\" \n                         and A'=\"\\<lambda>s Z. A' Z\", OF _ c])\n    apply  clarsimp\n    apply  (frule in_mono [rule_format, OF adapt])\n    apply  clarsimp\n    using spec\n    apply clarsimp\n    done\n  thus ?thesis\n    by (rule conseqPre) (insert P_S,blast)\nqed\n\n\nlemma DynProcProcPar: \nassumes adapt: \"P \\<subseteq> {s. p s = q \\<and> (\\<exists>Z. init s \\<in> P' Z  \\<and> \n                            (\\<forall>\\<tau>. \\<tau> \\<in> Q' Z \\<longrightarrow> return s \\<tau> \\<in> R s \\<tau>) \\<and>\n                            (\\<forall>\\<tau>. \\<tau> \\<in> A' Z \\<longrightarrow> return s \\<tau> \\<in> A))}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) Call q (Q' Z),(A' Z)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\n  apply (rule DynProcStaticSpec [where S=\"{s. p s = q}\",simplified, OF adapt c])\n  using spec\n  apply simp\n  done\n\n\nlemma DynProcProcParNoAbrupt: \nassumes adapt: \"P \\<subseteq> {s. p s = q \\<and> (\\<exists>Z. init s \\<in> P' Z  \\<and> \n                            (\\<forall>\\<tau>. \\<tau> \\<in> Q' Z \\<longrightarrow> return s \\<tau> \\<in> R s \\<tau>))}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) Call q (Q' Z),{}\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -  \n  have \"P \\<subseteq> {s. p s = q \\<and> (\\<exists> Z. init s \\<in> P' Z \\<and> \n                      (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t) \\<and>\n                      (\\<forall>t. t \\<in> {} \\<longrightarrow> return s t \\<in> A))}\"\n    (is \"P \\<subseteq> ?P'\")\n  proof \n    fix s\n    assume P: \"s\\<in>P\"\n    with adapt obtain Z where\n      Pre: \"p s = q \\<and> init s \\<in> P' Z\" and\n      adapt_Norm: \"\\<forall>\\<tau>. \\<tau> \\<in> Q' Z \\<longrightarrow> return s \\<tau> \\<in> R s \\<tau>\" \n      by blast\n    from  adapt_Norm \n    have \"\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t\"\n      by auto\n    then\n    show \"s\\<in>?P'\"\n      using Pre by blast\n  qed\n  note P = this\n  show ?thesis\n    apply -\n    apply (rule DynProcStaticSpec [where S=\"{s. p s = q}\",simplified, OF P c])\n    apply (insert spec)\n    apply auto\n    done\nqed\n\n\nlemma DynProcModifyReturnNoAbr: \n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause: \n            \"\\<forall>s \\<in> P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} Call (p s)  (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from ret_nrm_modif\n  have \"\\<forall>s t. t  \\<in> (Modif (init s)) \n        \\<longrightarrow> return' s t = return s t\"\n    by iprover\n  then \n  have ret_nrm_modif': \"\\<forall>s t. t \\<in> (Modif (init s)) \n                      \\<longrightarrow> return' s t = return s t\"\n    by simp\n  have ret_abr_modif': \"\\<forall>s t. t \\<in> {} \n                        \\<longrightarrow> return' s t = return s t\"\n    by simp\n  from to_prove ret_nrm_modif' ret_abr_modif' modif_clause show ?thesis\n    by (rule dynProcModifyReturn)\nqed\n\n\nlemma ProcDynModifyReturnNoAbrSameFaults: \n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause: \n            \"\\<forall>s \\<in> P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} (Call (p s)) (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from ret_nrm_modif\n  have \"\\<forall>s t. t  \\<in> (Modif (init s)) \n        \\<longrightarrow> return' s t = return s t\"\n    by iprover\n  then\n  have ret_nrm_modif': \"\\<forall>s t. t \\<in> (Modif (init s)) \n                      \\<longrightarrow> return' s t = return s t\"\n    by simp\n  have ret_abr_modif': \"\\<forall>s t. t \\<in> {} \n                        \\<longrightarrow> return' s t = return s t\"\n    by simp\n  from to_prove ret_nrm_modif' ret_abr_modif' modif_clause show ?thesis\n    by (rule dynProcModifyReturnSameFaults)\nqed\n\n\nlemma ProcProcParModifyReturn: \n  assumes q: \"P \\<subseteq> {s. p s = q} \\<inter> P'\"\n   --{* @{thm[source] DynProcProcPar} introduces the same constraint as first conjunction in \n         @{term P'}, so the vcg can simplify it. *}\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes ret_abr_modif: \"\\<forall>s t. t \\<in> (ModifAbr (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause: \n          \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call q) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from to_prove have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return' c) Q,A\"\n    by (rule conseqPre) blast\n  from this ret_nrm_modif \n       ret_abr_modif \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return c) Q,A\"\n    by (rule dynProcModifyReturn) (insert modif_clause,auto)\n  from this q show ?thesis\n    by (rule conseqPre) \nqed\n\n\nlemma ProcProcParModifyReturnSameFaults: \n  assumes q: \"P \\<subseteq> {s. p s = q} \\<inter> P'\"\n   --{* @{thm[source] DynProcProcPar} introduces the same constraint as first conjunction in \n         @{term P'}, so the vcg can simplify it. *}\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes ret_abr_modif: \"\\<forall>s t. t \\<in> (ModifAbr (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause: \n          \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call q (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from to_prove \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return' c) Q,A\"\n    by (rule conseqPre) blast\n  from this ret_nrm_modif \n       ret_abr_modif \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return c) Q,A\"\n    by (rule dynProcModifyReturnSameFaults) (insert modif_clause,auto)\n  from this q show ?thesis\n    by (rule conseqPre) \nqed\n\n\nlemma ProcProcParModifyReturnNoAbr: \n  assumes q: \"P \\<subseteq> {s. p s = q} \\<inter> P'\"\n   --{* @{thm[source] DynProcProcParNoAbrupt} introduces the same constraint as \n      first conjunction in @{term P'}, so the vcg can simplify it. *}\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause: \n            \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call q) (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from to_prove have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return' c) Q,A\"\n    by (rule conseqPre) blast\n  from this ret_nrm_modif \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return c) Q,A\"\n    by (rule DynProcModifyReturnNoAbr) (insert modif_clause,auto)\n  from this q show ?thesis\n    by (rule conseqPre) \nqed\n\nlemma ProcProcParModifyReturnNoAbrSameFaults: \n  assumes q: \"P \\<subseteq> {s. p s = q} \\<inter> P'\"\n   --{* @{thm[source] DynProcProcParNoAbrupt} introduces the same constraint as \n      first conjunction in @{term P'}, so the vcg can simplify it. *}\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause: \n            \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} (Call q) (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from to_prove have \n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return' c) Q,A\"\n    by (rule conseqPre) blast\n  from this ret_nrm_modif \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return c) Q,A\"\n    by (rule ProcDynModifyReturnNoAbrSameFaults) (insert modif_clause,auto)\n  from this q show ?thesis\n    by (rule conseqPre) \nqed\n\nlemma MergeGuards_iff: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P merge_guards c Q,A = \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (auto intro: MergeGuardsI MergeGuardsD)\n\nlemma CombineStrip': \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c' Q,A\"\n  assumes deriv_strip_triv: \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/{}\\<^esub> P c'' UNIV,UNIV\"\n  assumes c'': \"c''= mark_guards False (strip_guards (-F) c')\"\n  assumes c: \"merge_guards c = merge_guards (mark_guards False c')\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof -\n  from deriv_strip_triv have deriv_strip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c'' UNIV,UNIV\"\n    by (auto intro: hoare_augment_context)\n  from deriv_strip [simplified c'']\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P (strip_guards (- F) c') UNIV,UNIV\"\n    by (rule MarkGuardsD)\n  with deriv \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c' Q,A\"\n    by (rule CombineStrip)\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P mark_guards False c' Q,A\"\n    by (rule MarkGuardsI)\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P merge_guards (mark_guards False c') Q,A\"\n    by (rule MergeGuardsI)\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P merge_guards c Q,A\"\n    by (simp add: c)\n  thus ?thesis\n    by (rule MergeGuardsD)\nqed\n\nlemma CombineStrip'': \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{True}\\<^esub> P c' Q,A\"\n  assumes deriv_strip_triv: \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/{}\\<^esub> P c'' UNIV,UNIV\"\n  assumes c'': \"c''= mark_guards False (strip_guards ({False}) c')\"\n  assumes c: \"merge_guards c = merge_guards (mark_guards False c')\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c Q,A\"\n  apply (rule CombineStrip' [OF deriv deriv_strip_triv _ c]) \n  apply (insert c'')\n  apply (subgoal_tac \"- {True} = {False}\")\n  apply auto\n  done\n\nlemma AsmUN:\n  \"(\\<Union>Z. {(P Z, p, Q Z,A Z)}) \\<subseteq> \\<Theta> \n  \\<Longrightarrow> \n  \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) (Call p) (Q Z),(A Z)\"\n  by (blast intro: hoarep.Asm)\n\nlemma augment_context': \n  \"\\<lbrakk>\\<Theta> \\<subseteq> \\<Theta>'; \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P Z)  p (Q Z),(A Z)\\<rbrakk> \n   \\<Longrightarrow> \\<forall>Z. \\<Gamma>,\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z)\"\n  by (iprover intro: hoare_augment_context)\n\n\nlemma hoarep_strip: \n \"\\<lbrakk>\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z); F' \\<subseteq> -F\\<rbrakk> \\<Longrightarrow> \n    \\<forall>Z. strip F' \\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z)\"\n  by (iprover intro: hoare_strip_\\<Gamma>)\n\nlemma augment_emptyFaults:\n \"\\<lbrakk>\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^bsub>/{}\\<^esub> (P Z) p (Q Z),(A Z)\\<rbrakk> \\<Longrightarrow> \n    \\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z)\"\n  by (blast intro: augment_Faults)\n\nlemma augment_FaultsUNIV:\n \"\\<lbrakk>\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z)\\<rbrakk> \\<Longrightarrow> \n    \\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^bsub>/UNIV\\<^esub> (P Z) p (Q Z),(A Z)\"\n  by (blast intro: augment_Faults)\n\nlemma PostConjI [trans]:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c R,B\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\n  by (rule PostConjI)\n\nlemma PostConjI' :\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c R,B\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\n  by (rule PostConjI) iprover+\n\nlemma PostConjE [consumes 1]: \n  assumes conj: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\" \n  assumes E: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c R,B\\<rbrakk> \\<Longrightarrow> S\"\n  shows \"S\"\nproof -\n  from conj have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\" by (rule conseqPost) blast+\n  moreover\n  from conj have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c R,B\" by (rule conseqPost) blast+\n  ultimately show \"S\" \n    by (rule E)\nqed\n\n\nsubsection {* Rules for Single-Step Proof \\label{sec:hoare-isar} *}\n\ntext {*\n We are now ready to introduce a set of Hoare rules to be used in\n single-step structured proofs in Isabelle/Isar.  \n\n \\medskip Assertions of Hoare Logic may be manipulated in\n calculational proofs, with the inclusion expressed in terms of sets\n or predicates.  Reversed order is supported as well.\n*}\n\nlemma annotateI [trans]:\n\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P anno Q,A; c = anno\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P c Q,A\" \n  by simp\n\nlemma annotate_normI:\n  assumes deriv_anno: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P anno Q,A\" \n  assumes norm_eq: \"normalize c = normalize anno\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P c Q,A\"\nproof -\n  from NormalizeI [OF deriv_anno] norm_eq\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P normalize c Q,A\"\n    by simp\n  from NormalizeD [OF this]\n  show ?thesis .\nqed\n\nlemma annotateWhile:\n\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnnoG gs b I V c) Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (while gs b c) Q,A\"\n  by (simp add: whileAnnoG_def)\n\n\nlemma reannotateWhile:\n\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnnoG gs b I V c) Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnnoG gs b J V c) Q,A\"\n  by (simp add: whileAnnoG_def)\n\nlemma reannotateWhileNoGuard:\n\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnno b I V c) Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnno b J V c) Q,A\"\n  by (simp add: whileAnno_def)\n\nlemma [trans] : \"P' \\<subseteq> P \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' c Q,A\"\n  by (rule conseqPre)\n \nlemma [trans]: \"Q \\<subseteq> Q' \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q',A\"\n  by (rule conseqPost) blast+\n\nlemma [trans]:\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s} c Q,A \\<Longrightarrow> (\\<And>s. P' s \\<longrightarrow> P s) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P' s} c Q,A\"\n  by (rule conseqPre) auto\n\nlemma [trans]:\n    \"(\\<And>s. P' s \\<longrightarrow> P s) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s} c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P' s} c Q,A\"\n  by (rule conseqPre) auto\n\nlemma [trans]:\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P c {s. Q s},A \\<Longrightarrow> (\\<And>s. Q s \\<longrightarrow> Q' s) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P c {s. Q' s},A\"\n  by (rule conseqPost) auto\n\nlemma [trans]:\n    \"(\\<And>s. Q s \\<longrightarrow> Q' s) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P c {s. Q s},A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P c {s. Q' s},A\"\n  by (rule conseqPost) auto\n\nlemma [intro?]: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Skip P,A\"\n  by (rule Skip) auto\n\nlemma CondInt [trans,intro?]:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> b) c1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> - b) c2 Q,A\\<rbrakk>\n   \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c1 c2) Q,A\"\n  by (rule Cond) auto\n \nlemma CondConj [trans, intro?]:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s \\<and> b s} c1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s \\<and> \\<not> b s} c2 Q,A\\<rbrakk>\n   \\<Longrightarrow> \n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s} (Cond {s. b s} c1 c2) Q,A\"\n  by (rule Cond) auto\n \nlemma WhileInvInt [intro?]:\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> b) c P,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnno b P V c) (P \\<inter> -b),A\"\n  by (rule While) auto\n\nlemma WhileInt [intro?]:\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> b) c P,A \n    \\<Longrightarrow> \n    \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnno b {s. undefined} V c) (P \\<inter> -b),A\"\n  by (unfold whileAnno_def) \n     (rule HoarePartialDef.While [THEN conseqPrePost],auto)\n\nlemma WhileInvConj [intro?]:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s \\<and> b s} c {s. P s},A\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s} (whileAnno {s. b s} {s. P s} V c) {s. P s \\<and> \\<not> b s},A\"\n  by (simp add: While Collect_conj_eq Collect_neg_eq)\n\nlemma WhileConj [intro?]:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s \\<and> b s} c {s. P s},A\n    \\<Longrightarrow> \n\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s} (whileAnno {s. b s} {s. undefined} V c) {s. P s \\<and> \\<not> b s},A\"\n  by (unfold whileAnno_def) \n     (simp add: HoarePartialDef.While [THEN conseqPrePost] \n      Collect_conj_eq Collect_neg_eq)\n\n(* FIXME: Add rules for guarded while *)\n\nend", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Simpl/HoarePartial.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926665999540697, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.27783654677291364}}
{"text": "theory SINVAR_DomainHierarchyNG_impl\nimports SINVAR_DomainHierarchyNG \"../TopoS_Interface_impl\"\nbegin\n\n\nsubsubsection {* SecurityInvariant DomainHierarchy List Implementation *}\n\ncode_identifier code_module SINVAR_DomainHierarchyNG_impl => (Scala) SINVAR_DomainHierarchyNG\n\nfun sinvar :: \"'v list_graph \\<Rightarrow> ('v \\<Rightarrow> domainNameTrust) \\<Rightarrow> bool\" where\n  \"sinvar G nP = (\\<forall> (s, r) \\<in> set (edgesL G). (nP r) \\<sqsubseteq>\\<^sub>t\\<^sub>r\\<^sub>u\\<^sub>s\\<^sub>t (nP s))\"\n\n\ndefinition DomainHierarchyNG_sanity_check_config :: \"domainNameTrust list \\<Rightarrow> domainTree \\<Rightarrow> bool\" where\n  \"DomainHierarchyNG_sanity_check_config host_attributes tree = (\\<forall> c \\<in> set host_attributes.\n    case c of Unassigned \\<Rightarrow> True\n            | DN (level, trust) \\<Rightarrow> valid_hierarchy_pos tree level\n   )\"\n\nfun verify_globals :: \"'v list_graph \\<Rightarrow> ('v \\<Rightarrow> domainNameTrust) \\<Rightarrow> domainTree \\<Rightarrow> bool\" where\n  \"verify_globals G nP tree = (\\<forall> v \\<in> set (nodesL G). \n    case (nP v) of Unassigned \\<Rightarrow> True | DN (level, trust) \\<Rightarrow> valid_hierarchy_pos tree level\n   )\"\n\n(*TODO: to get rid of verify_globals\n  this stronger DomainHierarchyNG_sanity_check_config sanity checker checks the config\n  for all graphs!*)\nlemma \"DomainHierarchyNG_sanity_check_config c tree \\<Longrightarrow>\n    {x. \\<exists>v. nP v = x} = set c \\<Longrightarrow>\n    verify_globals G nP tree\"\n  apply(simp add: DomainHierarchyNG_sanity_check_config_def split: if_split_asm)\n  apply(clarify)\n  apply(case_tac \"nP v\")\n   apply(simp_all)\n  apply(clarify)\n  by force\n\n\ndefinition DomainHierarchyNG_offending_list:: \"'v list_graph \\<Rightarrow> ('v \\<Rightarrow> domainNameTrust) \\<Rightarrow> ('v \\<times> 'v) list list\" where\n  \"DomainHierarchyNG_offending_list G nP = (if sinvar G nP then\n    []\n   else \n    [ [e \\<leftarrow> edgesL G. case e of (s,r) \\<Rightarrow> \\<not> (nP r) \\<sqsubseteq>\\<^sub>t\\<^sub>r\\<^sub>u\\<^sub>s\\<^sub>t (nP s) ] ])\"\n\n\n\nlemma \"DomainHierarchyNG.node_props P = \n  (\\<lambda>i. case node_properties P i of None \\<Rightarrow> SINVAR_DomainHierarchyNG.default_node_properties | Some property \\<Rightarrow> property)\"\nby(fact SecurityInvariant.node_props.simps[OF TopoS_DomainHierarchyNG, of \"P\"])\n\ndefinition \"NetModel_node_props P = (\\<lambda> i. (case (node_properties P) i of Some property \\<Rightarrow> property | None \\<Rightarrow> SINVAR_DomainHierarchyNG.default_node_properties))\"\n(*\n\n(*TODO does this work?*)\nlemma[code_unfold]: \"DomainHierarchyNG.node_props P = NetModel_node_props P\"\nby(simp add: NetModel_node_props_def)\n\ndefinition \"DomainHierarchyNG_eval G P = (wf_list_graph G \\<and>\n  sinvar G (SecurityInvariant.node_props SINVAR_DomainHierarchyNG.default_node_properties P))\"\n\n\ninterpretation DomainHierarchyNG_impl:TopoS_List_Impl \n  where default_node_properties=SINVAR_DomainHierarchyNG.default_node_properties\n  and sinvar_spec=SINVAR_DomainHierarchyNG.sinvar\n  and sinvar_impl=sinvar\n  and receiver_violation=SINVAR_DomainHierarchyNG.receiver_violation\n  and offending_flows_impl=DomainHierarchyNG_offending_list\n  and node_props_impl=NetModel_node_props\n  and eval_impl=DomainHierarchyNG_eval\n apply(unfold TopoS_List_Impl_def)\n apply(rule conjI)\n  apply(simp add: TopoS_DomainHierarchyNG list_graph_to_graph_def; fail)\n apply(rule conjI)\n  apply(simp add: list_graph_to_graph_def DomainHierarchyNG_offending_set\n        DomainHierarchyNG_offending_set_def DomainHierarchyNG_offending_list_def; fail)\n apply(rule conjI)\n  apply(simp only: NetModel_node_props_def)\n  apply(metis DomainHierarchyNG.node_props.simps DomainHierarchyNG.node_props_eq_node_props_formaldef)\n apply(simp only: DomainHierarchyNG_eval_def)\n apply(intro allI)\n apply(rule TopoS_eval_impl_proofrule[OF TopoS_DomainHierarchyNG])\n apply(simp add: list_graph_to_graph_def)\ndone\n\n\nsubsubsection {* DomainHierarchyNG packing *}\n  definition SINVAR_LIB_DomainHierarchyNG :: \"('v::vertex, domainNameTrust) TopoS_packed\" where\n    \"SINVAR_LIB_DomainHierarchyNG \\<equiv> \n    \\<lparr> nm_name = ''DomainHierarchyNG'', \n      nm_receiver_violation = SINVAR_DomainHierarchyNG.receiver_violation,\n      nm_default = SINVAR_DomainHierarchyNG.default_node_properties, \n      nm_sinvar = sinvar,\n      nm_offending_flows = DomainHierarchyNG_offending_list, \n      nm_node_props = NetModel_node_props,\n      nm_eval = DomainHierarchyNG_eval\n      \\<rparr>\"\n  interpretation SINVAR_LIB_DomainHierarchyNG_interpretation: TopoS_modelLibrary SINVAR_LIB_DomainHierarchyNG \n      SINVAR_DomainHierarchyNG.sinvar\n    apply(unfold TopoS_modelLibrary_def SINVAR_LIB_DomainHierarchyNG_def)\n    apply(rule conjI)\n     apply(simp)\n    apply(simp)\n    by(unfold_locales)\n\n\n\n\n\n\ntext {*Examples:*}\ndefinition example_TUM_net :: \"string list_graph\" where\n  \"example_TUM_net \\<equiv> \\<lparr> nodesL=[''Gateway'', ''LowerSVR'', ''UpperSRV''], \n        edgesL=[\n          (''Gateway'',''LowerSVR''), (''Gateway'',''UpperSRV''), \n          (''LowerSVR'', ''Gateway''),\n          (''UpperSRV'', ''Gateway'')\n        ] \\<rparr>\"\nvalue \"wf_list_graph example_TUM_net\"\n\ndefinition example_TUM_config :: \"string \\<Rightarrow> domainNameTrust\" where\n  \"example_TUM_config \\<equiv> ((\\<lambda> e. default_node_properties)\n        (''Gateway'':= DN (''ACD''--''AISD''--Leaf, 1),\n         ''LowerSVR'':= DN (''ACD''--''AISD''--Leaf, 0),\n         ''UpperSRV'':= DN (''ACD''--Leaf, 0)\n       ))\"\n\ndefinition example_TUM_hierarchy :: \"domainTree\" where\n\"example_TUM_hierarchy \\<equiv> (Department ''ACD'' [\n           Department ''AISD'' []\n       ])\"\n\nvalue \"verify_globals example_TUM_net example_TUM_config example_TUM_hierarchy\"\nvalue \"sinvar     example_TUM_net example_TUM_config\"\n\ndefinition example_TUM_net_invalid where\n\"example_TUM_net_invalid \\<equiv> example_TUM_net\\<lparr>edgesL :=  \n    (''LowerSRV'', ''UpperSRV'')#(edgesL example_TUM_net)\\<rparr>\"\n\nvalue \"verify_globals example_TUM_net_invalid example_TUM_config example_TUM_hierarchy\"\nvalue \"sinvar     example_TUM_net_invalid example_TUM_config\"\nvalue \"DomainHierarchyNG_offending_list example_TUM_net_invalid example_TUM_config\"\n\n\nhide_const (open) NetModel_node_props\n\nhide_const (open) sinvar \n\nend\n", "meta": {"author": "diekmann", "repo": "topoS", "sha": "4303ebd95a501283c02fd513c109e645a48ad080", "save_path": "github-repos/isabelle/diekmann-topoS", "path": "github-repos/isabelle/diekmann-topoS/topoS-4303ebd95a501283c02fd513c109e645a48ad080/thy/Network_Security_Policy_Verification/Security_Invariants/SINVAR_DomainHierarchyNG_impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6757646010190476, "lm_q2_score": 0.411110869232168, "lm_q1q2_score": 0.27781417252126983}}
{"text": "(*  Title:      HOL/Library/Rewrite.thy\n    Author:     Christoph Traut, Lars Noschinski, TU Muenchen\n\nProof method \"rewrite\" with support for subterm-selection based on patterns.\n*)\n\ntheory Rewrite\nimports Main\nbegin\n\nconsts rewrite_HOLE :: \"'a::{}\"  (\"\\<hole>\")\n\nlemma eta_expand:\n  fixes f :: \"'a::{} \\<Rightarrow> 'b::{}\"\n  shows \"f \\<equiv> \\<lambda>x. f x\" .\n\nlemma rewr_imp:\n  assumes \"PROP A \\<equiv> PROP B\"\n  shows \"(PROP A \\<Longrightarrow> PROP C) \\<equiv> (PROP B \\<Longrightarrow> PROP C)\"\n  apply (rule Pure.equal_intr_rule)\n  apply (drule equal_elim_rule2[OF assms]; assumption)\n  apply (drule equal_elim_rule1[OF assms]; assumption)\n  done\n\nlemma imp_cong_eq:\n  \"(PROP A \\<Longrightarrow> (PROP B \\<Longrightarrow> PROP C) \\<equiv> (PROP B' \\<Longrightarrow> PROP C')) \\<equiv>\n    ((PROP B \\<Longrightarrow> PROP A \\<Longrightarrow> PROP C) \\<equiv> (PROP B' \\<Longrightarrow> PROP A \\<Longrightarrow> PROP C'))\"\n  apply (intro Pure.equal_intr_rule)\n     apply (drule (1) cut_rl; drule Pure.equal_elim_rule1 Pure.equal_elim_rule2; assumption)+\n   apply (drule Pure.equal_elim_rule1 Pure.equal_elim_rule2; assumption)+\n  done\n\nML_file \"cconv.ML\"\nML_file \"rewrite.ML\"\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/HOL/Library/Rewrite.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.2777921560835902}}
{"text": "(*  Author:      Lukas Bulwahn, TU Muenchen, 2009  *)\n\ntheory Execute\nimports FJSound\nbegin\n\nsection {* Executing FeatherweightJava programs *}\ntext {* We execute FeatherweightJava programs using the predicate compiler. *}\n\ncode_pred (modes: i => i => i => bool,\n  i => i => o => bool as supertypes_of) subtyping .\n\nthm subtyping.equation\n\ntext {* The reduction relation requires that we inverse the @{term List.append} function.\nTherefore, we define a new predicate append and derive introduction rules. *}\n\ndefinition append where \"append xs ys zs = (zs = xs @ ys)\"\n\nlemma [code_pred_intro]: \"append [] xs xs\"\nunfolding append_def by simp\n\nlemma [code_pred_intro]: \"append xs ys zs \\<Longrightarrow> append (x#xs) ys (x#zs)\"\nunfolding append_def by simp\n\ntext {* With this at hand, we derive new introduction rules for the reduction relation: *}\n\nlemma rc_invk_arg': \"CT \\<turnstile> ei \\<rightarrow> ei' \\<Longrightarrow> append el (ei # er) e' \\<Longrightarrow> append el (ei' # er) e'' \\<Longrightarrow>\nCT \\<turnstile> MethodInvk e m e' \\<rightarrow> MethodInvk e m e''\"\nunfolding append_def by simp (rule reduction.intros(6))\n\nlemma rc_new_arg': \"CT \\<turnstile> ei \\<rightarrow> ei' \\<Longrightarrow> append el (ei # er) e \\<Longrightarrow> append el (ei' # er) e'\n   ==> CT \\<turnstile> New C e \\<rightarrow> New C e'\"\nunfolding append_def by simp (rule reduction.intros(7))\n\nlemmas [code_pred_intro] = reduction.intros(1-5)\n  rc_invk_arg' rc_new_arg' reduction.intros(8)\n\ncode_pred (modes: i => i => i => bool, i => i => o => bool as reduce) reduction\nproof -\n  case append\n  from this show thesis\n    unfolding append_def by (cases xa) fastforce+\nnext\n  case reduction\n  from reduction.prems show thesis\n  proof (cases rule: reduction.cases)\n    case r_field\n    with reduction(1) show thesis by fastforce\n  next\n    case r_invk\n    with reduction(2) show thesis by fastforce\n  next\n    case r_cast\n    with reduction(3) show thesis by fastforce\n  next\n    case rc_field\n    with reduction(4) show thesis by fastforce\n  next\n    case rc_invk_recv\n    with reduction(5) show thesis by fastforce\n  next\n    case rc_invk_arg\n    with reduction(6) show thesis\n      unfolding append_def by fastforce\n  next\n    case rc_new_arg\n    with reduction(7) show thesis\n      unfolding append_def by fastforce\n  next\n    case rc_cast\n    with reduction(8) show thesis by fastforce\n  qed\nqed\n\nthm reduction.equation\n\ncode_pred reductions .\n\nthm reductions.equation\n\ntext {* We also make the class typing executable: this requires that\n  we derive rules for @{term \"method_typing\"}. *}\n\ndefinition method_typing_aux\nwhere\n  \"method_typing_aux CT m D Cs C = (\\<not> (\\<forall>Ds D0. mtype(CT,m,D) = Ds \\<rightarrow> D0 \\<longrightarrow> Cs = Ds \\<and> C = D0))\"\n\nlemma method_typing_aux:\n  \"(\\<forall>Ds D0. mtype(CT,m,D) = Ds \\<rightarrow> D0 \\<longrightarrow> Cs = Ds \\<and> C = D0) = (\\<not> method_typing_aux CT m D Cs C)\"\nunfolding method_typing_aux_def by auto\n\nlemma [code_pred_intro]:\n  \"mtype(CT,m,D) = Ds \\<rightarrow> D0 \\<Longrightarrow> Cs \\<noteq> Ds \\<Longrightarrow> method_typing_aux CT m D Cs C\"\nunfolding method_typing_aux_def by auto\n\nlemma [code_pred_intro]:\n  \"mtype(CT,m,D) = Ds \\<rightarrow> D0 \\<Longrightarrow> C \\<noteq> D0 \\<Longrightarrow> method_typing_aux CT m D Cs C\"\nunfolding method_typing_aux_def by auto\n\ndeclare method_typing.intros[unfolded method_typing_aux, code_pred_intro]\n\ndeclare class_typing.intros[unfolded append_def[symmetric], code_pred_intro]\n\ncode_pred (modes: i => i => bool) class_typing\nproof -\n  case class_typing\n  from class_typing.cases[OF class_typing.prems, of thesis] this(1) show thesis\n    unfolding append_def by fastforce\nnext\n  case method_typing\n  from method_typing.cases[OF method_typing.prems, of thesis] this(1) show thesis\n    unfolding append_def method_typing_aux_def by fastforce\nnext\n  case method_typing_aux\n  from this show thesis\n    unfolding method_typing_aux_def by auto\nqed\n\nsubsection {* A simple example *}\n\ntext {* We now execute a simple FJ example program: *}\n\nabbreviation A :: className\nwhere \"A == Suc 0\"\n\nabbreviation B :: className\nwhere \"B == 2\"\n\nabbreviation cPair :: className\nwhere \"cPair == 3\"\n\ndefinition classA_Def :: classDef\nwhere\n  \"classA_Def = \\<lparr> cName = A, cSuper = Object, cFields = [], cConstructor = \\<lparr>kName = A, kParams = [], kSuper = [], kInits = []\\<rparr>, cMethods = []\\<rparr>\"\n\ndefinition\n  \"classB_Def = \\<lparr> cName = B, cSuper = Object, cFields = [], cConstructor = \\<lparr>kName = B, kParams = [], kSuper = [], kInits = []\\<rparr>, cMethods = []\\<rparr>\"\n\nabbreviation ffst :: varName\nwhere\n  \"ffst == 4\"\n\nabbreviation fsnd :: varName\nwhere\n  \"fsnd == 5\"\n\nabbreviation setfst :: methodName\nwhere\n  \"setfst == 6\"\n\nabbreviation newfst :: varName\nwhere\n  \"newfst == 7\"\n\ndefinition classPair_Def :: classDef\nwhere\n  \"classPair_Def = \\<lparr> cName = cPair, cSuper = Object,\n    cFields = [\\<lparr> vdName = ffst, vdType = Object \\<rparr>, \\<lparr> vdName = fsnd, vdType = Object \\<rparr>],\n    cConstructor = \\<lparr> kName = cPair, kParams = [\\<lparr> vdName = ffst, vdType = Object \\<rparr>, \\<lparr> vdName = fsnd, vdType = Object \\<rparr>], kSuper = [], kInits = [ffst, fsnd]\\<rparr> ,\n    cMethods = [\\<lparr> mReturn = cPair, mName = setfst, mParams = [\\<lparr>vdName = newfst, vdType = Object \\<rparr>],\n      mBody = New cPair [Var newfst, FieldProj (Var this) fsnd]  \\<rparr>]\\<rparr>\"\n\ndefinition exampleProg :: classTable\n  where \"exampleProg = (((%x. None)(A := Some classA_Def))(B := Some classB_Def))(cPair := Some classPair_Def)\"\n\n\nvalue \"exampleProg \\<turnstile> classA_Def OK\"\nvalue \"exampleProg \\<turnstile> classB_Def OK\"\nvalue \"exampleProg \\<turnstile> classPair_Def OK\"\n\n\nvalues \"{x. exampleProg \\<turnstile> MethodInvk (New cPair [New A [], New B []]) setfst [New B []] \\<rightarrow>* x}\"\nvalues \"{x. exampleProg \\<turnstile> FieldProj (FieldProj (New cPair [New cPair [New A [], New B []], New A []]) ffst) fsnd \\<rightarrow>* x}\"\n\n\nend", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/FeatherweightJava/Execute.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.2777921560835902}}
{"text": "(* This file requires:\n\n - An Isabelle Snapshot from no earlier than October 5, 2007\n\n*)\n\n(*\n   This contains occurence typing with:\n   - variables as tests\n   - eta-expansion\n*)\n\ntheory TypedSchemePreOr\nimports Nominal\n\nbegin\n\nML {*ResAtp.set_prover \"vampire\"*}\n(* ML {* ThmDeps.enable() *} *) \n\n\n(* datatype definitions *)\natom_decl name\n\n\ndatatype ty =\n    Top | Int | TT | FF | Arr \"ty\" \"ty\" \"latent_eff\" (\"_ \\<rightarrow> _ : _\" [100,100] 100) | Union \"ty list\"  \nand latent_eff = NE | Latent ty\n\nconstdefs\n\"BoolTy == Union [TT , FF]\"\n\nprimrec (unchecked perm_ty)\n \"pi\\<bullet>(ty.Top) = ty.Top\"\n \"pi\\<bullet>(ty.Int) = ty.Int\"\n \"pi\\<bullet>(TT) = TT\"\n \"pi\\<bullet>(FF) = FF\"\n \"pi\\<bullet>(\\<tau> \\<rightarrow> \\<sigma> : L) = ((pi\\<bullet>\\<tau>) \\<rightarrow> (pi\\<bullet>\\<sigma>) : (pi\\<bullet>L))\"\n \"pi\\<bullet>(Union l) = Union (pi\\<bullet>l)\" \n \"pi\\<bullet>latent_eff.NE = latent_eff.NE\"\n \"pi\\<bullet>(Latent S) = Latent (pi\\<bullet>S)\"\n\ndeclare perm_ty.simps[eqvt]\n\nlemma perm_ty_latent_eff_ty_list[simp]:\n  fixes pi ::\"name prm\"\n  and   \\<tau>  ::\"ty\"\n  and   Ts ::\"ty list\"\n  and   l  ::\"latent_eff\"\n  shows \"pi\\<bullet>\\<tau> = \\<tau>\" and \"pi\\<bullet>l = l\" and \"pi\\<bullet>Ts = Ts\"\n  by (induct \\<tau> and l rule: ty_latent_eff.inducts) auto\n\ninstance ty :: pt_name\nby intro_classes auto\n\ninstance ty :: fs_name\nby intro_classes (simp add: supp_def)\n\ninstance latent_eff :: pt_name\nby intro_classes auto\n\ninstance latent_eff :: fs_name\nby intro_classes (simp add: supp_def)\n\nfun\n  size_ty :: \"ty \\<Rightarrow> nat\" and\n  size_le :: \"latent_eff \\<Rightarrow> nat\" \nwhere \n  \"size_ty (ty.Int) = 1\"\n| \"size_ty (TT) = 1\"\n| \"size_ty (FF) = 1\"\n| \"size_ty (Top) = 1\"\n| \"size_ty (Union []) = 1\"\n| \"size_ty (Union (t#ts)) = size_ty t + size_ty (Union ts)\"\n| \"size_ty (T1 \\<rightarrow> T2 : L) = (size_ty T1) + (size_ty T2) + (size_le L)\"\n| \"size_le (Latent L) = size_ty L\"\n| \"size_le (latent_eff.NE) = 1\"\n\nlemma size_ty_pos:\n  \"size_ty T > 0\"\nproof (induct T )\n  fix l\n  show \"0 < size_ty (Union l)\" by (induct l) auto\nqed (auto)\n\nnominal_datatype eff = NE | TE \"ty\" \"name\" | VE \"name\" | TT | FF\n\nnominal_datatype builtin = Add1 | NumberP | BooleanP | Nott | ProcP\n\nnominal_datatype trm = \n    Var \"name\"\n  | App \"trm\" \"trm\"\n  | Abs \"\\<guillemotleft>name\\<guillemotright>trm\" \"ty\"\n  | Iff \"trm\" \"trm\" \"trm\"\n  | Num \"nat\"\n  | Bool \"bool\"\n  | BI \"builtin\"\n\nabbreviation\n  \"lam\" :: \"name \\<Rightarrow> ty \\<Rightarrow> trm \\<Rightarrow> trm\" (\"Lam [_:_]._\" [100,100,100] 100) where\n  \"Lam[x:T].b \\<equiv> trm.Abs x b T\"\n\n(* lemmas about names, types, effects *)\n\nlemma trm_finite_supp:\n  fixes x::\"trm\"\n  shows \"finite ((supp x)::name set)\"\n  using fs_name_class.axioms[of x] by simp\n\nlemma pt_trm_inst: \"pt TYPE(trm) TYPE(name)\" using pt_name_inst by auto\n\nlemma fs_trm_inst: \"fs TYPE(trm) TYPE(name)\" using fs_name_inst by auto\n\nlemma perm_ty_latent[simp]: \n  fixes T::\"ty\"\n  and   le::\"latent_eff\"\n  and   pi::\"name prm\"\n  shows \"pi\\<bullet>le = le \\<and> pi\\<bullet>T = T\"\n  by simp\n\nlemma perm_ty: \n  fixes T::\"ty\"\n  and   le::\"latent_eff\"\n  and   pi::\"name prm\"\n  shows \"pi\\<bullet>T = T\"\n  by simp\n\nlemma perm_builtin[simp]: \n  fixes e::\"builtin\"\n  and   pi::\"name prm\"\n  shows \"pi\\<bullet>e = e\"\n  by (induct rule: builtin.weak_induct) (simp_all)\n\nlemma fresh_ty[simp]:\n  fixes x::\"name\" \n  and   T::\"ty\"\n  shows \"x\\<sharp>T\"\n  by (simp add: fresh_def supp_def)\n\nlemma fresh_latent_eff[simp]:\n  fixes x::\"name\" \n  and   T::\"latent_eff\"\n  shows \"x\\<sharp>T\"\n  by (simp add: fresh_def supp_def)\n\nlemma fresh_builtin[simp]:\n  fixes x::\"name\" \n  and   b::\"builtin\"\n  shows \"x\\<sharp>b\"\n  by (simp add: fresh_def supp_def)\n\nlemma supp_latent_eff_ty:\n  fixes T::ty and le::latent_eff\n  shows \" supp le = ({}::name set)  \\<and> supp T = ({}::name set)\"\n  by (simp add: supp_def)\n\ntext {* size of a term *}\n\ninstance trm :: size ..\n\nnominal_primrec\n  \"size (Var x) = 1\"\n  \"size (BI b) = 1\"\n  \"size (Bool b) = 1\"\n  \"size (Num b) = 1\"\n  \"size (App t1 t2) = (max (size t1) (size t2)) + 1\"\n  \"size (Iff t1 t2 t3) = (max (size t1) (max (size t2) (size t3))) + 1\"\n  \"size (Lam [a:T].t) = (size t) + 1\"\n  by (auto simp add: fresh_nat, finite_guess+, fresh_guess+)\n\nabbreviation\n  \"smaller_than_abb\" :: \"trm \\<Rightarrow> trm \\<Rightarrow> bool\" (\"_ \\<guillemotleft> _\" [80,80] 80)\nwhere \n  \"a \\<guillemotleft> b == size a < size b\"\n\ntext {* complete induction on terms *}\n\nlemma trm_comp_induct[consumes 0, case_names Var App Lam BI Num Bool Iff]:\n  fixes P::\"'a::fs_name \\<Rightarrow> trm \\<Rightarrow> bool\"\n  and t::\"trm\"\n  and x::\"'a::fs_name\"\n  assumes a1:\"!! n z. (!! x t. (t \\<guillemotleft> Var n) \\<Longrightarrow> P x t) \\<Longrightarrow> P z (Var n)\"\n  and a2:\"!! t1 t2 z. (!! x t. (t \\<guillemotleft> App t1 t2) \\<Longrightarrow> P x t) \\<Longrightarrow> (!! x. P x t1) \\<Longrightarrow> (!! x . P x t2)\n  \\<Longrightarrow> P z (App t1 t2)\"\n  and a3:\"!! a b z T. \\<lbrakk>a \\<sharp> z ; (!! x t. (t \\<guillemotleft> Lam[a:T].b)  \\<Longrightarrow> P x t)\\<rbrakk> \\<Longrightarrow> (!! x . P x b) \\<Longrightarrow> P z (Lam[a:T].b)\"\n  and a4:\"!! b z. (!! x t. (t \\<guillemotleft> BI b) \\<Longrightarrow> P x t) \\<Longrightarrow> P z (BI b)\"\n  and a5:\"!! n z. (!! x t. (t \\<guillemotleft> Num n)  \\<Longrightarrow> P x t) \\<Longrightarrow> P z (Num n)\"\n  and a6:\"!! b z. (!! x t. (t \\<guillemotleft> Bool b) \\<Longrightarrow> P x t) \\<Longrightarrow> P z (Bool b)\"\n  and a7:\"!! t1 t2 t3 z. (!! x t. t \\<guillemotleft> (Iff t1 t2 t3) \\<Longrightarrow> P x t) \n  \\<Longrightarrow> (!! x. P x t1) \\<Longrightarrow> (!! x . P x t2) \\<Longrightarrow> (!! x. P x t3) \\<Longrightarrow> P z (Iff t1 t2 t3)\"\n  shows \"P x t\"\nproof (induct t arbitrary: x taking:\"(% t :: trm. size t)\" rule: measure_induct_rule)\n  case (less s x) thus ?case\n    -- \"This would go through automatically, but I'm skeptical of that sort of thing\"\n  proof (nominal_induct s avoiding: x rule: trm.induct)\n    case (Var v) thus ?case using a1 by auto\n  next\n    case (App t1 t2) thus ?case using a2 by auto\n  next\n    case (Abs a b T) thus ?case using a3 by auto\n  next\n    case (Iff t1 t2 t3) thus ?case using a7 by auto\n  next\n    case (BI b) thus ?case using a4 by auto\n  next\n    case (Num n) thus ?case using a5 by auto\n  next\n    case (Bool b) thus ?case using a6 by auto    \n  qed\nqed  \n\n\ntext {* closed terms *}\n\nconstdefs\nfv :: \"trm \\<Rightarrow> name set\"\nfv_def[simp]:\"fv e == ((supp e):: name set)\"\n\nconstdefs\n  closed :: \"trm \\<Rightarrow> bool\"\n  closed_def: \"closed e == (fv e = {})\"\n\n\nlemma closed_lam: --\"A statement about the free variables of lam bodies\"\n  assumes \"closed (Lam[x:T].b)\" (is \"closed ?e\")\n  shows \"fv b <= {x}\"\n  proof -\n    have \"(supp ([x].b)::name set) = supp b - {x}\" \n      using fs_name_class.axioms abs_fun_supp[of b x] pt_trm_inst at_name_inst by auto\n    hence \"supp ?e = ((((supp b):: name set) - {x}) :: name set)\" using supp_latent_eff_ty trm.supp by simp\n    thus ?thesis using prems closed_def by auto \n  qed\n\nlemma closed_eqvt[eqvt]:\n  fixes pi::\"name prm\"\n  shows \"closed e \\<Longrightarrow> closed (pi\\<bullet>e)\"\nproof -\n  have A:\"(pi\\<bullet>fv e) = fv (pi\\<bullet>e)\" using pt_perm_supp[of pi e] at_name_inst pt_trm_inst by auto\n  assume \"closed e\"\n  hence \"fv e = {}\" using closed_def by simp\n  hence \"(pi\\<bullet>fv e) = {}\" using empty_eqvt[of pi] by auto\n  hence \"closed (pi\\<bullet>e)\" using A closed_def by auto\n  thus ?thesis .\nqed    \n\n\ntext {* capture-avoiding substitution *}\n\nconsts subst :: \"trm \\<Rightarrow> name \\<Rightarrow> trm \\<Rightarrow> trm\" (\"_[_::=_]\" [100,100,100] 100)\n\nnominal_primrec\n \"(Var x)[y::=t'] = (if x=y then t' else (Var x))\"\n \"(App t1 t2)[y::=t'] = App (t1[y::=t']) (t2[y::=t'])\"\n \"x\\<sharp>(y,t',T) \\<Longrightarrow> (Lam[x:T].t)[y::=t'] = Lam[x:T].(t[y::=t'])\"\n \"(Iff tst thn els)[y::=t'] = (Iff (tst[y::=t']) (thn[y::=t']) (els[y::=t']))\"\n \"(BI c)[y::=t'] = (BI c)\"\n \"(Num c)[y::=t'] = (Num c)\"\n \"(Bool c)[y::=t'] = (Bool c)\"\n  by (finite_guess+, auto simp add: abs_fresh, fresh_guess+)\n\nlemma subst_eqvt[simp, eqvt]:\n  fixes pi:: \"name prm\"\n  and   t1:: \"trm\"\n  and   t2:: \"trm\"\n  and   a :: \"name\"\n  shows \"pi\\<bullet>(t1[b::=t2]) = (pi\\<bullet>t1)[(pi\\<bullet>b)::=(pi\\<bullet>t2)]\"\nby (nominal_induct t1 avoiding: b t2 rule: trm.induct)\n   (auto simp add: perm_bij fresh_prod fresh_atm fresh_bij)\n\nlemma subst_rename[rule_format]: \n  shows \"c\\<sharp>t1 \\<longrightarrow> (t1[a::=t2] = ([(c,a)]\\<bullet>t1)[c::=t2])\"\nby (nominal_induct t1 avoiding: a c t2 rule: trm.induct)\n   (auto simp add: calc_atm fresh_atm abs_fresh fresh_nat trm.inject perm_nat_def perm_bool)\n\n\nlemma forget: \n  assumes a: \"a\\<sharp>t1\"\n  shows \"t1[a::=t2] = t1\"\n  using a\nby (nominal_induct t1 avoiding: a t2 rule: trm.induct)\n   (auto simp add: abs_fresh fresh_atm)\n\n\nlemma subst_removes_var:\n  assumes \"e1[x::=e0] = e2\" and \"x \\<sharp> e0\"\n  shows \"x \\<sharp> e2\"\n  using prems\nproof (nominal_induct e1 avoiding: e0 x e2 rule: trm.induct)\n  case (Var v e0' x' e2')\n  thus ?case using at_fresh[of x' v] at_name_inst\n    by (cases \"x' = v\") auto\nnext\n  case App thus ?case by auto\nnext\n  case Iff thus ?case by auto\nnext\n  case BI thus ?case by auto\nnext\n  case Num thus ?case by (auto simp add: fresh_nat)\nnext\n  case (Bool b) thus ?case \n    by (auto simp add: fresh_def supp_bool trm.supp)\nnext\n  case (Abs v e1' T e0' x' e2')\n  let ?body = \"(e1'[x'::=e0'])\"\n  have a:\"finite ((supp ?body) :: name set)\" using fs_name1 by auto\n  have f:\"x' \\<sharp> (e1'[x'::=e0'])\" using Abs by auto\n  hence \"v \\<sharp> (x',e0',T)\" using Abs by auto\n  hence \"(Abs v e1' T)[x'::=e0'] = Abs v (e1'[x'::=e0']) T\" by auto\n  hence \"\\<dots> = e2'\" using Abs by auto\n  have \"v \\<noteq> x'\" using `v \\<sharp> x'` at_fresh[of v x'] at_name_inst by auto\n  hence \"x' \\<sharp> v\" using  at_fresh[of x' v] at_name_inst by auto\n  have \"x' \\<sharp> T\" using fresh_def supp_latent_eff_ty by auto\n  have \"x' \\<sharp> [v].(e1'[x'::=e0'])\" using `v ~= x'` fresh_abs_funI1[of ?body x' v ] pt_trm_inst at_name_inst a f by auto\n  hence \"x' \\<sharp>  Abs v (e1'[x'::=e0']) T\" using f trm.fresh Abs by auto\n  thus ?case using Abs  by auto\nqed\n \n\nlemma fv_lam:\n  fixes name\n  shows \"fv (Lam[name:T].body) =  fv body - {name}\"\nproof -\n  have sT:\"supp T = ({} :: name set)\" using supp_latent_eff_ty by auto\n  have \"fv (Lam[name:T].body) = (supp ([name].body):: name set) \\<union> supp T\" using trm.supp by auto\n  also have \"\\<dots> = (supp ([name].body):: name set)\" using sT by auto\n  also have \"\\<dots> = supp body - ({name} :: name set)\" \n    using  abs_fun_supp[of body name] at_name_inst pt_trm_inst fs_name1[of body] by simp\n  also have \"\\<dots> = fv body - {name}\" by simp\n  finally show \"fv (Lam[name:T].body) = fv body - {name}\" by simp\nqed\n\nlemma subst_closed:\n  assumes \"e1[x::=e0] = e2\" and \"closed e0\"\n  shows \"fv e2 <= fv e1\"\n  using prems\nproof (nominal_induct e1 avoiding: e0 x e2 rule: trm.induct)\n  case (Var v e0' x' e2')\n  thus ?case using at_fresh[of x' v] at_name_inst closed_def\n    by (cases \"x' = v\") auto\nnext\n  case (App rator rand e0' x' e2')\n  let ?subrator = \"rator[x'::=e0']\"\n  let ?subrand = \"rand[x'::=e0']\"\n  have a:\"e2' = App ?subrator ?subrand\" using App by simp\n  have s1:\"fv ?subrator <= fv rator\" using App by simp\n  have s2:\"fv ?subrand <= fv rand\" using App by simp\n  have b:\"fv e2' = fv ?subrator \\<union> fv ?subrand\" using trm.supp App a by simp\n  have d:\"fv (App rator rand) = fv rator  \\<union> fv rand\" using trm.supp by simp\n  show ?case using d s1 s2 b by auto\nnext\n  case BI thus ?case by auto\nnext\n  case Num thus ?case by (auto simp add: fresh_nat)\nnext\n  case (Bool b) thus ?case \n    by (auto simp add: fresh_def supp_bool trm.supp)\nnext\n  case (Iff tst thn els e0' x' e2')\n  let ?subtst = \"tst[x'::=e0']\"\n  let ?subthn = \"thn[x'::=e0']\"\n  let ?subels = \"els[x'::=e0']\"\n  have a:\"e2' = Iff ?subtst ?subthn ?subels\" using Iff by simp\n  have s1:\"fv ?subtst <= fv tst\" using Iff by simp\n  have s2:\"fv ?subthn <= fv thn\" using Iff by simp\n  have s3:\"fv ?subels <= fv els\" using Iff by simp\n  have b:\"fv e2' = fv ?subtst \\<union> fv ?subthn \\<union> fv ?subels\" using trm.supp Iff a by auto\n  have d:\"fv (Iff tst thn els) = fv tst  \\<union> fv thn  \\<union> fv els\" using trm.supp by auto\n  show ?case using d s1 s2 s3 b by auto\nnext\n  case (Abs name body T e0' x' e2')\n  have aa:\"fv (body[x'::=e0']) \\<subseteq> fv body\" using Abs by auto\n  have a:\"fv (Lam[name:T].body) = fv body - {name}\" using fv_lam by simp\n  have b:\"fv (Lam[name:T].(body[x'::=e0'])) = fv (body[x'::=e0']) - {name}\" using fv_lam by simp\n  have \"name \\<sharp> (e0',T,x')\" using Abs by auto\n  hence c:\"(Lam[name:T].(body[x'::=e0'])) = (Lam[name:T].(body))[x'::=e0']\" by simp\n  hence d:\"fv e2' = fv (body[x'::=e0']) - {name}\" using b Abs by auto\n  thus ?case using a aa  by auto\nqed\n\n\nlemma subst_only_var_closed:\n  assumes \"closed e0\" and \"fv e1 <= {x}\"\n  shows \"closed (e1[x::=e0])\"\nproof -\n  let ?e2 = \"(e1[x::=e0])\"\n  have a:\"fv ?e2 <= {x}\" using prems subst_closed[of e1 x e0 ?e2] by auto\n  have \"x \\<sharp> e0\" using prems fresh_def[of x e0] closed_def[of e0] by auto\n  hence \"x \\<sharp> ?e2\" using subst_removes_var[of e1 x e0 ?e2] by auto\n  hence b:\"x \\<notin> fv ?e2\" using fresh_def[of x ?e2] closed_def[of ?e2] by auto\n  from a b have \"fv ?e2 = {}\" by auto\n  thus ?thesis using closed_def by simp\nqed\n\nlemma beta_closed_closed:\n  assumes \"closed (Lam[x:T].b)\" and \"closed v\"\n  shows \"closed (b[x::=v])\"\n  using prems closed_lam subst_only_var_closed\n  by auto\n\n\ntext {* values *}\n\n\ninductive values :: \"trm \\<Rightarrow> bool\" (\"_ : values\" [80])\nwhere\n  abs_value[simp]: \"Lam[x:t].b : values\"\n|  bi_value[simp]: \"BI c : values\"\n|  num_value[simp]: \"Num n : values\"\n|  bool_value[simp]: \"Bool b : values\"\n\nequivariance values\n\nabbreviation\n  \"in_values\" :: \"trm \\<Rightarrow> bool\" (\"_ \\<in> values\" [100] 100) where\n  \"e \\<in> values \\<equiv> (e : values)\"\n\nabbreviation\n  \"not_in_values\" :: \"trm \\<Rightarrow> bool\" (\"_ \\<notin>  values\" [100] 100) where\n  \"e \\<notin> values \\<equiv> (~ e : values)\"\n\nlemma not_false_eqvt:\n  fixes pi :: \"name prm\"\n  and   t  :: \"trm\"\n  assumes a:\"t ~= trm.Bool False\" and b:\"t : values\"\n  shows \"(pi\\<bullet>t) ~= trm.Bool False\"\n  using b a\n  by induct (auto simp add: perm_bool)\n\ninductive_cases iff_value:\"Iff a b c : values\"\ninductive_cases app_value:\"App a b : values\"\ninductive_cases var_value:\"Var a : values\"\n\nnominal_inductive values by (simp add: abs_fresh)\n\ntext {* Typing Constants *}\n\nconsts\n  \\<Delta>\\<^isub>\\<tau> :: \"builtin \\<Rightarrow> ty\"\n\nnominal_primrec\n  \"\\<Delta>\\<^isub>\\<tau> NumberP = (Top \\<rightarrow> BoolTy : Latent ty.Int)\"\n  \"\\<Delta>\\<^isub>\\<tau> BooleanP = (Top \\<rightarrow> BoolTy : Latent BoolTy)\"\n  \"\\<Delta>\\<^isub>\\<tau> ProcP = (Top \\<rightarrow> BoolTy : Latent (Union [] \\<rightarrow> Top : latent_eff.NE))\"\n  \"\\<Delta>\\<^isub>\\<tau> Add1 = (ty.Int \\<rightarrow> ty.Int : latent_eff.NE)\"\n  \"\\<Delta>\\<^isub>\\<tau> Nott = (Top \\<rightarrow> BoolTy : latent_eff.NE)\"\n  by simp_all\n\nlemma delta_t_eqvt[eqvt]:\n  fixes pi :: \"name prm\"\n  shows \"pi \\<bullet> \\<Delta>\\<^isub>\\<tau> b = \\<Delta>\\<^isub>\\<tau> (pi \\<bullet> b)\"\n  by (nominal_induct b rule: builtin.induct) auto\n\n\n(* Delta Function *)\n\nconsts\n  \\<Delta>  :: \"builtin \\<Rightarrow> trm \\<Rightarrow> trm option\"\n  add1_fun :: \"trm \\<Rightarrow> trm option\"\n  nott_fun :: \"trm \\<Rightarrow> trm option\"\n  numberp_fun :: \"trm \\<Rightarrow> bool\"\n  booleanp_fun :: \"trm \\<Rightarrow> bool\"\n  procp_fun :: \"trm \\<Rightarrow> bool\"\n  procp_bi_fun :: \"builtin \\<Rightarrow> bool\"\n\nnominal_primrec\n  \"add1_fun (Num n) = Some (Num (n+1))\"\n  \"add1_fun (Lam[x:ty].b) = None\"\n  \"add1_fun (Iff a b c) = None\"\n  \"add1_fun (App a b) = None\"\n  \"add1_fun (Bool a) = None\"\n  \"add1_fun (BI a) = None\"\n  \"add1_fun (Var a) = None\"\n  by (auto, finite_guess+, fresh_guess+)\n\nnominal_primrec\n  \"nott_fun (Num n) = (Some (Bool False))\"\n  \"nott_fun (Lam[x:ty].b) = (Some (Bool False))\"\n  \"nott_fun (Iff a b c) = (Some (Bool False))\"\n  \"nott_fun (App a b) = (Some (Bool False))\"\n  \"nott_fun (Bool b) = Some (Bool (~b))\"\n  \"nott_fun (BI a) = (Some (Bool False))\"\n  \"nott_fun (Var a) = (Some (Bool False))\"\n  by (auto, finite_guess+, fresh_guess+)\n  \n\nnominal_primrec\n  \"booleanp_fun (Bool b) = True\"\n  \"booleanp_fun (Num n) = False\"\n  \"booleanp_fun (Abs a b c) = False\"\n  \"booleanp_fun (App a b) = False\"\n  \"booleanp_fun (BI c) = False\"\n  \"booleanp_fun (Var v) = False\"\n  \"booleanp_fun (Iff a b c) = False\"\n  by (auto, finite_guess+, fresh_guess+)\n\nnominal_primrec\n  \"procp_fun (Bool b) = False\"\n  \"procp_fun (Num n) = False\"\n  \"procp_fun (Abs a b c) = True\"\n  \"procp_fun (App a b) = False\"\n  \"procp_fun (BI c) = True\"\n  \"procp_fun (Var v) = False\"\n  \"procp_fun (Iff a b c) = False\"\n  by (auto, finite_guess+, fresh_guess+)\n\nnominal_primrec\n  \"numberp_fun (Bool b) = False\"\n  \"numberp_fun (Num n) = True\"\n  \"numberp_fun (Abs a b c) = False\"\n  \"numberp_fun (App a b) = False\"\n  \"numberp_fun (BI c) = False\"\n  \"numberp_fun (Var v) = False\"\n  \"numberp_fun (Iff a b c) = False\"\n  by (auto, finite_guess+, fresh_guess+)\n\nnominal_primrec\n  \"\\<Delta> Add1 t = add1_fun t\"\n  \"\\<Delta> Nott t = nott_fun t\"\n  \"\\<Delta> BooleanP t = Some (Bool (booleanp_fun t))\"\n  \"\\<Delta> NumberP t = Some (Bool (numberp_fun t))\"\n  \"\\<Delta> ProcP t = Some (Bool (procp_fun t))\"\nby simp_all\n\n\nlemma delta_eqvt:\n  fixes pi :: \"name prm\"\n  and   b :: builtin\n  and   t  :: \"trm\"\n  shows \"\\<Delta> (pi\\<bullet>b) (pi\\<bullet>t) = \\<Delta> b t\"\nproof -\n  have A:\"(pi\\<bullet>b) = b\" by (nominal_induct b rule: builtin.induct) auto\n  have B:\"\\<Delta> b (pi\\<bullet>t) = \\<Delta> b t\"\n  proof (nominal_induct rule: builtin.induct)\n    case Add1\n    thus ?case \n      by (nominal_induct t rule: trm.induct) (auto simp add: perm_nat_def)       \n  next\n    case Nott\n    thus ?case \n      by (nominal_induct t rule: trm.induct) (auto simp add: perm_bool)\n  next\n    case BooleanP\n    thus ?case \n      by (nominal_induct t rule: trm.induct) (auto simp add: perm_bool)\n  next\n    case NumberP\n    thus ?case \n      by (nominal_induct t rule: trm.induct) (auto simp add: perm_bool)\n  next\n    case ProcP\n    thus ?case \n      by (nominal_induct t rule: trm.induct) (auto simp add: perm_bool)\n  qed\n  from A B show ?thesis by auto\nqed\n\nlemma delta_eqvt2[eqvt]:\n  fixes pi :: \"name prm\"\n  and   b :: builtin\n  and   t  :: \"trm\"\n  shows \"(pi\\<bullet>(\\<Delta> b t)) = \\<Delta> (pi\\<bullet>b) (pi\\<bullet>t)\"\nproof -\n  have A:\"(pi\\<bullet>b) = b\" by (nominal_induct b rule: builtin.induct) auto\n  have B:\"\\<Delta> b (pi\\<bullet>t) = (pi\\<bullet>(\\<Delta> b t))\"\n  proof (nominal_induct rule: builtin.induct)\n    case Add1\n    thus ?case \n      by (nominal_induct t rule: trm.induct) (auto simp add: perm_nat_def)       \n  next\n    case Nott\n    thus ?case \n      by (nominal_induct t rule: trm.induct) (auto simp add: perm_bool)\n  next\n    case BooleanP\n    thus ?case \n      by (nominal_induct t rule: trm.induct) (auto simp add: perm_bool)\n  next\n    case NumberP\n    thus ?case \n      by (nominal_induct t rule: trm.induct) (auto simp add: perm_bool)\n  next\n    case ProcP\n    thus ?case \n      by (nominal_induct t rule: trm.induct) (auto simp add: perm_bool)\n  qed\n  from A B show ?thesis by auto\nqed\n\n\nlemma delta_closed:\n  fixes b :: builtin and t::trm\n  assumes \"\\<Delta> b t = Some v\"\n  shows \"closed v\"\n  using prems\n  proof (nominal_induct b rule: builtin.induct)\n    case Add1\n    thus ?case \n      by (nominal_induct t rule: trm.induct)\n         (auto simp add: supp_nat closed_def trm.supp)\n  next\n    case Nott\n    thus ?case\n      by (nominal_induct t rule: trm.induct)\n         (auto simp add: supp_def perm_bool closed_def trm.supp)\n  next\n    case BooleanP\n    thus ?case\n      by (nominal_induct t rule: trm.induct)\n         (auto simp add: supp_def perm_bool closed_def trm.supp)\n  next\n    case NumberP\n    thus ?case\n      by (nominal_induct t rule: trm.induct)\n         (auto simp add: supp_def perm_bool closed_def trm.supp)\n  next\n    case ProcP\n    thus ?case\n      by (nominal_induct t rule: trm.induct)\n         (auto simp add: supp_def perm_bool closed_def trm.supp)\n       qed\n\nlemma delta_value:\n  fixes b :: builtin and t::trm\n  assumes \"\\<Delta> b t = Some v\"\n  shows \"v : values\"\n  using prems\n  proof (nominal_induct b rule: builtin.induct)\n    case Add1\n    thus ?case by (nominal_induct t rule: trm.induct) auto\n  next\n    case Nott\n    thus ?case\n      by (nominal_induct t rule: trm.induct) auto\n  next\n    case BooleanP\n    thus ?case\n      by (nominal_induct t rule: trm.induct) auto\n  next\n    case NumberP\n    thus ?case\n      by (nominal_induct t rule: trm.induct) auto\n  next\n    case ProcP\n    thus ?case\n      by (nominal_induct t rule: trm.induct) auto\n  qed\n\ntext {* Evaluation contexts *}\n\n\ninductive_set ctxt :: \"(trm \\<Rightarrow> trm) set\"\nwhere\n  C_Hole[simp, intro]: \"(%t. t) \\<in> ctxt\"\n|  C_App1[simp, intro]: \"E : ctxt \\<Longrightarrow> (%t .  (App (E t) u)) : ctxt\"\n|  C_App2[simp, intro]: \"E : ctxt \\<Longrightarrow> v : values \\<Longrightarrow> (%t . (App v (E t))) : ctxt\"\n|  C_Iff[simp, intro]: \"E : ctxt \\<Longrightarrow> (%t . (Iff (E t) thn els)) : ctxt\"\n\nlemma ctxt_compose:\n  assumes a:\"E1 : ctxt\" and b:\"E2 : ctxt\"\n  shows \"(%t. E1 (E2 t)) : ctxt\"\n  using a b\n  by (induct E1) auto\n\nconstdefs\n  closed_ctxt :: \"(trm \\<Rightarrow> trm) \\<Rightarrow> bool\"\n  closed_ctxt_def[simp]:\"closed_ctxt C == (C : ctxt \\<and> closed (C (Num 3)))\" --\"3 is a trivially closed term\"\n\nlemma ctxt_closed:\n  assumes \"closed_ctxt C\" \n  shows \"closed (C e) = closed e\"\n  using prems\nproof -\n  have \"C : ctxt\" using prems by simp\n  thus ?thesis using prems\n    by (induct) (auto simp add: closed_def trm.supp)\nqed  \n \nlemma closed_in_ctxt_closed_ctxt:\n  assumes \"closed e\" and a:\"C : ctxt\" and \"e = C L\"\n  shows \"closed L \\<and> closed_ctxt C\"\n  using a prems \n  proof (induct C arbitrary: L e rule: ctxt.induct)\n    case C_Hole\n    thus ?case by (auto simp add: closed_def trm.supp supp_nat)\n  next\n    case (C_App1 E arg L' e')\n    have IH:\"!!e L. \\<lbrakk>closed e; E \\<in> ctxt; e = E L\\<rbrakk> \\<Longrightarrow> closed L \\<and> closed_ctxt E\" using prems by blast\n    have cl:\"closed (App (E L') arg)\" using `e' = (App (E L') arg)` `closed e'` by simp\n    from cl have \"closed arg\"by (auto simp add: closed_def trm.supp)\n    from cl have \"closed (E L')\"  by (auto simp add: closed_def trm.supp)\n    thus ?case using IH[of \"(E L')\" L'] `E : ctxt` `closed arg`\n      by (auto simp add: trm.supp closed_def)\n  next\n    case (C_App2 E rator L' e')\n    have IH:\"!!e L. \\<lbrakk>closed e; E \\<in> ctxt; e = E L\\<rbrakk> \\<Longrightarrow> closed L \\<and> closed_ctxt E\" using prems by blast\n    have cl:\"closed (App rator (E L'))\" using prems by blast\n    from cl have \"closed rator\" by (auto simp add: closed_def trm.supp)\n    from cl have \"closed (E L')\"  by (auto simp add: closed_def trm.supp)\n    thus ?case using IH[of \"(E L')\" L'] `E : ctxt` `closed rator`\n      by (auto simp add: trm.supp closed_def)\n  next\n    case (C_Iff E thn els L' e')\n    let ?trm = \"Iff (E L') thn els\"\n    have IH:\"!!e L. \\<lbrakk>closed e; E \\<in> ctxt; e = E L\\<rbrakk> \\<Longrightarrow> closed L \\<and> closed_ctxt E\" using prems by blast\n    have cl:\"closed ?trm\" using prems by blast\n    from cl have \"closed thn\" and \"closed els\" by (auto simp add: closed_def trm.supp)\n    from cl have \"closed (E L')\"  by (auto simp add: closed_def trm.supp)\n    thus ?case using IH[of \"(E L')\" L'] `E : ctxt` `closed thn` `closed els`\n      by (auto simp add: trm.supp closed_def)\n  qed\n\nlemma closed_in_ctxt:\n  assumes \"closed (C L)\"\n  and \"C : ctxt\"\n  shows \"closed L\"\n  using `C : ctxt` `closed (C L)`\n  by (induct C) (auto simp add: closed_def trm.supp)\n\n\ntext{* Reduction *}\n\ninductive reduce :: \"trm \\<Rightarrow> trm \\<Rightarrow> bool\" (\"_ \\<hookrightarrow> _\" [200,200] 200)\n  where\n  e_beta[simp]: \"v : values \\<Longrightarrow> x \\<sharp> v \\<Longrightarrow> (App (Lam[x:t].b) v) \\<hookrightarrow> (b[x::=v])\"\n  | e_if_false[simp]: \"Iff (Bool False) e1 e2 \\<hookrightarrow> e2\"\n  | e_if_true[simp]: \"v ~= Bool False \\<Longrightarrow> v : values \\<Longrightarrow> Iff v e1 e2 \\<hookrightarrow> e1\"\n  | e_delta[simp]: \"\\<lbrakk>v : values; \\<Delta> p v = Some e\\<rbrakk> \\<Longrightarrow> App (BI p) v \\<hookrightarrow> e\"\n\nequivariance reduce\n\nnominal_inductive reduce\n  by (simp_all add: abs_fresh subst_removes_var)\n\ninductive\n  \"step\" :: \"trm\\<Rightarrow>trm\\<Rightarrow>bool\" (\" _ \\<longrightarrow> _\" [80,80]80)\nwhere\n  step_one[intro]:\"\\<lbrakk>E : ctxt; L \\<hookrightarrow> R\\<rbrakk> \\<Longrightarrow> E L \\<longrightarrow> E R\"\n\ninductive\nstep_multi :: \"trm \\<Rightarrow> trm \\<Rightarrow> bool\" (\" _ \\<longrightarrow>\\<^sup>* _\" [80,80] 80)\nwhere \n  sm_refl:\"a \\<longrightarrow>\\<^sup>* a\"\n| sm_trans:\"a \\<longrightarrow> b \\<Longrightarrow> b \\<longrightarrow>\\<^sup>* c \\<Longrightarrow> a \\<longrightarrow>\\<^sup>* c\"\n\n(* doesn't work *)\n(* equivariance step *)\n\n\nconstdefs\nreduce_forever :: \"trm \\<Rightarrow> bool\"\n\"reduce_forever e == \\<forall>e' . (e \\<longrightarrow>\\<^sup>* e') \\<longrightarrow> (EX e''. e' \\<longrightarrow> e'')\"\n\n\n(* reduction examples *)\n\n\nlemma \"(App (Lam [x:t].(Var x)) (Num 4)) \\<hookrightarrow> Num 4\"\n  proof -\n    have \"Num 4 : values\" \"x \\<sharp> Num 4\" by (auto simp add: fresh_nat)\n    hence h:\"(App (Lam [x:t].(Var x)) (Num 4)) \\<hookrightarrow> ((Var x)[x::=(Num 4)])\" by (rule e_beta)\n    have \"((Var x)[x::=(Num 4)]) = Num 4\" by auto\n    thus ?thesis using h  by auto\n  qed\n\n(* some lemmas about reduction *)\n\n\nlemma if_val_reduces: \n  assumes a:\"tst : values\"\n  shows \"Iff tst thn els \\<hookrightarrow> thn \\<or> Iff tst thn els \\<hookrightarrow> els\"\n  using a\nproof (nominal_induct tst rule: trm.induct)\n  case (Bool b) \n  thus ?case using e_if_true e_if_false\n    by (cases b) (auto simp add: trm.inject)\nqed (auto)\n\n(* a helper lemma - whee abstraction *)\nlemma ex_help: \n  assumes a:\"e = E t \\<and> E : ctxt \\<and>  t \\<hookrightarrow> t'\"\n  shows \"\\<exists>E t t' . e = E t \\<and> E \\<in> ctxt \\<and> t \\<hookrightarrow> t'\"\n  using a by blast\n\nlemma reduce_in_ctxt:\n  fixes e :: trm\n  assumes ct:\"C : ctxt\"\n  and ih:\"(EX E L R. e = E L \\<and> E : ctxt \\<and> L \\<hookrightarrow> R)\"\n  shows \"(EX E L R. C e = E L \\<and> E : ctxt \\<and> L \\<hookrightarrow> R)\"\nproof -\n  from ih ct obtain Enew tnew t'new where \"e = Enew tnew\" and  1:\"Enew \\<in> ctxt\" and g1:\"tnew \\<hookrightarrow> t'new\" by auto\n  let ?E=\"(%t . C (Enew t))\"\n  have g3:\"?E tnew = C e\" using `e = Enew tnew` by auto\n  thus \"\\<exists>E t t' . C e = E t \\<and> E \\<in> ctxt \\<and> t \\<hookrightarrow> t'\"\n    using ctxt_compose[OF ct 1] g1 g3 ex_help[of \"C e\" ?E tnew] by auto\nqed\n\ninductive_cases iff_bi_red : \"(Iff (Const (BI bi)) thn els) \\<hookrightarrow> e\"\ninductive_cases iff_red : \"(Iff tst thn els) \\<hookrightarrow> e\"\n\nlemma reduce_closed:\n  assumes \"closed L\" and \"L \\<hookrightarrow> R\"\n  shows \"closed R\"\n  using `L \\<hookrightarrow> R` `closed L`\n  proof (induct)\n    case (e_beta v x t b) \n    have a:\"closed (Abs x b t)\" using e_beta closed_def trm.supp by simp\n    have b:\"closed v\" using e_beta closed_def trm.supp by simp\n    from a b show ?case using e_beta beta_closed_closed by simp\n  next\n    case e_if_true thus ?case using closed_def trm.supp by auto\n  next\n    case e_if_false thus ?case using closed_def trm.supp by auto\n  next\n    case e_delta thus ?case using delta_closed by auto\n  qed\n\n\nlemma step_closed:\n  assumes A:\"closed e\" and B:\"(e :: trm) \\<longrightarrow> e'\"\n  shows \"closed e'\"\nproof - \n  from B obtain E L R where C:\"E : ctxt\"  \"e = E L\"  \"L \\<hookrightarrow> R\"  \"e' = E R\" by induct auto\n  hence D:\"closed L\" \"closed_ctxt E\" using A closed_in_ctxt_closed_ctxt[of e E L] by auto\n  hence \"closed R\" using C reduce_closed[of L R] by auto\n  hence \"closed e'\" using C D ctxt_closed[of E R] by auto\n  thus ?thesis .\nqed\n\nlemma multi_step_closed:\n  assumes A:\"closed e\" and B:\"e \\<longrightarrow>\\<^sup>* e'\"\n  shows \"closed e'\"\n  using B A step_closed\n  by induct auto\n  \n\n\n\ntext {* \"partial order\" (not really) between effects *}\n\ninductive\n  subeff :: \"eff \\<Rightarrow> eff \\<Rightarrow> bool\"(\"\\<turnstile> _ <e: _\" [60,60] 60)\nwhere\n  SE_Refl[intro]: \"\\<turnstile> F <e: F\"\n| SE_FF[intro]: \"F \\<noteq> TT \\<Longrightarrow> \\<turnstile> FF <e: F\"\n| SE_TT[intro]: \"F \\<noteq> FF \\<Longrightarrow> \\<turnstile> TT <e: F\"\n| SE_VE[intro]: \"\\<turnstile> NE <e: VE x\"\n| SE_TE[intro]: \"\\<turnstile> NE <e: TE S x\"\n\nequivariance subeff\n\ninductive_cases ne_case:\"\\<turnstile> F1 <e: eff.NE\"\ninductive_cases ne_case_rev:\"\\<turnstile> eff.NE <e: F1\"\ninductive_cases tt_case:\"\\<turnstile> F1 <e: eff.TT\"\ninductive_cases tt_case_rev:\"\\<turnstile> eff.TT <e: F1\"\ninductive_cases ff_case:\"\\<turnstile> F1 <e: eff.FF\"\ninductive_cases ff_case_rev:\"\\<turnstile> eff.FF <e: F1\"\n\nlemma no_sub_FF: \n   \"\\<lbrakk>\\<turnstile> T <e: T' ; T' = FF \\<rbrakk> \\<Longrightarrow> T = FF\"\n  by (induct rule: subeff.induct) auto\n\nlemma no_sub_TT: \n   \"\\<lbrakk>\\<turnstile> T <e: T' ; T' = TT \\<rbrakk> \\<Longrightarrow> T = TT\"\n  by (induct rule: subeff.induct) auto\n\nconstdefs\n  simple_eff :: \"eff \\<Rightarrow> bool\"\n  simple_eff_def[simp]:\"simple_eff e == e = eff.NE \\<or> e = FF \\<or> e = TT\"\n\nlemma simple_eff_cases[consumes 1, case_names NE FF TT]:\n  fixes F::eff\n  and P :: \"eff \\<Rightarrow> bool\"\n  assumes a:\"simple_eff F\"\n  and a1:\"P NE\"\n  and a2:\"P FF\"\n  and a3:\"P TT\"\n  shows \"P F\"\n  using prems\nby (nominal_induct F rule: eff.induct) auto\n\nlemma simple_eff_below_ne:\n  assumes \"simple_eff F\"\n  shows \"\\<turnstile> F <e: NE\"\n  using prems\nby (nominal_induct F rule: eff.induct) auto\n\n\nlemma SE_Trans[intro]: \n  assumes\"\\<turnstile> F1 <e: F2 \"and \"\\<turnstile> F2 <e: F3 \" and \"simple_eff F1\" and \"simple_eff F2\" and \"simple_eff F3\"\n  shows \" \\<turnstile> F1 <e: F3\"\n  using `simple_eff F3` prems\n  proof (induct F3 rule: simple_eff_cases)\n    case NE thus ?case using simple_eff_below_ne by auto\n  next\n    case FF thus ?case using no_sub_FF by auto\n  next\n    case TT thus ?case using no_sub_TT by auto\nqed\n\ntext{* subtyping *}\n\ninductive\n  subtype :: \"ty \\<Rightarrow> ty \\<Rightarrow> bool\" (\"\\<turnstile> _ <: _\" [60,60] 60)\nwhere\n  S_Refl[intro]: \"\\<turnstile> T <: T\"\n| S_Fun[intro]: \"\\<lbrakk>\\<turnstile> S1 <: T1 ; \\<turnstile> T2 <: S2 ; eff = eff' \\<or> eff' = latent_eff.NE\\<rbrakk> \\<Longrightarrow> \\<turnstile> (T1 \\<rightarrow> T2 : eff) <: (S1 \\<rightarrow> S2 : eff')\"\n| S_Top[intro]: \"\\<turnstile> T <: Top\"\n| S_UnionAbove[intro]: \"\\<lbrakk>T : set Ts ; \\<turnstile> S <: T\\<rbrakk> \\<Longrightarrow> \\<turnstile> S <: Union Ts\"\n| S_UnionBelow[intro]: \"\\<lbrakk>!! T.( T : set Ts \\<Longrightarrow> \\<turnstile> T <: S)\\<rbrakk> \\<Longrightarrow> \\<turnstile> Union Ts <: S\"\n\nequivariance subtype\n\nnominal_inductive subtype done\n\n\ninductive_cases sub_arr_cases: \"\\<turnstile> T <: S1 \\<rightarrow> S2 : L\"\n\nlemma subtype_arr_elim:\n  \"\\<lbrakk>\\<turnstile> T <: S ; S = S0 \\<rightarrow> S1 : le\\<rbrakk> \\<Longrightarrow> (EX T0 T1. T = T0 \\<rightarrow> T1 : le \\<and> \\<turnstile> S0 <: T0 \\<and> \\<turnstile> T1 <: S1) \\<or> (EX T0 T1 le'. T = T0 \\<rightarrow> T1 : le' \\<and> le = latent_eff.NE \\<and> \\<turnstile> S0 <: T0 \\<and> \\<turnstile> T1 <: S1) \\<or> (EX Ts. T = Union Ts)\"\nproof (induct arbitrary: S0 S1  rule: subtype.induct)\n  qed (auto)\n\nlemma S_TopE:\n  assumes a: \"\\<turnstile> Top <: T\"\n  shows \"T = Top \\<or> (EX Ts T'. T = Union Ts \\<and> T' : set Ts \\<and> \\<turnstile> Top <: T')\"\nusing a by (cases, auto) \n\nlemma S_ArrowE_left:\n  assumes a: \"\\<turnstile> S\\<^isub>1 \\<rightarrow> S\\<^isub>2 : L <: T\" \n  shows \"T = Top \\<or> (\\<exists>T\\<^isub>1 T\\<^isub>2. T = T\\<^isub>1 \\<rightarrow> T\\<^isub>2  : L \\<and> \\<turnstile> T\\<^isub>1 <: S\\<^isub>1 \\<and> \\<turnstile> S\\<^isub>2 <: T\\<^isub>2) \\<or> \n  (\\<exists>T\\<^isub>1 T\\<^isub>2. T = T\\<^isub>1 \\<rightarrow> T\\<^isub>2  : latent_eff.NE \\<and> \\<turnstile> T\\<^isub>1 <: S\\<^isub>1 \\<and> \\<turnstile> S\\<^isub>2 <: T\\<^isub>2) \\<or>\n  (EX Ts T1. T = Union Ts \\<and> T1 : set Ts \\<and> \\<turnstile> S\\<^isub>1 \\<rightarrow> S\\<^isub>2 : L <: T1)\"\nusing a by (cases, auto simp add: ty.inject)\n\nlemma union_size_ty:\n  assumes \"T : set Ts\"\n  shows \"size_ty T < size_ty (Union Ts)\"\n  using prems size_ty_pos\n  by (induct Ts) auto\n\nfun size_ty3 :: \"ty*ty*ty \\<Rightarrow> nat\"\nwhere \nsize_ty3_def[simp]:\"size_ty3 (a,b,c) = size_ty a + size_ty b + size_ty c\"\n\ninductive_cases union_sub_cases[consumes 1, case_names 1 2 3 4]:\"\\<turnstile> Union Ts <: S\"\n\nlemma union_sub_elim: \n  assumes A:\"\\<turnstile> Union Ts <: T \" (is \"\\<turnstile> ?S <: T\") \n  and B:\" T1 : set Ts \"\n  shows \"\\<turnstile> T1 <: T\"\n  using prems\nproof (induct \"X\"==\"(T1,?S,T)\"  arbitrary: T1 Ts T taking: \"size_ty3\" rule: measure_induct_rule)\n  case (less X)\n  show \" \\<turnstile> T1 <: T\" using `\\<turnstile>  Union Ts <: T` less \n  proof (induct rule: union_sub_cases)\n    case 1 thus ?case by auto\n  next\n    case 2 thus ?case by auto\n  next\n    case (3 T' Ts')\n    have X_inst:\"X = (T1, ty.Union Ts, T)\" .\n    have \"size_ty T' < size_ty T\" using 3 union_size_ty by auto\n    hence \"\\<turnstile> T1 <: T'\" using X_inst 3(4)[OF _ ` \\<turnstile> ty.Union Ts <: T'` `T1 : set Ts`] by auto\n    thus ?case using 3 by auto\n  next\n    case 4 thus ?case by auto\n  qed\nqed\n\n\nlemma S_Trans[intro]:\n  assumes \"\\<turnstile>S<:Q\" and \" \\<turnstile>Q<:T\"\n  shows \"\\<turnstile>S<:T\" \nusing prems\nproof (induct \"X\"==\"(S,Q,T)\"  arbitrary: S Q T taking: \"size_ty3\" rule: measure_induct_rule)\n  case (less X S Q T)\n  show \" \\<turnstile> S <: T\" using `\\<turnstile> S <: Q` less \n  proof (induct  S Q\\<equiv>Q rule: subtype.induct) \n    case S_Refl thus ?case by auto\n  next\n    case (S_Top A)\n    have X_inst:\"X = (A,Q,T)\" .\n    show ?case  \n    proof -\n      {\n\tassume \"EX Ts T'. T = Union Ts \\<and> T' : set Ts \\<and> \\<turnstile> Q <: T'\"\n\tthen obtain Ts T' where \"T = Union Ts \"\" T' : set Ts \"\" \\<turnstile> Q <: T'\" by auto\n\thence \"size_ty T' < size_ty T\" using union_size_ty by auto\n\thence \"size_ty3 (A,Q,T') < size_ty3 (A,Q,T)\" by auto\n\thence \"\\<turnstile> A <: T'\" using `\\<turnstile> A <: Q` `\\<turnstile> Q <: T'` using less(1)[of \"(A,Q,T')\" A Q T'] X_inst by auto\n\thence ?thesis using S_Top prems by auto\n      }\n      thus ?thesis using S_TopE S_Top by auto\n    qed\n  next\n    case (S_Fun Q1 S1 S2 Q2 L L') \n    hence rh_drv: \" \\<turnstile> Q1 \\<rightarrow> Q2 : L' <: T\" by simp\n    have X_inst:\"X = (S1 \\<rightarrow> S2 : L, Q1 \\<rightarrow> Q2 : L', T)\" using S_Fun by auto\n    note `Q1 \\<rightarrow> Q2 : L' = Q`  \n    hence Q12_less: \"size_ty Q1 < size_ty Q\" \"size_ty Q2 < size_ty Q\" using size_ty_pos by auto\n    have lh_drv_prm1: \" \\<turnstile> Q1 <: S1\" by fact\n    have lh_drv_prm2: \" \\<turnstile> S2 <: Q2\" by fact      \n    have \"T=Top \\<or> (\\<exists>T1 T2 LL. T=T1\\<rightarrow>T2 : LL \\<and> \\<turnstile>T1<:Q1 \\<and> \\<turnstile>Q2<:T2 \\<and> LL = L') \\<or> \n      (\\<exists>T1 T2. T=T1\\<rightarrow>T2 : latent_eff.NE \\<and> \\<turnstile>T1<:Q1 \\<and> \\<turnstile>Q2<:T2) \\<or>\n      (EX Ts T1. T = Union Ts \\<and> T1 : set Ts \\<and> \\<turnstile> Q1 \\<rightarrow> Q2 : L' <: T1)\" \n      using S_ArrowE_left[OF rh_drv] by auto\n    moreover\n    { \n      assume \"\\<exists>T1 T2 LL. T=T1\\<rightarrow>T2:LL \\<and> \\<turnstile>T1<:Q1 \\<and> \\<turnstile>Q2<:T2 \\<and> LL = L'\"\n      then obtain T1 T2 LL\n\twhere T_inst: \"T = T1 \\<rightarrow> T2 : L'\" \n\tand   rh_drv_prm1: \" \\<turnstile> T1 <: Q1\"\n\tand   rh_drv_prm2: \" \\<turnstile> Q2 <: T2\"\n\tand   LL': \"LL = L'\" by auto\n      from X_inst T_inst have X_inst':\"X = (S1 \\<rightarrow> S2 : L, Q1 \\<rightarrow> Q2 : L', T1 \\<rightarrow> T2 : L')\" by simp\n      hence \"size_ty3 (T1, Q1, S1) < size_ty3 X\" using size_ty_pos by auto     \n      from X_inst' lh_drv_prm1  rh_drv_prm1 have  \" \\<turnstile> T1 <: S1\" using S_Fun(6)[of _ T1 Q1 S1] size_ty_pos by auto\n      moreover\n      from X_inst' lh_drv_prm2  rh_drv_prm2 have \" \\<turnstile> S2 <: T2\" using S_Fun(6)[of _ S2 Q2   T2] size_ty_pos by auto\n      ultimately have \" \\<turnstile> S1 \\<rightarrow> S2 : L <: T1 \\<rightarrow> T2 : LL\" using LL' S_Fun by (simp add: subtype.S_Fun)\n      hence \" \\<turnstile> S1 \\<rightarrow> S2 : L <: T\" using T_inst LL' by simp\n    }\n    moreover \n    { \n      assume \"EX Ts T1. T = Union Ts \\<and> T1 : set Ts \\<and> \\<turnstile> Q1 \\<rightarrow> Q2 : L' <: T1\"\n      then obtain Ts T1\n\twhere T_inst: \"T = Union Ts\"\n\tand elem: \"T1 : set Ts\"\n\tand sub:\"\\<turnstile> Q1 \\<rightarrow> Q2 : L' <: T1\"\n\tby auto\n      have sub':\"\\<turnstile> S1 \\<rightarrow> S2 : L <:  Q1 \\<rightarrow> Q2 : L'\" using S_Fun by simp\n      have sz:\"size_ty T1 < size_ty T\" using T_inst elem union_size_ty by auto\n      from X_inst T_inst have X_inst':\"X = (S1 \\<rightarrow> S2 : L, Q1 \\<rightarrow> Q2 : L', Union Ts)\" by simp\n      from sub sub' X_inst' \n      have \" \\<turnstile> S1 \\<rightarrow> S2 : L <: T1\"  using S_Fun(6)[OF _ sub' sub]  sz T_inst by auto\n      hence \" \\<turnstile> S1 \\<rightarrow> S2 : L <: T\"  using T_inst elem S_UnionAbove by auto      \n    }\n    moreover\n    {\n      assume \"\\<exists>T1 T2. T=T1\\<rightarrow>T2:latent_eff.NE \\<and> \\<turnstile>T1<:Q1 \\<and> \\<turnstile>Q2<:T2 \"\n      then obtain T1 T2 LL\n\twhere T_inst: \"T = T1 \\<rightarrow> T2 : latent_eff.NE\" \n\tand   rh_drv_prm1: \" \\<turnstile> T1 <: Q1\"\n\tand   rh_drv_prm2: \" \\<turnstile> Q2 <: T2\"\n\t by auto\n      from X_inst T_inst have X_inst':\"X = (S1 \\<rightarrow> S2 : L, Q1 \\<rightarrow> Q2 : L', T1 \\<rightarrow> T2 : latent_eff.NE)\" by simp\n      hence \"size_ty3 (T1, Q1, S1) < size_ty3 X\" using size_ty_pos by auto     \n      from X_inst' lh_drv_prm1  rh_drv_prm1 have  \" \\<turnstile> T1 <: S1\" using S_Fun(6)[of _ T1 Q1 S1] size_ty_pos by auto\n      moreover\n      from X_inst' lh_drv_prm2  rh_drv_prm2 have \" \\<turnstile> S2 <: T2\" using S_Fun(6)[of _ S2 Q2   T2] size_ty_pos by auto\n      ultimately have \" \\<turnstile> S1 \\<rightarrow> S2 : L <: T1 \\<rightarrow> T2 : latent_eff.NE\" using  S_Fun by (simp add: subtype.S_Fun)\n      hence \" \\<turnstile> S1 \\<rightarrow> S2 : L <: T\" using T_inst  by simp\n    }\n    ultimately show \" \\<turnstile> S1 \\<rightarrow> S2 : L <: T\" by blast\n  next\n    case (S_UnionAbove T1 Ts S)\n    have sub1:\"\\<turnstile> S <: T1\" .\n    hence sub2:\"\\<turnstile> T1 <: T\" using S_UnionAbove union_sub_elim[of Ts T T1] by auto\n    have sz:\"size_ty T1 < size_ty Q\" using S_UnionAbove union_size_ty by auto\n    hence \"\\<turnstile> S <: T\" using S_UnionAbove(4)[OF _ sub1 sub2] sz S_UnionAbove(7) by auto\n    thus ?case .\n  next\n    case (S_UnionBelow Ts S)\n    have \"!! T0. T0 : set Ts \\<Longrightarrow> \\<turnstile> T0 <: T\"\n      proof -\n\tfix T0\n\tassume \"T0 : set Ts\"\n\thence sz:\"size_ty T0 < size_ty (Union Ts)\" using union_size_ty by auto\n\thave s1:\"\\<turnstile> T0 <: S\" using S_UnionBelow `T0 : set Ts` by auto\n\thave s2:\"\\<turnstile> S <: T\" using S_UnionBelow by auto\n\tnote S_UnionBelow(6)\n\tthus \"\\<turnstile> T0 <: T\" using S_UnionBelow(3)[OF _ s1 s2] sz `S = Q` by auto\n      qed\n    thus ?case ..\n  qed\nqed\n\n\ntext {* type environments *}\n\ntypes varEnv = \"(name*ty) list\"\n\ntext {* valid contexts *}\ninductive\n  valid :: \"(name\\<times>ty) list \\<Rightarrow> bool\"\nwhere\n    v1[intro]: \"valid []\"\n  | v2[intro]: \"\\<lbrakk>valid \\<Gamma>;a\\<sharp>\\<Gamma>\\<rbrakk>\\<Longrightarrow> valid ((a,\\<sigma>)#\\<Gamma>)\"\n\nequivariance valid\n\nnominal_inductive valid done\n\nlemma fresh_context[rule_format]: \n  fixes  \\<Gamma> :: \"(name\\<times>ty)list\"\n  and    a :: \"name\"\n  assumes a: \"a\\<sharp>\\<Gamma>\"\n  shows \"\\<not>(\\<exists>\\<tau>::ty. (a,\\<tau>)\\<in>set \\<Gamma>)\"\nusing a\nby (induct \\<Gamma>)\n   (auto simp add: fresh_prod fresh_list_cons fresh_atm)\n\nlemma valid_elim: \n  fixes  \\<Gamma> :: \"(name\\<times>ty)list\"\n  and    pi:: \"name prm\"\n  and    a :: \"name\"\n  and    \\<tau> :: \"ty\"\n  shows \"valid ((a,\\<tau>)#\\<Gamma>) \\<Longrightarrow> valid \\<Gamma> \\<and> a\\<sharp>\\<Gamma>\"\nby (ind_cases \"valid ((a,\\<tau>)#\\<Gamma>)\") simp\n\nlemma valid_unicity[rule_format]: \n  assumes a: \"valid \\<Gamma>\"\n  and     b: \"(c,\\<sigma>)\\<in>set \\<Gamma>\"\n  and     c: \"(c,\\<tau>)\\<in>set \\<Gamma>\"\n  shows \"\\<sigma>=\\<tau>\" \nusing a b c\nby (induct \\<Gamma>) (auto dest!: valid_elim fresh_context)\n\ndeclare fresh_list_cons[simp]\ndeclare fresh_list_nil[simp]\n\n(* environment operations *)\n\nconsts \n  env_plus :: \"eff \\<Rightarrow> varEnv => varEnv\"\n  env_minus :: \"eff \\<Rightarrow> varEnv => varEnv\"\n\n(* original type is the SECOND argument *)\n\nconstdefs\nless_ty :: \"((ty * ty) * ty * ty) set\"\n\"less_ty == {((a,b),c,d) . (size_ty b) < (size_ty d)}\"\n\nfunction (sequential)\n  restrict :: \"ty \\<Rightarrow> ty \\<Rightarrow> ty\"\nwhere\n  restrict_union: \"restrict r (Union (ls :: ty list)) = \n  (if (\\<turnstile> r <: Union ls) then r else (if (\\<turnstile> Union ls <: r) then (Union ls) else Union (map (restrict r) ls)))\"\n| restrict_top:\"restrict r Top = r\"\n| restrict_other:\"restrict r T = (if (\\<turnstile> r <: T) then r else T)\"\n  by pat_completeness auto\ntermination using union_size_ty\n  by (relation \"measure (% (a,b). size_ty b)\") auto\n\nlemma restrict_eqvt[eqvt]:\n  fixes pi::\"name prm\"\n  shows \"pi\\<bullet>(restrict T1 T2) = restrict (pi\\<bullet>T1) (pi\\<bullet>T2)\"\nby (induct T2) (auto)\n\ntext {* this is the key lemma in the whole soundness proof *}\n\nfun simple_ty :: \"ty \\<Rightarrow> bool\"\nwhere\n  \"simple_ty ty.Int = True\"\n|  \"simple_ty ty.TT = True\"\n|  \"simple_ty ty.FF = True\"\n|  \"simple_ty (A1 \\<rightarrow> A2 : L) = True\"\n(* |  \"simple_ty (Union [ty.TT,ty.FF]) = True\" *)\n|  \"simple_ty T = False\"\n\nlemma ty_cases[consumes 0, case_names Top Int TT FF Arr Union]:\n  fixes P :: \"ty \\<Rightarrow> bool\"\n  and T :: ty\n  assumes a1:\"P Top\"\n  and a2:\"P ty.Int\"\n  and a3:\"P ty.TT\"\n  and a3':\"P ty.FF\"\n  and a4:\"!! t1 t2 L. P (t1 \\<rightarrow> t2 : L)\"\n  and a5:\"!! Ts . P (Union Ts)\"\n  shows \"P T\"\n  using  ty_latent_eff.induct[of P \"(%e . True)\" \"(%e . True)\" T] prems\n  by auto\n\ninductive_cases tt_below_union:  \"\\<turnstile> ty.TT <: ty.Union Ts\"\ninductive_cases ff_below_union:  \"\\<turnstile> ty.FF <: ty.Union Ts\"\n\n(* I believe this to be true without C, but it's easier to prove this way, and that's all we need *)\nlemma restrict_soundness:\n  assumes A:\"\\<turnstile> T0 <: T\"\n  and B:\"\\<turnstile> T0 <: S\"\n  and C:\"simple_ty T0\"\n  shows \"\\<turnstile> T0 <: restrict S T\"\n  using prems\nproof (induct T arbitrary: S T0 taking:\"size_ty\" rule: measure_induct_rule)\n  case (less T S T0)\n  thus ?case\n  proof (induct T==T rule: ty_cases)\n    case Top thus ?case by auto\n  next\n    case Int thus ?case by auto\n  next\n    case TT thus ?case by auto\n  next\n    case FF thus ?case by auto\n  next\n    case Arr thus ?case by auto\n  next\n    case (Union Ts)\n    have r:\"restrict S T = (if (\\<turnstile> S <:T) then S else (if (\\<turnstile> T <: S) then T else Union (map (restrict S) Ts)))\" \n      using prems restrict_union[of S Ts] by auto\n    thus ?case\n    proof -\n      {\n\tassume \"\\<turnstile> S <: T\"\n\thence \"restrict S T = S\" using r by simp\t\n\thence ?thesis using prems by auto\n      }\n      moreover\n      {\n\tassume \"\\<turnstile> T <: S\" \"~ (\\<turnstile> S <: T)\"\n\thence \"restrict S T = T\" using r by simp\t\n\thence ?thesis using prems by auto\n      }\n      moreover\n      {\n\tassume \"~ (\\<turnstile> T <: S)\" \"~ (\\<turnstile> S <: T)\"\n\thence req:\"restrict S T =  Union (map (restrict S) Ts)\" using r by auto\n\thave T:\"\\<turnstile> T0 <: Union Ts\" using prems by simp\n\thave \"?this \\<Longrightarrow> ?thesis\"\n\tproof (ind_cases \"\\<turnstile> T0 <: Union Ts\")\n\t  assume 0:\"Union Ts = T0\" thus ?thesis using `simple_ty T0` by (induct T0 rule: simple_ty.induct) auto\n\tnext\n\t  fix Ts'\n\t  assume \"T0 = ty.Union Ts'\" thus ?thesis using `simple_ty T0` by (induct T0 rule: simple_ty.induct) auto\n(* \n\t  hence 1:\"T0 = Union [ty.TT,ty.FF]\" using `simple_ty T0` by (induct T0 rule: simple_ty.induct) auto\n\n          have \"\\<turnstile> ty.TT <: T0\" using 1 by auto\n          hence \"\\<turnstile> ty.TT <: Union Ts\" \"\\<turnstile> ty.TT <: T\" \"\\<turnstile> ty.TT <: S\" using T `\\<turnstile> T0 <: S` `\\<turnstile> T0 <: T` by auto\n          hence \"EX \\<sigma> . \\<sigma> : set Ts \\<and> \\<turnstile> ty.TT <: \\<sigma>\" using tt_below_union by auto\n          then guess \\<sigma> by auto\n          hence \"size_ty \\<sigma> < size_ty T\" using prems union_size_ty by auto\n          note prems(4)[OF `size_ty \\<sigma> < size_ty T` `\\<turnstile> ty.TT <: \\<sigma>` `\\<turnstile> ty.TT <: S`, simplified]\n          hence A_tt:\"\\<turnstile> ty.TT <: restrict S \\<sigma>\" .\n          have mem:\"restrict S \\<sigma> : set (map (restrict S) Ts)\" using `\\<sigma> : set Ts` by auto\n          hence \"\\<turnstile> ty.TT <: Union (map (restrict S) Ts)\" using A_tt S_UnionAbove by auto\n          hence tt_sub:\"\\<turnstile> ty.TT <: restrict S T\" using req by auto\n\n          have \"\\<turnstile> ty.FF <: T0\" using 1 by auto\n          hence \"\\<turnstile> ty.FF <: Union Ts\" \"\\<turnstile> ty.FF <: T\" \"\\<turnstile> ty.FF <: S\" using T `\\<turnstile> T0 <: S` `\\<turnstile> T0 <: T` by auto\n          hence \"EX \\<sigma> . \\<sigma> : set Ts \\<and> \\<turnstile> ty.FF <: \\<sigma>\" using ff_below_union by auto\n          then guess \\<sigma> by auto\n          hence \"size_ty \\<sigma> < size_ty T\" using prems union_size_ty by auto\n          note prems(4)[OF `size_ty \\<sigma> < size_ty T` `\\<turnstile> ty.FF <: \\<sigma>` `\\<turnstile> ty.FF <: S`, simplified]\n          hence A_ff:\"\\<turnstile> ty.FF <: restrict S \\<sigma>\" .\n          have mem:\"restrict S \\<sigma> : set (map (restrict S) Ts)\" using `\\<sigma> : set Ts` by auto\n          hence \"\\<turnstile> ty.FF <: Union (map (restrict S) Ts)\" using A_ff S_UnionAbove by auto\n          hence ff_sub:\"\\<turnstile> ty.FF <: restrict S T\" using req by auto\n\n          from ff_sub tt_sub have \"\\<turnstile> Union [ty.TT, ty.FF] <: restrict S T\" by auto\n          thus ?thesis using 1 by auto\n*)\n        next\n\t  fix T'\n\t  assume \"T' : set Ts\" \"\\<turnstile> T0 <: T'\"\n\t  have 1:\"\\<turnstile> T0 <: restrict S T'\" using union_size_ty prems by auto\n\t  have 2:\"set (map (restrict S) Ts) =  (restrict S) ` set Ts\" by auto\n\t  have 3:\"T' : set Ts\" using prems by auto\n\t  have 4:\"restrict S T' : set (map (restrict S) Ts)\" using 2 3 by auto\n\t  hence \"\\<turnstile> T0 <: Union (map (restrict S) Ts)\" using subtype.S_UnionAbove[OF 4 1] by auto\n\t  thus ?thesis using req by auto\n\tqed\n\thence ?thesis using T by simp\n      }\n      ultimately show ?thesis by auto\n    qed\n  qed\nqed\n\nfunction (sequential)\n  remove :: \"ty \\<Rightarrow> ty \\<Rightarrow> ty\"\nwhere\n  remove_union: \"remove r (Union (ls :: ty list)) = (if (\\<turnstile> Union ls <: r) then (Union []) else Union (map (remove r) ls))\"\n| remove_other:\"remove r T = (if (\\<turnstile> T <: r) then (Union []) else T)\"\n  by pat_completeness auto\ntermination using union_size_ty\n  by (relation \"measure (% (a,b). size_ty b)\") auto\n\nlemma remove_eqvt[eqvt]:\n  fixes pi::\"name prm\"\n  shows \"pi\\<bullet>(remove T1 T2) = remove (pi\\<bullet>T1) (pi\\<bullet>T2)\"\nby (induct T2) (auto)\n\nlemma remove_soundness:\n  assumes A:\"\\<turnstile> T0 <: T\" and B:\"~ (\\<turnstile> T0 <: S)\" and C:\"simple_ty T0\"\n  shows \"\\<turnstile> T0 <: remove S T\"\n  using prems\nproof (induct T arbitrary: S T0 taking:\"size_ty\" rule: measure_induct_rule)\n  case (less T S T0)\n  thus ?case\n  proof (induct T==T rule: ty_cases)\n    case (Union Ts)\n    have r:\"remove S T = (if (\\<turnstile> T <:S) then (Union []) else  Union (map (remove S) Ts))\" \n      using prems remove_union[of S Ts] by auto\n    thus ?case\n    proof -\n      {\n\tassume \"\\<turnstile> T <: S\"\n\thence \"remove S T = (Union [])\" using r by simp\t\n\thence ?thesis using prems by auto\n      }\n      moreover\n      {\n\tassume \"~ (\\<turnstile> T <: S)\" \n\thence req:\"remove S T =  Union (map (remove S) Ts)\" using r by auto\n\thave T:\"\\<turnstile> T0 <: Union Ts\" using prems by simp\n\thave \"?this \\<Longrightarrow> ?thesis\"\n\tproof (ind_cases \"\\<turnstile> T0 <: Union Ts\")\n\t  assume 0:\"Union Ts = T0\" thus ?thesis using `simple_ty T0` by auto\n\tnext\n\t  fix Ts'\n\t  assume \"T0 = ty.Union Ts'\"\n\t  thus ?thesis using `simple_ty T0` by auto\n\tnext\n\t  fix T'\n\t  assume \"T' : set Ts\" \"\\<turnstile> T0 <: T'\"\n\t  have 1:\"\\<turnstile> T0 <: remove S T'\" using union_size_ty prems by auto\n\t  have 2:\"set (map (remove S) Ts) =  (remove S) ` set Ts\" by auto\n\t  have 3:\"T' : set Ts\" using prems by auto\n\t  have 4:\"remove S T' : set (map (remove S) Ts)\" using 2 3 by auto\n\t  hence \"\\<turnstile> T0 <: Union (map (remove S) Ts)\" using subtype.S_UnionAbove[OF 4 1] by auto\n\t  thus ?thesis using req by auto\n\tqed\n\thence ?thesis using T by simp\n      }\n      ultimately show ?thesis by auto\n    qed\n  qed (auto)\nqed\n\nlemma restrict_remove_soundness:\n  assumes A:\"\\<turnstile> T0 <: T\" and B:\"simple_ty T0\"\n  shows\n  \"(\\<turnstile> T0 <: S \\<and> \\<turnstile> T0 <: restrict S T) \\<or> (~ (\\<turnstile> T0 <: S) \\<and> \\<turnstile> T0 <: remove S T)\"\nusing restrict_soundness[OF A _ B] remove_soundness[OF A _ B]\nby auto\n\nfun replace :: \"ty \\<Rightarrow> ty \\<Rightarrow> ty\"\nwhere\n  \"replace t u = t\"\n\nfun mapfun :: \"(ty \\<Rightarrow> ty \\<Rightarrow> ty) \\<Rightarrow> ty \\<Rightarrow> name \\<Rightarrow> (name*ty) \\<Rightarrow> (name * ty)\"\nwhere\nmapfun_def: \"mapfun f T x (v,S) =  (if (x = v) then (v, f T S) else (v,S))\" \n\n\nconstdefs\n  envop :: \"(ty \\<Rightarrow> ty \\<Rightarrow> ty) \\<Rightarrow> name \\<Rightarrow> ty \\<Rightarrow> (name*ty) list \\<Rightarrow> (name*ty) list\"\n  envop_def[simp]:\"envop f n t G == map (% (v,ty). (if (n = v) then (v,f t ty) else (v,ty))) G\"\n\nlemma envop_mapfun:\n  shows \"map (mapfun f T x) \\<Gamma> = envop f x T \\<Gamma> \" using mapfun_def by auto\n\nlemma envop_fresh:\n  fixes v::name\n  assumes a:\"v \\<sharp> \\<Gamma>\"  and c:\"valid \\<Gamma>\"\n  shows \"v \\<sharp> (envop f n t \\<Gamma>)\"\n  using c a\n  by (induct \\<Gamma> rule: valid.induct) auto\n\nlemma envop_valid:\n  assumes \"valid \\<Gamma>\"\n  shows \"valid (envop f n t \\<Gamma>)\"\n  using assms envop_fresh\n  by induct auto\n\nlemma envop_forget:\n  assumes \"valid \\<Gamma>\" and \"x \\<sharp> \\<Gamma>\"\n  shows \"envop f x T \\<Gamma> = \\<Gamma>\"\n  using prems\n  proof (induct rule: valid.induct)\n    case v1 thus ?case by auto\n  next\n    case (v2 \\<Gamma>' a S)\n    have \"x ~= a\" and \"x \\<sharp> \\<Gamma>'\" using v2 fresh_list_cons fresh_atm[of x a] by auto\n    hence A:\"envop f x T ((a,S)#\\<Gamma>') = (a,S)# (envop f x T \\<Gamma>')\" by auto\n    thus ?case using v2 `x \\<sharp> \\<Gamma>'` by auto\n  qed\n    \n\nnominal_primrec \n  \"env_plus (NE) G = G\"\n  \"env_plus (TE T x) G = envop restrict x T G\"\n  \"env_plus (VE x) G = envop remove x (ty.FF) G\"\n  \"env_plus (TT) G = G\"\n  \"env_plus (FF) G = G\"\n  by auto\n\nlemma map_eqvt[eqvt]:\n  fixes pi::\"name prm\"\n  and   l::\"('a::pt_name) list\"\n  shows \"pi\\<bullet>(map f l) = map (pi\\<bullet>f) (pi\\<bullet>l)\"\n  by (induct l) perm_simp+\n\nlemma env_plus_eqvt[eqvt]:\n  fixes pi::\"name prm\"\n  shows \"pi\\<bullet>(env_plus X G ) = env_plus (pi\\<bullet>X) (pi\\<bullet>G)\"\nproof (nominal_induct X rule: eff.induct)\n  case (TE T x) thus ?case by (perm_simp add: eqvts split_def) auto\nnext\n  case (VE x) thus ?case by (perm_simp add: eqvts split_def) auto\nqed(auto)\n\nnominal_primrec\n  \"env_minus (NE) G = G\"\n  \"env_minus (TE T x) G = envop remove x T G\"\n  \"env_minus (VE x) G = envop replace x ty.FF G\"\n  \"env_minus (TT) G = G\"\n  \"env_minus (FF) G = G\"\n  by auto\n\nlemma env_minus_eqvt[eqvt]:\n  fixes pi::\"name prm\"\n  shows \"pi\\<bullet>(env_minus X G) = env_minus (pi\\<bullet>X) (pi\\<bullet>G)\"\nproof (nominal_induct X rule: eff.induct)\n  case (TE T x) thus ?case\n    by (perm_simp add: eqvts perm_fun_def split_def) auto\n  case (VE x) thus ?case\n    by (perm_simp add: eqvts perm_fun_def split_def) \nqed(auto)\n\nabbreviation   env_plus_syn :: \"varEnv \\<Rightarrow> eff \\<Rightarrow> varEnv\" (\"_ |+ _\"  [70,70] 70)\nwhere\n  \"(G |+ eff) == env_plus eff G\"\n\nabbreviation env_minus_syn :: \"varEnv \\<Rightarrow> eff \\<Rightarrow> varEnv\" (\"_ |- _\"  [70,70] 70)\nwhere\n  \"(G |- eff) == env_minus eff G\"\n\n--\"Induction principle for type envs\"\nlemma env_induct[case_names Nil Cons]:\n  fixes \\<Gamma> :: varEnv\n  assumes a1:\"P []\"\n  and     a2:\"!!G v T. P G \\<Longrightarrow> P ((v,T)#G)\"\n  shows \"P \\<Gamma>\"\n  using a1 a2\n  by (induct \\<Gamma>) auto\n\nlemma envop_eqvt:\n  fixes pi::\"name prm\"\n  shows  \"envop f (pi\\<bullet>n) T (pi\\<bullet>\\<Gamma>) = (pi\\<bullet> (envop f n T \\<Gamma>))\"\n  proof (induct \\<Gamma> rule: env_induct)\n    case Nil thus ?case by auto\n  next\n    case (Cons  G v T0) thus ?case using pt_bij4[of pi n v] pt_name_inst at_name_inst by auto\n  qed\n \nlemma env_plus_eqvt:\n  fixes pi::\"name prm\"\n  shows \"(pi\\<bullet>\\<Gamma>) |+ pi\\<bullet>eff = pi\\<bullet>(\\<Gamma> |+ eff)\"\n  by (nominal_induct eff avoiding: \\<Gamma> rule: eff.induct)\n   (auto simp add: eff.eqvts envop_eqvt simp del: envop_def)\n\nlemma env_minus_eqvt:\n  fixes pi::\"name prm\"\n  shows \"(pi\\<bullet>\\<Gamma>) |- pi\\<bullet>eff = pi\\<bullet>(\\<Gamma> |- eff)\"\n  by (nominal_induct eff avoiding: \\<Gamma> rule: eff.induct)\n     (auto simp add: eff.eqvts envop_eqvt simp del: envop_def)\n\n\nlemma env_plus_simple_eff:\n  assumes \"simple_eff eff\"\n  shows \"\\<Gamma> |+ eff = \\<Gamma>\"\n  using prems \n  by (induct eff rule: simple_eff_cases) auto\n  \nlemma env_minus_simple_eff:\n  assumes \"simple_eff eff\"\n  shows \"\\<Gamma> |- eff = \\<Gamma>\"\n  using prems\n  by (induct eff rule: simple_eff_cases) auto\n\nfun comb_eff :: \"eff \\<Rightarrow> eff \\<Rightarrow> eff \\<Rightarrow> eff\"\nwhere\n  \"comb_eff F1 F2 F3 = eff.NE\"\n\nlemma comb_eff_eqvt[eqvt]:\n  fixes pi :: \"name prm\"\n  shows \"(pi\\<bullet> (comb_eff F1 F2 F3)) = comb_eff (pi\\<bullet>F1) (pi\\<bullet>F2) (pi\\<bullet>F3) \"\n  using comb_eff.simps by auto\n\ntext {* type judgments *}\ninductive\n  typing :: \"varEnv \\<Rightarrow> trm \\<Rightarrow> ty \\<Rightarrow> eff \\<Rightarrow> bool\" (\" _ \\<turnstile> _ : _ ; _ \" [60,60,60,60] 60) \nwhere\n  T_Var[intro]:   \"\\<lbrakk>valid \\<Gamma>; (v,T)\\<in>set \\<Gamma>\\<rbrakk>\\<Longrightarrow> \\<Gamma> \\<turnstile> Var v : T ; VE v\" \n| T_Const[intro]: \"valid \\<Gamma> \\<Longrightarrow> \\<Delta>\\<^isub>\\<tau> b = T \\<Longrightarrow> \\<Gamma> \\<turnstile> (BI b) : T ; TT\"\n| T_Num[intro]: \"valid \\<Gamma> \\<Longrightarrow> \\<Gamma> \\<turnstile> (Num n) : ty.Int ; TT\"\n| T_True[intro]: \"valid \\<Gamma> \\<Longrightarrow> \\<Gamma> \\<turnstile> (Bool True) : ty.TT ; TT\"\n| T_False[intro]: \"valid \\<Gamma> \\<Longrightarrow> \\<Gamma> \\<turnstile> (Bool False) : ty.FF ; FF\"\n| T_Abs[intro]:   \"\\<lbrakk>x \\<sharp> \\<Gamma>; ((x,T1)#\\<Gamma>) \\<turnstile> b : T2; eff\\<rbrakk> \\<Longrightarrow> \\<Gamma> \\<turnstile> Lam [x:T1].b : (T1\\<rightarrow>T2 : latent_eff.NE) ; TT\"\n| T_App[intro]: \"\\<lbrakk>(\\<Gamma> \\<turnstile> e1 : U ; eff1) ; \\<turnstile> U <: (T0 \\<rightarrow> T1 : le); (\\<Gamma> \\<turnstile> e2 : T; eff2) ;  \\<turnstile> T <: T0\\<rbrakk> \\<Longrightarrow> \\<Gamma> \\<turnstile> App e1 e2 : T1 ; NE\"\n| T_AppPred[intro]: \"\\<lbrakk>\\<Gamma> \\<turnstile> e1 : U; eff1; \\<turnstile> U <: (T0 \\<rightarrow> T1 : Latent S);  \\<Gamma> \\<turnstile> e2 : T; VE x ;  \\<turnstile> T <: T0\\<rbrakk> \\<Longrightarrow> \\<Gamma> \\<turnstile> App e1 e2 : T1 ; TE S x\"\n| T_If[intro]: \"\\<lbrakk>\\<Gamma> \\<turnstile> e1 : T1; eff1; (\\<Gamma> |+ eff1) \\<turnstile> e2 : T2; eff2; (\\<Gamma> |- eff1) \\<turnstile> e3 : T3; eff3; \\<turnstile> T2 <: T; \\<turnstile> T3 <: T\\<rbrakk> \\<Longrightarrow> \\<Gamma> \\<turnstile> (Iff e1 e2 e3) : T ; comb_eff eff1 eff2 eff3\"\n| T_AppPredTrue[intro]: \n  \"\\<lbrakk>\\<Gamma> \\<turnstile> e1 : U; eff1; \\<turnstile> U <: (T0 \\<rightarrow> T1 : Latent S); \\<Gamma> \\<turnstile> e2 : T; eff2 ;  \\<turnstile> T <: T0; \\<turnstile> T <: S\\<rbrakk> \\<Longrightarrow> \\<Gamma> \\<turnstile> App e1 e2 : T1 ; TT\"\n| T_AppPredFalse[intro]:\n  \"\\<lbrakk>\\<Gamma> \\<turnstile> e1 : U; eff1; \\<turnstile> U <: (T0 \\<rightarrow> T1 : Latent S); \\<Gamma> \\<turnstile> e2 : T; eff2 ;  \\<turnstile> T <: T0; ~(\\<turnstile> T <: S) ; e2 : values ; closed e2\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma> \\<turnstile> App e1 e2 : T1 ; FF\"\n| T_IfTrue[intro]: \"\\<lbrakk>\\<Gamma> \\<turnstile> e1 : T1 ; TT ; \\<Gamma> \\<turnstile> e2 : T2 ; eff;  \\<turnstile> T2 <: T\\<rbrakk> \\<Longrightarrow> \\<Gamma> \\<turnstile> (Iff e1 e2 e3) : T ; NE\" \n| T_IfFalse[intro]: \"\\<lbrakk>\\<Gamma> \\<turnstile> e1 : T1 ; FF ; \\<Gamma> \\<turnstile> e3 : T3 ; eff;  \\<turnstile> T3 <: T\\<rbrakk> \\<Longrightarrow> \\<Gamma> \\<turnstile> (Iff e1 e2 e3) : T ; NE\"\n| T_AbsPred[intro]:   \"\\<lbrakk>x \\<sharp> \\<Gamma>; ((x,T1)#\\<Gamma>) \\<turnstile> b : T2; TE S x\\<rbrakk> \\<Longrightarrow> \\<Gamma> \\<turnstile> Lam [x:T1].b : (T1\\<rightarrow>T2 : Latent S) ; TT\"\n\nequivariance typing\n\nnominal_inductive typing \n  by (auto simp add: abs_fresh)\n\ntext {* then we begin on preservation *}\n\nabbreviation\n  \"sub\" :: \"(name\\<times>ty) list \\<Rightarrow> (name\\<times>ty) list \\<Rightarrow> bool\" (\" _ \\<lless> _ \" [80,80] 80) where\n  \"\\<Gamma>1 \\<lless> \\<Gamma>2 \\<equiv> \\<forall>a \\<sigma>. (a,\\<sigma>)\\<in>set \\<Gamma>1 \\<longrightarrow>  (a,\\<sigma>)\\<in>set \\<Gamma>2\"\n\nlemma envplus_empty:\n  shows \"env_plus eff [] = []\"\n  by (nominal_induct rule: eff.induct) auto\nlemma envminus_empty:\n  shows \"env_minus eff [] = []\"\n  by (nominal_induct rule: eff.induct) auto\n\nlemma w_lem1:\n  fixes \\<Gamma> \\<Gamma>'\n  assumes \"\\<Gamma> \\<lless> \\<Gamma>'\" and a:\"valid \\<Gamma>'\"\n  shows \"map f \\<Gamma> \\<lless> map f \\<Gamma>'\"\nproof -\n  let ?mapfun = f\n  from prems have \"set \\<Gamma> <= set \\<Gamma>'\" by auto\n  hence \"set (map ?mapfun \\<Gamma>) <= set (map ?mapfun \\<Gamma>')\" by auto\n  hence \"(map ?mapfun \\<Gamma>) \\<lless> (map ?mapfun \\<Gamma>')\" by blast\n  thus ?thesis .\nqed\n  \n  \n\nlemma weakening_envplus: \n  assumes b:\"\\<Gamma> \\<lless> \\<Gamma>'\" and a:\"valid \\<Gamma>'\"\n  shows \"env_plus eff \\<Gamma> \\<lless> env_plus eff \\<Gamma>'\"\n  using a prems w_lem1[of \\<Gamma> \\<Gamma>']\n  by (nominal_induct eff avoiding: \\<Gamma> \\<Gamma>' rule: eff.induct) auto\n\nlemma weakening_envminus: \n  assumes \"\\<Gamma> \\<lless> \\<Gamma>'\" and a:\"valid \\<Gamma>'\" and b:\"valid \\<Gamma>\"\n  shows \"env_minus eff \\<Gamma> \\<lless> env_minus eff \\<Gamma>'\"\n  using a prems w_lem1[of \\<Gamma> \\<Gamma>']\n  by (nominal_induct eff avoiding: \\<Gamma> \\<Gamma>' rule: eff.induct) auto\n\nlemma envplus_valid:\n  assumes \"valid \\<Gamma>\"\n  shows \"valid (\\<Gamma> |+ F)\"\n  using prems\nproof (induct rule: valid.induct)\n  case v1 thus ?case using envplus_empty by auto\nnext\n  case (v2 \\<Gamma>' a T) \n\n  from v2 show ?case\n  proof (nominal_induct rule: eff.induct)\n    case (TE S x)\n    let ?op = \"restrict\"\n    let ?G = \"((a, T) # \\<Gamma>')\"\n    let ?mapfun = \"(% (v,ty). (if (x = v) then (v,?op S ty) else (v,ty)))\"\n    have C:\"valid (map ?mapfun \\<Gamma>')\" using v2 `valid (\\<Gamma>' |+ TE S x)` by auto\n    hence D:\"a \\<sharp> (map ?mapfun \\<Gamma>')\" using v2 envop_fresh `valid (\\<Gamma>' |+ TE S x)` by auto\n    thus ?case\n    proof (cases \"a = x\")\n      case False\n      from D have E:\"valid ((a,T)# (map ?mapfun \\<Gamma>'))\" using C by auto\n      from False have B:\"?G |+ TE S x = ((a,T)# (map ?mapfun \\<Gamma>'))\" by auto\n      thus ?thesis using E by auto\n    next\n      case True\n      hence B:\"?G |+ TE S x = ((a,?op S T)# (map ?mapfun \\<Gamma>'))\" by auto\n      from D have E:\"valid ((a,?op S T)# (map ?mapfun \\<Gamma>'))\" using C by auto\n      thus ?thesis using B by auto\n    qed\n  next\n    case (VE x) \n    thus ?case \n    proof -\n      let ?op = \"remove\"\n      let ?G = \"((a, T) # \\<Gamma>')\"\n      let ?mapfun = \"(% (v,ty). (if (x = v) then (v,?op ty.FF ty) else (v,ty)))\"\n      have C:\"valid (map ?mapfun \\<Gamma>')\" using v2 `valid (\\<Gamma>' |+ VE x)` by auto\n      hence D:\"a \\<sharp> (map ?mapfun \\<Gamma>')\" using v2 envop_fresh `valid (\\<Gamma>' |+ VE x)` by auto\n      thus ?case\n      proof (cases \"a = x\")\n\tcase False\n\tfrom D have E:\"valid ((a,T)# (map ?mapfun \\<Gamma>'))\" using C by auto\n\tfrom False have B:\"?G |+ VE x = ((a,T)# (map ?mapfun \\<Gamma>'))\" by auto\n\tthus ?thesis using E by auto\n      next\n\tcase True\n\thence B:\"?G |+ VE x = ((a,?op ty.FF T)# (map ?mapfun \\<Gamma>'))\" by auto\n\tfrom D have E:\"valid ((a,?op ty.FF T)# (map ?mapfun \\<Gamma>'))\" using C by auto\n\tthus ?thesis using B by auto\n      qed\n    qed\n  qed (auto)\nqed\n\nlemma envminus_valid:\n  assumes \"valid \\<Gamma>\"\n  shows \"valid (\\<Gamma> |- F)\"\n  using prems \nproof (induct rule: valid.induct)\n  case v1 thus ?case using envminus_empty by auto\nnext\n  case (v2 \\<Gamma>' a T) thus ?case\n  proof (nominal_induct rule: eff.induct)\n    case (TE S x)\n    let ?op = \"remove\"\n    let ?G = \"((a, T) # \\<Gamma>')\"\n    let ?mapfun = \"(% (v,ty). (if (x = v) then (v,?op S ty) else (v,ty)))\"\n    have C:\"valid (map ?mapfun \\<Gamma>')\" using v2 `valid (\\<Gamma>' |- TE S x)` by auto\n    hence D:\"a \\<sharp> (map ?mapfun \\<Gamma>')\" using v2 envop_fresh `valid (\\<Gamma>' |- TE S x)` by auto\n    thus ?case\n    proof (cases \"a = x\")\n      case False\n      from D have E:\"valid ((a,T)# (map ?mapfun \\<Gamma>'))\" using C by auto\n      from False have B:\"?G |- TE S x = ((a,T)# (map ?mapfun \\<Gamma>'))\" by auto\n      thus ?thesis using E by auto\n    next\n      case True\n      hence B:\"?G |- TE S x = ((a,?op S T)# (map ?mapfun \\<Gamma>'))\" by auto\n      from D have E:\"valid ((a,?op S T)# (map ?mapfun \\<Gamma>'))\" using C by auto\n      thus ?thesis using B by auto\n    qed\n  next\n    case (VE x) \n    thus ?case \n    proof -\n      let ?op = \"replace\"\n      let ?G = \"((a, T) # \\<Gamma>')\"\n      let ?mapfun = \"(% (v,ty). (if (x = v) then (v,?op ty.FF ty) else (v,ty)))\"\n      have C:\"valid (map ?mapfun \\<Gamma>')\" using v2 `valid (\\<Gamma>' |- VE x)` by auto\n      hence D:\"a \\<sharp> (map ?mapfun \\<Gamma>')\" using v2 envop_fresh `valid (\\<Gamma>' |- VE x)` by auto\n      thus ?case\n      proof (cases \"a = x\")\n\tcase False\n\tfrom D have E:\"valid ((a,T)# (map ?mapfun \\<Gamma>'))\" using C by auto\n\tfrom False have B:\"?G |- VE x = ((a,T)# (map ?mapfun \\<Gamma>'))\" by auto\n\tthus ?thesis using E by auto\n      next\n\tcase True\n\thence B:\"?G |- VE x = ((a,?op ty.FF T)# (map ?mapfun \\<Gamma>'))\" by auto\n\tfrom D have E:\"valid ((a,?op ty.FF T)# (map ?mapfun \\<Gamma>'))\" using C by auto\n\tthus ?thesis using B by auto\n      qed\n    qed\n  qed (auto)\nqed\n\nlemma weakening: \n  assumes a: \"\\<Gamma>1 \\<turnstile> t : \\<sigma> ; F\" \n  and     b: \"valid \\<Gamma>2\" \n  and     c: \"\\<Gamma>1 \\<lless> \\<Gamma>2\"\n  and d:\"valid \\<Gamma>1\"\n  shows \"\\<Gamma>2 \\<turnstile> t:\\<sigma> ; F\"\nusing a b c d\nproof (nominal_induct \\<Gamma>1 t \\<sigma> F avoiding: \\<Gamma>2 rule: typing.strong_induct)\n  case (T_If \\<Gamma> t1 T1 F1 t2 T2 F2 t3 T3 F3 T \\<Gamma>2)\n    have A:\"valid (\\<Gamma> |+ F1)\" using T_If envplus_valid by auto\n    have B:\"valid (\\<Gamma> |- F1)\" using T_If envminus_valid by auto\n    have A':\"valid (\\<Gamma>2 |+ F1)\" using T_If envplus_valid by auto\n    have B':\"valid (\\<Gamma>2 |- F1)\" using T_If envminus_valid by auto\n    have C:\"(\\<Gamma> |+ F1) \\<lless> (\\<Gamma>2 |+ F1)\" using T_If weakening_envplus by auto\n    have D:\"(\\<Gamma> |- F1) \\<lless> (\\<Gamma>2 |- F1)\" using T_If weakening_envminus by auto\n    show ?case using T_If A B C D A' B' by blast\nqed (auto | atomize)+ \n(* FIXME: before using meta-connectives and the new induction *)\n(* method, this was completely automatic *)\n(* need weakening lemmas about env+/- *)\n\n\nlemma \"[] \\<turnstile> (Lam[x:Top]. (Iff (App (BI NumberP) (Var x)) (App (BI Add1) (Var x)) (Num 12))) : (Top \\<rightarrow> ty.Int : latent_eff.NE) ; TT\"\n  apply (rule T_Abs)\n  apply (auto simp add: fresh_def   supp_def perm_fun_def)\n\n  apply (rule T_If)\n  apply auto\n  apply (rule T_AppPred)\n  apply (auto simp add: valid.intros)\n  apply (rule T_App)\n  apply (rule T_Const)\n  defer\n  apply ( simp add: valid.intros)\n  apply (rule S_Refl)\n  apply (rule T_Var)\n  apply (simp add: valid.intros)+\n  apply (rule S_Refl)\n  apply (simp add: valid.intros)+\n  \n  done\n\n\n(* inductive cases about typing *)\n\ninductive_cases iff_t_cases : \"G \\<turnstile> Iff tst thn els : t ; e\"\ninductive_cases app_bi_cases : \"G \\<turnstile> App (Const (BI b)) rand : t ; e\"\ninductive_cases type_arr_case_num: \"\\<Gamma> \\<turnstile> ((Num n)) : (T1 \\<rightarrow> T2 : eff) ; eff'\"\ninductive_cases type_arr_case_bool: \"\\<Gamma> \\<turnstile> ((Bool b)) : (T1 \\<rightarrow> T2 : eff) ; eff'\"\ninductive_cases type_bi_case: \"\\<Gamma> \\<turnstile> ((BI b)) : t ; eff\"\ninductive_cases type_add1_case: \"\\<Gamma> \\<turnstile> ((BI Add1)) : t ; eff\"\ninductive_cases bi_typing_cases: \"\\<Gamma> \\<turnstile> (BI b) : t ; eff\"\ninductive_cases abs_ty_int: \"\\<Gamma> \\<turnstile> (Abs x body t) : ty.Int ; eff'\"\ninductive_cases abs_ty_bool: \"\\<Gamma> \\<turnstile> (Abs x body t) : BoolTy ; eff'\"\ninductive_cases const_ty_int: \"\\<Gamma> \\<turnstile> e : ty.Int ; eff'\"\ninductive_cases const_ty_bool: \"\\<Gamma> \\<turnstile> e : BoolTy ; eff'\"\ninductive_cases iff_false_ty: \"\\<Gamma> \\<turnstile> Iff (Bool False) thn els : t ; eff\"\ninductive_cases app_bi_ty: \"\\<Gamma> \\<turnstile> App (BI b) arg : t ; eff\"\n\n(* Typing Values*)\n\n\nlemma false_ty_elim[rule_format]: \n  \"\\<Gamma> \\<turnstile> (trm.Bool False) : \\<sigma> ; eff \\<Longrightarrow> \\<sigma> = ty.FF \\<and> eff = FF \\<and> valid \\<Gamma>\"\napply (ind_cases \"\\<Gamma> \\<turnstile> (trm.Bool False) : \\<sigma> ; eff\")\napply (auto simp add: trm.inject)\ndone\n\nlemma num_ty_elim[rule_format]: \n  \"\\<Gamma> \\<turnstile> (Num n) : \\<sigma> ; eff \\<Longrightarrow> \\<sigma> = ty.Int \\<and> eff = TT \\<and> valid \\<Gamma>\"\nby (ind_cases \"\\<Gamma> \\<turnstile> (Num n) : \\<sigma> ; eff\") auto\n\nlemma true_ty_elim[rule_format]: \n  \"\\<Gamma> \\<turnstile> (trm.Bool True) : \\<sigma> ; eff \\<Longrightarrow> \\<sigma> = ty.TT \\<and> eff = TT \\<and> valid \\<Gamma> \"\nby (ind_cases \"\\<Gamma> \\<turnstile> (trm.Bool True) : \\<sigma> ; eff\") \n (auto simp add: trm.inject)\n\nlemma bool_ty_elim[rule_format]: \n  \"\\<Gamma> \\<turnstile> (trm.Bool b) : \\<sigma> ; eff \\<Longrightarrow>  (\\<sigma> = ty.TT \\<or> \\<sigma> = ty.FF) \\<and> valid \\<Gamma> \"\napply (ind_cases \"\\<Gamma> \\<turnstile> (trm.Bool b) : \\<sigma> ; eff\")\napply (auto simp add: trm.inject)\ndone\n\nlemma bi_ty_elim[rule_format]: \n  \"\\<Gamma> \\<turnstile> (BI b) : \\<sigma> ; eff \\<Longrightarrow> eff = TT \\<and> \\<sigma> = \\<Delta>\\<^isub>\\<tau> b \\<and> valid \\<Gamma>\"\napply (ind_cases \"\\<Gamma> \\<turnstile> (BI b) : \\<sigma> ; eff\")\napply (auto simp add: trm.inject)\ndone\n\ninductive_cases bool_sub_int: \"\\<turnstile> BoolTy <: ty.Int\"\ninductive_cases tt_sub_int: \"\\<turnstile> ty.TT <: ty.Int\"\ninductive_cases ff_sub_int: \"\\<turnstile> ty.FF <: ty.Int\"\nthm bool_sub_int\ninductive_cases arr_sub_int: \"\\<turnstile> A\\<rightarrow>B:L <: ty.Int\"\ninductive_cases int_sub_tt: \"\\<turnstile> ty.Int <: ty.TT\"\ninductive_cases int_sub_ff: \"\\<turnstile> ty.Int <: ty.FF\"\ninductive_cases arr_sub_tt: \"\\<turnstile> A\\<rightarrow>B:L <: ty.TT\"\ninductive_cases arr_sub_ff: \"\\<turnstile> A\\<rightarrow>B:L <: ty.FF\"\ninductive_cases int_sub_bool_cases: \"\\<turnstile> ty.Int <: Union [ty.TT, ty.FF]\"\ninductive_cases arr_sub_bool_cases: \"\\<turnstile> A\\<rightarrow>B:L <: Union [ty.TT, ty.FF]\"\n\ndeclare BoolTy_def[simp]\n\n\nlemma int_sub_bool:\n  assumes \"\\<turnstile> ty.Int <: BoolTy\"\n  shows \"P\"\n  using prems\nproof -\n  have \"\\<turnstile> ty.Int <: ty.TT \\<or> \\<turnstile> ty.Int <: ty.FF\" using prems int_sub_bool_cases by auto\n  thus ?thesis using int_sub_ff int_sub_tt by auto\nqed\n\nlemma arr_sub_bool:\n  assumes \"\\<turnstile> A\\<rightarrow>B:L <: BoolTy\"\n  shows \"P\"\n  using prems\nproof -\n  have \"\\<turnstile> A\\<rightarrow>B:L <: ty.TT \\<or> \\<turnstile> A\\<rightarrow>B:L <: ty.FF\" using prems arr_sub_bool_cases[of A B L] by auto\n  thus ?thesis using arr_sub_ff[of A B L] arr_sub_tt[of A B L] by auto\nqed\n\nthm int_sub_bool\n\ninductive_cases abs_ty_elim2[consumes 1, case_names 1]: \"\\<Gamma> \\<turnstile> Lam[x:S].b : T ; eff\"\n\nlemma int_value:\n  assumes a:\"v : values\"\n  and b:\"\\<Gamma> \\<turnstile> v : T ; F\"\n  and c:\"\\<turnstile> T <: ty.Int\"\n  shows \"EX n. v = (Num n)\"\n  using prems\nproof (induct rule: values.induct)\n  case num_value thus ?case by auto\nnext\n  case (bool_value b)\n  hence \"T = ty.TT \\<or> T = ty.FF\" using bool_ty_elim by auto\n  thus ?case using bool_value tt_sub_int ff_sub_int by auto\nnext\n  case (abs_value b S x)\n  thus ?case using arr_sub_int\n    by (induct rule: abs_ty_elim2) auto\nnext\n  case (bi_value b)\n  thus ?case using bi_ty_elim[of \\<Gamma> b T F] using arr_sub_int by (nominal_induct b rule: builtin.induct) auto\nqed\n\n  \nlemma bool_value:\n  assumes a:\"v : values\"\n  and b:\"\\<Gamma> \\<turnstile> v : T ; F\"\n  and c:\"\\<turnstile> T <: BoolTy\"\n  shows \"EX b. v = (Bool b)\"\n  using prems\nproof (induct rule: values.induct)\n  case num_value thus ?case using num_ty_elim[of \\<Gamma> _ T F] int_sub_bool by auto\nnext\n  case (bool_value b) thus ?case by auto\nnext\n  case (abs_value b S x)\n  thus ?case using arr_sub_bool \n    by (induct rule: abs_ty_elim2) auto\nnext\n  case (bi_value b)\n  thus ?case using bi_ty_elim[of \\<Gamma> b T F] using arr_sub_bool by (nominal_induct b rule: builtin.induct) auto\nqed\n\nlemma value_int_ty:\n  assumes a:\"\\<Gamma> \\<turnstile> e : ty.Int ; eff\"\n  and b: \"e : values\"\n  shows \"EX n. e = (Num n)\"\n  using b a int_value[of e _ ty.Int] by auto\n\nlemma value_bool_ty:\n  assumes a:\"\\<Gamma> \\<turnstile> e : BoolTy ; eff\"\n  and b: \"e : values\"\n  shows \"EX b. e = (Bool b)\"\n  using b a bool_value[OF b a] by auto\n\nlemma typing_bi:\n  assumes a:\"\\<Gamma> \\<turnstile> (BI b) : t ; eff\"\n  shows \"t = \\<Delta>\\<^isub>\\<tau> b\"\n  using a bi_typing_cases[of \\<Gamma> b t eff \"t = \\<Delta>\\<^isub>\\<tau> b\"]\n  by (simp add: trm.inject)  \n\ninductive_cases arr_sub_arr_cases:\"\\<turnstile> A1 \\<rightarrow> A2 : L <: B1 \\<rightarrow> B2 : L'\"\n\nlemma typed_prim_reduce:\n  assumes a:\"\\<Gamma> \\<turnstile> (BI b) : U ; eff\" and b:\"\\<Gamma> \\<turnstile> v : T ; eff'\" and c:\"v : values\"\n  and sub:\"\\<turnstile> T <: T0\" and d: \"\\<turnstile> U <:  T0 \\<rightarrow> T1 : le\" \n  shows \"EX v'. \\<Delta> b v = Some v'\"\n  using a b c d sub\n  proof (nominal_induct b rule: builtin.induct)\n    case Add1\n    have \"U = \\<Delta>\\<^isub>\\<tau> Add1\" using Add1 typing_bi[of \\<Gamma> Add1 \"U\" eff] by simp\n    hence \"U = ty.Int \\<rightarrow> ty.Int : latent_eff.NE\" by auto\n    hence \"\\<turnstile> T <: ty.Int \" and \"le = latent_eff.NE\" using sub d arr_sub_arr_cases[of ty.Int ty.Int latent_eff.NE T0 T1 le] \n      by auto\n    hence \"EX n. v = (Num n)\" using c b int_value by auto\n    then obtain n where \"v = (Num n)\" by auto\n    thus ?case by (auto simp add: \\<Delta>.simps)\n  next\n    case Nott show ?case using `v : values` Nott\n      by (induct v rule: values.induct)  auto\n  next\n    case NumberP thus ?case by auto\n  next\n    case BooleanP thus ?case by auto\n  next\n    case ProcP thus ?case by auto\n  qed\n\n\ntext {* Progress together with necessary lemmas *}\n\n(* first some lemmas about decomposing various kinds of syntax *)\n\nlemma if_decomp:\n  assumes b:\"closed tst \\<Longrightarrow> (\\<exists>E L R. tst = E L \\<and> E \\<in> ctxt \\<and> L \\<hookrightarrow> R) \\<or> tst : values\"\n  and c:\"closed (Iff tst thn els)\"\n  shows \"(EX E L R. (Iff tst thn els) = E L \\<and> E : ctxt \\<and> L \\<hookrightarrow> R) \\<or> (Iff tst thn els) : values\"\n  proof -\n    {\n      assume \"tst : values\"\n      hence \"EX E L R. Iff tst thn els = E L \\<and> E : ctxt \\<and> (L \\<hookrightarrow> R)\"\n        using if_val_reduces[of tst thn els] ex_help[of \"Iff tst thn els\" \"(%t. t)\"] by auto\n    }\n    moreover\n    {\n      assume asm:\"~ tst : values\"\n      have cl:\"closed tst\" using `closed (Iff tst thn els)` by (auto simp add: closed_def trm.supp)\n      hence ih:\"\\<exists>E t t'. tst = E t \\<and> E \\<in> ctxt \\<and> t \\<hookrightarrow> t'\" using b asm by auto\n      hence \"\\<exists>E t t' . Iff tst thn els = E t \\<and> E \\<in> ctxt \\<and> t \\<hookrightarrow> t'\"\n        using reduce_in_ctxt[of \"(%t . (Iff t thn els))\"] ih by auto\n    }\n    ultimately show ?thesis by auto\n  qed\n  \n\ninductive_cases tt_sub_arr_cases: \"\\<turnstile> ty.TT <:A1 \\<rightarrow> A2 : L\"\ninductive_cases ff_sub_arr_cases: \"\\<turnstile> ty.FF <:A1 \\<rightarrow> A2 : L\"\ninductive_cases num_sub_arr_cases: \"\\<turnstile> ty.Int <:A1 \\<rightarrow> A2 : L\"\n\nlemma app_decomp:\n  assumes a:\" G \\<turnstile> rator : U ; eff1\"\n  and a':\"\\<turnstile> U <: T0 \\<rightarrow> T1 : le\"\n  and aa:\" G \\<turnstile> rand : T ; eff\"\n  and b:\"closed rator \\<Longrightarrow> (\\<exists>E L R. rator = E L \\<and> E \\<in> ctxt \\<and> L \\<hookrightarrow> R) \\<or> rator \\<in> values\"\n  and bb:\"closed rand \\<Longrightarrow> (\\<exists>E L R. rand = E L \\<and> E \\<in> ctxt \\<and> L \\<hookrightarrow> R) \\<or> rand \\<in> values\"\n  and c:\"closed (App rator rand)\"\n  and sub:\"\\<turnstile> T <: T0\"\n  shows \"(EX E L R. (App rator rand) = E L \\<and> E : ctxt \\<and> L \\<hookrightarrow> R) \\<or> (App rator rand) : values\"\n  proof -\n    have well_typed:\"G \\<turnstile> (App rator rand) : T1 ; eff.NE\"\n      using T_App[of G rator U eff1 T0 T1 le rand T eff] a a' aa sub by auto\n    have \"closed rator\" using c by (auto simp add: closed_def trm.supp)\n    hence ih1:\"(\\<exists>E L R. rator = E L \\<and> E \\<in> ctxt \\<and> L \\<hookrightarrow> R) \\<or> rator \\<in> values\" using b by simp\n    have \"closed rand\" using c by (auto simp add: closed_def trm.supp)\n    hence ih2:\"(\\<exists>E L R. rand = E L \\<and> E \\<in> ctxt \\<and> L \\<hookrightarrow> R) \\<or> rand \\<in> values\" using bb by simp\n    {\n      assume asm1:\"rator \\<in> values\" and asm2:\"rand \\<in> values\"\n      hence \"(EX E L R. (App rator rand) = E L \\<and> E : ctxt \\<and> L \\<hookrightarrow> R)\" using asm1 a aa a' sub well_typed\n        proof (nominal_induct avoiding: rand rule: values.strong_induct )\n          case (abs_value x t b)\n          let ?E = \"(%t. t)\"\n          let ?L = \"App (Abs x b t) rand\"\n          have \"?L \\<hookrightarrow> (b[x::=rand])\" by (rule e_beta)\n          thus ?case using ex_help[of ?L ?E ?L] by auto\n        next\n          case (bool_value b)\n\t  hence \"U = ty.TT \\<or> U = ty.FF\" using true_ty_elim false_ty_elim by (cases b) auto\n\t  thus ?case using tt_sub_arr_cases[of T0 T1 le] ff_sub_arr_cases[of T0 T1 le] `\\<turnstile> U <: T0 \\<rightarrow> T1 : le` by blast\n        next\n          case (num_value b)\n\t  hence \"U = ty.Int\" using num_ty_elim by auto\n\t  thus ?case using num_sub_arr_cases[of T0 T1 le] num_value by auto\n        next\n          case (bi_value b) \n          let ?E = \"(%t. t)\"\n          let ?L = \"App ((BI b)) rand\"\n          have h:\"\\<And>v. (\\<Delta> b rand) = (Some v)  \\<Longrightarrow> App ((BI b)) rand \\<hookrightarrow> v\" using bi_value by auto\n          have \"EX v . (\\<Delta> b rand) = (Some v)\" using bi_value typed_prim_reduce[of G b U]  by auto\n          then obtain v' where \"(\\<Delta> b rand) = (Some v')\" by auto\n          then show ?case using h[of v'] ex_help[of ?L ?E] by auto\n        qed\n    }\n    moreover\n    {\n      assume asm1:\"rator \\<in> values\" and asm2:\"rand \\<notin> values\"\n      have \"\\<exists>E t t' . App rator rand = E t \\<and> E \\<in> ctxt \\<and> t \\<hookrightarrow> t'\"\n\tusing asm1 asm2 reduce_in_ctxt[of \"(%t . (App rator t))\"] ih2 by auto\n    }\n    moreover\n    {\n      assume asm:\"rator \\<notin> values\"\n      have \"\\<exists>E t t' . App rator rand = E t \\<and> E \\<in> ctxt \\<and> t \\<hookrightarrow> t'\"\n\tusing asm reduce_in_ctxt[of \"(%t . (App t rand))\"] ih1 by auto\n    }  \n    ultimately show ?thesis by auto\n  qed\n\n\n(* then the main lemma, that every well typed term can be decomposed\n   into a context and a redex *)\n\nlemma decomposition:\n  assumes a:\"closed e\" and b:\"\\<Gamma> \\<turnstile> e : t ; eff\"\n  shows \"(EX E L R. e = E L \\<and> E : ctxt \\<and> L \\<hookrightarrow> R) \\<or> e : values\"\n  using b a\nproof (induct rule: typing.induct)\n  case T_Var\n  thus ?case using closed_def by (auto simp add: at_supp at_name_inst trm.supp) \nnext\n  case T_If\n  thus ?case using if_decomp by auto\nnext\n  case T_IfTrue\n  thus ?case using if_decomp by auto\nnext\n  case T_IfFalse\n  thus ?case using if_decomp by auto\nnext\n  case T_App\n  thus ?case using app_decomp by auto\nnext\n  case T_AppPred\n  thus ?case using app_decomp by auto\nnext\n  case T_AppPredTrue\n  thus ?case using app_decomp by auto\nnext\n  case T_AppPredFalse\n  thus ?case using app_decomp by auto\nqed (simp_all) (* The value cases are automatic *)\n\n(* Now we conclude progress *)\n\ntheorem progress:\n  assumes typed:\"\\<Gamma> \\<turnstile> e : t ; eff\" and cl:\"closed e\"\n  shows \"e : values \\<or> (EX e'. e \\<longrightarrow> e')\"\nproof (cases \"e : values\")\n  case False\n  hence \"(\\<exists>E L R. e = E L \\<and> E \\<in> ctxt \\<and> L \\<hookrightarrow> R)\" using decomposition[OF cl typed] by auto\n  thus ?thesis by auto\nqed (simp)\n\n(* Some useful lemmas for deriving facts from typing derivations *)\n\ninductive_cases app_ty_elim2[consumes 1, case_names 1 2 3 4]: \"\\<Gamma> \\<turnstile> App t1 t2 : \\<sigma> ; eff\"\nthm app_ty_elim2\ninductive_cases iff_ty_elim2[consumes 1, case_names 1 2 3]: \"\\<Gamma> \\<turnstile> Iff t1 t2 t3 : T ; eff\"\nthm abs_ty_elim2\n\n(* slow *)\nlemma app_ty_elim[rule_format]: \n  \"\\<Gamma> \\<turnstile> App t1 t2 : \\<sigma> ; eff \\<Longrightarrow> \n  \\<exists> T0 T0' T1 le eff' eff'' U. (\\<Gamma> \\<turnstile> t1 : U ; eff' \\<and> \\<Gamma> \\<turnstile> t2 : T0' ; eff'' \\<and> \\<turnstile> U <: T0 \\<rightarrow> T1 : le \\<and> \\<turnstile> T0' <: T0 \\<and> T1 = \\<sigma>)\"\n  apply (ind_cases \"\\<Gamma> \\<turnstile> App t1 t2 : \\<sigma> ; eff\")\n  apply (auto simp add: trm.inject ty.inject)\n  by metis+\n\nlemma abs_ty_elim_eff[rule_format]: \n  \"\\<lbrakk>\\<Gamma> \\<turnstile> Lam[a:T0].b : \\<sigma> ; eff\\<rbrakk> \\<Longrightarrow> eff = eff.TT\"\n  by (ind_cases \"\\<Gamma> \\<turnstile> Lam[a:T0].b : \\<sigma> ; eff\")\n     (auto simp add: trm.inject)\n\n\nlemma abs_ty_elim[rule_format]: \n  \"\\<lbrakk>\\<Gamma> \\<turnstile> Lam[a:T0].b : \\<sigma> ; eff ; a \\<sharp> \\<Gamma>\\<rbrakk> \\<Longrightarrow> \n  \\<exists> T1 eff' L S. ((a,T0)#\\<Gamma> \\<turnstile> b : T1 ; eff' \\<and> \\<sigma> = (T0 \\<rightarrow> T1 : L) \\<and> eff = eff.TT \\<and> ((eff' = TE S a \\<and> L = Latent S) \\<or> L = latent_eff.NE))\"\napply (ind_cases \"\\<Gamma> \\<turnstile> Lam[a:T0].b: \\<sigma> ; eff\")\napply(auto simp add: trm.distinct trm.inject alpha) \napply(drule_tac pi=\"[(a,x)]::name prm\" in typing.eqvt)\napply(auto)\napply(subgoal_tac \"([(a,x)]::name prm)\\<bullet>\\<Gamma> = \\<Gamma>\")(*A*)\napply(force simp add: calc_atm)\n(*A*)\napply(force intro!: pt_fresh_fresh[OF pt_name_inst, OF at_name_inst])\n\napply(drule_tac pi=\"[(a,x)]::name prm\" in typing.eqvt)\napply(auto)\napply(subgoal_tac \"([(a,x)]::name prm)\\<bullet>\\<Gamma> = \\<Gamma>\")(*A*)\napply(force simp add: calc_atm)\n(*A*)\napply(force intro!: pt_fresh_fresh[OF pt_name_inst, OF at_name_inst])\ndone\n\ninductive_cases abs_ty_cases[consumes 1, case_names 1 2]:\"\\<Gamma> \\<turnstile> Lam[a:T0].b: \\<sigma> ; eff\"\nthm abs_ty_cases\n\n(*\nlemma app_abs_ty_elim_eff[rule_format]: \n  \"\\<lbrakk>\\<Gamma> \\<turnstile> App (Abs x b T) t2 : \\<sigma> ; eff ; x \\<sharp> \\<Gamma>\\<rbrakk> \\<Longrightarrow> eff = eff.NE\"\n  proof (ind_cases \"\\<Gamma> \\<turnstile> App (Abs x b T) t2 : \\<sigma> ; eff\", auto simp add: trm.inject abs_ty_elim)\n    fix T0 S eff1 U \n    assume \"\\<Gamma> \\<turnstile> Lam [x:T].b : U ; eff1 \"\" \\<turnstile> U <: T0 \\<rightarrow> \\<sigma> : Latent S\" \"x \\<sharp> \\<Gamma>\"\n    then obtain T1 L where \"U = T \\<rightarrow> T1 : L\" using abs_ty_elim[of \\<Gamma> x b T \"U\" L] by auto\n    thus False using prems arr_sub_arr_cases[of T _ latent_eff.NE T0 \\<sigma> \"Latent S\"] by (auto simp add: ty.inject)\n  next\n    fix T0 S eff1 U\n    assume \"\\<Gamma> \\<turnstile> Lam [x:T].b : U ; eff1 \"\" \\<turnstile> U <: T0 \\<rightarrow> \\<sigma> : Latent S\" \"x \\<sharp> \\<Gamma>\"\n    then obtain T1 where \"U = T \\<rightarrow> T1 : latent_eff.NE\" using abs_ty_elim[of \\<Gamma> x b T \"U\"] by auto\n    thus False using prems arr_sub_arr_cases[of T _ latent_eff.NE T0 \\<sigma> \"Latent S\"] by (auto simp add: ty.inject)\n  next\n    fix T0 S eff1 U\n    assume \"\\<Gamma> \\<turnstile> Lam [x:T].b : U ; eff1 \"\" \\<turnstile> U <: T0 \\<rightarrow> \\<sigma> : Latent S\" \"x \\<sharp> \\<Gamma>\"\n    then obtain T1 where \"U = T \\<rightarrow> T1 : latent_eff.NE\" using abs_ty_elim[of \\<Gamma> x b T \"U\"] by auto\n    thus False using prems arr_sub_arr_cases[of T _ latent_eff.NE T0 \\<sigma> \"Latent S\"] by (auto simp add: ty.inject)\n  qed\n\n*)\nlemma if_ty_elim_weak[rule_format]: \n  \"\\<Gamma> \\<turnstile> Iff t1 t2 t3: \\<sigma> ; eff \\<Longrightarrow> \\<exists> T0 eff'. (\\<Gamma> \\<turnstile> t1 : T0 ; eff') \\<and> eff = NE\"\nby (ind_cases \"\\<Gamma> \\<turnstile> Iff t1 t2 t3: \\<sigma> ; eff\")\n   (auto simp add: trm.inject)\n\nlemma if_ty_elim[rule_format]: \n  \"\\<Gamma> \\<turnstile> Iff t1 t2 t3: \\<sigma> ; eff \\<Longrightarrow> \n  (\\<exists> T1 T2 T3 F1 F2 F3. (\\<Gamma> \\<turnstile> t1 : T1 ; F1) \\<and> \\<Gamma> |+ F1 \\<turnstile> t2 : T2 ; F2 \\<and> \\<Gamma> |- F1 \\<turnstile> t3 : T3 ; F3 \\<and> \\<turnstile> T2 <: \\<sigma>  \\<and> \\<turnstile> T3 <: \\<sigma> \\<and> eff = NE)\n  \\<or>\n  (\\<exists> T1 T3 F3. (\\<Gamma> \\<turnstile> t1 : T1 ; FF) \\<and> \\<Gamma> \\<turnstile> t3 : T3 ; F3 \\<and> \\<turnstile> T3 <: \\<sigma> \\<and> eff = NE)\n  \\<or>\n  (\\<exists> T1 T2 F2. (\\<Gamma> \\<turnstile> t1 : T1 ; TT) \\<and> \\<Gamma> \\<turnstile> t2 : T2 ; F2 \\<and> \\<turnstile> T2 <: \\<sigma>  \\<and> eff = NE)\"\nproof (ind_cases \"\\<Gamma> \\<turnstile> Iff t1 t2 t3: \\<sigma> ; eff\")\n  fix e1 T1 eff1 e2 T2 eff2 e3 T3 eff3\n  assume \"Iff t1 t2 t3 = Iff e1 e2 e3\"\" eff = eff.NE\"\"  \\<Gamma> \\<turnstile> e1 : T1 ; eff1\"\"  env_plus eff1 \\<Gamma> \\<turnstile> e2 : T2 ; eff2 \"\n    \"env_minus eff1 \\<Gamma> \\<turnstile> e3 : T3 ; eff3\"\" \\<turnstile> T2 <: \\<sigma>\"\" \\<turnstile> T3 <: \\<sigma>\"\n  hence A:\"t1 = e1\" \"t2 = e2\" \"t3 = e3\" using trm.inject by auto\n  thus ?thesis using prems by blast \nnext\n  fix e1 T1 e2 T2 effa e3\n  assume \"Iff t1 t2 t3 = Iff e1 e2 e3\"\" eff = eff.NE\"\"  \\<Gamma> \\<turnstile> e1 : T1 ; TT \"\"  \\<Gamma> \\<turnstile> e2 : T2 ; effa \"\" \\<turnstile> T2 <: \\<sigma>\"\n  thus ?thesis by (auto simp add: trm.inject)\nnext\n  fix e1 T1 e2 T3 effa e3\n  assume \"Iff t1 t2 t3 = Iff e1 e2 e3\"\" eff = eff.NE\"\"  \\<Gamma> \\<turnstile> e1 : T1 ; FF \"\"  \\<Gamma> \\<turnstile> e3 : T3 ; effa \"\" \\<turnstile> T3 <: \\<sigma>\"\n  thus ?thesis by (auto simp add: trm.inject)\nqed\n\ninductive_cases iff_false_ty_cases:  \"\\<Gamma> \\<turnstile> Iff (trm.Bool False) t2 t3: \\<sigma> ; eff\"\ninductive_cases ff_eff_cases: \"\\<Gamma> \\<turnstile> e : T; FF\"\ninductive_cases tt_eff_cases: \"\\<Gamma> \\<turnstile> e : T; TT\"\ninductive_cases ne_eff_cases: \"\\<Gamma> \\<turnstile> e : T; NE\"\n\n\nlemma if_true_ty_elim[rule_format]: \n   \"\\<lbrakk>\\<Gamma> \\<turnstile> Iff v t2 t3: \\<sigma> ; eff ; v : values; v ~= Bool False\\<rbrakk> \\<Longrightarrow>\n  \\<exists> T0 eff'. ((\\<Gamma> \\<turnstile> t2 : T0 ; eff') \\<and> \\<turnstile> T0 <: \\<sigma> \\<and> eff = NE)\"  \nproof (ind_cases \"\\<Gamma> \\<turnstile> Iff (v) t2 t3: \\<sigma> ; eff\")\n  fix eff1 eff2 T1 T2 e1 e2 e3 \n  assume \"v : values\" \"env_plus eff1 \\<Gamma> \\<turnstile> e2 : T2 ; eff2\" \"Iff v t2 t3 = Iff e1 e2 e3\" \"\\<turnstile> T2 <: \\<sigma>\" \n    \"\\<Gamma> \\<turnstile> e1 : T1 ; eff1\" \"eff = NE\"\n  have \"\\<Gamma> \\<turnstile> v : T1 ; eff1\" using prems by (simp add: trm.inject)\n  have \"eff1 = eff.NE \\<or> eff1 = FF \\<or> eff1 = TT\" using `v : values` `\\<Gamma> \\<turnstile> v : T1 ; eff1`\n  proof (induct rule: values.induct)\n    case (abs_value b T x) thus ?case using abs_value abs_ty_elim_eff by auto\n  next\n    case (num_value n) thus ?case using num_ty_elim by auto\n  next\n    case (bool_value n) thus ?case using false_ty_elim true_ty_elim by (cases n) auto\n  next\n    case bi_value thus ?case using bi_ty_elim by auto\n  qed\n  hence \"env_plus eff1 \\<Gamma> = \\<Gamma>\" by auto\n  hence \"\\<Gamma> \\<turnstile> e2 : T2 ; eff2 \\<and> \\<turnstile> T2 <: \\<sigma>\" using prems by auto\n  thus ?thesis using prems by (auto simp add: trm.inject)\nnext\n  fix e1 T2 e2 e3 effa\n  assume \"Iff v t2 t3 = Iff e1 e2 e3\"  \"\\<Gamma> \\<turnstile> e2 : T2 ; effa\"  \"\\<turnstile> T2 <: \\<sigma>\" \"eff = NE\"\n  thus ?thesis by (auto simp add: trm.inject)\nnext\n  fix e1 T1 e3 T3 effa e2\n  assume \"v : values\" \"v \\<noteq> trm.Bool False\" \"Iff v t2 t3 = Iff e1 e2 e3\" \"\\<Gamma> \\<turnstile> e1 : T1 ; FF\" \"eff = NE\"\n  have \"v = e1\" using prems trm.inject by auto\n  hence tv:\"\\<Gamma> \\<turnstile> v : T1 ; FF\" by simp\n  have \"v = Bool False\" using `v : values` tv\n  proof (induct v rule: values.induct)\n    case (abs_value x T b) thus ?case using abs_ty_elim_eff[of \\<Gamma> x b T T1 FF] by auto\n  next\n    case (num_value n) thus ?case using num_ty_elim[of _ _ _ FF] by auto\n  next\n    case (bool_value n) thus ?case using true_ty_elim[of _ _ FF] by (cases n) auto\n  next\n    case bi_value thus ?case using bi_ty_elim[of _ _ _ FF] by auto\n  qed\n  show ?thesis using `v = Bool False` `v ~= Bool False` by auto\nqed \n\n\nlemma if_false_ty_elim[rule_format]: \n   \"\\<Gamma> \\<turnstile> Iff (trm.Bool False) t2 t3: \\<sigma> ; eff \\<Longrightarrow>\n  \\<exists> T0 eff'. ((\\<Gamma> \\<turnstile> t3 : T0 ; eff') \\<and> \\<turnstile> T0 <: \\<sigma> \\<and> eff = eff.NE)\"  \nproof (ind_cases \"\\<Gamma> \\<turnstile> Iff (trm.Bool False) t2 t3: \\<sigma> ; eff\")\n  fix e1 e2 e3 T1\n  assume \"Iff (trm.Bool False) t2 t3 = Iff e1 e2 e3\" and \"\\<Gamma> \\<turnstile> e1 : T1 ; TT\"\n  hence \"\\<Gamma> \\<turnstile> (trm.Bool False) : T1 ; TT\" by (simp add: trm.inject)\n  hence \"TT = FF\" using false_ty_elim[of \\<Gamma> T1 TT] by simp\n  thus ?thesis by (simp)\nnext\n  fix e1 e2 e3 T1 T3 effa\n  assume \"Iff (trm.Bool False) t2 t3 = Iff e1 e2 e3\" and \" eff = eff.NE\"and\" \\<Gamma> \\<turnstile> e1 : T1 ; FF\" and \"  \\<Gamma> \\<turnstile> e3 : T3 ; effa\"and \" \\<turnstile> T3 <: \\<sigma>\"\n  thus ?thesis by (auto simp add: trm.inject)\nnext\n  fix e1 e2 e3 T1 T3 eff1 eff3\n  assume \"Iff (trm.Bool False) t2 t3 = Iff e1 e2 e3\" and \"eff = eff.NE\" \n    and f:\"\\<Gamma> \\<turnstile> e1 : T1 ; eff1\" and g:\"env_minus eff1 \\<Gamma> \\<turnstile> e3 : T3 ; eff3\" and \"\\<turnstile> T3 <: \\<sigma>\"\n  hence \"e1 = Bool False\" and \"t3 = e3\" by (auto simp add: trm.inject)\n  hence \"eff1 = FF\" using f false_ty_elim by auto\n  hence \"env_minus eff1 \\<Gamma> = \\<Gamma>\" by simp\n  hence \"\\<Gamma> \\<turnstile> e3 : T3 ; eff3\" using g by simp\n  thus ?thesis using `t3 = e3` `\\<turnstile> T3 <: \\<sigma>` `eff = eff.NE` by auto\nqed \n\nlemma var_ty_elim:\n  \"\\<Gamma> \\<turnstile> Var v : \\<sigma> ; eff \\<Longrightarrow> (v,\\<sigma>) : set \\<Gamma> \\<and> eff = VE v \\<and> valid \\<Gamma>\"\n  by (ind_cases \"\\<Gamma> \\<turnstile> Var v : \\<sigma> ; eff\")\n     (auto simp add: trm.inject)\n\ninductive_cases app_ty_ff:\"\\<Gamma> \\<turnstile> App e arg : T' ; FF\"\n  \nlemma app_ty_ff_elim:\n  \"\\<Gamma> \\<turnstile> App rator rand : T ; FF \\<Longrightarrow>\n  EX S T0 le F1 T0' F2 U.  \\<Gamma> \\<turnstile> rator : U ; F1 \\<and> \\<Gamma> \\<turnstile> rand : T0' ; F2 \\<and> \\<turnstile> T0' <: T0 \\<and> \\<turnstile> U <: T0 \\<rightarrow> T : le \\<and>\n  le = Latent S \\<and> (~ (\\<turnstile> T0' <: S)) \\<and> rand : values \\<and> closed rand\"\n  proof (ind_cases \"\\<Gamma> \\<turnstile> App rator rand : T ; FF\")\n    fix e1 T0 S eff1 e2 Ta eff2 U\n    assume \"App rator rand = App e1 e2 \"\" \\<Gamma> \\<turnstile> e1 : U ; eff1 \" \"\\<turnstile> U <:  T0 \\<rightarrow> T : Latent S\"\n      \"\\<Gamma> \\<turnstile> e2 : Ta ; eff2 \"\"\\<turnstile> Ta <: T0\"\"~ (\\<turnstile> Ta <: S)\" \"e2 : values\" \"closed e2\"\n    have a:\" \\<Gamma> \\<turnstile> rator : U ; eff1 \" using prems trm.inject by auto\n    have b:\"\\<Gamma> \\<turnstile> rand : Ta ; eff2\"  using prems trm.inject by auto\n    have c:\"rand : values\" \"closed rand\" using prems trm.inject by auto\n    from a b c prems show ?thesis by blast\n  qed\n  \nlemma app_ty_tt_elim:\n  \"\\<Gamma> \\<turnstile> App rator rand : T ; TT \\<Longrightarrow>\n  EX S T0 le F1 T0' F2 U. \\<Gamma> \\<turnstile> rator : U ; F1 \\<and> \\<Gamma> \\<turnstile> rand : T0' ; F2 \\<and> \\<turnstile> T0' <: T0 \\<and> \\<turnstile> U <: T0 \\<rightarrow> T : le \n  \\<and> le = Latent S \\<and> \\<turnstile> T0' <: S \"\n  proof (ind_cases \"\\<Gamma> \\<turnstile> App rator rand : T ; TT\")\n    fix e1 T0 S eff1 e2 Ta eff2 U\n    assume \"App rator rand = App e1 e2 \"\" \\<Gamma> \\<turnstile> e1 : U ; eff1 \" \"\\<turnstile> U <: T0 \\<rightarrow> T : Latent S\"\n      \"\\<Gamma> \\<turnstile> e2 : Ta ; eff2 \"\"\\<turnstile> Ta <: T0\"\" \\<turnstile> Ta <: S\"\n    have a:\" \\<Gamma> \\<turnstile> rator : U ; eff1 \" using prems trm.inject by auto\n    have b:\"\\<Gamma> \\<turnstile> rand : Ta ; eff2\"  using prems trm.inject by auto\n    from a b prems show ?thesis by blast\n  qed\n\ntext {* values don't have union types *}\n\nlemma value_simple_type:\n  assumes A:\"\\<Gamma> \\<turnstile> v : T ; F\" and B:\"v : values\"\n  shows \"simple_ty T\"\nusing B A\nproof (nominal_induct v avoiding: \\<Gamma> rule: values.strong_induct)\n  case (bi_value b) thus ?case using bi_ty_elim[of \\<Gamma> b T F]\n    by (nominal_induct b rule: builtin.induct)  \n       (auto simp add: trm.inject)\nnext\n  case num_value thus ?case using num_ty_elim[OF num_value] by auto\nnext\n  case bool_value thus ?case using bool_ty_elim[OF bool_value] by auto\nnext\n  case (abs_value a T' b \\<Gamma>') thus ?case using abs_ty_elim[of \\<Gamma>' a b T' T F] by auto\nqed\n\ntext {* lemmas about the effects of closed terms *}\n\nlemma ve_not_closed:\n  \"\\<Gamma> \\<turnstile> e : T ; eff.VE x \\<Longrightarrow>\n  x : supp e\"\n  by (ind_cases \"\\<Gamma> \\<turnstile> e : T ; eff.VE x\")\n     (auto simp add: eff.inject trm.supp at_supp supp_atm)\n\nlemma te_not_closed:\n  \"\\<Gamma> \\<turnstile> e : T ; eff.TE T' x \\<Longrightarrow>\n  x : supp e\"\n  proof (ind_cases \"\\<Gamma> \\<turnstile> e : T ; eff.TE T' x\")\n    fix e1 T0 S eff1 e2 Ta xa\n    assume \"e = App e1 e2\" \"TE T' x = TE S xa\" \"\\<Gamma> \\<turnstile> e2 : Ta ; VE xa\"\n    have \"x = xa\" using prems eff.inject by auto\n    hence \"\\<Gamma> \\<turnstile> e2 : Ta ; VE x\" using prems eff.inject by auto\n    hence \"x : supp e2\" using ve_not_closed by auto\n    thus \"x : supp e\" using prems trm.supp by auto\n  qed\n\nlemma closed_eff:\n  assumes \"closed e\" and \"\\<Gamma> \\<turnstile> e : T ; eff\"\n  shows \"simple_eff eff\"\nusing prems\nproof (nominal_induct eff rule: eff.induct)\n  case (VE name) thus ?case using ve_not_closed[of _ e _ name] closed_def by auto\nnext\n  case (TE _ name) thus ?case using te_not_closed[of _ e _ _ name] closed_def by auto\nqed (auto)\n\nlemma closed_eff_below_NE:\n  assumes \"closed e\" and \"\\<Gamma> \\<turnstile> e : T ; eff\"\n  shows \"\\<turnstile> eff <e: eff.NE\"\n  using closed_eff simple_eff_below_ne prems by auto\n\ninductive_cases const_ty_int_case: \"\\<Gamma> \\<turnstile> (Num n) : ty.Int ; eff\"\ninductive_cases trm_ty_int_case: \"\\<Gamma> \\<turnstile> e : ty.Int ; eff\"\ninductive_cases const_ty_bool_case: \"\\<Gamma> \\<turnstile> (Bool b) : BoolTy ; eff\"\n\nlemma add1_eff_ne:\n  \"\\<Gamma> \\<turnstile> (App (BI Add1) v) :  T1 ; eff1 \\<Longrightarrow> eff1 = eff.NE\"\nproof (ind_cases \" \\<Gamma> \\<turnstile> (App (BI Add1) v) :  T1 ; eff1\")\n  assume \"eff1 = eff.NE\" thus ?thesis by simp\nnext\n  fix T0 T1 S eff1a e1 e2 U\n  assume \"\\<Gamma> \\<turnstile> e1 : U ; eff1a\" \"App (BI Add1) v = App e1 e2\" \"\\<turnstile> U <: T0 \\<rightarrow> T1 : Latent S\"\n  hence \"\\<Gamma> \\<turnstile> (BI Add1) : U ; eff1a\" by (simp add: trm.inject)\n  hence \"\\<Delta>\\<^isub>\\<tau> Add1 = U\" using type_add1_case[of \\<Gamma> \"U\"] by (auto simp add: trm.inject)\n  hence \"\\<dots> = ty.Int \\<rightarrow> ty.Int : latent_eff.NE\" by auto\n  thus ?thesis using prems arr_sub_arr_cases[of ty.Int ty.Int latent_eff.NE] by (auto simp add: ty.inject)\nnext\n  fix T0 T1 S eff1a e1 e2 U\n  assume \"\\<Gamma> \\<turnstile> e1 : U ; eff1a\" \"App (BI Add1) v = App e1 e2\" \"\\<turnstile> U <: T0 \\<rightarrow> T1 : Latent S\"\n  hence \"\\<Gamma> \\<turnstile> (BI Add1) : U ; eff1a\" by (simp add: trm.inject)\n  hence \"\\<Delta>\\<^isub>\\<tau> Add1 = U\" using type_add1_case[of \\<Gamma> \"U\"] by (auto simp add: trm.inject)\n  hence \"\\<dots> = ty.Int \\<rightarrow> ty.Int : latent_eff.NE\" by auto\n  thus ?thesis using prems arr_sub_arr_cases[of ty.Int ty.Int latent_eff.NE] by (auto simp add: ty.inject)\nnext\n  fix T0 T1 S eff1a e1 e2 U\n  assume \"\\<Gamma> \\<turnstile> e1 : U ; eff1a\" \"App (BI Add1) v = App e1 e2\" \"\\<turnstile> U <: T0 \\<rightarrow> T1 : Latent S\"\n  hence \"\\<Gamma> \\<turnstile> (BI Add1) : U ; eff1a\" by (simp add: trm.inject)\n  hence \"\\<Delta>\\<^isub>\\<tau> Add1 = U\" using type_add1_case[of \\<Gamma> \"U\"] by (auto simp add: trm.inject)\n  hence \"\\<dots> = ty.Int \\<rightarrow> ty.Int : latent_eff.NE\" by auto\n  thus ?thesis using prems arr_sub_arr_cases[of ty.Int ty.Int latent_eff.NE] by (auto simp add: ty.inject)\nqed\n\ninductive_cases type_nott_case: \"\\<Gamma> \\<turnstile> (BI Nott) : t ; e\"\n\nlemma nott_eff_ne:\n  \"\\<Gamma> \\<turnstile> (App (BI Nott) v) :  T1 ; eff1 \\<Longrightarrow> eff1 = eff.NE\"\nproof (ind_cases \" \\<Gamma> \\<turnstile> (App (BI Nott) v) :  T1 ; eff1\")\n  assume \"eff1 = eff.NE\" thus ?thesis by simp\nnext\n  fix T0 T1 S eff1a e1 e2 U\n  assume \"\\<Gamma> \\<turnstile> e1 : U ; eff1a\" \"App (BI Nott) v = App e1 e2\" \"\\<turnstile> U <: T0 \\<rightarrow> T1 : Latent S\"\n  hence \"\\<Gamma> \\<turnstile> (BI Nott) : U ; eff1a\" by (simp add: trm.inject)\n  hence \"\\<Delta>\\<^isub>\\<tau> Nott = U\" using type_nott_case[of \\<Gamma> \"U\"] by (auto simp add: trm.inject)\n  hence \"\\<dots> = Top \\<rightarrow> BoolTy : latent_eff.NE\" by auto\n  thus ?thesis using prems arr_sub_arr_cases[of Top BoolTy latent_eff.NE] by (auto simp add: ty.inject)\nnext\n  fix T0 T1 S eff1a e1 e2 U\n  assume \"\\<Gamma> \\<turnstile> e1 : U ; eff1a\" \"App (BI Nott) v = App e1 e2\" \"\\<turnstile> U <: T0 \\<rightarrow> T1 : Latent S\"\n  hence \"\\<Gamma> \\<turnstile> (BI Nott) : U ; eff1a\" by (simp add: trm.inject)\n  hence \"\\<Delta>\\<^isub>\\<tau> Nott = U\" using type_nott_case[of \\<Gamma> \"U\"] by (auto simp add: trm.inject)\n  hence \"\\<dots> = Top \\<rightarrow> BoolTy : latent_eff.NE\" by auto\n  thus ?thesis using prems arr_sub_arr_cases[of Top BoolTy latent_eff.NE] by (auto simp add: ty.inject)\nnext\n  fix T0 T1 S eff1a e1 e2 U\n  assume \"\\<Gamma> \\<turnstile> e1 : U ; eff1a\" \"App (BI Nott) v = App e1 e2\" \"\\<turnstile> U <: T0 \\<rightarrow> T1 : Latent S\"\n  hence \"\\<Gamma> \\<turnstile> (BI Nott) : U ; eff1a\" by (simp add: trm.inject)\n  hence \"\\<Delta>\\<^isub>\\<tau> Nott = U\" using type_nott_case[of \\<Gamma> \"U\"] by (auto simp add: trm.inject)\n  hence \"\\<dots> = Top \\<rightarrow> BoolTy : latent_eff.NE\" by auto\n  thus ?thesis using prems arr_sub_arr_cases[of Top BoolTy latent_eff.NE] by (auto simp add: ty.inject)\nqed\n\ninductive_cases type_booleanp_case: \"\\<Gamma> \\<turnstile> (BI BooleanP) : t ; e\"\n\nlemma value_eff:\n  assumes \"v : values\" and \"\\<Gamma> \\<turnstile> v :  T ; eff\"\n  shows \"simple_eff eff\"\n  using prems\n  proof (induct v rule :values.induct)\n    case abs_value thus ?case using abs_ty_elim_eff by auto\n  next\n    case num_value thus ?case using num_ty_elim by auto\n  next\n    case (bool_value b) thus ?case using true_ty_elim false_ty_elim by (cases b) auto\n  next\n    case bi_value thus ?case using bi_ty_elim by auto\n  qed\n\nlemma booleanp_eff_simple:\n  \"\\<lbrakk>\\<Gamma> \\<turnstile> (App (BI BooleanP) v) :  T1 ; eff1 ; v : values\\<rbrakk> \\<Longrightarrow> simple_eff eff1\"\nproof (ind_cases \" \\<Gamma> \\<turnstile> (App (BI BooleanP) v) :  T1 ; eff1\")\n  fix T0 T1 S eff1a e1 e2 xa T\n  assume \"\\<Gamma> \\<turnstile> e2 : T ; VE xa\" \"App (BI BooleanP) v = App e1 e2\" \"v : values\"\n  hence \"VE xa = eff.NE \\<or> VE xa = eff.TT  \\<or> VE xa = eff.FF \" using value_eff[of v \\<Gamma> T \"VE xa\"] \n    by (auto simp add: trm.inject)\n  thus ?thesis using ty.distinct by auto\nqed (auto)\n\nlemma numberp_eff_simple:\n  \"\\<lbrakk>\\<Gamma> \\<turnstile> (App (BI NumberP) v) :  T1 ; eff1 ; v : values\\<rbrakk> \\<Longrightarrow> simple_eff eff1\"\nproof (ind_cases \" \\<Gamma> \\<turnstile> (App (BI NumberP) v) :  T1 ; eff1\")\n  fix T0 T1 S eff1a e1 e2 xa T\n  assume \"\\<Gamma> \\<turnstile> e2 : T ; VE xa\" \"App (BI NumberP) v = App e1 e2\" \"v : values\"\n  hence \"VE xa = eff.NE \\<or> VE xa = eff.TT  \\<or> VE xa = eff.FF \" using value_eff[of v \\<Gamma> T \"VE xa\"]\n    by (auto simp add: trm.inject)\n  thus ?thesis using ty.distinct by auto\nqed (auto)\n\nlemma procp_eff_simple:\n  \"\\<lbrakk>\\<Gamma> \\<turnstile> (App (BI ProcP) v) :  T1 ; eff1 ; v : values\\<rbrakk> \\<Longrightarrow> simple_eff eff1\"\nproof (ind_cases \" \\<Gamma> \\<turnstile> (App (BI ProcP) v) :  T1 ; eff1\")\n  fix T0 T1 S eff1a e1 e2 xa T\n  assume \"\\<Gamma> \\<turnstile> e2 : T ; VE xa\" \"App (BI ProcP) v = App e1 e2\" \"v : values\"\n  hence \"VE xa = eff.NE \\<or> VE xa = eff.TT  \\<or> VE xa = eff.FF \" using value_eff[of v \\<Gamma> T \"VE xa\"]\n    by (auto simp add: trm.inject)\n  thus ?thesis using ty.distinct by auto\nqed (auto)\n\n\ninductive_cases app_boolp_ff: \"\\<Gamma> \\<turnstile> (App (BI BooleanP) v) :  T1 ; FF\"\n\nlemma booleanp_FF_preserved:\n  assumes \"\\<Gamma> \\<turnstile> (App (BI BooleanP) v) :  T1 ; FF\" and \"v : values\" and \"\\<Delta> BooleanP v = Some u\"\n  shows \"u = Bool False\"\n  using `v : values` prems\n  proof (induct v rule: values.induct)\n    case (bool_value b)\n    let ?P = \"\\<Gamma> \\<turnstile> App (BI BooleanP) (trm.Bool b) : T1 ; FF\" \n    have \"?P ==> ?case\"\n      proof (ind_cases ?P)\n        fix S T e1 e2 T0 eff1 eff2 U\n        assume \"App (BI BooleanP) (trm.Bool b) = App e1 e2\"  \"\\<Gamma> \\<turnstile> e1 : U ; eff1 \"  \"\\<Gamma> \\<turnstile> e2 : T ; eff2\"\n          \"~ (\\<turnstile> T <: S)\" \"e2 : values\" \"\\<turnstile> U <:  T0 \\<rightarrow> T1 : Latent S\"\n        hence a:\"\\<Gamma> \\<turnstile> (BI BooleanP) : U ; eff1 \" using trm.inject by auto\n        from prems have b:\"\\<Gamma> \\<turnstile> Bool b : T ; eff2\" using trm.inject by auto\n\thave \"U = Top \\<rightarrow> BoolTy : Latent BoolTy\" using a bi_ty_elim[of \\<Gamma> BooleanP \"U\"] by auto\n\thence c:\"S = BoolTy\" using prems arr_sub_arr_cases[of Top BoolTy _ T0 T1 \"Latent S\"] latent_eff.inject by auto\n        from b have d:\"T = ty.TT \\<or> T = ty.FF\" using true_ty_elim false_ty_elim by (cases b) auto\n        from c d have \"\\<turnstile> T <: S\" by auto\n        thus ?thesis using prems by auto\n      qed\n    thus ?case using bool_value by auto\n  qed (auto)\n\nlemma typing_valid:\n  assumes \"\\<Gamma> \\<turnstile> e : T ; F\"\n  shows \"valid \\<Gamma>\"\nusing prems \nproof (induct)\n  case (T_Abs a \\<Gamma> T b T' F') thus ?case using valid_elim[of a T \\<Gamma>] by auto\nnext\n  case (T_AbsPred a \\<Gamma> T b T' F') thus ?case using valid_elim[of a T \\<Gamma>] by auto\nqed (auto)\n\n\nlemma booleanp_TT_preserved:\n  assumes \"\\<Gamma> \\<turnstile> (App (BI BooleanP) v) :  T1 ; TT\" and \"v : values\" and \"\\<Delta> BooleanP v = Some u\"\n  shows \"u = Bool True\"\n  proof -\n    note app_ty_tt_elim[of \\<Gamma> \"(BI BooleanP)\" v T1]\n    then obtain A1 U T0 T1 S eff1 eff2 where  \n      A:\"\\<Gamma> \\<turnstile> (BI BooleanP) : U ; eff1\"  \"\\<turnstile> U <: A1 \\<rightarrow> T1 : Latent S\" \"\\<Gamma> \\<turnstile> v : T0 ; eff2\" \"\\<turnstile> T0 <: A1\"  \"\\<turnstile> T0 <: S\"\n      using prems by auto\n    hence B:\"U = Top \\<rightarrow> BoolTy : Latent BoolTy \" using bi_ty_elim[of \\<Gamma> BooleanP U] by auto\n    hence C:\"\\<turnstile> T0 <: BoolTy\"      \n      using prems arr_sub_arr_cases[of Top BoolTy \"Latent BoolTy\" _ _ \"Latent S\"] latent_eff.inject A by auto\n    then obtain b where D:\"v = Bool b\" using A bool_value[of v \\<Gamma> T0] prems by auto\n    thus ?thesis using prems by auto\n  qed\n\nlemma booleanp_soundness_eff:\n  assumes \"\\<Gamma> \\<turnstile> App (BI BooleanP) v : T ; F\" and \"v : values\" and \"\\<Delta> BooleanP v = Some u\" and \"\\<Gamma> \\<turnstile> u : T' ; F'\"\n  shows \"\\<turnstile> F' <e: F\"\n  proof -\n    have cl:\"closed u\" using prems delta_closed[of BooleanP v u] by auto\n    hence se:\"simple_eff F'\" using prems closed_eff by auto\n    have or:\"simple_eff F\" using booleanp_eff_simple prems by auto\n    thus ?thesis using prems\n      proof (induct rule: simple_eff_cases)\n        case NE thus ?case using se simple_eff_below_ne by auto\n      next\n        case FF thus ?case using false_ty_elim[of \\<Gamma> T' F'] booleanp_FF_preserved by auto \n      next\n        case TT thus ?case using true_ty_elim[of \\<Gamma> T' F'] booleanp_TT_preserved by auto \n      qed\n    qed\n\ninductive_cases app_nump_ff: \"\\<Gamma> \\<turnstile> (App (BI NumberP) v) :  T1 ; FF\"\nthm app_nump_ff\n\nlemma numberp_FF_preserved:\n  assumes \"\\<Gamma> \\<turnstile> (App (BI NumberP) v) :  T1 ; FF\" and \"v : values\" and \"\\<Delta> NumberP v = Some u\"\n  shows \"u = Bool False\"\n  using `v : values` prems\n  proof (induct v rule: values.induct)\n    case (bool_value b) thus ?case by (cases b) auto\n  next\n    case (num_value b) \n    let ?P = \"\\<Gamma> \\<turnstile> App (BI NumberP) (trm.Num b) : T1 ; FF\" \n    have \"?P ==> ?case\"\n      proof (ind_cases ?P)\n        fix S T e1 e2 T0 eff1 eff2 U\n        assume \"App (BI NumberP) (trm.Num b) = App e1 e2\"  \"\\<Gamma> \\<turnstile> e1 : U ; eff1 \"  \"\\<Gamma> \\<turnstile> e2 : T ; eff2\"\n          \"~ (\\<turnstile> T <: S)\" \"e2 : values\" \"\\<turnstile> U <:  T0 \\<rightarrow> T1 : Latent S\"\n        hence a:\"\\<Gamma> \\<turnstile> (BI NumberP) : U ; eff1 \" using trm.inject by auto\n        from prems have b:\"\\<Gamma> \\<turnstile> Num b : T ; eff2\" using trm.inject by auto\n\thave \"U = Top \\<rightarrow> BoolTy : Latent ty.Int\" using a bi_ty_elim[of \\<Gamma> NumberP \"U\"] by auto\n\thence c:\"S = ty.Int\" using prems arr_sub_arr_cases[of Top _ _ T0 T1 \"Latent S\"] latent_eff.inject by auto\n        from b have d:\"T = ty.Int\" using num_ty_elim by auto\n        from c d have \"\\<turnstile> T <: S\" by auto\n        thus ?thesis using prems by auto\n      qed\n    thus ?case using num_value by auto\n  qed (auto)\n\nlemma numberp_TT_preserved:\n  assumes \"\\<Gamma> \\<turnstile> (App (BI NumberP) v) :  T1 ; TT\" and \"v : values\" and \"\\<Delta> NumberP v = Some u\"\n  shows \"u = Bool True\"\n  proof -\n    note app_ty_tt_elim[of \\<Gamma> \"(BI NumberP)\" v T1]\n    then obtain A1 U T0 T1 S eff1 eff2 where  \n      A:\"\\<Gamma> \\<turnstile> (BI NumberP) : U ; eff1\"  \"\\<turnstile> U <: A1 \\<rightarrow> T1 : Latent S\" \"\\<Gamma> \\<turnstile> v : T0 ; eff2\" \"\\<turnstile> T0 <: A1\"  \"\\<turnstile> T0 <: S\"\n      using prems by auto\n    hence B:\"U = Top \\<rightarrow> BoolTy : Latent ty.Int \" using bi_ty_elim[of \\<Gamma> NumberP U] by auto\n    hence C:\"\\<turnstile> T0 <: ty.Int\"      \n      using prems arr_sub_arr_cases[of Top BoolTy \"Latent ty.Int\" _ _ \"Latent S\"] latent_eff.inject A by auto\n    then obtain b where D:\"v = Num b\" using A int_value[of v \\<Gamma> T0] prems by auto\n    thus ?thesis using prems by auto\n  qed\n\nlemma numberp_soundness_eff:\n  assumes \"\\<Gamma> \\<turnstile> App (BI NumberP) v : T ; F\" and \"v : values\" and \"\\<Delta> NumberP v = Some u\" and \"\\<Gamma> \\<turnstile> u : T' ; F'\"\n  shows \"\\<turnstile> F' <e: F\"\n  proof -\n    have cl:\"closed u\" using prems delta_closed[of NumberP v u] by auto\n    hence se:\"simple_eff F'\" using prems closed_eff by auto\n    have or:\"simple_eff F\" using numberp_eff_simple prems by auto\n    thus ?thesis using prems\n      proof (induct rule: simple_eff_cases)\n        case NE thus ?case using se simple_eff_below_ne by auto\n      next\n        case FF thus ?case using false_ty_elim[of \\<Gamma> T' F'] numberp_FF_preserved by auto \n      next\n        case TT thus ?case using true_ty_elim[of \\<Gamma> T' F'] numberp_TT_preserved by auto \n      qed\n    qed\n\nlemma empty_un_bot:\n  fixes T :: ty\n  shows \"\\<turnstile> Union [] <: T\"\n  by auto\n\nlemma all_fun_ty_below:\n  fixes S T :: ty\n  shows \"\\<turnstile> S \\<rightarrow> T : F <: (Union []) \\<rightarrow> Top : latent_eff.NE\"\n  by (rule S_Fun) auto\n\ninductive_cases below_latent_ne_cases: \"\\<turnstile> S \\<rightarrow> T : F <: S' \\<rightarrow> T' : latent_eff.NE\"\nthm below_latent_ne_cases\n\ninductive_cases app_procp_ff: \"\\<Gamma> \\<turnstile> (App (BI ProcP) v) :  T1 ; FF\"\nthm app_nump_ff\nthm app_procp_ff\n\nlemma procp_FF_preserved:\n  assumes \"\\<Gamma> \\<turnstile> (App (BI ProcP) v) :  T1 ; FF\" and \"v : values\" and \"\\<Delta> ProcP v = Some u\"\n  shows \"u = Bool False\"\n  using `v : values` prems\n  proof (nominal_induct v avoiding: \\<Gamma> rule: values.strong_induct)\n    case (bool_value b) thus ?case by (cases b) auto \n  next\n    case (num_value b) thus ?case by auto \n  next\n    case (abs_value x t b) \n    let ?P = \"\\<Gamma> \\<turnstile> App (BI ProcP) (Lam[x:t].b) : T1 ; FF\" \n    have \"?P ==> ?case\"\n      proof (ind_cases ?P)\n        fix e1 U eff1 T0 S e2 T eff2\n        assume \"App (BI ProcP) (Lam [x:t].b) = App e1 e2 \"\"  \\<Gamma> \\<turnstile> e1 : U ; eff1 \"\" \\<turnstile> U <: T0 \\<rightarrow> T1 : Latent S \"\n\t  \"\\<Gamma> \\<turnstile> e2 : T ; eff2 \"\"  \\<turnstile> T <: T0 \"\" \\<not> \\<turnstile> T <: S \"\" e2 \\<in> values \"\" closed e2\"\n        hence a:\"\\<Gamma> \\<turnstile> (BI ProcP) : U ; eff1 \" using trm.inject by auto\n        from prems have b:\"\\<Gamma> \\<turnstile> Lam[x:t].b : T ; eff2\" using trm.inject by auto\n\thave \"U = Top \\<rightarrow> BoolTy : Latent (Union [] \\<rightarrow> Top : latent_eff.NE)\" using a bi_ty_elim[of \\<Gamma> ProcP \"U\"] by auto\n\thence c:\"S = Union [] \\<rightarrow> Top : latent_eff.NE\" using prems arr_sub_arr_cases[of Top _ _ T0 T1 \"Latent S\"] latent_eff.inject by auto\n        have \"EX A1 A2 L. T = A1 \\<rightarrow> A2 : L\" using abs_ty_elim[OF b `x \\<sharp> \\<Gamma>`] by auto\n\tthen obtain A1 A2 L where d:\"T = A1 \\<rightarrow> A2 : L\" by auto\n        from c d have \"\\<turnstile> T <: S\" using all_fun_ty_below by auto\n        thus ?thesis using prems by auto\n      qed\n    thus ?case using abs_value by auto\n  next\n    case (bi_value c)\n    let ?P = \"\\<Gamma> \\<turnstile> App (BI ProcP) (BI c) : T1 ; FF\" \n    have \"?P ==> ?case\"\n    proof (ind_cases ?P)\n      fix e1 U eff1 T0 S e2 T eff2\n      assume \"App (BI ProcP) (BI c) = App e1 e2 \"\"  \\<Gamma> \\<turnstile> e1 : U ; eff1 \"\" \\<turnstile> U <: T0 \\<rightarrow> T1 : Latent S \"\n\t\"\\<Gamma> \\<turnstile> e2 : T ; eff2 \"\"  \\<turnstile> T <: T0 \"\" \\<not> \\<turnstile> T <: S \"\" e2 \\<in> values \"\" closed e2\"\n      hence a:\"\\<Gamma> \\<turnstile> (BI ProcP) : U ; eff1 \" using trm.inject by auto\n      from prems have b:\"\\<Gamma> \\<turnstile> (BI c) : T ; eff2\" using trm.inject by auto\n      have \"U = Top \\<rightarrow> BoolTy : Latent (Union [] \\<rightarrow> Top : latent_eff.NE)\" using a bi_ty_elim[of \\<Gamma> ProcP \"U\"] by auto\n      hence c:\"S = Union [] \\<rightarrow> Top : latent_eff.NE\" using prems arr_sub_arr_cases[of Top _ _ T0 T1 \"Latent S\"] latent_eff.inject by auto\n      have b':\"T = \\<Delta>\\<^isub>\\<tau> c\" using bi_ty_elim[OF b] by auto\n      hence \"EX A1 A2 FA. T = A1 \\<rightarrow> A2 : FA\"  by (nominal_induct c rule: builtin.induct) auto\n      then obtain A1 A2 F where d:\"T = A1 \\<rightarrow> A2 : F\" by auto\n      hence \"\\<turnstile> T <: S\" using c d all_fun_ty_below by auto\n      thus ?thesis using prems by auto\n    qed\n    thus ?case using bi_value by auto\n  qed \n\nlemma proc_value:\n  assumes \"\\<Gamma> \\<turnstile> v : T ; F\"\n  and \"v : values\"\n  and \"\\<turnstile> T <:  (A1 \\<rightarrow> A2 : latent_eff.NE)\"\n  shows \"EX x b t. v = Lam[x:t].b \\<or> (EX c. v = BI c)\"\n  using `v : values` prems\nproof (nominal_induct v avoiding: \\<Gamma> rule: values.strong_induct)\n  case abs_value thus ?case by auto\nnext\n  case (bool_value b)\n  hence \"T = ty.TT \\<or> T = ty.FF\" using bool_ty_elim by auto\n  thus ?case using sub_arr_cases[of T A1 A2 latent_eff.NE] using bool_value by auto\nnext\n  case (num_value b)\n  hence \"T = ty.Int\" using num_ty_elim by auto\n  thus ?case using sub_arr_cases[of T A1 A2 latent_eff.NE] using num_value by auto\nnext\n  case (bi_value c) thus ?case by auto\nqed\n      \n\nlemma procp_TT_preserved:\n  assumes \"\\<Gamma> \\<turnstile> (App (BI ProcP) v) :  T1 ; TT\" and \"v : values\" and \"\\<Delta> ProcP v = Some u\"\n  shows \"u = Bool True\"\n  proof -\n    note app_ty_tt_elim[of \\<Gamma> \"(BI ProcP)\" v T1]\n    then obtain A1 U T0 T1 S eff1 eff2 where  \n      A:\"\\<Gamma> \\<turnstile> (BI ProcP) : U ; eff1\"  \"\\<turnstile> U <: A1 \\<rightarrow> T1 : Latent S\" \"\\<Gamma> \\<turnstile> v : T0 ; eff2\" \"\\<turnstile> T0 <: A1\"  \"\\<turnstile> T0 <: S\"\n      using prems by auto\n    hence B:\"U = Top \\<rightarrow> BoolTy : Latent (Union [] \\<rightarrow> Top : latent_eff.NE) \" using bi_ty_elim[of \\<Gamma> ProcP U] by auto\n    hence C:\"\\<turnstile> T0 <:  (Union [] \\<rightarrow> Top : latent_eff.NE)\"      \n      using prems arr_sub_arr_cases[of Top BoolTy \"Latent  (Union [] \\<rightarrow> Top : latent_eff.NE)\" _ _ \"Latent S\"] latent_eff.inject A \n      by auto\n    moreover\n    {\n      assume D:\"EX x b t. v = Lam[x:t].b\"\n      then obtain x b t where \"v = Lam[x:t].b\" by auto\n      hence ?thesis using prems by auto\n    }\n    moreover\n    {\n      assume \"EX c. v = BI c\"\n      then obtain c where \"v = BI c\" by auto\n      hence ?thesis using prems by (nominal_induct c rule: builtin.induct) auto\n    }\n    ultimately show ?thesis using prems proc_value[of \\<Gamma> v T0 eff2 \"Union []\" Top] by auto\n  qed\n\nlemma procp_soundness_eff:\n  assumes \"\\<Gamma> \\<turnstile> App (BI ProcP) v : T ; F\" and \"v : values\" and \"\\<Delta> ProcP v = Some u\" and \"\\<Gamma> \\<turnstile> u : T' ; F'\"\n  shows \"\\<turnstile> F' <e: F\"\n  proof -\n    have cl:\"closed u\" using prems delta_closed[of ProcP v u] by auto\n    hence se:\"simple_eff F'\" using prems closed_eff by auto\n    have or:\"simple_eff F\" using procp_eff_simple prems by auto\n    thus ?thesis using prems\n      proof (induct rule: simple_eff_cases)\n        case NE thus ?case using se simple_eff_below_ne by auto\n      next\n        case FF thus ?case using false_ty_elim[of \\<Gamma> T' F'] procp_FF_preserved by auto \n      next\n        case TT thus ?case using true_ty_elim[of \\<Gamma> T' F'] procp_TT_preserved by auto \n      qed\n    qed\n\n\ntext {* soundness of the \\<Delta> rule *}\n\nlemma bool_sub_boolty[simp]: \"\\<turnstile> ty.FF <: BoolTy\" \"\\<turnstile> ty.TT <: BoolTy\" by auto\n\n\nlemma delta_soundness:\n  assumes \"\\<Delta>\\<^isub>\\<tau> b = (T0 \\<rightarrow> T1 : le)\" and \"v : values\" and \"\\<Gamma> \\<turnstile> v : T ; eff1\" and \"\\<turnstile> T <: T0\" \n  and \"\\<Gamma> \\<turnstile> (App (BI b) v) : T1' ; eff\" and \"\\<turnstile> T1 <: T1'\"\n  and \"\\<Delta> b v = Some u\" and \"valid \\<Gamma>\"\n  shows \"EX eff' T1'. \\<Gamma> \\<turnstile> u : T1' ; eff' \\<and> \\<turnstile> eff' <e: eff \\<and> \\<turnstile> T1' <: T1\"\n  using prems\nproof (nominal_induct b rule: builtin.induct)\n  case Add1\n  hence a:\"eff = NE\" using add1_eff_ne[of \\<Gamma> v T1' eff] by auto\n  have \"EX  eff'. \\<Gamma> \\<turnstile> u : T1 ; eff'\" using `v : values` `valid \\<Gamma>` Add1\n    by (induct v rule: values.induct) (auto simp add: ty.inject)\n  then obtain eff' where b:\"\\<Gamma> \\<turnstile> u : T1 ; eff'\" by auto\n  have \"simple_eff eff'\" using delta_closed[of Add1 v u] closed_eff b Add1 by auto\n  hence c:\"\\<turnstile> eff' <e: eff\" using a simple_eff_below_ne by auto \n  from b c show ?case by auto\nnext\n  case Nott\n  hence a:\"eff = NE\" using nott_eff_ne[of \\<Gamma> v T1' eff] by auto\n  have \"EX  eff' T1'. \\<Gamma> \\<turnstile> u : T1' ; eff' \\<and> \\<turnstile> T1' <: T1\" using `v : values` `valid \\<Gamma>` Nott\n  proof (induct v rule: values.induct) \n    case (bool_value b)\n    thus ?case using bool_value bool_sub_boolty by (cases b) auto\n  next\n    case num_value thus ?case using bool_sub_boolty by auto\n  next\n    case bi_value thus ?case using bool_sub_boolty by auto\n  next\n    case abs_value thus ?case using bool_sub_boolty by auto\n  qed \n  then obtain eff' T1' where b:\"\\<Gamma> \\<turnstile> u : T1' ; eff'\" and b':\"\\<turnstile> T1' <: T1\" by auto\n  have \"simple_eff eff'\" using delta_closed[of Nott v u] closed_eff b Nott by auto\n  hence c:\"\\<turnstile> eff' <e: eff\" using a simple_eff_below_ne by auto \n  from b b' c show ?case by auto\nnext\n  case BooleanP\n  have \"valid \\<Gamma>\" using typing_valid prems by auto\n  have \"T1 = BoolTy\" using BooleanP by (simp add: ty.inject)\n  then obtain bb where veq:\"\\<Delta> BooleanP v = Some (Bool bb)\" by (nominal_induct v rule: trm.induct) (auto)\n  hence \"EX  T1' eff'. \\<Gamma> \\<turnstile> u : T1' ; eff' \\<and> \\<turnstile> T1' <: T1\" \n    using `T1 = BoolTy` BooleanP bool_sub_boolty\n  proof (cases bb)\n    case True\n    hence \"u = Bool True\" using veq BooleanP by auto\n    hence \"\\<Gamma> \\<turnstile> u : ty.TT; TT\" using `valid \\<Gamma>` by auto\n    thus ?thesis using `T1 = BoolTy` bool_sub_boolty by auto\n  next\n    case False\n    hence \"u = Bool False\" using veq BooleanP by auto\n    hence \"\\<Gamma> \\<turnstile> u : ty.FF; FF\" using `valid \\<Gamma>` by auto\n    thus ?thesis using `T1 = BoolTy` bool_sub_boolty by auto\n  qed\n  then obtain T1a eff' where a:\"\\<Gamma> \\<turnstile> u : T1a ; eff'\" and a':\"\\<turnstile> T1a <: T1\" by auto\n  have c:\"simple_eff eff'\" using delta_closed[of BooleanP v u] closed_eff prems by auto  \n  have b:\"simple_eff eff\" using BooleanP booleanp_eff_simple by auto\n  hence \"\\<turnstile> eff' <e: eff\" using b prems\n  proof (induct rule: simple_eff_cases)\n    case NE thus ?case using simple_eff_below_ne c by auto\n  next\n    case FF\n    hence \"u = Bool False\" \n      using booleanp_FF_preserved  `v : values`  `\\<Gamma> \\<turnstile> App (BI BooleanP) v : T1' ; eff` `\\<Delta> BooleanP v = Some u` by auto\n    hence \"eff'= FF\" using a false_ty_elim by auto\n    thus ?case using FF by auto\n  next\n    case TT\n    hence \"u = Bool True\" \n      using booleanp_TT_preserved  `v : values`  `\\<Gamma> \\<turnstile> App (BI BooleanP) v : T1' ; eff` `\\<Delta> BooleanP v = Some u` by auto\n    hence \"eff'= TT\" using a true_ty_elim by auto\n    thus ?case using TT by auto\n  qed\n  thus ?case using a a' by auto\nnext\n  case NumberP\n  have \"valid \\<Gamma>\" using typing_valid prems by auto\n  have \"T1 = BoolTy\" using NumberP by (simp add: ty.inject)\n  then obtain bb where veq:\"\\<Delta> NumberP v = Some (Bool bb)\" by (nominal_induct v rule: trm.induct) (auto)\n  hence \"EX  T1' eff'. \\<Gamma> \\<turnstile> u : T1' ; eff' \\<and> \\<turnstile> T1' <: T1\" \n    using `T1 = BoolTy` NumberP bool_sub_boolty\n  proof (cases bb)\n    case True\n    hence \"u = Bool True\" using veq NumberP by auto\n    hence \"\\<Gamma> \\<turnstile> u : ty.TT; TT\" using `valid \\<Gamma>` by auto\n    thus ?thesis using `T1 = BoolTy` bool_sub_boolty by auto\n  next\n    case False\n    hence \"u = Bool False\" using veq NumberP by auto\n    hence \"\\<Gamma> \\<turnstile> u : ty.FF; FF\" using `valid \\<Gamma>` by auto\n    thus ?thesis using `T1 = BoolTy` bool_sub_boolty by auto\n  qed\n  then obtain T1a eff' where a:\"\\<Gamma> \\<turnstile> u : T1a ; eff'\" and a':\"\\<turnstile> T1a <: T1\" by auto\n  have c:\"simple_eff eff'\" using delta_closed[of NumberP v u] closed_eff prems by auto  \n  have b:\"simple_eff eff\" using NumberP numberp_eff_simple by auto\n  hence \"\\<turnstile> eff' <e: eff\" using b prems\n  proof (induct rule: simple_eff_cases)\n    case NE thus ?case using simple_eff_below_ne c by auto\n  next\n    case FF\n    hence \"u = Bool False\" \n      using numberp_FF_preserved  `v : values`  `\\<Gamma> \\<turnstile> App (BI NumberP) v : T1' ; eff` `\\<Delta> NumberP v = Some u` by auto\n    hence \"eff'= FF\" using a false_ty_elim by auto\n    thus ?case using FF by auto\n  next\n    case TT\n    hence \"u = Bool True\" \n      using numberp_TT_preserved  `v : values`  `\\<Gamma> \\<turnstile> App (BI NumberP) v : T1' ; eff` `\\<Delta> NumberP v = Some u` by auto\n    hence \"eff'= TT\" using a true_ty_elim by auto\n    thus ?case using TT by auto\n  qed\n  thus ?case using a a' by auto\nnext\n  case ProcP\n  have \"valid \\<Gamma>\" using typing_valid prems by auto\n  have \"T1 = BoolTy\" using ProcP by (simp add: ty.inject)\n  then obtain bb where veq:\"\\<Delta> ProcP v = Some (Bool bb)\" by (nominal_induct v rule: trm.induct) (auto)\n  hence \"EX  T1' eff'. \\<Gamma> \\<turnstile> u : T1' ; eff' \\<and> \\<turnstile> T1' <: T1\" \n    using `T1 = BoolTy` ProcP bool_sub_boolty\n  proof (cases bb)\n    case True\n    hence \"u = Bool True\" using veq ProcP by auto\n    hence \"\\<Gamma> \\<turnstile> u : ty.TT; TT\" using `valid \\<Gamma>` by auto\n    thus ?thesis using `T1 = BoolTy` bool_sub_boolty by auto\n  next\n    case False\n    hence \"u = Bool False\" using veq ProcP by auto\n    hence \"\\<Gamma> \\<turnstile> u : ty.FF; FF\" using `valid \\<Gamma>` by auto\n    thus ?thesis using `T1 = BoolTy` bool_sub_boolty by auto\n  qed\n  then obtain T1a eff' where a:\"\\<Gamma> \\<turnstile> u : T1a ; eff'\" and a':\"\\<turnstile> T1a <: T1\" by auto\n  have c:\"simple_eff eff'\" using delta_closed[of ProcP v u] closed_eff prems by auto  \n  have b:\"simple_eff eff\" using ProcP procp_eff_simple by auto\n  hence \"\\<turnstile> eff' <e: eff\" using b prems\n  proof (induct rule: simple_eff_cases)\n    case NE thus ?case using simple_eff_below_ne c by auto\n  next\n    case FF\n    hence \"u = Bool False\" \n      using procp_FF_preserved  `v : values`  `\\<Gamma> \\<turnstile> App (BI ProcP) v : T1' ; eff` `\\<Delta> ProcP v = Some u` by auto\n    hence \"eff'= FF\" using a false_ty_elim by auto\n    thus ?case using FF by auto\n  next\n    case TT\n    hence \"u = Bool True\" \n      using procp_TT_preserved  `v : values`  `\\<Gamma> \\<turnstile> App (BI ProcP) v : T1' ; eff` `\\<Delta> ProcP v = Some u` by auto\n    hence \"eff'= TT\" using a true_ty_elim by auto\n    thus ?case using TT by auto\n  qed\n  thus ?case using a a' by auto\nqed\n\nlemma simple_eff_below_ve:\n  assumes \"simple_eff F\"\n  shows \"\\<turnstile> F <e: VE x\"\n  using prems\n  by (induct F rule: simple_eff_cases) auto\n\nlemma below_ne_simple:\n  assumes \"\\<turnstile> F <e: G\" and \"G = NE\"\n  shows \"simple_eff F\"\n  using prems no_sub_TT no_sub_FF\n  by induct auto\n\nlemma below_ve_simple:\n  assumes \"\\<turnstile> F <e: G\" and \"G = VE x\"\n  shows \"simple_eff F \\<or> F = VE x\"\n  using prems\n  by induct auto\n\nconsts\n  remove_env  :: \"'a list => 'a => 'a list\" (\"_ - _\" [100,100] 100)\n\nprimrec\n  \"[] - x = []\"\n  \"(y#xs) - x = (if x=y then (xs - x) else y#(xs - x))\"\n\nlemma fresh_remove:\n  fixes a::\"name\"\n  and   \\<Gamma>::\"(name\\<times>ty) list\"\n  assumes a: \"a\\<sharp>\\<Gamma>\"\n  shows \"a\\<sharp>(\\<Gamma> - (x,T))\"\nusing a\nby (induct \\<Gamma>) (auto simp add: fresh_list_cons)\n\nlemma valid_remove:\n  fixes pair::\"name\\<times>ty\"\n  assumes a: \"valid \\<Gamma>\"\n  shows \"valid (\\<Gamma> - (x,T))\"\nusing a\nby (induct \\<Gamma>) (auto simp add: fresh_remove)\n\nlemma set_remove:\n  assumes a: \"(a,T)\\<in>set \\<Gamma>\"\n  and     b: \"a\\<noteq>x\"\n  shows \"(a,T)\\<in>set (\\<Gamma> - (x,T'))\"\nusing a b\nby (induct \\<Gamma>) (auto)\n\nlemma closed_elim:\"closed e \\<Longrightarrow> (supp e = ({}::name set))\" using closed_def by auto\n\nlemma set_remove_comm:\n  shows \"set (l - a) = (set l) - {a}\"\n  by (induct l) auto\n\n\nlemma envplus_set:\n  shows \"set (\\<Gamma> |+ TE T x) = (mapfun restrict T x) ` set \\<Gamma>\"\nproof -\n  have A:\"!! a b. a = b \\<Longrightarrow> set a = set b\" by auto\n  have \"\\<Gamma> |+ TE T x = map (mapfun restrict T x) \\<Gamma>\" by auto\n  hence \"set (\\<Gamma> |+ TE T x) = set (map (mapfun restrict T x) \\<Gamma>)\" \n    using A[of \"(\\<Gamma> |+ TE T x)\" \"map (mapfun restrict T x) \\<Gamma>\"] by auto\n  also have \"\\<dots> = (mapfun restrict T x) ` set \\<Gamma>\" by auto\n  ultimately show ?thesis by auto\nqed\n\nlemma envminus_set:\n  shows \"set (\\<Gamma> |- TE T x) = (mapfun remove T x) ` set \\<Gamma>\"\nproof -\n  have A:\"!! a b. a = b \\<Longrightarrow> set a = set b\" by auto\n  have \"\\<Gamma> |- TE T x = map (mapfun remove T x) \\<Gamma>\" by auto\n  hence \"set (\\<Gamma> |- TE T x) = set (map (mapfun remove T x) \\<Gamma>)\" \n    using A[of \"(\\<Gamma> |- TE T x)\" \"map (mapfun remove T x) \\<Gamma>\"] by auto\n  also have \"\\<dots> = (mapfun remove T x) ` set \\<Gamma>\" by auto\n  ultimately show ?thesis by auto\nqed\n\n\n\nlemma envplus_set_ve:\n  shows \"set (\\<Gamma> |+ VE x) = (mapfun remove ty.FF x) ` set \\<Gamma>\"\nproof -\n  have A:\"!! a b. a = b \\<Longrightarrow> set a = set b\" by auto\n  have \"\\<Gamma> |+ VE x = map (mapfun remove ty.FF x) \\<Gamma>\" by auto\n  hence \"set (\\<Gamma> |+ VE x) = set (map (mapfun remove ty.FF x) \\<Gamma>)\" \n    using A[of \"(\\<Gamma> |+ VE x)\" \"map (mapfun remove ty.FF x) \\<Gamma>\"] by auto\n  also have \"\\<dots> = (mapfun remove ty.FF x) ` set \\<Gamma>\" by auto\n  ultimately show ?thesis by auto\nqed\n\nlemma envminus_set_ve:\n  shows \"set (\\<Gamma> |- VE x) = (mapfun replace ty.FF x) ` set \\<Gamma>\"\nproof -\n  have A:\"!! a b. a = b \\<Longrightarrow> set a = set b\" by auto\n  have \"\\<Gamma> |- VE x = map (mapfun replace ty.FF x) \\<Gamma>\" by auto\n  hence \"set (\\<Gamma> |- VE x) = set (map (mapfun replace ty.FF x) \\<Gamma>)\" \n    using A[of \"(\\<Gamma> |- VE x)\" \"map (mapfun replace ty.FF x) \\<Gamma>\"] by auto\n  also have \"\\<dots> = (mapfun replace ty.FF x) ` set \\<Gamma>\" by auto\n  ultimately show ?thesis by auto\nqed\n\n\nlemma fresh_weakening:\n  assumes a:\"x\\<sharp>e\" and b:\"\\<Gamma> \\<turnstile> e : T ; F\" and c: \"valid \\<Gamma>\" \n  shows \"(\\<Gamma> - (x,T')) \\<turnstile> e : T ; F\"\n  using b a c \nproof (nominal_induct \\<Gamma> e T F avoiding: x T'  rule: typing.strong_induct)\n  case T_Var thus ?case\n    by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)+\nnext\n  case (T_App \\<Gamma>' _ _ t1 t2) thus ?case\n    by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)\nnext\n  case T_Abs thus ?case\n    by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)+\nnext\n  case T_AbsPred thus ?case\n    by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)+\nnext\n  case T_AppPred thus ?case\n    by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)+\nnext\n  case T_IfTrue thus ?case\n    by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)+\nnext\n  case T_IfFalse thus ?case\n    by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)+\nnext\n  case T_True thus ?case\n    by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)+\nnext\n  case T_False thus ?case\n    by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)+\nnext\n  case T_Num thus ?case\n    by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)+\nnext\n  case T_Const thus ?case\n    by(force simp add: fresh_atm abs_fresh set_remove valid_remove fresh_remove)+\nnext\n  case (T_AppPredTrue \\<Gamma>' e1 U F1 T0 T1 S e2 T F2 x T')\n  have A:\"x \\<sharp> e1\" \"x \\<sharp> e2\" using T_AppPredTrue by auto\n  hence \"\\<Gamma>' - (x,T') \\<turnstile> e1 : U; F1\" using T_AppPredTrue by auto\n  also have \"\\<Gamma>' - (x,T') \\<turnstile> e2 : T ; F2\" using T_AppPredTrue A by auto\n  ultimately show ?case using T_AppPredTrue(3) `\\<turnstile> T <: T0` `\\<turnstile> T <: S` by auto\nnext\n  case (T_AppPredFalse  \\<Gamma>' e1 U F1 T0 T1 S e2 T F2 x T')\n  have A:\"x \\<sharp> e1\" \"x \\<sharp> e2\" using T_AppPredFalse by auto\n  hence \"\\<Gamma>' - (x,T') \\<turnstile> e1 : U ; F1\" using T_AppPredFalse by auto\n  also have \"\\<Gamma>' - (x,T') \\<turnstile> e2 : T ; F2\" using T_AppPredFalse A by auto\n  ultimately show ?case using `~ (\\<turnstile> T <: S)` `\\<turnstile> T <: T0` `e2 : values` `closed e2`  T_AppPredFalse(3) by auto\nnext\n  case (T_If \\<Gamma>' e1 T1 F1 e2 T2 F2 e3 T3 F3 T x)\n  have A:\"x \\<sharp> e1\" \"x \\<sharp> e2\" \"x \\<sharp> e3\" using T_If by auto\n  have \"\\<Gamma>' - (x,T') \\<turnstile> e1 : T1 ; F1\" using T_If A by auto\n  thus ?case using T_If\n    proof (nominal_induct \"F1\" rule: eff.induct)\n      case NE\n      from NE have 1:\"\\<Gamma>' - (x, T') \\<turnstile> e1 : T1 ; eff.NE\" by auto\n      from NE have 2:\"(\\<Gamma>' - (x, T') |+ eff.NE) \\<turnstile> e2 : T2 ; F2\" by auto\n      from NE have 3:\"(\\<Gamma>' - (x, T') |- eff.NE) \\<turnstile> e3 : T3 ; F3\" by auto\n      from 1 2 3 show ?case using `\\<turnstile> T2 <: T` `\\<turnstile> T3 <: T` ..\n    next\n      case TT\n      from TT have 1:\"\\<Gamma>' - (x, T') \\<turnstile> e1 : T1 ; eff.TT\" by auto\n      from TT have 2:\"(\\<Gamma>' - (x, T') |+ eff.TT) \\<turnstile> e2 : T2 ; F2\" by auto\n      from 1 2 show ?case using `\\<turnstile> T2 <: T` by auto\n    next\n      case FF\n      from FF have 1:\"\\<Gamma>' - (x, T') \\<turnstile> e1 : T1 ; eff.FF\" by auto\n      from FF have 3:\"(\\<Gamma>' - (x, T') |+ eff.FF) \\<turnstile> e3 : T3 ; F3\" by auto\n      from 1 3 show ?case using `\\<turnstile> T3 <: T` by auto \n    next\n      case (VE z)\n      from VE have 1:\"\\<Gamma>' - (x, T') \\<turnstile> e1 : T1 ; VE z\" by auto\n      have val1:\"valid (\\<Gamma>' |+ VE z)\" using VE envplus_valid[of \\<Gamma>' \"VE z\"] by auto\n      have val2:\"valid (\\<Gamma>' |- VE z)\" using VE envminus_valid[of \\<Gamma>' \"VE z\"] by auto\n      have \"valid (\\<Gamma>' |- VE z)\" using VE envminus_valid[of \\<Gamma>' \"VE z\"] by auto\n      have A0:\"!!T0 . (\\<Gamma>' |- VE z) - (x, T0) \\<turnstile> e3 : T3 ; F3\" using VE(7) A `valid (\\<Gamma>' |- VE z)` by auto\n\n      have A:\"!!T0 . (\\<Gamma>' |+ VE z) - (x, T0) \\<turnstile> e2 : T2 ; F2\" using VE(5) A `valid (\\<Gamma>' |+ VE z)` by auto\n      let ?op = \"replace\"\n      let ?mapfun = \"(% (v,ty). (if (x = v) then (v,?op ty.FF ty) else (v,ty)))\"\n      have B:\"!! p. set ((\\<Gamma>' |+ VE z) - p) = ((mapfun remove ty.FF z) ` (set \\<Gamma>')) - {p}\" \n\tusing envplus_set_ve set_remove_comm[of \"(\\<Gamma>' |+ VE z)\"] by auto\n      have image_lem:\"!! f S v. (f ` S) - {(f v)} <= (f ` (S - {v}))\" by auto\n      note image_lem[of \"mapfun remove ty.FF z\" \"set \\<Gamma>'\" \"(x,T0)\"]\n      \n      have eq1:\"!! p. mapfun remove ty.FF z ` set \\<Gamma>' - {mapfun remove ty.FF z p} = set ((\\<Gamma>' |+ VE z) - (mapfun remove ty.FF z p))\" using envplus_set_ve set_remove_comm[of \"(\\<Gamma>' |+ VE z)\"] by auto\n\n      have eq2:\"!! p. mapfun remove ty.FF z ` (set \\<Gamma>' - {p}) = set (\\<Gamma>' - p |+ VE z)\"\n      proof -\n\tfix p\n\tshow \"mapfun remove ty.FF z ` (set \\<Gamma>' - {p}) = set (\\<Gamma>' - p |+ VE z)\"\n\t  using envplus_set_ve[of _ \"\\<Gamma>' - p\"]  set_remove_comm[of \\<Gamma>'] by auto\n      qed\n      have eq3:\"!! x T0. mapfun remove ty.FF z (x,T0) = (x, (if (x = z) then (remove ty.FF T0) else (T0)))\" by auto\n      let ?removeT' = \"(if (x = z) then (remove ty.FF T') else (T'))\"\n      have goal:\"((\\<Gamma>' |+ VE z) - (x,?removeT')) \\<lless> ((\\<Gamma>' - (x,T')) |+ VE z)\"\n      proof -\n\thave \" mapfun remove ty.FF z ` set \\<Gamma>' - {mapfun remove ty.FF z (x,T')} <= \n\t  mapfun remove ty.FF z ` (set \\<Gamma>' - {(x,T')})\" using  image_lem[of \"mapfun remove ty.FF z\" \"set \\<Gamma>'\" \"(x,T')\"] by auto\n\thence \" mapfun remove ty.FF z ` set \\<Gamma>' - {mapfun remove ty.FF z (x,T')} <= \n\t  set ((\\<Gamma>' - ((x,T'))) |+ VE z)\" using eq2[of \" (x, T')\"] by auto\n\thence \"set ((\\<Gamma>' |+ VE z) - (mapfun remove ty.FF z (x,T'))) <= \n\t  set ((\\<Gamma>' - ((x,T'))) |+ VE z)\" \n\t  using eq1[of \"(x,T')\"] by auto\n\thence \"set ((\\<Gamma>' |+ VE z) - (x,?removeT')) <= set ((\\<Gamma>' - (x,T')) |+ VE z)\" using eq3 by auto\n\tthus ?thesis by auto\n      qed\n      have val3:\"valid ((\\<Gamma>' |+ VE z) - (x,?removeT'))\" using val1 valid_remove by auto\n      have \"valid ((\\<Gamma>' - (x, T')))\" using `valid \\<Gamma>'` valid_remove envplus_valid by auto\n      hence val4:\"valid ((\\<Gamma>' - (x, T')) |+ VE z)\" using  envplus_valid[of \"\\<Gamma>' - (x, T')\" \"VE z\"] by auto\n      from  A have \"(\\<Gamma>' |+ VE z) - (x,?removeT') \\<turnstile>  e2 : T2 ; F2\" by auto\n      hence 2:\"(\\<Gamma>' - (x, T')) |+ VE z \\<turnstile> e2 : T2 ; F2\" using goal val3 val4\n\tweakening[of  \"(\\<Gamma>' |+ VE z) - (x,?removeT')\" e2 T2 F2 \"\\<Gamma>' - (x,T') |+ VE z\"] by auto\n\n      have eq4:\"!! p. mapfun replace ty.FF z ` set \\<Gamma>' - {mapfun replace ty.FF z p} = set ((\\<Gamma>' |- VE z) - (mapfun replace ty.FF z p))\" using envminus_set_ve[of _ \\<Gamma>'] set_remove_comm[of \"(\\<Gamma>' |- VE z)\"] by auto\n\n      have eq5:\"!! p. mapfun replace ty.FF z ` (set \\<Gamma>' - {p}) = set (\\<Gamma>' - p |- VE z)\"\n      proof -\n\tfix p\n\tshow \"mapfun replace ty.FF z ` (set \\<Gamma>' - {p}) = set (\\<Gamma>' - p |- VE z)\"\n\t  using envminus_set_ve[of _ \"\\<Gamma>' - p\" ] set_remove_comm[of \\<Gamma>'] by auto\n      qed\n      have eq6:\"!! x T0. mapfun replace ty.FF z (x,T0) = (x, (if (x = z) then (replace ty.FF T0) else (T0)))\" by auto\n      let ?replaceT' = \"(if (x = z) then (replace ty.FF T') else (T'))\"\n      have goal':\"((\\<Gamma>' |- VE z) - (x,?replaceT')) \\<lless> ((\\<Gamma>' - (x,T')) |- VE z)\"\n      proof -\n\thave \" mapfun replace ty.FF z ` set \\<Gamma>' - {mapfun replace ty.FF z (x,T')} <= \n\t  mapfun replace ty.FF z ` (set \\<Gamma>' - {(x,T')})\" using  image_lem[of \"mapfun replace ty.FF z\" \"set \\<Gamma>'\" \"(x,T')\"] by auto\n\thence \" mapfun replace ty.FF z ` set \\<Gamma>' - {mapfun replace ty.FF z (x,T')} <= \n\t  set ((\\<Gamma>' - ((x,T'))) |- VE z)\" using eq5[of \" (x, T')\"] by auto\n\thence \"set ((\\<Gamma>' |- VE z) - (mapfun replace ty.FF z (x,T'))) <= \n\t  set ((\\<Gamma>' - ((x,T'))) |- VE z)\" \n\t  using eq4[of \"(x,T')\"] by auto\n\thence \"set ((\\<Gamma>' |- VE z) - (x,?replaceT')) <= set ((\\<Gamma>' - (x,T')) |- VE z)\" using eq6 by auto\n\tthus ?thesis by auto\n      qed\n      have val5:\"valid ((\\<Gamma>' |- VE z) - (x,?replaceT'))\" using val2 valid_remove by auto\n      have \"valid ((\\<Gamma>' - (x, T')))\" using `valid \\<Gamma>'` valid_remove envminus_valid by auto\n      hence val6:\"valid ((\\<Gamma>' - (x, T')) |- VE z)\" using  envminus_valid[of \"\\<Gamma>' - (x, T')\" \"VE z\"] by auto\n      from  A0 have \"(\\<Gamma>' |- VE z) - (x,?replaceT') \\<turnstile>  e3 : T3 ; F3\" by auto\n      hence 3:\"(\\<Gamma>' - (x, T')) |- VE z \\<turnstile> e3 : T3 ; F3\" using goal' val5 val6\n\tweakening[of  \"(\\<Gamma>' |- VE z) - (x,?replaceT')\" e3 T3 F3 \"\\<Gamma>' - (x,T') |- VE z\"] by auto\n      from 1 2 3 show ?case using `\\<turnstile> T2 <: T` `\\<turnstile> T3 <: T` ..\n    next\n      case (TE U z)\n      from TE have 1:\"\\<Gamma>' - (x, T') \\<turnstile> e1 : T1 ; TE U z\" by auto\n      have val1:\"valid (\\<Gamma>' |+ TE U z)\" using TE envplus_valid[of \\<Gamma>' \"TE U z\"] by auto\n      have val2:\"valid (\\<Gamma>' |- TE U z)\" using TE envminus_valid[of \\<Gamma>' \"TE U z\"] by auto\n      have \"valid (\\<Gamma>' |- TE U z)\" using TE envminus_valid[of \\<Gamma>' \"TE U z\"] by auto\n      have A0:\"!!T0 . (\\<Gamma>' |- TE U z) - (x, T0) \\<turnstile> e3 : T3 ; F3\" using TE(7) A `valid (\\<Gamma>' |- TE U z)` by auto\n\n      have A:\"!!T0 . (\\<Gamma>' |+ TE U z) - (x, T0) \\<turnstile> e2 : T2 ; F2\" using TE(5) A `valid (\\<Gamma>' |+ TE U z)` by auto\n      let ?op = \"remove\"\n      let ?mapfun = \"(% (v,ty). (if (x = v) then (v,?op S ty) else (v,ty)))\"\n      have B:\"!! p. set ((\\<Gamma>' |+ TE U z) - p) = ((mapfun restrict U z) ` (set \\<Gamma>')) - {p}\" \n\tusing envplus_set set_remove_comm[of \"(\\<Gamma>' |+ TE U z)\"] by auto\n      have image_lem:\"!! f S v. (f ` S) - {(f v)} <= (f ` (S - {v}))\" by auto\n      note image_lem[of \"mapfun restrict U z\" \"set \\<Gamma>'\" \"(x,T0)\"]\n      \n      have eq1:\"!! p. mapfun restrict U z ` set \\<Gamma>' - {mapfun restrict U z p} = set ((\\<Gamma>' |+ TE U z) - (mapfun restrict U z p))\" using envplus_set set_remove_comm[of \"(\\<Gamma>' |+ TE U z)\"] by auto\n\n      have eq2:\"!! p. mapfun restrict U z ` (set \\<Gamma>' - {p}) = set (\\<Gamma>' - p |+ TE U z)\"\n      proof -\n\tfix p\n\tshow \"mapfun restrict U z ` (set \\<Gamma>' - {p}) = set (\\<Gamma>' - p |+ TE U z)\"\n\t  using envplus_set[of _ _ \"\\<Gamma>' - p\"] set_remove_comm[of \\<Gamma>'] by auto\n      qed\n      have eq3:\"!! x T0. mapfun restrict U z (x,T0) = (x, (if (x = z) then (restrict U T0) else (T0)))\" by auto\n      let ?restrictT' = \"(if (x = z) then (restrict U T') else (T'))\"\n      have goal:\"((\\<Gamma>' |+ TE U z) - (x,?restrictT')) \\<lless> ((\\<Gamma>' - (x,T')) |+ TE U z)\"\n      proof -\n\thave \" mapfun restrict U z ` set \\<Gamma>' - {mapfun restrict U z (x,T')} <= \n\t  mapfun restrict U z ` (set \\<Gamma>' - {(x,T')})\" using  image_lem[of \"mapfun restrict U z\" \"set \\<Gamma>'\" \"(x,T')\"] by auto\n\thence \" mapfun restrict U z ` set \\<Gamma>' - {mapfun restrict U z (x,T')} <= \n\t  set ((\\<Gamma>' - ((x,T'))) |+ TE U z)\" using eq2[of \" (x, T')\"] by auto\n\thence \"set ((\\<Gamma>' |+ TE U z) - (mapfun restrict U z (x,T'))) <= \n\t  set ((\\<Gamma>' - ((x,T'))) |+ TE U z)\" \n\t  using eq1[of \"(x,T')\"] by auto\n\thence \"set ((\\<Gamma>' |+ TE U z) - (x,?restrictT')) <= set ((\\<Gamma>' - (x,T')) |+ TE U z)\" using eq3 by auto\n\tthus ?thesis by auto\n      qed\n      have val3:\"valid ((\\<Gamma>' |+ TE U z) - (x,?restrictT'))\" using val1 valid_remove by auto\n      have \"valid ((\\<Gamma>' - (x, T')))\" using `valid \\<Gamma>'` valid_remove envplus_valid by auto\n      hence val4:\"valid ((\\<Gamma>' - (x, T')) |+ TE U z)\" using  envplus_valid[of \"\\<Gamma>' - (x, T')\" \"TE U z\"] by auto\n      from  A have \"(\\<Gamma>' |+ TE U z) - (x,?restrictT') \\<turnstile>  e2 : T2 ; F2\" by auto\n      hence 2:\"(\\<Gamma>' - (x, T')) |+ TE U z \\<turnstile> e2 : T2 ; F2\" using goal val3 val4\n\tweakening[of  \"(\\<Gamma>' |+ TE U z) - (x,?restrictT')\" e2 T2 F2 \"\\<Gamma>' - (x,T') |+ TE U z\"] by auto\n\n      have eq4:\"!! p. mapfun remove U z ` set \\<Gamma>' - {mapfun remove U z p} = set ((\\<Gamma>' |- TE U z) - (mapfun remove U z p))\" using envminus_set[of _ _ \\<Gamma>'] set_remove_comm[of \"(\\<Gamma>' |- TE U z)\"] by auto\n\n      have eq5:\"!! p. mapfun remove U z ` (set \\<Gamma>' - {p}) = set (\\<Gamma>' - p |- TE U z)\"\n      proof -\n\tfix p\n\tshow \"mapfun remove U z ` (set \\<Gamma>' - {p}) = set (\\<Gamma>' - p |- TE U z)\"\n\t  using envminus_set[of _ _ \"\\<Gamma>' - p\" ] set_remove_comm[of \\<Gamma>'] by auto\n      qed\n      have eq6:\"!! x T0. mapfun remove U z (x,T0) = (x, (if (x = z) then (remove U T0) else (T0)))\" by auto\n      let ?removeT' = \"(if (x = z) then (remove U T') else (T'))\"\n      have goal':\"((\\<Gamma>' |- TE U z) - (x,?removeT')) \\<lless> ((\\<Gamma>' - (x,T')) |- TE U z)\"\n      proof -\n\thave \" mapfun remove U z ` set \\<Gamma>' - {mapfun remove U z (x,T')} <= \n\t  mapfun remove U z ` (set \\<Gamma>' - {(x,T')})\" using  image_lem[of \"mapfun remove U z\" \"set \\<Gamma>'\" \"(x,T')\"] by auto\n\thence \" mapfun remove U z ` set \\<Gamma>' - {mapfun remove U z (x,T')} <= \n\t  set ((\\<Gamma>' - ((x,T'))) |- TE U z)\" using eq5[of \" (x, T')\"] by auto\n\thence \"set ((\\<Gamma>' |- TE U z) - (mapfun remove U z (x,T'))) <= \n\t  set ((\\<Gamma>' - ((x,T'))) |- TE U z)\" \n\t  using eq4[of \"(x,T')\"] by auto\n\thence \"set ((\\<Gamma>' |- TE U z) - (x,?removeT')) <= set ((\\<Gamma>' - (x,T')) |- TE U z)\" using eq6 by auto\n\tthus ?thesis by auto\n      qed\n      have val5:\"valid ((\\<Gamma>' |- TE U z) - (x,?removeT'))\" using val2 valid_remove by auto\n      have \"valid ((\\<Gamma>' - (x, T')))\" using `valid \\<Gamma>'` valid_remove envminus_valid by auto\n      hence val6:\"valid ((\\<Gamma>' - (x, T')) |- TE U z)\" using  envminus_valid[of \"\\<Gamma>' - (x, T')\" \"TE U z\"] by auto\n      from  A0 have \"(\\<Gamma>' |- TE U z) - (x,?removeT') \\<turnstile>  e3 : T3 ; F3\" by auto\n      hence 3:\"(\\<Gamma>' - (x, T')) |- TE U z \\<turnstile> e3 : T3 ; F3\" using goal' val5 val6\n\tweakening[of  \"(\\<Gamma>' |- TE U z) - (x,?removeT')\" e3 T3 F3 \"\\<Gamma>' - (x,T') |- TE U z\"] by auto\n      from 1 2 3 show ?case using `\\<turnstile> T2 <: T` `\\<turnstile> T3 <: T` ..\n    qed\n  qed\n\nlemma fresh_weakening_cons:\n  assumes \"valid ((a,S)#\\<Gamma>)\" (is \"valid ?\\<Gamma>\") and \"(a,S)# \\<Gamma> \\<turnstile> e : T ; F\" and \"a \\<sharp> e\"\n  shows \"\\<Gamma> \\<turnstile> e : T ; F\"\n  proof -\n    have v1:\"valid \\<Gamma>\" using prems valid_elim by blast\n    hence v2:\"valid (\\<Gamma> - (a,S))\" using valid_remove by auto\n    have A:\"?\\<Gamma> - (a,S) \\<turnstile> e : T ; F\" using prems fresh_weakening[of a e ?\\<Gamma> T F S] by auto\n    have \"?\\<Gamma> - (a,S) = \\<Gamma> - (a,S)\" by auto\n    hence B:\"\\<Gamma> - (a,S)  \\<lless> \\<Gamma>\" by (induct \\<Gamma>) auto\n    thus ?thesis using A weakening[of _ e T F \\<Gamma>] v1 v2 by auto\n  qed\n    \n\nlemma closed_empty_env:\n  assumes \"closed e\" and \"\\<Gamma> \\<turnstile> e : T ; F\" and \"valid \\<Gamma>\"\n  shows \"[] \\<turnstile> e : T ; F\"\n  using `valid \\<Gamma>` prems\n  proof (induct \\<Gamma> rule: valid.induct)\n    case v1 thus ?case by simp\n  next\n    case (v2 \\<Gamma>' a S)\n    have \"a \\<sharp> e\" using `closed e` closed_def fresh_def[of a e] by auto\n    thus ?case using v2 fresh_weakening_cons by auto\n  qed\n\n\n\nlemma closed_any_env:\n  assumes \"closed e\" and \"\\<Gamma> \\<turnstile> e : T ; F\" and val1:\"valid \\<Gamma>\" and val2:\"valid \\<Gamma>'\"\n  shows \"\\<Gamma>' \\<turnstile> e : T ; F\"\n  using prems closed_empty_env weakening \n  proof -\n    have A:\"[] \\<turnstile> e : T ; F\" using prems closed_empty_env by auto\n    note weakening\n    have B:\"[] \\<lless> \\<Gamma>'\" by auto\n    from A B val1 val2 have \"\\<Gamma>' \\<turnstile> e : T ; F\" using weakening by blast\n    thus ?thesis by simp\n  qed    \n\ninductive_cases ve_ty_elim: \"\\<Gamma> \\<turnstile> e : T ; VE x\"  \n\nlemma te_ty_elim: \n \"\\<Gamma> \\<turnstile> t1 : T ; TE U z \\<Longrightarrow>\n  EX f A A1 Fn S B. t1 = (App f (Var z)) \\<and> \\<Gamma> \\<turnstile> f : B ; Fn \\<and> \\<turnstile> B <:  A1 \\<rightarrow> T : Latent U \\<and>\n  \\<Gamma> \\<turnstile> (Var z) : A ; VE z \\<and> \\<turnstile> A <: A1 \"\n  proof (ind_cases \"\\<Gamma> \\<turnstile> t1 : T ; TE U z\")\n    fix e1 T0 eff1 e2 Ta x S B\n    assume \"t1 = App e1 e2\" \"TE U z = TE S x\"\n      \"\\<Gamma> \\<turnstile> e1 : B ; eff1 \"\" \\<Gamma> \\<turnstile> e2 : Ta ; VE x \" \"\\<turnstile> B <: T0 \\<rightarrow> T : Latent S\"\n      \"\\<turnstile> Ta <: T0\"\n    from prems have A:\"e2 = Var x\" using ve_ty_elim[of \\<Gamma> e2 Ta x]  eff.inject by auto\n    hence B:\"t1 = App e1 (Var z)\" using prems trm.inject eff.inject by auto\n    have C:\" \\<Gamma> \\<turnstile> (Var z) : Ta ; VE z\" using prems A trm.inject eff.inject by auto\n    have D:\" \\<Gamma> \\<turnstile> e1 : B ; eff1\" using ty.inject latent_eff.inject prems eff.inject by auto\n    have E:\"\\<turnstile> B <: T0 \\<rightarrow> T : Latent U\" using ty.inject latent_eff.inject prems eff.inject by auto\n    from `\\<turnstile> Ta <: T0` B C D E  show ?thesis by blast\n  qed\n    \n  \n\nlemma unique_var_typing:\n  assumes  \"(x,T)#\\<Gamma> \\<turnstile> Var x : T; VE x\" and \"(x,T)#\\<Gamma> \\<turnstile> Var x : T' ; VE x\"\n  shows \"T = T'\"\n  proof (rule ccontr)\n    assume \"T ~= T'\"\n    have \"(x,T) : set ((x,T)#\\<Gamma>)\" using var_ty_elim[of _ x T \"VE x\"] prems by auto\n    have \"(x,T') : set ((x,T)#\\<Gamma>)\" \"valid ((x,T)#\\<Gamma>)\" using var_ty_elim[of \"((x,T)#\\<Gamma>)\" x T' \"VE x\"] prems by auto\n    hence A:\"(x,T') : set \\<Gamma>\" \"valid \\<Gamma>\" \"x \\<sharp> \\<Gamma>\" using prems valid_elim[of x T \\<Gamma>] by auto\n    have \"x : supp \\<Gamma>\" using `valid \\<Gamma>` A\n    proof (induct \\<Gamma> rule: valid.induct)\n      case v1 thus ?case by auto\n    next\n      case (v2 \\<Gamma>' a S) \n      hence \"x \\<sharp> (a,S)\" \"x \\<sharp> \\<Gamma>'\" using fresh_list_cons by auto\n      hence \"x \\<sharp> a\" by auto\n      hence \"x ~= a\" using fresh_atm by auto\n      hence \"(x,T') : set \\<Gamma>'\" using v2 by auto\n      have \"valid \\<Gamma>'\" using v2 valid_elim[of a S \\<Gamma>'] by auto\n      hence \"x : supp \\<Gamma>'\" using v2 `(x,T') : set \\<Gamma>'` `x \\<sharp> \\<Gamma>'` by auto\n      hence \"x : supp (a,S)  \\<union> supp \\<Gamma>'\" by auto\n      hence \"x : (supp ((a,S)#\\<Gamma>') :: name set)\" using supp_list_cons[of \"(a,S)\" \\<Gamma>'] by force\n      thus ?case by simp \n    qed\n    hence \"~ (x \\<sharp> \\<Gamma>)\" using fresh_def[of x \\<Gamma>] by blast\n    thus False using `x \\<sharp> \\<Gamma>` by auto\n  qed\n\ninductive_cases tt_sub_ff:\"\\<turnstile> ty.TT <: ty.FF\"\ninductive_cases ff_sub_tt:\"\\<turnstile> ty.FF <: ty.TT\"\n\nlemma value_effect_tt_or_ff:\n  assumes \"v : values\" and \"\\<Gamma> \\<turnstile> v : T ; F\"\n  shows \"F = FF \\<and> v = Bool False \\<or> F = TT \\<and> v ~= Bool False\"\n  using prems\nproof (nominal_induct v avoiding: \\<Gamma> rule: values.strong_induct)\n  case num_value thus ?case using num_ty_elim by auto\nnext\n  case bi_value thus ?case using bi_ty_elim by auto\nnext\n  case abs_value thus ?case using abs_ty_elim[of \\<Gamma> _ _ _ T F] by auto\nnext\n  case (bool_value b)\n  thus ?case using true_ty_elim false_ty_elim by (cases b) auto\nqed\n\nlemma remove_fresh_env:\n  assumes A:\"y \\<sharp> \\<Gamma>\" and B:\"valid \\<Gamma>\"\n  shows \"\\<Gamma> - (y,T) = \\<Gamma>\"\n  using B A\nproof (induct \\<Gamma> rule: valid.induct)\n  case v1 thus ?case by auto\nnext\n  case (v2 \\<Gamma>' a S)\n  have \"y \\<noteq> a\" \"y \\<sharp> \\<Gamma>'\" using `y \\<sharp> ((a, S) # \\<Gamma>')` using fresh_atm[of y a] fresh_list_cons by auto\n  hence \"((a, S) # \\<Gamma>') - (y, T) = (a, S) # (\\<Gamma>' - (y, T))\" by auto\n  thus ?case using v2 `y \\<sharp> \\<Gamma>'` by auto\nqed\n\n\nlemma subst_preserve_TE_app:\n  assumes tapp:\"(y,T0)#\\<Gamma> \\<turnstile> App e1 e2 : T ; TE S x\"\n  and neq:\"y \\<noteq> x\"\n  and val:\"valid ((y,T0)#\\<Gamma>)\"\n  and ih: \"!! t bc bf . \\<lbrakk>t \\<guillemotleft> App e1 e2;  (y, T0) # \\<Gamma> \\<turnstile> t : bc ; bf \\<rbrakk> \n  \\<Longrightarrow> \\<exists>T' F'.  \\<Gamma> \\<turnstile> t[y::=v] : T' ; F'  \\<and> \\<turnstile> T' <: bc \\<and> \\<turnstile> F' <e: bf\"\n  shows \"\\<Gamma> \\<turnstile> (App e1 e2)[y::=v] : T ; TE S x\"\nproof -\n  note te_ty_elim[OF tapp]\n  then obtain f  A A1 Fn Sa B\n    where sz:\"App e1 e2 = App f (Var x)\"\n    and tf:\"(y, T0) # \\<Gamma> \\<turnstile> f : B ; Fn  \"\" \\<turnstile> B <: A1 \\<rightarrow> T : Latent S\" \n    and tvx:\"(y, T0) # \\<Gamma> \\<turnstile> Var x : A ; VE x\" and sub:\" \\<turnstile> A <: A1\"\n    by auto\n  hence \"e1 = f\" and \"e2 = Var x\" using trm.inject by auto\n  hence \"e2[y::=v] = Var x\" using `y \\<noteq> x` forget by auto\n  hence tsub:\" (y, T0)#\\<Gamma> \\<turnstile> e2[y::=v] : A ; VE x\" using `e2=Var x` tvx by auto\n  have fr:\"y \\<sharp> e2[y::=v]\" using `e2 = Var x``e2[y::=v] = Var x` `y \\<noteq> x` using fresh_atm by auto\n  have \"y \\<sharp> \\<Gamma>\" \"valid \\<Gamma>\" using valid_elim[OF val] by auto\n  hence \"((y, T0) # \\<Gamma>) - (y, T0) = \\<Gamma>\" using remove_fresh_env[OF `y \\<sharp> \\<Gamma>` `valid \\<Gamma>`] by auto\n  hence te2:\"\\<Gamma> \\<turnstile> e2[y::=v] : A ; VE x\" using fresh_weakening[OF fr tsub `valid ((y,T0)#\\<Gamma>)`, of T0]  by auto\n  have szf:\"f \\<guillemotleft> App e1 e2\" using sz by auto\n  note ih[OF szf tf(1)]\n  then obtain T' F' where  tfsub:\"\\<Gamma> \\<turnstile> f[y::=v] : T' ; F'  \"\" \\<turnstile> T' <: B \" \"\\<turnstile> F' <e: Fn\" by auto\n  hence \" \\<turnstile> T' <: A1 \\<rightarrow> T : Latent S \" using  `\\<turnstile> B <: A1 \\<rightarrow> T : Latent S` by auto\n  hence \"\\<Gamma> \\<turnstile> (App f e2)[y::=v] : T ; TE S x\" using te2 tfsub `\\<turnstile> A <: A1` by auto\n  thus ?thesis using sz using trm.inject by auto\nqed\n\ninductive_cases te_elim_auto: \"\\<Gamma> \\<turnstile> e : T ; TE S x\"\nthm te_elim_auto\n\nlemma subst_preserve_TE:\n  fixes v\n  assumes tapp:\"(y,T0)#\\<Gamma> \\<turnstile> e : T ; TE S x\"\n  and neq:\"y \\<noteq> x\"\n  and val:\"valid ((y,T0)#\\<Gamma>)\"\n  and ih: \"!! t bc bf . \\<lbrakk>t \\<guillemotleft> e;  (y, T0) # \\<Gamma> \\<turnstile> t : bc ; bf \\<rbrakk> \n  \\<Longrightarrow> \\<exists>T' F'.  \\<Gamma> \\<turnstile> t[y::=v] : T' ; F'  \\<and> \\<turnstile> T' <: bc \\<and> \\<turnstile> F' <e: bf\"\n  shows \"\\<Gamma> \\<turnstile> e[y::=v] : T ; TE S x\"\nproof -\n  obtain e1 e2 where \"e = App e1 e2\" using te_elim_auto[OF tapp, of thesis] by auto\n  hence A:\"(y,T0)#\\<Gamma> \\<turnstile> App e1 e2 : T ; TE S x\" using tapp by auto\n  note subst_preserve_TE_app[OF A neq val , of v]\n  have \"!! t bc bf . \\<lbrakk>t \\<guillemotleft> App e1 e2;  (y, T0) # \\<Gamma> \\<turnstile> t : bc ; bf \\<rbrakk> \n    \\<Longrightarrow> \\<exists>T' F'.  \\<Gamma> \\<turnstile> t[y::=v] : T' ; F'  \\<and> \\<turnstile> T' <: bc \\<and> \\<turnstile> F' <e: bf\" using ih `e = App e1 e2` by auto\n  hence \"\\<Gamma> \\<turnstile> App e1 e2[y::=v] : T ; TE S x\" using subst_preserve_TE_app[OF A neq val , of v] by auto\n  thus ?thesis using `e = App e1 e2` by auto\nqed\n  \ninductive_cases lam_latent_eff_elim_auto: \"\\<Gamma> \\<turnstile> Lam[x:T].b : S1 \\<rightarrow> S2 : Latent U ; F\"\nthm lam_latent_eff_elim_auto\n\nlemma preserve_subst:\n  assumes \"(x,T0)#\\<Gamma> \\<turnstile> e : T ; F\" and \"\\<Gamma> \\<turnstile> e' : T1 ; G\" and \"\\<turnstile> T1 <: T0\" and \"valid ((x,T0)#\\<Gamma>)\" \n  and \"closed e'\" and \"e' : values\"\n  shows \"EX T' F'. \\<Gamma> \\<turnstile> e[x::=e'] : T' ; F' \\<and> \\<turnstile> T' <: T \\<and> \\<turnstile> F' <e: F\"\n  using prems\nproof (nominal_induct e avoiding: \\<Gamma> x e' T T1 T0 F G rule: trm_comp_induct)\n  case (Var v)\n  have a1: \"\\<Gamma> \\<turnstile>e':T1;G\" by fact\n  have a2: \"((x,T0)#\\<Gamma>) \\<turnstile> Var v:T;F\" by fact\n  hence a21: \"(v,T)\\<in>set((x,T0)#\\<Gamma>)\" and a22: \"valid((x,T0)#\\<Gamma>)\" and a22b:\"F = VE v\"\n    using var_ty_elim[of \"(x, T0) # \\<Gamma>\"] by auto\n  from a22 have a23: \"valid \\<Gamma>\" and a24: \"x\\<sharp>\\<Gamma>\" by (auto dest: valid_elim) \n  from a24 have a25: \"\\<not>(\\<exists>\\<tau>. (x,\\<tau>)\\<in>set \\<Gamma>)\" by (rule fresh_context)\n  show ?case\n  proof (cases \"v=x\")\n    assume case1: \"v=x\"\n    hence \"(Var v)[x::=e'] = e'\" by simp\n    hence A:\"\\<Gamma> \\<turnstile> (Var v)[x::=e'] : T1; G\" using Var by auto\n    have \"simple_eff G\" using closed_eff `closed e'` prems by auto\n    hence C:\"\\<turnstile> G <e: F\" using a22b simple_eff_below_ve by auto\n    have B:\"T = T0\"\n    proof (rule ccontr)\n      assume a3:\"T ~= T0\"\n      from a3 a21 have \"(v,T)\\<in>set \\<Gamma>\" by force\n      with case1 a25 show False by force \n    qed\n    hence D:\"\\<turnstile> T1 <: T\" using  `\\<turnstile> T1 <: T0` by auto\n    have \"~ (\\<exists>S y. F = TE S y)\" using a22b by auto\n    thus ?thesis using A a22b C D by blast\n  next\n    assume case2: \"v\\<noteq>x\"\n    with a21 have a26: \"(v,T)\\<in>set \\<Gamma>\" by force\n    have a27:\" Var v[x::=e'] = Var v\" using case2 by simp\n    from a23 a26 a27 have \"\\<Gamma> \\<turnstile> Var v:T;VE v\" by force\n    thus ?thesis using a27 a22b by auto\n  qed\nnext\n  case (Num n)\n  have A:\"(Num n)[x::=e'] = Num n\" by auto\n  have B:\"F = eff.TT\" using Num num_ty_elim by auto\n  have \"T = ty.Int\" using num_ty_elim Num by auto\n  hence \"\\<Gamma> \\<turnstile> (Num n)[x::=e'] : T ; eff.TT\" using Num A valid_elim[of x T0 \\<Gamma>] by auto\n  thus ?case using Num B by auto\nnext\n  case (Bool b)\n  have v:\"valid \\<Gamma>\" using prems typing_valid by auto\n  have A:\"(Bool b)[x::=e'] = Bool b\" by auto\n  thus ?case \n  proof (cases b)\n    case True\n    hence B:\"T = ty.TT\" and \"F = TT\" using Bool true_ty_elim by auto\n    thus ?thesis using A v True by auto\n  next\n    case False\n    hence B:\"T = ty.FF\" and \"F = FF\" using Bool false_ty_elim by auto\n    thus ?thesis using A v False by auto\n  qed\nnext\n  case (BI b)\n  have A:\"(BI b)[x::=e'] = (BI b)\" by auto\n  have B:\"F = eff.TT\" using BI bi_ty_elim by auto\n  have \"T = \\<Delta>\\<^isub>\\<tau> b\" using bi_ty_elim BI by auto\n  hence \"\\<Gamma> \\<turnstile> (BI b)[x::=e'] : T ; eff.TT\" using BI A valid_elim[of x T0 \\<Gamma>] by  auto\n  thus ?case using BI B by auto\nnext\n  case (App s1 s2 \\<Gamma>' x' e'' T' T1' T0' F' G')\n  have ih_s1: \"\\<And>c \\<sigma> T F T' F' e' \\<Gamma>. ((c,\\<sigma>)#\\<Gamma>) \\<turnstile> s1:T; F \\<Longrightarrow> closed e' \\<Longrightarrow> e' : values \\<Longrightarrow> valid ((c,\\<sigma>)#\\<Gamma>) \\<Longrightarrow> \\<Gamma>\\<turnstile> e': T' ; F' \\<Longrightarrow> \\<turnstile> T' <: \\<sigma> \\<Longrightarrow> EX S G. \\<Gamma> \\<turnstile> s1[c::=e']:S ; G \\<and> \\<turnstile> S <: T \\<and> \\<turnstile> G <e: F\" .\n  have ih_s2: \"\\<And>c \\<sigma> T F T' F' e' \\<Gamma>. ((c,\\<sigma>)#\\<Gamma>) \\<turnstile> s2:T; F \\<Longrightarrow> closed e' \\<Longrightarrow> e' : values \\<Longrightarrow> valid ((c,\\<sigma>)#\\<Gamma>) \\<Longrightarrow> \\<Gamma>\\<turnstile> e': T' ; F' \\<Longrightarrow> \\<turnstile> T' <: \\<sigma> \\<Longrightarrow> EX S G. \\<Gamma> \\<turnstile> s2[c::=e']:S ; G \\<and> \\<turnstile> S <: T \\<and> \\<turnstile> G <e: F\" .\n  have appty:\"((x',T0')#\\<Gamma>')\\<turnstile>App s1 s2 : T'; F'\" .\n  from appty have\n    elim1:\"\\<exists>T0 T0'a T1 le eff' eff'' U.(x',T0')#\\<Gamma>' \\<turnstile> s1 :U;eff' \\<and> (x',T0')# \\<Gamma>'\\<turnstile> s2 : T0'a;eff'' \\<and> \\<turnstile> U <: T0\\<rightarrow>T1:le \\<and> \\<turnstile> T0'a <: T0 \\<and> T1 = T'\"\n    using app_ty_elim by auto\n  from appty \n  have elim2:\"(x', T0') # \\<Gamma>' \\<turnstile> App s1 s2 : T' ; FF \\<Longrightarrow> \\<exists>T0 T0'a leS eff' eff'' le U.(x',T0')#\\<Gamma>' \\<turnstile> s1 :U;eff' \\<and> \n    (x',T0')# \\<Gamma>'\\<turnstile> s2 : T0'a;eff''  \\<and> \\<turnstile> T0'a <: T0\\<and> \\<turnstile> U <: T0\\<rightarrow>T':le \\<and> le = Latent leS  \\<and> ~ (\\<turnstile> T0'a <: leS) \\<and> s2 : values \\<and> closed s2\"\n    using app_ty_ff_elim[of \"((x',T0')#\\<Gamma>')\" s1 s2 T'] by blast\n  have elim3:\"(x', T0') # \\<Gamma>' \\<turnstile> App s1 s2 : T' ; TT \\<Longrightarrow> \\<exists>T0 T0'a leS eff' eff'' U le.(x',T0')#\\<Gamma>' \\<turnstile> s1 :U;eff' \\<and> \n    (x',T0')# \\<Gamma>'\\<turnstile> s2 : T0'a;eff'' \\<and> \\<turnstile> T0'a <: T0  \\<and> \\<turnstile> U <: T0\\<rightarrow>T':le \\<and> le = Latent leS \\<and> \\<turnstile> T0'a <: leS \" \n    using app_ty_tt_elim[of \"((x',T0')#\\<Gamma>')\" s1 s2 T'] by blast\n  from elim1  obtain T0 T0'a T1 le eff' eff'' U where\n    P:\"(x',T0')#\\<Gamma>' \\<turnstile> s1 :U;eff'\"\" (x',T0')# \\<Gamma>'\\<turnstile> s2 : T0'a;eff''\"\" \\<turnstile> T0'a <: T0 \"\" T1 = T'\" \"\\<turnstile> U <: T0\\<rightarrow>T1:le\" by auto\n  hence \"EX S1 G1. \\<Gamma>' \\<turnstile> s1[x'::=e''] : S1 ; G1 \\<and> \\<turnstile> S1 <: U \\<and> \\<turnstile> G1 <e: eff'\"\n    using ih_s1 App by auto\n  then obtain S1 G1 where Q:\" \\<Gamma>' \\<turnstile> s1[x'::=e''] : S1 ; G1 \"\" \\<turnstile> S1 <: U\" \"\\<turnstile> G1 <e: eff'\" by auto\n  have sub1:\"\\<turnstile>S1 <: T0\\<rightarrow>T1:le\" using P Q by auto\n    (* then apply ih_s2, get something about the substition of s2, and put it all back together. *)\n  from P have \"EX S G. \\<Gamma>' \\<turnstile> s2[x'::=e'']:S ; G \\<and> \\<turnstile> S <: T0'a \\<and> \\<turnstile> G <e: eff''\"\n    using ih_s2[of x' T0' \\<Gamma>' T0'a eff''] App by auto\n  then obtain S2 G2 where S:\"\\<Gamma>' \\<turnstile> s2[x'::=e'']:S2 ; G2 \"\" \\<turnstile> S2 <: T0'a\" \"\\<turnstile> G2 <e: eff''\" by auto\n  let ?ns1 = \"s1[x'::=e'']\" and ?ns2 = \"s2[x'::=e'']\"\n  have sub2:\"\\<turnstile> S2 <: T0\" using P S by auto\n  have L1:\"\\<Gamma>' \\<turnstile> App ?ns1 ?ns2 : T1 ; NE\" using Q S sub1 sub2 by auto\n  have L2:\"T1 = T'\" .\n  show ?case using appty\n  proof (nominal_induct F' rule: eff.induct)\n    case NE thus ?case using L1 L2 by auto\n  next\n    case VE thus ?case using L1 L2 by auto\n  next\n    case (TE ty var) thus ?case using L1 L2 by auto\n  next\n    case TT\n    from elim3 TT  obtain T0 T0'a T1 le leS eff' eff'' U where\n      P:\"(x',T0')#\\<Gamma>' \\<turnstile> s1 :U;eff'\"\" (x',T0')# \\<Gamma>'\\<turnstile> s2 : T0'a;eff''\"\" \\<turnstile> T0'a <: T0 \"\" T1 = T'\" \"\\<turnstile> U <: T0\\<rightarrow>T1:le\"\n      \"le = Latent leS\" \"\\<turnstile> T0'a <: leS\" by auto\n    hence \"EX S1 G1. \\<Gamma>' \\<turnstile> s1[x'::=e''] : S1 ; G1 \\<and> \\<turnstile> S1 <: U \\<and> \\<turnstile> G1 <e: eff'\"\n      using ih_s1 App by blast\n    then obtain S1 G1 where Q:\" \\<Gamma>' \\<turnstile> s1[x'::=e''] : S1 ; G1 \"\" \\<turnstile> S1 <: U\" \"\\<turnstile> G1 <e: eff'\" by auto\n    hence R:\"\\<turnstile> S1 <: T0\\<rightarrow>T1:le\" using P by auto\n      (* then apply ih_s2, get something about the substition of s2, and put it all back together. *)\n    from P have \"EX S G. \\<Gamma>' \\<turnstile> s2[x'::=e'']:S ; G \\<and> \\<turnstile> S <: T0'a \\<and> \\<turnstile> G <e: eff''\"\n      using ih_s2[of x' T0' \\<Gamma>' T0'a eff''] App by auto\n    then obtain S2 G2 where S:\"\\<Gamma>' \\<turnstile> s2[x'::=e'']:S2 ; G2 \"\" \\<turnstile> S2 <: T0'a\" \"\\<turnstile> G2 <e: eff''\" by auto\n    let ?ns1 = \"s1[x'::=e'']\" and ?ns2 = \"s2[x'::=e'']\"\n    have noover: \"\\<turnstile> S2 <: leS\" using `\\<turnstile> S2 <: T0'a` `\\<turnstile> T0'a <: leS` by auto\n    have L1:\"\\<Gamma>' \\<turnstile> App ?ns1 ?ns2 : T1 ; TT\" using P Q R S noover T_AppPredFalse[of \\<Gamma>' \" s1[x'::=e'']\" U] by auto\n    have L2:\"T1 = T'\" .\n    from L1 L2 show ?case by auto\n  next\n    case FF\n    from elim2 FF  obtain T0 T0'a T1 le leS eff' eff'' U where\n      P:\"(x',T0')#\\<Gamma>' \\<turnstile> s1 :U;eff'\"\" (x',T0')# \\<Gamma>'\\<turnstile> s2 : T0'a;eff''\"\" \\<turnstile> T0'a <: T0 \"\" T1 = T'\" \"\\<turnstile> U <: T0\\<rightarrow>T1:le\"\n      \"le = Latent leS\" \"~ (\\<turnstile> T0'a <: leS)\" \"s2 :values\" \"closed s2\" by auto\n    hence \"EX S1 G1. \\<Gamma>' \\<turnstile> s1[x'::=e''] : S1 ; G1 \\<and> \\<turnstile> S1 <: U \\<and> \\<turnstile> G1 <e: eff'\"\n      using ih_s1 App by auto\n    then obtain S1 G1 where Q:\" \\<Gamma>' \\<turnstile> s1[x'::=e''] : S1 ; G1 \"\" \\<turnstile> S1 <: U\" \"\\<turnstile> G1 <e: eff'\" by auto\n    hence R:\"\\<turnstile> S1 <: T0\\<rightarrow>T1:le\" using P by auto\n      (* then apply ih_s2, get something about the substition of s2, and put it all back together. *)\n    from P have \"EX S G. \\<Gamma>' \\<turnstile> s2[x'::=e'']:S ; G \\<and> \\<turnstile> S <: T0'a \\<and> \\<turnstile> G <e: eff''\"\n      using ih_s2[of x' T0' \\<Gamma>' T0'a eff''] App by auto\n    then obtain S2 G2 where S:\"\\<Gamma>' \\<turnstile> s2[x'::=e'']:S2 ; G2 \"\" \\<turnstile> S2 <: T0'a\" \"\\<turnstile> G2 <e: eff''\" by auto\n    let ?ns1 = \"s1[x'::=e'']\" and ?ns2 = \"s2[x'::=e'']\"\n    have \"x' \\<sharp> s2\" using closed_def fresh_def[of x' s2] `closed s2` by auto\n    hence \"s2 = ?ns2\" using forget by auto\n    hence S':\"\\<Gamma>' \\<turnstile> ?ns2 : T0'a ; eff''\" \n      using `(x',T0')#\\<Gamma>' \\<turnstile> s2 : T0'a ; eff''` fresh_weakening_cons `valid ((x',T0')#\\<Gamma>')` `x' \\<sharp> s2`\n      by auto\n\n    have noover: \"~(\\<turnstile> T0'a <: leS)\" .\n    have T:\"closed ?ns2\" \"?ns2 : values\" using `s2 = ?ns2` `closed s2` `s2 : values` by auto\n    have L1:\"\\<Gamma>' \\<turnstile> App ?ns1 ?ns2 : T1 ; FF\" using P Q R S' T noover  by auto\n    have L2:\"T1 = T'\" by fact\n    from L1 L2 show ?case by auto\n  qed\nnext\n  case (Lam a body \\<Gamma>' x' e''  T' T1' T0' F' G' ty )\n  hence f1: \"a\\<sharp>\\<Gamma>'\" and f2: \"a\\<noteq>x'\" and f2': \"x'\\<sharp>a\" and f3: \"a\\<sharp>e''\" and f4: \"a\\<sharp>((x',T0')#\\<Gamma>')\"\n    by (auto simp add: fresh_atm fresh_prod fresh_list_cons)\n  have c1: \"((x',T0')#\\<Gamma>')\\<turnstile>Lam [a:ty].body : T' ; F'\" by fact\n(*  hence \"\\<exists>\\<tau>2 eff L S. ((a,ty)#(x',T0')#\\<Gamma>') \\<turnstile> body : \\<tau>2 ; eff \\<and> T'=ty\\<rightarrow>\\<tau>2:L  \\<and> F' = TT\" using f4 abs_ty_elim by auto *)\n  then obtain \\<tau>2 eff L S where c11: \"T'=ty\\<rightarrow>\\<tau>2:L\" and c12: \"((a,ty)#(x',T0')#\\<Gamma>') \\<turnstile> body : \\<tau>2 ; eff\" and \"F' = TT\"\n    and c13:\"L = latent_eff.NE \\<or> (eff = TE S a \\<and> L = Latent S)\" using f4 abs_ty_elim by blast\n  from c12 have \"valid ((a,ty)#(x',T0')#\\<Gamma>')\" using Lam by auto\n  hence ca: \"valid \\<Gamma>'\" and cb: \"a\\<sharp>\\<Gamma>'\" and cc: \"x'\\<sharp>\\<Gamma>'\" \n    by (auto dest: valid_elim simp add: fresh_list_cons)\n  have c2: \"((a,ty)#(x',T0')#\\<Gamma>') \\<lless> ((x',T0')#(a,ty)#\\<Gamma>')\" by force\n  have c3: \"valid ((x',T0')#(a,ty)#\\<Gamma>')\"\n    by (rule v2, rule v2, auto simp add: fresh_list_cons fresh_prod ca cb cc f2' fresh_ty)\n  from c12 c2 c3 have c14: \"((x',T0')#(a,ty)#\\<Gamma>') \\<turnstile> body : \\<tau>2 ; eff\" using `valid ((a, ty) # (x', T0') # \\<Gamma>')`\n    by (force intro: weakening)\n  let ?inner\\<Gamma> = \"(a,ty)#\\<Gamma>'\"\n  have validig:\"valid ?inner\\<Gamma>\" using `a \\<sharp> \\<Gamma>'` `valid \\<Gamma>'` by auto\n  have c15:\"\\<Gamma>' \\<lless>  ?inner\\<Gamma>\" by auto\n  hence c16:\"?inner\\<Gamma> \\<turnstile> e'' : T1' ; G'\"\n    using weakening[of \\<Gamma>' _ _ _ ?inner\\<Gamma>] `\\<Gamma>' \\<turnstile> e'' : T1' ; G'` validig `valid \\<Gamma>'` by simp\n  have \"EX TA0 FA0. ?inner\\<Gamma> \\<turnstile> body[x'::=e''] : TA0 ; FA0 \\<and> \\<turnstile> TA0 <: \\<tau>2 \\<and> \\<turnstile> FA0 <e: eff\"\n    using c16 Lam(10)[of x' T0' ?inner\\<Gamma> \\<tau>2 eff e'' T1' G'] ` \\<turnstile> T1' <: T0'` `valid ((x', T0') # (a, ty) # \\<Gamma>')` c14 `closed e''`\n    `e'' : values`\n    by auto\n  then obtain TA0 FA0 where body_ty:\"?inner\\<Gamma> \\<turnstile> body[x'::=e''] : TA0 ; FA0 \"\" \\<turnstile> TA0 <: \\<tau>2\" by auto\n  hence L11:\"\\<Gamma>' \\<turnstile> (Lam[a:ty].(body[x'::=e''])) : ty \\<rightarrow> TA0 : latent_eff.NE; eff.TT\" using `a \\<sharp> \\<Gamma>'` by auto \n  note Lam(9)[OF _ _ `(a, ty)# \\<Gamma>' \\<turnstile> e'' : T1' ; G'` `\\<turnstile> T1' <: T0'` `valid ((x', T0')# (a, ty) # \\<Gamma>')` `closed e''` `e'' : values`]\n  hence \"!! t bc bf . \\<lbrakk>t \\<guillemotleft> Lam [a:ty].body;  (x', T0') #(a, ty)# \\<Gamma>' \\<turnstile> t : bc ; bf \\<rbrakk>\n\\<Longrightarrow> \\<exists>T' F'.  (a, ty)#\\<Gamma>' \\<turnstile> t[x'::=e''] : T' ; F'  \\<and> \\<turnstile> T' <: bc \\<and> \\<turnstile> F' <e: bf\" .\n  hence ih_body:\"!! t bc bf . \\<lbrakk>t \\<guillemotleft> body;  (x', T0') # (a, ty)#\\<Gamma>' \\<turnstile> t : bc ; bf \\<rbrakk>\n\\<Longrightarrow> \\<exists>T' F'.  (a, ty)#\\<Gamma>' \\<turnstile> t[x'::=e''] : T' ; F'  \\<and> \\<turnstile> T' <: bc \\<and> \\<turnstile> F' <e: bf\" by auto\n  hence L12:\"L = Latent S \\<Longrightarrow> \\<Gamma>' \\<turnstile> (Lam[a:ty].(body[x'::=e''])) : ty \\<rightarrow> \\<tau>2 : Latent S; eff.TT\" \n  proof -\n    assume \"L = Latent S\"\n    hence \"eff = TE S a\" using c13 by auto\n    hence c12':\"(a, ty) # (x', T0') # \\<Gamma>' \\<turnstile> body : \\<tau>2 ; TE S a\" using c12 by simp\n    have c12'':\" (x', T0') # (a, ty) # \\<Gamma>' \\<turnstile> body : \\<tau>2 ; TE S a\" using weakening[OF c12' _ c2 ] \n      using `valid ((x', T0') # (a, ty) # \\<Gamma>')` `valid ((a, ty) # (x', T0') # \\<Gamma>')` by auto\n    have f2':\"x' \\<noteq> a\" using f2 by auto\n    note body_ty subst_preserve_TE[OF c12'' f2' `valid ((x', T0') # (a, ty) # \\<Gamma>')` , of e'']\n    hence \"(a, ty) # \\<Gamma>' \\<turnstile> body[x'::=e''] : \\<tau>2 ; TE S a\" using ih_body by auto\n    hence \"?inner\\<Gamma> \\<turnstile> body[x'::=e''] : \\<tau>2 ; TE S a \" .\n    thus ?thesis using `a \\<sharp> \\<Gamma>'` by auto\n  qed\n  (* from L11 L12 have L1:\"\\<Gamma>' \\<turnstile> (Lam[a:ty].(body[x'::=e''])) : ty \\<rightarrow> TA0 : L; eff.TT\" using c13 by auto *)\n  have L21:\"\\<turnstile> ty \\<rightarrow> TA0 : L <: T'\" using c11 ` \\<turnstile> TA0 <: \\<tau>2` by auto\n  have L22: \"\\<turnstile> ty \\<rightarrow> \\<tau>2 : L <: T'\" using c11 by auto\n  have L3:\"(Lam[a:ty].body)[x'::=e''] = (Lam[a:ty].(body[x'::=e'']))\" using Lam by auto\n  have L4:\"\\<turnstile> eff.TT <e: F'\" using `F' = TT` by auto\n  thm Lam\n  \n  have L5:\"!! Env a ty body T S x. Env \\<turnstile>  (Lam [a:ty].body) : T ; TE S x \\<Longrightarrow> False\"\n    proof -\n    fix Env a ty body T S x\n    assume  \"Env \\<turnstile>  (Lam [a:ty].body) : T ; TE S x\"\n    have  \" Env \\<turnstile>  (Lam [a:ty].body) : T ; TE S x \\<Longrightarrow> False\"\n      by (ind_cases \" Env \\<turnstile>  (Lam [a:ty].body) : T ; TE S x\") \n    thus False using prems by auto\n  qed\n\n  from L11 L12 L21 L22 L3 L4 L5[of \\<Gamma>' a _ ty ] c13\n  \n  show  ?case by auto\nnext\n  case (Iff t1 t2 t3 \\<Gamma>' x' e'' T' T0' T1' F' G')\n  let ?\\<Gamma> = \"(x', T1') # \\<Gamma>'\"\n  have A:\"(\\<exists> T1 T2 T3 F1 F2 F3. \n    (?\\<Gamma> \\<turnstile> t1 : T1 ; F1) \\<and> ?\\<Gamma> |+ F1 \\<turnstile> t2 : T2 ; F2 \\<and> ?\\<Gamma> |- F1 \\<turnstile> t3 : T3 ; F3 \\<and> \\<turnstile> T2 <: T'  \\<and> \\<turnstile> T3 <: T' \\<and> F' = NE)\n    \\<or>\n    (\\<exists> T1 T3 F3. (?\\<Gamma> \\<turnstile> t1 : T1 ; FF) \\<and> ?\\<Gamma> \\<turnstile> t3 : T3 ; F3 \\<and> \\<turnstile> T3 <: T' \\<and> F' = NE)\n    \\<or>\n    (\\<exists> T1 T2 F2. (?\\<Gamma> \\<turnstile> t1 : T1 ; TT) \\<and> ?\\<Gamma> \\<turnstile> t2 : T2 ; F2 \\<and> \\<turnstile> T2 <: T'  \\<and> F' = NE)\" using Iff if_ty_elim by auto\n  thus ?case\n  proof -\n    {\n      assume \"(\\<exists> T1 T2 T3 F1 F2 F3. \n        (?\\<Gamma> \\<turnstile> t1 : T1 ; F1) \\<and> ?\\<Gamma> |+ F1 \\<turnstile> t2 : T2 ; F2 \\<and> ?\\<Gamma> |- F1 \\<turnstile> t3 : T3 ; F3 \\<and> \\<turnstile> T2 <: T'  \\<and> \\<turnstile> T3 <: T' \\<and> F' = NE)\"\n      then obtain T1 T2 T3 F1 F2 F3 where\n\t\"?\\<Gamma> \\<turnstile> t1 : T1 ; F1 \"\" ?\\<Gamma> |+ F1 \\<turnstile> t2 : T2 ; F2 \"\" ?\\<Gamma> |- F1 \\<turnstile> t3 : T3 ; F3 \"\" \\<turnstile> T2 <: T'\"\"\\<turnstile> T3 <: T'\"\"F' = NE\"\n\tby auto\n      hence ?thesis\n      proof (nominal_induct F1 rule: eff.induct)\n\tcase NE\n\tfrom NE have \"\\<exists>S1 G1.  \\<Gamma>' \\<turnstile> t1[x'::=e''] : S1 ; G1  \\<and> \\<turnstile> S1 <: T1 \\<and> \\<turnstile> G1 <e: NE\" using Iff by auto\n\tthen obtain S1 G1 where  A:\"\\<Gamma>' \\<turnstile> t1[x'::=e''] : S1 ; G1  \"\" \\<turnstile> S1 <: T1 \"\" \\<turnstile> G1 <e: NE\" by auto\n\thave simple:\"simple_eff G1\" using `\\<turnstile> G1 <e: NE` below_ne_simple by auto\n\thave p1:\"(?\\<Gamma> \\<turnstile> t2 : T2 ; F2)\" using prems by auto\n\thave p2:\"(?\\<Gamma> \\<turnstile> t3 : T3 ; F3)\" using prems by auto\n\tfrom p1 have \"\\<exists>S2 G2.  \\<Gamma>' \\<turnstile> t2[x'::=e''] : S2 ; G2  \\<and> \\<turnstile> S2 <: T2 \\<and> \\<turnstile> G2 <e: F2\" using Iff by auto\n\tthen obtain S2 G2 where  B:\"\\<Gamma>' \\<turnstile> t2[x'::=e''] : S2 ; G2  \"\" \\<turnstile> S2 <: T2 \"\" \\<turnstile> G2 <e: F2\" by auto\n\tfrom p2 have \"\\<exists>S3 G3.  \\<Gamma>' \\<turnstile> t3[x'::=e''] : S3 ; G3  \\<and> \\<turnstile> S3 <: T3 \\<and> \\<turnstile> G3 <e: F3\" using Iff by auto\n\tthen obtain S3 G3 where  C:\"\\<Gamma>' \\<turnstile> t3[x'::=e''] : S3 ; G3  \"\" \\<turnstile> S3 <: T3 \"\" \\<turnstile> G3 <e: F3\" by auto\n\thave B':\"\\<Gamma>' |+ G1 \\<turnstile> t2[x'::=e''] : S2 ; G2\" using B simple by auto\n\thave C':\"\\<Gamma>' |- G1 \\<turnstile> t3[x'::=e''] : S3 ; G3\" using C simple by auto\n\thave D:\"\\<turnstile> S2 <: T'\" using prems B by auto\n\thave E:\"\\<turnstile> S3 <: T'\" using prems C by auto\n\tfrom A B'  C' D E have \" \\<Gamma>' \\<turnstile> Iff t1 t2 t3[x'::=e''] : T' ; comb_eff G1 G2 G3\" by (auto simp del: comb_eff.simps)\n\tthus ?case using `F' = NE` by auto\n      next\n\tcase TT\n\tfrom TT have \"\\<exists>S1 G1.  \\<Gamma>' \\<turnstile> t1[x'::=e''] : S1 ; G1  \\<and> \\<turnstile> S1 <: T1 \\<and> \\<turnstile> G1 <e: TT\" using Iff by auto\n\tthen obtain S1 G1 where  A:\"\\<Gamma>' \\<turnstile> t1[x'::=e''] : S1 ; G1  \"\" \\<turnstile> S1 <: T1 \"\" \\<turnstile> G1 <e: TT\" by auto\n\thave simple:\"G1 = TT\" using A no_sub_TT by blast\n\thave p1:\"(?\\<Gamma> \\<turnstile> t2 : T2 ; F2)\" using prems by auto\n\thave p2:\"(?\\<Gamma> \\<turnstile> t3 : T3 ; F3)\" using prems by auto\n\tfrom p1 have \"\\<exists>S2 G2.  \\<Gamma>' \\<turnstile> t2[x'::=e''] : S2 ; G2  \\<and> \\<turnstile> S2 <: T2 \\<and> \\<turnstile> G2 <e: F2\" using Iff by auto\n\tthen obtain S2 G2 where  B:\"\\<Gamma>' \\<turnstile> t2[x'::=e''] : S2 ; G2  \"\" \\<turnstile> S2 <: T2 \"\" \\<turnstile> G2 <e: F2\" by auto\n\tfrom p2 have \"\\<exists>S3 G3.  \\<Gamma>' \\<turnstile> t3[x'::=e''] : S3 ; G3  \\<and> \\<turnstile> S3 <: T3 \\<and> \\<turnstile> G3 <e: F3\" using Iff by auto\n\tthen obtain S3 G3 where  C:\"\\<Gamma>' \\<turnstile> t3[x'::=e''] : S3 ; G3  \"\" \\<turnstile> S3 <: T3 \"\" \\<turnstile> G3 <e: F3\" by auto\n\thave B':\"\\<Gamma>' |+ G1 \\<turnstile> t2[x'::=e''] : S2 ; G2\" using B simple by auto\n\thave C':\"\\<Gamma>' |- G1 \\<turnstile> t3[x'::=e''] : S3 ; G3\" using C simple by auto\n\thave D:\"\\<turnstile> S2 <: T'\" using prems B by auto\n\thave E:\"\\<turnstile> S3 <: T'\" using prems C by auto\n\tfrom A B' C' D E have \" \\<Gamma>' \\<turnstile> Iff t1 t2 t3[x'::=e''] : T' ; comb_eff G1 G2 G3\" by (auto simp del: comb_eff.simps)\n\tthus ?case using `F' = NE` by auto\n      next\n\tcase FF\n\tfrom FF have \"\\<exists>S1 G1.  \\<Gamma>' \\<turnstile> t1[x'::=e''] : S1 ; G1  \\<and> \\<turnstile> S1 <: T1 \\<and> \\<turnstile> G1 <e: FF\" using Iff by auto\n\tthen obtain S1 G1 where  A:\"\\<Gamma>' \\<turnstile> t1[x'::=e''] : S1 ; G1  \"\" \\<turnstile> S1 <: T1 \"\" \\<turnstile> G1 <e: FF\" by auto\n\thave simple:\"G1 = FF\" using A no_sub_FF by blast\n\thave p1:\"(?\\<Gamma> \\<turnstile> t2 : T2 ; F2)\" using prems by auto\n\thave p2:\"(?\\<Gamma> \\<turnstile> t3 : T3 ; F3)\" using prems by auto\n\tfrom p1 have \"\\<exists>S2 G2.  \\<Gamma>' \\<turnstile> t2[x'::=e''] : S2 ; G2  \\<and> \\<turnstile> S2 <: T2 \\<and> \\<turnstile> G2 <e: F2\" using Iff by auto\n\tthen obtain S2 G2 where  B:\"\\<Gamma>' \\<turnstile> t2[x'::=e''] : S2 ; G2  \"\" \\<turnstile> S2 <: T2 \"\" \\<turnstile> G2 <e: F2\" by auto\n\tfrom p2 have \"\\<exists>S3 G3.  \\<Gamma>' \\<turnstile> t3[x'::=e''] : S3 ; G3  \\<and> \\<turnstile> S3 <: T3 \\<and> \\<turnstile> G3 <e: F3\" using Iff by auto\n\tthen obtain S3 G3 where  C:\"\\<Gamma>' \\<turnstile> t3[x'::=e''] : S3 ; G3  \"\" \\<turnstile> S3 <: T3 \"\" \\<turnstile> G3 <e: F3\" by auto\n\thave B':\"\\<Gamma>' |+ G1 \\<turnstile> t2[x'::=e''] : S2 ; G2\" using B simple by auto\n\thave C':\"\\<Gamma>' |- G1 \\<turnstile> t3[x'::=e''] : S3 ; G3\" using C simple by auto\n\thave D:\"\\<turnstile> S2 <: T'\" using prems B by auto\n\thave E:\"\\<turnstile> S3 <: T'\" using prems C by auto\n\tfrom A B' C' D E have \" \\<Gamma>' \\<turnstile> Iff t1 t2 t3[x'::=e''] : T' ; comb_eff G1 G2 G3\" by (auto simp del: comb_eff.simps)\n\tthus ?case using `F' = NE` by auto\n      next\n\tcase (VE z)\n\thence  A:\"t1 = (Var z) \" \"?\\<Gamma> \\<turnstile> Var z : T1 ; VE z\"\n\t  using ve_ty_elim[OF `?\\<Gamma> \\<turnstile> t1 :  T1;  VE z`] using eff.inject by auto\n\thave size1:\"(Var z\\<guillemotleft>Iff t1 t2 t3)\" using A by simp\n\tnote Iff(1)[of \"Var z\"]\n        hence ih_f:\"!! c \\<sigma> \\<Gamma> T F e' T0 F0 . \n          (c,\\<sigma>)#\\<Gamma> \\<turnstile> (Var z) : T ; F \\<Longrightarrow> \\<Gamma> \\<turnstile> e' : T0 ; F0 \\<Longrightarrow> \\<turnstile> T0 <: \\<sigma> \\<Longrightarrow> valid ((c,\\<sigma>)#\\<Gamma>) \\<Longrightarrow> closed e' \\<Longrightarrow> e' : values\n          \\<Longrightarrow> EX T' F' . \\<Gamma> \\<turnstile> (Var z)[c::=e'] : T' ; F' \\<and> \\<turnstile> T' <: T \\<and> \\<turnstile> F' <e: F\" using size1 by auto\n        have \"EX A' Fn' . \\<Gamma>' \\<turnstile> (Var z)[x'::=e''] : A' ; Fn' \\<and> \\<turnstile> A' <: T1 \\<and> \\<turnstile> Fn' <e: VE z\" \n           using ih_f A Iff by auto\n\tthen obtain A' Fn' where  B:\"\\<Gamma>' \\<turnstile> (Var z)[x'::=e''] : A' ; Fn' \\<and> \\<turnstile> A' <:T1\" by auto\n\tlet ?mapfun = \"(%f. (% (v,ty). (if (z = v) then (v,f ty.FF ty) else (v,ty))))\"\n        let ?\\<Gamma>1 = \"(map (?mapfun remove) \\<Gamma>')\"\n        let ?\\<Gamma>2 = \"(map (?mapfun replace) \\<Gamma>')\"          \n        have \"valid \\<Gamma>'\" using `valid ?\\<Gamma>` using valid_elim[of x' T1' \\<Gamma>'] by auto\n\tshow ?case \n\tproof (cases \"x' = z\")\n\t  case True\n          from A True have  \"(Var z)[x'::=e''] = e''\" by auto\n          hence D:\"\\<Gamma>' \\<turnstile> (Var z)[x'::=e''] : T0' ; G'\" \"closed ((Var z)[x'::=e''])\" \"((Var z)[x'::=e'']) : values\"\n\t    using Iff by auto\n          have \"\\<turnstile> T0' <: T1'\" .\n          note var_ty_elim[of ?\\<Gamma> z _ \"VE z\"]\n          hence \"(x', T1') : set ?\\<Gamma>\" using A True by auto\n          have \"?\\<Gamma> \\<turnstile> (Var x') : T1' ; VE x'\" using `valid ?\\<Gamma>` by auto\n\t  have \"simple_ty T0'\" using `\\<Gamma>' \\<turnstile> e'' : T0' ; G'` `e'' : values` value_simple_type by auto\n\t  let ?mapfun = \"(%f. (% (v,ty). (if (z = v) then (v,f ty.FF ty) else (v,ty))))\"\n          let ?\\<Gamma>1 = \"(map (?mapfun remove) \\<Gamma>')\"\n          let ?\\<Gamma>2 = \"(map (?mapfun replace) \\<Gamma>')\"  \n\n          have \"?\\<Gamma>1 = envop remove z ty.FF \\<Gamma>'\" by auto\n          have \"?\\<Gamma>2 = envop replace z ty.FF \\<Gamma>'\" by auto\n          have \"x' \\<sharp> \\<Gamma>'\" using Iff valid_elim[of x' T1' \\<Gamma>'] by auto\n          hence \"?\\<Gamma>1 = \\<Gamma>'\" using True envop_forget `valid \\<Gamma>'` by auto\n          hence GA:\"?\\<Gamma> |+ VE z = (x',remove ty.FF T1') # \\<Gamma>'\" using True by auto\n          hence G1:\"\\<dots> \\<turnstile> t2 : T2; F2\" using `(?\\<Gamma> |+ VE z)\\<turnstile> t2 : T2 ; F2` by auto\n          have \"?\\<Gamma>2 = \\<Gamma>'\" using `x' \\<sharp> \\<Gamma>'` True envop_forget `valid \\<Gamma>'` by auto\n          hence \"?\\<Gamma> |- VE z = (x',replace ty.FF T1') # \\<Gamma>'\" using True by auto\n\t  hence GB:\"?\\<Gamma> |- VE z = (x',ty.FF) # \\<Gamma>'\" by auto\n          hence G2:\"\\<dots> \\<turnstile> t3 : T3; F3\" using `(?\\<Gamma> |- VE z)\\<turnstile> t3 : T3 ; F3` by auto\n          have \"valid (?\\<Gamma> |+ VE z)\" using `valid ?\\<Gamma>` envplus_valid[of ?\\<Gamma> \"VE z\"] by auto\n          hence G3:\"valid ((x',remove ty.FF T1') # \\<Gamma>')\" using GA by auto\n          have \"valid (?\\<Gamma> |- VE z)\" using `valid ?\\<Gamma>` envminus_valid[of ?\\<Gamma> \"VE z\"] by auto\n          hence G4:\"valid ((x',ty.FF) # \\<Gamma>')\" using GB by auto        \n\t  show ?thesis \n\t  proof (cases \"e'' = Bool False\")\n\t    case True\n\t    hence \"(Var z)[x'::=e''] = Bool False\" using `x' = z` by auto\n\t    hence \"t1[x'::=e''] = Bool False\" using `t1 = Var z` by auto\n\t    hence X1:\"?\\<Gamma> \\<turnstile> t1[x'::=e''] : ty.FF ; FF\" using `valid ?\\<Gamma>` by auto\n\t    have \"\\<Gamma>' \\<turnstile> e'' : ty.FF ; FF\" using True `valid \\<Gamma>'` by auto\n\t    note `?\\<Gamma> |- VE z = (x', ty.FF) # \\<Gamma>'`\n\t    hence \"valid  ((x', ty.FF) # \\<Gamma>')\" using G4 by auto\n\t    have X2:\"(x', ty.FF) # \\<Gamma>' \\<turnstile> t3 : T3 ; F3\" using VE  `?\\<Gamma> |- VE z = (x', ty.FF) # \\<Gamma>'` by auto\n\t    note Iff(4)[ OF X2 `\\<Gamma>' \\<turnstile> e'' : ty.FF ; FF ` _ `valid ((x', ty.FF) # \\<Gamma>')`]\n\t    then obtain T'' F'' where X3:\"\\<Gamma>' \\<turnstile> t3[x'::=e''] : T'' ; F''  \" and X4:\" \\<turnstile> T'' <: T3 \"\" \\<turnstile> F'' <e: F3\"\n\t      using `closed e''` `e'' : values` by auto\n\t    hence \"\\<turnstile> T'' <: T'\" using `\\<turnstile> T3 <: T'` by auto\n\t    hence \"\\<Gamma>' \\<turnstile> Iff (Bool False) (t2[x'::=e'']) (t3[x'::=e'']) : T'' ; NE\" using `valid \\<Gamma>'` X3 by auto\n\t    hence \"\\<Gamma>' \\<turnstile> (Iff t1 t2 t3)[x'::=e''] : T'' ; NE\" using ` t1[x'::=e''] = Bool False` by auto\n\t    thus ?thesis  using `\\<turnstile> T'' <: T'` `F' = NE` by auto\n\t  next\n\t    case False\n\t    hence \"(Var z)[x'::=e''] = e''\" using `x' = z` by auto\n\t    hence \"t1[x'::=e''] = e''\" using `t1 = Var z` by auto\n\t    hence X1:\"\\<Gamma>' \\<turnstile> t1[x'::=e''] : T0' ; G'\" by auto\n\t    have \"\\<Gamma>' \\<turnstile> e'' : T0' ; G'\" .\n\t    hence \"G' = TT\" using value_effect_tt_or_ff[OF `e'' : values` `\\<Gamma>' \\<turnstile> e'' : T0' ; G'`] False by auto\n\t    hence X2:\"\\<Gamma>' \\<turnstile> t1[x'::=e''] : T0' ; TT\" using X1 by auto\n\t    have \"\\<turnstile> T0' <: T1'\" .\n\n\t    have X3:\"\\<not> \\<turnstile> T0' <: ty.FF\"\n\t    proof (rule ccontr)\n\t      assume \"\\<not>\\<not> \\<turnstile> T0' <: ty.FF\"\n\t      hence \"\\<turnstile> T0' <: ty.FF\" by simp\n\t      hence \"\\<turnstile> T0' <: BoolTy\" using BoolTy_def by auto\n\t      hence \"EX b. e'' = Bool b\" using bool_value `e'' : values ` `\\<Gamma>' \\<turnstile> e'' : T0' ; G'` by auto\n\t      then obtain b where A:\"e'' = Bool b\" by auto\n\t      thus False\n\t      proof (cases b)\n\t\tcase False\n\t\tthus ?thesis using A `e'' ~= Bool False` by auto\n\t      next\n\t\tcase True\n\t\thence \"T0' = ty.TT\" using  `\\<Gamma>' \\<turnstile> e'' : T0' ; G'` A true_ty_elim by auto\n\t\tthus ?thesis using `\\<turnstile> T0' <: ty.FF` tt_sub_ff by auto\n\t      qed\n\t    qed\n\n\n\t    \n\t    let ?rty = \"remove ty.FF T1'\"\n\n\t    note `?\\<Gamma> |+ VE z = (x', ?rty) # \\<Gamma>'`\n\t    hence \"valid  ((x',  ?rty) # \\<Gamma>')\" using G3 by auto\n\t    have X2:\"(x', ?rty) # \\<Gamma>' \\<turnstile> t2 : T2 ; F2\" using VE  `?\\<Gamma> |+ VE z = (x', ?rty) # \\<Gamma>'` by auto\n\t    note Iff(3)[ OF X2 `\\<Gamma>' \\<turnstile> e'' : T0'  ; G' ` _ `valid ((x', ?rty) # \\<Gamma>')`]\n\t    then obtain T'' F'' where X3:\"\\<Gamma>' \\<turnstile> t2[x'::=e''] : T'' ; F''  \" and X4:\" \\<turnstile> T'' <: T2 \"\" \\<turnstile> F'' <e: F2\"\n\t      using `closed e''` `e'' : values` remove_soundness[OF `\\<turnstile> T0' <: T1'` X3 `simple_ty T0'`] by auto\n\t    hence \"\\<turnstile> T'' <: T'\" using `\\<turnstile> T2 <: T'` by auto\n\t    hence \"\\<Gamma>' \\<turnstile> Iff e'' (t2[x'::=e'']) (t3[x'::=e'']) : T'' ; NE\" using `valid \\<Gamma>'` X3  `\\<Gamma>' \\<turnstile> e'' : T0'  ; G' ` \n\t      `G' = TT` by auto\n\t    hence \"\\<Gamma>' \\<turnstile> (Iff t1 t2 t3)[x'::=e''] : T'' ; NE\" using ` t1[x'::=e''] = e''` by auto\n\t    thus ?thesis  using `\\<turnstile> T'' <: T'` `F' = NE` by auto\n\t    \n\t  qed\n\tnext\n\t  case False\n\t  from A False have \"(Var z)[x'::=e''] = (Var z)\" by auto\n\t  hence D:\"\\<Gamma>' \\<turnstile> (Var z)[x'::=e''] : T1 ; VE z\" using False A \n          proof -\n            have q1:\"?\\<Gamma> \\<turnstile> Var z : T1 ; VE z\" using A by auto\n            have \"x' \\<sharp> Var z\" using trm.fresh False fresh_atm by auto\n            hence \"\\<Gamma>' \\<turnstile> Var z : T1 ; VE z\" using q1 fresh_weakening_cons `valid ((x',T1')# \\<Gamma>')` by auto\n            thus ?thesis using `(Var z)[x'::=e''] = Var z` by auto\n          qed\n          hence typetst: \"\\<Gamma>' \\<turnstile> t1[x'::=e''] : T1 ; VE z\" using A by auto\n\t  have F:\"?\\<Gamma> |+ VE z = (x',T1') # ?\\<Gamma>1\" using False by auto\n          hence H:\"(x',T1') # ?\\<Gamma>1 \\<turnstile> t2 : T2 ; F2\" using `?\\<Gamma> |+ VE z \\<turnstile> t2 : T2 ; F2` by auto\n          hence K:\"valid ?\\<Gamma>1\" using envop_valid `valid \\<Gamma>'` by auto\n          have J:\"?\\<Gamma>1 \\<turnstile> e'' : T0' ; G'\" using K `valid \\<Gamma>'` closed_any_env `closed e''` Iff by blast\n          have \"x' \\<sharp> ?\\<Gamma>1\" using Iff valid_elim[of x' T1' \\<Gamma>'] envop_fresh[of x' \\<Gamma>' remove] `valid \\<Gamma>'` by auto\n          hence \"valid ((x',T1')#?\\<Gamma>1)\" using `valid ?\\<Gamma>1` by auto\n          hence ex1:\"\\<exists>S2 G2. ?\\<Gamma>1  \\<turnstile> t2[x'::=e''] : S2 ; G2  \\<and> \\<turnstile> S2 <: T2 \\<and> \\<turnstile> G2 <e: F2\"\n            using H J K Iff by auto \n\n\t  have G:\"?\\<Gamma> |- VE z = (x',T1') # ?\\<Gamma>2\" using False by auto\n          hence H:\"(x',T1') # ?\\<Gamma>2 \\<turnstile> t3 : T3 ; F3\" using `?\\<Gamma> |- VE z \\<turnstile> t3 : T3 ; F3` by auto\n          hence K:\"valid ?\\<Gamma>2\" using envop_valid `valid \\<Gamma>'` by auto\n          have J:\"?\\<Gamma>2 \\<turnstile> e'' : T0' ; G'\" using K `valid \\<Gamma>'` closed_any_env `closed e''` Iff by blast\n          have \"x' \\<sharp> ?\\<Gamma>2\" using Iff valid_elim[of x' T1' \\<Gamma>'] envop_fresh[of x' \\<Gamma>' _ z _] `valid \\<Gamma>'` by auto\n          hence \"valid ((x',T1')#?\\<Gamma>2)\" using `valid ?\\<Gamma>2` by auto\n          hence ex2:\"\\<exists>S3 G3. ?\\<Gamma>2  \\<turnstile> t3[x'::=e''] : S3 ; G3  \\<and> \\<turnstile> S3 <: T3 \\<and> \\<turnstile> G3 <e: F3\"\n            using H J K Iff by auto\n\n          from ex1 obtain S2 G2 where 1:\"?\\<Gamma>1  \\<turnstile> t2[x'::=e''] : S2 ; G2\"\" \\<turnstile> S2 <: T'\" using `\\<turnstile> T2 <: T'` by auto\n          from ex2 obtain S3 G3 where 2:\"?\\<Gamma>2  \\<turnstile> t3[x'::=e''] : S3 ; G3\"\" \\<turnstile> S3 <: T'\" using `\\<turnstile> T3 <: T'`  by auto\n          have 4:\"?\\<Gamma>1 = \\<Gamma>' |+ (VE z)\" by auto\n          have 5:\"?\\<Gamma>2 = \\<Gamma>' |- (VE z)\" by auto\n          have X:\"!! G G' e T F. G = G' \\<Longrightarrow> G \\<turnstile> e : T ; F \\<Longrightarrow> G' \\<turnstile> e : T ; F\" by auto\n          from 1 4 have 6:\"\\<Gamma>' |+ (VE z) \\<turnstile> t2[x'::=e''] : S2 ; G2\" using X[of ?\\<Gamma>1 \"\\<Gamma>' |+ (VE z)\" \" t2[x'::=e'']\" S2 G2]\n            by blast\n          from 2 5 have 7:\"\\<Gamma>' |- (VE z) \\<turnstile> t3[x'::=e''] : S3 ; G3\" using X[of ?\\<Gamma>2 \"\\<Gamma>' |- (VE z)\" \" t3[x'::=e'']\" S3 G3]\n            by blast\n          \n          from typetst 1 2 6 7 have \"\\<Gamma>' \\<turnstile> (Iff t1 t2 t3)[x'::=e''] : T' ; comb_eff (VE z) G2 G3\" by (auto simp del: comb_eff.simps)\n\t  thus ?thesis  using `F' = NE` by auto\n\tqed\n      next\n\tcase (TE U z)\n\thave \"EX f A A1 Fn B. t1 = (App f (Var z)) \\<and> (x', T1') # \\<Gamma>' \\<turnstile> f : B ; Fn \\<and> \\<turnstile> B <: A1 \\<rightarrow> T1 : Latent U \\<and>\n\t  (x', T1') # \\<Gamma>' \\<turnstile> (Var z) : A ; VE z \\<and> \\<turnstile> A <: A1\" \n          using TE te_ty_elim[of ?\\<Gamma> t1 T1 U z] by auto\n\tthen obtain f A1 A Fn B where A:\"t1 = (App f (Var z)) \"\" (x', T1') # \\<Gamma>' \\<turnstile> f : B ; Fn\" \"\\<turnstile> B <: A1 \\<rightarrow> T1 : Latent U\"\n\t  \"(x', T1') # \\<Gamma>' \\<turnstile> (Var z) : A ; VE z \"\" \\<turnstile> A <: A1\" by auto\n\thave size1:\"(f\\<guillemotleft>Iff t1 t2 t3)\" using A(1) by (simp )\n\tnote Iff(1)[of f]\n        hence ih_f:\"!! c \\<sigma> \\<Gamma> T F e' T0 F0 . \n          (c,\\<sigma>)#\\<Gamma> \\<turnstile> f : T ; F \\<Longrightarrow> \\<Gamma> \\<turnstile> e' : T0 ; F0 \\<Longrightarrow> \\<turnstile> T0 <: \\<sigma> \\<Longrightarrow> valid ((c,\\<sigma>)#\\<Gamma>) \\<Longrightarrow> closed e' \\<Longrightarrow> e' : values\n          \\<Longrightarrow> EX T' F' . \\<Gamma> \\<turnstile> f[c::=e'] : T' ; F' \\<and> \\<turnstile> T' <: T \\<and> \\<turnstile> F' <e: F\" using size1 by auto\n        have \"EX A' Fn' . \\<Gamma>' \\<turnstile> f[x'::=e''] : A' ; Fn' \\<and> \\<turnstile> A' <: B \\<and> \\<turnstile> Fn' <e: Fn\" \n          using ih_f A Iff by auto\n\tthen obtain A' Fn' where  B:\"\\<Gamma>' \\<turnstile> f[x'::=e''] : A' ; Fn' \\<and> \\<turnstile> A' <:B\" by auto\n\tlet ?mapfun = \"(%f. (% (v,ty). (if (z = v) then (v,f U ty) else (v,ty))))\"\n        let ?\\<Gamma>1 = \"(map (?mapfun restrict) \\<Gamma>')\"\n        let ?\\<Gamma>2 = \"(map (?mapfun remove) \\<Gamma>')\"          \n        have \"valid \\<Gamma>'\" using `valid ?\\<Gamma>` using valid_elim[of x' T1' \\<Gamma>'] by auto\n\n\tshow ?case \n\tproof (cases \"x' = z\")\n\t  case True\n          from A True have  \"(Var z)[x'::=e''] = e''\" by auto\n          hence D:\"\\<Gamma>' \\<turnstile> (Var z)[x'::=e''] : T0' ; G'\" \"closed ((Var z)[x'::=e''])\" \"((Var z)[x'::=e'']) : values\"\n\t    using Iff by auto\n          have \"\\<turnstile> T0' <: T1'\" .\n          note var_ty_elim[of ?\\<Gamma> z A \"VE z\"]\n          hence \"(x', A) : set ?\\<Gamma>\" using A True by auto\n          have \"?\\<Gamma> \\<turnstile> (Var x') : T1' ; VE x'\" using `valid ?\\<Gamma>` by auto\n          hence \"T1' = A\" using A unique_var_typing[of ] True by auto\n          have \"\\<turnstile> T0' <: T1'\" .\n          hence \"\\<turnstile> T0' <: A\" using `T1' = A` by simp\n\t  have \"simple_ty T0'\" using `\\<Gamma>' \\<turnstile> e'' : T0' ; G'` `e'' : values` value_simple_type by auto\n          have or:\"\n            (\\<turnstile> T0' <: U \\<and> \\<turnstile> T0' <: restrict U T1') \\<or>\n            (~ (\\<turnstile> T0' <: U)  \\<and> \\<turnstile> T0' <: remove U T1')\" \n            using `\\<Gamma>' \\<turnstile> e'' : T0' ; G'` `e'' : values` `\\<turnstile> T0' <: T1'` `closed e''` `simple_ty T0'`\n            restrict_remove_soundness\n            by auto\n          have \"?\\<Gamma>1 = envop restrict z U \\<Gamma>'\" by auto\n          have \"?\\<Gamma>2 = envop remove z U \\<Gamma>'\" by auto\n          have \"x' \\<sharp> \\<Gamma>'\" using Iff valid_elim[of x' T1' \\<Gamma>'] by auto\n          hence \"?\\<Gamma>1 = \\<Gamma>'\" using True envop_forget `valid \\<Gamma>'` by auto\n          hence GA:\"?\\<Gamma> |+ TE U z = (x',restrict U T1') # \\<Gamma>'\" using True by auto\n          hence G1:\"\\<dots> \\<turnstile> t2 : T2; F2\" using `(?\\<Gamma> |+ TE U z)\\<turnstile> t2 : T2 ; F2` by auto\n          have \"?\\<Gamma>2 = \\<Gamma>'\" using `x' \\<sharp> \\<Gamma>'` True envop_forget `valid \\<Gamma>'` by auto\n          hence GB:\"?\\<Gamma> |- TE U z = (x',remove U T1') # \\<Gamma>'\" using True by auto\n          hence G2:\"\\<dots> \\<turnstile> t3 : T3; F3\" using `(?\\<Gamma> |- TE U z)\\<turnstile> t3 : T3 ; F3` by auto\n          have \"valid (?\\<Gamma> |+ TE U z)\" using `valid ?\\<Gamma>` envplus_valid[of ?\\<Gamma> \"TE U z\"] by auto\n          hence G3:\"valid ((x',restrict U T1') # \\<Gamma>')\" using GA by auto\n          have \"valid (?\\<Gamma> |- TE U z)\" using `valid ?\\<Gamma>` envminus_valid[of ?\\<Gamma> \"TE U z\"] by auto\n          hence G4:\"valid ((x',remove U T1') # \\<Gamma>')\" using GB by auto\n          show ?thesis\n          proof -\n            {\n              assume \"\\<turnstile> T0' <: U \"\" \\<turnstile> T0' <: restrict U T1'\"\n              have 2:\"(x', restrict U T1') # \\<Gamma>' \\<turnstile> t2 : T2 ; F2 \" using `?\\<Gamma> |+ TE U z \\<turnstile> t2 : T2 ; F2` GA by auto\n              note Iff(2)[of x' \"restrict U T1'\" \\<Gamma>' T2 F2 e'' T0' G'] \n              hence \"\\<exists>S2 G2.  \\<Gamma>' \\<turnstile> t2[x'::=e''] : S2 ; G2  \\<and> \\<turnstile> S2 <: T2 \\<and> \\<turnstile> G2 <e: F2\" using G3 prems `closed e''` 2 by auto\n              then obtain S2 G2 where L1:\"\\<Gamma>'|+ eff.TT \\<turnstile> t2[x'::=e''] : S2 ; G2  \"\" \\<turnstile> S2 <: T2 \"\" \\<turnstile> G2 <e: F2\" by auto\n              have \"\\<turnstile> T0' <: A1\" \"\\<turnstile> A' <:  A1 \\<rightarrow> T1 : Latent U\" using A B D `\\<turnstile> T0' <: A` by auto\n              hence \"\\<Gamma>' \\<turnstile> (App f (Var z))[x'::=e''] : T1 ; eff.TT\" using A B D `\\<turnstile> T0' <: A` `\\<turnstile> T0' <: U` \n\t\tusing T_AppPredTrue[of \\<Gamma>' _ A' Fn' A1 T1 U _ T0' G'] by auto\n              hence L3:\"\\<Gamma>' \\<turnstile> t1[x'::=e''] : T1 ; eff.TT\" using `t1 = App f (Var z)` by auto\n              have \"\\<turnstile> S2 <: T'\"  using L1 `\\<turnstile> T2 <: T'` by auto\n              hence \"\\<Gamma>'\\<turnstile> (Iff t1 t2 t3)[x'::=e''] : T' ; eff.NE\"\n                using L3 ` \\<Gamma>'|+eff.TT \\<turnstile> t2[x'::=e''] : S2 ; G2` by auto\n              hence ?thesis using `F' = NE` by auto              \n            }\n            moreover\n            {\n              assume \"~ (\\<turnstile> T0' <: U) \"\" \\<turnstile> T0' <: remove U T1'\"\n              have 3:\"(x', remove U T1') # \\<Gamma>' \\<turnstile> t3 : T3 ; F3 \" using `?\\<Gamma> |- TE U z \\<turnstile> t3 : T3 ; F3` GB by auto\n              note Iff(3)[of x' \"remove U T1'\" \\<Gamma>' T3 F3 e'' T0' G'] \n              hence \"\\<exists>S3 G3.  \\<Gamma>' \\<turnstile> t3[x'::=e''] : S3 ; G3  \\<and> \\<turnstile> S3 <: T3 \\<and> \\<turnstile> G3 <e: F3\" using G4 prems `closed e''` 3 by auto\n              then obtain S3 G3 where L1:\"\\<Gamma>'|+ eff.FF \\<turnstile> t3[x'::=e''] : S3 ; G3  \"\" \\<turnstile> S3 <: T3 \"\" \\<turnstile> G3 <e: F3\" by auto\n              have \"\\<turnstile> T0' <: A1\" using A B D `\\<turnstile> T0' <: A` by auto\n              hence \"\\<Gamma>' \\<turnstile> (App f (Var z))[x'::=e''] : T1 ; eff.FF\" using A B D `\\<turnstile> T0' <: A` `~ (\\<turnstile> T0' <: U)` \n\t\tusing T_AppPredFalse[of \\<Gamma>' _ A' Fn' A1 T1 U _ T0' G'] by auto\n              hence L3:\"\\<Gamma>' \\<turnstile> t1[x'::=e''] : T1 ; eff.FF\" using `t1 = App f (Var z)` by auto\n              have \"\\<turnstile> S3 <: T'\"  using L1 `\\<turnstile> T3 <: T'` by auto\n              hence \"\\<Gamma>'\\<turnstile> (Iff t1 t2 t3)[x'::=e''] : T' ; eff.NE\"\n                using L3 ` \\<Gamma>'|+eff.FF \\<turnstile> t3[x'::=e''] : S3 ; G3` by auto\n              hence ?thesis using `F' = NE` by auto              \n            }\n            ultimately show ?thesis using or by auto\n          qed\n\tnext\n\t  case False\n\t  from A False have \"(Var z)[x'::=e''] = (Var z)\" by auto\n\t  hence D:\"\\<Gamma>' \\<turnstile> (Var z)[x'::=e''] : A ; VE z\" using False A\n          proof -\n            have q1:\"?\\<Gamma> \\<turnstile> Var z : A ; VE z\" .\n            have \"x' \\<sharp> Var z\" using trm.fresh False fresh_atm by auto\n            hence \"\\<Gamma>' \\<turnstile> Var z : A ; VE z\" using q1 fresh_weakening_cons `valid ((x',T1')# \\<Gamma>')` by auto\n            thus ?thesis using `(Var z)[x'::=e''] = Var z` by auto\n          qed\n\t  from A B D have \"\\<Gamma>' \\<turnstile> App (f[x'::=e'']) ((Var z)[x'::=e'']) : T1 ; TE U z\" by auto\n          hence typetst: \"\\<Gamma>' \\<turnstile> t1[x'::=e''] : T1 ; TE U z\" using A by auto\n\t  have F:\"?\\<Gamma> |+ TE U z = (x',T1') # ?\\<Gamma>1\" using False by auto\n          hence H:\"(x',T1') # ?\\<Gamma>1 \\<turnstile> t2 : T2 ; F2\" using `?\\<Gamma> |+ TE U z \\<turnstile> t2 : T2 ; F2` by auto\n          hence K:\"valid ?\\<Gamma>1\" using envop_valid `valid \\<Gamma>'` by auto\n          have J:\"?\\<Gamma>1 \\<turnstile> e'' : T0' ; G'\" using K `valid \\<Gamma>'` closed_any_env `closed e''` Iff by blast\n          have \"x' \\<sharp> ?\\<Gamma>1\" using Iff valid_elim[of x' T1' \\<Gamma>'] envop_fresh[of x' \\<Gamma>' restrict z U] `valid \\<Gamma>'` by auto\n          hence \"valid ((x',T1')#?\\<Gamma>1)\" using `valid ?\\<Gamma>1` by auto\n          hence ex1:\"\\<exists>S2 G2. ?\\<Gamma>1  \\<turnstile> t2[x'::=e''] : S2 ; G2  \\<and> \\<turnstile> S2 <: T2 \\<and> \\<turnstile> G2 <e: F2\"\n            using H J K Iff by auto \n\n\t  have G:\"?\\<Gamma> |- TE U z = (x',T1') # ?\\<Gamma>2\" using False by auto\n          hence H:\"(x',T1') # ?\\<Gamma>2 \\<turnstile> t3 : T3 ; F3\" using `?\\<Gamma> |- TE U z \\<turnstile> t3 : T3 ; F3` by auto\n          hence K:\"valid ?\\<Gamma>2\" using envop_valid `valid \\<Gamma>'` by auto\n          have J:\"?\\<Gamma>2 \\<turnstile> e'' : T0' ; G'\" using K `valid \\<Gamma>'` closed_any_env `closed e''` Iff by blast\n          have \"x' \\<sharp> ?\\<Gamma>2\" using Iff valid_elim[of x' T1' \\<Gamma>'] envop_fresh[of x' \\<Gamma>' remove z U] `valid \\<Gamma>'` by auto\n          hence \"valid ((x',T1')#?\\<Gamma>2)\" using `valid ?\\<Gamma>2` by auto\n          hence ex2:\"\\<exists>S3 G3. ?\\<Gamma>2  \\<turnstile> t3[x'::=e''] : S3 ; G3  \\<and> \\<turnstile> S3 <: T3 \\<and> \\<turnstile> G3 <e: F3\"\n            using H J K Iff by auto\n\n          from ex1 obtain S2 G2 where 1:\"?\\<Gamma>1  \\<turnstile> t2[x'::=e''] : S2 ; G2\"\" \\<turnstile> S2 <: T'\" using `\\<turnstile> T2 <: T'` by auto\n          from ex2 obtain S3 G3 where 2:\"?\\<Gamma>2  \\<turnstile> t3[x'::=e''] : S3 ; G3\"\" \\<turnstile> S3 <: T'\" using `\\<turnstile> T3 <: T'`  by auto\n          have 4:\"?\\<Gamma>1 = \\<Gamma>' |+ (TE U z)\" by auto\n          have 5:\"?\\<Gamma>2 = \\<Gamma>' |- (TE U z)\" by auto\n          have X:\"!! G G' e T F. G = G' \\<Longrightarrow> G \\<turnstile> e : T ; F \\<Longrightarrow> G' \\<turnstile> e : T ; F\" by auto\n          from 1 4 have 6:\"\\<Gamma>' |+ (TE U z) \\<turnstile> t2[x'::=e''] : S2 ; G2\" using X[of ?\\<Gamma>1 \"\\<Gamma>' |+ (TE U z)\" \" t2[x'::=e'']\" S2 G2]\n            by blast\n          from 2 5 have 7:\"\\<Gamma>' |- (TE U z) \\<turnstile> t3[x'::=e''] : S3 ; G3\" using X[of ?\\<Gamma>2 \"\\<Gamma>' |- (TE U z)\" \" t3[x'::=e'']\" S3 G3]\n            by blast\n          \n          from typetst 1 2 6 7 have \"\\<Gamma>' \\<turnstile> (Iff t1 t2 t3)[x'::=e''] : T' ; comb_eff (TE U z) G2 G3\" by (auto simp del: comb_eff.simps)\n\t  thus ?thesis  using `F' = NE` by auto\n\tqed\n      qed\n    }\n    moreover\n    {\n      assume \"\\<exists> T1 T3 F3. (?\\<Gamma> \\<turnstile> t1 : T1 ; FF) \\<and> ?\\<Gamma> \\<turnstile> t3 : T3 ; F3 \\<and> \\<turnstile> T3 <: T' \\<and> F' = NE\"\n      then obtain T1 T3 F3 where \"?\\<Gamma> \\<turnstile> t1 : T1 ; FF\" \"?\\<Gamma> \\<turnstile> t3 : T3 ; F3\" \"\\<turnstile> T3 <: T'\" \"F' = NE\"\n\tby auto\n      hence \"\\<exists>S1 G1.  \\<Gamma>' \\<turnstile> t1[x'::=e''] : S1 ; G1  \\<and> \\<turnstile> S1 <: T1 \\<and> \\<turnstile> G1 <e: FF\" using Iff by auto\n      then obtain S1 G1 where B:\"\\<Gamma>' \\<turnstile> t1[x'::=e''] : S1 ; G1  \"\" \\<turnstile> S1 <: T1 \"\" \\<turnstile> G1 <e: FF\" by auto\n      hence  C:\"\\<Gamma>' \\<turnstile> t1[x'::=e''] : S1 ; FF  \" using B no_sub_FF by auto\n      from prems have \"\\<exists>S3 G3.  \\<Gamma>' \\<turnstile> t3[x'::=e''] : S3 ; G3  \\<and> \\<turnstile> S3 <: T3 \\<and> \\<turnstile> G3 <e: F3\" using Iff by auto\n      then obtain S3 G3 where D:\"\\<Gamma>' \\<turnstile> t3[x'::=e''] : S3 ; G3 \"\"\\<turnstile> S3 <: T3\" by auto\n      from B C D have \"\\<Gamma>' \\<turnstile> (Iff  (t1[x'::=e'']) (t2[x'::=e'']) (t3[x'::=e''])) : S3 ; eff.NE\" by auto\n      hence ?thesis  using `\\<turnstile> T3 <: T'` `\\<turnstile> S3 <: T3` `F' = NE` by auto\n    }\n    moreover\n    {\n      assume \"\\<exists> T1 T2 F2. (?\\<Gamma> \\<turnstile> t1 : T1 ; TT) \\<and> ?\\<Gamma> \\<turnstile> t2 : T2 ; F2 \\<and> \\<turnstile> T2 <: T'  \\<and> F' = NE\"\n      then obtain T1 T2 F2 where \"?\\<Gamma> \\<turnstile> t1 : T1 ; TT\" \"?\\<Gamma> \\<turnstile> t2 : T2 ; F2\" \"\\<turnstile> T2 <: T'\" \"F' = NE\"\n\tby auto\n      hence \"\\<exists>S1 G1.  \\<Gamma>' \\<turnstile> t1[x'::=e''] : S1 ; G1  \\<and> \\<turnstile> S1 <: T1 \\<and> \\<turnstile> G1 <e: TT\" using Iff by auto\n      then obtain S1 G1 where B:\"\\<Gamma>' \\<turnstile> t1[x'::=e''] : S1 ; G1  \"\" \\<turnstile> S1 <: T1 \"\" \\<turnstile> G1 <e: TT\" by auto\n      hence  C:\"\\<Gamma>' \\<turnstile> t1[x'::=e''] : S1 ; TT  \" using B no_sub_TT by auto\n      from prems have \"\\<exists>S2 G2.  \\<Gamma>' \\<turnstile> t2[x'::=e''] : S2 ; G2  \\<and> \\<turnstile> S2 <: T2 \\<and> \\<turnstile> G2 <e: F2\" using Iff by auto\n      then obtain S2 G2 where D:\"\\<Gamma>' \\<turnstile> t2[x'::=e''] : S2 ; G2 \"\"\\<turnstile> S2 <: T2\" by auto\n      from B C D have \"\\<Gamma>' \\<turnstile> (Iff  (t1[x'::=e'']) (t2[x'::=e'']) (t3[x'::=e''])) : S2 ; eff.NE\" by auto\n      hence ?thesis  using `\\<turnstile> T2 <: T'` `\\<turnstile> S2 <: T2` `F' = NE` by auto\n    }\n    ultimately show ?thesis using A by blast\n  qed\nqed\n\nlemma subst_produces_TT:\n  assumes ty:\"(x,T0)#\\<Gamma> \\<turnstile> e : T ; TE S x\"\n  and vty:\"\\<Gamma> \\<turnstile> v : T0' ; F\"\n  and A:\"\\<turnstile> T0' <: T0\"\n  and B:\"valid ((x,T0)#\\<Gamma>)\" \n  and C:\"closed v\" and D:\"v : values\"\n  and E:\"\\<turnstile> T0' <: S\"\n  shows \"EX T'. \\<Gamma> \\<turnstile> e[x::=v] : T' ; TT \\<and> \\<turnstile> T' <: T\"\nproof -\n  obtain f A A1 Fn Sa B\n    where\n    eq:\"e = App f (Var x)\" and fty:\"(x, T0) # \\<Gamma> \\<turnstile> f : B ; Fn  \"\n    and bsub:\" \\<turnstile> B <: A1 \\<rightarrow> T : Latent S \" and xty:\" (x, T0) # \\<Gamma> \\<turnstile> Var x : A ; VE x  \"\n    and asub:\" \\<turnstile> A <: A1\"\n    using te_ty_elim[OF ty] by auto\n  note preserve_subst[OF fty vty A B C D]\n  then obtain T' F' where\n    X1:\"\\<Gamma> \\<turnstile> f[x::=v] : T' ; F'  \" and \" \\<turnstile> T' <: B \"\" \\<turnstile> F' <e: Fn\"\n    by auto\n  hence X2:\"\\<turnstile> T' <: A1 \\<rightarrow> T : Latent S\" using bsub by auto\n  have \"(Var x)[x::=v] = v\" by simp\n  hence X3:\"\\<Gamma> \\<turnstile> (Var x)[x::=v] : T0' ; F\" using vty by auto\n  have \"(x, T0) # \\<Gamma> \\<turnstile> Var x : T0 ; VE x\" using `valid ((x, T0) # \\<Gamma>)` by auto\n  hence \"T0 = A\" using xty unique_var_typing by auto\n  hence \"\\<turnstile> T0' <: A1\" using A asub by auto\n  from X1 X2 X3 show ?thesis using T_AppPredTrue[OF X1 X2 X3 `\\<turnstile> T0' <: A1` E] using  asub E eq \n    by auto\nqed\n  \n\nlemma subst_produces_FF:\n  assumes ty:\"(x,T0)#\\<Gamma> \\<turnstile> e : T ; TE S x\"\n  and vty:\"\\<Gamma> \\<turnstile> v : T0' ; F\"\n  and A:\"\\<turnstile> T0' <: T0\"\n  and B:\"valid ((x,T0)#\\<Gamma>)\" \n  and C:\"closed v\" and D:\"v : values\"\n  and E:\"~ \\<turnstile> T0' <: S\"\n  shows \"EX T'. \\<Gamma> \\<turnstile> e[x::=v] : T' ; FF \\<and> \\<turnstile> T' <: T\"\nproof -\n  obtain f A A1 Fn Sa B\n    where\n    eq:\"e = App f (Var x)\" and fty:\"(x, T0) # \\<Gamma> \\<turnstile> f : B ; Fn  \"\n    and bsub:\" \\<turnstile> B <: A1 \\<rightarrow> T : Latent S \" and xty:\" (x, T0) # \\<Gamma> \\<turnstile> Var x : A ; VE x  \"\n    and asub:\" \\<turnstile> A <: A1\"\n    using te_ty_elim[OF ty] by auto\n  note preserve_subst[OF fty vty A B C D]\n  then obtain T' F' where\n    X1:\"\\<Gamma> \\<turnstile> f[x::=v] : T' ; F'  \" and \" \\<turnstile> T' <: B \"\" \\<turnstile> F' <e: Fn\"\n    by auto\n  hence X2:\"\\<turnstile> T' <: A1 \\<rightarrow> T : Latent S\" using bsub by auto\n  have veq:\"(Var x)[x::=v] = v\" by simp\n  hence X3:\"\\<Gamma> \\<turnstile> (Var x)[x::=v] : T0' ; F\" using vty by auto\n  have \"(x, T0) # \\<Gamma> \\<turnstile> Var x : T0 ; VE x\" using `valid ((x, T0) # \\<Gamma>)` by auto\n  hence \"T0 = A\" using xty unique_var_typing by auto\n  hence \"\\<turnstile> T0' <: A1\" using A asub by auto\n  from X1 X2 X3 show ?thesis using T_AppPredFalse[OF X1 X2 X3 `\\<turnstile> T0' <: A1` E] using  asub E eq C D veq\n    by auto\nqed\n\ninductive_cases beta_cases:\"App (Abs x b T) v \\<hookrightarrow> e \"\n\ninductive_cases beta_TT_cases:\"\\<Gamma> \\<turnstile> App (Abs x b T) v : T' ; TT\"\ninductive_cases beta_FF_cases:\"\\<Gamma> \\<turnstile> App (Abs x b T) v : T' ; FF\"\n\nlemma preserve_red:\n  assumes typed:\"\\<Gamma> \\<turnstile> e : t ; eff\" and cl:\"closed e\"\n  and red:\"e \\<hookrightarrow> e'\" and val:\"valid \\<Gamma>\"\n  shows \"EX t' eff'. \\<Gamma> \\<turnstile> e' : t' ; eff' \\<and> \\<turnstile> t' <: t \\<and> \\<turnstile> eff' <e: eff \"\n  using red typed cl val red\n  proof (nominal_induct e e' avoiding: \\<Gamma> t rule: reduce.strong_induct)\n    case (e_delta v' p v \\<Gamma> T)\n    thm app_ty_elim[of \\<Gamma> \"(BI p)\" v' T eff]\n    hence \"\\<exists>T0 T0' T1 le eff' eff'' U.  \\<Gamma> \\<turnstile> BI p : U ; eff'  \\<and>  \\<Gamma> \\<turnstile> v' : T0' ; eff''  \\<and> \\<turnstile> U <: T0 \\<rightarrow> T1 : le \n      \\<and> \\<turnstile> T0' <: T0 \\<and> T1 = T\"\n      using app_ty_elim[of \\<Gamma> \"(BI p)\" v' T eff] by simp\n    then obtain T0 T0' T1 le eff' eff'' U where \n      A1:\" \\<Gamma> \\<turnstile> BI p : U ; eff'\" and  A2:\"\\<Gamma> \\<turnstile> v' : T0' ; eff''\" and A3:\"\\<turnstile> T0' <: T0\"\n      and A4:\"T1 = T\" and A5:\"\\<turnstile> U <: T0 \\<rightarrow> T1 : le\"\n      by auto\n    hence \"U = \\<Delta>\\<^isub>\\<tau> p\" using e_delta typing_bi[of \\<Gamma> p  _ eff'] by simp\n    then obtain A0 A1 LA where \"\\<Delta>\\<^isub>\\<tau> p = A0 \\<rightarrow> A1 : LA\" \"U = A0 \\<rightarrow> A1 : LA\" by (nominal_induct p rule: builtin.induct) auto\n    hence \"\\<turnstile> A0 \\<rightarrow> A1 : LA <: T0 \\<rightarrow> T1 : le\" using `\\<turnstile> U <: T0 \\<rightarrow> T1 : le` by auto\n    hence B:\"le = LA \\<or> le = latent_eff.NE\" \"\\<turnstile> T0 <: A0\" \"\\<turnstile> A1 <: T1\" using arr_sub_arr_cases[of A0 A1 LA T0 T1 le] by auto\n    have C1:\" \\<Gamma> \\<turnstile> App (BI p) v' : T1 ; eff\" using prems `T1 = T` by auto\n    have C2:\"\\<turnstile> T0' <: A0\" and C3:\"\\<turnstile> A1 <: T \" using B A3 A4 by auto\n    have C4:\"valid \\<Gamma>\" .\n    note delta_soundness[OF `\\<Delta>\\<^isub>\\<tau> p = A0 \\<rightarrow> A1 : LA` `v' : values` `\\<Gamma> \\<turnstile> v' : T0' ; eff''` C2 e_delta(3) C3 `\\<Delta> p v' = Some v` C4]\n    then obtain A1' eff' where \"\\<Gamma> \\<turnstile> v : A1' ; eff' \"\" \\<turnstile> eff' <e: eff\" \"\\<turnstile> A1' <: A1\" by auto\n    thus ?case using C3 by auto\n  next\n    case (e_if_false thn els \\<Gamma>' t') \n    have \"eff = NE\" using if_false_ty_elim[of _ _ _ _ eff] e_if_false by auto\n    have \" \\<exists>T0 eff'.  \\<Gamma>' \\<turnstile> els : T0 ; eff'  \\<and> \\<turnstile> T0 <: t' \" using   if_false_ty_elim[of \\<Gamma>' thn els t' eff] e_if_false by auto\n    then obtain T0 eff' where  f:\"\\<Gamma>' \\<turnstile> els : T0 ; eff'\"  and g:\"\\<turnstile> T0 <: t'\" by auto\n    have \"closed els\" using e_if_false closed_def trm.supp by auto\n    hence \"simple_eff eff'\" using closed_eff f by auto\n    hence h:\"\\<turnstile> eff' <e: eff\" using simple_eff_below_ne `eff = NE` by auto\n    thus ?case using f g  by auto\n  next\n    case (e_if_true v thn els \\<Gamma>' t') \n    have \"eff = NE\" using if_true_ty_elim[of \\<Gamma>' v thn els _ eff] e_if_true by auto\n    have \" \\<exists>T0 eff'.  \\<Gamma>' \\<turnstile> thn : T0 ; eff'  \\<and> \\<turnstile> T0 <: t' \" using   if_true_ty_elim[of \\<Gamma>' v thn els t' eff] e_if_true by auto\n    then obtain T0 eff' where  f:\"\\<Gamma>' \\<turnstile> thn : T0 ; eff'\"  and g:\"\\<turnstile> T0 <: t'\" by auto\n    have \"closed thn\" using e_if_true closed_def trm.supp by auto\n    hence \"simple_eff eff'\" using closed_eff f by auto\n    hence h:\"\\<turnstile> eff' <e: eff\" using `eff = NE` by auto\n    thus ?case using f g  by auto\n  next\n    case (e_beta v x T b \\<Gamma>' T')\n    hence \"simple_eff eff\" using closed_eff by auto\n    thm app_ty_elim[of \\<Gamma>' \"(Lam[x:T].b)\" v t eff]\n    (* hence \"eff = NE\" using app_abs_ty_elim_eff by auto *)\n    from e_beta have \"\\<exists>T0 T0' T1 le eff' eff'' U.  \\<Gamma>' \\<turnstile> Abs x b T : U ; eff'  \\<and>  \\<Gamma>' \\<turnstile> v : T0' ; eff''  \n      \\<and> \\<turnstile> T0' <: T0 \\<and> T1 = T' \\<and> \\<turnstile> U <: T0 \\<rightarrow> T1 : le\"\n      using app_ty_elim[of \\<Gamma>' \"Abs x b T\" v T' eff] by blast\n    then obtain T0 T0' T1 le eff' eff'' U where \" \\<Gamma>' \\<turnstile> Lam[x:T].b :U; eff'\" and \"\\<Gamma>' \\<turnstile> v : T0' ; eff''\" \n      and \"\\<turnstile> T0' <: T0\" and \"T1 = T'\"  and usub:\"\\<turnstile> U <:  T0 \\<rightarrow> T1 : le \" by auto\n    hence \"\\<exists>T1a eff2 L S.  (x,T)#\\<Gamma>' \\<turnstile> b : T1a ; eff2 \\<and> U = T \\<rightarrow> T1a : L \\<and> (L = Latent S \\<and> eff2 = TE S x \\<or> L = latent_eff.NE)\"\n      using abs_ty_elim[of \\<Gamma>' x b T \"U\" eff'] e_beta `x \\<sharp> \\<Gamma>'` by auto\n    then obtain T1a eff2 L S where  bty:\"(x,T)#\\<Gamma>' \\<turnstile> b : T1a ; eff2\" and ueq:\"U = T \\<rightarrow> T1a : L\"\n      and \"(L = Latent S \\<and> eff2 = TE S x \\<or> L = latent_eff.NE)\"\n      by auto\n    have \"closed v\" using e_beta closed_def trm.supp by auto\n    have \"v : values\" using e_beta beta_cases[of _ _ _ v _ \"v : values\"]  trm.inject by auto\n    have \"\\<turnstile> T0 <: T\" using usub ueq arr_sub_arr_cases[of T T1a L T0 T1 le] by auto\n    have \"\\<turnstile> T1a <: T1\" using usub ueq arr_sub_arr_cases[of T T1a L T0 T1 le] by auto\n    hence \"\\<turnstile> T1a <: T'\" using `T1 = T'` by simp\n    have \"\\<turnstile> T0' <: T\" using ` \\<turnstile> T0' <: T0` `\\<turnstile>T0<:T` by auto\n    have \" \\<exists>T'a F'.  \\<Gamma>' \\<turnstile> b[x::=v] : T'a ; F'  \\<and> \\<turnstile> T'a <: T1a\"\n      using preserve_subst[of x T \\<Gamma>' b T1a eff2 v T0' eff''] `\\<Gamma>' \\<turnstile> v : T0' ; eff''` bty `\\<turnstile> T0' <: T` `x \\<sharp> \\<Gamma>'` `valid \\<Gamma>'` \n      `closed v` `v : values`\n      by auto\n    then obtain T'a F' where a:\"\\<Gamma>' \\<turnstile> b[x::=v] : T'a ; F'\" and b:\"\\<turnstile> T'a <: T1a\" by auto\n    have \"closed (b[x::=v])\" using e_beta reduce_closed by blast\n    hence c:\"simple_eff F'\" using a closed_eff by auto\n    have ?case using `simple_eff eff` e_beta a b\n\n    proof (induct eff rule: simple_eff_cases)\n      case NE thus ?case using simple_eff_below_ne[of F'] c a b `\\<turnstile> T1a <: T'` by auto\n    next\n      case TT\n      obtain U T0 Ta S eff1 eff2 where  X1:\"\\<Gamma>' \\<turnstile> (Lam [x:T].b) : U ; eff1 \" and X2:\"\\<turnstile> U <: T0 \\<rightarrow> T' : Latent S\" and\n\tX3:\" \\<Gamma>' \\<turnstile> v : Ta ; eff2 \" \"\\<turnstile> Ta <: T0\"\" \\<turnstile> Ta <: S\"\n\tusing trm.inject  beta_TT_cases[OF TT(5), of thesis]\n\tby auto\n      note abs_ty_elim[OF X1 `x \\<sharp> \\<Gamma>'`]\n      then obtain T1' eff' L S' where f:\n\t\"(x, T) # \\<Gamma>' \\<turnstile> b : T1' ; eff'  \"\n\t\" U = T \\<rightarrow> T1' : L \"\n\t\" eff1 = eff.TT \"\n\t\" (eff' = TE S' x \\<and> L = Latent S' \\<or> L = latent_eff.NE)\" \n\tby auto\n      hence \"eff' = TE S x\" \"\\<turnstile> T0 <: T\" \"\\<turnstile> T1' <: T'\"using `U = T \\<rightarrow> T1' : L` X2 using arr_sub_arr_cases[of T T1' L T0 T' \"Latent S\"] \n\tby auto\n      hence X4:\"(x, T) # \\<Gamma>' \\<turnstile> b : T1' ; TE S x\" using f by auto\n      have valcons:\"valid ((x,T)#\\<Gamma>')\" using `valid \\<Gamma>'` `x \\<sharp> \\<Gamma>'` by auto\n      have \"\\<turnstile> Ta <: T\" using `\\<turnstile> Ta <: T0``\\<turnstile> T0 <: T`  by auto\n      have \"EX T2'. \\<Gamma>' \\<turnstile> b[x::=v] : T2' ; TT \\<and> \\<turnstile> T2' <: T1'\" using X3 \n\tusing subst_produces_TT[OF X4 `\\<Gamma>' \\<turnstile> v : Ta ; eff2` `\\<turnstile> Ta <: T` valcons ` closed v`` v \\<in> values` `\\<turnstile> Ta <: S`] \n\tby auto\n      \n      thus ?case using `\\<turnstile> T1' <: T'` by auto\n    next\n      case FF\n      obtain U T0 Ta S eff1 eff2 where  X1:\"\\<Gamma>' \\<turnstile> (Lam [x:T].b) : U ; eff1 \" and X2:\"\\<turnstile> U <: T0 \\<rightarrow> T' : Latent S\" and\n\tX3:\" \\<Gamma>' \\<turnstile> v : Ta ; eff2 \" \"\\<turnstile> Ta <: T0\"\"~ \\<turnstile> Ta <: S\"\n\tusing trm.inject  beta_FF_cases[OF FF(5), of thesis]\n\tby auto\n      note abs_ty_elim[OF X1 `x \\<sharp> \\<Gamma>'`]\n      then obtain T1' eff' L S' where f:\n\t\"(x, T) # \\<Gamma>' \\<turnstile> b : T1' ; eff'  \"\n\t\" U = T \\<rightarrow> T1' : L \"\n\t\" eff1 = eff.TT \"\n\t\" (eff' = TE S' x \\<and> L = Latent S' \\<or> L = latent_eff.NE)\" \n\tby auto\n      hence \"eff' = TE S x\"  \"\\<turnstile> T0 <: T\" \"\\<turnstile> T1' <: T'\" using `U = T \\<rightarrow> T1' : L` X2 using arr_sub_arr_cases[of T T1' L T0 T' \"Latent S\"] \n\tby auto\n      hence X4:\"(x, T) # \\<Gamma>' \\<turnstile> b : T1' ; TE S x\" using f by auto\n      have valcons:\"valid ((x,T)#\\<Gamma>')\" using `valid \\<Gamma>'` `x \\<sharp> \\<Gamma>'` by auto\n      have \"\\<turnstile> Ta <: T\" using `\\<turnstile> Ta <: T0``\\<turnstile> T0 <: T`  by auto\n\n      hence \"EX T2'. \\<Gamma>' \\<turnstile> b[x::=v] : T2' ; FF \\<and> \\<turnstile> T2' <: T1'\" using X3 \n\tusing subst_produces_FF[OF X4 `\\<Gamma>' \\<turnstile> v : Ta ; eff2` `\\<turnstile> Ta <: T` valcons ` closed v`` v \\<in> values` _] \n\tby auto     \n      thus ?case using `\\<turnstile> T1' <: T'` by auto\n    qed\n    thus ?case .\n  qed\n\nlemma value_no_ctxt:\n  assumes \"v : values\" and \"v = E t\" and \"E : ctxt\"\n  shows \"E = (% t . t)\"\n  using prems\n  proof (induct)\n    case bi_value show ?case using `E : ctxt` bi_value\n      by (induct E rule: ctxt.induct) (auto simp add: trm.inject)\n  next\n    case num_value show ?case using `E : ctxt` num_value\n      by (induct E rule: ctxt.induct) (auto simp add: trm.inject)\n  next\n    case abs_value show ?case using `E : ctxt` abs_value\n      by (induct E rule: ctxt.induct) (auto simp add: trm.inject)\n  next\n    case bool_value show ?case using `E : ctxt` bool_value\n      by (induct E rule: ctxt.induct) (auto simp add: trm.inject)\n  qed\n\n\nlemma subst_in_ctxt_preserves_type:\n  assumes a:\"\\<Gamma> \\<turnstile> u : T ; F\"\n  and b:\"C : ctxt\"\n  and c:\"u = C e\"\n  and \"~ (e : values)\"\n  and \"closed (C e)\" and \"closed (C e')\"\n  and \"!! T0 F0  . \\<Gamma> \\<turnstile> e : T0 ; F0 \\<Longrightarrow> EX T1 F1. \\<Gamma> \\<turnstile> e' : T1 ; F1 \\<and> \\<turnstile> T1 <: T0 \\<and> \\<turnstile> F1 <e: F0\"\n  shows \"EX S G. \\<Gamma> \\<turnstile> C e' : S ; G \\<and> \\<turnstile> S <: T \\<and> \\<turnstile> G <e: F\"\n  using b prems\n  proof (induct C arbitrary: u e e' T F rule: ctxt.induct)\n    case C_Hole\n    hence \"\\<Gamma> \\<turnstile> e : T ; F\" using C_Hole by simp\n    hence \"EX S G. \\<Gamma> \\<turnstile> e' : S; G \\<and> \\<turnstile> S <: T \\<and> \\<turnstile> G <e: F\" using C_Hole by auto\n    thus ?case by simp\n  next\n    case (C_App1 E arg u' t t' T' F')\n    have A:\"closed (E t)\" and B:\"closed (E t')\" using C_App1 closed_def trm.supp by auto\n    have C:\"\\<Gamma> \\<turnstile> App (E t) arg : T' ; F'\" using C_App1 by auto\n    hence D:\"simple_eff F'\" using C_App1 closed_eff by auto\n    thus ?case using C_App1 A B C\n      proof (induct rule: simple_eff_cases)\n        case NE\n        hence \"EX T0 T0' T1 le eff' eff'' U.  \\<Gamma> \\<turnstile> E t :U ; eff'  \\<and>  \\<Gamma> \\<turnstile> arg : T0' ; eff''  \\<and> \\<turnstile> U <:  T0 \\<rightarrow> T1 : le\n\t  \\<and> \\<turnstile> T0' <: T0 \\<and> T1 = T'\"\n          using app_ty_elim by auto\n        then obtain T0 T0' le eff' eff'' U\n          where  a:\"\\<Gamma> \\<turnstile> E t : U ; eff'\" and b:\"\\<Gamma> \\<turnstile> arg : T0' ; eff''\" and c:\"\\<turnstile> T0' <: T0\"  and d:\"\\<turnstile> U <: T0 \\<rightarrow> T' : le\"\n\t  by auto\n        have  \"\\<exists>S G.  \\<Gamma> \\<turnstile> E t' : S ; G  \\<and> \\<turnstile> S <: U \\<and> \\<turnstile> G <e: eff'\"\n          using C_App1(2)[of \"E t\" _ eff' t t']  `E : ctxt` `closed (E t)` `closed (E t')` C_App1(8) a\n\t  `t \\<notin> values` C_App1 by auto\n        then obtain S G where et'ty:\"\\<Gamma> \\<turnstile> E t' : S ; G \" and subarr:\" \\<turnstile> S <: U \" and \"\\<turnstile> G <e: eff'\" by auto\n\thence \"\\<Gamma> \\<turnstile> App (E t') arg : T' ; NE\" using b c d by auto\n        thus ?case   by auto\n      next\n        case FF\n        have \"EX S T0 T0' le F1 F2 U.  \\<Gamma> \\<turnstile> E t : U ; F1  \\<and>  \\<Gamma> \\<turnstile> arg : T0' ; F2 \\<and> \\<turnstile> T0' <: T0 \\<and> le = Latent S \\<and> \n\t  ~ (\\<turnstile> T0' <: S) \\<and> arg : values \\<and> closed arg \\<and> \\<turnstile> U <: T0 \\<rightarrow> T' : le\"\n          using `\\<Gamma> \\<turnstile> App (E t) arg : T' ; FF` app_ty_ff_elim[of \\<Gamma> \"E t\" arg T'] by blast\n        then obtain S T0 T0' F1 F2 U where  a:\"\\<Gamma> \\<turnstile> E t :U ; F1\" and  b:\"\\<Gamma> \\<turnstile> arg : T0' ; F2 \" \n\t  and c:\"\\<turnstile> T0' <: T0 \" and d:\" ~ (\\<turnstile> T0' <: S)\"  \"closed arg\" \"arg : values\" \" \\<turnstile> U <:  T0 \\<rightarrow> T' : Latent S\"\n          by auto\n        have  \"\\<exists>S' G.  \\<Gamma> \\<turnstile> E t' : S' ; G  \\<and> \\<turnstile> S' <: U \\<and> \\<turnstile> G <e: F1\"\n          using C_App1(2)[of \"E t\" U F1 t t']  `E : ctxt` `closed (E t)` `closed (E t')` C_App1(8) a C_App1 by auto\n        then obtain S' G where et'ty:\"\\<Gamma> \\<turnstile> E t' : S' ; G \" and subarr:\" \\<turnstile> S' <: U\" and \"\\<turnstile> G <e: F1\" by auto\n\thence \"\\<Gamma> \\<turnstile> App (E t') arg : T' ; FF\" using b c d by auto\n        thus ?case by auto\n      next\n        case TT\n        have \"EX S T0 T0' le F1 F2 U.  \\<Gamma> \\<turnstile> E t : U ; F1  \\<and>  \\<Gamma> \\<turnstile> arg : T0' ; F2 \\<and> \\<turnstile> T0' <: T0 \\<and> \n\t  le = Latent S \\<and> \\<turnstile> T0' <: S \\<and>  \\<turnstile> U <: T0 \\<rightarrow> T' : le\"\n          using `\\<Gamma> \\<turnstile> App (E t) arg : T' ; TT` app_ty_tt_elim[of \\<Gamma> \"E t\" arg T'] by blast\n        then obtain S T0 T0' F1 F2 U where  a:\"\\<Gamma> \\<turnstile> E t : U ; F1\" and  b:\"\\<Gamma> \\<turnstile> arg : T0' ; F2 \" \n\t  and c:\"\\<turnstile> T0' <: T0 \" and d:\"\\<turnstile> T0' <: S\" \"\\<turnstile> U <: T0 \\<rightarrow> T' : Latent S\"\n          by auto\n        have  \"\\<exists>S' G.  \\<Gamma> \\<turnstile> E t' : S' ; G  \\<and> \\<turnstile> S' <: U \\<and> \\<turnstile> G <e: F1\"\n          using C_App1(2)[of \"E t\" U F1 t t']  `E : ctxt` `closed (E t)` `closed (E t')` C_App1 a by auto\n        then obtain S' G where et'ty:\"\\<Gamma> \\<turnstile> E t' : S' ; G \" and subarr:\" \\<turnstile> S' <: U \" and \"\\<turnstile> G <e: F1\" by auto\n\thence \"\\<Gamma> \\<turnstile> App (E t') arg : T' ; TT\" using b c d by auto\n        thus ?case by auto\n      qed\n    next\n      case (C_App2 E v u' t t' T' F')\n      have A:\"closed (E t)\" and B:\"closed (E t')\" using C_App2 closed_def trm.supp by auto\n      have C:\"\\<Gamma> \\<turnstile> App v (E t) : T' ; F'\" using C_App2 by auto\n      hence D:\"simple_eff F'\" using C_App2 closed_eff by auto\n      thus ?case using C_App2 A B C\n      proof (induct rule: simple_eff_cases)\n        case NE\n\thave \"\\<exists>T0 T0' T1 le eff' eff'' U.  \\<Gamma> \\<turnstile> v : U ; eff'  \\<and>  \\<Gamma> \\<turnstile> E t : T0' ; eff''  \\<and> \\<turnstile> T0' <: T0 \n\t  \\<and> T1 = T' \\<and> \\<turnstile> U <: T0 \\<rightarrow> T1 : le\"\n\t  using  app_ty_elim[of \\<Gamma> v \"E t\" T' F'] `\\<Gamma> \\<turnstile> App v (E t) : T' ; F'` by blast\n\tthen obtain T0 T0' le eff' eff'' U\n\t  where  a:\"\\<Gamma> \\<turnstile> v : U ; eff'\"  \" \\<Gamma> \\<turnstile> E t : T0' ; eff'' \" \"\\<turnstile> T0' <: T0\" \"\\<turnstile> U <: T0 \\<rightarrow> T' : le\" by auto\n\thence \"\\<exists>S G.  \\<Gamma> \\<turnstile> E t' : S ; G  \\<and> \\<turnstile> S <: T0' \\<and> \\<turnstile> G <e: eff''\" using NE(2)[of \"E t\" T0' eff'' t t'] NE by auto\n\tthen obtain S G where  \"\\<Gamma> \\<turnstile> E t' : S ; G \"\" \\<turnstile> S <: T0'\" by auto\n\thence \"\\<Gamma> \\<turnstile> App v (E t') : T' ; eff.NE\" using a `\\<turnstile> T0' <: T0` by auto\n\tthus ?case by auto\n      next\n        case FF \n\thave \"\\<exists>S T0 T0' le eff' eff'' U.  \\<Gamma> \\<turnstile> v : U ; eff'  \\<and>  \\<Gamma> \\<turnstile> E t : T0' ; eff''  \\<and> \\<turnstile> T0' <: T0  \\<and> le = Latent S \\<and> ~ (\\<turnstile> T0' <: S) \\<and> E t : values \\<and> closed (E t) \\<and> \\<turnstile> U <:  T0 \\<rightarrow> T' : le\"\t  \n\t  using  app_ty_ff_elim[of \\<Gamma> v \"E t\" T'] `\\<Gamma> \\<turnstile> App v (E t) : T' ; FF` by blast\n\tthen obtain S T0 T0' le eff' eff'' U \n\t  where \"\\<Gamma> \\<turnstile> v : U ; eff'  \"\" \\<Gamma> \\<turnstile> E t : T0' ; eff''  \"\" \\<turnstile> T0' <: T0 \" \" ~ (\\<turnstile> T0' <: S) \"\n\t  \" E t : values \"\" closed (E t)\"\n\t  by auto\n\thence \"E = (% t. t)\" using  value_no_ctxt[of \"E t\" E t] `E : ctxt` by simp\n\thence \"t : values\" using `E t : values` by simp\n\tthus ?case using `t \\<notin> values` by auto\n      next\n        case TT\n\thave \"\\<exists>S T0 T0' le eff' eff'' U.  \\<Gamma> \\<turnstile> v : U ; eff'  \\<and>  \\<Gamma> \\<turnstile> E t : T0' ; eff''  \\<and> \\<turnstile> T0' <: T0  \\<and> \n\t  le = Latent S \\<and> \\<turnstile> T0' <: S \\<and> \\<turnstile> U <: T0 \\<rightarrow> T' : le\"\n\t  using  app_ty_tt_elim[of \\<Gamma> v \"E t\" T'] `\\<Gamma> \\<turnstile> App v (E t) : T' ; TT` by blast\n\tthen obtain S T0 T0' le eff' eff'' U\n\t  where a:\"\\<Gamma> \\<turnstile> v : U ; eff'  \"\" \\<Gamma> \\<turnstile> E t : T0' ; eff''  \"\" \\<turnstile> T0' <: T0 \" \" \\<turnstile> T0' <: S\" \"\\<turnstile> U <: T0 \\<rightarrow> T' : Latent S\"\n\t  by auto\n\thence \"\\<exists>S' G.  \\<Gamma> \\<turnstile> E t' : S' ; G  \\<and> \\<turnstile> S' <: T0' \\<and> \\<turnstile> G <e: eff''\" using TT(2)[of \"E t\" T0' eff'' t t'] TT by auto\n\tthen obtain S' G where  b:\"\\<Gamma> \\<turnstile> E t' : S' ; G \"\" \\<turnstile> S' <: T0'\" by auto\n\thave \"\\<turnstile> S' <: S\" using ` \\<turnstile> S' <: T0'` `\\<turnstile> T0' <: S` by auto\n\thave \"\\<turnstile> S' <: T0\" using `\\<turnstile> S' <: T0'` `\\<turnstile> T0' <: T0` by auto\n\thence \"\\<Gamma> \\<turnstile> App v (E t') : T' ; TT\" using b T_AppPredTrue[OF a(1) a(5) b(1) `\\<turnstile> S' <: T0` ] using `\\<turnstile> S' <: S` by auto\n\tthus ?case by auto\n      qed\n    next\n      case (C_Iff E thn els u' t t' T' F')\n      have A:\"closed (E t)\" and B:\"closed (E t')\" using C_Iff closed_def trm.supp by auto\n      have C:\"\\<Gamma> \\<turnstile> Iff (E t) thn els: T' ; F'\" using C_Iff by auto\n      hence\n\tbigor:\n\t\"(\\<exists>T1 T2 T3 F1 F2 F3. \\<Gamma> \\<turnstile> E t : T1 ; F1  \\<and> \\<Gamma> |+ F1 \\<turnstile> thn : T2 ; F2  \\<and>  \\<Gamma> |- F1 \\<turnstile> els : T3 ; F3  \\<and> \\<turnstile> T2 <: T' \\<and> \\<turnstile> T3 <: T' \\<and> F' = eff.NE) \\<or>\n\t(\\<exists>T1 T3 F3.  \\<Gamma> \\<turnstile> E t : T1 ; FF  \\<and>  \\<Gamma> \\<turnstile> els : T3 ; F3  \\<and> \\<turnstile> T3 <: T' \\<and> F' = eff.NE) \\<or>\n\t(\\<exists>T1 T2 F2.  \\<Gamma> \\<turnstile> E t : T1 ; TT  \\<and>  \\<Gamma> \\<turnstile> thn : T2 ; F2  \\<and> \\<turnstile> T2 <: T' \\<and> F' = eff.NE)\"\n\tusing if_ty_elim[of \\<Gamma> \"(E t)\" thn els T' F'] by auto\n      thus ?case\n\tproof -\n\t  {\n\t    assume \"(\\<exists>T1 T2 T3 F1 F2 F3. \\<Gamma> \\<turnstile> E t : T1 ; F1  \\<and> \\<Gamma> |+ F1 \\<turnstile> thn : T2 ; F2  \\<and>  \\<Gamma> |- F1 \\<turnstile> els : T3 ; F3  \\<and> \\<turnstile> T2 <: T' \\<and> \\<turnstile> T3 <: T' \\<and> F' = eff.NE)\"\n\t    then obtain T1 T2 T3 F1 F2 F3 where \n\t      P:\"\\<Gamma> \\<turnstile> E t : T1 ; F1\"\"\\<Gamma> |+ F1 \\<turnstile> thn : T2 ; F2\"\"\\<Gamma> |- F1 \\<turnstile> els : T3 ; F3\"\"\\<turnstile> T2 <: T'\"\"\\<turnstile> T3 <: T'\"\"F' = eff.NE\"\n\t      by auto\n\t    have \"closed (E t)\" and \"closed (E t')\" using prems trm.supp closed_def by auto\n\t    hence \"EX T1' F1'. \\<Gamma> \\<turnstile> E t' : T1' ; F1' \\<and> \\<turnstile> T1' <: T1 \\<and> \\<turnstile> F1' <e: F1\"\n\t      using C_Iff(2)[of \"E t\" T1 F1 t t'] C_Iff P by auto\n\t    then obtain T1' F1' where Q:\"\\<Gamma> \\<turnstile> E t' : T1' ; F1' \"\" \\<turnstile> T1' <: T1 \"\" \\<turnstile> F1' <e: F1\" by auto\n\t    have \"simple_eff F1'\" and \"simple_eff F1\" using `closed (E t)` `closed (E t')` P Q closed_eff by auto\n\t    hence \"\\<Gamma> |+ F1 = \\<Gamma>\" \"\\<Gamma> |- F1 = \\<Gamma>\" \"\\<Gamma> |+ F1' = \\<Gamma>\" \"\\<Gamma> |- F1' = \\<Gamma>\" by (auto simp add: env_plus_simple_eff)\n\t    hence \"\\<Gamma> |+ F1' \\<turnstile> thn : T2 ; F2 \" \"\\<Gamma> |- F1' \\<turnstile> els : T3 ; F3\" using P by auto\n\t    hence \"\\<Gamma> \\<turnstile> Iff (E t') thn els : T'; comb_eff F1' F2 F3\" using `\\<Gamma> \\<turnstile> E t' : T1' ; F1'` ` \\<turnstile> T2 <: T' `` \\<turnstile> T3 <: T'`\n\t      by (auto simp del: comb_eff.simps)\n\t    hence ?thesis using `F' = NE` by auto\n\t  }\n\t  moreover\n\t  {\n\t    assume \"(\\<exists>T1 T3 F3.  \\<Gamma> \\<turnstile> E t : T1 ; FF  \\<and>  \\<Gamma> \\<turnstile> els : T3 ; F3  \\<and> \\<turnstile> T3 <: T' \\<and> F' = eff.NE)\"\n\t    then obtain T1 T3 F3 where P:\"\\<Gamma> \\<turnstile> E t : T1 ; FF \"\" \\<Gamma> \\<turnstile> els : T3 ; F3  \"\" \\<turnstile> T3 <: T'\"\" F' = eff.NE\"\n\t      by auto\n\t    have \"closed (E t)\" and \"closed (E t')\" using prems trm.supp closed_def by auto\n\t    hence \"EX T1' F1'. \\<Gamma> \\<turnstile> E t' : T1' ; F1' \\<and> \\<turnstile> T1' <: T1 \\<and> \\<turnstile> F1' <e: FF\"\n\t      using C_Iff(2)[of \"E t\" T1 FF t t'] C_Iff P by auto\n\t    then obtain T1' F1' where Q:\"\\<Gamma> \\<turnstile> E t' : T1' ; F1' \"\" \\<turnstile> T1' <: T1 \"\" \\<turnstile> F1' <e: FF\" by auto\n\t    have \"F1' = FF\" using Q no_sub_FF[of F1' FF] by simp\n\t    hence \"\\<Gamma> \\<turnstile> E t' : T1' ; FF \" using Q by auto\n\t    hence ?thesis using P by auto\n\t  }\n\t  moreover\n\t  {\n\t    assume \"(\\<exists>T1 T2 F2.  \\<Gamma> \\<turnstile> E t : T1 ; TT  \\<and>  \\<Gamma> \\<turnstile> thn : T2 ; F2  \\<and> \\<turnstile> T2 <: T' \\<and> F' = eff.NE)\"\n\t    then obtain T1 T2 F2 where P:\"\\<Gamma> \\<turnstile> E t : T1 ; TT \"\" \\<Gamma> \\<turnstile> thn : T2 ; F2  \"\" \\<turnstile> T2 <: T'\"\" F' = eff.NE\"\n\t      by auto\n\t    have \"closed (E t)\" and \"closed (E t')\" using prems trm.supp closed_def by auto\n\t    hence \"EX T1' F1'. \\<Gamma> \\<turnstile> E t' : T1' ; F1' \\<and> \\<turnstile> T1' <: T1 \\<and> \\<turnstile> F1' <e: TT\"\n\t      using C_Iff(2)[of \"E t\" T1 TT t t'] C_Iff P by auto\n\t    then obtain T1' F1' where Q:\"\\<Gamma> \\<turnstile> E t' : T1' ; F1' \"\" \\<turnstile> T1' <: T1 \"\" \\<turnstile> F1' <e: TT\" by auto\n\t    have \"F1' = TT\" using Q no_sub_TT[of F1' TT] by simp\n\t    hence \"\\<Gamma> \\<turnstile> E t' : T1' ; TT \" using Q by auto\n\t    hence ?thesis using P by auto\n\t  }\n\t  ultimately show ?thesis using bigor by blast\n\tqed\n      qed        \n        \n\nlemma typing_ctxt:\n  assumes a:\"\\<Gamma> \\<turnstile> C L : T ; eff\"\n  and b:\"C : ctxt\"\n  shows \"EX T' eff'. \\<Gamma> \\<turnstile> L : T' ; eff'\"\n  using b a\n  proof(induct C arbitrary: T eff rule: ctxt.induct )\n    case C_Hole thus ?case by auto\n  next\n    case (C_App1 C' arg S)\n    hence ih: \"!! T0 eff. \\<Gamma> \\<turnstile> C' L : T0 ; eff  \\<Longrightarrow> \\<exists>T' a.  \\<Gamma> \\<turnstile> L : T' ; a\" by simp\n    obtain T0 T0' T1 le eff' eff'' U where \"\\<Gamma> \\<turnstile> C' L : U ; eff'\" \"\\<Gamma> \\<turnstile> arg : T0' ; eff''\" \"\\<turnstile> T0' <: T0 \\<and> T1 = S\"    \n      \"\\<turnstile> U <:  T0 \\<rightarrow> T1 : le\"\n      using app_ty_elim[of \\<Gamma> \"C' L\" arg S eff] ` \\<Gamma> \\<turnstile> App (C' L) arg : S ; eff` by blast\n    thus ?case using ih by auto\n  next\n    case (C_App2 C' rator S F)\n    hence ih: \"!! T0 eff. \\<Gamma> \\<turnstile> C' L : T0 ; eff  \\<Longrightarrow> \\<exists>T' a.  \\<Gamma> \\<turnstile> L : T' ; a\" by simp\n    obtain T0 T0' T1 le eff' eff'' U where \"\\<Gamma> \\<turnstile> rator : U ; eff'\" \"\\<Gamma> \\<turnstile> C' L : T0' ; eff''\" \"\\<turnstile> T0' <: T0 \\<and> T1 = S\"  \n      \"\\<turnstile> U <: T0 \\<rightarrow> T1 : le\"\n      using app_ty_elim[of \\<Gamma> rator \"C' L\" S F] ` \\<Gamma> \\<turnstile> App rator (C' L)  : S ; F` by blast\n    thus ?case using ih by auto\n  next\n    case (C_Iff C' thn els S F)\n    hence ih: \"!! T0 eff. \\<Gamma> \\<turnstile> C' L : T0 ; eff  \\<Longrightarrow> \\<exists>T' a.  \\<Gamma> \\<turnstile> L : T' ; a\" by simp\n    obtain T0 eff' where  \"\\<Gamma> \\<turnstile> C' L : T0 ; eff'\"\n      using if_ty_elim[of \\<Gamma> \"C' L\" thn els S F] ` \\<Gamma> \\<turnstile> Iff (C' L) thn els : S ; F` by auto\n    thus ?case using ih by auto\n  qed\n\ninductive_cases step_cases: \"(e::trm) \\<longrightarrow> e'\"\n\n\ninductive_cases bi_reduce:\"BI b \\<hookrightarrow> x\"\ninductive_cases bool_reduce:\"Bool b \\<hookrightarrow> x\"\ninductive_cases abs_reduce:\"(Lam[a:T].b) \\<hookrightarrow> x\"\ninductive_cases num_reduce:\"Num n \\<hookrightarrow> x\"\n\nlemma value_reduce_step:\n  assumes A:\"v : values\" and B:\"v \\<longrightarrow> (v'::trm)\"\n  shows \"v \\<hookrightarrow> v'\"\n  using B A\n  proof(induct)\n    fix E L R\n    assume \"E : ctxt\" \"L \\<hookrightarrow> R\" \"E L \\<in> values\"\n    hence \"E L = L\" and \"E R = R\" using value_no_ctxt by auto\n    thus \"E L \\<hookrightarrow> E R\" using prems by auto\n  qed\n\nlemma value_not_step:\n  assumes \"v : values\"\n  shows \"~ (EX v'. v \\<hookrightarrow> v')\"\nproof(rule ccontr, simp)\n  assume \"\\<exists>v'. v \\<hookrightarrow> v'\"\n  then obtain v' where A:\"v \\<hookrightarrow> v'\" by auto\n  show False using `v : values` A\n    proof (induct v rule: values.induct)\n      case (bi_value b) thus ?case using bi_reduce by auto\n    next\n      case num_value thus ?case using num_reduce by auto\n    next\n      case abs_value thus ?case using abs_reduce by blast\n    next\n      case bool_value thus ?case using bool_reduce by auto\n    qed\n  qed\n\n\nlemma value_not_reduce:\n  fixes v v' :: trm\n  assumes \"v : values\"\n  shows \"~ (EX v'. v \\<longrightarrow> v')\"\nproof (rule ccontr)\n  assume \"\\<not> \\<not> (\\<exists>v'.  v \\<longrightarrow> v')\"\n  then obtain v' where \"v \\<longrightarrow> v'\" by auto\n  hence A:\"v \\<hookrightarrow> v'\" using value_reduce_step prems by auto\n  show False using `v : values` A value_not_step by auto\nqed\n\n\ntheorem preservation:\n  fixes e e' :: trm\n  assumes typed:\"\\<Gamma> \\<turnstile> e : t ; eff\" and cl:\"closed e\"\n  and red:\"e \\<longrightarrow> e'\"\n  shows \"EX t' eff'. \\<Gamma> \\<turnstile> e' : t' ; eff' \\<and> \\<turnstile> t' <: t \\<and> \\<turnstile> eff' <e: eff\"\n  using red typed cl\nproof -\n  have val:\"valid \\<Gamma>\" using typing_valid typed by auto\n  obtain C L R where \"e = C L\" \"e' = C R\" and \"L \\<hookrightarrow> R\" and \"C : ctxt\" using red step_cases[of e e' thesis] by auto\n  hence f:\"EX T F. \\<Gamma> \\<turnstile> L : T ; F\" using typed typing_ctxt by auto\n  have \"L \\<notin> values\" using `L \\<hookrightarrow> R` value_not_step by auto\n  have \"closed L\" and \"closed_ctxt C\" using closed_in_ctxt_closed_ctxt[of e C L] `C : ctxt`  cl `e = C L` by auto\n  hence \"closed R\" using reduce_closed[of L R] `L  \\<hookrightarrow> R` by auto\n  hence \"closed (C R)\" and \"closed (C L)\"  using `closed_ctxt C` ctxt_closed[of C L] ctxt_closed[of C R] `closed L` by auto\n  have \" \\<And>T0 F0. \\<Gamma> \\<turnstile> L : T0 ; F0  \\<Longrightarrow> \\<exists>T1 F1.  \\<Gamma> \\<turnstile> R : T1 ; F1  \\<and> \\<turnstile> T1 <: T0 \\<and> \\<turnstile> F1 <e: F0\"\n  proof -\n    fix T0 F0\n    show \"\\<Gamma> \\<turnstile> L : T0 ; F0 \\<Longrightarrow>  (\\<exists>T1 F1.  \\<Gamma> \\<turnstile> R : T1 ; F1  \\<and> \\<turnstile> T1 <: T0 \\<and> \\<turnstile> F1 <e: F0)\"\n      using `e = C L` `C : ctxt` `L \\<hookrightarrow> R` closed_in_ctxt[of C L] cl preserve_red[of \\<Gamma> L T0 F0 R] `closed L` val by auto\n  qed\n  hence \"\\<exists>S G.  \\<Gamma> \\<turnstile> C R : S ; G  \\<and> \\<turnstile> S <: t \\<and> \\<turnstile> G <e: eff\"\n    using `C : ctxt` subst_in_ctxt_preserves_type[of \\<Gamma> e t eff C L R] typed `e = C L` `closed (C L)` `closed (C R)`\n      `L \\<notin> values`by auto\n  thus ?thesis using `e' = C R` by auto\nqed\n\ntext {* soundness *}\n\nlemma soundness_finite:\n  fixes e e' e'' :: trm\n  assumes A:\"\\<Gamma> \\<turnstile> e : T ; F\" and B:\"e \\<longrightarrow>\\<^sup>* e'\" and C:\"~ (EX e''. e' \\<longrightarrow> e'')\" and E:\"closed e\"\n  shows \"EX T' F'. (e' : values \\<and> \\<Gamma> \\<turnstile> e' : T' ; F' \\<and> \\<turnstile> T' <: T \\<and> \\<turnstile> F' <e: F)\"\n  using B prems\nproof (induct arbitrary: \\<Gamma> T F rule: step_multi.induct)\n  case (sm_refl v)\n  have \"v : values\" using sm_refl progress[of \\<Gamma> v T F] by auto\n  thus ?case using sm_refl by auto\nnext\n  case (sm_trans a b c)\n  have \"closed b\" \"closed c\" using `closed a` `b \\<longrightarrow>\\<^sup>* c` `a \\<longrightarrow> b` step_closed[of a b] multi_step_closed[of b c] by auto\n  then obtain T' F' where 1:\"\\<Gamma> \\<turnstile> b : T' ; F'\"  \"\\<turnstile> T' <: T\" \"\\<turnstile> F' <e: F\"\n    using preservation[of \\<Gamma> a T F b] sm_trans by auto\n  then obtain T'' F'' where 2:\"\\<Gamma> \\<turnstile> c : T'' ; F''\"  \"\\<turnstile> T'' <: T'\"  \"\\<turnstile> F'' <e: F'\" \"c : values\"\n    using  sm_trans(3)[of \\<Gamma> T' F'] sm_trans `closed b` by blast\n  have \"\\<turnstile> T'' <: T\" using 1 2 by auto\n  have 3:\"simple_eff F\" using prems closed_eff by auto\n  have 4:\"simple_eff F'\" using 1 prems closed_eff `closed b` by auto\n  have 5:\"simple_eff F''\" using  prems closed_eff `closed c` by auto\n  from 3 4 5 have \"\\<turnstile> F'' <e: F\" using SE_Trans[of F'' F' F] 1 2 by auto\n  thus ?case using 2 `\\<turnstile> T'' <: T`  by auto\nqed\n\ntext\n{*\n    interesting fact:\n    let e = (Iff True 3 x)\n    then [] \\<turnstile> e : Int ; NE\n    but e is not closed\n*}\n\n\ntheorem soundness:\n  assumes A:\"\\<Gamma> \\<turnstile> e : T ; F\" and E:\"closed e\" \n  shows \"reduce_forever e \\<or> (EX v T' F'. (v : values \\<and> e \\<longrightarrow>\\<^sup>* v \\<and> \\<Gamma> \\<turnstile> v : T' ; F' \\<and> \\<turnstile> T' <: T \\<and> \\<turnstile> F' <e: F))\"\nproof -\n  {\n    assume \"~(reduce_forever e)\"\n    hence \"EX e'. (e \\<longrightarrow>\\<^sup>* e') \\<and> ~(EX e''. e' \\<longrightarrow> e'')\" by (auto simp add: reduce_forever_def)\n    then obtain e'::trm where B:\"e \\<longrightarrow>\\<^sup>* e'\" and C:\"~ (EX e''. e' \\<longrightarrow> e'')\" by auto\n    hence ?thesis using soundness_finite[OF A B C E] by auto\n  }\n  moreover\n  {\n    assume \"reduce_forever e\" \n    hence ?thesis by simp\n  }\n  ultimately show ?thesis by auto\nqed\n\ntext {* simpler type system, without silly rules *}\n\ninductive\n  typing2 :: \"varEnv \\<Rightarrow> trm \\<Rightarrow> ty \\<Rightarrow> eff \\<Rightarrow> bool\" (\" _ \\<turnstile>\\<^isub>2 _ : _ ; _ \" [60,60,60,60] 60) \nwhere\n  T2_Var[intro]:   \"\\<lbrakk>valid \\<Gamma>; (v,T)\\<in>set \\<Gamma>\\<rbrakk>\\<Longrightarrow> \\<Gamma> \\<turnstile>\\<^isub>2 Var v : T ; VE v\" \n| T2_Const[intro]: \"valid \\<Gamma> \\<Longrightarrow> \\<Delta>\\<^isub>\\<tau> b = T \\<Longrightarrow> \\<Gamma> \\<turnstile>\\<^isub>2 (BI b) : T ; TT\"\n| T2_Num[intro]: \"valid \\<Gamma> \\<Longrightarrow> \\<Gamma> \\<turnstile>\\<^isub>2 (Num n) : ty.Int ; TT\"\n| T2_True[intro]: \"valid \\<Gamma> \\<Longrightarrow> \\<Gamma> \\<turnstile>\\<^isub>2 (Bool True) : ty.TT ; TT\"\n| T2_False[intro]: \"valid \\<Gamma> \\<Longrightarrow> \\<Gamma> \\<turnstile>\\<^isub>2 (Bool False) : ty.FF ; FF\"\n| T2_Abs[intro]:   \"\\<lbrakk>x \\<sharp> \\<Gamma>; ((x,T1)#\\<Gamma>) \\<turnstile>\\<^isub>2 b : T2; eff\\<rbrakk> \\<Longrightarrow> \\<Gamma> \\<turnstile>\\<^isub>2 Lam [x:T1].b : (T1\\<rightarrow>T2 : latent_eff.NE) ; TT\"\n| T2_App[intro]: \"\\<lbrakk>\\<Gamma> \\<turnstile>\\<^isub>2 e1 : U ; eff1 ; \\<turnstile> U <: (T0 \\<rightarrow> T1 : le); \\<Gamma> \\<turnstile>\\<^isub>2 e2 : T; eff2 ;  \\<turnstile> T <: T0\\<rbrakk> \\<Longrightarrow> \\<Gamma> \\<turnstile>\\<^isub>2 App e1 e2 : T1 ; NE\"\n| T2_AppPred[intro]: \"\\<lbrakk>\\<Gamma> \\<turnstile>\\<^isub>2 e1 : U; eff1; \\<turnstile> U <: (T0 \\<rightarrow> T1 : Latent S);  \\<Gamma> \\<turnstile>\\<^isub>2 e2 : T; VE x ;  \\<turnstile> T <: T0\\<rbrakk> \\<Longrightarrow> \\<Gamma> \\<turnstile>\\<^isub>2 App e1 e2 : T1 ; TE S x\"\n| T2_If[intro]: \"\\<lbrakk>\\<Gamma> \\<turnstile>\\<^isub>2 e1 : T1; eff1; (\\<Gamma> |+ eff1) \\<turnstile>\\<^isub>2 e2 : T2; eff2; (\\<Gamma> |- eff1) \\<turnstile>\\<^isub>2 e3 : T3; eff3; \\<turnstile> T2 <: T; \\<turnstile> T3 <: T\\<rbrakk> \\<Longrightarrow>\n  \\<Gamma> \\<turnstile>\\<^isub>2 (Iff e1 e2 e3) : T ; comb_eff eff1 eff2 eff3\"\n| T2_AbsPred[intro]:   \"\\<lbrakk>x \\<sharp> \\<Gamma>; ((x,T1)#\\<Gamma>) \\<turnstile>\\<^isub>2  b : T2; TE S x\\<rbrakk> \\<Longrightarrow> \\<Gamma> \\<turnstile>\\<^isub>2 Lam [x:T1].b : (T1\\<rightarrow>T2 : Latent S) ; TT\"\n\nlemma typing2_typing:\n  assumes \"\\<Gamma> \\<turnstile>\\<^isub>2 e : T ; F\"\n  shows \"\\<Gamma> \\<turnstile> e : T ; F\"\n  using prems\n  by induct (auto simp del: comb_eff.simps)\n\nlemma typing2_soundness1:\n  assumes A:\"\\<Gamma> \\<turnstile>\\<^isub>2 e : T ; F\" and E:\"closed e\" \n  shows \"reduce_forever e \\<or> (EX v T' F'. (v : values \\<and> e \\<longrightarrow>\\<^sup>* v \\<and> \\<Gamma> \\<turnstile> v : T' ; F' \\<and> \\<turnstile> T' <: T \\<and> \\<turnstile> F' <e: F))\"\n  using A E soundness typing2_typing\n  by auto\n\nlemma typing2_soundness_int:\n  assumes A:\"\\<Gamma> \\<turnstile>\\<^isub>2 e : ty.Int ; F\" and E:\"closed e\" \n  shows \"reduce_forever e \\<or> (EX v F'. (v : values \\<and> (e  \\<longrightarrow>\\<^sup>* v) \\<and> \\<Gamma> \\<turnstile>\\<^isub>2 v : ty.Int ; F' \\<and> \\<turnstile> F' <e: F))\"\nproof -\n  from typing2_soundness1[OF A E]\n  have B:\"reduce_forever e \\<or> (EX v T' F'. (v : values  \\<and> (e  \\<longrightarrow>\\<^sup>* v) \\<and> \\<Gamma> \\<turnstile> v : T' ; F' \\<and> \\<turnstile> T' <: ty.Int \\<and> \\<turnstile> F' <e: F))\" by auto\n  thus ?thesis\n  proof \n    assume \"EX v T' F'. (v : values  \\<and> (e  \\<longrightarrow>\\<^sup>* v) \\<and> \\<Gamma> \\<turnstile> v : T' ; F' \\<and> \\<turnstile> T' <: ty.Int \\<and> \\<turnstile> F' <e: F)\"\n    then guess v T' F' by auto\n    then obtain n where \"v = Num n\" using int_value by blast\n    hence \"\\<Gamma> \\<turnstile>\\<^isub>2 v : ty.Int ; F'\" using num_ty_elim[of \\<Gamma> _ T' F'] `\\<Gamma> \\<turnstile> v : T' ; F'` by auto\n    thus ?thesis  using `\\<turnstile> F' <e: F` `v : values` `(e  \\<longrightarrow>\\<^sup>* v)` by auto\n  qed (auto)\nqed\n\nlemma typing2_soundness_help:\n  assumes A:\"\\<Gamma> \\<turnstile>\\<^isub>2 e : \\<sigma> ; F\" and E:\"closed e\" \n  and B: \"((\\<exists>v T' F'. v \\<in> values \\<and>  \\<Gamma> \\<turnstile> v : T' ; F'  \\<and> \\<turnstile> T' <: \\<sigma> \\<and> \\<turnstile> F' <e: F)) \\<Longrightarrow>  \n  (reduce_forever e \\<or> (\\<exists>v F'. v \\<in> values \\<and>  \\<Gamma> \\<turnstile>\\<^isub>2 v : \\<sigma> ; F'  \\<and> \\<turnstile> F' <e: F))\"\n  shows \"(reduce_forever e \\<or> (\\<exists>v F'. v \\<in> values \\<and>  \\<Gamma> \\<turnstile>\\<^isub>2 v : \\<sigma> ; F'  \\<and> \\<turnstile> F' <e: F))\"\n  using A B E typing2_soundness1 by blast\n\nlemma typing2_soundness_bool:\n  assumes A:\"\\<Gamma> \\<turnstile>\\<^isub>2 e : T ; F\" and E:\"closed e\" and sub:\"\\<turnstile> T <: BoolTy\"\n  shows \"reduce_forever e \\<or> (EX v F' T'. (v : values \\<and> (e  \\<longrightarrow>\\<^sup>* v) \\<and> \\<Gamma> \\<turnstile>\\<^isub>2 v : T' ; F' \\<and> \\<turnstile> F' <e: F \\<and> \\<turnstile> T' <: T))\"\nproof -\n  from typing2_soundness1[OF A E]\n  have B:\"reduce_forever e \\<or> (EX v T' F'. (v : values \\<and> (e  \\<longrightarrow>\\<^sup>* v) \\<and> \\<Gamma> \\<turnstile> v : T' ; F' \\<and> \\<turnstile> T' <: T \\<and> \\<turnstile> F' <e: F))\"\n    by blast\n  thus ?thesis\n  proof\n    assume \"EX v T' F'. (v : values \\<and> (e  \\<longrightarrow>\\<^sup>* v) \\<and> \\<Gamma> \\<turnstile> v : T' ; F' \\<and> \\<turnstile> T' <: T \\<and> \\<turnstile> F' <e: F)\"\n    then guess v T' F' by auto\n    then obtain b where \"v = Bool b\" using bool_value[OF `v : values` `\\<Gamma> \\<turnstile> v : T' ; F'`] sub by auto\n    hence \"\\<Gamma> \\<turnstile>\\<^isub>2 Bool b : T' ; F'\" using `\\<Gamma> \\<turnstile> v : T' ; F'`\n      true_ty_elim[of \\<Gamma> T' F'] false_ty_elim[of \\<Gamma> T' F']\n      by (cases b) auto\n    thus ?thesis using `v = Bool b`  `e  \\<longrightarrow>\\<^sup>* v` `v : values` `\\<turnstile> F' <e: F` `\\<turnstile> T' <: T` by blast\n  qed (auto)\nqed\n\nconstdefs\n  ground_type :: \"ty \\<Rightarrow> bool\"\n  \"ground_type t == t = ty.Int \\<or> t = BoolTy \\<or> t = ty.TT \\<or> t = ty.FF\"\n\n\nlemma supp_env:\n  \"(a,b) : set (\\<Gamma> :: varEnv) \\<Longrightarrow> a : supp \\<Gamma>\"\n  by (induct \\<Gamma>) (auto simp add: supp_list_cons supp_prod supp_atm)\n\nlemma envop_supp:\n  assumes \"valid \\<Gamma>\"\n  shows \"x : (supp (envop f n t \\<Gamma>)) \\<Longrightarrow> x : (supp \\<Gamma> :: name set)\"\nproof -\n  assume A:\"x : (supp (envop f n t \\<Gamma>))\"\n  have \"!! a. a \\<notin> (supp \\<Gamma> :: name set) \\<Longrightarrow> a \\<notin> supp (envop f n t \\<Gamma>)\"\n  proof -\n    fix a\n    show  \"a \\<notin> (supp \\<Gamma> :: name set) \\<Longrightarrow> a \\<notin> supp (envop f n t \\<Gamma>)\"\n      using fresh_def[of a \"envop f n t \\<Gamma>\"] envop_fresh[OF _  `valid \\<Gamma>`] fresh_def[of a \\<Gamma>]\n      by auto\n  qed\n  hence \"(supp (envop f n t \\<Gamma>)) <= (supp \\<Gamma> :: name set)\" by blast\n  thus ?thesis using A by auto\nqed\n\ndeclare envop_def[simp del]\n\nlemma envplus_supp:\n  assumes \"valid \\<Gamma>\"\n  shows \"(supp (\\<Gamma> |+ F) :: name set) <= (supp \\<Gamma> :: name set)\"\n  using prems\n  apply (nominal_induct F rule: eff.induct)\n  apply (auto simp add: envop_supp)\n  done\n\nlemma envminus_supp:\n  assumes \"valid \\<Gamma>\"\n  shows \"(supp (\\<Gamma> |- F) :: name set) <= (supp \\<Gamma> :: name set)\"\n  using prems\n  apply (nominal_induct F rule: eff.induct)\n  apply (auto simp add: envop_supp)\n  done\n\nlemma env_supp_typing2:\n  assumes \"\\<Gamma> \\<turnstile>\\<^isub>2 e : T ; F\"\n  shows \"fv e <= supp \\<Gamma>\"\n  using prems\nproof (induct \\<Gamma> e T F rule: typing2.induct)\n  case T2_Var\n  thus ?case by (auto simp add: trm.supp supp_atm supp_env)\nnext\n  case T2_App thus ?case by (auto simp add: trm.supp)\nnext\n  case T2_AppPred thus ?case by (auto simp add: trm.supp)\nnext\n  case (T2_If \\<Gamma> _ _ F)\n  have \"valid \\<Gamma>\" using typing_valid typing2_typing[OF T2_If(1)] by auto\n  thus ?case using T2_If envminus_supp[OF `valid \\<Gamma>`, of F] envplus_supp[OF `valid \\<Gamma>`, of F]\n    by (auto simp add: trm.supp)\nnext\n  case T2_Abs thus ?case \n    by (auto simp add: trm.supp fv_lam abs_supp supp_list_cons supp_prod supp_latent_eff_ty supp_atm)\nnext\n  case T2_AbsPred thus ?case \n    by (auto simp add: trm.supp fv_lam abs_supp supp_list_cons supp_prod supp_latent_eff_ty supp_atm)\nnext\n  case (T2_Const \\<Gamma> b) thus ?case\n    by (nominal_induct b rule: builtin.induct)\n     (auto simp add: trm.supp  builtin.supp)\nqed (auto simp add: trm.supp supp_nat supp_bool)\n\nlemma empty_env_typing2_closed:\n  assumes \"[] \\<turnstile>\\<^isub>2 e : T ; F\"\n  shows \"closed e\"\n  using env_supp_typing2[OF prems] closed_def prems supp_list_nil\n  by auto\n\ntheorem ground_type_soundness:\n  assumes A:\"[] \\<turnstile>\\<^isub>2 e : T ; F\" and B:\"ground_type T\"\n  shows \"reduce_forever e \\<or> (EX v T' F'. (v : values \\<and> (e  \\<longrightarrow>\\<^sup>* v) \\<and> [] \\<turnstile>\\<^isub>2 v : T' ; F' \\<and> \\<turnstile> T' <: T \\<and> \\<turnstile> F' <e: F))\"\nproof -\n  have E:\"closed e\" using empty_env_typing2_closed[OF A] by simp\n  {\n    assume \"T = ty.Int\"\n    hence \"reduce_forever e \\<or> (EX v F'. (v : values \\<and> (e  \\<longrightarrow>\\<^sup>* v) \\<and> [] \\<turnstile>\\<^isub>2 v : ty.Int ; F' \\<and> \\<turnstile> F' <e: F))\"\n      using A E typing2_soundness_int by auto\n    hence ?thesis using prems by auto\n  }\n  moreover\n  {\n    assume \"T ~= ty.Int\"\n    hence \"\\<turnstile> T <: BoolTy\" using B by (auto simp add: ground_type_def)\n    hence \"reduce_forever e \\<or> (EX v F' T'. (v : values \\<and> (e  \\<longrightarrow>\\<^sup>* v) \\<and> [] \\<turnstile>\\<^isub>2 v : T' ; F' \\<and> \\<turnstile> F' <e: F \\<and> \\<turnstile> T' <: T))\"\n      using typing2_soundness_bool[OF A E] by auto\n    hence ?thesis using prems by auto\n  }\n  ultimately show ?thesis using B ground_type_def by auto\nqed\n\n\nend\n\n\nlemma unique_decomposition: \n  assumes a:\"closed e\"\n  shows \"\\<lbrakk>E : ctxt; E t = e; E' : ctxt; E' t' = e\\<rbrakk> \\<Longrightarrow> E = E'\"\n  using a\n  proof (nominal_induct e rule: trm.induct)\n    case (Var v)\n    have f1:\"E = (%t. t)\" using Var by cases auto\n    have f2:\"E'= (%t. t)\" using `E' : ctxt` Var by cases auto\n    from f1 f2 show ?case by simp\n  next\n    case (Bool c)\n    have f1:\"E = (%t. t)\" using Bool by cases auto\n    have f2:\"E'= (%t. t)\" using `E' : ctxt` Bool by cases auto\n    from f1 f2 show ?case by simp\n  next\n    case (Num c)\n    have f1:\"E = (%t. t)\" using Num by cases auto\n    have f2:\"E'= (%t. t)\" using `E' : ctxt` Num by cases auto\n    from f1 f2 show ?case by simp\n  next\n    case Abs\n    have f1:\"E = (%t. t)\" using `E : ctxt` Abs by cases auto\n    have f2:\"E'= (%t. t)\" using `E' : ctxt` Abs by cases auto\n    from f1 f2 show ?case by simp\n  next\n    case (Iff tst thn els)\n    {\n      assume \"tst \\<notin> values\"\n      hence \"EX E L R. tst = E L \\<and> E \\<in> ctxt \\<and> L \\<hookrightarrow> R\" using decomposition \n      have f1:\"E = (%t. t)\" using `E : ctxt` Iff apply cases apply (auto  simp add: trm.inject)\n      have f2:\"E'= (%t. t)\" using `E' : ctxt` Iff by cases auto\n      from f1 f2 have ?case by simp\n      {\n    oops\n    \nlemma fresh_fact: \n  fixes a::\"name\"\n  assumes a: \"a\\<sharp>t1\"\n  and     b: \"a\\<sharp>t2\"\n  shows \"a\\<sharp>(t1[b::=t2])\"\nusing a b\nby (nominal_induct t1 avoiding: a b t2 rule: trm.induct)\n   (auto simp add: abs_fresh fresh_atm)\n\nlemma id_subs: \"t[x::=Var x] = t\"\nby (nominal_induct t avoiding: x rule: trm.induct)\n   (simp_all add: fresh_atm)\n\nlemma random_eqvt[simp]:\n  fixes pi :: \"name prm\"\nshows \"\\<forall>T. T \\<in> set Ts \\<longrightarrow> \\<turnstile> T <: S \\<and> \\<turnstile> pi \\<bullet> T <: pi \\<bullet> S \\<Longrightarrow>\n    \\<forall>T. T \\<in> set (pi \\<bullet> Ts) \\<longrightarrow> \\<turnstile> T <: pi \\<bullet> S\"\nproof - \n  assume 0:\"\\<forall>T. T \\<in> set Ts \\<longrightarrow> \\<turnstile> T <: S \\<and> \\<turnstile> pi \\<bullet> T <: pi \\<bullet> S\"\n  hence 1:\"!! T. T \\<in> set Ts \\<Longrightarrow> \\<turnstile> T <: S \\<and> \\<turnstile> pi \\<bullet> T <: pi \\<bullet> S\" by auto\n  have A:\"(pi \\<bullet> Ts) = Ts\" by (induct Ts) auto\n  have B:\"pi \\<bullet> S = S\" by auto\n  have \"!! T.  T \\<in> set (pi \\<bullet> Ts) \\<Longrightarrow> \\<turnstile> T <: pi \\<bullet> S\"\n  proof -\n    fix T\n    assume \"T \\<in> set (pi \\<bullet> Ts)\"\n    hence \"T : set Ts\" using A by auto\n    hence \"\\<turnstile> T <: S\" using 1 by auto\n    thus \"\\<turnstile> T <: pi \\<bullet> S\" using B by auto\n  qed\n  thus ?thesis by auto\nqed\n\n\ntext {* complete induction on typing derivations *}\n\nlemma typing_induct_complete[consumes 1, case_names T_Var T_Const T_Num T_True T_False T_App T_Lam T_AppPred T_If \n  T_AppPredTrue T_AppPredFalse T_IfTrue T_IfFalse]:\n  fixes  P :: \"'a::fs_name\\<Rightarrow>(name\\<times>ty) list \\<Rightarrow> trm \\<Rightarrow> ty \\<Rightarrow> eff \\<Rightarrow> bool\"\n  and    \\<Gamma> :: \"(name\\<times>ty) list\"\n  and    t :: \"trm\"\n  and    T :: \"ty\"\n  and    F :: \"eff\"\n  and    x :: \"'a::fs_name\"\n  assumes a: \"\\<Gamma> \\<turnstile> t : T ; F\"\n  and a1:    \"\\<And>\\<Gamma> (a::name) \\<tau> x. valid \\<Gamma> \\<Longrightarrow> (a,\\<tau>) \\<in> set \\<Gamma> \\<Longrightarrow> \n  (!! x t T \\<Gamma> F. (t\\<guillemotleft>Var a) \\<Longrightarrow> \\<Gamma> \\<turnstile> t : T ; F \\<Longrightarrow> P x \\<Gamma> t T F) \\<Longrightarrow> valid \\<Gamma> \\<Longrightarrow> P x \\<Gamma> (Var a) \\<tau> (VE a)\"\n  and a2:    \"!! \\<Gamma> b T x. \\<Delta>\\<^isub>\\<tau> b = T \\<Longrightarrow> \n  (!! x t T \\<Gamma> F. (t\\<guillemotleft>BI b) \\<Longrightarrow> \\<Gamma> \\<turnstile> t : T ; F \\<Longrightarrow> P x \\<Gamma> t T F) \\<Longrightarrow> valid \\<Gamma> \\<Longrightarrow> P x \\<Gamma> (BI b) T NE\"\n  and a3:    \"!! \\<Gamma> n x.   (!! x t T \\<Gamma> F. (t\\<guillemotleft>Num n) \\<Longrightarrow> \\<Gamma> \\<turnstile> t : T ; F \\<Longrightarrow> P x \\<Gamma> t T F) \\<Longrightarrow> valid \\<Gamma> \\<Longrightarrow> \n  P x \\<Gamma> (Num n) ty.Int NE\"\n  and a4:    \"!! \\<Gamma> x.   (!! x t T \\<Gamma> F. (t\\<guillemotleft>Bool True) \\<Longrightarrow> \\<Gamma> \\<turnstile> t : T ; F \\<Longrightarrow> P x \\<Gamma> t T F) \\<Longrightarrow> valid \\<Gamma> \\<Longrightarrow> \n  P x \\<Gamma> (Bool True) BoolTy TT\"\n  and a5:    \"!! \\<Gamma> x. (!! x t T \\<Gamma> F. (t\\<guillemotleft>Bool False)  \\<Longrightarrow> \\<Gamma> \\<turnstile> t : T ; F \\<Longrightarrow> P x \\<Gamma> t T F) \\<Longrightarrow> valid \\<Gamma> \\<Longrightarrow> \n  P x \\<Gamma> (Bool False) BoolTy FF\"\n  and a6:    \"\\<And>\\<Gamma> \\<tau> \\<sigma> t1 t2 x F1 F2 le \\<tau>0 U. (!! x t T \\<Gamma> F. (t\\<guillemotleft>App t1 t2) \\<Longrightarrow> \\<Gamma> \\<turnstile> t : T ; F \\<Longrightarrow> P x \\<Gamma> t T F) \\<Longrightarrow> \n              \\<Gamma> \\<turnstile> t1 : U ; F1 \\<Longrightarrow> \\<turnstile> U <: \\<tau>\\<rightarrow>\\<sigma>:le \\<Longrightarrow> (\\<And>z. P z \\<Gamma> t1 U F1) \\<Longrightarrow> \\<Gamma> \\<turnstile> t2 : \\<tau>0 ; F2 \\<Longrightarrow> (\\<And>z. P z \\<Gamma> t2 \\<tau>0 F2) \\<Longrightarrow> \\<turnstile> \\<tau>0 <: \\<tau>\n              \\<Longrightarrow> P x \\<Gamma> (App t1 t2) \\<sigma> NE\"\n  and a7:    \"\\<And>a \\<Gamma> \\<tau> \\<sigma> t x F0. a\\<sharp>x \\<Longrightarrow> a\\<sharp>\\<Gamma> \\<Longrightarrow> ((a,\\<tau>) # \\<Gamma>) \\<turnstile> t : \\<sigma> ; F0 \\<Longrightarrow> (\\<And>z. P z ((a,\\<tau>)#\\<Gamma>) t \\<sigma> F0) \\<Longrightarrow>\n              (!! x t' T \\<Gamma> F. (t'\\<guillemotleft>Lam[a:\\<tau>].t) \\<Longrightarrow> \\<Gamma> \\<turnstile> t' : T ; F \\<Longrightarrow> P x \\<Gamma> t' T F) \n              \\<Longrightarrow> P x \\<Gamma> (Lam [a:\\<tau>].t) (\\<tau>\\<rightarrow>\\<sigma>:latent_eff.NE) NE\"\n  and a8:    \"\\<And>\\<Gamma> \\<tau> \\<sigma> t1 t2 x F1 \\<tau>0 S v U. \n              (!! x t T \\<Gamma> F. t \\<guillemotleft> App t1 t2 \\<Longrightarrow> \\<Gamma> \\<turnstile> t : T ; F \\<Longrightarrow> P x \\<Gamma> t T F) \\<Longrightarrow> \n              \\<Gamma> \\<turnstile> t1 : U ; F1 \\<Longrightarrow> \\<turnstile> U <: (\\<tau>\\<rightarrow>\\<sigma>:Latent S) \\<Longrightarrow> (\\<And>z. P z \\<Gamma> t1 U F1) \\<Longrightarrow> \\<Gamma> \\<turnstile> t2 : \\<tau>0 ; VE v \\<Longrightarrow> \n              (\\<And>z. P z \\<Gamma> t2 \\<tau>0 (VE v)) \n              \\<Longrightarrow> \\<turnstile> \\<tau>0 <: \\<tau>  \\<Longrightarrow> P x \\<Gamma> (App t1 t2) \\<sigma> (TE S v)\"\n  and a9:    \"!! \\<Gamma> e1 e2 e3 T1 T2 T3 T eff1 eff2 eff3 x. \n                 \\<lbrakk>\\<Gamma> \\<turnstile> e1 : T1; eff1; !!z. P z \\<Gamma> e1 T1 eff1; (\\<Gamma> |+ eff1) \\<turnstile> e2 : T2; eff2; !!z. P z (\\<Gamma>|+ eff1) e2 T2 eff2; \n                (!! x t T \\<Gamma> F. t \\<guillemotleft> Iff e1 e2 e3 \\<Longrightarrow> \\<Gamma> \\<turnstile> t : T ; F \\<Longrightarrow> P x \\<Gamma> t T F);\n                 (\\<Gamma> |- eff1) \\<turnstile> e3 : T3; eff3; !!z. P z (\\<Gamma>|- eff1) e3 T3 eff3; \\<turnstile> T2 <: T; \\<turnstile> T3 <: T\\<rbrakk>\n                 \\<Longrightarrow> P x \\<Gamma> (Iff e1 e2 e3) T NE\"\n  and a10:   \"!! \\<Gamma> e1 e2 T0 T1 T S eff1 eff2 x U. \n              \\<lbrakk>\\<Gamma> \\<turnstile> e1 : U; eff1; \\<turnstile> U <: (T0 \\<rightarrow> T1 : Latent S) ; !!z. P z \\<Gamma> e1 U eff1;\n              (!! x t T \\<Gamma> F. t \\<guillemotleft> App e1 e2 \\<Longrightarrow> \\<Gamma> \\<turnstile> t : T ; F \\<Longrightarrow> P x \\<Gamma> t T F);\n              \\<Gamma> \\<turnstile> e2 : T; eff2 ;  !! z. P z \\<Gamma> e2 T eff2; \\<turnstile> T <: T0; \\<turnstile> T <: S\\<rbrakk> \\<Longrightarrow> P x \\<Gamma> (App e1 e2) T1 TT\"\n  and a11:   \"!! \\<Gamma> e1 e2 T0 T1 T S eff1 eff2 x U. \n              \\<lbrakk>\\<Gamma> \\<turnstile> e1 : U; eff1; \\<turnstile> U <: (T0 \\<rightarrow> T1 : Latent S) ; !!z. P z \\<Gamma> e1 U eff1;\n              (!! x t T \\<Gamma> F. t \\<guillemotleft> App e1 e2 \\<Longrightarrow> \\<Gamma> \\<turnstile> t : T ; F \\<Longrightarrow> P x \\<Gamma> t T F);\n              \\<Gamma> \\<turnstile> e2 : T; eff2 ;  !! z. P z \\<Gamma> e2 T eff2; \\<turnstile> T <: T0; ~(\\<turnstile> T <: S) ; e2 : values ; closed e2\\<rbrakk>\n  \\<Longrightarrow> P x \\<Gamma> (App e1 e2) T1 FF\"\n  and a12:   \"!! \\<Gamma> e1 e2 e3 T T1 T2 eff x. \\<lbrakk>\\<Gamma> \\<turnstile> e1 : T1 ; TT ; !! z. P z \\<Gamma> e1 T1 TT; \n                (!! x t T \\<Gamma> F. t \\<guillemotleft> Iff e1 e2 e3 \\<Longrightarrow> \\<Gamma> \\<turnstile> t : T ; F \\<Longrightarrow> P x \\<Gamma> t T F);\n               \\<Gamma> \\<turnstile> e2 : T2 ; eff;  !!z .P z \\<Gamma> e2 T2 eff; \\<turnstile> T2 <: T\\<rbrakk> \\<Longrightarrow> P x \\<Gamma> (Iff e1 e2 e3) T NE\"\n  and a13:   \"!! \\<Gamma> e1 e2 e3 T T1 T3 eff x. \\<lbrakk>\\<Gamma> \\<turnstile> e1 : T1 ; FF ; !! z. P z \\<Gamma> e1 T1 FF; \n                (!! x t T \\<Gamma> F. t \\<guillemotleft> Iff e1 e2 e3 \\<Longrightarrow> \\<Gamma> \\<turnstile> t : T ; F \\<Longrightarrow> P x \\<Gamma> t T F);\n               \\<Gamma> \\<turnstile> e3 : T3 ; eff;  !!z .P z \\<Gamma> e3 T3 eff; \\<turnstile> T3 <: T\\<rbrakk> \\<Longrightarrow> P x \\<Gamma> (Iff e1 e2 e3) T NE\"\n  shows \"P x \\<Gamma> t T F\"\n  using a\n  proof (nominal_induct t avoiding: x \\<Gamma> T F rule: trm_comp_induct)\n    case (Var v) \n    thus ?case using a1 var_ty_elim[of \\<Gamma> v T F] by auto\n  next\n    case (App t1 t2 x \\<Gamma> T)\n    show ?case using App(4)\n    proof (induct rule: app_ty_elim2)\n      case 1 thus ?thesis using a6 App trm.inject ty.inject by auto\n    next\n      case 2 thus ?thesis using a8 App trm.inject ty.inject by auto\n    next\n      case 3 thus ?thesis using a10 App trm.inject ty.inject by auto\n    next\n      case 4 thus ?thesis using a11 App trm.inject ty.inject by auto\n    qed\n  next\n    case Iff\n    show ?case using Iff(5)\n    proof (induct rule: iff_ty_elim2)\n      case 1 thus ?thesis using a9 Iff trm.inject ty.inject by auto\n    next\n      case 2 thus ?thesis using a12 Iff trm.inject ty.inject by auto\n    next\n      case 3 thus ?thesis using a13 Iff trm.inject ty.inject by auto\n    qed\n  next\n    case (Lam v b x \\<Gamma> S1 F S2)\n    show ?case using Lam abs_ty_elim[of \\<Gamma> v b S2 S1 F] a7 by (auto simp add: trm.inject ty.inject)\n  next\n    case (BI b) thus ?case using bi_ty_elim[of \\<Gamma> b T F] trm.inject a2 by auto\n  next\n    case (Num n) thus ?case using num_ty_elim[of \\<Gamma> n T F] trm.inject a3 by auto\n  next\n    case (Bool b) thus ?case using true_ty_elim[of \\<Gamma> T F] false_ty_elim[of \\<Gamma> T F] trm.inject a4 a5 by (cases b) auto\nqed\n\n\n", "meta": {"author": "samth", "repo": "samth.github.io", "sha": "5005dd35a90a9c0d92c485b0551cb3ef993f462b", "save_path": "github-repos/isabelle/samth-samth.github.io", "path": "github-repos/isabelle/samth-samth.github.io/samth.github.io-5005dd35a90a9c0d92c485b0551cb3ef993f462b/TypedScheme.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.5117166047041652, "lm_q1q2_score": 0.27779215608359015}}
{"text": "theory PermEnvMisc\n  imports PermEnvLeq\nbegin\n  \n    (* \n      ####################################\n        P2. weak disjointness lemmas\n      ####################################\n    *)  \n\nlemma mini_disj_leq_use_env1: \"\\<lbrakk> mini_disj_use_env r_s r_ex; leq_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> mini_disj_use_env r_x r_ex\"    \n  apply (simp add: leq_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (rule_tac allI)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (case_tac \"r_s x\")\n     apply (auto)\n  done\n\nlemma mini_disj_leq_use_env2: \"\\<lbrakk> mini_disj_use_env r_ex r_s; leq_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> mini_disj_use_env r_ex r_x\"        \n  apply (simp add: leq_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (rule_tac allI)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)  \n  apply (case_tac \"r_x x\")\n    apply (auto)\n  done   \n\nlemma mini_disj_comp_use_env: \"\\<lbrakk> mini_disj_use_env r_x r_ex; mini_disj_use_env r_s r_ex \\<rbrakk> \\<Longrightarrow> mini_disj_use_env (comp_use_env r_x r_s) r_ex\"    \n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: comp_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)  \n  apply (case_tac \"r_x x\")\n    apply (auto)\n   apply (case_tac \"r_s x\")\n     apply (auto)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n  done\n \nlemma mini_disj_comp_use_env_alt: \"\\<lbrakk> mini_disj_use_env r_ex r_x; mini_disj_use_env r_ex r_s \\<rbrakk> \\<Longrightarrow> mini_disj_use_env r_ex (comp_use_env r_x r_s)\"       \n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: comp_use_env_def)\n  done    \n\nlemma mini_disj_diff_use_env: \"mini_disj_use_env r_x (diff_use_env r_s r_x)\"\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: diff_use_env_def)\n  apply (simp add: minus_use_env_def)\n  apply (simp add: neg_use_env_def)\n  apply (auto)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n  done     \n\nlemma swp_mini_disj_use_env: \"\\<lbrakk> leq_use_env rx_p (diff_use_env r_s r_ex) \\<rbrakk> \\<Longrightarrow> mini_disj_use_env r_ex rx_p\"    \n  apply (simp add: mini_disj_use_env_def)\n  apply (auto)\n  apply (rule_tac r_s=\"diff_use_env r_s r_ex\" in leq_use_none)\n   apply (auto)\n  apply (rule_tac diff_use_none_ex)\n  apply (auto)\n  done    \n    \nlemma mini_disj_empty_use_env: \"mini_disj_use_env empty_use_env r_s\"\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: empty_use_env_def)\n  done\n  \n    \n    (* \n      ####################################\n        P3. main disjointness lemmas\n      ####################################\n    *)    \n\nlemma comm_disj_use_env: \"\\<lbrakk> disj_use_env r_s r_x \\<rbrakk> \\<Longrightarrow> disj_use_env r_x r_s\"\n  apply (simp add: disj_use_env_def)\n  done        \n    \n    (* - ordering lemmas *)\n    \nlemma disj_leq_use_env1: \"\\<lbrakk> disj_use_env r_s r_ex; leq_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> disj_use_env r_x r_ex\"\n  apply (simp add: disj_use_env_def)\n  apply (auto)\n   apply (rule_tac mini_disj_leq_use_env1)\n    apply (auto)\n  apply (rule_tac mini_disj_leq_use_env2)\n   apply (auto)\n  done\n\nlemma disj_leq_use_env2: \"\\<lbrakk> disj_use_env r_ex r_s; leq_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> disj_use_env r_ex r_x\"\n  apply (simp add: disj_use_env_def)\n  apply (auto)\n   apply (rule_tac mini_disj_leq_use_env2)\n    apply (auto)\n  apply (rule_tac mini_disj_leq_use_env1)\n   apply (auto)\n  done     \n    \n    (* - comp lemmas *)\n    \nlemma disj_comp_use_env1: \"\\<lbrakk> disj_use_env r_s1 r_ex; disj_use_env r_s2 r_ex \\<rbrakk> \\<Longrightarrow> disj_use_env (comp_use_env r_s1 r_s2) r_ex\"\n  apply (simp add: disj_use_env_def)\n  apply (auto)\n   apply (rule_tac mini_disj_comp_use_env)\n    apply (auto)\n  apply (rule_tac mini_disj_comp_use_env_alt)\n   apply (auto)\n  done\n\nlemma disj_comp_use_env2: \"\\<lbrakk> disj_use_env r_ex r_s1; disj_use_env r_ex r_s2 \\<rbrakk> \\<Longrightarrow> disj_use_env r_ex (comp_use_env r_s1 r_s2)\"    \n  apply (simp add: disj_use_env_def)\n  apply (auto)\n   apply (rule_tac mini_disj_comp_use_env_alt)\n    apply (auto)\n  apply (rule_tac mini_disj_comp_use_env)\n   apply (auto)\n  done\n\n    (* - lemmas TO BE SORTED *)    \n\nlemma gen_mini_disj_use_env1: \"\\<lbrakk> disj_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> mini_disj_use_env r_x r_s\"    \n  apply (simp add: disj_use_env_def)\n  done\n    \nlemma gen_mini_disj_use_env2: \"\\<lbrakk> disj_use_env r_s r_x \\<rbrakk> \\<Longrightarrow> mini_disj_use_env r_x r_s\"    \n  apply (simp add: disj_use_env_def)\n  done\n    \nlemma disj_add_use_env: \"\\<lbrakk> r_x x = NoPerm; disj_use_env r_s r_x \\<rbrakk> \\<Longrightarrow> disj_use_env (add_use_env r_s x r) r_x\"    \n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: add_use_env_def)\n  done    \n    \nlemma disj_rem_use_env1: \"\\<lbrakk> disj_use_env r_s r_x \\<rbrakk> \\<Longrightarrow> disj_use_env r_s (rem_use_env r_x x)\"      \n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: rem_use_env_def)\n  done\n    \nlemma disj_rem_use_envx: \"\\<lbrakk> disj_use_env r_s r_x \\<rbrakk> \\<Longrightarrow> disj_use_env  (rem_use_env r_s x) r_x\"      \n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: rem_use_env_def)\n  done    \n  \nlemma disj_rem_use_env2: \"\\<lbrakk> r_s x = NoPerm; disj_use_env r_s (rem_use_env r_x x) \\<rbrakk> \\<Longrightarrow> disj_use_env r_s r_x\"    \n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: rem_use_env_def)\n  apply (auto)\n   apply (erule_tac x=\"xa\" in allE)\n   apply (auto)\n   apply (case_tac \"x = xa\")\n    apply (auto)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (auto)\n   apply (case_tac \"x = xa\")\n    apply (auto)\n  apply (case_tac \"x = xa\")\n   apply (auto)\n  done\n\nlemma disj_add_rem_use_env: \"\\<lbrakk> r_s x = NoPerm; disj_use_env r_s r_x \\<rbrakk> \\<Longrightarrow> disj_use_env (add_use_env r_s x r) (rem_use_env r_x x)\"\n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: add_use_env_def)\n  apply (simp add: rem_use_env_def)\n  done\n\nlemma double_weak_disj_use_env: \"\\<lbrakk> weak_use_env r_x; weak_use_env r_s \\<rbrakk> \\<Longrightarrow> disj_use_env r_x r_s\"\n  apply (simp add: weak_use_env_def)\n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  done\n    \n    (* - empty lemmas *)\n    \nlemma disj_empty_use_env1: \"disj_use_env r_s empty_use_env\"\n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: empty_use_env_def)\n  done\n\nlemma disj_empty_use_env2: \"disj_use_env empty_use_env r_s\"\n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: empty_use_env_def)\n  done\n    \n    (* - singleton lemmas *)\n    \nlemma disj_one_use_env: \"\\<lbrakk> r_s x = NoPerm \\<rbrakk> \\<Longrightarrow> disj_use_env r_s (one_use_env x OwnPerm)\"    \n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: one_use_env_def)\n  done  \n    \n    (* \n      ####################################\n        P3. weakness lemmas\n      ####################################\n    *)        \n  \nlemma leq_weak_use_env: \"\\<lbrakk> weak_use_env r_s; leq_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> weak_use_env r_x\"    \n  apply (simp add: weak_use_env_def)\n  apply (simp add: leq_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n  done    \n    \nlemma weak_comp_use_env1: \"\\<lbrakk> weak_use_env (comp_use_env r_sa r_sb) \\<rbrakk> \\<Longrightarrow> weak_use_env r_sa\"    \n  apply (simp add: weak_use_env_def)\n  apply (simp add: comp_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_sb x\")\n    apply (auto)\n  done\n \nlemma weak_comp_use_env2: \"\\<lbrakk> weak_use_env (comp_use_env r_sa r_sb) \\<rbrakk> \\<Longrightarrow> weak_use_env r_sb\"    \n  apply (simp add: weak_use_env_def)\n  apply (simp add: comp_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_sa x\")\n    apply (auto)\n  done    \n \nlemma dist_weak_comp_use_env: \"\\<lbrakk> weak_use_env r_sa; weak_use_env r_sb \\<rbrakk> \\<Longrightarrow> weak_use_env (comp_use_env r_sa r_sb)\"    \n  apply (simp add: weak_use_env_def)\n  apply (simp add: comp_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_sa x\")\n    apply (auto)\n   apply (case_tac \"r_sb x\")\n     apply (auto)\n  apply (case_tac \"r_sb x\")\n    apply (auto)\n  done       \n    \nlemma weak_diff_use_env: \"\\<lbrakk> weak_use_env r_s \\<rbrakk> \\<Longrightarrow> weak_use_env (diff_use_env r_s r_x)\"     \n  apply (simp add: weak_use_env_def)\n  apply (simp add: diff_use_env_def)\n  apply (simp add: minus_use_env_def)\n  apply (simp add: neg_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n  done        \n\n    \nend", "meta": {"author": "dcco", "repo": "perm_lang_ax1", "sha": "5742edc2c5db417002ed6b8acd159c522b3e6e38", "save_path": "github-repos/isabelle/dcco-perm_lang_ax1", "path": "github-repos/isabelle/dcco-perm_lang_ax1/perm_lang_ax1-5742edc2c5db417002ed6b8acd159c522b3e6e38/perm_unsafe_lift/PermEnvMisc.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.2776401202318738}}
{"text": "theory SingleInstruction_CFG\nimports SSA_CFG Generic_Interpretation\nbegin\n\ndatatype node'_part = PhisUses | Defs\ntype_synonym 'node node' = \"'node \\<times> node'_part\"\n\nlemma node'_cases:\n  obtains (PhisUses) n' where \"n = (n',PhisUses)\"\n|         (Defs)     n' where \"n = (n',Defs)\"\n  by (cases n, case_tac b, auto)\n\nlemma[dest!]: \"x \\<noteq> PhisUses \\<Longrightarrow> x = Defs\" by (cases x, simp)\nlemma[dest!]: \"x \\<noteq> Defs \\<Longrightarrow> x = PhisUses\" by (cases x, auto)\n\ninstantiation node'_part :: linorder\nbegin\n  definition[simp]: \"less_node'_part n m \\<equiv> n = PhisUses \\<and> m = Defs\"\n\n  definition[simp]: \"less_eq_node'_part (n::node'_part) m \\<equiv> n = m \\<or> n < m\"\n\n  instance by intro_classes auto\nend\n\nlocale SingleInstruction_CFG = CFG_base \\<alpha>n predecessors Entry \"defs\" \"uses\"\n+ graph_Entry \\<alpha>n predecessors Entry\nfor\n  \\<alpha>n :: \"'node::linorder list\" and\n  predecessors :: \"'node \\<Rightarrow> 'node list\" and\n  Entry :: \"'node\" and\n  \"defs\" :: \"'node \\<Rightarrow> 'var::linorder set\" and\n  \"uses\" :: \"'node \\<Rightarrow> 'var set\" +\nassumes defs_finite: \"finite (defs n)\"\nassumes uses_in_\\<alpha>n: \"v \\<in> uses n \\<Longrightarrow> n \\<in> set \\<alpha>n\"\nassumes uses_finite: \"finite (uses n)\"\nbegin\n  definition[code]: \"disj_\\<alpha>n = List.maps (\\<lambda>n. [(n, PhisUses), (n, Defs)]) \\<alpha>n\"\n  definition[code]: \"disj_predecessors \\<equiv> \\<lambda>(n,part). case part of\n    PhisUses \\<Rightarrow> map (\\<lambda>n. (n, Defs)) (predecessors n)\n  | Defs     \\<Rightarrow> if n \\<in> set \\<alpha>n then [(n, PhisUses)] else []\"\n  definition[code]: \"disj_Entry = (Entry, PhisUses)\"\n  definition[code]: \"disj_defs \\<equiv> \\<lambda>(n,part). case part of\n    PhisUses \\<Rightarrow> {}\n  | Defs     \\<Rightarrow> defs n\"\n  definition[code]: \"disj_uses \\<equiv> \\<lambda>(n,part). case part of\n    PhisUses \\<Rightarrow> uses n\n  | Defs     \\<Rightarrow> {}\"\n\n  declare List.maps_def[simp]\n\n  lemma disj_\\<alpha>n[simp]: \"(n,p) \\<in> set disj_\\<alpha>n \\<longleftrightarrow> n \\<in> set \\<alpha>n\"\n    by (cases p, auto simp: disj_\\<alpha>n_def)\n\n  lemma distinct_disj_\\<alpha>n: \"distinct disj_\\<alpha>n\"\n    unfolding disj_\\<alpha>n_def List.maps_def\n    by (rule distinct_concat, auto simp: \\<alpha>n_distinct inj_on_def distinct_map)\n\n  sublocale disj: graph_path_base disj_\\<alpha>n disj_predecessors .\n\n  lemma disj_inEdges_pred: \"set (disj.inEdges n) = pred (disj.\\<alpha> ()) n\"\n    by (cases n, auto simp: \"disj.inEdges_def\" pred_def disj.\\<alpha>e_def)\n\n  lemma PhisUses_disj_predecessors [simp]: \"(n,PhisUses) \\<in> set (disj_predecessors m) \\<longleftrightarrow> m = (n,Defs) \\<and> n \\<in> set \\<alpha>n\"\n    by (auto simp: disj_predecessors_def split: node'_part.splits)\n\n  lemma Defs_disj_predecessors [simp]: \"(n,Defs) \\<in> set (disj_predecessors m) \\<longleftrightarrow> (\\<exists>m'. m = (m',PhisUses) \\<and> n \\<in> set (predecessors m'))\"\n    by (auto simp: disj_predecessors_def split: node'_part.splits)\n\n  lemma disj_predecessor_is_node: \"n \\<in> set (disj_predecessors m) \\<Longrightarrow> n \\<in> set disj_\\<alpha>n\"\n    by (auto simp: disj_predecessors_def split: node'_part.splits)\n\n  lemma disj_successor_is_node: \"n \\<in> set (disj_predecessors m) \\<Longrightarrow> m \\<in> set disj_\\<alpha>n\"\n    by (auto simp: disj_predecessors_def split: node'_part.splits)\n\n  lemma finite_disj_\\<alpha>e: \"finite disj.\\<alpha>e\"\n    by (rule finite_subset[of _ \"set disj_\\<alpha>n \\<times> {()} \\<times> set disj_\\<alpha>n\"])\n       (auto simp: disj.\\<alpha>e_def dest: disj_predecessor_is_node disj_successor_is_node)\n\n  sublocale disj: graph_path disj_\\<alpha>n disj_predecessors\n  apply unfold_locales\n        apply (simp add: disj_\\<alpha>n_def)\n       apply (simp add: finite_disj_\\<alpha>e)\n      apply (auto simp: disj.\\<alpha>e_def dest: disj_predecessor_is_node)[1]\n     apply (auto simp: disj.\\<alpha>e_def dest: disj_successor_is_node)[1]\n    apply (rule set_iterator_I)\n      prefer 3\n      apply (simp add: foldri_def)\n     apply (simp add: distinct_disj_\\<alpha>n)\n    apply simp\n   unfolding disj_inEdges_pred[symmetric]\n   apply (rule set_iterator_foldri_correct)\n   unfolding \"disj.inEdges_def\"\n   apply (auto simp: disj_predecessors_def distinct_map distinct_predecessors split: node'_part.split)\n  done\n\n  definition \"disj_pathElems p ns p' \\<equiv>\n    let ns = List.maps (\\<lambda>n. [(n, PhisUses), (n, Defs)]) ns in\n    let ns = if p = Defs then tl ns else ns in\n    if p' = PhisUses then butlast ns else ns\"\n\n  lemma disj_pathElems_empty [simp]: \"disj_pathElems p [] p' = []\"\n    by (auto simp: disj_pathElems_def Let_def)\n\n  lemma hd_disj_pathElems [simp]: \"disj_pathElems p ns p' \\<noteq> [] \\<Longrightarrow> hd (disj_pathElems p ns p') = (hd ns,p)\"\n    by (cases ns, auto simp: disj_pathElems_def Let_def)\n\n  lemma disj_pathElems_trivial [simp]: \"disj_pathElems p [n] p = [(n,p)]\"\n    by (auto simp: disj_pathElems_def Let_def)\n\n  lemma disj_pathElems_cons_Defs [simp]: \"ns \\<noteq> [] \\<Longrightarrow> disj_pathElems Defs (n#ns) p' = (n, Defs)#disj_pathElems PhisUses ns p'\"\n    by (auto simp: disj_pathElems_def Let_def)\n\n  lemma disj_pathElems_cons_PhisUses: \"ns \\<noteq> [] \\<Longrightarrow> disj_pathElems PhisUses ns p' = (hd ns, PhisUses)#disj_pathElems Defs ns p'\"\n    by (cases ns, auto simp: disj_pathElems_def Let_def)\n\n  lemma butlast_Defs_in_disj_pathElems: \"n \\<in> set (butlast ns) \\<Longrightarrow> (n, Defs) \\<in> set (disj_pathElems PhisUses ns p)\"\n    by (cases ns rule: rev_cases, auto simp: disj_pathElems_def Let_def butlast_append)\n\n  lemma path2_to_disj_path2:\n    assumes \"path2 n ns m\" \"p \\<le> p'\"\n    shows \"disj.path2 (n,p) (disj_pathElems p ns p') (m,p')\"\n  using assms(1) proof (induction rule: path2_induct)\n    case empty_path\n    have[simp]: \"m \\<in> set \\<alpha>n\" using assms by auto\n    show ?case\n    proof (cases \"p = p'\")\n      case True\n      thus ?thesis\n        by auto\n    next\n      case False\n      with empty_path assms(2) have [simp]: \"p = PhisUses\" \"p' = Defs\"\n        by auto\n      show ?thesis\n        by (simp add: disj_pathElems_cons_PhisUses, rule disj.Cons_path2, rule disj.empty_path2, auto)\n    qed\n  next\n    case (Cons_path ns n' n)\n    have IH: \"disj.path2 (n,p) (disj_pathElems p ns p') (m,p')\"\n      by (rule Cons_path.IH)\n    hence [simp]: \"ns \\<noteq> []\" by (cases ns, auto)\n    from IH have [simp]: \"hd ns = n\" by - (frule disj.path2_hd, subst(asm) hd_disj_pathElems, auto)\n    show ?case\n    apply (cases p)\n     apply simp\n     apply (subst disj_pathElems_cons_PhisUses)\n      apply simp\n     apply simp\n     apply (rule disj.Cons_path2)\n      apply (rule disj.Cons_path2)\n       using IH apply simp\n      using Cons_path.hyps(2) apply auto[2]\n     apply auto[1]\n    apply (subst disj_pathElems_cons_PhisUses)\n     apply simp\n    apply (rule disj.Cons_path2)\n     apply (rule disj.Cons_path2)\n      using IH apply simp\n     using IH Cons_path.hyps(2) by auto\n  qed\n\n  lemma disj_path2_to_path2:\n    assumes \"disj.path2 n ns m\"\n    obtains ns' where \"path2 (fst n) ns' (fst m)\" \"disj_pathElems (snd n) ns' (snd m) = ns\"\n  using assms proof (induction rule: \"disj.path2_induct\")\n    case empty_path\n    from assms have \"fst m \\<in> set \\<alpha>n\"\n      by - (drule disj.path2_tl_in_\\<alpha>n, auto simp: disj_\\<alpha>n_def)\n    thus ?case by - (rule empty_path(1), auto simp: disj_pathElems_trivial)\n  next\n    case (Cons_path ns n' n)\n    show ?case\n    proof (rule Cons_path.IH)\n      fix ns'\n      assume ns': \"fst n\\<comment>ns'\\<rightarrow>fst m\" \"disj_pathElems (snd n) ns' (snd m) = ns\"\n      hence[simp]: \"ns' \\<noteq> []\" by auto\n      show thesis\n      proof (cases n' rule: node'_cases)\n        case[simp]: (PhisUses n')\n        from Cons_path(2) have[simp]: \"n' = fst n\" \"snd n = Defs\"\n          by (auto simp: disj_predecessors_def split: node'_part.splits)\n        from ns' show ?thesis\n          by - (rule Cons_path.prems(1), auto dest: path2_hd simp: disj_pathElems_cons_PhisUses)\n      next\n        case[simp]: (Defs n')\n        from Cons_path(2) have \"n' \\<in> set (predecessors (fst n))\" and[simp]: \"snd n = PhisUses\"\n          by (auto simp: disj_predecessors_def split: node'_part.splits)\n        with Cons_path(3) ns' show ?thesis\n          by - (rule Cons_path.prems(1), auto simp: disj_pathElems_cons_Defs)\n      qed\n    qed\n  qed\n\n  sublocale disj: CFG disj_\\<alpha>n disj_predecessors disj_Entry disj_defs disj_uses\n  apply unfold_locales\n        apply (simp add: disj_\\<alpha>n_def disj_Entry_def)\n       apply (simp add: disj_predecessors_def disj_Entry_def)\n      apply (subst(asm) disj_\\<alpha>n_def disj_Entry_def)\n      apply (auto simp: disj_Entry_def dest!: Entry_reaches path2_to_disj_path2[where p=PhisUses])[1]\n     apply (auto simp: disj_defs_def disj_uses_def split: node'_part.splits)[1]\n    apply (auto simp: disj_defs_def split: node'_part.split intro: defs_finite)[1]\n   apply (auto simp: disj_uses_def disj_\\<alpha>n_def split: node'_part.splits intro: uses_in_\\<alpha>n)[1]\n  apply (auto simp: disj_uses_def split: node'_part.splits intro: uses_finite)\n  done\nend\n\nlocale SingleInstruction_CFG_wf = SingleInstruction_CFG \\<alpha>n predecessors Entry \"defs\" \"uses\"\nfor\n  \\<alpha>n :: \"'node::linorder list\" and\n  predecessors :: \"'node \\<Rightarrow> 'node list\" and\n  Entry :: \"'node\" and\n  \"defs\" :: \"'node \\<Rightarrow> 'var::linorder set\" and\n  \"uses\" :: \"'node \\<Rightarrow> 'var set\" +\n(* note that, in contrast to @{term defAss'}, the last node must be excluded *)\nassumes def_ass_uses: \"\\<forall>m \\<in> set \\<alpha>n. \\<forall>v \\<in> uses m. \\<forall>ns. Entry\\<comment>ns\\<rightarrow>m \\<longrightarrow> (\\<exists>n \\<in> set (butlast ns). v \\<in> defs n)\"\nbegin\n  lemma disj_defAss':\n    assumes \"m \\<in> set disj_\\<alpha>n\" \"v \\<in> disj_uses m\"\n    shows \"disj.defAss' m v\"\n  proof (rule \"disj.defAss'I\")\n    fix ns\n    assume \"disj.path2 disj_Entry ns m\"\n    then obtain ns' where ns': \"Entry\\<comment>ns'\\<rightarrow>fst m\" \"disj_pathElems PhisUses ns' (snd m) = ns\"\n      by (rule disj_path2_to_path2, simp add: disj_Entry_def)\n    with assms(2) obtain n where \"n \\<in> set (butlast ns')\" \"v \\<in> defs n\"\n      using def_ass_uses[rule_format, of \"fst m\" v ns'] by (auto simp: disj_uses_def dest!: path2_tl_in_\\<alpha>n split:node'_part.splits)\n    with ns'(2) show \"\\<exists>n\\<in>set ns. v \\<in> disj_defs n\"\n      by - (rule bexI[where x=\"(n,Defs)\"], auto simp: disj_defs_def butlast_Defs_in_disj_pathElems)\n  qed\n\n  sublocale disj: CFG_Construct_linorder disj_\\<alpha>n disj_predecessors disj_Entry disj_defs disj_uses\n    by unfold_locales (auto intro!: disj_defAss')\n\n  lift_definition disj_cfg_wf :: \"('node node', 'var) gen_cfg_wf\" is \"\\<lparr>\n      gen_\\<alpha>n = disj_\\<alpha>n,\n      gen_predecessors = disj_predecessors,\n      gen_Entry = disj_Entry,\n      gen_defs = disj_defs,\n      gen_uses = disj_uses\n    \\<rparr>\"\n    by simp unfold_locales\n\n  \n\n  (*\n  definition \"ssa_defs n = disj.defs' (n,Defs)\"\n  definition \"ssa_uses n = disj.uses' (n,PhisUses)\"\n  definition \"ssa_phis = Mapping.map (\\<lambda>(n,v). ((n,PhisUses),v)) id disj.phis'_code\"\n\n  sublocale ssa: CFG_SSA_Transformed \\<alpha>n predecessors Entry defs \"uses\" ssa_defs ssa_uses \"Mapping.lookup ssa_phis\" disj.var\n  apply unfold_locales\n  *)\n\n  definition \"disj_ssa_cfg \\<equiv> let (uses,phis) = disj.uses'_phis' in \\<lparr>\n    gen_\\<alpha>n = disj_\\<alpha>n,\n    gen_predecessors = disj_predecessors,\n    gen_Entry = disj_Entry,\n    gen_defs = disj_defs,\n    gen_uses = disj_uses,\n    gen_ssa_defs = disj.defs',\n    gen_ssa_uses = uses,\n    gen_phis = phis,\n    gen_var = gen_wf_var\n  \\<rparr>\"\nend\n\ntypedef ('node, 'var) si_cfg_wf = \"{g :: ('node::linorder, 'var::linorder) gen_cfg.\n  SingleInstruction_CFG_wf (gen_\\<alpha>n g) (gen_predecessors g) (gen_Entry g) (gen_defs g) (gen_uses g)}\"\napply (rule exI[where x=\"trivial_gen_cfg undefined\"])\napply auto\napply unfold_locales\nby (auto simp: gen_cfg.defs graph_path_base.path2_def pred_def \"graph_path_base.\\<alpha>e_def\" \"graph_path_base_base.inEdges_def\" List.maps_def intro!: graph_path_base.path.intros(1) exI)\n\n\nsetup_lifting type_definition_si_cfg_wf\n\nlift_definition si_wf_\\<alpha>n :: \"('node::linorder, 'var::linorder) si_cfg_wf \\<Rightarrow> 'node list\" is gen_\\<alpha>n .\nlift_definition si_wf_predecessors :: \"('node::linorder, 'var::linorder) si_cfg_wf \\<Rightarrow> 'node \\<Rightarrow> 'node list\" is gen_predecessors .\nlift_definition si_wf_Entry :: \"('node::linorder, 'var::linorder) si_cfg_wf \\<Rightarrow> 'node\" is gen_Entry .\nlift_definition si_wf_defs :: \"('node::linorder, 'var::linorder) si_cfg_wf \\<Rightarrow> 'node \\<Rightarrow> 'var set\" is gen_defs .\nlift_definition si_wf_uses :: \"('node::linorder, 'var::linorder) si_cfg_wf \\<Rightarrow> 'node \\<Rightarrow> 'var set\" is gen_uses .\n\nglobal_interpretation si_wf: SingleInstruction_CFG_wf \"si_wf_\\<alpha>n g\" \"si_wf_predecessors g\" \"si_wf_Entry g\" \"si_wf_defs g\" \"si_wf_uses g\"\nfor g\ndefines\n  si_wf_disj_\\<alpha>n = \"si_wf.disj_\\<alpha>n\" and\n  si_wf_disj_predecessors = \"si_wf.disj_predecessors\" and\n  si_wf_disj_Entry = \"si_wf.disj_Entry\" and\n  si_wf_disj_defs = \"si_wf.disj_defs\" and\n  si_wf_disj_uses = \"si_wf.disj_uses\" and\n  si_wf_disj_cfg_wf = \"si_wf.disj_cfg_wf\"\n  by transfer\n\nend\n", "meta": {"author": "lohner", "repo": "FormalSSA", "sha": "34253ae0ea0db6ef78b644f41ab5e9d0bde6c32e", "save_path": "github-repos/isabelle/lohner-FormalSSA", "path": "github-repos/isabelle/lohner-FormalSSA/FormalSSA-34253ae0ea0db6ef78b644f41ab5e9d0bde6c32e/SingleInstruction_CFG.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6688802603710086, "lm_q2_score": 0.41489884579676883, "lm_q1q2_score": 0.27751764800417367}}
{"text": "chapter \\<open>Forward Analysis on DBMs\\<close>\n\ntheory DBM_Operations\n  imports DBM_Basics\nbegin\n\nsection \\<open>Auxiliary\\<close>\n\nlemma gt_swap:\n  fixes a b c :: \"'t :: time\"\n  assumes \"c < a + b\"\n  shows \"c < b + a\"\nby (simp add: add.commute assms)\n\nlemma le_swap:\n  fixes a b c :: \"'t :: time\"\n  assumes \"c \\<le> a + b\"\n  shows \"c \\<le> b + a\"\nby (simp add: add.commute assms)\n\nabbreviation clock_numbering :: \"('c \\<Rightarrow> nat) \\<Rightarrow> bool\"\nwhere\n  \"clock_numbering v \\<equiv> \\<forall> c. v c > 0\"\n\nsection \\<open>Time Lapse\\<close>\n\ndefinition up :: \"('t::time) DBM \\<Rightarrow> ('t::time) DBM\"\nwhere\n  \"up M \\<equiv>\n    \\<lambda> i j. if i > 0 then if j = 0 then \\<infinity> else min (dbm_add (M i 0) (M 0 j)) (M i j) else M i j\"\n\nlemma dbm_entry_dbm_lt:\n  assumes \"dbm_entry_val u (Some c1) (Some c2) a\" \"a \\<prec> b\"\n  shows \"dbm_entry_val u (Some c1) (Some c2) b\"\nusing assms\nproof (cases, auto, goal_cases)\n  case 1 thus ?case by (cases, auto)\nnext\n  case 2 thus ?case by (cases, auto)\nqed\n\nlemma dbm_entry_dbm_min2:\n  assumes \"dbm_entry_val u None (Some c) (min a b)\"\n  shows \"dbm_entry_val u None (Some c) b\"\nusing dbm_entry_val_mono_2[folded less_eq, OF assms] by auto\n\nlemma dbm_entry_dbm_min3:\n  assumes \"dbm_entry_val u (Some c) None (min a b)\"\n  shows \"dbm_entry_val u (Some c) None b\"\nusing dbm_entry_val_mono_3[folded less_eq, OF assms] by auto\n\nlemma dbm_entry_dbm_min:\n  assumes \"dbm_entry_val u (Some c1) (Some c2) (min a b)\"\n  shows \"dbm_entry_val u (Some c1) (Some c2) b\"\nusing dbm_entry_val_mono_1[folded less_eq, OF assms] by auto\n\nlemma dbm_entry_dbm_min3':\n  assumes \"dbm_entry_val u (Some c) None (min a b)\"\n  shows \"dbm_entry_val u (Some c) None a\"\nusing dbm_entry_val_mono_3[folded less_eq, OF assms] by auto\n\nlemma dbm_entry_dbm_min2':\n  assumes \"dbm_entry_val u None (Some c) (min a b)\"\n  shows \"dbm_entry_val u None (Some c) a\"\nusing dbm_entry_val_mono_2[folded less_eq, OF assms] by auto\n\nlemma dbm_entry_dbm_min':\n  assumes \"dbm_entry_val u (Some c1) (Some c2) (min a b)\"\n  shows \"dbm_entry_val u (Some c1) (Some c2) a\"\nusing dbm_entry_val_mono_1[folded less_eq, OF assms] by auto\n\nlemma DBM_up_complete': \"clock_numbering v \\<Longrightarrow> u \\<in> ([M]\\<^bsub>v,n\\<^esub>)\\<^sup>\\<up> \\<Longrightarrow> u \\<in> [up M]\\<^bsub>v,n\\<^esub>\"\nunfolding up_def DBM_zone_repr_def DBM_val_bounded_def zone_delay_def\nproof (safe, goal_cases)\n  case prems: (2 u d c)\n  hence *: \"dbm_entry_val u None (Some c) (M 0 (v c))\" by auto\n  thus ?case\n  proof (cases, goal_cases)\n    case (1 d')\n    have \"- (u c + d) \\<le> - u c\" using \\<open>d \\<ge> 0\\<close> by simp\n    with 1(2) have \"- (u c + d)\\<le> d'\" by (blast intro: order.trans)\n    thus ?case unfolding cval_add_def using 1 by fastforce\n  next\n    case (2 d')\n    have \"- (u c + d) \\<le> - u c\" using \\<open>d \\<ge> 0\\<close> by simp\n    with 2(2) have \"- (u c + d) < d'\" by (blast intro: order_le_less_trans)\n    thus ?case unfolding cval_add_def using 2 by fastforce\n  qed auto\nnext\n  case prems: (4 u d c1 c2)\n  then have\n    \"dbm_entry_val u (Some c1) None (M (v c1) 0)\" \"dbm_entry_val u None (Some c2) (M 0 (v c2))\"\n  by auto\n  from dbm_entry_val_add_4[OF this] prems have\n    \"dbm_entry_val u (Some c1) (Some c2) (min (dbm_add (M (v c1) 0) (M 0 (v c2))) (M (v c1) (v c2)))\"\n  by (auto split: split_min)\n  with prems(1) show ?case\n  by (cases \"min (dbm_add (M (v c1) 0) (M 0 (v c2))) (M (v c1) (v c2))\", auto simp: cval_add_def)\nqed auto\n\nfun theLe :: \"('t::time) DBMEntry \\<Rightarrow> 't\" where\n  \"theLe (Le d) = d\" |\n  \"theLe (Lt d) = d\" |\n  \"theLe \\<infinity> = 0\"\n\nlemma DBM_up_sound':\n  assumes \"clock_numbering' v n\" \"u \\<in> [up M]\\<^bsub>v,n\\<^esub>\"\n  shows \"u \\<in> ([M]\\<^bsub>v,n\\<^esub>)\\<^sup>\\<up>\"\nunfolding DBM_zone_repr_def zone_delay_def using assms\nproof (clarsimp, goal_cases)\n  case A: 1\n  obtain S_Max_Le where S_Max_Le:\n    \"S_Max_Le = {d - u c | c d. 0 < v c \\<and> v c \\<le> n \\<and> M (v c) 0 = Le d}\"\n  by auto\n  obtain S_Max_Lt where S_Max_Lt:\n    \"S_Max_Lt = {d - u c | c d. 0 < v c \\<and> v c \\<le> n \\<and> M (v c) 0 = Lt d}\"\n  by auto\n  obtain S_Min_Le where S_Min_Le:\n    \"S_Min_Le = {- d - u c| c d. 0 < v c \\<and> v c \\<le> n \\<and> M 0 (v c) = Le d}\"\n  by auto\n  obtain S_Min_Lt where S_Min_Lt:\n    \"S_Min_Lt = {- d - u c | c d. 0 < v c \\<and> v c \\<le> n \\<and> M 0 (v c) = Lt d}\"\n  by auto\n  have \"finite {c. 0 < v c \\<and> v c \\<le> n}\"\n  using A(2,3)\n  proof (induction n)\n    case 0\n    then have \"{c. 0 < v c \\<and> v c \\<le> 0} = {}\" by auto\n    then show ?case by (metis finite.emptyI) \n  next\n    case (Suc n)\n    then have \"finite {c. 0 < v c \\<and> v c \\<le> n}\" by auto\n    moreover have \"{c. 0 < v c \\<and> v c \\<le> Suc n} = {c. 0 < v c \\<and> v c \\<le> n} \\<union> {c. v c = Suc n}\" by auto\n    moreover have \"finite {c. v c = Suc n}\"\n    proof (cases \"{c. v c = Suc n} = {}\", auto)\n      fix c assume \"v c = Suc n\"\n      then have \"{c. v c = Suc n} = {c}\" using Suc.prems(2) by auto\n      then show ?thesis by auto\n    qed\n    ultimately show ?case by auto\n  qed\n  then have \"\\<forall> f. finite {(c,b) | c b. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = b}\" by auto\n  moreover have\n    \"\\<forall> f K. {(c,K d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\n    \\<subseteq> {(c,b) | c b. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = b}\"\n  by auto\n  ultimately have 1:\n    \"\\<forall> f K. finite {(c,K d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\" using finite_subset\n  by fast\n  have \"\\<forall> f K. theLe o K = id \\<longrightarrow> finite {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\"\n  proof (safe, goal_cases)\n    case prems: (1 f K)\n    then have\n      \"{(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\n      = (\\<lambda> (c,b). (c, theLe b)) ` {(c,K d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\"\n    proof (auto simp add: pointfree_idE, goal_cases)\n      case (1 a b)\n      then have \"(a, K b) \\<in> {(c, K d) |c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\" by auto\n      moreover from 1(1) have \"theLe (K b) = b\" by (simp add: pointfree_idE)\n      ultimately show ?case by force\n    qed\n    moreover from 1 have\n      \"finite ((\\<lambda> (c,b). (c, theLe b)) ` {(c,K d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d})\"\n    by auto\n    ultimately show ?case by auto\n  qed\n  then have finI:\n    \"\\<And> f g K. theLe o K = id \\<Longrightarrow> finite (g ` {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d})\"\n  by auto\n  \n  have\n    \"finite ((\\<lambda>(c,d). - d - u c) ` {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> M 0 (v c) = Le d})\"\n  by (rule finI, auto)\n  moreover have\n    \"S_Min_Le = ((\\<lambda>(c,d). - d - u c) ` {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> M 0 (v c) = Le d})\"\n  using S_Min_Le by auto\n  ultimately have fin_min_le: \"finite S_Min_Le\" by auto\n  \n  have\n    \"finite ((\\<lambda>(c,d). - d - u c) ` {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> M 0 (v c) = Lt d})\"\n  by (rule finI, auto)\n  moreover have\n    \"S_Min_Lt = ((\\<lambda>(c,d). - d - u c) ` {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> M 0 (v c) = Lt d})\"\n  using S_Min_Lt by auto\n  ultimately have fin_min_lt: \"finite S_Min_Lt\" by auto\n\n  have \"finite ((\\<lambda>(c,d). d - u c) ` {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> M (v c) 0 = Le d})\"\n  by (rule finI, auto)\n  moreover have\n    \"S_Max_Le = ((\\<lambda>(c,d). d - u c) ` {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> M (v c) 0 = Le d})\"\n  using S_Max_Le by auto\n  ultimately have fin_max_le: \"finite S_Max_Le\" by auto\n\n  have\n    \"finite ((\\<lambda>(c,d). d - u c) ` {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> M (v c) 0 = Lt d})\"\n  by (rule finI, auto)\n  moreover have\n    \"S_Max_Lt = ((\\<lambda>(c,d). d - u c) ` {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> M (v c) 0 = Lt d})\"\n  using S_Max_Lt by auto\n  ultimately have fin_max_lt: \"finite S_Max_Lt\" by auto\n\n  { fix x assume \"x \\<in> S_Min_Le\"\n    hence \"x \\<le> 0\" unfolding S_Min_Le\n    proof (safe, goal_cases)\n      case (1 c d)\n      with A(1) have \"- u c \\<le> d\" unfolding DBM_zone_repr_def DBM_val_bounded_def up_def by auto\n      thus ?case by (simp add: minus_le_iff)\n    qed\n  } note Min_Le_le_0 = this\n  have Min_Lt_le_0: \"x < 0\" if \"x \\<in> S_Min_Lt\" for x using that unfolding S_Min_Lt\n  proof (safe, goal_cases)\n    case (1 c d)\n    with A(1) have \"- u c < d\" unfolding DBM_zone_repr_def DBM_val_bounded_def up_def by auto\n    thus ?case by (simp add: minus_less_iff)\n  qed\n  text \\<open>\n    The following basically all use the same proof.\n    Only the first is not completely identical but nearly identical.\n\\<close>\n  { fix l r assume \"l \\<in> S_Min_Le\" \"r \\<in> S_Max_Le\"\n    with S_Min_Le S_Max_Le have \"l \\<le> r\"\n    proof (safe, goal_cases)\n    case (1 c c' d d')\n      note G1 = this\n      hence *:\"(up M) (v c') (v c) = min (dbm_add (M (v c') 0) (M 0 (v c))) (M (v c') (v c))\"\n      using A unfolding up_def by (auto split: split_min)\n      have \"dbm_entry_val u (Some c') (Some c) ((up M) (v c') (v c))\"\n      using A G1 unfolding DBM_zone_repr_def DBM_val_bounded_def by fastforce\n      hence \"dbm_entry_val u (Some c') (Some c) (dbm_add (M (v c') 0) (M 0 (v c)))\"\n      using dbm_entry_dbm_min' * by auto\n      hence \"u c' - u c \\<le> d' + d\" using G1 by auto\n      hence \"u c' + (- u c - d) \\<le> d'\" by (simp add: add_diff_eq diff_le_eq)\n      hence \"- u c - d \\<le> d' - u c'\" by (simp add: add.commute le_diff_eq) \n      thus ?case by (metis add_uminus_conv_diff uminus_add_conv_diff)\n    qed\n  } note EE = this\n  { fix l r assume \"l \\<in> S_Min_Le\" \"r \\<in> S_Max_Le\"\n    with S_Min_Le S_Max_Le have \"l \\<le> r\"\n    proof (auto, goal_cases)\n    case (1 c c' d d')\n      note G1 = this\n      hence *:\"(up M) (v c') (v c) = min (dbm_add (M (v c') 0) (M 0 (v c))) (M (v c') (v c))\"\n      using A unfolding up_def by (auto split: split_min)\n      have \"dbm_entry_val u (Some c') (Some c) ((up M) (v c') (v c))\"\n      using A G1 unfolding DBM_zone_repr_def DBM_val_bounded_def by fastforce\n      hence \"dbm_entry_val u (Some c') (Some c) (dbm_add (M (v c') 0) (M 0 (v c)))\"\n      using dbm_entry_dbm_min' * by auto\n      hence \"u c' - u c \\<le> d' + d\" using G1 by auto\n      hence \"u c' + (- u c - d) \\<le> d'\" by (simp add: add_diff_eq diff_le_eq)\n      hence \"- u c - d \\<le> d' - u c'\" by (simp add: add.commute le_diff_eq) \n      thus ?case by (metis add_uminus_conv_diff uminus_add_conv_diff)\n    qed\n  } note EE = this\n  { fix l r assume \"l \\<in> S_Min_Lt\" \"r \\<in> S_Max_Le\"\n    with S_Min_Lt S_Max_Le have \"l < r\"\n    proof (auto, goal_cases)\n    case (1 c c' d d')\n      note G1 = this\n      hence *:\"(up M) (v c') (v c) = min (dbm_add (M (v c') 0) (M 0 (v c))) (M (v c') (v c))\"\n      using A unfolding up_def by (auto split: split_min)\n      have \"dbm_entry_val u (Some c') (Some c) ((up M) (v c') (v c))\"\n      using A G1 unfolding DBM_zone_repr_def DBM_val_bounded_def by fastforce\n      hence \"dbm_entry_val u (Some c') (Some c) (dbm_add (M (v c') 0) (M 0 (v c)))\"\n      using dbm_entry_dbm_min' * by auto\n      hence \"u c' - u c < d' + d\" using G1 by auto\n      hence \"u c' + (- u c - d) < d'\" by (simp add: add_diff_eq diff_less_eq)\n      hence \"- u c - d < d' - u c'\" by (simp add: add.commute less_diff_eq) \n      thus ?case by (metis add_uminus_conv_diff uminus_add_conv_diff)\n    qed\n  } note LE = this\n  { fix l r assume \"l \\<in> S_Min_Le\" \"r \\<in> S_Max_Lt\"\n    with S_Min_Le S_Max_Lt have \"l < r\"\n    proof (auto, goal_cases)\n    case (1 c c' d d')\n      note G1 = this\n      hence *:\"(up M) (v c') (v c) = min (dbm_add (M (v c') 0) (M 0 (v c))) (M (v c') (v c))\"\n      using A unfolding up_def by (auto split: split_min)\n      have \"dbm_entry_val u (Some c') (Some c) ((up M) (v c') (v c))\"\n      using A G1 unfolding DBM_zone_repr_def DBM_val_bounded_def by fastforce\n      hence \"dbm_entry_val u (Some c') (Some c) (dbm_add (M (v c') 0) (M 0 (v c)))\"\n      using dbm_entry_dbm_min' * by auto\n      hence \"u c' - u c < d' + d\" using G1 by auto\n      hence \"u c' + (- u c - d) < d'\" by (simp add: add_diff_eq diff_less_eq)\n      hence \"- u c - d < d' - u c'\" by (simp add: add.commute less_diff_eq) \n      thus ?case by (metis add_uminus_conv_diff uminus_add_conv_diff)\n    qed\n  } note EL = this\n  { fix l r assume \"l \\<in> S_Min_Lt\" \"r \\<in> S_Max_Lt\"\n    with S_Min_Lt S_Max_Lt have \"l < r\"\n    proof (auto, goal_cases)\n    case (1 c c' d d')\n      note G1 = this\n      hence *:\"(up M) (v c') (v c) = min (dbm_add (M (v c') 0) (M 0 (v c))) (M (v c') (v c))\"\n      using A unfolding up_def by (auto split: split_min)\n      have \"dbm_entry_val u (Some c') (Some c) ((up M) (v c') (v c))\"\n      using A G1 unfolding DBM_zone_repr_def DBM_val_bounded_def by fastforce\n      hence \"dbm_entry_val u (Some c') (Some c) (dbm_add (M (v c') 0) (M 0 (v c)))\"\n      using dbm_entry_dbm_min' * by auto\n      hence \"u c' - u c < d' + d\" using G1 by auto\n      hence \"u c' + (- u c - d) < d'\" by (simp add: add_diff_eq diff_less_eq)\n      hence \"- u c - d < d' - u c'\" by (simp add: add.commute less_diff_eq) \n      thus ?case by (metis add_uminus_conv_diff uminus_add_conv_diff)\n    qed\n  } note LL = this\n  obtain m where m: \"\\<forall> t \\<in> S_Min_Le. m \\<ge> t\" \"\\<forall> t \\<in> S_Min_Lt. m > t\"\n                    \"\\<forall> t \\<in> S_Max_Le. m \\<le> t\" \"\\<forall> t \\<in> S_Max_Lt. m < t\" \"m \\<le> 0\"\n  proof -\n    assume m:\"(\\<And>m. \\<forall>t\\<in>S_Min_Le. t \\<le> m \\<Longrightarrow>\n          \\<forall>t\\<in>S_Min_Lt. t < m \\<Longrightarrow> \\<forall>t\\<in>S_Max_Le. m \\<le> t \\<Longrightarrow> \\<forall>t\\<in>S_Max_Lt. m < t \\<Longrightarrow> m \\<le> 0 \\<Longrightarrow> thesis)\"\n    let ?min_le = \"Max S_Min_Le\"\n    let ?min_lt = \"Max S_Min_Lt\" \n    let ?max_le = \"Min S_Max_Le\"\n    let ?max_lt = \"Min S_Max_Lt\"\n    show thesis\n    proof (cases \"S_Min_Le = {} \\<and> S_Min_Lt = {}\")\n      case True\n      note T = this\n      show thesis\n      proof (cases \"S_Max_Le = {} \\<and> S_Max_Lt = {}\")\n        case True\n        let ?d' = \"0 :: 't :: time\"\n        show thesis using True T by (intro m[of ?d']) auto\n      next\n        case False\n        let ?d =\n          \"if S_Max_Le \\<noteq> {}\n           then if S_Max_Lt \\<noteq> {} then min ?max_lt ?max_le else ?max_le\n           else ?max_lt\"\n        obtain a :: \"'b\" where a: \"a < 0\" using non_trivial_neg by auto\n        let ?d' = \"min 0 (?d + a)\"\n        { fix x assume \"x \\<in> S_Max_Le\"\n          with fin_max_le a have \"min 0 (Min S_Max_Le + a) \\<le> x\"\n          by (metis Min_le add_le_same_cancel1 le_less_trans less_imp_le min.cobounded2 not_less)\n          then have \"min 0 (Min S_Max_Le + a) \\<le> x\" by auto\n        } note 1 = this\n        { fix x assume x: \"x \\<in> S_Max_Lt\"\n          have \"min 0 (min (Min S_Max_Lt) (Min S_Max_Le) + a) < ?max_lt\"\n          by (meson a add_less_same_cancel1 min.cobounded1 min.strict_coboundedI2 order.strict_trans2) \n          also from fin_max_lt x have \"\\<dots> \\<le> x\" by auto\n          finally have \"min 0 (min (Min S_Max_Lt) (Min S_Max_Le) + a) < x\" .\n        } note 2 = this\n        { fix x assume x: \"x \\<in> S_Max_Le\"\n          have \"min 0 (min (Min S_Max_Lt) (Min S_Max_Le) + a) \\<le> ?max_le\"\n          by (metis le_add_same_cancel1 linear not_le a min_le_iff_disj)\n          also from fin_max_le x have \"\\<dots> \\<le> x\" by auto\n          finally have \"min 0 (min (Min S_Max_Lt) (Min S_Max_Le) + a) \\<le> x\" .\n        } note 3 = this\n        show thesis using False T a 1 2 3\n        proof ((intro m[of ?d']), auto, goal_cases)\n          case 1 then show ?case\n          by (metis Min.coboundedI add_less_same_cancel1 dual_order.strict_trans2 fin_max_lt\n                    min.boundedE not_le)\n        qed\n      qed\n    next\n      case False\n      note F = this\n      show thesis\n      proof (cases \"S_Max_Le = {} \\<and> S_Max_Lt = {}\")\n        case True\n        let ?d' = \"0 :: 't :: time\"\n        show thesis using True Min_Le_le_0 Min_Lt_le_0 by (intro m[of ?d']) auto\n      next\n        case False\n        let ?r =\n          \"if S_Max_Le \\<noteq> {}\n           then if S_Max_Lt \\<noteq> {} then min ?max_lt ?max_le else ?max_le\n           else ?max_lt\"\n        let ?l =\n          \"if S_Min_Le \\<noteq> {}\n           then if S_Min_Lt \\<noteq> {} then max ?min_lt ?min_le else ?min_le\n           else ?min_lt\"\n\n        have 1: \"x \\<le> max ?min_lt ?min_le\" \"x \\<le> ?min_le\" if \"x \\<in> S_Min_Le\" for x\n        using that fin_min_le by (simp add: max.coboundedI2)+\n        \n        {\n          fix x y assume x: \"x \\<in> S_Max_Le\" \"y \\<in> S_Min_Lt\"\n          then have \"S_Min_Lt \\<noteq> {}\" by auto\n          from LE[OF Max_in[OF fin_min_lt], OF this, OF x(1)] have \"?min_lt \\<le> x\" by auto\n        } note 3 = this\n        \n        have 4: \"?min_le \\<le> x\" if \"x \\<in> S_Max_Le\" \"y \\<in> S_Min_Le\" for x y\n        using EE[OF Max_in[OF fin_min_le], OF _ that(1)] that by auto\n        \n        {\n          fix x y assume x: \"x \\<in> S_Max_Lt\" \"y \\<in> S_Min_Lt\"\n          then have \"S_Min_Lt \\<noteq> {}\" by auto\n          from LL[OF Max_in[OF fin_min_lt], OF this, OF x(1)] have \"?min_lt < x\" by auto\n        } note 5 = this\n        {\n          fix x y assume x: \"x \\<in> S_Max_Lt\" \"y \\<in> S_Min_Le\"\n          then have \"S_Min_Le \\<noteq> {}\" by auto\n          from EL[OF Max_in[OF fin_min_le], OF this, OF x(1)] have \"?min_le < x\" by auto\n        } note 6 = this\n        {\n          fix x y assume x: \"y \\<in> S_Min_Le\"\n          then have \"S_Min_Le \\<noteq> {}\" by auto\n          from Min_Le_le_0[OF Max_in[OF fin_min_le], OF this] have \"?min_le \\<le> 0\" by auto\n        } note 7 = this\n        {\n          fix x y assume x: \"y \\<in> S_Min_Lt\"\n          then have \"S_Min_Lt \\<noteq> {}\" by auto\n          from Min_Lt_le_0[OF Max_in[OF fin_min_lt], OF this] have \"?min_lt < 0\" \"?min_lt \\<le> 0\" by auto\n        } note 8 = this\n        show thesis\n        proof (cases \"?l < ?r\")\n          case False\n          then have *: \"S_Max_Le \\<noteq> {}\"\n          proof (auto, goal_cases)\n            case 1\n            with \\<open>\\<not> (S_Max_Le = {} \\<and> S_Max_Lt = {})\\<close> obtain y where y:\"y \\<in> S_Max_Lt\" by auto\n            note 1 = 1 this\n            { fix x y assume A: \"x \\<in> S_Min_Le\" \"y \\<in> S_Max_Lt\"\n                  with EL[OF Max_in[OF fin_min_le] Min_in[OF fin_max_lt]]\n                  have \"Max S_Min_Le < Min S_Max_Lt\" by auto\n            } note ** = this\n            { fix x y assume A: \"x \\<in> S_Min_Lt\" \"y \\<in> S_Max_Lt\"\n                with LL[OF Max_in[OF fin_min_lt] Min_in[OF fin_max_lt]]\n                have \"Max S_Min_Lt < Min S_Max_Lt\" by auto\n            } note *** = this\n            show ?case\n            proof (cases \"S_Min_Le \\<noteq> {}\")\n              case True\n              note T = this\n              show ?thesis\n              proof (cases \"S_Min_Lt \\<noteq> {}\")\n                case True\n                then show False using 1 T True ** *** by auto\n              next\n                case False with 1 T ** show False by auto\n              qed\n            next\n              case False\n              with 1 False *** \\<open>\\<not> (S_Min_Le = {} \\<and> S_Min_Lt = {})\\<close> show ?thesis by auto\n            qed\n          qed\n          { fix x y assume A: \"x \\<in> S_Min_Lt\" \"y \\<in> S_Max_Lt\"\n                with LL[OF Max_in[OF fin_min_lt] Min_in[OF fin_max_lt]]\n                have \"Max S_Min_Lt < Min S_Max_Lt\" by auto\n            } note *** = this\n          { fix x y assume A: \"x \\<in> S_Min_Lt\" \"y \\<in> S_Max_Le\"\n                  with LE[OF Max_in[OF fin_min_lt] Min_in[OF fin_max_le]]\n                  have \"Max S_Min_Lt < Min S_Max_Le\" by auto\n          } note **** = this\n          from F False have **: \"S_Min_Le \\<noteq> {}\"\n          proof (auto, goal_cases)\n            case 1\n            show ?case\n            proof (cases \"S_Max_Le \\<noteq> {}\")\n              case True\n              note T = this\n              show ?thesis\n              proof (cases \"S_Max_Lt \\<noteq> {}\")\n                case True\n                then show False using 1 T True **** *** by auto\n              next\n                case False with 1 T **** show False by auto\n              qed\n            next\n              case False\n              with 1 False *** \\<open>\\<not> (S_Max_Le = {} \\<and> S_Max_Lt = {})\\<close> show ?thesis by auto\n            qed\n          qed\n          {\n            fix x assume x: \"x \\<in> S_Min_Lt\"\n            then have \"x \\<le> ?min_lt\" using fin_min_lt by (simp add: max.coboundedI2)\n            also have \"?min_lt < ?min_le\"\n            proof (rule ccontr, goal_cases)\n              case 1\n              with x ** have 1: \"?l = ?min_lt\" by (auto simp: max.absorb1)\n              have 2: \"?min_lt < ?max_le\" using * ****[OF x] by auto\n              show False\n              proof (cases \"S_Max_Lt = {}\")\n                case False\n                then have \"?min_lt < ?max_lt\" using * ***[OF x] by auto\n                with 1 2 have \"?l < ?r\" by auto\n                with \\<open>\\<not> ?l < ?r\\<close> show False by auto\n              next\n                case True\n                with 1 2 have \"?l < ?r\" by auto\n                with \\<open>\\<not> ?l < ?r\\<close> show False by auto\n              qed\n            qed\n            finally have \"x < max ?min_lt ?min_le\" by (simp add: max.strict_coboundedI2) \n          } note 2 = this\n          show thesis using F False 1 2 3 4 5 6 7 8 * ** by ((intro m[of ?l]), auto)\n        next\n          case True\n          then obtain d where d: \"?l < d\" \"d < ?r\" using dense by auto\n          let ?d' = \"min 0 d\"\n          {\n            fix t assume \"t \\<in> S_Min_Le\"\n            then have \"t \\<le> ?l\" using 1 by auto\n            with d have \"t \\<le> d\" by auto\n          }\n          moreover {\n            fix t assume t: \"t \\<in> S_Min_Lt\"\n            then have \"t \\<le> max ?min_lt ?min_le\" using fin_min_lt by (simp add: max.coboundedI1)\n            with t Min_Lt_le_0 have \"t \\<le> ?l\" using fin_min_lt by auto\n            with d have \"t < d\" by auto\n          }\n          moreover {\n            fix t assume t: \"t \\<in> S_Max_Le\"\n            then have \"min ?max_lt ?max_le \\<le> t\" using fin_max_le by (simp add: min.coboundedI2)\n            then have \"?r \\<le> t\" using fin_max_le t by auto\n            with d have \"d \\<le> t\" by auto\n            then have \"min 0 d \\<le> t\" by (simp add: min.coboundedI2)\n          }\n          moreover {\n            fix t assume t: \"t \\<in> S_Max_Lt\"\n            then have \"min ?max_lt ?max_le \\<le> t\" using fin_max_lt by (simp add: min.coboundedI1)\n            then have \"?r \\<le> t\" using fin_max_lt t by auto\n            with d have \"d < t\" by auto\n            then have \"min 0 d < t\" by (simp add: min.strict_coboundedI2)\n          }\n          ultimately show thesis using Min_Le_le_0 Min_Lt_le_0 by ((intro m[of ?d']), auto)\n        qed\n      qed\n    qed\n  qed\n  obtain u' where \"u' = (u \\<oplus> m)\" by blast\n  hence u': \"u = (u' \\<oplus> (-m))\" unfolding cval_add_def by force\n  have \"DBM_val_bounded v u' M n\" unfolding DBM_val_bounded_def\n  proof (auto, goal_cases)\n    case 1 with A(1,2) show ?case unfolding DBM_zone_repr_def DBM_val_bounded_def up_def by auto\n  next\n    case (3 c)\n    thus ?case\n    proof (cases \"M (v c) 0\", goal_cases)\n      case (1 x1)\n      hence \"m \\<le> x1 - u c\" using m(3) S_Max_Le A(2) by blast\n      hence \"u c + m \\<le> x1\" by (simp add: add.commute le_diff_eq)\n      thus ?case using u' 1(2) unfolding cval_add_def by auto\n    next\n      case (2 x2)\n      hence \"m < x2 - u c\" using m(4) S_Max_Lt A(2) by blast\n      hence \"u c + m < x2\" by (metis add_less_cancel_left diff_add_cancel gt_swap)\n      thus ?case using u' 2(2) unfolding cval_add_def by auto\n    next\n      case 3 thus ?case by auto\n    qed\n  next\n    case (2 c) thus ?case\n    proof (cases \"M 0 (v c)\", goal_cases)\n      case (1 x1)\n      hence \"- x1 - u c \\<le> m\" using m(1) S_Min_Le A(2) by blast\n      hence \"- u c - m \\<le> x1\" using diff_le_eq neg_le_iff_le by fastforce\n      thus ?case using u' 1(2) unfolding cval_add_def by auto\n    next\n      case (2 x2)\n      hence \"- x2  - u c < m\" using m(2) S_Min_Lt A(2) by blast\n      hence \"- u c - m < x2\" using diff_less_eq neg_less_iff_less by fastforce \n      thus ?case using u' 2(2) unfolding cval_add_def by auto\n    next\n      case 3 thus ?case by auto\n    qed\n  next\n    case (4 c1 c2)\n    from A(2) have \"v c1 > 0\" \"v c2 \\<noteq> 0\" by auto\n    then have B: \"(up M) (v c1) (v c2) = min (dbm_add (M (v c1) 0) (M 0 (v c2))) (M (v c1) (v c2))\"\n    unfolding up_def by simp\n    \n    show ?case\n    proof (cases \"(dbm_add (M (v c1) 0) (M 0 (v c2))) < (M (v c1) (v c2))\")\n      case False\n      with B have \"(up M) (v c1) (v c2) = M (v c1) (v c2)\" by (auto split: split_min)\n      with A(1) 4 have\n        \"dbm_entry_val u (Some c1) (Some c2) (M (v c1) (v c2))\"\n      unfolding DBM_zone_repr_def unfolding DBM_val_bounded_def by fastforce\n      thus ?thesis using u' by cases (auto simp add: cval_add_def)\n    next\n      case True\n      with B have \"(up M) (v c1) (v c2) = dbm_add (M (v c1) 0) (M 0 (v c2))\" by (auto split: split_min)\n      with A(1) 4 have\n        \"dbm_entry_val u (Some c1) (Some c2) (dbm_add (M (v c1) 0) (M 0 (v c2)))\"\n      unfolding DBM_zone_repr_def unfolding DBM_val_bounded_def by fastforce\n      with True dbm_entry_dbm_lt have\n        \"dbm_entry_val u (Some c1) (Some c2) (M (v c1) (v c2))\"\n      unfolding less by fast\n      thus ?thesis using u' by cases (auto simp add: cval_add_def)\n    qed\n  qed\n  with m(5) u' show ?case by fastforce\nqed\n\nsection \\<open>From Clock Constraints to DBMs\\<close>\n\nfun And :: \"('t :: time) DBM \\<Rightarrow> 't DBM \\<Rightarrow> 't DBM\" where\n  \"And M1 M2 = (\\<lambda> i j. min (M1 i j) (M2 i j))\"\n\nfun abstr :: \"('c, 't::time) cconstraint \\<Rightarrow> 't DBM \\<Rightarrow> ('c \\<Rightarrow> nat) \\<Rightarrow> 't DBM\"\nwhere\n  \"abstr (AND cc1 cc2) M v = And (abstr cc1 M v) (abstr cc2 M v)\" |\n  \"abstr (EQ c d) M v =\n    (\\<lambda> i j . if i = 0 \\<and> j = v c then Le (-d) else if i = v c \\<and> j = 0 then Le d else M i j)\" |\n  \"abstr (LT c d) M v =\n    (\\<lambda> i j . if i = 0 \\<and> j = v c then \\<infinity> else if i = v c \\<and> j = 0 then Lt d else M i j)\" |\n  \"abstr (LE c d) M v =\n    (\\<lambda> i j . if i = 0 \\<and> j = v c then \\<infinity> else if i = v c \\<and> j = 0 then Le d else M i j)\" |\n  \"abstr (GT c d) M v =\n    (\\<lambda> i j. if i = 0 \\<and> j = v c then Lt (- d) else if i = v c \\<and> j = 0 then \\<infinity> else M i j)\" |\n  \"abstr (GE c d) M v =\n    (\\<lambda> i j. if i = 0 \\<and> j = v c then Le (- d) else if i = v c \\<and> j = 0 then \\<infinity> else M i j)\"\n\nlemma abstr_id1:\n  \"c \\<notin> collect_clks cc \\<Longrightarrow> clock_numbering' v n \\<Longrightarrow> \\<forall> c \\<in> collect_clks cc. v c \\<le> n\n    \\<Longrightarrow> abstr cc M v 0 (v c) = M 0 (v c)\"\nby (induction cc) auto\n\nlemma abstr_id2:\n  \"c \\<notin> collect_clks cc \\<Longrightarrow> clock_numbering' v n \\<Longrightarrow> \\<forall> c \\<in> collect_clks cc. v c \\<le> n\n    \\<Longrightarrow> abstr cc M v (v c) 0 = M (v c) 0\"\nby (induction cc) auto\n\ntext \\<open>\n  This lemma is trivial because we constrained our theory to difference constraints.\n\\<close>\n\nlemma abstr_id3:\n  \"clock_numbering v \\<Longrightarrow> abstr cc M v (v c1) (v c2) = M (v c1) (v c2)\"\nproof goal_cases\n  case 1\n  have \"\\<And>c. v c = 0 \\<Longrightarrow> False\"\n  proof -\n    fix c assume \"v c = 0\"\n    moreover from 1 have \"v c > 0\" by auto\n    ultimately show False by linarith\n  qed\n  then show ?case by ((induction cc), auto, fastforce)\nqed\n\nlemma dbm_abstr_soundness :\n  \"\\<lbrakk>u \\<turnstile> cc; clock_numbering' v n; \\<forall> c \\<in> collect_clks cc. v c \\<le> n\\<rbrakk>\n    \\<Longrightarrow> DBM_val_bounded v u (abstr cc (\\<lambda> i j. \\<infinity>) v) n\"\nproof (unfold DBM_val_bounded_def, auto, goal_cases)\n  case 1\n  from this(3) have \"abstr cc (\\<lambda>i j. \\<infinity>) v 0 0 = \\<infinity>\" by (induction cc) auto\n  then show ?case unfolding dbm_le_def by auto\nnext\n  case (2 c)\n  then have \"clock_numbering' v n\" by auto\n  note A = 2(1) this 2(5,2)\n  show ?case\n  proof (cases \"c \\<in> collect_clks cc\")\n    case True\n    then show ?thesis using A(1,4)\n    proof (induction rule: collect_clks.induct)\n      case (1 cc1 cc2)\n      { assume cc: \"c \\<in> collect_clks cc1\" \"c \\<in> collect_clks cc2\"\n        with 1 have ?case by auto linarith\n      } note both = this\n      show ?case\n      proof (cases \"c \\<in> collect_clks cc1\")\n        case True\n        note cc1 = this\n        with 1 have *: \"dbm_entry_val u None (Some c) (abstr cc1 (\\<lambda>i j. \\<infinity>) v 0 (v c))\" by auto\n        show ?thesis\n        proof (cases \"c \\<in> collect_clks cc2\")\n          case True with cc1 both show ?thesis by auto\n        next\n          case False\n          from abstr_id1[OF False A(2)] 1(5)\n          have\n            \"min (abstr cc1 (\\<lambda>i j. \\<infinity>) v 0 (v c)) (abstr cc2 (\\<lambda>i j. \\<infinity>) v 0 (v c))\n            = abstr cc1 (\\<lambda>i j. \\<infinity>) v 0 (v c)\"\n          by (simp add: any_le_inf min.absorb1)\n          with * show ?thesis by auto\n        qed\n      next\n        case False\n        note cc1 = this\n        show ?thesis\n        proof (cases \"c \\<in> collect_clks cc2\")\n          case True\n          with 1 have *: \"dbm_entry_val u None (Some c) (abstr cc2 (\\<lambda>i j. \\<infinity>) v 0 (v c))\" by auto\n          from abstr_id1[OF cc1 A(2)] 1(5)\n          have\n            \"min (abstr cc1 (\\<lambda>i j. \\<infinity>) v 0 (v c)) (abstr cc2 (\\<lambda>i j. \\<infinity>) v 0 (v c))\n            = abstr cc2 (\\<lambda>i j. \\<infinity>) v 0 (v c)\"\n          by (simp add: any_le_inf min.absorb2)\n          with * show ?thesis by auto\n        next\n          case False\n          with 1 cc1 show ?thesis by auto\n        qed\n      qed\n    qed auto\n  next\n    case False\n    from abstr_id1[OF this A(2,4)] show ?thesis by auto\n  qed\nnext\n  case (3 c)\n  then have \"clock_numbering' v n\" by auto\n  note A = 3(1) this 3(5,2)\n  from A(2) have gt0: \"v c > 0\" by auto\n  show ?case\n  proof (cases \"c \\<in> collect_clks cc\")\n    case True\n    then show ?thesis using A(1,4)\n    proof (induction rule: collect_clks.induct)\n      case (1 cc1 cc2)\n      { assume cc: \"c \\<in> collect_clks cc1\" \"c \\<in> collect_clks cc2\"\n        with 1 have ?case by auto linarith\n      } note both = this\n      show ?case\n      proof (cases \"c \\<in> collect_clks cc1\")\n        case True\n        note cc1 = this\n        with 1 have *: \"dbm_entry_val u (Some c) None (abstr cc1 (\\<lambda>i j. \\<infinity>) v (v c) 0)\" by auto\n        show ?thesis\n        proof (cases \"c \\<in> collect_clks cc2\")\n          case True with cc1 both show ?thesis by auto\n        next\n          case False\n          from abstr_id2[OF False A(2)] 1(5)\n          have\n            \"min (abstr cc1 (\\<lambda>i j. \\<infinity>) v (v c) 0) (abstr cc2 (\\<lambda>i j. \\<infinity>) v (v c) 0)\n            = abstr cc1 (\\<lambda>i j. \\<infinity>) v (v c) 0\"\n          by (simp add: any_le_inf min.absorb1)\n          with * show ?thesis by auto\n        qed\n      next\n        case False\n        note cc1 = this\n        show ?thesis\n        proof (cases \"c \\<in> collect_clks cc2\")\n          case True\n          with 1 have *: \"dbm_entry_val u (Some c) None (abstr cc2 (\\<lambda>i j. \\<infinity>) v (v c) 0)\"\n          by auto\n          from abstr_id2[OF cc1 A(2)] 1(5)\n          have\n            \"min (abstr cc1 (\\<lambda>i j. \\<infinity>) v (v c) 0) (abstr cc2 (\\<lambda>i j. \\<infinity>) v (v c) 0)\n            = abstr cc2 (\\<lambda>i j. \\<infinity>) v (v c) 0\"\n          by (simp add: any_le_inf min.absorb2)\n          with * show ?thesis by auto\n        next\n          case False\n          with 1 cc1 show ?thesis by auto\n        qed\n      qed\n    qed (insert gt0, auto)\n  next\n    case False\n    from abstr_id2[OF this A(2,4)] show ?thesis by auto\n  qed\nnext\n  text \\<open>Trivial because of missing difference constraints\\<close>\n  case (4 c1 c2)\n  from abstr_id3[OF this(3)] have \"abstr cc (\\<lambda>i j. \\<infinity>) v (v c1) (v c2) = \\<infinity>\" by auto\n  then show ?case by auto\nqed\n\nlemma dbm_abstr_completeness:\n  \"\\<lbrakk>DBM_val_bounded v u (abstr cc (\\<lambda> i j. \\<infinity>) v) n; \\<forall>c. v c > 0; \\<forall> c \\<in> collect_clks cc. v c \\<le> n\\<rbrakk>\n    \\<Longrightarrow> u \\<turnstile> cc\"\nproof (induction cc, goal_cases)\n  case (1 cc1 cc2)\n  then have AND: \"u \\<in> [abstr (AND cc1 cc2) (\\<lambda>i j. \\<infinity>) v]\\<^bsub>v,n\\<^esub>\" by (simp add: DBM_zone_repr_def)\n  from 1 have \"\\<forall>i j. i \\<le> n \\<longrightarrow> j \\<le> n\n    \\<longrightarrow> (abstr (AND cc1 cc2) (\\<lambda>i j. \\<infinity>) v) i j \\<preceq> (abstr cc1 (\\<lambda>i j. \\<infinity>) v) i j\"\n  by (simp add: less_eq[symmetric])\n  from DBM_le_subset[OF this AND] 1 have \"u \\<turnstile> cc1\" unfolding DBM_zone_repr_def by auto\n  from 1 have \"\\<forall>i j. i \\<le> n \\<longrightarrow> j \\<le> n\n    \\<longrightarrow> (abstr (AND cc1 cc2) (\\<lambda>i j. \\<infinity>) v) i j \\<preceq> (abstr cc2 (\\<lambda>i j. \\<infinity>) v) i j\"\n  by (simp add: less_eq[symmetric])\n  from DBM_le_subset[OF this AND] 1 have \"u \\<turnstile> cc2\" unfolding DBM_zone_repr_def by auto\n  from \\<open>u \\<turnstile> cc1\\<close> \\<open>u \\<turnstile> cc2\\<close> show ?case by auto\nnext\n  case (2 c d)\n  from this have \"v c \\<le> n\" by auto\n  with 2(1) have \"dbm_entry_val u (Some c) None ((abstr (LT c d) (\\<lambda>i j. \\<infinity>) v) (v c) 0)\"\n  by (auto simp: DBM_val_bounded_def)\n  moreover from 2(2) have \"v c > 0\" by auto\n  ultimately show ?case by auto\nnext\n  case (3 c d)\n  from this have \"v c \\<le> n\" by auto\n  with 3(1) have \"dbm_entry_val u (Some c) None ((abstr (LE c d) (\\<lambda>i j. \\<infinity>) v) (v c) 0)\"\n  by (auto simp: DBM_val_bounded_def)\n  moreover from 3(2) have \"v c > 0\" by auto\n  ultimately show ?case by auto\nnext\n  case (4 c d)\n  from this have c: \"v c > 0\" \"v c \\<le> n\" by auto\n  with 4(1) have B:\n    \"dbm_entry_val u (Some c) None ((abstr (EQ c d) (\\<lambda>i j. \\<infinity>) v) (v c) 0)\"\n    \"dbm_entry_val u None (Some c) ((abstr (EQ c d) (\\<lambda>i j. \\<infinity>) v) 0 (v c))\"\n  by (auto simp: DBM_val_bounded_def)\n  from c B have \"u c \\<le> d\" \"- u c \\<le> -d\" by auto\n  then show ?case by auto\nnext\n  case (5 c d)\n  from this have \"v c \\<le> n\" by auto\n  with 5(1) have \"dbm_entry_val u None (Some c) ((abstr (GT c d) (\\<lambda>i j. \\<infinity>) v) 0 (v c))\"\n  by (auto simp: DBM_val_bounded_def)\n  moreover from 5(2) have \"v c > 0\" by auto\n  ultimately show ?case by auto\nnext\n  case (6 c d)\n  from this have \"v c \\<le> n\" by auto\n  with 6(1) have \"dbm_entry_val u None (Some c) ((abstr (GE c d) (\\<lambda>i j. \\<infinity>) v) 0 (v c))\"\n  by (auto simp: DBM_val_bounded_def)\n  moreover from 6(2) have \"v c > 0\" by auto\n  ultimately show ?case by auto\nqed\n\nlemma dbm_abstr_zone_eq:\n  assumes \"clock_numbering' v n\" \"\\<forall>c\\<in>collect_clks cc. v c \\<le> n\"\n  shows \"[abstr cc (\\<lambda>i j. \\<infinity>) v]\\<^bsub>v,n\\<^esub> = {u. u \\<turnstile> cc}\"\nusing dbm_abstr_soundness dbm_abstr_completeness assms unfolding DBM_zone_repr_def by metis\n\n\nsection \\<open>Zone Intersection\\<close>\n\nlemma DBM_and_complete:\n  assumes \"DBM_val_bounded v u M1 n\" \"DBM_val_bounded v u M2 n\"\n  shows \"DBM_val_bounded v u (And M1 M2) n\"\nusing assms unfolding DBM_val_bounded_def by (auto simp: min_def)\n\nlemma DBM_and_sound1:\n  assumes \"DBM_val_bounded v u (And M1 M2) n\"\n  shows \"DBM_val_bounded v u M1 n\"\nunfolding DBM_val_bounded_def\nusing assms\nproof (safe, goal_cases)\n  case 1\n  then show ?case unfolding DBM_val_bounded_def by (auto simp: less_eq[symmetric])\nnext\n  case (2 c)\n  then have \"(And M1 M2) 0 (v c) \\<le> M1 0 (v c)\" by simp\n  from dbm_entry_val_mono_2[folded less_eq, OF _ this, of u] 2 show ?case\n  unfolding DBM_val_bounded_def by auto\nnext\n  case (3 c)\n  then have \"(And M1 M2) (v c) 0 \\<le> M1 (v c) 0\" by simp\n  from dbm_entry_val_mono_3[folded less_eq, OF _ this, of u] 3 show ?case\n  unfolding DBM_val_bounded_def by auto\nnext\n  case (4 c1 c2)\n  then have \"(And M1 M2) (v c1) (v c2) \\<le> M1 (v c1) (v c2)\" by simp\n  from dbm_entry_val_mono_1[folded less_eq, OF _ this, of u] 4 show ?case\n  unfolding DBM_val_bounded_def by auto\nqed\n\nlemma DBM_and_sound2:\n  assumes \"DBM_val_bounded v u (And M1 M2) n\"\n  shows \"DBM_val_bounded v u M2 n\"\nunfolding DBM_val_bounded_def\nusing assms\nproof (safe, goal_cases)\n  case 1\n  then show ?case unfolding DBM_val_bounded_def by (auto simp: less_eq[symmetric])\nnext\n  case (2 c)\n  then have \"(And M1 M2) 0 (v c) \\<le> M2 0 (v c)\" by simp\n  from dbm_entry_val_mono_2[folded less_eq, OF _ this, of u] 2 show ?case\n  unfolding DBM_val_bounded_def by auto\nnext\n  case (3 c)\n  then have \"(And M1 M2) (v c) 0 \\<le> M2 (v c) 0\" by simp\n  from dbm_entry_val_mono_3[folded less_eq, OF _ this, of u] 3 show ?case\n  unfolding DBM_val_bounded_def by auto\nnext\n  case (4 c1 c2)\n  then have \"(And M1 M2) (v c1) (v c2) \\<le> M2 (v c1) (v c2)\" by simp\n  from dbm_entry_val_mono_1[folded less_eq, OF _ this, of u] 4 show ?case\n  unfolding DBM_val_bounded_def by auto\nqed\n\n\nsection \\<open>Clock Reset\\<close>\n\ndefinition\n  DBM_reset :: \"('t :: time) DBM \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> 't \\<Rightarrow> 't DBM \\<Rightarrow> bool\"\nwhere\n  \"DBM_reset M n k d M' \\<equiv>\n    (\\<forall> j \\<le> n. 0 < j \\<and> k \\<noteq> j\\<longrightarrow> M' k j =  \\<infinity> \\<and> M' j k =  \\<infinity>) \\<and> M' k 0 = Le d \\<and> M' 0 k = Le (- d)\n    \\<and> M' k k = M k k\n    \\<and> (\\<forall>i \\<le> n. \\<forall>j \\<le> n.\n        i \\<noteq> k \\<and> j \\<noteq> k \\<longrightarrow> M' i j = min (dbm_add (M i k) (M k j)) (M i j))\"\n\n\nlemma DBM_reset_mono:\n  assumes \"DBM_reset M n k d M'\" \"i \\<le> n\" \"j \\<le> n\" \"i \\<noteq> k\" \"j \\<noteq> k\"\n  shows \"M' i j \\<le> M i j\"\nusing assms unfolding DBM_reset_def by auto\n\nlemma DBM_reset_len_mono:\n  assumes \"DBM_reset M n k d M'\" \"k \\<notin> set xs\" \"i \\<noteq> k\" \"j \\<noteq> k\" \"set (i # j # xs) \\<subseteq> {0..n}\"\n  shows \"len M' i j xs \\<le> len M i j xs\"\nusing assms by (induction xs arbitrary: i) (auto intro: add_mono DBM_reset_mono)\n\nlemma DBM_reset_neg_cycle_preservation:\n  assumes \"DBM_reset M n k d M'\" \"len M i i xs < Le 0\" \"set (k # i # xs) \\<subseteq> {0..n}\"\n  shows \"\\<exists> j. \\<exists> ys. set (j # ys) \\<subseteq> {0..n} \\<and> len M' j j ys < Le 0\"\nproof (cases \"xs = []\")\n  case Nil: True\n  show ?thesis\n  proof (cases \"k = i\")\n    case True\n    with Nil assms have \"len M' i i [] < Le 0\" unfolding DBM_reset_def by auto\n    moreover from assms have \"set (i # []) \\<subseteq> {0..n}\" by auto\n    ultimately show ?thesis by blast\n  next\n    case False\n    with Nil assms DBM_reset_mono have \"len M' i i [] < Le 0\" by fastforce\n    moreover from assms have \"set (i # []) \\<subseteq> {0..n}\" by auto\n    ultimately show ?thesis by blast\n  qed\nnext\n  case False\n  with assms obtain j ys where cycle:\n    \"len M j j ys < Le 0\" \"distinct (j # ys)\" \"j \\<in> set (i # xs)\" \"set ys \\<subseteq> set xs\"\n  by (metis negative_len_shortest neutral)\n  show ?thesis\n  proof (cases \"k \\<in> set (j # ys)\")\n    case False\n    with cycle assms have \"len M' j j ys \\<le> len M j j ys\" by - (rule DBM_reset_len_mono, auto)\n    moreover from cycle assms have \"set (j # ys) \\<subseteq> {0..n}\" by auto\n    ultimately show ?thesis using cycle(1) by fastforce\n  next\n    case True\n    then obtain l where l: \"(l, k) \\<in> set (arcs j j ys)\"\n    proof (cases \"j = k\", goal_cases)\n      case True\n      show ?thesis\n      proof (cases \"ys = []\")\n        case T: True\n        with True show ?thesis by (auto intro: that)\n      next\n        case False\n        then obtain z zs where \"ys = zs @ [z]\" by (metis append_butlast_last_id)\n        from arcs_decomp[OF this] True show ?thesis by (auto intro: that)\n      qed\n    next\n      case False\n      from arcs_set_elem2[OF False True] show ?thesis by (blast intro: that)\n    qed\n    show ?thesis\n    proof (cases \"ys = []\")\n      case False\n      from cycle_rotate_2'[OF False l, of M] cycle(1) obtain zs where rotated:\n        \"len M l l (k # zs) < Le 0\" \"set (l # k # zs) = set (j # ys)\" \"1 + length zs = length ys\"\n      by auto\n      with length_eq_distinct[OF this(2)[symmetric] cycle(2)] have \"distinct (l # k # zs)\" by auto\n      note rotated = rotated(1,2) this\n      from this(2) cycle(3,4) assms(3) have n_bound: \"set (l # k # zs) \\<subseteq> {0..n}\" by auto\n      then have \"l \\<le> n\" by auto\n      show ?thesis\n      proof (cases zs)\n        case Nil\n        with rotated have \"M l k + M k l < Le 0\" \"l \\<noteq> k\"  by auto\n        with assms(1) \\<open>l \\<le> n\\<close> have \"M' l l < Le 0\" unfolding DBM_reset_def mult min_def by auto\n        with \\<open>l \\<le> n\\<close> have \"len M' l l [] < Le 0\" \"set [l] \\<subseteq> {0..n}\" by auto\n        then show ?thesis by blast\n      next\n        case (Cons w ws)\n        with n_bound have *: \"set (w # l # ws) \\<subseteq> {0..n}\" by auto\n        from Cons n_bound rotated(3) have \"w \\<le> n\" \"w \\<noteq> k\" \"l \\<noteq> k\" by auto\n        with assms(1) \\<open>l \\<le> n\\<close> have\n          \"M' l w \\<le> M l k + M k w\"\n        unfolding DBM_reset_def mult min_def by auto\n        moreover from Cons rotated assms * have\n          \"len M' w l ws \\<le> len M w l ws\"\n        by - (rule DBM_reset_len_mono, auto)\n        ultimately have\n          \"len M' l l zs \\<le> len M l l (k # zs)\"\n        using Cons by (auto intro: add_mono simp add: assoc[symmetric])\n        with n_bound rotated(1) show ?thesis by fastforce\n      qed\n    next\n      case T: True\n      with True cycle have \"M j j < Le 0\" \"j = k\" by auto\n      with assms(1) have \"len M' k k [] < Le 0\" unfolding DBM_reset_def by simp\n      moreover from assms(3) have \"set (k # []) \\<subseteq> {0..n}\" by auto\n      ultimately show ?thesis by blast\n    qed\n  qed\nqed\n\ntext \\<open>Implementation of DBM reset\\<close>\n\ndefinition reset :: \"('t::time) DBM \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> 't \\<Rightarrow> 't DBM\"\nwhere\n  \"reset M n k d =\n    (\\<lambda> i j.\n        if i = k \\<and> j = 0 then Le d\n        else if i = 0 \\<and> j = k then Le (-d)\n        else if i = k \\<and> j \\<noteq> k then \\<infinity>\n        else if i \\<noteq> k \\<and> j = k then \\<infinity>\n        else if i = k \\<and> j = k then M k k\n        else min (dbm_add (M i k) (M k j)) (M i j)\n       )\"\n\nfun reset' :: \"('t::time) DBM \\<Rightarrow> nat \\<Rightarrow> 'c list \\<Rightarrow> ('c \\<Rightarrow> nat) \\<Rightarrow> 't \\<Rightarrow> 't DBM\"\nwhere\n  \"reset' M n [] v d = M\" |\n  \"reset' M n (c # cs) v d = reset (reset' M n cs v d) n (v c) d\"\n\nlemma DBM_reset_reset:\n  \"0 < k \\<Longrightarrow> k \\<le> n \\<Longrightarrow> DBM_reset M n k d (reset M n k d)\"\nunfolding DBM_reset_def by (auto simp: reset_def)\n\nlemma DBM_reset_complete:\n  assumes \"clock_numbering' v n\" \"v c \\<le> n\" \"DBM_reset M n (v c) d M'\" \"DBM_val_bounded v u M n\"\n  shows \"DBM_val_bounded v (u(c := d)) M' n\"\nunfolding DBM_val_bounded_def using assms\nproof (auto, goal_cases)\n  case 1\n  then have *: \"M 0 0 \\<ge> Le 0\" unfolding DBM_val_bounded_def less_eq by auto\n  from 1 have **: \"M' 0 0 = min (M 0 (v c) + M (v c) 0) (M 0 0)\" unfolding DBM_reset_def mult by auto\n  show ?case\n  proof (cases \"M 0 (v c) + M (v c) 0 \\<le> M 0 0\")\n    case False\n    with * ** show ?thesis unfolding min_def less_eq by auto\n  next\n    case True\n    have \"dbm_entry_val u (Some c) (Some c) (M (v c) 0 + M 0 (v c))\"\n    by (metis DBM_val_bounded_def assms(2,4) dbm_entry_val_add_4 mult)\n    then have \"M (v c) 0 + M 0 (v c) \\<ge> Le 0\"\n    unfolding less_eq dbm_le_def by (cases \"M (v c) 0 + M 0 (v c)\") auto\n    with True ** have \"M' 0 0 \\<ge> Le 0\" by (simp add: comm)\n    then show ?thesis unfolding less_eq .\n  qed\nnext\n  case (2 c')\n  show ?case\n  proof (cases \"c = c'\")\n    case False\n    hence F:\"v c' \\<noteq> v c\" using 2 by metis\n    hence *:\"M' 0 (v c') = min (dbm_add (M 0 (v c)) (M (v c) (v c'))) (M 0 (v c'))\"\n    using F 2(1,2,4,6) unfolding DBM_reset_def by simp\n    show ?thesis\n    proof (cases \"dbm_add (M 0 (v c)) (M (v c) (v c')) < M 0 (v c')\")\n      case False\n      with * have \"M' 0 (v c') = M 0 (v c')\" by (auto split: split_min)\n      hence \"dbm_entry_val u None (Some c') (M' 0 (v c'))\"\n      using 2(3,6) unfolding DBM_val_bounded_def by auto\n      thus ?thesis using F by cases fastforce+\n    next\n      case True\n      with * have **:\"M' 0 (v c') = dbm_add (M 0 (v c)) (M (v c) (v c'))\" by (auto split: split_min)\n      from 2 have \"dbm_entry_val u None (Some c) (M 0 (v c))\"\n      \"dbm_entry_val u (Some c) (Some c') (M (v c) (v c'))\"\n      unfolding DBM_val_bounded_def by auto\n      thus ?thesis\n      proof (cases, auto simp add: **, goal_cases)\n        case (1 d)\n        note G1 = this\n        from this(2) show ?case\n        proof (cases, goal_cases)\n          case (1 d')\n          from this(2) G1(3) have \"- u c' \\<le> d + d'\"\n          by (metis diff_minus_eq_add less_diff_eq less_le_trans minus_diff_eq minus_le_iff not_le)\n          thus ?case using 1 \\<open>c \\<noteq> c'\\<close> by fastforce\n        next\n          case (2 d')\n          from this(2) G1(3) have \"u c - u c' - u c < d + d'\" using add_le_less_mono by fastforce\n          hence \"- u c' < d + d'\" by simp\n          thus ?case using 2 \\<open>c \\<noteq> c'\\<close> by fastforce\n        next\n          case (3) thus ?case by auto\n        qed\n      next\n        case (2 d)\n        note G2 = this\n        from this(2) show ?case\n        proof (cases, goal_cases)\n          case (1 d')\n          from this(2) G2(3) have \"u c - u c' - u c < d' + d\" using add_le_less_mono by fastforce\n          hence \"- u c' < d' + d\" by simp\n          hence \"- u c' < d + d'\"\n          by (metis (hide_lams, no_types) diff_0_right diff_minus_eq_add minus_add_distrib minus_diff_eq)\n          thus ?case using 1 \\<open>c \\<noteq> c'\\<close> by fastforce\n        next\n          case (2 d')\n          from this(2) G2(3) have \"u c - u c' - u c < d + d'\" using add_strict_mono by fastforce\n          hence \"- u c' < d + d'\" by simp\n          thus ?case using 2 \\<open>c \\<noteq> c'\\<close> by fastforce\n        next\n          case (3) thus ?case by auto\n        qed\n      qed\n    qed\n  next\n    case True\n    with 2 show ?thesis unfolding DBM_reset_def by auto\n  qed\nnext\n  case (3 c')\n  show ?case\n  proof (cases \"c = c'\")\n    case False\n    hence F:\"v c' \\<noteq> v c\" using 3 by metis\n    hence *:\"M' (v c') 0 = min (dbm_add (M (v c') (v c)) (M (v c) 0)) (M (v c') 0)\"\n    using F 3(1,2,4,6) unfolding DBM_reset_def by simp\n    show ?thesis\n    proof (cases \"dbm_add (M (v c') (v c)) (M (v c) 0) < M (v c') 0\")\n      case False\n      with * have \"M' (v c') 0 = M (v c') 0\" by (auto split: split_min)\n      hence \"dbm_entry_val u (Some c') None (M' (v c') 0)\"\n      using 3(3,6) unfolding DBM_val_bounded_def by auto\n      thus ?thesis using F by cases fastforce+\n    next\n      case True\n      with * have **:\"M' (v c') 0 = dbm_add (M (v c') (v c)) (M (v c) 0)\" by (auto split: split_min)\n      from 3 have \"dbm_entry_val u (Some c') (Some c) (M (v c') (v c))\"\n      \"dbm_entry_val u (Some c) None (M (v c) 0)\"\n      unfolding DBM_val_bounded_def by auto\n      thus ?thesis\n      proof (cases, auto simp add: **, goal_cases)\n        case (1 d)\n        note G1 = this\n        from this(2) show ?case\n        proof (cases, goal_cases)\n          case (1 d')\n          from this(2) G1(3) have \"u c' \\<le> d + d'\" using ordered_ab_semigroup_add_class.add_mono\n          by fastforce \n          thus ?case using 1 \\<open>c \\<noteq> c'\\<close> by fastforce\n        next\n          case (2 d')\n          from this(2) G1(3) have \"u c + u c' - u c < d + d'\" using add_le_less_mono by fastforce\n          hence \"u c' < d + d'\" by simp\n          thus ?case using 2 \\<open>c \\<noteq> c'\\<close> by fastforce\n        next\n          case (3) thus ?case by auto\n        qed\n      next\n        case (2 d)\n        note G2 = this\n        from this(2) show ?case\n        proof (cases, goal_cases)\n          case (1 d')\n          from this(2) G2(3) have \"u c + u c' - u c < d' + d\" using add_le_less_mono by fastforce\n          hence \"u c' < d' + d\" by simp\n          hence \"u c' < d + d'\"\n          by (metis (hide_lams, no_types) diff_0_right diff_minus_eq_add minus_add_distrib minus_diff_eq)\n          thus ?case using 1 \\<open>c \\<noteq> c'\\<close> by fastforce\n        next\n          case (2 d')\n          from this(2) G2(3) have \"u c + u c' - u c < d + d'\" using add_strict_mono by fastforce\n          hence \"u c' < d + d'\" by simp\n          thus ?case using 2 \\<open>c \\<noteq> c'\\<close> by fastforce\n        next\n          case 3 thus ?case by auto\n        qed\n      qed\n    qed\n  next\n    case True\n    with 3 show ?thesis unfolding DBM_reset_def by auto\n  qed\nnext\n  case (4 c1 c2)\n  show ?case\n  proof (cases \"c = c1\")\n    case False\n    note F1 = this\n    show ?thesis\n    proof (cases \"c = c2\")\n      case False\n      with F1 4 have F: \"v c \\<noteq> v c1\" \"v c \\<noteq> v c2\" \"v c1 \\<noteq> 0\" \"v c2 \\<noteq> 0\" by force+\n      hence *:\"M' (v c1) (v c2) = min (dbm_add (M (v c1) (v c)) (M (v c) (v c2))) (M (v c1) (v c2))\"\n      using 4(1,2,6,7) unfolding DBM_reset_def by simp\n      show ?thesis\n      proof (cases \"dbm_add (M (v c1) (v c)) (M (v c) (v c2)) < M (v c1) (v c2)\")\n        case False\n        with * have \"M' (v c1) (v c2) = M (v c1) (v c2)\" by (auto split: split_min)\n        hence \"dbm_entry_val u (Some c1) (Some c2) (M' (v c1) (v c2))\"\n        using 4(3,6,7) unfolding DBM_val_bounded_def by auto\n        thus ?thesis using F by cases fastforce+\n      next\n        case True\n        with * have **:\"M' (v c1) (v c2) = dbm_add (M (v c1) (v c)) (M (v c) (v c2))\" by (auto split: split_min)\n        from 4 have \"dbm_entry_val u (Some c1) (Some c) (M (v c1) (v c))\"\n        \"dbm_entry_val u (Some c) (Some c2) (M (v c) (v c2))\" unfolding DBM_val_bounded_def by auto\n        thus ?thesis\n        proof (cases, auto simp add: **, goal_cases)\n          case (1 d)\n          note G1 = this\n          from this(2) show ?case\n          proof (cases, goal_cases)\n            case (1 d')\n            from this(2) G1(3) have \"u c1 - u c2 \\<le> d + d'\"\n            by (metis (hide_lams, no_types) ab_semigroup_add_class.add_ac(1) add_le_cancel_right\n                                  add_left_mono diff_add_cancel dual_order.refl dual_order.trans)\n            thus ?case using 1 \\<open>c \\<noteq> c1\\<close> \\<open>c \\<noteq> c2\\<close> by fastforce\n          next\n            case (2 d')\n            from add_less_le_mono[OF this(2) G1(3)] have \"- u c2 + u c1 < d' + d\" by simp\n            hence \"u c1 - u c2 < d + d'\" by (simp add: add.commute) \n            thus ?case using 2 \\<open>c \\<noteq> c1\\<close> \\<open>c \\<noteq> c2\\<close> by fastforce\n          next\n            case (3) thus ?case by auto\n          qed\n        next\n          case (2 d)\n          note G2 = this\n          from this(2) show ?case\n          proof (cases, goal_cases)\n            case (1 d')\n            from add_less_le_mono[OF G2(3) this(2)] have \"u c1 - u c2 < d + d'\"\n            by (metis (hide_lams, no_types) ab_semigroup_add_class.add_ac(1) add_le_cancel_right\n              diff_add_cancel dual_order.order_iff_strict dual_order.strict_trans2)\n            thus ?case using 1 \\<open>c \\<noteq> c1\\<close> \\<open>c \\<noteq> c2\\<close> by fastforce\n          next\n            case (2 d')\n            from add_strict_mono[OF this(2) G2(3)] have \"- u c2 + u c1 < d' + d\" by simp\n            hence \"- u c2 + u c1 < d + d'\"\n            by (metis (full_types) diff_0 diff_minus_eq_add minus_add_distrib minus_diff_eq)\n            hence \"u c1 - u c2 < d + d'\" by (metis add_diff_cancel_left diff_0 diff_0_right diff_add_cancel)\n            thus ?case using 2 \\<open>c \\<noteq> c1\\<close> \\<open>c \\<noteq> c2\\<close> by fastforce\n          next\n            case (3) thus ?case by auto\n          qed\n        qed\n      qed\n    next\n      case True\n      with F1 4 have F: \"v c \\<noteq> v c1\" \"v c1 \\<noteq> 0\" \"v c2 \\<noteq> 0\" by force+\n      thus ?thesis using 4(1,2,4,6,7) True unfolding DBM_reset_def by auto\n    qed\n  next\n    case True\n    note T1 = this\n    show ?thesis\n    proof (cases \"c = c2\")\n      case False\n      with T1 4 have F: \"v c \\<noteq> v c2\" \"v c1 \\<noteq> 0\" \"v c2 \\<noteq> 0\" by force+\n      thus ?thesis using 4(1,2,7) True unfolding DBM_reset_def by auto\n    next\n      case True\n      then have *: \"M' (v c1) (v c1) = M (v c1) (v c1)\"\n      using T1 4 unfolding DBM_reset_def by auto\n      from 4(1,3) True T1 have \"dbm_entry_val u (Some c1) (Some c2) (M (v c1) (v c2))\"\n      unfolding DBM_val_bounded_def by auto\n      then show ?thesis by (cases rule: dbm_entry_val.cases, auto simp: * True[symmetric] T1)\n    qed\n  qed\nqed\n\nlemma DBM_reset_sound_empty:\n  assumes \"clock_numbering' v n\" \"v c \\<le> n\" \"DBM_reset M n (v c) d M'\"\n          \"\\<forall> u . \\<not> DBM_val_bounded v u M' n\"\n  shows \"\\<not> DBM_val_bounded v u M n\"\nusing assms DBM_reset_complete by metis\n\nlemma DBM_reset_diag_preservation:\n  \"\\<forall>k\\<le>n. M k k \\<le> \\<one> \\<Longrightarrow> DBM_reset M n i d M' \\<Longrightarrow> \\<forall>k\\<le>n. M' k k \\<le> \\<one>\"\n  apply auto\n  apply (case_tac \"k = i\")\n   apply (simp add: DBM_reset_def less[symmetric])\n  apply (case_tac \"k = 0\")\nby (auto simp add: DBM_reset_def less[symmetric] neutral split: split_min)\n\nlemma FW_diag_preservation:\n  \"\\<forall>k\\<le>n. M k k \\<le> \\<one> \\<Longrightarrow> \\<forall>k\\<le>n. (FW M n) k k \\<le> \\<one>\"\nproof clarify\n  fix k assume A: \"\\<forall>k\\<le>n. M k k \\<le> \\<one>\" \"k \\<le> n\"\n  then have \"M k k \\<le> \\<one>\" by auto\n  with fw_mono[of n n n k k M n] A show \"FW M n k k \\<le> \\<one>\" by auto\nqed\n\nlemma DBM_reset_not_cyc_free_preservation:\n  assumes \"\\<not> cyc_free M n\" \"DBM_reset M n k d M'\" \"k \\<le> n\"\n  shows \"\\<not> cyc_free M' n\"\nproof -\n  from assms(1) obtain i xs where \"i \\<le> n\" \"set xs \\<subseteq> {0..n}\" \"len M i i xs < Le 0\"\n  unfolding neutral by auto\n  with DBM_reset_neg_cycle_preservation[OF assms(2) this(3)] assms(3) obtain j ys where\n    \"set (j # ys) \\<subseteq> {0..n}\" \"len M' j j ys < Le 0\"\n  by auto\n  then show ?thesis unfolding neutral by force\nqed\n\nlemma DBM_reset_complete_empty':\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering v\" \"k \\<le> n\"\n          \"DBM_reset M n k d M'\" \"\\<forall> u . \\<not> DBM_val_bounded v u M n\"\n  shows \"\\<not> DBM_val_bounded v u M' n\"\nproof -\n  from assms(5) have \"[M]\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\n  from empty_not_cyc_free[OF _ this] have \"\\<not> cyc_free M n\" using assms(2) by auto\n  from DBM_reset_not_cyc_free_preservation[OF this assms(4,3)] have \"\\<not> cyc_free M' n\" by auto\n  then obtain i xs where \"i \\<le> n\" \"set xs \\<subseteq> {0..n}\" \"len M' i i xs < \\<one>\" by auto\n  from DBM_val_bounded_neg_cycle[OF _ this assms(1)] show ?thesis by fast\nqed\n\nlemma DBM_reset_complete_empty:\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering v\"\n          \"DBM_reset (FW M n) n (v c) d M'\" \"\\<forall> u . \\<not> DBM_val_bounded v u (FW M n) n\"\n  shows \"\\<not> DBM_val_bounded v u M' n\"\nproof -\n  note A = assms\n  from A(4) have \"[FW M n]\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\n  with FW_detects_empty_zone[OF A(1), of M] A(2)\n  obtain i where i: \"i \\<le> n\" \"FW M n i i < Le 0\" by blast\n  with A(3,4) have \"M' i i < Le 0\"\n  unfolding DBM_reset_def by (cases \"i = v c\", auto split: split_min)\n  with fw_mono[of n n n i i M' n] i have \"FW M' n i i < Le 0\" by auto\n  with FW_detects_empty_zone[OF A(1), of M'] A(2) i\n  have \"[FW M' n]\\<^bsub>v,n\\<^esub> = {}\" by auto\n  with FW_zone_equiv[OF A(1)] show ?thesis by (auto simp: DBM_zone_repr_def)\nqed\n\nlemma DBM_reset_complete_empty1:\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering v\"\n          \"DBM_reset (FW M n) n (v c) d M'\" \"\\<forall> u . \\<not> DBM_val_bounded v u M n\"\n  shows \"\\<not> DBM_val_bounded v u M' n\"\nproof -\n  from assms have \"[M]\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\n  with FW_zone_equiv[OF assms(1)] have\n    \"\\<forall> u . \\<not> DBM_val_bounded v u (FW M n) n\"\n  unfolding DBM_zone_repr_def by auto\n  from DBM_reset_complete_empty[OF assms(1-3) this] show ?thesis by auto\nqed\n\ntext \\<open>\n  Lemma \\<open>FW_canonical_id\\<close> allows us to prove correspondences between reset and canonical,\n  like for the two below.\n  Can be left out for the rest because of the triviality of the correspondence.\n\\<close>\n\nlemma DBM_reset_empty'':\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering' v n\" \"v c \\<le> n\"\n          \"DBM_reset M n (v c) d M'\"\n  shows \"[M]\\<^bsub>v,n\\<^esub> = {} \\<longleftrightarrow> [M']\\<^bsub>v,n\\<^esub> = {}\"\nproof\n  assume A: \"[M]\\<^bsub>v,n\\<^esub> = {}\"\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u M n\" unfolding DBM_zone_repr_def by auto\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u M' n\"\n  using DBM_reset_complete_empty'[OF assms(1) _ assms(3,4)] assms(2) by auto\n  thus \"[M']\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\nnext\n  assume \"[M']\\<^bsub>v,n\\<^esub> = {}\"\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u M' n\" unfolding DBM_zone_repr_def by auto\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u M n\" using DBM_reset_sound_empty[OF assms(2-4)] by auto\n  thus \"[M]\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\nqed\n\nlemma DBM_reset_empty:\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering' v n\" \"v c \\<le> n\"\n          \"DBM_reset (FW M n) n (v c) d M'\"\n  shows \"[FW M n]\\<^bsub>v,n\\<^esub> = {} \\<longleftrightarrow> [M']\\<^bsub>v,n\\<^esub> = {}\"\nproof\n  assume A: \"[FW M n]\\<^bsub>v,n\\<^esub> = {}\"\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u (FW M n) n\" unfolding DBM_zone_repr_def by auto\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u M' n\"\n  using DBM_reset_complete_empty[of n v M, OF assms(1) _ assms(4)] assms(2,3) by auto\n  thus \"[M']\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\nnext\n  assume \"[M']\\<^bsub>v,n\\<^esub> = {}\"\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u M' n\" unfolding DBM_zone_repr_def by auto\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u (FW M n) n\" using DBM_reset_sound_empty[OF assms(2-)] by auto\n  thus \"[FW M n]\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\nqed\n\nlemma DBM_reset_empty':\n  assumes \"canonical M n\" \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering' v n\" \"v c \\<le> n\"\n          \"DBM_reset (FW M n) n (v c) d M'\"\n  shows   \"[M]\\<^bsub>v,n\\<^esub> = {} \\<longleftrightarrow> [M']\\<^bsub>v,n\\<^esub> = {}\"\nusing FW_canonical_id[OF assms(1)] DBM_reset_empty[OF assms(2-)] by simp\n\nlemma DBM_reset_sound':\n  assumes \"clock_numbering' v n\" \"v c \\<le> n\" \"DBM_reset M n (v c) d M'\" \"DBM_val_bounded v u M' n\"\n          \"DBM_val_bounded v u'' M n\"\n  obtains d' where  \"DBM_val_bounded v (u(c := d')) M n\"\nusing assms\nproof (auto, goal_cases)\n  case 1\n  note A = this\n  obtain S_Min_Le where S_Min_Le:\n  \"S_Min_Le = {u c' - d | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c') (v c) = Le d}\n               \\<union> {-d | d. M 0 (v c) = Le d}\" by auto\n  obtain S_Min_Lt where S_Min_Lt:\n  \"S_Min_Lt = {u c' - d | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c') (v c) = Lt d}\n              \\<union> {-d | d. M 0 (v c) = Lt d}\" by auto\n  obtain S_Max_Le where S_Max_Le:\n  \"S_Max_Le = {u c' + d | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c) (v c') = Le d}\n              \\<union> {d | d. M (v c) 0 = Le d}\" by auto\n  obtain S_Max_Lt where S_Max_Lt:\n  \"S_Max_Lt = {u c' + d | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c) (v c') = Lt d}\n              \\<union> {d | d. M (v c) 0 = Lt d}\" by auto\n\n  have \"finite {c. 0 < v c \\<and> v c \\<le> n}\" using A(6,7)\n  proof (induction n)\n    case 0\n    then have \"{c. 0 < v c \\<and> v c \\<le> 0} = {}\" by auto\n    then show ?case by (metis finite.emptyI) \n  next\n    case (Suc n)\n    then have \"finite {c. 0 < v c \\<and> v c \\<le> n}\" by auto\n    moreover have \"{c. 0 < v c \\<and> v c \\<le> Suc n} = {c. 0 < v c \\<and> v c \\<le> n} \\<union> {c. v c = Suc n}\" by auto\n    moreover have \"finite {c. v c = Suc n}\"\n    proof (cases \"{c. v c = Suc n} = {}\", auto)\n      fix c assume \"v c = Suc n\"\n      then have \"{c. v c = Suc n} = {c}\" using Suc.prems(2) by auto\n      then show ?thesis by auto\n    qed\n    ultimately show ?case by auto\n  qed\n  then have \"\\<forall> f. finite {(c,b) | c b. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = b}\" by auto\n  moreover have\n    \"\\<forall> f K. {(c,K d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\n    \\<subseteq> {(c,b) | c b. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = b}\"\n  by auto\n  ultimately have B:\n    \"\\<forall> f K. finite {(c,K d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\"\n  using finite_subset by fast\n  have \"\\<forall> f K. theLe o K = id \\<longrightarrow> finite {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\"\n  proof (auto, goal_cases)\n    case (1 f K)\n    then have\n      \"{(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\n      = (\\<lambda> (c,b). (c, theLe b)) ` {(c,K d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\"\n    proof (auto simp add: pointfree_idE, goal_cases)\n      case (1 a b)\n      then have \"(a, K b) \\<in> {(c, K d) |c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\" by auto\n      moreover from 1(1) have \"theLe (K b) = b\" by (simp add: pointfree_idE)\n      ultimately show ?case by force\n    qed\n    moreover from B have\n      \"finite ((\\<lambda> (c,b). (c, theLe b)) ` {(c,K d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d})\"\n    by auto\n    ultimately show ?case by auto\n  qed\n  then have finI:\n    \"\\<And> f g K. theLe o K = id \\<Longrightarrow> finite (g ` {(c',d) | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> f M (v c') = K d})\"\n  by auto\n  have finI1:\n    \"\\<And> f g K. theLe o K = id \\<Longrightarrow> finite (g ` {(c',d) | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> f M (v c') = K d})\"\n  proof goal_cases\n    case (1 f g K)\n    have\n      \"g ` {(c',d) | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> f M (v c') = K d}\n      \\<subseteq> g ` {(c',d) | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> f M (v c') = K d}\"\n    by auto\n    from finite_subset[OF this finI[OF 1, of g f]] show ?case .\n  qed\n  have \"\\<forall> f. finite {b. f M (v c) = b}\" by auto\n  moreover have \"\\<forall> f K. {K d | d. f M (v c) = K d} \\<subseteq> {b. f M (v c) = b}\" by auto\n  ultimately have B: \"\\<forall> f K. finite {K d | d. f M (v c) = K d}\" using finite_subset by fast\n\n  have \"\\<forall> f K. theLe o K = id \\<longrightarrow> finite {d | d. f M (v c) = K d}\"\n  proof (auto, goal_cases)\n    case (1 f K)\n    then have \"{d | d. f M (v c) = K d} = theLe ` {K d | d. f M (v c) = K d}\"\n    proof (auto simp add: pointfree_idE, goal_cases)\n      case (1 x)\n      have \"K x \\<in> {K d |d. K x = K d}\" by auto\n      moreover from 1 have \"theLe (K x) = x\"  by (simp add: pointfree_idE)\n      ultimately show ?case by auto\n    qed\n    moreover from B have \"finite {K d |d. f M (v c) = K d}\" by auto\n    ultimately show ?case by auto\n  qed\n  then have C: \"\\<forall> f g K. theLe o K = id \\<longrightarrow> finite (g ` {d | d. f M (v c) = K d})\" by auto\n  have finI2: \"\\<And> f g K. theLe o K = id \\<Longrightarrow> finite ({g d | d. f M (v c) = K d})\"\n  proof goal_cases\n    case (1 f g K)\n    have \"{g d |d. f M (v c) = K d} = g ` {d | d. f M (v c) = K d}\" by auto\n    with C 1 show ?case by auto\n  qed\n\n  { fix K :: \"'b \\<Rightarrow> 'b DBMEntry\" assume A: \"theLe o K = id\"\n    then have\n      \"finite ((\\<lambda>(c,d). u c - d) ` {(c',d) | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c') (v c) = K d})\"\n    by (intro finI1, auto)\n    moreover have\n      \"{u c' - d |c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c') (v c) = K d}\n      = ((\\<lambda>(c,d). u c - d) ` {(c',d) | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c') (v c) = K d})\"\n    by auto\n    ultimately have \"finite {u c' - d |c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c') (v c) = K d}\"\n    by auto\n    moreover have \"finite {- d |d. M 0 (v c) = K d}\" using A by (intro finI2, auto)\n    ultimately have\n      \"finite ({u c' - d |c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c') (v c) = K d}\n                \\<union> {- d |d. M 0 (v c) = K d})\"\n    by (auto simp: S_Min_Le)\n  } note fin1 = this\n  have fin_min_le: \"finite S_Min_Le\" unfolding S_Min_Le by (rule fin1, auto)\n  have fin_min_lt: \"finite S_Min_Lt\" unfolding S_Min_Lt by (rule fin1, auto)\n\n  { fix K :: \"'b \\<Rightarrow> 'b DBMEntry\" assume A: \"theLe o K = id\"\n    then have \"finite ((\\<lambda>(c,d). u c + d) ` {(c',d) | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c) (v c') = K d})\"\n    by (intro finI1, auto)\n    moreover have\n      \"{u c' + d |c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c) (v c') = K d}\n      = ((\\<lambda>(c,d). u c + d) ` {(c',d) | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c) (v c') = K d})\"\n    by auto\n    ultimately have \"finite {u c' + d |c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c) (v c') = K d}\"\n    by auto\n    moreover have \"finite {d |d. M (v c) 0 = K d}\" using A by (intro finI2, auto)\n    ultimately have\n      \"finite ({u c' + d |c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c) (v c') = K d}\n               \\<union> {d |d. M (v c) 0 = K d})\"\n    by (auto simp: S_Min_Le)\n  } note fin2 = this\n  have fin_max_le: \"finite S_Max_Le\" unfolding S_Max_Le by (rule fin2, auto)\n  have fin_max_lt: \"finite S_Max_Lt\" unfolding S_Max_Lt by (rule fin2, auto)\n\n  { fix l r assume \"l \\<in> S_Min_Le\" \"r \\<in> S_Max_Le\"\n    then have \"l \\<le> r\"\n    proof (auto simp: S_Min_Le S_Max_Le, goal_cases)\n      case (1 c1 d1 c2 d2)\n      with A have\n        \"dbm_entry_val u (Some c1) (Some c2) (M' (v c1) (v c2))\"\n      unfolding DBM_val_bounded_def by presburger\n      moreover have\n        \"M' (v c1) (v c2) = min (dbm_add (M (v c1) (v c)) (M (v c) (v c2))) (M (v c1) (v c2))\"\n      using A(3,7) 1 unfolding DBM_reset_def by metis\n      ultimately have\n        \"dbm_entry_val u (Some c1) (Some c2) (dbm_add (M (v c1) (v c)) (M (v c) (v c2)))\"\n      using dbm_entry_dbm_min' by auto \n      with 1 have \"u c1 - u c2 \\<le> d1 + d2\" by auto\n      thus ?case\n      by (metis (hide_lams, no_types) add_diff_cancel_left diff_0_right diff_add_cancel diff_eq_diff_less_eq)\n    next\n      case (2 c' d)\n      with A have\n        \"(\\<forall>i\\<le>n. i \\<noteq> v c \\<and> i > 0 \\<longrightarrow> M' i 0 = min (dbm_add (M i (v c)) (M (v c) 0)) (M i 0))\"\n        \"v c' \\<noteq> v c\"\n      unfolding DBM_reset_def by auto\n      hence \"(M' (v c') 0 = min (dbm_add (M (v c') (v c)) (M (v c) 0)) (M (v c') 0))\"\n      using 2 by blast \n      moreover from A 2 have \"dbm_entry_val u (Some c') None (M' (v c') 0)\"\n      unfolding DBM_val_bounded_def by presburger\n      ultimately have \"dbm_entry_val u (Some c') None (dbm_add (M (v c') (v c)) (M (v c) 0))\"\n      using dbm_entry_dbm_min3' by fastforce\n      with 2 have \"u c' \\<le> d + r\" by auto\n      thus ?case by (metis add_diff_cancel_left add_le_cancel_right diff_0_right diff_add_cancel)\n    next\n      case (3 d c' d')\n      with A have\n        \"(\\<forall>i\\<le>n. i \\<noteq> v c \\<and> i > 0 \\<longrightarrow> M' 0 i = min (dbm_add (M 0 (v c)) (M (v c) i)) (M 0 i))\"\n        \"v c' \\<noteq> v c\"\n      unfolding DBM_reset_def by auto\n      hence \"(M' 0 (v c') = min (dbm_add (M 0 (v c)) (M (v c) (v c'))) (M 0 (v c')))\"\n      using 3 by blast \n      moreover from A 3 have \"dbm_entry_val u None (Some c') (M' 0 (v c'))\"\n      unfolding DBM_val_bounded_def by presburger\n      ultimately have \"dbm_entry_val u None (Some c') (dbm_add (M 0 (v c)) (M (v c) (v c')))\"\n      using dbm_entry_dbm_min2' by fastforce\n      with 3 have \"-u c' \\<le> d + d'\" by auto\n      thus ?case\n      by (metis add_uminus_conv_diff diff_le_eq minus_add_distrib minus_le_iff)\n    next\n      case (4 d)\n      text \\<open>\n        Here is the reason we need the assumption that the zone was not empty before the reset.\n        We cannot deduce anything from the current value of \\<open>c\\<close> itself because we reset it.\n        We can only ensure that we can reset the value of \\<open>c\\<close> by using the value from the\n        alternative assignment.\n        This case is only relevant if the tightest bounds for \\<open>d\\<close> were given by its original\n        lower and upper bounds. If they would overlap, the original zone would be empty.\n      \\<close>\n      from A(2,5) have\n        \"dbm_entry_val u'' None (Some c) (M 0 (v c))\"\n        \"dbm_entry_val u'' (Some c) None (M (v c) 0)\"\n      unfolding DBM_val_bounded_def by auto\n      with 4 have \"- u'' c \\<le> d\" \"u'' c \\<le> r\" by auto\n      thus ?case by (metis minus_le_iff order.trans)\n    qed\n  } note EE = this\n  { fix l r assume \"l \\<in> S_Min_Le\" \"r \\<in> S_Max_Lt\"\n    then have \"l < r\"\n    proof (auto simp: S_Min_Le S_Max_Lt, goal_cases)\n      case (1 c1 d1 c2 d2)\n      with A have \"dbm_entry_val u (Some c1) (Some c2) (M' (v c1) (v c2))\"\n      unfolding DBM_val_bounded_def by presburger\n      moreover have \"M' (v c1) (v c2) = min (dbm_add (M (v c1) (v c)) (M (v c) (v c2))) (M (v c1) (v c2))\"\n      using A(3,7) 1 unfolding DBM_reset_def by metis\n      ultimately have \"dbm_entry_val u (Some c1) (Some c2) (dbm_add (M (v c1) (v c)) (M (v c) (v c2)))\"\n      using dbm_entry_dbm_min' by fastforce\n      with 1 have \"u c1 - u c2 < d1 + d2\" by auto\n      then show ?case by (metis add.assoc add.commute diff_less_eq)\n    next\n      case (2 c' d)\n      with A have\n        \"(\\<forall>i\\<le>n. i \\<noteq> v c \\<and> i > 0 \\<longrightarrow> M' i 0 = min (dbm_add (M i (v c)) (M (v c) 0)) (M i 0))\"\n        \"v c' \\<noteq> v c\"\n      unfolding DBM_reset_def by auto\n      hence \"(M' (v c') 0 = min (dbm_add (M (v c') (v c)) (M (v c) 0)) (M (v c') 0))\"\n      using 2 by blast\n      moreover from A 2 have \"dbm_entry_val u (Some c') None (M' (v c') 0)\"\n      unfolding DBM_val_bounded_def by presburger\n      ultimately have \"dbm_entry_val u (Some c') None (dbm_add (M (v c') (v c)) (M (v c) 0))\"\n      using dbm_entry_dbm_min3' by fastforce\n      with 2 have \"u c' < d + r\" by auto\n      thus ?case by (metis add_less_imp_less_right diff_add_cancel gt_swap)\n    next\n      case (3 d c' da)\n      with A have\n        \"(\\<forall>i\\<le>n. i \\<noteq> v c \\<and> i > 0 \\<longrightarrow> M' 0 i = min (dbm_add (M 0 (v c)) (M (v c) i)) (M 0 i))\"\n        \"v c' \\<noteq> v c\"\n      unfolding DBM_reset_def by auto\n      hence \"(M' 0 (v c') = min (dbm_add (M 0 (v c)) (M (v c) (v c'))) (M 0 (v c')))\"\n      using 3 by blast\n      moreover from A 3 have \"dbm_entry_val u None (Some c') (M' 0 (v c'))\"\n      unfolding DBM_val_bounded_def by presburger\n      ultimately have \"dbm_entry_val u None (Some c') (dbm_add (M 0 (v c)) (M (v c) (v c')))\"\n      using dbm_entry_dbm_min2' by fastforce\n      with 3 have \"-u c' < d + da\" by auto\n      thus ?case by (metis add.commute diff_less_eq uminus_add_conv_diff)\n    next\n      case (4 d)\n      from A(2,5) have\n        \"dbm_entry_val u'' None (Some c) (M 0 (v c))\"\n        \"dbm_entry_val u'' (Some c) None (M (v c) 0)\"\n      unfolding DBM_val_bounded_def by auto\n      with 4 have \"- u'' c \\<le> d\" \"u'' c < r\" by auto\n      thus ?case by (metis minus_le_iff neq_iff not_le order.strict_trans)\n    qed\n  } note EL = this\n  { fix l r assume \"l \\<in> S_Min_Lt\" \"r \\<in> S_Max_Le\"\n    then have \"l < r\"\n    proof (auto simp: S_Min_Lt S_Max_Le, goal_cases)\n      case (1 c1 d1 c2 d2)\n      with A have \"dbm_entry_val u (Some c1) (Some c2) (M' (v c1) (v c2))\"\n      unfolding DBM_val_bounded_def by presburger\n      moreover have \"M' (v c1) (v c2) = min (dbm_add (M (v c1) (v c)) (M (v c) (v c2))) (M (v c1) (v c2))\"\n      using A(3,7) 1 unfolding DBM_reset_def by metis\n      ultimately have \"dbm_entry_val u (Some c1) (Some c2) (dbm_add (M (v c1) (v c)) (M (v c) (v c2)))\"\n      using dbm_entry_dbm_min' by fastforce\n      with 1 have \"u c1 - u c2 < d1 + d2\" by auto\n      thus ?case by (metis add.assoc add.commute diff_less_eq)\n    next\n      case (2 c' d)\n      with A have\n        \"(\\<forall>i\\<le>n. i \\<noteq> v c \\<and> i > 0 \\<longrightarrow> M' i 0 = min (dbm_add (M i (v c)) (M (v c) 0)) (M i 0))\"\n        \"v c' \\<noteq> v c\"\n      unfolding DBM_reset_def by auto\n      hence \"(M' (v c') 0 = min (dbm_add (M (v c') (v c)) (M (v c) 0)) (M (v c') 0))\"\n      using 2 by blast\n      moreover from A 2 have \"dbm_entry_val u (Some c') None (M' (v c') 0)\"\n      unfolding DBM_val_bounded_def by presburger\n      ultimately have \"dbm_entry_val u (Some c') None (dbm_add (M (v c') (v c)) (M (v c) 0))\"\n      using dbm_entry_dbm_min3' by fastforce\n      with 2 have \"u c' < d + r\" by auto\n      thus ?case by (metis add_less_imp_less_right diff_add_cancel gt_swap)\n    next\n      case (3 d c' da)\n      with A have\n        \"(\\<forall>i\\<le>n. i \\<noteq> v c \\<and> i > 0 \\<longrightarrow> M' 0 i = min (dbm_add (M 0 (v c)) (M (v c) i)) (M 0 i))\"\n        \"v c' \\<noteq> v c\"\n      unfolding DBM_reset_def by auto\n      hence \"(M' 0 (v c') = min (dbm_add (M 0 (v c)) (M (v c) (v c'))) (M 0 (v c')))\"\n      using 3 by blast\n      moreover from A 3 have \"dbm_entry_val u None (Some c') (M' 0 (v c'))\"\n      unfolding DBM_val_bounded_def by presburger\n      ultimately have \"dbm_entry_val u None (Some c') (dbm_add (M 0 (v c)) (M (v c) (v c')))\"\n      using dbm_entry_dbm_min2' by fastforce\n      with 3 have \"-u c' < d + da\" by auto\n      thus ?case by (metis add.commute diff_less_eq uminus_add_conv_diff)\n    next\n      case (4 d)\n      from A(2,5) have\n        \"dbm_entry_val u'' None (Some c) (M 0 (v c))\"\n        \"dbm_entry_val u'' (Some c) None (M (v c) 0)\"\n      unfolding DBM_val_bounded_def by auto\n      with 4 have \"- u'' c < d\" \"u'' c \\<le> r\" by auto\n      thus ?case by (meson less_le_trans minus_less_iff)\n    qed\n  } note LE = this\n  { fix l r assume \"l \\<in> S_Min_Lt\" \"r \\<in> S_Max_Lt\"\n    then have \"l < r\"\n    proof (auto simp: S_Min_Lt S_Max_Lt, goal_cases)\n      case (1 c1 d1 c2 d2)\n      with A have \"dbm_entry_val u (Some c1) (Some c2) (M' (v c1) (v c2))\"\n      unfolding DBM_val_bounded_def by presburger\n      moreover have \"M' (v c1) (v c2) = min (dbm_add (M (v c1) (v c)) (M (v c) (v c2))) (M (v c1) (v c2))\"\n      using A(3,7) 1 unfolding DBM_reset_def by metis \n      ultimately have \"dbm_entry_val u (Some c1) (Some c2) (dbm_add (M (v c1) (v c)) (M (v c) (v c2)))\"\n      using dbm_entry_dbm_min' by fastforce\n      with 1 have \"u c1 - u c2 < d1 + d2\" by auto\n      then show ?case by (metis add.assoc add.commute diff_less_eq)\n    next\n      case (2 c' d)\n      with A have\n        \"(\\<forall>i\\<le>n. i \\<noteq> v c \\<and> i > 0\\<longrightarrow> M' i 0 = min (dbm_add (M i (v c)) (M (v c) 0)) (M i 0))\"\n        \"v c' \\<noteq> v c\"\n      unfolding DBM_reset_def by auto\n      hence \"(M' (v c') 0 = min (dbm_add (M (v c') (v c)) (M (v c) 0)) (M (v c') 0))\"\n      using 2 by blast\n      moreover from A 2 have \"dbm_entry_val u (Some c') None (M' (v c') 0)\"\n      unfolding DBM_val_bounded_def by presburger\n      ultimately have \"dbm_entry_val u (Some c') None (dbm_add (M (v c') (v c)) (M (v c) 0))\"\n      using dbm_entry_dbm_min3' by fastforce\n      with 2 have \"u c' < d + r\" by auto\n      thus ?case by (metis add_less_imp_less_right diff_add_cancel gt_swap)\n    next\n      case (3 d c' da)\n      with A have\n        \"(\\<forall>i\\<le>n. i \\<noteq> v c \\<and> i > 0 \\<longrightarrow> M' 0 i = min (dbm_add (M 0 (v c)) (M (v c) i)) (M 0 i))\"\n        \"v c' \\<noteq> v c\"\n      unfolding DBM_reset_def by auto\n      hence \"(M' 0 (v c') = min (dbm_add (M 0 (v c)) (M (v c) (v c'))) (M 0 (v c')))\"\n      using 3 by blast\n      moreover from A 3 have \"dbm_entry_val u None (Some c') (M' 0 (v c'))\"\n      unfolding DBM_val_bounded_def by presburger\n      ultimately have \"dbm_entry_val u None (Some c') (dbm_add (M 0 (v c)) (M (v c) (v c')))\"\n      using dbm_entry_dbm_min2' by fastforce\n      with 3 have \"-u c' < d + da\" by auto\n      thus ?case by (metis ab_group_add_class.ab_diff_conv_add_uminus add.commute diff_less_eq)\n    next\n      case (4 d)\n      from A(2,5) have\n        \"dbm_entry_val u'' None (Some c) (M 0 (v c))\"\n        \"dbm_entry_val u'' (Some c) None (M (v c) 0)\"\n      unfolding DBM_val_bounded_def by auto\n      with 4 have \"- u'' c \\<le> d\" \"u'' c < r\" by auto\n      thus ?case by (metis minus_le_iff neq_iff not_le order.strict_trans)\n    qed\n  } note LL = this\n\n  obtain d' where d':\n    \"\\<forall> t \\<in> S_Min_Le. d' \\<ge> t\" \"\\<forall> t \\<in> S_Min_Lt. d' > t\"\n    \"\\<forall> t \\<in> S_Max_Le. d' \\<le> t\" \"\\<forall> t \\<in> S_Max_Lt. d' < t\"\n  proof -\n    assume m:\n      \"\\<And>d'. \\<lbrakk>\\<forall>t\\<in>S_Min_Le. t \\<le> d'; \\<forall>t\\<in>S_Min_Lt. t < d'; \\<forall>t\\<in>S_Max_Le. d' \\<le> t; \\<forall>t\\<in>S_Max_Lt. d' < t\\<rbrakk>\n        \\<Longrightarrow> thesis\"\n    let ?min_le = \"Max S_Min_Le\"\n    let ?min_lt = \"Max S_Min_Lt\" \n    let ?max_le = \"Min S_Max_Le\"\n    let ?max_lt = \"Min S_Max_Lt\"\n    \n    show thesis\n    proof (cases \"S_Min_Le = {} \\<and> S_Min_Lt = {}\")\n      case True\n      note T = this\n      show thesis\n      proof (cases \"S_Max_Le = {} \\<and> S_Max_Lt = {}\")\n        case True\n        let ?d' = \"0 :: 't :: time\"\n        show thesis using True T by (intro m[of ?d']) auto\n      next\n        case False\n        let ?d =\n          \"if S_Max_Le \\<noteq> {}\n           then if S_Max_Lt \\<noteq> {} then min ?max_lt ?max_le else ?max_le\n           else ?max_lt\"\n        obtain a :: \"'b\" where a: \"a < 0\" using non_trivial_neg by auto\n        let ?d' = \"min 0 (?d + a)\"\n        { fix x assume \"x \\<in> S_Max_Le\"\n          with fin_max_le a have \"min 0 (Min S_Max_Le + a) \\<le> x\"\n          by (metis Min.boundedE add_le_same_cancel1 empty_iff less_imp_le min.coboundedI2)\n          then have \"min 0 (Min S_Max_Le + a) \\<le> x\" by auto\n        } note 1 = this\n        { fix x assume x: \"x \\<in> S_Max_Lt\"\n          have \"min 0 (min (Min S_Max_Lt) (Min S_Max_Le) + a) < ?max_lt\"\n          by (meson a add_less_same_cancel1 min.cobounded1 min.strict_coboundedI2 order.strict_trans2) \n          also from fin_max_lt x have \"\\<dots> \\<le> x\" by auto\n          finally have \"min 0 (min (Min S_Max_Lt) (Min S_Max_Le) + a) < x\" .\n        } note 2 = this\n        { fix x assume x: \"x \\<in> S_Max_Le\"\n          have \"min 0 (min (Min S_Max_Lt) (Min S_Max_Le) + a) \\<le> ?max_le\"\n          by (metis le_add_same_cancel1 linear not_le a min_le_iff_disj)\n          also from fin_max_le x have \"\\<dots> \\<le> x\" by auto\n          finally have \"min 0 (min (Min S_Max_Lt) (Min S_Max_Le) + a) \\<le> x\" .\n        } note 3 = this\n        show thesis using False T a 1 2 3\n        proof ((intro m[of ?d']), auto, goal_cases)\n          case 1 then show ?case\n          by (metis Min.in_idem add.commute fin_max_lt leD le_add_same_cancel2 min.orderI\n                    min_less_iff_disj not_less_iff_gr_or_eq)\n        qed\n      qed\n    next\n      case False\n      note F = this\n      show thesis\n      proof (cases \"S_Max_Le = {} \\<and> S_Max_Lt = {}\")\n        case True\n        let ?l =\n          \"if S_Min_Le \\<noteq> {}\n           then if S_Min_Lt \\<noteq> {} then max ?min_lt ?min_le else ?min_le\n           else ?min_lt\"\n        obtain a :: \"'b\" where \"a < 0\" using non_trivial_neg by blast\n        then have a: \"-a > 0\" using non_trivial_neg by simp\n        then obtain a :: \"'b\" where a: \"a > 0\" by blast\n        let ?d' = \"?l + a\"\n        {\n          fix x assume x: \"x \\<in> S_Min_Le\"\n          then have \"x \\<le> max ?min_lt ?min_le\" \"x \\<le> ?min_le\" using fin_min_le by (simp add: max.coboundedI2)+\n          then have \"x \\<le> max ?min_lt ?min_le + a\" \"x \\<le> ?min_le + a\" using a by (simp add: add_increasing2)+\n        } note 1 = this\n        {\n          fix x assume x: \"x \\<in> S_Min_Lt\"\n          then have \"x \\<le> max ?min_lt ?min_le\" \"x \\<le> ?min_lt\" using fin_min_lt by (simp add: max.coboundedI1)+\n          then have \"x < ?d'\" using a x by (auto simp add: add.commute add_strict_increasing)\n        } note 2 = this\n        show thesis using True F a 1 2 by ((intro m[of ?d']), auto)\n      next\n        case False\n        let ?r =\n          \"if S_Max_Le \\<noteq> {}\n           then if S_Max_Lt \\<noteq> {} then min ?max_lt ?max_le else ?max_le\n           else ?max_lt\"\n        let ?l =\n          \"if S_Min_Le \\<noteq> {}\n           then if S_Min_Lt \\<noteq> {} then max ?min_lt ?min_le else ?min_le\n           else ?min_lt\"\n        have 1: \"x \\<le> max ?min_lt ?min_le\" \"x \\<le> ?min_le\" if \"x \\<in> S_Min_Le\" for x\n        by (simp add: max.coboundedI2 that fin_min_le)+\n        {\n          fix x y assume x: \"x \\<in> S_Max_Le\" \"y \\<in> S_Min_Lt\"\n          then have \"S_Min_Lt \\<noteq> {}\" by auto\n          from LE[OF Max_in[OF fin_min_lt], OF this, OF x(1)] have \"?min_lt \\<le> x\" by auto\n        } note 3 = this\n        {\n          fix x y assume x: \"x \\<in> S_Max_Le\" \"y \\<in> S_Min_Le\"\n          with EE[OF Max_in[OF fin_min_le], OF _ x(1)] have \"?min_le \\<le> x\" by auto\n        } note 4 = this\n        {\n          fix x y assume x: \"x \\<in> S_Max_Lt\" \"y \\<in> S_Min_Lt\"\n          then have \"S_Min_Lt \\<noteq> {}\" by auto\n          from LL[OF Max_in[OF fin_min_lt], OF this, OF x(1)] have \"?min_lt < x\" by auto\n        } note 5 = this\n        {\n          fix x y assume x: \"x \\<in> S_Max_Lt\" \"y \\<in> S_Min_Le\"\n          then have \"S_Min_Le \\<noteq> {}\" by auto\n          from EL[OF Max_in[OF fin_min_le], OF this, OF x(1)] have \"?min_le < x\" by auto\n        } note 6 = this\n        \n        show thesis\n        proof (cases \"?l < ?r\")\n          case False\n          then have *: \"S_Max_Le \\<noteq> {}\"\n          proof (auto, goal_cases)\n            case 1\n            with \\<open>\\<not> (S_Max_Le = {} \\<and> S_Max_Lt = {})\\<close> obtain y where y:\"y \\<in> S_Max_Lt\" by auto\n            note 1 = 1 this\n            { fix x y assume A: \"x \\<in> S_Min_Le\" \"y \\<in> S_Max_Lt\"\n                  with EL[OF Max_in[OF fin_min_le] Min_in[OF fin_max_lt]]\n                  have \"Max S_Min_Le < Min S_Max_Lt\" by auto\n            } note ** = this\n            { fix x y assume A: \"x \\<in> S_Min_Lt\" \"y \\<in> S_Max_Lt\"\n                with LL[OF Max_in[OF fin_min_lt] Min_in[OF fin_max_lt]]\n                have \"Max S_Min_Lt < Min S_Max_Lt\" by auto\n            } note *** = this\n            show ?case\n            proof (cases \"S_Min_Le \\<noteq> {}\")\n              case True\n              note T = this\n              show ?thesis\n              proof (cases \"S_Min_Lt \\<noteq> {}\")\n                case True\n                then show False using 1 T True ** *** by auto\n              next\n                case False with 1 T ** show False by auto\n              qed\n            next\n              case False\n              with 1 False *** \\<open>\\<not> (S_Min_Le = {} \\<and> S_Min_Lt = {})\\<close> show ?thesis by auto\n            qed\n          qed\n          { fix x y assume A: \"x \\<in> S_Min_Lt\" \"y \\<in> S_Max_Lt\"\n                with LL[OF Max_in[OF fin_min_lt] Min_in[OF fin_max_lt]]\n                have \"Max S_Min_Lt < Min S_Max_Lt\" by auto\n            } note *** = this\n          { fix x y assume A: \"x \\<in> S_Min_Lt\" \"y \\<in> S_Max_Le\"\n                  with LE[OF Max_in[OF fin_min_lt] Min_in[OF fin_max_le]]\n                  have \"Max S_Min_Lt < Min S_Max_Le\" by auto\n          } note **** = this\n          from F False have **: \"S_Min_Le \\<noteq> {}\"\n          proof (auto, goal_cases)\n            case 1\n            show ?case\n            proof (cases \"S_Max_Le \\<noteq> {}\")\n              case True\n              note T = this\n              show ?thesis\n              proof (cases \"S_Max_Lt \\<noteq> {}\")\n                case True\n                then show False using 1 T True **** *** by auto\n              next\n                case False with 1 T **** show False by auto\n              qed\n            next\n              case False\n              with 1 False *** \\<open>\\<not> (S_Max_Le = {} \\<and> S_Max_Lt = {})\\<close> show ?thesis by auto\n            qed\n          qed\n          {\n            fix x assume x: \"x \\<in> S_Min_Lt\"\n            then have \"x \\<le> ?min_lt\" using fin_min_lt by (simp add: max.coboundedI2)\n            also have \"?min_lt < ?min_le\"\n            proof (rule ccontr, goal_cases)\n              case 1\n              with x ** have 1: \"?l = ?min_lt\" by (auto simp: max.absorb1)\n              have 2: \"?min_lt < ?max_le\" using * ****[OF x] by auto\n              show False\n              proof (cases \"S_Max_Lt = {}\")\n                case False\n                then have \"?min_lt < ?max_lt\" using * ***[OF x] by auto\n                with 1 2 have \"?l < ?r\" by auto\n                with \\<open>\\<not> ?l < ?r\\<close> show False by auto\n              next\n                case True\n                with 1 2 have \"?l < ?r\" by auto\n                with \\<open>\\<not> ?l < ?r\\<close> show False by auto\n              qed\n            qed\n            finally have \"x < max ?min_lt ?min_le\" by (simp add: max.strict_coboundedI2) \n          } note 2 = this\n          show thesis using F False 1 2 3 4 5 6 * ** by ((intro m[of ?l]), auto)\n        next\n          case True\n          then obtain d where d: \"?l < d\" \"d < ?r\" using dense by auto\n          let ?d' = \"d\"\n          {\n            fix t assume \"t \\<in> S_Min_Le\"\n            then have \"t \\<le> ?l\" using 1 by auto\n            with d have \"t \\<le> d\" by auto\n          }\n          moreover {\n            fix t assume t: \"t \\<in> S_Min_Lt\"\n            then have \"t \\<le> max ?min_lt ?min_le\" using fin_min_lt by (simp add: max.coboundedI1)\n            with t have \"t \\<le> ?l\" using fin_min_lt by auto\n            with d have \"t < d\" by auto\n          }\n          moreover {\n            fix t assume t: \"t \\<in> S_Max_Le\"\n            then have \"min ?max_lt ?max_le \\<le> t\" using fin_max_le by (simp add: min.coboundedI2)\n            then have \"?r \\<le> t\" using fin_max_le t by auto\n            with d have \"d \\<le> t\" by auto\n            then have \"d \\<le> t\" by (simp add: min.coboundedI2)\n          }\n          moreover {\n            fix t assume t: \"t \\<in> S_Max_Lt\"\n            then have \"min ?max_lt ?max_le \\<le> t\" using fin_max_lt by (simp add: min.coboundedI1)\n            then have \"?r \\<le> t\" using fin_max_lt t by auto\n            with d have \"d < t\" by auto\n            then have \"d < t\" by (simp add: min.strict_coboundedI2)\n          }\n          ultimately show thesis by ((intro m[of ?d']), auto)\n        qed\n      qed\n    qed\n  qed\n  have \"DBM_val_bounded v (u(c := d')) M n\" unfolding DBM_val_bounded_def\n  proof (auto, goal_cases)\n    case 1\n    with A show ?case unfolding DBM_reset_def DBM_val_bounded_def by auto\n  next\n    case (2 c')\n    show ?case\n    proof (cases \"c = c'\")\n      case False\n      with A(2,7) have \"v c \\<noteq> v c'\" by auto\n      hence *:\"M' 0 (v c') = min (dbm_add (M 0 (v c)) (M (v c) (v c'))) (M 0 (v c'))\"\n      using A(2,3,6,7) 2 unfolding DBM_reset_def by auto\n      from 2 A(2,4) have \"dbm_entry_val u None (Some c') (M' 0 (v c'))\"\n      unfolding DBM_val_bounded_def by auto\n      with dbm_entry_dbm_min2 * have \"dbm_entry_val u None (Some c') (M 0 (v c'))\" by auto\n      thus ?thesis using False by cases auto\n    next\n      case True\n      show ?thesis\n      proof (simp add: True[symmetric], cases \"M 0 (v c)\", goal_cases)\n        case (1 t)\n        hence \"-t \\<in> S_Min_Le\" unfolding S_Min_Le by force\n        hence \"d' \\<ge> -t\" using d' by auto\n        thus ?case using 1 by (auto simp: minus_le_iff)\n      next\n        case (2 t)\n        hence \"-t \\<in> S_Min_Lt\" unfolding S_Min_Lt by force\n        hence \"d' > -t\" using d' by auto\n        thus ?case using 2 by (auto simp: minus_less_iff)\n      next\n        case 3 thus ?case by auto\n      qed\n    qed\n  next\n    case (3 c')\n    show ?case\n    proof (cases \"c = c'\")\n      case False\n      with A(2,7) have \"v c \\<noteq> v c'\" by auto\n      hence *:\"M' (v c') 0 = min (dbm_add (M (v c') (v c)) (M (v c) 0)) (M (v c') 0)\"\n      using A(2,3,6,7) 3 unfolding DBM_reset_def by auto\n      from 3 A(2,4) have \"dbm_entry_val u (Some c') None (M' (v c') 0)\"\n      unfolding DBM_val_bounded_def by auto\n      with dbm_entry_dbm_min3 * have \"dbm_entry_val u (Some c') None (M (v c') 0)\" by auto\n      thus ?thesis using False by cases auto\n    next\n      case True\n      show ?thesis\n      proof (simp add: True[symmetric], cases \"M (v c) 0\", goal_cases)\n        case (1 t)\n        hence \"t \\<in> S_Max_Le\" unfolding S_Max_Le by force\n        hence \"d' \\<le> t\" using d' by auto\n        thus ?case using 1 by (auto simp: minus_le_iff)\n      next\n        case (2 t)\n        hence \"t \\<in> S_Max_Lt\" unfolding S_Max_Lt by force\n        hence \"d' < t\" using d' by auto\n        thus ?case using 2 by (auto simp: minus_less_iff)\n      next\n        case 3 thus ?case by auto\n      qed\n    qed\n  next\n    case (4 c1 c2)\n    show ?case\n    proof (cases \"c = c1\")\n      case False\n      note F1 = this\n      show ?thesis\n      proof (cases \"c = c2\")\n        case False\n        with A(2,6,7) F1 have \"v c \\<noteq> v c1\" \"v c \\<noteq> v c2\" by auto\n        hence *:\"M' (v c1) (v c2) = min (dbm_add (M (v c1) (v c)) (M (v c) (v c2))) (M (v c1) (v c2))\"\n        using A(2,3,6,7) 4 unfolding DBM_reset_def by auto\n        from 4 A(2,4) have \"dbm_entry_val u (Some c1) (Some c2) (M' (v c1) (v c2))\"\n        unfolding DBM_val_bounded_def by auto\n        with dbm_entry_dbm_min * have \"dbm_entry_val u (Some c1) (Some c2) (M (v c1) (v c2))\" by auto\n        thus ?thesis using F1 False by cases auto\n      next\n        case True\n        show ?thesis\n        proof (simp add: True[symmetric], cases \"M (v c1) (v c)\", goal_cases)\n          case (1 t)\n          hence \"u c1 - t \\<in> S_Min_Le\" unfolding S_Min_Le using A F1 4 by blast\n          hence \"d' \\<ge> u c1 - t\" using d' by auto\n          hence \"t + d' \\<ge> u c1\" by (metis le_swap add_le_cancel_right diff_add_cancel) \n          hence \"u c1 - d' \\<le> t\" by (metis add_le_imp_le_right diff_add_cancel) \n          thus ?case using 1 F1 by auto\n        next\n          case (2 t)\n          hence \"u c1 - t \\<in> S_Min_Lt\" unfolding S_Min_Lt using A 4 F1 by blast\n          hence \"d' > u c1 - t\" using d' by auto\n          hence \"d' + t > u c1\" by (metis add_strict_right_mono diff_add_cancel)\n          hence \"u c1 - d' < t\" by (metis gt_swap add_less_cancel_right diff_add_cancel)\n          thus ?case using 2 F1 by auto\n        next\n          case 3 thus ?case by auto\n        qed\n      qed\n    next\n      case True\n      note T = this\n      show ?thesis\n      proof (cases \"c = c2\")\n        case False\n        show ?thesis\n        proof (cases \"M (v c) (v c2)\", goal_cases)\n          case (1 t)\n          hence \"u c2 + t \\<in> S_Max_Le\" unfolding S_Max_Le using A 4 False by blast\n          hence \"d' \\<le> u c2 + t\" using d' by auto\n          hence \"d' - u c2 \\<le> t\"\n          by (metis (hide_lams, no_types) add_diff_cancel_left add_ac(1) add_le_cancel_right\n              add_right_cancel diff_add_cancel)\n          thus ?case using 1 T False by auto\n        next\n          case (2 t)\n          hence \"u c2 + t \\<in> S_Max_Lt\" unfolding S_Max_Lt using A 4 False by blast\n          hence \"d' < u c2 + t\" using d' by auto\n          hence \"d' - u c2 < t\" by (metis gt_swap add_less_cancel_right diff_add_cancel)\n          thus ?case using 2 T False by force\n        next\n          case 3 thus ?case using T by auto\n        qed\n      next\n        case True\n        from A 4 have *:\"dbm_entry_val u'' (Some c1) (Some c1) (M (v c1) (v c1))\"\n        unfolding DBM_val_bounded_def by auto\n        show ?thesis using True T\n        proof (simp add: True T, cases \"M (v c1) (v c1)\", goal_cases)\n          case (1 t)\n          with * have \"0 \\<le> t\" by auto\n          thus ?case using 1 by auto\n        next\n          case (2 t)\n          with * have \"0 < t\" by auto\n          thus ?case using 2 by auto\n        next\n          case 3 thus ?case by auto\n        qed\n      qed\n    qed\n  qed\n  thus ?thesis using A(1) by blast\nqed\n\nlemma DBM_reset_sound2:\n  assumes \"v c \\<le> n\" \"DBM_reset M n (v c) d M'\" \"DBM_val_bounded v u M' n\"\n  shows \"u c = d\"\nusing assms unfolding DBM_val_bounded_def DBM_reset_def\nby fastforce\n\nlemma DBM_reset_sound'':\n  fixes M v c n d\n  defines \"M' \\<equiv> reset M n (v c) d\"\n  assumes \"clock_numbering' v n\" \"v c \\<le> n\" \"DBM_val_bounded v u M' n\"\n          \"DBM_val_bounded v u'' M n\"\n  obtains d' where  \"DBM_val_bounded v (u(c := d')) M n\"\nproof -\n  assume A:\"\\<And>d'. DBM_val_bounded v (u(c := d')) M n \\<Longrightarrow> thesis\"\n  from assms DBM_reset_reset[of \"v c\" n M d]\n  have *:\"DBM_reset M n (v c) d M'\" by (auto simp add: M'_def)\n  with DBM_reset_sound'[of v n c M d M', OF _ _ this] assms obtain d' where\n  \"DBM_val_bounded v (u(c := d')) M n\" by auto\n  with A show thesis by auto\nqed\n\nlemma DBM_reset_sound:\n  fixes M v c n d\n  defines \"M' \\<equiv> reset M n (v c) d\"\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering' v n\" \"v c \\<le> n\"\n          \"u \\<in> [M']\\<^bsub>v,n\\<^esub>\"\n  obtains d' where  \"u(c := d') \\<in>[M]\\<^bsub>v,n\\<^esub>\"\nproof (cases \"[M]\\<^bsub>v,n\\<^esub> = {}\")\n  case False\n  then obtain u' where \"DBM_val_bounded v u' M n\" unfolding DBM_zone_repr_def by auto\n  from DBM_reset_sound''[OF assms(3-4) _ this] assms(1,5) that show ?thesis\n  unfolding DBM_zone_repr_def by auto\nnext\n  case True\n  with DBM_reset_complete_empty'[OF assms(2) _ _ DBM_reset_reset, of \"v c\" M u d] assms show ?thesis\n  unfolding DBM_zone_repr_def by simp\nqed\n\nlemma DBM_reset'_complete':\n  assumes \"DBM_val_bounded v u M n\" \"clock_numbering' v n\" \"\\<forall> c \\<in> set cs. v c \\<le> n\"\n  shows \"\\<exists> u'. DBM_val_bounded v u' (reset' M n cs v d) n\"\nusing assms\nproof (induction cs)\n  case Nil thus ?case by auto\nnext\n  case (Cons c cs)\n  let ?M' = \"reset' M n cs v d\"\n  let ?M'' = \"reset ?M' n (v c) d\"\n  from Cons obtain u' where u': \"DBM_val_bounded v u' ?M' n\" by fastforce\n  from Cons(3,4) have \"0 < v c\" \"v c \\<le> n\" by auto\n  from DBM_reset_reset[OF this] have **: \"DBM_reset ?M' n (v c) d ?M''\" by fast\n  from Cons(4) have \"v c \\<le> n\" by auto\n  from DBM_reset_complete[of v n c ?M' d ?M'', OF Cons(3) this ** u']\n  have \"DBM_val_bounded v (u'(c := d)) (reset (reset' M n cs v d) n (v c) d) n\" by fast\n  thus ?case by auto\nqed\n\nlemma DBM_reset'_complete:\n  assumes \"DBM_val_bounded v u M n\" \"clock_numbering' v n\" \"\\<forall> c \\<in> set cs. v c \\<le> n\"\n  shows \"DBM_val_bounded v ([cs \\<rightarrow> d]u) (reset' M n cs v d) n\"\nusing assms\nproof (induction cs)\n  case Nil thus ?case by auto\nnext\n  case (Cons c cs)\n  let ?M' = \"reset' M n cs v d\"\n  let ?M'' = \"reset ?M' n (v c) d\"\n  from Cons have *: \"DBM_val_bounded v ([cs\\<rightarrow>d]u) (reset' M n cs v d) n\" by fastforce\n  from Cons(3,4) have \"0 < v c\" \"v c \\<le> n\" by auto\n  from DBM_reset_reset[OF this] have **: \"DBM_reset ?M' n (v c) d ?M''\" by fast\n  from Cons(4) have \"v c \\<le> n\" by auto\n  from DBM_reset_complete[of v n c ?M' d ?M'', OF Cons(3) this ** *]\n  have ***:\"DBM_val_bounded v ([c#cs\\<rightarrow>d]u) (reset (reset' M n cs v d) n (v c) d) n\" by simp\n  have \"reset' M n (c#cs) v d = reset (reset' M n cs v d) n (v c) d\" by auto\n  with *** show ?case by presburger\nqed\n\nlemma DBM_reset'_sound_empty:\n  assumes \"clock_numbering' v n\" \"\\<forall>c \\<in> set cs. v c \\<le> n\"\n          \"\\<forall> u . \\<not> DBM_val_bounded v u (reset' M n cs v d) n\"\n  shows \"\\<not> DBM_val_bounded v u M n\"\nusing assms DBM_reset'_complete by metis\n\nfun set_clocks :: \"'c list \\<Rightarrow> 't::time list\\<Rightarrow> ('c,'t) cval \\<Rightarrow> ('c,'t) cval\"\nwhere\n  \"set_clocks [] _ u = u\" |\n  \"set_clocks _ [] u = u\" |\n  \"set_clocks (c#cs) (t#ts) u = (set_clocks cs ts (u(c:=t)))\"\n\nlemma DBM_reset'_sound':\n  fixes M v c n d cs\n  assumes \"clock_numbering' v n\" \"\\<forall> c \\<in> set cs. v c \\<le> n\"\n          \"DBM_val_bounded v u (reset' M n cs v d) n\" \"DBM_val_bounded v u'' M n\"\n  shows \"\\<exists>ts. DBM_val_bounded v (set_clocks cs ts u) M n\"\nusing assms\nproof (induction cs arbitrary: M u)\n  case Nil\n  hence \"DBM_val_bounded v (set_clocks [] [] u) M n\" by auto\n  thus ?case by blast\nnext\n  case (Cons c' cs)\n  let ?M' = \"reset' M n (c' # cs) v d\"\n  let ?M'' = \"reset' M n cs v d\"\n  from DBM_reset'_complete[OF Cons(5) Cons(2)] Cons(3)\n  have u'': \"DBM_val_bounded v ([cs\\<rightarrow>d]u'') ?M'' n\" by fastforce\n  from Cons(3,4) have \"v c' \\<le> n\" \"DBM_val_bounded v u (reset ?M'' n (v c') d) n\" by auto\n  from DBM_reset_sound''[OF Cons(2) this u'']\n  obtain d' where **:\"DBM_val_bounded v (u(c' := d')) ?M'' n\" by blast\n  from Cons.IH[OF Cons.prems(1) _ ** Cons.prems(4)] Cons.prems(2)\n  obtain ts where ts:\"DBM_val_bounded v (set_clocks cs ts (u(c' := d'))) M n\" by fastforce\n  hence \"DBM_val_bounded v (set_clocks (c' # cs) (d'#ts) u) M n\" by auto\n  thus ?case by fast\nqed\n\nlemma DBM_reset'_resets:\n  fixes M v c n d cs\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering' v n\" \"\\<forall> c \\<in> set cs. v c \\<le> n\"\n          \"DBM_val_bounded v u (reset' M n cs v d) n\"\n  shows \"\\<forall>c \\<in> set cs. u c = d\"\nusing assms\nproof (induction cs arbitrary: M u)\n  case Nil thus ?case by auto\nnext\n  case (Cons c' cs)\n  let ?M' = \"reset' M n (c' # cs) v d\"\n  let ?M'' = \"reset' M n cs v d\"\n  from Cons(4,5) have \"v c' \\<le> n\" \"DBM_val_bounded v u (reset ?M'' n (v c') d) n\" by auto\n  from DBM_reset_sound2[OF this(1) _ Cons(5), of ?M'' d] DBM_reset_reset[OF _ this(1), of ?M'' d] Cons(3)\n  have c':\"u c' = d\" by auto\n  from Cons(4,5) have \"v c' \\<le> n\" \"DBM_val_bounded v u (reset ?M'' n (v c') d) n\" by auto\n  with DBM_reset_sound[OF Cons.prems(1,2) this(1)]\n  obtain d' where **:\"DBM_val_bounded v (u(c' := d')) ?M'' n\" unfolding DBM_zone_repr_def by blast\n  from Cons.IH[OF Cons.prems(1,2) _ **] Cons.prems(3) have \"\\<forall>c\\<in>set cs. (u(c' := d')) c = d\" by auto\n  thus ?case using c'\n   apply safe\n   apply (rename_tac c)\n   apply (case_tac \"c = c'\")\n  by auto\nqed\n\nlemma DBM_reset'_resets':\n  fixes M v c n d cs\n  assumes \"clock_numbering' v n\" \"\\<forall> c \\<in> set cs. v c \\<le> n\" \"DBM_val_bounded v u (reset' M n cs v d) n\"\n          \"DBM_val_bounded v u'' M n\"\n  shows \"\\<forall>c \\<in> set cs. u c = d\"\nusing assms\nproof (induction cs arbitrary: M u)\n  case Nil thus ?case by auto\nnext\n  case (Cons c' cs)\n  let ?M' = \"reset' M n (c' # cs) v d\"\n  let ?M'' = \"reset' M n cs v d\"\n  from DBM_reset'_complete[OF Cons(5) Cons(2)] Cons(3)\n  have u'': \"DBM_val_bounded v ([cs\\<rightarrow>d]u'') ?M'' n\" by fastforce\n  from Cons(3,4) have \"v c' \\<le> n\" \"DBM_val_bounded v u (reset ?M'' n (v c') d) n\" by auto\n  from DBM_reset_sound2[OF this(1) _ Cons(4), of ?M'' d] DBM_reset_reset[OF _ this(1), of ?M'' d] Cons(2)\n  have c':\"u c' = d\" by auto\n  from Cons(3,4) have \"v c' \\<le> n\" \"DBM_val_bounded v u (reset ?M'' n (v c') d) n\" by auto\n  from DBM_reset_sound''[OF Cons(2) this u'']\n  obtain d' where **:\"DBM_val_bounded v (u(c' := d')) ?M'' n\" by blast\n  from Cons.IH[OF Cons.prems(1) _ ** Cons.prems(4)] Cons.prems(2)\n  have \"\\<forall>c\\<in>set cs. (u(c' := d')) c = d\" by auto\n  thus ?case using c'\n   apply safe\n   apply (rename_tac c)\n   apply (case_tac \"c = c'\")\n  by auto\nqed\n\nlemma DBM_reset'_neg_diag_preservation':\n  assumes \"k\\<le>n\" \"M k k < \\<one>\" \"clock_numbering v\" \"\\<forall> c \\<in> set cs. v c \\<le> n\"\n  shows \"reset' M n cs v d k k < \\<one>\" using assms\nproof (induction cs)\n  case Nil thus ?case by auto\nnext\n  case (Cons c cs)\n  then have IH: \"reset' M n cs v d k k < \\<one>\" by auto\n  from Cons.prems have \"v c > 0\" \"v c \\<le> n\" by auto\n  from DBM_reset_reset[OF this, of \"reset' M n cs v d\" d] \\<open>k \\<le> n\\<close>\n  have \"reset (reset' M n cs v d) n (v c) d k k \\<le> reset' M n cs v d k k\" unfolding DBM_reset_def\n  by (cases \"v c = k\", simp add: less[symmetric], case_tac \"k = 0\", auto simp: less[symmetric])\n  with IH show ?case by auto\nqed\n\nlemma DBM_reset'_complete_empty':\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering' v n\"\n          \"\\<forall> c \\<in> set cs. v c \\<le> n\" \"\\<forall> u . \\<not> DBM_val_bounded v u M n\"\n  shows \"\\<forall> u . \\<not> DBM_val_bounded v u (reset' M n cs v d) n\" using assms\nproof (induction cs)\n  case Nil then show ?case by simp\nnext\n  case (Cons c cs)\n  then have \"\\<forall>u. \\<not> DBM_val_bounded v u (reset' M n cs v d) n\" by auto\n  from Cons.prems(2,3) DBM_reset_complete_empty'[OF Cons.prems(1) _ _ DBM_reset_reset this] \n  show ?case by auto\nqed\n\nlemma DBM_reset'_complete_empty:\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering' v n\"\n          \"\\<forall> c \\<in> set cs. v c \\<le> n\" \"\\<forall> u . \\<not> DBM_val_bounded v u M n\"\n  shows \"\\<forall> u . \\<not> DBM_val_bounded v u (reset' (FW M n) n cs v d) n\" using assms\nproof -\n  note A = assms\n  from A(4) have \"[M]\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\n  with FW_zone_equiv[OF A(1)] have \"[FW M n]\\<^bsub>v,n\\<^esub> = {}\" by auto\n  with FW_detects_empty_zone[OF A(1)] A(2) obtain i where i: \"i \\<le> n\" \"FW M n i i < Le 0\" by blast\n  with DBM_reset'_neg_diag_preservation' A(2,3) have\n    \"reset' (FW M n) n cs v d i i < Le 0\"\n  by (auto simp: neutral)\n  with fw_mono[of n n n i i \"reset' (FW M n) n cs v d\" n] i\n  have \"FW (reset' (FW M n) n cs v d) n i i < Le 0\" by auto\n  with FW_detects_empty_zone[OF A(1), of \"reset' (FW M n) n cs v d\"] A(2,3) i\n  have \"[FW (reset' (FW M n) n cs v d) n]\\<^bsub>v,n\\<^esub> = {}\" by auto\n  with FW_zone_equiv[OF A(1), of \"reset' (FW M n) n cs v d\"] A(3,4)\n  show ?thesis by (auto simp: DBM_zone_repr_def)\nqed\n\nlemma DBM_reset'_empty':\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering' v n\" \"\\<forall> c \\<in> set cs. v c \\<le> n\"\n  shows \"[M]\\<^bsub>v,n\\<^esub> = {} \\<longleftrightarrow> [reset' (FW M n) n cs v d]\\<^bsub>v,n\\<^esub> = {}\"\nproof\n  let ?M' = \"reset' (FW M n) n cs v d\"\n  assume A: \"[M]\\<^bsub>v,n\\<^esub> = {}\"\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u M n\" unfolding DBM_zone_repr_def by auto\n  with DBM_reset'_complete_empty[OF assms] show \"[?M']\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\nnext\n  let ?M' = \"reset' (FW M n) n cs v d\"\n  assume A: \"[?M']\\<^bsub>v,n\\<^esub> = {}\"\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u ?M' n\" unfolding DBM_zone_repr_def by auto\n  from DBM_reset'_sound_empty[OF assms(2,3) this] have \"\\<forall> u. \\<not> DBM_val_bounded v u (FW M n) n\" by auto\n  with FW_zone_equiv[OF assms(1)] show \"[M]\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\nqed\n\nlemma DBM_reset'_empty:\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering' v n\" \"\\<forall> c \\<in> set cs. v c \\<le> n\"\n  shows \"[M]\\<^bsub>v,n\\<^esub> = {} \\<longleftrightarrow> [reset' M n cs v d]\\<^bsub>v,n\\<^esub> = {}\"\nproof\n  let ?M' = \"reset' M n cs v d\"\n  assume A: \"[M]\\<^bsub>v,n\\<^esub> = {}\"\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u M n\" unfolding DBM_zone_repr_def by auto\n  with DBM_reset'_complete_empty'[OF assms] show \"[?M']\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\nnext\n  let ?M' = \"reset' M n cs v d\"\n  assume A: \"[?M']\\<^bsub>v,n\\<^esub> = {}\"\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u ?M' n\" unfolding DBM_zone_repr_def by auto\n  from DBM_reset'_sound_empty[OF assms(2,3) this] have \"\\<forall> u. \\<not> DBM_val_bounded v u M n\" by auto\n  with FW_zone_equiv[OF assms(1)] show \"[M]\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\nqed\n\nlemma DBM_reset'_sound:\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering' v n\"\n    and \"\\<forall>c\\<in>set cs. v c \\<le> n\"\n    and \"u \\<in> [reset' M n cs v d]\\<^bsub>v,n\\<^esub>\"\n  shows \"\\<exists>ts. set_clocks cs ts u \\<in> [M]\\<^bsub>v,n\\<^esub>\"\nproof -\n  from DBM_reset'_empty[OF assms(1-3)] assms(4) obtain u' where \"u' \\<in> [M]\\<^bsub>v,n\\<^esub>\" by blast\n  with DBM_reset'_sound'[OF assms(2,3)] assms(4) show ?thesis unfolding DBM_zone_repr_def by blast\nqed\n\nsection \\<open>Misc Preservation Lemmas\\<close>\n\nlemma get_const_sum[simp]:\n  \"a \\<noteq> \\<infinity> \\<Longrightarrow> b \\<noteq> \\<infinity> \\<Longrightarrow> get_const a \\<in> \\<int> \\<Longrightarrow> get_const b \\<in> \\<int> \\<Longrightarrow> get_const (a + b) \\<in> \\<int>\"\nby (cases a) (cases b, auto simp: mult)+\n\nlemma sum_not_inf_dest:\n  assumes \"a + b \\<noteq> \\<infinity>\"\n  shows \"a \\<noteq> \\<infinity> \\<and> b \\<noteq> \\<infinity>\"\nusing assms by (cases a; cases b; simp add: mult)\n\nlemma sum_not_inf_int:\n  assumes \"a + b \\<noteq> \\<infinity>\" \"get_const a \\<in> \\<int>\" \"get_const b \\<in> \\<int>\"\n  shows \"get_const (a + b) \\<in> \\<int>\"\nusing assms sum_not_inf_dest by fastforce\n\nlemma int_fw_upd:\n  \"\\<forall> i \\<le> n. \\<forall> j \\<le> n. m i j \\<noteq> \\<infinity> \\<longrightarrow> get_const (m i j) \\<in> \\<int> \\<Longrightarrow> k \\<le> n \\<Longrightarrow> i \\<le> n \\<Longrightarrow> j \\<le> n\n  \\<Longrightarrow> i' \\<le> n \\<Longrightarrow> j' \\<le> n \\<Longrightarrow> (fw_upd m k i j i' j') \\<noteq> \\<infinity>\n  \\<Longrightarrow> get_const (fw_upd m k i j i' j') \\<in> \\<int>\"\nproof (goal_cases)\n  case 1\n  show ?thesis\n  proof (cases \"i = i' \\<and> j = j'\")\n    case True\n    with 1 show ?thesis by (fastforce simp: fw_upd_def upd_def min_def dest: sum_not_inf_dest)\n  next\n    case False\n    with 1 show ?thesis by (auto simp : fw_upd_def upd_def)\n  qed\nqed\n\nlemma fw_int_aux_c:\n  assumes \"\\<forall> i \\<le> n. \\<forall> j \\<le> n. M i j \\<noteq> \\<infinity> \\<longrightarrow> get_const (M i j) \\<in> \\<int>\" \"a \\<le> n\" \"b \\<le> n\" \"c \\<le> n\"\n          \"i \\<le> n\" \"j \\<le> n\" \"((fw M n) 0 0 c) i j \\<noteq> \\<infinity>\"\n  shows \"get_const (((fw M n) 0 0 c) i j) \\<in> \\<int>\"\nusing assms\n apply (induction c arbitrary: i j)\n  apply (auto simp: fw_upd_def upd_def min_def)[]\n  apply (case_tac \"M 0 0 = \\<infinity>\")\n   apply (simp add: mult)\n  apply simp\n apply (fastforce simp: min_def fw_upd_def upd_def dest: sum_not_inf_dest)\ndone\n\nlemma fw_int_aux_Suc_b:\n  assumes \"\\<forall> i \\<le> n. \\<forall> j \\<le> n. (fw M n) a b n i j \\<noteq> \\<infinity> \\<longrightarrow> get_const ((fw M n) a b n i j) \\<in> \\<int>\"\n          \"a \\<le> n\" \"Suc b \\<le> n\" \"c \\<le> n\" \"i \\<le> n\" \"j \\<le> n\" \"((fw M n) a (Suc b) c) i j \\<noteq> \\<infinity>\"\n  shows \"get_const (((fw M n) a (Suc b) c) i j) \\<in> \\<int>\"\nusing assms by (induction c arbitrary: i j) (auto intro: int_fw_upd[of n])\n\nlemma fw_int_aux_b:\n  assumes \"\\<forall> i \\<le> n. \\<forall> j \\<le> n. M i j \\<noteq> \\<infinity> \\<longrightarrow> get_const (M i j) \\<in> \\<int>\" \"a \\<le> n\" \"b \\<le> n\" \"c \\<le> n\"\n          \"i \\<le> n\" \"j \\<le> n\" \"((fw M n) 0 b c) i j \\<noteq> \\<infinity>\"\n  shows \"get_const (((fw M n) 0 b c) i j) \\<in> \\<int>\" using assms\n apply (induction b arbitrary: i j c)\n  apply (blast intro: fw_int_aux_c)\n apply (rule fw_int_aux_Suc_b[of n])\nby auto\n\nlemma fw_int_aux_Suc_a:\n  assumes \"\\<forall> i \\<le> n. \\<forall> j \\<le> n. (fw M n) a n n i j \\<noteq> \\<infinity> \\<longrightarrow> get_const ((fw M n) a n n i j) \\<in> \\<int>\"\n          \"Suc a \\<le> n\" \"b \\<le> n\" \"c \\<le> n\" \"i \\<le> n\" \"j \\<le> n\" \"((fw M n) (Suc a) b c) i j \\<noteq> \\<infinity>\"\n  shows \"get_const (((fw M n) (Suc a) b c) i j) \\<in> \\<int>\"\nusing assms\nproof (induction b arbitrary: i j c)\n  case 0\n  then show ?case\n  by (induction c arbitrary: i j) (auto intro: int_fw_upd[of n])\nnext\n  case (Suc b)\n  then show ?case by (intro fw_int_aux_Suc_b) auto\nqed\n\nlemma fw_int_preservation:\n  assumes \"\\<forall> i \\<le> n. \\<forall> j \\<le> n. M i j \\<noteq> \\<infinity> \\<longrightarrow> get_const (M i j) \\<in> \\<int>\" \"a \\<le> n\" \"b \\<le> n\" \"c \\<le> n\"\n          \"i \\<le> n\" \"j \\<le> n\" \"((fw M n) a b c) i j \\<noteq> \\<infinity>\"\n  shows \"get_const (((fw M n) a b c) i j) \\<in> \\<int>\"\nusing assms\n apply (induction a arbitrary: i j b c)\n  apply (blast intro: fw_int_aux_b)\n apply (rule fw_int_aux_Suc_a[of n])\nby auto\n\nlemma FW_int_preservation:\n  assumes \"\\<forall> i \\<le> n. \\<forall> j \\<le> n. M i j \\<noteq> \\<infinity> \\<longrightarrow> get_const (M i j) \\<in> \\<int>\"\n  shows \"\\<forall> i \\<le> n. \\<forall> j \\<le> n. FW M n i j \\<noteq> \\<infinity> \\<longrightarrow> get_const (FW M n i j) \\<in> \\<int>\"\nby (blast intro: fw_int_preservation[OF assms(1)])\n\nabbreviation \"dbm_int M n \\<equiv> \\<forall> i\\<le>n. \\<forall> j\\<le>n. M i j \\<noteq> \\<infinity> \\<longrightarrow> get_const (M i j) \\<in> \\<int>\"\n\nlemma And_int_preservation:\n  assumes \"dbm_int M1 n\" \"dbm_int M2 n\"\n  shows \"dbm_int (And M1 M2) n\"\nusing assms by (auto simp: min_def)\n\nlemma up_int_preservation:\n  \"dbm_int M n \\<Longrightarrow> dbm_int (up M) n\"\nunfolding up_def min_def\n apply safe\n apply (case_tac \"i = 0\")\n  apply fastforce\n apply (case_tac \"j = 0\")\n  apply fastforce\n apply auto\nunfolding mult[symmetric] by (auto dest: sum_not_inf_dest)\n\n(* Definitely a candidate for cleaning *)\nlemma DBM_reset_int_preservation':\n  assumes \"dbm_int M n\" \"DBM_reset M n k d M'\" \"d \\<in> \\<int>\" \"k \\<le> n\"\n  shows \"dbm_int M' n\"\nproof clarify\n  fix i j\n  assume A: \"i \\<le> n\" \"j \\<le> n\" \"M' i j \\<noteq> \\<infinity>\"\n  from assms(2) show \"get_const (M' i j) \\<in> \\<int>\" unfolding DBM_reset_def\n    apply (cases \"i = k\"; cases \"j = k\")\n      apply simp\n      using A assms(1,4) apply presburger\n     apply (cases \"j = 0\")\n      using assms(3) apply simp\n     using A apply simp\n    apply simp\n    apply (cases \"i = 0\")\n      using assms(3) apply simp\n     using A apply simp\n    using A apply simp\n    apply (simp split: split_min, safe)\n    subgoal\n    proof goal_cases\n      case 1\n      then have *: \"M i k + M k j \\<noteq> \\<infinity>\" unfolding mult min_def by meson\n      with sum_not_inf_dest have \"M i k \\<noteq> \\<infinity>\" \"M k j \\<noteq> \\<infinity>\" by auto\n      with 1(3,4) assms(1,4) have \"get_const (M i k) \\<in> \\<int>\" \"get_const (M k j) \\<in> \\<int>\" by auto\n      with sum_not_inf_int[folded mult, OF *] show ?case unfolding mult by auto\n    qed\n    subgoal\n    proof goal_cases\n      case 1\n      then have *: \"M i j \\<noteq> \\<infinity>\" unfolding mult min_def by meson\n      with 1(3,4) assms(1,4) show ?case by auto\n    qed\n  done\nqed\n\nlemma DBM_reset_int_preservation:\n  assumes \"dbm_int M n\" \"d \\<in> \\<int>\" \"0 < k\" \"k \\<le> n\"\n  shows \"dbm_int (reset M n k d) n\"\nusing assms(3-) DBM_reset_int_preservation'[OF assms(1) DBM_reset_reset assms(2)] by blast\n\nlemma DBM_reset'_int_preservation:\n  assumes \"dbm_int M n\" \"d \\<in> \\<int>\" \"\\<forall>c. v c > 0\" \"\\<forall> c \\<in> set cs. v c \\<le> n\"\n  shows \"dbm_int (reset' M n cs v d) n\" using assms\nproof (induction cs)\n  case Nil then show ?case by simp\nnext\n  case (Cons c cs)\n  from Cons.IH[OF Cons.prems(1,2,3)] Cons.prems(4) have \"dbm_int (reset' M n cs v d) n\" by fastforce\n  from DBM_reset_int_preservation[OF this Cons.prems(2), of \"v c\"] Cons.prems(3,4) show ?case by auto\nqed\n\nlemma int_zone_dbm:\n  assumes \"clock_numbering' v n\"\n    \"\\<forall> (_,d) \\<in> collect_clock_pairs cc. d \\<in> \\<int>\" \"\\<forall> c \\<in> collect_clks cc. v c \\<le> n\"\n  obtains M where \"{u. u \\<turnstile> cc} = [M]\\<^bsub>v,n\\<^esub>\"\n            and   \"\\<forall> i \\<le> n. \\<forall> j \\<le> n. M i j \\<noteq> \\<infinity> \\<longrightarrow> get_const (M i j) \\<in> \\<int>\"\nproof -\n  let ?M = \"abstr cc (\\<lambda>i j. \\<infinity>) v\"\n  from assms(2) have \"\\<forall> i \\<le> n. \\<forall> j \\<le> n. ?M i j \\<noteq> \\<infinity> \\<longrightarrow> get_const (?M i j) \\<in> \\<int>\"\n  by (induction cc) (auto simp: min_def)\n  with dbm_abstr_zone_eq[OF assms(1) assms(3)] show ?thesis by (auto intro: that)\nqed\n\nlemma reset_set1:\n  \"\\<forall>c \\<in> set cs. ([cs\\<rightarrow>d]u) c = d\"\nby (induction cs) auto\n\nlemma reset_set11:\n  \"\\<forall>c. c \\<notin> set cs \\<longrightarrow> ([cs\\<rightarrow>d]u) c = u c\"\nby (induction cs) auto\n\nlemma reset_set2:\n  \"\\<forall>c. c \\<notin> set cs \\<longrightarrow> (set_clocks cs ts u)c = u c\"\nproof (induction cs arbitrary: ts u)\n  case Nil then show ?case by auto\nnext\n  case Cons then show ?case\n  proof (cases ts, goal_cases)\n   case Nil then show ?thesis by simp\n  next\n    case (2 a') then show ?case by auto\n  qed\nqed\n\nlemma reset_set:\n  assumes \"\\<forall> c \\<in> set cs. u c = d\"\n  shows \"[cs\\<rightarrow>d](set_clocks cs ts u) = u\"\nproof\n  fix c\n  show \"([cs\\<rightarrow>d]set_clocks cs ts u) c = u c\"\n  proof (cases \"c \\<in> set cs\")\n    case True\n    hence \"([cs\\<rightarrow>d]set_clocks cs ts u) c = d\" using reset_set1 by fast\n    also have \"d = u c\" using assms True by auto\n    finally show ?thesis by auto\n  next\n    case False\n    hence \"([cs\\<rightarrow>d]set_clocks cs ts u) c = set_clocks cs ts u c\" by (simp add: reset_set11)\n    also  with False have \"\\<dots> = u c\" by (simp add: reset_set2)\n    finally show ?thesis by auto\n  qed\nqed\n\nabbreviation global_clock_numbering ::\n  \"('a, 'c, 't :: time, 's) ta \\<Rightarrow> ('c \\<Rightarrow> nat) \\<Rightarrow> nat \\<Rightarrow> bool\"\nwhere\n  \"global_clock_numbering A v n \\<equiv>\n    clock_numbering' v n \\<and> (\\<forall> c \\<in> clk_set A. v c \\<le> n) \\<and> (\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k))\"\n\nlemma dbm_int_abstr:\n  assumes \"\\<forall> (x, m) \\<in> collect_clock_pairs g. m \\<in> \\<int>\"\n  shows \"dbm_int (abstr g (\\<lambda>i j. \\<infinity>) v) n\"\nusing assms\n  apply (induction g)\n       apply auto[]\nunfolding min_def by auto\n\nlemma dbm_int_inv_abstr:\n  assumes \"\\<forall>(x,m) \\<in> clkp_set A. m \\<in> \\<nat>\"\n  shows \"dbm_int (abstr (inv_of A l) (\\<lambda>i j. \\<infinity>) v) n\"\nproof -\n  from assms have \"\\<forall> (x, m) \\<in> collect_clock_pairs (inv_of A l). m \\<in> \\<int>\"\n  unfolding clkp_set_def collect_clki_def inv_of_def using Nats_subset_Ints by auto\n  from dbm_int_abstr[OF this] show ?thesis .\nqed\n\nlemma dbm_int_guard_abstr:\n  assumes \"valid_abstraction A X k\" \"A \\<turnstile> l \\<longrightarrow>\\<^bsup>g,a,r\\<^esup> l'\"\n  shows \"dbm_int (abstr g (\\<lambda>i j. \\<infinity>) v) n\"\nproof -\n  from assms have \"\\<forall>(x,m) \\<in> clkp_set A. m \\<le> k x \\<and> x \\<in> X \\<and> m \\<in> \\<nat>\"\n  by (auto elim: valid_abstraction.cases)\n  then have \"\\<forall> (x, m) \\<in> collect_clock_pairs g. m \\<in> \\<int>\"\n  unfolding clkp_set_def collect_clkt_def using assms(2) Nats_subset_Ints by fastforce\n  from dbm_int_abstr[OF this] show ?thesis .\nqed\n\nlemma collect_clks_id: \"collect_clks cc = fst ` collect_clock_pairs cc\" by (induction cc) auto\n\nsubsection \\<open>Unused theorems\\<close>\n\n\n\nlemma canonical_cyc_free2:\n  \"canonical M n \\<Longrightarrow> cyc_free M n \\<longleftrightarrow> (\\<forall>i \\<le> n. M i i \\<ge> \\<one>)\"\n apply safe\n  apply (simp add: cyc_free_diag_dest')\nusing canonical_cyc_free by blast\n\nlemma DBM_reset'_diag_preservation:\n  assumes \"\\<forall>k\\<le>n. M k k \\<le> \\<one>\" \"clock_numbering v\" \"\\<forall> c \\<in> set cs. v c \\<le> n\"\n  shows \"\\<forall>k\\<le>n. reset' M n cs v d k k \\<le> \\<one>\" using assms\nproof (induction cs)\n  case Nil thus ?case by auto\nnext\n  case (Cons c cs)\n  then have IH: \"\\<forall>k\\<le>n. reset' M n cs v d k k \\<le> \\<one>\" by auto\n  from Cons.prems have \"v c > 0\" \"v c \\<le> n\" by auto\n  from DBM_reset_diag_preservation[of n \"reset' M n cs v d\", OF IH DBM_reset_reset, of \"v c\", OF this]\n  show ?case by simp\nqed\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Evaluation/Timed_Automata/DBM_Operations.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953651858118, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.2774742096432722}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      HoarePartialDef.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer\nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection \\<open>Hoare Logic for Partial Correctness\\<close>\ntheory HoarePartialDef imports Semantic begin\n\ntype_synonym ('s,'p) quadruple = \"('s assn \\<times> 'p \\<times> 's assn \\<times> 's assn)\"\n\nsubsection \\<open>Validity of Hoare Tuples: \\<open>\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\\<close>\\<close>\n\ndefinition\n  valid :: \"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com,'s assn,'s assn] => bool\"\n                (\"_\\<Turnstile>\\<^bsub>'/_\\<^esub>/ _ _ _,_\"  [61,60,1000, 20, 1000,1000] 60)\nwhere\n \"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<equiv> \\<forall>s t. \\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t \\<longrightarrow> s \\<in> Normal ` P \\<longrightarrow> t \\<notin> Fault ` F\n                      \\<longrightarrow>  t \\<in>  Normal ` Q \\<union> Abrupt ` A\"\n\ndefinition\n  cvalid::\n  \"[('s,'p,'f) body,('s,'p) quadruple set,'f set,\n      's assn,('s,'p,'f) com,'s assn,'s assn] =>bool\"\n                (\"_,_\\<Turnstile>\\<^bsub>'/_\\<^esub>/ _ _ _,_\"  [61,60,60,1000, 20, 1000,1000] 60)\nwhere\n \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<equiv> (\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A) \\<longrightarrow> \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n\n\ndefinition\n  nvalid :: \"[('s,'p,'f) body,nat,'f set,\n                's assn,('s,'p,'f) com,'s assn,'s assn] => bool\"\n                (\"_\\<Turnstile>_:\\<^bsub>'/_\\<^esub>/ _ _ _,_\"  [61,60,60,1000, 20, 1000,1000] 60)\nwhere\n \"\\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A \\<equiv> \\<forall>s t. \\<Gamma>\\<turnstile>\\<langle>c,s \\<rangle> =n\\<Rightarrow> t \\<longrightarrow> s \\<in> Normal ` P \\<longrightarrow> t \\<notin> Fault ` F\n                        \\<longrightarrow> t \\<in>  Normal ` Q \\<union> Abrupt ` A\"\n\n\ndefinition\n  cnvalid::\n  \"[('s,'p,'f) body,('s,'p) quadruple set,nat,'f set,\n     's assn,('s,'p,'f) com,'s assn,'s assn] \\<Rightarrow> bool\"\n                (\"_,_\\<Turnstile>_:\\<^bsub>'/_\\<^esub>/ _ _ _,_\"  [61,60,60,60,1000, 20, 1000,1000] 60)\nwhere\n \"\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A \\<equiv> (\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A) \\<longrightarrow> \\<Gamma> \\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\n\n\nnotation (ASCII)\n  valid  (\"_|='/_/ _ _ _,_\"  [61,60,1000, 20, 1000,1000] 60) and\n  cvalid  (\"_,_|='/_/ _ _ _,_\"  [61,60,60,1000, 20, 1000,1000] 60) and\n  nvalid  (\"_|=_:'/_/ _ _ _,_\"  [61,60,60,1000, 20, 1000,1000] 60) and\n  cnvalid  (\"_,_|=_:'/_/ _ _ _,_\"  [61,60,60,60,1000, 20, 1000,1000] 60)\n\n\nsubsection \\<open>Properties of Validity\\<close>\n\nlemma valid_iff_nvalid: \"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A = (\\<forall>n. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A)\"\n  apply (simp only: valid_def nvalid_def exec_iff_execn )\n  apply (blast dest: exec_final_notin_to_execn)\n  done\n\nlemma cnvalid_to_cvalid: \"(\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (unfold cvalid_def cnvalid_def valid_iff_nvalid [THEN eq_reflection])\n  apply fast\n  done\n\nlemma nvalidI:\n \"\\<lbrakk>\\<And>s t. \\<lbrakk>\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> =n\\<Rightarrow> t;s \\<in> P; t\\<notin> Fault ` F\\<rbrakk> \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (auto simp add: nvalid_def)\n\nlemma validI:\n \"\\<lbrakk>\\<And>s t. \\<lbrakk>\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> t;s \\<in> P; t\\<notin>Fault ` F\\<rbrakk> \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (auto simp add: valid_def)\n\nlemma cvalidI:\n \"\\<lbrakk>\\<And>s t. \\<lbrakk>\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A;\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t;s \\<in> P;t\\<notin>Fault ` F\\<rbrakk>\n          \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (auto simp add: cvalid_def valid_def)\n\nlemma cvalidD:\n \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A;\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A;\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t;s \\<in> P;t\\<notin>Fault ` F\\<rbrakk>\n  \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  by (auto simp add: cvalid_def valid_def)\n\nlemma cnvalidI:\n \"\\<lbrakk>\\<And>s t. \\<lbrakk>\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A;\n   \\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> =n\\<Rightarrow> t;s \\<in> P;t\\<notin>Fault ` F\\<rbrakk>\n          \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (auto simp add: cnvalid_def nvalid_def)\n\n\nlemma cnvalidD:\n \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A;\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P (Call p) Q,A;\n   \\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> =n\\<Rightarrow> t;s \\<in> P;\n   t\\<notin>Fault ` F\\<rbrakk>\n  \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  by (auto simp add: cnvalid_def nvalid_def)\n\nlemma nvalid_augment_Faults:\n  assumes validn:\"\\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes F': \"F \\<subseteq> F'\"\n  shows \"\\<Gamma>\\<Turnstile>n:\\<^bsub>/F'\\<^esub> P c Q,A\"\nproof (rule nvalidI)\n  fix s t\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> =n\\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume F: \"t \\<notin> Fault ` F'\"\n  with F' have \"t \\<notin> Fault ` F\"\n    by blast\n  with exec P validn\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    by (auto simp add: nvalid_def)\nqed\n\nlemma valid_augment_Faults:\n  assumes validn:\"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes F': \"F \\<subseteq> F'\"\n  shows \"\\<Gamma>\\<Turnstile>\\<^bsub>/F'\\<^esub> P c Q,A\"\nproof (rule validI)\n  fix s t\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume F: \"t \\<notin> Fault ` F'\"\n  with F' have \"t \\<notin> Fault ` F\"\n    by blast\n  with exec P validn\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    by (auto simp add: valid_def)\nqed\n\nlemma nvalid_to_nvalid_strip:\n  assumes validn:\"\\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes F': \"F' \\<subseteq> -F\"\n  shows \"strip F' \\<Gamma>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule nvalidI)\n  fix s t\n  assume exec_strip: \"strip F' \\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> =n\\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume F: \"t \\<notin> Fault ` F\"\n  from exec_strip obtain t' where\n    exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> =n\\<Rightarrow> t'\" and\n    t': \"t' \\<in> Fault ` (-F') \\<longrightarrow> t'=t\" \"\\<not> isFault t' \\<longrightarrow> t'=t\"\n    by (blast dest: execn_strip_to_execn)\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases \"t' \\<in> Fault ` F\")\n    case True\n    with t' F F' have False\n      by blast\n    thus ?thesis ..\n  next\n    case False\n    with exec P validn\n    have *: \"t' \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by (auto simp add: nvalid_def)\n    with t' have \"t'=t\"\n      by auto\n    with * show ?thesis\n      by simp\n  qed\nqed\n\n\nlemma valid_to_valid_strip:\n  assumes valid:\"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes F': \"F' \\<subseteq> -F\"\n  shows \"strip F' \\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule validI)\n  fix s t\n  assume exec_strip: \"strip F' \\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume F: \"t \\<notin> Fault ` F\"\n  from exec_strip obtain t' where\n    exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> t'\" and\n    t': \"t' \\<in> Fault ` (-F') \\<longrightarrow> t'=t\" \"\\<not> isFault t' \\<longrightarrow> t'=t\"\n    by (blast dest: exec_strip_to_exec)\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases \"t' \\<in> Fault ` F\")\n    case True\n    with t' F F' have False\n      by blast\n    thus ?thesis ..\n  next\n    case False\n    with exec P valid\n    have *: \"t' \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by (auto simp add: valid_def)\n    with t' have \"t'=t\"\n      by auto\n    with * show ?thesis\n      by simp\n  qed\nqed\n\n\nsubsection \\<open>The Hoare Rules: \\<open>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\\<close>\\<close>\n\nlemma mono_WeakenContext: \"A \\<subseteq> B \\<Longrightarrow>\n        (\\<lambda>(P, c, Q, A'). (\\<Gamma>, \\<Theta>, F, P, c, Q, A') \\<in> A) x \\<longrightarrow>\n        (\\<lambda>(P, c, Q, A'). (\\<Gamma>, \\<Theta>, F, P, c, Q, A') \\<in> B) x\"\napply blast\ndone\n\n\ninductive \"hoarep\"::\"[('s,'p,'f) body,('s,'p) quadruple set,'f set,\n    's assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n    (\"(3_,_/\\<turnstile>\\<^bsub>'/_ \\<^esub>(_/ (_)/ _,/_))\" [60,60,60,1000,20,1000,1000]60)\n  for \\<Gamma>::\"('s,'p,'f) body\"\nwhere\n  Skip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> Q Skip Q,A\"\n\n| Basic: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. f s \\<in> Q} (Basic f) Q,A\"\n\n| Spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. (\\<forall>t. (s,t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s,t) \\<in> r)} (Spec r) Q,A\"\n\n| Seq: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>1 R,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk>\n        \\<Longrightarrow>\n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Seq c\\<^sub>1 c\\<^sub>2) Q,A\"\n\n| Cond: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> b) c\\<^sub>1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> - b) c\\<^sub>2 Q,A\\<rbrakk>\n         \\<Longrightarrow>\n         \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) Q,A\"\n\n| While: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> b) c P,A\n          \\<Longrightarrow>\n          \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (While b c) (P \\<inter> - b),A\"\n\n| Guard: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\n          \\<Longrightarrow>\n          \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (g \\<inter> P) (Guard f g c) Q,A\"\n\n| Guarantee: \"\\<lbrakk>f \\<in> F; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\n\n| CallRec:\n  \"\\<lbrakk>(P,p,Q,A) \\<in> Specs;\n    \\<forall>(P,p,Q,A) \\<in> Specs. p \\<in> dom \\<Gamma> \\<and> \\<Gamma>,\\<Theta>\\<union>Specs\\<turnstile>\\<^bsub>/F\\<^esub> P (the (\\<Gamma> p)) Q,A \\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n\n| DynCom:\n      \"\\<forall>s \\<in> P. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (c s) Q,A\n      \\<Longrightarrow>\n      \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (DynCom c) Q,A\"\n\n| Throw: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> A Throw Q,A\"\n\n| Catch: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk> \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Catch c\\<^sub>1 c\\<^sub>2 Q,A\"\n\n| Conseq: \"\\<forall>s \\<in> P. \\<exists>P' Q' A'. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' c Q',A' \\<and> s \\<in> P' \\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A\n           \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n\n\n| Asm: \"\\<lbrakk>(P,p,Q,A) \\<in> \\<Theta>\\<rbrakk>\n         \\<Longrightarrow>\n         \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n\n\n| ExFalso: \"\\<lbrakk>\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A; \\<not> \\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  \\<comment> \\<open>This is a hack rule that enables us to derive completeness for\n        an arbitrary context \\<open>\\<Theta>\\<close>, from completeness for an empty context.\\<close>\n\n\n\ntext \\<open>Does not work, because of rule ExFalso, the context \\<open>\\<Theta>\\<close> is to blame.\n A weaker version with empty context can be derived from soundness\n and completeness later on.\\<close>\nlemma hoare_strip_\\<Gamma>:\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P p Q,A\"\n  shows \"strip (-F) \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P p Q,A\"\nusing deriv\nproof induct\n  case Skip thus ?case by (iprover intro: hoarep.Skip)\nnext\n  case Basic thus ?case by (iprover intro: hoarep.Basic)\nnext\n  case Spec thus ?case by (iprover intro: hoarep.Spec)\nnext\n  case Seq thus ?case by (iprover intro: hoarep.Seq)\nnext\n  case Cond thus ?case by (iprover intro: hoarep.Cond)\nnext\n  case While thus ?case by (iprover intro: hoarep.While)\nnext\n  case Guard thus ?case by (iprover intro: hoarep.Guard)\n(*next\n  case CallSpec thus ?case by (iprover intro: hoarep.CallSpec)\nnext\n  case (CallRec A Abr Abr' Init P Post Pre Procs Q R Result Return Z \\<Gamma> \\<Theta> init p\n         result return )\n  from CallRec.hyps\n  have \"\\<forall>p\\<in>Procs. \\<forall>Z. (strip \\<Gamma>),\\<Theta> \\<union>\n             (\\<Union>\\<^bsub>p\\<in>Procs\\<^esub>\n                 \\<Union>\\<^bsub>Z\\<^esub> {(Pre p Z, Call (Init p) p (Return p) (Result p),\n                      Post p Z, Abr p Z)})\\<turnstile>\n            (Pre p Z) (the (\\<Gamma> p)) (R p Z),(Abr' p Z)\" by blast\n  hence \"\\<forall>p\\<in>Procs. \\<forall>Z. (strip \\<Gamma>),\\<Theta> \\<union>\n             (\\<Union>\\<^bsub>p\\<in>Procs\\<^esub>\n                 \\<Union>\\<^bsub>Z\\<^esub> {(Pre p Z, Call (Init p) p (Return p) (Result p),\n                      Post p Z, Abr p Z)})\\<turnstile>\n            (Pre p Z) (the ((strip \\<Gamma>) p)) (R p Z),(Abr' p Z)\"\n    by (auto intro: hoarep.StripI)\n  then show ?case\n    apply -\n    apply (rule hoarep.CallRec)\n    apply (assumption | simp only:dom_strip)+\n    done*)\nnext\n  case DynCom\n  thus ?case\n    by - (rule hoarep.DynCom,best  elim!: ballE exE)\nnext\n  case Throw thus ?case by (iprover intro: hoarep.Throw)\nnext\n  case Catch thus ?case by (iprover intro: hoarep.Catch)\n(*next\n  case CONSEQ thus ?case apply (auto intro: hoarep.CONSEQ)*)\nnext\n  case Asm thus ?case by (iprover intro: hoarep.Asm)\nnext\n  case ExFalso\n  thus ?case\n    oops\n\nlemma hoare_augment_context:\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P p Q,A\"\n  shows \"\\<And>\\<Theta>'. \\<Theta> \\<subseteq> \\<Theta>' \\<Longrightarrow> \\<Gamma>,\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> P p Q,A\"\nusing deriv\nproof (induct)\n  case CallRec\n  case (CallRec P p Q A Specs \\<Theta> F \\<Theta>')\n  from CallRec.prems\n  have \"\\<Theta>\\<union>Specs\n       \\<subseteq> \\<Theta>'\\<union>Specs\"\n    by blast\n  with CallRec.hyps (2)\n  have \"\\<forall>(P,p,Q,A)\\<in>Specs.  p \\<in> dom \\<Gamma> \\<and> \\<Gamma>,\\<Theta>'\\<union>Specs \\<turnstile>\\<^bsub>/F\\<^esub> P  (the (\\<Gamma> p)) Q,A\"\n    by fastforce\n\n  with CallRec show ?case by - (rule hoarep.CallRec)\nnext\n  case DynCom thus ?case by (blast intro: hoarep.DynCom)\nnext\n  case (Conseq P \\<Theta> F c Q A \\<Theta>')\n  from Conseq\n  have \"\\<forall>s \\<in> P.\n         (\\<exists>P' Q' A'. \\<Gamma>,\\<Theta>' \\<turnstile>\\<^bsub>/F\\<^esub> P' c Q',A' \\<and> s \\<in> P' \\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A)\"\n    by blast\n  with Conseq show ?case by - (rule hoarep.Conseq)\nnext\n  case (ExFalso \\<Theta> F P c Q A \\<Theta>')\n  have valid_ctxt: \"\\<forall>n. \\<Gamma>,\\<Theta>\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\" \"\\<Theta> \\<subseteq> \\<Theta>'\" by fact+\n  hence \"\\<forall>n. \\<Gamma>,\\<Theta>'\\<Turnstile>n:\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (simp add: cnvalid_def) blast\n  moreover have invalid: \"\\<not> \\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"  by fact\n  ultimately show ?case\n    by (rule hoarep.ExFalso)\nqed (blast intro: hoarep.intros)+\n\n\nsubsection \\<open>Some Derived Rules\\<close>\n\nlemma  Conseq': \"\\<forall>s. s \\<in> P \\<longrightarrow>\n            (\\<exists>P' Q' A'.\n              (\\<forall> Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z)) \\<and>\n                    (\\<exists>Z. s \\<in> P' Z \\<and> (Q' Z \\<subseteq> Q) \\<and> (A' Z \\<subseteq> A)))\n           \\<Longrightarrow>\n           \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\napply (rule Conseq)\napply (rule ballI)\napply (erule_tac x=s in allE)\napply (clarify)\napply (rule_tac x=\"P' Z\" in exI)\napply (rule_tac x=\"Q' Z\" in exI)\napply (rule_tac x=\"A' Z\" in exI)\napply blast\ndone\n\nlemma conseq:\"\\<lbrakk>\\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z);\n              \\<forall>s. s \\<in> P \\<longrightarrow> (\\<exists> Z. s\\<in>P' Z \\<and> (Q' Z \\<subseteq> Q) \\<and> (A' Z \\<subseteq> A))\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule Conseq) blast\n\ntheorem conseqPrePost [trans]:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' c Q',A' \\<Longrightarrow> P \\<subseteq> P' \\<Longrightarrow>  Q' \\<subseteq> Q \\<Longrightarrow> A' \\<subseteq> A \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule conseq [where ?P'=\"\\<lambda>Z. P'\" and ?Q'=\"\\<lambda>Z. Q'\"]) auto\n\nlemma conseqPre [trans]: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' c Q,A \\<Longrightarrow> P \\<subseteq> P' \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\nby (rule conseq) auto\n\nlemma conseqPost [trans]: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q',A' \\<Longrightarrow> Q' \\<subseteq> Q \\<Longrightarrow> A' \\<subseteq> A\n \\<Longrightarrow>   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule conseq) auto\n\n\nlemma CallRec':\n  \"\\<lbrakk>p\\<in>Procs; Procs \\<subseteq> dom \\<Gamma>;\n   \\<forall>p\\<in>Procs.\n    \\<forall>Z. \\<Gamma>,\\<Theta> \\<union> (\\<Union>p\\<in>Procs. \\<Union>Z. {((P p Z),p,Q p Z,A p Z)})\n        \\<turnstile>\\<^bsub>/F\\<^esub> (P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\\<rbrakk>\n   \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P p Z) (Call p) (Q p Z),(A p Z)\"\napply (rule CallRec [where Specs=\"\\<Union>p\\<in>Procs. \\<Union>Z. {((P p Z),p,Q p Z,A p Z)}\"])\napply  blast\napply blast\ndone\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/c-parser/Simpl/HoarePartialDef.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953651858117, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.27747420964327213}}
{"text": "theory WordArrayScorres\n  imports\n    WordArrayMono\n    \"build/Generated_SCorres_Normal\"\n    AutoCorres.AutoCorres\nbegin\n\nsection \"Shallow word array method definitions\"\n\nprimrec swa_to_list\n  where\n\"swa_to_list (SWA xs) = xs\"\n\nfun list_to_swa\n  where\n\"list_to_swa xs = SWA xs\"\n\n\noverloading swa_length \\<equiv> wordarray_length\nbegin\ndefinition swa_length :: \"'a WordArray \\<Rightarrow> 32 word\"\n  where\n\"swa_length x = (of_nat (length (swa_to_list x)) :: 32 word)\"\nend (* of overloading *)\n\noverloading swa_get \\<equiv> wordarray_get\nbegin\ndefinition swa_get :: \"('a WordArray, 32 word, 'a) WordArrayGetP \\<Rightarrow> 'a\"\n  where\n\"swa_get x = \n  (let arr = swa_to_list (WordArrayGetP.arr\\<^sub>f x);\n         i = unat (WordArrayGetP.idx\\<^sub>f x);\n         v = WordArrayGetP.val\\<^sub>f x\n   in if i < length arr then arr ! i else v)\"\nend (* of overloading *)\n\noverloading swa_put \\<equiv> wordarray_put\nbegin\ndefinition swa_put :: \"('a WordArray, 32 word, 'a) WordArrayGetP \\<Rightarrow> 'a WordArray\"\n  where\n\"swa_put x = \n  (let arr = swa_to_list (WordArrayGetP.arr\\<^sub>f x);\n         i = unat (WordArrayGetP.idx\\<^sub>f x);\n         v = WordArrayGetP.val\\<^sub>f x\n   in list_to_swa (arr[i:= v]))\"\nend (* of overloading *)\n\noverloading swa_get_opt \\<equiv> wordarray_get_opt\nbegin\ndefinition swa_get_opt :: \"('a WordArray, 32 word) WordArrayGetOP \\<Rightarrow> (unit, 'a) Opt\"\n  where\n\"swa_get_opt x = \n  (let arr = swa_to_list (WordArrayGetOP.arr\\<^sub>f x);\n         i = unat (WordArrayGetOP.idx\\<^sub>f x)\n   in if i < length arr then Something (arr ! i) else Nothing ())\"\nend (* of overloading *)\n\noverloading\n  valRel_WordArrayWord \\<equiv> valRel\nbegin\ndefinition valRel_WordArrayWord:\n\"\\<And>\\<xi>' x v. \n  valRel_WordArrayWord (\\<xi>' :: (funtyp, vabstyp) vabsfuns) (x :: (('a::len8) word) WordArray) (v :: (funtyp, vabstyp) vval) \\<equiv> \n    (if len_of TYPE('a) = 8 then \n        \\<exists>xs xs'. v = VAbstract (VWA (TPrim (Num U8)) xs) \\<and> xs' = swa_to_list x \\<and> length xs' = length xs \\<and> (\\<forall>i < length xs. (xs ! i) = VPrim (LU8 (ucast (xs' ! i))))\n      else if len_of TYPE('a) = 16 then \n        \\<exists>xs xs'. v = VAbstract (VWA (TPrim (Num U16)) xs) \\<and> xs' = swa_to_list x \\<and> length xs' = length xs \\<and> (\\<forall>i < length xs. (xs ! i) = VPrim (LU16 (ucast (xs' ! i))))\n      else if len_of TYPE('a) = 32 then \n        \\<exists>xs xs'. v = VAbstract (VWA (TPrim (Num U32)) xs) \\<and> xs' = swa_to_list x \\<and> length xs' = length xs \\<and> (\\<forall>i < length xs. (xs ! i) = VPrim (LU32 (ucast (xs' ! i))))\n      else if len_of TYPE('a) = 64 then \n        \\<exists>xs xs'. v = VAbstract (VWA (TPrim (Num U64)) xs) \\<and> xs' = swa_to_list x \\<and> length xs' = length xs \\<and> (\\<forall>i < length xs. (xs ! i) = VPrim (LU64 (ucast (xs' ! i))))\n      else False)\"\nend\n\nsublocale level0_value \\<subseteq> shallow l0v_typing\n  by (unfold_locales)\n\nsublocale WordArrayValue \\<subseteq> shallow wa_abs_typing_v\n  by (unfold_locales)\n\ncontext WordArrayValue begin\n\nlemma wordarray_length_scorres:\n  \"\\<xi> ''wordarray_length'' =  vwa_length \n    \\<Longrightarrow> scorres (wordarray_length :: ('a :: len8) word WordArray \\<Rightarrow> 32 word) \n        (AFun ''wordarray_length'' ts []) \\<gamma> \\<xi>\"\n  apply (clarsimp simp: scorres_def)\n  apply (erule v_sem_afunE; clarsimp)\n  apply (erule notE)\n  unfolding vwa_length_def swa_length_def valRel_WordArrayWord\n  apply (clarsimp split: if_splits)\n  done\n\nlemma wordarray_get_u8_scorres:\n  \"\\<xi> ''wordarray_get'' =  vwa_get \n    \\<Longrightarrow> scorres \n       (wordarray_get :: (8 word WordArray, 32 word, 8 word) WordArrayGetP \\<Rightarrow> 8 word) \n       (AFun ''wordarray_get'' ts []) \\<gamma> \\<xi>\"\n  apply (clarsimp simp: scorres_def)\n  apply (erule v_sem_afunE; clarsimp)\n  apply (erule notE)\n  unfolding vwa_get_def swa_get_def valRel_WordArrayWord valRel_records\n  apply (clarsimp split: if_splits simp: Let_def ucast_id valRel_records)\n  done\n\nlemma wordarray_get_u16_scorres:\n  \"\\<xi> ''wordarray_get'' =  vwa_get \n    \\<Longrightarrow> scorres \n        (wordarray_get :: (16 word WordArray, 32 word, 16 word) WordArrayGetP \\<Rightarrow> 16 word) \n        (AFun ''wordarray_get'' ts []) \\<gamma> \\<xi>\"\n  apply (clarsimp simp: scorres_def)\n  apply (erule v_sem_afunE; clarsimp)\n  apply (erule notE)\n  unfolding vwa_get_def swa_get_def valRel_WordArrayWord valRel_records\n  apply (clarsimp split: if_splits simp: Let_def ucast_id valRel_records)\n  done\n\nlemma wordarray_get_u32_scorres:\n  \"\\<xi> ''wordarray_get'' =  vwa_get \n    \\<Longrightarrow> scorres \n        (wordarray_get :: (32 word WordArray, 32 word, 32 word) WordArrayGetP \\<Rightarrow> 32 word) \n        (AFun ''wordarray_get'' ts []) \\<gamma> \\<xi>\"\n  apply (clarsimp simp: scorres_def)\n  apply (erule v_sem_afunE; clarsimp)\n  apply (erule notE)\n  unfolding vwa_get_def swa_get_def valRel_WordArrayWord valRel_records\n  apply (clarsimp split: if_splits simp: Let_def ucast_id valRel_records)\n  done\n\nlemma wordarray_get_u64_scorres:\n  \"\\<xi> ''wordarray_get'' =  vwa_get \n    \\<Longrightarrow> scorres \n        (wordarray_get :: (64 word WordArray, 32 word, 64 word) WordArrayGetP \\<Rightarrow> 64 word) \n        (AFun ''wordarray_get'' ts []) \\<gamma> \\<xi>\"\n  apply (clarsimp simp: scorres_def)\n  apply (erule v_sem_afunE; clarsimp)\n  apply (erule notE)\n  unfolding vwa_get_def swa_get_def valRel_WordArrayWord valRel_records\n  apply (clarsimp split: if_splits simp: Let_def ucast_id valRel_records)\n  done\n\nlemma wordarray_put_u8_scorres:\n  \"\\<xi> ''wordarray_put'' =  vwa_put \n    \\<Longrightarrow> scorres \n        (wordarray_put :: (8 word WordArray, 32 word, 8 word) WordArrayGetP \\<Rightarrow> 8 word WordArray) \n        (AFun ''wordarray_put'' ts []) \\<gamma> \\<xi>\"\n  apply (clarsimp simp: scorres_def)\n  apply (erule v_sem_afunE; clarsimp)\n  apply (erule notE)\n  unfolding vwa_put_def swa_put_def valRel_WordArrayWord valRel_records\n  apply (clarsimp split: if_splits simp: Let_def ucast_id valRel_records)\n  by (metis (no_types, hide_lams) nth_list_update_eq nth_list_update_neq)\n\nlemma wordarray_put_u16_scorres:\n  \"\\<xi> ''wordarray_put'' =  vwa_put \n    \\<Longrightarrow> scorres (wordarray_put :: (16 word WordArray, 32 word, 16 word) WordArrayGetP \\<Rightarrow> 16 word WordArray) (AFun ''wordarray_put'' ts []) \\<gamma> \\<xi>\"\n  apply (clarsimp simp: scorres_def)\n  apply (erule v_sem_afunE; clarsimp)\n  apply (erule notE)\n  unfolding vwa_put_def swa_put_def valRel_WordArrayWord valRel_records\n  apply (clarsimp split: if_splits simp: Let_def ucast_id valRel_records)\n  by (metis (no_types, hide_lams) nth_list_update_eq nth_list_update_neq)\n\nlemma wordarray_put_u32_scorres:\n  \"\\<xi> ''wordarray_put'' =  vwa_put \n    \\<Longrightarrow> scorres (wordarray_put :: (32 word WordArray, 32 word, 32 word) WordArrayGetP \\<Rightarrow> 32 word WordArray) (AFun ''wordarray_put'' ts []) \\<gamma> \\<xi>\"\n  apply (clarsimp simp: scorres_def)\n  apply (erule v_sem_afunE; clarsimp)\n  apply (erule notE)\n  unfolding vwa_put_def swa_put_def valRel_WordArrayWord valRel_records\n  apply (clarsimp split: if_splits simp: Let_def ucast_id valRel_records)\n  by (metis (no_types, hide_lams) nth_list_update_eq nth_list_update_neq)\n\nlemma wordarray_put_u64_scorres:\n  \"\\<xi> ''wordarray_put'' =  vwa_put \n    \\<Longrightarrow> scorres (wordarray_put :: (64 word WordArray, 32 word, 64 word) WordArrayGetP \\<Rightarrow> 64 word WordArray) (AFun ''wordarray_put'' ts []) \\<gamma> \\<xi>\"\n  apply (clarsimp simp: scorres_def)\n  apply (erule v_sem_afunE; clarsimp)\n  apply (erule notE)\n  unfolding vwa_put_def swa_put_def valRel_WordArrayWord valRel_records\n  apply (clarsimp split: if_splits simp: Let_def ucast_id valRel_records)\n  by (metis (no_types, hide_lams) nth_list_update_eq nth_list_update_neq)\n\n\nlemma wordarray_get_opt_u8_scorres:\n  \"\\<xi> ''wordarray_get_opt'' =  vwa_get_opt \n    \\<Longrightarrow> scorres (wordarray_get_opt :: (8 word WordArray, 32 word) WordArrayGetOP \\<Rightarrow> (unit, 8 word) Opt) (AFun ''wordarray_get_opt'' ts []) \\<gamma> \\<xi>\"\n  apply (clarsimp simp: scorres_def)\n  apply (erule v_sem_afunE; clarsimp)\n  apply (erule notE)\n  unfolding vwa_get_opt_def swa_get_opt_def valRel_WordArrayWord valRel_records\n  apply (clarsimp split: if_splits simp: Let_def ucast_id valRel_records)\n  done\n\nlemma wordarray_get_opt_u16_scorres:\n  \"\\<xi> ''wordarray_get_opt'' =  vwa_get_opt \n    \\<Longrightarrow> scorres (wordarray_get_opt :: (16 word WordArray, 32 word) WordArrayGetOP \\<Rightarrow> (unit, 16 word) Opt) (AFun ''wordarray_get_opt'' ts []) \\<gamma> \\<xi>\"\n  apply (clarsimp simp: scorres_def)\n  apply (erule v_sem_afunE; clarsimp)\n  apply (erule notE)\n  unfolding vwa_get_opt_def swa_get_opt_def valRel_WordArrayWord valRel_records\n  apply (clarsimp split: if_splits simp: Let_def ucast_id valRel_records)\n  done\n\nlemma wordarray_get_opt_u32_scorres:\n  \"\\<xi> ''wordarray_get_opt'' =  vwa_get_opt \n    \\<Longrightarrow> scorres (wordarray_get_opt :: (32 word WordArray, 32 word) WordArrayGetOP \\<Rightarrow> (unit, 32 word) Opt) (AFun ''wordarray_get_opt'' ts []) \\<gamma> \\<xi>\"\n  apply (clarsimp simp: scorres_def)\n  apply (erule v_sem_afunE; clarsimp)\n  apply (erule notE)\n  unfolding vwa_get_opt_def swa_get_opt_def valRel_WordArrayWord valRel_records\n  apply (clarsimp split: if_splits simp: Let_def ucast_id valRel_records)\n  done\n\nlemma wordarray_get_opt_u64_scorres:\n  \"\\<xi> ''wordarray_get_opt'' =  vwa_get_opt \n    \\<Longrightarrow> scorres (wordarray_get_opt :: (64 word WordArray, 32 word) WordArrayGetOP \\<Rightarrow> (unit, 64 word) Opt) (AFun ''wordarray_get_opt'' ts []) \\<gamma> \\<xi>\"\n  apply (clarsimp simp: scorres_def)\n  apply (erule v_sem_afunE; clarsimp)\n  apply (erule notE)\n  unfolding vwa_get_opt_def swa_get_opt_def valRel_WordArrayWord valRel_records\n  apply (clarsimp split: if_splits simp: Let_def ucast_id valRel_records)\n  done\n\nend (* of context *)\n\nend", "meta": {"author": "zilinc", "repo": "popl23-artefact", "sha": "1fe1490d2d34f93dc01ada940c160477db3b9b72", "save_path": "github-repos/isabelle/zilinc-popl23-artefact", "path": "github-repos/isabelle/zilinc-popl23-artefact/popl23-artefact-1fe1490d2d34f93dc01ada940c160477db3b9b72/arrays/loops/WordArrayScorres.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5506073655352403, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.27745444903196853}}
{"text": "(*  Title:      ZF/Induct/Datatypes.thy\n    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory\n    Copyright   1994  University of Cambridge\n*)\n\nsection \\<open>Sample datatype definitions\\<close>\n\ntheory Datatypes imports Main begin\n\nsubsection \\<open>A type with four constructors\\<close>\n\ntext \\<open>\n  It has four contructors, of arities 0--3, and two parameters \\<open>A\\<close> and \\<open>B\\<close>.\n\\<close>\n\nconsts\n  data :: \"[i, i] => i\"\n\ndatatype \"data(A, B)\" =\n    Con0\n  | Con1 (\"a \\<in> A\")\n  | Con2 (\"a \\<in> A\", \"b \\<in> B\")\n  | Con3 (\"a \\<in> A\", \"b \\<in> B\", \"d \\<in> data(A, B)\")\n\nlemma data_unfold: \"data(A, B) = ({0} + A) + (A \\<times> B + A \\<times> B \\<times> data(A, B))\"\n  by (fast intro!: data.intros [unfolded data.con_defs]\n    elim: data.cases [unfolded data.con_defs])\n\ntext \\<open>\n  \\medskip Lemmas to justify using @{term data} in other recursive\n  type definitions.\n\\<close>\n\nlemma data_mono: \"[| A \\<subseteq> C; B \\<subseteq> D |] ==> data(A, B) \\<subseteq> data(C, D)\"\n  apply (unfold data.defs)\n  apply (rule lfp_mono)\n   apply (rule data.bnd_mono)+\n  apply (rule univ_mono Un_mono basic_monos | assumption)+\n  done\n\nlemma data_univ: \"data(univ(A), univ(A)) \\<subseteq> univ(A)\"\n  apply (unfold data.defs data.con_defs)\n  apply (rule lfp_lowerbound)\n   apply (rule_tac [2] subset_trans [OF A_subset_univ Un_upper1, THEN univ_mono])\n  apply (fast intro!: zero_in_univ Inl_in_univ Inr_in_univ Pair_in_univ)\n  done\n\nlemma data_subset_univ:\n    \"[| A \\<subseteq> univ(C); B \\<subseteq> univ(C) |] ==> data(A, B) \\<subseteq> univ(C)\"\n  by (rule subset_trans [OF data_mono data_univ])\n\n\nsubsection \\<open>Example of a big enumeration type\\<close>\n\ntext \\<open>\n  Can go up to at least 100 constructors, but it takes nearly 7\n  minutes \\dots\\ (back in 1994 that is).\n\\<close>\n\nconsts\n  enum :: i\n\ndatatype enum =\n    C00 | C01 | C02 | C03 | C04 | C05 | C06 | C07 | C08 | C09\n  | C10 | C11 | C12 | C13 | C14 | C15 | C16 | C17 | C18 | C19\n  | C20 | C21 | C22 | C23 | C24 | C25 | C26 | C27 | C28 | C29\n  | C30 | C31 | C32 | C33 | C34 | C35 | C36 | C37 | C38 | C39\n  | C40 | C41 | C42 | C43 | C44 | C45 | C46 | C47 | C48 | C49\n  | C50 | C51 | C52 | C53 | C54 | C55 | C56 | C57 | C58 | C59\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/ZF/Induct/Datatypes.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6224593452091673, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.27732402265207723}}
{"text": "(* @LICENSE(NICTA_CORE) *)\n\n(*  Author:     Rafal Kolanski, NICTA & UNSW \n\n    Machine setup for 32-bit little-endian ARM.\n\n    Machines should export the types:\n    * machine_word \n    * virtual/physical address width types: paddr_word, vaddr_word\n\n    Machines should export the functions:\n    * machine_w2b - transform words to bytes (of size \\<le> machine_word)\n    * machine_b2w - transform bytes to words (of size \\<le> machine_word)\n\n    FIXME: these can be derived if we know paddr_word, vaddr_word\n    * address types: vaddr, paddr\n    * memory_size - size of physical memory address space in bytes\n    * addr_space_size - size of virtual memory address space in bytes\n\n    Understanding is: a virtual pointer carrying a virtual address resolves to\n    a physical address; the smallest granularity of memory is a byte.\n*)\n\ntheory MachineARM\nimports Pointers Word_Lib.Word_Lib\nbegin\n\ntext \\<open>Address types\\<close>\n\ntype_synonym machine_word = \"32 word\"\ntype_synonym vaddr_word = \"32 word\"\ntype_synonym paddr_word = \"32 word\"\n\ntype_synonym vaddr = \"(vaddr_word,virtual) addr_t\"\ntype_synonym paddr = \"(paddr_word,physical) addr_t\"\n\ntranslations\n  (type) \"paddr\" <=(type) \"(32 word,physical) addr_t\"\n  (type) \"vaddr\" <=(type) \"(32 word,virtual) addr_t\"\n  (*XXX: these can be derived, but you'd have to expand vaddr_word etc.*)\n\ntext \\<open>Memory size\\<close>\n\ndefinition\n  memory_size :: nat where\n  \"memory_size \\<equiv> 2 ^ size (addr_val(undefined::paddr))\"\ndefinition\n  addr_space_size :: nat where\n  \"addr_space_size \\<equiv> 2 ^ size (addr_val(undefined::vaddr))\"\n\n(*XXX: not derivable*)\nlemma memory_size: \"memory_size = 2 ^ 32\" (*XXX: used to be [simp]*)\n  by (simp add: memory_size_def word_size)\nlemma addr_space_size: \"addr_space_size = 2 ^ 32\" (*XXX: used to be [simp]*)\n  by (simp add: addr_space_size_def word_size)\n\ntext \\<open>Endianness setup\\<close>\n\ndefinition\n  machine_w2b :: \"'a::len0 word \\<Rightarrow> 8 word list\" where\n  \"machine_w2b \\<equiv> rev \\<circ> word_rsplit\"\n\ndefinition\n  machine_b2w :: \"8 word list => 'b :: len0 word\" where\n  \"machine_b2w \\<equiv> word_rcat \\<circ> rev\"\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "tlb", "sha": "88bb017dd96c3830baed93ba62e45b45050d1417", "save_path": "github-repos/isabelle/SEL4PROJ-tlb", "path": "github-repos/isabelle/SEL4PROJ-tlb/tlb-88bb017dd96c3830baed93ba62e45b45050d1417/Page_Tables/MachineARM.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6224593452091673, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.27732402265207723}}
{"text": "(*  Title:      Jinja/Compiler/Compiler.thy\n\n    Author:     Tobias Nipkow\n    Copyright   TUM 2003\n*)\n\nheader {* \\isaheader{Combining Stages 1 and 2} *}\n\ntheory Compiler\nimports Correctness1 Correctness2\nbegin\n\ndefinition J2JVM :: \"J_prog \\<Rightarrow> jvm_prog\"\nwhere \n  \"J2JVM  \\<equiv>  compP\\<^sub>2 \\<circ> compP\\<^sub>1\"\n\ntheorem comp_correct:\nassumes wwf: \"wwf_J_prog P\"\nand method: \"P \\<turnstile> C sees M:Ts\\<rightarrow>T = (pns,body) in C\"\nand eval: \"P \\<turnstile> \\<langle>body,(h,[this#pns [\\<mapsto>] vs])\\<rangle> \\<Rightarrow> \\<langle>e',(h',l')\\<rangle>\"\nand sizes: \"size vs = size pns + 1\"    \"size rest = max_vars body\"\nshows \"J2JVM P \\<turnstile> (None,h,[([],vs@rest,C,M,0)]) -jvm\\<rightarrow> (exception e',h',[])\"\n(*<*)\nproof -\n  let ?P\\<^sub>1 = \"compP\\<^sub>1 P\"\n  have fv: \"fv body \\<subseteq> set (this#pns)\"\n    using wwf method by(auto dest!:sees_wf_mdecl simp:wf_mdecl_def)\n  have init: \"[this#pns [\\<mapsto>] vs] \\<subseteq>\\<^sub>m [this#pns [\\<mapsto>] vs@rest]\"\n    using sizes by simp\n  have \"?P\\<^sub>1 \\<turnstile> C sees M: Ts\\<rightarrow>T = (compE\\<^sub>1 (this#pns) body) in C\"\n    using sees_method_compP[OF method, of \"\\<lambda>(pns,e). compE\\<^sub>1 (this#pns) e\"]\n    by(simp)\n  moreover obtain ls' where\n    \"?P\\<^sub>1 \\<turnstile>\\<^sub>1 \\<langle>compE\\<^sub>1 (this#pns) body, (h, vs@rest)\\<rangle> \\<Rightarrow> \\<langle>fin\\<^sub>1 e', (h',ls')\\<rangle>\"\n    using eval\\<^sub>1_eval[OF wwf eval fv init] sizes by auto\n  ultimately show ?thesis using comp\\<^sub>2_correct eval_final[OF eval]\n    by(fastforce simp add:J2JVM_def final_def)\nqed\n(*>*)\n\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Jinja/Compiler/Compiler.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331462646254, "lm_q2_score": 0.4649015713733885, "lm_q1q2_score": 0.27728270691759843}}
{"text": "(*  Title:      HOL/Statespace/StateFun.thy\n    Author:     Norbert Schirmer, TU Muenchen\n*)\n\nsection \\<open>State Space Representation as Function \\label{sec:StateFun}\\<close>\n\ntheory StateFun imports DistinctTreeProver\nbegin\n\n\ntext \\<open>The state space is represented as a function from names to\nvalues. We neither fix the type of names nor the type of values. We\ndefine lookup and update functions and provide simprocs that simplify\nexpressions containing these, similar to HOL-records.\n\nThe lookup and update function get constructor/destructor functions as\nparameters. These are used to embed various HOL-types into the\nabstract value type. Conceptually the abstract value type is a sum of\nall types that we attempt to store in the state space.\n\nThe update is actually generalized to a map function. The map supplies\nbetter compositionality, especially if you think of nested state\nspaces.\\<close>\n\ndefinition K_statefun :: \"'a \\<Rightarrow> 'b \\<Rightarrow> 'a\" where \"K_statefun c x \\<equiv> c\"\n\nlemma K_statefun_apply [simp]: \"K_statefun c x = c\"\n  by (simp add: K_statefun_def)\n\nlemma K_statefun_comp [simp]: \"(K_statefun c \\<circ> f) = K_statefun c\"\n  by (rule ext) (simp add: comp_def)\n\nlemma K_statefun_cong [cong]: \"K_statefun c x = K_statefun c x\"\n  by (rule refl)\n\ndefinition lookup :: \"('v \\<Rightarrow> 'a) \\<Rightarrow> 'n \\<Rightarrow> ('n \\<Rightarrow> 'v) \\<Rightarrow> 'a\"\n  where \"lookup destr n s = destr (s n)\"\n\ndefinition update ::\n  \"('v \\<Rightarrow> 'a1) \\<Rightarrow> ('a2 \\<Rightarrow> 'v) \\<Rightarrow> 'n \\<Rightarrow> ('a1 \\<Rightarrow> 'a2) \\<Rightarrow> ('n \\<Rightarrow> 'v) \\<Rightarrow> ('n \\<Rightarrow> 'v)\"\n  where \"update destr constr n f s = s(n := constr (f (destr (s n))))\"\n\nlemma lookup_update_same:\n  \"(\\<And>v. destr (constr v) = v) \\<Longrightarrow> lookup destr n (update destr constr n f s) =\n         f (destr (s n))\"\n  by (simp add: lookup_def update_def)\n\nlemma lookup_update_id_same:\n  \"lookup destr n (update destr' id n (K_statefun (lookup id n s')) s) =\n     lookup destr n s'\"\n  by (simp add: lookup_def update_def)\n\nlemma lookup_update_other:\n  \"n\\<noteq>m \\<Longrightarrow> lookup destr n (update destr' constr m f s) = lookup destr n s\"\n  by (simp add: lookup_def update_def)\n\n\nlemma id_id_cancel: \"id (id x) = x\"\n  by (simp add: id_def)\n\nlemma destr_contstr_comp_id: \"(\\<And>v. destr (constr v) = v) \\<Longrightarrow> destr \\<circ> constr = id\"\n  by (rule ext) simp\n\n\n\nlemma block_conj_cong: \"(P \\<and> Q) = (P \\<and> Q)\"\n  by simp\n\nlemma conj1_False: \"P \\<equiv> False \\<Longrightarrow> (P \\<and> Q) \\<equiv> False\"\n  by simp\n\nlemma conj2_False: \"Q \\<equiv> False \\<Longrightarrow> (P \\<and> Q) \\<equiv> False\"\n  by simp\n\nlemma conj_True: \"P \\<equiv> True \\<Longrightarrow> Q \\<equiv> True \\<Longrightarrow> (P \\<and> Q) \\<equiv> True\"\n  by simp\n\nlemma conj_cong: \"P \\<equiv> P' \\<Longrightarrow> Q \\<equiv> Q' \\<Longrightarrow> (P \\<and> Q) \\<equiv> (P' \\<and> Q')\"\n  by simp\n\n\nlemma update_apply: \"(update destr constr n f s x) =\n     (if x=n then constr (f (destr (s n))) else s x)\"\n  by (simp add: update_def)\n\nlemma ex_id: \"\\<exists>x. id x = y\"\n  by (simp add: id_def)\n\nlemma swap_ex_eq:\n  \"\\<exists>s. f s = x \\<equiv> True \\<Longrightarrow>\n   \\<exists>s. x = f s \\<equiv> True\"\n  apply (rule eq_reflection)\n  apply auto\n  done\n\nlemmas meta_ext = eq_reflection [OF ext]\n\n(* This lemma only works if the store is welltyped:\n    \"\\<exists>x.  s ''n'' = (c x)\"\n   or in general when c (d x) = x,\n     (for example: c=id and d=id)\n *)\nlemma \"update d c n (K_statespace (lookup d n s)) s = s\"\n  apply (simp add: update_def lookup_def)\n  apply (rule ext)\n  apply simp\n  oops\n\nend\n", "meta": {"author": "xqyww123", "repo": "phi-system", "sha": "c8dca186bcc8ac2c9b38d813fc0f0dfec486ebab", "save_path": "github-repos/isabelle/xqyww123-phi-system", "path": "github-repos/isabelle/xqyww123-phi-system/phi-system-c8dca186bcc8ac2c9b38d813fc0f0dfec486ebab/Phi_Semantics_Framework/Statespace/StateFun.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331462646254, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.2772827069175984}}
{"text": "(*  Title:      Stateful_Typing.thy\n    Author:     Andreas Viktor Hess, DTU\n    SPDX-License-Identifier: BSD-3-Clause\n*)\n\nsection \\<open>Extending the Typing Result to Stateful Constraints\\<close>\n\ntheory Stateful_Typing\nimports Typing_Result Stateful_Strands\nbegin\n\ntext \\<open>Locale setup\\<close>\nlocale stateful_typed_model = typed_model arity public Ana \\<Gamma>\n  for arity::\"'fun \\<Rightarrow> nat\"\n    and public::\"'fun \\<Rightarrow> bool\"\n    and Ana::\"('fun,'var) term \\<Rightarrow> (('fun,'var) term list \\<times> ('fun,'var) term list)\"\n    and \\<Gamma>::\"('fun,'var) term \\<Rightarrow> ('fun,'atom::finite) term_type\"\n  +\n  fixes Pair::\"'fun\"\n  assumes Pair_arity: \"arity Pair = 2\"\n  and Ana_subst': \"\\<And>f T \\<delta> K M. Ana (Fun f T) = (K,M) \\<Longrightarrow> Ana (Fun f T \\<cdot> \\<delta>) = (K \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta>,M \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta>)\"\nbegin\n\nlemma Ana_invar_subst'[simp]: \"Ana_invar_subst \\<S>\"\nusing Ana_subst' unfolding Ana_invar_subst_def by force\n\ndefinition pair where\n  \"pair d \\<equiv> case d of (t,t') \\<Rightarrow> Fun Pair [t,t']\"\n\nfun tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s::\n  \"(('fun,'var) term \\<times> ('fun,'var) term) list \\<Rightarrow>\n   ('fun,'var) dbstatelist \\<Rightarrow>\n   (('fun,'var) term \\<times> ('fun,'var) term) list list\"\nwhere\n  \"tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s [] D = [[]]\"\n| \"tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ((s,t)#F) D =\n    concat (map (\\<lambda>d. map ((#) (pair (s,t), pair d)) (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F D)) D)\"\n\ntext \\<open>\n  A translation/reduction \\<open>tr\\<close> from stateful constraints to (lists of) \"non-stateful\" constraints.\n  The output represents a finite disjunction of constraints whose models constitute exactly the\n  models of the input constraint. The typing result for \"non-stateful\" constraints is later lifted\n  to the stateful setting through this reduction procedure.\n\\<close>\nfun tr::\"('fun,'var) stateful_strand \\<Rightarrow> ('fun,'var) dbstatelist \\<Rightarrow> ('fun,'var) strand list\"\nwhere\n  \"tr [] D = [[]]\"\n| \"tr (send\\<langle>ts\\<rangle>#A) D = map ((#) (send\\<langle>ts\\<rangle>\\<^sub>s\\<^sub>t)) (tr A D)\"\n| \"tr (receive\\<langle>ts\\<rangle>#A) D = map ((#) (receive\\<langle>ts\\<rangle>\\<^sub>s\\<^sub>t)) (tr A D)\"\n| \"tr (\\<langle>ac: t \\<doteq> t'\\<rangle>#A) D = map ((#) (\\<langle>ac: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t)) (tr A D)\"\n| \"tr (insert\\<langle>t,s\\<rangle>#A) D = tr A (List.insert (t,s) D)\"\n| \"tr (delete\\<langle>t,s\\<rangle>#A) D =\n    concat (map (\\<lambda>Di. map (\\<lambda>B. (map (\\<lambda>d. \\<langle>check: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t) Di)@\n                               (map (\\<lambda>d. \\<forall>[]\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) [d\\<leftarrow>D. d \\<notin> set Di])@B)\n                          (tr A [d\\<leftarrow>D. d \\<notin> set Di]))\n                (subseqs D))\"\n| \"tr (\\<langle>ac: t \\<in> s\\<rangle>#A) D =\n    concat (map (\\<lambda>B. map (\\<lambda>d. \\<langle>ac: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t#B) D) (tr A D))\"\n| \"tr (\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: F'\\<rangle>#A) D =\n    map ((@) (map (\\<lambda>G. \\<forall>X\\<langle>\\<or>\\<noteq>: (F@G)\\<rangle>\\<^sub>s\\<^sub>t) (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' D))) (tr A D)\"\n\ntext \\<open>Type-flaw resistance of stateful constraint steps\\<close>\nfun tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p where\n  \"tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Equality _ t t') = ((\\<exists>\\<delta>. Unifier \\<delta> t t') \\<longrightarrow> \\<Gamma> t = \\<Gamma> t')\"\n| \"tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (NegChecks X F F') = (\n    (F' = [] \\<and> (\\<forall>x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F-set X. \\<exists>a. \\<Gamma> (Var x) = TAtom a)) \\<or>\n    (\\<forall>f T. Fun f T \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> pair ` set F') \\<longrightarrow>\n              T = [] \\<or> (\\<exists>s \\<in> set T. s \\<notin> Var ` set X)))\"\n| \"tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p _ = True\"\n\ntext \\<open>Type-flaw resistance of stateful constraints\\<close>\ndefinition tfr\\<^sub>s\\<^sub>s\\<^sub>t where \"tfr\\<^sub>s\\<^sub>s\\<^sub>t S \\<equiv> tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t S \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S) \\<and> list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p S\"\n\n\n\nsubsection \\<open>Minor Lemmata\\<close>\nlemma pair_in_pair_image_iff:\n  \"pair (s,t) \\<in> pair ` P \\<longleftrightarrow> (s,t) \\<in> P\"\nunfolding pair_def by fast\n\nlemma subst_apply_pairs_pair_image_subst:\n  \"pair ` set (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<theta>) = pair ` set F \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\"\nunfolding subst_apply_pairs_def pair_def by (induct F) auto\n\nlemma Ana_subst_subterms_cases:\n  fixes \\<theta>::\"('fun,'var) subst\"\n  assumes t: \"t \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\"\n    and s: \"s \\<in> set (snd (Ana t))\"\n  shows \"(\\<exists>u \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t M. t = u \\<cdot> \\<theta> \\<and> s \\<in> set (snd (Ana u)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>) \\<or> (\\<exists>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t M. t \\<sqsubseteq> \\<theta> x)\"\nproof (cases \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\")\n  case True\n  then obtain u where u: \"u \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t M\" \"t = u \\<cdot> \\<theta>\" by moura\n  show ?thesis\n  proof (cases u)\n    case (Var x)\n    hence \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t M\" using fv_subset_subterms[OF u(1)] by simp\n    thus ?thesis using u(2) Var by fastforce\n  next\n    case (Fun f T)\n    hence \"set (snd (Ana t)) = set (snd (Ana u)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\"\n      using Ana_subst'[of f T _ _ \\<theta>] u(2) by (cases \"Ana u\") auto\n    thus ?thesis using s u by blast\n  qed\nqed (use s t subterms\\<^sub>s\\<^sub>e\\<^sub>t_subst in blast)\n\nlemma Ana_snd_subst_nth_inv:\n  fixes \\<theta>::\"('fun,'var) subst\" and f ts\n  defines \"R \\<equiv> snd (Ana (Fun f ts \\<cdot> \\<theta>))\"\n  assumes r: \"r = R ! i\" \"i < length R\"\n  shows \"r = snd (Ana (Fun f ts)) ! i \\<cdot> \\<theta>\"\nproof -\n  obtain K R where \"Ana (Fun f ts) = (K,R)\" by (metis surj_pair)\n  thus ?thesis using Ana_subst'[of f ts K R \\<theta>] r unfolding R_def by auto\nqed\n\nlemma Ana_snd_subst_inv:\n  fixes \\<theta>::\"('fun,'var) subst\"\n  assumes r: \"r \\<in> set (snd (Ana (Fun f ts \\<cdot> \\<theta>)))\"\n  shows \"\\<exists>t \\<in> set (snd (Ana (Fun f ts))). r = t \\<cdot> \\<theta>\"\nproof -\n  obtain K R where \"Ana (Fun f ts) = (K,R)\" by (metis surj_pair)\n  thus ?thesis using Ana_subst'[of f ts K R \\<theta>] r by auto\nqed\n\n\nlemma fun_pair_eq[dest]: \"pair d = pair d' \\<Longrightarrow> d = d'\"\nproof -\n  obtain t s t' s' where \"d = (t,s)\" \"d' = (t',s')\" by moura\n  thus \"pair d = pair d' \\<Longrightarrow> d = d'\" unfolding pair_def by simp\nqed\n\nlemma fun_pair_subst: \"pair d \\<cdot> \\<delta> = pair (d \\<cdot>\\<^sub>p \\<delta>)\"\nusing surj_pair[of d] unfolding pair_def by force  \n\nlemma fun_pair_subst_set: \"pair ` M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta> = pair ` (M \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>)\"\nproof\n  show \"pair ` M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta> \\<subseteq> pair ` (M \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>)\"\n    using fun_pair_subst[of _ \\<delta>] by fastforce\n\n  show \"pair ` (M \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>) \\<subseteq> pair ` M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>\"\n  proof\n    fix t assume t: \"t \\<in> pair ` (M \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>)\"\n    then obtain p where p: \"p \\<in> M\" \"t = pair (p \\<cdot>\\<^sub>p \\<delta>)\" by blast\n    thus \"t \\<in> pair ` M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>\" using fun_pair_subst[of p \\<delta>] by force\n  qed\nqed\n\nlemma fun_pair_eq_subst: \"pair d \\<cdot> \\<delta> = pair d' \\<cdot> \\<theta> \\<longleftrightarrow> d \\<cdot>\\<^sub>p \\<delta> = d' \\<cdot>\\<^sub>p \\<theta>\"\nby (metis fun_pair_subst fun_pair_eq[of \"d \\<cdot>\\<^sub>p \\<delta>\" \"d' \\<cdot>\\<^sub>p \\<theta>\"])\n\nlemma setops\\<^sub>s\\<^sub>s\\<^sub>t_pair_image_cons[simp]:\n  \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (x#S) = pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S\"\n  \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (send\\<langle>ts\\<rangle>#S) = pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S\"\n  \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (receive\\<langle>ts\\<rangle>#S) = pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S\"\n  \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (\\<langle>ac: t \\<doteq> t'\\<rangle>#S) = pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S\"\n  \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (insert\\<langle>t,s\\<rangle>#S) = {pair (t,s)} \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S\"\n  \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (delete\\<langle>t,s\\<rangle>#S) = {pair (t,s)} \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S\"\n  \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (\\<langle>ac: t \\<in> s\\<rangle>#S) = {pair (t,s)} \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S\"\n  \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: G\\<rangle>#S) = pair ` set G \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S\"\nunfolding setops\\<^sub>s\\<^sub>s\\<^sub>t_def by auto\n\nlemma setops\\<^sub>s\\<^sub>s\\<^sub>t_pair_image_subst_cons[simp]:\n  \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (x#S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>) = pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (x \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n  \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (send\\<langle>ts\\<rangle>#S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>) = pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n  \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (receive\\<langle>ts\\<rangle>#S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>) = pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n  \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (\\<langle>ac: t \\<doteq> t'\\<rangle>#S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>) = pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n  \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (insert\\<langle>t,s\\<rangle>#S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>) = {pair (t,s) \\<cdot> \\<theta>} \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n  \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (delete\\<langle>t,s\\<rangle>#S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>) = {pair (t,s) \\<cdot> \\<theta>} \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n  \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (\\<langle>ac: t \\<in> s\\<rangle>#S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>) = {pair (t,s) \\<cdot> \\<theta>} \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n  \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: G\\<rangle>#S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>) =\n    pair ` set (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<theta>) \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\nusing subst_sst_cons[of _ S \\<theta>] unfolding setops\\<^sub>s\\<^sub>s\\<^sub>t_def pair_def by auto\n\nlemma setops\\<^sub>s\\<^sub>s\\<^sub>t_are_pairs: \"t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A \\<Longrightarrow> \\<exists>s s'. t = pair (s,s')\"\nproof (induction A)\n  case (Cons a A) thus ?case\n    by (cases a) (auto simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\nqed (simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma fun_pair_wf\\<^sub>t\\<^sub>r\\<^sub>m: \"wf\\<^sub>t\\<^sub>r\\<^sub>m t \\<Longrightarrow> wf\\<^sub>t\\<^sub>r\\<^sub>m t' \\<Longrightarrow> wf\\<^sub>t\\<^sub>r\\<^sub>m (pair (t,t'))\"\nusing Pair_arity unfolding wf\\<^sub>t\\<^sub>r\\<^sub>m_def pair_def by auto\n\nlemma wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s_pairs: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F) \\<Longrightarrow> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (pair ` set F)\"\nusing fun_pair_wf\\<^sub>t\\<^sub>r\\<^sub>m by blast\n\nlemma wf_fun_pair_ineqs_map:\n  assumes \"wf\\<^sub>s\\<^sub>t X A\"\n  shows \"wf\\<^sub>s\\<^sub>t X (map (\\<lambda>d. \\<forall>Y\\<langle>\\<or>\\<noteq>: [(pair (t, s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) D@A)\"\nusing assms by (induct D) auto\n\nlemma wf_fun_pair_negchecks_map:\n  assumes \"wf\\<^sub>s\\<^sub>t X A\"\n  shows \"wf\\<^sub>s\\<^sub>t X (map (\\<lambda>G. \\<forall>Y\\<langle>\\<or>\\<noteq>: (F@G)\\<rangle>\\<^sub>s\\<^sub>t) M@A)\"\nusing assms by (induct M) auto\n\nlemma wf_fun_pair_eqs_ineqs_map:\n  fixes A::\"('fun,'var) strand\"\n  assumes \"wf\\<^sub>s\\<^sub>t X A\" \"Di \\<in> set (subseqs D)\" \"\\<forall>(t,t') \\<in> set D. fv t \\<union> fv t' \\<subseteq> X\"\n  shows \"wf\\<^sub>s\\<^sub>t X ((map (\\<lambda>d. \\<langle>check: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t) Di)@\n                 (map (\\<lambda>d. \\<forall>[]\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) [d\\<leftarrow>D. d \\<notin> set Di])@A)\"\nproof -\n  let ?c1 = \"map (\\<lambda>d. \\<langle>check: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t) Di\"\n  let ?c2 = \"map (\\<lambda>d. \\<forall>[]\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) [d\\<leftarrow>D. d \\<notin> set Di]\"\n  have 1: \"wf\\<^sub>s\\<^sub>t X (?c2@A)\" using wf_fun_pair_ineqs_map[OF assms(1)] by simp\n  have 2: \"\\<forall>(t,t') \\<in> set Di. fv t \\<union> fv t' \\<subseteq> X\" \n    using assms(2,3) by (meson contra_subsetD subseqs_set_subset(1))\n  have \"wf\\<^sub>s\\<^sub>t X (?c1@B)\" when \"wf\\<^sub>s\\<^sub>t X B\" for B::\"('fun,'var) strand\"\n    using 2 that by (induct Di) auto\n  thus ?thesis using 1 by simp\nqed\n\nlemma trms\\<^sub>s\\<^sub>s\\<^sub>t_wt_subst_ex:\n  assumes \\<theta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n    and t: \"t \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n  shows \"\\<exists>s \\<delta>. s \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t S \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> t = s \\<cdot> \\<delta>\"\nusing t\nproof (induction S)\n  case (Cons s S) thus ?case\n  proof (cases \"t \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\")\n    case False\n    hence \"t \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (s \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\"\n      using Cons.prems trms\\<^sub>s\\<^sub>s\\<^sub>t_subst_cons[of s S \\<theta>]\n      by auto\n    then obtain u where u: \"u \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p s\" \"t = u \\<cdot> rm_vars (set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p s)) \\<theta>\"\n      using trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst'' by blast\n    thus ?thesis\n      using trms\\<^sub>s\\<^sub>s\\<^sub>t_subst_cons[of s S \\<theta>]\n            wt_subst_rm_vars[OF \\<theta>(1), of \"set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p s)\"]\n            wf_trms_subst_rm_vars'[OF \\<theta>(2), of \"set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p s)\"]\n      by fastforce\n  qed auto\nqed simp\n\nlemma setops\\<^sub>s\\<^sub>s\\<^sub>t_wt_subst_ex:\n  assumes \\<theta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n    and t: \"t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n  shows \"\\<exists>s \\<delta>. s \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> t = s \\<cdot> \\<delta>\"\nusing t\nproof (induction S)\n  case (Cons x S) thus ?case\n  proof (cases x)\n    case (Insert t' s)\n    hence \"t = pair (t',s) \\<cdot> \\<theta> \\<or> t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n      using Cons.prems subst_sst_cons[of _ S \\<theta>]\n      unfolding pair_def by (force simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n    thus ?thesis\n      using Insert Cons.IH \\<theta> by (cases \"t = pair (t', s) \\<cdot> \\<theta>\") (fastforce, auto)\n  next\n    case (Delete t' s)\n    hence \"t = pair (t',s) \\<cdot> \\<theta> \\<or> t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n      using Cons.prems subst_sst_cons[of _ S \\<theta>]\n      unfolding pair_def by (force simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n    thus ?thesis\n      using Delete Cons.IH \\<theta> by (cases \"t = pair (t', s) \\<cdot> \\<theta>\") (fastforce, auto)\n  next\n    case (InSet ac t' s)\n    hence \"t = pair (t',s) \\<cdot> \\<theta> \\<or> t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n      using Cons.prems subst_sst_cons[of _ S \\<theta>]\n      unfolding pair_def by (force simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n    thus ?thesis\n      using InSet Cons.IH \\<theta> by (cases \"t = pair (t', s) \\<cdot> \\<theta>\") (fastforce, auto)\n  next\n    case (NegChecks X F F')\n    hence \"t \\<in> pair ` set (F' \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<theta>) \\<or> t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n      using Cons.prems subst_sst_cons[of _ S \\<theta>]\n      unfolding pair_def by (force simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n    thus ?thesis\n    proof\n      assume \"t \\<in> pair ` set (F' \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<theta>)\"\n      then obtain s where s: \"t = s \\<cdot> rm_vars (set X) \\<theta>\" \"s \\<in> pair ` set F'\"\n        using subst_apply_pairs_pair_image_subst[of F' \"rm_vars (set X) \\<theta>\"] by auto\n      thus ?thesis\n        using NegChecks setops\\<^sub>s\\<^sub>s\\<^sub>t_pair_image_cons(8)[of X F F' S]\n              wt_subst_rm_vars[OF \\<theta>(1), of \"set X\"]\n              wf_trms_subst_rm_vars'[OF \\<theta>(2), of \"set X\"]\n        by fast\n    qed (use Cons.IH in auto)\n  qed (auto simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def subst_sst_cons[of _ S \\<theta>])\nqed (simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma setops\\<^sub>s\\<^sub>s\\<^sub>t_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s:\n  \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>s\\<^sub>t A) \\<Longrightarrow> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A)\"\n  \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>s\\<^sub>t A) \\<Longrightarrow> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A)\"\nproof -\n  show \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>s\\<^sub>t A) \\<Longrightarrow> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A)\"\n  proof (induction A)\n    case (Cons a A)\n    hence 0: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A)\" by auto\n    thus ?case\n    proof (cases a)\n      case (NegChecks X F F')\n      hence \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F')\" using 0 by simp\n      thus ?thesis using NegChecks wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s_pairs[of F'] 0 by (auto simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n    qed (auto simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def dest: fun_pair_wf\\<^sub>t\\<^sub>r\\<^sub>m)\n  qed (auto simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n  thus \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>s\\<^sub>t A) \\<Longrightarrow> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A)\" by fast\nqed\n\nlemma SMP_MP_split:\n  assumes \"t \\<in> SMP M\"\n    and M: \"\\<forall>m \\<in> M. is_Fun m\"\n  shows \"(\\<exists>\\<delta>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> t \\<in> M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>) \\<or>\n         t \\<in> SMP ((subterms\\<^sub>s\\<^sub>e\\<^sub>t M \\<union> \\<Union>((set \\<circ> fst \\<circ> Ana) ` M)) - M)\"\n  (is \"?P t \\<or> ?Q t\")\nusing assms(1)\nproof (induction t rule: SMP.induct)\n  case (MP t)\n  have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t Var\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range Var)\" \"M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t Var = M\" by simp_all\n  thus ?case using MP by metis\nnext\n  case (Subterm t t')\n  show ?case using Subterm.IH\n  proof\n    assume \"?P t\"\n    then obtain s \\<delta> where s: \"s \\<in> M\" \"t = s \\<cdot> \\<delta>\" and \\<delta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\" by moura\n    then obtain f T where fT: \"s = Fun f T\" using M by fast\n\n    have \"(\\<exists>s'. s' \\<sqsubseteq> s \\<and> t' = s' \\<cdot> \\<delta>) \\<or> (\\<exists>x \\<in> fv s. t' \\<sqsubset> \\<delta> x)\"\n      using subterm_subst_unfold[OF Subterm.hyps(2)[unfolded s(2)]] by blast\n    thus ?thesis\n    proof\n      assume \"\\<exists>s'. s' \\<sqsubseteq> s \\<and> t' = s' \\<cdot> \\<delta>\"\n      then obtain s' where s': \"s' \\<sqsubseteq> s\" \"t' = s' \\<cdot> \\<delta>\" by moura\n      show ?thesis\n      proof (cases \"s' \\<in> M\")\n        case True thus ?thesis using s' \\<delta> by blast\n      next\n        case False\n        hence \"s' \\<in> (subterms\\<^sub>s\\<^sub>e\\<^sub>t M \\<union> \\<Union>((set \\<circ> fst \\<circ> Ana) ` M)) - M\" using s'(1) s(1) by force\n        thus ?thesis using SMP.Substitution[OF SMP.MP[of s'] \\<delta>] s' by presburger\n      qed\n    next\n      assume \"\\<exists>x \\<in> fv s. t' \\<sqsubset> \\<delta> x\"\n      then obtain x where x: \"x \\<in> fv s\" \"t' \\<sqsubset> \\<delta> x\" by moura\n      have \"Var x \\<notin> M\" using M by blast\n      hence \"Var x \\<in> (subterms\\<^sub>s\\<^sub>e\\<^sub>t M \\<union> \\<Union>((set \\<circ> fst \\<circ> Ana) ` M)) - M\"\n        using s(1) var_is_subterm[OF x(1)] by blast\n      hence \"\\<delta> x \\<in> SMP ((subterms\\<^sub>s\\<^sub>e\\<^sub>t M \\<union> \\<Union>((set \\<circ> fst \\<circ> Ana) ` M)) - M)\"\n        using SMP.Substitution[OF SMP.MP[of \"Var x\"] \\<delta>] by auto\n      thus ?thesis using SMP.Subterm x(2) by presburger\n    qed\n  qed (metis SMP.Subterm[OF _ Subterm.hyps(2)])\nnext\n  case (Substitution t \\<delta>)\n  show ?case using Substitution.IH\n  proof\n    assume \"?P t\"\n    then obtain \\<theta> where \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\" \"t \\<in> M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\" by moura\n    hence \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t (\\<theta> \\<circ>\\<^sub>s \\<delta>)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range (\\<theta> \\<circ>\\<^sub>s \\<delta>))\" \"t \\<cdot> \\<delta> \\<in> M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t (\\<theta> \\<circ>\\<^sub>s \\<delta>)\"\n      using wt_subst_compose[of \\<theta>, OF _ Substitution.hyps(2)]\n            wf_trm_subst_compose[of \\<theta> _ \\<delta>, OF _ wf_trm_subst_rangeD[OF Substitution.hyps(3)]]\n            wf_trm_subst_range_iff\n      by (argo, blast, auto)\n    thus ?thesis by blast\n  next\n    assume \"?Q t\" thus ?thesis using SMP.Substitution[OF _ Substitution.hyps(2,3)] by meson\n  qed\nnext\n  case (Ana t K T k)\n  show ?case using Ana.IH\n  proof\n    assume \"?P t\"\n    then obtain \\<theta> where \\<theta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\" \"t \\<in> M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\" by moura\n    then obtain s where s: \"s \\<in> M\" \"t = s \\<cdot> \\<theta>\" by auto\n    then obtain f S where fT: \"s = Fun f S\" using M by (cases s) auto\n    obtain K' T' where s_Ana: \"Ana s = (K', T')\" by (metis surj_pair)\n    hence \"set K = set K' \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\" \"set T = set T' \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\"\n      using Ana_subst'[of f S K' T'] fT Ana.hyps(2) s(2) by auto\n    then obtain k' where k': \"k' \\<in> set K'\" \"k = k' \\<cdot> \\<theta>\" using Ana.hyps(3) by fast\n    show ?thesis\n    proof (cases \"k' \\<in> M\")\n      case True thus ?thesis using k' \\<theta>(1,2) by blast\n    next\n      case False\n      hence \"k' \\<in> (subterms\\<^sub>s\\<^sub>e\\<^sub>t M \\<union> \\<Union>((set \\<circ> fst \\<circ> Ana) ` M)) - M\" using k'(1) s_Ana s(1) by force\n      thus ?thesis using SMP.Substitution[OF SMP.MP[of k'] \\<theta>(1,2)] k'(2) by presburger\n    qed\n  next\n    assume \"?Q t\" thus ?thesis using SMP.Ana[OF _ Ana.hyps(2,3)] by meson\n  qed\nqed\n\nlemma setops_subterm_trms:\n  assumes t: \"t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S\"\n    and s: \"s \\<sqsubset> t\"\n  shows \"s \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t S)\"\nproof -\n  obtain u u' where u: \"pair (u,u') \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S\" \"t = pair (u,u')\"\n    using t setops\\<^sub>s\\<^sub>s\\<^sub>t_are_pairs[of _ S] by blast\n  hence \"s \\<sqsubseteq> u \\<or> s \\<sqsubseteq> u'\" using s unfolding pair_def by auto\n  thus ?thesis using u setops\\<^sub>s\\<^sub>s\\<^sub>t_member_iff[of u u' S] unfolding trms\\<^sub>s\\<^sub>s\\<^sub>t_def by force\nqed\n\nlemma setops_subterms_cases:\n  assumes t: \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S)\"\n  shows \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t S) \\<or> t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S\"\nproof -\n  obtain s s' where s: \"pair (s,s') \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S\" \"t \\<sqsubseteq> pair (s,s')\"\n    using t setops\\<^sub>s\\<^sub>s\\<^sub>t_are_pairs[of _ S] by blast\n  hence \"t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S \\<or> t \\<sqsubseteq> s \\<or> t \\<sqsubseteq> s'\" unfolding pair_def by auto\n  thus ?thesis using s setops\\<^sub>s\\<^sub>s\\<^sub>t_member_iff[of s s' S] unfolding trms\\<^sub>s\\<^sub>s\\<^sub>t_def by force\nqed\n\nlemma setops_SMP_cases:\n  assumes \"t \\<in> SMP (pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S)\"\n    and \"\\<forall>p. Ana (pair p) = ([], [])\"\n  shows \"(\\<exists>\\<delta>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>) \\<or> t \\<in> SMP (trms\\<^sub>s\\<^sub>s\\<^sub>t S)\"\nproof -\n  have 0: \"\\<Union>((set \\<circ> fst \\<circ> Ana) ` pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S) = {}\"\n  proof (induction S)\n    case (Cons x S) thus ?case\n      using assms(2) by (cases x) (auto simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n  qed (simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n  \n  have 1: \"\\<forall>m \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S. is_Fun m\"\n  proof (induction S)\n    case (Cons x S) thus ?case\n      unfolding pair_def by (cases x) (auto simp add: assms(2) setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n  qed (simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\n  have 2:\n      \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S) \\<union>\n       \\<Union>((set \\<circ> fst \\<circ> Ana) ` (pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S)) - pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S\n        \\<subseteq> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t S)\"\n    using 0 setops_subterms_cases by fast\n\n  show ?thesis\n    using SMP_MP_split[OF assms(1) 1] SMP_mono[OF 2] SMP_subterms_eq[of \"trms\\<^sub>s\\<^sub>s\\<^sub>t S\"]\n    by blast\nqed\n\nlemma constraint_model_priv_const_in_constr_prefix:\n  assumes A: \"wf\\<^sub>s\\<^sub>s\\<^sub>t A\"\n    and I: \"I \\<Turnstile>\\<^sub>s A\"\n           \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t I\"\n           \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range I)\"\n           \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t I\"\n    and c: \"\\<not>public c\"\n           \"arity c = 0\"\n           \"Fun c [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t ik\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I\"\n  shows \"Fun c [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t trms\\<^sub>s\\<^sub>s\\<^sub>t A\"\nusing const_subterms_subst_cases[OF c(3)]\nproof\n  assume \"Fun c [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t ik\\<^sub>s\\<^sub>s\\<^sub>t A\" thus ?thesis using ik\\<^sub>s\\<^sub>s\\<^sub>t_trms\\<^sub>s\\<^sub>s\\<^sub>t_subset by blast \nnext\n  assume \"\\<exists>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>s\\<^sub>s\\<^sub>t A). x \\<in> subst_domain I \\<and> Fun c [] \\<sqsubseteq> I x\"\n  then obtain x where x: \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>s\\<^sub>s\\<^sub>t A)\" \"Fun c [] \\<sqsubseteq> I x\" by blast\n  \n  have 0: \"wf\\<^sub>t\\<^sub>r\\<^sub>m (I x)\" \"wf'\\<^sub>s\\<^sub>s\\<^sub>t {} A\" \"Fun c [] \\<cdot> I = Fun c []\"\n    using I A by simp_all\n\n  have 1: \"x \\<in> wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t A\"\n    using x(1) in_ik\\<^sub>s\\<^sub>s\\<^sub>t_iff[of _ A] unfolding wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t_def by force\n  hence 2: \"\\<exists>v \\<in> wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t A. Fun c [] \\<cdot> I \\<sqsubseteq> I v\" using 0(3) x(2) by force\n\n\n  obtain A\\<^sub>p\\<^sub>r\\<^sub>e A\\<^sub>s\\<^sub>u\\<^sub>f where A': \"\\<not>(\\<exists>w \\<in> wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t A\\<^sub>p\\<^sub>r\\<^sub>e. Fun c [] \\<sqsubseteq> I w)\"\n    \"(\\<exists>ts. A = A\\<^sub>p\\<^sub>r\\<^sub>e@send\\<langle>ts\\<rangle>#A\\<^sub>s\\<^sub>u\\<^sub>f \\<and> Fun c [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t set ts \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I) \\<or>\n     (\\<exists>s u. A = A\\<^sub>p\\<^sub>r\\<^sub>e@\\<langle>assign: s \\<doteq> u\\<rangle>#A\\<^sub>s\\<^sub>u\\<^sub>f \\<and> Fun c [] \\<sqsubseteq> s \\<cdot> I \\<and> \\<not>(Fun c [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t (I ` fv u))) \\<or>\n     (\\<exists>s u. A = A\\<^sub>p\\<^sub>r\\<^sub>e@\\<langle>assign: s \\<in> u\\<rangle>#A\\<^sub>s\\<^sub>u\\<^sub>f \\<and> (Fun c [] \\<sqsubseteq> s \\<cdot> I \\<or> Fun c [] \\<sqsubseteq> u \\<cdot> I))\"\n    (is \"?X \\<or> ?Y \\<or> ?Z\")\n    using wf\\<^sub>s\\<^sub>s\\<^sub>t_strand_first_Send_var_split[OF 0(2) 2] by force\n\n  show ?thesis using A'(2)\n  proof (elim disjE)\n    assume ?X\n    then obtain ts where ts: \"A = A\\<^sub>p\\<^sub>r\\<^sub>e@send\\<langle>ts\\<rangle>#A\\<^sub>s\\<^sub>u\\<^sub>f\" \"Fun c [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t set ts \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I\" by blast\n    hence \"I \\<Turnstile>\\<^sub>s (A\\<^sub>p\\<^sub>r\\<^sub>e@[send\\<langle>ts\\<rangle>])\"\n      using I(1) strand_sem_append_stateful[of \"{}\" \"{}\" \"A\\<^sub>p\\<^sub>r\\<^sub>e@[send\\<langle>ts\\<rangle>]\" A\\<^sub>s\\<^sub>u\\<^sub>f I] by auto\n    hence \"(ik\\<^sub>s\\<^sub>s\\<^sub>t A\\<^sub>p\\<^sub>r\\<^sub>e) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I \\<turnstile> t \\<cdot> I\" when \"t \\<in> set ts\" for t\n      using that strand_sem_append_stateful[of \"{}\" \"{}\" A\\<^sub>p\\<^sub>r\\<^sub>e \"[send\\<langle>ts\\<rangle>]\" I]\n            strand_sem_stateful.simps(2)[of _ _ ts \"[]\"]\n      unfolding list_all_iff by force\n    hence \"Fun c [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t ik\\<^sub>s\\<^sub>s\\<^sub>t A\\<^sub>p\\<^sub>r\\<^sub>e \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I\"\n      using ts(2) c(1) private_fun_deduct_in_ik by fast\n    hence \"Fun c [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t ik\\<^sub>s\\<^sub>s\\<^sub>t A\\<^sub>p\\<^sub>r\\<^sub>e\"\n      using A'(1) const_subterms_subst_cases[of c I \"ik\\<^sub>s\\<^sub>s\\<^sub>t A\\<^sub>p\\<^sub>r\\<^sub>e\"]\n            ik\\<^sub>s\\<^sub>s\\<^sub>t_fv_subset_wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t[of A\\<^sub>p\\<^sub>r\\<^sub>e]\n      by fast\n    thus ?thesis\n      using ik\\<^sub>s\\<^sub>s\\<^sub>t_trms\\<^sub>s\\<^sub>s\\<^sub>t_subset[of \"A\\<^sub>p\\<^sub>r\\<^sub>e\"] unfolding ts(1) by fastforce\n  next\n    assume ?Y\n    then obtain s u where su:\n        \"A = A\\<^sub>p\\<^sub>r\\<^sub>e@\\<langle>assign: s \\<doteq> u\\<rangle>#A\\<^sub>s\\<^sub>u\\<^sub>f\" \"Fun c [] \\<sqsubseteq> s \\<cdot> I\" \"\\<not>(Fun c [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t I ` fv u)\"\n      by fast\n    hence \"s \\<cdot> I = u \\<cdot> I\"\n      using I(1) strand_sem_append_stateful[of \"{}\" \"{}\" \"A\\<^sub>p\\<^sub>r\\<^sub>e@[\\<langle>assign: s \\<doteq> u\\<rangle>]\" A\\<^sub>s\\<^sub>u\\<^sub>f I]\n            strand_sem_append_stateful[of _ _ A\\<^sub>p\\<^sub>r\\<^sub>e \"[\\<langle>assign: s \\<doteq> u\\<rangle>]\" I]\n      by auto\n    hence \"Fun c [] \\<sqsubseteq> u\" using su(2,3) const_subterm_subst_var_obtain[of c u I] by auto\n    thus ?thesis unfolding su(1) by auto\n  next\n    assume ?Z\n    then obtain s u where su:\n        \"A = A\\<^sub>p\\<^sub>r\\<^sub>e@\\<langle>assign: s \\<in> u\\<rangle>#A\\<^sub>s\\<^sub>u\\<^sub>f\" \"Fun c [] \\<sqsubseteq> s \\<cdot> I \\<or> Fun c [] \\<sqsubseteq> u \\<cdot> I\"\n      by fast\n    hence \"(s,u) \\<cdot>\\<^sub>p I \\<in> dbupd\\<^sub>s\\<^sub>s\\<^sub>t A\\<^sub>p\\<^sub>r\\<^sub>e I {}\"\n      using I(1) strand_sem_append_stateful[of \"{}\" \"{}\" \"A\\<^sub>p\\<^sub>r\\<^sub>e@[\\<langle>assign: s \\<in> u\\<rangle>]\" A\\<^sub>s\\<^sub>u\\<^sub>f I]\n            strand_sem_append_stateful[of _ _ A\\<^sub>p\\<^sub>r\\<^sub>e \"[\\<langle>assign: s \\<in> u\\<rangle>]\" I]\n      unfolding db\\<^sub>s\\<^sub>s\\<^sub>t_def by auto\n    then obtain s' u' where su': \"insert\\<langle>s',u'\\<rangle> \\<in> set A\\<^sub>p\\<^sub>r\\<^sub>e\" \"s \\<cdot> I = s' \\<cdot> I\" \"u \\<cdot> I = u' \\<cdot> I\"\n      using db\\<^sub>s\\<^sub>s\\<^sub>t_in_cases[of \"s \\<cdot> I\" \"u \\<cdot> I\" A\\<^sub>p\\<^sub>r\\<^sub>e I \"[]\"] db\\<^sub>s\\<^sub>s\\<^sub>t_set_is_dbupd\\<^sub>s\\<^sub>s\\<^sub>t[of A\\<^sub>p\\<^sub>r\\<^sub>e I \"[]\"]\n      by fastforce\n\n    have \"fv s' \\<union> fv u' \\<subseteq> wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t A\\<^sub>p\\<^sub>r\\<^sub>e\"\n      using su'(1) unfolding wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t_def by force\n    hence \"Fun c [] \\<sqsubseteq> s' \\<or> Fun c [] \\<sqsubseteq> u'\"\n      using su(2) A'(1) su'(2,3)\n            const_subterm_subst_cases[of c s' I]\n            const_subterm_subst_cases[of c u' I]\n      by auto\n    thus ?thesis using su'(1) unfolding su(1) by force\n  qed\nqed\n\nlemma tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_empty_case:\n  assumes \"tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F D = []\"\n  shows \"D = []\" \"F \\<noteq> []\"\nproof -\n  show \"F \\<noteq> []\" using assms by (auto intro: ccontr)\n\n  have \"tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F (a#A) \\<noteq> []\" for a A\n    by (induct F \"a#A\" rule: tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s.induct) fastforce+\n  thus \"D = []\" using assms by (cases D) simp_all\nqed\n\nlemma tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_elem_length_eq:\n  assumes \"G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F D)\"\n  shows \"length G = length F\" \nusing assms by (induct F D arbitrary: G rule: tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s.induct) auto\n\nlemma tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_index:\n  assumes \"G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F D)\" \"i < length F\"\n  shows \"\\<exists>d \\<in> set D. G ! i = (pair (F ! i), pair d)\"\nusing assms\nproof (induction F D arbitrary: i G rule: tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s.induct)\n  case (2 s t F D)\n  obtain d G' where G:\n      \"d \\<in> set D\" \"G' \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F D)\"\n      \"G = (pair (s,t), pair d)#G'\"\n    using \"2.prems\"(1) by moura\n  show ?case\n    using \"2.IH\"[OF G(1,2)] \"2.prems\"(2) G(1,3)\n    by (cases i) auto\nqed simp\n\nlemma tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_cons:\n  assumes \"G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F D)\" \"d \\<in> set D\"\n  shows \"(pair (s,t), pair d)#G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ((s,t)#F) D)\"\nusing assms by auto\n\nlemma tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_has_pair_lists:\n  assumes \"G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F D)\" \"g \\<in> set G\"\n  shows \"\\<exists>f \\<in> set F. \\<exists>d \\<in> set D. g = (pair f, pair d)\"\nusing assms\nproof (induction F D arbitrary: G rule: tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s.induct)\n  case (2 s t F D)\n  obtain d G' where G:\n      \"d \\<in> set D\" \"G' \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F D)\"\n      \"G = (pair (s,t), pair d)#G'\"\n    using \"2.prems\"(1) by moura\n  show ?case\n    using \"2.IH\"[OF G(1,2)] \"2.prems\"(2) G(1,3)\n    by (cases \"g \\<in> set G'\") auto\nqed simp\n\nlemma tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_is_pair_lists:\n  assumes \"f \\<in> set F\" \"d \\<in> set D\"\n  shows \"\\<exists>G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F D). (pair f, pair d) \\<in> set G\"\n  (is \"?P F D f d\")\nproof -\n  have \"\\<forall>f \\<in> set F. \\<forall>d \\<in> set D. ?P F D f d\"\n  proof (induction F D rule: tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s.induct)\n    case (2 s t F D)\n    hence IH: \"\\<forall>f \\<in> set F. \\<forall>d \\<in> set D. ?P F D f d\" by metis\n    moreover have \"\\<forall>d \\<in> set D. ?P ((s,t)#F) D (s,t) d\"\n    proof\n      fix d assume d: \"d \\<in> set D\"\n      then obtain G where G: \"G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F D)\"\n        using tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_empty_case(1) by force\n      hence \"(pair (s, t), pair d)#G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ((s,t)#F) D)\"\n        using d by auto\n      thus \"?P ((s,t)#F) D (s,t) d\" using d G by auto\n    qed\n    ultimately show ?case by fastforce\n  qed simp\n  thus ?thesis by (metis assms)\nqed\n\nlemma tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_db_append_subset:\n  \"set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F D) \\<subseteq> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F (D@E))\" (is ?A)\n  \"set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F E) \\<subseteq> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F (D@E))\" (is ?B)\nproof -\n  show ?A\n  proof (induction F D rule: tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s.induct)\n    case (2 s t F D)\n    show ?case\n    proof\n      fix G assume \"G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ((s,t)#F) D)\"\n      then obtain d G' where G':\n          \"d \\<in> set D\" \"G' \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F D)\" \"G = (pair (s,t), pair d)#G'\"\n        by moura\n      have \"d \\<in> set (D@E)\" \"G' \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F (D@E))\" using \"2.IH\"[OF G'(1)] G'(1,2) by auto\n      thus \"G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ((s,t)#F) (D@E))\" using G'(3) by auto\n    qed\n  qed simp\n\n  show ?B\n  proof (induction F E rule: tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s.induct)\n    case (2 s t F E)\n    show ?case\n    proof\n      fix G assume \"G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ((s,t)#F) E)\"\n      then obtain d G' where G':\n          \"d \\<in> set E\" \"G' \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F E)\" \"G = (pair (s,t), pair d)#G'\"\n        by moura\n      have \"d \\<in> set (D@E)\" \"G' \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F (D@E))\" using \"2.IH\"[OF G'(1)] G'(1,2) by auto\n      thus \"G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ((s,t)#F) (D@E))\" using G'(3) by auto\n    qed\n  qed simp\nqed\n\nlemma tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_trms_subset:\n  \"G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F D) \\<Longrightarrow> trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G \\<subseteq> pair ` set F \\<union> pair ` set D\"\nproof (induction F D arbitrary: G rule: tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s.induct)\n  case (2 s t F D G)\n  obtain d G' where G:\n      \"d \\<in> set D\" \"G' \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F D)\" \"G = (pair (s,t), pair d)#G'\"\n    using \"2.prems\"(1) by moura\n \n  show ?case using \"2.IH\"[OF G(1,2)] G(1,3) by auto\nqed simp\n\nlemma tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_trms_subset':\n  \"\\<Union>(trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ` set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F D)) \\<subseteq> pair ` set F \\<union> pair ` set D\"\nusing tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_trms_subset by blast\n\nlemma tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_vars_subset:\n  \"G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F D) \\<Longrightarrow> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G \\<subseteq> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s D\"\nproof (induction F D arbitrary: G rule: tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s.induct)\n  case (2 s t F D G)\n  obtain d G' where G:\n      \"d \\<in> set D\" \"G' \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F D)\" \"G = (pair (s,t), pair d)#G'\"\n    using \"2.prems\"(1) by moura\n \n  show ?case using \"2.IH\"[OF G(1,2)] G(1,3) unfolding pair_def by auto\nqed simp\n\nlemma tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_vars_subset': \"\\<Union>(fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ` set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F D)) \\<subseteq> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s D\"\nusing tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_vars_subset[of _ F D] by blast\n\n\nlemma tr_trms_subset:\n  \"A' \\<in> set (tr A D) \\<Longrightarrow> trms\\<^sub>s\\<^sub>t A' \\<subseteq> trms\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` set D\"\nproof (induction A D arbitrary: A' rule: tr.induct)\n  case 1 thus ?case by simp\nnext\n  case (2 t A D)\n  then obtain A'' where A'': \"A' = send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#A''\" \"A'' \\<in> set (tr A D)\" by moura\n  hence \"trms\\<^sub>s\\<^sub>t A'' \\<subseteq> trms\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` set D\" by (metis \"2.IH\")\n  thus ?case using A'' by (auto simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\nnext\n  case (3 t A D)\n  then obtain A'' where A'': \"A' = receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#A''\" \"A'' \\<in> set (tr A D)\" by moura\n  hence \"trms\\<^sub>s\\<^sub>t A'' \\<subseteq> trms\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` set D\" by (metis \"3.IH\")\n  thus ?case using A'' by (auto simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\nnext\n  case (4 ac t t' A D)\n  then obtain A'' where A'': \"A' = \\<langle>ac: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#A''\" \"A'' \\<in> set (tr A D)\" by moura\n  hence \"trms\\<^sub>s\\<^sub>t A'' \\<subseteq> trms\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` set D\" by (metis \"4.IH\")\n  thus ?case using A'' by (auto simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\nnext\n  case (5 t s A D)\n  hence \"A' \\<in> set (tr A (List.insert (t,s) D))\" by simp\n  hence \"trms\\<^sub>s\\<^sub>t A' \\<subseteq> trms\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` set (List.insert (t, s) D)\"\n    by (metis \"5.IH\")\n  thus ?case by (auto simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\nnext\n  case (6 t s A D)\n  from 6 obtain Di A'' B C where A'':\n      \"Di \\<in> set (subseqs D)\" \"A'' \\<in> set (tr A [d\\<leftarrow>D. d \\<notin> set Di])\" \"A' = (B@C)@A''\"\n      \"B = map (\\<lambda>d. \\<langle>check: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t) Di\"\n      \"C = map (\\<lambda>d. Inequality [] [(pair (t,s) , pair d)]) [d\\<leftarrow>D. d \\<notin> set Di]\"\n    by moura\n  hence \"trms\\<^sub>s\\<^sub>t A'' \\<subseteq> trms\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` set [d\\<leftarrow>D. d \\<notin> set Di]\"\n    by (metis \"6.IH\")\n  hence \"trms\\<^sub>s\\<^sub>t A'' \\<subseteq> trms\\<^sub>s\\<^sub>s\\<^sub>t (Delete t s#A) \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (Delete t s#A) \\<union> pair ` set D\"\n    by (auto simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n  moreover have \"trms\\<^sub>s\\<^sub>t (B@C) \\<subseteq> insert (pair (t,s)) (pair ` set D)\"\n    using A''(4,5) subseqs_set_subset[OF A''(1)] by auto\n  moreover have \"pair (t,s) \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (Delete t s#A)\" by (simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n  ultimately show ?case using A''(3) trms\\<^sub>s\\<^sub>t_append[of \"B@C\" A'] by auto\nnext\n  case (7 ac t s A D)\n  from 7 obtain d A'' where A'':\n      \"d \\<in> set D\" \"A'' \\<in> set (tr A D)\"\n      \"A' = \\<langle>ac: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t#A''\"\n    by moura\n  hence \"trms\\<^sub>s\\<^sub>t A'' \\<subseteq> trms\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` set D\" by (metis \"7.IH\")\n  moreover have \"trms\\<^sub>s\\<^sub>t A' = {pair (t,s), pair d} \\<union> trms\\<^sub>s\\<^sub>t A''\"\n    using A''(1,3) by auto\n  ultimately show ?case using A''(1) by (auto simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\nnext\n  case (8 X F F' A D)\n  from 8 obtain A'' where A'':\n      \"A'' \\<in> set (tr A D)\" \"A' = (map (\\<lambda>G. \\<forall>X\\<langle>\\<or>\\<noteq>: (F@G)\\<rangle>\\<^sub>s\\<^sub>t) (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' D))@A''\"\n    by moura\n\n  define B where \"B \\<equiv> \\<Union>(trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ` set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' D))\"\n\n  have \"trms\\<^sub>s\\<^sub>t A'' \\<subseteq> trms\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` set D\" by (metis A''(1) \"8.IH\")\n  hence \"trms\\<^sub>s\\<^sub>t A' \\<subseteq> B \\<union> trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> trms\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` set D\"\n    using A'' B_def by auto\n  moreover have \"B \\<subseteq> pair ` set F' \\<union> pair ` set D\"\n    using tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_trms_subset'[of F' D] B_def by simp\n  moreover have \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: F'\\<rangle>#A) = pair ` set F' \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A\"\n    by (auto simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n  ultimately show ?case by auto\nqed\n\nlemma tr_vars_subset:\n  assumes \"A' \\<in> set (tr A D)\"\n  shows \"fv\\<^sub>s\\<^sub>t A' \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> (\\<Union>(t,t') \\<in> set D. fv t \\<union> fv t')\" (is ?P)\n  and \"bvars\\<^sub>s\\<^sub>t A' \\<subseteq> bvars\\<^sub>s\\<^sub>s\\<^sub>t A\" (is ?Q)\nproof -\n  show ?P using assms\n  proof (induction A arbitrary: A' D rule: strand_sem_stateful_induct)\n    case (ConsIn A' D ac t s A)\n    then obtain A'' d where *:\n        \"d \\<in> set D\" \"A' = \\<langle>ac: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t#A''\"\n        \"A'' \\<in> set (tr A D)\"\n      by moura\n    hence \"fv\\<^sub>s\\<^sub>t A'' \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> (\\<Union>(t,t')\\<in>set D. fv t \\<union> fv t')\" by (metis ConsIn.IH)\n    thus ?case using * unfolding pair_def by auto\n  next\n    case (ConsDel A' D t s A)\n    define Dfv where \"Dfv \\<equiv> \\<lambda>D::('fun,'var) dbstatelist. (\\<Union>(t,t')\\<in>set D. fv t \\<union> fv t')\"\n    define fltD where \"fltD \\<equiv> \\<lambda>Di. filter (\\<lambda>d. d \\<notin> set Di) D\"\n    define constr where\n      \"constr \\<equiv> \\<lambda>Di. (map (\\<lambda>d. \\<langle>check: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t) Di)@\n                      (map (\\<lambda>d. \\<forall>[]\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) (fltD Di))\"\n    from ConsDel obtain A'' Di where *:\n        \"Di \\<in> set (subseqs D)\" \"A' = (constr Di)@A''\" \"A'' \\<in> set (tr A (fltD Di))\"\n      unfolding constr_def fltD_def by moura\n    hence \"fv\\<^sub>s\\<^sub>t A'' \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> Dfv (fltD Di)\"\n      unfolding Dfv_def constr_def fltD_def by (metis ConsDel.IH)\n    moreover have \"Dfv (fltD Di) \\<subseteq> Dfv D\" unfolding Dfv_def constr_def fltD_def by auto\n    moreover have \"Dfv Di \\<subseteq> Dfv D\"\n      using subseqs_set_subset(1)[OF *(1)] unfolding Dfv_def constr_def fltD_def by fast\n    moreover have \"fv\\<^sub>s\\<^sub>t (constr Di) \\<subseteq> fv t \\<union> fv s \\<union> (Dfv Di \\<union> Dfv (fltD Di))\"\n      unfolding Dfv_def constr_def fltD_def pair_def by auto\n    moreover have \"fv\\<^sub>s\\<^sub>s\\<^sub>t (Delete t s#A) = fv t \\<union> fv s \\<union> fv\\<^sub>s\\<^sub>s\\<^sub>t A\" by auto\n    moreover have \"fv\\<^sub>s\\<^sub>t A' = fv\\<^sub>s\\<^sub>t (constr Di) \\<union> fv\\<^sub>s\\<^sub>t A''\" using * by force\n    ultimately have \"fv\\<^sub>s\\<^sub>t A' \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t (Delete t s#A) \\<union> Dfv D\" by auto\n    thus ?case unfolding Dfv_def fltD_def constr_def by simp\n  next\n    case (ConsNegChecks A' D X F F' A)\n    then obtain A'' where A'':\n        \"A'' \\<in> set (tr A D)\" \"A' = (map (\\<lambda>G. \\<forall>X\\<langle>\\<or>\\<noteq>: (F@G)\\<rangle>\\<^sub>s\\<^sub>t) (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' D))@A''\"\n      by moura\n\n    define B where \"B \\<equiv> \\<Union>(fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ` set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' D))\"\n\n    have 1: \"fv\\<^sub>s\\<^sub>t (map (\\<lambda>G. \\<forall>X\\<langle>\\<or>\\<noteq>: (F@G)\\<rangle>\\<^sub>s\\<^sub>t) (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' D)) \\<subseteq> (B \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F) - set X\"\n      unfolding B_def by auto\n\n    have 2: \"B \\<subseteq> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s D\"\n      using tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_vars_subset'[of F' D]\n      unfolding B_def by simp\n\n    have \"fv\\<^sub>s\\<^sub>t A' \\<subseteq> ((fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s D \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F) - set X) \\<union> fv\\<^sub>s\\<^sub>t A''\"\n      using 1 2 A''(2) by fastforce\n    thus ?case using ConsNegChecks.IH[OF A''(1)] by auto\n  qed fastforce+\n\n  show ?Q using assms by (induct A arbitrary: A' D rule: strand_sem_stateful_induct) fastforce+\nqed\n\nlemma tr_vars_disj:\n  assumes \"A' \\<in> set (tr A D)\" \"\\<forall>(t,t') \\<in> set D. (fv t \\<union> fv t') \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\n    and \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\n  shows \"fv\\<^sub>s\\<^sub>t A' \\<inter> bvars\\<^sub>s\\<^sub>t A' = {}\"\nusing assms tr_vars_subset by fast\n\n\nlemma tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_alt_def:\n  \"list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p S =\n    ((\\<forall>ac t t'. Equality ac t t' \\<in> set S \\<and> (\\<exists>\\<delta>. Unifier \\<delta> t t') \\<longrightarrow> \\<Gamma> t = \\<Gamma> t') \\<and>\n     (\\<forall>X F F'. NegChecks X F F' \\<in> set S \\<longrightarrow> (\n        (F' = [] \\<and> (\\<forall>x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F-set X. \\<exists>a. \\<Gamma> (Var x) = TAtom a)) \\<or>\n        (\\<forall>f T. Fun f T \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> pair ` set F') \\<longrightarrow>\n                  T = [] \\<or> (\\<exists>s \\<in> set T. s \\<notin> Var ` set X)))))\"\n  (is \"?P S = ?Q S\")\nproof\n  show \"?P S \\<Longrightarrow> ?Q S\"\n  proof (induction S)\n    case (Cons x S) thus ?case by (cases x) auto\n  qed simp\n\n  show \"?Q S \\<Longrightarrow> ?P S\"\n  proof (induction S)\n    case (Cons x S) thus ?case by (cases x) auto\n  qed simp\nqed\n\nlemma tfr\\<^sub>s\\<^sub>s\\<^sub>t_Nil[simp]: \"tfr\\<^sub>s\\<^sub>s\\<^sub>t []\"\nby (simp add: tfr\\<^sub>s\\<^sub>s\\<^sub>t_def setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma tfr\\<^sub>s\\<^sub>s\\<^sub>t_append: \"tfr\\<^sub>s\\<^sub>s\\<^sub>t (A@B) \\<Longrightarrow> tfr\\<^sub>s\\<^sub>s\\<^sub>t A\"\nproof -\n  assume assms: \"tfr\\<^sub>s\\<^sub>s\\<^sub>t (A@B)\"\n  let ?M = \"trms\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A\"\n  let ?N = \"trms\\<^sub>s\\<^sub>s\\<^sub>t (A@B) \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (A@B)\"\n  let ?P = \"\\<lambda>t t'. \\<forall>x \\<in> fv t \\<union> fv t'. \\<exists>a. \\<Gamma> (Var x) = Var a\"\n  let ?Q = \"\\<lambda>X t t'. X = [] \\<or> (\\<forall>x \\<in> (fv t \\<union> fv t')-set X. \\<exists>a. \\<Gamma> (Var x) = Var a)\"\n  have *: \"SMP ?M - Var`\\<V> \\<subseteq> SMP ?N - Var`\\<V>\" \"?M \\<subseteq> ?N\"\n    using SMP_mono[of ?M ?N] setops\\<^sub>s\\<^sub>s\\<^sub>t_append[of A B]\n    by auto\n  { fix s t assume **: \"tfr\\<^sub>s\\<^sub>e\\<^sub>t ?N\" \"s \\<in> SMP ?M - Var`\\<V>\" \"t \\<in> SMP ?M - Var`\\<V>\" \"(\\<exists>\\<delta>. Unifier \\<delta> s t)\"\n    hence \"s \\<in> SMP ?N - Var`\\<V>\" \"t \\<in> SMP ?N - Var`\\<V>\" using * by auto\n    hence \"\\<Gamma> s = \\<Gamma> t\" using **(1,4) unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by blast\n  } moreover have \"\\<forall>t \\<in> ?N. wf\\<^sub>t\\<^sub>r\\<^sub>m t \\<Longrightarrow> \\<forall>t \\<in> ?M. wf\\<^sub>t\\<^sub>r\\<^sub>m t\" using * by blast\n  ultimately have \"tfr\\<^sub>s\\<^sub>e\\<^sub>t ?N \\<Longrightarrow> tfr\\<^sub>s\\<^sub>e\\<^sub>t ?M\" unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by blast\n  hence \"tfr\\<^sub>s\\<^sub>e\\<^sub>t ?M\" using assms unfolding tfr\\<^sub>s\\<^sub>s\\<^sub>t_def by metis\n  thus \"tfr\\<^sub>s\\<^sub>s\\<^sub>t A\" using assms unfolding tfr\\<^sub>s\\<^sub>s\\<^sub>t_def by simp\nqed\n\nlemma tfr\\<^sub>s\\<^sub>s\\<^sub>t_append': \"tfr\\<^sub>s\\<^sub>s\\<^sub>t (A@B) \\<Longrightarrow> tfr\\<^sub>s\\<^sub>s\\<^sub>t B\"\nproof -\n  assume assms: \"tfr\\<^sub>s\\<^sub>s\\<^sub>t (A@B)\"\n  let ?M = \"trms\\<^sub>s\\<^sub>s\\<^sub>t B \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t B\"\n  let ?N = \"trms\\<^sub>s\\<^sub>s\\<^sub>t (A@B) \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (A@B)\"\n  let ?P = \"\\<lambda>t t'. \\<forall>x \\<in> fv t \\<union> fv t'. \\<exists>a. \\<Gamma> (Var x) = Var a\"\n  let ?Q = \"\\<lambda>X t t'. X = [] \\<or> (\\<forall>x \\<in> (fv t \\<union> fv t')-set X. \\<exists>a. \\<Gamma> (Var x) = Var a)\"\n  have *: \"SMP ?M - Var`\\<V> \\<subseteq> SMP ?N - Var`\\<V>\" \"?M \\<subseteq> ?N\"\n    using SMP_mono[of ?M ?N] setops\\<^sub>s\\<^sub>s\\<^sub>t_append[of A B]\n    by auto\n  { fix s t assume **: \"tfr\\<^sub>s\\<^sub>e\\<^sub>t ?N\" \"s \\<in> SMP ?M - Var`\\<V>\" \"t \\<in> SMP ?M - Var`\\<V>\" \"(\\<exists>\\<delta>. Unifier \\<delta> s t)\"\n    hence \"s \\<in> SMP ?N - Var`\\<V>\" \"t \\<in> SMP ?N - Var`\\<V>\" using * by auto\n    hence \"\\<Gamma> s = \\<Gamma> t\" using **(1,4) unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by blast\n  } moreover have \"\\<forall>t \\<in> ?N. wf\\<^sub>t\\<^sub>r\\<^sub>m t \\<Longrightarrow> \\<forall>t \\<in> ?M. wf\\<^sub>t\\<^sub>r\\<^sub>m t\" using * by blast\n  ultimately have \"tfr\\<^sub>s\\<^sub>e\\<^sub>t ?N \\<Longrightarrow> tfr\\<^sub>s\\<^sub>e\\<^sub>t ?M\" unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by blast\n  hence \"tfr\\<^sub>s\\<^sub>e\\<^sub>t ?M\" using assms unfolding tfr\\<^sub>s\\<^sub>s\\<^sub>t_def by metis\n  thus \"tfr\\<^sub>s\\<^sub>s\\<^sub>t B\" using assms unfolding tfr\\<^sub>s\\<^sub>s\\<^sub>t_def by simp\nqed\n\nlemma tfr\\<^sub>s\\<^sub>s\\<^sub>t_cons: \"tfr\\<^sub>s\\<^sub>s\\<^sub>t (a#A) \\<Longrightarrow> tfr\\<^sub>s\\<^sub>s\\<^sub>t A\"\nusing tfr\\<^sub>s\\<^sub>s\\<^sub>t_append'[of \"[a]\" A] by simp\n\nlemma tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst:\n  assumes s: \"tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p s\"\n    and \\<theta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\" \"set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p s) \\<inter> range_vars \\<theta> = {}\"\n  shows \"tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (s \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\"\nproof (cases s)\n  case (Equality a t t')\n  thus ?thesis\n  proof (cases \"\\<exists>\\<delta>. Unifier \\<delta> (t \\<cdot> \\<theta>) (t' \\<cdot> \\<theta>)\")\n    case True\n    hence \"\\<exists>\\<delta>. Unifier \\<delta> t t'\" by (metis subst_subst_compose[of _ \\<theta>])\n    moreover have \"\\<Gamma> t = \\<Gamma> (t \\<cdot> \\<theta>)\" \"\\<Gamma> t' = \\<Gamma> (t' \\<cdot> \\<theta>)\" by (metis wt_subst_trm''[OF assms(2)])+\n    ultimately have \"\\<Gamma> (t \\<cdot> \\<theta>) = \\<Gamma> (t' \\<cdot> \\<theta>)\" using s Equality by simp\n    thus ?thesis using Equality True by simp\n  qed simp\nnext\n  case (NegChecks X F G)\n  let ?P = \"\\<lambda>F G. G = [] \\<and> (\\<forall>x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F-set X. \\<exists>a. \\<Gamma> (Var x) = TAtom a)\"\n  let ?Q = \"\\<lambda>F G. \\<forall>f T. Fun f T \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> pair ` set G) \\<longrightarrow>\n                          T = [] \\<or> (\\<exists>s \\<in> set T. s \\<notin> Var ` set X)\"\n  let ?\\<theta> = \"rm_vars (set X) \\<theta>\"\n\n  have \"?P F G \\<or> ?Q F G\" using NegChecks assms(1) by simp\n  hence \"?P (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ?\\<theta>) (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ?\\<theta>) \\<or> ?Q (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ?\\<theta>) (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ?\\<theta>)\"\n  proof\n    assume *: \"?P F G\"\n    have \"G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ?\\<theta> = []\" using * by simp\n    moreover have \"\\<exists>a. \\<Gamma> (Var x) = TAtom a\" when x: \"x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ?\\<theta>) - set X\" for x\n    proof -\n      obtain t t' where t: \"(t,t') \\<in> set (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ?\\<theta>)\" \"x \\<in> fv t \\<union> fv t' - set X\"\n        using x(1) by auto\n      then obtain u u' where u: \"(u,u') \\<in> set F\" \"u \\<cdot> ?\\<theta> = t\" \"u' \\<cdot> ?\\<theta> = t'\"\n        unfolding subst_apply_pairs_def by auto\n      obtain y where y: \"y \\<in> fv u \\<union> fv u' - set X\" \"x \\<in> fv (?\\<theta> y)\"\n        using t(2) u(2,3) rm_vars_fv_obtain by fast\n      hence a: \"\\<exists>a. \\<Gamma> (Var y) = TAtom a\" using u * by auto\n      \n      have a': \"\\<Gamma> (Var y) = \\<Gamma> (?\\<theta> y)\"\n        using wt_subst_trm''[OF wt_subst_rm_vars[OF \\<theta>(1), of \"set X\"], of \"Var y\"]\n        by simp\n\n      have \"(\\<exists>z. ?\\<theta> y = Var z) \\<or> (\\<exists>c. ?\\<theta> y = Fun c [])\"\n      proof (cases \"?\\<theta> y \\<in> subst_range \\<theta>\")\n        case True thus ?thesis\n          using a a' \\<theta>(2) const_type_inv_wf\n          by (cases \"?\\<theta> y\") fastforce+\n      qed fastforce\n      hence \"?\\<theta> y = Var x\" using y(2) by fastforce\n      hence \"\\<Gamma> (Var x) = \\<Gamma> (Var y)\" using a' by simp\n      thus ?thesis using a by presburger\n    qed\n    ultimately show ?thesis by simp\n  next\n    assume *: \"?Q F G\"\n    have **: \"set X \\<inter> range_vars ?\\<theta> = {}\"\n      using \\<theta>(3) NegChecks rm_vars_img_fv_subset[of \"set X\" \\<theta>] by auto\n    have \"?Q (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ?\\<theta>) (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ?\\<theta>)\"\n      using ineq_subterm_inj_cond_subst[OF ** *]\n            trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_subst[of F \"rm_vars (set X) \\<theta>\"]\n            subst_apply_pairs_pair_image_subst[of G \"rm_vars (set X) \\<theta>\"]\n      by (metis (no_types, lifting) image_Un)\n    thus ?thesis by simp\n  qed\n  thus ?thesis using NegChecks by simp\nqed simp_all\n\nlemma tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_all_wt_subst_apply:\n  assumes S: \"list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p S\"\n    and \\<theta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\" \"bvars\\<^sub>s\\<^sub>s\\<^sub>t S \\<inter> range_vars \\<theta> = {}\"\n  shows \"list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\nproof -\n  have \"set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p s) \\<inter> range_vars \\<theta> = {}\" when \"s \\<in> set S\" for s\n    using that \\<theta>(3) unfolding bvars\\<^sub>s\\<^sub>s\\<^sub>t_def range_vars_alt_def by fastforce\n  thus ?thesis\n    using tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst[OF _ \\<theta>(1,2)] S\n    unfolding list_all_iff\n    by (auto simp add: subst_apply_stateful_strand_def)\nqed\n\nlemma tfr_setops_if_tfr_trms:\n  assumes \"Pair \\<notin> \\<Union>(funs_term ` SMP (trms\\<^sub>s\\<^sub>s\\<^sub>t S))\"\n    and \"\\<forall>p. Ana (pair p) = ([], [])\"\n    and \"\\<forall>s \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S. \\<forall>t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S. (\\<exists>\\<delta>. Unifier \\<delta> s t) \\<longrightarrow> \\<Gamma> s = \\<Gamma> t\"\n    and \"\\<forall>s \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S. \\<forall>t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S.\n          (\\<exists>\\<sigma> \\<theta> \\<rho>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma> \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<sigma>) \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>) \\<and>\n                   Unifier \\<rho> (s \\<cdot> \\<sigma>) (t \\<cdot> \\<theta>))\n          \\<longrightarrow> (\\<exists>\\<delta>. Unifier \\<delta> s t)\"\n    and tfr: \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t S)\"\n  shows \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t S \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S)\"\nproof -\n  have 0: \"t \\<in> SMP (trms\\<^sub>s\\<^sub>s\\<^sub>t S) - range Var \\<or> t \\<in> SMP (pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S) - range Var\"\n    when \"t \\<in> SMP (trms\\<^sub>s\\<^sub>s\\<^sub>t S \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S) - range Var\" for t\n    using that SMP_union by blast\n\n  have 1: \"s \\<in> SMP (trms\\<^sub>s\\<^sub>s\\<^sub>t S) - range Var\"\n      when st: \"s \\<in> SMP (pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S) - range Var\"\n               \"t \\<in> SMP (trms\\<^sub>s\\<^sub>s\\<^sub>t S) - range Var\"\n               \"\\<exists>\\<delta>. Unifier \\<delta> s t\"\n         for s t\n  proof -\n    have \"(\\<exists>\\<delta>. s \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>) \\<or> s \\<in> SMP (trms\\<^sub>s\\<^sub>s\\<^sub>t S) - range Var\"\n      using st setops_SMP_cases[of s S] assms(2) by blast\n    moreover {\n      fix \\<delta> assume \\<delta>: \"s \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>\"\n      then obtain s' where s': \"s' \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S\" \"s = s' \\<cdot> \\<delta>\" by blast\n      then obtain u u' where u: \"s' = Fun Pair [u,u']\"\n        using setops\\<^sub>s\\<^sub>s\\<^sub>t_are_pairs[of s'] unfolding pair_def by fast\n      hence *: \"s = Fun Pair [u \\<cdot> \\<delta>, u' \\<cdot> \\<delta>]\" using \\<delta> s' by simp\n\n      obtain f T where fT: \"t = Fun f T\" using st(2) by (cases t) auto\n      hence \"f \\<noteq> Pair\" using st(2) assms(1) by auto\n      hence False using st(3) * fT s' u by fast\n    } ultimately show ?thesis by meson\n  qed\n  \n  have 2: \"\\<Gamma> s = \\<Gamma> t\"\n      when \"s \\<in> SMP (trms\\<^sub>s\\<^sub>s\\<^sub>t S) - range Var\"\n           \"t \\<in> SMP (trms\\<^sub>s\\<^sub>s\\<^sub>t S) - range Var\"\n           \"\\<exists>\\<delta>. Unifier \\<delta> s t\"\n       for s t\n    using that tfr unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by blast\n  \n  have 3: \"\\<Gamma> s = \\<Gamma> t\"\n      when st: \"s \\<in> SMP (pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S) - range Var\"\n               \"t \\<in> SMP (pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S) - range Var\"\n               \"\\<exists>\\<delta>. Unifier \\<delta> s t\"\n      for s t\n  proof -\n    let ?P = \"\\<lambda>s \\<delta>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> s \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>\"\n    have \"(\\<exists>\\<delta>. ?P s \\<delta>) \\<or> s \\<in> SMP (trms\\<^sub>s\\<^sub>s\\<^sub>t S) - range Var\"\n         \"(\\<exists>\\<delta>. ?P t \\<delta>) \\<or> t \\<in> SMP (trms\\<^sub>s\\<^sub>s\\<^sub>t S) - range Var\"\n      using setops_SMP_cases[of _ S] assms(2) st(1,2) by auto\n    hence \"(\\<exists>\\<delta> \\<delta>'. ?P s \\<delta> \\<and> ?P t \\<delta>') \\<or> \\<Gamma> s = \\<Gamma> t\" by (metis 1 2 st)\n    moreover {\n      fix \\<delta> \\<delta>' assume *: \"?P s \\<delta>\" \"?P t \\<delta>'\"\n      then obtain s' t' where **:\n          \"s' \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S\" \"t' \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S\" \"s = s' \\<cdot> \\<delta>\" \"t = t' \\<cdot> \\<delta>'\"\n        by blast\n      hence \"\\<exists>\\<theta>. Unifier \\<theta> s' t'\" using st(3) assms(4) * by blast\n      hence \"\\<Gamma> s' = \\<Gamma> t'\" using assms(3) ** by blast\n      hence \"\\<Gamma> s = \\<Gamma> t\" using * **(3,4) wt_subst_trm''[of \\<delta> s'] wt_subst_trm''[of \\<delta>' t'] by argo\n    } ultimately show ?thesis by blast\n  qed\n  \n  show ?thesis using 0 1 2 3 unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by metis\nqed\n\nend\n\n\nsubsection \\<open>The Typing Result for Stateful Constraints\\<close>\n\nsubsubsection \\<open>Correctness of the Constraint Reduction\\<close>\ncontext stateful_typed_model\nbegin\n\ncontext\nbegin\nprivate lemma tr_wf':\n  assumes \"\\<forall>(t,t') \\<in> set D. (fv t \\<union> fv t') \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\n  and \"\\<forall>(t,t') \\<in> set D. fv t \\<union> fv t' \\<subseteq> X\"\n  and \"wf'\\<^sub>s\\<^sub>s\\<^sub>t X A\" \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\n  and \"A' \\<in> set (tr A D)\"\n  shows \"wf\\<^sub>s\\<^sub>t X A'\"\nproof -\n  define P where\n    \"P = (\\<lambda>(D::('fun,'var) dbstatelist) (A::('fun,'var) stateful_strand).\n          (\\<forall>(t,t') \\<in> set D. (fv t \\<union> fv t') \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}) \\<and> fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {})\"\n\n  have \"P D A\" using assms(1,4) by (simp add: P_def)\n  with assms(5,3,2) show ?thesis\n  proof (induction A arbitrary: A' D X rule: wf'\\<^sub>s\\<^sub>s\\<^sub>t.induct)\n    case 1 thus ?case by simp\n  next\n    case (2 X ts A A')\n    then obtain A'' where A'': \"A' = receive\\<langle>ts\\<rangle>\\<^sub>s\\<^sub>t#A''\" \"A'' \\<in> set (tr A D)\" \"fv\\<^sub>s\\<^sub>e\\<^sub>t (set ts) \\<subseteq> X\"\n      by moura\n    have *: \"wf'\\<^sub>s\\<^sub>s\\<^sub>t X A\" \"\\<forall>(s,s') \\<in> set D. fv s \\<union> fv s' \\<subseteq> X\" \"P D A\"\n      using 2(1,2,3,4) apply (force, force)\n      using 2(5) unfolding P_def by force\n    show ?case using \"2.IH\"[OF A''(2) *] A''(1,3) by simp\n  next\n    case (3 X ts A A')\n    then obtain A'' where A'': \"A' = send\\<langle>ts\\<rangle>\\<^sub>s\\<^sub>t#A''\" \"A'' \\<in> set (tr A D)\"\n      by moura\n    have *: \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (X \\<union> fv\\<^sub>s\\<^sub>e\\<^sub>t (set ts)) A\"\n            \"\\<forall>(s,s') \\<in> set D. fv s \\<union> fv s' \\<subseteq> X \\<union> fv\\<^sub>s\\<^sub>e\\<^sub>t (set ts)\" \"P D A\"\n      using 3(1,2,3,4) apply (force, force)\n      using 3(5) unfolding P_def by force\n    show ?case using \"3.IH\"[OF A''(2) *] A''(1) by simp\n  next\n    case (4 X t t' A A')\n    then obtain A'' where A'': \"A' = \\<langle>assign: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#A''\" \"A'' \\<in> set (tr A D)\" \"fv t' \\<subseteq> X\"\n      by moura\n    have *: \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (X \\<union> fv t) A\" \"\\<forall>(s,s') \\<in> set D. fv s \\<union> fv s' \\<subseteq> X \\<union> fv t\" \"P D A\"\n      using 4(1,2,3,4) apply (force, force)\n      using 4(5) unfolding P_def by force\n    show ?case using \"4.IH\"[OF A''(2) *] A''(1,3) by simp\n  next\n    case (5 X t t' A A')\n    then obtain A'' where A'': \"A' = \\<langle>check: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#A''\" \"A'' \\<in> set (tr A D)\"\n      by moura\n    have *: \"wf'\\<^sub>s\\<^sub>s\\<^sub>t X A\" \"P D A\"\n      using 5(3) apply force\n      using 5(5) unfolding P_def by force\n    show ?case using \"5.IH\"[OF A''(2) *(1) 5(4) *(2)] A''(1) by simp\n  next\n    case (6 X t s A A')\n    hence A': \"A' \\<in> set (tr A (List.insert (t,s) D))\" \"fv t \\<subseteq> X\" \"fv s \\<subseteq> X\" by auto\n    have *: \"wf'\\<^sub>s\\<^sub>s\\<^sub>t X A\" \"\\<forall>(s,s') \\<in> set (List.insert (t,s) D). fv s \\<union> fv s' \\<subseteq> X\" using 6 by auto\n    have **: \"P (List.insert (t,s) D) A\" using 6(5) unfolding P_def by force\n    show ?case using \"6.IH\"[OF A'(1) * **] A'(2,3) by simp\n  next\n    case (7 X t s A A')\n    let ?constr = \"\\<lambda>Di. (map (\\<lambda>d. \\<langle>check: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t) Di)@\n                        (map (\\<lambda>d. \\<forall>[]\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) [d\\<leftarrow>D. d \\<notin> set Di])\"\n    from 7 obtain Di A'' where A'':\n        \"A' = ?constr Di@A''\" \"A'' \\<in> set (tr A [d\\<leftarrow>D. d \\<notin> set Di])\"\n        \"Di \\<in> set (subseqs D)\"\n      by moura\n    have *: \"wf'\\<^sub>s\\<^sub>s\\<^sub>t X A\" \"\\<forall>(t',s') \\<in> set [d\\<leftarrow>D. d \\<notin> set Di]. fv t' \\<union> fv s' \\<subseteq> X\"\n      using 7 by auto\n    have **: \"P [d\\<leftarrow>D. d \\<notin> set Di] A\" using 7 unfolding P_def by force\n    have ***: \"\\<forall>(t, t') \\<in> set D. fv t \\<union> fv t' \\<subseteq> X\" using 7 by auto\n    show ?case\n      using \"7.IH\"[OF A''(2) * **] A''(1) wf_fun_pair_eqs_ineqs_map[OF _ A''(3) ***]\n      by simp\n  next\n    case (8 X t s A A')\n    then obtain d A'' where A'':\n        \"A' = \\<langle>assign: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t#A''\"\n        \"A'' \\<in> set (tr A D)\" \"d \\<in> set D\"\n      by moura\n    have *: \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (X \\<union> fv t \\<union> fv s) A\" \"\\<forall>(t',s')\\<in>set D. fv t' \\<union> fv s' \\<subseteq> X \\<union> fv t \\<union> fv s\" \"P D A\"\n      using 8(1,2,3,4) apply (force, force)\n      using 8(5) unfolding P_def by force\n    have **: \"fv (pair d) \\<subseteq> X\" using A''(3) \"8.prems\"(3) unfolding pair_def by fastforce\n    have ***: \"fv (pair (t,s)) = fv s \\<union> fv t\" unfolding pair_def by auto\n    show ?case using \"8.IH\"[OF A''(2) *] A''(1) ** *** unfolding pair_def by (simp add: Un_assoc)\n  next\n    case (9 X t s A A')\n    then obtain d A'' where A'':\n        \"A' = \\<langle>check: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t#A''\"\n        \"A'' \\<in> set (tr A D)\" \"d \\<in> set D\"\n      by moura\n    have *: \"wf'\\<^sub>s\\<^sub>s\\<^sub>t X A\"\"P D A\"\n      using 9(3) apply force\n      using 9(5) unfolding P_def by force\n    have **: \"fv (pair d) \\<subseteq> X\" using A''(3) \"9.prems\"(3) unfolding pair_def by fastforce\n    have ***: \"fv (pair (t,s)) = fv s \\<union> fv t\" unfolding pair_def by auto\n    show ?case using \"9.IH\"[OF A''(2) *(1) 9(4) *(2)] A''(1) ** *** by (simp add: Un_assoc)\n  next\n    case (10 X Y F F' A A')\n    from 10 obtain A'' where A'':\n        \"A' = (map (\\<lambda>G. \\<forall>Y\\<langle>\\<or>\\<noteq>: (F@G)\\<rangle>\\<^sub>s\\<^sub>t) (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' D))@A''\" \"A'' \\<in> set (tr A D)\"\n      by moura\n\n    have *: \"wf'\\<^sub>s\\<^sub>s\\<^sub>t X A\" \"\\<forall>(t',s') \\<in> set D. fv t' \\<union> fv s' \\<subseteq> X\" using 10 by auto\n    \n    have \"bvars\\<^sub>s\\<^sub>s\\<^sub>t A \\<subseteq> bvars\\<^sub>s\\<^sub>s\\<^sub>t (\\<forall>Y\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: F'\\<rangle>#A)\" \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t (\\<forall>Y\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: F'\\<rangle>#A)\" by auto\n    hence **:  \"P D A\" using 10 unfolding P_def by blast\n\n    show ?case using \"10.IH\"[OF A''(2) * **] A''(1) wf_fun_pair_negchecks_map by simp\n  qed\nqed\n\nprivate lemma tr_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s:\n  assumes \"A' \\<in> set (tr A [])\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>s\\<^sub>t A)\"\n  shows \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t A')\"\nusing tr_trms_subset[OF assms(1)] setops\\<^sub>s\\<^sub>s\\<^sub>t_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s(2)[OF assms(2)]\nby auto\n\nlemma tr_wf:\n  assumes \"A' \\<in> set (tr A [])\"\n    and \"wf\\<^sub>s\\<^sub>s\\<^sub>t A\"\n    and \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>s\\<^sub>t A)\" \n  shows \"wf\\<^sub>s\\<^sub>t {} A'\"\n    and \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t A')\"\n    and \"fv\\<^sub>s\\<^sub>t A' \\<inter> bvars\\<^sub>s\\<^sub>t A' = {}\"\nusing tr_wf'[OF _ _ _ _ assms(1)]\n      tr_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s[OF assms(1,3)]\n      tr_vars_disj[OF assms(1)]\n      assms(2)\nby fastforce+\n\nprivate lemma fun_pair_ineqs:\n  assumes \"d \\<cdot>\\<^sub>p \\<delta> \\<cdot>\\<^sub>p \\<theta> \\<noteq> d' \\<cdot>\\<^sub>p \\<I>\"\n  shows \"pair d \\<cdot> \\<delta> \\<cdot> \\<theta> \\<noteq> pair d' \\<cdot> \\<I>\"\nproof -\n  have \"d \\<cdot>\\<^sub>p (\\<delta> \\<circ>\\<^sub>s \\<theta>) \\<noteq> d' \\<cdot>\\<^sub>p \\<I>\" using assms subst_pair_compose by metis\n  hence \"pair d \\<cdot> (\\<delta> \\<circ>\\<^sub>s \\<theta>) \\<noteq> pair d' \\<cdot> \\<I>\" using fun_pair_eq_subst by metis\n  thus ?thesis by simp\nqed\n\nprivate lemma tr_Delete_constr_iff_aux1:\n  assumes \"\\<forall>d \\<in> set Di. (t,s) \\<cdot>\\<^sub>p \\<I> = d \\<cdot>\\<^sub>p \\<I>\"\n  and \"\\<forall>d \\<in> set D - set Di. (t,s) \\<cdot>\\<^sub>p \\<I> \\<noteq> d \\<cdot>\\<^sub>p \\<I>\"\n  shows \"\\<lbrakk>M; (map (\\<lambda>d. \\<langle>check: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t) Di)@\n             (map (\\<lambda>d. \\<forall>[]\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) [d\\<leftarrow>D. d \\<notin> set Di])\\<rbrakk>\\<^sub>d \\<I>\"\nproof -\n  from assms(2) have\n    \"\\<lbrakk>M; map (\\<lambda>d. \\<forall>[]\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) [d\\<leftarrow>D. d \\<notin> set Di]\\<rbrakk>\\<^sub>d \\<I>\"\n  proof (induction D)\n    case (Cons d D)\n    hence IH: \"\\<lbrakk>M; map (\\<lambda>d. \\<forall>[]\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) [d\\<leftarrow>D . d \\<notin> set Di]\\<rbrakk>\\<^sub>d \\<I>\" by auto\n    thus ?case\n    proof (cases \"d \\<in> set Di\")\n      case False\n      hence \"(t,s) \\<cdot>\\<^sub>p \\<I> \\<noteq> d \\<cdot>\\<^sub>p \\<I>\" using Cons by simp\n      hence \"pair (t,s) \\<cdot> \\<I> \\<noteq> pair d \\<cdot> \\<I>\" using fun_pair_eq_subst by metis\n      moreover have \"\\<And>t (\\<delta>::('fun,'var) subst). subst_domain \\<delta> = {} \\<Longrightarrow> t \\<cdot> \\<delta> = t\" by auto\n      ultimately have \"\\<forall>\\<delta>. subst_domain \\<delta> = {} \\<longrightarrow> pair (t,s) \\<cdot> \\<delta> \\<cdot> \\<I> \\<noteq> pair d \\<cdot> \\<delta> \\<cdot> \\<I>\" by metis\n      thus ?thesis using IH by (simp add: ineq_model_def)\n    qed simp\n  qed simp\n  moreover {\n    fix B assume \"\\<lbrakk>M; B\\<rbrakk>\\<^sub>d \\<I>\" \n    with assms(1) have \"\\<lbrakk>M; (map (\\<lambda>d. \\<langle>check: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t) Di)@B\\<rbrakk>\\<^sub>d \\<I>\"\n      unfolding pair_def by (induction Di) auto\n  } ultimately show ?thesis by metis\nqed\n\nprivate lemma tr_Delete_constr_iff_aux2:\n  assumes \"ground M\"\n  and \"\\<lbrakk>M; (map (\\<lambda>d. \\<langle>check: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t) Di)@\n           (map (\\<lambda>d. \\<forall>[]\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) [d\\<leftarrow>D. d \\<notin> set Di])\\<rbrakk>\\<^sub>d \\<I>\"\n  shows \"(\\<forall>d \\<in> set Di. (t,s) \\<cdot>\\<^sub>p \\<I> = d \\<cdot>\\<^sub>p \\<I>) \\<and> (\\<forall>d \\<in> set D - set Di. (t,s) \\<cdot>\\<^sub>p \\<I> \\<noteq> d \\<cdot>\\<^sub>p \\<I>)\"\nproof -\n  let ?c1 = \"map (\\<lambda>d. \\<langle>check: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t) Di\"\n  let ?c2 = \"map (\\<lambda>d. \\<forall>[]\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) [d\\<leftarrow>D. d \\<notin> set Di]\"\n\n  have \"M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> = M\" using assms(1) subst_all_ground_ident by metis\n  moreover have \"ik\\<^sub>s\\<^sub>t ?c1 = {}\" by auto\n  ultimately have *:\n       \"\\<lbrakk>M; map (\\<lambda>d. \\<langle>check: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t) Di\\<rbrakk>\\<^sub>d \\<I>\"\n       \"\\<lbrakk>M; map (\\<lambda>d. \\<forall>[]\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) [d\\<leftarrow>D. d \\<notin> set Di]\\<rbrakk>\\<^sub>d \\<I>\"\n    using strand_sem_split(3,4)[of M ?c1 ?c2 \\<I>] assms(2) by auto\n  \n  from *(1) have 1: \"\\<forall>d \\<in> set Di. (t,s) \\<cdot>\\<^sub>p \\<I> = d \\<cdot>\\<^sub>p \\<I>\" unfolding pair_def by (induct Di) auto\n  from *(2) have 2: \"\\<forall>d \\<in> set D - set Di. (t,s) \\<cdot>\\<^sub>p \\<I> \\<noteq> d \\<cdot>\\<^sub>p \\<I>\"\n  proof (induction D arbitrary: Di)\n    case (Cons d D) thus ?case\n    proof (cases \"d \\<in> set Di\")\n      case False\n      hence IH: \"\\<forall>d \\<in> set D - set Di. (t,s) \\<cdot>\\<^sub>p \\<I> \\<noteq> d \\<cdot>\\<^sub>p \\<I>\" using Cons by force\n      have \"\\<And>t (\\<delta>::('fun,'var) subst). subst_domain \\<delta> = {} \\<and> ground (subst_range \\<delta>) \\<longleftrightarrow> \\<delta> = Var\"\n        by auto\n      moreover have \"ineq_model \\<I> [] [((pair (t,s)), (pair d))]\"\n        using False Cons.prems by simp\n      ultimately have \"pair (t,s) \\<cdot> \\<I> \\<noteq> pair d \\<cdot> \\<I>\" by (simp add: ineq_model_def)\n      thus ?thesis using IH unfolding pair_def by force\n    qed simp\n  qed simp\n\n  show ?thesis by (metis 1 2)\nqed\n\nprivate lemma tr_Delete_constr_iff:\n  fixes \\<I>::\"('fun,'var) subst\"\n  assumes \"ground M\"\n  shows \"set Di \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<subseteq> {(t,s) \\<cdot>\\<^sub>p \\<I>} \\<and> (t,s) \\<cdot>\\<^sub>p \\<I> \\<notin> (set D - set Di) \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<longleftrightarrow>\n         \\<lbrakk>M; (map (\\<lambda>d. \\<langle>check: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t) Di)@\n             (map (\\<lambda>d. \\<forall>[]\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) [d\\<leftarrow>D. d \\<notin> set Di])\\<rbrakk>\\<^sub>d \\<I>\"\nproof -\n  let ?constr = \"(map (\\<lambda>d. \\<langle>check: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t) Di)@\n                 (map (\\<lambda>d. \\<forall>[]\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) [d\\<leftarrow>D. d \\<notin> set Di])\"\n  { assume \"set Di \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<subseteq> {(t,s) \\<cdot>\\<^sub>p \\<I>}\" \"(t,s) \\<cdot>\\<^sub>p \\<I> \\<notin> (set D - set Di) \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n    hence \"\\<forall>d \\<in> set Di. (t,s) \\<cdot>\\<^sub>p \\<I> = d \\<cdot>\\<^sub>p \\<I>\" \"\\<forall>d \\<in> set D - set Di. (t,s) \\<cdot>\\<^sub>p \\<I> \\<noteq> d \\<cdot>\\<^sub>p \\<I>\"\n      by auto\n    hence \"\\<lbrakk>M; ?constr\\<rbrakk>\\<^sub>d \\<I>\" using tr_Delete_constr_iff_aux1 by simp\n  } moreover {\n    assume \"\\<lbrakk>M; ?constr\\<rbrakk>\\<^sub>d \\<I>\"\n    hence \"\\<forall>d \\<in> set Di. (t,s) \\<cdot>\\<^sub>p \\<I> = d \\<cdot>\\<^sub>p \\<I>\" \"\\<forall>d \\<in> set D - set Di. (t,s) \\<cdot>\\<^sub>p \\<I> \\<noteq> d \\<cdot>\\<^sub>p \\<I>\"\n      using assms tr_Delete_constr_iff_aux2 by auto\n    hence \"set Di \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<subseteq> {(t,s) \\<cdot>\\<^sub>p \\<I>} \\<and> (t,s) \\<cdot>\\<^sub>p \\<I> \\<notin> (set D - set Di) \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" by force\n  } ultimately show ?thesis by metis\nqed\n\nprivate lemma tr_NotInSet_constr_iff:\n  fixes \\<I>::\"('fun,'var) subst\"\n  assumes \"\\<forall>(t,t') \\<in> set D. (fv t \\<union> fv t') \\<inter> set X = {}\"\n  shows \"(\\<forall>\\<delta>. subst_domain \\<delta> = set X \\<and> ground (subst_range \\<delta>) \\<longrightarrow> (t,s) \\<cdot>\\<^sub>p \\<delta> \\<cdot>\\<^sub>p \\<I> \\<notin> set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>)\n          \\<longleftrightarrow> \\<lbrakk>M; map (\\<lambda>d. \\<forall>X\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) D\\<rbrakk>\\<^sub>d \\<I>\"\nproof -\n  { assume \"\\<forall>\\<delta>. subst_domain \\<delta> = set X \\<and> ground (subst_range \\<delta>) \\<longrightarrow> (t,s) \\<cdot>\\<^sub>p \\<delta> \\<cdot>\\<^sub>p \\<I> \\<notin> set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n    with assms have \"\\<lbrakk>M; map (\\<lambda>d. \\<forall>X\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) D\\<rbrakk>\\<^sub>d \\<I>\"\n    proof (induction D)\n      case (Cons d D)\n      obtain t' s' where d: \"d = (t',s')\" by moura\n      have \"\\<lbrakk>M; map (\\<lambda>d. \\<forall>X\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) D\\<rbrakk>\\<^sub>d \\<I>\"\n           \"map (\\<lambda>d. \\<forall>X\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) (d#D) =\n            \\<forall>X\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t#map (\\<lambda>d. \\<forall>X\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) D\"\n        using Cons by auto\n      moreover have\n          \"\\<forall>\\<delta>. subst_domain \\<delta> = set X \\<and> ground (subst_range \\<delta>) \\<longrightarrow> pair (t, s) \\<cdot> \\<delta> \\<cdot> \\<I> \\<noteq> pair d \\<cdot> \\<I>\"\n        using fun_pair_ineqs[of \\<I> _  \"(t,s)\" \\<I> d] Cons.prems(2) by auto\n      moreover have \"(fv t' \\<union> fv s') \\<inter> set X = {}\" using Cons.prems(1) d by auto\n      hence \"\\<forall>\\<delta>. subst_domain \\<delta> = set X \\<longrightarrow> pair d \\<cdot> \\<delta> = pair d\" using d unfolding pair_def by auto\n      ultimately show ?case by (simp add: ineq_model_def)\n    qed simp\n  } moreover {\n    fix \\<delta>::\"('fun,'var) subst\"\n    assume \"\\<lbrakk>M; map (\\<lambda>d. \\<forall>X\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) D\\<rbrakk>\\<^sub>d \\<I>\"\n      and \\<delta>: \"subst_domain \\<delta> = set X\" \"ground (subst_range \\<delta>)\"\n    with assms have \"(t,s) \\<cdot>\\<^sub>p \\<delta> \\<cdot>\\<^sub>p \\<I> \\<notin> set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n    proof (induction D)\n      case (Cons d D)\n      obtain t' s' where d: \"d = (t',s')\" by moura\n      have \"(t,s) \\<cdot>\\<^sub>p \\<delta> \\<cdot>\\<^sub>p \\<I> \\<notin> set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n           \"pair (t,s) \\<cdot> \\<delta> \\<cdot> \\<I> \\<noteq> pair d \\<cdot> \\<delta> \\<cdot> \\<I>\"\n        using Cons d by (auto simp add: ineq_model_def simp del: subst_range.simps)\n      moreover have \"pair d \\<cdot> \\<delta> = pair d\"\n        using Cons.prems(1) fun_pair_subst[of d \\<delta>] d \\<delta>(1) unfolding pair_def by auto\n      ultimately show ?case unfolding pair_def by force\n    qed simp\n  } ultimately show ?thesis by metis\nqed\n\nlemma tr_NegChecks_constr_iff:\n  \"(\\<forall>G\\<in>set L. ineq_model \\<I> X (F@G)) \\<longleftrightarrow> \\<lbrakk>M; map (\\<lambda>G. \\<forall>X\\<langle>\\<or>\\<noteq>: (F@G)\\<rangle>\\<^sub>s\\<^sub>t) L\\<rbrakk>\\<^sub>d \\<I>\" (is ?A)\n  \"negchecks_model \\<I> D X F F' \\<longleftrightarrow> \\<lbrakk>M; D; [\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: F'\\<rangle>]\\<rbrakk>\\<^sub>s \\<I>\" (is ?B)\nproof -\n  show ?A by (induct L) auto\n  show ?B by simp\nqed\n\nlemma tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_sem_equiv:\n  fixes \\<I>::\"('fun,'var) subst\"\n  assumes \"\\<forall>(t,t') \\<in> set D. (fv t \\<union> fv t') \\<inter> set X = {}\"\n  shows \"negchecks_model \\<I> (set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) X F F' \\<longleftrightarrow>\n         (\\<forall>G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' D). ineq_model \\<I> X (F@G))\"\nproof -\n  define P where\n    \"P \\<equiv> \\<lambda>\\<delta>::('fun,'var) subst. subst_domain \\<delta> = set X \\<and> ground (subst_range \\<delta>)\" \n\n  define Ineq where\n    \"Ineq \\<equiv> \\<lambda>(\\<delta>::('fun,'var) subst) F. \\<exists>(s,t) \\<in> set F. s \\<cdot> \\<delta> \\<circ>\\<^sub>s \\<I> \\<noteq> t \\<cdot> \\<delta> \\<circ>\\<^sub>s \\<I>\"\n\n  define Ineq' where\n    \"Ineq' \\<equiv> \\<lambda>(\\<delta>::('fun,'var) subst) F. \\<exists>(s,t) \\<in> set F. s \\<cdot> \\<delta> \\<circ>\\<^sub>s \\<I> \\<noteq> t \\<cdot> \\<I>\"\n  \n  define Notin where\n    \"Notin \\<equiv> \\<lambda>(\\<delta>::('fun,'var) subst) D F'. \\<exists>(s,t) \\<in> set F'. (s,t) \\<cdot>\\<^sub>p \\<delta> \\<circ>\\<^sub>s \\<I> \\<notin> set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n\n  have sublmm:\n      \"((s,t) \\<cdot>\\<^sub>p \\<delta> \\<circ>\\<^sub>s \\<I> \\<notin> set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<longleftrightarrow> (list_all (\\<lambda>d. Ineq' \\<delta> [(pair (s,t),pair d)]) D)\"\n    for s t \\<delta> D\n    unfolding pair_def by (induct D) (auto simp add: Ineq'_def)\n\n  have \"Notin \\<delta> D F' \\<longleftrightarrow> (\\<forall>G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' D). Ineq' \\<delta> G)\"\n    (is \"?A \\<longleftrightarrow> ?B\")\n    when \"P \\<delta>\" for \\<delta>\n  proof\n    show \"?A \\<Longrightarrow> ?B\"\n    proof (induction F' D rule: tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s.induct)\n      case (2 s t F' D)\n      show ?case\n      proof (cases \"Notin \\<delta> D F'\")\n        case False\n        hence \"(s,t) \\<cdot>\\<^sub>p \\<delta> \\<circ>\\<^sub>s \\<I> \\<notin> set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n          using \"2.prems\"\n          by (auto simp add: Notin_def)\n        hence \"pair (s,t) \\<cdot> \\<delta> \\<circ>\\<^sub>s \\<I> \\<noteq> pair d \\<cdot> \\<I>\" when \"d \\<in> set D\" for d\n          using that sublmm Ball_set[of D \"\\<lambda>d. Ineq' \\<delta> [(pair (s,t), pair d)]\"]\n          by (simp add: Ineq'_def)\n        moreover have \"\\<exists>d \\<in> set D. \\<exists>G'. G = (pair (s,t), pair d)#G'\"\n          when \"G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ((s,t)#F') D)\" for G\n          using that tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_index[OF that, of 0] by force\n        ultimately show ?thesis by (simp add: Ineq'_def)\n      qed (auto dest: \"2.IH\" simp add: Ineq'_def)\n    qed (simp add: Notin_def)\n\n    have \"\\<not>?A \\<Longrightarrow> \\<not>?B\"\n    proof (induction F' D rule: tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s.induct)\n      case (2 s t F' D)\n      hence \"\\<not>Notin \\<delta> D F'\" \"D \\<noteq> []\" unfolding Notin_def by auto\n      then obtain G where G: \"G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' D)\" \"\\<not>Ineq' \\<delta> G\"\n        using \"2.IH\" by (cases D) auto\n\n      obtain d where d: \"d \\<in> set D\" \"pair (s,t) \\<cdot> \\<delta> \\<circ>\\<^sub>s \\<I> = pair d \\<cdot> \\<I>\"\n        using \"2.prems\"\n        unfolding pair_def by (auto simp add: Notin_def)\n      thus ?case\n        using G(2) tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_cons[OF G(1) d(1)]\n        by (auto simp add: Ineq'_def)\n    qed (simp add: Ineq'_def)\n    thus \"?B \\<Longrightarrow> ?A\" by metis\n  qed\n  hence *: \"(\\<forall>\\<delta>. P \\<delta> \\<longrightarrow> Ineq \\<delta> F \\<or> Notin \\<delta> D F') \\<longleftrightarrow>\n            (\\<forall>G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' D). \\<forall>\\<delta>. P \\<delta> \\<longrightarrow> Ineq \\<delta> F \\<or> Ineq' \\<delta> G)\"\n    by auto\n\n  have \"t \\<cdot> \\<delta> = t\"\n    when \"G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' D)\" \"(s,t) \\<in> set G\" \"P \\<delta>\"\n    for \\<delta> s t G\n    using assms that(3) tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_has_pair_lists[OF that(1,2)]\n    unfolding pair_def by (fastforce simp add: P_def)\n  hence **: \"Ineq' \\<delta> G = Ineq \\<delta> G\"\n    when \"G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' D)\" \"P \\<delta>\"\n    for \\<delta> G\n    using that unfolding Ineq_def Ineq'_def by force\n\n  have ***: \"negchecks_model \\<I> (set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) X F F' \\<longleftrightarrow> (\\<forall>\\<delta>. P \\<delta> \\<longrightarrow> Ineq \\<delta> F \\<or> Notin \\<delta> D F')\"\n    unfolding P_def Ineq_def Notin_def negchecks_model_def by blast\n\n  have \"ineq_model \\<I> X (F@G) \\<longleftrightarrow> (\\<forall>\\<delta>. P \\<delta> \\<longrightarrow> Ineq \\<delta> (F@G))\" for G\n    unfolding P_def Ineq_def ineq_model_def by blast\n  hence ****: \"ineq_model \\<I> X (F@G) \\<longleftrightarrow> (\\<forall>\\<delta>. P \\<delta> \\<longrightarrow> Ineq \\<delta> F \\<or> Ineq \\<delta> G)\" for G\n    unfolding Ineq_def by fastforce\n\n  show ?thesis\n    using * ** *** **** by simp\nqed\n\nlemma tr_sem_equiv':\n  assumes \"\\<forall>(t,t') \\<in> set D. (fv t \\<union> fv t') \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\n    and \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\n    and \"ground M\"\n    and \\<I>: \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\"\n  shows \"\\<lbrakk>M; set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>; A\\<rbrakk>\\<^sub>s \\<I> \\<longleftrightarrow> (\\<exists>A' \\<in> set (tr A D). \\<lbrakk>M; A'\\<rbrakk>\\<^sub>d \\<I>)\" (is \"?P \\<longleftrightarrow> ?Q\")\nproof\n  have \\<I>_grounds: \"\\<And>t. fv (t \\<cdot> \\<I>) = {}\" by (rule interpretation_grounds[OF \\<I>])\n  have \"\\<exists>A' \\<in> set (tr A D). \\<lbrakk>M; A'\\<rbrakk>\\<^sub>d \\<I>\" when ?P using that assms(1,2,3)\n  proof (induction A arbitrary: D rule: strand_sem_stateful_induct)\n    case (ConsRcv M D ts A)\n    have \"\\<lbrakk>(set ts \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> M; set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>; A\\<rbrakk>\\<^sub>s \\<I>\"\n         \"\\<forall>(t,t') \\<in> set D. (fv t \\<union> fv t') \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\n         \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" \"ground ((set ts \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> M)\"\n      using \\<I> ConsRcv.prems unfolding fv\\<^sub>s\\<^sub>s\\<^sub>t_def bvars\\<^sub>s\\<^sub>s\\<^sub>t_def by force+\n    then obtain A' where A': \"A' \\<in> set (tr A D)\" \"\\<lbrakk>(set ts \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> M; A'\\<rbrakk>\\<^sub>d \\<I>\" by (metis ConsRcv.IH)\n    thus ?case by auto\n  next\n    case (ConsSnd M D ts A)\n    have \"\\<lbrakk>M; set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>; A\\<rbrakk>\\<^sub>s \\<I>\"\n         \"\\<forall>(t,t') \\<in> set D. (fv t \\<union> fv t') \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\n         \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" \"ground M\"\n      and *: \"\\<forall>t \\<in> set ts. M \\<turnstile> t \\<cdot> \\<I>\"\n      using \\<I> ConsSnd.prems unfolding fv\\<^sub>s\\<^sub>s\\<^sub>t_def bvars\\<^sub>s\\<^sub>s\\<^sub>t_def by force+\n    then obtain A' where A': \"A' \\<in> set (tr A D)\" \"\\<lbrakk>M; A'\\<rbrakk>\\<^sub>d \\<I>\" by (metis ConsSnd.IH)\n    thus ?case using * by auto\n  next\n    case (ConsEq M D ac t t' A)\n    have \"\\<lbrakk>M; set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>; A\\<rbrakk>\\<^sub>s \\<I>\"\n         \"\\<forall>(t,t') \\<in> set D. (fv t \\<union> fv t') \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\n         \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" \"ground M\"\n      and *: \"t \\<cdot> \\<I> = t' \\<cdot> \\<I>\"\n      using \\<I> ConsEq.prems unfolding fv\\<^sub>s\\<^sub>s\\<^sub>t_def bvars\\<^sub>s\\<^sub>s\\<^sub>t_def by force+\n    then obtain A' where A': \"A' \\<in> set (tr A D)\" \"\\<lbrakk>M; A'\\<rbrakk>\\<^sub>d \\<I>\" by (metis ConsEq.IH)\n    thus ?case using * by auto\n  next\n    case (ConsIns M D t s A)\n    have \"\\<lbrakk>M; set (List.insert (t,s) D) \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>; A\\<rbrakk>\\<^sub>s \\<I>\"\n         \"\\<forall>(t,t') \\<in> set (List.insert (t,s) D). (fv t \\<union> fv t') \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\n         \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" \"ground M\"\n      using ConsIns.prems unfolding fv\\<^sub>s\\<^sub>s\\<^sub>t_def bvars\\<^sub>s\\<^sub>s\\<^sub>t_def by force+\n    then obtain A' where A': \"A' \\<in> set (tr A (List.insert (t,s) D))\" \"\\<lbrakk>M; A'\\<rbrakk>\\<^sub>d \\<I>\"\n      by (metis ConsIns.IH)\n    thus ?case by auto\n  next\n    case (ConsDel M D t s A)\n    have *: \"\\<lbrakk>M; (set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) - {(t,s) \\<cdot>\\<^sub>p \\<I>}; A\\<rbrakk>\\<^sub>s \\<I>\"\n            \"\\<forall>(t,t')\\<in>set D. (fv t \\<union> fv t') \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\n            \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" \"ground M\"\n      using ConsDel.prems unfolding fv\\<^sub>s\\<^sub>s\\<^sub>t_def bvars\\<^sub>s\\<^sub>s\\<^sub>t_def by force+\n    then obtain Di where Di:\n        \"Di \\<subseteq> set D\" \"Di \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<subseteq> {(t,s) \\<cdot>\\<^sub>p \\<I>}\" \"(t,s) \\<cdot>\\<^sub>p \\<I> \\<notin> (set D - Di) \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n      using subset_subst_pairs_diff_exists'[of \"set D\"] by moura\n    hence **: \"(set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) - {(t,s) \\<cdot>\\<^sub>p \\<I>} = (set D - Di) \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" by blast\n\n    obtain Di' where Di': \"set Di' = Di\" \"Di' \\<in> set (subseqs D)\"\n      using subset_sublist_exists[OF Di(1)] by moura\n    hence ***: \"(set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) - {(t,s) \\<cdot>\\<^sub>p \\<I>} = (set [d\\<leftarrow>D. d \\<notin> set Di'] \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>)\"\n      using Di ** by auto\n    \n    define constr where \"constr \\<equiv>\n        map (\\<lambda>d. \\<langle>check: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t) Di'@\n        map (\\<lambda>d. \\<forall>[]\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) [d\\<leftarrow>D. d \\<notin> set Di']\"\n    \n    have ****: \"\\<forall>(t,t')\\<in>set [d\\<leftarrow>D. d \\<notin> set Di']. (fv t \\<union> fv t') \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\n      using *(2) Di(1) Di'(1) subseqs_set_subset[OF Di'(2)] by simp\n    have \"set D - Di = set [d\\<leftarrow>D. d \\<notin> set Di']\" using Di Di' by auto\n    hence *****: \"\\<lbrakk>M; set [d\\<leftarrow>D. d \\<notin> set Di'] \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>; A\\<rbrakk>\\<^sub>s \\<I>\"\n      using *(1) ** by metis\n    obtain A' where A': \"A' \\<in> set (tr A [d\\<leftarrow>D. d \\<notin> set Di'])\" \"\\<lbrakk>M; A'\\<rbrakk>\\<^sub>d \\<I>\"\n      using ConsDel.IH[OF ***** **** *(3,4)] by moura\n    hence constr_sat: \"\\<lbrakk>M; constr\\<rbrakk>\\<^sub>d \\<I>\"\n      using Di Di' *(1) *** tr_Delete_constr_iff[OF *(4), of \\<I> Di' t s D] \n      unfolding constr_def by auto\n\n    have \"constr@A' \\<in> set (tr (Delete t s#A) D)\" using A'(1) Di' unfolding constr_def by auto\n    moreover have \"ik\\<^sub>s\\<^sub>t constr = {}\" unfolding constr_def by auto\n    hence \"\\<lbrakk>M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>; constr\\<rbrakk>\\<^sub>d \\<I>\" \"\\<lbrakk>M \\<union> (ik\\<^sub>s\\<^sub>t constr \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>); A'\\<rbrakk>\\<^sub>d \\<I>\"\n      using constr_sat A'(2) subst_all_ground_ident[OF *(4)] by simp_all\n    ultimately show ?case\n      using strand_sem_append(2)[of _ _ \\<I>]\n            subst_all_ground_ident[OF *(4), of \\<I>]\n      by metis\n  next\n    case (ConsIn M D ac t s A)\n    have \"\\<lbrakk>M; set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>; A\\<rbrakk>\\<^sub>s \\<I>\"\n         \"\\<forall>(t,t') \\<in> set D. (fv t \\<union> fv t') \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\n         \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" \"ground M\"\n      and *: \"(t,s) \\<cdot>\\<^sub>p \\<I> \\<in> set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n      using \\<I> ConsIn.prems unfolding fv\\<^sub>s\\<^sub>s\\<^sub>t_def bvars\\<^sub>s\\<^sub>s\\<^sub>t_def by force+\n    then obtain A' where A': \"A' \\<in> set (tr A D)\" \"\\<lbrakk>M; A'\\<rbrakk>\\<^sub>d \\<I>\" by (metis ConsIn.IH)\n    moreover obtain d where \"d \\<in> set D\" \"pair (t,s) \\<cdot> \\<I> = pair d \\<cdot> \\<I>\"\n      using * unfolding pair_def by auto\n    ultimately show ?case using * by auto\n  next\n    case (ConsNegChecks M D X F F' A)\n    let ?ineqs = \"(map (\\<lambda>G. \\<forall>X\\<langle>\\<or>\\<noteq>: (F@G)\\<rangle>\\<^sub>s\\<^sub>t) (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' D))\"\n    have 1: \"\\<lbrakk>M; set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>; A\\<rbrakk>\\<^sub>s \\<I>\" \"ground M\" using ConsNegChecks by auto\n    have 2: \"\\<forall>(t,t') \\<in> set D. (fv t \\<union> fv t') \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" \n      using ConsNegChecks.prems(2,3) \\<I> unfolding fv\\<^sub>s\\<^sub>s\\<^sub>t_def bvars\\<^sub>s\\<^sub>s\\<^sub>t_def by fastforce+\n    \n    have 3: \"negchecks_model \\<I> (set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) X F F'\" using ConsNegChecks.prems(1) by simp\n    from 1 2 obtain A' where A': \"A' \\<in> set (tr A D)\" \"\\<lbrakk>M; A'\\<rbrakk>\\<^sub>d \\<I>\" by (metis ConsNegChecks.IH)\n    \n    have 4: \"\\<forall>(t,t') \\<in> set D. (fv t \\<union> fv t') \\<inter> set X = {}\"\n      using ConsNegChecks.prems(2) unfolding bvars\\<^sub>s\\<^sub>s\\<^sub>t_def by auto\n    \n    have \"\\<lbrakk>M; ?ineqs\\<rbrakk>\\<^sub>d \\<I>\"\n      using 3 tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_sem_equiv[OF 4] tr_NegChecks_constr_iff\n      by metis\n    moreover have \"ik\\<^sub>s\\<^sub>t ?ineqs = {}\" by auto\n    moreover have \"M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> = M\" using 1(2) \\<I> by (simp add: subst_all_ground_ident)\n    ultimately show ?case\n      using strand_sem_append(2)[of M ?ineqs \\<I> A'] A'\n      by force\n  qed simp\n  thus \"?P \\<Longrightarrow> ?Q\" by metis\n\n  have \"(\\<exists>A' \\<in> set (tr A D). \\<lbrakk>M; A'\\<rbrakk>\\<^sub>d \\<I>) \\<Longrightarrow> ?P\" using assms(1,2,3)\n  proof (induction A arbitrary: D rule: strand_sem_stateful_induct)\n    case (ConsRcv M D ts A)\n    have \"\\<exists>A' \\<in> set (tr A D). \\<lbrakk>(set ts \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> M; A'\\<rbrakk>\\<^sub>d \\<I>\"\n         \"\\<forall>(t,t') \\<in> set D. (fv t \\<union> fv t') \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\n         \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" \"ground ((set ts \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> M)\"\n      using \\<I> ConsRcv.prems unfolding fv\\<^sub>s\\<^sub>s\\<^sub>t_def bvars\\<^sub>s\\<^sub>s\\<^sub>t_def by force+\n    hence \"\\<lbrakk>(set ts \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<union> M; set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>; A\\<rbrakk>\\<^sub>s \\<I>\" by (metis ConsRcv.IH)\n    thus ?case by auto\n  next\n    case (ConsSnd M D ts A)\n    have \"\\<exists>A' \\<in> set (tr A D). \\<lbrakk>M; A'\\<rbrakk>\\<^sub>d \\<I>\"\n         \"\\<forall>(t,t') \\<in> set D. (fv t \\<union> fv t') \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\n         \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" \"ground M\"\n      and *: \"\\<forall>t \\<in> set ts. M \\<turnstile> t \\<cdot> \\<I>\"\n      using \\<I> ConsSnd.prems unfolding fv\\<^sub>s\\<^sub>s\\<^sub>t_def bvars\\<^sub>s\\<^sub>s\\<^sub>t_def by force+\n    hence \"\\<lbrakk>M; set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>; A\\<rbrakk>\\<^sub>s \\<I>\" by (metis ConsSnd.IH)\n    thus ?case using * by auto\n  next\n    case (ConsEq M D ac t t' A)\n    have \"\\<exists>A' \\<in> set (tr A D). \\<lbrakk>M; A'\\<rbrakk>\\<^sub>d \\<I>\"\n         \"\\<forall>(t,t') \\<in> set D. (fv t \\<union> fv t') \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\n         \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" \"ground M\"\n      and *: \"t \\<cdot> \\<I> = t' \\<cdot> \\<I>\"\n      using \\<I> ConsEq.prems unfolding fv\\<^sub>s\\<^sub>s\\<^sub>t_def bvars\\<^sub>s\\<^sub>s\\<^sub>t_def by force+\n    hence \"\\<lbrakk>M; set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>; A\\<rbrakk>\\<^sub>s \\<I>\" by (metis ConsEq.IH)\n    thus ?case using * by auto\n  next\n    case (ConsIns M D t s A)\n    hence \"\\<exists>A' \\<in> set (tr A (List.insert (t,s) D)). \\<lbrakk>M; A'\\<rbrakk>\\<^sub>d \\<I>\"\n          \"\\<forall>(t,t') \\<in> set (List.insert (t,s) D). (fv t \\<union> fv t') \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\n          \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" \"ground M\"\n      unfolding fv\\<^sub>s\\<^sub>s\\<^sub>t_def bvars\\<^sub>s\\<^sub>s\\<^sub>t_def by auto+\n    hence \"\\<lbrakk>M; set (List.insert (t,s) D) \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>; A\\<rbrakk>\\<^sub>s \\<I>\" by (metis ConsIns.IH)\n    thus ?case by auto\n  next\n    case (ConsDel M D t s A)\n    define constr where \"constr \\<equiv>\n      \\<lambda>Di. map (\\<lambda>d. \\<langle>check: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t) Di@\n           map (\\<lambda>d. \\<forall>[]\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) [d\\<leftarrow>D. d \\<notin> set Di]\"\n    let ?flt = \"\\<lambda>Di. filter (\\<lambda>d. d \\<notin> set Di) D\"\n\n    have \"\\<exists>Di \\<in> set (subseqs D). \\<exists>B' \\<in> set (tr A (?flt Di)). B = constr Di@B'\"\n      when \"B \\<in> set (tr (delete\\<langle>t,s\\<rangle>#A) D)\" for B\n      using that unfolding constr_def by auto\n    then obtain A' Di where A':\n        \"constr Di@A' \\<in> set (tr (Delete t s#A) D)\"\n        \"A' \\<in> set (tr A (?flt Di))\"\n        \"Di \\<in> set (subseqs D)\"\n        \"\\<lbrakk>M; constr Di@A'\\<rbrakk>\\<^sub>d \\<I>\"\n      using ConsDel.prems(1) by blast\n\n    have 1: \"\\<forall>(t,t')\\<in>set (?flt Di). (fv t \\<union> fv t') \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" using ConsDel.prems(2) by auto\n    have 2: \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" using ConsDel.prems(3) by force+\n    have \"ik\\<^sub>s\\<^sub>t (constr Di) = {}\" unfolding constr_def by auto\n    hence 3: \"\\<lbrakk>M; A'\\<rbrakk>\\<^sub>d \\<I>\"\n      using subst_all_ground_ident[OF ConsDel.prems(4)] A'(4)\n            strand_sem_split(4)[of M \"constr Di\" A' \\<I>]\n      by simp\n    have IH: \"\\<lbrakk>M; set (?flt Di) \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>; A\\<rbrakk>\\<^sub>s \\<I>\"\n      by (metis ConsDel.IH[OF _ 1 2 ConsDel.prems(4)] 3 A'(2))\n\n    have \"\\<lbrakk>M; constr Di\\<rbrakk>\\<^sub>d \\<I>\"\n      using subst_all_ground_ident[OF ConsDel.prems(4)] strand_sem_split(3) A'(4)\n      by metis\n    hence *: \"set Di \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<subseteq> {(t,s) \\<cdot>\\<^sub>p \\<I>}\" \"(t,s) \\<cdot>\\<^sub>p \\<I> \\<notin> (set D - set Di) \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n      using tr_Delete_constr_iff[OF ConsDel.prems(4), of \\<I> Di t s D] unfolding constr_def by auto\n    have 4: \"set (?flt Di) \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I> = (set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) - {((t,s) \\<cdot>\\<^sub>p \\<I>)}\"\n    proof\n      show \"set (?flt Di) \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<subseteq> (set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) - {((t,s) \\<cdot>\\<^sub>p \\<I>)}\"\n      proof\n        fix u u' assume u: \"(u,u') \\<in> set (?flt Di) \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n        then obtain v v' where v: \"(v,v') \\<in> set D - set Di\" \"(v,v') \\<cdot>\\<^sub>p \\<I> = (u,u')\" by auto\n        hence \"(u,u') \\<noteq> (t,s) \\<cdot>\\<^sub>p \\<I>\" using * by force\n        thus \"(u,u') \\<in>  (set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) - {((t,s) \\<cdot>\\<^sub>p \\<I>)}\"\n          using u v * subseqs_set_subset[OF A'(3)] by auto\n      qed\n      show \"(set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) - {((t,s) \\<cdot>\\<^sub>p \\<I>)} \\<subseteq> set (?flt Di) \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n        using * subseqs_set_subset[OF A'(3)] by force\n    qed\n\n    show ?case using 4 IH by simp\n  next\n    case (ConsIn M D ac t s A)\n    have \"\\<exists>A' \\<in> set (tr A D). \\<lbrakk>M; A'\\<rbrakk>\\<^sub>d \\<I>\"\n         \"\\<forall>(t,t') \\<in> set D. (fv t \\<union> fv t') \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\n         \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" \"ground M\"\n      and *: \"(t,s) \\<cdot>\\<^sub>p \\<I> \\<in> set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n      using ConsIn.prems(1,2,3,4) apply (fastforce, fastforce, fastforce, fastforce)\n      using ConsIn.prems(1) tr.simps(7)[of ac t s A D] unfolding pair_def by fastforce\n    hence \"\\<lbrakk>M; set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>; A\\<rbrakk>\\<^sub>s \\<I>\" by (metis ConsIn.IH)\n    moreover obtain d where \"d \\<in> set D\" \"pair (t,s) \\<cdot> \\<I> = pair d \\<cdot> \\<I>\"\n      using * unfolding pair_def by auto\n    ultimately show ?case using * by auto\n  next\n    case (ConsNegChecks M D X F F' A)\n    let ?ineqs = \"(map (\\<lambda>G. \\<forall>X\\<langle>\\<or>\\<noteq>: (F@G)\\<rangle>\\<^sub>s\\<^sub>t) (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' D))\"\n\n    obtain B where B:\n        \"?ineqs@B \\<in> set (tr (NegChecks X F F'#A) D)\" \"\\<lbrakk>M; ?ineqs@B\\<rbrakk>\\<^sub>d \\<I>\" \"B \\<in> set (tr A D)\"\n      using ConsNegChecks.prems(1) by moura\n    moreover have \"M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> = M\"\n      using ConsNegChecks.prems(4) \\<I> by (simp add: subst_all_ground_ident)\n    moreover have \"ik\\<^sub>s\\<^sub>t ?ineqs = {}\" by auto\n    ultimately have \"\\<lbrakk>M; B\\<rbrakk>\\<^sub>d \\<I>\" using strand_sem_split(4)[of M ?ineqs B \\<I>] by simp\n    moreover have \"\\<forall>(t,t')\\<in>set D. (fv t \\<union> fv t') \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\n      using ConsNegChecks.prems(2,3) unfolding fv\\<^sub>s\\<^sub>s\\<^sub>t_def bvars\\<^sub>s\\<^sub>s\\<^sub>t_def by force+\n    ultimately have \"\\<lbrakk>M; set D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>; A\\<rbrakk>\\<^sub>s \\<I>\"\n      by (metis ConsNegChecks.IH B(3) ConsNegChecks.prems(4))\n    moreover have \"\\<forall>(t, t')\\<in>set D. (fv t \\<union> fv t') \\<inter> set X = {}\"\n      using ConsNegChecks.prems(2) unfolding bvars\\<^sub>s\\<^sub>s\\<^sub>t_def by force\n    ultimately show ?case\n      using tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_sem_equiv tr_NegChecks_constr_iff\n            B(2) strand_sem_split(3)[of M ?ineqs B \\<I>] \\<open>M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> = M\\<close>\n      by simp\n  qed simp\n  thus \"?Q \\<Longrightarrow> ?P\" by metis\nqed\n\nlemma tr_sem_equiv:\n  assumes \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" and \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\"\n  shows \"\\<I> \\<Turnstile>\\<^sub>s A \\<longleftrightarrow> (\\<exists>A' \\<in> set (tr A []). (\\<I> \\<Turnstile> \\<langle>A'\\<rangle>))\"\nusing tr_sem_equiv'[OF _ assms(1) _ assms(2), of \"[]\" \"{}\"]\nunfolding constr_sem_d_def\nby auto\n\nend\n\nend\n\n\nsubsubsection \\<open>Typing Result Locale Definition\\<close>\n\nlocale stateful_typing_result =\n  stateful_typed_model arity public Ana \\<Gamma> Pair\n+ typing_result arity public Ana \\<Gamma>\n  for arity::\"'fun \\<Rightarrow> nat\"\n    and public::\"'fun \\<Rightarrow> bool\"\n    and Ana::\"('fun,'var) term \\<Rightarrow> (('fun,'var) term list \\<times> ('fun,'var) term list)\"\n    and \\<Gamma>::\"('fun,'var) term \\<Rightarrow> ('fun,'atom::finite) term_type\"\n    and Pair::\"'fun\"\n\n\nsubsubsection \\<open>Type-Flaw Resistance Preservation of the Constraint Reduction\\<close>\ncontext stateful_typing_result\nbegin\n\ncontext\nbegin\n\nprivate lemma tr_tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p:\n  assumes \"A' \\<in> set (tr A D)\" \"list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p A\"\n  and \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" (is \"?P0 A D\")\n  and \"\\<forall>(t,s) \\<in> set D. (fv t \\<union> fv s) \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" (is \"?P1 A D\")\n  and \"\\<forall>t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` set D. \\<forall>t' \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` set D.\n          (\\<exists>\\<delta>. Unifier \\<delta> t t') \\<longrightarrow> \\<Gamma> t = \\<Gamma> t'\" (is \"?P3 A D\")\n  shows \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p A'\"\nproof -\n  have sublmm: \"list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p A\" \"?P0 A D\" \"?P1 A D\" \"?P3 A D\"\n    when p: \"list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (a#A)\" \"?P0 (a#A) D\" \"?P1 (a#A) D\" \"?P3 (a#A) D\"\n    for a A D\n    using p(1) apply (simp add: tfr\\<^sub>s\\<^sub>s\\<^sub>t_def)\n    using p(2) fv\\<^sub>s\\<^sub>s\\<^sub>t_cons_subset bvars\\<^sub>s\\<^sub>s\\<^sub>t_cons_subset apply fast\n    using p(3) bvars\\<^sub>s\\<^sub>s\\<^sub>t_cons_subset apply fast\n    using p(4) setops\\<^sub>s\\<^sub>s\\<^sub>t_cons_subset by fast\n\n  show ?thesis using assms\n  proof (induction A D arbitrary: A' rule: tr.induct)\n    case 1 thus ?case by simp\n  next\n    case (2 t A D)\n    note prems = \"2.prems\"\n    note IH = \"2.IH\"\n    from prems(1) obtain A'' where A'': \"A' = send\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#A''\" \"A'' \\<in> set (tr A D)\"\n      by moura\n    have \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p A''\" using IH[OF A''(2)] prems(5) sublmm[OF prems(2,3,4,5)] by meson\n    thus ?case using A''(1) by simp\n  next\n    case (3 t A D)\n    note prems = \"3.prems\"\n    note IH = \"3.IH\"\n    from prems(1) obtain A'' where A'': \"A' = receive\\<langle>t\\<rangle>\\<^sub>s\\<^sub>t#A''\" \"A'' \\<in> set (tr A D)\"\n      by moura\n    have \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p A''\" using IH[OF A''(2)] prems(5) sublmm[OF prems(2,3,4,5)] by meson\n    thus ?case using A''(1) by simp\n  next\n    case (4 ac t t' A D)\n    note prems = \"4.prems\"\n    note IH = \"4.IH\"\n    from prems(1) obtain A'' where A'':\n        \"A' = \\<langle>ac: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t#A''\" \"A'' \\<in> set (tr A D)\"\n      by moura\n    have \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p A''\" using IH[OF A''(2)] prems(5) sublmm[OF prems(2,3,4,5)] by meson\n    moreover have \"(\\<exists>\\<delta>. Unifier \\<delta> t t') \\<Longrightarrow> \\<Gamma> t = \\<Gamma> t'\" using prems(2) by (simp add: tfr\\<^sub>s\\<^sub>s\\<^sub>t_def)\n    ultimately show ?case using A''(1) by auto\n  next\n    case (5 t s A D)\n    note prems = \"5.prems\"\n    note IH = \"5.IH\"\n    from prems(1) have A': \"A' \\<in> set (tr A (List.insert (t,s) D))\" by simp\n  \n    have 1: \"list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p A\" using sublmm[OF prems(2,3,4,5)] by simp\n  \n    have \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (Insert t s#A) \\<union> pair`set D =\n          pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair`set (List.insert (t,s) D)\"\n      by (simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n    hence 3: \"?P3 A (List.insert (t,s) D)\" using prems(5) by metis\n    moreover have \"?P1 A (List.insert (t, s) D)\" using prems(3,4) bvars\\<^sub>s\\<^sub>s\\<^sub>t_cons_subset[of A] by auto\n    ultimately have \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p A'\" using IH[OF A' sublmm(1,2)[OF prems(2,3,4,5)] _ 3] by metis\n    thus ?case using A'(1) by auto\n  next\n    case (6 t s A D)\n    note prems = \"6.prems\"\n    note IH = \"6.IH\"\n    \n    define constr where constr:\n      \"constr \\<equiv> (\\<lambda>Di. (map (\\<lambda>d. \\<langle>check: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t) Di)@\n                       (map (\\<lambda>d. \\<forall>[]\\<langle>\\<or>\\<noteq>: [(pair (t,s), pair d)]\\<rangle>\\<^sub>s\\<^sub>t) [d\\<leftarrow>D. d \\<notin> set Di]))\"\n    \n    from prems(1) obtain Di A'' where A'':\n        \"A' = constr Di@A''\" \"A'' \\<in> set (tr A [d\\<leftarrow>D. d \\<notin> set Di])\"\n        \"Di \\<in> set (subseqs D)\"\n      unfolding constr by auto\n  \n    define Q1 where \"Q1 \\<equiv> (\\<lambda>(F::(('fun,'var) term \\<times> ('fun,'var) term) list) X.\n        \\<forall>x \\<in> (fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F) - set X. \\<exists>a. \\<Gamma> (Var x) = TAtom a)\"\n\n    define Q2 where \"Q2 \\<equiv> (\\<lambda>(F::(('fun,'var) term \\<times> ('fun,'var) term) list) X.\n        \\<forall>f T. Fun f T \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F) \\<longrightarrow> T = [] \\<or> (\\<exists>s \\<in> set T. s \\<notin> Var ` set X))\"\n  \n    have \"set [d\\<leftarrow>D. d \\<notin> set Di] \\<subseteq> set D\"\n         \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` set [d\\<leftarrow>D. d \\<notin> set Di]\n          \\<subseteq> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (Delete t s#A) \\<union> pair ` set D\"\n      by (auto simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n    hence *: \"?P3 A [d\\<leftarrow>D. d \\<notin> set Di]\" using prems(5) by blast\n    have **: \"?P1 A [d\\<leftarrow>D. d \\<notin> set Di]\" using prems(4,5) by auto\n    have 1: \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p A''\"\n      using IH[OF A''(3,2) sublmm(1,2)[OF prems(2,3,4,5)] ** *]\n      by metis\n  \n    have 2: \"\\<langle>ac: u \\<doteq> u'\\<rangle>\\<^sub>s\\<^sub>t \\<in> set A'' \\<or>\n             (\\<exists>d \\<in> set Di. u = pair (t,s) \\<and> u' = pair d)\"\n      when \"\\<langle>ac: u \\<doteq> u'\\<rangle>\\<^sub>s\\<^sub>t \\<in> set A'\" for ac u u'\n      using that A''(1) unfolding constr by force\n    have 3: \"Inequality X U \\<in> set A' \\<Longrightarrow> Inequality X U \\<in> set A'' \\<or>\n             (\\<exists>d \\<in> set [d\\<leftarrow>D. d \\<notin> set Di].\n                U = [(pair (t,s), pair d)] \\<and> Q2 [(pair (t,s), pair d)] X)\"\n        for X U\n      using A''(1) unfolding Q2_def constr by force\n    have 4:\n        \"\\<forall>d\\<in>set D. (\\<exists>\\<delta>. Unifier \\<delta> (pair (t,s)) (pair d)) \\<longrightarrow> \\<Gamma> (pair (t,s)) = \\<Gamma> (pair d)\"\n      using prems(5) by (simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n  \n    { fix ac u u'\n      assume a: \"\\<langle>ac: u \\<doteq> u'\\<rangle>\\<^sub>s\\<^sub>t \\<in> set A'\" \"\\<exists>\\<delta>. Unifier \\<delta> u u'\"\n      hence \"\\<langle>ac: u \\<doteq> u'\\<rangle>\\<^sub>s\\<^sub>t \\<in> set A'' \\<or> (\\<exists>d \\<in> set Di. u = pair (t,s) \\<and> u' = pair d)\"\n        using 2 by metis\n      hence \"\\<Gamma> u = \\<Gamma> u'\"\n        using 1(1) 4 subseqs_set_subset[OF A''(3)] a(2) tfr\\<^sub>s\\<^sub>t\\<^sub>p_list_all_alt_def[of A'']\n        by blast\n    } moreover {\n      fix u U\n      assume \"\\<forall>U\\<langle>\\<or>\\<noteq>: u\\<rangle>\\<^sub>s\\<^sub>t \\<in> set A'\"\n      hence \"\\<forall>U\\<langle>\\<or>\\<noteq>: u\\<rangle>\\<^sub>s\\<^sub>t \\<in> set A'' \\<or>\n             (\\<exists>d \\<in> set [d\\<leftarrow>D. d \\<notin> set Di]. u = [(pair (t,s), pair d)] \\<and> Q2 u U)\"\n        using 3 by metis\n      hence \"Q1 u U \\<or> Q2 u U\"\n        using 1 4 subseqs_set_subset[OF A''(3)] tfr\\<^sub>s\\<^sub>t\\<^sub>p_list_all_alt_def[of A'']\n        unfolding Q1_def Q2_def\n        by blast\n    } ultimately show ?case using tfr\\<^sub>s\\<^sub>t\\<^sub>p_list_all_alt_def[of A'] unfolding Q1_def Q2_def by blast\n  next\n    case (7 ac t s A D)\n    note prems = \"7.prems\"\n    note IH = \"7.IH\"\n\n    from prems(1) obtain d A'' where A'':\n        \"A' = \\<langle>ac: (pair (t,s)) \\<doteq> (pair d)\\<rangle>\\<^sub>s\\<^sub>t#A''\"\n        \"A'' \\<in> set (tr A D)\" \"d \\<in> set D\"\n      by moura\n\n    have \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p A''\"\n      using IH[OF A''(2) sublmm(1,2,3)[OF prems(2,3,4,5)] sublmm(4)[OF prems(2,3,4,5)]]\n      by metis\n    moreover have \"(\\<exists>\\<delta>. Unifier \\<delta> (pair (t,s)) (pair d)) \\<Longrightarrow> \\<Gamma> (pair (t,s)) = \\<Gamma> (pair d)\"\n      using prems(2,5) A''(3) unfolding tfr\\<^sub>s\\<^sub>s\\<^sub>t_def by (simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n    ultimately show ?case using A''(1) by fastforce\n  next\n    case (8 X F F' A D)\n    note prems = \"8.prems\"\n    note IH = \"8.IH\"\n\n    define constr where \"constr = (map (\\<lambda>G. \\<forall>X\\<langle>\\<or>\\<noteq>: (F@G)\\<rangle>\\<^sub>s\\<^sub>t) (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' D))\"\n\n    define Q1 where \"Q1 \\<equiv> (\\<lambda>(F::(('fun,'var) term \\<times> ('fun,'var) term) list) X.\n        \\<forall>x \\<in> (fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F) - set X. \\<exists>a. \\<Gamma> (Var x) = TAtom a)\"\n\n    define Q2 where \"Q2 \\<equiv> (\\<lambda>(M::('fun,'var) terms) X.\n        \\<forall>f T. Fun f T \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t M \\<longrightarrow> T = [] \\<or> (\\<exists>s \\<in> set T. s \\<notin> Var ` set X))\"\n\n    have Q2_subset: \"Q2 M' X\" when \"M' \\<subseteq> M\" \"Q2 M X\" for X M M'\n      using that unfolding Q2_def by auto\n\n    have Q2_supset: \"Q2 (M \\<union> M') X\" when \"Q2 M X\" \"Q2 M' X\" for X M M'\n      using that unfolding Q2_def by auto\n\n    from prems(1) obtain A'' where A'': \"A' = constr@A''\" \"A'' \\<in> set (tr A D)\"\n      using constr_def by moura\n\n    have 0: \"F' = [] \\<Longrightarrow> constr = [\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t]\" unfolding constr_def by simp\n\n    have 1: \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p A''\"\n      using IH[OF A''(2) sublmm(1,2,3)[OF prems(2,3,4,5)] sublmm(4)[OF prems(2,3,4,5)]]\n      by metis\n\n    have 2: \"(F' = [] \\<and> Q1 F X) \\<or> Q2 (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> pair ` set F') X\"\n      using prems(2) unfolding Q1_def Q2_def by simp\n  \n    have 3: \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p constr\" when \"F' = []\" \"Q1 F X\"\n      using that 0 2 tfr\\<^sub>s\\<^sub>t\\<^sub>p_list_all_alt_def[of constr] unfolding Q1_def by auto\n\n    { fix c assume \"c \\<in> set constr\"\n      hence \"\\<exists>G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' D). c = \\<forall>X\\<langle>\\<or>\\<noteq>: (F@G)\\<rangle>\\<^sub>s\\<^sub>t\" unfolding constr_def by force\n    } moreover {\n      fix G\n      assume G: \"G \\<in> set (tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' D)\"\n         and c: \"\\<forall>X\\<langle>\\<or>\\<noteq>: (F@G)\\<rangle>\\<^sub>s\\<^sub>t \\<in> set constr\"\n         and e: \"Q2 (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> pair ` set F') X\"\n\n      have d_Q2: \"Q2 (pair ` set D) X\" unfolding Q2_def\n      proof (intro allI impI)\n        fix f T assume \"Fun f T \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (pair ` set D)\"\n        then obtain d where d: \"d \\<in> set D\" \"Fun f T \\<in> subterms (pair d)\" by auto\n        hence \"fv (pair d) \\<inter> set X = {}\" using prems(4) unfolding pair_def by force\n        thus \"T = [] \\<or> (\\<exists>s \\<in> set T. s \\<notin> Var ` set X)\"\n          by (metis fv_disj_Fun_subterm_param_cases d(2))\n      qed\n\n      have \"trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (F@G) \\<subseteq> trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> pair ` set F' \\<union> pair ` set D\"\n        using tr\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_trms_subset[OF G] by auto\n      hence \"Q2 (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (F@G)) X\" using Q2_subset[OF _ Q2_supset[OF e d_Q2]] by metis\n      hence \"tfr\\<^sub>s\\<^sub>t\\<^sub>p (\\<forall>X\\<langle>\\<or>\\<noteq>: (F@G)\\<rangle>\\<^sub>s\\<^sub>t)\" by (metis Q2_def tfr\\<^sub>s\\<^sub>t\\<^sub>p.simps(2))\n    } ultimately have 4: \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p constr\" when \"Q2 (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> pair ` set F') X\"\n      using that Ball_set by blast\n\n    have 5: \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p constr\" using 2 3 4 by metis\n\n    show ?case using 1 5 A''(1) by simp\n  qed\nqed\n\nlemma tr_tfr:\n  assumes \"A' \\<in> set (tr A [])\" and \"tfr\\<^sub>s\\<^sub>s\\<^sub>t A\" and \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\n  shows \"tfr\\<^sub>s\\<^sub>t A'\"\nproof -\n  have *: \"trms\\<^sub>s\\<^sub>t A' \\<subseteq> trms\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A\" using tr_trms_subset[OF assms(1)] by simp\n  hence \"SMP (trms\\<^sub>s\\<^sub>t A') \\<subseteq> SMP (trms\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A)\" using SMP_mono by simp\n  moreover have \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A)\" using assms(2) unfolding tfr\\<^sub>s\\<^sub>s\\<^sub>t_def by fast\n  ultimately have 1: \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t A')\" by (metis tfr_subset(2)[OF _ *])\n\n  have **: \"list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p A\" using assms(2) unfolding tfr\\<^sub>s\\<^sub>s\\<^sub>t_def by fast\n  have \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A \\<subseteq> SMP (trms\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t A) - Var`\\<V>\"\n    using setops\\<^sub>s\\<^sub>s\\<^sub>t_are_pairs unfolding pair_def by auto\n  hence ***: \"\\<forall>t \\<in> pair`setops\\<^sub>s\\<^sub>s\\<^sub>t A. \\<forall>t' \\<in> pair`setops\\<^sub>s\\<^sub>s\\<^sub>t A. (\\<exists>\\<delta>. Unifier \\<delta> t t') \\<longrightarrow> \\<Gamma> t = \\<Gamma> t'\"\n    using assms(2) unfolding tfr\\<^sub>s\\<^sub>s\\<^sub>t_def tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by blast\n  have 2: \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p A'\"\n    using tr_tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p[OF assms(1) ** assms(3)] *** unfolding pair_def by fastforce\n\n  show ?thesis by (metis 1 2 tfr\\<^sub>s\\<^sub>t_def)\nqed\n\nend\n\nend\n\n\nsubsubsection \\<open>Theorem: The Stateful Typing Result\\<close>\ncontext stateful_typing_result\nbegin\n\ntheorem stateful_typing_result:\n  assumes \"wf\\<^sub>s\\<^sub>s\\<^sub>t \\<A>\"\n    and \"tfr\\<^sub>s\\<^sub>s\\<^sub>t \\<A>\"\n    and \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)\"\n    and \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\"\n    and \"\\<I> \\<Turnstile>\\<^sub>s \\<A>\"\n  obtains \\<I>\\<^sub>\\<tau>\n    where \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\\<^sub>\\<tau>\"\n    and \"\\<I>\\<^sub>\\<tau> \\<Turnstile>\\<^sub>s \\<A>\"\n    and \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\\<^sub>\\<tau>\"\n    and \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<I>\\<^sub>\\<tau>)\"\nproof -\n  obtain \\<A>' where \\<A>':\n      \"\\<A>' \\<in> set (tr \\<A> [])\" \"\\<I> \\<Turnstile> \\<langle>\\<A>'\\<rangle>\"\n    using tr_sem_equiv[of \\<A>] assms(1,4,5)\n    by auto\n\n  have *: \"wf\\<^sub>s\\<^sub>t {} \\<A>'\"\n          \"fv\\<^sub>s\\<^sub>t \\<A>' \\<inter> bvars\\<^sub>s\\<^sub>t \\<A>' = {}\"\n          \"tfr\\<^sub>s\\<^sub>t \\<A>'\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t \\<A>')\"\n    using tr_wf[OF \\<A>'(1) assms(1,3)]\n          tr_tfr[OF \\<A>'(1) assms(2)] assms(1)\n    by metis+\n\n  obtain \\<I>\\<^sub>\\<tau> where \\<I>\\<^sub>\\<tau>:\n      \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\\<^sub>\\<tau>\" \"\\<lbrakk>{}; \\<A>'\\<rbrakk>\\<^sub>d \\<I>\\<^sub>\\<tau>\"\n      \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\\<^sub>\\<tau>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<I>\\<^sub>\\<tau>)\"\n    using wt_attack_if_tfr_attack_d \n          * Ana_invar_subst' assms(4)\n          \\<A>'(2)\n    unfolding constr_sem_d_def\n    by moura\n\n  thus ?thesis\n    using that tr_sem_equiv[of \\<A>] assms(1,3) \\<A>'(1)\n    unfolding constr_sem_d_def\n    by auto\nqed\n\nend\n\n\nsubsection \\<open>Proving Type-Flaw Resistance Automatically\\<close>\ndefinition pair' where\n  \"pair' pair_fun d \\<equiv> case d of (t,t') \\<Rightarrow> Fun pair_fun [t,t']\"\n\nfun comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p where\n  \"comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<Gamma> pair_fun (\\<langle>_: t \\<doteq> t'\\<rangle>) = (mgu t t' \\<noteq> None \\<longrightarrow> \\<Gamma> t = \\<Gamma> t')\"\n| \"comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<Gamma> pair_fun (\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: F'\\<rangle>) = (\n    (F' = [] \\<and> (\\<forall>x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F - set X. is_Var (\\<Gamma> (Var x)))) \\<or>\n    (\\<forall>u \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> pair' pair_fun ` set F').\n      is_Fun u \\<longrightarrow> (args u = [] \\<or> (\\<exists>s \\<in> set (args u). s \\<notin> Var ` set X))))\"\n| \"comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p _ _ _ = True\"\n\ndefinition comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t where\n  \"comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t arity Ana \\<Gamma> pair_fun M S \\<equiv>\n    list_all (comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<Gamma> pair_fun) S \\<and>\n    list_all (wf\\<^sub>t\\<^sub>r\\<^sub>m' arity) (trms_list\\<^sub>s\\<^sub>s\\<^sub>t S) \\<and>\n    has_all_wt_instances_of \\<Gamma> (trms\\<^sub>s\\<^sub>s\\<^sub>t S \\<union> pair' pair_fun ` setops\\<^sub>s\\<^sub>s\\<^sub>t S) M \\<and>\n    comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t arity Ana \\<Gamma> M\"\n\nlocale stateful_typed_model' = stateful_typed_model arity public Ana \\<Gamma> Pair\n  for arity::\"'fun \\<Rightarrow> nat\"\n    and public::\"'fun \\<Rightarrow> bool\"\n    and Ana::\"('fun,(('fun,'atom::finite) term_type \\<times> nat)) term\n              \\<Rightarrow> (('fun,(('fun,'atom) term_type \\<times> nat)) term list\n                 \\<times> ('fun,(('fun,'atom) term_type \\<times> nat)) term list)\"\n    and \\<Gamma>::\"('fun,(('fun,'atom) term_type \\<times> nat)) term \\<Rightarrow> ('fun,'atom) term_type\"\n    and Pair::\"'fun\"\n  +\n  assumes \\<Gamma>_Var_fst': \"\\<And>\\<tau> n m. \\<Gamma> (Var (\\<tau>,n)) = \\<Gamma> (Var (\\<tau>,m))\"\n    and Ana_const': \"\\<And>c T. arity c = 0 \\<Longrightarrow> Ana (Fun c T) = ([], [])\"\nbegin\n\nsublocale typed_model'\nby (unfold_locales, rule \\<Gamma>_Var_fst', metis Ana_const', metis Ana_subst')\n\nlemma pair_code:\n  \"pair d = pair' Pair d\"\nby (simp add: pair_def pair'_def)\n\nend\n\nlocale stateful_typing_result' =\n  stateful_typed_model' arity public Ana \\<Gamma> Pair + stateful_typing_result arity public Ana \\<Gamma> Pair\n  for arity::\"'fun \\<Rightarrow> nat\"\n    and public::\"'fun \\<Rightarrow> bool\"\n    and Ana::\"('fun,(('fun,'atom::finite) term_type \\<times> nat)) term\n              \\<Rightarrow> (('fun,(('fun,'atom) term_type \\<times> nat)) term list\n                 \\<times> ('fun,(('fun,'atom) term_type \\<times> nat)) term list)\"\n    and \\<Gamma>::\"('fun,(('fun,'atom) term_type \\<times> nat)) term \\<Rightarrow> ('fun,'atom) term_type\"\n    and Pair::\"'fun\"\nbegin\n\nlemma tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_is_comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p: \"tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a = comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<Gamma> Pair a\"\nproof (cases a)\n  case (Equality ac t t')\n  thus ?thesis\n    using mgu_always_unifies[of t _ t'] mgu_gives_MGU[of t t']\n    by auto\nnext\n  case (NegChecks X F F')\n  thus ?thesis\n    using tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p.simps(2)[of X F F']\n          comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p.simps(2)[of \\<Gamma> Pair X F F']\n          Fun_range_case(2)[of \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> pair ` set F')\"]\n    unfolding is_Var_def pair_code[symmetric]\n    by auto\nqed auto\n\nlemma tfr\\<^sub>s\\<^sub>s\\<^sub>t_if_comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t:\n  assumes \"comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t arity Ana \\<Gamma> Pair M S\"\n  shows \"tfr\\<^sub>s\\<^sub>s\\<^sub>t S\"\nunfolding tfr\\<^sub>s\\<^sub>s\\<^sub>t_def\nproof\n  have comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t_M: \"comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t arity Ana \\<Gamma> M\"\n    using assms unfolding comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t_def by blast\n\n  have SMP_repr_M: \"finite_SMP_representation arity Ana \\<Gamma> M\"\n    using comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t_M unfolding comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by blast\n  \n  have wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s_M: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s M\"\n      and wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s_S: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>s\\<^sub>t S \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S)\"\n      and S_trms_instance_M: \"has_all_wt_instances_of \\<Gamma> (trms\\<^sub>s\\<^sub>s\\<^sub>t S \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S) M\"\n    using assms setops\\<^sub>s\\<^sub>s\\<^sub>t_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s(2)[of S] trms_list\\<^sub>s\\<^sub>s\\<^sub>t_is_trms\\<^sub>s\\<^sub>s\\<^sub>t[of S]\n          finite_SMP_representationD[OF SMP_repr_M]\n    unfolding comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t_def comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t_def list_all_iff pair_code[symmetric] wf\\<^sub>t\\<^sub>r\\<^sub>m_code[symmetric]\n              finite_SMP_representation_def\n    by (meson, argo, argo)\n\n  show \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t S \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t S)\"\n    using tfr_subset(3)[OF tfr\\<^sub>s\\<^sub>e\\<^sub>t_if_comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t[OF comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t_M] SMP_SMP_subset]\n          SMP_I'[OF wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s_S wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s_M S_trms_instance_M]\n    by blast\n\n  have \"list_all (comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<Gamma> Pair) S\" by (metis assms comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t_def)\n  thus \"list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p S\" by (induct S) (simp_all add: tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_is_comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p)\nqed\n\nlemma tfr\\<^sub>s\\<^sub>s\\<^sub>t_if_comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t':\n  fixes S\n  defines \"M \\<equiv> SMP0 Ana \\<Gamma> (trms_list\\<^sub>s\\<^sub>s\\<^sub>t S@map pair (setops_list\\<^sub>s\\<^sub>s\\<^sub>t S))\"\n  assumes comp_tfr: \"comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t arity Ana \\<Gamma> Pair (set M) S\"\n  shows \"tfr\\<^sub>s\\<^sub>s\\<^sub>t S\"\nby (rule tfr\\<^sub>s\\<^sub>s\\<^sub>t_if_comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t[OF comp_tfr[unfolded M_def]])\n\nend\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Stateful_Protocol_Composition_and_Typing/Stateful_Typing.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.5, "lm_q1q2_score": 0.27723523248021364}}
{"text": "theory \"Andrew_cert_auto\"\nimports\n  \"ESPLogic\"\nbegin\n\n(* section:  Andrew Secure RPC  *)\n\n(* text: \n  We do not have the original model of the Isabelle/OFMC AndrewRPC protocol.\n  Therefore, we orient ourself on the SPORE library model.\n\n  Notable differences:\n\n    1. Instead of implicit typing, we are using explicit global constants to\n       discern messages.\n *)\n\nrole I\nwhere \"I =\n  [ Send ''1'' <| sAV ''I'',\n                  PEnc <| sC ''TT1'', sN ''ni'' |> ( sK ''I'' ''R'' )\n               |>\n  , Recv ''2'' ( PEnc <| sC ''TT2'', PHash <| sC ''TT1'', sN ''ni'' |>,\n                         sMV ''nr''\n                      |>\n                      ( sK ''I'' ''R'' )\n               )\n  , Send ''3'' ( PEnc <| sC ''TT3'', PHash <| sC ''TT1'', sMV ''nr'' |> |>\n                      ( sK ''I'' ''R'' )\n               )\n  , Recv ''4'' ( PEnc <| sC ''TT4'', sMV ''kIR'', sMV ''nr2'' |>\n                      ( sK ''I'' ''R'' )\n               )\n  ]\"\n\nrole R\nwhere \"R =\n  [ Recv ''1'' <| sMV ''I'',\n                  PEnc <| sC ''TT1'', sMV ''ni'' |> ( PSymK ( sMV ''I'' ) ( sAV ''R'' ) )\n               |>\n  , Send ''2'' ( PEnc <| sC ''TT2'', PHash <| sC ''TT1'', sMV ''ni'' |>,\n                         sN ''nr''\n                      |>\n                      ( PSymK ( sMV ''I'' ) ( sAV ''R'' ) )\n               )\n  , Recv ''3'' ( PEnc <| sC ''TT3'', PHash <| sC ''TT1'', sN ''nr'' |> |>\n                      ( PSymK ( sMV ''I'' ) ( sAV ''R'' ) )\n               )\n  , Send ''4'' ( PEnc <| sC ''TT4'', sN ''kIR'', sN ''nr2'' |>\n                      ( PSymK ( sMV ''I'' ) ( sAV ''R'' ) )\n               )\n  ]\"\n\nprotocol Andrew\nwhere \"Andrew = { I, R }\"\n\nlocale restricted_Andrew_state = Andrew_state\n\ntype_invariant Andrew_msc_typing for Andrew\nwhere \"Andrew_msc_typing = mk_typing\n  [ ((R, ''I''), (KnownT R_1))\n  , ((I, ''kIR''), (SumT (KnownT I_4) (NonceT R ''kIR'')))\n  , ((R, ''ni''), (SumT (KnownT R_1) (NonceT I ''ni'')))\n  , ((I, ''nr''), (SumT (KnownT I_2) (NonceT R ''nr'')))\n  , ((I, ''nr2''), (SumT (KnownT I_4) (NonceT R ''nr2'')))\n  ]\"\n\nsublocale Andrew_state < Andrew_msc_typing_state\nproof -\n  have \"(t,r,s) : approx Andrew_msc_typing\"\n  proof(cases rule: reachable_in_approxI_ext\n        [OF Andrew_msc_typing.monoTyp, completeness_cases_rule])\n    case (I_2_nr t r s tid0)\n    then interpret state: Andrew_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = I_2_nr\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''TT2'', Hash {| LC ''TT1'', LN ''ni'' tid0 |},\n               s(MV ''nr'' tid0)\n            |}\n            ( K ( s(AV ''I'' tid0) ) ( s(AV ''R'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (I_4_kIR t r s tid0)\n    then interpret state: Andrew_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = I_4_kIR\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''TT4'', s(MV ''kIR'' tid0), s(MV ''nr2'' tid0) |}\n            ( K ( s(AV ''I'' tid0) ) ( s(AV ''R'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (I_4_nr2 t r s tid0)\n    then interpret state: Andrew_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = I_4_nr2\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''TT4'', s(MV ''kIR'' tid0), s(MV ''nr2'' tid0) |}\n            ( K ( s(AV ''I'' tid0) ) ( s(AV ''R'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (R_1_I t r s tid0)\n    then interpret state: Andrew_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = R_1_I\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (R_1_ni t r s tid0)\n    then interpret state: Andrew_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = R_1_ni\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''TT1'', s(MV ''ni'' tid0) |}\n            ( K ( s(MV ''I'' tid0) ) ( s(AV ''R'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  qed\n  thus \"Andrew_msc_typing_state t r s\" by unfold_locales auto\nqed\n\ntext{* Prove secrecy of long-term keys. *}\ncontext Andrew_state begin\n\n  (* This rule is unsafe in general, but OK here, \n     as we are only reasoning about static compromise. \n  *)\n  lemma static_longterm_key_reveal[dest!]:\n    \"predOrd t (LKR a) e ==> RLKR a : reveals t\"\n    by (auto intro: compr_predOrdI)\n\n  lemma longterm_private_key_secrecy:\n    assumes facts:\n      \"SK m : knows t\"\n      \"RLKR m ~: reveals t\"\n    shows \"False\"\n  using facts by (sources \"SK m\")\n\n  lemma longterm_sym_ud_key_secrecy:\n    assumes facts:\n      \"K m1 m2 : knows t\"\n      \"RLKR m1 ~: reveals t\"\n      \"RLKR m2 ~: reveals t\"\n    shows \"False\"\n  using facts by (sources \"K m1 m2\")\n\n  lemma longterm_sym_bd_key_secrecy:\n    assumes facts:\n      \"Kbd m1 m2 : knows t\"\n      \"RLKR m1 ~: reveals t\"\n      \"RLKR m2 ~: reveals t\"\n      \"m1 : Agent\"\n      \"m2 : Agent\"\n    shows \"False\"\n  proof -\n    from facts \n    have \"KShr (agents {m1, m2}) : knows t\"\n      by (auto simp: Kbd_def)\n    thus ?thesis using facts\n    proof (sources \"KShr (agents {m1, m2})\")\n    qed (auto simp: agents_def Agent_def)\n  qed\n\n  lemmas ltk_secrecy =\n    longterm_sym_ud_key_secrecy\n    longterm_sym_ud_key_secrecy[OF in_knows_predOrd1]\n    longterm_sym_bd_key_secrecy\n    longterm_sym_bd_key_secrecy[OF in_knows_predOrd1]\n    longterm_private_key_secrecy\n    longterm_private_key_secrecy[OF in_knows_predOrd1]\n\nend\n\n(* subsection:  Security Properties  *)\n\nlemma (in restricted_Andrew_state) R_sec_kIR:\n  assumes facts:\n    \"roleMap r tid0 = Some R\"\n    \"RLKR(s(AV ''R'' tid0)) ~: reveals t\"\n    \"RLKR(s(MV ''I'' tid0)) ~: reveals t\"\n    \"LN ''kIR'' tid0 : knows t\"\n  shows \"False\"\nusing facts proof(sources! \" LN ''kIR'' tid0 \")\n  case R_4_kIR note_unified facts = this facts\n  thus ?thesis by (auto dest!: ltk_secrecy)\nqed (safe?, simp_all?, insert facts, (fastforce+)?)\n\nlemma (in restricted_Andrew_state) I_sec_kIR:\n  assumes facts:\n    \"roleMap r tid0 = Some I\"\n    \"RLKR(s(AV ''I'' tid0)) ~: reveals t\"\n    \"RLKR(s(AV ''R'' tid0)) ~: reveals t\"\n    \"( tid0, I_4 ) : steps t\"\n    \"s(MV ''kIR'' tid0) : knows t\"\n  shows \"False\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''TT4'', s(MV ''kIR'' tid0), s(MV ''nr2'' tid0) |}\n                       ( K ( s(AV ''I'' tid0) ) ( s(AV ''R'' tid0) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (auto dest!: ltk_secrecy)\n  next\n    case (R_4_enc tid1) note_unified facts = this facts\n    thus ?thesis by (fastforce dest: R_sec_kIR intro: event_predOrdI)\n  qed (safe?, simp_all?, insert facts, (fastforce+)?)\nqed\n\nlemma (in restricted_Andrew_state) I_ni_agree:\n  assumes facts:\n    \"roleMap r tid1 = Some I\"\n    \"RLKR(s(AV ''I'' tid1)) ~: reveals t\"\n    \"RLKR(s(AV ''R'' tid1)) ~: reveals t\"\n    \"( tid1, I_4 ) : steps t\"\n  shows\n    \"(?  tid2.\n        roleMap r tid2 = Some R &\n        s(AV ''I'' tid1) = s(MV ''I'' tid2) &\n        s(AV ''R'' tid1) = s(AV ''R'' tid2) &\n        s(MV ''nr2'' tid1) = LN ''nr2'' tid2 &\n        s(MV ''kIR'' tid1) = LN ''kIR'' tid2)\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''TT4'', s(MV ''kIR'' tid1), s(MV ''nr2'' tid1) |}\n                       ( K ( s(AV ''I'' tid1) ) ( s(AV ''R'' tid1) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (auto dest!: ltk_secrecy)\n  next\n    case (R_4_enc tid2) note_unified facts = this facts\n    thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\n  qed (safe?, simp_all?, insert facts, (fastforce+)?)\nqed\n\nlemma (in restricted_Andrew_state) R_ni_agree:\n  assumes facts:\n    \"roleMap r tid1 = Some R\"\n    \"RLKR(s(AV ''R'' tid1)) ~: reveals t\"\n    \"RLKR(s(MV ''I'' tid1)) ~: reveals t\"\n    \"( tid1, R_4 ) : steps t\"\n  shows\n    \"(?  tid2.\n        roleMap r tid2 = Some I &\n        s(MV ''I'' tid1) = s(AV ''I'' tid2) &\n        s(AV ''R'' tid1) = s(AV ''R'' tid2) &\n        s(MV ''ni'' tid1) = LN ''ni'' tid2 & LN ''nr'' tid1 = s(MV ''nr'' tid2))\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''TT3'', Hash {| LC ''TT1'', LN ''nr'' tid1 |} |}\n                       ( K ( s(MV ''I'' tid1) ) ( s(AV ''R'' tid1) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (auto dest!: ltk_secrecy)\n  next\n    case (I_3_enc tid2) note_unified facts = this facts\n    thus ?thesis proof(sources! \"\n                     Enc {| LC ''TT2'', Hash {| LC ''TT1'', LN ''ni'' tid2 |}, LN ''nr'' tid1\n                         |}\n                         ( K ( s(AV ''I'' tid2) ) ( s(AV ''R'' tid1) ) ) \")\n      case fake note_unified facts = this facts\n      thus ?thesis by (auto dest!: ltk_secrecy)\n    next\n      case (R_2_enc tid3) note_unified facts = this facts\n      thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\n    qed (safe?, simp_all?, insert facts, (fastforce+)?)\n  qed (safe?, simp_all?, insert facts, (fastforce+)?)\nqed\n\nend", "meta": {"author": "meiersi", "repo": "scyther-proof", "sha": "84e42366a46f66f1b090651be3bfaa3497696280", "save_path": "github-repos/isabelle/meiersi-scyther-proof", "path": "github-repos/isabelle/meiersi-scyther-proof/scyther-proof-84e42366a46f66f1b090651be3bfaa3497696280/examples/classic/isabelle-proofs/Andrew_cert_auto.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.5, "lm_q1q2_score": 0.27723523248021364}}
{"text": "theory Pierson    (*** Benzmüller, Fuenmayor & Lomfeld, 2020 ***)  \n  imports GeneralKnowledge\nbegin (*** Pierson v. Post \"wild animal\" case **)\n\n(*case-specific 'world-vocabulary'*)\nconsts \\<alpha>::\"e\" (*appropriated animal (fox in this case) *)\nconsts Pursue::\"c\\<Rightarrow>e\\<Rightarrow>\\<sigma>\"\nconsts Capture::\"c\\<Rightarrow>e\\<Rightarrow>\\<sigma>\"\n\n(*case-specific taxonomic (legal domain) knowledge*)\naxiomatization where \n CW1: \"\\<lfloor>(\\<^bold>\\<exists>c. Capture c \\<alpha> \\<^bold>\\<and> \\<^bold>\\<not>Domestic \\<alpha>) \\<^bold>\\<rightarrow> appWildAnimal\\<rfloor>\" and\n CW2: \"\\<lfloor>\\<^bold>\\<forall>c. Pursue c \\<alpha> \\<^bold>\\<rightarrow> Intent c\\<rfloor>\" and\n CW3: \"\\<lfloor>\\<^bold>\\<forall>c. Capture c \\<alpha> \\<^bold>\\<rightarrow> Poss c\\<rfloor>\"\n\nlemma True nitpick[satisfy,card i=4] oops (*satisfiable*)\n\n(****************** pro-Pierson's argument ****************)  \nabbreviation \"Pierson_facts \\<equiv> \\<lfloor>Fox \\<alpha> \\<^bold>\\<and> (FreeRoaming \\<alpha>) \\<^bold>\\<and> \n  (\\<^bold>\\<not>Pet \\<alpha>) \\<^bold>\\<and> Pursue p \\<alpha> \\<^bold>\\<and> (\\<^bold>\\<not>Pursue d \\<alpha>) \\<^bold>\\<and> Capture d \\<alpha>\\<rfloor>\"\n\n(*decision for defendant (Pierson) is compatible with premises*)\nlemma \"Pierson_facts \\<and> \\<lfloor>\\<^bold>\\<not>INCONS\\<^sup>p\\<rfloor> \\<and> \\<lfloor>\\<^bold>\\<not>INCONS\\<^sup>d\\<rfloor> \\<and> \\<lfloor>For p \\<^bold>\\<prec> For d\\<rfloor>\"\n  nitpick[satisfy,card i=4] oops (* (non-trivial) model found*)\n\n(*decision for plaintiff (Post) is compatible with premises*)\nlemma \"Pierson_facts \\<and> \\<lfloor>\\<^bold>\\<not>INCONS\\<^sup>p\\<rfloor> \\<and> \\<lfloor>\\<^bold>\\<not>INCONS\\<^sup>d\\<rfloor> \\<and> \\<lfloor>For d \\<^bold>\\<prec> For p\\<rfloor>\"\n  nitpick[satisfy,card i=4] oops (* (non-trivial) model found*)\n\n(*decision for defendant (Pierson) is provable*)\ntheorem assumes Pierson_facts shows \"\\<lfloor>For p \\<^bold>\\<prec> For d\\<rfloor>\"\n  by (metis assms CW1 CW2 W6 W8 ForAx R2 F1 other.simps(2) rBR)\n\n(*while a decision for the plaintiff is not*)\nlemma assumes Pierson_facts shows \"\\<lfloor>For d \\<^bold>\\<prec> For p\\<rfloor>\"\n  nitpick[card i=4] oops (*counterexample found*)\n\n(****************** pro-Post's argument ****************)\n(* Theory amendment: the animal is not free-roaming since it\n   is being chased by a professional hunter (Post) *)\nconsts Hunter::\"c\\<Rightarrow>\\<sigma>\"\naxiomatization where (*case-specific legal rule for hunters*)\n R5: \"\\<lfloor>(Hunter x \\<^bold>\\<and> Pursue x \\<alpha>)  \\<^bold>\\<rightarrow> (STAB\\<^sup>x\\<inverse> \\<^bold>\\<prec>\\<^sub>v EFFI\\<^sup>x)\\<rfloor>\"\n\nabbreviation \"Post_facts \\<equiv> \\<lfloor>Fox \\<alpha> \\<^bold>\\<and> (\\<^bold>\\<not>FreeRoaming \\<alpha>) \\<^bold>\\<and>\n   Hunter p \\<^bold>\\<and> Pursue p \\<alpha> \\<^bold>\\<and> (\\<^bold>\\<not>Pursue d \\<alpha>) \\<^bold>\\<and> Capture d \\<alpha>\\<rfloor>\"\n\n(*decision for defendant (Pierson) is compatible with premises*)\nlemma \"Post_facts \\<and> \\<lfloor>\\<^bold>\\<not>INCONS\\<^sup>p\\<rfloor> \\<and> \\<lfloor>\\<^bold>\\<not>INCONS\\<^sup>d\\<rfloor> \\<and> \\<lfloor>For p \\<^bold>\\<prec> For d\\<rfloor>\"\n  nitpick[satisfy,card i=4] oops (* (non-trivial) model found*)\n\n(*decision for plaintiff (Post) is compatible with premises too*)\nlemma \"Post_facts \\<and> \\<lfloor>\\<^bold>\\<not>INCONS\\<^sup>p\\<rfloor> \\<and> \\<lfloor>\\<^bold>\\<not>INCONS\\<^sup>d\\<rfloor> \\<and> \\<lfloor>For d \\<^bold>\\<prec> For p\\<rfloor>\"\n  nitpick[satisfy,card i=4] oops (* (non-trivial) model found*)\n\n(*indeed, a decision for plaintiff (Post) now becomes provable*)\ntheorem assumes Post_facts shows \"\\<lfloor>For d \\<^bold>\\<prec> For p\\<rfloor>\" \n  using assms by (metis CW3 ForAx R5 F3 other.simps rBR)\n\n(*while a decision for the defendant is now refutable*)\nlemma assumes Post_facts shows \"\\<lfloor>For p \\<^bold>\\<prec> For d\\<rfloor>\" \n  nitpick[card i=4] oops (* counterexample found*)\nend\n\n", "meta": {"author": "cbenzmueller", "repo": "LogiKEy", "sha": "5c16bdeb68bf8131e24ba9c8d774d4af663cb2cf", "save_path": "github-repos/isabelle/cbenzmueller-LogiKEy", "path": "github-repos/isabelle/cbenzmueller-LogiKEy/LogiKEy-5c16bdeb68bf8131e24ba9c8d774d4af663cb2cf/Preference-Logics/vanBenthemEtAl2009/Pierson.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.5, "lm_q1q2_score": 0.27723523248021364}}
{"text": "(*  Title:      Service_Matrix.thy\n    Authors:    Cornelius Diekmann, Max Haslbeck\n*)\n(*IPPartitioning.thy\n  Original Author: Max Haslbeck, 2015*)\nsection\\<open>Service Matrices\\<close>\ntheory Service_Matrix\nimports \"Common/List_Product_More\"\n        \"Common/IP_Partition_Preliminaries\"\n        \"Common/GroupF\"\n        \"Common/IP_Addr_WordInterval_toString\"\n        \"Primitives/Primitives_toString\"\n        SimpleFw_Semantics\n        IP_Addresses.WordInterval_Sorted\nbegin\n\n\nsubsection\\<open>IP Address Space Partition\\<close>\n\n(* could be generalized more *)\nfun extract_IPSets_generic0\n  :: \"('i::len simple_match \\<Rightarrow> 'i word \\<times> nat) \\<Rightarrow> 'i simple_rule list \\<Rightarrow> ('i wordinterval) list\"\n  where\n  \"extract_IPSets_generic0 _ [] = []\" |\n  \"extract_IPSets_generic0 sel ((SimpleRule m _)#ss) = (ipcidr_tuple_to_wordinterval (sel m)) #\n                                                       (extract_IPSets_generic0 sel ss)\"\n\nlemma extract_IPSets_generic0_length: \"length (extract_IPSets_generic0 sel rs) = length rs\"\n  by(induction rs rule: extract_IPSets_generic0.induct) (simp_all)\n\n\n(*\nThe order in which extract_IPSets returns the collected IP ranges heavily influences the running time\nof the subsequent algorithms.\nFor example:\n1) iterating through the ruleset and collecting all source and destination ips:\n   10:10:49 elapsed time, 38:41:17 cpu time, factor 3.80\n2) iterating through the ruleset and first returning all source ips and iterating again and then return all destination ips:\n   3:39:56 elapsed time, 21:08:34 cpu time, factor 5.76\n\nTo get a more deterministic runtime, we are sorting the output. As a performance optimization, we also remove duplicate entries.\nWe use mergesort_remdups, which does a mergesort (i.e sorts!) and removes duplicates and mergesort_by_rel which does a mergesort\n(without removing duplicates) and allows to specify the relation we use to sort.\nIn theory, the largest ip ranges (smallest prefix length) should be put first, the following evaluation shows that this may not\nbe the fastest solution. The reason might be that access_matrix_pretty_ipv4 picks (almost randomly) one IP from the result and\nthere are fast and slower choices. The faster choices are the ones where the firewall ruleset has a decision very early. \nTherefore, the running time is still a bit unpredictable.\n\nHere is the data:\nmap ipcidr_tuple_to_wordinterval (mergesort_by_rel (\\<lambda> (a1,a2) (b1, b2). (a2, a1) \\<le> (b2, b1)) (mergesort_remdups\n                        ((map (src \\<circ> match_sel) rs) @ (map (dst \\<circ> match_sel) rs))))\n (2:47:04 elapsed time, 17:08:01 cpu time, factor 6.15)\n\n\nmap ipcidr_tuple_to_wordinterval (mergesort_remdups ((map (src \\<circ> match_sel) rs) @ (map (dst \\<circ> match_sel) rs)))\n (2:41:03 elapsed time, 16:56:46 cpu time, factor 6.31)\n\n\nmap ipcidr_tuple_to_wordinterval (mergesort_by_rel (\\<lambda> (a1,a2) (b1, b2). (a2, a1) \\<le> (b2, b1)) (\n                         ((map (src \\<circ> match_sel) rs) @ (map (dst \\<circ> match_sel) rs)))\n (5:52:28 elapsed time, 41:50:10 cpu time, factor 7.12)\n\n\nmap ipcidr_tuple_to_wordinterval (mergesort_by_rel (\\<le>)\n                         ((map (src \\<circ> match_sel) rs) @ (map (dst \\<circ> match_sel) rs))))\n  (3:10:57 elapsed time, 19:12:25 cpu time, factor 6.03)\n\n\nmap ipcidr_tuple_to_wordinterval (mergesort_by_rel (\\<lambda> (a1,a2) (b1, b2). (a2, a1) \\<le> (b2, b1)) (mergesort_remdups\n                        (extract_src_dst_ips rs [])))\n (2:49:57 elapsed time, 17:10:49 cpu time, factor 6.06)\n\nmap ipcidr_tuple_to_wordinterval ((mergesort_remdups (extract_src_dst_ips rs [])))\n (2:43:44 elapsed time, 16:57:49 cpu time, factor 6.21)\n\nmap ipcidr_tuple_to_wordinterval (mergesort_by_rel (\\<lambda> (a1,a2) (b1, b2). (a2, a1) \\<ge> (b2, b1)) (mergesort_remdups (extract_src_dst_ips rs [])))\n (2:47:37 elapsed time, 16:54:47 cpu time, factor 6.05)\n\nThere is a clear looser: not using mergesort_remdups\nThere is no clear winner. We will just stick to mergesort_remdups.\n\n*)\n\n(*check the the order of mergesort_remdups did not change*)\nlemma \"mergesort_remdups [(1::ipv4addr, 2::nat), (8,0), (8,1), (2,2), (2,4), (1,2), (2,2)] =\n        [(1, 2), (2, 2), (2, 4), (8, 0), (8, 1)]\" by eval\n\n\n(*a tail-recursive implementation*)\nfun extract_src_dst_ips\n  :: \"'i::len simple_rule list \\<Rightarrow> ('i word \\<times> nat) list \\<Rightarrow> ('i word \\<times> nat) list\" where\n  \"extract_src_dst_ips [] ts = ts\" |\n  \"extract_src_dst_ips ((SimpleRule m _)#ss) ts = extract_src_dst_ips ss  (src m # dst m # ts)\"\n\nlemma extract_src_dst_ips_length: \"length (extract_src_dst_ips rs acc) = 2*length rs + length acc\"\nproof(induction rs arbitrary: acc)\ncase (Cons r rs) thus ?case by(cases r, simp)\nqed(simp)\n\ndefinition extract_IPSets\n  :: \"'i::len simple_rule list \\<Rightarrow> ('i wordinterval) list\" where\n  \"extract_IPSets rs \\<equiv> map ipcidr_tuple_to_wordinterval (mergesort_remdups (extract_src_dst_ips rs []))\"\nlemma extract_IPSets:\n  \"set (extract_IPSets rs) = set (extract_IPSets_generic0 src rs) \\<union> set (extract_IPSets_generic0 dst rs)\"\nproof -\n  { fix acc\n    have \"ipcidr_tuple_to_wordinterval ` set (extract_src_dst_ips rs acc) =\n            ipcidr_tuple_to_wordinterval ` set acc \\<union> set (extract_IPSets_generic0 src rs) \\<union>\n            set (extract_IPSets_generic0 dst rs)\"\n    proof(induction rs arbitrary: acc)\n    case (Cons r rs ) thus ?case\n      apply(cases r)\n      apply(simp)\n      by fast\n    qed(simp)\n  } thus ?thesis unfolding extract_IPSets_def by(simp_all add: extract_IPSets_def mergesort_remdups_correct)\nqed\n\nlemma \"(a::nat) div 2 + a mod 2 \\<le> a\" by fastforce\n\nlemma merge_length: \"length (merge l1 l2) \\<le> length l1 + length l2\"\nby(induction l1 l2 rule: merge.induct) auto\n\nlemma merge_list_length: \"length (merge_list as ls) \\<le> length (concat (as @ ls))\"\nproof(induction as ls rule: merge_list.induct)\ncase (5 l1 l2 acc2 ls)\n  have \"length (merge l2 acc2) \\<le> length l2 + length acc2\" using merge_length by blast\n  with 5 show ?case by simp\nqed(simp_all)\n\nlemma mergesort_remdups_length: \"length (mergesort_remdups as) \\<le> length as\"\nunfolding mergesort_remdups_def\nproof -\n  have \"concat ([] @ (map (\\<lambda>x. [x]) as)) = as\" by simp\n  with merge_list_length show \"length (merge_list [] (map (\\<lambda>x. [x]) as)) \\<le> length as\" by metis\nqed\n\nlemma extract_IPSets_length: \"length (extract_IPSets rs) \\<le> 2 * length rs\"\napply(simp add: extract_IPSets_def)\nusing extract_src_dst_ips_length mergesort_remdups_length by (metis add.right_neutral list.size(3)) \n\n\n(*\nexport_code extract_IPSets in SML\nwhy you no work?\n*)\n\n\nlemma extract_equi0:\n  \"set (map wordinterval_to_set (extract_IPSets_generic0 sel rs)) =\n    (\\<lambda>(base,len). ipset_from_cidr base len) ` sel ` match_sel ` set rs\"\n  proof(induction rs)\n  case (Cons r rs) thus ?case\n    apply(cases r, simp)\n    using wordinterval_to_set_ipcidr_tuple_to_wordinterval by fastforce\n  qed(simp)\n\nlemma src_ipPart_motivation:\nfixes   rs\ndefines \"X \\<equiv> (\\<lambda>(base,len). ipset_from_cidr base len) ` src ` match_sel ` set rs\"\nassumes \"\\<forall>A \\<in> X. B \\<subseteq> A \\<or> B \\<inter> A = {}\" and \"s1 \\<in> B\" and \"s2 \\<in> B\"\nshows \"simple_fw rs (p\\<lparr>p_src:=s1\\<rparr>) = simple_fw rs (p\\<lparr>p_src:=s2\\<rparr>)\"\nproof -\n  have \"\\<forall>A \\<in> (\\<lambda>(base,len). ipset_from_cidr base len) ` src ` match_sel ` set rs. B \\<subseteq> A \\<or> B \\<inter> A = {} \\<Longrightarrow> ?thesis\"\n  proof(induction rs)\n    case Nil thus ?case by simp\n  next\n    case (Cons r rs)\n    { fix m\n      from \\<open>s1 \\<in> B\\<close> \\<open>s2 \\<in> B\\<close> have \n        \"B \\<subseteq> (case src m of (x, xa) \\<Rightarrow> ipset_from_cidr x xa) \\<or> B \\<inter> (case src m of (x, xa) \n                      \\<Rightarrow> ipset_from_cidr x xa) = {} \\<Longrightarrow>\n             simple_matches m (p\\<lparr>p_src := s1\\<rparr>) \\<longleftrightarrow> simple_matches m (p\\<lparr>p_src := s2\\<rparr>)\"\n      apply(cases m)\n      apply(rename_tac iiface oiface srca dst proto sports dports)\n      apply(case_tac srca)\n      apply(simp add: simple_matches.simps)\n      by blast\n    } note helper=this\n    from Cons[simplified] show ?case\n     apply(cases r, rename_tac m a)\n     apply(simp)\n     apply(case_tac a)\n      using helper apply force+\n     done\n  qed\n  with assms show ?thesis by blast\nqed\n\n    \nlemma src_ipPart:\n  assumes \"ipPartition (set (map wordinterval_to_set (extract_IPSets_generic0 src rs))) A\"\n          \"B \\<in> A\" \"s1 \\<in> B\" \"s2 \\<in> B\"\n  shows \"simple_fw rs (p\\<lparr>p_src:=s1\\<rparr>) = simple_fw rs (p\\<lparr>p_src:=s2\\<rparr>)\"\nproof -\n  from src_ipPart_motivation[OF _ assms(3) assms(4)]\n  have \"\\<forall>A \\<in> (\\<lambda>(base,len). ipset_from_cidr base len) ` src ` match_sel ` set rs. B \\<subseteq> A \\<or> B \\<inter> A = {} \\<Longrightarrow>\n      simple_fw rs (p\\<lparr>p_src:=s1\\<rparr>) = simple_fw rs (p\\<lparr>p_src:=s2\\<rparr>)\" by fast\n  thus ?thesis using assms(1) assms(2)\n    unfolding ipPartition_def\n    by (metis (full_types) Int_commute extract_equi0)\nqed\n  \n(*basically a copy of src_ipPart*)\nlemma dst_ipPart:\n  assumes \"ipPartition (set (map wordinterval_to_set (extract_IPSets_generic0 dst rs))) A\"\n          \"B \\<in> A\" \"s1 \\<in> B\" \"s2 \\<in> B\"\n  shows \"simple_fw rs (p\\<lparr>p_dst:=s1\\<rparr>) = simple_fw rs (p\\<lparr>p_dst:=s2\\<rparr>)\"\nproof -\n  have \"\\<forall>A \\<in> (\\<lambda>(base,len). ipset_from_cidr base len) ` dst ` match_sel ` set rs. B \\<subseteq> A \\<or> B \\<inter> A = {} \\<Longrightarrow>\n      simple_fw rs (p\\<lparr>p_dst:=s1\\<rparr>) = simple_fw rs (p\\<lparr>p_dst:=s2\\<rparr>)\"\n  proof(induction rs)\n    case Nil thus ?case by simp\n  next\n    case (Cons r rs)\n    { fix m\n      from \\<open>s1 \\<in> B\\<close> \\<open>s2 \\<in> B\\<close> have\n        \"B \\<subseteq> (case dst m of (x, xa) \\<Rightarrow> ipset_from_cidr x xa) \\<or> B \\<inter> (case dst m of (x, xa) \n                  \\<Rightarrow> ipset_from_cidr x xa) = {} \\<Longrightarrow>\n         simple_matches m (p\\<lparr>p_dst := s1\\<rparr>) \\<longleftrightarrow> simple_matches m (p\\<lparr>p_dst := s2\\<rparr>)\"\n          apply(cases m)\n          apply(rename_tac iiface oiface src dsta proto sports dports)\n          apply(case_tac dsta)\n          apply(simp add: simple_matches.simps)\n          by blast\n    } note helper=this\n    from Cons show ?case\n     apply(simp)\n     apply(case_tac r, rename_tac m a)\n     apply(simp)\n     apply(case_tac a)\n      using helper apply force+\n     done\n  qed\n  thus ?thesis using assms(1) assms(2)\n    unfolding ipPartition_def\n    by (metis (full_types) Int_commute extract_equi0)\nqed\n\n\n\n(* OPTIMIZED PARTITIONING *)\n\ndefinition wordinterval_list_to_set :: \"'a::len wordinterval list \\<Rightarrow> 'a::len word set\" where\n  \"wordinterval_list_to_set ws = \\<Union>(set (map wordinterval_to_set ws))\"\n\nlemma wordinterval_list_to_set_compressed:\n  \"wordinterval_to_set (wordinterval_compress (foldr wordinterval_union xs Empty_WordInterval)) =\n          wordinterval_list_to_set xs\"\n  proof(induction xs)\n  qed(simp_all add: wordinterval_compress wordinterval_list_to_set_def)\n\nfun partIps :: \"'a::len wordinterval \\<Rightarrow> 'a::len wordinterval list \n                \\<Rightarrow> 'a::len wordinterval list\" where\n  \"partIps _ [] = []\" |\n  \"partIps s (t#ts) = (if wordinterval_empty s then (t#ts) else\n                        (if wordinterval_empty (wordinterval_intersection s t)\n                          then (t#(partIps s ts))\n                          else\n                            (if wordinterval_empty (wordinterval_setminus t s)\n                              then (t#(partIps (wordinterval_setminus s t) ts))\n                              else (wordinterval_intersection t s)#((wordinterval_setminus t s)#\n                                   (partIps (wordinterval_setminus s t) ts)))))\"\n\n\nlemma \"partIps (WordInterval (1::ipv4addr) 1) [WordInterval 0 1] = [WordInterval 1 1, WordInterval 0 0]\" by eval\n\nlemma partIps_length: \"length (partIps s ts) \\<le> (length ts) * 2\"\nproof(induction ts arbitrary: s)\ncase Cons thus ?case \n  apply(simp)\n  using le_Suc_eq by blast\nqed(simp)\n\nfun partitioningIps :: \"'a::len wordinterval list \\<Rightarrow> 'a::len wordinterval list \\<Rightarrow>\n                        'a::len wordinterval list\" where\n  \"partitioningIps [] ts = ts\" |\n  \"partitioningIps (s#ss) ts = partIps s (partitioningIps ss ts)\"\n\n\nlemma partitioningIps_length: \"length (partitioningIps ss ts) \\<le> (2^length ss) * length ts\"\nproof(induction ss)\ncase Nil thus ?case by simp\nnext\ncase (Cons s ss)\n  have \"length (partIps s (partitioningIps ss ts)) \\<le> length (partitioningIps ss ts) * 2\"\n    using partIps_length by fast\n  with Cons show  ?case by force\nqed\n\nlemma partIps_equi: \"map wordinterval_to_set (partIps s ts) = \n    partList4 (wordinterval_to_set s) (map wordinterval_to_set ts)\"\n  proof(induction ts arbitrary: s)\n  qed(simp_all)\n\nlemma partitioningIps_equi: \"map wordinterval_to_set (partitioningIps ss ts)\n       = (partitioning1 (map wordinterval_to_set ss) (map wordinterval_to_set ts))\"\n  apply(induction ss arbitrary: ts)\n   apply(simp; fail)\n  apply(simp add: partIps_equi)\n  done\n\n           \ndefinition getParts :: \"'i::len simple_rule list \\<Rightarrow> 'i wordinterval list\" where\n   \"getParts rs = partitioningIps (extract_IPSets rs) [wordinterval_UNIV]\"\n\nlemma partitioningIps_foldr: \"partitioningIps ss ts = foldr partIps ss ts\"\n  by(induction ss) (simp_all)\n\nlemma getParts_foldr: \"getParts rs = foldr partIps (extract_IPSets rs) [wordinterval_UNIV]\"\n  by(simp add: getParts_def partitioningIps_foldr)\n\nlemma getParts_length: \"length (getParts rs) \\<le> 2^(2 * length rs)\"\nproof -\n  from partitioningIps_length[where ss=\"extract_IPSets rs\" and ts=\"[wordinterval_UNIV]\"] have\n    1: \"length (partitioningIps (extract_IPSets rs) [wordinterval_UNIV]) \\<le> 2 ^ length (extract_IPSets rs)\" by simp\n  from extract_IPSets_length have \"(2::nat) ^ length (extract_IPSets rs) \\<le> 2 ^ (2 * length rs)\" by simp\n  with 1 have \"length (partitioningIps (extract_IPSets rs) [wordinterval_UNIV]) \\<le> 2 ^ (2 * length rs)\" by linarith\n  thus ?thesis by(simp add: getParts_def) \nqed\n\nlemma getParts_ipPartition: \"ipPartition (set (map wordinterval_to_set (extract_IPSets rs)))\n                                         (set (map wordinterval_to_set (getParts rs)))\"\nproof -\n  have hlp_rule: \"{} \\<notin> set (map wordinterval_to_set ts) \\<Longrightarrow> disjoint_list (map wordinterval_to_set ts) \\<Longrightarrow> \n     (wordinterval_list_to_set ss) \\<subseteq> (wordinterval_list_to_set ts) \\<Longrightarrow> \n     ipPartition (set (map wordinterval_to_set ss)) \n                 (set (map wordinterval_to_set (partitioningIps ss ts)))\" for ts ss::\"'a wordinterval list\"\n  by (metis ipPartitioning_helper_opt partitioningIps_equi wordinterval_list_to_set_def)\n  have \"disjoint_list [UNIV]\" by(simp add: disjoint_list_def disjoint_def)\n  have \"ipPartition (set (map wordinterval_to_set ss)) \n                   (set (map wordinterval_to_set (partitioningIps ss [wordinterval_UNIV])))\"\n     for ss::\"'a wordinterval list\"\n  apply(rule hlp_rule)\n    apply(simp_all add: wordinterval_list_to_set_def \\<open>disjoint_list [UNIV]\\<close>)\n  done\n  thus ?thesis\n  unfolding getParts_def by blast\nqed\n\n\nlemma getParts_complete: \"wordinterval_list_to_set (getParts rs) = UNIV\"\n  proof -\n  have \"{} \\<notin> set (map wordinterval_to_set ts) \\<Longrightarrow>\n     (wordinterval_list_to_set ss) \\<subseteq> (wordinterval_list_to_set ts) \\<Longrightarrow> \n     wordinterval_list_to_set (partitioningIps ss ts) = (wordinterval_list_to_set ts)\"\n     for ss ts::\"'a wordinterval list\"\n    using complete_helper by (metis partitioningIps_equi wordinterval_list_to_set_def)\n  hence \"wordinterval_list_to_set (getParts rs) = wordinterval_list_to_set [wordinterval_UNIV]\"\n    unfolding getParts_def by(simp add: wordinterval_list_to_set_def)\n  also have \"\\<dots> = UNIV\" by (simp add: wordinterval_list_to_set_def)\n  finally show ?thesis .\nqed\n\ntheorem getParts_samefw: \n  assumes \"A \\<in> set (map wordinterval_to_set (getParts rs))\" \"s1 \\<in> A\" \"s2 \\<in> A\" \n  shows \"simple_fw rs (p\\<lparr>p_src:=s1\\<rparr>) = simple_fw rs (p\\<lparr>p_src:=s2\\<rparr>) \\<and>\n         simple_fw rs (p\\<lparr>p_dst:=s1\\<rparr>) = simple_fw rs (p\\<lparr>p_dst:=s2\\<rparr>)\"\nproof -\n  let ?X=\"(set (map wordinterval_to_set (getParts rs)))\"\n  from getParts_ipPartition have \"ipPartition (set (map wordinterval_to_set (extract_IPSets rs))) ?X\" .\n  hence \"ipPartition (set (map wordinterval_to_set (extract_IPSets_generic0 src rs))) ?X \\<and>\n         ipPartition (set (map wordinterval_to_set (extract_IPSets_generic0 dst rs))) ?X\"\n    by(simp add: extract_IPSets ipPartitionUnion image_Un)\n  thus ?thesis using assms dst_ipPart src_ipPart by blast\nqed\n\n\nlemma partIps_nonempty: \"ts \\<noteq> [] \\<Longrightarrow> partIps s ts \\<noteq> []\"\n  by(induction ts arbitrary: s) simp_all\nlemma partitioningIps_nonempty: \"ts \\<noteq> [] \\<Longrightarrow> partitioningIps ss ts \\<noteq> []\"\nproof(induction ss arbitrary: ts)\n  case Nil thus ?case by simp\n  next\n  case (Cons s ss) thus ?case\n    apply(cases ts)\n     apply(simp; fail)\n    apply(simp)\n    using partIps_nonempty by blast\nqed\n\n(*\nlemma partIps_nonempty: \"\\<forall>t \\<in> set ts. \\<not> wordinterval_empty t \n       \\<Longrightarrow> {} \\<notin> set (map wordinterval_to_set (partIps s ts))\"\n  apply(induction ts arbitrary: s)\n   apply(simp; fail)\n  apply(simp)\n  by blast\n*)\n\nlemma getParts_nonempty: \"getParts rs \\<noteq> []\" by(simp add: getParts_def partitioningIps_nonempty)\nlemma getParts_nonempty_elems: \"\\<forall>w\\<in>set (getParts rs). \\<not> wordinterval_empty w\"\n  unfolding getParts_def\n  proof -\n    have partitioning_nonempty: \"\\<forall>t \\<in> set ts. \\<not> wordinterval_empty t \\<Longrightarrow>\n      {} \\<notin> set (map wordinterval_to_set (partitioningIps ss ts))\"\n      for ts ss::\"'a wordinterval list\"\n      proof(induction ss arbitrary: ts)\n        case Nil thus ?case by auto\n        case Cons thus ?case by (simp add: partIps_equi partList4_empty)\n      qed\n    have \"\\<forall>t \\<in> set [wordinterval_UNIV].\\<not> wordinterval_empty t\" by(simp)\n    with partitioning_nonempty have\n      \"{} \\<notin> set (map wordinterval_to_set (partitioningIps (extract_IPSets rs) [wordinterval_UNIV]))\" \n      by blast\n    thus \"\\<forall>w\\<in>set (partitioningIps (extract_IPSets rs) [wordinterval_UNIV]). \\<not> wordinterval_empty w\" by auto\n  qed\n\n(* HELPER FUNCTIONS UNIFICATION *)\n\nfun getOneIp :: \"'a::len wordinterval \\<Rightarrow> 'a::len word\" where\n  \"getOneIp (WordInterval b _) = b\" |\n  \"getOneIp (RangeUnion r1 r2) = (if wordinterval_empty r1 then getOneIp r2\n                                                           else getOneIp r1)\"\n\nlemma getOneIp_elem: \"\\<not> wordinterval_empty W \\<Longrightarrow> wordinterval_element (getOneIp W) W\"\n  by (induction W) simp_all\n\nrecord parts_connection = pc_iiface :: string\n                          pc_oiface :: string\n                          pc_proto :: primitive_protocol\n                          pc_sport :: \"16 word\"\n                          pc_dport :: \"16 word\"\n\n\n\n(* SAME FW DEFINITIONS AND PROOFS *)\n\n\n\ndefinition same_fw_behaviour :: \"\\<^cancel>\\<open>'pkt_ext itself \\<Rightarrow>\\<close> 'i::len word \\<Rightarrow> 'i word \\<Rightarrow> 'i simple_rule list \\<Rightarrow> bool\" where\n  \"same_fw_behaviour \\<^cancel>\\<open>TYPE('pkt_ext)\\<close> a b rs \\<equiv>\n      \\<forall>(p:: 'i::len simple_packet).\n                simple_fw rs (p\\<lparr>p_src:=a\\<rparr>) = simple_fw rs (p\\<lparr>p_src:=b\\<rparr>) \\<and>\n                simple_fw rs (p\\<lparr>p_dst:=a\\<rparr>) = simple_fw rs (p\\<lparr>p_dst:=b\\<rparr>)\"\n\nlemma getParts_same_fw_behaviour:\n  \"A \\<in> set (map wordinterval_to_set (getParts rs)) \\<Longrightarrow>  s1 \\<in> A \\<Longrightarrow> s2 \\<in> A \\<Longrightarrow> \n   same_fw_behaviour s1 s2 rs\"\n  unfolding same_fw_behaviour_def\n  using getParts_samefw by blast\n\ndefinition \"runFw s d c rs = simple_fw rs \\<lparr>p_iiface=pc_iiface c,p_oiface=pc_oiface c,\n                          p_src=s,p_dst=d,\n                          p_proto=pc_proto c,\n                          p_sport=pc_sport c,p_dport=pc_dport c,\n                          p_tcp_flags={TCP_SYN},\n                          p_payload=''''\\<rparr>\"\n\ntext\\<open>We use @{const runFw} for executable code, but in general, everything applies to generic packets\\<close>\ndefinition runFw_scheme :: \"'i::len word \\<Rightarrow> 'i word \\<Rightarrow> 'b parts_connection_scheme \\<Rightarrow>\n                              ('i, 'a) simple_packet_scheme \\<Rightarrow> 'i simple_rule list \\<Rightarrow> state\"\n  where\n\"runFw_scheme s d c p rs = simple_fw rs\n                        (p\\<lparr>p_iiface:=pc_iiface c,\n                          p_oiface:=pc_oiface c,\n                          p_src:=s,\n                          p_dst:=d,\n                          p_proto:=pc_proto c,\n                          p_sport:=pc_sport c,\n                          p_dport:=pc_dport c\\<rparr>)\"\n\nlemma runFw_scheme: \"runFw s d c rs = runFw_scheme s d c p rs\"\n  apply(simp add: runFw_def runFw_scheme_def)\n  apply(case_tac p)\n  apply(simp)\n  apply(thin_tac _, simp)\nproof(induction rs)\n  case Nil thus ?case by(simp; fail)\nnext\n  case(Cons r rs)\n  obtain m a where r: \"r = SimpleRule m a\" by(cases r) simp\n  from simple_matches_extended_packet[symmetric, of _ \"pc_iiface c\" \"pc_oiface c\"\n                                      s d \"pc_proto c\" \"pc_sport c\" \"pc_dport c\" _ _ _ \"{TCP_SYN}\" \"[]\"]\n  have pext: \"simple_matches m\n   \\<lparr>p_iiface = pc_iiface c, p_oiface = pc_oiface c, p_src = s, p_dst = d, p_proto = pc_proto c, p_sport = pc_sport c, p_dport = pc_dport c,\n      p_tcp_flags = tcp_flags2, p_payload = payload2, \\<dots> = aux\\<rparr> =\n  simple_matches m\n   \\<lparr>p_iiface = pc_iiface c, p_oiface = pc_oiface c, p_src = s, p_dst = d, p_proto = pc_proto c, p_sport = pc_sport c, p_dport = pc_dport c,\n      p_tcp_flags = {TCP_SYN}, p_payload = []\\<rparr>\" for tcp_flags2 payload2 and aux::'c by fast\n  show ?case\n   apply(simp add: r, cases a, simp)\n    using Cons.IH by(simp add: pext)+\nqed \n\n\nlemma has_default_policy_runFw: \"has_default_policy rs \\<Longrightarrow> runFw s d c rs = Decision FinalAllow \\<or> runFw s d c rs = Decision FinalDeny\"\n  by(simp add: runFw_def has_default_policy)\n\ndefinition same_fw_behaviour_one :: \"'i::len word \\<Rightarrow> 'i word \\<Rightarrow> 'a parts_connection_scheme \\<Rightarrow> 'i simple_rule list \\<Rightarrow> bool\" where\n  \"same_fw_behaviour_one ip1 ip2 c rs \\<equiv>\n            \\<forall>d s. runFw ip1 d c rs = runFw ip2 d c rs \\<and> runFw s ip1 c rs = runFw s ip2 c rs\"\n\n\n\ntext\\<open>Is an equivalence relation\\<close>\nlemma same_fw_behaviour_one_equi:\n  \"same_fw_behaviour_one x x c rs\"\n  \"same_fw_behaviour_one x y c rs = same_fw_behaviour_one y x c rs\"\n  \"same_fw_behaviour_one x y c rs \\<and> same_fw_behaviour_one y z c rs \\<Longrightarrow> same_fw_behaviour_one x z c rs\"\n  unfolding same_fw_behaviour_one_def by metis+\n\nlemma same_fw_behaviour_equi:\n  \"same_fw_behaviour x x rs\"\n  \"same_fw_behaviour x y rs = same_fw_behaviour y x rs\"\n  \"same_fw_behaviour x y rs \\<and> same_fw_behaviour y z rs \\<Longrightarrow> same_fw_behaviour x z rs\"\n  unfolding same_fw_behaviour_def by auto\n\nlemma runFw_sameFw_behave: \n       fixes W :: \"'i::len word set set\"\n       shows\n       \"\\<forall>A \\<in> W. \\<forall>a1 \\<in> A. \\<forall>a2 \\<in> A. same_fw_behaviour_one a1 a2 c rs \\<Longrightarrow> \\<Union> W = UNIV \\<Longrightarrow>\n       \\<forall>B \\<in> W. \\<exists>b \\<in> B. runFw ip1 b c rs = runFw ip2 b c rs \\<Longrightarrow>\n       \\<forall>B \\<in> W. \\<exists>b \\<in> B. runFw b ip1 c rs = runFw b ip2 c rs \\<Longrightarrow>\n       same_fw_behaviour_one ip1 ip2 c rs\"\nproof -\n  assume a1: \"\\<forall>A \\<in> W. \\<forall>a1 \\<in> A. \\<forall>a2 \\<in> A. same_fw_behaviour_one a1 a2 c rs\"\n   and a2: \"\\<Union> W = UNIV \"\n   and a3: \"\\<forall>B \\<in> W. \\<exists>b \\<in> B. runFw ip1 b c rs = runFw ip2 b c rs\"\n   and a4: \"\\<forall>B \\<in> W. \\<exists>b \\<in> B. runFw b ip1 c rs = runFw b ip2 c rs\"\n\n   \n  have relation_lem: \"\\<forall>D \\<in> W. \\<forall>d1 \\<in> D. \\<forall>d2 \\<in> D. \\<forall>s. f s d1 = f s d2 \\<Longrightarrow> \\<Union> W = UNIV \\<Longrightarrow>\n                     \\<forall>B \\<in> W. \\<exists>b \\<in> B. f s1 b = f s2 b \\<Longrightarrow>\n                     f s1 d = f s2 d\" for W and f::\"'c \\<Rightarrow> 'b \\<Rightarrow> 'd\" and s1 d s2\n    by (metis UNIV_I Union_iff)\n\n  from a1 have a1':\"\\<forall>A\\<in>W. \\<forall>a1\\<in>A. \\<forall>a2\\<in>A. \\<forall>s. runFw s a1 c rs = runFw s a2 c rs\"\n    unfolding same_fw_behaviour_one_def by fast\n  from relation_lem[OF a1' a2 a3] have s1: \"\\<And> d. runFw ip1 d c rs = runFw ip2 d c rs\" by simp\n\n  from a1 have a1'':\"\\<forall>A\\<in>W. \\<forall>a1\\<in>A. \\<forall>a2\\<in>A. \\<forall>d. runFw a1 d c rs = runFw a2 d c rs\"\n    unfolding same_fw_behaviour_one_def by fast\n  from relation_lem[OF a1'' a2 a4] have s2: \"\\<And> s. runFw s ip1 c rs = runFw s ip2 c rs\" by simp\n  from s1 s2 show \"same_fw_behaviour_one ip1 ip2 c rs\"\n    unfolding same_fw_behaviour_one_def by fast\nqed\n\nlemma sameFw_behave_sets:\n  \"\\<forall>w\\<in>set A. \\<forall>a1 \\<in> w. \\<forall>a2 \\<in> w. same_fw_behaviour_one a1 a2 c rs \\<Longrightarrow>\n   \\<forall>w1\\<in>set A. \\<forall>w2\\<in>set A. \\<exists>a1\\<in>w1. \\<exists>a2\\<in>w2. same_fw_behaviour_one a1 a2 c rs \\<Longrightarrow>\n   \\<forall>w1\\<in>set A. \\<forall>w2\\<in>set A.\n     \\<forall>a1\\<in>w1. \\<forall>a2\\<in>w2. same_fw_behaviour_one a1 a2 c rs\"\nproof -\n  assume a1: \"\\<forall>w\\<in>set A. \\<forall>a1 \\<in> w. \\<forall>a2 \\<in> w. same_fw_behaviour_one a1 a2 c rs\" and\n         \"\\<forall>w1\\<in>set A. \\<forall>w2\\<in>set A. \\<exists>a1\\<in>w1. \\<exists>a2\\<in>w2.  same_fw_behaviour_one a1 a2 c rs\"\n  from this have \"\\<forall>w1\\<in>set A. \\<forall>w2\\<in>set A. \\<exists>a1\\<in>w1. \\<forall>a2\\<in>w2.  same_fw_behaviour_one a1 a2 c rs\"\n    using same_fw_behaviour_one_equi(3) by metis\n  from a1 this show \"\\<forall>w1\\<in>set A. \\<forall>w2\\<in>set A. \\<forall>a1\\<in>w1. \\<forall>a2\\<in>w2. same_fw_behaviour_one a1 a2 c rs\"\n    using same_fw_behaviour_one_equi(3) by metis\nqed\n  \n\n\n\ndefinition groupWIs :: \"parts_connection \\<Rightarrow> 'i::len simple_rule list \\<Rightarrow> 'i wordinterval list list\" where\n  \"groupWIs c rs = (let W = getParts rs in \n                       (let f = (\\<lambda>wi. (map (\\<lambda>d. runFw (getOneIp wi) d c rs) (map getOneIp W),\n                                      map (\\<lambda>s. runFw s (getOneIp wi) c rs) (map getOneIp W))) in\n                       groupF f W))\"\n\n\n\nlemma groupWIs_not_empty: \"groupWIs c rs \\<noteq> []\"\n  proof -\n    have \"getParts rs \\<noteq> []\" by(simp add: getParts_def partitioningIps_nonempty)\n    with groupF_empty have \"\\<And>f. groupF f (getParts rs) \\<noteq> []\" by blast\n    thus ?thesis by(simp add: groupWIs_def Let_def) blast\n  qed\nlemma groupWIs_not_empty_elem: \"V \\<in> set (groupWIs c rs) \\<Longrightarrow> V \\<noteq> []\"\n  by(simp add: groupWIs_def Let_def groupF_empty_elem)\nlemma groupWIs_not_empty_elems: \n  assumes V: \"V \\<in> set (groupWIs c rs)\" and w: \"w \\<in> set V\"\n  shows \"\\<not> wordinterval_empty w\"\n  proof -\n    have \"\\<forall>w\\<in>set (concat (groupWIs c rs)). \\<not> wordinterval_empty w\"\n      apply(subst groupWIs_def)\n      apply(subst Let_def)+\n      apply(subst groupF_concat_set)\n      using getParts_nonempty_elems by blast\n    from this V w show ?thesis by auto\n  qed\n\nlemma groupParts_same_fw_wi0:\n    assumes \"V \\<in> set (groupWIs c rs)\"\n    shows \"\\<forall>w \\<in> set (map wordinterval_to_set V). \\<forall>a1 \\<in> w. \\<forall>a2 \\<in> w. same_fw_behaviour_one a1 a2 c rs\"\nproof -\n  have \"\\<forall>A\\<in>set (map wordinterval_to_set (concat (groupWIs c rs))). \n        \\<forall>a1\\<in>A. \\<forall>a2\\<in>A. same_fw_behaviour_one a1 a2 c rs\"\n    apply(subst groupWIs_def)\n    apply(subst Let_def)+\n    apply(subst set_map)\n    apply(subst groupF_concat_set)\n    using getParts_same_fw_behaviour same_fw_spec by fastforce\n  from this assms show ?thesis by force\nqed\n\nlemma groupWIs_same_fw_not: \"A \\<in> set (groupWIs c rs) \\<Longrightarrow> B \\<in> set (groupWIs c rs) \\<Longrightarrow> \n                            A \\<noteq> B \\<Longrightarrow>\n                             \\<forall>aw \\<in> set (map wordinterval_to_set A).\n                             \\<forall>bw \\<in> set (map wordinterval_to_set B).\n                             \\<forall>a \\<in> aw. \\<forall>b \\<in> bw. \\<not> same_fw_behaviour_one a b c rs\"\nproof -\n  assume asm: \"A \\<in> set (groupWIs c rs)\" \"B \\<in> set (groupWIs c rs)\" \"A \\<noteq> B\"\n  from this have b1: \"\\<forall>aw \\<in> set A. \\<forall>bw \\<in> set B.\n                  (map (\\<lambda>d. runFw (getOneIp aw) d c rs) (map getOneIp (getParts rs)),\n                   map (\\<lambda>s. runFw s (getOneIp aw) c rs) (map getOneIp (getParts rs))) \\<noteq>\n                  (map (\\<lambda>d. runFw (getOneIp bw) d c rs) (map getOneIp (getParts rs)),\n                   map (\\<lambda>s. runFw s (getOneIp bw) c rs) (map getOneIp (getParts rs)))\"\n    apply(simp add: groupWIs_def Let_def)\n    using groupF_nequality by fastforce\n  have same_behave_runFw_not:\n        \"(map (\\<lambda>d. runFw x1 d c rs) W, map (\\<lambda>s. runFw s x1 c rs) W) \\<noteq>\n         (map (\\<lambda>d. runFw x2 d c rs) W, map (\\<lambda>s. runFw s x2 c rs) W) \\<Longrightarrow>\n         \\<not> same_fw_behaviour_one x1 x2 c rs\" for x1 x2 W\n  by (simp add: same_fw_behaviour_one_def) (blast)\n  have \"\\<forall>C \\<in> set (groupWIs c rs). \\<forall>c \\<in> set C. getOneIp c \\<in> wordinterval_to_set c\"\n    apply(simp add: groupWIs_def Let_def)\n    using getParts_nonempty_elems groupF_set getOneIp_elem by fastforce\n  from this b1 asm have\n  \"\\<forall>aw \\<in> set (map wordinterval_to_set A). \\<forall>bw \\<in> set (map wordinterval_to_set B).\n   \\<exists>a \\<in> aw. \\<exists>b \\<in> bw. (map (\\<lambda>d. runFw a d c rs) (map getOneIp (getParts rs)), map (\\<lambda>s. runFw s a c rs) (map getOneIp (getParts rs))) \\<noteq>\n    (map (\\<lambda>d. runFw b d c rs) (map getOneIp (getParts rs)), map (\\<lambda>s. runFw s b c rs) (map getOneIp (getParts rs)))\"\n   by (simp) (blast)\n  from this same_behave_runFw_not asm\n  have \" \\<forall>aw \\<in> set (map wordinterval_to_set A). \\<forall>bw \\<in> set (map wordinterval_to_set B).\n         \\<exists>a \\<in> aw. \\<exists>b \\<in> bw. \\<not> same_fw_behaviour_one a b c rs\" by fast\n  from this groupParts_same_fw_wi0[of A c rs]  groupParts_same_fw_wi0[of B c rs] asm\n  have \"\\<forall>aw \\<in> set (map wordinterval_to_set A).\n        \\<forall>bw \\<in> set (map wordinterval_to_set B).\n        \\<forall>a \\<in> aw. \\<exists>b \\<in> bw. \\<not> same_fw_behaviour_one a b c rs\"\n    apply(simp) using same_fw_behaviour_one_equi(3) by blast\n  from this groupParts_same_fw_wi0[of A c rs]  groupParts_same_fw_wi0[of B c rs] asm\n  show \"\\<forall>aw \\<in> set (map wordinterval_to_set A).\n        \\<forall>bw \\<in> set (map wordinterval_to_set B).\n        \\<forall>a \\<in> aw. \\<forall>b \\<in> bw. \\<not> same_fw_behaviour_one a b c rs\"\n    apply(simp) using same_fw_behaviour_one_equi(3) by fast\nqed\n\n\n\n\n\n(*beginning is copy&paste of previous proof*)\nlemma groupParts_same_fw_wi1:\n  \"V \\<in> set (groupWIs c rs) \\<Longrightarrow> \\<forall>w1 \\<in> set V. \\<forall>w2 \\<in> set V.\n     \\<forall>a1 \\<in> wordinterval_to_set w1. \\<forall>a2 \\<in> wordinterval_to_set w2. same_fw_behaviour_one a1 a2 c rs\"\nproof -\n  assume asm: \"V \\<in> set (groupWIs c rs)\"\n  from getParts_same_fw_behaviour same_fw_spec\n    have b1: \"\\<forall>A \\<in> set (map wordinterval_to_set (getParts rs)) . \\<forall>a1 \\<in> A. \\<forall>a2 \\<in> A.\n              same_fw_behaviour_one a1 a2 c rs\" by fast\n  from getParts_complete have complete: \"\\<Union>(set (map wordinterval_to_set (getParts rs))) = UNIV\"\n    by(simp add: wordinterval_list_to_set_def)\n  from getParts_nonempty_elems have nonempty: \"\\<forall>w\\<in>set (getParts rs). \\<not> wordinterval_empty w\" by simp\n\n  { fix W x1 x2\n    assume a1: \"\\<forall>A \\<in> set (map wordinterval_to_set W). \\<forall>a1 \\<in> A. \\<forall>a2 \\<in> A. same_fw_behaviour_one a1 a2 c rs\"\n    and a2: \"wordinterval_list_to_set W = UNIV\"\n    and a3: \"\\<forall>w \\<in> set W. \\<not> wordinterval_empty w\"\n    and a4: \"(map (\\<lambda>d. runFw x1 d c rs) (map getOneIp W), map (\\<lambda>s. runFw s x1 c rs) (map getOneIp W)) =\n             (map (\\<lambda>d. runFw x2 d c rs) (map getOneIp W), map (\\<lambda>s. runFw s x2 c rs) (map getOneIp W))\"\n      from a3 a4 getOneIp_elem\n        have b1: \"\\<forall>B \\<in> set (map wordinterval_to_set W). \\<exists>b \\<in> B. runFw x1 b c rs = runFw x2 b c rs\"\n        by fastforce\n      from a3 a4 getOneIp_elem\n        have b2: \"\\<forall>B \\<in> set (map wordinterval_to_set W). \\<exists>b \\<in> B. runFw b x1 c rs = runFw b x2 c rs\"\n        by fastforce\n      from runFw_sameFw_behave[OF a1 _ b1 b2] a2[unfolded wordinterval_list_to_set_def] have\n        \"same_fw_behaviour_one x1 x2 c rs\" by simp\n  } note same_behave_runFw=this\n\n  from same_behave_runFw[OF b1 getParts_complete nonempty]\n       groupF_equality[of \"(\\<lambda>wi. (map (\\<lambda>d. runFw (getOneIp wi) d c rs) (map getOneIp (getParts rs)),\n                             map (\\<lambda>s. runFw s (getOneIp wi) c rs) (map getOneIp (getParts rs))))\"\n                     \"(getParts rs)\"] asm\n  have b2: \"\\<forall>a1\\<in>set V. \\<forall>a2\\<in>set V. same_fw_behaviour_one (getOneIp a1) (getOneIp a2) c rs\"\n    apply(subst (asm) groupWIs_def)\n    apply(subst (asm) Let_def)+\n    by fast\n  from groupWIs_not_empty_elems asm have \"\\<forall>w \\<in> set V. \\<not> wordinterval_empty w\" by blast\n  from this b2 getOneIp_elem\n    have b3: \"\\<forall>w1\\<in>set (map wordinterval_to_set V). \\<forall>w2\\<in>set (map wordinterval_to_set V). \n           \\<exists>ip1\\<in> w1. \\<exists>ip2\\<in>w2.\n           same_fw_behaviour_one ip1 ip2 c rs\" by (simp) (blast)\n  from groupParts_same_fw_wi0 asm \n    have \"\\<forall>A\\<in>set (map wordinterval_to_set V). \\<forall>a1\\<in> A. \\<forall>a2\\<in> A. same_fw_behaviour_one a1 a2 c rs\" \n    by metis\n  from sameFw_behave_sets[OF this b3]\n  show \"\\<forall>w1 \\<in> set V. \\<forall>w2 \\<in> set V.\n   \\<forall>a1 \\<in> wordinterval_to_set w1. \\<forall>a2 \\<in> wordinterval_to_set w2. same_fw_behaviour_one a1 a2 c rs\"\n  by force\nqed\n\nlemma groupParts_same_fw_wi2: \"V \\<in> set (groupWIs c rs) \\<Longrightarrow>\n                               \\<forall>ip1 \\<in> wordinterval_list_to_set V.\n                               \\<forall>ip2 \\<in> wordinterval_list_to_set V.\n                               same_fw_behaviour_one ip1 ip2 c rs\"\n  using groupParts_same_fw_wi0 groupParts_same_fw_wi1\n  apply (simp add: wordinterval_list_to_set_def)\n  by fast\n\nlemma groupWIs_same_fw_not2: \"A \\<in> set (groupWIs c rs) \\<Longrightarrow> B \\<in> set (groupWIs c rs) \\<Longrightarrow> \n                                A \\<noteq> B \\<Longrightarrow>\n                                \\<forall>ip1 \\<in> wordinterval_list_to_set A.\n                                \\<forall>ip2 \\<in> wordinterval_list_to_set B.\n                                \\<not> same_fw_behaviour_one ip1 ip2 c rs\"\n  apply(simp add: wordinterval_list_to_set_def)\n  using groupWIs_same_fw_not by fastforce\n\n(*I like this version -- corny*)\nlemma \"A \\<in> set (groupWIs c rs) \\<Longrightarrow> B \\<in> set (groupWIs c rs) \\<Longrightarrow> \n                \\<exists>ip1 \\<in> wordinterval_list_to_set A.\n                \\<exists>ip2 \\<in> wordinterval_list_to_set B. same_fw_behaviour_one ip1 ip2 c rs\n                \\<Longrightarrow> A = B\"\nusing groupWIs_same_fw_not2 by blast\n\n\nlemma groupWIs_complete: \"(\\<Union>x\\<in> set (groupWIs c rs). wordinterval_list_to_set x) = (UNIV::'i::len word set)\"\n  proof -\n  have \"(\\<Union> y \\<in> (\\<Union>x\\<in> set (groupWIs c rs). set x). wordinterval_to_set y) = (UNIV::'i word set)\"\n    apply(simp add: groupWIs_def Let_def groupF_Union_set)\n    using getParts_complete wordinterval_list_to_set_def by fastforce\n  thus ?thesis by(simp add: wordinterval_list_to_set_def)\nqed\n\n\n(*begin groupWIs1 and groupWIs2 optimization*)\n  definition groupWIs1 :: \"'a parts_connection_scheme \\<Rightarrow> 'i::len simple_rule list \\<Rightarrow> 'i wordinterval list list\" where\n    \"groupWIs1 c rs = (let P = getParts rs in\n                        (let W = map getOneIp P in \n                         (let f = (\\<lambda>wi. (map (\\<lambda>d. runFw (getOneIp wi) d c rs) W,\n                                         map (\\<lambda>s. runFw s (getOneIp wi) c rs) W)) in\n                        map (map fst) (groupF snd (map (\\<lambda>x. (x, f x)) P)))))\"\n  \n  lemma groupWIs_groupWIs1_equi: \"groupWIs1 c rs = groupWIs c rs\"\n    apply(subst groupWIs1_def)\n    apply(subst groupWIs_def)\n  using groupF_tuple by metis\n  \n  definition simple_conn_matches :: \"'i::len simple_match \\<Rightarrow> parts_connection \\<Rightarrow> bool\" where\n      \"simple_conn_matches m c \\<longleftrightarrow>\n        (match_iface (iiface m) (pc_iiface c)) \\<and>\n        (match_iface (oiface m) (pc_oiface c)) \\<and>\n        (match_proto (proto m) (pc_proto c)) \\<and>\n        (simple_match_port (sports m) (pc_sport c)) \\<and>\n        (simple_match_port (dports m) (pc_dport c))\"\n  \n  lemma simple_conn_matches_simple_match_any: \"simple_conn_matches simple_match_any c\"\n    apply(simp add: simple_conn_matches_def)\n    apply(simp add: simple_match_any_def match_ifaceAny)\n    apply(subgoal_tac \"(65535::16 word) = max_word\")\n     apply(simp)\n    by(simp add: max_word_def)\n  \n  lemma has_default_policy_simple_conn_matches:\n    \"has_default_policy rs \\<Longrightarrow> has_default_policy [r\\<leftarrow>rs . simple_conn_matches (match_sel r) c]\"\n    apply(induction rs rule: has_default_policy.induct)\n      apply(simp; fail)\n     apply(simp add: simple_conn_matches_simple_match_any; fail)\n    apply(simp)\n    apply(intro conjI)\n     apply(simp split: if_split_asm; fail)\n    apply(simp add: has_default_policy_fst split: if_split_asm)\n    done\n  \n  \n  lemma filter_conn_fw_lem: \n    \"runFw s d c (filter (\\<lambda>r. simple_conn_matches (match_sel r) c) rs) = runFw s d c rs\"\n    apply(simp add: runFw_def simple_conn_matches_def match_sel_def)\n    apply(induction rs \"\\<lparr>p_iiface = pc_iiface c, p_oiface = pc_oiface c,\n                         p_src = s, p_dst = d, p_proto = pc_proto c, \n                         p_sport = pc_sport c, p_dport = pc_dport c,\n                         p_tcp_flags = {TCP_SYN},p_payload=''''\\<rparr>\"\n          rule: simple_fw.induct)\n    apply(simp add: simple_matches.simps)+\n  done\n  \n  \n  (*performance: despite optimization, this function takes quite long and can be optimized*)\n  definition groupWIs2 :: \"parts_connection \\<Rightarrow> 'i::len simple_rule list \\<Rightarrow> 'i wordinterval list list\" where\n    \"groupWIs2 c rs =  (let P = getParts rs in\n                         (let W = map getOneIp P in \n                         (let filterW = (filter (\\<lambda>r. simple_conn_matches (match_sel r) c) rs) in\n                           (let f = (\\<lambda>wi. (map (\\<lambda>d. runFw (getOneIp wi) d c filterW) W,\n                                           map (\\<lambda>s. runFw s (getOneIp wi) c filterW) W)) in\n                        map (map fst) (groupF snd (map (\\<lambda>x. (x, f x)) P))))))\"\n  \n  lemma groupWIs1_groupWIs2_equi: \"groupWIs2 c rs = groupWIs1 c rs\"\n    by(simp add: groupWIs2_def groupWIs1_def filter_conn_fw_lem)\n  \n  \n  lemma groupWIs_code[code]: \"groupWIs c rs = groupWIs2 c rs\"\n    using groupWIs1_groupWIs2_equi groupWIs_groupWIs1_equi by metis\n(*end groupWIs1 and groupWIs2 optimization*)\n\n\n(*begin groupWIs3 optimization*)\n  fun matching_dsts :: \"'i::len word \\<Rightarrow> 'i simple_rule list \\<Rightarrow> 'i wordinterval \\<Rightarrow> 'i wordinterval\" where\n    \"matching_dsts _ [] _ = Empty_WordInterval\" |\n    \"matching_dsts s ((SimpleRule m Accept)#rs) acc_dropped =\n        (if simple_match_ip (src m) s then\n           wordinterval_union (wordinterval_setminus (ipcidr_tuple_to_wordinterval (dst m)) acc_dropped) (matching_dsts s rs acc_dropped)\n         else\n           matching_dsts s rs acc_dropped)\" |\n    \"matching_dsts s ((SimpleRule m Drop)#rs) acc_dropped =\n        (if simple_match_ip (src m) s then\n           matching_dsts s rs (wordinterval_union (ipcidr_tuple_to_wordinterval (dst m)) acc_dropped)\n         else\n           matching_dsts s rs acc_dropped)\"\n  \n  lemma matching_dsts_pull_out_accu:\n    \"wordinterval_to_set (matching_dsts s rs (wordinterval_union a1 a2)) = wordinterval_to_set (matching_dsts s rs a2) - wordinterval_to_set a1\"\n    apply(induction s rs a2 arbitrary: a1 a2 rule: matching_dsts.induct)\n       apply(simp_all)\n    by blast+\n  \n  (*a copy of matching_dsts*)\n  fun matching_srcs :: \"'i::len word \\<Rightarrow> 'i simple_rule list \\<Rightarrow> 'i wordinterval \\<Rightarrow> 'i wordinterval\" where\n    \"matching_srcs _ [] _ = Empty_WordInterval\" |\n    \"matching_srcs d ((SimpleRule m Accept)#rs) acc_dropped =\n        (if simple_match_ip (dst m) d then\n           wordinterval_union (wordinterval_setminus (ipcidr_tuple_to_wordinterval (src m)) acc_dropped) (matching_srcs d rs acc_dropped)\n         else\n           matching_srcs d rs acc_dropped)\" |\n    \"matching_srcs d ((SimpleRule m Drop)#rs) acc_dropped =\n        (if simple_match_ip (dst m) d then\n           matching_srcs d rs (wordinterval_union (ipcidr_tuple_to_wordinterval (src m)) acc_dropped)\n         else\n           matching_srcs d rs acc_dropped)\"\n  \n  lemma matching_srcs_pull_out_accu:\n    \"wordinterval_to_set (matching_srcs d rs (wordinterval_union a1 a2)) = wordinterval_to_set (matching_srcs d rs a2) - wordinterval_to_set a1\"\n    apply(induction d rs a2 arbitrary: a1 a2 rule: matching_srcs.induct)\n       apply(simp_all)\n    by blast+\n  \n  \n  lemma matching_dsts: \"\\<forall>r \\<in> set rs. simple_conn_matches (match_sel r) c \\<Longrightarrow>\n          wordinterval_to_set (matching_dsts s rs Empty_WordInterval) = {d. runFw s d c rs = Decision FinalAllow}\"\n    proof(induction rs)\n    case Nil thus ?case by (simp add: runFw_def)\n    next\n    case (Cons r rs)\n      obtain m a where r: \"r = SimpleRule m a\" by(cases r, blast)\n      \n      from Cons.prems r have simple_match_ip_Accept: \"\\<And>d. simple_match_ip (src m) s \\<Longrightarrow>\n        runFw s d c (SimpleRule m Accept # rs) = Decision FinalAllow \\<longleftrightarrow> simple_match_ip (dst m) d \\<or> runFw s d c rs = Decision FinalAllow\"\n        by(simp add: simple_conn_matches_def runFw_def simple_matches.simps)\n  \n      { fix d a\n        have \"\\<not> simple_match_ip (src m) s \\<Longrightarrow>\n         runFw s d c (SimpleRule m a # rs) = Decision FinalAllow \\<longleftrightarrow> runFw s d c rs = Decision FinalAllow\"\n        apply(cases a)\n         by(simp add: simple_conn_matches_def runFw_def simple_matches.simps)+\n       } note not_simple_match_ip=this\n  \n      from Cons.prems r have simple_match_ip_Drop: \"\\<And>d. simple_match_ip (src m) s \\<Longrightarrow>\n             runFw s d c (SimpleRule m Drop # rs) = Decision FinalAllow \\<longleftrightarrow> \\<not> simple_match_ip (dst m) d \\<and> runFw s d c rs = Decision FinalAllow\"\n        by(simp add: simple_conn_matches_def runFw_def simple_matches.simps)\n  \n      show ?case\n        proof(cases a)\n        case Accept with r Cons show ?thesis\n         apply(simp, intro conjI impI)\n          apply(simp add: simple_match_ip_Accept wordinterval_to_set_ipcidr_tuple_to_wordinterval_simple_match_ip_set)\n          apply blast\n         apply(simp add: not_simple_match_ip; fail)\n         done\n        next\n        case Drop with r Cons show ?thesis\n          apply(simp,intro conjI impI)\n           apply(simp add: simple_match_ip_Drop matching_dsts_pull_out_accu wordinterval_to_set_ipcidr_tuple_to_wordinterval_simple_match_ip_set)\n           apply blast\n          apply(simp add: not_simple_match_ip; fail)\n         done\n        qed\n    qed\n  lemma matching_srcs: \"\\<forall>r \\<in> set rs. simple_conn_matches (match_sel r) c \\<Longrightarrow>\n          wordinterval_to_set (matching_srcs d rs Empty_WordInterval) = {s. runFw s d c rs = Decision FinalAllow}\"\n    proof(induction rs)\n    case Nil thus ?case by (simp add: runFw_def)\n    next\n    case (Cons r rs)\n      obtain m a where r: \"r = SimpleRule m a\" by(cases r, blast)\n      \n      from Cons.prems r have simple_match_ip_Accept: \"\\<And>s. simple_match_ip (dst m) d \\<Longrightarrow>\n         runFw s d c (SimpleRule m Accept # rs) = Decision FinalAllow \\<longleftrightarrow>\n          simple_match_ip (src m) s \\<or> runFw s d c rs = Decision FinalAllow\"\n        by(simp add: simple_conn_matches_def runFw_def simple_matches.simps)\n  \n      { fix s a\n        have \"\\<not> simple_match_ip (dst m) d \\<Longrightarrow>\n         runFw s d c (SimpleRule m a # rs) = Decision FinalAllow \\<longleftrightarrow> runFw s d c rs = Decision FinalAllow\"\n        apply(cases a)\n         by(simp add: simple_conn_matches_def runFw_def simple_matches.simps)+\n       } note not_simple_match_ip=this\n  \n      from Cons.prems r have simple_match_ip_Drop: \"\\<And>s. simple_match_ip (dst m) d \\<Longrightarrow>\n         runFw s d c (SimpleRule m Drop # rs) = Decision FinalAllow \\<longleftrightarrow>\n          \\<not> simple_match_ip (src m) s \\<and> runFw s d c rs = Decision FinalAllow\"\n        by(simp add: simple_conn_matches_def runFw_def simple_matches.simps)\n  \n      show ?case\n        proof(cases a)\n        case Accept with r Cons show ?thesis\n         apply(simp, intro conjI impI)\n          apply(simp add: simple_match_ip_Accept wordinterval_to_set_ipcidr_tuple_to_wordinterval_simple_match_ip_set)\n          apply blast\n         apply(simp add: not_simple_match_ip; fail)\n         done\n        next\n        case Drop with r Cons show ?thesis\n          apply(simp,intro conjI impI)\n           apply(simp add: simple_match_ip_Drop matching_srcs_pull_out_accu wordinterval_to_set_ipcidr_tuple_to_wordinterval_simple_match_ip_set)\n           apply blast\n          apply(simp add: not_simple_match_ip; fail)\n         done\n        qed\n    qed\n  \n  \n  \n  (*TODO: if we can get wordinterval_element to log runtime ...*)\n  definition groupWIs3_default_policy :: \"parts_connection \\<Rightarrow> 'i::len simple_rule list \\<Rightarrow> 'i wordinterval list list\" where\n    \"groupWIs3_default_policy c rs =  (let P = getParts rs in\n                         (let W = map getOneIp P in \n                         (let filterW = (filter (\\<lambda>r. simple_conn_matches (match_sel r) c) rs) in\n                           (let f = (\\<lambda>wi. let mtch_dsts = (matching_dsts (getOneIp wi) filterW Empty_WordInterval);\n                                              mtch_srcs = (matching_srcs (getOneIp wi) filterW Empty_WordInterval) in \n                                          (map (\\<lambda>d. wordinterval_element d mtch_dsts) W,\n                                           map (\\<lambda>s. wordinterval_element s mtch_srcs) W)) in\n                        map (map fst) (groupF snd (map (\\<lambda>x. (x, f x)) P))))))\"\n  \n  \n  lemma groupWIs3_default_policy_groupWIs2:\n  fixes rs :: \"'i::len simple_rule list\"\n  assumes \"has_default_policy rs\"\n  shows \"groupWIs2 c rs = groupWIs3_default_policy c rs\"\n  proof -\n    { fix filterW s d\n      from matching_dsts[where c=c] have \"filterW = filter (\\<lambda>r. simple_conn_matches (match_sel r) c) rs \\<Longrightarrow>\n           wordinterval_element d (matching_dsts s filterW Empty_WordInterval) \\<longleftrightarrow> runFw s d c filterW = Decision FinalAllow\"\n      by force\n    } note matching_dsts_filterW=this[simplified]\n  \n    { fix filterW s d\n      from matching_srcs[where c=c] have \"filterW = filter (\\<lambda>r. simple_conn_matches (match_sel r) c) rs \\<Longrightarrow>\n            wordinterval_element s (matching_srcs d filterW Empty_WordInterval) \\<longleftrightarrow> runFw s d c filterW = Decision FinalAllow\"\n      by force\n    } note matching_srcs_filterW=this[simplified]\n  \n    { fix W and rs :: \"'i::len simple_rule list\"\n      assume assms': \"has_default_policy rs\"\n      have \"groupF (\\<lambda>wi. (map (\\<lambda>d. runFw (getOneIp wi) d c rs = Decision FinalAllow) (map getOneIp W),\n                           map (\\<lambda>s. runFw s (getOneIp wi) c rs = Decision FinalAllow) (map getOneIp W))) W =\n             groupF (\\<lambda>wi. (map (\\<lambda>d. runFw (getOneIp wi) d c rs) (map getOneIp W),\n                           map (\\<lambda>s. runFw s (getOneIp wi) c rs) (map getOneIp W))) W\"\n      proof -\n        { (*unused fresh generic variables. 'a is used for the tuple already*)\n          fix f1::\"'w \\<Rightarrow> 'u \\<Rightarrow> 'v\" and f2::\" 'w \\<Rightarrow> 'u \\<Rightarrow> 'x\" and x and y and g1::\"'w \\<Rightarrow> 'u \\<Rightarrow> 'y\" and g2::\"'w \\<Rightarrow> 'u \\<Rightarrow> 'z\" and W::\"'u list\"\n            assume 1: \"\\<forall>w \\<in> set W. (f1 x) w = (f1 y) w \\<longleftrightarrow> (f2 x) w =  (f2 y) w\"\n               and 2: \"\\<forall>w \\<in> set W. (g1 x) w = (g1 y) w \\<longleftrightarrow> (g2 x) w =  (g2 y) w\"\n               have \"\n                 ((map (f1 x) W, map (g1 x) W) = (map (f1 y) W, map (g1 y) W)) \n                 \\<longleftrightarrow>\n                 ((map (f2 x) W, map (g2 x) W) = (map (f2 y) W, map (g2 y) W))\"\n          proof -\n            from 1 have p1: \"(map (f1 x) W = map (f1 y) W \\<longleftrightarrow> map (f2 x) W = map (f2 y) W)\" by(induction W)(simp_all)\n            from 2 have p2: \"(map (g1 x) W = map (g1 y) W \\<longleftrightarrow> map (g2 x) W = map (g2 y) W)\" by(induction W)(simp_all)\n            from p1 p2 show ?thesis by fast\n          qed\n        } note map_over_tuples_equal_helper=this\n      \n        show ?thesis\n        apply(rule groupF_cong)\n        apply(intro ballI)\n        apply(rule map_over_tuples_equal_helper)\n         using has_default_policy_runFw[OF assms'] by metis+\n      qed\n    } note has_default_policy_groupF=this[simplified]\n  \n    from assms show ?thesis\n    apply(simp add: groupWIs3_default_policy_def groupWIs_code[symmetric])\n    apply(subst groupF_tuple[symmetric])\n    apply(simp add: Let_def)\n    apply(simp add: matching_srcs_filterW matching_dsts_filterW)\n    apply(subst has_default_policy_groupF)\n     apply(simp add: has_default_policy_simple_conn_matches; fail)\n    apply(simp add: groupWIs_def Let_def filter_conn_fw_lem)\n    done\n  qed\n  \n  \n  definition groupWIs3 :: \"parts_connection \\<Rightarrow> 'i::len simple_rule list \\<Rightarrow> 'i wordinterval list list\" where\n    \"groupWIs3 c rs = (if has_default_policy rs then groupWIs3_default_policy c rs else groupWIs2 c rs)\"\n  \n  lemma groupWIs3: \"groupWIs3 = groupWIs\"\n    by(simp add: fun_eq_iff groupWIs3_def groupWIs_code groupWIs3_default_policy_groupWIs2) \n\n(*end groupWIs3 optimization*)\n\n(*construct partitions. main function!*)\ndefinition build_ip_partition :: \"parts_connection \\<Rightarrow> 'i::len simple_rule list \\<Rightarrow> 'i wordinterval list\" where\n  \"build_ip_partition c rs = map\n    (\\<lambda>xs. wordinterval_sort (wordinterval_compress (foldr wordinterval_union xs Empty_WordInterval)))\n      (groupWIs3 c rs)\"\n\n\ntheorem build_ip_partition_same_fw: \"V \\<in> set (build_ip_partition c rs) \\<Longrightarrow>\n                               \\<forall>ip1::'i::len word \\<in> wordinterval_to_set V.\n                               \\<forall>ip2::'i::len word \\<in> wordinterval_to_set V.\n                               same_fw_behaviour_one ip1 ip2 c rs\"\n  apply(simp add: build_ip_partition_def groupWIs3)\n  using wordinterval_list_to_set_compressed groupParts_same_fw_wi2 wordinterval_sort by blast\n\ntheorem build_ip_partition_same_fw_min: \"A \\<in> set (build_ip_partition c rs) \\<Longrightarrow> B \\<in> set (build_ip_partition c rs) \\<Longrightarrow> \n                                A \\<noteq> B \\<Longrightarrow>\n                                \\<forall>ip1::'i::len word \\<in> wordinterval_to_set A.\n                                \\<forall>ip2::'i::len word \\<in> wordinterval_to_set B.\n                                \\<not> same_fw_behaviour_one ip1 ip2 c rs\"\n  apply(simp add: build_ip_partition_def groupWIs3)\n  using  groupWIs_same_fw_not2 wordinterval_list_to_set_compressed wordinterval_sort by blast\n\ntheorem build_ip_partition_complete: \"(\\<Union>x\\<in>set (build_ip_partition c rs). wordinterval_to_set x) = (UNIV :: 'i::len word set)\"\n  proof -\n  have \"wordinterval_to_set (foldr wordinterval_union x Empty_WordInterval) = \\<Union>(set (map wordinterval_to_set x))\"\n    for x::\"'i wordinterval list\"\n    by(induction x) simp_all\n  thus ?thesis\n  apply(simp add: build_ip_partition_def groupWIs3 wordinterval_compress wordinterval_sort)\n  using groupWIs_complete[simplified wordinterval_list_to_set_def] by simp\n  qed\n\n\n\nlemma build_ip_partition_no_empty_elems: \"wi \\<in> set (build_ip_partition c rs) \\<Longrightarrow> \\<not> wordinterval_empty wi\"\n  proof -\n    assume \"wi \\<in> set (build_ip_partition c rs)\"\n    hence assm: \"wi \\<in> (\\<lambda>xs. wordinterval_sort (wordinterval_compress (foldr wordinterval_union xs Empty_WordInterval))) ` set (groupWIs c rs)\"\n      by(simp add: build_ip_partition_def groupWIs3)\n    from assm obtain wi_orig where 1: \"wi_orig \\<in>  set (groupWIs c rs)\" and\n       2: \"wi = wordinterval_sort (wordinterval_compress (foldr wordinterval_union wi_orig Empty_WordInterval))\" by blast\n    from 1 groupWIs_not_empty_elem have i1: \"wi_orig \\<noteq> []\" by blast\n    from 1 groupWIs_not_empty_elems have i2: \"\\<And>w. w \\<in> set wi_orig \\<Longrightarrow> \\<not> wordinterval_empty w\" by simp\n    from i1 i2 have \"wordinterval_to_set (foldr wordinterval_union wi_orig Empty_WordInterval) \\<noteq> {}\"\n      by(induction wi_orig) simp_all\n    with 2 show ?thesis by(simp add: wordinterval_compress wordinterval_sort)\n  qed\n\n\nlemma build_ip_partition_disjoint: \n      \"V1 \\<in> set (build_ip_partition c rs) \\<Longrightarrow> V2 \\<in> set (build_ip_partition c rs) \\<Longrightarrow>\n       V1 \\<noteq> V2 \\<Longrightarrow>\n        wordinterval_to_set V1 \\<inter> wordinterval_to_set V2 = {}\"\n  by (meson build_ip_partition_same_fw_min int_not_emptyD same_fw_behaviour_one_equi(1))\n\n\nlemma map_wordinterval_to_set_distinct:\n  assumes distinct: \"distinct xs\"\n  and disjoint: \"(\\<forall>x1 \\<in> set xs. \\<forall>x2 \\<in> set xs. x1 \\<noteq> x2 \\<longrightarrow> wordinterval_to_set x1 \\<inter> wordinterval_to_set x2 = {})\" \n  and notempty: \"\\<forall>x \\<in> set xs. \\<not> wordinterval_empty x\"\n  shows \"distinct (map wordinterval_to_set xs)\"\n  proof -\n    have \"\\<not> wordinterval_empty x1 \\<Longrightarrow> \n        wordinterval_to_set x1 \\<inter> wordinterval_to_set x2 = {} \\<Longrightarrow> \n        wordinterval_to_set x1 \\<noteq> wordinterval_to_set x2\" for x1::\"('b::len) wordinterval\" and x2\n      by auto\n    with disjoint notempty have \"(\\<forall>x1 \\<in> set xs. \\<forall>x2 \\<in> set xs. x1 \\<noteq> x2 \\<longrightarrow> wordinterval_to_set x1 \\<noteq> wordinterval_to_set x2)\"\n      by force\n    with distinct show \"distinct (map wordinterval_to_set xs)\"\n    proof(induction xs)\n    case Cons thus ?case by simp fast\n    qed(simp)\n  qed\n\nlemma map_getOneIp_distinct: assumes\n  distinct: \"distinct xs\"\n  and disjoint: \"(\\<forall>x1 \\<in> set xs. \\<forall>x2 \\<in> set xs. x1 \\<noteq> x2 \\<longrightarrow> wordinterval_to_set x1 \\<inter> wordinterval_to_set x2 = {})\" \n  and notempty: \"\\<forall>x \\<in> set xs. \\<not> wordinterval_empty x\"\n  shows \"distinct (map getOneIp xs)\"\n  proof -\n    have \"\\<not> wordinterval_empty x \\<Longrightarrow> \\<not> wordinterval_empty xa \\<Longrightarrow> \n          wordinterval_to_set x \\<inter> wordinterval_to_set xa = {} \\<Longrightarrow> getOneIp x \\<noteq> getOneIp xa\"\n     for x xa::\"'b::len wordinterval\"\n     by(fastforce dest: getOneIp_elem)\n    with disjoint notempty have \"(\\<forall>x1 \\<in> set xs. \\<forall>x2 \\<in> set xs. x1 \\<noteq> x2 \\<longrightarrow> getOneIp x1 \\<noteq> getOneIp x2)\"\n      by metis\n    with distinct show ?thesis\n    proof(induction xs)\n    case Cons thus ?case by simp fast\n    qed(simp)\n  qed\n\n\nlemma getParts_disjoint_list: \"disjoint_list (map wordinterval_to_set (getParts rs))\"\nproof-\n  have disjoint_list_partitioningIps: \n    \"{} \\<notin> set (map wordinterval_to_set ts) \\<Longrightarrow> disjoint_list (map wordinterval_to_set ts) \\<Longrightarrow> \n     (wordinterval_list_to_set ss) \\<subseteq> (wordinterval_list_to_set ts) \\<Longrightarrow>\n     disjoint_list (map wordinterval_to_set (partitioningIps ss ts))\"\n     for ts::\"'a::len wordinterval list\" and ss\n  by (simp add: partitioning1_disjoint_list partitioningIps_equi wordinterval_list_to_set_def)\n  have \"{} \\<notin> set (map wordinterval_to_set [wordinterval_UNIV])\"\n  and \"disjoint_list (map wordinterval_to_set [wordinterval_UNIV])\"\n  and \"wordinterval_list_to_set (extract_IPSets rs) \\<subseteq> wordinterval_list_to_set [wordinterval_UNIV]\"\n    by(simp add: wordinterval_list_to_set_def disjoint_list_def disjoint_def)+\n  thus ?thesis\n  unfolding getParts_def by(rule disjoint_list_partitioningIps)\nqed\n\nlemma build_ip_partition_distinct: \"distinct (map wordinterval_to_set (build_ip_partition c rs))\"\nproof -\n  have  \n  \"(wordinterval_to_set \\<circ> (\\<lambda>xs. wordinterval_sort (wordinterval_compress (foldr wordinterval_union xs Empty_WordInterval)))) ws\n       = \\<Union>(set (map wordinterval_to_set ws))\" for ws::\"'a::len wordinterval list\"\n    proof(induction ws)\n    qed(simp_all add: wordinterval_compress wordinterval_sort)\n  hence hlp1: \"map wordinterval_to_set (build_ip_partition c rs) =\n                   map (\\<lambda>x. \\<Union>(set (map wordinterval_to_set x))) (groupWIs c rs)\"\n    unfolding build_ip_partition_def groupWIs3 by auto\n\n  \\<comment> \\<open>generic rule\\<close>\n  have \"\\<forall>x \\<in> set xs. \\<not> wordinterval_empty x \\<Longrightarrow>\n         disjoint_list (map wordinterval_to_set xs) \\<Longrightarrow>\n         distinct (map (\\<lambda>x. \\<Union>(set (map wordinterval_to_set x))) (groupF f xs))\"\n         for f::\"'x::len wordinterval \\<Rightarrow> 'y\" and xs::\"'x::len wordinterval list\"\n    proof(induction f xs rule: groupF.induct)\n    case 1 thus ?case by simp\n    next\n    case (2 f x xs)\n      have hlp_internal:\n          \"\\<Union> (set (map (\\<lambda>x. \\<Union>(set (map wordinterval_to_set x))) (groupF f xs))) =\n           \\<Union> (set (map wordinterval_to_set xs))\" for f::\"'x wordinterval \\<Rightarrow> 'y\" and xs\n      by(induction f xs rule: groupF.induct) (auto)\n\n      from 2(2,3) have \"wordinterval_to_set x \\<inter> \\<Union>(wordinterval_to_set ` set xs) = {}\"\n        by(auto simp add: disjoint_def disjoint_list_def)\n      hence \"\\<not> (wordinterval_to_set x) \\<subseteq> \\<Union>(wordinterval_to_set ` set xs)\" using 2(2) by auto\n      hence \"\\<not> wordinterval_to_set x \\<subseteq> \\<Union>(set (map wordinterval_to_set [y\\<leftarrow>xs . f x \\<noteq> f y]))\" by auto\n      hence \"\\<not> wordinterval_to_set x \\<union> (\\<Union>x\\<in>{xa \\<in> set xs. f x = f xa}.\n         wordinterval_to_set x) \\<subseteq> \\<Union> (set (map (\\<lambda>x. \\<Union>(set (map wordinterval_to_set x))) (groupF f [y\\<leftarrow>xs . f x \\<noteq> f y])))\" \n      unfolding hlp_internal by blast\n      hence g1: \"wordinterval_to_set x \\<union> (\\<Union>x\\<in>{xa \\<in> set xs. f x = f xa}. wordinterval_to_set x)\n        \\<notin> (\\<lambda>x. \\<Union>x\\<in>set x. wordinterval_to_set x) ` set (groupF f [y\\<leftarrow>xs . f x \\<noteq> f y])\" by force\n      \n      from 2(3) have \"distinct (map wordinterval_to_set [y\\<leftarrow>xs . f x \\<noteq> f y])\"\n        by (simp add: disjoint_list_def  distinct_map_filter) \n      moreover from 2 have \"disjoint (wordinterval_to_set ` {xa \\<in> set xs. f x \\<noteq> f xa})\"\n       by(simp add: disjoint_def disjoint_list_def)\n      ultimately have g2: \"distinct (map (\\<lambda>x. \\<Union>x\\<in>set x. wordinterval_to_set x) (groupF f [y\\<leftarrow>xs . f x \\<noteq> f y]))\"\n        using 2(1,2) unfolding disjoint_list_def by(simp)\n\n      from g1 g2 show ?case by simp\n    qed\n    with getParts_disjoint_list getParts_nonempty_elems have\n      \"distinct\n     (map (\\<lambda>x. \\<Union>(set (map wordinterval_to_set x)))\n       (groupF (\\<lambda>wi. (map (\\<lambda>d. runFw (getOneIp wi) d c rs) (map getOneIp (getParts rs)),\n                      map (\\<lambda>s. runFw s (getOneIp wi) c rs) (map getOneIp (getParts rs))))\n         (getParts rs)))\" by blast\n\n  thus ?thesis unfolding hlp1 groupWIs_def Let_def by presburger\nqed\n\nlemma build_ip_partition_distinct': \"distinct (build_ip_partition c rs)\"\n  using build_ip_partition_distinct distinct_mapI by blast\n\n\nsubsection\\<open>Service Matrix over an IP Address Space Partition\\<close>\n\n\ndefinition simple_firewall_without_interfaces :: \"'i::len simple_rule list \\<Rightarrow> bool\" where\n  \"simple_firewall_without_interfaces rs \\<equiv> \\<forall>m \\<in> match_sel ` set rs. iiface m = ifaceAny \\<and> oiface m = ifaceAny\"\n\nlemma simple_fw_no_interfaces:\n  assumes no_ifaces: \"simple_firewall_without_interfaces rs\"\n  shows \"simple_fw rs p = simple_fw rs (p\\<lparr> p_iiface:= x, p_oiface:= y\\<rparr>)\"\nproof -\n  from no_ifaces have \"\\<forall>r\\<in>set rs. iiface (match_sel r) = ifaceAny \\<and> oiface (match_sel r) = ifaceAny\"\n    by(simp add: simple_firewall_without_interfaces_def)\n  thus ?thesis apply(induction rs p rule:simple_fw.induct)\n     by(simp_all add: simple_matches.simps match_ifaceAny)\nqed\n   \nlemma runFw_no_interfaces:\n  assumes no_ifaces: \"simple_firewall_without_interfaces rs\"\n  shows \"runFw s d c rs = runFw s d (c\\<lparr> pc_iiface:= x, pc_oiface:= y\\<rparr>) rs\"\n  apply(simp add: runFw_def)\n  apply(subst simple_fw_no_interfaces[OF no_ifaces])\n  by(simp)\n\n\n\n(*only defined for simple_firewall_without_interfaces*)\ndefinition access_matrix \n  :: \"parts_connection \\<Rightarrow> 'i::len simple_rule list \\<Rightarrow> ('i word \\<times> 'i wordinterval) list \\<times> ('i word \\<times> 'i word) list\" \n  where\n  \"access_matrix c rs \\<equiv>\n    (let W = build_ip_partition c rs;\n         R = map getOneIp W\n     in\n     (zip R W, [(s, d)\\<leftarrow>all_pairs R. runFw s d c rs = Decision FinalAllow]))\"\n\nlemma access_matrix_nodes_defined:\n      \"(V,E) = access_matrix c rs \\<Longrightarrow> (s, d) \\<in> set E \\<Longrightarrow> s \\<in> dom (map_of V)\" and\n      \"(V,E) = access_matrix c rs \\<Longrightarrow> (s, d) \\<in> set E \\<Longrightarrow> d \\<in> dom (map_of V)\"\n  by(auto simp add: access_matrix_def Let_def all_pairs_def)\n\ntext\\<open>For all the entries @{term E} of the matrix, the access is allowed\\<close>\nlemma \"(V,E) = access_matrix c rs \\<Longrightarrow> (s, d) \\<in> set E \\<Longrightarrow> runFw s d c rs = Decision FinalAllow\"\n  by(auto simp add: access_matrix_def Let_def)\ntext\\<open>However, the entries are only a representation of a whole set of IP addresses. \n      For all IP addresses which the entries represent, the access must be allowed.\\<close>\n\n\n(*TODO: move to generic library*)\nlemma map_of_zip_map: \"map_of (zip (map f rs) rs) k = Some v \\<Longrightarrow> k = f v\"\n  apply(induction rs)\n   apply(simp)\n  apply(simp split: if_split_asm)\n  done\n\nlemma access_matrix_sound: assumes matrix: \"(V,E) = access_matrix c rs\" and\n              repr: \"(s_repr, d_repr) \\<in> set E\" and\n              s_range: \"(map_of V) s_repr = Some s_range\" and s: \"s \\<in> wordinterval_to_set s_range\" and\n              d_range: \"(map_of V) d_repr = Some d_range\" and d: \"d \\<in> wordinterval_to_set d_range\"\n      shows \"runFw s d c rs = Decision FinalAllow\"\n  proof -\n    let ?part=\"(build_ip_partition c rs)\"\n    have V: \"V = (zip (map getOneIp ?part) ?part)\"\n      using matrix by(simp add: access_matrix_def Let_def)\n    (*have \"E = [(s, d)\\<leftarrow>all_pairs (map getOneIp ?part). runFw s d c rs = Decision FinalAllow]\"\n      using matrix by(simp add: access_matrix_def Let_def)\n    with repr have \"(s_repr, d_repr) \\<in> set (all_pairs (map getOneIp ?part))\" by simp\n    hence \"s_repr \\<in> set (map getOneIp ?part)\" and\n          \"d_repr \\<in> set (map getOneIp ?part)\"\n      by(simp add: all_pairs_set)+*)\n    (*from s_range have \"(s_repr, s_range) \\<in> set V\" by (simp add: map_of_SomeD)*)\n\n    from matrix repr have repr_Allow: \"runFw s_repr d_repr c rs = Decision FinalAllow\"\n      by(auto simp add: access_matrix_def Let_def)\n\n    have s_range_in_part: \"s_range \\<in> set ?part\" using V s_range by (fastforce elim: in_set_zipE dest: map_of_SomeD)\n    with build_ip_partition_no_empty_elems have \"\\<not> wordinterval_empty s_range\" by simp\n\n    have d_range_in_part: \"d_range \\<in> set ?part\" using V d_range by (fastforce elim: in_set_zipE dest: map_of_SomeD)\n    with build_ip_partition_no_empty_elems have \"\\<not> wordinterval_empty d_range\" by simp\n\n    from map_of_zip_map V s_range have \"s_repr = getOneIp s_range\" by fast\n    with \\<open>\\<not> wordinterval_empty s_range\\<close> getOneIp_elem wordinterval_element_set_eq \n    have \"s_repr \\<in> wordinterval_to_set s_range\" by blast \n\n    from map_of_zip_map V d_range have \"d_repr = getOneIp d_range\" by fast\n    with \\<open>\\<not> wordinterval_empty d_range\\<close> getOneIp_elem wordinterval_element_set_eq \n    have \"d_repr \\<in> wordinterval_to_set d_range\" by blast \n\n    from s_range_in_part have s_range_in_part': \"s_range \\<in> set (build_ip_partition c rs)\" by simp\n    from d_range_in_part have d_range_in_part': \"d_range \\<in> set (build_ip_partition c rs)\" by simp\n\n    from build_ip_partition_same_fw[OF s_range_in_part', unfolded same_fw_behaviour_one_def] s\n                                                        \\<open>s_repr \\<in> wordinterval_to_set s_range\\<close> have \n      \"\\<forall>d. runFw s_repr d c rs = runFw s d c rs\" by blast\n    with repr_Allow have 1: \"runFw s d_repr c rs = Decision FinalAllow\" by simp\n\n    from build_ip_partition_same_fw[OF d_range_in_part', unfolded same_fw_behaviour_one_def] d\n                                                        \\<open>d_repr \\<in> wordinterval_to_set d_range\\<close> have \n      \"\\<forall>s. runFw s d_repr c rs = runFw s d c rs\" by blast\n    with 1 have 2: \"runFw s d c rs = Decision FinalAllow\" by simp\n    thus ?thesis .\nqed\n\n\nlemma distinct_map_getOneIp_obtain: \"v \\<in> set xs \\<Longrightarrow> distinct (map getOneIp xs) \\<Longrightarrow> \n  \\<exists>s_repr. map_of (zip (map getOneIp xs) xs) s_repr = Some v\"\n  proof(induction xs)\n  case Nil thus ?case by simp\n  next\n  case (Cons x xs)\n    consider \"v = x\" | \"v \\<in> set xs\" using Cons.prems(1) by fastforce\n    thus ?case\n    proof(cases)\n    case 1 thus ?thesis by simp blast\n    next\n    case 2 with Cons.IH Cons.prems(2) obtain s_repr where\n      s_repr: \"map_of (zip (map getOneIp xs) xs) s_repr = Some v\" by force\n      show ?thesis\n      proof(cases \"s_repr \\<noteq> getOneIp x\")\n        case True with Cons.prems s_repr show ?thesis by(rule_tac x=s_repr in exI, simp)\n        next\n        case False with Cons.prems s_repr show ?thesis by(fastforce elim: in_set_zipE)\n      qed\n    qed\n  qed\n\n\nlemma access_matrix_complete:\n      fixes rs :: \"'i::len simple_rule list\"\n      assumes matrix: \"(V,E) = access_matrix c rs\" and\n              allow: \"runFw s d c rs = Decision FinalAllow\"\n      shows \"\\<exists>s_repr d_repr s_range d_range. (s_repr, d_repr) \\<in> set E \\<and>\n              (map_of V) s_repr = Some s_range \\<and> s \\<in> wordinterval_to_set s_range \\<and>\n              (map_of V) d_repr = Some d_range \\<and> d \\<in> wordinterval_to_set d_range\"\n  proof -\n    let ?part=\"(build_ip_partition c rs)\"\n    have V: \"V = zip (map getOneIp ?part) ?part\"\n      using matrix by(simp add: access_matrix_def Let_def)\n    have E: \"E = [(s, d)\\<leftarrow>all_pairs (map getOneIp ?part). runFw s d c rs = Decision FinalAllow]\"\n      using matrix by(simp add: access_matrix_def Let_def)\n\n    have build_ip_partition_obtain:\n      \"\\<exists>V. V \\<in> set (build_ip_partition c rs) \\<and> s \\<in> wordinterval_to_set V\" for s\n      using build_ip_partition_complete by blast\n\n    have distinct_map_getOneIp_build_ip_partition_obtain:\n        \"v \\<in> set (build_ip_partition c rs) \\<Longrightarrow>\n           \\<exists>s_repr. map_of (zip (map getOneIp (build_ip_partition c rs)) (build_ip_partition c rs)) s_repr = Some v\"\n      for v and rs :: \"'i::len simple_rule list\"\n    proof(erule distinct_map_getOneIp_obtain)\n      show \"distinct (map getOneIp (build_ip_partition c rs))\"  \n      apply(rule map_getOneIp_distinct)\n        subgoal using build_ip_partition_distinct' by blast\n       subgoal using build_ip_partition_disjoint build_ip_partition_distinct' by blast\n      subgoal using build_ip_partition_no_empty_elems[simplified] by auto\n      done\n    qed\n\n    from build_ip_partition_obtain obtain s_range where\n      \"s_range \\<in> set ?part\" and \"s \\<in> wordinterval_to_set s_range\" by blast\n    from this distinct_map_getOneIp_build_ip_partition_obtain V obtain s_repr where\n      ex_s1: \"(map_of V) s_repr = Some s_range\" and ex_s2: \"s \\<in> wordinterval_to_set s_range\"\n      by blast\n\n\n    from build_ip_partition_obtain obtain d_range where\n      \"d_range \\<in> set ?part\" and \"d \\<in> wordinterval_to_set d_range\" by blast\n    from this distinct_map_getOneIp_build_ip_partition_obtain V obtain d_repr where\n      ex_d1: \"(map_of V) d_repr = Some d_range\" and ex_d2: \"d \\<in> wordinterval_to_set d_range\"\n      by blast\n\n    have 1: \"s_repr \\<in> getOneIp ` set (build_ip_partition c rs)\"\n      using V \\<open>map_of V s_repr = Some s_range\\<close> by (fastforce elim: in_set_zipE dest: map_of_SomeD)\n    have 2: \"d_repr \\<in> getOneIp ` set (build_ip_partition c rs)\"\n      using V \\<open>map_of V d_repr = Some d_range\\<close> by (fastforce elim: in_set_zipE dest: map_of_SomeD)\n\n    have \"runFw s_repr d_repr c rs = Decision FinalAllow\"\n    proof -\n      have f1: \"(\\<forall>w wa p ss. \\<not> same_fw_behaviour_one w wa (p::parts_connection) ss \\<or>\n              (\\<forall>wb wc. runFw w wb p ss = runFw wa wb p ss \\<and> runFw wc w p ss = runFw wc wa p ss)) \\<and>\n              (\\<forall>w wa p ss. (\\<exists>wb wc. runFw w wb (p::parts_connection) ss \\<noteq> runFw wa wb p ss \\<or> runFw wc w p ss \\<noteq> runFw wc wa p ss) \\<or>\n              same_fw_behaviour_one w wa p ss)\"\n        unfolding same_fw_behaviour_one_def by blast\n      from \\<open>s_range \\<in> set (build_ip_partition c rs)\\<close>  have f2: \"same_fw_behaviour_one s s_repr c rs\"\n        by (metis (no_types) map_of_zip_map V build_ip_partition_no_empty_elems\n            build_ip_partition_same_fw ex_s1 ex_s2 getOneIp_elem wordinterval_element_set_eq)\n      from \\<open>d_range \\<in> set (build_ip_partition c rs)\\<close> have \"same_fw_behaviour_one d_repr d c rs\"\n        by (metis (no_types) map_of_zip_map V build_ip_partition_no_empty_elems\n            build_ip_partition_same_fw ex_d1 ex_d2 getOneIp_elem wordinterval_element_set_eq)\n      with f1 f2 show ?thesis\n        using allow by metis\n    qed\n      \n    hence ex1: \"(s_repr, d_repr) \\<in> set E\" by(simp add: E all_pairs_set 1 2)\n    \n    thus ?thesis using ex1 ex_s1 ex_s2 ex_d1 ex_d2 by blast \nqed\n\n\ntheorem access_matrix:\n      fixes rs :: \"'i::len simple_rule list\"\n      assumes matrix: \"(V,E) = access_matrix c rs\"\n      shows \"(\\<exists>s_repr d_repr s_range d_range. (s_repr, d_repr) \\<in> set E \\<and>\n              (map_of V) s_repr = Some s_range \\<and> s \\<in> wordinterval_to_set s_range \\<and>\n              (map_of V) d_repr = Some d_range \\<and> d \\<in> wordinterval_to_set d_range)\n             \\<longleftrightarrow>\n             runFw s d c rs = Decision FinalAllow\"\nusing matrix access_matrix_sound access_matrix_complete by blast\n\ntext\\<open>\nFor a @{typ \"'i::len simple_rule list\"} and a fixed @{typ parts_connection}, \nwe support to partition the IP address space; for IP addresses of arbitrary length (eg., IPv4, IPv6).\n\nAll members of a partition have the same access rights:\n@{thm build_ip_partition_same_fw [no_vars]}\n\nMinimal:\n@{thm build_ip_partition_same_fw_min [no_vars]}\n\n\nThe resulting access control matrix is sound and complete:\n\n@{thm access_matrix [no_vars]}\n\nTheorem reads: \nFor a fixed connection, you can look up IP addresses (source and destination pairs) in the matrix \nif and only if the firewall accepts this src,dst IP address pair for the fixed connection.\nNote: The matrix is actually a graph (nice visualization!), you need to look up IP addresses \nin the Vertices and check the access of the representants in the edges. If you want to visualize\nthe graph (e.g. with Graphviz or tkiz): The vertices are the node description (i.e. header; \n  @{term \"dom V\"} is the label for each node which will also be referenced in the edges,\n  @{term \"ran V\"} is the human-readable description for each node (i.e. the full IP range it represents)), \nthe edges are the edges. Result looks nice. Theorem also tells us that this visualization is correct.\n\\<close>\n\n\n\n\n(*construct an ip partition and print it in some usable format\n  returns:\n  (vertices, edges) where\n  vertices = (name, list of ip addresses this vertex corresponds to)\n  and edges = (name \\<times> name) list\n\n  Note that the WordInterval is already sorted, which is important for prettyness!\n*)\ntext\\<open>Only defined for @{const simple_firewall_without_interfaces}\\<close>\ndefinition access_matrix_pretty_ipv4\n  :: \"parts_connection \\<Rightarrow> 32 simple_rule list \\<Rightarrow> (string \\<times> string) list \\<times> (string \\<times> string) list\" \n  where\n  \"access_matrix_pretty_ipv4 c rs \\<equiv>\n    if \\<not> simple_firewall_without_interfaces rs then undefined else\n    (let (V,E) = (access_matrix c rs);\n         formatted_nodes =\n              map (\\<lambda>(v_repr, v_range). (ipv4addr_toString v_repr, ipv4addr_wordinterval_toString v_range)) V;\n         formatted_edges =\n              map (\\<lambda>(s,d). (ipv4addr_toString s, ipv4addr_toString d)) E\n     in\n      (formatted_nodes, formatted_edges)\n    )\"\n\ndefinition access_matrix_pretty_ipv4_code\n  :: \"parts_connection \\<Rightarrow> 32 simple_rule list \\<Rightarrow> (string \\<times> string) list \\<times> (string \\<times> string) list\" \n  where\n  \"access_matrix_pretty_ipv4_code c rs \\<equiv>\n    if \\<not> simple_firewall_without_interfaces rs then undefined else\n    (let W = build_ip_partition c rs;\n         R = map getOneIp W;\n         U = all_pairs R\n     in\n     (zip (map ipv4addr_toString R) (map ipv4addr_wordinterval_toString W), \n      map (\\<lambda>(x,y). (ipv4addr_toString x, ipv4addr_toString y)) [(s, d)\\<leftarrow>all_pairs R. runFw s d c rs = Decision FinalAllow]))\"\n\nlemma access_matrix_pretty_ipv4_code[code]: \"access_matrix_pretty_ipv4 = access_matrix_pretty_ipv4_code\"\n  by(simp add: fun_eq_iff access_matrix_pretty_ipv4_def access_matrix_pretty_ipv4_code_def Let_def access_matrix_def map_prod_fun_zip)\n\n\ndefinition access_matrix_pretty_ipv6\n  :: \"parts_connection \\<Rightarrow> 128 simple_rule list \\<Rightarrow> (string \\<times> string) list \\<times> (string \\<times> string) list\" \n  where\n  \"access_matrix_pretty_ipv6 c rs \\<equiv>\n    if \\<not> simple_firewall_without_interfaces rs then undefined else\n    (let (V,E) = (access_matrix c rs);\n         formatted_nodes =\n              map (\\<lambda>(v_repr, v_range). (ipv6addr_toString v_repr, ipv6addr_wordinterval_toString v_range)) V;\n         formatted_edges =\n              map (\\<lambda>(s,d). (ipv6addr_toString s, ipv6addr_toString d)) E\n     in\n      (formatted_nodes, formatted_edges)\n    )\"\n\ndefinition access_matrix_pretty_ipv6_code\n  :: \"parts_connection \\<Rightarrow> 128 simple_rule list \\<Rightarrow> (string \\<times> string) list \\<times> (string \\<times> string) list\" \n  where\n  \"access_matrix_pretty_ipv6_code c rs \\<equiv>\n    if \\<not> simple_firewall_without_interfaces rs then undefined else\n    (let W = build_ip_partition c rs;\n         R = map getOneIp W;\n         U = all_pairs R\n     in\n     (zip (map ipv6addr_toString R) (map ipv6addr_wordinterval_toString W), \n      map (\\<lambda>(x,y). (ipv6addr_toString x, ipv6addr_toString y)) [(s, d)\\<leftarrow>all_pairs R. runFw s d c rs = Decision FinalAllow]))\"\n\nlemma access_matrix_pretty_ipv6_code[code]: \"access_matrix_pretty_ipv6 = access_matrix_pretty_ipv6_code\"\n  by(simp add: fun_eq_iff access_matrix_pretty_ipv6_def access_matrix_pretty_ipv6_code_def Let_def access_matrix_def map_prod_fun_zip)\n\n  \n\ndefinition parts_connection_ssh where\n  \"parts_connection_ssh \\<equiv> \\<lparr>pc_iiface=''1'', pc_oiface=''1'', pc_proto=TCP, pc_sport=10000, pc_dport=22\\<rparr>\"\n\ndefinition parts_connection_http where\n  \"parts_connection_http \\<equiv> \\<lparr>pc_iiface=''1'', pc_oiface=''1'', pc_proto=TCP, pc_sport=10000, pc_dport=80\\<rparr>\"\n\n\ndefinition mk_parts_connection_TCP :: \"16 word \\<Rightarrow> 16 word \\<Rightarrow> parts_connection\" where\n  \"mk_parts_connection_TCP sport dport = \\<lparr>pc_iiface=''1'', pc_oiface=''1'', pc_proto=TCP,\n                               pc_sport=sport, pc_dport=dport\\<rparr>\"\n\nlemma \"mk_parts_connection_TCP 10000 22 = parts_connection_ssh\"\n      \"mk_parts_connection_TCP 10000 80 = parts_connection_http\"\n  by(simp_all add: mk_parts_connection_TCP_def parts_connection_ssh_def parts_connection_http_def)\n\n\nvalue[code] \"partitioningIps [WordInterval (0::ipv4addr) 0] [WordInterval 0 2, WordInterval 0 2]\"\n\n\ntext_raw\\<open>\nHere is an example of a really large and complicated firewall:\n\n\n\\begin{figure}\n\\centering\n\\resizebox{\\linewidth}{!}{%\n\\tikzset{every loop/.style={looseness=1}}\n\\tikzset{myptr/.style={decoration={markings,mark=at position 1 with %\n    {\\arrow[scale=2,>=latex]{>}}},shorten >=0.1cm,shorten <=0.2cm, postaction={decorate}}}%\n\\tikzset{myloop/.style={-to}}%\n\\begin{tikzpicture}\n\\node (m) at (2,-2) {$\\{224.0.0.0 .. 239.255.255.255\\}$};\n\n\\node[align=left] (inet) at (-3,8.5) {$\\{0.0.0.0 .. 126.255.255.255\\} \\cup \\{128.0.0.0 .. 131.159.13.255\\} \\cup $ \\\\ \n\t\t\t\t\t\t\t\t\t $ \\{131.159.16.0 .. 131.159.19.255\\} \\cup \\{131.159.22.0 .. 138.246.253.4\\} \\cup $ \\\\ \n\t\t\t\t\t\t\t\t\t $ \\{138.246.253.11 .. 185.86.231.255\\} \\cup \\{185.86.236.0 .. 188.1.239.85\\} \\cup $ \\\\ \n\t\t\t\t\t\t\t\t\t $ \\{188.1.239.87 .. 188.95.232.63\\} \\cup \\{188.95.232.224 .. 188.95.232.255\\} \\cup $\\\\\n\t\t\t\t\t\t\t\t\t $ \\{188.95.240.0 .. 192.48.106.255\\} \\cup \\{192.48.108.0 .. 223.255.255.255\\} \\cup $\\\\\n\t\t\t\t\t\t\t\t\t $ \\{240.0.0.0 .. 255.255.255.255\\}$};\n\\node[align=left] (internal) at (-5,-10) {$\\{131.159.14.0 .. 131.159.14.7\\} \\cup \\{131.159.14.12 .. 131.159.14.25\\} \\cup $ \\\\ \n$ 131.159.14.27 \\cup \\{131.159.14.29 .. 131.159.14.33\\} \\cup $ \\\\ \n$ \\{131.159.14.38 .. 131.159.14.39\\} \\cup 131.159.14.41 \\cup $ \\\\ \n$ \\{131.159.14.43 .. 131.159.14.51\\} \\cup \\{131.159.14.53 .. 131.159.14.55\\} \\cup $ \\\\ \n$ \\{131.159.14.57 .. 131.159.14.59\\} \\cup \\{131.159.14.61 .. 131.159.14.68\\} \\cup $ \\\\ \n$ 131.159.14.70 .. 131.159.14.82\\} \\cup \\{131.159.14.84 .. 131.159.14.103\\} \\cup $ \\\\ \n$ \\{131.159.14.105 .. 131.159.14.124\\} \\cup \\{131.159.14.126 .. 131.159.14.136\\} \\cup $ \\\\  \n$ \\{131.159.14.138 .. 131.159.14.139\\} \\cup \\{131.159.14.141 .. 131.159.14.144\\} \\cup $ \\\\ \n$ \\{131.159.14.147 .. 131.159.14.154\\} \\cup \\{131.159.14.157 .. 131.159.14.162\\} \\cup $ \\\\ \n$ \\{131.159.14.164 .. 131.159.14.168\\} \\cup \\{131.159.14.170 .. 131.159.14.200\\} \\cup $ \\\\ \n$ \\{131.159.14.202 .. 131.159.14.213\\} \\cup \\{131.159.14.215 .. 131.159.15.4\\} \\cup $ \\\\ \n$ 131.159.15.6 \\cup \\{131.159.15.14 .. 131.159.15.15\\} \\cup $ \\\\ \n$ \\{131.159.15.21 .. 131.159.15.22\\} \\cup 131.159.15.26 \\cup 131.159.15.28 \\cup $ \\\\ \n$ 131.159.15.30 \\cup \\{131.159.15.33 .. 131.159.15.35\\} \\cup $ \\\\ \n$ \\{131.159.15.37 .. 131.159.15.38\\} \\cup 131.159.15.40 \\cup $ \\\\ \n$ \\{131.159.15.45 .. 131.159.15.46\\} \\cup \\{131.159.15.48 .. 131.159.15.49\\} \\cup $ \\\\ \n$ \\{131.159.15.52 .. 131.159.15.55\\} \\cup 131.159.15.57 \\cup 131.159.15.59 \\cup $ \\\\ \n$ \\{131.159.15.61 .. 131.159.15.67\\} \\cup \\{131.159.15.70 .. 131.159.15.196\\} \\cup $ \\\\ \n$ \\{131.159.15.198 .. 131.159.15.227\\} \\cup \\{131.159.15.229 .. 131.159.15.233\\} \\cup $ \\\\ \n$ \\{131.159.15.235 .. 131.159.15.246\\} \\cup \\{131.159.15.250 .. 131.159.15.255\\} \\cup $ \\\\ \n$ \\{131.159.20.0 .. 131.159.20.20\\} \\cup \\{131.159.20.22 .. 131.159.20.28\\} \\cup $ \\\\ \n$ \\{131.159.20.30 .. 131.159.20.35\\} \\cup \\{131.159.20.37 .. 131.159.20.44\\} \\cup $ \\\\ \n$ \\{131.159.20.46 .. 131.159.20.51\\} \\cup \\{131.159.20.53 .. 131.159.20.58\\} \\cup $ \\\\ \n$ \\{131.159.20.60 .. 131.159.20.62\\} \\cup \\{131.159.20.64 .. 131.159.20.70\\} \\cup $ \\\\ \n$ \\{131.159.20.72 .. 131.159.20.73\\} \\cup \\{131.159.20.75 .. 131.159.20.84\\} \\cup $ \\\\ \n$ \\{131.159.20.86 .. 131.159.20.96\\} \\cup \\{131.159.20.98 .. 131.159.20.119\\} \\cup $ \\\\ \n$ \\{131.159.20.121 .. 131.159.20.138\\} \\cup \\{131.159.20.140 .. 131.159.20.149\\} \\cup $ \\\\ \n$ \\{131.159.20.152 .. 131.159.20.154\\} \\cup \\{131.159.20.156 .. 131.159.20.159\\} \\cup $ \\\\ \n$ \\{131.159.20.161 .. 131.159.20.164\\} \\cup \\{131.159.20.167 .. 131.159.20.179\\} \\cup $ \\\\ \n$ \\{131.159.20.181 .. 131.159.20.184\\} \\cup \\{131.159.20.186 .. 131.159.20.199\\} \\cup $ \\\\ \n$ \\{131.159.20.201 .. 131.159.20.232\\} \\cup \\{131.159.20.235 .. 131.159.20.255\\} \\cup $ \\\\ \n$ \\{185.86.232.0 .. 185.86.235.255\\} \\cup \\{188.95.233.0 .. 188.95.233.3\\} \\cup $ \\\\ \n$ \\{188.95.233.5 .. 188.95.233.8\\} \\cup \\{188.95.233.10 .. 188.95.233.255\\} \\cup $ \\\\ \n$ \\{192.48.107.0 .. 192.48.107.255\\}$}; \n\n\\node[align=left] (srvs) at (10,0) {$\\{131.159.14.8 .. 131.159.14.11\\} \\cup 131.159.14.26 \\cup 131.159.14.28 \\cup $ \\\\ \n$ \\{131.159.14.34 .. 131.159.14.37\\} \\cup 131.159.14.40 \\cup 131.159.14.42 \\cup $ \\\\ \n$ 131.159.14.52 \\cup 131.159.14.56 \\cup 131.159.14.60 \\cup 131.159.14.69 \\cup $ \\\\ \n$ 131.159.14.83 \\cup 131.159.14.104 \\cup 131.159.14.125 \\cup 131.159.14.137 \\cup $ \\\\ \n$ 131.159.14.140 \\cup \\{131.159.14.145 .. 131.159.14.146\\} \\cup $ \\\\ \n$ \\{131.159.14.155 .. 131.159.14.156\\} \\cup 131.159.14.163 \\cup 131.159.14.169 \\cup $ \\\\ \n$ 131.159.14.201 \\cup 131.159.14.214 \\cup 131.159.15.5 \\cup $ \\\\ \n$ \\{131.159.15.7 .. 131.159.15.13\\} \\cup \\{131.159.15.16 .. 131.159.15.20\\} \\cup $ \\\\ \n$ \\{131.159.15.23 .. 131.159.15.25\\} \\cup 131.159.15.27 \\cup 131.159.15.29 \\cup $ \\\\ \n$ \\{131.159.15.31 .. 131.159.15.32\\} \\cup 131.159.15.36 \\cup 131.159.15.39 \\cup $ \\\\ \n$ \\{131.159.15.41 .. 131.159.15.44\\} \\cup 131.159.15.47 \\cup 131.159.15.51 \\cup $ \\\\ \n$ 131.159.15.56 \\cup 131.159.15.58 \\cup 131.159.15.60 \\cup $ \\\\ \n$ \\{131.159.15.68 .. 131.159.15.69\\} \\cup 131.159.15.197 \\cup 131.159.15.228 \\cup $ \\\\ \n$ 131.159.15.234 \\cup \\{131.159.15.247 .. 131.159.15.249\\} \\cup 131.159.20.21 \\cup $ \\\\ \n$ 131.159.20.29 \\cup 131.159.20.36 \\cup 131.159.20.45 \\cup 131.159.20.52 \\cup $ \\\\ \n$ 131.159.20.59 \\cup 131.159.20.63 \\cup 131.159.20.71 \\cup 131.159.20.74 \\cup $ \\\\ \n$ 131.159.20.85 \\cup 131.159.20.97 \\cup 131.159.20.120 \\cup 131.159.20.139 \\cup $ \\\\ \n$ \\{131.159.20.150 .. 131.159.20.151\\} \\cup 131.159.20.155 \\cup 131.159.20.160 \\cup $ \\\\ \n$ \\{131.159.20.165 .. 131.159.20.166\\} \\cup 131.159.20.180 \\cup 131.159.20.185 \\cup $ \\\\ \n$ 131.159.20.200 \\cup \\{131.159.20.233 .. 131.159.20.234\\} \\cup $ \\\\ \n$ \\{131.159.21.0 .. 131.159.21.255\\} \\cup \\{188.95.232.192 .. 188.95.232.223\\} \\cup $ \\\\ \n$ 188.95.233.4 \\cup 188.95.233.9 \\cup \\{188.95.234.0 .. 188.95.239.255\\}$}; \n\n\\node[align=left] (ips1) at (-3,-1) {$188.1.239.86 \\cup \\{188.95.232.64 .. 188.95.232.191\\}$};\n\n\\node[align=left] (ips2) at (10,-8) {$\\{138.246.253.6 .. 138.246.253.10\\}$};\n\n\\node[align=left] (ip3) at (5,-6) {$138.246.253.5$};\n\n\\node[align=left] (ip4) at (4.5,-8) {$131.159.15.50$};\n\n\\node[align=left] (l) at (8,-10) {$\\{127.0.0.0 .. 127.255.255.255\\}$};\n\n\n\n\\draw[myloop] (m) to[loop above] (m);\n\\draw[myptr] (m) to (srvs);\n\\draw[myptr] (inet) to (m);\n\\draw[myptr] (inet) to (srvs);\n\\draw[myptr,shorten <=-0.8cm] (internal) to (m);\n\\draw[myptr] (internal) to (inet);\n\\draw[myloop] (internal) to[loop above] (internal);\n\\draw[myptr] (internal) to (srvs);\n\\draw[myptr] (internal) to (ips1);\n\\draw[myptr] (internal) to (ips2);\n\\draw[myptr] (internal) to (ip3);\n\\draw[myptr] (internal) to (ip4);\n\\draw[myptr] (internal) to (l);\n\\draw[myptr] (srvs) to (m);\n\\draw[myptr] (srvs) to (inet);\n\\draw[myptr] (srvs) to (internal);\n\\draw[myloop] (srvs) to[loop above] (srvs);\n\\draw[myptr] (srvs) to (ips1);\n\\draw[myptr] (srvs) to (ips2);\n\\draw[myptr] (srvs) to (ip3);\n\\draw[myptr] (srvs) to (ip4);\n\\draw[myptr] (srvs) to (l);\n\\draw[myptr] (ips1) to (m);\n\\draw[myptr] (ips1) to (inet);\n\\draw[myptr] (ips1) to (internal);\n\\draw[myptr] (ips1) to (srvs);\n\\draw[myloop] (ips1.west) to[loop left] (ips1);\n\\draw[myptr] (ips1) to (ips2);\n\\draw[myptr] (ips1) to (ip3);\n\\draw[myptr] (ips1) to (ip4);\n\\draw[myptr] (ips1) to (l);\n\\draw[myptr] (ips2) to (m);\n\\draw[myptr] (ips2) to (srvs);\n\\draw[myptr] (ips2) to (ip4);\n\\draw[myptr] (ip3) to (m);\n\\draw[myptr] (ip3) to (internal);\n\\draw[myptr] (ip3) to (srvs);\n\\draw[myptr] (ip3) to (ip4);\n\\draw[myptr] (ip4) to (m);\n\\draw[myptr] (ip4) to (inet);\n\\draw[myptr] (ip4) to (internal);\n\\draw[myptr] (ip4) to (srvs);\n\\draw[myptr] (ip4) to (ips1);\n\\draw[myptr] (ip4) to (ips2);\n\\draw[myptr] (ip4) to (ip3);\n\\draw[myloop] (ip4) to[loop below] (ip4);\n\\draw[myptr] (ip4) to (l);\n\n\\end{tikzpicture}%\n}\n\\caption{TUM ssh Service Matrix}\n\\label{fig:tumssh}\n\\end{figure}\n\n\\<close>\n\n\nend                            \n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Simple_Firewall/Service_Matrix.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5813030906443134, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.2770372241015033}}
{"text": "(*  Title:       Tree Automata\n    Author:      Peter Lammich <peter dot lammich at uni-muenster.de>\n    Maintainer:  Peter Lammich <peter dot lammich at uni-muenster.de>\n*)\nsection \"Executable Implementation of Tree Automata\"\ntheory Ta_impl\nimports \n  Main\n  Collections.CollectionsV1 \n  Ta AbsAlgo\n  \"HOL-Library.Code_Target_Numeral\" \nbegin\n\n\n\n\ntext_raw \\<open>\\label{sec:taimpl}\\<close>\n\ntext \\<open>\n  In this theory, an effcient executable implementation of non-deterministic \n  tree automata and basic algorithms is defined.\n\n  The algorithms use red-black trees to represent sets of states or rules \n  where appropriate.\n\\<close>\n\nsubsection \"Prelude\"\n\n  \\<comment> \\<open>Make rules hashable\\<close>\ninstantiation ta_rule :: (hashable,hashable) hashable\nbegin\nfun hashcode_of_ta_rule \n  :: \"('Q1::hashable,'Q2::hashable) ta_rule \\<Rightarrow> hashcode\" \n  where\n  \"hashcode_of_ta_rule (q \\<rightarrow> f qs) = hashcode q + hashcode f + hashcode qs\"\n\ndefinition [simp]: \"hashcode = hashcode_of_ta_rule\"\n\ndefinition \"def_hashmap_size::(('a,'b) ta_rule itself \\<Rightarrow> nat) == (\\<lambda>_. 32)\"\n\ninstance \n  by (intro_classes)(auto simp add: def_hashmap_size_ta_rule_def)\nend\n\n\n  \\<comment> \\<open>Make wrapped states hashable\\<close>\ninstantiation ustate_wrapper :: (hashable,hashable) hashable\nbegin\n  definition \"hashcode x == (case x of USW1 a \\<Rightarrow> 2 * hashcode a | USW2 b \\<Rightarrow> 2 * hashcode b + 1)\"\n  definition \"def_hashmap_size = (\\<lambda>_ :: (('a,'b) ustate_wrapper) itself. def_hashmap_size TYPE('a) + def_hashmap_size TYPE('b))\"\n\n  instance using def_hashmap_size[where ?'a=\"'a\"] def_hashmap_size[where ?'a=\"'b\"]\n    by(intro_classes)(simp_all add: bounded_hashcode_bounds def_hashmap_size_ustate_wrapper_def split: ustate_wrapper.split)\n\nend\n\nsubsubsection \\<open>Ad-Hoc instantiations of generic Algorithms\\<close>\nsetup Locale_Code.open_block\ninterpretation hll_idx: build_index_loc hm_ops ls_ops ls_ops by unfold_locales\ninterpretation ll_set_xy: g_set_xy_loc ls_ops ls_ops \n  by unfold_locales\n\ninterpretation lh_set_xx: g_set_xx_loc ls_ops hs_ops\n  by unfold_locales\ninterpretation lll_iflt_cp: inj_image_filter_cp_loc ls_ops ls_ops ls_ops\n  by unfold_locales\ninterpretation hhh_cart: cart_loc hs_ops hs_ops hs_ops by unfold_locales\ninterpretation hh_set_xy: g_set_xy_loc hs_ops hs_ops \n  by unfold_locales\n\ninterpretation llh_set_xyy: g_set_xyy_loc ls_ops ls_ops hs_ops\n  by unfold_locales\n\ninterpretation hh_map_to_nat: map_to_nat_loc hs_ops hm_ops by unfold_locales\ninterpretation hh_set_xy: g_set_xy_loc hs_ops hs_ops by unfold_locales\ninterpretation lh_set_xy: g_set_xy_loc ls_ops hs_ops by unfold_locales\ninterpretation hh_set_xx: g_set_xx_loc hs_ops hs_ops by unfold_locales\ninterpretation hs_to_fifo: set_to_list_loc hs_ops fifo_ops by unfold_locales\n\nsetup Locale_Code.close_block\n\nsubsection \"Generating Indices of Rules\"\ntext \\<open>\n  Rule indices are pieces of extra information that may be attached to a \n  tree automaton.\n  There are three possible rule indices\n    \\begin{description}\n      \\item[f]   index of rules by function symbol\n      \\item[s]   index of rules by lhs\n      \\item[sf]  index of rules\n    \\end{description}\n\\<close>\n\ndefinition build_rule_index \n  :: \"(('q,'l) ta_rule \\<Rightarrow> 'i::hashable) \\<Rightarrow> ('q,'l) ta_rule ls \n      \\<Rightarrow> ('i,('q,'l) ta_rule ls) hm\"\n  where \"build_rule_index == hll_idx.idx_build\"\n\ndefinition \"build_rule_index_f \\<delta> == build_rule_index (\\<lambda>r. rhsl r) \\<delta>\"\ndefinition \"build_rule_index_s \\<delta> == build_rule_index (\\<lambda>r. lhs r) \\<delta>\"\ndefinition \"build_rule_index_sf \\<delta> == build_rule_index (\\<lambda>r. (lhs r, rhsl r)) \\<delta>\"\n\nlemma build_rule_index_f_correct[simp]: \n  assumes I[simp, intro!]: \"ls_invar \\<delta>\"\n  shows \"hll_idx.is_index rhsl (ls_\\<alpha> \\<delta>) (build_rule_index_f \\<delta>)\"\n  apply (unfold build_rule_index_f_def build_rule_index_def)\n  apply (simp add: hll_idx.idx_build_is_index)\n  done\n\nlemma build_rule_index_s_correct[simp]: \n  assumes I[simp, intro!]: \"ls_invar \\<delta>\"\n  shows\n  \"hll_idx.is_index lhs (ls_\\<alpha> \\<delta>) (build_rule_index_s \\<delta>)\"\n  by (unfold build_rule_index_s_def build_rule_index_def)\n     (simp add: hll_idx.idx_build_is_index)\n\nlemma build_rule_index_sf_correct[simp]: \n  assumes I[simp, intro!]: \"ls_invar \\<delta>\"\n  shows\n  \"hll_idx.is_index (\\<lambda>r. (lhs r, rhsl r)) (ls_\\<alpha> \\<delta>) (build_rule_index_sf \\<delta>)\"\n  by (unfold build_rule_index_sf_def build_rule_index_def)\n     (simp add: hll_idx.idx_build_is_index)\n\nsubsection \"Tree Automaton with Optional Indices\"\n\ntext \\<open>\n  A tree automaton contains a hashset of initial states, a list-set of rules and\n  several (optional) rule indices.\n\\<close>\n\nrecord (overloaded) ('q,'l) hashedTa =\n    \\<comment> \\<open>Initial states\\<close>\n  hta_Qi :: \"'q hs\"           \n    \\<comment> \\<open>Rules\\<close>\n  hta_\\<delta> :: \"('q,'l) ta_rule ls\"    \n    \\<comment> \\<open>Rules by function symbol\\<close>\n  hta_idx_f :: \"('l,('q,'l) ta_rule ls) hm option\" \n    \\<comment> \\<open>Rules by lhs state\\<close>\n  hta_idx_s :: \"('q,('q,'l) ta_rule ls) hm option\" \n    \\<comment> \\<open>Rules by lhs state and function symbol\\<close>\n  hta_idx_sf :: \"('q\\<times>'l,('q,'l) ta_rule ls) hm option\" \n\n  \\<comment> \\<open>Abstraction of a concrete tree automaton to an abstract one\\<close>\ndefinition hta_\\<alpha> \n  where \"hta_\\<alpha> H = \\<lparr> ta_initial = hs_\\<alpha> (hta_Qi H), ta_rules = ls_\\<alpha> (hta_\\<delta> H) \\<rparr>\"\n\n  \\<comment> \\<open>Builds the f-index if not present\\<close>\ndefinition \"hta_ensure_idx_f H ==\n  case hta_idx_f H of \n    None \\<Rightarrow> H\\<lparr> hta_idx_f := Some (build_rule_index_f (hta_\\<delta> H)) \\<rparr> |\n    Some _ \\<Rightarrow> H\n  \"\n\n  \\<comment> \\<open>Builds the s-index if not present\\<close>\ndefinition \"hta_ensure_idx_s H ==\n  case hta_idx_s H of \n    None \\<Rightarrow> H\\<lparr> hta_idx_s := Some (build_rule_index_s (hta_\\<delta> H)) \\<rparr> |\n    Some _ \\<Rightarrow> H\n  \"\n\n  \\<comment> \\<open>Builds the sf-index if not present\\<close>\ndefinition \"hta_ensure_idx_sf H ==\n  case hta_idx_sf H of \n    None \\<Rightarrow> H\\<lparr> hta_idx_sf := Some (build_rule_index_sf (hta_\\<delta> H)) \\<rparr> |\n    Some _ \\<Rightarrow> H\n  \"\n\nlemma hta_ensure_idx_f_correct_\\<alpha>[simp]: \n  \"hta_\\<alpha> (hta_ensure_idx_f H) = hta_\\<alpha> H\" \n  by (simp add: hta_ensure_idx_f_def hta_\\<alpha>_def split: option.split)\nlemma hta_ensure_idx_s_correct_\\<alpha>[simp]: \n  \"hta_\\<alpha> (hta_ensure_idx_s H) = hta_\\<alpha> H\" \n  by (simp add: hta_ensure_idx_s_def hta_\\<alpha>_def split: option.split)\nlemma hta_ensure_idx_sf_correct_\\<alpha>[simp]: \n  \"hta_\\<alpha> (hta_ensure_idx_sf H) = hta_\\<alpha> H\" \n  by (simp add: hta_ensure_idx_sf_def hta_\\<alpha>_def split: option.split)\n\nlemma hta_ensure_idx_other[simp]:\n  \"hta_Qi (hta_ensure_idx_f H) = hta_Qi H\"  \n  \"hta_\\<delta> (hta_ensure_idx_f H) = hta_\\<delta> H\"\n  \n  \"hta_Qi (hta_ensure_idx_s H) = hta_Qi H\"  \n  \"hta_\\<delta> (hta_ensure_idx_s H) = hta_\\<delta> H\"\n  \n  \"hta_Qi (hta_ensure_idx_sf H) = hta_Qi H\" \n  \"hta_\\<delta> (hta_ensure_idx_sf H) = hta_\\<delta> H\"\n  by (auto \n    simp add: hta_ensure_idx_f_def hta_ensure_idx_s_def hta_ensure_idx_sf_def \n    split: option.split)\n\n  \\<comment> \\<open>Check whether the f-index is present\\<close>\ndefinition \"hta_has_idx_f H == hta_idx_f H \\<noteq> None\"\n  \\<comment> \\<open>Check whether the s-index is present\\<close>\ndefinition \"hta_has_idx_s H == hta_idx_s H \\<noteq> None\"\n  \\<comment> \\<open>Check whether the sf-index is present\\<close>\ndefinition \"hta_has_idx_sf H == hta_idx_sf H \\<noteq> None\"\n\nlemma hta_idx_f_pres\n  [simp, intro!]: \"hta_has_idx_f (hta_ensure_idx_f H)\" and\n  [simp, intro]: \"hta_has_idx_s H \\<Longrightarrow> hta_has_idx_s (hta_ensure_idx_f H)\" and\n  [simp, intro]: \"hta_has_idx_sf H \\<Longrightarrow> hta_has_idx_sf (hta_ensure_idx_f H)\"\n  by (simp_all \n    add: hta_has_idx_f_def hta_has_idx_s_def hta_has_idx_sf_def \n         hta_ensure_idx_f_def \n    split: option.split)\n\nlemma hta_idx_s_pres\n  [simp, intro!]: \"hta_has_idx_s (hta_ensure_idx_s H)\" and\n  [simp, intro]: \"hta_has_idx_f H \\<Longrightarrow> hta_has_idx_f (hta_ensure_idx_s H)\" and\n  [simp, intro]: \"hta_has_idx_sf H \\<Longrightarrow> hta_has_idx_sf (hta_ensure_idx_s H)\"\n  by (simp_all \n    add: hta_has_idx_f_def hta_has_idx_s_def hta_has_idx_sf_def \n         hta_ensure_idx_s_def \n    split: option.split)\n\nlemma hta_idx_sf_pres\n  [simp, intro!]: \"hta_has_idx_sf (hta_ensure_idx_sf H)\" and\n  [simp, intro]: \"hta_has_idx_f H \\<Longrightarrow> hta_has_idx_f (hta_ensure_idx_sf H)\" and\n  [simp, intro]: \"hta_has_idx_s H \\<Longrightarrow> hta_has_idx_s (hta_ensure_idx_sf H)\"\n  by (simp_all \n    add: hta_has_idx_f_def hta_has_idx_s_def hta_has_idx_sf_def \n         hta_ensure_idx_sf_def \n    split: option.split)\n\ntext \\<open>\n  The lookup functions are only defined if the required index is present. \n  This enforces generation of the index before applying lookup functions.\n\\<close>\n  \\<comment> \\<open>Lookup rules by function symbol\\<close>\ndefinition \"hta_lookup_f f H == hll_idx.lookup f (the (hta_idx_f H))\"\n  \\<comment> \\<open>Lookup rules by lhs-state\\<close>\ndefinition \"hta_lookup_s q H == hll_idx.lookup q (the (hta_idx_s H))\"\n  \\<comment> \\<open>Lookup rules by function symbol and lhs-state\\<close>\ndefinition \"hta_lookup_sf q f H == hll_idx.lookup (q,f) (the (hta_idx_sf H))\"\n\n\n  \\<comment> \\<open>This locale defines the invariants of a tree automaton\\<close>\nlocale hashedTa =\n  fixes H :: \"('Q::hashable,'L::hashable) hashedTa\"\n\n  \\<comment> \\<open>The involved sets satisfy their invariants\\<close>\n  assumes invar[simp, intro!]: \n    \"hs_invar (hta_Qi H)\"\n    \"ls_invar (hta_\\<delta> H)\"\n\n  \\<comment> \\<open>The indices are correct, if present\\<close>\n  assumes index_correct:\n    \"hta_idx_f H = Some idx_f \n      \\<Longrightarrow> hll_idx.is_index rhsl (ls_\\<alpha> (hta_\\<delta> H)) idx_f\"\n    \"hta_idx_s H = Some idx_s \n      \\<Longrightarrow> hll_idx.is_index lhs (ls_\\<alpha> (hta_\\<delta> H)) idx_s\"\n    \"hta_idx_sf H = Some idx_sf \n      \\<Longrightarrow> hll_idx.is_index (\\<lambda>r. (lhs r, rhsl r)) (ls_\\<alpha> (hta_\\<delta> H)) idx_sf\"\n\nbegin\n  \\<comment> \\<open>Inside this locale, some shorthand notations for the sets of \n      rules and initial states are used\\<close>\n  abbreviation \"\\<delta> == hta_\\<delta> H\"\n  abbreviation \"Qi == hta_Qi H\"\n\n  \\<comment> \\<open>The lookup-xxx operations are correct\\<close>\n  lemma hta_lookup_f_correct: \n    \"hta_has_idx_f H \\<Longrightarrow> ls_\\<alpha> (hta_lookup_f f H) = {r\\<in>ls_\\<alpha> \\<delta> . rhsl r = f}\"\n    \"hta_has_idx_f H \\<Longrightarrow> ls_invar (hta_lookup_f f H)\"\n    apply (cases \"hta_has_idx_f H\")\n    apply (unfold hta_has_idx_f_def hta_lookup_f_def)\n    apply (auto \n      simp add: hll_idx.lookup_correct[OF index_correct(1)] \n                index_def)\n    done\n\n  lemma hta_lookup_s_correct: \n    \"hta_has_idx_s H \\<Longrightarrow> ls_\\<alpha> (hta_lookup_s q H) = {r\\<in>ls_\\<alpha> \\<delta> . lhs r = q}\"\n    \"hta_has_idx_s H \\<Longrightarrow> ls_invar (hta_lookup_s q H)\"\n    apply (cases \"hta_has_idx_s H\")\n    apply (unfold hta_has_idx_s_def hta_lookup_s_def)\n    apply (auto \n      simp add: hll_idx.lookup_correct[OF index_correct(2)] \n                index_def)\n    done\n\n  lemma hta_lookup_sf_correct: \n    \"hta_has_idx_sf H \n      \\<Longrightarrow> ls_\\<alpha> (hta_lookup_sf q f H) = {r\\<in>ls_\\<alpha> \\<delta> . lhs r = q \\<and> rhsl r = f}\"\n    \"hta_has_idx_sf H \\<Longrightarrow> ls_invar (hta_lookup_sf q f H)\"\n    apply (cases \"hta_has_idx_sf H\")\n    apply (unfold hta_has_idx_sf_def hta_lookup_sf_def)\n    apply (auto \n      simp add: hll_idx.lookup_correct[OF index_correct(3)] \n                index_def)\n    done\n\n  \\<comment> \\<open>The ensure-index operations preserve the invariants\\<close>\n  lemma hta_ensure_idx_f_correct[simp, intro!]: \"hashedTa (hta_ensure_idx_f H)\"\n    apply (unfold_locales)\n    apply (auto)\n    apply (auto \n      simp add: hta_ensure_idx_f_def hta_ensure_idx_s_def hta_ensure_idx_sf_def \n               index_correct \n      split: option.split_asm)\n    done\n\n  lemma hta_ensure_idx_s_correct[simp, intro!]: \"hashedTa (hta_ensure_idx_s H)\"\n    apply (unfold_locales)\n    apply (auto)\n    apply (auto \n      simp add: hta_ensure_idx_f_def hta_ensure_idx_s_def hta_ensure_idx_sf_def \n                index_correct \n      split: option.split_asm)\n    done\n\n  lemma hta_ensure_idx_sf_correct[simp, intro!]: \"hashedTa (hta_ensure_idx_sf H)\"\n    apply (unfold_locales)\n    apply (auto)\n    apply (auto \n      simp add: hta_ensure_idx_f_def hta_ensure_idx_s_def hta_ensure_idx_sf_def \n                index_correct \n      split: option.split_asm)\n    done\n\n  text \\<open>The abstract tree automaton satisfies the invariants for an abstract\n          tree automaton\\<close>\n  lemma hta_\\<alpha>_is_ta[simp, intro!]: \"tree_automaton (hta_\\<alpha> H)\"\n    apply unfold_locales\n    apply (unfold hta_\\<alpha>_def)\n    apply auto\n    done\n\nend\n\n\\<comment> \\<open>Add some lemmas to simpset -- also outside the locale\\<close>\nlemmas [simp, intro] = \n  hashedTa.hta_ensure_idx_f_correct\n  hashedTa.hta_ensure_idx_s_correct\n  hashedTa.hta_ensure_idx_sf_correct\n\n  \\<comment> \\<open>Build a tree automaton from a set of initial states and a set of rules\\<close>\ndefinition \"init_hta Qi \\<delta> == \n  \\<lparr> hta_Qi= Qi, \n    hta_\\<delta> = \\<delta>, \n    hta_idx_f = None, \n    hta_idx_s = None, \n    hta_idx_sf = None \n  \\<rparr>\"\n\n  \\<comment> \\<open>Building a tree automaton from a valid tree automaton yields again a \n      valid tree automaton. This operation has the only effect of removing \n      the indices.\\<close>\nlemma (in hashedTa) init_hta_is_hta: \n  \"hashedTa (init_hta (hta_Qi H) (hta_\\<delta> H))\"\n  apply (unfold_locales)\n  apply (unfold init_hta_def)\n  apply (auto)\n  done\n\nsubsection \"Algorithm for the Word Problem\"\n\nlemma r_match_by_laz: \"r_match L l = list_all_zip (\\<lambda>Q q. q\\<in>Q) L l\"\n  by (unfold r_match_alt list_all_zip_alt)\n      auto\n\n\ntext \"Executable function that computes the set of accepting states for \n    a given tree\"\nfun faccs' where\n  \"faccs' H (NODE f ts) = (\n    let Qs = List.map (faccs' H) ts in\n      ll_set_xy.g_image_filter (\\<lambda>r. case r of (q \\<rightarrow> f' qs) \\<Rightarrow> \n           if list_all_zip (\\<lambda>Q q. ls_memb q Q) Qs qs then Some (lhs r) else None\n                          ) \n                      (hta_lookup_f f H)\n  )\"\n\n  \\<comment> \\<open>Executable algorithm to decide the word-problem. The first version \n      depends on the f-index to be present, the second version computes the \n      index if not present.\\<close>\ndefinition \"hta_mem' t H == \\<not>lh_set_xx.g_disjoint (faccs' H t) (hta_Qi H)\"\ndefinition \"hta_mem t H == hta_mem' t (hta_ensure_idx_f H)\"\n\ncontext hashedTa\nbegin\n\n  lemma faccs'_invar:\n    assumes HI[simp, intro!]: \"hta_has_idx_f H\"\n    shows \"ls_invar (faccs' H t)\" (is ?T1) \n          \"list_all ls_invar (List.map (faccs' H) ts)\" (is ?T2)\n  proof -\n    have \"?T1 \\<and> ?T2\"\n      apply (induct rule: compat_tree_tree_list.induct)\n      apply (auto simp add: ll_set_xy.image_filter_correct hta_lookup_f_correct)\n      done\n    thus ?T1 ?T2 by auto\n  qed\n\n  declare faccs'_invar(1)[simp, intro]\n\n  lemma faccs'_correct:\n    assumes HI[simp, intro!]: \"hta_has_idx_f H\"\n    shows \n      \"ls_\\<alpha> (faccs' H t) = faccs (ls_\\<alpha> (hta_\\<delta> H)) t\" (is ?T1)\n      \"List.map ls_\\<alpha> (List.map (faccs' H) ts) \n       = List.map (faccs (ls_\\<alpha> (hta_\\<delta> H))) ts\" (is ?T2)\n  proof -\n    have \"?T1 \\<and> ?T2\"\n    proof (induct rule: compat_tree_tree_list.induct)\n      case (NODE f ts)\n      let ?\\<delta> = \"(ls_\\<alpha> (hta_\\<delta> H))\"\n      have \"faccs ?\\<delta> (NODE f ts) = (\n        let Qs = List.map (faccs ?\\<delta>) ts in\n          {q. \\<exists>r\\<in>?\\<delta>. r_matchc q f Qs r })\"\n        by (rule faccs.simps)\n      also note NODE.hyps[symmetric]\n      finally have \n        1: \"faccs ?\\<delta> (NODE f ts) \n            = ( let Qs = List.map ls_\\<alpha> (List.map (faccs' H) ts) in\n                 {q. \\<exists>r\\<in>?\\<delta>. r_matchc q f Qs r })\" .\n      {\n        fix Qsc:: \"'Q ls list\"\n        assume QI: \"list_all ls_invar Qsc\"\n        let ?Qs = \"List.map ls_\\<alpha> Qsc\"\n        have \"{ q. \\<exists>r\\<in>?\\<delta>. r_matchc q f ?Qs r } \n              = { q. \\<exists>qs. (q \\<rightarrow> f qs)\\<in>?\\<delta> \\<and> r_match ?Qs qs }\"\n          apply (safe)\n          apply (case_tac r)\n          apply auto [1]\n          apply force\n          done\n        also have \"\\<dots> = lhs ` { r\\<in>{r\\<in>?\\<delta>. rhsl r = f}. \n                                 case r of (q \\<rightarrow> f' qs) \\<Rightarrow> r_match ?Qs qs}\"\n          apply auto\n          apply force\n          apply (case_tac xa)\n          apply auto\n          done\n        finally have \n          1: \"{ q. \\<exists>r\\<in>?\\<delta>. r_matchc q f ?Qs r } \n              = lhs ` { r\\<in>{r\\<in>?\\<delta>. rhsl r = f}. \n                         case r of (q \\<rightarrow> f' qs) \\<Rightarrow> r_match ?Qs qs}\" \n          by auto\n        from QI have \n          [simp]: \"!!qs. list_all_zip (\\<lambda>Q q. q\\<in>ls_\\<alpha> Q) Qsc qs \n                         \\<longleftrightarrow> list_all_zip (\\<lambda>Q q. ls_memb q Q) Qsc qs\"\n          apply (induct Qsc)\n          apply (case_tac qs)\n          apply auto [2]\n          apply (case_tac qs)\n          apply (auto simp add: ls.correct) [2]\n          done\n        have 2: \"!!qs. r_match ?Qs qs = list_all_zip (\\<lambda>a b. ls_memb b a) Qsc qs\"\n          apply (unfold r_match_by_laz)\n          apply (simp add: list_all_zip_map1)\n          done\n        from 1 have \n          \"{ q. \\<exists>r\\<in>?\\<delta>. r_matchc q f ?Qs r } \n           = lhs ` { r\\<in>{r\\<in>?\\<delta>. rhsl r = f}. \n                     case r of (q \\<rightarrow> f' qs) \\<Rightarrow> \n                       list_all_zip (\\<lambda>a b. ls_memb b a) Qsc qs}\" \n          by (simp only: 2)\n        also have \n          \"\\<dots> = lhs ` { r\\<in>ls_\\<alpha> (hta_lookup_f f H). \n                         case r of (q \\<rightarrow> f' qs) \\<Rightarrow> \n                           list_all_zip (\\<lambda>a b. ls_memb b a) Qsc qs}\" \n          by (simp add: hta_lookup_f_correct)\n        also have \n          \"\\<dots> = ls_\\<alpha> ( ll_set_xy.g_image_filter \n                         ( \\<lambda>r. case r of (q \\<rightarrow> f' qs) \\<Rightarrow> \n                             (if (list_all_zip (\\<lambda>Q q. ls_memb q Q) Qsc qs) then Some (lhs r) else None))\n                         (hta_lookup_f f H)\n                     )\"\n          apply (simp add: ll_set_xy.image_filter_correct hta_lookup_f_correct)\n          apply (auto split: ta_rule.split)\n          apply (rule_tac x=xa in exI)\n          apply auto\n          apply (case_tac a)\n          apply (simp add: image_iff)\n          apply (rule_tac x=a in exI)\n          apply auto\n          done\n        finally have \n          \"{ q. \\<exists>r\\<in>?\\<delta>. r_matchc q f ?Qs r } \n           = ls_\\<alpha> ( ll_set_xy.g_image_filter \n                      (\\<lambda>r. case r of (q \\<rightarrow> f' qs) \\<Rightarrow> \n                        (if (list_all_zip (\\<lambda>Q q. ls_memb q Q) Qsc qs) then Some (lhs r) else None))\n                      (hta_lookup_f f H))\" .\n      } note 2=this\n      \n      from \n        1 \n        2[ where Qsc2 = \"(List.map (faccs' H) ts)\", \n           simplified faccs'_invar[OF HI]] \n      show ?case by simp\n    qed simp_all\n    thus ?T1 ?T2 by auto\n  qed\n\n    \\<comment> \\<open>Correctness of the algorithms for the word problem\\<close>\n  lemma hta_mem'_correct: \n    \"hta_has_idx_f H \\<Longrightarrow> hta_mem' t H \\<longleftrightarrow> t\\<in>ta_lang (hta_\\<alpha> H)\"\n    apply (unfold ta_lang_def hta_\\<alpha>_def hta_mem'_def)\n    apply (auto simp add: lh_set_xx.disjoint_correct faccs'_correct faccs_alt)\n    done\n\n  theorem hta_mem_correct: \"hta_mem t H \\<longleftrightarrow> t\\<in>ta_lang (hta_\\<alpha> H)\"\n    using hashedTa.hta_mem'_correct[OF hta_ensure_idx_f_correct, simplified]\n    apply (unfold hta_mem_def)\n    apply simp\n    done\n\nend\n\n\nsubsection \"Product Automaton and Intersection\"\n\nsubsubsection \"Brute Force Product Automaton\"\ntext \\<open>\n  In this section, an algorithm that computes the product \n  automaton without reduction is implemented. While the runtime is always\n  quadratic, this algorithm is very simple and the constant factors are \n  smaller than that of the version with integrated reduction.\n  Moreover, lazy languages like Haskell seem to profit from this algorithm.\n\\<close>\n\ndefinition \\<delta>_prod_h \n  :: \"('q1::hashable,'l::hashable) ta_rule ls \n      \\<Rightarrow> ('q2::hashable,'l) ta_rule ls \\<Rightarrow> ('q1\\<times>'q2,'l) ta_rule ls\" \n  where \"\\<delta>_prod_h \\<delta>1 \\<delta>2 == \n    lll_iflt_cp.inj_image_filter_cp (\\<lambda>(r1,r2). r_prod r1 r2) \n                (\\<lambda>(r1,r2). rhsl r1 = rhsl r2 \n                         \\<and> length (rhsq r1) = length (rhsq r2)) \n                \\<delta>1 \\<delta>2\"\n\nlemma r_prod_inj: \n  \"\\<lbrakk> rhsl r1 = rhsl r2; length (rhsq r1) = length (rhsq r2); \n     rhsl r1' = rhsl r2'; length (rhsq r1') = length (rhsq r2'); \n     r_prod r1 r2 = r_prod r1' r2' \\<rbrakk> \\<Longrightarrow> r1=r1' \\<and> r2=r2'\"\n  apply (cases r1, cases r2, cases r1', cases r2')\n  apply (auto dest: zip_inj)\n  done\n\nlemma \\<delta>_prod_h_correct:\n  assumes INV[simp]: \"ls_invar \\<delta>1\" \"ls_invar \\<delta>2\"\n  shows \n    \"ls_\\<alpha> (\\<delta>_prod_h \\<delta>1 \\<delta>2) = \\<delta>_prod (ls_\\<alpha> \\<delta>1) (ls_\\<alpha> \\<delta>2)\"\n    \"ls_invar (\\<delta>_prod_h \\<delta>1 \\<delta>2)\"\n  apply (unfold \\<delta>_prod_def \\<delta>_prod_h_def)\n  apply (subst lll_iflt_cp.inj_image_filter_cp_correct)\n  apply simp_all [2]\n  using r_prod_inj\n  apply (auto intro!: inj_onI) []\n  apply auto []\n  apply (case_tac xa, case_tac y, simp, blast)\n  apply force\n  apply simp\n  done\n\ndefinition \"hta_prodWR H1 H2 == \n  init_hta (hhh_cart.cart (hta_Qi H1) (hta_Qi H2)) (\\<delta>_prod_h (hta_\\<delta> H1) (hta_\\<delta> H2))\"\n\nlemma hta_prodWR_correct_aux: \n  assumes A: \"hashedTa H1\" \"hashedTa H2\"\n  shows \n    \"hta_\\<alpha> (hta_prodWR H1 H2) = ta_prod (hta_\\<alpha> H1) (hta_\\<alpha> H2)\" (is ?T1)\n    \"hashedTa (hta_prodWR H1 H2)\" (is ?T2)\nproof -\n  interpret a1: hashedTa H1 + a2: hashedTa H2 using A .\n  show ?T1 ?T2\n    apply (unfold hta_prodWR_def init_hta_def hta_\\<alpha>_def ta_prod_def)\n    apply (simp add: hhh_cart.cart_correct \\<delta>_prod_h_correct)\n    apply (unfold_locales)\n    apply (simp_all add: hhh_cart.cart_correct \\<delta>_prod_h_correct)\n    done\nqed\n  \nlemma hta_prodWR_correct:\n  assumes TA: \"hashedTa H1\" \"hashedTa H2\"\n  shows \n    \"ta_lang (hta_\\<alpha> (hta_prodWR H1 H2)) \n     = ta_lang (hta_\\<alpha> H1) \\<inter> ta_lang (hta_\\<alpha> H2)\"\n    \"hashedTa (hta_prodWR H1 H2)\"\n  by (simp_all add: hta_prodWR_correct_aux[OF TA] ta_prod_correct_aux1)\n\nsubsubsection \"Product Automaton with Forward-Reduction\"\ntext \\<open>\n  A more elaborated algorithm combines forward-reduction and the product \n  construction, i.e. product rules are only created ,,by need''.\n\\<close>\n\n  \\<comment> \\<open>State of the product-automaton DFS-algorithm\\<close>\ntype_synonym ('q1,'q2,'l) pa_state \n  = \"('q1\\<times>'q2) hs \\<times> ('q1\\<times>'q2) list \\<times> ('q1\\<times>'q2,'l) ta_rule ls\"\n\n  \\<comment> \\<open>Abstraction mapping to algorithm specified in \n  Section~\\ref{sec:absalgo}.\\<close>\ndefinition pa_\\<alpha> \n  :: \"('q1::hashable,'q2::hashable,'l::hashable) pa_state \n      \\<Rightarrow> ('q1,'q2,'l) frp_state\"\n  where \"pa_\\<alpha> S == let (Q,W,\\<delta>d)=S in (hs_\\<alpha> Q,W,ls_\\<alpha> \\<delta>d)\"\n\ndefinition pa_cond \n  :: \"('q1::hashable,'q2::hashable,'l::hashable) pa_state \\<Rightarrow> bool\" \n  where \"pa_cond S == let (Q,W,\\<delta>d) = S in W\\<noteq>[]\"\n\n  \\<comment> \\<open>Adds all successor states to the set of discovered states and to the \n  worklist\\<close>\nfun pa_upd_rule \n  :: \"('q1\\<times>'q2) hs \\<Rightarrow> ('q1\\<times>'q2) list \n      \\<Rightarrow> (('q1::hashable)\\<times>('q2::hashable)) list \n      \\<Rightarrow> (('q1\\<times>'q2) hs \\<times> ('q1\\<times>'q2) list)\" \n  where\n  \"pa_upd_rule Q W [] = (Q,W)\" |\n  \"pa_upd_rule Q W (qp#qs) = (\n    if \\<not> hs_memb qp Q then\n      pa_upd_rule (hs_ins qp Q) (qp#W) qs\n    else pa_upd_rule Q W qs\n  )\"\n\n\ndefinition pa_step \n  :: \"('q1::hashable,'l::hashable) hashedTa \n      \\<Rightarrow> ('q2::hashable,'l) hashedTa \n      \\<Rightarrow> ('q1,'q2,'l) pa_state \\<Rightarrow> ('q1,'q2,'l) pa_state\"\n  where \"pa_step H1 H2 S == let \n    (Q,W,\\<delta>d)=S;\n    (q1,q2)=hd W\n  in  \n    ls_iteratei (hta_lookup_s q1 H1) (\\<lambda>_. True) (\\<lambda>r1 res. \n      ls_iteratei (hta_lookup_sf q2 (rhsl r1) H2) (\\<lambda>_. True) (\\<lambda>r2 res.\n        if (length (rhsq r1) = length (rhsq r2)) then\n          let \n            rp=r_prod r1 r2;\n            (Q,W,\\<delta>d) = res;\n            (Q',W') = pa_upd_rule Q W (rhsq rp)\n          in\n            (Q',W',ls_ins_dj rp \\<delta>d)\n        else\n          res\n      ) res\n    ) (Q,tl W,\\<delta>d)\n  \"\n\ndefinition pa_initial \n  :: \"('q1::hashable,'l::hashable) hashedTa \n      \\<Rightarrow> ('q2::hashable,'l) hashedTa \n      \\<Rightarrow> ('q1,'q2,'l) pa_state\"\nwhere \"pa_initial H1 H2 == \n  let Qip = hhh_cart.cart (hta_Qi H1) (hta_Qi H2) in (\n    Qip,\n    hs_to_list Qip,\n    ls_empty ()\n  )\"\n\ndefinition pa_invar_add:: \n  \"('q1::hashable,'q2::hashable,'l::hashable) pa_state set\" \n  where \"pa_invar_add == { (Q,W,\\<delta>d). hs_invar Q \\<and> ls_invar \\<delta>d }\"\n\ndefinition \"pa_invar H1 H2 == \n  pa_invar_add \\<inter> {s. (pa_\\<alpha> s) \\<in> frp_invar (hta_\\<alpha> H1) (hta_\\<alpha> H2)}\"\n\ndefinition \"pa_det_algo H1 H2 \n  == \\<lparr> dwa_cond=pa_cond, \n       dwa_step = pa_step H1 H2, \n       dwa_initial = pa_initial H1 H2, \n       dwa_invar = pa_invar H1 H2 \\<rparr>\"\n\nlemma pa_upd_rule_correct:\n  assumes INV[simp, intro!]: \"hs_invar Q\"\n  assumes FMT: \"pa_upd_rule Q W qs = (Q',W')\"\n  shows\n    \"hs_invar Q'\" (is ?T1)\n    \"hs_\\<alpha> Q' = hs_\\<alpha> Q \\<union> set qs\" (is ?T2)\n    \"\\<exists>Wn. distinct Wn \\<and> set Wn = set qs - hs_\\<alpha> Q \\<and> W'=Wn@W\" (is ?T3)\nproof -\n  from INV FMT have \"?T1 \\<and> ?T2 \\<and> ?T3\"\n  proof (induct qs arbitrary: Q W Q' W')\n    case Nil thus ?case by simp\n  next\n    case (Cons q qs Q W Q' W')\n    show ?case \n    proof (cases \"q\\<in>hs_\\<alpha> Q\")\n      case True \n      obtain Qh Wh where RF: \"pa_upd_rule Q W qs = (Qh,Wh)\" by force\n      with True Cons.prems have [simp]: \"Q'=Qh\" \"W'=Wh\"\n        by (auto simp add: hs.correct)\n      from Cons.hyps[OF Cons.prems(1) RF] have\n        \"hs_invar Qh\" \n        \"hs_\\<alpha> Qh = hs_\\<alpha> Q \\<union> set qs\" \n        \"(\\<exists>Wn. distinct Wn \\<and> set Wn = set qs - hs_\\<alpha> Q \\<and> Wh = Wn @ W)\"\n        by auto\n      thus ?thesis using True by auto\n    next\n      case False\n      with Cons.prems have RF: \"pa_upd_rule (hs_ins q Q) (q#W) qs = (Q',W')\"\n        by (auto simp add: hs.correct)\n\n      from Cons.hyps[OF _ RF] Cons.prems(1) have\n        \"hs_invar Q'\" \n        \"hs_\\<alpha> Q' = insert q (hs_\\<alpha> Q) \\<union> set (qs)\"\n        \"\\<exists>Wn. distinct Wn \n              \\<and> set Wn = set qs - insert q (hs_\\<alpha> Q) \n              \\<and> W' = Wn @ q # W\"\n        by (auto simp add: hs.correct)\n      thus ?thesis using False by auto\n    qed\n  qed\n  thus ?T1 ?T2 ?T3 by auto\nqed\n\n\nlemma pa_step_correct:\n  assumes TA: \"hashedTa H1\" \"hashedTa H2\"\n  assumes idx[simp]: \"hta_has_idx_s H1\" \"hta_has_idx_sf H2\"\n  assumes INV: \"(Q,W,\\<delta>d)\\<in>pa_invar H1 H2\"\n  assumes COND: \"pa_cond (Q,W,\\<delta>d)\"\n  shows \n    \"(pa_step H1 H2 (Q,W,\\<delta>d))\\<in>pa_invar_add\" (is ?T1)\n    \"(pa_\\<alpha> (Q,W,\\<delta>d), pa_\\<alpha> (pa_step H1 H2 (Q,W,\\<delta>d))) \n     \\<in> frp_step (ls_\\<alpha> (hta_\\<delta> H1)) (ls_\\<alpha> (hta_\\<delta> H2))\" (is ?T2)\nproof -\n  interpret h1: hashedTa H1 by fact\n  interpret h2: hashedTa H2 by fact\n\n  from COND obtain q1 q2 Wtl where \n    [simp]: \"W=(q1,q2)#Wtl\" \n    by (cases W) (auto simp add: pa_cond_def)\n\n  from INV have [simp]: \"hs_invar Q\" \"ls_invar \\<delta>d\" \n    by (auto simp add: pa_invar_add_def pa_invar_def)\n\n  define inv where \"inv = (\\<lambda>\\<delta>p (Q', W', \\<delta>d'). \n    hs_invar Q' \n    \\<and> ls_invar \\<delta>d' \n    \\<and> (\\<exists>Wn. distinct Wn \n            \\<and> set Wn = (f_succ \\<delta>p `` {(q1,q2)}) - hs_\\<alpha> Q \n            \\<and> W'=Wn@Wtl \n            \\<and> hs_\\<alpha> Q'=hs_\\<alpha> Q \\<union> (f_succ \\<delta>p `` {(q1,q2)}))\n    \\<and> (ls_\\<alpha> \\<delta>d' = ls_\\<alpha> \\<delta>d \\<union> {r\\<in>\\<delta>p. lhs r = (q1,q2) }))\"\n\n  have G: \"inv (\\<delta>_prod (ls_\\<alpha> (hta_\\<delta> H1)) (ls_\\<alpha> (hta_\\<delta> H2))) \n               (pa_step H1 H2 (Q,W,\\<delta>d))\"\n    apply (unfold pa_step_def)\n    apply simp\n    apply (rule_tac \n      I=\"\\<lambda>it1 res. inv (\\<delta>_prod (ls_\\<alpha> (hta_\\<delta> H1) - it1) (ls_\\<alpha> (hta_\\<delta> H2))) res\"\n      in ls.iterate_rule_P)\n    \\<comment> \\<open>Invar\\<close>\n    apply (simp add: h1.hta_lookup_s_correct)\n    \\<comment> \\<open>Initial\\<close>\n    apply (fastforce simp add: inv_def \\<delta>_prod_def h1.hta_lookup_s_correct \n                              f_succ_alt)\n    \\<comment> \\<open>Step\\<close>\n    apply (rule_tac \n      I=\"\\<lambda>it2 res. inv ( \\<delta>_prod (ls_\\<alpha> (hta_\\<delta> H1) - it) (ls_\\<alpha> (hta_\\<delta> H2)) \n                         \\<union> \\<delta>_prod {x} (ls_\\<alpha> (hta_\\<delta> H2) - it2)) \n                        res\" \n      in ls.iterate_rule_P)\n      \\<comment> \\<open>Invar\\<close>\n      apply (simp add: h2.hta_lookup_sf_correct)\n      \\<comment> \\<open>Init\\<close>\n      apply (case_tac \\<sigma>)\n      apply (simp add: inv_def h1.hta_lookup_s_correct h2.hta_lookup_sf_correct)\n      apply (force simp add: f_succ_alt elim: \\<delta>_prodE intro: \\<delta>_prodI) [1]\n      \\<comment> \\<open>Step\\<close>\n      defer \\<comment> \\<open>Requires considerably more work: Deferred to Isar proof below\\<close>\n      \\<comment> \\<open>Final\\<close>\n      apply (simp add: h1.hta_lookup_s_correct h2.hta_lookup_sf_correct)\n      apply (auto) [1]\n      apply (subgoal_tac \n        \"ls_\\<alpha> (hta_\\<delta> H1) - (it - {x}) = (ls_\\<alpha> (hta_\\<delta> H1) - it) \\<union> {x}\")\n      apply (simp add: \\<delta>_prod_insert)\n      apply (subst Un_commute)\n      apply simp\n      apply blast\n    \\<comment> \\<open>Final\\<close>\n    apply force\n  proof goal_cases\n    case prems: (1 r1 it1 resxh r2 it2 resh)\n    \\<comment> \\<open>Resolve lookup-operations\\<close>\n    hence G': \n      \"it1 \\<subseteq> {r \\<in> ls_\\<alpha> (hta_\\<delta> H1). lhs r = q1}\" \n      \"it2 \\<subseteq> {r \\<in> ls_\\<alpha> (hta_\\<delta> H2). lhs r = q2 \\<and> rhsl r = rhsl r1}\"\n      by (simp_all add: h1.hta_lookup_s_correct h2.hta_lookup_sf_correct)\n\n    \\<comment> \\<open>Basic reasoning setup\\<close>\n    from prems(1,4) G' have \n      [simp]: \"ls_\\<alpha> (hta_\\<delta> H2) - (it2 - {r2}) = (ls_\\<alpha> (hta_\\<delta> H2) - it2) \\<union> {r2}\"\n      by auto\n    obtain Qh Wh \\<delta>dh Q' W' \\<delta>d' where [simp]: \"resh=(Qh,Wh,\\<delta>dh)\" \n      by (cases resh) fastforce\n    from prems(6) have INVAH[simp]: \"hs_invar Qh\" \"ls_invar \\<delta>dh\" \n      by (auto simp add: inv_def)\n\n    \\<comment> \\<open>The involved rules have the same label, and their lhs is determined\\<close>\n    from prems(1,4) G' obtain l qs1 qs2 where \n      RULE_FMT: \"r1 = (q1 \\<rightarrow> l qs1)\" \"r2=(q2 \\<rightarrow> l qs2)\"\n      apply (cases r1, cases r2)\n      apply force\n      done\n\n    {\n      \\<comment> \\<open>If the rhs have different lengths, the algorithm ignores the rule:\\<close>\n      assume LEN: \"length (rhsq r1) \\<noteq> length (rhsq r2)\"\n      \n      hence [simp]: \"\\<delta>_prod_sng2 {r1} r2 = {}\"\n        by (auto simp add: \\<delta>_prod_sng2_def split: ta_rule.split)\n\n      have ?case using prems \n        by (simp add: LEN \\<delta>_prod_insert)\n    } moreover {\n      \\<comment> \\<open>If the rhs have the same length, the rule is inserted\\<close>\n      assume LEN: \"length (rhsq r1) = length (rhsq r2)\"\n      hence [simp]: \"length qs1 = length qs2\" by (simp add: RULE_FMT)\n\n      hence [simp]: \"\\<delta>_prod_sng2 {r1} r2 = {(q1,q2) \\<rightarrow> l (zip qs1 qs2)}\"\n        using prems(1,4) G'\n        by (auto simp add: \\<delta>_prod_sng2_def RULE_FMT)\n\n      \\<comment> \\<open>Obtain invariant of previous state\\<close>\n      from prems(6)[unfolded inv_def, simplified] obtain Wn where INVH:\n        \"distinct Wn\"\n        \"set Wn = f_succ (\\<delta>_prod (ls_\\<alpha> (hta_\\<delta> H1) - it1) (ls_\\<alpha> (hta_\\<delta> H2)) \n                          \\<union> \\<delta>_prod {r1} (ls_\\<alpha> (hta_\\<delta> H2) - it2)) \n                  `` {(q1, q2)} - hs_\\<alpha> Q\"\n        \"Wh = Wn @ Wtl\" \n        \"hs_\\<alpha> Qh = hs_\\<alpha> Q \n                   \\<union> f_succ (\\<delta>_prod (ls_\\<alpha> (hta_\\<delta> H1) - it1) (ls_\\<alpha> (hta_\\<delta> H2))\n                              \\<union> \\<delta>_prod {r1} (ls_\\<alpha> (hta_\\<delta> H2) - it2)) \n                      `` {(q1, q2)}\" \n        \"ls_\\<alpha> \\<delta>dh = ls_\\<alpha> \\<delta>d \n          \\<union> {r. ( r \\<in> \\<delta>_prod (ls_\\<alpha> (hta_\\<delta> H1) - it1) (ls_\\<alpha> (hta_\\<delta> H2)) \n                  \\<or> r \\<in> \\<delta>_prod {r1} (ls_\\<alpha> (hta_\\<delta> H2) - it2)\n                 ) \\<and> lhs r = (q1, q2)\n             }\"\n        by blast\n\n      \\<comment> \\<open>Required to justify disjoint insert\\<close>\n      have RPD: \"r_prod r1 r2 \\<notin> ls_\\<alpha> \\<delta>dh\" \n      proof -\n        from INV[unfolded pa_invar_def frp_invar_def frp_invar_add_def]\n        have LSDD: \n          \"ls_\\<alpha> \\<delta>d = {r \\<in> \\<delta>_prod (ls_\\<alpha> (hta_\\<delta> H1)) (ls_\\<alpha> (hta_\\<delta> H2)). \n                        lhs r \\<in> hs_\\<alpha> Q - set W}\"\n          by (auto simp add: pa_\\<alpha>_def hta_\\<alpha>_def)\n        have \"r_prod r1 r2 \\<notin> ls_\\<alpha> \\<delta>d\"\n        proof\n          assume \"r_prod r1 r2 \\<in> ls_\\<alpha> \\<delta>d\"\n          with LSDD have \"lhs (r_prod r1 r2) \\<notin> set W\" by auto\n          moreover from prems(1,4) G' have \"lhs (r_prod r1 r2) = (q1,q2)\" \n            by (cases r1, cases r2) auto\n          ultimately show False by simp\n        qed\n        moreover from prems(6) have \"ls_\\<alpha> \\<delta>dh = \n          ls_\\<alpha> \\<delta>d \\<union> \n          {r. ( r \\<in> \\<delta>_prod (ls_\\<alpha> (hta_\\<delta> H1) - it1) (ls_\\<alpha> (hta_\\<delta> H2)) \n                \\<or> r \\<in> \\<delta>_prod {r1} (ls_\\<alpha> (hta_\\<delta> H2) - it2)\n              ) \\<and> lhs r = (q1, q2)}\" (is \"_= _ \\<union> ?s\")\n          by (simp add: inv_def)\n        moreover have \"r_prod r1 r2 \\<notin> ?s\" using prems(1,4) G'(2) LEN\n          apply (cases r1, cases r2)\n          apply (auto simp add: \\<delta>_prod_def)\n          done\n        ultimately show ?thesis by blast\n      qed\n\n      \\<comment> \\<open>Correctness of result of @{text pa_upd_rule}\\<close>\n      obtain Q' W' where \n        PAUF: \"(pa_upd_rule Qh Wh (rhsq (r_prod r1 r2))) = (Q',W')\" \n        by force\n      from pa_upd_rule_correct[OF INVAH(1) PAUF] obtain Wnn where UC:\n        \"hs_invar Q'\"\n        \"hs_\\<alpha> Q' = hs_\\<alpha> Qh \\<union> set (rhsq (r_prod r1 r2))\"\n        \"distinct Wnn\" \n        \"set Wnn = set (rhsq (r_prod r1 r2)) - hs_\\<alpha> Qh\" \n        \"W' = Wnn @ Wh\"\n        by blast\n\n      \\<comment> \\<open>Put it all together\\<close>\n      have ?case\n        apply (simp add: LEN Let_def ls.ins_dj_correct[OF INVAH(2) RPD] \n                         PAUF inv_def UC(1))\n        apply (intro conjI)\n        apply (rule_tac x=\"Wnn@Wn\" in exI)\n        apply (auto simp add: f_succ_alt \\<delta>_prod_insert RULE_FMT UC INVH \n                              \\<delta>_prod_sng2_def \\<delta>_prod_sng1_def)\n        done\n    } ultimately show ?case by blast\n  qed\n  from G show ?T1\n    by (cases \"pa_step H1 H2 (Q,W,\\<delta>d)\")\n       (simp add: pa_invar_add_def inv_def)\n  from G show ?T2\n    by (cases \"pa_step H1 H2 (Q,W,\\<delta>d)\")\n       (auto simp add: inv_def pa_\\<alpha>_def Let_def intro: frp_step.intros)\n\nqed\n    \n  \n\n  \\<comment> \\<open>The product-automaton algorithm is a precise implementation of its\n      specification\\<close>\nlemma pa_pref_frp: \n  assumes TA: \"hashedTa H1\" \"hashedTa H2\"\n  assumes idx[simp]: \"hta_has_idx_s H1\" \"hta_has_idx_sf H2\"\n\n  shows \"wa_precise_refine (det_wa_wa (pa_det_algo H1 H2)) \n                           (frp_algo (hta_\\<alpha> H1) (hta_\\<alpha> H2)) \n                           pa_\\<alpha>\"\nproof -\n  interpret h1: hashedTa H1 by fact\n  interpret h2: hashedTa H2 by fact\n  \n  show ?thesis\n    apply (unfold_locales)\n    apply (auto simp add: det_wa_wa_def pa_det_algo_def pa_\\<alpha>_def \n                          pa_cond_def frp_algo_def frp_cond_def) [1]\n    apply (auto simp add: det_wa_wa_def pa_det_algo_def pa_cond_def\n                          hta_\\<alpha>_def frp_algo_def frp_cond_def \n                intro!: pa_step_correct(2)[OF TA]) [1]\n    apply (auto simp add: det_wa_wa_def pa_det_algo_def pa_\\<alpha>_def \n                          hta_\\<alpha>_def pa_cond_def frp_algo_def frp_cond_def\n                          pa_invar_def pa_step_def pa_initial_def \n                          hs.correct ls.correct Let_def hhh_cart.cart_correct \n                intro: frp_initial.intros\n    ) [3]\n    done\nqed\n\n\n  \\<comment> \\<open>The product automaton algorithm is a correct while-algorithm\\<close>\nlemma pa_while_algo: \n  assumes TA: \"hashedTa H1\" \"hashedTa H2\"\n  assumes idx[simp]: \"hta_has_idx_s H1\" \"hta_has_idx_sf H2\"\n\n  shows \"while_algo (det_wa_wa (pa_det_algo H1 H2))\"\nproof -\n  interpret h1: hashedTa H1 by fact\n  interpret h2: hashedTa H2 by fact\n\n  interpret ref: wa_precise_refine \"(det_wa_wa (pa_det_algo H1 H2))\" \n                                   \"(frp_algo (hta_\\<alpha> H1) (hta_\\<alpha> H2))\" \n                                   \"pa_\\<alpha>\" \n    using pa_pref_frp[OF TA idx] .\n  show ?thesis\n    apply (rule ref.wa_intro)\n    apply (simp add: frp_while_algo)\n    apply (simp add: det_wa_wa_def pa_det_algo_def pa_invar_def frp_algo_def)\n\n    apply (auto simp add: det_wa_wa_def pa_det_algo_def) [1]\n    apply (rule pa_step_correct(1)[OF TA idx])\n    apply (auto simp add: pa_invar_def frp_algo_def) [2]\n    \n    apply (simp add: det_wa_wa_def pa_det_algo_def pa_initial_def \n                     pa_invar_add_def Let_def hhh_cart.cart_correct ls.correct)\n    done\nqed\n    \n\\<comment> \\<open>By definition, the product automaton algorithm is deterministic\\<close>\nlemmas pa_det_while_algo = det_while_algo_intro[OF pa_while_algo]\n\n\\<comment> \\<open>Transferred correctness lemma\\<close>\nlemmas pa_inv_final = \n  wa_precise_refine.transfer_correctness[OF pa_pref_frp frp_inv_final]\n\n\n\\<comment> \\<open>The next two definitions specify the product-automata algorithm. The first\n    version requires the s-index of the first and the sf-index of the second\n    automaton to be present, while the second version computes the required \n    indices, if necessary\\<close>\ndefinition \"hta_prod' H1 H2 ==\n  let (Q,W,\\<delta>d) = while pa_cond (pa_step H1 H2) (pa_initial H1 H2) in\n    init_hta (hhh_cart.cart (hta_Qi H1) (hta_Qi H2)) \\<delta>d\n  \"\n\ndefinition \"hta_prod H1 H2 == \n  hta_prod' (hta_ensure_idx_s H1) (hta_ensure_idx_sf H2)\"\n\n\nlemma hta_prod'_correct_aux:\n  assumes TA: \"hashedTa H1\" \"hashedTa H2\"\n  assumes idx: \"hta_has_idx_s H1\" \"hta_has_idx_sf H2\"\n  shows \"hta_\\<alpha> (hta_prod' H1 H2) \n         = ta_fwd_reduce (ta_prod (hta_\\<alpha> H1) (hta_\\<alpha> H2))\" (is ?T1)\n        \"hashedTa (hta_prod' H1 H2)\" (is ?T2)\nproof -\n  interpret h1: hashedTa H1 by fact\n  interpret h2: hashedTa H2 by fact\n\n  interpret dwa: det_while_algo \"pa_det_algo H1 H2\" \n    using pa_det_while_algo[OF TA idx] .\n\n  have LC: \"while pa_cond (pa_step H1 H2) (pa_initial H1 H2) = dwa.loop\"\n    by (unfold dwa.loop_def)\n       (simp add: pa_det_algo_def)\n\n  from dwa.while_proof'[OF pa_inv_final[OF TA idx]]\n  show ?T1\n    apply (unfold dwa.loop_def)\n    apply (simp add: hta_prod'_def init_hta_def hta_\\<alpha>_def pa_det_algo_def)\n    apply (cases \"(while pa_cond (pa_step H1 H2) (pa_initial H1 H2))\")\n    apply (simp add: pa_\\<alpha>_def hhh_cart.cart_correct hta_\\<alpha>_def)\n    done\n\n  show ?T2\n    apply (simp add: hta_prod'_def LC)\n    apply (rule dwa.while_proof)\n    apply (case_tac s)\n    apply (simp add: pa_det_algo_def pa_invar_add_def pa_invar_def init_hta_def)\n    apply unfold_locales\n    apply (simp_all add: hhh_cart.cart_correct)\n    done\nqed\n\ntheorem hta_prod'_correct:\n  assumes TA: \"hashedTa H1\" \"hashedTa H2\"\n  assumes HI: \"hta_has_idx_s H1\" \"hta_has_idx_sf H2\"\n  shows \n    \"ta_lang (hta_\\<alpha> (hta_prod' H1 H2)) \n     = ta_lang (hta_\\<alpha> H1) \\<inter> ta_lang (hta_\\<alpha> H2)\"\n\n    \"hashedTa (hta_prod' H1 H2)\"\n  by (simp_all add: hta_prod'_correct_aux[OF TA HI] ta_prod_correct_aux1)\n\nlemma hta_prod_correct_aux:\n  assumes TA[simp]: \"hashedTa H1\" \"hashedTa H2\"\n  shows \n    \"hta_\\<alpha> (hta_prod H1 H2) = ta_fwd_reduce (ta_prod (hta_\\<alpha> H1) (hta_\\<alpha> H2))\"\n    \"hashedTa (hta_prod H1 H2)\"\n  by (unfold hta_prod_def)\n     (simp_all add: hta_prod'_correct_aux)\n  \ntheorem hta_prod_correct:\n  assumes TA: \"hashedTa H1\" \"hashedTa H2\"\n  shows \n    \"ta_lang (hta_\\<alpha> (hta_prod H1 H2)) \n     = ta_lang (hta_\\<alpha> H1) \\<inter> ta_lang (hta_\\<alpha> H2)\"\n    \"hashedTa (hta_prod H1 H2)\"\n  by (simp_all add: hta_prod_correct_aux[OF TA] ta_prod_correct_aux1)\n\n\nsubsection \"Remap States\"\n\n\\<comment> \\<open>Mapping the states of an automaton\\<close>\ndefinition hta_remap \n  :: \"('q::hashable \\<Rightarrow> 'qn::hashable) \\<Rightarrow> ('q,'l::hashable) hashedTa \n      \\<Rightarrow> ('qn,'l) hashedTa\" \n  where \"hta_remap f H == \n    init_hta (hh_set_xy.g_image f (hta_Qi H)) \n      (ll_set_xy.g_image (remap_rule f) (hta_\\<delta> H))\"\n  \nlemma (in hashedTa) hta_remap_correct:\n  shows \"hta_\\<alpha> (hta_remap f H) = ta_remap f (hta_\\<alpha> H)\"\n        \"hashedTa (hta_remap f H)\"\n  apply (auto \n    simp add: hta_remap_def init_hta_def hta_\\<alpha>_def \n              hh_set_xy.image_correct ll_set_xy.image_correct ta_remap_def)\n  apply (unfold_locales)\n  apply (auto simp add: hh_set_xy.image_correct ll_set_xy.image_correct)\n  done\n\n\nsubsubsection \"Reindex Automaton\"\ntext \\<open>\n  In this section, an algorithm for re-indexing the states of the automaton to\n  an initial segment of the naturals is implemented. The language of the \n  automaton is not changed by the reindexing operation.\n\\<close>\n\n  \\<comment> \\<open>Set of states of a rule\\<close>\nfun rule_states_l where\n  \"rule_states_l (q \\<rightarrow> f qs) = ls_ins q (ls.from_list qs)\"\n\nlemma rule_states_l_correct[simp]: \n  \"ls_\\<alpha> (rule_states_l r) = rule_states r\"\n  \"ls_invar (rule_states_l r)\"\n  by (cases r, simp add: ls.correct)+\n\ndefinition \"hta_\\<delta>_states H \n  == (llh_set_xyy.g_Union_image id (ll_set_xy.g_image_filter \n       (\\<lambda>r. Some (rule_states_l r)) (hta_\\<delta> H)))\"\n\ndefinition \"hta_states H ==\n  hs_union (hta_Qi H) (hta_\\<delta>_states H)\"\n\nlemma (in hashedTa) hta_\\<delta>_states_correct:\n  \"hs_\\<alpha> (hta_\\<delta>_states H) = \\<delta>_states (ta_rules (hta_\\<alpha> H))\"\n  \"hs_invar (hta_\\<delta>_states H)\"\nproof (simp_all add: hta_\\<alpha>_def hta_\\<delta>_states_def, goal_cases)\n  case 1\n  have \n    [simp]: \"ls_\\<alpha> (ll_set_xy.g_image_filter (\\<lambda>x. Some (rule_states_l x)) \\<delta>) \n             = rule_states_l ` ls_\\<alpha> \\<delta>\"\n    by (auto simp add: ll_set_xy.image_filter_correct)\n  show ?case\n    apply (simp add: \\<delta>_states_def)\n    apply (subst\n      llh_set_xyy.Union_image_correct[\n        of \"(ll_set_xy.g_image_filter (\\<lambda>x. Some (rule_states_l x)) \\<delta>)\", \n        simplified])\n    apply (auto simp add: ll_set_xy.image_filter_correct)\n    done\n(*next\n  case goal2 thus ?case\n    apply (rule llh.Union_image_correct)\n    apply (auto simp add: ls.image_filter_correct)\n    done*)\nqed\n\n\n\ndefinition \"reindex_map H == \n  \\<lambda>q. the (hm_lookup q (hh_map_to_nat.map_to_nat (hta_states H)))\"\n\ndefinition hta_reindex \n  :: \"('Q::hashable,'L::hashable) hashedTa \\<Rightarrow> (nat,'L) hashedTa\" where\n  \"hta_reindex H == hta_remap (reindex_map H) H\"\n\ndeclare hta_reindex_def [code del]\n\n  \\<comment> \\<open>This version is more efficient, as the map is only computed once\\<close>\n\n\n\nlemma (in hashedTa) reindex_map_correct:\n  \"inj_on (reindex_map H) (ta_rstates (hta_\\<alpha> H))\"\nproof -\n  have [simp]: \n    \"reindex_map H = the \\<circ> hm_\\<alpha> (hh_map_to_nat.map_to_nat (hta_states H))\"\n    by (rule ext)\n       (simp add: reindex_map_def hm.correct \n         hh_map_to_nat.map_to_nat_correct(4) \n         hta_states_correct)\n\n  show ?thesis\n    apply (simp add: hta_states_correct(1)[symmetric])\n    apply (rule inj_on_map_the)\n    apply (simp_all add: hh_map_to_nat.map_to_nat_correct hta_states_correct(2))\n    done\nqed\n\ntheorem (in hashedTa) hta_reindex_correct:\n  \"ta_lang (hta_\\<alpha> (hta_reindex H)) = ta_lang (hta_\\<alpha> H)\"\n  \"hashedTa (hta_reindex H)\"\n  apply (unfold hta_reindex_def)\n  apply (simp_all \n    add: hta_remap_correct tree_automaton.remap_lang[OF hta_\\<alpha>_is_ta] \n         reindex_map_correct)\n  done\n\nsubsection \"Union\"\n\ntext \"Computes the union of two automata\"\ndefinition hta_union \n  :: \"('q1::hashable,'l::hashable) hashedTa \n      \\<Rightarrow> ('q2::hashable,'l) hashedTa \n      \\<Rightarrow> (('q1,'q2) ustate_wrapper,'l) hashedTa\" \n  where \"hta_union H1 H2 == \n    init_hta (hs_union (hh_set_xy.g_image USW1 (hta_Qi H1)) \n                       (hh_set_xy.g_image USW2 (hta_Qi H2))) \n             (ls_union_dj (ll_set_xy.g_image (remap_rule USW1) (hta_\\<delta> H1)) \n                          (ll_set_xy.g_image (remap_rule USW2) (hta_\\<delta> H2)))\"\n\nlemma hta_union_correct': \n  assumes TA: \"hashedTa H1\" \"hashedTa H2\"\n  shows \"hta_\\<alpha> (hta_union H1 H2) \n         = ta_union_wrap (hta_\\<alpha> H1) (hta_\\<alpha> H2)\" (is ?T1)\n        \"hashedTa (hta_union H1 H2)\" (is ?T2)\nproof -\n  interpret a1: hashedTa H1 + a2: hashedTa H2 using TA .\n  show ?T1 ?T2 \n    apply (auto \n      simp add: hta_union_def init_hta_def hta_\\<alpha>_def \n                hs.correct ls.correct \n                ll_set_xy.image_correct hh_set_xy.image_correct\n                ta_remap_def ta_union_def ta_union_wrap_def)\n    apply (unfold_locales)\n    apply (auto \n      simp add: hs.correct ls.correct)\n    done\nqed\n\ntheorem hta_union_correct: \n  assumes TA: \"hashedTa H1\" \"hashedTa H2\"\n  shows \n    \"ta_lang (hta_\\<alpha> (hta_union H1 H2)) \n     = ta_lang (hta_\\<alpha> H1) \\<union> ta_lang (hta_\\<alpha> H2)\" (is ?T1)\n    \"hashedTa (hta_union H1 H2)\" (is ?T2)\nproof -\n  interpret a1: hashedTa H1 + a2: hashedTa H2 using TA .\n  show ?T1 ?T2\n    by (simp_all add: hta_union_correct'[OF TA] ta_union_wrap_correct)\nqed\n\nsubsection \"Operators to Construct Tree Automata\"\ntext \\<open>\n  This section defines operators that add initial states and rules to a tree \n  automaton, and thus incrementally construct a tree automaton from the empty\n  automaton.\n\\<close>\n\n\\<comment> \\<open>The empty automaton\\<close>\ndefinition hta_empty :: \"unit \\<Rightarrow> ('q::hashable,'l::hashable) hashedTa\" \n  where \"hta_empty u == init_hta (hs_empty ()) (ls_empty ())\"\nlemma hta_empty_correct [simp, intro!]: \n  shows \"(hta_\\<alpha> (hta_empty ())) = ta_empty\"\n        \"hashedTa (hta_empty ())\"\n  apply (auto\n    simp add: init_hta_def hta_empty_def hta_\\<alpha>_def \\<delta>_states_def ta_empty_def\n              hs.correct ls.correct)\n  apply (unfold_locales)\n  apply (auto simp add: hs.correct ls.correct)\n  done\n\n\\<comment> \\<open>Add an initial state to the automaton\\<close>\ndefinition hta_add_qi \n  :: \"'q \\<Rightarrow> ('q::hashable,'l::hashable) hashedTa \\<Rightarrow> ('q,'l) hashedTa\" \n  where \"hta_add_qi qi H == init_hta (hs_ins qi (hta_Qi H)) (hta_\\<delta> H)\"\n\nlemma (in hashedTa) hta_add_qi_correct[simp, intro!]:\n  shows \"hta_\\<alpha> (hta_add_qi qi H) \n         = \\<lparr> ta_initial = insert qi (ta_initial (hta_\\<alpha> H)), \n             ta_rules = ta_rules (hta_\\<alpha> H) \n           \\<rparr>\"\n        \"hashedTa (hta_add_qi qi H)\"\n  apply (auto \n    simp add: init_hta_def hta_add_qi_def hta_\\<alpha>_def \\<delta>_states_def \n              hs.correct)\n  apply (unfold_locales)\n  apply (auto simp add: hs.correct)\n  done\n\nlemmas [simp, intro] = hashedTa.hta_add_qi_correct\n\n\\<comment> \\<open>Add a rule to the automaton\\<close>\ndefinition hta_add_rule \n  :: \"('q,'l) ta_rule \\<Rightarrow> ('q::hashable,'l::hashable) hashedTa \n      \\<Rightarrow> ('q,'l) hashedTa\" \n  where \"hta_add_rule r H == init_hta (hta_Qi H) (ls_ins r (hta_\\<delta> H))\"\n\nlemma (in hashedTa) hta_add_rule_correct[simp, intro!]:\n  shows \"hta_\\<alpha> (hta_add_rule r H) \n         = \\<lparr> ta_initial = ta_initial (hta_\\<alpha> H), \n             ta_rules = insert r (ta_rules (hta_\\<alpha> H)) \n           \\<rparr>\"\n        \"hashedTa (hta_add_rule r H)\"\n  apply (auto \n    simp add: init_hta_def hta_add_rule_def hta_\\<alpha>_def \n              \\<delta>_states_def ls.correct)\n  apply (unfold_locales)\n  apply (auto simp add: ls.correct)\n  done\n\nlemmas [simp, intro] = hashedTa.hta_add_rule_correct\n\n\n  \\<comment> \\<open>Reduces an automaton to the given set of states\\<close>\ndefinition \"hta_reduce H Q ==\n  init_hta (hs_inter Q (hta_Qi H)) \n           (ll_set_xy.g_image_filter \n              (\\<lambda>r. if hs_memb (lhs r) Q \\<and> list_all (\\<lambda>q. hs_memb q Q) (rhsq r) then Some r else None) \n              (hta_\\<delta> H))\n\"\n\ntheorem (in hashedTa) hta_reduce_correct:\n  assumes INV[simp]: \"hs_invar Q\"\n  shows\n  \"hta_\\<alpha> (hta_reduce H Q) = ta_reduce (hta_\\<alpha> H) (hs_\\<alpha> Q)\" (is ?T1)\n  \"hashedTa (hta_reduce H Q)\" (is ?T2)\n  apply (auto \n    simp add: \n      hta_reduce_def ta_reduce_def hta_\\<alpha>_def init_hta_def \n      hs.correct ls.correct\n    (*hs_correct ls_correct *)\n      list_all_iff \n      reduce_rules_def rule_states_simp \n      ll_set_xy.image_filter_correct\n    split: \n      ta_rule.split_asm\n  ) [1]\n  apply (unfold_locales)\n  apply (unfold hta_reduce_def init_hta_def)\n  apply (auto simp add: hs.correct ls.correct)\n  done\n\n\n\nsubsection \"Backwards Reduction and Emptiness Check\"\n\ntext \\<open>\n  The algorithm uses a map from states to the set of rules that contain \n  the state on their rhs.\n\\<close>\n\n  \\<comment> \\<open>Add an entry to the index\\<close>\ndefinition \"rqrm_add q r res ==\n  case hm_lookup q res of\n    None \\<Rightarrow> hm_update q (ls_ins r (ls_empty ())) res |\n    Some s \\<Rightarrow> hm_update q (ls_ins r s) res\n  \"\n\n  \\<comment> \\<open>Lookup the set of rules with given state on rhs\\<close>\ndefinition \"rqrm_lookup rqrm q == case hm_lookup q rqrm of\n  None \\<Rightarrow> ls_empty () |\n  Some s \\<Rightarrow> s\n  \"\n\n  \\<comment> \\<open>Build the index from a set of rules\\<close>\ndefinition build_rqrm \n  :: \"('q::hashable,'l::hashable) ta_rule ls \n      \\<Rightarrow> ('q,('q,'l) ta_rule ls) hm\" \n  where\n  \"build_rqrm \\<delta> ==\n    ls_iteratei \\<delta> (\\<lambda>_. True)\n      (\\<lambda>r res. \n        foldl (\\<lambda>res q. rqrm_add q r res) res (rhsq r)\n      )\n      (hm_empty ())\n  \"\n\n\\<comment> \\<open>Whether the index satisfies the map and set invariants\\<close>\ndefinition \"rqrm_invar rqrm == \n  hm_invar rqrm \\<and> (\\<forall>q. ls_invar (rqrm_lookup rqrm q))\"\n\\<comment> \\<open>Whether the index really maps a state to the set of rules with this \n    state on their rhs\\<close>\ndefinition \"rqrm_prop \\<delta> rqrm == \n  \\<forall>q. ls_\\<alpha> (rqrm_lookup rqrm q) = {r\\<in>\\<delta>. q\\<in>set (rhsq r)}\"\n\nlemma rqrm_\\<alpha>_lookup_update[simp]: \n  \"rqrm_invar rqrm \\<Longrightarrow> \n    ls_\\<alpha> (rqrm_lookup (rqrm_add q r rqrm) q') \n    = ( if q=q' then \n          insert r (ls_\\<alpha> (rqrm_lookup rqrm q')) \n        else \n          ls_\\<alpha> (rqrm_lookup rqrm q')\n      )\"\n  by (simp \n    add: rqrm_lookup_def rqrm_add_def rqrm_invar_def hm.correct \n         ls.correct \n    split: option.split_asm option.split)\n\nlemma rqrm_propD: \n  \"rqrm_prop \\<delta> rqrm \\<Longrightarrow> ls_\\<alpha> (rqrm_lookup rqrm q) = {r\\<in>\\<delta>. q\\<in>set (rhsq r)}\"\n  by (simp add: rqrm_prop_def)\n\nlemma build_rqrm_correct:\n  fixes \\<delta>\n  assumes [simp]: \"ls_invar \\<delta>\"\n  shows \"rqrm_invar (build_rqrm \\<delta>)\" (is ?T1) and\n        \"rqrm_prop (ls_\\<alpha> \\<delta>) (build_rqrm \\<delta>)\" (is ?T2)\nproof -\n  have \"rqrm_invar (build_rqrm \\<delta>) \\<and> \n    (\\<forall>q. ls_\\<alpha> (rqrm_lookup (build_rqrm \\<delta>) q) = {r\\<in>ls_\\<alpha> \\<delta>. q\\<in>set (rhsq r)})\"\n    apply (unfold build_rqrm_def)\n    apply (rule_tac \n      I=\"\\<lambda>it res. (rqrm_invar res) \n                  \\<and> (\\<forall>q. ls_\\<alpha> (rqrm_lookup res q) \n                     = {r\\<in>ls_\\<alpha> \\<delta> - it. q\\<in>set (rhsq r)})\" \n      in ls.iterate_rule_P)\n      \\<comment> \\<open>Invar\\<close>\n    apply simp\n      \\<comment> \\<open>Initial\\<close>\n    apply (simp add: hm_correct ls_correct rqrm_lookup_def rqrm_invar_def)\n      \\<comment> \\<open>Step\\<close>\n    apply (rule_tac \n      I=\"\\<lambda>res itl itr. \n        (rqrm_invar res) \n        \\<and> (\\<forall>q. ls_\\<alpha> (rqrm_lookup res q) \n           = {r\\<in>ls_\\<alpha> \\<delta> - it. q\\<in>set (rhsq r)} \n             \\<union> {r. r=x \\<and> q\\<in>set itl})\" \n      in Misc.foldl_rule_P)\n        \\<comment> \\<open>Initial\\<close>\n      apply simp\n        \\<comment> \\<open>Step\\<close>\n      apply (intro conjI)\n      apply (simp \n        add: rqrm_invar_def rqrm_add_def rqrm_lookup_def hm_correct \n             ls_correct \n        split: option.split option.split_asm)\n      apply simp\n      apply (simp \n        add: rqrm_add_def rqrm_lookup_def hm_correct ls_correct \n        split: option.split option.split_asm)\n      apply (auto) [1]\n        \\<comment> \\<open>Final\\<close>\n      apply auto [1]\n      \\<comment> \\<open>Final\\<close>\n    apply simp\n    done\n  thus ?T1 ?T2 by (simp_all add: rqrm_prop_def)\nqed\n\n\\<comment> \\<open>A state of the basic algorithm contains a set of discovered states, \n    a worklist and a map from rules to the number of distinct states on \n    its RHS that have not yet been discovered or are still on the worklist\\<close>\ntype_synonym ('Q,'L) brc_state \n  = \"'Q hs \\<times> 'Q list \\<times> (('Q,'L) ta_rule, nat) hm\"\n\n\\<comment> \\<open>Abstraction to @{text \\<alpha>'}-level:\\<close>\ndefinition brc_\\<alpha> \n  :: \"('Q::hashable,'L::hashable) brc_state \\<Rightarrow> ('Q,'L) br'_state\"\n  where \"brc_\\<alpha> == \\<lambda>(Q,W,rcm). (hs_\\<alpha> Q, set W, hm_\\<alpha> rcm)\"\n\ndefinition brc_invar_add :: \"('Q::hashable,'L::hashable) brc_state set\" \n  where\n  \"brc_invar_add == {(Q,W,rcm). \n    hs_invar Q \\<and> \n    distinct W \\<and> \n    hm_invar rcm\n    \\<^cancel>\\<open>\\<and> set W \\<subseteq> hs_\\<alpha> Q\\<close>}\n  \"\n\ndefinition \"brc_invar \\<delta> == brc_invar_add \\<inter> {s. brc_\\<alpha> s \\<in> br'_invar \\<delta>}\"\n\ndefinition brc_cond :: \"('q::hashable,'l::hashable) brc_state \\<Rightarrow> bool\" \n  where \"brc_cond == \\<lambda>(Q,W,rcm). W\\<noteq>[]\"\n\ndefinition brc_inner_step \n  :: \"('q,'l) ta_rule \\<Rightarrow> ('q::hashable,'l::hashable) brc_state \n      \\<Rightarrow> ('q,'l) brc_state\"\n  where \n  \"brc_inner_step r == \\<lambda>(Q,W,rcm). \n    let c=the (hm_lookup r rcm);\n        rcm' = hm_update r (c-(1::nat)) rcm;\n        Q' = (if c \\<le> 1 then hs_ins (lhs r) Q else Q);\n        W' = (if c \\<le> 1 \\<and> \\<not> hs_memb (lhs r) Q then lhs r # W else W) in\n      (Q',W',rcm')\"\n\ndefinition brc_step \n  :: \"('q,('q,'l) ta_rule ls) hm \n      \\<Rightarrow> ('q::hashable,'l::hashable) brc_state \n      \\<Rightarrow> ('q,'l) brc_state\" \nwhere \n  \"brc_step rqrm == \\<lambda>(Q,W,rcm).\n    ls_iteratei (rqrm_lookup rqrm (hd W)) (\\<lambda>_. True) brc_inner_step \n      (Q,tl W, rcm)\"\n\n  \\<comment> \\<open>Initial concrete state\\<close>\ndefinition brc_iq :: \"('q,'l) ta_rule ls \\<Rightarrow> 'q::hashable hs\" \n  where \"brc_iq \\<delta> == lh_set_xy.g_image_filter (\\<lambda>r. \n    if rhsq r = [] then Some (lhs r) else None) \\<delta>\"\n\ndefinition brc_rcm_init \n  :: \"('q::hashable,'l::hashable) ta_rule ls \n      \\<Rightarrow> (('q,'l) ta_rule,nat) hm\" \n  where \"brc_rcm_init \\<delta> == \n    ls_iteratei \\<delta> (\\<lambda>_. True) \n      (\\<lambda>r res. hm_update r ((length (remdups (rhsq r)))) res) \n      (hm_empty ())\"\n\ndefinition brc_initial \n  :: \"('q::hashable,'l::hashable) ta_rule ls \\<Rightarrow> ('q,'l) brc_state\" \n  where \"brc_initial \\<delta> == \n    let iq=brc_iq \\<delta> in \n      (iq, hs_to_list (iq), brc_rcm_init \\<delta>)\"\n\ndefinition \"brc_det_algo rqrm \\<delta> == \\<lparr>\n  dwa_cond = brc_cond,\n  dwa_step = brc_step rqrm,\n  dwa_initial = brc_initial \\<delta>,\n  dwa_invar = brc_invar (ls_\\<alpha> \\<delta>)\n\\<rparr>\"\n\n  \\<comment> \\<open>Additional facts needed from the abstract level\\<close>\nlemma brc_inv_imp_WssQ: \"brc_\\<alpha> (Q,W,rcm)\\<in>br'_invar \\<delta> \\<Longrightarrow> set W \\<subseteq> hs_\\<alpha> Q\"\n  by (auto simp add: brc_\\<alpha>_def br'_invar_def br'_\\<alpha>_def br_invar_def)\n\nlemma brc_iq_correct: \n  assumes [simp]: \"ls_invar \\<delta>\"\n  shows \"hs_invar (brc_iq \\<delta>)\"\n        \"hs_\\<alpha> (brc_iq \\<delta>) = br_iq (ls_\\<alpha> \\<delta>)\"\n  by (auto simp add: brc_iq_def br_iq_def lh_set_xy.image_filter_correct)\n\nlemma brc_rcm_init_correct:\n  assumes INV[simp]: \"ls_invar \\<delta>\"\n  shows \"r\\<in>ls_\\<alpha> \\<delta> \n    \\<Longrightarrow> hm_\\<alpha> (brc_rcm_init \\<delta>) r = Some ((card (set (rhsq r))))\" \n  (is \"_ \\<Longrightarrow> ?T1 r\") and\n    \"hm_invar (brc_rcm_init \\<delta>)\" (is ?T2)\nproof -\n  have G: \"(\\<forall>r\\<in>ls_\\<alpha> \\<delta>. ?T1 r) \\<and> ?T2\"\n    apply (unfold brc_rcm_init_def)\n    apply (rule_tac \n      I=\"\\<lambda>it res. hm_invar res \n           \\<and> (\\<forall>r\\<in>ls_\\<alpha> \\<delta> - it. hm_\\<alpha> res r = Some ((card (set (rhsq r)))))\" \n      in ls.iterate_rule_P)\n      \\<comment> \\<open>Invar\\<close>\n    apply simp\n      \\<comment> \\<open>Init\\<close>\n    apply (auto simp add: hm_correct) [1]\n      \\<comment> \\<open>Step\\<close>\n    apply (rule conjI)\n      apply (simp add: hm.update_correct)\n\n      apply (simp only: hm_correct hs_correct INV)\n      apply (rule ballI)\n      apply (case_tac \"r=x\")\n      apply (auto \n        simp add: length_remdups_card \n        intro!: arg_cong[where f=card]) [1]\n      apply simp\n      \\<comment> \\<open>Final\\<close>\n    apply simp\n    done\n  from G show ?T2 by auto\n  fix r\n  assume \"r\\<in>ls_\\<alpha> \\<delta>\"\n  thus \"?T1 r\" using G by auto\nqed\n\nlemma brc_inner_step_br'_desc: \n  \"\\<lbrakk> (Q,W,rcm)\\<in>brc_invar \\<delta> \\<rbrakk> \\<Longrightarrow> brc_\\<alpha> (brc_inner_step r (Q,W,rcm)) = (\n    if the (hm_\\<alpha> rcm r) \\<le> 1 then \n      insert (lhs r) (hs_\\<alpha> Q) \n    else hs_\\<alpha> Q, \n    if the (hm_\\<alpha> rcm r) \\<le> 1 \\<and> (lhs r) \\<notin> hs_\\<alpha> Q then \n      insert (lhs r) (set W) \n    else (set W), \n    ((hm_\\<alpha> rcm)(r \\<mapsto> the (hm_\\<alpha> rcm r) - 1))\n  )\"\n  by (simp \n    add: brc_invar_def brc_invar_add_def brc_\\<alpha>_def brc_inner_step_def Let_def \n         hs_correct hm_correct)\n\nlemma brc_step_invar:\n  assumes RQRM: \"rqrm_invar rqrm\"\n  shows \"\\<lbrakk> \\<Sigma>\\<in>brc_invar_add; brc_\\<alpha> \\<Sigma>\\<in>br'_invar \\<delta>; brc_cond \\<Sigma> \\<rbrakk> \n         \\<Longrightarrow> (brc_step rqrm \\<Sigma>)\\<in>brc_invar_add\"\n  apply (cases \\<Sigma>)\n  apply (simp add: brc_step_def)\n  apply (rule_tac I=\"\\<lambda>it (Q,W,rcm). (Q,W,rcm)\\<in>brc_invar_add \\<and> set W \\<subseteq> hs_\\<alpha> Q\" \n                  in ls.iterate_rule_P)\n  apply (simp add: RQRM[unfolded rqrm_invar_def])\n  apply (case_tac b)\n  apply (simp add: brc_invar_add_def distinct_tl brc_cond_def)\n  apply (auto simp add: brc_invar_add_def distinct_tl brc_cond_def \n              dest!: brc_inv_imp_WssQ) [1]\n  apply (case_tac \\<sigma>)\n  apply (auto simp add: brc_invar_add_def br_invar_def brc_inner_step_def \n                        Let_def hs_correct hm_correct) [1]\n  apply (case_tac \\<sigma>)\n  apply simp\n  done\n\n\nlemma brc_step_abs:\n  assumes RQRM: \"rqrm_invar rqrm\" \"rqrm_prop \\<delta> rqrm\"\n  assumes A: \"\\<Sigma>\\<in>brc_invar \\<delta>\" \"brc_cond \\<Sigma>\"  \n  shows \"(brc_\\<alpha> \\<Sigma>, brc_\\<alpha> (brc_step rqrm \\<Sigma>)) \\<in> br'_step \\<delta>\"\nproof -\n  obtain Q W rcm where [simp]: \"\\<Sigma>=(Q,W,rcm)\" by (cases \\<Sigma>) auto\n  from A show ?thesis\n    apply (simp add: brc_step_def)\n    apply (rule \n      br'_inner_step_proof[OF ls.v1_iteratei_impl, \n         where cinvar=\"\\<lambda>it (Q,W,rcm). (Q,W,rcm)\\<in>brc_invar_add \n                                      \\<and> set W \\<subseteq> hs_\\<alpha> Q\" and \n               q=\"hd W\"])\n    apply (case_tac W) \n    apply (auto simp add: brc_cond_def brc_invar_add_def brc_invar_def \n                dest!: brc_inv_imp_WssQ) [2]\n    prefer 6\n    apply (simp add: brc_\\<alpha>_def)\n    apply (case_tac \\<Sigma>)\n    apply (auto \n      simp add: brc_invar_def brc_invar_add_def brc_inner_step_def \n                Let_def hm_correct hs_correct) [1]\n    apply (auto \n      simp add: brc_invar_add_def brc_inner_step_def brc_\\<alpha>_def \n                br'_inner_step_def Let_def hm_correct hs_correct) [1]\n    apply (simp add: RQRM[unfolded rqrm_invar_def])\n    apply (simp add: rqrm_propD[OF RQRM(2)])\n    apply (case_tac W)\n    apply (simp_all add: brc_\\<alpha>_def brc_cond_def brc_invar_def) [2]\n    apply (case_tac W)\n    apply (simp_all add: brc_\\<alpha>_def brc_cond_def brc_invar_def \n                         brc_invar_add_def) [2]\n    done\nqed\n    \nlemma brc_initial_invar: \"ls_invar \\<delta> \\<Longrightarrow> (brc_initial \\<delta>)\\<in>brc_invar_add\"\n  by (simp \n    add: brc_invar_add_def brc_initial_def brc_iq_correct Let_def \n         brc_rcm_init_correct hs_correct)\n\nlemma brc_cond_abs: \"brc_cond \\<Sigma> \\<longleftrightarrow> (brc_\\<alpha> \\<Sigma>)\\<in>br'_cond\"\n  apply (cases \\<Sigma>)\n  apply (simp add: brc_cond_def br'_cond_def brc_\\<alpha>_def)\n  done\n\nlemma brc_initial_abs: \n  \"ls_invar \\<delta> \\<Longrightarrow> brc_\\<alpha> (brc_initial \\<delta>) \\<in> br'_initial (ls_\\<alpha> \\<delta>)\"\n  by (auto \n    simp add: brc_initial_def Let_def brc_\\<alpha>_def brc_iq_correct \n              brc_rcm_init_correct hs_correct \n    intro: br'_initial.intros)\n\nlemma brc_pref_br':\n  assumes RQRM[simp]: \"rqrm_invar rqrm\" \"rqrm_prop (ls_\\<alpha> \\<delta>) rqrm\"\n  assumes INV[simp]: \"ls_invar \\<delta>\"\n  shows \"wa_precise_refine (det_wa_wa (brc_det_algo rqrm \\<delta>)) \n                           (br'_algo (ls_\\<alpha> \\<delta>)) \n                           brc_\\<alpha>\"\n  apply (unfold_locales)\n  apply (simp_all add: brc_det_algo_def br'_algo_def det_wa_wa_def)\n  apply (simp add: brc_cond_abs)\n  apply (auto simp add: brc_step_abs[OF RQRM]) [1]\n  apply (simp add: brc_initial_abs)\n  apply (auto simp add: brc_invar_def) [1]\n  apply (simp add: brc_cond_abs)\n  done\n\nlemma brc_while_algo:\n  assumes RQRM[simp]: \"rqrm_invar rqrm\" \"rqrm_prop (ls_\\<alpha> \\<delta>) rqrm\"\n  assumes INV[simp]: \"ls_invar \\<delta>\"\n  shows \"while_algo (det_wa_wa (brc_det_algo rqrm \\<delta>))\"\nproof -\n  from brc_pref_br'[OF RQRM INV] interpret \n    ref: wa_precise_refine \"(det_wa_wa (brc_det_algo rqrm \\<delta>))\" \n                           \"(br'_algo (ls_\\<alpha> \\<delta>))\" \n                           brc_\\<alpha> .\n  show ?thesis\n    apply (rule ref.wa_intro)\n    apply (simp add: br'_while_algo)\n    apply (simp_all add: det_wa_wa_def brc_det_algo_def br'_algo_def)\n    apply (simp add: brc_invar_def)\n    apply (auto simp add: brc_step_invar) [1]\n    apply (simp add: brc_initial_invar)\n    done\nqed\n\nlemmas brc_det_while_algo =\n  det_while_algo_intro[OF brc_while_algo]\n\n\nlemma fst_brc_\\<alpha>: \"fst (brc_\\<alpha> s) = hs_\\<alpha> (fst s)\" \n  by (cases s) (simp add: brc_\\<alpha>_def)\n\nlemmas brc_invar_final =\n  wa_precise_refine.transfer_correctness[OF \n    brc_pref_br' br'_invar_final, unfolded fst_brc_\\<alpha>]\n\ndefinition \"hta_bwd_reduce H == \n  let rqrm = build_rqrm (hta_\\<delta> H) in \n    hta_reduce \n      H \n      (fst (while brc_cond (brc_step rqrm) (brc_initial (hta_\\<delta> H))))\n\"\n\ntheorem (in hashedTa) hta_bwd_reduce_correct:\n  shows \"hta_\\<alpha> (hta_bwd_reduce H) \n         = ta_reduce (hta_\\<alpha> H) (b_accessible (ls_\\<alpha> (hta_\\<delta> H)))\" (is ?T1)\n        \"hashedTa (hta_bwd_reduce H)\" (is ?T2)\nproof -\n  interpret det_while_algo \"(brc_det_algo (build_rqrm \\<delta>) \\<delta>)\"\n    by (rule brc_det_while_algo)\n       (simp_all add: build_rqrm_correct)\n\n  have LC: \"(while brc_cond (brc_step (build_rqrm \\<delta>)) (brc_initial \\<delta>)) = loop\"\n    by (unfold loop_def)\n       (simp add: brc_det_algo_def)\n\n  from while_proof'[OF brc_invar_final] have \n    G1: \"hs_\\<alpha> (fst loop) = b_accessible (ls_\\<alpha> \\<delta>)\" \n    by (simp add: build_rqrm_correct)\n  have G2: \"loop \\<in> brc_invar (ls_\\<alpha> \\<delta>)\"\n    by (rule while_proof)\n       (simp add: brc_det_algo_def)\n  hence [simp]: \"hs_invar (fst loop)\"\n    by (cases loop)\n       (simp add: brc_invar_def brc_invar_add_def)\n\n  show ?T1 ?T2\n    by (simp_all add: hta_bwd_reduce_def LC hta_reduce_correct G1)\n    \nqed\n\nsubsubsection \\<open>Emptiness Check with Witness Computation\\<close>\n\ndefinition brec_construct_witness \n  :: \"('q::hashable,'l::hashable tree) hm \\<Rightarrow> ('q,'l) ta_rule \\<Rightarrow> 'l tree\"\n  where \"brec_construct_witness Qm r == \n  NODE (rhsl r) (List.map (\\<lambda>q. the (hm_lookup q Qm)) (rhsq r))\"\n\nlemma brec_construct_witness_correct: \n  \"\\<lbrakk>hm_invar Qm\\<rbrakk> \\<Longrightarrow> \n    brec_construct_witness Qm r = construct_witness (hm_\\<alpha> Qm) r\"\n  by (auto \n    simp add: construct_witness_def brec_construct_witness_def hm_correct)\n\ntype_synonym ('Q,'L) brec_state \n  = \"(('Q,'L tree) hm \n      \\<times> 'Q fifo \n      \\<times> (('Q,'L) ta_rule, nat) hm \n      \\<times> 'Q option)\"\n\n\n  \\<comment> \\<open>Abstractions\\<close>\ndefinition brec_\\<alpha> \n  :: \"('Q::hashable,'L::hashable) brec_state \\<Rightarrow> ('Q,'L) brw_state\"\n  where \"brec_\\<alpha> == \\<lambda>(Q,W,rcm,f). (hm_\\<alpha> Q, set (fifo_\\<alpha> W), (hm_\\<alpha> rcm))\"\n\ndefinition brec_inner_step \n  :: \"'q hs \\<Rightarrow> ('q,'l) ta_rule \n      \\<Rightarrow> ('q::hashable,'l::hashable) brec_state \n      \\<Rightarrow> ('q,'l) brec_state\"\n  where \"brec_inner_step Qi r == \\<lambda>(Q,W,rcm,qwit). \n    let c=the (hm_lookup r rcm); \n        cond = c \\<le> 1 \\<and> hm_lookup (lhs r) Q = None;\n        rcm' = hm_update r (c-(1::nat)) rcm;\n        Q' = ( if cond then \n                 hm_update (lhs r) (brec_construct_witness Q r) Q \n               else Q);\n        W' = (if cond then fifo_enqueue (lhs r) W else W);\n        qwit' = (if c \\<le> 1 \\<and> hs_memb (lhs r) Qi then Some (lhs r) else qwit)\n    in\n      (Q',W',rcm',qwit')\"\n\ndefinition brec_step \n  :: \"('q,('q,'l) ta_rule ls) hm \\<Rightarrow> 'q hs \n      \\<Rightarrow> ('q::hashable,'l::hashable) brec_state \n      \\<Rightarrow> ('q,'l) brec_state\" \n  where \"brec_step rqrm Qi == \\<lambda>(Q,W,rcm,qwit).\n    let (q,W')=fifo_dequeue W in \n      ls_iteratei (rqrm_lookup rqrm q) (\\<lambda>_. True) \n        (brec_inner_step Qi) (Q,W',rcm,qwit)\n  \"\n\ndefinition brec_iqm \n  :: \"('q::hashable,'l::hashable) ta_rule ls \\<Rightarrow> ('q,'l tree) hm\" \n  where \"brec_iqm \\<delta> == \n    ls_iteratei \\<delta> (\\<lambda>_. True) (\\<lambda>r m. if rhsq r = [] then \n                         hm_update (lhs r) (NODE (rhsl r) []) m \n                      else m) \n                (hm_empty ())\"\n\ndefinition brec_initial \n  :: \"'q hs \\<Rightarrow> ('q::hashable,'l::hashable) ta_rule ls \n      \\<Rightarrow> ('q,'l) brec_state\" \n  where \"brec_initial Qi \\<delta> == \n  let iq=brc_iq \\<delta> in \n    ( brec_iqm \\<delta>, \n      hs_to_fifo.g_set_to_listr iq, \n      brc_rcm_init \\<delta>,\n      hh_set_xx.g_disjoint_witness iq Qi)\"\n\ndefinition brec_cond \n  :: \"('q,'l) brec_state \\<Rightarrow> bool\" \n  where \"brec_cond == \\<lambda>(Q,W,rcm,qwit). \\<not> fifo_isEmpty W \\<and> qwit = None\"\n\ndefinition brec_invar_add\n  :: \"'Q set \\<Rightarrow> ('Q::hashable,'L::hashable) brec_state set\" \n  where\n  \"brec_invar_add Qi == {(Q,W,rcm,qwit). \n    hm_invar Q \\<and> \n    distinct (fifo_\\<alpha> W) \\<and> \n    hm_invar rcm \\<and>\n    ( case qwit of \n        None \\<Rightarrow> Qi \\<inter> dom (hm_\\<alpha> Q) = {} | \n        Some q \\<Rightarrow> q\\<in>Qi \\<inter> dom (hm_\\<alpha> Q))}\n  \"\n\ndefinition \"brec_invar Qi \\<delta> == brec_invar_add Qi \\<inter> {s. brec_\\<alpha> s \\<in> brw_invar \\<delta>}\"\n\ndefinition \"brec_invar_inner Qi == \n  brec_invar_add Qi \\<inter> {(Q,W,_,_). set (fifo_\\<alpha> W) \\<subseteq> dom (hm_\\<alpha> Q)}\"\n\nlemma brec_invar_cons: \n  \"\\<Sigma>\\<in>brec_invar Qi \\<delta> \\<Longrightarrow> \\<Sigma>\\<in>brec_invar_inner Qi\"\n  apply (cases \\<Sigma>)\n  apply (simp add: brec_invar_def brw_invar_def br'_invar_def br_invar_def\n                   brec_\\<alpha>_def brw_\\<alpha>_def br'_\\<alpha>_def brec_invar_inner_def)\n  done\n\nlemma brec_brw_invar_cons: \n  \"brec_\\<alpha> \\<Sigma> \\<in> brw_invar Qi \\<Longrightarrow> set (fifo_\\<alpha> (fst (snd \\<Sigma>))) \\<subseteq> dom (hm_\\<alpha> (fst \\<Sigma>))\"\n  apply (cases \\<Sigma>)\n  apply (simp add: brec_invar_def brw_invar_def br'_invar_def br_invar_def\n                   brec_\\<alpha>_def brw_\\<alpha>_def br'_\\<alpha>_def)\n  done\n\ndefinition \"brec_det_algo rqrm Qi \\<delta> == \\<lparr>\n  dwa_cond=brec_cond,\n  dwa_step=brec_step rqrm Qi,\n  dwa_initial=brec_initial Qi \\<delta>,\n  dwa_invar=brec_invar (hs_\\<alpha> Qi) (ls_\\<alpha> \\<delta>)\n\\<rparr>\"\n\nlemma brec_iqm_correct':\n  assumes INV[simp]: \"ls_invar \\<delta>\"\n  shows \n    \"dom (hm_\\<alpha> (brec_iqm \\<delta>)) = {lhs r | r. r\\<in>ls_\\<alpha> \\<delta> \\<and> rhsq r = []}\" (is ?T1)\n    \"witness_prop (ls_\\<alpha> \\<delta>) (hm_\\<alpha> (brec_iqm \\<delta>))\" (is ?T2)\n    \"hm_invar (brec_iqm \\<delta>)\" (is ?T3)\nproof -\n  have \"?T1 \\<and> ?T2 \\<and> ?T3\"\n    apply (unfold brec_iqm_def)\n    apply (rule_tac \n      I=\"\\<lambda>it m. hm_invar m \n                \\<and> dom (hm_\\<alpha> m) = {lhs r | r. r\\<in>ls_\\<alpha> \\<delta> - it \\<and> rhsq r = []} \n                \\<and> witness_prop (ls_\\<alpha> \\<delta>) (hm_\\<alpha> m)\" \n      in ls.iterate_rule_P)\n    apply simp\n    apply (auto simp add: hm_correct witness_prop_def) [1]\n    apply (auto simp add: hm_correct witness_prop_def) [1]\n    apply (case_tac x)\n    apply (auto intro: accs.intros) [1]\n    apply simp\n    done\n  thus ?T1 ?T2 ?T3 by auto\nqed\n\nlemma brec_iqm_correct:\n  assumes INV[simp]: \"ls_invar \\<delta>\"\n  shows \"hm_\\<alpha> (brec_iqm \\<delta>) \\<in> brw_iq (ls_\\<alpha> \\<delta>)\"\nproof -\n  have \"(\\<forall>q t. hm_\\<alpha> (brec_iqm \\<delta>) q = Some t \n          \\<longrightarrow> (\\<exists>r\\<in>ls_\\<alpha> \\<delta>. rhsq r = [] \\<and> q = lhs r \\<and> t = NODE (rhsl r) [])) \n        \\<and> (\\<forall>r\\<in>ls_\\<alpha> \\<delta>. rhsq r = [] \\<longrightarrow> hm_\\<alpha> (brec_iqm \\<delta>) (lhs r) \\<noteq> None)\" \n    apply (unfold brec_iqm_def)\n    apply (rule_tac I=\"\\<lambda>it m. (\n      (hm_invar m) \\<and> \n      (\\<forall>q t. hm_\\<alpha> m q = Some t \n        \\<longrightarrow> (\\<exists>r\\<in>ls_\\<alpha> \\<delta>. rhsq r = [] \\<and> q = lhs r \\<and> t = NODE (rhsl r) [])) \\<and> \n      (\\<forall>r\\<in>ls_\\<alpha> \\<delta>-it. rhsq r = [] \\<longrightarrow> hm_\\<alpha> m (lhs r) \\<noteq> None)\n      )\" \n      in ls.iterate_rule_P)\n    apply simp\n    apply (simp add: hm_correct)\n    apply (auto simp add: hm_correct) [1]\n    apply (auto simp add: hm_correct) [1]\n    done\n  thus ?thesis by (blast intro: brw_iq.intros)\nqed\n\nlemma brec_inner_step_brw_desc: \n  \"\\<lbrakk> \\<Sigma>\\<in>brec_invar_inner (hs_\\<alpha> Qi) \\<rbrakk> \n    \\<Longrightarrow> (brec_\\<alpha> \\<Sigma>, brec_\\<alpha> (brec_inner_step Qi r \\<Sigma>)) \\<in> brw_inner_step r\"\n  apply (cases \\<Sigma>)\n  apply (rule brw_inner_step.intros)\n  apply (simp only: )\n  apply (simp only: brec_\\<alpha>_def split_conv)\n  apply (simp only: brec_inner_step_def brec_\\<alpha>_def Let_def split_conv)\n  apply (auto \n    simp add: brec_invar_inner_def brec_invar_add_def brec_\\<alpha>_def \n              brec_inner_step_def \n              Let_def hs_correct hm_correct fifo_correct\n              brec_construct_witness_correct)\n  done\n\n\nlemma brec_step_invar:\n  assumes RQRM: \"rqrm_invar rqrm\" \"rqrm_prop \\<delta> rqrm\"\n  assumes [simp]: \"hs_invar Qi\"\n  shows \"\\<lbrakk> \\<Sigma>\\<in>brec_invar_add (hs_\\<alpha> Qi); brec_\\<alpha> \\<Sigma> \\<in> brw_invar \\<delta>;  brec_cond \\<Sigma> \\<rbrakk> \n          \\<Longrightarrow> (brec_step rqrm Qi \\<Sigma>)\\<in>brec_invar_add (hs_\\<alpha> Qi)\"\n  apply (frule brec_brw_invar_cons)\n  apply (cases \\<Sigma>)\n  apply (simp add: brec_step_def fifo_correct)\n  apply (case_tac \"fifo_\\<alpha> b\")\n  apply (simp \n    add: brec_invar_def distinct_tl brec_cond_def fifo_correct\n         )\n  apply (rule_tac s=b in fifo.removelE)\n  apply simp\n  apply simp\n  apply simp\n\n  apply (rule_tac \n    I=\"\\<lambda>it (Q,W,rcm,qwit). (Q,W,rcm,qwit)\\<in>brec_invar_add (hs_\\<alpha> Qi) \n                           \\<and> set (fifo_\\<alpha> W) \\<subseteq> dom (hm_\\<alpha> Q)\" \n    in ls.iterate_rule_P)\n  apply simp\n  apply (simp \n    add: brec_invar_def distinct_tl brec_cond_def fifo_correct\n         )\n  apply (simp \n    add: brec_invar_def brec_invar_add_def distinct_tl brec_cond_def \n         fifo_correct)\n  apply (case_tac \\<sigma>)\n  apply (auto \n    simp add: brec_invar_add_def brec_inner_step_def Let_def hs_correct \n              hm_correct fifo_correct split: option.split_asm) [1]\n  apply (case_tac \\<sigma>)\n  apply simp\n  done\n\nlemma brec_step_abs:\n  assumes RQRM: \"rqrm_invar rqrm\" \"rqrm_prop \\<delta> rqrm\"\n  assumes INV[simp]: \"hs_invar Qi\"\n  assumes A': \"\\<Sigma>\\<in>brec_invar (hs_\\<alpha> Qi) \\<delta>\"\n  assumes COND: \"brec_cond \\<Sigma>\"\n  shows \"(brec_\\<alpha> \\<Sigma>, brec_\\<alpha> (brec_step rqrm Qi \\<Sigma>)) \\<in> brw_step \\<delta>\"\nproof -\n  from A' have A: \"(brec_\\<alpha> \\<Sigma>)\\<in>brw_invar \\<delta>\" \"\\<Sigma>\\<in>brec_invar_add (hs_\\<alpha> Qi)\"\n    by (simp_all add: brec_invar_def)\n\n  obtain Q W rcm qwit where [simp]: \"\\<Sigma>=(Q,W,rcm,qwit)\" by (cases \\<Sigma>) blast\n  from A COND show ?thesis\n    apply (simp add: brec_step_def fifo_correct)\n    apply (case_tac \"fifo_\\<alpha> W\")\n    apply (simp \n      add: brec_invar_def distinct_tl brec_cond_def fifo_correct\n    )\n    apply (rule_tac s=W in fifo.removelE)\n    apply simp\n    apply simp\n    apply simp\n\n    apply (rule brw_inner_step_proof[\n      OF ls.v1_iteratei_impl, \n      where cinvar=\"\\<lambda>it \\<Sigma>. \\<Sigma>\\<in>brec_invar_inner (hs_\\<alpha> Qi)\" and \n            q=\"hd (fifo_\\<alpha> W)\"])\n    apply assumption\n    apply (frule brec_brw_invar_cons)\n    apply (simp_all \n      add: brec_cond_def brec_invar_add_def fifo_correct\n            brec_invar_inner_def) [1]\n    prefer 6\n    apply (simp add: brec_\\<alpha>_def)\n    apply (case_tac \\<Sigma>)\n    apply (auto \n      simp add: brec_invar_add_def brec_inner_step_def Let_def hm_correct \n                hs_correct fifo_correct brec_invar_inner_def \n      split: option.split_asm) [1]\n    apply (blast intro: brec_inner_step_brw_desc)\n    apply (simp add: RQRM[unfolded rqrm_invar_def])\n    apply (simp \n      add: rqrm_propD[OF RQRM(2)] fifo_correct)\n    apply (simp_all \n      add: brec_\\<alpha>_def brec_cond_def brec_invar_def fifo_correct) [1]\n    apply (simp_all \n      add: brec_\\<alpha>_def brec_cond_def brec_invar_add_def fifo_correct) [1]\n    done\nqed\n    \nlemma brec_invar_initial: \n  \"\\<lbrakk>ls_invar \\<delta>; hs_invar Qi\\<rbrakk> \\<Longrightarrow> (brec_initial Qi \\<delta>) \\<in> brec_invar_add (hs_\\<alpha> Qi)\"\n  apply (auto \n    simp add: brec_invar_add_def brec_initial_def brc_iq_correct \n              brec_iqm_correct' hs_correct hs.isEmpty_correct Let_def \n              brc_rcm_init_correct br_iq_def \n              hh_set_xx.disjoint_witness_correct \n              hs_to_fifo.g_set_to_listr_correct \n    split: option.split)\n  apply (auto simp add: brc_iq_correct \n    hh_set_xx.disjoint_witness_None br_iq_def) [1]\n\n  apply (drule hh_set_xx.disjoint_witness_correct[simplified])\n  apply simp\n\n  apply (drule hh_set_xx.disjoint_witness_correct[simplified])\n  apply (simp add: brc_iq_correct br_iq_def)\n  done\n\nlemma brec_cond_abs: \n  \"\\<lbrakk>\\<Sigma>\\<in>brec_invar Qi \\<delta>\\<rbrakk> \\<Longrightarrow> brec_cond \\<Sigma> \\<longleftrightarrow> (brec_\\<alpha> \\<Sigma>)\\<in>brw_cond Qi\"\n  apply (cases \\<Sigma>)\n  apply (auto \n    simp add: brec_cond_def brw_cond_def brec_\\<alpha>_def brec_invar_def \n              brec_invar_add_def fifo_correct\n    split: option.split_asm)\n  done\n\nlemma brec_initial_abs: \n  \"\\<lbrakk> ls_invar \\<delta>; hs_invar Qi \\<rbrakk> \n     \\<Longrightarrow> brec_\\<alpha> (brec_initial Qi \\<delta>) \\<in> brw_initial (ls_\\<alpha> \\<delta>)\"\n  by (auto simp add: brec_initial_def Let_def brec_\\<alpha>_def \n                     brc_iq_correct brc_rcm_init_correct brec_iqm_correct \n                     br_iq_def fifo_correct hs_to_fifo.g_set_to_listr_correct \n              intro: brw_initial.intros[unfolded br_iq_def])\n\nlemma brec_pref_brw:\n  assumes RQRM[simp]: \"rqrm_invar rqrm\" \"rqrm_prop (ls_\\<alpha> \\<delta>) rqrm\"\n  assumes INV[simp]: \"ls_invar \\<delta>\" \"hs_invar Qi\"\n  shows \"wa_precise_refine (det_wa_wa (brec_det_algo rqrm Qi \\<delta>)) \n                           (brw_algo (hs_\\<alpha> Qi) (ls_\\<alpha> \\<delta>))  \n                           brec_\\<alpha>\"\n  apply (unfold_locales)\n  apply (simp_all add: det_wa_wa_def brec_det_algo_def brw_algo_def)\n  apply (auto simp add: brec_cond_abs brec_step_abs brec_initial_abs)\n  apply (simp add: brec_invar_def)\n  done\n\nlemma brec_while_algo:\n  assumes RQRM[simp]: \"rqrm_invar rqrm\" \"rqrm_prop (ls_\\<alpha> \\<delta>) rqrm\"\n  assumes INV[simp]: \"ls_invar \\<delta>\" \"hs_invar Qi\"\n  shows \"while_algo (det_wa_wa (brec_det_algo rqrm Qi \\<delta>))\"\nproof -\n  interpret ref: \n    wa_precise_refine \"(det_wa_wa (brec_det_algo rqrm Qi \\<delta>))\" \n                      \"(brw_algo (hs_\\<alpha> Qi) (ls_\\<alpha> \\<delta>))\" \n                      \"brec_\\<alpha>\" \n    using brec_pref_brw[OF RQRM INV] . \n\n  show ?thesis\n    apply (rule ref.wa_intro)\n    apply (simp add: brw_while_algo)\n    apply (simp_all add: det_wa_wa_def brec_det_algo_def brw_algo_def)\n    apply (simp add: brec_invar_def)\n    apply (auto simp add: brec_step_invar[OF RQRM INV(2)]) [1]\n    apply (simp add: brec_invar_initial) [1]\n    done\nqed\n\nlemma fst_brec_\\<alpha>: \"fst (brec_\\<alpha> \\<Sigma>) = hm_\\<alpha> (fst \\<Sigma>)\"\n  by (cases \\<Sigma>) (simp add: brec_\\<alpha>_def)\n\nlemmas brec_invar_final = \n  wa_precise_refine.transfer_correctness[\n    OF brec_pref_brw brw_invar_final, \n    unfolded fst_brec_\\<alpha>]\n\nlemmas brec_det_algo = det_while_algo_intro[OF brec_while_algo]\n\ndefinition \"hta_is_empty_witness H == \n  let rqrm = build_rqrm (hta_\\<delta> H);\n      (Q,_,_,qwit) = (while brec_cond (brec_step rqrm (hta_Qi H)) \n                            (brec_initial (hta_Qi H) (hta_\\<delta> H))) \n  in\n    case qwit of \n      None \\<Rightarrow> None |\n      Some q \\<Rightarrow> (hm_lookup q Q)\n\"\n\ntheorem (in hashedTa) hta_is_empty_witness_correct:\n  shows [rule_format]: \"hta_is_empty_witness H = Some t \n                        \\<longrightarrow> t\\<in>ta_lang (hta_\\<alpha> H)\" (is ?T1)\n        \"hta_is_empty_witness H = None \\<longrightarrow> ta_lang (hta_\\<alpha> H) = {}\" (is ?T2)\nproof -\n\n  interpret det_while_algo \"(brec_det_algo (build_rqrm \\<delta>) Qi \\<delta>)\"\n    by (rule brec_det_algo)\n       (simp_all add: build_rqrm_correct)\n\n  have LC: \n    \"(while brec_cond (brec_step (build_rqrm \\<delta>) Qi) (brec_initial Qi \\<delta>)) = loop\"\n    by (unfold loop_def)\n       (simp add: brec_det_algo_def)\n\n  from while_proof'[OF brec_invar_final] have X:\n    \"hs_\\<alpha> Qi \\<inter> dom (hm_\\<alpha> (fst loop)) = {} \n     \\<longleftrightarrow> (hs_\\<alpha> Qi \\<inter> b_accessible (ls_\\<alpha> \\<delta>) = {})\"\n    \"witness_prop (ls_\\<alpha> \\<delta>) (hm_\\<alpha> (fst loop))\"\n    by (simp_all add: build_rqrm_correct)\n\n  obtain Q W rcm qwit where \n    [simp]: \"loop = (Q,W,rcm,qwit)\" \n    by (case_tac \"loop\") blast\n\n  from loop_invar have I: \"loop \\<in> brec_invar (hs_\\<alpha> Qi) (ls_\\<alpha> \\<delta>)\" \n    by (simp add: brec_det_algo_def)\n  hence INVARS[simp]: \"hm_invar Q\" \"hm_invar rcm\" \n    by (simp_all add: brec_invar_def brec_invar_add_def) \n  \n  {\n    assume C: \"hta_is_empty_witness H = Some t\"\n    then obtain q where \n      [simp]: \"qwit=Some q\" and \n        LUQ: \"hm_lookup q Q = Some t\"\n      by (unfold hta_is_empty_witness_def)\n         (simp add: LC split: option.split_asm)\n    from LUQ have QqF: \"hm_\\<alpha> Q q = Some t\" by (simp add: hm_correct)\n    from I have QMEM: \"q\\<in>hs_\\<alpha> Qi\" \n      by (simp_all add: brec_invar_def brec_invar_add_def)\n    moreover from witness_propD[OF X(2)] QqF have \"accs (ls_\\<alpha> \\<delta>) t q\" by simp\n    ultimately have \"t\\<in>ta_lang (hta_\\<alpha> H)\"\n      by (auto simp add: ta_lang_def hta_\\<alpha>_def)\n  } moreover {\n    assume C: \"hta_is_empty_witness H = None\"\n    hence DJ: \"hs_\\<alpha> Qi \\<inter> dom (hm_\\<alpha> Q) = {}\" using I\n      by (auto simp add: hta_is_empty_witness_def LC brec_invar_def \n                         brec_invar_add_def hm_correct \n               split: option.split_asm)\n    with X have \"hs_\\<alpha> Qi \\<inter> b_accessible (ls_\\<alpha> \\<delta>) = {}\" \n      by (simp add: brec_\\<alpha>_def)\n    with empty_if_no_b_accessible[of \"hta_\\<alpha> H\"] have \"ta_lang (hta_\\<alpha> H) = {}\"\n      by (simp add: hta_\\<alpha>_def)\n  } ultimately show ?T1 ?T2 by auto\nqed\n\nsubsection \\<open>Interface for Natural Number States and Symbols\\<close>\n  text_raw \\<open>\\label{sec:htai_intf}\\<close>\ntext \\<open>\n  The library-interface is statically instantiated to use natural numbers \n  as both, states and symbols.\n\n  This interface is easier to use from ML and OCaml, because there is no \n  overhead with typeclass emulation.\n\\<close>\n\ntype_synonym htai = \"(nat,nat) hashedTa\"\n\ndefinition htai_mem :: \"_ \\<Rightarrow> htai \\<Rightarrow> bool\" \n  where \"htai_mem == hta_mem\"\ndefinition htai_prod :: \"htai \\<Rightarrow> htai \\<Rightarrow> htai\" \n  where \"htai_prod H1 H2 == hta_reindex (hta_prod H1 H2)\"\ndefinition htai_prodWR :: \"htai \\<Rightarrow> htai \\<Rightarrow> htai\" \n  where \"htai_prodWR H1 H2 == hta_reindex (hta_prodWR H1 H2)\"\ndefinition htai_union :: \"htai \\<Rightarrow> htai \\<Rightarrow> htai\" \n  where \"htai_union H1 H2 == hta_reindex (hta_union H1 H2)\"\ndefinition htai_empty :: \"unit \\<Rightarrow> htai\"\n  where \"htai_empty == hta_empty\"\ndefinition htai_add_qi :: \"_ \\<Rightarrow> htai \\<Rightarrow> htai\" \n  where \"htai_add_qi == hta_add_qi\"\ndefinition htai_add_rule :: \"_ \\<Rightarrow> htai \\<Rightarrow> htai\" \n  where \"htai_add_rule == hta_add_rule\"\ndefinition htai_bwd_reduce :: \"htai \\<Rightarrow> htai\" \n  where \"htai_bwd_reduce == hta_bwd_reduce\"\ndefinition htai_is_empty_witness :: \"htai \\<Rightarrow> _\" \n  where \"htai_is_empty_witness == hta_is_empty_witness\"\ndefinition htai_ensure_idx_f :: \"htai \\<Rightarrow> htai\" \n  where \"htai_ensure_idx_f == hta_ensure_idx_f\"\ndefinition htai_ensure_idx_s :: \"htai \\<Rightarrow> htai\" \n  where \"htai_ensure_idx_s == hta_ensure_idx_s\"\ndefinition htai_ensure_idx_sf :: \"htai \\<Rightarrow> htai\" \n  where \"htai_ensure_idx_sf == hta_ensure_idx_sf\"\n\ndefinition htaip_prod :: \"htai \\<Rightarrow> htai \\<Rightarrow> (nat * nat,nat) hashedTa\" \n  where \"htaip_prod == hta_prod\"\ndefinition htaip_prodWR :: \"htai \\<Rightarrow> htai \\<Rightarrow> (nat * nat,nat) hashedTa\" \n  where \"htaip_prodWR == hta_prodWR\"\ndefinition htaip_reindex :: \"(nat * nat,nat) hashedTa \\<Rightarrow> htai\" \n  where \"htaip_reindex == hta_reindex\"\n\nlocale htai = hashedTa +\n  constrains H :: htai\nbegin\n  lemmas htai_mem_correct = hta_mem_correct[folded htai_mem_def]\n\n  lemma htai_empty_correct[simp]:\n    \"hta_\\<alpha> (htai_empty ()) = ta_empty\"\n    \"hashedTa (htai_empty ())\"\n  by (auto simp add: htai_empty_def hta_empty_correct)\n\n  lemmas htai_add_qi_correct = hta_add_qi_correct[folded htai_add_qi_def]\n  lemmas htai_add_rule_correct = hta_add_rule_correct[folded htai_add_rule_def]\n\n  lemmas htai_bwd_reduce_correct = \n    hta_bwd_reduce_correct[folded htai_bwd_reduce_def]\n  lemmas htai_is_empty_witness_correct = \n    hta_is_empty_witness_correct[folded htai_is_empty_witness_def]\n\n  lemmas htai_ensure_idx_f_correct = \n    hta_ensure_idx_f_correct[folded htai_ensure_idx_f_def]\n  lemmas htai_ensure_idx_s_correct = \n    hta_ensure_idx_s_correct[folded htai_ensure_idx_s_def]\n  lemmas htai_ensure_idx_sf_correct = \n    hta_ensure_idx_sf_correct[folded htai_ensure_idx_sf_def]\n\nend\n\nlemma htai_prod_correct:\n  assumes [simp]: \"hashedTa H1\" \"hashedTa H2\"\n  shows \n  \"ta_lang (hta_\\<alpha> (htai_prod H1 H2)) = ta_lang (hta_\\<alpha> H1) \\<inter> ta_lang (hta_\\<alpha> H2)\"\n  \"hashedTa (htai_prod H1 H2)\"\n  apply (unfold htai_prod_def)\n  apply (auto simp add: hta_prod_correct hashedTa.hta_reindex_correct)\n  done\n\nlemma htai_prodWR_correct:\n  assumes [simp]: \"hashedTa H1\" \"hashedTa H2\"\n  shows \n  \"ta_lang (hta_\\<alpha> (htai_prodWR H1 H2)) \n   = ta_lang (hta_\\<alpha> H1) \\<inter> ta_lang (hta_\\<alpha> H2)\"\n  \"hashedTa (htai_prodWR H1 H2)\"\n  apply (unfold htai_prodWR_def)\n  apply (auto simp add: hta_prodWR_correct hashedTa.hta_reindex_correct)\n  done\n\nlemma htai_union_correct:\n  assumes [simp]: \"hashedTa H1\" \"hashedTa H2\"\n  shows \n  \"ta_lang (hta_\\<alpha> (htai_union H1 H2)) \n   = ta_lang (hta_\\<alpha> H1) \\<union> ta_lang (hta_\\<alpha> H2)\"\n  \"hashedTa (htai_union H1 H2)\"\n  apply (unfold htai_union_def)\n  apply (auto simp add: hta_union_correct hashedTa.hta_reindex_correct)\n  done\n\nsubsection \\<open>Interface Documentation\\<close> text_raw\\<open>\\label{sec:intf_doc}\\<close>\ntext \\<open>\n  This section contains a documentation of the executable tree-automata\n  interface. The documentation contains a description of each function along\n  with the relevant correctness lemmas.\n\\<close>\n\ntext \\<open>\n  ML/OCaml users should note, that there is an interface that has the fixed type\n  Int for both states and function symbols. This interface is simpler to use\n  from ML/OCaml than the generic one, as it requires no overhead to emulate\n  Isabelle/HOL type-classes.\n\n  The functions of this interface start with the prefix {\\em htai} instead of\n  {\\em hta}, but have the same semantics otherwise \n  (cf Section~\\ref{sec:htai_intf}).\n\\<close>\n\nsubsubsection \\<open>Building a Tree Automaton\\<close>\ntext_raw \\<open>\n  \\newcommand{\\fundesc}[2]{{\\bf Function: #1}\\\\#2}\n\n\\<close>\n\ntext \\<open>\n  \\fundesc{@{const [show_types] hta_empty}}{\n    Returns a tree automaton with no states and no rules. \n  }\n  \n  \\paragraph{Relevant Lemmas}\n  \\begin{description}\n    \\item[@{thm [source] hta_empty_correct}:] @{thm hta_empty_correct[no_vars]}\n    \\item[@{thm [source] ta_empty_lang}:] @{thm ta_empty_lang[no_vars]}\n  \\end{description}\n\\<close>\n\ntext \\<open>\n  \\fundesc{@{const [show_types] hta_add_qi}}{\n    Adds an initial state to the given automaton.\n  }\n  \\paragraph{Relevant Lemmas}\n  \\begin{description}\n    \\item[@{thm [source] hashedTa.hta_add_qi_correct}]\n      @{thm hashedTa.hta_add_qi_correct[no_vars]}\n  \\end{description}\n\\<close>\n\ntext \\<open>\n  \\fundesc{@{const [show_types] hta_add_rule}}{\n    Adds a rule to the given automaton.\n  }\n  \\paragraph{Relevant Lemmas}\n  \\begin{description}\n    \\item[@{thm [source] hashedTa.hta_add_rule_correct}:]\n      @{thm hashedTa.hta_add_rule_correct[no_vars]}\n  \\end{description}\n\\<close>\n\nsubsubsection \\<open>Basic Operations\\<close>\n\ntext \\<open>\n  The tree automata of this library may have some optional indices, that \n  accelerate computation. The tree-automata operations will compute the \n  indices if necessary, but due to the pure nature of the Isabelle-language,\n  the computed index cannot be stored for the next usage. Hence, before using a\n  bulk of tree-automaton operations on the same tree-automata, the relevant \n  indexes should be pre-computed.\n\\<close>\n\ntext \\<open>\n  \\fundesc{\n    @{const [show_types] hta_ensure_idx_f}\\\\\n    @{const [show_types] hta_ensure_idx_s}\\\\\n    @{const [show_types] hta_ensure_idx_sf}\n  }{\n    Computes an index for a tree automaton, if it is not yet present.\n  }\n\\<close>\n\ntext \\<open>\n  \\fundesc{@{const [show_types] hta_mem}, @{const [show_types] hta_mem'}}{\n    Check whether a tree is accepted by the tree automaton.\n  }\n  \\paragraph{Relevant Lemmas}\n  \\begin{description}\n    \\item[@{thm [source] hashedTa.hta_mem_correct}:]\n      @{thm hashedTa.hta_mem_correct[no_vars]}\n    \\item[@{thm [source] hashedTa.hta_mem'_correct}:]\n      @{thm hashedTa.hta_mem'_correct[no_vars]}\n  \\end{description}\n\\<close>\n\ntext \\<open>\n  \\fundesc{@{const [show_types] hta_prod}, @{const [show_types] hta_prod'}}{\n    Compute the product automaton. The computed automaton is in \n    forward-reduced form. \n    The language of the product automaton is the intersection of \n    the languages of the two argument automata.\n  }\n  \\paragraph{Relevant Lemmas}\n  \\begin{description}\n    \\item[@{thm [source] hta_prod_correct_aux}:] \n      @{thm hta_prod_correct_aux[no_vars]}\n    \\item[@{thm [source] hta_prod_correct}:] \n      @{thm hta_prod_correct[no_vars]}\n    \\item[@{thm [source] hta_prod'_correct_aux}:] \n      @{thm hta_prod'_correct_aux[no_vars]}\n    \\item[@{thm [source] hta_prod'_correct}:] \n      @{thm hta_prod'_correct[no_vars]}\n  \\end{description}\n\\<close>\n\ntext \\<open>\n  \\fundesc{@{const [show_types] hta_prodWR}}{\n    Compute the product automaton by brute-force algorithm. \n    The resulting automaton is not reduced.\n    The language of the product automaton is the intersection of \n    the languages of the two argument automata.\n  }\n  \\paragraph{Relevant Lemmas}\n  \\begin{description}\n  \\item[@{thm [source] hta_prodWR_correct_aux}:]\n    @{thm hta_prodWR_correct_aux[no_vars]}\n  \\item[@{thm [source] hta_prodWR_correct}:] \n    @{thm hta_prodWR_correct[no_vars]}\n  \\end{description}\n\\<close>\n\ntext \\<open>\n  \\fundesc{@{const [show_types] hta_union}}{\n    Compute the union of two tree automata.\n  }\n  \\paragraph{Relevant Lemmas}\n  \\begin{description}\n  \\item[@{thm [source] hta_union_correct'}:] @{thm hta_union_correct'[no_vars]}\n  \\item[@{thm [source] hta_union_correct}:] @{thm hta_union_correct[no_vars]}\n  \\end{description}\n\\<close>\n\ntext \\<open>\n  \\fundesc{@{const [show_types] hta_reduce}}{\n    Reduce the automaton to the given set of states. All initial states outside\n    this set will be removed. Moreover, all rules that contain states outside \n    this set are removed, too.\n  }\n  \\paragraph{Relevant Lemmas}\n  \\begin{description}\n    \\item[@{thm [source] hashedTa.hta_reduce_correct}:]\n      @{thm hashedTa.hta_reduce_correct[no_vars]}\n  \\end{description}\n\\<close>\n\ntext \\<open>\n  \\fundesc{@{const [show_types] hta_bwd_reduce}}{\n    Compute the backwards-reduced version of a tree automata.\n    States from that no tree can be produced are removed. \n    Backwards reduction does not change the language of the automaton.\n  }\n  \\paragraph{Relevant Lemmas}\n  \\begin{description}\n    \\item[@{thm [source] hashedTa.hta_bwd_reduce_correct}:]\n      @{thm hashedTa.hta_bwd_reduce_correct[no_vars]}\n    \\item[@{thm [source] ta_reduce_b_acc}:] @{thm ta_reduce_b_acc[no_vars]}\n  \\end{description}\n\\<close>\n\ntext \\<open>\n  \\fundesc{@{const [show_types] hta_is_empty_witness}}{\n    Check whether the language of the automaton is empty.\n    If the language is not empty, a tree of the language is returned.\n\n    The following property is not (yet) formally proven, but should hold: \n    If a tree is returned, the language contains no tree with a smaller depth\n    than the returned one.\n  }\n  \\paragraph{Relevant Lemmas}\n  \\begin{description}\n    \\item[@{thm [source] hashedTa.hta_is_empty_witness_correct}:]\n       @{thm hashedTa.hta_is_empty_witness_correct[no_vars]}\n  \\end{description}\n\\<close>\n\nsubsection \\<open>Code Generation\\<close>\n\n(* TODO/FIXME: There seems to be no way to reference the project-directory,\n  in order to control the placement of the generated code files.\n  The code-generation in this file only dumps the generated code to standard output.\n  Hence it is safe to include this file from other projects.\n\n  Actual code generation is done in Ta_impl_codegen.thy\n  *)\n\nexport_code \n  hta_mem hta_mem' hta_prod hta_prod' hta_prodWR hta_union \n  hta_empty hta_add_qi hta_add_rule\n  hta_reduce hta_bwd_reduce hta_is_empty_witness\n  hta_ensure_idx_f hta_ensure_idx_s hta_ensure_idx_sf\n\n  htai_mem htai_prod htai_prodWR htai_union \n  htai_empty htai_add_qi htai_add_rule\n  htai_bwd_reduce htai_is_empty_witness\n  htai_ensure_idx_f htai_ensure_idx_s htai_ensure_idx_sf\n\n  (*ls_size hs_size rs_size*)\n  in SML \n  module_name Ta\n\n\nexport_code \n  hta_mem hta_mem' hta_prod hta_prod' hta_prodWR hta_union \n  hta_empty hta_add_qi hta_add_rule\n  hta_reduce hta_bwd_reduce hta_is_empty_witness\n  hta_ensure_idx_f hta_ensure_idx_s hta_ensure_idx_sf\n\n  htai_mem htai_prod htai_prodWR htai_union \n  htai_empty htai_add_qi htai_add_rule\n  htai_bwd_reduce htai_is_empty_witness\n  htai_ensure_idx_f htai_ensure_idx_s htai_ensure_idx_sf\n\n  (*ls_size hs_size rs_size*)\n  in Haskell \n  module_name Ta\n  (string_classes)\n\nexport_code \n  hta_mem hta_mem' hta_prod hta_prod' hta_prodWR hta_union \n  hta_empty hta_add_qi hta_add_rule\n  hta_reduce hta_bwd_reduce hta_is_empty_witness\n  hta_ensure_idx_f hta_ensure_idx_s hta_ensure_idx_sf\n\n  htai_mem htai_prod htai_prodWR htai_union \n  htai_empty htai_add_qi htai_add_rule\n  htai_bwd_reduce htai_is_empty_witness\n  htai_ensure_idx_f htai_ensure_idx_s htai_ensure_idx_sf\n\n  (*ls_size hs_size rs_size*)\n  in OCaml \n  module_name Ta\n\n(* If this statement fails with an error from ML, this indicates a problem \n  with the code-generator. The most frequent problem in this context is, that\n  the code generator generates code that violates the ML value-restriction.\n*)\n\nML \\<open>\n  @{code hta_mem};\n  @{code hta_mem'};\n  @{code hta_prod};\n  @{code hta_prod'};\n  @{code hta_prodWR};\n  @{code hta_union};\n  @{code hta_empty};\n  @{code hta_add_qi};\n  @{code hta_add_rule};\n  @{code hta_reduce};\n  @{code hta_bwd_reduce};\n  @{code hta_is_empty_witness};\n  @{code hta_ensure_idx_f};\n  @{code hta_ensure_idx_s};\n  @{code hta_ensure_idx_sf};\n  @{code htai_mem};\n  @{code htai_prod};\n  @{code htai_prodWR};\n  @{code htai_union};\n  @{code htai_empty};\n  @{code htai_add_qi};\n  @{code htai_add_rule};\n  @{code htai_bwd_reduce};\n  @{code htai_is_empty_witness};\n  @{code htai_ensure_idx_f};\n  @{code htai_ensure_idx_s};\n  @{code htai_ensure_idx_sf};\n  (*@{code ls_size};\n  @{code hs_size};\n  @{code rs_size}*)\n\\<close>\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Tree-Automata/Ta_impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5813030906443133, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.2770372241015032}}
{"text": "(*\n * Copyright (c) 2020, CleanQ Project - Systems Group, ETH Zurich\n * All rights reserved.\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n *\n * See \"LICENSE\" for details.\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\n\n\nsection \\<open>RB Model Simpl proofs\\<close>\n\ntext \\<open>\n  Due to problems importing both SIMPL and COMPLX we split the files and have all the proofs\n  using SIMPL in this file\n\\<close>\n\ntheory CleanQ_RBModel_Simpl\n(*<*) \n  imports Main \n    CleanQ_RB\n    CleanQ_RBModel\n    \"../Simpl/Vcg\"\n(*>*)  \nbegin\n\n(* ==================================================================================== *)\nsubsection \\<open>Integration in SIMPL\\<close>\n(* ==================================================================================== *)\n\nlemma CleanQ_RB_enq_x_preserves_invariants : \n  \"\\<Gamma>\\<turnstile> \\<lbrace> rb' = \\<acute>RingRB \\<and> CleanQ_RB_Invariants K \\<acute>RingRB \\<and> b \\<in> rSX \\<acute>RingRB \\<and> \n        CleanQ_RB_enq_x_possible \\<acute>RingRB \\<rbrace> \n        \\<acute>RingRB :== (CleanQ_RB_enq_x b \\<acute>RingRB) \n      \\<lbrace> CleanQ_RB_Invariants K \\<acute>RingRB \\<rbrace>\" \n  apply(vcg)\n  by (meson CleanQ_RB_enq_x_inv_all) \n\nlemma CleanQ_RB_enq_y_preserves_invariants : \n  \"\\<Gamma>\\<turnstile> \\<lbrace> rb' = \\<acute>RingRB \\<and> CleanQ_RB_Invariants K \\<acute>RingRB \\<and> b \\<in> rSY \\<acute>RingRB \\<and> \n        CleanQ_RB_enq_y_possible \\<acute>RingRB \\<rbrace> \n        \\<acute>RingRB :== (CleanQ_RB_enq_y b \\<acute>RingRB) \n      \\<lbrace> CleanQ_RB_Invariants K \\<acute>RingRB \\<rbrace>\" \n  apply(vcg)\n  by (meson CleanQ_RB_enq_y_inv_all) \n\nlemma CleanQ_RB_deq_x_preserves_invariants : \n  \"\\<Gamma>\\<turnstile> \\<lbrace> rb' = \\<acute>RingRB \\<and> CleanQ_RB_Invariants K \\<acute>RingRB \\<and> CleanQ_RB_deq_x_possible \\<acute>RingRB \\<rbrace> \n        \\<acute>RingRB :== (CleanQ_RB_deq_x \\<acute>RingRB) \n      \\<lbrace> CleanQ_RB_Invariants K \\<acute>RingRB \\<rbrace>\" \n  apply(vcg)\n  using CleanQ_RB_deq_x_all_inv by blast\n  \nlemma CleanQ_RB_deq_y_preserves_invariants : \n  \"\\<Gamma>\\<turnstile> \\<lbrace> rb' = \\<acute>RingRB \\<and> CleanQ_RB_Invariants K \\<acute>RingRB \\<and> CleanQ_RB_deq_y_possible \\<acute>RingRB \\<rbrace> \n        \\<acute>RingRB :== (CleanQ_RB_deq_y \\<acute>RingRB) \n      \\<lbrace> CleanQ_RB_Invariants K \\<acute>RingRB \\<rbrace>\" \n  apply(vcg)\n  using CleanQ_RB_deq_y_all_inv by blast\n\nend ", "meta": {"author": "CleanQ-Project", "repo": "cleanq-proofs", "sha": "5212fcd2aceba0028bd1474e0553578a6091ca63", "save_path": "github-repos/isabelle/CleanQ-Project-cleanq-proofs", "path": "github-repos/isabelle/CleanQ-Project-cleanq-proofs/cleanq-proofs-5212fcd2aceba0028bd1474e0553578a6091ca63/CleanQ/CleanQ_RBModel_Simpl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5583269943353745, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.2769825767168243}}
{"text": "(*  Title:      HOL/Auth/OtwayRees_Bad.thy\n    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory\n    Copyright   1996  University of Cambridge\n*)\n\n\nsection\\<open>The Otway-Rees Protocol: The Faulty BAN Version\\<close>\n\ntheory OtwayRees_Bad imports Public begin\n\ntext\\<open>The FAULTY version omitting encryption of Nonce NB, as suggested on \npage 247 of\n  Burrows, Abadi and Needham (1988).  A Logic of Authentication.\n  Proc. Royal Soc. 426\n\nThis file illustrates the consequences of such errors.  We can still prove\nimpressive-looking properties such as \\<open>Spy_not_see_encrypted_key\\<close>, yet\nthe protocol is open to a middleperson attack.  Attempting to prove some key\nlemmas indicates the possibility of this attack.\\<close>\n\ninductive_set otway :: \"event list set\"\n  where\n   Nil: \\<comment> \\<open>The empty trace\\<close>\n        \"[] \\<in> otway\"\n\n | Fake: \\<comment> \\<open>The Spy may say anything he can say.  The sender field is correct,\n            but agents don't use that information.\\<close>\n         \"\\<lbrakk>evsf \\<in> otway;  X \\<in> synth (analz (knows Spy evsf))\\<rbrakk>\n          \\<Longrightarrow> Says Spy B X  # evsf \\<in> otway\"\n\n        \n | Reception: \\<comment> \\<open>A message that has been sent can be received by the\n                  intended recipient.\\<close>\n              \"\\<lbrakk>evsr \\<in> otway;  Says A B X \\<in>set evsr\\<rbrakk>\n               \\<Longrightarrow> Gets B X # evsr \\<in> otway\"\n\n | OR1:  \\<comment> \\<open>Alice initiates a protocol run\\<close>\n         \"\\<lbrakk>evs1 \\<in> otway;  Nonce NA \\<notin> used evs1\\<rbrakk>\n          \\<Longrightarrow> Says A B \\<lbrace>Nonce NA, Agent A, Agent B,\n                         Crypt (shrK A) \\<lbrace>Nonce NA, Agent A, Agent B\\<rbrace>\\<rbrace>\n                 # evs1 \\<in> otway\"\n\n | OR2:  \\<comment> \\<open>Bob's response to Alice's message.\n             This variant of the protocol does NOT encrypt NB.\\<close>\n         \"\\<lbrakk>evs2 \\<in> otway;  Nonce NB \\<notin> used evs2;\n             Gets B \\<lbrace>Nonce NA, Agent A, Agent B, X\\<rbrace> \\<in> set evs2\\<rbrakk>\n          \\<Longrightarrow> Says B Server\n                  \\<lbrace>Nonce NA, Agent A, Agent B, X, Nonce NB,\n                    Crypt (shrK B) \\<lbrace>Nonce NA, Agent A, Agent B\\<rbrace>\\<rbrace>\n                 # evs2 \\<in> otway\"\n\n | OR3:  \\<comment> \\<open>The Server receives Bob's message and checks that the three NAs\n           match.  Then he sends a new session key to Bob with a packet for\n           forwarding to Alice.\\<close>\n         \"\\<lbrakk>evs3 \\<in> otway;  Key KAB \\<notin> used evs3;\n             Gets Server\n                  \\<lbrace>Nonce NA, Agent A, Agent B,\n                    Crypt (shrK A) \\<lbrace>Nonce NA, Agent A, Agent B\\<rbrace>,\n                    Nonce NB,\n                    Crypt (shrK B) \\<lbrace>Nonce NA, Agent A, Agent B\\<rbrace>\\<rbrace>\n               \\<in> set evs3\\<rbrakk>\n          \\<Longrightarrow> Says Server B\n                  \\<lbrace>Nonce NA,\n                    Crypt (shrK A) \\<lbrace>Nonce NA, Key KAB\\<rbrace>,\n                    Crypt (shrK B) \\<lbrace>Nonce NB, Key KAB\\<rbrace>\\<rbrace>\n                 # evs3 \\<in> otway\"\n\n | OR4:  \\<comment> \\<open>Bob receives the Server's (?) message and compares the Nonces with\n             those in the message he previously sent the Server.\n             Need \\<^term>\\<open>B \\<noteq> Server\\<close> because we allow messages to self.\\<close>\n         \"\\<lbrakk>evs4 \\<in> otway;  B \\<noteq> Server;\n             Says B Server \\<lbrace>Nonce NA, Agent A, Agent B, X', Nonce NB,\n                             Crypt (shrK B) \\<lbrace>Nonce NA, Agent A, Agent B\\<rbrace>\\<rbrace>\n               \\<in> set evs4;\n             Gets B \\<lbrace>Nonce NA, X, Crypt (shrK B) \\<lbrace>Nonce NB, Key K\\<rbrace>\\<rbrace>\n               \\<in> set evs4\\<rbrakk>\n          \\<Longrightarrow> Says B A \\<lbrace>Nonce NA, X\\<rbrace> # evs4 \\<in> otway\"\n\n | Oops: \\<comment> \\<open>This message models possible leaks of session keys.  The nonces\n             identify the protocol run.\\<close>\n         \"\\<lbrakk>evso \\<in> otway;\n             Says Server B \\<lbrace>Nonce NA, X, Crypt (shrK B) \\<lbrace>Nonce NB, Key K\\<rbrace>\\<rbrace>\n               \\<in> set evso\\<rbrakk>\n          \\<Longrightarrow> Notes Spy \\<lbrace>Nonce NA, Nonce NB, Key K\\<rbrace> # evso \\<in> otway\"\n\n\ndeclare Says_imp_knows_Spy [THEN analz.Inj, dest]\ndeclare parts.Body  [dest]\ndeclare analz_into_parts [dest]\ndeclare Fake_parts_insert_in_Un  [dest]\n\ntext\\<open>A \"possibility property\": there are traces that reach the end\\<close>\nlemma \"\\<lbrakk>B \\<noteq> Server; Key K \\<notin> used []\\<rbrakk>\n      \\<Longrightarrow> \\<exists>NA. \\<exists>evs \\<in> otway.\n            Says B A \\<lbrace>Nonce NA, Crypt (shrK A) \\<lbrace>Nonce NA, Key K\\<rbrace>\\<rbrace>\n              \\<in> set evs\"\napply (intro exI bexI)\napply (rule_tac [2] otway.Nil\n                    [THEN otway.OR1, THEN otway.Reception,\n                     THEN otway.OR2, THEN otway.Reception,\n                     THEN otway.OR3, THEN otway.Reception, THEN otway.OR4])\napply (possibility, simp add: used_Cons) \ndone\n\nlemma Gets_imp_Says [dest!]:\n     \"\\<lbrakk>Gets B X \\<in> set evs; evs \\<in> otway\\<rbrakk> \\<Longrightarrow> \\<exists>A. Says A B X \\<in> set evs\"\napply (erule rev_mp)\napply (erule otway.induct, auto)\ndone\n\n\nsubsection\\<open>For reasoning about the encrypted portion of messages\\<close>\n\nlemma OR2_analz_knows_Spy:\n     \"\\<lbrakk>Gets B \\<lbrace>N, Agent A, Agent B, X\\<rbrace> \\<in> set evs;  evs \\<in> otway\\<rbrakk>\n      \\<Longrightarrow> X \\<in> analz (knows Spy evs)\"\nby blast\n\nlemma OR4_analz_knows_Spy:\n     \"\\<lbrakk>Gets B \\<lbrace>N, X, Crypt (shrK B) X'\\<rbrace> \\<in> set evs;  evs \\<in> otway\\<rbrakk>\n      \\<Longrightarrow> X \\<in> analz (knows Spy evs)\"\nby blast\n\nlemma Oops_parts_knows_Spy:\n     \"Says Server B \\<lbrace>NA, X, Crypt K' \\<lbrace>NB,K\\<rbrace>\\<rbrace> \\<in> set evs\n      \\<Longrightarrow> K \\<in> parts (knows Spy evs)\"\nby blast\n\ntext\\<open>Forwarding lemma: see comments in OtwayRees.thy\\<close>\nlemmas OR2_parts_knows_Spy =\n    OR2_analz_knows_Spy [THEN analz_into_parts]\n\n\ntext\\<open>Theorems of the form \\<^term>\\<open>X \\<notin> parts (spies evs)\\<close> imply that\nNOBODY sends messages containing X!\\<close>\n\ntext\\<open>Spy never sees a good agent's shared key!\\<close>\nlemma Spy_see_shrK [simp]:\n     \"evs \\<in> otway \\<Longrightarrow> (Key (shrK A) \\<in> parts (knows Spy evs)) = (A \\<in> bad)\"\nby (erule otway.induct, force,\n    drule_tac [4] OR2_parts_knows_Spy, simp_all, blast+)\n\n\nlemma Spy_analz_shrK [simp]:\n     \"evs \\<in> otway \\<Longrightarrow> (Key (shrK A) \\<in> analz (knows Spy evs)) = (A \\<in> bad)\"\nby auto\n\nlemma Spy_see_shrK_D [dest!]:\n     \"\\<lbrakk>Key (shrK A) \\<in> parts (knows Spy evs);  evs \\<in> otway\\<rbrakk> \\<Longrightarrow> A \\<in> bad\"\nby (blast dest: Spy_see_shrK)\n\n\nsubsection\\<open>Proofs involving analz\\<close>\n\ntext\\<open>Describes the form of K and NA when the Server sends this message.  Also\n  for Oops case.\\<close>\nlemma Says_Server_message_form:\n     \"\\<lbrakk>Says Server B \\<lbrace>NA, X, Crypt (shrK B) \\<lbrace>NB, Key K\\<rbrace>\\<rbrace> \\<in> set evs;\n         evs \\<in> otway\\<rbrakk>\n      \\<Longrightarrow> K \\<notin> range shrK \\<and> (\\<exists>i. NA = Nonce i) \\<and> (\\<exists>j. NB = Nonce j)\"\napply (erule rev_mp)\napply (erule otway.induct, simp_all)\ndone\n\n\n(****\n The following is to prove theorems of the form\n\n  Key K \\<in> analz (insert (Key KAB) (knows Spy evs)) \\<Longrightarrow>\n  Key K \\<in> analz (knows Spy evs)\n\n A more general formula must be proved inductively.\n****)\n\n\ntext\\<open>Session keys are not used to encrypt other session keys\\<close>\n\ntext\\<open>The equality makes the induction hypothesis easier to apply\\<close>\nlemma analz_image_freshK [rule_format]:\n \"evs \\<in> otway \\<Longrightarrow>\n   \\<forall>K KK. KK \\<subseteq> -(range shrK) \\<longrightarrow>\n          (Key K \\<in> analz (Key`KK \\<union> (knows Spy evs))) =\n          (K \\<in> KK | Key K \\<in> analz (knows Spy evs))\"\napply (erule otway.induct)\napply (frule_tac [8] Says_Server_message_form)\napply (drule_tac [7] OR4_analz_knows_Spy)\napply (drule_tac [5] OR2_analz_knows_Spy, analz_freshK, spy_analz, auto) \ndone\n\nlemma analz_insert_freshK:\n  \"\\<lbrakk>evs \\<in> otway;  KAB \\<notin> range shrK\\<rbrakk> \\<Longrightarrow>\n      (Key K \\<in> analz (insert (Key KAB) (knows Spy evs))) =\n      (K = KAB | Key K \\<in> analz (knows Spy evs))\"\nby (simp only: analz_image_freshK analz_image_freshK_simps)\n\n\ntext\\<open>The Key K uniquely identifies the Server's  message.\\<close>\nlemma unique_session_keys:\n     \"\\<lbrakk>Says Server B \\<lbrace>NA, X, Crypt (shrK B) \\<lbrace>NB, K\\<rbrace>\\<rbrace>   \\<in> set evs;\n         Says Server B' \\<lbrace>NA',X',Crypt (shrK B') \\<lbrace>NB',K\\<rbrace>\\<rbrace> \\<in> set evs;\n         evs \\<in> otway\\<rbrakk> \\<Longrightarrow> X=X' \\<and> B=B' \\<and> NA=NA' \\<and> NB=NB'\"\napply (erule rev_mp)\napply (erule rev_mp)\napply (erule otway.induct, simp_all)\napply blast+  \\<comment> \\<open>OR3 and OR4\\<close>\ndone\n\n\ntext\\<open>Crucial secrecy property: Spy does not see the keys sent in msg OR3\n    Does not in itself guarantee security: an attack could violate\n    the premises, e.g. by having \\<^term>\\<open>A=Spy\\<close>\\<close>\nlemma secrecy_lemma:\n \"\\<lbrakk>A \\<notin> bad;  B \\<notin> bad;  evs \\<in> otway\\<rbrakk>\n  \\<Longrightarrow> Says Server B\n        \\<lbrace>NA, Crypt (shrK A) \\<lbrace>NA, Key K\\<rbrace>,\n          Crypt (shrK B) \\<lbrace>NB, Key K\\<rbrace>\\<rbrace> \\<in> set evs \\<longrightarrow>\n      Notes Spy \\<lbrace>NA, NB, Key K\\<rbrace> \\<notin> set evs \\<longrightarrow>\n      Key K \\<notin> analz (knows Spy evs)\"\napply (erule otway.induct, force)\napply (frule_tac [7] Says_Server_message_form)\napply (drule_tac [6] OR4_analz_knows_Spy)\napply (drule_tac [4] OR2_analz_knows_Spy)\napply (simp_all add: analz_insert_eq analz_insert_freshK pushes)\napply spy_analz  \\<comment> \\<open>Fake\\<close>\napply (blast dest: unique_session_keys)+  \\<comment> \\<open>OR3, OR4, Oops\\<close>\ndone\n\n\nlemma Spy_not_see_encrypted_key:\n     \"\\<lbrakk>Says Server B\n          \\<lbrace>NA, Crypt (shrK A) \\<lbrace>NA, Key K\\<rbrace>,\n                Crypt (shrK B) \\<lbrace>NB, Key K\\<rbrace>\\<rbrace> \\<in> set evs;\n         Notes Spy \\<lbrace>NA, NB, Key K\\<rbrace> \\<notin> set evs;\n         A \\<notin> bad;  B \\<notin> bad;  evs \\<in> otway\\<rbrakk>\n      \\<Longrightarrow> Key K \\<notin> analz (knows Spy evs)\"\nby (blast dest: Says_Server_message_form secrecy_lemma)\n\n\nsubsection\\<open>Attempting to prove stronger properties\\<close>\n\ntext\\<open>Only OR1 can have caused such a part of a message to appear. The premise\n  \\<^term>\\<open>A \\<noteq> B\\<close> prevents OR2's similar-looking cryptogram from being picked \n  up. Original Otway-Rees doesn't need it.\\<close>\nlemma Crypt_imp_OR1 [rule_format]:\n     \"\\<lbrakk>A \\<notin> bad;  A \\<noteq> B;  evs \\<in> otway\\<rbrakk>\n      \\<Longrightarrow> Crypt (shrK A) \\<lbrace>NA, Agent A, Agent B\\<rbrace> \\<in> parts (knows Spy evs) \\<longrightarrow>\n          Says A B \\<lbrace>NA, Agent A, Agent B,\n                     Crypt (shrK A) \\<lbrace>NA, Agent A, Agent B\\<rbrace>\\<rbrace>  \\<in> set evs\"\nby (erule otway.induct, force,\n    drule_tac [4] OR2_parts_knows_Spy, simp_all, blast+)\n\n\ntext\\<open>Crucial property: If the encrypted message appears, and A has used NA\n  to start a run, then it originated with the Server!\n  The premise \\<^term>\\<open>A \\<noteq> B\\<close> allows use of \\<open>Crypt_imp_OR1\\<close>\\<close>\ntext\\<open>Only it is FALSE.  Somebody could make a fake message to Server\n          substituting some other nonce NA' for NB.\\<close>\nlemma \"\\<lbrakk>A \\<notin> bad;  A \\<noteq> B;  evs \\<in> otway\\<rbrakk>\n       \\<Longrightarrow> Crypt (shrK A) \\<lbrace>NA, Key K\\<rbrace> \\<in> parts (knows Spy evs) \\<longrightarrow>\n           Says A B \\<lbrace>NA, Agent A, Agent B,\n                      Crypt (shrK A) \\<lbrace>NA, Agent A, Agent B\\<rbrace>\\<rbrace>\n            \\<in> set evs \\<longrightarrow>\n           (\\<exists>B NB. Says Server B\n                \\<lbrace>NA,\n                  Crypt (shrK A) \\<lbrace>NA, Key K\\<rbrace>,\n                  Crypt (shrK B) \\<lbrace>NB, Key K\\<rbrace>\\<rbrace> \\<in> set evs)\"\napply (erule otway.induct, force,\n       drule_tac [4] OR2_parts_knows_Spy, simp_all)\napply blast  \\<comment> \\<open>Fake\\<close>\napply blast  \\<comment> \\<open>OR1: it cannot be a new Nonce, contradiction.\\<close>\ntxt\\<open>OR3 and OR4\\<close>\napply (simp_all add: ex_disj_distrib)\n prefer 2 apply (blast intro!: Crypt_imp_OR1)  \\<comment> \\<open>OR4\\<close>\ntxt\\<open>OR3\\<close>\napply clarify\n(*The hypotheses at this point suggest an attack in which nonce NB is used\n  in two different roles:\n          Gets Server\n           \\<lbrace>Nonce NA, Agent Aa, Agent A,\n             Crypt (shrK Aa) \\<lbrace>Nonce NA, Agent Aa, Agent A\\<rbrace>, Nonce NB,\n             Crypt (shrK A) \\<lbrace>Nonce NA, Agent Aa, Agent A\\<rbrace>\\<rbrace>\n          \\<in> set evs3\n          Says A B\n           \\<lbrace>Nonce NB, Agent A, Agent B,\n             Crypt (shrK A) \\<lbrace>Nonce NB, Agent A, Agent B\\<rbrace>\\<rbrace>\n          \\<in> set evs3;\n*)\n\n\n(*Thus the key property A_can_trust probably fails too.*)\noops\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/Auth/OtwayRees_Bad.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5583269943353744, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.27698257671682425}}
{"text": "section \\<open>Example\\<close>\n\ntext \\<open>We provide an example in order to prove that our locale is non-vacuous.\nThis example corresponds to the computation and associated snapshot described\nin Section 4 of~\\cite{chandy}.\\<close>\n\ntheory Example\n  imports\n    Snapshot\n\nbegin\n\ndatatype PType = P | Q\ndatatype MType = M | M'\ndatatype SType = S_Wait | S_Send | T_Wait | T_Send\n\nfun trans :: \"PType \\<Rightarrow> SType \\<Rightarrow> SType \\<Rightarrow> bool\" where\n  \"trans p s s' = False\"\n\nfun send :: \"channel_id \\<Rightarrow> PType \\<Rightarrow> PType \\<Rightarrow> SType\n             \\<Rightarrow> SType \\<Rightarrow> MType \\<Rightarrow> bool\" where\n  \"send c p q s s' m = ((c = 0 \\<and> p = P \\<and> q = Q\n                          \\<and> s = S_Send \\<and> s' = S_Wait \\<and> m = M)\n                     \\<or> (c = 1 \\<and> p = Q \\<and> q = P\n                          \\<and> s = T_Send \\<and> s' = T_Wait \\<and> m = M'))\"\n\nfun recv :: \"channel_id \\<Rightarrow> PType \\<Rightarrow> PType \\<Rightarrow> SType\n             \\<Rightarrow> SType \\<Rightarrow> MType \\<Rightarrow> bool\" where\n  \"recv c p q s s' m = ((c = 1 \\<and> p = P \\<and> q = Q\n                          \\<and> s = S_Wait \\<and> s' = S_Send \\<and> m = M')\n                     \\<or> (c = 0 \\<and> p = Q \\<and> q = P\n                          \\<and> s = T_Wait \\<and> s' = T_Send \\<and> m = M))\"\n\nfun chan :: \"nat \\<Rightarrow> (PType * PType) option\" where\n \"chan n = (if n = 0 then Some (P, Q)\n            else if n = 1 then Some (Q, P)\n            else None)\"\n\nabbreviation init :: \"(PType, SType, MType) configuration\" where\n  \"init \\<equiv> \\<lparr>\n       states = (%p. if p = P then S_Send else T_Send),\n       msgs = (%d. []),\n       process_snapshot = (%p. None),\n       channel_snapshot = (%d. ([], NotStarted))\n    \\<rparr>\"\n\nabbreviation t0 where \"t0 \\<equiv> Snapshot P\"\n\nabbreviation s1 :: \"(PType, SType, MType) configuration\" where\n  \"s1 \\<equiv> \\<lparr>\n       states = (%p. if p = P then S_Send else T_Send),\n       msgs = (%d. if d = 0 then [Marker] else []),\n       process_snapshot = (%p. if p = P then Some S_Send else None),\n       channel_snapshot = (%d. if d = 1 then ([], Recording) else ([], NotStarted))\n    \\<rparr>\"\n\nabbreviation t1 where \"t1 \\<equiv> Send 0 P Q S_Send S_Wait M\"\n\nabbreviation s2 :: \"(PType, SType, MType) configuration\" where\n  \"s2 \\<equiv> \\<lparr>\n       states = (%p. if p = P then S_Wait else T_Send),\n       msgs = (%d. if d = 0 then [Marker, Msg M] else []),\n       process_snapshot = (%p. if p = P then Some S_Send else None),\n       channel_snapshot = (%d. if d = 1 then ([], Recording) else ([], NotStarted))\n    \\<rparr>\"\n\nabbreviation t2 where \"t2 \\<equiv> Send 1 Q P T_Send T_Wait M'\"\n\nabbreviation s3 :: \"(PType, SType, MType) configuration\" where\n  \"s3 \\<equiv> \\<lparr>\n       states = (%p. if p = P then S_Wait else T_Wait),\n       msgs = (%d. if d = 0 then [Marker, Msg M] else if d = 1 then [Msg M'] else []),\n       process_snapshot = (%p. if p = P then Some S_Send else None),\n       channel_snapshot = (%d. if d = 1 then ([], Recording) else ([], NotStarted))\n    \\<rparr>\"\n\nabbreviation t3 where \"t3 \\<equiv> Snapshot Q\"\n\nabbreviation s4 :: \"(PType, SType, MType) configuration\" where\n  \"s4 \\<equiv> \\<lparr>\n       states = (%p. if p = P then S_Wait else T_Wait),\n       msgs = (%d. if d = 0 then [Marker, Msg M] else if d = 1 then [Msg M', Marker] else []),\n       process_snapshot = (%p. if p = P then Some S_Send else Some T_Wait),\n       channel_snapshot = (%d. if d = 1 then ([], Recording) else if d = 0 then ([], Recording) else ([], NotStarted))\n    \\<rparr>\"\n\nabbreviation t4 where \"t4 \\<equiv> RecvMarker 0 Q P\"\n\nabbreviation s5 :: \"(PType, SType, MType) configuration\" where\n  \"s5 \\<equiv> \\<lparr>\n       states = (%p. if p = P then S_Wait else T_Wait),\n       msgs = (%d. if d = 0 then [Msg M] else if d = 1 then [Msg M', Marker] else []),\n       process_snapshot = (%p. if p = P then Some S_Send else Some T_Wait),\n       channel_snapshot = (%d. if d = 0 then ([], Done) else if d = 1 then ([], Recording) else ([], NotStarted))\n    \\<rparr>\"\n\nabbreviation t5 where \"t5 \\<equiv> Recv 1 P Q S_Wait S_Send M'\"\n\nabbreviation s6 :: \"(PType, SType, MType) configuration\" where\n  \"s6 \\<equiv> \\<lparr>\n       states = (%p. if p = P then S_Send else T_Wait),\n       msgs = (%d. if d = 0 then [Msg M] else if d = 1 then [Marker] else []),\n       process_snapshot = (%p. if p = P then Some S_Send else Some T_Wait),\n       channel_snapshot = (%d. if d = 0 then ([], Done) else if d = 1 then ([M'], Recording) else ([], NotStarted))\n    \\<rparr>\"\n\nabbreviation t6 where \"t6 \\<equiv> RecvMarker 1 P Q\"\n\nabbreviation s7 :: \"(PType, SType, MType) configuration\" where\n  \"s7 \\<equiv> \\<lparr>\n       states = (%p. if p = P then S_Send else T_Wait),\n       msgs = (%d. if d = 0 then [Msg M] else if d = 1 then [] else []),\n       process_snapshot = (%p. if p = P then Some S_Send else Some T_Wait),\n       channel_snapshot = (%d. if d = 0 then ([], Done) else if d = 1 then ([M'], Done) else ([], NotStarted))\n    \\<rparr>\"\n\nlemma s7_no_marker:\n  shows\n    \"\\<forall>cid. Marker \\<notin> set (msgs s7 cid)\"\n  by simp\n\ninterpretation computation chan trans send recv init s7\nproof\n  have \"distributed_system chan\"\n  proof\n    show \"\\<forall>i. \\<nexists>p. chan i = Some (p, p)\" by simp\n  qed\n  show \"\\<forall>p q. p \\<noteq> q \\<longrightarrow> (\\<lambda>p q. \\<exists>i. chan i = Some (p, q))\\<^sup>+\\<^sup>+ p q\"\n  proof ((rule allI)+, rule impI)\n    fix p q :: PType assume \"p \\<noteq> q\"\n    then have \"(p = P \\<and> q = Q) \\<or> (p = Q \\<and> q = P)\"\n      using PType.exhaust by auto\n    then have \"\\<exists>i. chan i = Some (p, q)\" by (elim disjE) auto\n    then show \"(\\<lambda>p q. \\<exists>i. chan i = Some (p, q))\\<^sup>+\\<^sup>+ p q\" by blast\n  qed\n  show \"finite {i. \\<exists>p q. chan i = Some (p, q)}\"\n  proof -\n    have \"{i. \\<exists>p q. chan i = Some (p, q)} = {0,1}\" by auto\n    then show ?thesis by simp\n  qed\n  show \"1 < card (UNIV :: PType set)\"\n  proof -\n    have \"(UNIV :: PType set) = {P, Q}\"\n      using PType.exhaust by blast\n    then have \"card (UNIV :: PType set) = 2\" \n      by (metis One_nat_def PType.distinct(1) Suc_1 card.insert card_empty finite.emptyI finite.insertI insert_absorb insert_not_empty singletonD)\n    then show ?thesis by auto\n  qed\n  show \"finite (UNIV :: PType set)\"\n  proof -\n    have \"(UNIV :: PType set) = {P, Q}\"\n      using PType.exhaust by blast\n    then show ?thesis \n      by (metis finite.emptyI finite.insertI)\n  qed\n  show \"\\<forall>i. \\<nexists>p. chan i = Some (p, p)\" by simp\n  show \"\\<forall>i. (\\<exists>p q. chan i = Some (p, q)) \\<longrightarrow> Marker \\<notin> set (msgs init i)\" by auto\n  show \"\\<forall>i. chan i = None \\<longrightarrow> msgs init i = []\" by auto\n  show \"\\<forall>p. \\<not> ps init p \\<noteq> None\" by auto\n  show \"\\<forall>i. cs init i = ([], NotStarted)\" by auto\n  show \"\\<exists>t. distributed_system.trace chan Example.trans send recv init t s7\"\n  proof -\n    let ?t = \"[t0, t1, t2, t3, t4, t5, t6]\"\n    have \"distributed_system.next chan trans send recv init t0 s1\"\n    proof -\n      have \"distributed_system.can_occur chan trans send recv t0 init\"\n        using \\<open>distributed_system chan\\<close> distributed_system.can_occur_def by fastforce\n      then show ?thesis \n        by (simp add: \\<open>distributed_system chan\\<close> distributed_system.next_snapshot)\n    qed\n    moreover have \"distributed_system.next chan trans send recv s1 t1 s2\"\n    proof -\n      have \"distributed_system.can_occur chan trans send recv t1 s1\"\n        using \\<open>distributed_system chan\\<close> distributed_system.can_occur_def by fastforce\n      then show ?thesis \n        by (simp add: \\<open>distributed_system chan\\<close> distributed_system.next_send)\n    qed\n    moreover have \"distributed_system.next chan trans send recv s2 t2 s3\"\n    proof -\n      have \"distributed_system.can_occur chan trans send recv t2 s2\"\n        using \\<open>distributed_system chan\\<close> distributed_system.can_occur_def by fastforce\n      moreover have \"\\<forall>r. r \\<noteq> P \\<longrightarrow> r = Q\" using PType.exhaust by auto\n      ultimately show ?thesis by (simp add: `distributed_system chan` distributed_system.next_send)\n    qed\n    moreover have \"distributed_system.next chan trans send recv s3 t3 s4\"\n    proof -\n      have \"distributed_system.can_occur chan trans send recv t3 s3\"\n        using \\<open>distributed_system chan\\<close> distributed_system.can_occur_def by fastforce\n      moreover have \"\\<forall>p'. p' \\<noteq> P \\<longrightarrow> p' = Q\" using PType.exhaust by auto\n      ultimately show ?thesis by (simp add: `distributed_system chan` distributed_system.next_snapshot)\n    qed\n    moreover have \"distributed_system.next chan trans send recv s4 t4 s5\"\n    proof -\n      have \"distributed_system.can_occur chan trans send recv t4 s4\"\n        using \\<open>distributed_system chan\\<close> distributed_system.can_occur_def by fastforce\n      then show ?thesis\n        by (simp add: `distributed_system chan` distributed_system.next_def)\n    qed\n    moreover have \"distributed_system.next chan trans send recv s5 t5 s6\"\n    proof -\n      have \"distributed_system.can_occur chan trans send recv t5 s5\"\n        using \\<open>distributed_system chan\\<close> distributed_system.can_occur_def by fastforce\n      then show ?thesis\n        by (simp add: `distributed_system chan` distributed_system.next_def)\n    qed\n    moreover have \"distributed_system.next chan trans send recv s6 t6 s7\"\n    proof -\n      have \"distributed_system.can_occur chan trans send recv t6 s6\"\n        using \\<open>distributed_system chan\\<close> distributed_system.can_occur_def by fastforce\n      then show ?thesis\n        by (simp add: `distributed_system chan` distributed_system.next_def)\n    qed\n    ultimately have \"distributed_system.trace chan trans send recv init ?t s7\" \n      by (meson \\<open>distributed_system chan\\<close> distributed_system.trace.simps)\n    then show ?thesis by blast\n  qed\n  show \"\\<forall>t i cid. distributed_system.trace chan Example.trans send recv init t s7 \\<and>\n       Marker \\<in> set (msgs (distributed_system.s chan Example.trans send recv init t i) cid) \\<longrightarrow>\n       (\\<exists>j\\<ge>i. Marker \\<notin> set (msgs (distributed_system.s chan Example.trans send recv init t j) cid))\"\n  proof ((rule allI)+, (rule impI)+)\n    fix t i cid\n    assume asm: \"distributed_system.trace chan Example.trans send recv init t s7 \\<and>\n                 Marker \\<in> set (msgs (distributed_system.s chan Example.trans send recv init t i) cid)\"\n    have tr_exists: \"distributed_system.trace chan Example.trans send recv init t s7\" using asm by blast\n    have marker_in_channel: \"Marker \\<in> set (msgs (distributed_system.s chan Example.trans send recv init t i) cid)\" using asm by simp\n    have s7_is_fin: \"s7 = (distributed_system.s chan Example.trans send recv init t (length t))\" \n      by (metis (no_types, lifting) \\<open>distributed_system chan\\<close> \\<open>distributed_system.trace chan Example.trans send recv init t s7\\<close> distributed_system.exists_trace_for_any_i distributed_system.trace_and_start_determines_end order_refl take_all)\n    have \"i < length t\"\n    proof (rule ccontr)\n      assume \"~ i < length t\"\n      then have \"distributed_system.trace chan Example.trans send recv\n                (distributed_system.s chan Example.trans send recv init t (length t))\n                []\n                (distributed_system.s chan Example.trans send recv init t i)\" \n        by (metis (no_types, lifting) \\<open>distributed_system chan\\<close> distributed_system.exists_trace_for_any_i distributed_system.trace.simps distributed_system.trace_and_start_determines_end not_less s7_is_fin take_all tr_exists)\n      then have \"Marker \\<notin> set (msgs (distributed_system.s chan Example.trans send recv init t i) cid)\"\n      proof -\n        have \"distributed_system.s chan Example.trans send recv init t i = s7\" \n          using \\<open>distributed_system chan\\<close> \\<open>distributed_system.trace chan Example.trans send recv (distributed_system.s chan Example.trans send recv init t (length t)) [] (distributed_system.s chan Example.trans send recv init t i)\\<close> distributed_system.trace.simps s7_is_fin by fastforce\n        then show ?thesis using s7_no_marker by simp\n      qed\n      then show False using marker_in_channel by simp\n    qed\n    then show \"(\\<exists>j\\<ge>i. Marker \\<notin> set (msgs (distributed_system.s chan Example.trans send recv init t j) cid))\"\n    proof -\n      have \"distributed_system.trace chan Example.trans send recv\n            (distributed_system.s chan Example.trans send recv init t i)\n            (take ((length t) - i) (drop i t))\n            (distributed_system.s chan Example.trans send recv init t (length t))\" \n        using \\<open>distributed_system chan\\<close> \\<open>i < length t\\<close> distributed_system.exists_trace_for_any_i_j less_imp_le_nat tr_exists by blast\n      then have \"Marker \\<notin> set (msgs (distributed_system.s chan Example.trans send recv init t (length t)) cid)\"\n      proof -\n        have \"distributed_system.s chan Example.trans send recv init t (length t) = s7\" \n          by (simp add: s7_is_fin)\n        then show ?thesis using s7_no_marker by simp\n      qed\n      then show ?thesis \n        using \\<open>i < length t\\<close> less_imp_le_nat by blast\n    qed\n  qed\n  show \"\\<forall>t p. distributed_system.trace chan Example.trans send recv init t s7 \\<longrightarrow>\n              (\\<exists>i. ps (distributed_system.s chan Example.trans send recv init t i) p \\<noteq> None \\<and> i \\<le> length t)\"\n  proof ((rule allI)+, rule impI)\n    fix t p\n    assume \"distributed_system.trace chan Example.trans send recv init t s7\"\n    have s7_is_fin: \"s7 = (distributed_system.s chan Example.trans send recv init t (length t))\" \n      by (metis (no_types, lifting) \\<open>distributed_system chan\\<close> \\<open>distributed_system.trace chan Example.trans send recv init t s7\\<close> distributed_system.exists_trace_for_any_i distributed_system.trace_and_start_determines_end order_refl take_all)\n    moreover have \"has_snapshotted s7 p\" by simp\n    ultimately show \"(\\<exists>i. ps (distributed_system.s chan Example.trans send recv init t i) p \\<noteq> None \\<and> i \\<le> length t)\"\n      by auto\n  qed\nqed\n\nend\n", "meta": {"author": "ThreeFx", "repo": "chandy-lamport-formalization", "sha": "a2ad5daf2fd37ee70c9f086b73e156cc068d2134", "save_path": "github-repos/isabelle/ThreeFx-chandy-lamport-formalization", "path": "github-repos/isabelle/ThreeFx-chandy-lamport-formalization/chandy-lamport-formalization-a2ad5daf2fd37ee70c9f086b73e156cc068d2134/Example.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.600188359260205, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.2766969043668829}}
{"text": "(*  Title:      HOL/Auth/n_mutualEx_on_inis.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mutualEx Protocol Case Study*} \n\ntheory n_mutualEx_on_inis imports n_mutualEx_on_ini\nbegin\nlemma on_inis:\n  assumes b1: \"f \\<in> (invariants N)\" and b2: \"ini \\<in> {andList (allInitSpecs N)}\" and b3: \"formEval ini s\"\n  shows \"formEval f s\"\n  proof -\n  have c1: \"(\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__1  p__Inv0 p__Inv1)\\<or>\n    (\\<exists> p__Inv0. p__Inv0\\<le>N\\<and>f=inv__2  p__Inv0)\\<or>\n    (\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__3  p__Inv0 p__Inv1)\\<or>\n    (\\<exists> p__Inv0. p__Inv0\\<le>N\\<and>f=inv__4  p__Inv0)\\<or>\n    (\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__5  p__Inv0 p__Inv1)\"\n  apply (cut_tac b1, simp) done\n    moreover {\n      assume d1: \"(\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__1  p__Inv0 p__Inv1)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__1)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> p__Inv0. p__Inv0\\<le>N\\<and>f=inv__2  p__Inv0)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__2)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__3  p__Inv0 p__Inv1)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__3)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> p__Inv0. p__Inv0\\<le>N\\<and>f=inv__4  p__Inv0)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__4)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__5  p__Inv0 p__Inv1)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__5)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n  ultimately show \"formEval f s\"\n  by satx\nqed\n\nend\n", "meta": {"author": "lyj238Gmail", "repo": "newParaVerifier", "sha": "5c2d49bf8e6c46c60efa53c98b0ba5c577d59618", "save_path": "github-repos/isabelle/lyj238Gmail-newParaVerifier", "path": "github-repos/isabelle/lyj238Gmail-newParaVerifier/newParaVerifier-5c2d49bf8e6c46c60efa53c98b0ba5c577d59618/examples/n_mutualEx/n_mutualEx_on_inis.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5851011542032312, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.2765676477434113}}
{"text": "theory flash9Rev imports flashPub\nbegin\nsection{*Main defintions*}\nlemma NI_FAckVsInv9:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_InvVsInv9:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_InvAck_1VsInv9:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by(cut_tac a1 a2 a3 a4, auto) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto \n qed\n  lemma NI_InvAck_1_HomeVsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_InvAck_2VsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Local_GetX_GetXVsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Local_GetX_Nak1VsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Local_GetX_Nak2VsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Local_GetX_Nak3VsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Local_GetX_PutX1VsInv9:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv9:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv9:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv9:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv9:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv9:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv9:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv9:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv9:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv9:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10VsInv9:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10_homeVsInv9:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX11VsInv9:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_GetVsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Local_Get_Nak1VsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Local_Get_Nak2VsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Local_Get_Nak3VsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Local_Get_Put1VsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Local_Get_Put2VsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Local_Get_Put3VsInv9:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''Dir_local'') )  ( Const true ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_PutVsInv9:  \n  (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n\n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Put ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma NI_Local_PutXAcksDoneVsInv9:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_NakVsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Nak_ClearVsInv9:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_Nak_HomeVsInv9:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_Remote_GetX_NakVsInv9:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by(cut_tac a1 a2 a3 a4, auto) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto \n qed\n  lemma NI_Remote_GetX_Nak_HomeVsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Remote_GetX_PutXVsInv9:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_PutX_HomeVsInv9:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Nak1VsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Remote_Get_Nak2VsInv9:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by(cut_tac a1 a2 a3 a4, auto) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto \n qed\n  lemma NI_Remote_Get_Put1VsInv9:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Put2VsInv9:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutVsInv9:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                     have allCases:\"formEval  ( eqn ( IVar ( Para ''InvMarked'' iInv1) )  ( Const true ))  s  \\<or>formEval   (neg ( eqn ( IVar ( Para ''InvMarked'' iInv1) )  ( Const true )) )  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume c1:\"formEval ( eqn ( IVar ( Para ''InvMarked'' iInv1) )  ( Const true ))  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1  c1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n\n    moreover\n                       {assume c1:\"formEval  (neg ( eqn ( IVar ( Para ''InvMarked'' iInv1) )  ( Const true )) )  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1  c1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n   ultimately have \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutXVsInv9:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_ReplaceVsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_ReplaceHomeVsInv9:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_ReplaceHomeShrVldVsInv9:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_ReplaceShrVldVsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_ShWbVsInv9:  \n  (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n\n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''ShWbMsg_Cmd'') )  ( Const SHWB_ShWb ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma NI_WbVsInv9:  \n  (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n\n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''WbMsg_Cmd'') )  ( Const WB_Wb ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_GetX1VsInv9:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_GetX_GetX2VsInv9:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_GetX_PutX1VsInv9:  \n  (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX2VsInv9:  \n  (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX3VsInv9:  \n  (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX4VsInv9:  \n  (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_Get_GetVsInv9:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_Get_PutVsInv9:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_PutXVsInv9:  \n  (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n\n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Para ''CacheState'' Home) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma PI_Local_ReplaceVsInv9:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Remote_GetVsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma PI_Remote_GetXVsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma PI_Remote_PutXVsInv9:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_ReplaceVsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma StoreVsInv9:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma StoreHomeVsInv9:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv9  iInv1 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash9Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.626124191181315, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.27654215343838406}}
{"text": "theory SATDecision\nimports ModelIso \"HOL-Library.Finite_Map\"\nbegin\n\nsubsection \\<open>AMS\\<close>\n\ndefinition equiv_classes :: \"('a \\<rightharpoonup> 'b) \\<Rightarrow> 'a set set\" where\n  \"equiv_classes m = { {x. m x = Some y}  | y. y \\<in> ran m}\"\n\nlemma classes_distinct: \"\\<lbrakk>c1 \\<in> equiv_classes m; c2 \\<in> equiv_classes m\\<rbrakk> \\<Longrightarrow> c1=c2 \\<or> c1\\<inter>c2={}\"\n  by (auto simp: equiv_classes_def)\n\ndatatype len = One | AtLeastTwo\ntype_synonym abst_var = \"var fset\"\n\ntypedef ams = \"{(V,E,\\<rho>,\\<gamma>)::\n  (abst_var fset \\<times> (abst_var,(abst_var\\<times>len)) fmap \\<times> abst_var fset fset \\<times> nat) | V E \\<rho> \\<gamma>.\n  (\\<forall>v\\<in>fset V. v\\<noteq>{||}) \\<and> (\\<exists>v\\<in>fset V. Nil |\\<in>|v) \\<and> (\\<forall>v1 v2. v1 |\\<in>| V \\<and> v2 |\\<in>| V \\<longrightarrow> v1=v2 \\<or> v1 |\\<inter>| v2 = {||})\n  \\<and> fmdom E |\\<subseteq>| V \\<and> fmimage (Abs_fmap (Some\\<circ>fst)) (fmran E) |\\<subseteq>| V \\<and> (\\<forall>v\\<in> fset (fmdom E). Nil |\\<notin>| v)\n  \\<and> (\\<forall>R1 R2. R1 |\\<in>| \\<rho> \\<and> R2 |\\<in>| \\<rho> \\<longrightarrow> R1=R2 \\<or> R1 |\\<inter>| R2 = {||}) \\<and> \n    (\\<forall>R\\<in>fset \\<rho>. R |\\<subseteq>| V \\<and> R |\\<inter>| fmdom E = {||} \\<and> (\\<forall>v\\<in>fset R. Nil |\\<notin>| v))}\"\nproof -\n  define ams :: \"(abst_var fset \\<times> (abst_var,(abst_var\\<times>len)) fmap \\<times> abst_var fset fset \\<times> nat)\" \n    where \"ams \\<equiv> ({|{|Nil|}|}, fmempty, {||}, 0)\"\n  then have \"ams \\<in> {(V, E, \\<rho>, \\<gamma>) |V E \\<rho> \\<gamma>. (\\<forall>v\\<in>fset V. v \\<noteq> {||}) \\<and>(\\<exists>v\\<in>fset V. var.Nil |\\<in>| v) \\<and>\n    (\\<forall>v1 v2. v1 |\\<in>| V \\<and> v2 |\\<in>| V \\<longrightarrow> v1 = v2 \\<or> v1 |\\<inter>| v2 = {||}) \\<and> fmdom E |\\<subseteq>| V \\<and>\n    fmimage (Abs_fmap (Some \\<circ> fst)) (fmran E) |\\<subseteq>| V \\<and> (\\<forall>v\\<in>fset (fmdom E). var.Nil |\\<notin>| v) \\<and>\n    (\\<forall>R1 R2. R1 |\\<in>| \\<rho> \\<and> R2 |\\<in>| \\<rho> \\<longrightarrow> R1 = R2 \\<or> R1 |\\<inter>| R2 = {||}) \\<and>\n    (\\<forall>R\\<in>fset \\<rho>. R |\\<subseteq>| V \\<and> R |\\<inter>| fmdom E = {||} \\<and> (\\<forall>v\\<in>fset R. var.Nil |\\<notin>| v))}\"\n    by simp\n  then show ?thesis by meson\nqed\n\nend", "meta": {"author": "firefighterduck", "repo": "ssl", "sha": "395041934a253815e77c405f24e5932b96b8e98d", "save_path": "github-repos/isabelle/firefighterduck-ssl", "path": "github-repos/isabelle/firefighterduck-ssl/ssl-395041934a253815e77c405f24e5932b96b8e98d/SATDecision.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6723316991792861, "lm_q2_score": 0.41111086923216794, "lm_q1q2_score": 0.2764028692619368}}
{"text": "theory Benchmark_Set_LC\nimports \n  Benchmark_Set\n  Containers.Set_Impl\n  \"HOL-Library.Code_Target_Nat\"\nbegin\n\nlemma [code_unfold del]: \"card \\<equiv> Cardinality.card'\" by(simp)\n\ninstantiation word :: (len) ceq begin\ndefinition \"CEQ('a word) = Some (=)\"\ninstance by(intro_classes)(simp add: ceq_word_def)\nend\n\ninstantiation word :: (len) compare begin\ndefinition \"compare_word = (comparator_of :: 'a word comparator)\"\ninstance by(intro_classes)(simp add: compare_word_def comparator_of)\nend\n\ninstantiation word :: (len) ccompare begin\ndefinition \"CCOMPARE('a word) = Some compare\"\ninstance by(intro_classes)(simp add: ccompare_word_def comparator_compare)\nend\n\ninstantiation word :: (len) set_impl begin\ndefinition \"SET_IMPL('a word) = Phantom('a word) set_RBT\"\ninstance ..\nend\n\ninstantiation word :: (len) proper_interval begin\n\nfun proper_interval_word :: \"'a word option \\<Rightarrow> 'a word option \\<Rightarrow> bool\"\nwhere\n  \"proper_interval_word None None = True\"\n| \"proper_interval_word None (Some y) = (y \\<noteq> 0)\"\n| \"proper_interval_word (Some x) None = (x \\<noteq> - 1)\"\n| \"proper_interval_word (Some x) (Some y) = (x < y \\<and> x \\<noteq> y - 1)\"\n\ninstance\nproof\n  let ?pi = \"proper_interval :: 'a word proper_interval\"\n  show \"?pi None None = True\" by simp\n  fix y\n  show \"?pi None (Some y) = (\\<exists>z. z < y)\"\n    using word_neq_0_conv [of y] by auto\n  fix x\n  show \"?pi (Some x) None = (\\<exists>z. x < z)\"\n    using word_order.not_eq_extremum [of x] by auto\n\n  have \"(x < y \\<and> x \\<noteq> y - 1) = (\\<exists>z>x. z < y)\" (is \"?lhs \\<longleftrightarrow> ?rhs\")\n  proof\n    assume ?lhs\n    then obtain \"x < y\" \"x \\<noteq> y - 1\" ..\n    have \"0 \\<le> uint x\" by simp\n    also have \"\\<dots> < uint y\" using \\<open>x < y\\<close> by(simp add: word_less_def)\n    finally have \"0 < uint y\" .\n    then have \"y - 1 < y\" by(simp add: word_less_def uint_sub_if' not_le)\n    moreover from \\<open>0 < uint y\\<close> \\<open>x < y\\<close> \\<open>x \\<noteq> y - 1\\<close>\n    have \"x < y - 1\" by(simp add: word_less_def uint_sub_if' uint_arith_simps(3))\n    ultimately show ?rhs by blast\n  next\n    assume ?rhs\n    then obtain z where z: \"x < z\" \"z < y\" by blast\n    have \"0 \\<le> uint z\" by simp\n    also have \"\\<dots> < uint y\" using \\<open>z < y\\<close> by(simp add: word_less_def)\n    finally show ?lhs using z by(auto simp add: word_less_def uint_sub_if')\n  qed\n  thus \"?pi (Some x) (Some y) = (\\<exists>z>x. z < y)\" by simp\nqed\n\nend\n\ninstantiation word :: (len) cproper_interval begin\ndefinition \"cproper_interval = (proper_interval :: 'a word proper_interval)\"\ninstance by( intro_classes, simp add: cproper_interval_word_def ccompare_word_def \n  compare_word_def le_lt_comparator_of ID_Some proper_interval_class.axioms)\nend\n\ninstantiation word :: (len) cenum begin\ndefinition \"CENUM('a word) = None\"\ninstance by(intro_classes)(simp_all add: cEnum_word_def)\nend\n\nnotepad begin\n  have \"Benchmark_Set.complete 30 40 (12345, 67899) = (32, 4294967296)\" by eval\nend\n\nend\n", "meta": {"author": "zabihullah331", "repo": "barakzai", "sha": "793257c1d71ec75a299fc6b5843af756ead2afb0", "save_path": "github-repos/isabelle/zabihullah331-barakzai", "path": "github-repos/isabelle/zabihullah331-barakzai/barakzai-793257c1d71ec75a299fc6b5843af756ead2afb0/thys/Containers/ITP-2013/Benchmark_Set_LC.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318337259584, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.2760794156570931}}
{"text": "theory Ipassmt\nimports Common_Primitive_Syntax\n        \"../Semantics_Ternary/Primitive_Normalization\"\n        \"../../Simple_Firewall/Primitives/Iface\"\n        \"../../Simple_Firewall/Common/IP_Addr_WordInterval_toString\" (*for debug pretty-printing*)\n        \"../../Automatic_Refinement/Lib/Misc\" (*dependnecy!*)\nbegin\n\n  text\\<open>A mapping from an interface to its assigned ip addresses in CIDR notation\\<close>\n  type_synonym 'i ipassignment=\"iface \\<rightharpoonup> ('i word \\<times> nat) list\" (*technically, a set*)\n\n\nsubsection\\<open>Sanity checking for an @{typ \"'i ipassignment\"}.\\<close>\n\n  text\\<open>warning if interface map has wildcards\\<close>\n  definition ipassmt_sanity_nowildcards :: \"'i ipassignment \\<Rightarrow> bool\" where\n    \"ipassmt_sanity_nowildcards ipassmt \\<equiv> \\<forall> iface \\<in> dom ipassmt. \\<not> iface_is_wildcard iface\"\n\n    text\\<open>Executable of the @{typ \"'i ipassignment\"} is given as a list.\\<close>\n    \n\n\n  (* use this in all exported code*)\n  (*TODO: generate useful error message in exported code*)\n  definition map_of_ipassmt :: \"(iface \\<times> ('i word \\<times> nat) list) list \\<Rightarrow> iface \\<rightharpoonup> ('i word \\<times> nat) list\" where\n    \"map_of_ipassmt ipassmt = (\n      if\n        distinct (map fst ipassmt) \\<and> ipassmt_sanity_nowildcards (map_of ipassmt)\n      then\n        map_of ipassmt\n      else undefined (*undefined_ipassmt_must_be_distinct_and_dont_have_wildcard_interfaces*))\"\n\n\n  text\\<open>some additional (optional) sanity checks\\<close>\n  \n  text\\<open>sanity check that there are no zone-spanning interfaces\\<close>\n  definition ipassmt_sanity_disjoint :: \"'i::len ipassignment \\<Rightarrow> bool\" where\n    \"ipassmt_sanity_disjoint ipassmt \\<equiv> \\<forall> i1 \\<in> dom ipassmt. \\<forall> i2 \\<in> dom ipassmt. i1 \\<noteq> i2 \\<longrightarrow>\n          ipcidr_union_set (set (the (ipassmt i1))) \\<inter> ipcidr_union_set (set (the (ipassmt i2))) = {}\"\n  \n  lemma[code_unfold]: \"ipassmt_sanity_disjoint (map_of ipassmt) \\<longleftrightarrow>\n    (let Is = fst` set ipassmt in \n      (\\<forall> i1 \\<in> Is. \\<forall> i2 \\<in> Is. i1 \\<noteq> i2 \\<longrightarrow> wordinterval_empty (wordinterval_intersection (l2wi (map ipcidr_to_interval (the ((map_of ipassmt) i1))))  (l2wi (map ipcidr_to_interval (the ((map_of ipassmt) i2)))))))\"\n    apply(simp add: ipassmt_sanity_disjoint_def Map.dom_map_of_conv_image_fst)\n    apply(simp add: ipcidr_union_set_def)\n    apply(simp add: l2wi)\n    apply(simp add: ipcidr_to_interval_def)\n    using ipset_from_cidr_ipcidr_to_interval by blast\n  \n  \n  text\\<open>Checking that the ipassmt covers the complete ipv4 address space.\\<close>\n  definition ipassmt_sanity_complete :: \"(iface \\<times> ('i::len word \\<times> nat) list) list \\<Rightarrow> bool\" where\n    \"ipassmt_sanity_complete ipassmt \\<equiv> distinct (map fst ipassmt) \\<and> (\\<Union>(ipcidr_union_set ` set ` (ran (map_of ipassmt)))) = UNIV\"\n\n    lemma[code_unfold]: \"ipassmt_sanity_complete ipassmt \\<longleftrightarrow> distinct (map fst ipassmt) \\<and> (let range = map snd ipassmt in \n        wordinterval_eq (wordinterval_Union (map (l2wi \\<circ> (map ipcidr_to_interval)) range)) wordinterval_UNIV\n        )\"\n     apply(cases \"distinct (map fst ipassmt)\")\n      apply(simp add: ipassmt_sanity_complete_def)\n      apply(simp add: Map.ran_distinct)\n      apply(simp add: wordinterval_eq_set_eq wordinterval_Union)\n      apply(simp add: l2wi)\n      apply(simp add: ipcidr_to_interval_def)\n      apply(simp add: ipcidr_union_set_def ipset_from_cidr_ipcidr_to_interval; fail)\n     apply(simp add: ipassmt_sanity_complete_def)\n     done\n\n\n\n    value[code] \"ipassmt_sanity_nowildcards (map_of [(Iface ''eth1.1017'', [(ipv4addr_of_dotdecimal (131,159,14,240), 28)])])\"\n\n  fun collect_ifaces' :: \"'i::len common_primitive rule list \\<Rightarrow> iface list\" where\n    \"collect_ifaces' [] = []\" |\n    \"collect_ifaces' ((Rule m a)#rs) = filter (\\<lambda>iface. iface \\<noteq> ifaceAny) (\n                                      (map (\\<lambda>x. case x of Pos i \\<Rightarrow> i | Neg i \\<Rightarrow> i) (fst (primitive_extractor (is_Iiface, iiface_sel) m))) @\n                                      (map (\\<lambda>x. case x of Pos i \\<Rightarrow> i | Neg i \\<Rightarrow> i) (fst (primitive_extractor (is_Oiface, oiface_sel) m))) @ collect_ifaces' rs)\"\n\n  definition collect_ifaces :: \"'i::len common_primitive rule list \\<Rightarrow> iface list\" where\n    \"collect_ifaces rs \\<equiv> mergesort_remdups (collect_ifaces' rs)\"\n  lemma \"set (collect_ifaces rs) = set (collect_ifaces' rs)\"\n    by(simp add: collect_ifaces_def mergesort_remdups_correct)\n\n  text\\<open>sanity check that all interfaces mentioned in the ruleset are also listed in the ipassmt. May fail for wildcard interfaces in the ruleset.\\<close>\n\n  (*primitive_extractor requires normalized_nnf_primitives*)\n  definition ipassmt_sanity_defined :: \"'i::len common_primitive rule list \\<Rightarrow> 'i ipassignment \\<Rightarrow> bool\" where\n    \"ipassmt_sanity_defined rs ipassmt \\<equiv> \\<forall> iface \\<in> set (collect_ifaces rs). iface \\<in> dom ipassmt\"\n\n    lemma[code]: \"ipassmt_sanity_defined rs ipassmt \\<longleftrightarrow> (\\<forall> iface \\<in> set (collect_ifaces rs). ipassmt iface \\<noteq> None)\"\n      by(simp add: ipassmt_sanity_defined_def Map.domIff)\n  \n    lemma \"ipassmt_sanity_defined [\n         Rule (MatchAnd (Match (Src (IpAddrNetmask (ipv4addr_of_dotdecimal (192,168,0,0)) 24))) (Match (IIface (Iface ''eth1.1017'')))) action.Accept,\n         Rule (MatchAnd (Match (Src (IpAddrNetmask (ipv4addr_of_dotdecimal (192,168,0,0)) 24))) (Match (IIface (ifaceAny)))) action.Accept,\n         Rule MatchAny action.Drop]\n             (map_of [(Iface ''eth1.1017'', [(ipv4addr_of_dotdecimal (131,159,14,240), 28)])])\" by eval\n\n\n\n  (*TODO: use and add code equation*)\n  definition ipassmt_ignore_wildcard :: \"'i::len ipassignment \\<Rightarrow> 'i ipassignment\" where\n    \"ipassmt_ignore_wildcard ipassmt \\<equiv> \\<lambda>k. case ipassmt k of None \\<Rightarrow> None \n                                                           | Some ips \\<Rightarrow> if ipcidr_union_set (set ips) = UNIV then None else Some ips\"\n\n  lemma ipassmt_ignore_wildcard_le: \"ipassmt_ignore_wildcard ipassmt \\<subseteq>\\<^sub>m ipassmt\"\n    apply(simp add: ipassmt_ignore_wildcard_def map_le_def)\n    apply(clarify)\n    apply(simp split: option.split_asm if_split_asm)\n    done\n\n  definition ipassmt_ignore_wildcard_list:: \"(iface \\<times> ('i::len word \\<times> nat) list) list \\<Rightarrow> (iface \\<times> ('i word \\<times> nat) list) list\" where\n    \"ipassmt_ignore_wildcard_list ipassmt = filter (\\<lambda>(_,ips).  \\<not> wordinterval_eq (l2wi (map ipcidr_to_interval ips)) wordinterval_UNIV) ipassmt\"\n\n  (*distinct fst ipassmt notwendig?*)\n  lemma \"distinct (map fst ipassmt) \\<Longrightarrow>\n    map_of (ipassmt_ignore_wildcard_list ipassmt) = ipassmt_ignore_wildcard (map_of ipassmt)\"\n      apply(simp add: ipassmt_ignore_wildcard_list_def ipassmt_ignore_wildcard_def)\n      apply(simp add: wordinterval_eq_set_eq)\n      apply(simp add: l2wi)\n      apply(simp add: ipcidr_to_interval_def)\n      apply(simp add: fun_eq_iff)\n      apply(clarify)\n      apply(induction ipassmt)\n       apply(simp; fail)\n      apply(simp)\n      apply(simp split:option.split option.split_asm)\n      apply(simp add: ipcidr_union_set_def ipset_from_cidr_ipcidr_to_interval)\n      apply(simp add: case_prod_unfold)\n      by blast\n      (*apply(safe)\n                       apply(simp_all)\n      by (simp add: rev_image_eqI)*)\n      \n\n  \n  text\\<open>Debug algorithm with human-readable output\\<close>\n  definition debug_ipassmt_generic\n    :: \"('i::len wordinterval \\<Rightarrow> string) \\<Rightarrow>\n          (iface \\<times> ('i word \\<times> nat) list) list \\<Rightarrow> 'i common_primitive rule list \\<Rightarrow> string list\" where\n    \"debug_ipassmt_generic toStr ipassmt rs \\<equiv> let ifaces = (map fst ipassmt) in [\n      ''distinct: '' @ (if distinct ifaces then ''passed'' else ''FAIL!'')\n      , ''ipassmt_sanity_nowildcards: '' @\n          (if ipassmt_sanity_nowildcards (map_of ipassmt)\n           then ''passed'' else ''fail: ''@list_toString iface_sel (filter iface_is_wildcard ifaces))\n      , ''ipassmt_sanity_defined (interfaces defined in the ruleset are also in ipassmt): '' @ \n          (if ipassmt_sanity_defined rs (map_of ipassmt)\n           then ''passed'' else ''fail: ''@list_toString iface_sel [i \\<leftarrow> (collect_ifaces rs). i \\<notin> set ifaces])\n      , ''ipassmt_sanity_disjoint (no zone-spanning interfaces): '' @\n          (if ipassmt_sanity_disjoint (map_of ipassmt)\n           then ''passed'' else ''fail: ''@list_toString (\\<lambda>(i1,i2). ''('' @ iface_sel i1 @ '','' @ iface_sel i2 @ '')'')\n               [(i1,i2) \\<leftarrow> List.product ifaces ifaces. i1 \\<noteq> i2 \\<and>\n                \\<not> wordinterval_empty (wordinterval_intersection\n                                        (l2wi (map ipcidr_to_interval (the ((map_of ipassmt) i1))))\n                                        (l2wi (map ipcidr_to_interval (the ((map_of ipassmt) i2)))))\n          ])\n      , ''ipassmt_sanity_disjoint excluding UNIV interfaces: '' @\n          (let ipassmt = ipassmt_ignore_wildcard_list ipassmt;\n               ifaces = (map fst ipassmt)\n           in\n          (if ipassmt_sanity_disjoint (map_of ipassmt)\n           then ''passed'' else ''fail: ''@list_toString (\\<lambda>(i1,i2). ''('' @ iface_sel i1 @ '','' @ iface_sel i2 @ '')'')\n               [(i1,i2) \\<leftarrow> List.product ifaces ifaces. i1 \\<noteq> i2 \\<and>\n                \\<not> wordinterval_empty (wordinterval_intersection\n                                        (l2wi (map ipcidr_to_interval (the ((map_of ipassmt) i1))))\n                                        (l2wi (map ipcidr_to_interval (the ((map_of ipassmt) i2)))))\n          ]))\n       , ''ipassmt_sanity_complete: '' @ \n          (if ipassmt_sanity_complete ipassmt\n           then ''passed''\n           else ''the following is not covered: '' @ \n            toStr (wordinterval_setminus wordinterval_UNIV (wordinterval_Union (map (l2wi \\<circ> (map ipcidr_to_interval)) (map snd ipassmt)))))\n      , ''ipassmt_sanity_complete excluding UNIV interfaces: '' @\n          (let ipassmt = ipassmt_ignore_wildcard_list ipassmt\n           in\n          (if ipassmt_sanity_complete ipassmt\n           then ''passed''\n           else ''the following is not covered: '' @\n            toStr (wordinterval_setminus wordinterval_UNIV (wordinterval_Union (map (l2wi \\<circ> (map ipcidr_to_interval)) (map snd ipassmt))))))\n      ]\"\n\n  definition \"debug_ipassmt_ipv4 \\<equiv> debug_ipassmt_generic ipv4addr_wordinterval_toString\"\n  definition \"debug_ipassmt_ipv6 \\<equiv> debug_ipassmt_generic ipv6addr_wordinterval_toString\"\n\n\n  lemma dom_ipassmt_ignore_wildcard:\n    \"i\\<in>dom (ipassmt_ignore_wildcard ipassmt) \\<longleftrightarrow> i \\<in> dom ipassmt \\<and> ipcidr_union_set (set (the (ipassmt i))) \\<noteq> UNIV\"\n    apply(simp add: ipassmt_ignore_wildcard_def)\n    apply(rule)\n     apply(clarify)\n     apply(simp split: option.split_asm if_split_asm)\n     apply blast\n    apply(clarify)\n    apply(simp)\n    done\n\n  lemma ipassmt_ignore_wildcard_the:\n    \"ipassmt i = Some ips \\<Longrightarrow> ipcidr_union_set (set ips) \\<noteq> UNIV \\<Longrightarrow> (the (ipassmt_ignore_wildcard ipassmt i)) = ips\"\n    \"ipassmt_ignore_wildcard ipassmt i = Some ips \\<Longrightarrow> the (ipassmt i) = ips\"\n    \"ipassmt_ignore_wildcard ipassmt i = Some ips \\<Longrightarrow> ipcidr_union_set (set ips) \\<noteq> UNIV\"\n    by (simp_all add: ipassmt_ignore_wildcard_def split: option.split_asm if_split_asm)\n    \n\n  lemma ipassmt_sanity_disjoint_ignore_wildcards:\n        \"ipassmt_sanity_disjoint (ipassmt_ignore_wildcard ipassmt) \\<longleftrightarrow>\n         (\\<forall>i1\\<in>dom ipassmt.\n          \\<forall>i2\\<in>dom ipassmt.\n            ipcidr_union_set (set (the (ipassmt i1))) \\<noteq> UNIV \\<and>\n            ipcidr_union_set (set (the (ipassmt i2))) \\<noteq> UNIV \\<and>\n            i1 \\<noteq> i2 \n            \\<longrightarrow> ipcidr_union_set (set (the (ipassmt i1))) \\<inter> ipcidr_union_set (set (the (ipassmt i2))) = {})\"\n    apply(simp add: ipassmt_sanity_disjoint_def)\n    apply(rule)\n     apply(clarify)\n     apply(simp)\n     subgoal for i1 i2 ips1 ips2\n     apply(erule_tac x=i1 in ballE)\n      prefer 2\n      using dom_ipassmt_ignore_wildcard  apply (metis domI option.sel)\n     apply(erule_tac x=i2 in ballE)\n      prefer 2\n      using dom_ipassmt_ignore_wildcard apply (metis domI domIff option.sel)\n     by(simp add: ipassmt_ignore_wildcard_the; fail)\n    apply(clarify)\n    apply(simp)\n    subgoal for i1 i2 ips1 ips2\n    apply(erule_tac x=i1 in ballE)\n     prefer 2\n     using dom_ipassmt_ignore_wildcard apply auto[1]\n    apply(erule_tac x=i2 in ballE)\n     prefer 2\n     using dom_ipassmt_ignore_wildcard apply auto[1]\n    by(simp add: ipassmt_ignore_wildcard_the)\n   done\n\n  text\\<open>Confusing names: @{const ipassmt_sanity_nowildcards} refers to wildcard interfaces.\n       @{const ipassmt_ignore_wildcard} refers to the UNIV ip range.\n\\<close>\n  lemma ipassmt_sanity_nowildcards_ignore_wildcardD:\n    \"ipassmt_sanity_nowildcards ipassmt \\<Longrightarrow> ipassmt_sanity_nowildcards (ipassmt_ignore_wildcard ipassmt)\"\n    by (simp add: dom_ipassmt_ignore_wildcard ipassmt_sanity_nowildcards_def)\n    \n\n lemma ipassmt_disjoint_nonempty_inj:\n     assumes ipassmt_disjoint: \"ipassmt_sanity_disjoint ipassmt\"\n        and ifce: \"ipassmt ifce = Some i_ips\"\n        and a: \"ipcidr_union_set (set i_ips) \\<noteq> {}\"\n        and k: \"ipassmt k = Some i_ips\"\n     shows \"k = ifce\"\n     proof(rule ccontr)\n       assume \"k \\<noteq> ifce\"\n       with ifce k ipassmt_disjoint have \"ipcidr_union_set (set (the (ipassmt k))) \\<inter> ipcidr_union_set (set (the (ipassmt ifce))) = {}\"\n         unfolding ipassmt_sanity_disjoint_def by fastforce\n       thus False using a ifce k by auto \n     qed\n\n  lemma ipassmt_ignore_wildcard_None_Some:\n    \"ipassmt_ignore_wildcard ipassmt ifce = None \\<Longrightarrow> ipassmt ifce = Some ips \\<Longrightarrow> ipcidr_union_set (set ips) = UNIV\"\n    by (metis domI domIff dom_ipassmt_ignore_wildcard option.sel)\n    \n\n (*can this lemma be somehow useful?\n   maybe when rewriting, we can try to rewrite in the ignore_wildcard space and just constrain the the other area?*)\n lemma ipassmt_disjoint_ignore_wildcard_nonempty_inj:\n     assumes ipassmt_disjoint: \"ipassmt_sanity_disjoint (ipassmt_ignore_wildcard ipassmt)\"\n        and ifce: \"ipassmt ifce = Some i_ips\"\n        and a: \"ipcidr_union_set (set i_ips) \\<noteq> {}\"\n        and k: \"(ipassmt_ignore_wildcard ipassmt) k = Some i_ips\"\n     shows \"k = ifce\"\n     proof(rule ccontr)\n       assume \"k \\<noteq> ifce\"\n       show False\n       proof(cases \"(ipassmt_ignore_wildcard ipassmt) ifce\")\n       case (Some i_ips') (*proofs mainly by sledgehammer*)\n         hence \"i_ips' = i_ips\" using ifce ipassmt_ignore_wildcard_the(2) by fastforce\n         hence \"(ipassmt_ignore_wildcard ipassmt) k = Some i_ips\" using Some ifce ipassmt_ignore_wildcard_def k by auto \n         thus False using Some \\<open>i_ips' = i_ips\\<close> \\<open>k \\<noteq> ifce\\<close> a ipassmt_disjoint ipassmt_disjoint_nonempty_inj by blast\n       next\n       case None\n         with ipassmt_ignore_wildcard_None_Some have \"ipcidr_union_set (set i_ips) = UNIV\" using ifce by auto \n         thus False using ipassmt_ignore_wildcard_the(3) k by blast \n       qed\n     qed\n\n lemma ipassmt_disjoint_inj_k: \n     assumes ipassmt_disjoint: \"ipassmt_sanity_disjoint ipassmt\"\n        and ifce: \"ipassmt ifce = Some ips\"\n        and k: \"ipassmt k = Some ips'\"\n        and a: \"p \\<in> ipcidr_union_set (set ips)\"\n        and b: \"p \\<in> ipcidr_union_set (set ips')\"\n     shows \"k = ifce\"\n     proof(rule ccontr)\n       assume \"k \\<noteq> ifce\"\n       with ipassmt_disjoint have\n          \"ipcidr_union_set (set (the (ipassmt k))) \\<inter> ipcidr_union_set (set (the (ipassmt ifce))) = {}\"\n         unfolding ipassmt_sanity_disjoint_def using ifce k by blast\n       hence \"ipcidr_union_set (set ips') \\<inter> ipcidr_union_set (set ips) = {}\" by(simp add: k ifce)\n       thus False using a b by blast\n     qed\n\n (*might also work when we ignore UNIVs in the ipassmt? (not tested)*)\n lemma ipassmt_disjoint_matcheq_iifce_srcip:\n        assumes ipassmt_nowild: \"ipassmt_sanity_nowildcards ipassmt\"\n            and ipassmt_disjoint: \"ipassmt_sanity_disjoint ipassmt\"\n            and ifce: \"ipassmt ifce = Some i_ips\"\n            and p_ifce: \"ipassmt (Iface (p_iiface p)) = Some p_ips \\<and> p_src p \\<in> ipcidr_union_set (set p_ips)\"\n        shows   \"match_iface ifce (p_iiface p) \\<longleftrightarrow> p_src p \\<in> ipcidr_union_set (set i_ips)\"\n    proof\n     assume \"match_iface ifce (p_iiface p)\"\n     thus \"p_src p \\<in> ipcidr_union_set (set i_ips)\"\n       apply(cases \"ifce = Iface (p_iiface p)\")\n        using ifce p_ifce apply force\n       by (metis domI iface.sel iface_is_wildcard_def ifce ipassmt_nowild ipassmt_sanity_nowildcards_def match_iface.elims(2) match_iface_case_nowildcard)\n   next\n     assume a: \"p_src p \\<in> ipcidr_union_set (set i_ips)\"\n     --\\<open>basically, we need to reverse the map @{term ipassmt}\\<close>\n\n     from ipassmt_disjoint_nonempty_inj[OF ipassmt_disjoint ifce] a have ipassmt_inj: \"\\<forall>k. ipassmt k = Some i_ips \\<longrightarrow> k = ifce\" by blast\n\n     from ipassmt_disjoint_inj_k[OF ipassmt_disjoint ifce _ a] have ipassmt_inj_k:\n      \"\\<And>k ips'. ipassmt k = Some ips' \\<Longrightarrow> p_src p \\<in> ipcidr_union_set (set ips') \\<Longrightarrow> k = ifce\" by simp\n\n     have ipassmt_inj_p: \"\\<forall>ips'. p_src p \\<in> ipcidr_union_set (set ips') \\<and> (\\<exists>k. ipassmt k = Some ips') \\<longrightarrow> ips' = i_ips\"\n       apply(clarify)\n       apply(rename_tac ips' k)\n       apply(subgoal_tac \"k = ifce\")\n        using ifce apply simp\n       using ipassmt_inj_k by simp\n\n     from p_ifce have \"(Iface (p_iiface p)) = ifce\" using ipassmt_inj_p ipassmt_inj by blast \n\n     thus \"match_iface ifce (p_iiface p)\" using match_iface_refl by blast \n   qed\n\n\n\n  definition ipassmt_generic_ipv4 :: \"(iface \\<times> (32 word \\<times> nat) list) list\" where\n    \"ipassmt_generic_ipv4 = [(Iface ''lo'', [(ipv4addr_of_dotdecimal (127,0,0,0),8)])]\"\n\n  definition ipassmt_generic_ipv6 :: \"(iface \\<times> (128 word \\<times> nat) list) list\" where\n    \"ipassmt_generic_ipv6 = [(Iface ''lo'', [(1,128)])]\" (*::1/128*)\n\n\n\nsubsection\\<open>IP Assignment difference\\<close>\n  text\\<open>Compare two ipassmts. Returns a list of tuples\n    First entry of the tuple: things which are in the left ipassmt but not in the right.\n    Second entry of the tupls: things which are in the right ipassmt but not in the left.\\<close>\n  definition ipassmt_diff\n    :: \"(iface \\<times> ('i::len word \\<times> nat) list) list \\<Rightarrow> (iface \\<times> ('i::len word \\<times> nat) list) list\n        \\<Rightarrow> (iface \\<times> ('i word \\<times> nat) list \\<times> ('i word \\<times> nat) list) list\"\n  where\n  \"ipassmt_diff a b \\<equiv> let\n      t = \\<lambda>s. (case s of None \\<Rightarrow> Empty_WordInterval\n                       | Some s \\<Rightarrow> wordinterval_Union (map ipcidr_tuple_to_wordinterval s));\n      k = \\<lambda>x y d. cidr_split (wordinterval_setminus (t (map_of x d)) (t (map_of y d)))\n    in\n      [(d, (k a b d, k b a d)). d \\<leftarrow> remdups (map fst (a @ b))]\"\n  \n  \n  text\\<open>If an interface is defined in both ipassignments and there is no difference\n       then the two ipassignements describe the same IP range for this interface.\\<close>\n  lemma ipassmt_diff_ifce_equal: \"(ifce, [], []) \\<in> set (ipassmt_diff ipassmt1 ipassmt2)  \\<Longrightarrow>\n         ifce \\<in> dom (map_of ipassmt1) \\<Longrightarrow> ifce \\<in> dom (map_of ipassmt2) \\<Longrightarrow>\n           ipcidr_union_set (set (the ((map_of ipassmt1) ifce))) =\n           ipcidr_union_set (set (the ((map_of ipassmt2) ifce)))\"\n    proof -\n    have cidr_empty: \"[] = cidr_split r \\<Longrightarrow> wordinterval_to_set r = {}\" for r :: \"'a wordinterval\"\n      apply(subst cidr_split_prefix[symmetric])\n      by(simp)\n    show \"(ifce, [], []) \\<in> set (ipassmt_diff ipassmt1 ipassmt2)  \\<Longrightarrow>\n         ifce \\<in> dom (map_of ipassmt1) \\<Longrightarrow> ifce \\<in> dom (map_of ipassmt2) \\<Longrightarrow>\n           ipcidr_union_set (set (the ((map_of ipassmt1) ifce))) =\n           ipcidr_union_set (set (the ((map_of ipassmt2) ifce)))\"\n    apply(simp add: ipassmt_diff_def Let_def ipcidr_union_set_uncurry)\n    apply(simp add: Set.image_iff)\n    apply(elim conjE)\n    apply(drule cidr_empty)+\n    apply(simp)\n    apply(simp add: domIff)\n    apply(elim exE)\n    apply(simp add: wordinterval_Union wordinterval_to_set_ipcidr_tuple_to_wordinterval_uncurry)\n    done\n  qed\n\n  lemma ipcidr_union_cidr_split[simp]: \"ipcidr_union_set (set (cidr_split a)) = wordinterval_to_set a\"\n    by(simp add: ipcidr_union_set_uncurry cidr_split_prefix)\n\n  lemma \n    defines \"assmt as ifce \\<equiv> ipcidr_union_set (set (the ((map_of as ifce))))\"\n    assumes diffs: \"(ifce, d1, d2) \\<in> set (ipassmt_diff ipassmt1 ipassmt2)\"\n        and  doms: \"ifce \\<in> dom (map_of ipassmt1)\" \"ifce \\<in> dom (map_of ipassmt2)\"\n    shows \"ipcidr_union_set (set d1) = assmt ipassmt1 ifce - assmt ipassmt2 ifce\"\n          \"ipcidr_union_set (set d2) = assmt ipassmt2 ifce - assmt ipassmt1 ifce\"\n    using assms by (clarsimp simp add: ipassmt_diff_def Let_def assmt_def wordinterval_Union; simp add: ipcidr_union_set_uncurry uncurry_def wordinterval_to_set_ipcidr_tuple_to_wordinterval_uncurry)+\n            \n  \n  text\\<open>Explanation for interface @{term \"Iface ''a''\"}: \n          Left ipassmt: The IP range 4/30 contains the addresses 4,5,6,7\n          Diff: right ipassmt contains 6/32, so 4,5,7 is only in the left ipassmt.\n          IP addresses 4,5 correspond to subnet 4/30.\\<close>\n  lemma \"ipassmt_diff (ipassmt_generic_ipv4 @ [(Iface ''a'', [(4,30)])])\n                       (ipassmt_generic_ipv4 @ [(Iface ''a'', [(6,32), (0,30)]), (Iface ''b'', [(42,32)])]) =\n    [(Iface ''lo'', [], []),\n     (Iface ''a'', [(4, 31),(7, 32)],\n                   [(0, 30)]\n     ),\n     (Iface ''b'', [], [(42, 32)])]\" by eval\n\nend", "meta": {"author": "diekmann", "repo": "Iptables_Semantics", "sha": "e0a2516bd885708fce875023b474ae341cbdee29", "save_path": "github-repos/isabelle/diekmann-Iptables_Semantics", "path": "github-repos/isabelle/diekmann-Iptables_Semantics/Iptables_Semantics-e0a2516bd885708fce875023b474ae341cbdee29/thy/Iptables_Semantics/Primitive_Matchers/Ipassmt.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318337259584, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.2760794156570931}}
{"text": "theory Common_Primitive_toString\nimports \"../../Simple_Firewall/Primitives/Primitives_toString\"\n        Common_Primitive_Matcher\nbegin\n\n\nsection\\<open>Firewall toString Functions\\<close>\n\nfun ipt_ipv4range_toString :: \"32 ipt_iprange \\<Rightarrow> string\" where\n  \"ipt_ipv4range_toString (IpAddr ip) = ipv4addr_toString ip\" |\n  \"ipt_ipv4range_toString (IpAddrNetmask ip n) = ipv4addr_toString ip@''/''@string_of_nat n\"  |\n  \"ipt_ipv4range_toString (IpAddrRange ip1 ip2) = ipv4addr_toString ip1@''-''@ipv4addr_toString ip2\"\n\nfun ipt_ipv6range_toString :: \"128 ipt_iprange \\<Rightarrow> string\" where\n  \"ipt_ipv6range_toString (IpAddr ip) = ipv6addr_toString ip\" |\n  \"ipt_ipv6range_toString (IpAddrNetmask ip n) = ipv6addr_toString ip@''/''@string_of_nat n\"  |\n  \"ipt_ipv6range_toString (IpAddrRange ip1 ip2) = ipv6addr_toString ip1@''-''@ipv6addr_toString ip2\"\n\ndefinition ipv4addr_wordinterval_pretty_toString :: \"32 wordinterval \\<Rightarrow> string\" where\n  \"ipv4addr_wordinterval_pretty_toString wi = list_toString ipt_ipv4range_toString (wi_to_ipt_iprange wi)\"\n\nlemma \"ipv4addr_wordinterval_pretty_toString \n    (RangeUnion (RangeUnion (WordInterval 0x7F000000 0x7FFFFFFF) (WordInterval 0x1020304 0x1020306))\n                (WordInterval 0x8080808 0x8080808)) = ''[127.0.0.0/8, 1.2.3.4-1.2.3.6, 8.8.8.8]''\" by eval\n  \n\n\nfun action_toString :: \"action \\<Rightarrow> string\" where\n  \"action_toString action.Accept = ''-j ACCEPT''\" |\n  \"action_toString action.Drop = ''-j DROP''\" |\n  \"action_toString action.Reject = ''-j REJECT''\" |\n  \"action_toString (action.Call target) = ''-j ''@target@'' (call)''\" |\n  \"action_toString (action.Goto target) = ''-g ''@target\" |\n  \"action_toString action.Empty = ''''\" |\n  \"action_toString action.Log = ''-j LOG''\" |\n  \"action_toString action.Return = ''-j RETURN''\" |\n  \"action_toString action.Unknown = ''!!!!!!!!!!! UNKNOWN !!!!!!!!!!!''\"\n\n\nfun common_primitive_toString :: \"('i::len word \\<Rightarrow> string) \\<Rightarrow> 'i common_primitive \\<Rightarrow> string\" where\n  \"common_primitive_toString ipToStr (Src (IpAddr ip)) = ''-s ''@ipToStr ip\" |\n  \"common_primitive_toString ipToStr (Dst (IpAddr ip)) = ''-d ''@ipToStr ip\" |\n  \"common_primitive_toString ipToStr (Src (IpAddrNetmask ip n)) = ''-s ''@ipToStr ip@''/''@string_of_nat n\"  |\n  \"common_primitive_toString ipToStr (Dst (IpAddrNetmask ip n)) = ''-d ''@ipToStr ip@''/''@string_of_nat n\"  |\n  \"common_primitive_toString ipToStr (Src (IpAddrRange ip1 ip2)) = ''-m iprange --src-range ''@ipToStr ip1@''-''@ipToStr ip2\"  |\n  \"common_primitive_toString ipToStr (Dst (IpAddrRange ip1 ip2)) = ''-m iprange --dst-range ''@ipToStr ip1@''-''@ipToStr ip2\"  |\n  \"common_primitive_toString _ (IIface ifce) = iface_toString ''-i '' ifce\" |\n  \"common_primitive_toString _ (OIface ifce) = iface_toString ''-o '' ifce\" |\n  \"common_primitive_toString _ (Prot prot) = ''-p ''@protocol_toString prot\" |\n  \"common_primitive_toString _ (Src_Ports (L4Ports prot pts)) = ''-m ''@primitive_protocol_toString prot@'' --spts '' @ list_toString (ports_toString '''') pts\" |\n  \"common_primitive_toString _ (Dst_Ports (L4Ports prot pts)) = ''-m ''@primitive_protocol_toString prot@'' --dpts '' @ list_toString (ports_toString '''') pts\" |\n  \"common_primitive_toString _ (MultiportPorts (L4Ports prot pts)) = ''-p ''@primitive_protocol_toString prot@'' -m multiport --ports '' @ list_toString (ports_toString '''') pts\" |\n  \"common_primitive_toString _ (CT_State S) = ''-m state --state ''@ctstate_set_toString S\" |\n  \"common_primitive_toString _ (L4_Flags (TCP_Flags c m)) = ''--tcp-flags ''@ipt_tcp_flags_toString c@'' ''@ipt_tcp_flags_toString m\" |\n  \"common_primitive_toString _ (Extra e) = ''~~''@e@''~~''\"\n\n\ndefinition common_primitive_ipv4_toString :: \"32 common_primitive \\<Rightarrow> string\" where\n  \"common_primitive_ipv4_toString \\<equiv> common_primitive_toString ipv4addr_toString\"\n\ndefinition common_primitive_ipv6_toString :: \"128 common_primitive \\<Rightarrow> string\" where\n  \"common_primitive_ipv6_toString \\<equiv> common_primitive_toString ipv6addr_toString\"\n\n\nfun common_primitive_match_expr_toString\n  :: \"('i common_primitive \\<Rightarrow> string) \\<Rightarrow> 'i common_primitive match_expr \\<Rightarrow> string\" where\n  \"common_primitive_match_expr_toString toStr MatchAny = ''''\" |\n  \"common_primitive_match_expr_toString toStr (Match m) = toStr m\" |\n  \"common_primitive_match_expr_toString toStr (MatchAnd m1 m2) =\n      common_primitive_match_expr_toString toStr m1 @'' '' @ common_primitive_match_expr_toString toStr m2\" |\n  \"common_primitive_match_expr_toString toStr (MatchNot (Match m)) = ''! ''@toStr m\" |\n  \"common_primitive_match_expr_toString toStr (MatchNot m) = ''NOT (''@common_primitive_match_expr_toString toStr m@'')''\"\n\ndefinition common_primitive_match_expr_ipv4_toString :: \"32 common_primitive match_expr \\<Rightarrow> string\" where\n  \"common_primitive_match_expr_ipv4_toString \\<equiv> common_primitive_match_expr_toString common_primitive_ipv4_toString\"\n\ndefinition common_primitive_match_expr_ipv6_toString :: \"128 common_primitive match_expr \\<Rightarrow> string\" where\n  \"common_primitive_match_expr_ipv6_toString \\<equiv> common_primitive_match_expr_toString common_primitive_ipv6_toString\"\n\nfun common_primitive_rule_toString :: \"32 common_primitive rule \\<Rightarrow> string\" where\n  \"common_primitive_rule_toString (Rule m a) = common_primitive_match_expr_ipv4_toString m @'' ''@action_toString a\"\n\n\nend\n", "meta": {"author": "diekmann", "repo": "Iptables_Semantics", "sha": "e0a2516bd885708fce875023b474ae341cbdee29", "save_path": "github-repos/isabelle/diekmann-Iptables_Semantics", "path": "github-repos/isabelle/diekmann-Iptables_Semantics/Iptables_Semantics-e0a2516bd885708fce875023b474ae341cbdee29/thy/Iptables_Semantics/Primitive_Matchers/Common_Primitive_toString.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.665410558746814, "lm_q2_score": 0.4148988457967688, "lm_q1q2_score": 0.2760780728050361}}
{"text": "(*  Title:      JinjaDCI/BV/BVExec.thy\n\n    Author:     Tobias Nipkow, Gerwin Klein, Susannah Mansky\n    Copyright   2000 TUM, 2020 UIUC\n\n    Based on the Jinja theory BV/BVExec.thy by Tobias Nipkow and Gerwin Klein\n*)\n\nsection \\<open> Kildall for the JVM \\label{sec:JVM} \\<close>\n\ntheory BVExec\nimports Jinja.Abstract_BV TF_JVM\nbegin\n\ndefinition kiljvm :: \"jvm_prog \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> ty \\<Rightarrow> \n             instr list \\<Rightarrow> ex_table \\<Rightarrow> ty\\<^sub>i' err list \\<Rightarrow> ty\\<^sub>i' err list\"\nwhere\n  \"kiljvm P mxs mxl T\\<^sub>r is xt \\<equiv>\n  kildall (JVM_SemiType.le P mxs mxl) (JVM_SemiType.sup P mxs mxl) \n          (exec P mxs T\\<^sub>r xt is)\"\n\ndefinition wt_kildall :: \"jvm_prog \\<Rightarrow> cname \\<Rightarrow> staticb \\<Rightarrow> ty list \\<Rightarrow> ty \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> \n                 instr list \\<Rightarrow> ex_table \\<Rightarrow> bool\"\nwhere\n  \"wt_kildall P C' b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt \\<equiv>\n   0 < size is \\<and> \n   (let first  = Some ([],(case b of Static \\<Rightarrow> [] | NonStatic \\<Rightarrow> [OK (Class C')])\n                            @(map OK Ts)@(replicate mxl\\<^sub>0 Err));\n        start  = (OK first)#(replicate (size is - 1) (OK None));\n        result = kiljvm P mxs\n                   ((case b of Static \\<Rightarrow> 0 | NonStatic \\<Rightarrow> 1)+size Ts+mxl\\<^sub>0)\n                     T\\<^sub>r is xt start\n    in \\<forall>n < size is. result!n \\<noteq> Err)\"\n\ndefinition wf_jvm_prog\\<^sub>k :: \"jvm_prog \\<Rightarrow> bool\"\nwhere\n  \"wf_jvm_prog\\<^sub>k P \\<equiv>\n  wf_prog (\\<lambda>P C' (M,b,Ts,T\\<^sub>r,(mxs,mxl\\<^sub>0,is,xt)). wt_kildall P C' b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt) P\"\n\n\ntheorem (in start_context) is_bcv_kiljvm:\n  \"is_bcv r Err step (size is) A (kiljvm P mxs mxl T\\<^sub>r is xt)\"\n(*<*)\nproof -\n  let ?n = \"length is\"\n  have \"Semilat A r f\" using semilat_JVM[OF wf]\n    by (simp add: Semilat.intro sl_def2)\n  moreover have \"acc r\" using wf by simp blast\n  moreover have \"top r Err\" by (simp add: JVM_le_unfold)\n  moreover have \"pres_type step ?n A\" by (rule exec_pres_type)\n  moreover have \"bounded step ?n\" by (rule bounded_step)\n  moreover have \"mono r step ?n A\" using step_mono[OF wf] by simp\n  ultimately have \"is_bcv r Err step ?n A (kildall r f step)\"\n    by(rule is_bcv_kildall)\n  moreover have kileq: \"kiljvm P mxs mxl T\\<^sub>r is xt = kildall r f step\"\n    using f_def kiljvm_def r_def step_def_exec by blast\n  ultimately show ?thesis by simp\nqed\n(*>*)\n\n(* FIXME: move? *)\nlemma subset_replicate [intro?]: \"set (replicate n x) \\<subseteq> {x}\"\n  by (induct n) auto\n\nlemma in_set_replicate:\n  assumes \"x \\<in> set (replicate n y)\"\n  shows \"x = y\"\n(*<*)\nproof -\n  note assms\n  also have \"set (replicate n y) \\<subseteq> {y}\" ..\n  finally show ?thesis by simp\nqed\n(*>*)\n\nlemma (in start_context) start_in_A [intro?]:\n  \"0 < size is \\<Longrightarrow> start \\<in> list (size is) A\"\n  using Ts C\n(*<*)\nproof(cases b)\nqed (force simp: JVM_states_unfold intro!: listI list_appendI\n           dest!: in_set_replicate)+\n(*>*)\n\n\ntheorem (in start_context) wt_kil_correct:\n  assumes wtk: \"wt_kildall P C b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt\"\n  shows \"\\<exists>\\<tau>s. wt_method P C b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt \\<tau>s\"\n(*<*)\nproof -\n  from wtk obtain res where    \n    result:   \"res = kiljvm P mxs mxl T\\<^sub>r is xt start\" and\n    success:  \"\\<forall>n < size is. res!n \\<noteq> Err\" and\n    instrs:   \"0 < size is\" \n    by (unfold wt_kildall_def) simp\n      \n  have bcv: \"is_bcv r Err step (size is) A (kiljvm P mxs mxl T\\<^sub>r is xt)\"\n    by (rule is_bcv_kiljvm)\n    \n  from instrs have \"start \\<in> list (size is) A\" ..\n  with bcv success result have \n    \"\\<exists>ts\\<in>list (size is) A. start [\\<sqsubseteq>\\<^sub>r] ts \\<and> wt_step r Err step ts\"\n    by (unfold is_bcv_def) blast\n  then obtain \\<tau>s' where\n    in_A: \"\\<tau>s' \\<in> list (size is) A\" and\n    s:    \"start [\\<sqsubseteq>\\<^sub>r] \\<tau>s'\" and\n    w:    \"wt_step r Err step \\<tau>s'\"\n    by blast\n  hence wt_err_step: \"wt_err_step (sup_state_opt P) step \\<tau>s'\"\n    by (simp add: wt_err_step_def JVM_le_Err_conv)\n\n  from in_A have l: \"size \\<tau>s' = size is\" by simp  \n  moreover {\n    from in_A  have \"check_types P mxs mxl \\<tau>s'\" by (simp add: check_types_def)\n    also from w have \"\\<forall>x \\<in> set \\<tau>s'. x \\<noteq> Err\" \n      by (auto simp add: wt_step_def all_set_conv_all_nth)\n    hence [symmetric]: \"map OK (map ok_val \\<tau>s') = \\<tau>s'\" \n      by (auto intro!: map_idI simp add: wt_step_def)\n    finally  have \"check_types P mxs mxl (map OK (map ok_val \\<tau>s'))\" .\n  } \n  moreover {  \n    from s have \"start!0 \\<sqsubseteq>\\<^sub>r \\<tau>s'!0\" by (rule le_listD) simp\n    moreover\n    from instrs w l \n    have \"\\<tau>s'!0 \\<noteq> Err\" by (unfold wt_step_def) simp\n    then obtain \\<tau>s0 where \"\\<tau>s'!0 = OK \\<tau>s0\" by auto\n    ultimately\n    have \"wt_start P C b Ts mxl\\<^sub>0 (map ok_val \\<tau>s')\" using l instrs\n      by (unfold wt_start_def) \n         (cases b; simp add: lesub_def JVM_le_Err_conv Err.le_def)\n  }\n  moreover \n  from in_A have \"set \\<tau>s' \\<subseteq> A\" by simp  \n  with wt_err_step bounded_step\n  have \"wt_app_eff (sup_state_opt P) app eff (map ok_val \\<tau>s')\"\n    by (auto intro: wt_err_imp_wt_app_eff simp add: l)\n  ultimately\n  have \"wt_method P C b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt (map ok_val \\<tau>s')\"\n    using instrs by (simp add: wt_method_def2 check_types_def del: map_map)\n  thus ?thesis by blast\nqed\n(*>*)\n\n\ntheorem (in start_context) wt_kil_complete:\n  assumes wtm: \"wt_method P C b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt \\<tau>s\"\n  shows \"wt_kildall P C b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt\"\n(*<*)\nproof -\n  from wtm obtain\n    instrs:   \"0 < size is\" and\n    length:   \"length \\<tau>s = length is\" and \n    ck_type:  \"check_types P mxs mxl (map OK \\<tau>s)\" and\n    wt_start: \"wt_start P C b Ts mxl\\<^sub>0 \\<tau>s\" and\n    app_eff:  \"wt_app_eff (sup_state_opt P) app eff \\<tau>s\"\n    by (simp add: wt_method_def2 check_types_def)\n\n  from ck_type\n  have in_A: \"set (map OK \\<tau>s) \\<subseteq> A\" \n    by (simp add: check_types_def)  \n  with app_eff in_A bounded_step\n  have \"wt_err_step (sup_state_opt P) (err_step (size \\<tau>s) app eff) (map OK \\<tau>s)\"\n    by - (erule wt_app_eff_imp_wt_err,\n          auto simp add: exec_def length states_def)\n  hence wt_err: \"wt_err_step (sup_state_opt P) step (map OK \\<tau>s)\" \n    by (simp add: length)\n  have is_bcv: \"is_bcv r Err step (size is) A (kiljvm P mxs mxl T\\<^sub>r is xt)\"\n    by (rule is_bcv_kiljvm)\n  moreover from instrs have \"start \\<in> list (size is) A\" ..\n  moreover\n  let ?\\<tau>s = \"map OK \\<tau>s\"  \n  have less_\\<tau>s: \"start [\\<sqsubseteq>\\<^sub>r] ?\\<tau>s\"\n  proof (rule le_listI)\n    from length instrs\n    show \"length start = length (map OK \\<tau>s)\" by simp\n  next\n    fix n\n    from wt_start have \"P \\<turnstile> ok_val (start!0) \\<le>' \\<tau>s!0\" \n      by (cases b; simp add: wt_start_def)\n    moreover from instrs length have \"0 < length \\<tau>s\" by simp\n    ultimately have \"start!0 \\<sqsubseteq>\\<^sub>r ?\\<tau>s!0\" \n      by (simp add: JVM_le_Err_conv lesub_def)\n    moreover {\n      fix n'\n      have \"OK None \\<sqsubseteq>\\<^sub>r ?\\<tau>s!n\"\n        by (auto simp add: JVM_le_Err_conv Err.le_def lesub_def \n                 split: err.splits)\n      hence \"\\<lbrakk>n = Suc n'; n < size start\\<rbrakk> \\<Longrightarrow> start!n \\<sqsubseteq>\\<^sub>r ?\\<tau>s!n\" by simp\n    }\n    ultimately\n    show \"n < size start \\<Longrightarrow> start!n \\<sqsubseteq>\\<^sub>r ?\\<tau>s!n\" by (cases n, blast+)   \n  qed\n  moreover\n  from ck_type length\n  have \"?\\<tau>s \\<in> list (size is) A\"\n    by (auto intro!: listI simp add: check_types_def)\n  moreover\n  from wt_err have \"wt_step r Err step ?\\<tau>s\" \n    by (simp add: wt_err_step_def JVM_le_Err_conv)\n  ultimately\n  have \"\\<forall>p. p < size is \\<longrightarrow> kiljvm P  mxs mxl T\\<^sub>r is xt start ! p \\<noteq> Err\" \n    by (unfold is_bcv_def) blast\n  with instrs \n  show \"wt_kildall P C b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt\" by (unfold wt_kildall_def) simp\nqed\n(*>*)\n\n\ntheorem jvm_kildall_correct:\n  \"wf_jvm_prog\\<^sub>k P = wf_jvm_prog P\"\n(*<*)\nproof -\n  let ?\\<Phi> = \"\\<lambda>C M. let (C,b,Ts,T\\<^sub>r,(mxs,mxl\\<^sub>0,is,xt)) = method P C M in \n              SOME \\<tau>s. wt_method P C b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt \\<tau>s\"\n  let ?A = \"\\<lambda>P C' (M, b, Ts, T\\<^sub>r, mxs, mxl\\<^sub>0, is, xt). wt_kildall P C' b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt\"\n  let ?B\\<^sub>\\<Phi> = \"\\<lambda>\\<Phi>. (\\<lambda>P C (M,b,Ts,T\\<^sub>r,(mxs,mxl\\<^sub>0,is,xt)). \n                wt_method P C b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt (\\<Phi> C M))\"\n\n  show ?thesis proof(rule iffI)\n    \\<comment> \\<open>soundness\\<close>\n    assume wt: \"wf_jvm_prog\\<^sub>k P\"\n    then have \"wf_prog ?A P\" by(simp add: wf_jvm_prog\\<^sub>k_def)\n    moreover {\n      fix wf_md C M b Ts Ca T m bd\n      assume \"wf_prog wf_md P\" and sees: \"P \\<turnstile> Ca sees M, b :  Ts\\<rightarrow>T = m in Ca\" and\n             \"set Ts \\<subseteq> types P\" and \"bd = (M, b, Ts, T, m)\" and\n             \"?A P Ca bd\"\n      then have \"(?B\\<^sub>\\<Phi> ?\\<Phi>) P Ca bd\" using sees_method_is_class[OF sees]\n        by (auto dest!: start_context.wt_kil_correct [OF start_context.intro] \n                 intro: someI)\n    }\n    ultimately have \"wf_prog (?B\\<^sub>\\<Phi> ?\\<Phi>) P\" by(rule wf_prog_lift)\n    then have \"wf_jvm_prog\\<^bsub>?\\<Phi>\\<^esub> P\" by (simp add: wf_jvm_prog_phi_def)\n    thus \"wf_jvm_prog P\" by (unfold wf_jvm_prog_def) fast\n  next  \n    \\<comment> \\<open>completeness\\<close>\n    assume wt: \"wf_jvm_prog P\"\n    then obtain \\<Phi> where \"wf_prog (?B\\<^sub>\\<Phi> \\<Phi>) P\" by(clarsimp simp: wf_jvm_prog_def wf_jvm_prog_phi_def)\n    moreover {\n      fix wf_md C M b Ts Ca T m bd\n      assume \"wf_prog wf_md P\" and sees: \"P \\<turnstile> Ca sees M, b :  Ts\\<rightarrow>T = m in Ca\" and\n             \"set Ts \\<subseteq> types P\" and \"bd = (M, b, Ts, T, m)\" and\n             \"(?B\\<^sub>\\<Phi> \\<Phi>) P Ca bd\"\n      then have \"?A P Ca bd\" using sees_method_is_class[OF sees]\n        by (auto intro!: start_context.wt_kil_complete start_context.intro)\n    }\n    ultimately have \"wf_prog ?A P\" by(rule wf_prog_lift)\n    thus \"wf_jvm_prog\\<^sub>k P\" by (simp add: wf_jvm_prog\\<^sub>k_def)\n  qed\nqed\n(*>*)\n\nend\n", "meta": {"author": "zabihullah331", "repo": "barakzai", "sha": "793257c1d71ec75a299fc6b5843af756ead2afb0", "save_path": "github-repos/isabelle/zabihullah331-barakzai", "path": "github-repos/isabelle/zabihullah331-barakzai/barakzai-793257c1d71ec75a299fc6b5843af756ead2afb0/thys/JinjaDCI/BV/BVExec.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5888891451980403, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.2760657113907823}}
{"text": "(*  Title:      SSA_Semantics.thy\n    Author:     Sebastian Ullrich\n*)\n\nsection {* Proof of Semantic Equivalence *}\n\ntheory SSA_Semantics\nimports SSA_CFG\nbegin\n\ntype_synonym ('node, 'var) state = \"'var \\<rightharpoonup> 'node\"\n\ncontext CFG_SSA_Transformed\nbegin\n  definition step ::\n    \"'node \\<Rightarrow> ('node, 'var) state \\<Rightarrow> ('node, 'var) state\"\n  where\n    \"step m s v \\<equiv> if v \\<in> oldDefs m then Some m else s v\"\n\n  no_notation Refine_Basic.conc_fun (\"\\<Down>\")\n\n  inductive bs :: \"'node list \\<Rightarrow> ('node, 'var) state \\<Rightarrow> bool\" (infix \"\\<Down>\" 50)\n  where\n    \"Entry\\<comment>ns\\<rightarrow>last ns \\<Longrightarrow> ns\\<Down>(fold (step) ns Map.empty)\"\n\n\n  definition ssaStep ::\n    \"'node \\<Rightarrow> nat \\<Rightarrow> ('node, 'val) state \\<Rightarrow> ('node, 'val) state\"\n  where\n    \"ssaStep m i s v \\<equiv>\n      if v \\<in> defs m then\n        Some m\n      else\n        case phis (m,v) of\n          Some phiParams \\<Rightarrow> s (phiParams ! i)\n        | None \\<Rightarrow> s v\"\n\n  inductive ssaBS :: \"'node list \\<Rightarrow> ('node, 'val) state \\<Rightarrow> bool\" (infix \"\\<Down>\\<^sub>s\" 50)\n  where\n    empty: \"[Entry]\\<Down>\\<^sub>s(ssaStep (Entry) 0 Map.empty)\"\n  | snoc: \"\\<lbrakk>ns\\<Down>\\<^sub>ss; last ns = predecessors m ! i; m \\<in> set \\<alpha>n; i < length (predecessors m)\\<rbrakk> \\<Longrightarrow>\n            (ns@[m])\\<Down>\\<^sub>s(ssaStep m i s)\"\n\n  lemma ssaBS_I:\n    assumes \"Entry\\<comment>ns\\<rightarrow>n\"\n    obtains s where \"ns\\<Down>\\<^sub>ss\"\n  using assms\n  proof (atomize_elim, induction rule:path2_rev_induct)\n    case (snoc ns m' m)\n    then obtain s where s: \"ns\\<Down>\\<^sub>ss\" by auto\n    from snoc.hyps(2) obtain i where \"m' = predecessors m ! i\" \"i < length (predecessors m)\" by (auto simp:in_set_conv_nth)\n    with snoc.hyps snoc.prems s show ?case by -(rule exI, erule ssaBS.snoc, auto dest:path2_last)\n  qed (auto intro: ssaBS.empty)\n\n  lemma ssaBS_nonempty[simp]: \"\\<not> ([]\\<Down>\\<^sub>ss)\"\n  by (rule notI, cases rule: ssaBS.cases, auto)\n\n  lemma ssaBS_hd[simp]: \"ns\\<Down>\\<^sub>ss \\<Longrightarrow> hd ns = Entry\"\n    apply (induction rule: ssaBS.induct)\n     apply (auto simp: hd_append)[1]\n    by (case_tac ns; simp)\n\n  lemma equiv_aux:\n    assumes \"ns\\<Down>s\" \"ns\\<Down>\\<^sub>ss'\" \"last ns\\<comment>ms\\<rightarrow>m\" \"v \\<in> allUses m\" \"\\<forall>n \\<in> set (tl ms). var v \\<notin> var ` allDefs n\"\n    shows \"s (var v) = s' v\"\n  using assms(2) assms(1,3-) proof (induction arbitrary: v s ms m)\n    case empty\n    have \"v \\<in> defs (Entry)\"\n    proof-\n      from empty.prems(2,3) have \"defAss m v\" by - (rule allUses_def_ass, auto)\n      with empty.prems(2) obtain n where n: \"n \\<in> set ms\" \"v \\<in> allDefs n\" by - (drule defAssD, auto)\n      with empty.prems(4) have \"n \\<notin> set (tl ms)\" by auto\n      with empty.prems(2) n have \"n = Entry\" by (cases ms, auto dest: path2_hd)\n      with n(2) show ?thesis by (auto simp: allDefs_def)\n    qed\n    with empty.prems(1) show ?case\n      by - (erule bs.cases, auto simp: step_def ssaStep_def oldDefs_def split: option.split)\n  next\n    case (snoc ns s' n i)\n    from snoc.prems(2) have[simp]: \"n \\<in> set \\<alpha>n\" \"m \\<in> set \\<alpha>n\" by auto\n    from snoc.prems(2,3) have[simp]: \"v \\<in> allVars\" by - (rule allUses_in_allVars, auto)\n    from snoc.hyps(4) have[simp]: \"n \\<noteq> Entry\" using Entry_unreachable len_greater_imp_nonempty by blast\n\n    show ?case\n    proof (cases \"var v \\<in> var ` allDefs n\")\n      case True\n\n      have[simp]: \"defNode v = n\" (is \"?n\\<^sub>v = _\")\n      proof-\n        from True obtain v' where v': \"v' \\<in> allDefs n\" \"var v' = var v\" by auto\n        from snoc.prems(3) have \"defAss m v\" by - (rule allUses_def_ass, auto)\n        moreover from snoc.prems(1) obtain ns' where ns': \"Entry\\<comment>ns'\\<rightarrow>n\" \"set ns' \\<subseteq> set (ns@[n])\" \"distinct ns'\"\n          by (auto elim!: bs.cases intro: simple_path2)\n        ultimately have \"?n\\<^sub>v \\<in> set (ns'@tl ms)\"\n          using snoc.prems(2) by - (drule defAss_defNode, auto elim!: bs.cases dest: path2_app)\n        moreover {\n          let ?n'' = \"last (butlast ns')\"\n          assume asm: \"?n\\<^sub>v \\<in> set (butlast ns')\"\n          with ns'(1,3) have[simp]: \"?n\\<^sub>v \\<noteq> n\" by (cases ns' rule: rev_cases, auto dest!: path2_last)\n          from ns'(1) have \"length ns' \\<ge> 2\" using \\<open>n \\<noteq> Entry\\<close> path2_nontrivial by blast\n          with ns' have bns': \"Entry\\<comment>butlast ns'\\<rightarrow>?n''\" \"?n'' \\<in> set (predecessors n)\"\n            by (auto elim: path2_unsnoc)\n          with asm obtain ns'' where ns'': \"?n\\<^sub>v\\<comment>ns''\\<rightarrow>?n''\" \"suffixeq ns'' (butlast ns')\" \"?n\\<^sub>v \\<notin> set (tl ns'')\"\n            by - (rule path2_split_first_last, auto)\n          with bns' snoc.prems(2) have \"?n\\<^sub>v\\<comment>(ns''@[n])@tl ms\\<rightarrow>m\" by - (rule path2_app, auto)\n          hence \"defNode v' \\<notin> set (tl (ns''@[n]@tl ms))\"\n            using v' snoc.prems(3,4) bns'(2) ns''(1,3)\n            by - (rule conventional''[of v _ m], auto intro!: path2_app simp: path2_not_Nil)\n          with ns' ns''(1) v'(1) have False by (auto simp: path2_not_Nil)\n        }\n        ultimately show ?thesis using snoc.prems(4) ns'(1) by (cases ns' rule: rev_cases, auto dest: path2_last)\n      qed\n      from `v \\<in> allVars` show ?thesis\n      proof (cases rule: defNode_cases)\n        case simpleDef\n        thus ?thesis using snoc.prems(1) by - (erule bs.cases, auto simp: step_def ssaStep_def oldDefs_def)\n      next\n        case phi\n        {\n          fix v'\n          assume asm: \"v' \\<in> defs n\" \"var v = var v'\"\n          with phi have \"v' = v\" using allDefs_var_disjoint[of n v' v]\n            \\<open>defNode v = n\\<close> \\<open>v \\<in> allVars\\<close> defNode(2) defs_in_allDefs snoc.hyps(3) by blast\n          with asm(1) phi have False using simpleDefs_phiDefs_disjoint[of n]\n            by (auto dest!: phi_phiDefs)\n        }\n        note 1 = this\n        {\n          fix vs\n          assume asm: \"Entry\\<comment>ns @ [n]\\<rightarrow>n\" \"phis (n, v) = Some vs\" \"var v \\<notin> var ` defs n\"\n          let ?n' = \"last ns\"\n          from asm(1) have \"length ns \\<ge> 1\"\n            by (metis One_nat_def \\<open>n \\<noteq> Entry\\<close> append_Nil graph_path_base.path2_def le_0_eq length_0_conv list.sel(1) not_less_eq_eq)\n          hence \"Entry\\<comment>ns\\<rightarrow>?n'\"\n            by - (rule path2_unsnoc[OF asm(1)], auto)\n          moreover have \"vs ! i \\<in> phiUses ?n'\" using snoc.hyps(2,4) phis_wf[OF asm(2)]\n            by - (rule phiUsesI[OF _ asm(2)], auto simp: set_zip)\n          ultimately have \"fold (step) ns Map.empty (var (vs ! i)) = s' (vs ! i)\"\n          by - (rule snoc.IH[where ms4=\"[?n']\" and m4=\"?n'\"], auto intro!: bs.intros)\n          hence \"fold (step) ns Map.empty (var v) = s' (vs ! i)\" using phis_same_var[OF asm(2), of \"vs ! i\"] snoc.hyps(4) phis_wf[OF asm(2)]\n            by auto\n        }\n        thus ?thesis using phi snoc.prems(1)\n          by - (erule bs.cases, auto dest!: 1 simp: step_def ssaStep_def oldDefs_def phi_def)\n      qed\n    next\n      case False\n      hence \"phis (n, v) = None\" by (auto simp: allDefs_def phiDefs_def)\n      moreover have \"fold (step) ns Map.empty (var v) = s' v\"\n      proof-\n        from snoc.hyps(1) have \"length ns \\<ge> 1\" by (cases ns, auto)\n        moreover from snoc.prems(2,4) False have \"\\<forall>n \\<in> set ms. var v \\<notin> var ` allDefs n\"\n          by (cases ms, auto simp: phiDefs_def dest: path2_hd)\n        ultimately show ?thesis\n          using snoc.prems(1,2,3) by - (rule snoc.IH[where ms4=\"last ns#ms\"], auto elim!: bs.cases intro!: bs.intros elim: path2_unsnoc intro!: Cons_path2)\n      qed\n      ultimately show ?thesis\n        using snoc.prems(1) False by - (erule bs.cases, auto simp: step_def ssaStep_def oldDefs_def defs_in_allDefs)\n    qed\n  qed\n\n  theorem equiv:\n    assumes \"ns\\<Down>s\" \"ns\\<Down>\\<^sub>ss'\" \"v \\<in> uses (last ns)\"\n    shows \"s (var v) = s' v\"\n  using assms by - (rule equiv_aux[where ms=\"[last ns]\"], auto elim!: bs.cases)\nend\n\nend\n", "meta": {"author": "lohner", "repo": "FormalSSA", "sha": "34253ae0ea0db6ef78b644f41ab5e9d0bde6c32e", "save_path": "github-repos/isabelle/lohner-FormalSSA", "path": "github-repos/isabelle/lohner-FormalSSA/FormalSSA-34253ae0ea0db6ef78b644f41ab5e9d0bde6c32e/SSA_Semantics.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.27606570462603597}}
{"text": "(*  Title:      JinjaThreads/Compiler/Compiler1.thy\n    Author:     Andreas Lochbihler, Tobias Nipkow\n\n    Based on Jinja/Compiler/Compiler1\n*)\n\nheader {* \\isaheader{Compilation Stage 1} *}\n\ntheory Compiler1 imports\n  PCompiler\n  J1State\n  ListIndex \nbegin\n\ndefinition fresh_var :: \"vname list \\<Rightarrow> vname\"\nwhere \"fresh_var Vs \\<equiv> Auxiliary.concat (STR ''V'' # Vs)\"\n\nlemma fresh_var_fresh: \"fresh_var Vs \\<notin> set Vs\"\nproof -\n  have \"\\<forall>V \\<in> set Vs. length (String.explode V) < length (String.explode (fresh_var Vs))\"\n    by(induct Vs)(auto simp add: fresh_var_def Auxiliary.concat_def STR_inverse implode_def)\n  thus ?thesis by auto\nqed\n\ntext{* Replacing variable names by indices. *}\n\nfunction compE1  :: \"vname list \\<Rightarrow> 'addr expr      \\<Rightarrow> 'addr expr1\"\n  and compEs1 :: \"vname list \\<Rightarrow> 'addr expr list \\<Rightarrow> 'addr expr1 list\"\nwhere\n  \"compE1 Vs (new C) = new C\"\n| \"compE1 Vs (newA T\\<lfloor>e\\<rceil>) = newA T\\<lfloor>compE1 Vs e\\<rceil>\"\n| \"compE1 Vs (Cast T e) = Cast T (compE1 Vs e)\"\n| \"compE1 Vs (e instanceof T) = (compE1 Vs e) instanceof T\"\n| \"compE1 Vs (Val v) = Val v\"\n| \"compE1 Vs (Var V) = Var(index Vs V)\"\n| \"compE1 Vs (e\\<guillemotleft>bop\\<guillemotright>e') = (compE1 Vs e)\\<guillemotleft>bop\\<guillemotright>(compE1 Vs e')\"\n| \"compE1 Vs (V:=e) = (index Vs V):= (compE1 Vs e)\"\n| \"compE1 Vs (a\\<lfloor>i\\<rceil>) = (compE1 Vs a)\\<lfloor>compE1 Vs i\\<rceil>\"\n| \"compE1 Vs (a\\<lfloor>i\\<rceil>:=e) = (compE1 Vs a)\\<lfloor>compE1 Vs i\\<rceil>:=compE1 Vs e\"\n| \"compE1 Vs (a\\<bullet>length) = compE1 Vs a\\<bullet>length\"\n| \"compE1 Vs (e\\<bullet>F{D}) = compE1 Vs e\\<bullet>F{D}\"\n| \"compE1 Vs (e\\<bullet>F{D}:=e') = compE1 Vs e\\<bullet>F{D}:=compE1 Vs e'\"\n| \"compE1 Vs (e\\<bullet>M(es)) = (compE1 Vs e)\\<bullet>M(compEs1 Vs es)\"\n| \"compE1 Vs {V:T=vo; e} = {(size Vs):T=vo; compE1 (Vs@[V]) e}\"\n| \"compE1 Vs (sync\\<^bsub>U\\<^esub> (o') e) = sync\\<^bsub>length Vs\\<^esub> (compE1 Vs o') (compE1 (Vs@[fresh_var Vs]) e)\"\n| \"compE1 Vs (insync\\<^bsub>U\\<^esub> (a) e) = insync\\<^bsub>length Vs\\<^esub> (a) (compE1 (Vs@[fresh_var Vs]) e)\"\n| \"compE1 Vs (e1;;e2) = (compE1 Vs e1);;(compE1 Vs e2)\"\n| \"compE1 Vs (if (b) e1 else e2) = (if (compE1 Vs b) (compE1 Vs e1) else (compE1 Vs e2))\"\n| \"compE1 Vs (while (b) e) = (while (compE1 Vs b) (compE1 Vs e))\"\n| \"compE1 Vs (throw e) = throw (compE1 Vs e)\"\n| \"compE1 Vs (try e1 catch(C V) e2) = try(compE1 Vs e1) catch(C (size Vs)) (compE1 (Vs@[V]) e2)\"\n\n| \"compEs1 Vs []     = []\"\n| \"compEs1 Vs (e#es) = compE1 Vs e # compEs1 Vs es\"\nby pat_completeness auto\ntermination\napply(relation \"case_sum (\\<lambda>p. size (snd p)) (\\<lambda>p. size_list size (snd p)) <*mlex*> {}\")\napply(rule wf_mlex[OF wf_empty])\napply(rule mlex_less, simp)+\ndone\n\nlemmas compE1_compEs1_induct =\n  compE1_compEs1.induct[case_names New NewArray Cast InstanceOf Val Var BinOp LAss AAcc AAss ALen FAcc FAss Call Block Synchronized InSynchronized Seq Cond While throw TryCatch Nil Cons]\n\nlemma compEs1_conv_map [simp]: \"compEs1 Vs es = map (compE1 Vs) es\"\nby(induct es) simp_all\n\nlemmas compEs1_map_Val = compEs1_conv_map\n\nlemma compE1_eq_Val [simp]: \"compE1 Vs e = Val v \\<longleftrightarrow> e = Val v\"\napply(cases e, auto)\ndone\n\nlemma Val_eq_compE1 [simp]: \"Val v = compE1 Vs e \\<longleftrightarrow> e = Val v\"\napply(cases e, auto)\ndone\n\nlemma compEs1_eq_map_Val [simp]: \"compEs1 Vs es = map Val vs \\<longleftrightarrow> es = map Val vs\"\napply(induct es arbitrary: vs)\napply(auto, blast)\ndone\n\nlemma compE1_eq_Var [simp]: \"compE1 Vs e = Var V \\<longleftrightarrow> (\\<exists>V'. e = Var V' \\<and> V = index Vs V')\"\nby(cases e, auto)\n\nlemma compE1_eq_Call [simp]:\n  \"compE1 Vs e = obj\\<bullet>M(params) \\<longleftrightarrow> (\\<exists>obj' params'. e = obj'\\<bullet>M(params') \\<and> compE1 Vs obj' = obj \\<and> compEs1 Vs params' = params)\"\nby(cases e, auto)\n\nlemma length_compEs2 [simp]:\n  \"length (compEs1 Vs es) = length es\"\nby(simp add: compEs1_conv_map)\n\nlemma fixes e :: \"'addr expr\" and es :: \"'addr expr list\"\n  shows expr_locks_compE1 [simp]: \"expr_locks (compE1 Vs e) = expr_locks e\"\n  and expr_lockss_compEs1 [simp]: \"expr_lockss (compEs1 Vs es) = expr_lockss es\"\nby(induct Vs e and Vs es rule: compE1_compEs1.induct)(auto intro: ext)\n\nlemma fixes e :: \"'addr expr\" and es :: \"'addr expr list\"\n  shows contains_insync_compE1 [simp]: \"contains_insync (compE1 Vs e) = contains_insync e\"\n  and contains_insyncs_compEs1 [simp]: \"contains_insyncs (compEs1 Vs es) = contains_insyncs es\"\nby(induct Vs e and Vs es rule: compE1_compEs1.induct)simp_all\n\nlemma fixes e :: \"'addr expr\" and es :: \"'addr expr list\"\n  shows max_vars_compE1: \"max_vars (compE1 Vs e) = max_vars e\"\n  and max_varss_compEs1: \"max_varss (compEs1 Vs es) = max_varss es\"\napply(induct Vs e and Vs es rule: compE1_compEs1.induct)\napply(auto)\ndone\n\nlemma fixes e :: \"'addr expr\" and es :: \"'addr expr list\"\n  shows \\<B>: \"size Vs = n \\<Longrightarrow> \\<B> (compE1 Vs e) n\"\n  and \\<B>s: \"size Vs = n \\<Longrightarrow> \\<B>s (compEs1 Vs es) n\"\napply(induct Vs e and Vs es arbitrary: n and n rule: compE1_compEs1.induct)\napply auto\ndone\n\nlemma fixes e :: \"'addr expr\" and es :: \"'addr expr list\"\n  shows fv_compE1: \"fv e \\<subseteq> set Vs \\<Longrightarrow> fv (compE1 Vs e) = (index Vs) ` (fv e)\"\n  and fvs_compEs1: \"fvs es \\<subseteq> set Vs \\<Longrightarrow> fvs (compEs1 Vs es) = (index Vs) ` (fvs es)\"\nproof(induct Vs e and Vs es rule: compE1_compEs1_induct)\n  case (Block Vs V ty vo exp)\n  have IH: \"fv exp \\<subseteq> set (Vs @ [V]) \\<Longrightarrow> fv (compE1 (Vs @ [V]) exp) = index (Vs @ [V]) ` fv exp\" by fact\n  from `fv {V:ty=vo; exp} \\<subseteq> set Vs` have fv': \"fv exp \\<subseteq> set (Vs @ [V])\" by auto\n  from IH[OF this] have IH': \"fv (compE1 (Vs @ [V]) exp) = index (Vs @ [V]) ` fv exp\" .\n  have \"fv (compE1 (Vs @ [V]) exp) - {length Vs} = index Vs ` (fv exp - {V})\"\n  proof(rule equalityI[OF subsetI subsetI])\n    fix x\n    assume x: \"x \\<in> fv (compE1 (Vs @ [V]) exp) - {length Vs}\"\n    hence \"x \\<noteq> length Vs\" by simp\n    from x IH' have \"x \\<in> index (Vs @ [V]) ` fv exp\" by simp\n    thus \"x \\<in> index Vs ` (fv exp - {V})\"\n    proof(rule imageE)\n      fix y\n      assume [simp]: \"x = index (Vs @ [V]) y\"\n        and y: \"y \\<in> fv exp\"\n      have \"y \\<noteq> V\"\n      proof\n        assume [simp]: \"y = V\"\n        hence \"x = length Vs\" by simp\n        with `x \\<noteq> length Vs` show False by contradiction\n      qed\n      moreover with fv' y have \"y \\<in> set Vs\" by auto\n      ultimately have \"index (Vs @ [V]) y = index Vs y\" by(simp)\n      thus ?thesis using y `y \\<noteq> V` by auto\n    qed\n  next\n    fix x\n    assume x: \"x \\<in> index Vs ` (fv exp - {V})\"\n    thus \"x \\<in> fv (compE1 (Vs @ [V]) exp) - {length Vs}\"\n    proof(rule imageE)\n      fix y\n      assume [simp]: \"x = index Vs y\"\n        and y: \"y \\<in> fv exp - {V}\"\n      with fv' have \"y \\<in> set Vs\" \"y \\<noteq> V\" by auto\n      hence \"index Vs y = index (Vs @ [V]) y\" by simp\n      with y have \"x \\<in> index (Vs @ [V]) ` fv exp\" by auto\n      thus ?thesis using IH' `y \\<in> set Vs` by simp\n    qed\n  qed\n  thus ?case by simp\nnext\n  case (Synchronized Vs V exp1 exp2)\n  have IH1: \"fv exp1 \\<subseteq> set Vs \\<Longrightarrow> fv (compE1 Vs exp1) = index Vs ` fv exp1\" \n    and IH2: \"fv exp2 \\<subseteq> set (Vs @ [fresh_var Vs]) \\<Longrightarrow> fv (compE1 (Vs @ [fresh_var Vs]) exp2) = index (Vs @ [fresh_var Vs]) ` fv exp2\"\n    by fact+\n  from `fv (sync\\<^bsub>V\\<^esub> (exp1) exp2) \\<subseteq> set Vs` have fv1: \"fv exp1 \\<subseteq> set Vs\"\n    and fv2: \"fv exp2 \\<subseteq> set Vs\" by auto\n  from fv2 have fv2': \"fv exp2 \\<subseteq> set (Vs @ [fresh_var Vs])\" by auto\n  have \"index (Vs @ [fresh_var Vs]) ` fv exp2 = index Vs ` fv exp2\"\n  proof(rule equalityI[OF subsetI subsetI])\n    fix x\n    assume x: \"x \\<in> index (Vs @ [fresh_var Vs]) ` fv exp2\"\n    thus \"x \\<in> index Vs ` fv exp2\"\n    proof(rule imageE)\n      fix y\n      assume [simp]: \"x = index (Vs @ [fresh_var Vs]) y\"\n        and y: \"y \\<in> fv exp2\"\n      from y fv2 have \"y \\<in> set Vs\" by auto\n      moreover hence \"y \\<noteq> (fresh_var Vs)\" by(auto simp add: fresh_var_fresh)\n      ultimately show ?thesis using y by(auto)\n    qed\n  next\n    fix x\n    assume x: \"x \\<in> index Vs ` fv exp2\"\n    thus \"x \\<in> index (Vs @ [fresh_var Vs]) ` fv exp2\"\n    proof(rule imageE)\n      fix y\n      assume [simp]: \"x = index Vs y\"\n        and y: \"y \\<in> fv exp2\"\n      from y fv2 have \"y \\<in> set Vs\" by auto\n      moreover hence \"y \\<noteq> (fresh_var Vs)\" by(auto simp add: fresh_var_fresh)\n      ultimately have \"index Vs y = index (Vs @ [fresh_var Vs]) y\" by simp\n      thus ?thesis using y by(auto)\n    qed\n  qed\n  with IH1[OF fv1] IH2[OF fv2'] show ?case by(auto)\nnext\n  case (InSynchronized Vs V a exp)\n  have IH: \"fv exp \\<subseteq> set (Vs @ [fresh_var Vs]) \\<Longrightarrow> fv (compE1 (Vs @ [fresh_var Vs]) exp) = index (Vs @ [fresh_var Vs]) ` fv exp\"\n    by fact\n  from `fv (insync\\<^bsub>V\\<^esub> (a) exp) \\<subseteq> set Vs` have fv: \"fv exp \\<subseteq> set Vs\" by simp\n  hence fv': \"fv exp \\<subseteq> set (Vs @ [fresh_var Vs])\" by auto\n  have \"index (Vs @ [fresh_var Vs]) ` fv exp = index Vs ` fv exp\"\n  proof(rule equalityI[OF subsetI subsetI])\n    fix x\n    assume \"x \\<in> index (Vs @ [fresh_var Vs]) ` fv exp\"\n    thus \"x \\<in> index Vs ` fv exp\"\n    proof(rule imageE)\n      fix y\n      assume [simp]: \"x = index (Vs @ [fresh_var Vs]) y\"\n        and y: \"y \\<in> fv exp\"\n      from y fv have \"y \\<in> set Vs\" by auto\n      moreover hence \"y \\<noteq> (fresh_var Vs)\" by(auto simp add: fresh_var_fresh)\n      ultimately have \"index (Vs @ [fresh_var Vs]) y = index Vs y\" by simp\n      thus ?thesis using y by simp\n    qed\n  next\n    fix x\n    assume \"x \\<in> index Vs ` fv exp\"\n    thus \"x \\<in> index (Vs @ [fresh_var Vs]) ` fv exp\"\n    proof(rule imageE)\n      fix y\n      assume [simp]: \"x = index Vs y\"\n        and y: \"y \\<in> fv exp\"\n      from y fv have \"y \\<in> set Vs\" by auto\n      moreover hence \"y \\<noteq> (fresh_var Vs)\" by(auto simp add: fresh_var_fresh)\n      ultimately have \"index Vs y = index (Vs @ [fresh_var Vs]) y\" by simp\n      thus ?thesis using y by auto\n    qed\n  qed\n  with IH[OF fv'] show ?case by simp\nnext\n  case (TryCatch Vs exp1 C V exp2)\n  have IH1: \"fv exp1 \\<subseteq> set Vs \\<Longrightarrow> fv (compE1 Vs exp1) = index Vs ` fv exp1\" \n    and IH2: \"fv exp2 \\<subseteq> set (Vs @ [V]) \\<Longrightarrow> fv (compE1 (Vs @ [V]) exp2) = index (Vs @ [V]) ` fv exp2\"\n    by fact+\n  from `fv (try exp1 catch(C V) exp2) \\<subseteq> set Vs` have fv1: \"fv exp1 \\<subseteq> set Vs\"\n    and fv2: \"fv exp2 \\<subseteq> set (Vs @ [V])\" by auto\n  have \"index (Vs @ [V]) ` fv exp2 - {length Vs} = index Vs ` (fv exp2 - {V})\" \n  proof(rule equalityI[OF subsetI subsetI])\n    fix x\n    assume x: \"x \\<in> index (Vs @ [V]) ` fv exp2 - {length Vs}\"\n    hence \"x \\<noteq> length Vs\" by simp\n    from x have \"x \\<in> index (Vs @ [V]) ` fv exp2\" by auto\n    thus \"x \\<in> index Vs ` (fv exp2 - {V})\"\n    proof(rule imageE)\n      fix y\n      assume [simp]: \"x = index (Vs @ [V]) y\"\n        and y: \"y \\<in> fv exp2\"\n      have \"y \\<noteq> V\"\n      proof\n        assume [simp]: \"y = V\"\n        hence \"x = length Vs\" by simp\n        with `x \\<noteq> length Vs` show False by contradiction\n      qed\n      moreover with fv2 y have \"y \\<in> set Vs\" by auto\n      ultimately have \"index (Vs @ [V]) y = index Vs y\" by(simp)\n      thus ?thesis using y `y \\<noteq> V` by auto\n    qed\n  next\n    fix x\n    assume x: \"x \\<in> index Vs ` (fv exp2 - {V})\"\n    thus \"x \\<in> index (Vs @ [V]) ` fv exp2 - {length Vs}\"\n    proof(rule imageE)\n      fix y\n      assume [simp]: \"x = index Vs y\"\n        and y: \"y \\<in> fv exp2 - {V}\"\n      with fv2 have \"y \\<in> set Vs\" \"y \\<noteq> V\" by auto\n      hence \"index Vs y = index (Vs @ [V]) y\" by simp\n      with y have \"x \\<in> index (Vs @ [V]) ` fv exp2\" by auto\n      thus ?thesis using `y \\<in> set Vs` by simp\n    qed\n  qed\n  with IH1[OF fv1] IH2[OF fv2] show ?case by auto\nqed(auto)\n\nlemma fixes e :: \"'addr expr\" and es :: \"'addr expr list\"\n  shows syncvars_compE1: \"fv e \\<subseteq> set Vs \\<Longrightarrow> syncvars (compE1 Vs e)\"\n  and syncvarss_compEs1: \"fvs es \\<subseteq> set Vs \\<Longrightarrow> syncvarss (compEs1 Vs es)\"\nproof(induct Vs e and Vs es rule: compE1_compEs1_induct)\n  case (Block Vs V ty vo exp)\n  from `fv {V:ty=vo; exp} \\<subseteq> set Vs` have \"fv exp \\<subseteq> set (Vs @ [V])\" by auto\n  from `fv exp \\<subseteq> set (Vs @ [V]) \\<Longrightarrow> syncvars (compE1 (Vs @ [V]) exp)`[OF this] show ?case by(simp)\nnext\n  case (Synchronized Vs V exp1 exp2)\n  note IH1 = `fv exp1 \\<subseteq> set Vs \\<Longrightarrow> syncvars (compE1 Vs exp1)`\n  note IH2 = `fv exp2 \\<subseteq> set (Vs @ [fresh_var Vs]) \\<Longrightarrow> syncvars (compE1 (Vs @ [fresh_var Vs]) exp2)`\n  from `fv (sync\\<^bsub>V\\<^esub> (exp1) exp2) \\<subseteq> set Vs` have fv1: \"fv exp1 \\<subseteq> set Vs\"\n    and fv2: \"fv exp2 \\<subseteq> set Vs\" and fv2': \"fv exp2 \\<subseteq> set (Vs @ [fresh_var Vs])\" by auto\n  have \"length Vs \\<notin> index (Vs @ [fresh_var Vs]) ` fv exp2\"\n  proof\n    assume \"length Vs \\<in> index (Vs @ [fresh_var Vs]) ` fv exp2\"\n    thus False\n    proof(rule imageE)\n      fix x\n      assume x: \"length Vs = index (Vs @ [fresh_var Vs]) x\"\n        and x': \"x \\<in> fv exp2\"\n      from x' fv2 have \"x \\<in> set Vs\" \"x \\<noteq> (fresh_var Vs)\" by(auto simp add: fresh_var_fresh)\n      with x show ?thesis by(simp)\n    qed\n  qed\n  with IH1[OF fv1] IH2[OF fv2'] fv2' show ?case by(simp add: fv_compE1)\nnext\n  case (InSynchronized Vs V a exp)\n  note IH = `fv exp \\<subseteq> set (Vs @ [fresh_var Vs]) \\<Longrightarrow> syncvars (compE1 (Vs @ [fresh_var Vs]) exp)`\n  from `fv (insync\\<^bsub>V\\<^esub> (a) exp) \\<subseteq> set Vs` have fv: \"fv exp \\<subseteq> set Vs\"\n    and fv': \"fv exp \\<subseteq> set (Vs @ [fresh_var Vs])\" by auto\n  have \"length Vs \\<notin> index (Vs @ [fresh_var Vs]) ` fv exp\"\n  proof\n    assume \"length Vs \\<in> index (Vs @ [fresh_var Vs]) ` fv exp\"\n    thus False\n    proof(rule imageE)\n      fix x\n      assume x: \"length Vs = index (Vs @ [fresh_var Vs]) x\"\n        and x': \"x \\<in> fv exp\"\n      from x' fv have \"x \\<in> set Vs\" \"x \\<noteq> (fresh_var Vs)\" by(auto simp add: fresh_var_fresh)\n      with x show ?thesis by(simp)\n    qed\n  qed\n  with IH[OF fv'] fv' show ?case by(simp add: fv_compE1)\nnext\n  case (TryCatch Vs exp1 C V exp2)\n  note IH1 = `fv exp1 \\<subseteq> set Vs \\<Longrightarrow> syncvars (compE1 Vs exp1)`\n  note IH2 = `fv exp2 \\<subseteq> set (Vs @ [V]) \\<Longrightarrow> syncvars (compE1 (Vs @ [V]) exp2)`\n  from `fv (try exp1 catch(C V) exp2) \\<subseteq> set Vs` have fv1: \"fv exp1 \\<subseteq> set Vs\"\n    and fv2: \"fv exp2 \\<subseteq> set (Vs @ [V])\" by auto\n  from IH1[OF fv1] IH2[OF fv2] show ?case by auto\nqed auto\n\nlemma (in heap_base) synthesized_call_compP [simp]:\n  \"synthesized_call (compP f P) h aMvs = synthesized_call P h aMvs\"\nby(simp add: synthesized_call_def)\n\n\nprimrec fin1 :: \"'addr expr \\<Rightarrow> 'addr expr1\"\nwhere\n  \"fin1 (Val v) = Val v\"\n| \"fin1 (throw e) = throw (fin1 e)\"\n\nlemma comp_final: \"final e \\<Longrightarrow> compE1 Vs e = fin1 e\"\nby(erule finalE, simp_all)\n\nlemma fixes e :: \"'addr expr\" and es :: \"'addr expr list\"\n  shows [simp]: \"max_vars (compE1 Vs e) = max_vars e\"\n  and \"max_varss (compEs1 Vs es) = max_varss es\"\nby (induct Vs e and Vs es rule: compE1_compEs1_induct)(simp_all)\n\ntext{* Compiling programs: *}\n\ndefinition compP1 :: \"'addr J_prog \\<Rightarrow> 'addr J1_prog\"\nwhere\n  \"compP1  \\<equiv>  compP (\\<lambda>C M Ts T (pns,body). compE1 (this#pns) body)\"\n\ndeclare compP1_def[simp]\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/JinjaThreads/Compiler/Compiler1.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5888891163376235, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.2760656978612895}}
{"text": "theory ARMv8_Syntax\n  imports ARMv8_Rules ARMv8_Inter\nbegin\n\ndatatype register = r\\<^sub>0 | r\\<^sub>1 | r\\<^sub>2 | r\\<^sub>3 | r\\<^sub>4 | r\\<^sub>5\n\nsyntax\n  \"_quote\"     :: \"'b \\<Rightarrow> ('a \\<Rightarrow> 'b)\"                (\"(\\<guillemotleft>_\\<guillemotright>)\" [0] 1000)\n  \"_antiquote\" :: \"('a \\<Rightarrow> 'b) \\<Rightarrow> 'b\"                (\"\\<acute>_\" [1000] 1000)\n  \"_Assert\"    :: \"'a \\<Rightarrow> 'a set\"                    (\"(\\<llangle>_\\<rrangle>)\" [0] 1000)\n\ntranslations\n  \"\\<llangle>b\\<rrangle>\" \\<rightharpoonup> \"CONST Collect \\<guillemotleft>b\\<guillemotright>\"\n\nparse_translation \\<open>\n  let\n    fun quote_tr [t] = Syntax_Trans.quote_tr \\<^syntax_const>\\<open>_antiquote\\<close> t\n      | quote_tr ts = raise TERM (\"quote_tr\", ts);\n  in [(\\<^syntax_const>\\<open>_quote\\<close>, K quote_tr)] end\n\\<close>\n\ntype_synonym ('v,'r,'a) thread = \"(('v,'a) grel \\<times> ('v,'a) grel \\<times> ('v,'r,'a) pred \\<times> ('v,'r,'a) pred \\<times> ('v,'r,'a) com_armv8 \\<times> ('v,'r,'a) pred)\"\ntype_synonym ('v,'r,'a) threads = \"('v,'r,'a) thread list\"\n\ndefinition addI\n  where \"addI I \\<equiv> \\<lambda>x. x ! 0 + I\"\n\ndefinition subI\n  where \"subI I \\<equiv> \\<lambda>x. x ! 0 - I\"\n\ndefinition addR\n  where \"addR \\<equiv> \\<lambda>x. x ! 0 + x ! 1\"\n\ndefinition subR\n  where \"subR \\<equiv> \\<lambda>x. x ! 0 - x ! 1\"\n\ndefinition modI\n  where \"modI I \\<equiv> \\<lambda>x. x ! 0 mod I\"\n\ndefinition modR\n  where \"modR \\<equiv> \\<lambda>x. x ! 0 mod x ! 1\"\n\ndefinition movI\n  where \"movI I \\<equiv> \\<lambda>x. I\"\n\ndefinition ODD :: \"'b \\<Rightarrow> ((nat,'b) exp \\<times> (nat \\<Rightarrow> nat \\<Rightarrow> bool) \\<times> (nat,'b) exp)\"\n  where \"ODD r = (Exp (\\<lambda>x. x ! 0 mod 2) [Var r], (=), Val 1)\"\n\ndefinition NEQ :: \"'b \\<Rightarrow> 'b \\<Rightarrow> ((nat,'b) exp \\<times> (nat \\<Rightarrow> nat \\<Rightarrow> bool) \\<times> (nat,'b) exp)\"\n  where \"NEQ r1 r2 = (Var r1, (\\<noteq>), Var r2)\"\n\ndefinition LE :: \"'b \\<Rightarrow> 'b \\<Rightarrow> ((nat,'b) bexp)\"\n  where \"LE r1 r2 = Exp\\<^sub>B (\\<lambda>x. x!0 < x!1) [Var r1, Var r2]\"\n\ndefinition Z ::  \"'b \\<Rightarrow> ((nat,'b) bexp)\"\n  where \"Z r = Exp\\<^sub>B (\\<lambda>x. x!0 = 0) [Var r]\"\n\nsyntax\n  \"_Load\"  :: \"'r \\<Rightarrow> 'r \\<Rightarrow> 'v set \\<Rightarrow> ('v,'r,'a) com_armv8\" (\"(_ := [_]~_)\" [70, 65] 61)\n  \"_LoadC\"  :: \"'r \\<Rightarrow> 'r \\<Rightarrow> 'v set \\<Rightarrow> 'c \\<Rightarrow> ('v,'r,'a) com_armv8\" (\"(_ := [_ + #_]~_)\" [70, 65] 61)\n  \"_LoadIC\"  :: \"('v,'r,'a) pred \\<Rightarrow> 'r \\<Rightarrow> 'r \\<Rightarrow> 'v set \\<Rightarrow> 'c \\<Rightarrow> ('v,'r,'a) com_armv8\" (\"(\\<lbrace>_\\<rbrace> _ := [_ + #_]~_)\" [20, 70, 65] 61)\n\n  \"_Store\" :: \"'r \\<Rightarrow> 'r \\<Rightarrow> 'v set \\<Rightarrow> ('v,'r,'a) com_armv8\" (\"([_] := _ ~ _)\" [70, 65] 61)\n  \"_StoreI\" :: \"('v,'r,'a) pred \\<Rightarrow> 'r \\<Rightarrow> 'v \\<Rightarrow> 'r \\<Rightarrow> 'v set \\<Rightarrow> ('v,'r,'a) com_armv8\" (\"(\\<lbrace>_\\<rbrace> [_ + #_] := _ ~ _)\" [20, 70, 65] 61)\n  \"_StoreIA\" :: \"('v,'r,'a) pred \\<Rightarrow> 'r \\<Rightarrow> 'v \\<Rightarrow> 'r \\<Rightarrow> 'v set \\<Rightarrow> ('v,'r,'a) auxfn  \\<Rightarrow> ('v,'r,'a) com_armv8\" (\"(\\<lbrace>_\\<rbrace> [_ + #_] := _ ~ _ :\\<^sub>a _)\" [20, 70, 65] 61)\n  \n  \"_Fence\" :: \"(nat,'b,'a) com_armv8\" (\"(fence)\" 61)\n  \"_CFence\" :: \"(nat,'b,'a) com_armv8\" (\"(cfence)\" 61)\n  \"_Cas\" :: \"('v,'r,'a) pred \\<Rightarrow> 'r \\<Rightarrow> 'r \\<Rightarrow> 'r \\<Rightarrow> 'r \\<Rightarrow> 'v set \\<Rightarrow> ('v,'r,'a) auxfn  \\<Rightarrow> ('v,'b,'a) com_armv8\" (\"(\\<lbrace>_\\<rbrace> _ := cas _ _ _ ~ _, _)\" [20, 70, 65] 61)\n\n  \"_AddI\"  :: \"'b \\<Rightarrow> 'b \\<Rightarrow> nat \\<Rightarrow> (nat,'b,'a) com_armv8\" (\"(_ := _ + #_)\" [70, 65, 65] 61)\n  \"_SubI\"  :: \"'b \\<Rightarrow> 'b \\<Rightarrow> nat \\<Rightarrow> (nat,'b,'a) com_armv8\" (\"(_ := _ - #_)\" [70, 65, 65] 61)\n\n  \"_AddR\"  :: \"'b \\<Rightarrow> 'b \\<Rightarrow> 'b \\<Rightarrow> (nat,'b,'a) com_armv8\" (\"(_ := _ + _)\" [70, 65, 65] 61)\n  \"_SubR\"  :: \"'b \\<Rightarrow> 'b \\<Rightarrow> 'b \\<Rightarrow> (nat,'b,'a) com_armv8\" (\"(_ := _ - _)\" [70, 65, 65] 61)\n\n  \"_ModI\"  :: \"'b \\<Rightarrow> 'b \\<Rightarrow> nat \\<Rightarrow> (nat,'b,'a) com_armv8\" (\"(_ := _ % #_)\" [70, 65, 65] 61)\n  \"_ModR\"  :: \"'b \\<Rightarrow> 'b \\<Rightarrow> 'b \\<Rightarrow> (nat,'b,'a) com_armv8\" (\"(_ := _ % _)\" [70, 65, 65] 61)\n  \"_MovI\"  :: \"'b \\<Rightarrow> nat \\<Rightarrow> (nat,'b,'a) com_armv8\" (\"(_ := #_)\" [70, 65] 61)\n  \"_Seq\"   :: \"(nat,'b,'a) com_armv8 \\<Rightarrow> (nat,'b,'a) com_armv8 \\<Rightarrow> (nat,'b,'a) com_armv8\" (\"(_;/ _)\" [60,61] 60)\n\n  \"_If\" :: \"((nat,'b) exp \\<times> (nat \\<Rightarrow> nat \\<Rightarrow> bool) \\<times> (nat,'b) exp) \\<Rightarrow> (nat,'b,'a) com_armv8 \\<Rightarrow> (nat,'b,'a) com_armv8 \\<Rightarrow> (nat,'b,'a) com_armv8\" \n                (\"(if _/ then _ //else _ /fi)\"   [0,0,0] 61)\n  \"_If1\" :: \"'b \\<Rightarrow> ('v,'r,'a) com_armv8 \\<Rightarrow> ('v,'r,'a) com_armv8\" \n                (\"(if _/ then _ /fi)\"   [0,0] 61)\n  \"_Spec\" :: \"('v,'a) grel \\<Rightarrow> ('v,'a) grel \\<Rightarrow> ('v,'r,'a) pred \\<Rightarrow> ('v,'r,'a) pred \\<Rightarrow> ('v,'r,'a) com_armv8 \\<Rightarrow> ('v,'r,'a) pred \\<Rightarrow> ('v,'r,'a) thread\"\n                (\"(R: _ //G:_ //I: _ //P: _ //{ _ } //Q: _)\" [0,0,0,0] 61)\n  \"_AuxAssign\"    :: \"idt \\<Rightarrow> 'b \\<Rightarrow> ('v,'r,'a) auxfn\" (\"(\\<^sup>a_ :=/ _)\" [70, 65] 61)\n\ntranslations\n  \"\\<^sup>ax := a\" \\<rightharpoonup> \"CONST state_rec.more o \\<guillemotleft>\\<acute>(state_rec.more_update (_update_name x (\\<lambda>_. a)))\\<guillemotright>\"\n\n  \"x := [a]~v\" \\<rightharpoonup> \"CONST Load (CONST UNIV) v (CONST Var a) x (CONST state_rec.more)\"\n  \"x := [a + #I]~v\" \\<rightharpoonup> \"CONST Load (CONST UNIV) v (CONST Exp (CONST addI I) [CONST Var a]) x (CONST state_rec.more)\"\n  \"\\<lbrace>P\\<rbrace> x := [a + #I]~v\" \\<rightharpoonup> \"CONST Load \\<llangle>P\\<rrangle> v (CONST Exp (CONST addI I) [CONST Var a]) x (CONST state_rec.more)\"\n\n  \"[a] := r ~ v\" \\<rightharpoonup> \"CONST Store (CONST UNIV) v (CONST Var a) r (CONST state_rec.more)\"\n  \"\\<lbrace>P\\<rbrace> [a + #I] := x ~ v\" \\<rightharpoonup> \"CONST Store \\<llangle>P\\<rrangle> v (CONST Exp (CONST addI I) [CONST Var a]) x (CONST state_rec.more)\"\n  \"\\<lbrace>P\\<rbrace> [ra + #I] := r ~ v :\\<^sub>a a\" \\<rightharpoonup> \"CONST Store \\<llangle>P\\<rrangle> v (CONST Exp (CONST addI I) [CONST Var ra]) r a\"\n\n  \"\\<lbrace>P\\<rbrace> r\\<^sub>1 := cas r\\<^sub>2 r\\<^sub>3 r\\<^sub>4 ~ v, a\" \\<rightharpoonup> \"CONST CAS \\<llangle>P\\<rrangle> v r\\<^sub>2 r\\<^sub>3 r\\<^sub>4 r\\<^sub>1 1 0 a\"\n\n  \"X := Y - #I\" \\<rightharpoonup> \"CONST Op X (CONST Exp (CONST subI I) [CONST Var Y])\"\n  \"X := Y + #I\" \\<rightharpoonup> \"CONST Op X (CONST Exp (CONST addI I) [CONST Var Y])\"\n  \"X := Y + Z\" \\<rightharpoonup> \"CONST Op X (CONST Exp (CONST addR) [CONST Var Y, CONST Var Z])\"\n  \"X := Y - Z\" \\<rightharpoonup> \"CONST Op X (CONST Exp (CONST subR) [CONST Var Y, CONST Var Z])\"\n  \"X := Y % #I\" \\<rightharpoonup> \"CONST Op X (CONST Exp (CONST modI I) [CONST Var Y])\"\n  \"X := Y % Z\" \\<rightharpoonup> \"CONST Op X (CONST Exp (CONST modR) [CONST Var Y, CONST Var Z])\"\n\n  \"X := #I\" \\<rightharpoonup> \"CONST Op X (CONST Exp (CONST movI I) [])\"\n  \"fence\" \\<rightharpoonup> \"CONST Fence\"\n  \"cfence\" \\<rightharpoonup> \"CONST Fence\"\n  \"c\\<^sub>1 ; c\\<^sub>2\" \\<rightharpoonup> \"CONST Seq c\\<^sub>1 c\\<^sub>2\"\n  \"if b then c\\<^sub>1 else c\\<^sub>2 fi\" \\<rightharpoonup> \"CONST If b c\\<^sub>1 c\\<^sub>2\"\n  \"if b then c\\<^sub>1 fi\" \\<rightharpoonup> \"CONST If b c\\<^sub>1 (CONST Skip)\"\n  \"R: R G: G I: I P: P {c} Q: Q\" \\<rightharpoonup> \"(\\<llangle>R\\<rrangle>,\\<llangle>G\\<rrangle>,\\<llangle>I\\<rrangle>,\\<llangle>P\\<rrangle>,c,\\<llangle>Q\\<rrangle>)\"\n\ndefinition inv2\n  where \"inv2 I \\<equiv> {(m,m'). m \\<in> glb ` I \\<longrightarrow> m' \\<in> glb ` I}\"\n\nfun fn_valid :: \"('v::equal,'r::equal,'a) threads \\<Rightarrow> bool\"\n  where \n    \"fn_valid [(R,G,I,P,c,Q)] = (stable\\<^sub>t R Q \\<and> wellformed R G \\<and> guar\\<^sub>c c (inv2 I \\<inter> G) \\<and> \n                                (stable\\<^sub>t R Q \\<longrightarrow> P \\<subseteq> wp (inv2 I \\<inter> R) c Q) \\<and>\n                                (wellformed R G \\<longrightarrow> rif_checks c R G))\" |\n    \"fn_valid _ = undefined\"\n\nnonterminal prgs\n\nsyntax\n  \"_PAR\"        :: \"prgs \\<Rightarrow> 'a\"              (\"COBEGIN//_//COEND\" 60)\n  \"_FN\"        :: \"prgs \\<Rightarrow> 'a\"              (\"FNBEGIN//_//FNEND\" 60)\n  \"_prg\"        :: \"'a \\<Rightarrow> prgs\"              (\"_\" 57)\n  \"_prgs\"       :: \"['a, prgs] \\<Rightarrow> prgs\"      (\"_//\\<parallel>//_\" [60,57] 57)\n\ntranslations\n  \"_prg a\" \\<rightharpoonup> \"[a]\"\n  \"_prgs a ps\" \\<rightharpoonup> \"a # ps\"\n  \"_FN t\" \\<rightharpoonup> \"CONST fn_valid t\"\n\nsyntax\n  \"_before\"  :: \"'b \\<Rightarrow> 'a\" (\"\\<^sup>1_\" [100] 400)\n  \"_after\"   :: \"'b \\<Rightarrow> 'a\" (\"\\<^sup>2_\" [100] 400)\n  \"_mem\"     :: \"'g \\<Rightarrow> 'a\" (\"\\<^sup>s[_]\")\n  \"_mbefore\" :: \"'g \\<Rightarrow> 'a\" (\"\\<^sup>1[_]\")\n  \"_mafter\"  :: \"'g \\<Rightarrow> 'a\" (\"\\<^sup>2[_]\")\n  \"_reg\"     :: \"'r \\<Rightarrow> 'a\" (\"\\<^sup>r_\" [100] 1000)\n  \"_rbefore\" :: \"'r \\<Rightarrow> 'a\" (\"\\<^sup>1\\<^sup>r_\")\n  \"_rafer\"   :: \"'r \\<Rightarrow> 'a\" (\"\\<^sup>2\\<^sup>r_\")\n  \"_aux\"     :: \"'b \\<Rightarrow> 'a\" (\"\\<^sup>a_\" [100] 1000)\n  \"_abefore\" :: \"'b \\<Rightarrow> 'a\" (\"\\<^sup>1\\<^sup>a_\" [100] 400)\n  \"_aafer\"   :: \"'b \\<Rightarrow> 'a\" (\"\\<^sup>2\\<^sup>a_\" [100] 400)\n\ndefinition gld :: \"('v,'r,'a) state \\<Rightarrow> ('v \\<Rightarrow> 'v)\"\n  where \"gld m \\<equiv> \\<lambda>v. st m (Glb v)\"\n\ntranslations\n  \"\\<^sup>1x\" \\<rightleftharpoons> \"x (\\<acute>CONST fst)\"\n  \"\\<^sup>2x\" \\<rightleftharpoons> \"x (\\<acute>CONST snd)\"\n  \"\\<^sup>s[X]\" \\<rightleftharpoons> \"(\\<acute>CONST gld) X\"\n  \"\\<^sup>1[X]\" \\<rightleftharpoons> \"(CONST st (\\<acute>CONST fst)) X\"\n  \"\\<^sup>2[X]\" \\<rightleftharpoons> \"(CONST st (\\<acute>CONST snd)) X\"\n  \"\\<^sup>rX\" \\<rightleftharpoons> \"(\\<acute>CONST rg) X\"\n  \"\\<^sup>1\\<^sup>rX\" \\<rightleftharpoons> \"(CONST rg (\\<acute>CONST fst)) X\"\n  \"\\<^sup>2\\<^sup>rX\" \\<rightleftharpoons> \"(CONST rg (\\<acute>CONST snd)) X\"\n  \"\\<^sup>aX\" \\<rightleftharpoons> \"X (\\<acute>CONST state_rec.more)\"\n  \"\\<^sup>1\\<^sup>aX\" \\<rightleftharpoons> \"X (CONST state_rec.more (\\<acute>CONST fst))\"\n  \"\\<^sup>2\\<^sup>aX\" \\<rightleftharpoons> \"X (CONST state_rec.more (\\<acute>CONST snd))\"\n\n(*\nsyntax\n  \"_before\"  :: \"'b \\<Rightarrow> 'a\" (\"\\<^sup>1_\" [100] 400)\n  \"_after\"   :: \"'b \\<Rightarrow> 'a\" (\"\\<^sup>2_\" [100] 400)\n  \"_mem\"     :: \"'b \\<Rightarrow> 'a\" (\"\\<lbrakk>_\\<rbrakk>\")\n  \"_mat\"     :: \"'b \\<Rightarrow> 'a\" (\"\\<^sup>0\\<lbrakk>_\\<rbrakk>\")\n  \"_mbefore\" :: \"'b \\<Rightarrow> 'a\" (\"\\<^sup>1\\<lbrakk>_\\<rbrakk>\")\n  \"_mafter\"  :: \"'b \\<Rightarrow> 'a\" (\"\\<^sup>2\\<lbrakk>_\\<rbrakk>\")\n  \"_reg\"     :: \"'r \\<Rightarrow> 'a\" (\"\\<^bold>r_\" [1000] 1000)\n  \"_rar\"     :: \"'r \\<Rightarrow> 'a\" (\"\\<^sup>0\\<^bold>r_\" [100] 1000)\n  \"_rbefore\" :: \"'r \\<Rightarrow> 'a\" (\"\\<^sup>1\\<^bold>r_\")\n  \"_rafer\"   :: \"'r \\<Rightarrow> 'a\" (\"\\<^sup>2\\<^bold>r_\")\n  \"_val\"     :: \"'b \\<Rightarrow> 'a\" (\"#_\" [100] 1000)\n  \"_aux\"     :: \"'b \\<Rightarrow> 'a\" (\"\\<^sup>a_\" [100] 1000)\n  \"_abefore\" :: \"'b \\<Rightarrow> 'a\" (\"\\<^sup>1\\<^sup>a_\" [100] 400)\n  \"_aafer\"   :: \"'b \\<Rightarrow> 'a\" (\"\\<^sup>2\\<^sup>a_\" [100] 400)\n\ntranslations\n  \"\\<^sup>1x\" \\<rightleftharpoons> \"x (\\<acute>CONST fst)\"\n  \"\\<^sup>2x\" \\<rightleftharpoons> \"x (\\<acute>CONST snd)\"\n  \"\\<lbrakk>X\\<rbrakk>\" \\<rightleftharpoons> \"CONST Var (CONST Glb X)\"\n  \"\\<^sup>0\\<lbrakk>X\\<rbrakk>\" \\<rightleftharpoons> \"(CONST st (\\<acute>CONST glb)) X\"\n  \"\\<^sup>1\\<lbrakk>X\\<rbrakk>\" \\<rightleftharpoons> \"(CONST st (\\<acute>CONST fst)) X\"\n  \"\\<^sup>2\\<lbrakk>X\\<rbrakk>\" \\<rightleftharpoons> \"(CONST st (\\<acute>CONST snd)) X\"\n  \"\\<^bold>rX\" \\<rightleftharpoons> \"CONST Var (CONST Var X)\"\n  \"\\<^sup>0\\<^bold>rX\" \\<rightleftharpoons> \"(\\<acute>CONST rg) X\"\n  \"\\<^sup>1\\<^bold>rX\" \\<rightleftharpoons> \"(CONST rg (\\<acute>CONST fst)) X\"\n  \"\\<^sup>2\\<^bold>rX\" \\<rightleftharpoons> \"(CONST rg (\\<acute>CONST snd)) X\"\n  \"#X\" \\<rightleftharpoons> \"CONST Val X\"\n  \"\\<^sup>aX\" \\<rightleftharpoons> \"X (\\<acute>CONST state_rec.more)\"\n  \"\\<^sup>1\\<^sup>aX\" \\<rightleftharpoons> \"X (CONST state_rec.more (\\<acute>CONST fst))\"\n  \"\\<^sup>2\\<^sup>aX\" \\<rightleftharpoons> \"X (CONST state_rec.more (\\<acute>CONST snd))\"\n*)\n\nsyntax\n  \"_con\" :: \"nat \\<Rightarrow> 'a\" (\"=[_]\" [100] 1000)\n  \"_inc\" :: \"nat \\<Rightarrow> 'a\" (\"\\<le>[_]\" [100] 1000)\n\ntranslations\n  \"=[X]\" \\<rightharpoonup> \"(CONST st (\\<acute>CONST snd)) X = (CONST st (\\<acute>CONST fst)) X\"\n  \"\\<le>[X]\" \\<rightharpoonup> \"(CONST st (\\<acute>CONST snd)) X \\<ge> (CONST st (\\<acute>CONST fst)) X\"\n\n\n\nlemma [simp]:\n  \"reflexive R \\<Longrightarrow> stabilize R {} = {}\"\n  by (auto simp: reflexive_def stabilize_def)\n\nlemma [simp]:\n  \"reflexive R \\<Longrightarrow> stabilize R (assert P) = assert P\"\n  by (auto simp: assert_def)\n\nlemma [simp]:\n  \"{m. m(a :=\\<^sub>s e) \\<in> (assert P)} = assert P\"\n  by (auto simp: assert_def)\n\nlemma [simp]:\n  \"reflexive R \\<Longrightarrow> UNIV \\<subseteq> stabilize R P = (\\<forall>m. m \\<in> P)\"\n  by (auto simp: reflexive_def stabilize_def assert_def glb_def)\n\nlemma [simp]:\n  \"stabilize R (P \\<inter> Q) = stabilize R P \\<inter> stabilize R Q\"\n  by (auto simp: stabilize_def)\n\nlemma [simp]:\n  \"{m. (f m) \\<in> assert P} = assert P\"\n  by (auto simp: assert_def)\n\nlemma [simp]:\n  \"UNIV \\<subseteq> assert P = P\"\n  by (auto simp: assert_def)\n\nlemma [simp]:\n  \"x(aux: state_rec.more) = x\"\n  by (auto simp: aux_upd_def)\n\nlemma [simp]:\n  \"st (glb (x(Glb z :=\\<^sub>s e))) = (st (glb x))(z := e)\"\n  by (auto simp: st_upd_def glb_def)\n\nlemma [simp]:\n  \"st (glb (x(aux:f ))) = (st (glb x))\"\n  by (auto simp: st_upd_def glb_def)\n\nlemma glb_in [intro!]:\n  assumes \"\\<exists>l. \\<lparr> st = (\\<lambda>v. case v of Reg v \\<Rightarrow> l v | _ \\<Rightarrow> st m v), \\<dots> = state_rec.more m \\<rparr> \\<in> P\"\n  shows \"glb m \\<in> glb ` P\"\nproof -\n  obtain l where \"\\<lparr> st = (\\<lambda>v. case v of Reg v \\<Rightarrow> l v | _ \\<Rightarrow> st m v), \\<dots> = state_rec.more m \\<rparr> \\<in> P\"\n    (is \"?m \\<in> P\")\n    using assms by auto\n  hence \"glb ?m \\<in> glb ` P\" by auto\n  moreover have \"glb m = glb ?m\" by (auto simp: glb_def)\n  ultimately show ?thesis by auto\nqed\n\nlemma  a:\n  \"glb x = glb y \\<Longrightarrow> st x (Glb e) = st y (Glb e)\"\n  unfolding glb_def\n  by (metis state_rec.select_convs(1))\n\nlemma  b:\n  \"glb x = glb y \\<Longrightarrow> state_rec.more x = state_rec.more y\"\n  unfolding glb_def by simp\n\nlemma [simp]:\n  \"st (glb x) y = st x (Glb y)\"\n  unfolding glb_def by auto\n\nfun chain\n  where \"chain [] Q = Q\" | \"chain (a#xs) Q = chain xs (wpre a Q)\"\ndeclare chain.simps [simp del]\n\nlemma chain_singleI:\n  \"wpre a Q = chain [a] Q\"\n  unfolding chain.simps by auto\n\nlemma chain_singleI':\n  \"stabilize R Q = chain [env R] Q\"\n  unfolding chain.simps by auto\n\nlemma chain_lastE:\n  \"chain (xs @ [a]) Q = wpre a ( (chain xs Q))\"\n  by (induct xs arbitrary: Q) (auto simp: chain.simps)\n\nlemma chain_lastI:\n  \"chain [a] (chain xs Q) = chain (xs@[a]) Q\"\n  by (induct xs) (auto simp: chain_lastE chain.simps)\n\nlemma chain_merge:\n  \"chain l (chain l' Q) = chain (l'@l) Q\"\n  by (induct l' arbitrary: Q) (simp add: chain.simps)+\n\nlemma stabilize_mono:\n  \"P \\<subseteq> Q \\<Longrightarrow> stabilize R P  \\<subseteq> stabilize R Q\"\n  unfolding stabilize_def by auto\n\nlemma pre_mono:\n  \"P \\<subseteq> Q \\<Longrightarrow> wpre a P \\<subseteq> wpre a Q\"\n  using  stabilize_mono apply (cases a) apply (auto)\n  by blast\n\nlemma chain_mono:\n  \"P \\<subseteq> Q \\<Longrightarrow> chain xs P \\<subseteq> chain xs Q\"\n  by (induct xs arbitrary: P Q) (auto simp: pre_mono stabilize_mono chain.simps)\n\nlemma chain1_wpre:\n  \"P \\<subseteq> chain xs (wpre a Q) \\<Longrightarrow> P \\<subseteq> chain (a#xs) Q\"\n  unfolding chain.simps .\n\nlemma chain1_stab:\n  \"P \\<subseteq> chain xs (stabilize R Q) \\<Longrightarrow> P \\<subseteq> chain (env R#xs) Q\"\n  unfolding chain.simps by auto\n\nlemma chain0:\n  \"P \\<subseteq> Q \\<Longrightarrow> P \\<subseteq>  chain [] Q\"\n  unfolding chain.simps .\n\nlemma chain_extend:\n  \"P \\<subseteq> chain xs (Q \\<inter> X) \\<Longrightarrow> P \\<subseteq> chain xs Q\"\n  using chain_mono[of \"Q \\<inter> X\" Q] by (auto simp: )\n\nlemma chain_rewrite:\n  \"X \\<subseteq> Q \\<Longrightarrow> P \\<subseteq> chain xs X \\<Longrightarrow> P \\<subseteq> chain xs Q\"\n  using chain_mono  by blast\n\ndefinition str where\n  \"str R P \\<equiv> if P \\<subseteq> stabilize R P then P else UNIV\"\n\nlemma str_mono:\n  \"Q \\<subseteq> P \\<Longrightarrow> Q \\<subseteq> str R P\"\n  unfolding str_def by (auto simp: )\n\nlemma stabilize_univ:\n  \"UNIV \\<subseteq> stabilize R UNIV\"\n  unfolding stabilize_def by auto\n\nlemma stabilize_str:\n  \"str R P \\<subseteq> stabilize R (str R P)\"\n  unfolding str_def stabilize_def by simp\n\nlemma [simp]: \"wpre a (P \\<inter> Q) = (wpre a P \\<inter> wpre a Q)\"\n  by (cases a, auto)\n\nlemma chain_inter: \"chain l (P \\<inter> Q) = (chain l P \\<inter> chain l Q)\"\n  by (induct l arbitrary: P Q, auto simp: chain.simps)\n\nlemma stable_stabilize:\n  \"stable\\<^sub>t R Q \\<Longrightarrow> Q \\<subseteq> stabilize R Q\"\n  unfolding stabilize_def stable_def step\\<^sub>t_def\n  by auto\n\nlemma strI:\n  \"stable\\<^sub>t R Q \\<Longrightarrow> K \\<subseteq> chain l (str R Q) \\<Longrightarrow>  K \\<subseteq> chain (env R#l) Q\"\n  unfolding chain.simps str_def apply simp\n  using stable_stabilize\n  by (metis (mono_tags) chain_rewrite)\n\nlemma envI:\n  \"stable\\<^sub>t R Q \\<Longrightarrow> K \\<subseteq> chain l (Q) \\<Longrightarrow>  K \\<subseteq> chain (env R#l) Q\"\n  unfolding chain.simps str_def apply simp\n  using stable_stabilize\n  by (metis (mono_tags) chain_rewrite)\n\nlemma ir_str:\n  \"wpre (ir r e) (str R Q) \\<supseteq> str R (wpre (ir r e) Q)\"\n  apply (auto simp: str_def stabilize_def st_upd_def)\n   apply (subgoal_tac \"rg (x\\<lparr>st := (st x)(Reg r := ev\\<^sub>E (rg m') e)\\<rparr>) = rg (m'\\<lparr>st := (st m')(Reg r := ev\\<^sub>E (rg m') e)\\<rparr>)\")\n     apply (subgoal_tac \"(glb (x\\<lparr>st := (st x)(Reg r := ev\\<^sub>E (rg m') e)\\<rparr>), glb (m'\\<lparr>st := (st m')(Reg r := ev\\<^sub>E (rg m') e)\\<rparr>)) \\<in> R\")\n     apply blast\n  apply (auto simp: glb_def)[1]\n  unfolding rg_def apply auto[1]\n  done\n\nlemma cm_str:\n  \"wpre (cm b) (str R Q) \\<supseteq> str R (wpre (cm b) Q)\"\n  by (auto simp: str_def stabilize_def st_upd_def)\n\nlemma ncm_str:\n  \"wpre (ncm b) (str R Q) \\<supseteq> str R (wpre (ncm b) Q)\"\n  by (auto simp: str_def stabilize_def st_upd_def)\n\nlemma ign_str:\n  \"Q \\<subseteq> str R Q\"\n  by (auto simp: str_def)\n\nlemma [simp]:\n  \"state_rec.more (glb x) = state_rec.more x\"\n  unfolding glb_def by auto\n\nend", "meta": {"author": "UQ-PAC", "repo": "wmm-rg", "sha": "7eef2f42693cb0723a9a7a75cd7cd6f73f9bdfb2", "save_path": "github-repos/isabelle/UQ-PAC-wmm-rg", "path": "github-repos/isabelle/UQ-PAC-wmm-rg/wmm-rg-7eef2f42693cb0723a9a7a75cd7cd6f73f9bdfb2/ARMv8/ARMv8_Syntax.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526660244838, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.2760252823944037}}
{"text": "section \\<open>The Second Monotonicity Calculus\\<close>\ntheory Mcalc2\nimports Mono\nbegin\n\n\n\nsubsection\\<open>Extension policies\\<close>\n\ntext\\<open>Extension policy: copy, true or false extension:\\<close>\n\ndatatype epol = Cext | Text | Fext\n\ntext\\<open>Problem with infinite knowledge and predicate-extension policy:\\<close>\n\nlocale ProblemIkPol = ProblemIk wtFsym wtPsym arOf resOf parOf \\<Phi> infTp\nfor wtFsym :: \"'fsym \\<Rightarrow> bool\" and wtPsym :: \"'psym \\<Rightarrow> bool\"\nand arOf :: \"'fsym \\<Rightarrow> 'tp list\"\nand resOf and parOf and \\<Phi> and infTp\n+ fixes (* the predicate-extension policy *) pol :: \"'tp \\<Rightarrow> 'psym \\<Rightarrow> epol\"\nand (* guard of a variable occurring in a certain literal of a certain clause: *)\n    grdOf ::\n\"('fsym, 'psym) cls \\<Rightarrow> ('fsym, 'psym) lit \\<Rightarrow> var \\<Rightarrow> ('fsym, 'psym) lit\"\n\n\ncontext ProblemIkPol begin\n\nsubsection\\<open>Naked variables\\<close>\n\nfun nv2T where\n\"nv2T (Var x) = {x}\"\n|\n\"nv2T (Fn f Tl) = {}\"\n\nfun nv2L where\n\"nv2L (Pos (Eq T1 T2)) = nv2T T1 \\<union> nv2T T2\"\n|\n\"nv2L (Neg (Eq T1 T2)) = {}\"\n|\n\"nv2L (Pos (Pr p Tl)) = {x \\<in> \\<Union> (set (map nv2T Tl)) . pol (tpOfV x) p = Fext}\"\n|\n\"nv2L (Neg (Pr p Tl)) = {x \\<in> \\<Union> (set (map nv2T Tl)) . pol (tpOfV x) p = Text}\"\n\ndefinition \"nv2C c \\<equiv> \\<Union> (set (map nv2L c))\"\n\nlemma in_nv2T: \"x \\<in> nv2T T \\<longleftrightarrow> T = Var x\"\napply(cases T)\n  apply (metis equals0D nv2T.simps singleton_iff)\n  by simp\n\nlemma nv2T_vars[simp]: \"x \\<in> nv2T T \\<Longrightarrow> x \\<in> vars T\"\nby (induct T, auto split: if_splits)\n\nlemma nv2L_varsL[simp]:\nassumes \"x \\<in> nv2L l\" shows \"x \\<in> varsL l\"\nproof (cases l)\n  case (Pos at)\n  show ?thesis proof(cases at)\n    case (Pr p Tl) thus ?thesis using assms unfolding Pos\n    apply(cases \"pol (tpOfV x) p\", simp_all) by (metis nv2T_vars)\n  qed(insert assms, unfold Pos, auto)\nnext\n  case (Neg at)\n  show ?thesis proof(cases at)\n    case (Pr p Tl) thus ?thesis using assms unfolding Neg\n    apply(cases \"pol (tpOfV x) p\", simp_all) by (metis nv2T_vars)\n  qed(insert assms, unfold Neg, auto)\nqed\n\nlemma nv2C_varsC[simp]: \"x \\<in> nv2C c \\<Longrightarrow> x \\<in> varsC c\"\nunfolding varsC_def nv2C_def by (induct c, auto)\n\nsubsection\\<open>The calculus\\<close>\n\ntext\\<open>The notion of a literal being a guard for a (typed) variable:\\<close>\n\nfun isGuard :: \"var \\<Rightarrow> ('fsym,'psym) lit \\<Rightarrow> bool\" where\n\"isGuard x (Pos (Eq T1 T2)) \\<longleftrightarrow> False\"\n|\n\"isGuard x (Neg (Eq T1 T2)) \\<longleftrightarrow>\n (T1 = Var x \\<and> (\\<exists> f Tl. T2 = Fn f Tl)) \\<or>\n (T2 = Var x \\<and> (\\<exists> f Tl. T1 = Fn f Tl))\"\n|\n\"isGuard x (Pos (Pr p Tl)) \\<longleftrightarrow> x \\<in> \\<Union> (set (map nv2T Tl)) \\<and> pol (tpOfV x) p = Text\"\n|\n\"isGuard x (Neg (Pr p Tl)) \\<longleftrightarrow> x \\<in> \\<Union> (set (map nv2T Tl)) \\<and> pol (tpOfV x) p = Fext\"\n\n\ntext\\<open>The monotonicity calculus from the Classen et. al. paper, applied\nto non-infinite types only: it checks that any variable in any literal of any clause\nis indeed guarded by its guard:\\<close>\n\ninductive mcalc2 (infix \"\\<turnstile>2\" 40) where\n [simp]: \"infTp \\<sigma> \\<Longrightarrow> \\<sigma> \\<turnstile>2 c\"\n|[simp]: \"(\\<And> l x. \\<lbrakk>l \\<in> set c; x \\<in> nv2L l; tpOfV x = \\<sigma>\\<rbrakk>\n         \\<Longrightarrow> isGuard x (grdOf c l x)) \\<Longrightarrow> \\<sigma> \\<turnstile>2 c\"\n\nlemma mcalc2_iff:\n\"\\<sigma> \\<turnstile>2 c \\<longleftrightarrow>\n infTp \\<sigma> \\<or> (\\<forall> l x. l \\<in> set c \\<and> x \\<in> nv2L l \\<and> tpOfV x = \\<sigma> \\<longrightarrow> isGuard x (grdOf c l x))\"\nunfolding mcalc2.simps by auto\n\nend (* context ProblemIk *)\n\nlocale ProblemIkPolMcalc2 = ProblemIkPol wtFsym wtPsym arOf resOf parOf \\<Phi> infTp pol grdOf\nfor wtFsym :: \"'fsym \\<Rightarrow> bool\" and wtPsym :: \"'psym \\<Rightarrow> bool\"\nand arOf :: \"'fsym \\<Rightarrow> 'tp list\"\nand resOf and parOf and \\<Phi> and infTp and pol and grdOf\n+ assumes\n(* well-definednedd of the guard: *)\n    grdOf: \"\\<And> c l x. \\<lbrakk>c \\<in> \\<Phi>; l \\<in> set c; x \\<in> nv2L l; \\<not> infTp (tpOfV x)\\<rbrakk>\n                     \\<Longrightarrow> grdOf c l x \\<in> set c\"\nand mcalc2: \"\\<And> \\<sigma> c. c \\<in> \\<Phi> \\<Longrightarrow> \\<sigma> \\<turnstile>2 c\"\nbegin\nlemma wtL_grdOf[simp]:\nassumes \"c \\<in> \\<Phi>\" and \"l \\<in> set c\" and \"x \\<in> nv2L l\" and \"\\<not> infTp (tpOfV x)\"\nshows \"wtL (grdOf c l x)\"\nusing grdOf[OF assms] by (metis assms list_all_iff wtC_def wtPB_def wt_\\<Phi>)\nend\n\nlocale ModelIkPolMcalc2 =\nModelIk wtFsym wtPsym arOf resOf parOf \\<Phi> infTp intT intF intP +\nProblemIkPolMcalc2 wtFsym wtPsym arOf resOf parOf \\<Phi> infTp pol grdOf\nfor wtFsym :: \"'fsym \\<Rightarrow> bool\" and wtPsym :: \"'psym \\<Rightarrow> bool\"\nand arOf :: \"'fsym \\<Rightarrow> 'tp list\"\nand resOf and parOf and \\<Phi> and infTp pol and grdOf and intT and intF and intP\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Sort_Encodings/Mcalc2.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526660244838, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.2760252823944037}}
{"text": "theory Failures_Stable_TickTock\n  imports Failures_TickTock Failures\nbegin\n\nthm sf2f_def F2f_def mkF24_def ttproc2F_def\n\n(* mapping from  tick-tock to stable failures (with stable tick) *)\ndefinition tt2sf :: \"'a ttprocess \\<Rightarrow> 'a process\" where\n  \"tt2sf P = \n    ({ (t, X) | t X. (map (\\<lambda> e. [ttevt2F e]\\<^sub>E) t) @ [[ttevt2F ` X]\\<^sub>R] \\<in> P }\n      \\<union> {(t, X) | t X. (map (\\<lambda> e. [ttevt2F e]\\<^sub>E) t) @ [[Tick]\\<^sub>E] \\<in> P \\<and> X \\<subseteq> UNIV-{tick}}\n      \\<union> {(t @ [tick], X) | t X. (map (\\<lambda> e. [ttevt2F e]\\<^sub>E) t) @ [[Tick]\\<^sub>E] \\<in> P \\<and> X \\<subseteq> UNIV}, \n    {tt2T y |y. y \\<in> P})\"\n\nlemma end_tick_in_traces:\n  \"\\<And>P. ttWF (map (\\<lambda>e. [ttevt2F e]\\<^sub>E) a @ [[Tick]\\<^sub>E]) \\<Longrightarrow>\n       map (\\<lambda>e. [ttevt2F e]\\<^sub>E) a @ [[Tick]\\<^sub>E] \\<in> P \\<Longrightarrow>\n  a @ [tick] \\<in> traces(({(s, X). \\<exists>y. Some (s, X) = tt2F y \\<and> y \\<in> P}, {tt2T y |y. y \\<in> P}))\"\n  apply (induct a, simp_all)\n  using traces_def apply force\n  apply (case_tac a1, simp_all)\n  apply (metis Nil_is_append_conv neq_Nil_conv ttWF.simps(8))\nproof -\n  fix a1 a2 P x2\n  assume ind_hyp: \"\\<And>P. map (\\<lambda>e. [ttevt2F e]\\<^sub>E) a2 @ [[Tick]\\<^sub>E] \\<in> P \\<Longrightarrow>\n           a2 @ [tick] \\<in> traces(({(s, X). \\<exists>y. Some (s, X) = tt2F y \\<and> y \\<in> P}, {tt2T y |y. y \\<in> P}))\"\n  assume \"[Event x2]\\<^sub>E # map (\\<lambda>e. [ttevt2F e]\\<^sub>E) a2 @ [[Tick]\\<^sub>E] \\<in> P\"\n  then have \"a2 @ [tick] \\<in> traces(({(s, X). \\<exists>y. Some (s, X) = tt2F y \\<and> y \\<in> {t. [Event x2]\\<^sub>E # t \\<in> P}},\n         {tt2T y |y. y \\<in> {t. [Event x2]\\<^sub>E # t \\<in> P}}))\"\n    using ind_hyp by force\n  then show \"evt x2 # a2 @ [tick] \\<in> traces(({(s, X). \\<exists>y. Some (s, X) = tt2F y \\<and> y \\<in> P}, {tt2T y |y. y \\<in> P}))\"\n    by (smt mem_Collect_eq snd_conv traces_def tt2T.simps(2))\nqed\n\nlemma end_refusal_ttWF_eq:\n  \"ttWF (map (\\<lambda>e. [ttevt2F e]\\<^sub>E) a @ [[ttevt2F ` b]\\<^sub>R])\n    \\<Longrightarrow> Some (a, b) = tt2F (map (\\<lambda>e. [ttevt2F e]\\<^sub>E) a @ [[ttevt2F ` b]\\<^sub>R])\"\n  apply (induct a, auto)\n  using Some_tt2F_set apply fastforce\n  apply (case_tac a1, auto)\n  apply (metis Nil_is_append_conv neq_Nil_conv ttWF.simps(8))\n  by (metis fst_conv option.simps(5) snd_conv)\n\nlemma tt2F_Some_ref_end_refusal:\n  \"\\<And>a. Some (a, b) = tt2F y \\<Longrightarrow>\n    y = map (\\<lambda>e. [ttevt2F e]\\<^sub>E) a @ [[ttevt2F ` b]\\<^sub>R]\n    \\<or> y = map (\\<lambda>e. [ttevt2F e]\\<^sub>E) a @ [[(ttevt2F ` b) \\<union> {Tock}]\\<^sub>R]\"\n  apply (induct y rule:ttWF.induct, auto)\n    apply (smt image_def mem_Collect_eq ttevent.exhaust ttevt2F.simps(1) ttevt2F.simps(2))\n  apply (case_tac xa, auto)\n  apply (metis image_eqI mem_Collect_eq ttevt2F.simps(1))\n   apply (metis mem_Collect_eq rev_image_eqI ttevt2F.simps(2))\n  by (case_tac \"tt2F \\<sigma>\", auto)\n\nlemma tt2F_Some_ref_end_refusal_in_TT1:\n  \"TT1 P \\<Longrightarrow> Some (a, b) = tt2F y \\<Longrightarrow> y \\<in> P \\<Longrightarrow>\n    map (\\<lambda>e. [ttevt2F e]\\<^sub>E) a @ [[ttevt2F ` b]\\<^sub>R] \\<in> P\"\nproof -\n  assume TT1_P: \"TT1 P\"\n  assume y_in_P: \"y \\<in> P\"\n  assume tt2F_y_Some: \"Some (a, b) = tt2F y\"\n\n  have \"y = map (\\<lambda>e. [ttevt2F e]\\<^sub>E) a @ [[ttevt2F ` b]\\<^sub>R]\n    \\<or> y = map (\\<lambda>e. [ttevt2F e]\\<^sub>E) a @ [[(ttevt2F ` b) \\<union> {Tock}]\\<^sub>R]\"\n    using tt2F_Some_ref_end_refusal tt2F_y_Some by blast\n  then show \"map (\\<lambda>e. [ttevt2F e]\\<^sub>E) a @ [[ttevt2F ` b]\\<^sub>R] \\<in> P\"\n    using y_in_P\n  proof auto\n    have \"map (\\<lambda>e. [ttevt2F e]\\<^sub>E) a @ [[ttevt2F ` b]\\<^sub>R]\n      \\<lesssim>\\<^sub>C map (\\<lambda>e. [ttevt2F e]\\<^sub>E) a @ [[insert Tock (ttevt2F ` b)]\\<^sub>R]\"\n      by (induct a, auto)\n    then show \"map (\\<lambda>e. [ttevt2F e]\\<^sub>E) a @ [[insert Tock (ttevt2F ` b)]\\<^sub>R] \\<in> P\n      \\<Longrightarrow> map (\\<lambda>e. [ttevt2F e]\\<^sub>E) a @ [[ttevt2F ` b]\\<^sub>R] \\<in> P\"\n      using TT1_P TT1_def by blast\n  qed\nqed\n\nlemma end_tick_in_traces_imp_in_ttproc:\n  \"\\<And>P. s @ [tick] \\<in> traces(({(s, X). \\<exists>y. Some (s, X) = tt2F y \\<and> y \\<in> P}, {tt2T y |y. y \\<in> P}))\n    \\<Longrightarrow> map (\\<lambda>e. [ttevt2F e]\\<^sub>E) s @ [[Tick]\\<^sub>E] \\<in> P\"\nproof (induct s, auto)\n  fix P\n  show \"[tick] \\<in> traces(({(s, X). \\<exists>y. Some (s, X) = tt2F y \\<and> y \\<in> P}, {tt2T y |y. y \\<in> P})) \\<Longrightarrow> [[Tick]\\<^sub>E] \\<in> P\"\n    by (smt append_Nil mem_Collect_eq snd_conv tick_tt2T_concat_TickE traces_def tt2T_tick_exists_Cons)\nnext\n  fix a s P\n  assume ind_hyp: \"\\<And>P. s @ [tick] \\<in> traces(({(s, X). \\<exists>y. Some (s, X) = tt2F y \\<and> y \\<in> P}, {tt2T y |y. y \\<in> P})) \\<Longrightarrow>\n             map (\\<lambda>e. [ttevt2F e]\\<^sub>E) s @ [[Tick]\\<^sub>E] \\<in> P\"\n  assume \"a # s @ [tick] \\<in> traces(({(s, X). \\<exists>y. Some (s, X) = tt2F y \\<and> y \\<in> P}, {tt2T y |y. y \\<in> P}))\"\n  then have \"s @ [tick]\n    \\<in> traces(({(s, X). \\<exists>y. Some (s, X) = tt2F y \\<and> y \\<in> {t. [ttevt2F a]\\<^sub>E # t \\<in> P}},\n               {tt2T y |y. y \\<in> {t. [ttevt2F a]\\<^sub>E # t \\<in> P}}))\"\n    unfolding traces_def\n  proof auto\n    fix y\n    assume case_assms: \"a # s @ [tick] = tt2T y\" \"y \\<in> P\"\n    then obtain y' where y'_assms: \"s @ [tick] = tt2T y' \\<and> y = [ttevt2F a]\\<^sub>E # y'\"\n      apply (cases y, auto, cases a, auto, case_tac aa, auto, case_tac x1, auto)\n      apply (metis append_Cons neq_Nil_conv self_append_conv2 tt2T.simps(1) tt2T.simps(7))\n      apply (case_tac aa, auto, case_tac x1, auto)\n      by (metis append_Cons neq_Nil_conv self_append_conv2 tt2T.simps(1) tt2T.simps(7))\n    then have \"map (\\<lambda>e. [ttevt2F e]\\<^sub>E) s @ [[Tick]\\<^sub>E] \\<in> {t. [ttevt2F a]\\<^sub>E # t \\<in> P}\"\n      using ind_hyp[where P=\"{t. [ttevt2F a]\\<^sub>E # t \\<in> P}\"] case_assms(2) traces_def by fastforce\n    then show \"\\<exists>y. s @ [tick] = tt2T y \\<and> [ttevt2F a]\\<^sub>E # y \\<in> P\"\n      using y'_assms case_assms(2) by blast\n  qed\n  then show \"a # s @ [tick] \\<in> traces(({(s, X). \\<exists>y. Some (s, X) = tt2F y \\<and> y \\<in> P}, {tt2T y |y. y \\<in> P})) \\<Longrightarrow>\n       [ttevt2F a]\\<^sub>E # map (\\<lambda>e. [ttevt2F e]\\<^sub>E) s @ [[Tick]\\<^sub>E] \\<in> P\"\n    using ind_hyp by blast\nqed\n\nlemma tt2sf_eq_mkF24_ttproc2F:\n  assumes P_wf: \"\\<forall>x\\<in>P. ttWF x\" and TT1_P: \"TT1 P\"\n  shows \"tt2sf P = mkF24 (ttproc2F P)\"\n  unfolding mkF24_def tt2sf_def ttproc2F_def\n  apply auto\n  using assms end_refusal_ttWF_eq apply blast\n  using assms end_tick_in_traces apply blast\n  using assms end_tick_in_traces apply blast\n  apply (simp add: TT1_P tt2F_Some_ref_end_refusal_in_TT1)\n  apply (simp add: TT1_P tt2F_Some_ref_end_refusal_in_TT1)\n  using end_tick_in_traces_imp_in_ttproc apply blast\n  using end_tick_in_traces_imp_in_ttproc apply blast\n  using end_tick_in_traces_imp_in_ttproc apply blast\n  by (auto simp add: traces_def)\n  \nend\n  ", "meta": {"author": "UoY-RoboStar", "repo": "tick-tock-CSP", "sha": "7186d2e7f70116589850112a7353bc521372c913", "save_path": "github-repos/isabelle/UoY-RoboStar-tick-tock-CSP", "path": "github-repos/isabelle/UoY-RoboStar-tick-tock-CSP/tick-tock-CSP-7186d2e7f70116589850112a7353bc521372c913/Failures/Failures_Stable_TickTock.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526660244838, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.2760252823944037}}
{"text": "(*  Title:      Mapping_Exts.thy\n    Author:     Denis Lohner, Sebastian Ullrich\n*)\n\nsubsection \"Mapping Extensions\"\n\ntext \\<open>Some lifted definition on mapping and efficient implementations.\\<close>\n\ntheory Mapping_Exts\nimports \"HOL-Library.Mapping\" FormalSSA_Misc\nbegin\n\nlift_definition mapping_delete_all :: \"('a \\<Rightarrow> bool) \\<Rightarrow> ('a,'b) mapping \\<Rightarrow> ('a,'b) mapping\"\n  is \"\\<lambda>P m x. if (P x) then None else m x\" .\nlift_definition map_keys :: \"('a \\<Rightarrow> 'b) \\<Rightarrow> ('a,'c) mapping \\<Rightarrow> ('b,'c) mapping\"\n  is \"\\<lambda>f m x. if f -` {x} \\<noteq> {} then m (THE k. f -` {x} = {k}) else None\" .\nlift_definition map_values :: \"('a \\<Rightarrow> 'b \\<Rightarrow> 'c option) \\<Rightarrow> ('a,'b) mapping \\<Rightarrow> ('a,'c) mapping\"\n  is \"\\<lambda>f m x. Option.bind (m x) (f x)\" .\nlift_definition restrict_mapping :: \"('a \\<Rightarrow> 'b) \\<Rightarrow> 'a set \\<Rightarrow> ('a, 'b) mapping\"\n  is \"\\<lambda>f. restrict_map (Some \\<circ> f)\" .\nlift_definition mapping_add :: \"('a, 'b) mapping \\<Rightarrow> ('a, 'b) mapping \\<Rightarrow> ('a, 'b) mapping\"\n  is \"(++)\" .\n\ndefinition \"mmap = Mapping.map id\"\n\nlemma lookup_map_keys: \"Mapping.lookup (map_keys f m) x = (if f -` {x} \\<noteq> {} then Mapping.lookup m (THE k. f -` {x} = {k}) else None)\"\napply transfer ..\n\nlemma Mapping_Mapping_lookup [simp, code_unfold]: \"Mapping.Mapping (Mapping.lookup m) = m\" by transfer simp\ndeclare Mapping.lookup.abs_eq[simp]\n\nlemma Mapping_eq_lookup: \"m = m' \\<longleftrightarrow> Mapping.lookup m = Mapping.lookup m'\" by transfer simp\n\nlemma map_of_map_if_conv:\n  \"map_of (map (\\<lambda>k. (k, f k)) xs) x = (if (x \\<in> set xs) then Some (f x) else None)\"\n  by (clarsimp simp: map_of_map_restrict)\n\nlemma Mapping_lookup_map: \"Mapping.lookup (Mapping.map f g m) a = map_option g (Mapping.lookup m (f a))\"\n  by transfer simp\n\nlemma Mapping_lookup_map_default: \"Mapping.lookup (Mapping.map_default k d f m) k' = (if k = k'\n  then (Some \\<circ> f) (case Mapping.lookup m k of None \\<Rightarrow> d | Some x \\<Rightarrow> x)\n  else Mapping.lookup m k')\"\n  unfolding Mapping.map_default_def Mapping.default_def\n  by transfer auto\n\nlemma Mapping_lookup_mapping_add: \"Mapping.lookup (mapping_add m1 m2) k =\n  case_option (Mapping.lookup m1 k) Some (Mapping.lookup m2 k)\"\n  by transfer (simp add: map_add_def)\n\nlemma Mapping_lookup_map_values: \"Mapping.lookup (map_values f m) k =\n  Option.bind (Mapping.lookup m k) (f k)\"\n  by transfer simp\n\nlemma lookup_fold_update [simp]: \"Mapping.lookup (fold (\\<lambda>n. Mapping.update n (g n)) xs m) x\n  = (if (x \\<in> set xs) then Some (g x) else Mapping.lookup m x)\"\n  by transfer (rule fold_update_conv)\n\nlemma mapping_eq_iff: \"m1 = m2 \\<longleftrightarrow> (\\<forall>k. Mapping.lookup m1 k = Mapping.lookup m2 k)\"\n  by transfer auto\n\nlemma lookup_delete: \"Mapping.lookup (Mapping.delete k m) k' = (if k = k' then None else Mapping.lookup m k')\"\n  by transfer auto\n\nlemma keys_map_values: \"Mapping.keys (map_values f m) = Mapping.keys m - {k\\<in>Mapping.keys m. f k (the (Mapping.lookup m k)) = None}\"\n  by transfer (auto simp add: bind_eq_Some_conv)\n\nlemma map_default_eq: \"Mapping.map_default k v f m = m \\<longleftrightarrow> (\\<exists>v. Mapping.lookup m k = Some v \\<and> f v = v)\"\n  apply (clarsimp simp: Mapping.map_default_def Mapping.default_def)\n  by transfer' (auto simp: fun_eq_iff split: if_splits)\n\nlemma lookup_update_cases: \"Mapping.lookup (Mapping.update k v m) k' = (if k=k' then Some v else Mapping.lookup m k')\"\nby (cases \"k=k'\", simp_all add: Mapping.lookup_update Mapping.lookup_update_neq)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Formal_SSA/Mapping_Exts.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526514141572, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.27602527531745247}}
{"text": "(* TODO: Move to Refine-Monadic *)\ntheory Refine_Monadic_Add\nimports Refine_Monadic_Thin\nbegin\n\n  lemma option_rel_inv_conv:\n    \"(x,Some v')\\<in>\\<langle>V\\<rangle>option_rel \\<longleftrightarrow> (\\<exists>v. x=Some v \\<and> (v,v')\\<in>V)\"\n    \"(Some v,x')\\<in>\\<langle>V\\<rangle>option_rel \\<longleftrightarrow> (\\<exists>v'. x'=Some v' \\<and> (v,v')\\<in>V)\"\n    subgoal by (cases x; auto)\n    subgoal by (cases x'; auto)\n    done\n\n\n\n  definition \"monadic_WHILEIT I b f s \\<equiv> do {\n    RECT (\\<lambda>D s. do {\n      ASSERT (I s);\n      bv \\<leftarrow> b s;\n      if bv then do {\n        s \\<leftarrow> f s;\n        D s\n      } else do {RETURN s}\n    }) s\n  }\"\n  \n  \n  \n  lemma WHILEIT_to_monadic: \"WHILEIT I b f s = monadic_WHILEIT I (\\<lambda>s. RETURN (b s)) f s\"\n    unfolding WHILEIT_def monadic_WHILEIT_def\n    unfolding WHILEI_body_def bind_ASSERT_eq_if\n    by (simp cong: if_cong)\n  \n\nlemma monadic_WHILEIT_refine[refine]:  \n  assumes [refine]: \"(s',s) \\<in> R\"\n  assumes [refine]: \"\\<And>s' s. \\<lbrakk> (s',s)\\<in>R; I s \\<rbrakk> \\<Longrightarrow> I' s'\"  \n  assumes [refine]: \"\\<And>s' s. \\<lbrakk> (s',s)\\<in>R; I s; I' s' \\<rbrakk> \\<Longrightarrow> b' s' \\<le>\\<Down>bool_rel (b s)\"\n  assumes [refine]: \"\\<And>s' s. \\<lbrakk> (s',s)\\<in>R; I s; I' s'; nofail (b s); inres (b s) True \\<rbrakk> \\<Longrightarrow> f' s' \\<le>\\<Down>R (f s)\"\n  shows \"monadic_WHILEIT I' b' f' s' \\<le>\\<Down>R (monadic_WHILEIT I b f s)\"\n  unfolding monadic_WHILEIT_def\n  by (refine_rcg bind_refine'; assumption?; auto)\n  \nlemma monadic_WHILEIT_refine_WHILEIT[refine]:  \n  assumes [refine]: \"(s',s) \\<in> R\"\n  assumes [refine]: \"\\<And>s' s. \\<lbrakk> (s',s)\\<in>R; I s \\<rbrakk> \\<Longrightarrow> I' s'\"  \n  assumes [THEN order_trans,refine_vcg]: \"\\<And>s' s. \\<lbrakk> (s',s)\\<in>R; I s; I' s' \\<rbrakk> \\<Longrightarrow> b' s' \\<le> SPEC (\\<lambda>r. r = b s)\"\n  assumes [refine]: \"\\<And>s' s. \\<lbrakk> (s',s)\\<in>R; I s; I' s'; b s \\<rbrakk> \\<Longrightarrow> f' s' \\<le>\\<Down>R (f s)\"\n  shows \"monadic_WHILEIT I' b' f' s' \\<le>\\<Down>R (WHILEIT I b f s)\"\n  unfolding WHILEIT_to_monadic\n  by (refine_vcg; assumption?; auto)\n  \nlemma monadic_WHILEIT_refine_WHILET[refine]:  \n  assumes [refine]: \"(s',s) \\<in> R\"\n  assumes [THEN order_trans,refine_vcg]: \"\\<And>s' s. \\<lbrakk> (s',s)\\<in>R \\<rbrakk> \\<Longrightarrow> b' s' \\<le> SPEC (\\<lambda>r. r = b s)\"\n  assumes [refine]: \"\\<And>s' s. \\<lbrakk> (s',s)\\<in>R; b s \\<rbrakk> \\<Longrightarrow> f' s' \\<le>\\<Down>R (f s)\"\n  shows \"monadic_WHILEIT (\\<lambda>_. True) b' f' s' \\<le>\\<Down>R (WHILET b f s)\"\n  unfolding WHILET_def\n  by (refine_vcg; assumption?)  \n\n\n\nend\n", "meta": {"author": "lammich", "repo": "isabelle_llvm", "sha": "6be37a9c3cae74a1134dbef2979e312abb5f7f42", "save_path": "github-repos/isabelle/lammich-isabelle_llvm", "path": "github-repos/isabelle/lammich-isabelle_llvm/isabelle_llvm-6be37a9c3cae74a1134dbef2979e312abb5f7f42/thys-2018/sepref/Refine_Monadic_Add.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5273165233795672, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.27600819866722237}}
{"text": "theory \"WooLam_cert_auto\"\nimports\n  \"ESPLogic\"\nbegin\n\n(* section:  Woo and Lam Mutual Authentication Protocol  *)\n\n(* text: \n  Modeled after the description in the SPORE library:\n\n    http://www.lsv.ens-cachan.fr/Software/spore/wooLamMutual.html\n\n  Notable differences:\n\n    1. We are using explicit global constants to discern between different\n       encryptions instead of the implicit typing, which introduces\n       ambiguities. This implies that we are not precisely modeling the Woo and\n       Lam protocol of the SPORE library and hence we may miss some attacks\n       possible on it. However, every implementation of the SPORE model could\n       easily be changed to our version and benefit from the full correctness\n       proof.\n *)\n\nrole A\nwhere \"A =\n  [ Send ''1'' <| sAV ''A'', sN ''na'' |>\n  , Recv ''2'' <| sMV ''B'', sMV ''nb'' |>\n  , Send ''3'' ( PEnc <| sC ''enc3'', sAV ''A'', sMV ''B'', sN ''na'',\n                         sMV ''nb''\n                      |>\n                      ( sK ''A'' ''S'' )\n               )\n  , Recv ''6'' <| PEnc <| sC ''enc51'', sMV ''B'', sN ''na'', sMV ''nb'',\n                          sMV ''kab''\n                       |>\n                       ( sK ''A'' ''S'' ),\n                  PEnc <| sC ''enc6'', sN ''na'', sMV ''nb'' |> ( sMV ''kab'' )\n               |>\n  , Send ''7'' ( PEnc <| sC ''enc7'', sMV ''nb'' |> ( sMV ''kab'' ) )\n  ]\"\n\nrole B\nwhere \"B =\n  [ Recv ''1'' <| sMV ''A'', sMV ''na'' |>\n  , Send ''2'' <| sAV ''B'', sN ''nb'' |>\n  , Recv ''3'' ( sMV ''Ticket1'' )\n  , Send ''4'' <| sMV ''Ticket1'',\n                  PEnc <| sC ''enc4'', sMV ''A'', sAV ''B'', sMV ''na'', sN ''nb'' |>\n                       ( sK ''B'' ''S'' )\n               |>\n  , Recv ''5'' <| sMV ''Ticket2'',\n                  PEnc <| sC ''enc52'', sMV ''A'', sMV ''na'', sN ''nb'', sMV ''kab'' |>\n                       ( sK ''B'' ''S'' )\n               |>\n  , Send ''6'' <| sMV ''Ticket2'',\n                  PEnc <| sC ''enc6'', sMV ''na'', sN ''nb'' |> ( sMV ''kab'' )\n               |>\n  , Recv ''7'' ( PEnc <| sC ''enc7'', sN ''nb'' |> ( sMV ''kab'' ) )\n  ]\"\n\nrole S\nwhere \"S =\n  [ Recv ''4'' <| PEnc <| sC ''enc3'', sMV ''A'', sMV ''B'', sMV ''na'',\n                          sMV ''nb''\n                       |>\n                       ( PSymK ( sMV ''A'' ) ( sAV ''S'' ) ),\n                  PEnc <| sC ''enc4'', sMV ''A'', sMV ''B'', sMV ''na'', sMV ''nb'' |>\n                       ( PSymK ( sMV ''A'' ) ( sAV ''S'' ) )\n               |>\n  , Send ''5'' <| PEnc <| sC ''enc51'', sMV ''B'', sMV ''na'', sMV ''nb'',\n                          sN ''kab''\n                       |>\n                       ( PSymK ( sMV ''A'' ) ( sAV ''S'' ) ),\n                  PEnc <| sC ''enc52'', sMV ''A'', sMV ''na'', sMV ''nb'', sN ''kab'' |>\n                       ( PSymK ( sMV ''B'' ) ( sAV ''S'' ) )\n               |>\n  ]\"\n\nprotocol WooLam\nwhere \"WooLam = { A, B, S }\"\n\nlocale restricted_WooLam_state = WooLam_state\n\ntype_invariant WooLam_msc_typing for WooLam\nwhere \"WooLam_msc_typing = mk_typing\n  [ ((B, ''A''), (KnownT B_1))\n  , ((S, ''A''), (SumT (KnownT S_4) AgentT))\n  , ((A, ''B''), (KnownT A_2))\n  , ((S, ''B''), (SumT (KnownT S_4) AgentT))\n  , ((B, ''Ticket1''), (KnownT B_3))\n  , ((B, ''Ticket2''), (KnownT B_5))\n  , ((A, ''kab''), (SumT (KnownT A_6) (NonceT S ''kab'')))\n  , ((B, ''kab''), (SumT (KnownT B_5) (NonceT S ''kab'')))\n  , ((B, ''na''), (KnownT B_1))\n  , ((S, ''na''), (SumT (KnownT S_4) (NonceT A ''na'')))\n  , ((A, ''nb''), (KnownT A_2))\n  , ((S, ''nb''), (SumT (KnownT S_4) (NonceT B ''nb'')))\n  ]\"\n\nsublocale WooLam_state < WooLam_msc_typing_state\nproof -\n  have \"(t,r,s) : approx WooLam_msc_typing\"\n  proof(cases rule: reachable_in_approxI_ext\n        [OF WooLam_msc_typing.monoTyp, completeness_cases_rule])\n    case (A_2_B t r s tid0)\n    then interpret state: WooLam_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = A_2_B\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (A_2_nb t r s tid0)\n    then interpret state: WooLam_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = A_2_nb\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (A_6_kab t r s tid0)\n    then interpret state: WooLam_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = A_6_kab\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''enc51'', s(MV ''B'' tid0), LN ''na'' tid0, s(MV ''nb'' tid0),\n               s(MV ''kab'' tid0)\n            |}\n            ( K ( s(AV ''A'' tid0) ) ( s(AV ''S'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (B_1_A t r s tid0)\n    then interpret state: WooLam_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = B_1_A\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (B_1_na t r s tid0)\n    then interpret state: WooLam_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = B_1_na\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (B_5_Ticket2 t r s tid0)\n    then interpret state: WooLam_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = B_5_Ticket2\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (B_5_kab t r s tid0)\n    then interpret state: WooLam_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = B_5_kab\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''enc52'', s(MV ''A'' tid0), s(MV ''na'' tid0), LN ''nb'' tid0,\n               s(MV ''kab'' tid0)\n            |}\n            ( K ( s(AV ''B'' tid0) ) ( s(AV ''S'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (S_4_A t r s tid0)\n    then interpret state: WooLam_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = S_4_A\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''enc3'', s(MV ''A'' tid0), s(MV ''B'' tid0),\n               s(MV ''na'' tid0), s(MV ''nb'' tid0)\n            |}\n            ( K ( s(MV ''A'' tid0) ) ( s(AV ''S'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (S_4_B t r s tid0)\n    then interpret state: WooLam_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = S_4_B\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''enc3'', s(MV ''A'' tid0), s(MV ''B'' tid0),\n               s(MV ''na'' tid0), s(MV ''nb'' tid0)\n            |}\n            ( K ( s(MV ''A'' tid0) ) ( s(AV ''S'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (S_4_na t r s tid0)\n    then interpret state: WooLam_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = S_4_na\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''enc3'', s(MV ''A'' tid0), s(MV ''B'' tid0),\n               s(MV ''na'' tid0), s(MV ''nb'' tid0)\n            |}\n            ( K ( s(MV ''A'' tid0) ) ( s(AV ''S'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (S_4_nb t r s tid0)\n    then interpret state: WooLam_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = S_4_nb\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''enc3'', s(MV ''A'' tid0), s(MV ''B'' tid0),\n               s(MV ''na'' tid0), s(MV ''nb'' tid0)\n            |}\n            ( K ( s(MV ''A'' tid0) ) ( s(AV ''S'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  qed\n  thus \"WooLam_msc_typing_state t r s\" by unfold_locales auto\nqed\n\ntext{* Prove secrecy of long-term keys. *}\ncontext WooLam_state begin\n\n  (* This rule is unsafe in general, but OK here, \n     as we are only reasoning about static compromise. \n  *)\n  lemma static_longterm_key_reveal[dest!]:\n    \"predOrd t (LKR a) e ==> RLKR a : reveals t\"\n    by (auto intro: compr_predOrdI)\n\n  lemma longterm_private_key_secrecy:\n    assumes facts:\n      \"SK m : knows t\"\n      \"RLKR m ~: reveals t\"\n    shows \"False\"\n  using facts by (sources \"SK m\")\n\n  lemma longterm_sym_ud_key_secrecy:\n    assumes facts:\n      \"K m1 m2 : knows t\"\n      \"RLKR m1 ~: reveals t\"\n      \"RLKR m2 ~: reveals t\"\n    shows \"False\"\n  using facts by (sources \"K m1 m2\")\n\n  lemma longterm_sym_bd_key_secrecy:\n    assumes facts:\n      \"Kbd m1 m2 : knows t\"\n      \"RLKR m1 ~: reveals t\"\n      \"RLKR m2 ~: reveals t\"\n      \"m1 : Agent\"\n      \"m2 : Agent\"\n    shows \"False\"\n  proof -\n    from facts \n    have \"KShr (agents {m1, m2}) : knows t\"\n      by (auto simp: Kbd_def)\n    thus ?thesis using facts\n    proof (sources \"KShr (agents {m1, m2})\")\n    qed (auto simp: agents_def Agent_def)\n  qed\n\n  lemmas ltk_secrecy =\n    longterm_sym_ud_key_secrecy\n    longterm_sym_ud_key_secrecy[OF in_knows_predOrd1]\n    longterm_sym_bd_key_secrecy\n    longterm_sym_bd_key_secrecy[OF in_knows_predOrd1]\n    longterm_private_key_secrecy\n    longterm_private_key_secrecy[OF in_knows_predOrd1]\n\nend\n\n(* subsection:  Secrecy Properties  *)\n\nlemma (in restricted_WooLam_state) S_sec_kab:\n  assumes facts:\n    \"roleMap r tid0 = Some S\"\n    \"RLKR(s(AV ''S'' tid0)) ~: reveals t\"\n    \"RLKR(s(MV ''A'' tid0)) ~: reveals t\"\n    \"RLKR(s(MV ''B'' tid0)) ~: reveals t\"\n    \"LN ''kab'' tid0 : knows t\"\n  shows \"False\"\nusing facts proof(sources! \" LN ''kab'' tid0 \")\n  case S_5_kab note_unified facts = this facts\n  thus ?thesis by (auto dest!: ltk_secrecy)\nnext\n  case S_5_kab_1 note_unified facts = this facts\n  thus ?thesis by (auto dest!: ltk_secrecy)\nqed (safe?, simp_all?, insert facts, (fastforce+)?)\n\nlemma (in restricted_WooLam_state) A_sec_kab:\n  assumes facts:\n    \"roleMap r tid0 = Some A\"\n    \"RLKR(s(AV ''A'' tid0)) ~: reveals t\"\n    \"RLKR(s(AV ''S'' tid0)) ~: reveals t\"\n    \"RLKR(s(MV ''B'' tid0)) ~: reveals t\"\n    \"( tid0, A_6 ) : steps t\"\n    \"s(MV ''kab'' tid0) : knows t\"\n  shows \"False\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''enc51'', s(MV ''B'' tid0), LN ''na'' tid0, s(MV ''nb'' tid0),\n                          s(MV ''kab'' tid0)\n                       |}\n                       ( K ( s(AV ''A'' tid0) ) ( s(AV ''S'' tid0) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (auto dest!: ltk_secrecy)\n  next\n    case (S_5_enc tid1) note_unified facts = this facts\n    thus ?thesis by (fastforce dest: S_sec_kab intro: event_predOrdI)\n  qed (safe?, simp_all?, insert facts, (fastforce+)?)\nqed\n\nlemma (in restricted_WooLam_state) B_sec_kab:\n  assumes facts:\n    \"roleMap r tid0 = Some B\"\n    \"RLKR(s(AV ''B'' tid0)) ~: reveals t\"\n    \"RLKR(s(AV ''S'' tid0)) ~: reveals t\"\n    \"RLKR(s(MV ''A'' tid0)) ~: reveals t\"\n    \"( tid0, B_5 ) : steps t\"\n    \"s(MV ''kab'' tid0) : knows t\"\n  shows \"False\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''enc52'', s(MV ''A'' tid0), s(MV ''na'' tid0), LN ''nb'' tid0,\n                          s(MV ''kab'' tid0)\n                       |}\n                       ( K ( s(AV ''B'' tid0) ) ( s(AV ''S'' tid0) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (auto dest!: ltk_secrecy)\n  next\n    case (S_5_enc_1 tid1) note_unified facts = this facts\n    thus ?thesis by (fastforce dest: S_sec_kab intro: event_predOrdI)\n  qed (safe?, simp_all?, insert facts, (fastforce+)?)\nqed\n\nlemma (in restricted_WooLam_state) A_sec_inv_kab:\n  assumes facts:\n    \"roleMap r tid0 = Some A\"\n    \"RLKR(s(AV ''A'' tid0)) ~: reveals t\"\n    \"RLKR(s(AV ''S'' tid0)) ~: reveals t\"\n    \"RLKR(s(MV ''B'' tid0)) ~: reveals t\"\n    \"( tid0, A_6 ) : steps t\"\n    \"inv(s(MV ''kab'' tid0)) : knows t\"\n  shows \"False\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''enc51'', s(MV ''B'' tid0), LN ''na'' tid0, s(MV ''nb'' tid0),\n                          s(MV ''kab'' tid0)\n                       |}\n                       ( K ( s(AV ''A'' tid0) ) ( s(AV ''S'' tid0) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (auto dest!: ltk_secrecy)\n  next\n    case (S_5_enc tid1) note_unified facts = this facts\n    thus ?thesis by (fastforce dest: S_sec_kab intro: event_predOrdI)\n  qed (safe?, simp_all?, insert facts, (fastforce+)?)\nqed\n\nlemma (in restricted_WooLam_state) B_sec_inv_kab:\n  assumes facts:\n    \"roleMap r tid0 = Some B\"\n    \"RLKR(s(AV ''B'' tid0)) ~: reveals t\"\n    \"RLKR(s(AV ''S'' tid0)) ~: reveals t\"\n    \"RLKR(s(MV ''A'' tid0)) ~: reveals t\"\n    \"( tid0, B_5 ) : steps t\"\n    \"inv(s(MV ''kab'' tid0)) : knows t\"\n  shows \"False\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''enc52'', s(MV ''A'' tid0), s(MV ''na'' tid0), LN ''nb'' tid0,\n                          s(MV ''kab'' tid0)\n                       |}\n                       ( K ( s(AV ''B'' tid0) ) ( s(AV ''S'' tid0) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (auto dest!: ltk_secrecy)\n  next\n    case (S_5_enc_1 tid1) note_unified facts = this facts\n    thus ?thesis by (fastforce dest: S_sec_kab intro: event_predOrdI)\n  qed (safe?, simp_all?, insert facts, (fastforce+)?)\nqed\n\n(* subsection:  Authentication  *)\n\nlemma (in restricted_WooLam_state) na_first_send:\n  assumes facts:\n    \"roleMap r tid1 = Some A\"\n    \"LN ''na'' tid1 : knows t\"\n  shows \"predOrd t (St( tid1, A_1 )) (Ln(LN ''na'' tid1))\"\nusing facts proof(sources! \" LN ''na'' tid1 \")\n  case A_1_na note_unified facts = this facts\n  thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\nnext\n  case A_3_na note_unified facts = this facts\n  thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\nnext\n  case (S_5_na tid2) note_unified facts = this facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''enc3'', s(MV ''A'' tid2), s(MV ''B'' tid2), LN ''na'' tid1,\n                          s(MV ''nb'' tid2)\n                       |}\n                       ( K ( s(MV ''A'' tid2) ) ( s(AV ''S'' tid2) ) ) \")\n    case (A_3_enc tid3) note_unified facts = this facts\n    thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\n  qed (safe?, simp_all?, insert facts, ((((clarsimp, order?) | order | fast))+)?)\nnext\n  case (S_5_na_1 tid2) note_unified facts = this facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''enc3'', s(MV ''A'' tid2), s(MV ''B'' tid2), LN ''na'' tid1,\n                          s(MV ''nb'' tid2)\n                       |}\n                       ( K ( s(MV ''A'' tid2) ) ( s(AV ''S'' tid2) ) ) \")\n    case (A_3_enc tid3) note_unified facts = this facts\n    thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\n  qed (safe?, simp_all?, insert facts, ((((clarsimp, order?) | order | fast))+)?)\nqed (safe?, simp_all?, insert facts, (fastforce+)?)\n\nlemma (in restricted_WooLam_state) nb_first_send:\n  assumes facts:\n    \"roleMap r tid1 = Some B\"\n    \"LN ''nb'' tid1 : knows t\"\n  shows \"predOrd t (St( tid1, B_2 )) (Ln(LN ''nb'' tid1))\"\nusing facts proof(sources! \" LN ''nb'' tid1 \")\n  case B_2_nb note_unified facts = this facts\n  thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\nnext\n  case B_4_nb note_unified facts = this facts\n  thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\nnext\n  case B_6_nb note_unified facts = this facts\n  thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\nnext\n  case (S_5_nb tid2) note_unified facts = this facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''enc3'', s(MV ''A'' tid2), s(MV ''B'' tid2),\n                          s(MV ''na'' tid2), LN ''nb'' tid1\n                       |}\n                       ( K ( s(MV ''A'' tid2) ) ( s(AV ''S'' tid2) ) ) \")\n  qed (safe?, simp_all?, insert facts, ((((clarsimp, order?) | order | fast))+)?)\nnext\n  case (S_5_nb_1 tid2) note_unified facts = this facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''enc3'', s(MV ''A'' tid2), s(MV ''B'' tid2),\n                          s(MV ''na'' tid2), LN ''nb'' tid1\n                       |}\n                       ( K ( s(MV ''A'' tid2) ) ( s(AV ''S'' tid2) ) ) \")\n  qed (safe?, simp_all?, insert facts, ((((clarsimp, order?) | order | fast))+)?)\nqed (safe?, simp_all?, insert facts, (fastforce+)?)\n\nlemma (in restricted_WooLam_state) A_ni_synch:\n  assumes facts:\n    \"roleMap r tid1 = Some A\"\n    \"RLKR(s(AV ''A'' tid1)) ~: reveals t\"\n    \"RLKR(s(AV ''S'' tid1)) ~: reveals t\"\n    \"RLKR(s(MV ''B'' tid1)) ~: reveals t\"\n    \"( tid1, A_6 ) : steps t\"\n  shows\n    \"(?  tid2.\n        (?  tid3.\n           roleMap r tid2 = Some B &\n           roleMap r tid3 = Some S &\n           s(AV ''A'' tid1) = s(MV ''A'' tid2) &\n           s(MV ''B'' tid1) = s(AV ''B'' tid2) &\n           s(AV ''S'' tid1) = s(AV ''S'' tid2) &\n           LN ''na'' tid1 = s(MV ''na'' tid2) &\n           s(MV ''nb'' tid1) = LN ''nb'' tid2 &\n           s(MV ''kab'' tid1) = s(MV ''kab'' tid2) &\n           s(AV ''A'' tid1) = s(MV ''A'' tid3) &\n           s(MV ''B'' tid1) = s(MV ''B'' tid3) &\n           s(AV ''S'' tid1) = s(AV ''S'' tid3) &\n           LN ''na'' tid1 = s(MV ''na'' tid3) &\n           s(MV ''nb'' tid1) = s(MV ''nb'' tid3) &\n           s(MV ''kab'' tid1) = LN ''kab'' tid3 &\n           predOrd t (St( tid1, A_1 )) (St( tid2, B_1 )) &\n           predOrd t (St( tid2, B_1 )) (St( tid2, B_2 )) &\n           predOrd t (St( tid2, B_2 )) (St( tid1, A_2 )) &\n           predOrd t (St( tid1, A_2 )) (St( tid1, A_3 )) &\n           predOrd t (St( tid1, A_3 )) (St( tid3, S_4 )) &\n           predOrd t (St( tid3, S_4 )) (St( tid3, S_5 )) &\n           predOrd t (St( tid3, S_5 )) (St( tid2, B_5 )) &\n           predOrd t (St( tid2, B_5 )) (St( tid2, B_6 )) &\n           predOrd t (St( tid2, B_6 )) (St( tid1, A_6 )) &\n           predOrd t (St( tid2, B_3 )) (St( tid2, B_4 )) &\n           predOrd t (St( tid2, B_4 )) (St( tid3, S_4 ))))\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''enc51'', s(MV ''B'' tid1), LN ''na'' tid1, s(MV ''nb'' tid1),\n                          s(MV ''kab'' tid1)\n                       |}\n                       ( K ( s(AV ''A'' tid1) ) ( s(AV ''S'' tid1) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (auto dest!: ltk_secrecy)\n  next\n    case (S_5_enc tid2) note_unified facts = this facts\n    thus ?thesis proof(sources! \"\n                     Enc {| LC ''enc3'', s(AV ''A'' tid1), s(MV ''B'' tid1), LN ''na'' tid1,\n                            s(MV ''nb'' tid1)\n                         |}\n                         ( K ( s(AV ''A'' tid1) ) ( s(AV ''S'' tid1) ) ) \")\n      case fake note_unified facts = this facts\n      thus ?thesis by (auto dest!: ltk_secrecy)\n    next\n      case (A_3_enc tid3) note_unified facts = this facts\n      thus ?thesis proof(sources! \"\n                       Enc {| LC ''enc4'', s(AV ''A'' tid1), s(MV ''B'' tid1), LN ''na'' tid1,\n                              s(MV ''nb'' tid1)\n                           |}\n                           ( K ( s(AV ''A'' tid1) ) ( s(AV ''S'' tid1) ) ) \")\n        case fake note_unified facts = this facts\n        thus ?thesis by (auto dest!: ltk_secrecy)\n      next\n        case (B_4_enc tid3) note_unified facts = this facts\n        have f1: \"roleMap r tid1 = Some A\" using facts by (auto intro: event_predOrdI)\n        have f2: \"LN ''na'' tid1 : knows t\" using facts by (auto intro: event_predOrdI)\n        note facts = facts na_first_send[OF f1 f2, simplified]\n        have f1: \"roleMap r tid3 = Some B\" using facts by (auto intro: event_predOrdI)\n        have f2: \"LN ''nb'' tid3 : knows t\" using facts by (auto intro: event_predOrdI)\n        note facts = facts nb_first_send[OF f1 f2, simplified]\n        thus ?thesis proof(sources! \"\n                         Enc {| LC ''enc6'', LN ''na'' tid1, LN ''nb'' tid3 |}\n                             ( LN ''kab'' tid2 ) \")\n          case fake note_unified facts = this facts\n          thus ?thesis by (fastforce dest: S_sec_kab intro: event_predOrdI)\n        next\n          case (B_6_enc tid4) note_unified facts = this facts\n          thus ?thesis proof(sources! \"\n                           Enc {| LC ''enc52'', s(AV ''A'' tid1), LN ''na'' tid1, LN ''nb'' tid3,\n                                  LN ''kab'' tid2\n                               |}\n                               ( K ( s(AV ''A'' tid1) ) ( s(AV ''S'' tid1) ) ) \")\n            case fake note_unified facts = this facts\n            thus ?thesis by (auto dest!: ltk_secrecy)\n          next\n            case (S_5_enc_1 tid4) note_unified facts = this facts\n            thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\n          qed (safe?, simp_all?, insert facts, (fastforce+)?)\n        qed (safe?, simp_all?, insert facts, (fastforce+)?)\n      qed (safe?, simp_all?, insert facts, (fastforce+)?)\n    qed (safe?, simp_all?, insert facts, (fastforce+)?)\n  qed (safe?, simp_all?, insert facts, (fastforce+)?)\nqed\n\nlemma (in restricted_WooLam_state) B_ni_synch:\n  assumes facts:\n    \"roleMap r tid2 = Some B\"\n    \"RLKR(s(AV ''B'' tid2)) ~: reveals t\"\n    \"RLKR(s(AV ''S'' tid2)) ~: reveals t\"\n    \"RLKR(s(MV ''A'' tid2)) ~: reveals t\"\n    \"( tid2, B_7 ) : steps t\"\n  shows\n    \"(?  tid1.\n        (?  tid3.\n           roleMap r tid1 = Some A &\n           roleMap r tid3 = Some S &\n           s(MV ''A'' tid2) = s(AV ''A'' tid1) &\n           s(AV ''B'' tid2) = s(MV ''B'' tid1) &\n           s(AV ''S'' tid2) = s(AV ''S'' tid1) &\n           s(MV ''na'' tid2) = LN ''na'' tid1 &\n           LN ''nb'' tid2 = s(MV ''nb'' tid1) &\n           s(MV ''kab'' tid2) = s(MV ''kab'' tid1) &\n           s(MV ''A'' tid2) = s(MV ''A'' tid3) &\n           s(AV ''B'' tid2) = s(MV ''B'' tid3) &\n           s(AV ''S'' tid2) = s(AV ''S'' tid3) &\n           s(MV ''na'' tid2) = s(MV ''na'' tid3) &\n           LN ''nb'' tid2 = s(MV ''nb'' tid3) &\n           s(MV ''kab'' tid2) = LN ''kab'' tid3 &\n           predOrd t (St( tid1, A_1 )) (St( tid2, B_1 )) &\n           predOrd t (St( tid2, B_1 )) (St( tid2, B_2 )) &\n           predOrd t (St( tid2, B_2 )) (St( tid1, A_2 )) &\n           predOrd t (St( tid1, A_2 )) (St( tid1, A_3 )) &\n           predOrd t (St( tid1, A_3 )) (St( tid3, S_4 )) &\n           predOrd t (St( tid3, S_4 )) (St( tid3, S_5 )) &\n           predOrd t (St( tid3, S_5 )) (St( tid2, B_5 )) &\n           predOrd t (St( tid2, B_5 )) (St( tid2, B_6 )) &\n           predOrd t (St( tid2, B_6 )) (St( tid1, A_6 )) &\n           predOrd t (St( tid1, A_6 )) (St( tid1, A_7 )) &\n           predOrd t (St( tid1, A_7 )) (St( tid2, B_7 )) &\n           predOrd t (St( tid2, B_3 )) (St( tid2, B_4 )) &\n           predOrd t (St( tid2, B_4 )) (St( tid3, S_4 ))))\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''enc52'', s(MV ''A'' tid2), s(MV ''na'' tid2), LN ''nb'' tid2,\n                          s(MV ''kab'' tid2)\n                       |}\n                       ( K ( s(AV ''B'' tid2) ) ( s(AV ''S'' tid2) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (auto dest!: ltk_secrecy)\n  next\n    case (S_5_enc_1 tid3) note_unified facts = this facts\n    thus ?thesis proof(sources! \"\n                     Enc {| LC ''enc3'', s(MV ''A'' tid2), s(AV ''B'' tid2),\n                            s(MV ''na'' tid2), LN ''nb'' tid2\n                         |}\n                         ( K ( s(MV ''A'' tid2) ) ( s(AV ''S'' tid2) ) ) \")\n      case fake note_unified facts = this facts\n      thus ?thesis by (auto dest!: ltk_secrecy)\n    next\n      case (A_3_enc tid4) note_unified facts = this facts\n      have f1: \"roleMap r tid4 = Some A\" using facts by (auto intro: event_predOrdI)\n      have f2: \"LN ''na'' tid4 : knows t\" using facts by (auto intro: event_predOrdI)\n      note facts = facts na_first_send[OF f1 f2, simplified]\n      have f1: \"roleMap r tid2 = Some B\" using facts by (auto intro: event_predOrdI)\n      have f2: \"LN ''nb'' tid2 : knows t\" using facts by (auto intro: event_predOrdI)\n      note facts = facts nb_first_send[OF f1 f2, simplified]\n      thus ?thesis proof(sources! \"\n                       Enc {| LC ''enc7'', LN ''nb'' tid2 |} ( LN ''kab'' tid3 ) \")\n        case fake note_unified facts = this facts\n        thus ?thesis by (fastforce dest: S_sec_kab intro: event_predOrdI)\n      next\n        case (A_7_enc tid5) note_unified facts = this facts\n        thus ?thesis proof(sources! \"\n                         Enc {| LC ''enc4'', s(AV ''A'' tid4), s(AV ''B'' tid2), LN ''na'' tid4,\n                                LN ''nb'' tid2\n                             |}\n                             ( K ( s(AV ''A'' tid4) ) ( s(AV ''S'' tid2) ) ) \")\n          case fake note_unified facts = this facts\n          thus ?thesis by (auto dest!: ltk_secrecy)\n        next\n          case (B_4_enc tid6) note_unified facts = this facts\n          thus ?thesis proof(sources! \"\n                           Enc {| LC ''enc6'', LN ''na'' tid5, LN ''nb'' tid2 |}\n                               ( LN ''kab'' tid3 ) \")\n            case fake note_unified facts = this facts\n            thus ?thesis by (fastforce dest: S_sec_kab intro: event_predOrdI)\n          next\n            case (B_6_enc tid6) note_unified facts = this facts\n            thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\n          qed (safe?, simp_all?, insert facts, (fastforce+)?)\n        qed (safe?, simp_all?, insert facts, (fastforce+)?)\n      qed (safe?, simp_all?, insert facts, (fastforce+)?)\n    qed (safe?, simp_all?, insert facts, (fastforce+)?)\n  qed (safe?, simp_all?, insert facts, (fastforce+)?)\nqed\n\nlemma (in restricted_WooLam_state) S_ni_synch:\n  assumes facts:\n    \"roleMap r tid3 = Some S\"\n    \"RLKR(s(AV ''S'' tid3)) ~: reveals t\"\n    \"RLKR(s(MV ''A'' tid3)) ~: reveals t\"\n    \"RLKR(s(MV ''B'' tid3)) ~: reveals t\"\n    \"( tid3, S_4 ) : steps t\"\n  shows\n    \"(?  tid1.\n        (?  tid2.\n           roleMap r tid1 = Some A &\n           roleMap r tid2 = Some B &\n           s(MV ''A'' tid2) = s(AV ''A'' tid1) &\n           s(AV ''B'' tid2) = s(MV ''B'' tid1) &\n           s(AV ''S'' tid2) = s(AV ''S'' tid1) &\n           s(MV ''na'' tid2) = LN ''na'' tid1 &\n           LN ''nb'' tid2 = s(MV ''nb'' tid1) &\n           s(MV ''A'' tid2) = s(MV ''A'' tid3) &\n           s(AV ''B'' tid2) = s(MV ''B'' tid3) &\n           s(AV ''S'' tid2) = s(AV ''S'' tid3) &\n           s(MV ''na'' tid2) = s(MV ''na'' tid3) &\n           LN ''nb'' tid2 = s(MV ''nb'' tid3) &\n           predOrd t (St( tid1, A_1 )) (St( tid2, B_1 )) &\n           predOrd t (St( tid2, B_1 )) (St( tid2, B_2 )) &\n           predOrd t (St( tid2, B_2 )) (St( tid1, A_2 )) &\n           predOrd t (St( tid1, A_2 )) (St( tid1, A_3 )) &\n           predOrd t (St( tid1, A_3 )) (St( tid3, S_4 )) &\n           predOrd t (St( tid2, B_3 )) (St( tid2, B_4 )) &\n           predOrd t (St( tid2, B_4 )) (St( tid3, S_4 ))))\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''enc3'', s(MV ''A'' tid3), s(MV ''B'' tid3),\n                          s(MV ''na'' tid3), s(MV ''nb'' tid3)\n                       |}\n                       ( K ( s(MV ''A'' tid3) ) ( s(AV ''S'' tid3) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (auto dest!: ltk_secrecy)\n  next\n    case (A_3_enc tid4) note_unified facts = this facts\n    thus ?thesis proof(sources! \"\n                     Enc {| LC ''enc4'', s(AV ''A'' tid4), s(MV ''B'' tid3), LN ''na'' tid4,\n                            s(MV ''nb'' tid3)\n                         |}\n                         ( K ( s(AV ''A'' tid4) ) ( s(AV ''S'' tid3) ) ) \")\n      case fake note_unified facts = this facts\n      thus ?thesis by (auto dest!: ltk_secrecy)\n    next\n      case (B_4_enc tid5) note_unified facts = this facts\n      have f1: \"roleMap r tid4 = Some A\" using facts by (auto intro: event_predOrdI)\n      have f2: \"LN ''na'' tid4 : knows t\" using facts by (auto intro: event_predOrdI)\n      note facts = facts na_first_send[OF f1 f2, simplified]\n      have f1: \"roleMap r tid5 = Some B\" using facts by (auto intro: event_predOrdI)\n      have f2: \"LN ''nb'' tid5 : knows t\" using facts by (auto intro: event_predOrdI)\n      note facts = facts nb_first_send[OF f1 f2, simplified]\n      thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\n    qed (safe?, simp_all?, insert facts, (fastforce+)?)\n  qed (safe?, simp_all?, insert facts, (fastforce+)?)\nqed\n\nend", "meta": {"author": "meiersi", "repo": "scyther-proof", "sha": "84e42366a46f66f1b090651be3bfaa3497696280", "save_path": "github-repos/isabelle/meiersi-scyther-proof", "path": "github-repos/isabelle/meiersi-scyther-proof/scyther-proof-84e42366a46f66f1b090651be3bfaa3497696280/examples/classic/isabelle-proofs/WooLam_cert_auto.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.2760081986672223}}
{"text": "theory TransformTools\nimports \"Launchbury.Nominal-HOLCF\" Launchbury.Terms Launchbury.Substitution Launchbury.Env\nbegin\n\ndefault_sort type\n\nfun lift_transform :: \"('a::cont_pt \\<Rightarrow> exp \\<Rightarrow> exp) \\<Rightarrow> ('a\\<^sub>\\<bottom> \\<Rightarrow> exp \\<Rightarrow> exp)\"\n  where \"lift_transform t Ibottom  e = e\"\n  |     \"lift_transform t (Iup a) e = t a e\"\n\nlemma lift_transform_simps[simp]:\n  \"lift_transform t \\<bottom> e = e\"\n  \"lift_transform t (up\\<cdot>a) e = t a e\"\n  apply (metis inst_up_pcpo lift_transform.simps(1))\n  apply (simp add: up_def cont_Iup)\n  done\n\nlemma lift_transform_eqvt[eqvt]: \"\\<pi> \\<bullet>  lift_transform t a e = lift_transform (\\<pi> \\<bullet> t) (\\<pi> \\<bullet> a) (\\<pi> \\<bullet> e)\"\n  by (cases \"a\") simp_all\n\nlemma lift_transform_fun_cong[fundef_cong]:\n  \"(\\<And> a. t1 a e1 = t2 a e1) \\<Longrightarrow> a1 = a2 \\<Longrightarrow> e1 = e2 \\<Longrightarrow> lift_transform t1 a1 e1 = lift_transform t2 a2 e2\"\n  by (cases \"(t2,a2,e2)\" rule: lift_transform.cases) auto\n\nlemma subst_lift_transform: \n  assumes \"\\<And> a. (t a e)[x ::= y] = t a (e[x ::= y])\"\n  shows \"(lift_transform t a e)[x ::=y] = lift_transform t a (e[x ::= y])\"\n  using assms by (cases a) auto\n\ndefinition\n  map_transform :: \"('a::cont_pt \\<Rightarrow> exp \\<Rightarrow> exp) \\<Rightarrow> (var \\<Rightarrow> 'a\\<^sub>\\<bottom>) \\<Rightarrow> heap \\<Rightarrow> heap\"\n  where \"map_transform t ae = map_ran (\\<lambda> x e . lift_transform t (ae x) e)\"\n\nlemma map_transform_eqvt[eqvt]: \"\\<pi> \\<bullet> map_transform t ae = map_transform (\\<pi> \\<bullet> t) (\\<pi> \\<bullet> ae)\"\n  unfolding map_transform_def by simp\n\nlemma domA_map_transform[simp]: \"domA (map_transform t ae \\<Gamma>) = domA \\<Gamma>\"\n  unfolding map_transform_def by simp\n\nlemma length_map_transform[simp]: \"length (map_transform t ae xs) = length xs\"\n  unfolding map_transform_def map_ran_def by simp\n \nlemma map_transform_delete:\n  \"map_transform t ae (delete x \\<Gamma>) = delete x (map_transform t ae \\<Gamma>)\"\n  unfolding map_transform_def by (simp add: map_ran_delete)\n\nlemma map_transform_restrA:\n  \"map_transform t ae (restrictA S \\<Gamma>) = restrictA S (map_transform t ae \\<Gamma>)\"\n  unfolding map_transform_def by (auto simp add: map_ran_restrictA)\n\nlemma delete_map_transform_env_delete:\n  \"delete x (map_transform t (env_delete x ae) \\<Gamma>) = delete x (map_transform t ae \\<Gamma>)\"\n  unfolding map_transform_def by (induction \\<Gamma>) auto\n\nlemma map_transform_Nil[simp]:\n  \"map_transform t ae [] = []\"\n  unfolding map_transform_def by simp\n\nlemma map_transform_Cons:\n  \"map_transform t ae ((x,e)# \\<Gamma>) = (x, lift_transform t (ae x) e) #  (map_transform t ae \\<Gamma>)\"\n  unfolding map_transform_def by simp\n\nlemma map_transform_append:\n  \"map_transform t ae (\\<Delta>@\\<Gamma>) = map_transform t ae \\<Delta> @ map_transform t ae \\<Gamma>\"\n  unfolding map_transform_def by (simp add: map_ran_append)\n\nlemma map_transform_fundef_cong[fundef_cong]:\n  \"(\\<And>x e a. (x,e) \\<in> set m1 \\<Longrightarrow> t1 a e = t2 a e) \\<Longrightarrow> ae1 = ae2 \\<Longrightarrow> m1 = m2 \\<Longrightarrow> map_transform t1 ae1 m1 = map_transform t2 ae2 m2\"\n  by (induction m2 arbitrary: m1)\n     (fastforce simp add: map_transform_Nil map_transform_Cons intro!: lift_transform_fun_cong)+\n\nlemma map_transform_cong:\n  \"(\\<And>x. x \\<in> domA m1 \\<Longrightarrow> ae x = ae' x) \\<Longrightarrow> m1 = m2 \\<Longrightarrow> map_transform t ae m1 = map_transform t ae' m2\"\n  unfolding map_transform_def by (auto intro!: map_ran_cong dest: domA_from_set)\n\nlemma map_of_map_transform: \"map_of (map_transform t ae \\<Gamma>) x = map_option (lift_transform t (ae x)) (map_of \\<Gamma> x)\"\n  unfolding map_transform_def by (simp add: map_ran_conv)\n\nlemma supp_map_transform_step:\n  assumes \"\\<And> x e a. (x, e) \\<in> set \\<Gamma> \\<Longrightarrow> supp (t a e) \\<subseteq> supp e\"\n  shows \"supp (map_transform t ae \\<Gamma>) \\<subseteq> supp \\<Gamma>\"\n  using assms\n    apply (induction \\<Gamma>)\n    apply (auto simp add: supp_Nil supp_Cons map_transform_Nil map_transform_Cons supp_Pair pure_supp)\n    apply (case_tac \"ae a\")\n    apply (fastforce)+\n    done\n\nlemma subst_map_transform: \n  assumes \"\\<And> x' e a. (x',e) : set \\<Gamma> \\<Longrightarrow> (t a e)[x ::= y] = t a (e[x ::= y])\"\n  shows \"(map_transform t ae \\<Gamma>)[x ::h=y] = map_transform t ae (\\<Gamma>[x ::h= y])\"\n  using assms\n  apply (induction \\<Gamma>)\n  apply (auto simp add: map_transform_Nil map_transform_Cons)\n  apply (subst subst_lift_transform)\n  apply auto\n  done\n\nlocale supp_bounded_transform = \n  fixes trans :: \"'a::cont_pt \\<Rightarrow> exp \\<Rightarrow> exp\"\n  assumes supp_trans: \"supp (trans a e) \\<subseteq> supp e\"\nbegin\n  lemma supp_lift_transform: \"supp (lift_transform trans a e) \\<subseteq> supp e\"\n    by (cases \"(trans, a, e)\" rule:lift_transform.cases) (auto dest!: subsetD[OF supp_trans])\n\n  lemma supp_map_transform: \"supp (map_transform trans ae \\<Gamma>) \\<subseteq> supp \\<Gamma>\"\n  unfolding map_transform_def\n     by (induction \\<Gamma>) (auto simp add: supp_Pair supp_Cons dest!: subsetD[OF supp_lift_transform])\n\n  lemma fresh_transform[intro]: \"a \\<sharp> e \\<Longrightarrow> a \\<sharp> trans n e\"\n    by (auto simp add: fresh_def) (auto dest!: subsetD[OF supp_trans])\n\n  lemma fresh_star_transform[intro]: \"a \\<sharp>* e \\<Longrightarrow> a \\<sharp>* trans n e\"\n    by (auto simp add: fresh_star_def)\n\n  lemma fresh_map_transform[intro]: \"a \\<sharp> \\<Gamma> \\<Longrightarrow> a \\<sharp> map_transform trans ae \\<Gamma>\"\n    unfolding fresh_def using supp_map_transform by auto\n\n  lemma fresh_star_map_transform[intro]: \"a \\<sharp>* \\<Gamma> \\<Longrightarrow> a \\<sharp>* map_transform trans ae \\<Gamma>\"\n    by (auto simp add: fresh_star_def)\nend\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Call_Arity/TransformTools.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.531209388216861, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.2759746035997862}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\ntheory TraceMonadLemmas\nimports TraceMonadVCG\nbegin\n\nlemma mapM_Cons:\n  \"mapM f (x # xs) = do\n    y \\<leftarrow> f x;\n    ys \\<leftarrow> mapM f xs;\n    return (y # ys)\n  od\"\n  and mapM_Nil:\n  \"mapM f [] = return []\"\n  by (simp_all add: mapM_def sequence_def)\n\nlemma mapM_x_Cons:\n  \"mapM_x f (x # xs) = do\n    y \\<leftarrow> f x;\n    mapM_x f xs\n  od\"\n  and mapM_x_Nil:\n  \"mapM_x f [] = return ()\"\n  by (simp_all add: mapM_x_def sequence_x_def)\n\nlemma mapM_append:\n  \"mapM f (xs @ ys) = (do\n    fxs \\<leftarrow> mapM f xs;\n    fys \\<leftarrow> mapM f ys;\n    return (fxs @ fys)\n  od)\"\n  by (induct xs, simp_all add: mapM_Cons mapM_Nil bind_assoc)\n\nlemma mapM_x_append:\n  \"mapM_x f (xs @ ys) = (do\n    x \\<leftarrow> mapM_x f xs;\n    mapM_x f ys\n  od)\"\n  by (induct xs, simp_all add: mapM_x_Cons mapM_x_Nil bind_assoc)\n\nlemma mapM_map:\n  \"mapM f (map g xs) = mapM (f o g) xs\"\n  by (induct xs; simp add: mapM_Nil mapM_Cons)\n\nlemma mapM_x_map:\n  \"mapM_x f (map g xs) = mapM_x (f o g) xs\"\n  by (induct xs; simp add: mapM_x_Nil mapM_x_Cons)\n\nprimrec\n  repeat_n :: \"nat \\<Rightarrow> ('s, unit) tmonad \\<Rightarrow> ('s, unit) tmonad\"\nwhere\n    \"repeat_n 0 f = return ()\"\n  | \"repeat_n (Suc n) f = do f; repeat_n n f od\"\n\nlemma repeat_n_mapM_x:\n  \"repeat_n n f = mapM_x (\\<lambda>_. f) (replicate n ())\"\n  by (induct n, simp_all add: mapM_x_Cons mapM_x_Nil)\n\ndefinition\n  repeat :: \"('s, unit) tmonad \\<Rightarrow> ('s, unit) tmonad\"\nwhere\n  \"repeat f = do n \\<leftarrow> select UNIV; repeat_n n f od\"\n\ndefinition\n  env_step :: \"('s,unit) tmonad\"\nwhere\n  \"env_step =\n  (do\n    s' \\<leftarrow> select UNIV;\n    put_trace_elem (Env, s');\n    put s'\n  od)\"\n\nabbreviation\n  \"env_n_steps n \\<equiv> repeat_n n env_step\"\n\nlemma elem_select_bind:\n  \"(tr, res) \\<in> (do x \\<leftarrow> select S; f x od) s\n    = (\\<exists>x \\<in> S. (tr, res) \\<in> f x s)\"\n  by (simp add: bind_def select_def)\n\nlemma select_bind_UN:\n  \"(do x \\<leftarrow> select S; f x od) = (\\<lambda>s. \\<Union>x \\<in> S. f x s)\"\n  by (rule ext, auto simp: elem_select_bind)\n\nlemma select_early:\n  \"S \\<noteq> {}\n    \\<Longrightarrow> do x \\<leftarrow> f; y \\<leftarrow> select S; g x y od\n        = do y \\<leftarrow> select S; x \\<leftarrow> f; g x y od\"\n  apply (simp add: bind_def select_def Sigma_def)\n  apply (rule ext)\n  apply (fastforce elim: rev_bexI image_eqI[rotated] split: tmres.split_asm)\n  done\n\nlemma repeat_n_choice:\n  \"S \\<noteq> {}\n    \\<Longrightarrow> repeat_n n (do x \\<leftarrow> select S; f x od)\n        = (do xs \\<leftarrow> select {xs. set xs \\<subseteq> S \\<and> length xs = n}; mapM_x f xs od)\"\n  apply (induct n; simp?)\n   apply (simp add: select_def bind_def mapM_x_Nil cong: conj_cong)\n  apply (simp add: select_early bind_assoc)\n  apply (subst select_early)\n   apply simp\n   apply (auto intro: exI[where x=\"replicate n xs\" for n xs])[1]\n  apply (simp(no_asm) add: fun_eq_iff set_eq_iff elem_select_bind)\n  apply (simp only: conj_comms[where Q=\"length xs = n\" for xs n])\n  apply (simp only: ex_simps[symmetric] conj_assoc length_Suc_conv, simp)\n  apply (auto simp: mapM_x_Cons)\n  done\n\nlemma repeat_choice:\n  \"S \\<noteq> {}\n    \\<Longrightarrow> repeat (do x \\<leftarrow> select S; f x od)\n        = (do xs \\<leftarrow> select {xs. set xs \\<subseteq> S}; mapM_x f xs od)\"\n  apply (simp add: repeat_def repeat_n_choice)\n  apply (simp(no_asm) add: fun_eq_iff set_eq_iff elem_select_bind)\n  done\n\nlemma put_trace_append:\n  \"put_trace (xs @ ys) = do put_trace ys; put_trace xs od\"\n  by (induct xs; simp add: bind_assoc)\n\nlemma put_trace_elem_put_comm:\n  \"do y \\<leftarrow> put_trace_elem x; put s od\n    = do y \\<leftarrow> put s; put_trace_elem x od\"\n  by (simp add: put_def put_trace_elem_def bind_def insert_commute)\n\nlemma put_trace_put_comm:\n  \"do y \\<leftarrow> put_trace xs; put s od\n    = do y \\<leftarrow> put s; put_trace xs od\"\n  apply (rule sym; induct xs; simp)\n  apply (simp add: bind_assoc put_trace_elem_put_comm)\n  apply (simp add: bind_assoc[symmetric])\n  done\n\nlemma mapM_x_comm:\n  \"(\\<forall>x \\<in> set xs. do y \\<leftarrow> g; f x od = do y \\<leftarrow> f x; g od)\n    \\<Longrightarrow> do y \\<leftarrow> g; mapM_x f xs od = do y \\<leftarrow> mapM_x f xs; g od\"\n  apply (induct xs; simp add: mapM_x_Nil mapM_x_Cons)\n  apply (simp add: bind_assoc[symmetric], simp add: bind_assoc)\n  done\n\nlemma mapM_x_split:\n  \"(\\<forall>x \\<in> set xs. \\<forall>y \\<in> set xs. do z \\<leftarrow> g y; f x od = do (z :: unit) \\<leftarrow> f x; g y od)\n    \\<Longrightarrow> mapM_x (\\<lambda>x. do z \\<leftarrow> f x; g x od) xs = do y \\<leftarrow> mapM_x f xs; mapM_x g xs od\"\n  apply (induct xs; simp add: mapM_x_Nil mapM_x_Cons bind_assoc)\n  apply (subst bind_assoc[symmetric], subst mapM_x_comm[where f=f and g=\"g x\" for x])\n   apply simp\n  apply (simp add: bind_assoc)\n  done\n\nlemma mapM_x_put:\n  \"mapM_x put xs = unless (xs = []) (put (last xs))\"\n  apply (induct xs rule: rev_induct)\n   apply (simp add: mapM_x_Nil unless_def when_def)\n  apply (simp add: mapM_x_append mapM_x_Cons mapM_x_Nil)\n  apply (simp add: bind_def unless_def when_def put_def return_def)\n  done\n\nlemma put_trace_mapM_x:\n  \"put_trace xs = mapM_x put_trace_elem (rev xs)\"\n  by (induct xs; simp add: mapM_x_Nil mapM_x_append mapM_x_Cons)\n\nlemma rev_surj:\n  \"surj rev\"\n  by (rule_tac f=rev in surjI, simp)\n\nlemma select_image:\n  \"select (f ` S) = do x \\<leftarrow> select S; return (f x) od\"\n  by (auto simp add: bind_def select_def return_def Sigma_def)\n\nlemma env_steps_repeat:\n  \"env_steps = repeat env_step\"\n  apply (simp add: env_step_def repeat_choice env_steps_def\n                   select_early)\n  apply (simp add: put_trace_elem_put_comm)\n  apply (simp add: mapM_x_split put_trace_elem_put_comm put_trace_put_comm\n                   mapM_x_put)\n  apply (simp add: put_trace_mapM_x rev_map mapM_x_map o_def)\n  apply (subst rev_surj[symmetric], simp add: select_image bind_assoc)\n  apply (rule arg_cong2[where f=bind, OF refl ext])\n  apply (simp add: bind_def get_def put_def unless_def when_def return_def)\n  apply (simp add: last_st_tr_def hd_map hd_rev)\n  done\n\nlemma repeat_n_plus:\n  \"repeat_n (n + m) f = do repeat_n n f; repeat_n m f od\"\n  by (induct n; simp add: bind_assoc)\n\nlemma repeat_eq_twice[simp]:\n  \"(do x \\<leftarrow> repeat f; repeat f od) = repeat f\"\n  apply (simp add: repeat_def select_early)\n  apply (simp add: bind_assoc repeat_n_plus[symmetric, simplified])\n  apply (simp add: bind_def select_def Sigma_def)\n  apply (rule ext, fastforce intro: exI[where x=0])\n  done\n\nlemmas bind_then_eq = arg_cong2[where f=bind, OF _ refl]\nlemmas repeat_eq_twice_then[simp]\n    = repeat_eq_twice[THEN bind_then_eq, simplified bind_assoc]\n\nlemmas env_steps_eq_twice[simp]\n    = repeat_eq_twice[where f=env_step, folded env_steps_repeat]\nlemmas env_steps_eq_twice_then[simp]\n    = env_steps_eq_twice[THEN bind_then_eq, simplified bind_assoc]\n\nlemmas mapM_collapse_append = mapM_append[symmetric, THEN bind_then_eq,\n    simplified bind_assoc, simplified]\n\nlemma prefix_closed_mapM[rule_format, wp_split]:\n  \"(\\<forall>x \\<in> set xs. prefix_closed (f x)) \\<Longrightarrow> prefix_closed (mapM f xs)\"\n  apply (induct xs)\n   apply (simp add: mapM_def sequence_def)\n  apply (clarsimp simp: mapM_Cons)\n  apply (intro prefix_closed_bind allI; clarsimp)\n  done\n\nlemma modify_id:\n  \"modify id = return ()\"\n  by (simp add: modify_def get_def bind_def put_def return_def)\n\nlemma modify_modify:\n  \"(do x \\<leftarrow> modify f; modify (g x) od) = modify (g () o f)\"\n  by (simp add: bind_def simpler_modify_def)\n\nlemmas modify_modify_bind = arg_cong2[where f=bind,\n  OF modify_modify refl, simplified bind_assoc]\n\nlemma select_single:\n  \"select {x} = return x\"\n  by (simp add: select_def return_def)\n\nlemma put_then_get[unfolded K_bind_def]:\n  \"do put s; get od = do put s; return s od\"\n  by (simp add: put_def bind_def get_def return_def)\n\nlemmas put_then_get_then\n    = put_then_get[THEN bind_then_eq, simplified bind_assoc return_bind]\n\nlemmas bind_promote_If\n    = if_distrib[where f=\"\\<lambda>f. bind f g\" for g]\n      if_distrib[where f=\"\\<lambda>g. bind f g\" for f]\n\nlemma bind_promote_If2:\n  \"do x \\<leftarrow> f; if P then g x else h x od\n    = (if P then bind f g else bind f h)\"\n  by simp\n\nlemma exec_put_trace[unfolded K_bind_def]:\n  \"(do put_trace xs; f od) s\n    = (\\<Union>n \\<in> {n. 0 < n \\<and> n \\<le> length xs}. {(drop n xs, Incomplete)})\n        \\<union> ((\\<lambda>(a, b). (a @ xs, b)) ` f s)\"\n  apply (simp add: put_trace_eq_drop bind_def)\n  apply (safe; (clarsimp split: if_split_asm)?;\n      fastforce intro: bexI[where x=0] rev_bexI)\n  done\n\nlemma if_fun_lift:\n  \"(if P then f else g) x = (if P then f x else g x)\"\n  by simp\n\nlemma UN_If_distrib:\n  \"(\\<Union>x \\<in> S. if P x then A x else B x)\n    = ((\\<Union>x \\<in> S \\<inter> {x. P x}. A x) \\<union> (\\<Union>x \\<in> S \\<inter> {x. \\<not> P x}. B x))\"\n  by (fastforce split: if_split_asm)\n\nlemma Await_redef:\n  \"Await P = do\n    s1 \\<leftarrow> select {s. P s};\n    env_steps;\n    s \\<leftarrow> get;\n    select (if P s then {()} else {})\n  od\"\n  apply (simp add: Await_def env_steps_def bind_assoc)\n  apply (cases \"{s. P s} = {}\")\n   apply (simp add: select_def bind_def get_def)\n  apply (rule ext)\n  apply (simp add: exec_get select_bind_UN put_then_get_then)\n  apply (simp add: bind_promote_If2 if_fun_lift if_distrib[where f=select])\n  apply (simp add: exec_put_trace cong: if_cong)\n  apply (simp add: put_def bind_def select_def cong: if_cong)\n  apply (strengthen equalityI)\n  apply clarsimp\n  apply (strengthen exI[where x=\"s # xs\" for s xs])\n  apply (strengthen exI[where x=\"Suc n\" for n])\n  apply simp\n  apply blast\n  done\n\nlemma bind_apply_cong':\n  \"f s = f' s\n    \\<Longrightarrow> (\\<forall>rv s'. (rv, s') \\<in> mres (f s) \\<longrightarrow> g rv s' = g' rv s')\n    \\<Longrightarrow> bind f g s = bind f' g' s\"\n  apply (simp add: bind_def)\n  apply (rule SUP_cong; simp?)\n  apply (clarsimp split: tmres.split)\n  apply (drule spec2, drule mp, erule in_mres)\n  apply simp\n  done\n\nlemmas bind_apply_cong = bind_apply_cong'[rule_format]\n\nlemma select_empty_bind[simp]:\n  \"select {} >>= f = select {}\"\n  by (simp add: select_def bind_def)\n\nlemma fail_bind[simp]:\n  \"fail >>= f = fail\"\n  by (simp add: bind_def fail_def)\n\nlemma eq_Me_neq_Env:\n  \"(x = Me) = (x \\<noteq> Env)\"\n  by (cases x; simp)\n\nlemma validI_invariant_imp:\n  assumes v: \"\\<lbrace>P\\<rbrace>,\\<lbrace>R\\<rbrace> f \\<lbrace>G\\<rbrace>,\\<lbrace>Q\\<rbrace>\"\n    and P: \"\\<forall>s0 s. P s0 s \\<longrightarrow> I s0\"\n    and R: \"\\<forall>s0 s. I s0 \\<longrightarrow> R s0 s \\<longrightarrow> I s\"\n    and G: \"\\<forall>s0 s. I s0 \\<longrightarrow> G s0 s \\<longrightarrow> I s\"\n  shows \"\\<lbrace>P\\<rbrace>,\\<lbrace>R\\<rbrace> f \\<lbrace>\\<lambda>s0 s. I s0 \\<and> I s \\<and> G s0 s\\<rbrace>,\\<lbrace>\\<lambda>rv s0 s. I s0 \\<and> Q rv s0 s\\<rbrace>\"\nproof -\n  { fix tr s0 i\n  assume r: \"rely_cond R s0 tr\" and g: \"guar_cond G s0 tr\"\n    and I: \"I s0\"\n  hence imp: \"\\<forall>(_, s, s') \\<in> trace_steps (rev tr) s0. I s \\<longrightarrow> I s'\"\n    apply (clarsimp simp: guar_cond_def rely_cond_def)\n    apply (drule(1) bspec)+\n    apply (clarsimp simp: eq_Me_neq_Env)\n    apply (metis R G)\n    done\n  hence \"i < length tr \\<longrightarrow> I (snd (rev tr ! i))\"\n    using I\n    apply (induct i)\n     apply (clarsimp simp: neq_Nil_conv[where xs=\"rev tr\" for tr, simplified])\n    apply clarsimp\n    apply (drule bspec, fastforce simp add: trace_steps_nth)\n    apply simp\n    done\n  }\n  note I = this\n  show ?thesis\n    using v\n    apply (clarsimp simp: validI_def rely_def imp_conjL)\n    apply (drule spec2, drule(1) mp)+\n    apply clarsimp\n    apply (frule P[rule_format])\n    apply (clarsimp simp: guar_cond_def trace_steps_nth I last_st_tr_def\n                          hd_append last_rev[symmetric]\n                          last_conv_nth rev_map)\n    done\nqed\n\nlemma validI_guar_post_conj_lift:\n  \"\\<lbrace>P\\<rbrace>,\\<lbrace>R\\<rbrace> f \\<lbrace>G1\\<rbrace>,\\<lbrace>Q1\\<rbrace>\n    \\<Longrightarrow> \\<lbrace>P\\<rbrace>,\\<lbrace>R\\<rbrace> f \\<lbrace>G2\\<rbrace>,\\<lbrace>Q2\\<rbrace>\n    \\<Longrightarrow> \\<lbrace>P\\<rbrace>,\\<lbrace>R\\<rbrace> f \\<lbrace>\\<lambda>s0 s. G1 s0 s \\<and> G2 s0 s\\<rbrace>,\\<lbrace>\\<lambda>rv s0 s. Q1 rv s0 s \\<and> Q2 rv s0 s\\<rbrace>\"\n  apply (frule validI_prefix_closed)\n  apply (subst validI_def, clarsimp simp: rely_def)\n  apply (drule(3) validI_D)+\n  apply (auto simp: guar_cond_def)\n  done\n\nlemmas modify_prefix_closed[simp] =\n  modify_wp[THEN valid_validI_wp[OF no_trace_all(3)], THEN validI_prefix_closed]\nlemmas await_prefix_closed[simp] = Await_sync_twp[THEN validI_prefix_closed]\n\nlemma repeat_prefix_closed[intro!]:\n  \"prefix_closed f \\<Longrightarrow> prefix_closed (repeat f)\"\n  apply (simp add: repeat_def)\n  apply (rule prefix_closed_bind; clarsimp)\n  apply (rename_tac n)\n  apply (induct_tac n; simp)\n  apply (auto intro: prefix_closed_bind)\n  done\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/lib/Monads/TraceMonadLemmas.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5195213219520929, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.2759745958884768}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory MultByAdd\nimports\n  \"../../AutoCorres\"\nbegin\n\n(* Parse the input file. *)\ninstall_C_file \"mult_by_add.c\"\n\n(* Abstract the input file. *)\nautocorres [ ts_force nondet = mult_by_add ] \"mult_by_add.c\"\n\ncontext mult_by_add begin\n\n(*\n * Prove the function returns the correct result, and (simultaneously)\n * does not fail and terminates.\n *)\nlemma \"\\<lbrace> \\<lambda>s. True \\<rbrace> mult_by_add' a b \\<lbrace> \\<lambda>r s. r = a * b \\<rbrace>!\"\n  (* Unfold function definition. *)\n  apply (clarsimp simp: mult_by_add'_def)\n\n  (* Annotate while loop with an invariant and measure. *)\n  apply (subst whileLoop_add_inv\n    [where I=\"\\<lambda>(a', r) s. (a' * b) + r = (a * b)\"\n       and M=\"\\<lambda>((a', _), s). unat a'\"])\n\n  (* Run \"wp\" weakest precondition tactic, and solve verification *\n   * conditions generated by it. *)\n  apply wp\n     apply (simp add: field_simps)\n    apply unat_arith\n   apply (simp add: split_def word_neq_0_conv[symmetric])\n  apply (simp add: split_def | wp)+\n  done\n\n(*\n * Equivalent partial-correctness proof using Simpl framework.\n *)\nlemma \"\\<Gamma> \\<turnstile> {s. s = t} \\<acute>ret__unsigned :== CALL mult_by_add(\\<acute>a, \\<acute>b) \\<lbrace> (\\<acute>ret__unsigned = \\<^bsup>t\\<^esup>a * \\<^bsup>t\\<^esup>b) \\<rbrace>\"\n  (* Unfold the body. *)\n  apply vcg_step\n   defer\n\n   (* Annotate the while loop with an invariant and variant. *)\n   apply (subst whileAnno_def)\n   apply (subst whileAnno_def [symmetric,\n     where I=\" \\<lbrace> (\\<acute>a * \\<acute>b + \\<acute>result) = (\\<^bsup>t\\<^esup>a * \\<^bsup>t\\<^esup>b) \\<rbrace>\"\n     and V=\"measure (\\<lambda>s. unat (a_' s))\"])\n\n  (* Solve the remaining conditions. *)\n   apply vcg\n   apply (fastforce intro: unat_mono simp: gt0_iff_gem1 field_simps less_1_simp scast_id)+\n  done\n\nend\n\nend\n", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/autocorres/tests/examples/MultByAdd.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5312093585306514, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.27597458817716736}}
{"text": "(*  Title:      JinjaThreads/Basic/Set_without_equal.thy\n    Author:     Andreas Lochbihler\n*)\n\ntheory Set_without_equal\nimports Main\nbegin\n\ntext \\<open>\n  Adapt @{type \"set\"} code setup such that @{const \"insert\"}, \n  @{const \"union\"}, and @{term \"set_of_pred\"} do not generate\n  sort constraint @{class equal}.\n\\<close>\n\ndefinition insert' :: \"'a \\<Rightarrow> 'a set \\<Rightarrow> 'a set\"\nwhere \"insert' = Set.insert\"\n\ndefinition union' :: \"'a set \\<Rightarrow> 'a set \\<Rightarrow> 'a set\"\nwhere \"union' A B = sup A B\"\n\ndeclare\n  insert'_def [symmetric, code_unfold]\n  union'_def [symmetric, code_unfold]\n\nlemma insert'_code:\n  \"insert' x (set xs) = set (x # xs)\"\n  by (rule set_eqI) (simp add: insert'_def)\n\nlemma union'_code:\n  \"union' (set xs) (set ys) = set (xs @ ys)\"\n  by (rule set_eqI) (simp add: union'_def fun_eq_iff)\n\ndeclare\n  insert'_code [code]\n  union'_code [code]\n\ntext \\<open>Merge name spaces to avoid cyclic module dependencies\\<close>\n\ncode_identifier\n  code_module Set_without_equal \\<rightharpoonup>\n    (SML) Set and (Haskell) Set and (OCaml) Set\n\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/JinjaThreads/Basic/Set_without_equal.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.27590740667197156}}
{"text": "section \\<open>Correctness of Type Checker\\<close>\n\ntheory Wasm_Checker_Properties imports Wasm_Checker Wasm_Properties begin\n\nsubsection \\<open>Soundness\\<close>\n\nlemma b_e_check_single_type_sound:\n  assumes \"type_update (Type x1) (to_ct_list t_in) (Type t_out) = Type x2\"\n          \"c_types_agree (Type x2) tm\"\n          \"\\<C> \\<turnstile> [e] : (t_in _> t_out)\"\n  shows \"\\<exists>tn. c_types_agree (Type x1) tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\n  using assms(2) b_e_typing.intros(35)[OF assms(3)] type_update_type[OF assms(1)]\n  by auto\n\nlemma b_e_check_single_top_sound:\n  assumes \"type_update (TopType x1) (to_ct_list t_in) (Type t_out) = TopType x2\"\n          \"c_types_agree (TopType x2) tm\"\n          \"\\<C> \\<turnstile> [e] : (t_in _> t_out)\"\n  shows \"\\<exists>tn. c_types_agree (TopType x1) tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\nproof -\n  obtain t_ag where t_ag_def:\"ct_suffix (to_ct_list t_out) x2\"\n                             \"tm = t_ag @ t_out\"\n                             \"c_types_agree (TopType x1) (t_ag @ t_in)\"\n    using type_update_top_top[OF assms(1,2)]\n    by fastforce\n  hence \"\\<C> \\<turnstile> [e] : (t_ag@t_in _> t_ag@t_out)\"\n    using b_e_typing.intros(35)[OF assms(3)]\n    by fastforce\n  thus ?thesis\n    using t_ag_def\n    by fastforce\nqed\n\nlemma b_e_check_single_top_not_bot_sound:\n  assumes \"type_update ts (to_ct_list t_in) (TopType []) = ts'\"\n          \"ts \\<noteq> Bot\"\n          \"ts' \\<noteq> Bot\"\n  shows \"\\<exists>tn. c_types_agree ts tn \\<and> suffix t_in tn\"\nproof (cases ts)\n  case (TopType x1)\n  then obtain t_int where \"consume (TopType x1) (to_ct_list t_in) = t_int\" \"t_int \\<noteq> Bot\"\n    using assms(1,2,3)\n    by fastforce\n  thus ?thesis\n    using TopType ct_suffix_ct_list_eq_exists ct_suffix_ts_conv_suffix\n    unfolding consume.simps\n    by (metis append_Nil c_types_agree.simps(2) ct_suffix_def)\nnext\n  case (Type x2)\n  then obtain t_int where \"consume (Type x2) (to_ct_list t_in) = t_int\" \"t_int \\<noteq> Bot\"\n    using assms(1,2,3)\n    by fastforce\n  thus ?thesis\n    using c_types_agree_id Type consume_type suffixI ct_suffix_ts_conv_suffix\n    by fastforce\nnext\n  case Bot\n  thus ?thesis\n    using assms(2)\n    by simp\nqed\n\nlemma b_e_check_single_type_not_bot_sound:\n  assumes \"type_update ts (to_ct_list t_in) (Type t_out) = ts'\"\n          \"ts \\<noteq> Bot\"\n          \"ts' \\<noteq> Bot\"\n          \"c_types_agree ts' tm\"\n          \"\\<C> \\<turnstile> [e] : (t_in _> t_out)\"\n  shows \"\\<exists>tn. c_types_agree ts tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\n  using assms b_e_check_single_type_sound \nproof (cases ts)\n  case (TopType x1)\n  then obtain x1' where x_def:\"TopType x1' = ts'\"\n    using assms\n    by (simp, metis (full_types) produce.simps(1) produce.simps(6))\n  thus ?thesis\n    using assms b_e_check_single_top_sound TopType\n    by fastforce\nnext\n  case (Type x2)\n  then obtain x2' where x_def:\"Type x2' = ts'\"\n    using assms\n    by (simp, metis (full_types) produce.simps(2) produce.simps(6))\n  thus ?thesis\n    using assms b_e_check_single_type_sound Type\n    by fastforce\nnext\n  case Bot\n  thus ?thesis\n    using assms(2)\n    by simp\nqed\n\nlemma b_e_check_single_sound_unop_testop_cvtop:\n  assumes \"check_single \\<C> e tn' = tm'\"\n          \"((e = (Unop_i t uu) \\<or> e = (Testop t uv)) \\<and> is_int_t t)\n           \\<or> (e = (Unop_f t uw) \\<and> is_float_t t)\n           \\<or> (e = (Cvtop t1 Convert t sx) \\<and> convert_cond t1 t sx)\n           \\<or> (e = (Cvtop t1 Reinterpret t sx) \\<and> ((t1 \\<noteq> t) \\<and> t_length t1 = t_length t \\<and> sx = None))\"\n          \"c_types_agree tm' tm\"\n          \"tn' \\<noteq> Bot\"\n          \"tm' \\<noteq> Bot\"\n shows \"\\<exists>tn. c_types_agree tn' tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\nproof -\n  have \"(e = (Cvtop t1 Convert t sx) \\<Longrightarrow> convert_cond t1 t sx)\"\n    using assms(2)\n    by simp\n  hence temp0:\"(e = (Cvtop t1 Convert t sx)) \\<Longrightarrow> (type_update tn' [TSome t] (Type [arity_1_result e]) = tm')\"\n    using assms(1,5) arity_1_result_def\n    by (simp del: convert_cond.simps)\n  have temp1:\"(e = (Cvtop t1 Reinterpret t sx)) \\<Longrightarrow> (type_update tn' [TSome t] (Type [arity_1_result e]) = tm')\"\n    using assms(1,2,5) arity_1_result_def\n    by simp\n  have 1:\"type_update tn' (to_ct_list [t]) (Type [arity_1_result e]) = tm'\"\n    using assms arity_1_result_def\n    unfolding to_ct_list_def\n    apply (simp del: convert_cond.simps)\n    apply (metis (no_types, lifting) temp0 temp1 b_e.simps(978,979,982) check_single.simps(2) check_single.simps(3) check_single.simps(6) type_update.simps)\n    done\n  have \"\\<C> \\<turnstile> [e] : ([t] _> [arity_1_result e])\"\n    using assms(2) b_e_typing.intros(2,3,6,9,10)\n    unfolding arity_1_result_def\n    by fastforce\n  thus ?thesis\n    using b_e_check_single_type_not_bot_sound[OF 1 assms(4,5,3)]\n    by fastforce\nqed\n\nlemma b_e_check_single_sound_binop_relop:\n  assumes \"check_single \\<C> e tn' = tm'\"\n          \"((e = Binop_i t iop \\<and> is_int_t t)\n            \\<or> (e = Binop_f t fop \\<and> is_float_t t)\n            \\<or> (e = Relop_i t irop \\<and> is_int_t t)\n            \\<or> (e = Relop_f t frop \\<and> is_float_t t))\"\n          \"c_types_agree tm' tm\"\n          \"tn' \\<noteq> Bot\"\n          \"tm' \\<noteq> Bot\"\n shows \"\\<exists>tn. c_types_agree tn' tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\nproof -\n  have \"type_update tn' (to_ct_list [t,t]) (Type [arity_2_result e]) = tm'\"\n    using assms arity_2_result_def\n    unfolding to_ct_list_def\n    by auto\n  moreover\n  have \"\\<C> \\<turnstile> [e] : ([t,t] _> [arity_2_result e])\"\n    using assms(2) b_e_typing.intros(4,5,7,8)\n    unfolding arity_2_result_def\n    by fastforce\n  ultimately\n  show ?thesis\n    using b_e_check_single_type_not_bot_sound[OF _ assms(4,5,3)]\n    by fastforce\nqed\n\nlemma b_e_type_checker_sound:\n  assumes \"b_e_type_checker \\<C> es (tn _> tm)\"\n  shows \"\\<C> \\<turnstile> es : (tn _> tm)\"\nproof -\n  fix e tn'\n  have \"b_e_type_checker \\<C> es (tn _> tm) \\<Longrightarrow>\n          \\<C> \\<turnstile> es : (tn _> tm)\"\n  and \"\\<And>tm' tm.\n       check \\<C> es tn' = tm' \\<Longrightarrow>\n       c_types_agree tm' tm \\<Longrightarrow>\n         \\<exists>tn. c_types_agree tn' tn \\<and> \\<C> \\<turnstile> es : (tn _> tm)\"\n  and \"\\<And>tm' tm.\n       check_single \\<C> e tn' = tm' \\<Longrightarrow>\n       c_types_agree tm' tm \\<Longrightarrow>\n       tn' \\<noteq> Bot \\<Longrightarrow>\n       tm' \\<noteq> Bot \\<Longrightarrow>\n         \\<exists>tn. c_types_agree tn' tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\n  proof (induction rule: b_e_type_checker_check_check_single.induct)\n    case (1 \\<C> es tn' tm)\n    thus ?case\n      by simp\n  next\n    case (2 \\<C> es' ts)\n    show ?case\n    proof (cases es')\n      case Nil\n      thus ?thesis\n        using 2(5,6)\n        by (simp add: b_e_type_empty)\n    next\n      case (Cons e es)\n        thus ?thesis\n        proof (cases ts)\n        case (TopType x1)\n        have check_expand:\"check \\<C> es (check_single \\<C> e ts) = tm'\"\n          using 2(5,6) TopType Cons\n          by simp\n        obtain ts' where ts'_def:\"check_single \\<C> e ts = ts'\"\n          by blast\n        obtain t_int where t_int_def:\"\\<C> \\<turnstile> es : (t_int _> tm)\"\n                                     \"c_types_agree ts' t_int\"\n          using 2(2)[OF Cons TopType check_expand 2(6)] ts'_def\n          by blast\n        obtain t_int' where \"c_types_agree ts t_int'\" \"\\<C> \\<turnstile> [e] : (t_int' _> t_int)\"\n          using 2(1)[OF Cons _ ts'_def] TopType c_types_agree.simps(3) t_int_def(2)\n          by blast\n        thus ?thesis\n          using t_int_def(1) b_e_type_comp_conc Cons\n          by fastforce\n      next\n        case (Type x2)\n        have check_expand:\"check \\<C> es (check_single \\<C> e ts) = tm'\"\n          using 2(5,6) Type Cons\n          by simp\n        obtain ts' where ts'_def:\"check_single \\<C> e ts = ts'\"\n          by blast\n        obtain t_int where t_int_def:\"\\<C> \\<turnstile> es : (t_int _> tm)\"\n                                     \"c_types_agree ts' t_int\"\n          using 2(4)[OF Cons Type check_expand 2(6)] ts'_def\n          by blast\n        obtain t_int' where \"c_types_agree ts t_int'\" \"\\<C> \\<turnstile> [e] : (t_int' _> t_int)\"\n          using 2(3)[OF Cons _ ts'_def] Type c_types_agree.simps(3) t_int_def(2)\n          by blast\n        thus ?thesis\n          using t_int_def(1) b_e_type_comp_conc Cons\n          by fastforce\n      next\n        case Bot\n        then show ?thesis\n          using 2(5,6) Cons\n          by auto\n      qed\n    qed\n  next\n    case (3 \\<C> v ts)\n    hence \"type_update ts [] (Type [typeof v]) = tm'\"\n      by simp\n    moreover\n    have \"\\<C> \\<turnstile> [C v] : ([] _> [typeof v])\"\n      using b_e_typing.intros(1)\n      by blast\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 3(3,4,2)]\n      by (metis list.simps(8) to_ct_list_def)\n  next\n    case (4 \\<C> t uu ts)\n    hence \"is_int_t t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_unop_testop_cvtop 4\n      by fastforce\n  next\n    case (5 \\<C> t uv ts)\n    hence \"is_float_t t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_unop_testop_cvtop 5\n      by fastforce\n  next\n    case (6 \\<C> t uw ts)\n    hence \"is_int_t t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_binop_relop 6\n      by fastforce\n  next\n    case (7 \\<C> t ux ts)\n    hence \"is_float_t t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_binop_relop 7\n      by fastforce\n  next\n    case (8 \\<C> t uy ts)\n    hence \"is_int_t t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_unop_testop_cvtop 8\n      by fastforce\n  next\n    case (9 \\<C> t uz ts)\n    hence \"is_int_t t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_binop_relop 9\n      by fastforce\n  next\n    case (10 \\<C> t va ts)\n    hence \"is_float_t t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_binop_relop 10\n      by fastforce\n  next\n    case (11 \\<C> t1 t2 sx ts)\n    hence \"convert_cond t1 t2 sx\"\n      by (simp del: convert_cond.simps, meson)\n    thus ?case\n      using b_e_check_single_sound_unop_testop_cvtop 11\n      by fastforce\n  next\n    case (12 \\<C> t1 t2 sx ts)\n    hence \"t1 \\<noteq> t2 \\<and>  t_length t1 = t_length t2 \\<and> sx = None\"\n      by (simp, presburger)\n    thus ?case\n      using b_e_check_single_sound_unop_testop_cvtop 12\n      by fastforce\n  next\n    case (13 \\<C> ts)\n    thus ?case\n      using b_e_typing.intros(11) c_types_agree_not_bot_exists\n      by blast\n  next\n    case (14 \\<C> ts)\n    thus ?case\n      using b_e_typing.intros(12,35)\n      by fastforce\n  next\n    case (15 \\<C> ts)\n    thus ?case\n    proof (cases ts)\n      case (TopType x1)\n      thus ?thesis\n        proof (cases x1 rule: List.rev_cases)\n          case Nil\n          have \"\\<C> \\<turnstile> [Drop] : (tm@[T_i32] _> tm)\"\n            using b_e_typing.intros(13,35)\n            by fastforce\n          thus ?thesis\n            using c_types_agree_top1 Nil TopType\n            by fastforce\n        next\n          case (snoc ys y)\n            hence temp1:\"(consume (TopType (ys@[y])) [TAny]) = tm'\"\n              using 15 TopType type_update_empty\n              by (metis check_single.simps(13))\n            hence temp2:\"c_types_agree (TopType ys) tm\"\n              using consume_top_geq[OF temp1] 15(2,3,4)\n              by (metis Suc_leI add_diff_cancel_right' append_eq_conv_conj consume.simps(2)\n                        ct_suffix_def length_Cons length_append list.size(3) trans_le_add2\n                        zero_less_Suc)\n            obtain t where \"ct_list_eq [y] (to_ct_list [t])\"\n              using ct_list_eq_exists\n              unfolding ct_list_eq_def to_ct_list_def list_all2_map2\n              by (metis list_all2_Cons1 list_all2_Nil)\n            hence \"c_types_agree ts (tm@[t])\"\n              using temp2 ct_suffix_extend_ct_list_eq snoc TopType\n              by (simp add: to_ct_list_def)\n            thus ?thesis\n              using b_e_typing.intros(13,35)\n              by fastforce\n        qed\n    next\n      case (Type x2)\n      thus ?thesis\n      proof (cases x2 rule: List.rev_cases)\n        case Nil\n        hence \"(consume (Type []) [TAny]) = tm'\"\n          using 15 Type type_update_empty\n          by fastforce\n        thus ?thesis\n          using 15(4) ct_list_eq_def ct_suffix_def to_ct_list_def\n          by simp\n      next\n        case (snoc ys y)\n            hence temp1:\"(consume (Type (ys@[y])) [TAny]) = tm'\"\n              using 15 Type type_update_empty\n              by (metis check_single.simps(13))\n            hence temp2:\"c_types_agree (Type ys) tm\"\n              using 15(2,3,4) ct_suffix_def\n              by (simp, metis One_nat_def butlast_conv_take butlast_snoc c_types_agree.simps(1)\n                              length_Cons list.size(3))\n            obtain t where \"ct_list_eq [TSome y] (to_ct_list [t])\"\n              using ct_list_eq_exists\n              unfolding ct_list_eq_def to_ct_list_def list_all2_map2\n              by (metis list_all2_Cons1 list_all2_Nil)\n            hence \"c_types_agree ts (tm@[t])\"\n              using temp2 ct_suffix_extend_ct_list_eq snoc Type\n              by (simp add: ct_list_eq_def to_ct_list_def)\n            thus ?thesis\n              using b_e_typing.intros(13,35)\n              by fastforce\n      qed\n    qed simp\n  next\n    case (16 \\<C> ts)\n    thus ?case\n    proof (cases ts)\n      case (TopType x1)\n      consider\n          (1) \"length x1 = 0\"\n        | (2) \"length x1 = 1\"\n        | (3) \"length x1 = 2\"\n        | (4) \"length x1 \\<ge> 3\"\n        by linarith\n      thus ?thesis\n      proof (cases)\n        case 1\n        hence \"tm' = TopType [TAny]\"\n          using TopType 16\n          by simp\n        then obtain t'' tm'' where tm_def:\"tm = tm''@[t'']\"\n          using 16(2) ct_suffix_def\n          by (simp, metis Nil_is_append_conv append_butlast_last_id checker_type.inject(1)\n                          ct_prefixI ct_prefix_nil(2) produce.simps(1) produce_nil)\n        have \"\\<C> \\<turnstile> [Select] : ([t'',t'',T_i32] _> [t''])\"\n          using b_e_typing.intros(14)\n          by blast\n        thus ?thesis\n          using TopType 16 1 tm_def b_e_typing.intros(35) c_types_agree.simps(2) c_types_agree_top1\n          by fastforce\n      next\n        case 2\n        have \"type_update_select (TopType x1) = tm'\"\n          using 16 TopType\n          unfolding check_single.simps\n          by simp\n        hence x1_def:\"ct_list_eq x1 [TSome T_i32]\" \"tm' = TopType [TAny]\"\n          using type_update_select_length1[OF _ 2 16(4)]\n          by simp_all\n        then obtain t'' tm'' where tm_def:\"tm = tm''@[t'']\"\n          using 16(2) ct_suffix_def\n          by (metis Nil_is_append_conv append_butlast_last_id c_types_agree.simps(2) ct_prefixI\n                    ct_prefix_nil(2) list.simps(8) to_ct_list_def)\n        have \"c_types_agree (TopType x1) ((tm''@[t'',t''])@[T_i32])\"\n          using x1_def(1)\n          by (metis c_types_agree_top2 list.simps(8,9) to_ct_list_def)\n        thus ?thesis\n          using TopType b_e_typing.intros(14,35) tm_def\n          by auto\n      next\n        case 3\n        have \"type_update_select (TopType x1) = tm'\"\n          using 16 TopType\n          unfolding check_single.simps\n          by simp\n        then obtain ct1 ct2 where x1_def:\"x1 = [ct1, ct2]\"\n                                         \"ct_eq ct2 (TSome T_i32)\"\n                                         \"tm' = TopType [ct1]\"\n          using type_update_select_length2[OF _ 3 16(4)]\n          by blast\n        then obtain t'' tm'' where tm_def:\"tm = tm''@[t'']\"\n                                          \"ct_list_eq [ct1] [(TSome t'')]\"\n          using 16(2) c_types_agree_imp_ct_list_eq[of \"[ct1]\" tm]\n          by (metis append_Nil2 append_butlast_last_id append_eq_append_conv_if append_eq_conv_conj\n                    ct_list_eq_length diff_Suc_1 length_Cons length_butlast length_map\n                    list.simps(8,9) list.size(3) nat.distinct(2) to_ct_list_def)\n        hence \"ct_list_eq x1 (to_ct_list [ t'', T_i32])\"\n          using x1_def(1,2)\n          unfolding ct_list_eq_def to_ct_list_def\n          by fastforce\n        hence \"c_types_agree (TopType x1) ((tm''@[t''])@[t'',T_i32])\"\n          using c_types_agree_top2\n          by blast\n        thus ?thesis\n          using TopType b_e_typing.intros(14,35) tm_def\n          by auto\n      next\n        case 4\n        then obtain nat where nat_def:\"length x1 = Suc (Suc (Suc nat))\"\n          by (metis add_eq_if diff_Suc_1 le_Suc_ex numeral_3_eq_3 nat.distinct(2))\n        hence tm'_def:\"type_update_select (TopType x1) = tm'\"\n          using 16 TopType\n          by simp\n        then obtain tm_int where \"(select_return_top x1\n                                    (x1 ! (length x1 - 2))\n                                    (x1 ! (length x1 - 3))) = tm_int\"\n                                 \"tm_int \\<noteq> Bot\"\n          using nat_def 16(4)\n          unfolding type_update_select.simps\n          by fastforce\n        then obtain x2 where x2_def:\"(select_return_top x1\n                                       (x1 ! (length x1 - 2))\n                                       (x1 ! (length x1 - 3))) = TopType x2\"\n          using select_return_top_exists\n          by fastforce\n        have \"ct_suffix x1 [TAny, TAny, TSome T_i32] \\<or> ct_suffix [TAny, TAny, TSome T_i32] x1\"\n          using tm'_def nat_def 16(4)\n          by (simp, metis (full_types) produce.simps(6))\n        hence tm'_eq:\"tm' = TopType x2\"\n          using tm'_def nat_def 16(4) x2_def\n          by force\n        then obtain cts' ct1 ct2 ct3 where cts'_def:\"x1 = cts'@[ct1, ct2, ct3]\"\n                                                    \"ct_eq ct3 (TSome T_i32)\"\n          using type_update_select_length3 tm'_def 4\n          by blast\n        then obtain c' cm' where tm_def:\"tm = cm'@[c']\"\n                                        \"ct_suffix cts' (to_ct_list cm')\"\n                                        \"ct_eq (x1 ! (length x1 - 2)) (TSome c')\"\n                                        \"ct_eq (x1 ! (length x1 - 3)) (TSome c')\"\n          using select_return_top_ct_eq[OF x2_def 4] tm'_eq 4 16(2)\n          by fastforce\n        then obtain as bs where cm'_def:\"cm' = as@bs\"\n                                        \"ct_list_eq (to_ct_list bs) cts'\"\n          using ct_list_eq_cons_ct_list1 ct_list_eq_ts_conv_eq\n          by (metis ct_suffix_def to_ct_list_append(2))\n        hence \"ct_eq ct1 (TSome c')\"\n              \"ct_eq ct2 (TSome c')\"\n          using cts'_def tm_def\n          apply simp_all\n          apply (metis append.assoc append_Cons append_Nil length_append_singleton nth_append_length)\n          done\n        hence \"c_types_agree ts (cm'@[c',c',T_i32])\"\n          using c_types_agree_top2[of _ _ as] cm'_def(1) TopType\n                ct_list_eq_concat[OF ct_list_eq_commute[OF cm'_def(2)]] cts'_def\n          unfolding to_ct_list_def ct_list_eq_def\n          by fastforce\n        thus ?thesis\n          using b_e_typing.intros(14,35) tm_def\n          by auto\n      qed\n    next\n      (* TODO: refactor *)\n      case (Type x2)\n      hence x2_cond:\"(length x2 \\<ge> 3 \\<and> (x2!(length x2-2)) = (x2!(length x2-3)))\"\n        using 16\n        by (simp, meson)\n      hence tm'_def:\"consume (Type x2) [TAny, TSome T_i32] = tm'\"\n        using 16 Type\n        by simp\n      obtain ts' ts'' where cts_def:\"x2 = ts'@ ts''\" \"length ts'' = 3\"\n        using x2_cond\n        by (metis append_take_drop_id diff_diff_cancel length_drop)\n      then obtain t1 ts''2 where \"ts'' = t1#ts''2\" \"length ts''2 = Suc (Suc 0)\"\n        using List.length_Suc_conv[of ts' \"Suc (Suc 0)\"]\n        by (metis length_Suc_conv numeral_3_eq_3)\n      then obtain t2 t3 where \"ts'' = [t1,t2,t3]\"\n        using List.length_Suc_conv[of ts''2 \"Suc 0\"]\n        by (metis length_0_conv length_Suc_conv)\n      hence cts_def2:\"x2 = ts'@ [t1,t2,t3]\"\n        using cts_def\n        by simp\n      have ts'_suffix:\"ct_suffix [TAny, TSome T_i32] (to_ct_list (ts' @ [t1, t2, t3]))\"\n        using tm'_def 16(4)\n        by (simp, metis cts_def2)\n      hence tm'_def:\"tm' = Type (ts'@[t1])\"\n        using tm'_def 16(4) cts_def2\n        by simp\n      obtain as bs where \"(to_ct_list (ts' @ [t1])) @ (to_ct_list ([t2, t3])) = as@bs\"\n                         \"ct_list_eq bs [TAny, TSome T_i32]\"\n        using ts'_suffix\n        unfolding ct_suffix_def to_ct_list_def\n        by fastforce\n      hence \"t3 = T_i32\"\n        unfolding to_ct_list_def ct_list_eq_def\n        by (metis (no_types, lifting) Nil_is_map_conv append_eq_append_conv ct_eq.simps(1)\n                  length_Cons list.sel(1,3) list.simps(9) list_all2_Cons2 list_all2_lengthD)\n      moreover\n      have \"t1 = t2\"\n        using x2_cond cts_def2\n        by (simp, metis append.left_neutral append_Cons append_assoc length_append_singleton\n                        nth_append_length)\n      ultimately\n      have \"c_types_agree (Type x2) ((ts'@[t1,t1])@[T_i32])\"\n        using cts_def2\n        by simp\n      thus ?thesis\n        using b_e_typing.intros(14,35) Type tm'_def 16(2)\n        by fastforce\n    qed simp\n  next\n    case (17 \\<C> tn'' tm'' es ts)\n    hence \"type_update ts (to_ct_list tn'') (Type tm'') = tm'\"\n      by auto\n    moreover\n    have \"(b_e_type_checker (\\<C>\\<lparr>label := ([tm''] @ (label \\<C>))\\<rparr>) es (tn'' _> tm''))\"\n      using 17\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Block (tn'' _> tm'') es] : (tn'' _> tm'')\"\n      using b_e_typing.intros(15)[OF _ 17(1)]\n      by blast\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 17(4,5,3)]\n      by blast\n  next\n    case (18 \\<C> tn'' tm'' es ts)\n    hence \"type_update ts (to_ct_list tn'') (Type tm'') = tm'\"\n      by auto\n    moreover\n    have \"(b_e_type_checker (\\<C>\\<lparr>label := ([tn''] @ (label \\<C>))\\<rparr>) es (tn'' _> tm''))\"\n      using 18\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Loop (tn'' _> tm'') es] : (tn'' _> tm'')\"\n      using b_e_typing.intros(16)[OF _ 18(1)]\n      by blast\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 18(4,5,3)]\n      by blast\n  next\n    case (19 \\<C> tn'' tm'' es1 es2 ts)\n    hence \"type_update ts (to_ct_list (tn''@[T_i32])) (Type tm'') = tm'\"\n      by auto\n    moreover\n    have \"(b_e_type_checker (\\<C>\\<lparr>label := ([tm''] @ (label \\<C>))\\<rparr>) es1 (tn'' _> tm''))\"\n         \"(b_e_type_checker (\\<C>\\<lparr>label := ([tm''] @ (label \\<C>))\\<rparr>) es2 (tn'' _> tm''))\"\n      using 19\n      by (simp, meson)+\n    hence \"\\<C> \\<turnstile> [If (tn'' _> tm'') es1 es2] : (tn''@[T_i32] _> tm'')\"\n      using b_e_typing.intros(17)[OF _ 19(1,2)]\n      by blast\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 19(5,6,4)]\n      by blast\n  next\n    case (20 \\<C> i ts)\n    hence \"type_update ts (to_ct_list ((label \\<C>)!i)) (TopType []) = tm'\"\n      by auto\n    moreover\n    have \"i < length (label \\<C>)\"\n      using 20\n      by (simp, meson)\n    ultimately\n    show ?case\n      using b_e_check_single_top_not_bot_sound[OF _ 20(3,4)]\n            b_e_typing.intros(18)\n            b_e_typing.intros(35)\n      by (metis suffix_def)\n  next\n    case (21 \\<C> i ts)\n    hence \"type_update ts (to_ct_list ((label \\<C>)!i @ [T_i32])) (Type ((label \\<C>)!i)) = tm'\"\n      by auto\n    moreover\n    have \"i < length (label \\<C>)\"\n      using 21\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Br_if i] : ((label \\<C>)!i @ [T_i32] _> (label \\<C>)!i)\"\n      using b_e_typing.intros(19)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 21(3,4,2)]\n      by fastforce\n  next\n    case (22 \\<C> \"is\" i ts)\n    then obtain tls where tls_def:\"(same_lab (is@[i]) (label \\<C>)) = Some tls\"\n      by fastforce\n    hence \"type_update ts (to_ct_list (tls @ [T_i32])) (TopType []) = tm'\"\n      using 22\n      by simp\n    thus ?case\n      using b_e_check_single_top_not_bot_sound[OF _ 22(3,4)]\n            b_e_typing.intros(20)[OF same_lab_conv_list_all[OF tls_def]]\n            b_e_typing.intros(35)\n      by (metis suffix_def)\n  next\n    case (23 \\<C> ts)\n    then obtain ts_r where \"(return \\<C>) = Some ts_r\"\n      by fastforce\n    moreover\n    hence \"type_update ts (to_ct_list ts_r) (TopType []) = tm'\"\n      using 23\n      by simp\n    ultimately\n    show ?case\n      using b_e_check_single_top_not_bot_sound[OF _ 23(3,4)]\n            b_e_typing.intros(21,35)\n      by (metis suffix_def)\n  next\n    case (24 \\<C> i ts)\n    obtain tn'' tm'' where func_def:\"(func_t \\<C>)!i = (tn'' _> tm'')\"\n      using tf.exhaust\n      by blast\n    hence \"type_update ts (to_ct_list tn'') (Type tm'') = tm'\"\n      using 24\n      by auto\n    moreover\n    have \"i < length (func_t \\<C>)\"\n      using 24\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Call i] : (tn'' _> tm'')\"\n      using b_e_typing.intros(22) func_def\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 24(3,4,2)]\n      by fastforce\n  next\n    case (25 \\<C> i ts)\n    obtain tn'' tm'' where type_def:\"(types_t \\<C>)!i = (tn'' _> tm'')\"\n      using tf.exhaust\n      by blast\n    hence \"type_update ts (to_ct_list (tn''@[T_i32])) (Type tm'') = tm'\"\n      using 25\n      by auto\n    moreover\n    have \"(table \\<C>) \\<noteq> None \\<and> i < length (types_t \\<C>)\"\n      using 25\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Call_indirect i] : (tn''@[T_i32] _> tm'')\"\n      using b_e_typing.intros(23) type_def\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 25(3,4,2)]\n      by fastforce\n  next\n    case (26 \\<C> i ts)\n    hence \"type_update ts [] (Type [(local \\<C>)!i]) = tm'\"\n      by auto\n    moreover\n    have \"i < length (local \\<C>)\"\n      using 26\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Get_local i] : ([] _> [(local \\<C>)!i])\"\n      using b_e_typing.intros(24)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 26(3,4,2)]\n      unfolding to_ct_list_def\n      by (metis list.map_disc_iff)\n  next\n    case (27 \\<C> i ts)\n    hence \"type_update ts (to_ct_list [(local \\<C>)!i]) (Type []) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"i < length (local \\<C>)\"\n      using 27\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Set_local i] : ([(local \\<C>)!i] _> [])\"\n      using b_e_typing.intros(25)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 27(3,4,2)]\n      by fastforce\n  next\n    case (28 \\<C> i ts)\n    hence \"type_update ts (to_ct_list [(local \\<C>)!i]) (Type [(local \\<C>)!i]) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"i < length (local \\<C>)\"\n      using 28\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Tee_local i] : ([(local \\<C>)!i] _> [(local \\<C>)!i])\"\n      using b_e_typing.intros(26)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 28(3,4,2)]\n      by fastforce\n  next\n    case (29 \\<C> i ts)\n    hence \"type_update ts [] (Type [tg_t ((global \\<C>)!i)]) = tm'\"\n      by auto\n    moreover\n    have \"i < length (global \\<C>)\"\n      using 29\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Get_global i] : ([] _> [tg_t ((global \\<C>)!i)])\"\n      using b_e_typing.intros(27)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 29(3,4,2)]\n      unfolding to_ct_list_def\n      by (metis list.map_disc_iff)\n  next\n    case (30 \\<C> i ts)\n    hence \"type_update ts (to_ct_list [tg_t ((global \\<C>)!i)]) (Type []) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"i < length (global \\<C>) \\<and> is_mut (global \\<C> ! i)\"\n      using 30\n      by (simp, meson)\n    then obtain t where \"(global \\<C> ! i) = \\<lparr>tg_mut = T_mut, tg_t = t\\<rparr>\" \"i < length (global \\<C>)\"\n      unfolding is_mut_def\n      by (cases \"global \\<C> ! i\", auto)\n    hence \"\\<C> \\<turnstile> [Set_global i] : ([tg_t (global \\<C> ! i)] _> [])\"\n      using b_e_typing.intros(28)[of i \\<C> \"tg_t (global \\<C> ! i)\"]\n      unfolding is_mut_def tg_t_def\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 30(3,4,2)]\n      by fastforce\n  next\n    case (31 \\<C> t tp_sx a off ts)\n    hence \"type_update ts (to_ct_list [T_i32]) (Type [t]) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"(memory \\<C>) \\<noteq> None \\<and> load_store_t_bounds a (option_projl tp_sx) t\"\n      using 31\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Load t tp_sx a off] : ([T_i32] _> [t])\"\n      using b_e_typing.intros(29)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 31(3,4,2)]\n      by fastforce\n  next\n    case (32 \\<C> t tp a off ts)\n    hence \"type_update ts (to_ct_list [T_i32,t]) (Type []) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"(memory \\<C>) \\<noteq> None \\<and> load_store_t_bounds a tp t\"\n      using 32\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Store t tp a off] : ([T_i32,t] _> [])\"\n      using b_e_typing.intros(30)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 32(3,4,2)]\n      by fastforce\n  next\n    case (33 \\<C> ts)\n    hence \"type_update ts [] (Type [T_i32]) = tm'\"\n      by auto\n    moreover\n    have \"memory \\<C> \\<noteq> None\" \n      using 33\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Current_memory] : ([] _> [T_i32])\"\n      using b_e_typing.intros(31)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 33(3,4,2)]\n      unfolding to_ct_list_def\n      by (metis list.map_disc_iff)\n  next\n    case (34 \\<C> ts)\n    hence \"type_update ts (to_ct_list [T_i32]) (Type [T_i32]) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"memory \\<C> \\<noteq> None\" \n      using 34\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Grow_memory] : ([T_i32] _> [T_i32])\"\n      using b_e_typing.intros(32)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 34(3,4,2)]\n      by fastforce\n  qed\n  thus ?thesis\n    using assms\n    by simp\nqed\n\nsubsection \\<open>Completeness\\<close>\n\nlemma check_single_imp:\n  assumes \"check_single \\<C> e ctn = ctm\"\n          \"ctm \\<noteq> Bot\"\n  shows \"check_single \\<C> e = id\n         \\<or> check_single \\<C> e = (\\<lambda>ctn. type_update_select ctn)\n         \\<or> (\\<exists>cons prods. (check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)))\"\nproof -\n  have True\n  and True\n  and \"check_single \\<C> e ctn = ctm \\<Longrightarrow>\n       ctm \\<noteq> Bot \\<Longrightarrow>\n         ?thesis\"\n  proof (induction rule: b_e_type_checker_check_check_single.induct)\n    case (1 \\<C> es tn tm)\n    thus ?case\n      by simp\n  next\n    case (2 \\<C> es ts)\n    thus ?case\n      by simp\n  next\n    case (3 \\<C> v ts)\n    thus ?case\n      by fastforce\n  next\n    case (4 \\<C> t uu ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (5 \\<C> t uv ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (6 \\<C> t uw ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (7 \\<C> t ux ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (8 \\<C> t uy ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (9 \\<C> t uz ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (10 \\<C> t va ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (11 \\<C> t1 t2 sx ts)\n    thus ?case\n      by (simp del: convert_cond.simps, meson assms(2) type_update.simps)\n  next\n    case (12 \\<C> t1 t2 sx ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (13 \\<C> ts)\n    thus ?case\n      by fastforce\n  next\n    case (14 \\<C> ts)\n    thus ?case\n      by fastforce\n  next\n    case (15 \\<C> ts)\n    thus ?case\n      by fastforce\n  next\n    case (16 \\<C> ts)\n    thus ?case\n      by fastforce\n  next\n    case (17 \\<C> tn tm es ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (18 \\<C> tn tm es ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (19 \\<C> tn tm es1 es2 ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (20 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (21 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (22 \\<C> \"is\" ts)\n    thus ?case\n      by (simp, metis assms(2) option.case_eq_if type_update.simps)\n  next\n    case (23 \\<C> ts)\n    thus ?case\n      by (simp, metis assms(2) option.case_eq_if type_update.simps)\n  next\n    case (24 \\<C> i ts)\n    then show ?case\n      by (simp, metis (no_types, lifting) assms(2) tf.case tf.exhaust type_update.simps)\n  next\n    case (25 \\<C> i ts)\n    thus ?case\n      by (simp, metis (no_types, lifting) assms(2) tf.case tf.exhaust type_update.simps)\n  next\n    case (26 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (27 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (28 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (29 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (30 \\<C> i ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (31 \\<C> t tp_sx a off ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (32 \\<C> t tp a off ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (33 \\<C> ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  next\n    case (34 \\<C> ts)\n    thus ?case\n      by (simp, meson assms(2) type_update.simps)\n  qed\n  thus ?thesis\n    using assms\n    by simp\nqed\n\nlemma check_equiv_fold:\n  \"check \\<C> es ts = foldl (\\<lambda> ts e. (case ts of Bot \\<Rightarrow> Bot | _ \\<Rightarrow> check_single \\<C> e ts)) ts es\"\nproof (induction es arbitrary: ts)\n  case Nil\n  thus ?case\n    by simp\nnext\n  case (Cons e es)\n  obtain ts' where ts'_def:\"check \\<C> (e # es) ts = ts'\"\n    by blast\n  show ?case\n  proof (cases \"ts = Bot\")\n    case True\n    thus ?thesis\n      using ts'_def\n      by (induction es, simp_all)\n  next\n    case False\n    thus ?thesis\n      using ts'_def Cons\n      by (cases ts, simp_all)\n  qed\nqed\n\nlemma check_neq_bot_snoc:\n  assumes \"check \\<C> (es@[e]) ts \\<noteq> Bot\"\n  shows \"check \\<C> es ts \\<noteq> Bot\"\n  using assms\nproof (induction es arbitrary: ts)\n  case Nil\n  thus ?case\n    by (cases ts, simp_all)\nnext\n  case (Cons a es)\n  thus ?case\n    by (cases ts, simp_all)\nqed\n\nlemma check_unfold_snoc:\n  assumes \"check \\<C> es ts \\<noteq> Bot\"\n  shows \"check \\<C> (es@[e]) ts = check_single \\<C> e (check \\<C> es ts)\"\nproof -\n  obtain f where f_def:\"f = (\\<lambda> e ts. (case ts of Bot \\<Rightarrow> Bot | _ \\<Rightarrow> check_single \\<C> e ts))\"\n    by blast\n  have f_simp:\"\\<And>ts. ts \\<noteq> Bot \\<Longrightarrow> (f e ts = check_single \\<C> e ts)\"\n  proof -\n    fix ts\n    show \"ts \\<noteq> Bot \\<Longrightarrow> (f e ts = check_single \\<C> e ts)\"\n      using f_def\n      by (cases ts, simp_all)\n  qed\n  have \"check \\<C> (es@[e]) ts = foldl (\\<lambda> ts e. (case ts of Bot \\<Rightarrow> Bot | _ \\<Rightarrow> check_single \\<C> e ts)) ts (es@[e])\"\n    using check_equiv_fold\n    by simp\n  also\n  have \"... = foldr (\\<lambda> e ts. (case ts of Bot \\<Rightarrow> Bot | _ \\<Rightarrow> check_single \\<C> e ts)) (rev (es@[e])) ts\"\n    using foldl_conv_foldr\n    by fastforce\n  also\n  have \"... = f e (foldr (\\<lambda> e ts. (case ts of Bot \\<Rightarrow> Bot | _ \\<Rightarrow> check_single \\<C> e ts)) (rev es) ts)\"\n    using f_def\n    by simp\n  also\n  have \"... = f e (check \\<C> es ts)\"\n    using foldr_conv_foldl[of _ \"(rev es)\" ts] rev_rev_ident[of es] check_equiv_fold\n    by simp\n  also\n  have \"... = check_single \\<C> e (check \\<C> es ts)\"\n    using assms f_simp\n    by simp\n  finally\n  show ?thesis .\nqed\n\nlemma check_single_imp_weakening:\n  assumes \"check_single \\<C> e (Type t1s) = ctm\"\n          \"ctm \\<noteq> Bot\"\n          \"c_types_agree ctn t1s\"\n          \"c_types_agree ctm t2s\"\n  shows \"\\<exists>ctm'. check_single \\<C> e ctn = ctm' \\<and> c_types_agree ctm' t2s\"\nproof -\n  consider (1) \"check_single \\<C> e = id\" \n         | (2) \"check_single \\<C> e = (\\<lambda>ctn. type_update_select ctn)\"\n         | (3) \"(\\<exists>cons prods. (check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)))\"\n    using check_single_imp assms\n    by blast\n  thus ?thesis\n  proof (cases)\n    case 1\n    thus ?thesis\n      using assms(1,3,4)\n      by fastforce\n  next\n    (* TODO: better proof *)\n    case 2\n    note outer_2 = 2\n    hence t1s_cond:\"(length t1s \\<ge> 3 \\<and> (t1s!(length t1s-2)) = (t1s!(length t1s-3)))\"\n      using assms(1,2)\n      by (simp, meson)\n    hence ctm_def:\"ctm = consume (Type t1s) [TAny, TSome T_i32]\"\n      using assms(1,2) 2\n      by simp\n    then obtain c_t where c_t_def:\"ctm = Type c_t\"\n      using assms(2)\n      by (meson consume.simps(1))\n    hence t2s_eq:\"t2s = c_t\"\n      using assms(4)\n      by simp\n    hence t2s_len:\"length t2s > 0\"\n      using t1s_cond ctm_def c_t_def assms(2)\n      by (metis Suc_leI Suc_n_not_le_n checker_type.inject(2) consume.simps(1)\n                diff_is_0_eq dual_order.trans length_0_conv length_Cons length_greater_0_conv\n                nat.simps(3) numeral_3_eq_3 take_eq_Nil)\n    have t1s_suffix_full:\"ct_suffix [TAny, TSome T_i32] (to_ct_list t1s)\"\n      using assms(2) ctm_def ct_suffix_less\n      by (metis consume.simps(1))\n    hence t1s_suffix:\"ct_suffix [TSome T_i32] (to_ct_list t1s)\"\n      using assms(2) ctm_def ct_suffix_less\n      by (metis append_butlast_last_id last.simps list.distinct(1))\n    obtain t t1s' where t1s_suffix2:\"t1s = t1s'@[t,t,T_i32]\"\n      using type_update_select_type_length3 assms(1) c_t_def outer_2\n      by fastforce\n    hence t2s_def:\"t2s = t1s'@[t]\"\n      using ctm_def c_t_def t2s_eq t1s_suffix assms(2) t1s_suffix_full\n      by simp\n    show ?thesis\n      using assms(1,3,4)\n    proof (cases ctn)\n      case (TopType x1)\n      consider\n          (1) \"length x1 = 0\"\n        | (2) \"length x1 = 1\"\n        | (3) \"length x1 = 2\"\n        | (4) \"length x1 \\<ge> 3\"\n        by linarith\n      thus ?thesis\n      proof (cases)\n        case 1\n        hence \"check_single \\<C> e ctn = TopType [TAny]\"\n          using 2 TopType\n          by simp\n        thus ?thesis\n          using ct_suffix_singleton to_ct_list_def t2s_len\n          by auto\n      next\n        case 2\n        hence \"ct_suffix [TSome T_i32] x1\"\n          using assms(3) TopType ct_suffix_imp_ct_list_eq ct_suffix_shared t1s_suffix\n          by (metis One_nat_def append_Nil c_types_agree.simps(2) ct_list_eq_commute ct_suffix_def\n                    diff_self_eq_0 drop_0 length_Cons list.size(3))\n        hence \"check_single \\<C> e ctn = TopType [TAny]\"\n          using outer_2 TopType 2\n          by simp\n        thus ?thesis\n          using t2s_len ct_suffix_singleton\n          by (simp add: to_ct_list_def)\n      next\n        case 3\n        have \"ct_list_eq (to_ct_list t1s) (to_ct_list (t1s' @ [t, t, T_i32]))\"\n          using t1s_suffix2\n          by (simp add: ct_list_eq_ts_conv_eq)\n        hence temp1:\"to_ct_list t1s = (to_ct_list (t1s' @ [t])) @ (to_ct_list [t, T_i32])\"\n          using t1s_suffix2 to_ct_list_def\n          by simp\n        hence \"ct_suffix (to_ct_list [t, T_i32]) (to_ct_list t1s)\"\n          using ct_suffix_def[of \"(to_ct_list [t, T_i32])\" \"(to_ct_list t1s)\"]\n          by (simp add: ct_suffix_cons_it)\n        hence \"ct_suffix (to_ct_list [t, T_i32]) x1\"\n          using assms(3) TopType 3\n          by (simp, metis temp1 append_Nil ct_suffix_cons2 ct_suffix_def length_Cons length_map\n                          list.size(3) numeral_2_eq_2 to_ct_list_def)\n        hence temp3:\"ct_list_eq (to_ct_list [t, T_i32]) x1\"\n          using 3 ct_suffix_imp_ct_list_eq\n          unfolding to_ct_list_def\n          by (metis Suc_leI ct_list_eq_commute diff_is_0_eq drop_0 length_Cons length_map lessI\n                    list.size(3) numeral_2_eq_2)\n        hence temp4:\"ct_suffix [TSome T_i32] x1\" \n          using ct_suffix_less[of \"[TSome t]\" \"[TSome T_i32]\" x1]\n                ct_suffix_extend_ct_list_eq[of \"[]\" \"[]\"] ct_suffix_nil\n          unfolding to_ct_list_def\n          by fastforce\n        hence \"ct_suffix (take 1 x1) (to_ct_list [t])\"\n          using temp3 ct_suffix_nil ct_list_eq_commute ct_suffix_extend_ct_list_eq[of \"[]\" \"[]\" \"(take 1 x1)\" \"(to_ct_list [t])\"]\n          unfolding to_ct_list_def\n          by (simp, metis butlast.simps(2) butlast_conv_take ct_list_eq_take diff_Suc_1 length_Cons\n                          list.distinct(1) list.size(3))\n        thus ?thesis\n          using TopType 2 3 ct_suffix_nil temp3 temp4 t2s_def to_ct_list_def\n          apply (simp, safe)\n          apply (metis append.assoc ct_suffix_def)\n          done\n      next\n        case 4\n        then obtain nat where nat_def:\"length x1 = Suc (Suc (Suc nat))\"\n          by (metis add_eq_if diff_Suc_1 le_Suc_ex numeral_3_eq_3 nat.distinct(2))\n        obtain x1' x x' x'' where x1_split:\"x1 = x1'@[x,x',x'']\"\n        proof -\n          assume local_assms:\"(\\<And>x1' x x' x''. x1 = x1' @ [x, x', x''] \\<Longrightarrow> thesis)\"\n          obtain x1' x1'' where tn_split:\"x1 = x1'@x1''\"\n                               \"length x1'' = 3\"\n            using 4\n            by (metis append_take_drop_id diff_diff_cancel length_drop)\n          then obtain x x1''2 where \"x1'' = x#x1''2\" \"length x1''2 = Suc (Suc 0)\"\n            by (metis length_Suc_conv numeral_3_eq_3)\n          then obtain x' x'' where tn''_def:\"x1''= [x,x',x'']\"\n            using List.length_Suc_conv[of x1''2 \"Suc 0\"]\n            by (metis length_0_conv length_Suc_conv)\n          thus ?thesis\n            using tn_split local_assms\n            by simp\n        qed\n        hence a:\"ct_suffix (x1'@[x,x',x'']) (to_ct_list (t1s' @ [t, t, T_i32]))\"\n          using t1s_suffix2 assms(3) TopType\n          by simp\n        hence b:\"ct_suffix (x1'@[x,x']) (to_ct_list (t1s' @ [t, t])) \\<and> (ct_eq x'' (TSome T_i32))\"\n          using to_ct_list_def ct_suffix_unfold_one[of \"(x1'@[x,x'])\" \"x''\" \"to_ct_list (t1s' @ [t, t])\"]\n          by fastforce\n        hence c:\"ct_suffix (x1'@[x]) (to_ct_list (t1s' @ [t])) \\<and> (ct_eq x' (TSome t))\"\n          using to_ct_list_def ct_suffix_unfold_one[of \"(x1'@[x])\" \"x'\" \"to_ct_list (t1s' @ [t])\"]\n          by fastforce\n        hence d:\"ct_suffix x1' (to_ct_list t1s') \\<and> (ct_eq x (TSome t))\"\n          using to_ct_list_def ct_suffix_unfold_one[of \"(x1')\" \"x\" \"to_ct_list (t1s')\"]\n          by fastforce\n        have \"(take (length x1 - 3) x1) = x1'\"\n          using x1_split\n          by simp\n        have x'_ind:\"(x1!(length x1-2)) = x'\"\n          using x1_split List.nth_append_length[of \"x1' @ [x]\"]\n          by simp\n        have x_ind:\"(x1!(length x1-3)) = x\"\n          using x1_split\n          by simp\n        have \"ct_suffix [TSome T_i32] x1\"\n          using b x1_split ct_suffix_def ct_list_eq_def ct_suffixI[of x1 \"x1' @ [x, x']\"]\n          by simp\n        hence \"check_single \\<C> e (TopType x1) = (select_return_top x1 (x1!(length x1-2)) (x1!(length x1-3)))\"\n          using type_update_select_conv_select_return_top[OF _ 4]\n          unfolding 2\n          by blast\n        moreover\n        have \"... = (TopType (x1'@[x])) \\<or> ... = (TopType (x1'@[x']))\"\n          apply (cases x; cases x')\n          using x1_split 4 nat_def 2 x_ind x'_ind c d\n          by simp_all\n        moreover\n        have \"ct_suffix (x1'@[x]) (to_ct_list t2s)\"\n          by (simp add: c t2s_def)\n        moreover\n        have \"ct_suffix (x1'@[x']) (to_ct_list t2s)\"\n          using ct_suffix_unfold_one[symmetric, of x' \"(TSome t)\" x1' \"(to_ct_list t1s')\"] c d\n                t2s_def\n          unfolding to_ct_list_def\n          by fastforce\n        ultimately\n        show ?thesis\n          using TopType\n          by auto\n      qed\n    qed simp_all\n  next\n    case 3\n    then obtain cons prods where c_s_def:\"check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)\"\n      by blast\n    hence ctm_def:\"ctm = type_update (Type t1s) cons prods\"\n      using assms(1)\n      by fastforce\n    hence cons_suffix:\"ct_suffix cons (to_ct_list t1s)\"\n      using assms\n      by (simp, metis (full_types) produce.simps(6))\n    hence t_int_def:\"consume (Type t1s) cons = (Type (take (length t1s - length cons) t1s))\"\n      using ctm_def\n      by simp\n    hence ctm_def2:\"ctm = produce (Type (take (length t1s - length cons) t1s)) prods\"\n      using ctm_def\n      by simp\n    show ?thesis\n    proof (cases ctn)\n      case (TopType x1)\n      hence \"ct_suffix x1 (to_ct_list t1s)\"\n        using assms(3)\n        by simp\n      thus ?thesis\n        using assms(2) ctm_def2\n      proof (cases prods)\n        case (TopType x1)\n        thus ?thesis\n          using consume_c_types_agree[OF t_int_def assms(3)] ctm_def2 assms(4) c_s_def\n          by (metis c_types_agree.elims(2) produce.simps(3,4) type_update.simps)\n      next\n        case (Type x2)\n        hence ctm_def3:\"ctm = Type ((take (length t1s - length cons) t1s)@ x2)\"\n          using ctm_def2\n          by simp\n        have \"ct_suffix x1 cons \\<or> ct_suffix cons x1\"\n          using ct_suffix_shared assms(3) TopType cons_suffix\n          by auto\n        thus ?thesis\n        proof (rule disjE)\n          assume \"ct_suffix x1 cons\"\n          hence \"consume (TopType x1) cons = TopType []\"\n            by (simp add: ct_suffix_length)\n          hence \"check_single \\<C> e ctn = TopType (to_ct_list x2)\"\n            using c_s_def TopType Type\n            by simp\n          thus ?thesis\n            using TopType ctm_def3 assms(4) c_types_agree_top2 ct_list_eq_refl\n            by auto\n        next\n          assume \"ct_suffix cons x1\"\n          hence 4:\"consume (TopType x1) cons = TopType (take (length x1 - length cons ) x1)\"\n            by (simp add: ct_suffix_length)\n          hence 3:\"check_single \\<C> e ctn = TopType ((take (length x1 - length cons ) x1) @ to_ct_list x2)\"\n            using c_s_def TopType Type\n            by simp\n          have \"((take (length t1s - length cons ) t1s) @  x2) = t2s\"\n            using assms(4) ctm_def3\n            by simp\n          have \"c_types_agree (TopType (take (length x1 - length cons ) x1)) (take (length t1s - length cons) t1s)\"\n            using consume_c_types_agree[OF t_int_def assms(3)] 4 TopType\n            by simp\n          hence \"c_types_agree (TopType (take (length x1 - length cons ) x1 @ to_ct_list x2)) (take (length t1s - length cons) t1s @ x2)\"\n            unfolding c_types_agree.simps to_ct_list_def\n            by (simp add: ct_suffix_cons2 ct_suffix_cons_it ct_suffix_extend_ct_list_eq)\n          thus ?thesis\n            using ctm_def3 assms 3\n            by simp\n        qed\n      qed simp\n    next\n      case (Type x2)\n      thus ?thesis\n        using assms\n        by simp\n    next\n      case Bot\n      thus ?thesis\n        using assms\n        by simp\n    qed\n  qed\nqed\n\nlemma b_e_type_checker_compose:\n  assumes \"b_e_type_checker \\<C> es (t1s _> t2s)\"\n          \"b_e_type_checker \\<C> [e] (t2s _> t3s)\"\n  shows \"b_e_type_checker \\<C> (es @ [e]) (t1s _> t3s)\"\nproof -\n  have \"c_types_agree (check_single \\<C> e (Type t2s)) t3s\"\n    using assms(2)\n    by simp\n  then obtain ctm where ctm_def:\"check_single \\<C> e (Type t2s) = ctm\"\n                                \"c_types_agree ctm t3s\"\n                                \"ctm \\<noteq> Bot\"\n    by fastforce\n  have \"c_types_agree (check \\<C> es (Type t1s)) t2s\"\n    using assms(1)\n    by simp\n  then obtain ctn where ctn_def:\"check \\<C> es (Type t1s) = ctn\"\n                                \"c_types_agree ctn t2s\"\n                                \"ctn \\<noteq> Bot\"\n    by fastforce\n  thus ?thesis\n    using check_single_imp_weakening[OF ctm_def(1,3) ctn_def(2) ctm_def(2)]\n          check_unfold_snoc[of \\<C> es \"(Type t1s)\" e]\n    by simp\nqed\n\nlemma b_e_check_single_type_type:\n  assumes \"check_single \\<C> e xs = (Type tm)\"\n  shows \"\\<exists>tn. xs = (Type tn)\"\nproof -\n  consider (1) \"check_single \\<C> e = id\" \n         | (2) \"check_single \\<C> e = (\\<lambda>ctn. type_update_select ctn)\"\n         | (3) \"(\\<exists>cons prods. (check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)))\"\n    using check_single_imp assms\n    by blast\n  thus ?thesis\n  proof (cases)\n    case 1\n    thus ?thesis\n      using assms\n      by simp\n  next\n    case 2\n    note outer_2 = 2\n    thus ?thesis\n      using assms\n    proof (cases xs)\n      case (TopType x1)\n      consider\n          (1) \"length x1 = 0\"\n        | (2) \"length x1 = Suc 0\"\n        | (3) \"length x1 = Suc (Suc 0)\"\n        | (4) \"length x1 \\<ge> 3\"\n        by linarith\n      thus ?thesis\n      proof cases\n        case 1\n        thus ?thesis\n          using assms 2 TopType\n          by simp\n      next\n        case 2\n        thus ?thesis\n          using assms outer_2 TopType produce_type_type\n          by fastforce\n      next\n        case 3\n        thus ?thesis\n          using assms 2 TopType\n          by (simp, metis checker_type.distinct(1) checker_type.distinct(5))\n      next\n        case 4\n        then obtain nat where nat_def:\"length x1 = Suc (Suc (Suc nat))\"\n          by (metis add_eq_if diff_Suc_1 le_Suc_ex numeral_3_eq_3 nat.distinct(2))\n        thus ?thesis\n          using assms 2 TopType\n        proof -\n          {\n            assume a1: \"produce (if ct_suffix [TAny, TAny, TSome T_i32] x1 then TopType (take (length x1 - length [TAny, TAny, TSome T_i32]) x1) else if ct_suffix x1 [TAny, TAny, TSome T_i32] then TopType [] else Bot) (select_return_top x1 (x1 ! Suc nat) (x1 ! nat)) = Type tm\"\n            obtain tts :: \"checker_type \\<Rightarrow> t list\" where\n              f2: \"\\<forall>c. (\\<forall>ca ts. produce c ca \\<noteq> Type ts) \\<or> c = Type (tts c)\"\n              using produce_type_type by moura\n            then have f3: \"\\<And>ts. \\<not> ct_suffix [TAny, TAny, TSome T_i32] x1 \\<or> Type tm \\<noteq> Type ts\"\n              using a1 by fastforce\n            then have \"\\<And>ts. \\<not> ct_suffix x1 [TAny, TAny, TSome T_i32] \\<or> Type tm \\<noteq> Type ts\"\n              using f2 a1 by fastforce\n            then have False\n              using f3 a1 by fastforce\n          }\n          thus ?thesis\n            using assms 2 TopType nat_def\n            by simp\n        qed\n      qed\n    qed simp_all\n  next\n    case 3\n    then obtain cons prods where check_def:\"check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)\"\n      by blast\n    hence \"produce (consume xs cons) prods = (Type tm)\"\n      using assms(1)\n      by simp\n    thus ?thesis\n      using assms check_def consume_type_type produce_type_type\n      by blast\n  qed\nqed\n\nlemma b_e_check_single_weaken_type:\n  assumes \"check_single \\<C> e (Type tn) = (Type tm)\"\n  shows \"check_single \\<C> e (Type (ts@tn)) = Type (ts@tm)\"\nproof -\n  consider (1) \"check_single \\<C> e = id\" \n         | (2) \"check_single \\<C> e = (\\<lambda>ctn. type_update_select ctn)\"\n         | (3) \"(\\<exists>cons prods. (check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)))\"\n    using check_single_imp assms\n    by blast\n  thus ?thesis\n  proof (cases)\n    case 1\n    thus ?thesis\n      using assms(1)\n      by simp\n  next\n    case 2\n    hence cond:\"(length tn \\<ge> 3 \\<and> (tn!(length tn-2)) = (tn!(length tn-3)))\"\n      using assms\n      by (simp, metis checker_type.distinct(5))\n    hence \"consume (Type tn) [TAny, TSome T_i32] = (Type tm)\"\n      using assms 2\n      by simp\n    hence \"consume (Type (ts@tn)) [TAny, TSome T_i32] = (Type (ts@tm))\"\n      using consume_weaken_type\n      by blast\n    moreover\n    have \"(length (ts@tn) \\<ge> 3 \\<and> ((ts@tn)!(length (ts@tn)-2)) = ((ts@tn)!(length (ts@tn)-3)))\"\n      using cond\n      by (simp, metis add.commute add_leE nth_append_length_plus numeral_Bit1 numeral_One\n                      one_add_one ordered_cancel_comm_monoid_diff_class.diff_add_assoc2)\n    ultimately\n    show ?thesis\n      using 2\n      by simp\n  next\n    case 3\n    then obtain cons prods where check_def:\"check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)\"\n      by blast\n    hence \"produce (consume (Type tn) cons) prods = (Type tm)\"\n      using assms(1)\n      by simp\n    then obtain t_int where t_int_def:\"consume (Type tn) cons = (Type t_int)\"\n      by (metis consume.simps(1) produce.simps(6))\n    thus ?thesis\n      using assms(1) check_def\n            consume_weaken_type[OF t_int_def, of ts]\n            produce_weaken_type[of t_int prods tm ts]\n      by simp\n  qed\nqed\n\nlemma b_e_check_single_weaken_top:\n  assumes \"check_single \\<C> e (Type tn) = TopType tm\"\n  shows \"check_single \\<C> e (Type (ts@tn)) = TopType tm\"\nproof -\n  consider (1) \"check_single \\<C> e = id\" \n         | (2) \"check_single \\<C> e = (\\<lambda>ctn. type_update_select ctn)\"\n         | (3) \"(\\<exists>cons prods. (check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)))\"\n    using check_single_imp assms\n    by blast\n  thus ?thesis\n  proof (cases)\n    case 1\n    thus ?thesis\n      using assms\n      by simp\n  next\n    case 2\n    thus ?thesis\n      using assms\n      by (simp, metis checker_type.distinct(1) checker_type.distinct(3) consume.simps(1))\n  next\n    case 3\n    then obtain cons prods where check_def:\"check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)\"\n      by blast\n    hence \"produce (consume (Type tn) cons) prods = (TopType tm)\"\n      using assms(1)\n      by simp\n    moreover\n    then obtain t_int where t_int_def:\"consume (Type tn) cons = (Type t_int)\"\n      by (metis checker_type.distinct(3) consume.simps(1) produce.simps(6))\n    ultimately\n    show ?thesis\n      using check_def consume_weaken_type\n      by (cases prods, auto)\n  qed\nqed\n\nlemma b_e_check_weaken_type:\n  assumes \"check \\<C> es (Type tn) = (Type tm)\"\n  shows \"check \\<C> es (Type (ts@tn)) = (Type (ts@tm))\"\n  using assms\nproof (induction es arbitrary: tn tm rule: List.rev_induct)\n  case Nil\n  thus ?case\n    by simp\nnext\n  case (snoc e es)\n  hence \"check_single \\<C> e (check \\<C> es (Type tn)) = Type tm\"\n    using check_unfold_snoc[OF check_neq_bot_snoc]\n    by (metis checker_type.distinct(5))\n  thus ?case\n    using b_e_check_single_weaken_type b_e_check_single_type_type snoc\n    by (metis check_unfold_snoc checker_type.distinct(5))\nqed\n\nlemma check_bot: \"check \\<C> es Bot = Bot\"\n  by (simp add: list.case_eq_if)\n\nlemma b_e_check_weaken_top:\n  assumes \"check \\<C> es (Type tn) = (TopType tm)\"\n  shows \"check \\<C> es (Type (ts@tn)) = (TopType tm)\"\n  using assms\nproof (induction es arbitrary: tn tm)\n  case Nil\n  thus ?case\n    by simp\nnext\n  case (Cons e es)\n  show ?case\n  proof (cases \"(check_single \\<C> e (Type tn))\")\n    case (TopType x1)\n    hence \"check_single \\<C> e (Type (ts@tn)) = TopType x1\"\n      using b_e_check_single_weaken_top\n      by blast\n    thus ?thesis\n      using TopType Cons\n      by simp\n  next\n    case (Type x2)\n    hence \"check_single \\<C> e (Type (ts@tn)) = Type (ts@x2)\"\n      using b_e_check_single_weaken_type\n      by blast\n    thus ?thesis\n      using Cons Type\n      by fastforce\n  next\n    case Bot\n    thus ?thesis\n      using check_bot Cons\n      by simp\n  qed\n  \nqed\n\nlemma b_e_type_checker_weaken:\n  assumes \"b_e_type_checker \\<C> es (t1s _> t2s)\"\n  shows \"b_e_type_checker \\<C> es (ts@t1s _> ts@t2s)\"\nproof -\n  have \"c_types_agree (check \\<C> es (Type t1s)) t2s\"\n    using assms(1)\n    by simp\n  then obtain ctn where ctn_def:\"check \\<C> es (Type t1s) = ctn\"\n                                \"c_types_agree ctn t2s\"\n                                \"ctn \\<noteq> Bot\"\n    by fastforce\n  show ?thesis\n  proof (cases ctn)\n    case (TopType x1)\n    thus ?thesis\n      using ctn_def(1,2) b_e_check_weaken_top[of \\<C> es t1s x1 ts]\n      by (metis append_assoc b_e_type_checker.simps c_types_agree_imp_ct_list_eq c_types_agree_top2)\n  next\n    case (Type x2)\n    thus ?thesis\n      using ctn_def(1,2) b_e_check_weaken_type[of \\<C> es t1s x2 ts]\n      by simp\n  next\n    case Bot\n    thus ?thesis\n      using ctn_def(3)\n      by simp\n  qed\nqed\n\nlemma b_e_type_checker_complete:\n  assumes \"\\<C> \\<turnstile> es : (tn _> tm)\"\n  shows \"b_e_type_checker \\<C> es (tn _> tm)\"\n  using assms\nproof (induction es \"(tn _> tm)\" arbitrary: tn tm rule: b_e_typing.induct)\n  case (select \\<C> t)\n  have \"ct_list_eq [TAny, TSome T_i32] [TSome t, TSome T_i32]\"\n    by (simp add: to_ct_list_def ct_list_eq_def)\n  thus ?case\n    using ct_suffix_extend_ct_list_eq[OF ct_suffix_nil[of \"[TSome t]\"]] to_ct_list_def\n    by auto\nnext\n  case (br_table \\<C> ts \"is\" i t1s t2s)\n  show ?case\n    using list_all_conv_same_lab[OF br_table]\n    by (auto simp add: to_ct_list_def ct_suffix_nil ct_suffix_cons_it)\nnext\n  case (set_global i \\<C> t)\n  thus ?case\n    using to_ct_list_def ct_suffix_refl is_mut_def tg_t_def\n    by auto\nnext\n  case (composition \\<C> es t1s t2s e t3s)\n  thus ?case\n    using b_e_type_checker_compose\n    by simp\nnext\n  case (weakening \\<C> es t1s t2s ts)\n  thus ?case\n    using b_e_type_checker_weaken\n    by simp\nqed (auto simp add: to_ct_list_def ct_suffix_refl ct_suffix_nil ct_suffix_cons_it\n                    ct_suffix_singleton_any)\n\ntheorem b_e_typing_equiv_b_e_type_checker:\n  shows \"(\\<C> \\<turnstile> es : (tn _> tm)) = (b_e_type_checker \\<C> es (tn _> tm))\"\n  using b_e_type_checker_sound b_e_type_checker_complete\n  by blast\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/WebAssembly/Wasm_Checker_Properties.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.5117166047041652, "lm_q1q2_score": 0.27580666368281753}}
{"text": "theory CoCallFix\nimports CoCallAnalysisSig CoCallAnalysisBinds ArityAnalysisSig \"../Launchbury/Env-Nominal\"  ArityAnalysisFix\nbegin\n\n\nlocale CoCallArityAnalysis =\n  fixes cccExp :: \"exp \\<Rightarrow> (Arity \\<rightarrow> AEnv \\<times> CoCalls)\"\nbegin\n\ndefinition Aexp :: \"exp \\<Rightarrow> (Arity \\<rightarrow> AEnv)\"\n  where \"Aexp e = (\\<Lambda> a. fst (cccExp e \\<cdot> a))\"\n\nsublocale ArityAnalysis Aexp.\n\nabbreviation Aexp_syn' (\"\\<A>\\<^bsub>_\\<^esub>\") where \"\\<A>\\<^bsub>a\\<^esub> \\<equiv> (\\<lambda>e. Aexp e\\<cdot>a)\"\nabbreviation Aexp_bot_syn' (\"\\<A>\\<^sup>\\<bottom>\\<^bsub>_\\<^esub>\") where \"\\<A>\\<^sup>\\<bottom>\\<^bsub>a\\<^esub> \\<equiv> (\\<lambda>e. fup\\<cdot>(Aexp e)\\<cdot>a)\"\n\nlemma Aexp_eq:\n  \"\\<A>\\<^bsub>a\\<^esub> e = fst (cccExp e \\<cdot> a)\"\n  unfolding Aexp_def by (rule beta_cfun) (intro cont2cont)\n\nlemma fup_Aexp_eq:\n  \"fup\\<cdot>(Aexp e)\\<cdot>a = fst (fup\\<cdot>(cccExp e)\\<cdot>a)\"\n  by (cases a)(simp_all add: Aexp_eq)\n\n\ndefinition CCexp :: \"exp \\<Rightarrow> (Arity \\<rightarrow> CoCalls)\" where \"CCexp \\<Gamma> = (\\<Lambda> a. snd (cccExp \\<Gamma>\\<cdot>a))\"\nlemma CCexp_eq:\n  \"CCexp e\\<cdot>a = snd (cccExp e \\<cdot> a)\"\n  unfolding CCexp_def by (rule beta_cfun) (intro cont2cont)\n\nlemma fup_CCexp_eq:\n  \"fup\\<cdot>(CCexp e)\\<cdot>a = snd (fup\\<cdot>(cccExp e)\\<cdot>a)\"\n  by (cases a)(simp_all add: CCexp_eq)\n\nsublocale CoCallAnalysis CCexp.\n\ndefinition CCfix :: \"heap \\<Rightarrow> (AEnv \\<times> CoCalls) \\<rightarrow> CoCalls\"\n  where \"CCfix \\<Gamma> = (\\<Lambda> aeG. (\\<mu> G'. ccBindsExtra \\<Gamma>\\<cdot>(fst aeG , G') \\<squnion> snd aeG))\"\n\nlemma CCfix_eq:\n  \"CCfix \\<Gamma>\\<cdot>(ae,G) = (\\<mu> G'. ccBindsExtra \\<Gamma>\\<cdot>(ae, G') \\<squnion> G)\"\n  unfolding CCfix_def\n  by simp\n\nlemma CCfix_unroll: \"CCfix \\<Gamma>\\<cdot>(ae,G) = ccBindsExtra \\<Gamma>\\<cdot>(ae, CCfix \\<Gamma>\\<cdot>(ae,G)) \\<squnion> G\"\n  unfolding  CCfix_eq\n  apply (subst fix_eq)\n  apply simp\n  done\n\nlemma fup_ccExp_restr_subst': \n  assumes \"\\<And> a. cc_restr S (CCexp e[x::=y]\\<cdot>a) = cc_restr S (CCexp e\\<cdot>a)\"\n  shows \"cc_restr S (fup\\<cdot>(CCexp e[x::=y])\\<cdot>a) = cc_restr S (fup\\<cdot>(CCexp e)\\<cdot>a)\"\n  using assms\n  by (cases a) (auto simp del: cc_restr_cc_restr simp add: cc_restr_cc_restr[symmetric])\n\nlemma ccBindsExtra_restr_subst': \n  assumes \"\\<And> x' e a. (x',e) \\<in> set \\<Gamma> \\<Longrightarrow> cc_restr S (CCexp e[x::=y]\\<cdot>a) = cc_restr S (CCexp e\\<cdot>a)\"\n  assumes \"x \\<notin> S\"\n  assumes \"y \\<notin> S\"\n  assumes \"domA \\<Gamma> \\<subseteq> S\"\n  shows  \"cc_restr S (ccBindsExtra  \\<Gamma>[x::h=y]\\<cdot>(ae, G)) \n       = cc_restr S (ccBindsExtra  \\<Gamma>\\<cdot>(ae f|` S , cc_restr S G))\"\n  apply (simp add: ccBindsExtra_simp ccBinds_eq ccBind_eq Int_absorb2[OF assms(4)] fv_subst_int[OF assms(3,2)])\n  apply (intro arg_cong2[where f = \"op \\<squnion>\"] refl  arg_cong[OF mapCollect_cong])\n  apply (subgoal_tac \"k \\<in> S\")\n  apply (auto intro: fup_ccExp_restr_subst'[OF assms(1)[OF map_of_SomeD]] simp add: fv_subst_int[OF assms(3,2)]   fv_subst_int2[OF assms(3,2)] ccSquare_def)[1]\n  apply (metis assms(4) contra_subsetD domI dom_map_of_conv_domA)\n  apply (subgoal_tac \"k \\<in> S\")\n  apply (auto intro: fup_ccExp_restr_subst'[OF assms(1)[OF map_of_SomeD]]\n              simp add: fv_subst_int[OF assms(3,2)]   fv_subst_int2[OF assms(3,2)] ccSquare_def cc_restr_twist[where S = S] simp del: cc_restr_cc_restr)[1]\n  apply (subst fup_ccExp_restr_subst'[OF assms(1)[OF map_of_SomeD]], assumption)\n  apply (simp add: fv_subst_int[OF assms(3,2)]   fv_subst_int2[OF assms(3,2)] )\n  apply (subst fup_ccExp_restr_subst'[OF assms(1)[OF map_of_SomeD]], assumption)\n  apply (simp add: fv_subst_int[OF assms(3,2)]   fv_subst_int2[OF assms(3,2)] )\n  apply (metis assms(4) contra_subsetD domI dom_map_of_conv_domA)\n  done\n\nlemma ccBindsExtra_restr:\n  assumes \"domA \\<Gamma> \\<subseteq> S\"\n  shows \"cc_restr S (ccBindsExtra \\<Gamma>\\<cdot>(ae, G)) = cc_restr S (ccBindsExtra \\<Gamma>\\<cdot>(ae f|` S, cc_restr S G))\"\n  using assms\n  apply (simp add: ccBindsExtra_simp ccBinds_eq ccBind_eq Int_absorb2)\n  apply (intro arg_cong2[where f = \"op \\<squnion>\"] refl arg_cong[OF mapCollect_cong])\n  apply (subgoal_tac \"k \\<in> S\")\n  apply simp\n  apply (metis contra_subsetD domI dom_map_of_conv_domA)\n  apply (subgoal_tac \"k \\<in> S\")\n  apply simp\n  apply (metis contra_subsetD domI dom_map_of_conv_domA)\n  done\n\nlemma CCfix_restr:\n  assumes \"domA \\<Gamma> \\<subseteq> S\"\n  shows \"cc_restr S (CCfix \\<Gamma>\\<cdot>(ae, G)) = cc_restr S (CCfix \\<Gamma>\\<cdot>(ae f|` S, cc_restr S G))\"\n  unfolding CCfix_def\n  apply simp\n  apply (rule parallel_fix_ind[where P = \"\\<lambda> x y . cc_restr S x = cc_restr S y\"])\n  apply simp\n  apply rule\n  apply simp\n  apply (subst (1 2) ccBindsExtra_restr[OF assms])\n  apply (auto)\n  done\n\nlemma ccField_CCfix:\n  shows \"ccField (CCfix \\<Gamma>\\<cdot>(ae, G)) \\<subseteq> fv \\<Gamma> \\<union> ccField G\"\n  unfolding CCfix_def\n  apply simp\n  apply (rule fix_ind[where P = \"\\<lambda> x . ccField x \\<subseteq> fv \\<Gamma> \\<union> ccField G\"])\n  apply (auto dest!: set_mp[OF ccField_ccBindsExtra])\n  done\n\n\nlemma CCfix_restr_subst':\n  assumes \"\\<And> x' e a. (x',e) \\<in> set \\<Gamma> \\<Longrightarrow> cc_restr S (CCexp e[x::=y]\\<cdot>a) = cc_restr S (CCexp e\\<cdot>a)\"\n  assumes \"x \\<notin> S\"\n  assumes \"y \\<notin> S\"\n  assumes \"domA \\<Gamma> \\<subseteq> S\"\n  shows \"cc_restr S (CCfix \\<Gamma>[x::h=y]\\<cdot>(ae, G)) = cc_restr S (CCfix \\<Gamma>\\<cdot>(ae f|` S, cc_restr S G))\"\n  unfolding CCfix_def\n  apply simp\n  apply (rule parallel_fix_ind[where P = \"\\<lambda> x y . cc_restr S x = cc_restr S y\"])\n  apply simp\n  apply rule\n  apply simp\n  apply (subst  ccBindsExtra_restr_subst'[OF assms], assumption)\n  apply (subst ccBindsExtra_restr[OF assms(4)]) back \n  apply (auto)\n  done\n\n\nend\n\nlemma Aexp_eqvt[eqvt]:  \"\\<pi> \\<bullet> (CoCallArityAnalysis.Aexp cccExp e) = CoCallArityAnalysis.Aexp (\\<pi> \\<bullet> cccExp) (\\<pi> \\<bullet> e)\"\n  apply (rule cfun_eqvtI) unfolding CoCallArityAnalysis.Aexp_eq by perm_simp rule\n\nlemma CCexp_eqvt[eqvt]:  \"\\<pi> \\<bullet> (CoCallArityAnalysis.CCexp cccExp e) = CoCallArityAnalysis.CCexp (\\<pi> \\<bullet> cccExp) (\\<pi> \\<bullet> e)\"\n  apply (rule cfun_eqvtI) unfolding CoCallArityAnalysis.CCexp_eq by perm_simp rule\n\nlemma CCfix_eqvt[eqvt]: \"\\<pi> \\<bullet> (CoCallArityAnalysis.CCfix cccExp \\<Gamma>) = CoCallArityAnalysis.CCfix (\\<pi> \\<bullet> cccExp) (\\<pi> \\<bullet> \\<Gamma>)\"\n  unfolding CoCallArityAnalysis.CCfix_def by perm_simp (simp_all add: Abs_cfun_eqvt)\n\nlemma ccFix_cong[fundef_cong]:\n  \"\\<lbrakk> (\\<And> e. e \\<in> snd ` set heap2 \\<Longrightarrow> cccexp1 e = cccexp2 e); heap1 = heap2 \\<rbrakk>\n      \\<Longrightarrow> CoCallArityAnalysis.CCfix cccexp1 heap1 = CoCallArityAnalysis.CCfix cccexp2 heap2\"\n   unfolding CoCallArityAnalysis.CCfix_def\n   apply (rule arg_cong) back\n   apply (rule ccBindsExtra_cong)\n   apply (auto simp add: CoCallArityAnalysis.CCexp_def)\n   done\n\n\ncontext CoCallArityAnalysis\nbegin\ndefinition cccFix ::  \"heap \\<Rightarrow> ((AEnv \\<times> CoCalls) \\<rightarrow> (AEnv \\<times> CoCalls))\"\n  where \"cccFix \\<Gamma> = (\\<Lambda> i. (Afix \\<Gamma>\\<cdot>(fst i \\<squnion> (\\<lambda>_.up\\<cdot>0) f|` thunks \\<Gamma>), CCfix \\<Gamma>\\<cdot>(Afix \\<Gamma>\\<cdot>(fst i  \\<squnion> (\\<lambda>_.up\\<cdot>0) f|` (thunks \\<Gamma>)), snd i)))\"\n\nlemma cccFix_eq:\n  \"cccFix \\<Gamma>\\<cdot>i = (Afix \\<Gamma>\\<cdot>(fst i \\<squnion> (\\<lambda>_.up\\<cdot>0) f|` thunks \\<Gamma>), CCfix \\<Gamma>\\<cdot>(Afix \\<Gamma>\\<cdot>(fst i  \\<squnion> (\\<lambda>_.up\\<cdot>0) f|` (thunks \\<Gamma>)), snd i))\"\n  unfolding cccFix_def\n  by (rule beta_cfun)(intro cont2cont)\nend\n\nlemma cccFix_eqvt[eqvt]: \"\\<pi> \\<bullet> (CoCallArityAnalysis.cccFix cccExp \\<Gamma>) = CoCallArityAnalysis.cccFix  (\\<pi> \\<bullet> cccExp) (\\<pi> \\<bullet> \\<Gamma>)\"\n  apply (rule cfun_eqvtI) unfolding CoCallArityAnalysis.cccFix_eq by perm_simp rule\n\nlemma cccFix_cong[fundef_cong]:\n  \"\\<lbrakk> (\\<And> e. e \\<in> snd ` set heap2 \\<Longrightarrow> cccexp1 e = cccexp2 e); heap1 = heap2 \\<rbrakk>\n      \\<Longrightarrow> CoCallArityAnalysis.cccFix cccexp1 heap1 = CoCallArityAnalysis.cccFix cccexp2 heap2\"\n   unfolding CoCallArityAnalysis.cccFix_def\n   apply (rule cfun_eqI)\n   apply auto\n   apply (rule arg_cong[OF Afix_cong], auto simp add: CoCallArityAnalysis.Aexp_def)[1]\n   apply (rule arg_cong2[OF ccFix_cong Afix_cong ])\n   apply (auto simp add: CoCallArityAnalysis.Aexp_def)\n   done\n\n\nsubsubsection {* The non-recursive case *}\n\ndefinition ABind_nonrec :: \"var \\<Rightarrow> exp \\<Rightarrow> AEnv \\<times> CoCalls \\<rightarrow> Arity\\<^sub>\\<bottom>\"\nwhere\n  \"ABind_nonrec x e = (\\<Lambda> i. (if isVal e \\<or> x--x\\<notin>(snd i) then fst i x else up\\<cdot>0))\"\n\nlemma ABind_nonrec_eq:\n  \"ABind_nonrec x e\\<cdot>(ae,G) = (if isVal e \\<or> x--x\\<notin>G then ae x else up\\<cdot>0)\"\n  unfolding ABind_nonrec_def\n  apply (subst beta_cfun)\n  apply (rule cont_if_else_above)\n  apply auto\n  by (metis in_join join_self_below(4))\n\nlemma ABind_nonrec_eqvt[eqvt]: \"\\<pi> \\<bullet> (ABind_nonrec x e) = ABind_nonrec (\\<pi> \\<bullet> x) (\\<pi> \\<bullet> e)\"\n  apply (rule cfun_eqvtI)\n  apply (case_tac xa, simp)\n  unfolding ABind_nonrec_eq\n  by perm_simp rule\n\nlemma ABind_nonrec_above_arg:\n  \"ae x \\<sqsubseteq> ABind_nonrec x e \\<cdot> (ae, G)\"\nunfolding ABind_nonrec_eq by auto\n\ndefinition Aheap_nonrec where\n  \"Aheap_nonrec x e = (\\<Lambda> i. esing x\\<cdot>(ABind_nonrec x e\\<cdot>i))\"\n\nlemma Aheap_nonrec_simp:\n  \"Aheap_nonrec x e\\<cdot>i = esing x\\<cdot>(ABind_nonrec x e\\<cdot>i)\"\n  unfolding Aheap_nonrec_def by simp\n\nlemma Aheap_nonrec_lookup[simp]:\n  \"(Aheap_nonrec x e\\<cdot>i) x = ABind_nonrec x e\\<cdot>i\"\n  unfolding Aheap_nonrec_simp by simp\n\nlemma Aheap_nonrec_eqvt'[eqvt]:\n  \"\\<pi> \\<bullet> (Aheap_nonrec x e) = Aheap_nonrec (\\<pi> \\<bullet> x) (\\<pi> \\<bullet> e)\"\n  apply (rule cfun_eqvtI)\n  unfolding Aheap_nonrec_simp\n  by (perm_simp, rule)\n\n\ncontext CoCallArityAnalysis\nbegin\n\n  definition Afix_nonrec\n   where \"Afix_nonrec x e = (\\<Lambda> i. fup\\<cdot>(Aexp e)\\<cdot>(ABind_nonrec x e \\<cdot> i) \\<squnion> fst i)\"\n\n  lemma Afix_nonrec_eq[simp]:\n    \"Afix_nonrec x e \\<cdot> i = fup\\<cdot>(Aexp e)\\<cdot>(ABind_nonrec x e \\<cdot> i) \\<squnion> fst i\"\n    unfolding Afix_nonrec_def\n    by (rule beta_cfun) simp\n\n  definition CCfix_nonrec\n   where \"CCfix_nonrec x e = (\\<Lambda> i. ccBind x e \\<cdot> (Aheap_nonrec x e\\<cdot>i, snd i)  \\<squnion> ccProd (fv e) (ccNeighbors x (snd i) - (if isVal e then {} else {x})) \\<squnion> snd i)\"\n\n  lemma CCfix_nonrec_eq[simp]:\n    \"CCfix_nonrec x e \\<cdot> i = ccBind x e\\<cdot>(Aheap_nonrec x e\\<cdot>i, snd i)  \\<squnion> ccProd (fv e) (ccNeighbors x (snd i) - (if isVal e then {} else {x})) \\<squnion> snd i\"\n    unfolding CCfix_nonrec_def\n    by (rule beta_cfun) (intro cont2cont)\n\n  definition cccFix_nonrec ::  \"var \\<Rightarrow> exp \\<Rightarrow> ((AEnv \\<times> CoCalls) \\<rightarrow> (AEnv \\<times> CoCalls))\"\n    where \"cccFix_nonrec x e = (\\<Lambda> i. (Afix_nonrec x e \\<cdot>i , CCfix_nonrec x e \\<cdot>i))\"\n\n  lemma cccFix_nonrec_eq[simp]:\n    \"cccFix_nonrec x e\\<cdot>i = (Afix_nonrec x e \\<cdot>i , CCfix_nonrec x e \\<cdot>i)\"\n    unfolding cccFix_nonrec_def\n    by (rule beta_cfun) (intro cont2cont)\n\nend\n\n\nlemma AFix_nonrec_eqvt[eqvt]: \"\\<pi> \\<bullet> (CoCallArityAnalysis.Afix_nonrec cccExp x e) = CoCallArityAnalysis.Afix_nonrec (\\<pi> \\<bullet> cccExp) (\\<pi> \\<bullet> x) (\\<pi> \\<bullet> e)\"\n  apply (rule cfun_eqvtI)\n  unfolding CoCallArityAnalysis.Afix_nonrec_eq\n  by perm_simp rule\n\n\nlemma CCFix_nonrec_eqvt[eqvt]: \"\\<pi> \\<bullet> (CoCallArityAnalysis.CCfix_nonrec cccExp x e) = CoCallArityAnalysis.CCfix_nonrec (\\<pi> \\<bullet> cccExp) (\\<pi> \\<bullet> x) (\\<pi> \\<bullet> e)\"\n  apply (rule cfun_eqvtI)\n  unfolding CoCallArityAnalysis.CCfix_nonrec_eq\n  by perm_simp rule\n\nlemma cccFix_nonrec_eqvt[eqvt]: \"\\<pi> \\<bullet> (CoCallArityAnalysis.cccFix_nonrec cccExp x e) = CoCallArityAnalysis.cccFix_nonrec (\\<pi> \\<bullet> cccExp) (\\<pi> \\<bullet> x) (\\<pi> \\<bullet> e)\"\n  apply (rule cfun_eqvtI)\n  unfolding CoCallArityAnalysis.cccFix_nonrec_eq\n  by perm_simp rule\n\nsubsubsection {* Combining the cases *}\n\ncontext CoCallArityAnalysis\nbegin\n  definition cccFix_choose ::  \"heap \\<Rightarrow> ((AEnv \\<times> CoCalls) \\<rightarrow> (AEnv \\<times> CoCalls))\"\n    where \"cccFix_choose \\<Gamma> = (if nonrec \\<Gamma> then case_prod cccFix_nonrec (hd \\<Gamma>) else cccFix \\<Gamma>)\"\n\n  lemma cccFix_choose_simp1[simp]:\n    \"\\<not> nonrec \\<Gamma> \\<Longrightarrow> cccFix_choose \\<Gamma> = cccFix \\<Gamma>\"\n  unfolding cccFix_choose_def by simp\n\n  lemma cccFix_choose_simp2[simp]:\n    \"x \\<notin> fv e \\<Longrightarrow> cccFix_choose [(x,e)] = cccFix_nonrec x e\"\n  unfolding cccFix_choose_def nonrec_def by auto\n\nend\n\nlemma cccFix_choose_eqvt[eqvt]: \"\\<pi> \\<bullet> (CoCallArityAnalysis.cccFix_choose cccExp \\<Gamma>) = CoCallArityAnalysis.cccFix_choose (\\<pi> \\<bullet> cccExp) (\\<pi> \\<bullet> \\<Gamma>)\"\n  unfolding CoCallArityAnalysis.cccFix_choose_def \n  apply (cases nonrec \\<pi>  rule: eqvt_cases[where x = \\<Gamma>])\n  apply (perm_simp, rule)\n  apply simp\n  apply (erule nonrecE)\n  apply (simp )\n\n  apply simp\n  done\n\nlemma cccFix_nonrec_cong[fundef_cong]:\n  \"cccexp1 e = cccexp2 e  \\<Longrightarrow> CoCallArityAnalysis.cccFix_nonrec cccexp1 x e = CoCallArityAnalysis.cccFix_nonrec cccexp2 x e\"\n   apply (rule cfun_eqI)\n   unfolding CoCallArityAnalysis.cccFix_nonrec_eq\n   unfolding CoCallArityAnalysis.Afix_nonrec_eq\n   unfolding CoCallArityAnalysis.CCfix_nonrec_eq\n   unfolding CoCallArityAnalysis.fup_Aexp_eq\n   apply (simp only: )\n   apply (rule arg_cong[OF ccBind_cong])\n   apply simp\n   unfolding CoCallArityAnalysis.CCexp_def\n   apply simp\n   done\n\nlemma cccFix_choose_cong[fundef_cong]:\n  \"\\<lbrakk> (\\<And> e. e \\<in> snd ` set heap2 \\<Longrightarrow> cccexp1 e = cccexp2 e); heap1 = heap2 \\<rbrakk>\n      \\<Longrightarrow> CoCallArityAnalysis.cccFix_choose cccexp1 heap1 = CoCallArityAnalysis.cccFix_choose cccexp2 heap2\"\n   unfolding CoCallArityAnalysis.cccFix_choose_def\n   apply (rule cfun_eqI)\n   apply (auto elim!: nonrecE)\n   apply (rule arg_cong[OF cccFix_nonrec_cong], auto)\n   apply (rule arg_cong[OF cccFix_cong], auto)[1]\n   done\n\nend\n", "meta": {"author": "nomeata", "repo": "isa-launchbury", "sha": "2caa8d7d588e218aef1c49f2f327597af06d116e", "save_path": "github-repos/isabelle/nomeata-isa-launchbury", "path": "github-repos/isabelle/nomeata-isa-launchbury/isa-launchbury-2caa8d7d588e218aef1c49f2f327597af06d116e/Call_Arity/CoCallFix.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297746074044134, "lm_q2_score": 0.43782349911420193, "lm_q1q2_score": 0.27573012226707305}}
{"text": "(*  Title:      Uint.thy\n    Author:     Peter Lammich, TU Munich\n    Author:     Andreas Lochbihler, ETH Zurich\n*)\n\nchapter \\<open>Unsigned words of default size\\<close>\n\ntheory Uint imports\n  Code_Target_Word_Base\nbegin\n\ntext \\<open>\n  This theory provides access to words in the target languages of the code generator\n  whose bit width is the default of the target language. To that end, the type \\<open>uint\\<close>\n  models words of width \\<open>dflt_size\\<close>, but \\<open>dflt_size\\<close> is known only to be positive.\n\n  Usage restrictions:\n  Default-size words (type \\<open>uint\\<close>) cannot be used for evaluation, because \n  the results depend on the particular choice of word size in the target language\n  and implementation. Symbolic evaluation has not yet been set up for \\<open>uint\\<close>.\n\\<close>\n\ntext \\<open>The default size type\\<close>\ntypedecl dflt_size\n\ninstantiation dflt_size :: typerep begin\ndefinition \"typerep_class.typerep \\<equiv>  \\<lambda>_ :: dflt_size itself. Typerep.Typerep (STR ''Uint.dflt_size'') []\"\ninstance ..\nend\n\nconsts dflt_size_aux :: \"nat\"\nspecification (dflt_size_aux) dflt_size_aux_g0: \"dflt_size_aux > 0\"\n  by auto\nhide_fact dflt_size_aux_def\n\ninstantiation dflt_size :: len begin\ndefinition \"len_of_dflt_size (_ :: dflt_size itself) \\<equiv> dflt_size_aux\"\ninstance by(intro_classes)(simp add: len_of_dflt_size_def dflt_size_aux_g0)\nend\n\nabbreviation \"dflt_size \\<equiv> len_of (TYPE (dflt_size))\"\n\ncontext includes integer.lifting begin\nlift_definition dflt_size_integer :: integer is \"int dflt_size\" .\ndeclare dflt_size_integer_def[code del]\n  \\<comment> \\<open>The code generator will substitute a machine-dependent value for this constant\\<close>\n\nlemma dflt_size_by_int[code]: \"dflt_size = nat_of_integer dflt_size_integer\"\nby transfer simp\n\nlemma dflt_size[simp]: \n  \"dflt_size > 0\"\n  \"dflt_size \\<ge> Suc 0\"\n  \"\\<not> dflt_size < Suc 0\"\n  using len_gt_0[where 'a=dflt_size]\n  by (simp_all del: len_gt_0)\nend\n\ndeclare prod.Quotient[transfer_rule]\n\nsection \\<open>Type definition and primitive operations\\<close>\n\ntypedef uint = \"UNIV :: dflt_size word set\" .. \n\nsetup_lifting type_definition_uint\n\ntext \\<open>Use an abstract type for code generation to disable pattern matching on @{term Abs_uint}.\\<close>\ndeclare Rep_uint_inverse[code abstype]\n\ndeclare Quotient_uint[transfer_rule]\n\ninstantiation uint :: \"{neg_numeral, modulo, comm_monoid_mult, comm_ring}\" begin\nlift_definition zero_uint :: uint is \"0 :: dflt_size word\" .\nlift_definition one_uint :: uint is \"1\" .\nlift_definition plus_uint :: \"uint \\<Rightarrow> uint \\<Rightarrow> uint\" is \"(+) :: dflt_size word \\<Rightarrow> _\" .\nlift_definition minus_uint :: \"uint \\<Rightarrow> uint \\<Rightarrow> uint\" is \"(-)\" .\nlift_definition uminus_uint :: \"uint \\<Rightarrow> uint\" is uminus .\nlift_definition times_uint :: \"uint \\<Rightarrow> uint \\<Rightarrow> uint\" is \"(*)\" .\nlift_definition divide_uint :: \"uint \\<Rightarrow> uint \\<Rightarrow> uint\" is \"(div)\" .\nlift_definition modulo_uint :: \"uint \\<Rightarrow> uint \\<Rightarrow> uint\" is \"(mod)\" .\ninstance by standard (transfer, simp add: algebra_simps)+\nend\n\ninstantiation uint :: linorder begin\nlift_definition less_uint :: \"uint \\<Rightarrow> uint \\<Rightarrow> bool\" is \"(<)\" .\nlift_definition less_eq_uint :: \"uint \\<Rightarrow> uint \\<Rightarrow> bool\" is \"(\\<le>)\" .\ninstance by standard (transfer, simp add: less_le_not_le linear)+\nend\n\nlemmas [code] = less_uint.rep_eq less_eq_uint.rep_eq\n\ninstantiation uint :: bit_operations begin\nlift_definition bitNOT_uint :: \"uint \\<Rightarrow> uint\" is bitNOT .\nlift_definition bitAND_uint :: \"uint \\<Rightarrow> uint \\<Rightarrow> uint\" is bitAND .\nlift_definition bitOR_uint :: \"uint \\<Rightarrow> uint \\<Rightarrow> uint\" is bitOR .\nlift_definition bitXOR_uint :: \"uint \\<Rightarrow> uint \\<Rightarrow> uint\" is bitXOR .\nlift_definition test_bit_uint :: \"uint \\<Rightarrow> nat \\<Rightarrow> bool\" is test_bit .\nlift_definition set_bit_uint :: \"uint \\<Rightarrow> nat \\<Rightarrow> bool \\<Rightarrow> uint\" is set_bit .\nlift_definition lsb_uint :: \"uint \\<Rightarrow> bool\" is lsb .\nlift_definition shiftl_uint :: \"uint \\<Rightarrow> nat \\<Rightarrow> uint\" is shiftl .\nlift_definition shiftr_uint :: \"uint \\<Rightarrow> nat \\<Rightarrow> uint\" is shiftr .\nlift_definition msb_uint :: \"uint \\<Rightarrow> bool\" is msb .\ninstance ..\nend\n\ninstantiation uint :: bit_comprehension begin\nlift_definition set_bits_uint :: \"(nat \\<Rightarrow> bool) \\<Rightarrow> uint\" is \"set_bits\" .\ninstance ..\nend\n\nlemmas [code] = test_bit_uint.rep_eq lsb_uint.rep_eq msb_uint.rep_eq\n\ninstantiation uint :: equal begin\nlift_definition equal_uint :: \"uint \\<Rightarrow> uint \\<Rightarrow> bool\" is \"equal_class.equal\" .\ninstance by standard (transfer, simp add: equal_eq)\nend\n\nlemmas [code] = equal_uint.rep_eq\n\ninstantiation uint :: size begin\nlift_definition size_uint :: \"uint \\<Rightarrow> nat\" is \"size\" .\ninstance ..\nend\n\nlemmas [code] = size_uint.rep_eq\n\nlift_definition sshiftr_uint :: \"uint \\<Rightarrow> nat \\<Rightarrow> uint\" (infixl \">>>\" 55) is sshiftr .\n\nlift_definition uint_of_int :: \"int \\<Rightarrow> uint\" is \"word_of_int\" .\n\nlemma of_bool_integer_transfer [transfer_rule]:\n  \"(rel_fun (=) pcr_integer) of_bool of_bool\"\nby(auto simp add: integer.pcr_cr_eq cr_integer_def split: bit.split)\n\ntext \\<open>Use pretty numerals from integer for pretty printing\\<close>\n\ncontext includes integer.lifting begin\n\nlift_definition Uint :: \"integer \\<Rightarrow> uint\" is \"word_of_int\" .\n\nlemma Rep_uint_numeral [simp]: \"Rep_uint (numeral n) = numeral n\"\nby(induction n)(simp_all add: one_uint_def Abs_uint_inverse numeral.simps plus_uint_def)\n\n\n\nlemma numeral_uint [code_unfold]: \"numeral n = Uint (numeral n)\"\nby transfer simp\n\nlemma Rep_uint_neg_numeral [simp]: \"Rep_uint (- numeral n) = - numeral n\"\nby(simp only: uminus_uint_def)(simp add: Abs_uint_inverse)\n\nlemma neg_numeral_uint [code_unfold]: \"- numeral n = Uint (- numeral n)\"\nby transfer(simp add: cr_uint_def)\n\nend\n\nlemma Abs_uint_numeral [code_post]: \"Abs_uint (numeral n) = numeral n\"\nby(induction n)(simp_all add: one_uint_def numeral.simps plus_uint_def Abs_uint_inverse)\n\nlemma Abs_uint_0 [code_post]: \"Abs_uint 0 = 0\"\nby(simp add: zero_uint_def)\n\nlemma Abs_uint_1 [code_post]: \"Abs_uint 1 = 1\"\nby(simp add: one_uint_def)\n\nsection \\<open>Code setup\\<close>\n\ncode_printing code_module Uint \\<rightharpoonup> (SML)\n\\<open>\nstructure Uint : sig\n  val set_bit : Word.word -> IntInf.int -> bool -> Word.word\n  val shiftl : Word.word -> IntInf.int -> Word.word\n  val shiftr : Word.word -> IntInf.int -> Word.word\n  val shiftr_signed : Word.word -> IntInf.int -> Word.word\n  val test_bit : Word.word -> IntInf.int -> bool\nend = struct\n\nfun set_bit x n b =\n  let val mask = Word.<< (0wx1, Word.fromLargeInt (IntInf.toLarge n))\n  in if b then Word.orb (x, mask)\n     else Word.andb (x, Word.notb mask)\n  end\n\nfun shiftl x n =\n  Word.<< (x, Word.fromLargeInt (IntInf.toLarge n))\n\nfun shiftr x n =\n  Word.>> (x, Word.fromLargeInt (IntInf.toLarge n))\n\nfun shiftr_signed x n =\n  Word.~>> (x, Word.fromLargeInt (IntInf.toLarge n))\n\nfun test_bit x n =\n  Word.andb (x, Word.<< (0wx1, Word.fromLargeInt (IntInf.toLarge n))) <> Word.fromInt 0\n\nend; (* struct Uint *)\\<close>\ncode_reserved SML Uint\n\ncode_printing code_module Uint \\<rightharpoonup> (Haskell)\n \\<open>module Uint(Int, Word, dflt_size) where\n\n  import qualified Prelude\n  import Data.Int(Int)\n  import Data.Word(Word)\n  import qualified Data.Bits\n\n  dflt_size :: Prelude.Integer\n  dflt_size = Prelude.toInteger (bitSize_aux (0::Word)) where\n    bitSize_aux :: (Data.Bits.Bits a, Prelude.Bounded a) => a -> Int\n    bitSize_aux = Data.Bits.bitSize\\<close>\n  and (Haskell_Quickcheck)\n \\<open>module Uint(Int, Word, dflt_size) where\n\n  import qualified Prelude\n  import Data.Int(Int)\n  import Data.Word(Word)\n  import qualified Data.Bits\n\n  dflt_size :: Prelude.Int\n  dflt_size = bitSize_aux (0::Word) where\n    bitSize_aux :: (Data.Bits.Bits a, Prelude.Bounded a) => a -> Int\n    bitSize_aux = Data.Bits.bitSize\n\\<close>\ncode_reserved Haskell Uint dflt_size\n\ntext \\<open>\n  OCaml and Scala provide only signed bit numbers, so we use these and \n  implement sign-sensitive operations like comparisons manually.\n\\<close>\n\ncode_printing code_module \"Uint\" \\<rightharpoonup> (OCaml)\n\\<open>module Uint : sig\n  type t = int\n  val dflt_size : Z.t\n  val less : t -> t -> bool\n  val less_eq : t -> t -> bool\n  val set_bit : t -> Z.t -> bool -> t\n  val shiftl : t -> Z.t -> t\n  val shiftr : t -> Z.t -> t\n  val shiftr_signed : t -> Z.t -> t\n  val test_bit : t -> Z.t -> bool\n  val int_mask : int\n  val int32_mask : int32\n  val int64_mask : int64\nend = struct\n\ntype t = int\n\nlet dflt_size = Z.of_int Sys.int_size;;\n\n(* negative numbers have their highest bit set, \n   so they are greater than positive ones *)\nlet less x y =\n  if x<0 then\n    y<0 && x<y\n  else y < 0 || x < y;;\n\nlet less_eq x y =\n  if x < 0 then\n    y < 0 &&  x <= y\n  else y < 0 || x <= y;;\n\nlet set_bit x n b =\n  let mask = 1 lsl (Z.to_int n)\n  in if b then x lor mask\n     else x land (lnot mask);;\n\nlet shiftl x n = x lsl (Z.to_int n);;\n\nlet shiftr x n = x lsr (Z.to_int n);;\n\nlet shiftr_signed x n = x asr (Z.to_int n);;\n\nlet test_bit x n = x land (1 lsl (Z.to_int n)) <> 0;;\n\nlet int_mask =\n  if Sys.int_size < 32 then lnot 0 else 0xFFFFFFFF;;\n\nlet int32_mask = \n  if Sys.int_size < 32 then Int32.pred (Int32.shift_left Int32.one Sys.int_size)\n  else Int32.of_string \"0xFFFFFFFF\";;\n\nlet int64_mask = \n  if Sys.int_size < 64 then Int64.pred (Int64.shift_left Int64.one Sys.int_size)\n  else Int64.of_string \"0xFFFFFFFFFFFFFFFF\";;\n\nend;; (*struct Uint*)\\<close>\ncode_reserved OCaml Uint\n\ncode_printing code_module Uint \\<rightharpoonup> (Scala)\n\\<open>object Uint {\ndef dflt_size : BigInt = BigInt(32)\n\ndef less(x: Int, y: Int) : Boolean =\n  if (x < 0) y < 0 && x < y\n  else y < 0 || x < y\n\ndef less_eq(x: Int, y: Int) : Boolean =\n  if (x < 0) y < 0 && x <= y\n  else y < 0 || x <= y\n\ndef set_bit(x: Int, n: BigInt, b: Boolean) : Int =\n  if (b)\n    x | (1 << n.intValue)\n  else\n    x & (1 << n.intValue).unary_~\n\ndef shiftl(x: Int, n: BigInt) : Int = x << n.intValue\n\ndef shiftr(x: Int, n: BigInt) : Int = x >>> n.intValue\n\ndef shiftr_signed(x: Int, n: BigInt) : Int = x >> n.intValue\n\ndef test_bit(x: Int, n: BigInt) : Boolean =\n  (x & (1 << n.intValue)) != 0\n\n} /* object Uint */\\<close>\ncode_reserved Scala Uint\n\n\ntext \\<open>\n  OCaml's conversion from Big\\_int to int demands that the value fits into a signed integer.\n  The following justifies the implementation.\n\\<close>\n\ncontext includes integer.lifting begin\ndefinition wivs_mask :: int where \"wivs_mask = 2^ dflt_size - 1\"\nlift_definition wivs_mask_integer :: integer is wivs_mask .\n\n\ndefinition wivs_shift :: int where \"wivs_shift = 2 ^ dflt_size\"\nlift_definition wivs_shift_integer :: integer is wivs_shift .\nlemma [code]: \"wivs_shift_integer = 2 ^ dflt_size\"\n  by transfer (simp add: wivs_shift_def)\n\ndefinition wivs_index :: nat where \"wivs_index == dflt_size - 1\"\nlift_definition wivs_index_integer :: integer is \"int wivs_index\".\nlemma wivs_index_integer_code[code]: \"wivs_index_integer = dflt_size_integer - 1\"\n  by transfer (simp add: wivs_index_def of_nat_diff)\n\ndefinition wivs_overflow :: int where \"wivs_overflow == 2^ (dflt_size - 1)\"\nlift_definition wivs_overflow_integer :: integer is wivs_overflow .\nlemma [code]: \"wivs_overflow_integer = 2 ^ (dflt_size - 1)\"\n  by transfer (simp add: wivs_overflow_def)\n\ndefinition wivs_least :: int where \"wivs_least == - wivs_overflow\"\nlift_definition wivs_least_integer :: integer is wivs_least .\nlemma [code]: \"wivs_least_integer = - (2 ^ (dflt_size - 1))\"\n  by transfer (simp add: wivs_overflow_def wivs_least_def)\n\ndefinition Uint_signed :: \"integer \\<Rightarrow> uint\" where\n  \"Uint_signed i = (if i < wivs_least_integer \\<or> wivs_overflow_integer \\<le> i then undefined Uint i else Uint i)\"\n\nlemma Uint_code [code]:\n  \"Uint i = \n  (let i' = i AND wivs_mask_integer in \n   if i' !! wivs_index then Uint_signed (i' - wivs_shift_integer) else Uint_signed i')\"\n  including undefined_transfer \n  unfolding Uint_signed_def\n  apply transfer\n  apply (rule word_of_int_via_signed)\n  by (simp_all add: wivs_mask_def wivs_shift_def wivs_index_def wivs_overflow_def \n    wivs_least_def bin_mask_conv_pow2 shiftl_int_def)\n\nlemma Uint_signed_code [code abstract]:\n  \"Rep_uint (Uint_signed i) = \n  (if i < wivs_least_integer \\<or> i \\<ge> wivs_overflow_integer then Rep_uint (undefined Uint i) else word_of_int (int_of_integer_symbolic i))\"\n  unfolding Uint_signed_def Uint_def int_of_integer_symbolic_def word_of_integer_def\n  by(simp add: Abs_uint_inverse)\nend\n\ntext \\<open>\n  Avoid @{term Abs_uint} in generated code, use @{term Rep_uint'} instead. \n  The symbolic implementations for code\\_simp use @{term Rep_uint}.\n\n  The new destructor @{term Rep_uint'} is executable.\n  As the simplifier is given the [code abstract] equations literally, \n  we cannot implement @{term Rep_uint} directly, because that makes code\\_simp loop.\n\n  If code generation raises Match, some equation probably contains @{term Rep_uint} \n  ([code abstract] equations for @{typ uint} may use @{term Rep_uint} because\n  these instances will be folded away.)\n\\<close>\n\ndefinition Rep_uint' where [simp]: \"Rep_uint' = Rep_uint\"\n\nlemma Rep_uint'_code [code]: \"Rep_uint' x = (BITS n. x !! n)\"\nunfolding Rep_uint'_def by transfer simp\n\nlift_definition Abs_uint' :: \"dflt_size word \\<Rightarrow> uint\" is \"\\<lambda>x :: dflt_size word. x\" .\n\nlemma Abs_uint'_code [code]:\n  \"Abs_uint' x = Uint (integer_of_int (uint x))\"\nincluding integer.lifting by transfer simp\n\ndeclare [[code drop: \"term_of_class.term_of :: uint \\<Rightarrow> _\"]]\n\nlemma term_of_uint_code [code]:\n  defines \"TR \\<equiv> typerep.Typerep\" and \"bit0 \\<equiv> STR ''Numeral_Type.bit0''\" \n  shows\n  \"term_of_class.term_of x = \n   Code_Evaluation.App (Code_Evaluation.Const (STR ''Uint.uint.Abs_uint'') (TR (STR ''fun'') [TR (STR ''Word.word'')  [TR (STR ''Uint.dflt_size'') []], TR (STR ''Uint.uint'') []]))\n       (term_of_class.term_of (Rep_uint' x))\"\n  by(simp add: term_of_anything)\n\ntext \\<open>Important:\n  We must prevent the reflection oracle (eval-tac) to \n  use our machine-dependent type.\n\\<close>\n\ncode_printing\n  type_constructor uint \\<rightharpoonup>\n  (SML) \"Word.word\" and\n  (Haskell) \"Uint.Word\" and\n  (OCaml) \"Uint.t\" and\n  (Scala) \"Int\" and\n  (Eval) \"*** \\\"Error: Machine dependent type\\\" ***\" and\n  (Quickcheck) \"Word.word\" \n| constant dflt_size_integer \\<rightharpoonup>\n  (SML) \"(IntInf.fromLarge (Int.toLarge Word.wordSize))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.wordSize\" and\n  (Haskell) \"Uint.dflt'_size\" and\n  (OCaml) \"Uint.dflt'_size\" and\n  (Scala) \"Uint.dflt'_size\"\n| constant Uint \\<rightharpoonup>\n  (SML) \"Word.fromLargeInt (IntInf.toLarge _)\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.fromInt\" and\n  (Haskell) \"(Prelude.fromInteger _ :: Uint.Word)\" and\n  (Haskell_Quickcheck) \"(Prelude.fromInteger (Prelude.toInteger _) :: Uint.Word)\" and\n  (Scala) \"_.intValue\"\n| constant Uint_signed \\<rightharpoonup>\n  (OCaml) \"Z.to'_int\"\n| constant \"0 :: uint\" \\<rightharpoonup>\n  (SML) \"(Word.fromInt 0)\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"(Word.fromInt 0)\" and\n  (Haskell) \"(0 :: Uint.Word)\" and\n  (OCaml) \"0\" and\n  (Scala) \"0\"\n| constant \"1 :: uint\" \\<rightharpoonup>\n  (SML) \"(Word.fromInt 1)\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"(Word.fromInt 1)\" and\n  (Haskell) \"(1 :: Uint.Word)\" and\n  (OCaml) \"1\" and\n  (Scala) \"1\"\n| constant \"plus :: uint \\<Rightarrow> _ \" \\<rightharpoonup>\n  (SML) \"Word.+ ((_), (_))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.+ ((_), (_))\" and\n  (Haskell) infixl 6 \"+\" and\n  (OCaml) \"Pervasives.(+)\" and\n  (Scala) infixl 7 \"+\"\n| constant \"uminus :: uint \\<Rightarrow> _\" \\<rightharpoonup>\n  (SML) \"Word.~\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.~\" and\n  (Haskell) \"negate\" and\n  (OCaml) \"Pervasives.(~-)\" and\n  (Scala) \"!(- _)\"\n| constant \"minus :: uint \\<Rightarrow> _\" \\<rightharpoonup>\n  (SML) \"Word.- ((_), (_))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.- ((_), (_))\" and\n  (Haskell) infixl 6 \"-\" and\n  (OCaml) \"Pervasives.(-)\" and\n  (Scala) infixl 7 \"-\"\n| constant \"times :: uint \\<Rightarrow> _ \\<Rightarrow> _\" \\<rightharpoonup>\n  (SML) \"Word.* ((_), (_))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.* ((_), (_))\" and\n  (Haskell) infixl 7 \"*\" and\n  (OCaml) \"Pervasives.( * )\" and\n  (Scala) infixl 8 \"*\"\n| constant \"HOL.equal :: uint \\<Rightarrow> _ \\<Rightarrow> bool\" \\<rightharpoonup>\n  (SML) \"!((_ : Word.word) = _)\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"!((_ : Word.word) = _)\" and\n  (Haskell) infix 4 \"==\" and\n  (OCaml) \"(Pervasives.(=):Uint.t -> Uint.t -> bool)\" and\n  (Scala) infixl 5 \"==\"\n| class_instance uint :: equal \\<rightharpoonup>\n  (Haskell) -\n| constant \"less_eq :: uint \\<Rightarrow> _ \\<Rightarrow> bool\" \\<rightharpoonup>\n  (SML) \"Word.<= ((_), (_))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.<= ((_), (_))\" and\n  (Haskell) infix 4 \"<=\" and\n  (OCaml) \"Uint.less'_eq\" and\n  (Scala) \"Uint.less'_eq\"\n| constant \"less :: uint \\<Rightarrow> _ \\<Rightarrow> bool\" \\<rightharpoonup>\n  (SML) \"Word.< ((_), (_))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.< ((_), (_))\" and\n  (Haskell) infix 4 \"<\" and\n  (OCaml) \"Uint.less\" and\n  (Scala) \"Uint.less\"\n| constant \"bitNOT :: uint \\<Rightarrow> _\" \\<rightharpoonup>\n  (SML) \"Word.notb\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.notb\" and\n  (Haskell) \"Data'_Bits.complement\" and\n  (OCaml) \"Pervasives.lnot\" and\n  (Scala) \"_.unary'_~\"\n| constant \"bitAND :: uint \\<Rightarrow> _\" \\<rightharpoonup>\n  (SML) \"Word.andb ((_),/ (_))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.andb ((_),/ (_))\" and\n  (Haskell) infixl 7 \"Data_Bits..&.\" and\n  (OCaml) \"Pervasives.(land)\" and\n  (Scala) infixl 3 \"&\"\n| constant \"bitOR :: uint \\<Rightarrow> _\" \\<rightharpoonup>\n  (SML) \"Word.orb ((_),/ (_))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.orb ((_),/ (_))\" and\n  (Haskell) infixl 5 \"Data_Bits..|.\" and\n  (OCaml) \"Pervasives.(lor)\" and\n  (Scala) infixl 1 \"|\"\n| constant \"bitXOR :: uint \\<Rightarrow> _\" \\<rightharpoonup>\n  (SML) \"Word.xorb ((_),/ (_))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.xorb ((_),/ (_))\" and\n  (Haskell) \"Data'_Bits.xor\" and\n  (OCaml) \"Pervasives.(lxor)\" and\n  (Scala) infixl 2 \"^\"\n\ndefinition uint_divmod :: \"uint \\<Rightarrow> uint \\<Rightarrow> uint \\<times> uint\" where\n  \"uint_divmod x y = \n  (if y = 0 then (undefined ((div) :: uint \\<Rightarrow> _) x (0 :: uint), undefined ((mod) :: uint \\<Rightarrow> _) x (0 :: uint)) \n  else (x div y, x mod y))\"\n\ndefinition uint_div :: \"uint \\<Rightarrow> uint \\<Rightarrow> uint\" \nwhere \"uint_div x y = fst (uint_divmod x y)\"\n\ndefinition uint_mod :: \"uint \\<Rightarrow> uint \\<Rightarrow> uint\" \nwhere \"uint_mod x y = snd (uint_divmod x y)\"\n\nlemma div_uint_code [code]: \"x div y = (if y = 0 then 0 else uint_div x y)\"\nincluding undefined_transfer unfolding uint_divmod_def uint_div_def\nby transfer(simp add: word_div_def)\n\nlemma mod_uint_code [code]: \"x mod y = (if y = 0 then x else uint_mod x y)\"\nincluding undefined_transfer unfolding uint_mod_def uint_divmod_def\nby transfer(simp add: word_mod_def)\n\ndefinition uint_sdiv :: \"uint \\<Rightarrow> uint \\<Rightarrow> uint\"\nwhere [code del]:\n  \"uint_sdiv x y =\n   (if y = 0 then undefined ((div) :: uint \\<Rightarrow> _) x (0 :: uint)\n    else Abs_uint (Rep_uint x sdiv Rep_uint y))\"\n\ndefinition div0_uint :: \"uint \\<Rightarrow> uint\"\nwhere [code del]: \"div0_uint x = undefined ((div) :: uint \\<Rightarrow> _) x (0 :: uint)\"\ndeclare [[code abort: div0_uint]]\n\ndefinition mod0_uint :: \"uint \\<Rightarrow> uint\"\nwhere [code del]: \"mod0_uint x = undefined ((mod) :: uint \\<Rightarrow> _) x (0 :: uint)\"\ndeclare [[code abort: mod0_uint]]\n\ndefinition wivs_overflow_uint :: uint \n  where \"wivs_overflow_uint \\<equiv> 1 << (dflt_size - 1)\"\n\n(* TODO: Move to Word *)\nlemma dflt_size_word_pow_ne_zero [simp]:\n  \"(2 :: 'a word) ^ (LENGTH('a::len) - Suc 0) \\<noteq> 0\"\nproof\n  assume \"(2 :: 'a word) ^ (LENGTH('a::len) - Suc 0) = 0\"\n  then have \"unat ((2 :: 'a word) ^ (LENGTH('a::len) - Suc 0)) = unat 0\"\n    by simp\n  then show False by (simp add: unat_p2)\nqed\n\nlemma uint_divmod_code [code]:\n  \"uint_divmod x y =\n  (if wivs_overflow_uint \\<le> y then if x < y then (0, x) else (1, x - y)\n   else if y = 0 then (div0_uint x, mod0_uint x)\n   else let q = (uint_sdiv (x >> 1) y) << 1;\n            r = x - q * y\n        in if r \\<ge> y then (q + 1, r - y) else (q, r))\"\n  including undefined_transfer \n  unfolding uint_divmod_def uint_sdiv_def div0_uint_def mod0_uint_def\n    wivs_overflow_uint_def\n  by transfer (simp add: divmod_via_sdivmod)\n\nlemma uint_sdiv_code [code abstract]:\n  \"Rep_uint (uint_sdiv x y) =\n   (if y = 0 then Rep_uint (undefined ((div) :: uint \\<Rightarrow> _) x (0 :: uint))\n    else Rep_uint x sdiv Rep_uint y)\"\nunfolding uint_sdiv_def by(simp add: Abs_uint_inverse)\n\ntext \\<open>\n  Note that we only need a translation for signed division, but not for the remainder\n  because @{thm uint_divmod_code} computes both with division only.\n\\<close>\n\ncode_printing\n  constant uint_div \\<rightharpoonup>\n  (SML) \"Word.div ((_), (_))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.div ((_), (_))\" and\n  (Haskell) \"Prelude.div\"\n| constant uint_mod \\<rightharpoonup>\n  (SML) \"Word.mod ((_), (_))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.mod ((_), (_))\" and\n  (Haskell) \"Prelude.mod\"\n| constant uint_divmod \\<rightharpoonup>\n  (Haskell) \"divmod\"\n| constant uint_sdiv \\<rightharpoonup>\n  (OCaml) \"Pervasives.('/)\" and\n  (Scala) \"_ '/ _\"\n\ndefinition uint_test_bit :: \"uint \\<Rightarrow> integer \\<Rightarrow> bool\"\nwhere [code del]:\n  \"uint_test_bit x n =\n  (if n < 0 \\<or> dflt_size_integer \\<le> n then undefined (test_bit :: uint \\<Rightarrow> _) x n\n   else x !! (nat_of_integer n))\"\n\nlemma test_bit_uint_code [code]:\n  \"test_bit x n \\<longleftrightarrow> n < dflt_size \\<and> uint_test_bit x (integer_of_nat n)\"\n  including undefined_transfer integer.lifting unfolding uint_test_bit_def\n  by transfer (auto cong: conj_cong dest: test_bit_size simp add: word_size)\n\nlemma uint_test_bit_code [code]:\n  \"uint_test_bit w n =\n  (if n < 0 \\<or> dflt_size_integer \\<le> n then undefined (test_bit :: uint \\<Rightarrow> _) w n else Rep_uint w !! nat_of_integer n)\"\nunfolding uint_test_bit_def\nby(simp add: test_bit_uint.rep_eq)\n\ncode_printing constant uint_test_bit \\<rightharpoonup>\n  (SML) \"Uint.test'_bit\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Uint.test'_bit\" and\n  (Haskell) \"Data'_Bits.testBitBounded\" and\n  (OCaml) \"Uint.test'_bit\" and\n  (Scala) \"Uint.test'_bit\"\n\ndefinition uint_set_bit :: \"uint \\<Rightarrow> integer \\<Rightarrow> bool \\<Rightarrow> uint\"\nwhere [code del]:\n  \"uint_set_bit x n b =\n  (if n < 0 \\<or> dflt_size_integer \\<le> n then undefined (set_bit :: uint \\<Rightarrow> _) x n b\n   else set_bit x (nat_of_integer n) b)\"\n\nlemma set_bit_uint_code [code]:\n  \"set_bit x n b = (if n < dflt_size then uint_set_bit x (integer_of_nat n) b else x)\"\n  including undefined_transfer integer.lifting unfolding uint_set_bit_def\n  by (transfer) (auto cong: conj_cong simp add: not_less set_bit_beyond word_size)\n\nlemma uint_set_bit_code [code abstract]:\n  \"Rep_uint (uint_set_bit w n b) = \n  (if n < 0 \\<or> dflt_size_integer \\<le> n then Rep_uint (undefined (set_bit :: uint \\<Rightarrow> _) w n b)\n   else set_bit (Rep_uint w) (nat_of_integer n) b)\"\nincluding undefined_transfer integer.lifting unfolding uint_set_bit_def by transfer simp\n\ncode_printing constant uint_set_bit \\<rightharpoonup>\n  (SML) \"Uint.set'_bit\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Uint.set'_bit\" and\n  (Haskell) \"Data'_Bits.setBitBounded\" and\n  (OCaml) \"Uint.set'_bit\" and\n  (Scala) \"Uint.set'_bit\"\n\nlift_definition uint_set_bits :: \"(nat \\<Rightarrow> bool) \\<Rightarrow> uint \\<Rightarrow> nat \\<Rightarrow> uint\" is set_bits_aux .\n\nlemma uint_set_bits_code [code]:\n  \"uint_set_bits f w n =\n  (if n = 0 then w \n   else let n' = n - 1 in uint_set_bits f ((w << 1) OR (if f n' then 1 else 0)) n')\"\nby(transfer fixing: n)(cases n, simp_all)\n\nlemma set_bits_uint [code]:\n  \"(BITS n. f n) = uint_set_bits f 0 dflt_size\"\n  by transfer (simp add: set_bits_conv_set_bits_aux)\n\nlemma lsb_code [code]: fixes x :: uint shows \"lsb x = x !! 0\"\nby transfer(simp add: word_lsb_def word_test_bit_def)\n\ndefinition uint_shiftl :: \"uint \\<Rightarrow> integer \\<Rightarrow> uint\"\nwhere [code del]:\n  \"uint_shiftl x n = (if n < 0 \\<or> dflt_size_integer \\<le> n then undefined (shiftl :: uint \\<Rightarrow> _) x n else x << (nat_of_integer n))\"\n\nlemma shiftl_uint_code [code]: \"x << n = (if n < dflt_size then uint_shiftl x (integer_of_nat n) else 0)\"\nincluding undefined_transfer integer.lifting unfolding uint_shiftl_def\nby transfer(simp add: not_less shiftl_zero_size word_size)\n\nlemma uint_shiftl_code [code abstract]:\n  \"Rep_uint (uint_shiftl w n) =\n  (if n < 0 \\<or> dflt_size_integer \\<le> n then Rep_uint (undefined (shiftl :: uint \\<Rightarrow> _) w n) else Rep_uint w << (nat_of_integer n))\"\nincluding undefined_transfer integer.lifting unfolding uint_shiftl_def by transfer simp\n\ncode_printing constant uint_shiftl \\<rightharpoonup>\n  (SML) \"Uint.shiftl\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Uint.shiftl\" and\n  (Haskell) \"Data'_Bits.shiftlBounded\" and\n  (OCaml) \"Uint.shiftl\" and\n  (Scala) \"Uint.shiftl\"\n\ndefinition uint_shiftr :: \"uint \\<Rightarrow> integer \\<Rightarrow> uint\"\nwhere [code del]:\n  \"uint_shiftr x n = (if n < 0 \\<or> dflt_size_integer \\<le> n then undefined (shiftr :: uint \\<Rightarrow> _) x n else x >> (nat_of_integer n))\"\n\nlemma shiftr_uint_code [code]: \"x >> n = (if n < dflt_size then uint_shiftr x (integer_of_nat n) else 0)\"\nincluding undefined_transfer integer.lifting unfolding uint_shiftr_def\nby transfer(simp add: not_less shiftr_zero_size word_size)\n\nlemma uint_shiftr_code [code abstract]:\n  \"Rep_uint (uint_shiftr w n) =\n  (if n < 0 \\<or> dflt_size_integer \\<le> n then Rep_uint (undefined (shiftr :: uint \\<Rightarrow> _) w n) else Rep_uint w >> nat_of_integer n)\"\nincluding undefined_transfer unfolding uint_shiftr_def by transfer simp\n\ncode_printing constant uint_shiftr \\<rightharpoonup>\n  (SML) \"Uint.shiftr\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Uint.shiftr\" and\n  (Haskell) \"Data'_Bits.shiftrBounded\" and\n  (OCaml) \"Uint.shiftr\" and\n  (Scala) \"Uint.shiftr\"\n\ndefinition uint_sshiftr :: \"uint \\<Rightarrow> integer \\<Rightarrow> uint\"\nwhere [code del]:\n  \"uint_sshiftr x n =\n  (if n < 0 \\<or> dflt_size_integer \\<le> n then undefined sshiftr_uint x n else sshiftr_uint x (nat_of_integer n))\"\n\nlemma sshiftr_beyond: fixes x :: \"'a :: len word\" shows\n  \"size x \\<le> n \\<Longrightarrow> x >>> n = (if x !! (size x - 1) then -1 else 0)\"\nby(rule word_eqI)(simp add: nth_sshiftr word_size)\n\nlemma sshiftr_uint_code [code]:\n  \"x >>> n = \n  (if n < dflt_size then uint_sshiftr x (integer_of_nat n) else \n    if x !! wivs_index then -1 else 0)\"\nincluding undefined_transfer integer.lifting unfolding uint_sshiftr_def\nby transfer(simp add: not_less sshiftr_beyond word_size wivs_index_def)\n\nlemma uint_sshiftr_code [code abstract]:\n  \"Rep_uint (uint_sshiftr w n) =\n  (if n < 0 \\<or> dflt_size_integer \\<le> n then Rep_uint (undefined sshiftr_uint w n) else Rep_uint w >>> (nat_of_integer n))\"\nincluding undefined_transfer unfolding uint_sshiftr_def by transfer simp\n\ncode_printing constant uint_sshiftr \\<rightharpoonup>\n  (SML) \"Uint.shiftr'_signed\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Uint.shiftr'_signed\" and\n  (Haskell) \n    \"(Prelude.fromInteger (Prelude.toInteger (Data'_Bits.shiftrBounded (Prelude.fromInteger (Prelude.toInteger _) :: Uint.Int) _)) :: Uint.Word)\" and\n  (OCaml) \"Uint.shiftr'_signed\" and\n  (Scala) \"Uint.shiftr'_signed\"\n\nlemma uint_msb_test_bit: \"msb x \\<longleftrightarrow> (x :: uint) !! wivs_index\"\nby transfer(simp add: msb_nth wivs_index_def)\n\nlemma msb_uint_code [code]: \"msb x \\<longleftrightarrow> uint_test_bit x wivs_index_integer\"\n  apply(simp add: uint_test_bit_def uint_msb_test_bit \n  wivs_index_integer_code dflt_size_integer_def wivs_index_def)\n  by (metis (full_types) One_nat_def dflt_size(2) less_iff_diff_less_0 \n    nat_of_integer_of_nat of_nat_1 of_nat_diff of_nat_less_0_iff wivs_index_def)\n\nlemma uint_of_int_code [code]: \"uint_of_int i = (BITS n. i !! n)\"\nby transfer(simp add: word_of_int_conv_set_bits test_bit_int_def[abs_def])\n\nsection \\<open>Quickcheck setup\\<close>\n\ndefinition uint_of_natural :: \"natural \\<Rightarrow> uint\"\nwhere \"uint_of_natural x \\<equiv> Uint (integer_of_natural x)\"\n\ninstantiation uint :: \"{random, exhaustive, full_exhaustive}\" begin\ndefinition \"random_uint \\<equiv> qc_random_cnv uint_of_natural\"\ndefinition \"exhaustive_uint \\<equiv> qc_exhaustive_cnv uint_of_natural\"\ndefinition \"full_exhaustive_uint \\<equiv> qc_full_exhaustive_cnv uint_of_natural\"\ninstance ..\nend\n\ninstantiation uint :: narrowing begin\n\ninterpretation quickcheck_narrowing_samples\n  \"\\<lambda>i. (Uint i, Uint (- i))\" \"0\"\n  \"Typerep.Typerep (STR ''Uint.uint'') []\" .\n\ndefinition \"narrowing_uint d = qc_narrowing_drawn_from (narrowing_samples d) d\"\ndeclare [[code drop: \"partial_term_of :: uint itself \\<Rightarrow> _\"]]\nlemmas partial_term_of_uint [code] = partial_term_of_code\n\ninstance ..\nend\n\nno_notation sshiftr_uint (infixl \">>>\" 55)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Evaluation/Native_Word/Uint.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297746074044133, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.27573012226707294}}
{"text": "section {*FUNCTION\\_\\_DPDA\\_RMPE\\_\\_DPDA\\_REMOVE\\_MASS\\_PUSHING\\_EDGES*}\ntheory\n  FUNCTION__DPDA_RMPE__DPDA_REMOVE_MASS_PUSHING_EDGES\n\nimports\n  PRJ_12_04_04_04__ENTRY\n\nbegin\n\ndefinition mass_push_edges_splitted :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"mass_push_edges_splitted G \\<equiv>\n  \\<not> (\\<exists>e \\<in> epda_delta G. F_DPDA_RMPUE__edge_if e)\"\n\ndefinition mass_push_edges_splitted_ALT :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"mass_push_edges_splitted_ALT G \\<equiv>\n  \\<not> (\\<exists>e \\<in> epda_delta G. length (edge_push e) > 2)\"\n\nlemma mass_push_edges_splitted_ALT_vs_mass_push_edges_splitted: \"\n  mass_push_edges_splitted_ALT G = mass_push_edges_splitted G\"\n  apply(simp add: F_DPDA_RMPUE__edge_if_def mass_push_edges_splitted_ALT_def mass_push_edges_splitted_def)\n  apply(force)\n  done\n\ndefinition F_DPDA_RMPUE__edge_else__RL :: \"\n  (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda_step_label\n  \\<Rightarrow> ('state, 'event, 'stack) epda_step_label\"\n  where\n    \"F_DPDA_RMPUE__edge_else__RL e \\<equiv>\n  \\<lparr>edge_src = case edge_src e of cons_state_or_edge_nat_old q \\<Rightarrow> q,\n  edge_event = edge_event e,\n  edge_pop = edge_pop e,\n  edge_push = edge_push e,\n  edge_trg = case edge_trg e of cons_state_or_edge_nat_old q \\<Rightarrow> q\\<rparr>\"\n\ndefinition F_DPDA_RMPUE__edge_then_i_th__LR :: \"\n  ('state, 'event, 'stack) epda_step_label\n  \\<Rightarrow> nat\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda_step_label option\"\n  where\n    \"F_DPDA_RMPUE__edge_then_i_th__LR e i \\<equiv>\n  if i = 0\n  then None\n  else Some \\<lparr>edge_src = the (F_DPDA_RMPUE__state e (i - Suc 0)),\n            edge_event = None,\n            edge_pop = [(rev (edge_push e)) ! (i-Suc 0)],\n            edge_push = [(rev (edge_push e)) !i] @ [(rev (edge_push e)) ! (i-Suc 0)],\n            edge_trg = the (F_DPDA_RMPUE__state e i)\\<rparr>\"\n\ndefinition F_DPDA_RMPUE__conf_i_th__LR :: \"\n  (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack) epda_step_label\n  \\<Rightarrow> nat\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epdaS_conf option\"\n  where\n    \"F_DPDA_RMPUE__conf_i_th__LR c e i \\<equiv>\n  if i<length (edge_push e)\n  then Some \\<lparr>epdaS_conf_state = the (F_DPDA_RMPUE__state e i),\n            epdaS_conf_scheduler = epdaS_conf_scheduler c,\n            epdaS_conf_stack =\n                (if i = 0\n                then edge_pop e\n                else drop (length (edge_push e) - (Suc i)) (edge_push e))\n                @ tl (epdaS_conf_stack c)\\<rparr>\n  else None\"\n\ndefinition F_DPDA_RMPUE__conf_old__LR :: \"\n  ('state, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epdaS_conf\"\n  where\n    \"F_DPDA_RMPUE__conf_old__LR c \\<equiv>\n  \\<lparr>epdaS_conf_state = cons_state_or_edge_nat_old (epdaS_conf_state c),\n  epdaS_conf_scheduler = epdaS_conf_scheduler c,\n  epdaS_conf_stack = epdaS_conf_stack c\\<rparr>\"\n\ndefinition F_DPDA_RMPUE__conf_old__LR_rev :: \"\n  (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack) epdaS_conf\"\n  where\n    \"F_DPDA_RMPUE__conf_old__LR_rev c \\<equiv>\n  case epdaS_conf_state c of cons_state_or_edge_nat_old q\n  \\<Rightarrow> \\<lparr>epdaS_conf_state = q,\n    epdaS_conf_scheduler = epdaS_conf_scheduler c,\n    epdaS_conf_stack = epdaS_conf_stack c\\<rparr>\n  | cons_state_or_edge_nat_new e n\n  \\<Rightarrow> \\<lparr>epdaS_conf_state = edge_trg e,\n    epdaS_conf_scheduler = epdaS_conf_scheduler c,\n    epdaS_conf_stack = take (length (edge_push e) - Suc n) (edge_push e) @ epdaS_conf_stack c\\<rparr>\"\n\nlemma F_DPDA_RMPUE__preserves_epda: \"\n  valid_dpda G\n  \\<Longrightarrow> valid_epda (F_DPDA_RMPUE G)\"\n  apply(simp add: valid_epda_def F_DPDA_RMPUE_def)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(rule finite_imageI)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rule conjI)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   apply(rule finite_imageI)\n   apply (metis finite_less_ub le_SucI le_refl)\n  apply(rule conjI)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rule conjI)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rule conjI)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   apply(simp only: F_DPDA_RMPUE__edge_then_def)\n   apply(rule finite_big_union2)\n    apply(rename_tac x)(*strict*)\n    apply(clarsimp)\n    apply(rule_tac\n      s=\"(\\<exists>m. \\<forall>n\\<in> N. n < m)\" for N\n      in ssubst)\n     apply(rename_tac x)(*strict*)\n     apply(rule finite_nat_set_iff_bounded)\n    apply(rename_tac x)(*strict*)\n    apply(rule_tac\n      x=\"length(edge_push x)\"\n      in exI)\n    apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   apply(clarsimp)\n  apply(rule conjI)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rule conjI)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rule conjI)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(blast)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(simp add: F_DPDA_RMPUE__edge_else_def)\n   apply(clarsimp)\n   apply(rename_tac xa)(*strict*)\n   apply(subgoal_tac \"valid_epda_step_label G xa\")\n    apply(rename_tac xa)(*strict*)\n    prefer 2\n    apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac xa)(*strict*)\n   apply(simp add: valid_epda_step_label_def)\n  apply(rename_tac x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x xa)(*strict*)\n  apply(subgoal_tac \"valid_epda_step_label G xa\")\n   apply(rename_tac x xa)(*strict*)\n   prefer 2\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rename_tac x xa)(*strict*)\n  apply(simp add: valid_epda_step_label_def)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RMPUE__edge_then_def)\n  apply(clarsimp)\n  apply(rename_tac xa xb)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac xa xb)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__state_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"xa\"\n      in ballE)\n    apply(rename_tac xa xb)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac xa xb)(*strict*)\n   apply(subgoal_tac \"cons_state_or_edge_nat_new xa xb \\<in> (\\<lambda>i. the (if i = 0 then Some (cons_state_or_edge_nat_old (edge_src xa)) else if Suc i < length (edge_push xa) then Some (cons_state_or_edge_nat_new xa i) else if Suc i = length (edge_push xa) then Some (cons_state_or_edge_nat_old (edge_trg xa)) else None)) ` {i. Suc i \\<le> length (edge_push xa)}\")\n    apply(rename_tac xa xb)(*strict*)\n    apply(force)\n   apply(rename_tac xa xb)(*strict*)\n   apply(rule inMap)\n   apply(rule_tac\n      x=\"xb\"\n      in bexI)\n    apply(rename_tac xa xb)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac xa xb)(*strict*)\n   apply(force)\n  apply(rename_tac xa xb)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac xa xb)(*strict*)\n   apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G. the (F_DPDA_RMPUE__state xa (Suc xb)) \\<in> (\\<lambda>i. the (F_DPDA_RMPUE__state x i)) ` {i. Suc i \\<le> length (edge_push x)})\")\n    apply(rename_tac xa xb)(*strict*)\n    prefer 2\n    apply(rule_tac\n      x=\"xa\"\n      in bexI)\n     apply(rename_tac xa xb)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac xa xb)(*strict*)\n    apply(rule inMap)\n    apply(rule_tac\n      x=\"Suc xb\"\n      in bexI)\n     apply(rename_tac xa xb)(*strict*)\n     apply(force)\n    apply(rename_tac xa xb)(*strict*)\n    apply(force)\n   apply(rename_tac xa xb)(*strict*)\n   apply(force)\n  apply(rename_tac xa xb)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac xa xb)(*strict*)\n   apply(simp add: suffix_def option_to_set_def)\n  apply(rename_tac xa xb)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__edge_if_def)\n  apply(subgoal_tac \"set(edge_push xa)\\<subseteq> epda_gamma G\")\n   apply(rename_tac xa xb)(*strict*)\n   prefer 2\n   apply(rule valid_epda_push_in_gamma)\n    apply(rename_tac xa xb)(*strict*)\n    apply(simp add: valid_dpda_def valid_pda_def)\n   apply(rename_tac xa xb)(*strict*)\n   apply(force)\n  apply(rename_tac xa xb)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac xa xb)(*strict*)\n   apply(simp add: may_terminated_by_def kleene_star_def append_language_def F_DPDA_RMPUE__edge_if_def)\n   apply(clarsimp)\n   apply(rename_tac xa xb a aa)(*strict*)\n   apply(case_tac \"rev (edge_push xa) ! xb = epda_box G\")\n    apply(rename_tac xa xb a aa)(*strict*)\n    apply(clarsimp)\n    apply(rule_tac\n      x=\"[]\"\n      in exI)\n    apply(force)\n   apply(rename_tac xa xb a aa)(*strict*)\n   apply(clarsimp)\n   apply(rule_tac\n      A=\"set (edge_push xa)\"\n      in set_mp)\n    apply(rename_tac xa xb a aa)(*strict*)\n    apply(force)\n   apply(rename_tac xa xb a aa)(*strict*)\n   apply(rule rev_nth_in_set)\n   apply(force)\n  apply(rename_tac xa xb)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac xa xb)(*strict*)\n   apply(simp add: may_terminated_by_def kleene_star_def append_language_def F_DPDA_RMPUE__edge_if_def)\n   apply(clarsimp)\n   apply(rename_tac xa xb a aa)(*strict*)\n   apply(case_tac \"rev (edge_push xa) ! xb = epda_box G\")\n    apply(rename_tac xa xb a aa)(*strict*)\n    apply(clarsimp)\n    apply(rule_tac\n      x=\"[rev (edge_push xa) ! Suc xb]\"\n      in exI)\n    apply(clarsimp)\n    apply(rule conjI)\n     apply(rename_tac xa xb a aa)(*strict*)\n     apply(rule_tac\n      A=\"set (edge_push xa)\"\n      in set_mp)\n      apply(rename_tac xa xb a aa)(*strict*)\n      apply(force)\n     apply(rename_tac xa xb a aa)(*strict*)\n     apply(rule rev_nth_in_set)\n     apply(force)\n    apply(rename_tac xa xb a aa)(*strict*)\n    apply(erule_tac\n      P=\"edge_push xa = aa @ [epda_box G]\"\n      in disjE)\n     apply(rename_tac xa xb a aa)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"rev aa ! xb \\<in> set aa\")\n      apply(rename_tac xa xb a aa)(*strict*)\n      prefer 2\n      apply(rule rev_nth_in_set)\n      apply(force)\n     apply(rename_tac xa xb a aa)(*strict*)\n     apply(force)\n    apply(rename_tac xa xb a aa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac xa xb a)(*strict*)\n    apply(subgoal_tac \"rev (edge_push xa) ! Suc xb \\<in> set(edge_push xa)\")\n     apply(rename_tac xa xb a)(*strict*)\n     prefer 2\n     apply(rule rev_nth_in_set)\n     apply(force)\n    apply(rename_tac xa xb a)(*strict*)\n    apply(force)\n   apply(rename_tac xa xb a aa)(*strict*)\n   apply(clarsimp)\n   apply(rule conjI)\n    apply(rename_tac xa xb a aa)(*strict*)\n    apply(rule_tac\n      A=\"set (edge_push xa)\"\n      in set_mp)\n     apply(rename_tac xa xb a aa)(*strict*)\n     apply(force)\n    apply(rename_tac xa xb a aa)(*strict*)\n    apply(rule rev_nth_in_set)\n    apply(force)\n   apply(rename_tac xa xb a aa)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac xa xb a aa)(*strict*)\n    apply(erule_tac\n      P=\"edge_push xa = aa @ [epda_box G]\"\n      in disjE)\n     apply(rename_tac xa xb a aa)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"rev aa ! xb \\<in> set aa\")\n      apply(rename_tac xa xb a aa)(*strict*)\n      prefer 2\n      apply(rule rev_nth_in_set)\n      apply(force)\n     apply(rename_tac xa xb a aa)(*strict*)\n     apply(force)\n    apply(rename_tac xa xb a aa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac xa xb a)(*strict*)\n    apply(subgoal_tac \"rev (edge_push xa) ! Suc xb \\<in> set(edge_push xa)\")\n     apply(rename_tac xa xb a)(*strict*)\n     prefer 2\n     apply(rule rev_nth_in_set)\n     apply(force)\n    apply(rename_tac xa xb a)(*strict*)\n    apply(force)\n   apply(rename_tac xa xb a aa)(*strict*)\n   apply(rule_tac\n      A=\"set (edge_push xa)\"\n      in set_mp)\n    apply(rename_tac xa xb a aa)(*strict*)\n    apply(force)\n   apply(rename_tac xa xb a aa)(*strict*)\n   apply(rule rev_nth_in_set)\n   apply(force)\n  apply(rename_tac xa xb)(*strict*)\n  apply(rule order_antisym)\n   apply(rename_tac xa xb)(*strict*)\n   apply(clarsimp)\n   apply(simp add: must_terminated_by_def may_terminated_by_def kleene_star_def append_language_def F_DPDA_RMPUE__edge_if_def)\n   apply(clarsimp)\n   apply(rename_tac xa xb a aa)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac xa xb a aa)(*strict*)\n    apply(rule_tac\n      A=\"set (edge_push xa)\"\n      in set_mp)\n     apply(rename_tac xa xb a aa)(*strict*)\n     apply(force)\n    apply(rename_tac xa xb a aa)(*strict*)\n    apply(rule rev_nth_in_set)\n    apply(force)\n   apply(rename_tac xa xb a aa)(*strict*)\n   apply(erule_tac\n      P=\"edge_push xa = aa @ [epda_box G]\"\n      in disjE)\n    apply(rename_tac xa xb a aa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac xa xb a aa ab)(*strict*)\n    apply(subgoal_tac \"rev aa ! xb \\<in> set aa\")\n     apply(rename_tac xa xb a aa ab)(*strict*)\n     prefer 2\n     apply(rule rev_nth_in_set)\n     apply(force)\n    apply(rename_tac xa xb a aa ab)(*strict*)\n    apply(force)\n   apply(rename_tac xa xb a aa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac xa xb a)(*strict*)\n   apply(subgoal_tac \"rev (edge_push xa) ! Suc xb \\<in> set(edge_push xa)\")\n    apply(rename_tac xa xb a)(*strict*)\n    prefer 2\n    apply(rule rev_nth_in_set)\n    apply(force)\n   apply(rename_tac xa xb a)(*strict*)\n   apply(force)\n  apply(rename_tac xa xb)(*strict*)\n  apply(clarsimp)\n  apply(simp add: must_terminated_by_def may_terminated_by_def kleene_star_def append_language_def F_DPDA_RMPUE__edge_if_def)\n  done\n\nlemma F_DPDA_RMPUE__preserves_PDA: \"\n  valid_dpda G\n  \\<Longrightarrow> valid_pda (F_DPDA_RMPUE G)\"\n  apply(simp add: valid_pda_def)\n  apply(rule conjI)\n   apply(rule F_DPDA_RMPUE__preserves_epda)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac e)(*strict*)\n  apply(simp add: valid_epda_def valid_pda_def valid_dpda_def F_DPDA_RMPUE_def)\n  apply(clarsimp)\n  apply(erule disjE)\n   apply(rename_tac e)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac e x)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_then_def)\n   apply(clarsimp)\n  apply(rename_tac e)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__edge_else_def)\n  done\n\ntheorem F_DPDA_RMPUE__preserves_read_edges_seperated: \"\n  valid_dpda G\n  \\<Longrightarrow> read_edges_seperated G\n  \\<Longrightarrow> read_edges_seperated (F_DPDA_RMPUE G)\"\n  apply(simp add: read_edges_seperated_def F_DPDA_RMPUE_def)\n  apply(clarsimp)\n  apply(rename_tac e)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac e)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac e x)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_then_def FB_executing_edge_def)\n   apply(clarsimp)\n  apply(rename_tac e)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__edge_else_def)\n  apply(simp add: FB_executing_edge_def)\n  apply(clarsimp)\n  apply(rename_tac x y)(*strict*)\n  apply(simp add: strict_executing_edge_def F_DPDA_SEE__edge_else_def FB_executing_edge_def empty_push_edge_def multiple_push_edge_def)\n  done\n\ntheorem F_DPDA_RMPUE__preserves_neutral_edges_removed: \"\n  valid_dpda G\n  \\<Longrightarrow> neutral_edges_removed G\n  \\<Longrightarrow> neutral_edges_removed (F_DPDA_RMPUE G)\"\n  apply(simp add: neutral_edges_removed_def F_DPDA_RMPUE_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(subgoal_tac \"edge_pop x \\<noteq> []\")\n   apply(rename_tac x)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac x)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac x xa)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_then_def)\n    apply(clarsimp)\n    apply(rename_tac xa xb)(*strict*)\n    apply(simp add: FB_neutral_edge_def)\n   apply(rename_tac x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac xa)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_else_def FB_neutral_edge_def)\n   apply(clarsimp)\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: valid_dpda_def valid_pda_def)\n  apply(clarsimp)\n  apply(erule disjE)\n   apply(rename_tac x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x xa)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_then_def)\n   apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac xa)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__edge_else_def)\n  apply(force)\n  done\n\ntheorem F_DPDA_RMPUE__preserves_push_and_pop_edges_seperated: \"\n  valid_dpda G\n  \\<Longrightarrow> push_and_pop_edges_seperated G\n  \\<Longrightarrow> push_and_pop_edges_seperated (F_DPDA_RMPUE G)\"\n  apply(simp add: push_and_pop_edges_seperated_def F_DPDA_RMPUE_def)\n  apply(clarsimp)\n  apply(rename_tac e)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac e)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac e x)(*strict*)\n   apply(simp add: FB_neutral_edge_def FB_executing_edge_def F_DPDA_RMPUE__edge_then_def)\n   apply(clarsimp)\n   apply(rename_tac x xa)(*strict*)\n   apply(simp add: F_DPDA_SPPE__edge_if_def)\n  apply(rename_tac e)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__edge_else_def F_DPDA_SPPE__edge_if_def)\n  apply(clarsimp)\n  apply(rename_tac x w b)(*strict*)\n  apply(force)\n  done\n\ntheorem F_DPDA_RMPUE__produces_mass_push_edges_splitted: \"\n  valid_dpda G\n  \\<Longrightarrow> mass_push_edges_splitted (F_DPDA_RMPUE G)\"\n  apply(simp add: mass_push_edges_splitted_def F_DPDA_RMPUE_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x xa)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_if_def F_DPDA_RMPUE__edge_then_def)\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac xa)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__edge_if_def F_DPDA_RMPUE__edge_else_def)\n  done\n\ntheorem F_DPDA_RMPUE__preserves_pop_edges_seperated: \"\n  valid_dpda G\n  \\<Longrightarrow> pop_edges_seperated G\n  \\<Longrightarrow> pop_edges_seperated (F_DPDA_RMPUE G)\"\n  apply(simp add: pop_edges_seperated_def)\n  apply(clarsimp)\n  apply(rename_tac e)(*strict*)\n  apply(simp add: F_DPDA_RMPUE_def)\n  apply(clarsimp)\n  apply(erule disjE)\n   apply(rename_tac e)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac e x)(*strict*)\n   apply(simp add: FB_neutral_edge_def FB_executing_edge_def F_DPDA_RMPUE__edge_then_def)\n   apply(clarsimp)\n   apply(rename_tac x xa)(*strict*)\n   apply(simp add: strict_empty_push_edge_def empty_push_edge_def)\n  apply(rename_tac e)(*strict*)\n  apply(simp add: strict_empty_push_edge_def empty_push_edge_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__edge_else_def F_DPDA_SPPE__edge_if_def)\n  done\n\nlemma bexE_image_disj: \"\n  \\<exists>X \\<in> (f1 ` A) \\<union> (f2 ` B). P X\n  \\<Longrightarrow> ((\\<exists>X \\<in> f1 ` A. P X) \\<Longrightarrow> Q)\n \\<Longrightarrow> ((\\<exists>X \\<in> f2 ` B. P X) \\<Longrightarrow> Q)\n  \\<Longrightarrow> Q\"\n  apply(force)\n  done\n\ntheorem F_DPDA_RMPUE__produces_push_edges_seperated: \"\n  valid_dpda G\n  \\<Longrightarrow> valid_pda (F_DPDA_RMPUE G)\n  \\<Longrightarrow> read_edges_seperated (F_DPDA_RMPUE G)\n  \\<Longrightarrow> mass_push_edges_splitted (F_DPDA_RMPUE G)\n  \\<Longrightarrow> push_and_pop_edges_seperated (F_DPDA_RMPUE G)\n  \\<Longrightarrow> push_edges_seperated (F_DPDA_RMPUE G)\"\n  apply(simp add: push_and_pop_edges_seperated_def mass_push_edges_splitted_def F_DPDA_RMPUE__edge_if_def push_edges_seperated_def read_edges_seperated_def)\n  apply(clarsimp)\n  apply(rename_tac e)(*strict*)\n  apply(erule_tac\n      x=\"e\"\n      and P=\"\\<lambda>e. FB_executing_edge e \\<longrightarrow> strict_executing_edge e\"\n      in ballE)\n   apply(rename_tac e)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac e)(*strict*)\n  apply(erule_tac\n      x=\"e\"\n      and P=\"\\<lambda>e. \\<not> Suc (Suc 0) < length (edge_push e)\"\n      in ballE)\n   apply(rename_tac e)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac e)(*strict*)\n  apply(erule_tac\n      x=\"e\"\n      in ballE)\n   apply(rename_tac e)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac e)(*strict*)\n  apply(simp add: multiple_push_edge_def)\n  apply(subgoal_tac \"length (edge_push e) = Suc (Suc 0)\")\n   apply(rename_tac e)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac e)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"length (edge_pop e) = Suc 0\")\n   apply(rename_tac e)(*strict*)\n   prefer 2\n   apply(simp add: valid_pda_def)\n  apply(rename_tac e)(*strict*)\n  apply(subgoal_tac \"valid_epda_step_label (F_DPDA_RMPUE G) e\")\n   apply(rename_tac e)(*strict*)\n   prefer 2\n   apply(simp add: valid_epda_def valid_pda_def)\n  apply(rename_tac e)(*strict*)\n  apply(simp add: valid_epda_step_label_def)\n  apply(simp add: strict_multiple_push_edge_def)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(rename_tac e)(*strict*)\n   prefer 2\n   apply(case_tac \"edge_event e\")\n    apply(rename_tac e)(*strict*)\n    apply(force)\n   apply(rename_tac e a)(*strict*)\n   apply(simp add: FB_executing_edge_def)\n   apply(simp add: strict_executing_edge_def)\n  apply(rename_tac e)(*strict*)\n  apply(simp add: F_DPDA_RMPUE_def)\n  apply(erule bexE_image_disj)\n   apply(rename_tac e)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac e x)(*strict*)\n   apply(simp add: FB_neutral_edge_def FB_executing_edge_def F_DPDA_RMPUE__edge_then_def)\n   apply(clarsimp)\n   apply(rename_tac x xa)(*strict*)\n   apply(simp add: suffix_def)\n  apply(rename_tac e)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__edge_else_def)\n  apply(simp add: FB_executing_edge_def strict_executing_edge_def)\n  apply(simp add: F_DPDA_RMPUE__edge_if_def)\n  apply(simp add: F_DPDA_SPPE__edge_if_def)\n  apply(erule_tac\n      P=\"\\<exists>y. edge_event x = Some y\"\n      in disjE)\n   apply(rename_tac x)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(case_tac \"edge_push x\")\n   apply(rename_tac x)(*strict*)\n   apply(force)\n  apply(rename_tac x a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. edge_push x = w' @ [x']\")\n   apply(rename_tac x a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac x a list)(*strict*)\n  apply(thin_tac \"edge_push x= a # list\")\n  apply(clarsimp)\n  apply(rename_tac x w' x')(*strict*)\n  apply(simp add: suffix_def)\n  done\n\ndefinition F_DPDA_RMPUE__relation_structure__LR :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RMPUE__relation_structure__LR G1 G2 \\<equiv>\n  valid_dpda G1\n  \\<and> G2 = F_DPDA_RMPUE G1\n  \\<and> push_and_pop_edges_seperated G1\n  \\<and> read_edges_seperated G1\"\n\ndefinition F_DPDA_RMPUE__relation_configuration__LR :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RMPUE__relation_configuration__LR G1 G2 c1 c2 \\<equiv>\n  F_DPDA_RMPUE__relation_structure__LR G1 G2\n  \\<and> c1 \\<in> epdaS.get_accessible_configurations G1\n  \\<and> c2 = F_DPDA_RMPUE__conf_old__LR c1\"\n\ndefinition F_DPDA_RMPUE__relation_initial_configuration__LR :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RMPUE__relation_initial_configuration__LR G1 G2 c1 c2 \\<equiv>\n  F_DPDA_RMPUE__relation_structure__LR G1 G2\n  \\<and> c1 \\<in> epdaS_initial_configurations G1\n  \\<and> c2 = F_DPDA_RMPUE__conf_old__LR c1\"\n\ndefinition F_DPDA_RMPUE__relation_effect__LR :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RMPUE__relation_effect__LR G1 G2 w1 w2 \\<equiv>\n  F_DPDA_RMPUE__relation_structure__LR G1 G2\n  \\<and> w1 = w2\"\n\nlemma epdaS_epdaS_RMP_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs: \"\n  (\\<forall>G1. Ex (F_DPDA_RMPUE__relation_structure__LR G1) \\<longrightarrow> valid_epda G1)\"\n  apply(clarsimp)\n  apply(rename_tac G1 x)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n  apply(clarsimp)\n  apply(rename_tac G1)(*strict*)\n  apply(simp add: valid_dpda_def valid_pda_def)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimLR_inst_AX_TSstructure_relation_TSstructure2_belongs: \"\n  (\\<forall>G1 G2. F_DPDA_RMPUE__relation_structure__LR G1 G2 \\<longrightarrow> valid_epda G2)\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n  apply(clarsimp)\n  apply(rename_tac G1)(*strict*)\n  apply (metis F_DPDA_RMPUE__preserves_epda)\n  done\n\ndefinition F_DPDA_RMPUE__relation_step_simulation__LR :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack) epda_step_label\n  \\<Rightarrow> ('state, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ((('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda_step_label, (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epdaS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RMPUE__relation_step_simulation__LR G1 G2 c1 e c1' c2 d \\<equiv>\n  if F_DPDA_RMPUE__edge_if e\n  then d = (\\<lambda>n.\n    if n < length (edge_push e)\n    then Some (pair (F_DPDA_RMPUE__edge_then_i_th__LR e n) (the (F_DPDA_RMPUE__conf_i_th__LR (F_DPDA_RMPUE__conf_old__LR c1) e n)))\n    else None)\n  else d = der2\n    (F_DPDA_RMPUE__conf_old__LR c1)\n      (F_DPDA_RMPUE__edge_else e)\n    (F_DPDA_RMPUE__conf_old__LR c1')\"\n\ndefinition F_DPDA_RMPUE__relation_initial_simulation__LR :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ((('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda_step_label, (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epdaS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RMPUE__relation_initial_simulation__LR G1 G2 c1 d \\<equiv>\n  d = der1 (F_DPDA_RMPUE__conf_old__LR c1)\"\n\nlemma F_DPDA_RMPUE__conf_old__LR_preserves_configurations: \"\n  F_DPDA_RMPUE__relation_structure__LR G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS_configurations G1\n  \\<Longrightarrow> F_DPDA_RMPUE__conf_old__LR c1 \\<in> epdaS_configurations G2\"\n  apply(simp add: epdaS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac q i s)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__conf_old__LR_def)\n  apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RMPUE_def)\n  done\n\nlemma F_DPDA_RMPUE__conf_old__LR_preserves_initial_configurations: \"\n  F_DPDA_RMPUE__relation_structure__LR G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS_initial_configurations G1\n  \\<Longrightarrow> F_DPDA_RMPUE__conf_old__LR c1 \\<in> epdaS_initial_configurations G2\"\n  apply(simp add: epdaS_initial_configurations_def)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_def F_DPDA_RMPUE_def)\n   apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_def F_DPDA_RMPUE_def)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_def F_DPDA_RMPUE_def)\n   apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_def F_DPDA_RMPUE_def)\n  apply(rule F_DPDA_RMPUE__conf_old__LR_preserves_configurations)\n   apply(force)\n  apply(force)\n  done\n\nlemma F_DPDA_RMPUE__conf_old__LR_preserves_marking_configurations: \"\n  F_DPDA_RMPUE__relation_structure__LR G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS_marking_configurations G1\n  \\<Longrightarrow> F_DPDA_RMPUE__conf_old__LR c1 \\<in> epdaS_marking_configurations G2\"\n  apply(simp add: epdaS_marking_configurations_def)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_def F_DPDA_RMPUE_def)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_def F_DPDA_RMPUE_def)\n   apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_def F_DPDA_RMPUE_def)\n  apply(rule F_DPDA_RMPUE__conf_old__LR_preserves_configurations)\n   apply(force)\n  apply(force)\n  done\n\nlemma F_DPDA_RMPUE__initial_simulation_preserves_derivation: \"\n  F_DPDA_RMPUE__relation_structure__LR G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS_initial_configurations G1\n  \\<Longrightarrow> epdaS.derivation_initial G2 (der1 (F_DPDA_RMPUE__conf_old__LR c1))\"\n  apply(rule epdaS.derivation_initialI)\n   apply(rule epdaS.der1_is_derivation)\n  apply(clarsimp)\n  apply(rename_tac c)(*strict*)\n  apply(simp add: get_configuration_def der1_def)\n  apply(clarsimp)\n  apply(rule F_DPDA_RMPUE__conf_old__LR_preserves_initial_configurations)\n   apply(force)\n  apply(force)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimLR_inst_relation_initial_simulation: \"\n  \\<forall>G1 G2. F_DPDA_RMPUE__relation_structure__LR G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<exists>d2. epdaS.derivation_initial G2 d2 \\<and> F_DPDA_RMPUE__relation_initial_configuration__LR G1 G2 c1 (the (get_configuration (d2 0))) \\<and> F_DPDA_RMPUE__relation_initial_simulation__LR G1 G2 c1 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_DPDA_RMPUE__relation_configuration__LR G1 G2 c1 (the (get_configuration (d2 n))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_initial_simulation__LR_def)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule F_DPDA_RMPUE__initial_simulation_preserves_derivation)\n    apply(rename_tac G1 G2 c1)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_initial_configuration__LR_def)\n   apply(simp add: get_configuration_def der1_def)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule_tac\n      x=\"0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule der1_maximum_of_domain)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: get_configuration_def der1_def)\n  apply(simp add: F_DPDA_RMPUE__relation_configuration__LR_def)\n  apply(rule epdaS.initial_configurations_are_get_accessible_configurations)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def valid_pda_def valid_dpda_def)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(force)\n  done\n\nlemma F_DPDA_RMPUE__relation_step_simulation__LR_maps_to_derivation: \"\n  F_DPDA_RMPUE__relation_step_simulation__LR G1 G2 c1 e1 c1' c2 d2\n  \\<Longrightarrow> F_DPDA_RMPUE__relation_configuration__LR G1 G2 c1 c2\n  \\<Longrightarrow> epdaS_step_relation G1 c1 e1 c1'\n  \\<Longrightarrow> epdaS.derivation G2 d2\"\n  apply(simp add: F_DPDA_RMPUE__relation_step_simulation__LR_def)\n  apply(case_tac \"F_DPDA_RMPUE__edge_if e1\")\n   apply(clarsimp)\n   apply(simp add: epdaS.derivation_def)\n   apply(rule conjI)\n    apply(clarsimp)\n    apply(rename_tac i)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac i)(*strict*)\n     prefer 2\n     apply(clarsimp)\n     apply(case_tac i)\n      apply(rename_tac i)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac i nat)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac i)(*strict*)\n    apply(clarsimp)\n    apply(case_tac i)\n     apply(rename_tac i)(*strict*)\n     apply(clarsimp)\n     apply(simp add: F_DPDA_RMPUE__edge_then_i_th__LR_def)\n    apply(rename_tac i nat)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_if_def)\n    apply(clarsimp)\n    apply(rename_tac nat)(*strict*)\n    prefer 2\n    apply(clarsimp)\n    apply(rename_tac i)(*strict*)\n    apply(case_tac i)\n     apply(rename_tac i)(*strict*)\n     apply(clarsimp)\n     apply(simp add: F_DPDA_RMPUE__edge_if_def)\n    apply(rename_tac i nat)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac nat)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_then_i_th__LR_def)\n   apply(simp add: epdaS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac nat w)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac nat w)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__LR_def)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RMPUE_def)\n    apply(simp add: F_DPDA_RMPUE__edge_else_def F_DPDA_RMPUE__edge_then_def)\n    apply(case_tac \"F_DPDA_RMPUE__edge_if e1\")\n     apply(rename_tac nat w)(*strict*)\n     apply(rule_tac\n      x=\"e1\"\n      in bexI_image_disjI1)\n      apply(force)\n     apply(force)\n    apply(rule_tac\n      x=\"e1\"\n      in bexI_image_disjI2)\n     apply(force)\n    apply(clarsimp)\n    apply(rename_tac nat w)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_if_def)\n   apply(rename_tac nat w)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac nat w)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__LR_def)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RMPUE__state_def)\n    apply(simp only: F_DPDA_RMPUE__conf_i_th__LR_def)\n    apply(clarsimp)\n    apply(rule conjI)\n     apply(rename_tac nat w)(*strict*)\n     apply(simp only: F_DPDA_RMPUE__state_def)\n     apply(clarsimp)\n    apply(rename_tac nat w)(*strict*)\n    apply(clarsimp)\n    apply(simp only: F_DPDA_RMPUE__state_def)\n    apply(clarsimp)\n   apply(rename_tac nat w)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac nat w)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__LR_def)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RMPUE__state_def)\n    apply(rule conjI)\n     apply(rename_tac nat w)(*strict*)\n     apply(clarsimp)\n     apply(simp only: F_DPDA_RMPUE__conf_i_th__LR_def)\n     apply(clarsimp)\n     apply(simp only: F_DPDA_RMPUE__state_def)\n     apply(clarsimp)\n    apply(rename_tac nat w)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"Suc (Suc nat)=length(edge_push e1)\")\n     apply(rename_tac nat w)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac nat w)(*strict*)\n    apply(clarsimp)\n    apply(simp only: F_DPDA_RMPUE__conf_i_th__LR_def)\n    apply(clarsimp)\n    apply(simp only: F_DPDA_RMPUE__state_def)\n    apply(clarsimp)\n   apply(rename_tac nat w)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac nat w)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__LR_def)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RMPUE__conf_i_th__LR_def option_to_list_def)\n   apply(rename_tac nat w)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__conf_i_th__LR_def option_to_list_def F_DPDA_RMPUE__conf_old__LR_def)\n   apply(subgoal_tac \"valid_epda_step_label G1 e1\")\n    apply(rename_tac nat w)(*strict*)\n    prefer 2\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__LR_def)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n    apply(clarsimp)\n    apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac nat w)(*strict*)\n   apply(simp add: valid_epda_step_label_def)\n   apply(subgoal_tac \"length (edge_pop e1) = Suc 0\")\n    apply(rename_tac nat w)(*strict*)\n    prefer 2\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__LR_def)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n    apply(clarsimp)\n    apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac nat w)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"\\<exists>x. edge_pop e1 = [x]\")\n    apply(rename_tac nat w)(*strict*)\n    prefer 2\n    apply(case_tac \"edge_pop e1\")\n     apply(rename_tac nat w)(*strict*)\n     apply(force)\n    apply(rename_tac nat w a list)(*strict*)\n    apply(case_tac list)\n     apply(rename_tac nat w a list)(*strict*)\n     apply(force)\n    apply(rename_tac nat w a list aa lista)(*strict*)\n    apply(force)\n   apply(rename_tac nat w)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac nat w x)(*strict*)\n   apply(case_tac nat)\n    apply(rename_tac nat w x)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac w x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__LR_def)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n    apply(clarsimp)\n    apply(simp add: push_and_pop_edges_seperated_def F_DPDA_SPPE__edge_if_def)\n    apply(erule_tac\n      x=\"e1\"\n      in ballE)\n     apply(rename_tac w x)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac w x)(*strict*)\n    apply(simp add: suffix_def)\n    apply(erule disjE)\n     apply(rename_tac w x)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac w x y)(*strict*)\n     apply(simp add: read_edges_seperated_def)\n     apply(erule_tac\n      x=\"e1\"\n      in ballE)\n      apply(rename_tac w x y)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac w x y)(*strict*)\n     apply(simp add: FB_executing_edge_def)\n     apply(simp add: strict_executing_edge_def)\n    apply(rename_tac w x)(*strict*)\n    apply(case_tac \"edge_push e1\")\n     apply(rename_tac w x)(*strict*)\n     apply(force)\n    apply(rename_tac w x a list)(*strict*)\n    apply(subgoal_tac \"\\<exists>w' x'. edge_push e1 = w' @ [x']\")\n     apply(rename_tac w x a list)(*strict*)\n     prefer 2\n     apply(rule NonEmptyListHasTailElem)\n     apply(force)\n    apply(rename_tac w x a list)(*strict*)\n    apply(thin_tac \"edge_push e1= a # list\")\n    apply(clarify)\n    apply(rename_tac w x a list w' x')(*strict*)\n    apply(erule_tac\n      x=\"w'\"\n      in allE)\n    apply(erule_tac\n      x=\"x'\"\n      in allE)\n    apply(clarsimp)\n    apply(rename_tac w w' x')(*strict*)\n    apply(rule last_drop_rev_nth)\n    apply(force)\n   apply(rename_tac nat w x nata)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_configuration__LR_def)\n   apply(clarsimp)\n   apply(rename_tac w x nata)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n   apply(clarsimp)\n   apply(rule_tac\n      t=\"rev (edge_push e1) ! (Suc nata)\"\n      and s=\"drop (length (edge_push e1) - (Suc (Suc nata))) (edge_push e1) ! 0\"\n      in ssubst)\n    apply(rename_tac w x nata)(*strict*)\n    apply(rule rev_drop_nth)\n    apply(force)\n   apply(rename_tac w x nata)(*strict*)\n   apply(rule_tac\n      x=\"tl(drop (length (edge_push e1) - Suc (Suc nata)) (edge_push e1))@w\"\n      in exI)\n   apply(case_tac \"drop (length (edge_push e1) - Suc (Suc nata)) (edge_push e1)\")\n    apply(rename_tac w x nata)(*strict*)\n    apply(force)\n   apply(rename_tac w x nata a list)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac w x nata a list)(*strict*)\n    apply(force)\n   apply(rename_tac w x nata a list)(*strict*)\n   apply(rule_tac\n      t=\"rev (edge_push e1) ! Suc (Suc nata)\"\n      and s=\"drop (length (edge_push e1) - (Suc (Suc (Suc nata)))) (edge_push e1) ! 0\"\n      in ssubst)\n    apply(rename_tac w x nata a list)(*strict*)\n    apply(rule rev_drop_nth)\n    apply(force)\n   apply(rename_tac w x nata a list)(*strict*)\n   apply(case_tac \"drop (length (edge_push e1) - Suc (Suc (Suc nata))) (edge_push e1)\")\n    apply(rename_tac w x nata a list)(*strict*)\n    apply(force)\n   apply(rename_tac w x nata a list aa lista)(*strict*)\n   apply(rule drop_nth_tl_double_head)\n   apply(clarsimp)\n  apply(clarsimp)\n  apply(rule epdaS.der2_is_derivation)\n  apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_def F_DPDA_RMPUE__edge_else_def)\n  apply(clarsimp)\n  apply(rename_tac w)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_configuration__LR_def F_DPDA_RMPUE__relation_structure__LR_def F_DPDA_RMPUE_def)\n  apply(rule_tac\n      x=\"e1\"\n      in bexI_image_disjI2)\n   apply(force)\n  apply(rename_tac w)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__edge_else_def)\n  done\n\nlemma F_DPDA_RMPUE__conf_i_th__LR_F_DPDA_RMPUE__conf_old__LR_preserve_configuration: \"\n  valid_dpda G1\n  \\<Longrightarrow> c1 \\<in> epdaS_configurations G1\n  \\<Longrightarrow> epdaS_conf_stack c1 \\<in> must_terminated_by (epda_gamma G1) (epda_box G1)\n  \\<Longrightarrow> F_DPDA_RMPUE__edge_if e1\n  \\<Longrightarrow> e1 \\<in> epda_delta G1\n  \\<Longrightarrow> the (F_DPDA_RMPUE__conf_i_th__LR (F_DPDA_RMPUE__conf_old__LR c1) e1 0) \\<in> epdaS_configurations (F_DPDA_RMPUE G1)\"\n  apply(simp add: epdaS_configurations_def F_DPDA_RMPUE__conf_i_th__LR_def)\n  apply(clarsimp)\n  apply(rename_tac q i s)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac q i s)(*strict*)\n   prefer 2\n   apply(simp add: F_DPDA_RMPUE__edge_if_def)\n   apply(force)\n  apply(rename_tac q i s)(*strict*)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RMPUE__conf_old__LR_def)\n  apply(subgoal_tac \"valid_epda_step_label G1 e1\")\n   apply(rename_tac q i s)(*strict*)\n   prefer 2\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rename_tac q i s)(*strict*)\n  apply(simp add: valid_epda_step_label_def)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RMPUE__state_def F_DPDA_RMPUE_def)\n  apply(rule conjI)\n   apply(rename_tac q i s)(*strict*)\n   apply(rule valid_epda_pop_in_gamma)\n    apply(rename_tac q i s)(*strict*)\n    apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac q i s)(*strict*)\n   apply(force)\n  apply(rename_tac q i s)(*strict*)\n  apply(simp add: must_terminated_by_def may_terminated_by_def kleene_star_def append_language_def F_DPDA_RMPUE__edge_if_def)\n  apply(clarsimp)\n  apply(rename_tac q i x a aa ab)(*strict*)\n  apply(case_tac a)\n   apply(rename_tac q i x a aa ab)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac q i x a aa ab ac list)(*strict*)\n  apply(force)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimLR_inst_relation_step_simulation: \"\n  (\\<forall>G1 G2. F_DPDA_RMPUE__relation_structure__LR G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_DPDA_RMPUE__relation_configuration__LR G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<exists>d2. epdaS.derivation G2 d2 \\<and> epdaS.belongs G2 d2 \\<and> the (get_configuration (d2 0)) = c2 \\<and> F_DPDA_RMPUE__relation_step_simulation__LR G1 G2 c1 e1 c1' c2 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_DPDA_RMPUE__relation_configuration__LR G1 G2 c1' (the (get_configuration (d2 n)))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_step_simulation__LR_def)\n  apply(case_tac \"F_DPDA_RMPUE__edge_if e1\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(clarsimp)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    prefer 2\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RMPUE__edge_if_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(clarsimp)\n   apply(rule context_conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(rule F_DPDA_RMPUE__relation_step_simulation__LR_maps_to_derivation)\n      apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_step_simulation__LR_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(rule epdaS.derivation_belongs)\n       apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n       apply (metis epdaS_epdaS_RMP_StateSimLR_inst_AX_TSstructure_relation_TSstructure2_belongs)\n      apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n      apply(clarsimp)\n      apply(simp add: F_DPDA_RMPUE__edge_then_i_th__LR_def)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_configuration__LR_def)\n     apply(clarsimp)\n     apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n     apply(rule F_DPDA_RMPUE__conf_i_th__LR_F_DPDA_RMPUE__conf_old__LR_preserve_configuration)\n         apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n         apply(force)\n        apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n        apply(clarsimp)\n        apply(rename_tac G1 c1 e1 c1')(*strict*)\n        apply(rule set_mp)\n         apply(rename_tac G1 c1 e1 c1')(*strict*)\n         apply(rule epdaS.get_accessible_configurations_are_configurations)\n         apply(simp add: valid_dpda_def valid_pda_def)\n        apply(rename_tac G1 c1 e1 c1')(*strict*)\n        apply(force)\n       apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n       apply(rule epda_stack_is_must_terminated_by)\n        apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n        apply (metis epdaS_epdaS_RMP_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs F_DPDA_RMPUE__relation_structure__LR_def)\n       apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n     apply(simp add: epda_step_labels_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(simp add: get_configuration_def F_DPDA_RMPUE__conf_i_th__LR_def F_DPDA_RMPUE__relation_configuration__LR_def F_DPDA_RMPUE__conf_old__LR_def F_DPDA_RMPUE__state_def)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n     apply(simp add: epdaS_step_relation_def)\n    apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n    apply(simp add: epdaS_step_relation_def)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 e1 c1' w)(*strict*)\n    apply(subgoal_tac \"\\<exists>x. edge_pop e1 = [x]\")\n     apply(rename_tac G1 G2 c1 e1 c1' w)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G1 G2 c1 e1 c1' w)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def valid_dpda_def valid_pda_def)\n    apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n    apply(erule_tac\n      x=\"e1\"\n      in ballE)\n     apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n    apply(case_tac \"edge_pop e1\")\n     apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n     apply(force)\n    apply(rename_tac G1 c1 e1 c1' w a list)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule_tac\n      x=\"length(edge_push e1)-Suc 0\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(clarsimp)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     apply(simp only: maximum_of_domain_def)\n     apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__LR_def)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     prefer 2\n     apply(simp add: get_configuration_def)\n     apply(simp add: F_DPDA_RMPUE__conf_i_th__LR_def)\n     apply(rule conjI)\n      apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n      apply(clarsimp)\n      apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n      apply(simp add: F_DPDA_RMPUE__edge_if_def)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n     apply(simp add: F_DPDA_RMPUE__conf_old__LR_def)\n     apply(rule conjI)\n      apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n      apply(simp add: F_DPDA_RMPUE__state_def)\n      apply(simp add: epdaS_step_relation_def)\n     apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n     apply(rule conjI)\n      apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n      apply(simp add: epdaS_step_relation_def)\n      apply(simp add: option_to_list_def)\n      apply(clarsimp)\n      apply(rename_tac G1 G2 c1 e1 c1' w)(*strict*)\n      apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n      apply(clarsimp)\n      apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n      apply(simp add: read_edges_seperated_def push_and_pop_edges_seperated_def)\n      apply(erule_tac\n      x=\"e1\"\n      and P=\"\\<lambda>e1. \\<not> F_DPDA_SPPE__edge_if e1\"\n      in ballE)\n       apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n       prefer 2\n       apply(force)\n      apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n      apply(erule_tac\n      x=\"e1\"\n      in ballE)\n       apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n       prefer 2\n       apply(force)\n      apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n      apply(case_tac \"edge_event e1\")\n       apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac G1 c1 e1 c1' w a)(*strict*)\n      apply(clarsimp)\n      apply(simp add: FB_executing_edge_def)\n      apply(simp add: strict_executing_edge_def empty_push_edge_def multiple_push_edge_def F_DPDA_SPPE__edge_if_def F_DPDA_RMPUE__edge_if_def)\n      apply(simp add: valid_dpda_def valid_pda_def)\n     apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n     apply(simp add: epdaS_step_relation_def)\n     apply(clarsimp)\n     apply(rename_tac G1 G2 c1 e1 c1' w)(*strict*)\n     apply(subgoal_tac \"\\<exists>x. edge_pop e1=[x]\")\n      apply(rename_tac G1 G2 c1 e1 c1' w)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac G1 G2 c1 e1 c1' w)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def valid_dpda_def valid_pda_def)\n     apply(clarsimp)\n     apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n     apply(erule_tac\n      x=\"e1\"\n      in ballE)\n      apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n     apply(case_tac \"edge_pop e1\")\n      apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n      apply(force)\n     apply(rename_tac G1 c1 e1 c1' w a list)(*strict*)\n     apply(case_tac list)\n      apply(rename_tac G1 c1 e1 c1' w a list)(*strict*)\n      apply(force)\n     apply(rename_tac G1 c1 e1 c1' w a list aa lista)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(rule epdaS.der2_preserves_get_accessible_configurations)\n      apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n      apply (metis epdaS_epdaS_RMP_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     apply(rule epdaS.der2_is_derivation)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(clarsimp)\n  apply(rule context_conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule F_DPDA_RMPUE__relation_step_simulation__LR_maps_to_derivation)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_step_simulation__LR_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule epdaS.der2_belongs_prime)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     apply (metis epdaS_epdaS_RMP_StateSimLR_inst_AX_TSstructure_relation_TSstructure2_belongs)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(rule F_DPDA_RMPUE__conf_old__LR_preserves_configurations)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__LR_def)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n    apply (metis (full_types) epdaS_epdaS_RMP_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs epdaS.get_accessible_configurations_are_configurations subsetD)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(simp add: get_configuration_def der2_def F_DPDA_RMPUE__relation_configuration__LR_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule der2_maximum_of_domain)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(simp (no_asm) add: get_configuration_def der2_def)\n  apply(simp add: F_DPDA_RMPUE__relation_configuration__LR_def)\n  apply(rule epdaS.der2_preserves_get_accessible_configurations)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply (metis epdaS_epdaS_RMP_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule epdaS.der2_is_derivation)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(force)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms: \"\n  ATS_Simulation_Configuration_Weak_axioms valid_epda epdaS_initial_configurations epda_step_labels epdaS_step_relation valid_epda epdaS_configurations epdaS_initial_configurations epda_step_labels epdaS_step_relation F_DPDA_RMPUE__relation_configuration__LR F_DPDA_RMPUE__relation_initial_configuration__LR F_DPDA_RMPUE__relation_structure__LR F_DPDA_RMPUE__relation_initial_simulation__LR F_DPDA_RMPUE__relation_step_simulation__LR\"\n  apply(simp add: ATS_Simulation_Configuration_Weak_axioms_def)\n  apply(simp add: epdaS_epdaS_RMP_StateSimLR_inst_relation_initial_simulation epdaS_epdaS_RMP_StateSimLR_inst_relation_step_simulation epdaS_epdaS_RMP_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs epdaS_epdaS_RMP_StateSimLR_inst_AX_TSstructure_relation_TSstructure2_belongs)\n  done\n\ninterpretation \"epdaS_epdaS_RMP_StateSimLR\" : ATS_Simulation_Configuration_Weak\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaS_configurations\"\n  (* initial_configurations1 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaS_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaS_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_DPDA_RMPUE__relation_configuration__LR\"\n  (* relation_initial_configuration *)\n  \"F_DPDA_RMPUE__relation_initial_configuration__LR\"\n  (* relation_effect *)\n  \"F_DPDA_RMPUE__relation_effect__LR\"\n  (* relation_TSstructure *)\n  \"F_DPDA_RMPUE__relation_structure__LR\"\n  (* relation_initial_simulation *)\n  \"F_DPDA_RMPUE__relation_initial_simulation__LR\"\n  (* relation_step_simulation *)\n  \"F_DPDA_RMPUE__relation_step_simulation__LR\"\n  apply(simp add: LOCALE_DEFS epda_interpretations)\n  apply(simp add: epdaS_epdaS_RMP_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms epdaS_epdaS_RMP_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimLR_inst_relation_step_simulation_marking_condition: \"\n  (\\<forall>G1 G2. F_DPDA_RMPUE__relation_structure__LR G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_DPDA_RMPUE__relation_configuration__LR G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<forall>d2. F_DPDA_RMPUE__relation_step_simulation__LR G1 G2 c1 e1 c1' c2 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_DPDA_RMPUE__relation_initial_configuration__LR G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der2 c1 e1 c1') deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> epdaS_marking_condition G1 (derivation_append deri1 (der2 c1 e1 c1') deri1n) \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_DPDA_RMPUE__relation_configuration__LR F_DPDA_RMPUE__relation_initial_simulation__LR F_DPDA_RMPUE__relation_step_simulation__LR G1 G2 (derivation_append deri1 (der2 c1 e1 c1') deri1n) (Suc deri1n) (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> epdaS_marking_condition G2 (derivation_append deri2 d2 deri2n)))))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: epdaS_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(case_tac \"i\\<le>deri1n\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(subgoal_tac \"deri1 i = Some (pair e c)\")\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n    prefer 2\n    apply(simp add: derivation_append_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(thin_tac \"derivation_append deri1 (der2 c1 e1 c1') deri1n i = Some (pair e c)\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(simp add: epdaS_epdaS_RMP_StateSimLR.simulating_derivation_def)\n   apply(clarsimp)\n   apply(simp add: epdaS_epdaS_RMP_StateSimLR.simulating_derivation_DEF_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"i\"\n      in allE)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c y)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_configuration__LR_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c y)(*strict*)\n   apply(case_tac y)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c y option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c option b)(*strict*)\n   apply(rename_tac e c)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(rule_tac\n      x=\"f i\"\n      in exI)\n   apply(rule_tac\n      x=\"e\"\n      in exI)\n   apply(rule_tac\n      x=\"c\"\n      in exI)\n   apply(clarsimp)\n   apply(rule_tac\n      t=\"c\"\n      and s=\"F_DPDA_RMPUE__conf_old__LR ca\"\n      in ssubst)\n    apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__conf_old__LR_def derivation_append_def get_configuration_def)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(rule F_DPDA_RMPUE__conf_old__LR_preserves_marking_configurations)\n    apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(subgoal_tac \"i=Suc deri1n\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e c)(*strict*)\n   apply(subgoal_tac \"c=c1'\")\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e c)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e)(*strict*)\n    apply(simp add: epdaS_epdaS_RMP_StateSimLR.simulating_derivation_def)\n    apply(simp add: epdaS_epdaS_RMP_StateSimLR.simulating_derivation_DEF_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"Suc deri1n\"\n      in allE)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e y)(*strict*)\n    apply(rule_tac\n      x=\"deri2n+n\"\n      in exI)\n    apply(case_tac y)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e y option b)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e option b)(*strict*)\n    apply(rename_tac e c)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n    apply(rule_tac\n      t=\"c\"\n      and s=\"F_DPDA_RMPUE__conf_old__LR c1'\"\n      in ssubst)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_configuration__LR_def derivation_append_def get_configuration_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n    apply(rule F_DPDA_RMPUE__conf_old__LR_preserves_marking_configurations)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e c)(*strict*)\n   apply(simp add: derivation_append_def der2_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(case_tac \"i>Suc deri1n\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(clarsimp)\n  apply(simp add: derivation_append_def der2_def)\n  apply(case_tac \"i-deri1n\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c nat)(*strict*)\n  apply(clarsimp)\n  apply(case_tac nat)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i c)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c nat nata)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimLR_inst_relation_initial_simulation_marking_condition: \"\n  \\<forall>G1 G2. F_DPDA_RMPUE__relation_structure__LR G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<forall>d2. F_DPDA_RMPUE__relation_initial_simulation__LR G1 G2 c1 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_DPDA_RMPUE__relation_initial_configuration__LR G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der1 c1) deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> epdaS_marking_condition G1 (derivation_append deri1 (der1 c1) deri1n) \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_DPDA_RMPUE__relation_configuration__LR F_DPDA_RMPUE__relation_initial_simulation__LR F_DPDA_RMPUE__relation_step_simulation__LR G1 G2 (derivation_append deri1 (der1 c1) deri1n) deri1n (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> epdaS_marking_condition G2 (derivation_append deri2 d2 deri2n))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: epdaS_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(case_tac \"i\\<le>deri1n\")\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(subgoal_tac \"deri1 i = Some (pair e c)\")\n    apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n    prefer 2\n    apply(simp add: derivation_append_def)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(simp add: epdaS_epdaS_RMP_StateSimLR.simulating_derivation_def)\n   apply(clarsimp)\n   apply(simp add: epdaS_epdaS_RMP_StateSimLR.simulating_derivation_DEF_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"i\"\n      in allE)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c y)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_configuration__LR_def)\n   apply(clarsimp)\n   apply(case_tac y)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c y option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c option b)(*strict*)\n   apply(rename_tac e c)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(rule_tac\n      x=\"f i\"\n      in exI)\n   apply(rule_tac\n      x=\"e\"\n      in exI)\n   apply(rule_tac\n      x=\"c\"\n      in exI)\n   apply(clarsimp)\n   apply(rule_tac\n      t=\"c\"\n      and s=\"F_DPDA_RMPUE__conf_old__LR ca\"\n      in ssubst)\n    apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__conf_old__LR_def derivation_append_def get_configuration_def)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(rule F_DPDA_RMPUE__conf_old__LR_preserves_marking_configurations)\n    apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(subgoal_tac \"i=deri1n\")\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(case_tac \"i>deri1n\")\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(clarsimp)\n  apply(simp add: derivation_append_def der1_def)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimLR_inst_ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms: \"\n  ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms epdaS_initial_configurations epda_step_labels epdaS_step_relation epdaS_marking_condition epdaS_initial_configurations epdaS_step_relation epdaS_marking_condition F_DPDA_RMPUE__relation_configuration__LR F_DPDA_RMPUE__relation_initial_configuration__LR F_DPDA_RMPUE__relation_structure__LR F_DPDA_RMPUE__relation_initial_simulation__LR F_DPDA_RMPUE__relation_step_simulation__LR\"\n  apply(simp add: ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms_def)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(rule epdaS_epdaS_RMP_StateSimLR.relation_step_simulation_preservation_PROVE2)\n    apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n    prefer 2\n    apply(rename_tac G1 G2 d1' d2')(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(thin_tac \"epdaS_epdaS_RMP_StateSimLR.relation_step_simulation_preservation G1 G2 d1' d2'\")\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(metis epdaS_epdaS_RMP_StateSimLR_inst_relation_step_simulation_marking_condition)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 d1' d2')(*strict*)\n  apply(rule epdaS_epdaS_RMP_StateSimLR.relation_initial_simulation_preservation_PROVE2)\n   apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   prefer 2\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(thin_tac \"epdaS_epdaS_RMP_StateSimLR.relation_initial_simulation_preservation G1 G2 d1' d2'\")\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(metis epdaS_epdaS_RMP_StateSimLR_inst_relation_initial_simulation_marking_condition)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimLR_inst_relation_step_simulation_marked_effect: \"\n  (\\<forall>G1 G2. F_DPDA_RMPUE__relation_structure__LR G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_DPDA_RMPUE__relation_configuration__LR G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<forall>d2. F_DPDA_RMPUE__relation_step_simulation__LR G1 G2 c1 e1 c1' c2 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_DPDA_RMPUE__relation_initial_configuration__LR G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der2 c1 e1 c1') deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_DPDA_RMPUE__relation_configuration__LR F_DPDA_RMPUE__relation_initial_simulation__LR F_DPDA_RMPUE__relation_step_simulation__LR G1 G2 (derivation_append deri1 (der2 c1 e1 c1') deri1n) (Suc deri1n) (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> left_total_on (F_DPDA_RMPUE__relation_effect__LR G1 G2) (epdaS_marked_effect G1 (derivation_append deri1 (der2 c1 e1 c1') deri1n)) (epdaS_marked_effect G2 (derivation_append deri2 d2 deri2n))))))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(rule_tac\n      x=\"a\"\n      in bexI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_effect__LR_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(simp add: epdaS_marked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri2 0 = Some (pair None c)\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c ca)(*strict*)\n   apply(simp add: derivation_append_def F_DPDA_RMPUE__relation_initial_configuration__LR_def)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(rule_tac\n      M=\"G2\"\n      in epdaS.some_position_has_details_at_0)\n  apply (metis epdaS.derivation_initial_is_derivation)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimLR_inst_relation_initial_simulation_marked_effect: \"\n  \\<forall>G1 G2. F_DPDA_RMPUE__relation_structure__LR G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<forall>d2. F_DPDA_RMPUE__relation_initial_simulation__LR G1 G2 c1 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_DPDA_RMPUE__relation_initial_configuration__LR G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der1 c1) deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_DPDA_RMPUE__relation_configuration__LR F_DPDA_RMPUE__relation_initial_simulation__LR F_DPDA_RMPUE__relation_step_simulation__LR G1 G2 (derivation_append deri1 (der1 c1) deri1n) deri1n (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> left_total_on (F_DPDA_RMPUE__relation_effect__LR G1 G2) (epdaS_marked_effect G1 (derivation_append deri1 (der1 c1) deri1n)) (epdaS_marked_effect G2 (derivation_append deri2 d2 deri2n)))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(rule_tac\n      x=\"a\"\n      in bexI)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_effect__LR_def)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(simp add: epdaS_marked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri2 0 = Some (pair None c)\")\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c ca)(*strict*)\n   apply(simp add: derivation_append_def F_DPDA_RMPUE__relation_initial_configuration__LR_def)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_def)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(rule_tac\n      M=\"G2\"\n      in epdaS.some_position_has_details_at_0)\n  apply (metis epdaS.derivation_initial_is_derivation)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimLR_inst_ATS_Simulation_Configuration_Weak_Marked_Effect_axioms: \"\n  ATS_Simulation_Configuration_Weak_Marked_Effect_axioms epdaS_initial_configurations epda_step_labels epdaS_step_relation epdaS_marked_effect epdaS_initial_configurations epdaS_step_relation epdaS_marked_effect F_DPDA_RMPUE__relation_configuration__LR F_DPDA_RMPUE__relation_initial_configuration__LR F_DPDA_RMPUE__relation_effect__LR F_DPDA_RMPUE__relation_structure__LR F_DPDA_RMPUE__relation_initial_simulation__LR F_DPDA_RMPUE__relation_step_simulation__LR\"\n  apply(simp add: ATS_Simulation_Configuration_Weak_Marked_Effect_axioms_def)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(rule epdaS_epdaS_RMP_StateSimLR.relation_step_simulation_preservation_PROVE2)\n    apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n    prefer 2\n    apply(rename_tac G1 G2 d1' d2')(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(thin_tac \"epdaS_epdaS_RMP_StateSimLR.relation_step_simulation_preservation G1 G2 d1' d2'\")\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(metis epdaS_epdaS_RMP_StateSimLR_inst_relation_step_simulation_marked_effect)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 d1' d2')(*strict*)\n  apply(rule epdaS_epdaS_RMP_StateSimLR.relation_initial_simulation_preservation_PROVE2)\n   apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   prefer 2\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(thin_tac \"epdaS_epdaS_RMP_StateSimLR.relation_initial_simulation_preservation G1 G2 d1' d2'\")\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(metis epdaS_epdaS_RMP_StateSimLR_inst_relation_initial_simulation_marked_effect)\n  done\n\ninterpretation \"epdaS_epdaS_RMP_StateSimLR\" : ATS_Simulation_Configuration_Weak_Marked_Effect\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaS_configurations\"\n  (* initial_configurations1 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaS_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaS_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_DPDA_RMPUE__relation_configuration__LR\"\n  (* relation_initial_configuration *)\n  \"F_DPDA_RMPUE__relation_initial_configuration__LR\"\n  (* relation_effect *)\n  \"F_DPDA_RMPUE__relation_effect__LR\"\n  (* relation_TSstructure *)\n  \"F_DPDA_RMPUE__relation_structure__LR\"\n  (* relation_initial_simulation *)\n  \"F_DPDA_RMPUE__relation_initial_simulation__LR\"\n  (* relation_step_simulation *)\n  \"F_DPDA_RMPUE__relation_step_simulation__LR\"\n  apply(simp add: LOCALE_DEFS epda_interpretations)\n  apply(simp add: epdaS_epdaS_RMP_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms epdaS_epdaS_RMP_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms epdaS_epdaS_RMP_StateSimLR_inst_ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms epdaS_epdaS_RMP_StateSimLR_inst_ATS_Simulation_Configuration_Weak_Marked_Effect_axioms )\n  done\n\nlemma F_DPDA_RMPUE__preserves_lang1: \"\n  valid_dpda G\n  \\<Longrightarrow> push_and_pop_edges_seperated G\n  \\<Longrightarrow> read_edges_seperated G\n  \\<Longrightarrow> epdaS.marked_language G \\<subseteq> epdaS.marked_language (F_DPDA_RMPUE G)\"\n  apply(rule_tac\n      t=\"epdaS.marked_language G\"\n      and s=\"epdaS.finite_marked_language G\"\n      in subst)\n   apply (rule epdaS.AX_marked_language_finite)\n   apply(simp add: valid_dpda_def valid_pda_def)\n  apply(rule_tac\n      t=\"epdaS.marked_language (F_DPDA_RMPUE G)\"\n      and s=\"epdaS.finite_marked_language (F_DPDA_RMPUE G)\"\n      in ssubst)\n   apply(rule sym)\n   apply(rule epdaS.AX_marked_language_finite)\n   apply (rule F_DPDA_RMPUE__preserves_epda)\n   apply(force)\n  apply(subgoal_tac \"left_total_on (F_DPDA_RMPUE__relation_effect__LR SSG1 SSG2) (epdaS.finite_marked_language SSG1) (epdaS.finite_marked_language SSG2)\" for SSG1 SSG2)\n   prefer 2\n   apply(rule_tac\n      ?G1.0=\"G\"\n      in epdaS_epdaS_RMP_StateSimLR.ATS_Simulation_Configuration_Weak_Marked_Effect_sound)\n   apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(erule_tac\n      x=\"x\"\n      in ballE)\n   apply(rename_tac x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x b)(*strict*)\n   prefer 2\n   apply(rename_tac x)(*strict*)\n   apply(force)\n  apply(rename_tac x b)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_effect__LR_def)\n  done\n\ndefinition F_DPDA_RMPUE__relation_TSstructure__RL :: \"\n  (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RMPUE__relation_TSstructure__RL G1 G2 \\<equiv>\n  valid_dpda G2\n  \\<and> G1 = F_DPDA_RMPUE G2\n  \\<and> push_and_pop_edges_seperated G2\n  \\<and> read_edges_seperated G2\"\n\ndefinition F_DPDA_RMPUE__relation_configuration__RL :: \"\n  (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RMPUE__relation_configuration__RL G1 G2 c1 c2 \\<equiv>\n  F_DPDA_RMPUE__relation_TSstructure__RL G1 G2\n  \\<and> c1 \\<in> epdaS.get_accessible_configurations G1\n  \\<and> c2 = F_DPDA_RMPUE__conf_old__LR_rev c1\"\n\ndefinition F_DPDA_RMPUE__relation_initial_configuration__RL :: \"\n  (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RMPUE__relation_initial_configuration__RL G1 G2 c1 c2 \\<equiv>\n  F_DPDA_RMPUE__relation_TSstructure__RL G1 G2\n  \\<and> c1 \\<in> epdaS_initial_configurations G1\n  \\<and> c2 = F_DPDA_RMPUE__conf_old__LR_rev c1\"\n\ndefinition F_DPDA_RMPUE__relation_effect__RL :: \"\n  (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RMPUE__relation_effect__RL G1 G2 w1 w2 \\<equiv>\n  F_DPDA_RMPUE__relation_TSstructure__RL G1 G2\n  \\<and> w1 = w2\"\n\ndefinition F_DPDA_RMPUE__relation_step_simulation__LRRL :: \"\n  (('state, 'event, 'stack) DT_state_or_edge_nat, 'event , 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda_step_label\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event , 'stack) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> (('state, 'event, 'stack) epda_step_label, ('state, 'event, 'stack) epdaS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RMPUE__relation_step_simulation__LRRL G1 G2 c1 e c1' c2 d \\<equiv>\n  case edge_trg e of cons_state_or_edge_nat_old q\n  \\<Rightarrow> (case edge_src e of cons_state_or_edge_nat_old q\n    \\<Rightarrow> d = der2\n      (F_DPDA_RMPUE__conf_old__LR_rev c1)\n        (F_DPDA_RMPUE__edge_else__RL e)\n      (F_DPDA_RMPUE__conf_old__LR_rev c1')\n    | cons_state_or_edge_nat_new e' n\n    \\<Rightarrow> d = der1 (F_DPDA_RMPUE__conf_old__LR_rev c1))\n  | cons_state_or_edge_nat_new e' n\n  \\<Rightarrow> (case edge_src e of cons_state_or_edge_nat_old q\n    \\<Rightarrow> d = der2\n      (F_DPDA_RMPUE__conf_old__LR_rev c1)\n        e'\n      (F_DPDA_RMPUE__conf_old__LR_rev c1')\n    | cons_state_or_edge_nat_new e' n\n    \\<Rightarrow> d = der1 (F_DPDA_RMPUE__conf_old__LR_rev c1))\"\n\ndefinition F_DPDA_RMPUE__relation_initial_simulation__LRRL :: \"\n  (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'event , 'stack) DT_state_or_edge_nat, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> (('state, 'event , 'stack) epda_step_label, ('state, 'event , 'stack) epdaS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RMPUE__relation_initial_simulation__LRRL G1 G2 c1 d \\<equiv>\n  d = der1 (F_DPDA_RMPUE__conf_old__LR_rev c1)\"\n\nlemma F_DPDA_RMPUE__conf_old__LR_rev_preserves_configurations: \"\n  F_DPDA_RMPUE__relation_TSstructure__RL G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS.get_accessible_configurations G1\n  \\<Longrightarrow> c1 \\<in> epdaS_configurations G1\n  \\<Longrightarrow> F_DPDA_RMPUE__conf_old__LR_rev c1 \\<in> epdaS_configurations G2\"\n  apply(simp add: epdaS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac q i s)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__conf_old__LR_rev_def)\n  apply(case_tac q)\n   apply(rename_tac q i s qa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i s qa)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RMPUE_def)\n   apply(erule disjE)\n    apply(rename_tac i s qa)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac i s qa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i s qa x ia)(*strict*)\n   apply(subgoal_tac \"valid_epda_step_label G2 x\")\n    apply(rename_tac i s qa x ia)(*strict*)\n    apply(simp add: valid_epda_step_label_def)\n    apply(simp add: F_DPDA_RMPUE__state_def)\n    apply(clarsimp)\n    apply(case_tac ia)\n     apply(rename_tac i s qa x ia)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac i s qa x ia nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i s qa x nat)(*strict*)\n    apply(case_tac \"Suc (Suc nat) < length (edge_push x)\")\n     apply(rename_tac i s qa x nat)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac i s qa x nat)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac i s qa x ia)(*strict*)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rename_tac q i s epda_step_label_ext nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i s epda_step_label_ext nat)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RMPUE_def)\n  apply(erule disjE)\n   apply(rename_tac i s epda_step_label_ext nat)(*strict*)\n   apply(force)\n  apply(rename_tac i s epda_step_label_ext nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i s epda_step_label_ext nat x ia)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__state_def)\n  apply(case_tac ia)\n   apply(rename_tac i s epda_step_label_ext nat x ia)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac i s epda_step_label_ext nat x ia nata)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i s epda_step_label_ext nat x nata)(*strict*)\n  apply(case_tac \"Suc (Suc nata) < length (edge_push x)\")\n   apply(rename_tac i s epda_step_label_ext nat x nata)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac i s epda_step_label_ext nat x nata)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i s x nata)(*strict*)\n  apply(subgoal_tac \"valid_epda_step_label G2 x\")\n   apply(rename_tac i s x nata)(*strict*)\n   prefer 2\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rename_tac i s x nata)(*strict*)\n  apply(simp add: valid_epda_step_label_def)\n  apply(rule_tac\n      B=\"set (edge_push x)\"\n      in subset_trans)\n   apply(rename_tac i s x nata)(*strict*)\n   apply (metis List.set_take_subset)\n  apply(rename_tac i s x nata)(*strict*)\n  apply(rule valid_epda_push_in_gamma)\n   apply(rename_tac i s x nata)(*strict*)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rename_tac i s x nata)(*strict*)\n  apply(force)\n  done\n\nlemma F_DPDA_RMPUE__conf_old__LR_rev_preserves_initial_configurations: \"\n  F_DPDA_RMPUE__relation_TSstructure__RL G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS_initial_configurations G1\n  \\<Longrightarrow> F_DPDA_RMPUE__conf_old__LR_rev c1 \\<in> epdaS_initial_configurations G2\"\n  apply(simp add: epdaS_initial_configurations_def)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_rev_def)\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RMPUE_def)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_rev_def)\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RMPUE_def)\n  apply(clarsimp)\n  apply(simp add: epdaS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__conf_old__LR_rev_def F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE_def)\n  apply(clarsimp)\n  apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimRL_inst_relation_initial_simulation: \"\n  (\\<forall>G1 G2. F_DPDA_RMPUE__relation_TSstructure__RL G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<exists>d2. epdaS.derivation_initial G2 d2 \\<and> F_DPDA_RMPUE__relation_initial_configuration__RL G1 G2 c1 (the (get_configuration (d2 0))) \\<and> F_DPDA_RMPUE__relation_initial_simulation__LRRL G1 G2 c1 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_DPDA_RMPUE__relation_configuration__RL G1 G2 c1 (the (get_configuration (d2 n)))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_initial_simulation__LRRL_def)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule epdaS.derivation_initialI)\n    apply(rename_tac G1 G2 c1)(*strict*)\n    apply(rule epdaS.der1_is_derivation)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: get_configuration_def der1_def)\n   apply(rule F_DPDA_RMPUE__conf_old__LR_rev_preserves_initial_configurations)\n    apply(rename_tac G1 G2 c1)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: get_configuration_def der1_def)\n   apply(simp add: F_DPDA_RMPUE__relation_initial_configuration__RL_def)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule_tac\n      x=\"0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule der1_maximum_of_domain)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: get_configuration_def der1_def)\n  apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n  apply(rule epdaS.initial_configurations_are_get_accessible_configurations)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n   apply(rule F_DPDA_RMPUE__preserves_epda)\n   apply(force)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(force)\n  done\n\nlemma F_DPDA_RMPUE__relation_step_simulation__LRRL_maps_to_derivation: \"\n  F_DPDA_RMPUE__relation_TSstructure__RL G1 G2\n  \\<Longrightarrow> F_DPDA_RMPUE__relation_step_simulation__LRRL G1 G2 c1 e1 c1' c2 d2\n  \\<Longrightarrow> F_DPDA_RMPUE__relation_configuration__RL G1 G2 c1 c2\n  \\<Longrightarrow> epdaS_step_relation G1 c1 e1 c1'\n  \\<Longrightarrow> epdaS.derivation G2 d2\"\n  apply(simp add: F_DPDA_RMPUE__relation_step_simulation__LRRL_def)\n  apply(case_tac \"edge_trg e1\")\n   apply(rename_tac q)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"edge_src e1\")\n    apply(rename_tac q qa)(*strict*)\n    apply(clarsimp)\n    apply(rule epdaS.der2_is_derivation)\n    apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_rev_def F_DPDA_RMPUE__edge_else__RL_def)\n    apply(clarsimp)\n    apply(rename_tac q qa w)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RMPUE_def)\n    apply(clarsimp)\n    apply(erule disjE)\n     apply(rename_tac q qa w)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac q qa w x)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__edge_then_def)\n     apply(clarsimp)\n     apply(rename_tac q qa w x xa)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__state_def)\n     apply(case_tac xa)\n      apply(rename_tac q qa w x xa)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac q w x)(*strict*)\n      apply(case_tac \"Suc (Suc 0) < length (edge_push x)\")\n       apply(rename_tac q w x)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac q w x)(*strict*)\n      apply(simp add: F_DPDA_RMPUE__edge_if_def)\n     apply(rename_tac q qa w x xa nat)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac q qa w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q qa w x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_else_def)\n    apply(clarsimp)\n    apply(rename_tac w x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n    apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n    apply(clarsimp)\n    apply(thin_tac \" c1 \\<in> epdaS.get_accessible_configurations (F_DPDA_RMPUE G2)\")\n    apply(rename_tac w x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE_def)\n    apply(case_tac x)\n    apply(rename_tac w x edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n    apply(force)\n   apply(rename_tac q epda_step_label_ext nat)(*strict*)\n   apply(clarsimp)\n   apply(rule epdaS.der1_is_derivation)\n  apply(rename_tac epda_step_label_ext nat)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"edge_src e1\")\n   apply(rename_tac epda_step_label_ext nat q)(*strict*)\n   prefer 2\n   apply(rename_tac epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n   apply(clarsimp)\n   apply(rule epdaS.der1_is_derivation)\n  apply(rename_tac epda_step_label_ext nat q)(*strict*)\n  apply(clarsimp)\n  apply(rule epdaS.der2_is_derivation)\n  apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_rev_def)\n  apply(clarsimp)\n  apply(rename_tac epda_step_label_ext nat q w)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL_def)\n  apply(clarsimp)\n  apply(thin_tac \"c1 \\<in> epdaS.get_accessible_configurations (F_DPDA_RMPUE G2)\")\n  apply(rename_tac epda_step_label_ext nat q w)(*strict*)\n  apply(simp add: F_DPDA_RMPUE_def)\n  apply(clarsimp)\n  apply(erule disjE)\n   apply(rename_tac epda_step_label_ext nat q w)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac epda_step_label_ext nat q w x)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_if_def)\n   apply(simp add: F_DPDA_RMPUE__edge_else_def)\n  apply(rename_tac epda_step_label_ext nat q w)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac epda_step_label_ext nat q w x)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__edge_then_def)\n  apply(rename_tac epda_step_label_exta nat q w x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac epda_step_label_ext nat q w x xa)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__state_def)\n  apply(simp add: F_DPDA_RMPUE__edge_if_def)\n  apply(case_tac \"Suc (Suc xa) < length (edge_push x)\")\n   apply(rename_tac epda_step_label_ext nat q w x xa)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac epda_step_label_ext nat q w x xa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac epda_step_label_ext q w xa)(*strict*)\n  apply(case_tac xa)\n   apply(rename_tac epda_step_label_ext q w xa)(*strict*)\n   prefer 2\n   apply(rename_tac epda_step_label_ext q w xa nat)(*strict*)\n   apply(force)\n  apply(rename_tac epda_step_label_ext q w xa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac epda_step_label_ext w)(*strict*)\n  apply(rename_tac e w)\n  apply(rename_tac e w)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(simp add: read_edges_seperated_def)\n  apply(erule_tac\n      x=\"e\"\n      in ballE)\n   apply(rename_tac e w)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac e w)(*strict*)\n  apply(case_tac \"edge_event e\")\n   apply(rename_tac e w)(*strict*)\n   prefer 2\n   apply(rename_tac e w a)(*strict*)\n   apply(clarsimp)\n   apply(simp add: FB_executing_edge_def strict_executing_edge_def)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rename_tac e w)(*strict*)\n  apply(clarsimp)\n  apply(simp add: FB_executing_edge_def strict_executing_edge_def)\n  apply(simp add: push_and_pop_edges_seperated_def)\n  apply(erule_tac\n      x=\"e\"\n      in ballE)\n   apply(rename_tac e w)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac e w)(*strict*)\n  apply(simp add: F_DPDA_SPPE__edge_if_def)\n  apply(subgoal_tac \"\\<exists>x. edge_pop e=[x]\")\n   apply(rename_tac e w)(*strict*)\n   prefer 2\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"e\"\n      and P=\"\\<lambda>e. valid_epda_step_label G2 e\"\n      in ballE)\n    apply(rename_tac e w)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac e w)(*strict*)\n   apply(erule_tac\n      x=\"e\"\n      in ballE)\n    apply(rename_tac e w)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac e w)(*strict*)\n   apply(case_tac \"edge_pop e\")\n    apply(rename_tac e w)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac e w a list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac e w)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac e w x)(*strict*)\n  apply(case_tac \"edge_push e\")\n   apply(rename_tac e w x)(*strict*)\n   apply(force)\n  apply(rename_tac e w x a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. edge_push e = w' @ [x']\")\n   apply(rename_tac e w x a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac e w x a list)(*strict*)\n  apply(thin_tac \"edge_push e= a # list\")\n  apply(clarsimp)\n  apply(rename_tac e w w' x')(*strict*)\n  apply (metis One_nat_def append_take_drop_id last_drop_rev_nth length_0_conv less_zeroE)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimRL_step_relation_step_simulation: \"\n  \\<forall>G1 G2. F_DPDA_RMPUE__relation_TSstructure__RL G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_DPDA_RMPUE__relation_configuration__RL G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<exists>d2. epdaS.derivation G2 d2 \\<and> epdaS.belongs G2 d2 \\<and> the (get_configuration (d2 0)) = c2 \\<and> F_DPDA_RMPUE__relation_step_simulation__LRRL G1 G2 c1 e1 c1' c2 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_DPDA_RMPUE__relation_configuration__RL G1 G2 c1' (the (get_configuration (d2 n))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_step_simulation__LRRL_def)\n  apply(case_tac \"edge_trg e1\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"edge_src e1\")\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(clarsimp)\n    apply(rule context_conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(rule F_DPDA_RMPUE__relation_step_simulation__LRRL_maps_to_derivation)\n        apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n        apply(force)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n       prefer 2\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_step_simulation__LRRL_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(rule epdaS.der2_belongs_prime)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n       apply (metis epdaS_epdaS_RMP_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs F_DPDA_RMPUE__relation_structure__LR_def F_DPDA_RMPUE__relation_TSstructure__RL_def)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n     apply(rule F_DPDA_RMPUE__conf_old__LR_rev_preserves_configurations)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(rule_tac\n      A=\"epdaS.get_accessible_configurations G1\"\n      in set_mp)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      apply(rule epdaS.get_accessible_configurations_are_configurations)\n      apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n      apply(rule F_DPDA_RMPUE__preserves_epda)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply (metis)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(simp add: get_configuration_def der2_def)\n     apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(rule der2_maximum_of_domain)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(simp (no_asm) add: der2_def get_configuration_def)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n    apply(rule_tac\n      ?e1.0=\"e1\"\n      in epdaS.der2_preserves_get_accessible_configurations)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n      apply(rule F_DPDA_RMPUE__preserves_epda)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(rule epdaS.der2_is_derivation)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n   apply(clarsimp)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n    apply(rule epdaS.der1_is_derivation)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n    apply(rule epdaS.der1_belongs)\n    apply(rule F_DPDA_RMPUE__conf_old__LR_rev_preserves_configurations)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n    apply(rule_tac\n      A=\"epdaS.get_accessible_configurations G1\"\n      in set_mp)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n     apply(rule epdaS.get_accessible_configurations_are_configurations)\n     apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n     apply(rule F_DPDA_RMPUE__preserves_epda)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n    apply(simp add: der1_def get_configuration_def)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n   apply(rule_tac\n      x=\"0\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n    apply(rule der1_maximum_of_domain)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n   apply(simp add: der1_def get_configuration_def)\n   apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n    apply(rule_tac\n      ?e1.0=\"e1\"\n      in epdaS.der2_preserves_get_accessible_configurations)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n      apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n      apply(rule F_DPDA_RMPUE__preserves_epda)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n    apply(rule epdaS.der2_is_derivation)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' q epda_step_label_ext nat)(*strict*)\n   apply(thin_tac \"c1 \\<in> epdaS.get_accessible_configurations G1\")\n   apply(rename_tac G1 G2 c1 e1 c1' q epda_step_label_ext nat)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_rev_def)\n   apply(simp add: epdaS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' q epda_step_label_ext nat w)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 e1 c1' q epda_step_label_ext nat w)(*strict*)\n   apply(simp add: F_DPDA_RMPUE_def epda_step_labels_def)\n   apply(clarsimp)\n   apply(erule disjE)\n    apply(rename_tac G2 c1 e1 c1' q epda_step_label_ext nat w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G2 c1 e1 c1' q epda_step_label_ext nat w x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_then_def)\n    apply(rename_tac G2 c1 e1 c1' q epda_step_label_exta nat w x)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G2 c1 c1' q epda_step_label_ext nat w x xa)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__state_def)\n    apply(case_tac \"Suc (Suc xa) < length (edge_push x)\")\n     apply(rename_tac G2 c1 c1' q epda_step_label_ext nat w x xa)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G2 c1 c1' q epda_step_label_ext nat w x xa)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_if_def)\n    apply(clarsimp)\n    apply(rename_tac G2 c1 c1' epda_step_label_ext nat w)(*strict*)\n    apply(simp add: option_to_list_def)\n    apply(subgoal_tac \"Suc (Suc nat) = length (edge_push epda_step_label_ext)\")\n     apply(rename_tac G2 c1 c1' epda_step_label_ext nat w)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G2 c1 c1' epda_step_label_ext nat w)(*strict*)\n    apply(clarsimp)\n    apply(case_tac nat)\n     apply(rename_tac G2 c1 c1' epda_step_label_ext nat w)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G2 c1 c1' epda_step_label_ext nat w nata)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G2 c1 c1' epda_step_label_ext w nata)(*strict*)\n    apply(rule take_nth_rev)\n    apply(force)\n   apply(rename_tac G2 c1 e1 c1' q epda_step_label_ext nat w)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 c1' q epda_step_label_ext nat w x)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_else_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"edge_src e1\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n   apply(clarsimp)\n   apply(rule context_conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n    apply(rule F_DPDA_RMPUE__relation_step_simulation__LRRL_maps_to_derivation)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_step_simulation__LRRL_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n   apply(rule context_conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n    apply(rule epdaS.der2_belongs)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n      apply(rule F_DPDA_RMPUE__conf_old__LR_rev_preserves_configurations)\n        apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n        apply(force)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n       apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n      apply(rule_tac\n      A=\"epdaS.get_accessible_configurations G1\"\n      in set_mp)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n       apply(rule epdaS.get_accessible_configurations_are_configurations)\n       apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n       apply(rule F_DPDA_RMPUE__preserves_epda)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n      apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def epda_step_labels_def F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE_def)\n     apply(clarsimp)\n     apply(rename_tac G2 c1 e1 c1' epda_step_label_ext nat q)(*strict*)\n     apply(erule disjE)\n      apply(rename_tac G2 c1 e1 c1' epda_step_label_ext nat q)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac G2 c1 e1 c1' epda_step_label_ext nat q x)(*strict*)\n      apply(simp add: F_DPDA_RMPUE__edge_then_def)\n      apply(rename_tac G2 c1 e1 c1' epda_step_label_exta nat q x)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac G2 c1 c1' epda_step_label_exta nat q x xa)(*strict*)\n      apply(simp add: F_DPDA_RMPUE__state_def)\n      apply(case_tac xa)\n       apply(rename_tac G2 c1 c1' epda_step_label_exta nat q x xa)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac G2 c1 c1' epda_step_label_exta nat x)(*strict*)\n       apply(case_tac \"Suc (Suc 0) < length (edge_push x)\")\n        apply(rename_tac G2 c1 c1' epda_step_label_exta nat x)(*strict*)\n        apply(clarsimp)\n       apply(rename_tac G2 c1 c1' epda_step_label_exta nat x)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac G2 c1 c1' epda_step_label_exta nat q x xa nata)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac G2 c1 e1 c1' epda_step_label_ext nat q)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G2 c1 c1' epda_step_label_ext nat q x)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__edge_else_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n    apply(rule F_DPDA_RMPUE__conf_old__LR_rev_preserves_configurations)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n     apply(rule_tac\n      ?e1.0=\"e1\"\n      in epdaS.der2_preserves_get_accessible_configurations)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n       apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n       apply(rule F_DPDA_RMPUE__preserves_epda)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n     apply(rule epdaS.der2_is_derivation)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n    apply(rule epdaS.AX_step_relation_preserves_belongsC)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n      apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n      apply(rule F_DPDA_RMPUE__preserves_epda)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n    apply(rule_tac\n      A=\"epdaS.get_accessible_configurations G1\"\n      in set_mp)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n     apply(rule epdaS.get_accessible_configurations_are_configurations)\n     apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n     apply(rule F_DPDA_RMPUE__preserves_epda)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n    apply(simp add: get_configuration_def der2_def)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n   apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n    apply(rule der2_maximum_of_domain)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n   apply(simp (no_asm) add: der1_def get_configuration_def)\n   apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n    apply(rule_tac\n      ?e1.0=\"e1\"\n      in epdaS.der2_preserves_get_accessible_configurations)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n      apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n      apply(rule F_DPDA_RMPUE__preserves_epda)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n    apply(rule epdaS.der2_is_derivation)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext nat q)(*strict*)\n   apply(simp add: der2_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n   apply(rule epdaS.der1_is_derivation)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n   apply(rule epdaS.der1_belongs)\n   apply(rule F_DPDA_RMPUE__conf_old__LR_rev_preserves_configurations)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n   apply(rule_tac\n      A=\"epdaS.get_accessible_configurations G1\"\n      in set_mp)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n    apply(rule epdaS.get_accessible_configurations_are_configurations)\n    apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n    apply(rule F_DPDA_RMPUE__preserves_epda)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n   apply(simp add: der1_def get_configuration_def)\n   apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n  apply(rule_tac\n      x=\"0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n   apply(rule der1_maximum_of_domain)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n  apply(simp add: der1_def get_configuration_def)\n  apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n   apply(rule_tac\n      ?e1.0=\"e1\"\n      in epdaS.der2_preserves_get_accessible_configurations)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n     apply(rule F_DPDA_RMPUE__preserves_epda)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n   apply(rule epdaS.der2_is_derivation)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n  apply(rename_tac e1 n e2 m)\n  apply(rename_tac G1 G2 c1 c2 e1a c1' e1 n e2 m)(*strict*)\n  apply(subgoal_tac \"e1=e2 \\<and> n=Suc m\")\n   apply(rename_tac G1 G2 c1 c2 e1a c1' e1 n e2 m)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1a c1' e1 n e2 m)(*strict*)\n   apply(thin_tac \"c1 \\<in> epdaS.get_accessible_configurations G1\")\n   apply(rename_tac G1 G2 c1 e1a c1' e1 n e2 m)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 e1a c1' e1 n e2 m)(*strict*)\n   apply(simp add: epda_step_labels_def)\n   apply(simp add: F_DPDA_RMPUE_def)\n   apply(clarsimp)\n   apply(erule disjE)\n    apply(rename_tac G2 c1 e1a c1' e1 n e2 m)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G2 c1 e1a c1' e1 n e2 m x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_then_def)\n    apply(clarsimp)\n    apply(rename_tac G2 c1 c1' e1 n e2 m x xa)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_if_def)\n    apply(simp add: F_DPDA_RMPUE__state_def)\n    apply(case_tac \"Suc (Suc xa) < length (edge_push x)\")\n     apply(rename_tac G2 c1 c1' e1 n e2 m x xa)(*strict*)\n     prefer 2\n     apply(clarsimp)\n    apply(rename_tac G2 c1 c1' e1 n e2 m x xa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G2 c1 c1' e1 e2 m xa)(*strict*)\n    apply(case_tac xa)\n     apply(rename_tac G2 c1 c1' e1 e2 m xa)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G2 c1 c1' e1 e2 m xa nat)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G2 c1 e1a c1' e1 n e2 m)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 c1' e1 n e2 m x)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_else_def)\n  apply(rename_tac G1 G2 c1 c2 e1a c1' e1 n e2 m)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1a c1' e2 m)(*strict*)\n  apply(thin_tac \"c1 \\<in> epdaS.get_accessible_configurations G1\")\n  apply(rename_tac G1 G2 c1 e1a c1' e2 m)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1a c1' e2 m)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__conf_old__LR_rev_def)\n  apply(simp only: epdaS_step_relation_def)\n  apply(subgoal_tac \"\\<lparr>epdaS_conf_state = edge_trg e2, epdaS_conf_scheduler = option_to_list (edge_event e1a) @ epdaS_conf_scheduler c1', epdaS_conf_stack = take (length (edge_push e2) - Suc m) (edge_push e2) @ epdaS_conf_stack c1\\<rparr> = \\<lparr>epdaS_conf_state = edge_trg e2, epdaS_conf_scheduler = epdaS_conf_scheduler c1', epdaS_conf_stack = take (length (edge_push e2) - Suc (Suc m)) (edge_push e2) @ epdaS_conf_stack c1'\\<rparr>\")\n   apply(rename_tac G2 c1 e1a c1' e2 m)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G2 c1 e1a c1' e2 m)(*strict*)\n  apply(subgoal_tac \"\\<exists>x y. edge_pop e1a = [x] \\<and> edge_push e1a = [y,x]\")\n   apply(rename_tac G2 c1 e1a c1' e2 m)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac G2 c1 e1a c1' e2 m w)(*strict*)\n   apply(simp add: epda_step_labels_def F_DPDA_RMPUE_def)\n   apply(clarsimp)\n   apply(erule disjE)\n    apply(rename_tac G2 c1 e1a c1' e2 m w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G2 c1 e1a c1' e2 m w x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_then_def)\n    apply(clarsimp)\n   apply(rename_tac G2 c1 e1a c1' e2 m w)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 c1' e2 m w x)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_else_def)\n  apply(rename_tac G2 c1 e1a c1' e2 m)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1a c1' e2 m x y w)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 e1a c1' e2 m x y w)(*strict*)\n   apply(simp add: option_to_list_def)\n   apply(simp add: F_DPDA_RMPUE_def epda_step_labels_def)\n   apply(clarsimp)\n   apply(erule disjE)\n    apply(rename_tac G2 c1 e1a c1' e2 m x y w)(*strict*)\n    prefer 2\n    apply(rename_tac G2 c1 e1a c1' e2 m x y w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G2 c1 c1' e2 m x y w xa)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_else_def)\n   apply(rename_tac G2 c1 e1a c1' e2 m x y w)(*strict*)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RMPUE__edge_then_def)\n   apply(clarsimp)\n  apply(rename_tac G2 c1 e1a c1' e2 m x y w)(*strict*)\n  apply(simp add: F_DPDA_RMPUE_def epda_step_labels_def)\n  apply(clarsimp)\n  apply(erule disjE)\n   apply(rename_tac G2 c1 e1a c1' e2 m x y w)(*strict*)\n   prefer 2\n   apply(rename_tac G2 c1 e1a c1' e2 m x y w)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 c1' e2 m x y w xa)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_else_def)\n  apply(rename_tac G2 c1 e1a c1' e2 m x y w)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1a c1' e2 m x y w xa)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__edge_then_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 c1' e2 m w xa xb)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__state_def)\n  apply(case_tac xb)\n   apply(rename_tac G2 c1 c1' e2 m w xa xb)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G2 c1 c1' e2 m w xa xb nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 c1' e2 w nat)(*strict*)\n  apply(case_tac \"Suc (Suc (Suc nat)) < length (edge_push e2)\")\n   apply(rename_tac G2 c1 c1' e2 w nat)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G2 c1 c1' e2 w nat)(*strict*)\n  apply(clarsimp)\n  apply(rule take_rev_append_nth)\n  apply(force)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimRL_inst_AX_TSstructure_relation_TSstructure1_belongs: \"\n  (\\<forall>G1. Ex (F_DPDA_RMPUE__relation_TSstructure__RL G1) \\<longrightarrow> valid_epda G1)\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n  apply(clarsimp)\n  apply(rename_tac G2)(*strict*)\n  apply (metis F_DPDA_RMPUE__preserves_epda)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimRL_inst_AX_TSstructure_relation_TSstructure2_belongs: \"\n  (\\<forall>G1 G2. F_DPDA_RMPUE__relation_TSstructure__RL G1 G2 \\<longrightarrow> valid_epda G2)\"\n  apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n  apply(clarsimp)\n  apply(rename_tac G2)(*strict*)\n  apply (metis valid_dpda_def valid_pda_def)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axioms: \"\n  ATS_Simulation_Configuration_Weak_axioms valid_epda epdaS_initial_configurations epda_step_labels epdaS_step_relation valid_epda epdaS_configurations epdaS_initial_configurations epda_step_labels epdaS_step_relation F_DPDA_RMPUE__relation_configuration__RL F_DPDA_RMPUE__relation_initial_configuration__RL F_DPDA_RMPUE__relation_TSstructure__RL F_DPDA_RMPUE__relation_initial_simulation__LRRL F_DPDA_RMPUE__relation_step_simulation__LRRL\"\n  apply(simp add: ATS_Simulation_Configuration_Weak_axioms_def epdaS_epdaS_RMP_StateSimRL_inst_relation_initial_simulation epdaS_epdaS_RMP_StateSimRL_step_relation_step_simulation epdaS_epdaS_RMP_StateSimRL_inst_AX_TSstructure_relation_TSstructure1_belongs epdaS_epdaS_RMP_StateSimRL_inst_AX_TSstructure_relation_TSstructure2_belongs)\n  done\n\ninterpretation \"epdaS_epdaS_RMP_StateSimRL\" : ATS_Simulation_Configuration_Weak\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaS_configurations\"\n  (* initial_configurations1 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaS_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaS_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_DPDA_RMPUE__relation_configuration__RL\"\n  (* relation_initial_configuration *)\n  \"F_DPDA_RMPUE__relation_initial_configuration__RL\"\n  (* relation_effect *)\n  \"F_DPDA_RMPUE__relation_effect__RL\"\n  (* relation_TSstructure *)\n  \"F_DPDA_RMPUE__relation_TSstructure__RL\"\n  (* relation_initial_simulation *)\n  \"F_DPDA_RMPUE__relation_initial_simulation__LRRL\"\n  (* relation_step_simulation *)\n  \"F_DPDA_RMPUE__relation_step_simulation__LRRL\"\n  apply(simp add: LOCALE_DEFS epda_interpretations)\n  apply(simp add: epdaS_epdaS_RMP_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axioms)\n  done\n\nlemma F_DPDA_RMPUE__conf_old__LR_rev_preserves_marking_configurations: \"\n  F_DPDA_RMPUE__relation_TSstructure__RL G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS_marking_configurations G1\n  \\<Longrightarrow> c1 \\<in> epdaS.get_accessible_configurations G1\n  \\<Longrightarrow> F_DPDA_RMPUE__conf_old__LR_rev c1 \\<in> epdaS_marking_configurations G2\"\n  apply(simp add: epdaS_marking_configurations_def)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_rev_def F_DPDA_RMPUE_def)\n   apply(case_tac \"epdaS_conf_state c1\")\n    apply(rename_tac q)(*strict*)\n    apply(force)\n   apply(rename_tac epda_step_label_ext nat)(*strict*)\n   apply(force)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_rev_def F_DPDA_RMPUE_def)\n   apply(case_tac \"epdaS_conf_state c1\")\n    apply(rename_tac q)(*strict*)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RMPUE__conf_old__LR_rev_def F_DPDA_RMPUE_def)\n    apply(clarsimp)\n   apply(rename_tac epda_step_label_ext nat)(*strict*)\n   apply(case_tac \"epdaS_conf_state c1\")\n    apply(rename_tac epda_step_label_ext nat q)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac epda_step_label_ext nat)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_rev_def F_DPDA_RMPUE_def)\n   apply(clarsimp)\n  apply(rule F_DPDA_RMPUE__conf_old__LR_rev_preserves_configurations)\n    apply(force)\n   apply(force)\n  apply(force)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimRL_inst_relation_step_simulation_marking_condition: \"\n  \\<forall>G1 G2. F_DPDA_RMPUE__relation_TSstructure__RL G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_DPDA_RMPUE__relation_configuration__RL G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<forall>d2. F_DPDA_RMPUE__relation_step_simulation__LRRL G1 G2 c1 e1 c1' c2 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_DPDA_RMPUE__relation_initial_configuration__RL G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der2 c1 e1 c1') deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> epdaS_marking_condition G1 (derivation_append deri1 (der2 c1 e1 c1') deri1n) \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_DPDA_RMPUE__relation_configuration__RL F_DPDA_RMPUE__relation_initial_simulation__LRRL F_DPDA_RMPUE__relation_step_simulation__LRRL G1 G2 (derivation_append deri1 (der2 c1 e1 c1') deri1n) (Suc deri1n) (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> epdaS_marking_condition G2 (derivation_append deri2 d2 deri2n))))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: epdaS_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(case_tac \"i\\<le>deri1n\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(subgoal_tac \"deri1 i = Some (pair e c)\")\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n    prefer 2\n    apply(simp add: derivation_append_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(thin_tac \"derivation_append deri1 (der2 c1 e1 c1') deri1n i = Some (pair e c)\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(simp add: epdaS_epdaS_RMP_StateSimRL.simulating_derivation_def)\n   apply(clarsimp)\n   apply(simp add: epdaS_epdaS_RMP_StateSimRL.simulating_derivation_DEF_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"i\"\n      in allE)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c y)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c y)(*strict*)\n   apply(case_tac y)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c y option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c option b)(*strict*)\n   apply(rename_tac e c)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(rule_tac\n      x=\"f i\"\n      in exI)\n   apply(rule_tac\n      x=\"e\"\n      in exI)\n   apply(rule_tac\n      x=\"c\"\n      in exI)\n   apply(clarsimp)\n   apply(rule_tac\n      t=\"c\"\n      and s=\"F_DPDA_RMPUE__conf_old__LR_rev ca\"\n      in ssubst)\n    apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__conf_old__LR_rev_def derivation_append_def get_configuration_def)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(rule F_DPDA_RMPUE__conf_old__LR_rev_preserves_marking_configurations)\n     apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(rule_tac\n      t=\"ca\"\n      and s=\"the (get_configuration (derivation_append deri1 (der2 c1 e1 c1') deri1n i))\"\n      in ssubst)\n    apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(simp add: get_configuration_def derivation_append_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(subgoal_tac \"i=Suc deri1n\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e c)(*strict*)\n   apply(subgoal_tac \"c=c1'\")\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e c)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e)(*strict*)\n    apply(simp add: epdaS_epdaS_RMP_StateSimRL.simulating_derivation_def)\n    apply(simp add: epdaS_epdaS_RMP_StateSimRL.simulating_derivation_DEF_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"Suc deri1n\"\n      in allE)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e y)(*strict*)\n    apply(rule_tac\n      x=\"deri2n+n\"\n      in exI)\n    apply(case_tac y)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e y option b)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e option b)(*strict*)\n    apply(rename_tac e c)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n    apply(rule_tac\n      t=\"c\"\n      and s=\"F_DPDA_RMPUE__conf_old__LR_rev c1'\"\n      in ssubst)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def derivation_append_def get_configuration_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n    apply(rule F_DPDA_RMPUE__conf_old__LR_rev_preserves_marking_configurations)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n    apply(simp add: epdaS.get_accessible_configurations_def)\n    apply(rule_tac\n      x=\"derivation_append deri1 (der2 c1 e1 c1') deri1n \"\n      in exI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n     apply(rule epdaS.derivation_append_preserves_derivation_initial)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n       apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n       apply (rule F_DPDA_RMPUE__preserves_epda)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n     apply(rule epdaS.derivation_append_preserves_derivation)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n       apply (metis epdaS.derivation_initial_is_derivation)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n      apply(rule epdaS.der2_is_derivation)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n     apply(simp add: derivation_append_fit_def)\n     apply(case_tac \"deri1 deri1n\")\n      apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c a)(*strict*)\n     apply(clarsimp)\n     apply(case_tac a)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c a option b)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c option b)(*strict*)\n     apply(simp add: der2_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n    apply(rule_tac\n      x=\"Suc deri1n\"\n      in exI)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e c)(*strict*)\n   apply(simp add: get_configuration_def derivation_append_def der2_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(case_tac \"i>Suc deri1n\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(clarsimp)\n  apply(simp add: derivation_append_def der2_def)\n  apply(case_tac \"i-deri1n\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c nat)(*strict*)\n  apply(clarsimp)\n  apply(case_tac nat)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i c)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c nat nata)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimRL_inst_relation_initial_simulation_marking_condition: \"\n  \\<forall>G1 G2. F_DPDA_RMPUE__relation_TSstructure__RL G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<forall>d2. F_DPDA_RMPUE__relation_initial_simulation__LRRL G1 G2 c1 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_DPDA_RMPUE__relation_initial_configuration__RL G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der1 c1) deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> epdaS_marking_condition G1 (derivation_append deri1 (der1 c1) deri1n) \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_DPDA_RMPUE__relation_configuration__RL F_DPDA_RMPUE__relation_initial_simulation__LRRL F_DPDA_RMPUE__relation_step_simulation__LRRL G1 G2 (derivation_append deri1 (der1 c1) deri1n) deri1n (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> epdaS_marking_condition G2 (derivation_append deri2 d2 deri2n))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: epdaS_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(case_tac \"i\\<le>deri1n\")\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(subgoal_tac \"deri1 i = Some (pair e c)\")\n    apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n    prefer 2\n    apply(simp add: derivation_append_def)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(simp add: epdaS_epdaS_RMP_StateSimRL.simulating_derivation_def)\n   apply(clarsimp)\n   apply(simp add: epdaS_epdaS_RMP_StateSimRL.simulating_derivation_DEF_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"i\"\n      in allE)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c y)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n   apply(clarsimp)\n   apply(case_tac y)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c y option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c option b)(*strict*)\n   apply(rename_tac e c)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(rule_tac\n      x=\"f i\"\n      in exI)\n   apply(rule_tac\n      x=\"e\"\n      in exI)\n   apply(rule_tac\n      x=\"c\"\n      in exI)\n   apply(clarsimp)\n   apply(rule_tac\n      t=\"c\"\n      and s=\"F_DPDA_RMPUE__conf_old__LR_rev ca\"\n      in ssubst)\n    apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__conf_old__LR_rev_def derivation_append_def get_configuration_def)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(rule F_DPDA_RMPUE__conf_old__LR_rev_preserves_marking_configurations)\n     apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(subgoal_tac \"i=deri1n\")\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(case_tac \"i>deri1n\")\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(clarsimp)\n  apply(simp add: derivation_append_def der1_def)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimLR_inst_ATS_Simulation_Configuration_WeakRL_COND_axioms: \"\n  ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms epdaS_initial_configurations epda_step_labels epdaS_step_relation epdaS_marking_condition epdaS_initial_configurations epdaS_step_relation epdaS_marking_condition F_DPDA_RMPUE__relation_configuration__RL F_DPDA_RMPUE__relation_initial_configuration__RL F_DPDA_RMPUE__relation_TSstructure__RL F_DPDA_RMPUE__relation_initial_simulation__LRRL F_DPDA_RMPUE__relation_step_simulation__LRRL\"\n  apply(simp add: ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms_def)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(rule epdaS_epdaS_RMP_StateSimRL.relation_step_simulation_preservation_PROVE2)\n    apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n    prefer 2\n    apply(rename_tac G1 G2 d1' d2')(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(thin_tac \"epdaS_epdaS_RMP_StateSimRL.relation_step_simulation_preservation G1 G2 d1' d2'\")\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(metis epdaS_epdaS_RMP_StateSimRL_inst_relation_step_simulation_marking_condition)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 d1' d2')(*strict*)\n  apply(rule epdaS_epdaS_RMP_StateSimRL.relation_initial_simulation_preservation_PROVE2)\n   apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   prefer 2\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(thin_tac \"epdaS_epdaS_RMP_StateSimRL.relation_initial_simulation_preservation G1 G2 d1' d2'\")\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(metis epdaS_epdaS_RMP_StateSimRL_inst_relation_initial_simulation_marking_condition)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimRL_inst_relation_step_simulation_marked_effect: \"\n  (\\<forall>G1 G2. F_DPDA_RMPUE__relation_TSstructure__RL G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_DPDA_RMPUE__relation_configuration__RL G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<forall>d2. F_DPDA_RMPUE__relation_step_simulation__LRRL G1 G2 c1 e1 c1' c2 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_DPDA_RMPUE__relation_initial_configuration__RL G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der2 c1 e1 c1') deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_DPDA_RMPUE__relation_configuration__RL F_DPDA_RMPUE__relation_initial_simulation__LRRL F_DPDA_RMPUE__relation_step_simulation__LRRL G1 G2 (derivation_append deri1 (der2 c1 e1 c1') deri1n) (Suc deri1n) (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> left_total_on (F_DPDA_RMPUE__relation_effect__RL G1 G2) (epdaS_marked_effect G1 (derivation_append deri1 (der2 c1 e1 c1') deri1n)) (epdaS_marked_effect G2 (derivation_append deri2 d2 deri2n))))))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(rule_tac\n      x=\"a\"\n      in bexI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_effect__RL_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(simp add: epdaS_marked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri2 0 = Some (pair None c)\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c ca)(*strict*)\n   apply(simp add: derivation_append_def F_DPDA_RMPUE__relation_initial_configuration__RL_def)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_rev_def)\n   apply(case_tac \"epdaS_conf_state c\")\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c ca q)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c ca epda_step_label_ext nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(rule_tac\n      M=\"G2\"\n      in epdaS.some_position_has_details_at_0)\n  apply (metis epdaS.derivation_initial_is_derivation)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimRL_inst_relation_initial_simulation_marked_effect: \"\n  (\\<forall>G1 G2. F_DPDA_RMPUE__relation_TSstructure__RL G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<forall>d2. F_DPDA_RMPUE__relation_initial_simulation__LRRL G1 G2 c1 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_DPDA_RMPUE__relation_initial_configuration__RL G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der1 c1) deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_DPDA_RMPUE__relation_configuration__RL F_DPDA_RMPUE__relation_initial_simulation__LRRL F_DPDA_RMPUE__relation_step_simulation__LRRL G1 G2 (derivation_append deri1 (der1 c1) deri1n) deri1n (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> left_total_on (F_DPDA_RMPUE__relation_effect__RL G1 G2) (epdaS_marked_effect G1 (derivation_append deri1 (der1 c1) deri1n)) (epdaS_marked_effect G2 (derivation_append deri2 d2 deri2n))))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(rule_tac\n      x=\"a\"\n      in bexI)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_effect__RL_def)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(simp add: epdaS_marked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri2 0 = Some (pair None c)\")\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c ca)(*strict*)\n   apply(simp add: derivation_append_def F_DPDA_RMPUE__relation_initial_configuration__RL_def)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_rev_def)\n   apply(case_tac \"epdaS_conf_state c\")\n    apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c ca q)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c ca epda_step_label_ext nat)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(rule_tac\n      M=\"G2\"\n      in epdaS.some_position_has_details_at_0)\n  apply (metis epdaS.derivation_initial_is_derivation)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimLR_inst_ATS_Simulation_Configuration_WeakRL_ACCEPT_axioms: \"\n  ATS_Simulation_Configuration_Weak_Marked_Effect_axioms epdaS_initial_configurations epda_step_labels epdaS_step_relation epdaS_marked_effect epdaS_initial_configurations epdaS_step_relation epdaS_marked_effect F_DPDA_RMPUE__relation_configuration__RL F_DPDA_RMPUE__relation_initial_configuration__RL F_DPDA_RMPUE__relation_effect__RL F_DPDA_RMPUE__relation_TSstructure__RL F_DPDA_RMPUE__relation_initial_simulation__LRRL F_DPDA_RMPUE__relation_step_simulation__LRRL\"\n  apply(simp add: ATS_Simulation_Configuration_Weak_Marked_Effect_axioms_def)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(rule epdaS_epdaS_RMP_StateSimRL.relation_step_simulation_preservation_PROVE2)\n    apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n    prefer 2\n    apply(rename_tac G1 G2 d1' d2')(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(thin_tac \"epdaS_epdaS_RMP_StateSimRL.relation_step_simulation_preservation G1 G2 d1' d2'\")\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(metis epdaS_epdaS_RMP_StateSimRL_inst_relation_step_simulation_marked_effect)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 d1' d2')(*strict*)\n  apply(rule epdaS_epdaS_RMP_StateSimRL.relation_initial_simulation_preservation_PROVE2)\n   apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   prefer 2\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(thin_tac \"epdaS_epdaS_RMP_StateSimRL.relation_initial_simulation_preservation G1 G2 d1' d2'\")\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(metis epdaS_epdaS_RMP_StateSimRL_inst_relation_initial_simulation_marked_effect)\n  done\n\ninterpretation \"epdaS_epdaS_RMP_StateSimRL\" : ATS_Simulation_Configuration_Weak_Marked_Effect\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaS_configurations\"\n  (* initial_configurations1 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaS_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaS_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_DPDA_RMPUE__relation_configuration__RL\"\n  (* relation_initial_configuration *)\n  \"F_DPDA_RMPUE__relation_initial_configuration__RL\"\n  (* relation_effect *)\n  \"F_DPDA_RMPUE__relation_effect__RL\"\n  (* relation_TSstructure *)\n  \"F_DPDA_RMPUE__relation_TSstructure__RL\"\n  (* relation_initial_simulation *)\n  \"F_DPDA_RMPUE__relation_initial_simulation__LRRL\"\n  (* relation_step_simulation *)\n  \"F_DPDA_RMPUE__relation_step_simulation__LRRL\"\n  apply(simp add: LOCALE_DEFS epda_interpretations)\n  apply(simp add:  epdaS_epdaS_RMP_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axioms epdaS_epdaS_RMP_StateSimLR_inst_ATS_Simulation_Configuration_WeakRL_COND_axioms epdaS_epdaS_RMP_StateSimLR_inst_ATS_Simulation_Configuration_WeakRL_ACCEPT_axioms)\n  done\n\nlemma F_DPDA_RMPUE__preserves_lang2: \"\n  valid_dpda G\n  \\<Longrightarrow> push_and_pop_edges_seperated G\n  \\<Longrightarrow> read_edges_seperated G\n  \\<Longrightarrow> epdaS.marked_language G \\<supseteq> epdaS.marked_language (F_DPDA_RMPUE G)\"\n  apply(rule_tac\n      t=\"epdaS.marked_language G\"\n      and s=\"epdaS.finite_marked_language G\"\n      in subst)\n   apply (rule epdaS.AX_marked_language_finite)\n   apply(simp add: valid_dpda_def valid_pda_def)\n  apply(rule_tac\n      t=\"epdaS.marked_language (F_DPDA_RMPUE G)\"\n      and s=\"epdaS.finite_marked_language (F_DPDA_RMPUE G)\"\n      in ssubst)\n   apply(rule sym)\n   apply(rule epdaS.AX_marked_language_finite)\n   apply (rule F_DPDA_RMPUE__preserves_epda)\n   apply(force)\n  apply(subgoal_tac \"left_total_on (F_DPDA_RMPUE__relation_effect__RL SSG1 SSG2) (epdaS.finite_marked_language SSG1) (epdaS.finite_marked_language SSG2)\" for SSG1 SSG2)\n   prefer 2\n   apply(rule_tac\n      ?G2.0=\"G\"\n      in epdaS_epdaS_RMP_StateSimRL.ATS_Simulation_Configuration_Weak_Marked_Effect_sound)\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_effect__RL_def)\n  done\n\ntheorem F_DPDA_RMPUE__preserves_lang: \"\n  valid_dpda G\n  \\<Longrightarrow> push_and_pop_edges_seperated G\n  \\<Longrightarrow> read_edges_seperated G\n  \\<Longrightarrow> epdaS.marked_language G = epdaS.marked_language (F_DPDA_RMPUE G)\"\n  apply(rule order_antisym)\n   apply (metis F_DPDA_RMPUE__preserves_lang1)\n  apply (metis F_DPDA_RMPUE__preserves_lang2)\n  done\n\nlemma F_DPDA_RMPUE__conf_old__LR_rev_reflects_steps_OO: \"\n  x \\<in> epda_delta G\n  \\<Longrightarrow> epdaS_step_relation (F_DPDA_RMPUE G) c (F_DPDA_RMPUE__edge_else x) c1\n  \\<Longrightarrow> epdaS_step_relation G (F_DPDA_RMPUE__conf_old__LR_rev c) x (F_DPDA_RMPUE__conf_old__LR_rev c1)\"\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac w)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__conf_old__LR_rev_def F_DPDA_RMPUE__edge_else_def)\n  done\n\nlemma F_DPDA_RMPUE__conf_old__LR_rev_preserves_configurations2: \"\n  valid_dpda G2\n  \\<Longrightarrow> c1' \\<in> epdaS_configurations (F_DPDA_RMPUE G2)\n  \\<Longrightarrow> F_DPDA_RMPUE__conf_old__LR_rev c1' \\<in> epdaS_configurations G2\"\n  apply(simp add: F_DPDA_RMPUE__conf_old__LR_rev_def epdaS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac q i s)(*strict*)\n  apply(case_tac q)\n   apply(rename_tac q i s qa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i s qa)(*strict*)\n   apply(simp add: F_DPDA_RMPUE_def)\n   apply(erule disjE)\n    apply(rename_tac i s qa)(*strict*)\n    prefer 2\n    apply(clarsimp)\n    apply(rename_tac i s qa x ia)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__state_def)\n    apply(case_tac ia)\n     apply(rename_tac i s qa x ia)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac i s x)(*strict*)\n     apply(subgoal_tac \"valid_epda_step_label G2 x\")\n      apply(rename_tac i s x)(*strict*)\n      apply(simp add: valid_epda_step_label_def)\n     apply(rename_tac i s x)(*strict*)\n     apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n    apply(rename_tac i s qa x ia nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i s qa x nat)(*strict*)\n    apply(case_tac \"Suc (Suc nat) < length (edge_push x)\")\n     apply(rename_tac i s qa x nat)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac i s qa x nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i s x nat)(*strict*)\n    apply(subgoal_tac \"valid_epda_step_label G2 x\")\n     apply(rename_tac i s x nat)(*strict*)\n     apply(simp add: valid_epda_step_label_def)\n    apply(rename_tac i s x nat)(*strict*)\n    apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac i s qa)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac q i s epda_step_label_ext nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i s epda_step_label_ext nat)(*strict*)\n  apply(simp add: F_DPDA_RMPUE_def)\n  apply(erule disjE)\n   apply(rename_tac i s epda_step_label_ext nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac i s epda_step_label_ext nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i s epda_step_label_ext nat x ia)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__state_def)\n  apply(case_tac ia)\n   apply(rename_tac i s epda_step_label_ext nat x ia)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac i s epda_step_label_ext nat x ia nata)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i s epda_step_label_ext nat x nata)(*strict*)\n  apply(case_tac \"Suc (Suc nata) < length (edge_push x)\")\n   apply(rename_tac i s epda_step_label_ext nat x nata)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac i s epda_step_label_ext nat x nata)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i s x nata)(*strict*)\n  apply(subgoal_tac \"valid_epda_step_label G2 x\")\n   apply(rename_tac i s x nata)(*strict*)\n   prefer 2\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rename_tac i s x nata)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac i s x nata)(*strict*)\n   apply(simp add: valid_epda_step_label_def)\n  apply(rename_tac i s x nata)(*strict*)\n  apply(rule_tac\n      B=\"set (edge_push x)\"\n      in subset_trans)\n   apply(rename_tac i s x nata)(*strict*)\n   apply (metis List.set_take_subset)\n  apply(rename_tac i s x nata)(*strict*)\n  apply(rule valid_epda_push_in_gamma)\n   apply(rename_tac i s x nata)(*strict*)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rename_tac i s x nata)(*strict*)\n  apply(force)\n  done\n\nlemma F_DPDA_RMPUE__conf_old__LR_rev_preserves_steps_ON: \"\n  e1 \\<in> epda_delta (F_DPDA_RMPUE G2)\n  \\<Longrightarrow> epdaS_step_relation (F_DPDA_RMPUE G2) c1' e1 c1\n  \\<Longrightarrow> valid_dpda G2\n  \\<Longrightarrow> push_and_pop_edges_seperated G2\n  \\<Longrightarrow> read_edges_seperated G2\n  \\<Longrightarrow> edge_trg e1 = cons_state_or_edge_nat_new e n\n  \\<Longrightarrow> edge_src e1 = cons_state_or_edge_nat_old q\n  \\<Longrightarrow> epdaS_step_relation G2 (F_DPDA_RMPUE__conf_old__LR_rev c1') e (F_DPDA_RMPUE__conf_old__LR_rev c1)\"\n  apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE_def)\n  apply(clarsimp)\n  apply(rename_tac w)(*strict*)\n  apply(subgoal_tac \"n=Suc 0\")\n   apply(rename_tac w)(*strict*)\n   prefer 2\n   apply(erule disjE)\n    apply(rename_tac w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac w x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_then_def F_DPDA_RMPUE__state_def)\n    apply(clarsimp)\n    apply(rename_tac w x xa)(*strict*)\n    apply(case_tac xa)\n     apply(rename_tac w x xa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac w x)(*strict*)\n     prefer 2\n     apply(rename_tac w x xa nat)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac w x)(*strict*)\n    apply(case_tac \"Suc (Suc 0) < length (edge_push x)\")\n     apply(rename_tac w x)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac w x)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac w)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac w x)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_else_def)\n  apply(rename_tac w)(*strict*)\n  apply(clarsimp)\n  apply(erule disjE)\n   apply(rename_tac w)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac w x)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_then_def F_DPDA_RMPUE__state_def)\n   apply(clarsimp)\n   apply(rename_tac w x xa)(*strict*)\n   apply(case_tac \"Suc (Suc xa) < length (edge_push x)\")\n    apply(rename_tac w x xa)(*strict*)\n    prefer 2\n    apply(clarsimp)\n   apply(rename_tac w x xa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac w)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_rev_def)\n   apply(simp add: option_to_list_def)\n   apply(case_tac \"edge_event e\")\n    apply(rename_tac w)(*strict*)\n    prefer 2\n    apply(rename_tac w a)(*strict*)\n    apply(clarsimp)\n    apply(simp add: push_and_pop_edges_seperated_def read_edges_seperated_def)\n    apply(erule_tac\n      x=\"e\"\n      and P=\"\\<lambda>e. \\<not> F_DPDA_SPPE__edge_if e\"\n      in ballE)\n     apply(rename_tac w a)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac w a)(*strict*)\n    apply(erule_tac\n      x=\"e\"\n      in ballE)\n     apply(rename_tac w a)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac w a)(*strict*)\n    apply(simp add: strict_executing_edge_def F_DPDA_SPPE__edge_if_def empty_push_edge_def multiple_push_edge_def FB_executing_edge_def)\n    apply(simp add: F_DPDA_RMPUE__edge_if_def)\n    apply(subgoal_tac \"\\<exists>x. edge_pop e=[x]\")\n     apply(rename_tac w a)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac w a)(*strict*)\n    apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac w)(*strict*)\n   apply(clarsimp)\n   apply(simp add: push_and_pop_edges_seperated_def F_DPDA_SPPE__edge_if_def)\n   apply(erule_tac\n      x=\"e\"\n      in ballE)\n    apply(rename_tac w)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac w)(*strict*)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RMPUE__edge_if_def)\n   apply(case_tac \"edge_push e\")\n    apply(rename_tac w)(*strict*)\n    apply(force)\n   apply(rename_tac w a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. edge_push e = w' @ [x']\")\n    apply(rename_tac w a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac w a list)(*strict*)\n   apply(thin_tac \"edge_push e= a # list\")\n   apply(clarsimp)\n   apply(rename_tac w w' x')(*strict*)\n   apply (metis Suc_length Suc_lessD butn_def hd_conv_nth hd_rev length_0_conv length_drop length_rotate1 not_Cons_self nth_drop_0 rotate_simps take_1_rev take_eq_Nil take_last list.sel(2))\n  apply(rename_tac w)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac w x)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__edge_else_def)\n  done\n\nlemma F_DPDA_RMPUE__state_injective: \"\n  the (F_DPDA_RMPUE__state xa x) = the (F_DPDA_RMPUE__state xa xb)\n  \\<Longrightarrow> Suc x < length (edge_push xa)\n  \\<Longrightarrow> Suc xb < length (edge_push xa)\n  \\<Longrightarrow> x = xb\"\n  apply(simp add: F_DPDA_RMPUE__state_def)\n  apply(case_tac x)\n   apply(clarsimp)\n   apply(case_tac xb)\n    apply(clarsimp)\n   apply(rename_tac nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac nat)(*strict*)\n  apply(clarsimp)\n  apply(case_tac xb)\n   apply(rename_tac nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac nat nata)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma RMP_edge_pop_is_single: \"\n  valid_dpda G\n  \\<Longrightarrow> push_and_pop_edges_seperated G\n  \\<Longrightarrow> read_edges_seperated G\n  \\<Longrightarrow> x \\<in> epda_delta G\n  \\<Longrightarrow> F_DPDA_RMPUE__edge_if x\n  \\<Longrightarrow> \\<exists>y. edge_pop x = [y]\"\n  apply(simp add: valid_dpda_def valid_pda_def)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"x\"\n      in ballE)\n   prefer 2\n   apply(force)\n  apply(case_tac \"edge_pop x\")\n   apply(force)\n  apply(rename_tac a list)(*strict*)\n  apply(case_tac \"list\")\n   apply(rename_tac a list)(*strict*)\n   prefer 2\n   apply(rename_tac a list aa lista)(*strict*)\n   apply(force)\n  apply(rename_tac a list)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma RMP_edge_event_is_none: \"\n  valid_dpda G\n  \\<Longrightarrow> push_and_pop_edges_seperated G\n  \\<Longrightarrow> read_edges_seperated G\n  \\<Longrightarrow> x \\<in> epda_delta G\n  \\<Longrightarrow> F_DPDA_RMPUE__edge_if x\n  \\<Longrightarrow> edge_event x = None\"\n  apply(simp add: F_DPDA_RMPUE__edge_if_def read_edges_seperated_def push_and_pop_edges_seperated_def)\n  apply(simp add: FB_executing_edge_def empty_push_edge_def multiple_push_edge_def F_DPDA_SPPE__edge_if_def)\n  apply(erule_tac\n      x=\"x\"\n      and P=\"\\<lambda>x. (\\<exists>y. edge_event x = Some y) \\<or> (\\<forall>w b. edge_push x = w @ [b] \\<longrightarrow> edge_pop x = [b])\"\n      in ballE)\n   prefer 2\n   apply(force)\n  apply(erule_tac\n      x=\"x\"\n      in ballE)\n   prefer 2\n   apply(force)\n  apply(case_tac \"edge_push x\")\n   apply(force)\n  apply(rename_tac a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. edge_push x = w' @ [x']\")\n   apply(rename_tac a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac a list)(*strict*)\n  apply(thin_tac \"edge_push x= a # list\")\n  apply(clarsimp)\n  apply(rename_tac w' x')(*strict*)\n  apply(case_tac \"edge_event x\")\n   apply(rename_tac w' x')(*strict*)\n   apply(force)\n  apply(rename_tac w' x' a)(*strict*)\n  apply(clarsimp)\n  apply(simp add: strict_executing_edge_def)\n  apply(simp add: valid_dpda_def valid_pda_def)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"x\"\n      in ballE)\n   apply(rename_tac w' x' a)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac w' x' a)(*strict*)\n  apply(case_tac \"edge_pop x\")\n   apply(rename_tac w' x' a)(*strict*)\n   apply(force)\n  apply(rename_tac w' x' a aa list)(*strict*)\n  apply(force)\n  done\n\nlemma F_DPDA_RMPUE__edge_then_not_between_OO: \"\n  edge_src e1 = cons_state_or_edge_nat_old q\n  \\<Longrightarrow> edge_trg e1 = cons_state_or_edge_nat_old qa\n  \\<Longrightarrow> e1 \\<in> F_DPDA_RMPUE__edge_then x\n  \\<Longrightarrow> x \\<in> epda_delta G\n  \\<Longrightarrow> F_DPDA_RMPUE__edge_if x\n  \\<Longrightarrow> Q\"\n  apply(simp add: F_DPDA_RMPUE__edge_then_def)\n  apply(clarsimp)\n  apply(rename_tac xa)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__state_def)\n  apply(case_tac xa)\n   apply(rename_tac xa)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"Suc (Suc 0) < length (edge_push x)\")\n    apply(force)\n   apply(simp add: F_DPDA_RMPUE__edge_if_def)\n  apply(rename_tac xa nat)(*strict*)\n  apply(clarsimp)\n  done\n\ntheorem F_DPDA_RMPUE__preserves_is_forward_edge_deterministic_accessible: \"\n  valid_dpda G\n  \\<Longrightarrow> push_and_pop_edges_seperated G\n  \\<Longrightarrow> read_edges_seperated G\n  \\<Longrightarrow> epdaS.is_forward_edge_deterministic_accessible (F_DPDA_RMPUE G)\"\n  apply(simp add: epdaS.is_forward_edge_deterministic_accessible_def)\n  apply(clarsimp)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"edge_src e1 = epdaS_conf_state c\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"edge_src e2 = epdaS_conf_state c\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"prefix (option_to_list (edge_event e1)) (epdaS_conf_scheduler c)\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n   apply(simp add: prefix_def)\n   apply(clarsimp)\n   apply(rename_tac c c1 c2 e1 e2 w wa)(*strict*)\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"prefix (option_to_list (edge_event e2)) (epdaS_conf_scheduler c)\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n   apply(simp add: prefix_def)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"prefix (edge_pop e1) (epdaS_conf_stack c)\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n   apply(simp add: prefix_def)\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"prefix (edge_pop e2) (epdaS_conf_stack c)\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n   apply(simp add: prefix_def)\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"e1 \\<in> epda_delta (F_DPDA_RMPUE G)\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"e2 \\<in> epda_delta (F_DPDA_RMPUE G)\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"epdaS.is_forward_edge_deterministic_accessible G\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: valid_dpda_def)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(simp add: epdaS.is_forward_edge_deterministic_accessible_def)\n  apply(erule_tac\n      x=\"F_DPDA_RMPUE__conf_old__LR_rev c\"\n      in ballE)\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   apply(erule_tac\n      x=\"F_DPDA_RMPUE__conf_old__LR_rev c1\"\n      in allE)\n   apply(erule_tac\n      x=\"F_DPDA_RMPUE__conf_old__LR_rev c2\"\n      in allE)\n   apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G \\<inter> Collect F_DPDA_RMPUE__edge_if. e1 \\<in> F_DPDA_RMPUE__edge_then x) \\<or> (\\<exists>x\\<in> epda_delta G \\<inter> {e. \\<not> F_DPDA_RMPUE__edge_if e}. e1 = F_DPDA_RMPUE__edge_else x)\")\n    apply(rename_tac c c1 c2 e1 e2)(*strict*)\n    prefer 2\n    apply(simp add: F_DPDA_RMPUE_def)\n    apply(blast)\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G \\<inter> Collect F_DPDA_RMPUE__edge_if. e2 \\<in> F_DPDA_RMPUE__edge_then x) \\<or> (\\<exists>x\\<in> epda_delta G \\<inter> {e. \\<not> F_DPDA_RMPUE__edge_if e}. e2 = F_DPDA_RMPUE__edge_else x)\")\n    apply(rename_tac c c1 c2 e1 e2)(*strict*)\n    prefer 2\n    apply(simp add: F_DPDA_RMPUE_def)\n    apply(blast)\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"F_DPDA_RMPUE__conf_old__LR_rev c \\<in> epdaS.get_accessible_configurations G\")\n    apply(rename_tac c c1 c2 e1 e2)(*strict*)\n    apply(force)\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   apply(thin_tac \"F_DPDA_RMPUE__conf_old__LR_rev c \\<notin> epdaS.get_accessible_configurations G\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   apply(rule_tac\n      ?c1.0=\"c\"\n      in epdaS_epdaS_RMP_StateSimRL.get_accessible_configurations_transfer)\n       apply(rename_tac c c1 c2 e1 e2)(*strict*)\n       apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n      apply(rename_tac c c1 c2 e1 e2)(*strict*)\n      apply (metis F_DPDA_RMPUE__conf_old__LR_rev_preserves_configurations2 F_DPDA_RMPUE__preserves_epda epdaS.get_accessible_configurations_are_configurations2)\n     apply(rename_tac c c1 c2 e1 e2)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n     apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n    apply(rename_tac c c1 c2 e1 e2 cA cB)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__RL_def)\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"edge_src e1=edge_src e2\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"edge_src e1\")\n   apply(rename_tac c c1 c2 e1 e2 q)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"edge_trg e1\")\n    apply(rename_tac c c1 c2 e1 e2 q qa)(*strict*)\n    apply(erule_tac\n      P=\"\\<exists>x\\<in> epda_delta G \\<inter> Collect F_DPDA_RMPUE__edge_if. e1 \\<in> F_DPDA_RMPUE__edge_then x\"\n      in disjE)\n     apply(rename_tac c c1 c2 e1 e2 q qa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c c1 c2 e1 e2 q qa x)(*strict*)\n     apply(rule_tac\n      q=\"q\"\n      and ?e1.0=\"e1\"\n      in F_DPDA_RMPUE__edge_then_not_between_OO)\n         apply(rename_tac c c1 c2 e1 e2 q qa x)(*strict*)\n         apply(force)\n        apply(rename_tac c c1 c2 e1 e2 q qa x)(*strict*)\n        apply(force)\n       apply(rename_tac c c1 c2 e1 e2 q qa x)(*strict*)\n       apply(force)\n      apply(rename_tac c c1 c2 e1 e2 q qa x)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 e1 e2 q qa x)(*strict*)\n     apply(force)\n    apply(rename_tac c c1 c2 e1 e2 q qa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c c1 c2 e2 q qa x)(*strict*)\n    apply(erule_tac\n      x=\"x\"\n      in allE)\n    apply(subgoal_tac \"epdaS_step_relation G (F_DPDA_RMPUE__conf_old__LR_rev c) x (F_DPDA_RMPUE__conf_old__LR_rev c1)\")\n     apply(rename_tac c c1 c2 e2 q qa x)(*strict*)\n     prefer 2\n     apply(rule F_DPDA_RMPUE__conf_old__LR_rev_reflects_steps_OO)\n      apply(rename_tac c c1 c2 e2 q qa x)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 e2 q qa x)(*strict*)\n     apply(force)\n    apply(rename_tac c c1 c2 e2 q qa x)(*strict*)\n    apply(clarsimp)\n    apply(case_tac \"edge_trg e2\")\n     apply(rename_tac c c1 c2 e2 q qa x qb)(*strict*)\n     apply(erule disjE)\n      apply(rename_tac c c1 c2 e2 q qa x qb)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac c c1 c2 e2 q qa x qb xa)(*strict*)\n      apply(rule_tac\n      q=\"q\"\n      and ?e1.0=\"e2\"\n      in F_DPDA_RMPUE__edge_then_not_between_OO)\n          apply(rename_tac c c1 c2 e2 q qa x qb xa)(*strict*)\n          apply(force)\n         apply(rename_tac c c1 c2 e2 q qa x qb xa)(*strict*)\n         apply(force)\n        apply(rename_tac c c1 c2 e2 q qa x qb xa)(*strict*)\n        apply(force)\n       apply(rename_tac c c1 c2 e2 q qa x qb xa)(*strict*)\n       apply(force)\n      apply(rename_tac c c1 c2 e2 q qa x qb xa)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 e2 q qa x qb)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c c1 c2 q qa x qb xa)(*strict*)\n     apply(erule_tac\n      x=\"xa\"\n      in allE)\n     apply(erule impE)\n      apply(rename_tac c c1 c2 q qa x qb xa)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac c c1 c2 q qa x qb xa)(*strict*)\n     apply(rule F_DPDA_RMPUE__conf_old__LR_rev_reflects_steps_OO)\n      apply(rename_tac c c1 c2 q qa x qb xa)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 q qa x qb xa)(*strict*)\n     apply(force)\n    apply(rename_tac c c1 c2 e2 q qa x epda_step_label_ext nat)(*strict*)\n    apply(rename_tac e n)\n    apply(rename_tac c c1 c2 e2 q qa x e n)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac c c1 c2 e2 q qa x e n)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c c1 c2 e2 q qa x e n xa)(*strict*)\n     apply(erule_tac\n      x=\"e\"\n      in allE)\n     apply(erule impE)\n      apply(rename_tac c c1 c2 e2 q qa x e n xa)(*strict*)\n      prefer 2\n      apply(clarsimp)\n      apply(rename_tac c c1 c2 e2 q qa e n xa)(*strict*)\n      apply(simp add: F_DPDA_RMPUE__edge_then_def)\n      apply(clarsimp)\n      apply(rename_tac c c1 c2 q qa e n xa x)(*strict*)\n      apply(simp add: F_DPDA_RMPUE__edge_else_def)\n      apply(simp add: epdaS_step_relation_def)\n      apply(clarsimp)\n      apply(rename_tac c c1 c2 q e n xa x w wa wb)(*strict*)\n      apply(simp add: F_DPDA_RMPUE__state_def)\n      apply(case_tac \"Suc (Suc x) < length (edge_push xa)\")\n       apply(rename_tac c c1 c2 q e n xa x w wa wb)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac c c1 c2 q e n xa x w wa wb)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac c c1 c2 e2 q qa x e n xa)(*strict*)\n     apply(rule_tac\n      q=\"q\"\n      in F_DPDA_RMPUE__conf_old__LR_rev_preserves_steps_ON)\n           apply(rename_tac c c1 c2 e2 q qa x e n xa)(*strict*)\n           prefer 2\n           apply(force)\n          apply(rename_tac c c1 c2 e2 q qa x e n xa)(*strict*)\n          apply(force)\n         apply(rename_tac c c1 c2 e2 q qa x e n xa)(*strict*)\n         apply(force)\n        apply(rename_tac c c1 c2 e2 q qa x e n xa)(*strict*)\n        apply(force)\n       apply(rename_tac c c1 c2 e2 q qa x e n xa)(*strict*)\n       apply(force)\n      apply(rename_tac c c1 c2 e2 q qa x e n xa)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 e2 q qa x e n xa)(*strict*)\n     apply(force)\n    apply(rename_tac c c1 c2 e2 q qa x e n)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c c1 c2 q qa x e n xa)(*strict*)\n    apply(erule_tac\n      x=\"xa\"\n      in allE)\n    apply(erule impE)\n     apply(rename_tac c c1 c2 q qa x e n xa)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac c c1 c2 q qa x e n xa)(*strict*)\n    apply(rule F_DPDA_RMPUE__conf_old__LR_rev_reflects_steps_OO)\n     apply(rename_tac c c1 c2 q qa x e n xa)(*strict*)\n     apply(force)\n    apply(rename_tac c c1 c2 q qa x e n xa)(*strict*)\n    apply(force)\n   apply(rename_tac c c1 c2 e1 e2 q epda_step_label_ext nat)(*strict*)\n   apply(rename_tac e n)\n   apply(rename_tac c c1 c2 e1 e2 q e n)(*strict*)\n   apply(erule_tac\n      P=\"\\<exists>x\\<in> epda_delta G \\<inter> Collect F_DPDA_RMPUE__edge_if. e1 \\<in> F_DPDA_RMPUE__edge_then x\"\n      in disjE)\n    apply(rename_tac c c1 c2 e1 e2 q e n)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c c1 c2 e1 e2 q e n x)(*strict*)\n    apply(erule_tac\n      x=\"e\"\n      in allE)\n    apply(subgoal_tac \"epdaS_step_relation G (F_DPDA_RMPUE__conf_old__LR_rev c) e (F_DPDA_RMPUE__conf_old__LR_rev c1)\")\n     apply(rename_tac c c1 c2 e1 e2 q e n x)(*strict*)\n     prefer 2\n     apply(rule_tac\n      q=\"q\"\n      in F_DPDA_RMPUE__conf_old__LR_rev_preserves_steps_ON)\n           apply(rename_tac c c1 c2 e1 e2 q e n x)(*strict*)\n           prefer 2\n           apply(force)\n          apply(rename_tac c c1 c2 e1 e2 q e n x)(*strict*)\n          apply(force)\n         apply(rename_tac c c1 c2 e1 e2 q e n x)(*strict*)\n         apply(force)\n        apply(rename_tac c c1 c2 e1 e2 q e n x)(*strict*)\n        apply(force)\n       apply(rename_tac c c1 c2 e1 e2 q e n x)(*strict*)\n       apply(force)\n      apply(rename_tac c c1 c2 e1 e2 q e n x)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 e1 e2 q e n x)(*strict*)\n     apply(force)\n    apply(rename_tac c c1 c2 e1 e2 q e n x)(*strict*)\n    apply(clarsimp)\n    apply(case_tac \"edge_trg e2\")\n     apply(rename_tac c c1 c2 e1 e2 q e n x qa)(*strict*)\n     apply(erule disjE)\n      apply(rename_tac c c1 c2 e1 e2 q e n x qa)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac c c1 c2 e1 e2 q e n x qa xa)(*strict*)\n      apply(rule_tac\n      q=\"q\"\n      in F_DPDA_RMPUE__edge_then_not_between_OO)\n          apply(rename_tac c c1 c2 e1 e2 q e n x qa xa)(*strict*)\n          prefer 2\n          apply(force)\n         apply(rename_tac c c1 c2 e1 e2 q e n x qa xa)(*strict*)\n         apply(force)\n        apply(rename_tac c c1 c2 e1 e2 q e n x qa xa)(*strict*)\n        apply(force)\n       apply(rename_tac c c1 c2 e1 e2 q e n x qa xa)(*strict*)\n       apply(force)\n      apply(rename_tac c c1 c2 e1 e2 q e n x qa xa)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 e1 e2 q e n x qa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c c1 c2 e1 q e n x qa xa)(*strict*)\n     apply(erule_tac\n      x=\"xa\"\n      in allE)\n     apply(erule impE)\n      apply(rename_tac c c1 c2 e1 q e n x qa xa)(*strict*)\n      prefer 2\n      apply(clarsimp)\n      apply(rename_tac c c1 c2 e1 q n x qa xa)(*strict*)\n      apply(simp add: epdaS_step_relation_def)\n      apply(clarsimp)\n      apply(rename_tac c c1 c2 e1 q n x qa xa w wa wb)(*strict*)\n      apply(simp add: F_DPDA_RMPUE__edge_then_def F_DPDA_RMPUE__edge_else_def F_DPDA_RMPUE__state_def)\n      apply(clarsimp)\n      apply(rename_tac c c1 c2 q n x xa w wa wb xb)(*strict*)\n      apply(case_tac \"Suc (Suc xb) < length (edge_push x)\")\n       apply(rename_tac c c1 c2 q n x xa w wa wb xb)(*strict*)\n       prefer 2\n       apply(force)\n      apply(rename_tac c c1 c2 q n x xa w wa wb xb)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac c c1 c2 e1 q e n x qa xa)(*strict*)\n     apply(rule F_DPDA_RMPUE__conf_old__LR_rev_reflects_steps_OO)\n      apply(rename_tac c c1 c2 e1 q e n x qa xa)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 e1 q e n x qa xa)(*strict*)\n     apply(force)\n    apply(rename_tac c c1 c2 e1 e2 q e n x epda_step_label_ext nat)(*strict*)\n    apply(rename_tac e n)\n    apply(rename_tac c c1 c2 e1 e2 q ea na x e n)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac c c1 c2 e1 e2 q ea na x e n)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c c1 c2 e1 e2 q ea na x e n xa)(*strict*)\n     apply(erule_tac\n      x=\"e\"\n      in allE)\n     apply(subgoal_tac \"epdaS_step_relation G (F_DPDA_RMPUE__conf_old__LR_rev c) e (F_DPDA_RMPUE__conf_old__LR_rev c2)\")\n      apply(rename_tac c c1 c2 e1 e2 q ea na x e n xa)(*strict*)\n      prefer 2\n      apply(rule_tac\n      q=\"q\"\n      in F_DPDA_RMPUE__conf_old__LR_rev_preserves_steps_ON)\n            apply(rename_tac c c1 c2 e1 e2 q ea na x e n xa)(*strict*)\n            prefer 2\n            apply(force)\n           apply(rename_tac c c1 c2 e1 e2 q ea na x e n xa)(*strict*)\n           apply(force)\n          apply(rename_tac c c1 c2 e1 e2 q ea na x e n xa)(*strict*)\n          apply(force)\n         apply(rename_tac c c1 c2 e1 e2 q ea na x e n xa)(*strict*)\n         apply(force)\n        apply(rename_tac c c1 c2 e1 e2 q ea na x e n xa)(*strict*)\n        apply(force)\n       apply(rename_tac c c1 c2 e1 e2 q ea na x e n xa)(*strict*)\n       apply(force)\n      apply(rename_tac c c1 c2 e1 e2 q ea na x e n xa)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 e1 e2 q ea na x e n xa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c c1 c2 e1 e2 q na x e n xa)(*strict*)\n     apply(subgoal_tac \"F_DPDA_RMPUE__conf_old__LR_rev c1=F_DPDA_RMPUE__conf_old__LR_rev c2\")\n      apply(rename_tac c c1 c2 e1 e2 q na x e n xa)(*strict*)\n      prefer 2\n      apply(simp add: epdaS_step_relation_def)\n      apply(clarsimp)\n     apply(rename_tac c c1 c2 e1 e2 q na x e n xa)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"n=Suc 0\")\n      apply(rename_tac c c1 c2 e1 e2 q na x e n xa)(*strict*)\n      prefer 2\n      apply(thin_tac \"edge_trg e1 = cons_state_or_edge_nat_new e na\")\n      apply(simp add: F_DPDA_RMPUE__edge_then_def F_DPDA_RMPUE__state_def)\n      apply(rename_tac c c1 c2 e1 e2 q x e n xa)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac c c1 c2 q x e n xa xb xc)(*strict*)\n      apply(case_tac xc)\n       apply(rename_tac c c1 c2 q x e n xa xb xc)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac c c1 c2 q x e n xa xb)(*strict*)\n       apply(case_tac \"Suc (Suc 0) < length (edge_push xa)\")\n        apply(rename_tac c c1 c2 q x e n xa xb)(*strict*)\n        apply(clarsimp)\n       apply(rename_tac c c1 c2 q x e n xa xb)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac c c1 c2 q x e n xa xb xc nat)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac c c1 c2 q x e n xa xb nat)(*strict*)\n      apply(case_tac \"Suc (Suc (Suc nat)) < length (edge_push xa)\")\n       apply(rename_tac c c1 c2 q x e n xa xb nat)(*strict*)\n       prefer 2\n       apply(force)\n      apply(rename_tac c c1 c2 q x e n xa xb nat)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac c c1 c2 q x e xb nat)(*strict*)\n      apply(case_tac \"epdaS_conf_state c\")\n       apply(rename_tac c c1 c2 q x e xb nat qa)(*strict*)\n       apply(force)\n      apply(rename_tac c c1 c2 q x e xb nat epda_step_label_exta nata)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 e1 e2 q na x e n xa)(*strict*)\n     apply(subgoal_tac \"na=Suc 0\")\n      apply(rename_tac c c1 c2 e1 e2 q na x e n xa)(*strict*)\n      prefer 2\n      apply(thin_tac \"edge_trg e2 = cons_state_or_edge_nat_new e n\")\n      apply(simp add: F_DPDA_RMPUE__edge_then_def F_DPDA_RMPUE__state_def)\n      apply(clarsimp)\n      apply(rename_tac c c1 c2 q na x e xa xb xc)(*strict*)\n      apply(case_tac xb)\n       apply(rename_tac c c1 c2 q na x e xa xb xc)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac c c1 c2 q na x e xa xc)(*strict*)\n       apply(case_tac \"Suc (Suc 0) < length (edge_push x)\")\n        apply(rename_tac c c1 c2 q na x e xa xc)(*strict*)\n        apply(clarsimp)\n       apply(rename_tac c c1 c2 q na x e xa xc)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac c c1 c2 q na x e xa xb xc nat)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac c c1 c2 q na x e xa xc nat)(*strict*)\n      apply(case_tac \"Suc (Suc (Suc nat)) < length (edge_push x)\")\n       apply(rename_tac c c1 c2 q na x e xa xc nat)(*strict*)\n       prefer 2\n       apply(force)\n      apply(rename_tac c c1 c2 q na x e xa xc nat)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac c c1 c2 q e xa xc nat)(*strict*)\n      apply(case_tac \"epdaS_conf_state c\")\n       apply(rename_tac c c1 c2 q e xa xc nat qa)(*strict*)\n       apply(force)\n      apply(rename_tac c c1 c2 q e xa xc nat epda_step_label_exta nata)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 e1 e2 q na x e n xa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c c1 c2 e1 e2 q x e xa)(*strict*)\n     apply(subgoal_tac \"c1=c2\")\n      apply(rename_tac c c1 c2 e1 e2 q x e xa)(*strict*)\n      apply(rule_tac\n      G=\"F_DPDA_RMPUE G\"\n      in epdaS_step_relation_injective_on_edge)\n        apply(rename_tac c c1 c2 e1 e2 q x e xa)(*strict*)\n        apply (metis F_DPDA_RMPUE__preserves_PDA)\n       apply(rename_tac c c1 c2 e1 e2 q x e xa)(*strict*)\n       apply(force)\n      apply(rename_tac c c1 c2 e1 e2 q x e xa)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 e1 e2 q x e xa)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__conf_old__LR_rev_def)\n     apply(simp add: epdaS_step_relation_def)\n    apply(rename_tac c c1 c2 e1 e2 q ea na x e n)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c c1 c2 e1 q ea na x e n xa)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_else_def)\n   apply(rename_tac c c1 c2 e1 e2 q e n)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c c1 c2 e2 q e n x)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_else_def)\n  apply(rename_tac c c1 c2 e1 e2 epda_step_label_ext nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac e n)\n  apply(rename_tac c c1 c2 e1 e2 e n)(*strict*)\n  apply(erule_tac\n      P=\"\\<exists>x\\<in> epda_delta G \\<inter> Collect F_DPDA_RMPUE__edge_if. e1 \\<in> F_DPDA_RMPUE__edge_then x\"\n      in disjE)\n   apply(rename_tac c c1 c2 e1 e2 e n)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac c c1 c2 e2 e n x)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_else_def)\n   apply(case_tac \"epdaS_conf_state c\")\n    apply(rename_tac c c1 c2 e2 e n x q)(*strict*)\n    apply(force)\n   apply(rename_tac c c1 c2 e2 e n x epda_step_label_exta nat)(*strict*)\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2 e n)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac c c1 c2 e1 e2 e n)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac c c1 c2 e1 e n x xa)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_else_def)\n   apply(case_tac \"epdaS_conf_state c\")\n    apply(rename_tac c c1 c2 e1 e n x xa q)(*strict*)\n    apply(force)\n   apply(rename_tac c c1 c2 e1 e n x xa epda_step_label_exta nat)(*strict*)\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2 e n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c c1 c2 e1 e2 e n x xa)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__edge_then_def F_DPDA_RMPUE__state_def)\n  apply(clarsimp)\n  apply(rename_tac c c1 c2 e n x xa xb xc)(*strict*)\n  apply(case_tac xb)\n   apply(rename_tac c c1 c2 e n x xa xb xc)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c c1 c2 e n x xa xc)(*strict*)\n   apply(case_tac \"epdaS_conf_state c\")\n    apply(rename_tac c c1 c2 e n x xa xc q)(*strict*)\n    apply(force)\n   apply(rename_tac c c1 c2 e n x xa xc epda_step_label_exta nat)(*strict*)\n   apply(force)\n  apply(rename_tac c c1 c2 e n x xa xb xc nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c c1 c2 e n x xa xc nat)(*strict*)\n  apply(case_tac xc)\n   apply(rename_tac c c1 c2 e n x xa xc nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c c1 c2 e n x xa nat)(*strict*)\n   apply(case_tac \"epdaS_conf_state c\")\n    apply(rename_tac c c1 c2 e n x xa nat q)(*strict*)\n    apply(force)\n   apply(rename_tac c c1 c2 e n x xa nat epda_step_label_exta nata)(*strict*)\n   apply(force)\n  apply(rename_tac c c1 c2 e n x xa xc nat nata)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c c1 c2 e n x xa nat nata)(*strict*)\n  apply(subgoal_tac \"nat=nata\")\n   apply(rename_tac c c1 c2 e n x xa nat nata)(*strict*)\n   prefer 2\n   apply (metis DT_state_or_edge_nat.simps(2) nat.inject)\n  apply(rename_tac c c1 c2 e n x xa nat nata)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c c1 c2 e n x xa nata)(*strict*)\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac c c1 c2 e n x xa nata w)(*strict*)\n  apply(case_tac \"epdaS_conf_state c\")\n   apply(rename_tac c c1 c2 e n x xa nata w q)(*strict*)\n   apply(force)\n  apply(rename_tac c c1 c2 e n x xa nata w epda_step_label_exta nat)(*strict*)\n  apply(force)\n  done\n\nlemma F_DPDA_RMPUE__preserves_DPDA: \"\n  valid_dpda G\n  \\<Longrightarrow> push_and_pop_edges_seperated G\n  \\<Longrightarrow> read_edges_seperated G\n  \\<Longrightarrow> valid_dpda (F_DPDA_RMPUE G)\"\n  apply(simp (no_asm) add: valid_dpda_def)\n  apply(rule conjI)\n   apply(rule F_DPDA_RMPUE__preserves_PDA)\n   apply(force)\n  apply (metis F_DPDA_RMPUE__preserves_is_forward_edge_deterministic_accessible)\n  done\n\ndefinition F_DPDA_RMPUE__conf_old__LR_revX :: \"\n  (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack) epdaS_conf\"\n  where\n    \"F_DPDA_RMPUE__conf_old__LR_revX c \\<equiv>\n  case epdaS_conf_state c of cons_state_or_edge_nat_old q\n  \\<Rightarrow> \\<lparr>epdaS_conf_state = q,\n     epdaS_conf_scheduler = epdaS_conf_scheduler c,\n     epdaS_conf_stack = epdaS_conf_stack c\\<rparr>\n  | cons_state_or_edge_nat_new e n\n  \\<Rightarrow> \\<lparr>epdaS_conf_state = edge_src e,\n     epdaS_conf_scheduler = epdaS_conf_scheduler c,\n     epdaS_conf_stack = (edge_pop e) @ drop (Suc n) (epdaS_conf_stack c)\\<rparr>\"\n\ndefinition F_DPDA_RMPUE__relation_labels__LR2 :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda_step_label\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda_step_label\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RMPUE__relation_labels__LR2 G1 G2 e1 e2 \\<equiv>\n  F_DPDA_RMPUE__relation_structure__LR G1 G2\n  \\<and> e1 \\<in> F_DPDA_DRE__revert_F_DPDA_RMPUE G1 {e2}\"\n\ndefinition F_DPDA_RMPUE__relation_labels__RL2 :: \"\n  (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda_step_label\n  \\<Rightarrow> ('state, 'event, 'stack) epda_step_label\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RMPUE__relation_labels__RL2 G1 G2 e2 e1 \\<equiv>\n  F_DPDA_RMPUE__relation_TSstructure__RL G1 G2\n  \\<and> e1 \\<in> F_DPDA_DRE__revert_F_DPDA_RMPUE G2 {e2}\"\n\nlemma epdaS_epdaS_RMP_StateSimLRReach_ATS_Simulation_Configuration_WeakReach_axioms: \"\n  ATS_Simulation_Configuration_WeakReach_axioms epda_step_labels epdaS_step_relation epdaS_configurations epda_step_labels epdaS_step_relation F_DPDA_RMPUE__relation_configuration__LR F_DPDA_RMPUE__relation_structure__LR F_DPDA_RMPUE__relation_step_simulation__LR F_DPDA_RMPUE__relation_labels__LR2\"\n  apply(simp add: ATS_Simulation_Configuration_WeakReach_axioms_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def epda_step_labels_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 e1 c1' d2 n)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_step_simulation__LR_def)\n  apply(case_tac \"F_DPDA_RMPUE__edge_if e1\")\n   apply(rename_tac G1 c1 e1 c1' d2 n)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 c1 e1 c1' n)(*strict*)\n   apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n   apply(subgoal_tac \"Suc 0 < length (edge_push e1)\")\n    apply(rename_tac G1 c1 e1 c1' n)(*strict*)\n    prefer 2\n    apply(simp add: F_DPDA_RMPUE__edge_if_def)\n   apply(rename_tac G1 c1 e1 c1' n)(*strict*)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RMPUE__edge_then_i_th__LR_def)\n   apply(simp add: F_DPDA_RMPUE__relation_labels__LR2_def)\n   apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n   apply(simp add: F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n   apply(simp add: F_DPDA_RMPUE__edge_then_def)\n   apply(rule disjI1)\n   apply(rule_tac\n      x=\"0\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac G1 c1 e1 c1' d2 n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 e1 c1' n)(*strict*)\n  apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n  apply(rule_tac\n      x=\"(F_DPDA_RMPUE__edge_else e1)\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 c1 e1 c1' n)(*strict*)\n   apply(simp add: der2_def)\n  apply(rename_tac G1 c1 e1 c1' n)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_labels__LR2_def)\n  apply(rule conjI)\n   apply(rename_tac G1 c1 e1 c1' n)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n  apply(rename_tac G1 c1 e1 c1' n)(*strict*)\n  apply(simp only: F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n  apply(clarsimp)\n  done\n\ninterpretation \"epdaS_epdaS_RMP_StateSimLRReach\" : ATS_Simulation_Configuration_WeakReach\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaS_configurations\"\n  (* initial_configurations1 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaS_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaS_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_DPDA_RMPUE__relation_configuration__LR\"\n  (* relation_initial_configuration *)\n  \"F_DPDA_RMPUE__relation_initial_configuration__LR\"\n  (* relation_effect *)\n  \"F_DPDA_RMPUE__relation_effect__LR\"\n  (* relation_TSstructure *)\n  \"F_DPDA_RMPUE__relation_structure__LR\"\n  (* relation_initial_simulation *)\n  \"F_DPDA_RMPUE__relation_initial_simulation__LR\"\n  (* relation_step_simulation *)\n  \"F_DPDA_RMPUE__relation_step_simulation__LR\"\n  (* relation_labelsLR *)\n  \"F_DPDA_RMPUE__relation_labels__LR2\"\n  apply(simp add: LOCALE_DEFS epda_interpretations)\n  apply(simp add: epdaS_epdaS_RMP_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms epdaS_epdaS_RMP_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms epdaS_epdaS_RMP_StateSimLRReach_ATS_Simulation_Configuration_WeakReach_axioms)\n  done\n\ndefinition F_DPDA_RMPUE__relation_configuration__RL2 :: \"\n  (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RMPUE__relation_configuration__RL2 G1 G2 c1 c2 \\<equiv>\n  F_DPDA_RMPUE__relation_TSstructure__RL G1 G2\n  \\<and> c1 \\<in> epdaS.get_accessible_configurations G1\n  \\<and> c2 = F_DPDA_RMPUE__conf_old__LR_revX c1\"\n\ndefinition F_DPDA_RMPUE__relation_initial_configuration__RL2 :: \"\n  (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RMPUE__relation_initial_configuration__RL2 G1 G2 c1 c2 \\<equiv>\n  F_DPDA_RMPUE__relation_TSstructure__RL G1 G2\n  \\<and> c1 \\<in> epdaS_initial_configurations G1\n  \\<and> c2 = F_DPDA_RMPUE__conf_old__LR_revX c1\"\n\ndefinition F_DPDA_RMPUE__relation_initial_simulation__RL2 :: \"\n  (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'event , 'stack) DT_state_or_edge_nat, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> (('state, 'event , 'stack) epda_step_label, ('state, 'event , 'stack) epdaS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RMPUE__relation_initial_simulation__RL2 G1 G2 c1 d \\<equiv>\n  d = der1 (F_DPDA_RMPUE__conf_old__LR_revX c1)\"\n\ndefinition F_DPDA_RMPUE__relation_step_simulation__RL2 :: \"\n  (('state, 'event, 'stack) DT_state_or_edge_nat, 'event , 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event, 'stack) epda_step_label\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge_nat, 'event , 'stack) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> (('state, 'event, 'stack) epda_step_label, ('state, 'event, 'stack) epdaS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RMPUE__relation_step_simulation__RL2 G1 G2 c1 e c1' c2 d \\<equiv>\n  case edge_trg e of cons_state_or_edge_nat_old q\n  \\<Rightarrow> (case edge_src e of cons_state_or_edge_nat_old q\n    \\<Rightarrow> d = der2\n      (F_DPDA_RMPUE__conf_old__LR_revX c1)\n        (F_DPDA_RMPUE__edge_else__RL e)\n      (F_DPDA_RMPUE__conf_old__LR_revX c1')\n    | cons_state_or_edge_nat_new e' n\n    \\<Rightarrow> d = der2\n      (F_DPDA_RMPUE__conf_old__LR_revX c1)\n        e'\n      (F_DPDA_RMPUE__conf_old__LR_revX c1'))\n    | cons_state_or_edge_nat_new e' n\n  \\<Rightarrow> (case edge_src e of cons_state_or_edge_nat_old q\n    \\<Rightarrow> d = der1 (F_DPDA_RMPUE__conf_old__LR_revX c1)\n    | cons_state_or_edge_nat_new e' n\n    \\<Rightarrow> d = der1 (F_DPDA_RMPUE__conf_old__LR_revX c1))\"\n\nlemma F_DPDA_RMPUE__conf_old__LR_revX_preserves_configurations: \"\n  F_DPDA_RMPUE__relation_TSstructure__RL G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS.get_accessible_configurations G1\n  \\<Longrightarrow> c1 \\<in> epdaS_configurations G1\n  \\<Longrightarrow> F_DPDA_RMPUE__conf_old__LR_revX c1 \\<in> epdaS_configurations G2\"\n  apply(simp add: epdaS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac q i s)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__conf_old__LR_revX_def)\n  apply(case_tac q)\n   apply(rename_tac q i s qa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i s qa)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RMPUE_def)\n   apply(erule disjE)\n    apply(rename_tac i s qa)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac i s qa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i s qa x ia)(*strict*)\n   apply(subgoal_tac \"valid_epda_step_label G2 x\")\n    apply(rename_tac i s qa x ia)(*strict*)\n    apply(simp add: valid_epda_step_label_def)\n    apply(simp add: F_DPDA_RMPUE__state_def)\n    apply(clarsimp)\n    apply(case_tac ia)\n     apply(rename_tac i s qa x ia)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac i s qa x ia nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i s qa x nat)(*strict*)\n    apply(case_tac \"Suc (Suc nat) < length (edge_push x)\")\n     apply(rename_tac i s qa x nat)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac i s qa x nat)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac i s qa x ia)(*strict*)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rename_tac q i s epda_step_label_ext nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i s epda_step_label_ext nat)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RMPUE_def)\n  apply(erule disjE)\n   apply(rename_tac i s epda_step_label_ext nat)(*strict*)\n   apply(force)\n  apply(rename_tac i s epda_step_label_ext nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i s epda_step_label_ext nat x ia)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__state_def)\n  apply(case_tac ia)\n   apply(rename_tac i s epda_step_label_ext nat x ia)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac i s epda_step_label_ext nat x ia nata)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i s epda_step_label_ext nat x nata)(*strict*)\n  apply(case_tac \"Suc (Suc nata) < length (edge_push x)\")\n   apply(rename_tac i s epda_step_label_ext nat x nata)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac i s epda_step_label_ext nat x nata)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i s x nata)(*strict*)\n  apply(subgoal_tac \"valid_epda_step_label G2 x\")\n   apply(rename_tac i s x nata)(*strict*)\n   prefer 2\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rename_tac i s x nata)(*strict*)\n  apply(simp add: valid_epda_step_label_def)\n  apply(rule conjI)\n   apply(rename_tac i s x nata)(*strict*)\n   apply(rule valid_epda_pop_in_gamma)\n    apply(rename_tac i s x nata)(*strict*)\n    apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac i s x nata)(*strict*)\n   apply(force)\n  apply(rename_tac i s x nata)(*strict*)\n  apply (metis set_drop_subset subset_trans)\n  done\n\nlemma F_DPDA_RMPUE__conf_old__LR_revX_preserves_initial_configurations: \"\n  F_DPDA_RMPUE__relation_TSstructure__RL G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS_initial_configurations G1\n  \\<Longrightarrow> F_DPDA_RMPUE__conf_old__LR_revX c1 \\<in> epdaS_initial_configurations G2\"\n  apply(simp add: epdaS_initial_configurations_def)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_revX_def)\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RMPUE_def)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_revX_def)\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RMPUE_def)\n  apply(clarsimp)\n  apply(simp add: epdaS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__conf_old__LR_revX_def F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE_def)\n  apply(clarsimp)\n  apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimRL_inst_relation_initial_simulationX: \"\n  (\\<forall>G1 G2. F_DPDA_RMPUE__relation_TSstructure__RL G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<exists>d2. epdaS.derivation_initial G2 d2 \\<and> F_DPDA_RMPUE__relation_initial_configuration__RL2 G1 G2 c1 (the (get_configuration (d2 0))) \\<and> F_DPDA_RMPUE__relation_initial_simulation__RL2 G1 G2 c1 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_DPDA_RMPUE__relation_configuration__RL2 G1 G2 c1 (the (get_configuration (d2 n)))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_initial_simulation__RL2_def)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule epdaS.derivation_initialI)\n    apply(rename_tac G1 G2 c1)(*strict*)\n    apply(rule epdaS.der1_is_derivation)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: get_configuration_def der1_def)\n   apply(rule F_DPDA_RMPUE__conf_old__LR_revX_preserves_initial_configurations)\n    apply(rename_tac G1 G2 c1)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: get_configuration_def der1_def)\n   apply(simp add: F_DPDA_RMPUE__relation_initial_configuration__RL2_def)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule_tac\n      x=\"0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule der1_maximum_of_domain)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: get_configuration_def der1_def)\n  apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def)\n  apply(rule epdaS.initial_configurations_are_get_accessible_configurations)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n   apply(rule F_DPDA_RMPUE__preserves_epda)\n   apply(force)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(force)\n  done\n\nlemma pre_states_are_also_new: \"\n  F_DPDA_RMPUE__relation_TSstructure__RL G1 G2\n  \\<Longrightarrow> ea \\<in> epda_delta G2\n  \\<Longrightarrow> F_DPDA_RMPUE__edge_if ea\n  \\<Longrightarrow> Suc (Suc (Suc n)) = length (edge_push ea)\n  \\<Longrightarrow> epdaS.derivation_initial G1 d\n  \\<Longrightarrow> d i = Some (pair e \\<lparr>epdaS_conf_state = cons_state_or_edge_nat_new ea (Suc n), epdaS_conf_scheduler = option_to_list None @ epdaS_conf_scheduler c1', epdaS_conf_stack = rev (edge_push ea) ! Suc n # w\\<rparr>)\n  \\<Longrightarrow> k \\<le> n\n  \\<Longrightarrow> k \\<le> i \\<and> epdaS_conf_state (the (get_configuration (d (i - k)))) = cons_state_or_edge_nat_new ea (Suc n - k)\"\n  apply(induct k)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac k)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e c. d (i-k) = Some (pair e c)\")\n   apply(rename_tac k)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"i\"\n      in epdaS.pre_some_position_is_some_position)\n     apply(rename_tac k)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac k)(*strict*)\n    apply(rule epdaS.derivation_initial_is_derivation)\n    apply(force)\n   apply(rename_tac k)(*strict*)\n   apply(force)\n  apply(rename_tac k)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k eb c)(*strict*)\n  apply(case_tac \"k=i\")\n   apply(rename_tac k eb c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac eb c)(*strict*)\n   apply(simp add: epdaS.derivation_initial_def)\n   apply(clarsimp)\n   apply(rename_tac c)(*strict*)\n   apply(simp add: epdaS_initial_configurations_def)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RMPUE_def)\n  apply(rename_tac k eb c)(*strict*)\n  apply(clarsimp)\n  apply(case_tac i)\n   apply(rename_tac k eb c)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac k eb c nat)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d (nat-k) = Some (pair e1 c1) \\<and> SSd (Suc SSn) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation SSG c1 e2 c2\" for SSd SSn SSG)\n   apply(rename_tac k eb c nat)(*strict*)\n   prefer 2\n   apply(rule epdaS.step_detail_before_some_position)\n     apply(rename_tac k eb c nat)(*strict*)\n     apply(simp add: epdaS.derivation_initial_def)\n     apply(force)\n    apply(rename_tac k eb c nat)(*strict*)\n    apply(force)\n   apply(rename_tac k eb c nat)(*strict*)\n   apply(force)\n  apply(rename_tac k eb c nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k eb c nat e1 e2 c1 c2)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac k eb c nat e1 e2 c1 c2 wa)(*strict*)\n  apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G2 \\<inter> {e. F_DPDA_RMPUE__edge_if e}. e2 \\<in> F_DPDA_RMPUE__edge_then x) \\<or> (\\<exists>x\\<in> epda_delta G2 \\<inter> {e. (\\<not> F_DPDA_RMPUE__edge_if e)}. e2 = F_DPDA_RMPUE__edge_else x)\")\n   apply(rename_tac k eb c nat e1 e2 c1 c2 wa)(*strict*)\n   prefer 2\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL2_def)\n   apply(simp add: F_DPDA_RMPUE_def)\n   apply(blast)\n  apply(rename_tac k eb c nat e1 e2 c1 c2 wa)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac k eb c nat e1 e2 c1 c2 wa)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac k eb c nat e1 c1 c2 wa x)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_else_def)\n   apply (metis F_DPDA_RMPUE__edge_else_def DT_state_or_edge_nat.simps(3) Suc_diff_le equal_derivation_conf_coincide le_SucE)\n  apply(rename_tac k eb c nat e1 e2 c1 c2 wa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k eb c nat e1 e2 c1 c2 wa x)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__edge_then_def F_DPDA_RMPUE__state_def)\n  apply(clarsimp)\n  apply(rename_tac k eb c nat e1 c1 c2 wa x xa)(*strict*)\n  apply(subgoal_tac \"Suc nat - k=Suc (nat-k)\")\n   apply(rename_tac k eb c nat e1 c1 c2 wa x xa)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac k eb c nat e1 c1 c2 wa x xa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k c nat e1 c1 wa x xa)(*strict*)\n  apply(case_tac xa)\n   apply(rename_tac k c nat e1 c1 wa x xa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac k c nat e1 c1 wa x)(*strict*)\n   apply(case_tac \"Suc (Suc 0) < length (edge_push x)\")\n    apply(rename_tac k c nat e1 c1 wa x)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac k c nat e1 c1 wa x)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac k c nat e1 c1 wa x xa nata)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k c nat e1 c1 wa x nata)(*strict*)\n  apply(case_tac \"Suc (Suc (Suc nata)) < length (edge_push x)\")\n   apply(rename_tac k c nat e1 c1 wa x nata)(*strict*)\n   prefer 2\n   apply(clarsimp)\n  apply(rename_tac k c nat e1 c1 wa x nata)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k c nat e1 c1 wa nata)(*strict*)\n  apply (metis Suc_leD Suc_le_mono diff_Suc_Suc diff_diff_cancel diff_le_self le_Suc_eq)\n  done\n\nlemma stack_content_translates_back: \"\n  F_DPDA_RMPUE__relation_TSstructure__RL G1 G2\n  \\<Longrightarrow> ea \\<in> epda_delta G2\n  \\<Longrightarrow> F_DPDA_RMPUE__edge_if ea\n  \\<Longrightarrow> Suc (Suc (Suc n)) = length (edge_push ea)\n  \\<Longrightarrow> epdaS.derivation_initial G1 d\n  \\<Longrightarrow> d i = Some (pair e \\<lparr>epdaS_conf_state = cons_state_or_edge_nat_new ea (Suc n), epdaS_conf_scheduler = option_to_list None @ epdaS_conf_scheduler c1', epdaS_conf_stack = rev (edge_push ea) ! Suc n # w\\<rparr>)\n  \\<Longrightarrow> \\<forall>k\\<le>n. k \\<le> i \\<and> epdaS_conf_state (the (get_configuration (d (i - k)))) = cons_state_or_edge_nat_new ea (Suc n - k)\n  \\<Longrightarrow> d (i - n) = Some (pair eb c)\n  \\<Longrightarrow> i \\<noteq> n\n  \\<Longrightarrow> d (i - Suc n) = Some (pair ec ca)\n  \\<Longrightarrow> k \\<le> Suc n\n  \\<Longrightarrow> epdaS_conf_stack (the (get_configuration (d (i - Suc n + k)))) = drop (length (edge_push ea) - Suc k) (edge_push ea) @ drop (Suc 0) (epdaS_conf_stack ca)\"\n  apply(induct k)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n   apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d (i-Suc n) = Some (pair e1 c1) \\<and> SSd (Suc SSn) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation SSG c1 e2 c2\" for SSd SSn SSG)\n    prefer 2\n    apply(rule epdaS.step_detail_before_some_position)\n      apply(simp add: epdaS.derivation_initial_def)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(clarsimp)\n   apply(rename_tac e2 c2)(*strict*)\n   apply(subgoal_tac \"Suc(i-Suc n)=i-n\")\n    apply(rename_tac e2 c2)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac e2 c2)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac e2)(*strict*)\n   apply(simp add: epdaS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac e2 wa)(*strict*)\n   apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G2 \\<inter> {e. F_DPDA_RMPUE__edge_if e}. e2 \\<in> F_DPDA_RMPUE__edge_then x) \\<or> (\\<exists>x\\<in> epda_delta G2 \\<inter> {e. (\\<not> F_DPDA_RMPUE__edge_if e)}. e2 = F_DPDA_RMPUE__edge_else x)\")\n    apply(rename_tac e2 wa)(*strict*)\n    prefer 2\n    apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL2_def)\n    apply(simp add: F_DPDA_RMPUE_def)\n    apply(blast)\n   apply(rename_tac e2 wa)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac e2 wa)(*strict*)\n    prefer 2\n    apply(clarsimp)\n    apply(rename_tac wa x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_else_def)\n    apply(erule_tac\n      x=\"n\"\n      in allE)\n    apply(clarsimp)\n   apply(rename_tac e2 wa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac e2 wa x)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_then_def F_DPDA_RMPUE__state_def)\n   apply(clarsimp)\n   apply(rename_tac wa x xa)(*strict*)\n   apply(erule_tac\n      x=\"n\"\n      in allE)\n   apply(clarsimp)\n   apply(rename_tac wa x xa)(*strict*)\n   apply(case_tac xa)\n    apply(rename_tac wa x xa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac wa x)(*strict*)\n    apply(case_tac \"Suc (Suc 0) < length (edge_push x)\")\n     apply(rename_tac wa x)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac wa)(*strict*)\n     apply(case_tac \"edge_push ea\")\n      apply(rename_tac wa)(*strict*)\n      apply(force)\n     apply(rename_tac wa a list)(*strict*)\n     apply(subgoal_tac \"\\<exists>w' x'. edge_push ea = w' @ [x']\")\n      apply(rename_tac wa a list)(*strict*)\n      prefer 2\n      apply(rule NonEmptyListHasTailElem)\n      apply(force)\n     apply(rename_tac wa a list)(*strict*)\n     apply(thin_tac \"edge_push ea = a # list\")\n     apply(clarsimp)\n    apply(rename_tac wa x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_if_def)\n   apply(rename_tac wa x xa nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac wa x nat)(*strict*)\n   apply(case_tac \"Suc (Suc nat) < length (edge_push x)\")\n    apply(rename_tac wa x nat)(*strict*)\n    apply(clarsimp)\n    apply(case_tac \"Suc (Suc (Suc nat)) < length (edge_push x)\")\n     apply(rename_tac wa x nat)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac wa x nat)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac wa x nat)(*strict*)\n   apply(subgoal_tac \"Suc (Suc nat) = length (edge_push x)\")\n    apply(rename_tac wa x nat)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac wa x nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac k)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d (i-Suc n+k) = Some (pair e1 c1) \\<and> SSd (Suc SSn) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation SSG c1 e2 c2\" for SSd SSn SSG)\n   apply(rename_tac k)(*strict*)\n   prefer 2\n   apply(rule epdaS.step_detail_before_some_position)\n     apply(rename_tac k)(*strict*)\n     apply(simp add: epdaS.derivation_initial_def)\n     apply(force)\n    apply(rename_tac k)(*strict*)\n    apply(force)\n   apply(rename_tac k)(*strict*)\n   apply(force)\n  apply(rename_tac k)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k e1 e2 c1 c2)(*strict*)\n  apply(simp add: epdaS_step_relation_def get_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac k e1 e2 c1 c2 wa)(*strict*)\n  apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G2 \\<inter> {e. F_DPDA_RMPUE__edge_if e}. e2 \\<in> F_DPDA_RMPUE__edge_then x) \\<or> (\\<exists>x\\<in> epda_delta G2 \\<inter> {e. (\\<not> F_DPDA_RMPUE__edge_if e)}. e2 = F_DPDA_RMPUE__edge_else x)\")\n   apply(rename_tac k e1 e2 c1 c2 wa)(*strict*)\n   prefer 2\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL2_def)\n   apply(simp add: F_DPDA_RMPUE_def)\n   apply(blast)\n  apply(rename_tac k e1 e2 c1 c2 wa)(*strict*)\n  apply(subgoal_tac \"Suc (i - Suc n + k) = i-n+k\")\n   apply(rename_tac k e1 e2 c1 c2 wa)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac k e1 e2 c1 c2 wa)(*strict*)\n  apply(subgoal_tac \"Suc (i + k - Suc n) = i-n+k\")\n   apply(rename_tac k e1 e2 c1 c2 wa)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac k e1 e2 c1 c2 wa)(*strict*)\n  apply(clarsimp)\n  apply(erule disjE)\n   apply(rename_tac k e1 e2 c1 c2 wa)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac k e1 c1 c2 wa x)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_else_def)\n   apply(erule_tac\n      x=\"n-k\"\n      in allE)\n   apply(clarsimp)\n  apply(rename_tac k e1 e2 c1 c2 wa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k e1 e2 c1 c2 wa x)(*strict*)\n  apply(subgoal_tac \"n-k \\<le> i \\<and> epdaS_conf_state (the (case d (i - (n-k)) of None \\<Rightarrow> None | Some (pair e c) \\<Rightarrow> Some c)) = cons_state_or_edge_nat_new ea (Suc n - (n-k))\")\n   apply(rename_tac k e1 e2 c1 c2 wa x)(*strict*)\n   prefer 2\n   apply(erule_tac\n      x=\"n-k\"\n      in allE)\n   apply(clarsimp)\n  apply(rename_tac k e1 e2 c1 c2 wa x)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__edge_then_def F_DPDA_RMPUE__state_def)\n  apply(clarsimp)\n  apply(rename_tac k e1 c1 c2 wa x xa)(*strict*)\n  apply(case_tac \"edge_push ea\")\n   apply(rename_tac k e1 c1 c2 wa x xa)(*strict*)\n   apply(force)\n  apply(rename_tac k e1 c1 c2 wa x xa a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. edge_push ea = w' @ [x']\")\n   apply(rename_tac k e1 c1 c2 wa x xa a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac k e1 c1 c2 wa x xa a list)(*strict*)\n  apply(thin_tac \"edge_push ea = a # list\")\n  apply(clarsimp)\n  apply(rename_tac k e1 c1 c2 wa x xa w' x')(*strict*)\n  apply(case_tac w')\n   apply(rename_tac k e1 c1 c2 wa x xa w' x')(*strict*)\n   apply(clarsimp)\n  apply(rename_tac k e1 c1 c2 wa x xa w' x' a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w'' x'. w' = w'' @ [x']\")\n   apply(rename_tac k e1 c1 c2 wa x xa w' x' a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac k e1 c1 c2 wa x xa w' x' a list)(*strict*)\n  apply(thin_tac \"w' = a # list\")\n  apply(clarsimp)\n  apply(rename_tac k e1 c1 c2 wa x xa x' w'' x'a)(*strict*)\n  apply(case_tac xa)\n   apply(rename_tac k e1 c1 c2 wa x xa x' w'' x'a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac k e1 c1 c2 wa x x' w'' x'a)(*strict*)\n   apply(case_tac \"Suc (Suc 0) < length (edge_push x)\")\n    apply(rename_tac k e1 c1 c2 wa x x' w'' x'a)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac k e1 c1 c2 wa x x' w'' x'a)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_if_def)\n  apply(rename_tac k e1 c1 c2 wa x xa x' w'' x'a nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k e1 c1 c2 wa x x' w'' x'a nat)(*strict*)\n  apply(case_tac \"Suc (Suc (Suc nat)) < length (edge_push x)\")\n   apply(rename_tac k e1 c1 c2 wa x x' w'' x'a nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac e1 c1 c2 wa x' w'' x'a nat)(*strict*)\n   defer\n   apply(rename_tac k e1 c1 c2 wa x x' w'' x'a nat)(*strict*)\n   apply(subgoal_tac \"Suc (Suc nat) = length (edge_push x)\")\n    apply(rename_tac k e1 c1 c2 wa x x' w'' x'a nat)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac k e1 c1 c2 wa x x' w'' x'a nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac e1 c1 c2 wa x' w'' x'a nat)(*strict*)\n  apply(subgoal_tac \"\\<exists>x. x#drop (length w'' - nat) w'' = drop (length w'' - Suc nat) w''\")\n   apply(rename_tac e1 c1 c2 wa x' w'' x'a nat)(*strict*)\n   prefer 2\n   apply(rule drop_with_elem_head)\n   apply(force)\n  apply(rename_tac e1 c1 c2 wa x' w'' x'a nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac e1 c1 c2 wa x' w'' x'a nat x)(*strict*)\n  apply(rule_tac\n      t=\"drop (length w'' - Suc nat) w''\"\n      and s=\"x # drop (length w'' - nat) w''\"\n      in ssubst)\n   apply(rename_tac e1 c1 c2 wa x' w'' x'a nat x)(*strict*)\n   apply(force)\n  apply(rename_tac e1 c1 c2 wa x' w'' x'a nat x)(*strict*)\n  apply(rule_tac\n      t=\"(x # drop (length w'' - nat) w'') @ x'a # x' # drop (Suc 0) (epdaS_conf_stack ca)\"\n      and s=\"x # (drop (length w'' - nat) w'' @ x'a # x' # drop (Suc 0) (epdaS_conf_stack ca))\"\n      in ssubst)\n   apply(rename_tac e1 c1 c2 wa x' w'' x'a nat x)(*strict*)\n   apply(simp (no_asm))\n  apply(rename_tac e1 c1 c2 wa x' w'' x'a nat x)(*strict*)\n  apply(rule_tac\n      t=\"drop (length w'' - nat) w'' @ x'a # x' # drop (Suc 0) (epdaS_conf_stack ca)\"\n      and s=\"(x'a # rev w'') ! nat # wa\"\n      in ssubst)\n   apply(rename_tac e1 c1 c2 wa x' w'' x'a nat x)(*strict*)\n   apply(force)\n  apply(rename_tac e1 c1 c2 wa x' w'' x'a nat x)(*strict*)\n  apply(rule_tac\n      t=\"rev w'' ! nat # (x'a # rev w'') ! nat # wa\"\n      and s=\"(rev w'' ! nat # (x'a # rev w'') ! nat#[]) @ wa\"\n      in ssubst)\n   apply(rename_tac e1 c1 c2 wa x' w'' x'a nat x)(*strict*)\n   apply(force)\n  apply(rename_tac e1 c1 c2 wa x' w'' x'a nat x)(*strict*)\n  apply(rule_tac\n      t=\"[rev w'' ! nat, (x'a # rev w'') ! nat]\"\n      and s=\"[x,(x'a # rev w'') ! nat]\"\n      in ssubst)\n   apply(rename_tac e1 c1 c2 wa x' w'' x'a nat x)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac e1 c1 c2 wa x' w'' x'a nat x)(*strict*)\n  apply(clarsimp)\n  apply(rule drop_with_elem_head2)\n   apply(rename_tac e1 c1 c2 wa x' w'' x'a nat x)(*strict*)\n   apply(force)\n  apply(rename_tac e1 c1 c2 wa x' w'' x'a nat x)(*strict*)\n  apply(force)\n  done\n\nlemma F_DPDA_RMPUE__relation_step_simulation__RL2_maps_to_derivation: \"\n  F_DPDA_RMPUE__relation_TSstructure__RL G1 G2\n  \\<Longrightarrow> F_DPDA_RMPUE__relation_step_simulation__RL2 G1 G2 c1 e1 c1' c2 d2\n  \\<Longrightarrow> F_DPDA_RMPUE__relation_configuration__RL2 G1 G2 c1 c2\n  \\<Longrightarrow> epdaS_step_relation G1 c1 e1 c1'\n  \\<Longrightarrow> epdaS.derivation G2 d2\"\n  apply(simp add: F_DPDA_RMPUE__relation_step_simulation__RL2_def)\n  apply(case_tac \"edge_trg e1\")\n   apply(rename_tac q)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"edge_src e1\")\n    apply(rename_tac q qa)(*strict*)\n    apply(clarsimp)\n    apply(rule epdaS.der2_is_derivation)\n    apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def F_DPDA_RMPUE__edge_else__RL_def)\n    apply(clarsimp)\n    apply(rename_tac q qa w)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RMPUE_def)\n    apply(clarsimp)\n    apply(erule disjE)\n     apply(rename_tac q qa w)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac q qa w x)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__edge_then_def)\n     apply(clarsimp)\n     apply(rename_tac q qa w x xa)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__state_def)\n     apply(case_tac xa)\n      apply(rename_tac q qa w x xa)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac q w x)(*strict*)\n      apply(case_tac \"Suc (Suc 0) < length (edge_push x)\")\n       apply(rename_tac q w x)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac q w x)(*strict*)\n      apply(simp add: F_DPDA_RMPUE__edge_if_def)\n     apply(rename_tac q qa w x xa nat)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac q qa w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q qa w x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_else_def)\n    apply(clarsimp)\n    apply(rename_tac w x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def)\n    apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n    apply(clarsimp)\n    apply(thin_tac \" c1 \\<in> epdaS.get_accessible_configurations (F_DPDA_RMPUE G2)\")\n    apply(rename_tac w x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE_def)\n    apply(case_tac x)\n    apply(rename_tac w x edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n    apply(force)\n   apply(rename_tac q epda_step_label_ext nat)(*strict*)\n   apply(clarsimp)\n   prefer 2\n   apply(rename_tac epda_step_label_ext nat)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"edge_src e1\")\n    apply(rename_tac epda_step_label_ext nat q)(*strict*)\n    apply(clarsimp)\n    apply(rule epdaS.der1_is_derivation)\n   apply(rename_tac epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n   apply(clarsimp)\n   apply(rule epdaS.der1_is_derivation)\n  apply(rename_tac q epda_step_label_ext nat)(*strict*)\n  apply(rename_tac e n)\n  apply(rename_tac q e n)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. epdaS_conf_stack c1'=(edge_push e)@w\")\n   apply(rename_tac q e n)(*strict*)\n   apply(rule epdaS.der2_is_derivation)\n   apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G2 \\<inter> {e. F_DPDA_RMPUE__edge_if e}. e1 \\<in> F_DPDA_RMPUE__edge_then x) \\<or> (\\<exists>x\\<in> epda_delta G2 \\<inter> {e. (\\<not> F_DPDA_RMPUE__edge_if e)}. e1 = F_DPDA_RMPUE__edge_else x)\")\n    apply(rename_tac q e n)(*strict*)\n    prefer 2\n    apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def)\n    apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL2_def)\n    apply(simp add: F_DPDA_RMPUE_def)\n    apply(blast)\n   apply(rename_tac q e n)(*strict*)\n   apply(simp add: epdaS_step_relation_def)\n   apply(rule conjI)\n    apply(rename_tac q e n)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q e n w wa)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL2_def)\n    apply(clarsimp)\n    apply(erule disjE)\n     apply(rename_tac q e n w wa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac q e n w wa x)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__edge_then_def F_DPDA_RMPUE__state_def)\n     apply(clarsimp)\n     apply(rename_tac q e n w wa x xa)(*strict*)\n     apply(case_tac \"Suc (Suc xa) < length (edge_push x)\")\n      apply(rename_tac q e n w wa x xa)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac q e n w wa x xa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac e n w wa x xa)(*strict*)\n     apply(case_tac xa)\n      apply(rename_tac e n w wa x xa)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac e n w wa x xa nat)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac q e n w wa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q e n w wa x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_else_def)\n   apply(rename_tac q e n)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac q e n)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__conf_old__LR_revX_def)\n   apply(rename_tac q e n)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac q e n)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__conf_old__LR_revX_def)\n    apply(clarsimp)\n    apply(rename_tac q e n w wa)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL2_def)\n    apply(clarsimp)\n    apply(erule disjE)\n     apply(rename_tac q e n w wa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac q e n w wa x)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__edge_then_def F_DPDA_RMPUE__state_def)\n     apply(clarsimp)\n     apply(rename_tac q e n w wa x xa)(*strict*)\n     apply(case_tac \"Suc (Suc xa) < length (edge_push x)\")\n      apply(rename_tac q e n w wa x xa)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac q e n w wa x xa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac e n w wa x xa)(*strict*)\n     apply(case_tac xa)\n      apply(rename_tac e n w wa x xa)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac e n w wa x xa nat)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac q e n w wa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q e n w wa x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_else_def)\n   apply(rename_tac q e n)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac q e n)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__conf_old__LR_revX_def)\n    apply(clarsimp)\n    apply(rename_tac q e n w wa)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL2_def)\n    apply(clarsimp)\n    apply(erule disjE)\n     apply(rename_tac q e n w wa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac q e n w wa x)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__edge_then_def F_DPDA_RMPUE__state_def)\n     apply(clarsimp)\n     apply(rename_tac q e n w wa x xa)(*strict*)\n     apply(case_tac \"Suc (Suc xa) < length (edge_push x)\")\n      apply(rename_tac q e n w wa x xa)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac q e n w wa x xa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac e n w wa x xa)(*strict*)\n     apply(case_tac xa)\n      apply(rename_tac e n w wa x xa)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac e n w wa x xa nat)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac e w wa nat)(*strict*)\n     apply(subgoal_tac \"Suc (Suc (Suc nat)) = length (edge_push e)\")\n      apply(rename_tac e w wa nat)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac e w wa nat)(*strict*)\n     apply(clarsimp)\n     apply (metis RMP_edge_event_is_none)\n    apply(rename_tac q e n w wa)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_else_def)\n    apply(clarsimp)\n   apply(rename_tac q e n)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac q e n w wa)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_revX_def)\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL2_def)\n   apply(clarsimp)\n   apply(erule disjE)\n    apply(rename_tac q e n w wa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q e n w wa x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_then_def F_DPDA_RMPUE__state_def)\n    apply(clarsimp)\n    apply(rename_tac q e n w wa x xa)(*strict*)\n    apply(case_tac \"Suc (Suc xa) < length (edge_push x)\")\n     apply(rename_tac q e n w wa x xa)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac q e n w wa x xa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac e n w wa x xa)(*strict*)\n    apply(case_tac xa)\n     apply(rename_tac e n w wa x xa)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac e n w wa x xa nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac e w wa nat)(*strict*)\n    apply(subgoal_tac \"Suc (Suc (Suc nat)) = length (edge_push e)\")\n     apply(rename_tac e w wa nat)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac e w wa nat)(*strict*)\n    apply(clarsimp)\n    prefer 2\n    apply(rename_tac q e n w wa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q e n w wa x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_else_def)\n   apply(rename_tac e w wa nat)(*strict*)\n   apply (metis append_eq_conv_conj drop_Suc_Cons)\n  apply(rename_tac q e n)(*strict*)\n  apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G2 \\<inter> {e. F_DPDA_RMPUE__edge_if e}. e1 \\<in> F_DPDA_RMPUE__edge_then x) \\<or> (\\<exists>x\\<in> epda_delta G2 \\<inter> {e. (\\<not> F_DPDA_RMPUE__edge_if e)}. e1 = F_DPDA_RMPUE__edge_else x)\")\n   apply(rename_tac q e n)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def)\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL2_def)\n   apply(simp add: F_DPDA_RMPUE_def)\n   apply(blast)\n  apply(rename_tac q e n)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac q e n)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac q e n x)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_else_def)\n  apply(rename_tac q e n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac q e n x)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__edge_then_def)\n  apply(clarsimp)\n  apply(rename_tac q e n x xa)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__state_def)\n  apply(case_tac \"Suc (Suc xa) < length (edge_push x)\")\n   apply(rename_tac q e n x xa)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac q e n x xa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac e n x xa)(*strict*)\n  apply(case_tac xa)\n   apply(rename_tac e n x xa)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac e n x xa nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac e nat)(*strict*)\n  apply(subgoal_tac \"Suc (Suc (Suc nat)) = length (edge_push e)\")\n   apply(rename_tac e nat)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac e nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n)\n  apply(rename_tac e n)(*strict*)\n  apply(rule_tac\n      t=\"edge_push e\"\n      and s=\"drop (length(edge_push e)-Suc(Suc (Suc n))) (edge_push e)\"\n      in ssubst)\n   apply(rename_tac e n)(*strict*)\n   apply (metis diff_Suc_Suc diff_self_eq_0 drop_0)\n  apply(rename_tac e n)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. epdaS_conf_stack c1 = drop (length (edge_push e) - Suc (Suc n)) (edge_push e) @ w\")\n   apply(rename_tac e n)(*strict*)\n   apply(erule exE)+\n   apply(rename_tac e n w)(*strict*)\n   apply(rule_tac\n      x=\"w\"\n      in exI)\n   apply(clarsimp)\n   apply(simp add: epdaS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac e n w wa)(*strict*)\n   apply(case_tac \"edge_push e\")\n    apply(rename_tac e n w wa)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac e n w wa a list)(*strict*)\n   apply(clarsimp)\n   apply(case_tac list)\n    apply(rename_tac e n w wa a list)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac e n w wa a list aa lista)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac e n w a aa lista)(*strict*)\n   apply(rule_tac\n      t=\"(rev lista @ [aa, a]) ! Suc (length lista)\"\n      and s=\"([aa, a]) ! (Suc (length lista)- (length (rev lista)))\"\n      in ssubst)\n    apply(rename_tac e n w a aa lista)(*strict*)\n    apply(rule nth_append_2)\n    apply(force)\n   apply(rename_tac e n w a aa lista)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac e n)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. c1=\\<lparr>epdaS_conf_state = cons_state_or_edge_nat_new e (Suc n), epdaS_conf_scheduler = option_to_list None @ epdaS_conf_scheduler c1', epdaS_conf_stack = rev (edge_push e) ! Suc n # w\\<rparr>\")\n   apply(rename_tac e n)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac e n w)(*strict*)\n   apply(case_tac c1)\n   apply(rename_tac e n w epdaS_conf_statea epdaS_conf_schedulera epdaS_conf_stacka)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac e n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac e n w)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def)\n  apply(clarsimp)\n  apply(thin_tac \"epdaS_step_relation G1 \\<lparr>epdaS_conf_state = cons_state_or_edge_nat_new e (Suc n), epdaS_conf_scheduler = option_to_list None @ epdaS_conf_scheduler c1', epdaS_conf_stack = rev (edge_push e) ! Suc n # w\\<rparr> \\<lparr>edge_src = cons_state_or_edge_nat_new e (Suc n), edge_event = None, edge_pop = [rev (edge_push e) ! Suc n], edge_push = [rev (edge_push e) ! Suc (Suc n), rev (edge_push e) ! Suc n], edge_trg = cons_state_or_edge_nat_old (edge_trg e)\\<rparr> c1'\")\n  apply(rename_tac e n w)(*strict*)\n  apply(simp add: epdaS.get_accessible_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac e n w d i)(*strict*)\n  apply(case_tac \"d i\")\n   apply(rename_tac e n w d i)(*strict*)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac e n w d i a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac e n w d i a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac e n w d i option b)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac e n w d i option)(*strict*)\n  apply(rename_tac e)\n  apply(rename_tac ea n w d i e)(*strict*)\n  apply(subgoal_tac \"\\<forall>k\\<le>n. i\\<ge>k \\<and> epdaS_conf_state (the(get_configuration(d (i-k)))) = cons_state_or_edge_nat_new ea ((Suc n)-k) \")\n   apply(rename_tac ea n w d i e)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac ea n w d i e k)(*strict*)\n   apply(rule pre_states_are_also_new)\n         apply(rename_tac ea n w d i e k)(*strict*)\n         apply(force)\n        apply(rename_tac ea n w d i e k)(*strict*)\n        apply(force)\n       apply(rename_tac ea n w d i e k)(*strict*)\n       apply(force)\n      apply(rename_tac ea n w d i e k)(*strict*)\n      apply(force)\n     apply(rename_tac ea n w d i e k)(*strict*)\n     apply(force)\n    apply(rename_tac ea n w d i e k)(*strict*)\n    apply(force)\n   apply(rename_tac ea n w d i e k)(*strict*)\n   apply(force)\n  apply(rename_tac ea n w d i e)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d (i-n) = Some (pair e c)\")\n   apply(rename_tac ea n w d i e)(*strict*)\n   prefer 2\n   apply(erule_tac\n      x=\"n\"\n      in allE)\n   apply(clarsimp)\n   apply(rule_tac\n      m=\"i\"\n      in epdaS.pre_some_position_is_some_position)\n     apply(rename_tac ea n w d i e)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac ea n w d i e)(*strict*)\n    apply(rule epdaS.derivation_initial_is_derivation)\n    apply(force)\n   apply(rename_tac ea n w d i e)(*strict*)\n   apply(force)\n  apply(rename_tac ea n w d i e)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ea n w d i e eb c)(*strict*)\n  apply(case_tac \"i=n\")\n   apply(rename_tac ea n w d i e eb c)(*strict*)\n   apply(erule_tac\n      x=\"n\"\n      in allE)\n   apply(clarsimp)\n   apply(rename_tac ea n w d e eb c)(*strict*)\n   apply(simp add: epdaS.derivation_initial_def F_DPDA_RMPUE__relation_TSstructure__RL_def epdaS_initial_configurations_def)\n   apply(clarsimp)\n   apply(rename_tac ea n w d e c)(*strict*)\n   apply(simp add: F_DPDA_RMPUE_def get_configuration_def)\n  apply(rename_tac ea n w d i e eb c)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d (i-Suc n) = Some (pair e c)\")\n   apply(rename_tac ea n w d i e eb c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"i\"\n      in epdaS.pre_some_position_is_some_position)\n     apply(rename_tac ea n w d i e eb c)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac ea n w d i e eb c)(*strict*)\n    apply(rule epdaS.derivation_initial_is_derivation)\n    apply(force)\n   apply(rename_tac ea n w d i e eb c)(*strict*)\n   apply(force)\n  apply(rename_tac ea n w d i e eb c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ea n w d i e eb c ec ca)(*strict*)\n  apply(subgoal_tac \"\\<forall>k\\<le>Suc n. epdaS_conf_stack (the(get_configuration(d (i-Suc n+k)))) = drop (length (edge_push ea) - Suc k) (edge_push ea) @ drop(Suc 0)(epdaS_conf_stack ca) \")\n   apply(rename_tac ea n w d i e eb c ec ca)(*strict*)\n   apply(erule_tac\n      x=\"Suc n\"\n      and P=\"\\<lambda>k. k \\<le> Suc n \\<longrightarrow> epdaS_conf_stack (the (get_configuration (d (i - Suc n + k)))) = drop (length (edge_push ea) - Suc k) (edge_push ea) @ drop (Suc 0) (epdaS_conf_stack ca)\"\n      in allE)\n   apply(rename_tac ea n w d i e eb c ec ca)(*strict*)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n   apply(subgoal_tac \"(Suc (i - Suc n + n)) = i\")\n    apply(rename_tac ea n w d i e eb c ec ca)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac ea n w d i e eb c ec ca)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ea n w d i e eb c ec ca)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ea n w d i e eb c ec ca k)(*strict*)\n  apply(rule stack_content_translates_back)\n            apply(rename_tac ea n w d i e eb c ec ca k)(*strict*)\n            apply(force)+\n  done\n\nlemma epdaS_epdaS_RMP_StateSimRL_step_relation_step_simulationX: \"\n  \\<forall>G1 G2. F_DPDA_RMPUE__relation_TSstructure__RL G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_DPDA_RMPUE__relation_configuration__RL2 G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<exists>d2. epdaS.derivation G2 d2 \\<and> epdaS.belongs G2 d2 \\<and> the (get_configuration (d2 0)) = c2 \\<and> F_DPDA_RMPUE__relation_step_simulation__RL2 G1 G2 c1 e1 c1' c2 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_DPDA_RMPUE__relation_configuration__RL2 G1 G2 c1' (the (get_configuration (d2 n))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_step_simulation__RL2_def)\n  apply(case_tac \"edge_trg e1\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"edge_src e1\")\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(clarsimp)\n    apply(rule context_conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(rule F_DPDA_RMPUE__relation_step_simulation__RL2_maps_to_derivation)\n        apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n        apply(force)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n       prefer 2\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_step_simulation__RL2_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(rule epdaS.der2_belongs_prime)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n       apply (metis epdaS_epdaS_RMP_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs F_DPDA_RMPUE__relation_structure__LR_def F_DPDA_RMPUE__relation_TSstructure__RL_def)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def)\n     apply(rule F_DPDA_RMPUE__conf_old__LR_revX_preserves_configurations)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(rule_tac\n      A=\"epdaS.get_accessible_configurations G1\"\n      in set_mp)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      apply(rule epdaS.get_accessible_configurations_are_configurations)\n      apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n      apply(rule F_DPDA_RMPUE__preserves_epda)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply (metis)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(simp add: get_configuration_def der2_def)\n     apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(rule der2_maximum_of_domain)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(simp (no_asm) add: der2_def get_configuration_def)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def)\n    apply(rule_tac\n      ?e1.0=\"e1\"\n      in epdaS.der2_preserves_get_accessible_configurations)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n      apply(rule F_DPDA_RMPUE__preserves_epda)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(rule epdaS.der2_is_derivation)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n   apply(clarsimp)\n   prefer 2\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"edge_src e1\")\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n    apply(clarsimp)\n    prefer 2\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac ex1 n1 ex2 n2)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' ex1 n1 ex2 n2)(*strict*)\n    apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G2 \\<inter> {e. F_DPDA_RMPUE__edge_if e}. e1 \\<in> F_DPDA_RMPUE__edge_then x) \\<or> (\\<exists>x\\<in> epda_delta G2 \\<inter> {e. (\\<not> F_DPDA_RMPUE__edge_if e)}. e1 = F_DPDA_RMPUE__edge_else x)\")\n     apply(rename_tac G1 G2 c1 c2 e1 c1' ex1 n1 ex2 n2)(*strict*)\n     prefer 2\n     apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def)\n     apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL2_def)\n     apply(simp add: F_DPDA_RMPUE_def)\n     apply(blast)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' ex1 n1 ex2 n2)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' ex1 n1 ex2 n2)(*strict*)\n     prefer 2\n     apply(clarsimp)\n     apply(rename_tac G1 G2 c1 c2 c1' ex1 n1 ex2 n2 x)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__edge_else_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' ex1 n1 ex2 n2)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' ex1 n1 ex2 n2 x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_then_def)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 c1' ex1 n1 ex2 n2 x xa)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__state_def)\n    apply(case_tac \"Suc (Suc xa) < length (edge_push x)\")\n     apply(rename_tac G1 G2 c1 c2 c1' ex1 n1 ex2 n2 x xa)(*strict*)\n     prefer 2\n     apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 c1' ex1 n1 ex2 n2 x xa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 c1' ex1 ex2 n2 xa)(*strict*)\n    apply(case_tac \"xa\")\n     apply(rename_tac G1 G2 c1 c2 c1' ex1 ex2 n2 xa)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 c1' ex1 ex2 n2 xa nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 c1' ex2 nat)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 c1' ex2 nat)(*strict*)\n     apply(rule epdaS.der1_is_derivation)\n    apply(rename_tac G1 G2 c1 c2 c1' ex2 nat)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 c1' ex2 nat)(*strict*)\n     apply(rule epdaS.der1_belongs)\n     apply(rule F_DPDA_RMPUE__conf_old__LR_revX_preserves_configurations)\n       apply(rename_tac G1 G2 c1 c2 c1' ex2 nat)(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 c1' ex2 nat)(*strict*)\n      apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def)\n     apply(rename_tac G1 G2 c1 c2 c1' ex2 nat)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def)\n     apply(rule_tac\n      A=\"epdaS.get_accessible_configurations G1\"\n      in set_mp)\n      apply(rename_tac G1 G2 c1 c2 c1' ex2 nat)(*strict*)\n      apply(rule epdaS.get_accessible_configurations_are_configurations)\n      apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n      apply(rule F_DPDA_RMPUE__preserves_epda)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 c1' ex2 nat)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 c1' ex2 nat)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 c1' ex2 nat)(*strict*)\n     apply(simp add: der1_def get_configuration_def)\n     apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def)\n    apply(rename_tac G1 G2 c1 c2 c1' ex2 nat)(*strict*)\n    apply(rule_tac\n      x=\"0\"\n      in exI)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 c1' ex2 nat)(*strict*)\n     apply(rule der1_maximum_of_domain)\n    apply(rename_tac G1 G2 c1 c2 c1' ex2 nat)(*strict*)\n    apply(simp add: der1_def get_configuration_def)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 c1' ex2 nat)(*strict*)\n     apply(rule_tac\n      ?e1.0=\"\\<lparr>edge_src = cons_state_or_edge_nat_new ex2 (Suc nat), edge_event = None, edge_pop = [rev (edge_push ex2) ! Suc nat], edge_push = [rev (edge_push ex2) ! Suc (Suc nat), rev (edge_push ex2) ! Suc nat], edge_trg = cons_state_or_edge_nat_new ex2 (Suc (Suc nat))\\<rparr>\"\n      in epdaS.der2_preserves_get_accessible_configurations)\n       apply(rename_tac G1 G2 c1 c2 c1' ex2 nat)(*strict*)\n       apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n       apply(rule F_DPDA_RMPUE__preserves_epda)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 c1' ex2 nat)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 c1' ex2 nat)(*strict*)\n     apply(rule epdaS.der2_is_derivation)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 c1' ex2 nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n    apply(thin_tac \"c1 \\<in> epdaS.get_accessible_configurations G1\")\n    apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__conf_old__LR_revX_def)\n    apply(simp add: epdaS_step_relation_def)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c1' ex2 nat w)(*strict*)\n    apply(simp add: option_to_list_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext nat q)(*strict*)\n   apply(rename_tac ex nx q)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' ex nx q)(*strict*)\n   apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G2 \\<inter> {e. F_DPDA_RMPUE__edge_if e}. e1 \\<in> F_DPDA_RMPUE__edge_then x) \\<or> (\\<exists>x\\<in> epda_delta G2 \\<inter> {e. (\\<not> F_DPDA_RMPUE__edge_if e)}. e1 = F_DPDA_RMPUE__edge_else x)\")\n    apply(rename_tac G1 G2 c1 c2 e1 c1' ex nx q)(*strict*)\n    prefer 2\n    apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def)\n    apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL2_def)\n    apply(simp add: F_DPDA_RMPUE_def)\n    apply(blast)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' ex nx q)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' ex nx q)(*strict*)\n    prefer 2\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 c1' ex nx q x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_else_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' ex nx q)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' ex nx q x)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_then_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 c1' ex nx q x xa)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__state_def)\n   apply(case_tac \"Suc (Suc xa) < length (edge_push x)\")\n    apply(rename_tac G1 G2 c1 c2 c1' ex nx q x xa)(*strict*)\n    prefer 2\n    apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 c1' ex nx q x xa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 c1' ex q xa)(*strict*)\n   apply(case_tac \"xa\")\n    apply(rename_tac G1 G2 c1 c2 c1' ex q xa)(*strict*)\n    prefer 2\n    apply(rename_tac G1 G2 c1 c2 c1' ex q xa nat)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 c1' ex q xa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 c1' ex)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 c1' ex)(*strict*)\n    apply(rule epdaS.der1_is_derivation)\n   apply(rename_tac G1 G2 c1 c2 c1' ex)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 c1' ex)(*strict*)\n    apply(rule epdaS.der1_belongs)\n    apply(rule F_DPDA_RMPUE__conf_old__LR_revX_preserves_configurations)\n      apply(rename_tac G1 G2 c1 c2 c1' ex)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 c1' ex)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def)\n    apply(rename_tac G1 G2 c1 c2 c1' ex)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def)\n    apply(rule_tac\n      A=\"epdaS.get_accessible_configurations G1\"\n      in set_mp)\n     apply(rename_tac G1 G2 c1 c2 c1' ex)(*strict*)\n     apply(rule epdaS.get_accessible_configurations_are_configurations)\n     apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n     apply(rule F_DPDA_RMPUE__preserves_epda)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 c1' ex)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 c1' ex)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 c1' ex)(*strict*)\n    apply(simp add: der1_def get_configuration_def)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def)\n   apply(rename_tac G1 G2 c1 c2 c1' ex)(*strict*)\n   apply(rule_tac\n      x=\"0\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 c1' ex)(*strict*)\n    apply(rule der1_maximum_of_domain)\n   apply(rename_tac G1 G2 c1 c2 c1' ex)(*strict*)\n   apply(simp add: der1_def get_configuration_def)\n   apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 c1' ex)(*strict*)\n    apply(rule_tac\n      ?e1.0=\"\\<lparr>edge_src = cons_state_or_edge_nat_old (edge_src ex), edge_event = None, edge_pop = [rev (edge_push ex) ! 0], edge_push = [rev (edge_push ex) ! Suc 0, rev (edge_push ex) ! 0], edge_trg = cons_state_or_edge_nat_new ex (Suc 0)\\<rparr>\"\n      in epdaS.der2_preserves_get_accessible_configurations)\n      apply(rename_tac G1 G2 c1 c2 c1' ex)(*strict*)\n      apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n      apply(rule F_DPDA_RMPUE__preserves_epda)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 c1' ex)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 c1' ex)(*strict*)\n    apply(rule epdaS.der2_is_derivation)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 c1' ex)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n   apply(thin_tac \"c1 \\<in> epdaS.get_accessible_configurations G1\")\n   apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__conf_old__LR_revX_def)\n   apply(simp add: epdaS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' ex w)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c1' ex w)(*strict*)\n    apply(simp add: option_to_list_def)\n   apply(rename_tac G1 G2 c1 c1' ex w)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 c1' ex w)(*strict*)\n   apply(simp add: valid_dpda_def valid_pda_def push_and_pop_edges_seperated_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"ex\"\n      and P=\"\\<lambda>ex. \\<not> F_DPDA_SPPE__edge_if ex\"\n      in ballE)\n    apply(rename_tac G2 c1 c1' ex w)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G2 c1 c1' ex w)(*strict*)\n   apply(simp add: F_DPDA_SPPE__edge_if_def)\n   apply(erule disjE)\n    apply(rename_tac G2 c1 c1' ex w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G2 c1 c1' ex w y)(*strict*)\n    apply(simp add: read_edges_seperated_def)\n    apply(erule_tac\n      x=\"ex\"\n      and P=\"\\<lambda>ex. length (edge_pop ex) = Suc 0\"\n      in ballE)\n     apply(rename_tac G2 c1 c1' ex w y)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G2 c1 c1' ex w y)(*strict*)\n    apply(simp add: FB_executing_edge_def strict_executing_edge_def)\n   apply(rename_tac G2 c1 c1' ex w)(*strict*)\n   apply(case_tac \"edge_push ex\")\n    apply(rename_tac G2 c1 c1' ex w)(*strict*)\n    apply(force)\n   apply(rename_tac G2 c1 c1' ex w a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. edge_push ex = w' @ [x']\")\n    apply(rename_tac G2 c1 c1' ex w a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac G2 c1 c1' ex w a list)(*strict*)\n   apply(thin_tac \"edge_push ex = a # list\")\n   apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n  apply(rule context_conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n   apply(rule F_DPDA_RMPUE__relation_step_simulation__RL2_maps_to_derivation)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_step_simulation__RL2_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext nat)(*strict*)\n  apply(rename_tac ex nx)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' q ex nx)(*strict*)\n  apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G2 \\<inter> {e. F_DPDA_RMPUE__edge_if e}. e1 \\<in> F_DPDA_RMPUE__edge_then x) \\<or> (\\<exists>x\\<in> epda_delta G2 \\<inter> {e. (\\<not> F_DPDA_RMPUE__edge_if e)}. e1 = F_DPDA_RMPUE__edge_else x)\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q ex nx)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def)\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL2_def)\n   apply(simp add: F_DPDA_RMPUE_def)\n   apply(blast)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' q ex nx)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q ex nx)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 c1' q ex nx x)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_else_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' q ex nx)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' q ex nx x)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__edge_then_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 c1' q ex nx x xa)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__state_def)\n  apply(case_tac \"Suc (Suc xa) < length (edge_push x)\")\n   apply(rename_tac G1 G2 c1 c2 c1' q ex nx x xa)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 c1' q ex nx x xa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 c1' ex nx x xa)(*strict*)\n  apply(case_tac \"xa\")\n   apply(rename_tac G1 G2 c1 c2 c1' ex nx x xa)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 c1' ex nx x xa nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n  apply(subgoal_tac \"Suc (Suc (Suc nat)) = length (edge_push ex)\")\n   apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n  apply(clarsimp)\n  apply(rule context_conjI)\n   apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n   apply(rule epdaS.der2_belongs)\n     apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n     apply(rule F_DPDA_RMPUE__conf_old__LR_revX_preserves_configurations)\n       apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n      apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def)\n     apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n     apply(rule_tac\n      A=\"epdaS.get_accessible_configurations G1\"\n      in set_mp)\n      apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n      apply(rule epdaS.get_accessible_configurations_are_configurations)\n      apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n      apply(rule F_DPDA_RMPUE__preserves_epda)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def)\n    apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def epda_step_labels_def F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE_def)\n   apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n   apply(rule F_DPDA_RMPUE__conf_old__LR_revX_preserves_configurations)\n     apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def)\n    apply(rule_tac\n      ?e1.0=\"\\<lparr>edge_src = cons_state_or_edge_nat_new ex (Suc nat), edge_event = None, edge_pop = [rev (edge_push ex) ! Suc nat], edge_push = [rev (edge_push ex) ! Suc (Suc nat), rev (edge_push ex) ! Suc nat], edge_trg = cons_state_or_edge_nat_old (edge_trg ex)\\<rparr>\"\n      in epdaS.der2_preserves_get_accessible_configurations)\n      apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n      apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n      apply(rule F_DPDA_RMPUE__preserves_epda)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n    apply(rule epdaS.der2_is_derivation)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n   apply(rule epdaS.AX_step_relation_preserves_belongsC)\n     apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n     apply(rule F_DPDA_RMPUE__preserves_epda)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def)\n   apply(rule_tac\n      A=\"epdaS.get_accessible_configurations G1\"\n      in set_mp)\n    apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n    apply(rule epdaS.get_accessible_configurations_are_configurations)\n    apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n    apply(rule F_DPDA_RMPUE__preserves_epda)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n   apply(simp add: get_configuration_def der2_def)\n   apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def)\n  apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n  apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n   apply(rule der2_maximum_of_domain)\n  apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n  apply(simp (no_asm) add: der1_def get_configuration_def)\n  apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n   apply(rule_tac\n      ?e1.0=\"\\<lparr>edge_src = cons_state_or_edge_nat_new ex (Suc nat), edge_event = None, edge_pop = [rev (edge_push ex) ! Suc nat], edge_push = [rev (edge_push ex) ! Suc (Suc nat), rev (edge_push ex) ! Suc nat], edge_trg = cons_state_or_edge_nat_old (edge_trg ex)\\<rparr>\"\n      in epdaS.der2_preserves_get_accessible_configurations)\n     apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n     apply(rule F_DPDA_RMPUE__preserves_epda)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n   apply(rule epdaS.der2_is_derivation)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 c1' ex nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c1' ex nat)(*strict*)\n  apply(simp add: der2_def)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimRLReach_inst_ATS_Simulation_Configuration_WeakReach_axioms: \"\n  ATS_Simulation_Configuration_WeakReach_axioms epda_step_labels epdaS_step_relation epdaS_configurations epda_step_labels epdaS_step_relation F_DPDA_RMPUE__relation_configuration__RL2 F_DPDA_RMPUE__relation_TSstructure__RL F_DPDA_RMPUE__relation_step_simulation__RL2 F_DPDA_RMPUE__relation_labels__RL2\"\n  apply(simp add: ATS_Simulation_Configuration_WeakReach_axioms_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_step_simulation__RL2_def)\n  apply(case_tac \"edge_trg e1\")\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n q)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"edge_src e1\")\n    apply(rename_tac G1 G2 c1 e1 c1' d2 n q qa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 e1 c1' n q qa)(*strict*)\n    apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n    apply(rule_tac\n      x=\"(F_DPDA_RMPUE__edge_else__RL e1)\"\n      in exI)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 e1 c1' n q qa)(*strict*)\n     apply(simp add: der2_def)\n    apply(rename_tac G1 G2 c1 e1 c1' n q qa)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_labels__RL2_def F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 e1 c1' n q qa)(*strict*)\n     prefer 2\n     apply(rule disjI2)\n     apply(simp add: F_DPDA_RMPUE__edge_else_def F_DPDA_RMPUE__edge_else__RL_def)\n    apply(rename_tac G1 G2 c1 e1 c1' n q qa)(*strict*)\n    apply(rule_tac\n      t=\"epda_delta G2\"\n      and s=\"epda_step_labels G2\"\n      in ssubst)\n     apply(rename_tac G1 G2 c1 e1 c1' n q qa)(*strict*)\n     apply(simp add: epda_step_labels_def)\n    apply(rename_tac G1 G2 c1 e1 c1' n q qa)(*strict*)\n    apply(rule_tac\n      i=\"Suc 0\"\n      and d=\"(der2 (F_DPDA_RMPUE__conf_old__LR_revX c1) (F_DPDA_RMPUE__edge_else__RL e1) (F_DPDA_RMPUE__conf_old__LR_revX c1'))\"\n      in epdaS.belongs_step_labels)\n     apply(rename_tac G1 G2 c1 e1 c1' n q qa)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 e1 c1' n q qa)(*strict*)\n    apply(simp add: der2_def)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n q epda_step_label_ext nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' n q epda_step_label_ext nat)(*strict*)\n   apply(rename_tac ex nx)\n   apply(rename_tac G1 G2 c1 e1 c1' n q ex nx)(*strict*)\n   apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n   apply(rule_tac\n      x=\"ex\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 e1 c1' n q ex nx)(*strict*)\n    apply(simp add: der2_def)\n   apply(rename_tac G1 G2 c1 e1 c1' n q ex nx)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_labels__RL2_def F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n   apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G2 \\<inter> {e. F_DPDA_RMPUE__edge_if e}. e1 \\<in> F_DPDA_RMPUE__edge_then x) \\<or> (\\<exists>x\\<in> epda_delta G2 \\<inter> {e. (\\<not> F_DPDA_RMPUE__edge_if e)}. e1 = F_DPDA_RMPUE__edge_else x)\")\n    apply(rename_tac G1 G2 c1 e1 c1' n q ex nx)(*strict*)\n    prefer 2\n    apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def)\n    apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL2_def)\n    apply(simp add: F_DPDA_RMPUE_def)\n    apply(blast)\n   apply(rename_tac G1 G2 c1 e1 c1' n q ex nx)(*strict*)\n   apply(erule_tac\n      P=\"\\<exists>x\\<in> epda_delta G2 \\<inter> {e. F_DPDA_RMPUE__edge_if e}. e1 \\<in> F_DPDA_RMPUE__edge_then x\"\n      in disjE)\n    apply(rename_tac G1 G2 c1 e1 c1' n q ex nx)(*strict*)\n    prefer 2\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c1' n q ex nx x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_else_def)\n   apply(rename_tac G1 G2 c1 e1 c1' n q ex nx)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' n q ex nx x)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_then_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' n q ex nx x xa)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__state_def)\n   apply(case_tac \"Suc (Suc xa) < length (edge_push x)\")\n    apply(rename_tac G1 G2 c1 c1' n q ex nx x xa)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' n q ex nx x xa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' n ex nx x xa)(*strict*)\n   apply(subgoal_tac \"Suc (Suc xa) = length (edge_push x)\")\n    apply(rename_tac G1 G2 c1 c1' n ex nx x xa)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G1 G2 c1 c1' n ex nx x xa)(*strict*)\n   apply(clarsimp)\n   apply(case_tac xa)\n    apply(rename_tac G1 G2 c1 c1' n ex nx x xa)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' n ex nx x xa nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' n ex nat)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_else_def)\n   apply(rule_tac\n      x=\"Suc nat\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n epda_step_label_ext nat)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"edge_src e1\")\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n epda_step_label_ext nat q)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' n epda_step_label_ext nat q)(*strict*)\n   apply(subgoal_tac \"False\")\n    apply(rename_tac G1 G2 c1 e1 c1' n epda_step_label_ext nat q)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 e1 c1' n epda_step_label_ext nat q)(*strict*)\n   apply(subgoal_tac \"n=0\")\n    apply(rename_tac G1 G2 c1 e1 c1' n epda_step_label_ext nat q)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext nat q)(*strict*)\n    apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G2 \\<inter> {e. F_DPDA_RMPUE__edge_if e}. e1 \\<in> F_DPDA_RMPUE__edge_then x) \\<or> (\\<exists>x\\<in> epda_delta G2 \\<inter> {e. (\\<not> F_DPDA_RMPUE__edge_if e)}. e1 = F_DPDA_RMPUE__edge_else x)\")\n     apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext nat q)(*strict*)\n     prefer 2\n     apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def)\n     apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL2_def)\n     apply(simp add: F_DPDA_RMPUE_def)\n     apply(blast)\n    apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext nat q)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext nat q)(*strict*)\n     prefer 2\n     apply(clarsimp)\n     apply(rename_tac G1 G2 c1 c1' epda_step_label_ext nat q x)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__edge_else_def)\n    apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext nat q)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext nat q x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_then_def)\n    apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_exta nat q x)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c1' epda_step_label_exta nat q x xa)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__state_def)\n    apply(case_tac \"Suc (Suc xa) < length (edge_push x)\")\n     apply(rename_tac G1 G2 c1 c1' epda_step_label_exta nat q x xa)(*strict*)\n     prefer 2\n     apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c1' epda_step_label_exta nat q x xa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c1' epda_step_label_exta q xa)(*strict*)\n    apply(rename_tac ex qx xa)\n    apply(rename_tac G1 G2 c1 c1' ex qx xa)(*strict*)\n    apply(case_tac xa)\n     apply(rename_tac G1 G2 c1 c1' ex qx xa)(*strict*)\n     prefer 2\n     apply(rename_tac G1 G2 c1 c1' ex qx xa nat)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c1' ex qx xa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n    apply(subgoal_tac \"\\<exists>c. epdaS_step_relation G2 (F_DPDA_RMPUE__conf_old__LR_revX c1) ex c\")\n     apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G1 G2 c1 c1' ex c)(*strict*)\n     apply(erule_tac\n      x=\"der2 (F_DPDA_RMPUE__conf_old__LR_revX c1) ex c\"\n      in allE)\n     apply(erule impE)\n      apply(rename_tac G1 G2 c1 c1' ex c)(*strict*)\n      apply(simp add: get_configuration_def der2_def der1_def)\n     apply(rename_tac G1 G2 c1 c1' ex c)(*strict*)\n     apply(erule impE)\n      apply(rename_tac G1 G2 c1 c1' ex c)(*strict*)\n      apply(rule epdaS.der2_is_derivation)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c1' ex c)(*strict*)\n     apply(erule disjE)\n      apply(rename_tac G1 G2 c1 c1' ex c)(*strict*)\n      apply(erule_tac\n      x=\"Suc 0\"\n      in allE)\n      apply(simp add: maximum_of_domain_def der2_def)\n     apply(rename_tac G1 G2 c1 c1' ex c)(*strict*)\n     apply(erule_tac\n      x=\"Suc 0\"\n      in allE)\n     apply(erule_tac x=\"ex\"in allE)\n     apply(erule disjE)\n      apply(rename_tac G1 G2 c1 c1' ex c)(*strict*)\n      apply(simp add: der2_def)\n     apply(rename_tac G1 G2 c1 c1' ex c)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_labels__RL2_def)\n     apply(simp add: F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n     apply(erule conjE)\n     apply(simp add: F_DPDA_RMPUE__edge_then_def)\n     apply(erule_tac\n      x=\"0\"\n      in allE)\n     apply(clarsimp)\n     apply(simp add: F_DPDA_RMPUE__state_def)\n    apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n    apply(rule epdaS_step_exists)\n         apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n         apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n         apply(clarsimp)\n         apply(rename_tac G2 c1 c1' ex)(*strict*)\n         apply(simp add: valid_dpda_def valid_pda_def)\n        apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n        apply(rule_tac\n      i=\"0\"\n      and d=\"der1 (F_DPDA_RMPUE__conf_old__LR_revX c1)\"\n      in epdaS.belongs_configurations)\n         apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n         apply(force)\n        apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n        apply(simp add: der1_def)\n       apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n      apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def)\n     apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n     apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def prefix_def)\n     apply(rule_tac\n      x=\"epdaS_conf_scheduler c1'\"\n      in exI)\n     apply(clarsimp)\n     apply(rename_tac G1 G2 c1 c1' ex w)(*strict*)\n     apply(case_tac \"edge_event ex\")\n      apply(rename_tac G1 G2 c1 c1' ex w)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c1' ex w a)(*strict*)\n     apply(clarsimp)\n     apply(simp add: strict_executing_edge_def FB_executing_edge_def F_DPDA_RMPUE__edge_if_def F_DPDA_RMPUE__relation_TSstructure__RL_def read_edges_seperated_def)\n     apply(clarsimp)\n     apply(rename_tac G2 c1 c1' ex w a)(*strict*)\n     apply(erule_tac\n      x=\"ex\"\n      in ballE)\n      apply(rename_tac G2 c1 c1' ex w a)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac G2 c1 c1' ex w a)(*strict*)\n     apply(clarsimp)\n     apply(simp add: valid_dpda_def valid_pda_def)\n    apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n    apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def prefix_def)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c1' ex w)(*strict*)\n    apply(simp add: strict_executing_edge_def push_and_pop_edges_seperated_def FB_executing_edge_def F_DPDA_RMPUE__edge_if_def F_DPDA_RMPUE__relation_TSstructure__RL_def read_edges_seperated_def)\n    apply(simp add: valid_dpda_def valid_pda_def)\n    apply(clarsimp)\n    apply(rename_tac G2 c1 c1' ex w)(*strict*)\n    apply(erule_tac\n      x=\"ex\"\n      and P=\"\\<lambda>ex. length (edge_pop ex) = Suc 0\"\n      in ballE)\n     apply(rename_tac G2 c1 c1' ex w)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G2 c1 c1' ex w)(*strict*)\n    apply(erule_tac\n      x=\"ex\"\n      and P=\"\\<lambda>ex. \\<not> F_DPDA_SPPE__edge_if ex\"\n      in ballE)\n     apply(rename_tac G2 c1 c1' ex w)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G2 c1 c1' ex w)(*strict*)\n    apply(erule_tac\n      x=\"ex\"\n      in ballE)\n     apply(rename_tac G2 c1 c1' ex w)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G2 c1 c1' ex w)(*strict*)\n    apply(case_tac \"edge_event ex\")\n     apply(rename_tac G2 c1 c1' ex w)(*strict*)\n     prefer 2\n     apply(rename_tac G2 c1 c1' ex w a)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G2 c1 c1' ex w)(*strict*)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_SPPE__edge_if_def)\n    apply(case_tac \"edge_pop ex\")\n     apply(rename_tac G2 c1 c1' ex w)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G2 c1 c1' ex w a list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G2 c1 c1' ex w a)(*strict*)\n    apply(case_tac \"edge_push ex\")\n     apply(rename_tac G2 c1 c1' ex w a)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G2 c1 c1' ex w a aa list)(*strict*)\n    apply(subgoal_tac \"\\<exists>w' x'. edge_push ex = w' @ [x']\")\n     apply(rename_tac G2 c1 c1' ex w a aa list)(*strict*)\n     prefer 2\n     apply(rule NonEmptyListHasTailElem)\n     apply(force)\n    apply(rename_tac G2 c1 c1' ex w a aa list)(*strict*)\n    apply(thin_tac \"edge_push ex = aa # list\")\n    apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' n epda_step_label_ext nat q)(*strict*)\n   apply(rule epdaS.maximum_of_domainUnique)\n     apply(rename_tac G1 G2 c1 e1 c1' n epda_step_label_ext nat q)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 e1 c1' n epda_step_label_ext nat q)(*strict*)\n    apply(rule der1_maximum_of_domain)\n   apply(rename_tac G1 G2 c1 e1 c1' n epda_step_label_ext nat q)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1' n epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n  apply(rename_tac ex1 n1 ex2 n2)\n  apply(rename_tac G1 G2 c1 e1 c1' n ex1 n1 ex2 n2)(*strict*)\n  apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G2 \\<inter> {e. F_DPDA_RMPUE__edge_if e}. e1 \\<in> F_DPDA_RMPUE__edge_then x) \\<or> (\\<exists>x\\<in> epda_delta G2 \\<inter> {e. (\\<not> F_DPDA_RMPUE__edge_if e)}. e1 = F_DPDA_RMPUE__edge_else x)\")\n   apply(rename_tac G1 G2 c1 e1 c1' n ex1 n1 ex2 n2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def)\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL2_def)\n   apply(simp add: F_DPDA_RMPUE_def)\n   apply(blast)\n  apply(rename_tac G1 G2 c1 e1 c1' n ex1 n1 ex2 n2)(*strict*)\n  apply(erule_tac\n      P=\"\\<exists>x\\<in> epda_delta G2 \\<inter> {e. F_DPDA_RMPUE__edge_if e}. e1 \\<in> F_DPDA_RMPUE__edge_then x\"\n      in disjE)\n   apply(rename_tac G1 G2 c1 e1 c1' n ex1 n1 ex2 n2)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' n ex1 n1 ex2 n2 x)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_else_def)\n  apply(rename_tac G1 G2 c1 e1 c1' n ex1 n1 ex2 n2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1' n ex1 n1 ex2 n2 x)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__edge_then_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c1' n ex1 n1 ex2 n2 x xa)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__state_def)\n  apply(case_tac \"Suc (Suc xa) < length (edge_push x)\")\n   apply(rename_tac G1 G2 c1 c1' n ex1 n1 ex2 n2 x xa)(*strict*)\n   prefer 2\n   apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c1' n ex1 n1 ex2 n2 x xa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c1' n ex1 ex2 n2 xa)(*strict*)\n  apply(case_tac xa)\n   apply(rename_tac G1 G2 c1 c1' n ex1 ex2 n2 xa)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c1' n ex1 ex2 n2 xa nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c1' n ex2 nat)(*strict*)\n  apply(subgoal_tac \"False\")\n   apply(rename_tac G1 G2 c1 c1' n ex2 nat)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c1' n ex2 nat)(*strict*)\n  apply(subgoal_tac \"n=0\")\n   apply(rename_tac G1 G2 c1 c1' n ex2 nat)(*strict*)\n   prefer 2\n   apply(rule epdaS.maximum_of_domainUnique)\n     apply(rename_tac G1 G2 c1 c1' n ex2 nat)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c1' n ex2 nat)(*strict*)\n    apply(rule der1_maximum_of_domain)\n   apply(rename_tac G1 G2 c1 c1' n ex2 nat)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c1' n ex2 nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. epdaS_step_relation G2 (F_DPDA_RMPUE__conf_old__LR_revX c1) ex2 c\")\n   apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' ex2 nat c)(*strict*)\n   apply(erule_tac\n      x=\"der2 (F_DPDA_RMPUE__conf_old__LR_revX c1) ex2 c\"\n      in allE)\n   apply(erule impE)\n    apply(rename_tac G1 G2 c1 c1' ex2 nat c)(*strict*)\n    apply(simp add: get_configuration_def der2_def der1_def)\n   apply(rename_tac G1 G2 c1 c1' ex2 nat c)(*strict*)\n   apply(erule impE)\n    apply(rename_tac G1 G2 c1 c1' ex2 nat c)(*strict*)\n    apply(rule epdaS.der2_is_derivation)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c1' ex2 nat c)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac G1 G2 c1 c1' ex2 nat c)(*strict*)\n    apply(erule_tac\n      x=\"Suc 0\"\n      in allE)\n    apply(simp add: maximum_of_domain_def der2_def)\n   apply(rename_tac G1 G2 c1 c1' ex2 nat c)(*strict*)\n   apply(erule_tac\n      x=\"Suc 0\"\n      in allE)\n   apply(erule_tac x=\"ex2\"in allE)\n   apply(erule disjE)\n    apply(rename_tac G1 G2 c1 c1' ex2 nat c)(*strict*)\n    apply(simp add: der2_def)\n   apply(rename_tac G1 G2 c1 c1' ex2 nat c)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_labels__RL2_def)\n   apply(simp add: F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n   apply(erule conjE)\n   apply(simp add: F_DPDA_RMPUE__edge_then_def)\n   apply(erule_tac\n      x=\"Suc nat\"\n      in allE)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RMPUE__state_def)\n  apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n  apply(rule epdaS_step_exists)\n       apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n       apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n       apply(clarsimp)\n       apply(rename_tac G2 c1 c1' ex2 nat)(*strict*)\n       apply(simp add: valid_dpda_def valid_pda_def)\n      apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n      apply(rule_tac\n      i=\"0\"\n      and d=\"der1 (F_DPDA_RMPUE__conf_old__LR_revX c1)\"\n      in epdaS.belongs_configurations)\n       apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n      apply(simp add: der1_def)\n     apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n    apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def)\n   apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n   apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def prefix_def)\n   apply(rule_tac\n      x=\"epdaS_conf_scheduler c1'\"\n      in exI)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' ex2 nat w)(*strict*)\n   apply(case_tac \"edge_event ex2\")\n    apply(rename_tac G1 G2 c1 c1' ex2 nat w)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c1' ex2 nat w a)(*strict*)\n   apply(clarsimp)\n   apply(simp add: strict_executing_edge_def FB_executing_edge_def F_DPDA_RMPUE__edge_if_def F_DPDA_RMPUE__relation_TSstructure__RL_def read_edges_seperated_def)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 c1' ex2 nat w a)(*strict*)\n   apply(erule_tac\n      x=\"ex2\"\n      in ballE)\n    apply(rename_tac G2 c1 c1' ex2 nat w a)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G2 c1 c1' ex2 nat w a)(*strict*)\n   apply(clarsimp)\n   apply(simp add: valid_dpda_def valid_pda_def)\n  apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n  apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def prefix_def)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axiomsX: \"\n  ATS_Simulation_Configuration_Weak_axioms valid_epda epdaS_initial_configurations epda_step_labels epdaS_step_relation valid_epda epdaS_configurations epdaS_initial_configurations epda_step_labels epdaS_step_relation F_DPDA_RMPUE__relation_configuration__RL2 F_DPDA_RMPUE__relation_initial_configuration__RL2 F_DPDA_RMPUE__relation_TSstructure__RL F_DPDA_RMPUE__relation_initial_simulation__RL2 F_DPDA_RMPUE__relation_step_simulation__RL2\"\n  apply(simp add: ATS_Simulation_Configuration_Weak_axioms_def epdaS_epdaS_RMP_StateSimRL_inst_relation_initial_simulationX epdaS_epdaS_RMP_StateSimRL_step_relation_step_simulationX epdaS_epdaS_RMP_StateSimRL_inst_AX_TSstructure_relation_TSstructure1_belongs epdaS_epdaS_RMP_StateSimRL_inst_AX_TSstructure_relation_TSstructure2_belongs)\n  done\n\ninterpretation \"epdaS_epdaS_RMP_StateSimRLReach\" : ATS_Simulation_Configuration_WeakReach\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaS_configurations\"\n  (* initial_configurations1 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaS_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaS_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_DPDA_RMPUE__relation_configuration__RL2\"\n  (* relation_initial_configuration *)\n  \"F_DPDA_RMPUE__relation_initial_configuration__RL2\"\n  (* relation_effect *)\n  \"F_DPDA_RMPUE__relation_effect__RL\"\n  (* relation_TSstructure *)\n  \"F_DPDA_RMPUE__relation_TSstructure__RL\"\n  (* relation_initial_simulation *)\n  \"F_DPDA_RMPUE__relation_initial_simulation__RL2\"\n  (* relation_step_simulation *)\n  \"F_DPDA_RMPUE__relation_step_simulation__RL2\"\n  (* relation_labelsRL *)\n  \"F_DPDA_RMPUE__relation_labels__RL2\"\n  apply(simp add: LOCALE_DEFS epda_interpretations)\n  apply(simp add: epdaS_epdaS_RMP_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axiomsX epdaS_epdaS_RMP_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axiomsX epdaS_epdaS_RMP_StateSimRLReach_inst_ATS_Simulation_Configuration_WeakReach_axioms)\n  done\n\ndefinition F_DPDA_RMPUE__SpecInput :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RMPUE__SpecInput G \\<equiv>\n  valid_dpda G\n  \\<and> neutral_edges_removed G\n  \\<and> read_edges_seperated G\n  \\<and> push_and_pop_edges_seperated G\n  \\<and> pop_edges_seperated G\"\n\ndefinition F_DPDA_RMPUE__SpecOutput :: \"\n  ('stateA, 'event, 'stackA) epda\n  \\<Rightarrow> ('stateB, 'event, 'stackB) epda\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RMPUE__SpecOutput Gi Go \\<equiv>\n  valid_dpda Go\n  \\<and> epdaS.marked_language Gi = epdaS.marked_language Go\n  \\<and> neutral_edges_removed Go\n  \\<and> read_edges_seperated Go\n  \\<and> mass_push_edges_splitted Go\n  \\<and> push_and_pop_edges_seperated Go\n  \\<and> push_edges_seperated Go\n  \\<and> pop_edges_seperated Go\"\n\nlemma F_DPDA_RMPUE__SOUND: \"\n  F_DPDA_RMPUE__SpecInput G\n  \\<Longrightarrow> F_DPDA_RMPUE__SpecOutput G (F_DPDA_RMPUE G)\"\n  apply(simp add: F_DPDA_RMPUE__SpecInput_def F_DPDA_RMPUE__SpecOutput_def)\n  apply(rule context_conjI)\n   apply(rule F_DPDA_RMPUE__preserves_DPDA)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(rule conjI)\n   apply (rule F_DPDA_RMPUE__preserves_lang)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(rule context_conjI)\n   apply (metis F_DPDA_RMPUE__preserves_neutral_edges_removed)\n  apply(rule context_conjI)\n   apply (metis F_DPDA_RMPUE__preserves_read_edges_seperated)\n  apply(rule context_conjI)\n   apply (rule F_DPDA_RMPUE__produces_mass_push_edges_splitted)\n   apply(force)\n  apply(rule context_conjI)\n   apply (metis F_DPDA_RMPUE__preserves_push_and_pop_edges_seperated)\n  apply(rule context_conjI)\n   apply (rule F_DPDA_RMPUE__produces_push_edges_seperated)\n       apply(force)\n      apply(simp add: valid_dpda_def)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply (metis F_DPDA_RMPUE__preserves_pop_edges_seperated)\n  done\n\nlemma F_DPDA_DRE__revert_F_DPDA_RMPUE_SOUND_scheduled_case_rev_id: \"\n       F_DPDA_RMPUE__SpecInput G' \\<Longrightarrow>\n       x \\<in> epda_delta G' \\<Longrightarrow>\n       p \\<in> epda_delta (F_DPDA_RMPUE G') \\<Longrightarrow>\n       p \\<in> F_DPDA_RMPUE__edge_then x \\<or> p = F_DPDA_RMPUE__edge_else x \\<Longrightarrow>\n       epdaS.derivation_initial (F_DPDA_RMPUE G')\n        d \\<Longrightarrow>\n       d n = Some (pair (Some p) c) \\<Longrightarrow>\n       epdaS.derivation_initial G' d2 \\<Longrightarrow>\n       d2 n2 = Some (pair e2 c2) \\<Longrightarrow>\n              a \\<in> F_DPDA_DRE__revert_F_DPDA_RMPUE G' {p} \\<Longrightarrow> a = x\"\n  apply(simp add: F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>p1. edge_pop a=[p1]\")\n   prefer 2\n   apply(simp add: F_DPDA_RMPUE__SpecInput_def valid_dpda_def valid_pda_def valid_epda_def)\n   apply(clarsimp)\n   apply(erule_tac x=\"a\" and P=\"\\<lambda>a. valid_epda_step_label G' a\"in ballE)\n    prefer 2\n    apply(force)\n   apply(erule_tac\n      x=\"a\"\n      in ballE)\n    prefer 2\n    apply(force)\n   apply(case_tac \"edge_pop a\")\n    apply(clarsimp)\n   apply(clarsimp)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>p1. edge_pop x=[p1]\")\n   prefer 2\n   apply(simp add: F_DPDA_RMPUE__SpecInput_def valid_dpda_def valid_pda_def valid_epda_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"x\"\n      and P=\"\\<lambda>x. valid_epda_step_label G' x\"\n      in ballE)\n    prefer 2\n    apply(force)\n   apply(erule_tac\n      x=\"x\"\n      in ballE)\n    prefer 2\n    apply(force)\n   apply(case_tac \"edge_pop x\")\n    apply(clarsimp)\n   apply(clarsimp)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>w. edge_push a \\<noteq> [] \\<longrightarrow> edge_push a=w@(edge_pop a)\")\n   prefer 2\n   apply(clarsimp)\n   apply(simp add: FB_executing_edge_def strict_executing_edge_def read_edges_seperated_def F_DPDA_RMPUE__SpecInput_def valid_dpda_def valid_pda_def valid_epda_def push_and_pop_edges_seperated_def F_DPDA_SPPE__edge_if_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"a\"\n      and P=\"\\<lambda>a. valid_epda_step_label G' a\"\n      in ballE)\n    prefer 2\n    apply(force)\n   apply(erule_tac\n      x=\"a\"\n      and P=\"\\<lambda>a. length (edge_pop a) = Suc 0\"\n      in ballE)\n    prefer 2\n    apply(force)\n   apply(erule_tac\n      x=\"a\"\n      and P=\"\\<lambda>a. (\\<exists>y. edge_event a = Some y) \\<longrightarrow> edge_push a = edge_pop a\"\n      in ballE)\n    prefer 2\n    apply(force)\n   apply(erule_tac\n      x=\"a\"\n      in ballE)\n    prefer 2\n    apply(force)\n   apply(clarsimp)\n   apply(case_tac \"edge_push a\")\n    apply(clarsimp)\n   apply(subgoal_tac \"\\<exists>w' x'. edge_push a = w' @ [x']\")\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(thin_tac \"edge_push a = aa # list\")\n   apply(clarsimp)\n   apply(erule_tac\n      P=\"p \\<in> F_DPDA_RMPUE__edge_then x\"\n      in disjE)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"\\<exists>w. edge_push x \\<noteq> [] \\<longrightarrow> edge_push x=w@(edge_pop x)\")\n   prefer 2\n   apply(clarsimp)\n   apply(simp add: FB_executing_edge_def strict_executing_edge_def read_edges_seperated_def F_DPDA_RMPUE__SpecInput_def valid_dpda_def valid_pda_def valid_epda_def push_and_pop_edges_seperated_def F_DPDA_SPPE__edge_if_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"x\"\n      and P=\"\\<lambda>x. valid_epda_step_label G' x\"\n      in ballE)\n    prefer 2\n    apply(force)\n   apply(erule_tac\n      x=\"x\"\n      and P=\"\\<lambda>x. length (edge_pop x) = Suc 0\"\n      in ballE)\n    prefer 2\n    apply(force)\n   apply(erule_tac\n      x=\"x\"\n      and P=\"\\<lambda>x. (\\<exists>y. edge_event x = Some y) \\<longrightarrow> edge_push x = edge_pop x\"\n      in ballE)\n    prefer 2\n    apply(force)\n   apply(erule_tac\n      x=\"x\"\n      in ballE)\n    prefer 2\n    apply(force)\n   apply(clarsimp)\n   apply(case_tac \"edge_push x\")\n    apply(clarsimp)\n   apply(subgoal_tac \"\\<exists>w' x'. edge_push x = w' @ [x']\")\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(thin_tac \"edge_push x = aa # list\")\n   apply(clarsimp)\n   apply(erule_tac\n      P=\"p \\<in> F_DPDA_RMPUE__edge_then x\"\n      in disjE)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(erule_tac\n      P=\"p \\<in> F_DPDA_RMPUE__edge_then x\"\n      in disjE)\n   apply(erule disjE)\n    apply(simp add: F_DPDA_RMPUE__edge_then_def F_DPDA_RMPUE__state_def F_DPDA_RMPUE__edge_else_def)\n    apply(clarsimp)\n    apply(rename_tac p1 p1a i ia)\n    apply(case_tac i)\n     apply(case_tac ia)\n      prefer 2\n      apply(clarsimp)\n     apply(clarsimp)\n     apply(case_tac \"Suc (Suc 0) < length (edge_push x)\")\n      apply(case_tac \"Suc (Suc 0) < length (edge_push a)\")\n       prefer 2\n       apply(clarsimp)\n      apply(clarsimp)\n     apply(clarsimp)\n     apply(case_tac \"Suc (Suc 0) < length (edge_push a)\")\n      apply(clarsimp)\n     apply(clarsimp)\n     apply(subgoal_tac \"Suc (Suc 0) = length (edge_push x)\")\n      prefer 2\n      apply(force)\n     apply(subgoal_tac \"Suc (Suc 0) = length (edge_push a)\")\n      prefer 2\n      apply(force)\n     apply(clarsimp)\n     apply(subgoal_tac \"edge_event a=None\")\n      apply(subgoal_tac \"edge_event x=None\")\n       apply(case_tac a)\n       apply(case_tac x)\n       apply(clarsimp)\n       apply(erule_tac\n      P=\"edge_push \\<noteq> []\"\n      in impE)\n        apply(force)\n       apply(erule impE)\n        apply(force)\n       apply(clarsimp)\n       apply(case_tac w)\n        apply(clarsimp)\n       apply(case_tac list)\n        prefer 2\n        apply(clarsimp)\n       apply(clarsimp)\n       apply(case_tac wa)\n        apply(clarsimp)\n       apply(case_tac list)\n        prefer 2\n        apply(clarsimp)\n       apply(clarsimp)\n      apply(simp add: F_DPDA_RMPUE__SpecInput_def)\n      apply(simp add: FB_executing_edge_def strict_executing_edge_def read_edges_seperated_def F_DPDA_RMPUE__SpecInput_def valid_dpda_def valid_pda_def valid_epda_def push_and_pop_edges_seperated_def F_DPDA_SPPE__edge_if_def)\n      apply(clarsimp)\n      apply(erule_tac\n      x=\"x\"\n      and P=\"\\<lambda>x. valid_epda_step_label G' x\"\n      in ballE)\n       prefer 2\n       apply(force)\n      apply(erule_tac\n      x=\"x\"\n      and P=\"\\<lambda>x. length (edge_pop x) = Suc 0\"\n      in ballE)\n       prefer 2\n       apply(force)\n      apply(erule_tac\n      x=\"x\"\n      and P=\"\\<lambda>x. (\\<exists>y. edge_event x = Some y) \\<longrightarrow> edge_push x = edge_pop x\"\n      in ballE)\n       prefer 2\n       apply(force)\n      apply(erule_tac\n      x=\"x\"\n      in ballE)\n       prefer 2\n       apply(force)\n      apply(clarsimp)\n      apply(case_tac \"edge_event x\")\n       apply(clarsimp)\n      apply(clarsimp)\n     apply(simp add: F_DPDA_RMPUE__SpecInput_def)\n     apply(simp add: FB_executing_edge_def strict_executing_edge_def read_edges_seperated_def F_DPDA_RMPUE__SpecInput_def valid_dpda_def valid_pda_def valid_epda_def push_and_pop_edges_seperated_def F_DPDA_SPPE__edge_if_def)\n     apply(clarsimp)\n     apply(erule_tac\n      x=\"a\"\n      and P=\"\\<lambda>a. valid_epda_step_label G' a\"\n      in ballE)\n      prefer 2\n      apply(force)\n     apply(erule_tac\n      x=\"a\"\n      and P=\"\\<lambda>a. length (edge_pop a) = Suc 0\"\n      in ballE)\n      prefer 2\n      apply(force)\n     apply(erule_tac\n      x=\"a\"\n      and P=\"\\<lambda>a. (\\<exists>y. edge_event a = Some y) \\<longrightarrow> edge_push a = edge_pop a\"\n      in ballE)\n      prefer 2\n      apply(force)\n     apply(erule_tac\n      x=\"a\"\n      in ballE)\n      prefer 2\n      apply(force)\n     apply(clarsimp)\n     apply(case_tac \"edge_event a\")\n      apply(clarsimp)\n     apply(clarsimp)\n    apply(clarsimp)\n    apply(case_tac ia)\n     apply(clarsimp)\n    apply(clarsimp)\n   apply(simp add: F_DPDA_RMPUE__edge_then_def F_DPDA_RMPUE__state_def F_DPDA_RMPUE__edge_else_def)\n   apply(clarsimp)\n   apply(rename_tac p1a i)\n   apply(case_tac i)\n    apply(clarsimp)\n    apply(case_tac \"Suc (Suc 0) < length (edge_push x)\")\n     apply(clarsimp)\n    apply(clarsimp)\n    apply(subgoal_tac \"Suc (Suc 0) = length (edge_push x)\")\n     prefer 2\n     apply(force)\n    apply(clarsimp)\n    apply(subgoal_tac \"edge_event x=None\")\n     apply(case_tac a)\n     apply(case_tac x)\n     apply(clarsimp)\n     apply(case_tac \"edge_pusha\")\n      apply(clarsimp)\n     apply(subgoal_tac \"\\<exists>w' x'. edge_pusha = w' @ [x']\")\n      prefer 2\n      apply(rule_tac\n      n=\"length list\"\n      in NonEmptyListHasTailElem)\n      apply(force)\n     apply(thin_tac \"edge_pusha = a # list\")\n     apply(clarsimp)\n     apply(case_tac \"w'\")\n      apply(clarsimp)\n     apply(clarsimp)\n    apply(simp add: F_DPDA_RMPUE__SpecInput_def)\n    apply(simp add: FB_executing_edge_def strict_executing_edge_def read_edges_seperated_def F_DPDA_RMPUE__SpecInput_def valid_dpda_def valid_pda_def valid_epda_def push_and_pop_edges_seperated_def F_DPDA_SPPE__edge_if_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"x\"\n      and P=\"\\<lambda>x. valid_epda_step_label G' x\"\n      in ballE)\n     prefer 2\n     apply(force)\n    apply(erule_tac\n      x=\"x\"\n      and P=\"\\<lambda>x. length (edge_pop x) = Suc 0\"\n      in ballE)\n     prefer 2\n     apply(force)\n    apply(erule_tac\n      x=\"x\"\n      and P=\"\\<lambda>x. (\\<exists>y. edge_event x = Some y) \\<longrightarrow> edge_push x = edge_pop x\"\n      in ballE)\n     prefer 2\n     apply(force)\n    apply(erule_tac\n      x=\"x\"\n      in ballE)\n     prefer 2\n     apply(force)\n    apply(clarsimp)\n    apply(case_tac \"edge_event x\")\n     apply(clarsimp)\n    apply(clarsimp)\n   apply(clarsimp)\n  apply(clarsimp)\n  apply(erule_tac\n      P=\"F_DPDA_RMPUE__edge_else x \\<in> F_DPDA_RMPUE__edge_then a\"\n      in disjE)\n   apply(simp add: F_DPDA_RMPUE__edge_then_def F_DPDA_RMPUE__state_def F_DPDA_RMPUE__edge_else_def)\n   apply(clarsimp)\n   apply(rename_tac p1a i)\n   apply(case_tac i)\n    apply(clarsimp)\n    apply(case_tac \"Suc (Suc 0) < length (edge_push a)\")\n     apply(clarsimp)\n    apply(clarsimp)\n    apply(subgoal_tac \"Suc (Suc 0) = length (edge_push a)\")\n     prefer 2\n     apply(force)\n    apply(clarsimp)\n    apply(subgoal_tac \"edge_event a=None\")\n     apply(case_tac a)\n     apply(case_tac x)\n     apply(clarsimp)\n     apply(case_tac \"edge_push\")\n      apply(clarsimp)\n     apply(subgoal_tac \"\\<exists>w' x'. edge_push = w' @ [x']\")\n      prefer 2\n      apply(rule_tac\n      n=\"length list\"\n      in NonEmptyListHasTailElem)\n      apply(force)\n     apply(thin_tac \"edge_push = a # list\")\n     apply(clarsimp)\n     apply(case_tac \"w'\")\n      apply(clarsimp)\n     apply(clarsimp)\n    apply(simp add: F_DPDA_RMPUE__SpecInput_def)\n    apply(simp add: FB_executing_edge_def strict_executing_edge_def read_edges_seperated_def F_DPDA_RMPUE__SpecInput_def valid_dpda_def valid_pda_def valid_epda_def push_and_pop_edges_seperated_def F_DPDA_SPPE__edge_if_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"a\"\n      and P=\"\\<lambda>a. valid_epda_step_label G' a\"\n      in ballE)\n     prefer 2\n     apply(force)\n    apply(erule_tac\n      x=\"a\"\n      and P=\"\\<lambda>a. length (edge_pop a) = Suc 0\"\n      in ballE)\n     prefer 2\n     apply(force)\n    apply(erule_tac\n      x=\"a\"\n      and P=\"\\<lambda>a. (\\<exists>y. edge_event a = Some y) \\<longrightarrow> edge_push a = edge_pop a\"\n      in ballE)\n     prefer 2\n     apply(force)\n    apply(erule_tac\n      x=\"a\"\n      in ballE)\n     prefer 2\n     apply(force)\n    apply(clarsimp)\n    apply(case_tac \"edge_event a\")\n     apply(clarsimp)\n    apply(clarsimp)\n   apply(clarsimp)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RMPUE__edge_else_def)\n  done\n\nlemma F_DPDA_DRE__revert_F_DPDA_RMPUE_SOUND_scheduled_case: \"\n  F_DPDA_RMPUE__SpecInput G'\n  \\<Longrightarrow> F_DPDA_DRE__revert_F_DPDA_RMPUE G' (epdaS_accessible_edges (F_DPDA_RMPUE G')) = epdaS_accessible_edges G'\"\n  apply(rule order_antisym)\n   apply(simp add: epdaS_accessible_edges_def)\n   apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_accessible_edges_def)\n   apply(simp add: F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n   apply(clarsimp)\n   apply(rename_tac x d n c)(*strict*)\n   apply(subgoal_tac \"\\<exists>d2 n2 e2 c2. epdaS.derivation_initial SSG2 d2 \\<and> d2 n2 = Some (pair e2 c2) \\<and> (case SSe1 of None \\<Rightarrow> True | Some e1' \\<Rightarrow> \\<exists>k d2'. epdaS.derivation SSG2 d2' \\<and> the (get_configuration (d2' 0)) = the (get_configuration (d2 n2)) \\<and> (case get_label (derivation_append d2 d2' n2 k) of None \\<Rightarrow> False | Some e2' \\<Rightarrow> F_DPDA_RMPUE__relation_labels__LR2 SSG1 SSG2 e1' e2'))\" for SSe1 SSG1 SSG2)\n    apply(rename_tac x d n c)(*strict*)\n    prefer 2\n    apply(rule_tac\n      ?G1.0=\"G'\"\n      and ?d1.0=\"d\"\n      and ?G2.0=\"F_DPDA_RMPUE G'\"\n      in epdaS_epdaS_RMP_StateSimLRReach.ATS_Simulation_Configuration_WeakReach_exists)\n      apply(rename_tac x d n c)(*strict*)\n      apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n      apply(simp add: F_DPDA_RMPUE__SpecInput_def)\n     apply(rename_tac x d n c)(*strict*)\n     apply(force)\n    apply(rename_tac x d n c)(*strict*)\n    apply(force)\n   apply(rename_tac x d n c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x d n c d2 n2 e2 k c2 d2')(*strict*)\n   apply(case_tac \"(get_label (derivation_append d2 d2' n2 k))\")\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2')(*strict*)\n    apply(force)\n   apply(rename_tac x d n c d2 n2 e2 k c2 d2' a)(*strict*)\n   apply(clarsimp)\n   apply(simp add: get_label_def)\n   apply(rule_tac\n      x=\"a\"\n      in exI)\n   apply(simp add: F_DPDA_RMPUE__relation_labels__LR2_def F_DPDA_DRE__revert_F_DPDA_RNE_def)\n   apply(case_tac \"derivation_append d2 d2' n2 k\")\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2' a)(*strict*)\n    apply(force)\n   apply(rename_tac x d n c d2 n2 e2 k c2 d2' a aa)(*strict*)\n   apply(clarsimp)\n   apply(case_tac aa)\n   apply(rename_tac x d n c d2 n2 e2 k c2 d2' a aa option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   apply(subgoal_tac \"\\<exists>c. d2' 0 = Some (pair None c)\")\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    prefer 2\n    apply (metis epdaS.some_position_has_details_at_0)\n   apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   apply(subgoal_tac \"epdaS.derivation_initial (F_DPDA_RMPUE G') (derivation_append d2 d2' n2)\")\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    prefer 2\n    apply(rule epdaS.derivation_append_preserves_derivation_initial)\n      apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n      apply(rule F_DPDA_RMPUE__preserves_epda)\n      apply(simp add: F_DPDA_RMPUE__SpecInput_def valid_dpda_def valid_pda_def)\n     apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n     apply(force)\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    apply(rule epdaS.derivation_append_preserves_derivation)\n      apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n      apply(rule epdaS.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n     apply(force)\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b ca)(*strict*)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   apply(rule context_conjI)\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    apply(rule_tac\n      t=\"epda_delta (F_DPDA_RMPUE G')\"\n      and s=\"epda_step_labels (F_DPDA_RMPUE G')\"\n      in ssubst)\n     apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n     apply(simp add: epda_step_labels_def)\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    apply(rule_tac\n      i=\"k\"\n      and d=\"derivation_append d2 d2' n2\"\n      in epdaS.belongs_step_labels)\n     apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n     apply(rule epdaS.derivation_initial_belongs)\n      apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n      apply(rule F_DPDA_RMPUE__preserves_epda)\n      apply(simp add: F_DPDA_RMPUE__SpecInput_def valid_dpda_def valid_pda_def)\n     apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n     apply(force)\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    apply(force)\n   apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    apply(force)\n   apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   apply(simp add: F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n  apply(clarsimp)\n  apply(rename_tac x p d n c)(*strict*)\n  apply(subgoal_tac \"\\<exists>d2 n2 e2 c2. epdaS.derivation_initial SSG2 d2 \\<and> d2 n2 = Some (pair e2 c2) \\<and> (case SSe1 of None \\<Rightarrow> True | Some e1' \\<Rightarrow> \\<exists>k d2'. epdaS.derivation SSG2 d2' \\<and> the (get_configuration (d2' 0)) = the (get_configuration (d2 n2)) \\<and> (case get_label (derivation_append d2 d2' n2 k) of None \\<Rightarrow> False | Some e2' \\<Rightarrow> F_DPDA_RMPUE__relation_labels__RL2 SSG1 SSG2 e1' e2'))\" for SSe1 SSG1 SSG2)\n   apply(rename_tac x p d n c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      ?G2.0=\"G'\"\n      and ?d1.0=\"d\"\n      and ?G1.0=\"F_DPDA_RMPUE G'\"\n      in epdaS_epdaS_RMP_StateSimRLReach.ATS_Simulation_Configuration_WeakReach_exists)\n     apply(rename_tac x p d n c)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n     apply(simp add: F_DPDA_RMPUE__SpecInput_def)\n    apply(rename_tac x p d n c)(*strict*)\n    apply(force)\n   apply(rename_tac x p d n c)(*strict*)\n   apply(force)\n  apply(rename_tac x p d n c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2')(*strict*)\n  apply(case_tac \"(get_label (derivation_append d2 d2' n2 k))\")\n   apply(rename_tac x p d n c d2 n2 e2 k c2 d2')(*strict*)\n   apply(force)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a)(*strict*)\n  apply(clarsimp)\n  apply(simp add: get_label_def)\n  apply(case_tac \"derivation_append d2 d2' n2 k\")\n   apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a)(*strict*)\n   apply(force)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a aa)(*strict*)\n  apply(clarsimp)\n  apply(case_tac aa)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a aa option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. d2' 0 = Some (pair None c)\")\n   apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   prefer 2\n   apply (metis epdaS.some_position_has_details_at_0)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b ca)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n  apply(subgoal_tac \"epdaS.derivation_initial G' (derivation_append d2 d2' n2)\")\n   apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   prefer 2\n   apply(rule epdaS.derivation_append_preserves_derivation_initial)\n     apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__SpecInput_def valid_dpda_def valid_pda_def)\n    apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    apply(force)\n   apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   apply(rule epdaS.derivation_append_preserves_derivation)\n     apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n     apply(rule epdaS.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    apply(force)\n   apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n  apply(rule_tac\n      x=\"derivation_append d2 d2' n2\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   apply(force)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n  apply(rule_tac\n      x=\"k\"\n      in exI)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RMPUE__relation_labels__RL2_def)\n  apply(clarsimp)\n  apply(rule F_DPDA_DRE__revert_F_DPDA_RMPUE_SOUND_scheduled_case_rev_id)\n          apply(force)\n         apply(force)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(force)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimRLRequired__inst__AX_relation_configuration_compatible_with_marking_configurations: \"\n(\\<forall>G1 G2.\n        F_DPDA_RMPUE__relation_TSstructure__RL G1 G2 \\<longrightarrow>\n        (\\<forall>c1 c2.\n            F_DPDA_RMPUE__relation_configuration__RL2 G1 G2 c1 c2 \\<longrightarrow>\n            c1 \\<in> epdaS_marking_configurations G1 \\<longrightarrow> c2 \\<in> epdaS_marking_configurations G2))\"\n  apply(clarsimp)\n  apply(simp add: epdaS_marking_configurations_def)\n  apply(subgoal_tac \"c2 \\<in> epdaS_configurations G2\")\n   prefer 2\n   apply (metis (full_types) F_DPDA_RMPUE__conf_old__LR_revX_preserves_configurations F_DPDA_RMPUE__relation_configuration__RL2_def)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL2_def F_DPDA_RMPUE_def F_DPDA_RMPUE__conf_old__LR_revX_def)\n  apply(case_tac c1)\n  apply(clarsimp)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimRLRequired__inst__AX_relation_step_simulation_no_reach_marking_with_empty_simulant: \"\n  (\\<forall>G1 G2.\n        F_DPDA_RMPUE__relation_TSstructure__RL G1 G2 \\<longrightarrow>\n        (\\<forall>c1 c2.\n            F_DPDA_RMPUE__relation_configuration__RL2 G1 G2 c1 c2 \\<longrightarrow>\n            (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow>\n                  (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow>\n                         (\\<forall>d2. F_DPDA_RMPUE__relation_step_simulation__RL2 G1 G2 c1 e1 c1' c2\n                                d2 \\<longrightarrow>\n                               maximum_of_domain d2 0 \\<longrightarrow>\n                               c1' \\<notin> epdaS_marking_configurations G1)))))\"\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RMPUE__relation_step_simulation__RL2_def)\n  apply(case_tac \"edge_trg e1\")\n   apply(clarsimp)\n   apply(case_tac \"edge_src e1\")\n    apply(clarsimp)\n    apply(simp add: maximum_of_domain_def der2_def)\n   apply(clarsimp)\n   apply(simp add: maximum_of_domain_def der2_def)\n  apply(clarsimp)\n  apply(simp add: maximum_of_domain_def der2_def)\n  apply(clarsimp)\n  apply(case_tac \"edge_src e1\")\n   apply(clarsimp)\n   apply(simp add: maximum_of_domain_def der2_def der1_def)\n   apply(clarsimp)\n   apply(simp add: epdaS_step_relation_def epdaS_marking_configurations_def F_DPDA_RMPUE__relation_configuration__RL2_def F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE_def)\n   apply(clarsimp)\n  apply(clarsimp)\n  apply(simp add: maximum_of_domain_def der2_def der1_def)\n  apply(simp add: epdaS_step_relation_def epdaS_marking_configurations_def F_DPDA_RMPUE__relation_configuration__RL2_def F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE_def)\n  apply(clarsimp)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimRLRequired__inst__AX_relation_step_simulationReach: \"\n  \\<forall>G1 G2.\n       F_DPDA_RMPUE__relation_TSstructure__RL G1 G2 \\<longrightarrow>\n       (\\<forall>c1 c2.\n           F_DPDA_RMPUE__relation_configuration__RL2 G1 G2 c1 c2 \\<longrightarrow>\n           (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow>\n                 (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow>\n                        (\\<forall>d2. epdaS.derivation G2 d2 \\<longrightarrow>\n                              epdaS.belongs G2 d2 \\<longrightarrow>\n                              the (get_configuration (d2 0)) = c2 \\<longrightarrow>\n                              F_DPDA_RMPUE__relation_step_simulation__RL2 G1 G2 c1 e1 c1' c2\n                               d2 \\<longrightarrow>\n                              (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow>\n                                   F_DPDA_RMPUE__relation_configuration__RL2 G1 G2 c1'\n                                    (the (get_configuration (d2 n))) \\<longrightarrow>\n                                   (\\<exists>k e2. (\\<exists>c2. d2 k = Some (pair (Some e2) c2)) \\<and>\n                                           F_DPDA_RMPUE__relation_labels__RL2 G1 G2 e1 e2) \\<or>\n                                   n = 0 \\<and>\n                                   (\\<exists>e2. Ex (epdaS_step_relation G2 c2 e2) \\<and>\n                                         F_DPDA_RMPUE__relation_labels__RL2 G1 G2 e1 e2))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_step_simulation__RL2_def)\n  apply(case_tac \"edge_trg e1\")\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n q)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"edge_src e1\")\n    apply(rename_tac G1 G2 c1 e1 c1' d2 n q qa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 e1 c1' n q qa)(*strict*)\n    apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n    apply(rule_tac\n      x=\"(F_DPDA_RMPUE__edge_else__RL e1)\"\n      in exI)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 e1 c1' n q qa)(*strict*)\n     apply(simp add: der2_def)\n    apply(rename_tac G1 G2 c1 e1 c1' n q qa)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__relation_labels__RL2_def F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 e1 c1' n q qa)(*strict*)\n     prefer 2\n     apply(rule disjI2)\n     apply(simp add: F_DPDA_RMPUE__edge_else_def F_DPDA_RMPUE__edge_else__RL_def)\n    apply(rename_tac G1 G2 c1 e1 c1' n q qa)(*strict*)\n    apply(rule_tac\n      t=\"epda_delta G2\"\n      and s=\"epda_step_labels G2\"\n      in ssubst)\n     apply(rename_tac G1 G2 c1 e1 c1' n q qa)(*strict*)\n     apply(simp add: epda_step_labels_def)\n    apply(rename_tac G1 G2 c1 e1 c1' n q qa)(*strict*)\n    apply(rule_tac\n      i=\"Suc 0\"\n      and d=\"(der2 (F_DPDA_RMPUE__conf_old__LR_revX c1) (F_DPDA_RMPUE__edge_else__RL e1) (F_DPDA_RMPUE__conf_old__LR_revX c1'))\"\n      in epdaS.belongs_step_labels)\n     apply(rename_tac G1 G2 c1 e1 c1' n q qa)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 e1 c1' n q qa)(*strict*)\n    apply(simp add: der2_def)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n q epda_step_label_ext nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' n q epda_step_label_ext nat)(*strict*)\n   apply(rename_tac ex nx)\n   apply(rename_tac G1 G2 c1 e1 c1' n q ex nx)(*strict*)\n   apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n   apply(rule_tac\n      x=\"ex\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 e1 c1' n q ex nx)(*strict*)\n    apply(simp add: der2_def)\n   apply(rename_tac G1 G2 c1 e1 c1' n q ex nx)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_labels__RL2_def F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n   apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G2 \\<inter> {e. F_DPDA_RMPUE__edge_if e}. e1 \\<in> F_DPDA_RMPUE__edge_then x) \\<or> (\\<exists>x\\<in> epda_delta G2 \\<inter> {e. (\\<not> F_DPDA_RMPUE__edge_if e)}. e1 = F_DPDA_RMPUE__edge_else x)\")\n    apply(rename_tac G1 G2 c1 e1 c1' n q ex nx)(*strict*)\n    prefer 2\n    apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def)\n    apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL2_def)\n    apply(simp add: F_DPDA_RMPUE_def)\n    apply(blast)\n   apply(rename_tac G1 G2 c1 e1 c1' n q ex nx)(*strict*)\n   apply(erule_tac\n      P=\"\\<exists>x\\<in> epda_delta G2 \\<inter> {e. F_DPDA_RMPUE__edge_if e}. e1 \\<in> F_DPDA_RMPUE__edge_then x\"\n      in disjE)\n    apply(rename_tac G1 G2 c1 e1 c1' n q ex nx)(*strict*)\n    prefer 2\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c1' n q ex nx x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_else_def)\n   apply(rename_tac G1 G2 c1 e1 c1' n q ex nx)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' n q ex nx x)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_then_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' n q ex nx x xa)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__state_def)\n   apply(case_tac \"Suc (Suc xa) < length (edge_push x)\")\n    apply(rename_tac G1 G2 c1 c1' n q ex nx x xa)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' n q ex nx x xa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' n ex nx x xa)(*strict*)\n   apply(subgoal_tac \"Suc (Suc xa) = length (edge_push x)\")\n    apply(rename_tac G1 G2 c1 c1' n ex nx x xa)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G1 G2 c1 c1' n ex nx x xa)(*strict*)\n   apply(clarsimp)\n   apply(case_tac xa)\n    apply(rename_tac G1 G2 c1 c1' n ex nx x xa)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' n ex nx x xa nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' n ex nat)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_else_def)\n   apply(rule_tac\n      x=\"Suc nat\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n epda_step_label_ext nat)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"edge_src e1\")\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n epda_step_label_ext nat q)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' n epda_step_label_ext nat q)(*strict*)\n   apply(subgoal_tac \"False\")\n    apply(rename_tac G1 G2 c1 e1 c1' n epda_step_label_ext nat q)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 e1 c1' n epda_step_label_ext nat q)(*strict*)\n   apply(subgoal_tac \"n=0\")\n    apply(rename_tac G1 G2 c1 e1 c1' n epda_step_label_ext nat q)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext nat q)(*strict*)\n    apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G2 \\<inter> {e. F_DPDA_RMPUE__edge_if e}. e1 \\<in> F_DPDA_RMPUE__edge_then x) \\<or> (\\<exists>x\\<in> epda_delta G2 \\<inter> {e. (\\<not> F_DPDA_RMPUE__edge_if e)}. e1 = F_DPDA_RMPUE__edge_else x)\")\n     apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext nat q)(*strict*)\n     prefer 2\n     apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def)\n     apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL2_def)\n     apply(simp add: F_DPDA_RMPUE_def)\n     apply(blast)\n    apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext nat q)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext nat q)(*strict*)\n     prefer 2\n     apply(clarsimp)\n     apply(rename_tac G1 G2 c1 c1' epda_step_label_ext nat q x)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__edge_else_def)\n    apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext nat q)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext nat q x)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__edge_then_def)\n    apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_exta nat q x)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c1' epda_step_label_exta nat q x xa)(*strict*)\n    apply(simp add: F_DPDA_RMPUE__state_def)\n    apply(case_tac \"Suc (Suc xa) < length (edge_push x)\")\n     apply(rename_tac G1 G2 c1 c1' epda_step_label_exta nat q x xa)(*strict*)\n     prefer 2\n     apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c1' epda_step_label_exta nat q x xa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c1' epda_step_label_exta q xa)(*strict*)\n    apply(rename_tac ex qx xa)\n    apply(rename_tac G1 G2 c1 c1' ex qx xa)(*strict*)\n    apply(case_tac xa)\n     apply(rename_tac G1 G2 c1 c1' ex qx xa)(*strict*)\n     prefer 2\n     apply(rename_tac G1 G2 c1 c1' ex qx xa nat)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c1' ex qx xa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n    apply(subgoal_tac \"\\<exists>c. epdaS_step_relation G2 (F_DPDA_RMPUE__conf_old__LR_revX c1) ex c\")\n     apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n     apply(clarsimp)\n     apply(simp add: der1_def get_configuration_def)\n     apply(erule_tac x=\"ex\" in allE)\n     apply(erule disjE)\n      apply(clarsimp)\n     apply(rename_tac G1 G2 c1 c1' ex c)(*strict*)\n     apply(simp add: F_DPDA_RMPUE__relation_labels__RL2_def)\n     apply(simp add: F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n     apply(erule conjE)\n     apply(simp add: F_DPDA_RMPUE__edge_then_def)\n     apply(erule_tac\n      x=\"0\"\n      in allE)\n     apply(clarsimp)\n     apply(simp add: F_DPDA_RMPUE__state_def)\n    apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n    apply(rule epdaS_step_exists)\n         apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n         apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n         apply(clarsimp)\n         apply(rename_tac G2 c1 c1' ex)(*strict*)\n         apply(simp add: valid_dpda_def valid_pda_def)\n        apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n        apply(rule_tac\n      i=\"0\"\n      and d=\"der1 (F_DPDA_RMPUE__conf_old__LR_revX c1)\"\n      in epdaS.belongs_configurations)\n         apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n         apply(force)\n        apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n        apply(simp add: der1_def)\n       apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n      apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def)\n     apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n     apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def prefix_def)\n     apply(rule_tac\n      x=\"epdaS_conf_scheduler c1'\"\n      in exI)\n     apply(clarsimp)\n     apply(rename_tac G1 G2 c1 c1' ex w)(*strict*)\n     apply(case_tac \"edge_event ex\")\n      apply(rename_tac G1 G2 c1 c1' ex w)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c1' ex w a)(*strict*)\n     apply(clarsimp)\n     apply(simp add: strict_executing_edge_def FB_executing_edge_def F_DPDA_RMPUE__edge_if_def F_DPDA_RMPUE__relation_TSstructure__RL_def read_edges_seperated_def)\n     apply(clarsimp)\n     apply(rename_tac G2 c1 c1' ex w a)(*strict*)\n     apply(erule_tac\n      x=\"ex\"\n      in ballE)\n      apply(rename_tac G2 c1 c1' ex w a)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac G2 c1 c1' ex w a)(*strict*)\n     apply(clarsimp)\n     apply(simp add: valid_dpda_def valid_pda_def)\n    apply(rename_tac G1 G2 c1 c1' ex)(*strict*)\n    apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def prefix_def)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c1' ex w)(*strict*)\n    apply(simp add: strict_executing_edge_def push_and_pop_edges_seperated_def FB_executing_edge_def F_DPDA_RMPUE__edge_if_def F_DPDA_RMPUE__relation_TSstructure__RL_def read_edges_seperated_def)\n    apply(simp add: valid_dpda_def valid_pda_def)\n    apply(clarsimp)\n    apply(rename_tac G2 c1 c1' ex w)(*strict*)\n    apply(erule_tac\n      x=\"ex\"\n      and P=\"\\<lambda>ex. length (edge_pop ex) = Suc 0\"\n      in ballE)\n     apply(rename_tac G2 c1 c1' ex w)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G2 c1 c1' ex w)(*strict*)\n    apply(erule_tac\n      x=\"ex\"\n      and P=\"\\<lambda>ex. \\<not> F_DPDA_SPPE__edge_if ex\"\n      in ballE)\n     apply(rename_tac G2 c1 c1' ex w)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G2 c1 c1' ex w)(*strict*)\n    apply(erule_tac\n      x=\"ex\"\n      in ballE)\n     apply(rename_tac G2 c1 c1' ex w)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G2 c1 c1' ex w)(*strict*)\n    apply(case_tac \"edge_event ex\")\n     apply(rename_tac G2 c1 c1' ex w)(*strict*)\n     prefer 2\n     apply(rename_tac G2 c1 c1' ex w a)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G2 c1 c1' ex w)(*strict*)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_SPPE__edge_if_def)\n    apply(case_tac \"edge_pop ex\")\n     apply(rename_tac G2 c1 c1' ex w)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G2 c1 c1' ex w a list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G2 c1 c1' ex w a)(*strict*)\n    apply(case_tac \"edge_push ex\")\n     apply(rename_tac G2 c1 c1' ex w a)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G2 c1 c1' ex w a aa list)(*strict*)\n    apply(subgoal_tac \"\\<exists>w' x'. edge_push ex = w' @ [x']\")\n     apply(rename_tac G2 c1 c1' ex w a aa list)(*strict*)\n     prefer 2\n     apply(rule NonEmptyListHasTailElem)\n     apply(force)\n    apply(rename_tac G2 c1 c1' ex w a aa list)(*strict*)\n    apply(thin_tac \"edge_push ex = aa # list\")\n    apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' n epda_step_label_ext nat q)(*strict*)\n   apply(rule epdaS.maximum_of_domainUnique)\n     apply(rename_tac G1 G2 c1 e1 c1' n epda_step_label_ext nat q)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 e1 c1' n epda_step_label_ext nat q)(*strict*)\n    apply(rule der1_maximum_of_domain)\n   apply(rename_tac G1 G2 c1 e1 c1' n epda_step_label_ext nat q)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1' n epda_step_label_ext nat epda_step_label_exta nata)(*strict*)\n  apply(rename_tac ex1 n1 ex2 n2)\n  apply(rename_tac G1 G2 c1 e1 c1' n ex1 n1 ex2 n2)(*strict*)\n  apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G2 \\<inter> {e. F_DPDA_RMPUE__edge_if e}. e1 \\<in> F_DPDA_RMPUE__edge_then x) \\<or> (\\<exists>x\\<in> epda_delta G2 \\<inter> {e. (\\<not> F_DPDA_RMPUE__edge_if e)}. e1 = F_DPDA_RMPUE__edge_else x)\")\n   apply(rename_tac G1 G2 c1 e1 c1' n ex1 n1 ex2 n2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def)\n   apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL2_def)\n   apply(simp add: F_DPDA_RMPUE_def)\n   apply(blast)\n  apply(rename_tac G1 G2 c1 e1 c1' n ex1 n1 ex2 n2)(*strict*)\n  apply(erule_tac\n      P=\"\\<exists>x\\<in> epda_delta G2 \\<inter> {e. F_DPDA_RMPUE__edge_if e}. e1 \\<in> F_DPDA_RMPUE__edge_then x\"\n      in disjE)\n   apply(rename_tac G1 G2 c1 e1 c1' n ex1 n1 ex2 n2)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' n ex1 n1 ex2 n2 x)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__edge_else_def)\n  apply(rename_tac G1 G2 c1 e1 c1' n ex1 n1 ex2 n2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1' n ex1 n1 ex2 n2 x)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__edge_then_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c1' n ex1 n1 ex2 n2 x xa)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__state_def)\n  apply(case_tac \"Suc (Suc xa) < length (edge_push x)\")\n   apply(rename_tac G1 G2 c1 c1' n ex1 n1 ex2 n2 x xa)(*strict*)\n   prefer 2\n   apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c1' n ex1 n1 ex2 n2 x xa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c1' n ex1 ex2 n2 xa)(*strict*)\n  apply(case_tac xa)\n   apply(rename_tac G1 G2 c1 c1' n ex1 ex2 n2 xa)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c1' n ex1 ex2 n2 xa nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c1' n ex2 nat)(*strict*)\n  apply(subgoal_tac \"False\")\n   apply(rename_tac G1 G2 c1 c1' n ex2 nat)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c1' n ex2 nat)(*strict*)\n  apply(subgoal_tac \"n=0\")\n   apply(rename_tac G1 G2 c1 c1' n ex2 nat)(*strict*)\n   prefer 2\n   apply(rule epdaS.maximum_of_domainUnique)\n     apply(rename_tac G1 G2 c1 c1' n ex2 nat)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c1' n ex2 nat)(*strict*)\n    apply(rule der1_maximum_of_domain)\n   apply(rename_tac G1 G2 c1 c1' n ex2 nat)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c1' n ex2 nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. epdaS_step_relation G2 (F_DPDA_RMPUE__conf_old__LR_revX c1) ex2 c\")\n   apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n   apply(clarsimp)\n   apply(erule_tac x=\"ex2\" in allE)\n   apply(erule disjE)\n    apply(simp add: der1_def get_configuration_def)\n   apply(simp add: F_DPDA_RMPUE__relation_labels__RL2_def)\n   apply(simp add: F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n   apply(erule conjE)\n   apply(simp add: F_DPDA_RMPUE__edge_then_def)\n   apply(erule_tac\n      x=\"Suc nat\"\n      in allE)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RMPUE__state_def)\n  apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n  apply(rule epdaS_step_exists)\n       apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n       apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n       apply(clarsimp)\n       apply(rename_tac G2 c1 c1' ex2 nat)(*strict*)\n       apply(simp add: valid_dpda_def valid_pda_def)\n      apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n      apply(rule_tac\n      i=\"0\"\n      and d=\"der1 (F_DPDA_RMPUE__conf_old__LR_revX c1)\"\n      in epdaS.belongs_configurations)\n       apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n      apply(simp add: der1_def)\n     apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n    apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def)\n   apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n   apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def prefix_def)\n   apply(rule_tac\n      x=\"epdaS_conf_scheduler c1'\"\n      in exI)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' ex2 nat w)(*strict*)\n   apply(case_tac \"edge_event ex2\")\n    apply(rename_tac G1 G2 c1 c1' ex2 nat w)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c1' ex2 nat w a)(*strict*)\n   apply(clarsimp)\n   apply(simp add: strict_executing_edge_def FB_executing_edge_def F_DPDA_RMPUE__edge_if_def F_DPDA_RMPUE__relation_TSstructure__RL_def read_edges_seperated_def)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 c1' ex2 nat w a)(*strict*)\n   apply(erule_tac\n      x=\"ex2\"\n      in ballE)\n    apply(rename_tac G2 c1 c1' ex2 nat w a)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G2 c1 c1' ex2 nat w a)(*strict*)\n   apply(clarsimp)\n   apply(simp add: valid_dpda_def valid_pda_def)\n  apply(rename_tac G1 G2 c1 c1' ex2 nat)(*strict*)\n  apply(simp add: epdaS_step_relation_def F_DPDA_RMPUE__conf_old__LR_revX_def prefix_def)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimRLRequired__inst__ATS_Simulation_Configuration_WeakRequired_axioms: \"\n  ATS_Simulation_Configuration_WeakRequired_axioms epda_step_labels epdaS_step_relation\n     epdaS_configurations epda_step_labels epdaS_step_relation\n     F_DPDA_RMPUE__relation_configuration__RL2 F_DPDA_RMPUE__relation_TSstructure__RL\n     F_DPDA_RMPUE__relation_step_simulation__RL2 F_DPDA_RMPUE__relation_labels__RL2\n     epdaS_marking_configurations epdaS_marking_configurations\"\n  apply(simp add: ATS_Simulation_Configuration_WeakRequired_axioms_def\n      epdaS_epdaS_RMP_StateSimRLRequired__inst__AX_relation_configuration_compatible_with_marking_configurations\n      epdaS_epdaS_RMP_StateSimRLRequired__inst__AX_relation_step_simulation_no_reach_marking_with_empty_simulant\n      epdaS_epdaS_RMP_StateSimRLRequired__inst__AX_relation_step_simulationReach)\n  done\n\ninterpretation \"epdaS_epdaS_RMP_StateSimRLRequired\" : ATS_Simulation_Configuration_WeakRequired\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaS_configurations\"\n  (* initial_configurations1 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaS_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaS_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_DPDA_RMPUE__relation_configuration__RL2\"\n  (* relation_initial_configuration *)\n  \"F_DPDA_RMPUE__relation_initial_configuration__RL2\"\n  (* relation_effect *)\n  \"F_DPDA_RMPUE__relation_effect__RL\"\n  (* relation_TSstructure *)\n  \"F_DPDA_RMPUE__relation_TSstructure__RL\"\n  (* relation_initial_simulation *)\n  \"F_DPDA_RMPUE__relation_initial_simulation__RL2\"\n  (* relation_step_simulation *)\n  \"F_DPDA_RMPUE__relation_step_simulation__RL2\"\n  (* relation_labelsRL *)\n  \"F_DPDA_RMPUE__relation_labels__RL2\"\n  (* marking_configurations1 *)\n  \"epdaS_marking_configurations\"\n  (* marking_configurations2 *)\n  \"epdaS_marking_configurations\"\n  apply(simp add: LOCALE_DEFS epda_interpretations)\n  apply(simp add:   epdaS_epdaS_RMP_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axiomsX epdaS_epdaS_RMP_StateSimRLRequired__inst__ATS_Simulation_Configuration_WeakRequired_axioms)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimLRRequired__inst__AX_relation_configuration_compatible_with_marking_configurations: \"\n(\\<forall>G1 G2.\n        F_DPDA_RMPUE__relation_structure__LR G1 G2 \\<longrightarrow>\n        (\\<forall>c1 c2.\n            F_DPDA_RMPUE__relation_configuration__LR G1 G2 c1 c2 \\<longrightarrow>\n            c1 \\<in> epdaS_marking_configurations G1 \\<longrightarrow> c2 \\<in> epdaS_marking_configurations G2))\"\n  apply(clarsimp)\n  apply(simp add: epdaS_marking_configurations_def)\n  apply(subgoal_tac \"c2 \\<in> epdaS_configurations G2\")\n   prefer 2\n   apply (metis F_DPDA_RMPUE__conf_old__LR_preserves_configurations F_DPDA_RMPUE__relation_configuration__LR_def)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def F_DPDA_RMPUE__relation_configuration__LR_def F_DPDA_RMPUE__relation_TSstructure__RL_def F_DPDA_RMPUE__relation_configuration__RL2_def F_DPDA_RMPUE_def F_DPDA_RMPUE__conf_old__LR_revX_def F_DPDA_RMPUE__conf_old__LR_def)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimLRRequired__inst__AX_relation_step_simulation_no_reach_marking_with_empty_simulant: \"\n (\\<forall>G1 G2.\n        F_DPDA_RMPUE__relation_structure__LR G1 G2 \\<longrightarrow>\n        (\\<forall>c1 c2.\n            F_DPDA_RMPUE__relation_configuration__LR G1 G2 c1 c2 \\<longrightarrow>\n            (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow>\n                  (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow>\n                         (\\<forall>d2. F_DPDA_RMPUE__relation_step_simulation__LR G1 G2 c1 e1 c1' c2\n                                d2 \\<longrightarrow>\n                               maximum_of_domain d2 0 \\<longrightarrow>\n                               c1' \\<notin> epdaS_marking_configurations G1)))))\"\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RMPUE__relation_step_simulation__LR_def)\n  apply(case_tac \"F_DPDA_RMPUE__edge_if e1\")\n   apply(clarsimp)\n   apply(simp add: maximum_of_domain_def der2_def)\n   apply(clarsimp)\n   apply(case_tac \"Suc 0 < length (edge_push e1)\")\n    apply(clarsimp)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RMPUE__edge_if_def)\n  apply(clarsimp)\n  apply(simp add: maximum_of_domain_def der2_def)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimLRquired__inst__AX_relation_step_simulationReach: \"\n   \\<forall>G1 G2.\n       F_DPDA_RMPUE__relation_structure__LR G1 G2 \\<longrightarrow>\n       (\\<forall>c1 c2.\n           F_DPDA_RMPUE__relation_configuration__LR G1 G2 c1 c2 \\<longrightarrow>\n           (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow>\n                 (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow>\n                        (\\<forall>d2. epdaS.derivation G2 d2 \\<longrightarrow>\n                              epdaS.belongs G2 d2 \\<longrightarrow>\n                              the (get_configuration (d2 0)) = c2 \\<longrightarrow>\n                              F_DPDA_RMPUE__relation_step_simulation__LR G1 G2 c1 e1 c1' c2\n                               d2 \\<longrightarrow>\n                              (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow>\n                                   F_DPDA_RMPUE__relation_configuration__LR G1 G2 c1'\n                                    (the (get_configuration (d2 n))) \\<longrightarrow>\n                                   (\\<exists>k e2. (\\<exists>c2. d2 k = Some (pair (Some e2) c2)) \\<and>\n                                           F_DPDA_RMPUE__relation_labels__LR2 G1 G2 e1 e2) \\<or>\n                                   n = 0 \\<and>\n                                   (\\<exists>e2. Ex (epdaS_step_relation G2 c2 e2) \\<and>\n                                         F_DPDA_RMPUE__relation_labels__LR2 G1 G2 e1 e2))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def epda_step_labels_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 e1 c1' d2 n)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_step_simulation__LR_def)\n  apply(case_tac \"F_DPDA_RMPUE__edge_if e1\")\n   apply(rename_tac G1 c1 e1 c1' d2 n)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 c1 e1 c1' n)(*strict*)\n   apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n   apply(subgoal_tac \"Suc 0 < length (edge_push e1)\")\n    apply(rename_tac G1 c1 e1 c1' n)(*strict*)\n    prefer 2\n    apply(simp add: F_DPDA_RMPUE__edge_if_def)\n   apply(rename_tac G1 c1 e1 c1' n)(*strict*)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RMPUE__edge_then_i_th__LR_def)\n   apply(simp add: F_DPDA_RMPUE__relation_labels__LR2_def)\n   apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n   apply(simp add: F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n   apply(simp add: F_DPDA_RMPUE__edge_then_def)\n   apply(rule disjI1)\n   apply(rule_tac\n      x=\"0\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac G1 c1 e1 c1' d2 n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 e1 c1' n)(*strict*)\n  apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n  apply(rule_tac\n      x=\"(F_DPDA_RMPUE__edge_else e1)\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 c1 e1 c1' n)(*strict*)\n   apply(simp add: der2_def)\n  apply(rename_tac G1 c1 e1 c1' n)(*strict*)\n  apply(simp add: F_DPDA_RMPUE__relation_labels__LR2_def)\n  apply(rule conjI)\n   apply(rename_tac G1 c1 e1 c1' n)(*strict*)\n   apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n  apply(rename_tac G1 c1 e1 c1' n)(*strict*)\n  apply(simp only: F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n  apply(clarsimp)\n  done\n\nlemma epdaS_epdaS_RMP_StateSimLRRequired__inst__ATS_Simulation_Configuration_WeakRequired_axioms: \"\n  ATS_Simulation_Configuration_WeakRequired_axioms epda_step_labels epdaS_step_relation\n     epdaS_configurations epda_step_labels epdaS_step_relation\n     F_DPDA_RMPUE__relation_configuration__LR F_DPDA_RMPUE__relation_structure__LR\n     F_DPDA_RMPUE__relation_step_simulation__LR F_DPDA_RMPUE__relation_labels__LR2\n     epdaS_marking_configurations epdaS_marking_configurations\"\n  apply(simp add: ATS_Simulation_Configuration_WeakRequired_axioms_def\n      epdaS_epdaS_RMP_StateSimLRRequired__inst__AX_relation_configuration_compatible_with_marking_configurations\n      epdaS_epdaS_RMP_StateSimLRRequired__inst__AX_relation_step_simulation_no_reach_marking_with_empty_simulant\n      epdaS_epdaS_RMP_StateSimLRquired__inst__AX_relation_step_simulationReach\n      )\n  done\n\ninterpretation \"epdaS_epdaS_RMP_StateSimLRRequired\" : ATS_Simulation_Configuration_WeakRequired\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaS_configurations\"\n  (* initial_configurations1 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaS_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaS_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_DPDA_RMPUE__relation_configuration__LR\"\n  (* relation_initial_configuration *)\n  \"F_DPDA_RMPUE__relation_initial_configuration__LR\"\n  (* relation_effect *)\n  \"F_DPDA_RMPUE__relation_effect__LR\"\n  (* relation_TSstructure *)\n  \"F_DPDA_RMPUE__relation_structure__LR\"\n  (* relation_initial_simulation *)\n  \"F_DPDA_RMPUE__relation_initial_simulation__LR\"\n  (* relation_step_simulation *)\n  \"F_DPDA_RMPUE__relation_step_simulation__LR\"\n  (* relation_labelsLR *)\n  \"F_DPDA_RMPUE__relation_labels__LR2\"\n  (* marking_configurations1 *)\n  \"epdaS_marking_configurations\"\n  (* marking_configurations2 *)\n  \"epdaS_marking_configurations\"\n  apply(simp add: LOCALE_DEFS epda_interpretations)\n  apply(simp add: epdaS_epdaS_RMP_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms epdaS_epdaS_RMP_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms epdaS_epdaS_RMP_StateSimLRRequired__inst__ATS_Simulation_Configuration_WeakRequired_axioms)\n  done\n\nlemma F_DPDA_DRE__revert_F_DPDA_RMPUE_SOUND_scheduled_case_epdaS_required_edges: \"\n  F_DPDA_RMPUE__SpecInput G'\n  \\<Longrightarrow> F_DPDA_DRE__revert_F_DPDA_RMPUE G' (epdaS_required_edges (F_DPDA_RMPUE G')) = epdaS_required_edges G'\"\n  apply(rule order_antisym)\n   apply(simp add: epdaS_required_edges_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n   apply(clarsimp)\n   apply(subgoal_tac \"\\<exists>m. n+m=k\")\n    prefer 2\n    apply(rule_tac x=\"k-n\" in exI)\n    apply(force)\n   apply(clarsimp)\n   apply(subgoal_tac \"X\" for X)\n    prefer 2\n    apply(rule_tac ?G1.0=\"F_DPDA_RMPUE G'\" and ?G2.0=\"G'\" and ?n1'=\"n+m\" in epdaS_epdaS_RMP_StateSimRLRequired.ATS_Simulation_Configuration_WeakRequired_exists_ALT)\n          apply(simp add: F_DPDA_RMPUE__relation_TSstructure__RL_def)\n          apply(simp add: F_DPDA_RMPUE__SpecInput_def)\n         apply(simp add: F_DPDA_RMPUE__SpecInput_def)\n         apply(clarsimp)\n         apply (metis epdaS.is_forward_deterministic_accessible_def epdaS_dependency_between_determinism_properties valid_dpda_def valid_pda_def)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(clarsimp)\n   apply(rule_tac x=\"d2\" in exI)\n   apply(clarsimp)\n   apply(rule_tac x=\"n2\" in exI)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RMPUE__relation_labels__RL2_def)\n   apply(simp add: F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n   apply(clarsimp)\n   apply(rule conjI)\n    prefer 2\n    apply(rule_tac x=\"n2'\" in exI)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RMPUE__relation_configuration__RL2_def epdaS_marking_configurations_def)\n    apply(subgoal_tac \"X\" for X)\n     prefer 2\n     apply(rule_tac ?c1.0=\"ca\" in\n      F_DPDA_RMPUE__conf_old__LR_revX_preserves_configurations)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RMPUE__conf_old__LR_revX_def F_DPDA_RMPUE_def)\n    apply(case_tac \"epdaS_conf_state ca\")\n     apply(clarsimp)\n    apply(clarsimp)\n   apply(rule_tac ?n2.0=\"n2\" and d=\"d\" and ?d2.0=\"d2\" in F_DPDA_DRE__revert_F_DPDA_RMPUE_SOUND_scheduled_case_rev_id)\n           apply(force)\n          apply(force)\n         apply(force)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(simp add: F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n  apply(simp add: epdaS_required_edges_def)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n  apply(subgoal_tac \"\\<exists>m. n+m=k\")\n   prefer 2\n   apply(rule_tac x=\"k-n\" in exI)\n   apply(force)\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac ?G2.0=\"F_DPDA_RMPUE G'\" and ?G1.0=\"G'\" and ?n1'=\"n+m\" in epdaS_epdaS_RMP_StateSimLRRequired.ATS_Simulation_Configuration_WeakRequired_exists_ALT)\n         apply(simp add: F_DPDA_RMPUE__relation_structure__LR_def)\n         apply(simp add: F_DPDA_RMPUE__SpecInput_def)\n        apply(simp add: F_DPDA_RMPUE__SpecInput_def)\n        apply(clarsimp)\n        apply(simp add: epdaS.is_forward_deterministic_accessible_def)\n        apply(rule conjI)\n         prefer 2\n         apply(rule F_DPDA_RMPUE__preserves_is_forward_edge_deterministic_accessible)\n           apply(force)\n          apply(force)\n         apply(force)\n        apply(rule epdaS_is_forward_target_deterministic_accessible)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(rule_tac x=\"e2\" in exI)\n  apply(rule conjI)\n   apply(rule_tac\n      t=\"epda_delta SSX\" \n      and s=\"epda_step_labels SSX\" for SSX\n      in ssubst)\n    apply(simp add: epda_step_labels_def)\n   apply(rule_tac\n      i=\"n2\" and d=\"d2\"\n      in epdaS.belongs_step_labels)\n    prefer 2\n    apply(force)\n   apply(rule epdaS.derivation_initial_belongs)\n    apply(rule F_DPDA_RMPUE__preserves_epda)\n    apply(simp add: F_DPDA_RMPUE__SpecInput_def)\n   apply(force)\n  apply(rule conjI)\n   apply(rule_tac x=\"d2\" in exI)\n   apply(clarsimp)\n   apply(rule_tac x=\"n2\" in exI)\n   apply(clarsimp)\n   apply(rule_tac x=\"n2'\" in exI)\n   apply(clarsimp)\n   apply (metis F_DPDA_RMPUE__conf_old__LR_preserves_marking_configurations F_DPDA_RMPUE__relation_configuration__LR_def)\n  apply(simp add: F_DPDA_RMPUE__relation_labels__LR2_def F_DPDA_DRE__revert_F_DPDA_RMPUE_def)\n  done\n\nend\n\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_12_04_04_04/FUNCTION__DPDA_RMPE__DPDA_REMOVE_MASS_PUSHING_EDGES.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297745935070806, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.27573011618249416}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory FastMap\nimports\n  LemmaBucket\nbegin\n\ntext \\<open>\n  Efficient rules and tactics for working with large lookup tables (maps).\n\n  Features:\n    \\<^item> Define a binary lookup tree for any lookup table (requires linorder keys)\n    \\<^item> Conversion from lookup tree to lookup lists\n    \\<^item> Pre-computation of lookup results and domain/range sets\n\n  See FastMap_Test for examples.\n\\<close>\n\n(*\n * TODO:\n *\n *   • Storing the auxilliary list theorems with Local_Theory.notes\n *     takes quadratic time. Unfortunately, this seems to be a problem\n *     deep inside the Isabelle implementation. One might try to wrap\n *     the lists in new constants, but Local_Theory.define also takes\n *     quadratic time.\n *\n *   • Still a bit slower than the StaticFun package. Streamline the\n *     rulesets and proofs.\n *\n *   • We use a lot of manual convs for performance and to avoid\n *     relying on the dynamic simpset. However, we should clean up the\n *     convs and move as much as possible to (simp only:) invocations.\n *\n *     Note that running simp on deeply nested terms (e.g. lists)\n *     always takes quadratic time and we can't use it there. This is\n *     because rewritec unconditionally calls eta_conversion (urgh).\n *\n *   • The injectivity prover currently hardcodes inj_def into the\n *     simpset. This should be changed at some point, probably by\n *     asking the user to prove it beforehand.\n *\n *   • The key ordering prover is currently hardcoded to simp_tac;\n *     this should also be generalised. On the other hand, the user\n *     could work around this by manually supplying a simpset with\n *     precisely the needed theorems.\n *\n *   • Using the simplifier to evaluate tree lookups is still quite\n *     slow because it looks at the entire tree term (even though\n *     most of it is irrelevant for any given lookup). We should\n *     provide a tactic or simproc to do this.\n *\n *     We already generate lookup theorems for keys in the map, so\n *     this tactic should be optimised for missing keys.\n *\n *   • The linorder requirement can be cumbersome. It arises because\n *     we express the map_of conversion as a general theorem using\n *     lookup_tree_valid. An alternative approach is to extend what\n *     StaticFun does, and cleverly extract the set of all relevant\n *     bindings from the tree on a case-by-case basis.\n *\n *     We would still need to evaluate the key ordering function on\n *     the input keys, but any arbitrary relation would be allowed.\n *     This one probably calls for a wizard.\n *)\n\nlocale FastMap begin\n\ntext \\<open>\n  Binary lookup tree. This is largely an implementation detail, so we\n  choose the structure to make automation easier (e.g. separate fields\n  for the key and value).\n\n  We could reuse HOL.Tree instead, but the proofs would need changing.\n\\<close>\ndatatype ('k, 'v) Tree =\n    Leaf\n  | Node 'k 'v \"('k, 'v) Tree\" \"('k, 'v) Tree\"\n\nprimrec lookup_tree :: \"('k \\<Rightarrow> 'ok :: linorder) \\<Rightarrow> ('k, 'v) Tree \\<Rightarrow> 'k \\<Rightarrow> 'v option\"\n  where\n    \"lookup_tree key Leaf x = None\"\n  | \"lookup_tree key (Node k v l r) x =\n       (if key x = key k then Some v\n        else if key x < key k then lookup_tree key l x\n        else lookup_tree key r x)\"\n\ntext \\<open>\n  Predicate for well-formed lookup trees.\n  This states that the keys are distinct and appear in ascending order.\n  It also returns the lowest and highest keys in the tree (or None for empty trees).\n\\<close>\nprimrec lookup_tree_valid ::\n        \"('k \\<Rightarrow> 'ok :: linorder) \\<Rightarrow> ('k, 'v) Tree \\<Rightarrow> bool \\<times> ('k \\<times> 'k) option\"\n  where\n    \"lookup_tree_valid key Leaf = (True, None)\"\n  | \"lookup_tree_valid key (Node k v lt rt) =\n       (let (lt_valid, lt_range) = lookup_tree_valid key lt;\n            (rt_valid, rt_range) = lookup_tree_valid key rt;\n            lt_low = (case lt_range of None \\<Rightarrow> k | Some (low, high) \\<Rightarrow> low);\n            rt_high = (case rt_range of None \\<Rightarrow> k | Some (low, high) \\<Rightarrow> high)\n        in (lt_valid \\<and> rt_valid \\<and>\n            (case lt_range of None \\<Rightarrow> True | Some (low, high) \\<Rightarrow> key high < key k) \\<and>\n            (case rt_range of None \\<Rightarrow> True | Some (low, high) \\<Rightarrow> key k < key low),\n            Some (lt_low, rt_high)))\"\n\nlemma lookup_tree_valid_simps':\n  \"lookup_tree_valid key Leaf = (True, None)\"\n  \"lookup_tree_valid key (Node k v Leaf Leaf) = (True, Some (k, k))\"\n  \"\\<lbrakk> lookup_tree_valid key (Node lk lv llt lrt) = (True, Some (llow, lhigh));\n     key lhigh < key k\n   \\<rbrakk> \\<Longrightarrow> lookup_tree_valid key (Node k v (Node lk lv llt lrt) Leaf) =\n           (True, Some (llow, k))\"\n  \"\\<lbrakk> lookup_tree_valid key (Node rk rv rlt rrt) = (True, Some (rlow, rhigh));\n     key k < key rlow\n   \\<rbrakk> \\<Longrightarrow> lookup_tree_valid key (Node k v Leaf (Node rk rv rlt rrt)) =\n           (True, Some (k, rhigh))\"\n  \"\\<lbrakk> lookup_tree_valid key (Node lk lv llt lrt) = (True, Some (llow, lhigh));\n     lookup_tree_valid key (Node rk rv rlt rrt) = (True, Some (rlow, rhigh));\n     key lhigh < key k;\n     key k < key rlow\n   \\<rbrakk> \\<Longrightarrow> lookup_tree_valid key (Node k v (Node lk lv llt lrt) (Node rk rv rlt rrt)) =\n           (True, Some (llow, rhigh))\"\n  by auto\n\nlemma lookup_tree_valid_empty:\n  \"lookup_tree_valid key tree = (True, None) \\<Longrightarrow> tree = Leaf\"\n  apply (induct tree)\n   apply simp\n  apply (fastforce split: prod.splits option.splits if_splits)\n  done\n\nlemma lookup_tree_valid_range:\n  \"lookup_tree_valid key tree = (True, Some (low, high)) \\<Longrightarrow> key low \\<le> key high\"\n  apply (induct tree arbitrary: low high)\n   apply simp\n  apply (fastforce split: prod.splits option.splits if_splits)\n  done\n\nlemma lookup_tree_valid_in_range:\n  \"lookup_tree_valid key tree = (True, Some (low, high)) \\<Longrightarrow>\n   lookup_tree key tree k = Some v \\<Longrightarrow>\n   key k \\<in> {key low .. key high}\"\n  apply (induct tree arbitrary: k v low high)\n   apply simp\n  apply (fastforce split: prod.splits option.splits if_split_asm\n                   dest: lookup_tree_valid_empty lookup_tree_valid_range)\n  done\n\nlemma lookup_tree_valid_in_range_None:\n  \"lookup_tree_valid key tree = (True, Some (low, high)) \\<Longrightarrow>\n   key k \\<notin> {key low .. key high} \\<Longrightarrow>\n   lookup_tree key tree k = None\"\n  using lookup_tree_valid_in_range by fastforce\n\ntext \\<open>\n  Flatten a lookup tree into an assoc-list.\n  As long as the tree is well-formed, both forms are equivalent.\n\\<close>\nprimrec lookup_tree_to_list :: \"('k, 'v) Tree \\<Rightarrow> ('k \\<times> 'v) list\"\n  where\n    \"lookup_tree_to_list Leaf = []\"\n  | \"lookup_tree_to_list (Node k v lt rt) =\n        lookup_tree_to_list lt @ [(k, v)] @ lookup_tree_to_list rt\"\n\nlemma lookup_tree_to_list_range:\n  \"lookup_tree_valid key tree = (True, Some (low, high)) \\<Longrightarrow>\n   (k, v) \\<in> set (lookup_tree_to_list tree) \\<Longrightarrow>\n   key k \\<in> {key low .. key high}\"\n  apply (induct tree arbitrary: k v low high)\n   apply simp\n  apply (fastforce split: prod.splits option.splits if_split_asm\n                   dest: lookup_tree_valid_empty lookup_tree_valid_range)\n  done\n\nlemma lookup_tree_dom_distinct_sorted_:\n  \"fst (lookup_tree_valid key tree) \\<Longrightarrow>\n   distinct (lookup_tree_to_list tree) \\<and> sorted (map (key o fst) (lookup_tree_to_list tree))\"\n  apply (induct tree)\n   apply simp\n  apply (fastforce simp: sorted_append\n                   split: prod.splits option.splits if_splits\n                   dest: lookup_tree_valid_empty lookup_tree_valid_range\n                         lookup_tree_valid_in_range lookup_tree_to_list_range\n                   elim: lookup_tree_valid_in_range_None)\n  done\n\nlemmas lookup_tree_dom_distinct = lookup_tree_dom_distinct_sorted_[THEN conjunct1]\nlemmas lookup_tree_dom_sorted = lookup_tree_dom_distinct_sorted_[THEN conjunct2]\n\n(* This goal is eta-expanded and flipped, which seems to help its proof *)\nlemma lookup_tree_to_list_of_:\n  \"fst (lookup_tree_valid key tree) \\<Longrightarrow>\n   map_of (map (apfst key) (lookup_tree_to_list tree)) (key k) = lookup_tree key tree k\"\n  apply (induct tree arbitrary: k)\n   apply simp\n  (* this big blob just does case distinctions of both subtrees and\n     all possible lookup results within each, then solves *)\n  (* slow 10s *)\n  by (fastforce simp: apfst_def map_prod_def map_add_def\n                split: prod.splits option.splits if_splits\n                dest: lookup_tree_valid_empty lookup_tree_valid_range lookup_tree_valid_in_range\n                elim: lookup_tree_valid_in_range_None)\n\n(* Standard form of above *)\nlemma lookup_tree_to_list_of:\n  \"fst (lookup_tree_valid key tree) \\<Longrightarrow>\n   lookup_tree key tree = map_of (map (apfst key) (lookup_tree_to_list tree)) o key\"\n  apply (rule ext)\n  apply (simp add: lookup_tree_to_list_of_)\n  done\n\nlemma map_of_key:\n  \"inj key \\<Longrightarrow> map_of (map (apfst key) binds) o key = map_of binds\"\n  apply (rule ext)\n  apply (induct binds)\n   apply simp\n  apply (clarsimp simp: inj_def dom_def)\n  done\n\nlemma lookup_tree_to_list_of_distinct:\n  \"\\<lbrakk> fst (lookup_tree_valid key tree);\n     lookup_tree_to_list tree = binds;\n     lookup_tree key tree = map_of (map (apfst key) binds) o key\n   \\<rbrakk> \\<Longrightarrow> distinct (map (key o fst) binds)\"\n  apply (drule sym[where t = binds])\n  apply clarsimp\n  apply (thin_tac \"binds = _\")\n  apply (induct tree)\n   apply simp\n  apply (fastforce simp: map_add_def lookup_tree_to_list_of\n                   split: prod.splits option.splits if_splits\n                   dest: lookup_tree_valid_empty lookup_tree_valid_range\n                         lookup_tree_valid_in_range lookup_tree_to_list_range\n                   elim: lookup_tree_valid_in_range_None)\n  done\n\n(* Top-level rule for converting to lookup list.\n   We add a distinctness assertion for inferring the range of values. *)\nlemma lookup_tree_to_list_of_gen:\n  \"\\<lbrakk> inj key;\n     fst (lookup_tree_valid key tree);\n     lookup_tree_to_list tree = binds\n   \\<rbrakk> \\<Longrightarrow> lookup_tree key tree = map_of binds \\<and> distinct (map fst binds)\"\n  using lookup_tree_to_list_of\n  apply (fastforce intro: lookup_tree_to_list_of_distinct\n                   simp: map_of_key distinct_inj)\n  done\n\ntext \\<open>\n  Domain and range of a @{const map_of}.\n  Like @{thm dom_map_of_conv_image_fst} but leaving out the set bloat.\n\\<close>\nlemma dom_map_of_conv_list:\n  \"dom (map_of xs) = set (map fst xs)\"\n  by (simp add: dom_map_of_conv_image_fst)\n\nlemma ran_map_of_conv_list:\n  \"distinct (map fst xs) \\<Longrightarrow> ran (map_of xs) = set (map snd xs)\"\n  by (erule distinct_map_via_ran)\n\ntext \\<open>\n  Read lookup rules from a @{const map_of}.\n\\<close>\n\nlemma map_of_lookups:\n  \"m = map_of binds \\<and> distinct (map fst binds) \\<Longrightarrow>\n   list_all (\\<lambda>(k, v). m k = Some v) binds\"\n  apply (induct binds)\n   apply simp\n  apply (force simp: list_all_iff)\n  done\n\n(* Helper for converting from maps defined as @{const fun_upd} chains,\n * which are applied in reverse order *)\nlemma map_of_rev:\n  \"distinct (map fst binds) \\<Longrightarrow>\n   map_of (rev binds) = map_of binds\"\n  apply (subgoal_tac \"distinct (map fst (rev binds))\")\n   apply (rule ext)\n   apply (induct binds)\n    apply simp\n   apply (force simp: map_add_def split: option.splits)\n  apply (metis distinct_rev rev_map)\n  done\n\nlemma list_all_dest:\n  \"list_all P [(x, y)] \\<equiv> P (x, y)\"\n  \"list_all P ((x, y) # z # xs) \\<equiv> (P (x, y) \\<and> list_all P (z # xs))\"\n  by auto\n\n(* Install lookup rules that don't depend on if_cong/if_weak_cong setup *)\nlemma lookup_tree_simps':\n  \"lookup_tree key Leaf x = None\"\n  \"key x = key k \\<Longrightarrow> lookup_tree key (Node k v l r) x = Some v\"\n  \"key x < key k \\<Longrightarrow> lookup_tree key (Node k v l r) x = lookup_tree key l x\"\n  \"key x > key k \\<Longrightarrow> lookup_tree key (Node k v l r) x = lookup_tree key r x\"\n  by auto\nend\n\ndeclare FastMap.lookup_tree.simps[simp del]\ndeclare FastMap.lookup_tree_simps'[simp]\n\nML \\<open>\nstructure FastMap = struct\n\n(* utils *)\nfun mk_optionT typ = Type (\"Option.option\", [typ])\nfun dest_optionT (Type (\"Option.option\", [typ])) = typ\n  | dest_optionT t = raise TYPE (\"dest_optionT\", [t], [])\n\n(* O(1) version of thm RS @{thm eq_reflection} *)\nfun then_eq_reflection thm = let\n  val (x, y) = Thm.dest_binop (Thm.dest_arg (Thm.cprop_of thm));\n  val cT = Thm.ctyp_of_cterm x;\n  val rule = @{thm eq_reflection} |> Thm.instantiate' [SOME cT] [SOME x, SOME y];\n  in Thm.implies_elim rule thm end;\n\nval lhs_conv = Conv.fun_conv o Conv.arg_conv\nval rhs_conv = Conv.arg_conv\n(* first order rewr_conv *)\nfun fo_rewr_conv rule ct = let\n  val (pure_eq, eqn) =\n        ((true, Thm.instantiate (Thm.first_order_match (Thm.lhs_of rule, ct)) rule)\n         handle TERM _ =>\n           (false, Thm.instantiate (Thm.first_order_match\n                      (fst (Thm.dest_binop (Thm.dest_arg (Thm.cprop_of rule))), ct)) rule))\n        handle Pattern.MATCH => raise CTERM (\"fo_rewr_conv\", [Thm.cprop_of rule, ct]);\n  in if pure_eq then eqn else then_eq_reflection eqn end;\nfun fo_rewrs_conv rules = Conv.first_conv (map fo_rewr_conv rules);\n\n(* Evaluate a term with rewrite rules. Unlike the simplifier, this\n * does only one top-down pass, but that's enough for tasks like\n * pushing List.map through a list. Also runs much faster. *)\nfun fo_topdown_rewr_conv rules ctxt =\n      Conv.top_conv (K (Conv.try_conv (fo_rewrs_conv rules))) ctxt\n\n(* Allow recursive conv in cv2, deferred by function application *)\ninfix 1 then_conv'\nfun (cv1 then_conv' cv2) ct =\n  let\n    val eq1 = cv1 ct;\n    val eq2 = cv2 () (Thm.rhs_of eq1);\n  in\n    if Thm.is_reflexive eq1 then eq2\n    else if Thm.is_reflexive eq2 then eq1\n    else Thm.transitive eq1 eq2\n  end;\n\n(*\n * Helper that makes it easier to describe where to apply a conv.\n * This takes a skeleton term and applies the conversion wherever \"HERE\"\n * appears in the skeleton.\n *\n * FIXME: use HOL-Library.Rewrite instead\n *)\nfun conv_at skel conv ctxt ct = let\n  fun mismatch current_skel current_ct =\n    raise TERM (\"conv_at mismatch\", [current_skel, Thm.term_of current_ct, skel, Thm.term_of ct])\n\n  fun walk (Free (\"HERE\", _)) _ ct = conv ct\n    | walk (skel as skel_f $ skel_x) ctxt ct =\n        (case Thm.term_of ct of\n            _ $ _ => Conv.combination_conv (walk skel_f ctxt) (walk skel_x ctxt) ct\n          | _ => mismatch skel ct)\n    | walk (skel as Abs (_, _, skel_body)) ctxt ct =\n        (case Thm.term_of ct of\n            Abs _ => Conv.abs_conv (fn (_, ctxt') => walk skel_body ctxt') ctxt ct\n          | _ => mismatch skel ct)\n    (* Also check that Consts match the skeleton pattern *)\n    | walk (skel as Const (skel_name, _)) _ ct =\n        if (case Thm.term_of ct of Const (name, _) => name = skel_name | _ => false)\n        then Thm.reflexive ct\n        else mismatch skel ct\n    (* Default case *)\n    | walk _ _ ct = Thm.reflexive ct\n  in walk skel ctxt ct end\n\nfun gconv_at_tac pat conv ctxt = Conv.gconv_rule (conv_at pat conv ctxt) 1 #> Seq.succeed\n\n\n(* Tree builder code, copied from StaticFun *)\n\n(* Actually build the tree -- theta (n lg(n)) *)\nfun build_tree' _ mk_leaf [] = mk_leaf\n  | build_tree' mk_node mk_leaf xs = let\n    val len = length xs\n    val (ys, zs) = chop (len div 2) xs\n  in case zs of [] => error \"build_tree': impossible\"\n    | ((a, b) :: zs) => mk_node a b (build_tree' mk_node mk_leaf ys)\n        (build_tree' mk_node mk_leaf zs)\n  end\n\nfun build_tree xs = case xs of [] => error \"build_tree : empty\"\n  | (idx, v) :: _ => let\n    val idxT = fastype_of idx\n    val vT = fastype_of v\n    val treeT = Type (@{type_name FastMap.Tree}, [idxT, vT])\n    val mk_leaf = Const (@{const_name FastMap.Leaf}, treeT)\n    val node = Const (@{const_name FastMap.Node},\n        idxT --> vT --> treeT --> treeT --> treeT)\n    fun mk_node a b l r = node $ a $ b $ l $ r\n  in\n    build_tree' mk_node mk_leaf xs\n  end\n\nfun define_partial_map_tree map_name mappings ord_term ctxt = let\n    val (idxT, vT) = apply2 fastype_of (hd mappings)\n    val treeT = Type (@{type_name FastMap.Tree}, [idxT, vT])\n    val lookup = Const (@{const_name FastMap.lookup_tree},\n                        fastype_of ord_term --> treeT --> idxT\n                            --> Type (@{type_name option}, [vT]))\n    val map_term = lookup $ ord_term $ build_tree mappings\n    val ((map_const, (_, map_def)), ctxt) =\n          Local_Theory.define ((map_name, NoSyn), ((Thm.def_binding map_name, []), map_term)) ctxt\n  in\n    ((map_const, map_def), ctxt)\n  end\n\n(* Prove key ordering theorems. This lets us issue precise error messages\n   when the user gives us keys whose ordering cannot be verified.\n   We will also need these thms to prove the lookup_tree_valid property. *)\nfun prove_key_ord_thms tree_name keyT mappings get_key simp_ctxt ctxt =\n  let\n    val solver = simp_tac (simp_ctxt ctxt [] []) 1;\n  in\n    fst (split_last mappings) ~~ tl mappings\n    |> map_index (fn (i, ((k1, _), (k2, _))) => let\n           val prop = Const (@{const_name less}, keyT --> keyT --> HOLogic.boolT) $\n                            (get_key $ k1) $ (get_key $ k2)\n                      |> HOLogic.mk_Trueprop;\n           in case try (Goal.prove ctxt [] [] prop) (K solver) of\n                  SOME x => x\n                | _ => raise TERM (tree_name ^ \": failed to prove less-than ordering for keys #\" ^\n                                   string_of_int i ^ \", #\" ^ string_of_int (i + 1),\n                                   [prop])\n           end)\n  end;\n\n(* Prove lookup_tree_valid *)\nfun prove_tree_valid tree_name mappings kT keyT tree_term get_key simp_ctxt ctxt = let\n    val key_ord_thms = prove_key_ord_thms tree_name keyT mappings get_key simp_ctxt ctxt;\n    val treeT = fastype_of tree_term\n    val valid_resultT = HOLogic.mk_prodT (HOLogic.boolT, mk_optionT (HOLogic.mk_prodT (kT, kT)))\n    val tree_valid_prop =\n          HOLogic.mk_Trueprop (\n            Const (@{const_name fst}, valid_resultT --> HOLogic.boolT) $\n            (Const (@{const_name FastMap.lookup_tree_valid},\n                    (kT --> keyT) --> treeT --> valid_resultT) $\n               get_key $ tree_term))\n    val solver = simp_tac (put_simpset HOL_basic_ss ctxt\n                           addsimps (@{thms prod.sel FastMap.lookup_tree_valid_simps'} @\n                                     key_ord_thms)) 1\n  in Goal.prove ctxt [] [] tree_valid_prop (K solver) end\n\nfun solve_simp_tac name ctxt = SUBGOAL (fn (t, i) =>\n      (simp_tac ctxt THEN_ALL_NEW SUBGOAL (fn (t', _) =>\n          raise TERM (name ^ \": unsolved\", [t, t']))) i)\n\nfun convert_to_lookup_list kT valT mappings map_const map_def tree_valid_thm simp_ctxt ctxt = let\n  val lookupT = fastype_of map_const\n  (* map_eq = \"<tree_const> = map_of <mappings>\" *)\n  val bindT = HOLogic.mk_prodT (kT, valT)\n  val lookup_list = HOLogic.mk_list bindT (map HOLogic.mk_prod mappings)\n  val map_of_Const = Const (@{const_name map_of}, HOLogic.listT bindT --> lookupT)\n  val map_eq = HOLogic.mk_eq (map_const, map_of_Const $ lookup_list)\n  (* distinct_pred = \"distinct (map fst <mappings>)\" *)\n  val distinct_pred =\n        Const (@{const_name distinct}, HOLogic.listT kT --> HOLogic.boolT) $\n          (Const (@{const_name map}, (bindT --> kT) --> HOLogic.listT bindT --> HOLogic.listT kT) $\n             Const (@{const_name fst}, bindT --> kT) $\n             lookup_list)\n  val convert_prop = HOLogic.mk_Trueprop (\n        HOLogic.mk_conj (map_eq, distinct_pred)\n        )\n  fun TIMED desc tac = fn st =>\n        Seq.make (K (Timing.timeap_msg (\"tactic timing for \" ^ desc)\n                          (fn () => Seq.pull (tac st)) ()))\n\n  val append_basecase = @{thm append.simps(1)}\n  val append_rec = @{thm append.simps(2)}\n  val lookup_tree_to_list_basecase = @{thm FastMap.lookup_tree_to_list.simps(1)}\n  val lookup_tree_to_list_rec = @{thm FastMap.lookup_tree_to_list.simps(2)[simplified append.simps]}\n\n  val lookup_tree_to_list_eval = let\n    fun append_conv () =\n            fo_rewr_conv append_basecase else_conv\n            (fo_rewr_conv append_rec then_conv'\n             (fn () => rhs_conv (append_conv ())))\n    fun to_map_conv () =\n            fo_rewr_conv lookup_tree_to_list_basecase else_conv\n            (fo_rewr_conv lookup_tree_to_list_rec then_conv'\n             (fn () => lhs_conv (to_map_conv ())) then_conv'\n             (fn () => rhs_conv (rhs_conv (to_map_conv ()))) then_conv\n             append_conv ())\n  in to_map_conv () end\n\n  val solver =\n        TIMED \"unfold\" (gconv_at_tac @{term \"Trueprop (HERE = map_of dummy1 \\<and> dummy2)\"}\n                                     (K map_def) ctxt)\n        THEN\n        TIMED \"main rule\" (resolve_tac ctxt @{thms FastMap.lookup_tree_to_list_of_gen} 1)\n        THEN\n          TIMED \"solve inj\" (solve_simp_tac \"solve inj\"\n                              (simp_ctxt ctxt @{thms simp_thms} @{thms inj_def}) 1)\n          THEN\n         TIMED \"resolve valid\" (resolve_tac ctxt [tree_valid_thm] 1)\n         THEN\n        TIMED \"convert tree\" (gconv_at_tac @{term \"Trueprop (HERE = dummy1)\"}\n                                           lookup_tree_to_list_eval ctxt)\n        THEN\n        resolve_tac ctxt @{thms refl} 1\n  val convert_thm = Goal.prove ctxt [] [] convert_prop (K solver)\n  in convert_thm end\n\n(* Obtain domain and range from lookup list *)\nfun domain_range_common dom_ran_const xT xs map_const lookup_list_eqn intro_conv_tac ctxt = let\n  val mapT = fastype_of map_const\n  val prop = HOLogic.mk_Trueprop (\n        HOLogic.mk_eq (\n          Const (dom_ran_const, mapT --> HOLogic.mk_setT xT) $ map_const,\n          Const (@{const_name set}, HOLogic.listT xT --> HOLogic.mk_setT xT) $\n            (HOLogic.mk_list xT xs)\n        ))\n  val lookup_list_eqn' = then_eq_reflection lookup_list_eqn\n  val map_fst_snd_conv = fo_topdown_rewr_conv @{thms list.map prod.sel} ctxt\n  val solver =\n        (gconv_at_tac @{term \"Trueprop (dom_ran_dummy1 HERE = dummy2)\"}\n                      (K lookup_list_eqn') ctxt)\n        THEN\n        intro_conv_tac\n        THEN\n        gconv_at_tac @{term \"Trueprop (HERE = dummy1)\"} map_fst_snd_conv ctxt\n        THEN\n        resolve_tac ctxt @{thms refl} 1\n  in Goal.prove ctxt [] [] prop (K solver) end;\n\nfun tree_domain kT mappings map_const lookup_list_eqn ctxt =\n  domain_range_common\n    @{const_name dom} kT (map fst mappings) map_const lookup_list_eqn\n    (* like (subst dom_map_of_conv_list) but faster *)\n    (resolve_tac ctxt @{thms FastMap.dom_map_of_conv_list[THEN trans]} 1)\n    ctxt;\n\nfun tree_range valT mappings map_const lookup_list_eqn map_distinct_thm ctxt =\n  domain_range_common\n    @{const_name ran} valT (map snd mappings) map_const lookup_list_eqn\n    (* like (subst ran_map_of_conv_list) but faster *)\n    (resolve_tac ctxt @{thms FastMap.ran_map_of_conv_list[THEN trans]} 1 THEN\n     resolve_tac ctxt [map_distinct_thm] 1)\n    ctxt;\n\n\n(* Choosing names for the const and its theorems. The constant will be named with\n   map_name; Local_Theory.define may also add extra names (e.g. <map_name>_def) *)\ntype name_opts = {\n    map_name: string,\n    tree_valid_thm: string,\n    to_lookup_list: string,\n    keys_distinct_thm: string,\n    lookup_thms: string,\n    domain_thm: string,\n    range_thm: string\n};\n\nfun name_opts_default (map_name: string): name_opts = {\n    map_name = map_name,\n    tree_valid_thm = map_name ^ \"_tree_valid\",\n    to_lookup_list = map_name ^ \"_to_lookup_list\",\n    keys_distinct_thm = map_name ^ \"_keys_distinct\",\n    lookup_thms = map_name ^ \"_lookups\",\n    domain_thm = map_name ^ \"_domain\",\n    range_thm = map_name ^ \"_range\"\n};\n\n(* Top level interface *)\nfun define_map\n            (name_opts: name_opts)\n            (mappings: (term * term) list)\n            (get_key: term) (* function to get linorder key, must be injective *)\n            (extra_simps: thm list)\n            (minimal_simp: bool) (* true: start with minimal simpset; extra_simps must be adequate *)\n            ctxt = let\n    fun simp_ctxt ctxt basic_simps more_simps = if minimal_simp\n      then put_simpset HOL_basic_ss ctxt addsimps (basic_simps @ extra_simps @ more_simps)\n      else ctxt addsimps (extra_simps @ more_simps)\n\n    val (kT, keyT) = dest_funT (fastype_of get_key)\n    val valT = fastype_of (snd (hd mappings))\n\n    val _ = tracing (#map_name name_opts ^ \": defining tree\")\n    val start = Timing.start ()\n    val ((map_const, map_def), ctxt) =\n            define_partial_map_tree\n                (Binding.name (#map_name name_opts))\n                mappings get_key ctxt\n    val _ = tracing (\"  done: \" ^ Timing.message (Timing.result start))\n\n    val _ = tracing (#map_name name_opts ^ \": proving tree is well-formed\")\n    val start = Timing.start ()\n    val _ $ _ $ tree_term = Thm.term_of (Thm.rhs_of map_def)\n    val tree_valid_thm =\n          prove_tree_valid (#map_name name_opts) mappings kT keyT tree_term get_key simp_ctxt ctxt\n    val (_, ctxt) = ctxt |> Local_Theory.notes\n        [((Binding.name (#tree_valid_thm name_opts), []), [([tree_valid_thm], [])])]\n    val _ = tracing (\"  done: \" ^ Timing.message (Timing.result start))\n\n    val _ = tracing (#map_name name_opts ^ \": converting tree to map\")\n    val start = Timing.start ()\n    val convert_thm =\n          convert_to_lookup_list kT valT mappings map_const map_def tree_valid_thm simp_ctxt ctxt\n    val [lookup_list_eqn, map_distinct_thm] = HOLogic.conj_elims ctxt convert_thm\n    val _ = tracing (\"  done: \" ^ Timing.message (Timing.result start))\n    val _ = tracing (#map_name name_opts ^ \": storing map and distinctness theorems\")\n    val start = Timing.start ()\n    val (_, ctxt) = ctxt |> Local_Theory.notes\n        [((Binding.name (#to_lookup_list name_opts), []), [([lookup_list_eqn], [])]),\n         ((Binding.name (#keys_distinct_thm name_opts), []), [([map_distinct_thm], [])])]\n    val _ = tracing (\"  done: \" ^ Timing.message (Timing.result start))\n\n    val _ = tracing (#map_name name_opts ^ \": obtaining lookup rules\")\n    val start = Timing.start ()\n    fun dest_list_all_conv () =\n          fo_rewr_conv @{thm FastMap.list_all_dest(1)} else_conv\n          (fo_rewr_conv @{thm FastMap.list_all_dest(2)} then_conv'\n           (fn () => rhs_conv (dest_list_all_conv())))\n    val combined_lookup_thm =\n          (convert_thm RS @{thm FastMap.map_of_lookups})\n          |> Conv.fconv_rule (conv_at @{term \"Trueprop HERE\"} (dest_list_all_conv ()) ctxt)\n    val _ = tracing (\"  splitting... \" ^ Timing.message (Timing.result start))\n    val lookup_thms =\n          HOLogic.conj_elims ctxt combined_lookup_thm\n          |> map (Conv.fconv_rule (conv_at @{term \"Trueprop HERE\"}\n                                     (fo_rewr_conv @{thm prod.case[THEN eq_reflection]}) ctxt))\n\n    val _ = if length lookup_thms = length mappings then () else\n              raise THM (\"wrong number of lookup thms: \" ^ string_of_int (length lookup_thms) ^\n                         \" instead of \" ^ string_of_int (length mappings), 0,\n                         lookup_thms)\n    val (_, ctxt) = ctxt |> Local_Theory.notes\n        [((Binding.name (#lookup_thms name_opts), []), [(lookup_thms, [])])]\n    val _ = tracing (\"  done: \" ^ Timing.message (Timing.result start))\n\n    (* domain and range *)\n    val _ = tracing (#map_name name_opts ^ \": getting domain and range\")\n    val start = Timing.start ()\n    val domain_thm = timeap_msg \"  calculate domain\"\n            (tree_domain kT mappings map_const lookup_list_eqn) ctxt\n    val range_thm = timeap_msg \"  calculate range\"\n            (tree_range valT mappings map_const lookup_list_eqn map_distinct_thm) ctxt\n    val (_, ctxt) = ctxt |> Local_Theory.notes\n        [((Binding.name (#domain_thm name_opts), []), [([domain_thm], [])]),\n         ((Binding.name (#range_thm name_opts), []), [([range_thm], [])])]\n    val _ = tracing (\"  done: \" ^ Timing.message (Timing.result start))\n  in ctxt end\n\nend\n\\<close>\n\nend", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/lib/FastMap.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6187804337438501, "lm_q2_score": 0.44552953503957277, "lm_q1q2_score": 0.2756849589374827}}
{"text": "theory IICF_List_MsetO\nimports \"../Intf/IICF_Multiset\"\nbegin\n\n  definition \"lmso_assn A \\<equiv> hr_comp (list_assn A) (br mset (\\<lambda>_. True))\"\n  lemmas [fcomp_norm_unfold] = lmso_assn_def[symmetric]\n\n  lemma lmso_is_pure[safe_constraint_rules]: \"is_pure A \\<Longrightarrow> is_pure (lmso_assn A)\"\n    unfolding lmso_assn_def by safe_constraint\n\n  lemma lmso_empty_aref: \"(uncurry0 (RETURN []), uncurry0 (RETURN op_mset_empty)) \\<in> unit_rel \\<rightarrow>\\<^sub>f \\<langle>br mset (\\<lambda>_. True)\\<rangle>nres_rel\"\n    by (auto intro!: frefI nres_relI simp: in_br_conv)\n    \n  (*  \n  definition [simp]: \"list_single x \\<equiv> [x]\"\n  lemma lmso_single_aref: \"(RETURN o list_single,RETURN o op_mset_single) \\<in> Id \\<rightarrow>\\<^sub>f \\<langle>br mset (\\<lambda>_. True)\\<rangle>nres_rel\"  \n    by (auto intro!: frefI nres_relI simp: in_br_conv)\n  *)  \n\n  lemma lmso_is_empty_aref: \"(RETURN o List.null, RETURN o op_mset_is_empty) \\<in> br mset (\\<lambda>_. True) \\<rightarrow>\\<^sub>f \\<langle>bool_rel\\<rangle>nres_rel\"  \n    by (auto intro!: frefI nres_relI simp: in_br_conv List.null_def split: list.split)\n\n\n  lemma lmso_insert_aref: \"(uncurry (RETURN oo (#) ), uncurry (RETURN oo op_mset_insert)) \\<in> (Id \\<times>\\<^sub>r br mset (\\<lambda>_. True)) \\<rightarrow>\\<^sub>f \\<langle>br mset (\\<lambda>_. True)\\<rangle>nres_rel\"  \n    by (auto intro!: frefI nres_relI simp: in_br_conv)\n    \n  (*  \n  lemma list_single_hnr: \"(return o list_single, RETURN o list_single) \\<in> A\\<^sup>d \\<rightarrow>\\<^sub>a list_assn A\"  \n    apply sepref_to_hoare\n    apply sep_auto\n    done  \n  *)\n    \n  definition [simp]: \"hd_tl l \\<equiv> (hd l, tl l)\"\n\n  lemma hd_tl_opt[sepref_opt_simps]: \"hd_tl l = (case l of (x#xs) \\<Rightarrow> (x,xs) | _ \\<Rightarrow> CODE_ABORT (\\<lambda>_. (hd l, tl l)))\"  \n    by (auto split: list.split)\n\n  lemma lmso_pick_aref: \"(RETURN o hd_tl,op_mset_pick) \\<in> [\\<lambda>m. m\\<noteq>{#}]\\<^sub>f br mset (\\<lambda>_. True) \\<rightarrow> \\<langle>Id \\<times>\\<^sub>r br mset (\\<lambda>_. True)\\<rangle>nres_rel\"  \n    by (auto intro!: frefI nres_relI simp: in_br_conv pw_le_iff refine_pw_simps neq_Nil_conv algebra_simps)\n    \n  lemma hd_tl_hnr: \"(return o hd_tl,RETURN o hd_tl) \\<in> [\\<lambda>l. \\<not>is_Nil l]\\<^sub>a (list_assn A)\\<^sup>d \\<rightarrow> prod_assn A (list_assn A)\"\n    apply sepref_to_hoare\n    subgoal for l li by (cases l; cases li; sep_auto)\n    done  \n\n  sepref_decl_impl (no_register) lmso_empty: hn_Nil[to_hfref] uses lmso_empty_aref .\n  definition [simp]: \"op_lmso_empty \\<equiv> op_mset_empty\"\n  sepref_register op_lmso_empty\n  lemma lmso_fold_custom_empty: \n    \"{#} = op_lmso_empty\"\n    \"op_mset_empty = op_lmso_empty\"\n    \"mop_mset_empty = RETURN op_lmso_empty\"\n    by auto\n  lemmas [sepref_fr_rules] = lmso_empty_hnr[folded op_lmso_empty_def]  \n\n  (*\n  sepref_decl_impl (no_register) lmso_single: list_single_hnr uses lmso_single_aref .\n  definition [simp]: \"op_lmso_single \\<equiv> op_mset_single\"\n  sepref_register op_lmso_single\n  lemma lmso_fold_custom_single: \n    \"{#x#} = op_lmso_single x\"\n    \"op_mset_single x = op_lmso_single x\"\n    \"mop_mset_single x = RETURN (op_lmso_single x)\"\n    by auto\n  lemmas [sepref_fr_rules] = lmso_single_hnr[folded op_lmso_single_def]  \n *) \n\n  \n\n  sepref_decl_impl lmso_is_empty: list_null_hnr uses lmso_is_empty_aref .\n\n  sepref_decl_impl lmso_insert: hn_Cons[to_hfref] uses lmso_insert_aref .\n\n  (* As parametricity heuristics of sepref_decl_impl fails here,\n    we use FCOMP and some dummy-lemma to still get the automation benefits of \n    sepref_decl_impl. *)\n  context notes [simp] = in_br_conv and [split] = list.splits begin\n    text \\<open>Dummy lemma, to exloit \\<open>sepref_decl_impl\\<close> automation without parametricity stuff.\\<close>\n    private lemma op_mset_pick_dummy_param: \"(op_mset_pick, op_mset_pick) \\<in> Id \\<rightarrow>\\<^sub>f \\<langle>Id\\<rangle>nres_rel\" \n      by (auto intro!: frefI nres_relI)\n\n    sepref_decl_impl lmso_pick: hd_tl_hnr[FCOMP lmso_pick_aref] uses op_mset_pick_dummy_param by simp\n  end  \n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Evaluation/Refine_Imperative_HOL/IICF/Impl/IICF_List_MsetO.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.27567241587655955}}
{"text": "(*  Title:      HOL/Auth/n_mutualEx_lemma_inv__1_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mutualEx Protocol Case Study*} \n\ntheory n_mutualEx_lemma_inv__1_on_rules imports n_mutualEx_lemma_on_inv__1\nbegin\nsection{*All lemmas on causal relation between inv__1*}\nlemma lemma_inv__1_on_rules:\n  assumes b1: \"r \\<in> rules N\" and b2: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__1  p__Inv3 p__Inv4)\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have c1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n  apply (cut_tac b1, auto) done\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_TryVsinv__1) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_CritVsinv__1) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_ExitVsinv__1) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_IdleVsinv__1) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "paraVerifier", "repo": "paraVerifier", "sha": "5de62b433a160bf8d714e0a5085a38b9dd8899f0", "save_path": "github-repos/isabelle/paraVerifier-paraVerifier", "path": "github-repos/isabelle/paraVerifier-paraVerifier/paraVerifier-5de62b433a160bf8d714e0a5085a38b9dd8899f0/proof_scripts/mutualEx/n_mutualEx_lemma_inv__1_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.689305616785446, "lm_q2_score": 0.39981164073979497, "lm_q1q2_score": 0.2755924096181455}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\n(* Author: Andrew Boyton, 2012\n   Maintainers: Gerwin Klein <kleing at cse.unsw.edu.au>\n                Rafal Kolanski <rafal.kolanski at nicta.com.au>\n*)\n\nchapter \"Defining some separation logic maps-to predicates on top of the instantiation.\"\n\ntheory Separation_D\nimports Abstract_Separation_D\nbegin\n\ntype_synonym sep_pred = \"sep_state \\<Rightarrow> bool\"\n\ndefinition\n  state_sep_projection :: \"cdl_state \\<Rightarrow> sep_state\"\nwhere\n  \"state_sep_projection \\<equiv> \\<lambda>s. SepState (cdl_objects s) (cdl_ghost_state s)\"\n\n(* This turns a separation logic predicate into a predicate on the capDL state. *)\nabbreviation\n  lift' :: \"(sep_state \\<Rightarrow> 'a) \\<Rightarrow> cdl_state \\<Rightarrow> 'a\" (\"<_>\")\nwhere\n  \"<P> s \\<equiv> P (state_sep_projection s)\"\n\n(* The generalisation of the maps to operator for separation logic. *)\ndefinition\n  sep_map_general :: \"cdl_object_id \\<Rightarrow> cdl_object \\<Rightarrow> cdl_components \\<Rightarrow> sep_pred\"\nwhere\n  \"sep_map_general p obj gs \\<equiv> \\<lambda>s. sep_heap s = [p \\<mapsto> obj] \\<and> sep_ghost_state s p = gs\"\n\n(* Alternate definition without the [p \\<mapsto> obj] notation. *)\nlemma sep_map_general_def2:\n  \"sep_map_general p obj gs s =\n   (dom (sep_heap s) = {p} \\<and> ko_at obj p (sep_heap s) \\<and> sep_ghost_state s p = gs)\"\n  apply (clarsimp simp: sep_map_general_def object_at_def)\n  apply (rule)\n   apply clarsimp\n  apply (clarsimp simp: fun_upd_def)\n  apply (rule ext)\n  apply (fastforce simp: dom_def split:if_split)\n  done\n\n(* There is an object there. *)\ndefinition\n  sep_map_i :: \"cdl_object_id \\<Rightarrow> cdl_object \\<Rightarrow> sep_pred\" (\"_ \\<mapsto>i _\" [76,71] 76)\nwhere\n  \"p \\<mapsto>i obj \\<equiv> sep_map_general p obj UNIV\"\n\n(* The fields are there (and there are no caps). *)\ndefinition\n  sep_map_f :: \"cdl_object_id \\<Rightarrow> cdl_object \\<Rightarrow> sep_pred\" (\"_ \\<mapsto>f _\" [76,71] 76)\nwhere\n  \"p \\<mapsto>f obj \\<equiv> sep_map_general p (update_slots empty obj) {None}\"\n\n(* There is that cap there. *)\ndefinition\n  sep_map_c :: \"cdl_cap_ref \\<Rightarrow> cdl_cap \\<Rightarrow> sep_pred\" (\"_ \\<mapsto>c _\" [76,71] 76)\nwhere\n  \"p \\<mapsto>c cap \\<equiv> \\<lambda>s. let (obj_id, slot) = p; heap = sep_heap s in\n  \\<exists>obj. sep_map_general obj_id obj {Some slot} s \\<and> object_slots obj = [slot \\<mapsto> cap]\"\n\ndefinition\n  sep_any :: \"('a \\<Rightarrow> 'b \\<Rightarrow> sep_pred) \\<Rightarrow> ('a \\<Rightarrow> sep_pred)\" where\n  \"sep_any m \\<equiv> (\\<lambda>p s. \\<exists>v. (m p v) s)\"\n\nabbreviation \"sep_any_map_i \\<equiv> sep_any sep_map_i\"\nnotation sep_any_map_i (\"_ \\<mapsto>i -\" 76)\n\nabbreviation \"sep_any_map_c \\<equiv> sep_any sep_map_c\"\nnotation sep_any_map_c (\"_ \\<mapsto>c -\" 76)\n\nend\n", "meta": {"author": "pirapira", "repo": "eth-isabelle", "sha": "d0bb02b3e64a2046a7c9670545d21f10bccd7b27", "save_path": "github-repos/isabelle/pirapira-eth-isabelle", "path": "github-repos/isabelle/pirapira-eth-isabelle/eth-isabelle-d0bb02b3e64a2046a7c9670545d21f10bccd7b27/sep_algebra/ex/capDL/Separation_D.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.640635868562172, "lm_q2_score": 0.4301473485858429, "lm_q1q2_score": 0.27556782027100685}}
{"text": "section \\<open>Control Flow Graph\\<close>\ntheory SM_Cfg\nimports \n  SM_Syntax \n  \"../Lib/LTS\" \n  \"../Lib/SOS_Misc_Add\" \nbegin\n  text \\<open>\n    We define the control flow graph of SM, in the style of\n    an structural operational semantics.\n\\<close>\n\n\n  text \\<open>\n    The edges of the CFG are labeled with actions. These are\n    assignments, tests, and skip.\n    Assignment actions come in three versions: Assignment to local variables,\n    assignment to global variables, and assignment to variables without\n    specification of a scope. These will be mapped to local or global variables,\n    depending on the scope.\n\\<close>\n  datatype action = \n      AAssign exp ident exp | AAssign_local exp ident exp | AAssign_global exp ident exp\n    | ATest exp | ASkip\n\n  text \\<open>\n    Moreover, the semantics uses internal actions to handle break and continue\n    statements. For well-formed programs, this type of actions will\n    never be exposed\n\\<close>\n  datatype brk_ctd = AIBreak | AIContinue\n\n  text \\<open>\n    The control flow graph is a graph over commands, labeled with actions\n\\<close>\n  inductive cfg :: \"cmd \\<Rightarrow> (action + brk_ctd) \\<Rightarrow> cmd \\<Rightarrow> bool\" where\n    Ass: \"cfg (Assign c x e) (Inl (AAssign c x e)) Skip\"\n  | Assl: \"cfg (Assign_local c x e) (Inl (AAssign_local c x e)) Skip\"\n  | Assg: \"cfg (Assign_global c x e) (Inl (AAssign_global c x e)) Skip\"\n  | Test: \"cfg (Test e) (Inl (ATest e)) Skip\"\n\n  | Seq1: \"cfg (Seq Skip c2) (Inl ASkip) c2\"\n  | Seq2': \"\\<lbrakk> cfg c1 e Skip \\<rbrakk> \\<Longrightarrow> cfg (Seq c1 c2) e c2\"\n  | Seq2: \"\\<lbrakk> cfg c1 e c1'; c1'\\<noteq>Skip \\<rbrakk> \\<Longrightarrow> cfg (Seq c1 c2) e (Seq c1' c2)\"\n\n  | Or1: \"cfg c1 e c1' \\<Longrightarrow> cfg (Or c1 c2) e c1'\"\n  | Or2: \"cfg c2 e c2' \\<Longrightarrow> cfg (Or c1 c2) e c2'\"\n\n  | Break: \"cfg (Break) (Inr AIBreak) Invalid\"\n  | Continue: \"cfg (Continue) (Inr AIContinue) Invalid\"\n  \n  | Iterate1: \"cfg (Iterate Skip c) (Inl ASkip) (Iterate c c)\"\n  | Iterate2': \"\\<lbrakk> cfg c (Inl e) Skip \\<rbrakk> \\<Longrightarrow> cfg (Iterate c cb) (Inl e) (Iterate cb cb)\"\n  | Iterate2: \"\\<lbrakk> cfg c (Inl e) c'; c'\\<noteq>Skip \\<rbrakk> \\<Longrightarrow> cfg (Iterate c cb) (Inl e) (Iterate c' cb)\"\n  | IterateBrk: \"\\<lbrakk> cfg c (Inr AIBreak) _  \\<rbrakk> \\<Longrightarrow> cfg (Iterate c cb) (Inl ASkip) Skip\"\n  | IterateCtd: \"\\<lbrakk> cfg c (Inr AIContinue) _  \\<rbrakk> \\<Longrightarrow> cfg (Iterate c cb) (Inl ASkip) (Iterate cb cb)\"\n\n  inductive_cases Seq_cases: \"cfg (Seq c1 c2) e c'\"\n\nsection \\<open>Reachable Nodes\\<close>\n\ninterpretation cfg_lts: LTS cfg .\n\ntext \\<open>Finite set of reachable CFG nodes\\<close>\n\nprimrec reachable_term_order_aux :: \"cmd \\<Rightarrow> nat\" where\n  \"reachable_term_order_aux (Assign c x e) = 0\"\n| \"reachable_term_order_aux (Assign_local c x e) = 0\"\n| \"reachable_term_order_aux (Assign_global c x e) = 0\"\n| \"reachable_term_order_aux (Test e) = 0\"\n| \"reachable_term_order_aux (Skip) = 0\"\n| \"reachable_term_order_aux (Seq c1 c2) = reachable_term_order_aux c1 + reachable_term_order_aux c2\"\n| \"reachable_term_order_aux (Or c1 c2) = reachable_term_order_aux c1 + reachable_term_order_aux c2\"\n| \"reachable_term_order_aux (Break) = 0\"\n| \"reachable_term_order_aux (Continue) = 0\"\n| \"reachable_term_order_aux (Iterate c1 c2) = reachable_term_order_aux c1 + reachable_term_order_aux c2\"\n| \"reachable_term_order_aux Invalid = 0\"\n\nfunction approx_reachable :: \"cmd \\<Rightarrow> cmd set\" where\n  \"approx_reachable (Assign c x e) = {Assign c x e, Skip}\"\n| \"approx_reachable (Assign_local c x e) = {Assign_local c x e, Skip}\"\n| \"approx_reachable (Assign_global c x e) = {Assign_global c x e, Skip}\"\n| \"approx_reachable (Test e) = {Test e, Skip}\"\n| \"approx_reachable (Skip) = {Skip}\"\n| \"approx_reachable (Seq c1 c2) = (approx_reachable c2) \\<union> (do { c1\\<leftarrow>approx_reachable c1; {Seq c1 c2} })\"\n| \"approx_reachable (Or c1 c2) = insert (Or c1 c2) (approx_reachable c1 \\<union> approx_reachable c2)\"\n| \"approx_reachable (Break) = {Break,Invalid}\"\n| \"approx_reachable (Continue) = {Continue,Invalid}\"\n| \"approx_reachable (Iterate c1 c2) = insert Skip\n    (do { c1\\<leftarrow>approx_reachable c1; {Iterate c1 c2} })\n  \\<union> (do { c2'\\<leftarrow>approx_reachable c2; {Iterate c2' c2} })\"\n| \"approx_reachable Invalid = {Invalid}\"\nby pat_completeness auto\n\ntermination\n  apply (relation \"reachable_term_order_aux <*mlex*> measure size\")\n  apply (metis wf_measure wf_mlex)\n  apply (auto simp: mlex_prod_def)\n  done\n\nlemma finite_approx_reachable[simp, intro!]: \"finite (approx_reachable c)\"\n  by (induction c rule: approx_reachable.induct) auto\n\nlemma approx_reachable_refl[simp]: \"c\\<in>approx_reachable c\"\n  by (induction c rule: approx_reachable.induct) auto\n\nlemma approx_reachable_closed:\n  assumes \"c\\<in>approx_reachable c0\"\n  assumes \"cfg c a c'\"\n  shows \"c'\\<in>approx_reachable c0\"\n  using assms\n  apply (induction c0 arbitrary: c c' rule: approx_reachable.induct)\n  apply (auto elim: cfg.cases) [] \n  apply (auto elim: cfg.cases) [] \n  apply (auto elim: cfg.cases) [] \n  apply (auto elim: cfg.cases) [] \n  apply (auto elim: cfg.cases) []\n  apply (auto elim: cfg.cases) []\n  apply (auto, erule cfg.cases, simp_all, force+) []\n  apply (auto elim: cfg.cases) [] \n  apply (auto elim: cfg.cases) [] \n  apply (auto elim: cfg.cases) []\n  apply (auto elim: cfg.cases) [] \n  done\n\nlemma approx_reachable_approx: \"cfg_lts.reachable c c' \\<Longrightarrow> c'\\<in>approx_reachable c\"\n  unfolding cfg_lts.reachable_def\nproof safe\n  fix p\n  assume \"cfg_lts.path c p c'\"\n  thus \"c'\\<in>approx_reachable c\"\n    by (induction p arbitrary: c' rule: rev_induct)\n       (auto intro: approx_reachable_closed)\nqed\n\nlemma finite_cfg_reachable: \"finite (Collect (cfg_lts.reachable c))\"\n  apply (rule finite_subset[OF _ finite_approx_reachable])\n  using approx_reachable_approx by auto\n\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/CAVA_LTL_Modelchecker/SM/RefPoint/SM_Cfg.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926665999540698, "lm_q2_score": 0.4649015713733885, "lm_q1q2_score": 0.2755316336191705}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      ProcParEx.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2007-2008 Norbert Schirmer\nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection \"Examples for Procedures as Parameters using Statespaces\"\ntheory ProcParExSP imports \"../Vcg\" begin\n\n\n\n\n\n\n\nlemma conseq_exploit_pre':\n             \"\\<lbrakk>\\<forall>s \\<in> S. \\<Gamma>,\\<Theta> \\<turnstile> ({s} \\<inter> P) c Q,A\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile> (P \\<inter> S)c Q,A\"\n  apply (rule HoarePartialDef.Conseq)\n  apply clarify\n  by (metis IntI insertI1 subset_refl)\n\nlemma conseq_exploit_pre'':\n             \"\\<lbrakk>\\<forall>Z. \\<forall>s \\<in> S Z.  \\<Gamma>,\\<Theta> \\<turnstile> ({s} \\<inter> P Z) c (Q Z),(A Z)\\<rbrakk>\n              \\<Longrightarrow>\n              \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile> (P Z \\<inter> S Z)c (Q Z),(A Z)\"\n  apply (rule allI)\n  apply (rule conseq_exploit_pre')\n  apply blast\n  done\n\nlemma conseq_exploit_pre''':\n             \"\\<lbrakk>\\<forall>s \\<in> S. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile> ({s} \\<inter> P Z) c (Q Z),(A Z)\\<rbrakk>\n              \\<Longrightarrow>\n              \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile> (P Z \\<inter> S)c (Q Z),(A Z)\"\n  apply (rule allI)\n  apply (rule conseq_exploit_pre')\n  apply blast\n  done\n\n\nprocedures compare(i::nat,j::nat|r::bool) \"NoBody\"\n\n\nprint_locale! compare_signature\n\n\ncontext compare_impl\nbegin\ndeclare [[hoare_use_call_tr' = false]]\nterm \"\\<acute>r :== CALL compare(\\<acute>i,\\<acute>j)\"\ndeclare [[hoare_use_call_tr' = true]]\nend\n\n\n(* FIXME: typing issue with modifies locale*)\nprocedures\n  LEQ (i::nat,j::nat | r::bool) \"\\<acute>r :== \\<acute>i \\<le> \\<acute>j\"\n  LEQ_spec: \"\\<forall>\\<sigma>. \\<Gamma>\\<turnstile> {\\<sigma>}  PROC LEQ(\\<acute>i,\\<acute>j,\\<acute>r) \\<lbrace>\\<acute>r = (\\<^bsup>\\<sigma>\\<^esup>i \\<le> \\<^bsup>\\<sigma>\\<^esup>j)\\<rbrace>\"\n\n  LEQ_modifies: \"\\<forall>\\<sigma>. \\<Gamma>\\<turnstile> {\\<sigma>} PROC LEQ(\\<acute>i,\\<acute>j,\\<acute>r) {t. t may_only_modify_globals \\<sigma> in []}\"\n\n\n\ndefinition mx:: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool) \\<Rightarrow> 'a \\<Rightarrow> 'a \\<Rightarrow> 'a\"\n  where \"mx leq a b = (if leq a b then a else b)\"\n\nprocedures (imports compare_signature)\n  Max (compare::string, n::nat, m::nat | k::nat)\n  where b::bool\n  in\n  \"\\<acute>b :== DYNCALL \\<acute>compare(\\<acute>n,\\<acute>m);;\n   IF \\<acute>b THEN \\<acute>k :== \\<acute>n ELSE \\<acute>k :== \\<acute>m FI\"\n\n  Max_spec: \"\\<And>leq. \\<forall>\\<sigma>. \\<Gamma>\\<turnstile>\n  ({\\<sigma>} \\<inter> {s. (\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<^bsup>s\\<^esup>compare(\\<acute>i,\\<acute>j) \\<lbrace>\\<acute>r = (leq \\<^bsup>\\<tau>\\<^esup>i \\<^bsup>\\<tau>\\<^esup>j)\\<rbrace>) \\<and>\n              (\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<^bsup>s\\<^esup>compare(\\<acute>i,\\<acute>j) {t. t may_only_modify_globals \\<tau> in []})})\n    PROC Max(\\<acute>compare,\\<acute>n,\\<acute>m,\\<acute>k)\n  \\<lbrace>\\<acute>k = mx leq \\<^bsup>\\<sigma>\\<^esup>n \\<^bsup>\\<sigma>\\<^esup>m\\<rbrace>\"\n\ncontext Max_spec\nbegin\nthm Max_spec\nend\ncontext Max_impl\nbegin\nterm \"\\<acute>b :== DYNCALL \\<acute>compare(\\<acute>n,\\<acute>m)\"\ndeclare [[hoare_use_call_tr' = false]]\nterm \"\\<acute>b :== DYNCALL \\<acute>compare(\\<acute>n,\\<acute>m)\"\ndeclare [[hoare_use_call_tr' = true]]\nend\n\n\n\nlemma (in Max_impl ) Max_spec1:\nshows\n\"\\<forall>\\<sigma> leq. \\<Gamma>\\<turnstile>\n  ({\\<sigma>} \\<inter> \\<lbrace> (\\<forall>\\<tau>. \\<Gamma>\\<turnstile>{\\<tau>} \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) \\<lbrace>\\<acute>r = (leq \\<^bsup>\\<tau>\\<^esup>i \\<^bsup>\\<tau>\\<^esup>j)\\<rbrace>) \\<and>\n      (\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) {t. t may_only_modify_globals \\<tau> in []})\\<rbrace>)\n    \\<acute>k :== PROC Max(\\<acute>compare,\\<acute>n,\\<acute>m)\n  \\<lbrace>\\<acute>k = mx leq \\<^bsup>\\<sigma>\\<^esup>n \\<^bsup>\\<sigma>\\<^esup>m\\<rbrace>\"\napply (hoare_rule HoarePartial.ProcNoRec1)\napply (intro allI)\napply (rule conseq_exploit_pre')\napply (rule)\napply clarify\nproof -\n  fix \\<sigma>:: \"('a, 'b, 'c, 'd) stateSP_scheme\" and s::\"('a, 'b, 'c, 'd) stateSP_scheme\" and leq\n   assume compare_spec:\n       \"\\<forall>\\<tau>. \\<Gamma>\\<turnstile>{\\<tau>} \\<acute>r :== PROC \\<^bsup>s\\<^esup>compare(\\<acute>i,\\<acute>j) \\<lbrace>\\<acute>r = leq \\<^bsup>\\<tau>\\<^esup>i \\<^bsup>\\<tau>\\<^esup>j\\<rbrace>\"\n\n  assume compare_modifies:\n        \"\\<forall>\\<tau>. \\<Gamma>\\<turnstile>{\\<tau>} \\<acute>r :== PROC \\<^bsup>s\\<^esup>compare(\\<acute>i,\\<acute>j)\n                {t. t may_only_modify_globals \\<tau> in []}\"\n\n   show \"\\<Gamma>\\<turnstile>({s} \\<inter> {\\<sigma>})\n            \\<acute>b :== DYNCALL \\<acute>compare (\\<acute>n,\\<acute>m);;\n            IF \\<acute>b THEN \\<acute>k :== \\<acute>n ELSE \\<acute>k :== \\<acute>m FI\n            \\<lbrace>\\<acute>k = mx leq \\<^bsup>\\<sigma>\\<^esup>n \\<^bsup>\\<sigma>\\<^esup>m\\<rbrace>\"\n     apply vcg\n     apply (clarsimp simp add: mx_def)\n     done\n qed\n\n\nlemma (in Max_impl) Max_spec2:\nshows\n\"\\<forall>\\<sigma> leq. \\<Gamma>\\<turnstile>\n  ({\\<sigma>} \\<inter> \\<lbrace>(\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) \\<lbrace>\\<acute>r = (leq \\<^bsup>\\<tau>\\<^esup>i \\<^bsup>\\<tau>\\<^esup>j)\\<rbrace>) \\<and>\n      (\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) {t. t may_only_modify_globals \\<tau> in []})\\<rbrace>)\n    \\<acute>k :== PROC Max(\\<acute>compare,\\<acute>n,\\<acute>m)\n  \\<lbrace>\\<acute>k = mx leq \\<^bsup>\\<sigma>\\<^esup>n \\<^bsup>\\<sigma>\\<^esup>m\\<rbrace>\"\napply (hoare_rule HoarePartial.ProcNoRec1)\napply (intro allI)\napply (rule conseq_exploit_pre')\napply (rule)\napply clarify\napply vcg\napply (clarsimp simp add: mx_def)\ndone\n\nlemma (in Max_impl) Max_spec3:\nshows\n\"\\<forall>n m leq. \\<Gamma>\\<turnstile>\n  (\\<lbrace>\\<acute>n=n \\<and> \\<acute>m=m\\<rbrace>  \\<inter>\n   \\<lbrace>(\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) \\<lbrace>\\<acute>r = (leq \\<^bsup>\\<tau>\\<^esup>i \\<^bsup>\\<tau>\\<^esup>j)\\<rbrace>) \\<and>\n     (\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) {t. t may_only_modify_globals \\<tau> in []})\\<rbrace>)\n    \\<acute>k :== PROC Max(\\<acute>compare,\\<acute>n,\\<acute>m)\n  \\<lbrace>\\<acute>k = mx leq n m\\<rbrace>\"\napply (hoare_rule HoarePartial.ProcNoRec1)\napply (intro allI)\napply (rule conseq_exploit_pre')\napply (rule)\napply clarify\napply vcg\napply (clarsimp simp add: mx_def)\ndone\n\n\n\nprint_locale Max_spec\n\n(* We have to rename the parameters of the compare procedure to match the LEQ procedure *)\nlocale Max_test = Max_spec where\n        i_'compare_' = i_'LEQ_' and\n        j_'compare_' = j_'LEQ_' and\n        r_'compare_' = r_'LEQ_'\n       + LEQ_spec + LEQ_modifies\n\nlemma (in Max_test)\n  shows\n  \"\\<Gamma>\\<turnstile> {\\<sigma>} \\<acute>k :== CALL Max(LEQ_'proc,\\<acute>n,\\<acute>m) \\<lbrace>\\<acute>k = mx (\\<le>) \\<^bsup>\\<sigma>\\<^esup>n \\<^bsup>\\<sigma>\\<^esup>m\\<rbrace>\"\nproof -\n  note Max_spec = Max_spec [where leq=\"(\\<le>)\"]\n  show ?thesis\n    apply vcg\n    apply (clarsimp)\n    apply (rule conjI)\n    apply (rule LEQ_spec)\n    apply (rule LEQ_modifies)\n    done\nqed\n\n\n\n\n\n\nlemma (in Max_impl) Max_spec5:\nshows\n\"\\<forall>n m leq. \\<Gamma>\\<turnstile>\n  (\\<lbrace>\\<acute>n=n \\<and> \\<acute>m=m\\<rbrace> \\<inter> \\<lbrace>\\<forall>n' m'. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>i=n' \\<and> \\<acute>j=m'\\<rbrace> \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) \\<lbrace>\\<acute>r = (leq n' m')\\<rbrace>\\<rbrace>)\n    \\<acute>k :== PROC Max(\\<acute>compare,\\<acute>n,\\<acute>m)\n  \\<lbrace>\\<acute>k = mx leq n m\\<rbrace>\"\napply (hoare_rule HoarePartial.ProcNoRec1)\napply (intro allI)\napply (rule conseq_exploit_pre')\napply (rule)\napply clarify\napply vcg\napply clarsimp\napply (clarsimp simp add: mx_def)\ndone\n\nlemma (in LEQ_impl)\n LEQ_spec: \"\\<forall>n m. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>i=n \\<and> \\<acute>j=m\\<rbrace>  PROC LEQ(\\<acute>i,\\<acute>j,\\<acute>r) \\<lbrace>\\<acute>r = (n \\<le> m)\\<rbrace>\"\n  apply vcg\n  apply simp\n  done\n\n\nprint_locale Max_impl\nlocale Max_test' = Max_impl where\n        i_'compare_' = i_'LEQ_' and\n        j_'compare_' = j_'LEQ_' and\n        r_'compare_' = r_'LEQ_'\n        + LEQ_impl\nlemma (in Max_test')\n  shows\n  \"\\<forall>n m. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>n=n \\<and> \\<acute>m=m\\<rbrace> \\<acute>k :== CALL Max(LEQ_'proc,\\<acute>n,\\<acute>m) \\<lbrace>\\<acute>k = mx (\\<le>) n m\\<rbrace>\"\nproof -\n  note Max_spec = Max_spec5\n  show ?thesis\n    apply vcg\n    apply (rule_tac x=\"(\\<le>)\" in exI)\n    apply clarsimp\n    apply (rule LEQ_spec [rule_format])\n    done\nqed\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/c-parser/Simpl/ex/ProcParExSP.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5467381667555714, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.2755047358918898}}
{"text": "section \\<open>\\isaheader{Specification of Sequences}\\<close>\ntheory ListSpec \nimports ICF_Spec_Base\nbegin\n\n(*@intf List\n  @abstype 'a list\n  This interface specifies sequences.\n*)\n\nsubsection \"Definition\"\nlocale list =\n  \\<comment> \\<open>Abstraction to HOL-lists\\<close>\n  fixes \\<alpha> :: \"'s \\<Rightarrow> 'x list\"\n  \\<comment> \\<open>Invariant\\<close>\n  fixes invar :: \"'s \\<Rightarrow> bool\"\n\nlocale list_no_invar = list +\n  assumes invar[simp, intro!]: \"\\<And>l. invar l\"\n\nsubsection \"Functions\"\n\nlocale list_empty = list +\n  constrains \\<alpha> :: \"'s \\<Rightarrow> 'x list\"\n  fixes empty :: \"unit \\<Rightarrow> 's\"\n  assumes empty_correct:\n    \"\\<alpha> (empty ()) = []\"\n    \"invar (empty ())\"\n\n\nlocale list_isEmpty = list +\n  constrains \\<alpha> :: \"'s \\<Rightarrow> 'x list\"\n  fixes isEmpty :: \"'s \\<Rightarrow> bool\"\n  assumes isEmpty_correct:\n    \"invar s \\<Longrightarrow> isEmpty s \\<longleftrightarrow> \\<alpha> s = []\"\n\nlocale poly_list_iteratei = list +\n  constrains \\<alpha> :: \"'s \\<Rightarrow> 'x list\"\nbegin  \n  definition iteratei where\n    iteratei_correct[code_unfold]: \"iteratei s \\<equiv> foldli (\\<alpha> s)\"\n  definition iterate where\n    iterate_correct[code_unfold]: \"iterate s \\<equiv> foldli (\\<alpha> s) (\\<lambda>_. True)\"\nend\n\nlocale poly_list_rev_iteratei = list +\n  constrains \\<alpha> :: \"'s \\<Rightarrow> 'x list\"\nbegin  \n  definition rev_iteratei where\n    rev_iteratei_correct[code_unfold]: \"rev_iteratei s \\<equiv> foldri (\\<alpha> s)\"\n  definition rev_iterate where\n    rev_iterate_correct[code_unfold]: \"rev_iterate s \\<equiv> foldri (\\<alpha> s) (\\<lambda>_. True)\"\nend\n\n(*\nlocale list_iteratei = list +\n  constrains \\<alpha> :: \"'s \\<Rightarrow> 'x list\"\n  fixes iteratei :: \"'s \\<Rightarrow> ('x,'\\<sigma>) set_iterator\"\n  assumes iteratei_correct:\n    \"invar s \\<Longrightarrow> iteratei s = foldli (\\<alpha> s)\"\nbegin\n  lemma iteratei_no_sel_rule:\n    \"invar s \\<Longrightarrow> distinct (\\<alpha> s) \\<Longrightarrow> set_iterator (iteratei s) (set (\\<alpha> s))\"\n    by (simp add: iteratei_correct set_iterator_foldli_correct)\nend\n\nlemma list_iteratei_iteratei_linord_rule:\n  \"list_iteratei \\<alpha> invar iteratei \\<Longrightarrow> invar s \\<Longrightarrow> distinct (\\<alpha> s) \\<Longrightarrow> sorted (\\<alpha> s) \\<Longrightarrow>\n   set_iterator_linord (iteratei s) (set (\\<alpha> s))\"\n  by (simp add: list_iteratei_def set_iterator_linord_foldli_correct)\n\nlemma list_iteratei_iteratei_rev_linord_rule:\n  \"list_iteratei \\<alpha> invar iteratei \\<Longrightarrow> invar s \\<Longrightarrow> distinct (\\<alpha> s) \\<Longrightarrow> sorted (rev (\\<alpha> s)) \\<Longrightarrow>\n   set_iterator_rev_linord (iteratei s) (set (\\<alpha> s))\"\n  by (simp add: list_iteratei_def set_iterator_rev_linord_foldli_correct)\n\n\nlocale list_reverse_iteratei = list +\n  constrains \\<alpha> :: \"'s \\<Rightarrow> 'x list\"\n  fixes reverse_iteratei :: \"'s \\<Rightarrow> ('x,'\\<sigma>) set_iterator\"\n  assumes reverse_iteratei_correct:\n    \"invar s \\<Longrightarrow> reverse_iteratei s = foldri (\\<alpha> s)\"\nbegin\n  lemma reverse_iteratei_no_sel_rule:\n    \"invar s \\<Longrightarrow> distinct (\\<alpha> s) \\<Longrightarrow> set_iterator (reverse_iteratei s) (set (\\<alpha> s))\"\n    by (simp add: reverse_iteratei_correct set_iterator_foldri_correct)\nend\n\nlemma list_reverse_iteratei_iteratei_linord_rule:\n  \"list_reverse_iteratei \\<alpha> invar iteratei \\<Longrightarrow> invar s \\<Longrightarrow> distinct (\\<alpha> s) \\<Longrightarrow> sorted (rev (\\<alpha> s)) \\<Longrightarrow>\n   set_iterator_linord (iteratei s) (set (\\<alpha> s))\"\n  by (simp add: list_reverse_iteratei_def set_iterator_linord_foldri_correct)\n\nlemma list_reverse_iteratei_iteratei_rev_linord_rule:\n  \"list_reverse_iteratei \\<alpha> invar iteratei \\<Longrightarrow> invar s \\<Longrightarrow> distinct (\\<alpha> s) \\<Longrightarrow> sorted (\\<alpha> s) \\<Longrightarrow>\n   set_iterator_rev_linord (iteratei s) (set (\\<alpha> s))\"\n  by (simp add: list_reverse_iteratei_def set_iterator_rev_linord_foldri_correct)\n*)\n\nlocale list_size = list +\n  constrains \\<alpha> :: \"'s \\<Rightarrow> 'x list\"\n  fixes size :: \"'s \\<Rightarrow> nat\"\n  assumes size_correct:\n    \"invar s \\<Longrightarrow> size s = length (\\<alpha> s)\"\n  \nlocale list_appendl = list +\n  constrains \\<alpha> :: \"'s \\<Rightarrow> 'x list\"\n  fixes appendl :: \"'x \\<Rightarrow> 's \\<Rightarrow> 's\"\n  assumes appendl_correct:\n    \"invar s \\<Longrightarrow> \\<alpha> (appendl x s) = x#\\<alpha> s\"\n    \"invar s \\<Longrightarrow> invar (appendl x s)\"\nbegin\n  abbreviation (input) \"push \\<equiv> appendl\" \n  lemmas push_correct = appendl_correct\nend\n\nlocale list_removel = list +\n  constrains \\<alpha> :: \"'s \\<Rightarrow> 'x list\"\n  fixes removel :: \"'s \\<Rightarrow> ('x \\<times> 's)\"\n  assumes removel_correct:\n    \"\\<lbrakk>invar s; \\<alpha> s \\<noteq> []\\<rbrakk> \\<Longrightarrow> fst (removel s) = hd (\\<alpha> s)\"\n    \"\\<lbrakk>invar s; \\<alpha> s \\<noteq> []\\<rbrakk> \\<Longrightarrow> \\<alpha> (snd (removel s)) = tl (\\<alpha> s)\"\n    \"\\<lbrakk>invar s; \\<alpha> s \\<noteq> []\\<rbrakk> \\<Longrightarrow> invar (snd (removel s))\"\nbegin\n  lemma removelE: \n    assumes I: \"invar s\" \"\\<alpha> s \\<noteq> []\" \n    obtains s' where \"removel s = (hd (\\<alpha> s), s')\" \"invar s'\" \"\\<alpha> s' = tl (\\<alpha> s)\"\n  proof -\n    from removel_correct(1,2,3)[OF I] have \n      C: \"fst (removel s) = hd (\\<alpha> s)\"\n         \"\\<alpha> (snd (removel s)) = tl (\\<alpha> s)\"\n         \"invar (snd (removel s))\" .\n    from that[of \"snd (removel s)\", OF _ C(3,2), folded C(1)] show thesis\n      by simp\n  qed\n\n\n  text \\<open>The following shortcut notations are not meant for generating efficient code,\n    but solely to simplify reasoning\\<close>\n  (* TODO: Is this actually used somewhere ? *)\n  (*\n  definition \"head s == fst (removef s)\"\n  definition \"tail s == snd (removef s)\"\n\n  lemma tail_correct: \"\\<lbrakk>invar F; \\<alpha> F \\<noteq> []\\<rbrakk> \\<Longrightarrow> \\<alpha> (tail F) = tl (\\<alpha> F)\"\n    by (simp add: tail_def removef_correct)\n\n  \n\n  lemma removef_split: \"removef F = (head F, tail F)\"\n    apply (cases \"removef F\")\n    apply (simp add: head_def tail_def)\n    done\n    *)\n      \n  abbreviation (input) \"pop \\<equiv> removel\"\n  lemmas pop_correct = removel_correct\n\n  abbreviation (input) \"dequeue \\<equiv> removel\"\n  lemmas dequeue_correct = removel_correct\nend\n\nlocale list_leftmost = list +\n  constrains \\<alpha> :: \"'s \\<Rightarrow> 'x list\"\n  fixes leftmost :: \"'s \\<Rightarrow> 'x\"\n  assumes leftmost_correct:\n    \"\\<lbrakk>invar s; \\<alpha> s \\<noteq> []\\<rbrakk> \\<Longrightarrow> leftmost s = hd (\\<alpha> s)\"\nbegin\n  abbreviation (input) top where \"top \\<equiv> leftmost\"\n  lemmas top_correct = leftmost_correct\nend\n\nlocale list_appendr = list +\n  constrains \\<alpha> :: \"'s \\<Rightarrow> 'x list\"\n  fixes appendr :: \"'x \\<Rightarrow> 's \\<Rightarrow> 's\"\n  assumes appendr_correct: \n    \"invar s \\<Longrightarrow> \\<alpha> (appendr x s) = \\<alpha> s @ [x]\"\n    \"invar s \\<Longrightarrow> invar (appendr x s)\"\nbegin\n  abbreviation (input) \"enqueue \\<equiv> appendr\"\n  lemmas enqueue_correct = appendr_correct\nend\n\nlocale list_remover = list +\n  constrains \\<alpha> :: \"'s \\<Rightarrow> 'x list\"\n  fixes remover :: \"'s \\<Rightarrow> 's \\<times> 'x\"\n  assumes remover_correct: \n    \"\\<lbrakk>invar s; \\<alpha> s \\<noteq> []\\<rbrakk> \\<Longrightarrow> \\<alpha> (fst (remover s)) = butlast (\\<alpha> s)\"\n    \"\\<lbrakk>invar s; \\<alpha> s \\<noteq> []\\<rbrakk> \\<Longrightarrow> snd (remover s) = last (\\<alpha> s)\"\n    \"\\<lbrakk>invar s; \\<alpha> s \\<noteq> []\\<rbrakk> \\<Longrightarrow> invar (fst (remover s))\"\n\nlocale list_rightmost = list +\n  constrains \\<alpha> :: \"'s \\<Rightarrow> 'x list\"\n  fixes rightmost :: \"'s \\<Rightarrow> 'x\"\n  assumes rightmost_correct:\n    \"\\<lbrakk>invar s; \\<alpha> s \\<noteq> []\\<rbrakk> \\<Longrightarrow> rightmost s = List.last (\\<alpha> s)\"\nbegin\n  abbreviation (input) bot where \"bot \\<equiv> rightmost\"\n  lemmas bot_correct = rightmost_correct\nend\n\nsubsubsection \"Indexing\"\nlocale list_get = list +\n  constrains \\<alpha> :: \"'s \\<Rightarrow> 'x list\"\n  fixes get :: \"'s \\<Rightarrow> nat \\<Rightarrow> 'x\"\n  assumes get_correct:\n    \"\\<lbrakk>invar s; i<length (\\<alpha> s)\\<rbrakk> \\<Longrightarrow> get s i = \\<alpha> s ! i\"\n\nlocale list_set = list +\n  constrains \\<alpha> :: \"'s \\<Rightarrow> 'x list\"\n  fixes set :: \"'s \\<Rightarrow> nat \\<Rightarrow> 'x \\<Rightarrow> 's\"\n  assumes set_correct:\n    \"\\<lbrakk>invar s; i<length (\\<alpha> s)\\<rbrakk> \\<Longrightarrow> \\<alpha> (set s i x) = (\\<alpha> s) [i := x]\"\n    \"\\<lbrakk>invar s; i<length (\\<alpha> s)\\<rbrakk> \\<Longrightarrow> invar (set s i x)\"\n\nrecord ('a,'s) list_ops = \n  list_op_\\<alpha> :: \"'s \\<Rightarrow> 'a list\"\n  list_op_invar :: \"'s \\<Rightarrow> bool\"\n  list_op_empty :: \"unit \\<Rightarrow> 's\"\n  list_op_isEmpty :: \"'s \\<Rightarrow> bool\"\n  list_op_size :: \"'s \\<Rightarrow> nat\"\n  list_op_appendl :: \"'a \\<Rightarrow> 's \\<Rightarrow> 's\"\n  list_op_removel :: \"'s \\<Rightarrow> 'a \\<times> 's\"\n  list_op_leftmost :: \"'s \\<Rightarrow> 'a\"\n  list_op_appendr :: \"'a \\<Rightarrow> 's \\<Rightarrow> 's\"\n  list_op_remover :: \"'s \\<Rightarrow> 's \\<times> 'a\"\n  list_op_rightmost :: \"'s \\<Rightarrow> 'a\"\n  list_op_get :: \"'s \\<Rightarrow> nat \\<Rightarrow> 'a\"\n  list_op_set :: \"'s \\<Rightarrow> nat \\<Rightarrow> 'a \\<Rightarrow> 's\"\n\nlocale StdListDefs = \n  poly_list_iteratei \"list_op_\\<alpha> ops\" \"list_op_invar ops\"\n  + poly_list_rev_iteratei \"list_op_\\<alpha> ops\" \"list_op_invar ops\"\n  for ops :: \"('a,'s,'more) list_ops_scheme\"\nbegin\n  abbreviation \\<alpha> where \"\\<alpha> \\<equiv> list_op_\\<alpha> ops\"\n  abbreviation invar where \"invar \\<equiv> list_op_invar ops\"\n  abbreviation empty where \"empty \\<equiv> list_op_empty ops\"\n  abbreviation isEmpty where \"isEmpty \\<equiv> list_op_isEmpty ops\"\n  abbreviation size where \"size \\<equiv> list_op_size ops\"\n  abbreviation appendl where \"appendl \\<equiv> list_op_appendl ops\"\n  abbreviation removel where \"removel \\<equiv> list_op_removel ops\"\n  abbreviation leftmost where \"leftmost \\<equiv> list_op_leftmost ops\"\n  abbreviation appendr where \"appendr \\<equiv> list_op_appendr ops\"\n  abbreviation remover where \"remover \\<equiv> list_op_remover ops\"\n  abbreviation rightmost where \"rightmost \\<equiv> list_op_rightmost ops\"\n  abbreviation get where \"get \\<equiv> list_op_get ops\"\n  abbreviation set where \"set \\<equiv> list_op_set ops\"\nend\n\nlocale StdList = StdListDefs ops\n  + list \\<alpha> invar\n  + list_empty \\<alpha> invar empty \n  + list_isEmpty \\<alpha> invar isEmpty \n  + list_size \\<alpha> invar size \n  + list_appendl \\<alpha> invar appendl \n  + list_removel \\<alpha> invar removel \n  + list_leftmost \\<alpha> invar leftmost \n  + list_appendr \\<alpha> invar appendr \n  + list_remover \\<alpha> invar remover \n  + list_rightmost \\<alpha> invar rightmost \n  + list_get \\<alpha> invar get \n  + list_set \\<alpha> invar set \n  for ops :: \"('a,'s,'more) list_ops_scheme\"\nbegin\n  lemmas correct = \n    empty_correct\n    isEmpty_correct\n    size_correct\n    appendl_correct\n    removel_correct\n    leftmost_correct\n    appendr_correct\n    remover_correct\n    rightmost_correct\n    get_correct\n    set_correct\n\nend\n\nlocale StdList_no_invar = StdList + list_no_invar \\<alpha> invar\n    \nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Evaluation/Collections/ICF/spec/ListSpec.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5467381667555714, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.2755047358918898}}
{"text": "(*  Title:       Isabelle Collections Library\n    Author:      Peter Lammich <peter dot lammich at uni-muenster.de>\n    Maintainer:  Peter Lammich <peter dot lammich at uni-muenster.de>\n*)\nheader {* \\isaheader{Map Implementation by Associative Lists} *}\ntheory ListMapImpl\nimports \n  \"../spec/MapSpec\" \n  \"../../Lib/Assoc_List\" \n  \"../gen_algo/MapGA\"\nbegin\ntext_raw {*\\label{thy:ListMapImpl}*}\n\n(*@impl Map\n  @type 'a lm\n  @abbrv lm,l\n  Maps implemented by associative lists. If you need efficient \n  @{text \"insert_dj\"} operation, you should use list sets with explicit \n  invariants (lmi).\n*)\n\ntype_synonym ('k,'v) lm = \"('k,'v) assoc_list\"\n\ndefinition [icf_rec_def]: \"lm_basic_ops \\<equiv> \\<lparr>\n  bmap_op_\\<alpha> = Assoc_List.lookup,\n  bmap_op_invar = \\<lambda>_. True,\n  bmap_op_empty = (\\<lambda>_::unit. Assoc_List.empty),\n  bmap_op_lookup = (\\<lambda>k m. Assoc_List.lookup m k),\n  bmap_op_update = Assoc_List.update,\n  bmap_op_update_dj = Assoc_List.update,\n  bmap_op_delete = Assoc_List.delete,\n  bmap_op_list_it = Assoc_List.iteratei\n\\<rparr>\"\n\nsetup Locale_Code.open_block\ninterpretation lm_basic!: StdBasicMapDefs lm_basic_ops .\ninterpretation lm_basic!: StdBasicMap lm_basic_ops\n  apply unfold_locales\n  apply (simp_all add: icf_rec_unf \n    Assoc_List.lookup_empty' Assoc_List.iteratei_correct)\n  done\nsetup Locale_Code.close_block\n\ndefinition [icf_rec_def]: \"lm_ops \\<equiv> lm_basic.dflt_ops\"\nsetup Locale_Code.open_block\ninterpretation lm!: StdMapDefs lm_ops .\ninterpretation lm!: StdMap lm_ops \n  unfolding lm_ops_def\n  by (rule lm_basic.dflt_ops_impl)\ninterpretation lm!: StdMap_no_invar lm_ops \n  by unfold_locales (simp add: icf_rec_unf)\nsetup Locale_Code.close_block\n\nsetup {* ICF_Tools.revert_abbrevs \"lm\"*}\n\nlemma pi_lm[proper_it]: \n  \"proper_it' Assoc_List.iteratei Assoc_List.iteratei\"\n  unfolding Assoc_List.iteratei_def[abs_def]\n  by (intro icf_proper_iteratorI proper_it'I)\n\ninterpretation pi_lm: proper_it_loc Assoc_List.iteratei Assoc_List.iteratei\n  apply unfold_locales\n  apply (rule pi_lm)\n  done\n\nlemma pi_lm'[proper_it]: \n  \"proper_it' lm.iteratei lm.iteratei\"\n  unfolding lm.iteratei_def[abs_def]\n  by (intro icf_proper_iteratorI proper_it'I)\n\ninterpretation pi_lm': proper_it_loc lm.iteratei lm.iteratei\n  apply unfold_locales\n  apply (rule pi_lm')\n  done\n\n\ntext {* Code generator test *}\ndefinition \"test_codegen \\<equiv> (\n  lm.add ,\n  lm.add_dj ,\n  lm.ball ,\n  lm.bex ,\n  lm.delete ,\n  lm.empty ,\n  lm.isEmpty ,\n  lm.isSng ,\n  lm.iterate ,\n  lm.iteratei ,\n  lm.list_it ,\n  lm.lookup ,\n  lm.restrict ,\n  lm.sel ,\n  lm.size ,\n  lm.size_abort ,\n  lm.sng ,\n  lm.to_list ,\n  lm.to_map ,\n  lm.update ,\n  lm.update_dj)\"\n\nexport_code test_codegen in SML\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Collections/ICF/impl/ListMapImpl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.546738151984614, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.2755047284487132}}
{"text": "section \"Invariant Context Simplifications\"\ntheory invContext_simps\nimports repliss_sem\nbegin\n\n\ntext \"Here we prove various simplifications for the invariant contexts.\"\n\n\nlemma invContext_unchanged_happensBefore:\n  assumes \"co c \\<triangleq> t\" and \"ts t \\<triangleq> Uncommitted\"\n  shows \"invContextH co to ts (hbOld \\<union> vis \\<times> {c}) cs ki io ir \n    = invContextH co to ts hbOld cs ki io ir \"\n  using assms by (auto simp add: invContextH_def restrict_relation_def committedCallsH_def isCommittedH_def)\n\nlemma invContext_unchanged_happensBefore2:\n  assumes \"co c = None\"\n  shows \"invContextH co to ts (hbOld \\<union> vis \\<times> {c}) cs ki io ir  \n    = invContextH co to ts hbOld cs ki io ir  \"\n  using assms by (auto simp add: invContextH_def restrict_relation_def committedCallsH_def isCommittedH_def)\n\nlemma committedCallsH_notin:\n  assumes \"co c = None\"\n  shows \"c \\<notin> committedCallsH co ts\"\n  by (simp add: assms committedCallsH_def isCommittedH_def)\n\nlemma committedCallsH_in:\n  shows \"(c \\<in> committedCallsH co ts) \\<longleftrightarrow> (case co c of None \\<Rightarrow> False | Some t \\<Rightarrow> ts t \\<triangleq> Committed) \"\n  by (auto simp add: committedCallsH_def isCommittedH_def split: option.splits)\n\n\n\nlemma committedCalls_unchanged_callOrigin:\n  assumes a1: \"ts t \\<triangleq> Uncommitted\"\n    and a2: \"co c = None\"\n  shows \"committedCallsH (co(c \\<mapsto> t)) ts = committedCallsH co ts\"\n  using a1 a2 by (auto simp add: committedCallsH_def isCommittedH_def)\n\nlemma invContextH_map_update_all:\n  assumes \"co c = None\" and \"ts t \\<triangleq> Uncommitted\"\n  shows \"invContextH (co(c \\<mapsto> t)) to ts hb cs ki io ir   =\n       invContextH co to ts hb cs ki io ir  \"\n  using assms by (auto simp add: invContextH_def committedCallsH_notin committedCalls_unchanged_callOrigin)\n\n\n\nlemma invContextH_update_calls:\n  assumes \"co c \\<triangleq> t\" and \"ts t \\<triangleq> Uncommitted\"\n  shows \"invContextH co to ts hb (cs(c \\<mapsto> newCall)) ki io ir   =\n       invContextH co to ts hb cs ki io ir  \"\n  using assms by (auto simp add: invContextH_def committedCallsH_in)\n\n\n\nlemma committedCallsH_update_uncommitted:\n  assumes \"ts t = None\"\n  shows \"committedCallsH co (ts(t \\<mapsto> Uncommitted))\n     = committedCallsH co ts\"\n  using assms by (auto simp add: committedCallsH_def isCommittedH_def, force)\n\n\nlemma invContextH_update_txstatus:\n  assumes \"ts t = None\" \n  shows \"invContextH co to (ts(t\\<mapsto>Uncommitted)) hb cs ki io ir  =\n       invContextH co to ts hb cs ki io ir \"\n  using assms by (auto simp add: invContextH_def restrict_map_def committedCallsH_update_uncommitted)\n\nlemmas invContextH_simps = invContextH_update_calls invContextH_map_update_all invContextH_update_txstatus\n\n\n\nend", "meta": {"author": "peterzeller", "repo": "repliss-isabelle", "sha": "f43744678cc9c5a4684e8bd0e9c83510bae1d9a4", "save_path": "github-repos/isabelle/peterzeller-repliss-isabelle", "path": "github-repos/isabelle/peterzeller-repliss-isabelle/repliss-isabelle-f43744678cc9c5a4684e8bd0e9c83510bae1d9a4/invContext_simps.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5544704796847396, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.27506938359538013}}
{"text": "subsection \\<open>Stuttering\\<close>\n\ntheory Stuttering\n  imports\n    Semantics.IRStepThms\nbegin\n\ninductive stutter:: \"IRGraph \\<Rightarrow> MapState \\<Rightarrow> Params \\<Rightarrow> FieldRefHeap \\<Rightarrow> ID \\<Rightarrow> ID \\<Rightarrow> bool\" (\"_ _ _ _ \\<turnstile> _ \\<leadsto> _\" 55)\n  for g m p h where\n\n  StutterStep:\n  \"\\<lbrakk>g, p \\<turnstile> (nid,m,h) \\<rightarrow> (nid',m,h)\\<rbrakk>\n   \\<Longrightarrow> g m p h \\<turnstile> nid \\<leadsto> nid'\" |\n\n  Transitive:\n  \"\\<lbrakk>g, p \\<turnstile> (nid,m,h) \\<rightarrow> (nid'',m,h);\n    g m p h \\<turnstile> nid'' \\<leadsto> nid'\\<rbrakk>\n   \\<Longrightarrow> g m p h \\<turnstile> nid \\<leadsto> nid'\"\n\nlemma stuttering_successor:\n  assumes \"(g, p \\<turnstile> (nid, m, h) \\<rightarrow> (nid', m, h))\"\n  shows \"{P'. (g m p h \\<turnstile> nid \\<leadsto> P')} = {nid'} \\<union> {nid''. (g m p h \\<turnstile> nid' \\<leadsto> nid'')}\"\nproof -\n  have nextin: \"nid' \\<in> {P'. (g m p h \\<turnstile> nid \\<leadsto> P')}\"\n    using assms StutterStep by blast\n  have nextsubset: \"{nid''. (g m p h \\<turnstile> nid' \\<leadsto> nid'')} \\<subseteq> {P'. (g m p h \\<turnstile> nid \\<leadsto> P')}\"\n    by (metis Collect_mono assms stutter.Transitive)\n  have \"\\<forall>n \\<in> {P'. (g m p h \\<turnstile> nid \\<leadsto> P')} . n = nid' \\<or> n \\<in> {nid''. (g m p h \\<turnstile> nid' \\<leadsto> nid'')}\"\n    using stepDet\n    by (metis (no_types, lifting) Pair_inject assms mem_Collect_eq stutter.simps)\n  then show ?thesis\n    using insert_absorb mk_disjoint_insert nextin nextsubset by auto\nqed\n\nend", "meta": {"author": "uqcyber", "repo": "veriopt-releases", "sha": "4ffab3c91bbd699772889dbf263bb6d2582256d7", "save_path": "github-repos/isabelle/uqcyber-veriopt-releases", "path": "github-repos/isabelle/uqcyber-veriopt-releases/veriopt-releases-4ffab3c91bbd699772889dbf263bb6d2582256d7/Proofs/Stuttering.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.27506937629073963}}
{"text": "(*** This file is part of Lem.  eth-isabelle project just uses it.  See lem-license. ***)\n\nchapter {* Generated by Lem from list.lem. *}\n\ntheory \"Lem_list\" \n\nimports \n \t Main\n\t \"Lem_bool\" \n\t \"Lem_maybe\" \n\t \"Lem_basic_classes\" \n\t \"Lem_function\" \n\t \"Lem_tuple\" \n\t \"Lem_num\" \n\t \"Lem\" \n\nbegin \n\n \n\n(*open import Bool Maybe Basic_classes Function Tuple Num*)\n\n(*open import {coq} `Coq.Lists.List`*)\n(*open import {isabelle} `$LIB_DIR/Lem`*)\n(*open import {hol} `lemTheory` `listTheory` `rich_listTheory` `sortingTheory`*)\n\n(* ========================================================================== *)\n(* Basic list functions                                                       *)\n(* ========================================================================== *)\n\n(* The type of lists as well as list literals like [], [1;2], ... are hardcoded. \n   Thus, we can directly dive into derived definitions. *)\n\n\n(* ----------------------- *)\n(* cons                    *)\n(* ----------------------- *)\n\n(*val :: : forall 'a. 'a -> list 'a -> list 'a*)\n\n\n(* ----------------------- *)\n(* Emptyness check         *)\n(* ----------------------- *)\n\n(*val null : forall 'a. list 'a -> bool*)\n(*let null l=  match l with [] -> true | _ -> false end*)\n\n(* ----------------------- *)\n(* Length                  *)\n(* ----------------------- *)\n\n(*val length : forall 'a. list 'a -> nat*)\n(*let rec length l= \n  match l with\n    | [] -> 0\n    | x :: xs -> (Instance_Num_NumAdd_nat.+) (length xs) 1\n  end*)\n\n(* ----------------------- *)\n(* Equality                *)\n(* ----------------------- *)\n\n(*val listEqual : forall 'a. Eq 'a => list 'a -> list 'a -> bool*)\n(*val listEqualBy : forall 'a. ('a -> 'a -> bool) -> list 'a -> list 'a -> bool*)\n\nfun  listEqualBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list \\<Rightarrow> bool \"  where \n     \" listEqualBy eq ([]) ([]) = ( True )\"\n|\" listEqualBy eq ([]) (_ # _) = ( False )\"\n|\" listEqualBy eq (_ # _) ([]) = ( False )\"\n|\" listEqualBy eq (x # xs) (y # ys) = ( (eq x y \\<and> listEqualBy eq xs ys))\" \ndeclare listEqualBy.simps [simp del]\n\n\n\n(* ----------------------- *)\n(* compare                 *)\n(* ----------------------- *)\n\n(*val lexicographicCompare : forall 'a. Ord 'a => list 'a -> list 'a -> ordering*)\n(*val lexicographicCompareBy : forall 'a. ('a -> 'a -> ordering) -> list 'a -> list 'a -> ordering*)\n\nfun  lexicographicCompareBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> ordering)\\<Rightarrow> 'a list \\<Rightarrow> 'a list \\<Rightarrow> ordering \"  where \n     \" lexicographicCompareBy cmp ([]) ([]) = ( EQ )\"\n|\" lexicographicCompareBy cmp ([]) (_ # _) = ( LT )\"\n|\" lexicographicCompareBy cmp (_ # _) ([]) = ( GT )\"\n|\" lexicographicCompareBy cmp (x # xs) (y # ys) = ( (\n      (case  cmp x y of \n          LT => LT\n        | GT => GT\n        | EQ => lexicographicCompareBy cmp xs ys\n      )\n    ))\" \ndeclare lexicographicCompareBy.simps [simp del]\n\n\n(*val lexicographicLess : forall 'a. Ord 'a => list 'a -> list 'a -> bool*)\n(*val lexicographicLessBy : forall 'a. ('a -> 'a -> bool) -> ('a -> 'a -> bool) -> list 'a -> list 'a -> bool*)\nfun  lexicographicLessBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow>('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list \\<Rightarrow> bool \"  where \n     \" lexicographicLessBy less1 less_eq1 ([]) ([]) = ( False )\"\n|\" lexicographicLessBy less1 less_eq1 ([]) (_ # _) = ( True )\"\n|\" lexicographicLessBy less1 less_eq1 (_ # _) ([]) = ( False )\"\n|\" lexicographicLessBy less1 less_eq1 (x # xs) (y # ys) = ( ((less1 x y) \\<or> ((less_eq1 x y) \\<and> (lexicographicLessBy less1 less_eq1 xs ys))))\" \ndeclare lexicographicLessBy.simps [simp del]\n\n\n(*val lexicographicLessEq : forall 'a. Ord 'a => list 'a -> list 'a -> bool*)\n(*val lexicographicLessEqBy : forall 'a. ('a -> 'a -> bool) -> ('a -> 'a -> bool) -> list 'a -> list 'a -> bool*)\nfun  lexicographicLessEqBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow>('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list \\<Rightarrow> bool \"  where \n     \" lexicographicLessEqBy less1 less_eq1 ([]) ([]) = ( True )\"\n|\" lexicographicLessEqBy less1 less_eq1 ([]) (_ # _) = ( True )\"\n|\" lexicographicLessEqBy less1 less_eq1 (_ # _) ([]) = ( False )\"\n|\" lexicographicLessEqBy less1 less_eq1 (x # xs) (y # ys) = ( (less1 x y \\<or> (less_eq1 x y \\<and> lexicographicLessEqBy less1 less_eq1 xs ys)))\" \ndeclare lexicographicLessEqBy.simps [simp del]\n\n\n\ndefinition instance_Basic_classes_Ord_list_dict  :: \" 'a Ord_class \\<Rightarrow>('a list)Ord_class \"  where \n     \" instance_Basic_classes_Ord_list_dict dict_Basic_classes_Ord_a = ((|\n\n  compare_method = (lexicographicCompareBy \n  (compare_method   dict_Basic_classes_Ord_a)),\n\n  isLess_method = (lexicographicLessBy \n  (isLess_method   dict_Basic_classes_Ord_a) (isLessEqual_method   dict_Basic_classes_Ord_a)),\n\n  isLessEqual_method = (lexicographicLessEqBy \n  (isLess_method   dict_Basic_classes_Ord_a) (isLessEqual_method   dict_Basic_classes_Ord_a)),\n\n  isGreater_method = (\\<lambda> x y. (lexicographicLessBy \n  (isLess_method   dict_Basic_classes_Ord_a) (isLessEqual_method   dict_Basic_classes_Ord_a) y x)),\n\n  isGreaterEqual_method = (\\<lambda> x y. (lexicographicLessEqBy \n  (isLess_method   dict_Basic_classes_Ord_a) (isLessEqual_method   dict_Basic_classes_Ord_a) y x))|) )\"\n\n\n\n(* ----------------------- *)\n(* Append                  *)\n(* ----------------------- *)\n\n(*val ++ : forall 'a. list 'a -> list 'a -> list 'a*) (* originally append *)\n(*let rec ++ xs ys=  match xs with\n                     | [] -> ys\n                     | x :: xs' -> x :: (xs' ++ ys)\n                   end*)\n\n(* ----------------------- *)\n(* snoc                    *)\n(* ----------------------- *)\n\n(*val snoc : forall 'a. 'a -> list 'a -> list 'a*)\n(*let snoc e l=  l ++ [e]*)\n\n\n(* ----------------------- *)\n(* Reverse                 *)\n(* ----------------------- *)\n\n(* First lets define the function [reverse_append], which is\n   closely related to reverse. [reverse_append l1 l2] appends the list [l2] to the reverse of [l1].\n   This can be implemented more efficienctly than appending and is\n   used to implement reverse. *)\n\n(*val reverseAppend : forall 'a. list 'a -> list 'a -> list 'a*) (* originally named rev_append *)\n(*let rec reverseAppend l1 l2=  match l1 with \n                                | [] -> l2\n                                | x :: xs -> reverseAppend xs (x :: l2)\n                               end*)\n\n(* Reversing a list *)\n(*val reverse : forall 'a. list 'a -> list 'a*) (* originally named rev *)\n(*let reverse l=  reverseAppend l []*)\n\n(* ----------------------- *)\n(* Map                     *)\n(* ----------------------- *)\n\n(*val map_tr : forall 'a 'b. list 'b -> ('a -> 'b) -> list 'a -> list 'b*)\nfunction (sequential,domintros)  map_tr  :: \" 'b list \\<Rightarrow>('a \\<Rightarrow> 'b)\\<Rightarrow> 'a list \\<Rightarrow> 'b list \"  where \n     \" map_tr rev_acc f ([]) = ( List.rev rev_acc )\"\n|\" map_tr rev_acc f (x # xs) = ( map_tr ((f x) # rev_acc) f xs )\" \nby pat_completeness auto\n\n\n(* taken from: https://blogs.janestreet.com/optimizing-list-map/ *)\n(*val count_map : forall 'a 'b. ('a -> 'b) -> list 'a -> nat -> list 'b*)\nfunction (sequential,domintros)  count_map  :: \"('a \\<Rightarrow> 'b)\\<Rightarrow> 'a list \\<Rightarrow> nat \\<Rightarrow> 'b list \"  where \n     \" count_map f ([]) ctr = ( [])\"\n|\" count_map f (hd1 # tl1) ctr = ( f hd1 # \n    (if ctr <( 5000 :: nat) then count_map f tl1 (ctr +( 1 :: nat)) \n    else map_tr [] f tl1))\" \nby pat_completeness auto\n\n \n(*val map : forall 'a 'b. ('a -> 'b) -> list 'a -> list 'b*)\n(*let map f l=  count_map f l 0*)\n\n(* ----------------------- *)\n(* Reverse Map             *)\n(* ----------------------- *)\n\n(*val reverseMap : forall 'a 'b. ('a -> 'b) -> list 'a -> list 'b*)\n\n\n(* ========================================================================== *)\n(* Folding                                                                    *)\n(* ========================================================================== *)\n\n(* ----------------------- *)\n(* fold left               *)\n(* ----------------------- *)\n\n(*val foldl : forall 'a 'b. ('a -> 'b -> 'a) -> 'a -> list 'b -> 'a*) (* originally foldl *)\n\n(*let rec foldl f b l=  match l with\n  | []      -> b\n  | x :: xs -> foldl f (f b x) xs\nend*)\n\n\n(* ----------------------- *)\n(* fold right              *)\n(* ----------------------- *)\n\n(*val foldr : forall 'a 'b. ('a -> 'b -> 'b) -> 'b -> list 'a -> 'b*) (* originally foldr with different argument order *)\n(*let rec foldr f b l=  match l with\n  | []      -> b\n  | x :: xs -> f x (foldr f b xs)\nend*)\n\n\n(* ----------------------- *)\n(* concatenating lists     *)\n(* ----------------------- *)\n\n(*val concat : forall 'a. list (list 'a) -> list 'a*) (* before also called flatten *)\n(*let concat=  foldr (++) []*)\n\n\n(* -------------------------- *)\n(* concatenating with mapping *)\n(* -------------------------- *)\n\n(*val concatMap : forall 'a 'b. ('a -> list 'b) -> list 'a -> list 'b*)\n\n\n(* ------------------------- *)\n(* universal qualification   *)\n(* ------------------------- *)\n\n(*val all : forall 'a. ('a -> bool) -> list 'a -> bool*) (* originally for_all *)\n(*let all P l=  foldl (fun r e -> P e && r) true l*)\n\n\n\n(* ------------------------- *)\n(* existential qualification *)\n(* ------------------------- *)\n\n(*val any : forall 'a. ('a -> bool) -> list 'a -> bool*) (* originally exist *)\n(*let any P l=  foldl (fun r e -> P e || r) false l*)\n\n\n(* ------------------------- *)\n(* dest_init                 *)\n(* ------------------------- *)\n\n(* get the initial part and the last element of the list in a safe way *)\n\n(*val dest_init : forall 'a. list 'a -> maybe (list 'a * 'a)*) \n\nfun  dest_init_aux  :: \" 'a list \\<Rightarrow> 'a \\<Rightarrow> 'a list \\<Rightarrow> 'a list*'a \"  where \n     \" dest_init_aux rev_init last_elem_seen ([]) = ( (List.rev rev_init, last_elem_seen))\"\n|\" dest_init_aux rev_init last_elem_seen (x # xs) = ( dest_init_aux (last_elem_seen # rev_init) x xs )\" \ndeclare dest_init_aux.simps [simp del]\n\n\nfun dest_init  :: \" 'a list \\<Rightarrow>('a list*'a)option \"  where \n     \" dest_init ([]) = ( None )\"\n|\" dest_init (x # xs) = ( Some (dest_init_aux [] x xs))\" \ndeclare dest_init.simps [simp del]\n\n\n\n(* ========================================================================== *)\n(* Indexing lists                                                             *)\n(* ========================================================================== *)\n\n(* ------------------------- *)\n(* index / nth with maybe   *)\n(* ------------------------- *)\n\n(*val index : forall 'a. list 'a -> nat -> maybe 'a*)\n\n(*let rec index l n=  match l with \n  | []      -> Nothing\n  | x :: xs -> if (Instance_Basic_classes_Eq_nat.=) n 0 then Just x else index xs ((Instance_Num_NumMinus_nat.-)n 1)\nend*)\n\n(* ------------------------- *)\n(* findIndices               *)\n(* ------------------------- *)\n\n(* [findIndices P l] returns the indices of all elements of list [l] that satisfy predicate [P]. \n   Counting starts with 0, the result list is sorted ascendingly *)\n(*val findIndices : forall 'a. ('a -> bool) -> list 'a -> list nat*)\n\nfun  findIndices_aux  :: \" nat \\<Rightarrow>('a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow>(nat)list \"  where \n     \" findIndices_aux (i::nat) P ([]) = ( [])\"\n|\" findIndices_aux (i::nat) P (x # xs) = ( if P x then i # findIndices_aux (i +( 1 :: nat)) P xs else findIndices_aux (i +( 1 :: nat)) P xs )\" \ndeclare findIndices_aux.simps [simp del]\n\n(*let findIndices P l=  findIndices_aux 0 P l*)\n\n\n\n(* ------------------------- *)\n(* findIndex                 *)\n(* ------------------------- *)\n\n(* findIndex returns the first index of a list that satisfies a given predicate. *)\n(*val findIndex : forall 'a. ('a -> bool) -> list 'a -> maybe nat*)\n(*let findIndex P l=  match findIndices P l with\n  | [] -> Nothing\n  | x :: _ -> Just x\nend*)\n\n(* ------------------------- *)\n(* elemIndices               *)\n(* ------------------------- *)\n\n(*val elemIndices : forall 'a. Eq 'a => 'a -> list 'a -> list nat*)\n\n(* ------------------------- *)\n(* elemIndex                 *)\n(* ------------------------- *)\n\n(*val elemIndex : forall 'a. Eq 'a => 'a -> list 'a -> maybe nat*)\n\n\n(* ========================================================================== *)\n(* Creating lists                                                             *)\n(* ========================================================================== *)\n\n(* ------------------------- *)\n(* genlist                   *)\n(* ------------------------- *)\n\n(* [genlist f n] generates the list [f 0; f 1; ... (f (n-1))] *)\n(*val genlist : forall 'a. (nat -> 'a) -> nat -> list 'a*)\n\n\n(*let rec genlist f n= \n  match n with\n    | 0 -> []\n    | n' + 1 -> snoc (f n') (genlist f n')\n  end*)\n\n\n(* ------------------------- *)\n(* replicate                 *)\n(* ------------------------- *)\n\n(*val replicate : forall 'a. nat -> 'a -> list 'a*)\n(*let rec replicate n x= \n  match n with\n    | 0 -> []\n    | n' + 1 -> x :: replicate n' x\n  end*)\n\n\n(* ========================================================================== *)\n(* Sublists                                                                   *)\n(* ========================================================================== *)\n\n(* ------------------------- *)\n(* splitAt                   *)\n(* ------------------------- *)\n\n(* [splitAt n xs] returns a tuple (xs1, xs2), with append xs1 xs2 = xs and \n   length xs1 = n. If there are not enough elements \n   in [xs], the original list and the empty one are returned. *)\n(*val splitAtAcc : forall 'a. list 'a -> nat -> list 'a -> (list 'a * list 'a)*)\nfunction (sequential,domintros)  splitAtAcc  :: \" 'a list \\<Rightarrow> nat \\<Rightarrow> 'a list \\<Rightarrow> 'a list*'a list \"  where \n     \" splitAtAcc revAcc n l = ( \n  (case  l of\n      []    => (List.rev revAcc, [])\n    | x # xs => if n \\<le>( 0 :: nat) then (List.rev revAcc, l) else splitAtAcc (x # revAcc) (n-( 1 :: nat)) xs\n  ))\" \nby pat_completeness auto\n\n\n(*val splitAt : forall 'a. nat -> list 'a -> (list 'a * list 'a)*)\n(*let rec splitAt n l=  \n   splitAtAcc [] n l*)\n\n\n(* ------------------------- *)\n(* take                      *)\n(* ------------------------- *)\n\n(* take n xs returns the prefix of xs of length n, or xs itself if n > length xs *)\n(*val take : forall 'a. nat -> list 'a -> list 'a*)\n(*let take n l=  fst (splitAt n l)*)\n\n\n\n(* ------------------------- *)\n(* drop                      *)\n(* ------------------------- *)\n\n(* [drop n xs] drops the first [n] elements of [xs]. It returns the empty list, if [n] > [length xs]. *)\n(*val drop : forall 'a. nat -> list 'a -> list 'a*)\n(*let drop n l=  snd (splitAt n l)*)\n\n(* ------------------------- *)\n(* dropWhile                 *)\n(* ------------------------- *)\n\n(* [dropWhile p xs] drops the first elements of [xs] that satisfy [p]. *)\n(*val dropWhile : forall 'a. ('a -> bool) -> list 'a -> list 'a*)\nfun  dropWhile  :: \"('a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list \"  where \n     \" dropWhile p l = ( (case  l of \n    [] => []\n  | x # xs => if p x then dropWhile p xs else l\n))\" \ndeclare dropWhile.simps [simp del]\n\n\n\n(* ------------------------- *)\n(* takeWhile                 *)\n(* ------------------------- *)\n\n(* [takeWhile p xs] takes the first elements of [xs] that satisfy [p]. *)\n(*val takeWhile : forall 'a. ('a -> bool) -> list 'a -> list 'a*)\nfun  takeWhile  :: \"('a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list \"  where \n     \" takeWhile p ([]) = ( [])\"\n|\" takeWhile p (x # xs) = ( if p x then x # takeWhile p xs else [])\" \ndeclare takeWhile.simps [simp del]\n\n\n(* ------------------------- *)\n(* splitWhile                *)\n(* ------------------------- *)\n\n(*val splitWhile : forall 'a. ('a -> bool) -> list 'a -> (list 'a * list 'a)*)\ndefinition splitWhile  :: \"('a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list*'a list \"  where \n     \" splitWhile p xs = ( (takeWhile p xs, dropWhile p xs))\"\n\n\n\n(* ------------------------- *)\n(* isPrefixOf                *)\n(* ------------------------- *)\n\n(*val isPrefixOf : forall 'a. Eq 'a => list 'a -> list 'a -> bool*)\nfun  isPrefixOf  :: \" 'a list \\<Rightarrow> 'a list \\<Rightarrow> bool \"  where \n     \" isPrefixOf ([]) _ = ( True )\"\n|\" isPrefixOf (_ # _) ([]) = ( False )\"\n|\" isPrefixOf (x # xs) (y # ys) = ( (x = y) \\<and> isPrefixOf xs ys )\" \ndeclare isPrefixOf.simps [simp del]\n\n\n(* ------------------------- *)\n(* update                    *)\n(* ------------------------- *)\n(*val update : forall 'a. list 'a -> nat -> 'a -> list 'a*)\n(*let rec update l n e=  \n  match l with\n    | []      -> []\n    | x :: xs -> if (Instance_Basic_classes_Eq_nat.=) n 0 then e :: xs else x :: (update xs ((Instance_Num_NumMinus_nat.-) n 1) e)\nend*)\n\n\n\n(* ========================================================================== *)\n(* Searching lists                                                            *)\n(* ========================================================================== *)\n\n(* ------------------------- *)\n(* Membership test           *)\n(* ------------------------- *)\n\n(* The membership test, one of the basic list functions, is actually tricky for\n   Lem, because it is tricky, which equality to use. From Lem`s point of \n   perspective, we want to use the equality provided by the equality type - class.\n   This allows for example to check whether a set is in a list of sets.\n\n   However, in order to use the equality type class, elem essentially becomes\n   existential quantification over lists. For types, which implement semantic\n   equality (=) with syntactic equality, this is overly complicated. In\n   our theorem prover backend, we would end up with overly complicated, harder\n   to read definitions and some of the automation would be harder to apply.\n   Moreover, nearly all the old Lem generated code would change and require \n   (hopefully minor) adaptions of proofs.\n\n   For now, we ignore this problem and just demand, that all instances of\n   the equality type class do the right thing for the theorem prover backends.   \n*)\n\n(*val elem : forall 'a. Eq 'a => 'a -> list 'a -> bool*)\n(*val elemBy : forall 'a. ('a -> 'a -> bool) -> 'a -> list 'a -> bool*)\n\ndefinition elemBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow> 'a \\<Rightarrow> 'a list \\<Rightarrow> bool \"  where \n     \" elemBy eq e l = ( ((\\<exists> x \\<in> (set l).  (eq e) x)))\"\n\n(*let elem=  elemBy (=)*)\n\n(* ------------------------- *)\n(* Find                      *)\n(* ------------------------- *)\n(*val find : forall 'a. ('a -> bool) -> list 'a -> maybe 'a*) (* previously not of maybe type *)\n(*let rec find P l=  match l with \n  | []      -> Nothing\n  | x :: xs -> if P x then Just x else find P xs\nend*)\n\n\n(* ----------------------------- *)\n(* Lookup in an associative list *)\n(* ----------------------------- *)\n(*val lookup   : forall 'a 'b. Eq 'a              => 'a -> list ('a * 'b) -> maybe 'b*)\n(*val lookupBy : forall 'a 'b. ('a -> 'a -> bool) -> 'a -> list ('a * 'b) -> maybe 'b*)\n\n(* DPM: eta-expansion for Coq backend type-inference. *)\ndefinition lookupBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow> 'a \\<Rightarrow>('a*'b)list \\<Rightarrow> 'b option \"  where \n     \" lookupBy eq k m = ( map_option (\\<lambda> x .  snd x) (List.find (\\<lambda> (k', _) .  eq k k') m))\"\n\n\n(* ------------------------- *)\n(* filter                    *)\n(* ------------------------- *)\n(*val filter : forall 'a. ('a -> bool) -> list 'a -> list 'a*)\n(*let rec filter P l=  match l with\n                       | [] -> []\n                       | x :: xs -> if (P x) then x :: (filter P xs) else filter P xs\n                     end*)\n\n\n(* ------------------------- *)\n(* partition                 *)\n(* ------------------------- *)\n(*val partition : forall 'a. ('a -> bool) -> list 'a -> list 'a * list 'a*)\n(*let partition P l=  (filter P l, filter (fun x -> not (P x)) l)*)\n\n(*val reversePartition : forall 'a. ('a -> bool) -> list 'a -> list 'a * list 'a*)\ndefinition reversePartition  :: \"('a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list*'a list \"  where \n     \" reversePartition P l = ( List.partition P (List.rev l))\"\n\n\n\n(* ------------------------- *)\n(* delete first element      *)\n(* with certain property     *)\n(* ------------------------- *)\n\n(*val deleteFirst : forall 'a. ('a -> bool) -> list 'a -> maybe (list 'a)*) \n(*let rec deleteFirst P l=  match l with\n                            | [] -> Nothing\n                            | x :: xs -> if (P x) then Just xs else Maybe.map (fun xs' -> x :: xs') (deleteFirst P xs)\n                          end*)\n\n\n(*val delete : forall 'a. Eq 'a => 'a -> list 'a -> list 'a*)\n(*val deleteBy : forall 'a. ('a -> 'a -> bool) -> 'a -> list 'a -> list 'a*)\n\ndefinition deleteBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow> 'a \\<Rightarrow> 'a list \\<Rightarrow> 'a list \"  where \n     \" deleteBy eq x l = ( case_option l id (delete_first (eq x) l))\"\n\n\n\n(* ========================================================================== *)\n(* Zipping and unzipping lists                                                *)\n(* ========================================================================== *)\n\n(* ------------------------- *)\n(* zip                       *)\n(* ------------------------- *)\n\n(* zip takes two lists and returns a list of corresponding pairs. If one input list is short, excess elements of the longer list are discarded. *)\n(*val zip : forall 'a 'b. list 'a -> list 'b -> list ('a * 'b)*) (* before combine *)\n(*let rec zip l1 l2=  match (l1, l2) with\n  | (x :: xs, y :: ys) -> (x, y) :: zip xs ys\n  | _ -> []\nend*)\n\n(* ------------------------- *)\n(* unzip                     *)\n(* ------------------------- *)\n\n(*val unzip: forall 'a 'b. list ('a * 'b) -> (list 'a * list 'b)*)\n(*let rec unzip l=  match l with\n  | [] -> ([], [])\n  | (x, y) :: xys -> let (xs, ys) = unzip xys in (x :: xs, y :: ys)\nend*)\n\n(* ------------------------- *)\n(* distinct elements         *)\n(* ------------------------- *)\n\n(*val allDistinct : forall 'a. Eq 'a => list 'a -> bool*)\nfun  allDistinct  :: \" 'a list \\<Rightarrow> bool \"  where \n     \" allDistinct ([]) = ( True )\"\n|\" allDistinct (x # l') = ( \\<not> (Set.member x (set l')) \\<and> allDistinct l' )\" \ndeclare allDistinct.simps [simp del]\n\n\n(* some more useful functions *)\n(*val mapMaybe : forall 'a 'b. ('a -> maybe 'b) -> list 'a -> list 'b*)\nfunction (sequential,domintros)  mapMaybe  :: \"('a \\<Rightarrow> 'b option)\\<Rightarrow> 'a list \\<Rightarrow> 'b list \"  where \n     \" mapMaybe f ([]) = ( [])\"\n|\" mapMaybe f (x # xs) = (\n      (case  f x of\n        None => mapMaybe f xs\n      | Some y => y # (mapMaybe f xs)\n      ))\" \nby pat_completeness auto\n\n\n(*val mapi : forall 'a 'b. (nat -> 'a -> 'b) -> list 'a -> list 'b*)\nfunction (sequential,domintros)  mapiAux  :: \"(nat \\<Rightarrow> 'b \\<Rightarrow> 'a)\\<Rightarrow> nat \\<Rightarrow> 'b list \\<Rightarrow> 'a list \"  where \n     \" mapiAux f (n :: nat) ([]) = ( [])\"\n|\" mapiAux f (n :: nat) (x # xs) = ( (f n x) # mapiAux f (n +( 1 :: nat)) xs )\" \nby pat_completeness auto\n\ndefinition mapi  :: \"(nat \\<Rightarrow> 'a \\<Rightarrow> 'b)\\<Rightarrow> 'a list \\<Rightarrow> 'b list \"  where \n     \" mapi f l = ( mapiAux f(( 0 :: nat)) l )\"\n\n\n(*val deletes: forall 'a. Eq 'a => list 'a -> list 'a -> list 'a*)\ndefinition deletes  :: \" 'a list \\<Rightarrow> 'a list \\<Rightarrow> 'a list \"  where \n     \" deletes xs ys = (\n  List.foldl ((\\<lambda> x y. remove1 y x)) xs ys )\"\n\n\n(* ========================================================================== *)\n(* Comments (not clean yet, please ignore the rest of the file)               *)\n(* ========================================================================== *)\n\n(* ----------------------- *)\n(* skipped from Haskell Lib*)\n(* ----------------------- \n\nintersperse :: a -> [a] -> [a]\nintercalate :: [a] -> [[a]] -> [a]\ntranspose :: [[a]] -> [[a]]\nsubsequences :: [a] -> [[a]]\npermutations :: [a] -> [[a]]\nfoldl` :: (a -> b -> a) -> a -> [b] -> aSource\nfoldl1` :: (a -> a -> a) -> [a] -> aSource\n\nand\nor\nsum\nproduct\nmaximum\nminimum\nscanl\nscanr\nscanl1\nscanr1\nAccumulating maps\n\nmapAccumL :: (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])Source\nmapAccumR :: (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])Source\n\niterate :: (a -> a) -> a -> [a]\nrepeat :: a -> [a]\ncycle :: [a] -> [a]\nunfoldr\n\n\ntakeWhile :: (a -> Bool) -> [a] -> [a]Source\ndropWhile :: (a -> Bool) -> [a] -> [a]Source\ndropWhileEnd :: (a -> Bool) -> [a] -> [a]Source\nspan :: (a -> Bool) -> [a] -> ([a], [a])Source\nbreak :: (a -> Bool) -> [a] -> ([a], [a])Source\nbreak p is equivalent to span (not . p).\nstripPrefix :: Eq a => [a] -> [a] -> Maybe [a]Source\ngroup :: Eq a => [a] -> [[a]]Source\ninits :: [a] -> [[a]]Source\ntails :: [a] -> [[a]]Source\n\n\nisPrefixOf :: Eq a => [a] -> [a] -> BoolSource\nisSuffixOf :: Eq a => [a] -> [a] -> BoolSource\nisInfixOf :: Eq a => [a] -> [a] -> BoolSource\n\n\n\nnotElem :: Eq a => a -> [a] -> BoolSource\n\nzip3 :: [a] -> [b] -> [c] -> [(a, b, c)]Source\nzip4 :: [a] -> [b] -> [c] -> [d] -> [(a, b, c, d)]Source\nzip5 :: [a] -> [b] -> [c] -> [d] -> [e] -> [(a, b, c, d, e)]Source\nzip6 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [(a, b, c, d, e, f)]Source\nzip7 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [(a, b, c, d, e, f, g)]Source\n\nzipWith :: (a -> b -> c) -> [a] -> [b] -> [c]Source\nzipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]Source\nzipWith4 :: (a -> b -> c -> d -> e) -> [a] -> [b] -> [c] -> [d] -> [e]Source\nzipWith5 :: (a -> b -> c -> d -> e -> f) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f]Source\nzipWith6 :: (a -> b -> c -> d -> e -> f -> g) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g]Source\nzipWith7 :: (a -> b -> c -> d -> e -> f -> g -> h) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [h]Source\n\n\nunzip3 :: [(a, b, c)] -> ([a], [b], [c])Source\nunzip4 :: [(a, b, c, d)] -> ([a], [b], [c], [d])Source\nunzip5 :: [(a, b, c, d, e)] -> ([a], [b], [c], [d], [e])Source\nunzip6 :: [(a, b, c, d, e, f)] -> ([a], [b], [c], [d], [e], [f])Source\nunzip7 :: [(a, b, c, d, e, f, g)] -> ([a], [b], [c], [d], [e], [f], [g])Source\n\n\nlines :: String -> [String]Source\nwords :: String -> [String]Source\nunlines :: [String] -> StringSource\nunwords :: [String] -> StringSource\nnub :: Eq a => [a] -> [a]Source\ndelete :: Eq a => a -> [a] -> [a]Source\n\n() :: Eq a => [a] -> [a] -> [a]Source\nunion :: Eq a => [a] -> [a] -> [a]Source\nintersect :: Eq a => [a] -> [a] -> [a]Source\nsort :: Ord a => [a] -> [a]Source\ninsert :: Ord a => a -> [a] -> [a]Source\n\n\nnubBy :: (a -> a -> Bool) -> [a] -> [a]Source\ndeleteBy :: (a -> a -> Bool) -> a -> [a] -> [a]Source\ndeleteFirstsBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]Source\nunionBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]Source\nintersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]Source\ngroupBy :: (a -> a -> Bool) -> [a] -> [[a]]Source\nsortBy :: (a -> a -> Ordering) -> [a] -> [a]Source\ninsertBy :: (a -> a -> Ordering) -> a -> [a] -> [a]Source\nmaximumBy :: (a -> a -> Ordering) -> [a] -> aSource\nminimumBy :: (a -> a -> Ordering) -> [a] -> aSource\ngenericLength :: Num i => [b] -> iSource\ngenericTake :: Integral i => i -> [a] -> [a]Source\ngenericDrop :: Integral i => i -> [a] -> [a]Source\ngenericSplitAt :: Integral i => i -> [b] -> ([b], [b])Source\ngenericIndex :: Integral a => [b] -> a -> bSource\ngenericReplicate :: Integral i => i -> a -> [a]Source\n\n\n*)\n\n\n(* ----------------------- *)\n(* skipped from Lem Lib    *)\n(* ----------------------- \n\n\nval for_all2 : forall 'a 'b. ('a -> 'b -> bool) -> list 'a -> list 'b -> bool\nval exists2 : forall 'a 'b. ('a -> 'b -> bool) -> list 'a -> list 'b -> bool\nval map2 : forall 'a 'b 'c. ('a -> 'b -> 'c) -> list 'a -> list 'b -> list 'c \nval rev_map2 : forall 'a 'b 'c. ('a -> 'b -> 'c) -> list 'a -> list 'b -> list 'c\nval fold_left2 : forall 'a 'b 'c. ('a -> 'b -> 'c -> 'a) -> 'a -> list 'b -> list 'c -> 'a\nval fold_right2 : forall 'a 'b 'c. ('a -> 'b -> 'c -> 'c) -> list 'a -> list 'b -> 'c -> 'c\n\n\n(* now maybe result and called lookup *)\nval assoc : forall 'a 'b. 'a -> list ('a * 'b) -> 'b\nlet inline {ocaml} assoc = Ocaml.List.assoc\n\n\nval mem_assoc : forall 'a 'b. 'a -> list ('a * 'b) -> bool\nval remove_assoc : forall 'a 'b. 'a -> list ('a * 'b) -> list ('a * 'b)\n\n\n\nval stable_sort : forall 'a. ('a -> 'a -> num) -> list 'a -> list 'a\nval fast_sort : forall 'a. ('a -> 'a -> num) -> list 'a -> list 'a\n\nval merge : forall 'a. ('a -> 'a -> num) -> list 'a -> list 'a -> list 'a\nval intersect : forall 'a. list 'a -> list 'a -> list 'a\n\n\n*)\n\n(*val     catMaybes : forall 'a. list (maybe 'a) -> list 'a*)\nfunction (sequential,domintros)  catMaybes  :: \"('a option)list \\<Rightarrow> 'a list \"  where \n     \" catMaybes ([]) = (\n        [])\"\n|\" catMaybes (None # xs') = (\n        catMaybes xs' )\"\n|\" catMaybes (Some x # xs') = (\n        x # catMaybes xs' )\" \nby pat_completeness auto\n\nend\n", "meta": {"author": "pirapira", "repo": "eth-isabelle", "sha": "d0bb02b3e64a2046a7c9670545d21f10bccd7b27", "save_path": "github-repos/isabelle/pirapira-eth-isabelle", "path": "github-repos/isabelle/pirapira-eth-isabelle/eth-isabelle-d0bb02b3e64a2046a7c9670545d21f10bccd7b27/lem/Lem_list.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5544704502361149, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.2750693689860991}}
{"text": "section {*LR1\\_Property\\_Satisfaction\\_\\_entire\\_derivation\\_tree\\_invariant*}\ntheory\n  LR1_Property_Satisfaction__entire_derivation_tree_invariant\n\nimports\n  PRJ_12_04_06_06_11__ENTRY\n\nbegin\n\ndefinition EValidSplitExt_no_elim_before_nonterminal :: \"\n  ('q, 's, 't) ESplit\n  \\<Rightarrow> bool\"\n  where\n    \"EValidSplitExt_no_elim_before_nonterminal S \\<equiv>\n  \\<forall>k < length S. \n    (\\<exists>A. ESplitItem_elem (S ! k) = Some (teA A))\n    \\<longrightarrow> (\\<forall>i \\<le> k. ESplitItem_elim (S ! i) = [])\"\n\ndefinition EValidSplitExt_no_pop_in_prods_before_nonterminal :: \"\n  ('q, 's, 't) ESplit\n  \\<Rightarrow> bool\"\n  where\n    \"EValidSplitExt_no_pop_in_prods_before_nonterminal S \\<equiv>\n  \\<forall>k < length S. \n    (\\<exists>A. ESplitItem_elem (S ! k) = Some (teA A)) \n    \\<longrightarrow> (\\<forall>i \\<le> k. \\<forall>j < length (ESplitItem_prods (S ! i)) . prod_rhs (ESplitItem_prods (S ! i) ! j) \\<noteq> [])\"\n\ndefinition Eident_line :: \"\n  ('q, 's, 't) ESplitItem\n  \\<Rightarrow> bool\"\n  where\n    \"Eident_line S \\<equiv>\n   (ESplitItem_prods S = []\n  \\<and> ESplitItem_elim S = [])\"\n\ndefinition Eident_lines :: \"\n  ('q, 's, 't) ESplit\n  \\<Rightarrow> nat set\"\n  where\n    \"Eident_lines S \\<equiv>\n  {n. n < length S\n  \\<and> Eident_line (S ! n) }\"\n\ndefinition EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal :: \"\n  ('q, 's, 't) ESplit\n  \\<Rightarrow> bool\"\n  where\n    \"EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal S \\<equiv>\n   (\\<forall>k < length S. (\\<exists>A. ESplitItem_elem (S ! k) = Some (teA A)) \\<longrightarrow> (\\<forall>i < k. i \\<notin> Eident_lines S))\"\n\ndefinition EValidSplitExt :: \"\n  ('q, 's, 't) ESplit\n  \\<Rightarrow> bool\"\n  where\n    \"EValidSplitExt S \\<equiv>\n   (EValidSplitExt_no_elim_before_nonterminal S\n  \\<and> EValidSplitExt_no_pop_in_prods_before_nonterminal S\n  \\<and> EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal S)\"\n\nlemma entirely_ignored_can_not_happend_to_early: \"\n  F2LR1inputx G G'\n  \\<Longrightarrow> split_TSstructure G\n  \\<Longrightarrow> EValidSplit G (S@SX#SY#SZ#S')\n  \\<Longrightarrow> EValidSplitExt (S@SX#SY#SZ#S')\n  \\<Longrightarrow> ESplitItem_elim SY = []\n  \\<Longrightarrow> ESplitItem_prods SY = []\n  \\<Longrightarrow> ESplitItem_to SX = X#to\n  \\<Longrightarrow> ESplitItem_ignore SX = ig\n  \\<Longrightarrow> ESplitItem_ignore SZ = c @ to @ ig\n  \\<Longrightarrow> Q\"\n  apply(simp add: EValidSplit_def)\n  apply(clarsimp)\n  apply(simp add: EValidSplit_interline_def)\n  apply(erule_tac x=\"length S\" in allE')\n  apply(erule_tac\n      x=\"Suc(length S)\"\n      in allE)\n  apply(clarsimp)\n  apply(subgoal_tac \"(S @ SX # SY # SZ # S') ! (length S) = SX\")\n   prefer 2\n   apply(force)\n  apply(subgoal_tac \"(S @ SX # SY # SZ # S') ! Suc (length S) = SY\")\n   prefer 2\n   apply (metis drop_append2 drop_nth_hlp1)\n  apply(subgoal_tac \"(S @ SX # SY # SZ # S') ! Suc (Suc(length S)) = SSX\" for SSX)\n   prefer 2\n   apply(rule nth_append_2)\n   apply(force)\n  apply(clarsimp)\n  apply(simp add: EValidSplit_interlineX_def)\n  apply(case_tac \"ESplitItem_from SY\")\n   apply(simp add: EValidSplit_producing_def)\n   apply(erule_tac\n      x=\"SY\"\n      in ballE_prime)\n    apply(clarsimp)\n   apply(simp add: option_to_list_def)\n   apply(subgoal_tac \"SY \\<in> set (butlast (S @ SX # SY # SZ # S'))\")\n    apply(force)\n   apply(thin_tac \"SY \\<notin> set (butlast (S @ SX # SY # SZ # S'))\")\n   apply(rule_tac\n      xs=\"S'\"\n      in rev_cases)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"butlast (S @ [SX, SY, SZ])\"\n      in ssubst)\n     apply(rule butlast_direct)\n     apply(force)\n    apply(force)\n   apply(rename_tac ys y)(*strict*)\n   apply(clarsimp)\n   apply(rule_tac\n      t=\"butlast (S @ SX # SY # SZ # ys @ [y])\"\n      in ssubst)\n    apply(rename_tac ys y)(*strict*)\n    apply(rule butlast_direct)\n    apply(force)\n   apply(rename_tac ys y)(*strict*)\n   apply(force)\n  apply(rename_tac a)(*strict*)\n  apply(case_tac \"ESplitItem_from SX\")\n   apply(rename_tac a)(*strict*)\n   apply(simp add: EValidSplit_producing_def)\n   apply(erule_tac\n      x=\"SX\"\n      in ballE_prime)\n    apply(rename_tac a)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac a)(*strict*)\n   apply(subgoal_tac \"SX \\<in> set (butlast (S @ SX # SY # SZ # S'))\")\n    apply(rename_tac a)(*strict*)\n    apply(force)\n   apply(rename_tac a)(*strict*)\n   apply(rule_tac\n      xs=\"S'\"\n      in rev_cases)\n    apply(rename_tac a)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"butlast (S @ [SX, SY, SZ]) = SSX\" for SSX)\n     apply(rename_tac a)(*strict*)\n     prefer 2\n     apply(rule butlast_direct)\n     apply(force)\n    apply(rename_tac a)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac a ys y)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"butlast (S @ SX # SY # SZ # ys @ [y]) = SSX\" for SSX)\n    apply(rename_tac a ys y)(*strict*)\n    prefer 2\n    apply(rule butlast_direct)\n    apply(force)\n   apply(rename_tac a ys y)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac a aa)(*strict*)\n  apply(clarsimp)\n  apply(simp add: option_to_list_def)\n  apply(case_tac \"ESplitItem_to SX\")\n   apply(rename_tac a aa)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac a aa ab list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac aa)(*strict*)\n  apply(subgoal_tac \"ESplitItem_to SY = []\")\n   apply(rename_tac aa)(*strict*)\n   prefer 2\n   apply(simp add: EValidSplit_ValidItem_def)\n   apply(clarsimp)\n   apply(simp add: EValidSplitItem_def EValidSplitItem_gen_def)\n   apply(clarsimp)\n   apply(rename_tac aa d da db)(*strict*)\n   apply(simp add: cfgLM.trans_der_def option_to_list_def)\n   apply(clarsimp)\n   apply(rename_tac aa d da db e eb)(*strict*)\n   apply(simp add: EValidSplit_producing_def)\n   apply(erule_tac\n      x=\"SY\"\n      and A=\"set (butlast (S @ SX # SY # SZ # S'))\"\n      in ballE)\n    apply(rename_tac aa d da db e eb)(*strict*)\n    apply(clarsimp)\n    apply(case_tac \"ESplitItem_to SY\")\n     apply(rename_tac aa d da db e eb)(*strict*)\n     apply(force)\n    apply(rename_tac aa d da db e eb a list)(*strict*)\n    apply(force)\n   apply(rename_tac aa d da db e eb)(*strict*)\n   apply(subgoal_tac \"SY \\<in> set (butlast (S @ SX # SY # SZ # S'))\")\n    apply(rename_tac aa d da db e eb)(*strict*)\n    apply(force)\n   apply(rename_tac aa d da db e eb)(*strict*)\n   apply(rule_tac\n      xs=\"S'\"\n      in rev_cases)\n    apply(rename_tac aa d da db e eb)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"butlast (S @ [SX, SY, SZ]) = SSX\" for SSX)\n     apply(rename_tac aa d da db e eb)(*strict*)\n     prefer 2\n     apply(rule butlast_direct)\n     apply(force)\n    apply(rename_tac aa d da db e eb)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac aa d da db e eb ys y)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac aa d da db e eb ys y dc ea)(*strict*)\n   apply(subgoal_tac \"butlast ((S @ SX # SY # SZ # ys) @ [y]) = SSX\" for SSX)\n    apply(rename_tac aa d da db e eb ys y dc ea)(*strict*)\n    prefer 2\n    apply(rule_tac\n      w=\"S @ SX # SY # SZ # ys\"\n      in butlast_direct)\n    apply(force)\n   apply(rename_tac aa d da db e eb ys y dc ea)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac aa)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"ESplitItem_from SZ\")\n   apply(rename_tac aa)(*strict*)\n   prefer 2\n   apply(rename_tac aa a)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac aa)(*strict*)\n  apply(clarsimp)\n  apply(simp add: EValidSplit_produce_or_elim_def)\n  done\n\nlemma restrict_equal_before_step_nonterminal: \"\n       F2LR1inputx G' G\n  \\<Longrightarrow> split_TSstructure G'\n  \\<Longrightarrow> Esplit_signature S2 = w @ teB b # liftB \\<alpha>1 @ teA A2 # liftB \\<alpha>2\n  \\<Longrightarrow> EValidSplit G' S2\n  \\<Longrightarrow> EValidSplit G' (S2a @ S2b)\n  \\<Longrightarrow> Esplit_step_relation G' S2 \\<lparr>prod_lhs = A2, prod_rhs = []\\<rparr> (S2a @ S2b)\n  \\<Longrightarrow> Esplit_signature S2a = w @ [teB b]\n  \\<Longrightarrow> length S2a = Suc (length w)\n  \\<Longrightarrow> Esplit_signature S2b = liftB \\<alpha>1 @ liftB \\<alpha>2\n  \\<Longrightarrow> EValidSplitExt S2\n  \\<Longrightarrow> EValidSplitExt (S2a @ S2b)\n  \\<Longrightarrow> restrict G G' S2 (Suc(length w)) = restrict G G' (S2a @ S2b) (Suc (length w))\"\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(rule_tac\n      t=\"min (length S2) (Suc (length w))\"\n      and s=\"Suc (length w)\"\n      in ssubst)\n   apply(subgoal_tac \"X\" for X)\n    prefer 2\n    apply(rule_tac\n      S=\"S2\"\n      and S'=\"[]\"\n      in EValidSplit_Esplit_signature_length)\n    apply(force)\n   apply(clarsimp)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(subgoal_tac \"0\\<le> x \\<and> x \\<le> SSX\" for SSX)\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(rule nat_seq_in_interval)\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(clarsimp)\n  apply(simp add: Esplit_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac x S1 SL S2)(*strict*)\n  apply(simp add: Xstep_gen_def)\n  apply (simp add: Esplit_signature_append)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac x S1 SL S2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      S=\"S1\"\n      and S'=\"SL#S2\"\n      in EValidSplit_Esplit_signature_length)\n   apply(force)\n  apply(rename_tac x S1 SL S2)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac x S1 SL S2)(*strict*)\n   prefer 2\n   apply (rule_tac\n      w=\"SL\"\n      and v=\"S2\"\n      in Esplit_signature_Cons)\n  apply(rename_tac x S1 SL S2)(*strict*)\n  apply(subgoal_tac \"Esplit_signature S1 @ Esplit_signature [SL] @ Esplit_signature S2 = w @ teB b # liftB \\<alpha>1 @ teA A2 # liftB \\<alpha>2\")\n   apply(rename_tac x S1 SL S2)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac x S1 SL S2)(*strict*)\n  apply(thin_tac \"Esplit_signature S1 @ Esplit_signature (SL # S2) = w @ teB b # liftB \\<alpha>1 @ teA A2 # liftB \\<alpha>2\")\n  apply(rename_tac x S1 SL S2)(*strict*)\n  apply(thin_tac \"Esplit_signature (SL # S2) = Esplit_signature [SL] @ Esplit_signature S2\")\n  apply(subgoal_tac \"Esplit_signature [SL] = [teA A2]\")\n   apply(rename_tac x S1 SL S2)(*strict*)\n   prefer 2\n   apply(simp add: Esplit_signature_def option_to_list_def)\n  apply(rename_tac x S1 SL S2)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"Esplit_signature S2 = liftB \\<alpha>2\")\n   apply(rename_tac x S1 SL S2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      ?w1.0=\"Esplit_signature S1\"\n      and A=\"A2\"\n      in equal_terminal_suffix)\n     apply(rename_tac x S1 SL S2)(*strict*)\n     apply(force)\n    apply(rename_tac x S1 SL S2)(*strict*)\n    apply(force)\n   apply(rename_tac x S1 SL S2)(*strict*)\n   apply(rule setA_liftB)\n  apply(rename_tac x S1 SL S2)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"strict_prefix S1 S2a \\<or> SSX\" for SSX)\n   apply(rename_tac x S1 SL S2)(*strict*)\n   prefer 2\n   apply(rule mutual_strict_prefix_prefix)\n   apply(rule sym)\n   apply(force)\n  apply(rename_tac x S1 SL S2)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac x S1 SL S2)(*strict*)\n   apply(simp add: strict_prefix_def)\n   apply(clarsimp)\n  apply(rename_tac x S1 SL S2)(*strict*)\n  apply(simp add: prefix_def)\n  apply(clarsimp)\n  apply(rename_tac x SL S2 c)(*strict*)\n  apply (simp add: Esplit_signature_append)\n  apply(subgoal_tac \"(S2a @ c @ SL # S2) ! x = SSX\" for SSX)\n   apply(rename_tac x SL S2 c)(*strict*)\n   prefer 2\n   apply(rule nth_append_1)\n   apply(force)\n  apply(rename_tac x SL S2 c)(*strict*)\n  apply(clarsimp)\n  done\n\ntheorem Esplit_derivation_enforces_EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal: \"\n  Esplit_TSstructure G\n  \\<Longrightarrow> F2LR1inputx G G'\n  \\<Longrightarrow> split_TSstructure G\n  \\<Longrightarrow> Esplit.derivation_initial G d\n  \\<Longrightarrow> d n = Some (pair e S)\n  \\<Longrightarrow> k<length S\n  \\<Longrightarrow> ESplitItem_elem (S!k) = Some (teA A)\n  \\<Longrightarrow> i<k\n  \\<Longrightarrow> i \\<notin> (Eident_lines S)\"\n  apply(induct n arbitrary: e S k A i)\n   apply(rename_tac e S k A i)(*strict*)\n   apply(simp add: Esplit.derivation_initial_def)\n   apply(clarsimp)\n   apply(rename_tac S k A i)(*strict*)\n   apply(simp add: Esplit_initial_configurations_def)\n  apply(rename_tac n e S k A i)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac n e S k A i)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"G\"\n      and d=\"d\"\n      and n=\"n\"\n      and m=\"Suc n\"\n      in Esplit.step_detail_before_some_position)\n     apply(rename_tac n e S k A i)(*strict*)\n     apply(rule Esplit.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac n e S k A i)(*strict*)\n    apply(force)\n   apply(rename_tac n e S k A i)(*strict*)\n   apply(force)\n  apply(rename_tac n e S k A i)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n S k A i e1 e2 c1)(*strict*)\n  apply(simp add: Esplit_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac n k A i e1 e2 S1 SL S2)(*strict*)\n  apply(erule_tac\n      x=\"e1\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"S1 @ SL # S2\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"length S1\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(case_tac e2)\n  apply(rename_tac n k A i e1 e2 S1 SL S2 prod_lhsa prod_rhsa)(*strict*)\n  apply(rename_tac A w)\n  apply(rename_tac n k Aa i e1 e2 S1 SL S2 A w)(*strict*)\n  apply(erule_tac\n      x=\"A\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(rename_tac n k Aa i e1 S1 SL S2 A w)(*strict*)\n  apply(thin_tac \"Esplit.derivation_initial G d\")\n  apply(thin_tac \"d (Suc n) = Some (pair (Some \\<lparr>prod_lhs = A, prod_rhs = w\\<rparr>) (S1 @ Xstep_mergeL (Xstep_elem SL \\<lparr>prod_lhs = A, prod_rhs = w\\<rparr> # Xstep_gen (filterA (tl w)) (ESplitItem_to SL @ ESplitItem_ignore SL)) (nth_opt S2 0) @ drop (Suc 0) S2))\")\n  apply(rename_tac n k Aa i e1 S1 SL S2 A w)(*strict*)\n  apply(thin_tac \"d n = Some (pair e1 (S1 @ SL # S2))\")\n  apply(case_tac \"i<length S1\")\n   apply(rename_tac n k Aa i e1 S1 SL S2 A w)(*strict*)\n   apply(erule_tac\n      x=\"i\"\n      in meta_allE)\n   apply(clarsimp)\n   apply(rename_tac k Aa i S1 SL S2 A w)(*strict*)\n   apply(simp add: Eident_lines_def Eident_line_def)\n   apply(clarsimp)\n   apply(subgoal_tac \"(S1 @ SL # S2) ! i = (S1 @ Xstep_mergeL (Xstep_elem SL \\<lparr>prod_lhs = A, prod_rhs = w\\<rparr> # Xstep_gen (filterA (tl w)) (ESplitItem_to SL @ ESplitItem_ignore SL)) (nth_opt S2 0) @ drop (Suc 0) S2) ! i\")\n    apply(rename_tac k Aa i S1 SL S2 A w)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac k Aa i S1 SL S2 A w)(*strict*)\n   apply(rule nth_eq_ignore_append)\n     apply(rename_tac k Aa i S1 SL S2 A w)(*strict*)\n     prefer 3\n     apply(force)\n    apply(rename_tac k Aa i S1 SL S2 A w)(*strict*)\n    apply(force)\n   apply(rename_tac k Aa i S1 SL S2 A w)(*strict*)\n   apply(force)\n  apply(rename_tac n k Aa i e1 S1 SL S2 A w)(*strict*)\n  apply(subgoal_tac \"length S1\\<le>i\")\n   apply(rename_tac n k Aa i e1 S1 SL S2 A w)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac n k Aa i e1 S1 SL S2 A w)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k Aa i S1 SL S2 A w)(*strict*)\n  apply(subgoal_tac \"length(Xstep_gen (filterA (tl w)) (ESplitItem_to SL @ ESplitItem_ignore SL)) = SSX\" for SSX)\n   apply(rename_tac k Aa i S1 SL S2 A w)(*strict*)\n   prefer 2\n   apply(rule Xstep_gen_length)\n    apply(rename_tac k Aa i S1 SL S2 A w)(*strict*)\n    apply(simp add: split_TSstructure_def)\n    apply(force)\n   apply(rename_tac k Aa i S1 SL S2 A w)(*strict*)\n   apply(force)\n  apply(rename_tac k Aa i S1 SL S2 A w)(*strict*)\n  apply(case_tac S2)\n   apply(rename_tac k Aa i S1 SL S2 A w)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac k Aa i S1 SL A w)(*strict*)\n   apply(simp add: nth_opt_def)\n   apply(simp add: Xstep_mergeL_def)\n   apply(case_tac \"Xstep_gen (filterA (tl w)) (ESplitItem_to SL @ ESplitItem_ignore SL)\")\n    apply(rename_tac k Aa i S1 SL A w)(*strict*)\n    apply(subgoal_tac \"k < length S1 + (length (if True then [] else Xstep_elem SL \\<lparr>prod_lhs = A, prod_rhs = w\\<rparr> # butlast (Xstep_gen (filterA (tl w)) (ESplitItem_to SL @ ESplitItem_ignore SL))) + length (case ESplitItem_elem (if True then Xstep_elem SL \\<lparr>prod_lhs = A, prod_rhs = w\\<rparr> else last (Xstep_gen (filterA (tl w)) (ESplitItem_to SL @ ESplitItem_ignore SL))) of None \\<Rightarrow> [Xstep_merge1 (last (Xstep_elem SL \\<lparr>prod_lhs = A, prod_rhs = w\\<rparr> # Xstep_gen (filterA (tl w)) (ESplitItem_to SL @ ESplitItem_ignore SL))) EmptyESplitItem] | Some e \\<Rightarrow> [last (Xstep_elem SL \\<lparr>prod_lhs = A, prod_rhs = w\\<rparr> # Xstep_gen (filterA (tl w)) (ESplitItem_to SL @ ESplitItem_ignore SL))]))\")\n     apply(rename_tac k Aa i S1 SL A w)(*strict*)\n     prefer 2\n     apply(rule_tac\n      t=\"True\"\n      and s=\"Xstep_gen (filterA (tl w)) (ESplitItem_to SL @ ESplitItem_ignore SL) = []\"\n      in ssubst)\n      apply(rename_tac k Aa i S1 SL A w)(*strict*)\n      apply(force)\n     apply(rename_tac k Aa i S1 SL A w)(*strict*)\n     apply(force)\n    apply(rename_tac k Aa i S1 SL A w)(*strict*)\n    apply(thin_tac \"k < length S1 + (length (if Xstep_gen (filterA (tl w)) (ESplitItem_to SL @ ESplitItem_ignore SL) = [] then [] else Xstep_elem SL \\<lparr>prod_lhs = A, prod_rhs = w\\<rparr> # butlast (Xstep_gen (filterA (tl w)) (ESplitItem_to SL @ ESplitItem_ignore SL))) + length (case ESplitItem_elem (if Xstep_gen (filterA (tl w)) (ESplitItem_to SL @ ESplitItem_ignore SL) = [] then Xstep_elem SL \\<lparr>prod_lhs = A, prod_rhs = w\\<rparr> else last (Xstep_gen (filterA (tl w)) (ESplitItem_to SL @ ESplitItem_ignore SL))) of None \\<Rightarrow> [Xstep_merge1 (last (Xstep_elem SL \\<lparr>prod_lhs = A, prod_rhs = w\\<rparr> # Xstep_gen (filterA (tl w)) (ESplitItem_to SL @ ESplitItem_ignore SL))) EmptyESplitItem] | Some e \\<Rightarrow> [last (Xstep_elem SL \\<lparr>prod_lhs = A, prod_rhs = w\\<rparr> # Xstep_gen (filterA (tl w)) (ESplitItem_to SL @ ESplitItem_ignore SL))]))\")\n    apply(rename_tac k Aa i S1 SL A w)(*strict*)\n    apply(clarsimp)\n    apply(case_tac \"ESplitItem_elem (Xstep_elem SL \\<lparr>prod_lhs = A, prod_rhs = w\\<rparr>)\")\n     apply(rename_tac k Aa i S1 SL A w)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac k Aa i S1 SL A w a)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac k Aa i S1 SL A w a list)(*strict*)\n   apply(case_tac w)\n    apply(rename_tac k Aa i S1 SL A w a list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n    apply(subgoal_tac \"a#list=[]\")\n     apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n     apply(force)\n    apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n    apply(rule_tac\n      t=\"a#list\"\n      and s=\"Xstep_gen [] (ESplitItem_to SL @ ESplitItem_ignore SL)\"\n      in ssubst)\n     apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n     apply(force)\n    apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n    apply(rule_tac\n      t=\"[]\"\n      and s=\"Xstep_gen [] (ESplitItem_to SL @ ESplitItem_ignore SL)\"\n      in subst)\n     apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n     apply(thin_tac \"Xstep_gen [] (ESplitItem_to SL @ ESplitItem_ignore SL) = a # list\")\n     apply(force)\n    apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n    apply(force)\n   apply(rename_tac k Aa i S1 SL A w a list aa lista)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac k Aa i S1 SL A a list aa lista)(*strict*)\n   apply(case_tac lista)\n    apply(rename_tac k Aa i S1 SL A a list aa lista)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac k Aa i S1 SL A a list aa lista ab listb)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac k Aa i S1 SL A a list aa ab listb)(*strict*)\n   apply(subgoal_tac \"listb=[]\")\n    apply(rename_tac k Aa i S1 SL A a list aa ab listb)(*strict*)\n    prefer 2\n    apply(rule LR1_at_most_two_symbols)\n     apply(rename_tac k Aa i S1 SL A a list aa ab listb)(*strict*)\n     apply(force)\n    apply(rename_tac k Aa i S1 SL A a list aa ab listb)(*strict*)\n    apply(force)\n   apply(rename_tac k Aa i S1 SL A a list aa ab listb)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac k Aa i S1 SL A a aa ab)(*strict*)\n   apply(case_tac ab)\n    apply(rename_tac k Aa i S1 SL A a aa ab ac)(*strict*)\n    prefer 2\n    apply(rename_tac k Aa i S1 SL A a aa ab b)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac k Aa i S1 SL A a aa b)(*strict*)\n    apply(simp add: Xstep_gen_def)\n   apply(rename_tac k Aa i S1 SL A a aa ab ac)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac k Aa i S1 SL A a aa ac)(*strict*)\n   apply(simp add: Xstep_gen_def)\n   apply(subgoal_tac \"nat_seq 0 0 = [0]\")\n    apply(rename_tac k Aa i S1 SL A a aa ac)(*strict*)\n    prefer 2\n    apply (metis natUptTo_n_n)\n   apply(rename_tac k Aa i S1 SL A a aa ac)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac k Aa i S1 SL A aa ac)(*strict*)\n   apply(simp add: Xstep_elem_def)\n   apply(simp add: Xstep_gen_def)\n   apply(simp add: nth_opt_def)\n   apply(case_tac \"Suc k = Suc (Suc (length S1))\")\n    apply(rename_tac k Aa i S1 SL A aa ac)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac Aa i S1 SL A aa ac)(*strict*)\n    apply(subgoal_tac \"(S1 @ [SL\\<lparr>ESplitItem_prods := ESplitItem_prods SL @ [\\<lparr>prod_lhs = A, prod_rhs = [aa, teA ac]\\<rparr>], ESplitItem_elem := Some aa, ESplitItem_to := ac # ESplitItem_to SL\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some ac, ESplitItem_ignore = ESplitItem_to SL @ ESplitItem_ignore SL, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA ac), ESplitItem_to = []\\<rparr>]) ! Suc (length S1) = [\\<lparr>ESplitItem_elim = [], ESplitItem_from = Some ac, ESplitItem_ignore = ESplitItem_to SL @ ESplitItem_ignore SL, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA ac), ESplitItem_to = []\\<rparr>]!SSX\" for SSX)\n     apply(rename_tac Aa i S1 SL A aa ac)(*strict*)\n     prefer 2\n     apply(rule nth_append_2_prime)\n       apply(rename_tac Aa i S1 SL A aa ac)(*strict*)\n       apply(force)\n      apply(rename_tac Aa i S1 SL A aa ac)(*strict*)\n      apply(force)\n     apply(rename_tac Aa i S1 SL A aa ac)(*strict*)\n     apply(force)\n    apply(rename_tac Aa i S1 SL A aa ac)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac Aa i S1 SL A aa)(*strict*)\n    apply(case_tac \"i=length S1\")\n     apply(rename_tac Aa i S1 SL A aa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac Aa S1 SL A aa)(*strict*)\n     apply(simp add: Eident_lines_def Eident_line_def)\n    apply(rename_tac Aa i S1 SL A aa)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac k Aa i S1 SL A aa ac)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac k Aa i S1 SL S2 A w a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k Aa i S1 SL A w a list)(*strict*)\n  apply(simp add: nth_opt_def)\n  apply(case_tac w)\n   apply(rename_tac k Aa i S1 SL A w a list)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n   apply(simp add: Xstep_mergeL_def)\n   apply(simp add: Xstep_gen_def)\n   apply(simp add: Xstep_elem_def)\n   apply(simp add: nth_opt_def)\n   apply(simp add: Xstep_merge1_def)\n   apply(case_tac \"strict_prefix (ESplitItem_elim a) (ESplitItem_to (Xstep_elem SL \\<lparr>prod_lhs = A, prod_rhs = []\\<rparr>))\")\n    apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n    apply(clarsimp)\n    apply(simp add: Xstep_merge1_toWasNotEliminated_def Xstep_elem_def)\n    apply(case_tac \"length S1=k\")\n     apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n    apply(subgoal_tac \"length S1 < k\")\n     apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"(S1 @ \\<lparr>ESplitItem_elim = ESplitItem_elim SL, ESplitItem_from = ESplitItem_from SL, ESplitItem_ignore = ESplitItem_ignore SL, ESplitItem_elim_prods = ESplitItem_elim_prods SL, ESplitItem_prods = ESplitItem_prods SL @ \\<lparr>prod_lhs = A, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods a) @ ESplitItem_prods a, ESplitItem_elem = ESplitItem_elem a, ESplitItem_to = ESplitItem_to a @ drop (length (ESplitItem_elim a) + length (option_to_list (ESplitItem_from a))) (ESplitItem_to SL)\\<rparr> # list) ! k = SSlistX\" for SSlistX)\n     apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n     prefer 2\n     apply(rule nth_append_2_prime)\n       apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n       apply(force)\n      apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n      apply(force)\n     apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n     apply(force)\n    apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n    apply(clarsimp)\n    apply(thin_tac \"(S1 @ \\<lparr>ESplitItem_elim = ESplitItem_elim SL, ESplitItem_from = ESplitItem_from SL, ESplitItem_ignore = ESplitItem_ignore SL, ESplitItem_elim_prods = ESplitItem_elim_prods SL, ESplitItem_prods = ESplitItem_prods SL @ \\<lparr>prod_lhs = A, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods a) @ ESplitItem_prods a, ESplitItem_elem = ESplitItem_elem a, ESplitItem_to = ESplitItem_to a @ drop (length (ESplitItem_elim a) + length (option_to_list (ESplitItem_from a))) (ESplitItem_to SL)\\<rparr> # list) ! k = list ! (k - Suc (length S1))\")\n    apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n    apply(rule Esplit_signature_Cons_not_empty_setA2)\n      apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n      apply(force)\n     apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n     apply(force)\n    apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n    apply(force)\n   apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n   apply(clarsimp)\n   apply(simp add: Xstep_merge1_toWasEliminated_def Xstep_elem_def)\n   apply(subgoal_tac \"(S1 @ \\<lparr>ESplitItem_elim = ESplitItem_elim SL @ option_to_list (ESplitItem_from SL) @ drop (length (ESplitItem_to SL)) (ESplitItem_elim a), ESplitItem_from = ESplitItem_from a, ESplitItem_ignore = ESplitItem_ignore a, ESplitItem_elim_prods = ESplitItem_elim_prods SL @ (ESplitItem_prods SL @ \\<lparr>prod_lhs = A, prod_rhs = []\\<rparr> # foldl (@) [] (take (length (ESplitItem_to SL)) (ESplitItem_elim_prods a))) # drop (length (ESplitItem_to SL)) (ESplitItem_elim_prods a), ESplitItem_prods = ESplitItem_prods a, ESplitItem_elem = ESplitItem_elem a, ESplitItem_to = ESplitItem_to a\\<rparr> # list) ! k = SSlistX\" for SSlistX)\n    apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n    prefer 2\n    apply(rule nth_append_2_prime)\n      apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n      apply(force)\n     apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n     apply(force)\n    apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n    apply(force)\n   apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n   apply(clarsimp)\n   apply(thin_tac \"(S1 @ \\<lparr>ESplitItem_elim = ESplitItem_elim SL @ option_to_list (ESplitItem_from SL) @ drop (length (ESplitItem_to SL)) (ESplitItem_elim a), ESplitItem_from = ESplitItem_from a, ESplitItem_ignore = ESplitItem_ignore a, ESplitItem_elim_prods = ESplitItem_elim_prods SL @ (ESplitItem_prods SL @ \\<lparr>prod_lhs = A, prod_rhs = []\\<rparr> # foldl (@) [] (take (length (ESplitItem_to SL)) (ESplitItem_elim_prods a))) # drop (length (ESplitItem_to SL)) (ESplitItem_elim_prods a), ESplitItem_prods = ESplitItem_prods a, ESplitItem_elem = ESplitItem_elem a, ESplitItem_to = ESplitItem_to a\\<rparr> # list) ! k = list ! (k - Suc (length S1))\")\n   apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n   apply(rule Esplit_signature_Cons_not_empty_setA2)\n     apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n     apply(force)\n    apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n    apply(force)\n   apply(rename_tac k Aa i S1 SL A a list)(*strict*)\n   apply(force)\n  apply(rename_tac k Aa i S1 SL A w a list aa lista)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k Aa i S1 SL A a list aa lista)(*strict*)\n  apply(case_tac lista)\n   apply(rename_tac k Aa i S1 SL A a list aa lista)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac k Aa i S1 SL A a list aa)(*strict*)\n   apply(simp add: Xstep_mergeL_def)\n   apply(simp add: Xstep_gen_def)\n   apply(simp add: Xstep_elem_def)\n   apply(simp add: nth_opt_def)\n   apply(simp add: Xstep_elem_def)\n   apply(subgoal_tac \"(S1 @ SL\\<lparr>ESplitItem_prods := ESplitItem_prods SL @ [\\<lparr>prod_lhs = A, prod_rhs = [aa]\\<rparr>], ESplitItem_elem := nth_opt [aa] 0\\<rparr> # a # list) ! k = (a#list)!SSX\" for SSX)\n    apply(rename_tac k Aa i S1 SL A a list aa)(*strict*)\n    prefer 2\n    apply(rule nth_append_2_prime)\n      apply(rename_tac k Aa i S1 SL A a list aa)(*strict*)\n      apply(force)\n     apply(rename_tac k Aa i S1 SL A a list aa)(*strict*)\n     apply(force)\n    apply(rename_tac k Aa i S1 SL A a list aa)(*strict*)\n    apply(force)\n   apply(rename_tac k Aa i S1 SL A a list aa)(*strict*)\n   apply(clarsimp)\n   apply(thin_tac \"(S1 @ SL\\<lparr>ESplitItem_prods := ESplitItem_prods SL @ [\\<lparr>prod_lhs = A, prod_rhs = [aa]\\<rparr>], ESplitItem_elem := nth_opt [aa] 0\\<rparr> # a # list) ! k = (a # list) ! (k - Suc (length S1))\")\n   apply(rename_tac k Aa i S1 SL A a list aa)(*strict*)\n   apply(case_tac \"k-Suc(length S1)\")\n    apply(rename_tac k Aa i S1 SL A a list aa)(*strict*)\n    apply(clarsimp)\n    apply(rule Esplit_signature_Cons_not_empty_setA)\n     apply(rename_tac k Aa i S1 SL A a list aa)(*strict*)\n     apply(force)\n    apply(rename_tac k Aa i S1 SL A a list aa)(*strict*)\n    apply(force)\n   apply(rename_tac k Aa i S1 SL A a list aa nat)(*strict*)\n   apply(clarsimp)\n   apply(rule Esplit_signature_Cons_not_empty_setA2)\n     apply(rename_tac k Aa i S1 SL A a list aa nat)(*strict*)\n     apply(force)\n    apply(rename_tac k Aa i S1 SL A a list aa nat)(*strict*)\n    apply(force)\n   apply(rename_tac k Aa i S1 SL A a list aa nat)(*strict*)\n   apply(force)\n  apply(rename_tac k Aa i S1 SL A a list aa lista ab listb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k Aa i S1 SL A a list aa ab listb)(*strict*)\n  apply(subgoal_tac \"listb=[]\")\n   apply(rename_tac k Aa i S1 SL A a list aa ab listb)(*strict*)\n   prefer 2\n   apply(rule LR1_at_most_two_symbols)\n    apply(rename_tac k Aa i S1 SL A a list aa ab listb)(*strict*)\n    apply(force)\n   apply(rename_tac k Aa i S1 SL A a list aa ab listb)(*strict*)\n   apply(force)\n  apply(rename_tac k Aa i S1 SL A a list aa ab listb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k Aa i S1 SL A a list aa ab)(*strict*)\n  apply(case_tac ab)\n   apply(rename_tac k Aa i S1 SL A a list aa ab ac)(*strict*)\n   prefer 2\n   apply(rename_tac k Aa i S1 SL A a list aa ab b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac k Aa i S1 SL A a list aa b)(*strict*)\n   apply(rule LR1_terminal_only_at_front_in_prods)\n    apply(rename_tac k Aa i S1 SL A a list aa b)(*strict*)\n    apply(force)\n   apply(rename_tac k Aa i S1 SL A a list aa b)(*strict*)\n   apply(force)\n  apply(rename_tac k Aa i S1 SL A a list aa ab ac)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k Aa i S1 SL A a list aa ac)(*strict*)\n  apply(simp add: Xstep_mergeL_def)\n  apply(simp add: Xstep_gen_def)\n  apply(subgoal_tac \"nat_seq 0 0 = [0]\")\n   apply(rename_tac k Aa i S1 SL A a list aa ac)(*strict*)\n   prefer 2\n   apply (metis natUptTo_n_n)\n  apply(rename_tac k Aa i S1 SL A a list aa ac)(*strict*)\n  apply(clarsimp)\n  apply(simp add: Xstep_gen_def)\n  apply(simp add: Xstep_elem_def)\n  apply(simp add: nth_opt_def)\n  apply(subgoal_tac \"(S1 @ SL\\<lparr>ESplitItem_prods := ESplitItem_prods SL @ [\\<lparr>prod_lhs = A, prod_rhs = [aa, teA ac]\\<rparr>], ESplitItem_elem := Some aa, ESplitItem_to := ac # ESplitItem_to SL\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some ac, ESplitItem_ignore = ESplitItem_to SL @ ESplitItem_ignore SL, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA ac), ESplitItem_to = []\\<rparr> # a # list) ! k = (SL\\<lparr>ESplitItem_prods := ESplitItem_prods SL @ [\\<lparr>prod_lhs = A, prod_rhs = [aa, teA ac]\\<rparr>], ESplitItem_elem := Some aa, ESplitItem_to := ac # ESplitItem_to SL\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some ac, ESplitItem_ignore = ESplitItem_to SL @ ESplitItem_ignore SL, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA ac), ESplitItem_to = []\\<rparr> # a # list)!SSX\" for SSX)\n   apply(rename_tac k Aa i S1 SL A a list aa ac)(*strict*)\n   prefer 2\n   apply(rule nth_append_2_prime)\n     apply(rename_tac k Aa i S1 SL A a list aa ac)(*strict*)\n     apply(force)\n    apply(rename_tac k Aa i S1 SL A a list aa ac)(*strict*)\n    apply(force)\n   apply(rename_tac k Aa i S1 SL A a list aa ac)(*strict*)\n   apply(force)\n  apply(rename_tac k Aa i S1 SL A a list aa ac)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k Aa i S1 SL A a list aa ac)(*strict*)\n  apply(case_tac \"k-length S1\")\n   apply(rename_tac k Aa i S1 SL A a list aa ac)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac k Aa i S1 SL A a list aa ac nat)(*strict*)\n  apply(subgoal_tac \"k=Suc nat+length S1\")\n   apply(rename_tac k Aa i S1 SL A a list aa ac nat)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac k Aa i S1 SL A a list aa ac nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac Aa i S1 SL A a list aa ac nat)(*strict*)\n  apply(case_tac nat)\n   apply(rename_tac Aa i S1 SL A a list aa ac nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac Aa i S1 SL A a list aa)(*strict*)\n   apply(subgoal_tac \"i=length S1\")\n    apply(rename_tac Aa i S1 SL A a list aa)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac Aa i S1 SL A a list aa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac Aa S1 SL A a list aa)(*strict*)\n   apply(simp add: Eident_lines_def Eident_line_def)\n  apply(rename_tac Aa i S1 SL A a list aa ac nat nata)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac Aa i S1 SL A a list aa ac nata)(*strict*)\n  apply(case_tac \"i=Suc(length S1)\")\n   apply(rename_tac Aa i S1 SL A a list aa ac nata)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac Aa S1 SL A a list aa ac nata)(*strict*)\n   apply(simp add: Eident_lines_def Eident_line_def)\n   apply(clarsimp)\n   apply(subgoal_tac \"(S1 @ SL\\<lparr>ESplitItem_prods := ESplitItem_prods SL @ [\\<lparr>prod_lhs = A, prod_rhs = [aa, teA ac]\\<rparr>], ESplitItem_elem := Some aa, ESplitItem_to := ac # ESplitItem_to SL\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some ac, ESplitItem_ignore = ESplitItem_to SL @ ESplitItem_ignore SL, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA ac), ESplitItem_to = []\\<rparr> # a # list) ! Suc (length S1) = (\\<lparr>ESplitItem_elim = [], ESplitItem_from = Some ac, ESplitItem_ignore = ESplitItem_to SL @ ESplitItem_ignore SL, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA ac), ESplitItem_to = []\\<rparr> # a # list)!SSY\" for SSY)\n    apply(rename_tac Aa S1 SL A a list aa ac nata)(*strict*)\n    prefer 2\n    apply(rule nth_append_2_prime)\n      apply(rename_tac Aa S1 SL A a list aa ac nata)(*strict*)\n      apply(force)\n     apply(rename_tac Aa S1 SL A a list aa ac nata)(*strict*)\n     apply(force)\n    apply(rename_tac Aa S1 SL A a list aa ac nata)(*strict*)\n    apply(force)\n   apply(rename_tac Aa S1 SL A a list aa ac nata)(*strict*)\n   apply(clarsimp)\n   apply(case_tac nata)\n    apply(rename_tac Aa S1 SL A a list aa ac nata)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac Aa S1 SL A a list aa ac)(*strict*)\n    apply(rule Esplit_signature_Cons_not_empty_setA)\n     apply(rename_tac Aa S1 SL A a list aa ac)(*strict*)\n     apply(force)\n    apply(rename_tac Aa S1 SL A a list aa ac)(*strict*)\n    apply(force)\n   apply(rename_tac Aa S1 SL A a list aa ac nata nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac Aa S1 SL A a list aa ac nat)(*strict*)\n   apply(rule Esplit_signature_Cons_not_empty_setA2)\n     apply(rename_tac Aa S1 SL A a list aa ac nat)(*strict*)\n     apply(force)\n    apply(rename_tac Aa S1 SL A a list aa ac nat)(*strict*)\n    apply(force)\n   apply(rename_tac Aa S1 SL A a list aa ac nat)(*strict*)\n   apply(force)\n  apply(rename_tac Aa i S1 SL A a list aa ac nata)(*strict*)\n  apply(simp add: Eident_lines_def Eident_line_def)\n  apply(subgoal_tac \"(S1 @ SL\\<lparr>ESplitItem_prods := ESplitItem_prods SL @ [\\<lparr>prod_lhs = A, prod_rhs = [aa, teA ac]\\<rparr>], ESplitItem_elem := Some aa, ESplitItem_to := ac # ESplitItem_to SL\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some ac, ESplitItem_ignore = ESplitItem_to SL @ ESplitItem_ignore SL, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA ac), ESplitItem_to = []\\<rparr> # a # list) ! i = (a#list)!SSX\" for SSX)\n   apply(rename_tac Aa i S1 SL A a list aa ac nata)(*strict*)\n   prefer 2\n   apply(rule nth_append_2_prime)\n     apply(rename_tac Aa i S1 SL A a list aa ac nata)(*strict*)\n     apply(force)\n    apply(rename_tac Aa i S1 SL A a list aa ac nata)(*strict*)\n    apply(force)\n   apply(rename_tac Aa i S1 SL A a list aa ac nata)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"i<Suc (Suc (length S1))\")\n    apply(rename_tac Aa i S1 SL A a list aa ac nata)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac Aa i S1 SL A a list aa ac nata)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"Suc i=Suc (Suc (length S1))\")\n    apply(rename_tac Aa i S1 SL A a list aa ac nata)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac Aa i S1 SL A a list aa ac nata)(*strict*)\n   apply(subgoal_tac \"i < (Suc (length S1))\")\n    apply(rename_tac Aa i S1 SL A a list aa ac nata)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac Aa i S1 SL A a list aa ac nata)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"Suc i = Suc(length S1)\")\n    apply(rename_tac Aa i S1 SL A a list aa ac nata)(*strict*)\n    apply(force)\n   apply(rename_tac Aa i S1 SL A a list aa ac nata)(*strict*)\n   apply(subgoal_tac \"Suc i<Suc (length S1)\")\n    apply(rename_tac Aa i S1 SL A a list aa ac nata)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac Aa i S1 SL A a list aa ac nata)(*strict*)\n   apply(force)\n  apply(rename_tac Aa i S1 SL A a list aa ac nata)(*strict*)\n  apply(clarsimp)\n  apply(case_tac nata)\n   apply(rename_tac Aa i S1 SL A a list aa ac nata)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac Aa i S1 SL A a list aa ac)(*strict*)\n   apply(rule Esplit_signature_Cons_not_empty_setA)\n    apply(rename_tac Aa i S1 SL A a list aa ac)(*strict*)\n    apply(force)\n   apply(rename_tac Aa i S1 SL A a list aa ac)(*strict*)\n   apply(force)\n  apply(rename_tac Aa i S1 SL A a list aa ac nata nat)(*strict*)\n  apply(rule Esplit_signature_Cons_not_empty_setA2)\n    apply(rename_tac Aa i S1 SL A a list aa ac nata nat)(*strict*)\n    apply(force)\n   apply(rename_tac Aa i S1 SL A a list aa ac nata nat)(*strict*)\n   apply(force)\n  apply(rename_tac Aa i S1 SL A a list aa ac nata nat)(*strict*)\n  apply(force)\n  done\n\ntheorem Esplit_derivation_enforces_EValidSplitExt: \"\n  Esplit_TSstructure G\n  \\<Longrightarrow> F2LR1inputx G G'\n  \\<Longrightarrow> split_TSstructure G\n  \\<Longrightarrow> Esplit.derivation_initial G d\n  \\<Longrightarrow> d n = Some (pair e S)\n  \\<Longrightarrow> EValidSplitExt S\"\n  apply(simp add: EValidSplitExt_def)\n  apply(rule conjI)\n   apply(simp add: EValidSplitExt_no_elim_before_nonterminal_def)\n   apply(clarsimp)\n   apply(rename_tac k A i)(*strict*)\n   apply(rule Esplit_derivation_enforces_EValidSplitExt_no_elim_before_nonterminal)\n          apply(rename_tac k A i)(*strict*)\n          apply(force)\n         apply(rename_tac k A i)(*strict*)\n         apply(force)\n        apply(rename_tac k A i)(*strict*)\n        apply(force)\n       apply(rename_tac k A i)(*strict*)\n       apply(force)\n      apply(rename_tac k A i)(*strict*)\n      apply(force)\n     apply(rename_tac k A i)(*strict*)\n     apply(force)\n    apply(rename_tac k A i)(*strict*)\n    apply(force)\n   apply(rename_tac k A i)(*strict*)\n   apply(force)\n  apply(rule conjI)\n   apply(simp add: EValidSplitExt_no_pop_in_prods_before_nonterminal_def)\n   apply(clarsimp)\n   apply(rename_tac k A i j)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac k A i j)(*strict*)\n    prefer 2\n    apply(rule Esplit_derivation_enforces_EValidSplitExt_no_pop_in_prods_before_nonterminal)\n            apply(rename_tac k A i j)(*strict*)\n            apply(force)\n           apply(rename_tac k A i j)(*strict*)\n           apply(force)\n          apply(rename_tac k A i j)(*strict*)\n          apply(force)\n         apply(rename_tac k A i j)(*strict*)\n         apply(force)\n        apply(rename_tac k A i j)(*strict*)\n        apply(force)\n       apply(rename_tac k A i j)(*strict*)\n       apply(force)\n      apply(rename_tac k A i j)(*strict*)\n      apply(force)\n     apply(rename_tac k A i j)(*strict*)\n     apply(force)\n    apply(rename_tac k A i j)(*strict*)\n    apply(force)\n   apply(rename_tac k A i j)(*strict*)\n   apply(force)\n  apply(simp add: EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal_def)\n  apply(rule allI)\n  apply(rename_tac k)(*strict*)\n  apply(rule impI)\n  apply(rule impI)\n  apply(rule allI)\n  apply(rename_tac k i)(*strict*)\n  apply(rule impI)\n  apply(erule exE)+\n  apply(rename_tac k i A)(*strict*)\n  apply(rule Esplit_derivation_enforces_EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal)\n         apply(rename_tac k i A)(*strict*)\n         apply(force)\n        apply(rename_tac k i A)(*strict*)\n        apply(force)\n       apply(rename_tac k i A)(*strict*)\n       apply(force)\n      apply(rename_tac k i A)(*strict*)\n      apply(force)\n     apply(rename_tac k i A)(*strict*)\n     apply(force)\n    apply(rename_tac k i A)(*strict*)\n    apply(force)\n   apply(rename_tac k i A)(*strict*)\n   apply(force)\n  apply(rename_tac k i A)(*strict*)\n  apply(force)\n  done\n\nhide_fact Esplit_derivation_enforces_EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal\n  (* important entirely_ignored_can_not_happend_to_early *)\n  (* important Esplit_derivation_enforces_EValidSplitExt *)\n  (* important restrict_equal_before_step_nonterminal *)\n\nend\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_12_04_06_06_11/LR1_Property_Satisfaction__entire_derivation_tree_invariant.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331462646254, "lm_q2_score": 0.46101677931231594, "lm_q1q2_score": 0.27496568816602907}}
{"text": "(* \n   Title: The pi-calculus   \n   Author/Maintainer: Jesper Bengtson (jebe.dk), 2012\n*)\ntheory Weak_Late_Bisim_Subst_SC\n  imports Weak_Late_Bisim_Subst Strong_Late_Bisim_Subst_SC\nbegin\n\n(******** Structural Congruence **********)\n\n(******** The \\<nu>-operator *****************)\n\nlemma resComm:\n  fixes P :: pi\n  \n  shows \"<\\<nu>a><\\<nu>b>P \\<approx>\\<^sup>s <\\<nu>b><\\<nu>a>P\"\nproof -\n  have \"<\\<nu>a><\\<nu>b>P \\<sim>\\<^sup>s <\\<nu>b><\\<nu>a>P\"\n    by(rule Strong_Late_Bisim_Subst_SC.resComm)\n  thus ?thesis by(rule strongBisimWeakBisim)\nqed\n\n(******** Match *********)\n\nlemma matchId:\n  fixes a :: name\n  and   P :: pi\n\n  shows \"[a\\<frown>a]P \\<approx>\\<^sup>s P\"\nproof -\n  have \"[a\\<frown>a]P \\<sim>\\<^sup>s P\" by(rule Strong_Late_Bisim_Subst_SC.matchId)\n  thus ?thesis by(rule strongBisimWeakBisim)\nqed\n\n(******** Mismatch *********)\n\n\n\n  shows \"[a\\<noteq>a]P \\<approx>\\<^sup>s \\<zero>\"\nproof -\n  have \"[a\\<noteq>a]P \\<sim>\\<^sup>s \\<zero>\" by(rule Strong_Late_Bisim_Subst_SC.mismatchNil)\n  thus ?thesis by(rule strongBisimWeakBisim)\nqed\n\n(******** The +-operator *********)\n\nlemma sumSym:\n  fixes P :: pi\n  and   Q :: pi\n  \n  shows \"P \\<oplus> Q \\<approx>\\<^sup>s Q \\<oplus> P\"\nproof -\n  have \"P \\<oplus> Q \\<sim>\\<^sup>s Q \\<oplus> P\" by(rule Strong_Late_Bisim_Subst_SC.sumSym)\n  thus ?thesis by(rule strongBisimWeakBisim)\nqed\n\n\n\n\n\n(******** The |-operator *********)\n\nlemma parZero:\n  fixes P :: pi\n\n  shows \"P \\<parallel> \\<zero> \\<approx>\\<^sup>s P\"\nproof -\n  have \"P \\<parallel> \\<zero> \\<sim>\\<^sup>s P\" by(rule Strong_Late_Bisim_Subst_SC.parZero)\n  thus ?thesis by(rule strongBisimWeakBisim)\nqed\n\nlemma parSym:\n  fixes P :: pi\n  and   Q :: pi\n\n  shows \"P \\<parallel> Q \\<approx>\\<^sup>s Q \\<parallel> P\"\nproof -\n  have \"P \\<parallel> Q \\<sim>\\<^sup>s Q \\<parallel> P\" by(rule Strong_Late_Bisim_Subst_SC.parSym)\n  thus ?thesis by(rule strongBisimWeakBisim)\nqed\n\n\n\n  assumes \"x \\<sharp> P\"\n\n  shows \"<\\<nu>x>(P \\<parallel> Q) \\<approx>\\<^sup>s P \\<parallel> <\\<nu>x>Q\"\nproof -\n  from `x \\<sharp> P` have \"<\\<nu>x>(P \\<parallel> Q) \\<sim>\\<^sup>s P \\<parallel> <\\<nu>x>Q\" by(rule Strong_Late_Bisim_Subst_SC.scopeExtPar)\n  thus ?thesis by(rule strongBisimWeakBisim)\nqed\n\nlemma scopeExtPar':\n  fixes P :: pi\n  and   Q :: pi\n  and   x :: name\n\n  assumes \"x \\<sharp> Q\"\n\n  shows \"<\\<nu>x>(P \\<parallel> Q) \\<approx>\\<^sup>s (<\\<nu>x>P) \\<parallel> Q\"\nproof -\n  from `x \\<sharp> Q` have \"<\\<nu>x>(P \\<parallel> Q) \\<sim>\\<^sup>s (<\\<nu>x>P) \\<parallel> Q\" by(rule Strong_Late_Bisim_Subst_SC.scopeExtPar')\n  thus ?thesis by(rule strongBisimWeakBisim)\nqed\n\n\n\n  shows \"(P \\<parallel> Q) \\<parallel> R \\<approx>\\<^sup>s P \\<parallel> (Q \\<parallel> R)\"\nproof -\n  have \"(P \\<parallel> Q) \\<parallel> R \\<sim>\\<^sup>s P \\<parallel> (Q \\<parallel> R)\" by(rule Strong_Late_Bisim_Subst_SC.parAssoc)\n  thus ?thesis by(rule strongBisimWeakBisim)\nqed\n\nlemma freshRes:\n  fixes P :: pi\n  and   a :: name\n\n  assumes \"a \\<sharp> P\"\n\n  shows \"<\\<nu>a>P \\<approx>\\<^sup>s P\"\nusing assms\nproof -\n  from `a \\<sharp> P` have \"<\\<nu>a>P \\<sim>\\<^sup>s P\" by(rule Strong_Late_Bisim_Subst_SC.scopeFresh)\n  thus ?thesis by(rule strongBisimWeakBisim)\nqed\n\nlemma scopeExtSum:\n  fixes P :: pi\n  and   Q :: pi\n  and   x :: name\n  \n  assumes \"x \\<sharp> P\"\n\n  shows \"<\\<nu>x>(P \\<oplus> Q) \\<approx>\\<^sup>s P \\<oplus> <\\<nu>x>Q\"\nproof -\n  from `x \\<sharp> P` have \"<\\<nu>x>(P \\<oplus> Q) \\<sim>\\<^sup>s P \\<oplus> <\\<nu>x>Q\" by(rule Strong_Late_Bisim_Subst_SC.scopeExtSum)\n  thus ?thesis by(rule strongBisimWeakBisim)\nqed\n\nlemma bangSC:\n  fixes P\n\n  shows \"!P \\<approx>\\<^sup>s P \\<parallel> !P\"\nproof -\n  have \"!P \\<sim>\\<^sup>s P \\<parallel> !P\" by(rule Strong_Late_Bisim_Subst_SC.bangSC)\n  thus ?thesis by(rule strongBisimWeakBisim)\nqed\n\nend", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Pi_Calculus/Weak_Late_Bisim_Subst_SC.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331462646254, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.274965688166029}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |               December 2004               |\n            |                   June 2005  (modified)   |\n            |              September 2005  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |               November 2005  (modified)   |\n            |               December 2005  (modified)   |\n            |                  April 2006  (modified)   |\n            |                  March 2007  (modified)   |\n            |                 August 2007  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory CSP_F_law\nimports CSP_F_law_SKIP      CSP_F_law_ref\n        CSP_F_law_dist      CSP_F_law_alpha_par \n        CSP_F_law_step      CSP_F_law_rep_par   \n        CSP_F_law_fix\n        CSP_F_law_DIV       CSP_F_law_SKIP_DIV  \n        CSP_F_law_step_ext  CSP_F_law_norm      \n        CSP_T.CSP_T_law\nbegin\n\n(*********************************************************\n            SKIP , DIV  and Internal choice\n *********************************************************)\n\n(*** |~| ***)\n\nlemma cspF_SKIP_DIV_Int_choice: \n  \"[| P = SKIP | P = DIV ; Q = SKIP | Q = DIV |] ==>\n   (P |~| Q) =F[M1,M2] (if (P = SKIP | Q = SKIP) then SKIP else DIV)\"\napply (elim disjE)\napply (simp_all)\napply (rule cspF_rw_left)\napply (rule cspF_idem)\napply (rule cspF_reflex)\napply (rule cspF_rw_left)\napply (rule cspF_unit)\napply (rule cspF_reflex)\napply (rule cspF_rw_left)\napply (rule cspF_unit)\napply (rule cspF_reflex)\napply (rule cspF_rw_left)\napply (rule cspF_idem)\napply (rule cspF_reflex)\ndone\n\n(*** !! ***)\n\nlemma cspF_SKIP_DIV_Rep_int_choice_sum: \n  \"[| ALL c: sumset C. (Qf c = SKIP | Qf c = DIV) |] ==>\n   (!! c:C .. Qf c) =F[M1,M2] \n   (if (EX c: sumset C. Qf c = SKIP) then SKIP else DIV)\"\napply (case_tac \" sumset C={}\")\napply (simp add: cspF_Rep_int_choice_empty)\napply (case_tac \"ALL c: sumset C. Qf c = DIV\")\n apply (simp)\n apply (rule cspF_rw_left)\n apply (rule cspF_Rep_int_choice_const)\n apply (simp)\n apply (force)\n apply (simp)\n\n apply (simp)\n apply (elim bexE)\n apply (frule_tac x=\"c\" in bspec)\n apply (simp_all)\n apply (intro conjI impI)\n\n  apply (rule cspF_rw_left)\n  apply (subgoal_tac \n  \"!! :C .. Qf =F[M1,M1]\n   !! :({c:C. Qf c = SKIP}s Uns {c:C. Qf c ~= SKIP}s) .. Qf\")\n  apply (simp (no_asm))\n  apply (rule cspF_decompo)\n   apply (simp)\n   apply (simp)\n\n  apply (rule cspF_rw_left)\n  apply (rule cspF_Rep_int_choice_union_Int)\n  apply (simp)\n\n  apply (rule cspF_rw_left)\n  apply (rule cspF_decompo)\n  apply (rule cspF_Rep_int_choice_const)\n  apply (force)\n  apply (rule ballI)\n  apply (simp)\n  apply (case_tac \" sumset ({c:C. Qf c ~= SKIP}s) ={}\")\n   apply (rule cspF_Rep_int_choice_DIV)\n   apply (simp)\n\n   apply (rule cspF_rw_left)\n   apply (rule cspF_Rep_int_choice_const)\n   apply (simp_all)\n   apply (intro allI impI)\n   apply (subgoal_tac \"Qf ca = DIV\")\n   apply (simp)\n   apply (force)\n   apply (simp)\n\n  apply (rule cspF_rw_left)\n  apply (rule cspF_unit)\n  apply (simp)\ndone\n\nlemma cspF_SKIP_DIV_Rep_int_choice_nat: \n  \"[| ALL n:N. (Qf n = SKIP | Qf n = DIV) |] ==>\n   (!nat n:N .. Qf n) =F[M1,M2] \n   (if (EX n:N. Qf n = SKIP) then SKIP else DIV)\"\napply (unfold Rep_int_choice_ss_def)\napply (rule cspF_rw_left)\napply (rule cspF_SKIP_DIV_Rep_int_choice_sum)\napply (auto)\ndone\n\nlemma cspF_SKIP_DIV_Rep_int_choice_set: \n  \"[| ALL X:Xs. (Qf X = SKIP | Qf X = DIV) |] ==>\n   (!set X:Xs .. Qf X) =F[M1,M2] \n   (if (EX X:Xs. Qf X = SKIP) then SKIP else DIV)\"\napply (unfold Rep_int_choice_ss_def)\napply (rule cspF_rw_left)\napply (rule cspF_SKIP_DIV_Rep_int_choice_sum)\napply (auto)\ndone\n\nlemmas cspF_SKIP_DIV_Rep_int_choice =\n       cspF_SKIP_DIV_Rep_int_choice_sum\n       cspF_SKIP_DIV_Rep_int_choice_nat\n       cspF_SKIP_DIV_Rep_int_choice_set\n\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/CSP_F/CSP_F_law.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6224593312018546, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.2749234837159158}}
{"text": "theory TopoS_Interface_impl\nimports \"Lib/FiniteGraph\" \"Lib/FiniteListGraph\" TopoS_Interface TopoS_Helper\nbegin\n\nsection\\<open>Executable Implementation with Lists\\<close>\n  text \\<open>Correspondence List Implementation and set Specification\\<close>\n  \n  subsection\\<open>Abstraction from list implementation to set specification\\<close>\n  text\\<open>Nomenclature: \\<open>_spec\\<close> is the specification, \\<open>_impl\\<close> the corresponding implementation.\\<close>\n\n  text\\<open>\\<open>_spec\\<close> and \\<open>_impl\\<close> only need to comply for @{const wf_graph}s. \n   We will always require the stricter @{const wf_list_graph}, which implies @{const wf_graph}.\n\\<close>\n  lemma \"wf_list_graph G \\<Longrightarrow> wf_graph (list_graph_to_graph G)\"\n    by %invisible (metis wf_list_graph_def wf_list_graph_iff_wf_graph)\n\n  locale TopoS_List_Impl = \n    fixes default_node_properties :: \"'a\" (\"\\<bottom>\") \n    and sinvar_spec::\"('v::vertex) graph \\<Rightarrow> ('v::vertex \\<Rightarrow> 'a) \\<Rightarrow> bool\"\n    and sinvar_impl::\"('v::vertex) list_graph \\<Rightarrow> ('v::vertex \\<Rightarrow> 'a) \\<Rightarrow> bool\"\n    and receiver_violation :: \"bool\"\n    and offending_flows_impl::\"('v::vertex) list_graph \\<Rightarrow> ('v \\<Rightarrow> 'a) \\<Rightarrow> ('v \\<times> 'v) list list\"\n    and node_props_impl::\"('v::vertex, 'a) TopoS_Params \\<Rightarrow> ('v \\<Rightarrow> 'a)\"\n    and eval_impl::\"('v::vertex) list_graph \\<Rightarrow> ('v, 'a) TopoS_Params \\<Rightarrow> bool\"\n    assumes\n      spec: \"SecurityInvariant sinvar_spec default_node_properties receiver_violation\" \\<comment> \\<open>specification is valid\\<close>\n    and\n      sinvar_spec_impl: \"wf_list_graph G \\<Longrightarrow> \n        (sinvar_spec (list_graph_to_graph G) nP) = (sinvar_impl G nP)\"\n    and\n      offending_flows_spec_impl: \"wf_list_graph G \\<Longrightarrow> \n      (SecurityInvariant_withOffendingFlows.set_offending_flows sinvar_spec (list_graph_to_graph G) nP) = \n      set`set (offending_flows_impl G nP)\"\n    and \n      node_props_spec_impl: \n     \"SecurityInvariant.node_props_formaldef default_node_properties P = node_props_impl P\"\n    and\n      eval_spec_impl:\n     \"(distinct (nodesL G) \\<and> distinct (edgesL G) \\<and> \n     SecurityInvariant.eval sinvar_spec default_node_properties (list_graph_to_graph G) P ) = \n     (eval_impl G P)\"\n\n  subsection \\<open>Security Invariants Packed\\<close>\n\n  text \\<open>We pack all necessary functions and properties of a security invariant in a struct-like data structure.\\<close>\n  record ('v::vertex, 'a) TopoS_packed =\n    nm_name :: \"string\"\n    nm_receiver_violation :: \"bool\"\n    nm_default :: \"'a\"\n    nm_sinvar::\"('v::vertex) list_graph \\<Rightarrow> ('v \\<Rightarrow> 'a) \\<Rightarrow> bool\"\n    nm_offending_flows::\"('v::vertex) list_graph \\<Rightarrow> ('v \\<Rightarrow> 'a) \\<Rightarrow> ('v \\<times> 'v) list list\"\n    nm_node_props::\"('v::vertex, 'a) TopoS_Params \\<Rightarrow> ('v \\<Rightarrow> 'a)\" \n    nm_eval::\"('v::vertex) list_graph \\<Rightarrow> ('v, 'a)TopoS_Params \\<Rightarrow> bool\"\n    \n\n\n   text\\<open>The packed list implementation must comply with the formal definition.\\<close>\n   locale TopoS_modelLibrary =\n    fixes m :: \"('v::vertex, 'a) TopoS_packed\" \\<comment> \\<open>concrete model implementation\\<close>\n    and sinvar_spec::\"('v::vertex) graph \\<Rightarrow> ('v::vertex \\<Rightarrow> 'a) \\<Rightarrow> bool\" \\<comment> \\<open>specification\\<close>\n    assumes\n       name_not_empty: \"length (nm_name m) > 0\"\n     and\n       impl_spec: \"TopoS_List_Impl \n        (nm_default m)\n        sinvar_spec\n        (nm_sinvar m)\n        (nm_receiver_violation m)\n        (nm_offending_flows m)\n        (nm_node_props m)\n        (nm_eval m)\"\n\n\n\n  subsection\\<open>Helpful Lemmata\\<close>\n\n  text\\<open>show that @{term \"sinvar\"} complies\\<close>\n  lemma TopoS_eval_impl_proofrule: \n    assumes inst: \"SecurityInvariant sinvar_spec default_node_properties receiver_violation\"\n    assumes ev: \"\\<And>nP. wf_list_graph G \\<Longrightarrow> sinvar_spec (list_graph_to_graph G) nP = sinvar_impl G nP\"\n    shows \"\n      (distinct (nodesL G) \\<and> distinct (edgesL G) \\<and> \n       SecurityInvariant.eval sinvar_spec default_node_properties (list_graph_to_graph G) P) =\n      (wf_list_graph G \\<and> sinvar_impl G (SecurityInvariant.node_props default_node_properties P))\"\n  proof (cases \"wf_list_graph G\")\n    case True\n    hence \"sinvar_spec (list_graph_to_graph G) (SecurityInvariant.node_props default_node_properties P) =\n       sinvar_impl G (SecurityInvariant.node_props default_node_properties P)\"\n      using ev by blast\n\n    with inst show ?thesis\n      unfolding wf_list_graph_def \n      by (simp add: wf_list_graph_iff_wf_graph SecurityInvariant.eval_def)\n  next\n    case False\n    hence \"(distinct (nodesL G) \\<and> distinct (edgesL G) \\<and> wf_list_graph_axioms G) = False\"\n      unfolding wf_list_graph_def by blast\n    with False show ?thesis\n      unfolding SecurityInvariant.eval_def[OF inst]\n      by (fastforce simp: wf_list_graph_iff_wf_graph)\n  qed\n\n\nsubsection \\<open>Helper lemmata\\<close>\n\n  text\\<open>Provide @{term sinvar} function and get back a function that computes the list of offending flows\n  \n  Exponential time!\n\\<close>\n  definition Generic_offending_list:: \"('v list_graph \\<Rightarrow> ('v \\<Rightarrow> 'a) \\<Rightarrow> bool )\\<Rightarrow> 'v list_graph \\<Rightarrow> ('v \\<Rightarrow> 'a) \\<Rightarrow> ('v \\<times> 'v) list list\" where\n    \"Generic_offending_list sinvar G nP = [f \\<leftarrow> (subseqs (edgesL G)). \n    (\\<not> sinvar G nP \\<and> sinvar (FiniteListGraph.delete_edges G f) nP) \\<and> \n      (\\<forall>(e1, e2)\\<in>set f. \\<not> sinvar (add_edge e1 e2 (FiniteListGraph.delete_edges G f)) nP)]\"\n  \n  \n  text\\<open>proof rule: if @{term sinvar} complies, @{const Generic_offending_list} complies\\<close>\n  lemma Generic_offending_list_correct: \n    assumes valid: \"wf_list_graph G\"\n    assumes spec_impl: \"\\<And>G nP. wf_list_graph G \\<Longrightarrow> sinvar_spec (list_graph_to_graph G) nP = sinvar_impl G nP\"\n    shows \"SecurityInvariant_withOffendingFlows.set_offending_flows sinvar_spec (list_graph_to_graph G) nP = \n      set`set( Generic_offending_list sinvar_impl G nP )\"\n  proof -\n    have \"\\<And> P G. set ` {x \\<in> set (subseqs (edgesL G)). P G (set x)} = {x \\<in> set ` set (subseqs (edgesL G)). P G (x)}\"\n      by fastforce\n    hence subset_subseqs_filter: \"\\<And> G P. {f. f \\<subseteq> edges (list_graph_to_graph G) \\<and> P G f} \n    = set ` set [f\\<leftarrow>subseqs (edgesL G) . P G (set f)]\"\n      unfolding list_graph_to_graph_def\n      by (auto simp: subseqs_powset)\n\n    from valid delete_edges_wf have \"\\<forall>f. wf_list_graph(FiniteListGraph.delete_edges G f)\" by fast\n    with spec_impl[symmetric] FiniteListGraph.delete_edges_correct[of \"G\"] have impl_spec_delete:\n      \"\\<forall>f. sinvar_impl (FiniteListGraph.delete_edges G f) nP = \n          sinvar_spec (FiniteGraph.delete_edges (list_graph_to_graph G) (set f)) nP\" by simp\n\n    from spec_impl[OF valid, symmetric] have impl_spec_not:\n      \"(\\<not> sinvar_impl G nP) = (\\<not> sinvar_spec (list_graph_to_graph G) nP)\" by auto\n\n    from spec_impl[symmetric, OF FiniteListGraph.add_edge_wf[OF FiniteListGraph.delete_edges_wf[OF valid]]] have impl_spec_allE:\n    \"\\<forall> e1 e2 E. sinvar_impl (FiniteListGraph.add_edge e1 e2 (FiniteListGraph.delete_edges G E)) nP =\n    sinvar_spec (list_graph_to_graph (FiniteListGraph.add_edge e1 e2 (FiniteListGraph.delete_edges G E))) nP\" by simp\n\n    have list_graph: \"\\<And> e1 e2 G f. (list_graph_to_graph (FiniteListGraph.add_edge e1 e2 (FiniteListGraph.delete_edges G f))) = \n      (FiniteGraph.add_edge e1 e2 (FiniteGraph.delete_edges (list_graph_to_graph G) (set f)))\"\n    by(simp add: FiniteListGraph.add_edge_correct FiniteListGraph.delete_edges_correct)\n    \n    show ?thesis \n      unfolding SecurityInvariant_withOffendingFlows.set_offending_flows_def \n      SecurityInvariant_withOffendingFlows.is_offending_flows_min_set_def \n      SecurityInvariant_withOffendingFlows.is_offending_flows_def\n      Generic_offending_list_def\n        apply(subst impl_spec_delete)\n        apply(subst impl_spec_not)\n        apply(subst impl_spec_allE)\n        apply(subst list_graph)\n        apply(rule subset_subseqs_filter)\n        done\n  qed\n\n  lemma all_edges_list_I: \"P (list_graph_to_graph G) = Pl G \\<Longrightarrow> \n    (\\<forall>(e1, e2)\\<in> (edges (list_graph_to_graph G)). P (list_graph_to_graph G) e1 e2) = (\\<forall>(e1, e2)\\<in>set (edgesL G). Pl G e1 e2)\"\n  unfolding list_graph_to_graph_def\n  by simp\n\n  lemma all_nodes_list_I: \"P (list_graph_to_graph G) = Pl G \\<Longrightarrow> \n    (\\<forall>n \\<in> (nodes (list_graph_to_graph G)). P (list_graph_to_graph G) n) = (\\<forall> n \\<in>set (nodesL G). Pl G n)\"\n  unfolding list_graph_to_graph_def\n  by simp\n\n\n\n\n\n\n  fun minimalize_offending_overapprox :: \"('v list_graph \\<Rightarrow> bool) \\<Rightarrow> \n    ('v \\<times> 'v) list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> 'v list_graph \\<Rightarrow> ('v \\<times> 'v) list\" where\n  \"minimalize_offending_overapprox _ [] keep _ = keep\" |\n  \"minimalize_offending_overapprox m (f#fs) keep G = (if m (delete_edges G (fs@keep)) then\n      minimalize_offending_overapprox m fs keep G\n    else\n      minimalize_offending_overapprox m fs (f#keep) G\n    )\"\n\n  thm minimalize_offending_overapprox_boundnP (*is usage of this one better?*)\n  lemma minimalize_offending_overapprox_spec_impl:\n    assumes valid: \"wf_list_graph (G::'v::vertex list_graph)\"\n        and spec_impl: \"\\<And>G nP::('v \\<Rightarrow> 'a). wf_list_graph G \\<Longrightarrow> sinvar_spec (list_graph_to_graph G) nP = sinvar_impl G nP\"\n    shows \"minimalize_offending_overapprox (\\<lambda>G. sinvar_impl G nP) fs keeps G =\n       TopoS_withOffendingFlows.minimalize_offending_overapprox (\\<lambda>G. sinvar_spec G nP) fs keeps (list_graph_to_graph G)\"\n    apply(subst minimalize_offending_overapprox_boundnP)\n    using valid spec_impl apply(induction fs arbitrary: keeps)\n     apply(simp add: SecurityInvariant_withOffendingFlows.minimalize_offending_overapprox.simps; fail)\n    apply(simp add: SecurityInvariant_withOffendingFlows.minimalize_offending_overapprox.simps)\n    apply (metis FiniteListGraph.delete_edges_wf delete_edges_list_set list_graph_correct(5))\n    done\n\n  text\\<open>With @{const minimalize_offending_overapprox}, we can get one offending flow\\<close>\n  lemma minimalize_offending_overapprox_gives_some_offending_flow:\n    assumes wf: \"wf_list_graph G\"\n        and NetModelLib: \"TopoS_modelLibrary m sinvar_spec\"\n        and violation: \"\\<not> (nm_sinvar m) G nP\"\n    shows \"set (minimalize_offending_overapprox (\\<lambda>G. (nm_sinvar m) G nP) (edgesL G) [] G) \\<in>\n            SecurityInvariant_withOffendingFlows.set_offending_flows sinvar_spec (list_graph_to_graph G) nP\"\n    proof -\n      from wf have wfG: \"wf_graph (list_graph_to_graph G)\"\n        by (simp add: wf_list_graph_def wf_list_graph_iff_wf_graph)\n      from wf have dist_edges: \"distinct (edgesL G)\" by (simp add: wf_list_graph_def)\n\n      let ?spec_algo=\"TopoS_withOffendingFlows.minimalize_offending_overapprox\n                          (\\<lambda>G. sinvar_spec G nP) (edgesL G) [] (list_graph_to_graph G)\"\n\n      note spec=TopoS_List_Impl.spec[OF TopoS_modelLibrary.impl_spec[OF NetModelLib]]\n\n      from spec have spec_prelim: \"SecurityInvariant_preliminaries sinvar_spec\"\n        by(simp add: SecurityInvariant_def)\n      from spec_prelim SecurityInvariant_preliminaries.sinvar_monoI have mono:\n        \"SecurityInvariant_withOffendingFlows.sinvar_mono sinvar_spec\" by blast\n        \n      from spec_prelim have empty_edges: \"sinvar_spec \\<lparr>nodes = set (nodesL G), edges = {}\\<rparr> nP\"\n      using SecurityInvariant_preliminaries.defined_offending \n        SecurityInvariant_withOffendingFlows.sinvar_mono_imp_sinvar_mono \n        SecurityInvariant_withOffendingFlows.valid_empty_edges_iff_exists_offending_flows  \n        mono empty_subsetI graph.simps(1) \n        list_graph_to_graph_def local.wf wf_list_graph_def wf_list_graph_iff_wf_graph\n        by (metis)\n\n      (*TODO: tune*)\n      have spec_impl: \"wf_list_graph G \\<Longrightarrow> sinvar_spec (list_graph_to_graph G) nP = (nm_sinvar m) G nP\" for G nP\n        using NetModelLib TopoS_List_Impl.sinvar_spec_impl TopoS_modelLibrary.impl_spec by fastforce\n      \n      from minimalize_offending_overapprox_spec_impl[OF wf] spec_impl have alog_spec:\n        \"minimalize_offending_overapprox (\\<lambda>G. (nm_sinvar m) G nP) fs keeps G =\n         TopoS_withOffendingFlows.minimalize_offending_overapprox (\\<lambda>G. sinvar_spec G nP) fs keeps (list_graph_to_graph G)\"\n         for fs keeps by blast\n\n      (*TODO: tune*)\n      from spec_impl violation have\n        \"SecurityInvariant_withOffendingFlows.is_offending_flows sinvar_spec (set (edgesL G)) (list_graph_to_graph G) nP\"\n        apply(simp add: SecurityInvariant_withOffendingFlows.is_offending_flows_def)\n        apply(intro conjI)\n         apply (simp add: local.wf; fail)\n        apply(simp add: FiniteGraph.delete_edges_simp2 list_graph_to_graph_def)\n        apply(simp add: empty_edges)\n        done\n      hence goal: \"SecurityInvariant_withOffendingFlows.is_offending_flows_min_set sinvar_spec\n        (set ?spec_algo) (list_graph_to_graph G) nP\"\n      apply(subst minimalize_offending_overapprox_boundnP) (*we do this subst pretty often. is this the right abstraction here?*)\n      apply(rule SecurityInvariant_withOffendingFlows.is_offending_flows_min_set_minimalize_offending_overapprox[OF\n              mono wfG _ _ dist_edges])\n       apply(simp add: list_graph_to_graph_def)+\n      done\n\n      from SecurityInvariant_withOffendingFlows.minimalize_offending_overapprox_subseteq_input[of\n        \"sinvar_spec\" \"(edgesL G)\" \"[]\"] have subset_edges:\n        \"set ?spec_algo \\<subseteq> edges (list_graph_to_graph G)\" \n        apply(subst minimalize_offending_overapprox_boundnP)\n        by(simp add: list_graph_to_graph_def)\n\n      from goal show ?thesis\n        by(simp add: SecurityInvariant_withOffendingFlows.set_offending_flows_def alog_spec subset_edges)\n    qed\n\n\n\n\n\n\n(*TODO: this should be a header of TopoS_Libary. The header should be printed BEFORE the imports are processed. *)\nsection\\<open>Security Invariant Library\\<close>\n(*The SINVAR_* theory files all use the \"subsection\" command. Here is the top-section.*)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Network_Security_Policy_Verification/TopoS_Interface_impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6224593312018546, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.2749234837159158}}
{"text": "section \\<open>Sets Bounded by a Finite Cardinal $>2$ Are Not BNFs\\<close>\n\n(*<*)\ntheory Finitely_Bounded_Set_Counterexample\nimports\n  \"HOL-Cardinals.Cardinals\"\nbegin\n(*>*)\n\ntext \\<open>Do not import this theory. It contains an inconsistent axiomatization.\nThe point is to exhibit the particular inconsistency.\\<close>\n\ntypedef ('a, 'k) bset (\"_ set[_]\" [22, 21] 21) =\n  \"{A :: 'a set. |A| <o |UNIV :: 'k set|}\"\n  morphisms set_bset Abs_bset\n  by (rule exI[of _ \"{}\"]) (auto simp: card_of_empty4 csum_def)\n\nsetup_lifting type_definition_bset\n\nlift_definition map_bset ::\n  \"('a \\<Rightarrow> 'b) \\<Rightarrow> 'a set['k] \\<Rightarrow> 'b set['k]\" is image\n  using card_of_image ordLeq_ordLess_trans by blast\n\ninductive rel_bset :: \"('a \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow> ('a, 'k) bset \\<Rightarrow> ('b, 'k) bset \\<Rightarrow> bool\" for R where\n  \"set_bset x \\<subseteq> {(x, y). R x y} \\<Longrightarrow> rel_bset R (map_bset fst x) (map_bset snd x)\"\n\ntext \\<open>\nWe axiomatize the relator commutation property and show that we can deduce @{term False} from it.\n\nWe cannot do this with a locale, since we need the fully polymorphic version of the following axiom.\n\\<close>\n\naxiomatization where\n  inconsistent: \"rel_bset R1 OO rel_bset R2 \\<le> rel_bset (R1 OO R2)\"\n\nbnf \"('a, 'k) bset\"\n  map: map_bset\n  sets: set_bset\n  bd: \"|UNIV :: 'k set| +c natLeq\"\n  rel: rel_bset\nproof (standard, goal_cases)\n  case 1 then show ?case\n    by transfer simp\nnext\n  case 2 then show ?case\n    apply (rule ext)\n    apply transfer\n    apply auto\n    done\nnext\n  case 3 then show ?case\n    apply transfer\n    apply (auto simp: image_iff)\n    done\nnext\n  case 4 then show ?case\n    apply (rule ext)\n    apply transfer\n    apply simp\n    done\nnext\n  case 5 then show ?case by (simp add: card_order_csum natLeq_card_order)\nnext\n  case 6 then show ?case by (simp add: cinfinite_csum natLeq_cinfinite)\nnext\n  case 7 then show ?case\n    apply transfer\n    apply (erule ordLeq_transitive[OF ordLess_imp_ordLeq ordLeq_csum1])\n    apply simp\n    done\nnext\n  case 8 then show ?case by (rule inconsistent) \\<comment> \\<open>BAAAAAMMMM\\<close>\nnext\n  case 9 then show ?case\n    by (auto simp: fun_eq_iff intro: rel_bset.intros elim: rel_bset.cases)\nqed\n\nlemma card_option_finite[simp]:\n  assumes \"finite (UNIV :: 'k set)\"\n  shows \"card (UNIV :: 'k option set) = Suc (card (UNIV :: 'k set))\"\n  (is \"card ?L = Suc (card ?R)\")\nproof -\n  have \"card ?L = Suc (card (?L - {None}))\" by (rule card.remove) (auto simp: assms)\n  also have \"card (?L - {None}) = card ?R\"\n    by (rule bij_betw_same_card[of the])\n      (auto simp: bij_betw_def inj_on_def image_iff intro!: bexI[of _ \"Some x\" for x])\n  finally show ?thesis .\nqed\n\ndatatype ('a :: enum) x = A | B \"'a option\" | C\n\nabbreviation \"Bs \\<equiv> B ` (insert None (Some ` set Enum.enum))\"\n\nlemma UNIV_x[simp]:\n  \"(UNIV :: ('a :: enum) x set) = {A, C} \\<union> Bs\"\n  (is \"_ = ?R\")\nproof (intro set_eqI iffI)\n  fix x :: \"'a x\" show \"x \\<in> ?R\" by (cases x) (auto simp add: enum_UNIV)\nqed simp\n\nlemma Collect_split_in_rel: \"{(x, y). in_rel R x y} = R\"\n  by auto\n\nlift_definition X :: \"('a :: enum x, 'a x) bset\" is \"insert A Bs\"\n  by (subst finite_card_of_iff_card3) (auto simp: card_insert card_Diff_singleton_if)\n\nlift_definition Y :: \"('a :: enum x, 'a x) bset\" is \"insert C Bs\"\n  by (subst finite_card_of_iff_card3) (auto simp: card_insert card_Diff_singleton_if)\n\nlift_definition Z :: \"('a :: enum x, 'a x) bset\" is \"{A, C}\"\n  by (subst finite_card_of_iff_card3) (auto simp: card_insert card_Diff_singleton_if)\n\nlift_definition R :: \"('a x \\<times> 'a x, 'a :: enum x) bset\" is \"insert (A, A) ((\\<lambda>B. (B, C)) ` Bs)\"\n  by (subst finite_card_of_iff_card3)\n    (auto simp: card_insert card_Diff_singleton_if image_iff card_image inj_on_def)\n\nlift_definition S :: \"('a x \\<times> 'a x, 'a :: enum x) bset\" is \"insert (C, C) ((\\<lambda>B. (A, B)) ` Bs)\"\n  by (subst finite_card_of_iff_card3)\n    (auto simp: card_insert card_Diff_singleton_if image_iff card_image inj_on_def)\n\nlift_definition in_brel :: \"('a \\<times> 'b, 'k) bset \\<Rightarrow> 'a \\<Rightarrow> 'b \\<Rightarrow> bool\" is in_rel .\n\nlemma False\nproof -\n  have \"rel_bset (in_brel R) X Z\"\n    unfolding bset.in_rel mem_Collect_eq\n    apply (intro exI[of _ R])\n    apply transfer\n    apply (auto simp: image_iff)\n    done\n  moreover\n  have \"rel_bset (in_brel S) Z Y\"\n    unfolding bset.in_rel mem_Collect_eq\n    apply (intro exI[of _ S])\n    apply transfer\n    apply (auto simp: image_iff)\n    done\n  ultimately have \"rel_bset (in_brel R OO in_brel S) X Y\"\n    unfolding bset.rel_compp by blast\n  moreover\n  have *: \"insert (A, A) ((\\<lambda>B. (B, C)) ` Bs) O insert (C, C) ((\\<lambda>B. (A, B)) ` Bs) =\n    ((\\<lambda>B. (B, C)) ` Bs) \\<union> ((\\<lambda>B. (A, B)) ` Bs)\" (is \"_ = ?RS\" ) by auto\n  have \"\\<not> rel_bset (in_brel R OO in_brel S) X Y\"\n  unfolding bset.in_rel mem_Collect_eq\n  proof (transfer, safe, unfold relcompp_in_rel * Collect_split_in_rel)\n    fix Z :: \"('a :: enum x \\<times> 'a x) set\"\n    note enum_UNIV[simp] UNIV_option_conv[symmetric, simp]\n    assume \"Z \\<subseteq> ?RS\" \"fst ` Z = insert A Bs\" \"snd ` Z = insert C Bs\"\n    then have \"Z = ?RS\" unfolding fst_eq_Domain snd_eq_Range by auto\n    moreover assume \"|Z| <o |UNIV :: 'a x set|\"\n    ultimately show False unfolding \\<open>Z = ?RS\\<close>\n      by (subst (asm) finite_card_of_iff_card3, simp, simp, subst (asm) card_Un_disjoint)\n        (auto simp: card_insert card_Diff_singleton_if card_image inj_on_def split: if_splits)\n  qed\n  ultimately show False by blast\nqed\n\n(*<*)\nend\n(*>*)\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Probabilistic_System_Zoo/Finitely_Bounded_Set_Counterexample.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.63341026367784, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.2748883140527326}}
{"text": "(* \n   Title: Psi-calculi   \n   Author/Maintainer: Jesper Bengtson (jebe@itu.dk), 2012\n*)\ntheory Weak_Bisimulation\n  imports Weak_Simulation Weak_Stat_Imp Bisim_Struct_Cong\nbegin\n\ncontext env begin\n\nlemma monoCoinduct: \"\\<And>x y xa xb xc P Q \\<Psi>.\n                      x \\<le> y \\<Longrightarrow>\n                      (\\<Psi> \\<rhd> Q \\<leadsto><{(xc, xb, xa). x xc xb xa}> P) \\<longrightarrow>\n                     (\\<Psi> \\<rhd> Q \\<leadsto><{(xb, xa, xc). y xb xa xc}> P)\"\napply auto\napply(rule weakSimMonotonic)\nby(auto dest: le_funE)\n\nlemma monoCoinduct2: \"\\<And>x y xa xb xc P Q \\<Psi>.\n                      x \\<le> y \\<Longrightarrow>\n                      (\\<Psi> \\<rhd> Q \\<lessapprox><{(xc, xb, xa). x xc xb xa}> P) \\<longrightarrow>\n                     (\\<Psi> \\<rhd> Q \\<lessapprox><{(xb, xa, xc). y xb xa xc}> P)\"\napply auto\napply(rule weakStatImpMonotonic)\nby(auto dest: le_funE)\n\ncoinductive_set weakBisim :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\" \nwhere\n  step: \"\\<lbrakk>\\<Psi> \\<rhd> P \\<lessapprox><weakBisim> Q; \\<Psi> \\<rhd> P \\<leadsto><weakBisim> Q;\n          \\<forall>\\<Psi>'. (\\<Psi> \\<otimes> \\<Psi>',  P, Q) \\<in> weakBisim; (\\<Psi>, Q, P) \\<in> weakBisim\\<rbrakk> \\<Longrightarrow> (\\<Psi>, P, Q) \\<in> weakBisim\"\nmonos monoCoinduct monoCoinduct2\n\nabbreviation\n  weakBisimJudge (\"_ \\<rhd> _ \\<approx> _\" [70, 70, 70] 65) where \"\\<Psi> \\<rhd> P \\<approx> Q \\<equiv> (\\<Psi>, P, Q) \\<in> weakBisim\"\nabbreviation\n  weakBisimNilJudge (\"_ \\<approx> _\" [70, 70] 65) where \"P \\<approx> Q \\<equiv> \\<one> \\<rhd> P \\<approx> Q\"\n\nlemma weakBisimCoinductAux[consumes 1]:\n  fixes F :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   X :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n\n  assumes \"(\\<Psi>, P, Q) \\<in> X\"\n  and     \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> (\\<Psi> \\<rhd> P \\<lessapprox><(X \\<union> weakBisim)> Q) \\<and>\n                                      (\\<Psi> \\<rhd> P \\<leadsto><(X \\<union> weakBisim)> Q) \\<and>\n                                      (\\<forall>\\<Psi>'. (\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> X \\<or> (\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> weakBisim) \\<and>\n                                      ((\\<Psi>, Q, P) \\<in> X \\<or> (\\<Psi>, Q, P) \\<in> weakBisim)\"\n\n  shows \"(\\<Psi>, P, Q) \\<in> weakBisim\"\nproof -\n  have \"X \\<union> weakBisim = {(\\<Psi>, P, Q). (\\<Psi>, P, Q) \\<in> X \\<or> (\\<Psi>, P, Q) \\<in> weakBisim}\" by auto\n  with assms show ?thesis\n    by coinduct (simp add: rtrancl_def)\nqed\n\nlemma weakBisimCoinduct[consumes 1, case_names cStatImp cSim cExt cSym]:\n  fixes F :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   X :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n\n  assumes \"(\\<Psi>, P, Q) \\<in> X\"\n  and     \"\\<And>\\<Psi>' R S. (\\<Psi>', R, S) \\<in> X \\<Longrightarrow> \\<Psi>' \\<rhd> R \\<lessapprox><(X \\<union> weakBisim)> S\"\n  and     \"\\<And>\\<Psi>' R S. (\\<Psi>', R, S) \\<in> X \\<Longrightarrow> \\<Psi>' \\<rhd> R \\<leadsto><(X \\<union> weakBisim)> S\"\n  and     \"\\<And>\\<Psi>' R S \\<Psi>''. (\\<Psi>', R, S) \\<in> X \\<Longrightarrow> (\\<Psi>' \\<otimes> \\<Psi>'', R, S) \\<in> X \\<or> \\<Psi>' \\<otimes> \\<Psi>'' \\<rhd> R \\<approx> S\"\n  and     \"\\<And>\\<Psi>' R S. (\\<Psi>', R, S) \\<in> X \\<Longrightarrow> (\\<Psi>', S, R) \\<in> X \\<or> \\<Psi>' \\<rhd> S \\<approx> R\"\n\n  shows \"\\<Psi> \\<rhd> P \\<approx> Q\"\nproof -\n  have \"X \\<union> weakBisim = {(\\<Psi>, P, Q). (\\<Psi>, P, Q) \\<in> X \\<or> (\\<Psi>, P, Q) \\<in> weakBisim}\" by auto\n  with assms show ?thesis\n    by coinduct (simp add: rtrancl_def)\nqed\n\nlemma weakBisimWeakCoinductAux[consumes 1]:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   X :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n\n  assumes \"(\\<Psi>, P, Q) \\<in> X\"\n  and     \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> \\<Psi> \\<rhd> P \\<lessapprox><X> Q \\<and> \\<Psi> \\<rhd> P \\<leadsto><X> Q \\<and>\n                                      (\\<forall>\\<Psi>'. (\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> X) \\<and> (\\<Psi>, Q, P) \\<in> X\" \n\n  shows \"\\<Psi> \\<rhd> P \\<approx> Q\"\nusing assms\nby(coinduct rule: weakBisimCoinductAux) (blast intro: weakSimMonotonic weakStatImpMonotonic)\n\nlemma weakBisimWeakCoinduct[consumes 1, case_names cStatImp cSim cExt cSym]:\n  fixes F :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   X :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n\n  assumes \"(\\<Psi>, P, Q) \\<in> X\"\n  and     \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> \\<Psi> \\<rhd> P \\<lessapprox><X> Q\"\n  and     \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> \\<Psi> \\<rhd> P \\<leadsto><X> Q\"\n  and     \"\\<And>\\<Psi> P Q \\<Psi>'. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> (\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> X\"\n  and     \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> (\\<Psi>, Q, P) \\<in> X\"\n\n  shows \"(\\<Psi>, P, Q) \\<in> weakBisim\"\nproof -\n  have \"X \\<union> weakBisim = {(\\<Psi>, P, Q). (\\<Psi>, P, Q) \\<in> X \\<or> (\\<Psi>, P, Q) \\<in> weakBisim}\" by auto\n  with assms show ?thesis\n    by(coinduct rule: weakBisimWeakCoinductAux) blast\nqed\n\nlemma weakBisimE:\n  fixes P  :: \"('a, 'b, 'c) psi\"\n  and   Q  :: \"('a, 'b, 'c) psi\"\n  and   \\<Psi>  :: 'b\n  and   \\<Psi>' :: 'b\n\n  assumes \"\\<Psi> \\<rhd> P \\<approx> Q\"\n\n  shows \"\\<Psi> \\<rhd> P \\<lessapprox><weakBisim> Q\"\n  and   \"\\<Psi> \\<rhd> P \\<leadsto><weakBisim> Q\"\n  and   \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd>  P \\<approx> Q\"\n  and   \"\\<Psi> \\<rhd> Q \\<approx> P\"\nusing assms\nby(auto intro: weakBisim.cases simp add: rtrancl_def)\n\nlemma weakBisimI:\n  fixes P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   \\<Psi> :: 'b\n\n  assumes \"\\<Psi> \\<rhd> P \\<lessapprox><weakBisim> Q\"\n  and     \"\\<Psi> \\<rhd> P \\<leadsto><weakBisim> Q\"\n  and     \"\\<forall>\\<Psi>'. \\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<approx> Q\"\n  and     \"\\<Psi> \\<rhd> Q \\<approx> P\"\n\n  shows \"\\<Psi> \\<rhd> P \\<approx> Q\"\nusing assms\nby(rule_tac weakBisim.step) (auto simp add: rtrancl_def)\n\nlemma weakBisimReflexive:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n\n\n  shows \"\\<Psi> \\<rhd> P \\<approx> P\"\nproof -\n  let ?X = \"{(\\<Psi>, P, P) | \\<Psi> P. True}\"\n  have \"(\\<Psi>, P, P) \\<in> ?X\" by simp\n  thus ?thesis\n    by(coinduct rule: weakBisimWeakCoinduct, auto intro: weakSimReflexive weakStatImpReflexive)\nqed\n\nlemma weakBisimClosed:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   p :: \"name prm\"\n  \n  assumes \"\\<Psi> \\<rhd> P \\<approx> Q\"\n\n  shows \"(p \\<bullet> \\<Psi>) \\<rhd>  (p \\<bullet> P) \\<approx> (p \\<bullet> Q)\"\nproof -\n  let ?X = \"{(p \\<bullet> \\<Psi>, p \\<bullet> P, p \\<bullet> Q) | (p::name prm) \\<Psi>  P Q. \\<Psi> \\<rhd> P \\<approx> Q}\"\n  have \"eqvt ?X\"\n    apply(auto simp add: eqvt_def)\n    apply(rule_tac x=\"pa@p\" in exI)\n    by(auto simp add: pt2[OF pt_name_inst])\n  from \\<open>\\<Psi> \\<rhd> P \\<approx> Q\\<close> have \"(p \\<bullet> \\<Psi>, p \\<bullet> P, p \\<bullet> Q) \\<in> ?X\" by blast\n  thus ?thesis\n  proof(coinduct rule: weakBisimWeakCoinduct)\n    case(cStatImp \\<Psi> P Q)\n    {\n      fix \\<Psi> P Q p\n      assume \"\\<Psi> \\<rhd> P \\<approx> (Q::('a, 'b, 'c) psi)\"\n      hence \"\\<Psi> \\<rhd> P \\<lessapprox><weakBisim> Q\" by(rule weakBisimE)\n      hence \"\\<Psi> \\<rhd> P \\<lessapprox><?X> Q\"\n        apply(rule_tac A=weakBisim in weakStatImpMonotonic, auto)\n        by(rule_tac x=\"[]::name prm\" in exI) auto\n      with \\<open>eqvt ?X\\<close> have \"((p::name prm) \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P) \\<lessapprox><?X> (p \\<bullet> Q)\"\n        by(rule weakStatImpClosed)\n    }\n    with \\<open>(\\<Psi>, P, Q) \\<in> ?X\\<close> show ?case by blast\n  next\n    case(cSim \\<Psi> P Q)\n    {\n      fix p :: \"name prm\"\n      fix \\<Psi> P Q\n      assume \"\\<Psi> \\<rhd> P \\<leadsto><weakBisim> Q\"\n      hence \"\\<Psi> \\<rhd> P \\<leadsto><?X> Q\"\n        apply(rule_tac A=weakBisim in weakSimMonotonic, auto)\n        by(rule_tac x=\"[]::name prm\" in exI) auto\n      with \\<open>eqvt ?X\\<close> have \"((p::name prm) \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P) \\<leadsto><?X> (p \\<bullet> Q)\"\n        by(rule_tac weakSimClosed)\n    }\n    with \\<open>(\\<Psi>, P, Q) \\<in> ?X\\<close> show ?case\n      by(blast dest: weakBisimE)\n  next\n    case(cExt \\<Psi> P Q \\<Psi>')\n    {\n      fix p :: \"name prm\"\n      fix \\<Psi> P Q \\<Psi>'\n      assume \"\\<forall>\\<Psi>'. (\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> weakBisim\"\n      hence \"((p \\<bullet> \\<Psi>) \\<otimes> \\<Psi>', p \\<bullet> P, p \\<bullet> Q) \\<in> ?X\"\n        apply(auto, rule_tac x=p in exI)\n        apply(rule_tac x=\"\\<Psi> \\<otimes> (rev p \\<bullet> \\<Psi>')\" in exI)\n        by(auto simp add: eqvts)\n    }\n    with \\<open>(\\<Psi>, P, Q) \\<in> ?X\\<close> show ?case\n      by(blast dest: weakBisimE)\n  next\n    case(cSym \\<Psi> P Q)\n    thus ?case\n      by(blast dest: weakBisimE)\n  qed\nqed\n\nlemma weakBisimEqvt[simp]:\n  shows \"eqvt weakBisim\"\nby(auto simp add: eqvt_def weakBisimClosed)\n\nlemma statEqWeakBisim:\n  fixes \\<Psi>  :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   Q  :: \"('a, 'b, 'c) psi\"\n  and   \\<Psi>' :: 'b\n  \n  assumes \"\\<Psi> \\<rhd> P \\<approx> Q\"\n  and     \"\\<Psi> \\<simeq> \\<Psi>'\"\n\n  shows \"\\<Psi>' \\<rhd> P \\<approx> Q\"\nproof -\n  let ?X = \"{(\\<Psi>', P, Q) | \\<Psi> P Q \\<Psi>'. \\<Psi> \\<rhd> P \\<approx> Q \\<and> \\<Psi> \\<simeq> \\<Psi>'}\"\n  from \\<open>\\<Psi> \\<rhd> P \\<approx> Q\\<close> \\<open>\\<Psi> \\<simeq> \\<Psi>'\\<close> have \"(\\<Psi>', P, Q) \\<in> ?X\" by auto\n  thus ?thesis\n  proof(coinduct rule: weakBisimCoinduct)\n    case(cStatImp \\<Psi>' P Q)\n    from \\<open>(\\<Psi>', P, Q) \\<in> ?X\\<close> obtain \\<Psi> where \"\\<Psi> \\<rhd> P \\<approx> Q\" and \"\\<Psi> \\<simeq> \\<Psi>'\"\n      by auto\n    from \\<open>\\<Psi> \\<rhd> P \\<approx> Q\\<close> have \"\\<Psi> \\<rhd> P \\<lessapprox><weakBisim> Q\" by(rule weakBisimE)\n    moreover note \\<open>\\<Psi> \\<simeq> \\<Psi>'\\<close>\n    moreover have \"\\<And>\\<Psi> P Q \\<Psi>'. \\<lbrakk>\\<Psi> \\<rhd> P \\<approx> Q; \\<Psi> \\<simeq> \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', P, Q) \\<in> ?X \\<union> weakBisim\"\n      by auto\n    ultimately show ?case by(rule weakStatImpStatEq)\n  next\n    case(cSim \\<Psi>' P Q)\n    from \\<open>(\\<Psi>', P, Q) \\<in> ?X\\<close> obtain \\<Psi> where \"\\<Psi> \\<rhd> P \\<approx> Q\" and \"\\<Psi> \\<simeq> \\<Psi>'\"\n      by auto\n    from \\<open>\\<Psi> \\<rhd> P \\<approx> Q\\<close> have \"\\<Psi> \\<rhd> P \\<leadsto><weakBisim> Q\" by(blast dest: weakBisimE)\n    moreover have \"eqvt ?X\"\n      by(auto simp add: eqvt_def) (metis weakBisimClosed AssertionStatEqClosed)\n    hence \"eqvt(?X \\<union> weakBisim)\" by auto\n    moreover note \\<open>\\<Psi> \\<simeq> \\<Psi>'\\<close>\n    moreover have \"\\<And>\\<Psi> P Q \\<Psi>'. \\<lbrakk>\\<Psi> \\<rhd> P \\<approx> Q; \\<Psi> \\<simeq> \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', P, Q) \\<in> ?X \\<union> weakBisim\"\n      by auto\n    ultimately show ?case by(rule weakSimStatEq)\n  next\n    case(cExt \\<Psi>' P Q \\<Psi>'')\n    from \\<open>(\\<Psi>', P, Q) \\<in> ?X\\<close> obtain \\<Psi> where \"\\<Psi> \\<rhd> P \\<approx> Q\" and \"\\<Psi> \\<simeq> \\<Psi>'\"\n      by auto\n    from \\<open>\\<Psi> \\<rhd> P \\<approx> Q\\<close> have \"\\<Psi> \\<otimes> \\<Psi>'' \\<rhd> P \\<approx> Q\" by(rule weakBisimE)\n    moreover from \\<open>\\<Psi> \\<simeq> \\<Psi>'\\<close> have \"\\<Psi> \\<otimes> \\<Psi>'' \\<simeq> \\<Psi>' \\<otimes> \\<Psi>''\" by(rule Composition)\n    ultimately show ?case by blast\n  next\n    case(cSym \\<Psi>' P Q)\n    from \\<open>(\\<Psi>', P, Q) \\<in> ?X\\<close> obtain \\<Psi> where \"\\<Psi> \\<rhd> P \\<approx> Q\" and \"\\<Psi> \\<simeq> \\<Psi>'\"\n      by auto\n    from \\<open>\\<Psi> \\<rhd> P \\<approx> Q\\<close> have \"\\<Psi> \\<rhd> Q \\<approx> P\" by(rule weakBisimE)\n    thus ?case using \\<open>\\<Psi> \\<simeq> \\<Psi>'\\<close> by auto\n  qed\nqed\n\nlemma weakBisimTransitive:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   R :: \"('a, 'b, 'c) psi\"\n\n  assumes PQ: \"\\<Psi> \\<rhd> P \\<approx> Q\"\n  and     QR: \"\\<Psi> \\<rhd> Q \\<approx> R\"\n\n  shows \"\\<Psi> \\<rhd> P \\<approx> R\"\nproof -\n  let ?X = \"{(\\<Psi>, P, R) | \\<Psi> P R. \\<exists>Q. \\<Psi> \\<rhd> P \\<approx> Q \\<and> \\<Psi> \\<rhd> Q \\<approx> R}\" \n  from PQ QR have \"(\\<Psi>, P, R) \\<in> ?X\" by auto\n  thus ?thesis\n  proof(coinduct rule: weakBisimCoinduct)\n    case(cStatImp \\<Psi> P R)\n    from \\<open>(\\<Psi>, P, R) \\<in> ?X\\<close> obtain Q where \"\\<Psi> \\<rhd> P \\<approx> Q\" and  \"\\<Psi> \\<rhd> Q \\<approx> R\" by blast\n    from \\<open>\\<Psi> \\<rhd> P \\<approx> Q\\<close> have \"\\<Psi> \\<rhd> P \\<lessapprox><weakBisim> Q\" by(rule weakBisimE)\n    moreover note \\<open>\\<Psi> \\<rhd> Q \\<approx> R\\<close>\n    moreover have \"?X \\<subseteq> ?X \\<union> weakBisim\" by auto\n    moreover note weakBisimE(1)\n    moreover from weakBisimE(2) have \"\\<And>\\<Psi> P Q P'. \\<lbrakk>\\<Psi> \\<rhd> P \\<approx> Q; \\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\\<rbrakk> \\<Longrightarrow> \\<exists>Q'. \\<Psi> \\<rhd> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q' \\<and> \\<Psi> \\<rhd> P' \\<approx> Q'\"\n      by(metis weakBisimE(4) weakSimTauChain)\n    ultimately show ?case by(rule weakStatImpTransitive)\n  next\n    case(cSim \\<Psi> P R)\n    {\n      fix \\<Psi> P Q R\n      assume \"\\<Psi> \\<rhd> P \\<approx> Q\" and \"\\<Psi> \\<rhd> Q \\<leadsto><weakBisim> R\"\n      moreover have \"eqvt ?X\"\n        by(force simp add: eqvt_def dest: weakBisimClosed)\n      with weakBisimEqvt have \"eqvt (?X \\<union> weakBisim)\" by blast\n      moreover have \"?X \\<subseteq> ?X \\<union> weakBisim\" by auto\n      moreover note weakBisimE(2)\n      ultimately have \"\\<Psi> \\<rhd> P \\<leadsto><(?X \\<union> weakBisim)> R\"\n        by(rule_tac weakSimTransitive) auto\n    }\n    with \\<open>(\\<Psi>, P, R) \\<in> ?X\\<close> show ?case\n      by(blast dest: weakBisimE)\n  next\n    case(cExt \\<Psi> P R \\<Psi>')\n    thus ?case by(blast dest: weakBisimE)\n  next\n    case(cSym \\<Psi> P R)\n    thus ?case by(blast dest: weakBisimE)\n  qed\nqed\n\nlemma strongBisimWeakBisim:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<sim> Q\"\n\n  shows \"\\<Psi> \\<rhd> P \\<approx> Q\"\nproof -\n  from \\<open>\\<Psi> \\<rhd> P \\<sim> Q\\<close>\n  show ?thesis\n  proof(coinduct rule: weakBisimWeakCoinduct)\n    case(cStatImp \\<Psi> P Q)\n    from \\<open>\\<Psi> \\<rhd> P \\<sim> Q\\<close> have \"insertAssertion(extractFrame P) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion(extractFrame Q) \\<Psi>\"\n      by(metis bisimE FrameStatEq_def)\n    moreover from \\<open>\\<Psi> \\<rhd> P \\<sim> Q\\<close> have \"\\<And>\\<Psi>'. \\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<sim> Q\" by(rule bisimE)\n    ultimately show ?case by(rule statImpWeakStatImp)\n  next\n    case(cSim \\<Psi> P Q)\n    note \\<open>\\<Psi> \\<rhd> P \\<sim> Q\\<close>\n    moreover have \"\\<And>\\<Psi> P Q. \\<Psi> \\<rhd> P \\<sim> Q \\<Longrightarrow> insertAssertion(extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion(extractFrame P) \\<Psi>\"\n      by(drule_tac bisimE) (simp add: FrameStatEq_def)\n    ultimately show ?case using bisimE(2) bisimE(3)\n      by(rule strongSimWeakSim)\n  next\n    case(cExt \\<Psi> P Q \\<Psi>')\n    from \\<open>\\<Psi> \\<rhd> P \\<sim> Q\\<close> show ?case\n      by(rule bisimE)\n  next\n    case(cSym \\<Psi> P Q)\n    from \\<open>\\<Psi> \\<rhd> P \\<sim> Q\\<close> show ?case\n      by(rule bisimE)\n  qed\nqed\n\nlemma structCongWeakBisim:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes \"P \\<equiv>\\<^sub>s Q\"\n\n  shows \"P \\<approx> Q\"\nusing assms\nby(metis structCongBisim strongBisimWeakBisim)\n\nlemma simTauChain:\n  fixes \\<Psi> :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   Q  :: \"('a, 'b, 'c) psi\"\n  and   Q' :: \"('a, 'b, 'c) psi\"\n\n  assumes \"(\\<Psi>, P, Q) \\<in> Rel\"\n  and     \"\\<Psi> \\<rhd> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q'\"\n  and     Sim: \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> Rel \\<Longrightarrow> \\<Psi> \\<rhd> P \\<leadsto>[Rel] Q\"\n  \n  obtains P' where \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" and \"(\\<Psi>, P', Q') \\<in> Rel\"\nproof -\n  assume A: \"\\<And>P'. \\<lbrakk>\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'; (\\<Psi>, P', Q') \\<in> Rel\\<rbrakk> \\<Longrightarrow> thesis\"\n  from \\<open>\\<Psi> \\<rhd> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q'\\<close> \\<open>(\\<Psi>, P, Q) \\<in> Rel\\<close> A show ?thesis\n  proof(induct arbitrary: P thesis rule: tauChainInduct)\n    case(TauBase Q P)\n    moreover have \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P\" by simp\n    ultimately show ?case by blast\n  next\n    case(TauStep Q Q' Q'' P)\n    from \\<open>(\\<Psi>, P, Q) \\<in> Rel\\<close> obtain P' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" and \"(\\<Psi>, P', Q') \\<in> Rel\"\n      by(rule TauStep)\n    from \\<open>(\\<Psi>, P', Q') \\<in> Rel\\<close> have \"\\<Psi> \\<rhd> P' \\<leadsto>[Rel] Q'\" by(rule Sim)\n    then obtain P'' where P'Chain: \"\\<Psi> \\<rhd> P' \\<longmapsto>\\<tau> \\<prec> P''\" and \"(\\<Psi>, P'', Q'') \\<in> Rel\"\n      using \\<open>\\<Psi> \\<rhd> Q' \\<longmapsto>\\<tau> \\<prec> Q''\\<close> by(drule_tac simE) auto\n    from PChain P'Chain have \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" by(auto dest: tauActTauChain)\n    thus ?case using \\<open>(\\<Psi>, P'', Q'') \\<in> Rel\\<close> by(rule TauStep)\n  qed\nqed\n\nlemma quietBisimNil:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n\n  assumes \"quiet P\"\n\n  shows \"\\<Psi> \\<rhd> P \\<approx> \\<zero>\"\nproof -\n  let ?X = \"{(\\<Psi>, \\<zero>, P) | \\<Psi> P. quiet P} \\<union> {(\\<Psi>, P, \\<zero>) | \\<Psi> P. quiet P}\"\n\n  from \\<open>quiet P\\<close> have \"(\\<Psi>, P, \\<zero>) \\<in> ?X\" by auto\n  thus ?thesis\n  proof(coinduct rule: weakBisimWeakCoinduct)\n    case(cStatImp \\<Psi> P Q)\n    thus ?case\n      apply(simp add: weakStatImp_def)\n      apply(rule allI)\n      apply(rule_tac x=Q in exI)\n      apply auto\n      apply(drule_tac \\<Psi>=\\<Psi> in quietFrame)\n      apply(rule_tac G=\"\\<langle>\\<epsilon>, \\<Psi>\\<rangle>\" in FrameStatImpTrans)\n      using Identity\n      apply(simp add: AssertionStatEq_def)\n      apply(simp add: FrameStatEq_def)\n      apply(drule_tac \\<Psi>=\\<Psi> in quietFrame)\n      apply(rule_tac G=\"\\<langle>\\<epsilon>, \\<Psi>\\<rangle>\" in FrameStatImpTrans)\n      apply auto\n      defer\n      using Identity\n      apply(simp add: AssertionStatEq_def)\n      apply(simp add: FrameStatEq_def)\n      done\n  next\n    case(cSim \\<Psi> P Q)\n    moreover have \"eqvt ?X\" by(auto simp add: eqvt_def intro: quietEqvt)\n    ultimately show ?case\n      apply auto\n      apply(rule quietSim)\n      apply auto\n      apply(auto simp add: weakSimulation_def)\n      done\n  next\n    case(cExt \\<Psi> P Q \\<Psi>')\n    thus ?case by blast\n  next\n    case(cSym \\<Psi> P Q)\n    thus ?case by blast\n  qed\nqed\n\nlemma weakTransitiveWeakCoinduct[case_names cStatImp cSim cExt cSym, case_conclusion bisim step, consumes 2]:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   X :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n\n  assumes p: \"(\\<Psi>, P, Q) \\<in> X\"\n  and Eqvt: \"eqvt X\"\n  and rStatImp: \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> \\<Psi> \\<rhd> P \\<lessapprox><X> Q\"\n  and rSim: \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> \\<Psi> \\<rhd> P \\<leadsto><({(\\<Psi>, P, Q) | \\<Psi> P Q. \\<exists>P' Q'. \\<Psi> \\<rhd> P \\<sim> P' \\<and>\n                                                                        (\\<Psi>, P', Q') \\<in> X \\<and>\n                                                                        \\<Psi> \\<rhd> Q' \\<sim> Q})> Q\"\n  and rExt: \"\\<And>\\<Psi> P Q \\<Psi>'. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> (\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> X\"\n  and rSym: \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> (\\<Psi>, Q, P) \\<in> X\"\n\n  shows \"\\<Psi> \\<rhd> P \\<approx> Q\"\nproof -\n  let ?X = \"{(\\<Psi>, P, Q) | \\<Psi> P Q. \\<exists>P' Q'. \\<Psi> \\<rhd> P \\<sim> P' \\<and> (\\<Psi>, P', Q') \\<in> X \\<and> \\<Psi> \\<rhd> Q' \\<sim> Q}\"\n  from p have \"(\\<Psi>, P, Q) \\<in> ?X\"\n    by(blast intro: bisimReflexive)\n  thus ?thesis\n  proof(coinduct rule: weakBisimWeakCoinduct)\n    case(cStatImp \\<Psi> P Q)\n    {\n      fix \\<Psi>'\n      from \\<open>(\\<Psi> , P, Q) \\<in> ?X\\<close> obtain P' Q' where \"\\<Psi> \\<rhd> P \\<sim> P'\" and \"(\\<Psi>, P', Q') \\<in> X\" and \"\\<Psi> \\<rhd> Q' \\<sim> Q\" by auto\n      from \\<open>(\\<Psi>, P', Q') \\<in> X\\<close> obtain Q'' Q''' where Q'Chain: \"\\<Psi> \\<rhd> Q' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q''\"\n                                               and PImpQ: \"insertAssertion (extractFrame P') \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame Q'') \\<Psi>\"\n                                               and Q''Chain: \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> Q'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q'''\" and \"(\\<Psi> \\<otimes> \\<Psi>', P', Q''') \\<in> X\"\n        apply(drule_tac rStatImp) by(auto simp add: weakStatImp_def) blast\n      from \\<open>\\<Psi> \\<rhd> Q' \\<sim> Q\\<close> have \"\\<Psi> \\<rhd> Q \\<sim> Q'\" by(rule bisimE)\n      then obtain Q'''' where \"\\<Psi> \\<rhd> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q''''\" and \"\\<Psi> \\<rhd> Q'''' \\<sim> Q''\" using  \\<open>\\<Psi> \\<rhd> Q' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q''\\<close> bisimE(2)\n        by(rule simTauChain)\n      note \\<open>\\<Psi> \\<rhd> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q''''\\<close>\n      moreover have \"insertAssertion (extractFrame P) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame Q'''') \\<Psi>\"\n      proof -\n        from \\<open>\\<Psi> \\<rhd> P \\<sim> P'\\<close> have \"insertAssertion (extractFrame P) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P') \\<Psi>\"\n          by(drule_tac bisimE) (simp add: FrameStatEq_def)\n        moreover from \\<open>\\<Psi> \\<rhd> Q'''' \\<sim> Q''\\<close> have \"insertAssertion (extractFrame Q'') \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame Q'''') \\<Psi>\"\n          by(drule_tac bisimE) (simp add: FrameStatEq_def)\n        ultimately show ?thesis using PImpQ by(blast intro: FrameStatImpTrans)\n      qed\n      moreover from \\<open>\\<Psi> \\<rhd> Q'''' \\<sim> Q''\\<close> have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> Q'''' \\<sim> Q''\" by(metis bisimE)\n      then obtain Q''''' where Q''''Chain: \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> Q'''' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q'''''\" and \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> Q''''' \\<sim> Q'''\" using Q''Chain bisimE(2)\n        by(rule simTauChain)\n      moreover from \\<open>\\<Psi> \\<rhd> P \\<sim> P'\\<close> \\<open>(\\<Psi> \\<otimes> \\<Psi>' , P', Q''') \\<in> X\\<close> \\<open>\\<Psi> \\<otimes> \\<Psi>' \\<rhd> Q''''' \\<sim> Q'''\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>', P, Q''''') \\<in> ?X\" by(auto dest: bisimE)\n      ultimately have \"\\<exists>Q' Q''. \\<Psi> \\<rhd> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q'' \\<and> insertAssertion (extractFrame P) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame Q'') \\<Psi> \\<and> \\<Psi> \\<otimes> \\<Psi>' \\<rhd> Q'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q' \\<and> (\\<Psi> \\<otimes> \\<Psi>', P, Q') \\<in> ?X\" by blast\n    }\n    with \\<open>(\\<Psi>, P, Q) \\<in> ?X\\<close> show ?case by(simp add: weakStatImp_def) blast\n  next\n    case(cSim \\<Psi> P Q)\n    from \\<open>(\\<Psi>, P, Q) \\<in> ?X\\<close> obtain P' Q' where \"\\<Psi> \\<rhd> P \\<sim> P'\" and \"(\\<Psi>, P', Q') \\<in> X\" and \"\\<Psi> \\<rhd> Q' \\<sim> Q\" by auto\n    from \\<open>(\\<Psi>, P', Q') \\<in> X\\<close> have \"\\<Psi> \\<rhd> P' \\<leadsto><?X> Q'\" \n      by(rule rSim)\n    moreover from \\<open>\\<Psi> \\<rhd> Q' \\<sim> Q\\<close> have \"\\<Psi> \\<rhd> Q' \\<leadsto>[bisim] Q\" by(rule bisimE)\n    moreover from \\<open>eqvt X\\<close> have \"eqvt ?X\"\n      apply(auto simp add: eqvt_def)\n      apply(drule_tac p=p in bisimClosed)\n      apply(drule_tac p=p in bisimClosed)\n      apply(rule_tac x=\"p \\<bullet> P'\" in exI, simp)\n      by(rule_tac x=\"p \\<bullet> Q'\" in exI, auto)\n    moreover from \\<open>\\<Psi> \\<rhd> Q' \\<sim> Q\\<close> have \"insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame Q') \\<Psi>\"\n      by(drule_tac bisimE) (simp add: FrameStatEq_def)\n    moreover have \"{(\\<Psi>, P, R) | \\<Psi> P R. \\<exists>Q. (\\<Psi>, P, Q) \\<in> ?X \\<and> \\<Psi> \\<rhd> Q \\<sim> R} \\<subseteq> ?X\"\n      by(blast intro: bisimTransitive)\n    moreover note bisimE(3)\n    ultimately have \"\\<Psi> \\<rhd> P' \\<leadsto><?X> Q\" by(rule strongAppend) \n    moreover have \"{(\\<Psi>, P, R) | \\<Psi> P R. \\<exists>Q. \\<Psi> \\<rhd> P \\<sim> Q \\<and> (\\<Psi>, Q, R) \\<in> ?X} \\<subseteq> ?X\"\n      by(blast intro: bisimTransitive)\n    moreover {\n      fix \\<Psi> P Q\n\n      assume \"\\<Psi> \\<rhd> P \\<sim> Q\"\n      moreover have \"\\<And>\\<Psi> P Q. \\<Psi> \\<rhd> P \\<sim> Q \\<Longrightarrow> insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P) \\<Psi>\"\n        by(drule_tac bisimE) (simp add: FrameStatEq_def)\n      ultimately have \"\\<Psi> \\<rhd> P \\<leadsto><bisim> Q\" using bisimE(2) bisimE(3)\n        by(rule strongSimWeakSim)\n    }\n    ultimately show ?case using \\<open>\\<Psi> \\<rhd> P \\<sim> P'\\<close> \\<open>eqvt ?X\\<close>\n      by(rule_tac weakSimTransitive)\n  next\n    case(cExt \\<Psi> P Q \\<Psi>')\n    thus ?case by(blast dest: bisimE intro: rExt)\n  next\n    case(cSym \\<Psi> P Q)\n    thus ?case by(blast dest: bisimE intro: rSym)\n  qed\nqed\n\n\n\n  assumes p: \"(\\<Psi>, P, Q) \\<in> X\"\n  and Eqvt: \"eqvt X\"\n  and rStatImp: \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> \\<Psi> \\<rhd> P \\<lessapprox><(X \\<union> weakBisim)> Q\"\n  and rSim: \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> \\<Psi> \\<rhd> P \\<leadsto><({(\\<Psi>, P, Q) | \\<Psi> P Q. \\<exists>P' Q'. \\<Psi> \\<rhd> P \\<sim> P' \\<and>\n                                                                        (\\<Psi>, P', Q') \\<in> (X \\<union> weakBisim) \\<and>\n                                                                        \\<Psi> \\<rhd> Q' \\<sim> Q})> Q\"\n  and rExt: \"\\<And>\\<Psi> P Q \\<Psi>'. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> (\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> X \\<union> weakBisim\"\n  and rSym: \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> (\\<Psi>, Q, P) \\<in> X \\<union> weakBisim\"\n\n  shows \"\\<Psi> \\<rhd> P \\<approx> Q\"\nproof -\n  from p have \"(\\<Psi>, P, Q) \\<in> X \\<union> weakBisim\" by auto\n  moreover from \\<open>eqvt X\\<close> have \"eqvt(X \\<union> weakBisim)\" by auto\n  ultimately show ?thesis\n  proof(coinduct rule: weakTransitiveWeakCoinduct)\n    case(cStatImp \\<Psi> P Q)\n    thus ?case by(blast dest: rStatImp weakBisimE(1) weakStatImpMonotonic)\n  next\n    case(cSim \\<Psi> P Q)\n    thus ?case by(fastforce intro: rSim weakBisimE(2) weakSimMonotonic bisimReflexive)\n  next\n    case(cExt \\<Psi> P Q \\<Psi>')\n    thus ?case by(blast dest: weakBisimE rExt) \n  next\n    case(cSym \\<Psi> P Q)\n    thus ?case by(blast dest: weakBisimE rSym)\n  qed\nqed\n\nlemma weakTransitiveCoinduct2[case_names cStatImp cSim cExt cSym, case_conclusion bisim step, consumes 2]:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   X :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n\n  assumes p: \"(\\<Psi>, P, Q) \\<in> X\"\n  and Eqvt: \"eqvt X\"\n  and rStatImp: \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> \\<Psi> \\<rhd> P \\<lessapprox><X> Q\"\n  and rSim: \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> \\<Psi> \\<rhd> P \\<leadsto><({(\\<Psi>, P, Q) | \\<Psi> P Q. \\<exists>P' Q'. \\<Psi> \\<rhd> P \\<approx> P' \\<and> (\\<Psi>, P', Q') \\<in> X \\<and> \\<Psi> \\<rhd> Q' \\<sim> Q})> Q\"\n  and rExt: \"\\<And>\\<Psi> P Q \\<Psi>'. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> (\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> X\"\n  and rSym: \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> (\\<Psi>, Q, P) \\<in> X\"\n\n  shows \"\\<Psi> \\<rhd> P \\<approx> Q\"\nproof -\n  let ?X = \"{(\\<Psi>, P, Q) | \\<Psi> P Q. \\<exists>P' Q'. \\<Psi> \\<rhd> P \\<approx> P' \\<and> (\\<Psi>, P', Q') \\<in> X \\<and> \\<Psi> \\<rhd> Q' \\<sim> Q}\"\n  let ?Y = \"{(\\<Psi>, P, Q) | \\<Psi> P Q. \\<exists>P' Q'. \\<Psi> \\<rhd> P \\<approx> P' \\<and> (\\<Psi>, P', Q') \\<in> X \\<and> \\<Psi> \\<rhd> Q' \\<approx> Q}\"\n\n  from \\<open>eqvt X\\<close> have \"eqvt ?X\"\n    apply(auto simp add: eqvt_def)\n    apply(drule_tac p=p in bisimClosed)\n    apply(drule_tac p=p in weakBisimClosed)\n    apply(rule_tac x=\"p \\<bullet> P'\" in exI, simp)\n    by(rule_tac x=\"p \\<bullet> Q'\" in exI, auto)\n  from \\<open>eqvt X\\<close> have \"eqvt ?Y\"\n    apply(auto simp add: eqvt_def)\n    apply(drule_tac p=p in weakBisimClosed)\n    apply(drule_tac p=p in weakBisimClosed)\n    apply(rule_tac x=\"p \\<bullet> P'\" in exI, simp)\n    by(rule_tac x=\"p \\<bullet> Q'\" in exI, auto)\n\n  {\n    fix \\<Psi> P Q\n    assume \"(\\<Psi>, P, Q) \\<in> ?X\"\n    then obtain P' Q' where \"\\<Psi> \\<rhd> P \\<approx> P'\" and \"(\\<Psi>, P', Q') \\<in> X\" and \"\\<Psi> \\<rhd> Q' \\<sim> Q\"\n      by auto\n    note \\<open>\\<Psi> \\<rhd> P \\<approx> P'\\<close>\n    moreover from \\<open>(\\<Psi>, P', Q') \\<in> X\\<close> have \"\\<Psi> \\<rhd> P' \\<leadsto><?X> Q'\" by(rule rSim)\n    moreover note \\<open>eqvt ?X\\<close>\n    moreover have \"{(\\<Psi>, P, R) | \\<Psi> P R. \\<exists>Q. \\<Psi> \\<rhd> P \\<approx> Q \\<and> (\\<Psi>, Q, R) \\<in> ?X} \\<subseteq> ?X\"\n      by(blast intro: weakBisimTransitive)\n    ultimately have \"\\<Psi> \\<rhd> P \\<leadsto><?X> Q'\" using weakBisimE(2) by(rule weakSimTransitive)\n    moreover from \\<open>\\<Psi> \\<rhd> Q' \\<sim> Q\\<close> have \"\\<Psi> \\<rhd> Q' \\<leadsto>[bisim] Q\" by(rule bisimE)\n    moreover note \\<open>eqvt ?X\\<close>\n    moreover from \\<open>\\<Psi> \\<rhd> Q' \\<sim> Q\\<close> have \"insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame Q') \\<Psi>\"\n      by(drule_tac bisimE) (simp add: FrameStatEq_def)\n    moreover have \"{(\\<Psi>, P, R) | \\<Psi> P R. \\<exists>Q. (\\<Psi>, P, Q) \\<in> ?X \\<and> \\<Psi> \\<rhd> Q \\<sim> R} \\<subseteq> ?X\"\n      by(blast dest: bisimTransitive)\n    moreover note bisimE(3)\n    ultimately have \"\\<Psi> \\<rhd> P \\<leadsto><?X> Q\" by(rule_tac strongAppend) \n  }\n  note Goal = this\n\n  from p have \"(\\<Psi>, P, Q) \\<in> ?Y\" by(blast intro: weakBisimReflexive bisimReflexive rSym)\n  thus ?thesis\n  proof(coinduct rule: weakBisimWeakCoinduct)\n  next\n    case(cStatImp \\<Psi> P Q)\n    {\n      fix \\<Psi>'\n\n      from \\<open>(\\<Psi>, P, Q) \\<in> ?Y\\<close> obtain R S where \"\\<Psi> \\<rhd> P \\<approx> R\" and \"(\\<Psi>, R, S) \\<in> X\" and \"\\<Psi> \\<rhd> S \\<approx> Q\" by auto\n      from \\<open>\\<Psi> \\<rhd> P \\<approx> R\\<close> obtain R'' R' \n        where RChain: \"\\<Psi> \\<rhd> R \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> R''\" \n          and PImpR'': \"insertAssertion (extractFrame P) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame R'') \\<Psi>\"\n          and R''Chain: \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> R'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> R'\" \n          and \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<approx> R'\"\n        apply(drule_tac weakBisimE) by(simp add: weakStatImp_def) blast\n\n      from \\<open>(\\<Psi>, R, S) \\<in> X\\<close> have \"(\\<Psi>, S, R) \\<in> ?X\" by(blast intro: weakBisimReflexive bisimReflexive rSym)\n      with RChain obtain S'' where SChain: \"\\<Psi> \\<rhd> S \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> S''\" and \"(\\<Psi>, S'', R'') \\<in> ?X\" using Goal\n        by(rule weakSimTauChain)\n\n      from \\<open>(\\<Psi>, S'', R'') \\<in> ?X\\<close> obtain T U where \"\\<Psi> \\<rhd> S'' \\<approx> T\" and \"(\\<Psi>, T, U) \\<in> X\" and \"\\<Psi> \\<rhd> U \\<sim> R''\"\n        by auto\n      from \\<open>\\<Psi> \\<rhd> U \\<sim> R''\\<close> have R''ImpU: \"insertAssertion (extractFrame R'') \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame U) \\<Psi>\"\n        by(drule_tac bisimE) (simp add: FrameStatEq_def)\n      \n      from \\<open>(\\<Psi>, T, U) \\<in> X\\<close> weakStatImp_def\n      obtain T'' T' where TChain: \"\\<Psi> \\<rhd> T \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> T''\"\n                      and UImpT'': \"insertAssertion (extractFrame U) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame T'') \\<Psi>\"\n                      and T''Chain: \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> T'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> T'\" \n                      and \"(\\<Psi> \\<otimes> \\<Psi>', U, T') \\<in> X\"\n        by(blast dest: rStatImp rSym)\n\n      from TChain \\<open>\\<Psi> \\<rhd> S'' \\<approx> T\\<close> weakBisimE(2) obtain S''' where S''Chain: \"\\<Psi> \\<rhd> S'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> S'''\" and \"\\<Psi> \\<rhd> S''' \\<approx> T''\"\n        by(rule weakSimTauChain)\n\n      from \\<open>\\<Psi> \\<rhd> S''' \\<approx> T''\\<close> weakStatImp_def\n      obtain S''''' S'''' where S'''Chain: \"\\<Psi> \\<rhd> S''' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> S'''''\"\n                            and T''ImpS''''': \"insertAssertion (extractFrame T'') \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame S''''') \\<Psi>\"\n                            and S'''''Chain: \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> S''''' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> S''''\" \n                            and \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> T'' \\<approx> S''''\"\n        by(metis weakBisimE)\n      \n      from SChain S''Chain S'''Chain have \"\\<Psi> \\<rhd> S \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> S'''''\" by auto\n      moreover from \\<open>\\<Psi> \\<rhd> S \\<approx> Q\\<close> have \"\\<Psi> \\<rhd> Q \\<approx> S\" by(rule weakBisimE)\n      ultimately obtain Q''' where QChain: \"\\<Psi> \\<rhd> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q'''\" and \"\\<Psi> \\<rhd> Q''' \\<approx> S'''''\" using weakBisimE(2)\n        by(rule weakSimTauChain)\n      from \\<open>\\<Psi> \\<rhd> Q''' \\<approx> S'''''\\<close> have \"\\<Psi> \\<rhd> S''''' \\<approx> Q'''\" by(rule weakBisimE)\n      then obtain Q'' Q' where Q'''Chain: \"\\<Psi> \\<rhd> Q''' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q''\"\n                           and S'''''ImpQ'': \"insertAssertion (extractFrame S''''') \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame Q'') \\<Psi>\"\n                           and Q''Chain: \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> Q'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q'\" \n                           and \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> S''''' \\<approx> Q'\" using weakStatImp_def\n        by(metis weakBisimE)\n\n      from QChain Q'''Chain have \"\\<Psi> \\<rhd> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q''\" by auto\n      moreover from PImpR'' R''ImpU UImpT'' T''ImpS''''' S'''''ImpQ''\n      have \"insertAssertion (extractFrame P) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame Q'') \\<Psi>\"\n        by(blast dest: FrameStatImpTrans)\n\n      moreover from \\<open>\\<Psi> \\<rhd> U \\<sim> R''\\<close> have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> U \\<approx> R''\" by(metis weakBisimE strongBisimWeakBisim)\n      with R''Chain obtain U' where UChain: \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> U \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> U'\" and \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> U' \\<approx> R'\" using weakBisimE(2)\n        by(rule weakSimTauChain)\n      from \\<open>\\<Psi> \\<otimes> \\<Psi>' \\<rhd> U' \\<approx> R'\\<close> have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> R' \\<approx> U'\" by(rule weakBisimE)\n      from \\<open>(\\<Psi> \\<otimes> \\<Psi>', U, T') \\<in> X\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>', T', U) \\<in> ?X\" by(blast intro: rSym weakBisimReflexive bisimReflexive)\n      with UChain obtain T''' where T'Chain: \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> T' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> T'''\" and \"(\\<Psi> \\<otimes> \\<Psi>', T''', U') \\<in> ?X\" using Goal\n        by(rule weakSimTauChain)\n      from \\<open>(\\<Psi> \\<otimes> \\<Psi>', T''', U') \\<in> ?X\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>', U', T''') \\<in> ?Y\" \n        by(blast dest: weakBisimE rSym strongBisimWeakBisim)\n      from T''Chain T'Chain have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> T'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> T'''\" by auto\n      then obtain S'''''' where S''''Chain: \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> S'''' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> S''''''\" and \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> T''' \\<approx> S''''''\" \n        using  \\<open>\\<Psi> \\<otimes> \\<Psi>' \\<rhd> T'' \\<approx> S''''\\<close> weakBisimE(2)\n        apply(drule_tac weakBisimE(4))\n        by(rule weakSimTauChain) (auto dest: weakBisimE(4))\n      from S'''''Chain S''''Chain have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> S''''' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> S''''''\" by auto\n\n      with \\<open>\\<Psi> \\<otimes> \\<Psi>' \\<rhd> S''''' \\<approx> Q'\\<close>\n      obtain Q'''' where Q'Chain: \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> Q' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q''''\" and \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> S'''''' \\<approx> Q''''\" using weakBisimE(2)\n        apply(drule_tac weakBisimE(4))\n        by(rule weakSimTauChain) (auto dest: weakBisimE(4))\n\n      from Q''Chain Q'Chain have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> Q'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q''''\" by auto\n      moreover from \\<open>\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<approx> R'\\<close> \\<open>\\<Psi> \\<otimes> \\<Psi>' \\<rhd> R' \\<approx> U'\\<close> \\<open>(\\<Psi> \\<otimes> \\<Psi>', U', T''') \\<in> ?Y\\<close> \\<open>\\<Psi> \\<otimes> \\<Psi>' \\<rhd> T''' \\<approx> S''''''\\<close>\n                    \\<open>\\<Psi> \\<otimes> \\<Psi>' \\<rhd> S'''''' \\<approx> Q''''\\<close>\n      have \"(\\<Psi> \\<otimes> \\<Psi>', P, Q'''') \\<in> ?Y\"\n        by auto (blast dest: weakBisimTransitive)\n      ultimately have \"\\<exists>Q'' Q'. \\<Psi> \\<rhd> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q'' \\<and> insertAssertion (extractFrame P) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame Q'') \\<Psi> \\<and> \\<Psi> \\<otimes> \\<Psi>' \\<rhd> Q'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q' \\<and> (\\<Psi> \\<otimes> \\<Psi>', P, Q') \\<in> ?Y\"\n        by blast\n    }\n    thus ?case by(simp add: weakStatImp_def)\n  next\n    case(cSim \\<Psi> P Q)\n    moreover {\n      fix \\<Psi> P P' Q' Q\n      assume \"\\<Psi> \\<rhd> P \\<approx> P'\" and \"(\\<Psi>, P', Q') \\<in> X\" and \"\\<Psi> \\<rhd> Q' \\<approx> Q\"\n      from \\<open>(\\<Psi>, P', Q') \\<in> X\\<close> have \"(\\<Psi>, P', Q') \\<in> ?X\"\n        by(blast intro: weakBisimReflexive bisimReflexive)\n      moreover from \\<open>\\<Psi> \\<rhd> Q' \\<approx> Q\\<close> have \"\\<Psi> \\<rhd> Q' \\<leadsto><weakBisim> Q\" by(rule weakBisimE)\n      moreover note \\<open>eqvt ?Y\\<close>\n      moreover have \"{(\\<Psi>, P, R) | \\<Psi> P R. \\<exists>Q. (\\<Psi>, P, Q) \\<in> ?X \\<and> \\<Psi> \\<rhd> Q \\<approx> R} \\<subseteq> ?Y\"\n        by(blast dest: weakBisimTransitive strongBisimWeakBisim)\n      ultimately have \"\\<Psi> \\<rhd> P' \\<leadsto><?Y> Q\" using Goal\n        by(rule weakSimTransitive)\n      note \\<open>\\<Psi> \\<rhd> P \\<approx> P'\\<close> this \\<open>eqvt ?Y\\<close>\n      moreover have \"{(\\<Psi>, P, R) | \\<Psi> P R. \\<exists>Q. \\<Psi> \\<rhd> P \\<approx> Q \\<and> (\\<Psi>, Q, R) \\<in> ?Y} \\<subseteq> ?Y\"\n        by(blast dest: weakBisimTransitive)\n      ultimately have \"\\<Psi> \\<rhd> P \\<leadsto><?Y> Q\" using weakBisimE(2)\n        by(rule weakSimTransitive)\n    }      \n    ultimately show ?case by auto\n  next\n    case(cExt \\<Psi> P Q \\<Psi>')\n    thus ?case by(blast dest: bisimE weakBisimE intro: rExt)\n  next\n    case(cSym \\<Psi> P Q) \n    thus ?case by(blast dest: bisimE(4) weakBisimE(4) rSym)\n  qed\nqed\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Psi_Calculi/Weak_Bisimulation.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5583269943353744, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.27480192246452306}}
{"text": "theory RedSafeCase\n  imports WTLemma RedSafeUnpack\nbegin \n  \n  (* ###### case lemmas *)    \n\nlemma safe_app_op_case: \"\\<lbrakk> app_red_exp OpApp (s1, AppExp (OpExp xop) v) ax (s2, e2); FunTy tx tau r a = op_type xop \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e2 tau r_s1 empty_use_env\"\n  apply (case_tac v)\n       apply (auto)\n  apply (case_tac ax)\n   apply (auto)\n    (* given xop: op, x1: const, assuming tau matches the return type of xop, we want to show that e2 is well-typed.\n        now e2 can either be an op or a const.\n    *)\n  apply (case_tac \"\\<not> (\\<exists> rop. e2 = OpExp rop)\")\n   apply (case_tac \"\\<not> (\\<exists> c. e2 = ConstExp c)\")\n    apply (auto)\n        apply (case_tac xop)\n             apply (auto)\n    (* the hard part is proving that e2 will have the right type. *)\n       apply (case_tac xop)\n            apply (auto)\n         apply (simp add: pure_fun_def)\n        apply (simp add: pure_fun_def)\n       apply (simp add: pure_fun_def)\n      apply (rule_tac id_leq_use_env)\n     apply (rule_tac leq_empty_use_env)\n    (* op case, same thing *)\n    apply (case_tac xop)\n         apply (auto)\n      apply (simp add: pure_fun_def)\n     apply (simp add: pure_fun_def)\n    apply (simp add: pure_fun_def)\n   apply (rule_tac id_leq_use_env)\n  apply (rule_tac leq_empty_use_env)\n  done  \n\nlemma well_typed_state_add_vars: \"\\<lbrakk> well_typed_state s1 env rs_map; fresh_var s1 x; well_typed_mem_value env r_s tau v; proper_mem_value rs_map v;\n  sub_use_env s1 r_s; sep_nres_map r_s (rem_env rs_map x) \\<rbrakk> \\<Longrightarrow>\n  well_typed_state (add_env s1 x v) (add_env env (Loc x) tau) (add_env rs_map x r_s)\"\n    (* starts by proving the validity of the env + res map *)\n  apply (simp add: well_typed_state_def)\n  apply (auto)\n    apply (rule_tac dist_add_sub_env)\n    apply (simp)\n   apply (simp add: valid_nres_map_def)\n   apply (auto)\n    (* the state is still fully covered by the map *)\n     apply (simp add: full_nres_map_def)\n     apply (auto)\n      apply (simp add: add_env_def)\n      apply (auto)\n     apply (simp add: add_env_def)\n     apply (auto)\n    (* prove disjointness remains *)\n    apply (rule_tac disj_add_nres_map)\n     apply (auto)\n    (* prove containment remains *)\n   apply (rule_tac add_sub_nres_map2)\n    apply (rule_tac add_sub_nres_map1)\n     apply (simp_all)\n   apply (simp add: fresh_var_def)\n    (* now it remains to prove that all the values are still well-typed. we do the x = xa case first *)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (case_tac \"x = xa\")\n   apply (case_tac \"add_env s1 x v x\")\n    apply (simp add: add_env_def)\n   apply (auto)\n   apply (case_tac \"add_env env (Loc x) tau (Loc x)\")\n    apply (simp add: add_env_def)\n   apply (auto)\n   apply (cut_tac rs_map=\"rs_map\" and x=\"x\" and r_s=\"r_s\" in nres_add_same)\n   apply (simp)\n   apply (rule_tac well_typed_mv_add_vars)\n    apply (simp add: add_env_def)\n   apply (simp add: fresh_var_def)\n    apply (simp add: sub_env_def)\n    apply (erule_tac x=\"Loc x\" in allE)\n    apply (auto)\n    (* proper mem value *)\n   apply (rule_tac proper_add_mv)\n    apply (simp add: add_env_def)\n   apply (simp add: nres_lookup_def)\n   apply (simp add: valid_nres_map_def)\n   apply (simp add: full_nres_map_def)\n   apply (simp add: fresh_var_def)\n   apply (rule_tac leq_empty_use_env)\n    (* now we do that x \\<noteq> xa case *)\n  apply (simp add: add_env_def)\n  apply (case_tac \"s1 xa\")\n   apply (auto)\n  apply (simp add: add_env_def)\n  apply (case_tac \"env (Loc xa)\")\n   apply (auto)\n  apply (cut_tac rs_map=\"rs_map\" and x=\"x\" and r_s=\"r_s\" and y=\"xa\" in nres_add_diff)\n   apply (simp_all)\n  apply (rule_tac well_typed_mv_add_vars)\n   apply (auto)\n  apply (simp add: fresh_var_def)\n   apply (simp add: sub_env_def)\n   apply (erule_tac x=\"Loc x\" in allE)\n   apply (auto)\n    (* properness *)\n  apply (rule_tac proper_add_mv)\n   apply (simp)\n  apply (simp add: fresh_var_def)\n  apply (simp add: valid_nres_map_def)\n  apply (simp add: full_nres_map_def)\n  apply (simp add: nres_lookup_def)\n  apply (rule_tac leq_empty_use_env)\n  done    \n\n    \nlemma sacc_make_act_case: \"\n        \\<lbrakk>well_typed_state s1 env rs_map; app_red_exp ConstApp (s1, AppExp (ConstExp c) v) (MakeAct x) (s2, e2); valid_exp_use_env s1 rs_map r_f;\n                well_typed env r_s1 v t1 r_s2 rx2; leq_use_env r_s3 (diff_use_env r_s2 (comp_use_env rx1 (lift_use_env rx2 r))); leq_use_env rx r_s3;\n                FunTy t1 t2 r a \\<in> const_type c; c \\<noteq> FixConst; ax = MakeAct x; leq_use_env r_s1 r_f\\<rbrakk>\n               \\<Longrightarrow> well_typed (add_env env (Loc x) t2) (add_use_env r_s1 (Loc x) OwnPerm) e2 t2 r_s3 rx\"\n    (* e2 will always be the generated variable *)\n  apply (case_tac \"e2 \\<noteq> VarExp (LocType x x)\")\n   apply (case_tac c)\n                apply (auto)\n    (* simple var reqs *)\n   apply (simp add: add_env_def)\n    apply (case_tac c)\n               apply (auto)\n  apply (simp add: add_env_def)\n  apply (auto)\n    apply (case_tac c)\n                apply (auto)\n    apply (simp add: pure_fun_def)\n   apply (rule_tac ereq_leq_use_envx)\n   apply (simp add: add_use_env_def)\n    (* prelim: x2 is fresh *)\n  apply (case_tac \"\\<not> fresh_var s1 x\")\n   apply (case_tac c)\n                apply (auto)\n    (* prelim: cs is empty, remove elim *)(*\n  apply (case_tac \"\\<not> cs = {}\")\n   apply (case_tac c)\n                apply (auto)*)\n    (* prelim: r_s3 \\<le> r_s1 *)\n  apply (cut_tac r_sc=\"r_s3\" and r_sb=\"diff_use_env r_s2 (comp_use_env rx1 (lift_use_env rx2 r))\" and r_sa=\"r_s1\" in trans_leq_use_env)\n    apply (rule_tac diff_leq_use_env)\n    apply (simp_all)\n    (* we can achieve the desired permissions by removing x from the end perms + reqs (which is okay since they dont appear anywhere else yet). *)\n  apply (rule_tac x=\"one_use_env (Loc x) OwnPerm\" in exI)\n  apply (auto)\n    (* - the end perm bound is possible since we assume r_s3 didnt already contain x2 *)\n    apply (rule_tac t=\" leq_use_env r_s3 (diff_use_env (add_use_env r_s1 (Loc x) OwnPerm) (comp_use_env (ereq_use_env (Loc x) t2) (one_use_env (Loc x) OwnPerm)))\" and\n        s=\" leq_use_env (rem_use_env r_s3 (Loc x)) (diff_use_env (add_use_env r_s1 (Loc x) OwnPerm) (comp_use_env (ereq_use_env (Loc x) t2) (one_use_env (Loc x) OwnPerm)))\" in subst)\n     apply (cut_tac r_s=\"r_s3\" and x=\"Loc x\" in ignore_rem_use_env)\n      apply (rule_tac r_s=\"r_s1\" in leq_use_none)\n       apply (auto)\n     apply (simp add: valid_exp_use_env_def)\n     apply (simp add: sub_use_env_def)\n     apply (auto)\n     apply (simp add: fresh_var_def)\n     apply (cut_tac r_x=\"r_s1\" and r_s=\"r_f\" and x=\"Loc x\" in leq_use_none)\n       apply (auto)\n    (* - given this, we can finish proving the bound *)\n    apply (rule_tac rhs_unroll_dcl_use_env)\n    apply (rule_tac rhs_unroll_rem_use_env)\n    apply (rule_tac dist_rem_leq_use_env)\n    apply (rule_tac rhs_weak_leq_use_env)\n     apply (rule_tac weak_ereq_use_env)\n     apply (case_tac c)\n                   apply (auto)\n     apply (simp add: pure_fun_def)\n     apply (simp add: unlim_def)\n    apply (rule_tac rhs_add_leq_use_env)\n     apply (auto)\n    (* - unrolling definitions to prove the subtracter bound *)\n   apply (simp add: leq_use_env_def)\n   apply (simp add: one_use_env_def)\n   apply (simp add: add_use_env_def)\n    (* - proving the requirement bound *)\n  apply (rule_tac r_sb=\"diff_use_env (ereq_use_env (Loc x) t2) (one_use_env (Loc x) OwnPerm)\" in trans_leq_use_env)\n   apply (simp add: ereq_use_env_def)\n   apply (rule_tac diff_one_leq_use_env)\n  apply (rule_tac lhs_unroll_dcl_use_env)\n  apply (rule_tac dist_diff_leq_use_env)\n  apply (rule_tac self_diff_leq_use_env)\n  done    \n    \nlemma add_env_force_ex: \"\\<lbrakk> \\<forall> z. add_env s x v z = add_env s x w z \\<rbrakk> \\<Longrightarrow> v = w\"    \n  apply (erule_tac x=\"x\" in allE)\n  apply (simp add: add_env_def)\n  done\n    \nlemma add_env_force: \"\\<lbrakk> add_env s x v = add_env s x w \\<rbrakk> \\<Longrightarrow> v = w\"    \n  apply (rule_tac s=\"s\" and x=\"x\" and v=\"v\" and w=\"w\" in add_env_force_ex)\n  apply (auto)\n  done\n    \nlemma disj_add_use_env: \"\\<lbrakk> disj_use_env r_s r_x; r_s x = NoPerm \\<rbrakk> \\<Longrightarrow> disj_use_env r_s (add_use_env r_x x r)\"    \n  apply (simp add: disj_use_env_def)\n  apply (simp add: add_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  done\n    \nlemma strong_disj_add_use_env: \"\\<lbrakk> strong_disj_use_env r_s r_x; r_s x = NoPerm \\<rbrakk> \\<Longrightarrow> strong_disj_use_env r_s (add_use_env r_x x r)\"    \n  apply (simp add: strong_disj_use_env_def)\n  apply (simp add: add_use_env_def)\n  done    \n\nlemma add_valid_exp_use_env: \"\\<lbrakk> valid_nres_map s rs_map; valid_exp_use_env s rs_map r_s; fresh_var s x \\<rbrakk> \\<Longrightarrow>\n  valid_exp_use_env (add_env s x v) (add_env rs_map x empty_use_env) (add_use_env r_s (Loc x) OwnPerm)\"  \n  apply (simp add: valid_exp_use_env_def)  \n  apply (auto)\n    (* domain preservation *)\n   apply (rule_tac rhs_add_sub_use_env)\n   apply (rule_tac add_sub_use_env)\n    apply (simp)\n   apply (simp add: add_env_def)\n    (* separation *)\n  apply (simp add: sep_nres_map_def)\n  apply (auto)\n  apply (case_tac \"x = xa\")\n   apply (auto)\n   apply (simp add: nres_add_same)\n   apply (rule_tac empty_strong_disj_use_env2)\n  apply (simp add: nres_add_diff)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (rule_tac comm_strong_disj_use_env)\n  apply (rule_tac strong_disj_add_use_env)\n  apply (rule_tac comm_strong_disj_use_env)\n   apply (simp)\n  apply (simp add: valid_nres_map_def)\n  apply (simp add: sub_nres_map_def)\n  apply (auto)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (simp add: sub_use_env_def)\n  apply (simp add: fresh_var_def)\n  apply (auto)\n  done\n\n\n  \n    (*\n      the hard part that we're dealing with right now is that at the end using pairs does NOT work for the WRITE constants,\n        since we want \"use\" permission for the array, but \"own\" permission for the value being written.\n\n      what this suggests is that we have to allow for constant + application to be a value.\n      even if we do this, we need to give them all their own unique cases, just like for unpacking.\n      - this is more complicated than it is with constants, since the contents of the first arg will generally be somewhat complex.\n\n    *)\n    \n\nlemma saccmk2_var_type: \"\\<lbrakk> env (Loc x) = Some (ChanTy t c_end) \\<rbrakk> \\<Longrightarrow>\n  well_typed env (one_use_env (Loc x) OwnPerm) (VarExp (LocType x x)) (ChanTy t c_end) (one_use_env (Loc x) OwnPerm) (one_use_env (Loc x) OwnPerm)\"    \n  apply (auto)\n   apply (rule_tac ereq_leq_use_envx)\n   apply (simp add: one_use_env_def)\n  apply (rule_tac x=\"empty_use_env\" in exI)\n  apply (auto)\n     apply (rule_tac rhs_weak_leq_use_env)\n      apply (rule_tac dist_weak_comp_use_env)\n       apply (rule_tac weak_ereq_use_env)\n       apply (simp add: unlim_def)\n      apply (simp add: weak_use_env_def)\n      apply (simp add: empty_use_env_def)\n     apply (rule_tac id_leq_use_env)\n     apply (rule_tac id_leq_use_env)\n   apply (rule_tac leq_empty_use_env)\n  apply (rule_tac diff_leq_use_env)\n  apply (rule_tac ereq_leq_use_envx)\n  apply (simp add: one_use_env_def)\n  done\n  \nlemma saccmk2_pair_type: \"\\<lbrakk> well_typed env (one_use_env x1 OwnPerm) v1 t1 (one_use_env x1 OwnPerm) (one_use_env x1 OwnPerm);\n  well_typed env (one_use_env x2 OwnPerm) v2 t2 (one_use_env x2 OwnPerm) (one_use_env x2 OwnPerm);\n  r_s1 x1 = OwnPerm; r_s1 x2 = OwnPerm; r_s2 x1 = NoPerm; r_s2 x2 = NoPerm;\n  leq_use_env r_s2 r_s1; leq_use_env rx r_s2; is_own r; x1 \\<noteq> x2 \\<rbrakk> \\<Longrightarrow>\n  well_typed env r_s1 (PairExp v1 v2) (PairTy t1 t2 r) r_s2 rx\"\n  apply (auto)\n  apply (rule_tac x=\"r_s1\" in exI)\n  apply (rule_tac x=\"r_s1\" in exI)\n  apply (rule_tac x=\"one_use_env x1 OwnPerm\" in exI)\n  apply (auto)\n   apply (rule_tac r_s=\"one_use_env x1 OwnPerm\" in well_typed_incr_simul_perm)\n    apply (simp add: leq_use_env_def)\n    apply (simp add: one_use_env_def)\n   apply (simp)\n  apply (rule_tac x=\"one_use_env x2 OwnPerm\" in exI)\n  apply (auto)\n       apply (rule_tac r_s=\"one_use_env x2 OwnPerm\" in well_typed_incr_simul_perm)\n        apply (simp add: leq_use_env_def)\n        apply (simp add: one_use_env_def)\n       apply (simp)\n      apply (simp add: is_own_def)\n      apply (simp add: leq_use_env_def)\n      apply (simp add: one_use_env_def)\n     apply (simp add: is_own_def)\n     apply (simp add: leq_use_env_def)\n     apply (simp add: one_use_env_def)\n    apply (simp add: is_own_def)\n    apply (case_tac \"max_aff (req_type t1) (req_type t2)\")\n      apply (auto)\n   apply (simp add: is_own_def)\n   apply (simp add: one_use_env_def)\n   apply (simp add: disj_use_env_def)\n   apply (simp add: mini_disj_use_env_def)\n  apply (rule_tac x=\"add_use_env (one_use_env x1 OwnPerm) x2 OwnPerm\" in exI)\n  apply (auto)\n    apply (rule_tac mini_disj_diff_leq_use_env2)\n     apply (simp)\n    apply (simp add: mini_disj_use_env_def)\n    apply (simp add: one_use_env_def)\n    apply (simp add: add_use_env_def)\n    apply (auto)\n   apply (rule_tac add_leq_use_env)\n    apply (simp add: leq_use_env_def)\n    apply (simp add: one_use_env_def)\n   apply (auto)\n  apply (simp add: pair_req_def)\n  apply (auto)\n   apply (rule_tac leq_empty_use_env)\n  apply (simp add: leq_use_env_def)\n  apply (simp add: add_use_env_def)\n  apply (simp add: diff_use_env_def)\n  apply (simp add: comp_use_env_def)\n  apply (simp add: one_use_env_def)\n  apply (simp add: is_own_def)\n  done\n    \nlemma sacc_mk2_act_case: \"\n  \\<lbrakk>well_typed_state s1 env rs_map; valid_exp_use_env s1 rs_map r_f; well_typed env r_s1 v t1 r_s2 rx2; proper_exp rs_map (AppExp (ConstExp c) v);\n                leq_use_env r_s3 (diff_use_env r_s2 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex));\n                leq_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_s2; leq_use_env r_ex r_s1; leq_use_env rx r_s3;\n                leq_use_env (app_req rx1 rx2 r t2 r_ex) rx; leq_use_env r_s1 r_f; FunTy t1 t2 r a \\<in> const_type c; c \\<noteq> FixConst; ax = Mk2Act x31 x32;\n                is_value v; app_con s1 c v (Mk2Act x31 x32) (s2, e2)\\<rbrakk>\n               \\<Longrightarrow> \\<exists>g_ax. well_typed (red_env env g_ax) (exp_red_use_env r_s1 g_ax) e2 t2 (end_red_use_env r_s3 g_ax) (end_red_use_env rx g_ax) \\<and>\n                          proper_exp (red_nres_map rs_map g_ax) e2 \\<and>\n                          well_typed_state s2 (red_env env g_ax) (red_nres_map rs_map g_ax) \\<and>\n                          valid_exp_use_env s2 (red_nres_map rs_map g_ax) (exp_red_use_env r_f g_ax) \\<and>\n                          safe_act s1 (infl_use_env r_f r_s3) g_ax \\<and> corr_act (Mk2Act x31 x32) g_ax\"\n  apply (case_tac c)\n              apply (auto)\n  apply (cut_tac eq_own)\n  apply (auto)\n  apply (rule_tac x=\"Add2ResAct x31 x32 t\" in exI)\n  apply (auto)\n       apply (cut_tac env=\"add_env (add_env env (Loc x31) (ChanTy t SEnd)) (Loc x32) (ChanTy t REnd)\" and\n        ?r_s1.0=\"add_use_env (add_use_env r_s1 (Loc x31) OwnPerm) (Loc x32) OwnPerm\" and\n        ?r_s2.0=\"r_s3\" and ?v1.0=\"VarExp (LocType x31 x31)\" and ?v2.0=\"VarExp (LocType x32 x32)\" and ?t1.0=\"ChanTy t SEnd\" and ?t2.0=\"ChanTy t REnd\"\n        and ?x1.0=\"Loc x31\" and ?x2.0=\"Loc x32\" in saccmk2_pair_type)\n                 apply (rule_tac saccmk2_var_type)\n                 apply (simp add: add_env_def)\n                apply (rule_tac saccmk2_var_type)\n                apply (simp add: add_env_def)\n               apply (auto)\n            apply (simp add: add_use_env_def)\n           apply (simp add: add_use_env_def)\n          apply (rule_tac r_s=\"r_f\" in leq_use_none)\n           apply (rule_tac r_sb=\"r_s1\" in trans_leq_use_env)\n            apply (simp)\n           apply (rule_tac r_sb=\"diff_use_env r_s2 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n            apply (rule_tac diff_leq_use_env)\n            apply (simp_all)\n          apply (simp add: fresh_var_def)\n          apply (simp add: valid_exp_use_env_def)\n          apply (simp add: sub_use_env_def)\n          apply (auto)\n         apply (rule_tac r_s=\"r_f\" in leq_use_none)\n          apply (rule_tac r_sb=\"r_s1\" in trans_leq_use_env)\n           apply (simp)\n          apply (rule_tac r_sb=\"diff_use_env r_s2 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n           apply (rule_tac diff_leq_use_env)\n            apply (simp_all)\n         apply (simp add: fresh_var_def)\n         apply (simp add: valid_exp_use_env_def)\n         apply (simp add: sub_use_env_def)\n         apply (auto)\n        apply (rule_tac rhs_add_leq_use_env)\n         apply (rule_tac rhs_add_leq_use_env)\n          apply (rule_tac r_sb=\"diff_use_env r_s2 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n           apply (rule_tac diff_leq_use_env)\n           apply (simp_all)\n       apply (rule_tac x=\"ChanTy t REnd\" in exI)\n       apply (rule_tac x=\"ra\" in exI)\n       apply (auto)\n        apply (simp add: pure_fun_def)\n        apply (simp add: is_own_def)\n       apply (rule_tac x=\"r_s2a\" in exI)\n       apply (rule_tac x=\"r_s3a\" in exI)\n       apply (rule_tac x=\"rx1a\" in exI)\n       apply (auto)\n       apply (rule_tac x=\"rx2a\" in exI)\n       apply (auto)\n       apply (rule_tac x=\"r_exb\" in exI)\n       apply (auto)\n       apply (simp add: pure_fun_def)\n       apply (simp add: is_own_def)\n    (* proving the state remains proper *)\n      apply (simp add: proper_exp_def)\n      apply (auto)\n       apply (rule_tac x=\"[]\" in exI)\n       apply (simp)\n      apply (rule_tac x=\"[]\" in exI)\n      apply (simp)\n    (* proving the state remains well-typed: environment containment *)\n     apply (simp add: well_typed_state_def)\n     apply (auto)\n       apply (rule_tac dist_add_sub_env)\n       apply (rule_tac dist_add_sub_env)\n       apply (simp)\n    (* res_map validity: completeness *)\n      apply (simp add: valid_nres_map_def)\n      apply (auto)\n        apply (rule_tac add_full_nres_map)\n        apply (rule_tac add_full_nres_map)\n        apply (simp)\n    (* - disjointness *)\n       apply (rule_tac disj_add_nres_map)\n        apply (rule_tac disj_add_nres_map)\n         apply (simp)\n        apply (simp add: sep_nres_map_def)\n        apply (simp add: empty_strong_disj_use_env1)\n       apply (simp add: sep_nres_map_def)\n       apply (simp add: empty_strong_disj_use_env1)\n    (* - element containment *)\n      apply (rule_tac dist_add_sub_nres_map)\n       apply (rule_tac dist_add_sub_nres_map)\n        apply (simp)\n       apply (rule_tac empty_sub_use_env)\n      apply (rule_tac empty_sub_use_env)\n    (* proving that the memory is still well-typed. starting with x = x31 / x = x32 *)\n     apply (case_tac \"x = x31\")\n      apply (simp add: add_env_def)\n     apply (case_tac \"x = x32\")\n      apply (simp add: add_env_def)\n    (* - otherwise compare with the originals *)\n     apply (simp add: add_env_def)\n     apply (erule_tac x=\"x\" in allE)\n     apply (case_tac \"s1 x\")\n      apply (auto)\n     apply (simp add: add_env_def)\n     apply (case_tac \"env (Loc x)\")\n      apply (auto)\n     apply (rule_tac well_typed_mv_add_vars)\n      apply (rule_tac well_typed_mv_add_vars)\n       apply (simp add: nres_lookup_def)\n       apply (simp add: add_env_def)\n      apply (simp add: fresh_var_def)\n       apply (simp add: sub_env_def)\n       apply (auto)\n     apply (simp add: fresh_var_def)\n     apply (simp add: sub_env_def)\n      apply (simp add: add_env_def)\n      apply (auto)\n    (* - properness *)\n     apply (rule_tac proper_add_mv)\n      apply (rule_tac proper_add_mv)\n       apply (simp)\n      apply (simp add: fresh_var_def)\n      apply (simp add: valid_nres_map_def)\n      apply (simp add: full_nres_map_def)\n      apply (simp add: nres_lookup_def)\n      apply (rule_tac leq_empty_use_env)\n     apply (simp add: fresh_var_def)\n     apply (simp add: valid_nres_map_def)\n     apply (simp add: full_nres_map_def)\n     apply (simp add: nres_lookup_def)\n     apply (simp add: add_env_def)\n     apply (rule_tac leq_empty_use_env)\n    (* proving the new res_map is still valid: expression map containment *)\n    apply (simp add: valid_exp_use_env_def)\n    apply (auto)\n     apply (rule_tac rhs_add_sub_use_env)\n      apply (rule_tac rhs_add_sub_use_env)\n       apply (rule_tac add_sub_use_env)\n       apply (rule_tac add_sub_use_env)\n       apply (simp)\n      apply (simp add: add_env_def)\n     apply (simp add: add_env_def)\n    (* map separation *)\n    apply (rule_tac add_sep_nres_map)\n     apply (rule_tac add_sep_nres_map)\n      apply (simp add: sep_nres_map_def)\n      apply (auto)\n      apply (simp add: well_typed_state_def)\n      apply (simp add: valid_nres_map_def)\n      apply (simp add: sub_nres_map_def)\n      apply (rule_tac add_strong_disj_use_env)\n       apply (rule_tac add_strong_disj_use_env)\n        apply (auto)\n       apply (case_tac \"\\<forall>xa. nres_lookup rs_map x xa \\<noteq> NoPerm \\<longrightarrow> (\\<exists>y. xa = Loc y \\<and> (\\<exists>ya. s1 y = Some ya))\")\n        apply (erule_tac x=\"Loc x31\" in allE)\n        apply (simp add: fresh_var_def)\n       apply (simp add: sub_use_env_def)\n      apply (case_tac \"\\<forall>xa. nres_lookup rs_map x xa \\<noteq> NoPerm \\<longrightarrow> (\\<exists>y. xa = Loc y \\<and> (\\<exists>ya. s1 y = Some ya))\")\n       apply (erule_tac x=\"Loc x32\" in allE)\n       apply (simp add: fresh_var_def)\n      apply (simp add: sub_use_env_def)\n     apply (rule_tac empty_strong_disj_use_env2)\n    apply (rule_tac empty_strong_disj_use_env2)\n   apply (simp add: fresh_var_def)\n  apply (simp add: fresh_var_def)\n  done\n      \n  \n    (* the idea is that if we added a permission, we required it to be a variable not already in the env, ie a variable free in e2.\n      so then we can remove x by default. *)\n    (* in general, this statement says that given a constant-application, the result can be typed with a certain env + perm set,\n      so that the state remains well-typed relative to the env + global perm_map, and the env + perm set remains valid *)\nlemma safe_app_con_case: \"\\<lbrakk> well_typed_state s1 env rs_map;\n    app_red_exp ConstApp (s1, AppExp (ConstExp c) v) ax (s2, e2); valid_exp_use_env s1 rs_map r_f;\n    well_typed env r_s1 v t1 r_s2 rx2; proper_exp rs_map (AppExp (ConstExp c) v);\n    leq_use_env r_s3 (diff_use_env r_s2 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex));\n    leq_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_s2; leq_use_env r_ex r_s1; disj_use_env rx1 (lift_use_env rx2 r);\n    leq_use_env rx r_s3; leq_use_env (app_req rx1 rx2 r t2 r_ex) rx; leq_use_env r_s1 r_f;\n    FunTy t1 t2 r a \\<in> const_type c; c \\<noteq> FixConst\\<rbrakk>\n       \\<Longrightarrow> \\<exists>g_ax . well_typed (red_env env g_ax) (exp_red_use_env r_s1 g_ax) e2 t2 (end_red_use_env r_s3 g_ax) (end_red_use_env rx g_ax) \\<and>\n                  proper_exp (red_nres_map rs_map g_ax) e2 \\<and> well_typed_state s2 (red_env env g_ax) (red_nres_map rs_map g_ax) \\<and>\n                  valid_exp_use_env s2 (red_nres_map rs_map g_ax) (exp_red_use_env r_f g_ax) \\<and> safe_act s1 (infl_use_env r_f r_s3) g_ax \\<and> corr_act ax g_ax\"\n  apply (case_tac ax)\n     apply (auto)\n    (* no action cases *)\n     apply (cut_tac ?r_s2.0=\"r_s2\" and ?r_s1.0=\"r_s1\" and env=\"env\" in well_typed_perm_leq)\n      apply (auto)\n     apply (case_tac c)\n                 apply (auto)\n     apply (rule_tac sares_unpack_case)\n                apply (auto)\n     apply (simp add: upc_init_abbrev_def)\n     apply (rule_tac x=\"r_s1\" in exI)\n     apply (auto)\n      apply (rule_tac id_leq_use_env)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n      apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n       apply (simp)\n      apply (rule_tac r_sb=\"comp_use_env rx1 (lift_use_env rx2 r)\" in trans_leq_use_env)\n       apply (simp)\n      apply (rule_tac self_comp_leq_use_env1)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (rule_tac x=\"r_s2\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (rule_tac x=\"r_s3a\" in exI)\n     apply (rule_tac x=\"rx1a\" in exI)\n     apply (auto)\n    (* new resource cases. in all cases t2 should be the correct type to add *)\n    apply (rule_tac x=\"AddResAct x2 t2 empty_use_env\" in exI)\n    apply (auto)\n    (* - lemma for main well-typedness statement *)\n        apply (rule_tac ?s2.0=\"s2\" and ?rx1.0=\"rx1\" in sacc_make_act_case)\n                  apply (auto)\n         apply (rule_tac r_sb=\"diff_use_env r_s2 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n          apply (rule_tac lhs_unroll_dcl_use_env)\n          apply (rule_tac self_diff_leq_use_env)\n         apply (simp)\n    (* - proper expression *)\n        apply (case_tac c)\n                    apply (auto)\n        apply (simp add: proper_exp_def)\n        apply (rule_tac x=\"[]\" in exI)\n        apply (auto)\n    (* - well typed state. *)\n       apply (case_tac \"\\<not> (\\<exists> v. s2 = add_env s1 x2 v)\")\n        apply (case_tac c)\n                    apply (auto)\n       apply (rule_tac well_typed_state_add_vars)\n           apply (auto)\n          apply (case_tac c)\n                      apply (auto)\n    (* - wt mem val: array case *)\n         apply (case_tac c)\n                     apply (auto)\n         apply (cut_tac s=\"s1\" and x=\"x2\" and v=\"va\" and w=\"ArrValue []\" in add_env_force)\n          apply (auto)\n         apply (simp add: pure_fun_def)\n    (* - valid res list *)\n         apply (rule_tac x=\"\\<lambda> x. None\" in exI)\n          apply (simp add: valid_res_list_def)\n    (* - properness *)\n         apply (case_tac c)\n                     apply (auto)\n         apply (cut_tac s=\"s1\" and x=\"x2\" and v=\"va\" and w=\"ArrValue []\" in add_env_force)\n          apply (simp)\n         apply (auto)\n    (* - x22 is contained in rs_map (true because x22 is the empty set) *)\n        apply (simp add: sub_use_env_def)\n        apply (simp add: empty_use_env_def)\n    (* - map separation + strength *)\n       apply (simp add: sep_nres_map_def)\n       apply (auto)\n       apply (rule_tac empty_strong_disj_use_env1)\n    (* - valid use env. *)\n      apply (case_tac \"\\<not> (\\<exists> v. s2 = add_env s1 x2 v)\")\n       apply (case_tac c)\n                   apply (auto)\n      apply (rule_tac add_valid_exp_use_env)\n        apply (simp add: well_typed_state_def)\n       apply (simp)\n      apply (case_tac c)\n                  apply (auto)\n     apply (case_tac c)\n                 apply (auto)\n     apply (simp add: fresh_var_def)\n    apply (rule_tac leq_empty_use_env)\n    (* dual new resource case. (basically only channel creation) *)\n   apply (rule_tac sacc_mk2_act_case)\n                apply (auto)\n    (* resource usage case. (currently empty) *)\n  apply (case_tac c)\n              apply (auto)\n(*\n   apply (case_tac c)\n                apply (auto)\n  apply (case_tac c)\n               apply (auto)*)\n  done    \n\n  \nlemma well_typed_empty_state: \"well_typed_state empty_env empty_env empty_env\"\n  apply (simp add: well_typed_state_def)\n  apply (auto)\n    apply (simp add: sub_env_def)\n    apply (simp add: empty_env_def)\n   apply (simp add: valid_nres_map_def)(*\n   apply (simp add: disj_res_map_def)\n   apply (auto)\n     apply (simp add: lookup_res_def)\n     apply (rule_tac empty_strong_disj_use_env1)*)\n   apply (auto)\n     apply (simp add: full_nres_map_def)\n     apply (simp add: empty_env_def)\n    apply (simp add: disj_nres_map_def)\n    apply (auto)\n    apply (simp add: nres_lookup_def)\n    apply (simp add: empty_env_def)\n    apply (rule_tac empty_strong_disj_use_env1)\n   apply (simp add: sub_nres_map_def)\n   apply (simp add: sub_use_env_def)\n   apply (simp add: nres_lookup_def)\n   apply (simp add: empty_env_def)\n   apply (simp add: empty_use_env_def) \n  apply (simp add: empty_env_def)\n  done\n\n  \nfun state_vars where\n  \"state_vars s = { x | x. s x \\<noteq> None }\"\n  \ndefinition fv_restr_env where\n  \"fv_restr_env e s = (\\<lambda> x. if x \\<in> free_vars e then s x else None)\"\n  \nlemma fv_restr_env_use: \"\\<lbrakk> x \\<in> free_vars e \\<rbrakk> \\<Longrightarrow> fv_restr_env e s x = s x\"  \n  apply (simp add: fv_restr_env_def)\n  done\n    \nlemma dist_rem_contain_env: \"\\<lbrakk> contain_env s s' \\<rbrakk> \\<Longrightarrow> contain_env (rem_env s x) (rem_env s' x)\"    \n  apply (simp add: contain_env_def)\n  apply (simp add: rem_env_def)\n  apply (auto)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (case_tac \"s' xa\")\n   apply (auto)\n  apply (simp add: rem_env_def)\n  done\n\nlemma fv_contain_env: \"\\<lbrakk> free_vars e' \\<subseteq> free_vars e \\<rbrakk> \\<Longrightarrow> contain_env (fv_restr_env e s) (fv_restr_env e' s)\"    \n  apply (simp add: contain_env_def)\n  apply (simp add: fv_restr_env_def)\n  apply (auto)\n  apply (case_tac \"s x\")\n   apply (auto)\n  apply (simp add: fv_restr_env_def)\n  apply (auto)\n  done\n\nlemma rem_fv_contain_env: \"\\<lbrakk> free_vars e' - {x} \\<subseteq> free_vars e \\<rbrakk> \\<Longrightarrow> contain_env (fv_restr_env e (rem_env s x)) (fv_restr_env e' (rem_env s x))\"    \n  apply (simp add: contain_env_def)\n  apply (simp add: fv_restr_env_def)\n  apply (auto)\n  apply (simp add: rem_env_def)\n  apply (auto)\n  apply (case_tac \"s xa\")\n   apply (auto)\n  apply (simp add: fv_restr_env_def)\n  apply (simp add: rem_env_def)\n  apply (auto)\n  done\n    \nlemma rem_fv_restr_env: \"rem_env (fv_restr_env e s) x = fv_restr_env e (rem_env s x)\"    \n  apply (case_tac \"\\<not> (\\<forall> y. rem_env (fv_restr_env e s) x y = fv_restr_env e (rem_env s x) y)\")\n   apply (auto)\n  apply (simp add: rem_env_def)\n  apply (simp add: fv_restr_env_def)\n  apply (case_tac \"x = y\")\n   apply (auto)\n   apply (case_tac \"x \\<in> free_vars e\")\n    apply (auto)\n  apply (simp add: fv_restr_env_def)\n  apply (case_tac \"y \\<in> free_vars e\")\n   apply (auto)\n  done\n\n    \n    (* the question is, how do we allow for replicable pairs while enforcing full resource disjointness?\n        i guess the \"natural\" way to do it based on what we already have is to simply allow pairs that contain\n        values that are not unique to also be values.\n\n        - if x is in the end perms, x is in the reqs. if r is own, (lift rx r) subtracts it out.\n        - if r is not own, it means that e is replicable, in which case it is again not a var,\n        - x is not in the end perms, which is trivial\n\n        an even cleaner solution is to make a \"replicable\" pair value and type accordingly.\n        in this case e is still a var, however at the level of reduction semantics, we can keep\n        the var out of the name set.\n     *)\n    \nend", "meta": {"author": "anon-ef", "repo": "perm_lang_ef2", "sha": "0fcb6e4c175193cc7b94f297a8aaa605f502d711", "save_path": "github-repos/isabelle/anon-ef-perm_lang_ef2", "path": "github-repos/isabelle/anon-ef-perm_lang_ef2/perm_lang_ef2-0fcb6e4c175193cc7b94f297a8aaa605f502d711/perm_ref/RedSafeCase.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5813031051514763, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.2747723727132529}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\nsection \"Additional Syntax for Word Bit Operations\"\n\ntheory Word_Syntax\nimports\n  \"~~/src/HOL/Word/WordBitwise\"\n  WordBitwise_Signed\n  Hex_Words\n  Norm_Words\nbegin\n\ntext \\<open>Additional bit and type syntax that forces word types.\\<close>\n\ntype_synonym word8 = \"8 word\"\ntype_synonym word16 = \"16 word\"\ntype_synonym word32 = \"32 word\"\ntype_synonym word64 = \"64 word\"\n\nlemma len8: \"len_of (x :: 8 itself) = 8\" by simp\nlemma len16: \"len_of (x :: 16 itself) = 16\" by simp\nlemma len32: \"len_of (x :: 32 itself) = 32\" by simp\nlemma len64: \"len_of (x :: 64 itself) = 64\" by simp\n\n\nabbreviation\n  wordNOT  :: \"'a::len0 word \\<Rightarrow> 'a word\"      (\"~~ _\" [70] 71)\nwhere\n  \"~~ x == NOT x\"\n\nabbreviation\n  wordAND  :: \"'a::len0 word \\<Rightarrow> 'a word \\<Rightarrow> 'a word\" (infixr \"&&\" 64)\nwhere\n  \"a && b == a AND b\"\n\nabbreviation\n  wordOR   :: \"'a::len0 word \\<Rightarrow> 'a word \\<Rightarrow> 'a word\" (infixr \"||\"  59)\nwhere\n  \"a || b == a OR b\"\n\nabbreviation\n  wordXOR  :: \"'a::len0 word \\<Rightarrow> 'a word \\<Rightarrow> 'a word\" (infixr \"xor\" 59)\nwhere\n  \"a xor b == a XOR b\"\n\n(* testing for presence of word_bitwise *)\nlemma \"((x :: word32) >> 3) AND 7 = (x AND 56) >> 3\"\n  by word_bitwise\n\n(* FIXME: move to Word distribution *)\nlemma bin_nth_minus_Bit0[simp]:\n  \"0 < n \\<Longrightarrow> bin_nth (numeral (num.Bit0 w)) n = bin_nth (numeral w) (n - 1)\"\n  by (cases n; simp)\n\nlemma bin_nth_minus_Bit1[simp]:\n  \"0 < n \\<Longrightarrow> bin_nth (numeral (num.Bit1 w)) n = bin_nth (numeral w) (n - 1)\"\n  by (cases n; simp)\n\nend\n", "meta": {"author": "diekmann", "repo": "Iptables_Semantics", "sha": "e0a2516bd885708fce875023b474ae341cbdee29", "save_path": "github-repos/isabelle/diekmann-Iptables_Semantics", "path": "github-repos/isabelle/diekmann-Iptables_Semantics/Iptables_Semantics-e0a2516bd885708fce875023b474ae341cbdee29/thy/Word_Lib/Word_Syntax.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621765155565327, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.2745014577715254}}
{"text": "section \\<open>\\isaheader{Generic Map To Set Converter}\\<close>\ntheory Gen_Map2Set\nimports \n  \"../Intf/Intf_Map\"\n  \"../Intf/Intf_Set\"\n  \"../Intf/Intf_Comp\"\n  \"../../Iterator/Iterator\"\nbegin\n\nlemma map_fst_unit_distinct_eq[simp]:\n  fixes l :: \"('k\\<times>unit) list\"\n  shows \"distinct (map fst l) \\<longleftrightarrow> distinct l\"\n  by (induct l) auto\n\ndefinition \n  map2set_rel :: \"\n    (('ki\\<times>'k) set \\<Rightarrow> (unit\\<times>unit) set \\<Rightarrow> ('mi\\<times>('k\\<rightharpoonup>unit))set) \\<Rightarrow> \n    ('ki\\<times>'k) set \\<Rightarrow> \n    ('mi\\<times>('k set)) set\"\n  where \n  map2set_rel_def_internal: \n  \"map2set_rel R Rk \\<equiv> \\<langle>Rk,Id::(unit\\<times>_) set\\<rangle>R O {(m,dom m)| m. True}\"\n\nlemma map2set_rel_def: \"\\<langle>Rk\\<rangle>(map2set_rel R) \n  = \\<langle>Rk,Id::(unit\\<times>_) set\\<rangle>R O {(m,dom m)| m. True}\"\n  unfolding map2set_rel_def_internal[abs_def] by (simp add: relAPP_def)\n\nlemma map2set_relI:\n  assumes \"(s,m')\\<in>\\<langle>Rk,Id\\<rangle>R\" and \"s'=dom m'\"\n  shows \"(s,s')\\<in>\\<langle>Rk\\<rangle>map2set_rel R\"\n  using assms unfolding map2set_rel_def by blast\n\nlemma map2set_relE:\n  assumes \"(s,s')\\<in>\\<langle>Rk\\<rangle>map2set_rel R\"\n  obtains m' where \"(s,m')\\<in>\\<langle>Rk,Id\\<rangle>R\" and \"s'=dom m'\"\n  using assms unfolding map2set_rel_def by blast\n\nlemma map2set_rel_sv[relator_props]:\n  \"single_valued (\\<langle>Rk,Id\\<rangle>Rm) \\<Longrightarrow> single_valued (\\<langle>Rk\\<rangle>map2set_rel Rm)\"\n  unfolding map2set_rel_def\n  by (auto intro: single_valuedI dest: single_valuedD)\n\nlemma map2set_empty[autoref_rules_raw]:\n  assumes \"PRIO_TAG_GEN_ALGO\"\n  assumes \"GEN_OP e op_map_empty (\\<langle>Rk,Id\\<rangle>R)\"\n  shows \"(e,{})\\<in>\\<langle>Rk\\<rangle>map2set_rel R\"\n  using assms\n  unfolding map2set_rel_def\n  by auto\n\nlemmas [autoref_rel_intf] = \n  REL_INTFI[of \"map2set_rel R\" i_set] for R\n\n\ndefinition \"map2set_insert i k s \\<equiv> i k () s\"\nlemma map2set_insert[autoref_rules_raw]:\n  assumes \"PRIO_TAG_GEN_ALGO\"\n  assumes \"GEN_OP i op_map_update (Rk \\<rightarrow> Id \\<rightarrow> \\<langle>Rk,Id\\<rangle>R \\<rightarrow> \\<langle>Rk,Id\\<rangle>R)\"\n  shows \n    \"(map2set_insert i,Set.insert)\\<in>Rk\\<rightarrow>\\<langle>Rk\\<rangle>map2set_rel R \\<rightarrow> \\<langle>Rk\\<rangle>map2set_rel R\"\n  using assms\n  unfolding map2set_rel_def map2set_insert_def[abs_def]\n  by (force dest: fun_relD)\n\ndefinition \"map2set_memb l k s \\<equiv> case l k s of None \\<Rightarrow> False | Some _ \\<Rightarrow> True\"\nlemma map2set_memb[autoref_rules_raw]:\n  assumes \"PRIO_TAG_GEN_ALGO\"\n  assumes \"GEN_OP l op_map_lookup (Rk \\<rightarrow> \\<langle>Rk,Id\\<rangle>R \\<rightarrow> \\<langle>Id\\<rangle>option_rel)\"\n  shows \"(map2set_memb l ,(\\<in>))\n    \\<in> Rk\\<rightarrow>\\<langle>Rk\\<rangle>map2set_rel R\\<rightarrow>Id\"\n  using assms\n  unfolding map2set_rel_def map2set_memb_def[abs_def]\n  by (force dest: fun_relD split: option.splits)\n  \nlemma map2set_delete[autoref_rules_raw]:\n  assumes \"PRIO_TAG_GEN_ALGO\"\n  assumes \"GEN_OP d op_map_delete (Rk\\<rightarrow>\\<langle>Rk,Id\\<rangle>R\\<rightarrow>\\<langle>Rk,Id\\<rangle>R)\"\n  shows \"(d,op_set_delete)\\<in>Rk\\<rightarrow>\\<langle>Rk\\<rangle>map2set_rel R\\<rightarrow>\\<langle>Rk\\<rangle>map2set_rel R\"\n  using assms\n  unfolding map2set_rel_def\n  by (force dest: fun_relD)\n\nlemma map2set_to_sorted_list[autoref_ga_rules]:\n  fixes it :: \"'m \\<Rightarrow> ('k\\<times>unit) list\"\n  assumes A: \"GEN_ALGO_tag (is_map_to_sorted_list ordR Rk Id R it)\"\n  shows \"is_set_to_sorted_list ordR Rk (map2set_rel R) \n    (it_to_list (map_iterator_dom o (foldli o it)))\"\nproof -\n  { \n    fix l::\"('k\\<times>unit) list\"\n    have \"\\<And>l0. foldli l (\\<lambda>_. True) (\\<lambda>x \\<sigma>. \\<sigma> @ [fst x]) l0 = l0@map fst l\"\n      by (induct l) auto\n  }\n  hence S: \"it_to_list (map_iterator_dom o (foldli o it)) = map fst o it\"\n    unfolding it_to_list_def[abs_def] map_iterator_dom_def[abs_def]\n      set_iterator_image_def set_iterator_image_filter_def\n    by (auto)\n  show ?thesis\n    unfolding S\n    using assms\n    unfolding is_map_to_sorted_list_def is_set_to_sorted_list_def\n    apply clarsimp\n    apply (erule map2set_relE)\n    apply (drule spec, drule spec)\n    apply (drule (1) mp)\n    apply (elim exE conjE)\n    apply (rule_tac x=\"map fst l'\" in exI)\n    apply (rule conjI)\n    apply parametricity\n\n    unfolding it_to_sorted_list_def\n    apply (simp add: map_to_set_dom)\n    apply (simp add: sorted_wrt_map key_rel_def[abs_def])\n    done\nqed\n\nlemma map2set_to_list[autoref_ga_rules]:\n  fixes it :: \"'m \\<Rightarrow> ('k\\<times>unit) list\"\n  assumes A: \"GEN_ALGO_tag (is_map_to_list Rk Id R it)\"\n  shows \"is_set_to_list Rk (map2set_rel R) \n    (it_to_list (map_iterator_dom o (foldli o it)))\"\n  using assms unfolding is_set_to_list_def is_map_to_list_def\n  by (rule map2set_to_sorted_list)\n\n\n(*lemma map2set_it_simp[iterator_simps]:\n  \"foldli ((map fst o it) x) c f s = foldli (it x) c (\\<lambda>(k,v) s. f k s) s\" \n  by (simp add: foldli_map comp_def fn_fst_conv)\n*)\n\ntext \\<open>Transfering also non-basic operations results in specializations\n  of map-algorithms to also be used for sets\\<close>\nlemma map2set_union[autoref_rules_raw]:\n  assumes \"MINOR_PRIO_TAG (- 9)\"\n  assumes \"GEN_OP u (++) (\\<langle>Rk,Id\\<rangle>R\\<rightarrow>\\<langle>Rk,Id\\<rangle>R\\<rightarrow>\\<langle>Rk,Id\\<rangle>R)\"\n  shows \"(u,(\\<union>))\\<in>\\<langle>Rk\\<rangle>map2set_rel R\\<rightarrow>\\<langle>Rk\\<rangle>map2set_rel R\\<rightarrow>\\<langle>Rk\\<rangle>map2set_rel R\"\n  using assms\n  unfolding map2set_rel_def\n  by (force dest: fun_relD)\n\nlemmas [autoref_ga_rules] = cmp_unit_eq_linorder \nlemmas [autoref_rules_raw] = param_cmp_unit\n\nlemma cmp_lex_zip_unit[simp]:\n  \"cmp_lex (cmp_prod cmp cmp_unit) (map (\\<lambda>k. (k, ())) l)\n           (map (\\<lambda>k. (k, ())) m) =\n          cmp_lex cmp l m\"\n  apply (induct cmp l m rule: cmp_lex.induct)\n  apply (auto split: comp_res.split)\n  done\n\nlemma cmp_img_zip_unit[simp]:\n  \"cmp_img (\\<lambda>m. map (\\<lambda>k. (k,())) (f m)) (cmp_lex (cmp_prod cmp1 cmp_unit))\n    = cmp_img f (cmp_lex cmp1)\"\n  unfolding cmp_img_def[abs_def]\n  apply (intro ext)\n  apply simp\n  done\n\n(* TODO: Move *)\n\nlemma map2set_finite[relator_props]:\n  assumes \"finite_map_rel (\\<langle>Rk,Id\\<rangle>R)\"\n  shows \"finite_set_rel (\\<langle>Rk\\<rangle>map2set_rel R)\"\n  using assms\n  unfolding map2set_rel_def finite_set_rel_def finite_map_rel_def\n  by auto\n\nlemma map2set_cmp[autoref_rules_raw]:\n  assumes ELO: \"SIDE_GEN_ALGO (eq_linorder cmpk)\"\n  assumes MPAR:\n    \"GEN_OP cmp (cmp_map cmpk cmp_unit) (\\<langle>Rk,Id\\<rangle>R \\<rightarrow> \\<langle>Rk,Id\\<rangle>R \\<rightarrow> Id)\"\n  assumes FIN: \"PREFER finite_map_rel (\\<langle>Rk, Id\\<rangle>R)\"\n  shows \"(cmp,cmp_set cmpk)\\<in>\\<langle>Rk\\<rangle>map2set_rel R \\<rightarrow> \\<langle>Rk\\<rangle>map2set_rel R \\<rightarrow> Id\"\nproof -\n  interpret linorder \"comp2le cmpk\" \"comp2lt cmpk\"\n    using ELO by (simp add: eq_linorder_class_conv)\n\n  show ?thesis\n    using MPAR\n    unfolding cmp_map_def cmp_set_def\n    apply simp\n    apply parametricity\n    apply (drule cmp_extend_paramD)\n    apply (insert FIN, fastforce simp add: finite_map_rel_def) []\n    apply (simp add: sorted_list_of_map_def[abs_def])\n    apply (auto simp: map2set_rel_def cmp_img_def[abs_def] dest: fun_relD) []\n\n    apply (insert map2set_finite[OF FIN[unfolded autoref_tag_defs]],\n      fastforce simp add: finite_set_rel_def)\n    done\nqed\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Evaluation/Collections/GenCF/Gen/Gen_Map2Set.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621765155565326, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.27450145777152535}}
{"text": "(*******************************************************************************\n\n  Project: Refining Authenticated Key Agreement with Strong Adversaries\n\n  Module:  Implem_asymmetric.thy (Isabelle/HOL 2016-1)\n  ID:      $Id: Implem_asymmetric.thy 132885 2016-12-23 18:41:32Z csprenge $\n  Author:  Joseph Lallemand, INRIA Nancy <joseph.lallemand@loria.fr>\n           Christoph Sprenger, ETH Zurich <sprenger@inf.ethz.ch>\n  \n  Asymmetric channel implementation (local interpretation) using\n  public-key encryption and signatures.\n\n  Copyright (c) 2015-2016 Joseph Lallemand and Christoph Sprenger\n  Licence: LGPL\n\n*******************************************************************************)\n\nsection \\<open>Asymmetric Implementation of Channel Messages\\<close>\n\ntheory Implem_asymmetric\nimports Implem\nbegin\n\n(**************************************************************************************************)\nsubsection \\<open>Implementation of channel messages\\<close>\n(**************************************************************************************************)\n\nfun implem_asym :: \"chan \\<Rightarrow> msg\" where\n  \"implem_asym (Insec A B M) = \\<langle>InsecTag, Agent A, Agent B, M\\<rangle>\"\n |\"implem_asym (Confid A B M) = Aenc \\<langle>Agent A, M\\<rangle> (pubK B)\"\n |\"implem_asym (Auth A B M) = Sign \\<langle>Agent B, M\\<rangle> (priK A)\"\n |\"implem_asym (Secure A B M) = Sign (Aenc \\<langle>SecureTag, Agent A, M\\<rangle> (pubK B)) (priK A)\"\n\n\ntext \\<open>\nFirst step: @{locale \"basic_implem\"}. \nTrivial as there are no assumption, this locale just defines some useful abbreviations and valid.\n\\<close>\ninterpretation asym: basic_implem implem_asym\ndone\n\n\ntext \\<open>Second step: @{locale \"semivalid_implem\"}.\nHere we prove some basic properties such as injectivity and some properties about the \ninteraction of sets of implementation messages with @{term analz}; these properties are \nproved as separate lemmas as the proofs are more complex. \n\\<close>\n\ntext \\<open>Auxiliary: simpler definitions of the \\<open>implSets\\<close> for the proofs, using the \n\\<open>msgSet\\<close> definitions. \n\\<close>\n\nabbreviation implInsecSet_aux :: \"msg set \\<Rightarrow> msg set\"\nwhere \"implInsecSet_aux G \\<equiv> PairSet Tags (PairSet AgentSet (PairSet AgentSet G))\"\n\nabbreviation implAuthSet_aux :: \"msg set \\<Rightarrow> msg set\"\nwhere \"implAuthSet_aux G \\<equiv> SignSet (PairSet AgentSet G) (range priK)\"\n\nabbreviation implConfidSet_aux :: \"(agent * agent) set \\<Rightarrow> msg set \\<Rightarrow> msg set\"\nwhere \"implConfidSet_aux Ag G \\<equiv> AencSet (PairSet AgentSet G) (pubK` (Ag `` UNIV))\"\n\nabbreviation implSecureSet_aux :: \"(agent * agent) set \\<Rightarrow> msg set \\<Rightarrow> msg set\"\nwhere \"implSecureSet_aux Ag G \\<equiv>\n  SignSet (AencSet (PairSet Tags (PairSet AgentSet G)) (pubK` (Ag `` UNIV))) (range priK)\"\n\ntext \\<open>These auxiliary definitions are overapproximations.\\<close>\n\nlemma implInsecSet_implInsecSet_aux: \"asym.implInsecSet G \\<subseteq> implInsecSet_aux G\"\nby auto\n\nlemma implAuthSet_implAuthSet_aux: \"asym.implAuthSet G \\<subseteq> implAuthSet_aux G\"\nby auto\n\nlemma implConfidSet_implConfidSet_aux: \"asym.implConfidSet Ag G \\<subseteq> implConfidSet_aux Ag G\"\nby (auto, blast)\n\nlemma implSecureSet_implSecureSet_aux: \"asym.implSecureSet Ag G \\<subseteq> implSecureSet_aux Ag G\"\nby (auto, blast)\n\nlemmas implSet_implSet_aux =\n  implInsecSet_implInsecSet_aux implAuthSet_implAuthSet_aux\n  implConfidSet_implConfidSet_aux implSecureSet_implSecureSet_aux\n\ndeclare Enc_keys_clean_msgSet_Un [intro]\n\n\n(**************************************************************************************************)\nsubsection \\<open>Lemmas to pull implementation sets out of @{term analz}\\<close>\n(**************************************************************************************************)\n\ntext \\<open>\nAll these proofs are similar:\n\\begin{enumerate}\n\\item prove the lemma for the @{term \"implSet_aux\"} and with the set added outside of  \n  @{term analz} given explicitly,\n\\item prove the lemma for the @{term \"implSet_aux\"} but with payload, and\n\\item prove the lemma for the @{term \"implSet\"}.\n\\end{enumerate}\nThere  are two cases for the confidential and secure messages:\nthe general case (the payloads stay in @{term  analz}) and the case where the key is unknown\n(the messages cannot be opened and are completely removed from the @{term analz}).\n\\<close>\n\n\nsubsubsection \\<open>Pull @{term PairAgentSet} out of \\<open>analz\\<close>\\<close>\n(**************************************************************************************************)\n\nlemma analz_Un_PairAgentSet:\nshows\n  \"analz (PairSet AgentSet G \\<union> H) \\<subseteq> PairSet AgentSet G \\<union> AgentSet \\<union> analz (G \\<union> H)\"\nproof -\n  have \"analz (PairSet AgentSet G \\<union> H) \\<subseteq> PairSet AgentSet G \\<union> analz (AgentSet \\<union> G \\<union> H)\"\n    by (rule analz_Un_PairSet)\n  also have \"... \\<subseteq> PairSet AgentSet G \\<union> AgentSet \\<union> analz (G \\<union> H)\"\n    apply (simp only: Un_assoc)\n    apply (intro Un_mono analz_Un_AgentSet, fast)\n    done \n  finally show ?thesis .\nqed\n\n\nsubsubsection \\<open>Pull @{term implInsecSet} out of @{term analz}\\<close>\n(**************************************************************************************************)\n\nlemma analz_Un_implInsecSet_aux_aux:\nassumes \"Enc_keys_clean (G \\<union> H)\"\nshows \"analz (implInsecSet_aux G \\<union> H) \\<subseteq> implInsecSet_aux G \\<union> Tags \\<union> synth (analz (G \\<union> H))\"\nproof -\n   have \"analz (implInsecSet_aux G \\<union> H) \\<subseteq> \n         implInsecSet_aux G \\<union> analz (Tags \\<union> PairSet AgentSet (PairSet AgentSet G) \\<union> H)\"\n     by (rule analz_Un_PairSet)\n   also have \"... \\<subseteq> implInsecSet_aux G \\<union> Tags \\<union> analz (PairSet AgentSet (PairSet AgentSet G) \\<union> H)\"\n     using assms\n     apply - \n     apply (simp only: Un_assoc, rule Un_mono, fast)\n     apply (rule analz_Un_Tag, blast)\n     done\n   also have \"... \\<subseteq> implInsecSet_aux G \\<union> Tags \\<union> PairSet AgentSet (PairSet AgentSet G) \\<union> AgentSet \n                     \\<union> analz (PairSet AgentSet G \\<union> H)\"\n     apply -\n     apply (simp only: Un_assoc, (rule Un_mono, fast)+)\n     apply (simp only: Un_assoc [symmetric], rule analz_Un_PairAgentSet)\n     done\n   also have \n     \"... \\<subseteq> implInsecSet_aux G \\<union> Tags \\<union> PairSet AgentSet (PairSet AgentSet G) \\<union> AgentSet \n            \\<union> PairSet AgentSet G \\<union> AgentSet \\<union> analz (G \\<union> H)\"\n     apply -\n     apply (simp only: Un_assoc, (rule Un_mono, fast)+)\n     apply (simp only: Un_assoc [symmetric], rule analz_Un_PairAgentSet)\n     done\n   also have \"... \\<subseteq> implInsecSet_aux G \\<union> Tags \\<union> synth (analz (G \\<union> H))\"\n     apply - \n     apply (simp only: Un_assoc, (rule Un_mono, fast)+, auto)\n     done\n   finally show ?thesis .\nqed\n\nlemma analz_Un_implInsecSet_aux:\n  \"Enc_keys_clean (G \\<union> H) \\<Longrightarrow>\n   analz (implInsecSet_aux G \\<union> H) \\<subseteq> synth (analz (G \\<union> H)) \\<union> -payload\"\nby (rule subset_trans [OF analz_Un_implInsecSet_aux_aux], auto)\n\nlemma analz_Un_implInsecSet:\n  \"Enc_keys_clean (G \\<union> H) \\<Longrightarrow>\n   analz (asym.implInsecSet G \\<union> H) \\<subseteq> synth (analz (G \\<union> H)) \\<union> -payload\"\napply (rule subset_trans [of _ \"analz (implInsecSet_aux G \\<union> H)\" _])\napply (rule analz_mono, rule Un_mono, blast intro!: implSet_implSet_aux, simp)\napply (blast dest: analz_Un_implInsecSet_aux)\ndone\n\n\nsubsection \\<open>Pull @{term implConfidSet} out of @{term analz}\\<close>\n(**************************************************************************************************)\n\nlemma analz_Un_implConfidSet_aux_aux:\n  \"Enc_keys_clean (G \\<union> H) \\<Longrightarrow>\n  analz (implConfidSet_aux Ag G \\<union> H) \\<subseteq> \n  implConfidSet_aux Ag G \\<union> PairSet AgentSet G \\<union>\n  synth (analz (G \\<union> H))\"\napply (rule subset_trans [OF analz_Un_AencSet], blast, blast)\napply (simp only: Un_assoc, rule Un_mono, simp)\napply (rule subset_trans [OF analz_Un_PairAgentSet], blast)\ndone\n\nlemma analz_Un_implConfidSet_aux:\n  \"Enc_keys_clean (G \\<union> H) \\<Longrightarrow>\n  analz (implConfidSet_aux Ag G \\<union> H) \\<subseteq> synth (analz (G \\<union> H)) \\<union> -payload\"\nby (rule subset_trans [OF analz_Un_implConfidSet_aux_aux], auto)\n\nlemma analz_Un_implConfidSet:\n  \"Enc_keys_clean (G \\<union> H) \\<Longrightarrow>\n   analz (asym.implConfidSet Ag G \\<union> H) \\<subseteq> synth (analz (G \\<union> H)) \\<union> -payload\"\napply (rule subset_trans [of _ \"analz (implConfidSet_aux Ag G \\<union> H)\" _])\napply (rule analz_mono, rule Un_mono, blast intro!: implSet_implSet_aux, simp)\nusing analz_Un_implConfidSet_aux apply blast\ndone\n\ntext \\<open>Pull @{term implConfidSet} out of @{term analz}, 2nd case where the agents are honest.\\<close>\n\nlemma analz_Un_implConfidSet_aux_aux_2:\n  \"Enc_keys_clean H \\<Longrightarrow>\n   Ag \\<inter> broken (parts H \\<inter> range LtK) = {} \\<Longrightarrow>\n   analz (implConfidSet_aux Ag G \\<union> H) \\<subseteq> implConfidSet_aux Ag G \\<union> synth (analz H)\"\napply (rule subset_trans [OF analz_Un_AencSet2], simp)\napply (auto dest:analz_into_parts)\ndone\n\nlemma analz_Un_implConfidSet_aux_2:\n  \"Enc_keys_clean H \\<Longrightarrow>\n   Ag \\<inter> broken (parts H \\<inter> range LtK) = {} \\<Longrightarrow>\n   analz (implConfidSet_aux Ag G \\<union> H) \\<subseteq> synth (analz H) \\<union> -payload\"\nby (rule subset_trans [OF analz_Un_implConfidSet_aux_aux_2], auto)\n\nlemma analz_Un_implConfidSet_2:\n  \"Enc_keys_clean H \\<Longrightarrow>\n   Ag \\<inter> broken (parts H \\<inter> range LtK) = {} \\<Longrightarrow>\n   analz (asym.implConfidSet Ag G \\<union> H) \\<subseteq> synth (analz H) \\<union> -payload\"\napply (rule subset_trans [of _ \"analz (implConfidSet_aux Ag G \\<union> H)\" _])\napply (rule analz_mono, rule Un_mono, blast intro!: implSet_implSet_aux, simp)\nusing analz_Un_implConfidSet_aux_2 apply auto\ndone\n\n\nsubsection \\<open>Pull @{term implAuthSet} out of @{term analz}\\<close>\n(**************************************************************************************************)\n\nlemma analz_Un_implAuthSet_aux_aux:\n  \"Enc_keys_clean (G \\<union> H) \\<Longrightarrow>\n   analz (implAuthSet_aux G \\<union> H) \\<subseteq> implAuthSet_aux G \\<union> synth (analz (G \\<union> H))\"\napply (rule subset_trans [OF analz_Un_SignSet], blast, blast)\napply (rule Un_mono, blast)\napply (rule subset_trans [OF analz_Un_PairAgentSet], blast)\ndone\n\nlemma analz_Un_implAuthSet_aux:\n  \"Enc_keys_clean (G \\<union> H) \\<Longrightarrow>\n   analz (implAuthSet_aux G \\<union> H) \\<subseteq> synth (analz (G \\<union> H)) \\<union> -payload\"\nby (rule subset_trans [OF analz_Un_implAuthSet_aux_aux], auto)\n\nlemma analz_Un_implAuthSet:\n  \"Enc_keys_clean (G \\<union> H) \\<Longrightarrow>\n   analz (asym.implAuthSet G \\<union> H) \\<subseteq> synth (analz (G \\<union> H)) \\<union> -payload\"\napply (rule subset_trans [of _ \"analz (implAuthSet_aux G \\<union> H)\" _])\napply (rule analz_mono, rule Un_mono, blast intro!: implSet_implSet_aux, simp)\nusing analz_Un_implAuthSet_aux apply blast\ndone\n\n\nsubsection \\<open>Pull @{term implSecureSet} out of @{term analz}\\<close>\n(**************************************************************************************************)\n\nlemma analz_Un_implSecureSet_aux_aux:\n  \"Enc_keys_clean (G \\<union> H) \\<Longrightarrow>\n   analz (implSecureSet_aux Ag G \\<union> H) \\<subseteq>\n   implSecureSet_aux Ag G \\<union> AencSet (PairSet Tags (PairSet AgentSet G)) (pubK` (Ag`` UNIV)) \\<union> \n   PairSet Tags (PairSet AgentSet G) \\<union> Tags \\<union> PairSet AgentSet G \\<union>\n   synth (analz (G \\<union> H))\"\napply (rule subset_trans [OF analz_Un_SignSet], blast, blast)\napply (simp only:Un_assoc, rule Un_mono, simp)\napply (rule subset_trans [OF analz_Un_AencSet], blast, blast)\napply (rule Un_mono, simp)\napply (rule subset_trans [OF analz_Un_PairSet], rule Un_mono, simp, simp only: Un_assoc)\napply (rule subset_trans [OF analz_Un_Tag], blast)\napply (rule Un_mono, simp)\napply (rule subset_trans [OF analz_Un_PairAgentSet], blast)\ndone\n\nlemma analz_Un_implSecureSet_aux:\n  \"Enc_keys_clean (G \\<union> H) \\<Longrightarrow>\n  analz (implSecureSet_aux Ag G \\<union> H) \\<subseteq> synth (analz (G \\<union> H)) \\<union> -payload\"\nby (rule subset_trans [OF analz_Un_implSecureSet_aux_aux], auto)\n\nlemma analz_Un_implSecureSet:\n  \"Enc_keys_clean (G \\<union> H) \\<Longrightarrow>\n   analz (asym.implSecureSet Ag G \\<union> H) \\<subseteq> synth (analz (G \\<union> H)) \\<union> -payload\"\napply (rule subset_trans [of _ \"analz (implSecureSet_aux Ag G \\<union> H)\" _])\napply (rule analz_mono, rule Un_mono, blast intro!: implSet_implSet_aux, simp)\nusing analz_Un_implSecureSet_aux apply blast\ndone\n\ntext \\<open>\nPull @{term implSecureSet} out of @{term analz}, 2nd case, where the agents are honest. \n\\<close>\nlemma analz_Un_implSecureSet_aux_aux_2:\n  \"Enc_keys_clean (G \\<union> H) \\<Longrightarrow>\n   Ag \\<inter> broken (parts H \\<inter> range LtK) = {} \\<Longrightarrow>\n   analz (implSecureSet_aux Ag G \\<union> H) \\<subseteq> \n   implSecureSet_aux Ag G \\<union> AencSet (PairSet Tags (PairSet AgentSet G)) (pubK` (Ag`` UNIV)) \\<union>\n   synth (analz H)\"\napply (rule subset_trans [OF analz_Un_SignSet], blast, blast)\napply (simp only: Un_assoc, rule Un_mono, simp)\napply (rule subset_trans [OF analz_Un_AencSet2], simp)\napply (auto dest: analz_into_parts)\ndone\n\nlemma analz_Un_implSecureSet_aux_2:\n  \"Enc_keys_clean (G \\<union> H) \\<Longrightarrow>\n   Ag \\<inter> broken (parts H \\<inter> range LtK) = {} \\<Longrightarrow>\n   analz (implSecureSet_aux Ag G \\<union> H) \\<subseteq> synth (analz H) \\<union> -payload\"\nby (rule subset_trans [OF analz_Un_implSecureSet_aux_aux_2], auto)\n\nlemma analz_Un_implSecureSet_2:\n  \"Enc_keys_clean (G \\<union> H) \\<Longrightarrow>\n   Ag \\<inter> broken (parts H \\<inter> range LtK) = {} \\<Longrightarrow>\n   analz (asym.implSecureSet Ag G \\<union> H) \\<subseteq>\n   synth (analz H) \\<union> -payload\"\napply (rule subset_trans [of _ \"analz (implSecureSet_aux Ag G \\<union> H)\" _])\napply (rule analz_mono, rule Un_mono, blast intro!: implSet_implSet_aux, simp)\nusing analz_Un_implSecureSet_aux_2 apply auto\ndone\n\ndeclare Enc_keys_clean_msgSet_Un [rule del]\n\n\nsubsection \\<open>Locale interpretations\\<close>\n(**************************************************************************************************)\n\ninterpretation asym: semivalid_implem implem_asym\nproof (unfold_locales)\n  fix x A B M x' A' B' M'\n  show \"implem_asym (Chan x A B M) = implem_asym (Chan x' A' B' M') \\<longleftrightarrow>\n        x = x' \\<and> A = A' \\<and> B = B' \\<and> M = M'\"\n    by (cases x, (cases x', auto)+)\nnext\n  fix M' M x x' A A' B B'\n  assume \"M' \\<in> payload\" \"implem_asym (Chan x A B M) \\<in> parts {implem_asym (Chan x' A' B' M')}\"\n  then show \"x = x' \\<and> A = A' \\<and> B = B' \\<and> M = M'\"\n    by (cases \"x\", auto,(cases x', auto)+)\nnext\n  fix I\n  assume \"I \\<subseteq> asym.valid\"\n  then show \"Enc_keys_clean I\"\n    proof (simp add: Enc_keys_clean_def, intro allI impI)\n      fix X Y\n      assume \"Enc X Y \\<in> parts I\"\n      obtain x A B M where \"M \\<in> payload\" and \"Enc X Y \\<in> parts {implem_asym (Chan x A B M)}\"\n      using parts_singleton [OF \\<open>Enc X Y \\<in> parts I\\<close>] \\<open>I \\<subseteq> asym.valid\\<close>\n        by (auto elim!: asym.validE)\n      then show \"Y \\<in> range LtK \\<or> Y \\<in> payload\" by (cases x, auto)\n    qed\nnext\n  fix Z\n  show \"composed (implem_asym Z)\"\n    proof (cases Z, simp)\n      fix x A B M\n      show \"composed (implem_asym (Chan x A B M))\" by (cases x, auto)\n    qed\nnext\n  fix x A B M\n  show \"implem_asym (Chan x A B M) \\<notin> payload\"\n    by (cases x, auto)\nnext\n  fix X K\n  assume \"X \\<in> asym.valid\"\n  then obtain x A B M where \"M \\<in> payload\" \"X = implem_asym (Chan x A B M)\" \n    by (auto elim: asym.validE)\n  then show \"LtK K \\<notin> parts {X}\"\n  by (cases x, auto)\nnext\n  fix G H\n  assume \"G \\<subseteq> payload\" \"Enc_keys_clean H\"\n  hence \"Enc_keys_clean (G \\<union> H)\" by (auto intro: Enc_keys_clean_Un)\n  then show \"analz ({implem_asym (Insec A B M) |A B M. M \\<in> G} \\<union> H) \\<subseteq> \n               synth (analz (G \\<union> H)) \\<union> - payload\"\n    by (rule analz_Un_implInsecSet)\nnext\n  fix G H\n  assume \"G \\<subseteq> payload\" \"Enc_keys_clean H\"\n  hence \"Enc_keys_clean (G \\<union> H)\" by (auto intro: Enc_keys_clean_Un)\n  then show \"analz ({implem_asym (Auth A B M) |A B M. M \\<in> G} \\<union> H) \\<subseteq> \n               synth (analz (G \\<union> H)) \\<union> - payload\"\n    by (rule analz_Un_implAuthSet)\nnext\n  fix G H Ag\n  assume \"G \\<subseteq> payload\" \"Enc_keys_clean H\"\n  hence \"Enc_keys_clean (G \\<union> H)\" by (auto intro: Enc_keys_clean_Un)\n  then show \"analz ({implem_asym (Confid A B M) |A B M. (A, B) \\<in> Ag \\<and> M \\<in> G} \\<union> H) \\<subseteq> \n               synth (analz (G \\<union> H)) \\<union> - payload\"\n    by (rule analz_Un_implConfidSet)\nnext\n  fix G H Ag\n  assume \"G \\<subseteq> payload\" \"Enc_keys_clean H\"\n  hence \"Enc_keys_clean (G \\<union> H)\" by (auto intro: Enc_keys_clean_Un)\n  then show \"analz ({implem_asym (Secure A B M) |A B M. (A, B) \\<in> Ag \\<and> M \\<in> G} \\<union> H) \\<subseteq> \n               synth (analz (G \\<union> H)) \\<union> - payload\"\n    by (rule analz_Un_implSecureSet)\nnext\n  fix G H Ag\n  assume \"G \\<subseteq> payload\" (*unused*)\n  assume \"Enc_keys_clean H\"\n  moreover assume \"Ag \\<inter> broken (parts H \\<inter> range LtK) = {}\"\n  ultimately show \"analz ({implem_asym (Confid A B M) |A B M. (A, B) \\<in> Ag \\<and> M \\<in> G} \\<union> H) \\<subseteq> \n               synth (analz H) \\<union> - payload\"\n    by (rule analz_Un_implConfidSet_2)\nnext\n  fix G H Ag\n  assume \"G \\<subseteq> payload\" \"Enc_keys_clean H\"\n  hence \"Enc_keys_clean (G \\<union> H)\" by (auto intro: Enc_keys_clean_Un)\n  moreover assume \"Ag \\<inter> broken (parts H \\<inter> range LtK) = {}\"\n  ultimately \n    show \"analz ({implem_asym (Secure A B M) |A B M. (A, B) \\<in> Ag \\<and> M \\<in> G} \\<union> H) \\<subseteq> \n          synth (analz H) \\<union> - payload\"\n    by (rule analz_Un_implSecureSet_2)\nqed\n\n\ntext \\<open>\nThird step: @{locale \"valid_implem\"}. The lemmas giving conditions on $M$, $A$ and $B$ for \n@{prop [display] \"implXXX A B M \\<in> synth (analz Z)\"}.\n\\<close>\n\nlemma implInsec_synth_analz:\n  \"H \\<subseteq> payload \\<union> asym.valid \\<union> range LtK \\<union> Tags \\<Longrightarrow>\n   asym.implInsec A B M \\<in> synth (analz H) \\<Longrightarrow>\n   asym.implInsec A B M \\<in> I \\<or> M \\<in> synth (analz H)\"\napply (erule synth.cases, auto)\ndone\n\nlemma implConfid_synth_analz:\n  \"H \\<subseteq> payload \\<union> asym.valid \\<union> range LtK \\<union> Tags \\<Longrightarrow>\n   asym.implConfid A B M \\<in> synth (analz H) \\<Longrightarrow>\n   asym.implConfid A B M \\<in> H \\<or> M \\<in> synth (analz H)\"\napply (erule synth.cases, auto)\napply (frule asym.analz_valid [where x=confid], auto)\ndone\n\nlemma implAuth_synth_analz:\n  \"H \\<subseteq> payload \\<union> asym.valid \\<union> range LtK \\<union> Tags \\<Longrightarrow>\n   asym.implAuth A B M \\<in> synth (analz H) \\<Longrightarrow>\n   asym.implAuth A B M \\<in> H \\<or> (M \\<in> synth (analz H) \\<and> (A, B) \\<in> broken H)\"\napply (erule synth.cases, auto)\napply (frule asym.analz_valid [where x=auth], auto)\napply (frule asym.analz_valid [where x=auth], auto)\napply (blast dest: asym.analz_LtKeys)\ndone\n\nlemma implSecure_synth_analz:\n  \"H \\<subseteq> payload \\<union> asym.valid \\<union> range LtK \\<union> Tags \\<Longrightarrow>\n   asym.implSecure A B M \\<in> synth (analz H) \\<Longrightarrow>\n   asym.implSecure A B M \\<in> H \\<or> (M \\<in> synth (analz H) \\<and> (A, B) \\<in> broken H)\"\nproof (erule synth.cases, simp_all)\n  fix X\n  assume H:\"H \\<subseteq> payload \\<union> asym.valid \\<union> range LtK \\<union> Tags\"\n  assume H':\"Sign (Aenc \\<langle>SecureTag, Agent A, M\\<rangle> (pubK B)) (priK A) = X\"\n            \" X \\<in> analz H\"\n  hence \"asym.implSecure A B M \\<in> analz H\" by auto\n  with H have \"asym.implSecure A B M \\<in> H\" by (rule asym.analz_valid)\n  with H' show \"X \\<in> H \\<or> M \\<in> synth (analz H) \\<and> (A, B) \\<in> broken H\"\n    by auto\nnext\n  fix X Y\n  assume H:\"H \\<subseteq> payload \\<union> asym.valid \\<union> range LtK \\<union> Tags\"\n  assume H':\"Aenc \\<langle>SecureTag, Agent A, M\\<rangle> (pubK B) = X \\<and> priK A = Y\"\n            \"X \\<in> synth (analz H)\" \"Y \\<in> synth (analz H)\"\n  hence \"priK A \\<in> analz H\" by auto\n  with H have HAgents:\"(A, B) \\<in> broken H \" by (auto dest: asym.analz_LtKeys)\n  from H' have \"Aenc \\<langle>SecureTag, Agent A, M\\<rangle> (pubK B) \\<in> synth (analz H)\" by auto\n  then have \"Aenc \\<langle>SecureTag, Agent A, M\\<rangle> (pubK B) \\<in> analz H \\<or> \n             M \\<in> synth (analz H)\"\n    by (rule synth.cases, auto)\n  then show \"Sign X Y \\<in> H \\<or> M \\<in> synth (analz H) \\<and> (A, B) \\<in> broken H\"\n    proof\n      assume \"M \\<in> synth (analz H)\"\n      with HAgents show ?thesis by auto\n    next\n      assume \"Aenc \\<langle>SecureTag, Agent A, M\\<rangle> (pubK B) \\<in> analz H\"\n      hence \"Aenc \\<langle>SecureTag, Agent A, M\\<rangle> (pubK B) \\<in> parts H\" by (rule analz_into_parts)\n      from H obtain Z where \n        \"Z \\<in> H\" and H'':\"Aenc \\<langle>SecureTag, Agent A, M\\<rangle> (pubK B) \\<in> parts {Z}\"\n        using parts_singleton [OF \\<open>Aenc \\<langle>SecureTag, Agent A, M\\<rangle> (pubK B) \\<in> parts H\\<close>] \n        by blast\n      moreover with H have \"Z \\<in> asym.valid\" by (auto dest!: subsetD)\n      moreover with H'' have \"Z = asym.implSecure A B M\"\n        by (auto) (erule asym.valid_cases, auto)\n      ultimately have \"asym.implSecure A B M \\<in> H\" by auto\n      with H' show ?thesis by auto\n    qed\nqed\n\n\n\ninterpretation asym: valid_implem implem_asym\nproof (unfold_locales)\n  fix H A B M\n  assume \"H \\<subseteq> payload \\<union> asym.valid \\<union> range LtK \\<union> Tags\"\n         \"implem_asym (Insec A B M) \\<in> synth (analz H)\"\n  then show \"implem_asym (Insec A B M) \\<in> H \\<or> M \\<in> synth (analz H)\"\n    by (rule implInsec_synth_analz)\nnext\n  fix H A B M\n  assume \"H \\<subseteq> payload \\<union> asym.valid \\<union> range LtK \\<union> Tags\"\n         \"implem_asym (Confid A B M) \\<in> synth (analz H)\"\n  then show \"implem_asym (Confid A B M) \\<in> H \\<or> M \\<in> synth (analz H)\"\n    by (rule implConfid_synth_analz)\nnext\n  fix H A B M\n  assume \"H \\<subseteq> payload \\<union> asym.valid \\<union> range LtK \\<union> Tags\"\n         \"implem_asym (Auth A B M) \\<in> synth (analz H)\"\n  then show \"implem_asym (Auth A B M) \\<in> H \\<or> \n             M \\<in> synth (analz H) \\<and> (A, B) \\<in> broken H\"\n    by (rule implAuth_synth_analz)\nnext\n  fix H A B M\n  assume \"H \\<subseteq> payload \\<union> asym.valid \\<union> range LtK \\<union> Tags\"\n         \"implem_asym (Secure A B M) \\<in> synth (analz H)\"\n  then show \"implem_asym (Secure A B M) \\<in> H \\<or> \n             M \\<in> synth (analz H) \\<and> (A, B) \\<in> broken H\"\n    by (rule implSecure_synth_analz)\nqed\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Key_Agreement_Strong_Adversaries/Implem_asymmetric.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6001883449573377, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.2743681294919253}}
{"text": "theory TopoS_Composition_Theory\nimports TopoS_Interface TopoS_Helper\nbegin\n\nsection\\<open>Composition Theory\\<close>\n\ntext\\<open>Several invariants may apply to one policy.\\<close>\n\ntext\\<open>The security invariants are all collected in a list. \nThe list corresponds to the security requirements. \nThe list should have the type @{typ \"('v graph \\<Rightarrow> bool) list\"}, i.e.\\ a list of predicates over the policy. \nWe need in instantiated security invariant, i.e.\\ get rid of @{typ \"'a\"} and @{typ \"'b\"}\\<close>\n\n \\<comment> \\<open>An instance (configured) a security invariant I.e.\\ a concrete security requirement, in different terminology.\\<close>\n record ('v) SecurityInvariant_configured =\n    c_sinvar::\"('v) graph \\<Rightarrow> bool\"\n    c_offending_flows::\"('v) graph \\<Rightarrow> ('v \\<times> 'v) set set\"\n    c_isIFS::\"bool\"\n\n  \\<comment> \\<open>parameters 1-3 are the @{text \"SecurityInvariant\"}:\n      @{text sinvar} @{text \"\\<bottom>\"} @{text \"receiver_violation\"}\n\n      Fourth parameter is the host attribute mapping @{text nP}\n\n      \n      TODO: probably check @{text \"wf_graph\"} here and optionally some host-attribute sanity checker as in DomainHierachy.\\<close>\n  fun new_configured_SecurityInvariant ::\n    \"((('v::vertex) graph \\<Rightarrow> ('v \\<Rightarrow> 'a) \\<Rightarrow> bool) \\<times> 'a \\<times> bool \\<times> ('v \\<Rightarrow> 'a)) \\<Rightarrow> ('v SecurityInvariant_configured) option\" where \n      \"new_configured_SecurityInvariant (sinvar, defbot, receiver_violation, nP) = \n        ( \n        if SecurityInvariant sinvar defbot receiver_violation then \n          Some \\<lparr> \n            c_sinvar = (\\<lambda>G. sinvar G nP),\n            c_offending_flows = (\\<lambda>G. SecurityInvariant_withOffendingFlows.set_offending_flows sinvar G nP),\n            c_isIFS = receiver_violation\n          \\<rparr>\n        else None\n        )\"\n\n   declare new_configured_SecurityInvariant.simps[simp del]\n\n   lemma new_configured_TopoS_sinvar_correct:\n   \"SecurityInvariant sinvar defbot receiver_violation \\<Longrightarrow> \n   c_sinvar (the (new_configured_SecurityInvariant (sinvar, defbot, receiver_violation, nP))) = (\\<lambda>G. sinvar G nP)\"\n   by(simp add: Let_def new_configured_SecurityInvariant.simps)\n\n   lemma new_configured_TopoS_offending_flows_correct:\n   \"SecurityInvariant sinvar defbot receiver_violation \\<Longrightarrow> \n   c_offending_flows (the (new_configured_SecurityInvariant (sinvar, defbot, receiver_violation, nP))) = \n   (\\<lambda>G. SecurityInvariant_withOffendingFlows.set_offending_flows sinvar G nP)\"\n   by(simp add: Let_def new_configured_SecurityInvariant.simps)\n\n\ntext\\<open>We now collect all the core properties of a security invariant, but without the @{typ \"'a\"} @{typ \"'b\"} \n      types, so it is instantiated with a concrete configuration.\\<close>\nlocale configured_SecurityInvariant =\n  fixes m :: \"('v::vertex) SecurityInvariant_configured\"\n  assumes\n    \\<comment> \\<open>As in SecurityInvariant definition\\<close>\n    valid_c_offending_flows:\n    \"c_offending_flows m G = {F. F \\<subseteq> (edges G) \\<and> \\<not> c_sinvar m G \\<and> c_sinvar m (delete_edges G F) \\<and> \n      (\\<forall> (e1, e2) \\<in> F. \\<not> c_sinvar m (add_edge e1 e2 (delete_edges G F)))}\"\n  and\n    \\<comment> \\<open>A empty network can have no security violations\\<close>\n    defined_offending:\n    \"\\<lbrakk> wf_graph \\<lparr> nodes = N, edges = {} \\<rparr> \\<rbrakk> \\<Longrightarrow> c_sinvar m \\<lparr> nodes = N, edges = {}\\<rparr>\"\n  and\n    \\<comment> \\<open>prohibiting more does not decrease security\\<close>\n    mono_sinvar:\n    \"\\<lbrakk> wf_graph \\<lparr> nodes = N, edges = E \\<rparr>; E' \\<subseteq> E; c_sinvar m \\<lparr> nodes = N, edges = E \\<rparr> \\<rbrakk> \\<Longrightarrow> \n      c_sinvar m \\<lparr> nodes = N, edges = E' \\<rparr>\"\n  begin\n    (*compatibility with other definitions*)\n    lemma sinvar_monoI: \n    \"SecurityInvariant_withOffendingFlows.sinvar_mono (\\<lambda> (G::('v::vertex) graph) (nP::'v \\<Rightarrow> 'a). c_sinvar m G)\"\n      apply(simp add: SecurityInvariant_withOffendingFlows.sinvar_mono_def, clarify)\n      by(fact mono_sinvar)\n\n    text\\<open>if the network where nobody communicates with anyone fulfilles its security requirement,\n          the offending flows are always defined.\\<close>\n    lemma defined_offending': \n      \"\\<lbrakk> wf_graph G; \\<not> c_sinvar m G \\<rbrakk> \\<Longrightarrow> c_offending_flows m G \\<noteq> {}\"\n      proof -\n        assume a1: \"wf_graph G\"\n        and    a2: \"\\<not> c_sinvar m G\"\n        have subst_set_offending_flows: \n        \"\\<And>nP. SecurityInvariant_withOffendingFlows.set_offending_flows (\\<lambda>G nP. c_sinvar m G) G nP = c_offending_flows m G\"\n        by(simp add: valid_c_offending_flows fun_eq_iff \n            SecurityInvariant_withOffendingFlows.set_offending_flows_def\n            SecurityInvariant_withOffendingFlows.is_offending_flows_min_set_def\n            SecurityInvariant_withOffendingFlows.is_offending_flows_def)\n\n        from a1 have wfG_empty: \"wf_graph \\<lparr>nodes = nodes G, edges = {}\\<rparr>\" by(simp add:wf_graph_def)\n\n        from a1 have \"\\<And>nP. \\<not> c_sinvar m G \\<Longrightarrow> SecurityInvariant_withOffendingFlows.set_offending_flows (\\<lambda>G nP. c_sinvar m G) G nP \\<noteq> {}\"\n          apply(frule_tac finite_distinct_list[OF wf_graph.finiteE])\n          apply(erule_tac exE)\n          apply(rename_tac list_edges)\n          apply(rule_tac ff=\"list_edges\" in SecurityInvariant_withOffendingFlows.mono_imp_set_offending_flows_not_empty[OF sinvar_monoI])\n          by(auto simp add: SecurityInvariant_withOffendingFlows.is_offending_flows_def delete_edges_simp2 defined_offending[OF wfG_empty])\n      \n          thus ?thesis by(simp add: a2 subst_set_offending_flows)\n    qed\n\n    (* The offending flows definitions are equal, compatibility *)\n    lemma subst_offending_flows: \"\\<And> nP. SecurityInvariant_withOffendingFlows.set_offending_flows (\\<lambda>G nP. c_sinvar m G) G nP = c_offending_flows m G\"\n      apply (unfold SecurityInvariant_withOffendingFlows.set_offending_flows_def\n            SecurityInvariant_withOffendingFlows.is_offending_flows_min_set_def\n            SecurityInvariant_withOffendingFlows.is_offending_flows_def)\n      by(simp add: valid_c_offending_flows)\n\n    text\\<open>all the @{term SecurityInvariant_preliminaries} stuff must hold, for an arbitrary @{term nP}\\<close>\n    lemma SecurityInvariant_preliminariesD:\n      \"SecurityInvariant_preliminaries (\\<lambda> (G::('v::vertex) graph) (nP::'v \\<Rightarrow> 'a). c_sinvar m G)\"\n      proof(unfold_locales, goal_cases)\n      case 1 thus ?case using defined_offending' by(simp add: subst_offending_flows)\n      next case 2 thus ?case by(fact mono_sinvar)\n      next case 3 thus ?case by(fact SecurityInvariant_withOffendingFlows.sinvar_mono_imp_is_offending_flows_mono[OF sinvar_monoI])\n      qed\n\n    lemma negative_mono:\n     \"\\<And> N E' E. wf_graph \\<lparr> nodes = N, edges = E \\<rparr> \\<Longrightarrow> \n        E' \\<subseteq> E \\<Longrightarrow> \\<not> c_sinvar m \\<lparr> nodes = N, edges = E' \\<rparr> \\<Longrightarrow> \\<not> c_sinvar m \\<lparr> nodes = N, edges = E \\<rparr>\"\n     by(blast dest: mono_sinvar)\n\n    \n    subsection\\<open>Reusing Lemmata\\<close>\n      lemmas mono_extend_set_offending_flows =\n      SecurityInvariant_preliminaries.mono_extend_set_offending_flows[OF SecurityInvariant_preliminariesD, simplified subst_offending_flows]\n      text\\<open>@{thm mono_extend_set_offending_flows [no_vars]}\\<close>\n\n      lemmas offending_flows_union_mono =\n      SecurityInvariant_preliminaries.offending_flows_union_mono[OF SecurityInvariant_preliminariesD, simplified subst_offending_flows]\n      text\\<open>@{thm offending_flows_union_mono [no_vars]}\\<close>\n\n      lemmas sinvar_valid_remove_flattened_offending_flows =\n      SecurityInvariant_preliminaries.sinvar_valid_remove_flattened_offending_flows[OF SecurityInvariant_preliminariesD, simplified subst_offending_flows]\n      text\\<open>@{thm sinvar_valid_remove_flattened_offending_flows [no_vars]}\\<close>\n\n      lemmas sinvar_valid_remove_SOME_offending_flows =\n      SecurityInvariant_preliminaries.sinvar_valid_remove_SOME_offending_flows[OF SecurityInvariant_preliminariesD, simplified subst_offending_flows]\n      text\\<open>@{thm sinvar_valid_remove_SOME_offending_flows [no_vars]}\\<close>\n\n\n      lemmas sinvar_valid_remove_minimalize_offending_overapprox =\n      SecurityInvariant_preliminaries.sinvar_valid_remove_minimalize_offending_overapprox[OF SecurityInvariant_preliminariesD, simplified subst_offending_flows]\n      text\\<open>@{thm sinvar_valid_remove_minimalize_offending_overapprox [no_vars]}\\<close>\n      \n\n      lemmas empty_offending_contra =\n      SecurityInvariant_withOffendingFlows.empty_offending_contra[where sinvar=\"(\\<lambda>G nP. c_sinvar m G)\", simplified subst_offending_flows]\n      text\\<open>@{thm empty_offending_contra [no_vars]}\\<close>\n\n      lemmas Un_set_offending_flows_bound_minus_subseteq = \n      SecurityInvariant_preliminaries.Un_set_offending_flows_bound_minus_subseteq[OF SecurityInvariant_preliminariesD, simplified subst_offending_flows]\n      text\\<open>@{thm Un_set_offending_flows_bound_minus_subseteq [no_vars]}\\<close>\n\n      lemmas Un_set_offending_flows_bound_minus_subseteq' = \n      SecurityInvariant_preliminaries.Un_set_offending_flows_bound_minus_subseteq'[OF SecurityInvariant_preliminariesD, simplified subst_offending_flows]\n      text\\<open>@{thm Un_set_offending_flows_bound_minus_subseteq' [no_vars]}\\<close>\nend\n\nthm configured_SecurityInvariant_def\ntext\\<open>@{thm configured_SecurityInvariant_def [no_vars]}\\<close>\n\nthm configured_SecurityInvariant.mono_sinvar\ntext\\<open>@{thm configured_SecurityInvariant.mono_sinvar [no_vars]}\\<close>\n\n\n\ntext\\<open>\n  Naming convention:\n    m :: network security requirement\n    M :: network security requirement list\n\\<close>\n\n  text\\<open>The function @{term new_configured_SecurityInvariant} takes some tuple and if it returns a result,\n         the locale assumptions are automatically fulfilled.\\<close>\n  theorem new_configured_SecurityInvariant_sound: \n  \"\\<lbrakk> new_configured_SecurityInvariant (sinvar, defbot, receiver_violation, nP) = Some m \\<rbrakk> \\<Longrightarrow>\n    configured_SecurityInvariant m\"\n    proof -\n      assume a: \"new_configured_SecurityInvariant (sinvar, defbot, receiver_violation, nP) = Some m\"\n      hence NetModel: \"SecurityInvariant sinvar defbot receiver_violation\"\n        by(simp add: new_configured_SecurityInvariant.simps split: if_split_asm)\n      hence NetModel_p: \"SecurityInvariant_preliminaries sinvar\" by(simp add: SecurityInvariant_def)\n\n      from a have c_eval: \"c_sinvar m = (\\<lambda>G. sinvar G nP)\"\n         and c_offending: \"c_offending_flows m = (\\<lambda>G. SecurityInvariant_withOffendingFlows.set_offending_flows sinvar G nP)\"\n         and \"c_isIFS m = receiver_violation\"\n        by(auto simp add: new_configured_SecurityInvariant.simps NetModel split: if_split_asm)\n\n      have monoI: \"SecurityInvariant_withOffendingFlows.sinvar_mono sinvar\"\n        apply(simp add: SecurityInvariant_withOffendingFlows.sinvar_mono_def, clarify)\n        by(fact SecurityInvariant_preliminaries.mono_sinvar[OF NetModel_p])\n      from SecurityInvariant_withOffendingFlows.valid_empty_edges_iff_exists_offending_flows[OF monoI, symmetric]\n            SecurityInvariant_preliminaries.defined_offending[OF NetModel_p]\n      have eval_empty_graph: \"\\<And> N nP. wf_graph \\<lparr>nodes = N, edges = {}\\<rparr> \\<Longrightarrow> sinvar \\<lparr>nodes = N, edges = {}\\<rparr> nP\"\n      by fastforce\n\n       show ?thesis\n        apply(unfold_locales)\n          apply(simp add: c_eval c_offending SecurityInvariant_withOffendingFlows.set_offending_flows_def SecurityInvariant_withOffendingFlows.is_offending_flows_min_set_def SecurityInvariant_withOffendingFlows.is_offending_flows_def)\n         apply(simp add: c_eval eval_empty_graph)\n        apply(simp add: c_eval,drule(3) SecurityInvariant_preliminaries.mono_sinvar[OF NetModel_p])\n        done\n   qed\n\ntext\\<open>All security invariants are valid according to the definition\\<close>\ndefinition valid_reqs :: \"('v::vertex) SecurityInvariant_configured list \\<Rightarrow> bool\" where\n  \"valid_reqs M \\<equiv> \\<forall> m \\<in> set M. configured_SecurityInvariant m\"\n\n subsection \\<open>Algorithms\\<close>\n    text\\<open>A (generic) security invariant corresponds to a type of security requirements (type: @{typ \"'v graph \\<Rightarrow> ('v \\<Rightarrow> 'a) \\<Rightarrow> bool\"}).\n          A configured security invariant is a security requirement in a scenario specific setting (type: @{typ \"'v graph \\<Rightarrow> bool\"}).\n          I.e., it is a security requirement as listed in the requirements document.\n          All security requirements are fulfilled for a fixed policy @{term G} if all security requirements are fulfilled for @{term G}.\\<close>\n\n\n    text\\<open>Get all possible offending flows from all security requirements\\<close>\n    definition get_offending_flows :: \"'v SecurityInvariant_configured list \\<Rightarrow> 'v graph \\<Rightarrow> (('v \\<times> 'v) set set)\" where\n      \"get_offending_flows M G = (\\<Union>m\\<in>set M. c_offending_flows m G)\"  \n\n    (*Note: only checks sinvar, not eval!! No 'a 'b type variables here*)\n    definition all_security_requirements_fulfilled :: \"('v::vertex) SecurityInvariant_configured list \\<Rightarrow> 'v graph \\<Rightarrow> bool\" where\n      \"all_security_requirements_fulfilled M G \\<equiv> \\<forall>m \\<in> set M. (c_sinvar m) G\"\n    \n    text\\<open>Generate a valid topology from the security requirements\\<close>\n    (*constant G, remove after algorithm*)\n    fun generate_valid_topology :: \"'v SecurityInvariant_configured list \\<Rightarrow> 'v graph \\<Rightarrow> 'v graph\" where\n      \"generate_valid_topology [] G = G\" |\n      \"generate_valid_topology (m#Ms) G = delete_edges (generate_valid_topology Ms G) (\\<Union> (c_offending_flows m G))\"\n\n     \\<comment> \\<open>return all Access Control Strategy models from a list of models\\<close>\n    definition get_ACS :: \"('v::vertex) SecurityInvariant_configured list \\<Rightarrow> 'v SecurityInvariant_configured list\" where\n      \"get_ACS M \\<equiv> [m \\<leftarrow> M. \\<not> c_isIFS m]\"\n     \\<comment> \\<open>return all Information Flows Strategy models from a list of models\\<close>\n    definition get_IFS :: \"('v::vertex) SecurityInvariant_configured list \\<Rightarrow> 'v SecurityInvariant_configured list\" where\n      \"get_IFS M \\<equiv> [m \\<leftarrow> M. c_isIFS m]\"\n    lemma get_ACS_union_get_IFS: \"set (get_ACS M) \\<union> set (get_IFS M) = set M\"\n      by(auto simp add: get_ACS_def get_IFS_def)\n  \n\n   subsection\\<open>Lemmata\\<close>\n    lemma valid_reqs1: \"valid_reqs (m # M) \\<Longrightarrow> configured_SecurityInvariant m\"\n      by(simp add: valid_reqs_def)\n    lemma valid_reqs2: \"valid_reqs (m # M) \\<Longrightarrow> valid_reqs M\"\n      by(simp add: valid_reqs_def)\n    lemma get_offending_flows_alt1: \"get_offending_flows M G = \\<Union> {c_offending_flows m G | m. m \\<in> set M}\"\n      apply(simp add: get_offending_flows_def)\n      by fastforce\n    lemma get_offending_flows_un: \"\\<Union>(get_offending_flows M G) = (\\<Union>m\\<in>set M. \\<Union>(c_offending_flows m G))\"\n      apply(simp add: get_offending_flows_def)\n      by blast\n  \n  \n    lemma all_security_requirements_fulfilled_mono:\n      \"\\<lbrakk> valid_reqs M; E' \\<subseteq> E; wf_graph \\<lparr> nodes = V, edges = E \\<rparr> \\<rbrakk> \\<Longrightarrow>  \n        all_security_requirements_fulfilled M \\<lparr> nodes = V, edges = E \\<rparr> \\<Longrightarrow>\n        all_security_requirements_fulfilled M \\<lparr> nodes = V, edges = E' \\<rparr>\"\n        apply(induction M arbitrary: E' E)\n         apply(simp_all add: all_security_requirements_fulfilled_def)\n        apply(rename_tac m M E' E)\n        apply(rule conjI)\n         apply(erule(2) configured_SecurityInvariant.mono_sinvar[OF valid_reqs1])\n         apply(simp_all)\n        apply(drule valid_reqs2)\n        apply blast\n        done\n\n    subsection\\<open>generate valid topology\\<close>\n    (*\n      lemma generate_valid_topology_def_delete_multiple: \n        \"generate_valid_topology M G = delete_edges (generate_valid_topology M G) (\\<Union> (get_offending_flows M G))\"\n        proof(induction M arbitrary: G)\n          case Nil\n            thus ?case by(simp add: get_offending_flows_def)\n          next\n          case (Cons m M)\n            from Cons[simplified delete_edges_simp2 get_offending_flows_def] \n            have \"edges (generate_valid_topology M G) = edges (generate_valid_topology M G) - \\<Union>(\\<Union>m\\<in>set M. c_offending_flows m G)\"\n              by (metis graph.select_convs(2))\n            thus ?case\n              apply(simp add: get_offending_flows_def delete_edges_simp2)\n              by blast\n        qed*)\n      lemma generate_valid_topology_nodes:\n      \"nodes (generate_valid_topology M G) = (nodes G)\"\n        apply(induction M arbitrary: G)\n         by(simp_all add: graph_ops)\n\n      lemma generate_valid_topology_def_alt:\n        \"generate_valid_topology M G = delete_edges G (\\<Union> (get_offending_flows M G))\"\n        proof(induction M arbitrary: G)\n          case Nil\n            thus ?case by(simp add: get_offending_flows_def)\n          next\n          case (Cons m M)\n            from Cons[simplified delete_edges_simp2 get_offending_flows_def] \n            have \"edges (generate_valid_topology M G) = edges G - \\<Union>(\\<Union>m\\<in>set M. c_offending_flows m G)\"\n              by (metis graph.select_convs(2))\n            thus ?case\n              apply(simp add: get_offending_flows_def delete_edges_simp2)\n              apply(rule)\n               apply(simp add: generate_valid_topology_nodes)\n              by blast\n        qed\n    \n      lemma wf_graph_generate_valid_topology: \"wf_graph G \\<Longrightarrow> wf_graph (generate_valid_topology M G)\"\n        proof(induction M arbitrary: G)\n        qed(simp_all)\n  \n     lemma generate_valid_topology_mono_models:\n      \"edges (generate_valid_topology (m#M) \\<lparr> nodes = V, edges = E \\<rparr>) \\<subseteq> edges (generate_valid_topology M \\<lparr> nodes = V, edges = E \\<rparr>)\"\n        proof(induction M arbitrary: E m)\n        case Nil thus ?case by(simp add: delete_edges_simp2)\n        case Cons thus ?case by(simp add: delete_edges_simp2)\n      qed\n     \n      lemma generate_valid_topology_subseteq_edges:\n      \"edges (generate_valid_topology M G) \\<subseteq> (edges G)\"\n        proof(induction M arbitrary: G)\n        case Cons thus ?case by (simp add: delete_edges_simp2) blast\n        qed(simp)\n\n      text\\<open>@{term generate_valid_topology} generates a valid topology (Policy)!\\<close>\n      theorem generate_valid_topology_sound:\n      \"\\<lbrakk> valid_reqs M; wf_graph \\<lparr>nodes = V, edges = E\\<rparr> \\<rbrakk> \\<Longrightarrow> \n      all_security_requirements_fulfilled M (generate_valid_topology M \\<lparr>nodes = V, edges = E\\<rparr>)\"\n        proof(induction M arbitrary: V E)\n          case Nil\n          thus ?case by(simp add: all_security_requirements_fulfilled_def)\n        next\n          case (Cons m M)\n          from valid_reqs1[OF Cons(2)] have validReq: \"configured_SecurityInvariant m\" .\n\n          from Cons(3) have valid_rmUnOff: \"wf_graph \\<lparr>nodes = V, edges = E - \\<Union>(c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>) \\<rparr>\"\n            by(simp add: wf_graph_remove_edges)\n          \n          from configured_SecurityInvariant.sinvar_valid_remove_flattened_offending_flows[OF validReq Cons(3)]\n          have valid_eval_rmUnOff: \"c_sinvar m \\<lparr>nodes = V, edges = E - \\<Union>(c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>) \\<rparr>\" .\n    \n          from generate_valid_topology_subseteq_edges have edges_gentopo_subseteq: \n            \"edges (generate_valid_topology M \\<lparr>nodes = V, edges = E\\<rparr>) - \\<Union>(c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>)\n               \\<subseteq>\n            E - \\<Union>(c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>)\"  by fastforce\n    \n          from configured_SecurityInvariant.mono_sinvar[OF validReq valid_rmUnOff edges_gentopo_subseteq valid_eval_rmUnOff]\n          have \"c_sinvar m \\<lparr>nodes = V, edges = (edges (generate_valid_topology M \\<lparr>nodes = V, edges = E\\<rparr>)) - \\<Union>(c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>) \\<rparr>\" .\n          from this have goal1: \n            \"c_sinvar m (delete_edges (generate_valid_topology M \\<lparr>nodes = V, edges = E\\<rparr>) (\\<Union>(c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>)))\"\n               by(simp add: delete_edges_simp2 generate_valid_topology_nodes)\n    \n          from valid_reqs2[OF Cons(2)] have \"valid_reqs M\" .\n          from Cons.IH[OF \\<open>valid_reqs M\\<close> Cons(3)] have IH:\n            \"all_security_requirements_fulfilled M (generate_valid_topology M \\<lparr>nodes = V, edges = E\\<rparr>)\" .\n\n          have generate_valid_topology_EX_graph_record:\n            \"\\<exists> hypE. (generate_valid_topology M \\<lparr>nodes = V, edges = E\\<rparr>) = \\<lparr>nodes = V, edges = hypE\\<rparr> \"\n              apply(induction M arbitrary: V E)\n               by(simp_all add: delete_edges_simp2 generate_valid_topology_nodes)\n              \n          from generate_valid_topology_EX_graph_record obtain E_IH where  E_IH_prop:\n            \"(generate_valid_topology M \\<lparr>nodes = V, edges = E\\<rparr>) = \\<lparr>nodes = V, edges = E_IH\\<rparr>\" by blast\n    \n          from wf_graph_generate_valid_topology[OF Cons(3)] E_IH_prop\n          have valid_G_E_IH: \"wf_graph \\<lparr>nodes = V, edges = E_IH\\<rparr>\" by metis\n    \n          \\<comment> \\<open>@{thm IH[simplified E_IH_prop]}\\<close>\n          \\<comment> \\<open>@{thm all_security_requirements_fulfilled_mono[OF `valid_reqs M` _  valid_G_E_IH IH[simplified E_IH_prop]]}\\<close>\n    \n          from all_security_requirements_fulfilled_mono[OF \\<open>valid_reqs M\\<close> _  valid_G_E_IH IH[simplified E_IH_prop]] have mono_rule:\n            \"\\<And> E'. E' \\<subseteq> E_IH \\<Longrightarrow> all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = E'\\<rparr>\" .\n    \n          have \"all_security_requirements_fulfilled M \n            (delete_edges (generate_valid_topology M \\<lparr>nodes = V, edges = E\\<rparr>) (\\<Union>(c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>)))\"\n            apply(subst E_IH_prop)\n            apply(simp add: delete_edges_simp2)\n            apply(rule mono_rule)\n            by fast\n    \n          from this have goal2:\n            \"(\\<forall>ma\\<in>set M.\n            c_sinvar ma (delete_edges (generate_valid_topology M \\<lparr>nodes = V, edges = E\\<rparr>) (\\<Union>(c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>))))\"\n            by(simp add: all_security_requirements_fulfilled_def)\n    \n          from goal1 goal2 \n          show  \"all_security_requirements_fulfilled (m # M) (generate_valid_topology (m # M) \\<lparr>nodes = V, edges = E\\<rparr>)\" \n          by (simp add: all_security_requirements_fulfilled_def)\n       qed\n\n\n  lemma generate_valid_topology_as_set: \n  \"generate_valid_topology M G = delete_edges G (\\<Union>m \\<in> set M. (\\<Union> (c_offending_flows m G)))\"\n   apply(induction M arbitrary: G)\n    apply(simp_all add: delete_edges_simp2 generate_valid_topology_nodes) by fastforce\n\n  lemma c_offending_flows_subseteq_edges: \"configured_SecurityInvariant m \\<Longrightarrow> \\<Union>(c_offending_flows m G) \\<subseteq> edges G\"\n    apply(clarify)\n    apply(simp only: configured_SecurityInvariant.valid_c_offending_flows)\n    apply(thin_tac \"configured_SecurityInvariant x\" for x)\n    by auto\n\n\n  text\\<open>Does it also generate a maximum topology? It does, if the security invariants are in ENF-form. That means, if \n        all security invariants can be expressed as a predicate over the edges, \n        @{term \"\\<exists>P. \\<forall>G. c_sinvar m G = (\\<forall>(v1,v2) \\<in> edges G. P (v1,v2))\"}\\<close>\n  definition max_topo :: \"('v::vertex) SecurityInvariant_configured list \\<Rightarrow> 'v graph \\<Rightarrow> bool\" where\n    \"max_topo M G \\<equiv> all_security_requirements_fulfilled M G \\<and> (\n      \\<forall> (v1, v2) \\<in> (nodes G \\<times> nodes G) - (edges G). \\<not> all_security_requirements_fulfilled M (add_edge v1 v2 G))\"\n\n  lemma unique_offending_obtain: \n    assumes m: \"configured_SecurityInvariant m\" and unique: \"c_offending_flows m G = {F}\"\n    obtains P where \"F = {(v1, v2) \\<in> edges G. \\<not> P (v1, v2)}\" and \"c_sinvar m G = (\\<forall>(v1,v2) \\<in> edges G. P (v1, v2))\" and \n                    \"(\\<forall>(v1,v2) \\<in> edges G - F. P (v1, v2))\"\n    proof -\n    assume EX: \"(\\<And>P. F = {(v1, v2). (v1, v2) \\<in> edges G \\<and> \\<not> P (v1, v2)} \\<Longrightarrow> c_sinvar m G = (\\<forall>(v1, v2)\\<in>edges G. P (v1, v2)) \\<Longrightarrow> \\<forall>(v1, v2)\\<in>edges G - F. P (v1, v2) \\<Longrightarrow> thesis)\"\n\n    from unique c_offending_flows_subseteq_edges[OF m] have \"F \\<subseteq> edges G\" by force\n    from this obtain P where \"F = {e \\<in> edges G. \\<not> P e}\" by (metis double_diff set_diff_eq subset_refl)\n    hence 1: \"F = {(v1, v2) \\<in> edges G. \\<not> P (v1, v2)}\" by auto\n\n    from configured_SecurityInvariant.valid_c_offending_flows[OF m] have \"c_offending_flows m G =\n          {F. F \\<subseteq> edges G \\<and> \\<not> c_sinvar m G \\<and> c_sinvar m (delete_edges G F) \\<and> \n              (\\<forall>(e1, e2)\\<in>F. \\<not> c_sinvar m (add_edge e1 e2 (delete_edges G F)))}\" .\n\n    from this unique have \"\\<not> c_sinvar m G\" and 2: \"c_sinvar m (delete_edges G F)\" and \n                          3: \"(\\<forall>(e1, e2)\\<in>F. \\<not> c_sinvar m (add_edge e1 e2 (delete_edges G F)))\" by auto\n\n    from this \\<open>F = {e \\<in> edges G. \\<not> P e}\\<close> have x3: \"\\<forall> e \\<in> edges G - F. P e\" by (metis (lifting) mem_Collect_eq set_diff_eq)\n    hence 4: \"\\<forall>(v1,v2) \\<in> edges G - F. P (v1, v2)\" by blast\n\n    have \"F \\<noteq> {}\" by (metis assms(1) assms(2) configured_SecurityInvariant.empty_offending_contra insertCI)\n    from this \\<open>F = {e \\<in> edges G. \\<not> P e}\\<close> \\<open>\\<not> c_sinvar m G\\<close> have 5: \"c_sinvar m G = (\\<forall>(v1,v2) \\<in> edges G. P (v1, v2))\"\n      apply(simp add: graph_ops)\n      by(blast)\n\n    from EX[of P] unique 1 x3 5 show ?thesis by fast\n  qed\n\n  lemma enf_offending_flows:\n    assumes vm: \"configured_SecurityInvariant m\" and enf: \"\\<forall>G. c_sinvar m G = (\\<forall>e \\<in> edges G. P e)\"\n    shows \"\\<forall>G. c_offending_flows m G = (if c_sinvar m G then {} else {{e \\<in> edges G. \\<not> P e}})\"\n    proof -\n      { fix G\n        from vm configured_SecurityInvariant.valid_c_offending_flows have offending_formaldef:\n          \"c_offending_flows m G =\n            {F. F \\<subseteq> edges G \\<and> \\<not> c_sinvar m G \\<and> c_sinvar m (delete_edges G F) \\<and>\n                (\\<forall>(e1, e2)\\<in>F. \\<not> c_sinvar m (add_edge e1 e2 (delete_edges G F)))}\" by auto\n        have \"c_offending_flows m G = (if c_sinvar m G then {} else {{e \\<in> edges G. \\<not> P e}})\"\n          proof(cases \"c_sinvar m G\")\n          case True thus ?thesis \\<comment> \\<open>@{term \"{}\"}\\<close>\n            by(simp add: offending_formaldef)\n          next\n          case False thus ?thesis by(auto simp add: offending_formaldef graph_ops enf)\n        qed\n      } thus ?thesis by simp\n    qed\n      \n      \nlemma enf_not_fulfilled_if_in_offending:\n  assumes validRs: \"valid_reqs M\"\n    and   wfG:     \"wf_graph G\"\n    and   enf:     \"\\<forall>m \\<in> set M. \\<exists>P. \\<forall>G. c_sinvar m G = (\\<forall>e \\<in> edges G. P e)\"\n    shows \"\\<forall>x \\<in> (\\<Union>m\\<in>set M. \\<Union>(c_offending_flows m (fully_connected G))).\n                \\<not> all_security_requirements_fulfilled M \\<lparr> nodes = V, edges = insert x E\\<rparr>\"\n   unfolding all_security_requirements_fulfilled_def\n   proof(simp, clarify, rename_tac m F a b)\n     let ?G=\"(fully_connected G)\"\n     fix m F v1 v2\n     assume \"m \\<in> set M\" and \"F \\<in> c_offending_flows m ?G\" and \"(v1, v2) \\<in> F\"\n       \n    from validRs have valid_mD:\"\\<And>m. m \\<in> set M \\<Longrightarrow> configured_SecurityInvariant m \" \n      by(simp add: valid_reqs_def)\n    \n     from \\<open>m \\<in> set M\\<close> valid_mD have \"configured_SecurityInvariant m\" by simp\n\n     from enf \\<open>m \\<in> set M\\<close> obtain P where enf_m: \"\\<forall>G. c_sinvar m G = (\\<forall>e\\<in>edges G. P e)\" by blast\n     \n     from \\<open>(v1, v2) \\<in> F\\<close> have \"F \\<noteq> {}\" by auto\n\n     from enf_offending_flows[OF \\<open>configured_SecurityInvariant m\\<close> \\<open>\\<forall>G. c_sinvar m G = (\\<forall>e\\<in>edges G. P e)\\<close>] have\n      offending: \"\\<And>G. c_offending_flows m G = (if c_sinvar m G then {} else {{e \\<in> edges G. \\<not> P e}})\" by simp\n     from \\<open>F \\<in> c_offending_flows m ?G\\<close> \\<open>F \\<noteq> {}\\<close> have \"F = {e \\<in> edges ?G. \\<not> P e}\"\n       by(simp split: if_split_asm add: offending)\n     from this \\<open>(v1, v2) \\<in> F\\<close>  have \"\\<not> P (v1, v2)\" by simp\n\n     from this enf_m have \"\\<not> c_sinvar m \\<lparr>nodes = V, edges = insert (v1, v2) E\\<rparr>\" by(simp)\n     thus \"\\<exists>m\\<in>set M. \\<not> c_sinvar m \\<lparr>nodes = V, edges = insert (v1, v2) E\\<rparr>\" using \\<open>m \\<in> set M\\<close>\n      apply(rule_tac x=\"m\" in bexI)\n       by simp_all\nqed\n        \n\n theorem generate_valid_topology_max_topo: \"\\<lbrakk> valid_reqs M; wf_graph G;\n      \\<forall>m \\<in> set M. \\<exists>P. \\<forall>G. c_sinvar m G = (\\<forall>e \\<in> edges G. P e)\\<rbrakk> \\<Longrightarrow> \n      max_topo M (generate_valid_topology M (fully_connected G))\"\n  proof -\n    let ?G=\"(fully_connected G)\"\n    assume validRs: \"valid_reqs M\"\n    and    wfG:       \"wf_graph G\"\n    and enf: \"\\<forall>m \\<in> set M. \\<exists>P. \\<forall>G. c_sinvar m G = (\\<forall>e \\<in> edges G. P e)\"\n\n    obtain V E where VE_prop: \"\\<lparr> nodes = V, edges = E \\<rparr> = generate_valid_topology M ?G\" by (metis graph.cases)\n    hence VE_prop_asset:\n      \"\\<lparr> nodes = V, edges = E \\<rparr> = \\<lparr> nodes = V, edges = V \\<times> V - (\\<Union>m\\<in>set M. \\<Union>(c_offending_flows m ?G))\\<rparr>\"\n      by(simp add: fully_connected_def generate_valid_topology_as_set delete_edges_simp2)\n\n    from VE_prop_asset have E_prop: \"E =  V \\<times> V - (\\<Union>m\\<in>set M. \\<Union>(c_offending_flows m ?G))\" by fast\n    from VE_prop have V_prop: \"nodes G = V\"\n      by (simp add: fully_connected_def delete_edges_simp2 generate_valid_topology_def_alt)\n    from VE_prop have V_full_prop: \"nodes (generate_valid_topology M ?G) = V\" by (metis graph.select_convs(1))\n    from VE_prop have E_full_prop: \"edges (generate_valid_topology M ?G) = E\" by (metis graph.select_convs(2))\n\n    from VE_prop wf_graph_generate_valid_topology[OF fully_connected_wf[OF wfG]]\n    have wfG_VE: \"wf_graph \\<lparr> nodes = V, edges = E \\<rparr>\" by force\n\n    from generate_valid_topology_sound[OF validRs wfG_VE] fully_connected_wf[OF wfG] have VE_all_valid: \n      \"all_security_requirements_fulfilled M \\<lparr> nodes = V, edges = V \\<times> V - (\\<Union>m\\<in>set M. \\<Union>(c_offending_flows m ?G))\\<rparr>\"\n      by (metis VE_prop VE_prop_asset fully_connected_def generate_valid_topology_sound validRs)\n    hence goal1: \"all_security_requirements_fulfilled M (generate_valid_topology M (fully_connected G))\" by (metis VE_prop VE_prop_asset)\n\n    from validRs have valid_mD:\"\\<And>m. m \\<in> set M \\<Longrightarrow> configured_SecurityInvariant m \" \n      by(simp add: valid_reqs_def)\n\n    from c_offending_flows_subseteq_edges[where G=\"?G\"] validRs have hlp1: \"(\\<Union>m\\<in>set M. \\<Union>(c_offending_flows m ?G)) \\<subseteq> V \\<times> V\"\n      apply(simp add: fully_connected_def V_prop)\n      using valid_reqs_def by blast\n    have \"\\<And>A B. A - (A - B) = B \\<inter> A\" by fast \n    from E_prop hlp1 have \"V \\<times> V - E = (\\<Union>m\\<in>set M. \\<Union>(c_offending_flows m ?G))\" by force\n\n\n    from enf_not_fulfilled_if_in_offending[OF validRs wfG enf]\n    have \"\\<forall>(v1, v2) \\<in> (\\<Union>m\\<in>set M. \\<Union>(c_offending_flows m ?G)).\n       \\<not> all_security_requirements_fulfilled M \\<lparr> nodes = V, edges = E \\<union> {(v1, v2)}\\<rparr>\" by simp\n          \n    from this \\<open>V \\<times> V - E = (\\<Union>m\\<in>set M. \\<Union>(c_offending_flows m ?G))\\<close> have \"\\<forall>(v1, v2) \\<in> V \\<times> V - E.\n         \\<not> all_security_requirements_fulfilled M \\<lparr> nodes = V, edges = E \\<union> {(v1, v2)}\\<rparr>\" by simp\n    hence goal2: \"(\\<forall>(v1, v2)\\<in>nodes (generate_valid_topology M ?G) \\<times> nodes (generate_valid_topology M ?G) -\n                edges (generate_valid_topology M ?G).\n        \\<not> all_security_requirements_fulfilled M (add_edge v1 v2 (generate_valid_topology M ?G)))\"\n    proof(unfold V_full_prop E_full_prop graph_ops)\n      assume a: \"\\<forall>(v1, v2)\\<in>V \\<times> V - E. \\<not> all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = E \\<union> {(v1, v2)}\\<rparr>\"\n      have \"\\<forall>(v1, v2)\\<in>V \\<times> V - E.  V \\<union> {v1, v2} = V\" by blast\n      hence \"\\<forall>(v1, v2)\\<in>V \\<times> V - E. \\<lparr>nodes = V \\<union> {v1, v2}, edges = {(v1, v2)} \\<union> E\\<rparr> = \\<lparr>nodes = V, edges = E \\<union> {(v1, v2)}\\<rparr>\" by blast\n      from this a show \"\\<forall>(v1, v2)\\<in>V \\<times> V - E. \\<not> all_security_requirements_fulfilled M \\<lparr>nodes = V \\<union> {v1, v2}, edges = {(v1, v2)} \\<union> E\\<rparr>\"\n        \\<comment> \\<open>TODO: this should be trivial ...\\<close>\n        apply(simp)\n        apply(rule ballI)\n        apply(erule_tac x=x and A=\"V \\<times> V - E\" in ballE)\n         prefer 2 apply(simp; fail)\n        apply(erule_tac x=x and A=\"V \\<times> V - E\" in ballE)\n         prefer 2 apply(simp; fail)\n        apply(clarify)\n        by presburger\n    qed\n     \n    from goal1 goal2 show ?thesis\n      unfolding max_topo_def by presburger\n  qed\n\n  lemma enf_all_valid_policy_subset_of_max:\n    assumes validRs: \"valid_reqs M\"\n    and     wfG:     \"wf_graph G\"\n    and     enf:     \"\\<forall>m \\<in> set M. \\<exists>P. \\<forall>G. c_sinvar m G = (\\<forall>e \\<in> edges G. P e)\"\n    and     nodesG': \"nodes G = nodes G'\"\n    shows \"\\<lbrakk> wf_graph G';\n        all_security_requirements_fulfilled M G'\\<rbrakk> \\<Longrightarrow> \n        edges G' \\<subseteq> edges (generate_valid_topology M (fully_connected G))\"\n    using nodesG' apply(cases \"generate_valid_topology M (fully_connected G)\", rename_tac V E, simp)\n    apply(cases \"G'\", rename_tac V' E', simp)\n    apply(subgoal_tac \"nodes G = V\")\n     prefer 2\n     apply (metis fully_connected_def generate_valid_topology_nodes graph.select_convs(1))\n    apply(simp)\n  proof(rule ccontr)\n    fix V E V' E'\n    assume a5: \"all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = E'\\<rparr>\" and\n           a6: \"generate_valid_topology M (fully_connected G) = \\<lparr>nodes = V, edges = E\\<rparr>\" and\n           a10: \"wf_graph \\<lparr>nodes = V, edges = E'\\<rparr>\" and\n           contr: \"\\<not> E' \\<subseteq> E\"\n    \n    from wfG a6 have \"wf_graph \\<lparr>nodes = V, edges = E\\<rparr>\"\n      by (metis fully_connected_wf wf_graph_generate_valid_topology)\n    with a10 have EE'subsets: \"fst ` E \\<subseteq> V \\<and> snd ` E \\<subseteq> V \\<and> fst ` E' \\<subseteq> V \\<and> snd ` E' \\<subseteq> V\"\n      by(simp add: wf_graph_def)\n    hence EE'subsets': \"E \\<subseteq> V \\<times> V \\<and> E' \\<subseteq> V \\<times> V\" by auto\n    \n    from generate_valid_topology_max_topo[OF validRs wfG enf]\n      have m1: \"all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = E\\<rparr>\" and\n           m2: \"(\\<forall>x\\<in>V \\<times> V - E. case x of (v1, v2) \\<Rightarrow> \\<not> all_security_requirements_fulfilled M (add_edge v1 v2 \\<lparr>nodes = V, edges = E\\<rparr>))\"\n      by(simp add: max_topo_def a6)+\n        \n    from m2 have m2': \"\\<forall>x\\<in>V \\<times> V - E. \\<not> all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = insert x E\\<rparr>\"\n      apply(simp add: add_edge_def)\n      apply(rule ballI, rename_tac x)\n      apply(erule_tac x=x in ballE, simp_all)\n      apply(case_tac x, simp)\n      by (simp add: insert_absorb)\n    \n     show False\n       proof(cases \"V = {}\")\n         case True\n         with EE'subsets a10 have \"E = {}\" and \"E' = {}\"\n           by(simp add: wf_graph_def)+\n         with True contr show ?thesis by simp\n       next\n         case False\n         with EE'subsets' contr obtain x where x: \"x \\<in> E' \\<and> x \\<notin> E \\<and> x \\<in> V \\<times> V\"\n           by blast\n         from m2' x have \"\\<not> all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = insert x E\\<rparr>\"\n           by (simp)\n         \n         from a6 x have x_offedning: \"x \\<in> (\\<Union>m\\<in>set M. \\<Union>(c_offending_flows m (fully_connected G)))\"\n           apply(simp add: generate_valid_topology_as_set delete_edges_simp2 fully_connected_def)\n           by blast\n  \n         from enf_not_fulfilled_if_in_offending[OF validRs wfG enf] x_offedning have\n           1: \"\\<not> all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = insert x myE\\<rparr>\" for myE by blast\n         \n         from x have insertxE': \"insert x E' = E'\" by blast\n         with a5 have\n           \"all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = insert x E'\\<rparr>\" by simp\n         with insertxE' all_security_requirements_fulfilled_mono[OF validRs _ a10 a5] have \n           2: \"all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = insert x {}\\<rparr>\" by blast\n         from 1 2 show ?thesis by blast\n       qed\n  qed\n    \n\n\n   subsection\\<open>More Lemmata\\<close>\n     lemma (in configured_SecurityInvariant) c_sinvar_valid_imp_no_offending_flows: \n      \"c_sinvar m G \\<Longrightarrow> c_offending_flows m G = {}\"\n        by(simp add: valid_c_offending_flows)\n\n     lemma all_security_requirements_fulfilled_imp_no_offending_flows:\n        \"valid_reqs M \\<Longrightarrow> all_security_requirements_fulfilled M G \\<Longrightarrow> (\\<Union>m\\<in>set M. \\<Union>(c_offending_flows m G)) = {}\"\n        proof(induction M)\n        case Cons thus ?case\n          unfolding all_security_requirements_fulfilled_def\n          apply(simp)\n          by(blast dest: valid_reqs2 valid_reqs1 configured_SecurityInvariant.c_sinvar_valid_imp_no_offending_flows)\n        qed(simp)\n\n    corollary all_security_requirements_fulfilled_imp_get_offending_empty:\n      \"valid_reqs M \\<Longrightarrow> all_security_requirements_fulfilled M G \\<Longrightarrow> get_offending_flows M G = {}\"\n      apply(frule(1) all_security_requirements_fulfilled_imp_no_offending_flows)\n      apply(simp add: get_offending_flows_def)\n      apply(thin_tac \"all_security_requirements_fulfilled M G\")\n      apply(simp add: valid_reqs_def)\n      apply(clarify)\n      using configured_SecurityInvariant.empty_offending_contra by fastforce\n  \n    corollary generate_valid_topology_does_nothing_if_valid:\n      \"\\<lbrakk> valid_reqs M; all_security_requirements_fulfilled M G\\<rbrakk> \\<Longrightarrow> \n          generate_valid_topology M G = G\"\n      by(simp add: generate_valid_topology_as_set graph_ops all_security_requirements_fulfilled_imp_no_offending_flows)\n\n\n    lemma mono_extend_get_offending_flows: \"\\<lbrakk> valid_reqs M;\n         wf_graph \\<lparr>nodes = V, edges = E\\<rparr>;\n         E' \\<subseteq> E;\n         F' \\<in> get_offending_flows M \\<lparr>nodes = V, edges = E'\\<rparr> \\<rbrakk> \\<Longrightarrow>\n       \\<exists>F\\<in>get_offending_flows M \\<lparr>nodes = V, edges = E\\<rparr>. F' \\<subseteq> F\"\n     proof(induction M)\n     case Nil thus ?case by(simp add: get_offending_flows_def)\n     next\n     case (Cons m M)\n      from Cons.prems have \"configured_SecurityInvariant m\"\n                       and \"valid_reqs M\" using valid_reqs2 valid_reqs1 by blast+\n      from Cons.prems(4) have\n        \"F' \\<in> c_offending_flows m \\<lparr>nodes = V, edges = E'\\<rparr> \\<or>\n         (F' \\<in> get_offending_flows M \\<lparr>nodes = V, edges = E'\\<rparr>)\"\n       by(simp add: get_offending_flows_def)\n      from this show ?case\n       proof(elim disjE, goal_cases)\n       case 1\n         with \\<open>configured_SecurityInvariant m\\<close> Cons.prems(2,3,4) obtain F where\n           \"F\\<in>c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>\" and \"F' \\<subseteq> F\"\n           by(blast dest: configured_SecurityInvariant.mono_extend_set_offending_flows)\n         hence \"F\\<in>get_offending_flows (m # M) \\<lparr>nodes = V, edges = E\\<rparr>\"\n           by (simp add: get_offending_flows_def)\n         with \\<open>F' \\<subseteq> F\\<close> show ?case by blast\n       next\n       case 2 with Cons \\<open>valid_reqs M\\<close> show ?case by(simp add: get_offending_flows_def) blast\n       qed\n     qed\n\n     lemma get_offending_flows_subseteq_edges: \"valid_reqs M \\<Longrightarrow> F \\<in> get_offending_flows M \\<lparr>nodes = V, edges = E\\<rparr> \\<Longrightarrow> F \\<subseteq> E\"\n      apply(induction M)\n       apply(simp add: get_offending_flows_def)\n      apply(simp add: get_offending_flows_def)\n      apply(frule valid_reqs2, drule valid_reqs1)\n      apply(simp add: configured_SecurityInvariant.valid_c_offending_flows)\n      by blast\n\n    thm configured_SecurityInvariant.offending_flows_union_mono\n    lemma get_offending_flows_union_mono: \"\\<lbrakk>valid_reqs M; \n      wf_graph \\<lparr>nodes = V, edges = E\\<rparr>; E' \\<subseteq> E \\<rbrakk> \\<Longrightarrow>\n      \\<Union>(get_offending_flows M \\<lparr>nodes = V, edges = E'\\<rparr>) \\<subseteq> \\<Union>(get_offending_flows M \\<lparr>nodes = V, edges = E\\<rparr>)\"\n      apply(induction M)\n       apply(simp add: get_offending_flows_def)\n      apply(frule valid_reqs2, drule valid_reqs1)\n      apply(drule(2) configured_SecurityInvariant.offending_flows_union_mono)\n      apply(simp add: get_offending_flows_def)\n      by auto\n\n    thm configured_SecurityInvariant.Un_set_offending_flows_bound_minus_subseteq'\n    lemma Un_set_offending_flows_bound_minus_subseteq':\"\\<lbrakk>valid_reqs M; \n      wf_graph \\<lparr>nodes = V, edges = E\\<rparr>; E' \\<subseteq> E;\n      \\<Union>(get_offending_flows M \\<lparr>nodes = V, edges = E\\<rparr>) \\<subseteq> X \\<rbrakk> \\<Longrightarrow> \\<Union>(get_offending_flows M \\<lparr>nodes = V, edges = E - E'\\<rparr>) \\<subseteq> X - E'\"\n      proof(induction M)\n      case Nil thus ?case by (simp add: get_offending_flows_def)\n      next\n      case (Cons m M)\n        from Cons.prems(1) valid_reqs2 have \"valid_reqs M\" by force\n        from Cons.prems(1) valid_reqs1 have \"configured_SecurityInvariant m\" by force\n        from Cons.prems(4) have \"\\<Union>(get_offending_flows M \\<lparr>nodes = V, edges = E\\<rparr>) \\<subseteq> X\" by(simp add: get_offending_flows_def)\n        from Cons.IH[OF \\<open>valid_reqs M\\<close> Cons.prems(2) Cons.prems(3) \\<open>\\<Union>(get_offending_flows M \\<lparr>nodes = V, edges = E\\<rparr>) \\<subseteq> X\\<close>] have IH: \"\\<Union>(get_offending_flows M \\<lparr>nodes = V, edges = E - E'\\<rparr>) \\<subseteq> X - E'\" .\n        from Cons.prems(4) have \"\\<Union>(c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>) \\<subseteq> X\" by(simp add: get_offending_flows_def)\n        from configured_SecurityInvariant.Un_set_offending_flows_bound_minus_subseteq'[OF \\<open>configured_SecurityInvariant m\\<close> Cons.prems(2) \\<open>\\<Union>(c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>) \\<subseteq> X\\<close>] have \"\\<Union>(c_offending_flows m \\<lparr>nodes = V, edges = E - E'\\<rparr>) \\<subseteq> X - E'\" .\n        from this IH show ?case by(simp add: get_offending_flows_def)\n      qed\n\n \n\n\n (*ENF has uniquely defined offending flows*)\n lemma ENF_uniquely_defined_offedning: \"valid_reqs M \\<Longrightarrow> wf_graph G \\<Longrightarrow> \n      \\<forall>m \\<in> set M. \\<exists>P. \\<forall>G. c_sinvar m G = (\\<forall>e \\<in> edges G. P e) \\<Longrightarrow> \n      \\<forall>m \\<in> set M. \\<forall>G. \\<not> c_sinvar m G \\<longrightarrow>  (\\<exists>OFF. c_offending_flows m G = {OFF})\"\n apply -\n apply(induction M)\n  apply(simp; fail)\n apply(rename_tac m M)\n apply(frule valid_reqs1)\n apply(drule valid_reqs2)\n apply(simp)\n apply(elim conjE)\n apply(erule_tac x=m in ballE)\n  apply(simp_all; fail)\n apply(erule exE, rename_tac P)\n apply(drule_tac P=P in enf_offending_flows)\n  apply(simp; fail)\n apply(simp; fail)\n done\n\n lemma assumes \"configured_SecurityInvariant m\"\n       and \"\\<forall>G. \\<not> c_sinvar m G \\<longrightarrow> (\\<exists>OFF. c_offending_flows m G = {OFF})\"\n       shows \"\\<exists>OFF_P. \\<forall>G. c_offending_flows m G = (if c_sinvar m G then {} else {OFF_P G})\"\n proof -\n   from assms have \"\\<exists>OFF_P. \n          c_offending_flows m G = (if c_sinvar m G then {} else {OFF_P G})\" for G\n     apply(erule_tac x=G in allE)\n     apply(cases \"c_sinvar m G\")\n      apply(drule configured_SecurityInvariant.c_sinvar_valid_imp_no_offending_flows, simp)\n      apply(simp; fail)\n     apply(simp)\n     by meson\n   with assms show ?thesis by metis\n qed\n (*TODO: generate_valid_topology_max_topo for sinvars with unique offending flows in general*)\n\n\n\n   text\\<open>Hilber's eps operator example\\<close>\n   lemma \"(SOME x. x : {1::nat, 2, 3}) = x \\<Longrightarrow> x = 1 \\<or> x = 2 \\<or> x = 3\"\n     proof -\n      have \"(SOME x. x \\<in> {1::nat, 2, 3}) \\<in> {1::nat, 2, 3}\" unfolding some_in_eq by simp\n      thus \"(SOME x. x : {1::nat, 2, 3}) = x \\<Longrightarrow> x = 1 \\<or> x = 2 \\<or> x = 3\" by fast\n     qed\n\n  (*TODO: remove the offending flows from the graph for each iteration. requires proof arbitrary: G\n          allows to put expensive invariants at back of list and hope that sinvar is true until the are evaluated*)\n  text\\<open>Only removing one offending flow should be enough\\<close>\n  fun generate_valid_topology_SOME :: \"'v SecurityInvariant_configured list \\<Rightarrow> 'v graph \\<Rightarrow> 'v graph\" where\n    \"generate_valid_topology_SOME [] G = G\" |\n    \"generate_valid_topology_SOME (m#Ms) G = (if c_sinvar m G\n      then generate_valid_topology_SOME Ms G\n      else delete_edges (generate_valid_topology_SOME Ms G) (SOME F. F \\<in> c_offending_flows m G)\n      )\"\n\n  lemma generate_valid_topology_SOME_nodes: \"nodes (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>) = V\"\n    proof(induction M)\n    qed(simp_all add: delete_edges_simp2)\n\n  theorem generate_valid_topology_SOME_sound:\n    \"\\<lbrakk> valid_reqs M; wf_graph \\<lparr>nodes = V, edges = E\\<rparr> \\<rbrakk> \\<Longrightarrow> \n    all_security_requirements_fulfilled M (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>)\"\n      proof(induction M)\n        case Nil\n        thus ?case by(simp add: all_security_requirements_fulfilled_def)\n      next\n        case (Cons m M)\n        from valid_reqs1[OF Cons(2)] have validReq: \"configured_SecurityInvariant m\" .\n        \n        from configured_SecurityInvariant.sinvar_valid_remove_SOME_offending_flows[OF validReq] have\n         \"c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> \\<noteq> {} \\<Longrightarrow>\n           c_sinvar m \\<lparr>nodes = V, edges = E - (SOME F. F \\<in> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>)\\<rparr>\" .\n\n        have generate_valid_topology_SOME_edges: \"edges (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>) \\<subseteq> E\"\n          for M::\"'a SecurityInvariant_configured list\" and V E\n          proof(induction M)\n          qed(auto simp add: delete_edges_simp2)\n\n        from configured_SecurityInvariant.mono_sinvar[OF validReq Cons.prems(2),\n              of \"edges (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>)\"]\n            generate_valid_topology_SOME_edges\n          have \"c_sinvar m \\<lparr>nodes = V, edges = E\\<rparr> \\<Longrightarrow>\n            c_sinvar m \\<lparr>nodes = V, edges = edges (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>)\\<rparr>\"\n          by simp\n        moreover from configured_SecurityInvariant.defined_offending'[OF validReq Cons.prems(2)] have not_sinvar_off:\n          \"\\<not> c_sinvar m \\<lparr>nodes = V, edges = E\\<rparr> \\<Longrightarrow> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> \\<noteq> {}\" by blast\n        ultimately have goal_sinvar_m:\n          \"c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> = {} \\<Longrightarrow> \n              c_sinvar m (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>)\"\n           using generate_valid_topology_SOME_nodes \n           by (metis graph.select_convs(1) graph.select_convs(2) graph_eq_intro)\n\n        from valid_reqs2[OF Cons(2)] have \"valid_reqs M\" .\n        from Cons.IH[OF \\<open>valid_reqs M\\<close> Cons(3)] have IH:\n          \"all_security_requirements_fulfilled M (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>)\" .\n\n        have goal_rm_SOME_m: \"c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> \\<noteq> {} \\<Longrightarrow>\n            c_sinvar m (delete_edges (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>)\n                                      (SOME F. F \\<in> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>))\"\n        proof - (*sledgehammered*)\n          assume a1: \"c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> \\<noteq> {}\"\n          have f2: \"(\\<forall>r ra p. \\<not> r \\<subseteq> ra \\<or> (p::'a \\<times> 'a) \\<notin> r \\<or> p \\<in> ra) = (\\<forall>r ra p. \\<not> r \\<subseteq> ra \\<or> (p::'a \\<times> 'a) \\<notin> r \\<or> p \\<in> ra)\"\n            by meson\n          have f3: \"wf_graph \\<lparr>nodes = V, edges = E - (SOME r. r \\<in> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>)\\<rparr>\"\n            by (simp add: Cons.prems(2) wf_graph_remove_edges)\n          have \"edges (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>) - (SOME r. r \\<in> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>) \\<subseteq> E - (SOME r. r \\<in> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>)\"\n            using f2 generate_valid_topology_SOME_edges[of M V E] by blast\n          then have \"c_sinvar m \\<lparr>nodes = V, edges = edges (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>) - (SOME r. r \\<in> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>)\\<rparr>\"\n            using f3 a1 \\<open>c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> \\<noteq> {} \\<Longrightarrow> c_sinvar m \\<lparr>nodes = V, edges = E - (SOME F. F \\<in> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>)\\<rparr>\\<close> configured_SecurityInvariant.negative_mono validReq by blast\n          then show \"c_sinvar m (delete_edges (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>) (SOME r. r \\<in> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>))\"\n            by (simp add: generate_valid_topology_SOME_nodes graph_ops(5))\n        qed\n\n        have wf_graph_generate_valid_topology_SOME: \"wf_graph G \\<Longrightarrow> wf_graph (generate_valid_topology_SOME M G)\"\n          for G (*TODO: tune*)\n          apply(cases G)\n          apply(simp add: wf_graph_def generate_valid_topology_SOME_nodes)\n          using generate_valid_topology_SOME_edges by (meson dual_order.trans image_mono rev_finite_subset) \n\n        { assume notempty: \"c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> \\<noteq> {}\"\n          hence \"\\<exists> hypE. (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>) = \\<lparr>nodes = V, edges = hypE\\<rparr>\"\n            proof(induction M arbitrary: V E)\n            qed(simp_all add: delete_edges_simp2 generate_valid_topology_SOME_nodes)\n          from this obtain E_IH where E_IH_prop:\n            \"(generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>) = \\<lparr>nodes = V, edges = E_IH\\<rparr>\" by blast\n    \n          from wf_graph_generate_valid_topology_SOME[OF Cons(3)] E_IH_prop\n          have valid_G_E_IH: \"wf_graph \\<lparr>nodes = V, edges = E_IH\\<rparr>\" by simp\n    \n          from all_security_requirements_fulfilled_mono[OF \\<open>valid_reqs M\\<close> _ valid_G_E_IH ] IH E_IH_prop\n          have mono_rule: \"E' \\<subseteq> E_IH \\<Longrightarrow> all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = E'\\<rparr>\" for E' by simp\n  \n          have \"all_security_requirements_fulfilled M\n            (delete_edges (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>)\n                          (SOME F. F \\<in> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>))\"\n            unfolding E_IH_prop by(auto simp add: delete_edges_simp2 intro:mono_rule)\n        } note goal_fulfilled_M=this\n\n        have no_offending: \"c_sinvar m \\<lparr>nodes = V, edges = E\\<rparr> \\<Longrightarrow> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> = {}\"\n          by (simp add: configured_SecurityInvariant.c_sinvar_valid_imp_no_offending_flows validReq)\n\n        show \"all_security_requirements_fulfilled (m # M) (generate_valid_topology_SOME (m # M) \\<lparr>nodes = V, edges = E\\<rparr>)\"\n        apply(simp add: all_security_requirements_fulfilled_def)\n        apply(intro conjI impI)\n           subgoal using goal_sinvar_m no_offending by blast\n          subgoal using IH by(simp add: all_security_requirements_fulfilled_def; fail)\n         subgoal using goal_rm_SOME_m not_sinvar_off by blast \n        subgoal using goal_fulfilled_M not_sinvar_off by(simp add: all_security_requirements_fulfilled_def)\n        done\n     qed\n\n    \n   lemma generate_valid_topology_SOME_def_alt:\n      \"generate_valid_topology_SOME M G = delete_edges G (\\<Union>m \\<in> set M. if c_sinvar m G then {} else (SOME F. F \\<in> c_offending_flows m G))\"\n      proof(induction M arbitrary: G)\n        case Nil\n          thus ?case by(simp add: get_offending_flows_def)\n        next\n        case (Cons m M)\n          from Cons[simplified delete_edges_simp2 get_offending_flows_def] \n          have IH :\"edges (generate_valid_topology_SOME M G) =\n                   edges G - (\\<Union>m\\<in>set M. if c_sinvar m G then {} else SOME F. F \\<in> c_offending_flows m G)\"\n            by simp\n          hence \"\\<not> c_sinvar m G \\<Longrightarrow> \n                    edges (generate_valid_topology_SOME (m # M) G) =\n                    (edges G) - (\\<Union>m\\<in>set (m#M). if c_sinvar m G then {} else SOME F. F \\<in> c_offending_flows m G)\"\n            apply(simp add: get_offending_flows_def delete_edges_simp2)\n            by blast\n          with Cons.IH show ?case by(simp add: get_offending_flows_def delete_edges_simp2)\n      qed\n\n    lemma generate_valid_topology_SOME_superset:\n      \"\\<lbrakk> valid_reqs M; wf_graph G \\<rbrakk> \\<Longrightarrow> \n      edges (generate_valid_topology M G) \\<subseteq> edges (generate_valid_topology_SOME M G)\"\n    proof -\n      have isabelle2016_1_helper:\n        \"x \\<in> (\\<Union>m\\<in>set M. if c_sinvar m G then {} else SOME F. F \\<in> c_offending_flows m G) \\<longleftrightarrow>\n          (\\<exists>m\\<in>set M. \\<not> c_sinvar m G \\<and> (c_sinvar m G \\<or> x \\<in> (SOME F. F \\<in> c_offending_flows m G)))\"\n        for x by auto\n      have 1: \"m\\<in>set M \\<Longrightarrow> \\<not> c_sinvar m G \\<and> (c_sinvar m G \\<or> x \\<in> (SOME F. F \\<in> c_offending_flows m G)) \\<Longrightarrow>\n            c_offending_flows m G \\<noteq> {} \\<Longrightarrow>\n            x \\<in> \\<Union>(\\<Union>m\\<in>set M. c_offending_flows m G)\"\n      for x m\n      apply(simp)\n      apply(rule_tac x=m in bexI)\n      apply(simp_all)\n       using some_in_eq by blast\n     \n      show \"valid_reqs M \\<Longrightarrow> wf_graph G \\<Longrightarrow> ?thesis\"\n      unfolding generate_valid_topology_SOME_def_alt generate_valid_topology_def_alt\n      apply (rule delete_edges_edges_mono)\n      apply (auto simp add: delete_edges_simp2 get_offending_flows_def valid_reqs_def)\n      apply (metis (full_types) configured_SecurityInvariant.defined_offending' some_in_eq)\n      done\n    qed\n\n\n\n\n  text\\<open>Notation:\n    @{const generate_valid_topology_SOME}: non-deterministic choice\n    \\<open>generate_valid_topology_some\\<close>: executable which selects always the same\n\\<close>\n  fun generate_valid_topology_some :: \"'v SecurityInvariant_configured list \\<Rightarrow> ('v\\<times>'v) list \\<Rightarrow> 'v graph \\<Rightarrow> 'v graph\" where\n    \"generate_valid_topology_some [] _ G = G\" |\n    \"generate_valid_topology_some (m#Ms) Es G = (if c_sinvar m G\n      then generate_valid_topology_some Ms Es G\n      else delete_edges (generate_valid_topology_some Ms Es G) (set (minimalize_offending_overapprox (c_sinvar m) Es [] G))\n      )\"\n  theorem generate_valid_topology_some_sound:\n    \"\\<lbrakk> valid_reqs M; wf_graph \\<lparr>nodes = V, edges = E\\<rparr>; set Es = E; distinct Es \\<rbrakk> \\<Longrightarrow> \n    all_security_requirements_fulfilled M (generate_valid_topology_some M Es \\<lparr>nodes = V, edges = E\\<rparr>)\"\n      proof(induction M)\n        case Nil\n        thus ?case by(simp add: all_security_requirements_fulfilled_def)\n      next\n        case (Cons m M)\n        from valid_reqs1[OF Cons(2)] have validReq: \"configured_SecurityInvariant m\" .\n         \n        from configured_SecurityInvariant.sinvar_valid_remove_minimalize_offending_overapprox[OF\n          validReq Cons.prems(2) _  Cons.prems(3) Cons.prems(4)] have rm_off_valid:\n         \"\\<not> c_sinvar m \\<lparr>nodes = V, edges = E\\<rparr>\\<Longrightarrow>\n           c_sinvar m \\<lparr>nodes = V, edges = E - (set (minimalize_offending_overapprox (c_sinvar m) Es [] \\<lparr>nodes = V, edges = E\\<rparr>))\\<rparr>\"\n        apply(subst(asm) minimalize_offending_overapprox_boundnP[symmetric]) (*TODO: type for nP unspecified!*)\n        by blast\n\n        have generate_valid_topology_some_nodes: \"nodes (generate_valid_topology_some M Es \\<lparr>nodes = V, edges = E\\<rparr>) = V\"\n          for M::\"'a SecurityInvariant_configured list\" and V E\n          proof(induction M)\n          qed(simp_all add: delete_edges_simp2)\n\n\n        have generate_valid_topology_some_edges: \"edges (generate_valid_topology_some M Es \\<lparr>nodes = V, edges = E\\<rparr>) \\<subseteq> E\"\n          for M::\"'a SecurityInvariant_configured list\" and V E\n          proof(induction M)\n          qed(auto simp add: delete_edges_simp2)\n        \n        from configured_SecurityInvariant.mono_sinvar[OF validReq Cons.prems(2),\n              of \"edges (generate_valid_topology_some M Es \\<lparr>nodes = V, edges = E\\<rparr>)\"]\n            generate_valid_topology_some_edges\n          have \"c_sinvar m \\<lparr>nodes = V, edges = E\\<rparr> \\<Longrightarrow>\n            c_sinvar m \\<lparr>nodes = V, edges = edges (generate_valid_topology_some M Es \\<lparr>nodes = V, edges = E\\<rparr>)\\<rparr>\"\n          by simp\n        moreover from configured_SecurityInvariant.defined_offending'[OF validReq Cons.prems(2)] have not_sinvar_off:\n          \"\\<not> c_sinvar m \\<lparr>nodes = V, edges = E\\<rparr> \\<Longrightarrow> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> \\<noteq> {}\" by blast\n        ultimately have goal_sinvar_m:\n          \"c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> = {} \\<Longrightarrow> \n              c_sinvar m (generate_valid_topology_some M Es \\<lparr>nodes = V, edges = E\\<rparr>)\"\n           using generate_valid_topology_some_nodes \n           by (metis graph.select_convs(1) graph.select_convs(2) graph_eq_intro)\n\n  \n        from valid_reqs2[OF Cons(2)] have \"valid_reqs M\" .\n        from Cons.IH[OF \\<open>valid_reqs M\\<close> Cons(3)] Cons.prems have IH:\n          \"all_security_requirements_fulfilled M (generate_valid_topology_some M Es \\<lparr>nodes = V, edges = E\\<rparr>)\" by simp\n\n \n\n\n        have wf_graph_generate_valid_topology_some: \"wf_graph G \\<Longrightarrow> wf_graph (generate_valid_topology_some M Es G)\"\n          for G (*TODO: tune*)\n          apply(cases G)\n          apply(simp add: wf_graph_def generate_valid_topology_some_nodes)\n          using generate_valid_topology_some_edges by (meson dual_order.trans image_mono rev_finite_subset) \n\n        \n        { assume notempty: \"c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> \\<noteq> {}\"\n          hence \"\\<exists> hypE. (generate_valid_topology_some M Es \\<lparr>nodes = V, edges = E\\<rparr>) = \\<lparr>nodes = V, edges = hypE\\<rparr>\"\n            proof(induction M arbitrary: V E)\n            qed(simp_all add: delete_edges_simp2 generate_valid_topology_some_nodes)\n          from this obtain E_IH where E_IH_prop:\n            \"(generate_valid_topology_some M Es \\<lparr>nodes = V, edges = E\\<rparr>) = \\<lparr>nodes = V, edges = E_IH\\<rparr>\" by blast\n    \n          from wf_graph_generate_valid_topology_some[OF Cons(3)] E_IH_prop\n          have valid_G_E_IH: \"wf_graph \\<lparr>nodes = V, edges = E_IH\\<rparr>\" by simp\n    \n          from all_security_requirements_fulfilled_mono[OF \\<open>valid_reqs M\\<close> _ valid_G_E_IH ] IH E_IH_prop\n          have mono_rule: \"E' \\<subseteq> E_IH \\<Longrightarrow> all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = E'\\<rparr>\" for E' by simp\n  \n          have \"all_security_requirements_fulfilled M\n            (delete_edges (generate_valid_topology_some M Es \\<lparr>nodes = V, edges = E\\<rparr>)\n                          (set (minimalize_offending_overapprox (c_sinvar m) Es [] \\<lparr>nodes = V, edges = E\\<rparr>)))\"\n            unfolding E_IH_prop by(auto simp add: delete_edges_simp2 intro:mono_rule)\n        } note goal_fulfilled_M=this\n\n        have no_offending: \"c_sinvar m \\<lparr>nodes = V, edges = E\\<rparr> \\<Longrightarrow> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> = {}\"\n          by (simp add: configured_SecurityInvariant.c_sinvar_valid_imp_no_offending_flows validReq)\n\n        show \"all_security_requirements_fulfilled (m # M) (generate_valid_topology_some (m # M) Es \\<lparr>nodes = V, edges = E\\<rparr>)\"\n        apply(simp add: all_security_requirements_fulfilled_def)\n        apply(intro conjI impI)\n           subgoal using goal_sinvar_m no_offending by blast\n          subgoal using IH by(simp add: all_security_requirements_fulfilled_def; fail)\n         subgoal using rm_off_valid by (metis (no_types, lifting) Cons.prems(2) Diff_mono \n            configured_SecurityInvariant.mono_sinvar delete_edges_simp2 generate_valid_topology_some_edges\n            generate_valid_topology_some_nodes order_refl validReq wf_graph_remove_edges) (*TODO!*)\n        subgoal using goal_fulfilled_M not_sinvar_off by(simp add: all_security_requirements_fulfilled_def)\n        done\n     qed\n\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Network_Security_Policy_Verification/TopoS_Composition_Theory.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5851011397337391, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.27428992993550894}}
{"text": "(*<*)\ntheory Monitor\n  imports\n    Formula\n    Optimized_Join\n    \"MFOTL_Monitor_Devel.Abstract_Monitor\"\n    \"HOL-Library.While_Combinator\"\n    \"HOL-Library.Mapping\"\n    \"Deriving.Derive\"\n    \"Generic_Join_Devel.Generic_Join_Correctness\"\nbegin\n(*>*)\n\nsection \\<open>Generic monitoring algorithm\\<close>\n\ntext \\<open>The algorithm defined here abstracts over the implementation of the temporal operators.\\<close>\n\nsubsection \\<open>Monitorable formulas\\<close>\n\ndefinition \"mmonitorable \\<phi> \\<longleftrightarrow> safe_formula \\<phi> \\<and> Formula.future_bounded \\<phi>\"\ndefinition \"mmonitorable_regex b g r \\<longleftrightarrow> safe_regex b g r \\<and> Regex.pred_regex Formula.future_bounded r\"\n\ndefinition is_simple_eq :: \"Formula.trm \\<Rightarrow> Formula.trm \\<Rightarrow> bool\" where\n  \"is_simple_eq t1 t2 = (Formula.is_Const t1 \\<and> (Formula.is_Const t2 \\<or> Formula.is_Var t2) \\<or>\n    Formula.is_Var t1 \\<and> Formula.is_Const t2)\"\n\nfun mmonitorable_exec :: \"Formula.formula \\<Rightarrow> bool\" where\n  \"mmonitorable_exec (Formula.Eq t1 t2) = is_simple_eq t1 t2\"\n| \"mmonitorable_exec (Formula.Neg (Formula.Eq (Formula.Var x) (Formula.Var y))) = (x = y)\"\n| \"mmonitorable_exec (Formula.Pred e ts) = list_all (\\<lambda>t. Formula.is_Var t \\<or> Formula.is_Const t) ts\"\n| \"mmonitorable_exec (Formula.Let p \\<phi> \\<psi>) = ({0..<Formula.nfv \\<phi>} \\<subseteq> Formula.fv \\<phi> \\<and> mmonitorable_exec \\<phi> \\<and> mmonitorable_exec \\<psi>)\"\n| \"mmonitorable_exec (Formula.Neg \\<phi>) = (fv \\<phi> = {} \\<and> mmonitorable_exec \\<phi>)\"\n| \"mmonitorable_exec (Formula.Or \\<phi> \\<psi>) = (fv \\<phi> = fv \\<psi> \\<and> mmonitorable_exec \\<phi> \\<and> mmonitorable_exec \\<psi>)\"\n| \"mmonitorable_exec (Formula.And \\<phi> \\<psi>) = (mmonitorable_exec \\<phi> \\<and>\n    (safe_assignment (fv \\<phi>) \\<psi> \\<or> mmonitorable_exec \\<psi> \\<or>\n      fv \\<psi> \\<subseteq> fv \\<phi> \\<and> (is_constraint \\<psi> \\<or> (case \\<psi> of Formula.Neg \\<psi>' \\<Rightarrow> mmonitorable_exec \\<psi>' | _ \\<Rightarrow> False))))\"\n| \"mmonitorable_exec (Formula.Ands l) = (let (pos, neg) = partition mmonitorable_exec l in\n    pos \\<noteq> [] \\<and> list_all mmonitorable_exec (map remove_neg neg) \\<and>\n    \\<Union>(set (map fv neg)) \\<subseteq> \\<Union>(set (map fv pos)))\"\n| \"mmonitorable_exec (Formula.Exists \\<phi>) = (mmonitorable_exec \\<phi>)\"\n| \"mmonitorable_exec (Formula.Agg y \\<omega> b f \\<phi>) = (mmonitorable_exec \\<phi> \\<and>\n    y + b \\<notin> Formula.fv \\<phi> \\<and> {0..<b} \\<subseteq> Formula.fv \\<phi> \\<and> Formula.fv_trm f \\<subseteq> Formula.fv \\<phi>)\"\n| \"mmonitorable_exec (Formula.Prev I \\<phi>) = (mmonitorable_exec \\<phi>)\"\n| \"mmonitorable_exec (Formula.Next I \\<phi>) = (mmonitorable_exec \\<phi>)\"\n| \"mmonitorable_exec (Formula.Since \\<phi> I \\<psi>) = (Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi> \\<and>\n    (mmonitorable_exec \\<phi> \\<or> (case \\<phi> of Formula.Neg \\<phi>' \\<Rightarrow> mmonitorable_exec \\<phi>' | _ \\<Rightarrow> False)) \\<and> mmonitorable_exec \\<psi>)\"\n| \"mmonitorable_exec (Formula.Until \\<phi> I \\<psi>) = (Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi> \\<and> bounded I \\<and>\n    (mmonitorable_exec \\<phi> \\<or> (case \\<phi> of Formula.Neg \\<phi>' \\<Rightarrow> mmonitorable_exec \\<phi>' | _ \\<Rightarrow> False)) \\<and> mmonitorable_exec \\<psi>)\"\n| \"mmonitorable_exec (Formula.MatchP I r) = Regex.safe_regex Formula.fv (\\<lambda>g \\<phi>. mmonitorable_exec \\<phi> \\<or> (g = Lax \\<and> (case \\<phi> of Formula.Neg \\<phi>' \\<Rightarrow> mmonitorable_exec \\<phi>' | _ \\<Rightarrow> False))) Past Strict r\"\n| \"mmonitorable_exec (Formula.MatchF I r) = (Regex.safe_regex Formula.fv (\\<lambda>g \\<phi>. mmonitorable_exec \\<phi> \\<or> (g = Lax \\<and> (case \\<phi> of Formula.Neg \\<phi>' \\<Rightarrow> mmonitorable_exec \\<phi>' | _ \\<Rightarrow> False))) Futu Strict r \\<and> bounded I)\"\n| \"mmonitorable_exec _ = False\"\n\nlemma cases_Neg_iff:\n  \"(case \\<phi> of formula.Neg \\<psi> \\<Rightarrow> P \\<psi> | _ \\<Rightarrow> False) \\<longleftrightarrow> (\\<exists>\\<psi>. \\<phi> = formula.Neg \\<psi> \\<and> P \\<psi>)\"\n  by (cases \\<phi>) auto\n\nlemma safe_formula_mmonitorable_exec: \"safe_formula \\<phi> \\<Longrightarrow> Formula.future_bounded \\<phi> \\<Longrightarrow> mmonitorable_exec \\<phi>\"\nproof (induct \\<phi> rule: safe_formula.induct)\n  case (8 \\<phi> \\<psi>)\n  then show ?case\n    unfolding safe_formula.simps future_bounded.simps mmonitorable_exec.simps\n    by (auto simp: cases_Neg_iff)\nnext\n  case (9 \\<phi> \\<psi>)\n  then show ?case\n    unfolding safe_formula.simps future_bounded.simps mmonitorable_exec.simps\n    by (auto simp: cases_Neg_iff)\nnext\n  case (10 l)\n  from \"10.prems\"(2) have bounded: \"Formula.future_bounded \\<phi>\" if \"\\<phi> \\<in> set l\" for \\<phi>\n    using that by (auto simp: list.pred_set)\n  obtain poss negs where posnegs: \"(poss, negs) = partition safe_formula l\" by simp\n  obtain posm negm where posnegm: \"(posm, negm) = partition mmonitorable_exec l\" by simp\n  have \"set poss \\<subseteq> set posm\"\n  proof (rule subsetI)\n    fix x assume \"x \\<in> set poss\"\n    then have \"x \\<in> set l\" \"safe_formula x\" using posnegs by simp_all\n    then have \"mmonitorable_exec x\" using \"10.hyps\"(1) bounded by blast\n    then show \"x \\<in> set posm\" using \\<open>x \\<in> set poss\\<close> posnegm posnegs by simp\n  qed\n  then have \"set negm \\<subseteq> set negs\" using posnegm posnegs by auto\n  obtain \"poss \\<noteq> []\" \"list_all safe_formula (map remove_neg negs)\"\n    \"(\\<Union>x\\<in>set negs. fv x) \\<subseteq> (\\<Union>x\\<in>set poss. fv x)\"\n    using \"10.prems\"(1) posnegs by simp\n  then have \"posm \\<noteq> []\" using \\<open>set poss \\<subseteq> set posm\\<close> by auto\n  moreover have \"list_all mmonitorable_exec (map remove_neg negm)\"\n  proof -\n    let ?l = \"map remove_neg negm\"\n    have \"\\<And>x. x \\<in> set ?l \\<Longrightarrow> mmonitorable_exec x\"\n    proof -\n      fix x assume \"x \\<in> set ?l\"\n      then obtain y where \"y \\<in> set negm\" \"x = remove_neg y\" by auto\n      then have \"y \\<in> set negs\" using \\<open>set negm \\<subseteq> set negs\\<close> by blast\n      then have \"safe_formula x\"\n        unfolding \\<open>x = remove_neg y\\<close> using \\<open>list_all safe_formula (map remove_neg negs)\\<close>\n        by (simp add: list_all_def)\n      show \"mmonitorable_exec x\"\n      proof (cases \"\\<exists>z. y = Formula.Neg z\")\n        case True\n        then obtain z where \"y = Formula.Neg z\" by blast\n        then show ?thesis\n          using \"10.hyps\"(2)[OF posnegs refl] \\<open>x = remove_neg y\\<close> \\<open>y \\<in> set negs\\<close> posnegs bounded\n            \\<open>safe_formula x\\<close> by fastforce\n      next\n        case False\n        then have \"remove_neg y = y\" by (cases y) simp_all\n        then have \"y = x\" unfolding \\<open>x = remove_neg y\\<close> by simp\n        show ?thesis\n          using \"10.hyps\"(1) \\<open>y \\<in> set negs\\<close> posnegs \\<open>safe_formula x\\<close> unfolding \\<open>y = x\\<close>\n          by auto\n      qed\n    qed\n    then show ?thesis by (simp add: list_all_iff)\n  qed\n  moreover have \"(\\<Union>x\\<in>set negm. fv x) \\<subseteq> (\\<Union>x\\<in>set posm. fv x)\"\n    using \\<open>\\<Union> (fv ` set negs) \\<subseteq> \\<Union> (fv ` set poss)\\<close> \\<open>set poss \\<subseteq> set posm\\<close> \\<open>set negm \\<subseteq> set negs\\<close>\n    by fastforce\n  ultimately show ?case using posnegm by simp\nnext\n  case (15 \\<phi> I \\<psi>)\n  then show ?case\n    unfolding safe_formula.simps future_bounded.simps mmonitorable_exec.simps\n    by (auto simp: cases_Neg_iff)\nnext\n  case (16 \\<phi> I \\<psi>)\n  then show ?case\n    unfolding safe_formula.simps future_bounded.simps mmonitorable_exec.simps\n    by (auto simp: cases_Neg_iff)\nnext\n  case (17 I r)\n  then show ?case\n    by (auto elim!: safe_regex_mono[rotated] simp: cases_Neg_iff regex.pred_set)\nnext\n  case (18 I r)\n  then show ?case\n    by (auto elim!: safe_regex_mono[rotated] simp: cases_Neg_iff regex.pred_set)\nqed (auto simp add: is_simple_eq_def list.pred_set)\n\nlemma safe_assignment_future_bounded: \"safe_assignment X \\<phi> \\<Longrightarrow> Formula.future_bounded \\<phi>\"\n  unfolding safe_assignment_def by (auto split: formula.splits)\n\nlemma is_constraint_future_bounded: \"is_constraint \\<phi> \\<Longrightarrow> Formula.future_bounded \\<phi>\"\n  by (induction rule: is_constraint.induct) simp_all\n\nlemma mmonitorable_exec_mmonitorable: \"mmonitorable_exec \\<phi> \\<Longrightarrow> mmonitorable \\<phi>\"\nproof (induct \\<phi> rule: mmonitorable_exec.induct)\n  case (7 \\<phi> \\<psi>)\n  then show ?case\n    unfolding mmonitorable_def mmonitorable_exec.simps safe_formula.simps\n    by (auto simp: cases_Neg_iff intro: safe_assignment_future_bounded is_constraint_future_bounded)\nnext\n  case (8 l)\n  obtain poss negs where posnegs: \"(poss, negs) = partition safe_formula l\" by simp\n  obtain posm negm where posnegm: \"(posm, negm) = partition mmonitorable_exec l\" by simp\n  have pos_monitorable: \"list_all mmonitorable_exec posm\" using posnegm by (simp add: list_all_iff)\n  have neg_monitorable: \"list_all mmonitorable_exec (map remove_neg negm)\"\n    using \"8.prems\" posnegm by (simp add: list_all_iff)\n  have \"set posm \\<subseteq> set poss\"\n    using \"8.hyps\"(1) posnegs posnegm unfolding mmonitorable_def by auto\n  then have \"set negs \\<subseteq> set negm\"\n    using posnegs posnegm by auto\n\n  have \"poss \\<noteq> []\" using \"8.prems\" posnegm \\<open>set posm \\<subseteq> set poss\\<close> by auto\n  moreover have \"list_all safe_formula (map remove_neg negs)\"\n    using neg_monitorable \"8.hyps\"(2)[OF posnegm refl] \\<open>set negs \\<subseteq> set negm\\<close>\n    unfolding mmonitorable_def by (auto simp: list_all_iff)\n  moreover have \"\\<Union> (fv ` set negm) \\<subseteq> \\<Union> (fv ` set posm)\"\n    using \"8.prems\" posnegm by simp\n  then have \"\\<Union> (fv ` set negs) \\<subseteq> \\<Union> (fv ` set poss)\"\n    using \\<open>set posm \\<subseteq> set poss\\<close> \\<open>set negs \\<subseteq> set negm\\<close> by fastforce\n  ultimately have \"safe_formula (Formula.Ands l)\" using posnegs by simp\n  moreover have \"Formula.future_bounded (Formula.Ands l)\"\n  proof -\n    have \"list_all Formula.future_bounded posm\"\n      using pos_monitorable \"8.hyps\"(1) posnegm unfolding mmonitorable_def\n      by (auto elim!: list.pred_mono_strong)\n    moreover have fnegm: \"list_all Formula.future_bounded (map remove_neg negm)\"\n      using neg_monitorable \"8.hyps\"(2) posnegm unfolding mmonitorable_def\n      by (auto elim!: list.pred_mono_strong)\n    then have \"list_all Formula.future_bounded negm\"\n    proof -\n      have \"\\<And>x. x \\<in> set negm \\<Longrightarrow> Formula.future_bounded x\"\n      proof -\n        fix x assume \"x \\<in> set negm\"\n        have \"Formula.future_bounded (remove_neg x)\" using fnegm \\<open>x \\<in> set negm\\<close> by (simp add: list_all_iff)\n        then show \"Formula.future_bounded x\" by (cases x) auto\n      qed\n      then show ?thesis by (simp add: list_all_iff)\n    qed\n    ultimately have \"list_all Formula.future_bounded l\" using posnegm by (auto simp: list_all_iff)\n    then show ?thesis by (auto simp: list_all_iff)\n  qed\n  ultimately show ?case unfolding mmonitorable_def ..\nnext\n  case (13 \\<phi> I \\<psi>)\n  then show ?case\n    unfolding mmonitorable_def mmonitorable_exec.simps safe_formula.simps\n    by (fastforce simp: cases_Neg_iff)\nnext\n  case (14 \\<phi> I \\<psi>)\n  then show ?case\n    unfolding mmonitorable_def mmonitorable_exec.simps safe_formula.simps\n    by (fastforce simp: one_enat_def cases_Neg_iff)\nnext\n  case (15 I r)\n  then show ?case\n    by (auto elim!: safe_regex_mono[rotated] dest: safe_regex_safe[rotated]\n        simp: mmonitorable_regex_def mmonitorable_def cases_Neg_iff regex.pred_set)\nnext\n  case (16 I r)\n  then show ?case\n    by (auto 0 3 elim!: safe_regex_mono[rotated] dest: safe_regex_safe[rotated]\n        simp: mmonitorable_regex_def mmonitorable_def cases_Neg_iff regex.pred_set)\nqed (auto simp add: mmonitorable_def mmonitorable_regex_def is_simple_eq_def one_enat_def list.pred_set)\n\nlemma monitorable_formula_code[code]: \"mmonitorable \\<phi> = mmonitorable_exec \\<phi>\"\n  using mmonitorable_exec_mmonitorable safe_formula_mmonitorable_exec mmonitorable_def\n  by blast\n\nsubsection \\<open>Handling regular expressions\\<close>\n\ndatatype mregex =\n  MSkip nat\n  | MTestPos nat\n  | MTestNeg nat\n  | MPlus mregex mregex\n  | MTimes mregex mregex\n  | MStar mregex\n\nprimrec ok where\n  \"ok _ (MSkip n) = True\"\n| \"ok m (MTestPos n) = (n < m)\"\n| \"ok m (MTestNeg n) = (n < m)\"\n| \"ok m (MPlus r s) = (ok m r \\<and> ok m s)\"\n| \"ok m (MTimes r s) = (ok m r \\<and> ok m s)\"\n| \"ok m (MStar r) = ok m r\"\n\nprimrec from_mregex where\n  \"from_mregex (MSkip n) _ = Regex.Skip n\"\n| \"from_mregex (MTestPos n) \\<phi>s = Regex.Test (\\<phi>s ! n)\"\n| \"from_mregex (MTestNeg n) \\<phi>s = (if safe_formula (Formula.Neg (\\<phi>s ! n))\n    then Regex.Test (Formula.Neg (Formula.Neg (Formula.Neg (\\<phi>s ! n))))\n    else Regex.Test (Formula.Neg (\\<phi>s ! n)))\"\n| \"from_mregex (MPlus r s) \\<phi>s = Regex.Plus (from_mregex r \\<phi>s) (from_mregex s \\<phi>s)\"\n| \"from_mregex (MTimes r s) \\<phi>s = Regex.Times (from_mregex r \\<phi>s) (from_mregex s \\<phi>s)\"\n| \"from_mregex (MStar r) \\<phi>s = Regex.Star (from_mregex r \\<phi>s)\"\n\nprimrec to_mregex_exec where\n  \"to_mregex_exec (Regex.Skip n) xs = (MSkip n, xs)\"\n| \"to_mregex_exec (Regex.Test \\<phi>) xs = (if safe_formula \\<phi> then (MTestPos (length xs), xs @ [\\<phi>])\n     else case \\<phi> of Formula.Neg \\<phi>' \\<Rightarrow> (MTestNeg (length xs), xs @ [\\<phi>']) | _ \\<Rightarrow> (MSkip 0, xs))\"\n| \"to_mregex_exec (Regex.Plus r s) xs =\n     (let (mr, ys) = to_mregex_exec r xs; (ms, zs) = to_mregex_exec s ys\n     in (MPlus mr ms, zs))\"\n| \"to_mregex_exec (Regex.Times r s) xs =\n     (let (mr, ys) = to_mregex_exec r xs; (ms, zs) = to_mregex_exec s ys\n     in (MTimes mr ms, zs))\"\n| \"to_mregex_exec (Regex.Star r) xs =\n     (let (mr, ys) = to_mregex_exec r xs in (MStar mr, ys))\"\n\nprimrec shift where\n  \"shift (MSkip n) k = MSkip n\"\n| \"shift (MTestPos i) k = MTestPos (i + k)\"\n| \"shift (MTestNeg i) k = MTestNeg (i + k)\"\n| \"shift (MPlus r s) k = MPlus (shift r k) (shift s k)\"\n| \"shift (MTimes r s) k = MTimes (shift r k) (shift s k)\"\n| \"shift (MStar r) k = MStar (shift r k)\"\n\nprimrec to_mregex where\n  \"to_mregex (Regex.Skip n) = (MSkip n, [])\"\n| \"to_mregex (Regex.Test \\<phi>) = (if safe_formula \\<phi> then (MTestPos 0, [\\<phi>])\n     else case \\<phi> of Formula.Neg \\<phi>' \\<Rightarrow> (MTestNeg 0, [\\<phi>']) | _ \\<Rightarrow> (MSkip 0, []))\"\n| \"to_mregex (Regex.Plus r s) =\n     (let (mr, ys) = to_mregex r; (ms, zs) = to_mregex s\n     in (MPlus mr (shift ms (length ys)), ys @ zs))\"\n| \"to_mregex (Regex.Times r s) =\n     (let (mr, ys) = to_mregex r; (ms, zs) = to_mregex s\n     in (MTimes mr (shift ms (length ys)), ys @ zs))\"\n| \"to_mregex (Regex.Star r) =\n     (let (mr, ys) = to_mregex r in (MStar mr, ys))\"\n\nlemma shift_0: \"shift r 0 = r\"\n  by (induct r) auto\n\nlemma shift_shift: \"shift (shift r k) j = shift r (k + j)\"\n  by (induct r) auto\n\nlemma to_mregex_to_mregex_exec:\n  \"case to_mregex r of (mr, \\<phi>s) \\<Rightarrow> to_mregex_exec r xs = (shift mr (length xs), xs @ \\<phi>s)\"\n  by (induct r arbitrary: xs)\n    (auto simp: shift_shift ac_simps split: formula.splits prod.splits)\n\nlemma to_mregex_to_mregex_exec_Nil[code]: \"to_mregex r = to_mregex_exec r []\"\n  using to_mregex_to_mregex_exec[where xs=\"[]\" and r = r] by (auto simp: shift_0)\n\nlemma ok_mono: \"ok m mr \\<Longrightarrow> m \\<le> n \\<Longrightarrow> ok n mr\"\n  by (induct mr) auto\n\nlemma from_mregex_cong: \"ok m mr \\<Longrightarrow> (\\<forall>i < m. xs ! i = ys ! i) \\<Longrightarrow> from_mregex mr xs = from_mregex mr ys\"\n  by (induct mr) auto\n\nlemma not_Neg_cases:\n  \"(\\<forall>\\<psi>. \\<phi> \\<noteq> Formula.Neg \\<psi>) \\<Longrightarrow> (case \\<phi> of formula.Neg \\<psi> \\<Rightarrow> f \\<psi> | _ \\<Rightarrow> x) = x\"\n  by (cases \\<phi>) auto\n\nlemma to_mregex_exec_ok:\n  \"to_mregex_exec r xs = (mr, ys) \\<Longrightarrow> \\<exists>zs. ys = xs @ zs \\<and> set zs = atms r \\<and> ok (length ys) mr\"\nproof (induct r arbitrary: xs mr ys)\n  case (Skip x)\n  then show ?case by (auto split: if_splits prod.splits simp: atms_def elim: ok_mono)\nnext\n  case (Test x)\n  show ?case proof (cases \"\\<exists>x'. x = Formula.Neg x'\")\n    case True\n    with Test show ?thesis by (auto split: if_splits prod.splits simp: atms_def elim: ok_mono)\n  next\n    case False\n    with Test show ?thesis by (auto split: if_splits prod.splits simp: atms_def not_Neg_cases elim: ok_mono)\n  qed\nnext\n  case (Plus r1 r2)\n  then show ?case by (fastforce split: if_splits prod.splits formula.splits simp: atms_def elim: ok_mono)\nnext\n  case (Times r1 r2)\n  then show ?case by (fastforce split: if_splits prod.splits formula.splits simp: atms_def elim: ok_mono)\nnext\n  case (Star r)\n  then show ?case by (auto split: if_splits prod.splits simp: atms_def elim: ok_mono)\nqed\n\nlemma ok_shift: \"ok (i + m) (Monitor.shift r i) \\<longleftrightarrow> ok m r\"\n  by (induct r) auto\n\nlemma to_mregex_ok: \"to_mregex r = (mr, ys) \\<Longrightarrow> set ys = atms r \\<and> ok (length ys) mr\"\nproof (induct r arbitrary: mr ys)\n  case (Skip x)\n  then show ?case by (auto simp: atms_def elim: ok_mono split: if_splits prod.splits)\nnext\n  case (Test x)\n  show ?case proof (cases \"\\<exists>x'. x = Formula.Neg x'\")\n    case True\n    with Test show ?thesis by (auto split: if_splits prod.splits simp: atms_def elim: ok_mono)\n  next\n    case False\n    with Test show ?thesis by (auto split: if_splits prod.splits simp: atms_def not_Neg_cases elim: ok_mono)\n  qed\nnext\n  case (Plus r1 r2)\n  then show ?case by (fastforce simp: ok_shift atms_def elim: ok_mono split: if_splits prod.splits)\nnext\n  case (Times r1 r2)\n  then show ?case by (fastforce simp: ok_shift atms_def elim: ok_mono split: if_splits prod.splits)\nnext\n  case (Star r)\n  then show ?case by (auto simp: atms_def elim: ok_mono split: if_splits prod.splits)\nqed\n\nlemma from_mregex_shift: \"from_mregex (shift r (length xs)) (xs @ ys) = from_mregex r ys\"\n  by (induct r) (auto simp: nth_append)\n\nlemma from_mregex_to_mregex: \"safe_regex m g r \\<Longrightarrow> case_prod from_mregex (to_mregex r) = r\"\n  by (induct r rule: safe_regex.induct)\n    (auto dest: to_mregex_ok intro!: from_mregex_cong simp: nth_append from_mregex_shift cases_Neg_iff\n      split: prod.splits modality.splits)\n\nlemma from_mregex_eq: \"safe_regex m g r \\<Longrightarrow> to_mregex r = (mr, \\<phi>s) \\<Longrightarrow> from_mregex mr \\<phi>s = r\"\n  using from_mregex_to_mregex[of m g r] by auto\n\nlemma from_mregex_to_mregex_exec: \"safe_regex m g r \\<Longrightarrow> case_prod from_mregex (to_mregex_exec r xs) = r\"\nproof (induct r arbitrary: xs rule: safe_regex_induct)\n  case (Plus b g r s)\n  from Plus(3) Plus(1)[of xs] Plus(2)[of \"snd (to_mregex_exec r xs)\"] show ?case\n    by (auto split: prod.splits simp: nth_append dest: to_mregex_exec_ok\n        intro!: from_mregex_cong[where m = \"length (snd (to_mregex_exec r xs))\"])\nnext\n  case (TimesF g r s)\n  from TimesF(3) TimesF(2)[of xs] TimesF(1)[of \"snd (to_mregex_exec r xs)\"] show ?case\n    by (auto split: prod.splits simp: nth_append dest: to_mregex_exec_ok\n        intro!: from_mregex_cong[where m = \"length (snd (to_mregex_exec r xs))\"])\nnext\n  case (TimesP g r s)\n  from TimesP(3) TimesP(1)[of xs] TimesP(2)[of \"snd (to_mregex_exec r xs)\"] show ?case\n    by (auto split: prod.splits simp: nth_append dest: to_mregex_exec_ok\n        intro!: from_mregex_cong[where m = \"length (snd (to_mregex_exec r xs))\"])\nnext\n  case (Star b g r)\n  from Star(2) Star(1)[of xs] show ?case\n    by (auto split: prod.splits)\nqed (auto split: prod.splits simp: cases_Neg_iff)\n\n\nderive linorder mregex\n\nsubsubsection \\<open>LPD\\<close>\n\ndefinition saturate where\n  \"saturate f = while (\\<lambda>S. f S \\<noteq> S) f\"\n\nlemma saturate_code[code]:\n  \"saturate f S = (let S' = f S in if S' = S then S else saturate f S')\"\n  unfolding saturate_def Let_def\n  by (subst while_unfold) auto\n\ndefinition \"MTimesL r S = MTimes r ` S\"\ndefinition \"MTimesR R s = (\\<lambda>r. MTimes r s) ` R\"\n\nprimrec LPD where\n  \"LPD (MSkip n) = (case n of 0 \\<Rightarrow> {} | Suc m \\<Rightarrow> {MSkip m})\"\n| \"LPD (MTestPos \\<phi>) = {}\"\n| \"LPD (MTestNeg \\<phi>) = {}\"\n| \"LPD (MPlus r s) = (LPD r \\<union> LPD s)\"\n| \"LPD (MTimes r s) = MTimesR (LPD r) s \\<union> LPD s\"\n| \"LPD (MStar r) = MTimesR (LPD r) (MStar r)\"\n\nprimrec LPDi where\n  \"LPDi 0 r = {r}\"\n| \"LPDi (Suc i) r = (\\<Union>s \\<in> LPD r. LPDi i s)\"\n\nlemma LPDi_Suc_alt: \"LPDi (Suc i) r = (\\<Union>s \\<in> LPDi i r. LPD s)\"\n  by (induct i arbitrary: r) fastforce+\n\ndefinition \"LPDs r = (\\<Union>i. LPDi i r)\"\n\nlemma LPDs_refl: \"r \\<in> LPDs r\"\n  by (auto simp: LPDs_def intro: exI[of _ 0])\nlemma LPDs_trans: \"r \\<in> LPD s \\<Longrightarrow> s \\<in> LPDs t \\<Longrightarrow> r \\<in> LPDs t\"\n  by (force simp: LPDs_def LPDi_Suc_alt simp del: LPDi.simps intro: exI[of _ \"Suc _\"])\n\nlemma LPDi_Test:\n  \"LPDi i (MSkip 0) \\<subseteq> {MSkip 0}\"\n  \"LPDi i (MTestPos \\<phi>) \\<subseteq> {MTestPos \\<phi>}\"\n  \"LPDi i (MTestNeg \\<phi>) \\<subseteq> {MTestNeg \\<phi>}\"\n  by (induct i) auto\n\nlemma LPDs_Test:\n  \"LPDs (MSkip 0) \\<subseteq> {MSkip 0}\"\n  \"LPDs (MTestPos \\<phi>) \\<subseteq> {MTestPos \\<phi>}\"\n  \"LPDs (MTestNeg \\<phi>) \\<subseteq> {MTestNeg \\<phi>}\"\n  unfolding LPDs_def using LPDi_Test by blast+\n\nlemma LPDi_MSkip: \"LPDi i (MSkip n) \\<subseteq> MSkip ` {i. i \\<le> n}\"\n  by (induct i arbitrary: n) (auto dest: set_mp[OF LPDi_Test(1)] simp: le_Suc_eq split: nat.splits)\n\nlemma LPDs_MSkip: \"LPDs (MSkip n) \\<subseteq> MSkip ` {i. i \\<le> n}\"\n  unfolding LPDs_def using LPDi_MSkip by auto\n\nlemma LPDi_Plus: \"LPDi i (MPlus r s) \\<subseteq> {MPlus r s} \\<union> LPDi i r \\<union> LPDi i s\"\n  by (induct i arbitrary: r s) auto\n\nlemma LPDs_Plus: \"LPDs (MPlus r s) \\<subseteq> {MPlus r s} \\<union> LPDs r \\<union> LPDs s\"\n  unfolding LPDs_def using LPDi_Plus[of _ r s] by auto\n\nlemma LPDi_Times:\n  \"LPDi i (MTimes r s) \\<subseteq> {MTimes r s} \\<union> MTimesR (\\<Union>j \\<le> i. LPDi j r) s \\<union> (\\<Union>j \\<le> i. LPDi j s)\"\nproof (induct i arbitrary: r s)\n  case (Suc i)\n  show ?case\n    by (fastforce simp: MTimesR_def dest: bspec[of _ _ \"Suc _\"] dest!: set_mp[OF Suc])\nqed simp\n\nlemma LPDs_Times: \"LPDs (MTimes r s) \\<subseteq> {MTimes r s} \\<union> MTimesR (LPDs r) s \\<union> LPDs s\"\n  unfolding LPDs_def using LPDi_Times[of _ r s] by (force simp: MTimesR_def)\n\nlemma LPDi_Star: \"j \\<le> i \\<Longrightarrow> LPDi j (MStar r) \\<subseteq> {MStar r} \\<union> MTimesR (\\<Union>j \\<le> i. LPDi j r) (MStar r)\"\nproof (induct i arbitrary: j r)\n  case (Suc i)\n  from Suc(2) show ?case\n    by (auto 0 5 simp: MTimesR_def image_iff le_Suc_eq\n        dest: bspec[of _ _ \"Suc 0\"] bspec[of _ _ \"Suc _\"] set_mp[OF Suc(1)] dest!: set_mp[OF LPDi_Times])\nqed simp\n\nlemma LPDs_Star: \"LPDs (MStar r) \\<subseteq> {MStar r} \\<union> MTimesR (LPDs r) (MStar r)\"\n  unfolding LPDs_def using LPDi_Star[OF order_refl, of _ r] by (force simp: MTimesR_def)\n\nlemma finite_LPDs: \"finite (LPDs r)\"\nproof (induct r)\n  case (MSkip n)\n  then show ?case by (intro finite_subset[OF LPDs_MSkip]) simp\nnext\n  case (MTestPos \\<phi>)\n  then show ?case by (intro finite_subset[OF LPDs_Test(2)]) simp\nnext\n  case (MTestNeg \\<phi>)\n  then show ?case by (intro finite_subset[OF LPDs_Test(3)]) simp\nnext\n  case (MPlus r s)\n  then show ?case by (intro finite_subset[OF LPDs_Plus]) simp\nnext\n  case (MTimes r s)\n  then show ?case by (intro finite_subset[OF LPDs_Times]) (simp add: MTimesR_def)\nnext\n  case (MStar r)\n  then show ?case by (intro finite_subset[OF LPDs_Star]) (simp add: MTimesR_def)\nqed\n\ncontext begin\n\nprivate abbreviation (input) \"addLPD r \\<equiv> \\<lambda>S. insert r S \\<union> Set.bind (insert r S) LPD\"\n\nprivate lemma mono_addLPD: \"mono (addLPD r)\"\n  unfolding mono_def Set.bind_def by auto\n\nprivate lemma LPDs_aux1: \"lfp (addLPD r) \\<subseteq> LPDs r\"\n  by (rule lfp_induct[OF mono_addLPD], auto intro: LPDs_refl LPDs_trans simp: Set.bind_def)\n\nprivate lemma LPDs_aux2: \"LPDi i r \\<subseteq> lfp (addLPD r)\"\nproof (induct i)\n  case 0\n  then show ?case\n    by (subst lfp_unfold[OF mono_addLPD]) auto\nnext\n  case (Suc i)\n  then show ?case\n    by (subst lfp_unfold[OF mono_addLPD]) (auto simp: LPDi_Suc_alt simp del: LPDi.simps)\nqed\n\nlemma LPDs_alt: \"LPDs r = lfp (addLPD r)\"\n  using LPDs_aux1 LPDs_aux2 by (force simp: LPDs_def)\n\nlemma LPDs_code[code]:\n  \"LPDs r = saturate (addLPD r) {}\"\n  unfolding LPDs_alt saturate_def\n  by (rule lfp_while[OF mono_addLPD _ finite_LPDs, of r]) (auto simp: LPDs_refl LPDs_trans Set.bind_def)\n\nend\n\nsubsubsection \\<open>RPD\\<close>\n\nprimrec RPD where\n  \"RPD (MSkip n) = (case n of 0 \\<Rightarrow> {} | Suc m \\<Rightarrow> {MSkip m})\"\n| \"RPD (MTestPos \\<phi>) = {}\"\n| \"RPD (MTestNeg \\<phi>) = {}\"\n| \"RPD (MPlus r s) = (RPD r \\<union> RPD s)\"\n| \"RPD (MTimes r s) = MTimesL r (RPD s) \\<union> RPD r\"\n| \"RPD (MStar r) = MTimesL (MStar r) (RPD r)\"\n\nprimrec RPDi where\n  \"RPDi 0 r = {r}\"\n| \"RPDi (Suc i) r = (\\<Union>s \\<in> RPD r. RPDi i s)\"\n\nlemma RPDi_Suc_alt: \"RPDi (Suc i) r = (\\<Union>s \\<in> RPDi i r. RPD s)\"\n  by (induct i arbitrary: r) fastforce+\n\ndefinition \"RPDs r = (\\<Union>i. RPDi i r)\"\n\nlemma RPDs_refl: \"r \\<in> RPDs r\"\n  by (auto simp: RPDs_def intro: exI[of _ 0])\nlemma RPDs_trans: \"r \\<in> RPD s \\<Longrightarrow> s \\<in> RPDs t \\<Longrightarrow> r \\<in> RPDs t\"\n  by (force simp: RPDs_def RPDi_Suc_alt simp del: RPDi.simps intro: exI[of _ \"Suc _\"])\n\nlemma RPDi_Test:\n  \"RPDi i (MSkip 0) \\<subseteq> {MSkip 0}\"\n  \"RPDi i (MTestPos \\<phi>) \\<subseteq> {MTestPos \\<phi>}\"\n  \"RPDi i (MTestNeg \\<phi>) \\<subseteq> {MTestNeg \\<phi>}\"\n  by (induct i) auto\n\nlemma RPDs_Test:\n  \"RPDs (MSkip 0) \\<subseteq> {MSkip 0}\"\n  \"RPDs (MTestPos \\<phi>) \\<subseteq> {MTestPos \\<phi>}\"\n  \"RPDs (MTestNeg \\<phi>) \\<subseteq> {MTestNeg \\<phi>}\"\n  unfolding RPDs_def using RPDi_Test by blast+\n\nlemma RPDi_MSkip: \"RPDi i (MSkip n) \\<subseteq> MSkip ` {i. i \\<le> n}\"\n  by (induct i arbitrary: n) (auto dest: set_mp[OF RPDi_Test(1)] simp: le_Suc_eq split: nat.splits)\n\nlemma RPDs_MSkip: \"RPDs (MSkip n) \\<subseteq> MSkip ` {i. i \\<le> n}\"\n  unfolding RPDs_def using RPDi_MSkip by auto\n\nlemma RPDi_Plus: \"RPDi i (MPlus r s) \\<subseteq> {MPlus r s} \\<union> RPDi i r \\<union> RPDi i s\"\n  by (induct i arbitrary: r s) auto\n\nlemma RPDi_Suc_RPD_Plus:\n  \"RPDi (Suc i) r \\<subseteq> RPDs (MPlus r s)\"\n  \"RPDi (Suc i) s \\<subseteq> RPDs (MPlus r s)\"\n  unfolding RPDs_def by (force intro!: exI[of _ \"Suc i\"])+\n\nlemma RPDs_Plus: \"RPDs (MPlus r s) \\<subseteq> {MPlus r s} \\<union> RPDs r \\<union> RPDs s\"\n  unfolding RPDs_def using RPDi_Plus[of _ r s] by auto\n\nlemma RPDi_Times:\n  \"RPDi i (MTimes r s) \\<subseteq> {MTimes r s} \\<union> MTimesL r (\\<Union>j \\<le> i. RPDi j s) \\<union> (\\<Union>j \\<le> i. RPDi j r)\"\nproof (induct i arbitrary: r s)\n  case (Suc i)\n  show ?case\n    by (fastforce simp: MTimesL_def dest: bspec[of _ _ \"Suc _\"] dest!: set_mp[OF Suc])\nqed simp\n\nlemma RPDs_Times: \"RPDs (MTimes r s) \\<subseteq> {MTimes r s} \\<union> MTimesL r (RPDs s) \\<union> RPDs r\"\n  unfolding RPDs_def using RPDi_Times[of _ r s] by (force simp: MTimesL_def)\n\nlemma RPDi_Star: \"j \\<le> i \\<Longrightarrow> RPDi j (MStar r) \\<subseteq> {MStar r} \\<union> MTimesL (MStar r) (\\<Union>j \\<le> i. RPDi j r)\"\nproof (induct i arbitrary: j r)\n  case (Suc i)\n  from Suc(2) show ?case\n    by (auto 0 5 simp: MTimesL_def image_iff le_Suc_eq\n        dest: bspec[of _ _ \"Suc 0\"] bspec[of _ _ \"Suc _\"] set_mp[OF Suc(1)] dest!: set_mp[OF RPDi_Times])\nqed simp\n\nlemma RPDs_Star: \"RPDs (MStar r) \\<subseteq> {MStar r} \\<union> MTimesL (MStar r) (RPDs r)\"\n  unfolding RPDs_def using RPDi_Star[OF order_refl, of _ r] by (force simp: MTimesL_def)\n\nlemma finite_RPDs: \"finite (RPDs r)\"\nproof (induct r)\n  case MSkip\n  then show ?case by (intro finite_subset[OF RPDs_MSkip]) simp\nnext\n  case (MTestPos \\<phi>)\n  then show ?case by (intro finite_subset[OF RPDs_Test(2)]) simp\nnext\n  case (MTestNeg \\<phi>)\n  then show ?case by (intro finite_subset[OF RPDs_Test(3)]) simp\nnext\n  case (MPlus r s)\n  then show ?case by (intro finite_subset[OF RPDs_Plus]) simp\nnext\n  case (MTimes r s)\n  then show ?case by (intro finite_subset[OF RPDs_Times]) (simp add: MTimesL_def)\nnext\n  case (MStar r)\n  then show ?case by (intro finite_subset[OF RPDs_Star]) (simp add: MTimesL_def)\nqed\n\ncontext begin\n\nprivate abbreviation (input) \"addRPD r \\<equiv> \\<lambda>S. insert r S \\<union> Set.bind (insert r S) RPD\"\n\nprivate lemma mono_addRPD: \"mono (addRPD r)\"\n  unfolding mono_def Set.bind_def by auto\n\nprivate lemma RPDs_aux1: \"lfp (addRPD r) \\<subseteq> RPDs r\"\n  by (rule lfp_induct[OF mono_addRPD], auto intro: RPDs_refl RPDs_trans simp: Set.bind_def)\n\nprivate lemma RPDs_aux2: \"RPDi i r \\<subseteq> lfp (addRPD r)\"\nproof (induct i)\n  case 0\n  then show ?case\n    by (subst lfp_unfold[OF mono_addRPD]) auto\nnext\n  case (Suc i)\n  then show ?case\n    by (subst lfp_unfold[OF mono_addRPD]) (auto simp: RPDi_Suc_alt simp del: RPDi.simps)\nqed\n\nlemma RPDs_alt: \"RPDs r = lfp (addRPD r)\"\n  using RPDs_aux1 RPDs_aux2 by (force simp: RPDs_def)\n\nlemma RPDs_code[code]:\n  \"RPDs r = saturate (addRPD r) {}\"\n  unfolding RPDs_alt saturate_def\n  by (rule lfp_while[OF mono_addRPD _ finite_RPDs, of r]) (auto simp: RPDs_refl RPDs_trans Set.bind_def)\n\nend\n\nsubsection \\<open>The executable monitor\\<close>\n\ntype_synonym ts = nat\n\ntype_synonym 'a mbuf2 = \"'a table list \\<times> 'a table list\"\ntype_synonym 'a mbufn = \"'a table list list\"\ntype_synonym 'a msaux = \"(ts \\<times> 'a table) list\"\ntype_synonym 'a muaux = \"(ts \\<times> 'a table \\<times> 'a table) list\"\ntype_synonym 'a mr\\<delta>aux = \"(ts \\<times> (mregex, 'a table) mapping) list\"\ntype_synonym 'a ml\\<delta>aux = \"(ts \\<times> 'a table list \\<times> 'a table) list\"\n\ndatatype mconstraint = MEq | MLess | MLessEq\n\nrecord aggargs =\n  aggargs_cols :: \"nat set\"\n  aggargs_n :: nat\n  aggargs_g0 :: bool\n  aggargs_y :: nat\n  aggargs_\\<omega> :: \"Formula.agg_op\"\n  aggargs_b :: nat\n  aggargs_f :: \"Formula.trm\"\n\nrecord args =\n  args_ivl :: \\<I>\n  args_n :: nat\n  args_L :: \"nat set\"\n  args_R :: \"nat set\"\n  args_pos :: bool\n  args_agg :: \"aggargs option\"\n\ndefinition init_args :: \"\\<I> \\<Rightarrow> nat \\<Rightarrow> nat set \\<Rightarrow> nat set \\<Rightarrow> bool \\<Rightarrow> aggargs option \\<Rightarrow> args\" where\n  \"init_args I n L R pos agg = \\<lparr>args_ivl = I, args_n = n, args_L = L, args_R = R,\n    args_pos = pos, args_agg = agg\\<rparr>\"\n\ndefinition init_aggargs :: \"nat set \\<Rightarrow> nat \\<Rightarrow> bool \\<Rightarrow> nat \\<Rightarrow> Formula.agg_op \\<Rightarrow> nat \\<Rightarrow>\n  Formula.trm \\<Rightarrow> aggargs\" where\n  \"init_aggargs cols n g0 y \\<omega> b f = \\<lparr>aggargs_cols = cols, aggargs_n = n, aggargs_g0 = g0,\n    aggargs_y = y, aggargs_\\<omega> = \\<omega>, aggargs_b = b, aggargs_f = f\\<rparr>\"\n\nfun meval_trm :: \"Formula.trm \\<Rightarrow> event_data tuple \\<Rightarrow> event_data\" where\n  \"meval_trm (Formula.Var x) v = the (v ! x)\"\n| \"meval_trm (Formula.Const x) v = x\"\n| \"meval_trm (Formula.Plus x y) v = meval_trm x v + meval_trm y v\"\n| \"meval_trm (Formula.Minus x y) v = meval_trm x v - meval_trm y v\"\n| \"meval_trm (Formula.UMinus x) v = - meval_trm x v\"\n| \"meval_trm (Formula.Mult x y) v = meval_trm x v * meval_trm y v\"\n| \"meval_trm (Formula.Div x y) v = meval_trm x v div meval_trm y v\"\n| \"meval_trm (Formula.Mod x y) v = meval_trm x v mod meval_trm y v\"\n| \"meval_trm (Formula.F2i x) v = EInt (integer_of_event_data (meval_trm x v))\"\n| \"meval_trm (Formula.I2f x) v = EFloat (double_of_event_data (meval_trm x v))\"\n\ndefinition packagg :: \"args \\<Rightarrow> Formula.formula \\<Rightarrow> Formula.formula\" where\n  \"packagg args f = (case args_agg args of None \\<Rightarrow> f\n    | Some aggargs \\<Rightarrow> Formula.Agg (aggargs_y aggargs)\n      (aggargs_\\<omega> aggargs) (aggargs_b aggargs) (aggargs_f aggargs) f)\"\n\ndefinition eval_agg :: \"nat \\<Rightarrow> bool \\<Rightarrow> nat \\<Rightarrow> Formula.agg_op \\<Rightarrow> nat \\<Rightarrow> Formula.trm \\<Rightarrow>\n  event_data table \\<Rightarrow> event_data table\" where\n  \"eval_agg n g0 y \\<omega> b f rel = (if g0 \\<and> rel = empty_table\n    then singleton_table n y (eval_agg_op \\<omega> {})\n    else (\\<lambda>k.\n      let group = Set.filter (\\<lambda>x. drop b x = k) rel;\n        M = (\\<lambda>y. (y, ecard (Set.filter (\\<lambda>x. meval_trm f x = y) group))) ` meval_trm f ` group\n      in k[y:=Some (eval_agg_op \\<omega> M)]) ` (drop b) ` rel)\"\n\ndefinition eval_aggargs :: \"aggargs \\<Rightarrow> event_data table \\<Rightarrow> event_data table\" where\n  \"eval_aggargs args = eval_agg (aggargs_n args) (aggargs_g0 args)\n    (aggargs_y args) (aggargs_\\<omega> args) (aggargs_b args) (aggargs_f args)\"\n\ndefinition eval_args_agg :: \"args \\<Rightarrow> event_data table \\<Rightarrow> event_data table\" where\n  \"eval_args_agg args X = (case args_agg args of None \\<Rightarrow> X | Some aggargs \\<Rightarrow> eval_aggargs aggargs X)\"\n\ndefinition type_restr :: \"aggargs \\<Rightarrow> event_data table \\<Rightarrow> bool\" where\n  \"type_restr args X = (let Z = meval_trm (aggargs_f args) ` X;\n    all_int = Z \\<subseteq> range EInt;\n    all_float = Z \\<subseteq> range EFloat;\n    all_string = Z \\<subseteq> range EString in\n    case aggargs_\\<omega> args of (Formula.Agg_Cnt, _) \\<Rightarrow> True\n    | (Formula.Agg_Min, _) \\<Rightarrow> all_int \\<or> all_string\n    | (Formula.Agg_Max, _) \\<Rightarrow> all_int \\<or> all_string\n    | (Formula.Agg_Sum, _) \\<Rightarrow> all_int\n    | (Formula.Agg_Avg, _) \\<Rightarrow> all_int\n    | (Formula.Agg_Med, _) \\<Rightarrow> all_int)\"\n\nlemma meval_trm_cong: \"(\\<And>i. i \\<in> Formula.fv_trm f \\<Longrightarrow> ts ! i = ts' ! i) \\<Longrightarrow>\n  meval_trm f ts = meval_trm f ts'\"\n  by (induction f ts rule: meval_trm.induct) auto\n\ndefinition safe_aggargs :: \"aggargs \\<Rightarrow> bool\" where\n  \"safe_aggargs args = (aggargs_y args < aggargs_n args \\<and>\n    (\\<forall>i \\<in> aggargs_cols args. i < aggargs_b args + aggargs_n args) \\<and>\n    aggargs_y args + aggargs_b args \\<notin> aggargs_cols args \\<and>\n    {0..<aggargs_b args} \\<subseteq> aggargs_cols args \\<and>\n    Formula.fv_trm (aggargs_f args) \\<subseteq> aggargs_cols args \\<and>\n    aggargs_g0 args = (aggargs_cols args \\<subseteq> {0..<aggargs_b args}))\"\n\ndefinition \"valid_aggargs n R args = (case args of None \\<Rightarrow> True | Some aggargs \\<Rightarrow>\n  n = aggargs_b aggargs + aggargs_n aggargs \\<and> R = aggargs_cols aggargs \\<and> safe_aggargs aggargs)\"\n\nlocale msaux =\n  fixes valid_msaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'msaux \\<Rightarrow> event_data msaux \\<Rightarrow> bool\"\n    and init_msaux :: \"args \\<Rightarrow> 'msaux\"\n    and add_new_ts_msaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'msaux \\<Rightarrow> 'msaux\"\n    and join_msaux :: \"args \\<Rightarrow> event_data table \\<Rightarrow> 'msaux \\<Rightarrow> 'msaux\"\n    and add_new_table_msaux :: \"args \\<Rightarrow> event_data table \\<Rightarrow> 'msaux \\<Rightarrow> 'msaux\"\n    and result_msaux :: \"args \\<Rightarrow> 'msaux \\<Rightarrow> event_data table\"\n  assumes valid_init_msaux: \"L \\<subseteq> R \\<Longrightarrow> valid_aggargs n R agg \\<Longrightarrow>\n    valid_msaux (init_args I n L R pos agg) 0 (init_msaux (init_args I n L R pos agg)) []\"\n  assumes valid_add_new_ts_msaux: \"valid_msaux args cur aux auxlist \\<Longrightarrow> nt \\<ge> cur \\<Longrightarrow>\n    valid_msaux args nt (add_new_ts_msaux args nt aux)\n    (filter (\\<lambda>(t, rel). memR (args_ivl args) (nt - t)) auxlist)\"\n  assumes valid_join_msaux: \"valid_msaux args cur aux auxlist \\<Longrightarrow>\n    table (args_n args) (args_L args) rel1 \\<Longrightarrow>\n    valid_msaux args cur (join_msaux args rel1 aux)\n    (map (\\<lambda>(t, rel). (t, join rel (args_pos args) rel1)) auxlist)\"\n  assumes valid_add_new_table_msaux: \"valid_msaux args cur aux auxlist \\<Longrightarrow>\n    table (args_n args) (args_R args) rel2 \\<Longrightarrow>\n    valid_msaux args cur (add_new_table_msaux args rel2 aux)\n    (case auxlist of\n      [] => [(cur, rel2)]\n    | ((t, y) # ts) \\<Rightarrow> if t = cur then (t, y \\<union> rel2) # ts else (cur, rel2) # auxlist)\"\n  assumes valid_result_msaux: \"valid_msaux args cur aux auxlist \\<Longrightarrow> result_msaux args aux =\n    eval_args_agg args (foldr (\\<union>) [rel. (t, rel) \\<leftarrow> auxlist, memL (args_ivl args) (cur - t)] {})\"\n\nfun check_before :: \"\\<I> \\<Rightarrow> ts \\<Rightarrow> (ts \\<times> 'a \\<times> 'b) \\<Rightarrow> bool\" where\n  \"check_before I dt (t, a, b) \\<longleftrightarrow> \\<not> memR I (dt - t)\"\n\nfun proj_thd :: \"('a \\<times> 'b \\<times> 'c) \\<Rightarrow> 'c\" where\n  \"proj_thd (t, a1, a2) = a2\"\n\ndefinition update_until :: \"args \\<Rightarrow> event_data table \\<Rightarrow> event_data table \\<Rightarrow> ts \\<Rightarrow> event_data muaux \\<Rightarrow> event_data muaux\" where\n  \"update_until args rel1 rel2 nt aux =\n    (map (\\<lambda>x. case x of (t, a1, a2) \\<Rightarrow> (t, if (args_pos args) then join a1 True rel1 else a1 \\<union> rel1,\n      if mem  (args_ivl args) (nt - t) then a2 \\<union> join rel2 (args_pos args) a1 else a2)) aux) @\n    [(nt, rel1, if memL (args_ivl args) 0 then rel2 else empty_table)]\"\n\nlemma map_proj_thd_update_until: \"map proj_thd (takeWhile (check_before (args_ivl args) nt) auxlist) =\n  map proj_thd (takeWhile (check_before (args_ivl args) nt) (update_until args rel1 rel2 nt auxlist))\"\nproof (induction auxlist)\n  case Nil\n  then show ?case by (simp add: update_until_def)\nnext\n  case (Cons a auxlist)\n  then show ?case\n    by (auto simp add: update_until_def split: if_splits prod.splits)\nqed\n\nfun eval_until :: \"\\<I> \\<Rightarrow> ts \\<Rightarrow> event_data muaux \\<Rightarrow> event_data table list \\<times> event_data muaux\" where\n  \"eval_until I nt [] = ([], [])\"\n| \"eval_until I nt ((t, a1, a2) # aux) = (if \\<not> memR I (nt - t) then\n    (let (xs, aux) = eval_until I nt aux in (a2 # xs, aux)) else ([], (t, a1, a2) # aux))\"\n\nlemma eval_until_length:\n  \"eval_until I nt auxlist = (res, auxlist') \\<Longrightarrow> length auxlist = length res + length auxlist'\"\n  by (induction I nt auxlist arbitrary: res auxlist' rule: eval_until.induct)\n    (auto split: if_splits prod.splits)\n\nlemma eval_until_res: \"eval_until I nt auxlist = (res, auxlist') \\<Longrightarrow>\n  res = map proj_thd (takeWhile (check_before I nt) auxlist)\"\n  by (induction I nt auxlist arbitrary: res auxlist' rule: eval_until.induct)\n    (auto split: prod.splits)\n\nlemma eval_until_auxlist': \"eval_until I nt auxlist = (res, auxlist') \\<Longrightarrow>\n  auxlist' = drop (length res) auxlist\"\n  by (induction I nt auxlist arbitrary: res auxlist' rule: eval_until.induct)\n    (auto split: if_splits prod.splits)\n\nlocale muaux =\n  fixes valid_muaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'muaux \\<Rightarrow> event_data muaux \\<Rightarrow> bool\"\n    and init_muaux :: \"args \\<Rightarrow> 'muaux\"\n    and add_new_muaux :: \"args \\<Rightarrow> event_data table \\<Rightarrow> event_data table \\<Rightarrow> ts \\<Rightarrow> 'muaux \\<Rightarrow> 'muaux\"\n    and length_muaux :: \"args \\<Rightarrow> 'muaux \\<Rightarrow> nat\"\n    and eval_muaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'muaux \\<Rightarrow> event_data table list \\<times> 'muaux\"\n  assumes valid_init_muaux: \"L \\<subseteq> R \\<Longrightarrow> valid_aggargs n R aggargs \\<Longrightarrow>\n    valid_muaux (init_args I n L R pos aggargs) 0 (init_muaux (init_args I n L R pos aggargs)) []\"\n  assumes valid_add_new_muaux: \"valid_muaux args cur aux auxlist \\<Longrightarrow>\n    table (args_n args) (args_L args) rel1 \\<Longrightarrow>\n    table (args_n args) (args_R args) rel2 \\<Longrightarrow>\n    nt \\<ge> cur \\<Longrightarrow>\n    valid_muaux args nt (add_new_muaux args rel1 rel2 nt aux)\n    (update_until args rel1 rel2 nt auxlist)\"\n  assumes valid_length_muaux: \"valid_muaux args cur aux auxlist \\<Longrightarrow> length_muaux args aux = length auxlist\"\n  assumes valid_eval_muaux: \"valid_muaux args cur aux auxlist \\<Longrightarrow> nt \\<ge> cur \\<Longrightarrow>\n    eval_muaux args nt aux = (res, aux') \\<Longrightarrow> eval_until (args_ivl args) nt auxlist = (res', auxlist') \\<Longrightarrow>\n    valid_muaux args cur aux' auxlist' \\<and> res = map (eval_args_agg args) res'\"\n\nlocale maux = msaux valid_msaux init_msaux add_new_ts_msaux join_msaux add_new_table_msaux result_msaux +\n  muaux valid_muaux init_muaux add_new_muaux length_muaux eval_muaux\n  for valid_msaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'msaux \\<Rightarrow> event_data msaux \\<Rightarrow> bool\"\n    and init_msaux :: \"args \\<Rightarrow> 'msaux\"\n    and add_new_ts_msaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'msaux \\<Rightarrow> 'msaux\"\n    and join_msaux :: \"args \\<Rightarrow> event_data table \\<Rightarrow> 'msaux \\<Rightarrow> 'msaux\"\n    and add_new_table_msaux :: \"args \\<Rightarrow> event_data table \\<Rightarrow> 'msaux \\<Rightarrow> 'msaux\"\n    and result_msaux :: \"args \\<Rightarrow> 'msaux \\<Rightarrow> event_data table\"\n    and valid_muaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'muaux \\<Rightarrow> event_data muaux \\<Rightarrow> bool\"\n    and init_muaux :: \"args \\<Rightarrow> 'muaux\"\n    and add_new_muaux :: \"args \\<Rightarrow> event_data table \\<Rightarrow> event_data table \\<Rightarrow> ts \\<Rightarrow> 'muaux \\<Rightarrow> 'muaux\"\n    and length_muaux :: \"args \\<Rightarrow> 'muaux \\<Rightarrow> nat\"\n    and eval_muaux :: \"args \\<Rightarrow> nat \\<Rightarrow> 'muaux \\<Rightarrow> event_data table list \\<times> 'muaux\"\n\ndatatype (dead 'msaux, dead 'muaux) mformula =\n  MRel \"event_data table\"\n  | MPred Formula.name \"Formula.trm list\"\n  | MLet Formula.name nat \"('msaux, 'muaux) mformula\" \"('msaux, 'muaux) mformula\"\n  | MAnd \"nat set\" \"('msaux, 'muaux) mformula\" bool \"nat set\" \"('msaux, 'muaux) mformula\" \"event_data mbuf2\"\n  | MAndAssign \"('msaux, 'muaux) mformula\" \"nat \\<times> Formula.trm\"\n  | MAndRel \"('msaux, 'muaux) mformula\" \"Formula.trm \\<times> bool \\<times> mconstraint \\<times> Formula.trm\"\n  | MAnds \"nat set list\" \"nat set list\" \"('msaux, 'muaux) mformula list\" \"event_data mbufn\"\n  | MOr \"('msaux, 'muaux) mformula\" \"('msaux, 'muaux) mformula\" \"event_data mbuf2\"\n  | MNeg \"('msaux, 'muaux) mformula\"\n  | MExists \"('msaux, 'muaux) mformula\"\n  | MAgg bool nat Formula.agg_op nat \"Formula.trm\" \"('msaux, 'muaux) mformula\"\n  | MPrev \\<I> \"('msaux, 'muaux) mformula\" bool \"event_data table list\" \"ts list\"\n  | MNext \\<I> \"('msaux, 'muaux) mformula\" bool \"ts list\"\n  | MSince args \"('msaux, 'muaux) mformula\" \"('msaux, 'muaux) mformula\" \"event_data mbuf2\" \"ts list\" \"'msaux\"\n  | MUntil args \"('msaux, 'muaux) mformula\" \"('msaux, 'muaux) mformula\" \"event_data mbuf2\" \"ts list\" ts \"'muaux\"\n  | MMatchP \\<I> \"mregex\" \"mregex list\" \"('msaux, 'muaux) mformula list\" \"event_data mbufn\" \"ts list\" \"event_data mr\\<delta>aux\"\n  | MMatchF \\<I> \"mregex\" \"mregex list\" \"('msaux, 'muaux) mformula list\" \"event_data mbufn\" \"ts list\" ts \"event_data ml\\<delta>aux\"\n\nrecord ('msaux, 'muaux) mstate =\n  mstate_i :: nat\n  mstate_m :: \"('msaux, 'muaux) mformula\"\n  mstate_n :: nat\n\nfun eq_rel :: \"nat \\<Rightarrow> Formula.trm \\<Rightarrow> Formula.trm \\<Rightarrow> event_data table\" where\n  \"eq_rel n (Formula.Const x) (Formula.Const y) = (if x = y then unit_table n else empty_table)\"\n| \"eq_rel n (Formula.Var x) (Formula.Const y) = singleton_table n x y\"\n| \"eq_rel n (Formula.Const x) (Formula.Var y) = singleton_table n y x\"\n| \"eq_rel n _ _ = undefined\"\n\nlemma regex_atms_size: \"x \\<in> regex.atms r \\<Longrightarrow> size x < regex.size_regex size r\"\n  by (induct r) auto\n\nlemma atms_size:\n  assumes \"x \\<in> atms r\"\n  shows \"size x < Regex.size_regex size r\"\nproof -\n  { fix y assume \"y \\<in> regex.atms r\" \"case y of formula.Neg z \\<Rightarrow> x = z | _ \\<Rightarrow> False\"\n    then have \"size x < Regex.size_regex size r\"\n      by (cases y rule: formula.exhaust) (auto dest: regex_atms_size)\n  }\n  with assms show ?thesis\n    unfolding atms_def\n    by (auto split: formula.splits dest: regex_atms_size)\nqed\n\nfun split_assignment :: \"nat set \\<Rightarrow> Formula.formula \\<Rightarrow> nat \\<times> Formula.trm\" where\n  \"split_assignment X (Formula.Eq t1 t2) = (case (t1, t2) of\n      (Formula.Var x, Formula.Var y) \\<Rightarrow> if x \\<in> X then (y, t1) else (x, t2)\n    | (Formula.Var x, _) \\<Rightarrow> (x, t2)\n    | (_, Formula.Var y) \\<Rightarrow> (y, t1))\"\n| \"split_assignment _ _ = undefined\"\n\nfun split_constraint :: \"Formula.formula \\<Rightarrow> Formula.trm \\<times> bool \\<times> mconstraint \\<times> Formula.trm\" where\n  \"split_constraint (Formula.Eq t1 t2) = (t1, True, MEq, t2)\"\n| \"split_constraint (Formula.Less t1 t2) = (t1, True, MLess, t2)\"\n| \"split_constraint (Formula.LessEq t1 t2) = (t1, True, MLessEq, t2)\"\n| \"split_constraint (Formula.Neg (Formula.Eq t1 t2)) = (t1, False, MEq, t2)\"\n| \"split_constraint (Formula.Neg (Formula.Less t1 t2)) = (t1, False, MLess, t2)\"\n| \"split_constraint (Formula.Neg (Formula.LessEq t1 t2)) = (t1, False, MLessEq, t2)\"\n| \"split_constraint _ = undefined\"\n\ndefinition (in maux) \"init_since minit0 n agg \\<phi> I \\<psi> =\n  (let args = (\\<lambda>b. (init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) b agg)) in\n   if safe_formula \\<phi>\n   then MSince (args True) (minit0 n \\<phi>) (minit0 n \\<psi>) ([], []) [] (init_msaux (args True))\n   else (case \\<phi> of\n     Formula.Neg \\<phi>' \\<Rightarrow> MSince (args False) (minit0 n \\<phi>') (minit0 n \\<psi>) ([], []) [] (init_msaux (args False))\n   | _ \\<Rightarrow> undefined))\"\n\nlemma (in maux) init_since_cong[fundef_cong]:\n  assumes \"\\<And>\\<alpha> m. size \\<alpha> \\<le> size \\<phi> + size \\<psi> \\<Longrightarrow> minit0 m \\<alpha> = minit0' m \\<alpha>\"\n  shows \"init_since minit0 n agg \\<phi> I \\<psi> = init_since minit0' n agg \\<phi> I \\<psi>\"\n  using assms\n  by (auto simp: init_since_def split: formula.splits)\n\ndefinition (in maux) \"init_until minit0 n agg \\<phi> I \\<psi> =\n  (let args = (\\<lambda>b. (init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) b agg)) in\n   if safe_formula \\<phi>\n   then MUntil (args True) (minit0 n \\<phi>) (minit0 n \\<psi>) ([], []) [] 0 (init_muaux (args True))\n   else (case \\<phi> of\n     Formula.Neg \\<phi>' \\<Rightarrow> MUntil (args False) (minit0 n \\<phi>') (minit0 n \\<psi>) ([], []) [] 0 (init_muaux (args False))\n   | _ \\<Rightarrow> undefined))\"\n\nlemma (in maux) init_until_cong[fundef_cong]:\n  assumes \"\\<And>\\<alpha> m. size \\<alpha> \\<le> size \\<phi> + size \\<psi> \\<Longrightarrow> minit0 m \\<alpha> = minit0' m \\<alpha>\"\n  shows \"init_until minit0 n agg \\<phi> I \\<psi> = init_until minit0' n agg \\<phi> I \\<psi>\"\n  using assms\n  by (auto simp: init_until_def split: formula.splits)\n\nfunction (in maux) (sequential) minit0 :: \"nat \\<Rightarrow> Formula.formula \\<Rightarrow> ('msaux, 'muaux) mformula\" where\n  \"minit0 n (Formula.Neg \\<phi>) = (if fv \\<phi> = {} then MNeg (minit0 n \\<phi>) else MRel empty_table)\"\n| \"minit0 n (Formula.Eq t1 t2) = MRel (eq_rel n t1 t2)\"\n| \"minit0 n (Formula.Pred e ts) = MPred e ts\"\n| \"minit0 n (Formula.Let p \\<phi> \\<psi>) = MLet p (Formula.nfv \\<phi>) (minit0 (Formula.nfv \\<phi>) \\<phi>) (minit0 n \\<psi>)\"\n| \"minit0 n (Formula.Or \\<phi> \\<psi>) = MOr (minit0 n \\<phi>) (minit0 n \\<psi>) ([], [])\"\n| \"minit0 n (Formula.And \\<phi> \\<psi>) = (if safe_assignment (fv \\<phi>) \\<psi> then\n      MAndAssign (minit0 n \\<phi>) (split_assignment (fv \\<phi>) \\<psi>)\n    else if safe_formula \\<psi> then\n      MAnd (fv \\<phi>) (minit0 n \\<phi>) True (fv \\<psi>) (minit0 n \\<psi>) ([], [])\n    else if is_constraint \\<psi> then\n      MAndRel (minit0 n \\<phi>) (split_constraint \\<psi>)\n    else (case \\<psi> of Formula.Neg \\<psi> \\<Rightarrow>\n      MAnd (fv \\<phi>) (minit0 n \\<phi>) False (fv \\<psi>) (minit0 n \\<psi>) ([], [])))\"\n| \"minit0 n (Formula.Ands l) = (let (pos, neg) = partition safe_formula l in\n    let mpos = map (minit0 n) pos in\n    let mneg = map (minit0 n) (map remove_neg neg) in\n    let vpos = map fv pos in\n    let vneg = map fv neg in\n    MAnds vpos vneg (mpos @ mneg) (replicate (length l) []))\"\n| \"minit0 n (Formula.Exists \\<phi>) = MExists (minit0 (Suc n) \\<phi>)\"\n| \"minit0 n (Formula.Agg y \\<omega> b f \\<phi>) =\n    (let default = MAgg (fv \\<phi> \\<subseteq> {0..<b}) y \\<omega> b f (minit0 (b + n) \\<phi>) in\n    (case \\<phi> of Formula.Since \\<phi>' I \\<psi>' \\<Rightarrow>\n        let agg = Some (init_aggargs (fv \\<phi>) n (fv \\<phi> \\<subseteq> {0..<b}) y \\<omega> b f) in\n        init_since minit0 (b + n) agg \\<phi>' I \\<psi>'\n     | Formula.Until \\<phi>' I \\<psi>' \\<Rightarrow>\n        let agg = Some (init_aggargs (fv \\<phi>) n (fv \\<phi> \\<subseteq> {0..<b}) y \\<omega> b f) in\n        init_until minit0 (b + n) agg \\<phi>' I \\<psi>'\n     | _ \\<Rightarrow> default))\"\n| \"minit0 n (Formula.Prev I \\<phi>) = MPrev I (minit0 n \\<phi>) True [] []\"\n| \"minit0 n (Formula.Next I \\<phi>) = MNext I (minit0 n \\<phi>) True []\"\n| \"minit0 n (Formula.Since \\<phi> I \\<psi>) = init_since minit0 n None \\<phi> I \\<psi>\"\n| \"minit0 n (Formula.Until \\<phi> I \\<psi>) = init_until minit0 n None \\<phi> I \\<psi>\"\n| \"minit0 n (Formula.MatchP I r) =\n    (let (mr, \\<phi>s) = to_mregex r\n    in MMatchP I mr (sorted_list_of_set (RPDs mr)) (map (minit0 n) \\<phi>s) (replicate (length \\<phi>s) []) [] [])\"\n| \"minit0 n (Formula.MatchF I r) =\n    (let (mr, \\<phi>s) = to_mregex r\n    in MMatchF I mr (sorted_list_of_set (LPDs mr)) (map (minit0 n) \\<phi>s) (replicate (length \\<phi>s) []) [] 0 [])\"\n| \"minit0 n _ = undefined\"\n  by pat_completeness auto\ntermination (in maux)\n  by (relation \"measure (\\<lambda>(_, \\<phi>). size \\<phi>)\")\n     (auto simp: less_Suc_eq_le size_list_estimation' size_remove_neg\n      dest!: to_mregex_ok[OF sym] atms_size)\n\ndefinition (in maux) minit :: \"Formula.formula \\<Rightarrow> ('msaux, 'muaux) mstate\" where\n  \"minit \\<phi> = (let n = Formula.nfv \\<phi> in \\<lparr>mstate_i = 0, mstate_m = minit0 n \\<phi>, mstate_n = n\\<rparr>)\"\n\ndefinition (in maux) minit_safe where\n  \"minit_safe \\<phi> = (if mmonitorable_exec \\<phi> then minit \\<phi> else undefined)\"\n\nfun mprev_next :: \"\\<I> \\<Rightarrow> event_data table list \\<Rightarrow> ts list \\<Rightarrow> event_data table list \\<times> event_data table list \\<times> ts list\" where\n  \"mprev_next I [] ts = ([], [], ts)\"\n| \"mprev_next I xs [] = ([], xs, [])\"\n| \"mprev_next I xs [t] = ([], xs, [t])\"\n| \"mprev_next I (x # xs) (t # t' # ts) = (let (ys, zs) = mprev_next I xs (t' # ts)\n    in ((if mem I ((t' - t)) then x else empty_table) # ys, zs))\"\n\nfun mbuf2_add :: \"event_data table list \\<Rightarrow> event_data table list \\<Rightarrow> event_data mbuf2 \\<Rightarrow> event_data mbuf2\" where\n  \"mbuf2_add xs' ys' (xs, ys) = (xs @ xs', ys @ ys')\"\n\nfun mbuf2_take :: \"(event_data table \\<Rightarrow> event_data table \\<Rightarrow> 'b) \\<Rightarrow> event_data mbuf2 \\<Rightarrow> 'b list \\<times> event_data mbuf2\" where\n  \"mbuf2_take f (x # xs, y # ys) = (let (zs, buf) = mbuf2_take f (xs, ys) in (f x y # zs, buf))\"\n| \"mbuf2_take f (xs, ys) = ([], (xs, ys))\"\n\nfun mbuf2t_take :: \"(event_data table \\<Rightarrow> event_data table \\<Rightarrow> ts \\<Rightarrow> 'b \\<Rightarrow> 'b) \\<Rightarrow> 'b \\<Rightarrow>\n    event_data mbuf2 \\<Rightarrow> ts list \\<Rightarrow> 'b \\<times> event_data mbuf2 \\<times> ts list\" where\n  \"mbuf2t_take f z (x # xs, y # ys) (t # ts) = mbuf2t_take f (f x y t z) (xs, ys) ts\"\n| \"mbuf2t_take f z (xs, ys) ts = (z, (xs, ys), ts)\"\n\nlemma size_list_length_diff1: \"xs \\<noteq> [] \\<Longrightarrow> [] \\<notin> set xs \\<Longrightarrow>\n  size_list (\\<lambda>xs. length xs - Suc 0) xs < size_list length xs\"\nproof (induct xs)\n  case (Cons x xs)\n  then show ?case\n    by (cases xs) auto\nqed simp\n\nfun mbufn_add :: \"event_data table list list \\<Rightarrow> event_data mbufn \\<Rightarrow> event_data mbufn\" where\n  \"mbufn_add xs' xs = List.map2 (@) xs xs'\"\n\nfunction mbufn_take :: \"(event_data table list \\<Rightarrow> 'b \\<Rightarrow> 'b) \\<Rightarrow> 'b \\<Rightarrow> event_data mbufn \\<Rightarrow> 'b \\<times> event_data mbufn\" where\n  \"mbufn_take f z buf = (if buf = [] \\<or> [] \\<in> set buf then (z, buf)\n    else mbufn_take f (f (map hd buf) z) (map tl buf))\"\n  by pat_completeness auto\ntermination by (relation \"measure (\\<lambda>(_, _, buf). size_list length buf)\")\n    (auto simp: comp_def Suc_le_eq size_list_length_diff1)\n\nfun mbufnt_take :: \"(event_data table list \\<Rightarrow> ts \\<Rightarrow> 'b \\<Rightarrow> 'b) \\<Rightarrow>\n    'b \\<Rightarrow> event_data mbufn \\<Rightarrow> ts list \\<Rightarrow> 'b \\<times> event_data mbufn \\<times> ts list\" where\n  \"mbufnt_take f z buf ts =\n    (if [] \\<in> set buf \\<or> ts = [] then (z, buf, ts)\n    else mbufnt_take f (f (map hd buf) (hd ts) z) (map tl buf) (tl ts))\"\n\nfun match :: \"Formula.trm list \\<Rightarrow> event_data list \\<Rightarrow> (nat \\<rightharpoonup> event_data) option\" where\n  \"match [] [] = Some Map.empty\"\n| \"match (Formula.Const x # ts) (y # ys) = (if x = y then match ts ys else None)\"\n| \"match (Formula.Var x # ts) (y # ys) = (case match ts ys of\n      None \\<Rightarrow> None\n    | Some f \\<Rightarrow> (case f x of\n        None \\<Rightarrow> Some (f(x \\<mapsto> y))\n      | Some z \\<Rightarrow> if y = z then Some f else None))\"\n| \"match _ _ = None\"\n\ndefinition (in maux) update_since :: \"args \\<Rightarrow> event_data table \\<Rightarrow> event_data table \\<Rightarrow> ts \\<Rightarrow>\n  'msaux \\<Rightarrow> event_data table \\<times> 'msaux\" where\n  \"update_since args rel1 rel2 nt aux =\n    (let aux0 = join_msaux args rel1 (add_new_ts_msaux args nt aux);\n         aux' = add_new_table_msaux args rel2 aux0\n    in (result_msaux args aux', aux'))\"\n\ndefinition \"lookup = Mapping.lookup_default empty_table\"\n\nfun \\<epsilon>_lax where\n  \"\\<epsilon>_lax guard \\<phi>s (MSkip n) = (if n = 0 then guard else empty_table)\"\n| \"\\<epsilon>_lax guard \\<phi>s (MTestPos i) = join guard True (\\<phi>s ! i)\"\n| \"\\<epsilon>_lax guard \\<phi>s (MTestNeg i) = join guard False (\\<phi>s ! i)\"\n| \"\\<epsilon>_lax guard \\<phi>s (MPlus r s) = \\<epsilon>_lax guard \\<phi>s r \\<union> \\<epsilon>_lax guard \\<phi>s s\"\n| \"\\<epsilon>_lax guard \\<phi>s (MTimes r s) = join (\\<epsilon>_lax guard \\<phi>s r) True (\\<epsilon>_lax guard \\<phi>s s)\"\n| \"\\<epsilon>_lax guard \\<phi>s (MStar r) = guard\"\n\nfun r\\<epsilon>_strict where\n  \"r\\<epsilon>_strict n \\<phi>s (MSkip m) = (if m = 0 then unit_table n else empty_table)\"\n| \"r\\<epsilon>_strict n \\<phi>s (MTestPos i) = \\<phi>s ! i\"\n| \"r\\<epsilon>_strict n \\<phi>s (MTestNeg i) = (if \\<phi>s ! i = empty_table then unit_table n else empty_table)\"\n| \"r\\<epsilon>_strict n \\<phi>s (MPlus r s) = r\\<epsilon>_strict n \\<phi>s r \\<union> r\\<epsilon>_strict n \\<phi>s s\"\n| \"r\\<epsilon>_strict n \\<phi>s (MTimes r s) = \\<epsilon>_lax (r\\<epsilon>_strict n \\<phi>s r) \\<phi>s s\"\n| \"r\\<epsilon>_strict n \\<phi>s (MStar r) = unit_table n\"\n\nfun l\\<epsilon>_strict where\n  \"l\\<epsilon>_strict n \\<phi>s (MSkip m) = (if m = 0 then unit_table n else empty_table)\"\n| \"l\\<epsilon>_strict n \\<phi>s (MTestPos i) = \\<phi>s ! i\"\n| \"l\\<epsilon>_strict n \\<phi>s (MTestNeg i) = (if \\<phi>s ! i = empty_table then unit_table n else empty_table)\"\n| \"l\\<epsilon>_strict n \\<phi>s (MPlus r s) = l\\<epsilon>_strict n \\<phi>s r \\<union> l\\<epsilon>_strict n \\<phi>s s\"\n| \"l\\<epsilon>_strict n \\<phi>s (MTimes r s) = \\<epsilon>_lax (l\\<epsilon>_strict n \\<phi>s s) \\<phi>s r\"\n| \"l\\<epsilon>_strict n \\<phi>s (MStar r) = unit_table n\"\n\nfun r\\<delta> :: \"(mregex \\<Rightarrow> mregex) \\<Rightarrow> (mregex, 'a table) mapping \\<Rightarrow> 'a table list \\<Rightarrow> mregex \\<Rightarrow> 'a table\"  where\n  \"r\\<delta> \\<kappa> X \\<phi>s (MSkip n) = (case n of 0 \\<Rightarrow> empty_table | Suc m \\<Rightarrow> lookup X (\\<kappa> (MSkip m)))\"\n| \"r\\<delta> \\<kappa> X \\<phi>s (MTestPos i) = empty_table\"\n| \"r\\<delta> \\<kappa> X \\<phi>s (MTestNeg i) = empty_table\"\n| \"r\\<delta> \\<kappa> X \\<phi>s (MPlus r s) = r\\<delta> \\<kappa> X \\<phi>s r \\<union> r\\<delta> \\<kappa> X \\<phi>s s\"\n| \"r\\<delta> \\<kappa> X \\<phi>s (MTimes r s) = r\\<delta> (\\<lambda>t. \\<kappa> (MTimes r t)) X \\<phi>s s \\<union> \\<epsilon>_lax (r\\<delta> \\<kappa> X \\<phi>s r) \\<phi>s s\"\n| \"r\\<delta> \\<kappa> X \\<phi>s (MStar r) = r\\<delta> (\\<lambda>t. \\<kappa> (MTimes (MStar r) t)) X \\<phi>s r\"\n\nfun l\\<delta> :: \"(mregex \\<Rightarrow> mregex) \\<Rightarrow> (mregex, 'a table) mapping \\<Rightarrow> 'a table list \\<Rightarrow> mregex \\<Rightarrow> 'a table\" where\n  \"l\\<delta> \\<kappa> X \\<phi>s (MSkip n) = (case n of 0 \\<Rightarrow> empty_table | Suc m \\<Rightarrow> lookup X (\\<kappa> (MSkip m)))\"\n| \"l\\<delta> \\<kappa> X \\<phi>s (MTestPos i) = empty_table\"\n| \"l\\<delta> \\<kappa> X \\<phi>s (MTestNeg i) = empty_table\"\n| \"l\\<delta> \\<kappa> X \\<phi>s (MPlus r s) = l\\<delta> \\<kappa> X \\<phi>s r \\<union> l\\<delta> \\<kappa> X \\<phi>s s\"\n| \"l\\<delta> \\<kappa> X \\<phi>s (MTimes r s) = l\\<delta> (\\<lambda>t. \\<kappa> (MTimes t s)) X \\<phi>s r \\<union> \\<epsilon>_lax (l\\<delta> \\<kappa> X \\<phi>s s) \\<phi>s r\"\n| \"l\\<delta> \\<kappa> X \\<phi>s (MStar r) = l\\<delta> (\\<lambda>t. \\<kappa> (MTimes t (MStar r))) X \\<phi>s r\"\n\nlift_definition mrtabulate :: \"mregex list \\<Rightarrow> (mregex \\<Rightarrow> 'b table) \\<Rightarrow> (mregex, 'b table) mapping\"\n  is \"\\<lambda>ks f. (map_of (List.map_filter (\\<lambda>k. let fk = f k in if fk = empty_table then None else Some (k, fk)) ks))\" .\n\nlemma lookup_tabulate:\n  \"distinct xs \\<Longrightarrow> lookup (mrtabulate xs f) x = (if x \\<in> set xs then f x else empty_table)\"\n  unfolding lookup_default_def lookup_def\n  by transfer (auto simp: Let_def map_filter_def map_of_eq_None_iff o_def image_image dest!: map_of_SomeD\n      split: if_splits option.splits)\n\ndefinition update_matchP :: \"nat \\<Rightarrow> \\<I> \\<Rightarrow> mregex \\<Rightarrow> mregex list \\<Rightarrow> event_data table list \\<Rightarrow> ts \\<Rightarrow>\n  event_data mr\\<delta>aux \\<Rightarrow> event_data table \\<times> event_data mr\\<delta>aux\" where\n  \"update_matchP n I mr mrs rels nt aux =\n    (let aux = (case [(t, mrtabulate mrs (\\<lambda>mr.\n        r\\<delta> id rel rels mr \\<union> (if t = nt then r\\<epsilon>_strict n rels mr else {}))).\n      (t, rel) \\<leftarrow> aux, memR I (nt - t)]\n      of [] \\<Rightarrow> [(nt, mrtabulate mrs (r\\<epsilon>_strict n rels))]\n      | x # aux' \\<Rightarrow> (if fst x = nt then x # aux'\n                     else (nt, mrtabulate mrs (r\\<epsilon>_strict n rels)) # x # aux'))\n    in (foldr (\\<union>) [lookup rel mr. (t, rel) \\<leftarrow> aux, memL I (nt - t)] {}, aux))\"\n\ndefinition update_matchF_base where\n  \"update_matchF_base n I mr mrs rels nt =\n     (let X = mrtabulate mrs (l\\<epsilon>_strict n rels)\n     in ([(nt, rels, if memL I 0 then lookup X mr else empty_table)], X))\"\n\ndefinition update_matchF_step where\n  \"update_matchF_step I mr mrs nt = (\\<lambda>(t, rels', rel) (aux', X).\n     (let Y = mrtabulate mrs (l\\<delta> id X rels')\n     in ((t, rels', if mem I ((nt - t)) then rel \\<union> lookup Y mr else rel) # aux', Y)))\"\n\ndefinition update_matchF :: \"nat \\<Rightarrow> \\<I> \\<Rightarrow> mregex \\<Rightarrow> mregex list \\<Rightarrow> event_data table list \\<Rightarrow> ts \\<Rightarrow> event_data ml\\<delta>aux \\<Rightarrow> event_data ml\\<delta>aux\" where\n  \"update_matchF n I mr mrs rels nt aux =\n     fst (foldr (update_matchF_step I mr mrs nt) aux (update_matchF_base n I mr mrs rels nt))\"\n\nfun eval_matchF :: \"\\<I> \\<Rightarrow> mregex \\<Rightarrow> ts \\<Rightarrow> event_data ml\\<delta>aux \\<Rightarrow> event_data table list \\<times> event_data ml\\<delta>aux\" where\n  \"eval_matchF I mr nt [] = ([], [])\"\n| \"eval_matchF I mr nt ((t, rels, rel) # aux) = (if \\<not> memR I (nt - t) then\n    (let (xs, aux) = eval_matchF I mr nt aux in (rel # xs, aux)) else ([], (t, rels, rel) # aux))\"\n\nprimrec map_split where\n  \"map_split f [] = ([], [])\"\n| \"map_split f (x # xs) =\n    (let (y, z) = f x; (ys, zs) = map_split f xs\n    in (y # ys, z # zs))\"\n\nfun eval_assignment :: \"nat \\<times> Formula.trm \\<Rightarrow> event_data tuple \\<Rightarrow> event_data tuple\" where\n  \"eval_assignment (x, t) y = (y[x:=Some (meval_trm t y)])\"\n\nfun eval_constraint0 :: \"mconstraint \\<Rightarrow> event_data \\<Rightarrow> event_data \\<Rightarrow> bool\" where\n  \"eval_constraint0 MEq x y = (x = y)\"\n| \"eval_constraint0 MLess x y = (x < y)\"\n| \"eval_constraint0 MLessEq x y = (x \\<le> y)\"\n\nfun eval_constraint :: \"Formula.trm \\<times> bool \\<times> mconstraint \\<times> Formula.trm \\<Rightarrow> event_data tuple \\<Rightarrow> bool\" where\n  \"eval_constraint (t1, p, c, t2) x = (eval_constraint0 c (meval_trm t1 x) (meval_trm t2 x) = p)\"\n\ndefinition \"lookahead_ts nts' nts ts t = hd (nts' @ rev (nts @ ts) @ [t])\"\n\nlemma lookahead_ts_code[code]: \"lookahead_ts nts' nts ts t =\n   (case nts' of t # _ \\<Rightarrow> t\n   | [] \\<Rightarrow> (case ts of _ # _ \\<Rightarrow> last ts\n           | [] \\<Rightarrow> (case nts of _ # _ \\<Rightarrow> last nts\n                   | [] \\<Rightarrow> t)))\"\n  by (auto simp: lookahead_ts_def hd_append hd_rev split: list.splits)\n\nprimrec (in maux) meval :: \"nat \\<Rightarrow> ts list \\<Rightarrow> Formula.database \\<Rightarrow> ('msaux, 'muaux) mformula \\<Rightarrow>\n    event_data table list \\<times> ('msaux, 'muaux) mformula\" where\n  \"meval n ts db (MRel rel) = (replicate (length ts) rel, MRel rel)\"\n| \"meval n ts db (MPred e tms) = (map (\\<lambda>X. (\\<lambda>f. Table.tabulate f 0 n) ` Option.these\n    (match tms ` X)) (case Mapping.lookup db e of None \\<Rightarrow> replicate (length ts) {} | Some xs \\<Rightarrow> xs), MPred e tms)\"\n| \"meval n ts db (MLet p m \\<phi> \\<psi>) =\n    (let (xs, \\<phi>) = meval m ts db \\<phi>; (ys, \\<psi>) = meval n ts (Mapping.update p (map (image (map the)) xs) db) \\<psi>\n    in (ys, MLet p m \\<phi> \\<psi>))\"\n| \"meval n ts db (MAnd A_\\<phi> \\<phi> pos A_\\<psi> \\<psi> buf) =\n    (let (xs, \\<phi>) = meval n ts db \\<phi>; (ys, \\<psi>) = meval n ts db \\<psi>;\n      (zs, buf) = mbuf2_take (\\<lambda>r1 r2. bin_join n A_\\<phi> r1 pos A_\\<psi> r2) (mbuf2_add xs ys buf)\n    in (zs, MAnd A_\\<phi> \\<phi> pos A_\\<psi> \\<psi> buf))\"\n| \"meval n ts db (MAndAssign \\<phi> conf) =\n    (let (xs, \\<phi>) = meval n ts db \\<phi> in (map (\\<lambda>r. eval_assignment conf ` r) xs, MAndAssign \\<phi> conf))\"\n| \"meval n ts db (MAndRel \\<phi> conf) =\n    (let (xs, \\<phi>) = meval n ts db \\<phi> in (map (Set.filter (eval_constraint conf)) xs, MAndRel \\<phi> conf))\"\n| \"meval n ts db (MAnds A_pos A_neg L buf) =\n    (let R = map (meval n ts db) L in\n    let buf = mbufn_add (map fst R) buf in\n    let (zs, buf) = mbufn_take (\\<lambda>xs zs. zs @ [mmulti_join n A_pos A_neg xs]) [] buf in\n    (zs, MAnds A_pos A_neg (map snd R) buf))\"\n| \"meval n ts db (MOr \\<phi> \\<psi> buf) =\n    (let (xs, \\<phi>) = meval n ts db \\<phi>; (ys, \\<psi>) = meval n ts db \\<psi>;\n      (zs, buf) = mbuf2_take (\\<lambda>r1 r2. r1 \\<union> r2) (mbuf2_add xs ys buf)\n    in (zs, MOr \\<phi> \\<psi> buf))\"\n| \"meval n ts db (MNeg \\<phi>) =\n    (let (xs, \\<phi>) = meval n ts db \\<phi> in (map (\\<lambda>r. (if r = empty_table then unit_table n else empty_table)) xs, MNeg \\<phi>))\"\n| \"meval n ts db (MExists \\<phi>) =\n    (let (xs, \\<phi>) = meval (Suc n) ts db \\<phi> in (map (\\<lambda>r. tl ` r) xs, MExists \\<phi>))\"\n| \"meval n ts db (MAgg g0 y \\<omega> b f \\<phi>) =\n    (let (xs, \\<phi>) = meval (b + n) ts db \\<phi> in (map (eval_agg n g0 y \\<omega> b f) xs, MAgg g0 y \\<omega> b f \\<phi>))\"\n| \"meval n ts db (MPrev I \\<phi> first buf nts) =\n    (let (xs, \\<phi>) = meval n ts db \\<phi>\n    in if first \\<and> ts = [] then ([], MPrev I \\<phi> True (buf @ xs) (nts @ ts))\n    else let (zs, buf, nts) = mprev_next I (buf @ xs) (nts @ ts)\n      in (if first then empty_table # zs else zs, MPrev I \\<phi> False buf nts))\"\n| \"meval n ts db (MNext I \\<phi> first nts) =\n    (let (xs, \\<phi>) = meval n ts db \\<phi>;\n      (xs, first) = (case (xs, first) of (_ # xs, True) \\<Rightarrow> (xs, False) | a \\<Rightarrow> a);\n      (zs, _, nts) = mprev_next I xs (nts @ ts)\n    in (zs, MNext I \\<phi> first nts))\"\n| \"meval n ts db (MSince args \\<phi> \\<psi> buf nts aux) =\n    (let (xs, \\<phi>) = meval (args_n args) ts db \\<phi>; (ys, \\<psi>) = meval (args_n args) ts db \\<psi>;\n      ((zs, aux), buf, nts) = mbuf2t_take (\\<lambda>r1 r2 t (zs, aux).\n        let (z, aux) = update_since args r1 r2 t aux\n        in (zs @ [z], aux)) ([], aux) (mbuf2_add xs ys buf) (nts @ ts)\n    in (zs, MSince args \\<phi> \\<psi> buf nts aux))\"\n| \"meval n ts db (MUntil args \\<phi> \\<psi> buf nts t aux) =\n    (let (xs, \\<phi>) = meval (args_n args) ts db \\<phi>; (ys, \\<psi>) = meval (args_n args) ts db \\<psi>;\n      (aux, buf, nts') = mbuf2t_take (add_new_muaux args) aux (mbuf2_add xs ys buf) (nts @ ts);\n      nt = lookahead_ts nts' nts ts t;\n      (zs, aux) = eval_muaux args nt aux\n    in (zs, MUntil args \\<phi> \\<psi> buf nts' nt aux))\"\n| \"meval n ts db (MMatchP I mr mrs \\<phi>s buf nts aux) =\n    (let (xss, \\<phi>s) = map_split id (map (meval n ts db) \\<phi>s);\n      ((zs, aux), buf, nts) = mbufnt_take (\\<lambda>rels t (zs, aux).\n        let (z, aux) = update_matchP n I mr mrs rels t aux\n        in (zs @ [z], aux)) ([], aux) (mbufn_add xss buf) (nts @ ts)\n    in (zs, MMatchP I mr mrs \\<phi>s buf nts aux))\"\n| \"meval n ts db (MMatchF I mr mrs \\<phi>s buf nts t aux) =\n    (let (xss, \\<phi>s) = map_split id (map (meval n ts db) \\<phi>s);\n      (aux, buf, nts') = mbufnt_take (update_matchF n I mr mrs) aux (mbufn_add xss buf) (nts @ ts);\n      nt = lookahead_ts nts' nts ts t;\n      (zs, aux) = eval_matchF I mr nt aux\n    in (zs, MMatchF I mr mrs \\<phi>s buf nts' nt aux))\"\n\ndefinition (in maux) mstep :: \"Formula.database \\<times> ts \\<Rightarrow> ('msaux, 'muaux) mstate \\<Rightarrow> (nat \\<times> event_data table) list \\<times> ('msaux, 'muaux) mstate\" where\n  \"mstep tdb st =\n     (let (xs, m) = meval (mstate_n st) [snd tdb] (fst tdb) (mstate_m st)\n     in (List.enumerate (mstate_i st) xs,\n      \\<lparr>mstate_i = mstate_i st + length xs, mstate_m = m, mstate_n = mstate_n st\\<rparr>))\"\n\nsubsection \\<open>Verdict delay\\<close>\n\ncontext fixes \\<sigma> :: Formula.trace begin\n\nfun progress :: \"(Formula.name \\<rightharpoonup> nat) \\<Rightarrow> Formula.formula \\<Rightarrow> nat \\<Rightarrow> nat\" where\n  \"progress P (Formula.Pred e ts) j = (case P e of None \\<Rightarrow> j | Some k \\<Rightarrow> k)\"\n| \"progress P (Formula.Let p \\<phi> \\<psi>) j = progress (P(p \\<mapsto> progress P \\<phi> j)) \\<psi> j\"\n| \"progress P (Formula.Eq t1 t2) j = j\"\n| \"progress P (Formula.Less t1 t2) j = j\"\n| \"progress P (Formula.LessEq t1 t2) j = j\"\n| \"progress P (Formula.Neg \\<phi>) j = progress P \\<phi> j\"\n| \"progress P (Formula.Or \\<phi> \\<psi>) j = min (progress P \\<phi> j) (progress P \\<psi> j)\"\n| \"progress P (Formula.And \\<phi> \\<psi>) j = min (progress P \\<phi> j) (progress P \\<psi> j)\"\n| \"progress P (Formula.Ands l) j = (if l = [] then j else Min (set (map (\\<lambda>\\<phi>. progress P \\<phi> j) l)))\"\n| \"progress P (Formula.Exists \\<phi>) j = progress P \\<phi> j\"\n| \"progress P (Formula.Agg y \\<omega> b f \\<phi>) j = progress P \\<phi> j\"\n| \"progress P (Formula.Prev I \\<phi>) j = (if j = 0 then 0 else min (Suc (progress P \\<phi> j)) j)\"\n| \"progress P (Formula.Next I \\<phi>) j = progress P \\<phi> j - 1\"\n| \"progress P (Formula.Since \\<phi> I \\<psi>) j = min (progress P \\<phi> j) (progress P \\<psi> j)\"\n| \"progress P (Formula.Until \\<phi> I \\<psi>) j =\n    Inf {i. \\<forall>k. k < j \\<and> k \\<le> min (progress P \\<phi> j) (progress P \\<psi> j) \\<longrightarrow> memR I (\\<tau> \\<sigma> k - \\<tau> \\<sigma> i)}\"\n| \"progress P (Formula.MatchP I r) j = min_regex_default (progress P) r j\"\n| \"progress P (Formula.MatchF I r) j =\n    Inf {i. \\<forall>k. k < j \\<and> k \\<le> min_regex_default (progress P) r j \\<longrightarrow> memR I (\\<tau> \\<sigma> k - \\<tau> \\<sigma> i)}\"\n\ndefinition \"progress_regex P = min_regex_default (progress P)\"\n\ndeclare progress.simps[simp del]\nlemmas progress_simps[simp] = progress.simps[folded progress_regex_def[THEN fun_cong, THEN fun_cong]]\n\nend\n\ndefinition \"pred_mapping Q = pred_fun (\\<lambda>_. True) (pred_option Q)\"\ndefinition \"rel_mapping Q = rel_fun (=) (rel_option Q)\"\n\nlemma pred_mapping_alt: \"pred_mapping Q P = (\\<forall>p \\<in> dom P. Q (the (P p)))\"\n  unfolding pred_mapping_def pred_fun_def option.pred_set dom_def\n  by (force split: option.splits)\n\nlemma rel_mapping_alt: \"rel_mapping Q P P' = (dom P = dom P' \\<and> (\\<forall>p \\<in> dom P. Q (the (P p)) (the (P' p))))\"\n  unfolding rel_mapping_def rel_fun_def rel_option_iff dom_def\n  by (force split: option.splits)\n\nlemma rel_mapping_map_upd[simp]: \"Q x y \\<Longrightarrow> rel_mapping Q P P' \\<Longrightarrow> rel_mapping Q (P(p \\<mapsto> x)) (P'(p \\<mapsto> y))\"\n  by (auto simp: rel_mapping_alt)\n\nlemma pred_mapping_map_upd[simp]: \"Q x \\<Longrightarrow> pred_mapping Q P \\<Longrightarrow> pred_mapping Q (P(p \\<mapsto> x))\"\n  by (auto simp: pred_mapping_alt)\n\nlemma pred_mapping_empty[simp]: \"pred_mapping Q Map.empty\"\n  by (auto simp: pred_mapping_alt)\n\nlemma pred_mapping_mono: \"pred_mapping Q P \\<Longrightarrow> Q \\<le> R \\<Longrightarrow> pred_mapping R P\"\n  by (auto simp: pred_mapping_alt)\n\nlemma pred_mapping_mono_strong: \"pred_mapping Q P \\<Longrightarrow>\n  (\\<And>p. p \\<in> dom P \\<Longrightarrow> Q (the (P p)) \\<Longrightarrow> R (the (P p))) \\<Longrightarrow> pred_mapping R P\"\n  by (auto simp: pred_mapping_alt)\n\nlemma progress_mono_gen: \"j \\<le> j' \\<Longrightarrow> rel_mapping (\\<le>) P P' \\<Longrightarrow> progress \\<sigma> P \\<phi> j \\<le> progress \\<sigma> P' \\<phi> j'\"\nproof (induction \\<phi> arbitrary: P P')\n  case (Pred e ts)\n  then show ?case\n    by (force simp: rel_mapping_alt dom_def split: option.splits)\nnext\n  case (Ands l)\n  then show ?case\n    by (auto simp: image_iff intro!: Min.coboundedI[THEN order_trans])\nnext\n  case (Until \\<phi> I \\<psi>)\n  from Until(1,2)[of P P'] Until.prems show ?case\n    by (auto 0 3 dest: memR_nonzeroD less_\\<tau>D spec[of _ j'] intro!: cInf_superset_mono)\nnext\n  case (MatchF I r)\n  from MatchF(1)[of _ P P'] MatchF.prems show ?case\n    by (auto 0 3 simp: Min_le_iff progress_regex_def dest: memR_nonzeroD less_\\<tau>D spec[of _ j']\n      elim!: order_trans less_le_trans intro!: cInf_superset_mono)\nqed (force simp: Min_le_iff progress_regex_def split: option.splits)+\n\nlemma rel_mapping_reflp: \"reflp Q \\<Longrightarrow> rel_mapping Q P P\"\n  by (auto simp: rel_mapping_alt reflp_def)\n\nlemmas progress_mono = progress_mono_gen[OF _ rel_mapping_reflp[unfolded reflp_def], simplified]\n\nlemma progress_le_gen: \"pred_mapping (\\<lambda>x. x \\<le> j) P \\<Longrightarrow> progress \\<sigma> P \\<phi> j \\<le> j\"\nproof (induction \\<phi> arbitrary: P)\n  case (Pred e ts)\n  then show ?case\n    by (auto simp: pred_mapping_alt dom_def split: option.splits)\nnext\n  case (Ands l)\n  then show ?case\n    by (auto simp: image_iff intro!: Min.coboundedI[where a=\"progress \\<sigma> P (hd l) j\", THEN order_trans])\nnext\n  case (Until \\<phi> I \\<psi>)\n  then show ?case\n    by (auto intro!: cInf_lower)\nnext\n  case (MatchF I r)\n  then show ?case\n    by (auto intro!: cInf_lower)\nqed (force simp: Min_le_iff progress_regex_def split: option.splits)+\n\nlemma progress_le: \"progress \\<sigma> Map.empty \\<phi> j \\<le> j\"\n  using progress_le_gen[of _ Map.empty] by auto\n\nlemma progress_0_gen[simp]:\n  \"pred_mapping (\\<lambda>x. x = 0) P \\<Longrightarrow> progress \\<sigma> P \\<phi> 0 = 0\"\n  using progress_le_gen[of 0 P] by auto\n\nlemma progress_0[simp]:\n  \"progress \\<sigma> Map.empty \\<phi> 0 = 0\"\n  by (auto simp: pred_mapping_alt)\n\ndefinition max_mapping :: \"('b \\<Rightarrow> 'a option) \\<Rightarrow> ('b \\<Rightarrow> 'a option) \\<Rightarrow> 'b \\<Rightarrow> ('a :: linorder) option\" where\n  \"max_mapping P P' x = (case (P x, P' x) of\n    (None, None) \\<Rightarrow> None\n  | (Some x, None) \\<Rightarrow> None\n  | (None, Some x) \\<Rightarrow> None\n  | (Some x, Some y) \\<Rightarrow> Some (max x y))\"\n\ndefinition Max_mapping :: \"('b \\<Rightarrow> 'a option) set \\<Rightarrow> 'b \\<Rightarrow> ('a :: linorder) option\" where\n  \"Max_mapping Ps x = (if (\\<forall>P \\<in> Ps. P x \\<noteq> None) then Some (Max ((\\<lambda>P. the (P x)) ` Ps)) else None)\"\n\nlemma dom_max_mapping[simp]: \"dom (max_mapping P1 P2) = dom P1 \\<inter> dom P2\"\n  unfolding max_mapping_def by (auto split: option.splits)\n\nlemma dom_Max_mapping[simp]: \"dom (Max_mapping X) = (\\<Inter>P \\<in> X. dom P)\"\n  unfolding Max_mapping_def by (auto split: if_splits)\n\nlemma Max_mapping_coboundedI:\n  assumes \"finite X\" \"\\<forall>Q \\<in> X. dom Q = dom P\" \"P \\<in> X\"\n  shows \"rel_mapping (\\<le>) P (Max_mapping X)\"\n  unfolding rel_mapping_alt\nproof (intro conjI ballI)\n  from assms(3) have \"X \\<noteq> {}\" by auto\n  then show \"dom P = dom (Max_mapping X)\" using assms(2) by auto\nnext\n  fix p\n  assume \"p \\<in> dom P\"\n  with assms show \"the (P p) \\<le> the (Max_mapping X p)\"\n    by (force simp add: Max_mapping_def intro!: Max.coboundedI imageI)\nqed\n\nlemma rel_mapping_trans: \"P OO Q \\<le> R \\<Longrightarrow>\n  rel_mapping P P1 P2 \\<Longrightarrow> rel_mapping Q P2 P3 \\<Longrightarrow> rel_mapping R P1 P3\"\n  by (force simp: rel_mapping_alt dom_def set_eq_iff)\n\nabbreviation range_mapping :: \"nat \\<Rightarrow> nat \\<Rightarrow> ('b \\<Rightarrow> nat option) \\<Rightarrow> bool\" where\n  \"range_mapping i j P \\<equiv> pred_mapping (\\<lambda>x. i \\<le> x \\<and> x \\<le> j) P\"\n\nlemma range_mapping_relax:\n  \"range_mapping i j P \\<Longrightarrow> i' \\<le> i \\<Longrightarrow> j' \\<ge> j \\<Longrightarrow> range_mapping i' j' P\"\n  by (auto simp: pred_mapping_alt dom_def set_eq_iff max_mapping_def split: option.splits)\n\nlemma range_mapping_max_mapping[simp]:\n  \"range_mapping i j1 P1 \\<Longrightarrow> range_mapping i j2 P2 \\<Longrightarrow> range_mapping i (max j1 j2) (max_mapping P1 P2)\"\n  by (auto simp: pred_mapping_alt dom_def set_eq_iff max_mapping_def split: option.splits)\n\nlemma range_mapping_Max_mapping[simp]:\n  \"finite X \\<Longrightarrow> X \\<noteq> {} \\<Longrightarrow> \\<forall>x\\<in>X. range_mapping i (j x) (P x) \\<Longrightarrow> range_mapping i (Max (j ` X)) (Max_mapping (P ` X))\"\n  by (force simp: pred_mapping_alt Max_mapping_def dom_def image_iff\n      intro!: Max_ge_iff[THEN iffD2] split: if_splits)\n\nlemma pred_mapping_le:\n  \"pred_mapping ((\\<le>) i) P1 \\<Longrightarrow> rel_mapping (\\<le>) P1 P2 \\<Longrightarrow> pred_mapping ((\\<le>) (i :: nat)) P2\"\n  by (force simp: rel_mapping_alt pred_mapping_alt dom_def set_eq_iff)\n\nlemma pred_mapping_le':\n  \"pred_mapping ((\\<le>) j) P1 \\<Longrightarrow> i \\<le> j \\<Longrightarrow> rel_mapping (\\<le>) P1 P2 \\<Longrightarrow> pred_mapping ((\\<le>) (i :: nat)) P2\"\n  by (force simp: rel_mapping_alt pred_mapping_alt dom_def set_eq_iff)\n\nlemma max_mapping_cobounded1: \"dom P1 \\<subseteq> dom P2 \\<Longrightarrow> rel_mapping (\\<le>) P1 (max_mapping P1 P2)\"\n  unfolding max_mapping_def rel_mapping_alt by (auto simp: dom_def split: option.splits)\n\nlemma max_mapping_cobounded2: \"dom P2 \\<subseteq> dom P1 \\<Longrightarrow> rel_mapping (\\<le>) P2 (max_mapping P1 P2)\"\n  unfolding max_mapping_def rel_mapping_alt by (auto simp: dom_def split: option.splits)\n\nlemma max_mapping_fun_upd2[simp]:\n  \"max_mapping P1 (P2(p := y))(p \\<mapsto> x) = (max_mapping P1 P2)(p \\<mapsto> x)\"\n  by (auto simp: max_mapping_def)\n\nlemma rel_mapping_max_mapping_fun_upd: \"dom P2 \\<subseteq> dom P1 \\<Longrightarrow> p \\<in> dom P2 \\<Longrightarrow> the (P2 p) \\<le> y \\<Longrightarrow>\n  rel_mapping (\\<le>) P2 (max_mapping P1 P2(p \\<mapsto> y))\"\n  by (auto simp: rel_mapping_alt max_mapping_def split: option.splits)\n\nlemma progress_ge_gen: \"Formula.future_bounded \\<phi> \\<Longrightarrow>\n   \\<exists>P j. dom P = S \\<and> range_mapping i j P \\<and> i \\<le> progress \\<sigma> P \\<phi> j\"\nproof (induction \\<phi> arbitrary: i S)\n  case (Pred e ts)\n  then show ?case\n    by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some i else None\"])\n      (auto split: option.splits if_splits simp: rel_mapping_alt pred_mapping_alt dom_def)\nnext\n  case (Let p \\<phi> \\<psi>)\n  from Let.prems obtain P2 j2 where P2: \"dom P2 = insert p S\" \"range_mapping i j2 P2\"\n    \"i \\<le> progress \\<sigma> P2 \\<psi> j2\"\n    by (atomize_elim, intro Let(2)) (force simp: pred_mapping_alt rel_mapping_alt dom_def)+\n  from Let.prems obtain P1 j1 where P1: \"dom P1 = S\" \"range_mapping (the (P2 p)) j1 P1\"\n    \"the (P2 p) \\<le> progress \\<sigma> P1 \\<phi> j1\"\n    by (atomize_elim, intro Let(1)) auto\n  let ?P12 = \"max_mapping P1 P2\"\n  from P1 P2 have le1: \"progress \\<sigma> P1 \\<phi> j1 \\<le> progress \\<sigma> (?P12(p := P1 p)) \\<phi> (max j1 j2)\"\n    by (intro progress_mono_gen) (auto simp: rel_mapping_alt max_mapping_def)\n  from P1 P2 have le2: \"progress \\<sigma> P2 \\<psi> j2 \\<le> progress \\<sigma> (?P12(p \\<mapsto> progress \\<sigma> P1 \\<phi> j1)) \\<psi> (max j1 j2)\"\n    by (intro progress_mono_gen) (auto simp: rel_mapping_alt max_mapping_def)\n  show ?case\n    unfolding progress.simps\n  proof (intro exI[of _ \"?P12(p := P1 p)\"] exI[of _ \"max j1 j2\"] conjI)\n    show \"dom (?P12(p := P1 p)) = S\"\n      using P1 P2 by (auto simp: dom_def max_mapping_def)\n  next\n    show \"range_mapping i (max j1 j2) (?P12(p := P1 p))\"\n      using P1 P2 by (force simp add: pred_mapping_alt dom_def max_mapping_def split: option.splits)\n  next\n    have \"i \\<le> progress \\<sigma> P2 \\<psi> j2\" by fact\n    also have \"... \\<le> progress \\<sigma> (?P12(p \\<mapsto> progress \\<sigma> P1 \\<phi> j1)) \\<psi> (max j1 j2)\"\n      using le2 by blast\n    also have \"... \\<le> progress \\<sigma> (?P12(p := P1 p)(p\\<mapsto>progress \\<sigma> (?P12(p := P1 p)) \\<phi> (max j1 j2))) \\<psi> (max j1 j2)\"\n      by (auto intro!: progress_mono_gen simp: le1 rel_mapping_alt)\n    finally show \"i \\<le> ...\" .\n  qed\nnext\n  case (Eq _ _)\n  then show ?case\n    by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some i else None\"]) (auto split: if_splits simp: pred_mapping_alt)\nnext\n  case (Less _ _)\n  then show ?case\n    by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some i else None\"]) (auto split: if_splits simp: pred_mapping_alt)\nnext\n  case (LessEq _ _)\n  then show ?case\n    by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some i else None\"]) (auto split: if_splits simp: pred_mapping_alt)\nnext\n  case (Or \\<phi>1 \\<phi>2)\n  from Or(3) obtain P1 j1 where P1: \"dom P1 = S\" \"range_mapping i j1 P1\"  \"i \\<le> progress \\<sigma> P1 \\<phi>1 j1\"\n    using Or(1)[of S i] by auto\n  moreover\n  from Or(3) obtain P2 j2 where P2: \"dom P2 = S\" \"range_mapping i j2 P2\" \"i \\<le> progress \\<sigma> P2 \\<phi>2 j2\"\n    using Or(2)[of S i] by auto\n  ultimately have \"i \\<le> progress \\<sigma> (max_mapping P1 P2) (Formula.Or \\<phi>1 \\<phi>2) (max j1 j2)\"\n    by (auto 0 3 elim!: order.trans[OF _ progress_mono_gen] intro: max_mapping_cobounded1 max_mapping_cobounded2)\n  with P1 P2 show ?case by (intro exI[of _ \"max_mapping P1 P2\"] exI[of _ \"max j1 j2\"]) auto\nnext\n  case (And \\<phi>1 \\<phi>2)\n  from And(3) obtain P1 j1 where P1: \"dom P1 = S\" \"range_mapping i j1 P1\"  \"i \\<le> progress \\<sigma> P1 \\<phi>1 j1\"\n    using And(1)[of S i] by auto\n  moreover\n  from And(3) obtain P2 j2 where P2: \"dom P2 = S\" \"range_mapping i j2 P2\" \"i \\<le> progress \\<sigma> P2 \\<phi>2 j2\"\n    using And(2)[of S i] by auto\n  ultimately have \"i \\<le> progress \\<sigma> (max_mapping P1 P2) (Formula.And \\<phi>1 \\<phi>2) (max j1 j2)\"\n    by (auto 0 3 elim!: order.trans[OF _ progress_mono_gen] intro: max_mapping_cobounded1 max_mapping_cobounded2)\n  with P1 P2 show ?case by (intro exI[of _ \"max_mapping P1 P2\"] exI[of _ \"max j1 j2\"]) auto\nnext\n  case (Ands l)\n  show ?case proof (cases \"l = []\")\n    case True\n    then show ?thesis\n      by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some i else None\"])\n        (auto split: if_splits simp: pred_mapping_alt)\n  next\n    case False\n    then obtain \\<phi> where \"\\<phi> \\<in> set l\" by (cases l) auto\n    from Ands.prems have \"\\<forall>\\<phi>\\<in>set l. Formula.future_bounded \\<phi>\"\n      by (simp add: list.pred_set)\n    { fix \\<phi>\n      assume \"\\<phi> \\<in> set l\"\n      with Ands.prems obtain P j where \"dom P = S\" \"range_mapping i j P\" \"i \\<le> progress \\<sigma> P \\<phi> j\"\n        by (atomize_elim, intro Ands(1)[of \\<phi> S i]) (auto simp: list.pred_set)\n      then have \"\\<exists>Pj. dom (fst Pj) = S \\<and> range_mapping i (snd Pj) (fst Pj) \\<and> i \\<le> progress \\<sigma> (fst Pj) \\<phi> (snd Pj)\"\n        (is \"\\<exists>Pj. ?P Pj\")\n        by (intro exI[of _ \"(P, j)\"]) auto\n    }\n    then have \"\\<forall>\\<phi>\\<in>set l. \\<exists>Pj. dom (fst Pj) = S \\<and> range_mapping i (snd Pj) (fst Pj) \\<and> i \\<le> progress \\<sigma> (fst Pj) \\<phi> (snd Pj)\"\n      (is \"\\<forall>\\<phi>\\<in>set l. \\<exists>Pj. ?P Pj \\<phi>\")\n      by blast\n    with Ands(1) Ands.prems False have \"\\<exists>Pjf. \\<forall>\\<phi>\\<in>set l. ?P (Pjf \\<phi>) \\<phi>\"\n      by (auto simp: Ball_def intro: choice)\n    then obtain Pjf where Pjf: \"\\<forall>\\<phi>\\<in>set l. ?P (Pjf \\<phi>) \\<phi>\" ..\n    define Pf where \"Pf = fst o Pjf\"\n    define jf where \"jf = snd o Pjf\"\n    have *: \"dom (Pf \\<phi>) = S\" \"range_mapping i (jf \\<phi>) (Pf \\<phi>)\" \"i \\<le> progress \\<sigma> (Pf \\<phi>) \\<phi> (jf \\<phi>)\"\n      if \"\\<phi> \\<in> set l\" for \\<phi>\n      using Pjf[THEN bspec, OF that] unfolding Pf_def jf_def by auto\n    with False show ?thesis\n      unfolding progress.simps eq_False[THEN iffD2, OF False] if_False\n      by ((subst Min_ge_iff; simp add: False),\n          intro exI[where x=\"MAX \\<phi>\\<in>set l. jf \\<phi>\"] exI[where x=\"Max_mapping (Pf ` set l)\"]\n          conjI ballI order.trans[OF *(3) progress_mono_gen] Max_mapping_coboundedI)\n        (auto simp: False *[OF \\<open>\\<phi> \\<in> set l\\<close>] \\<open>\\<phi> \\<in> set l\\<close>)\n  qed\nnext\n  case (Exists \\<phi>)\n  then show ?case by simp\nnext\n  case (Prev I \\<phi>)\n  then obtain P j where \"dom P = S\" \"range_mapping i j P\" \"i \\<le> progress \\<sigma> P \\<phi> j\"\n    by (atomize_elim, intro Prev(1)) (auto simp: pred_mapping_alt dom_def)\n  with Prev(2) have\n    \"dom P = S \\<and> range_mapping i (max i j) P \\<and> i \\<le> progress \\<sigma> P (formula.Prev I \\<phi>) (max i j)\"\n    by (auto simp: le_Suc_eq max_def pred_mapping_alt split: if_splits\n        elim: order.trans[OF _ progress_mono])\n  then show ?case by blast\nnext\n  case (Next I \\<phi>)\n  then obtain P j where \"dom P = S\" \"range_mapping (Suc i) j P\" \"Suc i \\<le> progress \\<sigma> P \\<phi> j\"\n    by (atomize_elim, intro Next(1)) (auto simp: pred_mapping_alt dom_def)\n  then show ?case\n    by (intro exI[of _ P] exI[of _ j]) (auto 0 3 simp: pred_mapping_alt dom_def)\nnext\n  case (Since \\<phi>1 I \\<phi>2)\n  from Since(3) obtain P1 j1 where P1: \"dom P1 = S\" \"range_mapping i j1 P1\"  \"i \\<le> progress \\<sigma> P1 \\<phi>1 j1\"\n    using Since(1)[of S i] by auto\n  moreover\n  from Since(3) obtain P2 j2 where P2: \"dom P2 = S\" \"range_mapping i j2 P2\" \"i \\<le> progress \\<sigma> P2 \\<phi>2 j2\"\n    using Since(2)[of S i] by auto\n  ultimately have \"i \\<le> progress \\<sigma> (max_mapping P1 P2) (Formula.Since \\<phi>1 I \\<phi>2) (max j1 j2)\"\n    by (auto elim!: order.trans[OF _ progress_mono_gen] simp: max_mapping_cobounded1 max_mapping_cobounded2)\n  with P1 P2 show ?case by (intro exI[of _ \"max_mapping P1 P2\"] exI[of _ \"max j1 j2\"])\n      (auto elim!: pred_mapping_le intro: max_mapping_cobounded1)\nnext\n  case (Until \\<phi>1 I \\<phi>2)\n  from Until.prems obtain m where \"\\<not> memR I m\"\n    by (auto simp: bounded_memR)\n  then obtain i' where \"i < i'\" and 1: \"\\<not> memR I (\\<tau> \\<sigma> i' - \\<tau> \\<sigma> i)\"\n    using ex_le_\\<tau>[where x=\"\\<tau> \\<sigma> i + m\" and s=\\<sigma> and i=\"Suc i\"]\n    by atomize_elim (auto simp add: less_eq_Suc_le memR_antimono)\n  from Until.prems obtain P1 j1 where P1: \"dom P1 = S\" \"range_mapping (Suc i') j1 P1\" \"Suc i' \\<le> progress \\<sigma> P1 \\<phi>1 j1\"\n    by (atomize_elim, intro Until(1)) (auto simp: pred_mapping_alt dom_def)\n  from Until.prems obtain P2 j2 where P2: \"dom P2 = S\" \"range_mapping (Suc i') j2 P2\" \"Suc i' \\<le> progress \\<sigma> P2 \\<phi>2 j2\"\n    by (atomize_elim, intro Until(2)) (auto simp: pred_mapping_alt dom_def)\n  let ?P12 = \"max_mapping P1 P2\"\n  have \"i \\<le> progress \\<sigma> ?P12 (Formula.Until \\<phi>1 I \\<phi>2) (max j1 j2)\"\n    unfolding progress.simps\n  proof (intro cInf_greatest, goal_cases nonempty greatest)\n    case nonempty\n    then show ?case\n      by (auto simp: trans_le_add1[OF \\<tau>_mono] intro!: exI[of _ \"max j1 j2\"])\n  next\n    case (greatest x)\n    from P1(2,3) have \"i' < j1\"\n      by (auto simp: less_eq_Suc_le intro!: progress_le_gen elim!: order.trans pred_mapping_mono_strong)\n    then have \"i' < max j1 j2\" by simp\n    have \"progress \\<sigma> P1 \\<phi>1 j1 \\<le> progress \\<sigma> ?P12 \\<phi>1 (max j1 j2)\"\n      using P1(1) P2(1) by (auto intro!: progress_mono_gen max_mapping_cobounded1)\n    moreover have \"progress \\<sigma> P2 \\<phi>2 j2 \\<le> progress \\<sigma> ?P12 \\<phi>2 (max j1 j2)\"\n      using P1(1) P2(1) by (auto intro!: progress_mono_gen max_mapping_cobounded2)\n    ultimately have \"i' \\<le> min (progress \\<sigma> ?P12 \\<phi>1 (max j1 j2)) (progress \\<sigma> ?P12 \\<phi>2 (max j1 j2))\"\n      using P1(3) P2(3) by simp\n    with greatest \\<open>i' < max j1 j2\\<close> have \"memR I (\\<tau> \\<sigma> i' - \\<tau> \\<sigma> x)\"\n      by simp\n    with 1 have \"\\<tau> \\<sigma> i < \\<tau> \\<sigma> x\"\n      by (auto 0 3 elim: contrapos_np)\n    then show ?case by (auto dest!: less_\\<tau>D)\n  qed\n  with P1 P2 \\<open>i < i'\\<close> show ?case\n    by (intro exI[of _ \"max_mapping P1 P2\"] exI[of _ \"max j1 j2\"]) (auto simp: range_mapping_relax)\nnext\n  case (MatchP I r)\n  then show ?case\n  proof (cases \"regex.atms r = {}\")\n    case True\n    with MatchP.prems show ?thesis\n      unfolding progress.simps\n      by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some i else None\"] exI[of _ i])\n        (auto split: if_splits simp: pred_mapping_alt regex.pred_set)\n  next\n    case False\n    define pick where \"pick = (\\<lambda>\\<phi>. SOME Pj. dom (fst Pj) = S \\<and> range_mapping i (snd Pj) (fst Pj) \\<and>\n       i \\<le> progress \\<sigma> (fst Pj) \\<phi> (snd Pj))\"\n    let ?pickP = \"fst o pick\" let ?pickj = \"snd o pick\"\n    from MatchP have pick: \"\\<phi> \\<in> regex.atms r \\<Longrightarrow> dom (?pickP \\<phi>) = S \\<and>\n      range_mapping i (?pickj \\<phi>) (?pickP \\<phi>) \\<and> i \\<le> progress \\<sigma> (?pickP \\<phi>) \\<phi> (?pickj \\<phi>)\" for \\<phi>\n      unfolding pick_def o_def future_bounded.simps regex.pred_set\n      by (intro someI_ex[where P = \"\\<lambda>Pj. dom (fst Pj) = S \\<and> range_mapping i (snd Pj) (fst Pj) \\<and>\n         i \\<le> progress \\<sigma> (fst Pj) \\<phi> (snd Pj)\"]) auto\n    with False show ?thesis\n      unfolding progress.simps\n      by (intro exI[of _ \"Max_mapping (?pickP ` regex.atms r)\"] exI[of _ \"Max (?pickj ` regex.atms r)\"])\n        (auto simp: Max_mapping_coboundedI\n          order_trans[OF pick[THEN conjunct2, THEN conjunct2] progress_mono_gen])\n  qed\nnext\n  case (MatchF I r)\n  from MatchF.prems obtain m where \"\\<not> memR I m\"\n    by (auto simp: bounded_memR)\n  then obtain i' where \"i < i'\" and i': \"\\<not> memR I (\\<tau> \\<sigma> i' - \\<tau> \\<sigma> i)\"\n    using ex_le_\\<tau>[where x=\"\\<tau> \\<sigma> i + m\" and s=\\<sigma> and i=\"Suc i\"]\n    by atomize_elim (auto simp add: less_eq_Suc_le memR_antimono)\n  have ix: \"i \\<le> x\" if \"memR I (\\<tau> \\<sigma> i' - \\<tau> \\<sigma> x)\" for x\n    using i' less_\\<tau>D[of \\<sigma> i x] that by (auto 0 3 simp: diff_le_mono2 elim: contrapos_np)\n  show ?case\n  proof (cases \"regex.atms r = {}\")\n    case True\n    with MatchF.prems ix show ?thesis\n      unfolding progress.simps\n      by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some (Suc i') else None\"] exI[of _ \"Suc i'\"])\n        (auto split: if_splits simp: pred_mapping_alt regex.pred_set add.commute less_Suc_eq\n          intro!: cInf_greatest dest!: spec[of _ i'] less_imp_le[THEN \\<tau>_mono, of _ i' \\<sigma>])\n  next\n    case False\n    then obtain \\<phi> where \\<phi>: \"\\<phi> \\<in> regex.atms r\" by auto\n    define pick where \"pick = (\\<lambda>\\<phi>. SOME Pj. dom (fst Pj) = S \\<and> range_mapping (Suc i') (snd Pj) (fst Pj) \\<and>\n      Suc i' \\<le> progress \\<sigma> (fst Pj) \\<phi> (snd Pj))\"\n    define pickP where \"pickP = fst o pick\" define pickj where \"pickj = snd o pick\"\n    from MatchF have pick: \"\\<phi> \\<in> regex.atms r \\<Longrightarrow> dom (pickP \\<phi>) = S \\<and>\n    range_mapping (Suc i') (pickj \\<phi>) (pickP \\<phi>) \\<and> Suc i' \\<le> progress \\<sigma> (pickP \\<phi>) \\<phi> (pickj \\<phi>)\" for \\<phi>\n      unfolding pick_def o_def future_bounded.simps regex.pred_set pickj_def pickP_def\n      by (intro someI_ex[where P = \"\\<lambda>Pj. dom (fst Pj) = S \\<and> range_mapping (Suc i') (snd Pj) (fst Pj) \\<and>\n       Suc i' \\<le> progress \\<sigma> (fst Pj) \\<phi> (snd Pj)\"]) auto\n    let ?P = \"Max_mapping (pickP ` regex.atms r)\" let ?j = \"Max (pickj ` regex.atms r)\"\n    from pick[OF \\<phi>] False \\<phi> have \"Suc i' \\<le> ?j\"\n      by (intro order_trans[OF pick[THEN conjunct2, THEN conjunct2], OF \\<phi>] order_trans[OF progress_le_gen])\n        (auto simp: Max_ge_iff dest: range_mapping_relax[of _ _ _ 0, OF _ _ order_refl, simplified])\n    moreover\n    note i' ix\n    moreover\n    from MatchF.prems have \"Regex.pred_regex Formula.future_bounded r\"\n      by auto\n    ultimately show ?thesis using \\<tau>_mono[of _ ?j \\<sigma>] less_\\<tau>D[of \\<sigma> i] pick False\n      by (intro exI[of _ \"?j\"]  exI[of _ \"?P\"])\n        (auto 0 3 intro!: cInf_greatest\n          order_trans[OF le_SucI[OF order_refl] order_trans[OF pick[THEN conjunct2, THEN conjunct2] progress_mono_gen]]\n          range_mapping_Max_mapping[OF _ _ ballI[OF range_mapping_relax[of \"Suc i'\" _ _ i, OF _ _ order_refl]]]\n          simp: ac_simps Suc_le_eq trans_le_add2 Max_mapping_coboundedI progress_regex_def\n          dest: spec[of _ \"i'\"] spec[of _ ?j])\n  qed\nqed (auto split: option.splits)\n\nlemma progress_ge: \"Formula.future_bounded \\<phi> \\<Longrightarrow> \\<exists>j. i \\<le> progress \\<sigma> Map.empty \\<phi> j\"\n  using progress_ge_gen[of \\<phi> \"{}\" i \\<sigma>]\n  by auto\n\n\n\nlemma progress_time_conv:\n  assumes \"\\<forall>i<j. \\<tau> \\<sigma> i = \\<tau> \\<sigma>' i\"\n  shows \"progress \\<sigma> P \\<phi> j = progress \\<sigma>' P \\<phi> j\"\n  using assms proof (induction \\<phi> arbitrary: P)\n  case (Until \\<phi>1 I \\<phi>2)\n  have *: \"i \\<le> j - 1 \\<longleftrightarrow> i < j\" if \"j \\<noteq> 0\" for i\n    using that by auto\n  with Until show ?case\n  proof (cases \"bounded I\")\n    case True\n    then show ?thesis\n    proof (cases \"j\")\n      case (Suc n)\n      with * Until show ?thesis\n        using \\<tau>_mono[THEN trans_le_add1]\n        by (auto 6 0\n            intro!: box_equals[OF arg_cong[where f=Inf]\n              cInf_restrict_nat[symmetric, where x=n] cInf_restrict_nat[symmetric, where x=n]])\n    qed simp\n  qed (simp add: bounded_memR)\nnext\n  case (MatchF I r)\n  have *: \"i \\<le> j - 1 \\<longleftrightarrow> i < j\" if \"j \\<noteq> 0\" for i\n    using that by auto\n  with MatchF show ?case using \\<tau>_mono[THEN trans_le_add1]\n    by (cases \"bounded I\"; cases j)\n      ((auto 6 0 simp: progress_le_gen progress_regex_def intro!: box_equals[OF arg_cong[where f=Inf]\n            cInf_restrict_nat[symmetric, where x=\"j-1\"] cInf_restrict_nat[symmetric, where x=\"j-1\"]]) [])+\nqed (auto simp: progress_regex_def)\n\nlemma Inf_UNIV_nat: \"(Inf UNIV :: nat) = 0\"\n  by (simp add: cInf_eq_minimum)\n\nlemma progress_prefix_conv:\n  assumes \"prefix_of \\<pi> \\<sigma>\" and \"prefix_of \\<pi> \\<sigma>'\"\n  shows \"progress \\<sigma> P \\<phi> (plen \\<pi>) = progress \\<sigma>' P \\<phi> (plen \\<pi>)\"\n  using assms by (auto intro: progress_time_conv \\<tau>_prefix_conv)\n\nlemma bounded_rtranclp_mono:\n  fixes n :: \"'x :: linorder\"\n  assumes \"\\<And>i j. R i j \\<Longrightarrow> j < n \\<Longrightarrow> S i j\" \"\\<And>i j. R i j \\<Longrightarrow> i \\<le> j\"\n  shows \"rtranclp R i j \\<Longrightarrow> j < n \\<Longrightarrow> rtranclp S i j\"\nproof (induct rule: rtranclp_induct)\n  case (step y z)\n  then show ?case\n    using assms(1,2)[of y z]\n    by (auto elim!: rtrancl_into_rtrancl[to_pred, rotated])\nqed auto\n\nlemma sat_prefix_conv_gen:\n  assumes \"prefix_of \\<pi> \\<sigma>\" and \"prefix_of \\<pi> \\<sigma>'\"\n  shows \"i < progress \\<sigma> P \\<phi> (plen \\<pi>) \\<Longrightarrow> dom V = dom V' \\<Longrightarrow> dom P = dom V \\<Longrightarrow>\n    pred_mapping (\\<lambda>x. x \\<le> plen \\<pi>) P \\<Longrightarrow>\n    (\\<And>p i \\<phi>. p \\<in> dom V \\<Longrightarrow> i < the (P p) \\<Longrightarrow> the (V p) i = the (V' p) i) \\<Longrightarrow>\n    Formula.sat \\<sigma> V v i \\<phi> \\<longleftrightarrow> Formula.sat \\<sigma>' V' v i \\<phi>\"\nproof (induction \\<phi> arbitrary: P V V' v i)\n  case (Pred e ts)\n  from Pred.prems(1,4) have \"i < plen \\<pi>\"\n    by (blast intro!: order.strict_trans2 progress_le_gen)\n  show ?case proof (cases \"V e\")\n    case None\n    then have \"V' e = None\" using \\<open>dom V = dom V'\\<close> by auto\n    with None \\<Gamma>_prefix_conv[OF assms(1,2) \\<open>i < plen \\<pi>\\<close>] show ?thesis by simp\n  next\n    case (Some a)\n    obtain a' where \"V' e = Some a'\" using Some \\<open>dom V = dom V'\\<close> by auto\n    then have \"i < the (P e)\"\n      using Pred.prems(1-3) by (auto split: option.splits)\n    then have \"the (V e) i = the (V' e) i\"\n      using Some by (intro Pred.prems(5)) (simp_all add: domI)\n    with Some \\<open>V' e = Some a'\\<close> show ?thesis by simp\n  qed\nnext\n  case (Let p \\<phi> \\<psi>)\n  let ?V = \"\\<lambda>V \\<sigma>. (V(p \\<mapsto> \\<lambda>i. {v. length v = Formula.nfv \\<phi> \\<and> Formula.sat \\<sigma> V v i \\<phi>}))\"\n  show ?case unfolding sat.simps proof (rule Let.IH(2))\n    from Let.prems show \"i < progress \\<sigma> (P(p \\<mapsto> progress \\<sigma> P \\<phi> (plen \\<pi>))) \\<psi> (plen \\<pi>)\"\n      by simp\n    from Let.prems show \"dom (?V V \\<sigma>) = dom (?V V' \\<sigma>')\"\n      by simp\n    from Let.prems show \"dom (P(p \\<mapsto> progress \\<sigma> P \\<phi> (plen \\<pi>))) = dom (?V V \\<sigma>)\"\n      by simp\n    from Let.prems show \"pred_mapping (\\<lambda>x. x \\<le> plen \\<pi>) (P(p \\<mapsto> progress \\<sigma> P \\<phi> (plen \\<pi>)))\"\n      by (auto intro!: pred_mapping_map_upd elim!: progress_le_gen)\n  next\n    fix p' i \\<phi>'\n    assume 1: \"p' \\<in> dom (?V V \\<sigma>)\" and 2: \"i < the ((P(p \\<mapsto> progress \\<sigma> P \\<phi> (plen \\<pi>))) p')\"\n    show \"the (?V V \\<sigma> p') i = the (?V V' \\<sigma>' p') i\" proof (cases \"p' = p\")\n      case True\n      with Let 2 show ?thesis by auto\n    next\n      case False\n      with 1 2 show ?thesis by (auto intro!: Let.prems(5))\n    qed\n  qed\nnext\n  case (Eq t1 t2)\n  show ?case by simp\nnext\n  case (Neg \\<phi>)\n  then show ?case by simp\nnext\n  case (Or \\<phi>1 \\<phi>2)\n  then show ?case by auto\nnext\n  case (Ands l)\n  from Ands.prems have \"\\<forall>\\<phi>\\<in>set l. i < progress \\<sigma> P \\<phi> (plen \\<pi>)\"\n    by (cases l) simp_all\n  with Ands show ?case unfolding sat_Ands by blast\nnext\n  case (Exists \\<phi>)\n  then show ?case by simp\nnext\n  case (Prev I \\<phi>)\n  with \\<tau>_prefix_conv[OF assms(1,2)] show ?case\n    by (cases i) (auto split: if_splits)\nnext\n  case (Next I \\<phi>)\n  then have \"Suc i < plen \\<pi>\"\n    by (auto intro: order.strict_trans2[OF _ progress_le_gen[of _ P \\<sigma> \\<phi>]])\n  with Next.prems \\<tau>_prefix_conv[OF assms(1,2)] show ?case\n    unfolding sat.simps\n    by (intro conj_cong Next) auto\nnext\n  case (Since \\<phi>1 I \\<phi>2)\n  then have \"i < plen \\<pi>\"\n    by (auto elim!: order.strict_trans2[OF _ progress_le_gen])\n  with Since.prems \\<tau>_prefix_conv[OF assms(1,2)] show ?case\n    unfolding sat.simps\n    by (intro conj_cong ex_cong ball_cong Since) auto\nnext\n  case (Until \\<phi>1 I \\<phi>2)\n  from Until.prems have [simp]: \"bounded I\"\n    by (cases \"bounded I\") (auto simp: bounded_memR Inf_UNIV_nat)\n  from Until.prems obtain j where \"\\<not> memR I (\\<tau> \\<sigma> j - \\<tau> \\<sigma> i)\"\n    \"j \\<le> progress \\<sigma> P \\<phi>1 (plen \\<pi>)\" \"j \\<le> progress \\<sigma> P \\<phi>2 (plen \\<pi>)\"\n    by atomize_elim (auto 0 4 simp add: less_eq_Suc_le not_le intro: Suc_leI dest: spec[of _ \"i\"]\n      dest!: le_cInf_iff[THEN iffD1, rotated -1])\n  then have 1: \"k < progress \\<sigma> P \\<phi>1 (plen \\<pi>)\" and 2: \"k < progress \\<sigma> P \\<phi>2 (plen \\<pi>)\"\n    if \"memR I (\\<tau> \\<sigma> k - \\<tau> \\<sigma> i)\" for k\n    using that\n    by (auto 0 3 elim!: order.strict_trans2[rotated] elim: contrapos_np intro!: less_\\<tau>D[of \\<sigma> k j])\n  have 3: \"k < plen \\<pi>\" if \"memR I (\\<tau> \\<sigma> k - \\<tau> \\<sigma> i)\" for k\n    using 1[OF that] Until(6) by (auto simp only: less_eq_Suc_le order.trans[OF _ progress_le_gen])\n\n  from Until.prems have \"i < progress \\<sigma>' P (Formula.Until \\<phi>1 I \\<phi>2) (plen \\<pi>)\"\n    unfolding progress_prefix_conv[OF assms(1,2)] by simp\n  then obtain j where \"\\<not> memR I (\\<tau> \\<sigma>' j - \\<tau> \\<sigma>' i)\"\n    \"j \\<le> progress \\<sigma>' P \\<phi>1 (plen \\<pi>)\" \"j \\<le> progress \\<sigma>' P \\<phi>2 (plen \\<pi>)\"\n    by atomize_elim (auto 0 4 simp add: less_eq_Suc_le not_le intro: Suc_leI dest: spec[of _ \"i\"]\n      dest!: le_cInf_iff[THEN iffD1, rotated -1])\n  then have 11: \"k < progress \\<sigma> P \\<phi>1 (plen \\<pi>)\" and 21: \"k < progress \\<sigma> P \\<phi>2 (plen \\<pi>)\"\n    if \"memR I (\\<tau> \\<sigma>' k - \\<tau> \\<sigma>' i)\" for k\n    unfolding progress_prefix_conv[OF assms(1,2)]\n    using that\n    by (auto 0 3 elim!: order.strict_trans2[rotated] elim: contrapos_np intro!: less_\\<tau>D[of \\<sigma>' k j])\n  have 31: \"k < plen \\<pi>\" if \"memR I (\\<tau> \\<sigma>' k - \\<tau> \\<sigma>' i)\" for k\n    using 11[OF that] Until(6) by (auto simp only: less_eq_Suc_le order.trans[OF _ progress_le_gen])\n  thm order.trans[OF _ progress_le_gen]\n\n  show ?case unfolding sat.simps\n  proof ((intro ex_cong iffI; elim conjE), goal_cases LR RL)\n    case (LR j)\n    with Until.IH(1)[OF 1] Until.IH(2)[OF 2] \\<tau>_prefix_conv[OF assms(1,2) 3] Until.prems show ?case\n      by (auto 0 4 simp: le_diff_conv add.commute memR_antimono dest: less_imp_le order.trans[OF \\<tau>_mono, rotated])\n  next\n    case (RL j)\n    with Until.IH(1)[OF 11] Until.IH(2)[OF 21] \\<tau>_prefix_conv[OF assms(1,2) 31] Until.prems show ?case\n      by (auto 0 4 simp: le_diff_conv add.commute memR_antimono dest: less_imp_le order.trans[OF \\<tau>_mono, rotated])\n  qed\nnext\n  case (MatchP I r)\n  then have \"i < plen \\<pi>\"\n    by (force simp: pred_mapping_alt elim!: order.strict_trans2[OF _ progress_le_gen])\n  with MatchP.prems \\<tau>_prefix_conv[OF assms(1,2)] show ?case\n    unfolding sat.simps\n    by (intro ex_cong conj_cong match_cong_strong MatchP) (auto simp: progress_regex_def split: if_splits)\nnext\n  case (MatchF I r)\n  from MatchF.prems have [simp]: \"bounded I\"\n    by (cases \"bounded I\") (auto simp: bounded_memR Inf_UNIV_nat)\n  show ?case\n  proof (cases \"regex.atms r = {}\")\n    case True\n    from MatchF.prems(1) obtain j where \"\\<not> memR I (\\<tau> \\<sigma> j - \\<tau> \\<sigma> i)\" \"j \\<le> plen \\<pi>\"\n      by atomize_elim (auto 0 4 simp add: less_eq_Suc_le not_le dest!: le_cInf_iff[THEN iffD1, rotated -1])\n    then have 1: \"k < plen \\<pi>\" if \"memR I (\\<tau> \\<sigma> k - \\<tau> \\<sigma> i)\" for k\n      by (meson \\<tau>_mono diff_le_mono memR_antimono not_le_imp_less that)\n    from MatchF.prems have \"i < progress \\<sigma>' P (Formula.MatchF I r) (plen \\<pi>)\"\n      unfolding progress_prefix_conv[OF assms(1,2)] by blast\n    then obtain j where \"\\<not> memR I (\\<tau> \\<sigma>' j - \\<tau> \\<sigma>' i)\" \"j \\<le> plen \\<pi>\"\n      by atomize_elim (auto 0 4 simp add: less_eq_Suc_le not_le dest!: le_cInf_iff[THEN iffD1, rotated -1])\n    then have 2: \"k < plen \\<pi>\" if \"memR I (\\<tau> \\<sigma>' k - \\<tau> \\<sigma>' i)\" for k\n      by (meson \\<tau>_mono diff_le_mono memR_antimono not_le_imp_less that)\n    from MatchF.prems(1,4) True show ?thesis\n      unfolding sat.simps conj_commute[of \"memL _ _\"]\n    proof (intro ex_cong conj_cong match_cong_strong, goal_cases memL memR sat)\n      case (memL j)\n      then show ?case\n        by (intro iffI)\n          ((subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 1, symmetric]; auto elim: order.trans[OF \\<tau>_mono, rotated]),\n            (subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 2]; auto elim: order.trans[OF \\<tau>_mono, rotated]))\n    next\n      case (memR j)\n      then show ?case\n        by (intro iffI)\n          ((subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 2, symmetric]; auto elim: order.trans[OF \\<tau>_mono, rotated]),\n            (subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 2]; auto elim: order.trans[OF \\<tau>_mono, rotated]))\n    qed auto\n  next\n    case False\n    from MatchF.prems(1) False obtain j where \"\\<not> memR I (\\<tau> \\<sigma> j - \\<tau> \\<sigma> i)\" \"(\\<forall>x\\<in>regex.atms r. j \\<le> progress \\<sigma> P x (plen \\<pi>))\"\n      by atomize_elim (auto 0 6 simp add: less_eq_Suc_le not_le progress_regex_def\n        dest!: le_cInf_iff[THEN iffD1, rotated -1])\n    then have 1: \"\\<phi> \\<in> regex.atms r \\<Longrightarrow> k < progress \\<sigma> P \\<phi> (plen \\<pi>)\" if \"memR I (\\<tau> \\<sigma> k - \\<tau> \\<sigma> i)\" for k \\<phi>\n      using that\n      by (auto 0 3 elim!: contrapos_np[of _ \"_ < _\"] simp: diff_le_mono)\n    then have 2: \"k < plen \\<pi>\" if \"memR I (\\<tau> \\<sigma> k - \\<tau> \\<sigma> i)\" \"regex.atms r \\<noteq> {}\" for k\n      using that\n      by (fastforce intro: order.strict_trans2[OF _ progress_le_gen[OF MatchF(5), of \\<sigma>], of k])\n\n    from MatchF.prems have \"i < progress \\<sigma>' P (Formula.MatchF I r) (plen \\<pi>)\"\n      unfolding progress_prefix_conv[OF assms(1,2)] by blast\n    with False obtain j where \"\\<not> memR I (\\<tau> \\<sigma>' j - \\<tau> \\<sigma>' i)\" \"(\\<forall>x\\<in>regex.atms r. j \\<le> progress \\<sigma>' P x (plen \\<pi>))\"\n      by atomize_elim (auto 0 6 simp add: less_eq_Suc_le not_le progress_regex_def\n        dest!: le_cInf_iff[THEN iffD1, rotated -1])\n    then have 11:  \"\\<phi> \\<in> regex.atms r \\<Longrightarrow> k < progress \\<sigma> P \\<phi> (plen \\<pi>)\" if \"memR I (\\<tau> \\<sigma>' k - \\<tau> \\<sigma>' i)\" for k \\<phi>\n      using that using progress_prefix_conv[OF assms(1,2)]\n      by (auto 0 3 elim!: contrapos_np[of _ \"_ < _\"] simp: diff_le_mono)\n    have 21: \"k < plen \\<pi>\" if \"memR I (\\<tau> \\<sigma>' k - \\<tau> \\<sigma>' i)\" for k\n      using 11[OF that(1)] False by (fastforce intro: order.strict_trans2[OF _ progress_le_gen[OF MatchF(5), of \\<sigma>], of k])\n    show ?thesis unfolding sat.simps conj_commute[of \"memL _ _\"]\n    proof ((intro ex_cong conj_cong match_cong_strong MatchF(1)[OF _ _ MatchF(3-6)]; assumption?), goal_cases memR memL progress)\n      case (memR j)\n      with False show ?case\n        by (intro iffI)\n          ((subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 2, symmetric]; auto elim: order.trans[OF \\<tau>_mono, rotated]),\n            (subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 21]; auto elim: order.trans[OF \\<tau>_mono, rotated]))\n    next\n      case (memL j)\n      with False show ?case\n        by (intro iffI)\n          ((subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 21, symmetric]; auto elim: order.trans[OF \\<tau>_mono, rotated]),\n            (subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 21]; auto elim: order.trans[OF \\<tau>_mono, rotated]))\n    next\n      case (progress j k z)\n      with False show ?case\n        by (elim 1[rotated])\n          (subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 21]; auto simp: diff_le_mono memR_antimono elim!: contrapos_np[of _ False])\n    qed\n  qed\nqed auto\n\nlemma sat_prefix_conv:\n  assumes \"prefix_of \\<pi> \\<sigma>\" and \"prefix_of \\<pi> \\<sigma>'\"\n  shows \"i < progress \\<sigma> Map.empty \\<phi> (plen \\<pi>) \\<Longrightarrow>\n    Formula.sat \\<sigma> Map.empty v i \\<phi> \\<longleftrightarrow> Formula.sat \\<sigma>' Map.empty v i \\<phi>\"\n  by (erule sat_prefix_conv_gen[OF assms]) auto\n\nlemma progress_remove_neg[simp]: \"progress \\<sigma> P (remove_neg \\<phi>) j = progress \\<sigma> P \\<phi> j\"\n  by (cases \\<phi>) simp_all\n\nlemma safe_progress_get_and: \"safe_formula \\<phi> \\<Longrightarrow>\n  Min ((\\<lambda>\\<phi>. progress \\<sigma> P \\<phi> j) ` set (get_and_list \\<phi>)) = progress \\<sigma> P \\<phi> j\"\n  by (induction \\<phi> rule: get_and_list.induct) auto\n\nlemma progress_convert_multiway: \"safe_formula \\<phi> \\<Longrightarrow> progress \\<sigma> P (convert_multiway \\<phi>) j = progress \\<sigma> P \\<phi> j\"\nproof (induction \\<phi> arbitrary: P rule: safe_formula_induct)\n  case (And_safe \\<phi> \\<psi>)\n  let ?c = \"convert_multiway (Formula.And \\<phi> \\<psi>)\"\n  let ?c\\<phi> = \"convert_multiway \\<phi>\"\n  let ?c\\<psi> = \"convert_multiway \\<psi>\"\n  have c_eq: \"?c = Formula.Ands (get_and_list ?c\\<phi> @ get_and_list ?c\\<psi>)\"\n    using And_safe by simp\n  from \\<open>safe_formula \\<phi>\\<close> have \"safe_formula ?c\\<phi>\" by (rule safe_convert_multiway)\n  moreover from \\<open>safe_formula \\<psi>\\<close> have \"safe_formula ?c\\<psi>\" by (rule safe_convert_multiway)\n  ultimately show ?case\n    unfolding c_eq\n    using And_safe.IH\n    by (auto simp: get_and_nonempty Min.union safe_progress_get_and)\nnext\n  case (And_Not \\<phi> \\<psi>)\n  let ?c = \"convert_multiway (Formula.And \\<phi> (Formula.Neg \\<psi>))\"\n  let ?c\\<phi> = \"convert_multiway \\<phi>\"\n  let ?c\\<psi> = \"convert_multiway \\<psi>\"\n  have c_eq: \"?c = Formula.Ands (Formula.Neg ?c\\<psi> # get_and_list ?c\\<phi>)\"\n    using And_Not by simp\n  from \\<open>safe_formula \\<phi>\\<close> have \"safe_formula ?c\\<phi>\" by (rule safe_convert_multiway)\n  moreover from \\<open>safe_formula \\<psi>\\<close> have \"safe_formula ?c\\<psi>\" by (rule safe_convert_multiway)\n  ultimately show ?case\n    unfolding c_eq\n    using And_Not.IH\n    by (auto simp: get_and_nonempty Min.union safe_progress_get_and)\nnext\n  case (Ands l)\n  then show ?case\n    unfolding progress.simps convert_multiway.simps\n    by (force simp: list.pred_set convert_multiway_remove_neg intro!: Sup.SUP_cong)\nnext\n  case (MatchP I r)\n  from MatchP show ?case\n    unfolding progress.simps regex.map convert_multiway.simps regex.set_map image_image\n    by (intro if_cong arg_cong[of _ _ Min] image_cong)\n      (auto 0 4 simp: atms_def elim!: disjE_Not2 dest: safe_regex_safe_formula)\nnext\n  case (MatchF I r)\n  from MatchF show ?case\n    unfolding progress.simps regex.map convert_multiway.simps regex.set_map image_image\n    by (intro if_cong arg_cong[of _ _ Min] arg_cong[of _ _ Inf] arg_cong[of _ _ \"(\\<le>) _\"]\n      image_cong Collect_cong all_cong1 imp_cong conj_cong image_cong)\n      (auto 0 4 simp: atms_def elim!: disjE_Not2 dest: safe_regex_safe_formula)\nqed auto\n\n\nsubsection \\<open>Specification\\<close>\n\ndefinition pprogress :: \"Formula.formula \\<Rightarrow> Formula.prefix \\<Rightarrow> nat\" where\n  \"pprogress \\<phi> \\<pi> = (THE n. \\<forall>\\<sigma>. prefix_of \\<pi> \\<sigma> \\<longrightarrow> progress \\<sigma> Map.empty \\<phi> (plen \\<pi>) = n)\"\n\nlemma pprogress_eq: \"prefix_of \\<pi> \\<sigma> \\<Longrightarrow> pprogress \\<phi> \\<pi> = progress \\<sigma> Map.empty \\<phi> (plen \\<pi>)\"\n  unfolding pprogress_def using progress_prefix_conv\n  by blast\n\nlocale future_bounded_mfodl =\n  fixes \\<phi> :: Formula.formula\n  assumes future_bounded: \"Formula.future_bounded \\<phi>\"\n\nsublocale future_bounded_mfodl \\<subseteq> sliceable_timed_progress \"Formula.nfv \\<phi>\" \"Formula.fv \\<phi>\" \"relevant_events \\<phi>\"\n  \"\\<lambda>\\<sigma> v i. Formula.sat \\<sigma> Map.empty v i \\<phi>\" \"pprogress \\<phi>\"\nproof (unfold_locales, goal_cases)\n  case (1 x)\n  then show ?case by (simp add: fvi_less_nfv)\nnext\n  case (2 v v' \\<sigma> i)\n  then show ?case by (simp cong: sat_fv_cong[rule_format])\nnext\n  case (3 v S \\<sigma> i)\n  then show ?case\n    using sat_slice_iff[symmetric] by simp\nnext\n  case (4 \\<pi> \\<pi>')\n  moreover obtain \\<sigma> where \"prefix_of \\<pi>' \\<sigma>\"\n    using ex_prefix_of ..\n  moreover have \"prefix_of \\<pi> \\<sigma>\"\n    using prefix_of_antimono[OF \\<open>\\<pi> \\<le> \\<pi>'\\<close> \\<open>prefix_of \\<pi>' \\<sigma>\\<close>] .\n  ultimately show ?case\n    by (simp add: pprogress_eq plen_mono progress_mono)\nnext\n  case (5 \\<sigma> x)\n  obtain j where \"x \\<le> progress \\<sigma> Map.empty \\<phi> j\"\n    using future_bounded progress_ge by blast\n  then have \"x \\<le> pprogress \\<phi> (take_prefix j \\<sigma>)\"\n    by (simp add: pprogress_eq[of _ \\<sigma>])\n  then show ?case by force\nnext\n  case (6 \\<pi> \\<sigma> \\<sigma>' i v)\n  then have \"i < progress \\<sigma> Map.empty \\<phi> (plen \\<pi>)\"\n    by (simp add: pprogress_eq)\n  with 6 show ?case\n    using sat_prefix_conv by blast\nnext\n  case (7 \\<pi> \\<pi>')\n  then have \"plen \\<pi> = plen \\<pi>'\"\n    by transfer (simp add: list_eq_iff_nth_eq)\n  moreover obtain \\<sigma> \\<sigma>' where \"prefix_of \\<pi> \\<sigma>\" \"prefix_of \\<pi>' \\<sigma>'\"\n    using ex_prefix_of by blast+\n  moreover have \"\\<forall>i < plen \\<pi>. \\<tau> \\<sigma> i = \\<tau> \\<sigma>' i\"\n    using 7 calculation\n    by transfer (simp add: list_eq_iff_nth_eq)\n  ultimately show ?case\n    by (simp add: pprogress_eq progress_time_conv)\nqed\n\nlocale verimon_spec =\n  fixes \\<phi> :: Formula.formula\n  assumes monitorable: \"mmonitorable \\<phi>\"\n\nsublocale verimon_spec \\<subseteq> future_bounded_mfodl\n  using monitorable by unfold_locales (simp add: mmonitorable_def)\n\n\nsubsection \\<open>Correctness\\<close>\n\nsubsubsection \\<open>Invariants\\<close>\n\ndefinition wf_mbuf2 :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> (nat \\<Rightarrow> event_data table \\<Rightarrow> bool) \\<Rightarrow> (nat \\<Rightarrow> event_data table \\<Rightarrow> bool) \\<Rightarrow>\n    event_data mbuf2 \\<Rightarrow> bool\" where\n  \"wf_mbuf2 i ja jb P Q buf \\<longleftrightarrow> i \\<le> ja \\<and> i \\<le> jb \\<and> (case buf of (xs, ys) \\<Rightarrow>\n    list_all2 P [i..<ja] xs \\<and> list_all2 Q [i..<jb] ys)\"\n\ninductive list_all3 :: \"('a \\<Rightarrow> 'b \\<Rightarrow> 'c \\<Rightarrow> bool) \\<Rightarrow> 'a list \\<Rightarrow> 'b list \\<Rightarrow> 'c list \\<Rightarrow> bool\" for P :: \"('a \\<Rightarrow> 'b \\<Rightarrow> 'c \\<Rightarrow> bool)\" where\n  \"list_all3 P [] [] []\"\n| \"P a1 a2 a3 \\<Longrightarrow> list_all3 P q1 q2 q3 \\<Longrightarrow> list_all3 P (a1 # q1) (a2 # q2) (a3 # q3)\"\n\nlemma list_all3_list_all2D: \"list_all3 P xs ys zs \\<Longrightarrow>\n  (length xs = length ys \\<and> list_all2 (case_prod P) (zip xs ys) zs)\"\n  by (induct xs ys zs rule: list_all3.induct) auto\n\nlemma list_all2_list_all3I: \"length xs = length ys \\<Longrightarrow> list_all2 (case_prod P) (zip xs ys) zs \\<Longrightarrow>\n  list_all3 P xs ys zs\"\n  by (induct xs ys arbitrary: zs rule: list_induct2)\n    (auto simp: list_all2_Cons1 intro: list_all3.intros)\n\nlemma list_all3_list_all2_eq: \"list_all3 P xs ys zs \\<longleftrightarrow>\n  (length xs = length ys \\<and> list_all2 (case_prod P) (zip xs ys) zs)\"\n  using list_all2_list_all3I list_all3_list_all2D by blast\n\nlemma list_all3_mapD: \"list_all3 P (map f xs) (map g ys) (map h zs) \\<Longrightarrow>\n  list_all3 (\\<lambda>x y z. P (f x) (g y) (h z)) xs ys zs\"\n  by (induct \"map f xs\" \"map g ys\" \"map h zs\" arbitrary: xs ys zs rule: list_all3.induct)\n    (auto intro: list_all3.intros)\n\nlemma list_all3_mapI: \"list_all3 (\\<lambda>x y z. P (f x) (g y) (h z)) xs ys zs \\<Longrightarrow>\n  list_all3 P (map f xs) (map g ys) (map h zs)\"\n  by (induct xs ys zs rule: list_all3.induct)\n    (auto intro: list_all3.intros)\n\nlemma list_all3_map_iff: \"list_all3 P (map f xs) (map g ys) (map h zs) \\<longleftrightarrow>\n  list_all3 (\\<lambda>x y z. P (f x) (g y) (h z)) xs ys zs\"\n  using list_all3_mapD list_all3_mapI by blast\n\nlemmas list_all3_map =\n  list_all3_map_iff[where g=id and h=id, unfolded list.map_id id_apply]\n  list_all3_map_iff[where f=id and h=id, unfolded list.map_id id_apply]\n  list_all3_map_iff[where f=id and g=id, unfolded list.map_id id_apply]\n\nlemma list_all3_conv_all_nth:\n  \"list_all3 P xs ys zs =\n  (length xs = length ys \\<and> length ys = length zs \\<and> (\\<forall>i < length xs. P (xs!i) (ys!i) (zs!i)))\"\n  by (auto simp add: list_all3_list_all2_eq list_all2_conv_all_nth)\n\nlemma list_all3_refl [intro?]:\n  \"(\\<And>x. x \\<in> set xs \\<Longrightarrow> P x x x) \\<Longrightarrow> list_all3 P xs xs xs\"\n  by (simp add: list_all3_conv_all_nth)\n\ndefinition wf_mbufn :: \"nat \\<Rightarrow> nat list \\<Rightarrow> (nat \\<Rightarrow> event_data table \\<Rightarrow> bool) list \\<Rightarrow> event_data mbufn \\<Rightarrow> bool\" where\n  \"wf_mbufn i js Ps buf \\<longleftrightarrow> list_all3 (\\<lambda>P j xs. i \\<le> j \\<and> list_all2 P [i..<j] xs) Ps js buf\"\n\ndefinition wf_mbuf2' :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> event_data list set \\<Rightarrow>\n  Formula.formula \\<Rightarrow> Formula.formula \\<Rightarrow> event_data mbuf2 \\<Rightarrow> bool\" where\n  \"wf_mbuf2' \\<sigma> P V j n R \\<phi> \\<psi> buf \\<longleftrightarrow> wf_mbuf2 (min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j))\n    (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)\n    (\\<lambda>i. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>))\n    (\\<lambda>i. qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>)) buf\"\n\ndefinition wf_mbufn' :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> event_data list set \\<Rightarrow>\n  Formula.formula Regex.regex \\<Rightarrow> event_data mbufn \\<Rightarrow> bool\" where\n  \"wf_mbufn' \\<sigma>  P V j n R r buf \\<longleftrightarrow> (case to_mregex r of (mr, \\<phi>s) \\<Rightarrow>\n    wf_mbufn (progress_regex \\<sigma> P r j) (map (\\<lambda>\\<phi>. progress \\<sigma> P \\<phi> j) \\<phi>s)\n    (map (\\<lambda>\\<phi> i. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>)) \\<phi>s)\n    buf)\"\n\nlemma wf_mbuf2'_UNIV_alt: \"wf_mbuf2' \\<sigma> P V j n UNIV \\<phi> \\<psi> buf \\<longleftrightarrow> (case buf of (xs, ys) \\<Rightarrow>\n  list_all2 (\\<lambda>i. wf_table n (Formula.fv \\<phi>) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>))\n    [min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j) ..< (progress \\<sigma> P \\<phi> j)] xs \\<and>\n  list_all2 (\\<lambda>i. wf_table n (Formula.fv \\<psi>) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>))\n    [min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j) ..< (progress \\<sigma> P \\<psi> j)] ys)\"\n  unfolding wf_mbuf2'_def wf_mbuf2_def\n  by (simp add: mem_restr_UNIV[THEN eqTrueI, abs_def] split: prod.split)\n\ndefinition wf_ts :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> Formula.formula \\<Rightarrow> Formula.formula \\<Rightarrow> ts list \\<Rightarrow> bool\" where\n  \"wf_ts \\<sigma> P j \\<phi> \\<psi> ts \\<longleftrightarrow> list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)..<j] ts\"\n\ndefinition wf_ts_regex :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> Formula.formula Regex.regex \\<Rightarrow> ts list \\<Rightarrow> bool\" where\n  \"wf_ts_regex \\<sigma> P j r ts \\<longleftrightarrow> list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [progress_regex \\<sigma> P r j..<j] ts\"\n\ndefinition \"Sincep pos \\<phi> I \\<psi> \\<equiv> Formula.Since (if pos then \\<phi> else Formula.Neg \\<phi>) I \\<psi>\"\n\ndefinition \"agg_b args = (case args_agg args of None \\<Rightarrow> 0           | Some aggargs \\<Rightarrow> aggargs_b aggargs)\"\ndefinition \"agg_n args = (case args_agg args of None \\<Rightarrow> args_n args | Some aggargs \\<Rightarrow> aggargs_n aggargs)\"\n\ndefinition (in msaux) wf_since_aux :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> event_data list set \\<Rightarrow> args \\<Rightarrow>\n  Formula.formula \\<Rightarrow> Formula.formula \\<Rightarrow> 'msaux \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"wf_since_aux \\<sigma> V R args \\<phi> \\<psi> aux ne \\<longleftrightarrow> Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi> \\<and>\n    valid_aggargs (args_n args) (Formula.fv \\<psi>) (args_agg args) \\<and> (\\<exists>cur auxlist. valid_msaux args cur aux auxlist \\<and>\n    cur = (if ne = 0 then 0 else \\<tau> \\<sigma> (ne - 1)) \\<and>\n    sorted_wrt (\\<lambda>x y. fst x > fst y) auxlist \\<and>\n    (\\<forall>t X. (t, X) \\<in> set auxlist \\<longrightarrow> ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne - 1) \\<and> memR (args_ivl args) (\\<tau> \\<sigma> (ne - 1) - t) \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      qtable (args_n args) (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne-1) (Sincep (args_pos args) \\<phi> (point (\\<tau> \\<sigma> (ne - 1) - t)) \\<psi>)) X) \\<and>\n    (\\<forall>t. ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne - 1) \\<and> memR (args_ivl args) (\\<tau> \\<sigma> (ne - 1) - t) \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<longrightarrow>\n      (\\<exists>X. (t, X) \\<in> set auxlist)))\"\n\ndefinition wf_matchP_aux :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> event_data list set \\<Rightarrow>\n    \\<I> \\<Rightarrow> Formula.formula Regex.regex \\<Rightarrow> event_data mr\\<delta>aux \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"wf_matchP_aux \\<sigma> V n R I r aux ne \\<longleftrightarrow> sorted_wrt (\\<lambda>x y. fst x > fst y) aux \\<and>\n    (\\<forall>t X. (t, X) \\<in> set aux \\<longrightarrow> ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne-1) \\<and> memR I (\\<tau> \\<sigma> (ne-1) - t) \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      (case to_mregex r of (mr, \\<phi>s) \\<Rightarrow>\n      (\\<forall>ms \\<in> RPDs mr. qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne-1)\n         (Formula.MatchP (point (\\<tau> \\<sigma> (ne-1) - t)) (from_mregex ms \\<phi>s)))\n         (lookup X ms)))) \\<and>\n    (\\<forall>t. ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne-1) \\<and> memR I (\\<tau> \\<sigma> (ne-1) - t) \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<longrightarrow>\n      (\\<exists>X. (t, X) \\<in> set aux))\"\n\nlemma qtable_mem_restr_UNIV: \"qtable n A(mem_restr UNIV) Q X = wf_table n A Q X\"\n  unfolding qtable_def by auto\n\nlemma (in msaux) wf_since_aux_UNIV_alt:\n  \"wf_since_aux \\<sigma> V UNIV args \\<phi> \\<psi> aux ne \\<longleftrightarrow> Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi> \\<and>\n    valid_aggargs (args_n args) (Formula.fv \\<psi>) (args_agg args) \\<and> (\\<exists>cur auxlist. valid_msaux args cur aux auxlist \\<and>\n    cur = (if ne = 0 then 0 else \\<tau> \\<sigma> (ne - 1)) \\<and>\n    sorted_wrt (\\<lambda>x y. fst x > fst y) auxlist \\<and>\n    (\\<forall>t X. (t, X) \\<in> set auxlist \\<longrightarrow> ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne - 1) \\<and> memR (args_ivl args) (\\<tau> \\<sigma> (ne - 1) - t) \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      wf_table (args_n args) (Formula.fv \\<psi>)\n          (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne - 1) (Sincep (args_pos args) \\<phi> (point (\\<tau> \\<sigma> (ne - 1) - t)) \\<psi>)) X) \\<and>\n    (\\<forall>t. ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne - 1) \\<and> memR (args_ivl args) (\\<tau> \\<sigma> (ne - 1) - t) \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<longrightarrow>\n      (\\<exists>X. (t, X) \\<in> set auxlist)))\"\n  unfolding wf_since_aux_def qtable_mem_restr_UNIV ..\n\ndefinition wf_until_auxlist :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> event_data list set \\<Rightarrow> bool \\<Rightarrow>\n    Formula.formula \\<Rightarrow> \\<I> \\<Rightarrow> Formula.formula \\<Rightarrow> event_data muaux \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> auxlist ne \\<longleftrightarrow>\n    list_all2 (\\<lambda>x i. case x of (t, r1, r2) \\<Rightarrow> t = \\<tau> \\<sigma> i \\<and>\n      qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. if pos then (\\<forall>k\\<in>{i..<ne+length auxlist}. Formula.sat \\<sigma> V (map the v) k \\<phi>)\n          else (\\<exists>k\\<in>{i..<ne+length auxlist}. Formula.sat \\<sigma> V (map the v) k \\<phi>)) r1 \\<and>\n      qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. (\\<exists>j. i \\<le> j \\<and> j < ne + length auxlist \\<and> mem I ((\\<tau> \\<sigma> j - \\<tau> \\<sigma> i)) \\<and>\n          Formula.sat \\<sigma> V (map the v) j \\<psi> \\<and>\n          (\\<forall>k\\<in>{i..<j}. if pos then Formula.sat \\<sigma> V (map the v) k \\<phi> else \\<not> Formula.sat \\<sigma> V (map the v) k \\<phi>))) r2)\n      auxlist [ne..<ne+length auxlist]\"\n\ndefinition (in muaux) wf_until_aux :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> event_data list set \\<Rightarrow> args \\<Rightarrow>\n  Formula.formula \\<Rightarrow> Formula.formula \\<Rightarrow> 'muaux \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"wf_until_aux \\<sigma> V R args \\<phi> \\<psi> aux ne \\<longleftrightarrow> Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi> \\<and>\n    valid_aggargs (args_n args) (Formula.fv \\<psi>) (args_agg args) \\<and>\n    (\\<exists>cur auxlist. valid_muaux args cur aux auxlist \\<and>\n      cur = (if ne + length auxlist = 0 then 0 else \\<tau> \\<sigma> (ne + length auxlist - 1)) \\<and>\n      wf_until_auxlist \\<sigma> V (args_n args) R (args_pos args) \\<phi> (args_ivl args) \\<psi> auxlist ne)\"\n\nlemma (in muaux) wf_until_aux_UNIV_alt:\n  \"wf_until_aux \\<sigma> V UNIV args \\<phi> \\<psi> aux ne \\<longleftrightarrow> Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi> \\<and>\n    valid_aggargs (args_n args) (Formula.fv \\<psi>) (args_agg args) \\<and>\n    (\\<exists>cur auxlist. valid_muaux args cur aux auxlist \\<and>\n      cur = (if ne + length auxlist = 0 then 0 else \\<tau> \\<sigma> (ne + length auxlist - 1)) \\<and>\n      list_all2 (\\<lambda>x i. case x of (t, r1, r2) \\<Rightarrow> t = \\<tau> \\<sigma> i \\<and>\n      wf_table (args_n args) (Formula.fv \\<phi>) (\\<lambda>v. if (args_pos args)\n          then (\\<forall>k\\<in>{i..<ne+length auxlist}. Formula.sat \\<sigma> V (map the v) k \\<phi>)\n          else (\\<exists>k\\<in>{i..<ne+length auxlist}. Formula.sat \\<sigma> V (map the v) k \\<phi>)) r1 \\<and>\n      wf_table (args_n args) (Formula.fv \\<psi>) (\\<lambda>v. \\<exists>j. i \\<le> j \\<and> j < ne + length auxlist \\<and> mem (args_ivl args) (\\<tau> \\<sigma> j - \\<tau> \\<sigma> i) \\<and>\n          Formula.sat \\<sigma> V (map the v) j \\<psi> \\<and>\n          (\\<forall>k\\<in>{i..<j}. if (args_pos args) then Formula.sat \\<sigma> V (map the v) k \\<phi> else \\<not> Formula.sat \\<sigma> V (map the v) k \\<phi>)) r2)\n      auxlist [ne..<ne+length auxlist])\"\n  unfolding wf_until_aux_def wf_until_auxlist_def qtable_mem_restr_UNIV ..\n\ndefinition wf_matchF_aux :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> event_data list set \\<Rightarrow>\n    \\<I> \\<Rightarrow> Formula.formula Regex.regex \\<Rightarrow> event_data ml\\<delta>aux \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"wf_matchF_aux \\<sigma> V n R I r aux ne k \\<longleftrightarrow> (case to_mregex r of (mr, \\<phi>s) \\<Rightarrow>\n      list_all2 (\\<lambda>x i. case x of (t, rels, rel) \\<Rightarrow> t = \\<tau> \\<sigma> i \\<and>\n        list_all2 (\\<lambda>\\<phi>. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v.\n          Formula.sat \\<sigma> V (map the v) i \\<phi>)) \\<phi>s rels \\<and>\n        qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v. (\\<exists>j. i \\<le> j \\<and> j < ne + length aux + k \\<and> mem I ((\\<tau> \\<sigma> j - \\<tau> \\<sigma> i)) \\<and>\n          Regex.match (Formula.sat \\<sigma> V (map the v)) r i j)) rel)\n    aux [ne..<ne+length aux])\"\n\ndefinition wf_matchF_invar where\n  \"wf_matchF_invar \\<sigma> V n R I r st i =\n     (case st of (aux, Y) \\<Rightarrow> aux \\<noteq> [] \\<and> wf_matchF_aux \\<sigma> V n R I r aux i 0 \\<and>\n     (case to_mregex r of (mr, \\<phi>s) \\<Rightarrow> \\<forall>ms \\<in> LPDs mr.\n       qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v.\n         Regex.match (Formula.sat \\<sigma> V (map the v)) (from_mregex ms \\<phi>s) i (i + length aux - 1)) (lookup Y ms)))\"\n\ndefinition lift_envs' :: \"nat \\<Rightarrow> event_data list set \\<Rightarrow> event_data list set\" where\n  \"lift_envs' b R = (\\<lambda>(xs,ys). xs @ ys) ` ({xs. length xs = b} \\<times> R)\"\n\nfun formula_of_constraint :: \"Formula.trm \\<times> bool \\<times> mconstraint \\<times> Formula.trm \\<Rightarrow> Formula.formula\" where\n  \"formula_of_constraint (t1, True, MEq, t2) = Formula.Eq t1 t2\"\n| \"formula_of_constraint (t1, True, MLess, t2) = Formula.Less t1 t2\"\n| \"formula_of_constraint (t1, True, MLessEq, t2) = Formula.LessEq t1 t2\"\n| \"formula_of_constraint (t1, False, MEq, t2) = Formula.Neg (Formula.Eq t1 t2)\"\n| \"formula_of_constraint (t1, False, MLess, t2) = Formula.Neg (Formula.Less t1 t2)\"\n| \"formula_of_constraint (t1, False, MLessEq, t2) = Formula.Neg (Formula.LessEq t1 t2)\"\n\ninductive (in maux) wf_mformula :: \"Formula.trace \\<Rightarrow> nat \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow>\n  nat \\<Rightarrow> event_data list set \\<Rightarrow> ('msaux, 'muaux) mformula \\<Rightarrow> Formula.formula \\<Rightarrow> bool\"\n  for \\<sigma> j where\n    Eq: \"is_simple_eq t1 t2 \\<Longrightarrow>\n    \\<forall>x\\<in>Formula.fv_trm t1. x < n \\<Longrightarrow> \\<forall>x\\<in>Formula.fv_trm t2. x < n \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MRel (eq_rel n t1 t2)) (Formula.Eq t1 t2)\"\n  | neq_Var: \"x < n \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MRel empty_table) (Formula.Neg (Formula.Eq (Formula.Var x) (Formula.Var x)))\"\n  | Pred: \"\\<forall>x\\<in>Formula.fv (Formula.Pred e ts). x < n \\<Longrightarrow>\n    \\<forall>t\\<in>set ts. Formula.is_Var t \\<or> Formula.is_Const t \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MPred e ts) (Formula.Pred e ts)\"\n  | Let: \"wf_mformula \\<sigma> j P V m UNIV \\<phi> \\<phi>' \\<Longrightarrow>\n    wf_mformula \\<sigma> j (P(p \\<mapsto> progress \\<sigma> P \\<phi>' j))\n      (V(p \\<mapsto> \\<lambda>i. {v. length v = m \\<and> Formula.sat \\<sigma> V v i \\<phi>'})) n R \\<psi> \\<psi>' \\<Longrightarrow>\n    {0..<m} \\<subseteq> Formula.fv \\<phi>' \\<Longrightarrow> b \\<le> m \\<Longrightarrow> m = Formula.nfv \\<phi>' \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MLet p m \\<phi> \\<psi>) (Formula.Let p \\<phi>' \\<psi>')\"\n  | And: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow> wf_mformula \\<sigma> j P V n R \\<psi> \\<psi>' \\<Longrightarrow>\n    if pos then \\<chi> = Formula.And \\<phi>' \\<psi>'\n      else \\<chi> = Formula.And \\<phi>' (Formula.Neg \\<psi>') \\<and> Formula.fv \\<psi>' \\<subseteq> Formula.fv \\<phi>' \\<Longrightarrow>\n    wf_mbuf2' \\<sigma> P V j n R \\<phi>' \\<psi>' buf \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MAnd (fv \\<phi>') \\<phi> pos (fv \\<psi>') \\<psi> buf) \\<chi>\"\n  | AndAssign: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow>\n    x < n \\<Longrightarrow> x \\<notin> Formula.fv \\<phi>' \\<Longrightarrow> Formula.fv_trm t \\<subseteq> Formula.fv \\<phi>' \\<Longrightarrow> (x, t) = conf \\<Longrightarrow>\n    \\<psi>' = Formula.Eq (Formula.Var x) t \\<or> \\<psi>' = Formula.Eq t (Formula.Var x) \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MAndAssign \\<phi> conf) (Formula.And \\<phi>' \\<psi>')\"\n  | AndRel: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow>\n    \\<psi>' = formula_of_constraint conf \\<Longrightarrow>\n    (let (t1, _, _, t2) = conf in Formula.fv_trm t1 \\<union> Formula.fv_trm t2 \\<subseteq> Formula.fv \\<phi>') \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MAndRel \\<phi> conf) (Formula.And \\<phi>' \\<psi>')\"\n  | Ands: \"list_all2 (\\<lambda>\\<phi> \\<phi>'. wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>') l (l_pos @ map remove_neg l_neg) \\<Longrightarrow>\n    wf_mbufn (progress \\<sigma> P (Formula.Ands l') j) (map (\\<lambda>\\<psi>. progress \\<sigma> P \\<psi> j) (l_pos @ map remove_neg l_neg)) (map (\\<lambda>\\<psi> i.\n      qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>)) (l_pos @ map remove_neg l_neg)) buf \\<Longrightarrow>\n    (l_pos, l_neg) = partition safe_formula l' \\<Longrightarrow>\n    l_pos \\<noteq> [] \\<Longrightarrow>\n    list_all safe_formula (map remove_neg l_neg) \\<Longrightarrow>\n    A_pos = map fv l_pos \\<Longrightarrow>\n    A_neg = map fv l_neg \\<Longrightarrow>\n    \\<Union>(set A_neg) \\<subseteq> \\<Union>(set A_pos) \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MAnds A_pos A_neg l buf) (Formula.Ands l')\"\n  | Or: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow> wf_mformula \\<sigma> j P V n R \\<psi> \\<psi>' \\<Longrightarrow>\n    Formula.fv \\<phi>' = Formula.fv \\<psi>' \\<Longrightarrow>\n    wf_mbuf2' \\<sigma> P V j n R \\<phi>' \\<psi>' buf \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MOr \\<phi> \\<psi> buf) (Formula.Or \\<phi>' \\<psi>')\"\n  | Neg: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow> Formula.fv \\<phi>' = {} \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MNeg \\<phi>) (Formula.Neg \\<phi>')\"\n  | Exists: \"wf_mformula \\<sigma> j P V (Suc n) (lift_envs R) \\<phi> \\<phi>' \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MExists \\<phi>) (Formula.Exists \\<phi>')\"\n  | Agg: \"wf_mformula \\<sigma> j P V (b + n) (lift_envs' b R) \\<phi> \\<phi>' \\<Longrightarrow>\n    y < n \\<Longrightarrow>\n    y + b \\<notin> Formula.fv \\<phi>' \\<Longrightarrow>\n    {0..<b} \\<subseteq> Formula.fv \\<phi>' \\<Longrightarrow>\n    Formula.fv_trm f \\<subseteq> Formula.fv \\<phi>' \\<Longrightarrow>\n    g0 = (Formula.fv \\<phi>' \\<subseteq> {0..<b}) \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MAgg g0 y \\<omega> b f \\<phi>) (Formula.Agg y \\<omega> b f \\<phi>')\"\n  | Prev: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow>\n    first \\<longleftrightarrow> j = 0 \\<Longrightarrow>\n    list_all2 (\\<lambda>i. qtable n (Formula.fv \\<phi>') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>'))\n      [min (progress \\<sigma> P \\<phi>' j) (j-1)..<progress \\<sigma> P \\<phi>' j] buf \\<Longrightarrow>\n    list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [min (progress \\<sigma> P \\<phi>' j) (j-1)..<j] nts \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MPrev I \\<phi> first buf nts) (Formula.Prev I \\<phi>')\"\n  | Next: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow>\n    first \\<longleftrightarrow> progress \\<sigma> P \\<phi>' j = 0 \\<Longrightarrow>\n    list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [progress \\<sigma> P \\<phi>' j - 1..<j] nts \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MNext I \\<phi> first nts) (Formula.Next I \\<phi>')\"\n  | Since: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow> wf_mformula \\<sigma> j P V n R \\<psi> \\<psi>' \\<Longrightarrow>\n    if args_pos args then \\<phi>'' = \\<phi>' else \\<phi>'' = Formula.Neg \\<phi>' \\<Longrightarrow>\n    safe_formula \\<phi>'' = args_pos args \\<Longrightarrow>\n    args_ivl args = I \\<Longrightarrow>\n    args_n args = n \\<Longrightarrow>\n    args_L args = Formula.fv \\<phi>' \\<Longrightarrow>\n    args_R args = Formula.fv \\<psi>' \\<Longrightarrow>\n    mem_restr R = mem_restr (lift_envs' (agg_b args) R') \\<Longrightarrow>\n    Formula.fv \\<phi>' \\<subseteq> Formula.fv \\<psi>' \\<Longrightarrow>\n    wf_mbuf2' \\<sigma> P V j n R \\<phi>' \\<psi>' buf \\<Longrightarrow>\n    wf_ts \\<sigma> P j \\<phi>' \\<psi>' nts \\<Longrightarrow>\n    wf_since_aux \\<sigma> V R args \\<phi>' \\<psi>' aux (progress \\<sigma> P (Formula.Since \\<phi>'' I \\<psi>') j) \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V (agg_n args) R' (MSince args \\<phi> \\<psi> buf nts aux) (packagg args (Formula.Since \\<phi>'' I \\<psi>'))\"\n  | Until: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow> wf_mformula \\<sigma> j P V n R \\<psi> \\<psi>' \\<Longrightarrow>\n    if args_pos args then \\<phi>'' = \\<phi>' else \\<phi>'' = Formula.Neg \\<phi>' \\<Longrightarrow>\n    safe_formula \\<phi>'' = args_pos args \\<Longrightarrow>\n    args_ivl args = I \\<Longrightarrow>\n    args_n args = n \\<Longrightarrow>\n    args_L args = Formula.fv \\<phi>' \\<Longrightarrow>\n    args_R args = Formula.fv \\<psi>' \\<Longrightarrow>\n    mem_restr R = mem_restr (lift_envs' (agg_b args) R') \\<Longrightarrow>\n    Formula.fv \\<phi>' \\<subseteq> Formula.fv \\<psi>' \\<Longrightarrow>\n    wf_mbuf2' \\<sigma> P V j n R \\<phi>' \\<psi>' buf \\<Longrightarrow>\n    wf_ts \\<sigma> P j \\<phi>' \\<psi>' nts \\<Longrightarrow>\n    t = (if j = 0 then 0 else \\<tau> \\<sigma> (min (j - 1) (min (progress \\<sigma> P \\<phi>' j) (progress \\<sigma> P \\<psi>' j)))) \\<Longrightarrow>\n    wf_until_aux \\<sigma> V R args \\<phi>' \\<psi>' aux (progress \\<sigma> P (Formula.Until \\<phi>'' I \\<psi>') j) \\<Longrightarrow>\n    progress \\<sigma> P (Formula.Until \\<phi>'' I \\<psi>') j + length_muaux args aux = min (progress \\<sigma> P \\<phi>' j) (progress \\<sigma> P \\<psi>' j) \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V (agg_n args) R' (MUntil args \\<phi> \\<psi> buf nts t aux) (packagg args (Formula.Until \\<phi>'' I \\<psi>'))\"\n  | MatchP: \"(case to_mregex r of (mr', \\<phi>s') \\<Rightarrow>\n      list_all2 (wf_mformula \\<sigma> j P V n R) \\<phi>s \\<phi>s' \\<and> mr = mr') \\<Longrightarrow>\n    mrs = sorted_list_of_set (RPDs mr) \\<Longrightarrow>\n    safe_regex Past Strict r \\<Longrightarrow>\n    wf_mbufn' \\<sigma> P V j n R r buf \\<Longrightarrow>\n    wf_ts_regex \\<sigma> P j r nts \\<Longrightarrow>\n    wf_matchP_aux \\<sigma> V n R I r aux (progress \\<sigma> P (Formula.MatchP I r) j) \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MMatchP I mr mrs \\<phi>s buf nts aux) (Formula.MatchP I r)\"\n  | MatchF: \"(case to_mregex r of (mr', \\<phi>s') \\<Rightarrow>\n      list_all2 (wf_mformula \\<sigma> j P V n R) \\<phi>s \\<phi>s' \\<and> mr = mr') \\<Longrightarrow>\n    mrs = sorted_list_of_set (LPDs mr) \\<Longrightarrow>\n    safe_regex Futu Strict r \\<Longrightarrow>\n    wf_mbufn' \\<sigma> P V j n R r buf \\<Longrightarrow>\n    wf_ts_regex \\<sigma> P j r nts \\<Longrightarrow>\n    t = (if j = 0 then 0 else \\<tau> \\<sigma> (min (j - 1) (progress_regex \\<sigma> P r j))) \\<Longrightarrow>\n    wf_matchF_aux \\<sigma> V n R I r aux (progress \\<sigma> P (Formula.MatchF I r) j) 0 \\<Longrightarrow>\n    progress \\<sigma> P (Formula.MatchF I r) j + length aux = progress_regex \\<sigma> P r j \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MMatchF I mr mrs \\<phi>s buf nts t aux) (Formula.MatchF I r)\"\n\ndefinition (in maux) wf_mstate :: \"Formula.formula \\<Rightarrow> Formula.prefix \\<Rightarrow> event_data list set \\<Rightarrow> ('msaux, 'muaux) mstate \\<Rightarrow> bool\" where\n  \"wf_mstate \\<phi> \\<pi> R st \\<longleftrightarrow> mstate_n st = Formula.nfv \\<phi> \\<and> (\\<forall>\\<sigma>. prefix_of \\<pi> \\<sigma> \\<longrightarrow>\n    mstate_i st = progress \\<sigma> Map.empty \\<phi> (plen \\<pi>) \\<and>\n    wf_mformula \\<sigma> (plen \\<pi>) Map.empty Map.empty (mstate_n st) R (mstate_m st) \\<phi>)\"\n\n\nsubsubsection \\<open>Initialisation\\<close>\n\n\nlemma wf_mbuf2'_0: \"pred_mapping (\\<lambda>x. x = 0) P \\<Longrightarrow> wf_mbuf2' \\<sigma> P V 0 n R \\<phi> \\<psi> ([], [])\"\n  unfolding wf_mbuf2'_def wf_mbuf2_def by simp\n\nlemma wf_mbufn'_0: \"to_mregex r = (mr, \\<phi>s) \\<Longrightarrow> pred_mapping (\\<lambda>x. x = 0) P \\<Longrightarrow> wf_mbufn' \\<sigma> P V 0 n R r (replicate (length \\<phi>s) [])\"\n  unfolding wf_mbufn'_def wf_mbufn_def map_replicate_const[symmetric]\n  by (auto simp: list_all3_map intro: list_all3_refl simp: Min_eq_iff progress_regex_def)\n\nlemma wf_ts_0: \"wf_ts \\<sigma> P 0 \\<phi> \\<psi> []\"\n  unfolding wf_ts_def by simp\n\nlemma wf_ts_regex_0: \"wf_ts_regex \\<sigma> P 0 r []\"\n  unfolding wf_ts_regex_def by simp\n\nlemma (in msaux) wf_since_aux_Nil: \"Formula.fv \\<phi>' \\<subseteq> Formula.fv \\<psi>' \\<Longrightarrow>\n  valid_aggargs n (Formula.fv \\<psi>') agg \\<Longrightarrow>\n  wf_since_aux \\<sigma> V R (init_args I n (Formula.fv \\<phi>') (Formula.fv \\<psi>') b agg) \\<phi>' \\<psi>' (init_msaux (init_args I n (Formula.fv \\<phi>') (Formula.fv \\<psi>') b agg)) 0\"\n  unfolding wf_since_aux_def\n  by (auto intro!: valid_init_msaux) (simp add: init_args_def)\n\nlemma (in muaux) wf_until_aux_Nil: \"Formula.fv \\<phi>' \\<subseteq> Formula.fv \\<psi>' \\<Longrightarrow>\n  valid_aggargs n (Formula.fv \\<psi>') agg \\<Longrightarrow>\n  wf_until_aux \\<sigma> V R (init_args I n (Formula.fv \\<phi>') (Formula.fv \\<psi>') b agg) \\<phi>' \\<psi>' (init_muaux (init_args I n (Formula.fv \\<phi>') (Formula.fv \\<psi>') b agg)) 0\"\n  unfolding wf_until_aux_def wf_until_auxlist_def\n  by (auto intro!: valid_init_muaux) (simp add: init_args_def)\n\nlemma wf_matchP_aux_Nil: \"wf_matchP_aux \\<sigma> V n R I r [] 0\"\n  unfolding wf_matchP_aux_def by simp\n\nlemma wf_matchF_aux_Nil: \"wf_matchF_aux \\<sigma> V n R I r [] 0 k\"\n  unfolding wf_matchF_aux_def by simp\n\nlemma fv_regex_alt: \"safe_regex m g r \\<Longrightarrow> Formula.fv_regex r = (\\<Union>\\<phi> \\<in> atms r. Formula.fv \\<phi>)\"\n  unfolding fv_regex_alt atms_def\n  by (auto 0 3 dest: safe_regex_safe_formula)\n\nlemmas to_mregex_atms =\n  to_mregex_ok[THEN conjunct1, THEN equalityD1, THEN set_mp, rotated]\n\nlemma (in maux) wf_minit0_op:\n  assumes \"safe_formula \\<phi>\" \"fv \\<phi> \\<subseteq> fv \\<psi>\"\n    \"wf_mformula \\<sigma> 0 P V n R (minit0 n \\<phi>) \\<phi>\" \"wf_mformula \\<sigma> 0 P V n R (minit0 n \\<psi>) \\<psi>\"\n    \"args_type_restr \\<sigma> V n R \\<psi> args\"\n    \"valid_aggargs n (fv \\<psi>) (args_agg args)\"\n    \"pred_mapping (\\<lambda>x. x = 0) P\"\n    \"mem_restr R = mem_restr (lift_envs' (agg_b args) R')\"\n    \"args = init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) b agg\"\n    \"\\<phi>' = (if b then \\<phi> else formula.Neg \\<phi>)\"\n    \"safe_formula \\<phi>' \\<Longrightarrow> b\"\n    \"(op = formula.Since \\<and> init = init_since) \\<or> (op = formula.Until \\<and> init = init_until)\"\n  shows \"wf_mformula \\<sigma> 0 P V (agg_n args) R' (init minit0 n agg \\<phi>' I \\<psi>) (packagg args (op \\<phi>' I \\<psi>))\"\nproof -\n  have args_props: \"args_n args = n\" \"args_pos args = b\" \"args_ivl args = I\"\n    \"args_L args = fv \\<phi>\" \"args_R args = fv \\<psi>\" \"args_agg args = agg\"\n    by (auto simp: assms(9) init_args_def agg_n_def agg_b_def packagg_def split: option.splits)\n  have args_fold: \"b \\<Longrightarrow> init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) True agg = args\"\n    \"\\<not>b \\<Longrightarrow> init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) False agg = args\"\n    using assms(9)\n    by auto\n  show ?thesis\n    using assms(12)\n  proof (rule disjE)\n    assume \"op = formula.Since \\<and> init = init_since\"\n    then show ?thesis\n    using assms(1-8,10-11) valid_length_muaux[OF valid_init_muaux[OF assms(2)], of n agg I b, folded assms(9)]\n    by (auto simp: init_since_def init_until_def args_fold args_props valid_aggargs_def simp del: progress_simps\n        intro!: wf_mformula.Since[where ?args = \"args\", unfolded args_props] wf_mbuf2'_0 wf_ts_0\n        wf_since_aux_Nil[where ?I = I and ?n = n and ?\\<phi>' = \\<phi> and ?\\<psi>' = \\<psi> and ?b = b and ?agg = agg, folded assms(9)])\n  next\n    assume \"op = formula.Until \\<and> init = init_until\"\n    then show ?thesis\n    using assms(1-8,10-11) valid_length_muaux[OF valid_init_muaux[OF assms(2)], of n agg I b, folded assms(9)]\n    by (auto simp: init_since_def init_until_def args_fold args_props valid_aggargs_def simp del: progress_simps\n        intro!: wf_mformula.Until[where ?args = \"args\", unfolded args_props] wf_mbuf2'_0 wf_ts_0\n        wf_until_aux_Nil[where ?I = I and ?n = n and ?\\<phi>' = \\<phi> and ?\\<psi>' = \\<psi> and ?b = b and ?agg = agg, folded assms(9)])\n  qed\nqed\n\nlemma mem_restr_lift_envs'_append[simp]:\n  \"length xs = b \\<Longrightarrow> mem_restr (lift_envs' b R) (xs @ ys) = mem_restr R ys\"\n  unfolding mem_restr_def lift_envs'_def\n  by (auto simp: list_all2_append list.rel_map intro!: exI[where x=\"map the xs\"] list.rel_refl)\n\nlemma mem_restr_lift_envs'_zero[simp]: \"mem_restr (lift_envs' 0 R) = mem_restr R\"\n  using mem_restr_lift_envs'_append[of \"[]\" 0]\n  by auto\n\nlemma (in maux) wf_minit0: \"safe_formula \\<phi> \\<Longrightarrow> \\<forall>x\\<in>Formula.fv \\<phi>. x < n \\<Longrightarrow>\n  pred_mapping (\\<lambda>x. x = 0) P \\<Longrightarrow>\n  wf_mformula \\<sigma> 0 P V n R (minit0 n \\<phi>) \\<phi>\"\nproof (induction arbitrary: n R P V rule: safe_formula_induct)\n  case (Eq_Const c d)\n  then show ?case\n    by (auto simp add: is_simple_eq_def simp del: eq_rel.simps intro!: wf_mformula.Eq)\nnext\n  case (Eq_Var1 c x)\n  then show ?case\n    by (auto simp add: is_simple_eq_def simp del: eq_rel.simps intro!: wf_mformula.Eq)\nnext\n  case (Eq_Var2 c x)\n  then show ?case\n    by (auto simp add: is_simple_eq_def simp del: eq_rel.simps intro!: wf_mformula.Eq)\nnext\n  case (neq_Var x y)\n  then show ?case by (auto intro!: wf_mformula.neq_Var)\nnext\n  case (Pred e ts)\n  then show ?case by (auto intro!: wf_mformula.Pred)\nnext\n  case (Let p \\<phi> \\<psi>)\n  with fvi_less_nfv show ?case\n    by (auto simp: pred_mapping_alt dom_def intro!: wf_mformula.Let Let(4,5))\nnext\n  case (And_assign \\<phi> \\<psi>)\n  then have 1: \"\\<forall>x\\<in>fv \\<psi>. x < n\" by simp\n  from 1 \\<open>safe_assignment (fv \\<phi>) \\<psi>\\<close>\n  obtain x t where\n    \"x < n\" \"x \\<notin> fv \\<phi>\" \"fv_trm t \\<subseteq> fv \\<phi>\"\n    \"\\<psi> = Formula.Eq (Formula.Var x) t \\<or> \\<psi> = Formula.Eq t (Formula.Var x)\"\n    unfolding safe_assignment_def by (force split: formula.splits trm.splits)\n  with And_assign show ?case\n    by (auto intro!: wf_mformula.AndAssign split: trm.splits)\nnext\n  case (And_safe \\<phi> \\<psi>)\n  then show ?case by (auto intro!: wf_mformula.And wf_mbuf2'_0)\nnext\n  case (And_constraint \\<phi> \\<psi>)\n  from \\<open>fv \\<psi> \\<subseteq> fv \\<phi>\\<close> \\<open>is_constraint \\<psi>\\<close>\n  obtain t1 p c t2 where\n    \"(t1, p, c, t2) = split_constraint \\<psi>\"\n    \"formula_of_constraint (split_constraint \\<psi>) = \\<psi>\"\n    \"fv_trm t1 \\<union> fv_trm t2 \\<subseteq> fv \\<phi>\"\n    by (induction rule: is_constraint.induct) auto\n  with And_constraint show ?case\n    by (auto 0 3 intro!: wf_mformula.AndRel)\nnext\n  case (And_Not \\<phi> \\<psi>)\n  then show ?case by (auto intro!: wf_mformula.And wf_mbuf2'_0)\nnext\n  case (Ands l pos neg)\n  note posneg = \"Ands.hyps\"(1)\n  let ?wf_minit = \"\\<lambda>x. wf_mformula \\<sigma> 0 P V n R (minit0 n x)\"\n  let ?pos = \"filter safe_formula l\"\n  let ?neg = \"filter (Not \\<circ> safe_formula) l\"\n  have \"list_all2 ?wf_minit ?pos pos\"\n    using Ands.IH(1) Ands.prems posneg by (auto simp: list_all_iff intro!: list.rel_refl_strong)\n  moreover have \"list_all2 ?wf_minit (map remove_neg ?neg) (map remove_neg neg)\"\n    using Ands.IH(2) Ands.prems posneg by (auto simp: list.rel_map list_all_iff intro!: list.rel_refl_strong)\n  moreover have \"list_all3 (\\<lambda>_ _ _. True) (?pos @ map remove_neg ?neg) (?pos @ map remove_neg ?neg) l\"\n    by (auto simp: list_all3_conv_all_nth comp_def sum_length_filter_compl)\n  moreover have \"l \\<noteq> [] \\<Longrightarrow> (MIN \\<phi>\\<in>set l. (0 :: nat)) = 0\"\n    by (cases l) (auto simp: Min_eq_iff)\n  ultimately show ?case using Ands.hyps Ands.prems(2)\n    by (auto simp: wf_mbufn_def list_all3_map list.rel_map map_replicate_const[symmetric] subset_eq\n        map_map[symmetric] map_append[symmetric] simp del: map_map map_append\n        intro!: wf_mformula.Ands list_all2_appendI)\nnext\n  case (Neg \\<phi>)\n  then show ?case by (auto intro!: wf_mformula.Neg)\nnext\n  case (Or \\<phi> \\<psi>)\n  then show ?case by (auto intro!: wf_mformula.Or wf_mbuf2'_0)\nnext\n  case (Exists \\<phi>)\n  then show ?case by (auto simp: fvi_Suc_bound intro!: wf_mformula.Exists)\nnext\n  case (Agg y \\<omega> b f \\<phi>)\n  define default where \"default = MAgg (fv \\<phi> \\<subseteq> {0..<b}) y \\<omega> b f (minit0 (b + n) \\<phi>)\"\n  have fv_le: \"\\<forall>x\\<in>fv \\<phi>. x < b + n\"\n    using Agg\n    by (auto intro!: fvi_plus_bound)\n  have wf_default: \"wf_mformula \\<sigma> 0 P V n R default (formula.Agg y \\<omega> b f \\<phi>)\"\n    using Agg\n    by (auto simp: default_def intro!: wf_mformula.Agg Agg.IH fvi_plus_bound)\n  {\n    fix y0 \\<phi>' I \\<psi>' op init\n    assume op_def: \"(op = formula.Since \\<and> init = init_since) \\<or> (op = formula.Until \\<and> init = init_until)\"\n    assume agg_def: \"\\<phi> = op \\<phi>' I \\<psi>'\"\n    define aggargs where \"aggargs = Some (init_aggargs (fv \\<phi>) n (fv \\<phi> \\<subseteq> {0..<b}) y \\<omega> b f)\"\n    have \"wf_mformula \\<sigma> 0 P V n R (init minit0 (b + n) aggargs \\<phi>' I \\<psi>') (formula.Agg y \\<omega> b f (op \\<phi>' I \\<psi>'))\"\n    proof (cases \"safe_formula \\<phi>'\")\n      case True\n      have IH: \"wf_mformula \\<sigma> 0 P V (b + n) (lift_envs' b R) (minit0 (b + n) \\<phi>') \\<phi>'\"\n        \"wf_mformula \\<sigma> 0 P V (b + n) (lift_envs' b R) (minit0 (b + n) \\<psi>') \\<psi>'\"\n        using Agg(4,7) True fv_le op_def\n        by (auto simp: agg_def(1) intro!: Agg(5))\n      have fv_subsume: \"fv \\<phi>' \\<union> fv \\<psi>' = fv \\<psi>'\"\n        using Agg agg_def(1) op_def\n        by auto\n      show ?thesis\n        using wf_minit0_op[where ?b=True and ?agg=aggargs]\n          Agg agg_def(1) op_def IH fv_le True\n        by (auto simp: packagg_def aggargs_def init_args_def init_aggargs_def agg_n_def agg_b_def\n            fv_subsume type_restr_def valid_aggargs_def safe_aggargs_def)\n    next\n      case False\n      obtain \\<phi>'' where \\<phi>'_def: \"\\<phi>' = formula.Neg \\<phi>''\" \"safe_formula \\<phi>''\"\n        using Agg(4) op_def False\n        by (auto simp: agg_def(1) split: formula.splits)\n      have IH: \"wf_mformula \\<sigma> 0 P V (b + n) (lift_envs' b R) (minit0 (b + n) \\<phi>'') \\<phi>''\"\n        \"wf_mformula \\<sigma> 0 P V (b + n) (lift_envs' b R) (minit0 (b + n) \\<psi>') \\<psi>'\"\n        using Agg(4,7) \\<phi>'_def(2) fv_le op_def\n        by (auto simp: agg_def(1) \\<phi>'_def(1) intro!: Agg(5))\n      have fv_subsume: \"fv \\<phi>'' \\<union> fv \\<psi>' = fv \\<psi>'\"\n        using Agg agg_def(1) op_def \\<phi>'_def\n        by auto\n      show ?thesis\n        using wf_minit0_op[where ?b=False and ?\\<phi>=\\<phi>'' and ?agg=aggargs]\n          Agg agg_def(1) op_def IH fv_le False\n        by (auto simp: \\<phi>'_def packagg_def aggargs_def init_args_def init_aggargs_def agg_n_def agg_b_def\n            fv_subsume type_restr_def valid_aggargs_def safe_aggargs_def)\n    qed\n  }\n  then show ?case\n    using wf_default\n    by (fastforce simp: default_def[symmetric] split: formula.splits prod.splits agg_type.splits)\nnext\n  case (Prev I \\<phi>)\n  thm wf_mformula.Prev[where P=P]\n  then show ?case by (auto intro!: wf_mformula.Prev)\nnext\n  case (Next I \\<phi>)\n  then show ?case by (auto intro!: wf_mformula.Next)\nnext\n  case (Since \\<phi> I \\<psi>)\n  then show ?case\n    using wf_minit0_op[where ?b=True and ?agg=None]\n    by (auto simp: init_args_def agg_n_def agg_b_def packagg_def valid_aggargs_def)\nnext\n  case (Not_Since \\<phi> I \\<psi>)\n  then show ?case\n    using wf_minit0_op[where ?b=False and ?agg=None and ?\\<phi>=\\<phi>]\n    by (auto simp: init_args_def agg_n_def agg_b_def packagg_def valid_aggargs_def)\nnext\n  case (Until \\<phi> I \\<psi>)\n  then show ?case\n    using wf_minit0_op[where ?b=True and ?agg=None]\n    by (auto simp: init_args_def agg_n_def agg_b_def packagg_def valid_aggargs_def)\nnext\n  case (Not_Until \\<phi> I \\<psi>)\n  then show ?case\n    using wf_minit0_op[where ?b=False and ?agg=None and ?\\<phi>=\\<phi>]\n    by (auto simp: init_args_def agg_n_def agg_b_def packagg_def valid_aggargs_def)\nnext\n  case (MatchP I r)\n  then show ?case\n    by (auto simp: list.rel_map fv_regex_alt simp del: progress_simps split: prod.split\n        intro!: wf_mformula.MatchP list.rel_refl_strong wf_mbufn'_0 wf_ts_regex_0 wf_matchP_aux_Nil\n        dest!: to_mregex_atms)\nnext\n  case (MatchF I r)\n  then show ?case\n    by (auto simp: list.rel_map fv_regex_alt progress_le Min_eq_iff progress_regex_def\n        simp del: progress_simps split: prod.split\n        intro!: wf_mformula.MatchF list.rel_refl_strong wf_mbufn'_0 wf_ts_regex_0 wf_matchF_aux_Nil\n        dest!: to_mregex_atms)\nqed\n\nlemma (in maux) wf_mstate_minit: \"safe_formula \\<phi> \\<Longrightarrow> wf_mstate \\<phi> pnil R (minit \\<phi>)\"\n  unfolding wf_mstate_def minit_def Let_def\n  by (auto intro!: wf_minit0 fvi_less_nfv)\n\n\nsubsubsection \\<open>Evaluation\\<close>\n\nlemma match_wf_tuple: \"Some f = match ts xs \\<Longrightarrow>\n  wf_tuple n (\\<Union>t\\<in>set ts. Formula.fv_trm t) (Table.tabulate f 0 n)\"\n  by (induction ts xs arbitrary: f rule: match.induct)\n    (fastforce simp: wf_tuple_def split: if_splits option.splits)+\n\nlemma match_fvi_trm_None: \"Some f = match ts xs \\<Longrightarrow> \\<forall>t\\<in>set ts. x \\<notin> Formula.fv_trm t \\<Longrightarrow> f x = None\"\n  by (induction ts xs arbitrary: f rule: match.induct) (auto split: if_splits option.splits)\n\nlemma match_fvi_trm_Some: \"Some f = match ts xs \\<Longrightarrow> t \\<in> set ts \\<Longrightarrow> x \\<in> Formula.fv_trm t \\<Longrightarrow> f x \\<noteq> None\"\n  by (induction ts xs arbitrary: f rule: match.induct) (auto split: if_splits option.splits)\n\nlemma match_eval_trm: \"\\<forall>t\\<in>set ts. \\<forall>i\\<in>Formula.fv_trm t. i < n \\<Longrightarrow> Some f = match ts xs \\<Longrightarrow>\n    map (Formula.eval_trm (Table.tabulate (\\<lambda>i. the (f i)) 0 n)) ts = xs\"\nproof (induction ts xs arbitrary: f rule: match.induct)\n  case (3 x ts y ys)\n  from 3(1)[symmetric] 3(2,3) show ?case\n    by (auto 0 3 dest: match_fvi_trm_Some sym split: option.splits if_splits intro!: eval_trm_fv_cong)\nqed (auto split: if_splits)\n\nlemma wf_tuple_tabulate_Some: \"wf_tuple n A (Table.tabulate f 0 n) \\<Longrightarrow> x \\<in> A \\<Longrightarrow> x < n \\<Longrightarrow> \\<exists>y. f x = Some y\"\n  unfolding wf_tuple_def by auto\n\nlemma ex_match: \"wf_tuple n (\\<Union>t\\<in>set ts. Formula.fv_trm t) v \\<Longrightarrow>\n  \\<forall>t\\<in>set ts. (\\<forall>x\\<in>Formula.fv_trm t. x < n) \\<and> (Formula.is_Var t \\<or> Formula.is_Const t) \\<Longrightarrow>\n  \\<exists>f. match ts (map (Formula.eval_trm (map the v)) ts) = Some f \\<and> v = Table.tabulate f 0 n\"\nproof (induction ts \"map (Formula.eval_trm (map the v)) ts\" arbitrary: v rule: match.induct)\n  case (3 x ts y ys)\n  then show ?case\n  proof (cases \"x \\<in> (\\<Union>t\\<in>set ts. Formula.fv_trm t)\")\n    case True\n    with 3 show ?thesis\n      by (auto simp: insert_absorb dest!: wf_tuple_tabulate_Some meta_spec[of _ v])\n  next\n    case False\n    with 3(3,4) have\n      *: \"map (Formula.eval_trm (map the v)) ts = map (Formula.eval_trm (map the (v[x := None]))) ts\"\n      by (auto simp: wf_tuple_def nth_list_update intro!: eval_trm_fv_cong)\n    from False 3(2-4) obtain f where\n      \"match ts (map (Formula.eval_trm (map the v)) ts) = Some f\" \"v[x := None] = Table.tabulate f 0 n\"\n      unfolding *\n      by (atomize_elim, intro 3(1)[of \"v[x := None]\"])\n        (auto simp: wf_tuple_def nth_list_update intro!: eval_trm_fv_cong)\n    moreover from False this have \"f x = None\" \"length v = n\"\n      by (auto dest: match_fvi_trm_None[OF sym] arg_cong[of _ _ length])\n    ultimately show ?thesis using 3(3)\n      by (auto simp: list_eq_iff_nth_eq wf_tuple_def)\n  qed\nqed (auto simp: wf_tuple_def intro: nth_equalityI)\n\nlemma eq_rel_eval_trm: \"v \\<in> eq_rel n t1 t2 \\<Longrightarrow> is_simple_eq t1 t2 \\<Longrightarrow>\n  \\<forall>x\\<in>Formula.fv_trm t1 \\<union> Formula.fv_trm t2. x < n \\<Longrightarrow>\n  Formula.eval_trm (map the v) t1 = Formula.eval_trm (map the v) t2\"\n  by (cases t1; cases t2) (simp_all add: is_simple_eq_def singleton_table_def split: if_splits)\n\nlemma in_eq_rel: \"wf_tuple n (Formula.fv_trm t1 \\<union> Formula.fv_trm t2) v \\<Longrightarrow>\n  is_simple_eq t1 t2 \\<Longrightarrow>\n  Formula.eval_trm (map the v) t1 = Formula.eval_trm (map the v) t2 \\<Longrightarrow>\n  v \\<in> eq_rel n t1 t2\"\n  by (cases t1; cases t2)\n    (auto simp: is_simple_eq_def singleton_table_def wf_tuple_def unit_table_def\n      intro!: nth_equalityI split: if_splits)\n\nlemma table_eq_rel: \"is_simple_eq t1 t2 \\<Longrightarrow>\n  table n (Formula.fv_trm t1 \\<union> Formula.fv_trm t2) (eq_rel n t1 t2)\"\n  by (cases t1; cases t2; simp add: is_simple_eq_def)\n\nlemma wf_tuple_Suc_fviD: \"wf_tuple (Suc n) (Formula.fvi b \\<phi>) v \\<Longrightarrow> wf_tuple n (Formula.fvi (Suc b) \\<phi>) (tl v)\"\n  unfolding wf_tuple_def by (simp add: fvi_Suc nth_tl)\n\nlemma table_fvi_tl: \"table (Suc n) (Formula.fvi b \\<phi>) X \\<Longrightarrow> table n (Formula.fvi (Suc b) \\<phi>) (tl ` X)\"\n  unfolding table_def by (auto intro: wf_tuple_Suc_fviD)\n\nlemma wf_tuple_Suc_fvi_SomeI: \"0 \\<in> Formula.fvi b \\<phi> \\<Longrightarrow> wf_tuple n (Formula.fvi (Suc b) \\<phi>) v \\<Longrightarrow>\n  wf_tuple (Suc n) (Formula.fvi b \\<phi>) (Some x # v)\"\n  unfolding wf_tuple_def\n  by (auto simp: fvi_Suc less_Suc_eq_0_disj)\n\nlemma wf_tuple_Suc_fvi_NoneI: \"0 \\<notin> Formula.fvi b \\<phi> \\<Longrightarrow> wf_tuple n (Formula.fvi (Suc b) \\<phi>) v \\<Longrightarrow>\n  wf_tuple (Suc n) (Formula.fvi b \\<phi>) (None # v)\"\n  unfolding wf_tuple_def\n  by (auto simp: fvi_Suc less_Suc_eq_0_disj)\n\nlemma qtable_project_fv: \"qtable (Suc n) (fv \\<phi>) (mem_restr (lift_envs R)) P X \\<Longrightarrow>\n    qtable n (Formula.fvi (Suc 0) \\<phi>) (mem_restr R)\n      (\\<lambda>v. \\<exists>x. P ((if 0 \\<in> fv \\<phi> then Some x else None) # v)) (tl ` X)\"\n  using neq0_conv by (fastforce simp: image_iff Bex_def fvi_Suc elim!: qtable_cong dest!: qtable_project)\n\nlemma nth_list_update_alt: \"xs[i := x] ! j = (if i < length xs \\<and> i = j then x else xs ! j)\"\n  by auto\n\nlemma wf_tuple_upd_None: \"wf_tuple n A xs \\<Longrightarrow> A - {i} = B \\<Longrightarrow> wf_tuple n B (xs[i:=None])\"\n  unfolding wf_tuple_def\n  by (auto simp: nth_list_update_alt)\n\nlemma mem_restr_upd_None: \"mem_restr R xs \\<Longrightarrow> mem_restr R (xs[i:=None])\"\n  unfolding mem_restr_def\n  by (auto simp: list_all2_conv_all_nth nth_list_update_alt)\n\nlemma mem_restr_dropI: \"mem_restr (lift_envs' b R) xs \\<Longrightarrow> mem_restr R (drop b xs)\"\n  unfolding mem_restr_def lift_envs'_def\n  by (auto simp: append_eq_conv_conj list_all2_append2)\n\nlemma mem_restr_dropD:\n  assumes \"b \\<le> length xs\" and \"mem_restr R (drop b xs)\"\n  shows \"mem_restr (lift_envs' b R) xs\"\nproof -\n  let ?R = \"\\<lambda>a b. a \\<noteq> None \\<longrightarrow> a = Some b\"\n  from assms(2) obtain v where \"v \\<in> R\" and \"list_all2 ?R (drop b xs) v\"\n    unfolding mem_restr_def ..\n  show ?thesis unfolding mem_restr_def proof\n    have \"list_all2 ?R (take b xs) (map the (take b xs))\"\n      by (auto simp: list.rel_map intro!: list.rel_refl)\n    moreover note \\<open>list_all2 ?R (drop b xs) v\\<close>\n    ultimately have \"list_all2 ?R (take b xs @ drop b xs) (map the (take b xs) @ v)\"\n      by (rule list_all2_appendI)\n    then show \"list_all2 ?R xs (map the (take b xs) @ v)\" by simp\n    show \"map the (take b xs) @ v \\<in> lift_envs' b R\"\n      unfolding lift_envs'_def using assms(1) \\<open>v \\<in> R\\<close> by auto\n  qed\nqed\n\nlemma wf_tuple_append: \"wf_tuple a {x \\<in> A. x < a} xs \\<Longrightarrow>\n  wf_tuple b {x - a | x. x \\<in> A \\<and> x \\<ge> a} ys \\<Longrightarrow>\n  wf_tuple (a + b) A (xs @ ys)\"\n  unfolding wf_tuple_def by (auto simp: nth_append eq_diff_iff)\n\nlemma wf_tuple_map_Some: \"length xs = n \\<Longrightarrow> {0..<n} \\<subseteq> A \\<Longrightarrow> wf_tuple n A (map Some xs)\"\n  unfolding wf_tuple_def by auto\n\nlemma wf_tuple_drop: \"wf_tuple (b + n) A xs \\<Longrightarrow> {x - b | x. x \\<in> A \\<and> x \\<ge> b} = B \\<Longrightarrow>\n  wf_tuple n B (drop b xs)\"\n  unfolding wf_tuple_def by force\n\nlemma ecard_image: \"inj_on f A \\<Longrightarrow> ecard (f ` A) = ecard A\"\n  unfolding ecard_def by (auto simp: card_image dest: finite_imageD)\n\nlemma meval_trm_eval_trm: \"wf_tuple n A x \\<Longrightarrow> fv_trm t \\<subseteq> A \\<Longrightarrow> \\<forall>i\\<in>A. i < n \\<Longrightarrow>\n    meval_trm t x = Formula.eval_trm (map the x) t\"\n  unfolding wf_tuple_def\n  by (induction t) simp_all\n\nlemma list_update_id: \"xs ! i = z \\<Longrightarrow> xs[i:=z] = xs\"\n  by (induction xs arbitrary: i) (auto split: nat.split)\n\nlemma qtable_wf_tupleD: \"qtable n A P Q X \\<Longrightarrow> \\<forall>x\\<in>X. wf_tuple n A x\"\n  unfolding qtable_def table_def by blast\n\nlemma qtable_eval_agg:\n  assumes inner: \"qtable (b + n) (Formula.fv \\<phi>) (mem_restr (lift_envs' b R))\n      (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>) rel\"\n    and n: \"\\<forall>x\\<in>Formula.fv (Formula.Agg y \\<omega> b f \\<phi>). x < n\"\n    and fresh: \"y + b \\<notin> Formula.fv \\<phi>\"\n    and b_fv: \"{0..<b} \\<subseteq> Formula.fv \\<phi>\"\n    and f_fv: \"Formula.fv_trm f \\<subseteq> Formula.fv \\<phi>\"\n    and g0: \"g0 = (Formula.fv \\<phi> \\<subseteq> {0..<b})\"\n  shows \"qtable n (Formula.fv (Formula.Agg y \\<omega> b f \\<phi>)) (mem_restr R)\n      (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (Formula.Agg y \\<omega> b f \\<phi>)) (eval_agg n g0 y \\<omega> b f rel)\"\n    (is \"qtable _ ?fv _ ?Q ?rel'\")\nproof -\n  define M where \"M = (\\<lambda>v. {(x, ecard Zs) | x Zs.\n      Zs = {zs. length zs = b \\<and> Formula.sat \\<sigma> V (zs @ v) i \\<phi> \\<and> Formula.eval_trm (zs @ v) f = x} \\<and>\n      Zs \\<noteq> {}})\"\n  have f_fvi: \"Formula.fvi_trm b f \\<subseteq> Formula.fvi b \\<phi>\"\n    using f_fv by (auto simp: fvi_trm_iff_fv_trm[where b=b] fvi_iff_fv[where b=b])\n  show ?thesis proof (cases \"g0 \\<and> rel = empty_table\")\n    case True\n    then have [simp]: \"Formula.fvi b \\<phi> = {}\"\n      by (auto simp: g0 fvi_iff_fv(1)[where b=b])\n    then have [simp]: \"Formula.fvi_trm b f = {}\"\n      using f_fvi by auto\n    show ?thesis proof (rule qtableI)\n      show \"table n ?fv ?rel'\" by (simp add: eval_agg_def True)\n    next\n      fix v\n      assume \"wf_tuple n ?fv v\" \"mem_restr R v\"\n      have \"\\<not> Formula.sat \\<sigma> V (zs @ map the v) i \\<phi>\" if [simp]: \"length zs = b\" for zs\n      proof -\n        let ?zs = \"map2 (\\<lambda>z i. if i \\<in> Formula.fv \\<phi> then Some z else None) zs [0..<b]\"\n        have \"wf_tuple b {x \\<in> fv \\<phi>. x < b} ?zs\"\n          by (simp add: wf_tuple_def)\n        then have \"wf_tuple (b + n) (Formula.fv \\<phi>) (?zs @ v[y:=None])\"\n          using \\<open>wf_tuple n ?fv v\\<close> True\n          by (auto simp: g0 intro!: wf_tuple_append wf_tuple_upd_None)\n        then have \"\\<not> Formula.sat \\<sigma> V (map the (?zs @ v[y:=None])) i \\<phi>\"\n          using True \\<open>mem_restr R v\\<close>\n          by (auto simp del: map_append dest!: in_qtableI[OF inner, rotated -1]\n              intro!: mem_restr_upd_None)\n        also have \"Formula.sat \\<sigma> V (map the (?zs @ v[y:=None])) i \\<phi> \\<longleftrightarrow> Formula.sat \\<sigma> V (zs @ map the v) i \\<phi>\"\n          using True by (auto simp: g0 nth_append intro!: sat_fv_cong)\n        finally show ?thesis .\n      qed\n      then have M_empty: \"M (map the v) = {}\"\n        unfolding M_def by blast\n      show \"Formula.sat \\<sigma> V (map the v) i (Formula.Agg y \\<omega> b f \\<phi>)\"\n        if \"v \\<in> eval_agg n g0 y \\<omega> b f rel\"\n        using M_empty True that n\n        by (simp add: M_def eval_agg_def g0 singleton_table_def)\n      have \"v \\<in> singleton_table n y (the (v ! y))\" \"length v = n\"\n        using \\<open>wf_tuple n ?fv v\\<close> unfolding wf_tuple_def singleton_table_def\n        by (auto simp add: tabulate_alt map_nth\n            intro!: trans[OF map_cong[where g=\"(!) v\", simplified nth_map, OF refl], symmetric])\n      then show \"v \\<in> eval_agg n g0 y \\<omega> b f rel\"\n        if \"Formula.sat \\<sigma> V (map the v) i (Formula.Agg y \\<omega> b f \\<phi>)\"\n        using M_empty True that n\n        by (simp add: M_def eval_agg_def g0)\n    qed\n  next\n    case non_default_case: False\n    have union_fv: \"{0..<b} \\<union> (\\<lambda>x. x + b) ` Formula.fvi b \\<phi> = fv \\<phi>\"\n      using b_fv\n      by (auto simp: fvi_iff_fv(1)[where b=b] intro!: image_eqI[where b=x and x=\"x - b\" for x])\n    have b_n: \"\\<forall>x\\<in>fv \\<phi>. x < b + n\"\n    proof\n      fix x assume \"x \\<in> fv \\<phi>\"\n      show \"x < b + n\" proof (cases \"x \\<ge> b\")\n        case True\n        with \\<open>x \\<in> fv \\<phi>\\<close> have \"x - b \\<in> ?fv\"\n          by (simp add: fvi_iff_fv(1)[where b=b])\n        then show ?thesis using n f_fvi by (auto simp: Un_absorb2)\n      qed simp\n    qed\n\n    define M' where \"M' = (\\<lambda>k. let group = Set.filter (\\<lambda>x. drop b x = k) rel;\n        images = meval_trm f ` group\n      in (\\<lambda>y. (y, ecard (Set.filter (\\<lambda>x. meval_trm f x = y) group))) ` images)\"\n    have M'_M: \"M' (drop b x) = M (map the (drop b x))\" if \"x \\<in> rel\" \"mem_restr (lift_envs' b R) x\" for x\n    proof -\n      from that have wf_x: \"wf_tuple (b + n) (fv \\<phi>) x\"\n        by (auto elim!: in_qtableE[OF inner])\n      then have wf_zs_x: \"wf_tuple (b + n) (fv \\<phi>) (map Some zs @ drop b x)\"\n        if \"length zs = b\" for zs\n        using that b_fv\n        by (auto intro!: wf_tuple_append wf_tuple_map_Some wf_tuple_drop)\n      have 1: \"(length zs = b \\<and> Formula.sat \\<sigma> V (zs @ map the (drop b x)) i \\<phi> \\<and>\n          Formula.eval_trm (zs @ map the (drop b x)) f = y) \\<longleftrightarrow>\n        (\\<exists>a. a \\<in> rel \\<and> take b a = map Some zs \\<and> drop b a = drop b x \\<and> meval_trm f a = y)\"\n        (is \"?A \\<longleftrightarrow> (\\<exists>a. ?B a)\") for y zs\n      proof (intro iffI conjI)\n        assume ?A\n        then have \"?B (map Some zs @ drop (length zs) x)\"\n          using in_qtableI[OF inner wf_zs_x] \\<open>mem_restr (lift_envs' b R) x\\<close>\n            meval_trm_eval_trm[OF wf_zs_x f_fv b_n]\n          by (auto intro!: mem_restr_dropI)\n        then show \"\\<exists>a. ?B a\" ..\n      next\n        assume \"\\<exists>a. ?B a\"\n        then obtain a where \"?B a\" ..\n        then have \"a \\<in> rel\" and a_eq: \"a = map Some zs @ drop b x\"\n          using append_take_drop_id[of b a] by auto\n        then have \"length a = b + n\"\n          using inner unfolding qtable_def table_def\n          by (blast intro!: wf_tuple_length)\n        then show \"length zs = b\"\n          using wf_tuple_length[OF wf_x] unfolding a_eq by simp\n        then have \"mem_restr (lift_envs' b R) a\"\n          using \\<open>mem_restr _ x\\<close> unfolding a_eq by (auto intro!: mem_restr_dropI)\n        then show \"Formula.sat \\<sigma> V (zs @ map the (drop b x)) i \\<phi>\"\n          using in_qtableE[OF inner \\<open>a \\<in> rel\\<close>]\n          by (auto simp: a_eq sat_fv_cong[THEN iffD1, rotated -1])\n        from \\<open>?B a\\<close> show \"Formula.eval_trm (zs @ map the (drop b x)) f = y\"\n          using meval_trm_eval_trm[OF wf_zs_x f_fv b_n, OF \\<open>length zs = b\\<close>]\n          unfolding a_eq by simp\n      qed\n      have 2: \"map Some (map the (take b a)) = take b a\" if \"a \\<in> rel\" for a\n        using that b_fv inner[THEN qtable_wf_tupleD]\n        unfolding table_def wf_tuple_def\n        by (auto simp: list_eq_iff_nth_eq)\n      have 3: \"ecard {zs. \\<exists>a. a \\<in> rel \\<and> take b a = map Some zs \\<and> drop b a = drop b x \\<and> P a} =\n        ecard {a. a \\<in> rel \\<and> drop b a = drop b x \\<and> P a}\" (is \"ecard ?A = ecard ?B\") for P\n      proof -\n        have \"ecard ?A = ecard ((\\<lambda>zs. map Some zs @ drop b x) ` ?A)\"\n          by (auto intro!: ecard_image[symmetric] inj_onI)\n        also have \"(\\<lambda>zs. map Some zs @ drop b x) ` ?A = ?B\"\n          by (subst (1 2) eq_commute) (auto simp: image_iff, metis \"2\" append_take_drop_id)\n        finally show ?thesis .\n      qed\n      show ?thesis\n        unfolding M_def M'_def\n        by (auto simp: non_default_case Let_def image_def Set.filter_def 1 3, metis \"2\")\n    qed\n    have drop_lift: \"mem_restr (lift_envs' b R) x\" if \"x \\<in> rel\" \"mem_restr R ((drop b x)[y:=z])\" for x z\n    proof -\n      have \"(drop b x)[y:=None] = (drop b x)[y:=drop b x ! y]\" proof -\n        from \\<open>x \\<in> rel\\<close> have \"drop b x ! y = None\"\n          using fresh n inner[THEN qtable_wf_tupleD]\n          by (simp add: add.commute wf_tuple_def)\n        then show ?thesis by simp\n      qed\n      then have \"(drop b x)[y:=None] = drop b x\" by simp\n      moreover from \\<open>x \\<in> rel\\<close> have \"length x = b + n\"\n        using inner[THEN qtable_wf_tupleD]\n        by (simp add: wf_tuple_def)\n      moreover from that(2) have \"mem_restr R ((drop b x)[y:=z, y:=None])\"\n        by (rule mem_restr_upd_None)\n      ultimately show ?thesis\n        by (auto intro!: mem_restr_dropD)\n    qed\n\n    {\n      fix v\n      assume \"mem_restr R v\"\n      have \"v \\<in> (\\<lambda>k. k[y:=Some (eval_agg_op \\<omega> (M' k))]) ` drop b ` rel \\<longleftrightarrow>\n          v \\<in> (\\<lambda>k. k[y:=Some (eval_agg_op \\<omega> (M (map the k)))]) ` drop b ` rel\"\n        (is \"v \\<in> ?A \\<longleftrightarrow> v \\<in> ?B\")\n      proof\n        assume \"v \\<in> ?A\"\n        then obtain v' where *: \"v' \\<in> rel\" \"v = (drop b v')[y:=Some (eval_agg_op \\<omega> (M' (drop b v')))]\"\n          by auto\n        then have \"M' (drop b v') = M (map the (drop b v'))\"\n          using \\<open>mem_restr R v\\<close> by (auto intro!: M'_M drop_lift)\n        with * show \"v \\<in> ?B\" by simp\n      next\n        assume \"v \\<in> ?B\"\n        then obtain v' where *: \"v' \\<in> rel\" \"v = (drop b v')[y:=Some (eval_agg_op \\<omega> (M (map the (drop b v'))))]\"\n          by auto\n        then have \"M (map the (drop b v')) = M' (drop b v')\"\n          using \\<open>mem_restr R v\\<close> by (auto intro!: M'_M[symmetric] drop_lift)\n        with * show \"v \\<in> ?A\" by simp\n      qed\n      then have \"v \\<in> eval_agg n g0 y \\<omega> b f rel \\<longleftrightarrow> v \\<in> (\\<lambda>k. k[y:=Some (eval_agg_op \\<omega> (M (map the k)))]) ` drop b ` rel\"\n        by (simp add: non_default_case eval_agg_def M'_def Let_def)\n    }\n    note alt = this\n\n    show ?thesis proof (rule qtableI)\n      show \"table n ?fv ?rel'\"\n        using inner[THEN qtable_wf_tupleD] n f_fvi\n        by (auto simp: eval_agg_def non_default_case table_def wf_tuple_def Let_def nth_list_update\n            fvi_iff_fv[where b=b] add.commute)\n    next\n      fix v\n      assume \"wf_tuple n ?fv v\" \"mem_restr R v\"\n      then have length_v: \"length v = n\" by (simp add: wf_tuple_def)\n\n      show \"Formula.sat \\<sigma> V (map the v) i (Formula.Agg y \\<omega> b f \\<phi>)\"\n        if \"v \\<in> eval_agg n g0 y \\<omega> b f rel\"\n      proof -\n        from that obtain v' where \"v' \\<in> rel\"\n          \"v = (drop b v')[y:=Some (eval_agg_op \\<omega> (M (map the (drop b v'))))]\"\n          using alt[OF \\<open>mem_restr R v\\<close>] by blast\n        then have length_v': \"length v' = b + n\"\n          using inner[THEN qtable_wf_tupleD]\n          by (simp add: wf_tuple_def)\n        have \"Formula.sat \\<sigma> V (map the v') i \\<phi>\"\n          using \\<open>v' \\<in> rel\\<close> \\<open>mem_restr R v\\<close>\n          by (auto simp: \\<open>v = _\\<close> elim!: in_qtableE[OF inner] intro!: drop_lift \\<open>v' \\<in> rel\\<close>)\n        then have \"Formula.sat \\<sigma> V (map the (take b v') @ map the v) i \\<phi>\"\n        proof (rule sat_fv_cong[THEN iffD1, rotated], intro ballI)\n          fix x\n          assume \"x \\<in> fv \\<phi>\"\n          then have \"x \\<noteq> y + b\" using fresh by blast\n          moreover have \"x < length v'\"\n            using \\<open>x \\<in> fv \\<phi>\\<close> b_n by (simp add: length_v')\n          ultimately show \"map the v' ! x = (map the (take b v') @ map the v) ! x\"\n            by (auto simp: \\<open>v = _\\<close> nth_append)\n        qed\n        then have 1: \"M (map the v) \\<noteq> {}\" by (force simp: M_def length_v')\n\n        have \"y < length (drop b v')\" using n by (simp add: length_v')\n        moreover have \"Formula.sat \\<sigma> V (zs @ map the v) i \\<phi> \\<longleftrightarrow>\n          Formula.sat \\<sigma> V (zs @ map the (drop b v')) i \\<phi>\" if \"length zs = b\" for zs\n        proof (intro sat_fv_cong ballI)\n          fix x\n          assume \"x \\<in> fv \\<phi>\"\n          then have \"x \\<noteq> y + b\" using fresh by blast\n          moreover have \"x < length v'\"\n            using \\<open>x \\<in> fv \\<phi>\\<close> b_n by (simp add: length_v')\n          ultimately show \"(zs @ map the v) ! x = (zs @ map the (drop b v')) ! x\"\n            by (auto simp: \\<open>v = _\\<close> that nth_append)\n        qed\n        moreover have \"Formula.eval_trm (zs @ map the v) f =\n          Formula.eval_trm (zs @ map the (drop b v')) f\" if \"length zs = b\" for zs\n        proof (intro eval_trm_fv_cong ballI)\n          fix x\n          assume \"x \\<in> fv_trm f\"\n          then have \"x \\<noteq> y + b\" using f_fv fresh by blast\n          moreover have \"x < length v'\"\n            using \\<open>x \\<in> fv_trm f\\<close> f_fv b_n by (auto simp: length_v')\n          ultimately show \"(zs @ map the v) ! x = (zs @ map the (drop b v')) ! x\"\n            by (auto simp: \\<open>v = _\\<close> that nth_append)\n        qed\n        ultimately have \"map the v ! y = eval_agg_op \\<omega> (M (map the v))\"\n          by (simp add: M_def \\<open>v = _\\<close> conj_commute cong: conj_cong)\n        with 1 show ?thesis by (auto simp: M_def)\n      qed\n\n      show \"v \\<in> eval_agg n g0 y \\<omega> b f rel\"\n        if sat_Agg: \"Formula.sat \\<sigma> V (map the v) i (Formula.Agg y \\<omega> b f \\<phi>)\"\n      proof -\n        obtain zs where \"length zs = b\" and \"map Some zs @ v[y:=None] \\<in> rel\"\n        proof (cases \"fv \\<phi> \\<subseteq> {0..<b}\")\n          case True\n          with non_default_case have \"rel \\<noteq> empty_table\" by (simp add: g0)\n          then obtain x where \"x \\<in> rel\" by auto\n          have \"(\\<forall>i < n. (v[y:=None]) ! i = None)\"\n            using True \\<open>wf_tuple n ?fv v\\<close> f_fv\n            by (fastforce simp: wf_tuple_def fvi_iff_fv[where b=b] fvi_trm_iff_fv_trm[where b=b])\n          moreover have x: \"(\\<forall>i < n. drop b x ! i = None) \\<and> length x = b + n\"\n            using True \\<open>x \\<in> rel\\<close> inner[THEN qtable_wf_tupleD] f_fv\n            by (auto simp: wf_tuple_def)\n          ultimately have \"v[y:=None] = drop b x\"\n            unfolding list_eq_iff_nth_eq by (auto simp: length_v)\n          with \\<open>x \\<in> rel\\<close> have \"take b x @ v[y:=None] \\<in> rel\" by simp\n          moreover have \"map (Some \\<circ> the) (take b x) = take b x\"\n            using True \\<open>x \\<in> rel\\<close> inner[THEN qtable_wf_tupleD] b_fv\n            by (subst map_cong[where g=id, OF refl]) (auto simp: wf_tuple_def in_set_conv_nth)\n          ultimately have \"map Some (map the (take b x)) @ v[y:=None] \\<in> rel\" by simp\n          then show thesis using x[THEN conjunct2] by (fastforce intro!: that[rotated])\n        next\n          case False\n          with sat_Agg obtain zs where \"length zs = b\" and \"Formula.sat \\<sigma> V (zs @ map the v) i \\<phi>\"\n            by auto\n          then have \"Formula.sat \\<sigma> V (zs @ map the (v[y:=None])) i \\<phi>\"\n            using fresh\n            by (auto simp: map_update not_less nth_append elim!: sat_fv_cong[THEN iffD1, rotated]\n                intro!: nth_list_update_neq[symmetric])\n          then have \"map Some zs @ v[y:=None] \\<in> rel\"\n            using b_fv f_fv fresh\n            by (auto intro!: in_qtableI[OF inner] wf_tuple_append wf_tuple_map_Some\n                wf_tuple_upd_None \\<open>wf_tuple n ?fv v\\<close> mem_restr_upd_None \\<open>mem_restr R v\\<close>\n                simp: \\<open>length zs = b\\<close> set_eq_iff fvi_iff_fv[where b=b] fvi_trm_iff_fv_trm[where b=b])\n              force+\n          with that \\<open>length zs = b\\<close> show thesis by blast\n        qed\n        then have 1: \"v[y:=None] \\<in> drop b ` rel\" by (intro image_eqI) auto\n\n        have y_length: \"y < length v\" using n by (simp add: length_v)\n        moreover have \"Formula.sat \\<sigma> V (zs @ map the (v[y:=None])) i \\<phi> \\<longleftrightarrow>\n          Formula.sat \\<sigma> V (zs @ map the v) i \\<phi>\" if \"length zs = b\" for zs\n        proof (intro sat_fv_cong ballI)\n          fix x\n          assume \"x \\<in> fv \\<phi>\"\n          then have \"x \\<noteq> y + b\" using fresh by blast\n          moreover have \"x < b + length v\"\n            using \\<open>x \\<in> fv \\<phi>\\<close> b_n by (simp add: length_v)\n          ultimately show \"(zs @ map the (v[y:=None])) ! x = (zs @ map the v) ! x\"\n            by (auto simp: that nth_append)\n        qed\n        moreover have \"Formula.eval_trm (zs @ map the (v[y:=None])) f =\n          Formula.eval_trm (zs @ map the v) f\" if \"length zs = b\" for zs\n        proof (intro eval_trm_fv_cong ballI)\n          fix x\n          assume \"x \\<in> fv_trm f\"\n          then have \"x \\<noteq> y + b\" using f_fv fresh by blast\n          moreover have \"x < b + length v\"\n            using \\<open>x \\<in> fv_trm f\\<close> f_fv b_n by (auto simp: length_v)\n          ultimately show \"(zs @ map the (v[y:=None])) ! x = (zs @ map the v) ! x\"\n            by (auto simp: that nth_append)\n        qed\n        ultimately have \"map the v ! y = eval_agg_op \\<omega> (M (map the (v[y:=None])))\"\n          using sat_Agg by (simp add: M_def cong: conj_cong) (simp cong: rev_conj_cong)\n        then have 2: \"v ! y = Some (eval_agg_op \\<omega> (M (map the (v[y:=None]))))\"\n          using \\<open>wf_tuple n ?fv v\\<close> y_length by (auto simp add: wf_tuple_def)\n        show ?thesis\n          unfolding alt[OF \\<open>mem_restr R v\\<close>]\n          by (rule image_eqI[where x=\"v[y:=None]\"]) (use 1 2 in \\<open>auto simp: y_length list_update_id\\<close>)\n      qed\n    qed\n  qed\nqed\n\nlemma mprev_next_NilE[elim!]: \"mprev_next I xs ts = (ys, [], []) \\<Longrightarrow>\n  (xs = [] \\<Longrightarrow> ts = [] \\<Longrightarrow> ys = [] \\<Longrightarrow> R) \\<Longrightarrow> R\"\n  by (induct I xs ts arbitrary: ys rule: mprev_next.induct) (auto split: prod.splits)\n\nlemma mprev: \"mprev_next I xs ts = (ys, xs', ts') \\<Longrightarrow>\n  list_all2 P [i..<j'] xs \\<Longrightarrow> list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [i..<j] ts \\<Longrightarrow> i \\<le> j' \\<Longrightarrow> i \\<le> j \\<Longrightarrow>\n  list_all2 (\\<lambda>i X. if mem I ((\\<tau> \\<sigma> (Suc i) - \\<tau> \\<sigma> i)) then P i X else X = empty_table)\n    [i..<min j' (if i = j then j else j-1)] ys \\<and>\n  list_all2 P [min j' (if i = j then j else j-1)..<j'] xs' \\<and>\n  list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [min j' (if i = j then j else j-1)..<j] ts'\"\nproof (induction I xs ts arbitrary: i ys xs' ts' rule: mprev_next.induct)\n  case (1 I ts)\n  then have \"min j' (if i = j then j else j-1) = i\" by auto\n  with 1 show ?case by auto\nnext\n  case (3 I v v' t)\n  then have \"min j' (j-1) = i\" by (auto simp: list_all2_Cons2 upt_eq_Cons_conv)\n  with 3 show ?case by auto\nnext\n  case (4 I x xs t t' ts)\n  from 4(1)[of \"tl ys\" xs' ts' \"Suc i\"] 4(2-6) show ?case\n    by (auto simp add: list_all2_Cons2 upt_eq_Cons_conv Suc_less_eq2\n        elim!: list.rel_mono_strong split: prod.splits if_splits)\nqed (auto simp: gr0_conv_Suc)\n\nlemma mnext: \"mprev_next I xs ts = (ys, xs', ts') \\<Longrightarrow>\n  list_all2 P [Suc i..<j'] xs \\<Longrightarrow> list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [i..<j] ts \\<Longrightarrow> Suc i \\<le> j' \\<Longrightarrow> i \\<le> j \\<Longrightarrow>\n  list_all2 (\\<lambda>i X. if mem I ((\\<tau> \\<sigma> (Suc i) - \\<tau> \\<sigma> i)) then P (Suc i) X else X = empty_table)\n    [i..<min (j'-1) ((if i = j then j else j-1))] ys \\<and>\n  list_all2 P [Suc (min (j'-1) ((if i = j then j else j-1)))..<j'] xs' \\<and>\n  list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [min (j'-1) ((if i = j then j else j-1))..<j] ts'\"\nproof (induction I xs ts arbitrary: i ys xs' ts' rule: mprev_next.induct)\n  case (1 I ts)\n  then have \"min (j' - 1) ((if i = j then j else j-1)) = i\" by auto\n  with 1 show ?case by auto\nnext\n  case (3 I v v' t)\n  then have \"min (j' - 1) ((if i = j then j else j-1)) = i\" by (auto simp: list_all2_Cons2 upt_eq_Cons_conv)\n  with 3 show ?case by auto\nnext\n  case (4 I x xs t t' ts)\n  from 4(1)[of \"tl ys\" xs' ts' \"Suc i\"] 4(2-6) show ?case\n    by (auto simp add: list_all2_Cons2 upt_eq_Cons_conv Suc_less_eq2\n        elim!: list.rel_mono_strong split: prod.splits if_splits) (* slow 10 sec *)\nqed auto\n\nlemma in_foldr_UnI: \"x \\<in> A \\<Longrightarrow> A \\<in> set xs \\<Longrightarrow> x \\<in> foldr (\\<union>) xs {}\"\n  by (induction xs) auto\n\nlemma in_foldr_UnE: \"x \\<in> foldr (\\<union>) xs {} \\<Longrightarrow> (\\<And>A. A \\<in> set xs \\<Longrightarrow> x \\<in> A \\<Longrightarrow> P) \\<Longrightarrow> P\"\n  by (induction xs) auto\n\nlemma sat_the_restrict: \"fv \\<phi> \\<subseteq> A \\<Longrightarrow> Formula.sat \\<sigma> V (map the (restrict A v)) i \\<phi> = Formula.sat \\<sigma> V (map the v) i \\<phi>\"\n  by (rule sat_fv_cong) (auto intro!: map_the_restrict)\n\nlemma eps_the_restrict: \"fv_regex r \\<subseteq> A \\<Longrightarrow> Regex.eps (Formula.sat \\<sigma> V (map the (restrict A v))) i r = Regex.eps (Formula.sat \\<sigma> V (map the v)) i r\"\n  by (rule eps_fv_cong) (auto intro!: map_the_restrict)\n\nlemma sorted_wrt_filter[simp]: \"sorted_wrt R xs \\<Longrightarrow> sorted_wrt R (filter P xs)\"\n  by (induct xs) auto\n\nlemma concat_map_filter[simp]:\n  \"concat (map f (filter P xs)) = concat (map (\\<lambda>x. if P x then f x else []) xs)\"\n  by (induct xs) auto\n\nlemma map_filter_alt:\n  \"map f (filter P xs) = concat (map (\\<lambda>x. if P x then [f x] else []) xs)\"\n  by (induct xs) auto\n\nlemma qtable_eval_args_agg:\n  \"qtable (agg_n args) (fv (packagg args \\<psi>)) (mem_restr R') (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne (packagg args \\<psi>)) (eval_args_agg args rel)\"\n  if q: \"qtable (args_n args) (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne \\<psi>) rel\"\n    and mr: \"mem_restr R = mem_restr (lift_envs' (agg_b args) R')\"\n    and valid_aggargs: \"valid_aggargs (args_n args) (fv \\<psi>) (args_agg args)\"\nproof (cases \"args_agg args\")\n  case None\n  have pack: \"packagg args \\<psi> = \\<psi>\"\n    by (auto simp add: packagg_def None)\n  have \"mem_restr R' = mem_restr R\"\n    using mr mem_restr_lift_envs'_append[of \"[]\" 0]\n    by (auto simp: agg_b_def None)\n  then show ?thesis\n    using q\n    unfolding pack\n    by (auto simp: eval_args_agg_def agg_n_def None)\nnext\n  case (Some aggargs)\n  have n_def: \"agg_n args = aggargs_n aggargs\" \"args_n args = aggargs_b aggargs + aggargs_n aggargs\"\n    using valid_aggargs\n    by (auto simp: agg_n_def Some valid_aggargs_def)\n  have x_in_colsD: \"x + aggargs_b aggargs \\<in> aggargs_cols aggargs \\<Longrightarrow> x < aggargs_n aggargs\" for x\n    using valid_aggargs\n    by (auto simp: valid_aggargs_def Some safe_aggargs_def)\n  show ?thesis\n    unfolding packagg_def Some eval_args_agg_def\n    apply (auto simp del: sat.simps fvi.simps simp: eval_aggargs_def n_def)\n    apply (rule qtable_eval_agg)\n    using q valid_aggargs mr\n    by (auto simp: n_def agg_b_def Some valid_aggargs_def safe_aggargs_def\n        fvi_iff_fv[where ?b=\"aggargs_b aggargs\"] fvi_trm_iff_fv_trm[where ?b=\"aggargs_b aggargs\"]\n        dest!: x_in_colsD)\nqed\n\nlemma (in maux) update_since:\n  assumes pre: \"wf_since_aux \\<sigma> V R args \\<phi> \\<psi> aux ne\"\n    and qtable1: \"qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne \\<phi>) rel1\"\n    and qtable2: \"qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne \\<psi>) rel2\"\n    and result_eq: \"(rel, aux') = update_since args rel1 rel2 (\\<tau> \\<sigma> ne) aux\"\n    and fvi_subset: \"Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi>\"\n    and args_ivl: \"args_ivl args = I\"\n    and args_n: \"args_n args = n\"\n    and args_L: \"args_L args = Formula.fv \\<phi>\"\n    and args_R: \"args_R args = Formula.fv \\<psi>\"\n    and args_pos: \"args_pos args = pos\"\n    and mr: \"mem_restr R = mem_restr (lift_envs' (agg_b args) R')\"\n  shows \"wf_since_aux \\<sigma> V R args \\<phi> \\<psi> aux' (Suc ne)\"\n    and \"qtable (agg_n args) (Formula.fv (packagg args (Sincep pos \\<phi> I \\<psi>))) (mem_restr R') (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne (packagg args (Sincep pos \\<phi> I \\<psi>))) rel\"\nproof -\n  let ?wf_tuple = \"\\<lambda>v. wf_tuple n (Formula.fv \\<psi>) v\"\n  note sat.simps[simp del]\n  from pre[unfolded wf_since_aux_def] obtain cur auxlist where aux: \"valid_msaux args cur aux auxlist\"\n    \"sorted_wrt (\\<lambda>x y. fst y < fst x) auxlist\"\n    \"\\<And>t X. (t, X) \\<in> set auxlist \\<Longrightarrow> ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne - 1) \\<and> memR I (\\<tau> \\<sigma> (ne - 1) - t) \\<and>\n      (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      qtable n (fv \\<psi>) (mem_restr R)\n        (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne - 1) (Sincep pos \\<phi> (point (\\<tau> \\<sigma> (ne - 1) - t)) \\<psi>)) X\"\n    \"\\<And>t. ne \\<noteq> 0 \\<Longrightarrow> t \\<le> \\<tau> \\<sigma> (ne - 1) \\<Longrightarrow> memR I (\\<tau> \\<sigma> (ne - 1) - t) \\<Longrightarrow> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<Longrightarrow>\n      (\\<exists>X. (t, X) \\<in> set auxlist)\"\n    and cur_def:\n    \"cur = (if ne = 0 then 0 else \\<tau> \\<sigma> (ne - 1))\"\n    unfolding args_ivl args_n args_pos by blast\n  from pre[unfolded wf_since_aux_def] have fv_sub: \"Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi>\" by simp\n\n  define aux0 where \"aux0 = join_msaux args rel1 (add_new_ts_msaux args (\\<tau> \\<sigma> ne) aux)\"\n  define auxlist0 where \"auxlist0 = [(t, join rel pos rel1). (t, rel) \\<leftarrow> auxlist, memR I (\\<tau> \\<sigma> ne - t)]\"\n  have tabL: \"table (args_n args) (args_L args) rel1\"\n    using qtable1[unfolded qtable_def] unfolding args_n[symmetric] args_L[symmetric] by simp\n  have cur_le: \"cur \\<le> \\<tau> \\<sigma> ne\"\n    unfolding cur_def by auto\n  have valid0: \"valid_msaux args (\\<tau> \\<sigma> ne) aux0 auxlist0\" unfolding aux0_def auxlist0_def\n    using valid_join_msaux[OF valid_add_new_ts_msaux[OF aux(1)], OF cur_le tabL]\n    by (auto simp: args_ivl args_pos cur_def map_filter_alt split_beta cong: map_cong)\n  from aux(2) have sorted_auxlist0: \"sorted_wrt (\\<lambda>x y. fst x > fst y) auxlist0\"\n    unfolding auxlist0_def\n    by (induction auxlist) (auto simp add: sorted_wrt_append)\n  have in_auxlist0_1: \"(t, X) \\<in> set auxlist0 \\<Longrightarrow> ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne-1) \\<and> memR I (\\<tau> \\<sigma> ne - t) \\<and>\n      (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. (Formula.sat \\<sigma> V (map the v) (ne-1) (Sincep pos \\<phi> (point (\\<tau> \\<sigma> (ne-1) - t)) \\<psi>) \\<and>\n        (if pos then Formula.sat \\<sigma> V (map the v) ne \\<phi> else \\<not> Formula.sat \\<sigma> V (map the v) ne \\<phi>))) X\" for t X\n    unfolding auxlist0_def using fvi_subset\n    by (auto 0 1 elim!: qtable_join[OF _ qtable1] simp: sat_the_restrict Sincep_def dest!: aux(3))\n  then have in_auxlist0_le_\\<tau>: \"(t, X) \\<in> set auxlist0 \\<Longrightarrow> t \\<le> \\<tau> \\<sigma> ne\" for t X\n    by (meson \\<tau>_mono diff_le_self le_trans)\n  have in_auxlist0_2: \"ne \\<noteq> 0 \\<Longrightarrow> t \\<le> \\<tau> \\<sigma> (ne-1) \\<Longrightarrow> memR I (\\<tau> \\<sigma> ne - t) \\<Longrightarrow> \\<exists>i. \\<tau> \\<sigma> i = t \\<Longrightarrow>\n    \\<exists>X. (t, X) \\<in> set auxlist0\" for t\n  proof -\n    fix t\n    assume \"ne \\<noteq> 0\" \"t \\<le> \\<tau> \\<sigma> (ne-1)\" \"memR I (\\<tau> \\<sigma> ne - t)\" \"\\<exists>i. \\<tau> \\<sigma> i = t\"\n    then obtain X where \"(t, X) \\<in> set auxlist\"\n      by (atomize_elim, intro aux(4))\n        (auto simp: gr0_conv_Suc elim!: order_trans[rotated] intro!: diff_le_mono \\<tau>_mono)\n    with \\<open>memR I (\\<tau> \\<sigma> ne - t)\\<close> have \"(t, join X pos rel1) \\<in> set auxlist0\"\n      unfolding auxlist0_def by (auto elim!: bexI[rotated] intro!: exI[of _ X])\n    then show \"\\<exists>X. (t, X) \\<in> set auxlist0\"\n      by blast\n  qed\n  have auxlist0_Nil: \"auxlist0 = [] \\<Longrightarrow> ne = 0 \\<or> ne \\<noteq> 0 \\<and> (\\<forall>t. t \\<le> \\<tau> \\<sigma> (ne-1) \\<and> memR I (\\<tau> \\<sigma> ne - t) \\<longrightarrow>\n        (\\<nexists>i. \\<tau> \\<sigma> i = t))\"\n    using in_auxlist0_2 by (auto)\n\n  have aux'_eq: \"aux' = add_new_table_msaux args rel2 aux0\"\n    using result_eq unfolding aux0_def update_since_def Let_def by simp\n  define auxlist' where\n    auxlist'_eq: \"auxlist' = (case auxlist0 of\n      [] \\<Rightarrow> [(\\<tau> \\<sigma> ne, rel2)]\n    | x # auxlist' \\<Rightarrow> (if fst x = \\<tau> \\<sigma> ne then (fst x, snd x \\<union> rel2) # auxlist' else (\\<tau> \\<sigma> ne, rel2) # x # auxlist'))\"\n  have tabR: \"table (args_n args) (args_R args) rel2\"\n    using qtable2[unfolded qtable_def] unfolding args_n[symmetric] args_R[symmetric] by simp\n  have valid': \"valid_msaux args (\\<tau> \\<sigma> ne) aux' auxlist'\"\n    unfolding aux'_eq auxlist'_eq using valid_add_new_table_msaux[OF valid0 tabR]\n    by (auto simp: not_le split: list.splits option.splits if_splits)\n  have sorted_auxlist': \"sorted_wrt (\\<lambda>x y. fst x > fst y) auxlist'\"\n    unfolding auxlist'_eq\n    using sorted_auxlist0 in_auxlist0_le_\\<tau> by (cases auxlist0) fastforce+\n  have in_auxlist'_1: \"t \\<le> \\<tau> \\<sigma> ne \\<and> memR I (\\<tau> \\<sigma> ne - t) \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne (Sincep pos \\<phi> (point (\\<tau> \\<sigma> ne - t)) \\<psi>)) X\"\n    if auxlist': \"(t, X) \\<in> set auxlist'\" for t X\n  proof (cases auxlist0)\n    case Nil\n    with auxlist' show ?thesis\n      unfolding auxlist'_eq Sincep_def using qtable2 auxlist0_Nil\n      by (auto simp: zero_enat_def[symmetric] sat_Since_rec[where i=ne]\n          dest: spec[of _ \"\\<tau> \\<sigma> (ne-1)\"] elim!: qtable_cong[OF _ refl])\n  next\n    case (Cons a as)\n    show ?thesis\n    proof (cases \"t = \\<tau> \\<sigma> ne\")\n      case t: True\n      show ?thesis\n      proof (cases \"fst a = \\<tau> \\<sigma> ne\")\n        case True\n        with auxlist' Cons t have \"X = snd a \\<union> rel2\"\n          unfolding auxlist'_eq using sorted_auxlist0 by (auto split: if_splits)\n        moreover from in_auxlist0_1[of \"fst a\" \"snd a\"] Cons have \"ne \\<noteq> 0\"\n          \"fst a \\<le> \\<tau> \\<sigma> (ne - 1)\" \"memR I (\\<tau> \\<sigma> ne - fst a)\" \"\\<exists>i. \\<tau> \\<sigma> i = fst a\"\n          \"qtable n (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne - 1)\n            (Sincep pos \\<phi> (point (\\<tau> \\<sigma> (ne - 1) - fst a)) \\<psi>) \\<and> (if pos then Formula.sat \\<sigma> V (map the v) ne \\<phi>\n              else \\<not> Formula.sat \\<sigma> V (map the v) ne \\<phi>)) (snd a)\"\n          by (auto simp: True[symmetric] zero_enat_def[symmetric])\n        ultimately show ?thesis unfolding Sincep_def using qtable2 t True\n          by (auto simp: sat_Since_rec[where i=ne] sat.simps(6) elim!: qtable_union)\n      next\n        case False\n        with auxlist' Cons t have \"X = rel2\"\n          unfolding auxlist'_eq using sorted_auxlist0 in_auxlist0_le_\\<tau>[of \"fst a\" \"snd a\"] by (auto split: if_splits)\n        with auxlist' Cons t False show ?thesis\n          unfolding auxlist'_eq Sincep_def using qtable2 in_auxlist0_2[of \"\\<tau> \\<sigma> (ne-1)\"] in_auxlist0_le_\\<tau>[of \"fst a\" \"snd a\"] sorted_auxlist0\n          by (auto simp: sat_Since_rec[where i=ne] sat.simps(3) zero_enat_def[symmetric] enat_0_iff not_le\n              elim!: qtable_cong[OF _ refl] dest!: le_\\<tau>_less meta_mp)\n      qed\n    next\n      case False\n      with auxlist' Cons have \"(t, X) \\<in> set auxlist0\"\n        unfolding auxlist'_eq by (auto split: if_splits)\n      then have \"ne \\<noteq> 0\" \"t \\<le> \\<tau> \\<sigma> (ne - 1)\" \"memR I (\\<tau> \\<sigma> ne - t)\" \"\\<exists>i. \\<tau> \\<sigma> i = t\"\n        \"qtable n (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne - 1) (Sincep pos \\<phi> (point (\\<tau> \\<sigma> (ne - 1) - t)) \\<psi>) \\<and>\n           (if pos then Formula.sat \\<sigma> V (map the v) ne \\<phi> else \\<not> Formula.sat \\<sigma> V (map the v) ne \\<phi>)) X\"\n        using in_auxlist0_1 by blast+\n      with False auxlist' Cons show ?thesis\n        unfolding auxlist'_eq Sincep_def\n        by (fastforce simp: sat_Since_rec[where i=ne] sat.simps(6)\n            diff_diff_right[where i=\"\\<tau> \\<sigma> ne\" and j=\"\\<tau> \\<sigma> _ + \\<tau> \\<sigma> ne\" and k=\"\\<tau> \\<sigma> (ne - 1)\",\n              OF trans_le_add2, simplified] elim!: qtable_cong[OF _ refl] order_trans dest: le_\\<tau>_less)\n    qed\n  qed\n\n  have in_auxlist'_2: \"\\<exists>X. (t, X) \\<in> set auxlist'\" if \"t \\<le> \\<tau> \\<sigma> ne\" \"memR I (\\<tau> \\<sigma> ne - t)\" \"\\<exists>i. \\<tau> \\<sigma> i = t\" for t\n  proof (cases \"t = \\<tau> \\<sigma> ne\")\n    case True\n    then show ?thesis\n    proof (cases auxlist0)\n      case Nil\n      with True show ?thesis unfolding auxlist'_eq by (simp add: zero_enat_def[symmetric])\n    next\n      case (Cons a as)\n      with True show ?thesis unfolding auxlist'_eq\n        by (cases \"fst a = \\<tau> \\<sigma> ne\") (auto simp: zero_enat_def[symmetric])\n    qed\n  next\n    case False\n    with that have \"ne \\<noteq> 0\"\n      using le_\\<tau>_less neq0_conv by blast\n    moreover from False that have  \"t \\<le> \\<tau> \\<sigma> (ne-1)\"\n      by (metis One_nat_def Suc_leI Suc_pred \\<tau>_mono diff_is_0_eq' order.antisym neq0_conv not_le)\n    ultimately obtain X where \"(t, X) \\<in> set auxlist0\" using \\<open>memR I (\\<tau> \\<sigma> ne - t)\\<close> \\<open>\\<exists>i. \\<tau> \\<sigma> i = t\\<close>\n      using \\<tau>_mono[of \"ne - 1\" \"ne\" \\<sigma>] by (atomize_elim) (auto intro!: in_auxlist0_2 simp del: \\<tau>_mono)\n    then show ?thesis unfolding auxlist'_eq using False \\<open>memR I (\\<tau> \\<sigma> ne - t)\\<close>\n      by (auto intro: exI[of _ X] split: list.split)\n  qed\n\n  show \"wf_since_aux \\<sigma> V R args \\<phi> \\<psi> aux' (Suc ne)\"\n    using pre\n    unfolding wf_since_aux_def args_ivl args_n args_pos\n    by (auto simp add: fv_sub dest: in_auxlist'_1 intro: sorted_auxlist' in_auxlist'_2\n        intro!: exI[of _ auxlist'] valid')\n\n  have rel_msaux: \"rel = result_msaux args aux'\"\n    using result_eq by (auto simp add: update_since_def Let_def)\n  have rel_eq: \"rel = eval_args_agg args (foldr (\\<union>) [rel. (t, rel) \\<leftarrow> auxlist', memL I (\\<tau> \\<sigma> ne - t)] {})\"\n    by (auto simp: args_ivl rel_msaux valid_result_msaux[OF valid'])\n  have rel_alt: \"rel = eval_args_agg args (\\<Union>(t, rel) \\<in> set auxlist'. if memL I (\\<tau> \\<sigma> ne - t) then rel else empty_table)\"\n    unfolding rel_eq\n    by (auto elim!: in_foldr_UnE bexI[rotated] intro!: in_foldr_UnI arg_cong[where ?f=\"\\<lambda>x. eval_args_agg args x\"])\n  have qtable_since: \"qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne (Sincep pos \\<phi> I \\<psi>))\n    (\\<Union>(t, rel) \\<in> set auxlist'. if memL I (\\<tau> \\<sigma> ne - t) then rel else empty_table)\"\n  proof (rule qtable_Union[where Qi=\"\\<lambda>(t, X) v.\n    memL I (\\<tau> \\<sigma> ne - t) \\<and> Formula.sat \\<sigma> V (map the v) ne (Sincep pos \\<phi> (point (\\<tau> \\<sigma> ne - t)) \\<psi>)\"],\n        goal_cases finite qtable equiv)\n    case (equiv v)\n    show ?case\n      unfolding Sincep_def\n    proof (rule iffI, erule sat_Since_point, goal_cases left right)\n      case (left j)\n      then show ?case using in_auxlist'_2[of \"\\<tau> \\<sigma> j\", OF _ _ exI, OF _ _ refl] by auto\n    next\n      case right\n      then show ?case by (auto elim!: sat_Since_pointD dest: in_auxlist'_1)\n    qed\n  qed (auto dest!: in_auxlist'_1 intro!: qtable_empty)\n  have fv: \"fv (Sincep pos \\<phi> I \\<psi>) = fv \\<psi>\"\n    using fvi_subset\n    by (auto simp: Sincep_def)\n  show \"qtable (agg_n args) (fv (packagg args (Sincep pos \\<phi> I \\<psi>))) (mem_restr R') (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne (packagg args (Sincep pos \\<phi> I \\<psi>))) rel\"\n    unfolding rel_alt\n    apply (rule qtable_eval_args_agg[OF _ mr])\n    using qtable_since pre\n    by (auto simp: args_n fv wf_since_aux_def)\nqed\n\nlemma fv_regex_from_mregex:\n  \"ok (length \\<phi>s) mr \\<Longrightarrow> fv_regex (from_mregex mr \\<phi>s) \\<subseteq> (\\<Union>\\<phi> \\<in> set \\<phi>s. fv \\<phi>)\"\n  by (induct mr) (auto simp: Bex_def in_set_conv_nth)+\n\nlemma qtable_\\<epsilon>_lax:\n  assumes \"ok (length \\<phi>s) mr\"\n    and \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>) rel) \\<phi>s rels\"\n    and \"fv_regex (from_mregex mr \\<phi>s) \\<subseteq> A\" and \"qtable n A (mem_restr R) Q guard\"\n  shows \"qtable n A (mem_restr R)\n   (\\<lambda>v. Regex.eps (Formula.sat \\<sigma> V (map the v)) i (from_mregex mr \\<phi>s) \\<and> Q v) (\\<epsilon>_lax guard rels mr)\"\n  using assms\nproof (induct mr)\n  case (MPlus mr1 mr2)\n  from MPlus(3-6) show ?case\n    by (auto intro!: qtable_union[OF MPlus(1,2)])\nnext\n  case (MTimes mr1 mr2)\n  then have \"fv_regex (from_mregex mr1 \\<phi>s) \\<subseteq> A\" \"fv_regex (from_mregex mr2 \\<phi>s) \\<subseteq> A\"\n    using fv_regex_from_mregex[of \\<phi>s mr1] fv_regex_from_mregex[of \\<phi>s mr2] by (auto simp: subset_eq)\n  with MTimes(3-6) show ?case\n    by (auto simp: eps_the_restrict restrict_idle intro!: qtable_join[OF MTimes(1,2)])\nqed (auto split: prod.splits if_splits simp: qtable_empty_iff list_all2_conv_all_nth\n    in_set_conv_nth restrict_idle sat_the_restrict\n    intro: in_qtableI qtableI elim!: qtable_join[where A=A and C=A])\n\nlemma nullary_qtable_cases: \"qtable n {} P Q X \\<Longrightarrow> (X = empty_table \\<or> X = unit_table n)\"\n  by (simp add: qtable_def table_empty)\n\nlemma qtable_empty_unit_table:\n  \"qtable n {} R P empty_table \\<Longrightarrow> qtable n {} R (\\<lambda>v. \\<not> P v) (unit_table n)\"\n  by (auto intro: qtable_unit_table simp add: qtable_empty_iff)\n\nlemma qtable_unit_empty_table:\n  \"qtable n {} R P (unit_table n) \\<Longrightarrow> qtable n {} R (\\<lambda>v. \\<not> P v) empty_table\"\n  by (auto intro!: qtable_empty elim: in_qtableE simp add: wf_tuple_empty unit_table_def)\n\nlemma qtable_nonempty_empty_table:\n  \"qtable n {} R P X \\<Longrightarrow> x \\<in> X \\<Longrightarrow> qtable n {} R (\\<lambda>v. \\<not> P v) empty_table\"\n  by (frule nullary_qtable_cases) (auto dest: qtable_unit_empty_table)\n\n\nlemma qtable_r\\<epsilon>_strict:\n  assumes \"safe_regex Past Strict (from_mregex mr \\<phi>s)\" \"ok (length \\<phi>s) mr\" \"A = fv_regex (from_mregex mr \\<phi>s)\"\n    and \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>) rel) \\<phi>s rels\"\n  shows \"qtable n A (mem_restr R) (\\<lambda>v. Regex.eps (Formula.sat \\<sigma> V (map the v)) i (from_mregex mr \\<phi>s)) (r\\<epsilon>_strict n rels mr)\"\n  using assms\nproof (hypsubst, induct Past Strict \"from_mregex mr \\<phi>s\" arbitrary: mr rule: safe_regex_induct)\n  case (Skip n)\n  then show ?case\n    by (cases mr) (auto simp: qtable_empty_iff qtable_unit_table split: if_splits)\nnext\n  case (Test \\<phi>)\n  then show ?case\n    by (cases mr) (auto simp: list_all2_conv_all_nth qtable_empty_unit_table\n        dest!: qtable_nonempty_empty_table split: if_splits)\nnext\n  case (Plus r s)\n  then show ?case\n    by (cases mr) (fastforce intro: qtable_union split: if_splits)+\nnext\n  case (TimesP r s)\n  then show ?case\n    by (cases mr) (auto intro: qtable_cong[OF qtable_\\<epsilon>_lax] split: if_splits)+\nnext\n  case (Star r)\n  then show ?case\n    by (cases mr) (auto simp: qtable_unit_table split: if_splits)\nqed\n\nlemma qtable_l\\<epsilon>_strict:\n  assumes \"safe_regex Futu Strict (from_mregex mr \\<phi>s)\" \"ok (length \\<phi>s) mr\" \"A = fv_regex (from_mregex mr \\<phi>s)\"\n    and \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>) rel) \\<phi>s rels\"\n  shows \"qtable n A (mem_restr R) (\\<lambda>v. Regex.eps (Formula.sat \\<sigma> V (map the v)) i (from_mregex mr \\<phi>s)) (l\\<epsilon>_strict n rels mr)\"\n  using assms\nproof (hypsubst, induct Futu Strict \"from_mregex mr \\<phi>s\" arbitrary: mr rule: safe_regex_induct)\n  case (Skip n)\n  then show ?case\n    by (cases mr) (auto simp: qtable_empty_iff qtable_unit_table split: if_splits)\nnext\n  case (Test \\<phi>)\n  then show ?case\n    by (cases mr) (auto simp: list_all2_conv_all_nth qtable_empty_unit_table\n        dest!: qtable_nonempty_empty_table split: if_splits)\nnext\n  case (Plus r s)\n  then show ?case\n    by (cases mr) (fastforce intro: qtable_union split: if_splits)+\nnext\n  case (TimesF r s)\n  then show ?case\n    by (cases mr) (auto intro: qtable_cong[OF qtable_\\<epsilon>_lax] split: if_splits)+\nnext\n  case (Star r)\n  then show ?case\n    by (cases mr) (auto simp: qtable_unit_table split: if_splits)\nqed\n\nlemma rtranclp_False: \"(\\<lambda>i j. False)\\<^sup>*\\<^sup>* = (=)\"\nproof -\n  have \"(\\<lambda>i j. False)\\<^sup>*\\<^sup>* i j \\<Longrightarrow> i = j\" for i j :: 'a\n    by (induct i j rule: rtranclp.induct) auto\n  then show ?thesis\n    by (auto intro: exI[of _ 0])\nqed\n\ninductive ok_rctxt for \\<phi>s where\n  \"ok_rctxt \\<phi>s id id\"\n| \"ok_rctxt \\<phi>s \\<kappa> \\<kappa>' \\<Longrightarrow> ok_rctxt \\<phi>s (\\<lambda>t. \\<kappa> (MTimes mr t)) (\\<lambda>t. \\<kappa>' (Regex.Times (from_mregex mr \\<phi>s) t))\"\n\nlemma ok_rctxt_swap: \"ok_rctxt \\<phi>s \\<kappa> \\<kappa>' \\<Longrightarrow> from_mregex (\\<kappa> mr) \\<phi>s = \\<kappa>' (from_mregex mr \\<phi>s)\"\n  by (induct \\<kappa> \\<kappa>' arbitrary: mr rule: ok_rctxt.induct) auto\n\nlemma ok_rctxt_cong: \"ok_rctxt \\<phi>s \\<kappa> \\<kappa>' \\<Longrightarrow> Regex.match (Formula.sat \\<sigma> V v) r = Regex.match (Formula.sat \\<sigma> V v) s \\<Longrightarrow>\n  Regex.match (Formula.sat \\<sigma> V v) (\\<kappa>' r) i j = Regex.match (Formula.sat \\<sigma> V v) (\\<kappa>' s) i j\"\n  by (induct \\<kappa> \\<kappa>' arbitrary: r s rule: ok_rctxt.induct) simp_all\n\nlemma qtable_r\\<delta>\\<kappa>:\n  assumes \"ok (length \\<phi>s) mr\" \"fv_regex (from_mregex mr \\<phi>s) \\<subseteq> A\"\n    and \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) j \\<phi>) rel) \\<phi>s rels\"\n    and \"ok_rctxt \\<phi>s \\<kappa> \\<kappa>'\"\n    and \"\\<forall>ms \\<in> \\<kappa> ` RPD mr. qtable n A (mem_restr R) (\\<lambda>v. Q (map the v) (from_mregex ms \\<phi>s)) (lookup rel ms)\"\n  shows \"qtable n A (mem_restr R)\n  (\\<lambda>v. \\<exists>s \\<in> Regex.rpd\\<kappa> \\<kappa>' (Formula.sat \\<sigma> V (map the v)) j (from_mregex mr \\<phi>s). Q (map the v) s)\n  (r\\<delta> \\<kappa> rel rels mr)\"\n  using assms\nproof (induct mr arbitrary: \\<kappa> \\<kappa>')\n  case MSkip\n  then show ?case\n    by (auto simp: rtranclp_False ok_rctxt_swap qtable_empty_iff\n        elim!: qtable_cong[OF _ _ ok_rctxt_cong[of _ \\<kappa> \\<kappa>']] split: nat.splits)\nnext\n  case (MPlus mr1 mr2)\n  from MPlus(3-7) show ?case\n    by (auto intro!: qtable_union[OF MPlus(1,2)])\nnext\n  case (MTimes mr1 mr2)\n  from MTimes(3-7) show ?case\n    by (auto intro!: qtable_union[OF MTimes(2) qtable_\\<epsilon>_lax[OF _ _ _ MTimes(1)]]\n        elim!: ok_rctxt.intros(2) simp: MTimesL_def Ball_def)\nnext\n  case (MStar mr)\n  from MStar(2-6) show ?case\n    by (auto intro!: qtable_cong[OF MStar(1)] intro: ok_rctxt.intros simp: MTimesL_def Ball_def)\nqed (auto simp: qtable_empty_iff)\n\nlemmas qtable_r\\<delta> = qtable_r\\<delta>\\<kappa>[OF _ _ _ ok_rctxt.intros(1), unfolded rpd\\<kappa>_rpd image_id id_apply]\n\ninductive ok_lctxt for \\<phi>s where\n  \"ok_lctxt \\<phi>s id id\"\n| \"ok_lctxt \\<phi>s \\<kappa> \\<kappa>' \\<Longrightarrow> ok_lctxt \\<phi>s (\\<lambda>t. \\<kappa> (MTimes t mr)) (\\<lambda>t. \\<kappa>' (Regex.Times t (from_mregex mr \\<phi>s)))\"\n\nlemma ok_lctxt_swap: \"ok_lctxt \\<phi>s \\<kappa> \\<kappa>' \\<Longrightarrow> from_mregex (\\<kappa> mr) \\<phi>s = \\<kappa>' (from_mregex mr \\<phi>s)\"\n  by (induct \\<kappa> \\<kappa>' arbitrary: mr rule: ok_lctxt.induct) auto\n\nlemma ok_lctxt_cong: \"ok_lctxt \\<phi>s \\<kappa> \\<kappa>' \\<Longrightarrow> Regex.match (Formula.sat \\<sigma> V v) r = Regex.match (Formula.sat \\<sigma> V v) s \\<Longrightarrow>\n  Regex.match (Formula.sat \\<sigma> V v) (\\<kappa>' r) i j = Regex.match (Formula.sat \\<sigma> V v) (\\<kappa>' s) i j\"\n  by (induct \\<kappa> \\<kappa>' arbitrary: r s rule: ok_lctxt.induct) simp_all\n\nlemma qtable_l\\<delta>\\<kappa>:\n  assumes \"ok (length \\<phi>s) mr\" \"fv_regex (from_mregex mr \\<phi>s) \\<subseteq> A\"\n    and \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) j \\<phi>) rel) \\<phi>s rels\"\n    and \"ok_lctxt \\<phi>s \\<kappa> \\<kappa>'\"\n    and \"\\<forall>ms \\<in> \\<kappa> ` LPD mr. qtable n A (mem_restr R) (\\<lambda>v. Q (map the v) (from_mregex ms \\<phi>s)) (lookup rel ms)\"\n  shows \"qtable n A (mem_restr R)\n  (\\<lambda>v. \\<exists>s \\<in> Regex.lpd\\<kappa> \\<kappa>' (Formula.sat \\<sigma> V (map the v)) j (from_mregex mr \\<phi>s). Q (map the v) s)\n  (l\\<delta> \\<kappa> rel rels mr)\"\n  using assms\nproof (induct mr arbitrary: \\<kappa> \\<kappa>')\n  case MSkip\n  then show ?case\n    by (auto simp: rtranclp_False ok_lctxt_swap qtable_empty_iff\n        elim!: qtable_cong[OF _ _ ok_rctxt_cong[of _ \\<kappa> \\<kappa>']] split: nat.splits)\nnext\n  case (MPlus mr1 mr2)\n  from MPlus(3-7) show ?case\n    by (auto intro!: qtable_union[OF MPlus(1,2)])\nnext\n  case (MTimes mr1 mr2)\n  from MTimes(3-7) show ?case\n    by (auto intro!: qtable_union[OF MTimes(1) qtable_\\<epsilon>_lax[OF _ _ _ MTimes(2)]]\n        elim!: ok_lctxt.intros(2) simp: MTimesR_def Ball_def)\nnext\n  case (MStar mr)\n  from MStar(2-6) show ?case\n    by (auto intro!: qtable_cong[OF MStar(1)] intro: ok_lctxt.intros simp: MTimesR_def Ball_def)\nqed (auto simp: qtable_empty_iff)\n\nlemmas qtable_l\\<delta> = qtable_l\\<delta>\\<kappa>[OF _ _ _ ok_lctxt.intros(1), unfolded lpd\\<kappa>_lpd image_id id_apply]\n\nlemma RPD_fv_regex_le:\n  \"ms \\<in> RPD mr \\<Longrightarrow> fv_regex (from_mregex ms \\<phi>s) \\<subseteq> fv_regex (from_mregex mr \\<phi>s)\"\n  by (induct mr arbitrary: ms) (auto simp: MTimesL_def split: nat.splits)+\n\nlemma RPD_safe: \"safe_regex Past g (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> RPD mr \\<Longrightarrow> safe_regex Past g (from_mregex ms \\<phi>s)\"\nproof (induct Past g \"from_mregex mr \\<phi>s\" arbitrary: mr ms rule: safe_regex_induct)\n  case Skip\n  then show ?case\n    by (cases mr) (auto split: nat.splits)\nnext\n  case (Test g \\<phi>)\n  then show ?case\n    by (cases mr) auto\nnext\n  case (Plus g r s mrs)\n  then show ?case\n  proof (cases mrs)\n    case (MPlus mr ms)\n    with Plus(3-5) show ?thesis\n      by (auto dest!: Plus(1,2))\n  qed auto\nnext\n  case (TimesP g r s mrs)\n  then show ?case\n  proof (cases mrs)\n    case (MTimes mr ms)\n    with TimesP(3-5) show ?thesis\n      by (cases g) (auto 0 4 simp: MTimesL_def dest: RPD_fv_regex_le TimesP(1,2))\n  qed auto\nnext\n  case (Star g r)\n  then show ?case\n  proof (cases mr)\n    case (MStar x6)\n    with Star(2-4) show ?thesis\n      by (cases g) (auto 0 4 simp: MTimesL_def dest: RPD_fv_regex_le\n          elim!: safe_cosafe[rotated] dest!: Star(1))\n  qed auto\nqed\n\nlemma RPDi_safe: \"safe_regex Past g (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> RPDi n mr ==> safe_regex Past g (from_mregex ms \\<phi>s)\"\n  by (induct n arbitrary: ms mr) (auto dest: RPD_safe)\n\nlemma RPDs_safe: \"safe_regex Past g (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> RPDs mr ==> safe_regex Past g (from_mregex ms \\<phi>s)\"\n  unfolding RPDs_def by (auto dest: RPDi_safe)\n\nlemma RPD_safe_fv_regex: \"safe_regex Past Strict (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> RPD mr \\<Longrightarrow> fv_regex (from_mregex ms \\<phi>s) = fv_regex (from_mregex mr \\<phi>s)\"\nproof (induct Past Strict \"from_mregex mr \\<phi>s\" arbitrary: mr rule: safe_regex_induct)\n  case (Skip n)\n  then show ?case\n    by (cases mr) (auto split: nat.splits)\nnext\n  case (Test \\<phi>)\n  then show ?case\n    by (cases mr) auto\nnext\n  case (Plus r s)\n  then show ?case\n    by (cases mr) auto\nnext\n  case (TimesP r s)\n  then show ?case\n    by (cases mr) (auto 0 3 simp: MTimesL_def dest: RPD_fv_regex_le split: modality.splits)\nnext\n  case (Star r)\n  then show ?case\n    by (cases mr) (auto 0 3 simp: MTimesL_def dest: RPD_fv_regex_le)\nqed\n\nlemma RPDi_safe_fv_regex: \"safe_regex Past Strict (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> RPDi n mr ==> fv_regex (from_mregex ms \\<phi>s) = fv_regex (from_mregex mr \\<phi>s)\"\n  by (induct n arbitrary: ms mr) (auto 5 0 dest: RPD_safe_fv_regex RPD_safe)\n\nlemma RPDs_safe_fv_regex: \"safe_regex Past Strict (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> RPDs mr ==> fv_regex (from_mregex ms \\<phi>s) = fv_regex (from_mregex mr \\<phi>s)\"\n  unfolding RPDs_def by (auto dest: RPDi_safe_fv_regex)\n\nlemma RPD_ok: \"ok m mr \\<Longrightarrow> ms \\<in> RPD mr \\<Longrightarrow> ok m ms\"\nproof (induct mr arbitrary: ms)\n  case (MPlus mr1 mr2)\n  from MPlus(3,4) show ?case\n    by (auto elim: MPlus(1,2))\nnext\n  case (MTimes mr1 mr2)\n  from MTimes(3,4) show ?case\n    by (auto elim: MTimes(1,2) simp: MTimesL_def)\nnext\n  case (MStar mr)\n  from MStar(2,3) show ?case\n    by (auto elim: MStar(1) simp: MTimesL_def)\nqed (auto split: nat.splits)\n\nlemma RPDi_ok: \"ok m mr \\<Longrightarrow> ms \\<in> RPDi n mr \\<Longrightarrow> ok m ms\"\n  by (induct n arbitrary: ms mr) (auto intro: RPD_ok)\n\nlemma RPDs_ok: \"ok m mr \\<Longrightarrow> ms \\<in> RPDs mr \\<Longrightarrow> ok m ms\"\n  unfolding RPDs_def by (auto intro: RPDi_ok)\n\nlemma LPD_fv_regex_le:\n  \"ms \\<in> LPD mr \\<Longrightarrow> fv_regex (from_mregex ms \\<phi>s) \\<subseteq> fv_regex (from_mregex mr \\<phi>s)\"\n  by (induct mr arbitrary: ms) (auto simp: MTimesR_def split: nat.splits)+\n\nlemma LPD_safe: \"safe_regex Futu g (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> LPD mr ==> safe_regex Futu g (from_mregex ms \\<phi>s)\"\nproof (induct Futu g \"from_mregex mr \\<phi>s\" arbitrary: mr ms rule: safe_regex_induct)\n  case Skip\n  then show ?case\n    by (cases mr) (auto split: nat.splits)\nnext\n  case (Test g \\<phi>)\n  then show ?case\n    by (cases mr) auto\nnext\n  case (Plus g r s mrs)\n  then show ?case\n  proof (cases mrs)\n    case (MPlus mr ms)\n    with Plus(3-5) show ?thesis\n      by (auto dest!: Plus(1,2))\n  qed auto\nnext\n  case (TimesF g r s mrs)\n  then show ?case\n  proof (cases mrs)\n    case (MTimes mr ms)\n    with TimesF(3-5) show ?thesis\n      by (cases g) (auto 0 4 simp: MTimesR_def dest: LPD_fv_regex_le split: modality.splits dest: TimesF(1,2))\n  qed auto\nnext\n  case (Star g r)\n  then show ?case\n  proof (cases mr)\n    case (MStar x6)\n    with Star(2-4) show ?thesis\n      by (cases g) (auto 0 4 simp: MTimesR_def dest: LPD_fv_regex_le\n          elim!: safe_cosafe[rotated] dest!: Star(1))\n  qed auto\nqed\n\nlemma LPDi_safe: \"safe_regex Futu g (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> LPDi n mr ==> safe_regex Futu g (from_mregex ms \\<phi>s)\"\n  by (induct n arbitrary: ms mr) (auto dest: LPD_safe)\n\nlemma LPDs_safe: \"safe_regex Futu g (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> LPDs mr ==> safe_regex Futu g (from_mregex ms \\<phi>s)\"\n  unfolding LPDs_def by (auto dest: LPDi_safe)\n\nlemma LPD_safe_fv_regex: \"safe_regex Futu Strict (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> LPD mr ==> fv_regex (from_mregex ms \\<phi>s) = fv_regex (from_mregex mr \\<phi>s)\"\nproof (induct Futu Strict \"from_mregex mr \\<phi>s\" arbitrary: mr rule: safe_regex_induct)\n  case Skip\n  then show ?case\n    by (cases mr) (auto split: nat.splits)\nnext\n  case (Test \\<phi>)\n  then show ?case\n    by (cases mr) auto\nnext\n  case (Plus r s)\n  then show ?case\n    by (cases mr) auto\nnext\n  case (TimesF r s)\n  then show ?case\n    by (cases mr) (auto 0 3 simp: MTimesR_def dest: LPD_fv_regex_le split: modality.splits)\nnext\n  case (Star r)\n  then show ?case\n    by (cases mr) (auto 0 3 simp: MTimesR_def dest: LPD_fv_regex_le)\nqed\n\nlemma LPDi_safe_fv_regex: \"safe_regex Futu Strict (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> LPDi n mr ==> fv_regex (from_mregex ms \\<phi>s) = fv_regex (from_mregex mr \\<phi>s)\"\n  by (induct n arbitrary: ms mr) (auto 5 0 dest: LPD_safe_fv_regex LPD_safe)\n\nlemma LPDs_safe_fv_regex: \"safe_regex Futu Strict (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> LPDs mr ==> fv_regex (from_mregex ms \\<phi>s) = fv_regex (from_mregex mr \\<phi>s)\"\n  unfolding LPDs_def by (auto dest: LPDi_safe_fv_regex)\n\nlemma LPD_ok: \"ok m mr \\<Longrightarrow> ms \\<in> LPD mr \\<Longrightarrow> ok m ms\"\nproof (induct mr arbitrary: ms)\n  case (MPlus mr1 mr2)\n  from MPlus(3,4) show ?case\n    by (auto elim: MPlus(1,2))\nnext\n  case (MTimes mr1 mr2)\n  from MTimes(3,4) show ?case\n    by (auto elim: MTimes(1,2) simp: MTimesR_def)\nnext\n  case (MStar mr)\n  from MStar(2,3) show ?case\n    by (auto elim: MStar(1) simp: MTimesR_def)\nqed (auto split: nat.splits)\n\nlemma LPDi_ok: \"ok m mr \\<Longrightarrow> ms \\<in> LPDi n mr \\<Longrightarrow> ok m ms\"\n  by (induct n arbitrary: ms mr) (auto intro: LPD_ok)\n\nlemma LPDs_ok: \"ok m mr \\<Longrightarrow> ms \\<in> LPDs mr \\<Longrightarrow> ok m ms\"\n  unfolding LPDs_def by (auto intro: LPDi_ok)\n\nlemma update_matchP:\n  assumes pre: \"wf_matchP_aux \\<sigma> V n R I r aux ne\"\n    and safe: \"safe_regex Past Strict r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (RPDs mr)\"\n    and qtables: \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne \\<phi>) rel) \\<phi>s rels\"\n    and result_eq: \"(rel, aux') = update_matchP n I mr mrs rels (\\<tau> \\<sigma> ne) aux\"\n  shows \"wf_matchP_aux \\<sigma> V n R I r aux' (Suc ne)\"\n    and \"qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne (Formula.MatchP I r)) rel\"\nproof -\n  let ?wf_tuple = \"\\<lambda>v. wf_tuple n (Formula.fv_regex r) v\"\n  let ?update = \"\\<lambda>rel t. mrtabulate mrs (\\<lambda>mr.\n    r\\<delta> id rel rels mr \\<union> (if t = \\<tau> \\<sigma> ne then r\\<epsilon>_strict n rels mr else {}))\"\n  note sat.simps[simp del]\n\n  define aux0 where \"aux0 = [(t, ?update rel t). (t, rel) \\<leftarrow> aux, memR I (\\<tau> \\<sigma> ne - t)]\"\n  have sorted_aux0: \"sorted_wrt (\\<lambda>x y. fst x > fst y) aux0\"\n    using pre[unfolded wf_matchP_aux_def, THEN conjunct1]\n    unfolding aux0_def\n    by (induction aux) (auto simp add: sorted_wrt_append)\n  { fix ms\n    assume \"ms \\<in> RPDs mr\"\n    then have \"fv_regex (from_mregex ms \\<phi>s) = fv_regex r\"\n      \"safe_regex Past Strict (from_mregex ms \\<phi>s)\" \"ok (length \\<phi>s) ms\" \"RPD ms \\<subseteq> RPDs mr\"\n      using safe RPDs_safe RPDs_safe_fv_regex mr from_mregex_to_mregex RPDs_ok to_mregex_ok RPDs_trans\n      by fastforce+\n  } note * = this\n  have **: \"\\<tau> \\<sigma> ne - (\\<tau> \\<sigma> i + \\<tau> \\<sigma> ne - \\<tau> \\<sigma> (ne - Suc 0)) = \\<tau> \\<sigma> (ne - Suc 0) - \\<tau> \\<sigma> i\" for i\n    by (metis (no_types, lifting) Nat.diff_diff_right \\<tau>_mono add.commute add_diff_cancel_left diff_le_self le_add2 order_trans)\n  have ***: \"\\<tau> \\<sigma> i = \\<tau> \\<sigma> ne\"\n    if  \"\\<tau> \\<sigma> ne \\<le> \\<tau> \\<sigma> i\" \"\\<tau> \\<sigma> i \\<le> \\<tau> \\<sigma> (ne - Suc 0)\" \"ne > 0\" for i\n    by (metis (no_types, lifting) Suc_pred \\<tau>_mono diff_le_self le_\\<tau>_less le_antisym not_less_eq that)\n  then have in_aux0_1: \"(t, X) \\<in> set aux0 \\<Longrightarrow> ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> ne \\<and> memR I (\\<tau> \\<sigma> ne - t) \\<and>\n      (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      (\\<forall>ms\\<in>RPDs mr. qtable n (fv_regex r) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne\n         (Formula.MatchP (point (\\<tau> \\<sigma> ne - t)) (from_mregex ms \\<phi>s))) (lookup X ms))\" for t X\n    unfolding aux0_def using safe mr mrs\n    by (auto simp: lookup_tabulate map_of_map_restrict restrict_map_def finite_RPDs * ** RPDs_trans diff_le_mono2\n        intro!: sat_MatchP_rec[of \\<sigma> _ _ ne, THEN iffD2]\n        qtable_union[OF qtable_r\\<delta>[OF _ _ qtables] qtable_r\\<epsilon>_strict[OF _ _ _ qtables],\n          of ms \"fv_regex r\" \"\\<lambda>v r. Formula.sat \\<sigma> V v (ne - Suc 0) (Formula.MatchP (point 0) r)\" _ ms for ms]\n        qtable_cong[OF qtable_r\\<delta>[OF _ _ qtables],\n          of ms \"fv_regex r\" \"\\<lambda>v r. Formula.sat \\<sigma> V v (ne - Suc 0) (Formula.MatchP (point (\\<tau> \\<sigma> (ne - Suc 0) - \\<tau> \\<sigma> i)) r)\"\n          _ _  \"(\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne (Formula.MatchP (point (\\<tau> \\<sigma> ne - \\<tau> \\<sigma> i))  (from_mregex ms \\<phi>s)))\" for ms i]\n        dest!: assms(1)[unfolded wf_matchP_aux_def, THEN conjunct2, THEN conjunct1, rule_format]\n        sat_MatchP_rec[\"of\" \\<sigma> _ _ ne, THEN iffD1]\n        elim!: bspec order.trans[OF _ \\<tau>_mono] bexI[rotated] split: option.splits if_splits) (* slow 7 sec *)\n  then have in_aux0_le_\\<tau>: \"(t, X) \\<in> set aux0 \\<Longrightarrow> t \\<le> \\<tau> \\<sigma> ne\" for t X\n    by (meson \\<tau>_mono diff_le_self le_trans)\n  have in_aux0_2: \"ne \\<noteq> 0 \\<Longrightarrow> t \\<le> \\<tau> \\<sigma> (ne-1) \\<Longrightarrow> memR I (\\<tau> \\<sigma> ne - t) \\<Longrightarrow> \\<exists>i. \\<tau> \\<sigma> i = t \\<Longrightarrow>\n    \\<exists>X. (t, X) \\<in> set aux0\" for t\n  proof -\n    fix t\n    assume \"ne \\<noteq> 0\" \"t \\<le> \\<tau> \\<sigma> (ne-1)\" \"memR I (\\<tau> \\<sigma> ne - t)\" \"\\<exists>i. \\<tau> \\<sigma> i = t\"\n    then obtain X where \"(t, X) \\<in> set aux\"\n      by (atomize_elim, intro assms(1)[unfolded wf_matchP_aux_def, THEN conjunct2, THEN conjunct2, rule_format])\n        (auto simp: gr0_conv_Suc elim!: order_trans[rotated] intro!: diff_le_mono \\<tau>_mono)\n    with \\<open>memR I (\\<tau> \\<sigma> ne - t)\\<close> have \"(t, ?update X t) \\<in> set aux0\"\n      unfolding aux0_def by (auto simp: id_def elim!: bexI[rotated] intro!: exI[of _ X])\n    then show \"\\<exists>X. (t, X) \\<in> set aux0\"\n      by blast\n  qed\n  have aux0_Nil: \"aux0 = [] \\<Longrightarrow> ne = 0 \\<or> ne \\<noteq> 0 \\<and> (\\<forall>t. t \\<le> \\<tau> \\<sigma> (ne-1) \\<and> memR I (\\<tau> \\<sigma> ne - t) \\<longrightarrow>\n        (\\<nexists>i. \\<tau> \\<sigma> i = t))\"\n    using in_aux0_2 by (cases \"ne = 0\") (auto)\n\n  have aux'_eq: \"aux' = (case aux0 of\n      [] \\<Rightarrow> [(\\<tau> \\<sigma> ne, mrtabulate mrs (r\\<epsilon>_strict n rels))]\n    | x # aux' \\<Rightarrow> (if fst x = \\<tau> \\<sigma> ne then x # aux'\n       else (\\<tau> \\<sigma> ne, mrtabulate mrs (r\\<epsilon>_strict n rels)) # x # aux'))\"\n    using result_eq unfolding aux0_def update_matchP_def Let_def by simp\n  have sorted_aux': \"sorted_wrt (\\<lambda>x y. fst x > fst y) aux'\"\n    unfolding aux'_eq\n    using sorted_aux0 in_aux0_le_\\<tau> by (cases aux0) (fastforce)+\n\n  have in_aux'_1: \"t \\<le> \\<tau> \\<sigma> ne \\<and> memR I (\\<tau> \\<sigma> ne - t) \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n     (\\<forall>ms\\<in>RPDs mr. qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v.\n        Formula.sat \\<sigma> V (map the v) ne (Formula.MatchP (point (\\<tau> \\<sigma> ne - t)) (from_mregex ms \\<phi>s))) (lookup X ms))\"\n    if aux': \"(t, X) \\<in> set aux'\" for t X\n  proof (cases aux0)\n    case Nil\n    with aux' show ?thesis\n      unfolding aux'_eq using safe mrs qtables aux0_Nil *\n      by (auto simp: zero_enat_def[symmetric] sat_MatchP_rec[where i=ne]\n          lookup_tabulate finite_RPDs split: option.splits\n          intro!: qtable_cong[OF qtable_r\\<epsilon>_strict]\n          dest: spec[of _ \"\\<tau> \\<sigma> (ne-1)\"])\n  next\n    case (Cons a as)\n    show ?thesis\n    proof (cases \"t = \\<tau> \\<sigma> ne\")\n      case t: True\n      show ?thesis\n      proof (cases \"fst a = \\<tau> \\<sigma> ne\")\n        case True\n        with aux' Cons t have \"X = snd a\"\n          unfolding aux'_eq using sorted_aux0 by auto\n        moreover from in_aux0_1[of \"fst a\" \"snd a\"] Cons have \"ne \\<noteq> 0\"\n          \"fst a \\<le> \\<tau> \\<sigma> ne\" \"memR I (\\<tau> \\<sigma> ne - fst a)\" \"\\<exists>i. \\<tau> \\<sigma> i = fst a\"\n          \"\\<forall>ms \\<in> RPDs mr. qtable n (fv_regex r) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne\n            (Formula.MatchP (point (\\<tau> \\<sigma> ne - fst a)) (from_mregex ms \\<phi>s))) (lookup (snd a) ms)\"\n          by auto\n        ultimately show ?thesis using t True\n          by auto\n      next\n        case False\n        with aux' Cons t have \"X = mrtabulate mrs (r\\<epsilon>_strict n rels)\"\n          unfolding aux'_eq using sorted_aux0 in_aux0_le_\\<tau>[of \"fst a\" \"snd a\"] by auto\n        with aux' Cons t False show ?thesis\n          unfolding aux'_eq using safe mrs qtables * in_aux0_2[of \"\\<tau> \\<sigma> (ne-1)\"] in_aux0_le_\\<tau>[of \"fst a\" \"snd a\"] sorted_aux0\n          by (auto simp: sat_MatchP_rec[where i=ne] zero_enat_def[symmetric] enat_0_iff not_le\n              lookup_tabulate finite_RPDs split: option.splits\n              intro!: qtable_cong[OF qtable_r\\<epsilon>_strict] dest!: le_\\<tau>_less meta_mp)\n      qed\n    next\n      case False\n      with aux' Cons have \"(t, X) \\<in> set aux0\"\n        unfolding aux'_eq by (auto split: if_splits)\n      then have \"ne \\<noteq> 0\" \"t \\<le> \\<tau> \\<sigma> ne\" \"memR I (\\<tau> \\<sigma> ne - t)\" \"\\<exists>i. \\<tau> \\<sigma> i = t\"\n        \"\\<forall>ms \\<in> RPDs mr. qtable n (fv_regex r) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne\n          (Formula.MatchP (point (\\<tau> \\<sigma> ne - t)) (from_mregex ms \\<phi>s))) (lookup X ms)\"\n        using in_aux0_1 by blast+\n      with False aux' Cons show ?thesis\n        unfolding aux'_eq by auto\n    qed\n  qed\n\n  have in_aux'_2: \"\\<exists>X. (t, X) \\<in> set aux'\" if \"t \\<le> \\<tau> \\<sigma> ne\" \"memR I (\\<tau> \\<sigma> ne - t)\" \"\\<exists>i. \\<tau> \\<sigma> i = t\" for t\n  proof (cases \"t = \\<tau> \\<sigma> ne\")\n    case True\n    then show ?thesis\n    proof (cases aux0)\n      case Nil\n      with True show ?thesis unfolding aux'_eq by simp\n    next\n      case (Cons a as)\n      with True show ?thesis unfolding aux'_eq using eq_fst_iff[of t a]\n        by (cases \"fst a = \\<tau> \\<sigma> ne\") auto\n    qed\n  next\n    case False\n    with that have \"ne \\<noteq> 0\"\n      using le_\\<tau>_less neq0_conv by blast\n    moreover from False that have  \"t \\<le> \\<tau> \\<sigma> (ne-1)\"\n      by (metis One_nat_def Suc_leI Suc_pred \\<tau>_mono diff_is_0_eq' order.antisym neq0_conv not_le)\n    ultimately obtain X where \"(t, X) \\<in> set aux0\" using \\<open>memR I (\\<tau> \\<sigma> ne - t)\\<close> \\<open>\\<exists>i. \\<tau> \\<sigma> i = t\\<close>\n      by atomize_elim (auto intro!: in_aux0_2)\n    then show ?thesis unfolding aux'_eq using False\n      by (auto intro: exI[of _ X] split: list.split)\n  qed\n\n  show \"wf_matchP_aux \\<sigma> V n R I r aux' (Suc ne)\"\n    unfolding wf_matchP_aux_def using mr\n    by (auto dest: in_aux'_1 intro: sorted_aux' in_aux'_2)\n\n  have rel_eq: \"rel = foldr (\\<union>) [lookup rel mr. (t, rel) \\<leftarrow> aux', memL I (\\<tau> \\<sigma> ne - t)] {}\"\n    unfolding aux'_eq aux0_def\n    using result_eq by (simp add: update_matchP_def Let_def)\n  have rel_alt: \"rel = (\\<Union>(t, rel) \\<in> set aux'. if memL I (\\<tau> \\<sigma> ne - t) then lookup rel mr else empty_table)\"\n    unfolding rel_eq\n    by (auto elim!: in_foldr_UnE bexI[rotated] intro!: in_foldr_UnI)\n  show \"qtable n (fv_regex r) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne (Formula.MatchP I r)) rel\"\n    unfolding rel_alt\n  proof (rule qtable_Union[where Qi=\"\\<lambda>(t, X) v.\n    memL I (\\<tau> \\<sigma> ne - t) \\<and> Formula.sat \\<sigma> V (map the v) ne (Formula.MatchP (point (\\<tau> \\<sigma> ne - t)) r)\"],\n        goal_cases finite qtable equiv)\n    case (equiv v)\n    show ?case\n    proof (rule iffI, erule sat_MatchP_point, goal_cases left right)\n      case (left j)\n      then show ?case using in_aux'_2[of \"\\<tau> \\<sigma> j\", OF _ _ exI, OF _ _ refl] by auto\n    next\n      case right\n      then show ?case by (auto elim!: sat_MatchP_pointD dest: in_aux'_1)\n    qed\n  qed (auto dest!: in_aux'_1 intro!: qtable_empty dest!: bspec[OF _ RPDs_refl]\n      simp: from_mregex_eq[OF safe mr])\nqed\n\nlemma length_update_until: \"length (update_until args rel1 rel2 nt aux) = Suc (length aux)\"\n  unfolding update_until_def by simp\n\nlemma wf_update_until_auxlist:\n  assumes pre: \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> auxlist ne\"\n    and qtable1: \"qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne + length auxlist) \\<phi>) rel1\"\n    and qtable2: \"qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne + length auxlist) \\<psi>) rel2\"\n    and fvi_subset: \"Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi>\"\n    and args_ivl: \"args_ivl args = I\"\n    and args_n: \"args_n args = n\"\n    and args_pos: \"args_pos args = pos\"\n  shows \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> (update_until args rel1 rel2 (\\<tau> \\<sigma> (ne + length auxlist)) auxlist) ne\"\n  unfolding wf_until_auxlist_def length_update_until\n  unfolding update_until_def list.rel_map add_Suc_right upt.simps eqTrueI[OF le_add1] if_True\nproof (rule list_all2_appendI, unfold list.rel_map, goal_cases old new)\n  case old\n  show ?case\n  proof (rule list.rel_mono_strong[OF assms(1)[unfolded wf_until_auxlist_def]]; safe, goal_cases mono1 mono2)\n    case (mono1 i X Y v)\n    then show ?case\n      by (fastforce simp: args_ivl args_n args_pos sat_the_restrict less_Suc_eq\n          elim!: qtable_join[OF _ qtable1] qtable_union[OF _ qtable1])\n  next\n    case (mono2 i X Y v)\n    then show ?case using fvi_subset\n      by (auto 0 3 simp: args_ivl args_n args_pos sat_the_restrict less_Suc_eq split: if_splits\n          elim!: qtable_union[OF _ qtable_join_fixed[OF qtable2]]\n          elim: qtable_cong[OF _ refl] intro: exI[of _ \"ne + length auxlist\"]) (* slow 8 sec*)\n  qed\nnext\n  case new\n  then show ?case\n    by (auto intro!: qtable_empty qtable1 qtable2[THEN qtable_cong] exI[of _ \"ne + length auxlist\"]\n        simp: args_ivl args_n args_pos less_Suc_eq zero_enat_def[symmetric])\nqed\n\nlemma (in muaux) wf_update_until:\n  assumes pre: \"wf_until_aux \\<sigma> V R args \\<phi> \\<psi> aux ne\"\n    and qtable1: \"qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne + length_muaux args aux) \\<phi>) rel1\"\n    and qtable2: \"qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne + length_muaux args aux) \\<psi>) rel2\"\n    and fvi_subset: \"Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi>\"\n    and args_ivl: \"args_ivl args = I\"\n    and args_n: \"args_n args = n\"\n    and args_L: \"args_L args = Formula.fv \\<phi>\"\n    and args_R: \"args_R args = Formula.fv \\<psi>\"\n    and args_pos: \"args_pos args = pos\"\n  shows \"wf_until_aux \\<sigma> V R args \\<phi> \\<psi> (add_new_muaux args rel1 rel2 (\\<tau> \\<sigma> (ne + length_muaux args aux)) aux) ne \\<and>\n      length_muaux args (add_new_muaux args rel1 rel2 (\\<tau> \\<sigma> (ne + length_muaux args aux)) aux) = Suc (length_muaux args aux)\"\nproof -\n  from pre obtain cur auxlist where valid_aux: \"valid_muaux args cur aux auxlist\" and\n    cur: \"cur = (if ne + length auxlist = 0 then 0 else \\<tau> \\<sigma> (ne + length auxlist - 1))\" and\n    pre_list: \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> auxlist ne\"\n    unfolding wf_until_aux_def args_ivl args_n args_pos by auto\n  have length_aux: \"length_muaux args aux = length auxlist\"\n    using valid_length_muaux[OF valid_aux] .\n  define nt where \"nt \\<equiv> \\<tau> \\<sigma> (ne + length_muaux args aux)\"\n  have nt_mono: \"cur \\<le> nt\"\n    unfolding cur nt_def length_aux by simp\n  define auxlist' where \"auxlist' \\<equiv> update_until args rel1 rel2 (\\<tau> \\<sigma> (ne + length auxlist)) auxlist\"\n  have length_auxlist': \"length auxlist' = Suc (length auxlist)\"\n    unfolding auxlist'_def by (auto simp add: length_update_until)\n  have tab1: \"table (args_n args) (args_L args) rel1\"\n    using qtable1 unfolding args_n[symmetric] args_L[symmetric] by (auto simp add: qtable_def)\n  have tab2: \"table (args_n args) (args_R args) rel2\"\n    using qtable2 unfolding args_n[symmetric] args_R[symmetric] by (auto simp add: qtable_def)\n  have fv_sub: \"fv \\<phi> \\<subseteq> fv \\<psi>\"\n    using pre unfolding wf_until_aux_def by auto\n  moreover have valid_add_new_auxlist: \"valid_muaux args nt (add_new_muaux args rel1 rel2 nt aux) auxlist'\"\n    using valid_add_new_muaux[OF valid_aux tab1 tab2 nt_mono]\n    unfolding auxlist'_def nt_def length_aux .\n  moreover have \"length_muaux args (add_new_muaux args rel1 rel2 nt aux) = Suc (length_muaux args aux)\"\n    using valid_length_muaux[OF valid_add_new_auxlist] unfolding length_auxlist' length_aux[symmetric] .\n  moreover have \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> auxlist' ne\"\n    using wf_update_until_auxlist[OF pre_list qtable1[unfolded length_aux] qtable2[unfolded length_aux] fv_sub args_ivl args_n args_pos]\n    unfolding auxlist'_def .\n  moreover have \"\\<tau> \\<sigma> (ne + length auxlist) = (if ne + length auxlist' = 0 then 0 else \\<tau> \\<sigma> (ne + length auxlist' - 1))\"\n    unfolding cur length_auxlist' by auto\n  ultimately show ?thesis\n    using pre\n    unfolding wf_until_aux_def nt_def length_aux args_ivl args_n args_pos\n    by fast\nqed\n\nlemma length_update_matchF_base:\n  \"length (fst (update_matchF_base I mr mrs nt entry st)) = Suc 0\"\n  by (auto simp: Let_def update_matchF_base_def)\n\nlemma length_update_matchF_step:\n  \"length (fst (update_matchF_step I mr mrs nt entry st)) = Suc (length (fst st))\"\n  by (auto simp: Let_def update_matchF_step_def split: prod.splits)\n\nlemma length_foldr_update_matchF_step:\n  \"length (fst (foldr (update_matchF_step I mr mrs nt) aux base)) = length aux + length (fst base)\"\n  by (induct aux arbitrary: base) (auto simp: Let_def length_update_matchF_step)\n\nlemma length_update_matchF: \"length (update_matchF n I mr mrs rels nt aux) = Suc (length aux)\"\n  unfolding update_matchF_def update_matchF_base_def length_foldr_update_matchF_step\n  by (auto simp: Let_def)\n\nlemma wf_update_matchF_base_invar:\n  assumes safe: \"safe_regex Futu Strict r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (LPDs mr)\"\n    and qtables: \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) j \\<phi>) rel) \\<phi>s rels\"\n  shows \"wf_matchF_invar \\<sigma> V n R I r (update_matchF_base n I mr mrs rels (\\<tau> \\<sigma> j)) j\"\nproof -\n  have from_mregex: \"from_mregex mr \\<phi>s = r\"\n    using safe mr using from_mregex_eq by blast\n  { fix ms\n    assume \"ms \\<in> LPDs mr\"\n    then have \"fv_regex (from_mregex ms \\<phi>s) = fv_regex r\"\n      \"safe_regex Futu Strict (from_mregex ms \\<phi>s)\" \"ok (length \\<phi>s) ms\" \"LPD ms \\<subseteq> LPDs mr\"\n      using safe LPDs_safe LPDs_safe_fv_regex mr from_mregex_to_mregex LPDs_ok to_mregex_ok LPDs_trans\n      by fastforce+\n  } note * = this\n  show ?thesis\n    unfolding wf_matchF_invar_def wf_matchF_aux_def update_matchF_base_def mr prod.case Let_def mrs\n    using safe\n    by (auto simp: * from_mregex qtables qtable_empty_iff zero_enat_def[symmetric]\n        lookup_tabulate finite_LPDs eps_match less_Suc_eq LPDs_refl\n        intro!: qtable_cong[OF qtable_l\\<epsilon>_strict[where \\<phi>s=\\<phi>s]] intro: qtables exI[of _ j]\n        split: option.splits)\nqed\n\nlemma Un_empty_table[simp]: \"rel \\<union> empty_table = rel\" \"empty_table \\<union> rel = rel\"\n  unfolding empty_table_def by auto\n\nlemma wf_matchF_invar_step:\n  assumes wf: \"wf_matchF_invar \\<sigma> V n R I r st (Suc i)\"\n    and safe: \"safe_regex Futu Strict r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (LPDs mr)\"\n    and qtables: \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>) rel) \\<phi>s rels\"\n    and rel: \"qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v. (\\<exists>j. i \\<le> j \\<and> j < i + length (fst st) \\<and> mem I ((\\<tau> \\<sigma> j - \\<tau> \\<sigma> i)) \\<and>\n          Regex.match (Formula.sat \\<sigma> V (map the v)) r i j)) rel\"\n    and entry: \"entry = (\\<tau> \\<sigma> i, rels, rel)\"\n    and nt: \"nt = \\<tau> \\<sigma> (i + length (fst st))\"\n  shows \"wf_matchF_invar \\<sigma> V n R I r (update_matchF_step I mr mrs nt entry st) i\"\nproof -\n  have from_mregex: \"from_mregex mr \\<phi>s = r\"\n    using safe mr using from_mregex_eq by blast\n  { fix ms\n    assume \"ms \\<in> LPDs mr\"\n    then have \"fv_regex (from_mregex ms \\<phi>s) = fv_regex r\"\n      \"safe_regex Futu Strict (from_mregex ms \\<phi>s)\" \"ok (length \\<phi>s) ms\" \"LPD ms \\<subseteq> LPDs mr\"\n      using safe LPDs_safe LPDs_safe_fv_regex mr from_mregex_to_mregex LPDs_ok to_mregex_ok LPDs_trans\n      by fastforce+\n  } note * = this\n  { fix aux X ms\n    assume \"st = (aux, X)\" \"ms \\<in> LPDs mr\"\n    with wf mr have \"qtable n (fv_regex r) (mem_restr R)\n      (\\<lambda>v. Regex.match (Formula.sat \\<sigma> V (map the v)) (from_mregex ms \\<phi>s) i (i + length aux))\n      (l\\<delta> (\\<lambda>x. x) X rels ms)\"\n      by (intro qtable_cong[OF qtable_l\\<delta>[where \\<phi>s=\\<phi>s and A=\"fv_regex r\" and\n              Q=\"\\<lambda>v r. Regex.match (Formula.sat \\<sigma> V v) r (Suc i) (i + length aux)\", OF _ _ qtables]])\n        (auto simp: wf_matchF_invar_def * LPDs_trans lpd_match[of i] elim!: bspec)\n  } note l\\<delta> = this\n  have \"lookup (mrtabulate mrs f) ms = f ms\" if \"ms \\<in> LPDs mr\" for ms and f :: \"mregex \\<Rightarrow> 'a table\"\n    using that mrs  by (fastforce simp: lookup_tabulate finite_LPDs split: option.splits)+\n  then show ?thesis\n    using wf mr mrs entry nt LPDs_trans\n    by (auto 0 3 simp: Let_def wf_matchF_invar_def update_matchF_step_def wf_matchF_aux_def mr * LPDs_refl\n        list_all2_Cons1 append_eq_Cons_conv upt_eq_Cons_conv Suc_le_eq qtables\n        lookup_tabulate finite_LPDs id_def l\\<delta> from_mregex less_Suc_eq\n        intro!: qtable_union[OF rel l\\<delta>] qtable_cong[OF rel]\n        intro: exI[of _ \"i + length _\"]\n        split: if_splits prod.splits)\nqed\n\nlemma wf_update_matchF_invar:\n  assumes pre: \"wf_matchF_aux \\<sigma> V n R I r aux ne (length (fst st) - 1)\"\n    and wf: \"wf_matchF_invar \\<sigma> V n R I r st (ne + length aux)\"\n    and safe: \"safe_regex Futu Strict r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (LPDs mr)\"\n    and j: \"j = ne + length aux + length (fst st) - 1\"\n  shows \"wf_matchF_invar \\<sigma> V n R I r (foldr (update_matchF_step I mr mrs (\\<tau> \\<sigma> j)) aux st) ne\"\n  using pre wf unfolding j\nproof (induct aux arbitrary: ne)\n  case (Cons entry aux)\n  from Cons(1)[of \"Suc ne\"] Cons(2,3) show ?case\n    unfolding foldr.simps o_apply\n    by (intro wf_matchF_invar_step[where rels = \"fst (snd entry)\" and rel = \"snd (snd entry)\"])\n      (auto simp: safe mr mrs wf_matchF_aux_def wf_matchF_invar_def list_all2_Cons1 append_eq_Cons_conv\n        Suc_le_eq upt_eq_Cons_conv length_foldr_update_matchF_step add.assoc split: if_splits)\nqed simp\n\n\nlemma wf_update_matchF:\n  assumes pre: \"wf_matchF_aux \\<sigma> V n R I r aux ne 0\"\n    and safe: \"safe_regex Futu Strict r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (LPDs mr)\"\n    and nt: \"nt = \\<tau> \\<sigma> (ne + length aux)\"\n    and qtables: \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne + length aux) \\<phi>) rel) \\<phi>s rels\"\n  shows \"wf_matchF_aux \\<sigma> V n R I r (update_matchF n I mr mrs rels nt aux) ne 0\"\n  unfolding update_matchF_def using wf_update_matchF_base_invar[OF safe mr mrs qtables, of I]\n  unfolding nt\n  by (intro wf_update_matchF_invar[OF _ _ safe mr mrs, unfolded wf_matchF_invar_def split_beta, THEN conjunct2, THEN conjunct1])\n    (auto simp: length_update_matchF_base wf_matchF_invar_def update_matchF_base_def Let_def pre)\n\nlemma wf_until_aux_Cons: \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> (a # aux) ne \\<Longrightarrow>\n  wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> aux (Suc ne)\"\n  unfolding wf_until_auxlist_def\n  by (simp add: upt_conv_Cons del: upt_Suc cong: if_cong)\n\nlemma wf_matchF_aux_Cons: \"wf_matchF_aux \\<sigma> V n R I r (entry # aux) ne i \\<Longrightarrow>\n  wf_matchF_aux \\<sigma> V n R I r aux (Suc ne) i\"\n  unfolding wf_matchF_aux_def\n  by (simp add: upt_conv_Cons del: upt_Suc cong: if_cong split: prod.splits)\n\nlemma wf_until_aux_Cons1: \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> ((t, a1, a2) # aux) ne \\<Longrightarrow> t = \\<tau> \\<sigma> ne\"\n  unfolding wf_until_auxlist_def\n  by (simp add: upt_conv_Cons del: upt_Suc)\n\nlemma wf_matchF_aux_Cons1: \"wf_matchF_aux \\<sigma> V n R I r ((t, rels, rel) # aux) ne i \\<Longrightarrow> t = \\<tau> \\<sigma> ne\"\n  unfolding wf_matchF_aux_def\n  by (simp add: upt_conv_Cons del: upt_Suc split: prod.splits)\n\nlemma wf_until_aux_Cons3: \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> ((t, a1, a2) # aux) ne \\<Longrightarrow>\n  qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. (\\<exists>j. ne \\<le> j \\<and> j < Suc (ne + length aux) \\<and> mem I ((\\<tau> \\<sigma> j - \\<tau> \\<sigma> ne)) \\<and>\n    Formula.sat \\<sigma> V (map the v) j \\<psi> \\<and> (\\<forall>k\\<in>{ne..<j}. if pos then Formula.sat \\<sigma> V (map the v) k \\<phi> else \\<not> Formula.sat \\<sigma> V (map the v) k \\<phi>))) a2\"\n  unfolding wf_until_auxlist_def\n  by (simp add: upt_conv_Cons del: upt_Suc)\n\nlemma wf_matchF_aux_Cons3: \"wf_matchF_aux \\<sigma> V n R I r ((t, rels, rel) # aux) ne i \\<Longrightarrow>\n  qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v. (\\<exists>j. ne \\<le> j \\<and> j < Suc (ne + length aux + i) \\<and> mem I ((\\<tau> \\<sigma> j - \\<tau> \\<sigma> ne)) \\<and>\n    Regex.match (Formula.sat \\<sigma> V (map the v)) r ne j)) rel\"\n  unfolding wf_matchF_aux_def\n  by (simp add: upt_conv_Cons del: upt_Suc split: prod.splits)\n\nlemma upt_append: \"a \\<le> b \\<Longrightarrow> b \\<le> c \\<Longrightarrow> [a..<b] @ [b..<c] = [a..<c]\"\n  by (metis le_Suc_ex upt_add_eq_append)\n\nlemma wf_mbuf2_add:\n  assumes \"wf_mbuf2 i ja jb P Q buf\"\n    and \"list_all2 P [ja..<ja'] xs\"\n    and \"list_all2 Q [jb..<jb'] ys\"\n    and \"ja \\<le> ja'\" \"jb \\<le> jb'\"\n  shows \"wf_mbuf2 i ja' jb' P Q (mbuf2_add xs ys buf)\"\n  using assms unfolding wf_mbuf2_def\n  by (auto 0 3 simp: list_all2_append2 upt_append dest: list_all2_lengthD\n      intro: exI[where x=\"[i..<ja]\"] exI[where x=\"[ja..<ja']\"]\n      exI[where x=\"[i..<jb]\"] exI[where x=\"[jb..<jb']\"] split: prod.splits)\n\nlemma wf_mbufn_add:\n  assumes \"wf_mbufn i js Ps buf\"\n    and \"list_all3 list_all2 Ps (List.map2 (\\<lambda>j j'. [j..<j']) js js') xss\"\n    and \"list_all2 (\\<le>) js js'\"\n  shows \"wf_mbufn i js' Ps (mbufn_add xss buf)\"\n  unfolding wf_mbufn_def list_all3_conv_all_nth\nproof safe\n  show \"length Ps = length js'\" \"length js' = length (mbufn_add xss buf)\"\n    using assms unfolding wf_mbufn_def list_all3_conv_all_nth list_all2_conv_all_nth by auto\nnext\n  fix k assume k: \"k < length Ps\"\n  then show \"i \\<le> js' ! k\"\n    using assms unfolding wf_mbufn_def list_all3_conv_all_nth list_all2_conv_all_nth\n    by (auto 0 4 dest: spec[of _ i])\n  from k have \" [i..<js' ! k] =  [i..<js ! k] @ [js ! k ..<js' ! k]\" and\n    \"length [i..<js ! k] = length (buf ! k)\"\n    using assms(1,3) unfolding wf_mbufn_def list_all3_conv_all_nth list_all2_conv_all_nth\n    by (auto simp: upt_append)\n  with k show \"list_all2 (Ps ! k) [i..<js' ! k] (mbufn_add xss buf ! k)\"\n    using assms[unfolded wf_mbufn_def list_all3_conv_all_nth]\n    by (auto simp add: list_all2_append)\nqed\n\nlemma mbuf2_take_eqD:\n  assumes \"mbuf2_take f buf = (xs, buf')\"\n    and \"wf_mbuf2 i ja jb P Q buf\"\n  shows \"wf_mbuf2 (min ja jb) ja jb P Q buf'\"\n    and \"list_all2 (\\<lambda>i z. \\<exists>x y. P i x \\<and> Q i y \\<and> z = f x y) [i..<min ja jb] xs\"\n  using assms unfolding wf_mbuf2_def\n  by (induction f buf arbitrary: i xs buf' rule: mbuf2_take.induct)\n    (fastforce simp add: list_all2_Cons2 upt_eq_Cons_conv min_absorb1 min_absorb2 split: prod.splits)+\n\nlemma list_all3_Nil[simp]:\n  \"list_all3 P xs ys [] \\<longleftrightarrow> xs = [] \\<and> ys = []\"\n  \"list_all3 P xs [] zs \\<longleftrightarrow> xs = [] \\<and> zs = []\"\n  \"list_all3 P [] ys zs \\<longleftrightarrow> ys = [] \\<and> zs = []\"\n  unfolding list_all3_conv_all_nth by auto\n\nlemma list_all3_Cons:\n  \"list_all3 P xs ys (z # zs) \\<longleftrightarrow> (\\<exists>x xs' y ys'. xs = x # xs' \\<and> ys = y # ys' \\<and> P x y z \\<and> list_all3 P xs' ys' zs)\"\n  \"list_all3 P xs (y # ys) zs \\<longleftrightarrow> (\\<exists>x xs' z zs'. xs = x # xs' \\<and> zs = z # zs' \\<and> P x y z \\<and> list_all3 P xs' ys zs')\"\n  \"list_all3 P (x # xs) ys zs \\<longleftrightarrow> (\\<exists>y ys' z zs'. ys = y # ys' \\<and> zs = z # zs' \\<and> P x y z \\<and> list_all3 P xs ys' zs')\"\n  unfolding list_all3_conv_all_nth\n  by (auto simp: length_Suc_conv Suc_length_conv nth_Cons split: nat.splits)\n\nlemma list_all3_mono_strong: \"list_all3 P xs ys zs \\<Longrightarrow>\n  (\\<And>x y z. x \\<in> set xs \\<Longrightarrow> y \\<in> set ys \\<Longrightarrow> z \\<in> set zs \\<Longrightarrow> P x y z \\<Longrightarrow> Q x y z) \\<Longrightarrow>\n  list_all3 Q xs ys zs\"\n  by (induct xs ys zs rule: list_all3.induct) (auto intro: list_all3.intros)\n\ndefinition Mini where\n  \"Mini i js = (if js = [] then i else Min (set js))\"\n\nlemma wf_mbufn_in_set_Mini:\n  assumes \"wf_mbufn i js Ps buf\"\n  shows \"[] \\<in> set buf \\<Longrightarrow> Mini i js = i\"\n  unfolding in_set_conv_nth\nproof (elim exE conjE)\n  fix k\n  have \"i \\<le> j\" if \"j \\<in> set js\" for j\n    using that assms unfolding wf_mbufn_def list_all3_conv_all_nth in_set_conv_nth by auto\n  moreover assume \"k < length buf\" \"buf ! k = []\"\n  ultimately show ?thesis using assms\n    unfolding Mini_def wf_mbufn_def list_all3_conv_all_nth\n    by (auto 0 4 dest!: spec[of _ k] intro: Min_eqI simp: in_set_conv_nth)\nqed\n\nlemma wf_mbufn_notin_set:\n  assumes \"wf_mbufn i js Ps buf\"\n  shows \"[] \\<notin> set buf \\<Longrightarrow> j \\<in> set js \\<Longrightarrow> i < j\"\n  using assms unfolding wf_mbufn_def list_all3_conv_all_nth\n  by (cases \"i \\<in> set js\") (auto intro: le_neq_implies_less simp: in_set_conv_nth)\n\nlemma wf_mbufn_map_tl:\n  \"wf_mbufn i js Ps buf \\<Longrightarrow> [] \\<notin> set buf \\<Longrightarrow> wf_mbufn (Suc i) js Ps (map tl buf)\"\n  by (auto simp: wf_mbufn_def list_all3_map Suc_le_eq\n      dest: rel_funD[OF tl_transfer]  elim!: list_all3_mono_strong le_neq_implies_less)\n\nlemma list_all3_list_all2I: \"list_all3 (\\<lambda>x y z. Q x z) xs ys zs \\<Longrightarrow> list_all2 Q xs zs\"\n  by (induct xs ys zs rule: list_all3.induct) auto\n\nlemma mbuf2t_take_eqD:\n  assumes \"mbuf2t_take f z buf nts = (z', buf', nts')\"\n    and \"wf_mbuf2 i ja jb P Q buf\"\n    and \"list_all2 R [i..<j] nts\"\n    and \"ja \\<le> j\" \"jb \\<le> j\"\n  shows \"wf_mbuf2 (min ja jb) ja jb P Q buf'\"\n    and \"list_all2 R [min ja jb..<j] nts'\"\n  using assms unfolding wf_mbuf2_def\n  by (induction f z buf nts arbitrary: i z' buf' nts' rule: mbuf2t_take.induct)\n    (auto simp add: list_all2_Cons2 upt_eq_Cons_conv less_eq_Suc_le min_absorb1 min_absorb2\n      split: prod.split)\n\nlemma wf_mbufn_take:\n  assumes \"mbufn_take f z buf = (z', buf')\"\n    and \"wf_mbufn i js Ps buf\"\n  shows \"wf_mbufn (Mini i js) js Ps buf'\"\n  using assms unfolding wf_mbufn_def\nproof (induction f z buf arbitrary: i z' buf' rule: mbufn_take.induct)\n  case rec: (1 f z buf)\n  show ?case proof (cases \"buf = []\")\n    case True\n    with rec.prems show ?thesis by simp\n  next\n    case nonempty: False\n    show ?thesis proof (cases \"[] \\<in> set buf\")\n      case True\n      from rec.prems(2) have \"\\<forall>j\\<in>set js. i \\<le> j\"\n        by (auto simp: in_set_conv_nth list_all3_conv_all_nth)\n      moreover from True rec.prems(2) have \"i \\<in> set js\"\n        by (fastforce simp: in_set_conv_nth list_all3_conv_all_nth list_all2_iff)\n      ultimately have \"Mini i js = i\"\n        unfolding Mini_def\n        by (auto intro!: antisym[OF Min.coboundedI Min.boundedI])\n      with rec.prems nonempty True show ?thesis by simp\n    next\n      case False\n      from nonempty rec.prems(2) have \"Mini i js = Mini (Suc i) js\"\n        unfolding Mini_def by auto\n      show ?thesis\n        unfolding \\<open>Mini i js = Mini (Suc i) js\\<close>\n      proof (rule rec.IH)\n        show \"\\<not> (buf = [] \\<or> [] \\<in> set buf)\" using nonempty False by simp\n        show \"list_all3 (\\<lambda>P j xs. Suc i \\<le> j \\<and> list_all2 P [Suc i..<j] xs) Ps js (map tl buf)\"\n          using False rec.prems(2)\n          by (auto simp: list_all3_map elim!: list_all3_mono_strong dest: list.rel_sel[THEN iffD1])\n        show \"mbufn_take f (f (map hd buf) z) (map tl buf) = (z', buf')\"\n          using nonempty False rec.prems(1) by simp\n      qed\n    qed\n  qed\nqed\n\nlemma mbufnt_take_eqD:\n  assumes \"mbufnt_take f z buf nts = (z', buf', nts')\"\n    and \"wf_mbufn i js Ps buf\"\n    and \"list_all2 R [i..<j] nts\"\n    and \"\\<And>k. k \\<in> set js \\<Longrightarrow> k \\<le> j\"\n    and \"k = Mini (i + length nts) js\"\n  shows \"wf_mbufn k js Ps buf'\"\n    and \"list_all2 R [k..<j] nts'\"\n  using assms(1-4) unfolding assms(5)\nproof (induction f z buf nts arbitrary: i z' buf' nts' rule: mbufnt_take.induct)\n  case IH: (1 f z buf nts)\n  note mbufnt_take.simps[simp del]\n  case 1\n  then have *: \"list_all2 R [Suc i..<j] (tl nts)\"\n    by (auto simp: list.rel_sel[of R \"[i..<j]\" nts, simplified])\n  from 1 show ?case\n    using wf_mbufn_in_set_Mini[OF 1(2)]\n    by (subst (asm) mbufnt_take.simps)\n      (force simp: Mini_def wf_mbufn_def split: if_splits prod.splits elim!: list_all3_mono_strong\n        dest!: IH(1)[rotated, OF _ wf_mbufn_map_tl[OF 1(2)] *])\n  case 2\n  then have *: \"list_all2 R [Suc i..<j] (tl nts)\"\n    by (auto simp: list.rel_sel[of R \"[i..<j]\" nts, simplified])\n  have [simp]: \"Suc (i + (length nts - Suc 0)) = i + length nts\" if \"nts \\<noteq> []\"\n    using that by (fastforce simp flip: length_greater_0_conv)\n  with 2 show ?case\n    using wf_mbufn_in_set_Mini[OF 2(2)] wf_mbufn_notin_set[OF 2(2)]\n    by (subst (asm) mbufnt_take.simps) (force simp: Mini_def wf_mbufn_def\n        dest!: IH(2)[rotated, OF _ wf_mbufn_map_tl[OF 2(2)] *]\n        split: if_splits prod.splits)\nqed\n\nlemma mbuf2t_take_induct[consumes 5, case_names base step]:\n  assumes \"mbuf2t_take f z buf nts = (z', buf', nts')\"\n    and \"wf_mbuf2 i ja jb P Q buf\"\n    and \"list_all2 R [i..<j] nts\"\n    and \"ja \\<le> j\" \"jb \\<le> j\"\n    and \"U i z\"\n    and \"\\<And>k x y t z. i \\<le> k \\<Longrightarrow> Suc k \\<le> ja \\<Longrightarrow> Suc k \\<le> jb \\<Longrightarrow>\n      P k x \\<Longrightarrow> Q k y \\<Longrightarrow> R k t \\<Longrightarrow> U k z \\<Longrightarrow> U (Suc k) (f x y t z)\"\n  shows \"U (min ja jb) z'\"\n  using assms unfolding wf_mbuf2_def\n  by (induction f z buf nts arbitrary: i z' buf' nts' rule: mbuf2t_take.induct)\n    (auto simp add: list_all2_Cons2 upt_eq_Cons_conv less_eq_Suc_le min_absorb1 min_absorb2\n      elim!: arg_cong2[of _ _ _ _ U, OF _ refl, THEN iffD1, rotated] split: prod.split)\n\nlemma list_all2_hdD:\n  assumes \"list_all2 P [i..<j] xs\" \"xs \\<noteq> []\"\n  shows \"P i (hd xs)\" \"i < j\"\n  using assms unfolding list_all2_conv_all_nth\n  by (auto simp: hd_conv_nth intro: zero_less_diff[THEN iffD1] dest!: spec[of _ 0])\n\nlemma list_all2_lastD:\n  assumes \"list_all2 P [i..<j] xs\" \"xs \\<noteq> []\"\n  shows \"P (j - 1) (last xs)\"\n  using assms list_all2_hdD(2)[OF assms, THEN less_imp_add_positive] unfolding list_all2_conv_all_nth\n  by (auto dest!: spec[of _ \"length xs - 1\"] simp: last_conv_nth Suc_le_eq)\n\nlemma mbufn_take_induct[consumes 3, case_names base step]:\n  assumes \"mbufn_take f z buf = (z', buf')\"\n    and \"wf_mbufn i js Ps buf\"\n    and \"U i z\"\n    and \"\\<And>k xs z. i \\<le> k \\<Longrightarrow> Suc k \\<le> Mini i js \\<Longrightarrow>\n      list_all2 (\\<lambda>P x. P k x) Ps xs \\<Longrightarrow> U k z \\<Longrightarrow> U (Suc k) (f xs z)\"\n  shows \"U (Mini i js) z'\"\n  using assms unfolding wf_mbufn_def\nproof (induction f z buf arbitrary: i z' buf' rule: mbufn_take.induct)\n  case rec: (1 f z buf)\n  show ?case proof (cases \"buf = []\")\n    case True\n    with rec.prems show ?thesis unfolding Mini_def by simp\n  next\n    case nonempty: False\n    show ?thesis proof (cases \"[] \\<in> set buf\")\n      case True\n      from rec.prems(2) have \"\\<forall>j\\<in>set js. i \\<le> j\"\n        by (auto simp: in_set_conv_nth list_all3_conv_all_nth)\n      moreover from True rec.prems(2) have \"i \\<in> set js\"\n        by (fastforce simp: in_set_conv_nth list_all3_conv_all_nth list_all2_iff)\n      ultimately have \"Mini i js = i\"\n        unfolding Mini_def\n        by (auto intro!: antisym[OF Min.coboundedI Min.boundedI])\n      with rec.prems nonempty True show ?thesis by simp\n    next\n      case False\n      with nonempty rec.prems(2) have more: \"Suc i \\<le> Mini i js\"\n        using diff_is_0_eq not_le unfolding Mini_def\n        by (fastforce simp: in_set_conv_nth list_all3_conv_all_nth list_all2_iff)\n      then have \"Mini i js = Mini (Suc i) js\" unfolding Mini_def by auto\n      show ?thesis\n        unfolding \\<open>Mini i js = Mini (Suc i) js\\<close>\n      proof (rule rec.IH)\n        show \"\\<not> (buf = [] \\<or> [] \\<in> set buf)\" using nonempty False by simp\n        show \"mbufn_take f (f (map hd buf) z) (map tl buf) = (z', buf')\"\n          using nonempty False rec.prems by simp\n        show \"list_all3 (\\<lambda>P j xs. Suc i \\<le> j \\<and> list_all2 P [Suc i..<j] xs) Ps js (map tl buf)\"\n          using False rec.prems\n          by (auto simp: list_all3_map elim!: list_all3_mono_strong dest: list.rel_sel[THEN iffD1])\n        show \"U (Suc i) (f (map hd buf) z)\"\n          using more False rec.prems\n          by (auto 0 4 simp: list_all3_map intro!: rec.prems(4) list_all3_list_all2I\n              elim!: list_all3_mono_strong dest: list.rel_sel[THEN iffD1])\n        show \"\\<And>k xs z. Suc i \\<le> k \\<Longrightarrow> Suc k \\<le> Mini (Suc i) js \\<Longrightarrow>\n          list_all2 (\\<lambda>P. P k) Ps xs \\<Longrightarrow> U k z \\<Longrightarrow> U (Suc k) (f xs z)\"\n          by (rule rec.prems(4)) (auto simp: Mini_def)\n      qed\n    qed\n  qed\nqed\n\nlemma mbufnt_take_induct[consumes 5, case_names base step]:\n  assumes \"mbufnt_take f z buf nts = (z', buf', nts')\"\n    and \"wf_mbufn i js Ps buf\"\n    and \"list_all2 R [i..<j] nts\"\n    and \"\\<And>k. k \\<in> set js \\<Longrightarrow> k \\<le> j\"\n    and \"U i z\"\n    and \"\\<And>k xs t z. i \\<le> k \\<Longrightarrow> Suc k \\<le> Mini j js \\<Longrightarrow>\n      list_all2 (\\<lambda>P x. P k x) Ps xs \\<Longrightarrow> R k t \\<Longrightarrow> U k z \\<Longrightarrow> U (Suc k) (f xs t z)\"\n  shows \"U (Mini (i + length nts) js) z'\"\n  using assms\nproof (induction f z buf nts arbitrary: i z' buf' nts' rule: mbufnt_take.induct)\n  case (1 f z buf nts)\n  then have *: \"list_all2 R [Suc i..<j] (tl nts)\"\n    by (auto simp: list.rel_sel[of R \"[i..<j]\" nts, simplified])\n  note mbufnt_take.simps[simp del]\n  from 1(2-6) have \"i = Min (set js)\" if \"js \\<noteq> []\" \"nts = []\"\n    using that unfolding wf_mbufn_def using wf_mbufn_in_set_Mini[OF 1(3)]\n    by (fastforce simp: Mini_def list_all3_Cons neq_Nil_conv)\n  with 1(2-7) list_all2_hdD[OF 1(4)] show ?case\n    unfolding wf_mbufn_def using wf_mbufn_in_set_Mini[OF 1(3)] wf_mbufn_notin_set[OF 1(3)]\n    by (subst (asm) mbufnt_take.simps)\n      (auto simp add: Mini_def list.rel_map Suc_le_eq\n        elim!: arg_cong2[of _ _ _ _ U, OF _ refl, THEN iffD1, rotated]\n        list_all3_mono_strong[THEN list_all3_list_all2I[of _ _ js]] list_all2_hdD\n        dest!: 1(1)[rotated, OF _ wf_mbufn_map_tl[OF 1(3)] * _ 1(7)] split: prod.split if_splits)\nqed\n\nlemma mbuf2_take_add':\n  assumes eq: \"mbuf2_take f (mbuf2_add xs ys buf) = (zs, buf')\"\n    and pre: \"wf_mbuf2' \\<sigma> P V j n R \\<phi> \\<psi> buf\"\n    and rm: \"rel_mapping (\\<le>) P P'\"\n    and xs: \"list_all2 (\\<lambda>i. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>))\n      [progress \\<sigma> P \\<phi> j..<progress \\<sigma> P' \\<phi> j'] xs\"\n    and ys: \"list_all2 (\\<lambda>i. qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>))\n      [progress \\<sigma> P \\<psi> j..<progress \\<sigma> P' \\<psi> j'] ys\"\n    and \"j \\<le> j'\"\n  shows \"wf_mbuf2' \\<sigma> P' V j' n R \\<phi> \\<psi> buf'\"\n    and \"list_all2 (\\<lambda>i Z. \\<exists>X Y.\n      qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>) X \\<and>\n      qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>) Y \\<and>\n      Z = f X Y)\n      [min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)..<min (progress \\<sigma> P' \\<phi> j') (progress \\<sigma> P' \\<psi> j')] zs\"\n  using pre rm unfolding wf_mbuf2'_def\n  by (force intro!: mbuf2_take_eqD[OF eq] wf_mbuf2_add[OF _ xs ys] progress_mono_gen[OF \\<open>j \\<le> j'\\<close> rm])+\n\nlemma mbuf2t_take_add':\n  assumes eq: \"mbuf2t_take f z (mbuf2_add xs ys buf) nts = (z', buf', nts')\"\n    and bounded: \"pred_mapping (\\<lambda>x. x \\<le> j) P\" \"pred_mapping (\\<lambda>x. x \\<le> j') P'\"\n    and rm: \"rel_mapping (\\<le>) P P'\"\n    and pre_buf: \"wf_mbuf2' \\<sigma> P V j n R \\<phi> \\<psi> buf\"\n    and pre_nts: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)..<j'] nts\"\n    and xs: \"list_all2 (\\<lambda>i. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>))\n      [progress \\<sigma> P \\<phi> j..<progress \\<sigma> P' \\<phi> j'] xs\"\n    and ys: \"list_all2 (\\<lambda>i. qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>))\n      [progress \\<sigma> P \\<psi> j..<progress \\<sigma> P' \\<psi> j'] ys\"\n    and \"j \\<le> j'\"\n  shows \"wf_mbuf2' \\<sigma> P' V j' n R \\<phi> \\<psi> buf'\"\n    and \"wf_ts \\<sigma> P' j' \\<phi> \\<psi> nts'\"\n  using pre_buf pre_nts bounded rm unfolding wf_mbuf2'_def wf_ts_def\n  by (auto intro!: mbuf2t_take_eqD[OF eq] wf_mbuf2_add[OF _ xs ys] progress_mono_gen[OF \\<open>j \\<le> j'\\<close> rm]\n      progress_le_gen)\n\nlemma ok_0_atms: \"ok 0 mr \\<Longrightarrow> regex.atms (from_mregex mr []) = {}\"\n  by (induct mr) auto\n\nlemma ok_0_progress: \"ok 0 mr \\<Longrightarrow> progress_regex \\<sigma> P (from_mregex mr []) j = j\"\n  by (drule ok_0_atms) (auto simp: progress_regex_def)\n\nlemma atms_empty_atms: \"safe_regex m g r \\<Longrightarrow> atms r = {} \\<longleftrightarrow> regex.atms r = {}\"\n  by (induct r rule: safe_regex_induct) (auto split: if_splits simp: cases_Neg_iff)\n\nlemma atms_empty_progress: \"safe_regex m g r \\<Longrightarrow> atms r = {} \\<Longrightarrow> progress_regex \\<sigma> P r j = j\"\n  by (drule atms_empty_atms) (auto simp: progress_regex_def)\n\nlemma to_mregex_empty_progress: \"safe_regex m g r \\<Longrightarrow> to_mregex r = (mr, []) \\<Longrightarrow>\n  progress_regex \\<sigma> P r j = j\"\n  using from_mregex_eq ok_0_progress to_mregex_ok atms_empty_atms by fastforce\n\nlemma progress_regex_le: \"pred_mapping (\\<lambda>x. x \\<le> j) P \\<Longrightarrow> progress_regex \\<sigma> P r j \\<le> j\"\n  by (auto intro!: progress_le_gen simp: Min_le_iff progress_regex_def)\n\nlemma Neg_acyclic: \"formula.Neg x = x \\<Longrightarrow> P\"\n  by (induct x) auto\n\nlemma case_Neg_in_iff: \"x \\<in> (case y of formula.Neg \\<phi>' \\<Rightarrow> {\\<phi>'} | _ \\<Rightarrow> {}) \\<longleftrightarrow> y = formula.Neg x\"\n  by (cases y) auto\n\nlemma atms_nonempty_progress:\n  \"safe_regex m g r \\<Longrightarrow> atms r \\<noteq> {} \\<Longrightarrow> (\\<lambda>\\<phi>. progress \\<sigma> P \\<phi> j) ` atms r = (\\<lambda>\\<phi>. progress \\<sigma> P \\<phi> j) ` regex.atms r\"\n  by (frule atms_empty_atms; simp)\n    (auto 0 3 simp: atms_def image_iff case_Neg_in_iff elim!: disjE_Not2 dest: safe_regex_safe_formula)\n\nlemma to_mregex_nonempty_progress: \"safe_regex m g r \\<Longrightarrow> to_mregex r = (mr, \\<phi>s) \\<Longrightarrow> \\<phi>s \\<noteq> [] \\<Longrightarrow>\n  progress_regex \\<sigma> P r j = (MIN \\<phi>\\<in>set \\<phi>s. progress \\<sigma> P \\<phi> j)\"\n  using atms_nonempty_progress to_mregex_ok unfolding progress_regex_def by fastforce\n\nlemma to_mregex_progress: \"safe_regex m g r \\<Longrightarrow> to_mregex r = (mr, \\<phi>s) \\<Longrightarrow>\n  progress_regex \\<sigma> P r j = (if \\<phi>s = [] then j else (MIN \\<phi>\\<in>set \\<phi>s. progress \\<sigma> P \\<phi> j))\"\n  using to_mregex_nonempty_progress to_mregex_empty_progress unfolding progress_regex_def by auto\n\nlemma mbufnt_take_add':\n  assumes eq: \"mbufnt_take f z (mbufn_add xss buf) nts = (z', buf', nts')\"\n    and bounded: \"pred_mapping (\\<lambda>x. x \\<le> j) P\" \"pred_mapping (\\<lambda>x. x \\<le> j') P'\"\n    and rm: \"rel_mapping (\\<le>) P P'\"\n    and safe: \"safe_regex m g r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and pre_buf: \"wf_mbufn' \\<sigma> P V j n R r buf\"\n    and pre_nts: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [progress_regex \\<sigma> P r j..<j'] nts\"\n    and xss: \"list_all3 list_all2\n     (map (\\<lambda>\\<phi> i. qtable n (fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>)) \\<phi>s)\n     (map2 upt (map (\\<lambda>\\<phi>. progress \\<sigma> P \\<phi> j) \\<phi>s) (map (\\<lambda>\\<phi>. progress \\<sigma> P' \\<phi> j') \\<phi>s)) xss\"\n    and \"j \\<le> j'\"\n  shows \"wf_mbufn' \\<sigma> P' V j' n R r buf'\"\n    and \"wf_ts_regex \\<sigma> P' j' r nts'\"\n  using pre_buf pre_nts bounded rm mr safe xss \\<open>j \\<le> j'\\<close>  unfolding wf_mbufn'_def wf_ts_regex_def\n  using atms_empty_progress[of m g r] to_mregex_ok[OF mr]\n  by (auto 0 3 simp: list.rel_map to_mregex_empty_progress to_mregex_nonempty_progress Mini_def\n      intro: progress_mono_gen[OF \\<open>j \\<le> j'\\<close> rm] list.rel_refl_strong progress_le_gen\n      dest: list_all2_lengthD elim!: mbufnt_take_eqD[OF eq wf_mbufn_add])\n\nlemma mbuf2t_take_add_induct'[consumes 6, case_names base step]:\n  assumes eq: \"mbuf2t_take f z (mbuf2_add xs ys buf) nts = (z', buf', nts')\"\n    and bounded: \"pred_mapping (\\<lambda>x. x \\<le> j) P\" \"pred_mapping (\\<lambda>x. x \\<le> j') P'\"\n    and rm: \"rel_mapping (\\<le>) P P'\"\n    and pre_buf: \"wf_mbuf2' \\<sigma> P V j n R \\<phi> \\<psi> buf\"\n    and pre_nts: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)..<j'] nts\"\n    and xs: \"list_all2 (\\<lambda>i. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>))\n      [progress \\<sigma> P \\<phi> j..<progress \\<sigma> P' \\<phi> j'] xs\"\n    and ys: \"list_all2 (\\<lambda>i. qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>))\n      [progress \\<sigma> P \\<psi> j..<progress \\<sigma> P' \\<psi> j'] ys\"\n    and \"j \\<le> j'\"\n    and base: \"U (min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)) z\"\n    and step: \"\\<And>k X Y z. min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j) \\<le> k \\<Longrightarrow>\n      Suc k \\<le> progress \\<sigma> P' \\<phi> j' \\<Longrightarrow> Suc k \\<le> progress \\<sigma> P' \\<psi> j' \\<Longrightarrow>\n      qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) k \\<phi>) X \\<Longrightarrow>\n      qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) k \\<psi>) Y \\<Longrightarrow>\n      U k z \\<Longrightarrow> U (Suc k) (f X Y (\\<tau> \\<sigma> k) z)\"\n  shows \"U (min (progress \\<sigma> P' \\<phi> j') (progress \\<sigma> P' \\<psi> j')) z'\"\n  using pre_buf pre_nts bounded rm unfolding wf_mbuf2'_def\n  by (blast intro!: mbuf2t_take_induct[OF eq] wf_mbuf2_add[OF _ xs ys] progress_mono_gen[OF \\<open>j \\<le> j'\\<close> rm]\n      progress_le_gen base step)\n\nlemma mbufnt_take_add_induct'[consumes 6, case_names base step]:\n  assumes eq: \"mbufnt_take f z (mbufn_add xss buf) nts = (z', buf', nts')\"\n    and bounded: \"pred_mapping (\\<lambda>x. x \\<le> j) P\" \"pred_mapping (\\<lambda>x. x \\<le> j') P'\"\n    and rm: \"rel_mapping (\\<le>) P P'\"\n    and safe: \"safe_regex m g r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and pre_buf: \"wf_mbufn' \\<sigma> P V j n R r buf\"\n    and pre_nts: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [progress_regex \\<sigma> P r j..<j'] nts\"\n    and xss: \"list_all3 list_all2\n     (map (\\<lambda>\\<phi> i. qtable n (fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>)) \\<phi>s)\n     (map2 upt (map (\\<lambda>\\<phi>. progress \\<sigma> P \\<phi> j) \\<phi>s) (map (\\<lambda>\\<phi>. progress \\<sigma> P' \\<phi> j') \\<phi>s)) xss\"\n    and \"j \\<le> j'\"\n    and base: \"U (progress_regex \\<sigma> P r j) z\"\n    and step: \"\\<And>k Xs z. progress_regex \\<sigma> P r j \\<le> k \\<Longrightarrow> Suc k \\<le> progress_regex \\<sigma> P' r j' \\<Longrightarrow>\n      list_all2 (\\<lambda>\\<phi>. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) k \\<phi>)) \\<phi>s Xs \\<Longrightarrow>\n      U k z \\<Longrightarrow> U (Suc k) (f Xs (\\<tau> \\<sigma> k) z)\"\n  shows \"U (progress_regex \\<sigma> P' r j') z'\"\n  using pre_buf pre_nts bounded rm \\<open>j \\<le> j'\\<close> to_mregex_progress[OF safe mr, of \\<sigma> P' j'] to_mregex_empty_progress[OF safe, of mr \\<sigma> P j] base\n  unfolding wf_mbufn'_def mr prod.case\n  by (fastforce dest!: mbufnt_take_induct[OF eq wf_mbufn_add[OF _ xss] pre_nts, of U]\n      simp: list.rel_map le_imp_diff_is_add ac_simps Mini_def\n      intro: progress_mono_gen[OF \\<open>j \\<le> j'\\<close> rm] list.rel_refl_strong progress_le_gen\n      intro!: base step  dest: list_all2_lengthD split: if_splits)\n\nlemma progress_Until_le: \"progress \\<sigma> P (Formula.Until \\<phi> I \\<psi>) j \\<le> min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)\"\n  by (auto simp: trans_le_add1 intro!: cInf_lower)\n\nlemma progress_MatchF_le: \"progress \\<sigma> P (Formula.MatchF I r) j \\<le> progress_regex \\<sigma> P r j\"\n  by (auto simp: trans_le_add1 progress_regex_def intro!: cInf_lower)\n\nlemma list_all2_upt_Cons: \"P a x \\<Longrightarrow> list_all2 P [Suc a..<b] xs \\<Longrightarrow> Suc a \\<le> b \\<Longrightarrow>\n  list_all2 P [a..<b] (x # xs)\"\n  by (simp add: list_all2_Cons2 upt_eq_Cons_conv)\n\nlemma list_all2_upt_append: \"list_all2 P [a..<b] xs \\<Longrightarrow> list_all2 P [b..<c] ys \\<Longrightarrow>\n  a \\<le> b \\<Longrightarrow> b \\<le> c \\<Longrightarrow> list_all2 P [a..<c] (xs @ ys)\"\n  by (induction xs arbitrary: a) (auto simp add: list_all2_Cons2 upt_eq_Cons_conv)\n\nlemma list_all3_list_all2_conv: \"list_all3 R xs xs ys = list_all2 (\\<lambda>x. R x x) xs ys\"\n  by (auto simp: list_all3_conv_all_nth list_all2_conv_all_nth)\n\nlemma map_split_map: \"map_split f (map g xs) = map_split (f o g) xs\"\n  by (induct xs) auto\n\nlemma map_split_alt: \"map_split f xs = (map (fst o f) xs, map (snd o f) xs)\"\n  by (induct xs) (auto split: prod.splits)\n\nlemma fv_formula_of_constraint: \"fv (formula_of_constraint (t1, p, c, t2)) = fv_trm t1 \\<union> fv_trm t2\"\n  by (induction \"(t1, p, c, t2)\" rule: formula_of_constraint.induct) simp_all\n\nlemma (in maux) wf_mformula_wf_set: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow> wf_set n (Formula.fv \\<phi>')\"\n  unfolding wf_set_def\nproof (induction rule: wf_mformula.induct)\n  case (AndRel P V n R \\<phi> \\<phi>' \\<psi>' conf)\n  then show ?case by (auto simp: fv_formula_of_constraint dest!: subsetD)\nnext\n  case (Ands P V n R l l_pos l_neg l' buf A_pos A_neg)\n  from Ands.IH have \"\\<forall>\\<phi>'\\<in>set (l_pos @ map remove_neg l_neg). \\<forall>x\\<in>fv \\<phi>'. x < n\"\n    by (simp add: list_all2_conv_all_nth all_set_conv_all_nth[of \"_ @ _\"] del: set_append)\n  then have \"\\<forall>\\<phi>'\\<in>set (l_pos @ l_neg). \\<forall>x\\<in>fv \\<phi>'. x < n\"\n    by (auto dest: bspec[where x=\"remove_neg _\"])\n  then show ?case using Ands.hyps(2) by auto\nnext\n  case (Agg P V b n R \\<phi> \\<phi>' y f g0 \\<omega>)\n  then have \"Formula.fvi_trm b f \\<subseteq> Formula.fvi b \\<phi>'\"\n    by (auto simp: fvi_trm_iff_fv_trm[where b=b] fvi_iff_fv[where b=b])\n  with Agg show ?case by (auto 0 3 simp: Un_absorb2 fvi_iff_fv[where b=b])\nnext\n  case (Since P V n R \\<phi> \\<phi>' \\<psi> \\<psi>' args \\<phi>'' I R' buf nts aux)\n  then have valid: \"valid_aggargs n (Formula.fv \\<psi>') (args_agg args)\"\n    by (auto simp: wf_since_aux_def)\n  then show ?case\n    using Since(3,6,11,14,15)\n  proof (cases \"args_agg args\")\n    case (Some aggargs)\n    have \"Formula.fvi_trm (aggargs_b aggargs) (aggargs_f aggargs) \\<subseteq> Formula.fvi (aggargs_b aggargs) (formula.Since \\<phi>' I \\<psi>')\"\n      using valid\n      by (auto simp: fvi_trm_iff_fv_trm[where b=\"aggargs_b aggargs\"] fvi_iff_fv[where b=\"aggargs_b aggargs\"] valid_aggargs_def safe_aggargs_def Some)\n    then show ?thesis\n      using Since(3,6,11,14,15) valid\n      by (auto 0 3 simp: Un_absorb2 fvi_iff_fv[where b=\"aggargs_b aggargs\"] packagg_def agg_n_def Some valid_aggargs_def safe_aggargs_def split: if_splits)\n  qed (auto simp: packagg_def agg_n_def split: if_splits)\nnext\n  case (Until P V n R \\<phi> \\<phi>' \\<psi> \\<psi>' args \\<phi>'' I R' buf nts t aux)\n  then have valid: \"valid_aggargs n (Formula.fv \\<psi>') (args_agg args)\"\n    by (auto simp: wf_until_aux_def)\n  then show ?case\n    using Until(3,6,11,16,17)\n  proof (cases \"args_agg args\")\n    case (Some aggargs)\n    have \"Formula.fvi_trm (aggargs_b aggargs) (aggargs_f aggargs) \\<subseteq> Formula.fvi (aggargs_b aggargs) (formula.Since \\<phi>' I \\<psi>')\"\n      using valid\n      by (auto simp: fvi_trm_iff_fv_trm[where b=\"aggargs_b aggargs\"] fvi_iff_fv[where b=\"aggargs_b aggargs\"] valid_aggargs_def safe_aggargs_def Some)\n    then show ?thesis\n      using Until(3,6,11,16,17) valid\n      by (auto 0 3 simp: Un_absorb2 fvi_iff_fv[where b=\"aggargs_b aggargs\"] packagg_def agg_n_def Some valid_aggargs_def safe_aggargs_def split: if_splits)\n  qed (auto simp: packagg_def agg_n_def split: if_splits)\nnext\n  case (MatchP r P V n R \\<phi>s mr mrs buf nts I aux)\n  then obtain \\<phi>s' where conv: \"to_mregex r = (mr, \\<phi>s')\" by blast\n  with MatchP have \"\\<forall>\\<phi>'\\<in>set \\<phi>s'. \\<forall>x\\<in>fv \\<phi>'. x < n\"\n    by (simp add: list_all2_conv_all_nth all_set_conv_all_nth[of \\<phi>s'])\n  with conv show ?case\n    by (simp add: to_mregex_ok[THEN conjunct1] fv_regex_alt[OF \\<open>safe_regex _ _ r\\<close>])\nnext\n  case (MatchF r  P V n R \\<phi>s mr mrs buf nts I aux)\n  then obtain \\<phi>s' where conv: \"to_mregex r = (mr, \\<phi>s')\" by blast\n  with MatchF have \"\\<forall>\\<phi>'\\<in>set \\<phi>s'. \\<forall>x\\<in>fv \\<phi>'. x < n\"\n    by (simp add: list_all2_conv_all_nth all_set_conv_all_nth[of \\<phi>s'])\n  with conv show ?case\n    by (simp add: to_mregex_ok[THEN conjunct1] fv_regex_alt[OF \\<open>safe_regex _ _ r\\<close>])\nqed (auto simp: fvi_Suc split: if_splits)\n\nlemma qtable_mmulti_join:\n  assumes pos: \"list_all3 (\\<lambda>A Qi X. qtable n A P Qi X \\<and> wf_set n A) A_pos Q_pos L_pos\"\n    and neg: \"list_all3 (\\<lambda>A Qi X. qtable n A P Qi X \\<and> wf_set n A) A_neg Q_neg L_neg\"\n    and C_eq: \"C = \\<Union>(set A_pos)\" and L_eq: \"L = L_pos @ L_neg\"\n    and \"A_pos \\<noteq> []\" and fv_subset: \"\\<Union>(set A_neg) \\<subseteq> \\<Union>(set A_pos)\"\n    and restrict_pos: \"\\<And>x. wf_tuple n C x \\<Longrightarrow> P x \\<Longrightarrow> list_all (\\<lambda>A. P (restrict A x)) A_pos\"\n    and restrict_neg: \"\\<And>x. wf_tuple n C x \\<Longrightarrow> P x \\<Longrightarrow> list_all (\\<lambda>A. P (restrict A x)) A_neg\"\n    and Qs: \"\\<And>x. wf_tuple n C x \\<Longrightarrow> P x \\<Longrightarrow> Q x \\<longleftrightarrow>\n      list_all2 (\\<lambda>A Qi. Qi (restrict A x)) A_pos Q_pos \\<and>\n      list_all2 (\\<lambda>A Qi. \\<not> Qi (restrict A x)) A_neg Q_neg\"\n  shows \"qtable n C P Q (mmulti_join n A_pos A_neg L)\"\nproof (rule qtableI)\n  from pos have 1: \"list_all2 (\\<lambda>A X. table n A X \\<and> wf_set n A) A_pos L_pos\"\n    by (simp add: list_all3_conv_all_nth list_all2_conv_all_nth qtable_def)\n  moreover from neg have \"list_all2 (\\<lambda>A X. table n A X \\<and> wf_set n A) A_neg L_neg\"\n    by (simp add: list_all3_conv_all_nth list_all2_conv_all_nth qtable_def)\n  ultimately have L: \"list_all2 (\\<lambda>A X. table n A X \\<and> wf_set n A) (A_pos @ A_neg) (L_pos @ L_neg)\"\n    by (rule list_all2_appendI)\n  note in_join_iff = mmulti_join_correct[OF \\<open>A_pos \\<noteq> []\\<close> L]\n  from 1 have take_eq: \"take (length A_pos) (L_pos @ L_neg) = L_pos\"\n    by (auto dest!: list_all2_lengthD)\n  from 1 have drop_eq: \"drop (length A_pos) (L_pos @ L_neg) = L_neg\"\n    by (auto dest!: list_all2_lengthD)\n\n  note mmulti_join.simps[simp del]\n  show \"table n C (mmulti_join n A_pos A_neg L)\"\n    unfolding C_eq L_eq table_def by (simp add: in_join_iff)\n  show \"Q x\" if \"x \\<in> mmulti_join n A_pos A_neg L\" \"wf_tuple n C x\" \"P x\" for x\n    using that(2,3)\n  proof (rule Qs[THEN iffD2, OF _ _ conjI])\n    have pos': \"list_all2 (\\<lambda>A. (\\<in>) (restrict A x)) A_pos L_pos\"\n      and neg': \"list_all2 (\\<lambda>A. (\\<notin>) (restrict A x)) A_neg L_neg\"\n      using that(1) unfolding L_eq in_join_iff take_eq drop_eq by simp_all\n    show \"list_all2 (\\<lambda>A Qi. Qi (restrict A x)) A_pos Q_pos\"\n      using pos pos' restrict_pos that(2,3)\n      by (simp add: list_all3_conv_all_nth list_all2_conv_all_nth list_all_length qtable_def)\n    have fv_subset': \"\\<And>i. i < length A_neg \\<Longrightarrow> A_neg ! i \\<subseteq> C\"\n      using fv_subset unfolding C_eq by (auto simp: Sup_le_iff)\n    show \"list_all2 (\\<lambda>A Qi. \\<not> Qi (restrict A x)) A_neg Q_neg\"\n      using neg neg' restrict_neg that(2,3)\n      by (auto simp: list_all3_conv_all_nth list_all2_conv_all_nth list_all_length qtable_def\n          wf_tuple_restrict_simple[OF _ fv_subset'])\n  qed\n  show \"x \\<in> mmulti_join n A_pos A_neg L\" if \"wf_tuple n C x\" \"P x\" \"Q x\" for x\n    unfolding L_eq in_join_iff take_eq drop_eq\n  proof (intro conjI)\n    from that have pos': \"list_all2 (\\<lambda>A Qi. Qi (restrict A x)) A_pos Q_pos\"\n      and neg': \"list_all2 (\\<lambda>A Qi. \\<not> Qi (restrict A x)) A_neg Q_neg\"\n      using Qs[THEN iffD1] by auto\n    show \"wf_tuple n (\\<Union>A\\<in>set A_pos. A) x\"\n      using \\<open>wf_tuple n C x\\<close> unfolding C_eq by simp\n    show \"list_all2 (\\<lambda>A. (\\<in>) (restrict A x)) A_pos L_pos\"\n      using pos pos' restrict_pos that(1,2)\n      by (simp add: list_all3_conv_all_nth list_all2_conv_all_nth list_all_length qtable_def\n          C_eq wf_tuple_restrict_simple[OF _ Sup_upper])\n    show \"list_all2 (\\<lambda>A. (\\<notin>) (restrict A x)) A_neg L_neg\"\n      using neg neg' restrict_neg that(1,2)\n      by (auto simp: list_all3_conv_all_nth list_all2_conv_all_nth list_all_length qtable_def)\n  qed\nqed\n\nlemma nth_filter: \"i < length (filter P xs) \\<Longrightarrow>\n  (\\<And>i'. i' < length xs \\<Longrightarrow> P (xs ! i') \\<Longrightarrow> Q (xs ! i')) \\<Longrightarrow> Q (filter P xs ! i)\"\n  by (metis (lifting) in_set_conv_nth set_filter mem_Collect_eq)\n\nlemma nth_partition: \"i < length xs \\<Longrightarrow>\n  (\\<And>i'. i' < length (filter P xs) \\<Longrightarrow> Q (filter P xs ! i')) \\<Longrightarrow>\n  (\\<And>i'. i' < length (filter (Not \\<circ> P) xs) \\<Longrightarrow> Q (filter (Not \\<circ> P) xs ! i')) \\<Longrightarrow> Q (xs ! i)\"\n  by (metis (no_types, lifting) in_set_conv_nth set_filter mem_Collect_eq comp_apply)\n\nlemma qtable_bin_join:\n  assumes \"qtable n A P Q1 X\" \"qtable n B P Q2 Y\" \"\\<not> b \\<Longrightarrow> B \\<subseteq> A\" \"C = A \\<union> B\"\n    \"\\<And>x. wf_tuple n C x \\<Longrightarrow> P x \\<Longrightarrow> P (restrict A x) \\<and> P (restrict B x)\"\n    \"\\<And>x. b \\<Longrightarrow> wf_tuple n C x \\<Longrightarrow> P x \\<Longrightarrow> Q x \\<longleftrightarrow> Q1 (restrict A x) \\<and> Q2 (restrict B x)\"\n    \"\\<And>x. \\<not> b \\<Longrightarrow> wf_tuple n C x \\<Longrightarrow> P x \\<Longrightarrow> Q x \\<longleftrightarrow> Q1 (restrict A x) \\<and> \\<not> Q2 (restrict B x)\"\n  shows \"qtable n C P Q (bin_join n A X b B Y)\"\n  using qtable_join[OF assms] bin_join_table[of n A X B Y b] assms(1,2)\n  by (auto simp add: qtable_def)\n\nlemma restrict_update: \"y \\<notin> A \\<Longrightarrow> y < length x \\<Longrightarrow> restrict A (x[y:=z]) = restrict A x\"\n  unfolding restrict_def by (auto simp add: nth_list_update)\n\nlemma qtable_assign:\n  assumes \"qtable n A P Q X\"\n    \"y < n\" \"insert y A = A'\" \"y \\<notin> A\"\n    \"\\<And>x'. wf_tuple n A' x' \\<Longrightarrow> P x' \\<Longrightarrow> P (restrict A x')\"\n    \"\\<And>x. wf_tuple n A x \\<Longrightarrow> P x \\<Longrightarrow> Q x \\<Longrightarrow> Q' (x[y:=Some (f x)])\"\n    \"\\<And>x'. wf_tuple n A' x' \\<Longrightarrow> P x' \\<Longrightarrow> Q' x' \\<Longrightarrow> Q (restrict A x') \\<and> x' ! y = Some (f (restrict A x'))\"\n  shows \"qtable n A' P Q' ((\\<lambda>x. x[y:=Some (f x)]) ` X)\" (is \"qtable _ _ _ _ ?Y\")\nproof (rule qtableI)\n  from assms(1) have \"table n A X\" unfolding qtable_def by simp\n  then show \"table n A' ?Y\"\n    unfolding table_def wf_tuple_def using assms(2,3)\n    by (auto simp: nth_list_update)\nnext\n  fix x'\n  assume \"x' \\<in> ?Y\" \"wf_tuple n A' x'\" \"P x'\"\n  then obtain x where \"x \\<in> X\" and x'_eq: \"x' = x[y:=Some (f x)]\" by blast\n  then have \"wf_tuple n A x\"\n    using assms(1) unfolding qtable_def table_def by blast\n  then have \"y < length x\" using assms(2) by (simp add: wf_tuple_def)\n  with \\<open>wf_tuple n A x\\<close> have \"restrict A x' = x\"\n    unfolding x'_eq by (simp add: restrict_update[OF assms(4)] restrict_idle)\n  with \\<open>wf_tuple n A' x'\\<close> \\<open>P x'\\<close> have \"P x\"\n    using assms(5) by blast\n  with \\<open>wf_tuple n A x\\<close> \\<open>x \\<in> X\\<close> have \"Q x\"\n    using assms(1) by (elim in_qtableE)\n  with \\<open>wf_tuple n A x\\<close> \\<open>P x\\<close> show \"Q' x'\"\n    unfolding x'_eq by (rule assms(6))\nnext\n  fix x'\n  assume \"wf_tuple n A' x'\" \"P x'\" \"Q' x'\"\n  then have \"wf_tuple n A (restrict A x')\"\n    using assms(3) by (auto intro!: wf_tuple_restrict_simple)\n  moreover have \"P (restrict A x')\"\n    using \\<open>wf_tuple n A' x'\\<close> \\<open>P x'\\<close> by (rule assms(5))\n  moreover have \"Q (restrict A x')\" and y: \"x' ! y = Some (f (restrict A x'))\"\n    using \\<open>wf_tuple n A' x'\\<close> \\<open>P x'\\<close> \\<open>Q' x'\\<close> by (auto dest!: assms(7))\n  ultimately have \"restrict A x' \\<in> X\" by (intro in_qtableI[OF assms(1)])\n  moreover have \"x' = (restrict A x')[y:=Some (f (restrict A x'))]\"\n    using y assms(2,3) \\<open>wf_tuple n A (restrict A x')\\<close> \\<open>wf_tuple n A' x'\\<close>\n    by (auto simp: list_eq_iff_nth_eq wf_tuple_def nth_list_update nth_restrict)\n  ultimately show \"x' \\<in> ?Y\" by simp\nqed\n\nlemma sat_the_update: \"y \\<notin> fv \\<phi> \\<Longrightarrow> Formula.sat \\<sigma> V (map the (x[y:=z])) i \\<phi> = Formula.sat \\<sigma> V (map the x) i \\<phi>\"\n  by (rule sat_fv_cong) (metis map_update nth_list_update_neq)\n\nlemma progress_constraint: \"progress \\<sigma> P (formula_of_constraint c) j = j\"\n  by (induction rule: formula_of_constraint.induct) simp_all\n\nlemma qtable_filter:\n  assumes \"qtable n A P Q X\"\n    \"\\<And>x. wf_tuple n A x \\<Longrightarrow> P x \\<Longrightarrow> Q x \\<and> R x \\<longleftrightarrow> Q' x\"\n  shows \"qtable n A P Q' (Set.filter R X)\" (is \"qtable _ _ _ _ ?Y\")\nproof (rule qtableI)\n  from assms(1) have \"table n A X\"\n    unfolding qtable_def by simp\n  then show \"table n A ?Y\"\n    unfolding table_def wf_tuple_def by simp\nnext\n  fix x\n  assume \"x \\<in> ?Y\" \"wf_tuple n A x\" \"P x\"\n  with assms show \"Q' x\" by (auto elim!: in_qtableE)\nnext\n  fix x\n  assume \"wf_tuple n A x\" \"P x\" \"Q' x\"\n  with assms show \"x \\<in> Set.filter R X\" by (auto intro!: in_qtableI)\nqed\n\nlemma eval_constraint_sat_eq: \"wf_tuple n A x \\<Longrightarrow> fv_trm t1 \\<subseteq> A \\<Longrightarrow> fv_trm t2 \\<subseteq> A \\<Longrightarrow>\n  \\<forall>i\\<in>A. i < n \\<Longrightarrow> eval_constraint (t1, p, c, t2) x =\n    Formula.sat \\<sigma> V (map the x) i (formula_of_constraint (t1, p, c, t2))\"\n  by (induction \"(t1, p, c, t2)\" rule: formula_of_constraint.induct)\n    (simp_all add: meval_trm_eval_trm)\n\ndeclare progress_le_gen[simp]\n\ndefinition \"wf_envs \\<sigma> j \\<delta> P P' V db =\n  (dom V = dom P \\<and>\n   Mapping.keys db = dom P \\<union> (\\<Union>k \\<in> {j ..< j + \\<delta>}. {p. p \\<in> fst ` \\<Gamma> \\<sigma> k}) \\<and>\n   rel_mapping (\\<le>) P P' \\<and>\n   pred_mapping (\\<lambda>i. i \\<le> j) P \\<and>\n   pred_mapping (\\<lambda>i. i \\<le> j + \\<delta>) P' \\<and>\n   (\\<forall>p \\<in> Mapping.keys db - dom P. the (Mapping.lookup db p) = map (\\<lambda>k. {ts. (p, ts) \\<in> \\<Gamma> \\<sigma> k}) [j ..< j + \\<delta>]) \\<and>\n   (\\<forall>p \\<in> dom P. list_all2 (\\<lambda>i X. X = the (V p) i) [the (P p)..<the (P' p)] (the (Mapping.lookup db p))))\"\n\n\nlift_definition mk_db :: \"(Formula.name \\<times> event_data list) set \\<Rightarrow> Formula.database\" is\n  \"\\<lambda>X p. (if p \\<in> fst ` X then Some [{ts. (p, ts) \\<in> X}] else None)\" .\n\nlemma wf_envs_mk_db: \"wf_envs \\<sigma> j 1 Map.empty Map.empty Map.empty (mk_db (\\<Gamma> \\<sigma> j))\"\n  unfolding wf_envs_def mk_db_def\n  by transfer (force split: if_splits simp: image_iff rel_mapping_alt)\n\nlemma wf_envs_update:\n  assumes wf_envs: \"wf_envs \\<sigma> j \\<delta> P P' V db\"\n    and m_eq: \"m = Formula.nfv \\<phi>\"\n    and in_fv: \"{0 ..< m} \\<subseteq> fv \\<phi>\"\n    and xs: \"list_all2 (\\<lambda>i. qtable m (Formula.fv \\<phi>) (mem_restr UNIV) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>))\n      [progress \\<sigma> P \\<phi> j..<progress \\<sigma> P' \\<phi> (j + \\<delta>)] xs\"\n  shows \"wf_envs \\<sigma> j \\<delta> (P(p \\<mapsto> progress \\<sigma> P \\<phi> j)) (P'(p \\<mapsto> progress \\<sigma> P' \\<phi> (j + \\<delta>)))\n    (V(p \\<mapsto> \\<lambda>i. {v. length v = m \\<and> Formula.sat \\<sigma> V v i \\<phi>}))\n    (Mapping.update p (map (image (map the)) xs) db)\"\n  unfolding wf_envs_def\nproof (intro conjI ballI, goal_cases)\n  case 3\n  from assms show ?case\n    by (auto simp: wf_envs_def pred_mapping_alt progress_le progress_mono_gen\n        intro!: rel_mapping_map_upd)\nnext\n  case (6 p')\n  with assms show ?case by (cases \"p' \\<in> dom P\") (auto simp: wf_envs_def lookup_update')\nnext\n  case (7 p')\n  from xs in_fv have \"list_all2 (\\<lambda>x y. map the ` y = {v. length v = m \\<and> Formula.sat \\<sigma> V v x \\<phi>})\n      [progress \\<sigma> P \\<phi> j..<progress \\<sigma> P' \\<phi> (j + \\<delta>)] xs\"\n    by (elim list.rel_mono_strong) (auto 0 3 simp: wf_tuple_def nth_append\n      elim!: in_qtableE in_qtableI intro!: image_eqI[where x=\"map Some _\"])\n  moreover have \"list_all2 (\\<lambda>i X. X = the (V p') i) [the (P p')..<the (P' p')] (the (Mapping.lookup db p'))\"\n    if \"p \\<noteq> p'\"\n  proof -\n    from that 7 have \"p' \\<in> dom P\" by simp\n    with wf_envs show ?thesis by (simp add: wf_envs_def)\n  qed\n  ultimately show ?case\n    by (simp add: list.rel_map image_iff lookup_update')\nqed (use assms in \\<open>auto simp: wf_envs_def\\<close>)\n\nlemma wf_envs_P_simps[simp]:\n   \"wf_envs \\<sigma> j \\<delta> P P' V db \\<Longrightarrow> pred_mapping (\\<lambda>i. i \\<le> j) P\"\n   \"wf_envs \\<sigma> j \\<delta> P P' V db \\<Longrightarrow> pred_mapping (\\<lambda>i. i \\<le> j + \\<delta>) P'\"\n   \"wf_envs \\<sigma> j \\<delta> P P' V db \\<Longrightarrow> rel_mapping (\\<le>) P P'\"\n  unfolding wf_envs_def by auto\n\nlemma wf_envs_progress_le[simp]:\n   \"wf_envs \\<sigma> j \\<delta> P P' V db \\<Longrightarrow> progress \\<sigma> P \\<phi> j \\<le> j\"\n   \"wf_envs \\<sigma> j \\<delta> P P' V db \\<Longrightarrow> progress \\<sigma> P' \\<phi> (j + \\<delta>) \\<le> j + \\<delta>\"\n  unfolding wf_envs_def by auto\n\nlemma wf_envs_progress_regex_le[simp]:\n   \"wf_envs \\<sigma> j \\<delta> P P' V db \\<Longrightarrow> progress_regex \\<sigma> P r j \\<le> j\"\n   \"wf_envs \\<sigma> j \\<delta> P P' V db \\<Longrightarrow> progress_regex \\<sigma> P' r (j + \\<delta>) \\<le> j + \\<delta>\"\n  unfolding wf_envs_def by (auto simp: progress_regex_le)\n\nlemma wf_envs_progress_mono[simp]:\n   \"wf_envs \\<sigma> j \\<delta> P P' V db \\<Longrightarrow> a \\<le> b \\<Longrightarrow> progress \\<sigma> P \\<phi> a \\<le> progress \\<sigma> P' \\<phi> b\"\n  unfolding wf_envs_def\n  by (auto simp: progress_mono_gen)\n\nlemma qtable_wf_tuple_cong: \"qtable n A P Q X \\<Longrightarrow> A = B \\<Longrightarrow> (\\<And>v. wf_tuple n A v \\<Longrightarrow> P v \\<Longrightarrow> Q v = Q' v) \\<Longrightarrow> qtable n B P Q' X\"\n  unfolding qtable_def table_def by blast\n\nlemma list_all2_replicate[simp]: \"list_all2 R (replicate m x) xs \\<longleftrightarrow> length xs = m \\<and> (\\<forall>i < m. R x (xs ! i))\"\n  by (auto simp: list_all2_conv_all_nth)\n\nlemma list_all2_replicate2[simp]: \"list_all2 R xs (replicate m x) \\<longleftrightarrow> length xs = m \\<and> (\\<forall>i < m. R (xs ! i) x)\"\n  by (auto simp: list_all2_conv_all_nth)\n\ndefinition \"Untilp pos \\<phi> I \\<psi> \\<equiv> Formula.Until (if pos then \\<phi> else Formula.Neg \\<phi>) I \\<psi>\"\n\nlemma (in maux) update_until':\n  \"wf_until_aux \\<sigma> V R args \\<phi>'' \\<psi>'' aux'' (Monitor.progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (j + \\<delta>)) \\<and>\n  Monitor.progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j + length zs =\n  Monitor.progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (j + \\<delta>) \\<and>\n  Monitor.progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j + length zs + length_muaux args aux'' =\n  min (Monitor.progress \\<sigma> P' \\<phi>''' (j + \\<delta>)) (Monitor.progress \\<sigma> P' \\<psi>'' (j + \\<delta>)) \\<and>\n  list_all2 (\\<lambda>i. qtable (agg_n args) (fv (packagg args (Untilp pos \\<phi>'' I \\<psi>''))) (mem_restr R')\n    (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (packagg args (Untilp pos \\<phi>'' I \\<psi>''))))\n    [Monitor.progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j..<\n     Monitor.progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j + length zs] zs \\<and>\n  nt = (if j + \\<delta> = 0 then 0 else \\<tau> \\<sigma> (min (j + \\<delta> - 1) (min (Monitor.progress \\<sigma> P' \\<phi>'' (j + \\<delta>)) (Monitor.progress \\<sigma> P' \\<psi>'' (j + \\<delta>)))))\"\n  if q1: \"list_all2 (\\<lambda>i. qtable n (fv \\<phi>'') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>''))\n    [Monitor.progress \\<sigma> P \\<phi>'' j..<Monitor.progress \\<sigma> P' \\<phi>'' (j + \\<delta>)] xs\"\n  and q2: \"list_all2 (\\<lambda>i. qtable n (fv \\<psi>'') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>''))\n    [Monitor.progress \\<sigma> P \\<psi>'' j..<Monitor.progress \\<sigma> P' \\<psi>'' (j + \\<delta>)] ys\"\n  and eq1: \"mbuf2t_take (add_new_muaux args) aux (mbuf2_add xs ys buf) (nts @ map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) = (aux', buf', nts')\"\n  and eq2: \"eval_muaux args nt aux' = (zs, aux'')\"\n  and pos: \"if args_pos args then \\<phi>''' = \\<phi>'' else \\<phi>''' = Formula.Neg \\<phi>''\"\n  and wf_envs: \"wf_envs \\<sigma> j \\<delta> P P' V db\"\n  and fvi_sub: \"Formula.fv \\<phi>'' \\<subseteq> Formula.fv \\<psi>''\"\n  and buf: \"wf_mbuf2' \\<sigma> P V j n R \\<phi>'' \\<psi>'' buf\"\n  and nts: \"wf_ts \\<sigma> P j \\<phi>'' \\<psi>'' nts\"\n  and aux: \"wf_until_aux \\<sigma> V R args \\<phi>'' \\<psi>'' aux (progress \\<sigma> P (Formula.Until \\<phi>''' I \\<psi>'') j)\"\n  and args_ivl: \"args_ivl args = I\"\n  and args_n: \"args_n args = n\"\n  and args_L: \"args_L args = Formula.fv \\<phi>''\"\n  and args_R: \"args_R args = Formula.fv \\<psi>''\"\n  and args_pos: \"pos = args_pos args\"\n  and t: \"t = (if j = 0 then 0 else \\<tau> \\<sigma> (min (j - 1) (min (progress \\<sigma> P \\<phi>'' j) (progress \\<sigma> P \\<psi>'' j))))\"\n  and nt0: \"nt = lookahead_ts nts' nts (map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) t\"\n  and length_aux: \"progress \\<sigma> P (Formula.Until \\<phi>''' I \\<psi>'') j + length_muaux args aux = min (progress \\<sigma> P \\<phi>'' j) (progress \\<sigma> P \\<psi>'' j)\"\n  and nts_snoc: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [min (progress \\<sigma> P \\<phi>'' j) (progress \\<sigma> P \\<psi>'' j)..< j + \\<delta>] (nts @ map (\\<tau> \\<sigma>) [j ..< j + \\<delta>])\"\n  and mr: \"mem_restr R = mem_restr (lift_envs' (agg_b args) R')\"\n  and valid_aggargs: \"valid_aggargs n (fv \\<psi>'') (args_agg args)\"\nproof -\n  note sat.simps[simp del] progress_simps[simp del]\n  define ne where \"ne \\<equiv> progress \\<sigma> P (Formula.Until \\<phi>''' I \\<psi>'') j\"\n  have \\<phi>''': \"progress \\<sigma> P \\<phi>''' j = progress \\<sigma> P \\<phi>'' j\"  \"progress \\<sigma> P' \\<phi>''' j = progress \\<sigma> P' \\<phi>'' j\" for j\n    using pos by (simp_all add: progress.simps split: if_splits)\n  have update1: \"wf_until_aux \\<sigma> V R args \\<phi>'' \\<psi>'' aux' (progress \\<sigma> P (Formula.Until \\<phi>''' I \\<psi>'') j) \\<and>\n      ne + length_muaux args aux' = min (progress \\<sigma> P' \\<phi>''' (j + \\<delta>)) (progress \\<sigma> P' \\<psi>'' (j + \\<delta>))\"\n    using q1 q2 nts_snoc length_aux aux fvi_sub \n    unfolding \\<phi>'''\n    by (elim mbuf2t_take_add_induct'[where j'=\"j + \\<delta>\", OF eq1 wf_envs_P_simps[OF wf_envs] buf])\n      (auto simp: args_n args_L args_R ne_def wf_update_until split: option.splits)\n  then obtain cur auxlist' where valid_aux': \"valid_muaux args cur aux' auxlist'\" and\n    cur: \"cur = (if ne + length auxlist' = 0 then 0 else \\<tau> \\<sigma> (ne + length auxlist' - 1))\" and\n    wf_auxlist': \"wf_until_auxlist \\<sigma> V n R pos \\<phi>'' I \\<psi>'' auxlist' (progress \\<sigma> P (Formula.Until \\<phi>''' I \\<psi>'') j)\"\n    unfolding wf_until_aux_def ne_def args_ivl args_n args_pos by auto\n  have length_aux': \"length_muaux args aux' = length auxlist'\"\n    using valid_length_muaux[OF valid_aux'] .\n  have nts': \"wf_ts \\<sigma> P' (j + \\<delta>) \\<phi>'' \\<psi>'' nts'\"\n    using q1 q2 wf_envs nts_snoc\n    unfolding wf_ts_def\n    by (intro mbuf2t_take_eqD(2)[OF eq1]) (auto intro: wf_mbuf2_add buf[unfolded wf_mbuf2'_def])\n  have nt: \"nt = (if j + \\<delta> = 0 then 0 else \\<tau> \\<sigma> (min (j + \\<delta> - 1) (min (progress \\<sigma> P' \\<phi>'' (j + \\<delta>)) (progress \\<sigma> P' \\<psi>'' (j + \\<delta>)))))\"\n    using nts nts' unfolding nt0 t\n    apply (auto simp: hd_append hd_rev last_map wf_ts_def lookahead_ts_def)\n    using list_all2_hdD(1) list_all2_hdD(2) apply fastforce\n    using list_all2_lastD  apply fastforce\n      apply (metis (mono_tags) list_all2_hdD(1) list_all2_hdD(2) min.absorb2 Suc_diff_Suc diff_zero less_Suc_eq_le)\n     apply (metis (mono_tags, lifting) add_gr_0 list_all2_hdD(1) list_all2_hdD(2) min.absorb2 Suc_diff_Suc diff_zero less_Suc_eq_le)\n    apply (metis (mono_tags, lifting) add_gr_0 list_all2_hdD(1) list_all2_hdD(2) min.absorb2 Suc_diff_Suc diff_zero less_Suc_eq_le)\n    done\n  define zs'' where \"zs'' = fst (eval_until I nt auxlist')\"\n  define auxlist'' where \"auxlist'' = snd (eval_until I nt auxlist')\"\n  have current_w_le: \"cur \\<le> nt\"\n  proof (cases nts')\n    case Nil\n    have p_le: \"min (progress \\<sigma> P' \\<phi>''' (j + \\<delta>)) (progress \\<sigma> P' \\<psi>'' (j + \\<delta>)) \\<le> j + \\<delta>\"\n      using wf_envs_progress_le[OF wf_envs]\n      by (auto simp: min_def le_diff_conv)\n    then show ?thesis\n      unfolding cur conjunct2[OF update1, unfolded length_aux'] nt\n      using Nil by (auto simp: \\<phi>''' intro!: \\<tau>_mono)\n  next\n    case (Cons nt x)\n    have progress_\\<phi>''': \"progress \\<sigma> P' \\<phi>'' (j + \\<delta>) = progress \\<sigma> P' \\<phi>''' (j + \\<delta>)\"\n      using pos by (auto simp add: progress.simps split: if_splits)\n    have p_le: \"min (progress \\<sigma> P' \\<phi>''' (j + \\<delta>)) (progress \\<sigma> P' \\<psi>'' (j + \\<delta>)) \\<le> j + \\<delta>\"\n      using wf_envs_progress_le[OF wf_envs]\n      by (auto simp: min_def le_diff_conv)\n    then show ?thesis\n      unfolding cur conjunct2[OF update1, unfolded length_aux'] Cons progress_\\<phi>''' nt\n      by (auto split: if_splits list.splits intro!: \\<tau>_mono)\n  qed\n  have valid_aux'': \"valid_muaux args cur aux'' auxlist''\"\n    using valid_eval_muaux[OF valid_aux' current_w_le eq2, of zs'' auxlist'']\n    by (auto simp add: args_ivl zs''_def auxlist''_def)\n  have length_aux'': \"length_muaux args aux'' = length auxlist''\"\n    using valid_length_muaux[OF valid_aux''] .\n  have eq2': \"eval_until I nt auxlist' = (zs'', auxlist'')\"\n    by (auto simp: zs''_def auxlist''_def)\n  have length_aux'_aux'': \"length_muaux args aux' = length zs'' + length_muaux args aux''\"\n    using eval_until_length[OF eq2'] unfolding length_aux' length_aux'' .\n  have \"i \\<le> progress \\<sigma> P' (Formula.Until \\<phi>''' I \\<psi>'') (j + \\<delta>) \\<Longrightarrow>\n      wf_until_auxlist \\<sigma> V n R pos \\<phi>'' I \\<psi>'' auxlist' i \\<Longrightarrow>\n      i + length auxlist' = min (progress \\<sigma> P' \\<phi>''' (j + \\<delta>)) (progress \\<sigma> P' \\<psi>'' (j + \\<delta>)) \\<Longrightarrow>\n      wf_until_auxlist \\<sigma> V n R pos \\<phi>'' I \\<psi>'' auxlist'' (progress \\<sigma> P' (Formula.Until \\<phi>''' I \\<psi>'') (j + \\<delta>)) \\<and>\n        i + length zs'' = progress \\<sigma> P' (Formula.Until \\<phi>''' I \\<psi>'') (j + \\<delta>) \\<and>\n        i + length zs'' + length auxlist'' = min (progress \\<sigma> P' \\<phi>''' (j + \\<delta>)) (progress \\<sigma> P' \\<psi>'' (j + \\<delta>)) \\<and>\n        list_all2 (\\<lambda>i. qtable n (Formula.fv \\<psi>'') (mem_restr R)\n          (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (Untilp pos \\<phi>'' I \\<psi>'')))\n          [i..<i + length zs''] zs''\" for i\n    using eq2'\n  proof (induction auxlist' arbitrary: zs'' auxlist'' i)\n    case Nil\n    then show ?case\n      by (auto dest!: antisym[OF progress_Until_le])\n  next\n    case (Cons a aux')\n    obtain t a1 a2 where \"a = (t, a1, a2)\" by (cases a)\n    from Cons.prems(2) have aux': \"wf_until_auxlist \\<sigma> V n R pos \\<phi>'' I \\<psi>'' aux' (Suc i)\"\n      by (rule wf_until_aux_Cons)\n    from Cons.prems(2) have 1: \"t = \\<tau> \\<sigma> i\"\n      unfolding \\<open>a = (t, a1, a2)\\<close> by (rule wf_until_aux_Cons1)\n    from Cons.prems(2) have 3: \"qtable n (Formula.fv \\<psi>'') (mem_restr R) (\\<lambda>v.\n        (\\<exists>j\\<ge>i. j < Suc (i + length aux') \\<and> mem I ((\\<tau> \\<sigma> j - \\<tau> \\<sigma> i)) \\<and> Formula.sat \\<sigma> V (map the v) j \\<psi>'' \\<and>\n        (\\<forall>k\\<in>{i..<j}. if pos then Formula.sat \\<sigma> V (map the v) k \\<phi>'' else \\<not> Formula.sat \\<sigma> V (map the v) k \\<phi>''))) a2\"\n      unfolding \\<open>a = (t, a1, a2)\\<close> by (rule wf_until_aux_Cons3)\n    from Cons.prems(3) have Suc_i_aux': \"Suc i + length aux' =\n          min (progress \\<sigma> P' \\<phi>''' (j + \\<delta>)) (progress \\<sigma> P' \\<psi>'' (j + \\<delta>))\"\n      by simp\n    have \"i \\<ge> progress \\<sigma> P' (Formula.Until \\<phi>''' I \\<psi>'') (j + \\<delta>)\"\n      if \"memR I (nt - t)\"\n      using that nts' unfolding wf_ts_def progress.simps nt\n      by (auto simp add: 1 list_all2_Cons2 upt_eq_Cons_conv \\<phi>'''\n          intro!: cInf_lower \\<tau>_mono diff_le_mono simp del: upt_Suc split: if_splits list.splits)\n    moreover\n    have \"Suc i \\<le> progress \\<sigma> P' (Formula.Until \\<phi>''' I \\<psi>'') (j + \\<delta>)\"\n      if \"\\<not> memR I (nt - t)\"\n    proof -\n      have \\<tau>_min:  \"\\<tau> \\<sigma> (min (j + \\<delta> - 1) k) = min (\\<tau> \\<sigma> (j + \\<delta> - 1)) (\\<tau> \\<sigma> k)\" for k\n        by (simp add: min_of_mono monoI)\n      have le_progress_iff[simp]: \"j + \\<delta> \\<le> progress \\<sigma> P' \\<phi> (j + \\<delta>) \\<longleftrightarrow> progress \\<sigma> P' \\<phi> (j + \\<delta>) = (j + \\<delta>)\" for \\<phi>\n        using wf_envs_progress_le[OF wf_envs, of \\<phi>] by auto\n      let ?X = \"{i. \\<forall>k. k < j + \\<delta> \\<and> k \\<le> min (progress \\<sigma> P' \\<phi>''' (j + \\<delta>)) (progress \\<sigma> P' \\<psi>'' (j + \\<delta>)) \\<longrightarrow> memR I (\\<tau> \\<sigma> k - \\<tau> \\<sigma> i)}\"\n      let ?min = \"min (j + \\<delta> - 1) (min (progress \\<sigma> P' \\<phi>'' (j + \\<delta>)) (progress \\<sigma> P' \\<psi>'' (j + \\<delta>)))\"\n      have \"\\<tau> \\<sigma> ?min \\<le> \\<tau> \\<sigma> (j + \\<delta>)\"\n        by (rule \\<tau>_mono) auto\n      from that have \"?X \\<noteq> {}\"\n        by (auto simp: \\<phi>''' intro!: exI[of _ \"progress \\<sigma> P' \\<phi>'' (j + \\<delta>)\"])\n      show ?thesis\n        using that nts' Suc_i_aux' unfolding wf_ts_def progress.simps nt\n        by (intro cInf_greatest[OF \\<open>?X \\<noteq> {}\\<close>])\n          (auto 0 3 simp: 1 \\<phi>''' list_all2_Cons2 upt_eq_Cons_conv\n            simp del: upt_Suc split: list.splits if_splits\n            dest!: spec[of _ \"?min\"]\n            intro: diff_le_mono diff_le_mono2 order_trans[OF diff_le_mono diff_le_mono2] \\<tau>_mono\n            elim!: contrapos_np[of _ \"Suc i \\<le> _\"])\n    qed\n    moreover have *: \"k < progress \\<sigma> P' \\<psi> (j + \\<delta>)\" if\n      \"\\<not> memR I (nt - \\<tau> \\<sigma> i)\"\n      \"memR I (\\<tau> \\<sigma> k - \\<tau> \\<sigma> i)\" \"\\<psi> = \\<psi>'' \\<or> \\<psi> = \\<phi>''\" for k \\<psi>\n      using that nts' unfolding wf_ts_def nt\n      by (auto simp: list_all2_Cons2 upt_eq_Cons_conv\n          simp del: upt_Suc split: list.splits if_splits\n          elim!: contrapos_np[of _ \"k < _\"] intro!: diff_le_mono diff_le_mono2)\n    ultimately show ?case using Cons.prems Suc_i_aux'[simplified]\n      unfolding \\<open>a = (t, a1, a2)\\<close>\n      by (auto simp: \\<phi>''' 1 sat.simps upt_conv_Cons Untilp_def dest!: Cons.IH[OF _ aux' Suc_i_aux']\n          simp del: upt_Suc split: if_splits prod.splits intro!: iff_exI qtable_cong[OF 3 refl])\n  qed\n  note wf_aux'' = this[OF wf_envs_progress_mono[OF wf_envs le_add1]\n      wf_auxlist' conjunct2[OF update1, unfolded ne_def length_aux']]\n  have zs_def: \"zs = map (eval_args_agg args) zs''\"\n    using valid_eval_muaux[OF valid_aux' current_w_le eq2, of zs'' auxlist'']\n    unfolding eval_args_agg_def\n    by (auto simp add: args_ivl zs''_def auxlist''_def split: option.splits)\n  have len_zs'': \"length zs'' = length zs\"\n    by (auto simp: zs_def)\n  have fv: \"fv (Untilp pos \\<phi>'' I \\<psi>'') = fv \\<psi>''\"\n    using fvi_sub\n    by (auto simp: Untilp_def)\n  have \"list_all2 (\\<lambda>i. qtable n (fv \\<psi>'') (mem_restr R)\n      (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (Untilp pos \\<phi>'' I \\<psi>'')))\n      [Monitor.progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j..<\n       Monitor.progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (j + \\<delta>)] zs''\"\n    using wf_aux''\n    by auto\n  then have list_all2_zs: \"list_all2 (\\<lambda>i. qtable (agg_n args) (fv (packagg args (Untilp pos \\<phi>'' I \\<psi>''))) (mem_restr R')\n      (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (packagg args (Untilp pos \\<phi>'' I \\<psi>''))))\n      [Monitor.progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j..<\n       Monitor.progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (j + \\<delta>)] zs\"\n    unfolding zs_def list_all2_map2\n    apply (rule list_all2_mono)\n    apply (rule qtable_eval_args_agg[of _ _ R])\n    apply (auto simp: mr args_n fv valid_aggargs)\n    done\n  have \"progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j + length auxlist' =\n      progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (j + \\<delta>) + length auxlist''\"\n    using wf_aux'' valid_aux'' length_aux'_aux''\n    by (auto simp add: ne_def length_aux' length_aux'')\n  then have \"cur =\n      (if progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (j + \\<delta>) + length auxlist'' = 0 then 0\n      else \\<tau> \\<sigma> (progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (j + \\<delta>) + length auxlist'' - 1))\"\n    unfolding cur ne_def by auto\n  then show \"wf_until_aux \\<sigma> V R args \\<phi>'' \\<psi>'' aux'' (progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (j + \\<delta>)) \\<and>\n      progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j + length zs = progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (j + \\<delta>) \\<and>\n      progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j + length zs + length_muaux args aux'' = min (progress \\<sigma> P' \\<phi>''' (j + \\<delta>)) (progress \\<sigma> P' \\<psi>'' (j + \\<delta>)) \\<and>\n      list_all2 (\\<lambda>i. qtable (agg_n args) (fv (packagg args (Untilp pos \\<phi>'' I \\<psi>''))) (mem_restr R') (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (packagg args (Untilp pos \\<phi>'' I \\<psi>''))))\n      [progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j..<progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j + length zs] zs \\<and>\n      nt = (if j + \\<delta> = 0 then 0 else \\<tau> \\<sigma> (min (j + \\<delta> - 1) (min (progress \\<sigma> P' \\<phi>'' (j + \\<delta>)) (progress \\<sigma> P' \\<psi>'' (j + \\<delta>)))))\"\n    using aux wf_aux'' valid_aux'' fvi_sub list_all2_zs\n    unfolding wf_until_aux_def length_aux'' args_ivl args_n args_pos nt len_zs''\n    by (auto simp only: length_aux'')\nqed\n\nlemma progress_packagg[simp]: \"Monitor.progress \\<sigma> P (packagg args \\<phi>) j = Monitor.progress \\<sigma> P \\<phi> j\"\n  by (auto simp: packagg_def split: option.splits)\n\nlemma (in maux) meval:\n  assumes \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>'\" \"wf_envs \\<sigma> j \\<delta> P P' V db\"\n  shows \"case meval n (map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) db \\<phi> of (xs, \\<phi>\\<^sub>n) \\<Rightarrow> wf_mformula \\<sigma> (j + \\<delta>) P' V n R \\<phi>\\<^sub>n \\<phi>' \\<and>\n    list_all2 (\\<lambda>i. qtable n (Formula.fv \\<phi>') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>'))\n    [progress \\<sigma> P \\<phi>' j..<progress \\<sigma> P' \\<phi>' (j + \\<delta>)] xs\"\n  using assms\nproof (induction \\<phi> arbitrary: db P P' V n R \\<phi>')\n  case (MRel rel)\n  then show ?case\n    by (cases rule: wf_mformula.cases)\n      (auto simp add: ball_Un intro: wf_mformula.intros table_eq_rel eq_rel_eval_trm\n        in_eq_rel qtable_empty qtable_unit_table intro!: qtableI)\nnext\n  case (MPred e ts)\n  then show ?case\n  proof (cases \"e \\<in> dom P\")\n    case True\n    with MPred(2) have \"e \\<in> Mapping.keys db\" \"e \\<in> dom P'\" \"e \\<in> dom V\"\n      \"list_all2 (\\<lambda>i X. X = the (V e) i) [the (P e)..<the (P' e)]\n         (the (Mapping.lookup db e))\" unfolding wf_envs_def rel_mapping_alt by blast+\n    with MPred(1) True show ?thesis\n      by (cases rule: wf_mformula.cases)\n        (fastforce intro!: wf_mformula.Pred qtableI bexI[where P=\"\\<lambda>x. _ = tabulate x 0 n\", OF refl]\n        elim!: list.rel_mono_strong bexI[rotated] dest: ex_match\n        simp: list.rel_map table_def match_wf_tuple in_these_eq match_eval_trm image_iff\n          list.map_comp keys_dom_lookup)\n  next\n    note MPred(1)\n    moreover\n    case False\n    moreover\n    from False MPred(2) have \"e \\<notin> dom P'\" \"e \\<notin> dom V\"\n      unfolding wf_envs_def rel_mapping_alt by auto\n    moreover\n    from False MPred(2) have *: \"e \\<in> (\\<Union>k \\<in> {j ..< j + \\<delta>}. fst ` \\<Gamma> \\<sigma> k) \\<longleftrightarrow> e \\<in> Mapping.keys db\"\n      unfolding wf_envs_def by auto\n    from False MPred(2) have\n      \"e \\<in> Mapping.keys db \\<Longrightarrow> Mapping.lookup db e = Some (map (\\<lambda>k. {ts. (e, ts) \\<in> \\<Gamma> \\<sigma> k}) [j ..< j + \\<delta>])\"\n      unfolding wf_envs_def keys_dom_lookup by (metis Diff_iff domD option.sel)\n    with * have \"(case Mapping.lookup db e of None \\<Rightarrow> replicate \\<delta> {} | Some xs \\<Rightarrow> xs) =\n      map (\\<lambda>k. {ts. (e, ts) \\<in> \\<Gamma> \\<sigma> k}) [j ..< j + \\<delta>]\"\n      by (cases \"e \\<in> (\\<Union>k \\<in> {j ..< j + \\<delta>}. fst ` \\<Gamma> \\<sigma> k)\")\n        (auto 0 3 simp: image_iff keys_dom_lookup list.rel_eq[symmetric] list.rel_map\n         intro: list.rel_refl split: option.splits)\n    ultimately show ?thesis\n      by (cases rule: wf_mformula.cases)\n        (fastforce intro!: wf_mformula.Pred qtableI list.rel_refl dest: ex_match cong: option.case\n          simp: list.rel_map table_def match_wf_tuple in_these_eq match_eval_trm image_iff)\n  qed\nnext\n  case (MLet p m \\<phi>1 \\<phi>2)\n  from MLet.prems(1) obtain \\<phi>1' \\<phi>2' where Let: \"\\<phi>' = Formula.Let p \\<phi>1' \\<phi>2'\" and\n    1: \"wf_mformula \\<sigma> j P V m UNIV \\<phi>1 \\<phi>1'\" and\n    fv: \"m = Formula.nfv \\<phi>1'\" \"{0..<m} \\<subseteq> fv \\<phi>1'\" and\n    2: \"wf_mformula \\<sigma> j (P(p \\<mapsto> progress \\<sigma> P \\<phi>1' j))\n      (V(p \\<mapsto> \\<lambda>i. {v. length v = m \\<and> Formula.sat \\<sigma> V v i \\<phi>1'}))\n      n R \\<phi>2 \\<phi>2'\"\n    by (cases rule: wf_mformula.cases) auto\n  obtain xs \\<phi>1_new where e1: \"meval m (map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) db \\<phi>1 = (xs, \\<phi>1_new)\" and\n      wf1: \"wf_mformula \\<sigma> (j + \\<delta>) P' V m UNIV \\<phi>1_new \\<phi>1'\" and\n      res1: \"list_all2 (\\<lambda>i. qtable m (fv \\<phi>1') (mem_restr UNIV) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>1'))\n       [progress \\<sigma> P \\<phi>1' j..<progress \\<sigma> P' \\<phi>1' (j + \\<delta>)] xs\"\n    using MLet(1)[OF 1(1) MLet.prems(2)] by (auto simp: eqTrueI[OF mem_restr_UNIV, abs_def])\n  from MLet(2)[OF 2 wf_envs_update[OF MLet.prems(2) fv res1]] wf1 e1 fv\n  show ?case unfolding Let\n    by (auto simp: fun_upd_def intro!: wf_mformula.Let)\nnext\n  case (MAnd A_\\<phi> \\<phi> pos A_\\<psi> \\<psi> buf)\n  from MAnd.prems show ?case\n    by (cases rule: wf_mformula.cases)\n      (auto simp: sat_the_restrict simp del: bin_join.simps\n        dest!: MAnd.IH split: if_splits prod.splits intro!: wf_mformula.And qtable_bin_join\n        elim: mbuf2_take_add'(1) list.rel_mono_strong[OF mbuf2_take_add'(2)])\nnext\n  case (MAndAssign \\<phi> conf)\n  from MAndAssign.prems obtain \\<phi>'' x t \\<psi>'' where\n    wf_envs: \"wf_envs \\<sigma> j \\<delta> P P' V db\" and\n    \\<phi>'_eq: \"\\<phi>' = formula.And \\<phi>'' \\<psi>''\" and\n    wf_\\<phi>: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>''\" and\n    \"x < n\" and\n    \"x \\<notin> fv \\<phi>''\" and\n    fv_t_subset: \"fv_trm t \\<subseteq> fv \\<phi>''\" and\n    conf: \"(x, t) = conf\" and\n    \\<psi>''_eqs: \"\\<psi>'' = formula.Eq (trm.Var x) t \\<or> \\<psi>'' = formula.Eq t (trm.Var x)\"\n    by (cases rule: wf_mformula.cases)\n  from wf_\\<phi> wf_envs obtain xs \\<phi>\\<^sub>n where\n    meval_eq: \"meval n (map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) db \\<phi> = (xs, \\<phi>\\<^sub>n)\" and\n    wf_\\<phi>\\<^sub>n: \"wf_mformula \\<sigma> (j + \\<delta>) P' V n R \\<phi>\\<^sub>n \\<phi>''\" and\n    xs: \"list_all2 (\\<lambda>i. qtable n (fv \\<phi>'') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>''))\n        [progress \\<sigma> P \\<phi>'' j..<progress \\<sigma> P' \\<phi>'' (j + \\<delta>)] xs\"\n    by (auto dest!: MAndAssign.IH)\n  have progress_eqs:\n      \"progress \\<sigma> P \\<phi>' j = progress \\<sigma> P \\<phi>'' j\"\n      \"progress \\<sigma> P' \\<phi>' (j + \\<delta>) = progress \\<sigma> P' \\<phi>'' (j + \\<delta>)\"\n    using \\<psi>''_eqs wf_envs_progress_le[OF wf_envs] by (auto simp: \\<phi>'_eq)\n\n  show ?case proof (simp add: meval_eq, intro conjI)\n    show \"wf_mformula \\<sigma> (j + \\<delta>) P' V n R (MAndAssign \\<phi>\\<^sub>n conf) \\<phi>'\"\n      unfolding \\<phi>'_eq\n      by (rule wf_mformula.AndAssign) fact+\n  next\n    show \"list_all2 (\\<lambda>i. qtable n (fv \\<phi>') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>'))\n        [progress \\<sigma> P \\<phi>' j..<progress \\<sigma> P' \\<phi>' (j + \\<delta>)] (map ((`) (eval_assignment conf)) xs)\"\n      unfolding list.rel_map progress_eqs conf[symmetric] eval_assignment.simps\n      using xs\n    proof (rule list.rel_mono_strong)\n      fix i X\n      assume qtable: \"qtable n (fv \\<phi>'') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>'') X\"\n      then show \"qtable n (fv \\<phi>') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>')\n          ((\\<lambda>y. y[x := Some (meval_trm t y)]) ` X)\"\n      proof (rule qtable_assign)\n        show \"x < n\" by fact\n        show \"insert x (fv \\<phi>'') = fv \\<phi>'\"\n          using \\<psi>''_eqs fv_t_subset by (auto simp: \\<phi>'_eq)\n        show \"x \\<notin> fv \\<phi>''\" by fact\n      next\n        fix v\n        assume wf_v: \"wf_tuple n (fv \\<phi>') v\" and \"mem_restr R v\"\n        then show \"mem_restr R (restrict (fv \\<phi>'') v)\" by simp\n\n        assume sat: \"Formula.sat \\<sigma> V (map the v) i \\<phi>'\"\n        then have A: \"Formula.sat \\<sigma> V (map the (restrict (fv \\<phi>'') v)) i \\<phi>''\" (is ?A)\n          by (simp add: \\<phi>'_eq sat_the_restrict)\n        have \"map the v ! x = Formula.eval_trm (map the v) t\"\n          using sat \\<psi>''_eqs by (auto simp: \\<phi>'_eq)\n        also have \"... = Formula.eval_trm (map the (restrict (fv \\<phi>'') v)) t\"\n          using fv_t_subset by (auto simp: map_the_restrict intro!: eval_trm_fv_cong)\n        finally have \"map the v ! x = meval_trm t (restrict (fv \\<phi>'') v)\"\n          using meval_trm_eval_trm[of n \"fv \\<phi>''\" \"restrict (fv \\<phi>'') v\" t]\n            fv_t_subset wf_v wf_mformula_wf_set[unfolded wf_set_def, OF wf_\\<phi>]\n          by (fastforce simp: \\<phi>'_eq intro!: wf_tuple_restrict)\n        then have B: \"v ! x = Some (meval_trm t (restrict (fv \\<phi>'') v))\" (is ?B)\n          using \\<psi>''_eqs wf_v \\<open>x < n\\<close> by (auto simp: wf_tuple_def \\<phi>'_eq)\n        from A B show \"?A \\<and> ?B\" ..\n      next\n        fix v\n        assume wf_v: \"wf_tuple n (fv \\<phi>'') v\" and \"mem_restr R v\"\n          and sat: \"Formula.sat \\<sigma> V (map the v) i \\<phi>''\"\n        let ?v = \"v[x := Some (meval_trm t v)]\"\n        from sat have A: \"Formula.sat \\<sigma> V (map the ?v) i \\<phi>''\"\n          using \\<open>x \\<notin> fv \\<phi>''\\<close> by (simp add: sat_the_update)\n        have \"y \\<in> fv_trm t \\<Longrightarrow> x \\<noteq> y\" for y\n          using fv_t_subset \\<open>x \\<notin> fv \\<phi>''\\<close> by auto\n        then have B: \"Formula.sat \\<sigma> V (map the ?v) i \\<psi>''\"\n          using \\<psi>''_eqs meval_trm_eval_trm[of n \"fv \\<phi>''\" v t] \\<open>x < n\\<close>\n            fv_t_subset wf_v wf_mformula_wf_set[unfolded wf_set_def, OF wf_\\<phi>]\n          by (auto simp: wf_tuple_def map_update intro!: eval_trm_fv_cong)\n        from A B show \"Formula.sat \\<sigma> V (map the ?v) i \\<phi>'\"\n          by (simp add: \\<phi>'_eq)\n      qed\n    qed\n  qed\nnext\n  case (MAndRel \\<phi> conf)\n  from MAndRel.prems show ?case\n    by (cases rule: wf_mformula.cases)\n       (auto simp: progress_constraint progress_le list.rel_map fv_formula_of_constraint\n        Un_absorb2 wf_mformula_wf_set[unfolded wf_set_def] split: prod.splits\n        dest!: MAndRel.IH[where db2=db and P2=P and P'2=P'] eval_constraint_sat_eq[THEN iffD2]\n        intro!: wf_mformula.AndRel\n        elim!: list.rel_mono_strong qtable_filter eval_constraint_sat_eq[THEN iffD1])\nnext\n  case (MAnds A_pos A_neg l buf)\n  note mbufn_take.simps[simp del] mbufn_add.simps[simp del] mmulti_join.simps[simp del]\n\n  from MAnds.prems obtain pos neg l' where\n    wf_l: \"list_all2 (wf_mformula \\<sigma> j P V n R) l (pos @ map remove_neg neg)\" and\n    wf_buf: \"wf_mbufn (progress \\<sigma> P (formula.Ands l') j) (map (\\<lambda>\\<psi>. progress \\<sigma> P \\<psi> j) (pos @ map remove_neg neg))\n      (map (\\<lambda>\\<psi> i. qtable n (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>)) (pos @ map remove_neg neg)) buf\" and\n    posneg: \"(pos, neg) = partition safe_formula l'\" and\n    \"pos \\<noteq> []\" and\n    safe_neg: \"list_all safe_formula (map remove_neg neg)\" and\n    A_eq: \"A_pos = map fv pos\" \"A_neg = map fv neg\" and\n    fv_subset: \"\\<Union> (set A_neg) \\<subseteq> \\<Union> (set A_pos)\" and\n    \"\\<phi>' = Formula.Ands l'\"\n    by (cases rule: wf_mformula.cases) simp\n  have progress_eq: \"progress \\<sigma> P' (formula.Ands l') (j + \\<delta>) =\n      Mini (progress \\<sigma> P (formula.Ands l') j) (map (\\<lambda>\\<psi>. progress \\<sigma> P' \\<psi> (j + \\<delta>)) (pos @ map remove_neg neg))\"\n    using \\<open>pos \\<noteq> []\\<close> posneg\n    by (auto simp: Mini_def image_Un[symmetric] Collect_disj_eq[symmetric] intro!: arg_cong[where f=Min])\n\n  have join_ok: \"qtable n (\\<Union> (fv ` set l')) (mem_restr R)\n        (\\<lambda>v. list_all (Formula.sat \\<sigma> V (map the v) k) l')\n        (mmulti_join n A_pos A_neg L)\"\n    if args_ok: \"list_all2 (\\<lambda>x. qtable n (fv x) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) k x))\n        (pos @ map remove_neg neg) L\"\n    for k L\n  proof (rule qtable_mmulti_join)\n    let ?ok = \"\\<lambda>A Qi X. qtable n A (mem_restr R) Qi X \\<and> wf_set n A\"\n    let ?L_pos = \"take (length A_pos) L\"\n    let ?L_neg = \"drop (length A_pos) L\"\n    have 1: \"length pos \\<le> length L\"\n      using args_ok by (auto dest!: list_all2_lengthD)\n    show \"list_all3 ?ok A_pos (map (\\<lambda>\\<psi> v. Formula.sat \\<sigma> V (map the v) k \\<psi>) pos) ?L_pos\"\n      using args_ok wf_l unfolding A_eq\n      by (auto simp add: list_all3_conv_all_nth list_all2_conv_all_nth nth_append\n          split: if_splits intro!: wf_mformula_wf_set[of \\<sigma> j P V n R]\n          dest: order.strict_trans2[OF _ 1])\n    from args_ok have prems_neg: \"list_all2 (\\<lambda>\\<psi>. qtable n (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) k (remove_neg \\<psi>))) neg ?L_neg\"\n      by (auto simp: A_eq list_all2_append1 list.rel_map)\n    show \"list_all3 ?ok A_neg (map (\\<lambda>\\<psi> v. Formula.sat \\<sigma> V (map the v) k (remove_neg \\<psi>)) neg) ?L_neg\"\n      using prems_neg wf_l unfolding A_eq\n      by (auto simp add: list_all3_conv_all_nth list_all2_conv_all_nth list_all_length nth_append less_diff_conv\n          split: if_splits intro!: wf_mformula_wf_set[of \\<sigma> j P V n R _ \"remove_neg _\", simplified])\n    show \"\\<Union>(fv ` set l') = \\<Union>(set A_pos)\"\n      using fv_subset posneg unfolding A_eq by auto\n    show \"L = take (length A_pos) L @ drop (length A_pos) L\" by simp\n    show \"A_pos \\<noteq> []\" using \\<open>pos \\<noteq> []\\<close> A_eq by simp\n\n    fix x :: \"event_data tuple\"\n    assume \"wf_tuple n (\\<Union> (fv ` set l')) x\" and \"mem_restr R x\"\n    then show \"list_all (\\<lambda>A. mem_restr R (restrict A x)) A_pos\"\n      and \"list_all (\\<lambda>A. mem_restr R (restrict A x)) A_neg\"\n      by (simp_all add: list.pred_set)\n\n    have \"list_all Formula.is_Neg neg\"\n      using posneg safe_neg\n      by (auto 0 3 simp add: list.pred_map elim!: list.pred_mono_strong\n          intro: formula.exhaust[of \\<psi> \"Formula.is_Neg \\<psi>\" for \\<psi>])\n    then have \"list_all (\\<lambda>\\<psi>. Formula.sat \\<sigma> V (map the v) i (remove_neg \\<psi>) \\<longleftrightarrow>\n      \\<not> Formula.sat \\<sigma> V (map the v) i \\<psi>) neg\" for v i\n      by (fastforce simp: Formula.is_Neg_def elim!: list.pred_mono_strong)\n    then show \"list_all (Formula.sat \\<sigma> V (map the x) k) l' =\n       (list_all2 (\\<lambda>A Qi. Qi (restrict A x)) A_pos\n         (map (\\<lambda>\\<psi> v. Formula.sat \\<sigma> V (map the v) k \\<psi>) pos) \\<and>\n        list_all2 (\\<lambda>A Qi. \\<not> Qi (restrict A x)) A_neg\n         (map (\\<lambda>\\<psi> v. Formula.sat \\<sigma> V (map the v) k\n                       (remove_neg \\<psi>))\n           neg))\"\n      using posneg\n      by (auto simp add: A_eq list_all2_conv_all_nth list_all_length sat_the_restrict\n          elim: nth_filter nth_partition[where P=safe_formula and Q=\"Formula.sat _ _ _ _\"])\n  qed fact\n\n  from MAnds.prems(2) show ?case\n    unfolding \\<open>\\<phi>' = Formula.Ands l'\\<close>\n    by (auto 0 3 simp add: list.rel_map progress_eq map2_map_map list_all3_map\n        list_all3_list_all2_conv list.pred_map\n        simp del: set_append map_append progress_simps split: prod.splits\n        intro!: wf_mformula.Ands[OF _ _ posneg \\<open>pos \\<noteq> []\\<close> safe_neg A_eq fv_subset]\n        list.rel_mono_strong[OF wf_l] wf_mbufn_add[OF wf_buf]\n        list.rel_flip[THEN iffD1, OF list.rel_mono_strong, OF wf_l]\n        list.rel_refl join_ok[unfolded list.pred_set]\n        dest!: MAnds.IH[OF _ _ MAnds.prems(2), rotated]\n        elim!: wf_mbufn_take list_all2_appendI\n        elim: mbufn_take_induct[OF _ wf_mbufn_add[OF wf_buf]])\nnext\n  case (MOr \\<phi> \\<psi> buf)\n  from MOr.prems show ?case\n    by (cases rule: wf_mformula.cases)\n      (auto dest!: MOr.IH split: if_splits prod.splits intro!: wf_mformula.Or qtable_union\n        elim: mbuf2_take_add'(1) list.rel_mono_strong[OF mbuf2_take_add'(2)])\nnext\n  case (MNeg \\<phi>)\n  have *: \"qtable n {} (mem_restr R) (\\<lambda>v. P v) X \\<Longrightarrow>\n    \\<not> qtable n {} (mem_restr R) (\\<lambda>v. \\<not> P v) empty_table \\<Longrightarrow> x \\<in> X \\<Longrightarrow> False\" for P x X\n    using nullary_qtable_cases qtable_unit_empty_table by fastforce\n  from MNeg.prems show ?case\n    by (cases rule: wf_mformula.cases)\n      (auto 0 4 intro!: wf_mformula.Neg dest!: MNeg.IH\n        simp add: list.rel_map\n        dest: nullary_qtable_cases qtable_unit_empty_table intro!: qtable_empty_unit_table\n        elim!: list.rel_mono_strong elim: *)\nnext\n  case (MExists \\<phi>)\n  from MExists.prems show ?case\n    by (cases rule: wf_mformula.cases)\n      (force simp: list.rel_map fvi_Suc sat_fv_cong nth_Cons'\n        intro!: wf_mformula.Exists dest!: MExists.IH qtable_project_fv\n        elim!: list.rel_mono_strong table_fvi_tl qtable_cong sat_fv_cong[THEN iffD1, rotated -1]\n        split: if_splits)+\nnext\n  case (MAgg g0 y \\<omega> b f \\<phi>)\n  from MAgg.prems show ?case\n    using wf_mformula_wf_set[OF MAgg.prems(1), unfolded wf_set_def]\n    by (cases rule: wf_mformula.cases)\n      (auto 0 3 simp add: list.rel_map simp del: sat.simps fvi.simps split: prod.split\n        intro!: wf_mformula.Agg qtable_eval_agg dest!: MAgg.IH elim!: list.rel_mono_strong)\nnext\n  case (MPrev I \\<phi> first buf nts)\n  from MPrev.prems show ?case\n  proof (cases rule: wf_mformula.cases)\n    case (Prev \\<psi>)\n    let ?xs = \"fst (meval n (map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) db \\<phi>)\"\n    let ?\\<phi> = \"snd (meval n (map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) db \\<phi>)\"\n    let ?ls = \"fst (mprev_next I (buf @ ?xs) (nts @ map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]))\"\n    let ?rs = \"fst (snd (mprev_next I (buf @ ?xs) (nts @ map (\\<tau> \\<sigma>) [j ..< j + \\<delta>])))\"\n    let ?ts = \"snd (snd (mprev_next I (buf @ ?xs) (nts @ map (\\<tau> \\<sigma>) [j ..< j + \\<delta>])))\"\n    let ?P = \"\\<lambda>i X. qtable n (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>) X\"\n    let ?i = \"min (progress \\<sigma> P \\<psi> j) (j - 1)\"\n    let ?j = \"j + \\<delta>\"\n    let ?j' = \"progress \\<sigma> P' \\<psi> (j + \\<delta>)\"\n    define mini where \"mini = min ?j' (if ?i = ?j then ?j else ?j - 1)\"\n    from Prev MPrev.IH[OF _ MPrev.prems(2), of n R \\<psi>] have IH: \"wf_mformula \\<sigma> (j + \\<delta>) P' V n R ?\\<phi> \\<psi>\" and\n      \"list_all2 ?P [progress \\<sigma> P \\<psi> j..<progress \\<sigma> P' \\<psi> (j + \\<delta>)] ?xs\" by auto\n    with Prev(4,5) MPrev.prems(2) have\n      \"list_all2 (\\<lambda>i X. if mem I ((\\<tau> \\<sigma> (Suc i) - \\<tau> \\<sigma> i)) then ?P i X else X = empty_table) [?i..<mini] ?ls \\<and>\n       list_all2 ?P [mini..<?j'] ?rs \\<and> list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [mini..< ?j] ?ts\"\n      unfolding mini_def\n      by (intro mprev) (auto intro!: list_all2_upt_append list_all2_appendI order.trans[OF min.cobounded1]\n        list.rel_refl simp: list.rel_map)\n    moreover have \"min (Suc (progress \\<sigma> P \\<psi> j)) j = Suc (min (progress \\<sigma> P \\<psi> j) (j-1))\" if \"j > 0\" for P j\n      using that by auto\n    ultimately show ?thesis using Prev(1,3) MPrev.prems(2) IH\n      upt_conv_Cons[OF zero_less_Suc, of \"min (Monitor.progress \\<sigma> P' \\<psi> \\<delta>) (\\<delta> - Suc 0)\"]\n      by (auto 0 3 simp: map_Suc_upt[symmetric] list.rel_map qtable_empty_iff mini_def\n          simp del: upt_Suc elim!: wf_mformula.Prev list.rel_mono_strong dest: wf_envs_progress_le\n          split: prod.split if_split_asm) (* slow 25 sec*)\n  qed\nnext\n  case (MNext I \\<phi> first nts)\n  from MNext.prems show ?case\n  proof (cases rule: wf_mformula.cases)\n    case (Next \\<psi>)\n\n    have min[simp]:\n      \"min (progress \\<sigma> P \\<psi> j - Suc 0) (j - Suc 0) = progress \\<sigma> P \\<psi> j - Suc 0\"\n      \"min (progress \\<sigma> P' \\<psi> (j + \\<delta>) - Suc 0) (j + \\<delta> - Suc 0) = progress \\<sigma> P' \\<psi> (j + \\<delta>) - Suc 0\"\n      using wf_envs_progress_le[OF MNext.prems(2), of \\<psi>] by auto\n\n    let ?xs = \"fst (meval n (map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) db \\<phi>)\"\n    let ?ys = \"case (?xs, first) of (_ # xs, True) \\<Rightarrow> xs | _ \\<Rightarrow> ?xs\"\n    let ?\\<phi> = \"snd (meval n (map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) db \\<phi>)\"\n    let ?ls = \"fst (mprev_next I ?ys (nts @ map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]))\"\n    let ?rs = \"fst (snd (mprev_next I ?ys (nts @ map (\\<tau> \\<sigma>) [j ..< j + \\<delta>])))\"\n    let ?ts = \"snd (snd (mprev_next I ?ys (nts @ map (\\<tau> \\<sigma>) [j ..< j + \\<delta>])))\"\n    let ?P = \"\\<lambda>i X. qtable n (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>) X\"\n    let ?i = \"progress \\<sigma> P \\<psi> j - 1\"\n    let ?j = \"j + \\<delta>\"\n    let ?j' = \"progress \\<sigma> P' \\<psi> (j + \\<delta>)\"\n    define mini where \"mini = min (?j' - 1) (if ?i = ?j then ?j else ?j - 1)\"\n\n    from Next MNext.IH[OF _ MNext.prems(2), of n R \\<psi>] have IH: \"wf_mformula \\<sigma> (j + \\<delta>) P' V  n R ?\\<phi> \\<psi>\"\n      \"list_all2 ?P [progress \\<sigma> P \\<psi> j..<progress \\<sigma> P' \\<psi> (j + \\<delta>)] ?xs\" by auto\n    with Next have \"list_all2 (\\<lambda>i X. if mem I ((\\<tau> \\<sigma> (Suc i) - \\<tau> \\<sigma> i)) then ?P (Suc i) X else X = empty_table)\n         [?i..<mini] ?ls \\<and>\n       list_all2 ?P [Suc mini..<?j'] ?rs \\<and> list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [mini..<?j] ?ts\"\n       if \"progress \\<sigma> P \\<psi> j < progress \\<sigma> P' \\<psi> (j + \\<delta>)\"\n      using that wf_envs_progress_le[OF MNext.prems(2), of \\<psi>] unfolding mini_def\n      by (intro mnext)\n        (auto simp: list_all2_Cons2 upt_eq_Cons_conv list.rel_map\n          intro!: list_all2_upt_append list_all2_appendI list.rel_refl split: list.splits)\n    then show ?thesis using wf_envs_progress_le[OF MNext.prems(2), of \\<psi>]\n      upt_add_eq_append[of 0 j \\<delta>] upt_add_eq_append[of \"?j' - 1\" j \\<delta>]\n      wf_envs_progress_mono[OF MNext.prems(2), of j \"j + \\<delta>\" \\<psi>, simplified] Next IH\n      by (cases \"progress \\<sigma> P' \\<psi> (j + \\<delta>) > progress \\<sigma> P \\<psi> j\")\n        (auto 0 3 simp: qtable_empty_iff le_Suc_eq le_diff_conv mini_def list.rel_map\n          elim!: wf_mformula.Next list.rel_mono_strong list_all2_appendI intro!: list.rel_refl\n          split: prod.split list.splits if_split_asm)  (* slow 15 sec*)\n  qed\nnext\n  case (MSince args \\<phi> \\<psi> buf nts aux db P P' V n' R' \\<phi>')\n  note sat.simps[simp del]\n  from MSince.prems obtain \\<phi>'' \\<phi>''' \\<psi>'' I n R where Since_eq: \"\\<phi>' = packagg args (Formula.Since \\<phi>''' I \\<psi>'')\"\n    and pos: \"if args_pos args then \\<phi>''' = \\<phi>'' else \\<phi>''' = Formula.Neg \\<phi>''\"\n    and pos_eq: \"safe_formula \\<phi>''' = args_pos args\"\n    and \\<phi>: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>''\"\n    and \\<psi>: \"wf_mformula \\<sigma> j P V n R \\<psi> \\<psi>''\"\n    and fvi_subset: \"Formula.fv \\<phi>'' \\<subseteq> Formula.fv \\<psi>''\"\n    and buf: \"wf_mbuf2' \\<sigma> P V j n R \\<phi>'' \\<psi>'' buf\"\n    and nts: \"wf_ts \\<sigma> P j \\<phi>'' \\<psi>'' nts\"\n    and aux: \"wf_since_aux \\<sigma> V R args \\<phi>'' \\<psi>'' aux (progress \\<sigma> P (Formula.Since \\<phi>''' I \\<psi>'') j)\"\n    and args_ivl: \"args_ivl args = I\"\n    and args_n: \"args_n args = n\"\n    and args_L: \"args_L args = Formula.fv \\<phi>''\"\n    and args_R: \"args_R args = Formula.fv \\<psi>''\"\n    and mr: \"mem_restr R = mem_restr (lift_envs' (agg_b args) R')\"\n    and agg_n: \"agg_n args = n'\"\n    by (cases rule: wf_mformula.cases) auto\n  have \\<phi>''': \"Formula.fv \\<phi>''' = Formula.fv \\<phi>''\" \"progress \\<sigma> P \\<phi>''' j = progress \\<sigma> P \\<phi>'' j\"\n    \"progress \\<sigma> P' \\<phi>''' j = progress \\<sigma> P' \\<phi>'' j\" for j\n    using pos by (simp_all split: if_splits)\n  from MSince.prems(2) have nts_snoc: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i)\n    [min (progress \\<sigma> P \\<phi>'' j) (progress \\<sigma> P \\<psi>'' j)..< j + \\<delta>] (nts @ map (\\<tau> \\<sigma>) [j ..< j + \\<delta>])\"\n    using nts unfolding wf_ts_def\n    by (subst upt_add_eq_append) (auto simp add: wf_envs_progress_le[THEN min.coboundedI1] list.rel_map\n      intro!: list_all2_appendI list.rel_refl)\n  note upd_since = update_since[OF _ _ _ _ _ args_ivl args_n args_L args_R refl mr]\n  have update: \"wf_since_aux \\<sigma> V R args \\<phi>'' \\<psi>'' (snd (zs, aux')) (progress \\<sigma> P' (Formula.Since \\<phi>''' I \\<psi>'') (j + \\<delta>)) \\<and>\n    list_all2 (\\<lambda>i. qtable (agg_n args) (Formula.fv (packagg args (Formula.Since \\<phi>''' I \\<psi>''))) (mem_restr R')\n      (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (packagg args (Formula.Since \\<phi>''' I \\<psi>''))))\n      [progress \\<sigma> P (Formula.Since \\<phi>''' I \\<psi>'') j..<progress \\<sigma> P' (Formula.Since \\<phi>''' I \\<psi>'') (j + \\<delta>)] (fst (zs, aux'))\"\n    if eval_\\<phi>: \"fst (meval n (map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) db \\<phi>) = xs\"\n      and eval_\\<psi>: \"fst (meval n (map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) db \\<psi>) = ys\"\n      and eq: \"mbuf2t_take (\\<lambda>r1 r2 t (zs, aux).\n        case update_since args r1 r2 t aux of (z, x) \\<Rightarrow> (zs @ [z], x))\n        ([], aux) (mbuf2_add xs ys buf) (nts @ map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) = ((zs, aux'), buf', nts')\"\n    for xs ys zs aux' buf' nts'\n    unfolding progress_simps \\<phi>'''\n  proof (rule mbuf2t_take_add_induct'[where j=j and j'=\"j + \\<delta>\" and z'=\"(zs, aux')\",\n      OF eq wf_envs_P_simps[OF MSince.prems(2)] buf nts_snoc],\n      goal_cases xs ys _ base step)\n    case xs\n    then show ?case\n      using MSince.IH(1)[OF \\<phi> MSince.prems(2)] eval_\\<phi> by auto\n  next\n    case ys\n    then show ?case\n      using MSince.IH(2)[OF \\<psi> MSince.prems(2)] eval_\\<psi> by auto\n  next\n    case base\n    then show ?case\n      using aux by (simp add: \\<phi>''')\n  next\n    case (step k X Y z)\n    then show ?case\n      using fvi_subset pos\n      by (auto 0 3 simp: args_ivl args_n args_L args_R Un_absorb1 Sincep_def\n          elim!: upd_since(1) list_all2_appendI dest!: upd_since(2)\n          split: prod.split if_splits option.splits)\n  qed simp\n  with MSince.IH(1)[OF \\<phi> MSince.prems(2)] MSince.IH(2)[OF \\<psi> MSince.prems(2)] show ?case\n    by (auto 0 3 simp: Since_eq args_n agg_n[symmetric] split: prod.split\n        intro!: wf_mformula.Since[OF _ _ pos pos_eq args_ivl args_n args_L args_R mr fvi_subset]\n        elim: mbuf2t_take_add'(1)[OF _ wf_envs_P_simps[OF MSince.prems(2)] buf nts_snoc]\n              mbuf2t_take_add'(2)[OF _ wf_envs_P_simps[OF MSince.prems(2)] buf nts_snoc])\nnext\n  case (MUntil args \\<phi> \\<psi> buf nts t aux  db P P' V n' R' \\<phi>')\n  note sat.simps[simp del] progress_simps[simp del]\n  from MUntil.prems obtain \\<phi>'' \\<phi>''' \\<psi>'' I n R where Until_eq: \"\\<phi>' = packagg args (Formula.Until \\<phi>''' I \\<psi>'')\"\n    and pos: \"if args_pos args then \\<phi>''' = \\<phi>'' else \\<phi>''' = Formula.Neg \\<phi>''\"\n    and pos_eq: \"safe_formula \\<phi>''' = args_pos args\"\n    and \\<phi>: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>''\"\n    and \\<psi>: \"wf_mformula \\<sigma> j P V n R \\<psi> \\<psi>''\"\n    and fvi_subset: \"Formula.fv \\<phi>'' \\<subseteq> Formula.fv \\<psi>''\"\n    and buf: \"wf_mbuf2' \\<sigma> P V j n R \\<phi>'' \\<psi>'' buf\"\n    and nts: \"wf_ts \\<sigma> P j \\<phi>'' \\<psi>'' nts\"\n    and aux: \"wf_until_aux \\<sigma> V R args \\<phi>'' \\<psi>'' aux (progress \\<sigma> P (Formula.Until \\<phi>''' I \\<psi>'') j)\"\n    and args_ivl: \"args_ivl args = I\"\n    and args_n: \"args_n args = n\"\n    and args_L: \"args_L args = Formula.fv \\<phi>''\"\n    and args_R: \"args_R args = Formula.fv \\<psi>''\"\n    and mr: \"mem_restr R = mem_restr (lift_envs' (agg_b args) R')\"\n    and agg_n: \"agg_n args = n'\"\n    and t: \"t = (if j = 0 then 0 else \\<tau> \\<sigma> (min (j - 1) (min (progress \\<sigma> P \\<phi>'' j) (progress \\<sigma> P \\<psi>'' j))))\"\n    and length_aux: \"progress \\<sigma> P (Formula.Until \\<phi>''' I \\<psi>'') j + length_muaux args aux =\n      min (progress \\<sigma> P \\<phi>'' j) (progress \\<sigma> P \\<psi>'' j)\"\n    by (cases rule: wf_mformula.cases) (auto)\n  define pos where args_pos: \"pos = args_pos args\"\n  have \\<phi>''': \"progress \\<sigma> P \\<phi>''' j = progress \\<sigma> P \\<phi>'' j\"  \"progress \\<sigma> P' \\<phi>''' j = progress \\<sigma> P' \\<phi>'' j\" for j\n    using pos by (simp_all add: progress.simps split: if_splits)\n  from MUntil.prems(2) have nts_snoc: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i)\n    [min (progress \\<sigma> P \\<phi>'' j) (progress \\<sigma> P \\<psi>'' j)..< j + \\<delta>] (nts @ map (\\<tau> \\<sigma>) [j ..< j + \\<delta>])\"\n    using nts unfolding wf_ts_def\n    by (subst upt_add_eq_append) (auto simp add: wf_envs_progress_le[THEN min.coboundedI1] list.rel_map\n        intro!: list_all2_appendI list.rel_refl)\n  have valid: \"valid_aggargs n (fv \\<psi>'') (args_agg args)\"\n    using aux\n    by (auto simp: wf_until_aux_def args_n)\n  define xs where \"xs = fst (meval n (map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) db \\<phi>)\"\n  define ys where \"ys = fst (meval n (map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) db \\<psi>)\"\n  have list_all2_xs: \"list_all2 (\\<lambda>i. qtable n (fv \\<phi>'') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>''))\n    [Monitor.progress \\<sigma> P \\<phi>'' j..<Monitor.progress \\<sigma> P' \\<phi>'' (j + \\<delta>)] xs\"\n    using MUntil(1)[OF \\<phi> MUntil(4)]\n    by (auto simp: xs_def split: prod.splits)\n  have list_all2_ys: \"list_all2 (\\<lambda>i. qtable n (fv \\<psi>'') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>''))\n    [Monitor.progress \\<sigma> P \\<psi>'' j..<Monitor.progress \\<sigma> P' \\<psi>'' (j + \\<delta>)] ys\"\n    using MUntil(2)[OF \\<psi> MUntil(4)]\n    by (auto simp: ys_def split: prod.splits)\n  have Untilp: \"Untilp pos \\<phi>'' I \\<psi>'' = formula.Until \\<phi>''' I \\<psi>''\"\n    using pos\n    by (auto simp: Untilp_def args_pos split: if_splits)\n  have update:\n    \"wf_until_aux \\<sigma> V R args \\<phi>'' \\<psi>'' aux'' (progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (j + \\<delta>)) \\<and>\n      progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j + length zs = progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (j + \\<delta>) \\<and>\n      progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j + length zs + length_muaux args aux'' = min (progress \\<sigma> P' \\<phi>''' (j + \\<delta>)) (progress \\<sigma> P' \\<psi>'' (j + \\<delta>)) \\<and>\n      list_all2 (\\<lambda>i. qtable (agg_n args) (fv (packagg args (formula.Until \\<phi>''' I \\<psi>''))) (mem_restr R') (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (packagg args (formula.Until \\<phi>''' I \\<psi>''))))\n      [progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j..<progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j + length zs] zs \\<and>\n      nt = (if j + \\<delta> = 0 then 0 else \\<tau> \\<sigma> (min (j + \\<delta> - 1) (min (progress \\<sigma> P' \\<phi>'' (j + \\<delta>)) (progress \\<sigma> P' \\<psi>'' (j + \\<delta>)))))\"\n    if nt0: \"nt = lookahead_ts nts' nts (map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) t\"\n      and eq1: \"mbuf2t_take (add_new_muaux args) aux (mbuf2_add xs ys buf) (nts @ map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) = (aux', buf', nts')\"\n      and eq2: \"eval_muaux args nt aux' = (zs, aux'')\"\n    for aux' aux'' zs nt nts' buf'\n    using update_until'[OF list_all2_xs list_all2_ys eq1 eq2 pos MUntil(4) fvi_subset buf nts aux args_ivl args_n args_L args_R args_pos t nt0 length_aux nts_snoc mr valid]\n    by (auto simp: args_n agg_n_def Untilp split: option.splits)\n  from MUntil.IH(1)[OF \\<phi> MUntil.prems(2)] MUntil.IH(2)[OF \\<psi> MUntil.prems(2)] pos pos_eq fvi_subset show ?case\n    unfolding meval.simps Let_def\n    by (auto simp: args_ivl args_n args_pos agg_n[symmetric] Until_eq \\<phi>''' progress.simps(6) Let_def xs_def ys_def\n        split: prod.split if_splits dest!: update[OF refl, rotated]\n        intro!: wf_mformula.Until[OF _ _ _ _ args_ivl args_n args_L args_R mr fvi_subset]\n        elim!: list.rel_mono_strong qtable_cong\n        elim: mbuf2t_take_add'(1)[OF _ wf_envs_P_simps[OF MUntil.prems(2)] buf nts_snoc]\n        mbuf2t_take_add'(2)[OF _ wf_envs_P_simps[OF MUntil.prems(2)] buf nts_snoc])\nnext\n  case (MMatchP I mr mrs \\<phi>s buf nts aux)\n  note sat.simps[simp del] mbufnt_take.simps[simp del] mbufn_add.simps[simp del]\n  from MMatchP.prems obtain r \\<psi>s where eq: \"\\<phi>' = Formula.MatchP I r\"\n    and safe: \"safe_regex Past Strict r\"\n    and mr: \"to_mregex r = (mr, \\<psi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (RPDs mr)\"\n    and \\<psi>s: \"list_all2 (wf_mformula \\<sigma> j P V n R) \\<phi>s \\<psi>s\"\n    and buf: \"wf_mbufn' \\<sigma> P V j n R r buf\"\n    and nts: \"wf_ts_regex \\<sigma> P j r nts\"\n    and aux: \"wf_matchP_aux \\<sigma> V n R I r aux (progress \\<sigma> P (Formula.MatchP I r) j)\"\n    by (cases rule: wf_mformula.cases) (auto)\n  have nts_snoc: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [progress_regex \\<sigma> P r j..< j + \\<delta>] (nts @ map (\\<tau> \\<sigma>) [j ..< j + \\<delta>])\"\n    using nts unfolding wf_ts_regex_def\n    by (subst upt_add_eq_append) (auto simp add: wf_envs_progress_regex_le[OF MMatchP.prems(2)] list.rel_map\n      intro!: list_all2_appendI list.rel_refl)\n  have update: \"wf_matchP_aux \\<sigma> V n R I r (snd (zs, aux')) (progress \\<sigma> P' (Formula.MatchP I r) (j + \\<delta>)) \\<and>\n    list_all2 (\\<lambda>i. qtable n (Formula.fv_regex r) (mem_restr R)\n      (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (Formula.MatchP I r)))\n      [progress \\<sigma> P (Formula.MatchP I r) j..<progress \\<sigma> P' (Formula.MatchP I r) (j + \\<delta>)] (fst (zs, aux'))\"\n    if eval: \"map (fst o meval n (map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) db) \\<phi>s = xss\"\n      and eq: \"mbufnt_take (\\<lambda>rels t (zs, aux).\n        case update_matchP n I mr mrs rels t aux of (z, x) \\<Rightarrow> (zs @ [z], x))\n        ([], aux) (mbufn_add xss buf) (nts @ map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) = ((zs, aux'), buf', nts')\"\n    for xss zs aux' buf' nts'\n    unfolding progress_simps\n  proof (rule mbufnt_take_add_induct'[where j'=\"j + \\<delta>\" and z'=\"(zs, aux')\", OF eq wf_envs_P_simps[OF MMatchP.prems(2)] safe mr buf nts_snoc],\n      goal_cases xss _ base step)\n    case xss\n    then show ?case\n      using eval \\<psi>s\n      by (auto simp: list_all3_map map2_map_map list_all3_list_all2_conv list.rel_map\n          list.rel_flip[symmetric, of _ \\<psi>s \\<phi>s] dest!: MMatchP.IH(1)[OF _ _ MMatchP.prems(2)]\n          elim!: list.rel_mono_strong split: prod.splits)\n  next\n    case base\n    then show ?case\n      using aux by auto\n  next\n    case (step k Xs z)\n    then show ?case\n      by (auto simp: Un_absorb1 mrs safe mr elim!: update_matchP(1) list_all2_appendI\n          dest!: update_matchP(2) split: prod.split)\n  qed simp\n  then show ?case using \\<psi>s\n    by (auto simp: eq mr mrs safe map_split_alt list.rel_flip[symmetric, of _ \\<psi>s \\<phi>s]\n        list_all3_map map2_map_map list_all3_list_all2_conv list.rel_map intro!: wf_mformula.intros\n        elim!: list.rel_mono_strong mbufnt_take_add'(1)[OF _ wf_envs_P_simps[OF MMatchP.prems(2)] safe mr buf nts_snoc]\n        mbufnt_take_add'(2)[OF _ wf_envs_P_simps[OF MMatchP.prems(2)] safe mr buf nts_snoc]\n        dest!: MMatchP.IH[OF _ _ MMatchP.prems(2)] split: prod.splits)\nnext\n  case (MMatchF I mr mrs \\<phi>s buf nts t aux)\n  note sat.simps[simp del] mbufnt_take.simps[simp del] mbufn_add.simps[simp del] progress_simps[simp del]\n  from MMatchF.prems obtain r \\<psi>s where eq: \"\\<phi>' = Formula.MatchF I r\"\n    and safe: \"safe_regex Futu Strict r\"\n    and mr: \"to_mregex r = (mr, \\<psi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (LPDs mr)\"\n    and \\<psi>s: \"list_all2 (wf_mformula \\<sigma> j P V n R) \\<phi>s \\<psi>s\"\n    and buf: \"wf_mbufn' \\<sigma> P V j n R r buf\"\n    and nts: \"wf_ts_regex \\<sigma> P j r nts\"\n    and aux: \"wf_matchF_aux \\<sigma> V n R I r aux (progress \\<sigma> P (Formula.MatchF I r) j) 0\"\n    and t: \"t = (if j = 0 then 0 else \\<tau> \\<sigma> (min (j - 1) (progress_regex \\<sigma> P r j)))\"\n    and length_aux: \"progress \\<sigma> P (Formula.MatchF I r) j + length aux = progress_regex \\<sigma> P r j\"\n    by (cases rule: wf_mformula.cases) (auto)\n  have nts_snoc: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i)\n    [progress_regex \\<sigma> P r j..< j + \\<delta>] (nts @ map (\\<tau> \\<sigma>) [j ..< j + \\<delta>])\"\n    using nts unfolding wf_ts_regex_def\n    by (subst upt_add_eq_append) (auto simp add: wf_envs_progress_regex_le[OF MMatchF.prems(2)] list.rel_map\n      intro!: list_all2_appendI list.rel_refl)\n  {\n    fix xss zs aux' aux'' buf' nts' nt\n    assume eval: \"map (fst o meval n (map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) db) \\<phi>s = xss\"\n      and nt0: \"nt = lookahead_ts nts' nts (map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) t\"\n      and eq1: \"mbufnt_take (update_matchF n I mr mrs) aux (mbufn_add xss buf) (nts @ map (\\<tau> \\<sigma>) [j ..< j + \\<delta>]) =\n        (aux', buf', nts')\"\n      and eq2: \"eval_matchF I mr nt aux' = (zs, aux'')\"\n    have update1: \"wf_matchF_aux \\<sigma> V n R I r aux' (progress \\<sigma> P (Formula.MatchF I r) j) 0 \\<and>\n      progress \\<sigma> P (Formula.MatchF I r) j + length aux' = progress_regex \\<sigma> P' r (j + \\<delta>)\"\n      using eval nts_snoc nts_snoc length_aux aux \\<psi>s\n      by (elim mbufnt_take_add_induct'[where j'=\"j + \\<delta>\", OF eq1 wf_envs_P_simps[OF MMatchF.prems(2)] safe mr buf])\n        (auto simp: length_update_matchF\n          list_all3_map map2_map_map list_all3_list_all2_conv list.rel_map list.rel_flip[symmetric, of _ \\<psi>s \\<phi>s]\n          dest!: MMatchF.IH[OF _ _ MMatchF.prems(2)]\n          elim: wf_update_matchF[OF _ safe mr mrs] elim!: list.rel_mono_strong)\n    from MMatchF.prems(2) have nts': \"wf_ts_regex \\<sigma> P' (j + \\<delta>) r nts'\"\n      using eval eval nts_snoc \\<psi>s\n      unfolding wf_ts_regex_def\n      apply (intro mbufnt_take_eqD(2)[OF eq1 wf_mbufn_add[where js'=\"map (\\<lambda>\\<phi>. progress \\<sigma> P' \\<phi> (j + \\<delta>)) \\<psi>s\",\n              OF buf[unfolded wf_mbufn'_def mr prod.case]]])\n      apply (auto simp: to_mregex_progress[OF safe mr] Mini_def\n          list_all3_map map2_map_map list_all3_list_all2_conv list.rel_map list.rel_flip[symmetric, of _ \\<psi>s \\<phi>s]\n          list_all2_Cons1 elim!: list.rel_mono_strong intro!: list.rel_refl_strong\n          dest!: MMatchF.IH[OF _ _ MMatchF.prems(2)])\n      apply (auto simp: list_all2_conv_all_nth)\n      done\n    have nt: \"nt = (if j + \\<delta> = 0 then 0 else \\<tau> \\<sigma> (min (j + \\<delta> - 1) (progress_regex \\<sigma> P' r (j + \\<delta>))))\"\n      using nts nts' unfolding nt0 t\n      apply (auto simp: hd_append hd_rev last_map wf_ts_regex_def lookahead_ts_def)\n      using list_all2_hdD(1) list_all2_hdD(2) apply fastforce\n      using list_all2_lastD apply fastforce\n        apply (metis (mono_tags) list_all2_hdD(1) list_all2_hdD(2) min.absorb2 Suc_diff_Suc diff_zero less_Suc_eq_le)\n       apply (metis (mono_tags, lifting) add_gr_0 list_all2_hdD(1) list_all2_hdD(2) min.absorb2 Suc_diff_Suc diff_zero less_Suc_eq_le)\n      apply (metis (mono_tags, lifting) add_gr_0 list_all2_hdD(1) list_all2_hdD(2) min.absorb2 Suc_diff_Suc diff_zero less_Suc_eq_le)\n      done\n    have \"i \\<le> progress \\<sigma> P' (Formula.MatchF I r) (j + \\<delta>) \\<Longrightarrow>\n      wf_matchF_aux \\<sigma> V n R I r aux' i 0 \\<Longrightarrow>\n      i + length aux' = progress_regex \\<sigma> P' r (j + \\<delta>) \\<Longrightarrow>\n      wf_matchF_aux \\<sigma> V n R I r aux'' (progress \\<sigma> P' (Formula.MatchF I r) (j + \\<delta>)) 0 \\<and>\n        i + length zs = progress \\<sigma> P' (Formula.MatchF I r) (j + \\<delta>) \\<and>\n        i + length zs + length aux'' = progress_regex \\<sigma> P' r (j + \\<delta>) \\<and>\n        list_all2 (\\<lambda>i. qtable n (Formula.fv_regex r) (mem_restr R)\n          (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (Formula.MatchF I r)))\n          [i..<i + length zs] zs\" for i\n      using eq2\n    proof (induction aux' arbitrary: zs aux'' i)\n      case Nil\n      then show ?case by (auto dest!: antisym[OF progress_MatchF_le])\n    next\n      case (Cons a aux')\n      obtain t rels rel where \"a = (t, rels, rel)\" by (cases a)\n      from Cons.prems(2) have aux': \"wf_matchF_aux \\<sigma> V n R I r aux' (Suc i) 0\"\n        by (rule wf_matchF_aux_Cons)\n      from Cons.prems(2) have 1: \"t = \\<tau> \\<sigma> i\"\n        unfolding \\<open>a = (t, rels, rel)\\<close> by (rule wf_matchF_aux_Cons1)\n      from Cons.prems(2) have 3: \"qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v.\n        (\\<exists>j\\<ge>i. j < Suc (i + length aux') \\<and> mem I ((\\<tau> \\<sigma> j - \\<tau> \\<sigma> i)) \\<and> Regex.match (Formula.sat \\<sigma> V (map the v)) r i j)) rel\"\n        unfolding \\<open>a = (t, rels, rel)\\<close> using wf_matchF_aux_Cons3 by force\n      from Cons.prems(3) have Suc_i_aux': \"Suc i + length aux' = progress_regex \\<sigma> P' r (j + \\<delta>)\"\n        by simp\n      have \"i \\<ge> progress \\<sigma> P' (Formula.MatchF I r) (j + \\<delta>)\"\n        if \"memR I (nt - t)\"\n        using that nts' unfolding wf_ts_regex_def progress_simps nt\n        by (auto simp add: 1 list_all2_Cons2 upt_eq_Cons_conv\n          intro!: cInf_lower \\<tau>_mono diff_le_mono simp del: upt_Suc split: if_splits list.splits)\n      moreover\n      have \"Suc i \\<le> progress \\<sigma> P' (Formula.MatchF I r) (j + \\<delta>)\"\n        if \"\\<not> memR I (nt - t)\"\n      proof -\n        have \\<tau>_min:  \"\\<tau> \\<sigma> (min (j + \\<delta> - 1) k) = min (\\<tau> \\<sigma> (j + \\<delta> - 1) ) (\\<tau> \\<sigma> k)\" for k\n          by (simp add: min_of_mono monoI)\n        have le_progress_iff[simp]: \"j + \\<delta> \\<le> progress \\<sigma> P' \\<phi> (j + \\<delta>) \\<longleftrightarrow> progress \\<sigma> P' \\<phi> (j + \\<delta>) = (j + \\<delta>)\" for \\<phi>\n          using wf_envs_progress_le[OF MMatchF.prems(2), of \\<phi>] by auto\n        have min_Suc[simp]: \"min j (j + \\<delta>) = j\" by auto\n        let ?X = \"{i. \\<forall>k. k < j + \\<delta> \\<and> k \\<le> progress_regex \\<sigma> P' r (j + \\<delta>) \\<longrightarrow> memR I (\\<tau> \\<sigma> k - \\<tau> \\<sigma> i)}\"\n        let ?min = \"min (j + \\<delta> - 1) (progress_regex \\<sigma> P' r (j + \\<delta>))\"\n        have \"\\<tau> \\<sigma> ?min \\<le> \\<tau> \\<sigma> (j + \\<delta>)\"\n          by (rule \\<tau>_mono) auto\n        from that have \"?X \\<noteq> {}\"\n          by (auto intro!: exI[of _ \"progress_regex \\<sigma> P' r (j + \\<delta>)\"])\n        show ?thesis\n          using that nts' wf_envs_progress_regex_le[OF MMatchF.prems(2), of r]\n          unfolding wf_ts_regex_def progress_simps nt\n          by (intro cInf_greatest[OF \\<open>?X \\<noteq> {}\\<close>])\n            (auto 0 3 simp: 1 list_all2_Cons2 upt_eq_Cons_conv\n              simp del: upt_Suc split: list.splits if_splits\n              dest!: spec[of _ \"?min\"]\n              intro!: diff_le_mono diff_le_mono2 order_trans[OF diff_le_mono diff_le_mono2] \\<tau>_mono\n              elim!: contrapos_np[of _ \"Suc i \\<le> _\"])\n      qed\n      moreover have *: \"k < progress_regex \\<sigma> P' r (j + \\<delta>)\" if\n        \"\\<not> memR I (nt - \\<tau> \\<sigma> i)\"\n        \"memR I (\\<tau> \\<sigma> k - \\<tau> \\<sigma> i)\" for k\n        using that nts' unfolding wf_ts_regex_def nt\n        by (auto simp: list_all2_Cons2 upt_eq_Cons_conv\n          simp del: upt_Suc split: list.splits if_splits\n          elim!: contrapos_np[of _ \"k < _\"] intro!: diff_le_mono diff_le_mono2)\n      ultimately show ?case using Cons.prems Suc_i_aux'[simplified]\n        unfolding \\<open>a = (t, rels, rel)\\<close>\n        by (auto simp: 1 sat.simps upt_conv_Cons dest!: Cons.IH[OF _ aux' Suc_i_aux']\n            simp del: upt_Suc split: if_splits prod.splits intro!: iff_exI qtable_cong[OF 3 refl])\n\n    qed\n    note conjI[OF nt this[OF progress_mono_gen[OF le_add1] conjunct1[OF update1] conjunct2[OF update1]]]\n  }\n  note update = this[OF refl refl, rotated]\n  from MMatchF.prems(2) show ?case using \\<psi>s\n    by (auto simp: eq mr mrs safe map_split_alt list.rel_flip[symmetric, of _ \\<psi>s \\<phi>s]\n        list_all3_map map2_map_map list_all3_list_all2_conv list.rel_map Let_def\n        intro!: wf_mformula.intros\n        elim!: list.rel_mono_strong mbufnt_take_add'(1)[OF _ wf_envs_P_simps[OF MMatchF.prems(2)] safe mr buf nts_snoc]\n        mbufnt_take_add'(2)[OF _ wf_envs_P_simps[OF MMatchF.prems(2)] safe mr buf nts_snoc]\n        dest!: MMatchF.IH[OF _ _ MMatchF.prems(2)] update split: prod.splits)\nqed\n\n\nsubsubsection \\<open>Monitor step\\<close>\n\nlemma (in maux) wf_mstate_mstep: \"wf_mstate \\<phi> \\<pi> R st \\<Longrightarrow> last_ts \\<pi> \\<le> snd tdb \\<Longrightarrow>\n  wf_mstate \\<phi> (psnoc \\<pi> tdb) R (snd (mstep (map_prod mk_db id tdb) st))\"\n  unfolding wf_mstate_def mstep_def Let_def\n  by (fastforce simp add: progress_mono le_imp_diff_is_add split: prod.splits\n      elim!: prefix_of_psnocE dest: meval[OF _ wf_envs_mk_db] list_all2_lengthD)\n\ndefinition \"flatten_verdicts Vs = (\\<Union> (set (map (\\<lambda>(i, X). (\\<lambda>v. (i, v)) ` X) Vs)))\"\n\nlemma flatten_verdicts_append[simp]:\n  \"flatten_verdicts (Vs @ Us) = flatten_verdicts Vs \\<union> flatten_verdicts Us\"\n  by (induct Vs) (auto simp: flatten_verdicts_def)\n\nlemma (in maux) mstep_output_iff:\n  assumes \"wf_mstate \\<phi> \\<pi> R st\" \"last_ts \\<pi> \\<le> snd tdb\" \"prefix_of (psnoc \\<pi> tdb) \\<sigma>\" \"mem_restr R v\"\n  shows \"(i, v) \\<in> flatten_verdicts (fst (mstep (map_prod mk_db id tdb) st)) \\<longleftrightarrow>\n    progress \\<sigma> Map.empty \\<phi> (plen \\<pi>) \\<le> i \\<and> i < progress \\<sigma> Map.empty \\<phi> (Suc (plen \\<pi>)) \\<and>\n    wf_tuple (Formula.nfv \\<phi>) (Formula.fv \\<phi>) v \\<and> Formula.sat \\<sigma> Map.empty (map the v) i \\<phi>\"\nproof -\n  from prefix_of_psnocE[OF assms(3,2)] have \"prefix_of \\<pi> \\<sigma>\"\n    \"\\<Gamma> \\<sigma> (plen \\<pi>) = fst tdb\" \"\\<tau> \\<sigma> (plen \\<pi>) = snd tdb\" by auto\n  moreover from assms(1) \\<open>prefix_of \\<pi> \\<sigma>\\<close> have \"mstate_n st = Formula.nfv \\<phi>\"\n    \"mstate_i st = progress \\<sigma> Map.empty \\<phi> (plen \\<pi>)\" \"wf_mformula \\<sigma> (plen \\<pi>) Map.empty Map.empty (mstate_n st) R (mstate_m st) \\<phi>\"\n    unfolding wf_mstate_def by blast+\n  moreover from meval[OF \\<open>wf_mformula \\<sigma> (plen \\<pi>) Map.empty Map.empty (mstate_n st) R (mstate_m st) \\<phi>\\<close> wf_envs_mk_db] obtain Vs st' where\n    \"meval (mstate_n st) [\\<tau> \\<sigma> (plen \\<pi>)] (mk_db (\\<Gamma> \\<sigma> (plen \\<pi>))) (mstate_m st) = (Vs, st')\"\n    \"wf_mformula \\<sigma> (Suc (plen \\<pi>)) Map.empty Map.empty (mstate_n st) R st' \\<phi>\"\n    \"list_all2 (\\<lambda>i. qtable (mstate_n st) (fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> Map.empty (map the v) i \\<phi>))\n      [progress \\<sigma> Map.empty \\<phi> (plen \\<pi>)..<progress \\<sigma> Map.empty \\<phi> (Suc (plen \\<pi>))] Vs\" by auto\n  moreover from this assms(4) have \"qtable (mstate_n st) (fv \\<phi>) (mem_restr R)\n    (\\<lambda>v. Formula.sat \\<sigma> Map.empty (map the v) i \\<phi>) (Vs ! (i - progress \\<sigma> Map.empty \\<phi> (plen \\<pi>)))\"\n    if \"progress \\<sigma> Map.empty \\<phi> (plen \\<pi>) \\<le> i\" \"i < progress \\<sigma> Map.empty \\<phi> (Suc (plen \\<pi>))\"\n    using that by (auto simp: list_all2_conv_all_nth\n        dest!: spec[of _ \"(i - progress \\<sigma> Map.empty \\<phi> (plen \\<pi>))\"])\n  ultimately show ?thesis\n    using assms(4) unfolding mstep_def Let_def flatten_verdicts_def\n    by (auto simp: in_set_enumerate_eq list_all2_conv_all_nth progress_mono le_imp_diff_is_add\n        elim!: in_qtableE in_qtableI intro!: bexI[of _ \"(i, Vs ! (i - progress \\<sigma> Map.empty \\<phi> (plen \\<pi>)))\"])\nqed\n\n\nsubsubsection \\<open>Monitor function\\<close>\n\nlocale verimon = verimon_spec + maux\n\nlemma (in verimon) mstep_mverdicts:\n  assumes wf: \"wf_mstate \\<phi> \\<pi> R st\"\n    and le[simp]: \"last_ts \\<pi> \\<le> snd tdb\"\n    and restrict: \"mem_restr R v\"\n  shows \"(i, v) \\<in> flatten_verdicts (fst (mstep (map_prod mk_db id tdb) st)) \\<longleftrightarrow>\n    (i, v) \\<in> M (psnoc \\<pi> tdb) - M \\<pi>\"\nproof -\n  obtain \\<sigma> where p2: \"prefix_of (psnoc \\<pi> tdb) \\<sigma>\"\n    using ex_prefix_of by blast\n  with le have p1: \"prefix_of \\<pi> \\<sigma>\" by (blast elim!: prefix_of_psnocE)\n  show ?thesis\n    unfolding M_def\n    by (auto 0 3 simp: p2 progress_prefix_conv[OF _ p1] sat_prefix_conv[OF _ p1] not_less\n        pprogress_eq[OF p1] pprogress_eq[OF p2]\n        dest: mstep_output_iff[OF wf le p2 restrict, THEN iffD1] spec[of _ \\<sigma>]\n        mstep_output_iff[OF wf le _ restrict, THEN iffD1] progress_sat_cong[OF p1]\n        intro: mstep_output_iff[OF wf le p2 restrict, THEN iffD2] p1)\nqed\n\ncontext maux\nbegin\n\nprimrec msteps0 where\n  \"msteps0 [] st = ([], st)\"\n| \"msteps0 (tdb # \\<pi>) st =\n    (let (V', st') = mstep (map_prod mk_db id tdb) st; (V'', st'') = msteps0 \\<pi> st' in (V' @ V'', st''))\"\n\nprimrec msteps0_stateless where\n  \"msteps0_stateless [] st = []\"\n| \"msteps0_stateless (tdb # \\<pi>) st = (let (V', st') = mstep (map_prod mk_db id tdb) st in V' @ msteps0_stateless \\<pi> st')\"\n\nlemma msteps0_msteps0_stateless: \"fst (msteps0 w st) = msteps0_stateless w st\"\n  by (induct w arbitrary: st) (auto simp: split_beta)\n\nlift_definition msteps :: \"Formula.prefix \\<Rightarrow> ('msaux, 'muaux) mstate \\<Rightarrow> (nat \\<times> event_data table) list \\<times> ('msaux, 'muaux) mstate\"\n  is msteps0 .\n\nlift_definition msteps_stateless :: \"Formula.prefix \\<Rightarrow> ('msaux, 'muaux) mstate \\<Rightarrow> (nat \\<times> event_data table) list\"\n  is msteps0_stateless .\n\nlemma msteps_msteps_stateless: \"fst (msteps w st) = msteps_stateless w st\"\n  by transfer (rule msteps0_msteps0_stateless)\n\nlemma msteps0_snoc: \"msteps0 (\\<pi> @ [tdb]) st =\n   (let (V', st') = msteps0 \\<pi> st; (V'', st'') = mstep (map_prod mk_db id tdb) st' in (V' @ V'', st''))\"\n  by (induct \\<pi> arbitrary: st) (auto split: prod.splits)\n\nlemma msteps_psnoc: \"last_ts \\<pi> \\<le> snd tdb \\<Longrightarrow> msteps (psnoc \\<pi> tdb) st =\n   (let (V', st') = msteps \\<pi> st; (V'', st'') = mstep (map_prod mk_db id tdb) st' in (V' @ V'', st''))\"\n  by transfer' (auto simp: msteps0_snoc split: list.splits prod.splits if_splits)\n\ndefinition monitor where\n  \"monitor \\<phi> \\<pi> = msteps_stateless \\<pi> (minit_safe \\<phi>)\"\n\nend\n\nlemma Suc_length_conv_snoc: \"(Suc n = length xs) = (\\<exists>y ys. xs = ys @ [y] \\<and> length ys = n)\"\n  by (cases xs rule: rev_cases) auto\n\nlemma (in verimon) wf_mstate_msteps: \"wf_mstate \\<phi> \\<pi> R st \\<Longrightarrow> mem_restr R v \\<Longrightarrow> \\<pi> \\<le> \\<pi>' \\<Longrightarrow>\n  X = msteps (pdrop (plen \\<pi>) \\<pi>') st \\<Longrightarrow> wf_mstate \\<phi> \\<pi>' R (snd X) \\<and>\n  ((i, v) \\<in> flatten_verdicts (fst X)) = ((i, v) \\<in> M \\<pi>' - M \\<pi>)\"\nproof (induct \"plen \\<pi>' - plen \\<pi>\" arbitrary: X st \\<pi> \\<pi>')\n  case 0\n  from 0(1,4,5) have \"\\<pi> = \\<pi>'\"  \"X = ([], st)\"\n    by (transfer; auto)+\n  with 0(2) show ?case unfolding flatten_verdicts_def by simp\nnext\n  case (Suc x)\n  from Suc(2,5) obtain \\<pi>'' tdb where \"x = plen \\<pi>'' - plen \\<pi>\"  \"\\<pi> \\<le> \\<pi>''\"\n    \"\\<pi>' = psnoc \\<pi>'' tdb\" \"pdrop (plen \\<pi>) (psnoc \\<pi>'' tdb) = psnoc (pdrop (plen \\<pi>) \\<pi>'') tdb\"\n    \"last_ts (pdrop (plen \\<pi>) \\<pi>'') \\<le> snd tdb\" \"last_ts \\<pi>'' \\<le> snd tdb\"\n    \"\\<pi>'' \\<le> psnoc \\<pi>'' tdb\"\n  proof (atomize_elim, transfer, elim exE, goal_cases prefix)\n    case (prefix _ _ \\<pi>' _ \\<pi>_tdb)\n    then show ?case\n    proof (cases \\<pi>_tdb rule: rev_cases)\n      case (snoc \\<pi> tdb)\n      with prefix show ?thesis\n        by (intro bexI[of _ \"\\<pi>' @ \\<pi>\"] exI[of _ tdb])\n          (force simp: sorted_append append_eq_Cons_conv split: list.splits if_splits)+\n    qed simp\n  qed\n  with Suc(1)[OF this(1) Suc.prems(1,2) this(2) refl] Suc.prems show ?case\n    unfolding msteps_msteps_stateless[symmetric]\n    by (auto simp: msteps_psnoc split_beta mstep_mverdicts\n        dest: mono_monitor[THEN set_mp, rotated] intro!: wf_mstate_mstep)\nqed\n\nlemma (in verimon) wf_mstate_msteps_stateless:\n  assumes \"wf_mstate \\<phi> \\<pi> R st\" \"mem_restr R v\" \"\\<pi> \\<le> \\<pi>'\"\n  shows \"(i, v) \\<in> flatten_verdicts (msteps_stateless (pdrop (plen \\<pi>) \\<pi>') st) \\<longleftrightarrow> (i, v) \\<in> M \\<pi>' - M \\<pi>\"\n  using wf_mstate_msteps[OF assms refl] unfolding msteps_msteps_stateless by simp\n\nlemma (in verimon) wf_mstate_msteps_stateless_UNIV: \"wf_mstate \\<phi> \\<pi> UNIV st \\<Longrightarrow> \\<pi> \\<le> \\<pi>' \\<Longrightarrow>\n  flatten_verdicts (msteps_stateless (pdrop (plen \\<pi>) \\<pi>') st) = M \\<pi>' - M \\<pi>\"\n  by (auto dest: wf_mstate_msteps_stateless[OF _ mem_restr_UNIV])\n\nlemma (in verimon) mverdicts_Nil: \"M pnil = {}\"\n  by (simp add: M_def pprogress_eq)\n\ncontext maux\nbegin\n\nlemma minit_safe_minit: \"mmonitorable \\<phi> \\<Longrightarrow> minit_safe \\<phi> = minit \\<phi>\"\n  unfolding minit_safe_def monitorable_formula_code by simp\n\nlemma wf_mstate_minit_safe: \"mmonitorable \\<phi> \\<Longrightarrow> wf_mstate \\<phi> pnil R (minit_safe \\<phi>)\"\n  using wf_mstate_minit minit_safe_minit mmonitorable_def by metis\n\nend\n\nlemma (in verimon) monitor_mverdicts: \"flatten_verdicts (monitor \\<phi> \\<pi>) = M \\<pi>\"\n  unfolding monitor_def using monitorable\n  by (subst wf_mstate_msteps_stateless_UNIV[OF wf_mstate_minit_safe, simplified])\n    (auto simp: mmonitorable_def mverdicts_Nil)\n\nsubsection \\<open>Collected correctness results\\<close>\n\ncontext verimon\nbegin\n\ntext \\<open>We summarize the main results proved above.\n\\begin{enumerate}\n\\item The term @{term M} describes semantically the monitor's expected behaviour:\n\\begin{itemize}\n\\item @{thm[source] mono_monitor}: @{thm mono_monitor[no_vars]}\n\\item @{thm[source] sound_monitor}: @{thm sound_monitor[no_vars]}\n\\item @{thm[source] complete_monitor}: @{thm complete_monitor[no_vars]}\n\\item @{thm[source] sliceable_M}: @{thm sliceable_M[no_vars]}\n\\end{itemize}\n\\item The executable monitor's online interface @{term minit_safe} and @{term mstep}\n  preserves the invariant @{term wf_mstate} and produces the the verdicts according\n  to @{term M}:\n\\begin{itemize}\n\\item @{thm[source] wf_mstate_minit_safe}: @{thm wf_mstate_minit_safe[no_vars]}\n\\item @{thm[source] wf_mstate_mstep}: @{thm wf_mstate_mstep[no_vars]}\n\\item @{thm[source] mstep_mverdicts}: @{thm mstep_mverdicts[no_vars]}\n\\end{itemize}\n\\item The executable monitor's offline interface @{term monitor} implements @{term M}:\n\\begin{itemize}\n\\item @{thm[source] monitor_mverdicts}: @{thm monitor_mverdicts[no_vars]}\n\\end{itemize}\n\\end{enumerate}\n\\<close>\n\nend\n\n(*<*)\nend\n(*>*)\n", "meta": {"author": "EmanueleFWM", "repo": "verimon-optimized-aggregations", "sha": "62096c661eb0ccf422139da229c34bc2dc735e5b", "save_path": "github-repos/isabelle/EmanueleFWM-verimon-optimized-aggregations", "path": "github-repos/isabelle/EmanueleFWM-verimon-optimized-aggregations/verimon-optimized-aggregations-62096c661eb0ccf422139da229c34bc2dc735e5b/thys/MFODL_Monitor_Devel/Monitor.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6548947290421275, "lm_q2_score": 0.4186969093556867, "lm_q1q2_score": 0.2742023990032687}}
{"text": "(*  Title:       Tree Automata\n    Author:      Peter Lammich <peter dot lammich at uni-muenster.de>\n    Maintainer:  Peter Lammich <peter dot lammich at uni-muenster.de>\n*)\nheader \"Executable Implementation of Tree Automata\"\ntheory Ta_impl\nimports \n  Main\n  \"../Collections/ICF/CollectionsV1\" \n  Ta AbsAlgo\n  \"~~/src/HOL/Library/Code_Target_Numeral\" \nbegin\n\n\n\n\ntext_raw {*\\label{sec:taimpl}*}\n\ntext {*\n  In this theory, an effcient executable implementation of non-deterministic \n  tree automata and basic algorithms is defined.\n\n  The algorithms use red-black trees to represent sets of states or rules \n  where appropriate.\n  *}\n\nsubsection \"Prelude\"\n\n  -- \"Make rules hashable\"\ninstantiation ta_rule :: (hashable,hashable) hashable\nbegin\nfun hashcode_of_ta_rule \n  :: \"('Q1::hashable,'Q2::hashable) ta_rule \\<Rightarrow> hashcode\" \n  where\n  \"hashcode_of_ta_rule (q \\<rightarrow> f qs) = hashcode q + hashcode f + hashcode qs\"\n\ndefinition [simp]: \"hashcode = hashcode_of_ta_rule\"\n\ndefinition \"def_hashmap_size::(('a,'b) ta_rule itself \\<Rightarrow> nat) == (\\<lambda>_. 32)\"\n\ninstance \n  by (intro_classes)(auto simp add: def_hashmap_size_ta_rule_def)\nend\n\n\n  -- \"Make wrapped states hashable\"\ninstantiation ustate_wrapper :: (hashable,hashable) hashable\nbegin\n  definition \"hashcode x == (case x of USW1 a \\<Rightarrow> 2 * hashcode a | USW2 b \\<Rightarrow> 2 * hashcode b + 1)\"\n  definition \"def_hashmap_size = (\\<lambda>_ :: (('a,'b) ustate_wrapper) itself. def_hashmap_size TYPE('a) + def_hashmap_size TYPE('b))\"\n\n  instance using def_hashmap_size[where ?'a=\"'a\"] def_hashmap_size[where ?'a=\"'b\"]\n    by(intro_classes)(simp_all add: bounded_hashcode_bounds def_hashmap_size_ustate_wrapper_def split: ustate_wrapper.split)\n\nend\n\nsubsubsection {* Ad-Hoc instantiations of generic Algorithms *}\nsetup Locale_Code.open_block\ninterpretation hll_idx!: build_index_loc hm_ops ls_ops ls_ops by unfold_locales\ninterpretation ll_set_xy!: g_set_xy_loc ls_ops ls_ops \n  by unfold_locales\n\ninterpretation lh_set_xx!: g_set_xx_loc ls_ops hs_ops\n  by unfold_locales\ninterpretation lll_iflt_cp: inj_image_filter_cp_loc ls_ops ls_ops ls_ops\n  by unfold_locales\ninterpretation hhh_cart: cart_loc hs_ops hs_ops hs_ops by unfold_locales\ninterpretation hh_set_xy!: g_set_xy_loc hs_ops hs_ops \n  by unfold_locales\n\ninterpretation llh_set_xyy!: g_set_xyy_loc ls_ops ls_ops hs_ops\n  by unfold_locales\n\ninterpretation hh_map_to_nat!: map_to_nat_loc hs_ops hm_ops by unfold_locales\ninterpretation hh_set_xy!: g_set_xy_loc hs_ops hs_ops by unfold_locales\ninterpretation lh_set_xy!: g_set_xy_loc ls_ops hs_ops by unfold_locales\ninterpretation hh_set_xx!: g_set_xx_loc hs_ops hs_ops by unfold_locales\ninterpretation hs_to_fifo!: set_to_list_loc hs_ops fifo_ops by unfold_locales\n\nsetup Locale_Code.close_block\n\nsubsection \"Generating Indices of Rules\"\ntext {*\n  Rule indices are pieces of extra information that may be attached to a \n  tree automaton.\n  There are three possible rule indices\n    \\begin{description}\n      \\item[f]   index of rules by function symbol\n      \\item[s]   index of rules by lhs\n      \\item[sf]  index of rules\n    \\end{description}\n  *}\n\ndefinition build_rule_index \n  :: \"(('q,'l) ta_rule \\<Rightarrow> 'i::hashable) \\<Rightarrow> ('q,'l) ta_rule ls \n      \\<Rightarrow> ('i,('q,'l) ta_rule ls) hm\"\n  where \"build_rule_index == hll_idx.idx_build\"\n\ndefinition \"build_rule_index_f \\<delta> == build_rule_index (\\<lambda>r. rhsl r) \\<delta>\"\ndefinition \"build_rule_index_s \\<delta> == build_rule_index (\\<lambda>r. lhs r) \\<delta>\"\ndefinition \"build_rule_index_sf \\<delta> == build_rule_index (\\<lambda>r. (lhs r, rhsl r)) \\<delta>\"\n\nlemma build_rule_index_f_correct[simp]: \n  assumes I[simp, intro!]: \"ls_invar \\<delta>\"\n  shows \"hll_idx.is_index rhsl (ls_\\<alpha> \\<delta>) (build_rule_index_f \\<delta>)\"\n  apply (unfold build_rule_index_f_def build_rule_index_def)\n  apply (simp add: hll_idx.idx_build_is_index)\n  done\n\nlemma build_rule_index_s_correct[simp]: \n  assumes I[simp, intro!]: \"ls_invar \\<delta>\"\n  shows\n  \"hll_idx.is_index lhs (ls_\\<alpha> \\<delta>) (build_rule_index_s \\<delta>)\"\n  by (unfold build_rule_index_s_def build_rule_index_def)\n     (simp add: hll_idx.idx_build_is_index)\n\nlemma build_rule_index_sf_correct[simp]: \n  assumes I[simp, intro!]: \"ls_invar \\<delta>\"\n  shows\n  \"hll_idx.is_index (\\<lambda>r. (lhs r, rhsl r)) (ls_\\<alpha> \\<delta>) (build_rule_index_sf \\<delta>)\"\n  by (unfold build_rule_index_sf_def build_rule_index_def)\n     (simp add: hll_idx.idx_build_is_index)\n\nsubsection \"Tree Automaton with Optional Indices\"\n\ntext {*\n  A tree automaton contains a hashset of initial states, a list-set of rules and\n  several (optional) rule indices.\n  *}\n\nrecord ('q,'l) hashedTa =\n    -- \"Initial states\"\n  hta_Qi :: \"'q hs\"           \n    -- \"Rules\"\n  hta_\\<delta> :: \"('q,'l) ta_rule ls\"    \n    -- \"Rules by function symbol\"\n  hta_idx_f :: \"('l,('q,'l) ta_rule ls) hm option\" \n    -- \"Rules by lhs state\"\n  hta_idx_s :: \"('q,('q,'l) ta_rule ls) hm option\" \n    -- \"Rules by lhs state and function symbol\"\n  hta_idx_sf :: \"('q\\<times>'l,('q,'l) ta_rule ls) hm option\" \n\n  -- \"Abstraction of a concrete tree automaton to an abstract one\"\ndefinition hta_\\<alpha> \n  where \"hta_\\<alpha> H = \\<lparr> ta_initial = hs_\\<alpha> (hta_Qi H), ta_rules = ls_\\<alpha> (hta_\\<delta> H) \\<rparr>\"\n\n  -- \"Builds the f-index if not present\"\ndefinition \"hta_ensure_idx_f H ==\n  case hta_idx_f H of \n    None \\<Rightarrow> H\\<lparr> hta_idx_f := Some (build_rule_index_f (hta_\\<delta> H)) \\<rparr> |\n    Some _ \\<Rightarrow> H\n  \"\n\n  -- \"Builds the s-index if not present\"\ndefinition \"hta_ensure_idx_s H ==\n  case hta_idx_s H of \n    None \\<Rightarrow> H\\<lparr> hta_idx_s := Some (build_rule_index_s (hta_\\<delta> H)) \\<rparr> |\n    Some _ \\<Rightarrow> H\n  \"\n\n  -- \"Builds the sf-index if not present\"\ndefinition \"hta_ensure_idx_sf H ==\n  case hta_idx_sf H of \n    None \\<Rightarrow> H\\<lparr> hta_idx_sf := Some (build_rule_index_sf (hta_\\<delta> H)) \\<rparr> |\n    Some _ \\<Rightarrow> H\n  \"\n\nlemma hta_ensure_idx_f_correct_\\<alpha>[simp]: \n  \"hta_\\<alpha> (hta_ensure_idx_f H) = hta_\\<alpha> H\" \n  by (simp add: hta_ensure_idx_f_def hta_\\<alpha>_def split: option.split)\nlemma hta_ensure_idx_s_correct_\\<alpha>[simp]: \n  \"hta_\\<alpha> (hta_ensure_idx_s H) = hta_\\<alpha> H\" \n  by (simp add: hta_ensure_idx_s_def hta_\\<alpha>_def split: option.split)\nlemma hta_ensure_idx_sf_correct_\\<alpha>[simp]: \n  \"hta_\\<alpha> (hta_ensure_idx_sf H) = hta_\\<alpha> H\" \n  by (simp add: hta_ensure_idx_sf_def hta_\\<alpha>_def split: option.split)\n\nlemma hta_ensure_idx_other[simp]:\n  \"hta_Qi (hta_ensure_idx_f H) = hta_Qi H\"  \n  \"hta_\\<delta> (hta_ensure_idx_f H) = hta_\\<delta> H\"\n  \n  \"hta_Qi (hta_ensure_idx_s H) = hta_Qi H\"  \n  \"hta_\\<delta> (hta_ensure_idx_s H) = hta_\\<delta> H\"\n  \n  \"hta_Qi (hta_ensure_idx_sf H) = hta_Qi H\" \n  \"hta_\\<delta> (hta_ensure_idx_sf H) = hta_\\<delta> H\"\n  by (auto \n    simp add: hta_ensure_idx_f_def hta_ensure_idx_s_def hta_ensure_idx_sf_def \n    split: option.split)\n\n  -- \"Check whether the f-index is present\"\ndefinition \"hta_has_idx_f H == hta_idx_f H \\<noteq> None\"\n  -- \"Check whether the s-index is present\"\ndefinition \"hta_has_idx_s H == hta_idx_s H \\<noteq> None\"\n  -- \"Check whether the sf-index is present\"\ndefinition \"hta_has_idx_sf H == hta_idx_sf H \\<noteq> None\"\n\nlemma hta_idx_f_pres\n  [simp, intro!]: \"hta_has_idx_f (hta_ensure_idx_f H)\" and\n  [simp, intro]: \"hta_has_idx_s H \\<Longrightarrow> hta_has_idx_s (hta_ensure_idx_f H)\" and\n  [simp, intro]: \"hta_has_idx_sf H \\<Longrightarrow> hta_has_idx_sf (hta_ensure_idx_f H)\"\n  by (simp_all \n    add: hta_has_idx_f_def hta_has_idx_s_def hta_has_idx_sf_def \n         hta_ensure_idx_f_def \n    split: option.split)\n\nlemma hta_idx_s_pres\n  [simp, intro!]: \"hta_has_idx_s (hta_ensure_idx_s H)\" and\n  [simp, intro]: \"hta_has_idx_f H \\<Longrightarrow> hta_has_idx_f (hta_ensure_idx_s H)\" and\n  [simp, intro]: \"hta_has_idx_sf H \\<Longrightarrow> hta_has_idx_sf (hta_ensure_idx_s H)\"\n  by (simp_all \n    add: hta_has_idx_f_def hta_has_idx_s_def hta_has_idx_sf_def \n         hta_ensure_idx_s_def \n    split: option.split)\n\nlemma hta_idx_sf_pres\n  [simp, intro!]: \"hta_has_idx_sf (hta_ensure_idx_sf H)\" and\n  [simp, intro]: \"hta_has_idx_f H \\<Longrightarrow> hta_has_idx_f (hta_ensure_idx_sf H)\" and\n  [simp, intro]: \"hta_has_idx_s H \\<Longrightarrow> hta_has_idx_s (hta_ensure_idx_sf H)\"\n  by (simp_all \n    add: hta_has_idx_f_def hta_has_idx_s_def hta_has_idx_sf_def \n         hta_ensure_idx_sf_def \n    split: option.split)\n\ntext {*\n  The lookup functions are only defined if the required index is present. \n  This enforces generation of the index before applying lookup functions.\n  *}\n  -- \"Lookup rules by function symbol\"\ndefinition \"hta_lookup_f f H == hll_idx.lookup f (the (hta_idx_f H))\"\n  -- \"Lookup rules by lhs-state\"\ndefinition \"hta_lookup_s q H == hll_idx.lookup q (the (hta_idx_s H))\"\n  -- \"Lookup rules by function symbol and lhs-state\"\ndefinition \"hta_lookup_sf q f H == hll_idx.lookup (q,f) (the (hta_idx_sf H))\"\n\n\n  -- \"This locale defines the invariants of a tree automaton\"\nlocale hashedTa =\n  fixes H :: \"('Q::hashable,'L::hashable) hashedTa\"\n\n  -- \"The involved sets satisfy their invariants\"\n  assumes invar[simp, intro!]: \n    \"hs_invar (hta_Qi H)\"\n    \"ls_invar (hta_\\<delta> H)\"\n\n  -- \"The indices are correct, if present\"\n  assumes index_correct:\n    \"hta_idx_f H = Some idx_f \n      \\<Longrightarrow> hll_idx.is_index rhsl (ls_\\<alpha> (hta_\\<delta> H)) idx_f\"\n    \"hta_idx_s H = Some idx_s \n      \\<Longrightarrow> hll_idx.is_index lhs (ls_\\<alpha> (hta_\\<delta> H)) idx_s\"\n    \"hta_idx_sf H = Some idx_sf \n      \\<Longrightarrow> hll_idx.is_index (\\<lambda>r. (lhs r, rhsl r)) (ls_\\<alpha> (hta_\\<delta> H)) idx_sf\"\n\nbegin\n  -- \"Inside this locale, some shorthand notations for the sets of \n      rules and initial states are used\"\n  abbreviation \"\\<delta> == hta_\\<delta> H\"\n  abbreviation \"Qi == hta_Qi H\"\n\n  -- {* The lookup-xxx operations are correct *}\n  lemma hta_lookup_f_correct: \n    \"hta_has_idx_f H \\<Longrightarrow> ls_\\<alpha> (hta_lookup_f f H) = {r\\<in>ls_\\<alpha> \\<delta> . rhsl r = f}\"\n    \"hta_has_idx_f H \\<Longrightarrow> ls_invar (hta_lookup_f f H)\"\n    apply (cases \"hta_has_idx_f H\")\n    apply (unfold hta_has_idx_f_def hta_lookup_f_def)\n    apply (auto \n      simp add: hll_idx.lookup_correct[OF index_correct(1)] \n                index_def)\n    done\n\n  lemma hta_lookup_s_correct: \n    \"hta_has_idx_s H \\<Longrightarrow> ls_\\<alpha> (hta_lookup_s q H) = {r\\<in>ls_\\<alpha> \\<delta> . lhs r = q}\"\n    \"hta_has_idx_s H \\<Longrightarrow> ls_invar (hta_lookup_s q H)\"\n    apply (cases \"hta_has_idx_s H\")\n    apply (unfold hta_has_idx_s_def hta_lookup_s_def)\n    apply (auto \n      simp add: hll_idx.lookup_correct[OF index_correct(2)] \n                index_def)\n    done\n\n  lemma hta_lookup_sf_correct: \n    \"hta_has_idx_sf H \n      \\<Longrightarrow> ls_\\<alpha> (hta_lookup_sf q f H) = {r\\<in>ls_\\<alpha> \\<delta> . lhs r = q \\<and> rhsl r = f}\"\n    \"hta_has_idx_sf H \\<Longrightarrow> ls_invar (hta_lookup_sf q f H)\"\n    apply (cases \"hta_has_idx_sf H\")\n    apply (unfold hta_has_idx_sf_def hta_lookup_sf_def)\n    apply (auto \n      simp add: hll_idx.lookup_correct[OF index_correct(3)] \n                index_def)\n    done\n\n  -- {* The ensure-index operations preserve the invariants *}\n  lemma hta_ensure_idx_f_correct[simp, intro!]: \"hashedTa (hta_ensure_idx_f H)\"\n    apply (unfold_locales)\n    apply (auto)\n    apply (auto \n      simp add: hta_ensure_idx_f_def hta_ensure_idx_s_def hta_ensure_idx_sf_def \n               index_correct \n      split: option.split_asm)\n    done\n\n  lemma hta_ensure_idx_s_correct[simp, intro!]: \"hashedTa (hta_ensure_idx_s H)\"\n    apply (unfold_locales)\n    apply (auto)\n    apply (auto \n      simp add: hta_ensure_idx_f_def hta_ensure_idx_s_def hta_ensure_idx_sf_def \n                index_correct \n      split: option.split_asm)\n    done\n\n  lemma hta_ensure_idx_sf_correct[simp, intro!]: \"hashedTa (hta_ensure_idx_sf H)\"\n    apply (unfold_locales)\n    apply (auto)\n    apply (auto \n      simp add: hta_ensure_idx_f_def hta_ensure_idx_s_def hta_ensure_idx_sf_def \n                index_correct \n      split: option.split_asm)\n    done\n\n  text {* The abstract tree automaton satisfies the invariants for an abstract\n          tree automaton *}\n  lemma hta_\\<alpha>_is_ta[simp, intro!]: \"tree_automaton (hta_\\<alpha> H)\"\n    apply unfold_locales\n    apply (unfold hta_\\<alpha>_def)\n    apply auto\n    done\n\nend\n\n-- \"Add some lemmas to simpset -- also outside the locale\"\nlemmas [simp, intro] = \n  hashedTa.hta_ensure_idx_f_correct\n  hashedTa.hta_ensure_idx_s_correct\n  hashedTa.hta_ensure_idx_sf_correct\n\n  -- \"Build a tree automaton from a set of initial states and a set of rules\"\ndefinition \"init_hta Qi \\<delta> == \n  \\<lparr> hta_Qi= Qi, \n    hta_\\<delta> = \\<delta>, \n    hta_idx_f = None, \n    hta_idx_s = None, \n    hta_idx_sf = None \n  \\<rparr>\"\n\n  -- \"Building a tree automaton from a valid tree automaton yields again a \n      valid tree automaton. This operation has the only effect of removing \n      the indices.\"\nlemma (in hashedTa) init_hta_is_hta: \n  \"hashedTa (init_hta (hta_Qi H) (hta_\\<delta> H))\"\n  apply (unfold_locales)\n  apply (unfold init_hta_def)\n  apply (auto)\n  done\n\nsubsection \"Algorithm for the Word Problem\"\n\nlemma r_match_by_laz: \"r_match L l = list_all_zip (\\<lambda>Q q. q\\<in>Q) L l\"\n  by (unfold r_match_alt list_all_zip_alt)\n      auto\n\n\ntext \"Executable function that computes the set of accepting states for \n    a given tree\"\nfun faccs' where\n  \"faccs' H (NODE f ts) = (\n    let Qs = List.map (faccs' H) ts in\n      ll_set_xy.g_image_filter (\\<lambda>r. case r of (q \\<rightarrow> f' qs) \\<Rightarrow> \n           if list_all_zip (\\<lambda>Q q. ls_memb q Q) Qs qs then Some (lhs r) else None\n                          ) \n                      (hta_lookup_f f H)\n  )\"\n\n  -- \"Executable algorithm to decide the word-problem. The first version \n      depends on the f-index to be present, the second version computes the \n      index if not present.\"\ndefinition \"hta_mem' t H == \\<not>lh_set_xx.g_disjoint (faccs' H t) (hta_Qi H)\"\ndefinition \"hta_mem t H == hta_mem' t (hta_ensure_idx_f H)\"\n\ncontext hashedTa\nbegin\n\n  lemma faccs'_invar:\n    assumes HI[simp, intro!]: \"hta_has_idx_f H\"\n    shows \"ls_invar (faccs' H t)\" (is ?T1) \n          \"list_all ls_invar (List.map (faccs' H) ts)\" (is ?T2)\n  proof -\n    have \"?T1 \\<and> ?T2\"\n      apply (induct rule: compat_tree_tree_list.induct)\n      apply (auto simp add: ll_set_xy.image_filter_correct hta_lookup_f_correct)\n      done\n    thus ?T1 ?T2 by auto\n  qed\n\n  declare faccs'_invar(1)[simp, intro]\n\n  lemma faccs'_correct:\n    assumes HI[simp, intro!]: \"hta_has_idx_f H\"\n    shows \n      \"ls_\\<alpha> (faccs' H t) = faccs (ls_\\<alpha> (hta_\\<delta> H)) t\" (is ?T1)\n      \"List.map ls_\\<alpha> (List.map (faccs' H) ts) \n       = List.map (faccs (ls_\\<alpha> (hta_\\<delta> H))) ts\" (is ?T2)\n  proof -\n    have \"?T1 \\<and> ?T2\"\n    proof (induct rule: compat_tree_tree_list.induct)\n      case (NODE f ts)\n      let ?\\<delta> = \"(ls_\\<alpha> (hta_\\<delta> H))\"\n      have \"faccs ?\\<delta> (NODE f ts) = (\n        let Qs = List.map (faccs ?\\<delta>) ts in\n          {q. \\<exists>r\\<in>?\\<delta>. r_matchc q f Qs r })\"\n        by (rule faccs.simps)\n      also note NODE.hyps[symmetric]\n      finally have \n        1: \"faccs ?\\<delta> (NODE f ts) \n            = ( let Qs = List.map ls_\\<alpha> (List.map (faccs' H) ts) in\n                 {q. \\<exists>r\\<in>?\\<delta>. r_matchc q f Qs r })\" .\n      {\n        fix Qsc:: \"'Q ls list\"\n        assume QI: \"list_all ls_invar Qsc\"\n        let ?Qs = \"List.map ls_\\<alpha> Qsc\"\n        have \"{ q. \\<exists>r\\<in>?\\<delta>. r_matchc q f ?Qs r } \n              = { q. \\<exists>qs. (q \\<rightarrow> f qs)\\<in>?\\<delta> \\<and> r_match ?Qs qs }\"\n          apply (safe)\n          apply (case_tac r)\n          apply auto [1]\n          apply force\n          done\n        also have \"\\<dots> = lhs ` { r\\<in>{r\\<in>?\\<delta>. rhsl r = f}. \n                                 case r of (q \\<rightarrow> f' qs) \\<Rightarrow> r_match ?Qs qs}\"\n          apply auto\n          apply force\n          apply (case_tac xa)\n          apply auto\n          done\n        finally have \n          1: \"{ q. \\<exists>r\\<in>?\\<delta>. r_matchc q f ?Qs r } \n              = lhs ` { r\\<in>{r\\<in>?\\<delta>. rhsl r = f}. \n                         case r of (q \\<rightarrow> f' qs) \\<Rightarrow> r_match ?Qs qs}\" \n          by auto\n        from QI have \n          [simp]: \"!!qs. list_all_zip (\\<lambda>Q q. q\\<in>ls_\\<alpha> Q) Qsc qs \n                         \\<longleftrightarrow> list_all_zip (\\<lambda>Q q. ls_memb q Q) Qsc qs\"\n          apply (induct Qsc)\n          apply (case_tac qs)\n          apply auto [2]\n          apply (case_tac qs)\n          apply (auto simp add: ls.correct) [2]\n          done\n        have 2: \"!!qs. r_match ?Qs qs = list_all_zip (\\<lambda>a b. ls_memb b a) Qsc qs\"\n          apply (unfold r_match_by_laz)\n          apply (simp add: list_all_zip_map1)\n          done\n        from 1 have \n          \"{ q. \\<exists>r\\<in>?\\<delta>. r_matchc q f ?Qs r } \n           = lhs ` { r\\<in>{r\\<in>?\\<delta>. rhsl r = f}. \n                     case r of (q \\<rightarrow> f' qs) \\<Rightarrow> \n                       list_all_zip (\\<lambda>a b. ls_memb b a) Qsc qs}\" \n          by (simp only: 2)\n        also have \n          \"\\<dots> = lhs ` { r\\<in>ls_\\<alpha> (hta_lookup_f f H). \n                         case r of (q \\<rightarrow> f' qs) \\<Rightarrow> \n                           list_all_zip (\\<lambda>a b. ls_memb b a) Qsc qs}\" \n          by (simp add: hta_lookup_f_correct)\n        also have \n          \"\\<dots> = ls_\\<alpha> ( ll_set_xy.g_image_filter \n                         ( \\<lambda>r. case r of (q \\<rightarrow> f' qs) \\<Rightarrow> \n                             (if (list_all_zip (\\<lambda>Q q. ls_memb q Q) Qsc qs) then Some (lhs r) else None))\n                         (hta_lookup_f f H)\n                     )\"\n          apply (simp add: ll_set_xy.image_filter_correct hta_lookup_f_correct)\n          apply (auto split: ta_rule.split)\n          apply (rule_tac x=xa in exI)\n          apply auto\n          apply (case_tac a)\n          apply (simp add: image_iff)\n          apply (rule_tac x=a in exI)\n          apply auto\n          done\n        finally have \n          \"{ q. \\<exists>r\\<in>?\\<delta>. r_matchc q f ?Qs r } \n           = ls_\\<alpha> ( ll_set_xy.g_image_filter \n                      (\\<lambda>r. case r of (q \\<rightarrow> f' qs) \\<Rightarrow> \n                        (if (list_all_zip (\\<lambda>Q q. ls_memb q Q) Qsc qs) then Some (lhs r) else None))\n                      (hta_lookup_f f H))\" .\n      } note 2=this\n      \n      from \n        1 \n        2[ where Qsc2 = \"(List.map (faccs' H) ts)\", \n           simplified faccs'_invar[OF HI]] \n      show ?case by simp\n    qed simp_all\n    thus ?T1 ?T2 by auto\n  qed\n\n    -- \"Correctness of the algorithms for the word problem\"\n  lemma hta_mem'_correct: \n    \"hta_has_idx_f H \\<Longrightarrow> hta_mem' t H \\<longleftrightarrow> t\\<in>ta_lang (hta_\\<alpha> H)\"\n    apply (unfold ta_lang_def hta_\\<alpha>_def hta_mem'_def)\n    apply (auto simp add: lh_set_xx.disjoint_correct faccs'_correct faccs_alt)\n    done\n\n  theorem hta_mem_correct: \"hta_mem t H \\<longleftrightarrow> t\\<in>ta_lang (hta_\\<alpha> H)\"\n    using hashedTa.hta_mem'_correct[OF hta_ensure_idx_f_correct, simplified]\n    apply (unfold hta_mem_def)\n    apply simp\n    done\n\nend\n\n\nsubsection \"Product Automaton and Intersection\"\n\nsubsubsection \"Brute Force Product Automaton\"\ntext {*\n  In this section, an algorithm that computes the product \n  automaton without reduction is implemented. While the runtime is always\n  quadratic, this algorithm is very simple and the constant factors are \n  smaller than that of the version with integrated reduction.\n  Moreover, lazy languages like Haskell seem to profit from this algorithm.\n*}\n\ndefinition \\<delta>_prod_h \n  :: \"('q1::hashable,'l::hashable) ta_rule ls \n      \\<Rightarrow> ('q2::hashable,'l) ta_rule ls \\<Rightarrow> ('q1\\<times>'q2,'l) ta_rule ls\" \n  where \"\\<delta>_prod_h \\<delta>1 \\<delta>2 == \n    lll_iflt_cp.inj_image_filter_cp (\\<lambda>(r1,r2). r_prod r1 r2) \n                (\\<lambda>(r1,r2). rhsl r1 = rhsl r2 \n                         \\<and> length (rhsq r1) = length (rhsq r2)) \n                \\<delta>1 \\<delta>2\"\n\nlemma r_prod_inj: \n  \"\\<lbrakk> rhsl r1 = rhsl r2; length (rhsq r1) = length (rhsq r2); \n     rhsl r1' = rhsl r2'; length (rhsq r1') = length (rhsq r2'); \n     r_prod r1 r2 = r_prod r1' r2' \\<rbrakk> \\<Longrightarrow> r1=r1' \\<and> r2=r2'\"\n  apply (cases r1, cases r2, cases r1', cases r2')\n  apply (auto dest: zip_inj)\n  done\n\nlemma \\<delta>_prod_h_correct:\n  assumes INV[simp]: \"ls_invar \\<delta>1\" \"ls_invar \\<delta>2\"\n  shows \n    \"ls_\\<alpha> (\\<delta>_prod_h \\<delta>1 \\<delta>2) = \\<delta>_prod (ls_\\<alpha> \\<delta>1) (ls_\\<alpha> \\<delta>2)\"\n    \"ls_invar (\\<delta>_prod_h \\<delta>1 \\<delta>2)\"\n  apply (unfold \\<delta>_prod_def \\<delta>_prod_h_def)\n  apply (subst lll_iflt_cp.inj_image_filter_cp_correct)\n  apply simp_all [2]\n  using r_prod_inj\n  apply (auto intro!: inj_onI) []\n  apply auto []\n  apply (case_tac xa, case_tac y, simp, blast)\n  apply force\n  apply simp\n  done\n\ndefinition \"hta_prodWR H1 H2 == \n  init_hta (hhh_cart.cart (hta_Qi H1) (hta_Qi H2)) (\\<delta>_prod_h (hta_\\<delta> H1) (hta_\\<delta> H2))\"\n\nlemma hta_prodWR_correct_aux: \n  assumes A: \"hashedTa H1\" \"hashedTa H2\"\n  shows \n    \"hta_\\<alpha> (hta_prodWR H1 H2) = ta_prod (hta_\\<alpha> H1) (hta_\\<alpha> H2)\" (is ?T1)\n    \"hashedTa (hta_prodWR H1 H2)\" (is ?T2)\nproof -\n  interpret a1: hashedTa H1 + a2: hashedTa H2 using A .\n  show ?T1 ?T2\n    apply (unfold hta_prodWR_def init_hta_def hta_\\<alpha>_def ta_prod_def)\n    apply (simp add: hhh_cart.cart_correct \\<delta>_prod_h_correct)\n    apply (unfold_locales)\n    apply (simp_all add: hhh_cart.cart_correct \\<delta>_prod_h_correct)\n    done\nqed\n  \nlemma hta_prodWR_correct:\n  assumes TA: \"hashedTa H1\" \"hashedTa H2\"\n  shows \n    \"ta_lang (hta_\\<alpha> (hta_prodWR H1 H2)) \n     = ta_lang (hta_\\<alpha> H1) \\<inter> ta_lang (hta_\\<alpha> H2)\"\n    \"hashedTa (hta_prodWR H1 H2)\"\n  by (simp_all add: hta_prodWR_correct_aux[OF TA] ta_prod_correct_aux1)\n\nsubsubsection \"Product Automaton with Forward-Reduction\"\ntext {*\n  A more elaborated algorithm combines forward-reduction and the product \n  construction, i.e. product rules are only created ,,by need''.\n*}\n\n  -- \"State of the product-automaton DFS-algorithm\"\ntype_synonym ('q1,'q2,'l) pa_state \n  = \"('q1\\<times>'q2) hs \\<times> ('q1\\<times>'q2) list \\<times> ('q1\\<times>'q2,'l) ta_rule ls\"\n\n  -- {* Abstraction mapping to algorithm specified in \n  Section~\\ref{sec:absalgo}.*}\ndefinition pa_\\<alpha> \n  :: \"('q1::hashable,'q2::hashable,'l::hashable) pa_state \n      \\<Rightarrow> ('q1,'q2,'l) frp_state\"\n  where \"pa_\\<alpha> S == let (Q,W,\\<delta>d)=S in (hs_\\<alpha> Q,W,ls_\\<alpha> \\<delta>d)\"\n\ndefinition pa_cond \n  :: \"('q1::hashable,'q2::hashable,'l::hashable) pa_state \\<Rightarrow> bool\" \n  where \"pa_cond S == let (Q,W,\\<delta>d) = S in W\\<noteq>[]\"\n\n  -- \"Adds all successor states to the set of discovered states and to the \n  worklist\"\nfun pa_upd_rule \n  :: \"('q1\\<times>'q2) hs \\<Rightarrow> ('q1\\<times>'q2) list \n      \\<Rightarrow> (('q1::hashable)\\<times>('q2::hashable)) list \n      \\<Rightarrow> (('q1\\<times>'q2) hs \\<times> ('q1\\<times>'q2) list)\" \n  where\n  \"pa_upd_rule Q W [] = (Q,W)\" |\n  \"pa_upd_rule Q W (qp#qs) = (\n    if \\<not> hs_memb qp Q then\n      pa_upd_rule (hs_ins qp Q) (qp#W) qs\n    else pa_upd_rule Q W qs\n  )\"\n\n\ndefinition pa_step \n  :: \"('q1::hashable,'l::hashable) hashedTa \n      \\<Rightarrow> ('q2::hashable,'l) hashedTa \n      \\<Rightarrow> ('q1,'q2,'l) pa_state \\<Rightarrow> ('q1,'q2,'l) pa_state\"\n  where \"pa_step H1 H2 S == let \n    (Q,W,\\<delta>d)=S;\n    (q1,q2)=hd W\n  in  \n    ls_iteratei (hta_lookup_s q1 H1) (\\<lambda>_. True) (\\<lambda>r1 res. \n      ls_iteratei (hta_lookup_sf q2 (rhsl r1) H2) (\\<lambda>_. True) (\\<lambda>r2 res.\n        if (length (rhsq r1) = length (rhsq r2)) then\n          let \n            rp=r_prod r1 r2;\n            (Q,W,\\<delta>d) = res;\n            (Q',W') = pa_upd_rule Q W (rhsq rp)\n          in\n            (Q',W',ls_ins_dj rp \\<delta>d)\n        else\n          res\n      ) res\n    ) (Q,tl W,\\<delta>d)\n  \"\n\ndefinition pa_initial \n  :: \"('q1::hashable,'l::hashable) hashedTa \n      \\<Rightarrow> ('q2::hashable,'l) hashedTa \n      \\<Rightarrow> ('q1,'q2,'l) pa_state\"\nwhere \"pa_initial H1 H2 == \n  let Qip = hhh_cart.cart (hta_Qi H1) (hta_Qi H2) in (\n    Qip,\n    hs_to_list Qip,\n    ls_empty ()\n  )\"\n\ndefinition pa_invar_add:: \n  \"('q1::hashable,'q2::hashable,'l::hashable) pa_state set\" \n  where \"pa_invar_add == { (Q,W,\\<delta>d). hs_invar Q \\<and> ls_invar \\<delta>d }\"\n\ndefinition \"pa_invar H1 H2 == \n  pa_invar_add \\<inter> {s. (pa_\\<alpha> s) \\<in> frp_invar (hta_\\<alpha> H1) (hta_\\<alpha> H2)}\"\n\ndefinition \"pa_det_algo H1 H2 \n  == \\<lparr> dwa_cond=pa_cond, \n       dwa_step = pa_step H1 H2, \n       dwa_initial = pa_initial H1 H2, \n       dwa_invar = pa_invar H1 H2 \\<rparr>\"\n\nlemma pa_upd_rule_correct:\n  assumes INV[simp, intro!]: \"hs_invar Q\"\n  assumes FMT: \"pa_upd_rule Q W qs = (Q',W')\"\n  shows\n    \"hs_invar Q'\" (is ?T1)\n    \"hs_\\<alpha> Q' = hs_\\<alpha> Q \\<union> set qs\" (is ?T2)\n    \"\\<exists>Wn. distinct Wn \\<and> set Wn = set qs - hs_\\<alpha> Q \\<and> W'=Wn@W\" (is ?T3)\nproof -\n  from INV FMT have \"?T1 \\<and> ?T2 \\<and> ?T3\"\n  proof (induct qs arbitrary: Q W Q' W')\n    case Nil thus ?case by simp\n  next\n    case (Cons q qs Q W Q' W')\n    show ?case \n    proof (cases \"q\\<in>hs_\\<alpha> Q\")\n      case True \n      obtain Qh Wh where RF: \"pa_upd_rule Q W qs = (Qh,Wh)\" by force\n      with True Cons.prems have [simp]: \"Q'=Qh\" \"W'=Wh\"\n        by (auto simp add: hs.correct)\n      from Cons.hyps[OF Cons.prems(1) RF] have\n        \"hs_invar Qh\" \n        \"hs_\\<alpha> Qh = hs_\\<alpha> Q \\<union> set qs\" \n        \"(\\<exists>Wn. distinct Wn \\<and> set Wn = set qs - hs_\\<alpha> Q \\<and> Wh = Wn @ W)\"\n        by auto\n      thus ?thesis using True by auto\n    next\n      case False\n      with Cons.prems have RF: \"pa_upd_rule (hs_ins q Q) (q#W) qs = (Q',W')\"\n        by (auto simp add: hs.correct)\n\n      from Cons.hyps[OF _ RF] Cons.prems(1) have\n        \"hs_invar Q'\" \n        \"hs_\\<alpha> Q' = insert q (hs_\\<alpha> Q) \\<union> set (qs)\"\n        \"\\<exists>Wn. distinct Wn \n              \\<and> set Wn = set qs - insert q (hs_\\<alpha> Q) \n              \\<and> W' = Wn @ q # W\"\n        by (auto simp add: hs.correct)\n      thus ?thesis using False by auto\n    qed\n  qed\n  thus ?T1 ?T2 ?T3 by auto\nqed\n\n\nlemma pa_step_correct:\n  assumes TA: \"hashedTa H1\" \"hashedTa H2\"\n  assumes idx[simp]: \"hta_has_idx_s H1\" \"hta_has_idx_sf H2\"\n  assumes INV: \"(Q,W,\\<delta>d)\\<in>pa_invar H1 H2\"\n  assumes COND: \"pa_cond (Q,W,\\<delta>d)\"\n  shows \n    \"(pa_step H1 H2 (Q,W,\\<delta>d))\\<in>pa_invar_add\" (is ?T1)\n    \"(pa_\\<alpha> (Q,W,\\<delta>d), pa_\\<alpha> (pa_step H1 H2 (Q,W,\\<delta>d))) \n     \\<in> frp_step (ls_\\<alpha> (hta_\\<delta> H1)) (ls_\\<alpha> (hta_\\<delta> H2))\" (is ?T2)\nproof -\n  interpret h1: hashedTa H1 by fact\n  interpret h2: hashedTa H2 by fact\n\n  from COND obtain q1 q2 Wtl where \n    [simp]: \"W=(q1,q2)#Wtl\" \n    by (cases W) (auto simp add: pa_cond_def)\n\n  from INV have [simp]: \"hs_invar Q\" \"ls_invar \\<delta>d\" \n    by (auto simp add: pa_invar_add_def pa_invar_def)\n\n  def inv == \"\\<lambda>\\<delta>p (Q', W', \\<delta>d'). \n    hs_invar Q' \n    \\<and> ls_invar \\<delta>d' \n    \\<and> (\\<exists>Wn. distinct Wn \n            \\<and> set Wn = (f_succ \\<delta>p `` {(q1,q2)}) - hs_\\<alpha> Q \n            \\<and> W'=Wn@Wtl \n            \\<and> hs_\\<alpha> Q'=hs_\\<alpha> Q \\<union> (f_succ \\<delta>p `` {(q1,q2)}))\n    \\<and> (ls_\\<alpha> \\<delta>d' = ls_\\<alpha> \\<delta>d \\<union> {r\\<in>\\<delta>p. lhs r = (q1,q2) })\"\n\n  have G: \"inv (\\<delta>_prod (ls_\\<alpha> (hta_\\<delta> H1)) (ls_\\<alpha> (hta_\\<delta> H2))) \n               (pa_step H1 H2 (Q,W,\\<delta>d))\"\n    apply (unfold pa_step_def)\n    apply simp\n    apply (rule_tac \n      I=\"\\<lambda>it1 res. inv (\\<delta>_prod (ls_\\<alpha> (hta_\\<delta> H1) - it1) (ls_\\<alpha> (hta_\\<delta> H2))) res\"\n      in ls.iterate_rule_P)\n    -- \"Invar\"\n    apply (simp add: h1.hta_lookup_s_correct)\n    -- \"Initial\"\n    apply (fastforce simp add: inv_def \\<delta>_prod_def h1.hta_lookup_s_correct \n                              f_succ_alt)\n    -- \"Step\"\n    apply (rule_tac \n      I=\"\\<lambda>it2 res. inv ( \\<delta>_prod (ls_\\<alpha> (hta_\\<delta> H1) - it) (ls_\\<alpha> (hta_\\<delta> H2)) \n                         \\<union> \\<delta>_prod {x} (ls_\\<alpha> (hta_\\<delta> H2) - it2)) \n                        res\" \n      in ls.iterate_rule_P)\n      -- \"Invar\"\n      apply (simp add: h2.hta_lookup_sf_correct)\n      -- \"Init\"\n      apply (case_tac \\<sigma>)\n      apply (simp add: inv_def h1.hta_lookup_s_correct h2.hta_lookup_sf_correct)\n      apply (force simp add: f_succ_alt elim: \\<delta>_prodE intro: \\<delta>_prodI) [1]\n      -- \"Step\"\n      defer -- \"Requires considerably more work: Deferred to Isar proof below\"\n      -- \"Final\"\n      apply (simp add: h1.hta_lookup_s_correct h2.hta_lookup_sf_correct)\n      apply (auto) [1]\n      apply (subgoal_tac \n        \"ls_\\<alpha> (hta_\\<delta> H1) - (it - {x}) = (ls_\\<alpha> (hta_\\<delta> H1) - it) \\<union> {x}\")\n      apply (simp add: \\<delta>_prod_insert)\n      apply (subst Un_commute)\n      apply simp\n      apply blast\n    -- \"Final\"\n    apply force\n  proof -\n    case (goal1 r1 it1 resxh r2 it2 resh)\n    -- \"Resolve lookup-operations\"\n    hence G': \n      \"it1 \\<subseteq> {r \\<in> ls_\\<alpha> (hta_\\<delta> H1). lhs r = q1}\" \n      \"it2 \\<subseteq> {r \\<in> ls_\\<alpha> (hta_\\<delta> H2). lhs r = q2 \\<and> rhsl r = rhsl r1}\"\n      by (simp_all add: h1.hta_lookup_s_correct h2.hta_lookup_sf_correct)\n\n    -- \"Basic reasoning setup\"\n    from goal1(1,4) G' have \n      [simp]: \"ls_\\<alpha> (hta_\\<delta> H2) - (it2 - {r2}) = (ls_\\<alpha> (hta_\\<delta> H2) - it2) \\<union> {r2}\"\n      by auto\n    obtain Qh Wh \\<delta>dh Q' W' \\<delta>d' where [simp]: \"resh=(Qh,Wh,\\<delta>dh)\" \n      by (cases resh) fastforce\n    from goal1(6) have INVAH[simp]: \"hs_invar Qh\" \"ls_invar \\<delta>dh\" \n      by (auto simp add: inv_def)\n\n    -- \"The involved rules have the same label, and their lhs is determined\"\n    from goal1(1,4) G' obtain l qs1 qs2 where \n      RULE_FMT: \"r1 = (q1 \\<rightarrow> l qs1)\" \"r2=(q2 \\<rightarrow> l qs2)\"\n      apply (cases r1, cases r2)\n      apply force\n      done\n\n    {\n      -- \"If the rhs have different lengths, the algorithm ignores the rule: \"\n      assume LEN: \"length (rhsq r1) \\<noteq> length (rhsq r2)\"\n      \n      hence [simp]: \"\\<delta>_prod_sng2 {r1} r2 = {}\"\n        by (auto simp add: \\<delta>_prod_sng2_def split: ta_rule.split)\n\n      have ?case using goal1 \n        by (simp add: LEN \\<delta>_prod_insert)\n    } moreover {\n      -- \"If the rhs have the same length, the rule is inserted\"\n      assume LEN: \"length (rhsq r1) = length (rhsq r2)\"\n      hence [simp]: \"length qs1 = length qs2\" by (simp add: RULE_FMT)\n\n      hence [simp]: \"\\<delta>_prod_sng2 {r1} r2 = {(q1,q2) \\<rightarrow> l (zip qs1 qs2)}\"\n        using goal1(1,4) G'\n        by (auto simp add: \\<delta>_prod_sng2_def RULE_FMT)\n\n      -- \"Obtain invariant of previous state\"\n      from goal1(6)[unfolded inv_def, simplified] obtain Wn where INVH:\n        \"distinct Wn\"\n        \"set Wn = f_succ (\\<delta>_prod (ls_\\<alpha> (hta_\\<delta> H1) - it1) (ls_\\<alpha> (hta_\\<delta> H2)) \n                          \\<union> \\<delta>_prod {r1} (ls_\\<alpha> (hta_\\<delta> H2) - it2)) \n                  `` {(q1, q2)} - hs_\\<alpha> Q\"\n        \"Wh = Wn @ Wtl\" \n        \"hs_\\<alpha> Qh = hs_\\<alpha> Q \n                   \\<union> f_succ (\\<delta>_prod (ls_\\<alpha> (hta_\\<delta> H1) - it1) (ls_\\<alpha> (hta_\\<delta> H2))\n                              \\<union> \\<delta>_prod {r1} (ls_\\<alpha> (hta_\\<delta> H2) - it2)) \n                      `` {(q1, q2)}\" \n        \"ls_\\<alpha> \\<delta>dh = ls_\\<alpha> \\<delta>d \n          \\<union> {r. ( r \\<in> \\<delta>_prod (ls_\\<alpha> (hta_\\<delta> H1) - it1) (ls_\\<alpha> (hta_\\<delta> H2)) \n                  \\<or> r \\<in> \\<delta>_prod {r1} (ls_\\<alpha> (hta_\\<delta> H2) - it2)\n                 ) \\<and> lhs r = (q1, q2)\n             }\"\n        by blast\n\n      -- \"Required to justify disjoint insert\"\n      have RPD: \"r_prod r1 r2 \\<notin> ls_\\<alpha> \\<delta>dh\" \n      proof -\n        from INV[unfolded pa_invar_def frp_invar_def frp_invar_add_def]\n        have LSDD: \n          \"ls_\\<alpha> \\<delta>d = {r \\<in> \\<delta>_prod (ls_\\<alpha> (hta_\\<delta> H1)) (ls_\\<alpha> (hta_\\<delta> H2)). \n                        lhs r \\<in> hs_\\<alpha> Q - set W}\"\n          by (auto simp add: pa_\\<alpha>_def hta_\\<alpha>_def)\n        have \"r_prod r1 r2 \\<notin> ls_\\<alpha> \\<delta>d\"\n        proof\n          assume \"r_prod r1 r2 \\<in> ls_\\<alpha> \\<delta>d\"\n          with LSDD have \"lhs (r_prod r1 r2) \\<notin> set W\" by auto\n          moreover from goal1(1,4) G' have \"lhs (r_prod r1 r2) = (q1,q2)\" \n            by (cases r1, cases r2) auto\n          ultimately show False by simp\n        qed\n        moreover from goal1(6) have \"ls_\\<alpha> \\<delta>dh = \n          ls_\\<alpha> \\<delta>d \\<union> \n          {r. ( r \\<in> \\<delta>_prod (ls_\\<alpha> (hta_\\<delta> H1) - it1) (ls_\\<alpha> (hta_\\<delta> H2)) \n                \\<or> r \\<in> \\<delta>_prod {r1} (ls_\\<alpha> (hta_\\<delta> H2) - it2)\n              ) \\<and> lhs r = (q1, q2)}\" (is \"_= _ \\<union> ?s\")\n          by (simp add: inv_def)\n        moreover have \"r_prod r1 r2 \\<notin> ?s\" using goal1(1,4) G'(2) LEN\n          apply (cases r1, cases r2)\n          apply (auto simp add: \\<delta>_prod_def)\n          done\n        ultimately show ?thesis by blast\n      qed\n\n      -- {* Correctness of result of @{text pa_upd_rule} *}\n      obtain Q' W' where \n        PAUF: \"(pa_upd_rule Qh Wh (rhsq (r_prod r1 r2))) = (Q',W')\" \n        by force\n      from pa_upd_rule_correct[OF INVAH(1) PAUF] obtain Wnn where UC:\n        \"hs_invar Q'\"\n        \"hs_\\<alpha> Q' = hs_\\<alpha> Qh \\<union> set (rhsq (r_prod r1 r2))\"\n        \"distinct Wnn\" \n        \"set Wnn = set (rhsq (r_prod r1 r2)) - hs_\\<alpha> Qh\" \n        \"W' = Wnn @ Wh\"\n        by blast\n\n      -- \"Put it all together\"\n      have ?case\n        apply (simp add: LEN Let_def ls.ins_dj_correct[OF INVAH(2) RPD] \n                         PAUF inv_def UC(1))\n        apply (intro conjI)\n        apply (rule_tac x=\"Wnn@Wn\" in exI)\n        apply (auto simp add: f_succ_alt \\<delta>_prod_insert RULE_FMT UC INVH \n                              \\<delta>_prod_sng2_def \\<delta>_prod_sng1_def)\n        done\n    } ultimately show ?case by blast\n  qed\n  from G show ?T1\n    by (cases \"pa_step H1 H2 (Q,W,\\<delta>d)\")\n       (simp add: pa_invar_add_def inv_def)\n  from G show ?T2\n    by (cases \"pa_step H1 H2 (Q,W,\\<delta>d)\")\n       (auto simp add: inv_def pa_\\<alpha>_def Let_def intro: frp_step.intros)\n\nqed\n    \n  \n\n  -- \"The product-automaton algorithm is a precise implementation of its\n      specification\"\nlemma pa_pref_frp: \n  assumes TA: \"hashedTa H1\" \"hashedTa H2\"\n  assumes idx[simp]: \"hta_has_idx_s H1\" \"hta_has_idx_sf H2\"\n\n  shows \"wa_precise_refine (det_wa_wa (pa_det_algo H1 H2)) \n                           (frp_algo (hta_\\<alpha> H1) (hta_\\<alpha> H2)) \n                           pa_\\<alpha>\"\nproof -\n  interpret h1: hashedTa H1 by fact\n  interpret h2: hashedTa H2 by fact\n  \n  show ?thesis\n    apply (unfold_locales)\n    apply (auto simp add: det_wa_wa_def pa_det_algo_def pa_\\<alpha>_def \n                          pa_cond_def frp_algo_def frp_cond_def) [1]\n    apply (auto simp add: det_wa_wa_def pa_det_algo_def pa_cond_def\n                          hta_\\<alpha>_def frp_algo_def frp_cond_def \n                intro!: pa_step_correct(2)[OF TA]) [1]\n    apply (auto simp add: det_wa_wa_def pa_det_algo_def pa_\\<alpha>_def \n                          hta_\\<alpha>_def pa_cond_def frp_algo_def frp_cond_def\n                          pa_invar_def pa_step_def pa_initial_def \n                          hs.correct ls.correct Let_def hhh_cart.cart_correct \n                intro: frp_initial.intros\n    ) [3]\n    done\nqed\n\n\n  -- \"The product automaton algorithm is a correct while-algorithm\"\nlemma pa_while_algo: \n  assumes TA: \"hashedTa H1\" \"hashedTa H2\"\n  assumes idx[simp]: \"hta_has_idx_s H1\" \"hta_has_idx_sf H2\"\n\n  shows \"while_algo (det_wa_wa (pa_det_algo H1 H2))\"\nproof -\n  interpret h1: hashedTa H1 by fact\n  interpret h2: hashedTa H2 by fact\n\n  interpret ref: wa_precise_refine \"(det_wa_wa (pa_det_algo H1 H2))\" \n                                   \"(frp_algo (hta_\\<alpha> H1) (hta_\\<alpha> H2))\" \n                                   \"pa_\\<alpha>\" \n    using pa_pref_frp[OF TA idx] .\n  show ?thesis\n    apply (rule ref.wa_intro)\n    apply (simp add: frp_while_algo)\n    apply (simp add: det_wa_wa_def pa_det_algo_def pa_invar_def frp_algo_def)\n\n    apply (auto simp add: det_wa_wa_def pa_det_algo_def) [1]\n    apply (rule pa_step_correct(1)[OF TA idx])\n    apply (auto simp add: pa_invar_def frp_algo_def) [2]\n    \n    apply (simp add: det_wa_wa_def pa_det_algo_def pa_initial_def \n                     pa_invar_add_def Let_def hhh_cart.cart_correct ls.correct)\n    done\nqed\n    \n-- \"By definition, the product automaton algorithm is deterministic\"\nlemmas pa_det_while_algo = det_while_algo_intro[OF pa_while_algo]\n\n-- \"Transferred correctness lemma\"\nlemmas pa_inv_final = \n  wa_precise_refine.transfer_correctness[OF pa_pref_frp frp_inv_final]\n\n\n-- \"The next two definitions specify the product-automata algorithm. The first\n    version requires the s-index of the first and the sf-index of the second\n    automaton to be present, while the second version computes the required \n    indices, if necessary\"\ndefinition \"hta_prod' H1 H2 ==\n  let (Q,W,\\<delta>d) = while pa_cond (pa_step H1 H2) (pa_initial H1 H2) in\n    init_hta (hhh_cart.cart (hta_Qi H1) (hta_Qi H2)) \\<delta>d\n  \"\n\ndefinition \"hta_prod H1 H2 == \n  hta_prod' (hta_ensure_idx_s H1) (hta_ensure_idx_sf H2)\"\n\n\nlemma hta_prod'_correct_aux:\n  assumes TA: \"hashedTa H1\" \"hashedTa H2\"\n  assumes idx: \"hta_has_idx_s H1\" \"hta_has_idx_sf H2\"\n  shows \"hta_\\<alpha> (hta_prod' H1 H2) \n         = ta_fwd_reduce (ta_prod (hta_\\<alpha> H1) (hta_\\<alpha> H2))\" (is ?T1)\n        \"hashedTa (hta_prod' H1 H2)\" (is ?T2)\nproof -\n  interpret h1: hashedTa H1 by fact\n  interpret h2: hashedTa H2 by fact\n\n  interpret dwa: det_while_algo \"pa_det_algo H1 H2\" \n    using pa_det_while_algo[OF TA idx] .\n\n  have LC: \"while pa_cond (pa_step H1 H2) (pa_initial H1 H2) = dwa.loop\"\n    by (unfold dwa.loop_def)\n       (simp add: pa_det_algo_def)\n\n  from dwa.while_proof'[OF pa_inv_final[OF TA idx]]\n  show ?T1\n    apply (unfold dwa.loop_def)\n    apply (simp add: hta_prod'_def init_hta_def hta_\\<alpha>_def pa_det_algo_def)\n    apply (cases \"(while pa_cond (pa_step H1 H2) (pa_initial H1 H2))\")\n    apply (simp add: pa_\\<alpha>_def hhh_cart.cart_correct hta_\\<alpha>_def)\n    done\n\n  show ?T2\n    apply (simp add: hta_prod'_def LC)\n    apply (rule dwa.while_proof)\n    apply (case_tac s)\n    apply (simp add: pa_det_algo_def pa_invar_add_def pa_invar_def init_hta_def)\n    apply unfold_locales\n    apply (simp_all add: hhh_cart.cart_correct)\n    done\nqed\n\ntheorem hta_prod'_correct:\n  assumes TA: \"hashedTa H1\" \"hashedTa H2\"\n  assumes HI: \"hta_has_idx_s H1\" \"hta_has_idx_sf H2\"\n  shows \n    \"ta_lang (hta_\\<alpha> (hta_prod' H1 H2)) \n     = ta_lang (hta_\\<alpha> H1) \\<inter> ta_lang (hta_\\<alpha> H2)\"\n\n    \"hashedTa (hta_prod' H1 H2)\"\n  by (simp_all add: hta_prod'_correct_aux[OF TA HI] ta_prod_correct_aux1)\n\nlemma hta_prod_correct_aux:\n  assumes TA[simp]: \"hashedTa H1\" \"hashedTa H2\"\n  shows \n    \"hta_\\<alpha> (hta_prod H1 H2) = ta_fwd_reduce (ta_prod (hta_\\<alpha> H1) (hta_\\<alpha> H2))\"\n    \"hashedTa (hta_prod H1 H2)\"\n  by (unfold hta_prod_def)\n     (simp_all add: hta_prod'_correct_aux)\n  \ntheorem hta_prod_correct:\n  assumes TA: \"hashedTa H1\" \"hashedTa H2\"\n  shows \n    \"ta_lang (hta_\\<alpha> (hta_prod H1 H2)) \n     = ta_lang (hta_\\<alpha> H1) \\<inter> ta_lang (hta_\\<alpha> H2)\"\n    \"hashedTa (hta_prod H1 H2)\"\n  by (simp_all add: hta_prod_correct_aux[OF TA] ta_prod_correct_aux1)\n\n\nsubsection \"Remap States\"\n\n-- \"Mapping the states of an automaton\"\ndefinition hta_remap \n  :: \"('q::hashable \\<Rightarrow> 'qn::hashable) \\<Rightarrow> ('q,'l::hashable) hashedTa \n      \\<Rightarrow> ('qn,'l) hashedTa\" \n  where \"hta_remap f H == \n    init_hta (hh_set_xy.g_image f (hta_Qi H)) \n      (ll_set_xy.g_image (remap_rule f) (hta_\\<delta> H))\"\n  \nlemma (in hashedTa) hta_remap_correct:\n  shows \"hta_\\<alpha> (hta_remap f H) = ta_remap f (hta_\\<alpha> H)\"\n        \"hashedTa (hta_remap f H)\"\n  apply (auto \n    simp add: hta_remap_def init_hta_def hta_\\<alpha>_def \n              hh_set_xy.image_correct ll_set_xy.image_correct ta_remap_def)\n  apply (unfold_locales)\n  apply (auto simp add: hh_set_xy.image_correct ll_set_xy.image_correct)\n  done\n\n\nsubsubsection \"Reindex Automaton\"\ntext {*\n  In this section, an algorithm for re-indexing the states of the automaton to\n  an initial segment of the naturals is implemented. The language of the \n  automaton is not changed by the reindexing operation.\n*}\n\n  -- \"Set of states of a rule\"\nfun rule_states_l where\n  \"rule_states_l (q \\<rightarrow> f qs) = ls_ins q (ls.from_list qs)\"\n\nlemma rule_states_l_correct[simp]: \n  \"ls_\\<alpha> (rule_states_l r) = rule_states r\"\n  \"ls_invar (rule_states_l r)\"\n  by (cases r, simp add: ls.correct)+\n\ndefinition \"hta_\\<delta>_states H \n  == (llh_set_xyy.g_Union_image id (ll_set_xy.g_image_filter \n       (\\<lambda>r. Some (rule_states_l r)) (hta_\\<delta> H)))\"\n\ndefinition \"hta_states H ==\n  hs_union (hta_Qi H) (hta_\\<delta>_states H)\"\n\nlemma (in hashedTa) hta_\\<delta>_states_correct:\n  \"hs_\\<alpha> (hta_\\<delta>_states H) = \\<delta>_states (ta_rules (hta_\\<alpha> H))\"\n  \"hs_invar (hta_\\<delta>_states H)\"\nproof (simp_all add: hta_\\<alpha>_def hta_\\<delta>_states_def)\n  case goal1\n  have \n    [simp]: \"ls_\\<alpha> (ll_set_xy.g_image_filter (\\<lambda>x. Some (rule_states_l x)) \\<delta>) \n             = rule_states_l ` ls_\\<alpha> \\<delta>\"\n    by (auto simp add: ll_set_xy.image_filter_correct)\n  show ?case\n    apply (simp add: \\<delta>_states_def)\n    apply (subst\n      llh_set_xyy.Union_image_correct[\n        of \"(ll_set_xy.g_image_filter (\\<lambda>x. Some (rule_states_l x)) \\<delta>)\", \n        simplified])\n    apply (auto simp add: ll_set_xy.image_filter_correct)\n    done\n(*next\n  case goal2 thus ?case\n    apply (rule llh.Union_image_correct)\n    apply (auto simp add: ls.image_filter_correct)\n    done*)\nqed\n\n\n\ndefinition \"reindex_map H == \n  \\<lambda>q. the (hm_lookup q (hh_map_to_nat.map_to_nat (hta_states H)))\"\n\ndefinition hta_reindex \n  :: \"('Q::hashable,'L::hashable) hashedTa \\<Rightarrow> (nat,'L) hashedTa\" where\n  \"hta_reindex H == hta_remap (reindex_map H) H\"\n\ndeclare hta_reindex_def [code del]\n\n  -- \"This version is more efficient, as the map is only computed once\"\n\n\n\nlemma (in hashedTa) reindex_map_correct:\n  \"inj_on (reindex_map H) (ta_rstates (hta_\\<alpha> H))\"\nproof -\n  have [simp]: \n    \"reindex_map H = the \\<circ> hm_\\<alpha> (hh_map_to_nat.map_to_nat (hta_states H))\"\n    by (rule ext)\n       (simp add: reindex_map_def hm.correct \n         hh_map_to_nat.map_to_nat_correct(4) \n         hta_states_correct)\n\n  show ?thesis\n    apply (simp add: hta_states_correct(1)[symmetric])\n    apply (rule inj_on_map_the)\n    apply (simp_all add: hh_map_to_nat.map_to_nat_correct hta_states_correct(2))\n    done\nqed\n\ntheorem (in hashedTa) hta_reindex_correct:\n  \"ta_lang (hta_\\<alpha> (hta_reindex H)) = ta_lang (hta_\\<alpha> H)\"\n  \"hashedTa (hta_reindex H)\"\n  apply (unfold hta_reindex_def)\n  apply (simp_all \n    add: hta_remap_correct tree_automaton.remap_lang[OF hta_\\<alpha>_is_ta] \n         reindex_map_correct)\n  done\n\nsubsection \"Union\"\n\ntext \"Computes the union of two automata\"\ndefinition hta_union \n  :: \"('q1::hashable,'l::hashable) hashedTa \n      \\<Rightarrow> ('q2::hashable,'l) hashedTa \n      \\<Rightarrow> (('q1,'q2) ustate_wrapper,'l) hashedTa\" \n  where \"hta_union H1 H2 == \n    init_hta (hs_union (hh_set_xy.g_image USW1 (hta_Qi H1)) \n                       (hh_set_xy.g_image USW2 (hta_Qi H2))) \n             (ls_union_dj (ll_set_xy.g_image (remap_rule USW1) (hta_\\<delta> H1)) \n                          (ll_set_xy.g_image (remap_rule USW2) (hta_\\<delta> H2)))\"\n\nlemma hta_union_correct': \n  assumes TA: \"hashedTa H1\" \"hashedTa H2\"\n  shows \"hta_\\<alpha> (hta_union H1 H2) \n         = ta_union_wrap (hta_\\<alpha> H1) (hta_\\<alpha> H2)\" (is ?T1)\n        \"hashedTa (hta_union H1 H2)\" (is ?T2)\nproof -\n  interpret a1: hashedTa H1 + a2: hashedTa H2 using TA .\n  show ?T1 ?T2 \n    apply (auto \n      simp add: hta_union_def init_hta_def hta_\\<alpha>_def \n                hs.correct ls.correct \n                ll_set_xy.image_correct hh_set_xy.image_correct\n                ta_remap_def ta_union_def ta_union_wrap_def)\n    apply (unfold_locales)\n    apply (auto \n      simp add: hs.correct ls.correct)\n    done\nqed\n\ntheorem hta_union_correct: \n  assumes TA: \"hashedTa H1\" \"hashedTa H2\"\n  shows \n    \"ta_lang (hta_\\<alpha> (hta_union H1 H2)) \n     = ta_lang (hta_\\<alpha> H1) \\<union> ta_lang (hta_\\<alpha> H2)\" (is ?T1)\n    \"hashedTa (hta_union H1 H2)\" (is ?T2)\nproof -\n  interpret a1: hashedTa H1 + a2: hashedTa H2 using TA .\n  show ?T1 ?T2\n    by (simp_all add: hta_union_correct'[OF TA] ta_union_wrap_correct)\nqed\n\nsubsection \"Operators to Construct Tree Automata\"\ntext {*\n  This section defines operators that add initial states and rules to a tree \n  automaton, and thus incrementally construct a tree automaton from the empty\n  automaton.\n  *}\n\n-- \"The empty automaton\"\ndefinition hta_empty :: \"unit \\<Rightarrow> ('q::hashable,'l::hashable) hashedTa\" \n  where \"hta_empty u == init_hta (hs_empty ()) (ls_empty ())\"\nlemma hta_empty_correct [simp, intro!]: \n  shows \"(hta_\\<alpha> (hta_empty ())) = ta_empty\"\n        \"hashedTa (hta_empty ())\"\n  apply (auto\n    simp add: init_hta_def hta_empty_def hta_\\<alpha>_def \\<delta>_states_def ta_empty_def\n              hs.correct ls.correct)\n  apply (unfold_locales)\n  apply (auto simp add: hs.correct ls.correct)\n  done\n\n-- \"Add an initial state to the automaton\"\ndefinition hta_add_qi \n  :: \"'q \\<Rightarrow> ('q::hashable,'l::hashable) hashedTa \\<Rightarrow> ('q,'l) hashedTa\" \n  where \"hta_add_qi qi H == init_hta (hs_ins qi (hta_Qi H)) (hta_\\<delta> H)\"\n\nlemma (in hashedTa) hta_add_qi_correct[simp, intro!]:\n  shows \"hta_\\<alpha> (hta_add_qi qi H) \n         = \\<lparr> ta_initial = insert qi (ta_initial (hta_\\<alpha> H)), \n             ta_rules = ta_rules (hta_\\<alpha> H) \n           \\<rparr>\"\n        \"hashedTa (hta_add_qi qi H)\"\n  apply (auto \n    simp add: init_hta_def hta_add_qi_def hta_\\<alpha>_def \\<delta>_states_def \n              hs.correct)\n  apply (unfold_locales)\n  apply (auto simp add: hs.correct)\n  done\n\nlemmas [simp, intro] = hashedTa.hta_add_qi_correct\n\n-- \"Add a rule to the automaton\"\ndefinition hta_add_rule \n  :: \"('q,'l) ta_rule \\<Rightarrow> ('q::hashable,'l::hashable) hashedTa \n      \\<Rightarrow> ('q,'l) hashedTa\" \n  where \"hta_add_rule r H == init_hta (hta_Qi H) (ls_ins r (hta_\\<delta> H))\"\n\nlemma (in hashedTa) hta_add_rule_correct[simp, intro!]:\n  shows \"hta_\\<alpha> (hta_add_rule r H) \n         = \\<lparr> ta_initial = ta_initial (hta_\\<alpha> H), \n             ta_rules = insert r (ta_rules (hta_\\<alpha> H)) \n           \\<rparr>\"\n        \"hashedTa (hta_add_rule r H)\"\n  apply (auto \n    simp add: init_hta_def hta_add_rule_def hta_\\<alpha>_def \n              \\<delta>_states_def ls.correct)\n  apply (unfold_locales)\n  apply (auto simp add: ls.correct)\n  done\n\nlemmas [simp, intro] = hashedTa.hta_add_rule_correct\n\n\n  -- \"Reduces an automaton to the given set of states\"\ndefinition \"hta_reduce H Q ==\n  init_hta (hs_inter Q (hta_Qi H)) \n           (ll_set_xy.g_image_filter \n              (\\<lambda>r. if hs_memb (lhs r) Q \\<and> list_all (\\<lambda>q. hs_memb q Q) (rhsq r) then Some r else None) \n              (hta_\\<delta> H))\n\"\n\ntheorem (in hashedTa) hta_reduce_correct:\n  assumes INV[simp]: \"hs_invar Q\"\n  shows\n  \"hta_\\<alpha> (hta_reduce H Q) = ta_reduce (hta_\\<alpha> H) (hs_\\<alpha> Q)\" (is ?T1)\n  \"hashedTa (hta_reduce H Q)\" (is ?T2)\n  apply (auto \n    simp add: \n      hta_reduce_def ta_reduce_def hta_\\<alpha>_def init_hta_def \n      hs.correct ls.correct\n    (*hs_correct ls_correct *)\n      list_all_iff \n      reduce_rules_def rule_states_simp \n      ll_set_xy.image_filter_correct\n    split: \n      ta_rule.split_asm\n  ) [1]\n  apply (unfold_locales)\n  apply (unfold hta_reduce_def init_hta_def)\n  apply (auto simp add: hs.correct ls.correct)\n  done\n\n\n\nsubsection \"Backwards Reduction and Emptiness Check\"\n\ntext {*\n  The algorithm uses a map from states to the set of rules that contain \n  the state on their rhs.\n*}\n\n  -- \"Add an entry to the index\"\ndefinition \"rqrm_add q r res ==\n  case hm_lookup q res of\n    None \\<Rightarrow> hm_update q (ls_ins r (ls_empty ())) res |\n    Some s \\<Rightarrow> hm_update q (ls_ins r s) res\n  \"\n\n  -- \"Lookup the set of rules with given state on rhs\"\ndefinition \"rqrm_lookup rqrm q == case hm_lookup q rqrm of\n  None \\<Rightarrow> ls_empty () |\n  Some s \\<Rightarrow> s\n  \"\n\n  -- \"Build the index from a set of rules\"\ndefinition build_rqrm \n  :: \"('q::hashable,'l::hashable) ta_rule ls \n      \\<Rightarrow> ('q,('q,'l) ta_rule ls) hm\" \n  where\n  \"build_rqrm \\<delta> ==\n    ls_iteratei \\<delta> (\\<lambda>_. True)\n      (\\<lambda>r res. \n        foldl (\\<lambda>res q. rqrm_add q r res) res (rhsq r)\n      )\n      (hm_empty ())\n  \"\n\n-- \"Whether the index satisfies the map and set invariants\"\ndefinition \"rqrm_invar rqrm == \n  hm_invar rqrm \\<and> (\\<forall>q. ls_invar (rqrm_lookup rqrm q))\"\n-- \"Whether the index really maps a state to the set of rules with this \n    state on their rhs\"\ndefinition \"rqrm_prop \\<delta> rqrm == \n  \\<forall>q. ls_\\<alpha> (rqrm_lookup rqrm q) = {r\\<in>\\<delta>. q\\<in>set (rhsq r)}\"\n\nlemma rqrm_\\<alpha>_lookup_update[simp]: \n  \"rqrm_invar rqrm \\<Longrightarrow> \n    ls_\\<alpha> (rqrm_lookup (rqrm_add q r rqrm) q') \n    = ( if q=q' then \n          insert r (ls_\\<alpha> (rqrm_lookup rqrm q')) \n        else \n          ls_\\<alpha> (rqrm_lookup rqrm q')\n      )\"\n  by (simp \n    add: rqrm_lookup_def rqrm_add_def rqrm_invar_def hm.correct \n         ls.correct \n    split: option.split_asm option.split)\n\nlemma rqrm_propD: \n  \"rqrm_prop \\<delta> rqrm \\<Longrightarrow> ls_\\<alpha> (rqrm_lookup rqrm q) = {r\\<in>\\<delta>. q\\<in>set (rhsq r)}\"\n  by (simp add: rqrm_prop_def)\n\nlemma build_rqrm_correct:\n  fixes \\<delta>\n  assumes [simp]: \"ls_invar \\<delta>\"\n  shows \"rqrm_invar (build_rqrm \\<delta>)\" (is ?T1) and\n        \"rqrm_prop (ls_\\<alpha> \\<delta>) (build_rqrm \\<delta>)\" (is ?T2)\nproof -\n  have \"rqrm_invar (build_rqrm \\<delta>) \\<and> \n    (\\<forall>q. ls_\\<alpha> (rqrm_lookup (build_rqrm \\<delta>) q) = {r\\<in>ls_\\<alpha> \\<delta>. q\\<in>set (rhsq r)})\"\n    apply (unfold build_rqrm_def)\n    apply (rule_tac \n      I=\"\\<lambda>it res. (rqrm_invar res) \n                  \\<and> (\\<forall>q. ls_\\<alpha> (rqrm_lookup res q) \n                     = {r\\<in>ls_\\<alpha> \\<delta> - it. q\\<in>set (rhsq r)})\" \n      in ls.iterate_rule_P)\n      -- \"Invar\"\n    apply simp\n      -- \"Initial\"\n    apply (simp add: hm_correct ls_correct rqrm_lookup_def rqrm_invar_def)\n      -- \"Step\"\n    apply (rule_tac \n      I=\"\\<lambda>res itl itr. \n        (rqrm_invar res) \n        \\<and> (\\<forall>q. ls_\\<alpha> (rqrm_lookup res q) \n           = {r\\<in>ls_\\<alpha> \\<delta> - it. q\\<in>set (rhsq r)} \n             \\<union> {r. r=x \\<and> q\\<in>set itl})\" \n      in Misc.foldl_rule_P)\n        -- \"Initial\"\n      apply simp\n        -- \"Step\"\n      apply (intro conjI)\n      apply (simp \n        add: rqrm_invar_def rqrm_add_def rqrm_lookup_def hm_correct \n             ls_correct \n        split: option.split option.split_asm)\n      apply simp\n      apply (simp \n        add: rqrm_add_def rqrm_lookup_def hm_correct ls_correct \n        split: option.split option.split_asm)\n      apply (auto) [1]\n        -- \"Final\"\n      apply auto [1]\n      -- \"Final\"\n    apply simp\n    done\n  thus ?T1 ?T2 by (simp_all add: rqrm_prop_def)\nqed\n\n-- {* \n    A state of the basic algorithm contains a set of discovered states, \n    a worklist and a map from rules to the number of distinct states on \n    its RHS that have not yet been discovered or are still on the worklist\n*}\ntype_synonym ('Q,'L) brc_state \n  = \"'Q hs \\<times> 'Q list \\<times> (('Q,'L) ta_rule, nat) hm\"\n\n-- {* Abstraction to @{text \\<alpha>'}-level: *}\ndefinition brc_\\<alpha> \n  :: \"('Q::hashable,'L::hashable) brc_state \\<Rightarrow> ('Q,'L) br'_state\"\n  where \"brc_\\<alpha> == \\<lambda>(Q,W,rcm). (hs_\\<alpha> Q, set W, hm_\\<alpha> rcm)\"\n\ndefinition brc_invar_add :: \"('Q::hashable,'L::hashable) brc_state set\" \n  where\n  \"brc_invar_add == {(Q,W,rcm). \n    hs_invar Q \\<and> \n    distinct W \\<and> \n    hm_invar rcm\n    (*\\<and> set W \\<subseteq> hs_\\<alpha> Q *)}\n  \"\n\ndefinition \"brc_invar \\<delta> == brc_invar_add \\<inter> {s. brc_\\<alpha> s \\<in> br'_invar \\<delta>}\"\n\ndefinition brc_cond :: \"('q::hashable,'l::hashable) brc_state \\<Rightarrow> bool\" \n  where \"brc_cond == \\<lambda>(Q,W,rcm). W\\<noteq>[]\"\n\ndefinition brc_inner_step \n  :: \"('q,'l) ta_rule \\<Rightarrow> ('q::hashable,'l::hashable) brc_state \n      \\<Rightarrow> ('q,'l) brc_state\"\n  where \n  \"brc_inner_step r == \\<lambda>(Q,W,rcm). \n    let c=the (hm_lookup r rcm);\n        rcm' = hm_update r (c-(1::nat)) rcm;\n        Q' = (if c \\<le> 1 then hs_ins (lhs r) Q else Q);\n        W' = (if c \\<le> 1 \\<and> \\<not> hs_memb (lhs r) Q then lhs r # W else W) in\n      (Q',W',rcm')\"\n\ndefinition brc_step \n  :: \"('q,('q,'l) ta_rule ls) hm \n      \\<Rightarrow> ('q::hashable,'l::hashable) brc_state \n      \\<Rightarrow> ('q,'l) brc_state\" \nwhere \n  \"brc_step rqrm == \\<lambda>(Q,W,rcm).\n    ls_iteratei (rqrm_lookup rqrm (hd W)) (\\<lambda>_. True) brc_inner_step \n      (Q,tl W, rcm)\"\n\n  -- \"Initial concrete state\"\ndefinition brc_iq :: \"('q,'l) ta_rule ls \\<Rightarrow> 'q::hashable hs\" \n  where \"brc_iq \\<delta> == lh_set_xy.g_image_filter (\\<lambda>r. \n    if rhsq r = [] then Some (lhs r) else None) \\<delta>\"\n\ndefinition brc_rcm_init \n  :: \"('q::hashable,'l::hashable) ta_rule ls \n      \\<Rightarrow> (('q,'l) ta_rule,nat) hm\" \n  where \"brc_rcm_init \\<delta> == \n    ls_iteratei \\<delta> (\\<lambda>_. True) \n      (\\<lambda>r res. hm_update r ((length (remdups (rhsq r)))) res) \n      (hm_empty ())\"\n\ndefinition brc_initial \n  :: \"('q::hashable,'l::hashable) ta_rule ls \\<Rightarrow> ('q,'l) brc_state\" \n  where \"brc_initial \\<delta> == \n    let iq=brc_iq \\<delta> in \n      (iq, hs_to_list (iq), brc_rcm_init \\<delta>)\"\n\ndefinition \"brc_det_algo rqrm \\<delta> == \\<lparr>\n  dwa_cond = brc_cond,\n  dwa_step = brc_step rqrm,\n  dwa_initial = brc_initial \\<delta>,\n  dwa_invar = brc_invar (ls_\\<alpha> \\<delta>)\n\\<rparr>\"\n\n  -- \"Additional facts needed from the abstract level\"\nlemma brc_inv_imp_WssQ: \"brc_\\<alpha> (Q,W,rcm)\\<in>br'_invar \\<delta> \\<Longrightarrow> set W \\<subseteq> hs_\\<alpha> Q\"\n  by (auto simp add: brc_\\<alpha>_def br'_invar_def br'_\\<alpha>_def br_invar_def)\n\nlemma brc_iq_correct: \n  assumes [simp]: \"ls_invar \\<delta>\"\n  shows \"hs_invar (brc_iq \\<delta>)\"\n        \"hs_\\<alpha> (brc_iq \\<delta>) = br_iq (ls_\\<alpha> \\<delta>)\"\n  by (auto simp add: brc_iq_def br_iq_def lh_set_xy.image_filter_correct)\n\nlemma brc_rcm_init_correct:\n  assumes INV[simp]: \"ls_invar \\<delta>\"\n  shows \"r\\<in>ls_\\<alpha> \\<delta> \n    \\<Longrightarrow> hm_\\<alpha> (brc_rcm_init \\<delta>) r = Some ((card (set (rhsq r))))\" \n  (is \"_ \\<Longrightarrow> ?T1 r\") and\n    \"hm_invar (brc_rcm_init \\<delta>)\" (is ?T2)\nproof -\n  have G: \"(\\<forall>r\\<in>ls_\\<alpha> \\<delta>. ?T1 r) \\<and> ?T2\"\n    apply (unfold brc_rcm_init_def)\n    apply (rule_tac \n      I=\"\\<lambda>it res. hm_invar res \n           \\<and> (\\<forall>r\\<in>ls_\\<alpha> \\<delta> - it. hm_\\<alpha> res r = Some ((card (set (rhsq r)))))\" \n      in ls.iterate_rule_P)\n      -- \"Invar\"\n    apply simp\n      -- \"Init\"\n    apply (auto simp add: hm_correct) [1]\n      -- \"Step\"\n    apply (rule conjI)\n      apply (simp add: hm.update_correct)\n\n      apply (simp only: hm_correct hs_correct INV)\n      apply (rule ballI)\n      apply (case_tac \"r=x\")\n      apply (auto \n        simp add: length_remdups_card \n        intro!: arg_cong[where f=card]) [1]\n      apply simp\n      -- \"Final\"\n    apply simp\n    done\n  from G show ?T2 by auto\n  fix r\n  assume \"r\\<in>ls_\\<alpha> \\<delta>\"\n  thus \"?T1 r\" using G by auto\nqed\n\nlemma brc_inner_step_br'_desc: \n  \"\\<lbrakk> (Q,W,rcm)\\<in>brc_invar \\<delta> \\<rbrakk> \\<Longrightarrow> brc_\\<alpha> (brc_inner_step r (Q,W,rcm)) = (\n    if the (hm_\\<alpha> rcm r) \\<le> 1 then \n      insert (lhs r) (hs_\\<alpha> Q) \n    else hs_\\<alpha> Q, \n    if the (hm_\\<alpha> rcm r) \\<le> 1 \\<and> (lhs r) \\<notin> hs_\\<alpha> Q then \n      insert (lhs r) (set W) \n    else (set W), \n    ((hm_\\<alpha> rcm)(r \\<mapsto> the (hm_\\<alpha> rcm r) - 1))\n  )\"\n  by (simp \n    add: brc_invar_def brc_invar_add_def brc_\\<alpha>_def brc_inner_step_def Let_def \n         hs_correct hm_correct)\n\nlemma brc_step_invar:\n  assumes RQRM: \"rqrm_invar rqrm\"\n  shows \"\\<lbrakk> \\<Sigma>\\<in>brc_invar_add; brc_\\<alpha> \\<Sigma>\\<in>br'_invar \\<delta>; brc_cond \\<Sigma> \\<rbrakk> \n         \\<Longrightarrow> (brc_step rqrm \\<Sigma>)\\<in>brc_invar_add\"\n  apply (cases \\<Sigma>)\n  apply (simp add: brc_step_def)\n  apply (rule_tac I=\"\\<lambda>it (Q,W,rcm). (Q,W,rcm)\\<in>brc_invar_add \\<and> set W \\<subseteq> hs_\\<alpha> Q\" \n                  in ls.iterate_rule_P)\n  apply (simp add: RQRM[unfolded rqrm_invar_def])\n  apply (case_tac b)\n  apply (simp add: brc_invar_add_def distinct_tl brc_cond_def)\n  apply (auto simp add: brc_invar_add_def distinct_tl brc_cond_def \n              dest!: brc_inv_imp_WssQ) [1]\n  apply (case_tac \\<sigma>)\n  apply (auto simp add: brc_invar_add_def br_invar_def brc_inner_step_def \n                        Let_def hs_correct hm_correct) [1]\n  apply (case_tac \\<sigma>)\n  apply simp\n  done\n\n\nlemma brc_step_abs:\n  assumes RQRM: \"rqrm_invar rqrm\" \"rqrm_prop \\<delta> rqrm\"\n  assumes A: \"\\<Sigma>\\<in>brc_invar \\<delta>\" \"brc_cond \\<Sigma>\"  \n  shows \"(brc_\\<alpha> \\<Sigma>, brc_\\<alpha> (brc_step rqrm \\<Sigma>)) \\<in> br'_step \\<delta>\"\nproof -\n  obtain Q W rcm where [simp]: \"\\<Sigma>=(Q,W,rcm)\" by (cases \\<Sigma>) auto\n  from A show ?thesis\n    apply (simp add: brc_step_def)\n    apply (rule \n      br'_inner_step_proof[OF ls.v1_iteratei_impl, \n         where cinvar=\"\\<lambda>it (Q,W,rcm). (Q,W,rcm)\\<in>brc_invar_add \n                                      \\<and> set W \\<subseteq> hs_\\<alpha> Q\" and \n               q=\"hd W\"])\n    apply (case_tac W) \n    apply (auto simp add: brc_cond_def brc_invar_add_def brc_invar_def \n                dest!: brc_inv_imp_WssQ) [2]\n    prefer 6\n    apply (simp add: brc_\\<alpha>_def)\n    apply (case_tac \\<Sigma>)\n    apply (auto \n      simp add: brc_invar_def brc_invar_add_def brc_inner_step_def \n                Let_def hm_correct hs_correct) [1]\n    apply (auto \n      simp add: brc_invar_add_def brc_inner_step_def brc_\\<alpha>_def \n                br'_inner_step_def Let_def hm_correct hs_correct) [1]\n    apply (simp add: RQRM[unfolded rqrm_invar_def])\n    apply (simp add: rqrm_propD[OF RQRM(2)])\n    apply (case_tac W)\n    apply (simp_all add: brc_\\<alpha>_def brc_cond_def brc_invar_def) [2]\n    apply (case_tac W)\n    apply (simp_all add: brc_\\<alpha>_def brc_cond_def brc_invar_def \n                         brc_invar_add_def) [2]\n    done\nqed\n    \nlemma brc_initial_invar: \"ls_invar \\<delta> \\<Longrightarrow> (brc_initial \\<delta>)\\<in>brc_invar_add\"\n  by (simp \n    add: brc_invar_add_def brc_initial_def brc_iq_correct Let_def \n         brc_rcm_init_correct hs_correct)\n\nlemma brc_cond_abs: \"brc_cond \\<Sigma> \\<longleftrightarrow> (brc_\\<alpha> \\<Sigma>)\\<in>br'_cond\"\n  apply (cases \\<Sigma>)\n  apply (simp add: brc_cond_def br'_cond_def brc_\\<alpha>_def)\n  done\n\nlemma brc_initial_abs: \n  \"ls_invar \\<delta> \\<Longrightarrow> brc_\\<alpha> (brc_initial \\<delta>) \\<in> br'_initial (ls_\\<alpha> \\<delta>)\"\n  by (auto \n    simp add: brc_initial_def Let_def brc_\\<alpha>_def brc_iq_correct \n              brc_rcm_init_correct hs_correct \n    intro: br'_initial.intros)\n\nlemma brc_pref_br':\n  assumes RQRM[simp]: \"rqrm_invar rqrm\" \"rqrm_prop (ls_\\<alpha> \\<delta>) rqrm\"\n  assumes INV[simp]: \"ls_invar \\<delta>\"\n  shows \"wa_precise_refine (det_wa_wa (brc_det_algo rqrm \\<delta>)) \n                           (br'_algo (ls_\\<alpha> \\<delta>)) \n                           brc_\\<alpha>\"\n  apply (unfold_locales)\n  apply (simp_all add: brc_det_algo_def br'_algo_def det_wa_wa_def)\n  apply (simp add: brc_cond_abs)\n  apply (auto simp add: brc_step_abs[OF RQRM]) [1]\n  apply (simp add: brc_initial_abs)\n  apply (auto simp add: brc_invar_def) [1]\n  apply (simp add: brc_cond_abs)\n  done\n\nlemma brc_while_algo:\n  assumes RQRM[simp]: \"rqrm_invar rqrm\" \"rqrm_prop (ls_\\<alpha> \\<delta>) rqrm\"\n  assumes INV[simp]: \"ls_invar \\<delta>\"\n  shows \"while_algo (det_wa_wa (brc_det_algo rqrm \\<delta>))\"\nproof -\n  from brc_pref_br'[OF RQRM INV] interpret \n    ref: wa_precise_refine \"(det_wa_wa (brc_det_algo rqrm \\<delta>))\" \n                           \"(br'_algo (ls_\\<alpha> \\<delta>))\" \n                           brc_\\<alpha> .\n  show ?thesis\n    apply (rule ref.wa_intro)\n    apply (simp add: br'_while_algo)\n    apply (simp_all add: det_wa_wa_def brc_det_algo_def br'_algo_def)\n    apply (simp add: brc_invar_def)\n    apply (auto simp add: brc_step_invar) [1]\n    apply (simp add: brc_initial_invar)\n    done\nqed\n\nlemmas brc_det_while_algo =\n  det_while_algo_intro[OF brc_while_algo]\n\n\nlemma fst_brc_\\<alpha>: \"fst (brc_\\<alpha> s) = hs_\\<alpha> (fst s)\" \n  by (cases s) (simp add: brc_\\<alpha>_def)\n\nlemmas brc_invar_final =\n  wa_precise_refine.transfer_correctness[OF \n    brc_pref_br' br'_invar_final, unfolded fst_brc_\\<alpha>]\n\ndefinition \"hta_bwd_reduce H == \n  let rqrm = build_rqrm (hta_\\<delta> H) in \n    hta_reduce \n      H \n      (fst (while brc_cond (brc_step rqrm) (brc_initial (hta_\\<delta> H))))\n\"\n\ntheorem (in hashedTa) hta_bwd_reduce_correct:\n  shows \"hta_\\<alpha> (hta_bwd_reduce H) \n         = ta_reduce (hta_\\<alpha> H) (b_accessible (ls_\\<alpha> (hta_\\<delta> H)))\" (is ?T1)\n        \"hashedTa (hta_bwd_reduce H)\" (is ?T2)\nproof -\n  interpret det_while_algo \"(brc_det_algo (build_rqrm \\<delta>) \\<delta>)\"\n    by (rule brc_det_while_algo)\n       (simp_all add: build_rqrm_correct)\n\n  have LC: \"(while brc_cond (brc_step (build_rqrm \\<delta>)) (brc_initial \\<delta>)) = loop\"\n    by (unfold loop_def)\n       (simp add: brc_det_algo_def)\n\n  from while_proof'[OF brc_invar_final] have \n    G1: \"hs_\\<alpha> (fst loop) = b_accessible (ls_\\<alpha> \\<delta>)\" \n    by (simp add: build_rqrm_correct)\n  have G2: \"loop \\<in> brc_invar (ls_\\<alpha> \\<delta>)\"\n    by (rule while_proof)\n       (simp add: brc_det_algo_def)\n  hence [simp]: \"hs_invar (fst loop)\"\n    by (cases loop)\n       (simp add: brc_invar_def brc_invar_add_def)\n\n  show ?T1 ?T2\n    by (simp_all add: hta_bwd_reduce_def LC hta_reduce_correct G1)\n    \nqed\n\nsubsubsection {* Emptiness Check with Witness Computation *}\n\ndefinition brec_construct_witness \n  :: \"('q::hashable,'l::hashable tree) hm \\<Rightarrow> ('q,'l) ta_rule \\<Rightarrow> 'l tree\"\n  where \"brec_construct_witness Qm r == \n  NODE (rhsl r) (List.map (\\<lambda>q. the (hm_lookup q Qm)) (rhsq r))\"\n\nlemma brec_construct_witness_correct: \n  \"\\<lbrakk>hm_invar Qm\\<rbrakk> \\<Longrightarrow> \n    brec_construct_witness Qm r = construct_witness (hm_\\<alpha> Qm) r\"\n  by (auto \n    simp add: construct_witness_def brec_construct_witness_def hm_correct)\n\ntype_synonym ('Q,'L) brec_state \n  = \"(('Q,'L tree) hm \n      \\<times> 'Q fifo \n      \\<times> (('Q,'L) ta_rule, nat) hm \n      \\<times> 'Q option)\"\n\n\n  -- \"Abstractions\"\ndefinition brec_\\<alpha> \n  :: \"('Q::hashable,'L::hashable) brec_state \\<Rightarrow> ('Q,'L) brw_state\"\n  where \"brec_\\<alpha> == \\<lambda>(Q,W,rcm,f). (hm_\\<alpha> Q, set (fifo_\\<alpha> W), (hm_\\<alpha> rcm))\"\n\ndefinition brec_inner_step \n  :: \"'q hs \\<Rightarrow> ('q,'l) ta_rule \n      \\<Rightarrow> ('q::hashable,'l::hashable) brec_state \n      \\<Rightarrow> ('q,'l) brec_state\"\n  where \"brec_inner_step Qi r == \\<lambda>(Q,W,rcm,qwit). \n    let c=the (hm_lookup r rcm); \n        cond = c \\<le> 1 \\<and> hm_lookup (lhs r) Q = None;\n        rcm' = hm_update r (c-(1::nat)) rcm;\n        Q' = ( if cond then \n                 hm_update (lhs r) (brec_construct_witness Q r) Q \n               else Q);\n        W' = (if cond then fifo_enqueue (lhs r) W else W);\n        qwit' = (if c \\<le> 1 \\<and> hs_memb (lhs r) Qi then Some (lhs r) else qwit)\n    in\n      (Q',W',rcm',qwit')\"\n\ndefinition brec_step \n  :: \"('q,('q,'l) ta_rule ls) hm \\<Rightarrow> 'q hs \n      \\<Rightarrow> ('q::hashable,'l::hashable) brec_state \n      \\<Rightarrow> ('q,'l) brec_state\" \n  where \"brec_step rqrm Qi == \\<lambda>(Q,W,rcm,qwit).\n    let (q,W')=fifo_dequeue W in \n      ls_iteratei (rqrm_lookup rqrm q) (\\<lambda>_. True) \n        (brec_inner_step Qi) (Q,W',rcm,qwit)\n  \"\n\ndefinition brec_iqm \n  :: \"('q::hashable,'l::hashable) ta_rule ls \\<Rightarrow> ('q,'l tree) hm\" \n  where \"brec_iqm \\<delta> == \n    ls_iteratei \\<delta> (\\<lambda>_. True) (\\<lambda>r m. if rhsq r = [] then \n                         hm_update (lhs r) (NODE (rhsl r) []) m \n                      else m) \n                (hm_empty ())\"\n\ndefinition brec_initial \n  :: \"'q hs \\<Rightarrow> ('q::hashable,'l::hashable) ta_rule ls \n      \\<Rightarrow> ('q,'l) brec_state\" \n  where \"brec_initial Qi \\<delta> == \n  let iq=brc_iq \\<delta> in \n    ( brec_iqm \\<delta>, \n      hs_to_fifo.g_set_to_listr iq, \n      brc_rcm_init \\<delta>,\n      hh_set_xx.g_disjoint_witness iq Qi)\"\n\ndefinition brec_cond \n  :: \"('q,'l) brec_state \\<Rightarrow> bool\" \n  where \"brec_cond == \\<lambda>(Q,W,rcm,qwit). \\<not> fifo_isEmpty W \\<and> qwit = None\"\n\ndefinition brec_invar_add\n  :: \"'Q set \\<Rightarrow> ('Q::hashable,'L::hashable) brec_state set\" \n  where\n  \"brec_invar_add Qi == {(Q,W,rcm,qwit). \n    hm_invar Q \\<and> \n    distinct (fifo_\\<alpha> W) \\<and> \n    hm_invar rcm \\<and>\n    ( case qwit of \n        None \\<Rightarrow> Qi \\<inter> dom (hm_\\<alpha> Q) = {} | \n        Some q \\<Rightarrow> q\\<in>Qi \\<inter> dom (hm_\\<alpha> Q))}\n  \"\n\ndefinition \"brec_invar Qi \\<delta> == brec_invar_add Qi \\<inter> {s. brec_\\<alpha> s \\<in> brw_invar \\<delta>}\"\n\ndefinition \"brec_invar_inner Qi == \n  brec_invar_add Qi \\<inter> {(Q,W,_,_). set (fifo_\\<alpha> W) \\<subseteq> dom (hm_\\<alpha> Q)}\"\n\nlemma brec_invar_cons: \n  \"\\<Sigma>\\<in>brec_invar Qi \\<delta> \\<Longrightarrow> \\<Sigma>\\<in>brec_invar_inner Qi\"\n  apply (cases \\<Sigma>)\n  apply (simp add: brec_invar_def brw_invar_def br'_invar_def br_invar_def\n                   brec_\\<alpha>_def brw_\\<alpha>_def br'_\\<alpha>_def brec_invar_inner_def)\n  done\n\nlemma brec_brw_invar_cons: \n  \"brec_\\<alpha> \\<Sigma> \\<in> brw_invar Qi \\<Longrightarrow> set (fifo_\\<alpha> (fst (snd \\<Sigma>))) \\<subseteq> dom (hm_\\<alpha> (fst \\<Sigma>))\"\n  apply (cases \\<Sigma>)\n  apply (simp add: brec_invar_def brw_invar_def br'_invar_def br_invar_def\n                   brec_\\<alpha>_def brw_\\<alpha>_def br'_\\<alpha>_def)\n  done\n\ndefinition \"brec_det_algo rqrm Qi \\<delta> == \\<lparr>\n  dwa_cond=brec_cond,\n  dwa_step=brec_step rqrm Qi,\n  dwa_initial=brec_initial Qi \\<delta>,\n  dwa_invar=brec_invar (hs_\\<alpha> Qi) (ls_\\<alpha> \\<delta>)\n\\<rparr>\"\n\nlemma brec_iqm_correct':\n  assumes INV[simp]: \"ls_invar \\<delta>\"\n  shows \n    \"dom (hm_\\<alpha> (brec_iqm \\<delta>)) = {lhs r | r. r\\<in>ls_\\<alpha> \\<delta> \\<and> rhsq r = []}\" (is ?T1)\n    \"witness_prop (ls_\\<alpha> \\<delta>) (hm_\\<alpha> (brec_iqm \\<delta>))\" (is ?T2)\n    \"hm_invar (brec_iqm \\<delta>)\" (is ?T3)\nproof -\n  have \"?T1 \\<and> ?T2 \\<and> ?T3\"\n    apply (unfold brec_iqm_def)\n    apply (rule_tac \n      I=\"\\<lambda>it m. hm_invar m \n                \\<and> dom (hm_\\<alpha> m) = {lhs r | r. r\\<in>ls_\\<alpha> \\<delta> - it \\<and> rhsq r = []} \n                \\<and> witness_prop (ls_\\<alpha> \\<delta>) (hm_\\<alpha> m)\" \n      in ls.iterate_rule_P)\n    apply simp\n    apply (auto simp add: hm_correct witness_prop_def) [1]\n    apply (auto simp add: hm_correct witness_prop_def) [1]\n    apply (case_tac x)\n    apply (auto intro: accs.intros) [1]\n    apply simp\n    done\n  thus ?T1 ?T2 ?T3 by auto\nqed\n\nlemma brec_iqm_correct:\n  assumes INV[simp]: \"ls_invar \\<delta>\"\n  shows \"hm_\\<alpha> (brec_iqm \\<delta>) \\<in> brw_iq (ls_\\<alpha> \\<delta>)\"\nproof -\n  have \"(\\<forall>q t. hm_\\<alpha> (brec_iqm \\<delta>) q = Some t \n          \\<longrightarrow> (\\<exists>r\\<in>ls_\\<alpha> \\<delta>. rhsq r = [] \\<and> q = lhs r \\<and> t = NODE (rhsl r) [])) \n        \\<and> (\\<forall>r\\<in>ls_\\<alpha> \\<delta>. rhsq r = [] \\<longrightarrow> hm_\\<alpha> (brec_iqm \\<delta>) (lhs r) \\<noteq> None)\" \n    apply (unfold brec_iqm_def)\n    apply (rule_tac I=\"\\<lambda>it m. (\n      (hm_invar m) \\<and> \n      (\\<forall>q t. hm_\\<alpha> m q = Some t \n        \\<longrightarrow> (\\<exists>r\\<in>ls_\\<alpha> \\<delta>. rhsq r = [] \\<and> q = lhs r \\<and> t = NODE (rhsl r) [])) \\<and> \n      (\\<forall>r\\<in>ls_\\<alpha> \\<delta>-it. rhsq r = [] \\<longrightarrow> hm_\\<alpha> m (lhs r) \\<noteq> None)\n      )\" \n      in ls.iterate_rule_P)\n    apply simp\n    apply (simp add: hm_correct)\n    apply (auto simp add: hm_correct) [1]\n    apply (auto simp add: hm_correct) [1]\n    done\n  thus ?thesis by (blast intro: brw_iq.intros)\nqed\n\nlemma brec_inner_step_brw_desc: \n  \"\\<lbrakk> \\<Sigma>\\<in>brec_invar_inner (hs_\\<alpha> Qi) \\<rbrakk> \n    \\<Longrightarrow> (brec_\\<alpha> \\<Sigma>, brec_\\<alpha> (brec_inner_step Qi r \\<Sigma>)) \\<in> brw_inner_step r\"\n  apply (cases \\<Sigma>)\n  apply (rule brw_inner_step.intros)\n  apply (simp only: )\n  apply (simp only: brec_\\<alpha>_def split_conv)\n  apply (simp only: brec_inner_step_def brec_\\<alpha>_def Let_def split_conv)\n  apply (auto \n    simp add: brec_invar_inner_def brec_invar_add_def brec_\\<alpha>_def \n              brec_inner_step_def \n              Let_def hs_correct hm_correct fifo_correct\n              brec_construct_witness_correct)\n  done\n\n\nlemma brec_step_invar:\n  assumes RQRM: \"rqrm_invar rqrm\" \"rqrm_prop \\<delta> rqrm\"\n  assumes [simp]: \"hs_invar Qi\"\n  shows \"\\<lbrakk> \\<Sigma>\\<in>brec_invar_add (hs_\\<alpha> Qi); brec_\\<alpha> \\<Sigma> \\<in> brw_invar \\<delta>;  brec_cond \\<Sigma> \\<rbrakk> \n          \\<Longrightarrow> (brec_step rqrm Qi \\<Sigma>)\\<in>brec_invar_add (hs_\\<alpha> Qi)\"\n  apply (frule brec_brw_invar_cons)\n  apply (cases \\<Sigma>)\n  apply (simp add: brec_step_def fifo_correct)\n  apply (case_tac \"fifo_\\<alpha> b\")\n  apply (simp \n    add: brec_invar_def distinct_tl brec_cond_def fifo_correct\n         )\n  apply (rule_tac s=b in fifo.removelE)\n  apply simp\n  apply simp\n  apply simp\n\n  apply (rule_tac \n    I=\"\\<lambda>it (Q,W,rcm,qwit). (Q,W,rcm,qwit)\\<in>brec_invar_add (hs_\\<alpha> Qi) \n                           \\<and> set (fifo_\\<alpha> W) \\<subseteq> dom (hm_\\<alpha> Q)\" \n    in ls.iterate_rule_P)\n  apply simp\n  apply (simp \n    add: brec_invar_def distinct_tl brec_cond_def fifo_correct\n         )\n  apply (simp \n    add: brec_invar_def brec_invar_add_def distinct_tl brec_cond_def \n         fifo_correct)\n  apply (case_tac \\<sigma>)\n  apply (auto \n    simp add: brec_invar_add_def brec_inner_step_def Let_def hs_correct \n              hm_correct fifo_correct split: option.split_asm) [1]\n  apply (case_tac \\<sigma>)\n  apply simp\n  done\n\nlemma brec_step_abs:\n  assumes RQRM: \"rqrm_invar rqrm\" \"rqrm_prop \\<delta> rqrm\"\n  assumes INV[simp]: \"hs_invar Qi\"\n  assumes A': \"\\<Sigma>\\<in>brec_invar (hs_\\<alpha> Qi) \\<delta>\"\n  assumes COND: \"brec_cond \\<Sigma>\"\n  shows \"(brec_\\<alpha> \\<Sigma>, brec_\\<alpha> (brec_step rqrm Qi \\<Sigma>)) \\<in> brw_step \\<delta>\"\nproof -\n  from A' have A: \"(brec_\\<alpha> \\<Sigma>)\\<in>brw_invar \\<delta>\" \"\\<Sigma>\\<in>brec_invar_add (hs_\\<alpha> Qi)\"\n    by (simp_all add: brec_invar_def)\n\n  obtain Q W rcm qwit where [simp]: \"\\<Sigma>=(Q,W,rcm,qwit)\" by (cases \\<Sigma>) blast\n  from A COND show ?thesis\n    apply (simp add: brec_step_def fifo_correct)\n    apply (case_tac \"fifo_\\<alpha> W\")\n    apply (simp \n      add: brec_invar_def distinct_tl brec_cond_def fifo_correct\n    )\n    apply (rule_tac s=W in fifo.removelE)\n    apply simp\n    apply simp\n    apply simp\n\n    apply (rule brw_inner_step_proof[\n      OF ls.v1_iteratei_impl, \n      where cinvar=\"\\<lambda>it \\<Sigma>. \\<Sigma>\\<in>brec_invar_inner (hs_\\<alpha> Qi)\" and \n            q=\"hd (fifo_\\<alpha> W)\"])\n    apply assumption\n    apply (frule brec_brw_invar_cons)\n    apply (simp_all \n      add: brec_cond_def brec_invar_add_def fifo_correct\n            brec_invar_inner_def) [1]\n    prefer 6\n    apply (simp add: brec_\\<alpha>_def)\n    apply (case_tac \\<Sigma>)\n    apply (auto \n      simp add: brec_invar_add_def brec_inner_step_def Let_def hm_correct \n                hs_correct fifo_correct brec_invar_inner_def \n      split: option.split_asm) [1]\n    apply (blast intro: brec_inner_step_brw_desc)\n    apply (simp add: RQRM[unfolded rqrm_invar_def])\n    apply (simp \n      add: rqrm_propD[OF RQRM(2)] fifo_correct)\n    apply (simp_all \n      add: brec_\\<alpha>_def brec_cond_def brec_invar_def fifo_correct) [1]\n    apply (simp_all \n      add: brec_\\<alpha>_def brec_cond_def brec_invar_add_def fifo_correct) [1]\n    done\nqed\n    \nlemma brec_invar_initial: \n  \"\\<lbrakk>ls_invar \\<delta>; hs_invar Qi\\<rbrakk> \\<Longrightarrow> (brec_initial Qi \\<delta>) \\<in> brec_invar_add (hs_\\<alpha> Qi)\"\n  apply (auto \n    simp add: brec_invar_add_def brec_initial_def brc_iq_correct \n              brec_iqm_correct' hs_correct hs.isEmpty_correct Let_def \n              brc_rcm_init_correct br_iq_def \n              hh_set_xx.disjoint_witness_correct \n              hs_to_fifo.g_set_to_listr_correct \n    split: option.split)\n  apply (auto simp add: brc_iq_correct \n    hh_set_xx.disjoint_witness_None br_iq_def) [1]\n\n  apply (drule hh_set_xx.disjoint_witness_correct[simplified])\n  apply simp\n\n  apply (drule hh_set_xx.disjoint_witness_correct[simplified])\n  apply (simp add: brc_iq_correct br_iq_def)\n  done\n\nlemma brec_cond_abs: \n  \"\\<lbrakk>\\<Sigma>\\<in>brec_invar Qi \\<delta>\\<rbrakk> \\<Longrightarrow> brec_cond \\<Sigma> \\<longleftrightarrow> (brec_\\<alpha> \\<Sigma>)\\<in>brw_cond Qi\"\n  apply (cases \\<Sigma>)\n  apply (auto \n    simp add: brec_cond_def brw_cond_def brec_\\<alpha>_def brec_invar_def \n              brec_invar_add_def fifo_correct\n    split: option.split_asm)\n  done\n\nlemma brec_initial_abs: \n  \"\\<lbrakk> ls_invar \\<delta>; hs_invar Qi \\<rbrakk> \n     \\<Longrightarrow> brec_\\<alpha> (brec_initial Qi \\<delta>) \\<in> brw_initial (ls_\\<alpha> \\<delta>)\"\n  by (auto simp add: brec_initial_def Let_def brec_\\<alpha>_def \n                     brc_iq_correct brc_rcm_init_correct brec_iqm_correct \n                     br_iq_def fifo_correct hs_to_fifo.g_set_to_listr_correct \n              intro: brw_initial.intros[unfolded br_iq_def])\n\nlemma brec_pref_brw:\n  assumes RQRM[simp]: \"rqrm_invar rqrm\" \"rqrm_prop (ls_\\<alpha> \\<delta>) rqrm\"\n  assumes INV[simp]: \"ls_invar \\<delta>\" \"hs_invar Qi\"\n  shows \"wa_precise_refine (det_wa_wa (brec_det_algo rqrm Qi \\<delta>)) \n                           (brw_algo (hs_\\<alpha> Qi) (ls_\\<alpha> \\<delta>))  \n                           brec_\\<alpha>\"\n  apply (unfold_locales)\n  apply (simp_all add: det_wa_wa_def brec_det_algo_def brw_algo_def)\n  apply (auto simp add: brec_cond_abs brec_step_abs brec_initial_abs)\n  apply (simp add: brec_invar_def)\n  done\n\nlemma brec_while_algo:\n  assumes RQRM[simp]: \"rqrm_invar rqrm\" \"rqrm_prop (ls_\\<alpha> \\<delta>) rqrm\"\n  assumes INV[simp]: \"ls_invar \\<delta>\" \"hs_invar Qi\"\n  shows \"while_algo (det_wa_wa (brec_det_algo rqrm Qi \\<delta>))\"\nproof -\n  interpret ref: \n    wa_precise_refine \"(det_wa_wa (brec_det_algo rqrm Qi \\<delta>))\" \n                      \"(brw_algo (hs_\\<alpha> Qi) (ls_\\<alpha> \\<delta>))\" \n                      \"brec_\\<alpha>\" \n    using brec_pref_brw[OF RQRM INV] . \n\n  show ?thesis\n    apply (rule ref.wa_intro)\n    apply (simp add: brw_while_algo)\n    apply (simp_all add: det_wa_wa_def brec_det_algo_def brw_algo_def)\n    apply (simp add: brec_invar_def)\n    apply (auto simp add: brec_step_invar[OF RQRM INV(2)]) [1]\n    apply (simp add: brec_invar_initial) [1]\n    done\nqed\n\nlemma fst_brec_\\<alpha>: \"fst (brec_\\<alpha> \\<Sigma>) = hm_\\<alpha> (fst \\<Sigma>)\"\n  by (cases \\<Sigma>) (simp add: brec_\\<alpha>_def)\n\nlemmas brec_invar_final = \n  wa_precise_refine.transfer_correctness[\n    OF brec_pref_brw brw_invar_final, \n    unfolded fst_brec_\\<alpha>]\n\nlemmas brec_det_algo = det_while_algo_intro[OF brec_while_algo]\n\ndefinition \"hta_is_empty_witness H == \n  let rqrm = build_rqrm (hta_\\<delta> H);\n      (Q,_,_,qwit) = (while brec_cond (brec_step rqrm (hta_Qi H)) \n                            (brec_initial (hta_Qi H) (hta_\\<delta> H))) \n  in\n    case qwit of \n      None \\<Rightarrow> None |\n      Some q \\<Rightarrow> (hm_lookup q Q)\n\"\n\ntheorem (in hashedTa) hta_is_empty_witness_correct:\n  shows [rule_format]: \"hta_is_empty_witness H = Some t \n                        \\<longrightarrow> t\\<in>ta_lang (hta_\\<alpha> H)\" (is ?T1)\n        \"hta_is_empty_witness H = None \\<longrightarrow> ta_lang (hta_\\<alpha> H) = {}\" (is ?T2)\nproof -\n\n  interpret det_while_algo \"(brec_det_algo (build_rqrm \\<delta>) Qi \\<delta>)\"\n    by (rule brec_det_algo)\n       (simp_all add: build_rqrm_correct)\n\n  have LC: \n    \"(while brec_cond (brec_step (build_rqrm \\<delta>) Qi) (brec_initial Qi \\<delta>)) = loop\"\n    by (unfold loop_def)\n       (simp add: brec_det_algo_def)\n\n  from while_proof'[OF brec_invar_final] have X:\n    \"hs_\\<alpha> Qi \\<inter> dom (hm_\\<alpha> (fst loop)) = {} \n     \\<longleftrightarrow> (hs_\\<alpha> Qi \\<inter> b_accessible (ls_\\<alpha> \\<delta>) = {})\"\n    \"witness_prop (ls_\\<alpha> \\<delta>) (hm_\\<alpha> (fst loop))\"\n    by (simp_all add: build_rqrm_correct)\n\n  obtain Q W rcm qwit where \n    [simp]: \"loop = (Q,W,rcm,qwit)\" \n    by (case_tac \"loop\") blast\n\n  from loop_invar have I: \"loop \\<in> brec_invar (hs_\\<alpha> Qi) (ls_\\<alpha> \\<delta>)\" \n    by (simp add: brec_det_algo_def)\n  hence INVARS[simp]: \"hm_invar Q\" \"hm_invar rcm\" \n    by (simp_all add: brec_invar_def brec_invar_add_def) \n  \n  {\n    assume C: \"hta_is_empty_witness H = Some t\"\n    then obtain q where \n      [simp]: \"qwit=Some q\" and \n        LUQ: \"hm_lookup q Q = Some t\"\n      by (unfold hta_is_empty_witness_def)\n         (simp add: LC split: option.split_asm)\n    from LUQ have QqF: \"hm_\\<alpha> Q q = Some t\" by (simp add: hm_correct)\n    from I have QMEM: \"q\\<in>hs_\\<alpha> Qi\" \n      by (simp_all add: brec_invar_def brec_invar_add_def)\n    moreover from witness_propD[OF X(2)] QqF have \"accs (ls_\\<alpha> \\<delta>) t q\" by simp\n    ultimately have \"t\\<in>ta_lang (hta_\\<alpha> H)\"\n      by (auto simp add: ta_lang_def hta_\\<alpha>_def)\n  } moreover {\n    assume C: \"hta_is_empty_witness H = None\"\n    hence DJ: \"hs_\\<alpha> Qi \\<inter> dom (hm_\\<alpha> Q) = {}\" using I\n      by (auto simp add: hta_is_empty_witness_def LC brec_invar_def \n                         brec_invar_add_def hm_correct \n               split: option.split_asm)\n    with X have \"hs_\\<alpha> Qi \\<inter> b_accessible (ls_\\<alpha> \\<delta>) = {}\" \n      by (simp add: brec_\\<alpha>_def)\n    with empty_if_no_b_accessible[of \"hta_\\<alpha> H\"] have \"ta_lang (hta_\\<alpha> H) = {}\"\n      by (simp add: hta_\\<alpha>_def)\n  } ultimately show ?T1 ?T2 by auto\nqed\n\nsubsection {* Interface for Natural Number States and Symbols *}\n  text_raw {*\\label{sec:htai_intf}*}\ntext {*\n  The library-interface is statically instantiated to use natural numbers \n  as both, states and symbols.\n\n  This interface is easier to use from ML and OCaml, because there is no \n  overhead with typeclass emulation.\n*}\n\ntype_synonym htai = \"(nat,nat) hashedTa\"\n\ndefinition htai_mem :: \"_ \\<Rightarrow> htai \\<Rightarrow> bool\" \n  where \"htai_mem == hta_mem\"\ndefinition htai_prod :: \"htai \\<Rightarrow> htai \\<Rightarrow> htai\" \n  where \"htai_prod H1 H2 == hta_reindex (hta_prod H1 H2)\"\ndefinition htai_prodWR :: \"htai \\<Rightarrow> htai \\<Rightarrow> htai\" \n  where \"htai_prodWR H1 H2 == hta_reindex (hta_prodWR H1 H2)\"\ndefinition htai_union :: \"htai \\<Rightarrow> htai \\<Rightarrow> htai\" \n  where \"htai_union H1 H2 == hta_reindex (hta_union H1 H2)\"\ndefinition htai_empty :: \"unit \\<Rightarrow> htai\"\n  where \"htai_empty == hta_empty\"\ndefinition htai_add_qi :: \"_ \\<Rightarrow> htai \\<Rightarrow> htai\" \n  where \"htai_add_qi == hta_add_qi\"\ndefinition htai_add_rule :: \"_ \\<Rightarrow> htai \\<Rightarrow> htai\" \n  where \"htai_add_rule == hta_add_rule\"\ndefinition htai_bwd_reduce :: \"htai \\<Rightarrow> htai\" \n  where \"htai_bwd_reduce == hta_bwd_reduce\"\ndefinition htai_is_empty_witness :: \"htai \\<Rightarrow> _\" \n  where \"htai_is_empty_witness == hta_is_empty_witness\"\ndefinition htai_ensure_idx_f :: \"htai \\<Rightarrow> htai\" \n  where \"htai_ensure_idx_f == hta_ensure_idx_f\"\ndefinition htai_ensure_idx_s :: \"htai \\<Rightarrow> htai\" \n  where \"htai_ensure_idx_s == hta_ensure_idx_s\"\ndefinition htai_ensure_idx_sf :: \"htai \\<Rightarrow> htai\" \n  where \"htai_ensure_idx_sf == hta_ensure_idx_sf\"\n\ndefinition htaip_prod :: \"htai \\<Rightarrow> htai \\<Rightarrow> (nat * nat,nat) hashedTa\" \n  where \"htaip_prod == hta_prod\"\ndefinition htaip_prodWR :: \"htai \\<Rightarrow> htai \\<Rightarrow> (nat * nat,nat) hashedTa\" \n  where \"htaip_prodWR == hta_prodWR\"\ndefinition htaip_reindex :: \"(nat * nat,nat) hashedTa \\<Rightarrow> htai\" \n  where \"htaip_reindex == hta_reindex\"\n\nlocale htai = hashedTa +\n  constrains H :: htai\nbegin\n  lemmas htai_mem_correct = hta_mem_correct[folded htai_mem_def]\n\n  lemma htai_empty_correct[simp]:\n    \"hta_\\<alpha> (htai_empty ()) = ta_empty\"\n    \"hashedTa (htai_empty ())\"\n  by (auto simp add: htai_empty_def hta_empty_correct)\n\n  lemmas htai_add_qi_correct = hta_add_qi_correct[folded htai_add_qi_def]\n  lemmas htai_add_rule_correct = hta_add_rule_correct[folded htai_add_rule_def]\n\n  lemmas htai_bwd_reduce_correct = \n    hta_bwd_reduce_correct[folded htai_bwd_reduce_def]\n  lemmas htai_is_empty_witness_correct = \n    hta_is_empty_witness_correct[folded htai_is_empty_witness_def]\n\n  lemmas htai_ensure_idx_f_correct = \n    hta_ensure_idx_f_correct[folded htai_ensure_idx_f_def]\n  lemmas htai_ensure_idx_s_correct = \n    hta_ensure_idx_s_correct[folded htai_ensure_idx_s_def]\n  lemmas htai_ensure_idx_sf_correct = \n    hta_ensure_idx_sf_correct[folded htai_ensure_idx_sf_def]\n\nend\n\nlemma htai_prod_correct:\n  assumes [simp]: \"hashedTa H1\" \"hashedTa H2\"\n  shows \n  \"ta_lang (hta_\\<alpha> (htai_prod H1 H2)) = ta_lang (hta_\\<alpha> H1) \\<inter> ta_lang (hta_\\<alpha> H2)\"\n  \"hashedTa (htai_prod H1 H2)\"\n  apply (unfold htai_prod_def)\n  apply (auto simp add: hta_prod_correct hashedTa.hta_reindex_correct)\n  done\n\nlemma htai_prodWR_correct:\n  assumes [simp]: \"hashedTa H1\" \"hashedTa H2\"\n  shows \n  \"ta_lang (hta_\\<alpha> (htai_prodWR H1 H2)) \n   = ta_lang (hta_\\<alpha> H1) \\<inter> ta_lang (hta_\\<alpha> H2)\"\n  \"hashedTa (htai_prodWR H1 H2)\"\n  apply (unfold htai_prodWR_def)\n  apply (auto simp add: hta_prodWR_correct hashedTa.hta_reindex_correct)\n  done\n\nlemma htai_union_correct:\n  assumes [simp]: \"hashedTa H1\" \"hashedTa H2\"\n  shows \n  \"ta_lang (hta_\\<alpha> (htai_union H1 H2)) \n   = ta_lang (hta_\\<alpha> H1) \\<union> ta_lang (hta_\\<alpha> H2)\"\n  \"hashedTa (htai_union H1 H2)\"\n  apply (unfold htai_union_def)\n  apply (auto simp add: hta_union_correct hashedTa.hta_reindex_correct)\n  done\n\nsubsection {* Interface Documentation *} text_raw{*\\label{sec:intf_doc}*}\ntext {*\n  This section contains a documentation of the executable tree-automata\n  interface. The documentation contains a description of each function along\n  with the relevant correctness lemmas.\n*}\n\ntext {*\n  ML/OCaml users should note, that there is an interface that has the fixed type\n  Int for both states and function symbols. This interface is simpler to use\n  from ML/OCaml than the generic one, as it requires no overhead to emulate\n  Isabelle/HOL type-classes.\n\n  The functions of this interface start with the prefix {\\em htai} instead of\n  {\\em hta}, but have the same semantics otherwise \n  (cf Section~\\ref{sec:htai_intf}).\n*}\n\nsubsubsection {* Building a Tree Automaton *}\ntext_raw {*\n  \\newcommand{\\fundesc}[2]{{\\bf Function: #1}\\\\#2}\n\n*}\n\ntext {*\n  \\fundesc{@{const [show_types] hta_empty}}{\n    Returns a tree automaton with no states and no rules. \n  }\n  \n  \\paragraph{Relevant Lemmas}\n  \\begin{description}\n    \\item[@{thm [source] hta_empty_correct}:] @{thm hta_empty_correct[no_vars]}\n    \\item[@{thm [source] ta_empty_lang}:] @{thm ta_empty_lang[no_vars]}\n  \\end{description}\n*}\n\ntext {*\n  \\fundesc{@{const [show_types] hta_add_qi}}{\n    Adds an initial state to the given automaton.\n  }\n  \\paragraph{Relevant Lemmas}\n  \\begin{description}\n    \\item[@{thm [source] hashedTa.hta_add_qi_correct}]\n      @{thm hashedTa.hta_add_qi_correct[no_vars]}\n  \\end{description}\n*}\n\ntext {*\n  \\fundesc{@{const [show_types] hta_add_rule}}{\n    Adds a rule to the given automaton.\n  }\n  \\paragraph{Relevant Lemmas}\n  \\begin{description}\n    \\item[@{thm [source] hashedTa.hta_add_rule_correct}:]\n      @{thm hashedTa.hta_add_rule_correct[no_vars]}\n  \\end{description}\n*}\n\nsubsubsection {* Basic Operations *}\n\ntext {*\n  The tree automata of this library may have some optional indices, that \n  accelerate computation. The tree-automata operations will compute the \n  indices if necessary, but due to the pure nature of the Isabelle-language,\n  the computed index cannot be stored for the next usage. Hence, before using a\n  bulk of tree-automaton operations on the same tree-automata, the relevant \n  indexes should be pre-computed.\n*}\n\ntext {*\n  \\fundesc{\n    @{const [show_types] hta_ensure_idx_f}\\\\\n    @{const [show_types] hta_ensure_idx_s}\\\\\n    @{const [show_types] hta_ensure_idx_sf}\n  }{\n    Computes an index for a tree automaton, if it is not yet present.\n  }\n*}\n\ntext {*\n  \\fundesc{@{const [show_types] hta_mem}, @{const [show_types] hta_mem'}}{\n    Check whether a tree is accepted by the tree automaton.\n  }\n  \\paragraph{Relevant Lemmas}\n  \\begin{description}\n    \\item[@{thm [source] hashedTa.hta_mem_correct}:]\n      @{thm hashedTa.hta_mem_correct[no_vars]}\n    \\item[@{thm [source] hashedTa.hta_mem'_correct}:]\n      @{thm hashedTa.hta_mem'_correct[no_vars]}\n  \\end{description}\n*}\n\ntext {*\n  \\fundesc{@{const [show_types] hta_prod}, @{const [show_types] hta_prod'}}{\n    Compute the product automaton. The computed automaton is in \n    forward-reduced form. \n    The language of the product automaton is the intersection of \n    the languages of the two argument automata.\n  }\n  \\paragraph{Relevant Lemmas}\n  \\begin{description}\n    \\item[@{thm [source] hta_prod_correct_aux}:] \n      @{thm hta_prod_correct_aux[no_vars]}\n    \\item[@{thm [source] hta_prod_correct}:] \n      @{thm hta_prod_correct[no_vars]}\n    \\item[@{thm [source] hta_prod'_correct_aux}:] \n      @{thm hta_prod'_correct_aux[no_vars]}\n    \\item[@{thm [source] hta_prod'_correct}:] \n      @{thm hta_prod'_correct[no_vars]}\n  \\end{description}\n*}\n\ntext {*\n  \\fundesc{@{const [show_types] hta_prodWR}}{\n    Compute the product automaton by brute-force algorithm. \n    The resulting automaton is not reduced.\n    The language of the product automaton is the intersection of \n    the languages of the two argument automata.\n  }\n  \\paragraph{Relevant Lemmas}\n  \\begin{description}\n  \\item[@{thm [source] hta_prodWR_correct_aux}:]\n    @{thm hta_prodWR_correct_aux[no_vars]}\n  \\item[@{thm [source] hta_prodWR_correct}:] \n    @{thm hta_prodWR_correct[no_vars]}\n  \\end{description}\n*}\n\ntext {*\n  \\fundesc{@{const [show_types] hta_union}}{\n    Compute the union of two tree automata.\n  }\n  \\paragraph{Relevant Lemmas}\n  \\begin{description}\n  \\item[@{thm [source] hta_union_correct'}:] @{thm hta_union_correct'[no_vars]}\n  \\item[@{thm [source] hta_union_correct}:] @{thm hta_union_correct[no_vars]}\n  \\end{description}\n*}\n\ntext {*\n  \\fundesc{@{const [show_types] hta_reduce}}{\n    Reduce the automaton to the given set of states. All initial states outside\n    this set will be removed. Moreover, all rules that contain states outside \n    this set are removed, too.\n  }\n  \\paragraph{Relevant Lemmas}\n  \\begin{description}\n    \\item[@{thm [source] hashedTa.hta_reduce_correct}:]\n      @{thm hashedTa.hta_reduce_correct[no_vars]}\n  \\end{description}\n*}\n\ntext {*\n  \\fundesc{@{const [show_types] hta_bwd_reduce}}{\n    Compute the backwards-reduced version of a tree automata.\n    States from that no tree can be produced are removed. \n    Backwards reduction does not change the language of the automaton.\n  }\n  \\paragraph{Relevant Lemmas}\n  \\begin{description}\n    \\item[@{thm [source] hashedTa.hta_bwd_reduce_correct}:]\n      @{thm hashedTa.hta_bwd_reduce_correct[no_vars]}\n    \\item[@{thm [source] ta_reduce_b_acc}:] @{thm ta_reduce_b_acc[no_vars]}\n  \\end{description}\n*}\n\ntext {*\n  \\fundesc{@{const [show_types] hta_is_empty_witness}}{\n    Check whether the language of the automaton is empty.\n    If the language is not empty, a tree of the language is returned.\n\n    The following property is not (yet) formally proven, but should hold: \n    If a tree is returned, the language contains no tree with a smaller depth\n    than the returned one.\n  }\n  \\paragraph{Relevant Lemmas}\n  \\begin{description}\n    \\item[@{thm [source] hashedTa.hta_is_empty_witness_correct}:]\n       @{thm hashedTa.hta_is_empty_witness_correct[no_vars]}\n  \\end{description}\n*}\n\nsubsection {* Code Generation *}\n\n(* TODO/FIXME: There seems to be no way to reference the project-directory,\n  in order to control the placement of the generated code files.\n  The code-generation in this file only dumps the generated code to standard output.\n  Hence it is safe to include this file from other projects.\n\n  Actual code generation is done in Ta_impl_codegen.thy\n  *)\n\nexport_code \n  hta_mem hta_mem' hta_prod hta_prod' hta_prodWR hta_union \n  hta_empty hta_add_qi hta_add_rule\n  hta_reduce hta_bwd_reduce hta_is_empty_witness\n  hta_ensure_idx_f hta_ensure_idx_s hta_ensure_idx_sf\n\n  htai_mem htai_prod htai_prodWR htai_union \n  htai_empty htai_add_qi htai_add_rule\n  htai_bwd_reduce htai_is_empty_witness\n  htai_ensure_idx_f htai_ensure_idx_s htai_ensure_idx_sf\n\n  (*ls_size hs_size rs_size*)\n  in SML \n  module_name Ta\n\n\nexport_code \n  hta_mem hta_mem' hta_prod hta_prod' hta_prodWR hta_union \n  hta_empty hta_add_qi hta_add_rule\n  hta_reduce hta_bwd_reduce hta_is_empty_witness\n  hta_ensure_idx_f hta_ensure_idx_s hta_ensure_idx_sf\n\n  htai_mem htai_prod htai_prodWR htai_union \n  htai_empty htai_add_qi htai_add_rule\n  htai_bwd_reduce htai_is_empty_witness\n  htai_ensure_idx_f htai_ensure_idx_s htai_ensure_idx_sf\n\n  (*ls_size hs_size rs_size*)\n  in Haskell \n  module_name Ta\n  (string_classes)\n\nexport_code \n  hta_mem hta_mem' hta_prod hta_prod' hta_prodWR hta_union \n  hta_empty hta_add_qi hta_add_rule\n  hta_reduce hta_bwd_reduce hta_is_empty_witness\n  hta_ensure_idx_f hta_ensure_idx_s hta_ensure_idx_sf\n\n  htai_mem htai_prod htai_prodWR htai_union \n  htai_empty htai_add_qi htai_add_rule\n  htai_bwd_reduce htai_is_empty_witness\n  htai_ensure_idx_f htai_ensure_idx_s htai_ensure_idx_sf\n\n  (*ls_size hs_size rs_size*)\n  in OCaml \n  module_name Ta\n\n(* If this statement fails with an error from ML, this indicates a problem \n  with the code-generator. The most frequent problem in this context is, that\n  the code generator generates code that violates the ML value-restriction.\n*)\n\nML {*\n  @{code hta_mem};\n  @{code hta_mem'};\n  @{code hta_prod};\n  @{code hta_prod'};\n  @{code hta_prodWR};\n  @{code hta_union};\n  @{code hta_empty};\n  @{code hta_add_qi};\n  @{code hta_add_rule};\n  @{code hta_reduce};\n  @{code hta_bwd_reduce};\n  @{code hta_is_empty_witness};\n  @{code hta_ensure_idx_f};\n  @{code hta_ensure_idx_s};\n  @{code hta_ensure_idx_sf};\n  @{code htai_mem};\n  @{code htai_prod};\n  @{code htai_prodWR};\n  @{code htai_union};\n  @{code htai_empty};\n  @{code htai_add_qi};\n  @{code htai_add_rule};\n  @{code htai_bwd_reduce};\n  @{code htai_is_empty_witness};\n  @{code htai_ensure_idx_f};\n  @{code htai_ensure_idx_s};\n  @{code htai_ensure_idx_sf};\n  (*@{code ls_size};\n  @{code hs_size};\n  @{code rs_size}*)\n*}\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Tree-Automata/Ta_impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185205547239, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.2741680986886312}}
{"text": "header {* Execution rules for threads *}\n\ntheory KPL_execution_thread imports \n  KPL_state\nbegin\n\ntext {* Evaluate a local expression down to a word *}\nfun eval_word :: \"local_expr \\<Rightarrow> thread_state \\<Rightarrow> word\"\nwhere\n  \"eval_word (Loc (Var v)) \\<tau> = l \\<tau> (Inl v)\"\n(* eval_word (Loc (Name n)) \\<tau> = undefined *)\n| \"eval_word Lid \\<tau> = l \\<tau> LID\"\n| \"eval_word Gid \\<tau> = l \\<tau> GID\"\n| \"eval_word eTrue \\<tau> = 1\"\n| \"eval_word (e1 \\<and>* e2) \\<tau> = \n  (eval_word e1 \\<tau> * eval_word e2 \\<tau>)\"\n| \"eval_word (\\<not>* e) \\<tau> = (if eval_word e \\<tau> = 0 then 1 else 0)\"\n\ntext {* Evaluate a local expression down to a boolean *}\nfun eval_bool :: \"local_expr \\<Rightarrow> thread_state \\<Rightarrow> bool\"\nwhere\n  \"eval_bool e \\<tau> = (eval_word e \\<tau> \\<noteq> 0)\"\n\ntext {* Abstraction level: none, equality abstraction, or adversarial abstraction *}\ndatatype abs_level = No_Abst | Eq_Abst | Adv_Abst\n\ntext {* The rules of Figure 4, plus two additional rules \n  for adversarial abstraction (Fig 7b) *}\ninductive step_t \n  :: \"abs_level \\<Rightarrow> (thread_state \\<times> pred_basic_stmt) \\<Rightarrow> thread_state \\<Rightarrow> bool\"  \nwhere\n  T_Disabled: \n  \"\\<not> (eval_bool p \\<tau>) \\<Longrightarrow> step_t a (\\<tau>, (b, p)) \\<tau>\"\n| T_Assign: \n  \"\\<lbrakk> eval_bool p \\<tau> ; l' = (l \\<tau>) (Inl v := eval_word e \\<tau>) \\<rbrakk> \n  \\<Longrightarrow> step_t a (\\<tau>, (Assign (Var v) e, p)) (\\<tau> (| l := l' |))\"\n| T_Read: \n  \"\\<lbrakk> eval_bool p \\<tau> ; l' = (l \\<tau>) (Inl v := sh \\<tau> (eval_word e \\<tau>)) ;\n  R' = R \\<tau> \\<union> { eval_word e \\<tau> } ; a \\<in> {No_Abst, Eq_Abst} \\<rbrakk> \n  \\<Longrightarrow> step_t a (\\<tau>, (Read (Var v) e, p)) (\\<tau> (| l := l', R := R' |))\"\n| T_Write: \n  \"\\<lbrakk> eval_bool p \\<tau> ; \n  sh' = (sh \\<tau>) (eval_word e1 \\<tau> := eval_word e2 \\<tau>) ;\n  W' = W \\<tau> \\<union> { eval_word e1 \\<tau> } ; a \\<in> {No_Abst, Eq_Abst} \\<rbrakk> \n  \\<Longrightarrow> step_t a (\\<tau>, (Write e1 e2, p)) (\\<tau> (| sh := sh', W := W' |))\"\n| T_Read_Adv:\n  \"\\<lbrakk> eval_bool p \\<tau> ; l' = (l \\<tau>) (Inl v := asterisk) ;\n  R' = R \\<tau> \\<union> { eval_word e \\<tau> } \\<rbrakk> \n  \\<Longrightarrow> step_t Adv_Abst (\\<tau>, (Read (Var v) e, p)) (\\<tau> (| l := l', R := R' |))\"\n| T_Write_Adv:\n  \"\\<lbrakk> eval_bool p \\<tau> ; W' = W \\<tau> \\<union> { eval_word e1 \\<tau> } \\<rbrakk> \n  \\<Longrightarrow> step_t Adv_Abst (\\<tau>, (Write e1 e2, p)) (\\<tau> (| (* sh := sh',*) W := W' |))\"\n\ntext {* Rephrasing @{text T_Assign} to make it more usable *}\nlemma T_Assign_helper: \n  \"\\<lbrakk> eval_bool p \\<tau> ; l' = (l \\<tau>) (Inl v := eval_word e \\<tau>) ; \\<tau>' = \\<tau> (| l := l' |) \\<rbrakk> \n  \\<Longrightarrow> step_t a (\\<tau>, (Assign (Var v) e, p)) \\<tau>'\"\nby (auto simp add: step_t.T_Assign)\n\ntext {* Rephrasing @{text T_Read} to make it more usable *}\nlemma T_Read_helper: \n  \"\\<lbrakk> eval_bool p \\<tau> ; l' = (l \\<tau>) (Inl v := sh \\<tau> (eval_word e \\<tau>)) ;\n  R' = R \\<tau> \\<union> { eval_word e \\<tau> } ; a \\<in> {No_Abst, Eq_Abst} ; \n  \\<tau>' = \\<tau> (| l := l', R := R' |) \\<rbrakk> \n  \\<Longrightarrow> step_t a (\\<tau>, (Read (Var v) e, p)) \\<tau>'\"\nby (auto simp add: step_t.T_Read)\n\ntext {* Rephrasing @{text T_Write} to make it more usable *}\nlemma T_Write_helper:\n  \"\\<lbrakk> eval_bool p \\<tau> ; \n  sh' = (sh \\<tau>) (eval_word e1 \\<tau> := eval_word e2 \\<tau>) ;\n  W' = W \\<tau> \\<union> { eval_word e1 \\<tau> } ; a \\<in> {No_Abst, Eq_Abst} ;\n  \\<tau>' = \\<tau> (| sh := sh', W := W' |) \\<rbrakk> \n  \\<Longrightarrow> step_t a (\\<tau>, (Write e1 e2, p)) \\<tau>'\"\nby (auto simp add: step_t.T_Write)\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/GPU_Kernel_PL/KPL_execution_thread.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6150878555160665, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.274039806276561}}
{"text": "theory TopoS_Stateful_Policy_Algorithm\nimports TopoS_Stateful_Policy TopoS_Composition_Theory\nbegin\n\nsection{*Stateful Policy -- Algorithm*}\n\nsubsection{* Some unimportant lemmata *}\n  lemma False_set: \"{(r, s). False} = {}\" by simp\n  lemma valid_reqs_ACS_D: \"valid_reqs M \\<Longrightarrow> valid_reqs (get_ACS M)\"\n    by(simp add: valid_reqs_def get_ACS_def)\n  lemma valid_reqs_IFS_D: \"valid_reqs M \\<Longrightarrow> valid_reqs (get_IFS M)\"\n    by(simp add: valid_reqs_def get_IFS_def)\n  lemma all_security_requirements_fulfilled_ACS_D: \"all_security_requirements_fulfilled M G \\<Longrightarrow>\n    all_security_requirements_fulfilled (get_ACS M) G\"\n    by(simp add: all_security_requirements_fulfilled_def get_ACS_def)\n  lemma all_security_requirements_fulfilled_IFS_D: \"all_security_requirements_fulfilled M G \\<Longrightarrow>\n    all_security_requirements_fulfilled (get_IFS M) G\"\n    by(simp add: all_security_requirements_fulfilled_def get_IFS_def)\n  lemma all_security_requirements_fulfilled_mono_stateful_policy_to_network_graph:\n      \"\\<lbrakk> valid_reqs M; E' \\<subseteq> E; wf_graph \\<lparr> nodes = V, edges = Efix \\<union> E \\<rparr> \\<rbrakk> \\<Longrightarrow>  \n        all_security_requirements_fulfilled M \n          (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = Efix, flows_state = E \\<rparr>)\\<Longrightarrow>\n        all_security_requirements_fulfilled M \n          (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = Efix, flows_state = E' \\<rparr>)\"\n    apply(simp add: stateful_policy_to_network_graph_def all_flows_def)\n    apply(drule all_security_requirements_fulfilled_mono[where E=\"Efix \\<union> E \\<union> backflows E\" and E'=\"Efix \\<union> E' \\<union> backflows E'\" and V=\"V\"])\n       apply(thin_tac \"wf_graph G\" for G)\n       apply(thin_tac \"all_security_requirements_fulfilled M G\" for M G)\n       apply(simp add: backflows_def, blast)\n      apply(thin_tac \"all_security_requirements_fulfilled M G\" for M G)\n      apply(simp add: wf_graph_def)\n      apply(simp add: backflows_def)\n      using [[simproc add: finite_Collect]] apply(auto)[1]\n     apply(simp_all)\n   done\n\n\nsubsection {* Sketch for generating a stateful policy from a simple directed policy *}\n  text{* Having no stateful flows, we trivially get a valid stateful policy. *}\n    lemma trivial_stateful_policy_compliance:\n    \"\\<lbrakk> wf_graph \\<lparr> nodes = V, edges = E \\<rparr>; valid_reqs M; all_security_requirements_fulfilled M \\<lparr> nodes = V, edges = E \\<rparr> \\<rbrakk> \\<Longrightarrow> \n      stateful_policy_compliance \\<lparr> hosts = V, flows_fix = E, flows_state = {} \\<rparr> \\<lparr> nodes = V, edges = E \\<rparr> M\"\n      apply(unfold_locales)\n                   apply(simp_all add: wf_graph_def stateful_policy_to_network_graph_def all_flows_def backflows_def False_set)\n       apply(simp add: get_IFS_def get_ACS_def all_security_requirements_fulfilled_def)\n      apply(clarify)\n      apply(drule valid_reqs_ACS_D) \n      apply(drule all_security_requirements_fulfilled_ACS_D)\n      apply(drule(1) all_security_requirements_fulfilled_imp_get_offending_empty)\n      by force\n\n\n  text{*trying better*}\n\n    text{*First, filtering flows that cause no IFS violations*}\n    (*the edges front of the list are more likely to be kept*)\n    fun filter_IFS_no_violations_accu :: \"'v::vertex graph \\<Rightarrow> 'v SecurityInvariant_configured list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> ('v \\<times> 'v) list\" where\n      \"filter_IFS_no_violations_accu G M accu [] = accu\" |\n      \"filter_IFS_no_violations_accu G M accu (e#Es) = (if\n        all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<lparr> hosts = nodes G, flows_fix = edges G, flows_state = set (e#accu) \\<rparr>)\n        then filter_IFS_no_violations_accu G M (e#accu) Es\n        else filter_IFS_no_violations_accu G M accu Es)\"\n    definition filter_IFS_no_violations :: \"'v::vertex graph \\<Rightarrow> 'v SecurityInvariant_configured list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> ('v \\<times> 'v) list\" where\n      \"filter_IFS_no_violations G M Es = filter_IFS_no_violations_accu G M [] Es\"\n\n\n    lemma filter_IFS_no_violations_subseteq_input: \"set (filter_IFS_no_violations G M Es) \\<subseteq> set Es\"\n    apply(subgoal_tac \"\\<forall> accu. set (filter_IFS_no_violations_accu G M accu Es) \\<subseteq> set Es \\<union> set accu\")\n     apply(erule_tac x=\"[]\" in allE)\n     apply(simp add: filter_IFS_no_violations_def)\n    unfolding filter_IFS_no_violations_def\n    apply(induct_tac Es)\n     apply(simp_all)\n    apply force\n    done\n    lemma filter_IFS_no_violations_accu_correct_induction: \"valid_reqs (get_IFS M) \\<Longrightarrow> wf_graph \\<lparr> nodes = V, edges = E \\<rparr> \\<Longrightarrow>\n            all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = E, flows_state = set (accu) \\<rparr>) \\<Longrightarrow> \n            (set accu) \\<union> (set edgesList) \\<subseteq> E \\<Longrightarrow> \n            all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = E, flows_state = set (filter_IFS_no_violations_accu \\<lparr> nodes = V, edges = E \\<rparr> M accu edgesList) \\<rparr>)\"\n      apply(induction edgesList arbitrary: accu)\n       by(simp_all)\n    lemma filter_IFS_no_violations_correct: \"\\<lbrakk>valid_reqs (get_IFS M); wf_graph G;\n            all_security_requirements_fulfilled (get_IFS M) G; \n            (set edgesList) \\<subseteq> edges G \\<rbrakk> \\<Longrightarrow> \n            all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<lparr> hosts = nodes G, flows_fix = edges G, flows_state = set (filter_IFS_no_violations G M edgesList) \\<rparr>)\"\n    unfolding filter_IFS_no_violations_def\n    apply(case_tac G, simp)\n    apply(drule(1) filter_IFS_no_violations_accu_correct_induction[where accu=\"[]\", simplified])\n      apply(simp_all)\n    by(simp add: stateful_policy_to_network_graph_def all_flows_def backflows_def False_set)\n    lemma filter_IFS_no_violations_accu_no_IFS: \"valid_reqs (get_IFS M) \\<Longrightarrow> wf_graph G \\<Longrightarrow> get_IFS M = [] \\<Longrightarrow>\n            (set accu) \\<union> (set edgesList) \\<subseteq> edges G \\<Longrightarrow> \n            filter_IFS_no_violations_accu G M accu edgesList = rev(edgesList)@accu\"\n      apply(induction edgesList arbitrary: accu)\n       by(simp_all add: all_security_requirements_fulfilled_def)\n\n\n    lemma filter_IFS_no_violations_accu_maximal_induction: \"valid_reqs (get_IFS M) \\<Longrightarrow> wf_graph \\<lparr> nodes = V, edges = E \\<rparr> \\<Longrightarrow> \n      set accu \\<subseteq> E \\<Longrightarrow> set edgesList \\<subseteq> E \\<Longrightarrow>\n        \\<forall> e \\<in> E - (set accu \\<union> set edgesList).\n            \\<not> all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = E, flows_state = {e} \\<union> (set accu) \\<rparr>)\n         \\<Longrightarrow>\n           let stateful = set (filter_IFS_no_violations_accu \\<lparr> nodes = V, edges = E \\<rparr> M accu edgesList) in\n            (\\<forall> e \\<in> E - stateful.\n            \\<not> all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = E, flows_state = {e} \\<union> stateful \\<rparr>))\"\n      proof(induction edgesList arbitrary: accu)\n      case Nil thus ?case by(simp add: Let_def)\n      next\n      case(Cons e Es)\n        from Cons.prems(3) Cons.prems(2) have \"fst ` set accu \\<subseteq> V\" and \"snd ` set accu \\<subseteq> V\"\n          by(auto simp add: wf_graph_def)\n        --\"@{const wf_graph} for some complicated structures\"\n        from Cons.prems(2) this Cons.prems(4)  have \"\\<And>ea. ea\\<in>E \\<Longrightarrow> wf_graph \\<lparr> nodes = V, edges = insert e (insert ea (set accu)) \\<rparr>\"\n          by(auto simp add: wf_graph_def)\n        from backflows_wf[OF this] wf_graph_union_edges[OF Cons.prems(2)]\n        have \"\\<And>ea. ea\\<in>E  \\<Longrightarrow> wf_graph \\<lparr> nodes = V, edges = E \\<union> backflows (insert e (insert ea (set accu))) \\<rparr>\" by (simp)\n        hence \"\\<And>ea. ea\\<in>E \\<Longrightarrow> wf_graph \\<lparr> nodes = V, edges = E \\<union> set accu \\<union> backflows (insert e (insert ea (set accu))) \\<rparr>\" \n          by (metis Cons.prems(3) sup.order_iff)\n        from this Cons.prems(4)\n        have \"\\<And>ea. ea\\<in>E \\<Longrightarrow> wf_graph \\<lparr> nodes = V, edges = insert e (insert ea (E \\<union> set accu \\<union> backflows (insert e (insert ea (set accu))))) \\<rparr>\"\n          by(simp add: insert_absorb)\n        hence validgraph1: \"\\<And>ea. ea\\<in>E - (set (e # accu) \\<union> set Es) \\<Longrightarrow> \n          wf_graph \\<lparr> nodes = V, edges = insert e (insert ea (E \\<union> set accu \\<union> backflows (insert e (insert ea (set accu))))) \\<rparr>\" by(simp)\n\n        have validgraph2: \"\\<And> ea. \n         insert ea (E \\<union> set accu \\<union> backflows (insert ea (set accu))) \\<subseteq> insert e (insert ea (E \\<union> set accu \\<union> backflows (insert e (insert ea (set accu)))))\"\n         apply(simp add: backflows_def)\n         by blast\n        \n        from all_security_requirements_fulfilled_mono[OF Cons.prems(1) validgraph2 validgraph1] have neg_mono:\n            \"\\<And>ea. ea \\<in> E - (set (e # accu) \\<union> set Es) \\<Longrightarrow>\n         \\<not> all_security_requirements_fulfilled (get_IFS M) \n            \\<lparr>nodes = V, edges = insert ea (E \\<union> set accu \\<union> backflows (insert ea (set accu)))\\<rparr>\n         \\<Longrightarrow>\n         \\<not> all_security_requirements_fulfilled (get_IFS M) \n            \\<lparr>nodes = V, edges = insert e (insert ea (E \\<union> set accu \\<union> backflows (insert e (insert ea (set accu)))))\\<rparr>\"\n           apply(simp)\n           by blast\n\n         from Cons.prems(5) have \"\\<And>ea. ea\\<in>E - (set (e # accu) \\<union> set Es) \\<Longrightarrow>\n          \\<not> all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \n              \\<lparr>hosts = V, flows_fix = E, flows_state = {ea} \\<union> set (e # accu)\\<rparr>)\"\n           apply(erule_tac x=\"ea\" in ballE)\n           prefer 2\n           apply simp\n          apply(simp only: stateful_policy_to_network_graph_def all_flows_def stateful_policy.select_convs)\n          apply(simp)\n          apply(frule(1) neg_mono[simplified])\n          by(simp)\n         hence goalTrue:\n          \"\\<forall> ea\\<in>E - (set (e # accu) \\<union> set Es). \n            \\<not> all_security_requirements_fulfilled (get_IFS M) \n                (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = {ea} \\<union> set (e # accu)\\<rparr>)\"\n         by simp\n         \n        show ?case\n        apply(simp add: Let_def)\n        apply(rule conjI)\n\n         apply(rule impI)\n         apply(thin_tac \"_\") (*dont't need it*)\n         using Cons.IH[where accu=\"e # accu\", OF Cons.prems(1) Cons.prems(2) _ _ goalTrue, simplified Let_def] Cons.prems(3) Cons.prems(4)\n         apply(auto) [1]\n\n        apply(rule impI)\n        using Cons.IH[where accu=\"accu\", OF Cons.prems(1) Cons.prems(2), simplified Let_def] Cons.prems(5) Cons.prems(3) Cons.prems(4)\n        apply(auto)\n        done\n     qed\n    lemma filter_IFS_no_violations_maximal: \"\\<lbrakk>valid_reqs (get_IFS M); wf_graph G;\n            (set edgesList) = edges G \\<rbrakk> \\<Longrightarrow> \n            let stateful = set (filter_IFS_no_violations G M edgesList) in \n            \\<forall> e \\<in> edges G - stateful.\n              \\<not> all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<lparr> hosts = nodes G, flows_fix = edges G, flows_state = {e} \\<union> stateful \\<rparr>)\"\n    unfolding filter_IFS_no_violations_def\n    apply(case_tac G, simp)\n    apply(drule(1) filter_IFS_no_violations_accu_maximal_induction[where accu=\"[]\" and edgesList=\"edgesList\"])\n       by(simp_all)\n\n    --\"It is not only maximal for single flows but all non-empty subsets\"\n    corollary filter_IFS_no_violations_maximal_allsubsets: \n    assumes a1: \"valid_reqs (get_IFS M)\"\n    and     a2: \"wf_graph G\"\n    and     a4: \"(set edgesList) = edges G\"\n    shows   \"let stateful = set (filter_IFS_no_violations G M edgesList) in \n            \\<forall> E \\<subseteq> edges G - stateful. E \\<noteq> {} \\<longrightarrow>\n              \\<not> all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<lparr> hosts = nodes G, flows_fix = edges G, flows_state = E \\<union> stateful \\<rparr>)\"\n    proof -\n      let ?stateful = \"set (filter_IFS_no_violations G M edgesList)\"\n      from filter_IFS_no_violations_maximal[OF a1 a2 a4] have not_fulfilled_single: \n        \"\\<forall>e\\<in>edges G - ?stateful. \\<not> all_security_requirements_fulfilled (get_IFS M)\n                (stateful_policy_to_network_graph \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = {e} \\<union> ?stateful\\<rparr>)\"\n        by(simp add: Let_def)\n      have neg_mono:\n        \"\\<And> e E. e \\<in> E \\<Longrightarrow> E \\<subseteq> edges G - ?stateful \\<Longrightarrow> E \\<noteq> {} \\<Longrightarrow>\n          \\<not> all_security_requirements_fulfilled (get_IFS M) \n              (stateful_policy_to_network_graph \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = {e} \\<union> ?stateful\\<rparr>) \\<Longrightarrow> \n          \\<not> all_security_requirements_fulfilled (get_IFS M) \n              (stateful_policy_to_network_graph \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = E \\<union> ?stateful\\<rparr>)\"\n        proof -\n          fix e E\n          assume h1: \"e \\<in> E\"\n          and    h2: \"E \\<subseteq> edges G - ?stateful\"\n          and    h3: \"E \\<noteq> {}\"\n          and    h4: \"\\<not> all_security_requirements_fulfilled (get_IFS M) \n            (stateful_policy_to_network_graph \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = {e} \\<union> ?stateful\\<rparr>)\"\n  \n          from filter_IFS_no_violations_subseteq_input a4 have \"?stateful \\<subseteq> edges G\" by blast\n          hence \"edges G \\<union> (E \\<union> ?stateful) = edges G\" using h2 by blast\n          from a2 this have validgraph1: \"wf_graph \\<lparr>nodes = nodes G, edges = edges G \\<union> (E \\<union> ?stateful)\\<rparr>\"\n          by(case_tac G, simp)\n  \n          from h1 h2 h3 have subseteq: \"({e} \\<union> ?stateful) \\<subseteq> (E \\<union> ?stateful)\" by blast\n\n          have revimp: \"\\<And>A B. (A \\<Longrightarrow> B) \\<Longrightarrow> (\\<not> B \\<Longrightarrow> \\<not> A)\" by fast\n          \n          from all_security_requirements_fulfilled_mono_stateful_policy_to_network_graph[OF a1 subseteq validgraph1] h4\n          show \"\\<not> all_security_requirements_fulfilled (get_IFS M) \n            (stateful_policy_to_network_graph \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = E \\<union> ?stateful\\<rparr>)\" \n            apply(rule revimp)\n            by assumption\n        qed\n      \n      show ?thesis\n      proof(simp add: Let_def,rule allI,rule impI, rule impI)\n        fix E\n        assume h1: \"E \\<subseteq> edges G - ?stateful\"\n        and    h2: \"E \\<noteq> {}\"\n\n        from  h1 h2 obtain e where e_prop1: \"e \\<in> E\" by blast \n        from this h1 have \"e \\<in> edges G - ?stateful\" by blast\n        from this not_fulfilled_single have e_prop2: \"\\<not> all_security_requirements_fulfilled (get_IFS M)\n          (stateful_policy_to_network_graph \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = {e} \\<union> ?stateful\\<rparr>)\"\n          by simp\n        \n        from neg_mono[OF e_prop1 h1 h2 e_prop2]\n        show \" \\<not> all_security_requirements_fulfilled (get_IFS M)\n               (stateful_policy_to_network_graph \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = E \\<union> set (filter_IFS_no_violations G M edgesList)\\<rparr>)\"\n        .\n      qed\n    qed\n    \n    --\"soundness and completeness\"\n    thm filter_IFS_no_violations_correct filter_IFS_no_violations_maximal\n\n\n\n\n\n  text{*Next *}\n    (*\"\\<forall>F \\<in> get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<T> ). F \\<subseteq> backflows (filternew_flows_state \\<T>)\"*)\n    (*first in list are more likely to be kept*)\n    fun filter_compliant_stateful_ACS_accu :: \"'v::vertex graph \\<Rightarrow> 'v SecurityInvariant_configured list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> ('v \\<times> 'v) list\" where\n      \"filter_compliant_stateful_ACS_accu G M accu [] = accu\" |\n      \"filter_compliant_stateful_ACS_accu G M accu (e#Es) = (if\n        e \\<notin> backflows (edges G) \\<and> (\\<forall>F \\<in> get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr> hosts = nodes G, flows_fix = edges G, flows_state = set (e#accu) \\<rparr>). F \\<subseteq> backflows (set (e#accu)))\n        then filter_compliant_stateful_ACS_accu G M (e#accu) Es\n        else filter_compliant_stateful_ACS_accu G M accu Es)\"\n    definition filter_compliant_stateful_ACS :: \"'v::vertex graph \\<Rightarrow> 'v SecurityInvariant_configured list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> ('v \\<times> 'v) list\" where\n      \"filter_compliant_stateful_ACS G M Es = filter_compliant_stateful_ACS_accu G M [] Es\"\n\n\n    lemma filter_compliant_stateful_ACS_subseteq_input: \"set (filter_compliant_stateful_ACS G M Es) \\<subseteq> set Es\"\n      apply(subgoal_tac \"\\<forall> accu. set (filter_compliant_stateful_ACS_accu G M accu Es) \\<subseteq> set Es \\<union> set accu\")\n       apply(erule_tac x=\"[]\" in allE)\n       apply(simp add: filter_compliant_stateful_ACS_def)\n      apply(induct_tac Es)\n       apply(simp_all)\n      apply (metis Un_insert_right set_simps(2) set_subset_Cons set_union subset_trans)\n      done\n    lemma filter_compliant_stateful_ACS_accu_correct_induction: \"valid_reqs (get_ACS M) \\<Longrightarrow> wf_graph \\<lparr> nodes = V, edges = E \\<rparr> \\<Longrightarrow>\n            (set accu) \\<union> (set edgesList) \\<subseteq> E \\<Longrightarrow> \n            \\<forall>F \\<in> get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = E, flows_state = set (accu) \\<rparr>). F \\<subseteq> backflows (set accu) \\<Longrightarrow> \n            (\\<forall>a \\<in> set accu. a \\<notin> (backflows E)) \\<Longrightarrow>\n            \\<T> = \\<lparr> hosts = V, flows_fix = E, flows_state = set (filter_compliant_stateful_ACS_accu \\<lparr> nodes = V, edges = E \\<rparr> M accu edgesList) \\<rparr> \\<Longrightarrow>\n            \\<forall>F \\<in> get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<T>). F \\<subseteq> backflows (filternew_flows_state \\<T>)\"\n      proof(induction edgesList arbitrary: accu)\n        case Nil\n          from Nil(5) have \"backflows (set accu) = backflows {e \\<in> set accu. e \\<notin> backflows E}\" by (metis (lifting) Collect_cong Collect_mem_eq)\n          from this Nil(4) have \"\\<forall>F\\<in>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set accu\\<rparr>). F \\<subseteq> backflows {e \\<in> set accu. e \\<notin> backflows E}\" by simp\n          from this Nil(6) show ?case by(simp add: filternew_flows_state_alt2)\n        next\n        case (Cons e Es)\n          from Cons.IH[OF Cons.prems(1) Cons.prems(2)] Cons.prems(3) Cons.prems(4) Cons.prems(5) Cons.prems(6)\n          show ?case by(simp add: filternew_flows_state_alt2 split: if_split_asm)\n      qed\n\n    \n    lemma filter_compliant_stateful_ACS_accu_no_side_effects: \"valid_reqs (get_ACS M) \\<Longrightarrow> wf_graph G \\<Longrightarrow>\n            \\<forall>F \\<in> get_offending_flows (get_ACS M) \\<lparr>nodes = nodes G, edges = edges G \\<union> backflows (edges G)\\<rparr>. F \\<subseteq> (backflows (edges G)) - (edges G) \\<Longrightarrow>\n            (set accu) \\<union> (set edgesList) \\<subseteq> edges G \\<Longrightarrow> \n            (\\<forall>a \\<in> set accu. a \\<notin> (backflows (edges G))) \\<Longrightarrow>\n            filter_compliant_stateful_ACS_accu G M accu edgesList = rev([ e \\<leftarrow> edgesList. e \\<notin> backflows (edges G)])@accu\"\n      apply(simp add: backflows_minus_backflows)\n      apply(induction edgesList arbitrary: accu)\n       apply(simp)\n      apply(simp add: stateful_policy_to_network_graph_def all_flows_def)\n      apply(rule impI)\n      apply(case_tac G, simp, rename_tac V E)\n      thm Un_set_offending_flows_bound_minus_subseteq'[where X=\"backflows E - E\" and E=\"E \\<union> backflows E\"]\n      apply(drule_tac X=\"backflows E - E\" and E=\"E \\<union> backflows E\" and E'=\"(E \\<union> backflows E) - (insert a (E \\<union> set accu \\<union> backflows (insert a (set accu))))\" in Un_set_offending_flows_bound_minus_subseteq')\n         defer\n         prefer 2\n         apply blast\n        apply auto[1]\n       apply(subgoal_tac \"E \\<union> backflows E - (E \\<union> backflows E - insert a (E \\<union> set accu \\<union> backflows (insert a (set accu)))) = insert a (E \\<union> set accu \\<union> backflows (insert a (set accu)))\")\n        apply(simp)\n        prefer 2\n        apply (metis Un_assoc Un_least Un_mono backflows_subseteq double_diff insert_def insert_subset subset_refl)\n       apply(subgoal_tac \"backflows (insert a (set accu)) \\<subseteq> backflows E - E - (E \\<union> backflows E - insert a (E \\<union> set accu \\<union> backflows (insert a (set accu))))\")\n        apply(blast)\n       apply(simp add: backflows_def)\n       apply fast\n      using FiniteGraph.backflows_wf FiniteGraph.wf_graph_union_edges by metis\n\n\n\n    lemma filter_compliant_stateful_ACS_correct: \n      assumes a1: \"valid_reqs (get_ACS M)\"\n      and     a2: \"wf_graph G\"\n      and     a3: \"set edgesList \\<subseteq> edges G\"  \n      and     a4: \"all_security_requirements_fulfilled (get_ACS M) G\"\n      and     a5: \"\\<T> = \\<lparr> hosts = nodes G, flows_fix = edges G, flows_state = set (filter_compliant_stateful_ACS G M edgesList) \\<rparr>\"\n      shows   \"\\<forall>F \\<in> get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<T>). F \\<subseteq> backflows (filternew_flows_state \\<T>)\"\n      proof -\n        obtain V E where VE: \"G = \\<lparr> nodes = V, edges = E \\<rparr>\" by(case_tac G, blast)\n        from VE a2 have wfVE: \"wf_graph \\<lparr> nodes = V, edges = E \\<rparr>\" by simp\n        from VE a3 have \"set edgesList \\<subseteq> E\" by simp\n\n        from a5 VE have a5': \"\\<T> = \\<lparr>hosts = V, flows_fix = E, flows_state = set (filter_compliant_stateful_ACS_accu \\<lparr>nodes = V, edges = E\\<rparr> M [] edgesList)\\<rparr>\"\n          unfolding filter_compliant_stateful_ACS_def\n          by(simp)\n\n        from all_security_requirements_fulfilled_imp_get_offending_empty[OF a1 a4] VE\n        have \"\\<forall>F\\<in>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = {}\\<rparr>). F \\<subseteq> backflows {}\"\n          by(simp add: stateful_policy_to_network_graph_def all_flows_def backflows_def False_set)\n\n        from filter_compliant_stateful_ACS_accu_correct_induction[where accu=\"[]\" and edgesList=\"edgesList\", simplified, OF a1 wfVE `set edgesList \\<subseteq> E` this a5']\n        show ?thesis .\n     qed\n\n\n    lemma filter_compliant_stateful_ACS_accu_induction_maximal:\"\\<lbrakk> valid_reqs (get_ACS M);  wf_graph \\<lparr> nodes = V, edges = E \\<rparr>;\n            (set edgesList) \\<subseteq> E;\n            (set accu) \\<subseteq> E; \n            stateful = set (filter_compliant_stateful_ACS_accu \\<lparr> nodes = V, edges = E \\<rparr> M accu edgesList);\n            \\<forall>e \\<in> E - (set edgesList \\<union> set accu \\<union> {e \\<in> E. e \\<in> backflows E}).\n            \\<not> (\\<Union> get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = E, flows_state = set accu \\<union> {e} \\<rparr>) \n                \\<subseteq> backflows (filternew_flows_state \\<lparr> hosts = V, flows_fix = E, flows_state = set accu \\<union> {e} \\<rparr>))\n            \\<rbrakk> \\<Longrightarrow>\n            \\<forall>e \\<in> E - (stateful \\<union> {e \\<in> E. e \\<in> backflows E}). (* E - {computed stateful flows plus trivial stateful flows} *)\n            \\<not> (\\<Union> get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = E, flows_state = stateful \\<union> {e} \\<rparr>) \n                \\<subseteq> backflows (filternew_flows_state \\<lparr> hosts = V, flows_fix = E, flows_state = stateful \\<union> {e} \\<rparr>))\"\n   proof(induction edgesList arbitrary: accu E)\n   case Nil from Nil(5)[simplified] Nil(6) show ?case by(simp)\n   next\n   case (Cons a Es)\n     --\"case distinction\"\n     let ?caseDistinction=\"a \\<notin> backflows (E) \\<and>  (\\<forall>F\\<in>get_offending_flows (get_ACS M)\n                 (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set (a # accu)\\<rparr>).\n                    F \\<subseteq> backflows (set (a # accu)))\"\n     from Cons.prems(3) have \"set Es \\<subseteq> E\" by simp\n\n     show ?case\n      proof(cases ?caseDistinction)\n        assume CaseTrue: ?caseDistinction\n        from CaseTrue have \n          \"set (filter_compliant_stateful_ACS_accu \\<lparr>nodes = V, edges = E\\<rparr> M accu (a # Es)) = \n           set (filter_compliant_stateful_ACS_accu \\<lparr>nodes = V, edges = E\\<rparr> M (a # accu) Es)\"\n           by(simp)\n        from this Cons.prems(5) have statefulsimp:\n          \"stateful = set (filter_compliant_stateful_ACS_accu \\<lparr>nodes = V, edges = E\\<rparr> M (a # accu) Es)\" by simp\n        from Cons.prems(3) Cons.prems(4) have \"set (a # accu) \\<subseteq> E\" by simp\n\n        have \"\\<forall>e\\<in>E - (set Es \\<union> set (a # accu) \\<union> {e \\<in> E. e \\<in> backflows E}).\n     \\<not> \\<Union>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set (a # accu) \\<union> {e}\\<rparr>)\n        \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set (a # accu) \\<union> {e}\\<rparr>)\"\n          proof(rule ballI)\n            fix e\n            assume h1: \"e \\<in> E - (set Es \\<union> set (a # accu) \\<union> {e \\<in> E. e \\<in> backflows E})\"\n\n            from conjunct1[OF CaseTrue] have filternew_flows_state_moveout_a:\n              \"filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set (a # accu) \\<union> {e}\\<rparr> = \n              {a} \\<union> filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {e}\\<rparr>\"\n              apply(simp add: filternew_flows_state_alt) by blast\n\n            have backflowssubseta: \"\\<And>X. backflows X \\<subseteq> backflows ({a} \\<union> X)\" by(simp add: backflows_def, blast)\n\n            from Cons.prems(6) h1 have \n              \"\\<not> \\<Union>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {e}\\<rparr>)\n                \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {e}\\<rparr>)\" by simp\n            from this obtain dat_offender where \n              dat_in: \"dat_offender \\<in> \\<Union>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {e}\\<rparr>)\"\n              and dat_offends: \"dat_offender \\<notin> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {e}\\<rparr>)\" by blast\n\n            have wfGraphA: \"wf_graph (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set (a # accu) \\<union> {e}\\<rparr>)\"\n              proof(simp add: stateful_policy_to_network_graph_def all_flows_def)\n              from Cons.prems(2) h1 Cons.prems(3) Cons.prems(4)\n              have \"wf_graph \\<lparr>nodes=V, edges = insert e (insert a (set accu)) \\<rparr>\" \n              apply(auto simp add: wf_graph_def) by force\n              from this backflows_wf\n              have vgh1: \"wf_graph \\<lparr>nodes = V, edges = backflows (insert e (insert a (set accu)))\\<rparr>\" by auto\n              from Cons.prems(2) wf_graph_add_subset_edges h1  Cons.prems(3) Cons.prems(4)\n              have vgh2: \"wf_graph \\<lparr>nodes = V, edges = insert e ((insert a E) \\<union> set accu)\\<rparr>\"\n                proof -\n                  have f1: \"e \\<in> E - (set Es \\<union> insert a (set accu) \\<union> {R \\<in> E. R \\<in> backflows E})\"\n                    using h1 by simp\n                  have f2: \"insert a (set accu) \\<subseteq> E\"\n                    using `set (a # accu) \\<subseteq> E` by simp\n                  have f3: \"e \\<in> E\"\n                    using f1 by fastforce\n                  have \"E \\<union> insert a (set accu) = E\"\n                    using f2 by fastforce\n                  thus \"wf_graph \\<lparr>nodes = V, edges = insert e (insert a E \\<union> set accu)\\<rparr>\"\n                    using f3 Cons.prems(2) Un_insert_right insert_absorb sup_commute by fastforce\n                qed\n              from vgh1 vgh2 wf_graph_union_edges\n              show \"wf_graph \\<lparr>nodes = V, edges = insert e (insert a (E \\<union> set accu \\<union> backflows (insert e (insert a (set accu)))))\\<rparr>\" by fastforce\n           qed\n            \n            from dat_in have dat_in_simplified: \n              \"dat_offender \\<in> \\<Union>get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = insert e (E \\<union> set accu \\<union> backflows (insert e (set accu)))\\<rparr>\"\n              by(simp add: stateful_policy_to_network_graph_def all_flows_def)\n\n            have subsethlp: \"insert e (E \\<union> set accu \\<union> backflows (insert e (set accu))) \\<subseteq> E \\<union> (set (a # accu) \\<union> {e}) \\<union> backflows (set (a # accu) \\<union> {e})\"\n              apply(simp)\n              apply(rule, blast)\n              apply(rule, blast)\n              apply(rule)\n              apply(simp add: backflows_def, fast)\n              done\n\n            from get_offending_flows_union_mono[OF \n                Cons.prems(1) \n                wfGraphA[simplified stateful_policy_to_network_graph_def all_flows_def graph.select_convs stateful_policy.select_convs],\n                OF subsethlp]\n            dat_in_simplified have dat_in_a: \"dat_offender \\<in> \\<Union>get_offending_flows (get_ACS M) \n              (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set (a # accu) \\<union> {e}\\<rparr>)\"\n              by(simp add: stateful_policy_to_network_graph_def all_flows_def, fast)\n\n            have \"dat_offender \\<noteq> (snd a, fst a)\"\n              proof(rule ccontr)\n              assume \"\\<not> dat_offender \\<noteq> (snd a, fst a)\"\n              hence hlpassm: \"dat_offender = (snd a, fst a)\" by simp\n              from this obtain a1 a2 where \"dat_offender = (a2, a1)\" by blast\n              \n              \n              have \"\\<Union>get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = insert e (E \\<union> set accu \\<union> backflows (insert e (set accu)))\\<rparr> \\<subseteq> \n                  insert e (E \\<union> set accu \\<union> backflows (insert e (set accu)))\"\n                by (metis Cons.prems(1) Sup_le_iff get_offending_flows_subseteq_edges)\n              from this h1 have UN_get_subset: \n                    \"\\<Union>get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = insert e (E \\<union> set accu \\<union> backflows (insert e (set accu)))\\<rparr> \\<subseteq> \n                   (E \\<union> set accu \\<union> backflows (insert e (set accu)))\"\n                by blast\n\n            from dat_offends have dat_offends_simplified: \n              \"dat_offender \\<notin> backflows (insert e (set accu)) - E\"\n                by(simp only: filternew_flows_state_alt stateful_policy.select_convs backflows_minus_backflows, simp)\n              \n              from conjunct1[OF CaseTrue] hlpassm have \"dat_offender \\<notin> E\"\n                by(simp add: backflows_def, fastforce)\n              from dat_in_simplified UN_get_subset this have \"dat_offender \\<in> set accu \\<union> backflows (insert e (set accu))\" by blast\n              from this Cons.prems(4) `dat_offender \\<notin> E` have \"dat_offender \\<in> backflows (insert e (set accu))\" by blast\n              from dat_offends_simplified[simplified] this have \"dat_offender \\<in> E\" by simp\n              from `dat_offender \\<notin> E` `dat_offender \\<in> E` show False by simp\n            qed\n\n            from this dat_offends have \n              \"dat_offender \\<notin> backflows ({a} \\<union> filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {e}\\<rparr>)\"\n              apply(simp add: backflows_def) by force\n\n            from dat_in_a this\n            show \"\\<not> \\<Union>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set (a # accu) \\<union> {e}\\<rparr>)\n            \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set (a # accu) \\<union> {e}\\<rparr>)\"\n            apply(subst filternew_flows_state_moveout_a) by blast\n          qed\n\n        from Cons.IH[OF Cons.prems(1) Cons.prems(2) `set Es \\<subseteq> E` `set (a # accu) \\<subseteq> E` statefulsimp this ] show \"?case\" \n          by(simp)\n      next\n        assume CaseFalse: \"\\<not> ?caseDistinction\"\n\n        from CaseFalse have funapplysimp: \n          \"set (filter_compliant_stateful_ACS_accu \\<lparr>nodes = V, edges = E\\<rparr> M accu (a # Es)) = \n           set (filter_compliant_stateful_ACS_accu \\<lparr>nodes = V, edges = E\\<rparr> M accu Es)\"\n           by auto\n        from this Cons.prems(5) have statefulsimp:\n          \"stateful = set (filter_compliant_stateful_ACS_accu \\<lparr>nodes = V, edges = E\\<rparr> M accu Es)\" by simp\n        from Cons.prems(4) have \"set accu \\<subseteq> E\" .\n\n        have \"a \\<in> E - (set Es \\<union> set accu \\<union> {e \\<in> E. e \\<in> backflows E})\\<Longrightarrow> \\<not> \\<Union>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {a}\\<rparr>)\n          \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {a}\\<rparr>)\"\n          proof(rule ccontr)\n            assume h1: \"a \\<in> E - (set Es \\<union> set accu \\<union> {e \\<in> E. e \\<in> backflows E})\"\n            and    \"\\<not> \\<not>\\<Union>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {a}\\<rparr>) \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {a}\\<rparr>)\"\n            hence hccontr: \"\\<Union>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {a}\\<rparr>) \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {a}\\<rparr>)\" by simp\n\n            moreover from h1 have stateful_to_graph: \"stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {a}\\<rparr> =  \\<lparr>nodes = V, edges = E \\<union> set accu \\<union> backflows (insert a (set accu))\\<rparr>\"\n              by(simp add: stateful_policy_to_network_graph_def all_flows_def, blast)\n            moreover have \"backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {a}\\<rparr>) = backflows (insert a (set accu)) - E\"\n              by(simp add: filternew_flows_state_alt backflows_minus_backflows)\n            ultimately have hccontr_simp:\n              \"\\<Union>get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = E \\<union> set accu \\<union> backflows (insert a (set accu))\\<rparr> \\<subseteq> backflows (insert a (set accu)) - E\" by simp\n\n            from Cons.prems(3) Cons.prems(4) have backaaccusubE: \"backflows (set (a # accu)) \\<subseteq> backflows E\" by(simp add: backflows_def, fastforce)\n            from h1 have \"a \\<notin> backflows E\" by fastforce\n            from backaaccusubE `a \\<notin> backflows E` have \"a \\<notin> backflows (insert a (set accu))\" by auto\n\n\n            from `a \\<notin> backflows E` CaseFalse have \"\\<not> (\\<forall>F\\<in>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set (a # accu)\\<rparr>). F \\<subseteq> backflows (set (a # accu)))\" by(simp)\n            from this stateful_to_graph have \"\\<not> (\\<forall>F\\<in>get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = E \\<union> set accu \\<union> backflows (insert a (set accu))\\<rparr>. F \\<subseteq> backflows (insert a (set accu)))\" by(simp)\n            from this hccontr_simp show False by blast\n        qed\n        from  Cons.prems(6)[simplified funapplysimp statefulsimp] this\n        have \"\\<forall>e\\<in>E - (set Es \\<union> set accu \\<union> {e \\<in> E. e \\<in> backflows E}).\n       \\<not> \\<Union>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {e}\\<rparr>)\n          \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = set accu \\<union> {e}\\<rparr>)\"\n          by auto\n\n        from Cons.IH[OF Cons.prems(1) Cons.prems(2) `set Es \\<subseteq> E` `set accu \\<subseteq> E` statefulsimp this]\n        show ?case by simp\n      qed\n   qed\n\n\n\n\n\n\n   \n\n    lemma filter_compliant_stateful_ACS_maximal: \"\\<lbrakk> valid_reqs (get_ACS M); wf_graph \\<lparr> nodes = V, edges = E \\<rparr>;\n            (set edgesList) = E;\n            stateful = set (filter_compliant_stateful_ACS \\<lparr> nodes = V, edges = E \\<rparr> M edgesList)\n            \\<rbrakk> \\<Longrightarrow>\n            \\<forall>e \\<in> E - (stateful \\<union> {e \\<in> E. e \\<in> backflows E}). (* E - {computed stateful flows plus trivial stateful flows} *)\n            \\<not> (\\<Union> get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = E, flows_state = stateful \\<union> {e} \\<rparr>) \n                \\<subseteq> backflows (filternew_flows_state \\<lparr> hosts = V, flows_fix = E, flows_state = stateful \\<union> {e} \\<rparr>))\"\n    apply(drule(1) filter_compliant_stateful_ACS_accu_induction_maximal[where accu=\"[]\", simplified])\n       apply(blast)\n      apply(simp add: filter_compliant_stateful_ACS_def)\n     apply(simp)\n     apply fastforce\n    apply(simp add: filter_compliant_stateful_ACS_def)\n   done\n\n\n    lemma filter_compliant_stateful_ACS_maximal_allsubsets:\n      assumes a1: \"valid_reqs (get_ACS M)\" and a2: \"wf_graph \\<lparr> nodes = V, edges = E \\<rparr>\"\n      and a3: \"(set edgesList) = E\"\n      and a4: \"stateful = set (filter_compliant_stateful_ACS \\<lparr> nodes = V, edges = E \\<rparr> M edgesList)\"\n      and a5: \"X \\<subseteq> E - (stateful \\<union> backflows E)\" and a6: \"X \\<noteq> {}\"\n      shows \"\n      \\<not> (\\<Union> get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr> hosts = V, flows_fix = E, flows_state = stateful \\<union> X \\<rparr>) \n                \\<subseteq> backflows (filternew_flows_state \\<lparr> hosts = V, flows_fix = E, flows_state = stateful \\<union> X \\<rparr>))\"\n    proof(rule ccontr, simp)\n      from a5 have \"X \\<subseteq> E\" by blast\n      assume accontr: \"\\<Union>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> X\\<rparr>) \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> X\\<rparr>)\"\n      hence \"\\<Union>get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = E \\<union> (stateful \\<union> X) \\<union> backflows (stateful \\<union> X)\\<rparr> \\<subseteq> backflows (stateful \\<union> X) - E\"\n      by(simp add: stateful_policy_to_network_graph_def all_flows_def filternew_flows_state_alt backflows_minus_backflows)\n      hence \"\\<Union>get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = E \\<union> X \\<union> backflows (stateful \\<union> X)\\<rparr> \\<subseteq> backflows (stateful \\<union> X) - E\"\n      using a4 a3 filter_compliant_stateful_ACS_subseteq_input by (metis Diff_subset_conv Un_Diff_cancel Un_assoc a3 bot.extremum_unique sup_bot_right)\n      hence accontr_simp: \"\\<Union>get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = E \\<union> (backflows stateful) \\<union> (backflows X)\\<rparr> \\<subseteq> backflows (stateful \\<union> X) - E\"\n      using Set.Un_absorb2[OF `X \\<subseteq> E`] backflows_un[of \"stateful\" \"X\"] by (metis Un_assoc)\n      \n      from a2 a5 have \"finite X\" apply(simp add: wf_graph_def) by (metis (full_types) finite_Diff finite_subset)\n      from a6 obtain x where \"x \\<in> X\" by blast\n\n\n      from `x \\<in> X` a5 have xX_simp1: \"(backflows X) - (backflows (X - {x}) - E)  = backflows {x}\"\n        apply(simp add: backflows_def) by fast\n      from a5 have \"X \\<inter> stateful = {}\" by auto\n      from `x \\<in> X` this have xX_simp2: \"(backflows stateful) - (backflows (X - {x}) - E) = backflows stateful\"\n        apply(simp add: backflows_def) by fast\n      have xX_simp3:\"backflows (stateful \\<union> X) - (backflows (X - {x}) - E) = backflows (stateful \\<union> {x})\"\n        apply(simp only: backflows_un)\n        using xX_simp1 xX_simp2 by blast\n\n      have xX_simp4: \"backflows (stateful \\<union> X) - E - (backflows (X - {x}) - E) = backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> {x}\\<rparr>)\"\n        apply(simp add: filternew_flows_state_alt backflows_minus_backflows)\n        using xX_simp3 by auto\n\n\n      have xX_simp5: \"(E \\<union> backflows stateful \\<union> backflows X) - (backflows (X - {x}) - E) = E \\<union> backflows stateful \\<union> backflows {x}\"\n      using xX_simp3[simplified backflows_un] by blast\n\n      have Eexpand: \"E \\<union> stateful \\<union> {x} = E\" \n      using a4 a3 filter_compliant_stateful_ACS_subseteq_input a5 `x\\<in>X` by blast\n\n      have \"backflows (stateful \\<union> X) - E - backflows (X - {x}) = (backflows (stateful \\<union> X) - E) - backflows (X - {x})\" by simp\n      from `finite X` backflows_finite have finite: \"finite (backflows (X - {x}) - E)\" by auto\n      from a2 a4 a3 filter_compliant_stateful_ACS_subseteq_input have \"wf_graph \\<lparr>nodes = V, edges = stateful\\<rparr>\" by (metis Diff_partition wf_graph_remove_edges_union)\n      from backflows_wf[OF this] have \"wf_graph \\<lparr>nodes = V, edges = backflows stateful\\<rparr>\" .\n      from a2 `X \\<subseteq> E` have \"wf_graph \\<lparr>nodes = V, edges = X\\<rparr>\" by (metis double_diff dual_order.refl wf_graph_remove_edges)\n       from backflows_wf[OF this] have \"wf_graph \\<lparr>nodes = V, edges = backflows X\\<rparr>\" .\n      from this wf_graph_union_edges `wf_graph \\<lparr>nodes = V, edges = backflows stateful\\<rparr>` a2 have wfG: \n        \"wf_graph \\<lparr>nodes = V, edges = E \\<union> backflows stateful \\<union> backflows X\\<rparr>\" by metis\n\n      from `x\\<in>X` have subset: \"backflows (X - {x}) - E \\<subseteq> E \\<union> backflows stateful \\<union> backflows X\" apply(simp add: backflows_def) by fast\n\n      from Un_set_offending_flows_bound_minus_subseteq'[OF a1 wfG subset accontr_simp] have\n        \"\\<Union>get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = (E \\<union> backflows stateful \\<union> backflows X) - (backflows (X - {x}) - E)\\<rparr> \\<subseteq> (backflows (stateful \\<union> X) - E) - (backflows (X - {x}) - E)\" by simp\n      from this xX_simp4 xX_simp5 have trans1:\n        \"\\<Union>get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = E \\<union> backflows stateful \\<union> backflows {x}\\<rparr> \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> {x}\\<rparr>)\" by simp\n\n      hence \"\\<Union>get_offending_flows (get_ACS M) \\<lparr>nodes = V, edges = E \\<union> backflows (stateful \\<union> {x})\\<rparr> \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> {x}\\<rparr>)\"\n      apply(simp only: backflows_un) by (metis Un_assoc)\n      hence contr1: \"\\<Union>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> {x}\\<rparr>) \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> {x}\\<rparr>)\"\n      apply(simp only: stateful_policy_to_network_graph_def all_flows_def stateful_policy.select_convs)\n      using Eexpand by (metis Un_assoc)\n      \n\n      from filter_compliant_stateful_ACS_maximal[OF a1 a2 a3 a4] have\n        \"\\<forall>e\\<in>E - (stateful \\<union> {e \\<in> E. e \\<in> backflows E}). \\<not> \\<Union>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> {e}\\<rparr>) \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> {e}\\<rparr>)\" .\n      from this a5 `x \\<in> X` have contr2: \"\\<not> \\<Union>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> {x}\\<rparr>) \\<subseteq> backflows (filternew_flows_state \\<lparr>hosts = V, flows_fix = E, flows_state = stateful \\<union> {x}\\<rparr>)\" by blast\n\n      from contr1 contr2\n      show \"False\" by simp\n    qed\n\n\n    text{*@{term filter_compliant_stateful_ACS} is correct and maximal*}\n    thm filter_compliant_stateful_ACS_correct filter_compliant_stateful_ACS_maximal\n\n\n    text{*Getting those together. We cannot say @{text \"edgesList = E\"} here because one filters first. I guess filtering ACS first is easier, ...*}\n\n\n\n\n\n\n\n\n\n\n  definition generate_valid_stateful_policy_IFSACS :: \"'v::vertex graph \\<Rightarrow> 'v SecurityInvariant_configured list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> 'v stateful_policy\" where\n    \"generate_valid_stateful_policy_IFSACS G M edgesList \\<equiv> (let filterIFS = filter_IFS_no_violations G M edgesList in\n        (let filterACS = filter_compliant_stateful_ACS G M filterIFS in \\<lparr> hosts = nodes G, flows_fix = edges G, flows_state = set filterACS \\<rparr>))\"\n\n  lemma generate_valid_stateful_policy_IFSACS_wf_stateful_policy: assumes wfG: \"wf_graph G\"\n          and     edgesList: \"(set edgesList) = edges G\"\n          shows \"wf_stateful_policy (generate_valid_stateful_policy_IFSACS G M edgesList)\"\n   proof -\n    from  wfG show ?thesis\n     apply(simp add: generate_valid_stateful_policy_IFSACS_def wf_stateful_policy_def)\n     apply(auto simp add: wf_graph_def)\n     using edgesList filter_IFS_no_violations_subseteq_input filter_compliant_stateful_ACS_subseteq_input by (metis set_rev_mp)\n   qed\n\n   lemma generate_valid_stateful_policy_IFSACS_select_simps:\n   shows \"hosts (generate_valid_stateful_policy_IFSACS G M edgesList) = nodes G\"\n   and   \"flows_fix (generate_valid_stateful_policy_IFSACS G M edgesList) = edges G\"\n   and   \"flows_state (generate_valid_stateful_policy_IFSACS G M edgesList) \\<subseteq> set edgesList\"\n   proof -\n   show  \"hosts (generate_valid_stateful_policy_IFSACS G M edgesList) = nodes G\"\n      by(simp add: generate_valid_stateful_policy_IFSACS_def)\n    show \"flows_fix (generate_valid_stateful_policy_IFSACS G M edgesList) = edges G\"\n      by(simp add: generate_valid_stateful_policy_IFSACS_def)\n    show \"flows_state (generate_valid_stateful_policy_IFSACS G M edgesList) \\<subseteq> set edgesList\"\n      apply(simp add: generate_valid_stateful_policy_IFSACS_def)\n      using filter_IFS_no_violations_subseteq_input filter_compliant_stateful_ACS_subseteq_input by (metis subset_trans)\n    qed\n\n  lemma generate_valid_stateful_policy_IFSACS_all_security_requirements_fulfilled_IFS: assumes validReqs: \"valid_reqs M\"\n          and     wfG: \"wf_graph G\"\n          and     high_level_policy_valid: \"all_security_requirements_fulfilled M G\"\n          and     edgesList: \"(set edgesList) \\<subseteq> edges G\"\n          shows \"all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph (generate_valid_stateful_policy_IFSACS G M edgesList))\"\n  proof -\n   have simp3: \"flows_state (generate_valid_stateful_policy_IFSACS G M edgesList) \\<subseteq> edges G\" using generate_valid_stateful_policy_IFSACS_select_simps(3) edgesList by fast\n\n    have \"set (filter_compliant_stateful_ACS G M (filter_IFS_no_violations G M edgesList)) \\<subseteq> set (filter_IFS_no_violations G M edgesList)\"\n      using filter_compliant_stateful_ACS_subseteq_input edgesList by (metis)\n    from backflows_subseteq this have \n      \"backflows (set (filter_compliant_stateful_ACS G M (filter_IFS_no_violations G M edgesList))) \\<subseteq> backflows (set (filter_IFS_no_violations G M edgesList))\" by metis\n    hence subseteqhlp1:\n      \"edges G \\<union> backflows (set (filter_compliant_stateful_ACS G M (filter_IFS_no_violations G M edgesList))) \\<subseteq> edges G \\<union> backflows (set (filter_IFS_no_violations G M edgesList))\" by blast\n\n    from high_level_policy_valid have \"all_security_requirements_fulfilled (get_IFS M) G\" by(simp add: all_security_requirements_fulfilled_def get_IFS_def)\n    from filter_IFS_no_violations_correct[OF valid_reqs_IFS_D[OF validReqs] wfG this edgesList] have \n      \"all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = set (filter_IFS_no_violations G M edgesList)\\<rparr>)\" .\n      from this edgesList have goalIFS:\n        \"all_security_requirements_fulfilled (get_IFS M) \\<lparr>nodes = nodes G, edges = edges G \\<union> backflows (set (filter_IFS_no_violations G M edgesList))\\<rparr>\"\n        apply(simp add: stateful_policy_to_network_graph_def all_flows_def)\n        by (metis Un_absorb2 filter_IFS_no_violations_subseteq_input order_trans)\n\n\n      from  wfG filter_IFS_no_violations_subseteq_input[where Es=\"edgesList\" and G=\"G\" and M=\"M\"] edgesList have \n        \"wf_graph \\<lparr>nodes = nodes G, edges = set (filter_IFS_no_violations G M edgesList)\\<rparr>\" \n         apply(case_tac G, simp)\n         by (metis le_iff_sup wf_graph_remove_edges_union)\n      from backflows_wf[OF this] have\n        \"wf_graph \\<lparr>nodes = nodes G, edges = backflows (set (filter_IFS_no_violations G M edgesList))\\<rparr>\" by(simp)\n      from this wf_graph_union_edges wfG have \n        \"wf_graph \\<lparr>nodes = nodes G, edges = edges G \\<union> backflows (set (filter_IFS_no_violations G M edgesList))\\<rparr>\" \n        by (metis graph.cases graph.select_convs(1) graph.select_convs(2))\n\n      from all_security_requirements_fulfilled_mono[OF valid_reqs_IFS_D[OF validReqs] subseteqhlp1 this goalIFS]\n        have \"all_security_requirements_fulfilled (get_IFS M) \\<lparr>nodes = nodes G, edges = edges G \\<union> backflows (set (filter_compliant_stateful_ACS G M (filter_IFS_no_violations G M edgesList)))\\<rparr>\"\n        .\n      thus ?thesis\n        apply(simp add: stateful_policy_to_network_graph_def all_flows_def generate_valid_stateful_policy_IFSACS_select_simps simp3 Un_absorb2)\n        by(simp add: generate_valid_stateful_policy_IFSACS_def)\n  qed\n\n  theorem generate_valid_stateful_policy_IFSACS_stateful_policy_compliance:\n  assumes validReqs: \"valid_reqs M\"\n        and     wfG: \"wf_graph G\"\n        and     high_level_policy_valid: \"all_security_requirements_fulfilled M G\"\n        and     edgesList: \"(set edgesList) = edges G\"\n        and     Tau: \"\\<T> = generate_valid_stateful_policy_IFSACS G M edgesList\"\n    shows \"stateful_policy_compliance \\<T> G M\"\n    proof -\n      have 1: \"wf_stateful_policy \\<T>\"\n        apply(simp add: Tau)\n        by(simp add: generate_valid_stateful_policy_IFSACS_wf_stateful_policy[OF wfG edgesList])\n      have 2: \"wf_stateful_policy (generate_valid_stateful_policy_IFSACS G M edgesList)\"\n        by(simp add: generate_valid_stateful_policy_IFSACS_wf_stateful_policy[OF wfG edgesList])\n      have 3: \"hosts \\<T> = nodes G\"\n        apply(simp add: Tau)\n        by(simp add: generate_valid_stateful_policy_IFSACS_select_simps(1))\n      have 4: \"flows_fix \\<T> \\<subseteq> edges G\"\n        apply(simp add: Tau)\n        by(simp add: generate_valid_stateful_policy_IFSACS_select_simps(2))\n      have 5: \" all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<T>)\"\n        apply(simp add: Tau)\n        using generate_valid_stateful_policy_IFSACS_all_security_requirements_fulfilled_IFS[OF validReqs wfG high_level_policy_valid] edgesList by blast\n      have 6: \"\\<forall>F\\<in>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<T>). F \\<subseteq> backflows (filternew_flows_state \\<T>)\"\n        using filter_compliant_stateful_ACS_correct[OF valid_reqs_ACS_D[OF validReqs] wfG _ _ Tau[simplified generate_valid_stateful_policy_IFSACS_def Let_def]] all_security_requirements_fulfilled_ACS_D[OF high_level_policy_valid]\n        edgesList filter_IFS_no_violations_subseteq_input by metis\n\n    from 1 2 3 4 5 6 validReqs high_level_policy_valid wfG\n    show ?thesis\n    unfolding stateful_policy_compliance_def by simp\n  qed\n\n\n\n\n\n  definition generate_valid_stateful_policy_IFSACS_2 :: \"'v::vertex graph \\<Rightarrow> 'v SecurityInvariant_configured list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> 'v stateful_policy\" where\n    \"generate_valid_stateful_policy_IFSACS_2 G M edgesList \\<equiv> \n    \\<lparr> hosts = nodes G, flows_fix = edges G, flows_state = set (filter_IFS_no_violations G M edgesList) \\<inter> set (filter_compliant_stateful_ACS G M edgesList) \\<rparr>\"\n\n\n  lemma generate_valid_stateful_policy_IFSACS_2_wf_stateful_policy: assumes wfG: \"wf_graph G\"\n          and     edgesList: \"(set edgesList) = edges G\"\n          shows \"wf_stateful_policy (generate_valid_stateful_policy_IFSACS_2 G M edgesList)\"\n   proof -\n    from  wfG show ?thesis\n     apply(simp add: generate_valid_stateful_policy_IFSACS_2_def wf_stateful_policy_def)\n     apply(auto simp add: wf_graph_def)\n     using edgesList filter_IFS_no_violations_subseteq_input by (metis set_rev_mp)\n   qed\n\n   lemma generate_valid_stateful_policy_IFSACS_2_select_simps:\n   shows \"hosts (generate_valid_stateful_policy_IFSACS_2 G M edgesList) = nodes G\"\n   and   \"flows_fix (generate_valid_stateful_policy_IFSACS_2 G M edgesList) = edges G\"\n   and   \"flows_state (generate_valid_stateful_policy_IFSACS_2 G M edgesList) \\<subseteq> set edgesList\"\n   proof -\n   show  \"hosts (generate_valid_stateful_policy_IFSACS_2 G M edgesList) = nodes G\"\n      by(simp add: generate_valid_stateful_policy_IFSACS_2_def)\n    show \"flows_fix (generate_valid_stateful_policy_IFSACS_2 G M edgesList) = edges G\"\n      by(simp add: generate_valid_stateful_policy_IFSACS_2_def)\n    show \"flows_state (generate_valid_stateful_policy_IFSACS_2 G M edgesList) \\<subseteq> set edgesList\"\n      apply(simp add: generate_valid_stateful_policy_IFSACS_2_def)\n      using filter_compliant_stateful_ACS_subseteq_input by (metis inf.coboundedI2)\n    qed\n\n  lemma generate_valid_stateful_policy_IFSACS_2_all_security_requirements_fulfilled_IFS: assumes validReqs: \"valid_reqs M\"\n          and     wfG: \"wf_graph G\"\n          and     high_level_policy_valid: \"all_security_requirements_fulfilled M G\"\n          and     edgesList: \"(set edgesList) \\<subseteq> edges G\"\n          shows \"all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph (generate_valid_stateful_policy_IFSACS_2 G M edgesList))\"\n  proof -\n    have subseteq: \"set (filter_IFS_no_violations G M edgesList) \\<inter> set (filter_compliant_stateful_ACS G M edgesList) \\<subseteq> set (filter_IFS_no_violations G M edgesList)\" by blast\n\n    from wfG filter_IFS_no_violations_subseteq_input edgesList\n    have wfG': \"wf_graph \\<lparr>nodes = nodes G, edges = edges G \\<union> set (filter_IFS_no_violations G M edgesList)\\<rparr>\" \n      by (metis graph_eq_intro Un_absorb2 graph.select_convs(1) graph.select_convs(2) order.trans)\n\n    from high_level_policy_valid have \"all_security_requirements_fulfilled (get_IFS M) G\" by(simp add: all_security_requirements_fulfilled_def get_IFS_def)\n    from filter_IFS_no_violations_correct[OF valid_reqs_IFS_D[OF validReqs] wfG this edgesList] have \n      \"all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = set (filter_IFS_no_violations G M edgesList)\\<rparr>)\" .\n\n\n    from all_security_requirements_fulfilled_mono_stateful_policy_to_network_graph[OF valid_reqs_IFS_D[OF validReqs] subseteq wfG' this]\n    have \"all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph (generate_valid_stateful_policy_IFSACS_2 G M edgesList))\"\n      by(simp add: generate_valid_stateful_policy_IFSACS_2_def)\n    thus ?thesis .\n  qed\n\n\n  lemma generate_valid_stateful_policy_IFSACS_2_filter_compliant_stateful_ACS:\n  assumes validReqs: \"valid_reqs M\"\n        and     wfG: \"wf_graph G\"\n        and     high_level_policy_valid: \"all_security_requirements_fulfilled M G\"\n        and     edgesList: \"(set edgesList) \\<subseteq> edges G\"\n        and     Tau: \"\\<T> = generate_valid_stateful_policy_IFSACS_2 G M edgesList\"\n  shows \"\\<forall>F\\<in>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<T>). F \\<subseteq> backflows (filternew_flows_state \\<T>)\"\n    proof- \n      let ?filterACS = \"set (filter_compliant_stateful_ACS G M edgesList)\"\n      let ?filterIFS = \"set (filter_IFS_no_violations G M edgesList)\"\n      from all_security_requirements_fulfilled_ACS_D[OF high_level_policy_valid] have \"all_security_requirements_fulfilled (get_ACS M) G\" .\n\n      from filter_compliant_stateful_ACS_correct[OF valid_reqs_ACS_D[OF validReqs] wfG edgesList this] have \n        \"\\<forall>F\\<in>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph  \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = ?filterACS\\<rparr>). \n          F \\<subseteq> backflows (?filterACS) - edges G\"\n        apply(simp)\n        apply(simp add: backflows_minus_backflows[symmetric])\n        by(simp add: filternew_flows_state_alt)\n      hence \"\\<forall>F\\<in>get_offending_flows (get_ACS M) \\<lparr>nodes = nodes G, edges = edges G \\<union> backflows (?filterACS)\\<rparr>. F \\<subseteq> backflows (?filterACS) - edges G\"\n        apply(simp add: stateful_policy_to_network_graph_def all_flows_def)\n        using filter_compliant_stateful_ACS_subseteq_input by (metis (lifting, no_types) Un_absorb2 edgesList order_trans)\n      from this validReqs have offending_filterACS_upperbound:\n        \"\\<And>m. m \\<in> set (get_ACS M) \\<Longrightarrow> \n        \\<Union>c_offending_flows m \\<lparr>nodes = nodes G, edges = edges G \\<union> backflows (?filterACS)\\<rparr> \\<subseteq> \n          backflows (?filterACS) - edges G\"\n        by(simp add: valid_reqs_def get_offending_flows_def, blast)\n\n      from wfG filter_compliant_stateful_ACS_subseteq_input edgesList have \"wf_graph \\<lparr>nodes = nodes G, edges = ?filterACS\\<rparr>\"\n        by (metis graph.cases graph.select_convs(1) graph.select_convs(2) le_iff_sup wf_graph_remove_edges_union)\n      from this backflows_wf have \"wf_graph \\<lparr>nodes = nodes G, edges = backflows (?filterACS)\\<rparr>\" by blast\n      moreover have \"wf_graph \\<lparr>nodes = nodes G, edges = edges G\\<rparr>\" using wfG by(case_tac G, simp)\n      ultimately have wfG1: \"wf_graph \\<lparr>nodes = nodes G, edges = edges G \\<union> backflows (?filterACS)\\<rparr>\"\n        using wf_graph_union_edges by blast\n        \n      from edgesList have edgesUnsimp: \"edges G \\<union> (?filterACS \\<inter> ?filterIFS) = edges G\"\n        using filter_IFS_no_violations_subseteq_input filter_compliant_stateful_ACS_subseteq_input by blast\n\n      --\"We set up a ?REM that we use in the @{thm configured_SecurityInvariant.Un_set_offending_flows_bound_minus_subseteq} lemma\"\n      let ?REM = \"(backflows (?filterACS) - backflows (?filterIFS)) - edges G\"\n\n      have REM_gives_desired_upper_bound: \"(backflows (?filterACS) - edges G) - ?REM = backflows (?filterACS \\<inter> ?filterIFS) - edges G\"\n        by(simp add: backflows_def, blast)\n\n      have REM_gives_desired_edges: \"(edges G \\<union> backflows (?filterACS)) - ?REM = edges G \\<union> (backflows (?filterACS \\<inter> ?filterIFS))\"\n        by(simp add: backflows_def, blast)\n\n      from wfG have \"finite (edges G)\" using wf_graph_def by blast\n      hence \"finite (backflows ?filterACS)\" using backflows_finite by (metis List.finite_set)\n      hence finite1: \"finite (backflows (?filterACS) - backflows (?filterIFS) - edges G)\" by fast\n\n      from configured_SecurityInvariant.Un_set_offending_flows_bound_minus_subseteq[where E'=\"?REM\" and X=\"(backflows (?filterACS) - edges G)\",\n          OF _ wfG1 offending_filterACS_upperbound, simplified REM_gives_desired_upper_bound REM_gives_desired_edges\n          ] valid_reqs_ACS_D[OF validReqs, unfolded valid_reqs_def]\n      have \"\\<And>m. m \\<in> set (get_ACS M) \\<Longrightarrow>\n              \\<forall>F\\<in>c_offending_flows m \\<lparr>nodes = nodes G, edges = edges G \\<union> backflows (?filterACS \\<inter> ?filterIFS)\\<rparr>.\n                  F \\<subseteq> backflows (?filterACS \\<inter> ?filterIFS) - edges G\" by blast\n      hence \"\\<forall>F\\<in>get_offending_flows (get_ACS M)\n         \\<lparr>nodes = nodes G, edges = edges G \\<union> (backflows (?filterACS \\<inter> ?filterIFS))\\<rparr>. F \\<subseteq> backflows (?filterACS \\<inter> ?filterIFS) - edges G\"\n       using get_offending_flows_def by fast\n      hence \"\\<forall>F\\<in>get_offending_flows (get_ACS M)\n         \\<lparr>nodes = nodes G, edges = edges G \\<union> (?filterACS \\<inter> ?filterIFS) \\<union> (backflows (?filterACS \\<inter> ?filterIFS))\\<rparr>.\n       F \\<subseteq> backflows (?filterACS \\<inter> ?filterIFS) - edges G\"\n        by(simp add: edgesUnsimp)\n      hence \"\\<forall>F\\<in>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<lparr>hosts = nodes G, flows_fix = edges G, flows_state = ?filterACS \\<inter> ?filterIFS\\<rparr>).\n                F \\<subseteq> backflows (?filterACS \\<inter> ?filterIFS) - edges G\"\n        by(simp add: stateful_policy_to_network_graph_def all_flows_def)\n\n      thus ?thesis\n        apply(simp add: Tau generate_valid_stateful_policy_IFSACS_2_def)\n        apply(simp add: filternew_flows_state_alt backflows_minus_backflows)\n        by (metis inf_commute)\n    qed\n        \n\n\n\n\n  theorem generate_valid_stateful_policy_IFSACS_2_stateful_policy_compliance:\n  assumes validReqs: \"valid_reqs M\"\n        and     wfG: \"wf_graph G\"\n        and     high_level_policy_valid: \"all_security_requirements_fulfilled M G\"\n        and     edgesList: \"(set edgesList) = edges G\"\n        and     Tau: \"\\<T> = generate_valid_stateful_policy_IFSACS_2 G M edgesList\"\n    shows \"stateful_policy_compliance \\<T> G M\"\n    proof -\n      have 1: \"wf_stateful_policy \\<T>\"\n        apply(simp add: Tau)\n        by(simp add: generate_valid_stateful_policy_IFSACS_2_wf_stateful_policy[OF wfG edgesList])\n      have 2: \"wf_stateful_policy (generate_valid_stateful_policy_IFSACS G M edgesList)\"\n        by(simp add: generate_valid_stateful_policy_IFSACS_wf_stateful_policy[OF wfG edgesList])\n      have 3: \"hosts \\<T> = nodes G\"\n        apply(simp add: Tau)\n        by(simp add: generate_valid_stateful_policy_IFSACS_2_select_simps(1))\n      have 4: \"flows_fix \\<T> \\<subseteq> edges G\"\n        apply(simp add: Tau)\n        by(simp add: generate_valid_stateful_policy_IFSACS_2_select_simps(2))\n      have 5: \"all_security_requirements_fulfilled (get_IFS M) (stateful_policy_to_network_graph \\<T>)\"\n        apply(simp add: Tau)\n        using generate_valid_stateful_policy_IFSACS_2_all_security_requirements_fulfilled_IFS[OF validReqs wfG high_level_policy_valid] edgesList by blast\n      have 6: \"\\<forall>F\\<in>get_offending_flows (get_ACS M) (stateful_policy_to_network_graph \\<T>). F \\<subseteq> backflows (filternew_flows_state \\<T>)\"\n        using generate_valid_stateful_policy_IFSACS_2_filter_compliant_stateful_ACS[OF \n            validReqs wfG high_level_policy_valid]\n        Tau edgesList by auto\n\n    from 1 2 3 4 5 6 validReqs high_level_policy_valid wfG\n    show ?thesis\n    unfolding stateful_policy_compliance_def by simp\n  qed\n\n\n\n\n\n  text{*\n    If there are no IFS requirements and the ACS requirements cause no side effects,\n    effectively, the graph can be considered as undirected graph! \n  *}\n  lemma generate_valid_stateful_policy_IFSACS_2_noIFS_noACSsideeffects_imp_fullgraph:\n  assumes validReqs: \"valid_reqs M\"\n        and     wfG: \"wf_graph G\"\n        and     high_level_policy_valid: \"all_security_requirements_fulfilled M G\"\n        and     edgesList: \"(set edgesList) = edges G\"\n        and     no_ACS_sideeffects: \"\\<forall>F \\<in> get_offending_flows (get_ACS M) \\<lparr>nodes = nodes G, edges = edges G \\<union> backflows (edges G)\\<rparr>. F \\<subseteq> (backflows (edges G)) - (edges G)\"\n        and     no_IFS: \"get_IFS M = []\"\n  shows \"stateful_policy_to_network_graph (generate_valid_stateful_policy_IFSACS_2 G M edgesList) = undirected G\"\n  proof -\n    from filter_IFS_no_violations_accu_no_IFS[OF valid_reqs_IFS_D[OF validReqs] wfG no_IFS] edgesList\n      have \"filter_IFS_no_violations G M edgesList = rev edgesList\"\n      by(simp add: filter_IFS_no_violations_def)\n    from this filter_compliant_stateful_ACS_subseteq_input have flows_state_IFS: \"flows_state (generate_valid_stateful_policy_IFSACS_2 G M edgesList) = set (filter_compliant_stateful_ACS G M edgesList)\"\n      by(auto simp add: generate_valid_stateful_policy_IFSACS_2_def)\n\n    have flowsfix: \"flows_fix (generate_valid_stateful_policy_IFSACS_2 G M edgesList) = edges G\" by(simp add: generate_valid_stateful_policy_IFSACS_2_def)\n\n    have hosts: \"hosts (generate_valid_stateful_policy_IFSACS_2 G M edgesList) = nodes G\" by(simp add: generate_valid_stateful_policy_IFSACS_2_def)\n\n    from filter_compliant_stateful_ACS_accu_no_side_effects[OF valid_reqs_ACS_D[OF validReqs] wfG no_ACS_sideeffects] have \n      \"filter_compliant_stateful_ACS G M edgesList = rev [e\\<leftarrow>edgesList . e \\<notin> backflows (edges G)]\"\n      by(simp add: filter_compliant_stateful_ACS_def edgesList)\n    hence filterACS: \"set (filter_compliant_stateful_ACS G M edgesList) = edges G - (backflows (edges G))\" using edgesList by force\n\n    show ?thesis\n      apply(simp add: undirected_backflows stateful_policy_to_network_graph_def all_flows_def)\n      apply(simp add: hosts filterACS flows_state_IFS flowsfix)\n      apply(simp add: backflows_minus_backflows)\n      by fast\n    qed\n  lemma generate_valid_stateful_policy_IFSACS_noIFS_noACSsideeffects_imp_fullgraph:\n  assumes validReqs: \"valid_reqs M\"\n        and     wfG: \"wf_graph G\"\n        and     high_level_policy_valid: \"all_security_requirements_fulfilled M G\"\n        and     edgesList: \"(set edgesList) = edges G\"\n        and     no_ACS_sideeffects: \"\\<forall>F \\<in> get_offending_flows (get_ACS M) \\<lparr>nodes = nodes G, edges = edges G \\<union> backflows (edges G)\\<rparr>. F \\<subseteq> (backflows (edges G)) - (edges G)\"\n        and     no_IFS: \"get_IFS M = []\"\n  shows \"stateful_policy_to_network_graph (generate_valid_stateful_policy_IFSACS G M edgesList) = undirected G\"\n  proof -\n    from filter_IFS_no_violations_accu_no_IFS[OF valid_reqs_IFS_D[OF validReqs] wfG no_IFS] edgesList\n      have \"filter_IFS_no_violations G M edgesList = rev edgesList\"\n      by(simp add: filter_IFS_no_violations_def)\n    from this filter_compliant_stateful_ACS_subseteq_input have flows_state_IFS: \"flows_state (generate_valid_stateful_policy_IFSACS G M edgesList) = set (filter_compliant_stateful_ACS G M (rev edgesList))\"\n      by(simp add: generate_valid_stateful_policy_IFSACS_def)\n\n    have flowsfix: \"flows_fix (generate_valid_stateful_policy_IFSACS G M edgesList) = edges G\" by(simp add: generate_valid_stateful_policy_IFSACS_def)\n\n    have hosts: \"hosts (generate_valid_stateful_policy_IFSACS G M edgesList) = nodes G\" by(simp add: generate_valid_stateful_policy_IFSACS_def)\n\n    from filter_compliant_stateful_ACS_accu_no_side_effects[OF valid_reqs_ACS_D[OF validReqs] wfG no_ACS_sideeffects] have \n      \"filter_compliant_stateful_ACS G M (rev edgesList) = [e\\<leftarrow>edgesList . e \\<notin> backflows (edges G)]\"\n      apply(simp add: filter_compliant_stateful_ACS_def edgesList) by (metis rev_filter rev_swap)\n    hence filterACS: \"set (filter_compliant_stateful_ACS G M (rev edgesList)) = edges G - (backflows (edges G))\" using edgesList by force\n\n    show ?thesis\n      apply(simp add: undirected_backflows stateful_policy_to_network_graph_def all_flows_def)\n      apply(simp add: hosts filterACS flows_state_IFS flowsfix)\n      apply(simp add: backflows_minus_backflows)\n      by fast\n    qed\n\n\n(*\ntext{* In the repo history, we see failed attempts which try to prove that under composition, the IFS and ACS filtering is also maximal.\n       I guess this does not hold in general. Needs a counter example. *}\n\n*)\nend\n", "meta": {"author": "diekmann", "repo": "topoS", "sha": "4303ebd95a501283c02fd513c109e645a48ad080", "save_path": "github-repos/isabelle/diekmann-topoS", "path": "github-repos/isabelle/diekmann-topoS/topoS-4303ebd95a501283c02fd513c109e645a48ad080/thy/Network_Security_Policy_Verification/TopoS_Stateful_Policy_Algorithm.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6370308082623217, "lm_q2_score": 0.43014734858584286, "lm_q1q2_score": 0.27401711314153415}}
{"text": "section \\<open>Sets Bounded by a Finite Cardinal $>2$ Are Not BNFs\\<close>\n\n(*<*)\ntheory Finitely_Bounded_Set_Counterexample\nimports\n  \"HOL-Cardinals.Cardinals\"\nbegin\n(*>*)\n\ntext \\<open>Do not import this theory. It contains an inconsistent axiomatization.\nThe point is to exhibit the particular inconsistency.\\<close>\n\ntypedef ('a, 'k) bset (\"_ set[_]\" [22, 21] 21) =\n  \"{A :: 'a set. |A| <o |UNIV :: 'k set|}\"\n  morphisms set_bset Abs_bset\n  by (rule exI[of _ \"{}\"]) (auto simp: card_of_empty4 csum_def)\n\nsetup_lifting type_definition_bset\n\nlift_definition map_bset ::\n  \"('a \\<Rightarrow> 'b) \\<Rightarrow> 'a set['k] \\<Rightarrow> 'b set['k]\" is image\n  using card_of_image ordLeq_ordLess_trans by blast\n\ninductive rel_bset :: \"('a \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow> ('a, 'k) bset \\<Rightarrow> ('b, 'k) bset \\<Rightarrow> bool\" for R where\n  \"set_bset x \\<subseteq> {(x, y). R x y} \\<Longrightarrow> rel_bset R (map_bset fst x) (map_bset snd x)\"\n\ntext \\<open>\nWe axiomatize the relator commutation property and show that we can deduce @{term False} from it.\n\nWe cannot do this with a locale, since we need the fully polymorphic version of the following axiom.\n\\<close>\n\naxiomatization where\n  inconsistent: \"rel_bset R1 OO rel_bset R2 \\<le> rel_bset (R1 OO R2)\"\n\nbnf \"('a, 'k) bset\"\n  map: map_bset\n  sets: set_bset\n  bd: \"natLeq +c card_suc ( |UNIV :: 'k set| )\"\n  rel: rel_bset\nproof (standard, goal_cases)\n  case 1 then show ?case\n    by transfer simp\nnext\n  case 2 then show ?case\n    apply (rule ext)\n    apply transfer\n    apply auto\n    done\nnext\n  case 3 then show ?case\n    apply transfer\n    apply (auto simp: image_iff)\n    done\nnext\n  case 4 then show ?case\n    apply (rule ext)\n    apply transfer\n    apply simp\n    done\nnext\n  case 5 then show ?case by (rule card_order_bd_fun)\nnext\n  case 6 then show ?case by (rule Cinfinite_bd_fun[THEN conjunct1])\nnext\n  case 7 then show ?case by (rule regularCard_bd_fun)\nnext\n  case 8 then show ?case\n    by transfer\n      (erule ordLess_ordLeq_trans[OF _ ordLeq_transitive[OF _ ordLeq_csum2]];\n        simp add: card_suc_greater ordLess_imp_ordLeq Card_order_card_suc)\nnext\n  case 9 then show ?case by (rule inconsistent) \\<comment> \\<open>BAAAAAMMMM\\<close>\nnext\n  case 10 then show ?case\n    by (auto simp: fun_eq_iff intro: rel_bset.intros elim: rel_bset.cases)\nqed\n\nlemma card_option_finite[simp]:\n  assumes \"finite (UNIV :: 'k set)\"\n  shows \"card (UNIV :: 'k option set) = Suc (card (UNIV :: 'k set))\"\n  (is \"card ?L = Suc (card ?R)\")\nproof -\n  have \"card ?L = Suc (card (?L - {None}))\" by (rule card.remove) (auto simp: assms)\n  also have \"card (?L - {None}) = card ?R\"\n    by (rule bij_betw_same_card[of the])\n      (auto simp: bij_betw_def inj_on_def image_iff intro!: bexI[of _ \"Some x\" for x])\n  finally show ?thesis .\nqed\n\ndatatype ('a :: enum) x = A | B \"'a option\" | C\n\nabbreviation \"Bs \\<equiv> B ` (insert None (Some ` set Enum.enum))\"\n\nlemma UNIV_x[simp]:\n  \"(UNIV :: ('a :: enum) x set) = {A, C} \\<union> Bs\"\n  (is \"_ = ?R\")\nproof (intro set_eqI iffI)\n  fix x :: \"'a x\" show \"x \\<in> ?R\" by (cases x) (auto simp add: enum_UNIV)\nqed simp\n\nlemma Collect_split_in_rel: \"{(x, y). in_rel R x y} = R\"\n  by auto\n\nlift_definition X :: \"('a :: enum x, 'a x) bset\" is \"insert A Bs\"\n  by (subst finite_card_of_iff_card3) (auto simp: card.insert_remove card_Diff_singleton_if)\n\nlift_definition Y :: \"('a :: enum x, 'a x) bset\" is \"insert C Bs\"\n  by (subst finite_card_of_iff_card3) (auto simp: card.insert_remove card_Diff_singleton_if)\n\nlift_definition Z :: \"('a :: enum x, 'a x) bset\" is \"{A, C}\"\n  by (subst finite_card_of_iff_card3) (auto simp: card.insert_remove card_Diff_singleton_if)\n\nlift_definition R :: \"('a x \\<times> 'a x, 'a :: enum x) bset\" is \"insert (A, A) ((\\<lambda>B. (B, C)) ` Bs)\"\n  by (subst finite_card_of_iff_card3)\n    (auto simp: card.insert_remove card_Diff_singleton_if image_iff card_image inj_on_def)\n\nlift_definition S :: \"('a x \\<times> 'a x, 'a :: enum x) bset\" is \"insert (C, C) ((\\<lambda>B. (A, B)) ` Bs)\"\n  by (subst finite_card_of_iff_card3)\n    (auto simp: card.insert_remove card_Diff_singleton_if image_iff card_image inj_on_def)\n\nlift_definition in_brel :: \"('a \\<times> 'b, 'k) bset \\<Rightarrow> 'a \\<Rightarrow> 'b \\<Rightarrow> bool\" is in_rel .\n\nlemma False\nproof -\n  have \"rel_bset (in_brel R) X Z\"\n    unfolding bset.in_rel mem_Collect_eq\n    apply (intro exI[of _ R])\n    apply transfer\n    apply (auto simp: image_iff)\n    done\n  moreover\n  have \"rel_bset (in_brel S) Z Y\"\n    unfolding bset.in_rel mem_Collect_eq\n    apply (intro exI[of _ S])\n    apply transfer\n    apply (auto simp: image_iff)\n    done\n  ultimately have \"rel_bset (in_brel R OO in_brel S) X Y\"\n    unfolding bset.rel_compp by blast\n  moreover\n  have *: \"insert (A, A) ((\\<lambda>B. (B, C)) ` Bs) O insert (C, C) ((\\<lambda>B. (A, B)) ` Bs) =\n    ((\\<lambda>B. (B, C)) ` Bs) \\<union> ((\\<lambda>B. (A, B)) ` Bs)\" (is \"_ = ?RS\" ) by auto\n  have \"\\<not> rel_bset (in_brel R OO in_brel S) X Y\"\n  unfolding bset.in_rel mem_Collect_eq\n  proof (transfer, safe, unfold relcompp_in_rel * Collect_split_in_rel)\n    fix Z :: \"('a :: enum x \\<times> 'a x) set\"\n    note enum_UNIV[simp] UNIV_option_conv[symmetric, simp]\n    assume \"Z \\<subseteq> ?RS\" \"fst ` Z = insert A Bs\" \"snd ` Z = insert C Bs\"\n    then have \"Z = ?RS\" unfolding fst_eq_Domain snd_eq_Range by auto\n    moreover assume \"|Z| <o |UNIV :: 'a x set|\"\n    ultimately show False unfolding \\<open>Z = ?RS\\<close>\n      by (subst (asm) finite_card_of_iff_card3, simp, simp, subst (asm) card_Un_disjoint)\n        (auto simp: card.insert_remove card_Diff_singleton_if card_image inj_on_def split: if_splits)\n  qed\n  ultimately show False by blast\nqed\n\n(*<*)\nend\n(*>*)\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Probabilistic_System_Zoo/Finitely_Bounded_Set_Counterexample.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6370307944803831, "lm_q2_score": 0.43014734858584286, "lm_q1q2_score": 0.2740171072132698}}
{"text": "(*\n * Copyright 2018-2019, NTU\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n *  Author: Albert Rizaldi, NTU Singapore\n *)\n\ntheory VHDL_Hoare\n  imports Femto_VHDL_raw\nbegin\n\ntext \\<open>This theory is the first attempt for defining a Hoare logic for VHDL sequential statement.\nAs the exploration continues, I realise that we can only prove the soundness in this first attempt\nbut not the completeness. The second attempt is shown in @{theory_text \"VHDL_Hoare_Complete\"}. Even\nthough we cannot show that it is complete, many theorems and definitions in this theory are useful\nfor defining a sound and complete Hoare logic in @{theory_text \"VHDL_Hoare_Complete\"}.\\<close>\n\nsubsection \\<open>Hoare Logic for @{typ \"'signal seq_stmt\"}\\<close>\n\ntype_synonym 'signal worldline      = \"'signal \\<Rightarrow> nat \\<Rightarrow> val\"\ntype_synonym 'signal worldline_init = \"'signal state \\<times> ('signal \\<Rightarrow> nat \\<Rightarrow> val)\"\n\n\ntext \\<open>The type @{typ \"'signal worldline\"} represent the concept of ``worlds'' which are required\nfor the axiomatic semantics of VHDL specified in @{cite Breuer1995}. As can be seen from the\ndefinition, this type represents a function with two arguments: @{term \"signal :: 'signal\"} and\n@{term \"time :: nat\"} to a set of value.\n\nCompared to the standard ``worlds'' for defining the axiomatic semantics of sequential programming\nlanguage --- e.g. @{typ \"'variable \\<Rightarrow> val\"} --- we have added the notion of @{term \"time :: nat\"}\nhere. For example, when we do assignment in VHDL, we can specify the time when this assignment will\nhappen in the future. This construct is, of course, absent from the typical assignment in sequential\nprogramming language where assignments happen instantaneously. It is due to this notion of time, we\nadd a suffix ``line'' in the type @{typ \"'signal worldline\"}.\n\nWhat is the relationship between @{typ \"'signal worldline\"} with the context @{term \"\\<sigma> :: 'signal\nstate\"}, @{term \"\\<gamma> :: 'signal event\"}, @{term \"\\<theta> :: 'signal trans_raw\"}, @{term \"\\<tau>' \\<tau> :: 'signal\ntrans_raw\"} in the semantics @{term \"t, \\<sigma>, \\<gamma>, \\<theta>, def \\<turnstile> < ss, \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\"}? The answer is that the latter\nis the refined version of the former. We shall show the formal relationship later in this theory.\n\\<close>\n\ndefinition worldline_upd :: \"'signal worldline_init \\<Rightarrow> 'signal \\<Rightarrow> nat \\<Rightarrow> val \\<Rightarrow> 'signal worldline_init\"\n  (\"_[_, _:= _]\") where\n  \"worldline_upd w s t v = (fst w, \\<lambda>s' t'. if s' \\<noteq> s \\<or> t' < t then snd w s' t' else v)\"\n\ndefinition worldline_inert_upd :: \"'signal worldline_init \\<Rightarrow> 'signal \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> val \\<Rightarrow> 'signal worldline_init\"\n  (\"_[_, _, _ := _]\") where\n  \"worldline_inert_upd w s t dly v = (fst w,\n    (\\<lambda>s' t'. let\n                time = if snd w s t = v \\<or> snd w s (t + dly) \\<noteq> v then t + dly\n                       else GREATEST n. n \\<le> t + dly \\<and> (snd w s (n - 1) \\<noteq> v) \\<and> snd w s n = v\n             in\n                if s' \\<noteq> s \\<or> t' < t then snd w s' t' else if t' < time then snd w s' t  else v))\"\n\ndefinition to_worldline_init_bit :: \"'signal worldline_init \\<Rightarrow> 'signal \\<Rightarrow> nat \\<Rightarrow> 'signal worldline_init\" where\n  \"to_worldline_init_bit w sig b = ((fst w)(sig := to_bit b (fst w sig)),  \n                                    (snd w)(sig := to_bit b o (snd w sig)))\"\n\nfun worldline_inert_upd2 :: \"'signal worldline_init \\<Rightarrow> 'signal \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> val \\<Rightarrow> 'signal worldline_init\"\n  where\n  \"worldline_inert_upd2 w s t dly (Bv v) = worldline_inert_upd w s t dly (Bv v)\"\n| \"worldline_inert_upd2 w s t dly (Lv sign bs) = \n      (fst w, (snd w)(s := \\<lambda>n.  let \n                                    w' = \\<lambda>b. snd (worldline_inert_upd (to_worldline_init_bit w s b) s t dly (Bv (bs ! b))); \n                                    time = if \\<exists>n. t < n \\<and> n \\<le> t + dly \\<and> (\\<exists>b \\<in> set [0..< length bs] . w' b s (n - 1) \\<noteq> w' b s n) then \n                                              LEAST n. t < n \\<and> n \\<le> t + dly \\<and> (\\<exists>b \\<in> set [0..< length bs] . w' b s (n - 1) \\<noteq> w' b s n)\n                                           else t + dly\n                                in if n < t then snd w s n else if n < time then snd w s t else Lv sign (map (\\<lambda>b. bval_of (snd (worldline_inert_upd (to_worldline_init_bit w s b) s t dly (Bv (bs ! b))) s n)) [0..<length bs]))) \"\n\ntext \\<open>These are the two constructs we can use to update or modify a @{typ \"'signal worldline\"}. Note\nthat the syntax between these two are quite similar. The only difference is the number of arguments\non the left of the equality sign: @{term \"worldline_upd\"} has two while @{term\n\"worldline_inert_upd\"} has three. As the names suggest, they correspond to the transport delay\nassignment @{term \"Bassign_trans\"} and inertial delay assignment @{term \"Bassign_inert\"}.\\<close>\n\ntype_synonym 'signal assn = \"'signal worldline_init \\<Rightarrow> bool\"\n\nsubsection \\<open>Validity of Hoare proof rules\\<close>\n\ndefinition worldline_raw ::\n  \"nat \\<Rightarrow> 'signal state \\<Rightarrow> 'signal trans_raw \\<Rightarrow> 'signal state \\<Rightarrow> 'signal trans_raw \\<Rightarrow> 'signal worldline_init\" where\n  \"worldline_raw t \\<sigma> \\<theta> def \\<tau> = (def, \\<lambda>s' t'. if t' < t then signal_of (def s') \\<theta> s' t' else signal_of (\\<sigma> s') \\<tau> s' t')\"\n\ntext \\<open>@{term \"worldline_raw\"} is a constructor here. Note that we have used the same identifier (name)\nfor the constructor and the type here. This construct is the link from the operational semantics's\nworld such as @{typ \"'signal state\"}, @{typ \"'signal trans_raw\"} to the axiomatic semantics's\nworld @{typ \"'signal worldline\"}.\n\nAn observant reader might have noticed that there is no @{typ \"'signal event\"} when we construct\n@{typ \"'signal worldline\"}. This is because, as Breuer and Kloos~@{cite \"Breuer1995\"} argued, the\nnotion of event can be reconstructed from the notion of @{typ \"'signal worldline\"}. Or,\nalternatively, the notion of event is inherent in @{typ \"'signal worldline\"}. Simply find the\nsignals which have different values from those at the previous time correspondingly suffices for\nreconstructing the event at every time point.\\<close>\n\ndefinition difference_raw :: \"'signal worldline_init \\<Rightarrow> nat \\<Rightarrow> 'signal \\<rightharpoonup> val\" where\n  \"difference_raw w t = (if t = 0 then\n                          (\\<lambda>s. if snd w s t \\<noteq> fst w s then Some (snd w s t) else None)\n                         else\n                          (\\<lambda>s. if snd w s t \\<noteq> snd w s (t - 1) then Some (snd w s t) else None))\"\n\nlemma difference_raw_alt_def:\n  \"difference_raw w t = (let\n                            base = if t = 0 then fst w else (\\<lambda>s. snd w s (t - 1))\n                         in\n                            (\\<lambda>s. if snd w s t \\<noteq> base s then Some (snd w s t) else None))\"\n  unfolding difference_raw_def Let_def by auto\n\ndefinition derivative_raw :: \"'signal worldline_init \\<Rightarrow> nat \\<Rightarrow> 'signal trans_raw\"\n  where \"derivative_raw \\<equiv> (\\<lambda>w t n. if n \\<le> t then Map.empty else difference_raw w n)\"\n\ndefinition derivative_hist_raw :: \"'signal worldline_init \\<Rightarrow> nat \\<Rightarrow> 'signal trans_raw\"\n  where \"derivative_hist_raw \\<equiv> \\<lambda>w t n. if t \\<le> n then Map.empty else difference_raw w n\"\n\ntext \\<open> The function @{term \"derivative_raw\"} is a function to obtain the transaction\n@{term \"\\<tau> :: 'signal trans_raw\"} in the operational semantics @{term \"b_seq_exec\"}. Note that to\nuse @{typ \"'signal worldline\"} as a context to define the axiomatic semantics of VHDL, it is always\npaired with a time variable @{term \"t :: nat\"}. This variable denotes the current time of the\ncomputation; anything strictly before this time is a history (related to the notion of behaviour\n@{term \"\\<theta> :: 'signal trans_raw\"})  and anything after this time is a prediction (related to\nthe notion of transaction @{term \"\\<tau> :: 'signal trans_raw\"}).\n\nThe naming ``derivative'' signifies that this function acts similarly to a derivative in the\nreal number calculus. Hence, the derivative here only record those values which are different\n(via @{term \"difference_raw\"}) from the value at the previous time (hence the name ``difference''\nas the derivative counterpart for discrete-time signal).\n\nWhy do we still have the suffix ``raw'' in @{term \"derivative_raw\"}? Because we will still lift\nthis definition further as will be explained in @{theory_text \"VHDL_Hoare_Complete\"}.\n\\<close>\n\nlemma derivative_raw_zero:\n  assumes \"\\<forall>n \\<ge> d. \\<forall>s. snd w s n = snd w s d\" and \"d \\<le> t\"\n  shows \"derivative_raw w t = 0\"\nproof\n  fix n :: nat\n  have \"n \\<le> t \\<or> t < n\" by auto\n  moreover\n  { assume \"n \\<le> t\"\n    hence \"derivative_raw w t n  = 0\"\n      unfolding derivative_raw_def by (auto simp add: zero_fun_def zero_option_def) }\n  moreover\n  { assume \"t < n\"\n    hence \"derivative_raw w t n = difference_raw w n\"\n      unfolding derivative_raw_def by auto\n    also have \"... = 0\"\n    proof -\n      have \"\\<forall>s. snd w s n = snd w s d\"\n        using assms(1) `d \\<le> t` `t < n`  by (meson le_eq_less_or_eq le_less_trans)\n      moreover have \"\\<forall>s. snd w s (n - 1) = snd w s d\"\n        using assms(1) `d \\<le> t` `t < n`\n        by (metis Suc_diff_1 diff_is_0_eq' diff_less_mono leI less_Suc_eq_le not_less_zero)\n      ultimately have \"\\<forall>s. snd w s n = snd w s (n - 1)\"\n        by auto\n      thus ?thesis\n        using `t < n` unfolding difference_raw_def by (auto simp add: zero_option_def zero_fun_def)\n    qed\n    finally have \"derivative_raw w t n = 0\"\n      by auto }\n  ultimately show \"derivative_raw w t n = 0 n\"\n    by (auto simp add: zero_fun_def)\nqed\n\nlemma\n  \"n < t \\<Longrightarrow> (derivative_raw w t) n = 0\"\n   by (auto simp add:derivative_raw_def zero_fun_def zero_option_def)\n\nlemma lookup_derivative_in_between:\n  \"t < n \\<Longrightarrow> derivative_raw w t n = difference_raw w n\"\n  by (auto simp add: derivative_raw_def)\n\nlemma\n  assumes \"\\<forall>n \\<ge> d. \\<forall>s. snd w s n = snd w s d\" and \"d < n\"\n  shows \"derivative_raw w t n = 0\"\nproof -\n  have \"n \\<le> t \\<or> t < n\" by auto\n  moreover\n  { assume \"n \\<le> t\"\n    hence \"derivative_raw w t n = 0\"\n      unfolding derivative_raw_def by (auto simp add: zero_fun_def zero_option_def) }\n  moreover\n  { assume \"t < n\"\n    hence \"derivative_raw w t n = difference_raw w n\"\n      unfolding derivative_raw_def by auto\n    also have \"... = 0\"\n    proof -\n      have \"\\<forall>s. snd w s n = snd w s d\"\n        using assms le_eq_less_or_eq by blast\n      moreover have \"\\<forall>s. snd w s (n - 1) = snd w s d\"\n        using assms  by (metis Suc_diff_1 le_less_trans less_Suc_eq_le zero_le)\n      ultimately have \"\\<forall>s. snd w s n = snd w s (n - 1)\"\n        by auto\n      thus ?thesis\n        using `t < n` unfolding difference_raw_def by (auto simp add: zero_fun_def zero_option_def)\n    qed\n    ultimately have \"derivative_raw w t n = 0\"\n      by auto }\n  ultimately show \"derivative_raw w t n = 0\"\n    by auto\nqed\n\nlemma signal_of_derivative_hist_raw:\n  fixes w :: \"'signal worldline_init\"\n  assumes \"t' < t\"\n  shows \"signal_of (fst w s') (derivative_hist_raw w t) s' t' = snd w s' t'\"\n  using assms\nproof (induction t')\n  case 0\n  have *: \"derivative_hist_raw w t 0 = difference_raw w 0\"\n    using 0 by (auto simp add: derivative_hist_raw_def difference_raw_def)\n  have \"snd w s' 0 \\<noteq> fst w s' \\<or> snd w s' 0 = fst w s'\"\n    by auto\n  moreover\n  { assume \"snd w s' 0 = fst w s'\"\n    hence \"inf_time (to_trans_raw_sig (derivative_hist_raw w t)) s' 0 = None\"\n      unfolding sym[OF inf_time_none_iff] to_trans_raw_sig_def\n      by (smt \\<open>derivative_hist_raw w t 0 = difference_raw w 0\\<close> difference_raw_def domIff neq0_conv)\n    hence \"signal_of (fst w s') (derivative_hist_raw w t) s' 0 = fst w s'\"\n      unfolding to_signal_def comp_def by auto\n    also have \"... = snd w s' 0\"\n      using `snd w s' 0 = fst w s'` by auto\n    finally have ?case\n      by auto }\n  moreover\n  { assume \"snd w s' 0 \\<noteq> fst w s'\"\n    have \"inf_time (to_trans_raw_sig (derivative_hist_raw w t)) s' 0 = Some 0\"\n    proof (intro inf_time_someI)\n      show \"0 \\<in> dom (to_trans_raw_sig (derivative_hist_raw w t) s')\"\n        unfolding to_trans_raw_sig_def dom_def mem_Collect_eq * difference_raw_def\n        using `snd w s' 0 \\<noteq> fst w s'` by auto\n    qed (auto)\n    hence \"signal_of (fst w s') (derivative_hist_raw w t) s' 0 = the (to_trans_raw_sig (derivative_hist_raw w t) s' 0)\"\n      unfolding to_signal_def comp_def by auto\n    also have \"... = snd w s' 0\"\n      unfolding to_trans_raw_sig_def * difference_raw_def using `snd w s' 0 \\<noteq> fst w s'`\n      by auto\n    finally have ?case\n      by auto }\n  ultimately show ?case\n    by blast\nnext\n  case (Suc t')\n  have \"snd w s' (Suc t') = snd w s' t' \\<or> snd w s' (Suc t') \\<noteq> snd w s' t'\"\n    by auto\n  moreover\n  { assume \"snd w s' (Suc t') \\<noteq> snd w s' t'\"\n    have \"derivative_hist_raw w t (Suc t') = difference_raw w (Suc t')\"\n      using Suc by (auto simp add: derivative_hist_raw_def)\n    moreover have \"difference_raw w (Suc t') s' = Some (snd w s' (Suc t'))\"\n      using Suc `snd w s' (Suc t') \\<noteq> snd w s' t'` unfolding difference_raw_def by auto\n    ultimately have \"derivative_hist_raw w t (Suc t') s' = Some (snd w s' (Suc t'))\"\n      by auto\n    hence ?case\n      by (intro trans_some_signal_of', simp) }\n  moreover\n  { assume \" snd w s' (Suc t') = snd w s' t'\"\n    have \"derivative_hist_raw w t (Suc t') = difference_raw w (Suc t')\"\n      using Suc by (auto simp add : derivative_hist_raw_def)\n    moreover have \"difference_raw w (Suc t') s' = None\"\n      using Suc `snd w s' (Suc t') = snd w s' t'` unfolding difference_raw_def by auto\n    ultimately have \"derivative_hist_raw w t (Suc t') s' = None\"\n      by auto\n    hence \"signal_of (fst w s') (derivative_hist_raw w t) s' (Suc t') =  signal_of (fst w s') (derivative_hist_raw w t) s' t'\"\n      by (intro signal_of_suc_sig) (simp add: zero_option_def)\n    also have \"... = snd w s' t'\"\n      using Suc  Suc_lessD by blast\n    finally have ?case\n      using `snd w s' (Suc t') = snd w s' t'` by auto }\n  ultimately show ?case\n    by blast\nqed\n\nlemma signal_of_derivative_hist_raw2:\n  assumes \"t \\<le> t'\" and \"0 < t\"\n  shows \"signal_of (fst w s') (derivative_hist_raw w t) s' t' = snd w s' (t - 1)\"\nproof -\n  have \"t - 1 < t\"\n    using assms by auto\n  have \"signal_of (fst w s') (derivative_hist_raw w t) s' t' = signal_of (fst w s') (derivative_hist_raw w t) s' t\"\n    using assms\n    by (intro signal_of_less_ind')(auto simp add: derivative_hist_raw_def zero_option_def)\n  also have \"... = signal_of (fst w s') (derivative_hist_raw w t) s' (t - 1)\"\n    by (intro signal_of_less_sig) (auto simp add: derivative_hist_raw_def zero_option_def)\n  also have \"... = snd w s' (t - 1)\"\n    using signal_of_derivative_hist_raw[OF `t - 1 < t`] by metis\n  finally show \"signal_of (fst w s') (derivative_hist_raw w t) s' t' = snd w s' (t - 1)\"\n    by auto\nqed\n\nlemma signal_of_derivative_hist_raw3:\n  assumes \"0 \\<le> t'\" \n  shows   \"signal_of (fst w s') (derivative_hist_raw w 0) s' t' = fst w s'\"\nproof -\n  have \"derivative_hist_raw w 0 = (\\<lambda>n. Map.empty)\"\n    unfolding derivative_hist_raw_def by auto\n  hence \"inf_time (to_trans_raw_sig (derivative_hist_raw w 0)) s' t' = inf_time (to_trans_raw_sig (\\<lambda>n. Map.empty)) s' t'\"\n    by auto\n  also have \"... = inf_time (\\<lambda>n. Map.empty) s' t'\"\n    unfolding to_trans_raw_sig_def by auto\n  also have \"... = None\"\n    using inf_time_none_iff by force\n  finally show ?thesis\n    unfolding to_signal_def comp_def by auto\nqed\n\nlemma signal_of_derivative_raw_t:\n  assumes \"\\<sigma> s' = snd w s' t\"\n  shows \"signal_of (\\<sigma> s') (derivative_raw w t) s' t = snd w s' t\"\nproof -\n  have \"derivative_raw w t t = Map.empty\"\n    using assms by (auto simp add: derivative_raw_def)\n  have *: \"\\<And>n. 0 < n \\<Longrightarrow> n \\<le> t \\<Longrightarrow>  derivative_raw w t n = 0\"\n    by (auto simp add: derivative_raw_def zero_fun_def zero_option_def)\n  have \"signal_of (\\<sigma> s') (derivative_raw w t) s' t = signal_of (\\<sigma> s') (derivative_raw w t) s' 0\"\n    using * by (cases \"t = 0\")(rule_tac[!] signal_of_less_ind, simp_all)\n  also have \"... = \\<sigma> s'\"\n    by(intro signal_of_zero) (auto simp add: derivative_raw_def zero_option_def)\n  finally show ?thesis\n    using assms by auto\nqed\n\nlemma signal_of_derivative_raw:\n  assumes \"t \\<le> t'\"\n  assumes \"snd w s' t = \\<sigma> s'\"\n  shows \"signal_of (\\<sigma> s') (derivative_raw w t) s' t' = snd w s' t'\"\n  using assms\nproof (induction t')\n  case 0\n  hence \"t = 0\" by auto\n  have lookup: \"derivative_raw w 0 0 = Map.empty\"\n    by (auto simp add: derivative_raw_def)\n  hence \" signal_of (\\<sigma> s') (derivative_raw w t) s' 0 =  signal_of (\\<sigma> s') (derivative_raw w 0) s' 0\"\n    unfolding `t = 0` by auto\n  also have \"... = \\<sigma> s'\"\n    using lookup signal_of_zero by (metis (no_types, lifting) zero_option_def)\n  also have \"... = snd w s' 0\"\n    using `snd w s' t = \\<sigma> s'` `t = 0` by auto\n  finally show ?case by auto\nnext\n  case (Suc t')\n  hence \"Suc t' = t \\<or> t < Suc t'\"\n    by auto\n  moreover\n  { assume \"Suc t' = t\"\n    have lookup: \"derivative_raw w t (Suc t') = Map.empty\"\n      unfolding `Suc t' = t` by (auto simp add: derivative_raw_def)\n    have \" \\<And>n. 0 < n \\<Longrightarrow> n \\<le> Suc t' \\<Longrightarrow> (derivative_raw w t) n = 0\"\n      unfolding `Suc t' = t` by (auto simp add: derivative_raw_def zero_fun_def zero_option_def)\n    hence \" signal_of (\\<sigma> s') (derivative_raw w t) s' (Suc t') =  signal_of (\\<sigma> s') (derivative_raw w t) s' 0\"\n      by (intro signal_of_less_ind, simp_all)\n    also have \"... = \\<sigma> s'\"\n      by (metis (full_types, hide_lams) Suc.prems(2) \\<open>Suc t' = t\\<close> assms(2) calculation\n      signal_of_derivative_raw_t)\n    also have \"... = snd w s' (Suc t')\"\n      using `snd w s' t = \\<sigma> s'` `Suc t' = t` by auto\n    finally have ?case unfolding `Suc t' = t` by auto }\n  moreover\n  { assume \"t < Suc t'\"\n    hence \"t \\<le> t'\"\n      by auto\n    hence lookup: \" (derivative_raw w t) (Suc t') = difference_raw w (Suc t')\"\n      by (auto simp add: derivative_raw_def)\n    have \"snd w s' (Suc t') = snd w s' t' \\<or> snd w s' (Suc t') \\<noteq> snd w s' t'\"\n      by auto\n    moreover\n    { assume \"snd w s' (Suc t') = snd w s' t'\"\n      hence \"difference_raw w (Suc t') s' = None\"\n        unfolding difference_raw_def by auto\n      hence \"(derivative_raw w t) (Suc t') s' = None\"\n        using lookup by auto\n      hence \"signal_of (\\<sigma> s') (derivative_raw w t) s' (Suc t') =  signal_of (\\<sigma> s') (derivative_raw w t) s' t'\"\n        by(intro signal_of_suc_sig)(simp add: zero_option_def)\n      also have \"... = snd w s' t'\"\n        using Suc(1)[OF `t \\<le> t'` Suc(3)] by auto\n      also have \"... = snd w s' (Suc t')\"\n        using `snd w s' (Suc t') = snd w s' t'` by auto\n      finally have ?case by auto }\n    moreover\n    { assume \"snd w s' (Suc t') \\<noteq> snd w s' t'\"\n      hence \"difference_raw w (Suc t') s' = Some (snd w s' (Suc t'))\"\n        unfolding difference_raw_def by auto\n      hence \"(derivative_raw w t) (Suc t') s' = Some (snd w s' (Suc t'))\"\n        using lookup by auto\n      hence ?case\n        by (intro trans_some_signal_of') }\n    ultimately have ?case by blast }\n  ultimately show ?case by auto\nqed\n\nlemma signal_of_derivative_raw2:\n  assumes \"\\<forall>n\\<ge>d. snd w s' n = snd w s' d\"\n  assumes \"d \\<le> t'\"\n  assumes \"snd w s' t = \\<sigma> s'\"\n  shows \"signal_of (\\<sigma> s') (derivative_raw w t) s' t' = snd w s' d\"\nproof -\n  have \"\\<And>n. d < n \\<Longrightarrow> n \\<le> t' \\<Longrightarrow>  (derivative_raw w t) n s' = 0\"\n  proof -\n    fix n\n    assume \"d < n\" and \"n \\<le> t'\"\n    have \"n \\<le> t \\<or> t < n\" by auto\n    moreover\n    { assume \"n \\<le> t\"\n      hence \"derivative_raw w t n s' = 0\"\n        unfolding derivative_raw_def by (auto simp add: zero_fun_def zero_option_def) }\n    moreover\n    { assume \"t < n\"\n      have \"snd w s' n = snd w s' d\"\n        using assms `d < n`  using less_imp_le_nat by blast\n      also have \"... = snd w s' (n-1)\"\n        using `d < n` assms(1) by (metis Suc_diff_1 less_Suc_eq_0_disj less_Suc_eq_le\n        less_imp_Suc_add)\n      finally have \"snd w s' n = snd w s' (n - 1)\"\n        by auto\n      hence \"derivative_raw w t n s' = difference_raw w n s'\"\n        using `t < n` unfolding derivative_raw_def by auto\n      also have \"... = None\"\n        unfolding difference_raw_def using \\<open>snd w s' n = snd w s' (n-1)\\<close> `t < n` by auto\n      finally have \"derivative_raw w t n s' = 0\"\n        unfolding zero_option_def by auto }\n    ultimately show \"derivative_raw w t n s' = 0\"\n      by auto\n  qed\n  from signal_of_less_ind'[where \\<tau>=\" (derivative_raw w t)\", OF this]\n  have *: \"signal_of (\\<sigma> s') (derivative_raw w t) s' t' = signal_of (\\<sigma> s') (derivative_raw w t) s' d\"\n    using assms(2) using le_eq_less_or_eq by  auto\n  have \"t \\<le> t' \\<or> t' < t\" by auto\n  moreover\n  { assume \"t \\<le> t'\"\n    have \"signal_of (\\<sigma> s') (derivative_raw w t) s' t' = snd w s' t'\"\n      using signal_of_derivative_raw[OF `t \\<le> t'`, of \"w\" \"s'\" \"\\<sigma>\", OF assms(3)]  by auto\n    also have \"... = snd w s' d\"\n      using assms(1-2)  by blast\n    finally have \"signal_of (\\<sigma> s') (derivative_raw w t) s' t' = snd w s' d\"\n      by auto }\n  moreover\n  { assume \"t' < t\"\n    have \"signal_of (\\<sigma> s') (derivative_raw w t) s' d = signal_of (\\<sigma> s') (derivative_raw w t) s' 0\"\n    proof (intro  signal_of_less_ind')\n      fix n\n      assume \"0 < n\" and \"n \\<le> d\"\n      thus \"derivative_raw  w t n s' = 0\"\n        unfolding derivative_raw_def using `d \\<le> t'` `t' < t` by (auto simp add: zero_option_def)\n    qed (auto)\n    also have \"... = \\<sigma> s'\"\n      by (intro signal_of_zero)(auto intro!: signal_of_zero simp add: derivative_raw_def\n      zero_option_def)\n    also have \"... = snd w s' t\"\n      using assms(3) by auto\n    also have \"... = snd w s' d\"\n      using assms(1) `t' < t` `d \\<le> t'` by (meson less_trans not_le)\n    finally have \"signal_of (\\<sigma> s') (derivative_raw w t) s' d = snd w s' d\"\n      by auto\n    hence \"signal_of (\\<sigma> s') (derivative_raw w t) s' t' = snd w s' d\"\n      using * by auto }\n  ultimately show ?thesis by auto\nqed\n\nlemma signal_of_derivative_raw':\n  assumes \"t \\<le> t'\" and \"t \\<le> d\"\n  assumes \"\\<And>n s. d < n \\<Longrightarrow> snd w s n = snd w s d\"\n  assumes \"snd w s' t = \\<sigma> s'\"\n  shows \"signal_of (\\<sigma> s') (derivative_raw w t) s' t' = snd w s' t'\"\n  using assms by (metis signal_of_derivative_raw)\n\nlemma signal_of_derivative_raw_degree_lt_now:\n  assumes \"\\<forall>n\\<ge> d. \\<forall>s. snd w s n = snd w s d\"\n  assumes \"d < t\"\n  shows \"signal_of (\\<sigma> s') (derivative_raw w t) s' t' = \\<sigma> s'\"\nproof -\n  have \"derivative_raw w t = 0\"\n    using derivative_raw_zero assms by (simp add: derivative_raw_zero)\n  moreover have \"signal_of (\\<sigma> s') 0 s' t' = \\<sigma> s'\"\n    using signal_of_empty unfolding zero_fun_def by metis\n  ultimately show ?thesis by auto\nqed\n\nlemma signal_of2_derivative_before_now:\n  assumes \"t' < t\"\n  shows \"signal_of def (derivative_raw w t) s' t' = def\"\nproof -\n  have *: \"\\<And>k. k < t \\<Longrightarrow>  (derivative_raw w t) k = Map.empty\"\n    by (auto simp add: derivative_raw_def)\n  hence \"\\<And>n. 0 < n \\<Longrightarrow> n \\<le> t' \\<Longrightarrow>  (derivative_raw w t) n = 0\"\n    using `t' < t` unfolding derivative_raw_def by (auto simp add: zero_fun_def zero_option_def)\n  hence \"signal_of def (derivative_raw w t) s' t' = signal_of def (derivative_raw w t) s' 0\"\n    by (intro signal_of_less_ind, simp_all)\n  also have \"... = def\"\n    by (intro signal_of_zero, auto simp add: derivative_raw_def zero_option_def)\n  finally show \"signal_of def (derivative_raw w t) s' t' = def\"\n    by auto\nqed\n\ntext \\<open>non-stuttering\\<close>\n\ndefinition non_stuttering :: \"'signal trans_raw_sig \\<Rightarrow> 'signal state \\<Rightarrow> 'signal \\<Rightarrow> bool\" where\n  \"non_stuttering \\<tau> \\<sigma> s \\<equiv> (\\<forall>k1 k2.\n                                    k1 < k2 \\<and> k1 \\<in> keys (\\<tau> s) \\<and> k2 \\<in> keys (\\<tau> s)\n                                 \\<and> (\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (\\<tau> s)) \\<longrightarrow> \\<tau> s k1 \\<noteq> \\<tau> s k2)\n                         \\<and> (keys (\\<tau> s) \\<noteq> {} \\<longrightarrow> \\<sigma> s \\<noteq> the (\\<tau> s (LEAST k. k \\<in> keys (\\<tau> s))))\"\n\nlemma two_successive_keys_diff_value:\n  fixes \\<tau> :: \"'a trans_raw_sig\"\n  assumes \"non_stuttering \\<tau> \\<sigma> s\"\n  assumes \"t1 \\<in> keys (\\<tau> s)\" and \"t2 \\<in> keys (\\<tau> s)\"\n  defines \"v1 \\<equiv> the (\\<tau> s t1)\"\n  defines \"v2 \\<equiv> the (\\<tau> s t2)\"\n  assumes \"\\<forall>n>t1. n < t2 \\<longrightarrow> \\<tau> s n = 0\"\n  assumes \"t1 < t2\"\n  shows \"v1 \\<noteq> v2\"\nproof -\n  have \"\\<forall>k. t1 < k \\<and> k < t2 \\<longrightarrow> k \\<notin> keys (\\<tau> s)\"\n    using `\\<forall>n>t1. n < t2 \\<longrightarrow> \\<tau> s n = 0`  by (simp add: keys_def)\n  with assms(1-3) show ?thesis\n    using `t1 < t2` unfolding v1_def v2_def non_stuttering_def\n  proof -\n    assume a1: \"(\\<forall>k1 k2. k1 < k2 \\<and> k1 \\<in> keys (\\<tau> s) \\<and> k2 \\<in> keys (\\<tau> s) \\<and> (\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (\\<tau> s)) \\<longrightarrow> \\<tau> s k1 \\<noteq> \\<tau> s k2) \\<and> (keys (\\<tau> s) \\<noteq> {} \\<longrightarrow> \\<sigma> s \\<noteq> the (\\<tau> s (LEAST k. k \\<in> keys (\\<tau> s))))\"\n    have \"\\<And>n f. (n::nat) \\<notin> {n. f n \\<noteq> (None::val option)} \\<or> f n \\<noteq> None\"\n      by fastforce\n    then show \"the (\\<tau> s t1) \\<noteq> the (\\<tau> s t2)\"\n      using a1 by (metis \\<open>\\<forall>k. t1 < k \\<and> k < t2 \\<longrightarrow> k \\<notin> keys (\\<tau> s)\\<close> \\<open>t1 < t2\\<close> \\<open>t1 \\<in> keys (\\<tau> s)\\<close> \\<open>t2 \\<in> keys (\\<tau> s)\\<close> keys_def option.collapse zero_option_def)\n  qed\nqed\n\nlemma derivative_raw_of_worldline_specific:\n  fixes \\<sigma> :: \"'a state\"\n  fixes def \\<theta>\n  assumes \"\\<forall>n. n \\<le> t \\<longrightarrow>  \\<tau> n = 0\"\n  defines \"w \\<equiv> worldline_raw t \\<sigma> \\<theta> def \\<tau>\"\n  assumes \"\\<forall>s. non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma> s\"\n  shows \"derivative_raw w t = \\<tau>\"\nproof (rule ext)\n  fix k\n  have \"\\<tau> t = 0\"\n    using assms(1) by auto\n  have \"k \\<le> t \\<or> t < k\" by auto\n  moreover\n  { assume \"k \\<le> t\"\n    hence \"(derivative_raw w t) k = 0\"\n      by (auto simp add: derivative_raw_def zero_fun_def zero_option_def)\n    also have \"... = \\<tau> k\"\n      using assms(1) `k \\<le> t` by auto\n    finally have \"derivative_raw w t k = \\<tau> k\"\n      by auto }\n  moreover\n  { assume \"t < k\"\n    hence \"derivative_raw w t k = difference_raw w k\"\n      unfolding derivative_raw_def by auto\n    also have \"... = \\<tau> k\"\n    proof (rule ext)\n      fix s\n      have \"snd w s k \\<noteq> snd w s (k - 1) \\<or> snd w s k = snd w s (k - 1)\"\n        by auto\n      moreover\n      { assume \"snd w s k \\<noteq> snd w s (k - 1)\"\n        hence \"signal_of (\\<sigma> s) \\<tau> s k \\<noteq> signal_of (\\<sigma> s) \\<tau> s (k - 1)\"\n          unfolding w_def worldline_raw_def using `t < k`  by (simp add: discrete)\n        have lnone: \" (to_trans_raw_sig \\<tau> s) k \\<noteq> 0\"\n        proof (rule ccontr)\n          assume \"\\<not>  (to_trans_raw_sig \\<tau> s) k \\<noteq> 0\"\n          hence \" (to_trans_raw_sig \\<tau> s) k = 0\"\n            by auto\n          hence \" \\<tau> k s = 0\"\n             unfolding to_trans_raw_sig_def by auto\n          hence \"signal_of (\\<sigma> s) \\<tau> s k = signal_of (\\<sigma> s) \\<tau> s (k - 1)\"\n            by (intro signal_of_less_sig)\n          with `signal_of (\\<sigma> s) \\<tau> s k \\<noteq> signal_of (\\<sigma> s) \\<tau> s (k - 1)` show False\n            by auto\n        qed\n        then obtain val where \"to_trans_raw_sig \\<tau> s k = Some val\"\n          by (metis not_None_eq zero_fun_def zero_fun_def zero_option_def)\n        hence \"\\<tau> k s = Some val\"\n          by (auto simp add: to_trans_raw_sig_def)\n        hence inf: \"Femto_VHDL_raw.inf_time (to_trans_raw_sig \\<tau>) s k = Some k\"\n          by (auto intro!: some_inf_time'[where \\<sigma>=\"def(s := val)\"])\n        have \"difference_raw w k s = Some (snd w s k)\"\n          unfolding difference_raw_def using `snd w s k \\<noteq> snd w s (k - 1)` using \\<open>t < k\\<close> by auto\n        also have \"... =  (to_trans_raw_sig \\<tau> s) k\"\n          unfolding w_def worldline_raw_def using `t < k` unfolding Femto_VHDL_raw.to_signal_def\n          comp_def using inf \\<open> (to_trans_raw_sig \\<tau> s) k = Some val\\<close> by auto\n        also have \"... = \\<tau> k s\"\n          by (auto simp add: to_trans_raw_sig_def)\n        finally have \"difference_raw w k s =  \\<tau> k s\"\n          by auto }\n      moreover\n      { assume \"snd w s k = snd w s (k - 1)\"\n        hence sig_same: \"signal_of (\\<sigma> s) \\<tau> s k = signal_of (\\<sigma> s) \\<tau> s (k - 1)\"\n          unfolding w_def worldline_raw_def using `t < k` by auto\n        have lnone: \" (to_trans_raw_sig \\<tau> s) k = None\"\n        proof (rule ccontr)\n          assume \" (to_trans_raw_sig \\<tau> s) k \\<noteq> None\"\n          then obtain val where \" (to_trans_raw_sig \\<tau> s) k = Some val\"\n            by blast\n          hence \" \\<tau> k s = Some val\"\n            by (auto simp add: to_trans_raw_sig_def)\n          hence \"Femto_VHDL_raw.inf_time (to_trans_raw_sig \\<tau>) s k = Some k\"\n            by (auto intro!: some_inf_time'[where \\<sigma>=\"def(s := val)\"])\n          hence \"signal_of (\\<sigma> s) \\<tau> s k = val\"\n            unfolding Femto_VHDL_raw.to_signal_def comp_def by (simp add: \\<open> (to_trans_raw_sig \\<tau> s) k = Some val\\<close>)\n          with sig_same have \"signal_of (\\<sigma> s) \\<tau> s (k - 1) = val\"\n            by auto\n          from signal_of_elim[OF this]\n          have \"(\\<exists>m\\<le>k - 1.  (to_trans_raw_sig \\<tau> s) m = Some val) \\<or>\n                (\\<forall>m\\<le>k - 1.  (to_trans_raw_sig \\<tau> s) m = None \\<and> val = \\<sigma> s)\"\n            by (metis to_trans_raw_sig_def)\n          moreover\n          { assume \"(\\<exists>m\\<le>k - 1.  (to_trans_raw_sig \\<tau> s) m = Some val)\"\n            then obtain m where \"Femto_VHDL_raw.inf_time (to_trans_raw_sig \\<tau>) s (k-1) = Some m\" and \" (to_trans_raw_sig \\<tau> s) m = Some val\"\n              using `signal_of (\\<sigma> s) \\<tau> s (k - 1) = val` unfolding Femto_VHDL_raw.to_signal_def comp_def\n              by (smt \\<open>to_trans_raw_sig \\<tau> s k = Some val\\<close> \\<open>to_trans_raw_sig \\<tau> s k \\<noteq> None\\<close>\n              inf_time_noneE2 inf_time_some_exists keys_def mem_Collect_eq option.case_eq_if\n              option.collapse zero_option_def)\n            have \"m < k\"\n              using inf_time_at_most[OF `Femto_VHDL_raw.inf_time (to_trans_raw_sig \\<tau>) s (k-1) = Some m`]\n              \\<open>t < k\\<close> by linarith\n            moreover have \"m \\<in> keys (to_trans_raw_sig \\<tau> s)\"\n              using `to_trans_raw_sig \\<tau> s m = Some val` unfolding keys_def by (auto simp add: zero_option_def)\n            moreover have \"k \\<in> keys (to_trans_raw_sig \\<tau> s)\"\n              using `\\<tau> k s = Some val` unfolding keys_def to_trans_raw_sig_def by (auto simp add: zero_option_def)\n            moreover have \"\\<forall>n. m < n \\<and> n < k \\<longrightarrow> n \\<notin> keys (to_trans_raw_sig \\<tau> s)\"\n            proof (rule ccontr)\n              assume \"\\<not> (\\<forall>n. m < n \\<and> n < k \\<longrightarrow> n \\<notin> keys (to_trans_raw_sig \\<tau> s))\"\n              then obtain n where \"m < n\" and \"n < k\" and \"n \\<in> keys (to_trans_raw_sig \\<tau> s)\"\n                by auto\n              with inf_time_someE[OF `Femto_VHDL_raw.inf_time (to_trans_raw_sig \\<tau>) s (k-1) = Some m`]\n              show False\n                unfolding dom_is_keys  by auto\n            qed\n            ultimately have \"to_trans_raw_sig \\<tau> s m \\<noteq> to_trans_raw_sig \\<tau> s k\"\n              using assms(3) unfolding non_stuttering_def by metis\n            hence \"Some val \\<noteq> Some val\"\n              using \\<open>(to_trans_raw_sig \\<tau> s) m = Some val\\<close> \\<open>\\<tau> k s = Some val\\<close>\n              unfolding to_trans_raw_sig_def by auto\n            hence False by auto }\n          moreover\n          { assume \"(\\<forall>m\\<le>k - 1.  (to_trans_raw_sig \\<tau> s) m = None \\<and> val = \\<sigma> s)\"\n            hence must_zero: \"\\<And>m. m < k \\<Longrightarrow>  (to_trans_raw_sig \\<tau> s) m = 0\" and \"val = \\<sigma> s\"\n              by (auto simp add: zero_option_def)\n            have \"(LEAST n. n \\<in> keys (to_trans_raw_sig \\<tau> s)) = k\"\n            proof (rule Least_equality)\n              show \"k \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau> s)\"\n                using `\\<tau> k s = Some val` unfolding to_trans_raw_sig_def keys_def\n                by (auto simp add: zero_option_def)\n            next\n              { fix y\n                assume \"\\<not> k \\<le> y\" hence \"y < k\" by auto\n                with must_zero have \"y \\<notin> keys (to_trans_raw_sig \\<tau> s)\"\n                  by (simp add: keys_def) }\n              thus \"\\<And>y. y \\<in> keys (to_trans_raw_sig \\<tau> s) \\<Longrightarrow> k \\<le> y\"\n                by auto\n            qed\n            moreover have \"keys (to_trans_raw_sig \\<tau> s) \\<noteq> {}\"\n              using `\\<tau> k s = Some val` \\<open>Femto_VHDL_raw.inf_time (to_trans_raw_sig \\<tau>) s k = Some k\\<close>\n              inf_time_some_exists by fastforce\n            ultimately have \"\\<sigma> s \\<noteq> val\"\n              using assms(3) `\\<tau> k s = Some val` unfolding non_stuttering_def\n              using \\<open>to_trans_raw_sig \\<tau> s k = Some val\\<close> by auto\n            hence False\n              using `val = \\<sigma> s` by auto }\n          ultimately show False by auto\n        qed\n        hence \"difference_raw w k s = \\<tau> k s\"\n          unfolding difference_raw_def using `snd w s k = snd w s (k - 1)` `t < k`\n          by (auto simp add:to_trans_raw_sig_def) }\n      ultimately show \"difference_raw w k s = \\<tau> k s\"\n        by auto\n    qed\n    finally have \"derivative_raw w t k = \\<tau> k\"\n      by auto }\n  ultimately show \" derivative_raw w t k = \\<tau> k\"\n    by auto\nqed\n\nlemma current_sig_and_prev_same:\n  assumes \"signal_of def \\<theta> s k = signal_of def \\<theta> s (k - 1)\"\n  assumes \"0 < k\"\n  assumes \"non_stuttering (to_trans_raw_sig \\<theta>) state s\"\n  assumes \"state s = def\"\n  shows \"\\<theta> k s = 0\"\nproof (rule ccontr)\n  assume \"\\<theta> k s \\<noteq> 0\"\n  then obtain val where \"\\<theta> k s = Some val\"\n    by (metis not_None_eq zero_fun_def zero_fun_def zero_option_def)\n  hence \"signal_of def \\<theta> s k = val\"\n    using trans_some_signal_of'[of \"\\<theta>\" \"k\" \"s\" \"def_state(s := val)\" \"def\"] by auto\n  have \"the (to_trans_raw_sig \\<theta> s k) = val\"\n    using `\\<theta> k s = Some val` by (auto simp add: to_trans_raw_sig_def)\n  have \"k \\<in> dom (to_trans_raw_sig \\<theta> s)\"\n    using ` \\<theta> k s = Some val` by ( auto simp add: to_trans_raw_sig_def)\n  hence \"k \\<in> keys (to_trans_raw_sig \\<theta> s)\"\n    by (auto simp add: keys_def to_trans_raw_sig_def zero_option_def)\n  obtain k' where \"Femto_VHDL_raw.inf_time (to_trans_raw_sig \\<theta>) s (k - 1) = None \\<or>\n                   Femto_VHDL_raw.inf_time (to_trans_raw_sig \\<theta>) s (k - 1) = Some k'\"\n    using option.exhaust_sel by blast\n  moreover\n  { assume inf_none: \"Femto_VHDL_raw.inf_time (to_trans_raw_sig \\<theta>) s (k - 1) = None\"\n    hence noneE: \"\\<forall>t\\<in>dom ( (to_trans_raw_sig \\<theta> s)). (k - 1) < t\"\n      by (simp add: inf_time_none_iff)\n    have *: \"\\<forall>n. n < k \\<longrightarrow>  (to_trans_raw_sig \\<theta> s) n = 0\"\n    proof (rule ccontr)\n      assume \"\\<not> (\\<forall>n. n < k \\<longrightarrow>  (to_trans_raw_sig \\<theta> s) n = 0)\"\n      then obtain n where \"n < k\" and \" (to_trans_raw_sig \\<theta> s) n \\<noteq> 0\"\n        by auto\n      hence \"n \\<in> dom ( (to_trans_raw_sig \\<theta> s))\"\n        by (simp add: domIff zero_option_def)\n      hence \"k - 1 < n\" using noneE by auto\n      with `n < k` show False by auto\n    qed\n    have \"signal_of def \\<theta> s (k - 1) = def\"\n      using inf_none unfolding Femto_VHDL_raw.to_signal_def comp_def by auto\n    have \"k \\<in> keys (to_trans_raw_sig \\<theta> s)\"\n      using ` \\<theta> k s = Some val`   \\<open>signal_of def \\<theta> s (k - 1) = def\\<close>\n      \\<open>signal_of def \\<theta> s k = signal_of def \\<theta> s (k - 1)\\<close> inf_none inf_time_less\n      some_inf_time' \\<open>k \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<theta> s)\\<close> by blast\n    hence \"keys (to_trans_raw_sig \\<theta> s) \\<noteq> {}\"\n      by auto\n    moreover have \"(LEAST n. n \\<in> keys (to_trans_raw_sig \\<theta> s)) = k\"\n    proof (rule Least_equality)\n      { fix y\n        assume \"\\<not> k \\<le> y\" hence \"y < k\" by auto\n        hence \"y \\<notin> keys (to_trans_raw_sig \\<theta> s)\"\n          using * by (simp add: keys_def) }\n      thus \"\\<And>y. y \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<theta> s) \\<Longrightarrow> k \\<le> y\"\n        by auto\n    qed (simp add: `k \\<in> keys (to_trans_raw_sig \\<theta> s)`)\n    ultimately have \"state s \\<noteq> the (\\<theta> k s)\"\n      using assms(3) unfolding non_stuttering_def by (simp add: to_trans_raw_sig_def)\n    hence \"val \\<noteq> def\"\n      using assms(3-4) by (simp add: \\<open>\\<theta> k s = Some val\\<close>)\n    hence \"signal_of def \\<theta> s k \\<noteq> signal_of def \\<theta> s (k - 1)\"\n      using `signal_of def \\<theta> s k = val` `signal_of def \\<theta> s (k - 1) = def`\n      by auto\n    with `signal_of def \\<theta> s k = signal_of def \\<theta> s (k - 1)` have \"False\" by auto }\n  moreover\n  { assume inf_some: \"Femto_VHDL_raw.inf_time (to_trans_raw_sig \\<theta>) s (k - 1) = Some k'\"\n    have \"\\<forall>t\\<in>dom ( (to_trans_raw_sig \\<theta> s)). t \\<le> k-1 \\<longrightarrow> t \\<le> k'\"\n      using inf_time_someE[OF inf_some] by auto\n    hence \"\\<forall>n>k'. n < k \\<longrightarrow>  (to_trans_raw_sig \\<theta> s) n = None\"\n      by (metis diff_Suc_1 domIff le_add1 less_imp_Suc_add not_le)\n    have \"k' < k\"\n      using inf_time_at_most[OF inf_some] \\<open>0 < k\\<close> by linarith\n    have \"k' \\<in> dom ( (to_trans_raw_sig \\<theta> s))\"\n      by (metis (full_types) dom_def inf_some inf_time_some_exists keys_def zero_option_def)\n    hence \"k' \\<in> keys (to_trans_raw_sig \\<theta> s)\"\n      by (auto simp add: keys_def to_trans_raw_sig_def zero_option_def)\n    obtain val' where \" (to_trans_raw_sig \\<theta> s) k' = Some val'\"\n      using `k' \\<in> dom ( (to_trans_raw_sig \\<theta> s))` by auto\n    hence \"the ( (to_trans_raw_sig \\<theta> s) k') = val'\"\n      by ( auto simp add: to_trans_raw_sig_def)\n    hence \"val \\<noteq> val'\"\n      using two_successive_keys_diff_value[OF `non_stuttering (to_trans_raw_sig \\<theta>) state s`\n      `k' \\<in> keys (to_trans_raw_sig \\<theta> s)` `k \\<in> keys (to_trans_raw_sig \\<theta> s)` _ `k' < k`]\n      `\\<forall>n>k'. n < k \\<longrightarrow>  (to_trans_raw_sig \\<theta> s) n = None` `the ( (to_trans_raw_sig \\<theta> s) k) = val`\n      unfolding zero_option_def by auto\n    hence \"signal_of def \\<theta> s (k - 1) = val'\"\n      using inf_some `the ( (to_trans_raw_sig \\<theta> s) k') = val'`\n      unfolding Femto_VHDL_raw.to_signal_def comp_def by auto\n    with `signal_of def \\<theta> s k = val` have \"False\"\n      using `val \\<noteq> val'` `signal_of def \\<theta> s k = signal_of def \\<theta> s (k - 1)` by auto }\n  ultimately show False by auto\nqed\n\ntext \\<open>Here is an important result. In case that the history @{term \"\\<theta> :: 'a trans_raw\"} is\nnon-stuttering, the derivative raw of the worldline @{term \"w = worldline_raw t \\<sigma> \\<theta> \\<tau>\"} is exactly the\nhistory @{term \"\\<theta>\"}.\\<close>\n\n\\<comment> \\<open>It does not make any sense to have @{term \"\\<theta> 0 \\<noteq> 0\"} in the theorem below. Suppose that it is so.\nHence we have the history at zero is different from the initial state @{term \"def\"}. This means that\nthere is a delta delay transition at time zero for setting the new value at zero. Why don't we set\nthe time we wish at time zero directly in @{term \"def\"}?\\<close>\n\nlemma derivative_is_history:\n  fixes \\<sigma> :: \"'a state\"\n  fixes def \\<tau>\n  assumes *: \"\\<forall>n. t \\<le> n \\<longrightarrow>  \\<theta> n = 0\"\n  defines \"w \\<equiv> worldline_raw t \\<sigma> \\<theta> def \\<tau>\"\n  assumes \"\\<forall>s. non_stuttering (to_trans_raw_sig \\<theta>) def s\"\n  shows \"derivative_hist_raw w t = \\<theta>\"\nproof (rule ext)\n  fix k\n  have \"k = 0 \\<or> 0 < k \\<and> k < t \\<or> t < k \\<or> t = k\"\n    by auto\n  moreover\n  { assume \"t < k\"\n    hence \"derivative_hist_raw w t k = Map.empty\"\n      by (auto simp add: derivative_hist_raw_def)\n    also have \"... = \\<theta> k\"\n      using * `t < k` unfolding zero_fun_def zero_option_def by auto\n    finally have \"derivative_hist_raw w t k = \\<theta> k\"\n      using `t < k` by auto }\n  moreover\n  { assume \"0 < k \\<and> k < t\"\n    hence \"(derivative_hist_raw w t) k = difference_raw w k\"\n      by (auto simp add: derivative_hist_raw_def)\n    also have \"... = \\<theta> k\"\n      unfolding difference_raw_def\n    proof (rule ext)\n      fix s\n      have \"non_stuttering (to_trans_raw_sig \\<theta>) def s\"\n        using assms(3) by auto\n      have \"snd w s k = snd w s (k - 1) \\<or> snd w s k \\<noteq> snd w s (k - 1)\"\n        by auto\n      moreover\n      { assume \"snd w s k = snd w s (k - 1)\"\n        have \"signal_of (def s) \\<theta> s k = signal_of (def s) \\<theta> s (k - 1)\"\n          using `0 < k \\<and> k < t` `snd w s k = snd w s (k - 1)` unfolding w_def worldline_raw_def by auto\n        have \"\\<theta> k s = 0\"\n          using current_sig_and_prev_same \\<open>0 < k \\<and> k < t\\<close>\n          \\<open>non_stuttering (to_trans_raw_sig \\<theta>) def s\\<close> \\<open>signal_of (def s) \\<theta> s k = signal_of (def s) \\<theta> s (k - 1)\\<close>\n          by fastforce\n        hence \"(if snd w s k \\<noteq> snd w s (k - 1) then Some (snd w s k) else None) =  \\<theta> k s\"\n          using `snd w s k = snd w s (k-1)` by (auto simp add: zero_option_def) }\n      moreover\n      { assume \"snd w s k \\<noteq> snd w s (k - 1)\"\n        have \"signal_of (def s) \\<theta> s k \\<noteq> signal_of (def s) \\<theta> s (k - 1)\"\n          using `0 < k \\<and> k < t` `snd w s k \\<noteq> snd w s (k - 1)` unfolding w_def worldline_raw_def\n          by (simp add: less_imp_diff_less)\n        hence \"\\<theta> k s \\<noteq> 0\"\n          using signal_of_less_sig  by fastforce\n        have \"the (\\<theta> k s) = signal_of (def s) \\<theta> s k \"\n        proof -\n          obtain m where \"\\<theta> k s = Some m\"\n            using `\\<theta> k s \\<noteq> 0`  zero_option_def by fastforce\n          then obtain \\<sigma> where \"\\<theta> k s = Some (\\<sigma> s)\"\n            by simp\n          thus ?thesis\n            using trans_some_signal_of' by fastforce\n        qed\n        also have \"... = snd w s k\"\n          unfolding w_def worldline_raw_def using `0 < k \\<and> k < t` by auto\n        finally have \"(if snd w s k \\<noteq> snd w s (k - 1) then Some (snd w s k) else None) =\\<theta> k s\"\n          using `snd w s k \\<noteq> snd w s (k - 1)` by (smt \\<open>\\<theta> k s \\<noteq> 0\\<close> option.collapse zero_option_def) }\n      ultimately show \"(if k = 0 then \\<lambda>s. if snd w s k \\<noteq> get_time w s then Some (snd w s k) else None else (\\<lambda>s. if snd w s k \\<noteq> snd w s (k - 1) then Some (snd w s k) else None)) s = \\<theta> k s\"\n        using `0 < k \\<and> k < t` by auto\n    qed\n    finally have \"derivative_hist_raw w t k = \\<theta> k\"\n      using `0 < k \\<and> k < t` by auto }\n  moreover\n  { assume \"t = k\"\n    hence \"\\<theta> k = 0\"\n      using * by auto\n    hence \"derivative_hist_raw w t k = \\<theta> k\"\n      using `t = k` by (auto simp add: derivative_hist_raw_def zero_fun_def zero_option_def) }\n  moreover\n  { assume \"k = 0\"\n    have \"t = 0 \\<or> 0 < t\" by auto\n    moreover\n    { assume \"t = 0\"\n      hence \" derivative_hist_raw w t k = \\<theta> k\"\n        using * by (auto simp add: derivative_hist_raw_def zero_fun_def zero_option_def) }\n    moreover\n    { assume \"0 < t\"\n      hence \" derivative_hist_raw w t k = difference_raw w 0\"\n        unfolding `k = 0` by (auto simp add: derivative_hist_raw_def)\n      also have \"... = \\<theta> 0\"\n      proof (rule ext)\n        fix s\n        have \"non_stuttering (to_trans_raw_sig \\<theta>) def s\"\n          using assms(3) by auto\n        obtain val where \" \\<theta> 0 s = None \\<or>  \\<theta> 0 s = Some val\"\n          by (meson not_None_eq)\n        moreover\n        { assume \"\\<theta> 0 s = None\"\n          have \"snd w s 0 = signal_of (def s) \\<theta> s 0\"\n            unfolding w_def worldline_raw_def using `0 < t` by auto\n          also have \"... = def s\"\n            using ` \\<theta> 0 s = None` signal_of_empty by (metis signal_of_zero zero_option_def)\n          finally have \"snd w s 0 = def s\"\n            by auto\n          hence \"difference_raw w 0 s = None\"\n            unfolding difference_raw_def\n            by (simp add: w_def worldline_raw_def)\n          also have \"... =  \\<theta> 0 s\"\n            using ` \\<theta> 0 s = None` by auto\n          finally have \"difference_raw w 0 s =  \\<theta> 0 s\"\n            by auto }\n        moreover\n        { assume \"\\<theta> 0 s = Some val\"\n          hence \" (to_trans_raw_sig \\<theta> s) 0 \\<noteq> None\"\n            by (auto simp add: to_trans_raw_sig_def)\n          have \"0 \\<in> keys (to_trans_raw_sig \\<theta> s)\"\n            using ` \\<theta> 0 s = Some val`\n            by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n          hence \"keys (to_trans_raw_sig \\<theta> s) \\<noteq> {}\"\n            by auto\n          hence \"val \\<noteq> def s\"\n            using `non_stuttering (to_trans_raw_sig \\<theta>) def s`\n            unfolding non_stuttering_def\n            by (metis (full_types) Least_eq_0 \\<open>0 \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<theta> s)\\<close> \\<open>\\<theta> 0\n            s = Some val\\<close> option.sel to_trans_raw_sig_def)\n          hence \"snd w s 0 = signal_of (def s) \\<theta> s 0\"\n            unfolding w_def worldline_raw_def using `0 < t` by auto\n          also have \"... \\<noteq> def s\"\n            using ` \\<theta> 0 s = Some val` unfolding `val \\<noteq> def s`\n            by (metis (mono_tags) \\<open>val \\<noteq> def s\\<close> le_zero_eq signal_of_val_eq to_trans_raw_sig_def)\n          finally have \"snd w s 0 \\<noteq> def s\"\n            by auto\n          hence \"difference_raw w 0 s =  Some (snd w s 0)\"\n            unfolding difference_raw_def\n            by (simp add: w_def worldline_raw_def)\n          also have \"... = Some (signal_of (def s) \\<theta> s 0)\"\n            unfolding w_def worldline_raw_def using \\<open>0 < t\\<close> by auto\n          also have \"... = \\<theta> 0 s\"\n            using `\\<theta> 0 s = Some val`\n            by (metis (mono_tags) leD order_refl signal_of_intro to_trans_raw_sig_def)\n          finally have \"difference_raw w 0 s = \\<theta> 0 s\"\n            by auto }\n        ultimately show \"difference_raw w 0 s = \\<theta> 0 s\"\n          by auto\n      qed\n      finally have \"(derivative_hist_raw w t) k = \\<theta> k\"\n        unfolding `k = 0` by auto }\n    ultimately have \"(derivative_hist_raw w t) k = \\<theta> k\"\n      by auto }\n  ultimately show \"(derivative_hist_raw w t) k = \\<theta> k\"\n    by auto\nqed\n\ntext \\<open>Similar to @{thm \"derivative_is_history\"}, the derivative of a worldline constructed by the\nconstructor @{term \"worldline t \\<sigma> \\<theta> \\<tau>\"} is exactly the transaction @{term \"\\<tau>\"} provided that the\ntransaction @{term \"\\<tau>\"} is non-stuttering with respect to the initial state @{term \"\\<sigma> :: 'a\nstate\"}.\\<close>\n\nlemma derivative_raw_of_worldline:\n  fixes \\<sigma> :: \"'a state\"\n  fixes def \\<theta>\n  assumes \"\\<forall>n. n \\<le> t \\<longrightarrow>  \\<tau> n = 0\"\n  defines \"w \\<equiv> worldline_raw t \\<sigma> \\<theta> def \\<tau>\"\n  assumes \"\\<forall>s. non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma> s\"\n  shows \"derivative_raw w t = \\<tau>\"\nproof (cases \"\\<tau> = 0\", rule_tac[!] ext)\n  case True\n  fix n\n  have \"n \\<le> t \\<or> t < n\" by auto\n  moreover\n  { assume \"n \\<le> t\"\n    hence \"derivative_raw w t n = \\<tau> n\"\n      unfolding derivative_raw_def using True by (auto simp add: zero_fun_def zero_option_def) }\n  moreover\n  { assume \"t < n\"\n    hence \"derivative_raw w t n = difference_raw w n\"\n      unfolding derivative_raw_def by auto\n    { fix s\n      have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>) s n = signal_of (\\<sigma> s) \\<tau> s n\"\n        unfolding worldline_raw_def using `t < n` by auto\n      also have \"... = \\<sigma> s\"\n        unfolding True by (rule signal_of_empty)\n      finally have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>) s n = \\<sigma> s\"\n        by auto }\n    hence *: \"\\<And>s. snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>) s n = \\<sigma> s\"\n      by auto\n    { fix s\n      have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>) s (n-1) = signal_of (\\<sigma> s) \\<tau> s (n-1)\"\n        unfolding worldline_raw_def using `t < n` by auto\n      also have \"... = \\<sigma> s\"\n        unfolding True by (rule signal_of_empty)\n      finally have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>) s (n-1) = \\<sigma> s\"\n        by auto }\n    hence \"\\<And>s. snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>) s (n-1) = \\<sigma> s\"\n      by auto\n    with * have \"\\<And>s. snd w s n = snd w s (n-1)\"\n      unfolding w_def by auto\n    hence \"difference_raw w n = Map.empty\"\n      using `t < n` unfolding difference_raw_def by auto\n    also have \"... = \\<tau> n\"\n      using True by (auto simp add: zero_fun_def zero_option_def)\n    finally have \"derivative_raw w t n = \\<tau> n\"\n      using `derivative_raw w t n = difference_raw w n` by auto }\n  ultimately show \"derivative_raw w t n = \\<tau> n\"\n    by auto\nnext\n  case False\n  fix x\n  show \"derivative_raw w t x = \\<tau> x \"\n    using assms(3) nat_less_le\n    by (simp add: derivative_raw_of_worldline_specific assms(1) w_def)\nqed\n\nlemma preempted_keys_subset_of:\n  fixes dly t :: nat\n  fixes sig :: \"'signal\"\n  fixes \\<tau> :: \"'signal trans_raw\"\n  defines \"\\<tau>' \\<equiv> preempt_raw sig \\<tau> (t + dly)\"\n  shows \"k \\<in> keys (to_trans_raw_sig \\<tau>' sig) \\<Longrightarrow> k \\<in> keys (to_trans_raw_sig \\<tau> sig)\"\n    unfolding \\<tau>'_def preempt_raw_def\nproof -\n  assume \"k \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig (\\<lambda>t'. if t + dly \\<le> t' then (\\<tau> t')(sig := None) else \\<tau> t') sig)\"\n  then have f1: \"(if t + dly \\<le> k then (\\<tau> k)(sig := None) else \\<tau> k) sig \\<noteq> None\"\n    by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n  then have \"\\<not> t + dly \\<le> k\"\n    by force\n  then show ?thesis\n    using f1 by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\nqed\n\nlemma preempt_raw_preserves_non_stuttering:\n  fixes dly t :: nat\n  fixes sig :: \"'signal'\"\n  assumes \"non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma> sig\"\n  defines \"\\<tau>' \\<equiv> preempt_raw sig \\<tau> (t + dly)\"\n  shows \"non_stuttering (to_trans_raw_sig \\<tau>') \\<sigma> sig\"\nproof -\n  { fix k1 k2\n    assume \"k1 \\<in> keys (to_trans_raw_sig \\<tau>' sig)\" and \"k2 \\<in> keys (to_trans_raw_sig \\<tau>' sig)\"\n    hence \"k1 \\<in> keys (to_trans_raw_sig \\<tau> sig)\" and \"k2 \\<in> keys (to_trans_raw_sig \\<tau> sig)\"\n      by (simp add: \\<tau>'_def preempted_keys_subset_of)+\n    have \"k2 < t + dly\"\n      using `k2 \\<in> keys (to_trans_raw_sig \\<tau>' sig)` unfolding \\<tau>'_def to_trans_raw_sig_def preempt_raw_def\n      keys_def using leI zero_option_def by fastforce\n    assume \"k1 < k2\"\n    assume \"\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig \\<tau>' sig)\"\n    have \"\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig \\<tau> sig)\"\n    proof (rule ccontr)\n      assume \"\\<not> (\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig \\<tau> sig))\"\n      then obtain k where \"k1 < k\" and \"k < k2\" and \"k \\<in> keys (to_trans_raw_sig \\<tau> sig)\"\n        by auto\n      have \"k2 \\<le> t + dly\"\n        using `k2 \\<in> keys (to_trans_raw_sig \\<tau>' sig)` unfolding \\<tau>'_def to_trans_raw_sig_def preempt_raw_def\n        using \\<open>k2 < t + dly\\<close> le_less by blast\n      hence \"k < t + dly\"\n        using `k < k2` by auto\n      hence \"k \\<in> keys (to_trans_raw_sig \\<tau>' sig)\"\n        using `k \\<in> keys (to_trans_raw_sig \\<tau> sig)` unfolding \\<tau>'_def to_trans_raw_sig_def preempt_raw_def\n        by (simp add: keys_def)\n      thus False\n        using `\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig \\<tau>' sig)` `k1 <k` `k < k2`\n        by auto\n    qed\n    hence \"to_trans_raw_sig \\<tau> sig k1 \\<noteq> to_trans_raw_sig \\<tau> sig k2\"\n      using assms(1) `k1 < k2` `k1 \\<in> keys (to_trans_raw_sig \\<tau> sig)` `k2 \\<in> keys (to_trans_raw_sig \\<tau> sig)`\n      unfolding non_stuttering_def by auto\n    moreover have \"to_trans_raw_sig \\<tau> sig k2 = to_trans_raw_sig \\<tau>' sig k2\"\n      using `k2 < t + dly` unfolding \\<tau>'_def to_trans_raw_sig_def preempt_raw_def by auto\n    moreover have \"to_trans_raw_sig \\<tau> sig k1 = to_trans_raw_sig \\<tau>' sig k1\"\n      using `k1 < k2` `k2 < t + dly` unfolding \\<tau>'_def to_trans_raw_sig_def preempt_raw_def\n      by auto\n    ultimately have \"to_trans_raw_sig \\<tau>' sig k1 \\<noteq> to_trans_raw_sig \\<tau>' sig k2\"\n      by auto }\n  note first_po = this\n  { assume *: \"keys (to_trans_raw_sig \\<tau>' sig) \\<noteq> {}\"\n    hence \"keys (to_trans_raw_sig \\<tau> sig) \\<noteq> {}\"\n      unfolding \\<tau>'_def to_trans_raw_sig_def preempt_raw_def\n    proof -\n      have \"\\<forall>f n. (n::nat) \\<notin> {n. f n \\<noteq> (0::bool option)} \\<or> None \\<noteq> f n\"\n        using zero_option_def by auto\n      then have \"\\<exists>n. \\<tau> n sig \\<noteq> 0\"\n      proof -\n        have \"\\<And>n. n \\<notin> {n. to_trans_raw_sig \\<tau>' sig n \\<noteq> 0} \\<or> n \\<in> {n. to_trans_raw_sig \\<tau> sig n \\<noteq> 0}\"\n          by (metis \\<tau>'_def keys_def preempted_keys_subset_of)\n        then have f1: \"\\<And>n. to_trans_raw_sig \\<tau>' sig n = 0 \\<or> to_trans_raw_sig \\<tau> sig n \\<noteq> 0\"\n          by blast\n        have \"\\<exists>n. to_trans_raw_sig \\<tau>' sig n \\<noteq> 0\"\n          using \"*\" keys_def by fastforce\n        then show ?thesis\n          using f1 by (metis (lifting) to_trans_raw_sig_def)\n      qed\n      then show \"Femto_VHDL_raw.keys (\\<lambda>n. \\<tau> n sig) \\<noteq> {}\"\n        by (simp add: keys_def)\n    qed\n    hence **: \"\\<sigma> sig \\<noteq> the (to_trans_raw_sig \\<tau> sig (LEAST n. n \\<in> keys (to_trans_raw_sig \\<tau> sig)))\"\n      using assms(1) unfolding non_stuttering_def by auto\n    have subset: \"keys (to_trans_raw_sig \\<tau>' sig) \\<subseteq> keys (to_trans_raw_sig \\<tau> sig)\"\n      unfolding \\<tau>'_def preempt_raw_def to_trans_raw_sig_def keys_def\n      by (simp add: Collect_mono zero_option_def)\n    define least_key' where \"least_key' = (LEAST n. n \\<in> keys (to_trans_raw_sig \\<tau>' sig))\"\n    have \"least_key' \\<in> keys (to_trans_raw_sig \\<tau>' sig)\"\n    proof -\n      have \"\\<exists>k. k \\<in> keys (to_trans_raw_sig \\<tau>' sig)\"\n        using * by auto\n      thus ?thesis\n        by (metis LeastI_ex least_key'_def)\n    qed\n    have \"least_key' < t + dly\"\n    proof (rule ccontr)\n      assume \"\\<not> least_key' < t + dly\"\n      hence \"t + dly \\<le> least_key'\" by auto\n      hence \"\\<tau>' least_key' sig = None\"\n        unfolding \\<tau>'_def preempt_raw_def by auto\n      hence \"least_key' \\<notin> keys (to_trans_raw_sig \\<tau>' sig)\"\n        by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n      with `least_key' \\<in> keys (to_trans_raw_sig \\<tau>' sig)` show False\n        by auto\n    qed\n    have \"(LEAST n. n \\<in> keys (to_trans_raw_sig \\<tau> sig)) = least_key'\"\n    proof (rule Least_equality)\n      show \"least_key' \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau> sig)\"\n        using `least_key' \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>' sig)` subset\n        by auto\n    next\n      { fix y\n        assume \"\\<not> least_key' \\<le> y\" hence \"y < least_key'\" by auto\n        hence \"y \\<notin> keys (to_trans_raw_sig \\<tau>' sig)\"\n          unfolding least_key'_def using not_less_Least by blast\n        have \"y < t + dly\"\n          using `y < least_key'` `least_key' < t + dly` by auto\n        hence \"y \\<notin> keys (to_trans_raw_sig \\<tau> sig)\"\n            using `y \\<notin> keys (to_trans_raw_sig \\<tau>' sig)` unfolding \\<tau>'_def preempt_raw_def\n            by (simp add: keys_def to_trans_raw_sig_def) }\n      thus \"\\<And>y. y \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau> sig) \\<Longrightarrow> least_key' \\<le> y\"\n        by auto\n    qed\n    hence \"\\<sigma> sig \\<noteq> the (to_trans_raw_sig \\<tau>' sig least_key')\"\n      using ** `least_key' < t + dly`\n      by (metis \\<tau>'_def not_le preempt_raw_def to_trans_raw_sig_def) }\n  with first_po show ?thesis\n    unfolding non_stuttering_def by auto\nqed\n\nlemma purge_trans_post_preserve_non_stuttering:\n  fixes \\<tau> sig t dly cur_val\n  assumes \"non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma> sig\"\n  defines \"\\<tau>'  \\<equiv> purge_raw \\<tau> t dly sig (\\<sigma> sig) cur_val\"\n  defines \"\\<tau>'' \\<equiv> trans_post_raw sig cur_val (\\<sigma> sig) \\<tau>' t dly\"\n  assumes \"\\<forall>n. n \\<le> t \\<longrightarrow>  \\<tau> n = 0\"\n  shows \"non_stuttering (to_trans_raw_sig \\<tau>'') \\<sigma> sig\"\nproof (cases \"cur_val = \\<sigma> sig\")\n  case False\n  let ?s1 = \"signal_of (\\<sigma> sig) \\<tau> sig t\"\n  let ?s2 = \"signal_of (\\<sigma> sig) \\<tau> sig (t + dly)\"\n  let ?k2 = \"inf_time (to_trans_raw_sig \\<tau>) sig (t + dly)\"\n  have \"(?s1 = cur_val \\<or> ?s2 \\<noteq> cur_val) \\<or> (?s1 \\<noteq>  cur_val \\<and> ?s2 = cur_val)\"\n    by auto\n  moreover\n  { assume \"?s1 = cur_val \\<or> ?s2 \\<noteq> cur_val\"\n    hence lookup: \"\\<tau>' = override_on \\<tau> (\\<lambda>n. (\\<tau> n)(sig := None)) {t <.. t + dly} \"\n      unfolding \\<tau>'_def purge_raw_def by auto\n    hence \"\\<tau> t sig = None\"\n      using assms(4)  by (simp add: zero_fun_def zero_option_def)\n    have \"post_necessary_raw (dly - 1) \\<tau>' t sig cur_val (\\<sigma> sig)\"\n    proof -\n      have *: \"(\\<forall>i>t. i \\<le> t + (dly - 1) \\<longrightarrow> \\<tau>' i sig = None)\"\n        using lookup unfolding override_on_def by transfer' auto\n      hence \"\\<tau>' t sig = None\"\n        using lookup `\\<tau> t sig = None` unfolding override_on_def by auto\n      hence \"(\\<forall>i\\<ge>t. i \\<le> t + (dly - 1) \\<longrightarrow> \\<tau>' i sig = None)\"\n        using *  using le_eq_less_or_eq by blast\n      thus ?thesis\n        using post_necessary_raw_correctness2 False\n        by (metis \"*\" \\<open>\\<tau>' t sig = None\\<close> \\<tau>'_def assms(4) leI order_refl purge_preserve_trans_removal_nonstrict)\n    qed\n    hence lookup2: \"\\<tau>'' = post_raw sig cur_val \\<tau>' (t + dly)\"\n      unfolding \\<tau>''_def trans_post_raw_def by auto\n    have *: \"\\<forall>k \\<in> keys (to_trans_raw_sig \\<tau>'' sig). k = t + dly\"\n    proof\n      fix k\n      assume \"k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\"\n      have \"k \\<in> keys (to_trans_raw_sig \\<tau>' sig) \\<or> k = t + dly\"\n      proof (rule ccontr)\n        assume \"\\<not> (k \\<in> keys (to_trans_raw_sig \\<tau>' sig) \\<or> k = t + dly)\"\n        hence \"k \\<notin> keys (to_trans_raw_sig \\<tau>' sig)\" and \"k \\<noteq> t + dly\"\n          by auto\n        hence \"k < t + dly \\<or> k > t + dly\"\n          by auto\n        moreover\n        { assume \"k > t + dly\"\n          hence \"\\<tau>'' k sig = None\"\n            unfolding lookup2 post_raw_def by auto\n          hence \"k \\<notin> keys (to_trans_raw_sig \\<tau>'' sig)\"\n            by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n          with `k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)` have False\n            by auto }\n        moreover\n        { assume \"k < t + dly\"\n          hence \"\\<tau>'' k sig = \\<tau>' k sig\"\n            unfolding lookup2 post_raw_def by auto\n          also have \"... = None\"\n            unfolding lookup using \\<open>k < t + dly\\<close> assms(4)\n            by (metis \\<open>\\<not> (k \\<in> keys (to_trans_raw_sig \\<tau>' sig) \\<or> k = t + dly)\\<close> domIff dom_def keys_def\n            lookup to_trans_raw_sig_def zero_option_def)\n          finally have \"\\<tau>'' k  sig = None\"\n            by auto\n          hence \"k \\<notin> keys (to_trans_raw_sig \\<tau>'' sig)\"\n            by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n          with `k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)` have False\n            by auto }\n        ultimately show False\n          by auto\n      qed\n      moreover have \"k \\<notin> keys (to_trans_raw_sig \\<tau>' sig)\"\n      proof (rule ccontr)\n        assume \"\\<not> k \\<notin> keys (to_trans_raw_sig \\<tau>' sig)\"\n        hence \"k \\<in> keys (to_trans_raw_sig \\<tau>' sig)\"\n          by auto\n        have \"k > t + dly\"\n        proof (rule ccontr)\n          assume \"\\<not> k > t + dly\"\n          hence \"k \\<le> t + dly\"\n            by auto\n          hence \"\\<tau>' k sig = None\"\n            unfolding lookup using assms(4)\n            by (metis (mono_tags, lifting) One_nat_def \\<open>\\<tau> t sig = None\\<close> add.right_neutral\n            fun_upd_same greaterThanAtMost_iff leI less_Suc_eq_le nat_add_left_cancel_le\n            override_on_apply_in override_on_apply_notin zero_less_one)\n          hence \"k \\<notin> keys (to_trans_raw_sig \\<tau>' sig)\"\n            by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n          with `k \\<in> keys (to_trans_raw_sig \\<tau>' sig)` show False by auto\n        qed\n        hence \"\\<tau>'' k sig = None\"\n          unfolding lookup2 post_raw_def  by auto\n        hence \"k \\<notin> keys (to_trans_raw_sig \\<tau>'' sig)\"\n          by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n        with `k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)` show False\n          by auto\n      qed\n      ultimately show \"k = t + dly\"\n        by auto\n    qed\n    have \"\\<tau>'' (t + dly) sig \\<noteq> None\"\n      unfolding lookup2 post_raw_def  by simp\n    hence \"t + dly \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\"\n      by (metis domIff dom_def keys_def to_trans_raw_sig_def zero_option_def)\n    { fix k1 k2 :: nat\n      assume \"k1 < k2\"\n      assume \"k1 \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>'' sig)\"\n      assume \"k2 \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>'' sig)\"\n      hence \"k1 = k2\"\n        using `k1 \\<in> keys (to_trans_raw_sig \\<tau>'' sig)` using *  by metis\n      with `k1 < k2` have False by auto\n      hence \"to_trans_raw_sig \\<tau>'' sig k1 \\<noteq> to_trans_raw_sig \\<tau>'' sig k2\"\n        by auto }\n    hence first_po: \"(\\<forall>k1 k2.\n        k1 < k2 \\<and>\n        k1 \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>'' sig) \\<and>\n        k2 \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>'' sig) \\<and> (\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>'' sig)) \\<longrightarrow>\n        to_trans_raw_sig \\<tau>'' sig k1 \\<noteq> to_trans_raw_sig \\<tau>'' sig k2)\"\n      by auto\n    have \"Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>'' sig) \\<noteq> {}\"\n      using \\<open>t + dly \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\\<close> by auto\n    have \"(LEAST k. k \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>'' sig)) = t + dly\"\n      unfolding *  by (meson \"*\" LeastI \\<open>t + dly \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\\<close>)\n    hence \"the (to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>'' sig))) = cur_val\"\n      using * unfolding to_trans_raw_sig_def lookup2 post_raw_def by simp\n    hence \" \\<sigma> sig \\<noteq> the (to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>'' sig)))\"\n      using False by auto\n    with first_po have ?thesis\n      unfolding non_stuttering_def by auto }\n  moreover\n  { assume \"?s1 \\<noteq> (cur_val) \\<and> ?s2 = cur_val\"\n    hence lookup: \"\\<tau>' = override_on \\<tau> (\\<lambda>n. (\\<tau> n)(sig := None)) ({t <..< the ?k2} \\<union> {the ?k2 <.. t + dly}) \"\n      unfolding \\<tau>'_def purge_raw_def Let_def by auto\n    hence \"\\<tau> t sig = None\"\n      using assms(4)  by (simp add: zero_fun_def zero_option_def)\n    have \"?s1 \\<noteq> cur_val\" and \"?s2 = cur_val \"\n      using`?s1 \\<noteq> cur_val \\<and> ?s2 = cur_val` by auto\n    have *: \"\\<exists>n>t. n \\<le> t + dly \\<and> \\<tau> n sig = Some cur_val\"\n      using switch_signal_ex_mapping[of \"\\<sigma>\", OF `?s1 \\<noteq> cur_val` `?s2 = cur_val`]\n      assms(4)  by (simp add: zero_fun_def)\n    obtain time where \"?k2 = Some time \\<and> time \\<le> t + dly\"\n      by (metis False \\<open>signal_of (\\<sigma> sig) \\<tau> sig t \\<noteq> cur_val \\<and> signal_of (\\<sigma> sig) \\<tau> sig (t + dly)\n      = cur_val\\<close> comp_def inf_time_at_most option.case_eq_if option.collapse to_signal_def)\n    hence time_greatest: \"time = (GREATEST l. l \\<in> keys (to_trans_raw_sig \\<tau> sig) \\<and> l \\<le> t + dly)\"\n      by (simp add: inf_time_when_exist)\n    have \"time \\<in> keys (to_trans_raw_sig \\<tau> sig)\"\n      using GreatestI_ex_nat[where P=\"\\<lambda>x. x \\<in> keys (to_trans_raw_sig \\<tau> sig) \\<and> x \\<le> t + dly\"] *\n      by (meson \\<open>inf_time (to_trans_raw_sig \\<tau>) sig (t + dly) = Some time \\<and> time \\<le> t + dly\\<close>\n      inf_time_some_exists)\n    hence \"t < time\"\n      using assms(4)\n      by (metis domIff dom_def keys_def not_less to_trans_raw_sig_def zero_fun_def zero_option_def)\n    have time_greatest': \"\\<forall>n > time. n < t + dly \\<longrightarrow> \\<tau> n sig = None\"\n      unfolding time_greatest\n      using Greatest_le_nat[where P=\"\\<lambda>x. x \\<in> keys (to_trans_raw_sig \\<tau> sig) \\<and> x \\<le> t + dly\" and b=\"t + dly\"]\n      by (metis (mono_tags) domIff dom_def keys_def nat_le_linear not_le to_trans_raw_sig_def zero_option_def)\n    have \"\\<tau> time sig = Some cur_val\"\n    proof (rule ccontr)\n      assume \"\\<not> \\<tau> time sig = Some cur_val\"\n      hence \"\\<tau> time sig \\<noteq> Some cur_val\"\n      proof -\n        have \"to_trans_raw_sig \\<tau> sig time \\<noteq> 0\"\n          using \\<open>time \\<in> keys (to_trans_raw_sig \\<tau> sig)\\<close> keys_def by blast\n        then have \"\\<tau> time sig \\<noteq> None\"\n          by (simp add: to_trans_raw_sig_def zero_option_def)\n        then show ?thesis\n          using \\<open>\\<tau> time sig \\<noteq> Some cur_val\\<close> by force\n      qed\n      have \"inf_time (to_trans_raw_sig \\<tau>) sig (t + dly) = Some time\"\n      proof (intro inf_time_someI)\n        show \"time \\<in> dom (to_trans_raw_sig \\<tau> sig)\"\n          by (metis \\<open>time \\<in> keys (to_trans_raw_sig \\<tau> sig)\\<close> dom_def keys_def zero_option_def)\n      next\n        show \"time \\<le> t + dly\"\n          using \\<open>inf_time (to_trans_raw_sig \\<tau>) sig (t + dly) = Some time \\<and> time \\<le> t + dly\\<close> by blast\n      next\n        show \"\\<forall>ta\\<in>dom (to_trans_raw_sig \\<tau> sig). ta \\<le> t + dly \\<longrightarrow> ta \\<le> time\"\n          using time_greatest'\n          by (meson \\<open>inf_time (to_trans_raw_sig \\<tau>) sig (t + dly) = Some time \\<and> time \\<le> t + dly\\<close>\n          inf_time_someE)\n      qed\n      hence \"?s2 \\<noteq> cur_val\"\n        using \\<open>\\<tau> time sig \\<noteq> Some cur_val\\<close> unfolding to_signal_def comp_def\n        by (metis \\<open>time \\<in> keys (to_trans_raw_sig \\<tau> sig)\\<close> domIff dom_def keys_def option.exhaust_sel\n        option.simps(5) to_trans_raw_sig_def zero_option_def)\n      with `?s2 = cur_val` show False by auto\n    qed\n    have not_nec: \"time < t + dly \\<Longrightarrow> \\<not> post_necessary_raw (dly - 1) \\<tau>' t sig cur_val (\\<sigma> sig)\"\n    proof -\n      assume \"time < t + dly\"\n      have \"(\\<exists>i\\<le>t + (dly - 1). \\<tau>' i sig = Some cur_val \\<and> (\\<forall>j>i. j \\<le> t + (dly - 1) \\<longrightarrow> \\<tau>' j sig = None))\"\n      proof (intro exI[where x=\"time\"], intro conjI)\n        show \"time \\<le> t + (dly - 1)\"\n          using \\<open>time < t + dly\\<close> by linarith\n      next\n        show \"\\<tau>' time sig = Some cur_val\"\n          by (simp add: \\<open>\\<tau> time sig = Some cur_val\\<close> \\<open>inf_time (to_trans_raw_sig \\<tau>) sig (t + dly) =\n          Some time \\<and> time \\<le> t + dly\\<close> local.lookup)\n      next\n        show \"\\<forall>j>time. j \\<le> t + (dly - 1) \\<longrightarrow> \\<tau>' j sig = None\"\n          by (smt Suc_diff_1 \\<open>t < time\\<close> \\<open>time < t + dly\\<close> add_Suc_right fun_upd_triv le_imp_less_Suc\n          less_add_same_cancel1 less_trans lookup override_on_apply_in override_on_apply_notin\n          time_greatest')\n      qed\n      thus \"\\<not> post_necessary_raw (dly - 1) \\<tau>' t sig cur_val (\\<sigma> sig)\"\n        unfolding post_necessary_raw_correctness by auto\n    qed\n    have nec: \"time = t + dly \\<Longrightarrow> post_necessary_raw (dly - 1) \\<tau>' t sig cur_val (\\<sigma> sig)\"\n    proof -\n      assume \"time = t + dly\"\n      hence \"\\<tau>' = override_on \\<tau> (\\<lambda>n. (\\<tau> n)(sig := None)) ({t <..< t + dly})\"\n        unfolding lookup\n        using \\<open>inf_time (to_trans_raw_sig \\<tau>) sig (t + dly) = Some time \\<and> time \\<le> t + dly\\<close> by auto\n      hence \"\\<forall>i\\<le>t + (dly - 1). \\<tau>' i sig = None\"\n        using assms(4)\n        by (smt Suc_diff_1 \\<open>\\<tau> t sig = None\\<close> \\<open>inf_time (to_trans_raw_sig \\<tau>) sig (t + dly) = Some time\n        \\<and> time \\<le> t + dly\\<close> \\<open>t < time\\<close> \\<open>time = t + dly\\<close> \\<tau>'_def add_Suc_right add_diff_cancel_left'\n        add_diff_cancel_right' fun_upd_eqD fun_upd_triv greaterThanLessThan_iff le_diff_conv\n        le_imp_less_Suc not_less override_on_apply_in purge_preserve_trans_removal_nonstrict\n        zero_less_diff)\n      hence \"(\\<forall>i\\<le>t + (dly - 1). \\<tau>' i sig = None) \\<and> cur_val \\<noteq> \\<sigma> sig\"\n        using False by blast\n      thus \"post_necessary_raw (dly - 1) \\<tau>' t sig cur_val (\\<sigma> sig)\"\n        unfolding post_necessary_raw_correctness2 by auto\n    qed\n    have \"time < t + dly \\<or> time = t + dly\"\n      using \\<open>inf_time (to_trans_raw_sig \\<tau>) sig (t + dly) = Some time \\<and> time \\<le> t + dly\\<close>\n      le_neq_implies_less by blast\n    moreover\n    { assume \"time < t + dly\"\n      hence \"\\<not> post_necessary_raw (dly - 1) \\<tau>' t sig cur_val (\\<sigma> sig)\"\n        using not_nec by auto\n      hence \"\\<tau>'' = preempt_raw sig \\<tau>' (t + dly)\"\n        unfolding \\<tau>''_def trans_post_raw_def by auto\n      have *: \"\\<forall>k \\<in> keys (to_trans_raw_sig \\<tau>'' sig). k = the ?k2\"\n      proof\n        fix k\n        assume \"k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\"\n        hence in_prime: \"k \\<in> keys (to_trans_raw_sig \\<tau>' sig)\"\n          unfolding `\\<tau>'' = preempt_raw sig \\<tau>' (t + dly)`  by (simp add: preempted_keys_subset_of)\n        hence \"k \\<notin> {t <..< the ?k2} \\<and> k \\<notin> {the ?k2 <.. t + dly}\"\n          unfolding lookup\n        proof -\n          assume \"k \\<in> keys (to_trans_raw_sig (override_on \\<tau> (\\<lambda>n. (\\<tau> n)(sig := None)) ({t<..<the (inf_time (to_trans_raw_sig \\<tau>) sig (t + dly))} \\<union> {the (inf_time (to_trans_raw_sig \\<tau>) sig (t + dly))<..t + dly})) sig)\"\n          then have \"override_on \\<tau> (\\<lambda>n. (\\<tau> n)(sig := None)) ({t<..<the (inf_time (to_trans_raw_sig \\<tau>) sig (t + dly))} \\<union> {the (inf_time (to_trans_raw_sig \\<tau>) sig (t + dly))<..t + dly}) k sig \\<noteq> None\"\n            by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n          then show ?thesis\n            by force\n        qed\n        have \"\\<not> k \\<le> t\"\n          using `k \\<in> keys (to_trans_raw_sig \\<tau>' sig)` assms(4)\n          by (metis \\<tau>'_def domIff dom_def keys_def purge_raw_before_now_unchanged\n          to_trans_raw_sig_def zero_fun_def zero_option_def)\n        hence \"k = the ?k2 \\<or> k \\<ge> t + dly\"\n          using \\<open>k \\<notin> {t<..<the (inf_time (to_trans_raw_sig \\<tau>) sig (t + dly))} \\<and> k \\<notin> {the (inf_time\n          (to_trans_raw_sig \\<tau>) sig (t + dly))<..t + dly}\\<close> by auto\n        moreover have \"\\<not> k \\<ge> t + dly\"\n          using \\<open>k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\\<close>  unfolding `\\<tau>'' = preempt_raw sig \\<tau>' (t + dly)`  preempt_raw_def\n        proof -\n          assume \"k \\<in> keys (to_trans_raw_sig (\\<lambda>t'. if t + dly \\<le> t' then (\\<tau>' t')(sig := None) else \\<tau>' t') sig)\"\n          then have \"(if t + dly \\<le> k then (\\<tau>' k)(sig := None) else \\<tau>' k) sig \\<noteq> None\"\n            by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n          then show ?thesis\n            by force\n        qed\n        ultimately show \"k = the ?k2\"\n          by auto\n      qed\n      { fix k1 k2 :: nat\n        assume \"k1 < k2\"\n        assume \"k1 \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\" and \"k2 \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\"\n        hence \"k1 = k2\"\n          using *  by metis\n        with `k1 < k2` have False by auto\n        assume \"(\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig \\<tau>'' sig))\"\n        hence \"to_trans_raw_sig \\<tau>'' sig k1 \\<noteq> to_trans_raw_sig \\<tau>'' sig k2\"\n          using `False` by auto  }\n      hence first_po: \"(\\<forall>k1 k2.\n        k1 < k2 \\<and> k1 \\<in> keys (to_trans_raw_sig \\<tau>'' sig) \\<and> k2 \\<in> keys (to_trans_raw_sig \\<tau>'' sig) \\<and> (\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig \\<tau>'' sig)) \\<longrightarrow>\n        to_trans_raw_sig \\<tau>'' sig k1 \\<noteq> to_trans_raw_sig \\<tau>'' sig k2)\"\n        by auto\n      have \"time \\<in> keys (to_trans_raw_sig \\<tau>' sig)\"\n      proof -\n        have \"\\<tau>' time sig = \\<tau> time sig\"\n          unfolding lookup using `time < t + dly` `t < time` `?k2 = Some time \\<and> time \\<le> t + dly`\n          by auto\n        with \\<open>\\<tau> time sig = Some cur_val\\<close> have \"\\<tau>' time sig \\<noteq> 0\"\n          by (simp add: zero_option_def)\n        thus ?thesis\n          unfolding keys_def to_trans_raw_sig_def by auto\n      qed\n      moreover have \"\\<tau>'' time sig = \\<tau>' time sig\"\n        unfolding `\\<tau>'' = preempt_raw sig \\<tau>' (t + dly)`  preempt_raw_def\n        using `time < t + dly` by auto\n      ultimately have \"time \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\"\n        by (simp add: keys_def to_trans_raw_sig_def)\n      hence \"keys (to_trans_raw_sig \\<tau>'' sig) \\<noteq> {}\"\n        by (metis (full_types) domIff dom_def empty_iff keys_def to_trans_raw_sig_def\n        zero_option_def)\n      have \"(LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) = time\"\n        using * `?k2 = Some time \\<and> time \\<le> t + dly`\n        by (simp add: Least_equality \\<open>time \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\\<close>)\n      moreover have \"\\<tau>' time sig = \\<tau> time sig\"\n        unfolding lookup\n        by (simp add: \\<open>inf_time (to_trans_raw_sig \\<tau>) sig (t + dly) = Some time \\<and> time \\<le> t + dly\\<close>)\n      ultimately have \" \\<sigma> sig \\<noteq> the (to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)))\"\n        using False `\\<tau>'' time sig = \\<tau>' time sig` `\\<tau> time sig = Some cur_val`\n        by (metis option.sel to_trans_raw_sig_def)\n      hence ?thesis\n        using first_po unfolding non_stuttering_def by auto }\n    moreover\n    { assume \"time = t + dly\"\n      hence \"post_necessary_raw (dly - 1) \\<tau>' t sig cur_val (\\<sigma> sig)\"\n        using nec by auto\n      hence \\<tau>''_new_def: \"\\<tau>'' = post_raw sig cur_val \\<tau>' (t + dly)\"\n        unfolding \\<tau>''_def trans_post_raw_def by auto\n      have *: \"\\<forall>k \\<in> keys (to_trans_raw_sig \\<tau>'' sig). k = t + dly\"\n      proof\n        fix k\n        assume k_in_keys: \"k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\"\n        have \"k \\<le> t + dly\"\n        proof (rule ccontr)\n          assume \"\\<not> k \\<le> t + dly\"\n          hence \"t + dly < k\"\n            by auto\n          hence \"\\<tau>'' k sig = None\"\n            unfolding \\<tau>''_new_def post_raw_def by auto\n          hence \"k \\<notin> keys (to_trans_raw_sig \\<tau>'' sig)\"\n            unfolding to_trans_raw_sig_def  by (simp add: keys_def zero_option_def)\n          with k_in_keys show False\n            by auto\n        qed\n        moreover have \"t < k\"\n        proof (rule ccontr)\n          assume \"\\<not> t < k\"\n          hence \"k \\<le> t\"\n            by auto\n          hence \"\\<tau>'' k sig = \\<tau>' k sig\"\n            unfolding \\<tau>''_new_def post_raw_def  using \"*\" by auto\n          also have \"... = \\<tau> k sig\"\n            unfolding lookup using `k \\<le> t`\n            by (metis \\<tau>'_def local.lookup purge_raw_before_now_unchanged)\n          also have \"... = None\"\n            using assms(4) `k \\<le> t`  using \\<open>\\<tau> t sig = None\\<close> by auto\n          finally have \"\\<tau>'' k sig = None\"\n            by auto\n          with k_in_keys show False\n            by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n        qed\n        ultimately show \"k = t + dly\"\n          using k_in_keys unfolding \\<tau>''_new_def to_trans_raw_sig_def post_raw_def\n        proof -\n          assume a1: \"k \\<in> keys (\\<lambda>n. (if n = t + dly then \\<tau>' n(sig \\<mapsto> cur_val) else if t + dly < n then (\\<tau>' n)(sig := None) else \\<tau>' n) sig)\"\n          assume a2: \"t < k\"\n          have f3: \"(if k = t + dly then \\<tau>' k(sig \\<mapsto> cur_val) else if t + dly < k then (\\<tau>' k)(sig := None) else \\<tau>' k) sig \\<noteq> 0\"\n            using a1 by (simp add: keys_def)\n          have f4: \"\\<forall>n. if n = t + dly then (if n = t + dly then \\<tau>' n(sig \\<mapsto> cur_val) else if t + dly < n then (\\<tau>' n)(sig := None) else \\<tau>' n) sig = (\\<tau>' n(sig \\<mapsto> cur_val)) sig else if t + dly < n then (if n = t + dly then \\<tau>' n(sig \\<mapsto> cur_val) else if t + dly < n then (\\<tau>' n)(sig := None) else \\<tau>' n) sig = ((\\<tau>' n)(sig := None)) sig else (if n = t + dly then \\<tau>' n(sig \\<mapsto> cur_val) else if t + dly < n then (\\<tau>' n)(sig := None) else \\<tau>' n) sig = \\<tau>' n sig\"\n            by presburger\n          { assume \"\\<not> t + dly < k\"\n            moreover\n            { assume \"(if k = t + dly then \\<tau>' k(sig \\<mapsto> cur_val) else if t + dly < k then (\\<tau>' k)(sig := None) else \\<tau>' k) sig = \\<tau>' k sig\"\n              have \"\\<not> k < t + dly\"\n                using f3 a2 \\<open>inf_time (to_trans_raw_sig \\<tau>) sig (t + dly) = Some time \\<and> time \\<le> t + dly\\<close> \\<open>time = t + dly\\<close> local.lookup zero_option_def by auto\n              then have ?thesis\n                using \\<open>k \\<le> t + dly\\<close> le_neq_implies_less by blast }\n            ultimately have ?thesis\n              using f4 by meson }\n          then show ?thesis\n            using f3 zero_option_def by fastforce\n        qed\n      qed\n    { fix k1 k2 :: nat\n      assume \"k1 < k2\"\n      assume \"k1 \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>'' sig)\"\n      assume \"k2 \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>'' sig)\"\n      hence \"k1 = k2\"\n        using `k1 \\<in> keys (to_trans_raw_sig \\<tau>'' sig)`  * by metis\n      with `k1 < k2` have False by auto\n      hence \"to_trans_raw_sig \\<tau>'' sig k1 \\<noteq> to_trans_raw_sig \\<tau>'' sig k2\"\n        by auto }\n    hence first_po: \"(\\<forall>k1 k2.\n        k1 < k2 \\<and>\n        k1 \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>'' sig) \\<and>\n        k2 \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>'' sig) \\<and> (\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>'' sig)) \\<longrightarrow>\n        to_trans_raw_sig \\<tau>'' sig k1 \\<noteq> to_trans_raw_sig \\<tau>'' sig k2)\"\n      by auto\n    have \"keys (to_trans_raw_sig \\<tau>'' sig) \\<noteq> {}\"\n    proof -\n      have \"\\<tau>'' (t + dly) sig = Some cur_val\"\n        unfolding \\<tau>''_new_def post_raw_def by auto\n      thus ?thesis\n        by (metis domIff dom_def empty_iff keys_def option.distinct(1) to_trans_raw_sig_def zero_option_def)\n    qed\n    have \"(LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) = t + dly\"\n      by (smt \"*\" Collect_empty_eq LeastI \\<open>keys (to_trans_raw_sig \\<tau>'' sig) \\<noteq> {}\\<close> keys_def mem_Collect_eq)\n    hence \"the (to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>'' sig))) = cur_val\"\n      unfolding \\<tau>''_new_def post_raw_def  by (simp add: to_trans_raw_sig_def)\n    hence \" \\<sigma> sig \\<noteq> the (to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>'' sig)))\"\n      using False by auto\n    with first_po have ?thesis\n      unfolding non_stuttering_def by auto }\n  ultimately have ?thesis\n    by auto }\n  ultimately show ?thesis\n    by auto\nnext\n  case True\n  let ?s1 = \"signal_of (\\<sigma> sig) \\<tau> sig t\"\n  let ?s2 = \"signal_of (\\<sigma> sig) \\<tau> sig (t + dly)\"\n  let ?k2 = \"inf_time (to_trans_raw_sig \\<tau>) sig (t + dly)\"\n  have \"(?s1 = cur_val \\<or> ?s2 \\<noteq> cur_val) \\<or> (?s1 \\<noteq> cur_val \\<and> ?s2 = cur_val)\"\n    by auto\n  moreover\n  { assume \"?s1 = cur_val \\<or> ?s2 \\<noteq> cur_val\"\n    hence lookup: \"\\<tau>' = override_on \\<tau> (\\<lambda>n. (\\<tau> n)(sig := None)) {t <.. t + dly} \"\n      unfolding \\<tau>'_def purge_raw_def by auto\n    have \"\\<tau> t sig = None\"\n      using assms(4) by (auto simp add: zero_fun_def zero_option_def)\n    have \"\\<forall>n \\<le> t. \\<tau> n = 0\"\n      using assms(4) by (auto simp add: zero_option_def)\n    have \"\\<not> post_necessary_raw (dly - 1) \\<tau>' t sig cur_val (\\<sigma> sig)\"\n    proof -\n      have *: \"(\\<forall>i. i \\<le> t + (dly - 1) \\<longrightarrow> \\<tau>' i sig = None)\"\n        using lookup unfolding override_on_def\n        by (simp add: assms(4) not_less zero_fun_def zero_option_def)\n      thus ?thesis\n        using post_necessary_raw_correctness True\n        by (metis assms(1) le_add2 not_add_less1 signal_of_intro)\n    qed\n    hence lookup2: \"\\<tau>'' = preempt_raw sig \\<tau>' (t + dly)\"\n      unfolding \\<tau>''_def  trans_post_raw_def by auto\n    hence \"to_trans_raw_sig \\<tau>'' sig = 0\"\n      using `\\<forall>n \\<le> t. \\<tau> n = 0` `\\<tau> t sig = None` lookup\n      unfolding preempt_raw_def to_trans_raw_sig_def override_on_def zero_fun_def zero_option_def\n      by (intro ext, simp)\n    with True have ?thesis\n      unfolding non_stuttering_def Let_def keys_def by (simp add: zero_fun_def) }\n  moreover\n  { assume \"?s1 \\<noteq> cur_val \\<and> ?s2 = cur_val\"\n    have \"inf_time (to_trans_raw_sig \\<tau>) sig t = None\"\n      unfolding sym[OF inf_time_none_iff] using assms(4)\n      by (metis domIff not_less to_trans_raw_sig_def zero_fun_def zero_option_def)\n    hence \"signal_of (\\<sigma> sig) \\<tau> sig t = (\\<sigma> sig)\"\n      unfolding to_signal_def comp_def by auto\n    also have \"... = cur_val\"\n      using True by auto\n    finally have \"signal_of (\\<sigma> sig) \\<tau> sig t = cur_val\"\n      by auto\n    with \\<open>?s1 \\<noteq> cur_val \\<and> ?s2 = cur_val\\<close> have False\n      by auto\n    hence ?thesis\n      by auto }\n  ultimately show ?thesis\n    by auto\nqed\n\nlemma purge'_trans_post_preserve_non_stuttering_bv:\n  fixes \\<tau> sig t dly cur_val b\n  assumes \"non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma> sig\"\n  defines \"\\<tau>'  \\<equiv> purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Bv b)\"\n  defines \"\\<tau>'' \\<equiv> trans_post_raw sig (Bv b) (\\<sigma> sig) \\<tau>' t dly\"\n  assumes \"\\<forall>n. n \\<le> t \\<longrightarrow>  \\<tau> n = 0\"\n  shows \"non_stuttering (to_trans_raw_sig \\<tau>'') \\<sigma> sig\"\n  using purge_trans_post_preserve_non_stuttering assms\n  unfolding purge_raw'_def by auto\n\n(* lemma signal_of_to_trans_raw_bit:\n  assumes \"signal_of def \\<tau> sig t = Lv sign bs\"\n  shows   \"signal_of (Bv (lval_of def ! b)) (to_trans_raw_bit def \\<tau> b sig) sig t = Bv (bs ! b)\"\nproof -\n  have \"signal_of (Bv (case def of Lv sign bs \\<Rightarrow> bs ! b | Bv b' \\<Rightarrow> b')) (to_trans_raw_bit def \\<tau> b sig) sig t = Bv (bs ! b)\"\n    using to_bit_signal_of' assms  by (metis to_bit.simps(2)) \n  thus ?thesis\n    sledgehammer\n *)\n\n(* lemma keys_unchanged_to_trans_raw_bit:\n  assumes \"\\<forall>k. k \\<in> keys (to_trans_raw_sig \\<tau> sig) \\<longrightarrow> (type_of o the) (\\<tau> k sig) \\<noteq> Bty\"\n  shows   \"\\<forall>k. k \\<in> keys (to_trans_raw_sig (to_trans_raw_bit def \\<tau> b sig) sig) \\<longleftrightarrow> k \\<in> keys (to_trans_raw_sig \\<tau> sig)\"\n  using assms\n  unfolding to_trans_raw_sig_def to_trans_raw_bit_def keys_def by (auto simp add: zero_fun_def zero_option_def split: option.splits val.splits)\n *)\n\nlemma purge'_trans_post_preserve_non_stuttering_lv:\n  fixes \\<tau> sig t dly cur_val sign bs\n  assumes \"non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma> sig\"\n  defines \"\\<tau>'  \\<equiv> purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)\"\n  defines \"\\<tau>'' \\<equiv> trans_post_raw sig (Lv sign bs) (\\<sigma> sig) \\<tau>' t dly\"\n  assumes \"\\<forall>n. n \\<le> t \\<longrightarrow>  \\<tau> n = 0\"\n  shows \"non_stuttering (to_trans_raw_sig \\<tau>'') \\<sigma> sig\"\nproof -\n  have 1: \"\\<tau>' = combine_trans_bit \\<tau>\n          (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs]) \n               (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))\n          sign sig t dly\"\n    unfolding \\<tau>'_def purge_raw'_def by auto\n  have \"post_necessary_raw (dly - 1) \\<tau>' t sig (Lv sign bs) (\\<sigma> sig) \\<or> \n     \\<not> post_necessary_raw (dly - 1) \\<tau>' t sig (Lv sign bs) (\\<sigma> sig)\"\n    by auto\n  moreover\n  { assume \"post_necessary_raw (dly - 1) \\<tau>' t sig (Lv sign bs) (\\<sigma> sig)\"\n    hence 0: \"\\<tau>'' = post_raw sig (Lv sign bs) \\<tau>' (t + dly)\" and \"signal_of (\\<sigma> sig) \\<tau>' sig (t + (dly - 1)) \\<noteq> Lv sign bs\"\n      unfolding \\<tau>''_def trans_post_raw_def by auto\n    have ?thesis\n      unfolding non_stuttering_def \n    proof (rule, rule, rule, rule)\n      fix k1 k2\n      assume \"k1 < k2 \\<and> k1 \\<in> keys (to_trans_raw_sig \\<tau>'' sig) \\<and> k2 \\<in> keys (to_trans_raw_sig \\<tau>'' sig) \\<and> (\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig \\<tau>'' sig))\"\n      hence \"k1 < k2\" and \"k1 \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\" and \"k2 \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\" and \n        2: \"(\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig \\<tau>'' sig))\" by auto\n      have \"k2 \\<le> t + dly\"\n      proof (rule ccontr)\n        assume \"\\<not> k2 \\<le> t + dly\" hence \"t + dly < k2\" by auto\n        hence \"\\<tau>'' k2 sig = None\"\n          using `\\<tau>'' = post_raw sig (Lv sign bs) \\<tau>' (t + dly)` unfolding post_raw_def by auto\n        with `k2 \\<in> keys (to_trans_raw_sig \\<tau>'' sig)` show False \n          unfolding to_trans_raw_sig_def keys_def zero_option_def by auto\n      qed\n      have \"k1 \\<in> keys (to_trans_raw_sig \\<tau>' sig)\"\n        using `k1 \\<in> keys (to_trans_raw_sig \\<tau>'' sig)` unfolding 0 post_raw_def to_trans_raw_sig_def keys_def zero_option_def\n        using \\<open>k1 < k2\\<close> \\<open>k2 \\<le> t + dly\\<close> by auto\n      have 3: \"(\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig \\<tau>' sig))\"\n        using `k2 \\<le> t + dly` 0 2 `k1 < k2` unfolding post_raw_def \n        by (metis domIff dom_def dual_order.asym keys_def less_le_trans to_trans_raw_sig_def zero_option_def)\n      have \"k2 < t \\<or> k2 \\<ge> t\"\n        by auto\n      moreover\n      { assume \"k2 < t\"\n        hence \"\\<tau>'' k2 sig = \\<tau>' k2 sig\"\n          using 0 unfolding post_raw_def by auto\n        also have \"... = \\<tau> k2 sig\"\n          using 1 `k2 < t` unfolding combine_trans_bit_def Let_def by auto\n        finally have \"\\<tau>'' k2 sig = \\<tau> k2 sig\"\n          by auto\n        hence \"False\"\n          by (metis (full_types) \\<open>k1 < k2 \\<and> k1 \\<in> keys (to_trans_raw_sig \\<tau>'' sig) \\<and> k2 \\<in> keys\n          (to_trans_raw_sig \\<tau>'' sig) \\<and> (\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig \\<tau>'' sig))\\<close>\n          \\<open>k2 < t\\<close> assms(4) domIff dom_def keys_def less_imp_le_nat to_trans_raw_sig_def\n          zero_fun_def zero_option_def)\n        hence \"to_trans_raw_sig \\<tau>'' sig k1 \\<noteq> to_trans_raw_sig \\<tau>'' sig k2\"\n          by auto }\n      moreover\n      { assume \"k2 \\<ge> t\"\n        have \"dly = 0 \\<or> dly \\<noteq> 0\"\n          by auto\n        moreover\n        { assume \"dly = 0\"\n          hence \"k2 = t\" \n            using \\<open>k2 \\<le> t + dly\\<close> \\<open>t \\<le> k2\\<close> by linarith\n          have \"k1 < t\"\n            using `k1 < k2` `k2 = t` by auto\n          hence \"\\<tau>''  k1 sig = \\<tau>' k1 sig\"\n            using 0 unfolding post_raw_def by auto\n          also have \"... = \\<tau> k1 sig\"\n            using `k1 < t` unfolding 1 combine_trans_bit_def Let_def by auto\n          also have \"... = 0\"\n            using `k1 < t` assms(4) by (auto simp add: zero_fun_def zero_option_def)\n          finally have \"\\<tau>'' k1 sig = 0\"\n            by auto\n          hence \"k1 \\<notin> keys (to_trans_raw_sig \\<tau>'' sig)\"\n            unfolding to_trans_raw_sig_def keys_def by auto\n          with `k1 \\<in> keys (to_trans_raw_sig \\<tau>'' sig)` have False\n            by auto\n          hence \"to_trans_raw_sig \\<tau>'' sig k1 \\<noteq> to_trans_raw_sig \\<tau>'' sig k2\"\n            by auto }\n        moreover\n        { assume \"dly \\<noteq> 0\"\n          have \"k2 = t + dly \\<or> k2 < t + dly\"\n            using `k2 \\<le> t + dly` by auto\n          moreover\n          { assume \"k2 = t + dly\"\n            hence \"\\<tau>'' k2 sig = Some (Lv sign bs)\"\n              unfolding 0 post_raw_def by auto\n            have \"t < k1\"\n            proof (rule ccontr)\n              assume \"\\<not> t < k1\" hence \"k1 \\<le> t\" by auto\n              hence \"\\<tau>'' k1 sig = \\<tau>' k1 sig\"\n                using ` dly \\<noteq> 0` unfolding 0 post_raw_def by auto\n              also have \"... = \\<tau> k1 sig\"\n                unfolding 1 combine_trans_bit_def using `k1 \\<le> t` by auto\n              also have \"... = 0\"\n                using assms(4)  by (simp add: \\<open>k1 \\<le> t\\<close> zero_fun_def)\n              finally have \"\\<tau>'' k1 sig = 0\"\n                by auto\n              with `k1 \\<in> keys (to_trans_raw_sig \\<tau>'' sig)` show False\n                by (simp add: keys_def to_trans_raw_sig_def)\n            qed\n            hence \"\\<tau>'' k1 sig = \\<tau>' k1 sig\"\n              using `k1 < k2` `k2 = t + dly` unfolding 0 post_raw_def by auto\n            have \"inf_time (to_trans_raw_sig \\<tau>') sig (t + (dly - 1)) = Some k1\"\n            proof (rule inf_time_someI)\n              show \"k1 \\<in> dom (to_trans_raw_sig \\<tau>' sig)\"\n                using `k1 \\<in> keys (to_trans_raw_sig \\<tau>' sig)`  by (simp add: dom_def keys_def zero_option_def)\n            next\n              show \"k1 \\<le> t + (dly - 1)\"\n                using \\<open>k1 < k2\\<close> \\<open>k2 = t + dly\\<close> by linarith\n            next\n              { fix ta\n                assume \"ta \\<in> dom (to_trans_raw_sig \\<tau>' sig)\"\n                assume \"k1 < ta\"\n                assume \"ta \\<le> t + (dly - 1)\"\n                have \"ta < k2\"\n                  using \\<open>dly \\<noteq> 0\\<close> \\<open>k2 = t + dly\\<close> \\<open>ta \\<le> t + (dly - 1)\\<close> by linarith\n                hence \"ta \\<notin> keys (to_trans_raw_sig \\<tau>' sig)\"\n                  using 3 \\<open>k1 < ta\\<close> by blast\n                with `ta \\<in> dom (to_trans_raw_sig \\<tau>' sig)` have False\n                  by (simp add: dom_def keys_def zero_option_def) }\n              thus \"\\<forall>ta\\<in>dom (to_trans_raw_sig \\<tau>' sig). ta \\<le> t + (dly - 1) \\<longrightarrow> ta \\<le> k1\"\n                using leI by blast\n            qed\n            hence \"the (to_trans_raw_sig \\<tau>' sig k1) \\<noteq> Lv sign bs\"\n              using `(signal_of (\\<sigma> sig) \\<tau>' sig (t + (dly - 1)) \\<noteq> Lv sign bs)`\n              unfolding to_signal_def comp_def by auto\n            hence \"to_trans_raw_sig \\<tau>'' sig k1 \\<noteq> to_trans_raw_sig \\<tau>'' sig k2\"\n              by (metis \\<open>\\<tau>'' k1 sig = \\<tau>' k1 sig\\<close> \\<open>\\<tau>'' k2 sig = Some (Lv sign bs)\\<close> option.sel to_trans_raw_sig_def) }\n          moreover\n          { assume \"k2 < t + dly\"\n            hence \"\\<tau>'' k2 sig = \\<tau>' k2 sig\"\n              using 0 unfolding post_raw_def by auto\n            have \"t < k2\"\n            proof (rule ccontr)\n              assume \"\\<not> t < k2\" hence \"k2 \\<le> t\" by auto\n              hence \"\\<tau>' k2 sig = \\<tau> k2 sig\"\n                unfolding 1 combine_trans_bit_def by auto\n              also have \"... = 0\"\n                using assms  by (simp add: \\<open>k2 \\<le> t\\<close> zero_fun_def)\n              finally have \"\\<tau>'' k2 sig = 0\"\n                by (simp add: \\<open>\\<tau>'' k2 sig = \\<tau>' k2 sig\\<close>)\n              with `k2 \\<in> keys (to_trans_raw_sig \\<tau>'' sig)` show False\n                by (simp add: keys_def to_trans_raw_sig_def)\n            qed\n            hence \"k2 \\<in> keys (to_trans_raw_sig \\<tau>' sig)\"\n              using `k2 \\<in> keys (to_trans_raw_sig \\<tau>'' sig)` \n              by (simp add: \\<open>\\<tau>'' k2 sig = \\<tau>' k2 sig\\<close> keys_def to_trans_raw_sig_def)\n            hence \"\\<tau>' k2 sig \\<noteq> None\"\n              by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n            hence k2inset: \"k2 \\<in> fold (\\<union>)\n            (map (keys \\<circ> (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> snd)\n              (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])))\n            {}\"\n              using `t < k2` `k2 < t + dly` unfolding 1 combine_trans_bit_def Let_def \n              by (meson dual_order.asym leD)\n            hence \"\\<tau>' k2 sig = Some\n                (Lv sign\n                  (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig k2))\n                    (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                      (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))))\"\n              unfolding 1 combine_trans_bit_def Let_def  using \\<open>k2 < t + dly\\<close> \\<open>t < k2\\<close> by auto\n            hence 4: \"(lval_of o the) (\\<tau>' k2 sig) =  (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig k2))\n                    (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                      (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])))\"\n              by auto\n            have 5: \"\\<And>b. b \\<in> set [0..< length bs] \\<Longrightarrow> (lval_of o the) (\\<tau>' k2 sig) ! b = \n                      bval_of (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig k2)\"\n            proof -\n              fix b\n              assume \"b \\<in> set [0 ..< length bs]\"\n              have \"(lval_of o the) (\\<tau>' k2 sig) ! b = (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig k2))\n                    (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                      (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))) ! b\" (is \"_ = ?complex\")\n                using 4 by auto\n              have *: \"b < length (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                      (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))\"\n                using `b \\<in> set [0 ..< length bs]` by auto\n              have **: \"?complex = bval_of\n     (signal_of\n       (fst (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs]) \n                 (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]) ! b))\n       (snd (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs]) \n                 (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]) ! b))\n       sig k2)\"\n                unfolding  nth_map[OF *] by auto \n              moreover have \"[0 ..< length bs] ! b = b\"\n                using `b \\<in> set [0 ..< length bs]` by auto\n              ultimately have \"?complex = bval_of \n                (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig k2)\"\n                unfolding **  using \\<open>b \\<in> set [0..<length bs]\\<close> \n                by (simp add: val.case_eq_if)\n              thus \"(lval_of \\<circ> the) (\\<tau>' k2 sig) ! b = bval_of (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig k2)\"\n                using 4 by auto\n            qed\n            have helper: \"\\<And>f. length (map f [0..<length bs]) \\<le> length bs - 0\"\n              by auto\n            have  \"k2 \\<in> fold (\\<union>) (map keys\n                   (map (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig)\n                     (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n)))\n                       [0..<length bs]))) {}\"\n              using k2inset unfolding map_map[THEN sym] map_snd_zip_take  length_map min.idem length_upt\n              take_all[OF helper] by auto\n            hence helper2:\" k2 \\<in> fold (\\<union>)\n               (map (\\<lambda>x. keys\n                      (to_trans_raw_sig\n                        (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> x sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! x)) (Bv (bs ! x))) sig))\n             [0..<length bs]) {}\" \n              unfolding map_map comp_def  by auto                   \n            obtain b2 where \"b2 \\<in> set [0..< length bs]\" and \"k2 \\<in> keys (to_trans_raw_sig\n                            (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2))) sig)\"\n              using member_fold_union[OF helper2] by auto\n            hence purge_neq: \"purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2)) k2 sig \\<noteq> 0\"\n              unfolding keys_def to_trans_raw_sig_def by auto\n            have the_time: \"Some k2 = inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig)) sig (t + dly)\" and \n              sig_neq: \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) sig t \\<noteq> Bv (bs ! b2)\" and \n              sig_eq: \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) sig (t + dly) = Bv (bs ! b2)\"\n              using `t < k2` `k2 < t + dly` purge_raw_neq_0_imp[OF purge_neq `t < k2` `k2 < t + dly`] \n              by auto\n            moreover hence \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig k2 sig = Some (Bv (bs ! b2))\"\n              unfolding to_signal_def comp_def to_trans_raw_sig_def \n              by (smt inf_time_some_exists keys_def mem_Collect_eq not_None_eq option.sel\n              option.simps(5) zero_option_def)\n            ultimately have \"purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2)) k2 sig = Some (Bv (bs ! b2))\"\n              using `t < k2` `k2 < t + dly` unfolding purge_raw_def Let_def \n              by (smt \"3\" UnE \\<open>k1 < k2\\<close> \\<open>k2 \\<in> keys (to_trans_raw_sig \\<tau>' sig)\\<close> greaterThanAtMost_iff greaterThanLessThan_iff option.sel override_on_apply_notin)\n            hence \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2)) \n                            (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2))) sig k2 = Bv (bs ! b2)\"\n              using trans_some_signal_of'  by (metis o_apply option.sel )\n            hence \"(lval_of o the) (\\<tau>' k2 sig) ! b2 = bs ! b2\"\n              using 5[OF `b2 \\<in> set [0..< length bs]`] by auto\n\n            have \"k1 < t + dly\"\n              using `k1 < k2` `k2 < t + dly` by auto\n            have \"t < k1\"\n            proof (rule ccontr)\n              assume \"\\<not> t < k1\" hence \"k1 \\<le> t\" by auto\n              hence \"\\<tau>' k1 sig = \\<tau> k1 sig\"\n                unfolding 1 combine_trans_bit_def by auto\n              also have \"... = 0\"\n                using assms  by (simp add: \\<open>k1 \\<le> t\\<close> zero_fun_def)\n              finally have \"\\<tau>' k1 sig = 0\"\n                by (simp)\n              with `k1 \\<in> keys (to_trans_raw_sig \\<tau>' sig)` show False\n                by (simp add: keys_def to_trans_raw_sig_def)\n            qed\n            have \"\\<tau>' k1 sig \\<noteq> None\"\n              using `k1 \\<in> keys (to_trans_raw_sig \\<tau>' sig)` \n              by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n            hence k1inset: \"k1 \\<in> fold (\\<union>)\n            (map (keys \\<circ> (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> snd)\n              (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])))\n            {}\"\n              using `t < k1` `k1 < t + dly` unfolding 1 combine_trans_bit_def Let_def \n              by (meson dual_order.asym leD)\n            have  \"k1 \\<in> fold (\\<union>) (map keys\n                   (map (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig)\n                     (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n)))\n                       [0..<length bs]))) {}\"\n              using k1inset unfolding map_map[THEN sym] map_snd_zip_take  length_map min.idem length_upt\n              take_all[OF helper] by auto\n            hence k1inset':\" k1 \\<in> fold (\\<union>)\n               (map (\\<lambda>x. keys\n                      (to_trans_raw_sig\n                        (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> x sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! x)) (Bv (bs ! x))) sig))\n             [0..<length bs]) {}\" \n              unfolding map_map comp_def  by auto     \n            obtain b1 where \"b1 \\<in> set [0..< length bs]\" and \"k1 \\<in> keys (to_trans_raw_sig\n                            (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b1 sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b1)) (Bv (bs ! b1))) sig)\"\n              using member_fold_union[OF k1inset'] by auto \n            hence purge_neq: \"purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b1 sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b1)) (Bv (bs ! b1)) k1 sig \\<noteq> 0\"\n              unfolding keys_def to_trans_raw_sig_def by auto\n            have \"Some k1 = inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b1 sig)) sig (t + dly)\" and \n              \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b1)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b1 sig) sig t \\<noteq> Bv (bs ! b1)\" and \n              \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b1)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b1 sig) sig (t + dly) = Bv (bs ! b1)\"\n              using `t < k1` `k1 < t + dly` purge_raw_neq_0_imp[OF purge_neq `t < k1` `k1 < t + dly`] \n              by auto\n            have \"Some k1 = inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b1 sig)) sig (t + dly)\" and \n              \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b1)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b1 sig) sig t \\<noteq> Bv (bs ! b1)\" and \n              \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b1)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b1 sig) sig (t + dly) = Bv (bs ! b1)\"\n              using `t < k1` `k1 < t + dly` purge_raw_neq_0_imp[OF purge_neq `t < k1` `k1 < t + dly`] \n              by auto\n            hence \"\\<tau>' k1 sig = Some\n                (Lv sign\n                  (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig k1))\n                    (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                      (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))))\"\n              unfolding 1 combine_trans_bit_def Let_def  using \\<open>k1 < t + dly\\<close> \\<open>t < k1\\<close> k1inset by auto\n            hence 5: \"(lval_of o the) (\\<tau>' k1 sig) =  (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig k1))\n                    (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                      (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])))\"\n              by auto\n            have 6: \"\\<And>b. b \\<in> set [0..< length bs] \\<Longrightarrow> (lval_of o the) (\\<tau>' k1 sig) ! b = \n                      bval_of (signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig k1)\"\n            proof -\n              fix b\n              assume \"b \\<in> set [0 ..< length bs]\"\n              have \"(lval_of o the) (\\<tau>' k1 sig) ! b = (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig k1))\n                    (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                      (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))) ! b\" (is \"_ = ?complex\")\n                using 5 by auto\n              have *: \"b < length (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                      (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))\"\n                using `b \\<in> set [0 ..< length bs]` by auto\n              have **: \"?complex = bval_of\n     (signal_of\n       (fst (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs]) \n                 (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]) ! b))\n       (snd (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs]) \n                 (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]) ! b))\n       sig k1)\"\n                unfolding  nth_map[OF *] by auto \n              moreover have \"[0 ..< length bs] ! b = b\"\n                using `b \\<in> set [0 ..< length bs]` by auto\n              ultimately have \"?complex = bval_of \n                (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig k1)\"\n                unfolding **\n                using \\<open>b \\<in> set [0..<length bs]\\<close>  by (simp add: val.case_eq_if)\n              thus \"(lval_of \\<circ> the) (\\<tau>' k1 sig) ! b = bval_of (signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig k1)\"\n                using 5 by auto\n            qed\n          \n            have \"purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2)) k1 sig = None\"\n              using `t < k1` `k1 < k2` sig_neq sig_eq the_time unfolding purge_raw_def Let_def\n              by (smt Un_iff fun_upd_eqD fun_upd_triv greaterThanLessThan_iff option.sel override_on_apply_in)\n            have 7: \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2))) sig k1 = \n                  signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2))) sig t\"\n            proof (intro signal_of_less_ind')\n              fix n\n              assume \"t < n\" and \"n \\<le> k1\"\n              thus \" purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2)) n sig = 0\"\n                using `k1 < k2` sig_neq sig_eq the_time unfolding purge_raw_def Let_def\n                apply (auto simp add: override_on_def to_trans_raw_bit_def zero_option_def zero_fun_def split: option.splits val.splits intro!: ext)\n                   apply (metis linorder_neqE_nat not_le option.sel)\n                using \\<open>k2 \\<le> t + dly\\<close> apply linarith\n                 apply (metis le_less_trans option.sel)\n                using \\<open>k1 < t + dly\\<close> by linarith\n              next\n              show \"t \\<le> k1\"\n                using `t < k1` by auto\n            qed \n            also have \"... = signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) sig t \"\n            proof (rule signal_of_equal_when_trans_equal_upto)\n              fix n \n              assume \"n \\<le> t\"\n              thus \"purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2)) n = to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig n\"\n                unfolding purge_raw_def Let_def override_on_def \n                by (smt Un_iff \\<open>t \\<le> k2\\<close> greaterThanAtMost_iff greaterThanLessThan_iff leD less_le_trans option.sel the_time)\n            qed (auto)\n            also have \"... \\<noteq> Bv (bs ! b2)\"\n              using sig_neq by auto\n            finally have \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2))) sig k1 \\<noteq> Bv (bs ! b2)\"\n              by auto\n            moreover have \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) sig t  = (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2))\"\n              apply (rule signal_of_def)\n              using assms(4)\n              unfolding to_trans_raw_bit_def by (simp add: zero_fun_def zero_option_def)\n            ultimately have \"(lval_of o the) (\\<tau>' k1 sig) ! b2 \\<noteq> bs ! b2\"\n              using 6[OF `b2 \\<in> set [0 ..< length bs]`] \n              using \"7\"\n              using \\<open>signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2))) sig t = signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b2)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) sig t\\<close> by auto\n            with `(lval_of o the) (\\<tau>' k2 sig) ! b2 = bs ! b2` have \"\\<tau>' k1 sig \\<noteq> \\<tau>' k2 sig\"\n              by auto\n            moreover have \"\\<tau>'' k1 sig = \\<tau>' k1 sig\"\n              using 0 `t < k1` `k1 < t + dly` unfolding post_raw_def by auto\n            ultimately have \"to_trans_raw_sig \\<tau>'' sig k1 \\<noteq> to_trans_raw_sig \\<tau>'' sig k2\"\n              using `\\<tau>'' k2 sig = \\<tau>' k2 sig`  unfolding to_trans_raw_sig_def by auto }\n          ultimately have \"to_trans_raw_sig \\<tau>'' sig k1 \\<noteq> to_trans_raw_sig \\<tau>'' sig k2\"\n            by auto }\n        ultimately have \"to_trans_raw_sig \\<tau>'' sig k1 \\<noteq> to_trans_raw_sig \\<tau>'' sig k2\"\n          by auto }\n      ultimately show \"to_trans_raw_sig \\<tau>'' sig k1 \\<noteq> to_trans_raw_sig \\<tau>'' sig k2\"\n        by auto \n    next\n      have \"t + dly \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\"\n        unfolding 0 post_raw_def to_trans_raw_sig_def keys_def by (auto simp add: zero_fun_def zero_option_def)\n      hence \"(LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) \\<le> t + dly\"\n        using Least_le  by (simp add: Least_le)\n      hence \"(LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) = t + dly \\<or> (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) < t + dly\"\n        by auto\n      moreover\n      { assume \"(LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) = t + dly\"\n        hence \"(to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig))) = Some (Lv sign bs)\"\n          using 0 unfolding post_raw_def  by (simp add: to_trans_raw_sig_def)\n        have \"\\<And>n. n < t + dly \\<Longrightarrow> to_trans_raw_sig \\<tau>'' sig n = 0\"\n          using `(LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) = t + dly`\n            not_less_Least unfolding 0 post_raw_def   by (smt keys_def mem_Collect_eq)\n        have \"0 < dly \\<or> dly = 0\"\n          by auto\n        moreover \n        { assume \"0 < dly\"\n          have \"signal_of (\\<sigma> sig) \\<tau>' sig (t + (dly - 1)) = \\<sigma> sig\"\n            apply (intro signal_of_def)\n            using `\\<And>n. n < t + dly \\<Longrightarrow> to_trans_raw_sig \\<tau>'' sig n = 0` \n            unfolding to_trans_raw_sig_def 0 post_raw_def \n          proof -\n            fix n :: nat\n            assume a1: \"n \\<le> t + (dly - 1)\"\n            assume a2: \"\\<And>n. n < t + dly \\<Longrightarrow> (if n = t + dly then \\<tau>' n(sig \\<mapsto> Lv sign bs) else if t + dly < n then (\\<tau>' n)(sig := None) else \\<tau>' n) sig = 0\"\n            have \"Suc 0 \\<le> dly\"\n              by (metis (no_types) Suc_leI \\<open>0 < dly\\<close>)\n            then show \"\\<tau>' n sig = 0\"\n              using a2 a1 by simp\n          qed\n          hence \"\\<sigma> sig \\<noteq> the (to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)))\"\n            using \\<open>post_necessary_raw (dly - 1) \\<tau>' t sig (Lv sign bs) (\\<sigma> sig)\\<close> \\<open>to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) = Some (Lv sign bs)\\<close> by auto }\n        moreover\n        { assume \"dly = 0\"\n          hence \"(LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) = t\"\n            using `(LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) = t + dly` by auto\n          have \"to_trans_raw_sig \\<tau>'' sig t = Some (Lv sign bs)\"\n            unfolding 0 \n            using \"0\" \\<open>(LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) = t + dly\\<close> \\<open>dly = 0\\<close>\n            \\<open>to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) = Some (Lv sign\n            bs)\\<close> by auto\n          have \"signal_of (\\<sigma> sig) \\<tau>' sig (t + (dly - 1)) = signal_of (\\<sigma> sig) \\<tau>' sig t\"\n            using `dly = 0` by auto\n          also have \"... = \\<sigma> sig\"\n            using assms(4) \n            by (metis \\<tau>'_def purge_preserve_trans_removal_nonstrict' signal_of_def zero_fun_def)\n          finally have \"signal_of (\\<sigma> sig) \\<tau>' sig (t + (dly - 1)) = \\<sigma> sig\"\n            by auto\n          hence \"\\<sigma> sig \\<noteq> the (to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)))\"\n            using \\<open>post_necessary_raw (dly - 1) \\<tau>' t sig (Lv sign bs) (\\<sigma> sig)\\<close> \\<open>to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) = Some (Lv sign bs)\\<close> by auto }\n        ultimately have \"\\<sigma> sig \\<noteq> the (to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)))\"\n          by auto }\n      moreover\n      { assume lt: \" (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) < t + dly\"\n        have \"(LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\"\n          using LeastI  by (metis \\<open>t + dly \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\\<close>)      \n        hence \"to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) \\<noteq> 0\"\n          unfolding keys_def by auto\n        with lt have \"\\<tau>' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig \\<noteq> 0\"\n          unfolding 0 post_raw_def to_trans_raw_sig_def by auto\n        have \"t < (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig))\"\n        proof (rule ccontr)\n          assume \"\\<not> t < (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig))\"\n          hence \" (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) \\<le> t\"\n            by auto\n          hence \"\\<tau>' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig = 0\"\n            using assms(4)\n            unfolding 1  combine_trans_bit_def Let_def by (auto simp add :zero_fun_def)\n          with `\\<tau>' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig \\<noteq> 0`\n          show False\n            unfolding to_trans_raw_sig_def by auto\n        qed\n        hence \"\\<tau>'' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig = \\<tau>' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig\"\n          using lt unfolding 0 post_raw_def by auto\n        let ?t = \"LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\"\n        have **: \"?t \\<in> fold (\\<union>)\n          (map (keys \\<circ> (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> snd)\n            (zip (map (\\<lambda>n.  (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs]) \n                 (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig  (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))) {}\"\n          using `\\<tau>' ?t sig \\<noteq> 0` `t < ?t` `?t < t + dly` unfolding 1 combine_trans_bit_def\n          using not_le zero_option_def by fastforce\n        hence \"?t \\<in> fold (\\<union>) (map keys (map (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \n                                       (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig  (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))) {}\"\n          unfolding map_map[THEN sym] map_snd_zip_take length_map min.idem length_upt\n          using take_all by auto\n        hence *: \"?t  \\<in> fold (\\<union>) (map (keys \\<circ> ((\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))))) [0..<length bs]) {}\"\n          unfolding map_map by auto\n        have \"(\\<exists>x\\<in>set (map (keys \\<circ> ((\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))))) [0..<length bs]).\n                      ?t \\<in> x)\"\n          using member_fold_union[OF *] unfolding empty_iff by auto\n        then obtain b where \"?t \\<in> keys (((\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n)))) b)\" and \n          \"b \\<in> set [0..< length bs]\" by auto\n        hence \"?t \\<in>  keys (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)) n sig)\"\n          unfolding comp_def to_trans_raw_sig_def by auto\n        hence \"purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)) ?t sig \\<noteq> 0\"\n          unfolding keys_def by auto\n        from purge_raw_neq_0_imp[OF this `t < ?t` `?t < t + dly`]\n        have inf_time: \" inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly) = Some ?t\"\n          and sig_neq: \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig t \\<noteq> Bv (bs ! b) \"\n          and sig_eq: \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (t + dly) = Bv (bs ! b)\" \n          by auto\n        hence \"purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)) ?t sig = \n               to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?t sig\"\n          using `t < ?t` `?t < t + dly` unfolding purge_raw_def Let_def by auto\n        also have \"... = Some (Bv (bs ! b))\"\n          using sig_eq inf_time unfolding to_signal_def comp_def \n          by (metis (mono_tags, lifting) \\<open>purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma>\n          sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)) (LEAST k. k \\<in> keys (to_trans_raw_sig\n          \\<tau>'' sig)) sig \\<noteq> 0\\<close> calculation option.collapse option.simps(5) to_trans_raw_sig_def\n          zero_option_def)\n        finally have ***: \"purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)) ?t sig = Some (Bv (bs ! b))\"\n          by auto\n        have \"\\<tau>' ?t sig = Some\n            (Lv sign\n              (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig ?t))\n                (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs])\n                  (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))))\"\n          using ** unfolding 1 combine_trans_bit_def Let_def  using \\<open>?t < t + dly\\<close> \\<open>t < ?t\\<close> by auto\n        hence 4: \"(lval_of o the) (\\<tau>' ?t sig) =  (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig ?t))\n                (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs])\n                  (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])))\"\n          by auto        \n        have 5: \"\\<And>b. b \\<in> set [0..< length bs] \\<Longrightarrow> (lval_of o the) (\\<tau>' ?t sig) ! b = \n                  bval_of (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) \n                    (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig ?t)\"\n        proof -\n          fix b\n          assume \"b \\<in> set [0 ..< length bs]\"\n          have \"(lval_of o the) (\\<tau>' ?t sig) ! b = (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig ?t))\n                (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs])\n                  (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))) ! b\" (is \"_ = ?complex\")\n            using 4 by auto\n          have *: \"b < length (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs])\n                  (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))\"\n            using `b \\<in> set [0 ..< length bs]` by auto\n          have **: \"?complex = bval_of\n (signal_of\n   (fst (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs]) \n             (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]) ! b))\n   (snd (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs]) \n             (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]) ! b))\n   sig ?t)\"\n            unfolding  nth_map[OF *] by auto \n          moreover have \"[0 ..< length bs] ! b = b\"\n            using `b \\<in> set [0 ..< length bs]` by auto\n          ultimately have \"?complex = bval_of \n            (signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig ?t)\"\n            using \\<open>b \\<in> set [0..<length bs]\\<close> unfolding ** by (simp add: val.case_eq_if)\n          thus \"(lval_of \\<circ> the) (\\<tau>' ?t sig) ! b = bval_of (signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) \n                          (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig ?t)\"\n            using 4 by auto\n        qed\n        hence h: \"(lval_of o the) (\\<tau>' ?t sig) ! b = \n          bval_of (signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) \n              (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig ?t)\"\n          using `b \\<in> set [0..< length bs]` by auto\n        have \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) \n                (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig ?t = Bv (bs ! b)\"\n        proof (rule signal_of_intro, rule, rule)\n          show \"?t \\<le> ?t\" by auto\n        next\n          have \"to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig \n                                (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) = Some (Bv (bs ! b))\"\n            using ***  unfolding to_trans_raw_sig_def by auto\n          moreover have \"(\\<forall>j>LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig).\n        j \\<le> (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) \\<longrightarrow> to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig j = None)\"\n            by auto\n          ultimately show \" to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) = Some (Bv (bs ! b)) \\<and>\n    (\\<forall>j>LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig).\n        j \\<le> (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) \\<longrightarrow> to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig j = None) \\<or>\n    (\\<forall>i\\<le>LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig). purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)) i sig = None) \\<and>\n    Bv (bs ! b) = (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b))\"\n            by auto\n        qed\n        hence \"bval_of (signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig ?t) = bs ! b\"\n          by auto\n        hence \"(lval_of o the) (\\<tau>' ?t sig) ! b = bs ! b\"\n          using h by auto\n        have \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig t = (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b))\"\n          apply (intro signal_of_def)\n          using assms(4) unfolding to_trans_raw_bit_def  by (simp add: zero_fun_def zero_option_def)\n        hence \" (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b) \\<noteq> bs ! b\"\n          using sig_neq by auto\n        hence \"\\<sigma> sig \\<noteq> the (to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)))\"\n          using \\<open>(lval_of \\<circ> the) (\\<tau>' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig) ! b =\n          bs ! b\\<close> \\<open>\\<tau>'' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig = \\<tau>' (LEAST k. k \\<in> keys\n          (to_trans_raw_sig \\<tau>'' sig)) sig\\<close> comp_apply to_trans_raw_sig_def \n          apply auto\n          subgoal \n          proof -\n            assume a1: \"\\<tau>'' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig = \\<tau>' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig\"\n            assume a2: \"\\<sigma> sig = the (to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)))\"\n            assume a3: \"case the (to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig))) of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b\"\n            assume a4: \"\\<not> lval_of (the (\\<tau>' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig)) ! b\"\n            have \"Some (Lv sign (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig (LEAST n. n \\<in> keys (to_trans_raw_sig \\<tau>'' sig)))) (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv s bs \\<Rightarrow> bs ! n)) [0..<length bs]) (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv s bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])))) = to_trans_raw_sig \\<tau>'' sig (LEAST n. n \\<in> keys (to_trans_raw_sig \\<tau>'' sig))\"\n              using a1 by (metis (no_types) \\<open>\\<tau>' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig = Some (Lv sign (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)))) (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs]) (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))))\\<close> to_trans_raw_sig_def)\n            then have f5: \"Lv sign (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig (LEAST n. n \\<in> keys (to_trans_raw_sig \\<tau>'' sig)))) (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv s bs \\<Rightarrow> bs ! n)) [0..<length bs]) (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv s bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))) = \\<sigma> sig\"\n              using a2  by (metis (no_types, lifting) option.sel)\n            then have \"map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig (LEAST n. n \\<in> keys (to_trans_raw_sig \\<tau>'' sig)))) (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv s bs \\<Rightarrow> bs ! n)) [0..<length bs]) (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv s bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])) = lval_of (\\<sigma> sig)\"\n              by (metis (no_types, lifting) val.sel(3))\n            then have \"Lv sign (lval_of (\\<sigma> sig)) = \\<sigma> sig\"\n              using f5 by presburger\n            then show False\n              using a4 a3 a2 a1 by (metis to_trans_raw_sig_def val.case(2))\n          qed\n          subgoal\n          proof -\n            assume a1: \"\\<tau>'' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig = \\<tau>' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig\"\n            assume a2: \"\\<sigma> sig = the (to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)))\"\n            assume \"\\<not> (case the (to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig))) of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)\"\n            assume a3: \"bs ! b\"\n            have \"Lv sign (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig (LEAST n. n \\<in> keys (to_trans_raw_sig \\<tau>'' sig)))) (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv s bs \\<Rightarrow> bs ! n)) [0..<length bs]) (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv s bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))) = \\<sigma> sig\"\n              using a2 a1 by (metis (lifting) \\<open>\\<tau>' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig = Some (Lv sign (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)))) (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs]) (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))))\\<close> option.sel to_trans_raw_sig_def)\n            then have \"Lv sign ((lval_of \\<circ> the) (\\<tau>' (LEAST n. n \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig)) = \\<sigma> sig\"\n              by (metis (lifting) \"4\") \n            then show False\n              using a3 \n              by (metis \\<open>(lval_of \\<circ> the) (\\<tau>' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig) ! b = bs ! b\\<close> \\<open>\\<not> (case the (to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig))) of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)\\<close> a2 val.simps(6))\n          qed\n          done }\n      ultimately have \"\\<sigma> sig \\<noteq> the (to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)))\"\n        by auto\n      thus \"keys (to_trans_raw_sig \\<tau>'' sig) \\<noteq> {} \\<longrightarrow> \\<sigma> sig \\<noteq> the (to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)))\"\n        by auto\n    qed }\n  moreover\n  { assume \"\\<not> post_necessary_raw (dly - 1) \\<tau>' t sig (Lv sign bs) (\\<sigma> sig)\"\n    hence 0: \"\\<tau>'' = preempt_raw sig \\<tau>' (t + dly)\"\n      unfolding \\<tau>''_def trans_post_raw_def by auto\n    have ?thesis\n      unfolding non_stuttering_def\n    proof (rule, rule, rule, rule)\n      fix k1 k2\n      assume \"k1 < k2 \\<and> k1 \\<in> keys (to_trans_raw_sig \\<tau>'' sig) \\<and> k2 \\<in> keys (to_trans_raw_sig \\<tau>'' sig) \\<and> (\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig \\<tau>'' sig))\"\n      hence \"k1 < k2\" and \"k1 \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\" and \"k2 \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\" and \n        2: \"(\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig \\<tau>'' sig))\" by auto\n      have \"k2 \\<le> t + dly\"\n      proof (rule ccontr)\n        assume \"\\<not> k2 \\<le> t + dly\" hence \"t + dly < k2\" by auto\n        hence \"\\<tau>'' k2 sig = None\"\n          using `\\<tau>'' = preempt_raw sig  \\<tau>' (t + dly)` unfolding preempt_raw_def by auto\n        with `k2 \\<in> keys (to_trans_raw_sig \\<tau>'' sig)` show False \n          unfolding to_trans_raw_sig_def keys_def zero_option_def by auto\n      qed\n      have \"k1 \\<in> keys (to_trans_raw_sig \\<tau>' sig)\"\n        using `k1 \\<in> keys (to_trans_raw_sig \\<tau>'' sig)` unfolding 0 preempt_raw_def to_trans_raw_sig_def keys_def zero_option_def\n        using \\<open>k1 < k2\\<close> \\<open>k2 \\<le> t + dly\\<close> by auto\n      have 3: \"(\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig \\<tau>' sig))\"\n        using `k2 \\<le> t + dly` 0 2 `k1 < k2` unfolding preempt_raw_def \n        by (metis domIff dom_def dual_order.asym keys_def less_le_trans to_trans_raw_sig_def zero_option_def)\n      have \"k2 < t \\<or> k2 \\<ge> t\"\n        by auto\n      moreover\n      { assume \"k2 < t\"\n        hence \"\\<tau>'' k2 sig = \\<tau>' k2 sig\"\n          using 0 unfolding preempt_raw_def by auto\n        also have \"... = \\<tau> k2 sig\"\n          using 1 `k2 < t` unfolding combine_trans_bit_def Let_def by auto\n        finally have \"\\<tau>'' k2 sig = \\<tau> k2 sig\"\n          by auto\n        hence \"False\"\n          by (metis (full_types) \\<open>k1 < k2 \\<and> k1 \\<in> keys (to_trans_raw_sig \\<tau>'' sig) \\<and> k2 \\<in> keys\n          (to_trans_raw_sig \\<tau>'' sig) \\<and> (\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig \\<tau>'' sig))\\<close>\n          \\<open>k2 < t\\<close> assms(4) domIff dom_def keys_def less_imp_le_nat to_trans_raw_sig_def\n          zero_fun_def zero_option_def)\n        hence \"to_trans_raw_sig \\<tau>'' sig k1 \\<noteq> to_trans_raw_sig \\<tau>'' sig k2\"\n          by auto }\n      moreover\n      { assume \"k2 \\<ge> t\"\n        have \"dly = 0 \\<or> dly \\<noteq> 0\"\n          by auto\n        moreover\n        { assume \"dly = 0\"\n          hence \"k2 = t\" \n            using \\<open>k2 \\<le> t + dly\\<close> \\<open>t \\<le> k2\\<close> by linarith\n          have \"k1 < t\"\n            using `k1 < k2` `k2 = t` by auto\n          hence \"\\<tau>''  k1 sig = \\<tau>' k1 sig\"\n            using 0 unfolding preempt_raw_def by auto\n          also have \"... = \\<tau> k1 sig\"\n            using `k1 < t` unfolding 1 combine_trans_bit_def Let_def by auto\n          also have \"... = 0\"\n            using `k1 < t` assms(4) by (auto simp add: zero_fun_def zero_option_def)\n          finally have \"\\<tau>'' k1 sig = 0\"\n            by auto\n          hence \"k1 \\<notin> keys (to_trans_raw_sig \\<tau>'' sig)\"\n            unfolding to_trans_raw_sig_def keys_def by auto\n          with `k1 \\<in> keys (to_trans_raw_sig \\<tau>'' sig)` have False\n            by auto\n          hence \"to_trans_raw_sig \\<tau>'' sig k1 \\<noteq> to_trans_raw_sig \\<tau>'' sig k2\"\n            by auto }\n        moreover\n        { assume \"dly \\<noteq> 0\"\n          have \"k2 = t + dly \\<or> k2 < t + dly\"\n            using `k2 \\<le> t + dly` by auto\n          moreover\n          { assume \"k2 = t + dly\"\n            hence \"\\<tau>'' k2 sig = None\"\n              unfolding 0 preempt_raw_def by auto\n            hence False \n              using `k2 \\<in> keys (to_trans_raw_sig \\<tau>'' sig)` unfolding keys_def to_trans_raw_sig_def\n              by (simp add: zero_option_def)\n            hence \"to_trans_raw_sig \\<tau>'' sig k1 \\<noteq> to_trans_raw_sig \\<tau>'' sig k2\"\n              by auto }\n          moreover\n          { assume \"k2 < t + dly\"\n            hence \"\\<tau>'' k2 sig = \\<tau>' k2 sig\"\n              using 0 unfolding preempt_raw_def by auto\n            have \"t < k2\"\n            proof (rule ccontr)\n              assume \"\\<not> t < k2\" hence \"k2 \\<le> t\" by auto\n              hence \"\\<tau>' k2 sig = \\<tau> k2 sig\"\n                unfolding 1 combine_trans_bit_def by auto\n              also have \"... = 0\"\n                using assms  by (simp add: \\<open>k2 \\<le> t\\<close> zero_fun_def)\n              finally have \"\\<tau>'' k2 sig = 0\"\n                by (simp add: \\<open>\\<tau>'' k2 sig = \\<tau>' k2 sig\\<close>)\n              with `k2 \\<in> keys (to_trans_raw_sig \\<tau>'' sig)` show False\n                by (simp add: keys_def to_trans_raw_sig_def)\n            qed\n            hence \"k2 \\<in> keys (to_trans_raw_sig \\<tau>' sig)\"\n              using `k2 \\<in> keys (to_trans_raw_sig \\<tau>'' sig)` \n              by (simp add: \\<open>\\<tau>'' k2 sig = \\<tau>' k2 sig\\<close> keys_def to_trans_raw_sig_def)\n            hence \"\\<tau>' k2 sig \\<noteq> None\"\n              by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n            hence k2inset: \"k2 \\<in> fold (\\<union>)\n            (map (keys \\<circ> (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> snd)\n              (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])))\n            {}\"\n              using `t < k2` `k2 < t + dly` unfolding 1 combine_trans_bit_def Let_def \n              by (meson dual_order.asym leD)\n            hence \"\\<tau>' k2 sig = Some\n                (Lv sign\n                  (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig k2))\n                    (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs])\n                      (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))))\"\n              unfolding 1 combine_trans_bit_def Let_def  using \\<open>k2 < t + dly\\<close> \\<open>t < k2\\<close> by auto\n            hence 4: \"(lval_of o the) (\\<tau>' k2 sig) =  (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig k2))\n                    (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs])\n                      (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])))\"\n              by auto\n            have 5: \"\\<And>b. b \\<in> set [0..< length bs] \\<Longrightarrow> (lval_of o the) (\\<tau>' k2 sig) ! b = \n                      bval_of (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) \n                              (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig k2)\"\n            proof -\n              fix b\n              assume \"b \\<in> set [0 ..< length bs]\"\n              have \"(lval_of o the) (\\<tau>' k2 sig) ! b = (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig k2))\n                    (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs])\n                      (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))) ! b\" (is \"_ = ?complex\")\n                using 4 by auto\n              have *: \"b < length (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs])\n                      (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))\"\n                using `b \\<in> set [0 ..< length bs]` by auto\n              have **: \"?complex = bval_of\n     (signal_of\n       (fst (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs]) \n                 (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]) ! b))\n       (snd (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs]) \n                 (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]) ! b))\n       sig k2)\"\n                unfolding  nth_map[OF *] by auto \n              moreover have \"[0 ..< length bs] ! b = b\"\n                using `b \\<in> set [0 ..< length bs]` by auto\n              ultimately have \"?complex = bval_of \n                (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig k2)\"\n                using \\<open>b \\<in> set [0..<length bs]\\<close> unfolding ** \n                by (simp add: nth_map val.case_eq_if)\n              thus \"(lval_of o the) (\\<tau>' k2 sig) ! b = \n                      bval_of (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) \n                              (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig k2)\"\n                using 4 by auto\n            qed\n            have helper: \"\\<And>f. length (map f [0..<length bs]) \\<le> length bs - 0\"\n              by auto\n            have  \"k2 \\<in> fold (\\<union>) (map keys\n                   (map (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig)\n                     (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n)))\n                       [0..<length bs]))) {}\"\n              using k2inset unfolding map_map[THEN sym] map_snd_zip_take  length_map min.idem length_upt\n              take_all[OF helper] by auto\n            hence helper2:\" k2 \\<in> fold (\\<union>)\n               (map (\\<lambda>x. keys\n                      (to_trans_raw_sig\n                        (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> x sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! x)) (Bv (bs ! x))) sig))\n             [0..<length bs]) {}\" \n              unfolding map_map comp_def  by auto                   \n            obtain b2 where \"b2 \\<in> set [0..< length bs]\" and \"k2 \\<in> keys (to_trans_raw_sig\n                            (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2))) sig)\"\n              using member_fold_union[OF helper2] by auto\n            hence purge_neq: \"purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2)) k2 sig \\<noteq> 0\"\n              unfolding keys_def to_trans_raw_sig_def by auto\n            have the_time: \"Some k2 = inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig)) sig (t + dly)\" and \n              sig_neq: \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) sig t \\<noteq> Bv (bs ! b2)\" and \n              sig_eq: \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) sig (t + dly) = Bv (bs ! b2)\"\n              using `t < k2` `k2 < t + dly` purge_raw_neq_0_imp[OF purge_neq `t < k2` `k2 < t + dly`] \n              by auto\n            moreover hence \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig k2 sig = Some (Bv (bs ! b2))\"\n              unfolding to_signal_def comp_def to_trans_raw_sig_def \n              by (smt inf_time_some_exists keys_def mem_Collect_eq not_None_eq option.sel\n              option.simps(5) zero_option_def)\n            ultimately have \"purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2)) k2 sig = Some (Bv (bs ! b2))\"\n              using `t < k2` `k2 < t + dly` unfolding purge_raw_def Let_def \n              by (smt \"3\" UnE \\<open>k1 < k2\\<close> \\<open>k2 \\<in> keys (to_trans_raw_sig \\<tau>' sig)\\<close> greaterThanAtMost_iff greaterThanLessThan_iff option.sel override_on_apply_notin)\n            hence \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2))) sig k2 = Bv (bs ! b2)\"\n              using trans_some_signal_of'  by (metis o_apply option.sel )\n            hence \"(lval_of o the) (\\<tau>' k2 sig) ! b2 = bs ! b2\"\n              using 5[OF `b2 \\<in> set [0..< length bs]`] by auto\n\n            have \"k1 < t + dly\"\n              using `k1 < k2` `k2 < t + dly` by auto\n            have \"t < k1\"\n            proof (rule ccontr)\n              assume \"\\<not> t < k1\" hence \"k1 \\<le> t\" by auto\n              hence \"\\<tau>' k1 sig = \\<tau> k1 sig\"\n                unfolding 1 combine_trans_bit_def by auto\n              also have \"... = 0\"\n                using assms  by (simp add: \\<open>k1 \\<le> t\\<close> zero_fun_def)\n              finally have \"\\<tau>' k1 sig = 0\"\n                by (simp)\n              with `k1 \\<in> keys (to_trans_raw_sig \\<tau>' sig)` show False\n                by (simp add: keys_def to_trans_raw_sig_def)\n            qed\n            have \"\\<tau>' k1 sig \\<noteq> None\"\n              using `k1 \\<in> keys (to_trans_raw_sig \\<tau>' sig)` \n              by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n            hence k1inset: \"k1 \\<in> fold (\\<union>)\n            (map (keys \\<circ> (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> snd)\n              (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs])\n                (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])))\n            {}\"\n              using `t < k1` `k1 < t + dly` unfolding 1 combine_trans_bit_def Let_def \n              by (meson dual_order.asym leD)\n            have  \"k1 \\<in> fold (\\<union>) (map keys\n                   (map (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig)\n                     (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n)))\n                       [0..<length bs]))) {}\"\n              using k1inset unfolding map_map[THEN sym] map_snd_zip_take  length_map min.idem length_upt\n              take_all[OF helper] by auto\n            hence k1inset':\" k1 \\<in> fold (\\<union>)\n               (map (\\<lambda>x. keys\n                      (to_trans_raw_sig\n                        (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> x sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! x)) (Bv (bs ! x))) sig))\n             [0..<length bs]) {}\" \n              unfolding map_map comp_def  by auto     \n            obtain b1 where \"b1 \\<in> set [0..< length bs]\" and \"k1 \\<in> keys (to_trans_raw_sig\n                            (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b1 sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b1)) (Bv (bs ! b1))) sig)\"\n              using member_fold_union[OF k1inset'] by auto \n            hence purge_neq: \"purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b1 sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b1)) (Bv (bs ! b1)) k1 sig \\<noteq> 0\"\n              unfolding keys_def to_trans_raw_sig_def by auto\n            have \"Some k1 = inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b1 sig)) sig (t + dly)\" and \n              \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b1)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b1 sig) sig t \\<noteq> Bv (bs ! b1)\" and \n              \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b1)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b1 sig) sig (t + dly) = Bv (bs ! b1)\"\n              using `t < k1` `k1 < t + dly` purge_raw_neq_0_imp[OF purge_neq `t < k1` `k1 < t + dly`] \n              by auto\n            have \"Some k1 = inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b1 sig)) sig (t + dly)\" and \n              \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b1)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b1 sig) sig t \\<noteq> Bv (bs ! b1)\" and \n              \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b1)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b1 sig) sig (t + dly) = Bv (bs ! b1)\"\n              using `t < k1` `k1 < t + dly` purge_raw_neq_0_imp[OF purge_neq `t < k1` `k1 < t + dly`] \n              by auto\n            hence \"\\<tau>' k1 sig = Some\n                (Lv sign\n                  (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig k1))\n                    (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs])\n                      (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))))\"\n              unfolding 1 combine_trans_bit_def Let_def  using \\<open>k1 < t + dly\\<close> \\<open>t < k1\\<close> k1inset by auto\n            hence 5: \"(lval_of o the) (\\<tau>' k1 sig) =  (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig k1))\n                    (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs])\n                      (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])))\"\n              by auto\n            have 6: \"\\<And>b. b \\<in> set [0..< length bs] \\<Longrightarrow> (lval_of o the) (\\<tau>' k1 sig) ! b = \n                      bval_of (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig k1)\"\n            proof -\n              fix b\n              assume \"b \\<in> set [0 ..< length bs]\"\n              have \"(lval_of o the) (\\<tau>' k1 sig) ! b = (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig k1))\n                    (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs])\n                      (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))) ! b\" (is \"_ = ?complex\")\n                using 5 by auto\n              have *: \"b < length (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs])\n                      (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))\"\n                using `b \\<in> set [0 ..< length bs]` by auto\n              have **: \"?complex = bval_of\n     (signal_of\n       (fst (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs]) \n                 (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]) ! b))\n       (snd (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs]) \n                 (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]) ! b))\n       sig k1)\"\n                unfolding  nth_map[OF *] by auto \n              moreover have \"[0 ..< length bs] ! b = b\"\n                using `b \\<in> set [0 ..< length bs]` by auto\n              ultimately have \"?complex = bval_of \n                (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig k1)\"\n                using \\<open>b \\<in> set [0..<length bs]\\<close> unfolding **  by (simp add: val.case_eq_if)\n              thus \"(lval_of o the) (\\<tau>' k1 sig) ! b = \n                      bval_of (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig k1)\"\n                using 5 by auto\n            qed\n          \n            have \"purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2)) k1 sig = None\"\n              using `t < k1` `k1 < k2` sig_neq sig_eq the_time unfolding purge_raw_def Let_def\n              by (smt Un_iff fun_upd_eqD fun_upd_triv greaterThanLessThan_iff option.sel override_on_apply_in)\n            have 7: \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2))) sig k1 = \n                  signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2))) sig t\"\n            proof (intro signal_of_less_ind')\n              fix n\n              assume \"t < n\" and \"n \\<le> k1\"\n              thus \" purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2)) n sig = 0\"\n                using `k1 < k2` sig_neq sig_eq the_time unfolding purge_raw_def Let_def\n                apply (auto simp add: override_on_def to_trans_raw_bit_def zero_option_def zero_fun_def split: option.splits val.splits intro!: ext)\n                apply (metis linorder_neqE_nat not_le option.sel)\n                using \\<open>k1 < t + dly\\<close> apply linarith\n                apply (metis le_less_trans option.sel)\n                using \\<open>k1 < t + dly\\<close> by linarith\n            next\n              show \"t \\<le> k1\"\n                using `t < k1` by auto\n            qed \n            also have \"... = signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) sig t \"\n            proof (rule signal_of_equal_when_trans_equal_upto)\n              fix n \n              assume \"n \\<le> t\"\n              thus \"purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2)) n = to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig n\"\n                unfolding purge_raw_def Let_def override_on_def \n                by (smt Un_iff \\<open>t \\<le> k2\\<close> greaterThanAtMost_iff greaterThanLessThan_iff leD less_le_trans option.sel the_time)\n            qed (auto)\n            also have \"... \\<noteq> Bv (bs ! b2)\"\n              using sig_neq by auto\n            finally have \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2)) (Bv (bs ! b2))) sig k1 \\<noteq> Bv (bs ! b2)\"\n              by auto\n            moreover have \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) sig t  = (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2))\"\n              apply (rule signal_of_def)\n              using assms(4)\n              unfolding to_trans_raw_bit_def by (simp add: zero_fun_def zero_option_def)\n            ultimately have \"(lval_of o the) (\\<tau>' k1 sig) ! b2 \\<noteq> bs ! b2\"\n              using 6[OF `b2 \\<in> set [0 ..< length bs]`] \n              using \"7\" \n              using \\<open>signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b2)) (purge_raw\n              (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs\n              ! b2)) (Bv (bs ! b2))) sig t = signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow>\n              bs ! b2)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b2 sig) sig t\\<close> by auto\n            with `(lval_of o the) (\\<tau>' k2 sig) ! b2 = bs ! b2` have \"\\<tau>' k1 sig \\<noteq> \\<tau>' k2 sig\"\n              by auto\n            moreover have \"\\<tau>'' k1 sig = \\<tau>' k1 sig\"\n              using 0 `t < k1` `k1 < t + dly` unfolding preempt_raw_def by auto\n            ultimately have \"to_trans_raw_sig \\<tau>'' sig k1 \\<noteq> to_trans_raw_sig \\<tau>'' sig k2\"\n              using `\\<tau>'' k2 sig = \\<tau>' k2 sig`  unfolding to_trans_raw_sig_def by auto }\n          ultimately have \"to_trans_raw_sig \\<tau>'' sig k1 \\<noteq> to_trans_raw_sig \\<tau>'' sig k2\"\n            by auto }\n        ultimately have \"to_trans_raw_sig \\<tau>'' sig k1 \\<noteq> to_trans_raw_sig \\<tau>'' sig k2\"\n          by auto }\n      ultimately show \"to_trans_raw_sig \\<tau>'' sig k1 \\<noteq> to_trans_raw_sig \\<tau>'' sig k2\"\n        by auto \n    next  \n      { assume \"keys (to_trans_raw_sig \\<tau>'' sig) \\<noteq> {}\"\n        have lt: \"(LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) < t + dly\"\n        proof (rule ccontr)\n          assume \"\\<not> (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) < t + dly\"\n          hence atmost: \"t + dly \\<le> (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig))\"\n            by auto\n          have \"(LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\"\n            using `keys (to_trans_raw_sig \\<tau>'' sig) \\<noteq> {}`  by (meson LeastI all_not_in_conv)\n          hence \"to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) \\<noteq> 0\"\n            unfolding keys_def by auto\n          moreover have \"to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) = 0\"\n            using atmost unfolding 0 to_trans_raw_sig_def preempt_raw_def by (auto simp add: zero_option_def)\n          ultimately show False\n            by auto\n        qed\n        have \"(LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\"\n          using `keys (to_trans_raw_sig \\<tau>'' sig) \\<noteq> {}`  by (meson LeastI all_not_in_conv)      \n        hence \"to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) \\<noteq> 0\"\n          unfolding keys_def by auto\n        with lt have \"\\<tau>' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig \\<noteq> 0\"\n          unfolding 0 preempt_raw_def to_trans_raw_sig_def by auto\n        have \"t < (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig))\"\n        proof (rule ccontr)\n          assume \"\\<not> t < (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig))\"\n          hence \" (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) \\<le> t\"\n            by auto\n          hence \"\\<tau>' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig = 0\"\n            using assms(4)\n            unfolding 1  combine_trans_bit_def Let_def by (auto simp add :zero_fun_def)\n          with `\\<tau>' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig \\<noteq> 0`\n          show False\n            unfolding to_trans_raw_sig_def by auto\n        qed\n        hence \"\\<tau>'' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig = \\<tau>' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig\"\n          using lt unfolding 0 preempt_raw_def by auto\n        let ?t = \"LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)\"\n        have **: \"?t \\<in> fold (\\<union>)\n          (map (keys \\<circ> (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> snd)\n            (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs]) \n                 (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))) {}\"\n          using `\\<tau>' ?t sig \\<noteq> 0` `t < ?t` `?t < t + dly` unfolding 1 combine_trans_bit_def\n          using not_le zero_option_def by force\n        hence \"?t \\<in> fold (\\<union>) (map keys (map (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))) {}\"\n          unfolding map_map[THEN sym] map_snd_zip_take length_map min.idem length_upt\n          using take_all by auto\n        hence *: \"?t  \\<in> fold (\\<union>) (map (keys \\<circ> ((\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))))) [0..<length bs]) {}\"\n          unfolding map_map by auto\n        have \"(\\<exists>x\\<in>set (map (keys \\<circ> ((\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))))) [0..<length bs]).\n                      ?t \\<in> x)\"\n          using member_fold_union[OF *] unfolding empty_iff by auto\n        then obtain b where \"?t \\<in> keys (((\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n)))) b)\" and \n          \"b \\<in> set [0..< length bs]\" by auto\n        hence \"?t \\<in>  keys (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)) n sig)\"\n          unfolding comp_def to_trans_raw_sig_def by auto\n        hence \"purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)) ?t sig \\<noteq> 0\"\n          unfolding keys_def by auto\n        from purge_raw_neq_0_imp[OF this `t < ?t` `?t < t + dly`]\n        have inf_time: \" inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly) = Some ?t\"\n          and sig_neq: \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig t \\<noteq> Bv (bs ! b) \"\n          and sig_eq: \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig (t + dly) = Bv (bs ! b)\" \n          by auto\n        hence \"purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)) ?t sig = \n               to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig ?t sig\"\n          using `t < ?t` `?t < t + dly` unfolding purge_raw_def Let_def by auto\n        also have \"... = Some (Bv (bs ! b))\"\n          using sig_eq inf_time unfolding to_signal_def comp_def \n          by (metis (mono_tags, lifting) \\<open>purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) t dly sig (Bv (case \\<sigma>\n          sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)) (LEAST k. k \\<in> keys\n          (to_trans_raw_sig \\<tau>'' sig)) sig \\<noteq> 0\\<close> calculation option.collapse option.simps(5)\n          to_trans_raw_sig_def zero_option_def)\n        finally have ***: \"purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)) ?t sig = Some (Bv (bs ! b))\"\n          by auto\n        have \"\\<tau>' ?t sig = Some\n            (Lv sign\n              (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig ?t))\n                (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs])\n                  (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))))\"\n          using ** unfolding 1 combine_trans_bit_def Let_def  using \\<open>?t < t + dly\\<close> \\<open>t < ?t\\<close> by auto\n        hence 4: \"(lval_of o the) (\\<tau>' ?t sig) =  (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig ?t))\n                (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs])\n                  (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])))\"\n          by auto        \n        have 5: \"\\<And>b. b \\<in> set [0..< length bs] \\<Longrightarrow> (lval_of o the) (\\<tau>' ?t sig) ! b = \n                  bval_of (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig ?t)\"\n        proof -\n          fix b\n          assume \"b \\<in> set [0 ..< length bs]\"\n          have \"(lval_of o the) (\\<tau>' ?t sig) ! b = (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig ?t))\n                (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs])\n                  (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))) ! b\" (is \"_ = ?complex\")\n            using 4 by auto\n          have *: \"b < length (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs])\n                  (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))\"\n            using `b \\<in> set [0 ..< length bs]` by auto\n          have **: \"?complex = bval_of\n  (signal_of\n   (fst (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs]) \n             (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]) ! b))\n   (snd (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs]) \n             (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]) ! b))\n   sig ?t)\"\n            unfolding  nth_map[OF *] by auto \n          moreover have \"[0 ..< length bs] ! b = b\"\n            using `b \\<in> set [0 ..< length bs]` by auto\n          ultimately have \"?complex = bval_of \n            (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig ?t)\"\n            using \\<open>b \\<in> set [0..<length bs]\\<close> unfolding **  by (simp add: val.case_eq_if)\n          thus \" (lval_of o the) (\\<tau>' ?t sig) ! b = bval_of (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig ?t)\"\n            using 4 by auto\n        qed\n        hence h: \"(lval_of o the) (\\<tau>' ?t sig) ! b = \n          bval_of (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig ?t)\"\n          using `b \\<in> set [0..< length bs]` by auto\n        have \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig ?t = Bv (bs ! b)\"\n        proof (rule signal_of_intro, rule, rule)\n          show \"?t \\<le> ?t\" by auto\n        next\n          have \"to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) = Some (Bv (bs ! b))\"\n            using ***  unfolding to_trans_raw_sig_def by auto\n          moreover have \"(\\<forall>j>LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig).\n        j \\<le> (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) \\<longrightarrow> to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) t dly sig (Bv (lval_of (\\<sigma> sig) ! b)) (Bv (bs ! b))) sig j = None)\"\n            by auto\n          ultimately show \" to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig\n     (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) =\n    Some (Bv (bs ! b)) \\<and>\n    (\\<forall>j>LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig).\n        j \\<le> (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) \\<longrightarrow>\n        to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig j = None) \\<or>\n    (\\<forall>i\\<le>LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig). purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)) i sig = None) \\<and>\n    Bv (bs ! b) = Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)\"\n            by auto\n        qed\n        hence \"bval_of (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b))(Bv (bs ! b))) sig ?t) = bs ! b\"\n          by auto\n        hence \"(lval_of o the) (\\<tau>' ?t sig) ! b = bs ! b\"\n          using h by auto\n        have \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig t = (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b))\"\n          apply (intro signal_of_def)\n          using assms(4) unfolding to_trans_raw_bit_def  by (simp add: zero_fun_def zero_option_def)\n        hence \"(case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b) \\<noteq> bs ! b\"\n          using sig_neq by auto\n        hence \"\\<sigma> sig \\<noteq> the (to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)))\"\n        proof -\n          { assume \"Lv sign ((lval_of \\<circ> the) (\\<tau>'' (LEAST n. n \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig)) \\<noteq> the (\\<tau>'' (LEAST n. n \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig)\"\n            moreover\n            { assume \"map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig (LEAST n. n \\<in> keys (to_trans_raw_sig \\<tau>'' sig)))) (zip (map (\\<lambda>n. Bv (case the (to_trans_raw_sig \\<tau>'' sig (LEAST n. n \\<in> keys (to_trans_raw_sig \\<tau>'' sig))) of Bv b \\<Rightarrow> b | Lv s bs \\<Rightarrow> bs ! n)) [0..<length bs]) (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv s bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])) \\<noteq> (lval_of \\<circ> the) (\\<tau>'' (LEAST n. n \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig)\"\n              then have ?thesis\n                by (metis \"4\" \\<open>\\<tau>'' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig = \\<tau>' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig\\<close>) (* > 1.0 s, timed out *) }\n            ultimately have ?thesis\n              by (simp add: \\<open>\\<tau>' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig = Some (Lv sign (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)))) (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs]) (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig)  \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))))\\<close> \\<open>\\<tau>'' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig = \\<tau>' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig\\<close>) }\n          then show ?thesis\n            by (metis \\<open>(case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b) \\<noteq> bs ! b\\<close> \\<open>(lval_of \\<circ> the) (\\<tau>' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig) ! b = bs ! b\\<close> \\<open>\\<tau>'' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig = \\<tau>' (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)) sig\\<close> to_trans_raw_sig_def val.simps(6))\n        qed }\n      thus \"keys (to_trans_raw_sig \\<tau>'' sig) \\<noteq> {} \\<longrightarrow> \\<sigma> sig \\<noteq> the (to_trans_raw_sig \\<tau>'' sig (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>'' sig)))\"\n        by auto\n    qed }\n  ultimately show ?thesis\n    by auto\nqed\n\nlemma purge'_trans_post_preserve_non_stuttering:\n  fixes \\<tau> sig t dly cur_val\n  assumes \"non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma> sig\"\n  defines \"\\<tau>'  \\<equiv> purge_raw' \\<tau> t dly sig (\\<sigma> sig) cur_val\"\n  defines \"\\<tau>'' \\<equiv> trans_post_raw sig cur_val (\\<sigma> sig) \\<tau>' t dly\"\n  assumes \"\\<forall>n. n \\<le> t \\<longrightarrow>  \\<tau> n = 0\"\n  shows \"non_stuttering (to_trans_raw_sig \\<tau>'') \\<sigma> sig\"\n  using purge'_trans_post_preserve_non_stuttering_bv purge'_trans_post_preserve_non_stuttering_lv\n  by (metis \\<tau>''_def \\<tau>'_def assms(1) assms(4) val.exhaust)\n    \nlemma post_raw_preserves_non_stuttering:\n  fixes dly t val\n  assumes \"non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma> sig\"\n  defines \"\\<tau>' \\<equiv> post_raw sig val \\<tau> (t + dly)\"\n  assumes \"post_necessary_raw (dly-1) \\<tau> t sig val (\\<sigma> sig)\"\n  assumes \"\\<forall>n \\<le> t. \\<tau> n = 0\"\n  assumes \"0 < dly\"\n  shows   \"non_stuttering (to_trans_raw_sig \\<tau>') \\<sigma> sig\"\nproof -\n  have cases: \"(\\<exists>i val'. i \\<le> t + (dly - 1) \\<and> \\<tau> i sig = Some val' \\<and> val' \\<noteq> val \\<and> (\\<forall>j>i. j \\<le> t + (dly - 1) \\<longrightarrow> \\<tau> j sig = None)) \\<or>\n               (\\<forall>i\\<le>t + (dly - 1). \\<tau> i sig = None) \\<and> val \\<noteq> \\<sigma> sig\"\n    using assms(3) unfolding post_necessary_raw_correctness2 by auto\n  { fix k1 k2\n    assume \"k1 \\<in> keys (to_trans_raw_sig \\<tau>' sig)\" and \"k2 \\<in> keys (to_trans_raw_sig \\<tau>' sig)\"\n    assume \"k1 < k2\"\n    assume \"\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig \\<tau>' sig)\"\n    have \"k2 \\<le> t + dly\"\n      using `k2 \\<in> keys (to_trans_raw_sig \\<tau>' sig)` unfolding \\<tau>'_def post_raw_def to_trans_raw_sig_def\n    proof -\n      assume \"k2 \\<in> keys (\\<lambda>n. (if n = t + dly then \\<tau> n(sig \\<mapsto> val) else if t + dly < n then (\\<tau> n)(sig := None) else \\<tau> n) sig)\"\n      then have \"k2 \\<in> {n. (if n = t + dly then \\<tau> n(sig \\<mapsto> val) else if t + dly < n then (\\<tau> n)(sig := None) else \\<tau> n) sig \\<noteq> 0}\"\n        by (simp add: keys_def)\n      then show ?thesis\n        using leI zero_option_def by fastforce\n    qed\n    hence \"k2 = t + dly \\<or> k2 < t + dly\"\n      by auto\n    moreover\n    { assume \"k2 = t + dly\"\n      hence \"to_trans_raw_sig \\<tau>' sig k2 = Some val\"\n        unfolding \\<tau>'_def post_raw_def to_trans_raw_sig_def by auto\n      consider (case1) \"(\\<exists>i val'. i \\<le> t + (dly - 1) \\<and> \\<tau> i sig = Some val' \\<and> val' \\<noteq> val \\<and> (\\<forall>j>i. j \\<le> t + (dly - 1) \\<longrightarrow> \\<tau> j sig = None))\"\n             | (case2) \"(\\<forall>i\\<ge>t. i \\<le> t + (dly - 1) \\<longrightarrow> \\<tau> i sig = None) \\<and> val \\<noteq> \\<sigma> sig\"\n        using cases by auto\n      hence \"to_trans_raw_sig \\<tau>' sig k1 \\<noteq> to_trans_raw_sig \\<tau>' sig k2\"\n      proof (cases)\n        case case1\n        then obtain i val' where \"i\\<ge>t\" and \"i \\<le> t + (dly-1)\" and \"\\<tau> i sig = Some val'\" and \"val' \\<noteq> val\"\n          \"\\<forall>j>i. j \\<le> t + (dly - 1) \\<longrightarrow> \\<tau> j sig = None\"\n          by (metis assms(4) nat_le_linear option.distinct(1) zero_fun_def zero_option_def)\n        have \"k1 < t + dly\"\n          using `k1 < k2` `k2 \\<le> t + dly` by auto\n        have \"k1 \\<in> keys (to_trans_raw_sig \\<tau> sig)\"\n          using `k1 \\<in> keys (to_trans_raw_sig \\<tau>' sig)` unfolding \\<tau>'_def to_trans_raw_sig_def post_raw_def\n        proof -\n          assume a1: \"k1 \\<in> Femto_VHDL_raw.keys (\\<lambda>n. (if n = t + dly then \\<tau> n(sig \\<mapsto> val) else if t + dly < n then (\\<tau> n)(sig := None) else \\<tau> n) sig)\"\n          have \"\\<not> t + dly \\<le> k1\"\n            by (meson \\<open>k1 < t + dly\\<close> not_le)\n          then show \"k1 \\<in> Femto_VHDL_raw.keys (\\<lambda>n. \\<tau> n sig)\"\n            using a1 by (simp add: keys_def)\n        qed\n        have *: \"\\<forall>j>k1. j < t + dly \\<longrightarrow> \\<tau> j sig = None\"\n          using `\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig \\<tau>' sig)` unfolding `k2 = t + dly`\n          \\<tau>'_def post_raw_def to_trans_raw_sig_def  by (simp add: keys_def zero_option_def)\n        have \"i = k1\"\n        proof (rule ccontr)\n          assume \"\\<not> i = k1\" hence \"i < k1 \\<or> k1 < i\" by auto\n          moreover\n          { assume \"i < k1\"\n            hence \"\\<exists>j>i. j \\<le> t + (dly-1) \\<and> \\<tau> j sig \\<noteq> None\"\n              using `k1 < k2` `k2 = t + dly` `k1 \\<in> keys (to_trans_raw_sig \\<tau> sig)`\n              apply(intro exI[where x=\"k1\"])\n              unfolding to_trans_raw_sig_def keys_def\n              by (smt Suc_diff_1 \\<open>t \\<le> i\\<close> add_Suc_right dual_order.order_iff_strict less_Suc_eq_le\n              less_add_same_cancel1 less_trans mem_Collect_eq zero_option_def)\n            with `\\<forall>j>i. j \\<le> t + (dly - 1) \\<longrightarrow> \\<tau> j sig = None` have \"False\" by auto }\n          moreover\n          { assume \"k1 < i\"\n            hence \"\\<exists>j>k1. j < t + dly \\<and> \\<tau> j sig \\<noteq> None\"\n              using `i \\<le> t + (dly-1)` `\\<tau> i sig = Some val'`\n              by (intro exI[where x=\"i\"])(metis (no_types, hide_lams) One_nat_def Suc_diff_1\n              add.right_neutral add_Suc_right assms(4) diff_is_0_eq' less_Suc_eq_le nat_le_linear\n              not_le option.distinct(1) zero_fun_def zero_option_def)\n            with * have False by auto }\n          ultimately show False by auto\n        qed\n        thus \"to_trans_raw_sig \\<tau>' sig k1 \\<noteq> to_trans_raw_sig \\<tau>' sig k2\"\n          using `i = k1` `\\<tau> i sig = Some val'` `to_trans_raw_sig \\<tau>' sig k2 = Some val`\n          by (metis \\<open>k1 < k2\\<close> \\<open>k2 = t + dly\\<close> \\<open>val' \\<noteq> val\\<close> \\<tau>'_def add_less_same_cancel1\n          less_imp_add_positive not_less_zero option.sel post_raw_def to_trans_raw_sig_def)\n      next\n        case case2\n        have \"k1 < t + dly\"\n          using `k1 < k2` `k2 \\<le> t + dly` by auto\n        moreover have \"k1 \\<in> keys (to_trans_raw_sig \\<tau> sig)\"\n          using `k1 \\<in> keys (to_trans_raw_sig \\<tau>' sig)` unfolding \\<tau>'_def to_trans_raw_sig_def post_raw_def\n        proof -\n          assume a1: \"k1 \\<in> Femto_VHDL_raw.keys (\\<lambda>n. (if n = t + dly then \\<tau> n(sig \\<mapsto> val) else if t + dly < n then (\\<tau> n)(sig := None) else \\<tau> n) sig)\"\n          have \"\\<not> t + dly \\<le> k1\"\n            by (meson \\<open>k1 < t + dly\\<close> not_le)\n          then show \"k1 \\<in> Femto_VHDL_raw.keys (\\<lambda>n. \\<tau> n sig)\"\n            using a1 by (simp add: keys_def)\n        qed\n        moreover hence \"t < k1\"\n          using assms(4)\n          by (metis domIff dom_def keys_def leI to_trans_raw_sig_def zero_fun_def zero_option_def)\n        ultimately have \"\\<exists>i\\<ge>t. i \\<le> t + (dly - 1) \\<and> \\<tau> i sig \\<noteq> None\"\n          apply (intro exI[where x=\"k1\"])\n          unfolding to_trans_raw_sig_def keys_def by (simp add: zero_option_def)\n        with case2 have \"False\" by auto\n        then show ?thesis by auto\n      qed }\n    moreover\n    { assume \"k2 < t + dly\"\n      hence \"k2 \\<in> keys (to_trans_raw_sig \\<tau> sig)\"\n        using `k2 \\<in> keys (to_trans_raw_sig \\<tau>' sig)` unfolding \\<tau>'_def post_raw_def to_trans_raw_sig_def\n        by (simp add: keys_def)\n      moreover have \"k1 \\<in> keys (to_trans_raw_sig \\<tau> sig)\"\n        using `k1 \\<in> keys (to_trans_raw_sig \\<tau>' sig)` `k1 < k2` `k2 < t + dly`\n        unfolding \\<tau>'_def post_raw_def to_trans_raw_sig_def by (simp add: keys_def)\n      moreover have \"\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig \\<tau> sig)\"\n        using `\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig \\<tau>' sig)` `k1 < k2` `k2 < t +dly`\n        unfolding \\<tau>'_def post_raw_def to_trans_raw_sig_def  by (simp add: keys_def)\n      ultimately have \"to_trans_raw_sig \\<tau> sig k1 \\<noteq> to_trans_raw_sig \\<tau> sig k2\"\n        using assms(1) `k1 < k2` unfolding non_stuttering_def by auto\n      moreover have \"to_trans_raw_sig \\<tau> sig k1 = to_trans_raw_sig \\<tau>' sig k1\" and\n        \"to_trans_raw_sig \\<tau> sig k2 = to_trans_raw_sig \\<tau>' sig k2\"\n        using `k1 < k2` `k2 < t +dly` unfolding \\<tau>'_def post_raw_def to_trans_raw_sig_def\n        by auto\n      ultimately have \"to_trans_raw_sig \\<tau>' sig k1 \\<noteq> to_trans_raw_sig \\<tau>' sig k2\"\n        by auto }\n    ultimately have \"to_trans_raw_sig \\<tau>' sig k1 \\<noteq> to_trans_raw_sig \\<tau>' sig k2\"\n      by auto }\n  note first_po = this\n  { assume \"keys (to_trans_raw_sig \\<tau>' sig) \\<noteq> {}\"\n    { assume \"(\\<forall>i\\<ge>t. i \\<le> t + (dly - 1) \\<longrightarrow> \\<tau> i sig = None) \\<and> val \\<noteq> \\<sigma> sig\"\n      hence *: \"(\\<forall>i. i \\<le> t + (dly - 1) \\<longrightarrow> \\<tau>' i sig = None)\" and \"val \\<noteq> \\<sigma> sig\"\n        unfolding \\<tau>'_def post_raw_def using `0 < dly` assms(4)\n        by (smt Suc_diff_1 add_Suc_right fun_upd_same le_add1 le_imp_less_Suc less_irrefl_nat nat_le_linear)+\n      have \"(LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>' sig)) = t + dly\"\n      proof (intro Least_equality)\n        show \"t + dly \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>' sig)\"\n          unfolding \\<tau>'_def post_raw_def to_trans_raw_sig_def keys_def by (auto simp add: zero_option_def)\n      next\n        { fix y\n          assume \"\\<not> t + dly \\<le> y\" hence \"y < t + dly\" by auto\n          hence \"\\<tau>' y sig = None\"\n            using * by auto\n          hence \"y \\<notin> keys (to_trans_raw_sig \\<tau>' sig)\"\n            using * unfolding \\<tau>'_def to_trans_raw_sig_def keys_def post_raw_def\n            by (auto simp add: zero_option_def) }\n        thus \"\\<And>y. y \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>' sig) \\<Longrightarrow> t + dly \\<le> y\"\n          by auto\n      qed\n      hence \"\\<sigma> sig \\<noteq> the (to_trans_raw_sig \\<tau>' sig (LEAST k. k \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>' sig)))\"\n        using \\<tau>'_def `val \\<noteq> \\<sigma> sig` unfolding post_raw_def to_trans_raw_sig_def by auto }\n    moreover\n    { assume \"(\\<exists>i val'. i \\<le> t + (dly - 1) \\<and> \\<tau> i sig = Some val' \\<and> val' \\<noteq> val \\<and> (\\<forall>j>i. j \\<le> t + (dly - 1) \\<longrightarrow> \\<tau> j sig = None))\"\n      then obtain i val' where \"i \\<ge> t\" and \"i \\<le> t + (dly - 1)\" and \"\\<tau> i sig = Some val'\" and\n        \"\\<forall>j>i. j < t + (dly - 1) \\<longrightarrow> \\<tau> j sig = None\"\n        by (metis assms(4) nat_le_linear nat_less_le option.distinct(1) zero_fun_def zero_option_def)\n      hence **: \"i \\<in> keys (to_trans_raw_sig \\<tau> sig)\"\n        unfolding keys_def to_trans_raw_sig_def by (auto simp add: zero_option_def)\n      hence *: \"i \\<in> keys (to_trans_raw_sig \\<tau>' sig)\"\n        using `i \\<le> t + (dly - 1)` `0 < dly` unfolding \\<tau>'_def post_raw_def to_trans_raw_sig_def\n        keys_def by auto\n      define least_key where \"least_key = (LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau>' sig))\"\n      have \"least_key \\<le> t + (dly - 1)\"\n        using Least_le[where P=\"\\<lambda>k. k \\<in> keys (to_trans_raw_sig \\<tau>' sig)\", OF *] `i \\<le> t + (dly-1)`\n        unfolding least_key_def by auto\n      have \"(LEAST k. k \\<in> keys (to_trans_raw_sig \\<tau> sig)) = least_key\"\n      proof (rule Least_equality)\n        have \"least_key \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>' sig)\"\n          using LeastI[where P=\"\\<lambda>k. k \\<in> keys (to_trans_raw_sig \\<tau>' sig)\", OF *]\n          unfolding least_key_def by auto\n        then obtain val' where \"\\<tau>' least_key sig = Some val'\"\n          unfolding keys_def to_trans_raw_sig_def by (auto simp add: zero_option_def)\n        hence \"\\<tau> least_key sig = Some val'\"\n          unfolding \\<tau>'_def post_raw_def using `least_key \\<le> t + (dly - 1)` `0 < dly`\n          by (smt Suc_diff_1 add_Suc_right fun_upd_same le_imp_less_Suc not_le option.distinct(1)\n          order_refl)\n        thus \" least_key \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau> sig)\"\n          unfolding to_trans_raw_sig_def keys_def by (auto simp add: zero_option_def)\n      next\n        { fix y\n          assume \"\\<not> least_key \\<le> y\" hence \"y < least_key\" by auto\n          hence \"y \\<notin> keys (to_trans_raw_sig \\<tau>' sig)\"\n            using not_less_Least unfolding least_key_def by auto\n          have \"y < t + (dly - 1)\"\n            using `y < least_key` `least_key \\<le> t + (dly - 1)` by auto\n          hence \"\\<tau>' y sig = \\<tau> y sig\"\n            unfolding \\<tau>'_def post_raw_def by auto\n          hence \"y \\<notin> keys (to_trans_raw_sig \\<tau> sig)\"\n            using `y \\<notin> keys (to_trans_raw_sig \\<tau>' sig)`  by (simp add: keys_def to_trans_raw_sig_def) }\n        thus \"\\<And>y. y \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau> sig) \\<Longrightarrow> least_key \\<le> y\"\n          by auto\n      qed\n      note least_key_alt_def = sym[OF this]\n      have ***: \"\\<sigma> sig \\<noteq> the (to_trans_raw_sig \\<tau> sig (LEAST k. k \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau> sig)))\"\n        using assms(1) unfolding non_stuttering_def  using \"**\" by blast\n      have \"the (to_trans_raw_sig \\<tau> sig (LEAST k. k \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau> sig))) =\n            the (to_trans_raw_sig \\<tau> sig (LEAST k. k \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>' sig)))\"\n        using least_key_alt_def unfolding least_key_def by auto\n      also have \"... = the (to_trans_raw_sig \\<tau> sig least_key)\"\n        unfolding least_key_def by auto\n      also have \"... = the (to_trans_raw_sig \\<tau>' sig least_key)\"\n        unfolding \\<tau>'_def post_raw_def to_trans_raw_sig_def using `least_key \\<le> t + (dly -1)`\n        `0 < dly` by auto\n      finally have \"the (to_trans_raw_sig \\<tau> sig (LEAST k. k \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau> sig))) =\n                    the (to_trans_raw_sig \\<tau>' sig (LEAST k. k \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>' sig)))\"\n        unfolding least_key_def by auto\n      with *** have \"\\<sigma> sig \\<noteq> the (to_trans_raw_sig \\<tau>' sig (LEAST k. k \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>' sig)))\"\n        by auto }\n    ultimately have \"\\<sigma> sig \\<noteq> the (to_trans_raw_sig \\<tau>' sig (LEAST k. k \\<in> Femto_VHDL_raw.keys (to_trans_raw_sig \\<tau>' sig)))\"\n      using cases by auto }\n  note second_po = this\n  with first_po show ?thesis\n    unfolding non_stuttering_def by auto\nqed\n\nlemma trans_post_preserves_non_stuttering:\n  assumes \"non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma> s\"\n  assumes \"t, \\<sigma>, \\<gamma>, \\<theta>, def \\<turnstile> <cs, \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\"\n  assumes \"\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\"\n  assumes \"cs = Bassign_trans sig e dly\"\n  shows \"non_stuttering (to_trans_raw_sig \\<tau>') \\<sigma> s\"\n  using assms\nproof (induction cs arbitrary: \\<tau> \\<tau>')\n  case (Bcase x1 x2)\n  then show ?case  by force\nnext\n  case (Bassign_trans sig e dly)\n  obtain x where \"t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> e \\<longrightarrow>\\<^sub>b x\"\n    by (meson Bassign_trans.prems(2) seq_cases_trans)\n  hence \\<tau>'_def: \"\\<tau>' = trans_post_raw sig x (\\<sigma> sig) \\<tau> t dly\"\n    using Bassign_trans.prems(2) beval_raw_deterministic by (metis seq_cases_trans)\n  have prev_zero: \"\\<And>n. n < t \\<Longrightarrow> to_trans_raw_sig \\<tau> s n = 0\"\n    using Bassign_trans(3) unfolding to_trans_raw_sig_def\n    by (auto simp add: zero_fun_def zero_option_def)\n  have \"sig \\<noteq> s \\<or> sig = s\" by auto\n  moreover\n  { assume \"sig \\<noteq> s\"\n    hence \"to_trans_raw_sig \\<tau>' s = to_trans_raw_sig \\<tau> s\"\n      using \\<tau>'_def unfolding trans_post_raw_def to_trans_raw_sig_def preempt_raw_def post_raw_def\n      by auto\n    hence ?case\n      using Bassign_trans(1) unfolding non_stuttering_def Let_def by auto }\n  moreover\n  { assume \"sig = s\"\n    have \"post_necessary_raw (dly-1) \\<tau> t sig x (\\<sigma> sig) \\<or>\n          \\<not> post_necessary_raw (dly-1) \\<tau> t sig x (\\<sigma> sig)\" by auto\n    moreover\n    { assume notnec: \"\\<not> post_necessary_raw (dly-1) \\<tau> t sig x (\\<sigma> sig)\"\n      have look: \" \\<tau>' = preempt_raw sig ( \\<tau>) (t + dly)\"\n        using notnec unfolding \\<tau>'_def trans_post_raw_def by auto\n      hence ?case\n        using preempt_raw_preserves_non_stuttering[OF Bassign_trans(1)]  by (simp add: \\<open>sig = s\\<close>) }\n    moreover\n    { assume nec: \"post_necessary_raw (dly-1) \\<tau> t sig x (\\<sigma> sig)\"\n      hence lookup: \"\\<tau>' = post_raw sig x \\<tau> (t + dly)\"\n        unfolding \\<tau>'_def by (auto simp add: trans_post_raw_def)\n      have \"0 < dly \\<or> dly = 0\"\n        by auto\n      moreover\n      { assume \"0 < dly \"\n        hence ?case\n          using post_raw_preserves_non_stuttering[OF Bassign_trans(1)]\n          using Bassign_trans.prems(3) \\<open>0 < dly\\<close> \\<open>sig = s\\<close>  using lookup nec by blast }\n      moreover\n      { assume \"dly = 0\"\n        hence nec': \"post_necessary_raw 0 \\<tau> t sig x (\\<sigma> sig)\" and lookup': \"\\<tau>' = post_raw sig x \\<tau> t\"\n          using nec lookup by auto\n        have keys': \"keys (to_trans_raw_sig \\<tau>' s) = {t}\"\n        proof \n          { fix k\n            assume \"k \\<in> keys (to_trans_raw_sig \\<tau>' s)\"\n            hence \"to_trans_raw_sig \\<tau>' s k \\<noteq> 0\"\n              unfolding keys_def by auto\n            have \"\\<not> k < t\"\n            proof (rule ccontr)\n              assume \"\\<not> \\<not> k < t\" hence \"k < t\" by auto\n              hence \"to_trans_raw_sig \\<tau>' s k = 0\"\n                using prev_zero unfolding lookup' post_raw_def by (simp add: to_trans_raw_sig_def)\n              with `to_trans_raw_sig \\<tau>' s k \\<noteq> 0` show False by auto\n            qed\n            moreover have \"\\<not> k > t\"\n            proof (rule ccontr)\n              assume \"\\<not> \\<not> k > t\" hence \"k > t\" by auto\n              hence \"to_trans_raw_sig \\<tau>' s k = 0\"\n                unfolding lookup' post_raw_def\n              proof -\n                have \"k \\<noteq> t\"\n                  using \\<open>t < k\\<close> by blast\n              then show \"to_trans_raw_sig (\\<lambda>n. if n = t then \\<tau> n(sig \\<mapsto> x) else if t < n then (\\<tau> n)(sig := None) else \\<tau> n) s k = 0\"\n                by (simp add: \\<open>sig = s\\<close> \\<open>t < k\\<close> to_trans_raw_sig_def zero_option_def)\n              qed\n              with `to_trans_raw_sig \\<tau>' s k \\<noteq> 0` show False \n                by auto\n            qed\n            ultimately have \"k = t\"\n              by auto }\n          thus \"keys (to_trans_raw_sig \\<tau>' s) \\<subseteq> {t}\"\n            by auto\n          have \"t \\<in> keys (to_trans_raw_sig \\<tau>' s)\"\n            unfolding lookup' post_raw_def \n            by (simp add: \\<open>sig = s\\<close> keys_def to_trans_raw_sig_def zero_option_def)\n          thus \"{t} \\<subseteq> keys (to_trans_raw_sig \\<tau>' s)\"\n            by auto\n        qed\n        have least: \"(LEAST k. k \\<in> {t}) = t\"\n          by (meson LeastI_ex singleton_iff)\n        have \"(\\<exists>i val'. i \\<le> t \\<and> \\<tau> i sig = Some val' \\<and> val' \\<noteq> x \\<and> (\\<forall>j>i. j \\<le> t \\<longrightarrow> \\<tau> j sig = None)) \\<or> (\\<forall>i\\<le>t. \\<tau> i sig = None) \\<and> x \\<noteq> \\<sigma> sig\"\n          using nec' unfolding post_necessary_raw_correctness2 by auto\n        hence \"(\\<forall>i\\<le>t. \\<tau> i sig = None) \\<and> x \\<noteq> \\<sigma> sig\"\n          by (metis Bassign_trans.prems(3) add.right_neutral option.distinct(1) zero_fun_def\n          zero_option_def)\n        hence \" \\<sigma> s \\<noteq> the (to_trans_raw_sig \\<tau>' s (LEAST k. k \\<in> {t}))\"\n          unfolding lookup' post_raw_def least to_trans_raw_sig_def \\<open>sig = s\\<close> by auto\n        hence ?case\n          unfolding non_stuttering_def keys' by blast }\n      ultimately have ?case by auto }\n    ultimately have ?case by auto }\n  ultimately show ?case by auto\nnext\n  case (Bcomp cs1 cs2)\n  have False\n    using `Bcomp cs1 cs2 = Bassign_trans sig e dly` by auto\n  then show ?case by auto\nnext\n  case (Bguarded x1 cs1 cs2)\n  have \"False\"\n    using `Bguarded x1 cs1 cs2 = Bassign_trans sig e dly` by auto\n  then show ?case by auto\nnext\n  case (Bassign_inert x1 x2 x3)\n  then show ?case by auto\nnext\n  case Bnull\n  then show ?case by auto\nqed\n\nlemma b_seq_exec_preserves_non_stuttering:\n  assumes \"t, \\<sigma>, \\<gamma>, \\<theta>, def \\<turnstile> <cs, \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\"\n  assumes \"non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma> s\"\n  assumes \"\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\"\n  assumes \"nonneg_delay cs\"\n  shows \"non_stuttering (to_trans_raw_sig \\<tau>') \\<sigma> s\"\n  using assms\nproof (induction rule: b_seq_exec.inducts)\n  case (1 t \\<sigma> \\<gamma> \\<theta> def \\<tau>)\n  then show ?case by auto\nnext\n  case (2 t \\<sigma> \\<gamma> \\<theta> def ss1 \\<tau> \\<tau>'' ss2 \\<tau>')\n  hence *: \"non_stuttering (to_trans_raw_sig \\<tau>'') \\<sigma> s\"\n    using nonneg_delay.simps(2) by blast\n  have \"b_seq_exec t \\<sigma> \\<gamma> \\<theta> def ss2 \\<tau>'' \\<tau>'\"\n    by (simp add: \"2.hyps\"(2))\n  moreover have \"\\<And>n. n < t \\<Longrightarrow> \\<tau>'' n = 0\"\n    using \"2.hyps\"(1) \"2.prems\"(2) b_seq_exec_preserve_trans_removal less_imp_le_nat by blast\n  ultimately show ?case\n    by (metis \"*\" \"2.IH\"(2) \"2.hyps\"(1) \"2.prems\"(2) \"2.prems\"(3) \\<open>\\<And>n. n < t \\<Longrightarrow> \\<tau>'' n = 0\\<close>\n    nonneg_delay.simps(2) nonneg_delay_same order.not_eq_order_implies_strict)\nnext\n  case (3 t \\<sigma> \\<gamma> \\<theta> def guard ss1 \\<tau> \\<tau>' ss2)\n  then show ?case\n    using nonneg_delay.simps(3) by blast\nnext\n  case (4 t \\<sigma> \\<gamma> \\<theta> def guard ss2 \\<tau> \\<tau>' ss1)\n  then show ?case\n    using nonneg_delay.simps(3) by blast\nnext\n  case (5 t \\<sigma> \\<gamma> \\<theta> def e x sig \\<tau> dly \\<tau>')\n  then show ?case\n    by (meson b_seq_exec.intros(5) trans_post_preserves_non_stuttering)\nnext\n  case (6 t \\<sigma> \\<gamma> \\<theta> def e x sig \\<tau> dly \\<tau>')\n  hence \\<tau>'_def': \"\\<tau>' = trans_post_raw sig x (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) x) t dly\"\n    using 6  by (simp add: inr_post_raw'_def)\n  let ?\\<tau> = \"purge_raw' \\<tau> t dly sig (\\<sigma> sig) x\"\n  have \"s = sig \\<or> s \\<noteq> sig\"\n    by auto\n  moreover\n  { assume \"s \\<noteq> sig\"\n    hence \"\\<And>n. to_trans_raw_sig \\<tau>' s n = to_trans_raw_sig \\<tau> s n\"\n      using \\<tau>'_def'\n      by (metis \"6.hyps\"(2) inr_post_raw_does_not_affect_other_sig' to_trans_raw_sig_def)\n    hence \"to_trans_raw_sig \\<tau>' s = to_trans_raw_sig \\<tau> s\"\n      by blast\n    hence ?case\n      using 6 unfolding non_stuttering_def Let_def by auto }\n  moreover\n  { assume \"s = sig\"\n    moreover have 3: \"\\<And>n. n \\<le> t \\<Longrightarrow> ?\\<tau> n = 0\"\n      by (simp add: \"6.prems\"(2) purge_preserve_trans_removal_nonstrict')\n    obtain cs2 where cs2_def: \"cs2 = Bassign_trans sig e dly\"\n      by auto\n    hence 2: \"t, \\<sigma>, \\<gamma>, \\<theta>, def \\<turnstile> <cs2, ?\\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\"\n      using \\<tau>'_def' by (meson \"6.hyps\"(1) b_seq_exec.intros(5))\n    hence ?case\n      using \"6.prems\"(1) \"6.prems\"(2)  \\<tau>'_def' calculation\n      purge'_trans_post_preserve_non_stuttering by metis }\n  ultimately show ?case\n    by auto\nqed auto\n\ntext \\<open>end of non stuttering\\<close>\n\ntext \\<open>The type @{typ \"'signal assn\"} represents a predicate over a worldline, i.e., a property\nabout a worldline. The pre- and post-condition of a VHDL sequential statement will be of this type.\\<close>\n\ndefinition state_of_world :: \"'signal worldline_init \\<Rightarrow> nat \\<Rightarrow> 'signal state\" where\n  \"state_of_world w t = (\\<lambda>s. snd w s t)\"\n\ndefinition event_of_world :: \"'signal worldline_init  \\<Rightarrow> nat \\<Rightarrow> 'signal event\" where\n  \"event_of_world w t = (if t = 0 then {s :: 'signal. snd w s t \\<noteq> fst w s} else\n                                       {s :: 'signal. snd w s t \\<noteq> snd w s (t - 1)})\"\n\ndefinition beh_of_world_raw :: \"'signal worldline_init \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> 'signal \\<rightharpoonup> val\" where\n  \"beh_of_world_raw w t = (\\<lambda>t'. if t' < t then (\\<lambda>s. Some (snd w s t')) else Map.empty)\"\n\ninductive beval_world_raw :: \"'signal worldline_init \\<Rightarrow> nat \\<Rightarrow> 'signal bexp \\<Rightarrow> val \\<Rightarrow> bool\"\n  where\n  \" state_of_world w t = \\<sigma> \\<Longrightarrow> event_of_world w t = \\<gamma> \\<Longrightarrow> derivative_hist_raw w t = \\<theta> \\<Longrightarrow>\n    t, \\<sigma>, \\<gamma>, \\<theta>, (fst w) \\<turnstile> exp \\<longrightarrow>\\<^sub>b x \\<Longrightarrow> beval_world_raw w t exp x\"\n\ninductive_cases beval_world_raw_cases [elim!]: \"beval_world_raw w t exp x\"\n\nlemma beval_world_raw_deterministic:\n  assumes \"beval_world_raw w t exp x1\"\n  assumes \"beval_world_raw w t exp x2\"\n  shows \"x2 = x1\"\n  using assms(1) assms(2) beval_raw_deterministic beval_world_raw_cases by blast\n\ntext \\<open>As promised in the beginning of this theory, we show the first relationship from @{typ\n\"'signal worldline\"} to the realm of @{typ \"'signal state\"}, @{typ \"'signal event\"}, and @{typ\n\"'signal trans_raw\"}.\n\nFor @{term \"state_of_world\"}, the definition is obvious. We need a function abstraction --- instead\nof simply giving an argument to function @{term \"w :: 'signal worldline\"} to return another function\n--- here because the different order of the arguments: in @{typ \"'signal worldline\"} the name of the\nsignal comes before the time.\n\nEvent represents the set of signals whose values are different from the previous time. Here is the\ndilemma: what happens at time @{term \"0::nat\"}? There is no such time as @{term \"0 - 1\"} as this\nwill evaluate to @{term \"0\"} in natural numbers. Nevertheless, event at time @{term \"0 :: nat\"}\nhas different interpretation: it is the set of signals whose values are different from the default\nvalues, i.e., @{term \"Bv False :: val\"}. The expression for else-statement in @{term \"event_of_world\"}\nis obvious.\n\nNote that @{term \"beh_of_world\"} requires a lift_definition instead of standard definition\nconstruct; this is due to @{typ \"'signal trans_raw\"}. Its raw version @{term \"beh_of_world_raw\"}\nonly maps until the time @{term \"t\"} only. This is because behaviour is synonymous with history in\nour definition and, according to the order of time, we do not have any ``mapping'' from time now\nuntil the future.\n\\<close>\n\ninductive\n  seq_hoare :: \"nat \\<Rightarrow> 'signal assn \\<Rightarrow> 'signal seq_stmt \\<Rightarrow> 'signal assn \\<Rightarrow> bool\"\n  (\"\\<turnstile>\\<^sub>_ ({(1_)}/ (_)/ {(1_)})\" 50) where\nNull: \"\\<turnstile>\\<^sub>t {P} Bnull {P}\"\n\n| Assign: \"\\<turnstile>\\<^sub>t {\\<lambda>w . (\\<exists>x. beval_world_raw w t exp x \\<and> P (w[sig, t + dly := x]))} Bassign_trans sig exp dly {P}\"\n\n| AssignI: \"\\<turnstile>\\<^sub>t {\\<lambda>w . (\\<exists>x. beval_world_raw w  t exp x \\<and> P (worldline_inert_upd2 w sig t dly x))} Bassign_inert sig exp dly {P}\"\n\n| Comp: \"\\<lbrakk> \\<turnstile>\\<^sub>t {P} s1 {Q}; \\<turnstile>\\<^sub>t {Q} s2 {R}\\<rbrakk> \\<Longrightarrow> \\<turnstile>\\<^sub>t {P} Bcomp s1 s2 {R}\"\n\n| If: \" \\<turnstile>\\<^sub>t {\\<lambda>w . P w  \\<and> (\\<exists>x. beval_world_raw w  t g x \\<and>   bval_of x)} s1 {Q} \\<Longrightarrow>\n        \\<turnstile>\\<^sub>t {\\<lambda>w . P w  \\<and> (\\<exists>x. beval_world_raw w  t g x \\<and> \\<not> bval_of x)} s2 {Q} \\<Longrightarrow>\n        \\<turnstile>\\<^sub>t {P} Bguarded g s1 s2 {Q}\"\n\n| Conseq: \"\\<lbrakk>\\<forall>w . P' w  \\<longrightarrow> P w ; \\<turnstile>\\<^sub>t {P} s {Q}; \\<forall>w . Q w  \\<longrightarrow> Q' w \\<rbrakk> \\<Longrightarrow> \\<turnstile>\\<^sub>t {P'} s {Q'}\"\n\n| Bcase_empty_choices: \"\\<turnstile>\\<^sub>t {P} Bcase exp [] {P}\"\n\n| Bcase_others: \"\\<turnstile>\\<^sub>t {P} ss {Q} \\<Longrightarrow> \\<turnstile>\\<^sub>t {P} Bcase exp ((Others, ss) # choices) {Q}\"\n\n| Bcase_if: \"\\<turnstile>\\<^sub>t {\\<lambda>w. P w \\<and> (\\<exists>x. beval_world_raw w t exp x \\<and> beval_world_raw w t exp' x)} ss {Q}\n  \\<Longrightarrow> \\<turnstile>\\<^sub>t {\\<lambda>w. P w \\<and> (\\<exists>x x'. beval_world_raw w t exp x \\<and> beval_world_raw w t exp' x' \\<and> x \\<noteq> x')} Bcase exp choices {Q}\n  \\<Longrightarrow> \\<turnstile>\\<^sub>t {P} Bcase exp ( (Explicit exp', ss) # choices) {Q}\"\n\ntext \\<open>The inductive definition @{term \"seq_hoare\"} is similar to the inductive definition @{term\n\"hoare\"} in @{theory_text \"Hoare\"}. Rules other than @{thm \"Assign\"} and @{thm \"AssignI\"} are\nstandard; we explain those two only here. As can be seen, the construct @{term \"worldline_upd\"} and\n@{term \"worldline_inert_upd\"} are designed for the purpose of defining the axiomatic semantics\nof VHDL. We show how it makes sense later in the soundness property.\\<close>\n\ninductive_cases seq_hoare_ic: \"\\<turnstile>\\<^sub>t {P} s {Q}\"\n\ninductive_cases seq_hoare_cases_null [elim!]: \"\\<turnstile>\\<^sub>t {P} Bnull {Q}\" and\n                seq_hoare_cases_assign : \"\\<turnstile>\\<^sub>t {P} Bassign_trans sig exp dly {Q}\" and\n                seq_hoare_cases_assign_inert : \"\\<turnstile>\\<^sub>t {P} Bassign_inert sig exp dly {Q}\" and\n                seq_hoare_cases_comp : \"\\<turnstile>\\<^sub>t {P} Bcomp s1 s2 {Q}\" and\n                seq_hoare_cases_if : \"\\<turnstile>\\<^sub>t {P} Bguarded g s1 s2 {Q}\" and\n                seq_hoare_cases_bcase : \"\\<turnstile>\\<^sub>t {P} Bcase exp choices {Q}\"\n\nlemma BnullE:\n  assumes \"\\<turnstile>\\<^sub>t {P} s {Q}\"\n  assumes \"s = Bnull\"\n  shows \"\\<forall>w . P w  \\<longrightarrow> Q w \"\n  using assms\n  by (induction rule:seq_hoare.induct, auto)\n\nlemma BnullE':\n  \"\\<turnstile>\\<^sub>t {P} Bnull {Q} \\<Longrightarrow> \\<forall>w . P w  \\<longrightarrow> Q w \"\n  by (simp add: BnullE)\n\nlemma BassignE:\n  assumes \"\\<turnstile>\\<^sub>t {P} s {Q}\"\n  assumes \"s = Bassign_trans sig exp dly\"\n  shows \"\\<forall>w . P w  \\<longrightarrow> (\\<exists>x. beval_world_raw w t exp x \\<and> Q (w[sig, t + dly := x]))\"\n  using assms\nproof (induction rule:seq_hoare.induct)\n  case (Conseq P' P t s Q Q')\n  then show ?case by metis\nqed (auto)\n\nlemma BassignE2:\n  assumes \"\\<turnstile>\\<^sub>t {P} s {Q}\"\n  assumes \"s = Bassign_trans sig exp dly\"\n  shows \"\\<forall>w  x. P w  \\<and> beval_world_raw w t exp x \\<longrightarrow> Q (w[sig, t + dly := x])\"\n  using BassignE[OF assms] beval_world_raw_deterministic by metis\n\nlemma Bassign_inertE:\n  assumes \"\\<turnstile>\\<^sub>t {P} s {Q}\"\n  assumes \"s = Bassign_inert sig exp dly\"\n  shows \"\\<forall>w. P w \\<longrightarrow> (\\<exists>x. beval_world_raw w t exp x \\<and> Q (worldline_inert_upd2 w sig t dly x))\"\n  using assms\nproof (induction rule: seq_hoare.induct)\n  case (Conseq P' P t s Q Q')\n  then show ?case by  metis\nqed auto\n\nlemma Bassign_inertE2:\n  assumes \"\\<turnstile>\\<^sub>t {P} s {Q}\"\n  assumes \"s = Bassign_inert sig exp dly\"\n  shows \"\\<forall>w x. P w \\<and> beval_world_raw w t exp x \\<longrightarrow> Q (worldline_inert_upd2 w sig t dly x)\"\n  using Bassign_inertE[OF assms] beval_world_raw_deterministic by metis\n\nlemma BcompE:\n  assumes \"\\<turnstile>\\<^sub>t {P} s {R}\"\n  assumes \"s = Bcomp s1 s2\"\n  shows \"\\<exists>Q. \\<turnstile>\\<^sub>t {P} s1 {Q} \\<and> \\<turnstile>\\<^sub>t {Q} s2 {R}\"\n  using assms\nproof (induction rule:seq_hoare.induct)\n  case (Comp t P s1 Q s2 R)\n  then show ?case by blast\nnext\n  case (Conseq P' P t s Q Q')\n  then show ?case\n    by (metis seq_hoare.Conseq)\nqed auto\n\nlemmas [simp] = seq_hoare.Null seq_hoare.Assign seq_hoare.Comp seq_hoare.If\n                seq_hoare.Bcase_empty_choices seq_hoare.Bcase_if seq_hoare.Bcase_others\nlemmas [intro!] = seq_hoare.Null seq_hoare.Assign seq_hoare.Comp seq_hoare.If\n                  seq_hoare.Bcase_empty_choices seq_hoare.Bcase_if seq_hoare.Bcase_others\n\n\n\n\n\nlemma Assign':\n  assumes \"\\<forall>w. P w \\<longrightarrow> (\\<exists>x. beval_world_raw w t exp x \\<and> Q (worldline_upd w sig (t + dly) x))\"\n  shows \"\\<turnstile>\\<^sub>t {P} Bassign_trans sig exp dly {Q}\"\n  using assms by (simp add: strengthen_pre)\n\ndefinition\nseq_hoare_valid :: \"nat \\<Rightarrow> 'signal assn \\<Rightarrow> 'signal seq_stmt \\<Rightarrow> 'signal assn \\<Rightarrow> bool\" (\"\\<Turnstile>\\<^sub>_ {(1_)}/ (_)/ {(1_)}\" 50)\nwhere \"\\<Turnstile>\\<^sub>t {P} s {Q} \\<longleftrightarrow>  (\\<forall>\\<sigma> \\<tau> \\<gamma> \\<theta> \\<tau>' w w' def .  context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>\n                                            \\<and> (\\<forall>s. non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma> s)\n                                            \\<and> (\\<forall>s. non_stuttering (to_trans_raw_sig \\<theta>) def s)\n                                            \\<and>  w = worldline_raw t \\<sigma> \\<theta> def \\<tau>\n                                            \\<and>  P w\n                                            \\<and> (t, \\<sigma>, \\<gamma>, \\<theta>, def \\<turnstile> < s, \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>')\n                                            \\<and>  w' = worldline_raw t \\<sigma> \\<theta> def \\<tau>' \\<longrightarrow> Q w')\"\n\ntext \\<open>The definition @{term \"seq_hoare_valid\"} shall be the basis to define the soundness of the\nHoare logic rules. Note that the symbol of `\\<Turnstile>` has @{term \"t\"} as its subscript which indicates\nthat the validity is a function of time. Here is the diagram explaining the definition of the\nvalidity:\n\\<close>\n\n(*\n         P w             \\<longrightarrow>               Q w\n          \\<up>                                 \\<up>\n w = worldline t \\<sigma> \\<theta> \\<tau>          w' = worldline t \\<sigma> \\<theta> \\<tau>'\n          \\<up>                                 \\<up>\n          \\<tau>              \\<longrightarrow>\\<^sub>c               \\<tau>'\n*)\n\n\nsubsection \\<open>Soundness\\<close>\n\nlemma Bcomp_hoare_valid:\n  assumes \"\\<Turnstile>\\<^sub>t {P} s1 {Q}\" and \"\\<Turnstile>\\<^sub>t {Q} s2 {R}\"\n  assumes \"nonneg_delay (Bcomp s1 s2)\"\n  shows   \"\\<Turnstile>\\<^sub>t {P} Bcomp s1 s2 {R}\"\n  unfolding seq_hoare_valid_def\nproof (rule)+\n  fix \\<sigma> :: \"'a state\"\n  fix \\<tau> \\<theta> \\<tau>' :: \"'a trans_raw\"\n  fix \\<gamma> :: \"'a event\"\n  fix w w' :: \"'a worldline_init\"\n  fix def\n  assume \"context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau> \\<and> All (non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma>) \\<and> All (non_stuttering (to_trans_raw_sig \\<theta>) def) \\<and>\n          w = worldline_raw t \\<sigma> \\<theta> def \\<tau> \\<and> P w \\<and>\n          t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> <Bcomp s1 s2 , \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>' \\<and> w' = worldline_raw t \\<sigma> \\<theta> def \\<tau>'\"\n  hence \"context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>\" and \"w = worldline_raw t \\<sigma> \\<theta> def \\<tau>\" and \"P w\" and \"All (non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma>)\"\n    and \"All (non_stuttering (to_trans_raw_sig \\<theta>) def)\"\n    and \"t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> <Bcomp s1 s2 , \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>' \" and 2: \"w' = worldline_raw t \\<sigma> \\<theta> def \\<tau>'\"\n    by auto\n  then obtain \\<tau>'' where 0: \"t, \\<sigma>, \\<gamma>, \\<theta>, def \\<turnstile> < s1, \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>''\" and 1: \"t, \\<sigma>, \\<gamma>, \\<theta>, def \\<turnstile> < s2, \\<tau>''> \\<longrightarrow>\\<^sub>s \\<tau>'\"\n    using seq_cases_bcomp by blast\n  define w'' where \"w'' = worldline_raw t \\<sigma> \\<theta> def \\<tau>''\"\n  hence \"Q w''\"\n    using `\\<Turnstile>\\<^sub>t {P} s1 {Q}` unfolding seq_hoare_valid_def\n    using \\<open>P w\\<close> \\<open>context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>\\<close> \\<open>t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> < s1 , \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>''\\<close> \\<open>w = worldline_raw t \\<sigma> \\<theta> def \\<tau>\\<close>\n    \\<open>All (non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma>)\\<close> \\<open>All (non_stuttering (to_trans_raw_sig \\<theta>) def)\\<close>\n    by blast\n  have \"context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>''\"\n    using b_seq_exec_preserves_context_invariant[OF `context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>` 0] assms(3)\n    by auto\n  moreover have \"\\<forall>s. non_stuttering (to_trans_raw_sig \\<tau>') \\<sigma> s\"\n  proof -\n    have \"\\<forall>s. non_stuttering (to_trans_raw_sig \\<tau>'') \\<sigma> s\"\n      using b_seq_exec_preserves_non_stuttering[OF 0] `All (non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma>)`\n      `context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>` assms(3)  by (simp add: context_invariant_def)\n    thus ?thesis\n      using b_seq_exec_preserves_non_stuttering[OF 1]\n      `context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>` assms(3)\n      by (meson calculation context_invariant_def nonneg_delay.simps(2))\n  qed\n  ultimately show \"R w'\"\n    using `\\<Turnstile>\\<^sub>t {Q} s2 {R}` `w'' = worldline_raw t \\<sigma> \\<theta> def \\<tau>''` `Q w''` 1 2 unfolding seq_hoare_valid_def\n    by (metis (full_types, hide_lams) \"0\" \\<open>context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau> \\<and> All (non_stuttering\n    (to_trans_raw_sig \\<tau>) \\<sigma>) \\<and> All (non_stuttering (to_trans_raw_sig \\<theta>) def) \\<and> w = worldline_raw t \\<sigma> \\<theta> def \\<tau> \\<and> P w \\<and> t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> <Bcomp s1 s2 , \\<tau>>\n    \\<longrightarrow>\\<^sub>s \\<tau>' \\<and> w' = worldline_raw t \\<sigma> \\<theta> def \\<tau>'\\<close> assms(3) b_seq_exec_preserves_non_stuttering\n    context_invariant_def nonneg_delay.simps(2))\nqed\n\nlemma Bnull_sound:\n  \"\\<turnstile>\\<^sub>t {P} Bnull {Q} \\<Longrightarrow> \\<Turnstile>\\<^sub>t {P} Bnull {Q}\"\n  by (auto dest!: BnullE' simp add: seq_hoare_valid_def)\n\nlemma state_of_world:\n  assumes \"w = worldline_raw t \\<sigma> \\<theta> def \\<tau>\"\n  assumes \"\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\"\n  shows \"state_of_world w t = \\<sigma>\"\nproof\n  fix x\n  have \"signal_of (\\<sigma> x) \\<tau> x t = \\<sigma> x\"\n  proof -\n    have True: \"(to_trans_raw_sig \\<tau> x) t = 0\"\n      using assms(2) by (auto simp add: to_trans_raw_sig_def zero_fun_def)\n    hence \"\\<forall>k \\<in> dom ((to_trans_raw_sig \\<tau> x)). t \\<le> k\"\n      using assms(2) unfolding to_trans_raw_sig_def\n      by (metis domIff linear zero_option_def)\n    moreover have \"t \\<notin> dom ( (to_trans_raw_sig \\<tau> x))\"\n      using True  by (simp add: domIff zero_option_def)\n    ultimately have \"\\<forall>k \\<in> dom ( (to_trans_raw_sig \\<tau> x)). t < k\"\n      using nat_less_le by auto\n    hence \"Femto_VHDL_raw.inf_time (to_trans_raw_sig \\<tau>) x t = None\"\n      by (auto simp add: inf_time_none_iff)\n    thus \"signal_of (\\<sigma> x) \\<tau> x t = \\<sigma> x\"\n      unfolding Femto_VHDL_raw.to_signal_def comp_def by auto\n  qed\n  thus \"state_of_world w t x = \\<sigma> x\"\n    unfolding state_of_world_def assms worldline_raw_def by auto\nqed\n\nlemma beval_beh_of_world:\n  assumes \"beval_raw t \\<sigma> \\<gamma> \\<theta> def exp x\"\n  assumes \"w = worldline_raw t \\<sigma> \\<theta> def \\<tau>\"\n  assumes \"\\<And>n. t \\<le> n \\<Longrightarrow> \\<theta> n = 0\"\n  shows \"beval_raw t \\<sigma> \\<gamma> (beh_of_world_raw w t) def exp x\"\n  using assms\nproof (induction rule: beval_raw.inducts)\n  case (4 t \\<sigma> \\<gamma> \\<theta> def sig n)\n  have \"t , \\<sigma> , \\<gamma> , (beh_of_world_raw w t), def \\<turnstile> Bsig_delayed sig n \\<longrightarrow>\\<^sub>b (signal_of (def sig) (beh_of_world_raw w t) sig (t - n))\"\n    by (meson beval_raw.intros(4))\n  have *: \"beval_raw t \\<sigma> \\<gamma> \\<theta> def (Bsig_delayed sig n) (signal_of (def sig) \\<theta> sig (t - n))\"\n    by (meson beval_raw.intros(4))\n  have \"0 < n \\<and> 0 < t \\<or> (t \\<noteq> 0 \\<and> n = 0) \\<or> t = 0\"\n    by auto\n  moreover\n  { assume \"0 < n \\<and> 0 < t\"\n    hence \" (beh_of_world_raw w t) (t - n) = Some \\<circ> (\\<lambda>s. snd w s (t - n))\"\n      unfolding beh_of_world_raw_def comp_def by auto\n    hence \"signal_of (def sig) (beh_of_world_raw w t) sig (t - n) = snd w sig (t - n)\"\n      by (auto dest!:trans_some_signal_of)\n    also have \"... = signal_of (def sig) \\<theta> sig (t - n)\"\n      using `0 < n \\<and> 0 < t` unfolding 4 worldline_raw_def by auto\n    hence \"beval_raw t \\<sigma> \\<gamma> \\<theta> def (Bsig_delayed sig n) (signal_of (def sig) \\<theta> sig (t - n))\"\n      using * by auto\n    hence \"beval_raw t \\<sigma> \\<gamma> \\<theta> def (Bsig_delayed sig n) (signal_of (def sig) (beh_of_world_raw w t) sig (t - n))\"\n      using \\<open>snd w sig (t - n) = signal_of (def sig) \\<theta> sig (t - n)\\<close> calculation by auto\n    hence ?case\n      using \\<open>t , \\<sigma> , \\<gamma> , beh_of_world_raw w t, def \\<turnstile> Bsig_delayed sig n \\<longrightarrow>\\<^sub>b signal_of (def sig)\n      (beh_of_world_raw w t) sig (t - n)\\<close> \\<open>snd w sig (t - n) = signal_of (def sig) \\<theta> sig (t - n)\\<close>\n      calculation by auto }\n  moreover\n  { assume \"t \\<noteq> 0 \\<and> n = 0 \\<or> t = 0\"\n    moreover\n    { assume \"t = 0\"\n      hence \"t - n = 0\" by auto\n      have \"beh_of_world_raw w t = 0\" unfolding `t = 0`\n        by (auto simp add: beh_of_world_raw_def zero_fun_def zero_option_def)\n      hence \"signal_of (def sig) (beh_of_world_raw w t) sig (t - n) = signal_of (def sig) 0 sig 0\"\n        unfolding `t - n = 0` by auto\n      also have \"... = def sig\"\n        using signal_of_empty[of \"def sig\" \"sig\" \"0\"] by auto\n      finally have \"signal_of (def sig) (beh_of_world_raw w t) sig (t - n) = def sig\"\n        by auto\n      have \"\\<theta> = 0\"\n        using 4 unfolding `t = 0` by (auto simp add: zero_fun_def)\n      hence \"beval_raw t \\<sigma> \\<gamma> \\<theta> def (Bsig_delayed sig n) (signal_of (def sig) \\<theta> sig 0)\"\n        using `t - n = 0` \"*\" by auto\n      also have \"... = def sig\"\n        unfolding `\\<theta> = 0` using signal_of_empty[of \"def sig\"] by metis\n      finally have \"beval_raw t \\<sigma> \\<gamma> \\<theta> def (Bsig_delayed sig n) (def sig)\"\n        by auto\n      hence ?case\n        using `signal_of (def sig) (beh_of_world_raw w t) sig (t - n) = def sig`\n        by (simp add: \\<open>\\<theta> = 0\\<close> \\<open>beh_of_world_raw w t = 0\\<close>) }\n    moreover\n    { assume \"t \\<noteq> 0 \\<and> n = 0\"\n      have \" \\<theta> t = 0\"\n        using 4 by auto\n      have \" (beh_of_world_raw w t) t = 0\"\n        unfolding beh_of_world_raw_def\n        by (metis (full_types) less_not_refl map_add_subsumed1 map_add_subsumed2 map_le_def\n        zero_fun_def zero_option_def)\n      have *: \" (beh_of_world_raw w t) (t - 1) = Some o (\\<lambda>s. snd w s (t - 1))\"\n        using `t \\<noteq> 0 \\<and> n = 0` unfolding beh_of_world_raw_def by auto\n      have \"signal_of (def sig) (beh_of_world_raw w t) sig (t - n) = signal_of (def sig) (beh_of_world_raw w t) sig t\"\n        using `t \\<noteq> 0 \\<and> n = 0` by auto\n      also have \"... = signal_of (def sig) (beh_of_world_raw w t) sig (t - 1)\"\n        using signal_of_less[where \\<tau>=\"beh_of_world_raw w t\", OF `(beh_of_world_raw w t) t = 0`]\n        by metis\n      also have \"... = snd w sig (t - 1)\"\n        using * by(auto dest!: trans_some_signal_of)\n      also have \"... = signal_of (def sig) \\<theta> sig (t - 1)\"\n        using `t \\<noteq> 0 \\<and> n = 0` unfolding 4(1) worldline_raw_def by auto\n      also have \"... = signal_of (def sig) \\<theta> sig t\"\n        using signal_of_less[where \\<tau>=\"\\<theta>\", OF ` \\<theta> t = 0`] by metis\n      also have \"... = signal_of (def sig) \\<theta> sig (t - n)\"\n        using `t \\<noteq> 0 \\<and> n = 0` by auto\n      finally have \"signal_of (def sig) (beh_of_world_raw w t) sig (t - n) = signal_of (def sig) \\<theta> sig (t - n)\"\n        by auto\n      hence ?case\n        using \\<open>t , \\<sigma> , \\<gamma> , beh_of_world_raw w t, def \\<turnstile> Bsig_delayed sig n \\<longrightarrow>\\<^sub>b signal_of (def sig)\n        (beh_of_world_raw w t) sig (t - n)\\<close> by auto }\n    ultimately have ?case by auto }\n  ultimately show ?case by auto\nqed (metis beval_raw.intros)+\n\nlemma beval_beh_of_world':\n  assumes \"beval_raw t \\<sigma> \\<gamma> \\<theta>' def exp x\"\n  assumes \"w = worldline_raw t \\<sigma> \\<theta> def \\<tau>\"\n  assumes \"\\<And>n. t \\<le> n \\<Longrightarrow> \\<theta> n = 0\"\n  assumes \"\\<theta>' = beh_of_world_raw w t\"\n  shows \"beval_raw t \\<sigma> \\<gamma> \\<theta> def exp x\"\n  using assms\nproof (induction rule: beval_raw.inducts)\n  case (4 t \\<sigma> \\<gamma> \\<theta>' def sig n)\n  have *: \"t , \\<sigma> , \\<gamma> , \\<theta>, def  \\<turnstile> Bsig_delayed sig n \\<longrightarrow>\\<^sub>b signal_of (def sig) \\<theta> sig (t - n)\"\n    by (meson beval_raw.intros(4))\n\n  have \"0 < n \\<and> 0 < t \\<or> (t \\<noteq> 0 \\<and> n = 0) \\<or> t = 0\"\n    by auto\n  moreover\n  { assume \"0 < n \\<and> 0 < t\"\n    hence \" (beh_of_world_raw w t) (t - n) = Some \\<circ> (\\<lambda>s. snd w s (t - n))\"\n      unfolding beh_of_world_raw_def comp_def by auto\n    hence \"signal_of (def sig) (beh_of_world_raw w t) sig (t - n) = snd w sig (t - n)\"\n      by (auto dest!:trans_some_signal_of)\n    also have \"... = signal_of (def sig) \\<theta> sig (t - n)\"\n      using `0 < n \\<and> 0 < t` unfolding 4 worldline_raw_def by auto\n    hence \"beval_raw t \\<sigma> \\<gamma> \\<theta> def (Bsig_delayed sig n) (signal_of (def sig) \\<theta> sig (t - n))\"\n      using * by auto\n    hence \"beval_raw t \\<sigma> \\<gamma> \\<theta> def (Bsig_delayed sig n) (signal_of (def sig) (beh_of_world_raw w t) sig (t - n))\"\n      using \\<open>snd w sig (t - n) = signal_of (def sig) \\<theta> sig (t - n)\\<close> calculation by auto\n    hence ?case\n      using \"4.prems\"(3) by metis }\n  moreover\n  { assume \"t \\<noteq> 0 \\<and> n = 0 \\<or> t = 0\"\n    moreover\n    { assume \"t = 0\"\n      hence \"t - n = 0\" by auto\n      have \"beh_of_world_raw w t = 0\" unfolding `t = 0`\n        by (auto simp add: beh_of_world_raw_def zero_fun_def zero_option_def)\n      hence \"signal_of (def sig) (beh_of_world_raw w t) sig (t - n) = signal_of (def sig) 0 sig 0\"\n        unfolding `t - n = 0` by auto\n      also have \"... = def sig\"\n        using signal_of_empty[of \"def sig\" \"sig\" \"0\"] by auto\n      finally have \"signal_of (def sig) (beh_of_world_raw w t) sig (t - n) = def sig\"\n        by auto\n      have \"\\<theta> = 0\"\n        using 4 unfolding `t = 0` by (auto simp add: zero_fun_def)\n      hence \"beval_raw t \\<sigma> \\<gamma> \\<theta> def (Bsig_delayed sig n) (signal_of (def sig) \\<theta> sig 0)\"\n        using `t - n = 0` \"*\" by auto\n      also have \"... = def sig\"\n        unfolding `\\<theta> = 0` using signal_of_empty[of \"def sig\"] by metis\n      finally have \"beval_raw t \\<sigma> \\<gamma> \\<theta> def (Bsig_delayed sig n) (def sig)\"\n        by auto\n      hence ?case\n        using `signal_of (def sig) (beh_of_world_raw w t) sig (t - n) = def sig`\n        by (simp add: \"4.prems\"(3)) }\n    moreover\n    { assume \"t \\<noteq> 0 \\<and> n = 0\"\n      have \" \\<theta> t = 0\"\n        using 4 by auto\n      have \" (beh_of_world_raw w t) t = 0\"\n        unfolding beh_of_world_raw_def\n        by (metis (full_types) less_not_refl map_add_subsumed1 map_add_subsumed2 map_le_def\n        zero_fun_def zero_option_def)\n      have *: \" (beh_of_world_raw w t) (t - 1) = Some o (\\<lambda>s. snd w s (t - 1))\"\n        using `t \\<noteq> 0 \\<and> n = 0` unfolding beh_of_world_raw_def by auto\n      have \"signal_of (def sig) (beh_of_world_raw w t) sig (t - n) = signal_of (def sig) (beh_of_world_raw w t) sig t\"\n        using `t \\<noteq> 0 \\<and> n = 0` by auto\n      also have \"... = signal_of (def sig) (beh_of_world_raw w t) sig (t - 1)\"\n        using signal_of_less[where \\<tau>=\"beh_of_world_raw w t\", OF `(beh_of_world_raw w t) t = 0`]\n        by metis\n      also have \"... = snd w sig (t - 1)\"\n        using * by(auto dest!: trans_some_signal_of)\n      also have \"... = signal_of (def sig) \\<theta> sig (t - 1)\"\n        using `t \\<noteq> 0 \\<and> n = 0` unfolding 4(1) worldline_raw_def by auto\n      also have \"... = signal_of (def sig) \\<theta> sig t\"\n        using signal_of_less[where \\<tau>=\"\\<theta>\", OF ` \\<theta> t = 0`] by metis\n      also have \"... = signal_of (def sig) \\<theta> sig (t - n)\"\n        using `t \\<noteq> 0 \\<and> n = 0` by auto\n      finally have \"signal_of (def sig) (beh_of_world_raw w t) sig (t - n) = signal_of (def sig) \\<theta> sig (t - n)\"\n        by auto\n      hence ?case\n        using \"4.prems\"(3) beval_raw.intros(4) by fastforce }\n    ultimately have ?case by auto }\n  ultimately show ?case by auto\nqed (metis beval_raw.intros)+\n\nlemma beval_beh_of_world_iff:\n  assumes \"w = worldline_raw t \\<sigma> \\<theta> def \\<tau>\"\n  assumes \"\\<And>n. t \\<le> n \\<Longrightarrow> \\<theta> n = 0\"\n  shows \"beval_raw t \\<sigma> \\<gamma> \\<theta> def exp = beval_raw t \\<sigma> \\<gamma> (beh_of_world_raw w t) def exp\"\nproof (rule, rule)\n  fix x\n  assume \"t , \\<sigma> , \\<gamma> , \\<theta>, def  \\<turnstile> exp \\<longrightarrow>\\<^sub>b x\"\n  show \"t , \\<sigma> , \\<gamma> , beh_of_world_raw w t, def  \\<turnstile> exp \\<longrightarrow>\\<^sub>b x\"\n    using beval_beh_of_world[OF `t , \\<sigma> , \\<gamma> , \\<theta>, def  \\<turnstile> exp \\<longrightarrow>\\<^sub>b x` assms] by auto\nnext\n  fix x\n  assume \"t , \\<sigma> , \\<gamma> , beh_of_world_raw w t, def  \\<turnstile> exp \\<longrightarrow>\\<^sub>b x\"\n  thus \"t , \\<sigma> , \\<gamma> , \\<theta>, def  \\<turnstile> exp \\<longrightarrow>\\<^sub>b x \"\n    using beval_beh_of_world'[OF _ assms] by blast\nqed\n\ntext \\<open>Note that the definition of @{term \"\\<gamma>\"} below will only be preserved by VHDL code which does\nnot contain a zero time signal assignment. That is, in every assignment statement, be it of transport\nor inertial type, must have nonzero delay. Check @{thm \"context_invariant\"} and note the assumption\n@{term \"t < next_time t \\<tau>'\"}.\\<close>\n\nlemma beval_beval_world_raw:\n  assumes \"w = worldline_raw t \\<sigma> \\<theta> def \\<tau>\"\n  assumes \"\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\"\n  assumes gam: \"\\<gamma> = {s. \\<sigma> s \\<noteq> signal_of (def s) \\<theta> s (t - 1)}\"\n  assumes beh: \"\\<And>n. t \\<le> n \\<Longrightarrow> \\<theta> n = 0\"\n  assumes \"\\<forall>s. non_stuttering (to_trans_raw_sig \\<theta>) def s\"\n  shows \"beval_raw t \\<sigma> \\<gamma> \\<theta> def exp = beval_world_raw w t exp\"\nproof (rule, rule)\n  fix x\n  assume \"t , \\<sigma> , \\<gamma> , \\<theta>, def  \\<turnstile> exp \\<longrightarrow>\\<^sub>b x \"\n  have \"state_of_world w t = \\<sigma>\"\n    using state_of_world[OF assms(1) assms(2)] by auto\n  moreover have \"event_of_world w t = \\<gamma>\"\n  proof (cases \"0 < t\")\n    case True\n    fix s\n    have \"snd w s t = \\<sigma> s\"\n      using `state_of_world w t = \\<sigma>` unfolding state_of_world_def by auto\n    moreover have \"snd w s (t - 1) = signal_of (def s) \\<theta> s (t - 1)\"\n      unfolding assms(1) worldline_raw_def using True by auto\n    ultimately show ?thesis\n      unfolding event_of_world_def assms(3)\n      using True\n      by (smt Collect_cong \\<open>state_of_world w t = \\<sigma>\\<close> assms(1) diff_less less_numeral_extra(3)\n      snd_conv state_of_world_def worldline_raw_def zero_less_one)\n  next\n    case False\n    hence \"t = 0\" by auto\n    hence ev: \"event_of_world w t = {s. snd w s 0 \\<noteq> def s}\"\n      unfolding event_of_world_def  by (simp add: assms(1) worldline_raw_def)\n    have \\<gamma>_def': \"\\<gamma> = {s. \\<sigma> s \\<noteq> signal_of (def s) \\<theta> s 0}\"\n      using `t = 0` gam by auto\n    have \"\\<theta> = 0\"\n      using beh unfolding `t = 0` by (auto simp add: zero_fun_def)\n    hence \"\\<And>s. signal_of (def s) \\<theta> s 0 = def s\"\n      using signal_of_empty by metis\n    hence \"\\<gamma> = {s. \\<sigma> s \\<noteq> def s}\"\n      using \\<gamma>_def' by auto\n    moreover have \"\\<And>s.  snd w s 0 = \\<sigma> s\"\n      using `state_of_world w t = \\<sigma>` `t = 0` unfolding state_of_world_def by auto\n    ultimately  have \"\\<gamma> = {s. snd w s 0 \\<noteq> def s}\"\n      by auto\n    thus ?thesis  using ev by auto\n  qed\n  moreover have \"derivative_hist_raw w t = \\<theta>\"\n    by (simp add: assms(1) assms(5) beh derivative_is_history)\n  ultimately have \" beval_raw t (state_of_world w t) (event_of_world w t) (derivative_hist_raw w t) def exp =\n                    beval_raw t \\<sigma> \\<gamma> \\<theta> def exp\"\n    by auto\n  thus \"beval_world_raw w t exp x\"\n    by (simp add: \\<open>t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> exp \\<longrightarrow>\\<^sub>b x\\<close> assms(1) beval_world_raw.intros worldline_raw_def)\nnext\n  fix x\n  assume \"beval_world_raw w t exp x\"\n  hence \"beval_raw t (state_of_world w t) (event_of_world w t) (derivative_hist_raw w t) def exp x\"\n    by (simp add: assms(1) beval_world_raw.simps worldline_raw_def)\n  have \"state_of_world w t = \\<sigma>\"\n    using state_of_world[OF assms(1) assms(2)] by auto\n  moreover have \"event_of_world w t = \\<gamma>\"\n  proof (cases \"0 < t\")\n    case True\n    fix s\n    have \"snd w s t = \\<sigma> s\"\n      using `state_of_world w t = \\<sigma>` unfolding state_of_world_def by auto\n    moreover have \"snd w s (t - 1) = signal_of (def s) \\<theta> s (t - 1)\"\n      unfolding assms(1) worldline_raw_def using True by auto\n    ultimately show ?thesis\n      unfolding event_of_world_def assms(3)\n      using True\n      by (smt Collect_cong \\<open>state_of_world w t = \\<sigma>\\<close> assms(1) diff_less less_numeral_extra(3)\n      snd_conv state_of_world_def worldline_raw_def zero_less_one)\n  next\n    case False\n    hence \"t = 0\" by auto\n    hence ev: \"event_of_world w t = {s. snd w s 0 \\<noteq> def s}\"\n      unfolding event_of_world_def  by (simp add: assms(1) worldline_raw_def)\n    have \\<gamma>_def': \"\\<gamma> = {s. \\<sigma> s \\<noteq> signal_of (def s) \\<theta> s 0}\"\n      using `t = 0` gam by auto\n    have \"\\<theta> = 0\"\n      using beh unfolding `t = 0` by (auto simp add: zero_fun_def)\n    hence \"\\<And>s. signal_of (def s) \\<theta> s 0 = def s\"\n      using signal_of_empty by metis\n    hence \"\\<gamma> = {s. \\<sigma> s \\<noteq> def s}\"\n      using \\<gamma>_def' by auto\n    moreover have \"\\<And>s.  snd w s 0 = \\<sigma> s\"\n      using `state_of_world w t = \\<sigma>` `t = 0` unfolding state_of_world_def by auto\n    ultimately  have \"\\<gamma> = {s. snd w s 0 \\<noteq> def s}\"\n      by auto\n    thus ?thesis  using ev by auto\n  qed\n  moreover have \"derivative_hist_raw w t = \\<theta>\"\n    by (simp add: assms(1) assms(5) beh derivative_is_history)\n  ultimately have \"beval_raw t \\<sigma> \\<gamma> \\<theta> def exp x\"\n    using \\<open>t , state_of_world w t , event_of_world w t , derivative_hist_raw w t, def \\<turnstile> exp \\<longrightarrow>\\<^sub>b x\\<close> by blast\n  thus \"t , \\<sigma> , \\<gamma> , \\<theta>, def  \\<turnstile> exp \\<longrightarrow>\\<^sub>b x\"\n    using beval_beh_of_world' assms(1) beh by blast\nqed\n\nlemma beval_beval_world_raw_ci:\n  assumes \"w = worldline_raw t \\<sigma> \\<theta> def \\<tau>\"\n  assumes \"context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau> \"\n  assumes \"\\<forall>s. non_stuttering (to_trans_raw_sig \\<theta>) def s\"\n  shows \"beval_raw t \\<sigma> \\<gamma> \\<theta> def exp = beval_world_raw w t exp\"\nproof -\n  have 0: \"\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\" and\n       1: \"\\<gamma> = {s. \\<sigma> s \\<noteq> signal_of (def s) \\<theta> s (t - 1)}\" and\n       3: \"\\<And>n. t \\<le> n \\<Longrightarrow> \\<theta> n = 0\"\n    using assms(2) unfolding context_invariant_def by auto\n  show ?thesis\n    using beval_beval_world_raw[OF assms(1) 0 1 3 assms(3)] by auto\nqed\n\nlemma Bguarded_hoare_valid:\n  assumes \"\\<Turnstile>\\<^sub>t {\\<lambda>a. P a \\<and> (\\<exists>x. beval_world_raw a t g x \\<and> bval_of x)} s1 {Q}\" and \"\\<Turnstile>\\<^sub>t {\\<lambda>a. P a \\<and> (\\<exists>x. beval_world_raw a t g x \\<and> \\<not> bval_of x)} s2 {Q}\"\n  shows \"\\<Turnstile>\\<^sub>t {P} Bguarded g s1 s2 {Q}\"\n  unfolding seq_hoare_valid_def\nproof (rule)+\n  fix \\<sigma> :: \"'a state\"\n  fix \\<tau> \\<theta> \\<tau>' :: \"'a trans_raw\"\n  fix \\<gamma> :: \"'a event\"\n  fix w w' :: \"'a worldline_init\"\n  fix def\n  assume \"context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau> \\<and> All (non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma>) \\<and> All (non_stuttering (to_trans_raw_sig \\<theta>) def) \\<and>\n          w = worldline_raw t \\<sigma> \\<theta> def \\<tau> \\<and> P w \\<and>\n          t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> <Bguarded g s1 s2 , \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>' \\<and> w' = worldline_raw t \\<sigma> \\<theta> def \\<tau>'\"\n  hence s: \"t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> <Bguarded g s1 s2 , \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\" and w: \"w = worldline_raw t \\<sigma> \\<theta> def \\<tau>\"\n    and c: \"context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>\" and p: \"P w\" and w': \"w' = worldline_raw t \\<sigma> \\<theta> def \\<tau>'\" and\n      \"All (non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma>)\" and \"All (non_stuttering (to_trans_raw_sig \\<theta>) def)\"\n    by auto\n  obtain x where \"t, \\<sigma>, \\<gamma>, \\<theta>, def \\<turnstile> g \\<longrightarrow>\\<^sub>b x\"\n    using s by (metis seq_cases_bguarded)\n  hence \"is_Bv x\"\n    using beval_raw_deterministic s  by (metis seq_cases_bguarded val.discI(1))\n  have \"bval_of x \\<or> \\<not> bval_of x\"\n    by auto\n  moreover\n  { assume \"bval_of x \"\n    hence \\<tau>'_def: \"t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> < s1 , \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\"\n      using s \\<open>is_Bv x\\<close> \\<open>t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> g \\<longrightarrow>\\<^sub>b x\\<close> beval_raw_deterministic val.collapse(1)\n      by (metis seq_cases_bguarded val.inject(1))\n    have \"beval_world_raw w t g x\"\n      using `bval_of x` beval_beval_world_raw[OF w] c unfolding context_invariant_def\n      using \\<open>t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> g \\<longrightarrow>\\<^sub>b x\\<close>\n      by (simp add: \\<open>All (non_stuttering (to_trans_raw_sig \\<theta>) def)\\<close>)\n    with `P w` have \" Q w'\"\n      using assms(1) c w \\<tau>'_def w' \\<open>All (non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma>)\\<close>\n      \\<open>All (non_stuttering (to_trans_raw_sig \\<theta>) def)\\<close>\n      unfolding seq_hoare_valid_def  using \\<open>bval_of x\\<close>  by metis }\n  moreover\n  { assume \"\\<not> bval_of x\"\n    hence \\<tau>'_def: \"t, \\<sigma>, \\<gamma>, \\<theta>, def \\<turnstile> < s2, \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\"\n      using s \\<open>is_Bv x\\<close> \\<open>t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> g \\<longrightarrow>\\<^sub>b x\\<close> beval_raw_deterministic val.collapse(1)\n      by (metis dual_order.irrefl less_irrefl neq_iff seq_cases_bguarded val.sel(1))\n    have \"beval_world_raw w t g x\"\n      using `\\<not> bval_of x` beval_beval_world_raw[OF w] c unfolding context_invariant_def\n      using \\<open>t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> g \\<longrightarrow>\\<^sub>b x\\<close> \\<open>All (non_stuttering (to_trans_raw_sig \\<theta>) def)\\<close>\n      by auto\n    with `P w` have \"Q w'\"\n      using assms(2) c w \\<tau>'_def w' \\<open>All (non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma>)\\<close>\n      unfolding seq_hoare_valid_def  using \\<open>\\<not> bval_of x\\<close> \\<open>All (non_stuttering (to_trans_raw_sig \\<theta>) def)\\<close>\n      by metis }\n  ultimately show \"Q w'\" by auto\nqed\n\nlemma lift_trans_post_worldline_upd:\n  assumes \"\\<omega> = worldline_raw t \\<sigma> \\<theta> def \\<tau>\"\n  assumes \"beval_world_raw \\<omega> t exp x\"\n  assumes \\<tau>'_def: \"\\<tau>' = trans_post_raw sig x (\\<sigma> sig) \\<tau> t dly\"\n  assumes \"\\<forall>i < t. \\<tau> i = 0\"\n  assumes \"0 < dly\"\n  shows \"worldline_raw t \\<sigma> \\<theta> def \\<tau>' = \\<omega>[sig, t + dly := x]\"\nproof (rule, rule_tac[2] ext, rule_tac[2] ext)\n  fix s' t'\n  have \"t' < t \\<or> t' \\<ge> t\" by auto\n  moreover\n  { assume \"t' < t\"\n    hence 0: \" snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' =  signal_of (def s') \\<theta> s' t'\"\n      unfolding worldline_raw_def by auto\n    have \"t' < t + dly\"\n      using `t' < t` by auto\n    hence \"snd (\\<omega>[sig, t + dly := x]) s' t' = snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>) s' t'\"\n      unfolding `\\<omega> = worldline_raw t \\<sigma> \\<theta> def \\<tau>` worldline_upd_def by auto\n    also have \"... = signal_of (def s') \\<theta> s' t'\"\n      using `t' < t` unfolding worldline_raw_def by auto\n    finally have \"snd (\\<omega>[sig, t + dly := x]) s' t' = signal_of (def s') \\<theta> s' t'\"\n      by auto\n    hence \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (\\<omega>[sig, t + dly := x]) s' t'\"\n      using 0 by auto }\n  moreover\n  { assume \"t' \\<ge> t\"\n    hence 0: \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = signal_of (\\<sigma> s') \\<tau>' s' t'\"\n      unfolding worldline_raw_def by auto\n    have \"t' < t + dly \\<or> t' \\<ge> t + dly\"\n      by auto\n    moreover\n    { assume \"t' < t + dly\"\n      have \"snd (\\<omega>[sig, t + dly := x]) s' t' = snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>) s' t'\"\n        using `t' < t + dly` unfolding `\\<omega> = worldline_raw t \\<sigma> \\<theta> def \\<tau>` worldline_upd_def by auto\n      also have \"... = signal_of (\\<sigma> s') \\<tau> s' t'\"\n        using `t' \\<ge> t` unfolding worldline_raw_def by auto\n      finally have 1: \"snd (\\<omega>[sig, t + dly := x]) s' t' = signal_of (\\<sigma> s') \\<tau> s' t'\"\n        by auto\n      have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = signal_of (\\<sigma> s') \\<tau>' s' t'\"\n        using `t' \\<ge> t` unfolding worldline_raw_def by auto\n      also have \"... = signal_of (\\<sigma> s') \\<tau> s' t'\"\n        using signal_of_trans_post2[OF `t' < t + dly`] unfolding \\<tau>'_def by metis\n      also have \"... = snd (\\<omega>[sig, t + dly := x]) s' t'\"\n        using 1 by auto\n      finally have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (\\<omega>[sig, t + dly := x]) s' t'\"\n        by auto }\n    moreover\n    { assume \"t' \\<ge> t + dly\"\n      have \"s' = sig \\<or> s' \\<noteq> sig\" by auto\n      moreover\n      { assume \"s' = sig\"\n        hence 2: \"beval_world_raw (worldline_raw t \\<sigma> \\<theta> def \\<tau>) t exp (snd (\\<omega>[sig, t + dly := x]) s' t')\"\n          using `t' \\<ge> t + dly` `\\<omega> = worldline_raw t \\<sigma> \\<theta> def \\<tau>` worldline_upd_def\n          by (smt assms(2) le_eq_less_or_eq not_less_iff_gr_or_eq snd_conv)\n        have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = signal_of (\\<sigma> s') \\<tau>' s' t'\"\n          using `t' \\<ge> t` unfolding worldline_raw_def by auto\n        moreover have \"beval_world_raw (worldline_raw t \\<sigma> \\<theta> def \\<tau>) t exp (signal_of (\\<sigma> s') \\<tau>' s' t')\"\n          using signal_of_trans_post3[OF `t + dly \\<le> t'`, of _ \"\\<sigma> s'\" \"sig\"] \\<tau>'_def\n          `\\<omega> = worldline_raw t \\<sigma> \\<theta> def \\<tau>` \\<open>s' = sig\\<close> assms(2-5)  by auto\n        ultimately have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (\\<omega>[sig, t + dly := x]) s' t' \"\n          using 2 beval_world_raw_deterministic by metis }\n      moreover\n      { assume \"s' \\<noteq> sig\"\n        hence \"sig \\<noteq> s'\" by auto\n        hence \"snd (\\<omega>[sig, t + dly := x]) s' t' = snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>) s' t'\"\n          unfolding `\\<omega> = worldline_raw t \\<sigma> \\<theta> def \\<tau>` worldline_upd_def  by auto\n        also have \"... = signal_of (\\<sigma> s') \\<tau> s' t'\"\n          using `t' \\<ge> t` unfolding worldline_raw_def by auto\n        finally have 3: \"snd (\\<omega>[sig, t + dly := x]) s' t' = signal_of (\\<sigma> s') \\<tau> s' t'\"\n          by auto\n        have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = signal_of (\\<sigma> s') \\<tau>' s' t'\"\n          using `t' \\<ge> t` unfolding worldline_raw_def by auto\n        also have \"... = signal_of (\\<sigma> s') \\<tau> s' t'\"\n          unfolding \\<tau>'_def using signal_of_trans_post[OF `sig \\<noteq> s'`] by metis\n        also have \"... = snd (\\<omega>[sig, t + dly := x]) s' t'\"\n          using 3 by auto\n        finally have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (\\<omega>[sig, t + dly := x]) s' t' \"\n          by auto }\n      ultimately have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (\\<omega>[sig, t + dly := x]) s' t' \"\n        by auto }\n    ultimately have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (\\<omega>[sig, t + dly := x]) s' t' \"\n      by auto }\n  ultimately show \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (\\<omega>[sig, t + dly := x]) s' t'\"\n    by auto\nqed (simp add: assms(1) worldline_raw_def worldline_upd_def)\n\nlemma Bassign_trans_sound:\n  assumes \"0 < dly\"\n  shows \"\\<turnstile>\\<^sub>t {P} Bassign_trans sig exp dly {Q} \\<Longrightarrow> \\<Turnstile>\\<^sub>t {P} Bassign_trans sig exp dly {Q}\"\nproof -\n  assume \"\\<turnstile>\\<^sub>t {P} Bassign_trans sig exp dly {Q}\"\n  hence imp: \"\\<forall>w. P w \\<longrightarrow> (\\<exists>x. beval_world_raw w t exp x \\<and> Q (w[sig, t + dly := x]))\"\n    by (auto dest!: BassignE)\n  { fix \\<sigma> :: \"'a state\"\n    fix \\<tau> \\<tau>' \\<theta> :: \"'a trans_raw\"\n    fix w w' :: \"'a worldline_init\"\n    fix \\<gamma> def\n    assume \"context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>\"\n    hence \"\\<forall>n. n \\<le> t \\<longrightarrow>  \\<tau> n = 0\"\n      unfolding context_invariant_def by auto\n    assume \"w = worldline_raw t \\<sigma> \\<theta> def \\<tau>\"\n    assume \"P w\"\n    assume \"All (non_stuttering (to_trans_raw_sig \\<theta>) def)\"\n    assume \"t, \\<sigma>, \\<gamma>, \\<theta>, def \\<turnstile> <Bassign_trans sig exp dly, \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\"\n    then obtain x where \"beval_raw t \\<sigma> \\<gamma> \\<theta> def exp x\" and \"\\<tau>' = trans_post_raw sig x (\\<sigma> sig) \\<tau> t dly\"\n      by (metis seq_cases_trans)\n    moreover have \"beval_raw t \\<sigma> \\<gamma> \\<theta> def exp = beval_world_raw w t exp\"\n      using `w = worldline_raw t \\<sigma> \\<theta> def \\<tau>` \\<open>context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>\\<close> beval_beval_world_raw_ci\n      \\<open>All (non_stuttering (to_trans_raw_sig \\<theta>) def)\\<close> by blast\n    ultimately have \\<tau>'_def: \"\\<tau>' = trans_post_raw sig x (\\<sigma> sig) \\<tau> t dly\"\n      by auto\n    have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') = snd (w[sig, t + dly := x])\"\n      using \\<open>w = worldline_raw t \\<sigma> \\<theta> def \\<tau>\\<close> \\<tau>'_def lift_trans_post_worldline_upd `\\<forall>n. n \\<le> t \\<longrightarrow> \\<tau> n = 0` `0 < dly`\n      by (metis \\<open>beval_raw t \\<sigma> \\<gamma> \\<theta> def exp = beval_world_raw w t exp\\<close> \\<open>t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> exp \\<longrightarrow>\\<^sub>b x\\<close> less_imp_le_nat)\n    with imp and `P w` have \"Q(w[sig, t + dly := x])\"\n      by (metis (full_types) \\<open>beval_raw t \\<sigma> \\<gamma> \\<theta> def exp = beval_world_raw w t exp\\<close> \\<open>t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> exp \\<longrightarrow>\\<^sub>b x\\<close> beval_world_raw_deterministic)\n    assume \"w' = worldline_raw t \\<sigma> \\<theta> def \\<tau>'\"\n    hence \"Q w'\"\n      using `Q(w[sig, t + dly := x])` `snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') = snd (w[sig, t + dly := x])`\n      by (simp add: \\<open>w = worldline_raw t \\<sigma> \\<theta> def \\<tau>\\<close> worldline_raw_def worldline_upd_def) }\n  thus \" \\<Turnstile>\\<^sub>t {P} Bassign_trans sig exp dly {Q}\"\n    unfolding seq_hoare_valid_def  by meson\nqed\n\nlemma lift_inr_post_worldline_upd:\n  assumes \"\\<omega> = worldline_raw t \\<sigma> \\<theta> def \\<tau>\"\n  assumes \"context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>\"\n  assumes \"t, \\<sigma>, \\<gamma>, \\<theta>, def \\<turnstile> <Bassign_inert sig exp dly, \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\"\n  assumes \"0 < dly\"\n  assumes \"non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma> sig\"\n  assumes \"All (non_stuttering (to_trans_raw_sig \\<theta>) def)\"\n  assumes \"beval_world_raw \\<omega> t exp (Bv v)\"\n  shows \"worldline_raw t \\<sigma> \\<theta> def \\<tau>' = worldline_inert_upd2 \\<omega> sig t dly (Bv v)\"\nproof (rule, rule_tac[2] ext, rule_tac[2] ext)\n  fix s' t'\n  have \"beval_raw t \\<sigma> \\<gamma> \\<theta> def exp (Bv v)\"\n    using assms beval_beval_world_raw_ci by metis\n  have \"\\<tau>' = inr_post_raw' sig (Bv v) (\\<sigma> sig) \\<tau> t dly\"\n    using assms(3) \\<open>t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> exp \\<longrightarrow>\\<^sub>b(Bv v)\\<close> beval_raw_deterministic  by (metis seq_cases_inert)\n  moreover have \"beval_raw t \\<sigma> \\<gamma> \\<theta> def exp = beval_world_raw \\<omega> t exp\"\n    using `\\<omega> = worldline_raw t \\<sigma> \\<theta> def \\<tau> ` and `context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>`\n    by (simp add: assms(6) beval_beval_world_raw_ci)\n  hence \\<tau>'_def: \"\\<tau>' = inr_post_raw' sig(Bv v) (\\<sigma> sig) \\<tau> t dly\"\n    by (simp add: calculation)\n  have \"context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>'\"\n    using b_seq_exec_preserves_context_invariant[OF assms(2-3)] `0 < dly` by auto\n\n  have \"\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\"\n    using assms(2) unfolding context_invariant_def by auto\n  have \"s' \\<noteq> sig \\<or> t' < t \\<or> s' = sig \\<and> t \\<le> t'\"\n    by auto\n  moreover\n  { assume \"s' \\<noteq> sig \\<or> t' < t\"\n    moreover\n    { assume \"t' < t\"\n      hence 0: \" snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' =  signal_of (def s') \\<theta> s' t'\"\n        unfolding worldline_raw_def by auto\n      have \"t' < t + dly\"\n        using `t' < t` by auto\n      hence \"snd (\\<omega>[sig, t,  dly :=(Bv v)]) s' t' = snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>) s' t'\"\n        unfolding `\\<omega> = worldline_raw t \\<sigma> \\<theta> def \\<tau>` worldline_inert_upd_def  by (simp add: \\<open>t' < t\\<close>)\n      also have \"... = signal_of (def s') \\<theta> s' t'\"\n        using `t' < t` unfolding worldline_raw_def by auto\n      finally have \"snd (\\<omega>[sig, t, dly :=(Bv v)]) s' t' = signal_of (def s') \\<theta> s' t'\"\n        by auto\n      hence \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (\\<omega>[sig, t, dly :=(Bv v)]) s' t'\"\n        using 0 by auto }\n    moreover\n    { assume \"s' \\<noteq> sig\"\n      hence \"snd (\\<omega>[sig, t, dly :=(Bv v)]) s' t' = snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>) s' t'\"\n        unfolding worldline_inert_upd_def `\\<omega> = worldline_raw t \\<sigma> \\<theta> def \\<tau>` by auto\n      also have \"... = snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t'\"\n      proof -\n        have \"\\<And>n. (to_trans_raw_sig \\<tau> s') n = (to_trans_raw_sig \\<tau>' s') n\"\n          using `s' \\<noteq> sig` unfolding \\<tau>'_def inr_post_raw'_def\n          by (metis purge_raw_does_not_affect_other_sig' to_trans_raw_sig_def trans_post_raw_diff_sig)\n        hence \"signal_of (\\<sigma> s') \\<tau> s' t' = signal_of (\\<sigma> s') \\<tau>'  s' t'\"\n          by (meson signal_of_equal_when_trans_sig_equal_upto)\n        thus ?thesis\n          unfolding worldline_raw_def by auto\n      qed\n      finally have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (\\<omega>[sig, t, dly :=(Bv v)]) s' t'\"\n        by auto }\n    ultimately have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (\\<omega>[sig, t, dly := Bv v]) s' t'\"\n      by auto }\n  moreover\n  { assume \"s' = sig \\<and> t \\<le> t'\"\n    have \"(snd \\<omega> sig t = (Bv v) \\<or> snd \\<omega> sig (t + dly) \\<noteq> (Bv v)) \\<or> (snd \\<omega> sig t \\<noteq> (Bv v) \\<and> snd \\<omega> sig (t + dly) = (Bv v))\"\n      by auto\n    moreover\n    { assume \"snd \\<omega> sig t = (Bv v) \\<or> snd \\<omega> sig (t + dly) \\<noteq> (Bv v)\"\n      have \"t + dly \\<le> t' \\<or> t' < t + dly\" and \"s' = sig\" and \"t \\<le> t'\"\n        using leI \\<open>s' = sig \\<and> t \\<le> t'\\<close> by auto\n      moreover\n      { assume \"t + dly \\<le> t'\"\n        hence 2: \"beval_world_raw (worldline_raw t \\<sigma> \\<theta> def \\<tau>) t exp (snd (\\<omega>[sig, t, dly := (Bv v)]) s' t')\"\n            using `s' = sig`  `\\<omega> = worldline_raw t \\<sigma> \\<theta> def \\<tau>` worldline_inert_upd_def\n            using \\<open>snd \\<omega> sig t = (Bv v) \\<or> snd \\<omega> sig (t + dly) \\<noteq> (Bv v)\\<close> assms(1)\n            by (smt \\<open>s' = sig \\<and> t \\<le> t'\\<close> assms(7) not_le snd_conv)\n        have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = signal_of (\\<sigma> s') \\<tau>' s' t'\"\n          using `t' \\<ge> t` unfolding worldline_raw_def by auto\n        hence \"beval_world_raw (worldline_raw t \\<sigma> \\<theta> def \\<tau>) t exp (signal_of (\\<sigma> s') \\<tau>' s' t')\"\n          using signal_of_inr_post'[OF `t + dly \\<le> t'`, of _ \"\\<sigma> s'\" \"sig\"]  \\<tau>'_def\n          `\\<omega> = worldline_raw t \\<sigma> \\<theta> def \\<tau>`  using \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> \\<open>s' = sig \\<and> t \\<le> t'\\<close> `0 < dly`\n          assms(7) by auto\n        hence \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (\\<omega>[sig, t, dly := (Bv v)]) s' t' \"\n          using 2 \\<open>snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = signal_of (\\<sigma> s') \\<tau>' s' t'\\<close>\n          beval_world_raw_deterministic by metis }\n      moreover\n      { assume \"t' < t + dly\"\n        hence \"snd (\\<omega>[sig, t, dly := (Bv v)]) s' t' = snd \\<omega> sig t\"\n          unfolding worldline_inert_upd_def using `s' = sig`  using \\<open>s' = sig \\<and> t \\<le> t'\\<close>\n          using \\<open>snd \\<omega> sig t = (Bv v) \\<or> snd \\<omega> sig (t + dly) \\<noteq> (Bv v)\\<close> by auto\n        also have \"... = signal_of (\\<sigma> sig) \\<tau> sig t\"\n          unfolding `\\<omega> = worldline_raw t \\<sigma> \\<theta> def \\<tau>` worldline_raw_def by auto\n        also have \"... = \\<sigma> sig\"\n        proof -\n          have True: \"\\<tau> t sig = None\"\n            using `\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0` by (auto simp add: zero_fun_def zero_option_def)\n          have \"\\<And>k. k \\<in>dom ((to_trans_raw_sig \\<tau> sig)) \\<Longrightarrow> t < k\"\n          proof (rule ccontr)\n            fix k\n            assume in_dom: \"k \\<in>dom ((to_trans_raw_sig \\<tau> sig))\"\n            assume \"\\<not> t < k\" hence \"k \\<le> t\" by auto\n            hence \"\\<tau> k sig = None\"\n              using `\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0` True  by (metis dual_order.antisym leI zero_fun_def zero_option_def)\n            hence \"k \\<notin> dom ((to_trans_raw_sig \\<tau> sig))\"\n              unfolding to_trans_raw_sig_def by auto\n            with in_dom show \"False\" by auto\n          qed\n          hence \"Femto_VHDL_raw.inf_time (to_trans_raw_sig \\<tau>) sig t = None\"\n            by (meson inf_time_none_iff)\n          then show ?thesis\n            unfolding Femto_VHDL_raw.to_signal_def comp_def by auto\n        qed\n        finally have l: \"snd (\\<omega>[sig, t, dly := (Bv v)]) s' t' = \\<sigma> sig\"\n          by auto\n        have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = signal_of (\\<sigma> s') \\<tau>' s' t'\"\n          unfolding worldline_raw_def using `s' = sig \\<and> t \\<le> t'` by auto\n        also have \"... = \\<sigma> s'\"\n        proof -\n          have 0: \"signal_of (\\<sigma> s') \\<tau> s' t = (Bv v) \\<or> signal_of (\\<sigma> s') \\<tau> s' (t + dly) \\<noteq> (Bv v)\"\n            using `snd \\<omega> sig t = (Bv v) \\<or> snd \\<omega> sig (t + dly) \\<noteq> (Bv v)` \\<open>s' = sig\\<close>\n            unfolding assms(1) worldline_raw_def by auto\n          thus ?thesis\n            using signal_of_inr_post3[OF `t \\<le> t'` `t' < t + dly` `\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0`] \\<open>s' = sig\\<close>\n            unfolding \\<tau>'_def inr_post_raw'_eq_inr_post_raw\n            by (meson \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> \\<open>s' = sig \\<and> t \\<le> t'\\<close> \\<open>t' < t + dly\\<close> signal_of_inr_post3)\n        qed\n        finally have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = \\<sigma> s'\"\n          by auto\n        with l have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (\\<omega>[sig, t, dly := (Bv v)]) s' t' \"\n          using `s' = sig` by auto }\n      ultimately have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (\\<omega>[sig, t, dly := (Bv v)]) s' t' \"\n        by auto }\n    moreover\n    { assume \"snd \\<omega> sig t \\<noteq> (Bv v) \\<and> snd \\<omega> sig (t + dly) = (Bv v)\"\n      hence sig_not_eq: \"signal_of (\\<sigma> sig) \\<tau> sig t \\<noteq> (Bv v)\" and  sig_eq: \"signal_of (\\<sigma> sig) \\<tau> sig (t + dly) = (Bv v)\"\n        unfolding assms(1) worldline_raw_def by auto\n      hence exist_mapping: \"\\<exists>k > t. k\\<le>t + dly \\<and> \\<tau> k sig = Some (Bv v)\"\n        using switch_signal_ex_mapping[of \"\\<sigma>\", OF sig_not_eq] `\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0`\n        by (simp add: zero_fun_def)\n      let ?time = \"GREATEST n. n \\<le> t + dly \\<and> (snd \\<omega> sig (n - 1) \\<noteq> (Bv v)) \\<and> snd \\<omega> sig n = (Bv v)\"\n      have \"?time \\<le> t' \\<or> t' < ?time\" and \"s' = sig\" and \"t \\<le> t'\"\n        using \\<open>s' = sig \\<and> t \\<le> t'\\<close> by auto\n      moreover\n      { assume \"?time \\<le> t'\"\n        hence 2: \"beval_world_raw (worldline_raw t \\<sigma> \\<theta> def \\<tau>) t exp (snd (\\<omega>[sig, t, dly := (Bv v)]) s' t')\"\n            using `s' = sig` unfolding `\\<omega> = worldline_raw t \\<sigma> \\<theta> def \\<tau>` worldline_inert_upd_def\n            using \\<open>snd \\<omega> sig t \\<noteq> (Bv v) \\<and> snd \\<omega> sig (t + dly) = (Bv v)\\<close>\n            \\<open>s' = sig \\<and> t \\<le> t'\\<close> assms(1)  using assms(7) by auto\n        have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = signal_of (\\<sigma> s') \\<tau>' s' t'\"\n          using `t' \\<ge> t` unfolding worldline_raw_def by auto\n        also have \"... = (Bv v)\"\n          unfolding \\<tau>'_def \\<open>s' = sig\\<close> inr_post_raw'_eq_inr_post_raw\n        proof (rule signal_of_inr_post4)\n          show \"signal_of (\\<sigma> sig) \\<tau> sig t \\<noteq> (Bv v)\"\n            using \\<open>snd \\<omega> sig t \\<noteq> (Bv v) \\<and> snd \\<omega> sig (t + dly) = (Bv v)\\<close>\n            by (simp add: assms(1) worldline_raw_def)\n        next\n          show \"signal_of (\\<sigma> sig) \\<tau> sig (t + dly) = (Bv v)\"\n            using \\<open>snd \\<omega> sig t \\<noteq> (Bv v) \\<and> snd \\<omega> sig (t + dly) = (Bv v)\\<close>\n            by (simp add: assms(1) worldline_raw_def)\n        next\n          have \"?time = (GREATEST n. n \\<le> t + dly \\<and> \\<tau> n sig = Some (Bv v))\" (is \"_ = ?time2\")\n          proof (rule Greatest_equality)\n            have \"?time2 \\<le> t + dly\" and \"\\<tau> ?time2 sig = Some (Bv v)\"\n              using GreatestI_ex_nat[where P=\"\\<lambda>n. n \\<le> t + dly \\<and> \\<tau> n sig = Some (Bv v)\" and b=\"t + dly\"]\n              exist_mapping by auto\n            have \"t < ?time2\"\n              by (metis (no_types, lifting) \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close>\n                 \\<open>\\<tau> (GREATEST n. n \\<le> t + dly \\<and> \\<tau> n sig = Some (Bv v)) sig = Some (Bv v)\\<close> leI\n              option.distinct(1) zero_fun_def zero_option_def)\n            have \"signal_of (\\<sigma> sig) \\<tau> sig ?time2 = (Bv v)\"\n              using trans_some_signal_of'[of \"\\<tau>\", OF `\\<tau> ?time2 sig = Some (Bv v)`]\n              by auto\n            hence \"snd \\<omega> sig ?time2 = (Bv v)\"\n              using `t < ?time2` unfolding assms(1) worldline_raw_def by auto\n            have \"signal_of (\\<sigma> sig) \\<tau> sig (?time2 - 1) \\<noteq> (Bv v)\"\n            proof (cases \"\\<exists>n. t < n \\<and> n < ?time2 \\<and> \\<tau> n sig \\<noteq> None\")\n              case False\n              hence none: \"\\<And>n. t < n \\<Longrightarrow> n \\<le> ?time2 - 1 \\<Longrightarrow> \\<tau> n sig = 0\"\n                by (auto simp add: zero_option_def)\n              have \"signal_of (\\<sigma> sig) \\<tau> sig (?time2 - 1) = signal_of (\\<sigma> sig) \\<tau> sig t\"\n                using signal_of_less_ind'[of \"t\" \"?time2 - 1\" \"\\<tau>\" \"sig\", OF none] `t < ?time2`\n                by auto\n              also have \"... \\<noteq> (Bv v)\"\n                using sig_not_eq by auto\n              finally show \"signal_of (\\<sigma> sig) \\<tau> sig (?time2 - 1) \\<noteq> (Bv v)\"\n                by auto\n            next\n              case True\n              let ?key1 = \"(GREATEST n. t < n \\<and> n < ?time2 \\<and> \\<tau> n sig \\<noteq> None)\"\n              from True have \"t < ?key1\" and \"?key1 < ?time2\" and \"\\<tau> ?key1 sig \\<noteq> None\"\n                using GreatestI_ex_nat[OF True]  using less_imp_le_nat by blast+\n              have *: \"\\<And>n. n > ?key1 \\<Longrightarrow> n < ?time2 \\<Longrightarrow> \\<tau> n sig = None\"\n                using Greatest_le_nat[where P=\"\\<lambda>x. t < x \\<and> x < ?time2 \\<and> \\<tau> x sig \\<noteq> None\" and b=\"?time2\"]\n                by (smt \\<open>t < (GREATEST n. t < n \\<and> n < (GREATEST n. n \\<le> t + dly \\<and> \\<tau> n sig = Some (Bv v)) \\<and>\n                \\<tau> n sig \\<noteq> None)\\<close> leD less_imp_le_nat less_trans)\n              have inf_some: \"inf_time (to_trans_raw_sig \\<tau>) sig (?time2 - 1) = Some ?key1\"\n              proof (rule inf_time_someI)\n                show \"?key1 \\<in> dom (to_trans_raw_sig \\<tau> sig)\"\n                  using `\\<tau> ?key1 sig \\<noteq> None`  by (simp add: domIff to_trans_raw_sig_def)\n              next\n                show \"?key1 \\<le> ?time2 - 1\"\n                  using `?key1 < ?time2`  by linarith\n              next\n                { fix ta\n                  assume \"ta \\<in> dom (to_trans_raw_sig \\<tau> sig)\"\n                  assume \"ta \\<le> ?time2 - 1\"\n                  assume \"?key1 < ta\"\n                  hence \"\\<tau> ta sig = None\"\n                    using *[OF `?key1 < ta`] `ta \\<le> ?time2 - 1` by simp\n                  hence \"ta \\<notin> dom (to_trans_raw_sig \\<tau> sig)\"\n                    by (simp add: domIff to_trans_raw_sig_def)\n                  with `ta \\<in> dom (to_trans_raw_sig \\<tau> sig)` have False by auto }\n                thus \"\\<forall>ta \\<in> dom (to_trans_raw_sig \\<tau> sig). ta \\<le> ?time2 - 1 \\<longrightarrow> ta \\<le> ?key1\"\n                  using not_le_imp_less by blast\n              qed\n              have \"\\<tau> ?key1 sig \\<noteq> \\<tau> ?time2 sig\"\n              proof -\n                have \"?key1 \\<in> keys (to_trans_raw_sig \\<tau> sig)\"\n                  using `\\<tau> ?key1 sig \\<noteq> None`  by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n                moreover have \"?time2 \\<in> keys (to_trans_raw_sig \\<tau> sig)\"\n                  using `\\<tau> ?time2 sig = Some (Bv v)`\n                  by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n                moreover have \"\\<forall>k. ?key1 < k \\<and> k < ?time2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig \\<tau> sig)\"\n                  using *  by (metis (mono_tags, lifting) domIff keys_def mem_Collect_eq to_trans_raw_sig_def\n                  zero_option_def)\n                ultimately show ?thesis\n                  using `?key1 < ?time2` assms(5) unfolding non_stuttering_def\n                  by (simp add: to_trans_raw_sig_def)\n              qed\n              hence \"\\<tau> ?key1 sig \\<noteq> Some (Bv v)\"\n                using \\<open>\\<tau> (GREATEST n. n \\<le> t + dly \\<and> \\<tau> n sig = Some (Bv v)) sig = Some (Bv v)\\<close>\n                      \\<open>\\<tau> (GREATEST n. t < n \\<and> n < (GREATEST n. n \\<le> t + dly \\<and> \\<tau> n sig = Some (Bv v)) \\<and> \\<tau> n sig \\<noteq> None) sig \\<noteq> None\\<close> by auto\n              thus ?thesis\n                unfolding to_signal_def comp_def using inf_some\n                by (metis (no_types, lifting) \\<open>\\<tau> (GREATEST n. t < n \\<and> n < (GREATEST n. n \\<le> t + dly \\<and>\n                \\<tau> n sig = Some (Bv v)) \\<and> \\<tau> n sig \\<noteq> None) sig \\<noteq> None\\<close> not_None_eq option.sel\n                option.simps(5) to_trans_raw_sig_def)\n            qed\n            hence \"snd \\<omega> sig (?time2 - 1) \\<noteq>  (Bv v)\"\n              using `t < ?time2` unfolding assms(1) worldline_raw_def  by (simp add: leD)\n            thus \"?time2 \\<le> t + dly \\<and> snd \\<omega> sig (?time2 - 1) \\<noteq> (Bv v) \\<and> snd \\<omega> sig ?time2 = (Bv v)\"\n              using \\<open>(GREATEST n. n \\<le> t + dly \\<and> \\<tau> n sig = Some (Bv v)) \\<le> t + dly\\<close>\n              \\<open>snd \\<omega> sig (GREATEST n. n \\<le> t + dly \\<and> \\<tau> n sig = Some (Bv v)) = (Bv v)\\<close> by blast\n          next\n            fix y\n            assume \"y \\<le> t + dly \\<and> snd \\<omega> sig (y - 1) \\<noteq> (Bv v) \\<and> snd \\<omega> sig y = (Bv v)\"\n            hence \"y \\<le> t + dly\" and \"snd \\<omega> sig (y - 1) \\<noteq> (Bv v)\" and \"snd \\<omega> sig y = (Bv v)\"\n              by auto\n            have \"?time2 \\<le> t + dly\" and \"\\<tau> ?time2 sig = Some (Bv v)\"\n              using GreatestI_ex_nat[where P=\"\\<lambda>n. n \\<le> t + dly \\<and> \\<tau> n sig = Some (Bv v)\" and b=\"t + dly\"]\n              exist_mapping by auto\n            hence \"t < ?time2\"\n              by (metis (no_types, lifting) \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> leI\n              option.distinct(1) zero_fun_def zero_option_def)\n            have \"y \\<le> t \\<or> t < y\"\n              by auto\n            moreover\n            { assume \"y \\<le> t\"\n              hence \"y < ?time2\"\n                using `t < ?time2` by linarith }\n            moreover\n            { assume \"t < y\"\n              hence \"snd \\<omega> sig (y - 1) = signal_of (\\<sigma> sig) \\<tau> sig (y - 1)\"\n                unfolding assms(1) worldline_raw_def by auto\n              hence 0: \"... \\<noteq> (Bv v)\"\n                using `snd \\<omega> sig (y - 1) \\<noteq> (Bv v)` by auto\n              have \"snd \\<omega> sig y = signal_of (\\<sigma> sig) \\<tau> sig y\"\n                unfolding assms(1) worldline_raw_def using `t < y` by auto\n              hence 1: \"... = (Bv v)\"\n                using `snd \\<omega> sig y = (Bv v)` `t < y` by auto\n              have \"\\<tau> y sig = Some (Bv v)\"\n              proof (rule ccontr)\n                assume \"\\<not> \\<tau> y sig = Some (Bv v)\"\n                then obtain x' where \"\\<tau> y sig = None \\<or> \\<tau> y sig = Some x' \\<and> x' \\<noteq> (Bv v)\"\n                  using domIff by fastforce\n                moreover\n                { assume \"\\<tau> y sig = None\"\n                  hence \"signal_of (\\<sigma> sig) \\<tau> sig y = signal_of (\\<sigma> sig) \\<tau> sig (y - 1)\"\n                    by (intro signal_of_less_sig)(simp add: zero_option_def)\n                  with 0 1 have False by auto }\n                moreover\n                { assume \"\\<tau> y sig = Some x' \\<and> x' \\<noteq> (Bv v)\"\n                  hence \"signal_of (\\<sigma> sig) \\<tau> sig y = x'\" and \"x' \\<noteq> (Bv v)\"\n                    using trans_some_signal_of' by fastforce+\n                  with 1 have False by auto }\n                ultimately show False by auto\n              qed\n              with `y \\<le> t + dly` have \"y \\<le> ?time2\"\n                by (metis (mono_tags, lifting) Greatest_le_nat) }\n            ultimately show \"y \\<le> ?time2\"\n              by auto\n          qed\n          thus \"(GREATEST n. n \\<le> t + dly \\<and> \\<tau> n sig = Some (Bv v)) \\<le> t'\"\n            using \\<open>(GREATEST n. n \\<le> t + dly \\<and> snd \\<omega> sig (n - 1) \\<noteq> Bv v \\<and> snd \\<omega> sig n = Bv v) \\<le> t'\\<close> by linarith\n        next\n          show \"\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\"\n            using \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> by auto\n        qed\n        hence \"beval_world_raw (worldline_raw t \\<sigma> \\<theta> def \\<tau>) t exp (Bv v)\"\n          using assms(1) assms(7) by metis\n        hence \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (\\<omega>[sig, t, dly := (Bv v)]) s' t' \"\n          using 2  by (metis \\<open>signal_of (\\<sigma> s') \\<tau>' s' t' = (Bv v)\\<close> beval_world_raw_deterministic calculation) }\n      moreover\n      { assume \" t' < ?time\"\n        hence \"snd (\\<omega>[sig, t, dly := (Bv v)]) s' t' = snd \\<omega> sig t\"\n          unfolding worldline_inert_upd_def using `s' = sig`  using \\<open>s' = sig \\<and> t \\<le> t'\\<close>\n          using \\<open>snd \\<omega> sig t \\<noteq> (Bv v) \\<and> snd \\<omega> sig (t + dly) = (Bv v)\\<close> by auto\n        also have \"... = signal_of (\\<sigma> sig) \\<tau> sig t\"\n          unfolding `\\<omega> = worldline_raw t \\<sigma> \\<theta> def \\<tau>` worldline_raw_def by auto\n        also have \"... = \\<sigma> sig\"\n        proof -\n          have True: \"\\<tau> t sig = None\"\n            using `\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0` by (auto simp add: zero_fun_def zero_option_def)\n          have \"\\<And>k. k \\<in>dom ((to_trans_raw_sig \\<tau> sig)) \\<Longrightarrow> t < k\"\n          proof (rule ccontr)\n            fix k\n            assume in_dom: \"k \\<in>dom ((to_trans_raw_sig \\<tau> sig))\"\n            assume \"\\<not> t < k\" hence \"k \\<le> t\" by auto\n            hence \"\\<tau> k sig = None\"\n              using `\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0` True  by (metis dual_order.antisym leI zero_fun_def zero_option_def)\n            hence \"k \\<notin> dom ((to_trans_raw_sig \\<tau> sig))\"\n              unfolding to_trans_raw_sig_def by auto\n            with in_dom show \"False\" by auto\n          qed\n          hence \"Femto_VHDL_raw.inf_time (to_trans_raw_sig \\<tau>) sig t = None\"\n            by (meson inf_time_none_iff)\n          then show ?thesis\n            unfolding Femto_VHDL_raw.to_signal_def comp_def by auto\n        qed\n        finally have l: \"snd (\\<omega>[sig, t, dly := (Bv v)]) s' t' = \\<sigma> sig\"\n          by auto\n        have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = signal_of (\\<sigma> s') \\<tau>' s' t'\"\n          unfolding worldline_raw_def using `s' = sig \\<and> t \\<le> t'` by auto\n        also have \"... = \\<sigma> s'\"\n          unfolding \\<tau>'_def \\<open>s' = sig\\<close> inr_post_raw'_eq_inr_post_raw\n        proof(rule signal_of_inr_post2)\n          show \"t \\<le> t'\"\n            by (simp add: \\<open>s' = sig \\<and> t \\<le> t'\\<close>)\n        next\n          show \"\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\"\n            using \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> by blast\n        next\n          show \"\\<sigma> sig \\<noteq> (Bv v)\"\n            using \\<open>snd \\<omega> sig t = signal_of (\\<sigma> sig) \\<tau> sig t\\<close> \\<open>snd \\<omega> sig t \\<noteq> (Bv v) \\<and> snd \\<omega> sig (t + dly) = (Bv v)\\<close>\n            \\<open>signal_of (\\<sigma> sig) \\<tau> sig t = \\<sigma> sig\\<close> by simp\n        next\n          show \"signal_of (\\<sigma> sig) \\<tau> sig (t + dly) = (Bv v)\"\n            using sig_eq by blast\n        next\n          have \"?time = (GREATEST n. n \\<le> t + dly \\<and> \\<tau> n sig = Some (Bv v))\" (is \"_ = ?time2\")\n          proof (rule Greatest_equality)\n            have \"?time2 \\<le> t + dly\" and \"\\<tau> ?time2 sig = Some (Bv v)\"\n              using GreatestI_ex_nat[where P=\"\\<lambda>n. n \\<le> t + dly \\<and> \\<tau> n sig = Some (Bv v)\" and b=\"t + dly\"]\n              exist_mapping by auto\n            have \"t < ?time2\"\n              by (metis (no_types, lifting) \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> \\<open>\\<tau> (GREATEST n. n \\<le> t + dly \\<and> \\<tau> n\n              sig = Some (Bv v)) sig = Some (Bv v)\\<close> leI option.distinct(1) zero_fun_def zero_option_def)\n            have \"signal_of (\\<sigma> sig) \\<tau> sig ?time2 = (Bv v)\"\n              using trans_some_signal_of'[of \"\\<tau>\", OF `\\<tau> ?time2 sig = Some (Bv v)`]\n              by auto\n            hence \"snd \\<omega> sig ?time2 = (Bv v)\"\n              using `t < ?time2` unfolding assms(1) worldline_raw_def by auto\n            have \"signal_of (\\<sigma> sig) \\<tau> sig (?time2 - 1) \\<noteq>  (Bv v)\"\n            proof (cases \"\\<exists>n. t < n \\<and> n < ?time2 \\<and> \\<tau> n sig \\<noteq> None\")\n              case False\n              hence none: \"\\<And>n. t < n \\<Longrightarrow> n \\<le> ?time2 - 1 \\<Longrightarrow> \\<tau> n sig = 0\"\n                by (auto simp add: zero_option_def)\n              have \"signal_of (\\<sigma> sig) \\<tau> sig (?time2 - 1) = signal_of (\\<sigma> sig) \\<tau> sig t\"\n                using signal_of_less_ind'[of \"t\" \"?time2 - 1\" \"\\<tau>\" \"sig\", OF none] `t < ?time2`\n                by auto\n              also have \"... \\<noteq> (Bv v)\"\n                using sig_not_eq by auto\n              finally show \"signal_of (\\<sigma> sig) \\<tau> sig (?time2 - 1) \\<noteq> (Bv v)\"\n                by auto\n            next\n              case True\n              let ?key1 = \"(GREATEST n. t < n \\<and> n < ?time2 \\<and> \\<tau> n sig \\<noteq> None)\"\n              from True have \"t < ?key1\" and \"?key1 < ?time2\" and \"\\<tau> ?key1 sig \\<noteq> None\"\n                using GreatestI_ex_nat[OF True]  using less_imp_le_nat by blast+\n              have *: \"\\<And>n. n > ?key1 \\<Longrightarrow> n < ?time2 \\<Longrightarrow> \\<tau> n sig = None\"\n                using Greatest_le_nat[where P=\"\\<lambda>x. t < x \\<and> x < ?time2 \\<and> \\<tau> x sig \\<noteq> None\" and b=\"?time2\"]\n                by (smt \\<open>t < (GREATEST n. t < n \\<and> n < (GREATEST n. n \\<le> t + dly \\<and> \\<tau> n sig = Some (Bv v)) \\<and>\n                \\<tau> n sig \\<noteq> None)\\<close> leD less_imp_le_nat less_trans)\n              have inf_some: \"inf_time (to_trans_raw_sig \\<tau>) sig (?time2 - 1) = Some ?key1\"\n              proof (rule inf_time_someI)\n                show \"?key1 \\<in> dom (to_trans_raw_sig \\<tau> sig)\"\n                  using `\\<tau> ?key1 sig \\<noteq> None`  by (simp add: domIff to_trans_raw_sig_def)\n              next\n                show \"?key1 \\<le> ?time2 - 1\"\n                  using `?key1 < ?time2`  by linarith\n              next\n                { fix ta\n                  assume \"ta \\<in> dom (to_trans_raw_sig \\<tau> sig)\"\n                  assume \"ta \\<le> ?time2 - 1\"\n                  assume \"?key1 < ta\"\n                  hence \"\\<tau> ta sig = None\"\n                    using *[OF `?key1 < ta`] `ta \\<le> ?time2 - 1` by simp\n                  hence \"ta \\<notin> dom (to_trans_raw_sig \\<tau> sig)\"\n                    by (simp add: domIff to_trans_raw_sig_def)\n                  with `ta \\<in> dom (to_trans_raw_sig \\<tau> sig)` have False by auto }\n                thus \"\\<forall>ta \\<in> dom (to_trans_raw_sig \\<tau> sig). ta \\<le> ?time2 - 1 \\<longrightarrow> ta \\<le> ?key1\"\n                  using not_le_imp_less by blast\n              qed\n              have \"\\<tau> ?key1 sig \\<noteq> \\<tau> ?time2 sig\"\n              proof -\n                have \"?key1 \\<in> keys (to_trans_raw_sig \\<tau> sig)\"\n                  using `\\<tau> ?key1 sig \\<noteq> None`  by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n                moreover have \"?time2 \\<in> keys (to_trans_raw_sig \\<tau> sig)\"\n                  using `\\<tau> ?time2 sig = Some (Bv v)`\n                  by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n                moreover have \"\\<forall>k. ?key1 < k \\<and> k < ?time2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig \\<tau> sig)\"\n                  using *  by (metis (mono_tags, lifting) domIff keys_def mem_Collect_eq to_trans_raw_sig_def\n                  zero_option_def)\n                ultimately show ?thesis\n                  using `?key1 < ?time2` assms(5) unfolding non_stuttering_def\n                  by (simp add: to_trans_raw_sig_def)\n              qed\n              hence \"\\<tau> ?key1 sig \\<noteq> Some (Bv v)\"\n                using \\<open>\\<tau> (GREATEST n. n \\<le> t + dly \\<and> \\<tau> n sig = Some (Bv v)) sig =\n                Some (Bv v)\\<close> \\<open>\\<tau> (GREATEST n. t < n \\<and> n < (GREATEST n. n \\<le> t + dly\n                \\<and> \\<tau> n sig = Some (Bv v)) \\<and> \\<tau> n sig \\<noteq> None) sig \\<noteq> None\\<close> by auto\n              thus ?thesis\n                unfolding to_signal_def comp_def using inf_some\n                by (metis (no_types, lifting) \\<open>\\<tau> (GREATEST n. t < n \\<and> n < (GREATEST n. n \\<le> t + dly \\<and>\n                \\<tau> n sig = Some (Bv v)) \\<and> \\<tau> n sig \\<noteq> None) sig \\<noteq> None\\<close> not_None_eq option.sel\n                option.simps(5) to_trans_raw_sig_def)\n            qed\n            hence \"snd \\<omega> sig (?time2 - 1) \\<noteq>  (Bv v)\"\n              using `t < ?time2` unfolding assms(1) worldline_raw_def  by (simp add: leD)\n            thus \"?time2 \\<le> t + dly \\<and> snd \\<omega> sig (?time2 - 1) \\<noteq> (Bv v) \\<and> snd \\<omega> sig ?time2 = (Bv v)\"\n              using \\<open>(GREATEST n. n \\<le> t + dly \\<and> \\<tau> n sig = Some (Bv v)) \\<le> t + dly\\<close>\n              \\<open>snd \\<omega> sig (GREATEST n. n \\<le> t + dly \\<and> \\<tau> n sig = Some (Bv v)) = (Bv v)\\<close> by blast\n          next\n            fix y\n            assume \"y \\<le> t + dly \\<and> snd \\<omega> sig (y - 1) \\<noteq> (Bv v) \\<and> snd \\<omega> sig y = (Bv v)\"\n            hence \"y \\<le> t + dly\" and \"snd \\<omega> sig (y - 1) \\<noteq> (Bv v)\" and \"snd \\<omega> sig y = (Bv v)\"\n              by auto\n            have \"?time2 \\<le> t + dly\" and \"\\<tau> ?time2 sig = Some (Bv v)\"\n              using GreatestI_ex_nat[where P=\"\\<lambda>n. n \\<le> t + dly \\<and> \\<tau> n sig = Some (Bv v)\" and b=\"t + dly\"]\n              exist_mapping by auto\n            hence \"t < ?time2\"\n              by (metis (no_types, lifting) \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> leI\n              option.distinct(1) zero_fun_def zero_option_def)\n            have \"y \\<le> t \\<or> t < y\"\n              by auto\n            moreover\n            { assume \"y \\<le> t\"\n              hence \"y < ?time2\"\n                using `t < ?time2` by linarith }\n            moreover\n            { assume \"t < y\"\n              hence \"snd \\<omega> sig (y - 1) = signal_of (\\<sigma> sig) \\<tau> sig (y - 1)\"\n                unfolding assms(1) worldline_raw_def by auto\n              hence 0: \"... \\<noteq> (Bv v)\"\n                using `snd \\<omega> sig (y - 1) \\<noteq> (Bv v)` by auto\n              have \"snd \\<omega> sig y = signal_of (\\<sigma> sig) \\<tau> sig y\"\n                unfolding assms(1) worldline_raw_def using `t < y` by auto\n              hence 1: \"... = (Bv v)\"\n                using `snd \\<omega> sig y = (Bv v)` `t < y` by auto\n              have \"\\<tau> y sig = Some (Bv v)\"\n              proof (rule ccontr)\n                assume \"\\<not> \\<tau> y sig = Some (Bv v)\"\n                then obtain x' where \"\\<tau> y sig = None \\<or> \\<tau> y sig = Some x' \\<and> x' \\<noteq> (Bv v)\"\n                  using domIff by fastforce\n                moreover\n                { assume \"\\<tau> y sig = None\"\n                  hence \"signal_of (\\<sigma> sig) \\<tau> sig y = signal_of (\\<sigma> sig) \\<tau> sig (y - 1)\"\n                    by (intro signal_of_less_sig)(simp add: zero_option_def)\n                  with 0 1 have False by auto }\n                moreover\n                { assume \"\\<tau> y sig = Some x' \\<and> x' \\<noteq> (Bv v)\"\n                  hence \"signal_of (\\<sigma> sig) \\<tau> sig y = x'\" and \"x' \\<noteq> (Bv v)\"\n                    using trans_some_signal_of' by fastforce+\n                  with 1 have False by auto }\n                ultimately show False by auto\n              qed\n              with `y \\<le> t + dly` have \"y \\<le> ?time2\"\n                by (metis (mono_tags, lifting) Greatest_le_nat) }\n            ultimately show \"y \\<le> ?time2\"\n              by auto\n          qed\n          thus \"t' < (GREATEST n. n \\<le> t + dly \\<and> \\<tau> n sig = Some (Bv v))\"\n            using \\<open>t' < (GREATEST n. n \\<le> t + dly \\<and> snd \\<omega> sig (n - 1) \\<noteq> (Bv v) \\<and> snd \\<omega> sig n = (Bv v))\\<close>\n            by linarith\n        qed\n        finally have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = \\<sigma> s'\"\n          by auto\n        with l have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (\\<omega>[sig, t, dly := (Bv v)]) s' t' \"\n          using `s' = sig` by auto }\n      ultimately have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (\\<omega>[sig, t, dly := (Bv v)]) s' t'\"\n        by auto }\n    ultimately  have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (\\<omega>[sig, t, dly := (Bv v)]) s' t'\"\n      by auto }\n  ultimately show \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (worldline_inert_upd2 \\<omega> sig t dly (Bv v)) s' t' \"\n    by (simp add: assms(1) worldline_inert_upd_def worldline_raw_def)\nqed (simp add: assms(1) worldline_inert_upd_def worldline_raw_def)\n\nlemma to_bit_signal_of_eq:\n  \"signal_of (Bv (bs ! b)) (to_trans_raw_bit (Lv sign bs) \\<tau> b sig) sig t = v \\<longleftrightarrow> to_bit b (signal_of (Lv sign bs) \\<tau> sig t) = v\"\n  by (metis (no_types, lifting) to_bit_signal_of' val.case_eq_if val.collapse(1) val.distinct(1) val.sel(3))\n\nlemma non_stuttering_to_trans_raw_bit:\n  assumes \" non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma> sig\"\n  shows   \" non_stuttering (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) (to_bit b o \\<sigma>) sig\"\n  unfolding non_stuttering_def\nproof (rule)+\n  fix k1 k2 :: nat\n  assume \"k1 < k2 \\<and>\n       k1 \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig) \\<and>\n       k2 \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig) \\<and>\n       (\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig))\"\n  hence \"k1 < k2\" and \"k1 \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\" \n    and \"k2 \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\" \n    and *: \"(\\<forall>k. k1 < k \\<and> k < k2 \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig))\"\n    by auto\n  hence \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig k1 sig \\<noteq> None\" and  \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig k2 sig \\<noteq> None\" and \"0 < k2\"\n    unfolding keys_def to_trans_raw_sig_def by (auto simp add: zero_option_def)\n  hence \"\\<tau> k2 sig \\<noteq> None\" and \"to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (k2 - 1)) \\<noteq> to_bit b (the (\\<tau> k2 sig))\"\n    unfolding to_trans_raw_bit_def by (auto split: option.splits)\n  have \" inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (k2 - 1) = Some k1\"\n  proof (rule inf_time_someI)\n    show \" k1 \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n      using \\<open> k1 \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\\<close> \n      unfolding dom_def keys_def zero_option_def by auto\n  next\n    show \"k1 \\<le> k2 - 1\" using \\<open>k1 < k2\\<close> by auto\n  next\n    show \"\\<forall>t\\<in>dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig). t \\<le> k2 - 1 \\<longrightarrow> t \\<le> k1\"\n      using * unfolding dom_def keys_def zero_option_def  using leI by force\n  qed\n  hence \" signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (k2 - 1) = \n         the (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig k1)\"\n    unfolding to_bit_signal_of'_eq[THEN sym] to_signal_def comp_def by auto\n  moreover have \" the (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig k2)  = to_bit b (the (\\<tau> k2 sig))\"\n    using \\<open>0 < k2\\<close> \\<open>to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (k2 - 1)) \\<noteq> to_bit b (the (\\<tau> k2 sig))\\<close>\n    unfolding to_trans_raw_sig_def to_trans_raw_bit_def  using \\<open>\\<tau> k2 sig \\<noteq> None\\<close> by auto\n  ultimately have \"to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig k1 \\<noteq> to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig k2\"\n    using to_bit_signal_of'_eq \n    using \\<open>to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (k2 - 1)) \\<noteq> to_bit b (the (\\<tau> k2 sig))\\<close> by fastforce\n  moreover assume \"to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig k1 = to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig k2\"\n  ultimately show False\n    by auto\nnext\n  { assume ex: \" keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig) \\<noteq> {}\"\n    let ?time = \"(LEAST k. k \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig))\"\n    have \"?time \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n      using ex  by (meson LeastI all_not_in_conv)\n    have \"\\<tau> ?time sig \\<noteq> None\"\n    proof -\n      have \"\\<exists>n v. to_trans_raw_bit v \\<tau> n sig (LEAST n. n \\<in> {n. to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig n \\<noteq> None}) sig \\<noteq> None\"\n        by (metis \\<open>(LEAST k. k \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\\<close> domD dom_def keys_def option.simps(3) to_trans_raw_sig_def zero_option_def)\n      then have \"\\<tau> (LEAST n. n \\<in> {n. to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig n \\<noteq> None}) sig \\<noteq> None\"\n        by (smt option.simps(4) to_trans_raw_bit_def)\n      then show ?thesis\n        by (simp add: keys_def zero_option_def)\n    qed\n    have \"?time = 0 \\<or> ?time \\<noteq> 0\"\n      by auto\n    moreover\n    { assume \"?time = 0\"\n      hence \"the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time sig) \\<noteq> to_bit b (\\<sigma> sig)\"\n        unfolding to_trans_raw_bit_def \n      proof -\n        assume a1: \"(LEAST k. k \\<in> keys (to_trans_raw_sig (\\<lambda>n siga. if siga \\<noteq> sig then \\<tau> n siga else case \\<tau> n siga of None \\<Rightarrow> None | Some v \\<Rightarrow> if 0 < n \\<and> to_bit b (signal_of (\\<sigma> sig) \\<tau> siga (n - 1)) = to_bit b v then None else if n = 0 \\<and> to_bit b (\\<sigma> sig) = to_bit b v then None else Some (to_bit b v)) sig)) = 0\"\n        have \"0 \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n          using \\<open>(LEAST k. k \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)) = 0\\<close> \\<open>(LEAST k. k \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\\<close> by presburger\n        then have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig 0 sig \\<noteq> None\"\n          by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n        then have f2: \"(case \\<tau> 0 sig of None \\<Rightarrow> None | Some v \\<Rightarrow> if (0::nat) < 0 \\<and> to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (0 - 1)) = to_bit b v then None else if to_bit b (\\<sigma> sig) = to_bit b v then None else Some (to_bit b v)) \\<noteq> None\"\n          by (smt option.case_eq_if to_trans_raw_bit_def)  \n        then have f3: \"\\<tau> 0 sig \\<noteq> None\"\n          by (metis option.case_eq_if)\n        obtain vv :: \"val option \\<Rightarrow> val\" where\n          \"\\<And>z za v. (z = None \\<or> Some (vv z) = z) \\<and> (za \\<noteq> None \\<or> za \\<noteq> Some (v::val))\"\n          by (metis (full_types) not_None_eq)\n        then have f4: \"\\<And>z za f. z = None \\<or> (case z of None \\<Rightarrow> za::val option | Some x \\<Rightarrow> f x) = f (vv z)\"\n          by (metis (full_types) option.case_eq_if option.sel)\n        then have f5: \"(if (0::nat) < 0 \\<and> to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (0 - 1)) = to_bit b (vv (\\<tau> 0 sig)) then None else if to_bit b (\\<sigma> sig) = to_bit b (vv (\\<tau> 0 sig)) then None else Some (to_bit b (vv (\\<tau> 0 sig)))) \\<noteq> None \\<or> \\<tau> 0 sig = None\"\n          using f2  by smt\n        { assume \"(if (0::nat) < 0 \\<and> to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (0 - 1)) = to_bit b (vv (\\<tau> 0 sig)) then None else if True \\<and> to_bit b (\\<sigma> sig) = to_bit b (vv (\\<tau> 0 sig)) then None else Some (to_bit b (vv (\\<tau> 0 sig)))) \\<noteq> Some (to_bit b (\\<sigma> sig))\"\n          have \"\\<tau> 0 sig \\<noteq> None \\<and> the (if (0::nat) < 0 \\<and> to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (0 - 1)) = to_bit b (vv (\\<tau> 0 sig)) then None else if True \\<and> to_bit b (\\<sigma> sig) = to_bit b (vv (\\<tau> 0 sig)) then None else Some (to_bit b (vv (\\<tau> 0 sig)))) \\<noteq> to_bit b (\\<sigma> sig)\"\n            using f5 f3 by force }\n        then have \"\\<tau> 0 sig \\<noteq> None \\<and> the (if (0::nat) < 0 \\<and> to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (0 - 1)) = to_bit b (vv (\\<tau> 0 sig)) then None else if True \\<and> to_bit b (\\<sigma> sig) = to_bit b (vv (\\<tau> 0 sig)) then None else Some (to_bit b (vv (\\<tau> 0 sig)))) \\<noteq> to_bit b (\\<sigma> sig)\"\n          by simp\n        then have \"the (if False then \\<tau> 0 sig else case \\<tau> 0 sig of None \\<Rightarrow> None | Some v \\<Rightarrow> if (0::nat) < 0 \\<and> to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (0 - 1)) = to_bit b v then None else if to_bit b (\\<sigma> sig) = to_bit b v then None else Some (to_bit b v)) \\<noteq> to_bit b (\\<sigma> sig)\"\n          using f4  by (metis (no_types, lifting))\n        then show \"the (if sig \\<noteq> sig then \\<tau> (LEAST n. n \\<in> keys (to_trans_raw_sig (\\<lambda>n a. if a \\<noteq> sig then \\<tau> n a else case \\<tau> n a of None \\<Rightarrow> None | Some v \\<Rightarrow> if 0 < n \\<and> to_bit b (signal_of (\\<sigma> sig) \\<tau> a (n - 1)) = to_bit b v then None else if n = 0 \\<and> to_bit b (\\<sigma> sig) = to_bit b v then None else Some (to_bit b v)) sig)) sig else case \\<tau> (LEAST n. n \\<in> keys (to_trans_raw_sig (\\<lambda>n a. if a \\<noteq> sig then \\<tau> n a else case \\<tau> n a of None \\<Rightarrow> None | Some v \\<Rightarrow> if 0 < n \\<and> to_bit b (signal_of (\\<sigma> sig) \\<tau> a (n - 1)) = to_bit b v then None else if n = 0 \\<and> to_bit b (\\<sigma> sig) = to_bit b v then None else Some (to_bit b v)) sig)) sig of None \\<Rightarrow> None | Some v \\<Rightarrow> if 0 < (LEAST n. n \\<in> keys (to_trans_raw_sig (\\<lambda>n a. if a \\<noteq> sig then \\<tau> n a else case \\<tau> n a of None \\<Rightarrow> None | Some v \\<Rightarrow> if 0 < n \\<and> to_bit b (signal_of (\\<sigma> sig) \\<tau> a (n - 1)) = to_bit b v then None else if n = 0 \\<and> to_bit b (\\<sigma> sig) = to_bit b v then None else Some (to_bit b v)) sig)) \\<and> to_bit b (signal_of (\\<sigma> sig) \\<tau> sig ((LEAST n. n \\<in> keys (to_trans_raw_sig (\\<lambda>n a. if a \\<noteq> sig then \\<tau> n a else case \\<tau> n a of None \\<Rightarrow> None | Some v \\<Rightarrow> if 0 < n \\<and> to_bit b (signal_of (\\<sigma> sig) \\<tau> a (n - 1)) = to_bit b v then None else if n = 0 \\<and> to_bit b (\\<sigma> sig) = to_bit b v then None else Some (to_bit b v)) sig)) - 1)) = to_bit b v then None else if (LEAST n. n \\<in> keys (to_trans_raw_sig (\\<lambda>n a. if a \\<noteq> sig then \\<tau> n a else case \\<tau> n a of None \\<Rightarrow> None | Some v \\<Rightarrow> if 0 < n \\<and> to_bit b (signal_of (\\<sigma> sig) \\<tau> a (n - 1)) = to_bit b v then None else if n = 0 \\<and> to_bit b (\\<sigma> sig) = to_bit b v then None else Some (to_bit b v)) sig)) = 0 \\<and> to_bit b (\\<sigma> sig) = to_bit b v then None else Some (to_bit b v)) \\<noteq> to_bit b (\\<sigma> sig)\"\n          using a1 by presburger\n      qed\n      hence \" (to_bit b o \\<sigma>) sig \\<noteq> the (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig ?time)\"\n      proof -\n        have f1: \"\\<And>n. n \\<notin> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig) \\<or> to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig n \\<noteq> 0\"\n          by (simp add: keys_def)\n        have \"\\<forall>v n. \\<exists>b. to_bit n v = Bv b\"\n          by (metis to_bit.elims)\n        then obtain bb :: \"val \\<Rightarrow> nat \\<Rightarrow> bool\" where\n          f2: \"\\<And>n v. to_bit n v = Bv (bb v n)\"\n          by moura\n        moreover\n        { assume \"\\<exists>n. Bv (bb (\\<sigma> sig) n) \\<noteq> \\<sigma> sig\"\n          then have \"\\<exists>f v. Some (\\<sigma> sig) = Some (f sig) \\<and> signal_of v (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (LEAST n. n \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)) \\<noteq> f sig\"\n            using f2 by (metis to_bit.simps(1) to_bit_signal_of')\n          then have \"the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (LEAST n. n \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)) sig) \\<noteq> \\<sigma> sig\"\n            using f1 by (metis \\<open>(LEAST k. k \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\\<close> option.collapse to_trans_raw_sig_def trans_some_signal_of' zero_option_def) }\n        ultimately show ?thesis\n          by (metis \\<open>the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (LEAST k. k \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)) sig) \\<noteq> to_bit b (\\<sigma> sig)\\<close> comp_apply to_trans_raw_sig_def)\n      qed }\n    moreover\n    { assume \"?time \\<noteq> 0\"\n      hence \"  to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time - 1)) \\<noteq> to_bit b (the (\\<tau> ?time sig))\"\n        using \\<open>?time \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\\<close>\n        unfolding to_trans_raw_sig_def keys_def to_trans_raw_bit_def  by (smt mem_Collect_eq neq0_conv option.case_eq_if zero_option_def)\n      moreover have \"to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time - 1)) = (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b))\"\n        unfolding to_bit_signal_of'_eq[THEN sym]\n      proof (rule signal_of_def)\n        fix n \n        assume \"n \\<le> ?time - 1\"\n        thus \"         to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig n sig = 0\"\n        proof -\n          have \"n \\<le> (LEAST n. n \\<in> {n. to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig n \\<noteq> 0}) - 1\"\n            by (metis \\<open>n \\<le> (LEAST k. k \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)) - 1\\<close> keys_def)\n          then have f1: \"\\<forall>na. na \\<le> (LEAST n. n \\<in> {n. to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig n \\<noteq> 0}) - 1 \\<or> \\<not> na \\<le> n\"\n            by (meson le_trans)\n          have \"(LEAST n. n \\<in> {n. to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig n \\<noteq> 0}) \\<noteq> 0\"\n            by (metis \\<open>(LEAST k. k \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)) \\<noteq> 0\\<close> keys_def)\n          then have \"n \\<notin> {n. to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig n \\<noteq> 0}\"\n            using f1 by (metis Least_le diff_le_self le_antisym minus_eq zero_neq_one)\n          then show ?thesis\n            by (simp add: to_trans_raw_sig_def)\n        qed\n      qed\n      ultimately have \"(to_bit b \\<circ> \\<sigma>) sig \\<noteq> to_bit b (the (\\<tau> ?time sig))\"\n        unfolding comp_def\n        by (metis to_bit.simps(1) to_bit.simps(2) val.case_eq_if val.collapse(1) val.collapse(2))\n      moreover have \" to_bit b (the (\\<tau> ?time sig)) = the (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig ?time)\"\n        using \\<open>\\<tau> ?time sig \\<noteq> None\\<close> \\<open>to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time - 1)) \\<noteq> to_bit b (the (\\<tau> ?time sig))\\<close>\n        unfolding to_trans_raw_sig_def to_trans_raw_bit_def apply auto\n        by (smt inf_time_at_most le_zero_eq option.exhaust option.sel option.simps(4) option.simps(5) to_signal_def) \n      ultimately have \" (to_bit b \\<circ> \\<sigma>) sig \\<noteq> the (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig ?time)\"\n        by auto }\n    ultimately have \"(to_bit b \\<circ> \\<sigma>) sig \\<noteq>\n    the (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig\n          (LEAST k. k \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)))\"\n      by auto }\n  thus \"keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig) \\<noteq> {} \\<longrightarrow>\n    (to_bit b \\<circ> \\<sigma>) sig \\<noteq>\n    the (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig\n          (LEAST k. k \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)))\"\n    by auto\nqed\n  \nlemma lift_inr_post_worldline_upd2:\n  assumes \"\\<omega> = worldline_raw t \\<sigma> \\<theta> def \\<tau>\"\n  assumes \"context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>\"\n  assumes \"t, \\<sigma>, \\<gamma>, \\<theta>, def \\<turnstile> <Bassign_inert sig exp dly, \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\"\n  assumes \"0 < dly\"\n  assumes \"non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma> sig\"\n  assumes \"All (non_stuttering (to_trans_raw_sig \\<theta>) def)\"\n  assumes \"beval_world_raw \\<omega> t exp (Lv sign bs)\"\n  shows   \"worldline_raw t \\<sigma> \\<theta> def \\<tau>' = worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)\"\nproof (rule, rule_tac[2] ext, rule_tac[2] ext)\n  fix s' t'\n  have \"beval_raw t \\<sigma> \\<gamma> \\<theta> def exp (Lv sign bs)\"\n    using assms beval_beval_world_raw_ci by metis\n  have \"\\<tau>' = inr_post_raw' sig (Lv sign bs) (\\<sigma> sig) \\<tau> t dly\"\n    using assms(3) \\<open>t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> exp \\<longrightarrow>\\<^sub>b(Lv sign bs)\\<close> beval_raw_deterministic  by (metis seq_cases_inert)\n  moreover have \"beval_raw t \\<sigma> \\<gamma> \\<theta> def exp = beval_world_raw \\<omega> t exp\"\n    using `\\<omega> = worldline_raw t \\<sigma> \\<theta> def \\<tau> ` and `context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>`\n    by (simp add: assms(6) beval_beval_world_raw_ci)\n  hence \\<tau>'_def: \"\\<tau>' = inr_post_raw' sig(Lv sign bs) (\\<sigma> sig) \\<tau> t dly\"\n    by (simp add: calculation)\n  have \"context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>'\"\n    using b_seq_exec_preserves_context_invariant[OF assms(2-3)] `0 < dly` by auto\n\n  have \"\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\"\n    using assms(2) unfolding context_invariant_def by auto\n  have \"s' \\<noteq> sig \\<or> t' < t \\<or> s' = sig \\<and> t \\<le> t'\"\n    by auto\n  moreover\n  { assume \"s' = sig \\<and> t \\<le> t'\"\n    hence \"t + dly \\<le> t' \\<or> t' < t + dly\" and \"s' = sig\" and \"t \\<le> t'\"\n      by auto\n    moreover\n    { assume \"t + dly \\<le> t'\"\n      hence \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = signal_of (\\<sigma> s') \\<tau>' s' t'\"\n        unfolding worldline_raw_def snd_conv by auto\n      also have \"... = signal_of (\\<sigma> s') (inr_post_raw' sig (Lv sign bs) (\\<sigma> sig) \\<tau> t dly) s' t'\"\n        unfolding \\<tau>'_def by auto\n      also have \"... = signal_of (\\<sigma> s') (trans_post_raw sig (Lv sign bs) (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) t dly) s' t'\"\n        unfolding inr_post_raw'_def by auto\n      also have \"... = Lv sign bs\"\n        unfolding `s' = sig`\n      proof (intro signal_of_trans_post3)\n        show \"t + dly \\<le> t'\"\n          using `t + dly \\<le> t'` by auto\n      next\n        show \"\\<forall>i<t. purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) i = 0\"\n          using assms(2) unfolding purge_raw'_def combine_trans_bit_def context_invariant_def by auto\n      next\n        show \"0 < dly\"\n          by (simp add: assms(4))\n      qed\n      also have \"... = snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t'\"\n        unfolding worldline_inert_upd2.simps snd_conv `s' = sig`\n      proof -\n        have \"bs = map (\\<lambda>b. bval_of (snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig t')) [0..<length bs]\"\n        proof (rule nth_equalityI)\n          fix i \n          assume \"i < length bs\"\n          hence \"map (\\<lambda>b. bval_of (snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig t')) [0..<length bs] ! i = \n                 bval_of (snd to_worldline_init_bit \\<omega> sig i[sig, t, dly := Bv (bs ! i)] sig t')\"\n            by auto\n          also have \"... = bs ! i\"\n            unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv\n          proof (cases \"((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig t = Bv (bs ! i) \\<or> ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig (t + dly) \\<noteq> Bv (bs ! i)\")\n            case False\n            hence \"((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! i)\" and \n                  \"((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! i)\"\n              by auto\n            have *: \"\\<exists>k\\<le>t + dly. ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig (k - 1) \\<noteq> Bv (bs ! i) \\<and> ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig k = Bv (bs ! i) \"\n            proof (rule ccontr)\n              assume \"\\<not> (\\<exists>k\\<le>t + dly. ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig (k - 1) \\<noteq> Bv (bs ! i) \\<and> ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig k = Bv (bs ! i))\"\n              hence ind: \"\\<forall>k. k \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig (k - 1) \\<noteq> Bv (bs ! i) \\<longrightarrow> ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig k \\<noteq> Bv (bs ! i)\"\n                by auto\n              { fix k\n                assume \"t \\<le> k\"\n                assume \"k \\<le> t + dly\"\n                hence \"((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig k \\<noteq> Bv (bs ! i)\"\n                  using ind `t \\<le> k` `((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! i)`\n                proof (induction \"k - t\" arbitrary: t dly)\n                  case 0\n                  then show ?case  by auto\n                next\n                  case (Suc x)\n                  hence 0: \"x = k - Suc t\" and 1: \"k \\<le> Suc t + (dly - 1)\"\n                    by linarith+\n                  have \"k = Suc x + t\"\n                    using Suc by linarith\n                  have 3: \"\\<forall>k. k \\<le> Suc t + (dly - 1) \\<and> ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig (k - 1) \\<noteq> Bv (bs ! i) \\<longrightarrow> ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig k \\<noteq> Bv (bs ! i)\"\n                    using Suc(4) \n                    by (metis (no_types, lifting) One_nat_def Suc.hyps(2) Suc.prems(1) Suc_pred add_Suc_shift less_add_same_cancel1 less_le_trans zero_less_Suc zero_less_diff)\n                  have 4: \"Suc t \\<le> k\"\n                    using \\<open>k = Suc x + t\\<close> by linarith\n                  have 5: \"((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig (Suc t) \\<noteq> Bv (bs ! i)\"\n                    using Suc  by (metis \"3\" diff_Suc_1 le_add1)\n                  show ?case \n                    using Suc(1)[OF 0 1 3 4 5] by auto\n                qed }\n              with `((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! i)`\n              show False\n                by auto\n            qed\n            have \"(GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! i) \\<and> ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! i)) \\<le> t + dly\"\n              using GreatestI_ex_nat[where P=\"\\<lambda>n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! i) \\<and> ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! i)\" and b=\"t + dly\", OF *]\n              by auto\n            thus \"bval_of (let time = if ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig t = Bv (bs ! i) \\<or> ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig (t + dly) \\<noteq> Bv (bs ! i) then t + dly\n                                      else GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! i) \\<and> ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! i)\n                           in if sig \\<noteq> sig \\<or> t' < t then ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig t' else if t' < time then ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig t else Bv (bs ! i)) = bs ! i\"\n              using False  using \\<open>t + dly \\<le> t'\\<close> by auto\n          next\n            case True\n            thus \"bval_of (let time = if ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig t = Bv (bs ! i) \\<or> ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig (t + dly) \\<noteq> Bv (bs ! i) then t + dly\n                                      else GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! i) \\<and> ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! i)\n                           in if sig \\<noteq> sig \\<or> t' < t then ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig t' else if t' < time then ((snd \\<omega>)(sig := to_bit i \\<circ> snd \\<omega> sig)) sig t else Bv (bs ! i)) = bs ! i\"\n              using \\<open>t + dly \\<le> t'\\<close> by auto\n          qed\n          finally show \" bs ! i = map (\\<lambda>b. bval_of (snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig t')) [0..<length bs] ! i\"\n            by auto\n        qed (auto)\n        thus \" Lv sign bs =\n    ((snd \\<omega>)\n     (sig :=\n        \\<lambda>n. let w' = \\<lambda>b. snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)];\n                time =\n                  if \\<exists>n>t. n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length bs]. w' b sig (n - 1) \\<noteq> w' b sig n)\n                  then LEAST n. t < n \\<and> n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length bs]. w' b sig (n - 1) \\<noteq> w' b sig n) else t + dly\n            in if n < t then snd \\<omega> sig n\n               else if n < time then snd \\<omega> sig t else Lv sign (map (\\<lambda>b. bval_of (snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig n)) [0..<length bs])))\n     sig t'\"\n          using \\<open>t \\<le> t'\\<close> \n        proof ( cases \"\\<exists>n>t. n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length bs]. snd (to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)]) sig (n - 1) \\<noteq> snd (to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)]) sig n)\")\n          case True\n          let ?w' = \"\\<lambda>b. snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)]\"\n          have \"(LEAST n. t < n \\<and> n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length bs]. ?w' b sig (n - 1) \\<noteq> ?w' b sig n)) \\<le> t + dly\"\n            using True \n            by (metis (mono_tags, lifting) LeastI_ex)\n          then show ?thesis \n            using True \\<open>t + dly \\<le> t'\\<close> \\<open>bs = map (\\<lambda>b. bval_of (snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig t')) [0..<length bs]\\<close>\n            by auto\n        next\n          case False\n          then show ?thesis \n            using \\<open>t + dly \\<le> t'\\<close> \\<open>bs = map (\\<lambda>b. bval_of (snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig t')) [0..<length bs]\\<close>\n            by auto\n        qed\n      qed\n      finally have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t'\"\n        by auto }\n    moreover\n    { assume \"t' < t + dly\"\n      hence \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = signal_of (\\<sigma> s') \\<tau>' s' t'\"\n        using `t \\<le> t'` unfolding worldline_raw_def snd_conv by auto \n      also have \"... = signal_of (\\<sigma> s') (inr_post_raw' sig (Lv sign bs) (\\<sigma> sig) \\<tau> t dly) s' t'\"\n        unfolding \\<tau>'_def by auto    \n      also have \"... = signal_of (\\<sigma> s') (trans_post_raw sig (Lv sign bs) (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) t dly) s' t'\"\n        unfolding inr_post_raw'_def by auto\n      also have \"... = signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'\"\n        unfolding `s' = sig`  signal_of_trans_post2[OF `t' < t + dly`] by auto\n      finally have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'\"\n        by auto\n      let ?w' = \"\\<lambda>b. snd (to_worldline_init_bit \\<omega> sig b)[sig, t, dly := Bv (bs ! b)]\"\n      have \"\\<exists>n>t. n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length bs]. ?w' b sig (n - 1) \\<noteq> ?w' b sig n) \\<or> \n            \\<not> (\\<exists>n>t. n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length bs]. ?w' b sig (n - 1) \\<noteq> ?w' b sig n))\"\n        by auto\n      moreover\n      { assume thereis: \"\\<exists>n>t. n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length bs]. ?w' b sig (n - 1) \\<noteq> ?w' b sig n)\"\n        let ?zeit = \"LEAST n. t < n \\<and> n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length bs]. ?w' b sig (n - 1) \\<noteq> ?w' b sig n)\"\n        define zeit where \"zeit = ?zeit\"\n        have \"t < ?zeit\" and \"?zeit \\<le> t + dly\" and \"\\<exists>b\\<in>set [0..<length bs]. ?w' b sig (?zeit - 1) \\<noteq> ?w' b sig ?zeit\"\n          using LeastI_ex[OF thereis] by auto\n        then obtain index where \"index \\<in> set [0..< length bs]\" and \"?w' index sig (?zeit - 1) \\<noteq> ?w' index sig ?zeit\"\n          by auto\n        have \"?w' index sig (zeit - 1) = ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t\"\n        proof (cases \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t = Bv (bs ! index) \\<or> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) \\<noteq> Bv (bs ! index)\")\n          case True\n          then show ?thesis \n            using \\<open>?zeit \\<le> t + dly\\<close>\n            unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv \n            by (smt One_nat_def Suc_leI Suc_pred \\<open>(LEAST n. t < n \\<and> n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length bs]. snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig (n - 1) \\<noteq> snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig n)) \\<le> t + dly\\<close> \\<open>t < (LEAST n. t < n \\<and> n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length bs]. snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig (n - 1) \\<noteq> snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig n))\\<close> diff_less le_eq_less_or_eq le_zero_eq less_numeral_extra(1) less_trans not_le zeit_def)\n        next\n          case False\n          hence \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! index)\" and \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index)\"\n            by auto\n          have *: \"\\<exists>n. t < n \\<and> n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)\"\n          proof (rule ccontr)\n            assume \"\\<not> (\\<exists>n. t < n \\<and> n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\"\n            hence imp: \"\\<And>n. t < n \\<Longrightarrow> n \\<le> t + dly \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)\"\n              by auto\n            { fix n \n              assume \"t \\<le> n\" and \"n \\<le> t + dly\"\n              hence \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)\"\n                using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! index)\\<close> imp\n              proof (induction \"n - t\" arbitrary: t dly)\n                case 0 hence \"n = t\" by auto\n                then show ?case \n                  using 0 by auto\n              next\n                case (Suc x)\n                hence 0: \"x = n - Suc t\"\n                  by auto\n                have 2: \"n \\<le> Suc t + (dly - 1) \"\n                  using Suc by auto\n                hence 1: \"Suc t \\<le> n \"\n                  using Suc by linarith\n                hence \"Suc t \\<le> t + dly\"\n                  using Suc by linarith\n                hence 3: \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (Suc t) \\<noteq> Bv (bs ! index)\"\n                  using Suc(5-6) by auto\n                have 4: \"\\<And>n. Suc t < n \\<Longrightarrow> n \\<le> Suc t + (dly - 1) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)\"\n                  using Suc(6) by auto\n                have \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)\"\n                  using  Suc(1)[OF 0 1 2 3 4] by auto\n                thus ?case\n                  by auto\n              qed }\n            hence \"\\<And>n. t \\<le> n \\<Longrightarrow> n \\<le> t + dly \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)\"\n              by auto\n            thus False\n              using False le_add1 by blast\n          qed\n          let ?time_again =\"GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)\"\n\n          have \"t < ?time_again\"\n            using * \n          proof -\n            have f1: \"\\<forall>p n na. (n::nat) \\<le> Greatest p \\<or> (\\<exists>n. \\<not> n \\<le> na \\<and> p n) \\<or> \\<not> p n\"\n              by (metis (lifting) Greatest_le_nat)\n            obtain nn :: nat where\n              f2: \"Bv (bs ! index) = ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig nn \\<and> Bv (bs ! index) \\<noteq> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (nn - 1) \\<and> nn \\<le> t + dly \\<and> t < nn\"\n              by (metis (no_types) \"*\")\n            then have \"nn \\<le> (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\"\n              using f1 by force\n            then show ?thesis\n              using f2 by (meson less_le_trans)\n          qed\n          hence \"?time_again - 1 < ?time_again\"\n            by auto\n          have \"?time_again \\<le> t + dly\" and \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (?time_again - 1) \\<noteq> Bv (bs ! index)\" and \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig ?time_again = Bv (bs ! index)\"\n            using GreatestI_ex_nat *  apply (metis (mono_tags, lifting))\n            using GreatestI_ex_nat *  apply (metis (mono_tags, lifting))\n            using GreatestI_ex_nat *  by smt\n          have \"?w' index sig (?time_again - 1) = ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t\"\n            using \\<open>t < ?time_again\\<close> \\<open>?time_again - 1 < ?time_again\\<close> False\n            unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv by auto\n          moreover have \"?w' index sig (?time_again) = Bv (bs ! index)\"\n            unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv \n            using False \\<open>t < (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\\<close> by auto\n          ultimately have \"?w' index sig (?time_again - 1) \\<noteq> ?w' index sig ?time_again\"\n            using False by auto\n          hence \"?zeit \\<le> ?time_again\"\n          proof -\n            have \"t < (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) \\<and> (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) \\<le> t + dly \\<and> (\\<exists>n. n \\<in> set [0..<length bs] \\<and> snd to_worldline_init_bit \\<omega> sig n[sig, t, dly := Bv (bs ! n)] sig ((GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) - 1) \\<noteq> snd to_worldline_init_bit \\<omega> sig n[sig, t, dly := Bv (bs ! n)] sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)))\"\n              using \\<open>(GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) \\<le> t + dly\\<close> \\<open>index \\<in> set [0..<length bs]\\<close> \\<open>snd to_worldline_init_bit \\<omega> sig index[sig, t, dly := Bv (bs ! index)] sig ((GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) - 1) \\<noteq> snd to_worldline_init_bit \\<omega> sig index[sig, t, dly := Bv (bs ! index)] sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\\<close> \\<open>t < (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\\<close> by blast\n            then show ?thesis\n              by (simp add: Bex_def_raw Least_le)\n          qed\n              \n          show ?thesis \n            unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv\n            by (smt False One_nat_def Suc_leI Suc_pred \\<open>?zeit \\<le> ?time_again\\<close> \\<open>t <\n            (LEAST n. t < n \\<and> n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length bs]. snd to_worldline_init_bit \\<omega> sig\n            b[sig, t, dly := Bv (bs ! b)] sig (n - 1) \\<noteq> snd to_worldline_init_bit \\<omega> sig b[sig, t,\n            dly := Bv (bs ! b)] sig n))\\<close> le_eq_less_or_eq le_zero_eq lessI less_trans not_le\n            zeit_def)\n        qed\n        also have \"... =  (to_bit index \\<circ> snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>) sig) t\"\n          unfolding assms(1) fun_upd_def by auto\n        also have \"... = to_bit index (signal_of (\\<sigma> sig) \\<tau> sig t)\"\n          unfolding worldline_raw_def snd_conv by auto\n        finally have \"?w' index sig (zeit - 1) = to_bit index (signal_of (\\<sigma> sig) \\<tau> sig t)\"\n          by auto\n        have \"\\<not> zeit < t\"\n          using \\<open>t < (LEAST n. t < n \\<and> n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length bs]. snd\n          to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig (n - 1) \\<noteq> snd\n          to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig n))\\<close> not_le zeit_def \n          by linarith\n        have \"\\<not> zeit - 1 < t\"\n          using \\<open>t < (LEAST n. t < n \\<and> n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length bs]. snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig (n - 1) \\<noteq> snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig n))\\<close> zeit_def by linarith\n        have \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t  \\<noteq> Bv (bs ! index)\"\n        proof (rule ccontr)\n          assume \"\\<not> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! index)\"\n          hence \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t = Bv (bs ! index)\"\n            by auto\n          have \"zeit < t + dly \\<or> zeit = t + dly\"\n            using \\<open>(LEAST n. t < n \\<and> n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length bs]. snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig (n - 1) \\<noteq> snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig n)) \\<le> t + dly\\<close> le_eq_less_or_eq zeit_def by blast \n          moreover\n          { assume \"zeit < t + dly\"\n            hence \"?w' index sig zeit = ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t\"\n              unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv \n              using \\<open>\\<not> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! index)\\<close> \\<open>\\<not> zeit < t\\<close> by auto\n            hence False\n              using \\<open>?w' index sig (zeit - 1) = ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t\\<close>\n              \\<open>?w' index sig (?zeit - 1) \\<noteq> ?w' index sig (?zeit)\\<close> zeit_def by auto }\n          moreover\n          { assume \"zeit = t + dly\"\n            hence \"?w' index sig zeit = Bv (bs ! index)\"\n              unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv \n              using \\<open>\\<not> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! index)\\<close> by auto\n            with \\<open>?w' index sig (zeit - 1) = ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t\\<close> have False\n              unfolding \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t = Bv (bs ! index)\\<close>\n              using \\<open>?w' index sig (zeit - 1) = ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t\\<close>\n              \\<open>?w' index sig (?zeit - 1) \\<noteq> ?w' index sig (?zeit)\\<close> zeit_def by auto }\n          ultimately show False\n            by auto\n        qed\n        hence \"?w' index sig (zeit - 1) \\<noteq> Bv (bs ! index)\"\n          using \\<open>snd to_worldline_init_bit \\<omega> sig index[sig, t, dly := Bv (bs ! index)] sig (zeit -\n          1) = ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t\\<close> by auto\n        have \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) \\<noteq> Bv (bs ! index) \\<Longrightarrow> zeit = t + dly\"\n        proof (rule ccontr)\n          assume as: \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) \\<noteq> Bv (bs ! index)\"\n          assume \"\\<not> zeit = t + dly\" hence \"zeit < t + dly\"\n            using \\<open>?zeit \\<le> t + dly\\<close> unfolding zeit_def by auto\n          hence \"?w' index sig zeit = ?w' index sig (zeit - 1)\"\n            using \\<open>\\<not> zeit < t\\<close> \\<open>\\<not> zeit - 1 < t\\<close>  as\n            unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv by auto\n          thus False\n            using \\<open>?w' index sig (?zeit - 1) \\<noteq> ?w' index sig ?zeit\\<close> unfolding zeit_def\n            by auto\n        qed\n        have \"?w' index sig (zeit) =  Bv (bs ! index) \"\n        proof (cases \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) \\<noteq> Bv (bs ! index)\")\n          case True\n          then show ?thesis \n            using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) \\<noteq> Bv (bs ! index) \\<Longrightarrow> zeit = t + dly\\<close>\n            unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv by auto\n        next\n          case False\n          let ?time_again =\"GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)\"\n          have cond1: \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! index)\" and cond2: \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index)\"\n            using False  using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! index)\\<close> by blast+\n          have *: \"\\<exists>n. t < n \\<and> n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)\"\n          proof (rule ccontr)\n            assume \"\\<not> (\\<exists>n. t < n \\<and> n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\"\n            hence imp: \"\\<And>n. t < n \\<Longrightarrow> n \\<le> t + dly \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)\"\n              by auto\n            { fix n \n              assume \"t \\<le> n\" and \"n \\<le> t + dly\"\n              hence \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)\"\n                using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! index)\\<close> imp\n              proof (induction \"n - t\" arbitrary: t dly)\n                case 0 hence \"n = t\" by auto\n                then show ?case \n                  using 0 by auto\n              next\n                case (Suc x)\n                hence 0: \"x = n - Suc t\"\n                  by auto\n                have 2: \"n \\<le> Suc t + (dly - 1) \"\n                  using Suc by auto\n                hence 1: \"Suc t \\<le> n \"\n                  using Suc by linarith\n                hence \"Suc t \\<le> t + dly\"\n                  using Suc by linarith\n                hence 3: \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (Suc t) \\<noteq> Bv (bs ! index)\"\n                  using Suc(5-6) by auto\n                have 4: \"\\<And>n. Suc t < n \\<Longrightarrow> n \\<le> Suc t + (dly - 1) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)\"\n                  using Suc(6) by auto\n                have \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)\"\n                  using  Suc(1)[OF 0 1 2 3 4] by auto\n                thus ?case\n                  by auto\n              qed }\n            hence \"\\<And>n. t \\<le> n \\<Longrightarrow> n \\<le> t + dly \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)\"\n              by auto\n            thus False\n              using False le_add1 by blast\n          qed\n          { assume \"\\<not> ?w' index sig zeit = Bv (bs ! index)\"\n            hence \"zeit < ?time_again\"\n              using cond1 cond2\n              unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv \n              using \\<open>\\<not> zeit < t\\<close> by presburger\n            hence \"?w' index sig zeit = ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t\"\n              using cond1 cond2\n              unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv \n              by (simp add: \\<open>\\<not> zeit < t\\<close>)\n            hence \"?w' index sig zeit = ?w' index sig (zeit - 1)\"\n              using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t = (to_bit index \\<circ> snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>) sig) t\\<close> \\<open>(to_bit index \\<circ> snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>) sig) t = to_bit index (signal_of (\\<sigma> sig) \\<tau> sig t)\\<close> \\<open>snd to_worldline_init_bit \\<omega> sig index[sig, t, dly := Bv (bs ! index)] sig (zeit - 1) = to_bit index (signal_of (\\<sigma> sig) \\<tau> sig t)\\<close> by auto\n            hence False\n              using \\<open>?w' index sig (?zeit - 1) \\<noteq> ?w' index sig (?zeit)\\<close> zeit_def \n              by auto }\n          thus ?thesis \n            by auto\n        qed\n        hence \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index) \\<Longrightarrow> \n                zeit = (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\"\n          unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv\n        proof -\n          assume \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index)\"\n          let ?time_again =\"GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)\"\n          have cond1: \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! index)\" and cond2: \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index)\"\n            using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! index)\\<close> apply blast\n            using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index)\\<close> by blast\n          have *: \"\\<exists>n. t < n \\<and> n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)\"\n          proof (rule ccontr)\n            assume \"\\<not> (\\<exists>n. t < n \\<and> n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\"\n            hence imp: \"\\<And>n. t < n \\<Longrightarrow> n \\<le> t + dly \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)\"\n              by auto\n            { fix n \n              assume \"t \\<le> n\" and \"n \\<le> t + dly\"\n              hence \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)\"\n                using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! index)\\<close> imp\n              proof (induction \"n - t\" arbitrary: t dly)\n                case 0 hence \"n = t\" by auto\n                then show ?case \n                  using 0 by auto\n              next\n                case (Suc x)\n                hence 0: \"x = n - Suc t\"\n                  by auto\n                have 2: \"n \\<le> Suc t + (dly - 1) \"\n                  using Suc by auto\n                hence 1: \"Suc t \\<le> n \"\n                  using Suc by linarith\n                hence \"Suc t \\<le> t + dly\"\n                  using Suc by linarith\n                hence 3: \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (Suc t) \\<noteq> Bv (bs ! index)\"\n                  using Suc(5-6) by auto\n                have 4: \"\\<And>n. Suc t < n \\<Longrightarrow> n \\<le> Suc t + (dly - 1) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)\"\n                  using Suc(6) by auto\n                have \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)\"\n                  using  Suc(1)[OF 0 1 2 3 4] by auto\n                thus ?case\n                  by auto\n              qed }\n            hence \"\\<And>n. t \\<le> n \\<Longrightarrow> n \\<le> t + dly \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)\"\n              by auto\n            thus False\n              using cond2 le_add1 by blast\n          qed          \n          have \"t < ?time_again\"\n            using * \n          proof -\n            have f1: \"\\<forall>p n na. (n::nat) \\<le> Greatest p \\<or> (\\<exists>n. \\<not> n \\<le> na \\<and> p n) \\<or> \\<not> p n\"\n              by (metis (lifting) Greatest_le_nat)\n            obtain nn :: nat where\n              f2: \"Bv (bs ! index) = ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig nn \\<and> Bv (bs ! index) \\<noteq> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (nn - 1) \\<and> nn \\<le> t + dly \\<and> t < nn\"\n              by (metis (no_types) \"*\")\n            then have \"nn \\<le> (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\"\n              using f1 by force\n            then show ?thesis\n              using f2 by (meson less_le_trans)\n          qed\n          hence \"?time_again - 1 < ?time_again\"\n            by auto\n          have \"?time_again \\<le> t + dly\" and \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (?time_again - 1) \\<noteq> Bv (bs ! index)\" and \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig ?time_again = Bv (bs ! index)\"\n            using GreatestI_ex_nat *  apply (metis (mono_tags, lifting))\n            using GreatestI_ex_nat *  apply (metis (mono_tags, lifting))\n            using GreatestI_ex_nat *  by smt\n          have \"?w' index sig (?time_again - 1) = ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t\"\n            using \\<open>t < ?time_again\\<close> \\<open>?time_again - 1 < ?time_again\\<close> cond1 cond2\n            unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv by auto\n          moreover have \"?w' index sig (?time_again) = Bv (bs ! index)\"\n            unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv \n            using cond1 cond2 \\<open>t < (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\\<close> by auto\n          ultimately have \"?w' index sig (?time_again - 1) \\<noteq> ?w' index sig ?time_again\"\n            using cond1 cond2 by auto\n          hence \"?zeit \\<le> ?time_again\"\n          proof -\n            have \"t < (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) \\<and> (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) \\<le> t + dly \\<and> (\\<exists>n. n \\<in> set [0..<length bs] \\<and> snd to_worldline_init_bit \\<omega> sig n[sig, t, dly := Bv (bs ! n)] sig ((GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) - 1) \\<noteq> snd to_worldline_init_bit \\<omega> sig n[sig, t, dly := Bv (bs ! n)] sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)))\"\n              using \\<open>(GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) \\<le> t + dly\\<close> \\<open>index \\<in> set [0..<length bs]\\<close> \\<open>snd to_worldline_init_bit \\<omega> sig index[sig, t, dly := Bv (bs ! index)] sig ((GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) - 1) \\<noteq> snd to_worldline_init_bit \\<omega> sig index[sig, t, dly := Bv (bs ! index)] sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\\<close> \\<open>t < (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\\<close> by blast\n            then show ?thesis\n              by (simp add: Bex_def_raw Least_le)\n          qed\n          hence \"zeit \\<le> ?time_again\"\n            unfolding zeit_def by auto\n          moreover have \"\\<not> zeit < ?time_again\"\n            by (smt One_nat_def Suc_leI Suc_pred \\<open>?w' index sig (?time_again - 1) = ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t\\<close> \n            \\<open>?w' index sig (?time_again) = Bv (bs ! index)\\<close> \\<open>?w' index sig (zeit) =  Bv (bs ! index)\\<close> \n            \\<open>t < (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig\n            (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs !\n            index))\\<close> \\<open>t < ?zeit\\<close> cond1 gr_implies_not0\n            leD not_less_iff_gr_or_eq prod.sel(2) worldline_inert_upd_def zeit_def)\n          thus ?thesis\n            using calculation le_eq_less_or_eq by blast\n        qed\n        hence \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index) \\<Longrightarrow> \n               ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (zeit - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (zeit) = Bv (bs ! index)\"\n        proof -\n          assume \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index)\"\n          hence \"zeit = (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\"\n            using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index) \\<Longrightarrow> zeit = (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\\<close> by blast\n          have cond1: \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! index)\" and cond2: \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index)\"\n            using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! index)\\<close> apply blast\n            using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index)\\<close> by blast\n          have *: \"\\<exists>n. t < n \\<and> n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)\"\n          proof (rule ccontr)\n            assume \"\\<not> (\\<exists>n. t < n \\<and> n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\"\n            hence imp: \"\\<And>n. t < n \\<Longrightarrow> n \\<le> t + dly \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)\"\n              by auto\n            { fix n \n              assume \"t \\<le> n\" and \"n \\<le> t + dly\"\n              hence \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)\"\n                using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! index)\\<close> imp\n              proof (induction \"n - t\" arbitrary: t dly)\n                case 0 hence \"n = t\" by auto\n                then show ?case \n                  using 0 by auto\n              next\n                case (Suc x)\n                hence 0: \"x = n - Suc t\"\n                  by auto\n                have 2: \"n \\<le> Suc t + (dly - 1) \"\n                  using Suc by auto\n                hence 1: \"Suc t \\<le> n \"\n                  using Suc by linarith\n                hence \"Suc t \\<le> t + dly\"\n                  using Suc by linarith\n                hence 3: \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (Suc t) \\<noteq> Bv (bs ! index)\"\n                  using Suc(5-6) by auto\n                have 4: \"\\<And>n. Suc t < n \\<Longrightarrow> n \\<le> Suc t + (dly - 1) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)\"\n                  using Suc(6) by auto\n                have \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)\"\n                  using  Suc(1)[OF 0 1 2 3 4] by auto\n                thus ?case\n                  by auto\n              qed }\n            hence \"\\<And>n. t \\<le> n \\<Longrightarrow> n \\<le> t + dly \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)\"\n              by auto\n            thus False\n              using cond2 le_add1 by blast\n          qed         \n          thus ?thesis\n          proof -\n            obtain nn :: \"(nat \\<Rightarrow> bool) \\<Rightarrow> nat \\<Rightarrow> nat\" where\n              f1: \"\\<And>p n na nb. (\\<not> p n \\<or> p (Greatest p) \\<or> p (nn p na)) \\<and> (\\<not> p nb \\<or> \\<not> nn p na \\<le> na \\<or> p (Greatest p))\"\n              by (metis (lifting) GreatestI_ex_nat)\n            then have \"\\<And>n na. (\\<not> n \\<le> t + dly \\<or> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) = Bv (bs ! index) \\<or> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! index)) \\<or> zeit \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (zeit - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig zeit = Bv (bs ! index) \\<or> nn (\\<lambda>n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) na \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (nn (\\<lambda>n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) na - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (nn (\\<lambda>n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) na) = Bv (bs ! index)\"\n              by (smt \\<open>zeit = (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\\<close>) \n            moreover\n            { assume \"\\<exists>n\\<le>t + dly. ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)\"\n              { assume \"\\<exists>n. (n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) \\<and> (\\<not> zeit \\<le> t + dly \\<or> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (zeit - 1) = Bv (bs ! index) \\<or> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig zeit \\<noteq> Bv (bs ! index))\"\n                then have \"\\<exists>n. (n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) \\<and> (\\<not> (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>) (sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>) (sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) \\<le> t + dly \\<or> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig ((GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) - 1) = Bv (bs ! index) \\<or> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) \\<noteq> Bv (bs ! index))\"\n                  using \\<open>zeit = (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\\<close> by force\n                then have \"\\<exists>n. \\<not> nn (\\<lambda>n. n \\<le> t + dly \\<and> ((snd \\<omega>) (sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>) (sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) n \\<le> t + dly \\<or> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (nn (\\<lambda>n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) n - 1) = Bv (bs ! index) \\<or> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (nn (\\<lambda>n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) n) \\<noteq> Bv (bs ! index)\"\n                  using f1 by smt }\n              then have \"(\\<exists>n. \\<not> nn (\\<lambda>n. n \\<le> t + dly \\<and> ((snd \\<omega>) (sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>) (sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) n \\<le> t + dly \\<or> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (nn (\\<lambda>n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) n - 1) = Bv (bs ! index) \\<or> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (nn (\\<lambda>n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) n) \\<noteq> Bv (bs ! index)) \\<or> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (zeit - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig zeit = Bv (bs ! index)\"\n                by blast }\n            ultimately show ?thesis\n              using \"*\" by blast\n          qed\n        qed\n        have \"\\<And>b2. b2 < length bs \\<Longrightarrow> bval_of (snd to_worldline_init_bit \\<omega> sig b2[sig, t, dly := Bv (bs ! b2)] sig t') = bval_of (to_bit b2 (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'))\"\n        proof-\n          fix b\n          assume \"b < length bs\"\n          have *: \"bval_of (snd (to_worldline_init_bit \\<omega> sig b)[sig, t, dly := Bv (bs ! b)] sig t') =  bval_of\n       (let time =\n              if ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig t = Bv (bs ! b) \\<or> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (t + dly) \\<noteq> Bv (bs ! b) then t + dly\n              else GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)\n        in if t' < time then ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig t else Bv (bs ! b))\"\n            using `t \\<le> t'` unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv by auto\n          have \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig t = Bv (bs ! b) \\<or> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (t + dly) \\<noteq> Bv (bs ! b) \\<or> \n                ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! b)\"\n            by auto\n          moreover\n          { assume \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig t = Bv (bs ! b) \\<or> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (t + dly) \\<noteq> Bv (bs ! b)\"\n            hence \"bval_of (snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig t') = \n                   bval_of (((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig t)\"\n              using `t' < t + dly` unfolding * by auto\n            also have \"... =  bval_of (to_bit b (signal_of (\\<sigma> sig) \\<tau> sig t))\"\n              unfolding assms(1) worldline_raw_def snd_conv by auto\n            also have \"... = bval_of (to_bit b (\\<sigma> sig))\"\n            proof -\n              have \"inf_time (to_trans_raw_sig \\<tau>) sig t = None\"\n                using assms(2) unfolding context_invariant_def \n              proof -\n                assume a1: \"(\\<forall>n\\<le>t. \\<tau> n = 0) \\<and> \\<gamma> = {s. \\<sigma> s \\<noteq> signal_of (def s) \\<theta> s (t - 1)} \\<and> (\\<forall>n\\<ge>t. \\<theta> n = 0)\"\n                have \"\\<forall>f a n. \\<exists>na. (na \\<le> n \\<or> inf_time f (a::'a) n = None) \\<and> (na \\<in> keys (f a) \\<or> inf_time f a n = None)\"\n                  by (metis (lifting) inf_time_def)\n                then obtain nn :: \"('a \\<Rightarrow> nat \\<Rightarrow> val option) \\<Rightarrow> 'a \\<Rightarrow> nat \\<Rightarrow> nat\" where\n                  f2: \"\\<And>f a n. (nn f a n \\<le> n \\<or> inf_time f a n = None) \\<and> (nn f a n \\<in> keys (f a) \\<or> inf_time f a n = None)\"\n                  by moura\n                moreover\n                { assume \"nn (to_trans_raw_sig \\<tau>) sig t \\<le> t\"\n                  then have \"\\<tau> (nn (to_trans_raw_sig \\<tau>) sig t) sig = None\"\n                    using a1 by (simp add: zero_fun_def zero_option_def)\n                  then have ?thesis\n                    using f2 by (metis domIff dom_def keys_def to_trans_raw_sig_def zero_option_def) }\n                ultimately show ?thesis\n                  by blast\n              qed\n              thus ?thesis\n                unfolding to_signal_def comp_def by auto\n            qed \n            also have \"... = bval_of (to_bit b (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'))\"\n            proof (cases \"inf_time (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs))) sig t'\")\n              case None\n              then show ?thesis \n                unfolding to_signal_def comp_def by auto\n            next\n              case (Some a)\n              have \"t < a\"\n              proof (rule ccontr)\n                assume \"\\<not> t < a\" hence \"a \\<le> t\" by auto\n                have \"a \\<in> keys (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig)\" and \"a \\<le> t'\"\n                  using Some unfolding inf_time_def  by (meson Some inf_time_some_exists)+\n                hence \" purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig \\<noteq> 0\"\n                  unfolding keys_def to_trans_raw_sig_def by auto\n                hence \"\\<tau> a sig \\<noteq> 0\"\n                  unfolding purge_raw'_def combine_trans_bit_def using `a \\<le> t` by auto\n                with assms(2) show False\n                  unfolding context_invariant_def using `a \\<le> t`  by (simp add: zero_fun_def)\n              qed\n              have \"a < t + dly\"\n                using `t' < t + dly`  by (meson Some inf_time_some_exists le_less_trans)\n              have \"a \\<in> fold (\\<union>)\n                  (map (keys \\<circ> (\\<lambda>\\<tau> n. \\<tau> n sig) \\<circ> snd)\n                    (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                      (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])))\n                  {}\"\n              proof (rule ccontr)\n                assume anotin: \"a \\<notin> fold (\\<union>)\n                  (map (keys \\<circ> (\\<lambda>\\<tau> n. \\<tau> n sig) \\<circ> snd)\n                    (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                      (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])))\n                  {}\"\n                have \"purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig \\<noteq> 0\"\n                  using inf_time_some_exists[OF Some] \n                  unfolding keys_def to_trans_raw_sig_def by auto\n                moreover have \"purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig = 0\"\n                  using anotin `a < t + dly` `t < a` unfolding purge_raw'_def combine_trans_bit_def zero_option_def\n                  Let_def to_trans_raw_sig_def by auto\n                ultimately show False \n                  by auto\n              qed\n              hence \" (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig a) = Some\n                             (Lv sign         \n                               (map (\\<lambda>p. bval_of ((to_signal (get_time p) \\<circ> (\\<lambda>\\<tau> sig n. \\<tau> n sig)) (snd p) sig a))\n                                 (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                                   (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))))\"\n                (is \"_ = Some ?comp\") \n                using `t < a` `a < t + dly` unfolding to_trans_raw_sig_def purge_raw'_def combine_trans_bit_def by auto\n              have len: \"b < length (zip (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs]) (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))\"\n                using `b < length bs` by auto\n              have len2: \"b < length (map (\\<lambda>n. (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n))) [0..<length bs])\"\n                using `b < length bs` by auto\n              have len3: \"b < length (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])\"\n                using `b < length bs` by auto\n              have len4: \"b < length ([0..< length bs])\"\n                using `b < length bs` by auto\n              have len5: \"[0 ..< length bs] ! b = b\"\n                using `b < length bs` by auto\n              have \"to_bit b ?comp = Bv (bval_of (signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b))\n                                                             (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)) n) sig a))\"\n                unfolding to_bit.simps comp_def nth_map[OF len] to_trans_raw_sig_def nth_zip[OF len2 len3] nth_map[OF len4] len5 fst_conv \n                snd_conv by auto\n              also have \"... =  Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)\"\n              proof -\n                have \" to_bit b (signal_of (\\<sigma> sig) \\<tau> sig t) = Bv (bs ! b) \\<or> to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (t + dly)) \\<noteq> Bv (bs ! b)\"\n                  using `((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig t = Bv (bs ! b) \\<or> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (t + dly) \\<noteq> Bv (bs ! b)`\n                  unfolding assms(1) worldline_raw_def snd_conv by auto\n                hence \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig t = Bv (bs ! b) \\<or> \n                       signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (t + dly) \\<noteq> Bv (bs ! b)\"\n                  unfolding to_bit_signal_of'_eq[THEN sym] by auto\n                hence \"inf_time (to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)))) sig a = None\"\n                  unfolding to_trans_raw_sig_def purge_raw_def comp_def\n                  using assms(2) unfolding context_invariant_def Let_def inf_time_none_iff[THEN sym]\n                  by (smt \\<open>a < t + dly\\<close> domIff fun_upd_eqD fun_upd_triv greaterThanAtMost_iff leI\n                  le_trans less_imp_le_nat option.simps(4) override_on_apply_in\n                  override_on_apply_notin to_trans_raw_bit_def zero_fun_def zero_option_def)\n                thus ?thesis\n                  unfolding to_signal_def comp_def by auto\n              qed\n              then show ?thesis \n                unfolding to_signal_def comp_def\n                by (smt Some \\<open>Bv (bval_of (signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs !\n                b)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow>\n                b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig a)) = Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv\n                sign bs \\<Rightarrow> bs ! b)\\<close> \\<open>to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig\n                a = Some (Lv sign (map (\\<lambda>p. bval_of ((to_signal (get_time p) \\<circ> (\\<lambda>\\<tau> sig n. \\<tau> n sig))\n                (snd p) sig a)) (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n))\n                [0..<length bs]) (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv\n                (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))))\\<close>\n                calculation option.sel option.simps(5) to_bit.simps(1) to_bit.simps(2) val.case_eq_if\n                val.collapse(1) val.collapse(2))\n            qed \n            finally have \"bval_of (snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig t') = \n                          bval_of (to_bit b (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'))\"\n              by auto }\n          moreover\n          { assume 1: \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! b)\"\n            let ?time = \"(GREATEST n. n \\<le> t + dly  \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b))\"\n            have exist: \"\\<exists>n. t < n \\<and> n \\<le> t + dly  \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b) \"\n            proof (rule ccontr)\n              assume \"\\<not> (\\<exists>n. t < n \\<and> n \\<le> t + dly  \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b))\"\n              hence ind: \"\\<And>n. t < n \\<Longrightarrow> n \\<le> t + dly \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! b)\"\n                by auto\n              { fix n\n                assume \"n \\<le> t + dly\"\n                assume \"t < n\"\n                hence \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! b)\"\n                  using ind 1\n                proof (induction \"n - t\" arbitrary: t dly)\n                  case 0\n                  then show ?case using 1  using le_eq_less_or_eq by auto\n                next\n                  case (Suc m)\n                  hence h0: \"m = n - Suc t\"\n                    by linarith\n                  have h1: \"\\<And>n. Suc t < n \\<Longrightarrow> n \\<le> Suc t + (dly - 1) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! b)\"\n                    using Suc(4) by simp\n                  have h2: \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (Suc t) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (Suc t + (dly - 1)) = Bv (bs ! b)\"\n                    by (metis (no_types, lifting) Suc.prems(2) Suc.prems(3) Suc_pred add_Suc_shift diff_Suc_1 le_add1 le_eq_less_or_eq lessI less_add_same_cancel1)\n                  then show ?case \n                    using Suc.hyps(2)  Suc.hyps(1) Suc.prems(1) Suc_lessI h0 h1 by blast\n                qed }\n              thus False\n                using 1 \\<open>t \\<le> t'\\<close> \\<open>t' < t + dly\\<close> by auto\n            qed\n            hence exist': \"\\<exists>n. n \\<le> t + dly  \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b) \"\n              by auto\n            have \"?time \\<le> t + dly\" and \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time - 1) \\<noteq> Bv (bs ! b)\" and \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig ?time = Bv (bs ! b)\"\n              using GreatestI_ex_nat[OF exist'] by auto\n            have \"t < ?time\"\n            proof (rule ccontr)\n              assume \"\\<not> t < ?time\" hence \"?time \\<le> t\" by auto\n              obtain n where \"t < n\" and \"n \\<le> t + dly\" and \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b)\"\n                and \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)\" using exist by auto\n              hence \"n \\<le> ?time\"\n                using Greatest_le_nat[where k=\"n\" and b=\"t + dly\"] by auto\n              with `t < n` and `?time \\<le> t` show False\n                by auto\n            qed\n            have \"t' < ?time \\<or> ?time \\<le> t'\" by auto\n            moreover            \n            { assume \"?time \\<le> t'\"\n              hence \"bval_of (snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig t') = (bs ! b)\"\n                unfolding * using \\<open>((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig :=\n                to_bit b \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! b)\\<close> by auto\n              also have \"... = bval_of (to_bit b (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'))\"\n              proof (cases \"inf_time (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs))) sig t'\")\n                case None\n                hence \"Ball (dom (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig)) ((<) t')\"\n                  unfolding inf_time_none_iff[THEN sym] by auto\n                have \"to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time - 1)) \\<noteq> Bv (bs ! b)\"\n                  using `((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time - 1) \\<noteq> Bv (bs ! b)` `?time \\<le> t + dly` `t < ?time`\n                  unfolding assms(1) comp_def fun_upd_def worldline_raw_def snd_conv \n                  by presburger\n                moreover have \"to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time)) = Bv (bs ! b)\"\n                  using `((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig ?time = Bv (bs ! b)` `?time \\<le> t + dly` `t < ?time`\n                  unfolding assms(1) comp_def fun_upd_def worldline_raw_def snd_conv \n                  by presburger\n                ultimately have \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) ?time sig \\<noteq> None\"\n                  by (metis (no_types, lifting) signal_of_less_sig to_bit_signal_of' zero_option_def)\n                have h0: \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig t \\<noteq> Bv (bs ! b)\"\n                  using 1 unfolding to_bit_signal_of'_eq assms(1) comp_def fun_upd_def worldline_raw_def snd_conv \n                  using to_bit_signal_of'_eq by fastforce\n                have h1: \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (t + dly) = Bv (bs ! b)\"\n                  using 1 unfolding to_bit_signal_of'_eq assms(1) comp_def fun_upd_def worldline_raw_def snd_conv \n                  using to_bit_signal_of'_eq by fastforce\n                have exist_mapping: \"\\<exists>n>t. n \\<le> t + dly \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig n sig = Some (Bv (bs ! b))\"\n                  using switch_signal_ex_mapping_gen[OF h0 h1]\n                  by (simp add: \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> to_trans_raw_bit_def zero_fun_def zero_option_def)\n                have *: \"length (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs]) = \n                             length (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig\n                               (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n)))\n                      [0..<length bs])\"\n                  by auto  \n                have \"purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig\n                           (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)) ?time sig \\<noteq> None \n                  \\<or> purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig\n                           (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)) ?time sig = None\"\n                  by auto\n                moreover\n                { assume purge_neq_none: \"purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig\n                           (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)) ?time sig \\<noteq> None\"\n                  hence time_in: \"?time \\<in> fold (\\<union>) (map (keys \\<circ> (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> snd)\n                (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                     (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig\n                             (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n)))\n                    [0..<length bs]))) {}\"\n                    using `b < length bs` \n                    unfolding map_map[THEN sym] map_snd_zip[OF *] member_fold_union2\n                    keys_def zero_option_def  by (auto intro!: bexI[where x=\"b\"] simp add: to_trans_raw_sig_def) \n                  have \"purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) ?time sig = \n                        combine_trans_bit \\<tau>\n                        (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                          (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig\n                                     (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n)))\n                            [0..<length bs]))\n                        sign sig t dly ?time sig\"\n                    unfolding purge_raw'_def by auto\n                  also have \"... \\<noteq> None\"\n                    unfolding combine_trans_bit_def \n                    using time_in \\<open>?time \\<le> t + dly\\<close> \\<open>t < ?time\\<close> by auto\n                  finally have False\n                  proof -\n                    assume a1: \"purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) sig \\<noteq> None\"\n                    have \"\\<not> t' < (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b))\"\n                      using \\<open>(GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) \\<le> t'\\<close> leD by blast\n                    then show ?thesis\n                      using a1 by (simp add: \\<open>Ball (dom (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig)) ((<) t')\\<close> domIff to_trans_raw_sig_def)\n                  qed\n                  hence \" bs ! b = bval_of (to_bit b (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'))\"\n                    by auto }\n                moreover\n                { assume \"purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)) ?time sig = None\"\n                  hence \"?time < the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) \n                       \\<or> the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) < ?time\"\n                    using `t < ?time` `?time \\<le> t'` `t' < t + dly` h0 h1\n                    unfolding purge_raw_def Let_def \n                    by (smt Un_iff \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time sig \\<noteq> None\\<close> greaterThanAtMost_iff\n                    greaterThanLessThan_iff override_on_apply_notin)\n                  moreover have \"the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) < ?time \\<Longrightarrow> False\"\n                  proof -\n                    assume \"the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) < ?time\"\n                    have \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly) \\<noteq> None\"\n                    proof -\n                      have \"None \\<noteq> to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b))\"\n                        by (metis \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) sig \\<noteq> None\\<close> to_trans_raw_sig_def)\n                      then show ?thesis\n                        using \\<open>(GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) \\<le> t + dly\\<close> inf_time_noneE2 zero_option_def by fastforce\n                    qed\n                    then obtain time' where \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly) = Some time'\"\n                      by auto\n                    hence \"to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig ?time = None\"\n                      using \\<open>?time \\<le> t + dly\\<close> \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t +\n                      dly)) < ?time\\<close> inf_time_someE by fastforce\n                    with `(to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) ?time sig \\<noteq> None` show False\n                      by (simp add: to_trans_raw_sig_def)\n                  qed\n                  ultimately have \"?time < the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly))\" (is \"_ < ?time'\")\n                    by auto\n                  obtain val where \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time sig = Some val\" \n                    using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time sig \\<noteq> None\\<close> by auto\n                  hence \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig ?time = val\"\n                    using trans_some_signal_of'[where \\<tau>=\"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig\" and n=\"?time\" and \\<sigma>=\"(\\<lambda>x. _)(sig:= val)\"]\n                    by auto\n                  hence \"val = Bv (bs ! b)\"\n                    using to_bit_signal_of'[OF \\<open>to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time)) = Bv (bs ! b)\\<close>]\n                    by auto\n                  have \"\\<exists>k\\<in>keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig). k \\<le> t + dly\"\n                    by (metis (mono_tags, lifting) \\<open>?time \\<le> t + dly\\<close> \\<open>\\<And>thesis. (\\<And>val.\n                    to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time sig = Some val \\<Longrightarrow> thesis) \\<Longrightarrow> thesis\\<close> keys_def\n                    mem_Collect_eq option.simps(3) to_trans_raw_sig_def zero_option_def)\n                  hence time'_eq: \"?time' = (GREATEST k. k \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig) \\<and> k \\<le> t + dly)\"\n                    unfolding inf_time_def by auto\n                  hence \"?time' \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\" and \"?time' \\<le> t + dly\"\n                    using GreatestI_ex_nat \n                    by (metis (mono_tags, lifting) \\<open>\\<exists>k\\<in>keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig). k \\<le> t + dly\\<close> inf_time_def inf_time_ex1 inf_time_some_exists)+\n                  have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig = to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time sig\"\n                  proof (rule ccontr)\n                    assume \"\\<not> to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig ?time' sig = to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig ?time sig\"\n                    hence \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig ?time =  val\"\n                      using trans_some_signal_of'[of \"to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig\" \"?time\" \"sig\" \"(\\<lambda>x. _)(sig := val)\"]\n                      using \\<open>to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig :=\n                      to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ>\n                      snd \\<omega> sig)) sig n = Bv (bs ! b)) sig = Some val\\<close> by auto\n                    then obtain val' where \"to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig ?time' sig = Some val'\"\n                    proof -\n                      assume \"\\<And>val'. to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly))) sig = Some val' \\<Longrightarrow> thesis\"\n                      then show ?thesis\n                        by (metis \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig)\\<close> domIff dom_def keys_def not_None_eq to_trans_raw_sig_def zero_option_def)\n                    qed\n                    hence \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig ?time' =  val'\"\n                      using trans_some_signal_of'[of \"to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig\" \"?time\" \"sig\" \"(\\<lambda>x. _)(sig := val')\"] time'_eq\n                      by (meson trans_some_signal_of')\n                    also have \"... \\<noteq> val\"\n                      using \\<open>to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) sig = Some val\\<close> \\<open>to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly))) sig = Some val'\\<close> \\<open>to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly))) sig \\<noteq> to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) sig\\<close> by auto\n                    finally have \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig ?time' \\<noteq> \n                                  signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig ?time \"\n                      using \\<open>signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) = val\\<close> by blast\n                    have \"t < ?time'\"\n                      using \\<open>?time < the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly))\\<close> \\<open>t < (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b))\\<close> by linarith\n                    have \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time') = signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig ?time'\"\n                      using `t < ?time'` to_bit_signal_of'_eq unfolding assms(1) time'_eq worldline_raw_def snd_conv fun_upd_def  by fastforce\n                    moreover have \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time) = signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig ?time\"\n                      using `t < ?time` to_bit_signal_of'_eq unfolding assms(1) time'_eq worldline_raw_def snd_conv fun_upd_def  by fastforce\n                    ultimately have \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time') \\<noteq> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time)\"\n                      using \\<open>signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly))) \\<noteq> signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b))\\<close> by auto\n                      \n                    have \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig ?time' = val'\"\n                      using trans_some_signal_of'[of \"to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig\" \"?time'\" \"sig\" \"(\\<lambda>x. _)(sig := val')\"] \\<open>to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig ?time' sig = Some val'\\<close>\n                      by auto\n                    have \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly))) = \n                          inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly)\"\n                      using time'_eq \n                    proof -\n                      obtain nn :: nat where\n                        f1: \"nn \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig) \\<and> nn \\<le> t + dly\"\n                          using \\<open>\\<exists>k\\<in>keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig). k \\<le> t + dly\\<close> by blast\n                        have f2: \"to_signal (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv s bs \\<Rightarrow> bs ! b)) (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly) = Bv (bs ! b)\"\n                      using h1 by auto\n                      have f3: \"\\<forall>v n a f. to_signal v f (a::'a) n = the (f a (the (inf_time f a n))) \\<or> inf_time f a n = None\"\n                        by (simp add: option.case_eq_if to_signal_def)\n                        have f4: \"\\<forall>f. f (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly)))) = f (Some val')\"\n                      by (metis (no_types) \\<open>to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly))) sig = Some val'\\<close> to_trans_raw_sig_def)\n                        have \"Bv (bs ! b) \\<noteq> val'\"\n                          by (metis (no_types) \\<open>((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) = Bv (bs ! b)\\<close> \\<open>((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly))) = signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly)))\\<close> \\<open>((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly))) \\<noteq> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b))\\<close> \\<open>signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly))) = val'\\<close>)\n                      then have f5: \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly) = None\"\n                      using f4 f3 f2 option.sel \n                        by (metis \\<open>to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly))) sig = Some val'\\<close> to_trans_raw_sig_def)\n                      have \"\\<forall>n. Some (GREATEST na. na \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig) \\<and> na \\<le> n) = inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig n \\<or> \\<not> nn \\<le> n\"\n                      using f1 by (simp add: inf_time_def)\n                        then show ?thesis\n                      using f5 f1 by force\n                    qed\n                    hence \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig (t + dly) = \n                          signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig ?time'\"\n                      unfolding to_signal_def comp_def by auto\n                    hence \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig ?time' = Bv (bs ! b)\"\n                      using h1 by auto\n                    have \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time) = Bv (bs ! b)\"\n                      using \\<open>((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time) = Bv (bs ! b)\\<close> by blast\n                    have \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time') = Bv (bs ! b)\"\n                      using \\<open>((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time') = signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig ?time'\\<close>\n                      using \\<open>signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly))) = Bv (bs ! b)\\<close> by auto\n                    show False\n                      using \\<open>((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) = Bv (bs ! b)\\<close> \\<open>((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly))) = Bv (bs ! b)\\<close> \\<open>((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> b sig)) sig (t + dly))) \\<noteq> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b))\\<close> by auto\n                  qed\n                  have \"?time = ?time'\"\n                  proof (rule Greatest_equality)\n                    have \"t \\<le> ?time' - 1\" using \\<open>?time < ?time'\\<close> \\<open>t < ?time\\<close> by linarith\n                    moreover have \"to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time' - 1)) \\<noteq> Bv (bs ! b)\"\n                      unfolding to_bit_signal_of'_eq[THEN sym]\n                    proof (cases \"\\<exists>n. t < n \\<and> n < ?time' \\<and> (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) n sig \\<noteq> None\")\n                      case False\n                      hence none: \"\\<And>n. t < n \\<Longrightarrow> n \\<le> ?time' - 1 \\<Longrightarrow> (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) n sig = 0\"\n                        by (auto simp add: zero_option_def)\n                      have \" signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (?time' - 1) = \n                              signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig t\"\n                        using signal_of_less_ind'[of \"t\" \"?time' - 1\" \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig\" \"sig\", OF none] `t \\<le> ?time' - 1`\n                        by auto                    \n                      also have \"... \\<noteq> (Bv (bs ! b))\"\n                        using h0 to_bit_signal_of'_eq by force\n                      finally show \" signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (?time' - 1) \\<noteq> (Bv (bs ! b))\"\n                        by auto\n                    next\n                      case True\n                      let ?key1 = \"(GREATEST n. t < n \\<and> n < ?time' \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig n sig \\<noteq> None)\"\n                      from True have \"t < ?key1\" and \"?key1 < ?time'\" and \" to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig \\<noteq> None\"\n                        using GreatestI_ex_nat[OF True]  using less_imp_le_nat by blast+\n                      have *: \"\\<And>n. n > ?key1 \\<Longrightarrow> n < ?time' \\<Longrightarrow> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig n sig = None\"\n                        using Greatest_le_nat[where P=\"\\<lambda>x. t < x \\<and> x < ?time' \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig x sig \\<noteq> None\" and b=\"?time'\"]\n                        by (smt \\<open>t < (GREATEST n. t < n \\<and> n < the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig n sig \\<noteq> None)\\<close> leD less_imp_le_nat less_trans)\n                      have inf_some: \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (?time' - 1) = Some ?key1\"\n                      proof (rule inf_time_someI)\n                        show \"?key1 \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n                          using `to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig \\<noteq> None`  by (simp add: domIff to_trans_raw_sig_def)\n                      next\n                        show \"?key1 \\<le> ?time' - 1\"\n                          using `?key1 < ?time'`  by linarith\n                      next\n                        { fix ta\n                          assume \"ta \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n                          assume \"ta \\<le> ?time' - 1\"\n                          assume \"?key1 < ta\"\n                          hence \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ta sig = None\"\n                            using *[OF `?key1 < ta`] `ta \\<le> ?time' - 1` by simp\n                          hence \"ta \\<notin> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n                            by (simp add: domIff to_trans_raw_sig_def)\n                          with `ta \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)` have False by auto }\n                        thus \"\\<forall>ta \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig). ta \\<le> ?time' - 1 \\<longrightarrow> ta \\<le> ?key1\"\n                          using not_le_imp_less by blast\n                      qed\n                      have non_stut: \" non_stuttering (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) (to_bit b o \\<sigma>) sig\"\n                        using assms(5) non_stuttering_to_trans_raw_bit by force\n                      hence \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig  ?key1 sig) \\<noteq> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig\"\n                      proof -\n                        have \"?key1 \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n                          using `to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig \\<noteq> None`  by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n                        moreover have \"?time' \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n                          using \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\\<close> by blast\n                        moreover have \"\\<forall>k. ?key1 < k \\<and> k < ?time' \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n                          using *  by (metis (mono_tags, lifting) domIff keys_def mem_Collect_eq to_trans_raw_sig_def\n                          zero_option_def)\n                        ultimately show ?thesis    \n                          using `?key1 < ?time'` non_stut unfolding non_stuttering_def\n                          by (simp add: to_trans_raw_sig_def)\n                      qed\n                      moreover have \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig) = Some (Bv (bs ! b))\"\n                      proof -\n                        have \"the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig) = the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time sig)\"\n                          using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig = to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time sig\\<close> by auto\n                        also have \"... = Bv (bs ! b)\"\n                          using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) sig = Some val\\<close> \\<open>val = Bv (bs ! b)\\<close> by auto\n                        finally show ?thesis\n                          using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (?time) sig = Some val\\<close>\n                          \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (the (inf_time (to_trans_raw_sig\n                          (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly))) sig = to_trans_raw_bit\n                          (\\<sigma> sig) \\<tau> b sig (?time) sig\\<close> by auto\n                      qed\n                      ultimately have neq: \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig) \\<noteq> Some (Bv (bs ! b))\"\n                        by auto\n                      then obtain valu where \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig) = Some valu\" and \"valu \\<noteq> Bv (bs ! b)\"\n                        using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig \\<noteq> None\\<close> by blast\n                      have \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (?time' - 1) = \n                            the (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig ?key1)\"\n                        using inf_some unfolding to_signal_def comp_def\n                        by auto\n                      also have \"... \\<noteq> Bv (bs ! b)\"\n                        using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig \\<noteq> None\\<close> neq \n                        by (metis \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (GREATEST n. t < n \\<and> n < the\n                        (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly))\n                        \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig n sig \\<noteq> None) sig = Some valu\\<close> option.sel\n                        to_trans_raw_sig_def)\n                      finally show \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (?time' - 1) \\<noteq> (Bv (bs ! b))\"\n                        by blast\n                    qed\n                    ultimately have \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time' - 1) = to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time' - 1))\"\n                      unfolding assms(1) worldline_raw_def snd_conv fun_upd_def comp_def by auto\n                    hence *: \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time' - 1) \\<noteq> Bv (bs ! b)\"\n                      using \\<open>to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time' - 1)) \\<noteq> Bv (bs ! b)\\<close> by auto\n                    have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig = Some (Bv (bs ! b))\"\n                      using \\<open>t \\<le> ?time' - 1\\<close> exist_mapping\n                      using GreatestI_ex_nat[where P=\"\\<lambda>n. n \\<le> t + dly \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig n sig = Some (Bv (bs ! b))\" and b=\"t + dly\"]\n                      using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time sig = Some val\\<close> \n                            \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig = to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time sig\\<close> \\<open>val = Bv (bs ! b)\\<close> by auto\n                    have \"to_bit b (signal_of (\\<sigma> sig) \\<tau> sig ?time') = (Bv (bs ! b))\"\n                      using trans_some_signal_of'[of \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig\", OF `to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig = Some (Bv (bs ! b))`]\n                      using to_bit_signal_of'_eq by fastforce\n                    hence \" ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly))) = Bv (bs ! b)\"\n                      unfolding assms(1) worldline_raw_def snd_conv fun_upd_def comp_def \n                      using \\<open>t \\<le> the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) - 1\\<close> by auto\n                    thus \"?time' \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time' - 1) \\<noteq> Bv (bs ! b) \\<and>\n                                             ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig ?time' = Bv (bs ! b)\"    \n                      using * `?time' \\<le> t + dly` by auto  \n                  next\n                    have \"t \\<le> ?time' - 1\" using \\<open>?time < ?time'\\<close> \\<open>t < ?time\\<close> by linarith\n                    fix y\n                    assume \"y \\<le> t + dly \\<and>  ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (y - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig y = Bv (bs ! b)\"\n                    hence \"y \\<le> t + dly\" and \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (y - 1) \\<noteq> Bv (bs ! b)\" and \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (y) = Bv (bs ! b)\"\n                      by auto\n                    have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig = Some (Bv (bs ! b))\"\n                      using \\<open>t \\<le> ?time' - 1\\<close> exist_mapping\n                      using GreatestI_ex_nat[where P=\"\\<lambda>n. n \\<le> t + dly \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig n sig = Some (Bv (bs ! b))\" and b=\"t + dly\"]\n                      using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time sig = Some val\\<close> \n                            \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig = to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time sig\\<close> \\<open>val = Bv (bs ! b)\\<close> by auto\n                    hence \"t < ?time'\"\n                      by (meson \\<open>t < ?time\\<close> \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) < (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) \\<Longrightarrow> False\\<close> le_less_trans not_le)\n                    have \"y \\<le> t \\<or> t < y\"\n                      by auto\n                    moreover\n                    { assume \"y \\<le> t\"\n                      hence \"y < ?time'\" using `t < ?time'` by linarith }\n                    moreover\n                    { assume \"t < y\"\n                      hence \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (y - 1) =  to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (y - 1))\"\n                        unfolding assms(1) worldline_raw_def snd_conv fun_upd_def comp_def  by auto\n                      hence 0: \"... \\<noteq> (Bv (bs ! b))\"\n                        using \\<open>((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (y - 1) \\<noteq> Bv (bs ! b)\\<close> by auto\n                      have \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig y =  to_bit b (signal_of (\\<sigma> sig) \\<tau> sig y)\"\n                        using `t < y`  unfolding assms(1) worldline_raw_def snd_conv fun_upd_def comp_def  by auto\n                      hence 1: \"... = Bv (bs ! b)\"\n                        using \\<open>((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig y = Bv (bs ! b)\\<close> by auto\n                      have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = Some (Bv (bs ! b))\"\n                      proof (rule ccontr)\n                        assume \"\\<not> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = Some (Bv (bs ! b))\"\n                        then obtain x' where \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = None \\<or> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = Some x' \\<and> x' \\<noteq> (Bv (bs ! b))\"\n                          using domIff by fastforce\n                        moreover\n                        { assume \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = None\"\n                          hence \"signal_of (\\<sigma> sig) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig y = \n                                 signal_of (\\<sigma> sig) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (y - 1)\"\n                            by (intro signal_of_less_sig)(simp add: zero_option_def)\n                          with 0 1 have False \n                            by (metis \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = None\\<close> signal_of_less_sig to_bit_signal_of' zero_option_def) }\n                        moreover\n                        { assume \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = Some x' \\<and> x' \\<noteq> (Bv (bs ! b))\"\n                          hence \"signal_of ((Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b))) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig y = x'\" and \"x' \\<noteq> (Bv (bs ! b))\"\n                            using trans_some_signal_of' by fastforce+\n                          with 1 have False \n                            unfolding to_bit_signal_of'_eq by auto }\n                        ultimately show False\n                          by auto\n                      qed\n                      with `y \\<le> t + dly` have \"y \\<le> ?time'\"\n                        unfolding time'_eq \n                        apply (intro Greatest_le_nat)\n                        unfolding keys_def to_trans_raw_sig_def zero_option_def by auto }\n                    ultimately show \"y \\<le> ?time'\"\n                      by auto\n                  qed\n                  hence False\n                    using `?time < ?time'` by auto\n                  hence \" bs ! b = bval_of (to_bit b (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'))\"\n                    by auto }\n                ultimately show \" bs ! b = bval_of (to_bit b (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'))\"\n                  by auto\n              next\n                case (Some a)\n                hence \"signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t' = the (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig)\"\n                  by (simp add: to_signal_def to_trans_raw_sig_def)\n                have \"\\<forall>t\\<in>dom (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig). t \\<le> t' \\<longrightarrow> t \\<le> a\"\n                  using inf_time_someE[OF Some] by auto\n                have \"to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time - 1)) \\<noteq> Bv (bs ! b)\"\n                  using `((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time - 1) \\<noteq> Bv (bs ! b)` `?time \\<le> t + dly` `t < ?time`\n                  unfolding assms(1) comp_def fun_upd_def worldline_raw_def snd_conv \n                  by presburger\n                moreover have \"to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time)) = Bv (bs ! b)\"\n                  using `((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig ?time = Bv (bs ! b)` `?time \\<le> t + dly` `t < ?time`\n                  unfolding assms(1) comp_def fun_upd_def worldline_raw_def snd_conv \n                  by presburger\n                ultimately have \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) ?time sig \\<noteq> None\"\n                  by (metis (no_types, lifting) signal_of_less_sig to_bit_signal_of' zero_option_def)\n                have h0: \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig t \\<noteq> Bv (bs ! b)\"\n                  using 1 unfolding to_bit_signal_of'_eq assms(1) comp_def fun_upd_def worldline_raw_def snd_conv \n                  using to_bit_signal_of'_eq by fastforce\n                have h1: \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (t + dly) = Bv (bs ! b)\"\n                  using 1 unfolding to_bit_signal_of'_eq assms(1) comp_def fun_upd_def worldline_raw_def snd_conv \n                  using to_bit_signal_of'_eq by fastforce\n                let ?time' = \"the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly))\"\n                obtain val where \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time sig = Some val\" \n                    using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time sig \\<noteq> None\\<close> by auto\n                have \"\\<exists>k\\<in>keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig). k \\<le> t + dly\"\n                 by (metis (mono_tags, lifting) \\<open>?time \\<le> t + dly\\<close> \\<open>\\<And>thesis. (\\<And>val.\n                    to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time sig = Some val \\<Longrightarrow> thesis) \\<Longrightarrow> thesis\\<close> keys_def\n                    mem_Collect_eq option.simps(3) to_trans_raw_sig_def zero_option_def)\n                hence time'_eq: \"?time' = (GREATEST k. k \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig) \\<and> k \\<le> t + dly)\"\n                  unfolding inf_time_def by auto\n                hence \"?time' \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\" and \"?time' \\<le> t + dly\"\n                  using GreatestI_ex_nat \n                  by (metis (mono_tags, lifting) \\<open>\\<exists>k\\<in>keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig). k \\<le> t + dly\\<close> inf_time_def inf_time_ex1 inf_time_some_exists)+\n                have \"the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig) = Bv (bs ! b)\"\n                proof -\n                  have \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly) = Some ?time'\"\n                    by (simp add: \\<open>\\<exists>k\\<in>keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig). k \\<le> t + dly\\<close> inf_time_def)\n                  thus \"the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig) = Bv (bs ! b)\"\n                    using h1 unfolding to_signal_def comp_def \n                    by (metis option.simps(5) to_trans_raw_sig_def)\n                qed\n                have \"the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time sig) = Bv (bs ! b)\"\n                proof- \n                  have \" signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig ?time = Bv (bs ! b)\"\n                    using \\<open>to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time)) = Bv (bs ! b)\\<close>\n                    unfolding to_bit_signal_of'_eq[THEN sym] by auto\n                  moreover have \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig ?time = Some ?time\"\n                  proof (intro inf_time_someI)\n                    show \"?time \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n                    proof -\n                    have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) sig \\<noteq> None\"\n                      by (metis (full_types) \\<open>\\<And>thesis. (\\<And>val. to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) sig = Some val \\<Longrightarrow> thesis) \\<Longrightarrow> thesis\\<close> option.simps(3))\n                    then show ?thesis\n                        by (simp add: domIff to_trans_raw_sig_def)\n                    qed\n                  qed (auto)\n                  ultimately show ?thesis\n                    unfolding to_signal_def comp_def \n                    by (simp add: to_trans_raw_sig_def)\n                qed\n                have \"?time = ?time'\"\n                proof (rule Greatest_equality)\n                  have \"t \\<le> ?time' - 1\" \n                  proof (rule ccontr)\n                    assume \"\\<not> t \\<le> ?time' - 1\" hence \"?time' - 1 < t\"\n                      by auto\n                    hence \"?time' \\<le> t\" by auto\n                    hence \"\\<tau> ?time' sig = None\"\n                      using assms(2) unfolding context_invariant_def by (auto simp add: zero_fun_def zero_option_def)\n                    have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig \\<noteq> None\"\n                      using \\<open>?time' \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\\<close> \n                      by (metis domIff dom_is_keys to_trans_raw_sig_def)\n                    thus \"False\"\n                      using \\<open>\\<tau> ?time' sig = None\\<close> unfolding to_trans_raw_bit_def by auto\n                  qed\n                  moreover have \"to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time' - 1)) \\<noteq> Bv (bs ! b)\"\n                    unfolding to_bit_signal_of'_eq[THEN sym]\n                  proof (cases \"\\<exists>n. t < n \\<and> n < ?time' \\<and> (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) n sig \\<noteq> None\")\n                    case False\n                    hence none: \"\\<And>n. t < n \\<Longrightarrow> n \\<le> ?time' - 1 \\<Longrightarrow> (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) n sig = 0\"\n                      by (auto simp add: zero_option_def)\n                    have \" signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (?time' - 1) = \n                            signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig t\"\n                      using signal_of_less_ind'[of \"t\" \"?time' - 1\" \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig\" \"sig\", OF none] `t \\<le> ?time' - 1`\n                      by auto                    \n                    also have \"... \\<noteq> (Bv (bs ! b))\"\n                      using h0 to_bit_signal_of'_eq by force\n                    finally show \" signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (?time' - 1) \\<noteq> (Bv (bs ! b))\"\n                      by auto\n                  next\n                    case True\n                    let ?key1 = \"(GREATEST n. t < n \\<and> n < ?time' \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig n sig \\<noteq> None)\"\n                    from True have \"t < ?key1\" and \"?key1 < ?time'\" and \" to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig \\<noteq> None\"\n                      using GreatestI_ex_nat[OF True]  using less_imp_le_nat by blast+\n                    have *: \"\\<And>n. n > ?key1 \\<Longrightarrow> n < ?time' \\<Longrightarrow> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig n sig = None\"\n                      using Greatest_le_nat[where P=\"\\<lambda>x. t < x \\<and> x < ?time' \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig x sig \\<noteq> None\" and b=\"?time'\"]\n                      by (smt \\<open>t < (GREATEST n. t < n \\<and> n < the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig n sig \\<noteq> None)\\<close> leD less_imp_le_nat less_trans)\n                    have inf_some: \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (?time' - 1) = Some ?key1\"\n                    proof (rule inf_time_someI)\n                      show \"?key1 \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n                        using `to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig \\<noteq> None`  by (simp add: domIff to_trans_raw_sig_def)\n                    next\n                      show \"?key1 \\<le> ?time' - 1\"\n                        using `?key1 < ?time'`  by linarith\n                    next\n                      { fix ta\n                        assume \"ta \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n                        assume \"ta \\<le> ?time' - 1\"\n                        assume \"?key1 < ta\"\n                        hence \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ta sig = None\"\n                          using *[OF `?key1 < ta`] `ta \\<le> ?time' - 1` by simp\n                        hence \"ta \\<notin> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n                          by (simp add: domIff to_trans_raw_sig_def)\n                        with `ta \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)` have False by auto }\n                      thus \"\\<forall>ta \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig). ta \\<le> ?time' - 1 \\<longrightarrow> ta \\<le> ?key1\"\n                        using not_le_imp_less by blast\n                    qed\n                    have non_stut: \" non_stuttering (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) (to_bit b o \\<sigma>) sig\"\n                      using assms(5) non_stuttering_to_trans_raw_bit by force\n                    hence \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig  ?key1 sig) \\<noteq> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig\"\n                    proof -\n                      have \"?key1 \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n                        using `to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig \\<noteq> None`  by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n                      moreover have \"?time' \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n                        using \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\\<close> by blast\n                      moreover have \"\\<forall>k. ?key1 < k \\<and> k < ?time' \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n                        using *  by (metis (mono_tags, lifting) domIff keys_def mem_Collect_eq to_trans_raw_sig_def\n                        zero_option_def)\n                      ultimately show ?thesis    \n                        using `?key1 < ?time'` non_stut unfolding non_stuttering_def\n                        by (simp add: to_trans_raw_sig_def)\n                    qed\n                    moreover have \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig) = Some (Bv (bs ! b))\"\n                      by (metis \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\\<close> \\<open>the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly))) sig) = Bv (bs ! b)\\<close> domIff dom_def keys_def option.exhaust_sel to_trans_raw_sig_def zero_option_def)\n                    ultimately have neq: \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig) \\<noteq> Some (Bv (bs ! b))\"\n                      by auto\n                    then obtain valu where \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig) = Some valu\" and \"valu \\<noteq> Bv (bs ! b)\"\n                      using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig \\<noteq> None\\<close> by blast\n                    have \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (?time' - 1) = \n                          the (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig ?key1)\"\n                      using inf_some unfolding to_signal_def comp_def\n                      by auto\n                    also have \"... \\<noteq> Bv (bs ! b)\"\n                      using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig \\<noteq> None\\<close> neq \n                      by (metis \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (GREATEST n. t < n \\<and> n < the\n                      (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly))\n                      \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig n sig \\<noteq> None) sig = Some valu\\<close> option.sel\n                      to_trans_raw_sig_def)\n                    finally show \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (?time' - 1) \\<noteq> (Bv (bs ! b))\"\n                      by blast\n                  qed\n                  ultimately have \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time' - 1) = to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time' - 1))\"\n                    unfolding assms(1) worldline_raw_def snd_conv fun_upd_def comp_def by auto\n                  hence *: \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time' - 1) \\<noteq> Bv (bs ! b)\"\n                    using \\<open>to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time' - 1)) \\<noteq> Bv (bs ! b)\\<close> by auto\n                  have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig = Some (Bv (bs ! b))\"\n                    by (metis \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\\<close> \\<open>the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly))) sig) = Bv (bs ! b)\\<close> domIff dom_def keys_def option.exhaust_sel to_trans_raw_sig_def zero_option_def)\n                  have \"to_bit b (signal_of (\\<sigma> sig) \\<tau> sig ?time') = (Bv (bs ! b))\"\n                    using trans_some_signal_of'[of \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig\", OF `to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig = Some (Bv (bs ! b))`]\n                    using to_bit_signal_of'_eq by fastforce\n                  hence \" ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly))) = Bv (bs ! b)\"\n                    unfolding assms(1) worldline_raw_def snd_conv fun_upd_def comp_def \n                    using \\<open>t \\<le> the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) - 1\\<close> by auto\n                  thus \"?time' \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time' - 1) \\<noteq> Bv (bs ! b) \\<and>\n                                           ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig ?time' = Bv (bs ! b)\"    \n                    using * `?time' \\<le> t + dly` by auto  \n                next\n                  have \"t \\<le> ?time' - 1\" \n                  proof (rule ccontr)\n                    assume \"\\<not> t \\<le> ?time' - 1\" hence \"?time' - 1 < t\"\n                      by auto\n                    hence \"?time' \\<le> t\" by auto\n                    hence \"\\<tau> ?time' sig = None\"\n                      using assms(2) unfolding context_invariant_def by (auto simp add: zero_fun_def zero_option_def)\n                    have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig \\<noteq> None\"\n                      using \\<open>?time' \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\\<close> \n                      by (metis domIff dom_is_keys to_trans_raw_sig_def)\n                    thus \"False\"\n                      using \\<open>\\<tau> ?time' sig = None\\<close> unfolding to_trans_raw_bit_def by auto\n                  qed\n                  fix y\n                  assume \"y \\<le> t + dly \\<and>  ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (y - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig y = Bv (bs ! b)\"\n                  hence \"y \\<le> t + dly\" and \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (y - 1) \\<noteq> Bv (bs ! b)\" and \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (y) = Bv (bs ! b)\"\n                    by auto\n                  have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig = Some (Bv (bs ! b))\"\n                    by (metis \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\\<close> \\<open>the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly))) sig) = Bv (bs ! b)\\<close> domIff dom_def keys_def option.exhaust_sel to_trans_raw_sig_def zero_option_def)\n                  hence \"t < ?time'\"\n                    by (smt \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> \\<open>the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) sig) = Bv (bs ! b)\\<close> \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) sig = Some val\\<close> \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) sig \\<noteq> None\\<close> leI option.sel option.simps(4) to_trans_raw_bit_def zero_fun_def zero_option_def)\n                  have \"y \\<le> t \\<or> t < y\"\n                    by auto\n                  moreover\n                  { assume \"y \\<le> t\"\n                    hence \"y < ?time'\" using `t < ?time'` by linarith }\n                  moreover\n                  { assume \"t < y\"\n                    hence \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (y - 1) =  to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (y - 1))\"\n                      unfolding assms(1) worldline_raw_def snd_conv fun_upd_def comp_def  by auto\n                    hence 0: \"... \\<noteq> (Bv (bs ! b))\"\n                      using \\<open>((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (y - 1) \\<noteq> Bv (bs ! b)\\<close> by auto\n                    have \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig y =  to_bit b (signal_of (\\<sigma> sig) \\<tau> sig y)\"\n                      using `t < y`  unfolding assms(1) worldline_raw_def snd_conv fun_upd_def comp_def  by auto\n                    hence 1: \"... = Bv (bs ! b)\"\n                      using \\<open>((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig y = Bv (bs ! b)\\<close> by auto\n                    have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = Some (Bv (bs ! b))\"\n                    proof (rule ccontr)\n                      assume \"\\<not> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = Some (Bv (bs ! b))\"\n                      then obtain x' where \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = None \\<or> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = Some x' \\<and> x' \\<noteq> (Bv (bs ! b))\"\n                        using domIff by fastforce\n                      moreover\n                      { assume \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = None\"\n                        hence \"signal_of (\\<sigma> sig) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig y = \n                               signal_of (\\<sigma> sig) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (y - 1)\"\n                          by (intro signal_of_less_sig)(simp add: zero_option_def)\n                        with 0 1 have False \n                          by (metis \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = None\\<close> signal_of_less_sig to_bit_signal_of' zero_option_def) }\n                      moreover\n                      { assume \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = Some x' \\<and> x' \\<noteq> (Bv (bs ! b))\"\n                        hence \"signal_of ((Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b))) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig y = x'\" and \"x' \\<noteq> (Bv (bs ! b))\"\n                          using trans_some_signal_of' by fastforce+\n                        with 1 have False \n                          unfolding to_bit_signal_of'_eq by auto }\n                      ultimately show False\n                        by auto\n                    qed\n                    with `y \\<le> t + dly` have \"y \\<le> ?time'\"\n                      unfolding time'_eq \n                      apply (intro Greatest_le_nat)\n                      unfolding keys_def to_trans_raw_sig_def zero_option_def by auto }\n                  ultimately show \"y \\<le> ?time'\"\n                    by auto\n                qed\n                have \"?time' \\<le> a\"\n                proof (rule ccontr)\n                  have len_map: \"length (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]) \\<le> length bs - 0\"\n                    by auto\n                  assume \"\\<not> ?time' \\<le> a\" hence \"a \\<le> ?time'\" by auto\n                  hence \"purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) ?time' sig = None\"\n                    using Some \\<open>\\<forall>t\\<in>dom (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig). t \\<le> t' \\<longrightarrow> t \\<le> a\\<close>\n                    by (metis `?time = ?time'` \\<open>?time \\<le> t'\\<close> \\<open>\\<not> ?time' \\<le> a\\<close> domIff to_trans_raw_sig_def)\n                  hence \"?time' \\<notin> fold (\\<union>)\n                        (map (keys \\<circ> (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> snd)\n                        (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                             (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))) {}\"\n                    unfolding purge_raw'_def combine_trans_bit_def Let_def\n                    using \\<open>?time = ?time'\\<close> \\<open>t < ?time\\<close> \\<open>?time \\<le> t + dly\\<close> by auto\n                  hence \"?time' \\<notin> keys (to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig)\"\n                    using \\<open>b < length bs\\<close>  unfolding map_map[THEN sym] map_snd_zip_take length_map min.idem length_upt take_all[OF len_map] member_fold_union2 by auto\n                  moreover have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (the (inf_time (\\<lambda>siga n. to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig n siga) sig (t + dly))) sig \\<noteq> 0\"\n                    using \\<open>?time' \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\\<close> unfolding keys_def to_trans_raw_sig_def by auto\n                  ultimately show \"False\"\n                    using h0 h1\n                    unfolding to_trans_raw_sig_def keys_def purge_raw_def Let_def by auto\n                qed\n                have \"t < a\"\n                proof (rule ccontr)\n                  assume \"\\<not> t < a\" hence \"a \\<le> t\" by auto\n                  hence \"purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig = None\"\n                    unfolding purge_raw'_def combine_trans_bit_def Let_def \n                    using assms(2) unfolding context_invariant_def by (auto simp add: zero_fun_def zero_option_def)\n                  with Some show False\n                    by (metis (mono_tags, lifting) inf_time_some_exists keys_def mem_Collect_eq to_trans_raw_sig_def zero_option_def)\n                qed\n                have \"a \\<le> t + dly\"\n                  using Some  by (meson \\<open>t' < t + dly\\<close> inf_time_some_exists le_trans less_imp_le_nat)\n                have ainset: \"a \\<in> fold (\\<union>)\n                        (map (keys \\<circ> (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> snd)\n                        (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                             (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))) {}\"\n                proof (rule ccontr)\n                  assume \"a \\<notin> fold (\\<union>)\n            (map (keys \\<circ> (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> snd)\n              (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])))\n            {}\"\n                  hence \"purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig = None\"\n                    using `t < a` `a \\<le> t + dly` unfolding purge_raw'_def combine_trans_bit_def Let_def by auto\n                  with Some show False\n                    by (metis (mono_tags, lifting) inf_time_some_exists keys_def mem_Collect_eq to_trans_raw_sig_def zero_option_def)\n                qed\n                have \" purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig = \n                        combine_trans_bit \\<tau>\n                          (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                               (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))\n                        sign sig t dly a sig\"\n                  unfolding purge_raw'_def by auto\n                also have \"... = Some\n                         (Lv sign\n                           (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig a))\n                             (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                                  (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))))\" (is \"_ = Some (Lv sign ?list)\")\n                  using ainset `t < a` `a \\<le> t + dly` unfolding combine_trans_bit_def by auto\n                finally have \"to_bit b (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t') = Bv (?list ! b)\"\n                  using \\<open>signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t' = the (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig)\\<close> by auto\n                also have \"... = Bv (bval_of (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) \n                                    (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig a))\"\n                  using `b < length bs`  by (simp add: val.case_eq_if)\n                finally have imp: \"bval_of (to_bit b (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t')) = \n                              bval_of (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) \n                                      (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig a)\"\n                  by auto\n                have \"a \\<in> keys (to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig) \\<or>\n                      a \\<notin> keys (to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig)\"\n                  by auto\n                moreover\n                { assume ainkeys2: \"a \\<in> keys (to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig)\"\n                  hence cond0: \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig t \\<noteq> Bv (bs ! b)\"\n                    using \\<open>t < a\\<close> \\<open>a \\<le> t + dly\\<close> unfolding purge_raw_def to_trans_raw_sig_def keys_def Let_def override_on_def \n                    using zero_option_def by auto\n                  moreover have cond1: \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (t + dly) = Bv (bs ! b)\"\n                    using ainkeys2 \\<open>t < a\\<close> \\<open>a \\<le> t + dly\\<close> unfolding purge_raw_def to_trans_raw_sig_def keys_def Let_def override_on_def \n                    using zero_option_def fun_upd_eqD by fastforce\n                  ultimately have somea: \"Some a = inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)\"\n                    using ainkeys2 unfolding purge_raw_def\n                    by (metis Some \\<open>a \\<le> t + dly\\<close> \\<open>t < a\\<close> \\<open>t' < t + dly\\<close> ainkeys2 domIff dom_def inf_time_some_exists keys_def le_antisym not_le purge_raw_neq_0_imp to_trans_raw_sig_def zero_option_def)\n                  hence \"inf_time (to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)))) sig a = Some a\"\n                    apply (intro inf_time_someI)\n                    by(metis ainkeys2 dom_def keys_def zero_option_def)auto\n                  hence \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) \n                                      (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig a = \n                         the (to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig a)\"\n                    unfolding to_signal_def comp_def by auto\n                  also have \"... = the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig a sig)\"\n                    using cond0 cond1 somea unfolding to_trans_raw_sig_def purge_raw_def Let_def override_on_def \n                    by (smt UnE \\<open>inf_time (to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b\n                    sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs !\n                    b)))) sig a = Some a\\<close> greaterThanAtMost_iff greaterThanLessThan_iff\n                    inf_time_at_most leD option.sel)\n                  also have \"... = Bv (bs ! b)\"\n                    using cond1 somea unfolding to_signal_def comp_def  by (metis option.simps(5) to_trans_raw_sig_def)\n                  finally have \" bs ! b = bval_of (to_bit b (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'))\"\n                    using imp by auto }\n                moreover\n                { assume anotinkeys2: \"a \\<notin> keys (to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig)\"\n                  have \"inf_time (to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)))) sig a = Some ?time'\"\n                  proof (rule inf_time_someI)\n                    have \"\\<exists>y. to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (the (inf_time (\\<lambda>siga n. to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig n siga) sig (t + dly))) sig = Some y\"\n                      using \\<open>?time' \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\\<close> unfolding keys_def to_trans_raw_sig_def \n                      by (simp add: zero_option_def)\n                    thus \"?time' \\<in> dom (to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig)\"\n                      using h0 h1\n                      unfolding to_trans_raw_sig_def dom_def purge_raw_def Let_def by auto\n                  next\n                    show \"?time' \\<le> a\" using \\<open>?time' \\<le> a\\<close> by auto\n                  next\n                    show \"\\<forall>ta\\<in>dom (to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig).\n         ta \\<le> a \\<longrightarrow> ta \\<le> the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly))\"\n                      using h0 h1 \\<open>?time' \\<le> a\\<close>\n                      unfolding purge_raw_def Let_def to_trans_raw_sig_def dom_def  using \\<open>a \\<le> t + dly\\<close> leI by fastforce\n                  qed\n                  hence \"(signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) \n                                 (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig a) = \n                         the (to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig ?time')\"\n                    using \\<open>the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig) = Bv (bs ! b)\\<close> unfolding to_signal_def comp_def by auto\n                  also have \"... =  the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (?time') sig)\"\n                    using h0 h1 unfolding to_trans_raw_sig_def purge_raw_def Let_def by auto\n                  also have \"... = (Bv (bs ! b))\"\n                    using \\<open>the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig) = Bv (bs ! b)\\<close> by auto\n                  finally have \"bval_of (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) \n                                      (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig a) = bs ! b\"\n                    by auto\n                  hence \" bs ! b = bval_of (to_bit b (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'))\"\n                    using imp by auto }\n                ultimately show ?thesis \n                  by auto\n              qed\n              finally have \"bval_of (snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig t') = \n                            bval_of (to_bit b (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'))\"\n                by auto }\n            moreover\n            { assume \"t' < ?time\"\n              hence \"bval_of (snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig t') = bval_of ( ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig t)\"\n                unfolding * using \\<open>((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig :=\n                to_bit b \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! b)\\<close> by auto\n              also have \"... = bval_of (to_bit b (snd \\<omega> sig t))\"\n                unfolding fun_upd_def by auto\n              also have \"... = bval_of (to_bit b (signal_of (\\<sigma> sig) \\<tau> sig t))\"\n                unfolding assms(1) worldline_raw_def by auto\n              also have \"... = bval_of (to_bit b (\\<sigma> sig))\"\n                by (metis (full_types, hide_lams) assms(2) context_invariant_def signal_of_def zero_fun_def)\n              finally have \"bval_of (snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig t') = \n                            bval_of (to_bit b (\\<sigma> sig))\"\n                by auto\n              also have \"... = bval_of (to_bit b (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'))\"\n              proof (cases \"inf_time (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs))) sig t'\")\n                case None\n                then show ?thesis \n                  unfolding to_signal_def comp_def by auto\n              next\n                case (Some a)\n                hence \"signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t' = the (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig)\"\n                  by (simp add: to_signal_def to_trans_raw_sig_def)\n                have \"\\<forall>t\\<in>dom (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig). t \\<le> t' \\<longrightarrow> t \\<le> a\"\n                  using inf_time_someE[OF Some] by auto\n                have \"to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time - 1)) \\<noteq> Bv (bs ! b)\"\n                  using `((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time - 1) \\<noteq> Bv (bs ! b)` `?time \\<le> t + dly` `t < ?time`\n                  unfolding assms(1) comp_def fun_upd_def worldline_raw_def snd_conv \n                  by presburger\n                moreover have \"to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time)) = Bv (bs ! b)\"\n                  using `((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig ?time = Bv (bs ! b)` `?time \\<le> t + dly` `t < ?time`\n                  unfolding assms(1) comp_def fun_upd_def worldline_raw_def snd_conv \n                  by presburger\n                ultimately have \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) ?time sig \\<noteq> None\"\n                  by (metis (no_types, lifting) signal_of_less_sig to_bit_signal_of' zero_option_def)\n                have h0: \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig t \\<noteq> Bv (bs ! b)\"\n                  using 1 unfolding to_bit_signal_of'_eq assms(1) comp_def fun_upd_def worldline_raw_def snd_conv \n                  using to_bit_signal_of'_eq by fastforce\n                have h1: \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (t + dly) = Bv (bs ! b)\"\n                  using 1 unfolding to_bit_signal_of'_eq assms(1) comp_def fun_upd_def worldline_raw_def snd_conv \n                  using to_bit_signal_of'_eq by fastforce\n                let ?time' = \"the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly))\"\n                obtain val where \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time sig = Some val\" \n                    using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time sig \\<noteq> None\\<close> by auto\n                have \"\\<exists>k\\<in>keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig). k \\<le> t + dly\"\n                 by (metis (mono_tags, lifting) \\<open>?time \\<le> t + dly\\<close> \\<open>\\<And>thesis. (\\<And>val.\n                    to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time sig = Some val \\<Longrightarrow> thesis) \\<Longrightarrow> thesis\\<close> keys_def\n                    mem_Collect_eq option.simps(3) to_trans_raw_sig_def zero_option_def)\n                hence time'_eq: \"?time' = (GREATEST k. k \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig) \\<and> k \\<le> t + dly)\"\n                  unfolding inf_time_def by auto\n                hence \"?time' \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\" and \"?time' \\<le> t + dly\"\n                  using GreatestI_ex_nat \n                  by (metis (mono_tags, lifting) \\<open>\\<exists>k\\<in>keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig). k \\<le> t + dly\\<close> inf_time_def inf_time_ex1 inf_time_some_exists)+\n                have \"the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig) = Bv (bs ! b)\"\n                proof -\n                  have \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly) = Some ?time'\"\n                    by (simp add: \\<open>\\<exists>k\\<in>keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig). k \\<le> t + dly\\<close> inf_time_def)\n                  thus \"the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig) = Bv (bs ! b)\"\n                    using h1 unfolding to_signal_def comp_def \n                    by (metis option.simps(5) to_trans_raw_sig_def)\n                qed\n                have \"the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time sig) = Bv (bs ! b)\"\n                proof - \n                  have \" signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig ?time = Bv (bs ! b)\"\n                    using \\<open>to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time)) = Bv (bs ! b)\\<close> unfolding to_bit_signal_of'_eq[THEN sym] by auto\n                  moreover have \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig ?time = Some ?time\"\n                  proof (intro inf_time_someI)\n                    show \"?time \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n                    proof -\n                    have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) sig \\<noteq> None\"\n                      by (metis (full_types) \\<open>\\<And>thesis. (\\<And>val. to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) sig = Some val \\<Longrightarrow> thesis) \\<Longrightarrow> thesis\\<close> option.simps(3))\n                    then show ?thesis\n                        by (simp add: domIff to_trans_raw_sig_def)\n                    qed\n                  qed (auto)\n                  ultimately show ?thesis\n                    unfolding to_signal_def comp_def  by (simp add: to_trans_raw_sig_def)\n                qed\n                have \"?time = ?time'\"\n                proof (rule Greatest_equality)\n                  have \"t \\<le> ?time' - 1\" \n                  proof (rule ccontr)\n                    assume \"\\<not> t \\<le> ?time' - 1\" hence \"?time' - 1 < t\"\n                      by auto\n                    hence \"?time' \\<le> t\" by auto\n                    hence \"\\<tau> ?time' sig = None\"\n                      using assms(2) unfolding context_invariant_def by (auto simp add: zero_fun_def zero_option_def)\n                    have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig \\<noteq> None\"\n                      using \\<open>?time' \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\\<close> \n                      by (metis domIff dom_is_keys to_trans_raw_sig_def)\n                    thus \"False\"\n                      using \\<open>\\<tau> ?time' sig = None\\<close> unfolding to_trans_raw_bit_def by auto\n                  qed\n                  moreover have \"to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time' - 1)) \\<noteq> Bv (bs ! b)\"\n                    unfolding to_bit_signal_of'_eq[THEN sym]\n                  proof (cases \"\\<exists>n. t < n \\<and> n < ?time' \\<and> (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) n sig \\<noteq> None\")\n                    case False\n                    hence none: \"\\<And>n. t < n \\<Longrightarrow> n \\<le> ?time' - 1 \\<Longrightarrow> (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) n sig = 0\"\n                      by (auto simp add: zero_option_def)\n                    have \" signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (?time' - 1) = \n                            signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig t\"\n                      using signal_of_less_ind'[of \"t\" \"?time' - 1\" \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig\" \"sig\", OF none] `t \\<le> ?time' - 1`\n                      by auto                    \n                    also have \"... \\<noteq> (Bv (bs ! b))\"\n                      using h0 to_bit_signal_of'_eq by force\n                    finally show \" signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (?time' - 1) \\<noteq> (Bv (bs ! b))\"\n                      by auto\n                  next\n                    case True\n                    let ?key1 = \"(GREATEST n. t < n \\<and> n < ?time' \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig n sig \\<noteq> None)\"\n                    from True have \"t < ?key1\" and \"?key1 < ?time'\" and \" to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig \\<noteq> None\"\n                      using GreatestI_ex_nat[OF True]  using less_imp_le_nat by blast+\n                    have *: \"\\<And>n. n > ?key1 \\<Longrightarrow> n < ?time' \\<Longrightarrow> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig n sig = None\"\n                      using Greatest_le_nat[where P=\"\\<lambda>x. t < x \\<and> x < ?time' \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig x sig \\<noteq> None\" and b=\"?time'\"]\n                      by (smt \\<open>t < (GREATEST n. t < n \\<and> n < the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig n sig \\<noteq> None)\\<close> leD less_imp_le_nat less_trans)\n                    have inf_some: \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (?time' - 1) = Some ?key1\"\n                    proof (rule inf_time_someI)\n                      show \"?key1 \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n                        using `to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig \\<noteq> None`  by (simp add: domIff to_trans_raw_sig_def)\n                    next\n                      show \"?key1 \\<le> ?time' - 1\"\n                        using `?key1 < ?time'`  by linarith\n                    next\n                      { fix ta\n                        assume \"ta \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n                        assume \"ta \\<le> ?time' - 1\"\n                        assume \"?key1 < ta\"\n                        hence \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ta sig = None\"\n                          using *[OF `?key1 < ta`] `ta \\<le> ?time' - 1` by simp\n                        hence \"ta \\<notin> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n                          by (simp add: domIff to_trans_raw_sig_def)\n                        with `ta \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)` have False by auto }\n                      thus \"\\<forall>ta \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig). ta \\<le> ?time' - 1 \\<longrightarrow> ta \\<le> ?key1\"\n                        using not_le_imp_less by blast\n                    qed\n                    have non_stut: \" non_stuttering (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) (to_bit b o \\<sigma>) sig\"\n                      using assms(5) non_stuttering_to_trans_raw_bit by force\n                    hence \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig  ?key1 sig) \\<noteq> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig\"\n                    proof -\n                      have \"?key1 \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n                        using `to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig \\<noteq> None`  by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n                      moreover have \"?time' \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n                        using \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\\<close> by blast\n                      moreover have \"\\<forall>k. ?key1 < k \\<and> k < ?time' \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\"\n                        using *  by (metis (mono_tags, lifting) domIff keys_def mem_Collect_eq to_trans_raw_sig_def\n                        zero_option_def)\n                      ultimately show ?thesis    \n                        using `?key1 < ?time'` non_stut unfolding non_stuttering_def\n                        by (simp add: to_trans_raw_sig_def)\n                    qed\n                    moreover have \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig) = Some (Bv (bs ! b))\"\n                      by (metis \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\\<close> \\<open>the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly))) sig) = Bv (bs ! b)\\<close> domIff dom_def keys_def option.exhaust_sel to_trans_raw_sig_def zero_option_def)\n                    ultimately have neq: \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig) \\<noteq> Some (Bv (bs ! b))\"\n                      by auto\n                    then obtain valu where \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig) = Some valu\" and \"valu \\<noteq> Bv (bs ! b)\"\n                      using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig \\<noteq> None\\<close> by blast\n                    have \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (?time' - 1) = \n                          the (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig ?key1)\"\n                      using inf_some unfolding to_signal_def comp_def\n                      by auto\n                    also have \"... \\<noteq> Bv (bs ! b)\"\n                      using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?key1 sig \\<noteq> None\\<close> neq \n                      by (metis \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (GREATEST n. t < n \\<and> n < the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig n sig \\<noteq> None) sig = Some valu\\<close> option.sel to_trans_raw_sig_def)\n                    finally show \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (?time' - 1) \\<noteq> (Bv (bs ! b))\"\n                      by blast\n                  qed\n                  ultimately have \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time' - 1) = to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time' - 1))\"\n                    unfolding assms(1) worldline_raw_def snd_conv fun_upd_def comp_def by auto\n                  hence *: \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time' - 1) \\<noteq> Bv (bs ! b)\"\n                    using \\<open>to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (?time' - 1)) \\<noteq> Bv (bs ! b)\\<close> by auto\n                  have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig = Some (Bv (bs ! b))\"\n                    by (metis \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\\<close> \\<open>the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly))) sig) = Bv (bs ! b)\\<close> domIff dom_def keys_def option.exhaust_sel to_trans_raw_sig_def zero_option_def)\n                  have \"to_bit b (signal_of (\\<sigma> sig) \\<tau> sig ?time') = (Bv (bs ! b))\"\n                    using trans_some_signal_of'[of \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig\", OF `to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig = Some (Bv (bs ! b))`]\n                    using to_bit_signal_of'_eq by fastforce\n                  hence \" ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly))) = Bv (bs ! b)\"\n                    unfolding assms(1) worldline_raw_def snd_conv fun_upd_def comp_def \n                    using \\<open>t \\<le> the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) - 1\\<close> by auto\n                  thus \"?time' \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time' - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig ?time' = Bv (bs ! b)\"    \n                    using * `?time' \\<le> t + dly` by auto  \n                next\n                  have \"t \\<le> ?time' - 1\" \n                  proof (rule ccontr)\n                    assume \"\\<not> t \\<le> ?time' - 1\" hence \"?time' - 1 < t\"\n                      by auto\n                    hence \"?time' \\<le> t\" by auto\n                    hence \"\\<tau> ?time' sig = None\"\n                      using assms(2) unfolding context_invariant_def by (auto simp add: zero_fun_def zero_option_def)\n                    have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig \\<noteq> None\"\n                      using \\<open>?time' \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\\<close> \n                      by (metis domIff dom_is_keys to_trans_raw_sig_def)\n                    thus \"False\"\n                      using \\<open>\\<tau> ?time' sig = None\\<close> unfolding to_trans_raw_bit_def by auto\n                  qed\n                  fix y\n                  assume \"y \\<le> t + dly \\<and>  ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (y - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig y = Bv (bs ! b)\"\n                  hence \"y \\<le> t + dly\" and \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (y - 1) \\<noteq> Bv (bs ! b)\" and \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (y) = Bv (bs ! b)\"\n                    by auto\n                  have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig ?time' sig = Some (Bv (bs ! b))\"\n                    by (metis \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig)\\<close> \\<open>the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly))) sig) = Bv (bs ! b)\\<close> domIff dom_def keys_def option.exhaust_sel to_trans_raw_sig_def zero_option_def)\n                  hence \"t < ?time'\"\n                    by (smt \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> \\<open>the (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) sig) = Bv (bs ! b)\\<close> \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) sig = Some val\\<close> \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) sig \\<noteq> None\\<close> leI option.sel option.simps(4) to_trans_raw_bit_def zero_fun_def zero_option_def)\n                  have \"y \\<le> t \\<or> t < y\"\n                    by auto\n                  moreover\n                  { assume \"y \\<le> t\"\n                    hence \"y < ?time'\" using `t < ?time'` by linarith }\n                  moreover\n                  { assume \"t < y\"\n                    hence \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (y - 1) =  to_bit b (signal_of (\\<sigma> sig) \\<tau> sig (y - 1))\"\n                      unfolding assms(1) worldline_raw_def snd_conv fun_upd_def comp_def  by auto\n                    hence 0: \"... \\<noteq> (Bv (bs ! b))\"\n                      using \\<open>((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (y - 1) \\<noteq> Bv (bs ! b)\\<close> by auto\n                    have \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig y =  to_bit b (signal_of (\\<sigma> sig) \\<tau> sig y)\"\n                      using `t < y`  unfolding assms(1) worldline_raw_def snd_conv fun_upd_def comp_def  by auto\n                    hence 1: \"... = Bv (bs ! b)\"\n                      using \\<open>((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig y = Bv (bs ! b)\\<close> by auto\n                    have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = Some (Bv (bs ! b))\"\n                    proof (rule ccontr)\n                      assume \"\\<not> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = Some (Bv (bs ! b))\"\n                      then obtain x' where \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = None \\<or> to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = Some x' \\<and> x' \\<noteq> (Bv (bs ! b))\"\n                        using domIff by fastforce\n                      moreover\n                      { assume \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = None\"\n                        hence \"signal_of (\\<sigma> sig) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig y = \n                               signal_of (\\<sigma> sig) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (y - 1)\"\n                          by (intro signal_of_less_sig)(simp add: zero_option_def)\n                        with 0 1 have False \n                          by (metis \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = None\\<close> signal_of_less_sig to_bit_signal_of' zero_option_def) }\n                      moreover\n                      { assume \"to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig y sig = Some x' \\<and> x' \\<noteq> (Bv (bs ! b))\"\n                        hence \"signal_of ((Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b))) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig y = x'\" and \"x' \\<noteq> (Bv (bs ! b))\"\n                          using trans_some_signal_of' by fastforce+\n                        with 1 have False \n                          unfolding to_bit_signal_of'_eq by auto }\n                      ultimately show False\n                        by auto\n                    qed\n                    with `y \\<le> t + dly` have \"y \\<le> ?time'\"\n                      unfolding time'_eq \n                      apply (intro Greatest_le_nat)\n                      unfolding keys_def to_trans_raw_sig_def zero_option_def by auto }\n                  ultimately show \"y \\<le> ?time'\"\n                    by auto\n                qed\n                have \"a < ?time'\"\n                  using Some \\<open>(GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n\n                  - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) =\n                  the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly))\\<close>\n                  \\<open>t' < (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1)\n                  \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b))\\<close>\n                  inf_time_some_exists by fastforce\n                have \"t < a\"\n                proof (rule ccontr)\n                  assume \"\\<not> t < a\" hence \"a \\<le> t\" by auto\n                  hence \"purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig = None\"\n                    unfolding purge_raw'_def combine_trans_bit_def Let_def \n                    using assms(2) unfolding context_invariant_def by (auto simp add: zero_fun_def zero_option_def)\n                  with Some show False\n                    by (metis (mono_tags, lifting) inf_time_some_exists keys_def mem_Collect_eq to_trans_raw_sig_def zero_option_def)\n                qed\n                have \"a \\<le> t + dly\"\n                  using Some  by (meson \\<open>t' < t + dly\\<close> inf_time_some_exists le_trans less_imp_le_nat)\n                have ainset: \"a \\<in> fold (\\<union>)\n                        (map (keys \\<circ> (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> snd)\n                        (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                             (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))) {}\"\n                proof (rule ccontr)\n                  assume \"a \\<notin> fold (\\<union>)\n            (map (keys \\<circ> (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> snd)\n              (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])))\n            {}\"\n                  hence \"purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig = None\"\n                    using `t < a` `a \\<le> t + dly` unfolding purge_raw'_def combine_trans_bit_def Let_def by auto\n                  with Some show False\n                    by (metis (mono_tags, lifting) inf_time_some_exists keys_def mem_Collect_eq to_trans_raw_sig_def zero_option_def)\n                qed\n                have \" purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig = \n                        combine_trans_bit \\<tau>\n                          (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                               (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))\n                        sign sig t dly a sig\"\n                  unfolding purge_raw'_def by auto\n                also have \"... = Some\n                         (Lv sign\n                           (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig a))\n                             (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                                  (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))))\" (is \"_ = Some (Lv sign ?list)\")\n                  using ainset `t < a` `a \\<le> t + dly` unfolding combine_trans_bit_def by auto\n                finally have \"to_bit b (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t') = Bv (?list ! b)\"\n                  using \\<open>signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t' = the (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig)\\<close> by auto\n                also have \"... = Bv (bval_of (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) \n                                    (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig a))\"\n                  using `b < length bs`  by (simp add: val.case_eq_if)\n                finally have imp: \"bval_of (to_bit b (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t')) = \n                              bval_of (signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) \n                                      (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig a)\"\n                  by auto\n                have \"inf_time (to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b)))) sig a = None\"\n                proof (unfold inf_time_none_iff[THEN sym], rule)\n                  fix x\n                  assume \"x \\<in> dom (to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig)\"\n                  thus \"a < x\"\n                    using h0 h1 `a < ?time'` assms(2) \n                    unfolding context_invariant_def dom_def to_trans_raw_sig_def purge_raw_def Let_def \n                    by (smt Un_iff fun_upd_eqD fun_upd_triv greaterThanLessThan_iff leI le_less_trans mem_Collect_eq option.case_eq_if override_on_apply_in override_on_apply_notin to_trans_raw_bit_def zero_fun_def zero_option_def)\n                qed\n                hence \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) sig a = \n                      (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b))\" \n                  unfolding to_signal_def comp_def by auto\n                moreover have \"to_bit b (\\<sigma> sig) = (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! b))\"\n                  by (auto split: val.splits)\n                ultimately show ?thesis\n                  unfolding imp by auto \n              qed\n              finally have \"bval_of (snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig t') = \n                            bval_of (to_bit b (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'))\"\n                by auto }\n            ultimately have \"bval_of (snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig t') = \n                            bval_of (to_bit b (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'))\"\n              by auto }\n          ultimately show \"bval_of (snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig t') = \n                            bval_of (to_bit b (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'))\"\n            by auto \n        qed\n        have \"?zeit \\<le> t' \\<or> t' < ?zeit\"\n          by auto\n        moreover\n        { assume \"?zeit \\<le> t'\"\n          have \"snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t' = \n                Lv sign (map (\\<lambda>b. bval_of (snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig t')) [0..<length bs])\"\n            unfolding worldline_inert_upd2.simps snd_conv `s' = sig` fun_upd_def using \\<open>t \\<le> t'\\<close> \\<open>?zeit \\<le> t'\\<close> thereis by auto\n          hence midway: \"\\<And>b. b < length bs \\<Longrightarrow> lval_of (snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t') ! b = \n                                       bval_of (snd (to_worldline_init_bit \\<omega> sig b)[sig, t, dly := Bv (bs ! b)] sig t')\"\n            by auto\n          hence midway2: \"\\<And>b. b < length bs \\<Longrightarrow> lval_of (snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t') ! b = \n                          bval_of (to_bit b (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'))\"\n             using \\<open>\\<And>ba. ba < length bs \\<Longrightarrow> bval_of (snd to_worldline_init_bit \\<omega> sig ba[sig, t, dly :=\n             Bv (bs ! ba)] sig t') = bval_of (to_bit ba (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig\n             (\\<sigma> sig) (Lv sign bs)) sig t'))\\<close> by blast\n          have \"inf_time (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs))) sig t' \\<noteq> None\"\n            unfolding inf_time_none_iff[THEN sym]\n          proof (rule)\n            assume \"Ball (dom (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig)) ((<) t')\"\n            hence \"\\<forall>x\\<in>dom (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig). t' < x\"\n              by auto\n            have helper: \"length (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n))\n                         (Bv (bs ! n)))\n                [0..<length bs]) \\<le> length bs - 0\"\n              by auto\n            have \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) \\<noteq> Bv (bs ! index) \\<or> \n                  ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index)\"\n              by auto\n            moreover\n            { assume \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) \\<noteq> Bv (bs ! index)\"\n              hence \"zeit = t + dly\"\n                using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) \\<noteq> Bv (bs ! index) \\<Longrightarrow> zeit = t + dly\\<close> by blast\n              hence \"?zeit = t + dly\"\n                unfolding zeit_def by auto\n              with \\<open>t' < t + dly\\<close> \\<open>?zeit \\<le> t'\\<close> have \"False\"\n                by linarith }\n            moreover\n            { assume \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index)\"\n              hence zeit_def': \"zeit = (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\"\n                using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index) \\<Longrightarrow> zeit = (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\\<close> by blast\n              have \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig t \\<noteq> Bv (bs ! index)\"\n                using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t) \\<noteq> Bv (bs ! index)\\<close>\n                unfolding assms(1) worldline_raw_def snd_conv fun_upd_def to_bit_signal_of'_eq by auto\n              moreover have \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig (t + dly) = Bv (bs ! index)\"\n                using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index)\\<close>\n                unfolding assms(1) worldline_raw_def snd_conv fun_upd_def to_bit_signal_of'_eq by auto\n              let ?time' = \" the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly))\"\n              let ?time = \"(GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\"\n              have \"?time \\<le> t + dly\"\n                using \\<open>(LEAST n. t < n \\<and> n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length bs]. snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig (n - 1) \\<noteq> snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig n)) \\<le> t'\\<close> \\<open>t' < t + dly\\<close> \\<open>zeit = (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\\<close> zeit_def by linarith\n              have \"t < ?time\"\n                using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index) \\<Longrightarrow> zeit = (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\\<close> \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index)\\<close> \\<open>t < (LEAST n. t < n \\<and> n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length bs]. snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig (n - 1) \\<noteq> snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig n))\\<close> zeit_def by linarith\n              have \"to_bit index (signal_of (\\<sigma> sig) \\<tau> sig (?time - 1)) \\<noteq> Bv (bs ! index)\"\n                using `?w' index sig (zeit - 1) \\<noteq> Bv (bs ! index)`  unfolding \\<open>?w' index sig (zeit - 1) = ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig t\\<close>\n                using `?time \\<le> t + dly` `t < ?time` zeit_def zeit_def' unfolding assms(1) comp_def fun_upd_def worldline_raw_def snd_conv \n                by (smt \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (zeit - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig zeit = Bv (bs ! index)\\<close> \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) \\<noteq> Bv (bs ! index) \\<Longrightarrow> False\\<close> \\<open>\\<not> zeit - 1 < t\\<close> assms(1) fun_upd_same o_apply prod.sel(2) worldline_raw_def) \n              moreover have \"to_bit index (signal_of (\\<sigma> sig) \\<tau> sig (?time)) = Bv (bs ! index)\"\n                using  `?time \\<le> t + dly` `t < ?time`\n                assms(1) comp_def fun_upd_def worldline_raw_def snd_conv \n                by (smt \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (zeit - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig zeit = Bv (bs ! index)\\<close> \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index) \\<Longrightarrow> zeit = (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\\<close> \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index)\\<close> leD less_or_eq_imp_le)\n              ultimately have \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) ?time sig \\<noteq> None\"\n                by (metis (no_types, lifting) signal_of_less_sig to_bit_signal_of' zero_option_def)\n              obtain val where \"to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?time sig = Some val\" \n                  using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?time sig \\<noteq> None\\<close> by auto\n              have \"\\<exists>k\\<in>keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig). k \\<le> t + dly\"\n              proof -\n                have \"to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) = Some val\"\n                  by (metis \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) sig = Some val\\<close> to_trans_raw_sig_def)\n                then have \"\\<exists>n. to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig n \\<noteq> None \\<and> n \\<le> t + dly\"\n                  using \\<open>(GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) \\<le> t + dly\\<close> by blast\n                then show ?thesis\n                  by (simp add: keys_def zero_option_def)\n              qed\n              hence time'_eq: \"?time' = (GREATEST k. k \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig) \\<and> k \\<le> t + dly)\"\n                unfolding inf_time_def by auto\n              hence \"?time' \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig)\" and \"?time' \\<le> t + dly\"\n                using GreatestI_ex_nat \n                by (metis (mono_tags, lifting) \\<open>\\<exists>k\\<in>keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig). k \\<le> t + dly\\<close> inf_time_def inf_time_ex1 inf_time_some_exists)+\n              have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?time' sig = to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?time sig\"\n              proof (rule ccontr)\n                assume \"\\<not> to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig ?time' sig = to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig ?time sig\"\n                hence \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig) sig ?time =  val\"\n                  using trans_some_signal_of'[of \"to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig\" \"?time\" \"sig\" \"(\\<lambda>x. _)(sig := val)\"]\n                  using \\<open>to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig :=\n                  to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ>\n                  snd \\<omega> sig)) sig n = Bv (bs ! index)) sig = Some val\\<close> by auto\n                then obtain val' where \"to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig ?time' sig = Some val'\"\n                proof -\n                  assume \"\\<And>val'. to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig)) sig (t + dly))) sig = Some val' \\<Longrightarrow> thesis\"\n                  then show ?thesis\n                    by (metis \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig)) sig (t + dly)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig) sig)\\<close> domIff dom_def keys_def not_None_eq to_trans_raw_sig_def zero_option_def)\n                qed\n                hence \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig) sig ?time' =  val'\"\n                  using trans_some_signal_of'[of \"to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig\" \"?time\" \"sig\" \"(\\<lambda>x. _)(sig := val')\"] time'_eq\n                  by (meson trans_some_signal_of')\n                also have \"... \\<noteq> val\"\n                  using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig (GREATEST n. n \\<le> t + dly \\<and> ((snd\n                  \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig\n                  := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) sig = Some val\\<close>\n                  \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig (the (inf_time (to_trans_raw_sig\n                  (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly))) sig = Some val'\\<close>\n                  using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly))) sig \\<noteq> to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) sig\\<close> by auto\n                finally have \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig) sig ?time' \\<noteq> \n                              signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig) sig ?time \"\n                  using \\<open>signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! index))\n                  (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig\n                  := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig :=\n                  to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) = val\\<close> by blast\n                have \"t < ?time'\"\n                  by (smt \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly))) sig = Some val'\\<close> leI option.simps(3) option.simps(4) to_trans_raw_bit_def zero_fun_def zero_option_def)\n                have \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (?time') = signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig) sig ?time'\"\n                  using `t < ?time'` to_bit_signal_of'_eq unfolding assms(1) time'_eq worldline_raw_def snd_conv fun_upd_def  by fastforce\n                moreover have \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (?time) = signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig) sig ?time\"\n                  using `t < ?time` to_bit_signal_of'_eq unfolding assms(1) time'_eq worldline_raw_def snd_conv fun_upd_def  by fastforce\n                ultimately have \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (?time') \\<noteq> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (?time)\"\n                  using \\<open>signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly))) \\<noteq> signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\\<close> by auto                  \n                have \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig) sig ?time' = val'\"\n                  using trans_some_signal_of'[of \"to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig\" \"?time'\" \"sig\" \"(\\<lambda>x. _)(sig := val')\"] \\<open>to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig ?time' sig = Some val'\\<close>\n                  by auto\n                have \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig)) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig)) sig (t + dly))) = \n                      inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig)) sig (t + dly)\"\n                  using time'_eq \n                proof -\n                  obtain nn :: nat where\n                    f1: \"nn \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig) sig) \\<and> nn \\<le> t + dly\"\n                      using \\<open>\\<exists>k\\<in>keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig) sig). k \\<le> t + dly\\<close> by blast\n                  have f2: \"to_signal (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv s bs \\<Rightarrow> bs ! index)) (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig)) sig (t + dly) = Bv (bs ! index)\"\n                    using \\<open>signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig (t + dly) = Bv (bs ! index)\\<close> by auto\n                  have f3: \"\\<forall>v n a f. to_signal v f (a::'a) n = the (f a (the (inf_time f a n))) \\<or> inf_time f a n = None\"\n                    by (simp add: option.case_eq_if to_signal_def)\n                  have f4: \"\\<forall>f. f (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig)) sig (t + dly)))) = f (Some val')\"\n                    by (metis \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly))) sig = Some val'\\<close> to_trans_raw_sig_def)\n                  have \"Bv (bs ! index) \\<noteq> val'\"\n                    using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) = signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\\<close> \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (zeit - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig zeit = Bv (bs ! index)\\<close> \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index) \\<Longrightarrow> zeit = (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\\<close> \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index)\\<close> \\<open>signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) = val\\<close> \\<open>val' \\<noteq> val\\<close> by auto\n                  then have f5: \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig)) sig (t + dly) = None\"\n                    using f4 f3 f2 option.sel \n                    by (metis \\<open>to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig)) sig (t + dly))) sig = Some val'\\<close> to_trans_raw_sig_def)\n                  have \"\\<forall>n. Some (GREATEST na. na \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig) sig) \\<and> na \\<le> n) = inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig)) sig n \\<or> \\<not> nn \\<le> n\"\n                  using f1 by (simp add: inf_time_def)\n                    then show ?thesis\n                  using f5 f1 by force\n                qed\n                hence \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig) sig (t + dly) = \n                      signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig) sig ?time'\"\n                  unfolding to_signal_def comp_def by auto\n                hence \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> index sig) sig ?time' = Bv (bs ! index)\"\n                  using \\<open>signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig (t + dly) = Bv (bs ! index)\\<close> by auto\n                have \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (?time) = Bv (bs ! index)\"\n                  using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (zeit - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig zeit = Bv (bs ! index)\\<close> \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index) \\<Longrightarrow> zeit = (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\\<close> \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index)\\<close> by blast\n                have \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (?time') = Bv (bs ! index)\"\n                  using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly))) = signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly)))\\<close> \\<open>signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly))) = Bv (bs ! index)\\<close> by auto\n                show False\n                  using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) = Bv (bs ! index)\\<close> \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly))) = Bv (bs ! index)\\<close> \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly))) \\<noteq> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\\<close> by auto\n              qed\n              have h1: \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig (t + dly) = Bv (bs ! index)\"\n                using \\<open>signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig (t + dly) = Bv (bs ! index)\\<close> by blast\n              have \"the (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?time' sig) = Bv (bs ! index)\"\n              proof -\n                have \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly) = Some ?time'\"\n                  by (simp add: \\<open>\\<exists>k\\<in>keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig). k \\<le> t + dly\\<close> inf_time_def)\n                thus \"the (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?time' sig) = Bv (bs ! index)\"\n                  using h1 unfolding to_signal_def comp_def  by (metis option.simps(5) to_trans_raw_sig_def)\n              qed\n              have \"the (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?time sig) = Bv (bs ! index)\"\n              proof- \n                have \" signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig ?time = Bv (bs ! index)\"\n                  using \\<open>to_bit index (signal_of (\\<sigma> sig) \\<tau> sig (?time)) = Bv (bs ! index)\\<close>\n                  unfolding to_bit_signal_of'_eq[THEN sym] by auto\n                moreover have \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig ?time = Some ?time\"\n                proof (intro inf_time_someI)\n                  show \"?time \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig)\"\n                  proof -\n                    have \"\\<exists>v. to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) sig = Some v\"\n                      by (metis \\<open>\\<And>thesis. (\\<And>val. to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) sig = Some val \\<Longrightarrow> thesis) \\<Longrightarrow> thesis\\<close>)\n                    then show ?thesis\n                      by (simp add: domIff to_trans_raw_sig_def)\n                  qed\n                qed (auto)\n                ultimately show ?thesis\n                  unfolding to_signal_def comp_def \n                  by (simp add: to_trans_raw_sig_def)\n              qed\n              have \"?time = ?time'\"\n              proof (rule Greatest_equality)\n                have \"t \\<le> ?time' - 1\" \n                proof (rule ccontr)\n                  assume \"\\<not> t \\<le> ?time' - 1\" hence \"?time' - 1 < t\"\n                    by auto\n                  hence \"?time' \\<le> t\" by auto\n                  hence \"\\<tau> ?time' sig = None\"\n                    using assms(2) unfolding context_invariant_def by (auto simp add: zero_fun_def zero_option_def)\n                  have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?time' sig \\<noteq> None\"\n                    using \\<open>?time' \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig)\\<close> \n                    by (metis domIff dom_is_keys to_trans_raw_sig_def)\n                  thus \"False\"\n                    using \\<open>\\<tau> ?time' sig = None\\<close> unfolding to_trans_raw_bit_def by auto\n                qed\n                moreover have \"to_bit index (signal_of (\\<sigma> sig) \\<tau> sig (?time' - 1)) \\<noteq> Bv (bs ! index)\"\n                  unfolding to_bit_signal_of'_eq[THEN sym]\n                proof (cases \"\\<exists>n. t < n \\<and> n < ?time' \\<and> (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) n sig \\<noteq> None\")\n                  case False\n                  hence none: \"\\<And>n. t < n \\<Longrightarrow> n \\<le> ?time' - 1 \\<Longrightarrow> (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) n sig = 0\"\n                    by (auto simp add: zero_option_def)\n                  have \" signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig (?time' - 1) = \n                          signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig t\"\n                    using signal_of_less_ind'[of \"t\" \"?time' - 1\" \"to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig\" \"sig\", OF none] `t \\<le> ?time' - 1`\n                    by auto                    \n                  also have \"... \\<noteq> (Bv (bs ! index))\"\n                    using to_bit_signal_of'_eq \n                    using \\<open>signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig t \\<noteq> Bv (bs ! index)\\<close> by blast\n                  finally show \" signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig (?time' - 1) \\<noteq> (Bv (bs ! index))\"\n                    by auto\n                next\n                  case True\n                  let ?key1 = \"(GREATEST n. t < n \\<and> n < ?time' \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig n sig \\<noteq> None)\"\n                  from True have \"t < ?key1\" and \"?key1 < ?time'\" and \" to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?key1 sig \\<noteq> None\"\n                    using GreatestI_ex_nat[OF True]  using less_imp_le_nat by blast+\n                  have *: \"\\<And>n. n > ?key1 \\<Longrightarrow> n < ?time' \\<Longrightarrow> to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig n sig = None\"\n                    using Greatest_le_nat[where P=\"\\<lambda>x. t < x \\<and> x < ?time' \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig x sig \\<noteq> None\" and b=\"?time'\"]\n                    by (smt \\<open>t < (GREATEST n. t < n \\<and> n < the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly)) \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig n sig \\<noteq> None)\\<close> leD less_imp_le_nat less_trans)\n                  have inf_some: \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (?time' - 1) = Some ?key1\"\n                  proof (rule inf_time_someI)\n                    show \"?key1 \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig)\"\n                      using `to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?key1 sig \\<noteq> None`  by (simp add: domIff to_trans_raw_sig_def)\n                  next\n                    show \"?key1 \\<le> ?time' - 1\"\n                      using `?key1 < ?time'`  by linarith\n                  next\n                    { fix ta\n                      assume \"ta \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig)\"\n                      assume \"ta \\<le> ?time' - 1\"\n                      assume \"?key1 < ta\"\n                      hence \"to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ta sig = None\"\n                        using *[OF `?key1 < ta`] `ta \\<le> ?time' - 1` by simp\n                      hence \"ta \\<notin> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig)\"\n                        by (simp add: domIff to_trans_raw_sig_def)\n                      with `ta \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig)` have False by auto }\n                    thus \"\\<forall>ta \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig). ta \\<le> ?time' - 1 \\<longrightarrow> ta \\<le> ?key1\"\n                      using not_le_imp_less by blast\n                  qed\n                  have non_stut: \" non_stuttering (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) (to_bit index o \\<sigma>) sig\"\n                    using assms(5) non_stuttering_to_trans_raw_bit by force\n                  hence \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig  ?key1 sig) \\<noteq> to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?time' sig\"\n                  proof -\n                    have \"?key1 \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig)\"\n                      using `to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?key1 sig \\<noteq> None`  by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n                    moreover have \"?time' \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig)\"\n                      using \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig)\\<close> by blast\n                    moreover have \"\\<forall>k. ?key1 < k \\<and> k < ?time' \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig)\"\n                      using *  by (metis (mono_tags, lifting) domIff keys_def mem_Collect_eq to_trans_raw_sig_def\n                      zero_option_def)\n                    ultimately show ?thesis    \n                      using `?key1 < ?time'` non_stut unfolding non_stuttering_def\n                      by (simp add: to_trans_raw_sig_def)\n                  qed\n                  moreover have \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?time' sig) = Some (Bv (bs ! index))\"\n                    by (metis \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index\n                    sig)) sig (t + dly)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau>\n                    index sig) sig)\\<close> \\<open>the (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig (the (inf_time (to_trans_raw_sig\n                    (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly))) sig) = Bv (bs ! index)\\<close>\n                    domIff dom_def keys_def option.exhaust_sel to_trans_raw_sig_def zero_option_def)\n                  ultimately have neq: \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?key1 sig) \\<noteq> Some (Bv (bs ! index))\"\n                    by auto\n                  then obtain valu where \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?key1 sig) = Some valu\" and \"valu \\<noteq> Bv (bs ! index)\"\n                    using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?key1 sig \\<noteq> None\\<close> by blast\n                  have \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig (?time' - 1) = \n                        the (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig ?key1)\"\n                    using inf_some unfolding to_signal_def comp_def\n                    by auto\n                  also have \"... \\<noteq> Bv (bs ! index)\"\n                    using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?key1 sig \\<noteq> None\\<close> neq \n                    by (metis \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig (GREATEST n. t < n \\<and> n < the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly)) \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig n sig \\<noteq> None) sig = Some valu\\<close> option.sel to_trans_raw_sig_def)\n                  finally show \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig (?time' - 1) \\<noteq> (Bv (bs ! index))\"\n                    by blast\n                qed\n                ultimately have \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (?time' - 1) = to_bit index (signal_of (\\<sigma> sig) \\<tau> sig (?time' - 1))\"\n                  unfolding assms(1) worldline_raw_def snd_conv fun_upd_def comp_def by auto\n                hence *: \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (?time' - 1) \\<noteq> Bv (bs ! index)\"\n                  using \\<open>to_bit index (signal_of (\\<sigma> sig) \\<tau> sig (?time' - 1)) \\<noteq> Bv (bs ! index)\\<close> by auto\n                have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?time' sig = Some (Bv (bs ! index))\"\n                  using \\<open>the (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig (the (inf_time (to_trans_raw_sig\n                  (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly))) sig) = Bv (bs ! index)\\<close>\n                  \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig :=\n                  to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit\n                  index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) sig \\<noteq> None\\<close> \\<open>to_trans_raw_bit (\\<sigma> sig)\n                  \\<tau> index sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index\n                  sig)) sig (t + dly))) sig = to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig (GREATEST n. n \\<le>\n                  t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index)\n                  \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) sig\\<close> by\n                  force\n                have \"to_bit index (signal_of (\\<sigma> sig) \\<tau> sig ?time') = (Bv (bs ! index))\"\n                  using trans_some_signal_of'[of \"to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig\", OF `to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?time' sig = Some (Bv (bs ! index))`]\n                  using to_bit_signal_of'_eq by fastforce\n                hence \" ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly))) = Bv (bs ! index)\"\n                  unfolding assms(1) worldline_raw_def snd_conv fun_upd_def comp_def \n                  using \\<open>t \\<le> the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly)) - 1\\<close> by auto\n                thus \"?time' \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (?time' - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig ?time' = Bv (bs ! index)\"    \n                  using * `?time' \\<le> t + dly` by auto  \n              next\n                have \"t \\<le> ?time' - 1\" \n                proof (rule ccontr)\n                  assume \"\\<not> t \\<le> ?time' - 1\" hence \"?time' - 1 < t\"\n                    by auto\n                  hence \"?time' \\<le> t\" by auto\n                  hence \"\\<tau> ?time' sig = None\"\n                    using assms(2) unfolding context_invariant_def by (auto simp add: zero_fun_def zero_option_def)\n                  have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?time' sig \\<noteq> None\"\n                    using \\<open>?time' \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig)\\<close> \n                    by (metis domIff dom_is_keys to_trans_raw_sig_def)\n                  thus \"False\"\n                    using \\<open>\\<tau> ?time' sig = None\\<close> unfolding to_trans_raw_bit_def by auto\n                qed\n                fix y\n                assume \"y \\<le> t + dly \\<and>  ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (y - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig y = Bv (bs ! index)\"\n                hence \"y \\<le> t + dly\" and \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (y - 1) \\<noteq> Bv (bs ! index)\" and \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (y) = Bv (bs ! index)\"\n                  by auto\n                have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?time' sig = Some (Bv (bs ! index))\"\n                  by (metis \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig)\\<close> \\<open>the (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly))) sig) = Bv (bs ! index)\\<close> domIff dom_def keys_def option.exhaust_sel to_trans_raw_sig_def zero_option_def)\n                hence \"t < ?time'\"\n                  by (smt \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) sig \\<noteq> None\\<close> \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly))) sig = to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) sig\\<close> leI option.simps(4) to_trans_raw_bit_def zero_fun_def zero_option_def)\n                have \"y \\<le> t \\<or> t < y\"\n                  by auto\n                moreover\n                { assume \"y \\<le> t\"\n                  hence \"y < ?time'\" using `t < ?time'` by linarith }\n                moreover\n                { assume \"t < y\"\n                  hence \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (y - 1) =  to_bit index (signal_of (\\<sigma> sig) \\<tau> sig (y - 1))\"\n                    unfolding assms(1) worldline_raw_def snd_conv fun_upd_def comp_def  by auto\n                  hence 0: \"... \\<noteq> (Bv (bs ! index))\"\n                    using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (y - 1) \\<noteq> Bv (bs ! index)\\<close> by auto\n                  have \"((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig y =  to_bit index (signal_of (\\<sigma> sig) \\<tau> sig y)\"\n                    using `t < y`  unfolding assms(1) worldline_raw_def snd_conv fun_upd_def comp_def  by auto\n                  hence 1: \"... = Bv (bs ! index)\"\n                    using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig y = Bv (bs ! index)\\<close> by auto\n                  have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig y sig = Some (Bv (bs ! index))\"\n                  proof (rule ccontr)\n                    assume \"\\<not> to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig y sig = Some (Bv (bs ! index))\"\n                    then obtain x' where \"to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig y sig = None \\<or> to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig y sig = Some x' \\<and> x' \\<noteq> (Bv (bs ! index))\"\n                      using domIff by fastforce\n                    moreover\n                    { assume \"to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig y sig = None\"\n                      hence \"signal_of (\\<sigma> sig) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig y = \n                             signal_of (\\<sigma> sig) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig (y - 1)\"\n                        by (intro signal_of_less_sig)(simp add: zero_option_def)\n                      with 0 1 have False \n                        by (metis \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig y sig = None\\<close> signal_of_less_sig to_bit_signal_of' zero_option_def) }\n                    moreover\n                    { assume \"to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig y sig = Some x' \\<and> x' \\<noteq> (Bv (bs ! index))\"\n                      hence \"signal_of ((Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! index))) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig y = x'\" and \"x' \\<noteq> (Bv (bs ! index))\"\n                        using trans_some_signal_of' by fastforce+\n                      with 1 have False \n                        unfolding to_bit_signal_of'_eq by auto }\n                    ultimately show False\n                      by auto\n                  qed\n                  with `y \\<le> t + dly` have \"y \\<le> ?time'\"\n                    unfolding time'_eq \n                    apply (intro Greatest_le_nat)\n                    unfolding keys_def to_trans_raw_sig_def zero_option_def by auto }\n                ultimately show \"y \\<le> ?time'\"\n                  by auto  \n              qed\n              have \"purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! index)) (Bv (bs ! index)) zeit sig \\<noteq> 0\"\n              proof -\n                have \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig t \\<noteq> Bv (bs ! index)\"\n                  using \\<open>signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig t \\<noteq> Bv (bs ! index)\\<close> by blast\n                moreover have \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! index)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig) sig (t + dly) = Bv (bs ! index)\"\n                  using h1 by blast\n                moreover have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig ?time' sig \\<noteq> None\"\n                  using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig (GREATEST n. n \\<le> t + dly \\<and> ((snd\n                  \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig\n                  := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index)) sig \\<noteq> None\\<close>\n                  \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig (the (inf_time (to_trans_raw_sig\n                  (to_trans_raw_bit (\\<sigma> sig) \\<tau> index sig)) sig (t + dly))) sig = to_trans_raw_bit (\\<sigma>\n                  sig) \\<tau> index sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega>\n                  sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig))\n                  sig n = Bv (bs ! index)) sig\\<close> by auto\n                ultimately show ?thesis\n                  using \\<open>?time = ?time'\\<close> unfolding purge_raw_def Let_def \n                  by (smt UnE \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs !\n                  index) \\<Longrightarrow> zeit = (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega>\n                  sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig))\n                  sig n = Bv (bs ! index))\\<close> \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t +\n                  dly) \\<noteq> Bv (bs ! index) \\<Longrightarrow> False\\<close> greaterThanAtMost_iff greaterThanLessThan_iff\n                  order_less_irrefl override_on_apply_notin zero_option_def)\n              qed\n              hence \"\\<exists>x\\<in>{0..<length bs}. zeit \\<in> keys (to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> x sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! x)) (Bv (bs ! x))) sig)\"\n                apply (intro bexI[where x=\"index\"])\n                unfolding to_trans_raw_sig_def keys_def apply blast\n                using \\<open>index \\<in> set [0..<length bs]\\<close> set_upt by blast\n              hence \"zeit \\<in> fold (\\<union>) (map keys (map (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))) {}\"\n                unfolding member_fold_union2 by auto\n              hence \"zeit \\<in> fold (\\<union>) (map (keys \\<circ> (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> snd) (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs]) (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))) {}\" \n                unfolding map_map[THEN sym] map_snd_zip_take length_map min.idem length_upt take_all[OF helper] by auto\n              hence \"combine_trans_bit \\<tau> (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs]) (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])) sign sig t dly zeit sig \\<noteq> None\"\n                unfolding combine_trans_bit_def \n                using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index) \\<Longrightarrow>\n                zeit = (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n\n                - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs !\n                index))\\<close> \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) \\<noteq> Bv (bs ! index)\n                \\<Longrightarrow> False\\<close> \\<open>(GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig\n                (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv\n                (bs ! index)) \\<le> t + dly\\<close> \\<open>t < (LEAST n. t < n \\<and> n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length\n                bs]. snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig (n - 1) \\<noteq> snd\n                to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig n))\\<close> zeit_def by\n                fastforce\n              hence \"purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) zeit sig \\<noteq> None\"\n                unfolding purge_raw'_def by auto\n              hence False\n                by (metis (full_types) \\<open>(LEAST n. t < n \\<and> n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length bs]. snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig (n - 1) \\<noteq> snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig n)) \\<le> t'\\<close> \\<open>\\<forall>x\\<in>dom (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig). t' < x\\<close> domIff not_le to_trans_raw_sig_def zeit_def) }\n            ultimately show False\n              by auto\n          qed\n          have \"(\\<exists>list. signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t' = Lv sign list \\<and> length list = length bs)\"\n          proof (cases \"inf_time (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs))) sig t'\")\n            case None         \n            then show ?thesis \n              using \\<open>inf_time (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs))) sig t' \\<noteq> None\\<close> by auto\n          next\n            case (Some a)\n            hence \"purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig \\<noteq> None\"\n              by (metis domIff dom_def inf_time_some_exists keys_def to_trans_raw_sig_def zero_option_def)\n            have \"a \\<le> t + dly\"\n              by (meson Some \\<open>t' < t + dly\\<close> inf_time_at_most le_less_trans less_imp_le_nat)\n            have \"t < a\"\n              using assms(2) \\<open>purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig \\<noteq> None\\<close> \n              unfolding context_invariant_def purge_raw'_def \n              by (metis \\<open>purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig \\<noteq> None\\<close> leI purge_raw_before_now_unchanged' zero_fun_def zero_option_def)\n            then obtain list where \"purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig = Some (Lv sign list) \\<and> length list = length bs\"\n              using \\<open>a \\<le> t + dly\\<close> \\<open>purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig \\<noteq> None\\<close> unfolding purge_raw'_def \n              combine_trans_bit_def   by (smt leD length_map length_zip map_nth min.idem val.simps(6))\n            then show ?thesis \n              using Some unfolding to_signal_def comp_def to_trans_raw_sig_def by auto\n          qed\n          then obtain list where \"(signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t' = Lv sign list \\<and> length list = length bs)\"\n            by auto\n          have \" \n                lval_of (snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t') = \n                lval_of (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t')\"  \n          proof (intro nth_equalityI)\n            have \"length (lval_of (snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t')) = length bs\"\n              using \\<open>snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t' = Lv sign (map (\\<lambda>b.\n              bval_of (snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig t'))\n              [0..<length bs])\\<close> by auto                              \n            also have \"... = length (lval_of (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'))\"\n            proof (cases \"inf_time (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs))) sig t'\")\n              case None\n              hence \"signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t' = (\\<sigma> sig)\"\n                unfolding to_signal_def comp_def by auto\n              then show ?thesis \n                using None \\<open>inf_time (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs))) sig t' \\<noteq> None\\<close> by blast\n            next\n              case (Some a)\n              hence \"purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig \\<noteq> None\"\n                by (metis domIff dom_def inf_time_some_exists keys_def to_trans_raw_sig_def zero_option_def)\n              have \"a \\<le> t + dly\"\n                by (meson Some \\<open>t' < t + dly\\<close> inf_time_at_most le_less_trans less_imp_le_nat)\n              have \"t < a\"\n                using assms(2) \\<open>purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig \\<noteq> None\\<close> \n                unfolding context_invariant_def purge_raw'_def \n                by (metis \\<open>purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig \\<noteq> None\\<close> leI purge_raw_before_now_unchanged' zero_fun_def zero_option_def)\n              then obtain list where \"purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig = Some (Lv sign list) \\<and> length list = length bs\"\n                using \\<open>a \\<le> t + dly\\<close> \\<open>purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) a sig \\<noteq> None\\<close> unfolding purge_raw'_def \n                combine_trans_bit_def   by (smt leD length_map length_zip map_nth min.idem val.simps(6))\n              then show ?thesis \n                using Some  by (simp add: to_signal_def to_trans_raw_sig_def)\n            qed\n            finally show \"length (lval_of (snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t')) = length (lval_of (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'))\"\n              by auto\n          next\n            fix i\n            assume \" i < length (lval_of (snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t'))\"\n            hence \"i < length bs\"\n              using \\<open>snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t' = Lv sign (map (\\<lambda>b.\n              bval_of (snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig t'))\n              [0..<length bs])\\<close> by auto                 \n            have \"lval_of (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t') ! i = list ! i\"\n              using \\<open>inf_time (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs))) sig t' \\<noteq> None\\<close> \\<open>signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t' = Lv sign list \\<and> length list = length bs \\<close> by auto\n            also have \"... = bval_of (to_bit i (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'))\"\n              using \\<open>i < length bs\\<close> \n              using \\<open>inf_time (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs))) sig t' \\<noteq> None\\<close> \\<open>signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t' = Lv sign list \\<and> length list = length bs \\<close> by auto\n            finally have \"lval_of (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t') ! i = \n                          bval_of (to_bit i (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'))\"\n              by auto\n            thus \"lval_of (snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t') ! i = lval_of (signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t') ! i\"\n              using midway2 \\<open>i < length bs\\<close>  by blast\n          qed\n          hence \" snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t' = signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'\"\n            using \\<open>signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t' = Lv sign list \\<and> length list = length bs\\<close> \\<open>snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t' = Lv sign (map (\\<lambda>b. bval_of (snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig t')) [0..<length bs])\\<close> \n            by auto }\n        moreover\n        { assume \"t' < ?zeit\"\n          hence \"snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t' =  snd \\<omega> sig t\"\n            unfolding worldline_inert_upd2.simps snd_conv \\<open>s' = sig\\<close> Let_def fun_upd_def\n            using thereis  by (simp add: \\<open>t \\<le> t'\\<close> leD)\n          also have \"... = signal_of (\\<sigma> sig) \\<tau> sig t\"\n            unfolding assms(1) worldline_raw_def snd_conv by auto\n          also have \"... = \\<sigma> sig\"\n            by (metis \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> signal_of_def zero_fun_def)\n          finally have \"snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t' = \\<sigma> sig\"\n            by auto\n          have \"inf_time (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs))) sig t' = None\"\n            unfolding inf_time_none_iff[THEN sym]\n          proof \n            { fix x \n              assume \"x \\<le> t'\"\n              assume \"x \\<in> dom (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig)\"\n              hence \"purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) x sig \\<noteq> None\"\n                unfolding to_trans_raw_sig_def dom_def  by auto\n              hence comb: \"combine_trans_bit \\<tau>\n                      (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                           (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))\n                      sign sig t dly x sig \\<noteq> None\"\n                unfolding purge_raw'_def by auto\n              have help_len: \"length (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]) \\<le> length bs - 0\"\n                by auto\n              have \"\\<forall>xa\\<in>{0..<length bs}. x \\<notin> keys (to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (Bv (bs ! xa))) sig)\"\n                unfolding keys_def to_trans_raw_sig_def\n              proof \n                fix xa\n                assume \"xa \\<in> {0..<length bs}\"\n                have \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig t = Bv (bs ! xa) \\<or> \n                      signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig (t + dly) \\<noteq> Bv (bs ! xa) \\<or> \n                      signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig t \\<noteq> Bv (bs ! xa) \\<and> \n                      signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig (t + dly) = Bv (bs ! xa)\"\n                  by auto\n                moreover\n                { assume \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig t = Bv (bs ! xa) \\<or> \n                      signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig (t + dly) \\<noteq> Bv (bs ! xa)\"\n                  hence \"purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (Bv (bs ! xa)) x sig = 0\"\n                    unfolding purge_raw_def Let_def zero_option_def \n                    apply (cases \"x \\<le> t\")\n                    apply (metis \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> \\<open>purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) x sig \\<noteq> None\\<close> purge_raw_before_now_unchanged' zero_fun_def zero_option_def)\n                    using \\<open>t' < t + dly\\<close> \\<open>x \\<le> t'\\<close> by auto }\n                moreover\n                { assume \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig t \\<noteq> Bv (bs ! xa) \\<and> \n                          signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig (t + dly) = Bv (bs ! xa)\"\n                  hence \"purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (Bv (bs ! xa)) x sig = \n                         override_on (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) (\\<lambda>n. (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig n)(sig := None))\n                           ({t<..<the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly))} \n                          \\<union> {the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly))<..t + dly}) x sig\"\n                    unfolding purge_raw_def Let_def zero_option_def by auto\n                  also have \"... = None\"\n                  proof (cases \"x \\<le> t\")\n                    case True\n                    thus ?thesis\n                      by (metis \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> \\<open>purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) x sig \\<noteq> None\\<close> purge_raw_before_now_unchanged' zero_fun_def zero_option_def)\n                  next\n                    case False\n                    have \"x < ?zeit\"\n                      using \\<open>t' < ?zeit\\<close> \\<open>x \\<le> t'\\<close> dual_order.strict_trans2 by blast\n                    also have \"... \\<le> the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly))\"\n                    proof -\n                      have \"((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! xa)\" and \"((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! xa)\"\n                        using \\<open>signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig t \\<noteq> Bv (bs ! xa) \\<and> \n                          signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig (t + dly) = Bv (bs ! xa)\\<close>\n                        unfolding assms(1) worldline_raw_def snd_conv fun_upd_def to_bit_signal_of'_eq by auto\n                      have *: \"\\<exists>n. t < n \\<and> n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)\"\n                      proof (rule ccontr)\n                        assume \"\\<not> (\\<exists>n. t < n \\<and> n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa))\"\n                        hence imp: \"\\<And>n. t < n \\<Longrightarrow> n \\<le> t + dly \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! xa)\"\n                          by auto\n                        { fix n \n                          assume \"t \\<le> n\" and \"n \\<le> t + dly\"\n                          hence \"((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! xa)\"\n                            using \\<open>((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! xa)\\<close> imp\n                          proof (induction \"n - t\" arbitrary: t dly)\n                            case 0 hence \"n = t\" by auto\n                            then show ?case \n                              using 0 by auto\n                          next\n                            case (Suc x)\n                            hence 0: \"x = n - Suc t\"\n                              by auto\n                            have 2: \"n \\<le> Suc t + (dly - 1) \"\n                              using Suc by auto\n                            hence 1: \"Suc t \\<le> n \"\n                              using Suc by linarith\n                            hence \"Suc t \\<le> t + dly\"\n                              using Suc by linarith\n                            hence 3: \"((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (Suc t) \\<noteq> Bv (bs ! xa)\"\n                              using Suc(5-6) by auto\n                            have 4: \"\\<And>n. Suc t < n \\<Longrightarrow> n \\<le> Suc t + (dly - 1) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! xa)\"\n                              using Suc(6) by auto\n                            have \"((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! xa)\"\n                              using  Suc(1)[OF 0 1 2 3 4] by auto\n                            thus ?case\n                              by auto\n                          qed }\n                        hence \"\\<And>n. t \\<le> n \\<Longrightarrow> n \\<le> t + dly \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! xa)\"\n                          by auto\n                        thus False\n                          using \\<open>((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! xa)\\<close> le_add1 by blast\n                      qed\n                      let ?time_again =\"GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)\"    \n                      have \"t < ?time_again\"\n                        using * \n                      proof -\n                        have f1: \"\\<forall>p n na. (n::nat) \\<le> Greatest p \\<or> (\\<exists>n. \\<not> n \\<le> na \\<and> p n) \\<or> \\<not> p n\"\n                          by (metis (lifting) Greatest_le_nat)\n                        obtain nn :: nat where\n                          f2: \"Bv (bs ! xa) = ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig nn \\<and> Bv (bs ! xa) \\<noteq> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (nn - 1) \\<and> nn \\<le> t + dly \\<and> t < nn\"\n                          by (metis (no_types) \"*\")\n                        then have \"nn \\<le> (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa))\"\n                          using f1 by force\n                        then show ?thesis\n                          using f2 by (meson less_le_trans)\n                      qed\n                      hence \"?time_again - 1 < ?time_again\"\n                        by auto\n                      have \"?time_again \\<le> t + dly\" and \"((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (?time_again - 1) \\<noteq> Bv (bs ! xa)\" and \"((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig ?time_again = Bv (bs ! xa)\"\n                        using GreatestI_ex_nat *  apply (metis (mono_tags, lifting))\n                        using GreatestI_ex_nat *  apply (metis (mono_tags, lifting))\n                        using GreatestI_ex_nat *  by smt\n                      have \"?w' xa sig (?time_again - 1) = ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig t\"\n                        using \\<open>t < ?time_again\\<close> \\<open>?time_again - 1 < ?time_again\\<close> \n                        unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv \n                        by (smt One_nat_def Suc_leI \\<open>((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! xa)\\<close> gr_implies_not0 le_add_diff_inverse not_less_iff_gr_or_eq plus_1_eq_Suc zero_less_diff)\n                      moreover have \"?w' xa sig (?time_again) = Bv (bs ! xa)\"\n                        unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv \n                        using False \\<open>t < (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa))\\<close> \n                        using \\<open>((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! xa)\\<close> by auto\n                      ultimately have \"?w' xa sig (?time_again - 1) \\<noteq> ?w' xa sig ?time_again\"\n                        using \\<open>((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! xa)\\<close> by auto\n                      hence \"?zeit \\<le> ?time_again\"\n                      proof -\n                        have \"t < (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) \\<and> (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) \\<le> t + dly \\<and> (\\<exists>n. n \\<in> set [0..<length bs] \\<and> snd to_worldline_init_bit \\<omega> sig n[sig, t, dly := Bv (bs ! n)] sig ((GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) - 1) \\<noteq> snd to_worldline_init_bit \\<omega> sig n[sig, t, dly := Bv (bs ! n)] sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)))\"\n                          using \\<open>(GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) \\<le> t + dly\\<close> \\<open>xa \\<in> {0..<length bs}\\<close> \\<open>snd to_worldline_init_bit \\<omega> sig xa[sig, t, dly := Bv (bs ! xa)] sig ((GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) - 1) \\<noteq> snd to_worldline_init_bit \\<omega> sig xa[sig, t, dly := Bv (bs ! xa)] sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa))\\<close> \\<open>t < (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa))\\<close> \n                          using set_upt by blast\n                        then show ?thesis\n                          by (simp add: Bex_def_raw Least_le)\n                      qed\n                      let ?time' = \" the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly))\"\n                      have \"?time_again \\<le> t + dly\"\n                        using \\<open>(GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) \\<le> t + dly\\<close> by blast\n                      have \"t < ?time_again\"\n                        using \\<open>((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! index) \\<Longrightarrow> zeit = (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! index) \\<and> ((snd \\<omega>)(sig := to_bit index \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! index))\\<close> \n                            \\<open>t < (LEAST n. t < n \\<and> n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length bs]. snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig (n - 1) \\<noteq> snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig n))\\<close> zeit_def \n                        using \\<open>t < (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa))\\<close> by linarith\n                      have \"to_bit xa (signal_of (\\<sigma> sig) \\<tau> sig (?time_again - 1)) \\<noteq> Bv (bs ! xa)\"\n                        by (smt One_nat_def Suc_leI Suc_pred \\<open>((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig ((GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) - 1) \\<noteq> Bv (bs ! xa)\\<close> \\<open>(GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) - 1 < (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa))\\<close> \\<open>t < (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa))\\<close> assms(1) fun_upd_same leD leI le_zero_eq o_apply prod.sel(2) worldline_raw_def)\n                      moreover have \"to_bit xa (signal_of (\\<sigma> sig) \\<tau> sig (?time_again)) = Bv (bs ! xa)\"\n                        using  `?time_again \\<le> t + dly` `t < ?time_again`\n                        assms(1) comp_def fun_upd_def worldline_raw_def snd_conv\n                        by (smt \\<open>((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) = Bv (bs ! xa)\\<close> order.asym)\n                      ultimately have \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) ?time_again sig \\<noteq> None\"\n                        by (metis (no_types, lifting) signal_of_less_sig to_bit_signal_of' zero_option_def)\n                      obtain val where \"to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?time_again sig = Some val\" \n                          using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?time_again sig \\<noteq> None\\<close> by auto\n                      have \"\\<exists>k\\<in>keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig). k \\<le> t + dly\"\n                      proof -\n                        have \"to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) = Some val\"\n                          by (metis \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) sig = Some val\\<close> to_trans_raw_sig_def)\n                        then have \"\\<exists>n. to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig n \\<noteq> None \\<and> n \\<le> t + dly\"\n                          using \\<open>(GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) \\<le> t + dly\\<close> by blast\n                        then show ?thesis\n                          by (simp add: keys_def zero_option_def)\n                      qed\n                      hence time'_eq: \"?time' = (GREATEST k. k \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig) \\<and> k \\<le> t + dly)\"\n                        unfolding inf_time_def by auto\n                      hence \"?time' \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig)\" and \"?time' \\<le> t + dly\"\n                        using GreatestI_ex_nat \n                        by (metis (mono_tags, lifting) \\<open>\\<exists>k\\<in>keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig). k \\<le> t + dly\\<close> inf_time_def inf_time_ex1 inf_time_some_exists)+\n                      have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?time' sig = to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?time_again sig\"\n                      proof (rule ccontr)\n                        assume \"\\<not> to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig ?time' sig = to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig ?time_again sig\"\n                        hence \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig) sig ?time_again =  val\"\n                          using trans_some_signal_of'[of \"to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig\" \"?time_again\" \"sig\" \"(\\<lambda>x. _)(sig := val)\"]\n                          using \\<open>to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig :=\n                          to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ>\n                          snd \\<omega> sig)) sig n = Bv (bs ! xa)) sig = Some val\\<close> by auto\n                        then obtain val' where \"to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig ?time' sig = Some val'\"\n                        proof -\n                          assume \"\\<And>val'. to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig)) sig (t + dly))) sig = Some val' \\<Longrightarrow> thesis\"\n                          then show ?thesis\n                            by (metis \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig)) sig (t + dly)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig) sig)\\<close> domIff dom_def keys_def not_None_eq to_trans_raw_sig_def zero_option_def)\n                        qed\n                        hence \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig) sig ?time' =  val'\"\n                          using trans_some_signal_of'[of \"to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig\" \"?time_again\" \"sig\" \"(\\<lambda>x. _)(sig := val')\"] time'_eq\n                          by (meson trans_some_signal_of')\n                        also have \"... \\<noteq> val\"\n                          using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig (GREATEST n. n \\<le> t + dly \\<and> ((snd\n                          \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig\n                          := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) sig = Some val\\<close>\n                          \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig (the (inf_time (to_trans_raw_sig\n                          (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly))) sig = Some val'\\<close>\n                          using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly))) sig \\<noteq> to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) sig\\<close> by auto\n                        finally have \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig) sig ?time' \\<noteq> \n                                      signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig) sig ?time_again \"\n                          using \\<open>signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! xa))\n                          (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig\n                          := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig :=\n                          to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) = val\\<close> by blast\n                        have \"t < ?time'\"\n                          by (smt \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly))) sig = Some val'\\<close> leI option.simps(3) option.simps(4) to_trans_raw_bit_def zero_fun_def zero_option_def)\n                        have \"((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (?time') = signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig) sig ?time'\"\n                          using `t < ?time'` to_bit_signal_of'_eq unfolding assms(1) time'_eq worldline_raw_def snd_conv fun_upd_def  by fastforce\n                        moreover have \"((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (?time_again) = signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig) sig ?time_again\"\n                          using `t < ?time_again` to_bit_signal_of'_eq unfolding assms(1) time'_eq worldline_raw_def snd_conv fun_upd_def  by fastforce\n                        ultimately have \"((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (?time') \\<noteq> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (?time_again)\"\n                          using \\<open>signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly))) \\<noteq> signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa))\\<close> by auto                  \n                        have \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig) sig ?time' = val'\"\n                          using trans_some_signal_of'[of \"to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig\" \"?time'\" \"sig\" \"(\\<lambda>x. _)(sig := val')\"] \\<open>to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig ?time' sig = Some val'\\<close>\n                          by auto\n                        have \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig)) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig)) sig (t + dly))) = \n                              inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig)) sig (t + dly)\"\n                          using time'_eq \n                        proof -\n                          have \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly) \\<noteq> None\"\n                            by (metis (no_types) \\<open>\\<And>thesis. (\\<And>val'. to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly))) sig = Some val' \\<Longrightarrow> thesis) \\<Longrightarrow> thesis\\<close> \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly)) \\<le> t + dly\\<close> inf_time_noneE2 option.simps(3) to_trans_raw_sig_def zero_option_def)\n                          then show ?thesis\n                            by (metis (no_types) \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig)\\<close> dom_def inf_time_someI keys_def option.exhaust_sel order_refl zero_option_def)\n                        qed\n                        hence \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig) sig (t + dly) = \n                              signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig) sig ?time'\"\n                          unfolding to_signal_def comp_def by auto\n                        hence \"signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig)  \\<tau> xa sig) sig ?time' = Bv (bs ! xa)\"\n                          using \\<open>signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig t \\<noteq> Bv (bs ! xa) \\<and> signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig (t + dly) = Bv (bs ! xa)\\<close> by auto\n                        have \"((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (?time_again) = Bv (bs ! xa)\"\n                          using \\<open>((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) = Bv (bs ! xa)\\<close> by blast\n                        have \"((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (?time') = Bv (bs ! xa)\"\n                          using \\<open>((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly))) = signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly)))\\<close> \\<open>signal_of (Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly))) = Bv (bs ! xa)\\<close> by auto\n                        show False\n                          using \\<open>((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) = Bv (bs ! xa)\\<close> \\<open>((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly))) = Bv (bs ! xa)\\<close> \\<open>((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly))) \\<noteq> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa))\\<close> by auto\n                      qed\n                      have h1: \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig (t + dly) = Bv (bs ! xa)\"\n                        using \\<open>signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig t \\<noteq> Bv (bs ! xa) \\<and> signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig (t + dly) = Bv (bs ! xa)\\<close> by blast\n                      have \"the (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?time' sig) = Bv (bs ! xa)\"\n                      proof -\n                        have \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly) = Some ?time'\"\n                          by (simp add: \\<open>\\<exists>k\\<in>keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig). k \\<le> t + dly\\<close> inf_time_def)\n                        thus \"the (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?time' sig) = Bv (bs ! xa)\"\n                          using h1 unfolding to_signal_def comp_def  by (metis option.simps(5) to_trans_raw_sig_def)\n                      qed\n                      have \"the (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?time_again sig) = Bv (bs ! xa)\"\n                      proof- \n                        have \" signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig ?time_again = Bv (bs ! xa)\"\n                          using \\<open>to_bit xa (signal_of (\\<sigma> sig) \\<tau> sig (?time_again)) = Bv (bs ! xa)\\<close>\n                          unfolding to_bit_signal_of'_eq[THEN sym] by auto\n                        moreover have \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig ?time_again = Some ?time_again\"\n                        proof (intro inf_time_someI)\n                          show \"?time_again \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig)\"\n                          proof -\n                            have \"\\<exists>v. to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) sig = Some v\"\n                              by (metis \\<open>\\<And>thesis. (\\<And>val. to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) sig = Some val \\<Longrightarrow> thesis) \\<Longrightarrow> thesis\\<close>)\n                            then show ?thesis\n                              by (simp add: domIff to_trans_raw_sig_def)\n                          qed\n                        qed (auto)\n                        ultimately show ?thesis\n                          unfolding to_signal_def comp_def \n                          by (simp add: to_trans_raw_sig_def)\n                      qed\n                      have \"?time_again = ?time'\"\n                      proof (rule Greatest_equality)\n                        have \"t \\<le> ?time' - 1\" \n                        proof (rule ccontr)\n                          assume \"\\<not> t \\<le> ?time' - 1\" hence \"?time' - 1 < t\"\n                            by auto\n                          hence \"?time' \\<le> t\" by auto\n                          hence \"\\<tau> ?time' sig = None\"\n                            using assms(2) unfolding context_invariant_def by (auto simp add: zero_fun_def zero_option_def)\n                          have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?time' sig \\<noteq> None\"\n                            using \\<open>?time' \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig)\\<close> \n                            by (metis domIff dom_is_keys to_trans_raw_sig_def)\n                          thus \"False\"\n                            using \\<open>\\<tau> ?time' sig = None\\<close> unfolding to_trans_raw_bit_def by auto\n                        qed\n                        moreover have \"to_bit xa (signal_of (\\<sigma> sig) \\<tau> sig (?time' - 1)) \\<noteq> Bv (bs ! xa)\"\n                          unfolding to_bit_signal_of'_eq[THEN sym]\n                        proof (cases \"\\<exists>n. t < n \\<and> n < ?time' \\<and> (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) n sig \\<noteq> None\")\n                          case False\n                          hence none: \"\\<And>n. t < n \\<Longrightarrow> n \\<le> ?time' - 1 \\<Longrightarrow> (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) n sig = 0\"\n                            by (auto simp add: zero_option_def)\n                          have \" signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig (?time' - 1) = \n                                  signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig t\"\n                            using signal_of_less_ind'[of \"t\" \"?time' - 1\" \"to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig\" \"sig\", OF none] `t \\<le> ?time' - 1`\n                            by auto                    \n                          also have \"... \\<noteq> (Bv (bs ! xa))\"\n                            using to_bit_signal_of'_eq \n                            using \\<open>signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig t \\<noteq> Bv (bs ! xa) \\<and> signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig (t + dly) = Bv (bs ! xa)\\<close> by blast\n                          finally show \" signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig (?time' - 1) \\<noteq> (Bv (bs ! xa))\"\n                            by auto\n                        next\n                          case True\n                          let ?key1 = \"(GREATEST n. t < n \\<and> n < ?time' \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig n sig \\<noteq> None)\"\n                          from True have \"t < ?key1\" and \"?key1 < ?time'\" and \" to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?key1 sig \\<noteq> None\"\n                            using GreatestI_ex_nat[OF True]  using less_imp_le_nat by blast+\n                          have *: \"\\<And>n. n > ?key1 \\<Longrightarrow> n < ?time' \\<Longrightarrow> to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig n sig = None\"\n                            using Greatest_le_nat[where P=\"\\<lambda>x. t < x \\<and> x < ?time' \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig x sig \\<noteq> None\" and b=\"?time'\"]\n                            by (smt \\<open>t < (GREATEST n. t < n \\<and> n < the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly)) \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig n sig \\<noteq> None)\\<close> leD less_imp_le_nat less_trans)\n                          have inf_some: \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (?time' - 1) = Some ?key1\"\n                          proof (rule inf_time_someI)\n                            show \"?key1 \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig)\"\n                              using `to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?key1 sig \\<noteq> None`  by (simp add: domIff to_trans_raw_sig_def)\n                          next\n                            show \"?key1 \\<le> ?time' - 1\"\n                              using `?key1 < ?time'`  by linarith\n                          next\n                            { fix ta\n                              assume \"ta \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig)\"\n                              assume \"ta \\<le> ?time' - 1\"\n                              assume \"?key1 < ta\"\n                              hence \"to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ta sig = None\"\n                                using *[OF `?key1 < ta`] `ta \\<le> ?time' - 1` by simp\n                              hence \"ta \\<notin> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig)\"\n                                by (simp add: domIff to_trans_raw_sig_def)\n                              with `ta \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig)` have False by auto }\n                            thus \"\\<forall>ta \\<in> dom (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig). ta \\<le> ?time' - 1 \\<longrightarrow> ta \\<le> ?key1\"\n                              using not_le_imp_less by blast\n                          qed\n                          have non_stut: \" non_stuttering (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) (to_bit xa o \\<sigma>) sig\"\n                            using assms(5) non_stuttering_to_trans_raw_bit by force\n                          hence \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig  ?key1 sig) \\<noteq> to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?time' sig\"\n                          proof -\n                            have \"?key1 \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig)\"\n                              using `to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?key1 sig \\<noteq> None`  by (simp add: keys_def to_trans_raw_sig_def zero_option_def)\n                            moreover have \"?time' \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig)\"\n                              using \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig)\\<close> by blast\n                            moreover have \"\\<forall>k. ?key1 < k \\<and> k < ?time' \\<longrightarrow> k \\<notin> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig)\"\n                              using *  by (metis (mono_tags, lifting) domIff keys_def mem_Collect_eq to_trans_raw_sig_def\n                              zero_option_def)\n                            ultimately show ?thesis    \n                              using `?key1 < ?time'` non_stut unfolding non_stuttering_def\n                              by (simp add: to_trans_raw_sig_def)\n                          qed\n                          moreover have \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?time' sig) = Some (Bv (bs ! xa))\"\n                            by (metis \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa\n                            sig)) sig (t + dly)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau>\n                            xa sig) sig)\\<close> \\<open>the (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig (the (inf_time (to_trans_raw_sig\n                            (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly))) sig) = Bv (bs ! xa)\\<close>\n                            domIff dom_def keys_def option.exhaust_sel to_trans_raw_sig_def zero_option_def)\n                          ultimately have neq: \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?key1 sig) \\<noteq> Some (Bv (bs ! xa))\"\n                            by auto\n                          then obtain valu where \"(to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?key1 sig) = Some valu\" and \"valu \\<noteq> Bv (bs ! xa)\"\n                            using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?key1 sig \\<noteq> None\\<close> by blast\n                          have \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig (?time' - 1) = \n                                the (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig ?key1)\"\n                            using inf_some unfolding to_signal_def comp_def\n                            by auto\n                          also have \"... \\<noteq> Bv (bs ! xa)\"\n                            using \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?key1 sig \\<noteq> None\\<close> neq \n                            by (metis \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig (GREATEST n. t < n \\<and> n < the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly)) \\<and> to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig n sig \\<noteq> None) sig = Some valu\\<close> option.sel to_trans_raw_sig_def)\n                          finally show \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig (?time' - 1) \\<noteq> (Bv (bs ! xa))\"\n                            by blast\n                        qed\n                        ultimately have \"((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (?time' - 1) = to_bit xa (signal_of (\\<sigma> sig) \\<tau> sig (?time' - 1))\"\n                          unfolding assms(1) worldline_raw_def snd_conv fun_upd_def comp_def by auto\n                        hence *: \"((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (?time' - 1) \\<noteq> Bv (bs ! xa)\"\n                          using \\<open>to_bit xa (signal_of (\\<sigma> sig) \\<tau> sig (?time' - 1)) \\<noteq> Bv (bs ! xa)\\<close> by auto\n                        have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?time' sig = Some (Bv (bs ! xa))\"\n                          using \\<open>the (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig (the (inf_time (to_trans_raw_sig\n                          (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly))) sig) = Bv (bs ! xa)\\<close>\n                          \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig :=\n                          to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit\n                          xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) sig \\<noteq> None\\<close> \\<open>to_trans_raw_bit (\\<sigma> sig)\n                          \\<tau> xa sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa\n                          sig)) sig (t + dly))) sig = to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig (GREATEST n. n \\<le>\n                          t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa)\n                          \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) sig\\<close> by\n                          force\n                        have \"to_bit xa (signal_of (\\<sigma> sig) \\<tau> sig ?time') = (Bv (bs ! xa))\"\n                          using trans_some_signal_of'[of \"to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig\", OF `to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?time' sig = Some (Bv (bs ! xa))`]\n                          using to_bit_signal_of'_eq by fastforce\n                        hence \" ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly))) = Bv (bs ! xa)\"\n                          unfolding assms(1) worldline_raw_def snd_conv fun_upd_def comp_def \n                          using \\<open>t \\<le> the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly)) - 1\\<close> by auto\n                        thus \"?time' \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (?time' - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig ?time' = Bv (bs ! xa)\"    \n                          using * `?time' \\<le> t + dly` by auto  \n                      next\n                        have \"t \\<le> ?time' - 1\" \n                        proof (rule ccontr)\n                          assume \"\\<not> t \\<le> ?time' - 1\" hence \"?time' - 1 < t\"\n                            by auto\n                          hence \"?time' \\<le> t\" by auto\n                          hence \"\\<tau> ?time' sig = None\"\n                            using assms(2) unfolding context_invariant_def by (auto simp add: zero_fun_def zero_option_def)\n                          have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?time' sig \\<noteq> None\"\n                            using \\<open>?time' \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig)\\<close> \n                            by (metis domIff dom_is_keys to_trans_raw_sig_def)\n                          thus \"False\"\n                            using \\<open>\\<tau> ?time' sig = None\\<close> unfolding to_trans_raw_bit_def by auto\n                        qed\n                        fix y\n                        assume \"y \\<le> t + dly \\<and>  ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (y - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig y = Bv (bs ! xa)\"\n                        hence \"y \\<le> t + dly\" and \"((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (y - 1) \\<noteq> Bv (bs ! xa)\" and \"((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (y) = Bv (bs ! xa)\"\n                          by auto\n                        have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig ?time' sig = Some (Bv (bs ! xa))\"\n                          by (metis \\<open>the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly)) \\<in> keys (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig)\\<close> \\<open>the (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly))) sig) = Bv (bs ! xa)\\<close> domIff dom_def keys_def option.exhaust_sel to_trans_raw_sig_def zero_option_def)\n                        hence \"t < ?time'\"\n                          by (smt \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) sig \\<noteq> None\\<close> \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig (the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig)) sig (t + dly))) sig = to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa)) sig\\<close> leI option.simps(4) to_trans_raw_bit_def zero_fun_def zero_option_def)\n                        have \"y \\<le> t \\<or> t < y\"\n                          by auto\n                        moreover\n                        { assume \"y \\<le> t\"\n                          hence \"y < ?time'\" using `t < ?time'` by linarith }\n                        moreover\n                        { assume \"t < y\"\n                          hence \"((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (y - 1) =  to_bit xa (signal_of (\\<sigma> sig) \\<tau> sig (y - 1))\"\n                            unfolding assms(1) worldline_raw_def snd_conv fun_upd_def comp_def  by auto\n                          hence 0: \"... \\<noteq> (Bv (bs ! xa))\"\n                            using \\<open>((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (y - 1) \\<noteq> Bv (bs ! xa)\\<close> by auto\n                          have \"((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig y =  to_bit xa (signal_of (\\<sigma> sig) \\<tau> sig y)\"\n                            using `t < y`  unfolding assms(1) worldline_raw_def snd_conv fun_upd_def comp_def  by auto\n                          hence 1: \"... = Bv (bs ! xa)\"\n                            using \\<open>((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig y = Bv (bs ! xa)\\<close> by auto\n                          have \"to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig y sig = Some (Bv (bs ! xa))\"\n                          proof (rule ccontr)\n                            assume \"\\<not> to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig y sig = Some (Bv (bs ! xa))\"\n                            then obtain x' where \"to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig y sig = None \\<or> to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig y sig = Some x' \\<and> x' \\<noteq> (Bv (bs ! xa))\"\n                              using domIff by fastforce\n                            moreover\n                            { assume \"to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig y sig = None\"\n                              hence \"signal_of (\\<sigma> sig) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig y = \n                                     signal_of (\\<sigma> sig) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig (y - 1)\"\n                                by (intro signal_of_less_sig)(simp add: zero_option_def)\n                              with 0 1 have False \n                                by (metis \\<open>to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig y sig = None\\<close> signal_of_less_sig to_bit_signal_of' zero_option_def) }\n                            moreover\n                            { assume \"to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig y sig = Some x' \\<and> x' \\<noteq> (Bv (bs ! xa))\"\n                              hence \"signal_of ((Bv (case \\<sigma> sig of Bv b' \\<Rightarrow> b' | Lv sign bs \\<Rightarrow> bs ! xa))) (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) sig y = x'\" and \"x' \\<noteq> (Bv (bs ! xa))\"\n                                using trans_some_signal_of' by fastforce+\n                              with 1 have False \n                                unfolding to_bit_signal_of'_eq by auto }\n                            ultimately show False\n                              by auto\n                          qed\n                          with `y \\<le> t + dly` have \"y \\<le> ?time'\"\n                            unfolding time'_eq \n                            apply (intro Greatest_le_nat)\n                            unfolding keys_def to_trans_raw_sig_def zero_option_def by auto }\n                        ultimately show \"y \\<le> ?time'\"\n                          by auto  \n                      qed\n                      thus ?thesis    \n                        using \\<open>(LEAST n. t < n \\<and> n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length bs]. snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig (n - 1) \\<noteq> snd to_worldline_init_bit \\<omega> sig b[sig, t, dly := Bv (bs ! b)] sig n)) \\<le> (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! xa) \\<and> ((snd \\<omega>)(sig := to_bit xa \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! xa))\\<close> by linarith\n                    qed\n                    finally show ?thesis\n                      by (simp add: False not_le_imp_less)\n                  qed\n                  finally have \"purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (Bv (bs ! xa)) x sig = 0\"\n                    by (auto simp add: zero_option_def) }\n                ultimately have \"purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (Bv (bs ! xa)) x sig = 0\"\n                  by auto\n                thus \"x \\<notin> {k. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (Bv (bs ! xa)) k sig \\<noteq> 0}\"\n                  by auto\n              qed\n              hence \"x \\<notin> fold (\\<union>) (map (keys \\<circ> (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> snd) (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs]) (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))) {}\"\n                unfolding member_fold_union2 map_map[THEN sym] map_snd_zip_take length_map min.idem length_upt\n                take_all[OF help_len] by auto                  \n              with comb have \"False\"\n                unfolding combine_trans_bit_def \n                by (metis \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> \\<open>t' < t + dly\\<close> \\<open>x \\<le> t'\\<close> diff_diff_cancel less_imp_diff_less less_not_refl nat_diff_split zero_fun_def zero_less_diff zero_option_def) }\n            thus \" \\<And>x. x \\<in> dom (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig) \\<Longrightarrow> t' < x\"\n              using leI by blast\n          qed\n          hence \"signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t' = \\<sigma> sig\"\n            unfolding to_signal_def comp_def by auto\n          hence \"snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t' = signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'\"\n            using \\<open>snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t' = \\<sigma> sig\\<close> by auto }\n        ultimately have \"snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t' = signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'\"\n          by blast }\n      moreover\n      { assume thereisnt: \"\\<not> (\\<exists>n>t. n \\<le> t + dly \\<and> (\\<exists>b\\<in>set [0..<length bs]. ?w' b sig (n - 1) \\<noteq> ?w' b sig n))\"\n        hence \"snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t' = snd \\<omega> sig t\"\n          unfolding worldline_inert_upd2.simps snd_conv using \\<open>t' < t + dly\\<close> \n          using \\<open>s' = sig\\<close> \\<open>t \\<le> t'\\<close> by auto\n        also have \"... = signal_of (\\<sigma> sig) \\<tau> sig t\"\n          unfolding assms(1) worldline_raw_def snd_conv by auto\n        also have \"... = \\<sigma> sig\"\n          by (metis \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> signal_of_def zero_fun_def)\n        finally have \"snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t' = \\<sigma> sig\"\n          by auto\n        have \"inf_time (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs))) sig t' = None\"\n          unfolding inf_time_none_iff[THEN sym]\n        proof \n          { fix x \n            assume \"\\<not> t' < x\" hence \"x \\<le> t'\" by auto\n            hence \"x < t + dly\"\n              using \\<open>t' < t + dly\\<close> le_less_trans by blast\n            assume \"x \\<in> dom (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig)\"\n            hence \"purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) x sig \\<noteq> None\"\n              unfolding dom_def to_trans_raw_sig_def by auto\n            hence *: \"combine_trans_bit \\<tau>\n                    (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                         (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])) sign sig t dly x sig \\<noteq> None\"\n              unfolding purge_raw'_def by auto\n            have **: \"length (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]) \\<le> length bs - 0\"\n              by auto\n              \n            have \"x < t \\<or> t \\<le> x\"\n              by auto\n            moreover\n            { assume \"x < t\"\n              hence \"False\"\n                using * unfolding combine_trans_bit_def \n                by (simp add: \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> zero_fun_def zero_option_def) }\n            moreover\n            { assume \"t \\<le> x\"\n              hence \"x \\<in> fold (\\<union>)\n              (map (keys \\<circ> (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) \\<circ> snd)\n                (zip (map (\\<lambda>n. Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) [0..<length bs])\n                  (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs])))\n              {}\"\n                using * unfolding combine_trans_bit_def \n                by (metis (full_types) \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> \\<open>x < t + dly\\<close> dual_order.asym zero_fun_def zero_option_def)\n              also have \"... = fold (\\<union>) (map keys (map (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> sig) (map (\\<lambda>n. purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> n sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! n)) (Bv (bs ! n))) [0..<length bs]))) {}\"\n                unfolding map_map[THEN sym] map_snd_zip_take length_map length_upt min.idem take_all[OF **]\n                by auto\n              finally have \"\\<exists>xa\\<in>{0..<length bs}. \n                x \\<in> keys (to_trans_raw_sig (purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> xa sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! xa)) (Bv (bs ! xa))) sig)\"\n                unfolding member_fold_union2 by auto\n              then obtain b where pnone: \"(purge_raw (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) t dly sig (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (Bv (bs ! b))) x sig \\<noteq> None\" and \"b < length bs\"\n                unfolding to_trans_raw_sig_def keys_def zero_option_def  using atLeastLessThan_iff by blast\n              have \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig t = Bv (bs ! b) \n                  \\<or> signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (t + dly) \\<noteq> Bv (bs ! b)\n                  \\<or> signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig t \\<noteq>  Bv (bs ! b) \\<and> \n                    signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (t + dly) = Bv (bs ! b)\"\n                by auto\n              moreover\n              { assume \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig t = Bv (bs ! b) \n                  \\<or> signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (t + dly) \\<noteq> Bv (bs ! b)\"\n                hence \"False\"\n                  using pnone unfolding purge_raw_def Let_def\n                  by (metis (no_types, lifting) \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> \\<open>purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) x sig \\<noteq> None\\<close> \\<open>x < t + dly\\<close> less_or_eq_imp_le linorder_neqE_nat pnone purge_raw_before_now_unchanged' purge_raw_neq_0_imp zero_fun_def zero_option_def) }\n              moreover\n              { assume \"signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig t \\<noteq>  Bv (bs ! b) \\<and> \n                        signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (t + dly) = Bv (bs ! b)\"\n                hence \"inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly) = Some x\"\n                  using pnone unfolding purge_raw_def Let_def \n                  by (metis \\<open>\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\\<close> \\<open>purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs) x sig \\<noteq> None\\<close> \\<open>x < t + dly\\<close> not_le_imp_less pnone purge_raw_before_now_unchanged' purge_raw_neq_0_imp zero_fun_def zero_option_def)\n                let ?time' = \" the (inf_time (to_trans_raw_sig (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig)) sig (t + dly))\"\n                let ?time = \"(GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b))\"\n                have \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! b)\"\n                  using \\<open>signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig t \\<noteq> Bv (bs ! b) \\<and> signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (t + dly) = Bv (bs ! b)\\<close> \\<open>snd \\<omega> sig t = signal_of (\\<sigma> sig) \\<tau> sig t\\<close> to_bit_signal_of'_eq by fastforce\n                have \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! b)\"\n                  using \\<open>signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig t \\<noteq> Bv (bs ! b) \\<and> signal_of (Bv (case \\<sigma> sig of Bv b \\<Rightarrow> b | Lv sign bs \\<Rightarrow> bs ! b)) (to_trans_raw_bit (\\<sigma> sig) \\<tau> b sig) sig (t + dly) = Bv (bs ! b)\\<close>  \n                  unfolding to_bit_signal_of'_eq fun_upd_def  assms(1) worldline_raw_def snd_conv by auto\n                have *: \"\\<exists>n. t < n \\<and> n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)\"\n                proof (rule ccontr)\n                  assume \"\\<not> (\\<exists>n. t < n \\<and> n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b))\"\n                  hence imp: \"\\<And>n. t < n \\<Longrightarrow> n \\<le> t + dly \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! b)\"\n                    by auto\n                  { fix n \n                    assume \"t \\<le> n\" and \"n \\<le> t + dly\"\n                    hence \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! b)\"\n                      using \\<open>((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! b)\\<close> imp\n                    proof (induction \"n - t\" arbitrary: t dly)\n                      case 0 hence \"n = t\" by auto\n                      then show ?case \n                        using 0 by auto\n                    next\n                      case (Suc x)\n                      hence 0: \"x = n - Suc t\"\n                        by auto\n                      have 2: \"n \\<le> Suc t + (dly - 1) \"\n                        using Suc by auto\n                      hence 1: \"Suc t \\<le> n \"\n                        using Suc by linarith\n                      hence \"Suc t \\<le> t + dly\"\n                        using Suc by linarith\n                      hence 3: \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (Suc t) \\<noteq> Bv (bs ! b)\"\n                        using Suc(5-6) by auto\n                      have 4: \"\\<And>n. Suc t < n \\<Longrightarrow> n \\<le> Suc t + (dly - 1) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! b)\"\n                        using Suc(6) by auto\n                      have \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! b)\"\n                        using  Suc(1)[OF 0 1 2 3 4] by auto\n                      thus ?case\n                        by auto\n                    qed }\n                  hence \"\\<And>n. t \\<le> n \\<Longrightarrow> n \\<le> t + dly \\<Longrightarrow> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n \\<noteq> Bv (bs ! b)\"\n                    by auto\n                  thus False\n                    using \\<open>((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! b)\\<close> le_add1 by blast\n                qed\n                have \"t < ?time\"\n                proof -\n                  have f1: \"\\<forall>p n na. (n::nat) \\<le> Greatest p \\<or> (\\<exists>n. \\<not> n \\<le> na \\<and> p n) \\<or> \\<not> p n\"\n                    by (metis (lifting) Greatest_le_nat)\n                  obtain nn :: nat where\n                    f2: \"Bv (bs ! b) = ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig nn \\<and> Bv (bs ! b) \\<noteq> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (nn - 1) \\<and> nn \\<le> t + dly \\<and> t < nn\"\n                    by (metis (lifting) \"*\")\n                  then have \"nn \\<le> (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b))\"\n                    using f1 by fastforce\n                  then show ?thesis\n                    using f2 order.strict_trans2 by blast\n                qed\n                have \"?time \\<le> t + dly\"\n                  by (metis (mono_tags, lifting) \"*\" GreatestI_ex_nat fun_upd_same)\n                hence \"((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (?time - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig ?time = Bv (bs ! b)\"\n                  by (smt \"*\" GreatestI_nat)\n                hence \"?w' b sig (?time - 1) \\<noteq> ?w' b sig (?time)\"\n                  unfolding to_worldline_init_bit_def worldline_inert_upd_def snd_conv\n                  by (smt \\<open>((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (t + dly) = Bv (bs ! b)\\<close> \\<open>((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig t \\<noteq> Bv (bs ! b)\\<close> diff_le_self order.strict_iff_order)\n                with thereisnt have False\n                  using \\<open>(GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b)) \\<le> t + dly\\<close> \\<open>b < length bs\\<close> \\<open>t < (GREATEST n. n \\<le> t + dly \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig (n - 1) \\<noteq> Bv (bs ! b) \\<and> ((snd \\<omega>)(sig := to_bit b \\<circ> snd \\<omega> sig)) sig n = Bv (bs ! b))\\<close> by auto }\n              ultimately have False\n                by auto }\n            ultimately have False\n              by auto }\n          thus \"\\<And>x. x \\<in> dom (to_trans_raw_sig (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig) \\<Longrightarrow> t' < x\"\n            by auto\n        qed\n        hence \"signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t' = \\<sigma> sig\"\n          unfolding to_signal_def comp_def by auto\n        hence \"snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t' = signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'\"\n          using \\<open>snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t' = \\<sigma> sig\\<close> by auto }\n      ultimately have \"snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t' = signal_of (\\<sigma> sig) (purge_raw' \\<tau> t dly sig (\\<sigma> sig) (Lv sign bs)) sig t'\"\n        by blast }\n    ultimately have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t'\"\n      by (smt \\<tau>'_def inr_post_raw'_def not_le signal_of_trans_post2 snd_conv worldline_raw_def) }\n  moreover\n  { assume \"s' \\<noteq> sig \\<or> t' < t\"\n    moreover\n    { assume \"t' < t\"\n      hence 0: \" snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' =  signal_of (def s') \\<theta> s' t'\"\n        unfolding worldline_raw_def by auto\n      have \"t' < t + dly\"\n        using `t' < t` by auto\n      have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>) s' t' = snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t'\"\n        using `t' < t`  by (simp add: worldline_raw_def)\n      hence \"snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t' = snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t'\"\n        using `t' < t`  unfolding assms(1) worldline_inert_upd2.simps snd_conv worldline_inert_upd_def fun_upd_def\n        by auto }\n    moreover\n    { assume \"s' \\<noteq> sig\"\n      hence \"snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t' = snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>) s' t'\"\n        unfolding worldline_inert_upd2.simps snd_conv fun_upd_def assms(1) by auto\n      also have \"... = snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t'\"\n      proof -\n        have \"\\<And>n. (to_trans_raw_sig \\<tau> s') n = (to_trans_raw_sig \\<tau>' s') n\"\n          using `s' \\<noteq> sig` unfolding \\<tau>'_def inr_post_raw'_def\n          by (metis purge_raw_does_not_affect_other_sig' to_trans_raw_sig_def trans_post_raw_diff_sig)\n        hence \"signal_of (\\<sigma> s') \\<tau> s' t' = signal_of (\\<sigma> s') \\<tau>'  s' t'\"\n          by (meson signal_of_equal_when_trans_sig_equal_upto)\n        thus ?thesis\n          unfolding worldline_raw_def by auto\n      qed\n      finally have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t' \"\n        by auto }\n    ultimately have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t'\"\n      by auto }\n  ultimately show \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') s' t' = snd (worldline_inert_upd2 \\<omega> sig t dly (Lv sign bs)) s' t' \"\n    by blast\nqed (simp add: assms(1) worldline_inert_upd_def worldline_raw_def)\n\nlemma lift_inr_post_worldline_upd_comb:\n  assumes \"\\<omega> = worldline_raw t \\<sigma> \\<theta> def \\<tau>\"\n  assumes \"context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>\"\n  assumes \"t, \\<sigma>, \\<gamma>, \\<theta>, def \\<turnstile> <Bassign_inert sig exp dly, \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\"\n  assumes \"0 < dly\"\n  assumes \"non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma> sig\"\n  assumes \"All (non_stuttering (to_trans_raw_sig \\<theta>) def)\"\n  assumes \"beval_world_raw \\<omega> t exp v\"\n  shows \"worldline_raw t \\<sigma> \\<theta> def \\<tau>' = worldline_inert_upd2 \\<omega> sig t dly v\"\n  using lift_inr_post_worldline_upd2 lift_inr_post_worldline_upd\n  by (metis assms(1) assms(2) assms(3) assms(4) assms(5) assms(6) assms(7) val.exhaust)\n\nlemma Bassign_inert_sound:\n  assumes \"0 < dly\"\n  shows \"\\<turnstile>\\<^sub>t {P} Bassign_inert sig exp dly {Q} \\<Longrightarrow> \\<Turnstile>\\<^sub>t {P} Bassign_inert sig exp dly {Q}\"\nproof -\n  assume \"\\<turnstile>\\<^sub>t {P} Bassign_inert sig exp dly {Q}\"\n  hence imp: \"\\<forall>w. P w \\<longrightarrow> (\\<exists>x. beval_world_raw w t exp x \\<and> Q (worldline_inert_upd2 w sig t dly x))\"\n    by (auto dest!: Bassign_inertE)\n  { fix \\<sigma> :: \"'a state\"\n    fix \\<tau> \\<tau>' \\<theta> :: \"'a trans_raw\"\n    fix w w' :: \"'a  worldline_init\"\n    fix \\<gamma> def\n    assume c: \"context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>\"\n    assume \"All (non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma>)\"\n    assume \"All (non_stuttering (to_trans_raw_sig \\<theta>) def)\"\n    assume \"w = worldline_raw t \\<sigma> \\<theta> def \\<tau>\"\n    assume \"P w\"\n    assume ex: \"t, \\<sigma>, \\<gamma>, \\<theta>, def \\<turnstile> <Bassign_inert sig exp dly, \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\"\n    obtain x where \"beval_world_raw w t exp x\"\n      using \\<open>P w\\<close> imp by metis\n    have \"snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') = snd (worldline_inert_upd2 w sig t dly x)\"\n      using lift_inr_post_worldline_upd_comb[OF `w = worldline_raw t \\<sigma> \\<theta> def \\<tau>` c ex assms] \\<open>All (non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma>)\\<close>\n      \\<open>beval_world_raw w t exp x\\<close> \\<open>All (non_stuttering (to_trans_raw_sig \\<theta>) def)\\<close> by auto\n    with imp and `P w` have \"Q(worldline_inert_upd2 w sig t dly x)\"\n      using \\<open>beval_world_raw w t exp x\\<close> beval_world_raw_deterministic by metis\n    assume \"w' = worldline_raw t \\<sigma> \\<theta> def \\<tau>'\"\n    hence \"Q w'\"\n      using `Q(worldline_inert_upd2 w sig t dly x)` `snd (worldline_raw t \\<sigma> \\<theta> def \\<tau>') = snd (worldline_inert_upd2 w sig t dly x)`\n      by (metis (full_types) \\<open>All (non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma>)\\<close> \\<open>All (non_stuttering\n      (to_trans_raw_sig \\<theta>) def)\\<close> \\<open>beval_world_raw w t exp x\\<close> \\<open>w = worldline_raw t \\<sigma> \\<theta> def \\<tau>\\<close> assms c\n      ex lift_inr_post_worldline_upd_comb) }\n  thus \" \\<Turnstile>\\<^sub>t {P} Bassign_inert sig exp dly {Q}\"\n    unfolding seq_hoare_valid_def  by meson\nqed\n\nlemma Bcase_empty_valid:\n  \"\\<Turnstile>\\<^sub>t {P} Bcase exp [] {P}\"\nproof -\n  { fix \\<sigma> :: \"'a state\"\n    fix \\<tau> :: \"'a trans_raw\"\n    fix \\<gamma> \\<theta> \\<tau>' w w' def\n    assume w_def: \"w = worldline_raw t \\<sigma> \\<theta> def \\<tau>\"\n    assume \" P w\"\n    assume \" t , \\<sigma> , \\<gamma> , \\<theta>, def  \\<turnstile> <Bcase exp [] , \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>' \"\n    hence \"\\<tau>' = \\<tau>\"\n      using b_seq_exec.intros(10) b_seq_exec_deterministic  by blast\n    assume \" w' = worldline_raw t \\<sigma> \\<theta> def \\<tau>'\"\n    hence \"w' = w\"\n      unfolding \\<open>\\<tau>' = \\<tau>\\<close> w_def by auto\n    hence \"P w'\"\n      using \\<open>P w\\<close> by auto }\n  thus ?thesis\n    unfolding seq_hoare_valid_def by metis\nqed\n\nlemma Bcase_other_valid:\n  assumes \" \\<Turnstile>\\<^sub>t {P} ss {Q}\"\n  shows \"\\<Turnstile>\\<^sub>t {P} Bcase exp ((Others, ss) # choices) {Q}\"\nproof -\n  { fix \\<sigma> :: \"'a state\"\n    fix \\<tau> :: \"'a trans_raw\"\n    fix \\<gamma> \\<theta> \\<tau>' w w' def\n    assume \"t , \\<sigma> , \\<gamma> , \\<theta>, def  \\<turnstile> <Bcase exp ((Others, ss) # choices) , \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\"\n    hence \"t, \\<sigma>, \\<gamma>, \\<theta>, def \\<turnstile> < ss, \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\"\n      using Femto_VHDL_raw.seq_cases_bcase by fastforce\n    assume \"w = worldline_raw t \\<sigma> \\<theta> def \\<tau>\"\n    assume \"P w\"\n    assume \"context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau> \"\n    assume \"All (non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma>)\"\n    assume \"All (non_stuttering (to_trans_raw_sig \\<theta>) def)\"\n    assume \"w' = worldline_raw t \\<sigma> \\<theta> def \\<tau>' \"\n    hence  \"Q w'\"\n      using assms unfolding seq_hoare_valid_def\n      by (metis \\<open>All (non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma>)\\<close> \\<open>All (non_stuttering (to_trans_raw_sig\n      \\<theta>) def)\\<close> \\<open>P w\\<close> \\<open>context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>\\<close> \\<open>t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> < ss , \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\\<close> \\<open>w =\n      worldline_raw t \\<sigma> \\<theta> def \\<tau>\\<close>) }\n  thus ?thesis\n    unfolding seq_hoare_valid_def  by metis\nqed\n\nlemma Bcase_if_valid:\n  assumes \"\\<Turnstile>\\<^sub>t {\\<lambda>a. P a \\<and> (\\<exists>x. beval_world_raw a t exp x \\<and> beval_world_raw a t exp' x)} ss {Q}\"\n  assumes \"\\<Turnstile>\\<^sub>t {\\<lambda>a. P a \\<and> (\\<exists>x x'. beval_world_raw a t exp x \\<and> beval_world_raw a t exp' x' \\<and> x \\<noteq> x')} Bcase exp choices {Q}\"\n  shows   \"\\<Turnstile>\\<^sub>t {P} Bcase exp ((Explicit exp', ss) # choices) {Q}\"\nproof -\n  { fix \\<sigma> :: \"'a state\"\n    fix \\<tau> :: \"'a trans_raw\"\n    fix \\<gamma> \\<theta> \\<tau>' w w' def\n    assume *: \" t , \\<sigma> , \\<gamma> , \\<theta>, def  \\<turnstile> <Bcase exp ((Explicit exp', ss) # choices) , \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\"\n    have \"\\<exists>x x'. t , \\<sigma> , \\<gamma> , \\<theta>, def  \\<turnstile> exp \\<longrightarrow>\\<^sub>b x \\<and> t , \\<sigma> , \\<gamma> , \\<theta>, def  \\<turnstile> exp' \\<longrightarrow>\\<^sub>b x'\"\n      apply (rule Femto_VHDL_raw.seq_cases_bcase[OF *, rotated])\n      by (metis Pair_inject choices.inject list.inject) blast+\n    then obtain x x' where \"t , \\<sigma> , \\<gamma> , \\<theta>, def  \\<turnstile> exp \\<longrightarrow>\\<^sub>b x\" and \"t , \\<sigma> , \\<gamma> , \\<theta>, def  \\<turnstile> exp' \\<longrightarrow>\\<^sub>b x'\"\n      by blast\n    assume \"P w\"\n    assume \"context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>\"\n    hence \"\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0\"\n      unfolding context_invariant_def by auto\n    assume w_def: \"w = worldline_raw t \\<sigma> \\<theta> def \\<tau>\"\n    hence \"state_of_world w t = \\<sigma>\"\n      using state_of_world[OF _ `\\<And>n. n \\<le> t \\<Longrightarrow> \\<tau> n = 0`] by auto\n    have \"event_of_world w t = \\<gamma>\"\n    proof (cases \"0 < t\")\n      case True\n      fix s\n      have \"snd w s t = \\<sigma> s\"\n        using `state_of_world w t = \\<sigma>` unfolding state_of_world_def by auto\n      moreover have \"snd w s (t - 1) = signal_of (def s) \\<theta> s (t - 1)\"\n        using True  by (simp add: w_def worldline_raw_def)\n      ultimately show ?thesis\n        using True \\<open>context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>\\<close>\n        unfolding event_of_world_def context_invariant_def\n        by (smt Collect_cong \\<open>state_of_world w t = \\<sigma>\\<close> diff_less less_numeral_extra(1)\n        less_numeral_extra(3) snd_conv state_of_world_def w_def worldline_raw_def)\n    next\n      case False\n      hence \"t = 0\" by auto\n      hence ev: \"event_of_world w t = {s. snd w s 0 \\<noteq> def s}\"\n        unfolding event_of_world_def by (simp add: w_def worldline_raw_def)\n      have \\<gamma>_def': \"\\<gamma> = {s. \\<sigma> s \\<noteq> signal_of (def s) \\<theta> s 0}\"\n        using `t = 0` \\<open>context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>\\<close> unfolding context_invariant_def\n        by auto\n      have \"\\<theta> = 0\"\n        using \\<open>context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>\\<close> unfolding `t = 0`\n        by (auto simp add: context_invariant_def zero_fun_def)\n      hence \"\\<And>s. signal_of (def s) \\<theta> s 0 = def s\"\n        using signal_of_empty by metis\n      hence \"\\<gamma> = {s. \\<sigma> s \\<noteq> def s}\"\n        using \\<gamma>_def' by auto\n      moreover have \"\\<And>s.  snd w s 0 = \\<sigma> s\"\n        using `state_of_world w t = \\<sigma>` `t = 0` unfolding state_of_world_def by auto\n      ultimately  have \"\\<gamma> = {s. snd w s 0 \\<noteq> def s}\"\n        by auto\n      thus ?thesis  using ev by auto\n    qed\n    assume \"All (non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma>)\"\n    assume \"All (non_stuttering (to_trans_raw_sig \\<theta>) def)\"\n    hence \"derivative_hist_raw w t = \\<theta>\"\n      using derivative_is_history unfolding w_def\n      by (metis \\<open>context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>\\<close> context_invariant_def)\n    hence \"beval_world_raw w t exp x\"\n    proof -\n      have \"get_time w = def\"\n        by (simp add: w_def worldline_raw_def)\n      then show ?thesis\n        by (simp add: \\<open>derivative_hist_raw w t = \\<theta>\\<close> \\<open>event_of_world w t = \\<gamma>\\<close> \\<open>state_of_world w t = \\<sigma>\\<close> \\<open>t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> exp \\<longrightarrow>\\<^sub>b x\\<close> beval_world_raw.intros)\n    qed\n    have \"beval_world_raw w t exp' x'\"\n      using \\<open>All (non_stuttering (to_trans_raw_sig \\<theta>) def)\\<close> \\<open>context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>\\<close> \\<open>t , \\<sigma>\n      , \\<gamma> , \\<theta>, def \\<turnstile> exp' \\<longrightarrow>\\<^sub>b x'\\<close> beval_beval_world_raw_ci w_def by fastforce\n    assume \"w' = worldline_raw t \\<sigma> \\<theta> def \\<tau>'\"\n    have \"x = x' \\<or> x \\<noteq> x'\"\n      by auto\n    moreover\n    { assume \"x = x'\"\n      have \"t , \\<sigma> , \\<gamma> , \\<theta>, def  \\<turnstile> < ss , \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\"\n        apply (rule seq_cases_bcase[OF *, rotated])\n        by (metis Pair_inject \\<open>t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> exp \\<longrightarrow>\\<^sub>b x\\<close> \\<open>t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> exp' \\<longrightarrow>\\<^sub>b x'\\<close> \\<open>x\n        = x'\\<close> beval_raw_deterministic choices.inject list.inject)blast+\n      with `P w` have \"Q w'\"\n        using assms unfolding seq_hoare_valid_def\n        by (metis \\<open>All (non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma>)\\<close> \\<open>All (non_stuttering\n        (to_trans_raw_sig \\<theta>) def)\\<close> \\<open>beval_world_raw w t exp x\\<close> \\<open>beval_world_raw w t exp' x'\\<close>\n        \\<open>context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>\\<close> \\<open>w' = worldline_raw t \\<sigma> \\<theta> def \\<tau>'\\<close> \\<open>x = x'\\<close> w_def) }\n    moreover\n    { assume \"x \\<noteq> x'\"\n      have \"t, \\<sigma>, \\<gamma>, \\<theta>, def \\<turnstile> < Bcase exp choices, \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\"\n        apply (rule seq_cases_bcase[OF *])\n        by (metis Pair_inject \\<open>t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> exp \\<longrightarrow>\\<^sub>b x\\<close> \\<open>t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> exp' \\<longrightarrow>\\<^sub>b x'\\<close>\n        \\<open>x \\<noteq> x'\\<close> beval_raw_deterministic choices.inject list.inject) auto\n      with `P w` have \"Q w'\"\n        using assms(2) unfolding seq_hoare_valid_def\n        by (metis \\<open>All (non_stuttering (to_trans_raw_sig \\<tau>) \\<sigma>)\\<close> \\<open>All (non_stuttering\n        (to_trans_raw_sig \\<theta>) def)\\<close> \\<open>beval_world_raw w t exp x\\<close> \\<open>beval_world_raw w t exp' x'\\<close>\n        \\<open>context_invariant t \\<sigma> \\<gamma> \\<theta> def \\<tau>\\<close> \\<open>w' = worldline_raw t \\<sigma> \\<theta> def \\<tau>'\\<close> \\<open>x \\<noteq> x'\\<close> w_def) }\n    ultimately have \"Q w'\"\n      by auto }\n  thus ?thesis\n    unfolding seq_hoare_valid_def by metis\nqed\n\n\n\nend", "meta": {"author": "rizaldialbert", "repo": "vhdl-semantics", "sha": "352f89c9ccdfe830c054757dfd86caeadbd67159", "save_path": "github-repos/isabelle/rizaldialbert-vhdl-semantics", "path": "github-repos/isabelle/rizaldialbert-vhdl-semantics/vhdl-semantics-352f89c9ccdfe830c054757dfd86caeadbd67159/VHDL_Hoare.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.523420348936324, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.27396886168062323}}
{"text": "(*  Title:       Lifting to Non-Ground Calculi of the Saturation Framework\n *  Author:      Sophie Tourret <stourret at mpi-inf.mpg.de>, 2018-2020 *)\n\nsection \\<open>Lifting to Non-ground Calculi\\<close>\n\ntext \\<open>The section 3.1 to 3.3 of the report are covered by the current section.\n  Various forms of lifting are proven correct. These allow to obtain the dynamic\n  refutational completeness of a non-ground calculus from the static refutational\n  completeness of its ground counterpart.\\<close>\n\ntheory Lifting_to_Non_Ground_Calculi\n  imports\n    Calculi\n    Well_Quasi_Orders.Minimal_Elements\nbegin\n\nsubsection \\<open>Standard Lifting\\<close>\n\nlocale standard_lifting = Non_ground: inference_system Inf_F +\n  Ground: calculus_with_red_crit Bot_G Inf_G entails_G Red_Inf_G Red_F_G\n  for\n    Bot_F :: \\<open>'f set\\<close> and\n    Inf_F :: \\<open>'f inference set\\<close> and\n    Bot_G :: \\<open>'g set\\<close> and\n    Inf_G ::  \\<open>'g inference set\\<close> and\n    entails_G ::  \\<open>'g set  \\<Rightarrow> 'g set  \\<Rightarrow> bool\\<close> (infix \"\\<Turnstile>G\" 50) and\n    Red_Inf_G :: \\<open>'g set \\<Rightarrow> 'g inference set\\<close> and\n    Red_F_G :: \\<open>'g set \\<Rightarrow> 'g set\\<close>\n  + fixes\n    \\<G>_F :: \\<open>'f \\<Rightarrow> 'g set\\<close> and\n    \\<G>_Inf :: \\<open>'f inference \\<Rightarrow> 'g inference set option\\<close>\n  assumes\n    Bot_F_not_empty: \"Bot_F \\<noteq> {}\" and\n    Bot_map_not_empty: \\<open>B \\<in> Bot_F \\<Longrightarrow> \\<G>_F B \\<noteq> {}\\<close> and\n    Bot_map: \\<open>B \\<in> Bot_F \\<Longrightarrow> \\<G>_F B \\<subseteq> Bot_G\\<close> and\n    Bot_cond: \\<open>\\<G>_F C \\<inter> Bot_G \\<noteq> {} \\<longrightarrow> C \\<in> Bot_F\\<close> and\n    inf_map: \\<open>\\<iota> \\<in> Inf_F \\<Longrightarrow> \\<G>_Inf \\<iota> \\<noteq> None \\<Longrightarrow> the (\\<G>_Inf \\<iota>) \\<subseteq> Red_Inf_G (\\<G>_F (concl_of \\<iota>))\\<close>\nbegin\n\nabbreviation \\<G>_set :: \\<open>'f set \\<Rightarrow> 'g set\\<close> where\n  \\<open>\\<G>_set N \\<equiv> \\<Union> (\\<G>_F ` N)\\<close>\n\n\n\ndefinition entails_\\<G>  :: \\<open>'f set \\<Rightarrow> 'f set \\<Rightarrow> bool\\<close> (infix \"\\<Turnstile>\\<G>\" 50) where\n  \\<open>N1 \\<Turnstile>\\<G> N2 \\<equiv> \\<G>_set N1 \\<Turnstile>G \\<G>_set N2\\<close>\n\nlemma subs_Bot_G_entails:\n  assumes\n    not_empty: \\<open>sB \\<noteq> {}\\<close> and\n    in_bot: \\<open>sB \\<subseteq> Bot_G\\<close>\n  shows \\<open>sB \\<Turnstile>G N\\<close>\nproof -\n  have \\<open>\\<exists>B. B \\<in> sB\\<close> using not_empty by auto\n  then obtain B where B_in: \\<open>B \\<in> sB\\<close> by auto\n  then have r_trans: \\<open>{B} \\<Turnstile>G N\\<close> using Ground.bot_implies_all in_bot by auto\n  have l_trans: \\<open>sB \\<Turnstile>G {B}\\<close> using B_in Ground.subset_entailed by auto\n  then show ?thesis using r_trans Ground.entails_trans[of sB \"{B}\"] by auto\nqed\n\n(* lem:derived-consequence-relation *)\nsublocale lifted_consequence_relation: consequence_relation\n  where Bot=Bot_F and entails=entails_\\<G>\nproof\n  show \"Bot_F \\<noteq> {}\" using Bot_F_not_empty .\nnext\n  show \\<open>B\\<in>Bot_F \\<Longrightarrow> {B} \\<Turnstile>\\<G> N\\<close> for B N\n  proof -\n    assume \\<open>B \\<in> Bot_F\\<close>\n    then show \\<open>{B} \\<Turnstile>\\<G> N\\<close>\n      using Bot_map Ground.bot_implies_all[of _ \"\\<G>_set N\"] subs_Bot_G_entails Bot_map_not_empty\n      unfolding entails_\\<G>_def\n      by auto\n  qed\nnext\n  fix N1 N2 :: \\<open>'f set\\<close>\n  assume\n    \\<open>N2 \\<subseteq> N1\\<close>\n  then show \\<open>N1 \\<Turnstile>\\<G> N2\\<close> using entails_\\<G>_def \\<G>_subset Ground.subset_entailed by auto\nnext\n  fix N1 N2\n  assume\n    N1_entails_C: \\<open>\\<forall>C \\<in> N2. N1 \\<Turnstile>\\<G> {C}\\<close>\n  show \\<open>N1 \\<Turnstile>\\<G> N2\\<close> using Ground.all_formulas_entailed N1_entails_C entails_\\<G>_def\n    by (smt UN_E UN_I Ground.entail_set_all_formulas singletonI)\nnext\n  fix N1 N2 N3\n  assume\n    \\<open>N1 \\<Turnstile>\\<G> N2\\<close> and \\<open>N2 \\<Turnstile>\\<G> N3\\<close>\n  then show \\<open>N1 \\<Turnstile>\\<G> N3\\<close> using entails_\\<G>_def Ground.entails_trans by blast\nqed\n\nend\n\nsubsection \\<open>Strong Standard Lifting\\<close>\n\n(* rmk:strong-standard-lifting *)\nlocale strong_standard_lifting = Non_ground: inference_system Inf_F +\n  Ground: calculus_with_red_crit Bot_G Inf_G entails_G Red_Inf_G Red_F_G\n  for\n    Bot_F :: \\<open>'f set\\<close> and\n    Inf_F :: \\<open>'f inference set\\<close> and\n    Bot_G :: \\<open>'g set\\<close> and\n    Inf_G ::  \\<open>'g inference set\\<close> and\n    entails_G ::  \\<open>'g set  \\<Rightarrow> 'g set  \\<Rightarrow> bool\\<close> (infix \"\\<Turnstile>G\" 50) and\n    Red_Inf_G :: \\<open>'g set \\<Rightarrow> 'g inference set\\<close> and\n    Red_F_G :: \\<open>'g set \\<Rightarrow> 'g set\\<close>\n  + fixes\n    \\<G>_F :: \\<open>'f \\<Rightarrow> 'g set\\<close> and\n    \\<G>_Inf :: \\<open>'f inference \\<Rightarrow> 'g inference set option\\<close>\n  assumes\n    Bot_F_not_empty: \"Bot_F \\<noteq> {}\" and\n    Bot_map_not_empty: \\<open>B \\<in> Bot_F \\<Longrightarrow> \\<G>_F B \\<noteq> {}\\<close> and\n    Bot_map: \\<open>B \\<in> Bot_F \\<Longrightarrow> \\<G>_F B \\<subseteq> Bot_G\\<close> and\n    Bot_cond: \\<open>\\<G>_F C \\<inter> Bot_G \\<noteq> {} \\<longrightarrow> C \\<in> Bot_F\\<close> and\n    strong_inf_map: \\<open>\\<iota> \\<in> Inf_F \\<Longrightarrow> \\<G>_Inf \\<iota> \\<noteq> None \\<Longrightarrow> concl_of ` (the (\\<G>_Inf \\<iota>)) \\<subseteq> (\\<G>_F (concl_of \\<iota>))\\<close> and\n    inf_map_in_Inf: \\<open>\\<iota> \\<in> Inf_F \\<Longrightarrow> \\<G>_Inf \\<iota> \\<noteq> None \\<Longrightarrow> the (\\<G>_Inf \\<iota>) \\<subseteq> Inf_G\\<close>\nbegin\n\nsublocale standard_lifting\nproof\n  show \"Bot_F \\<noteq> {}\" using Bot_F_not_empty .\nnext\n  fix B\n  assume b_in: \"B \\<in> Bot_F\"\n  show \"\\<G>_F B \\<noteq> {}\" using Bot_map_not_empty[OF b_in] .\nnext\n  fix B\n  assume b_in: \"B \\<in> Bot_F\"\n  show \"\\<G>_F B \\<subseteq> Bot_G\" using Bot_map[OF b_in] .\nnext\n  show \"\\<And>C. \\<G>_F C \\<inter> Bot_G \\<noteq> {} \\<longrightarrow> C \\<in> Bot_F\" using Bot_cond .\nnext\n  fix \\<iota>\n  assume i_in: \"\\<iota> \\<in> Inf_F\" and\n    some_g: \"\\<G>_Inf \\<iota> \\<noteq> None\"\n  show \"the (\\<G>_Inf \\<iota>) \\<subseteq> Red_Inf_G (\\<G>_F (concl_of \\<iota>))\"\n  proof\n    fix \\<iota>G\n    assume ig_in1: \"\\<iota>G \\<in> the (\\<G>_Inf \\<iota>)\"\n    then have ig_in2: \"\\<iota>G \\<in> Inf_G\" using inf_map_in_Inf[OF i_in some_g] by blast\n    show \"\\<iota>G \\<in> Red_Inf_G (\\<G>_F (concl_of \\<iota>))\"\n      using strong_inf_map[OF i_in some_g] Ground.Red_Inf_of_Inf_to_N[OF ig_in2]\n        ig_in1 by blast\n  qed\nqed\n\nend\n\nsubsection \\<open>Lifting with a Family of Well-founded Orderings\\<close>\n\nlocale lifting_with_wf_ordering_family =\n  standard_lifting Bot_F Inf_F Bot_G Inf_G entails_G Red_Inf_G Red_F_G \\<G>_F \\<G>_Inf\n  for\n    Bot_F :: \\<open>'f set\\<close> and\n    Inf_F :: \\<open>'f inference set\\<close> and\n    Bot_G :: \\<open>'g set\\<close> and\n    entails_G :: \\<open>'g set \\<Rightarrow> 'g set \\<Rightarrow> bool\\<close> (infix \"\\<Turnstile>G\" 50) and\n    Inf_G :: \\<open>'g inference set\\<close> and\n    Red_Inf_G :: \\<open>'g set \\<Rightarrow> 'g inference set\\<close> and\n    Red_F_G :: \\<open>'g set \\<Rightarrow> 'g set\\<close> and\n    \\<G>_F :: \"'f \\<Rightarrow> 'g set\" and\n    \\<G>_Inf :: \"'f inference \\<Rightarrow> 'g inference set option\"\n  + fixes\n    Prec_F_g :: \\<open>'g \\<Rightarrow> 'f \\<Rightarrow> 'f \\<Rightarrow> bool\\<close>\n  assumes\n    all_wf: \"minimal_element (Prec_F_g g) UNIV\"\nbegin\n\ndefinition Red_Inf_\\<G> :: \"'f set \\<Rightarrow> 'f inference set\" where\n  \\<open>Red_Inf_\\<G> N = {\\<iota> \\<in> Inf_F. (\\<G>_Inf \\<iota> \\<noteq> None \\<and> the (\\<G>_Inf \\<iota>) \\<subseteq> Red_Inf_G (\\<G>_set N))\n    \\<or> (\\<G>_Inf \\<iota> = None \\<and> \\<G>_F (concl_of \\<iota>) \\<subseteq> (\\<G>_set N \\<union> Red_F_G (\\<G>_set N)))}\\<close>\n\ndefinition Red_F_\\<G> :: \"'f set \\<Rightarrow> 'f set\" where\n  \\<open>Red_F_\\<G> N = {C. \\<forall>D \\<in> \\<G>_F C. D \\<in> Red_F_G (\\<G>_set N) \\<or> (\\<exists>E \\<in> N. Prec_F_g D E C \\<and> D \\<in> \\<G>_F E)}\\<close>\n\nlemma Prec_trans:\n  assumes\n    \\<open>Prec_F_g D A B\\<close> and\n    \\<open>Prec_F_g D B C\\<close>\n  shows\n    \\<open>Prec_F_g D A C\\<close>\n  using minimal_element.po assms unfolding po_on_def transp_on_def by (smt UNIV_I all_wf)\n\nlemma prop_nested_in_set: \"D \\<in> P C \\<Longrightarrow> C \\<in> {C. \\<forall>D \\<in> P C. A D \\<or> B C D} \\<Longrightarrow> A D \\<or> B C D\"\n  by blast\n\n(* lem:wolog-C'-nonredundant *)\nlemma Red_F_\\<G>_equiv_def:\n  \\<open>Red_F_\\<G> N = {C. \\<forall>Di \\<in> \\<G>_F C. Di \\<in> Red_F_G (\\<G>_set N) \\<or>\n    (\\<exists>E \\<in> (N - Red_F_\\<G> N). Prec_F_g Di E C \\<and> Di \\<in> \\<G>_F E)}\\<close>\nproof (rule;clarsimp)\n  fix C D\n  assume\n    C_in: \\<open>C \\<in> Red_F_\\<G> N\\<close> and\n    D_in: \\<open>D \\<in> \\<G>_F C\\<close> and\n    not_sec_case: \\<open>\\<forall>E \\<in> N - Red_F_\\<G> N. Prec_F_g D E C \\<longrightarrow> D \\<notin> \\<G>_F E\\<close>\n  have C_in_unfolded: \"C \\<in> {C. \\<forall>Di \\<in> \\<G>_F C. Di \\<in> Red_F_G (\\<G>_set N) \\<or>\n    (\\<exists>E\\<in>N. Prec_F_g Di E C \\<and> Di \\<in> \\<G>_F E)}\"\n    using C_in unfolding Red_F_\\<G>_def .\n  have neg_not_sec_case: \\<open>\\<not> (\\<exists>E\\<in>N - Red_F_\\<G> N. Prec_F_g D E C \\<and> D \\<in> \\<G>_F E)\\<close>\n    using not_sec_case by clarsimp\n  have unfol_C_D: \\<open>D \\<in> Red_F_G (\\<G>_set N) \\<or> (\\<exists>E\\<in>N. Prec_F_g D E C \\<and> D \\<in> \\<G>_F E)\\<close>\n    using prop_nested_in_set[of D \\<G>_F C \"\\<lambda>x. x \\<in> Red_F_G (\\<Union> (\\<G>_F ` N))\"\n      \"\\<lambda>x y. \\<exists>E \\<in> N. Prec_F_g y E x \\<and> y \\<in> \\<G>_F E\", OF D_in C_in_unfolded] by blast\n  show \\<open>D \\<in> Red_F_G (\\<G>_set N)\\<close>\n  proof (rule ccontr)\n    assume contrad: \\<open>D \\<notin> Red_F_G (\\<G>_set N)\\<close>\n    have non_empty: \\<open>\\<exists>E\\<in>N. Prec_F_g D E C \\<and> D \\<in> \\<G>_F E\\<close> using contrad unfol_C_D by auto\n    define B where \\<open>B = {E \\<in> N. Prec_F_g D E C \\<and> D \\<in> \\<G>_F E}\\<close>\n    then have B_non_empty: \\<open>B \\<noteq> {}\\<close> using non_empty by auto\n    interpret minimal_element \"Prec_F_g D\" UNIV using all_wf[of D] .\n    obtain F :: 'f where F: \\<open>F = min_elt B\\<close> by auto\n    then have D_in_F: \\<open>D \\<in> \\<G>_F F\\<close> unfolding B_def using non_empty\n      by (smt Sup_UNIV Sup_upper UNIV_I contra_subsetD empty_iff empty_subsetI mem_Collect_eq\n        min_elt_mem unfol_C_D)\n    have F_prec: \\<open>Prec_F_g D F C\\<close> using F min_elt_mem[of B, OF _ B_non_empty] unfolding B_def by auto\n    have F_not_in: \\<open>F \\<notin> Red_F_\\<G> N\\<close>\n    proof\n      assume F_in: \\<open>F \\<in> Red_F_\\<G> N\\<close>\n      have unfol_F_D: \\<open>D \\<in> Red_F_G (\\<G>_set N) \\<or> (\\<exists>G\\<in>N. Prec_F_g D G F \\<and> D \\<in> \\<G>_F G)\\<close>\n        using F_in D_in_F unfolding Red_F_\\<G>_def by auto\n      then have \\<open>\\<exists>G\\<in>N. Prec_F_g D G F \\<and> D \\<in> \\<G>_F G\\<close> using contrad D_in unfolding Red_F_\\<G>_def by auto\n      then obtain G where G_in: \\<open>G \\<in> N\\<close> and G_prec: \\<open>Prec_F_g D G F\\<close> and G_map: \\<open>D \\<in> \\<G>_F G\\<close> by auto\n      have \\<open>Prec_F_g D G C\\<close> using G_prec F_prec Prec_trans by blast\n      then have \\<open>G \\<in> B\\<close> unfolding B_def using G_in G_map by auto\n      then show \\<open>False\\<close> using F G_prec min_elt_minimal[of B G, OF _ B_non_empty] by auto\n    qed\n    have \\<open>F \\<in> N\\<close> using F by (metis B_def B_non_empty mem_Collect_eq min_elt_mem top_greatest)\n    then have \\<open>F \\<in> N - Red_F_\\<G> N\\<close> using F_not_in by auto\n    then show \\<open>False\\<close>\n      using D_in_F neg_not_sec_case F_prec by blast\n  qed\nnext\n  fix C\n  assume only_if: \\<open>\\<forall>D\\<in>\\<G>_F C. D \\<in> Red_F_G (\\<G>_set N) \\<or> (\\<exists>E\\<in>N - Red_F_\\<G> N. Prec_F_g D E C \\<and> D \\<in> \\<G>_F E)\\<close>\n  show \\<open>C \\<in> Red_F_\\<G> N\\<close> unfolding Red_F_\\<G>_def using only_if by auto\nqed\n\n(* lem:lifting-main-technical *)\nlemma not_red_map_in_map_not_red: \\<open>\\<G>_set N - Red_F_G (\\<G>_set N) \\<subseteq> \\<G>_set (N - Red_F_\\<G> N)\\<close>\nproof\n  fix D\n  assume\n    D_hyp: \\<open>D \\<in> \\<G>_set N - Red_F_G (\\<G>_set N)\\<close>\n  interpret minimal_element \"Prec_F_g D\" UNIV using all_wf[of D] .\n  have D_in: \\<open>D \\<in> \\<G>_set N\\<close> using D_hyp by blast\n  have  D_not_in: \\<open>D \\<notin> Red_F_G (\\<G>_set N)\\<close> using D_hyp by blast\n  have exist_C: \\<open>\\<exists>C. C \\<in> N \\<and> D \\<in> \\<G>_F C\\<close> using D_in by auto\n  define B where \\<open>B = {C \\<in> N. D \\<in> \\<G>_F C}\\<close>\n  obtain C where C: \\<open>C = min_elt B\\<close> by auto\n  have C_in_N: \\<open>C \\<in> N\\<close>\n    using exist_C by (metis B_def C empty_iff mem_Collect_eq min_elt_mem top_greatest)\n  have D_in_C: \\<open>D \\<in> \\<G>_F C\\<close>\n    using exist_C by (metis B_def C empty_iff mem_Collect_eq min_elt_mem top_greatest)\n  have C_not_in: \\<open>C \\<notin> Red_F_\\<G> N\\<close>\n  proof\n    assume C_in: \\<open>C \\<in> Red_F_\\<G> N\\<close>\n    have \\<open>D \\<in> Red_F_G (\\<G>_set N) \\<or> (\\<exists>E\\<in>N. Prec_F_g D E C \\<and> D \\<in> \\<G>_F E)\\<close>\n      using C_in D_in_C unfolding Red_F_\\<G>_def by auto\n    then show \\<open>False\\<close>\n      proof\n        assume \\<open>D \\<in> Red_F_G (\\<G>_set N)\\<close>\n        then show \\<open>False\\<close> using D_not_in by simp\n      next\n        assume \\<open>\\<exists>E\\<in>N. Prec_F_g D E C \\<and> D \\<in> \\<G>_F E\\<close>\n        then show \\<open>False\\<close>\n          using C by (metis (no_types, lifting) B_def UNIV_I empty_iff mem_Collect_eq\n              min_elt_minimal top_greatest)\n      qed\n  qed\n  show \\<open>D \\<in> \\<G>_set (N - Red_F_\\<G> N)\\<close> using D_in_C C_not_in C_in_N by blast\nqed\n\n(* lem:nonredundant-entails-redundant *)\nlemma Red_F_Bot_F: \\<open>B \\<in> Bot_F \\<Longrightarrow> N \\<Turnstile>\\<G> {B} \\<Longrightarrow> N - Red_F_\\<G> N \\<Turnstile>\\<G> {B}\\<close>\nproof -\n  fix B N\n  assume\n    B_in: \\<open>B \\<in> Bot_F\\<close> and\n    N_entails: \\<open>N \\<Turnstile>\\<G> {B}\\<close>\n  then have to_bot: \\<open>\\<G>_set N - Red_F_G (\\<G>_set N) \\<Turnstile>G \\<G>_F B\\<close>\n    using Ground.Red_F_Bot Bot_map unfolding entails_\\<G>_def\n      by (smt cSup_singleton Ground.entail_set_all_formulas image_insert image_is_empty subsetCE)\n  have from_f: \\<open>\\<G>_set (N - Red_F_\\<G> N) \\<Turnstile>G \\<G>_set N - Red_F_G (\\<G>_set N)\\<close>\n    using Ground.subset_entailed[OF not_red_map_in_map_not_red] by blast\n  then have \\<open>\\<G>_set (N - Red_F_\\<G> N) \\<Turnstile>G \\<G>_F B\\<close> using to_bot Ground.entails_trans by blast\n  then show \\<open>N - Red_F_\\<G> N \\<Turnstile>\\<G> {B}\\<close> using Bot_map unfolding entails_\\<G>_def by simp\nqed\n\n(* lem:redundancy-monotonic-addition 1/2 *)\nlemma Red_F_of_subset_F: \\<open>N \\<subseteq> N' \\<Longrightarrow> Red_F_\\<G> N \\<subseteq> Red_F_\\<G> N'\\<close>\n  using Ground.Red_F_of_subset unfolding Red_F_\\<G>_def by (smt Collect_mono \\<G>_subset subset_iff)\n\n(* lem:redundancy-monotonic-addition 2/2 *)\nlemma Red_Inf_of_subset_F: \\<open>N \\<subseteq> N' \\<Longrightarrow> Red_Inf_\\<G> N \\<subseteq> Red_Inf_\\<G> N'\\<close>\n  using Collect_mono \\<G>_subset subset_iff Ground.Red_Inf_of_subset unfolding Red_Inf_\\<G>_def\n  by (smt Ground.Red_F_of_subset Un_iff)\n\n(* lem:redundancy-monotonic-deletion-forms *)\nlemma Red_F_of_Red_F_subset_F: \\<open>N' \\<subseteq> Red_F_\\<G> N \\<Longrightarrow> Red_F_\\<G> N \\<subseteq> Red_F_\\<G> (N - N')\\<close>\nproof\n  fix N N' C\n  assume\n    N'_in_Red_F_N: \\<open>N' \\<subseteq> Red_F_\\<G> N\\<close> and\n    C_in_red_F_N: \\<open>C \\<in> Red_F_\\<G> N\\<close>\n  have lem8: \\<open>\\<forall>D \\<in> \\<G>_F C. D \\<in> Red_F_G (\\<G>_set N) \\<or> (\\<exists>E \\<in> (N - Red_F_\\<G> N). Prec_F_g D E C \\<and> D \\<in> \\<G>_F E)\\<close>\n    using Red_F_\\<G>_equiv_def C_in_red_F_N by blast\n  show \\<open>C \\<in> Red_F_\\<G> (N - N')\\<close> unfolding Red_F_\\<G>_def\n  proof (rule,rule)\n    fix D\n    assume \\<open>D \\<in> \\<G>_F C\\<close>\n    then have \\<open>D \\<in> Red_F_G (\\<G>_set N) \\<or> (\\<exists>E \\<in> (N - Red_F_\\<G> N). Prec_F_g D E C \\<and> D \\<in> \\<G>_F E)\\<close>\n      using lem8 by auto\n    then show \\<open>D \\<in> Red_F_G (\\<G>_set (N - N')) \\<or> (\\<exists>E\\<in>N - N'. Prec_F_g D E C \\<and> D \\<in> \\<G>_F E)\\<close>\n    proof\n      assume \\<open>D \\<in> Red_F_G (\\<G>_set N)\\<close>\n      then have \\<open>D \\<in> Red_F_G (\\<G>_set N - Red_F_G (\\<G>_set N))\\<close>\n        using Ground.Red_F_of_Red_F_subset[of \"Red_F_G (\\<G>_set N)\" \"\\<G>_set N\"] by auto\n      then have \\<open>D \\<in> Red_F_G (\\<G>_set (N - Red_F_\\<G> N))\\<close>\n        using Ground.Red_F_of_subset[OF not_red_map_in_map_not_red[of N]] by auto\n      then have \\<open>D \\<in> Red_F_G (\\<G>_set (N - N'))\\<close>\n        using N'_in_Red_F_N \\<G>_subset[of \"N - Red_F_\\<G> N\" \"N - N'\"]\n        by (smt DiffE DiffI Ground.Red_F_of_subset subsetCE subsetI)\n      then show ?thesis by blast\n    next\n      assume \\<open>\\<exists>E\\<in>N - Red_F_\\<G> N. Prec_F_g D E C \\<and> D \\<in> \\<G>_F E\\<close>\n      then obtain E where\n        E_in: \\<open>E\\<in>N - Red_F_\\<G> N\\<close> and\n        E_prec_C: \\<open>Prec_F_g D E C\\<close> and\n        D_in: \\<open>D \\<in> \\<G>_F E\\<close>\n        by auto\n      have \\<open>E \\<in> N - N'\\<close> using E_in N'_in_Red_F_N by blast\n      then show ?thesis using E_prec_C D_in by blast\n    qed\n  qed\nqed\n\n(* lem:redundancy-monotonic-deletion-infs *)\nlemma Red_Inf_of_Red_F_subset_F: \\<open>N' \\<subseteq> Red_F_\\<G> N \\<Longrightarrow> Red_Inf_\\<G> N \\<subseteq> Red_Inf_\\<G> (N - N') \\<close>\nproof\n  fix N N' \\<iota>\n  assume\n    N'_in_Red_F_N: \\<open>N' \\<subseteq> Red_F_\\<G> N\\<close> and\n    i_in_Red_Inf_N: \\<open>\\<iota> \\<in> Red_Inf_\\<G> N\\<close>\n  have i_in: \\<open>\\<iota> \\<in> Inf_F\\<close> using i_in_Red_Inf_N unfolding Red_Inf_\\<G>_def by blast\n  {\n    assume not_none: \"\\<G>_Inf \\<iota> \\<noteq> None\"\n    have \\<open>\\<forall>\\<iota>' \\<in> the (\\<G>_Inf \\<iota>). \\<iota>' \\<in> Red_Inf_G (\\<G>_set N)\\<close>\n      using not_none i_in_Red_Inf_N unfolding Red_Inf_\\<G>_def by auto\n    then have \\<open>\\<forall>\\<iota>' \\<in> the (\\<G>_Inf \\<iota>). \\<iota>' \\<in> Red_Inf_G (\\<G>_set N - Red_F_G (\\<G>_set N))\\<close>\n      using not_none Ground.Red_Inf_of_Red_F_subset by blast\n    then have ip_in_Red_Inf_G: \\<open>\\<forall>\\<iota>' \\<in> the (\\<G>_Inf \\<iota>). \\<iota>' \\<in> Red_Inf_G (\\<G>_set (N - Red_F_\\<G> N))\\<close>\n      using not_none Ground.Red_Inf_of_subset[OF not_red_map_in_map_not_red[of N]] by auto\n    then have not_none_in: \\<open>\\<forall>\\<iota>' \\<in> the (\\<G>_Inf \\<iota>). \\<iota>' \\<in> Red_Inf_G (\\<G>_set (N - N'))\\<close>\n      using not_none N'_in_Red_F_N\n      by (meson Diff_mono Ground.Red_Inf_of_subset \\<G>_subset subset_iff subset_refl)\n    then have \"the (\\<G>_Inf \\<iota>) \\<subseteq> Red_Inf_G (\\<G>_set (N - N'))\" by blast\n  }\n  moreover {\n    assume none: \"\\<G>_Inf \\<iota> = None\"\n    have ground_concl_subs: \"\\<G>_F (concl_of \\<iota>) \\<subseteq> (\\<G>_set N \\<union> Red_F_G (\\<G>_set N))\"\n      using none i_in_Red_Inf_N unfolding Red_Inf_\\<G>_def by blast\n    then have d_in_imp12: \"D \\<in> \\<G>_F (concl_of \\<iota>) \\<Longrightarrow> D \\<in> \\<G>_set N - Red_F_G (\\<G>_set N) \\<or> D \\<in> Red_F_G (\\<G>_set N)\"\n      by blast\n    have d_in_imp1: \"D \\<in> \\<G>_set N - Red_F_G (\\<G>_set N) \\<Longrightarrow> D \\<in> \\<G>_set (N - N')\"\n      using not_red_map_in_map_not_red N'_in_Red_F_N by blast\n    have d_in_imp_d_in: \"D \\<in> Red_F_G (\\<G>_set N) \\<Longrightarrow> D \\<in> Red_F_G (\\<G>_set N - Red_F_G (\\<G>_set N))\"\n      using Ground.Red_F_of_Red_F_subset[of \"Red_F_G (\\<G>_set N)\" \"\\<G>_set N\"] by blast\n    have g_subs1: \"\\<G>_set N - Red_F_G (\\<G>_set N) \\<subseteq> \\<G>_set (N - Red_F_\\<G> N)\"\n      using not_red_map_in_map_not_red unfolding Red_F_\\<G>_def by auto\n    have g_subs2: \"\\<G>_set (N - Red_F_\\<G> N) \\<subseteq> \\<G>_set (N - N')\"\n      using N'_in_Red_F_N by blast\n    have d_in_imp2: \"D \\<in> Red_F_G (\\<G>_set N) \\<Longrightarrow> D \\<in> Red_F_G (\\<G>_set (N - N'))\"\n      using Ground.Red_F_of_subset Ground.Red_F_of_subset[OF g_subs1]\n        Ground.Red_F_of_subset[OF g_subs2] d_in_imp_d_in by blast\n    have \"\\<G>_F (concl_of \\<iota>) \\<subseteq> (\\<G>_set (N - N') \\<union> Red_F_G (\\<G>_set (N - N')))\"\n      using d_in_imp12 d_in_imp1 d_in_imp2\n      by (smt Ground.Red_F_of_Red_F_subset Ground.Red_F_of_subset UnCI UnE Un_Diff_cancel2\n        ground_concl_subs g_subs1 g_subs2 subset_iff)\n  }\n  ultimately show \\<open>\\<iota> \\<in> Red_Inf_\\<G> (N - N')\\<close> using i_in unfolding Red_Inf_\\<G>_def by auto\nqed\n\n(* lem:concl-contained-implies-red-inf *)\nlemma Red_Inf_of_Inf_to_N_F:\n  assumes\n    i_in: \\<open>\\<iota> \\<in> Inf_F\\<close> and\n    concl_i_in: \\<open>concl_of \\<iota> \\<in> N\\<close>\n  shows\n    \\<open>\\<iota> \\<in> Red_Inf_\\<G> N \\<close>\nproof -\n  have \\<open>\\<iota> \\<in> Inf_F \\<Longrightarrow> \\<G>_Inf \\<iota> \\<noteq> None \\<Longrightarrow> the (\\<G>_Inf \\<iota>) \\<subseteq> Red_Inf_G (\\<G>_F (concl_of \\<iota>))\\<close> using inf_map by simp\n  moreover have \\<open>Red_Inf_G (\\<G>_F (concl_of \\<iota>)) \\<subseteq> Red_Inf_G (\\<G>_set N)\\<close>\n    using concl_i_in Ground.Red_Inf_of_subset by blast\n  moreover have \"\\<iota> \\<in> Inf_F \\<Longrightarrow> \\<G>_Inf \\<iota> = None \\<Longrightarrow> concl_of \\<iota> \\<in> N \\<Longrightarrow> \\<G>_F (concl_of \\<iota>) \\<subseteq> \\<G>_set N\"\n    by blast\n  ultimately show ?thesis using i_in concl_i_in unfolding Red_Inf_\\<G>_def by auto\nqed\n\n(* thm:FRedsqsubset-is-red-crit and also thm:lifted-red-crit if ordering empty *)\nsublocale lifted_calculus_with_red_crit: calculus_with_red_crit\n  where\n    Bot = Bot_F and Inf = Inf_F and entails = entails_\\<G> and\n    Red_Inf = Red_Inf_\\<G> and Red_F = Red_F_\\<G>\nproof\n  fix B N N' \\<iota>\n  show \\<open>Red_Inf_\\<G> N \\<subseteq> Inf_F\\<close> unfolding Red_Inf_\\<G>_def by blast\n  show \\<open>B \\<in> Bot_F \\<Longrightarrow> N \\<Turnstile>\\<G> {B} \\<Longrightarrow> N - Red_F_\\<G> N \\<Turnstile>\\<G> {B}\\<close> using Red_F_Bot_F by simp\n  show \\<open>N \\<subseteq> N' \\<Longrightarrow> Red_F_\\<G> N \\<subseteq> Red_F_\\<G> N'\\<close> using Red_F_of_subset_F by simp\n  show \\<open>N \\<subseteq> N' \\<Longrightarrow> Red_Inf_\\<G> N \\<subseteq> Red_Inf_\\<G> N'\\<close> using Red_Inf_of_subset_F by simp\n  show \\<open>N' \\<subseteq> Red_F_\\<G> N \\<Longrightarrow> Red_F_\\<G> N \\<subseteq> Red_F_\\<G> (N - N')\\<close> using Red_F_of_Red_F_subset_F by simp\n  show \\<open>N' \\<subseteq> Red_F_\\<G> N \\<Longrightarrow> Red_Inf_\\<G> N \\<subseteq> Red_Inf_\\<G> (N - N')\\<close> using Red_Inf_of_Red_F_subset_F by simp\n  show \\<open>\\<iota> \\<in> Inf_F \\<Longrightarrow> concl_of \\<iota> \\<in> N \\<Longrightarrow> \\<iota> \\<in> Red_Inf_\\<G> N\\<close> using Red_Inf_of_Inf_to_N_F by simp\nqed\n\nlemma lifted_calc_is_calc: \"calculus_with_red_crit Bot_F Inf_F entails_\\<G> Red_Inf_\\<G> Red_F_\\<G>\"\n  using lifted_calculus_with_red_crit.calculus_with_red_crit_axioms .\n\nlemma grounded_inf_in_ground_inf: \"\\<iota> \\<in> Inf_F \\<Longrightarrow> \\<G>_Inf \\<iota> \\<noteq> None \\<Longrightarrow> the (\\<G>_Inf \\<iota>) \\<subseteq> Inf_G\"\n  using inf_map Ground.Red_Inf_to_Inf by blast\n\n(* lem:sat-wrt-finf *)\nlemma sat_imp_ground_sat: \"lifted_calculus_with_red_crit.saturated N \\<Longrightarrow> Ground.Inf_from (\\<G>_set N) \\<subseteq>\n  ({\\<iota>. \\<exists>\\<iota>'\\<in> Non_ground.Inf_from N. \\<G>_Inf \\<iota>' \\<noteq> None \\<and> \\<iota> \\<in> the (\\<G>_Inf \\<iota>')} \\<union> Red_Inf_G (\\<G>_set N)) \\<Longrightarrow>\n  Ground.saturated (\\<G>_set N)\"\nproof -\n  fix N\n  assume\n    sat_n: \"lifted_calculus_with_red_crit.saturated N\" and\n    inf_grounded_in: \"Ground.Inf_from (\\<G>_set N) \\<subseteq>\n    ({\\<iota>. \\<exists>\\<iota>'\\<in> Non_ground.Inf_from N. \\<G>_Inf \\<iota>' \\<noteq> None \\<and> \\<iota> \\<in> the (\\<G>_Inf \\<iota>')} \\<union> Red_Inf_G (\\<G>_set N))\"\n  show \"Ground.saturated (\\<G>_set N)\" unfolding Ground.saturated_def\n  proof\n    fix \\<iota>\n    assume i_in: \"\\<iota> \\<in> Ground.Inf_from (\\<G>_set N)\"\n    {\n      assume \"\\<iota> \\<in> {\\<iota>. \\<exists>\\<iota>'\\<in> Non_ground.Inf_from N. \\<G>_Inf \\<iota>' \\<noteq> None \\<and> \\<iota> \\<in> the (\\<G>_Inf \\<iota>')}\"\n      then obtain \\<iota>' where \"\\<iota>'\\<in> Non_ground.Inf_from N\" \"\\<G>_Inf \\<iota>' \\<noteq> None\" \"\\<iota> \\<in> the (\\<G>_Inf \\<iota>')\" by blast\n      then have \"\\<iota> \\<in> Red_Inf_G (\\<G>_set N)\"\n        using Red_Inf_\\<G>_def sat_n unfolding lifted_calculus_with_red_crit.saturated_def by auto\n    }\n    then show \"\\<iota> \\<in> Red_Inf_G (\\<G>_set N)\" using inf_grounded_in i_in by blast\n  qed\nqed\n\n(* thm:finf-complete *)\ntheorem stat_ref_comp_to_non_ground:\n  assumes\n    stat_ref_G: \"static_refutational_complete_calculus Bot_G Inf_G entails_G Red_Inf_G Red_F_G\" and\n    sat_n_imp: \"\\<And>N. (lifted_calculus_with_red_crit.saturated N \\<Longrightarrow> Ground.Inf_from (\\<G>_set N) \\<subseteq>\n    ({\\<iota>. \\<exists>\\<iota>'\\<in> Non_ground.Inf_from N. \\<G>_Inf \\<iota>' \\<noteq> None \\<and> \\<iota> \\<in> the (\\<G>_Inf \\<iota>')} \\<union> Red_Inf_G (\\<G>_set N)))\"\n  shows\n    \"static_refutational_complete_calculus Bot_F Inf_F entails_\\<G> Red_Inf_\\<G> Red_F_\\<G>\"\nproof\n  fix B N\n  assume\n    b_in: \"B \\<in> Bot_F\" and\n    sat_n: \"lifted_calculus_with_red_crit.saturated N\" and\n    n_entails_bot: \"N \\<Turnstile>\\<G> {B}\"\n  have ground_n_entails: \"\\<G>_set N \\<Turnstile>G \\<G>_F B\"\n    using n_entails_bot unfolding entails_\\<G>_def by simp\n  then obtain BG where bg_in1: \"BG \\<in> \\<G>_F B\"\n    using Bot_map_not_empty[OF b_in] by blast\n  then have bg_in: \"BG \\<in> Bot_G\"\n    using Bot_map[OF b_in] by blast\n  have ground_n_entails_bot: \"\\<G>_set N \\<Turnstile>G {BG}\"\n    using ground_n_entails bg_in1 Ground.entail_set_all_formulas by blast\n  have \"Ground.Inf_from (\\<G>_set N) \\<subseteq>\n    ({\\<iota>. \\<exists>\\<iota>'\\<in> Non_ground.Inf_from N. \\<G>_Inf \\<iota>' \\<noteq> None \\<and> \\<iota> \\<in> the (\\<G>_Inf \\<iota>')} \\<union> Red_Inf_G (\\<G>_set N))\"\n    using sat_n_imp[OF sat_n] .\n  have \"Ground.saturated (\\<G>_set N)\"\n    using sat_imp_ground_sat[OF sat_n sat_n_imp[OF sat_n]] .\n  then have \"\\<exists>BG'\\<in>Bot_G. BG' \\<in> (\\<G>_set N)\"\n    using stat_ref_G Ground.calculus_with_red_crit_axioms bg_in ground_n_entails_bot\n    unfolding static_refutational_complete_calculus_def static_refutational_complete_calculus_axioms_def\n    by blast\n  then show \"\\<exists>B'\\<in> Bot_F. B' \\<in> N\"\n    using bg_in Bot_cond Bot_map_not_empty Bot_cond by blast\nqed\n\nend\n\nabbreviation Empty_Order where\n  \"Empty_Order C1 C2 \\<equiv> False\"\n\nlemma any_to_empty_order_lifting:\n  \"lifting_with_wf_ordering_family Bot_F Inf_F Bot_G entails_G Inf_G Red_Inf_G Red_F_G \\<G>_F\n    \\<G>_Inf Prec_F_g \\<Longrightarrow> lifting_with_wf_ordering_family Bot_F Inf_F Bot_G entails_G Inf_G Red_Inf_G\n    Red_F_G \\<G>_F \\<G>_Inf (\\<lambda>g. Empty_Order)\"\nproof -\n  fix Bot_F Inf_F Bot_G entails_G Inf_G Red_Inf_G Red_F_G \\<G>_F \\<G>_Inf Prec_F_g\n  assume lift: \"lifting_with_wf_ordering_family Bot_F Inf_F Bot_G entails_G Inf_G Red_Inf_G\n    Red_F_G \\<G>_F \\<G>_Inf Prec_F_g\"\n  then interpret lift_g:\n    lifting_with_wf_ordering_family Bot_F Inf_F Bot_G entails_G Inf_G Red_Inf_G Red_F_G \\<G>_F\n      \\<G>_Inf Prec_F_g\n    by auto\n  have empty_wf: \"minimal_element ((\\<lambda>g. Empty_Order) g) UNIV\"\n    by (simp add: lift_g.all_wf minimal_element.intro po_on_def transp_on_def wfp_on_def\n      wfp_on_imp_irreflp_on)\n  then show \"lifting_with_wf_ordering_family Bot_F Inf_F Bot_G entails_G Inf_G Red_Inf_G Red_F_G\n    \\<G>_F \\<G>_Inf (\\<lambda>g. Empty_Order)\"\n    by (simp add: empty_wf lift_g.standard_lifting_axioms\n      lifting_with_wf_ordering_family_axioms.intro lifting_with_wf_ordering_family_def)\nqed\n\nlocale lifting_equivalence_with_empty_order =\n  any_order_lifting: lifting_with_wf_ordering_family Bot_F Inf_F Bot_G entails_G Inf_G Red_Inf_G\n    Red_F_G \\<G>_F \\<G>_Inf Prec_F_g +\n  empty_order_lifting: lifting_with_wf_ordering_family Bot_F Inf_F Bot_G entails_G Inf_G Red_Inf_G\n    Red_F_G \\<G>_F \\<G>_Inf \"\\<lambda>g. Empty_Order\"\n  for\n    \\<G>_F :: \\<open>'f \\<Rightarrow> 'g set\\<close> and\n    \\<G>_Inf :: \\<open>'f inference \\<Rightarrow> 'g inference set option\\<close> and\n    Bot_F :: \\<open>'f set\\<close> and\n    Inf_F :: \\<open>'f inference set\\<close> and\n    Bot_G :: \\<open>'g set\\<close> and\n    Inf_G :: \\<open>'g inference set\\<close> and\n    entails_G :: \\<open>'g set \\<Rightarrow> 'g set \\<Rightarrow> bool\\<close> (infix \"\\<Turnstile>G\" 50) and\n    Red_Inf_G :: \\<open>'g set \\<Rightarrow> 'g inference set\\<close> and\n    Red_F_G :: \\<open>'g set \\<Rightarrow> 'g set\\<close> and\n    Prec_F_g :: \\<open>'g \\<Rightarrow> 'f \\<Rightarrow> 'f \\<Rightarrow> bool\\<close>\n\nsublocale lifting_with_wf_ordering_family \\<subseteq> lifting_equivalence_with_empty_order\nproof\n  show \"po_on Empty_Order UNIV\"\n    unfolding po_on_def by (simp add: transp_onI wfp_on_imp_irreflp_on)\n  show \"wfp_on Empty_Order UNIV\"\n    unfolding wfp_on_def by simp\nqed\n\ncontext lifting_equivalence_with_empty_order\nbegin\n\n(* lem:saturation-indep-of-sqsubset *)\nlemma saturated_empty_order_equiv_saturated:\n  \"any_order_lifting.lifted_calculus_with_red_crit.saturated N =\n    empty_order_lifting.lifted_calculus_with_red_crit.saturated N\" by standard\n\n(* lem:static-ref-compl-indep-of-sqsubset *)\nlemma static_empty_order_equiv_static:\n  \"static_refutational_complete_calculus Bot_F Inf_F\n    any_order_lifting.entails_\\<G> empty_order_lifting.Red_Inf_\\<G> empty_order_lifting.Red_F_\\<G> =\n    static_refutational_complete_calculus Bot_F Inf_F any_order_lifting.entails_\\<G>\n      any_order_lifting.Red_Inf_\\<G> any_order_lifting.Red_F_\\<G>\"\n  unfolding static_refutational_complete_calculus_def\n  by (rule iffI) (standard,(standard)[],simp)+\n\n(* thm:FRedsqsubset-is-dyn-ref-compl *)\ntheorem static_to_dynamic:\n  \"static_refutational_complete_calculus Bot_F Inf_F\n    any_order_lifting.entails_\\<G> empty_order_lifting.Red_Inf_\\<G> empty_order_lifting.Red_F_\\<G> =\n    dynamic_refutational_complete_calculus Bot_F Inf_F\n    any_order_lifting.entails_\\<G> any_order_lifting.Red_Inf_\\<G> any_order_lifting.Red_F_\\<G> \"\n  (is \"?static=?dynamic\")\nproof\n  assume ?static\n  then have static_general:\n    \"static_refutational_complete_calculus Bot_F Inf_F any_order_lifting.entails_\\<G>\n      any_order_lifting.Red_Inf_\\<G> any_order_lifting.Red_F_\\<G>\" (is \"?static_gen\")\n    using static_empty_order_equiv_static by simp\n  interpret static_refutational_complete_calculus Bot_F Inf_F any_order_lifting.entails_\\<G>\n    any_order_lifting.Red_Inf_\\<G> any_order_lifting.Red_F_\\<G>\n    using static_general .\n  show \"?dynamic\" by standard\nnext\n  assume dynamic_gen: ?dynamic\n  interpret dynamic_refutational_complete_calculus Bot_F Inf_F any_order_lifting.entails_\\<G>\n    any_order_lifting.Red_Inf_\\<G> any_order_lifting.Red_F_\\<G>\n    using dynamic_gen .\n  have \"static_refutational_complete_calculus Bot_F Inf_F any_order_lifting.entails_\\<G>\n    any_order_lifting.Red_Inf_\\<G> any_order_lifting.Red_F_\\<G>\"\n    by standard\n  then show \"?static\" using static_empty_order_equiv_static by simp\nqed\n\nend\n\nsubsection \\<open>Lifting with a Family of Redundancy Criteria\\<close>\n\nlocale standard_lifting_with_red_crit_family = Non_ground: inference_system Inf_F\n  + Ground_family: calculus_with_red_crit_family Bot_G Inf_G Q entails_q Red_Inf_q Red_F_q\n  for\n    Inf_F :: \"'f inference set\" and\n    Bot_G :: \"'g set\" and\n    Inf_G :: \\<open>'g inference set\\<close> and\n    Q :: \"'q itself\" and\n    entails_q :: \"'q \\<Rightarrow> ('g set \\<Rightarrow> 'g set \\<Rightarrow> bool)\" and\n    Red_Inf_q :: \"'q \\<Rightarrow> ('g set \\<Rightarrow> 'g inference set)\" and\n    Red_F_q :: \"'q \\<Rightarrow> ('g set \\<Rightarrow> 'g set)\"\n  + fixes\n    Bot_F :: \"'f set\" and\n    \\<G>_F_q :: \"'q \\<Rightarrow> 'f \\<Rightarrow> 'g set\" and\n    \\<G>_Inf_q :: \"'q \\<Rightarrow> 'f inference \\<Rightarrow> 'g inference set option\" and\n    Prec_F_g :: \"'g \\<Rightarrow> 'f \\<Rightarrow> 'f \\<Rightarrow> bool\"\n  assumes\n    standard_lifting_family: \"lifting_with_wf_ordering_family Bot_F Inf_F Bot_G (entails_q q)\n      Inf_G (Red_Inf_q q) (Red_F_q q) (\\<G>_F_q q) (\\<G>_Inf_q q) Prec_F_g\"\nbegin\n\ndefinition \\<G>_set_q :: \"'q \\<Rightarrow> 'f set \\<Rightarrow> 'g set\" where\n  \"\\<G>_set_q q N \\<equiv> \\<Union> (\\<G>_F_q q ` N)\"\n\ndefinition Red_Inf_\\<G>_q :: \"'q \\<Rightarrow> 'f set \\<Rightarrow> 'f inference set\" where\n  \"Red_Inf_\\<G>_q q N = {\\<iota> \\<in> Inf_F. (\\<G>_Inf_q q \\<iota> \\<noteq> None \\<and> the (\\<G>_Inf_q q \\<iota>) \\<subseteq> Red_Inf_q q (\\<G>_set_q q N))\n  \\<or> (\\<G>_Inf_q q \\<iota> = None \\<and> \\<G>_F_q q (concl_of \\<iota>) \\<subseteq> (\\<G>_set_q q N \\<union> Red_F_q q (\\<G>_set_q q N)))}\"\n\ndefinition Red_Inf_\\<G>_Q :: \"'f set \\<Rightarrow> 'f inference set\" where\n  \"Red_Inf_\\<G>_Q N = \\<Inter> {X N |X. X \\<in> (Red_Inf_\\<G>_q ` UNIV)}\"\n\ndefinition Red_F_\\<G>_empty_q :: \"'q \\<Rightarrow> 'f set \\<Rightarrow> 'f set\" where\n  \"Red_F_\\<G>_empty_q q N = {C. \\<forall>D \\<in> \\<G>_F_q q C. D \\<in> Red_F_q q (\\<G>_set_q q N) \\<or>\n    (\\<exists>E \\<in> N. Empty_Order E C \\<and> D \\<in> \\<G>_F_q q E)}\"\n\ndefinition Red_F_\\<G>_empty :: \"'f set \\<Rightarrow> 'f set\" where\n  \"Red_F_\\<G>_empty N = \\<Inter> {X N |X. X \\<in> (Red_F_\\<G>_empty_q ` UNIV)}\"\n\ndefinition Red_F_\\<G>_q_g :: \"'q \\<Rightarrow> 'f set \\<Rightarrow> 'f set\" where\n  \"Red_F_\\<G>_q_g q N = {C. \\<forall>D \\<in> \\<G>_F_q q C. D \\<in> Red_F_q q (\\<G>_set_q q N) \\<or> (\\<exists>E \\<in> N. Prec_F_g D E C \\<and> D \\<in> \\<G>_F_q q E)}\"\n\ndefinition Red_F_\\<G>_g :: \"'f set \\<Rightarrow> 'f set\" where\n  \"Red_F_\\<G>_g N = \\<Inter> {X N |X. X \\<in> (Red_F_\\<G>_q_g ` UNIV)}\"\n\ndefinition entails_\\<G>_q :: \"'q \\<Rightarrow> 'f set \\<Rightarrow> 'f set \\<Rightarrow> bool\" where\n  \"entails_\\<G>_q q N1 N2 \\<equiv> entails_q q (\\<G>_set_q q N1) (\\<G>_set_q q N2)\"\n\ndefinition entails_\\<G>_Q :: \"'f set \\<Rightarrow> 'f set \\<Rightarrow> bool\" (infix \"\\<Turnstile>\\<inter>\" 50) where\n  \"entails_\\<G>_Q N1 N2 \\<equiv> \\<forall>q. entails_\\<G>_q q N1 N2\"\n\nlemma red_crit_lifting_family:\n  \"calculus_with_red_crit Bot_F Inf_F (entails_\\<G>_q q) (Red_Inf_\\<G>_q q) (Red_F_\\<G>_q_g q)\"\nproof -\n  fix q\n  interpret wf_lift:\n    lifting_with_wf_ordering_family Bot_F Inf_F Bot_G \"entails_q q\" Inf_G \"Red_Inf_q q\" \"Red_F_q q\"\n      \"\\<G>_F_q q\" \"\\<G>_Inf_q q\" Prec_F_g\n    using standard_lifting_family .\n  have \"entails_\\<G>_q q = wf_lift.entails_\\<G>\"\n    unfolding entails_\\<G>_q_def wf_lift.entails_\\<G>_def \\<G>_set_q_def by blast\n  moreover have \"Red_Inf_\\<G>_q q = wf_lift.Red_Inf_\\<G>\"\n    unfolding Red_Inf_\\<G>_q_def \\<G>_set_q_def wf_lift.Red_Inf_\\<G>_def by blast\n  moreover have \"Red_F_\\<G>_q_g q = wf_lift.Red_F_\\<G>\"\n    unfolding Red_F_\\<G>_q_g_def \\<G>_set_q_def wf_lift.Red_F_\\<G>_def by blast\n  ultimately show \"calculus_with_red_crit Bot_F Inf_F (entails_\\<G>_q q) (Red_Inf_\\<G>_q q) (Red_F_\\<G>_q_g q)\"\n    using wf_lift.lifted_calculus_with_red_crit.calculus_with_red_crit_axioms by simp\nqed\n\nlemma red_crit_lifting_family_empty_ord:\n  \"calculus_with_red_crit Bot_F Inf_F (entails_\\<G>_q q) (Red_Inf_\\<G>_q q) (Red_F_\\<G>_empty_q q)\"\nproof -\n  fix q\n  interpret wf_lift:\n    lifting_with_wf_ordering_family Bot_F Inf_F Bot_G \"entails_q q\" Inf_G \"Red_Inf_q q\" \"Red_F_q q\"\n      \"\\<G>_F_q q\" \"\\<G>_Inf_q q\" Prec_F_g\n    using standard_lifting_family .\n  have \"entails_\\<G>_q q = wf_lift.entails_\\<G>\"\n    unfolding entails_\\<G>_q_def wf_lift.entails_\\<G>_def \\<G>_set_q_def by blast\n  moreover have \"Red_Inf_\\<G>_q q = wf_lift.Red_Inf_\\<G>\"\n    unfolding Red_Inf_\\<G>_q_def \\<G>_set_q_def wf_lift.Red_Inf_\\<G>_def by blast\n  moreover have \"Red_F_\\<G>_empty_q q = wf_lift.empty_order_lifting.Red_F_\\<G>\"\n    unfolding Red_F_\\<G>_empty_q_def \\<G>_set_q_def wf_lift.empty_order_lifting.Red_F_\\<G>_def by blast\n  ultimately show \"calculus_with_red_crit Bot_F Inf_F (entails_\\<G>_q q) (Red_Inf_\\<G>_q q) (Red_F_\\<G>_empty_q q)\"\n    using wf_lift.empty_order_lifting.lifted_calculus_with_red_crit.calculus_with_red_crit_axioms\n    by simp\nqed\n\nlemma cons_rel_fam_Q_lem: \\<open>consequence_relation_family Bot_F entails_\\<G>_q\\<close>\nproof\n  show \"Bot_F \\<noteq> {}\"\n    using standard_lifting_family\n    by (meson ex_in_conv lifting_with_wf_ordering_family.axioms(1) standard_lifting.Bot_F_not_empty)\nnext\n  fix qi\n  show \"Bot_F \\<noteq> {}\"\n    using standard_lifting_family\n    by (meson ex_in_conv lifting_with_wf_ordering_family.axioms(1) standard_lifting.Bot_F_not_empty)\nnext\n  fix qi B N1\n  assume\n    B_in: \"B \\<in> Bot_F\"\n  interpret lift: lifting_with_wf_ordering_family Bot_F Inf_F Bot_G \"entails_q qi\" Inf_G \"Red_Inf_q qi\"\n    \"Red_F_q qi\" \"\\<G>_F_q qi\" \"\\<G>_Inf_q qi\" Prec_F_g\n    by (rule standard_lifting_family)\n  have \"(entails_\\<G>_q qi) = lift.entails_\\<G>\"\n    unfolding entails_\\<G>_q_def lift.entails_\\<G>_def \\<G>_set_q_def by simp\n  then show \"entails_\\<G>_q qi {B} N1\"\n    using B_in lift.lifted_consequence_relation.bot_implies_all by auto\nnext\n  fix qi and N2 N1::\"'f set\"\n  assume\n    N_incl: \"N2 \\<subseteq> N1\"\n  interpret lift: lifting_with_wf_ordering_family Bot_F Inf_F Bot_G \"entails_q qi\" Inf_G \"Red_Inf_q qi\"\n   \"Red_F_q qi\" \"\\<G>_F_q qi\" \"\\<G>_Inf_q qi\" Prec_F_g\n    by (rule standard_lifting_family)\n  have \"(entails_\\<G>_q qi) = lift.entails_\\<G>\"\n    unfolding entails_\\<G>_q_def lift.entails_\\<G>_def \\<G>_set_q_def by simp\n  then show \"entails_\\<G>_q qi N1 N2\"\n    using N_incl by (simp add: lift.lifted_consequence_relation.subset_entailed)\nnext\n  fix qi N1 N2\n  assume\n    all_C: \"\\<forall>C\\<in> N2. entails_\\<G>_q qi N1 {C}\"\n  interpret lift: lifting_with_wf_ordering_family Bot_F Inf_F Bot_G \"entails_q qi\" Inf_G \"Red_Inf_q qi\"\n    \"Red_F_q qi\" \"\\<G>_F_q qi\" \"\\<G>_Inf_q qi\" Prec_F_g\n    by (rule standard_lifting_family)\n  have \"(entails_\\<G>_q qi) = lift.entails_\\<G>\"\n    unfolding entails_\\<G>_q_def lift.entails_\\<G>_def \\<G>_set_q_def by simp\n  then show \"entails_\\<G>_q qi N1 N2\"\n    using all_C lift.lifted_consequence_relation.all_formulas_entailed by presburger\nnext\n  fix qi N1 N2 N3\n  assume\n    entails12: \"entails_\\<G>_q qi N1 N2\" and\n    entails23: \"entails_\\<G>_q qi N2 N3\"\n  interpret lift: lifting_with_wf_ordering_family Bot_F Inf_F Bot_G \"entails_q qi\" Inf_G \"Red_Inf_q qi\"\n    \"Red_F_q qi\" \"\\<G>_F_q qi\" \"\\<G>_Inf_q qi\" Prec_F_g\n    by (rule standard_lifting_family)\n  have \"(entails_\\<G>_q qi) = lift.entails_\\<G>\"\n    unfolding entails_\\<G>_q_def lift.entails_\\<G>_def \\<G>_set_q_def by simp\n  then show \"entails_\\<G>_q qi N1 N3\"\n    using entails12 entails23 lift.lifted_consequence_relation.entails_trans by presburger\nqed\n\ninterpretation cons_rel_Q: consequence_relation Bot_F entails_\\<G>_Q\nproof -\n  interpret cons_rel_fam: consequence_relation_family Bot_F Q entails_\\<G>_q\n    by (rule cons_rel_fam_Q_lem)\n  have \"consequence_relation_family.entails_Q entails_\\<G>_q = entails_\\<G>_Q\"\n    unfolding entails_\\<G>_Q_def cons_rel_fam.entails_Q_def by (simp add: entails_\\<G>_q_def)\n  then show \"consequence_relation Bot_F entails_\\<G>_Q\"\n  using consequence_relation_family.intersect_cons_rel_family[OF cons_rel_fam_Q_lem] by simp\nqed\n\nsublocale lifted_calc_w_red_crit_family:\n  calculus_with_red_crit_family Bot_F Inf_F Q entails_\\<G>_q Red_Inf_\\<G>_q Red_F_\\<G>_q_g\n  using cons_rel_fam_Q_lem red_crit_lifting_family\n  by (simp add: calculus_with_red_crit_family.intro calculus_with_red_crit_family_axioms_def)\n\nlemma lifted_calc_family_is_calc: \"calculus_with_red_crit Bot_F Inf_F entails_\\<G>_Q Red_Inf_\\<G>_Q Red_F_\\<G>_g\"\nproof -\n  have \"lifted_calc_w_red_crit_family.entails_Q = entails_\\<G>_Q\"\n    unfolding entails_\\<G>_Q_def lifted_calc_w_red_crit_family.entails_Q_def by simp\n  moreover have \"lifted_calc_w_red_crit_family.Red_Inf_Q = Red_Inf_\\<G>_Q\"\n    unfolding Red_Inf_\\<G>_Q_def lifted_calc_w_red_crit_family.Red_Inf_Q_def by simp\n  moreover have \"lifted_calc_w_red_crit_family.Red_F_Q = Red_F_\\<G>_g\"\n    unfolding Red_F_\\<G>_g_def lifted_calc_w_red_crit_family.Red_F_Q_def by simp\n  ultimately show \"calculus_with_red_crit Bot_F Inf_F entails_\\<G>_Q Red_Inf_\\<G>_Q Red_F_\\<G>_g\"\n  using lifted_calc_w_red_crit_family.inter_red_crit by simp\nqed\n\nsublocale empty_ord_lifted_calc_w_red_crit_family:\n  calculus_with_red_crit_family Bot_F Inf_F Q entails_\\<G>_q Red_Inf_\\<G>_q Red_F_\\<G>_empty_q\n  using cons_rel_fam_Q_lem red_crit_lifting_family_empty_ord\n  by (simp add: calculus_with_red_crit_family.intro calculus_with_red_crit_family_axioms_def)\n\n\n\n(* thm:intersect-finf-complete *)\ntheorem stat_ref_comp_to_non_ground_fam_inter:\n  assumes\n    stat_ref_G: \"\\<And>q. static_refutational_complete_calculus Bot_G Inf_G (entails_q q) (Red_Inf_q q) (Red_F_q q)\" and\n      sat_n_imp: \"\\<And>N. (empty_ord_lifted_calc_w_red_crit_family.inter_red_crit_calculus.saturated N \\<Longrightarrow>\n        \\<exists>q. Ground_family.Inf_from (\\<G>_set_q q N) \\<subseteq>\n        ({\\<iota>. \\<exists>\\<iota>'\\<in> Non_ground.Inf_from N. \\<G>_Inf_q q \\<iota>' \\<noteq> None \\<and> \\<iota> \\<in> the (\\<G>_Inf_q q \\<iota>')} \\<union> Red_Inf_q q (\\<G>_set_q q N)))\"\n  shows\n    \"static_refutational_complete_calculus Bot_F Inf_F entails_\\<G>_Q Red_Inf_\\<G>_Q Red_F_\\<G>_empty\"\n    using inter_calc\n    unfolding static_refutational_complete_calculus_def static_refutational_complete_calculus_axioms_def\nproof (standard, clarify)\n  fix B N\n  assume\n    b_in: \"B \\<in> Bot_F\" and\n    sat_n: \"calculus_with_red_crit.saturated Inf_F Red_Inf_\\<G>_Q N\" and\n    entails_bot: \"N \\<Turnstile>\\<inter> {B}\"\n  interpret calculus_with_red_crit Bot_F Inf_F entails_\\<G>_Q Red_Inf_\\<G>_Q Red_F_\\<G>_empty\n    using inter_calc by blast\n  have \"empty_ord_lifted_calc_w_red_crit_family.Red_Inf_Q = Red_Inf_\\<G>_Q\"\n    unfolding Red_Inf_\\<G>_Q_def lifted_calc_w_red_crit_family.Red_Inf_Q_def by simp\n  then have empty_ord_sat_n: \"empty_ord_lifted_calc_w_red_crit_family.inter_red_crit_calculus.saturated N\"\n    using sat_n\n    unfolding saturated_def empty_ord_lifted_calc_w_red_crit_family.inter_red_crit_calculus.saturated_def\n    by simp\n  then obtain q where inf_subs: \"Ground_family.Inf_from (\\<G>_set_q q N) \\<subseteq>\n    ({\\<iota>. \\<exists>\\<iota>'\\<in> Non_ground.Inf_from N. \\<G>_Inf_q q \\<iota>' \\<noteq> None \\<and> \\<iota> \\<in> the (\\<G>_Inf_q q \\<iota>')} \\<union> Red_Inf_q q (\\<G>_set_q q N))\"\n    using sat_n_imp[of N] by blast\n  interpret q_calc: calculus_with_red_crit Bot_F Inf_F \"entails_\\<G>_q q\" \"Red_Inf_\\<G>_q q\" \"Red_F_\\<G>_q_g q\"\n    using lifted_calc_w_red_crit_family.all_red_crit[of q] .\n  have n_q_sat: \"q_calc.saturated N\" using lifted_calc_w_red_crit_family.sat_int_to_sat_q empty_ord_sat_n by simp\n  interpret lifted_q_calc: lifting_with_wf_ordering_family Bot_F Inf_F Bot_G \"entails_q q\" Inf_G \"Red_Inf_q q\" \"Red_F_q q\" \"\\<G>_F_q q\" \"\\<G>_Inf_q q\"\n    by (simp add: standard_lifting_family)\n  have \"lifted_q_calc.empty_order_lifting.lifted_calculus_with_red_crit.saturated N\"\n    using n_q_sat unfolding Red_Inf_\\<G>_q_def \\<G>_set_q_def lifted_q_calc.empty_order_lifting.Red_Inf_\\<G>_def\n      lifted_q_calc.lifted_calculus_with_red_crit.saturated_def q_calc.saturated_def by auto\n  then have ground_sat_n: \"lifted_q_calc.Ground.saturated (\\<G>_set_q q N)\"\n    using lifted_q_calc.sat_imp_ground_sat[of N] inf_subs unfolding \\<G>_set_q_def by blast\n  have \"entails_\\<G>_q q N {B}\" using entails_bot unfolding entails_\\<G>_Q_def by simp\n  then have ground_n_entails_bot: \"entails_q q (\\<G>_set_q q N) (\\<G>_set_q q {B})\" unfolding entails_\\<G>_q_def .\n  interpret static_refutational_complete_calculus Bot_G Inf_G \"entails_q q\" \"Red_Inf_q q\" \"Red_F_q q\"\n    using stat_ref_G[of q] .\n  obtain BG where bg_in: \"BG \\<in> \\<G>_F_q q B\"\n    using lifted_q_calc.Bot_map_not_empty[OF b_in] by blast\n  then have \"BG \\<in> Bot_G\" using lifted_q_calc.Bot_map[OF b_in] by blast\n  then have \"\\<exists>BG'\\<in>Bot_G. BG' \\<in> \\<G>_set_q q N\"\n    using ground_sat_n ground_n_entails_bot static_refutational_complete[of BG, OF _ ground_sat_n]\n      bg_in lifted_q_calc.Ground.entail_set_all_formulas[of \"\\<G>_set_q q N\" \"\\<G>_set_q q {B}\"] unfolding \\<G>_set_q_def\n    by simp\n  then show \"\\<exists>B'\\<in> Bot_F. B' \\<in> N\" using lifted_q_calc.Bot_cond unfolding \\<G>_set_q_def by blast\nqed\n\n(* lem:intersect-saturation-indep-of-sqsubset *)\nlemma sat_eq_sat_empty_order: \"lifted_calc_w_red_crit_family.inter_red_crit_calculus.saturated N =\n  empty_ord_lifted_calc_w_red_crit_family.inter_red_crit_calculus.saturated N \"\n  by simp\n\n(* lem:intersect-static-ref-compl-indep-of-sqsubset *)\nlemma static_empty_ord_inter_equiv_static_inter:\n  \"static_refutational_complete_calculus Bot_F Inf_F lifted_calc_w_red_crit_family.entails_Q\n    lifted_calc_w_red_crit_family.Red_Inf_Q lifted_calc_w_red_crit_family.Red_F_Q =\n  static_refutational_complete_calculus Bot_F Inf_F lifted_calc_w_red_crit_family.entails_Q\n    empty_ord_lifted_calc_w_red_crit_family.Red_Inf_Q empty_ord_lifted_calc_w_red_crit_family.Red_F_Q\"\n  unfolding static_refutational_complete_calculus_def\n  by (simp add: empty_ord_lifted_calc_w_red_crit_family.inter_red_crit_calculus.calculus_with_red_crit_axioms\n    lifted_calc_w_red_crit_family.inter_red_crit_calculus.calculus_with_red_crit_axioms)\n\n(* thm:intersect-static-ref-compl-is-dyn-ref-compl-with-order *)\ntheorem stat_eq_dyn_ref_comp_fam_inter: \"static_refutational_complete_calculus Bot_F Inf_F lifted_calc_w_red_crit_family.entails_Q\n    empty_ord_lifted_calc_w_red_crit_family.Red_Inf_Q empty_ord_lifted_calc_w_red_crit_family.Red_F_Q =\n  dynamic_refutational_complete_calculus Bot_F Inf_F lifted_calc_w_red_crit_family.entails_Q\n    lifted_calc_w_red_crit_family.Red_Inf_Q lifted_calc_w_red_crit_family.Red_F_Q\"  (is \"?static=?dynamic\")\nproof\n  assume ?static\n  then have static_general: \"static_refutational_complete_calculus Bot_F Inf_F\n    lifted_calc_w_red_crit_family.entails_Q lifted_calc_w_red_crit_family.Red_Inf_Q\n    lifted_calc_w_red_crit_family.Red_F_Q\" (is \"?static_gen\")\n    using static_empty_ord_inter_equiv_static_inter\n    by simp\n  interpret static_refutational_complete_calculus Bot_F Inf_F lifted_calc_w_red_crit_family.entails_Q\n    lifted_calc_w_red_crit_family.Red_Inf_Q lifted_calc_w_red_crit_family.Red_F_Q\n    using static_general .\n  show \"?dynamic\" by standard\nnext\n  assume dynamic_gen: ?dynamic\n  interpret dynamic_refutational_complete_calculus Bot_F Inf_F lifted_calc_w_red_crit_family.entails_Q\n    lifted_calc_w_red_crit_family.Red_Inf_Q lifted_calc_w_red_crit_family.Red_F_Q\n    using dynamic_gen .\n  have \"static_refutational_complete_calculus Bot_F Inf_F lifted_calc_w_red_crit_family.entails_Q\n    lifted_calc_w_red_crit_family.Red_Inf_Q lifted_calc_w_red_crit_family.Red_F_Q\"\n    by standard\n  then show \"?static\" using static_empty_ord_inter_equiv_static_inter by simp\nqed\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Saturation_Framework/Lifting_to_Non_Ground_Calculi.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.2739521773133345}}
{"text": "(*<*)\n(*\n * Copyright 2015, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory CIMP_unbounded_buffer\nimports\n  \"../CIMP\"\n  \"HOL-Library.Prefix_Order\"\nbegin\n\nabbreviation (input)\n  Receive :: \"'location \\<Rightarrow> 'channel \\<Rightarrow> ('val \\<Rightarrow> 'state \\<Rightarrow> 'state)\n             \\<Rightarrow> (unit, 'location, 'channel \\<times> 'val, 'state) com\" (\"\\<lbrace>_\\<rbrace>/ _\\<triangleright>_\" [0,0,81] 81)\nwhere\n  \"\\<lbrace>l\\<rbrace> ch\\<triangleright>f \\<equiv> \\<lbrace>l\\<rbrace> Response (\\<lambda>q s. if fst q = ch then {(f (snd q) s, ())} else {})\"\n\nabbreviation (input)\n  Send :: \"'location \\<Rightarrow> 'channel \\<Rightarrow> ('state \\<Rightarrow> 'val) \\<times> ('state \\<Rightarrow> 'state)\n          \\<Rightarrow> (unit, 'location, 'channel \\<times> 'val, 'state) com\" (\"\\<lbrace>_\\<rbrace>/ _\\<triangleleft>_\" [0,0,81] 81)\nwhere\n  \"\\<lbrace>l\\<rbrace> ch\\<triangleleft>f \\<equiv> \\<lbrace>l\\<rbrace> Request (\\<lambda>s. (ch, fst f s)) (\\<lambda>ans s. {snd f s})\"\n\n(*>*)\nsection\\<open>Example: an unbounded buffer \\label{sec:unbounded_buffer}\\<close>\n\ntext\\<open>\n\nThis is more literally Kai Engelhardt's example from his notes titled\n\\emph{Proving an Asynchronous Message Passing Program Correct}, 2011.\n\n\\<close>\n\ndatatype ex_chname = \\<xi>12 | \\<xi>23\ntype_synonym ex_val = nat\ntype_synonym ex_ls = \"ex_val list\"\ntype_synonym ex_ch = \"ex_chname \\<times> ex_val\"\ndatatype ex_loc = c1 | r12 | r23 | s23 | s12\ndatatype ex_proc = p1 | p2 | p3\n\ntype_synonym ex_pgm = \"(unit, ex_loc, ex_ch, ex_ls) com\"\ntype_synonym ex_pred = \"(unit, ex_loc, ex_proc, ex_ch, ex_ls) state_pred\"\ntype_synonym ex_state = \"(unit, ex_loc, ex_proc, ex_ch, ex_ls) system_state\"\ntype_synonym ex_sys = \"(unit, ex_loc, ex_proc, ex_ch, ex_ls) system\"\ntype_synonym ex_history = \"(ex_ch \\<times> unit) list\"\n\ntext\\<open>\n\nThe local state for the producer process contains all values produced; consider that ghost state.\n\n\\<close>\n\nabbreviation (input) snoc :: \"'a \\<Rightarrow> 'a list \\<Rightarrow> 'a list\" where \"snoc x xs \\<equiv> xs @ [x]\"\n\nprimrec ex_coms :: \"ex_proc \\<Rightarrow> ex_pgm\" where\n  \"ex_coms p1 = LOOP DO \\<lbrace>c1\\<rbrace> LocalOp (\\<lambda>xs. {snoc x xs |x. True}) ;; \\<lbrace>s12\\<rbrace> \\<xi>12\\<triangleleft>(last, id) OD\"\n| \"ex_coms p2 = LOOP DO \\<lbrace>r12\\<rbrace> \\<xi>12\\<triangleright>snoc\n                      \\<oplus> \\<lbrace>c1\\<rbrace> IF (\\<lambda>s. length s > 0) THEN \\<lbrace>s23\\<rbrace> \\<xi>12\\<triangleleft>(hd, tl) FI\n                     OD\"\n| \"ex_coms p3 = LOOP DO \\<lbrace>r23\\<rbrace> \\<xi>23\\<triangleright>snoc OD\"\n\nabbreviation ex_init :: \"(ex_proc \\<Rightarrow> ex_ls) \\<Rightarrow> bool\" where\n  \"ex_init s \\<equiv> \\<forall>p. s p = []\"\n\nabbreviation sys :: ex_sys where\n  \"sys \\<equiv> \\<lparr>PGMs = ex_coms, INIT = ex_init, FAIR = \\<langle>True\\<rangle>\\<rparr>\" (* FIXME add fairness hypotheses *)\n\nabbreviation\n  filter_on_channel :: \"ex_chname \\<Rightarrow> ex_state \\<Rightarrow> ex_val list\" (\"\\<downharpoonright>_\" [100] 101)\nwhere\n  \"\\<downharpoonright>ch \\<equiv> map (snd \\<circ> fst) \\<circ> filter ((=) ch \\<circ> fst \\<circ> fst) \\<circ> HST\"\n\ndefinition I_pred :: ex_pred where\n  \"I_pred = pred_conjoin [\n       at p1 c1 \\<^bold>\\<longrightarrow> \\<downharpoonright>\\<xi>12 \\<^bold>= (\\<lambda>s. s\\<down> p1)\n     , at p1 s12 \\<^bold>\\<longrightarrow> (\\<lambda>s. length (s\\<down> p1) > 0 \\<and> butlast (s\\<down> p1) = (\\<downharpoonright>\\<xi>12) s)\n     , \\<downharpoonright>\\<xi>12 \\<^bold>\\<le> (\\<lambda>s. s\\<down> p1)\n     , \\<downharpoonright>\\<xi>12 \\<^bold>= \\<downharpoonright>\\<xi>23 \\<^bold>@ (\\<lambda>s. s\\<down> p2)\n     , at p2 s23 \\<^bold>\\<longrightarrow> (\\<lambda>s. length (s\\<down> p2) > 0)\n     , (\\<lambda>s. s\\<down> p3) \\<^bold>= \\<downharpoonright>\\<xi>23\n     ]\"\n\ntext\\<open>\n\nThe local state of @{const \"p3\"} is some prefix of the local state of\n@{const \"p1\"}.\n\n\\<close>\n\ndefinition Etern_pred :: ex_pred where\n  \"Etern_pred \\<equiv> \\<lambda>s. s\\<down> p3 \\<le> s\\<down> p1\"\n\nlemma correct_system:\n  assumes \"I_pred s\"\n  shows \"Etern_pred s\"\nusing assms unfolding Etern_pred_def I_pred_def less_eq_list_def prefix_def by clarsimp\n\nlemma p1_c1[simplified, intro]:\n  \"ex_coms, p1, lconst {s12} \\<turnstile> \\<lbrace>I_pred\\<rbrace> \\<lbrace>c1\\<rbrace> LocalOp (\\<lambda>xs. { snoc x xs |x. True })\"\napply (rule vcg.intros)\napply (clarsimp simp: I_pred_def atS_def)\ndone\n\nlemma p1_s12[simplified, intro]:\n  \"ex_coms, p1, lconst {c1} \\<turnstile> \\<lbrace>I_pred\\<rbrace> \\<lbrace>s12\\<rbrace> \\<xi>12\\<triangleleft>(last, id)\"\napply (rule vcg.intros)\napply (rename_tac p')\napply (case_tac p'; clarsimp)\napply (clarsimp simp: I_pred_def atS_def)\napply (metis Prefix_Order.prefix_snoc append.assoc append_butlast_last_id)\ndone\n\nlemma p2_s23[simplified, intro]:\n  \"ex_coms, p2, lconst {c1, r12} \\<turnstile> \\<lbrace>I_pred\\<rbrace> \\<lbrace>s23\\<rbrace> \\<xi>12\\<triangleleft>(hd, tl)\"\napply (rule vcg.intros)\napply (rename_tac p')\napply (case_tac p'; clarsimp)\ndone\n\nlemma p2_pi4[intro]:\n  \"ex_coms, p2, lcond {s23} {c1, r12} (\\<lambda>s. s \\<noteq> []) \\<turnstile> \\<lbrace>I_pred\\<rbrace> \\<lbrace>c1\\<rbrace> IF (\\<lambda>s. s \\<noteq> []) THEN c' FI\"\napply (rule vcg.intros)\napply (clarsimp simp: I_pred_def atS_def split: lcond_splits)\ndone\n\nlemma I: \"sys \\<Turnstile>\\<^bsub>pre\\<^esub> I_pred\"\napply (rule VCG)\n apply (clarsimp dest!: initial_stateD simp: I_pred_def atS_def)\napply (rename_tac p)\napply (case_tac p; auto)\ndone\n\nlemma I_valid: \"sys \\<Turnstile> \\<box>\\<lceil>I_pred\\<rceil>\"\nby (rule valid_prerun_lift[OF I])\n\n(*<*)\n\nend\n(*>*)\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/ConcurrentIMP/ex/CIMP_unbounded_buffer.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5156199157230156, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.2739021323302521}}
{"text": "(* \n   Title: Psi-calculi   \n   Author/Maintainer: Jesper Bengtson (jebe@itu.dk), 2012\n*)\ntheory Tau_Sim\n  imports Tau Sum\nbegin\n\nnominal_datatype 'a prefix =\n  pInput \"'a::fs_name\" \"name list\" 'a\n| pOutput 'a 'a                           \n| pTau                                    \n\ncontext tau\nbegin\n\nnominal_primrec bindPrefix :: \"'a prefix \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow> ('a, 'b, 'c) psi\"  (\"_\\<cdot>_\" [100, 100] 100)\nwhere\n  \"bindPrefix (pInput M xvec N) P = M\\<lparr>\\<lambda>*xvec N\\<rparr>.P\"\n| \"bindPrefix (pOutput M N) P = M\\<langle>N\\<rangle>.P\"\n| \"bindPrefix (pTau) P = \\<tau>.(P)\"\nby(rule TrueI)+\n\nlemma bindPrefixEqvt[eqvt]:\n  fixes p :: \"name prm\"\n  and   \\<alpha> :: \"'a prefix\"\n  and   P :: \"('a, 'b, 'c) psi\"\n\n  shows \"(p \\<bullet> (\\<alpha>\\<cdot>P)) = (p \\<bullet> \\<alpha>)\\<cdot>(p \\<bullet> P)\"\nby(nominal_induct \\<alpha> rule: prefix.strong_inducts) (auto simp add: eqvts)\n\nlemma prefixCases[consumes 1, case_names cInput cOutput cTau]:\n  fixes \\<Psi> :: 'b\n  and   \\<alpha>  :: \"'a prefix\"\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   \\<beta>  :: \"'a action\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<longmapsto>\\<beta> \\<prec> P'\"\n  and     rInput: \"\\<And>M xvec N K Tvec. \\<lbrakk>\\<Psi> \\<turnstile> M \\<leftrightarrow> K; set xvec \\<subseteq> supp N; length xvec = length Tvec; distinct xvec\\<rbrakk> \\<Longrightarrow> \n                                       Prop (pInput M xvec N) (K\\<lparr>N[xvec::=Tvec]\\<rparr>) (P[xvec::=Tvec])\"\n  and     rOutput: \"\\<And>M N K. \\<Psi> \\<turnstile> M \\<leftrightarrow> K \\<Longrightarrow> Prop (pOutput M N) (K\\<langle>N\\<rangle>) P\"\n  and     rTau: \"\\<Psi> \\<rhd> P \\<sim> P' \\<Longrightarrow> Prop (pTau) (\\<tau>) P'\"\n\n  shows \"Prop \\<alpha> \\<beta> P'\"\nusing \\<open>\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<longmapsto>\\<beta> \\<prec> P'\\<close>\nproof(nominal_induct rule: prefix.strong_induct)\n  case(pInput M xvec N)\n  from \\<open>\\<Psi> \\<rhd> (pInput M xvec N)\\<cdot>P \\<longmapsto>\\<beta> \\<prec> P'\\<close> have \"\\<Psi> \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.P \\<longmapsto>\\<beta> \\<prec> P'\" by simp\n  thus ?case by(auto elim: inputCases intro: rInput)\nnext\n  case(pOutput M N)\n  from \\<open>\\<Psi> \\<rhd> (pOutput M N)\\<cdot>P \\<longmapsto>\\<beta> \\<prec> P'\\<close> have \"\\<Psi> \\<rhd> M\\<langle>N\\<rangle>.P \\<longmapsto>\\<beta> \\<prec> P'\" by simp\n  thus ?case by(auto elim: outputCases intro: rOutput)\nnext\n  case pTau\n  from \\<open>\\<Psi> \\<rhd> (pTau)\\<cdot>P \\<longmapsto>\\<beta> \\<prec> P'\\<close> have \"\\<Psi> \\<rhd> \\<tau>.(P) \\<longmapsto>\\<beta> \\<prec> P'\" by simp\n  thus ?case\n    by(nominal_induct rule: action.strong_induct) (auto dest: tauActionE intro: rTau)\nqed  \n  \nlemma prefixTauCases[consumes 1, case_names cTau]:\n  fixes \\<alpha>  :: \"'a prefix\"\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<longmapsto>\\<tau> \\<prec> P'\"\n  and     rTau: \"\\<Psi> \\<rhd> P \\<sim> P' \\<Longrightarrow> Prop (pTau) P'\"\n\n  shows \"Prop \\<alpha> P'\"\nproof -\n  from \\<open>\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<longmapsto>\\<tau> \\<prec> P'\\<close> obtain \\<beta> where \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<longmapsto>\\<beta> \\<prec> P'\" and \"\\<beta> = \\<tau>\" \n    by auto\n  thus ?thesis\n    by(induct rule: prefixCases) (auto intro: rTau)\nqed\n\nlemma hennessySim1:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<leadsto><Rel> Q\"\n  and     C1: \"\\<And>\\<Psi> P Q R. \\<lbrakk>\\<Psi> \\<rhd> P \\<sim> Q; (\\<Psi>, Q, R) \\<in> Rel\\<rbrakk> \\<Longrightarrow> (\\<Psi>, P, R) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> \\<tau>.(P) \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\nproof(induct rule: weakCongSimI)\n  case(cTau Q')\n  from \\<open>\\<Psi> \\<rhd> P \\<leadsto><Rel> Q\\<close> \\<open>\\<Psi> \\<rhd> Q \\<longmapsto>\\<tau> \\<prec> Q'\\<close>\n  obtain P' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" and P'RelQ': \"(\\<Psi>, P', Q') \\<in> Rel\"\n    by(blast dest: weakSimE)\n\n  from PChain obtain P'' where \"\\<Psi> \\<rhd> \\<tau>.(P) \\<Longrightarrow>\\<^sub>\\<tau> P''\" and \"\\<Psi> \\<rhd> P' \\<sim> P''\"\n    by(rule tauChainStepCons)\n  thus ?case using P'RelQ' by(metis bisimE C1)\nqed\n\n\n\n  assumes PTrans: \"\\<Psi> \\<rhd> P \\<longmapsto>\\<tau> \\<prec> P'\"\n  and     P'RelQ: \"(\\<Psi>, P', Q) \\<in> Rel\"\n  and     C1: \"\\<And>\\<Psi> P Q R. \\<lbrakk>(\\<Psi>, P, Q) \\<in> Rel; \\<Psi> \\<rhd> Q \\<sim> R\\<rbrakk> \\<Longrightarrow> (\\<Psi>, P, R) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> \\<tau>.(Q)\"\nproof(induct rule: weakCongSimI)\n  case(cTau Q')\n  from \\<open>\\<Psi> \\<rhd> \\<tau>.(Q) \\<longmapsto>\\<tau> \\<prec> Q'\\<close> have \"\\<Psi> \\<rhd> Q \\<sim> Q'\" by(blast dest: tauActionE)\n  with PTrans P'RelQ show ?case by(metis C1 tauActTauStepChain)\nqed\n\nlemma hennessySim3:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<leadsto><Rel> Q\"\n  and     C1: \"\\<And>Q'. \\<Psi> \\<rhd> Q \\<longmapsto>\\<tau> \\<prec> Q' \\<Longrightarrow> (\\<Psi>, P, Q') \\<notin> Rel\"\n\n  shows \"\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\nproof(induct rule: weakCongSimI)\n  case(cTau Q')\n  from \\<open>\\<Psi> \\<rhd> P \\<leadsto><Rel> Q\\<close> \\<open>\\<Psi> \\<rhd> Q \\<longmapsto>\\<tau> \\<prec> Q'\\<close>\n  obtain P' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" and P'RelQ': \"(\\<Psi>, P', Q') \\<in> Rel\"\n    by(blast dest: weakSimE)\n  with C1 \\<open>\\<Psi> \\<rhd> Q \\<longmapsto>\\<tau> \\<prec> Q'\\<close> show ?case \n    by(force simp add: rtrancl_eq_or_trancl)\nqed\n\nlemma tauLaw1SimLeft:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<leadsto><Rel> Q\"\n  and     \"eqvt Rel\"\n  and     C1: \"\\<And>\\<Psi> P Q R. \\<lbrakk>\\<Psi> \\<rhd> P \\<sim> Q; (\\<Psi>, Q, R) \\<in> Rel\\<rbrakk> \\<Longrightarrow> (\\<Psi>, P, R) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> \\<tau>.(P) \\<leadsto><Rel> Q\"\nproof(induct rule: weakSimI2)\n  case(cAct \\<Psi>' \\<alpha> Q')\n  from \\<open>bn \\<alpha> \\<sharp>* (\\<tau>.(P))\\<close> have \"bn \\<alpha> \\<sharp>* P\" by simp\n  with \\<open>\\<Psi> \\<rhd> P \\<leadsto><Rel> Q\\<close> \\<open>\\<Psi> \\<rhd> Q \\<longmapsto>\\<alpha> \\<prec> Q'\\<close> \\<open>bn \\<alpha> \\<sharp>* \\<Psi>\\<close> \\<open>\\<alpha> \\<noteq> \\<tau>\\<close>\n  obtain P'' P' where PTrans: \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P''\" and P''Chain: \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n                  and P'RelQ': \"(\\<Psi> \\<otimes> \\<Psi>', P', Q') \\<in> Rel\"\n    by(blast dest: weakSimE)\n\n  from PTrans \\<open>bn \\<alpha> \\<sharp>* \\<Psi>\\<close> \\<open>bn \\<alpha> \\<sharp>* P\\<close> obtain P''' where \"\\<Psi> : Q \\<rhd> \\<tau>.(P) \\<Longrightarrow>\\<alpha> \\<prec> P'''\" and \"\\<Psi> \\<rhd> P'' \\<sim> P'''\"\n    by(rule weakTransitionTau)\n  moreover from \\<open>\\<Psi> \\<rhd> P'' \\<sim> P'''\\<close> have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P'' \\<sim> P'''\" by(rule bisimE)\n  with P''Chain obtain P'''' where \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P''' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''''\" and \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P' \\<sim> P''''\"\n    by(rule tauChainBisim)\n  ultimately show ?case using \\<open>(\\<Psi> \\<otimes> \\<Psi>', P', Q') \\<in> Rel\\<close> by(metis bisimE C1)\nnext\n  case(cTau Q')\n  from \\<open>\\<Psi> \\<rhd> P \\<leadsto><Rel> Q\\<close> \\<open>\\<Psi> \\<rhd> Q \\<longmapsto>\\<tau> \\<prec> Q'\\<close>\n  obtain P' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" and P'RelQ': \"(\\<Psi>, P', Q') \\<in> Rel\"\n    by(blast dest: weakSimE)\n\n  from PChain obtain P'' where \"\\<Psi> \\<rhd> \\<tau>.(P) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" and \"\\<Psi> \\<rhd> P' \\<sim> P''\"\n    by(rule tauChainCons)\n  thus ?case using P'RelQ' by(metis bisimE C1)  \nqed\n\nlemma tauLaw1SimRight:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes \"eqvt Rel\"\n  and     \"(\\<Psi>, P, Q) \\<in> Rel\"\n  and     C1: \"\\<And>\\<Psi> P Q R. \\<lbrakk>(\\<Psi>, P, Q) \\<in> Rel; \\<Psi> \\<rhd> Q \\<sim> R\\<rbrakk> \\<Longrightarrow> (\\<Psi>, P, R) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> P \\<leadsto><Rel> \\<tau>.(Q)\"\nusing \\<open>eqvt Rel\\<close>\nproof(induct rule: weakSimI[where C=Q])\n  case(cAct \\<Psi>' \\<alpha> Q')\n  hence False by(cases rule: actionCases[where \\<alpha>=\\<alpha>]) auto\n  thus ?case by simp\nnext\n  case(cTau Q')\n  have \"\\<Psi> \\<rhd> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q\" by simp\n  moreover from \\<open>\\<Psi> \\<rhd> \\<tau>.(Q) \\<longmapsto>\\<tau> \\<prec> Q'\\<close> have \"\\<Psi> \\<rhd> Q \\<sim> Q'\" by(rule tauActionE)\n  with \\<open>(\\<Psi>, P, Q) \\<in> Rel\\<close> have \"(\\<Psi>, P, Q') \\<in> Rel\" by(rule C1)\n  ultimately show ?case by blast\nqed\n\nlemma tauLaw3SimLeft:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha> :: \"'a prefix\"\n\n  assumes \"eqvt Rel\"\n  and     \"(\\<Psi>, P, Q) \\<in> Rel\"\n  and     Subst: \"\\<And>xvec Tvec. length xvec = length Tvec \\<Longrightarrow> (\\<Psi>, P[xvec::=Tvec], Q[xvec::=Tvec]) \\<in> Rel\"\n  and     C1: \"\\<And>\\<Psi> P Q R S. \\<lbrakk>\\<Psi> \\<rhd> P \\<sim> Q; (\\<Psi>, Q, R) \\<in> Rel; \\<Psi> \\<rhd> R \\<sim> S\\<rbrakk> \\<Longrightarrow> (\\<Psi>, P, S) \\<in> Rel\"\n  and     rExt: \"\\<And>\\<Psi> P Q \\<Psi>'. (\\<Psi>, P, Q) \\<in> Rel \\<Longrightarrow> (\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(P)) \\<leadsto><Rel> \\<alpha>\\<cdot>Q\"\nusing \\<open>eqvt Rel\\<close>\nproof(induct rule: weakSimI[where C=Q])\n  case(cAct \\<Psi>' \\<beta> Q')\n  from \\<open>\\<Psi> \\<rhd> \\<alpha>\\<cdot>Q \\<longmapsto>\\<beta> \\<prec> Q'\\<close> \\<open>\\<beta> \\<noteq> \\<tau>\\<close> show ?case\n  proof(induct rule: prefixCases)\n    case(cInput M xvec N K Tvec)\n    note \\<open>\\<Psi> \\<turnstile> M \\<leftrightarrow> K\\<close> \\<open>distinct xvec\\<close> \\<open>set xvec \\<subseteq> supp N\\<close> \\<open>length xvec = length Tvec\\<close>\n    moreover have \"insertAssertion (extractFrame(M\\<lparr>\\<lambda>*xvec N\\<rparr>.Q)) \\<Psi> \\<hookrightarrow>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi> \\<otimes> \\<one>\\<rangle>\" by auto\n    ultimately have \"\\<Psi> : (M\\<lparr>\\<lambda>*xvec N\\<rparr>.Q) \\<rhd> (M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P))) \\<Longrightarrow>K\\<lparr>(N[xvec::=Tvec])\\<rparr> \\<prec> (\\<tau>.(P))[xvec::=Tvec]\" \n      by(rule weakInput)\n    hence \"\\<Psi> : (M\\<lparr>\\<lambda>*xvec N\\<rparr>.Q) \\<rhd> (M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P))) \\<Longrightarrow>K\\<lparr>(N[xvec::=Tvec])\\<rparr> \\<prec> \\<tau>.(P[xvec::=Tvec])\"\n      using \\<open>length xvec = length Tvec\\<close> \\<open>distinct xvec\\<close>\n      by simp\n      \n    moreover obtain P' where PTrans: \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> \\<tau>.(P[xvec::=Tvec]) \\<longmapsto>\\<tau> \\<prec> P'\" and \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> (P[xvec::=Tvec]) \\<sim> P'\" using tauActionI\n      by auto\n    from PTrans have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> \\<tau>.(P[xvec::=Tvec]) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" by(rule tauActTauChain)\n    moreover from \\<open>length xvec = length Tvec\\<close> have \"(\\<Psi>, P[xvec::=Tvec], Q[xvec::=Tvec]) \\<in> Rel\" by(rule Subst)\n    hence \"(\\<Psi> \\<otimes> \\<Psi>', P[xvec::=Tvec], Q[xvec::=Tvec]) \\<in> Rel\" by(rule rExt)\n    with \\<open>\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P[xvec::=Tvec] \\<sim> P'\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>', P', Q[xvec::=Tvec]) \\<in> Rel\" by(blast intro: bisimE C1 bisimReflexive)\n    ultimately show ?case by fastforce\n  next\n    case(cOutput M N K)\n    note \\<open>\\<Psi> \\<turnstile> M \\<leftrightarrow> K\\<close>\n    moreover have \"insertAssertion (extractFrame (M\\<langle>N\\<rangle>.Q)) \\<Psi> \\<hookrightarrow>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi> \\<otimes> \\<one>\\<rangle>\" by auto\n    ultimately have \"\\<Psi> : M\\<langle>N\\<rangle>.Q \\<rhd> M\\<langle>N\\<rangle>.(\\<tau>.(P)) \\<Longrightarrow>K\\<langle>N\\<rangle> \\<prec> \\<tau>.(P)\" by(rule weakOutput)\n    moreover obtain P' where PTrans: \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P'\" and \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<sim> P'\" using tauActionI\n      by auto\n    from PTrans have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> \\<tau>.(P) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" by(rule tauActTauChain)\n    moreover from \\<open>(\\<Psi>, P, Q) \\<in> Rel\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> Rel\" by(rule rExt)\n    with \\<open>\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<sim> P'\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>', P', Q) \\<in> Rel\" by(blast intro: bisimE C1 bisimReflexive)\n    ultimately show ?case by fastforce\n  next\n    case cTau\n    with \\<open>\\<tau> \\<noteq> \\<tau>\\<close> show ?case\n      by simp\n  qed\nnext\n  case(cTau Q')\n  from \\<open>\\<Psi> \\<rhd> \\<alpha>\\<cdot>Q \\<longmapsto>\\<tau> \\<prec> Q'\\<close> show ?case\n  proof(induct rule: prefixTauCases)\n    case cTau\n    obtain P' where tPTrans: \"\\<Psi> \\<rhd> \\<tau>.(\\<tau>.(P)) \\<longmapsto>\\<tau> \\<prec> P'\" and \"\\<Psi> \\<rhd> \\<tau>.(P) \\<sim> P'\" using tauActionI\n      by auto\n    obtain P'' where PTrans: \"\\<Psi> \\<rhd> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P''\" and \"\\<Psi> \\<rhd> P \\<sim> P''\" using tauActionI\n      by auto\n    from PTrans \\<open>\\<Psi> \\<rhd> \\<tau>.(P) \\<sim> P'\\<close> obtain P''' where P'Trans: \"\\<Psi> \\<rhd> P' \\<longmapsto>\\<tau> \\<prec> P'''\" and \"\\<Psi> \\<rhd> P'' \\<sim> P'''\"\n      apply(drule_tac bisimE(4))\n      apply(drule_tac bisimE(2))\n      apply(drule_tac simE, auto)\n      by(metis bisimE)\n    from tPTrans P'Trans have \"\\<Psi> \\<rhd> \\<tau>.(\\<tau>.(P)) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'''\" by(fastforce dest: tauActTauChain)\n    moreover from \\<open>(\\<Psi>, P, Q) \\<in> Rel\\<close> \\<open>\\<Psi> \\<rhd> P \\<sim> P''\\<close> \\<open>\\<Psi> \\<rhd> P'' \\<sim> P'''\\<close> \\<open>\\<Psi> \\<rhd> Q \\<sim> Q'\\<close> have \"(\\<Psi>, P''', Q') \\<in> Rel\"\n      by(metis bisimTransitive C1 bisimSymmetric)\n    ultimately show ?case by fastforce\n  qed\nqed\n\nlemma tauLaw3SimRight:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes \"eqvt Rel\"\n  and     Subst: \"\\<And>\\<Psi> xvec Tvec. length xvec = length Tvec \\<Longrightarrow> (\\<Psi>, P[xvec::=Tvec], \\<tau>.(Q[xvec::=Tvec])) \\<in> Rel\"\n  and     C1: \"\\<And>\\<Psi> P Q R S. \\<lbrakk>\\<Psi> \\<rhd> P \\<sim> Q; (\\<Psi>, Q, R) \\<in> Rel; \\<Psi> \\<rhd> R \\<sim> S\\<rbrakk> \\<Longrightarrow> (\\<Psi>, P, S) \\<in> Rel\"\n  and     \"\\<And>\\<Psi>. (\\<Psi>, P, \\<tau>.(Q)) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<leadsto><Rel> \\<alpha>\\<cdot>(\\<tau>.(Q))\"\nusing \\<open>eqvt Rel\\<close>\nproof(induct rule: weakSimI[where C=Q])\n  case(cAct \\<Psi>' \\<beta> Q')\n  from \\<open>\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(Q)) \\<longmapsto>\\<beta> \\<prec> Q'\\<close> \\<open>\\<beta> \\<noteq> \\<tau>\\<close>\n  show ?case\n  proof(induct rule: prefixCases)\n    case(cInput M xvec N K Tvec)\n    note \\<open>\\<Psi> \\<turnstile> M \\<leftrightarrow> K\\<close> \\<open>distinct xvec\\<close> \\<open>set xvec \\<subseteq> supp N\\<close> \\<open>length xvec=length Tvec\\<close>\n    moreover have \"insertAssertion (extractFrame (M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(Q)))) \\<Psi> \\<hookrightarrow>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi> \\<otimes> \\<one>\\<rangle>\" by auto\n    ultimately have \"\\<Psi> : (M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(Q))) \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.P \\<Longrightarrow>K\\<lparr>(N[xvec::=Tvec])\\<rparr> \\<prec> P[xvec::=Tvec]\"\n      by(rule weakInput)\n    moreover have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P[xvec::=Tvec] \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P[xvec::=Tvec]\" by auto\n    ultimately show ?case using Subst \\<open>length xvec=length Tvec\\<close> \\<open>distinct xvec\\<close>\n      by fastforce\n  next\n    case(cOutput M N K)\n    note \\<open>\\<Psi> \\<turnstile> M \\<leftrightarrow> K\\<close>\n    moreover have \"insertAssertion (extractFrame (M\\<langle>N\\<rangle>.(\\<tau>.(Q)))) \\<Psi> \\<hookrightarrow>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi> \\<otimes> \\<one>\\<rangle>\" by auto\n    ultimately have \"\\<Psi> : M\\<langle>N\\<rangle>.(\\<tau>.(Q)) \\<rhd> M\\<langle>N\\<rangle>.P \\<Longrightarrow>K\\<langle>N\\<rangle> \\<prec> P\" by(rule weakOutput)\n    moreover have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P\" by auto\n    ultimately show ?case using \\<open>(\\<Psi> \\<otimes> \\<Psi>', P, \\<tau>.(Q)) \\<in> Rel\\<close> by fastforce\n  next\n    case cTau\n    with \\<open>\\<tau> \\<noteq> \\<tau>\\<close> show ?case by simp\n  qed\nnext\n  case(cTau Q')\n  from \\<open>\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(Q)) \\<longmapsto>\\<tau> \\<prec> Q'\\<close> show ?case\n  proof(induct rule: prefixTauCases)\n    case cTau\n    obtain P' where PTrans: \"\\<Psi> \\<rhd> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P'\" and \"\\<Psi> \\<rhd> P \\<sim> P'\" using tauActionI\n      by auto\n    from PTrans have \"\\<Psi> \\<rhd> \\<tau>.(P) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" by(rule tauActTauChain)\n    moreover from \\<open>\\<Psi> \\<rhd> P \\<sim> P'\\<close> \\<open>\\<Psi> \\<rhd> \\<tau>.(Q) \\<sim> Q'\\<close>  \\<open>(\\<Psi>, P, \\<tau>.(Q)) \\<in> Rel\\<close>\n    have \"(\\<Psi>, P', Q') \\<in> Rel\" by(metis bisimTransitive bisimSymmetric C1)\n    ultimately show ?case by fastforce\n  qed\nqed\n\nlemma tauLaw3CongSimLeft:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes \"(\\<Psi>, P, Q) \\<in> Rel\"\n  and     C1: \"\\<And>\\<Psi> P Q R S. \\<lbrakk>\\<Psi> \\<rhd> P \\<sim> Q; (\\<Psi>, Q, R) \\<in> Rel; \\<Psi> \\<rhd> R \\<sim> S\\<rbrakk> \\<Longrightarrow> (\\<Psi>, P, S) \\<in> Rel\"\n  and     rExt: \"\\<And>\\<Psi> P Q \\<Psi>'. (\\<Psi>, P, Q) \\<in> Rel \\<Longrightarrow> (\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(P)) \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> \\<alpha>\\<cdot>Q\"\nproof(induct rule: weakCongSimI)\n  case(cTau Q')\n  from \\<open>\\<Psi> \\<rhd> \\<alpha>\\<cdot>Q \\<longmapsto>\\<tau> \\<prec> Q'\\<close> show ?case\n  proof(induct rule: prefixTauCases)\n    case cTau\n    obtain P' where tPTrans: \"\\<Psi> \\<rhd> \\<tau>.(\\<tau>.(P)) \\<longmapsto>\\<tau> \\<prec> P'\" and \"\\<Psi> \\<rhd> \\<tau>.(P) \\<sim> P'\" using tauActionI\n      by auto\n    obtain P'' where PTrans: \"\\<Psi> \\<rhd> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P''\" and \"\\<Psi> \\<rhd> P \\<sim> P''\" using tauActionI\n      by auto\n    from PTrans \\<open>\\<Psi> \\<rhd> \\<tau>.(P) \\<sim> P'\\<close> obtain P''' where P'Trans: \"\\<Psi> \\<rhd> P' \\<longmapsto>\\<tau> \\<prec> P'''\" and \"\\<Psi> \\<rhd> P'' \\<sim> P'''\"\n      apply(drule_tac bisimE(4))\n      apply(drule_tac bisimE(2))\n      apply(drule_tac simE, auto)\n      by(metis bisimE)\n    from tPTrans P'Trans have \"\\<Psi> \\<rhd> \\<tau>.(\\<tau>.(P)) \\<Longrightarrow>\\<^sub>\\<tau> P'''\" by(fastforce dest: tauActTauStepChain)\n    moreover from \\<open>(\\<Psi>, P, Q) \\<in> Rel\\<close> \\<open>\\<Psi> \\<rhd> P \\<sim> P''\\<close> \\<open>\\<Psi> \\<rhd> P'' \\<sim> P'''\\<close> \\<open>\\<Psi> \\<rhd> Q \\<sim> Q'\\<close> have \"(\\<Psi>, P''', Q') \\<in> Rel\"\n      by(metis bisimTransitive C1 bisimSymmetric)\n    ultimately show ?case by fastforce\n  qed\nqed\n\nlemma tauLaw3CongSimRight:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes \"(\\<Psi>, P, Q) \\<in> Rel\"\n  and     C1: \"\\<And>\\<Psi> P Q R S. \\<lbrakk>\\<Psi> \\<rhd> P \\<sim> Q; (\\<Psi>, Q, R) \\<in> Rel; \\<Psi> \\<rhd> R \\<sim> S\\<rbrakk> \\<Longrightarrow> (\\<Psi>, P, S) \\<in> Rel\"\n  and     \"\\<And>\\<Psi>. (\\<Psi>, P, \\<tau>.(Q)) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> \\<alpha>\\<cdot>(\\<tau>.(Q))\"\nproof(induct rule: weakCongSimI)\n  case(cTau Q')\n  from \\<open>\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(Q)) \\<longmapsto>\\<tau> \\<prec> Q'\\<close> show ?case\n  proof(induct rule: prefixTauCases)\n    case cTau\n    obtain P' where PTrans: \"\\<Psi> \\<rhd> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P'\" and \"\\<Psi> \\<rhd> P \\<sim> P'\" using tauActionI\n      by auto\n    from PTrans have \"\\<Psi> \\<rhd> \\<tau>.(P) \\<Longrightarrow>\\<^sub>\\<tau> P'\" by(rule tauActTauStepChain)\n    moreover from \\<open>\\<Psi> \\<rhd> P \\<sim> P'\\<close> \\<open>\\<Psi> \\<rhd> \\<tau>.(Q) \\<sim> Q'\\<close>  \\<open>(\\<Psi>, P, \\<tau>.(Q)) \\<in> Rel\\<close>\n    have \"(\\<Psi>, P', Q') \\<in> Rel\" by(metis bisimTransitive bisimSymmetric C1)\n    ultimately show ?case by fastforce\n  qed\nqed\n\nend\n\nlocale tauSum = tau + sum\nbegin\n\nlemma tauLaw2SimLeft:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n\n  assumes Id: \"\\<And>\\<Psi> P. (\\<Psi>, P, P) \\<in> Rel\"\n  and     C1: \"\\<And>\\<Psi> P Q R S. \\<lbrakk>\\<Psi> \\<rhd> P \\<sim> Q; (\\<Psi>, Q, R) \\<in> Rel; \\<Psi> \\<rhd> R \\<sim> S\\<rbrakk> \\<Longrightarrow> (\\<Psi>, P, S) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> P \\<oplus> \\<tau>.(P) \\<leadsto><Rel> \\<tau>.(P)\"\nproof(induct rule: weakSimI2)\n  case(cAct \\<Psi>' \\<alpha> P')\n  thus ?case by(nominal_induct \\<alpha> rule: action.strong_inducts) auto\nnext\n  case(cTau P')\n  from \\<open>\\<Psi> \\<rhd> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P'\\<close> have \"\\<Psi> \\<rhd> P \\<sim> P'\" by(rule tauActionE)\n  obtain P'' where PTrans: \"\\<Psi> \\<rhd> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P''\" and \"\\<Psi> \\<rhd> P \\<sim> P''\" using tauActionI\n    by auto\n  have \"guarded(\\<tau>.(P))\" by(rule guardedTau)\n  with PTrans have \"\\<Psi> \\<rhd> P \\<oplus> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P''\" by(rule Sum2)\n  hence \"\\<Psi> \\<rhd> P \\<oplus> \\<tau>.(P) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" by(rule tauActTauChain)\n  moreover from \\<open>\\<Psi> \\<rhd> P \\<sim> P''\\<close> \\<open>(\\<Psi>, P, P) \\<in> Rel\\<close> \\<open>\\<Psi> \\<rhd> P \\<sim> P'\\<close> have \"(\\<Psi>, P'', P') \\<in> Rel\"\n    by(metis C1 bisimE)\n  ultimately show ?case by blast\nqed  \n\nlemma tauLaw2CongSimLeft:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n\n  assumes Id: \"\\<And>\\<Psi> P. (\\<Psi>, P, P) \\<in> Rel\"\n  and     C1: \"\\<And>\\<Psi> P Q R S. \\<lbrakk>\\<Psi> \\<rhd> P \\<sim> Q; (\\<Psi>, Q, R) \\<in> Rel; \\<Psi> \\<rhd> R \\<sim> S\\<rbrakk> \\<Longrightarrow> (\\<Psi>, P, S) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> P \\<oplus> \\<tau>.(P) \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> \\<tau>.(P)\"\nproof(induct rule: weakCongSimI)\n  case(cTau P')\n  from \\<open>\\<Psi> \\<rhd> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P'\\<close> have \"\\<Psi> \\<rhd> P \\<sim> P'\" by(rule tauActionE)\n  obtain P'' where PTrans: \"\\<Psi> \\<rhd> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P''\" and \"\\<Psi> \\<rhd> P \\<sim> P''\" using tauActionI\n    by auto\n  have \"guarded(\\<tau>.(P))\" by(rule guardedTau)\n  with PTrans have \"\\<Psi> \\<rhd> P \\<oplus> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P''\" by(rule Sum2)\n  hence \"\\<Psi> \\<rhd> P \\<oplus> \\<tau>.(P) \\<Longrightarrow>\\<^sub>\\<tau> P''\" by(rule tauActTauStepChain)\n  moreover from \\<open>\\<Psi> \\<rhd> P \\<sim> P''\\<close> \\<open>(\\<Psi>, P, P) \\<in> Rel\\<close> \\<open>\\<Psi> \\<rhd> P \\<sim> P'\\<close> have \"(\\<Psi>, P'', P') \\<in> Rel\"\n    by(metis C1 bisimE)\n  ultimately show ?case by blast\nqed  \n\nlemma tauLaw2SimRight:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n\n  assumes C1: \"\\<And>\\<Psi> P Q. \\<Psi> \\<rhd> P \\<sim> Q \\<Longrightarrow> (\\<Psi>, P, Q) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> \\<tau>.(P) \\<leadsto><Rel> P \\<oplus> \\<tau>.(P)\"\nproof(induct rule: weakSimI2)\n  case(cAct \\<Psi>' \\<alpha> P')\n  from \\<open>\\<Psi> \\<rhd> P \\<oplus> \\<tau>.(P) \\<longmapsto>\\<alpha> \\<prec> P'\\<close>\n  show ?case\n  proof(induct rule: sumCases)\n    case cSum1 \n    obtain P'' where PTrans: \"\\<Psi> \\<rhd> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P''\" and \"\\<Psi> \\<rhd> P \\<sim> P''\" using tauActionI\n      by auto\n    from PTrans have \"\\<Psi> \\<rhd> \\<tau>.(P) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" by(rule tauActTauChain)\n    moreover from \\<open>guarded P\\<close> have \"insertAssertion (extractFrame P) \\<Psi> \\<simeq>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi> \\<otimes> \\<one>\\<rangle>\"\n      by(rule insertGuardedAssertion)\n    with \\<open>\\<Psi> \\<rhd> P \\<sim> P''\\<close> have \"insertAssertion (extractFrame P'') \\<Psi> \\<simeq>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi> \\<otimes> \\<one>\\<rangle>\"\n      by(metis bisimE FrameStatEqTrans FrameStatEqSym)\n    hence \"insertAssertion (extractFrame(P \\<oplus> \\<tau>.(P))) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P'') \\<Psi>\"\n      by(simp add: FrameStatEq_def)\n    moreover from PTrans \\<open>bn \\<alpha> \\<sharp>* (\\<tau>.(P))\\<close> have \"bn \\<alpha> \\<sharp>* P''\" by(rule tauFreshChainDerivative)\n    with \\<open>\\<Psi> \\<rhd> P \\<sim> P''\\<close> \\<open>\\<Psi> \\<rhd> P \\<longmapsto>\\<alpha> \\<prec> P'\\<close> \\<open>bn \\<alpha> \\<sharp>* \\<Psi>\\<close>\n    obtain P''' where P''Trans: \"\\<Psi> \\<rhd> P'' \\<longmapsto>\\<alpha> \\<prec> P'''\" and \"\\<Psi> \\<rhd> P''' \\<sim> P'\"\n      by(metis bisimE simE)\n    ultimately have \"\\<Psi> : (P \\<oplus> \\<tau>.(P)) \\<rhd> \\<tau>.(P) \\<Longrightarrow>\\<alpha> \\<prec> P'''\"\n      by(rule_tac weakTransitionI)\n    moreover have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P''' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'''\" by auto\n    moreover from \\<open>\\<Psi> \\<rhd> P''' \\<sim> P'\\<close> have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P''' \\<sim> P'\" by(rule bisimE)\n    hence \"(\\<Psi> \\<otimes> \\<Psi>', P''', P') \\<in> Rel\" by(rule C1)\n    ultimately show ?case by blast\n  next\n    case cSum2\n    thus ?case using \\<open>\\<alpha> \\<noteq> \\<tau>\\<close>\n      by(nominal_induct \\<alpha> rule: action.strong_inducts) auto\n  qed\nnext\n  case(cTau P')\n  from \\<open>\\<Psi> \\<rhd> P \\<oplus> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P'\\<close>\n  show ?case\n  proof(induct rule: sumCases)\n    case cSum1 \n    obtain P'' where PTrans: \"\\<Psi> \\<rhd> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P''\" and \"\\<Psi> \\<rhd> P \\<sim> P''\" using tauActionI\n      by auto\n    moreover from \\<open>\\<Psi> \\<rhd> P \\<sim> P''\\<close> \\<open>\\<Psi> \\<rhd> P \\<longmapsto>\\<tau> \\<prec> P'\\<close> \n    obtain P''' where P''Trans: \"\\<Psi> \\<rhd> P'' \\<longmapsto>\\<tau> \\<prec> P'''\" and \"\\<Psi> \\<rhd> P''' \\<sim> P'\"\n      apply(drule_tac bisimE(4))\n      apply(drule_tac bisimE(2))\n      by(drule_tac simE, auto)\n    ultimately have \"\\<Psi> \\<rhd> \\<tau>.(P) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'''\" by(auto dest: tauActTauChain rtrancl_into_rtrancl)\n    moreover from \\<open>\\<Psi> \\<rhd> P''' \\<sim> P'\\<close> have \"(\\<Psi>, P''', P') \\<in> Rel\" by(rule C1)\n    ultimately show ?case by blast\n  next\n    case cSum2\n    from \\<open>\\<Psi> \\<rhd> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P'\\<close> have \"\\<Psi> \\<rhd> P \\<sim> P'\" by(rule tauActionE)\n    obtain P'' where PTrans: \"\\<Psi> \\<rhd> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P''\" and \"\\<Psi> \\<rhd> P \\<sim> P''\" using tauActionI\n      by auto\n    hence \"\\<Psi> \\<rhd> \\<tau>.(P) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" by(rule_tac tauActTauChain)\n    moreover from \\<open>\\<Psi> \\<rhd> P \\<sim> P''\\<close> \\<open>\\<Psi> \\<rhd> P \\<sim> P'\\<close> have \"(\\<Psi>, P'', P') \\<in> Rel\"\n      by(metis C1 bisimTransitive bisimE)\n    ultimately show ?case by blast\n  qed\nqed\n\nlemma tauLaw2CongSimRight:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n\n  assumes C1: \"\\<And>\\<Psi> P Q. \\<Psi> \\<rhd> P \\<sim> Q \\<Longrightarrow> (\\<Psi>, P, Q) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> \\<tau>.(P) \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> P \\<oplus> \\<tau>.(P)\"\nproof(induct rule: weakCongSimI)\n  case(cTau P')\n  from \\<open>\\<Psi> \\<rhd> P \\<oplus> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P'\\<close>\n  show ?case\n  proof(induct rule: sumCases)\n    case cSum1 \n    obtain P'' where PTrans: \"\\<Psi> \\<rhd> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P''\" and \"\\<Psi> \\<rhd> P \\<sim> P''\" using tauActionI\n      by auto\n    moreover from \\<open>\\<Psi> \\<rhd> P \\<sim> P''\\<close> \\<open>\\<Psi> \\<rhd> P \\<longmapsto>\\<tau> \\<prec> P'\\<close> \n    obtain P''' where P''Trans: \"\\<Psi> \\<rhd> P'' \\<longmapsto>\\<tau> \\<prec> P'''\" and \"\\<Psi> \\<rhd> P''' \\<sim> P'\"\n      apply(drule_tac bisimE(4))\n      apply(drule_tac bisimE(2))\n      by(drule_tac simE) auto\n    ultimately have \"\\<Psi> \\<rhd> \\<tau>.(P) \\<Longrightarrow>\\<^sub>\\<tau> P'''\" by(auto dest: tauActTauStepChain trancl_into_trancl)\n    moreover from \\<open>\\<Psi> \\<rhd> P''' \\<sim> P'\\<close> have \"(\\<Psi>, P''', P') \\<in> Rel\" by(rule C1)\n    ultimately show ?case by blast\n  next\n    case cSum2\n    from \\<open>\\<Psi> \\<rhd> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P'\\<close> have \"\\<Psi> \\<rhd> P \\<sim> P'\" by(rule tauActionE)\n    obtain P'' where PTrans: \"\\<Psi> \\<rhd> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P''\" and \"\\<Psi> \\<rhd> P \\<sim> P''\" using tauActionI\n      by auto\n    hence \"\\<Psi> \\<rhd> \\<tau>.(P) \\<Longrightarrow>\\<^sub>\\<tau> P''\" by(rule_tac tauActTauStepChain)\n    moreover from \\<open>\\<Psi> \\<rhd> P \\<sim> P''\\<close> \\<open>\\<Psi> \\<rhd> P \\<sim> P'\\<close> have \"(\\<Psi>, P'', P') \\<in> Rel\"\n      by(metis C1 bisimTransitive bisimE)\n    ultimately show ?case by blast\n  qed\nqed\n\nlemma tauLaw4SimLeft:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   M :: 'a\n  and   N :: 'a\n\n  assumes \"\\<And>\\<Psi> P. (\\<Psi>, P, P) \\<in> Rel\"\n  and     C1: \"\\<And>\\<Psi> P Q. \\<Psi> \\<rhd> P \\<sim> Q \\<Longrightarrow> (\\<Psi>, P, Q) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q) \\<leadsto><Rel> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q)\"\nproof(induct rule: weakSimI2)\n  case(cAct \\<Psi>' \\<beta> PQ)\n  from \\<open>\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q) \\<longmapsto>\\<beta> \\<prec> PQ\\<close> \\<open>\\<beta> \\<noteq> \\<tau>\\<close>\n  show ?case\n  proof(induct rule: prefixCases)\n    case(cInput M xvec N K Tvec)\n    have \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q)\" by auto\n    moreover have \"insertAssertion (extractFrame(\\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q))) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame(\\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q))) \\<Psi>\"\n      using insertTauAssertion Identity\n      by(nominal_induct \\<alpha> rule: prefix.strong_inducts, auto) \n        (rule FrameStatImpTrans[where G=\"\\<langle>\\<epsilon>, \\<Psi>\\<rangle>\"], auto simp add: FrameStatEq_def AssertionStatEq_def)\n    moreover from \\<open>\\<Psi> \\<turnstile> M \\<leftrightarrow> K\\<close> \\<open>distinct xvec\\<close> \\<open>set xvec \\<subseteq> supp N\\<close> \\<open>length xvec=length Tvec\\<close>\n    have \"\\<Psi> \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q) \\<longmapsto>K\\<lparr>(N[xvec::=Tvec])\\<rparr> \\<prec> (\\<tau>.(P) \\<oplus> Q)[xvec::=Tvec]\"\n      by(rule Input)\n    hence \"\\<Psi> \\<rhd> (M\\<lparr>\\<lambda>*xvec N\\<rparr>.P) \\<oplus> M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q) \\<longmapsto>K\\<lparr>(N[xvec::=Tvec])\\<rparr> \\<prec> (\\<tau>.(P) \\<oplus> Q)[xvec::=Tvec]\" \n      by(rule_tac Sum2) auto\n    ultimately have \"\\<Psi> : (M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q)) \\<rhd> (M\\<lparr>\\<lambda>*xvec N\\<rparr>.P) \\<oplus> M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q) \\<Longrightarrow>K\\<lparr>(N[xvec::=Tvec])\\<rparr> \\<prec> (\\<tau>.(P) \\<oplus> Q)[xvec::=Tvec]\"\n      by(rule_tac weakTransitionI) auto\n    moreover have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> (\\<tau>.(P) \\<oplus> Q)[xvec::=Tvec] \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> (\\<tau>.(P) \\<oplus> Q)[xvec::=Tvec]\" by auto\n    ultimately show ?case using \\<open>(\\<Psi> \\<otimes> \\<Psi>', (\\<tau>.(P) \\<oplus> Q)[xvec::=Tvec], (\\<tau>.(P) \\<oplus> Q)[xvec::=Tvec]) \\<in> Rel\\<close> by fastforce\n  next\n    case(cOutput M N K)\n    have \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q)\" by auto\n    moreover have \"insertAssertion (extractFrame(\\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q))) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame(\\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q))) \\<Psi>\"\n      using insertTauAssertion Identity\n      by(nominal_induct \\<alpha> rule: prefix.strong_inducts, auto) \n        (rule FrameStatImpTrans[where G=\"\\<langle>\\<epsilon>, \\<Psi>\\<rangle>\"], auto simp add: FrameStatEq_def AssertionStatEq_def)\n\n    moreover from \\<open>\\<Psi> \\<turnstile> M \\<leftrightarrow> K\\<close> have \"\\<Psi> \\<rhd> M\\<langle>N\\<rangle>.(\\<tau>.(P) \\<oplus> Q) \\<longmapsto>K\\<langle>N\\<rangle> \\<prec> (\\<tau>.(P) \\<oplus> Q)\"\n      by(rule Output)\n    hence \"\\<Psi> \\<rhd> M\\<langle>N\\<rangle>.P \\<oplus> M\\<langle>N\\<rangle>.(\\<tau>.(P) \\<oplus> Q) \\<longmapsto>K\\<langle>N\\<rangle> \\<prec> (\\<tau>.(P) \\<oplus> Q)\" by(rule_tac Sum2) auto\n    ultimately have \"\\<Psi> : (M\\<langle>N\\<rangle>.(\\<tau>.(P) \\<oplus> Q)) \\<rhd> M\\<langle>N\\<rangle>.P \\<oplus> M\\<langle>N\\<rangle>.(\\<tau>.(P) \\<oplus> Q) \\<Longrightarrow>K\\<langle>N\\<rangle> \\<prec> (\\<tau>.(P) \\<oplus> Q)\"\n      by(rule_tac weakTransitionI) auto\n    moreover have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> \\<tau>.(P) \\<oplus> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<tau>.(P) \\<oplus> Q\" by auto\n    ultimately show ?case using \\<open>(\\<Psi> \\<otimes> \\<Psi>', \\<tau>.(P) \\<oplus> Q, \\<tau>.(P) \\<oplus> Q) \\<in> Rel\\<close> by fastforce\n  next\n    case cTau\n    from \\<open>\\<tau> \\<noteq> \\<tau>\\<close> show ?case\n      by simp\n  qed\nnext\n  case(cTau Q')\n  from \\<open>\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(P)) \\<oplus>\\<^sub>\\<top> Q \\<longmapsto> \\<tau> \\<prec> Q'\\<close> show ?case\n  proof(induct rule: prefixTauCases)\n    case cTau\n    obtain P' where PTrans: \"\\<Psi> \\<rhd> \\<tau>.(\\<tau>.(P) \\<oplus> Q) \\<longmapsto>\\<tau> \\<prec> P'\" and \"\\<Psi> \\<rhd> \\<tau>.(P) \\<oplus> Q \\<sim> P'\" using tauActionI\n      by auto\n    from PTrans have \"\\<Psi> \\<rhd> (\\<tau>.(P)) \\<oplus> \\<tau>.(\\<tau>.(P) \\<oplus> Q) \\<longmapsto>\\<tau> \\<prec> P'\" by(rule_tac Sum2) (auto intro: guardedTau)\n    hence \"\\<Psi> \\<rhd> (\\<tau>.(P)) \\<oplus> \\<tau>.(\\<tau>.(P) \\<oplus> Q) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" by(rule tauActTauChain)\n    moreover from \\<open>\\<Psi> \\<rhd> \\<tau>.(P) \\<oplus> Q \\<sim> P'\\<close> \\<open>\\<Psi> \\<rhd> (\\<tau>.(P)) \\<oplus> Q \\<sim> Q'\\<close> have \"\\<Psi> \\<rhd> P' \\<sim> Q'\" by(metis bisimSymmetric bisimTransitive)\n    hence \"(\\<Psi>, P', Q') \\<in> Rel\" by(rule C1)\n    ultimately show ?case by fastforce\n  qed\nqed\n\nlemma tauLaw4CongSimLeft:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   M :: 'a\n  and   N :: 'a\n\n  assumes \"\\<And>\\<Psi> P. (\\<Psi>, P, P) \\<in> Rel\"\n  and     C1: \"\\<And>\\<Psi> P Q. \\<Psi> \\<rhd> P \\<sim> Q \\<Longrightarrow> (\\<Psi>, P, Q) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q) \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q)\"\nproof(induct rule: weakCongSimI)\n  case(cTau Q')\n  from \\<open>\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(P)) \\<oplus>\\<^sub>\\<top> Q \\<longmapsto> \\<tau> \\<prec> Q'\\<close> show ?case\n  proof(induct rule: prefixTauCases)\n    case cTau\n    obtain P' where PTrans: \"\\<Psi> \\<rhd> \\<tau>.(\\<tau>.(P) \\<oplus> Q) \\<longmapsto>\\<tau> \\<prec> P'\" and \"\\<Psi> \\<rhd> \\<tau>.(P) \\<oplus> Q \\<sim> P'\" using tauActionI\n      by auto\n    from PTrans have \"\\<Psi> \\<rhd> (\\<tau>.(P)) \\<oplus> \\<tau>.(\\<tau>.(P) \\<oplus> Q) \\<longmapsto>\\<tau> \\<prec> P'\" by(rule_tac Sum2) (auto intro: guardedTau)\n    hence \"\\<Psi> \\<rhd> (\\<tau>.(P)) \\<oplus> \\<tau>.(\\<tau>.(P) \\<oplus> Q) \\<Longrightarrow>\\<^sub>\\<tau> P'\" by(rule tauActTauStepChain)\n    moreover from \\<open>\\<Psi> \\<rhd> \\<tau>.(P) \\<oplus> Q \\<sim> P'\\<close> \\<open>\\<Psi> \\<rhd> (\\<tau>.(P)) \\<oplus> Q \\<sim> Q'\\<close> have \"\\<Psi> \\<rhd> P' \\<sim> Q'\" by(metis bisimSymmetric bisimTransitive)\n    hence \"(\\<Psi>, P', Q') \\<in> Rel\" by(rule C1)\n    ultimately show ?case by fastforce\n  qed\nqed\n\nlemma tauLaw4SimRight:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha> :: \"'a prefix\"\n\n  assumes C1: \"\\<And>\\<Psi> P Q. \\<Psi> \\<rhd> P \\<sim> Q \\<Longrightarrow> (\\<Psi>, P, Q) \\<in> Rel\"\n  and         \"\\<And>\\<Psi> P. (\\<Psi>, P, P) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q) \\<leadsto><Rel> \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q)\"\nproof(induct rule: weakSimI2)\n  case(cAct \\<Psi>' \\<beta> PQ)\n  from \\<open>\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q) \\<longmapsto>\\<beta> \\<prec> PQ\\<close> show ?case\n  proof(induct rule: sumCases)\n    case cSum1\n    from \\<open>\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<longmapsto>\\<beta> \\<prec> PQ\\<close> \\<open>\\<beta> \\<noteq> \\<tau>\\<close> show ?case\n    proof(induct rule: prefixCases)\n      case(cInput M xvec N K Tvec)\n      have \"\\<Psi> \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q)\" by auto\n      moreover have \"insertAssertion (extractFrame((M\\<lparr>\\<lambda>*xvec N\\<rparr>.P) \\<oplus> M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q))) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame(M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q))) \\<Psi>\"\n        by auto\n      moreover from \\<open>\\<Psi> \\<turnstile> M \\<leftrightarrow> K\\<close> \\<open>distinct xvec\\<close> \\<open>set xvec \\<subseteq> supp N\\<close> \\<open>length xvec = length Tvec\\<close>\n      have \"\\<Psi> \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q) \\<longmapsto>K\\<lparr>(N[xvec::=Tvec])\\<rparr> \\<prec> (\\<tau>.(P) \\<oplus> Q)[xvec::=Tvec]\" by(rule Input)\n      ultimately have \"\\<Psi> : ((M\\<lparr>\\<lambda>*xvec N\\<rparr>.P) \\<oplus> M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q)) \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q) \\<Longrightarrow>K\\<lparr>(N[xvec::=Tvec])\\<rparr>\\<prec> (\\<tau>.(P) \\<oplus> Q)[xvec::=Tvec]\"\n        by(rule_tac weakTransitionI) auto\n      with \\<open>length xvec = length Tvec\\<close> \\<open>distinct xvec\\<close>\n      have \"\\<Psi> : ((M\\<lparr>\\<lambda>*xvec N\\<rparr>.P) \\<oplus> M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q)) \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q) \\<Longrightarrow>K\\<lparr>(N[xvec::=Tvec])\\<rparr> \\<prec> (\\<tau>.(P[xvec::=Tvec]) \\<oplus> Q[xvec::=Tvec])\"\n        by auto\n      moreover obtain P' where PTrans: \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> \\<tau>.(P[xvec::=Tvec]) \\<longmapsto>\\<tau> \\<prec> P'\" and \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P[xvec::=Tvec] \\<sim> P'\" using tauActionI\n        by auto\n      have \"guarded(\\<tau>.(P[xvec::=Tvec]))\" by(rule guardedTau)\n      with PTrans have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> (\\<tau>.(P[xvec::=Tvec])) \\<oplus> (Q[xvec::=Tvec]) \\<longmapsto>\\<tau> \\<prec> P'\" by(rule Sum1)\n      hence \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> (\\<tau>.(P[xvec::=Tvec])) \\<oplus> (Q[xvec::=Tvec]) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" by(rule tauActTauChain)\n      moreover from \\<open>\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P[xvec::=Tvec] \\<sim> P'\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>', P', P[xvec::=Tvec]) \\<in> Rel\" by(metis bisimE C1)\n      ultimately show ?case by fastforce\n    next\n      case(cOutput M N K)\n      have \"\\<Psi> \\<rhd> M\\<langle>N\\<rangle>.(\\<tau>.(P) \\<oplus> Q) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> M\\<langle>N\\<rangle>.(\\<tau>.(P) \\<oplus> Q)\" by auto\n      moreover have \"insertAssertion (extractFrame(M\\<langle>N\\<rangle>.P \\<oplus> M\\<langle>N\\<rangle>.(\\<tau>.(P) \\<oplus> Q))) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame(M\\<langle>N\\<rangle>.(\\<tau>.(P) \\<oplus> Q))) \\<Psi>\"\n        by auto\n      moreover from \\<open>\\<Psi> \\<turnstile> M \\<leftrightarrow> K\\<close> have \"\\<Psi> \\<rhd> M\\<langle>N\\<rangle>.(\\<tau>.(P) \\<oplus> Q) \\<longmapsto>K\\<langle>N\\<rangle> \\<prec> (\\<tau>.(P) \\<oplus> Q)\" by(rule Output)\n      ultimately have \"\\<Psi> : (M\\<langle>N\\<rangle>.P \\<oplus> M\\<langle>N\\<rangle>.(\\<tau>.(P) \\<oplus> Q)) \\<rhd> M\\<langle>N\\<rangle>.(\\<tau>.(P) \\<oplus> Q) \\<Longrightarrow>K\\<langle>N\\<rangle> \\<prec> (\\<tau>.(P) \\<oplus> Q)\"\n        by(rule_tac weakTransitionI) auto\n      moreover obtain P' where PTrans: \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P'\" and \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<sim> P'\" using tauActionI\n        by auto\n      have \"guarded(\\<tau>.(P))\" by(rule guardedTau)\n      with PTrans have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> (\\<tau>.(P)) \\<oplus> Q \\<longmapsto>\\<tau> \\<prec> P'\" by(rule Sum1)\n      hence \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> (\\<tau>.(P)) \\<oplus> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" by(rule tauActTauChain)\n      moreover from \\<open>\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<sim> P'\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>', P', P) \\<in> Rel\" by(metis bisimE C1)\n      ultimately show ?case by fastforce \n    next\n      case cTau\n      from \\<open>\\<tau> \\<noteq> \\<tau>\\<close> show ?case by simp\n    qed\n  next\n    case cSum2\n    from \\<open>\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q) \\<longmapsto>\\<beta> \\<prec> PQ\\<close> \\<open>\\<beta> \\<noteq> \\<tau>\\<close> show ?case\n    proof(induct rule: prefixCases)\n      case(cInput M xvec N K Tvec)\n      have \"\\<Psi> \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q)\" by auto\n      moreover have \"insertAssertion (extractFrame((M\\<lparr>\\<lambda>*xvec N\\<rparr>.P) \\<oplus> M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q))) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame(M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q))) \\<Psi>\"\n        by auto\n      moreover from \\<open>\\<Psi> \\<turnstile> M \\<leftrightarrow> K\\<close> \\<open>distinct xvec\\<close> \\<open>set xvec \\<subseteq> supp N\\<close> \\<open>length xvec = length Tvec\\<close>\n      have \"\\<Psi> \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q) \\<longmapsto>K\\<lparr>(N[xvec::=Tvec])\\<rparr> \\<prec> (\\<tau>.(P) \\<oplus> Q)[xvec::=Tvec]\"\n        by(rule Input)\n      with \\<open>length xvec = length Tvec\\<close> \\<open>distinct xvec\\<close>\n      have \"\\<Psi> \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q) \\<longmapsto>K\\<lparr>(N[xvec::=Tvec])\\<rparr> \\<prec> (\\<tau>.(P[xvec::=Tvec]) \\<oplus> Q[xvec::=Tvec])\"\n        by simp\n      ultimately have \"\\<Psi> : ((M\\<lparr>\\<lambda>*xvec N\\<rparr>.P) \\<oplus> M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q)) \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.(\\<tau>.(P) \\<oplus> Q) \\<Longrightarrow>K\\<lparr>(N[xvec::=Tvec])\\<rparr> \\<prec> (\\<tau>.(P[xvec::=Tvec]) \\<oplus> Q[xvec::=Tvec])\"\n        by(rule_tac weakTransitionI) auto\n      moreover have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> \\<tau>.(P[xvec::=Tvec]) \\<oplus> (Q[xvec::=Tvec]) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<tau>.(P[xvec::=Tvec]) \\<oplus> (Q[xvec::=Tvec])\" by auto\n      ultimately show ?case using \\<open>(\\<Psi> \\<otimes> \\<Psi>', \\<tau>.(P[xvec::=Tvec]) \\<oplus> (Q[xvec::=Tvec]), \\<tau>.(P[xvec::=Tvec]) \\<oplus> (Q[xvec::=Tvec])) \\<in> Rel\\<close> \\<open>length xvec = length Tvec\\<close> \\<open>distinct xvec\\<close>\n        by fastforce\n    next\n      case(cOutput M N K)\n      have \"\\<Psi> \\<rhd> M\\<langle>N\\<rangle>.(\\<tau>.(P) \\<oplus> Q) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> M\\<langle>N\\<rangle>.(\\<tau>.(P) \\<oplus> Q)\" by auto\n      moreover have \"insertAssertion (extractFrame(M\\<langle>N\\<rangle>.P \\<oplus> M\\<langle>N\\<rangle>.(\\<tau>.(P) \\<oplus> Q))) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame(M\\<langle>N\\<rangle>.(\\<tau>.(P) \\<oplus> Q))) \\<Psi>\"\n        by auto\n      moreover from \\<open>\\<Psi> \\<turnstile> M \\<leftrightarrow> K\\<close> have \"\\<Psi> \\<rhd> M\\<langle>N\\<rangle>.(\\<tau>.(P) \\<oplus> Q) \\<longmapsto>K\\<langle>N\\<rangle> \\<prec> (\\<tau>.(P) \\<oplus> Q)\"\n        by(rule Output)\n      ultimately have \"\\<Psi> : (M\\<langle>N\\<rangle>.P \\<oplus> M\\<langle>N\\<rangle>.(\\<tau>.(P) \\<oplus> Q)) \\<rhd> M\\<langle>N\\<rangle>.(\\<tau>.(P) \\<oplus> Q) \\<Longrightarrow>K\\<langle>N\\<rangle> \\<prec> (\\<tau>.(P) \\<oplus> Q)\"\n        by(rule_tac weakTransitionI) auto\n      moreover have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> \\<tau>.(P) \\<oplus> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<tau>.(P) \\<oplus> Q\" by auto\n      ultimately show ?case using \\<open>(\\<Psi> \\<otimes> \\<Psi>', \\<tau>.(P) \\<oplus> Q, \\<tau>.(P) \\<oplus> Q) \\<in> Rel\\<close> by fastforce\n    next\n      case cTau\n      from \\<open>\\<tau> \\<noteq> \\<tau>\\<close> show ?case by simp\n    qed\n  qed\nnext\n  case(cTau PQ)\n  from \\<open>\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q) \\<longmapsto>\\<tau> \\<prec> PQ\\<close> show ?case\n  proof(induct rule: sumCases)\n    case cSum1\n    from \\<open>\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<longmapsto> \\<tau> \\<prec> PQ\\<close> show ?case\n    proof(induct rule: prefixTauCases)\n      case cTau\n      obtain P' where PTrans: \"\\<Psi> \\<rhd> \\<tau>.((\\<tau>.(P)) \\<oplus> Q) \\<longmapsto>\\<tau> \\<prec> P'\" and \"\\<Psi> \\<rhd> (\\<tau>.(P)) \\<oplus> Q \\<sim> P'\" using tauActionI\n        by auto\n      obtain P'' where P'Trans: \"\\<Psi> \\<rhd> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P''\" and \"\\<Psi> \\<rhd> P \\<sim> P''\" using tauActionI\n        by auto\n      from P'Trans have \"\\<Psi> \\<rhd> \\<tau>.(P) \\<oplus> Q\\<longmapsto>\\<tau> \\<prec> P''\" by(rule_tac Sum1) (auto intro: guardedTau)\n      with \\<open>\\<Psi> \\<rhd> (\\<tau>.(P)) \\<oplus> Q \\<sim> P'\\<close> obtain P''' where P''Trans: \"\\<Psi> \\<rhd> P' \\<longmapsto>\\<tau> \\<prec> P'''\" and \"\\<Psi> \\<rhd> P'' \\<sim> P'''\"\n        apply(drule_tac bisimE(4))\n        apply(drule_tac bisimE(2))\n        apply(drule_tac simE)\n        by(auto dest: bisimE)\n      from PTrans P''Trans have \"\\<Psi> \\<rhd> \\<tau>.((\\<tau>.(P)) \\<oplus> Q) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'''\" by(fastforce dest: tauActTauChain)\n      moreover from \\<open>\\<Psi> \\<rhd> P \\<sim> PQ\\<close> \\<open>\\<Psi> \\<rhd> P'' \\<sim> P'''\\<close> \\<open>\\<Psi> \\<rhd> P \\<sim> P''\\<close> have \"\\<Psi> \\<rhd> P''' \\<sim> PQ\"\n        by(metis bisimSymmetric bisimTransitive)\n      hence \"(\\<Psi>, P''', PQ) \\<in> Rel\" by(rule C1)\n      ultimately show ?case by fastforce\n    qed\n  next\n    case cSum2\n    from \\<open>\\<Psi> \\<rhd> \\<alpha>\\<cdot>((\\<tau>.(P)) \\<oplus> Q) \\<longmapsto>\\<tau> \\<prec> PQ\\<close> show ?case\n    proof(induct rule: prefixTauCases)\n      case cTau\n      obtain P' where PTrans: \"\\<Psi> \\<rhd> \\<tau>.((\\<tau>.(P)) \\<oplus> Q) \\<longmapsto>\\<tau> \\<prec> P'\" and \"\\<Psi> \\<rhd> (\\<tau>.(P)) \\<oplus> Q \\<sim> P'\" using tauActionI\n        by auto\n      from PTrans have \"\\<Psi> \\<rhd> \\<tau>.((\\<tau>.(P)) \\<oplus> Q) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" by(rule tauActTauChain)\n      moreover from \\<open>\\<Psi> \\<rhd> (\\<tau>.(P)) \\<oplus> Q \\<sim> P'\\<close> \\<open>\\<Psi> \\<rhd> \\<tau>.(P) \\<oplus> Q \\<sim> PQ\\<close> have \"\\<Psi> \\<rhd> P' \\<sim> PQ\"\n        by(metis bisimSymmetric bisimTransitive)\n      hence \"(\\<Psi>, P', PQ) \\<in> Rel\" by(rule C1)\n      ultimately show ?case by fastforce\n    qed\n  qed\nqed\n\n\n\n  assumes C1: \"\\<And>\\<Psi> P Q. \\<Psi> \\<rhd> P \\<sim> Q \\<Longrightarrow> (\\<Psi>, P, Q) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q) \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q)\"\nproof(induct rule: weakCongSimI)\n  case(cTau PQ)\n  from \\<open>\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<oplus> \\<alpha>\\<cdot>(\\<tau>.(P) \\<oplus> Q) \\<longmapsto>\\<tau> \\<prec> PQ\\<close> show ?case\n  proof(induct rule: sumCases)\n    case cSum1\n    from \\<open>\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<longmapsto> \\<tau> \\<prec> PQ\\<close> show ?case\n    proof(induct rule: prefixTauCases)\n      case cTau\n      obtain P' where PTrans: \"\\<Psi> \\<rhd> \\<tau>.((\\<tau>.(P)) \\<oplus> Q) \\<longmapsto>\\<tau> \\<prec> P'\" and \"\\<Psi> \\<rhd> (\\<tau>.(P)) \\<oplus> Q \\<sim> P'\" using tauActionI\n        by auto\n      obtain P'' where P'Trans: \"\\<Psi> \\<rhd> \\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P''\" and \"\\<Psi> \\<rhd> P \\<sim> P''\" using tauActionI\n        by auto\n      from P'Trans have \"\\<Psi> \\<rhd> \\<tau>.(P) \\<oplus> Q\\<longmapsto>\\<tau> \\<prec> P''\" by(rule_tac Sum1) (auto intro: guardedTau)\n      with \\<open>\\<Psi> \\<rhd> (\\<tau>.(P)) \\<oplus> Q \\<sim> P'\\<close> obtain P''' where P''Trans: \"\\<Psi> \\<rhd> P' \\<longmapsto>\\<tau> \\<prec> P'''\" and \"\\<Psi> \\<rhd> P'' \\<sim> P'''\"\n        apply(drule_tac bisimE(4))\n        apply(drule_tac bisimE(2))\n        apply(drule_tac simE)\n        by(auto dest: bisimE)\n      from PTrans P''Trans have \"\\<Psi> \\<rhd> \\<tau>.((\\<tau>.(P)) \\<oplus> Q) \\<Longrightarrow>\\<^sub>\\<tau> P'''\" by(fastforce dest: tauActTauStepChain)\n      moreover from \\<open>\\<Psi> \\<rhd> P \\<sim> PQ\\<close> \\<open>\\<Psi> \\<rhd> P'' \\<sim> P'''\\<close> \\<open>\\<Psi> \\<rhd> P \\<sim> P''\\<close> have \"\\<Psi> \\<rhd> P''' \\<sim> PQ\"\n        by(metis bisimSymmetric bisimTransitive)\n      hence \"(\\<Psi>, P''', PQ) \\<in> Rel\" by(rule C1)\n      ultimately show ?case by fastforce\n    qed\n  next\n    case cSum2\n    from \\<open>\\<Psi> \\<rhd> \\<alpha>\\<cdot>((\\<tau>.(P)) \\<oplus> Q) \\<longmapsto>\\<tau> \\<prec> PQ\\<close> show ?case\n    proof(induct rule: prefixTauCases)\n      case cTau\n      obtain P' where PTrans: \"\\<Psi> \\<rhd> \\<tau>.((\\<tau>.(P)) \\<oplus> Q) \\<longmapsto>\\<tau> \\<prec> P'\" and \"\\<Psi> \\<rhd> (\\<tau>.(P)) \\<oplus> Q \\<sim> P'\" using tauActionI\n        by auto\n      from PTrans have \"\\<Psi> \\<rhd> \\<tau>.((\\<tau>.(P)) \\<oplus> Q) \\<Longrightarrow>\\<^sub>\\<tau> P'\" by(rule tauActTauStepChain)\n      moreover from \\<open>\\<Psi> \\<rhd> (\\<tau>.(P)) \\<oplus> Q \\<sim> P'\\<close> \\<open>\\<Psi> \\<rhd> \\<tau>.(P) \\<oplus> Q \\<sim> PQ\\<close> have \"\\<Psi> \\<rhd> P' \\<sim> PQ\"\n        by(metis bisimSymmetric bisimTransitive)\n      hence \"(\\<Psi>, P', PQ) \\<in> Rel\" by(rule C1)\n      ultimately show ?case by fastforce\n    qed\n  qed\nqed\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Psi_Calculi/Tau_Sim.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5156199008363969, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.27390212442234074}}
{"text": "(* @TAG(OTHER_LGPL) *)\n\n(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      HoareTotalDef.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection {* Hoare Logic for Total Correctness *}\n\ntheory HoareTotalDef imports HoarePartialDef Termination begin \n\nsubsection {* Validity of Hoare Tuples: @{text  \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"} *}\n\ndefinition\n  validt :: \"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com,'s assn,'s assn] \\<Rightarrow> bool\"\n                (\"_\\<Turnstile>\\<^sub>t\\<^bsub>'/_\\<^esub>/ _ _ _,_\"  [61,60,1000, 20, 1000,1000] 60)\nwhere\n \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<equiv> \\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<and> (\\<forall>s \\<in> Normal ` P. \\<Gamma>\\<turnstile>c\\<down>s)\"\n\ndefinition\n  cvalidt::\n  \"[('s,'p,'f) body,('s,'p) quadruple set,'f set,\n    's assn,('s,'p,'f) com,'s assn,'s assn] \\<Rightarrow> bool\"\n                (\"_,_\\<Turnstile>\\<^sub>t\\<^bsub>'/_\\<^esub>/ _ _ _,_\"  [61,60, 60,1000, 20, 1000,1000] 60)\nwhere\n \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<equiv> (\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A) \\<longrightarrow> \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n\n\n\nnotation (ascii)\n  validt  (\"_|=t'/_/ _ _ _,_\"  [61,60,1000, 20, 1000,1000] 60) and\n  cvalidt  (\"_,_|=t'/_ / _ _ _,_\"  [61,60,60,1000, 20, 1000,1000] 60)\n\nsubsection {* Properties of Validity *}\n\nlemma validtI: \n \"\\<lbrakk>\\<And>s t. \\<lbrakk>\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t;s \\<in> P;t \\<notin> Fault ` F\\<rbrakk> \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A;\n   \\<And>s. s \\<in> P \\<Longrightarrow> \\<Gamma>\\<turnstile> c\\<down>(Normal s) \\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (auto simp add: validt_def valid_def)\n\nlemma cvalidtI: \n \"\\<lbrakk>\\<And>s t. \\<lbrakk>\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A;\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t;s \\<in> P; \n          t \\<notin> Fault ` F\\<rbrakk> \n          \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A;\n   \\<And>s. \\<lbrakk>\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A; s\\<in>P\\<rbrakk> \\<Longrightarrow>  \\<Gamma>\\<turnstile>c\\<down>(Normal s)\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (auto simp add: cvalidt_def validt_def valid_def)\n\nlemma cvalidt_postD: \n \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A; \\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A;\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> t;\n   s \\<in> P;t \\<notin> Fault ` F\\<rbrakk> \n  \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  by (simp add: cvalidt_def validt_def valid_def)\n\nlemma cvalidt_termD: \n \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A; \\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A;s \\<in> P\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>\\<turnstile>c\\<down>(Normal s)\"\n  by (simp add: cvalidt_def validt_def valid_def)\n\n\nlemma validt_augment_Faults:\n  assumes valid:\"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes F': \"F \\<subseteq> F'\"\n  shows \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F'\\<^esub> P c Q,A\"\n  using valid F'\n  by (auto intro: valid_augment_Faults simp add: validt_def)\n\nsubsection {* The Hoare Rules: @{text \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" } *}\n\ninductive \"hoaret\"::\"[('s,'p,'f) body,('s,'p) quadruple set,'f set,\n                        's assn,('s,'p,'f) com,'s assn,'s assn] \n                       => bool\"\n    (\"(3_,_/\\<turnstile>\\<^sub>t\\<^bsub>'/_\\<^esub> (_/ (_)/ _,_))\" [61,60,60,1000,20,1000,1000]60)  \n   for \\<Gamma>::\"('s,'p,'f) body\"\nwhere\n  Skip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> Q Skip Q,A\"\n\n| Basic: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. f s \\<in> Q} (Basic f) Q,A\"\n\n| Spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. (\\<forall>t. (s,t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s,t) \\<in> r)} (Spec r) Q,A\"\n\n| Seq: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 R,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk>\n        \\<Longrightarrow>\n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Seq c\\<^sub>1 c\\<^sub>2 Q,A\"\n  \n| Cond: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> b) c\\<^sub>1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> - b) c\\<^sub>2 Q,A\\<rbrakk>\n         \\<Longrightarrow> \n         \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) Q,A\"\n\n| While: \"\\<lbrakk>wf r; \\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P \\<inter> b) c ({t. (t,\\<sigma>)\\<in>r} \\<inter> P),A\\<rbrakk>\n          \\<Longrightarrow>\n          \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (While b c) (P \\<inter> - b),A\"\n\n| Guard: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\n          \\<Longrightarrow>\n          \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) Guard f g c Q,A\"\n\n| Guarantee: \"\\<lbrakk>f \\<in> F; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\n\n| CallRec: \n  \"\\<lbrakk>(P,p,Q,A) \\<in> Specs;\n    wf r; \n    Specs_wf = (\\<lambda>p \\<sigma>. (\\<lambda>(P,q,Q,A). (P \\<inter> {s. ((s,q),(\\<sigma>,p)) \\<in> r},q,Q,A)) ` Specs);\n    \\<forall>(P,p,Q,A)\\<in> Specs. \n      p \\<in> dom \\<Gamma> \\<and> (\\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<union> Specs_wf p \\<sigma>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P) (the (\\<Gamma> p)) Q,A)\n    \\<rbrakk>\n    \\<Longrightarrow>\n    \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n\n\n| DynCom:  \"\\<forall>s \\<in> P. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (c s) Q,A \n            \\<Longrightarrow> \n            \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (DynCom c) Q,A\"\n\n\n| Throw: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> A Throw Q,A\"\n\n| Catch: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk> \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Catch c\\<^sub>1 c\\<^sub>2 Q,A\"\n\n| Conseq: \"\\<forall>s \\<in> P. \\<exists>P' Q' A'. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A' \\<and> s \\<in> P' \\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A \n           \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n\n\n| Asm: \"(P,p,Q,A) \\<in> \\<Theta> \n        \\<Longrightarrow> \n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n\n| ExFalso: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A; \\<not> \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  -- {* This is a hack rule that enables us to derive completeness for\n        an arbitrary context @{text \"\\<Theta>\"}, from completeness for an empty context.*}\n\n  \ntext {* Does not work, because of rule ExFalso, the context @{text \\<Theta>} is to blame.\n A weaker version with empty context can be derived from soundness \n later on. *}\nlemma hoaret_to_hoarep:\n  assumes hoaret: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P p Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P p Q,A\"\nusing hoaret\nproof (induct)\n  case Skip thus ?case by (rule hoarep.intros)\nnext\n  case Basic thus ?case by (rule hoarep.intros)\nnext\n  case Seq thus ?case by - (rule hoarep.intros)\nnext\n  case Cond thus ?case by - (rule hoarep.intros)\nnext\n  case (While r \\<Theta> F P b c A)\n  hence \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P \\<inter> b) c ({t. (t, \\<sigma>) \\<in> r} \\<inter> P),A\"\n    by iprover\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> b) c P,A\"\n    by (rule HoarePartialDef.conseq) blast\n  then show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P While b c (P \\<inter> - b),A\"\n    by (rule hoarep.While)\nnext\n  case Guard thus ?case by - (rule hoarep.intros)\n(*next\n  case (CallRec A F P Procs Q Z \\<Theta>  p r)\n  hence hyp: \"\\<forall>p\\<in>Procs. \\<forall>\\<tau> Z. \n           \\<Gamma>,\\<Theta> \\<union> (\\<Union>q\\<in>Procs. \\<Union>Z. {(P q Z \\<inter> {s. ((s, q), \\<tau>, p) \\<in> r},\n                      Call q, Q q Z,A q Z)})\\<turnstile>\\<^bsub>/F\\<^esub>\n              ({\\<tau>} \\<inter> P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n    by blast\n  have \"\\<forall>p\\<in>Procs. \\<forall>Z. \n           \\<Gamma>,\\<Theta> \\<union> (\\<Union>q\\<in>Procs. \\<Union>Z. {(P q Z,\n                      Call q, Q q Z,A q Z)})\\<turnstile>\\<^bsub>/F\\<^esub>\n              (P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\" \n  proof (intro ballI allI)\n    fix p Z\n    assume \"p \\<in> Procs\"\n    with hyp\n    have hyp': \"\\<And> \\<tau>. \n           \\<Gamma>,\\<Theta> \\<union> (\\<Union>q\\<in>Procs. \\<Union>Z. {(P q Z \\<inter> {s. ((s, q), \\<tau>, p) \\<in> r},\n                      Call q, Q q Z, A q Z)})\\<turnstile>\\<^bsub>/F\\<^esub>\n              ({\\<tau>} \\<inter> P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n      by blast\n    have \"\\<forall>\\<tau>. \n           \\<Gamma>,\\<Theta> \\<union> (\\<Union>q\\<in>Procs. \\<Union>Z. {(P q Z,\n                      Call q, Q q Z,A q Z)})\\<turnstile>\\<^bsub>/F\\<^esub>\n              ({\\<tau>} \\<inter> P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n      (is \"\\<forall>\\<tau>. \\<Gamma>,?\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\")\n    proof (rule allI, rule WeakenContext [OF hyp'],clarify)\n      fix \\<tau> P' c Q' A'\n      assume \"(P', c, Q', A') \\<in> \\<Theta> \\<union>\n         (\\<Union>q\\<in>Procs.\n             \\<Union>Z. {(P q Z \\<inter> {s. ((s, q), \\<tau>, p) \\<in> r},\n                  Call q, Q q Z,\n                  A q Z)})\" (is \"(P', c, Q', A') \\<in> \\<Theta> \\<union> ?Spec\")\n      then show \"\\<Gamma>,?\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> P' c Q',A'\"\n      proof (cases rule: UnE [consumes 1])\n        assume \"(P',c,Q',A') \\<in> \\<Theta>\" \n        then show ?thesis\n          by (blast intro: HoarePartialDef.Asm)\n      next\n        assume \"(P',c,Q',A') \\<in> ?Spec\" \n        then show ?thesis\n        proof (clarify)\n          fix q Z\n          assume q: \"q \\<in> Procs\"\n          show \"\\<Gamma>,?\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> (P q Z \\<inter> {s. ((s, q), \\<tau>, p) \\<in> r}) \n                         Call  q \n                        (Q q Z),(A q Z)\"\n          proof -\n            from q\n            have \"\\<Gamma>,?\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> (P q Z) Call q (Q q Z),(A q Z)\"\n              by - (rule HoarePartialDef.Asm,blast)\n            thus ?thesis\n              by (rule HoarePartialDef.conseqPre) blast\n          qed\n        qed\n      qed\n    qed\n    then show \"\\<Gamma>,\\<Theta> \\<union> (\\<Union>q\\<in>Procs. \\<Union>Z. {(P q Z, Call q, Q q Z,A q Z)})\n                \\<turnstile>\\<^bsub>/F\\<^esub> (P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n      by (rule HoarePartialDef.conseq) blast\n  qed\n  thus ?case\n    by - (rule hoarep.CallRec)*)\nnext\n  case DynCom thus ?case by (blast intro: hoarep.DynCom)\nnext\n  case Throw thus ?case by - (rule hoarep.Throw)\nnext\n  case Catch thus ?case by - (rule hoarep.Catch)\nnext\n  case Conseq thus ?case by - (rule hoarep.Conseq,blast)\nnext\n  case Asm thus ?case by (rule HoarePartialDef.Asm)\nnext\n  case (ExFalso \\<Theta> F P c Q A)\n  assume \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  hence \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n    oops\n\n\nlemma hoaret_augment_context: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P p Q,A\"\n  shows \"\\<And>\\<Theta>'. \\<Theta> \\<subseteq> \\<Theta>' \\<Longrightarrow> \\<Gamma>,\\<Theta>'\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P p Q,A\"\nusing deriv\nproof (induct)\n  case (CallRec P p Q A Specs r Specs_wf \\<Theta> F \\<Theta>')\n  have aug: \"\\<Theta> \\<subseteq> \\<Theta>'\" by fact\n  then\n  have h: \"\\<And>\\<tau> p. \\<Theta> \\<union> Specs_wf p \\<tau>\n       \\<subseteq> \\<Theta>' \\<union> Specs_wf p \\<tau>\"\n    by blast\n  have \"\\<forall>(P,p,Q,A)\\<in>Specs. p \\<in> dom \\<Gamma> \\<and>\n     (\\<forall>\\<tau>. \\<Gamma>,\\<Theta> \\<union> Specs_wf p \\<tau>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> p)) Q,A \\<and>\n           (\\<forall>x. \\<Theta> \\<union> Specs_wf p \\<tau>\n                 \\<subseteq> x \\<longrightarrow>\n                 \\<Gamma>,x\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> p)) Q,A))\" by fact\n  hence \"\\<forall>(P,p,Q,A)\\<in>Specs. p \\<in> dom \\<Gamma> \\<and> \n         (\\<forall>\\<tau>. \\<Gamma>,\\<Theta>'\\<union> Specs_wf p \\<tau> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> p)) Q,A)\"\n    apply (clarify)\n    apply (rename_tac P p Q A)\n    apply (drule (1) bspec)\n    apply (clarsimp)\n    apply (erule_tac x=\\<tau> in allE)\n    apply clarify\n    apply (erule_tac x=\"\\<Theta>' \\<union> Specs_wf p \\<tau>\" in allE)\n    apply (insert aug)\n    apply auto\n    done\n  with CallRec show ?case by - (rule hoaret.CallRec)\nnext\n  case DynCom thus ?case by (blast intro: hoaret.DynCom)\nnext\n  case (Conseq P \\<Theta> F c Q A \\<Theta>')\n  from Conseq\n  have \"\\<forall>s \\<in> P. (\\<exists>P' Q' A'. (\\<Gamma>,\\<Theta>' \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A') \\<and> s \\<in> P'\\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A)\"\n    by blast\n  with Conseq show ?case by - (rule hoaret.Conseq)\nnext\n  case (ExFalso \\<Theta> F P  c Q A \\<Theta>')\n  have \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" \"\\<not> \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" \"\\<Theta> \\<subseteq> \\<Theta>'\"  by fact+\n  then show ?case\n    by (fastforce intro: hoaret.ExFalso simp add: cvalidt_def)\nqed (blast intro: hoaret.intros)+\n\nsubsection {* Some Derived Rules *}\n\n\nlemma  Conseq': \"\\<forall>s. s \\<in> P \\<longrightarrow> \n            (\\<exists>P' Q' A'. \n              (\\<forall> Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z)) \\<and>\n                    (\\<exists>Z. s \\<in> P' Z \\<and> (Q' Z \\<subseteq> Q) \\<and> (A' Z \\<subseteq> A)))\n           \\<Longrightarrow>\n           \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\napply (rule Conseq)\napply (rule ballI)\napply (erule_tac x=s in allE)\napply (clarify)\napply (rule_tac x=\"P' Z\" in exI)\napply (rule_tac x=\"Q' Z\" in exI)\napply (rule_tac x=\"A' Z\" in exI)\napply blast\ndone\n\nlemma conseq:\"\\<lbrakk>\\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z);\n              \\<forall>s. s \\<in> P \\<longrightarrow> (\\<exists> Z. s\\<in>P' Z \\<and> (Q' Z \\<subseteq> Q)\\<and> (A' Z \\<subseteq> A))\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule Conseq) blast\n\ntheorem conseqPrePost: \n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A' \\<Longrightarrow> P \\<subseteq> P' \\<Longrightarrow>  Q' \\<subseteq> Q \\<Longrightarrow> A' \\<subseteq> A \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule conseq [where ?P'=\"\\<lambda>Z. P'\" and ?Q'=\"\\<lambda>Z. Q'\"]) auto\n\nlemma conseqPre: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q,A \\<Longrightarrow> P \\<subseteq> P' \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nby (rule conseq) auto\n\nlemma conseqPost: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q',A'\\<Longrightarrow> Q' \\<subseteq> Q \\<Longrightarrow> A' \\<subseteq> A \\<Longrightarrow>   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule conseq) auto\n\n\nlemma Spec_wf_conv: \n  \"(\\<lambda>(P, q, Q, A). (P \\<inter> {s. ((s, q), \\<tau>, p) \\<in> r}, q, Q, A)) `\n                (\\<Union>p\\<in>Procs. \\<Union>Z. {(P p Z, p, Q p Z, A p Z)}) = \n        (\\<Union>q\\<in>Procs. \\<Union>Z. {(P q Z \\<inter> {s. ((s, q), \\<tau>, p) \\<in> r}, q, Q q Z, A q Z)})\"\napply (rule)\napply  fastforce\napply (fastforce simp add: image_def)\ndone\n\nlemma CallRec': \n  \"\\<lbrakk>p\\<in>Procs; Procs \\<subseteq> dom \\<Gamma>;\n    wf r; \n   \\<forall>p\\<in>Procs. \\<forall>\\<tau> Z. \n   \\<Gamma>,\\<Theta>\\<union>(\\<Union>q\\<in>Procs. \\<Union>Z. \n    {((P q Z) \\<inter> {s. ((s,q),(\\<tau>,p)) \\<in> r},q,Q q Z,(A q Z))})\n     \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> (P p Z)) (the (\\<Gamma> p)) (Q p Z),(A p Z)\\<rbrakk>\n   \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P p Z) (Call p) (Q p Z),(A p Z)\"\napply (rule CallRec [where Specs=\"\\<Union>p\\<in>Procs. \\<Union>Z. {((P p Z),p,Q p Z,A p Z)}\" and\n         r=r])\napply    blast\napply   assumption\napply  (rule refl)\napply (clarsimp)\napply (rename_tac p')\napply (rule conjI)\napply  blast\napply (intro allI)\napply (rename_tac Z \\<tau>)\napply (drule_tac x=p' in bspec, assumption)\napply (erule_tac x=\\<tau> in allE)\napply (erule_tac x=Z in allE)\napply (fastforce simp add: Spec_wf_conv)\ndone\n\nend\n\n", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/c-parser/Simpl/HoareTotalDef.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5350984286266116, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.27381875107934384}}
{"text": "(*<*)\n(*\n * Knowledge-based programs.\n * (C)opyright 2011, Peter Gammie, peteg42 at gmail.com.\n * License: BSD\n *)\n\ntheory Extra\nimports\n  Main\n  Equiv_Relations\n  \"~~/src/HOL/Library/Option_ord\"\n  \"~~/src/HOL/Library/Product_Lexorder\"\nbegin\n\n(* Extra lemmas that are not noteworthy. *)\n\nlemma relation_mono:\n  \"\\<lbrakk> A \\<subseteq> C; B \\<subseteq> D \\<rbrakk> \\<Longrightarrow> A \\<times> B \\<subseteq> C \\<times> D\"\n  by bestsimp\n\nlemma quotientI2:\n  \"\\<lbrakk> x \\<in> A; X = r `` {x} \\<rbrakk> \\<Longrightarrow> X \\<in> A // r\"\n  by (simp add: quotientI)\n\n(*\n\nConcretely enumerate all the agent action functions. Can't be too\nabstract here as we want extensionality.\n\nIntroduced in the clock view.\n\n*)\n\ndefinition\n  listToFun :: \"('a \\<times> 'b list) list \\<Rightarrow> ('a \\<Rightarrow> 'b) list\"\nwhere\n  \"listToFun xs \\<equiv> foldr (\\<lambda>(a, acts) M. [ m(a := act) . m \\<leftarrow> M, act \\<leftarrow> acts ])\n                     xs\n                     [(\\<lambda>_. undefined)]\"\n\nlemma listToFun_futz:\n  \"\\<lbrakk> M \\<in> set (listToFun xs); x \\<in> fst ` set xs \\<rbrakk>\n     \\<Longrightarrow> M x \\<in> { y |y ys. (x, ys) \\<in> set xs \\<and> y \\<in> set ys}\"\n  unfolding listToFun_def\n  apply (induct xs arbitrary: M)\n   apply (simp_all add: split_def)\n  apply (case_tac a)\n  apply clarsimp\n  apply auto\n  done\n\nlemma distinct_map_fst:\n  \"\\<lbrakk> x \\<notin> fst ` set xs; distinct (map fst xs) \\<rbrakk> \\<Longrightarrow> (x, y) \\<notin> set xs\"\n  by (induct xs) auto\n\nlemma listToFun_futz_rev:\n  \"\\<lbrakk> \\<And>x. M x \\<in> (if x \\<in> fst ` set xs then { y |y ys. (x, ys) \\<in> set xs \\<and> y \\<in> set ys} else {undefined}); distinct (map fst xs) \\<rbrakk>\n      \\<Longrightarrow> M \\<in> set (listToFun xs)\"\nproof(induct xs arbitrary: M)\n  case Nil thus ?case\n    unfolding listToFun_def by simp\nnext\n  case (Cons x xs)\n  let ?M' = \"M(fst x := undefined)\"\n  have M': \"?M' \\<in> set (listToFun xs)\"\n    apply (rule Cons.hyps)\n     prefer 2\n     using Cons(3)\n     apply simp\n    apply (case_tac \"xa = fst x\")\n     using Cons(3)\n     apply simp\n    apply (case_tac \"xa \\<in> fst ` set xs\")\n     apply (cut_tac x=xa in Cons(2))\n     apply (cases x)\n     apply auto[1]\n    apply (cut_tac x=xa in Cons(2))\n    apply simp\n    done\n  then show ?case\n    unfolding listToFun_def\n    apply (cases x)\n    apply simp\n    apply (rule bexI[where x=\"?M'\"])\n     apply simp_all\n    apply (rule_tac x=\"M a\" in image_eqI)\n     apply simp\n    apply (cut_tac x=a in Cons(2))\n    using Cons(3)\n    apply clarsimp\n    apply (erule disjE)\n     apply simp\n    apply (auto dest: distinct_map_fst)\n    done\nqed\n\ndefinition\n  listToFuns :: \"('a \\<Rightarrow> 'b list) \\<Rightarrow> 'a list \\<Rightarrow> ('a \\<Rightarrow> 'b) list\"\nwhere\n  \"listToFuns f \\<equiv> listToFun \\<circ> map (\\<lambda>x. (x, f x))\"\n\nlemma map_id_clunky:\n  \"set xs = UNIV \\<Longrightarrow> x \\<in> fst ` set (map (\\<lambda>x. (x, f x)) xs)\"\n  apply (simp only: set_map[symmetric] map_map)\n  apply simp\n  done\n\n(*\n\nThe main result is that we can freely move between representations.\n\n*)\n\nlemma listToFuns_ext:\n  assumes xs: \"set xs = UNIV\"\n  assumes d: \"distinct xs\"\n  shows \"g \\<in> set (listToFuns f xs) \\<longleftrightarrow> (\\<forall>x. g x \\<in> set (f x))\"\n  unfolding listToFuns_def\n  apply simp\n  apply rule\n   apply clarsimp\n   apply (cut_tac x=x in listToFun_futz[where M=g, OF _ map_id_clunky[OF xs]])\n    apply simp\n   apply clarsimp\n  apply (rule listToFun_futz_rev)\n   using map_id_clunky[OF xs]\n   apply auto[1]\n   apply (rule_tac x=\"f xa\" in exI)\n    apply simp\n   apply simp\n  using d\n  apply (simp add: distinct_map)\n  apply (auto intro: inj_onI)\n  done\n\nlemma listToFun_splice:\n  assumes xs: \"set xs = UNIV\"\n  assumes d: \"distinct xs\"\n  assumes g: \"g \\<in> set (listToFuns f xs)\"\n  assumes h: \"h \\<in> set (listToFuns f xs)\"\n  shows \"g(x := h x) \\<in> set (listToFuns f xs)\"\n  using g h by (auto iff: listToFuns_ext[OF xs d])\n(*<*)\n\nend\n(*>*)\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/KBPs/Extra.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.2738187510793438}}
{"text": "(*  Title:      HOL/HOLCF/IOA/CompoExecs.thy\n    Author:     Olaf Müller\n*)\n\nsection \\<open>Compositionality on Execution level\\<close>\n\ntheory CompoExecs\nimports Traces\nbegin\n\ndefinition ProjA2 :: \"('a, 's \\<times> 't) pairs \\<rightarrow> ('a, 's) pairs\"\n  where \"ProjA2 = Map (\\<lambda>x. (fst x, fst (snd x)))\"\n\ndefinition ProjA :: \"('a, 's \\<times> 't) execution \\<Rightarrow> ('a, 's) execution\"\n  where \"ProjA ex = (fst (fst ex), ProjA2 \\<cdot> (snd ex))\"\n\ndefinition ProjB2 :: \"('a, 's \\<times> 't) pairs \\<rightarrow> ('a, 't) pairs\"\n  where \"ProjB2 = Map (\\<lambda>x. (fst x, snd (snd x)))\"\n\ndefinition ProjB :: \"('a, 's \\<times> 't) execution \\<Rightarrow> ('a, 't) execution\"\n  where \"ProjB ex = (snd (fst ex), ProjB2 \\<cdot> (snd ex))\"\n\ndefinition Filter_ex2 :: \"'a signature \\<Rightarrow> ('a, 's) pairs \\<rightarrow> ('a, 's) pairs\"\n  where \"Filter_ex2 sig = Filter (\\<lambda>x. fst x \\<in> actions sig)\"\n\ndefinition Filter_ex :: \"'a signature \\<Rightarrow> ('a, 's) execution \\<Rightarrow> ('a, 's) execution\"\n  where \"Filter_ex sig ex = (fst ex, Filter_ex2 sig \\<cdot> (snd ex))\"\n\ndefinition stutter2 :: \"'a signature \\<Rightarrow> ('a, 's) pairs \\<rightarrow> ('s \\<Rightarrow> tr)\"\n  where \"stutter2 sig =\n    (fix \\<cdot>\n      (LAM h ex.\n        (\\<lambda>s.\n          case ex of\n            nil \\<Rightarrow> TT\n          | x ## xs \\<Rightarrow>\n              (flift1\n                (\\<lambda>p.\n                  (If Def (fst p \\<notin> actions sig) then Def (s = snd p) else TT)\n                  andalso (h\\<cdot>xs) (snd p)) \\<cdot> x))))\"\n\ndefinition stutter :: \"'a signature \\<Rightarrow> ('a, 's) execution \\<Rightarrow> bool\"\n  where \"stutter sig ex \\<longleftrightarrow> (stutter2 sig \\<cdot> (snd ex)) (fst ex) \\<noteq> FF\"\n\ndefinition par_execs ::\n  \"('a, 's) execution_module \\<Rightarrow> ('a, 't) execution_module \\<Rightarrow> ('a, 's \\<times> 't) execution_module\"\n  where \"par_execs ExecsA ExecsB =\n    (let\n      exA = fst ExecsA; sigA = snd ExecsA;\n      exB = fst ExecsB; sigB = snd ExecsB\n     in\n       ({ex. Filter_ex sigA (ProjA ex) \\<in> exA} \\<inter>\n        {ex. Filter_ex sigB (ProjB ex) \\<in> exB} \\<inter>\n        {ex. stutter sigA (ProjA ex)} \\<inter>\n        {ex. stutter sigB (ProjB ex)} \\<inter>\n        {ex. Forall (\\<lambda>x. fst x \\<in> actions sigA \\<union> actions sigB) (snd ex)},\n        asig_comp sigA sigB))\"\n\n\nlemmas [simp del] = split_paired_All\n\n\nsection \\<open>Recursive equations of operators\\<close>\n\nsubsection \\<open>\\<open>ProjA2\\<close>\\<close>\n\nlemma ProjA2_UU: \"ProjA2 \\<cdot> UU = UU\"\n  by (simp add: ProjA2_def)\n\nlemma ProjA2_nil: \"ProjA2 \\<cdot> nil = nil\"\n  by (simp add: ProjA2_def)\n\nlemma ProjA2_cons: \"ProjA2 \\<cdot> ((a, t) \\<leadsto> xs) = (a, fst t) \\<leadsto> ProjA2 \\<cdot> xs\"\n  by (simp add: ProjA2_def)\n\n\nsubsection \\<open>\\<open>ProjB2\\<close>\\<close>\n\nlemma ProjB2_UU: \"ProjB2 \\<cdot> UU = UU\"\n  by (simp add: ProjB2_def)\n\nlemma ProjB2_nil: \"ProjB2 \\<cdot> nil = nil\"\n  by (simp add: ProjB2_def)\n\nlemma ProjB2_cons: \"ProjB2 \\<cdot> ((a, t) \\<leadsto> xs) = (a, snd t) \\<leadsto> ProjB2 \\<cdot> xs\"\n  by (simp add: ProjB2_def)\n\n\nsubsection \\<open>\\<open>Filter_ex2\\<close>\\<close>\n\nlemma Filter_ex2_UU: \"Filter_ex2 sig \\<cdot> UU = UU\"\n  by (simp add: Filter_ex2_def)\n\nlemma Filter_ex2_nil: \"Filter_ex2 sig \\<cdot> nil = nil\"\n  by (simp add: Filter_ex2_def)\n\nlemma Filter_ex2_cons:\n  \"Filter_ex2 sig \\<cdot> (at \\<leadsto> xs) =\n    (if fst at \\<in> actions sig\n     then at \\<leadsto> (Filter_ex2 sig \\<cdot> xs)\n     else Filter_ex2 sig \\<cdot> xs)\"\n  by (simp add: Filter_ex2_def)\n\n\nsubsection \\<open>\\<open>stutter2\\<close>\\<close>\n\nlemma stutter2_unfold:\n  \"stutter2 sig =\n    (LAM ex.\n      (\\<lambda>s.\n        case ex of\n          nil \\<Rightarrow> TT\n        | x ## xs \\<Rightarrow>\n            (flift1\n              (\\<lambda>p.\n                (If Def (fst p \\<notin> actions sig) then Def (s= snd p) else TT)\n                andalso (stutter2 sig\\<cdot>xs) (snd p)) \\<cdot> x)))\"\n  apply (rule trans)\n  apply (rule fix_eq2)\n  apply (simp only: stutter2_def)\n  apply (rule beta_cfun)\n  apply (simp add: flift1_def)\n  done\n\nlemma stutter2_UU: \"(stutter2 sig \\<cdot> UU) s = UU\"\n  apply (subst stutter2_unfold)\n  apply simp\n  done\n\nlemma stutter2_nil: \"(stutter2 sig \\<cdot> nil) s = TT\"\n  apply (subst stutter2_unfold)\n  apply simp\n  done\n\nlemma stutter2_cons:\n  \"(stutter2 sig \\<cdot> (at \\<leadsto> xs)) s =\n    ((if fst at \\<notin> actions sig then Def (s = snd at) else TT)\n      andalso (stutter2 sig \\<cdot> xs) (snd at))\"\n  apply (rule trans)\n  apply (subst stutter2_unfold)\n  apply (simp add: Consq_def flift1_def If_and_if)\n  apply simp\n  done\n\ndeclare stutter2_UU [simp] stutter2_nil [simp] stutter2_cons [simp]\n\n\nsubsection \\<open>\\<open>stutter\\<close>\\<close>\n\nlemma stutter_UU: \"stutter sig (s, UU)\"\n  by (simp add: stutter_def)\n\nlemma stutter_nil: \"stutter sig (s, nil)\"\n  by (simp add: stutter_def)\n\nlemma stutter_cons:\n  \"stutter sig (s, (a, t) \\<leadsto> ex) \\<longleftrightarrow> (a \\<notin> actions sig \\<longrightarrow> (s = t)) \\<and> stutter sig (t, ex)\"\n  by (simp add: stutter_def)\n\ndeclare stutter2_UU [simp del] stutter2_nil [simp del] stutter2_cons [simp del]\n\nlemmas compoex_simps = ProjA2_UU ProjA2_nil ProjA2_cons\n  ProjB2_UU ProjB2_nil ProjB2_cons\n  Filter_ex2_UU Filter_ex2_nil Filter_ex2_cons\n  stutter_UU stutter_nil stutter_cons\n\ndeclare compoex_simps [simp]\n\n\nsection \\<open>Compositionality on execution level\\<close>\n\nlemma lemma_1_1a:\n  \\<comment> \\<open>\\<open>is_ex_fr\\<close> propagates from \\<open>A \\<parallel> B\\<close> to projections \\<open>A\\<close> and \\<open>B\\<close>\\<close>\n  \"\\<forall>s. is_exec_frag (A \\<parallel> B) (s, xs) \\<longrightarrow>\n    is_exec_frag A (fst s, Filter_ex2 (asig_of A) \\<cdot> (ProjA2 \\<cdot> xs)) \\<and>\n    is_exec_frag B (snd s, Filter_ex2 (asig_of B) \\<cdot> (ProjB2 \\<cdot> xs))\"\n  apply (pair_induct xs simp: is_exec_frag_def)\n  text \\<open>main case\\<close>\n  apply (auto simp add: trans_of_defs2)\n  done\n\nlemma lemma_1_1b:\n  \\<comment> \\<open>\\<open>is_ex_fr (A \\<parallel> B)\\<close> implies stuttering on projections\\<close>\n  \"\\<forall>s. is_exec_frag (A \\<parallel> B) (s, xs) \\<longrightarrow>\n    stutter (asig_of A) (fst s, ProjA2 \\<cdot> xs) \\<and>\n    stutter (asig_of B) (snd s, ProjB2 \\<cdot> xs)\"\n  apply (pair_induct xs simp: stutter_def is_exec_frag_def)\n  text \\<open>main case\\<close>\n  apply (auto simp add: trans_of_defs2)\n  done\n\nlemma lemma_1_1c:\n  \\<comment> \\<open>Executions of \\<open>A \\<parallel> B\\<close> have only \\<open>A\\<close>- or \\<open>B\\<close>-actions\\<close>\n  \"\\<forall>s. is_exec_frag (A \\<parallel> B) (s, xs) \\<longrightarrow> Forall (\\<lambda>x. fst x \\<in> act (A \\<parallel> B)) xs\"\n  apply (pair_induct xs simp: Forall_def sforall_def is_exec_frag_def)\n  text \\<open>main case\\<close>\n  apply auto\n  apply (simp add: trans_of_defs2 actions_asig_comp asig_of_par)\n  done\n\nlemma lemma_1_2:\n  \\<comment> \\<open>\\<open>ex A\\<close>, \\<open>exB\\<close>, stuttering and forall \\<open>a \\<in> A \\<parallel> B\\<close> implies \\<open>ex (A \\<parallel> B)\\<close>\\<close>\n  \"\\<forall>s.\n    is_exec_frag A (fst s, Filter_ex2 (asig_of A) \\<cdot> (ProjA2 \\<cdot> xs)) \\<and>\n    is_exec_frag B (snd s, Filter_ex2 (asig_of B) \\<cdot> (ProjB2 \\<cdot> xs)) \\<and>\n    stutter (asig_of A) (fst s, ProjA2 \\<cdot> xs) \\<and>\n    stutter (asig_of B) (snd s, ProjB2 \\<cdot> xs) \\<and>\n    Forall (\\<lambda>x. fst x \\<in> act (A \\<parallel> B)) xs \\<longrightarrow>\n    is_exec_frag (A \\<parallel> B) (s, xs)\"\n  apply (pair_induct xs simp: Forall_def sforall_def is_exec_frag_def stutter_def)\n  apply (auto simp add: trans_of_defs1 actions_asig_comp asig_of_par)\n  done\n\ntheorem compositionality_ex:\n  \"ex \\<in> executions (A \\<parallel> B) \\<longleftrightarrow>\n    Filter_ex (asig_of A) (ProjA ex) \\<in> executions A \\<and>\n    Filter_ex (asig_of B) (ProjB ex) \\<in> executions B \\<and>\n    stutter (asig_of A) (ProjA ex) \\<and>\n    stutter (asig_of B) (ProjB ex) \\<and>\n    Forall (\\<lambda>x. fst x \\<in> act (A \\<parallel> B)) (snd ex)\"\n  apply (simp add: executions_def ProjB_def Filter_ex_def ProjA_def starts_of_par)\n  apply (pair ex)\n  apply (rule iffI)\n  text \\<open>\\<open>\\<Longrightarrow>\\<close>\\<close>\n  apply (erule conjE)+\n  apply (simp add: lemma_1_1a lemma_1_1b lemma_1_1c)\n  text \\<open>\\<open>\\<Longleftarrow>\\<close>\\<close>\n  apply (erule conjE)+\n  apply (simp add: lemma_1_2)\n  done\n\ntheorem compositionality_ex_modules: \"Execs (A \\<parallel> B) = par_execs (Execs A) (Execs B)\"\n  apply (unfold Execs_def par_execs_def)\n  apply (simp add: asig_of_par)\n  apply (rule set_eqI)\n  apply (simp add: compositionality_ex actions_of_par)\n  done\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/HOLCF/IOA/CompoExecs.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526514141571, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.273802048633569}}
{"text": "(*  Title:      HOL/TLA/Memory/Memory.thy\n    Author:     Stephan Merz, University of Munich\n*)\n\nsection \\<open>RPC-Memory example: Memory specification\\<close>\n\ntheory Memory\nimports MemoryParameters ProcedureInterface\nbegin\n\ntype_synonym memChType = \"(memOp, Vals) channel\"\ntype_synonym memType = \"(Locs \\<Rightarrow> Vals) stfun\"  (* intention: MemLocs \\<Rightarrow> MemVals *)\ntype_synonym resType = \"(PrIds \\<Rightarrow> Vals) stfun\"\n\n\n(* state predicates *)\n\ndefinition MInit :: \"memType \\<Rightarrow> Locs \\<Rightarrow> stpred\"\n  where \"MInit mm l == PRED mm!l = #InitVal\"\n\ndefinition PInit :: \"resType \\<Rightarrow> PrIds \\<Rightarrow> stpred\"\n  where \"PInit rs p == PRED rs!p = #NotAResult\"\n\n\n(* auxiliary predicates: is there a pending read/write request for\n   some process id and location/value? *)\n\ndefinition RdRequest :: \"memChType \\<Rightarrow> PrIds \\<Rightarrow> Locs \\<Rightarrow> stpred\"\n  where \"RdRequest ch p l == PRED Calling ch p \\<and> (arg<ch!p> = #(read l))\"\n\ndefinition WrRequest :: \"memChType \\<Rightarrow> PrIds \\<Rightarrow> Locs \\<Rightarrow> Vals \\<Rightarrow> stpred\"\n  where \"WrRequest ch p l v == PRED Calling ch p \\<and> (arg<ch!p> = #(write l v))\"\n\n\n(* actions *)\n\n(* a read that doesn't raise BadArg *)\ndefinition GoodRead :: \"memType \\<Rightarrow> resType \\<Rightarrow> PrIds \\<Rightarrow> Locs \\<Rightarrow> action\"\n  where \"GoodRead mm rs p l == ACT #l \\<in> #MemLoc \\<and> ((rs!p)$ = $(mm!l))\"\n\n(* a read that raises BadArg *)\ndefinition BadRead :: \"memType \\<Rightarrow> resType \\<Rightarrow> PrIds \\<Rightarrow> Locs \\<Rightarrow> action\"\n  where \"BadRead mm rs p l == ACT #l \\<notin> #MemLoc \\<and> ((rs!p)$ = #BadArg)\"\n\n(* the read action with l visible *)\ndefinition ReadInner :: \"memChType \\<Rightarrow> memType \\<Rightarrow> resType \\<Rightarrow> PrIds \\<Rightarrow> Locs \\<Rightarrow> action\"\n  where \"ReadInner ch mm rs p l == ACT\n    $(RdRequest ch p l)\n    \\<and> (GoodRead mm rs p l  \\<or>  BadRead mm rs p l)\n    \\<and> unchanged (rtrner ch ! p)\"\n\n(* the read action with l quantified *)\ndefinition Read :: \"memChType \\<Rightarrow> memType \\<Rightarrow> resType \\<Rightarrow> PrIds \\<Rightarrow> action\"\n  where \"Read ch mm rs p == ACT (\\<exists>l. ReadInner ch mm rs p l)\"\n\n(* similar definitions for the write action *)\ndefinition GoodWrite :: \"memType \\<Rightarrow> resType \\<Rightarrow> PrIds \\<Rightarrow> Locs \\<Rightarrow> Vals \\<Rightarrow> action\"\n  where \"GoodWrite mm rs p l v ==\n    ACT #l \\<in> #MemLoc \\<and> #v \\<in> #MemVal\n      \\<and> ((mm!l)$ = #v) \\<and> ((rs!p)$ = #OK)\"\n\ndefinition BadWrite :: \"memType \\<Rightarrow> resType \\<Rightarrow> PrIds \\<Rightarrow> Locs \\<Rightarrow> Vals \\<Rightarrow> action\"\n  where \"BadWrite mm rs p l v == ACT\n    \\<not> (#l \\<in> #MemLoc \\<and> #v \\<in> #MemVal)\n    \\<and> ((rs!p)$ = #BadArg) \\<and> unchanged (mm!l)\"\n\ndefinition WriteInner :: \"memChType \\<Rightarrow> memType \\<Rightarrow> resType \\<Rightarrow> PrIds \\<Rightarrow> Locs \\<Rightarrow> Vals \\<Rightarrow> action\"\n  where \"WriteInner ch mm rs p l v == ACT\n    $(WrRequest ch p l v)\n    \\<and> (GoodWrite mm rs p l v  \\<or>  BadWrite mm rs p l v)\n    \\<and> unchanged (rtrner ch ! p)\"\n\ndefinition Write :: \"memChType \\<Rightarrow> memType \\<Rightarrow> resType \\<Rightarrow> PrIds \\<Rightarrow> Locs \\<Rightarrow> action\"\n  where \"Write ch mm rs p l == ACT (\\<exists>v. WriteInner ch mm rs p l v)\"\n\n\n(* the return action *)\ndefinition MemReturn :: \"memChType \\<Rightarrow> resType \\<Rightarrow> PrIds \\<Rightarrow> action\"\n  where \"MemReturn ch rs p == ACT\n   (   ($(rs!p) \\<noteq> #NotAResult)\n    \\<and> ((rs!p)$ = #NotAResult)\n    \\<and> Return ch p (rs!p))\"\n\n(* the failure action of the unreliable memory *)\ndefinition MemFail :: \"memChType \\<Rightarrow> resType \\<Rightarrow> PrIds \\<Rightarrow> action\"\n  where \"MemFail ch rs p == ACT\n    $(Calling ch p)\n    \\<and> ((rs!p)$ = #MemFailure)\n    \\<and> unchanged (rtrner ch ! p)\"\n\n(* next-state relations for reliable / unreliable memory *)\ndefinition RNext :: \"memChType \\<Rightarrow> memType \\<Rightarrow> resType \\<Rightarrow> PrIds \\<Rightarrow> action\"\n  where \"RNext ch mm rs p == ACT\n   (  Read ch mm rs p\n    \\<or> (\\<exists>l. Write ch mm rs p l)\n    \\<or> MemReturn ch rs p)\"\n\ndefinition UNext :: \"memChType \\<Rightarrow> memType \\<Rightarrow> resType \\<Rightarrow> PrIds \\<Rightarrow> action\"\n  where \"UNext ch mm rs p == ACT (RNext ch mm rs p \\<or> MemFail ch rs p)\"\n\n\n(* temporal formulas *)\n\ndefinition RPSpec :: \"memChType \\<Rightarrow> memType \\<Rightarrow> resType \\<Rightarrow> PrIds \\<Rightarrow> temporal\"\n  where \"RPSpec ch mm rs p == TEMP\n    Init(PInit rs p)\n    \\<and> \\<box>[ RNext ch mm rs p ]_(rtrner ch ! p, rs!p)\n    \\<and> WF(RNext ch mm rs p)_(rtrner ch ! p, rs!p)\n    \\<and> WF(MemReturn ch rs p)_(rtrner ch ! p, rs!p)\"\n\ndefinition UPSpec :: \"memChType \\<Rightarrow> memType \\<Rightarrow> resType \\<Rightarrow> PrIds \\<Rightarrow> temporal\"\n  where \"UPSpec ch mm rs p == TEMP\n    Init(PInit rs p)\n    \\<and> \\<box>[ UNext ch mm rs p ]_(rtrner ch ! p, rs!p)\n    \\<and> WF(RNext ch mm rs p)_(rtrner ch ! p, rs!p)\n    \\<and> WF(MemReturn ch rs p)_(rtrner ch ! p, rs!p)\"\n\ndefinition MSpec :: \"memChType \\<Rightarrow> memType \\<Rightarrow> resType \\<Rightarrow> Locs \\<Rightarrow> temporal\"\n  where \"MSpec ch mm rs l == TEMP\n    Init(MInit mm l)\n    \\<and> \\<box>[ \\<exists>p. Write ch mm rs p l ]_(mm!l)\"\n\ndefinition IRSpec :: \"memChType \\<Rightarrow> memType \\<Rightarrow> resType \\<Rightarrow> temporal\"\n  where \"IRSpec ch mm rs == TEMP\n    (\\<forall>p. RPSpec ch mm rs p)\n    \\<and> (\\<forall>l. #l \\<in> #MemLoc \\<longrightarrow> MSpec ch mm rs l)\"\n\ndefinition IUSpec :: \"memChType \\<Rightarrow> memType \\<Rightarrow> resType \\<Rightarrow> temporal\"\n  where \"IUSpec ch mm rs == TEMP\n    (\\<forall>p. UPSpec ch mm rs p)\n    \\<and> (\\<forall>l. #l \\<in> #MemLoc \\<longrightarrow> MSpec ch mm rs l)\"\n\ndefinition RSpec :: \"memChType \\<Rightarrow> resType \\<Rightarrow> temporal\"\n  where \"RSpec ch rs == TEMP (\\<exists>\\<exists>mm. IRSpec ch mm rs)\"\n\ndefinition USpec :: \"memChType \\<Rightarrow> temporal\"\n  where \"USpec ch == TEMP (\\<exists>\\<exists>mm rs. IUSpec ch mm rs)\"\n\n(* memory invariant: in the paper, the invariant is hidden in the definition of\n   the predicate S used in the implementation proof, but it is easier to verify\n   at this level. *)\ndefinition MemInv :: \"memType \\<Rightarrow> Locs \\<Rightarrow> stpred\"\n  where \"MemInv mm l == PRED  #l \\<in> #MemLoc \\<longrightarrow> mm!l \\<in> #MemVal\"\n\nlemmas RM_action_defs =\n  MInit_def PInit_def RdRequest_def WrRequest_def MemInv_def\n  GoodRead_def BadRead_def ReadInner_def Read_def\n  GoodWrite_def BadWrite_def WriteInner_def Write_def\n  MemReturn_def RNext_def\n\nlemmas UM_action_defs = RM_action_defs MemFail_def UNext_def\n\nlemmas RM_temp_defs = RPSpec_def MSpec_def IRSpec_def\nlemmas UM_temp_defs = UPSpec_def MSpec_def IUSpec_def\n\n\n(* The reliable memory is an implementation of the unreliable one *)\nlemma ReliableImplementsUnReliable: \"\\<turnstile> IRSpec ch mm rs \\<longrightarrow> IUSpec ch mm rs\"\n  by (force simp: UNext_def UPSpec_def IUSpec_def RM_temp_defs elim!: STL4E [temp_use] squareE)\n\n(* The memory spec implies the memory invariant *)\nlemma MemoryInvariant: \"\\<turnstile> MSpec ch mm rs l \\<longrightarrow> \\<box>(MemInv mm l)\"\n  by (auto_invariant simp: RM_temp_defs RM_action_defs)\n\n(* The invariant is trivial for non-locations *)\nlemma NonMemLocInvariant: \"\\<turnstile> #l \\<notin> #MemLoc \\<longrightarrow> \\<box>(MemInv mm l)\"\n  by (auto simp: MemInv_def intro!: necT [temp_use])\n\nlemma MemoryInvariantAll:\n    \"\\<turnstile> (\\<forall>l. #l \\<in> #MemLoc \\<longrightarrow> MSpec ch mm rs l) \\<longrightarrow> (\\<forall>l. \\<box>(MemInv mm l))\"\n  apply clarify\n  apply (auto elim!: MemoryInvariant [temp_use] NonMemLocInvariant [temp_use])\n  done\n\n(* The memory engages in an action for process p only if there is an\n   unanswered call from p.\n   We need this only for the reliable memory.\n*)\n\nlemma Memoryidle: \"\\<turnstile> \\<not>$(Calling ch p) \\<longrightarrow> \\<not> RNext ch mm rs p\"\n  by (auto simp: AReturn_def RM_action_defs)\n\n(* Enabledness conditions *)\n\nlemma MemReturn_change: \"\\<turnstile> MemReturn ch rs p \\<longrightarrow> <MemReturn ch rs p>_(rtrner ch ! p, rs!p)\"\n  by (force simp: MemReturn_def angle_def)\n\nlemma MemReturn_enabled: \"\\<And>p. basevars (rtrner ch ! p, rs!p) \\<Longrightarrow>\n      \\<turnstile> Calling ch p \\<and> (rs!p \\<noteq> #NotAResult)\n         \\<longrightarrow> Enabled (<MemReturn ch rs p>_(rtrner ch ! p, rs!p))\"\n  apply (tactic\n    \\<open>action_simp_tac \\<^context> [@{thm MemReturn_change} RSN (2, @{thm enabled_mono}) ] [] 1\\<close>)\n  apply (tactic\n    \\<open>action_simp_tac (\\<^context> addsimps [@{thm MemReturn_def}, @{thm AReturn_def},\n      @{thm rtrner_def}]) [exI] [@{thm base_enabled}, @{thm Pair_inject}] 1\\<close>)\n  done\n\nlemma ReadInner_enabled: \"\\<And>p. basevars (rtrner ch ! p, rs!p) \\<Longrightarrow>\n      \\<turnstile> Calling ch p \\<and> (arg<ch!p> = #(read l)) \\<longrightarrow> Enabled (ReadInner ch mm rs p l)\"\n  apply (case_tac \"l \\<in> MemLoc\")\n  apply (force simp: ReadInner_def GoodRead_def BadRead_def RdRequest_def\n    intro!: exI elim!: base_enabled [temp_use])+\n  done\n\nlemma WriteInner_enabled: \"\\<And>p. basevars (mm!l, rtrner ch ! p, rs!p) \\<Longrightarrow>\n      \\<turnstile> Calling ch p \\<and> (arg<ch!p> = #(write l v))\n         \\<longrightarrow> Enabled (WriteInner ch mm rs p l v)\"\n  apply (case_tac \"l \\<in> MemLoc \\<and> v \\<in> MemVal\")\n  apply (force simp: WriteInner_def GoodWrite_def BadWrite_def WrRequest_def\n    intro!: exI elim!: base_enabled [temp_use])+\n  done\n\nlemma ReadResult: \"\\<turnstile> Read ch mm rs p \\<and> (\\<forall>l. $(MemInv mm l)) \\<longrightarrow> (rs!p)` \\<noteq> #NotAResult\"\n  by (force simp: Read_def ReadInner_def GoodRead_def BadRead_def MemInv_def)\n\nlemma WriteResult: \"\\<turnstile> Write ch mm rs p l \\<longrightarrow> (rs!p)` \\<noteq> #NotAResult\"\n  by (auto simp: Write_def WriteInner_def GoodWrite_def BadWrite_def)\n\nlemma ReturnNotReadWrite: \"\\<turnstile> (\\<forall>l. $MemInv mm l) \\<and> MemReturn ch rs p\n         \\<longrightarrow> \\<not> Read ch mm rs p \\<and> (\\<forall>l. \\<not> Write ch mm rs p l)\"\n  by (auto simp: MemReturn_def dest!: WriteResult [temp_use] ReadResult [temp_use])\n\nlemma RWRNext_enabled: \"\\<turnstile> (rs!p = #NotAResult) \\<and> (\\<forall>l. MemInv mm l)\n         \\<and> Enabled (Read ch mm rs p \\<or> (\\<exists>l. Write ch mm rs p l))\n         \\<longrightarrow> Enabled (<RNext ch mm rs p>_(rtrner ch ! p, rs!p))\"\n  by (force simp: RNext_def angle_def elim!: enabled_mono2\n    dest: ReadResult [temp_use] WriteResult [temp_use])\n\n\n(* Combine previous lemmas: the memory can make a visible step if there is an\n   outstanding call for which no result has been produced.\n*)\nlemma RNext_enabled: \"\\<And>p. \\<forall>l. basevars (mm!l, rtrner ch!p, rs!p) \\<Longrightarrow>\n      \\<turnstile> (rs!p = #NotAResult) \\<and> Calling ch p \\<and> (\\<forall>l. MemInv mm l)\n         \\<longrightarrow> Enabled (<RNext ch mm rs p>_(rtrner ch ! p, rs!p))\"\n  apply (auto simp: enabled_disj [try_rewrite] intro!: RWRNext_enabled [temp_use])\n  apply (case_tac \"arg (ch w p)\")\n   apply (tactic \\<open>action_simp_tac (\\<^context> addsimps [@{thm Read_def},\n     temp_rewrite \\<^context> @{thm enabled_ex}]) [@{thm ReadInner_enabled}, exI] [] 1\\<close>)\n   apply (force dest: base_pair [temp_use])\n  apply (erule contrapos_np)\n  apply (tactic \\<open>action_simp_tac (\\<^context> addsimps [@{thm Write_def},\n    temp_rewrite \\<^context> @{thm enabled_ex}])\n    [@{thm WriteInner_enabled}, exI] [] 1\\<close>)\n  done\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/TLA/Memory/Memory.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5888891451980404, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.2737754889673005}}
{"text": "header {* \\isaheader{Dynamic Standard Control Dependence} *}\n\ntheory DynStandardControlDependence imports Postdomination begin\n\ncontext Postdomination begin\n\ndefinition\n  dyn_standard_control_dependence :: \"'node \\<Rightarrow> 'node \\<Rightarrow> 'edge list \\<Rightarrow> bool\"\n  (\"_ controls\\<^sub>s _ via _\" [51,0,0])\nwhere dyn_standard_control_dependence_def:\"n controls\\<^sub>s n' via as \\<equiv> \n    (\\<exists>a a' as'. (as = a#as') \\<and> (n' \\<notin> set(sourcenodes as)) \\<and> (n -as\\<rightarrow>* n') \\<and>\n                   (n' postdominates (targetnode a)) \\<and>\n                   (valid_edge a') \\<and> (sourcenode a' = n) \\<and> \n                   (\\<not> n' postdominates (targetnode a')))\"\n\n\nlemma Exit_not_dyn_standard_control_dependent:\n  assumes control:\"n controls\\<^sub>s (_Exit_) via as\" shows \"False\"\nproof -\n  from control obtain a as' where path:\"n -as\\<rightarrow>* (_Exit_)\" and as:\"as = a#as'\"\n    and pd:\"(_Exit_) postdominates (targetnode a)\" \n    by(auto simp:dyn_standard_control_dependence_def)\n  from path as have \"n -[]@a#as'\\<rightarrow>* (_Exit_)\" by simp\n  hence \"valid_edge a\" by(fastforce dest:path_split)\n  with pd show False by -(rule Exit_no_postdominator,auto)\nqed\n\n\nlemma dyn_standard_control_dependence_def_variant:\n  \"n controls\\<^sub>s n' via as = ((n -as\\<rightarrow>* n') \\<and> (n \\<noteq> n') \\<and>\n    (\\<not> n' postdominates n) \\<and> (n' \\<notin> set(sourcenodes as)) \\<and>\n  (\\<forall>n'' \\<in> set(targetnodes as). n' postdominates n''))\"\nproof\n  assume \"(n -as\\<rightarrow>* n') \\<and> (n \\<noteq> n') \\<and> (\\<not> n' postdominates n) \\<and> \n    (n' \\<notin> set(sourcenodes as)) \\<and>\n    (\\<forall>n''\\<in>set (targetnodes as). n' postdominates n'')\"\n  hence path:\"n -as\\<rightarrow>* n'\" and noteq:\"n \\<noteq> n'\"\n    and not_pd:\"\\<not> n' postdominates n\"\n    and notin:\"n' \\<notin> set(sourcenodes as)\"\n    and all:\"\\<forall>n''\\<in>set (targetnodes as). n' postdominates n''\"\n    by auto\n  have notExit:\"n \\<noteq> (_Exit_)\"\n  proof\n    assume \"n = (_Exit_)\"\n    with path have \"n = n'\" by(fastforce dest:path_Exit_source)\n    with noteq show False by simp\n  qed\n  from path have valid:\"valid_node n\" and valid':\"valid_node n'\"\n    by(auto dest:path_valid_node)\n  show \"n controls\\<^sub>s n' via as\"\n  proof(cases as)\n    case Nil    \n    with path valid not_pd notExit have False \n      by(fastforce elim:path.cases dest:postdominate_refl)\n    thus ?thesis by simp\n  next\n    case (Cons ax asx)\n    with all have pd:\"n' postdominates targetnode ax\"\n      by(auto simp:targetnodes_def)\n    from path Cons have source:\"n = sourcenode ax\" \n      and path2:\"targetnode ax -asx\\<rightarrow>* n'\"\n      by(auto intro:path_split_Cons)\n    show ?thesis\n    proof(cases \"\\<exists>as'. n -as'\\<rightarrow>* (_Exit_)\")\n      case True\n      with not_pd valid valid' obtain as' where path':\"n -as'\\<rightarrow>* (_Exit_)\"\n        and not_isin:\"n' \\<notin> set (sourcenodes as')\"\n        by(auto simp:postdominate_def)\n      have \"as' \\<noteq> []\"\n      proof\n        assume \"as' = []\"\n        with path' have \"n = (_Exit_)\" by(auto elim:path.cases)\n        with notExit show False by simp\n      qed\n      then obtain a' as'' where as':\"as' = a'#as''\"\n        by(cases as',auto elim:path.cases)\n      with path' have \"n -[]@a'#as''\\<rightarrow>* (_Exit_)\" by simp\n      hence source':\"n = sourcenode a'\" \n        and valid_edge:\"valid_edge a'\"\n        and path2':\"targetnode a' -as''\\<rightarrow>* (_Exit_)\"\n        by(fastforce dest:path_split)+\n      from path2' not_isin as' valid'\n      have \"\\<not> n' postdominates (targetnode a')\"\n        by(auto simp:postdominate_def sourcenodes_def)\n      with pd path Cons source source' notin valid_edge show ?thesis\n        by(auto simp:dyn_standard_control_dependence_def)\n    next\n      case False\n      with valid valid' have \"n' postdominates n\"\n        by(auto simp:postdominate_def)\n      with not_pd have False by simp\n      thus ?thesis by simp\n    qed\n  qed\nnext\n  assume \"n controls\\<^sub>s n' via as\"\n  then obtain a nx a' nx' as' where notin:\"n' \\<notin> set(sourcenodes as)\"\n    and path:\"n -as\\<rightarrow>* n'\" and as:\"as = a#as'\" and valid_edge:\"valid_edge a'\"\n    and pd:\"n' postdominates (targetnode a)\"\n    and source':\"sourcenode a' = n\"\n    and not_pd:\"\\<not> n' postdominates (targetnode a')\"\n    by(auto simp:dyn_standard_control_dependence_def)\n  from path as have source:\"sourcenode a = n\" by(auto elim:path.cases)\n  from path as have notExit:\"n \\<noteq> (_Exit_)\" by(auto elim:path.cases)\n  from path have valid:\"valid_node n\" and valid':\"valid_node n'\"\n    by(auto dest:path_valid_node)\n  from notin as source have noteq:\"n \\<noteq> n'\"\n    by(fastforce simp:sourcenodes_def)\n  from valid_edge have valid_target':\"valid_node (targetnode a')\"\n    by(fastforce simp:valid_node_def)\n  { assume pd':\"n' postdominates n\"\n    hence all:\"\\<forall>as. n -as\\<rightarrow>* (_Exit_) \\<longrightarrow> n' \\<in> set (sourcenodes as)\"\n      by(auto simp:postdominate_def)\n    from not_pd valid' valid_target' obtain as' \n      where \"targetnode a' -as'\\<rightarrow>* (_Exit_)\"\n      by(auto simp:postdominate_def)\n    with source' valid_edge have path':\"n -a'#as'\\<rightarrow>* (_Exit_)\"\n      by(fastforce intro:Cons_path)\n    with all have \"n' \\<in> set (sourcenodes (a'#as'))\" by blast\n    with source' have \"n' = n \\<or> n' \\<in> set (sourcenodes as')\"\n      by(fastforce simp:sourcenodes_def)\n    hence False\n    proof\n      assume \"n' = n\"\n      with noteq show ?thesis by simp\n    next\n      assume isin:\"n' \\<in> set (sourcenodes as')\"\n      from path' have path2:\"targetnode a' -as'\\<rightarrow>* (_Exit_)\"\n        by(fastforce elim:path_split_Cons)\n      thus ?thesis\n      proof(cases \"as' = []\")\n        case True\n        with path2 have \"targetnode a' = (_Exit_)\" by(auto elim:path.cases)\n        with valid_edge all source' have \"n' = n\"\n          by(fastforce dest:path_edge simp:sourcenodes_def)\n        with noteq show ?thesis by simp\n      next\n        case False\n        from path2 not_pd valid' valid_edge obtain as''\n          where path'':\"targetnode a' -as''\\<rightarrow>* (_Exit_)\"\n          and notin:\"n' \\<notin> set (sourcenodes as'')\"\n          by(auto simp:postdominate_def)\n        from valid_edge path'' have \"sourcenode a' -a'#as''\\<rightarrow>* (_Exit_)\"\n          by(fastforce intro:Cons_path)\n        with all source' have \"n' \\<in> set (sourcenodes ([a']@as''))\" by simp\n        with source' have \"n' = n \\<or> n' \\<in> set (sourcenodes as'')\"\n          by(auto simp:sourcenodes_def)\n        thus ?thesis\n        proof\n          assume \"n' = n\"\n          with noteq show ?thesis by simp\n        next\n          assume \"n' \\<in> set (sourcenodes as'')\"\n          with notin show ?thesis by simp\n        qed\n      qed\n    qed }\n  hence not_pd':\"\\<not> n' postdominates n\" by blast\n  { fix n'' assume \"n'' \\<in> set (targetnodes as)\"\n    with as source have \"n'' = targetnode a \\<or> n'' \\<in> set (targetnodes as')\" \n      by(auto simp:targetnodes_def)\n    hence \"n' postdominates n''\"\n    proof\n      assume \"n'' = targetnode a\"\n      with pd show ?thesis by simp\n    next\n      assume isin:\"n'' \\<in> set (targetnodes as')\"\n      hence \"\\<exists>ni \\<in> set (targetnodes as'). ni = n''\" by simp\n      then obtain ns ns' where targets:\"targetnodes as' = ns@n''#ns'\"\n        and all_noteq:\"\\<forall>ni \\<in> set ns'. ni \\<noteq> n''\"\n        by(fastforce elim!:rightmost_element_property)\n      from targets obtain xs ax ys where ys:\"ns' = targetnodes ys\"\n        and as':\"as' = xs@ax#ys\" and target'':\"targetnode ax = n''\"\n        by(fastforce elim:map_append_append_maps simp:targetnodes_def)\n      from all_noteq ys have notin_target:\"n'' \\<notin> set(targetnodes ys)\"\n        by auto\n      from path as have \"n -[]@a#as'\\<rightarrow>* n'\" by simp\n      hence \"targetnode a -as'\\<rightarrow>* n'\" \n        by(fastforce dest:path_split)\n      with isin have path':\"targetnode a -as'\\<rightarrow>* n'\"\n        by(fastforce split:split_if_asm simp:targetnodes_def)\n      with as' target'' have path1:\"targetnode a -xs\\<rightarrow>* sourcenode ax\"\n        and valid_edge':\"valid_edge ax\"\n        and path2:\"n'' -ys\\<rightarrow>* n'\"\n        by(auto intro:path_split)\n      from valid_edge' have \"sourcenode ax -[ax]\\<rightarrow>* targetnode ax\" by(rule path_edge)\n      with path1 target'' have path_n'':\"targetnode a -xs@[ax]\\<rightarrow>* n''\"\n        by(fastforce intro:path_Append)\n      from notin as as' have notin':\"n'\\<notin> set (sourcenodes (xs@[ax]))\"\n        by(simp add:sourcenodes_def)\n      show ?thesis\n      proof(rule ccontr)\n        assume \"\\<not> n' postdominates n''\"\n        with valid' target'' valid_edge' obtain asx' \n          where Exit_path:\"n'' -asx'\\<rightarrow>* (_Exit_)\"\n          and notin'':\"n' \\<notin> set(sourcenodes asx')\" by(auto simp:postdominate_def)\n        from path_n'' Exit_path\n        have Exit_path':\"targetnode a -(xs@[ax])@asx'\\<rightarrow>* (_Exit_)\"\n          by(fastforce intro:path_Append)\n        from notin' notin'' have \"n' \\<notin> set(sourcenodes (xs@ax#asx'))\"\n          by(simp add:sourcenodes_def)\n        with pd Exit_path' show False by(simp add:postdominate_def)\n      qed\n    qed }\n  with path not_pd' notin noteq show \"(n -as\\<rightarrow>* n') \\<and> (n \\<noteq> n') \\<and>\n    (\\<not> n' postdominates n) \\<and> (n' \\<notin> set(sourcenodes as)) \\<and>\n    (\\<forall>n'' \\<in> set(targetnodes as). n' postdominates n'')\" by blast\nqed\n\n\nlemma which_node_dyn_standard_control_dependence_source:\n  assumes path:\"(_Entry_) -as@a#as'\\<rightarrow>* n\"\n  and Exit_path:\"n -as''\\<rightarrow>* (_Exit_)\" and source:\"sourcenode a = n'\" \n  and source':\"sourcenode a' = n'\"\n  and no_source:\"n \\<notin> set(sourcenodes (a#as'))\" and valid_edge':\"valid_edge a'\"\n  and inner_node:\"inner_node n\" and not_pd:\"\\<not> n postdominates (targetnode a')\"\n  and last:\"\\<forall>ax ax'. ax \\<in> set as' \\<and> sourcenode ax = sourcenode ax' \\<and>\n    valid_edge ax' \\<longrightarrow> n postdominates targetnode ax'\"\n  shows \"n' controls\\<^sub>s n via a#as'\"\nproof -\n  from path source have path_n'n:\"n' -a#as'\\<rightarrow>* n\" by(fastforce dest:path_split_second)\n  from path have valid_edge:\"valid_edge a\" by(fastforce intro:path_split)\n  show ?thesis\n  proof(cases \"n postdominates (targetnode a)\")\n    case True\n    with path_n'n not_pd no_source source source' valid_edge' show ?thesis\n      by(auto simp:dyn_standard_control_dependence_def)\n  next\n    case False\n    hence not_pd':\"\\<not> n postdominates (targetnode a)\" .\n    show ?thesis\n    proof(cases \"as' = []\")\n      case True\n      with path_n'n have \"targetnode a = n\" by(fastforce elim:path.cases)\n      with inner_node have \"n postdominates (targetnode a)\"\n        by(cases \"n = (_Exit_)\",auto intro:postdominate_refl simp:inner_node_def)\n      with not_pd path_n'n no_source source source' valid_edge' show ?thesis\n        by(fastforce simp:dyn_standard_control_dependence_def)\n    next\n      case False\n      hence notempty':\"as' \\<noteq> []\" .\n      with path have path_nxn:\"targetnode a -as'\\<rightarrow>* n\"\n        by(fastforce dest:path_split)\n      from Exit_path path_nxn have \"\\<exists>as. targetnode a -as\\<rightarrow>* (_Exit_)\"\n        by(fastforce dest:path_Append)\n      with not_pd' inner_node valid_edge obtain asx \n        where path_Exit:\"targetnode a -asx\\<rightarrow>* (_Exit_)\" \n        and notin:\"n \\<notin> set (sourcenodes asx)\"\n        by(auto simp:postdominate_def inner_is_valid)\n      show ?thesis\n      proof(cases \"\\<exists>asx'. asx = as'@asx'\")\n        case True\n        then obtain asx' where asx:\"asx = as'@asx'\" by blast\n        from path notempty' have \"targetnode a -as'\\<rightarrow>* n\"\n          by(fastforce dest:path_split)\n        with path_Exit inner_node asx notempty'\n        obtain a'' as'' where \"asx' = a''#as'' \\<and> sourcenode a'' = n\"\n          apply(cases asx')\n           apply(fastforce dest:path_det)\n          by(fastforce dest:path_split path_det)\n        with asx have \"n \\<in> set(sourcenodes asx)\" by(simp add:sourcenodes_def)\n        with notin have False by simp\n        thus ?thesis by simp\n      next\n        case False\n        hence all:\"\\<forall>asx'. asx \\<noteq> as'@asx'\" by simp\n        then obtain j asx' where asx:\"asx = (take j as')@asx'\"\n          and length:\"j < length as'\"\n          and not_more:\"\\<forall>k > j. \\<forall>asx''. asx \\<noteq> (take k as')@asx''\"\n          by(auto elim:path_split_general)\n        from asx length have \"\\<exists>as'1 as'2. asx = as'1@asx' \\<and> \n          as' = as'1@as'2 \\<and> as'2 \\<noteq> [] \\<and> as'1 = take j as'\"\n          by simp(rule_tac x= \"drop j as'\" in exI,simp)\n        then obtain as'1 as'' where asx:\"asx = as'1@asx'\"\n          and take:\"as'1 = take j as'\"\n          and x:\"as' = as'1@as''\" and x':\"as'' \\<noteq> []\" by blast\n        from x x' obtain a1 as'2 where as':\"as' = as'1@a1#as'2\" and \"as'' = a1#as'2\"\n          by(cases as'') auto\n        have notempty_x':\"asx' \\<noteq> []\"\n        proof(cases \"asx' = []\")\n          case True\n          with asx as' have \"as' = asx@a1#as'2\" by simp\n          with path_n'n have \"n' -(a#asx)@a1#as'2\\<rightarrow>* n\"\n            by simp\n          hence \"n' -a#asx\\<rightarrow>* sourcenode a1\"\n            and valid_edge1:\"valid_edge a1\" by(fastforce elim:path_split)+\n          hence \"targetnode a -asx\\<rightarrow>* sourcenode a1\"\n            by(fastforce intro:path_split_Cons)\n          with path_Exit have \"(_Exit_) = sourcenode a1\" by(rule path_det)\n          from this[THEN sym] valid_edge1 have False by -(rule Exit_source,simp_all)\n          thus ?thesis by simp\n        qed simp\n        with asx obtain a2 asx'1 \n          where asx:\"asx = as'1@a2#asx'1\"\n          and asx':\"asx' = a2#asx'1\" by(cases asx') auto\n        from path_n'n as' have \"n' -(a#as'1)@a1#as'2\\<rightarrow>* n\" by simp\n        hence \"n' -a#as'1\\<rightarrow>* sourcenode a1\" and valid_edge1:\"valid_edge a1\"\n          by(fastforce elim:path_split)+\n        hence path1:\"targetnode a -as'1\\<rightarrow>* sourcenode a1\"\n          by(fastforce intro:path_split_Cons)\n        from path_Exit asx\n        have \"targetnode a -as'1\\<rightarrow>* sourcenode a2\"\n          and valid_edge2:\"valid_edge a2\"\n          and path2:\"targetnode a2 -asx'1\\<rightarrow>* (_Exit_)\"\n          by(auto intro:path_split)\n        with path1 have eq12:\"sourcenode a1 = sourcenode a2\"\n          by(cases as'1,auto dest:path_det)\n        from asx notin have \"n \\<notin> set (sourcenodes asx'1)\"\n          by(simp add:sourcenodes_def)\n        with path2 have not_pd'2:\"\\<not> n postdominates targetnode a2\"\n          by(cases \"asx'1 = []\",auto simp:postdominate_def)\n        from as' have \"a1 \\<in> set as'\" by simp\n        with eq12 last valid_edge2 have \"n postdominates targetnode a2\" by blast\n        with not_pd'2 have False by simp\n        thus ?thesis by simp\n      qed\n    qed\n  qed\nqed\n\n\nlemma inner_node_dyn_standard_control_dependence_predecessor:\n  assumes inner_node:\"inner_node n\"\n  obtains n' as where \"n' controls\\<^sub>s n via as\"\nproof(atomize_elim)\n  from inner_node obtain as' where pathExit:\"n -as'\\<rightarrow>* (_Exit_)\"\n    by(fastforce dest:inner_is_valid Exit_path)\n  from inner_node obtain as where pathEntry:\"(_Entry_) -as\\<rightarrow>* n\"\n    by(fastforce dest:inner_is_valid Entry_path)\n  with inner_node have notEmpty:\"as \\<noteq> []\" \n    by(auto elim:path.cases simp:inner_node_def)\n  have \"\\<exists>a asx. (_Entry_) -a#asx\\<rightarrow>* n \\<and> n \\<notin> set (sourcenodes (a#asx))\"\n  proof(cases \"n \\<in> set (sourcenodes as)\")\n    case True\n    hence \"\\<exists>n'' \\<in> set(sourcenodes as). n = n''\" by simp\n    then obtain ns' ns'' where nodes:\"sourcenodes as = ns'@n#ns''\"\n      and notin:\"\\<forall>n'' \\<in> set ns'. n \\<noteq> n''\"\n      by(fastforce elim!:split_list_first_propE)\n    from nodes obtain xs ys a'\n      where xs:\"sourcenodes xs = ns'\" and as:\"as = xs@a'#ys\"\n      and source:\"sourcenode a' = n\"\n      by(fastforce elim:map_append_append_maps simp:sourcenodes_def)\n    from pathEntry as have \"(_Entry_) -xs@a'#ys\\<rightarrow>* n\" by simp\n    hence path2:\"(_Entry_) -xs\\<rightarrow>* sourcenode a'\"\n      by(fastforce dest:path_split)\n    show ?thesis\n    proof(cases \"xs = []\")\n      case True\n      with path2 have \"(_Entry_) = sourcenode a'\" by(auto elim:path.cases)\n      with pathEntry source notEmpty have \"(_Entry_) -as\\<rightarrow>* (_Entry_) \\<and> as \\<noteq> []\"\n        by(auto elim:path.cases)\n      hence False by(fastforce dest:path_Entry_target)\n      thus ?thesis by simp\n    next\n      case False\n      then obtain n a'' xs' where \"xs = a''#xs'\" by(cases xs) auto\n      with False path2 notin xs source show ?thesis by simp blast\n    qed\n  next\n    case False\n    from notEmpty obtain a as' where \"as = a#as'\" by (cases as) auto\n    with False pathEntry show ?thesis by auto\n  qed\n  then obtain a asx where pathEntry':\"(_Entry_) -a#asx\\<rightarrow>* n\"\n    and notin:\"n \\<notin> set (sourcenodes (a#asx))\" by blast\n  show \"\\<exists>n' as. n' controls\\<^sub>s n via as\"\n  proof(cases \"\\<forall>a' a''. a' \\<in> set asx \\<and> sourcenode a' = sourcenode a'' \\<and> \n      valid_edge a'' \\<longrightarrow> n postdominates targetnode a''\")\n    case True\n    from inner_node have not_pd:\"\\<not> n postdominates (_Exit_)\" \n      by(fastforce intro:empty_path simp:postdominate_def sourcenodes_def)\n    from pathEntry' have path':\"(_Entry_) -[]@a#asx\\<rightarrow>* n\" by simp\n    hence eq:\"sourcenode a = (_Entry_)\"\n      by(fastforce dest:path_split elim:path.cases)\n    from Entry_Exit_edge obtain a' where \"sourcenode a' = (_Entry_)\"\n      and \"targetnode a' = (_Exit_)\" and \"valid_edge a'\" by auto\n    with path' inner_node not_pd True eq notin pathExit\n    have \"sourcenode a controls\\<^sub>s n via a#asx\"\n      by -(erule which_node_dyn_standard_control_dependence_source,auto)\n    thus ?thesis by blast\n  next\n    case False\n    hence \"\\<exists>a' \\<in> set asx. \\<exists>a''. sourcenode a' = sourcenode a'' \\<and> valid_edge a'' \\<and>\n      \\<not> n postdominates targetnode a''\"\n      by fastforce\n    then obtain ax asx' asx'' where \"asx = asx'@ax#asx'' \\<and>\n      (\\<exists>a''. sourcenode ax = sourcenode a'' \\<and> valid_edge a'' \\<and>\n      \\<not> n postdominates targetnode a'') \\<and>\n      (\\<forall>z \\<in> set asx''. \\<not> (\\<exists>a''. sourcenode z = sourcenode a'' \\<and> valid_edge a'' \\<and>\n      \\<not> n postdominates targetnode a''))\"\n      by(blast elim!:rightmost_element_property)\n    then obtain a'' where as':\"asx = asx'@ax#asx''\"\n      and eq:\"sourcenode ax = sourcenode a''\"\n      and valid_edge:\"valid_edge a''\"\n      and not_pd:\"\\<not> n postdominates targetnode a''\"\n      and last:\"\\<forall>z \\<in> set asx''. \\<not> (\\<exists>a''. sourcenode z = sourcenode a'' \\<and> \n        valid_edge a'' \\<and> \\<not> n postdominates targetnode a'')\"\n      by blast\n    from notin as' have notin':\"n \\<notin> set (sourcenodes (ax#asx''))\"\n      by(auto simp:sourcenodes_def)\n    from as' pathEntry' have \"(_Entry_) -(a#asx')@ax#asx''\\<rightarrow>* n\" by simp\n    with inner_node not_pd notin' eq last pathExit valid_edge\n    have \"sourcenode ax controls\\<^sub>s n via ax#asx''\"\n      by(fastforce elim!:which_node_dyn_standard_control_dependence_source)\n    thus ?thesis by blast\n  qed\nqed\n\n\nend\n\nend", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Slicing/Basic/DynStandardControlDependence.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.4649015713733885, "lm_q1q2_score": 0.273775482258674}}
{"text": "           (*-------------------------------------------*\n            |                                           |\n            |         ParaAlgo on LW-CSP-Prover         |\n            |                                           |\n            *-------------------------------------------*)\n\ntheory MBP_algo\nimports MBP_base CSP_semantics\nbegin\n\n(*************************************************************\n\n         1. Spec\n         2. \n         3. \n         4. \n\n *************************************************************)\n\n(* ----- loop test (process name) ------ *)\n\n\ndatatype ParaName = Bfr nodes edges \"nat => nodes\"  nat nodes\n                    | Aft nodes edges \"nat => nodes\" nat nodes nat\n\n\n(*ParaAlgo*)\ndefinition\nco :: \"nat => nat\"\nwhere\nco_def : \"co c = 3 - c\"\n\ndefinition\nCom :: \"Event set\"\nwhere\nCom_def : \"Com == {com c c' n| c c' n. True}\"\n(*Com_def : \"Com == {e. EX c c' n. e = com c c' n}\"*)\n\ndefinition\nComFin :: \"Event set\"\nwhere\nComFin_def : \"ComFin == Com Un {finish}\"\n\nprimrec\n  ParaDef :: \"ParaName => (ParaName, Event) proc\"\n  where\n  \"ParaDef (Bfr Blks Deps Asn c S) \n    = ((S = Blks) &> finish -> STOP)\n      [+] (~(S=Blks)) &> \n          ( ( [Nat] n : (enable Blks Deps S Int Asn(c)) .. blk n -> $Aft Blks Deps Asn c S n)\n      [+] (com (co(c)) c ? m -> $Bfr Blks Deps Asn c (S Un {m})))\"\n  |\"ParaDef(Aft Blks Deps Asn c S n)\n    = (com c (co(c)) ! n -> $Bfr Blks Deps Asn c (S Un {n}))\n      [+] (com (co(c)) c ? m  -> $Aft Blks Deps Asn c (S Un {m}) n)\"\n\noverloading ParaPNfun ==\n  \"PNfun :: ParaName => (ParaName, Event) proc\"\n  begin\ndefinition \"PNfun == ParaDef\"\nend\n\ndeclare ParaPNfun_def [simp]\n\n\ndefinition\n  ParaCtrl :: \"nodes => edges => (nat => nodes) => (ParaName,Event) proc\"\n  where\n  ParaCtrl_def : \"ParaCtrl Blks Deps Asn\n                  == ($Bfr Blks Deps Asn 1 {} |[ComFin]| $Bfr Blks Deps Asn 2 {}) ~~ Com\"\n\n(* ------------------------------------ *\n |              lemmas                  |\n * ------------------------------------ *)\n\n(*before com1*)\nlemma ParaAlgo_Bfr_blk:\n  \"ALL e c S P'. e ~: Ev`Com & e ~: Ev ` ComFin & $Bfr Blks Deps Asn c S ---e---> P' \n--> (EX n.  n : (enable Blks Deps S Int Asn(c)) & e = Ev (blk n) & P'= $Aft Blks Deps Asn c S n \n & S ~= Blks)\"\n  apply (auto)\n  apply (erule trn.cases, auto simp add: ComFin_def Com_def)+\n  done\n\n(*before finish*)\nlemma ParaAlgo_Bfr_blk_finish:\n  \"ALL e c S P'. e ~: Ev ` Com & e : Ev ` ComFin & $Bfr Blks Deps Asn c S ---e---> P' \n--> ( e = Ev (finish) & P'= STOP & S = Blks)\"\n  apply (auto)\n  apply (erule trn.cases, auto simp add: ComFin_def Com_def)+\n  done\n\n(*before com2*)\nlemma ParaAlgo_Bfr_blk_com:\n  \"ALL e c S P'. e : Ev ` Com & $Bfr Blks Deps Asn c S ---e---> P' \n--> (EX m.  e = Ev (com(co(c))c m) & P'= $Bfr Blks Deps Asn c (S Un {m})\n & S ~= Blks)\"\n  apply (auto)\n  apply (erule trn.cases, auto simp add: ComFin_def Com_def)+\n  done\n\n(*After*)\nlemma ParaAlgo_Aft_blk:\n  \"ALL e c S n P'.  $Aft Blks Deps Asn c S n ---e---> P' \n-->  e = Ev(com c (co(c)) n)  & P'= $Bfr Blks Deps Asn c (S Un {n}) |\n    (EX m.  e = Ev(com (co(c)) c m)  & P'= $Aft Blks Deps Asn c (S Un {m}) n) \"\n  apply (auto)\n  apply (erule trn.cases, auto simp add: ComFin_def Com_def)+\n  done\n\n(*STOP[]STOP*)\nlemma ParaAlgo_ws_STST:\n  \"ALL P e P'.  P ---e---> P' -->\n       P = (STOP |[ComFin]| STOP) ~~ Com  -->\n      False\"\n  apply (auto)\n  apply (erule trn.cases, auto)+\n  done\n\n(* existence of transitions *)\n\nlemma Bfr_Bfr_trn_1:\n  \"n : Asn (Suc 0) ==> n : enable Blks Deps S \n   ==>\n    ($Bfr Blks Deps Asn (Suc 0) S \n        |[ComFin]| $Bfr Blks Deps Asn 2 S) ~~ Com \n     ---(Ev (blk n))--->\n    ($Aft Blks Deps Asn (Suc 0) S n \n        |[ComFin]| $Bfr Blks Deps Asn 2 S) ~~ Com\"\n  apply (rule Hide1)\n  apply (rule conjI)\n   apply (rule Para1)\n   apply (rule conjI)\n    apply (rule PName)\n    apply (simp)\n    apply (rule ExtCh2)\n    apply (rule If1)\n    apply (rule conjI)\n     apply (rule ExtCh1)\n     apply (rule NatExtCh1) (* ?90 = n <— S b x n *)\n     apply (rule conjI)\n      apply (rule Prefix)\n     apply (simp)\n     apply (simp add: enable_def)\n    apply(force)\n   apply (simp add: ComFin_def)\n   apply (simp add:Com_def)\n   apply(force)(* Ev ` chutoriaru set sanshou*)\n  apply (simp add:Com_def)\n  apply(force)    \n  done  \n\nlemma Bfr_Bfr_trn_2:\n  \"n : Asn 2 ==> n : enable Blks Deps S \n   ==>\n    ($Bfr Blks Deps Asn (Suc 0) S \n        |[ComFin]| $Bfr Blks Deps Asn 2 S) ~~ Com \n     ---(Ev (blk n))--->\n    ($Bfr Blks Deps Asn (Suc 0) S \n        |[ComFin]| $Aft Blks Deps Asn 2 S n) ~~ Com\"\n\n  apply (rule Hide1)\n  apply (rule conjI)\n   apply (rule Para2)\n   apply (rule conjI)\n    apply (rule PName)\n    apply (simp)\n    apply (rule ExtCh2)\n    apply (rule If1)\n    apply (rule conjI)\n     apply (rule ExtCh1)\n     apply (rule NatExtCh1) (* ?90 = n <— S b x n *)\n     apply (rule conjI)\n      apply (rule Prefix)\n     apply (simp)\n     apply (simp add: enable_def)\n    apply(force)\n   apply (simp add: ComFin_def)\n   apply (simp add:Com_def)\n   apply(force)(* Ev ` chutoriaru set sanshou*)\n  apply (simp add:Com_def)\n  apply(force)    \n  done  \n\nlemma Bfr_Bfr_trn_finish:\n   \"($Bfr Blks Deps Asn (Suc 0) Blks \n        |[ComFin]| $Bfr Blks Deps Asn 2 Blks) \n          ~~ Com \n      ---(Ev finish)---> (STOP |[ComFin]| STOP) ~~ Com\"\n       apply (rule Hide1)\n       apply (rule conjI)\n        apply (rule Para3)\n        apply (simp add: ComFin_def)\n        apply (rule conjI)\n         apply (rule PName)\n         apply (simp)\n         apply (rule ExtCh1)\n         apply (rule If1)\n         apply (rule conjI)\n          apply (rule Prefix)\n         apply (simp)\n        apply (rule PName)\n        apply (simp)\n        apply (rule ExtCh1)\n        apply (rule If1)\n        apply (rule conjI)\n         apply (rule Prefix)\n        apply (simp)\n\n       apply (simp add: Com_def)\n       apply (force)\n  done\n\nlemma Aft_Bfr_trn_tau:\n   \"S \\<noteq> Blks\n    ==> ($Aft Blks Deps Asn (Suc 0) S n\n       |[ComFin]| $Bfr Blks Deps Asn 2 S) ~~ Com \n     ---Tau--->\n     ($Bfr Blks Deps Asn (Suc 0) (insert n S) \n        |[ComFin]| $Bfr Blks Deps Asn 2 (insert n S)) ~~ Com\"\n  apply (rule Hide2)\n  apply (rule conjI)\n   apply (rule Para3)\n\n(* Aft --com--> Bfr*)\n   apply (rule conjI)\n    apply (rule PName)\n    apply (simp)\n    apply (rule ExtCh1)\n    apply (rule Prefix)\n\n(* Bfr --com--> Bfr*)\n   apply (rule conjI)\n    apply (rule PName)\n    apply (simp)\n    apply (rule ExtCh2)\n    apply (rule If1)\n    apply (rule conjI)\n     apply (rule ExtCh2)\n     apply (rule NatExtCh1)\n     apply (simp add: co_def)\n     apply (rule Prefix)\n    apply (force)\n   apply (simp add: ComFin_def)\n   apply (simp add: Com_def)\n  apply (simp add: Com_def)\n  done\n\nlemma Bfr_Aft_trn_tau:\n   \"S \\<noteq> Blks\n    ==> ($Bfr Blks Deps Asn (Suc 0) S\n       |[ComFin]| $Aft Blks Deps Asn 2 S n) ~~ Com \n     ---Tau--->\n     ($Bfr Blks Deps Asn (Suc 0) (insert n S) \n        |[ComFin]| $Bfr Blks Deps Asn 2 (insert n S)) ~~ Com\"\n  apply (rule Hide2)\n  apply (rule conjI)\n   apply (rule Para3)\n\n(* Bfr --com--> Bfr*)\n   apply (rule conjI)\n    apply (rule PName)\n    apply (simp)\n    apply (rule ExtCh2)\n    apply (rule If1)\n    apply (rule conjI)\n     apply (rule ExtCh2)\n     apply (rule NatExtCh1)\n     apply (simp add: co_def)\n     apply (rule Prefix)\n    apply (force)\n\n\n(* Aft --com--> Bfr*)\n   apply (rule conjI)\n    apply (rule PName)\n    apply (simp)\n    apply (rule ExtCh1)\n    apply (simp add: co_def)\n    apply (rule Prefix)\n   apply (simp add: ComFin_def)\n   apply (simp add: Com_def)\n  apply (simp add: Com_def)\n  done\n\nlemma Aft_Aft_trn_tau_1:\n \"($Aft Blks Deps Asn (Suc 0) S n\n    |[ComFin]| $Aft Blks Deps Asn 2 S m) ~~ Com \n    ---Tau--->\n  ($Bfr Blks Deps Asn (Suc 0) (insert n S) \n    |[ComFin]| $Aft Blks Deps Asn 2 (insert n S) m) ~~ Com\"\n  apply (rule Hide2)\n  apply (rule conjI)\n   apply (rule Para3)\n   apply (rule conjI)\n\n(*Aft --com--> Bfr*)\n    apply (rule PName)\n    apply (simp)\n    apply (rule ExtCh1)\n    apply (rule Prefix)\n\n(*Aft --com--> Aft*)\n   apply (rule conjI)\n    apply (rule PName)\n    apply (simp)\n    apply (rule ExtCh2)\n    apply (rule NatExtCh1)\n    apply (simp add: co_def)\n    apply (rule Prefix)\n   apply (simp add: ComFin_def)\n   apply (simp add: Com_def)\n  apply (simp add: Com_def)\n  done\n\n\nlemma Aft_Aft_trn_tau_2:\n \"($Aft Blks Deps Asn (Suc 0) S n\n    |[ComFin]| $Aft Blks Deps Asn 2 S m) ~~ Com \n    ---Tau--->\n  ($Aft Blks Deps Asn (Suc 0) (insert m S) n\n    |[ComFin]| $Bfr Blks Deps Asn 2 (insert m S)) ~~ Com\"\n  apply (rule Hide2)\n  apply (rule conjI)\n   apply (rule Para3)\n   apply (rule conjI)\n\n  (*Aft --com--> Aft*)\n    apply (rule PName)\n    apply (simp)\n    apply (rule ExtCh2)\n    apply (rule NatExtCh1)\n    apply (simp add: co_def)\n    apply (rule Prefix)\n   apply (simp add: ComFin_def)\n   apply (simp add: Com_def)\n\n(*Aft --com--> Bfr*)\n    apply (rule PName)\n    apply (simp)\n    apply (rule ExtCh1)\n    apply (simp add: co_def)\n    apply (rule Prefix)\n\n  apply (simp add: Com_def)\n  done\n\nend\n", "meta": {"author": "nu-manycore", "repo": "public", "sha": "94b6a68b8183e6b756f6ece0fa483b93ad8cc833", "save_path": "github-repos/isabelle/nu-manycore-public", "path": "github-repos/isabelle/nu-manycore-public/public-94b6a68b8183e6b756f6ece0fa483b93ad8cc833/MBP-Prover/MBP_algo.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.27377548225867393}}
{"text": "theory Concrete_Reachability_Analysis\nimports\n  Concrete_Rigorous_Numerics\n  Abstract_Reachability_Analysis\nbegin\n\nabbreviation \"num_optns_rel \\<equiv> (Id::'b numeric_options rel)\"\n\nconsts i_flow1::interface\nconsts i_appr1::interface\n\nabbreviation \"float10_rel \\<equiv> Id::(float10 \\<times> float10) set\"\n\nlemma inj_on_nat_add_square: \"inj_on (\\<lambda>a::nat. a + a * a) S\"\n  by (rule strict_mono_imp_inj_on) (auto intro!: strict_monoI add_strict_mono mult_strict_mono)\n\nlemma add_sq_eq[simp]: \"a + a * a = b + b * b \\<longleftrightarrow> a = b\" for a b::nat\n  using inj_on_nat_add_square[of UNIV, unfolded inj_on_def, rule_format, of a b]\n  by auto\n\ncontext includes autoref_syntax begin\nlemma [autoref_rules]:\n  \"(precision, precision)\\<in>num_optns_rel \\<rightarrow> nat_rel\"\n  \"(start_stepsize, start_stepsize)\\<in>num_optns_rel \\<rightarrow> rnv_rel\"\n  \"(iterations, iterations)\\<in> num_optns_rel\\<rightarrow> nat_rel\"\n  \"(halve_stepsizes, halve_stepsizes)\\<in> (num_optns_rel) \\<rightarrow> nat_rel\"\n  \"(widening_mod, widening_mod)\\<in> (num_optns_rel) \\<rightarrow>nat_rel\"\n  \"(rk2_param, rk2_param)\\<in> (num_optns_rel) \\<rightarrow> rnv_rel\"\n  \"(method_id, method_id)\\<in> (num_optns_rel) \\<rightarrow> nat_rel\"\n  \"(adaptive_atol, adaptive_atol)\\<in> (num_optns_rel) \\<rightarrow> rnv_rel\"\n  \"(adaptive_rtol, adaptive_rtol)\\<in> (num_optns_rel) \\<rightarrow> rnv_rel\"\n  \"(printing_fun, printing_fun)\\<in> (num_optns_rel) \\<rightarrow> bool_rel \\<rightarrow> I \\<rightarrow> unit_rel\"\n  \"(tracing_fun, tracing_fun)\\<in> (num_optns_rel) \\<rightarrow> string_rel \\<rightarrow> \\<langle>I\\<rangle>option_rel \\<rightarrow> unit_rel\"\n  by auto\n\nend\n\nlemma [autoref_op_pat_def]:\n  includes autoref_syntax\n  shows\n    \"(\\<lambda>xs. xs @ replicate D 0) ` X \\<equiv> OP (pad_zeroes D) $ X\"\n    \"pad_zeroes D X \\<equiv> OP (pad_zeroes D) $ X\"\n  by simp_all\n\nsubsection \\<open>Relation Implementing \\<open>ode_ops\\<close>: Caching \\<open>slp_of\\<close>-Programs.\\<close>\n\ndefinition \"ode_slps_of ode_ops =\n  (approximate_sets_ode.ode_slp ode_ops,\n    approximate_sets_ode.euler_incr_slp ode_ops,\n    approximate_sets_ode.euler_slp ode_ops,\n    approximate_sets_ode.rk2_slp ode_ops,\n    approximate_sets_ode.D ode_ops)\"\n\ndefinition \"init_ode_ops poincare c1 ode_ops =\n  (ode_ops, ode_slps_of ode_ops,\n    (if poincare then Some(approximate_sets_ode.solve_poincare_slp ode_ops) else None),\n    (if c1 then Some(ode_slps_of (approximate_sets_ode'.var_ode_ops ode_ops)) else None))\"\n\ndefinition \"ode_ops_rel =\n  {(init, ode_ops). init = init_ode_ops True True ode_ops\n    \\<or> init = init_ode_ops True False ode_ops\n    \\<or> init = init_ode_ops False False ode_ops }\"\n\nconsts i_ode_ops::interface\nlemmas [autoref_rel_intf] = REL_INTFI[of ode_ops_rel i_ode_ops]\nlemmas [autoref_tyrel] = TYRELI[of ode_ops_rel]\n\n\ncontext approximate_sets begin\n\nunbundle autoref_syntax\n\nlemma print_set_impl[autoref_rules]:\n  shows \"(printing_fun optns, print_set) \\<in> bool_rel \\<rightarrow> A \\<rightarrow> Id\"\n  by auto\n\nlemma trace_set_impl[autoref_rules]:\n  shows \"(tracing_fun optns, trace_set) \\<in> string_rel \\<rightarrow> \\<langle>A\\<rangle>option_rel \\<rightarrow> Id\"\n  by auto\n\ndefinition \"print_msg_impl s = tracing_fun optns s None\"\n\nlemma print_msg_impl[autoref_rules]:\n  shows \"(print_msg_impl, print_msg) \\<in> string_rel \\<rightarrow> unit_rel\"\n  unfolding print_msg_def\n  by auto\n\ndefinition \"start_stepsize_impl = (if start_stepsize optns > 0 then start_stepsize optns else 1)\"\ndefinition \"rk2_param_impl = (let rk = rk2_param optns in if rk > 0 \\<and> rk \\<le> 1 then rk else 1)\"\n\nlemma options_impl[autoref_rules]:\n  \"(RETURN (precision optns), precision_spec) \\<in> \\<langle>nat_rel\\<rangle>nres_rel\"\n  \"(RETURN (adaptive_atol optns), adaptive_atol_spec) \\<in> \\<langle>rnv_rel\\<rangle>nres_rel\"\n  \"(RETURN (adaptive_rtol optns), adaptive_rtol_spec) \\<in> \\<langle>rnv_rel\\<rangle>nres_rel\"\n  \"(RETURN (method_id optns), method_spec) \\<in> \\<langle>nat_rel\\<rangle>nres_rel\"\n  \"(RETURN start_stepsize_impl, start_stepsize_spec) \\<in> \\<langle>rnv_rel\\<rangle>nres_rel\"\n  \"(RETURN (iterations optns), iterations_spec) \\<in> \\<langle>nat_rel\\<rangle>nres_rel\"\n  \"(RETURN (widening_mod optns), widening_mod_spec) \\<in> \\<langle>nat_rel\\<rangle>nres_rel\"\n  \"(RETURN (halve_stepsizes optns), halve_stepsizes_spec) \\<in> \\<langle>nat_rel\\<rangle>nres_rel\"\n  \"(RETURN (rk2_param_impl), rk2_param_spec) \\<in> \\<langle>rnv_rel\\<rangle>nres_rel\"\n  by (auto simp: nres_rel_def\n      precision_spec_def\n      adaptive_atol_spec_def\n      adaptive_rtol_spec_def\n      method_spec_def\n      start_stepsize_spec_def start_stepsize_impl_def\n      iterations_spec_def\n      widening_mod_spec_def\n      halve_stepsizes_spec_def\n      rk2_param_spec_def rk2_param_impl_def Let_def)\n\nsublocale approximate_sets_ode where ode_ops = ode_ops for ode_ops :: ode_ops ..\n\nschematic_goal trace_sets_impl:\n  assumes [autoref_rules]: \"(si, s) \\<in> string_rel\" \"(Xi, X) \\<in> clw_rel appr_rel\"\n  shows \"(RETURN ?f, trace_sets s X) \\<in> \\<langle>unit_rel\\<rangle>nres_rel\"\n  unfolding trace_sets_def\n  by (subst rel_ANNOT_eq[of X \"clw_rel appr_rel\"]) (autoref_monadic (plain))\nconcrete_definition trace_sets_impl for si Xi uses trace_sets_impl\nlemmas [autoref_rules] = trace_sets_impl.refine[autoref_higher_order_rule]\n\nschematic_goal print_sets_impl:\n  assumes [autoref_rules]: \"(si, s) \\<in> bool_rel\" \"(Xi, X) \\<in> clw_rel appr_rel\"\n  shows \"(RETURN ?f, print_sets s X) \\<in> \\<langle>unit_rel\\<rangle>nres_rel\"\n  unfolding print_sets_def\n  by (subst rel_ANNOT_eq[of X \"clw_rel appr_rel\"]) (autoref_monadic (plain))\nconcrete_definition print_sets_impl for si Xi uses print_sets_impl\nlemmas [autoref_rules] = print_sets_impl.refine[autoref_higher_order_rule]\n\ndefinition \"ode_slp_impl ode_ops =        (case ode_ops of (_, (x, _, _, _, _), _, _) \\<Rightarrow> x)\"\ndefinition \"euler_incr_slp_impl ode_ops = (case ode_ops of (_, (_, x, _, _, _), _, _) \\<Rightarrow> x)\"\ndefinition \"euler_slp_impl ode_ops =      (case ode_ops of (_, (_, _, x, _, _), _, _) \\<Rightarrow> x)\"\ndefinition \"rk2_slp_impl ode_ops =        (case ode_ops of (_, (_, _, _, x, _), _, _) \\<Rightarrow> x)\"\ndefinition \"D_impl ode_ops =              (case ode_ops of (_, (_, _, _, _, x), _, _) \\<Rightarrow> x)\"\ndefinition \"poincare_slp_impl ode_ops =   (case ode_ops of (ode_ops, (_, _, _, _, _), x, _) \\<Rightarrow>\n  (case x of\n    None \\<Rightarrow> let _ = print_msg_impl (''ODE solver not initialized: pslp missing'') in solve_poincare_slp ode_ops\n  | Some pslp \\<Rightarrow> pslp))\"\n\nlemma autoref_parameters[autoref_rules]:\n  \"(ode_slp_impl, ode_slp) \\<in> ode_ops_rel \\<rightarrow> slp_rel\"\n  \"(euler_incr_slp_impl, euler_incr_slp) \\<in> ode_ops_rel \\<rightarrow> slp_rel\"\n  \"(euler_slp_impl, euler_slp) \\<in> ode_ops_rel \\<rightarrow> slp_rel\"\n  \"(rk2_slp_impl, rk2_slp) \\<in> ode_ops_rel \\<rightarrow> slp_rel\"\n  \"(poincare_slp_impl, solve_poincare_slp) \\<in> ode_ops_rel \\<rightarrow> \\<langle>slp_rel\\<rangle>list_rel\"\n  \"(D_impl, D) \\<in> ode_ops_rel \\<rightarrow> nat_rel\"\n  by (auto simp: ode_ops_rel_def ode_slp_impl_def euler_incr_slp_def D_impl_def init_ode_ops_def\n      euler_incr_slp_impl_def euler_slp_impl_def rk2_slp_impl_def poincare_slp_impl_def\n      ode_slps_of_def\n      split: option.splits prod.splits)\n\ndefinition \"ode_e_impl = (\\<lambda>(ode_ops, _). ode_expression ode_ops)\"\nlemma ode_e_impl[autoref_rules]: \"(ode_e_impl, ode_e) \\<in> ode_ops_rel \\<rightarrow> fas_rel\"\n  by (auto simp: ode_e_impl_def ode_e_def ode_ops_rel_def init_ode_ops_def)\n\ndefinition \"safe_form_impl = (\\<lambda>(ode_ops, _). safe_form ode_ops)\"\nlemma safe_form_impl[autoref_rules]: \"(safe_form_impl, safe_form) \\<in> ode_ops_rel \\<rightarrow> Id\"\n  by (auto simp: safe_form_impl_def ode_ops_rel_def init_ode_ops_def)\n\nschematic_goal safe_set_appr:\n  assumes [autoref_rules]: \"(Xi, X::'a::executable_euclidean_space set) \\<in> appr_rel\"\n  assumes [autoref_rules]: \"(odoi, odo) \\<in> ode_ops_rel\"\n  notes [autoref_rules] = autoref_parameters\n  shows \"(nres_of ?f, safe_set odo X) \\<in> \\<langle>bool_rel\\<rangle>nres_rel\"\n  unfolding safe_set_def\n  including art\n  by autoref_monadic\nconcrete_definition safe_set_appr for odoi Xi uses safe_set_appr\nlemmas safe_set_appr_refine[autoref_rules] = safe_set_appr.refine[autoref_higher_order_rule]\n\nschematic_goal mk_safe_impl:\n  assumes [autoref_rules]: \"(odoi, odo) \\<in> ode_ops_rel\"\n  assumes [autoref_rules]: \"(Ri, R) \\<in> appr_rel\"\n  shows \"(nres_of ?f, mk_safe odo (R::'a::executable_euclidean_space set)) \\<in> \\<langle>appr_rel\\<rangle>nres_rel\"\n  unfolding autoref_tag_defs\n  unfolding mk_safe_def\n  including art\n  by autoref_monadic\nconcrete_definition mk_safe_impl for odoi Ri uses mk_safe_impl\nlemmas mk_safe_impl_refine[autoref_rules] = mk_safe_impl.refine[autoref_higher_order_rule]\nsublocale autoref_op_pat_def mk_safe .\n\nschematic_goal mk_safe_coll_impl:\n  assumes [autoref_rules]: \"(ISi, IS) \\<in> clw_rel appr_rel\"\n  assumes [autoref_rules]: \"(odoi, odo) \\<in> ode_ops_rel\"\n  shows \"(nres_of (?f), mk_safe_coll odo (IS::'a::executable_euclidean_space set)) \\<in> \\<langle>clw_rel appr_rel\\<rangle>nres_rel\"\n  unfolding mk_safe_coll_def\n  by autoref_monadic\nconcrete_definition mk_safe_coll_impl for ISi uses mk_safe_coll_impl\nlemmas mk_safe_coll_impl_refine[autoref_rules] = mk_safe_coll_impl.refine[autoref_higher_order_rule]\nsublocale autoref_op_pat_def mk_safe_coll .\n\nschematic_goal ode_set_impl:\n  assumes [autoref_rules_raw]: \"DIM_precond TYPE('a::executable_euclidean_space) E\"\n  assumes [autoref_rules]: \"(Xi, X) \\<in> appr_rel\"\n  assumes [autoref_rules]: \"(odoi, odo) \\<in> ode_ops_rel\"\n  notes [autoref_rules] = autoref_parameters\n  shows \"(nres_of ?f, ode_set odo X::'a set nres) \\<in> \\<langle>appr_rel\\<rangle>nres_rel\"\n  unfolding ode_set_def[abs_def]\n  including art\n  by autoref_monadic\nconcrete_definition ode_set_impl for E odoi Xi uses ode_set_impl\nlemmas ode_set_impl_refine[autoref_rules] = ode_set_impl.refine[autoref_higher_order_rule (1)]\nsublocale autoref_op_pat_def ode_set .\n\nschematic_goal Picard_step_ivl_impl:\n  fixes h::real\n  assumes [autoref_rules_raw]: \"DIM_precond TYPE('a::executable_euclidean_space) E\"\n  assumes [autoref_rules]: \"(odoi, odo) \\<in> ode_ops_rel\"\n  assumes [autoref_rules]: \"(X0i,X0)\\<in>appr_rel\" \"(hi, h) \\<in> rnv_rel\" \"(t0i, t0) \\<in> rnv_rel\" \"(PHIi,PHI)\\<in>appr_rel\"\n  notes [autoref_rules] = autoref_parameters\n  shows \"(nres_of ?f, Picard_step_ivl odo X0 t0 h PHI::'a set option nres) \\<in> \\<langle>\\<langle>appr_rel\\<rangle>option_rel\\<rangle>nres_rel\"\n  unfolding autoref_tag_defs\n  unfolding Picard_step_ivl_def\n  including art\n  by autoref_monadic\nconcrete_definition Picard_step_ivl_impl for X0i t0i hi PHIi uses Picard_step_ivl_impl\nlemmas Picard_step_ivl_impl_refine[autoref_rules] =\n  Picard_step_ivl_impl.refine[autoref_higher_order_rule (1)]\nsublocale autoref_op_pat_def Picard_step_ivl .\n\nlemma [autoref_rules]:\n  \"(abs, abs:: 'a \\<Rightarrow> 'a::executable_euclidean_space) \\<in> rnv_rel \\<rightarrow> rnv_rel\"\n  by simp_all\n\nlemma widening_spec[autoref_rules]:\n  \"(\\<lambda>i. RETURN (widening_mod optns mod i = 0), do_widening_spec) \\<in> nat_rel \\<rightarrow> \\<langle>bool_rel\\<rangle>nres_rel\"\n  by (auto simp: do_widening_spec_def nres_rel_def)\n\nschematic_goal P_iter_impl:\n  fixes h::real and i::nat\n  assumes [autoref_rules_raw]: \"DIM_precond TYPE('a::executable_euclidean_space) E\"\n  assumes [autoref_rules]: \"(odoi, odo) \\<in> ode_ops_rel\"\n  assumes [autoref_rules]: \"(X0i,X0)\\<in>appr_rel\" \"(PHIi,PHI)\\<in>appr_rel\"\n    \"(hi, h) \\<in> Id\" \"(i_i, i) \\<in> Id\"\n  notes [autoref_rules] = autoref_parameters\n  shows \"(nres_of (?f::?'r dres), P_iter odo X0 h i PHI::'a set option nres) \\<in> ?R\"\n  unfolding P_iter_def uncurry_rec_nat APP_def\n  including art\n  by autoref_monadic\n\nconcrete_definition P_iter_impl for E odoi X0i hi i_i PHIi uses P_iter_impl\nlemmas [autoref_rules] = P_iter_impl.refine[autoref_higher_order_rule(1)]\nsublocale autoref_op_pat_def P_iter .\n\nschematic_goal cert_stepsize_impl_nres:\n  fixes h::real and i n::nat\n  assumes [autoref_rules_raw]: \"DIM_precond TYPE('a::executable_euclidean_space) E\"\n  assumes [autoref_rules]:\n    \"(mi, m)\\<in>(appr_rel \\<rightarrow> rnv_rel \\<rightarrow> rnv_rel \\<rightarrow> appr_rel \\<rightarrow> \\<langle>\\<langle>appr_rel \\<times>\\<^sub>r R\\<rangle> option_rel\\<rangle>nres_rel)\"\n    \"(X0i,X0)\\<in>appr_rel\" \"(hi, h) \\<in> rnv_rel\" \"(ni, n) \\<in> nat_rel\" \"(i_i, i) \\<in> nat_rel\"\n  assumes [autoref_rules]: \"(odoi, odo) \\<in> ode_ops_rel\"\n  shows \"(?f::?'r nres, cert_stepsize odo m (X0::'a set) h n i) \\<in> ?R\"\n  unfolding cert_stepsize_def uncurry_rec_nat autoref_tag_defs\n  by autoref\nconcrete_definition cert_stepsize_impl_nres for mi X0i hi ni i_i uses cert_stepsize_impl_nres\nlemmas [autoref_rules] = cert_stepsize_impl_nres.refine[autoref_higher_order_rule(1)]\nsublocale autoref_op_pat_def cert_stepsize .\n\nschematic_goal cert_stepsize_impl_dres[refine_transfer]:\n  assumes [refine_transfer]: \"\\<And>a b c d. nres_of (m a b c d) \\<le> m' a b c d\"\n  shows \"nres_of ?f \\<le> cert_stepsize_impl_nres E odo m' x h n i\"\n  unfolding cert_stepsize_impl_nres_def\n  by (refine_transfer)\n\nconcrete_definition cert_stepsize_impl_dres for E m x h n i uses cert_stepsize_impl_dres\nlemmas [refine_transfer] = cert_stepsize_impl_dres.refine\n\nlemma DIM_obvious[autoref_rules_raw]: \"DIM_precond TYPE('a) DIM('a::executable_euclidean_space)\"\n  by (auto simp: )\n\nlemma default_reduce_argument_spec_impl[autoref_rules]:\n  \"(RETURN (default_reduce optns), default_reduce_argument_spec) \\<in> \\<langle>reduce_argument_rel TYPE('b)\\<rangle>nres_rel\"\n  by (auto simp: nres_rel_def default_reduce_argument_spec_def reduce_argument_rel_def\n      intro!: RETURN_RES_refine)\n\nschematic_goal euler_step_impl:\n  assumes [autoref_rules_raw]: \"DIM_precond TYPE('a::executable_euclidean_space) E\"\n  assumes ncc: \"ncc_precond TYPE('a::executable_euclidean_space)\"\n  notes [simp] = ncc_precondD[OF ncc]\n  assumes [autoref_rules]: \"(Xi, X) \\<in> appr_rel\" \"(hi, h) \\<in> Id\"\n  assumes [autoref_rules]: \"(odoi, odo) \\<in> ode_ops_rel\"\n  shows \"(nres_of (?f::?'r dres), euler_step odo (X::'a set) h) \\<in> ?R\"\n  unfolding one_step_def euler_step_def[abs_def]\n  including art\n  by autoref_monadic\nconcrete_definition euler_step_impl for odoi Xi hi uses euler_step_impl\nlemmas [autoref_rules] = euler_step_impl.refine[autoref_higher_order_rule(1 2)]\nsublocale autoref_op_pat_def euler_step .\n\nschematic_goal rk2_step_impl:\n  assumes [autoref_rules_raw]: \"DIM_precond TYPE('a::executable_euclidean_space) E\"\n  assumes ncc: \"ncc_precond TYPE('a::executable_euclidean_space)\"\n  assumes [autoref_rules]: \"(Xi, X) \\<in> appr_rel\" \"(hi, h) \\<in> Id\"\n  notes [simp] = ncc_precondD[OF ncc]\n  assumes [autoref_rules]: \"(odoi, odo) \\<in> ode_ops_rel\"\n  shows \"(nres_of (?f::?'r dres), rk2_step odo (X::'a set) h) \\<in> ?R\"\n  unfolding one_step_def rk2_step_def[abs_def]\n  by autoref_monadic\n\nconcrete_definition rk2_step_impl for odoi Xi hi uses rk2_step_impl\nlemmas [autoref_rules] = rk2_step_impl.refine[autoref_higher_order_rule (1 2)]\nsublocale autoref_op_pat_def rk2_step .\n\nschematic_goal choose_step_impl:\n  assumes [autoref_rules_raw]: \"DIM_precond TYPE('a::executable_euclidean_space) E\"\n  assumes [autoref_rules_raw]: \"ncc_precond TYPE('a)\"\n  assumes [autoref_rules]: \"(Xi, X) \\<in> appr_rel\" \"(hi, h) \\<in> rnv_rel\"\n  assumes [autoref_rules]: \"(odoi, odo) \\<in> ode_ops_rel\"\n  shows \"(nres_of (?f), choose_step odo (X::'a set) h) \\<in> \\<langle>rnv_rel \\<times>\\<^sub>r appr_rel \\<times>\\<^sub>r appr_rel \\<times>\\<^sub>r appr_rel\\<rangle>nres_rel\"\n  unfolding choose_step_def autoref_tag_defs if_distribR ncc_precond_def\n  including art\n  by autoref_monadic\n\nconcrete_definition choose_step_impl for Xi hi uses choose_step_impl\nlemmas [autoref_rules] = choose_step_impl.refine[autoref_higher_order_rule (1 2)]\nsublocale autoref_op_pat_def choose_step .\n\nlemma [autoref_rules]: \"(sgn, sgn) \\<in> rnv_rel \\<rightarrow> rnv_rel\"\n  by auto\n\nschematic_goal strongest_direction_impl:\n  assumes [autoref_rules_raw]: \"DIM_precond TYPE('a::executable_euclidean_space) E\"\n  assumes [autoref_rules]: \"(xs, x) \\<in> lv_rel\"\n  shows \"(?f, strongest_direction (x::'a)) \\<in> lv_rel \\<times>\\<^sub>r rnv_rel\"\n  unfolding strongest_direction_def\n  including art\n  by autoref\nconcrete_definition strongest_direction_impl for xs uses strongest_direction_impl\nlemmas [autoref_rules] = strongest_direction_impl.refine[autoref_higher_order_rule (1)]\nsublocale autoref_op_pat_def strongest_direction .\n\nlemma [autoref_rules]:\n  \"(real_divl, real_divl) \\<in> nat_rel \\<rightarrow> rnv_rel \\<rightarrow> rnv_rel \\<rightarrow> rnv_rel\"\n  \"(truncate_down, truncate_down) \\<in> nat_rel \\<rightarrow> rnv_rel \\<rightarrow> rnv_rel\"\n  \"(eucl_truncate_down, eucl_truncate_down) \\<in> nat_rel \\<rightarrow> rnv_rel \\<rightarrow> rnv_rel\"\n  \"(truncate_up, truncate_up) \\<in> nat_rel \\<rightarrow> rnv_rel \\<rightarrow> rnv_rel\"\n  \"(eucl_truncate_up, eucl_truncate_up) \\<in> nat_rel \\<rightarrow> rnv_rel \\<rightarrow> rnv_rel\"\n  \"(max, max) \\<in> rnv_rel \\<rightarrow> rnv_rel \\<rightarrow> rnv_rel\"\n  \"(min, min) \\<in> rnv_rel \\<rightarrow> rnv_rel \\<rightarrow> rnv_rel\"\n  \"((/), (/)) \\<in> rnv_rel \\<rightarrow> rnv_rel \\<rightarrow> rnv_rel\"\n  \"(lfloat10, lfloat10) \\<in> rnv_rel \\<rightarrow> float10_rel\"\n  \"(ufloat10, ufloat10) \\<in> rnv_rel \\<rightarrow> float10_rel\"\n  \"(shows_prec, shows_prec) \\<in> nat_rel \\<rightarrow> nat_rel \\<rightarrow> string_rel \\<rightarrow> string_rel\"\n  \"(shows_prec, shows_prec) \\<in> nat_rel \\<rightarrow> int_rel \\<rightarrow> string_rel \\<rightarrow> string_rel\"\n  \"(shows_prec, shows_prec) \\<in> nat_rel \\<rightarrow> float10_rel \\<rightarrow> string_rel \\<rightarrow> string_rel\"\n  \"(int, int) \\<in> nat_rel \\<rightarrow> int_rel\"\n  by (auto simp: string_rel_def)\n\nschematic_goal intersects_sctns_spec_impl:\n  assumes [autoref_rules]: \"(ai, a) \\<in> appr_rel\"\n  assumes sctns[autoref_rules]: \"(sctnsi, sctns) \\<in> sctns_rel\"\n  notes [simp] = list_set_rel_finiteD[OF sctns]\n  shows \"(nres_of (?x::_ dres), intersects_sctns (a::'a::executable_euclidean_space set) sctns) \\<in> \\<langle>bool_rel\\<rangle>nres_rel\"\n  unfolding autoref_tag_defs\n  unfolding intersects_sctns_def\n  by autoref_monadic\nconcrete_definition intersects_sctns_spec_impl for ai sctnsi uses intersects_sctns_spec_impl\nlemmas intersects_sctns_refine[autoref_rules] = intersects_sctns_spec_impl.refine[autoref_higher_order_rule]\nsublocale autoref_op_pat_def intersects_sctns .\n\nlemma\n  assumes \"GEN_OP ws width_spec (A \\<rightarrow> \\<langle>rnv_rel\\<rangle>nres_rel)\"\n  assumes \"\\<And>x. TRANSFER (RETURN (wsd x) \\<le> ws x)\"\n  shows width_spec_invar_rel[autoref_rules]:\n    \"(\\<lambda>(a, b). RETURN (wsd a), width_spec) \\<in> \\<langle>S, A\\<rangle>invar_rel b \\<rightarrow> \\<langle>rnv_rel\\<rangle>nres_rel\"\n    and width_spec_inter_rel[autoref_rules]:\n    \"(\\<lambda>(a, b). RETURN (wsd a), width_spec) \\<in> \\<langle>S, A\\<rangle>inter_rel \\<rightarrow> \\<langle>rnv_rel\\<rangle>nres_rel\"\n  using assms\n  by (auto simp: nres_rel_def width_spec_def invar_rel_def dest!: fun_relD)\n\nlemma width_spec_coll[autoref_rules]:\n  assumes \"GEN_OP ws width_spec (A \\<rightarrow> \\<langle>rnv_rel\\<rangle>nres_rel)\"\n  assumes \"\\<And>x. TRANSFER (RETURN (wsd x) \\<le> ws x)\"\n  shows \"(\\<lambda>xs. RETURN (sum_list (map wsd xs)), width_spec) \\<in> clw_rel A \\<rightarrow> \\<langle>rnv_rel\\<rangle>nres_rel\"\n  by (auto simp: nres_rel_def width_spec_def)\n\nschematic_goal intersects_sections_spec_clw[autoref_rules]:\n  assumes [autoref_rules]: \"(Ri, R) \\<in> clw_rel appr_rel\" \"(sctnsi, sctns) \\<in> sctns_rel\"\n  shows \"(nres_of (?r::_ dres), intersects_sctns_spec_clw $ R $ sctns) \\<in> \\<langle>bool_rel\\<rangle>nres_rel\"\n  unfolding intersects_sctns_spec_clw_def\n  including art\n  by autoref_monadic\n\nschematic_goal nonzero_component_impl:\n  assumes [autoref_rules]: \"(Xi, X) \\<in> appr_rel\" \"(ni, n) \\<in> lv_rel\" \"(si, s) \\<in> string_rel\"\n  shows \"(nres_of ?f, nonzero_component s X n) \\<in> \\<langle>unit_rel\\<rangle>nres_rel\"\n  unfolding nonzero_component_def autoref_tag_defs\n  by autoref_monadic\nconcrete_definition nonzero_component_impl for si Xi ni uses nonzero_component_impl\nlemmas nonzero_component_impl_refine[autoref_rules] = nonzero_component_impl.refine[autoref_higher_order_rule]\nlemma\n  take_set_of_apprI:\n  assumes \"xs \\<in> set_of_appr XS\" \"tXS = take d XS\" \"d < length xs\"\n  shows \"take d xs \\<in> set_of_appr tXS\"\n  using set_of_appr_project[OF assms(1), of \"[0..<d]\"]\n  apply (auto simp: assms take_eq_map_nth length_set_of_appr)\n  using assms(1) assms(3) length_set_of_appr take_eq_map_nth by fastforce\n\n\nlemma sv_appr_rell[relator_props]: \"single_valued appr_rell\"\n  by (auto simp: appr_rell_internal)\n\nlemma single_valued_union:\n  shows \"single_valued X \\<Longrightarrow> single_valued Y \\<Longrightarrow> Domain X \\<inter> Domain Y = {} \\<Longrightarrow> single_valued (X \\<union> Y)\"\n  by (auto simp: single_valued_def)\n\nlemma is_empty_ivl_rel[autoref_rules]:\n  assumes le[THEN GEN_OP_D, param_fo]: \"GEN_OP le (\\<le>) (A \\<rightarrow> A \\<rightarrow> bool_rel)\"\n  shows \"(\\<lambda>(x, y). \\<not> le x y, is_empty) \\<in> \\<langle>A\\<rangle>ivl_rel \\<rightarrow> bool_rel\"\n  apply (auto simp: ivl_rel_def br_def set_of_ivl_def)\n  subgoal premises prems for a b c d\n    using le[OF prems(2, 3)] prems(1,4-) order_trans\n    by auto\n  subgoal premises prems for a b c d\n    using le[OF prems(3,4)] prems(1,2) order_trans\n    by auto\n  done\n\nlemma real_autoref[autoref_rules]:\n  \"(real, real) \\<in> nat_rel \\<rightarrow> rnv_rel\"\n  by auto\n\nlemma map_option_autoref[autoref_rules]: \"(map_option, map_option) \\<in> (A \\<rightarrow> B) \\<rightarrow> \\<langle>A\\<rangle>option_rel \\<rightarrow> \\<langle>B\\<rangle>option_rel\"\n  by (rule map_option_param)\n\nlemma sv_plane_rel[relator_props]: \"single_valued A \\<Longrightarrow> single_valued (\\<langle>A\\<rangle>plane_rel)\"\n  by (auto simp: plane_rel_def intro!: relator_props)\nlemma sv_below_rel[relator_props]: \"single_valued A \\<Longrightarrow> single_valued (\\<langle>A\\<rangle>below_rel)\"\n  by (auto simp: below_rel_def intro!: relator_props)\nlemma sv_sbelow_rel[relator_props]: \"single_valued A \\<Longrightarrow> single_valued (\\<langle>A\\<rangle>sbelow_rel)\"\n  by (auto simp: sbelow_rel_def intro!: relator_props)\nlemma sv_sbelows_rel[relator_props]: \"single_valued A \\<Longrightarrow> single_valued (\\<langle>A\\<rangle>sbelows_rel)\"\n  by (auto simp: sbelows_rel_def intro!: relator_props)\n\nlemma closed_ivl_rel[intro, simp]:  \"(a, b) \\<in> lvivl_rel \\<Longrightarrow> closed b\"\n  by (auto simp: ivl_rel_def br_def set_of_ivl_def)\n\nlemma [autoref_rules]:\n  \"(float_of, float_of) \\<in> rnv_rel \\<rightarrow> Id\"\n  \"(approx, approx) \\<in> nat_rel \\<rightarrow> Id \\<rightarrow> \\<langle>\\<langle>Id\\<rangle>option_rel\\<rangle>list_rel \\<rightarrow> \\<langle>Id\\<rangle>option_rel\"\n  by auto\n\nlemma uninfo_autoref[autoref_rules]:\n  assumes \"PREFER single_valued X\"\n  assumes \"PREFER single_valued R\"\n  shows \"(map snd, uninfo) \\<in> clw_rel (\\<langle>R, X\\<rangle>info_rel) \\<rightarrow> clw_rel X\"\n  using assms\n  apply (auto simp: lw_rel_def Union_rel_br info_rel_def br_chain br_rel_prod elim!: single_valued_as_brE\n      dest!: brD\n      intro!: brI)\n  apply force\n  apply force\n  apply force\n  done\n\n\n\nlemma op_subset_ivl:\n  assumes le[THEN GEN_OP_D, autoref_rules, param_fo]: \"GEN_OP le (\\<le>) (A \\<rightarrow> A \\<rightarrow> bool_rel)\"\n  shows \"(\\<lambda>(a, b) (c, d). le a b \\<longrightarrow> le c a \\<and> le b d, op_subset_ivl) \\<in> \\<langle>A\\<rangle>ivl_rel \\<rightarrow> \\<langle>A\\<rangle>ivl_rel \\<rightarrow> bool_rel\"\n  apply (clarsimp dest!: brD simp: ivl_rel_def)\n  subgoal for a b c d e f g h\n    using le[of a c b d]\n    using le[of e g a c]\n    using le[of b d f h]\n    by (auto simp: set_of_ivl_def)\n  done\nconcrete_definition op_subset_ivl_impl uses op_subset_ivl\nlemmas [autoref_rules] = op_subset_ivl_impl.refine\n\nlemma [autoref_op_pat]: \"(=) \\<equiv> OP op_eq_ivl\"\n  by (force intro!: eq_reflection)\nlemma eq_ivl_impl:\n  assumes le[THEN GEN_OP_D, autoref_rules, param_fo]: \"GEN_OP le (\\<le>) (A \\<rightarrow> A \\<rightarrow> bool_rel)\"\n  shows \"(\\<lambda>(a, b) (c, d). (le a b \\<longrightarrow> le c a \\<and> le b d) \\<and> (le c d \\<longrightarrow> le a c \\<and> le d b), op_eq_ivl) \\<in> \\<langle>A\\<rangle>ivl_rel \\<rightarrow> \\<langle>A\\<rangle>ivl_rel \\<rightarrow> bool_rel\"\n  apply (clarsimp dest!: brD simp: )\n  subgoal premises prems for a b c d e f\n    using op_subset_ivl[param_fo, OF assms prems(1,2)]\n      op_subset_ivl[param_fo, OF assms prems(2,1)]\n    by (auto simp: )\n  done\nconcrete_definition eq_ivl_impl uses eq_ivl_impl\nlemmas [autoref_rules] = eq_ivl_impl.refine\n\nlemma [autoref_rules]: \"(RETURN, get_plane) \\<in> \\<langle>A\\<rangle>plane_rel \\<rightarrow> \\<langle>\\<langle>A\\<rangle>sctn_rel\\<rangle>nres_rel\"\n  by (auto simp: plane_rel_def get_plane_def nres_rel_def dest!: brD intro!: RETURN_SPEC_refine)\n\nlemma [autoref_op_pat_def del]: \"get_inter p \\<equiv> OP (get_inter p)\" by auto\n\nlemma inform_autoref[autoref_rules]:\n  \"(\\<lambda>x. Max (abs ` set x), (infnorm::'a::executable_euclidean_space\\<Rightarrow>real)) \\<in> lv_rel \\<rightarrow> rnv_rel\"\n  apply (auto simp: lv_rel_def br_def infnorm_def eucl_of_list_inner\n      intro!: Max_eqI le_cSup_finite)\n  subgoal for a y\n    apply (rule exI[where x=\"Basis_list ! index a y\"])\n    by (auto simp: eucl_of_list_inner)\n  subgoal\n    apply (rule rev_subsetD)\n     apply (rule closed_contains_Sup)\n       apply (auto intro!: finite_imp_closed)\n    apply (rule imageI)\n    apply (auto simp: eucl_of_list_inner)\n    done\n  done\n\nschematic_goal tolerate_error_impl:\n  assumes [autoref_rules_raw]: \"DIM_precond TYPE('a::executable_euclidean_space) dd\"\n  assumes [autoref_rules]: \"(Yi, Y::'a::executable_euclidean_space set) \\<in> appr_rel\"\n  assumes [autoref_rules]: \"(Ei, E) \\<in> appr_rel\"\n  shows \"(nres_of ?r, tolerate_error Y E) \\<in> \\<langle>bool_rel \\<times>\\<^sub>r rnv_rel\\<rangle>nres_rel\"\n  unfolding tolerate_error_def\n  including art\n  by autoref_monadic\nconcrete_definition tolerate_error_impl for dd Yi Ei uses tolerate_error_impl\nlemmas tolerate_error_refine[autoref_rules] = tolerate_error_impl.refine[autoref_higher_order_rule (1)]\n\nlemma adapt_stepsize_fa_autoref[autoref_rules]:\n  \"(adapt_stepsize_fa, adapt_stepsize_fa) \\<in> rnv_rel \\<rightarrow> nat_rel \\<rightarrow> rnv_rel \\<rightarrow> rnv_rel \\<rightarrow> Id\"\n  by auto\n\nlemma\n  list_wset_rel_finite:\n  assumes \"single_valued A\"\n  shows \"(xs, X) \\<in> \\<langle>A\\<rangle>list_wset_rel \\<Longrightarrow> finite X\"\n  using assms\n  by (auto simp: list_wset_rel_def set_rel_br dest!: brD elim!: single_valued_as_brE)\n\nlemma [autoref_rules_raw del]: \"(norm2_slp, norm2_slp) \\<in> nat_rel \\<rightarrow> Id\"\n  and [autoref_itype del]: \"norm2_slp ::\\<^sub>i i_nat \\<rightarrow>\\<^sub>i i_of_rel (Id::(floatarith list \\<times> floatarith list) set)\"\n  by auto\n\nlemma [autoref_rules]: \"(norm2_slp, norm2_slp) \\<in> nat_rel \\<rightarrow> slp_rel\"\n  by auto\n\nlemma [autoref_rules_raw]: \"DIM_precond TYPE(real) (Suc 0)\"\n  by auto\nlemma [autoref_rules]:\n  \"(real_divr, real_divr) \\<in> nat_rel \\<rightarrow> rnv_rel \\<rightarrow> rnv_rel \\<rightarrow> rnv_rel\"\n  by auto\n\nlemma length_norm2_slp_ge: \"length (norm2_slp E) \\<ge> 1\"\n  unfolding norm2_slp_def\n  by (auto simp: slp_of_fas_def split: prod.splits)\n\nlemma blinfun_of_vmatrix_scaleR: \"blinfun_of_vmatrix (c *\\<^sub>R e) = c *\\<^sub>R blinfun_of_vmatrix e\"\n  including blinfun.lifting\n  by transfer (vector sum_distrib_left algebra_simps matrix_vector_mult_def fun_eq_iff)\n\nlemma closed_clw_rel_iplane_rel:\n  \"(xi, x) \\<in> clw_rel (iplane_rel lvivl_rel) \\<Longrightarrow> closed x\"\n  unfolding lvivl_rel_br\n  by (force simp: lv_rel_def plane_rel_br inter_rel_br clw_rel_br set_of_ivl_def\n      dest!: brD)\n\nlemma closed_ivl_prod3_list_rel:\n  assumes \"(y, x') \\<in> clw_rel (iplane_rel lvivl_rel) \\<times>\\<^sub>r A\"\n  assumes \"(xa, x'a) \\<in> \\<langle>clw_rel (iplane_rel lvivl_rel) \\<times>\\<^sub>r B\\<rangle>list_rel\"\n  shows \"\\<forall>(guard, ro)\\<in>set (x' # x'a). closed guard\"\n  using assms closed_clw_rel_iplane_rel\n  apply (auto simp: list_rel_def prod_rel_def in_set_conv_nth list_all2_conv_all_nth)\n  apply (drule spec)\n  by auto\n\nlemma\n  rec_list_fun_eq1:\n  assumes \"\\<And>x xs a. snd (h x xs a) = snd a\"\n  shows \"rec_list z (\\<lambda>x xs r xa. f x xs xa (r (h x xs xa))) xs ab =\n    rec_list (\\<lambda>a. z (a, snd ab)) (\\<lambda>x xs r a. f x xs (a, snd ab) (r (fst (h x xs (a, snd ab))))) xs (fst ab)\"\n  using assms\n  unfolding split_beta'\n  by (induction xs arbitrary: ab) (auto simp: split_beta')\n\nlemma\n  rec_list_fun_eq2:\n  assumes \"\\<And>x xs a. fst (h x xs a) = fst a\"\n  shows \"rec_list z (\\<lambda>x xs r xa. f x xs xa (r (h x xs xa))) xs ab =\n    rec_list (\\<lambda>b. z (fst ab, b)) (\\<lambda>x xs r b. f x xs (fst ab, b) (r (snd (h x xs (fst ab, b))))) xs (snd ab)\"\n  using assms\n  unfolding split_beta'\n  by (induction xs arbitrary: ab) (auto simp: split_beta')\n\nlemma [autoref_itype]: \"compact ::\\<^sub>i A \\<rightarrow>\\<^sub>i i_bool\"\n  by auto\n\nlemma lvivl_rel_compact[autoref_rules]:\n  \"(\\<lambda>_::_\\<times>_. True, compact) \\<in> lvivl_rel \\<rightarrow> bool_rel\"\n  \"(\\<lambda>_::(_\\<times>_)list. True, compact) \\<in> clw_rel lvivl_rel \\<rightarrow> bool_rel\"\n  by (auto simp: lvivl_rel_br set_of_ivl_def lw_rel_def Union_rel_br dest!: brD)\n\nend\n\nend", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Ordinary_Differential_Equations/Numerics/Concrete_Reachability_Analysis.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.4649015713733884, "lm_q1q2_score": 0.2737754822586739}}
{"text": "theory flash48Rev imports flashPub\nbegin\nsection{*Main defintions*}\nlemma NI_FAckVsInv48:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvVsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_InvAck_1VsInv48:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1_HomeVsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_InvAck_2VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_GetXVsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_GetX ))     (neg ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv1)) )  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv2) )   (Const iInv1))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_GetX ))     (neg ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2)) )  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak1VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak2VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak3VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX1VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv48:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10VsInv48:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10_homeVsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX11VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_GetVsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_GetX ))     (neg ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv1)) )  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv2) )   (Const iInv1))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_GetX ))     (neg ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2)) )  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak1VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak2VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak3VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put1VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put2VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put3VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_PutVsInv48:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_PutXAcksDoneVsInv48:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_NakVsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Nak_ClearVsInv48:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Nak_HomeVsInv48:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_NakVsInv48:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_Nak_HomeVsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Remote_GetX_PutXVsInv48:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_PutX_HomeVsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Remote_Get_Nak1VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Remote_Get_Nak2VsInv48:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Put1VsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Remote_Get_Put2VsInv48:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutVsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutXVsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_ReplaceVsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_ReplaceHomeVsInv48:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceHomeShrVldVsInv48:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceShrVldVsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_ShWbVsInv48:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_WbVsInv48:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_GetX1VsInv48:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_GetX2VsInv48:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX1VsInv48:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX2VsInv48:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX3VsInv48:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX4VsInv48:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_Get_GetVsInv48:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_Get_PutVsInv48:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_PutXVsInv48:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_ReplaceVsInv48:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_GetVsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_GetXVsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_PutXVsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma PI_Remote_ReplaceVsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma StoreVsInv48:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma StoreHomeVsInv48:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv48  iInv1  iInv2 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash48Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.27370207411262276}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      Hoare.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection {* Auxiliary Definitions/Lemmas to Facilitate Hoare Logic *}\ntheory Hoare imports SmallStepCon LocalRG_HoareDef begin\n\n(*\nsyntax \n\n\"_hoarep_emptyFaults\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,\n   'f set,'s assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n    (\"(3_,_/\\<turnstile> (_/ (_)/ _,/_))\" [61,60,1000,20,1000,1000]60)\n\n\"_hoarep_emptyCtx\"::\n\"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n    (\"(3_/\\<turnstile>\\<^bsub>'/_\\<^esub> (_/ (_)/ _,/_))\" [61,60,1000,20,1000,1000]60)\n\n\"_hoarep_emptyCtx_emptyFaults\"::\n\"[('s,'p,'f) body,'s assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n    (\"(3_/\\<turnstile> (_/ (_)/ _,/_))\" [61,1000,20,1000,1000]60)\n\n\"_hoarep_noAbr\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,'f set,\n    's assn,('s,'p,'f) com, 's assn] => bool\"\n    (\"(3_,_/\\<turnstile>\\<^bsub>'/_\\<^esub> (_/ (_)/ _))\" [61,60,60,1000,20,1000]60)\n\n\"_hoarep_noAbr_emptyFaults\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,'s assn,('s,'p,'f) com, 's assn] => bool\"\n    (\"(3_,_/\\<turnstile> (_/ (_)/ _))\" [61,60,1000,20,1000]60)\n\n\"_hoarep_emptyCtx_noAbr\"::\n\"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com, 's assn] => bool\"\n    (\"(3_/\\<turnstile>\\<^bsub>'/_\\<^esub> (_/ (_)/ _))\" [61,60,1000,20,1000]60)\n\n\"_hoarep_emptyCtx_noAbr_emptyFaults\"::\n\"[('s,'p,'f) body,'s assn,('s,'p,'f) com, 's assn] => bool\"\n    (\"(3_/\\<turnstile> (_/ (_)/ _))\" [61,1000,20,1000]60)\n\n\n\n\"_hoaret_emptyFaults\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,\n    's assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n    (\"(3_,_/\\<turnstile>\\<^sub>t (_/ (_)/ _,/_))\" [61,60,1000,20,1000,1000]60)\n\n\"_hoaret_emptyCtx\"::\n\"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n    (\"(3_/\\<turnstile>\\<^sub>t\\<^bsub>'/_\\<^esub> (_/ (_)/ _,/_))\" [61,60,1000,20,1000,1000]60)\n\n\"_hoaret_emptyCtx_emptyFaults\"::\n\"[('s,'p,'f) body,'s assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n    (\"(3_/\\<turnstile>\\<^sub>t (_/ (_)/ _,/_))\" [61,1000,20,1000,1000]60)\n\n\"_hoaret_noAbr\"::\n\"[('s,'p,'f) body,'f set, ('s,'p) quadruple set,\n    's assn,('s,'p,'f) com, 's assn] => bool\"\n    (\"(3_,_/\\<turnstile>\\<^sub>t\\<^bsub>'/_\\<^esub> (_/ (_)/ _))\" [61,60,60,1000,20,1000]60)\n\n\"_hoaret_noAbr_emptyFaults\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,'s assn,('s,'p,'f) com, 's assn] => bool\"\n    (\"(3_,_/\\<turnstile>\\<^sub>t (_/ (_)/ _))\" [61,60,1000,20,1000]60)\n\n\"_hoaret_emptyCtx_noAbr\"::\n\"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com, 's assn] => bool\"\n    (\"(3_/\\<turnstile>\\<^sub>t\\<^bsub>'/_\\<^esub> (_/ (_)/ _))\" [61,60,1000,20,1000]60)\n\n\"_hoaret_emptyCtx_noAbr_emptyFaults\"::\n\"[('s,'p,'f) body,'s assn,('s,'p,'f) com, 's assn] => bool\"\n    (\"(3_/\\<turnstile>\\<^sub>t (_/ (_)/ _))\" [61,1000,20,1000]60)\n\n\nsyntax (ascii)\n\n\"_hoarep_emptyFaults\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,\n     's assn,('s,'p,'f) com, 's assn,'s assn] \\<Rightarrow> bool\"\n   (\"(3_,_/|- (_/ (_)/ _,/_))\" [61,60,1000,20,1000,1000]60)\n\n\"_hoarep_emptyCtx\"::\n\"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n   (\"(3_/|-'/_ (_/ (_)/ _,/_))\" [61,60,1000,20,1000,1000]60)\n\n\"_hoarep_emptyCtx_emptyFaults\"::\n\"[('s,'p,'f) body,'s assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n   (\"(3_/|-(_/ (_)/ _,/_))\" [61,1000,20,1000,1000]60)\n\n\"_hoarep_noAbr\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,'f set,\n   's assn,('s,'p,'f) com, 's assn] => bool\"\n   (\"(3_,_/|-'/_ (_/ (_)/ _))\" [61,60,60,1000,20,1000]60)\n\n\"_hoarep_noAbr_emptyFaults\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,'s assn,('s,'p,'f) com, 's assn] => bool\"\n   (\"(3_,_/|-(_/ (_)/ _))\" [61,60,1000,20,1000]60)\n\n\"_hoarep_emptyCtx_noAbr\"::\n\"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com, 's assn] => bool\"\n   (\"(3_/|-'/_ (_/ (_)/ _))\" [61,60,1000,20,1000]60)\n\n\"_hoarep_emptyCtx_noAbr_emptyFaults\"::\n\"[('s,'p,'f) body,'s assn,('s,'p,'f) com, 's assn] => bool\"\n   (\"(3_/|-(_/ (_)/ _))\" [61,1000,20,1000]60)\n\n\"_hoaret_emptyFault\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,\n     's assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n   (\"(3_,_/|-t (_/ (_)/ _,/_))\" [61,60,1000,20,1000,1000]60)\n\n\"_hoaret_emptyCtx\"::\n\"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n   (\"(3_/|-t'/_ (_/ (_)/ _,/_))\" [61,60,1000,20,1000,1000]60)\n\n\"_hoaret_emptyCtx_emptyFaults\"::\n\"[('s,'p,'f) body,'s assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n   (\"(3_/|-t(_/ (_)/ _,/_))\" [61,1000,20,1000,1000]60)\n\n\"_hoaret_noAbr\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,'f set,\n   's assn,('s,'p,'f) com, 's assn] => bool\"\n   (\"(3_,_/|-t'/_ (_/ (_)/ _))\" [61,60,60,1000,20,1000]60)\n\n\"_hoaret_noAbr_emptyFaults\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,'s assn,('s,'p,'f) com, 's assn] => bool\"\n   (\"(3_,_/|-t(_/ (_)/ _))\" [61,60,1000,20,1000]60)\n\n\"_hoaret_emptyCtx_noAbr\"::\n\"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com, 's assn] => bool\"\n   (\"(3_/|-t'/_ (_/ (_)/ _))\" [61,60,1000,20,1000]60)\n\n\"_hoaret_emptyCtx_noAbr_emptyFaults\"::\n\"[('s,'p,'f) body,'s assn,('s,'p,'f) com, 's assn] => bool\"\n   (\"(3_/|-t(_/ (_)/ _))\" [61,1000,20,1000]60)\n*)\n(*\ntranslations\n \n\n \"\\<Gamma>\\<turnstile> P c Q,A\"  == \"\\<Gamma>\\<turnstile>\\<^bsub>/{}\\<^esub> P c Q,A\" \n \"\\<Gamma>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"  == \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n\n \"\\<Gamma>,\\<Theta>\\<turnstile> P c Q\"  == \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c Q\"\n \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q\"  == \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,{}\"\n \"\\<Gamma>,\\<Theta>\\<turnstile> P c Q,A\" == \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c Q,A\" \n\n \"\\<Gamma>\\<turnstile> P c Q\"    ==  \"\\<Gamma>\\<turnstile>\\<^bsub>/{}\\<^esub> P c Q\"\n \"\\<Gamma>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q\"  == \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> P c Q\"\n \"\\<Gamma>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q\"  <=  \"\\<Gamma>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,{}\"\n \"\\<Gamma>\\<turnstile> P c Q\"    <=  \"\\<Gamma>\\<turnstile> P c Q,{}\"\n\n\n\n\n \"\\<Gamma>\\<turnstile>\\<^sub>t P c Q,A\"   == \"\\<Gamma>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\n \"\\<Gamma>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"  == \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n\n \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t P c Q\"   == \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q\"\n \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q\" == \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,{}\"\n \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t P c Q,A\"   == \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\n \n \"\\<Gamma>\\<turnstile>\\<^sub>t P c Q\"    == \"\\<Gamma>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q\"\n \"\\<Gamma>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q\"  == \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q\"\n \"\\<Gamma>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q\"  <=  \"\\<Gamma>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,{}\"\n \"\\<Gamma>\\<turnstile>\\<^sub>t P c Q\"    <=  \"\\<Gamma>\\<turnstile>\\<^sub>t P c Q,{}\"\n\n\nterm \"\\<Gamma>\\<turnstile> P c Q\"\nterm \"\\<Gamma>\\<turnstile> P c Q,A\"\n\nterm \"\\<Gamma>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q\"\nterm \"\\<Gamma>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n\nterm \"\\<Gamma>,\\<Theta>\\<turnstile> P c Q\"\nterm \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q\"\n\nterm \"\\<Gamma>,\\<Theta>\\<turnstile> P c Q,A\"\nterm \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n\n\nterm \"\\<Gamma>\\<turnstile>\\<^sub>t P c Q\"\nterm \"\\<Gamma>\\<turnstile>\\<^sub>t P c Q,A\"\n\nterm \"\\<Gamma>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q\"\nterm \"\\<Gamma>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n\nterm \"\\<Gamma>,\\<Theta>\\<turnstile> P c Q\"\nterm \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q\"\n\nterm \"\\<Gamma>,\\<Theta>\\<turnstile> P c Q,A\"\nterm \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n*)\n\nlocale hoare =\n  fixes \\<Gamma>::\"('s,'p,'f) body\" \n\n\nprimrec assoc:: \"('a \\<times>'b) list \\<Rightarrow> 'a \\<Rightarrow> 'b \"\nwhere\n\"assoc [] x = undefined\" |\n\"assoc (p#ps) x = (if fst p = x then (snd p) else assoc ps x)\"\n\nlemma conjE_simp: \"(P \\<and> Q \\<Longrightarrow> PROP R) \\<equiv> (P \\<Longrightarrow> Q \\<Longrightarrow> PROP R)\"\n  by rule simp_all\n\nlemma CollectInt_iff: \"{s. P s} \\<inter> {s. Q s} = {s. P s \\<and> Q s}\"\n  by auto\n\nlemma Compl_Collect:\"-(Collect b) = {x. \\<not>(b x)}\"\n  by fastforce\n\nlemma Collect_False: \"{s. False} = {}\"\n  by simp\n\nlemma Collect_True: \"{s. True} = UNIV\"\n  by simp\n\nlemma triv_All_eq: \"\\<forall>x. P \\<equiv> P\"\n  by simp\n\nlemma triv_Ex_eq: \"\\<exists>x. P \\<equiv> P\"\n  by simp\n\nlemma Ex_True: \"\\<exists>b. b\"\n   by blast\n\nlemma Ex_False: \"\\<exists>b. \\<not>b\"\n  by blast\n\ndefinition mex::\"('a \\<Rightarrow> bool) \\<Rightarrow> bool\"\n  where \"mex P = Ex P\"\n\ndefinition meq::\"'a \\<Rightarrow> 'a \\<Rightarrow> bool\"\n  where \"meq s Z = (s = Z)\"\n\nlemma subset_unI1: \"A \\<subseteq> B \\<Longrightarrow> A \\<subseteq> B \\<union> C\" \n  by blast\n\nlemma subset_unI2: \"A \\<subseteq> C \\<Longrightarrow> A \\<subseteq> B \\<union> C\" \n  by blast\n\nlemma split_paired_UN: \"(\\<Union>p. (P p)) = (\\<Union>a b. (P (a,b)))\" \n  by auto\n\nlemma in_insert_hd: \"f \\<in> insert f X\"\n  by simp\n \nlemma lookup_Some_in_dom: \"\\<Gamma> p = Some bdy \\<Longrightarrow> p \\<in> dom \\<Gamma>\"\n  by auto\n\nlemma unit_object: \"(\\<forall>u::unit. P u) = P ()\"\n  by auto\n\nlemma unit_ex: \"(\\<exists>u::unit. P u) = P ()\"\n  by auto\n\nlemma unit_meta: \"(\\<And>(u::unit). PROP P u) \\<equiv> PROP P ()\"\n  by auto\n\nlemma unit_UN: \"(\\<Union>z::unit. P z) = P ()\"\n  by auto\n\nlemma subset_singleton_insert1: \"y = x \\<Longrightarrow> {y} \\<subseteq> insert x A\"\n  by auto\n\nlemma subset_singleton_insert2: \"{y} \\<subseteq> A \\<Longrightarrow> {y} \\<subseteq> insert x A\"\n  by auto\n\nlemma in_Specs_simp: \"(\\<forall>x\\<in>\\<Union>Z. {(P Z, p, Q Z, A Z)}. Prop x) =\n       (\\<forall>Z. Prop (P Z,p,Q Z,A Z))\"\n  by auto\n\nlemma in_set_Un_simp: \"(\\<forall>x\\<in>A \\<union> B. P x) = ((\\<forall>x \\<in> A. P x) \\<and> (\\<forall>x \\<in> B. P x))\"\n  by auto\n\nlemma split_all_conj: \"(\\<forall>x. P x \\<and> Q x) = ((\\<forall>x. P x) \\<and> (\\<forall>x. Q x))\"\n  by blast\n\nlemma image_Un_single_simp: \"f ` (\\<Union>Z. {P Z}) = (\\<Union>Z. {f (P Z)}) \"\n  by auto\n\n\n\nlemma measure_lex_prod_def': \n  \"f <*mlex*> r \\<equiv> ({(x,y). (x,y) \\<in> measure f \\<or> f x=f y \\<and> (x,y) \\<in>  r})\"\n  by (auto simp add: mlex_prod_def inv_image_def)\n\nlemma in_measure_iff: \"(x,y) \\<in> measure f = (f x < f y)\"\n  by (simp add: measure_def inv_image_def)\n\nlemma in_lex_iff: \n  \"((a,b),(x,y)) \\<in> r <*lex*> s = ((a,x) \\<in> r \\<or> (a=x \\<and> (b,y)\\<in>s))\"\n  by (simp add: lex_prod_def)\n\nlemma in_mlex_iff:\n  \"(x,y) \\<in> f <*mlex*> r = (f x < f y \\<or> (f x=f y \\<and> (x,y) \\<in> r))\"\n  by (simp add: measure_lex_prod_def' in_measure_iff)\n\nlemma in_inv_image_iff: \"(x,y) \\<in> inv_image r f = ((f x, f y) \\<in> r)\" \n  by (simp add: inv_image_def)\n\ntext {* This is actually the same as @{thm [source] wf_mlex}. However, this basic\nproof took me so long that I'm not willing to delete it.\n*}\nlemma wf_measure_lex_prod [simp,intro]:\n  assumes wf_r: \"wf r\"\n  shows \"wf (f <*mlex*> r)\"\nproof (rule ccontr)\n  assume \" \\<not> wf (f <*mlex*> r)\"\n  then\n  obtain g where \"\\<forall>i. (g (Suc i), g i) \\<in> f <*mlex*> r\"\n    by (auto simp add: wf_iff_no_infinite_down_chain)\n  hence g: \"\\<forall>i. (g (Suc i), g i) \\<in> measure f \\<or>\n    f (g (Suc i)) = f (g i) \\<and> (g (Suc i), g i) \\<in> r\"\n    by (simp add: measure_lex_prod_def')\n  hence le_g: \"\\<forall>i. f (g (Suc i)) \\<le> f (g i)\"\n    by (auto simp add: in_measure_iff order_le_less)\n  have \"wf (measure f)\"\n    by simp\n  hence \" \\<forall>Q. (\\<exists>x. x \\<in> Q) \\<longrightarrow> (\\<exists>z\\<in>Q. \\<forall>y. (y, z) \\<in> measure f \\<longrightarrow> y \\<notin> Q)\"\n    by (simp add: wf_eq_minimal)\n  from this [rule_format, of \"g ` UNIV\"]\n  have \"\\<exists>z. z \\<in> range g \\<and> (\\<forall>y. (y, z) \\<in> measure f \\<longrightarrow> y \\<notin> range g)\"\n    by auto\n  then obtain z where \n    z: \"z \\<in> range g\" and\n    min_z: \"\\<forall>y. f y < f z \\<longrightarrow> y \\<notin> range g\"\n    by (auto simp add: in_measure_iff)\n  from z obtain k where \n    k: \"z = g k\"\n    by auto\n  have \"\\<forall>i. k \\<le> i \\<longrightarrow> f (g i) = f (g k)\" \n  proof (intro allI impI) \n    fix i\n    assume \"k \\<le> i\" then show \"f (g i) = f (g k)\"\n    proof (induct i)\n      case 0\n      have \"k \\<le> 0\" by fact hence \"k = 0\" by simp\n      thus \"f (g 0) = f (g k)\"\n        by simp\n    next\n      case (Suc n)\n      have k_Suc_n: \"k \\<le> Suc n\" by fact\n      then show \"f (g (Suc n)) = f (g k)\"\n      proof (cases \"k = Suc n\")\n        case True\n        thus ?thesis by simp\n      next\n        case False\n        with k_Suc_n\n        have \"k \\<le> n\"\n          by simp\n        with Suc.hyps\n        have n_k: \"f (g n) = f (g k)\" by simp\n        from le_g have le: \"f (g (Suc n)) \\<le> f (g n)\"\n          by simp\n        show ?thesis\n        proof (cases \"f (g (Suc n)) = f (g n)\")\n          case True with n_k show ?thesis by simp\n        next\n          case False\n          with le have \"f (g (Suc n)) < f (g n)\"\n            by simp\n          with n_k k have \"f (g (Suc n)) < f z\"\n            by simp\n          with min_z have \"g (Suc n) \\<notin> range g\"\n            by blast\n          hence False by simp\n          thus ?thesis\n            by simp\n        qed\n      qed\n    qed\n  qed\n  with k [symmetric] have \"\\<forall>i. k \\<le> i \\<longrightarrow> f (g i) = f z\" \n    by simp\n  hence \"\\<forall>i. k \\<le> i \\<longrightarrow> f (g (Suc i)) = f (g i)\"\n    by simp\n  with g have \"\\<forall>i. k \\<le> i \\<longrightarrow> (g (Suc i),(g i)) \\<in> r\"\n    by (auto simp add: in_measure_iff order_less_le )\n  hence \"\\<forall>i. (g (Suc (i+k)),(g (i+k))) \\<in> r\"\n    by simp\n  then\n  have \"\\<exists>f. \\<forall>i. (f (Suc i), f i) \\<in> r\"\n    by - (rule exI [where x=\"\\<lambda>i. g (i+k)\"],simp) \n  with wf_r show False\n    by (simp add: wf_iff_no_infinite_down_chain)\nqed\n\nlemmas all_imp_to_ex = all_simps (5)  \n(*\"!!P Q. (ALL x. P x --> Q) = ((EX x. P x) --> Q)\"\n\n Avoid introduction of existential quantification of states on negative\n position.\n*)\n\n", "meta": {"author": "CompSoftVer", "repo": "CSim", "sha": "816d36b7523796ace031c429003d82e9244eff9c", "save_path": "github-repos/isabelle/CompSoftVer-CSim", "path": "github-repos/isabelle/CompSoftVer-CSim/CSim-816d36b7523796ace031c429003d82e9244eff9c/CSimpl/Hoare.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5078118642792044, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.27370207411262276}}
{"text": "(******************************************************************************\n * Orca: A Functional Correctness Verifier for Imperative Programs\n *       Based on Isabelle/UTP\n *\n * Copyright (c) 2016-2018 Virginia Tech, USA\n *               2016-2018 Technische Universität München, Germany\n *               2016-2018 University of York, UK\n *               2016-2018 Université Paris-Saclay, Univ. Paris-Sud, France\n *\n * This software may be distributed and modified according to the terms of\n * the GNU Lesser General Public License version 3.0 or any later version.\n * Note that NO WARRANTY is provided.\n *\n * See CONTRIBUTORS, LICENSE and CITATION files for details.\n ******************************************************************************)\n\nsection \\<open>Algebraic laws of programming\\<close>\n\ntext \\<open>In this section we introduce the semantic rules related to the different\n      statements of IMP. In the literature this also known as the algebraic laws of programming.\n      In our framework we will use these rules in order to optimize a given program written in our\n      language, and this before any deductive proof verification activity or formal testing.\\<close>\n\ntheory Algebraic_laws_design\n  imports Algebraic_laws_design_aux\nbegin\n\nsection {*Algebraic laws for designs constructs*}\n\nsubsection Skip\n\ntext \\<open>In this section we introduce the algebraic laws of programming related to the SKIP\n      statement.\\<close>\n\nlemma skip_left_unit_design:\n  fixes P :: \"'a hrel_des\"\n  assumes \"P is \\<^bold>H\"\n  shows\"(SKIP\\<^sub>D ;; P) = P\"\n  by (simp add: H1_H2_impl_H1 H1_left_unit assms)   \n\nlemmas skip_left_unit_ndesign = skip_left_unit_design[OF H1_H3_impl_H2]\n\nlemma true_left_zero_skip_cpaD[udes_comp]:\n  \"(SKIP\\<^sub>D;; true) = (true)\"\n  by rel_auto\n\nlemma true_liftD_left_zero_skipD[udes_comp]:\n  \"(SKIP\\<^sub>D;; \\<lceil>true\\<rceil>\\<^sub>D) = (\\<lceil>true\\<rceil>\\<^sub>D)\"\n  by rel_auto\n\nlemma false_liftD_left_zero_skipD[udes_comp]:\n  \"(SKIP\\<^sub>D;; \\<lceil>false\\<rceil>\\<^sub>D) = (\\<lceil>false\\<rceil>\\<^sub>D)\"\n  by rel_auto\n\nlemma skipD_left_unit_assignsD[udes_comp]:\n  \"(SKIP\\<^sub>D;; \\<langle>\\<sigma>\\<rangle>\\<^sub>D) = (\\<langle>\\<sigma>\\<rangle>\\<^sub>D)\"\n  by rel_auto\n\nlemma skipD_topD_right_zero[udes_comp]:\n  \"(SKIP\\<^sub>D;; \\<top>\\<^sub>D) = (\\<top>\\<^sub>D)\"\n  by rel_auto\n\nlemma skipD_uvar_left_zero[udes_comp]:\n  \"($x;; SKIP\\<^sub>D) = $x\"\n  by rel_auto\n\nlemma skipD_bot_left_zero[udes_comp]:\n  \"(\\<top>\\<^sub>D;; SKIP\\<^sub>D) = (\\<top>\\<^sub>D)\"\n  by rel_auto\n\nlemma skip_d_alpha_eq:\n  \"SKIP\\<^sub>D =  ($ok \\<Rightarrow> ($ok\\<acute> \\<and> ($\\<Sigma>\\<^sub>D\\<acute> =\\<^sub>u $\\<Sigma>\\<^sub>D)))\"\n   by rel_simp\n\nlemma simpl_pre_skip_d_post:\n  \"(\\<lceil>b\\<rceil>\\<^sub>D\\<^sub>< \\<and> SKIP\\<^sub>D =\\<^sub>u $ok) = (SKIP\\<^sub>D =\\<^sub>u $ok \\<and> \\<lceil>b\\<rceil>\\<^sub>D\\<^sub>>)\"\n  by rel_auto\n\nlemma simpl_pre_skip_d_var:\n  fixes x :: \"(bool \\<Longrightarrow> 'b des)\"\n  shows \"($x \\<and> SKIP\\<^sub>D =\\<^sub>u $ok) = (SKIP\\<^sub>D =\\<^sub>u $ok \\<and> $x\\<acute>)\"\n  by rel_auto\n\nlemma skip_d_is_H1_H2:\n  \"SKIP\\<^sub>D is \\<^bold>H\" \n  by rel_auto\n\nlemma skip_d_post_left_unit[udes_comp]:\n  \"(S \\<turnstile> (SKIP\\<^sub>D;; Q)) = (S \\<turnstile> Q)\"\n  apply pred_simp\n  apply rel_simp\n  apply fastforce\n  done\n    \nlemma skip_refine_des:\n  assumes \"`(SKIP\\<^sub>D \\<Rightarrow> (p \\<turnstile> q))`\"\n  shows \" (p \\<turnstile> q) \\<sqsubseteq> SKIP\\<^sub>D\"\nproof (rule refine_reverse_impl, goal_cases)\n  case 1\n  then show ?case using assms by pred_simp \nqed\n\nlemma skip_d_left_unit:\n  \"P is H1 \\<Longrightarrow> SKIP\\<^sub>D ;; P = P\"\n  by rel_blast\n    \nsubsection \\<open>Assignment Laws\\<close>\ntext \\<open>In this section we introduce the algebraic laws of programming related to the assignment\n      statement.\\<close>\n\nlemma usubst_d_cancel [usubst]:\n  assumes 1:\"weak_lens v\"\n  shows \"($v)\\<lbrakk>\\<lceil>expr\\<rceil>\\<^sub>D\\<^sub></$v\\<rbrakk> = \\<lceil>expr\\<rceil>\\<^sub>D\\<^sub><\"\n  using 1\n  by  rel_auto\n\nlemma usubst_d_lift_cancel[usubst]:\n  assumes 1:\"weak_lens v\"\n  shows \"\\<lceil>($v)\\<lbrakk>\\<lceil>expr\\<rceil>\\<^sub></$v\\<rbrakk>\\<rceil>\\<^sub>D = \\<lceil>expr\\<rceil>\\<^sub>D\\<^sub><\"\n  using 1\n  by  rel_auto\n\nlemma assigns_d_id: \n  \"SKIP\\<^sub>D = \\<langle>id\\<rangle>\\<^sub>D\"\n  unfolding skip_d_def assigns_d_def\n  by (rel_auto)\n    \nlemma assign_design_test[udes_comp]:\n  assumes 1:\"mwb_lens x\"\n  shows     \"(x :=\\<^sub>D \\<guillemotleft>u\\<guillemotright>;; x :=\\<^sub>D \\<guillemotleft>v\\<guillemotright>) = (x :=\\<^sub>D \\<guillemotleft>v\\<guillemotright>)\"\n  using 1\n  by (simp add: usubst udes_comp)\n\nlemma assigns_d_left_comp_subst[udes_comp]:\n  \"(x :=\\<^sub>D u;; (\\<lceil>P\\<rceil>\\<^sub>D \\<turnstile> \\<lceil>Q\\<rceil>\\<^sub>D)) = (\\<lceil>P\\<lbrakk>\\<lceil>u\\<rceil>\\<^sub></$x\\<rbrakk>\\<rceil>\\<^sub>D \\<turnstile> \\<lceil>Q\\<lbrakk>\\<lceil>u\\<rceil>\\<^sub></$x\\<rbrakk>\\<rceil>\\<^sub>D)\"\n  by rel_blast\n\nlemma assigns_d_left_comp_subst_hdesigns[udes_comp]:\n  assumes \"P is \\<^bold>H\"\n  shows \"(x :=\\<^sub>D u;; (P)) = (\\<lceil>[x \\<mapsto>\\<^sub>s u]\\<rceil>\\<^sub>s\\<^sub>D \\<dagger> P)\" (*fix the syntax sugar for substitution lifting*)\n  using assms  \n  by rel_blast\n    \nlemmas assigns_d_left_comp_subst_ndesigns[udes_comp] = \n  assigns_d_left_comp_subst_hdesigns[OF H1_H3_impl_H2] \n\nlemma assign_d_twice[udes_comp]:\n  assumes \"mwb_lens x\" and  \"x \\<sharp> f\"\n  shows \"(x :=\\<^sub>D e;; x :=\\<^sub>D f) = (x :=\\<^sub>D f)\"\n  using assms\n  by (simp add: udes_comp usubst)\n\nlemma assigns_d_commute:\n  assumes \"x \\<bowtie> y\" \"x \\<sharp> f\" \"y \\<sharp> e\"\n  shows \"(x :=\\<^sub>D e ;; y :=\\<^sub>D f) = (y :=\\<^sub>D f ;; x :=\\<^sub>D e)\"\n  using assms\n  by (simp add: udes_comp usubst usubst_upd_comm)\n\nlemma assigns_d_left_cond_d_H1[udes_comp]: (*needs more laws to be automatic*)\n  fixes x :: \"('a \\<Longrightarrow> '\\<alpha>)\"\n  assumes \"P is H1\" and \"Q is H1\"  \n  shows \"(x :=\\<^sub>D e ;; (bif\\<^sub>D b then P else Q eif)) =\n         (bif\\<^sub>D (b\\<lbrakk>e/x\\<rbrakk>) then (x :=\\<^sub>D e;; P) else (x :=\\<^sub>D e ;; Q) eif)\"\n  using assms  \n  apply (simp add: usubst udes_comp)\n  apply rel_simp\n  apply smt\n  done    \nlemmas assigns_d_left_cond_d_hdesigns[udes_comp] = \n  assigns_d_left_cond_d_H1[OF H1_H2_impl_H1 H1_H2_impl_H1]\n\nlemmas assigns_d_left_cond_d_ndesigns[udes_comp] = \n  assigns_d_left_cond_d_hdesigns[OF H1_H3_impl_H2 H1_H3_impl_H2]   \n  \nlemma assigns_d_uop1[udes_comp]:\n  assumes 1: \"mwb_lens v\"\n  shows \"(v :=\\<^sub>D e1;; v :=\\<^sub>D (uop F (&v))) = (v :=\\<^sub>D (uop F e1))\"\n  by (simp add: usubst udes_comp assms)\n\nlemma assign_d_bop1[udes_comp]:\n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\"\n  shows \"(v :=\\<^sub>D e1;; v :=\\<^sub>D (bop bp (&v) e2)) = (v :=\\<^sub>D (bop bp e1 e2))\"\n  by (simp add: usubst udes_comp assms)\n\nlemma assign_d_bop2[udes_comp]:\n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\"\n  shows \"(v :=\\<^sub>D e1;; v :=\\<^sub>D (bop bp e2 (&v))) = (v :=\\<^sub>D (bop bp e2 e1))\"\n  by (simp add: usubst udes_comp assms)\n\nlemma assign_d_trop1[udes_comp]:\n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\"\n  shows \"(v :=\\<^sub>D e1;; v :=\\<^sub>D (trop tp (&v) e2 e3)) =\n         (v :=\\<^sub>D (trop tp e1 e2 e3))\"\n  by (simp add: usubst udes_comp assms)\n\nlemma assign_d_trop2[udes_comp]:\n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\"\n  shows \"(v :=\\<^sub>D e1;; v :=\\<^sub>D (trop tp e2 (&v) e3)) =\n         (v :=\\<^sub>D (trop tp e2 e1 e3))\"\n  by (simp add: usubst udes_comp assms)\n\nlemma assign_d_trop3[udes_comp]:\n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\"\n  shows \"(v :=\\<^sub>D e1;; v :=\\<^sub>D (trop tp e2 e3 (&v))) =\n         (v :=\\<^sub>D (trop tp e2 e3 e1))\"\n  by (simp add: usubst udes_comp assms)\n\nlemma assign_d_qtop1[udes_comp]:\n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\" and 4:\"v \\<sharp> e4\"\n  shows \"(v :=\\<^sub>D e1;; v :=\\<^sub>D (qtop tp (&v) e2 e3 e4)) =\n         (v :=\\<^sub>D (qtop tp e1 e2 e3 e4))\"\n  by (simp add: usubst udes_comp assms)\n\nlemma assign_d_qtop2[udes_comp]:\n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\" and 4:\"v \\<sharp> e4\"\n  shows \"(v :=\\<^sub>D e1;; v :=\\<^sub>D (qtop tp e2 (&v) e3 e4)) =\n         (v :=\\<^sub>D (qtop tp e2 e1 e3 e4))\"\n  by (simp add: usubst udes_comp assms)\n\nlemma assign_d_qtop3[udes_comp]:\n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\" and 4:\"v \\<sharp> e4\"\n  shows \"(v :=\\<^sub>D e1;; v :=\\<^sub>D (qtop tp e2 e3 (&v) e4)) =\n         (v :=\\<^sub>D (qtop tp e2 e3 e1 e4))\"\n  by (simp add: usubst udes_comp assms)\n\nlemma assign_d_qtop4[udes_comp]:\n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\" and 4:\"v \\<sharp> e4\"\n  shows \"(v :=\\<^sub>D e1;; v :=\\<^sub>D (qtop tp e2 e3 e4 (&v))) =\n         (v :=\\<^sub>D (qtop tp e2 e3 e4 e1))\"\n  by (simp add: usubst udes_comp assms)\n\ntext \\<open>In the sequel we define assignment laws proposed by Hoare\\<close>\n\nlemma assign_d_vwb_skip_d[udes_comp]:\n  assumes 1: \"vwb_lens v\"\n  shows \"(v :=\\<^sub>D &v) = SKIP\\<^sub>D\"\n  by (simp add: assms usubst)\n\nlemma assign_d_simultaneous:\n  assumes  1: \"vwb_lens var2\"\n  and      2: \"var1 \\<bowtie> var2\"\n  shows \"var1, var2 :=\\<^sub>D expr, &var2 = var1 :=\\<^sub>D expr\"\n  by (simp add: assms usubst_upd_comm usubst)\n\nlemma assign_d_seq[udes_comp]:\n  assumes  1: \"vwb_lens var2\"\n  shows\"(var1 :=\\<^sub>D expr);; (var2 :=\\<^sub>D &var2) = (var1 :=\\<^sub>D expr)\"\n  using assms by rel_blast\n    \nlemma assign_d_cond_d_uop_H1[udes_comp]: (*needs more laws to be automatic*)\n  assumes \"P is H1\" and \"Q is H1\" and 1: \"weak_lens v\"  \n  shows \"bif\\<^sub>D uop F expr then (v :=\\<^sub>D expr;; P) else (v :=\\<^sub>D expr ;; Q) eif =\n          v :=\\<^sub>D expr;; bif\\<^sub>D uop F (&v) then P else Q eif\"\n  using assms\n  by (simp add: assigns_d_left_cond_d_H1 subst_uop usubst_cancel)\n    \nlemmas assign_d_cond_d_uop_hdesigns[udes_comp] = \n    assign_d_cond_d_uop_H1 [OF H1_H2_impl_H1 H1_H2_impl_H1]\n    \nlemmas assign_d_cond_d_uop_ndesigns [udes_comp] = \n  assign_d_cond_d_uop_hdesigns[OF H1_H3_impl_H2 H1_H3_impl_H2] \n  \nlemma assign_d_cond_d_bop1_H1[udes_comp]: (*needs more laws to be automatic*)\n  assumes \"P is H1\" and \"Q is H1\" and 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" \n  shows \"bif\\<^sub>D bop bp expr exp2 then (v :=\\<^sub>D expr;; P) else (v :=\\<^sub>D expr;; Q) eif =\n          v :=\\<^sub>D expr;; bif\\<^sub>D bop bp (&v) exp2 then P else Q eif\"\n  using assms\n  by (simp add: assigns_d_left_cond_d_H1 subst_bop subst_to_singleton(2) subst_unrest usubst_cancel)\n\nlemmas assign_d_cond_d_bop1_hdesigns[udes_comp] =\n  assign_d_cond_d_bop1_H1 [OF H1_H2_impl_H1 H1_H2_impl_H1] \n     \nlemmas assign_d_cond_d_bop1_ndesigns[udes_comp] = \n  assign_d_cond_d_bop1_hdesigns [OF H1_H3_impl_H2 H1_H3_impl_H2] \n    \nlemma assign_d_cond_d_bop2_H1[udes_comp]: (*needs more laws to be automatic*)\n  assumes \"P is H1\" and \"Q is H1\" and 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\"\n  shows \"bif\\<^sub>D bop bp exp2 expr then (v :=\\<^sub>D expr;; P) else (v :=\\<^sub>D expr;; Q) eif =\n          v :=\\<^sub>D expr;; bif\\<^sub>D bop bp exp2 (&v) then P else Q eif\"\n  using assms  \n  by (simp add: assigns_d_left_cond_d_H1 subst_bop subst_to_singleton(2) subst_unrest usubst_cancel)\n\nlemmas assign_d_cond_d_bop2_hdesigns[udes_comp] =\n  assign_d_cond_d_bop2_H1 [OF H1_H2_impl_H1 H1_H2_impl_H1]     \n    \nlemmas assign_d_cond_d_bop2_ndesigns[udes_comp] = \n  assign_d_cond_d_bop2_hdesigns [OF H1_H3_impl_H2 H1_H3_impl_H2] \n\nlemma assign_d_cond_d_trop1_H1[udes_comp]: (*needs more laws to be automatic*)\n  assumes \"P is H1\" and \"Q is H1\" and 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\"\n  shows \"bif\\<^sub>D trop bp expr exp2 exp3 then (v :=\\<^sub>D expr;; P) else (v :=\\<^sub>D expr;; Q) eif =\n         v :=\\<^sub>D expr;; bif\\<^sub>D trop bp (&v) exp2 exp3 then P else Q eif\"\n  using assms  \n  by (simp add: assigns_d_left_cond_d_H1 subst_trop subst_to_singleton(2) subst_unrest usubst_cancel)\n\nlemmas assign_d_cond_d_trop1_hdesigns[udes_comp] =   \n    assign_d_cond_d_trop1_H1 [OF H1_H2_impl_H1 H1_H2_impl_H1]\n    \nlemmas assign_d_cond_d_trop1_ndesigns[udes_comp] = \n  assign_d_cond_d_trop1_hdesigns [OF H1_H3_impl_H2 H1_H3_impl_H2]\n  \nlemma assign_d_cond_d_trop2_H1[udes_comp]: (*needs more laws to be automatic*)\n  assumes \"P is H1\" and \"Q is H1\" and 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\"\n  shows \"bif\\<^sub>D trop bp exp2 expr exp3 then (v :=\\<^sub>D expr;; P) else (v :=\\<^sub>D expr;; Q) eif =\n         v :=\\<^sub>D expr;; bif\\<^sub>D trop bp  exp2 (&v) exp3 then P else Q eif\"\n  using assms  \n  by (simp add: assigns_d_left_cond_d_H1 subst_trop subst_to_singleton(2) subst_unrest usubst_cancel)\n\nlemmas assign_d_cond_d_trop2_hdesigns[udes_comp] =   \n    assign_d_cond_d_trop2_H1 [OF H1_H2_impl_H1 H1_H2_impl_H1]\n      \nlemmas assign_d_cond_d_trop2_ndesigns[udes_comp] = \n  assign_d_cond_d_trop2_hdesigns [OF H1_H3_impl_H2 H1_H3_impl_H2]    \n\nlemma assign_d_cond_d_trop3_H1[udes_comp]: (*needs more laws to be automatic*)\n  assumes \"P is H1\" and \"Q is H1\" and 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\"\n  shows \"bif\\<^sub>D trop bp exp2 exp3 expr then (v :=\\<^sub>D expr;; P) else (v :=\\<^sub>D expr;; Q) eif =\n         v :=\\<^sub>D expr;; bif\\<^sub>D trop bp exp2 exp3 (&v) then P else Q eif\"\n  using assms  \n  by (simp add: assigns_d_left_cond_d_H1 subst_trop subst_to_singleton(2) subst_unrest usubst_cancel)\n\nlemmas assign_d_cond_d_trop3_hdesigns[udes_comp] =   \n    assign_d_cond_d_trop3_H1 [OF H1_H2_impl_H1 H1_H2_impl_H1]\n    \nlemmas assign_d_cond_d_trop3_ndesigns[udes_comp] = \n  assign_d_cond_d_trop3_hdesigns [OF H1_H3_impl_H2 H1_H3_impl_H2]\n  \nlemma assign_d_cond_d_qtop1_H1[udes_comp]: (*needs more laws to be automatic*)\n  assumes \"P is H1\" and \"Q is H1\" and 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\" and 4: \"v \\<sharp> exp4\"\n  shows \"bif\\<^sub>D qtop bp expr exp2 exp3 exp4 then (v :=\\<^sub>D expr;; P) else (v :=\\<^sub>D expr;; Q) eif =\n         v :=\\<^sub>D expr;; bif\\<^sub>D qtop bp (&v) exp2 exp3 exp4 then P else Q eif\"\n  using assms  \n  by (simp add: assigns_d_left_cond_d_H1 subst_qtop subst_to_singleton(2) subst_unrest usubst_cancel)\n\nlemmas assign_d_cond_d_qtop1_hdesigns[udes_comp] =     \n     assign_d_cond_d_qtop1_H1 [OF H1_H2_impl_H1 H1_H2_impl_H1]\n     \nlemmas assign_d_cond_d_qtop1_ndesigns[udes_comp] = \n  assign_d_cond_d_qtop1_hdesigns [OF H1_H3_impl_H2 H1_H3_impl_H2]\n  \nlemma assign_d_cond_d_qtop2_H1[udes_comp]: (*needs more laws to be automatic*)\n  assumes \"P is H1\" and \"Q is H1\" and 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\" and 4:\"v \\<sharp> exp4\"\n  shows \"bif\\<^sub>D qtop bp exp2 expr  exp3 exp4 then (v :=\\<^sub>D expr;;P) else (v :=\\<^sub>D expr;; Q) eif =\n         v :=\\<^sub>D expr;; bif\\<^sub>D qtop bp exp2 (&v) exp3 exp4 then P else Q eif\"\n  using assms  \n  by (simp add: assigns_d_left_cond_d_H1 subst_qtop subst_to_singleton(2) subst_unrest usubst_cancel)\n\nlemmas  assign_d_cond_d_qtop2_hdesigns[udes_comp] =     \n  assign_d_cond_d_qtop2_H1[OF H1_H2_impl_H1 H1_H2_impl_H1]\n  \nlemmas assign_d_cond_d_qtop2_ndesigns[udes_comp] = \n  assign_d_cond_d_qtop2_hdesigns [OF H1_H3_impl_H2 H1_H3_impl_H2]\n  \nlemma assign_d_cond_d_qtop3_H1[udes_comp]: (*needs more laws to be automatic*)\n  assumes \"P is H1\" and \"Q is H1\" and 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\" and 4: \"v \\<sharp> exp4\"\n  shows \"bif\\<^sub>D qtop bp exp2 exp3 expr exp4 then (v :=\\<^sub>D expr;;P) else (v :=\\<^sub>D expr;; Q) eif =\n         v :=\\<^sub>D expr;; bif\\<^sub>D qtop bp exp2 exp3 (&v) exp4 then P else Q eif\"\n  using assms  \n  by (simp add: assigns_d_left_cond_d_H1 subst_qtop subst_to_singleton(2) subst_unrest usubst_cancel)\n\nlemmas  assign_d_cond_d_qtop3_hdesigns[udes_comp] =     \n  assign_d_cond_d_qtop3_H1[OF H1_H2_impl_H1 H1_H2_impl_H1]\n  \nlemmas assign_d_cond_d_qtop3_ndesigns[udes_comp] = \n  assign_d_cond_d_qtop3_hdesigns [OF H1_H3_impl_H2 H1_H3_impl_H2]\n\nlemma assign_d_cond_d_qtop4_H1[udes_comp]: (*needs more laws to be automatic*)\n  assumes \"P is H1\" and \"Q is H1\" and 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\" and 4: \"v \\<sharp> exp4\"\n  shows \"bif\\<^sub>D qtop bp exp2 exp3 exp4 expr then (v :=\\<^sub>D expr;; P) else (v :=\\<^sub>D expr;; Q) eif =\n         v :=\\<^sub>D expr;; bif\\<^sub>D qtop bp exp2  exp3 exp4 (&v) then P else Q eif\"\n  using assms  \n  by (simp add: assigns_d_left_cond_d_H1 subst_qtop subst_to_singleton(2) subst_unrest usubst_cancel)\n\nlemmas  assign_d_cond_d_qtop4_hdesigns[udes_comp] =     \n  assign_d_cond_d_qtop4_H1[OF H1_H2_impl_H1 H1_H2_impl_H1]\n  \nlemmas assign_d_cond_d_qtop4_ndesigns[udes_comp] = \n  assign_d_cond_d_qtop4_hdesigns[OF H1_H3_impl_H2 H1_H3_impl_H2]\n    \nlemma assign_d_cond_d_If [udes_cond]:\n  \"(bif\\<^sub>D bexp then (v :=\\<^sub>D exp1) else (v :=\\<^sub>D exp2) eif) =\n   (v :=\\<^sub>D (exp1 \\<triangleleft> bexp \\<triangleright> exp2))\"\n  by rel_auto\n\nsubsection \\<open>Sequential composition laws for designs\\<close>\n\nlemma weaker_seq_r_H1_H2_closed[closure]:\n  assumes \"P is H1\"  \"Q is \\<^bold>H\"\n  shows \"(P ;; Q) is \\<^bold>H\"\nproof -\n  obtain Q\\<^sub>1 Q\\<^sub>2 where Q_def:\"Q = Q\\<^sub>1 \\<turnstile>\\<^sub>r Q\\<^sub>2\" and Q\\<^sub>1_Q\\<^sub>2_is_H1_H2:\"Q\\<^sub>1 \\<turnstile>\\<^sub>r Q\\<^sub>2 is \\<^bold>H\"\n    using assms(2) unfolding Healthy_def\n   by (metis H1_H2_eq_rdesign )\n   moreover have \"(P ;; (Q\\<^sub>1 \\<turnstile>\\<^sub>r Q\\<^sub>2)) is \\<^bold>H\"\n   proof -\n     have *:\"H1 P = P\" \n       using assms(1)[unfolded Healthy_def] .\n     then show ?thesis using Q\\<^sub>1_Q\\<^sub>2_is_H1_H2 unfolding  Healthy_def H2_def \n       by (simp add: H1_rdesign H1_distrib_left_J H1_distrib_left_rdesign  seqr_assoc')\n     qed \n  ultimately show ?thesis by simp\nqed      \n  \nlemma weaker_seq_r_H1_H3_closed:\n  assumes 1: \"P is H1\"\n  assumes 2: \"Q is \\<^bold>N\"\n  shows      \"(P;; Q) is \\<^bold>N\" \nproof -\n from 1 2 have 11:\"\\<lfloor>pre\\<^sub>D Q\\<rfloor>\\<^sub>< \\<turnstile>\\<^sub>n post\\<^sub>D Q = Q\"\n    by (metis ndesign_form)\n  then show ?thesis\n    using 1 2 \n  proof -\n    have seq_r_H1_H2_closed_def: \"\\<forall>P Q. \\<not> (P is H1) \\<or> \\<not> (Q is \\<^bold>H) \\<or> P ;; Q is (\\<lambda>P. \\<^bold>H P)\"\n      using weaker_seq_r_H1_H2_closed by fastforce\n    have \"\\<forall>P. (P is \\<^bold>N \\<longrightarrow> P is \\<^bold>H) = (\\<not> (P is \\<^bold>N) \\<or> P is \\<^bold>H)\"\n      by auto\n    then have \"\\<forall>P. \\<not> (P is \\<^bold>N) \\<or> P is \\<^bold>H\" \n      using H1_H3_impl_H2 by blast\n    then have \"Q is \\<^bold>H\" using 2\n           by blast\n    then have \"P ;; Q is (\\<lambda>P. \\<^bold>H P)\"\n      using seq_r_H1_H2_closed_def 1 by blast \n    from this[THEN H1_H2_impl_H1] show ?thesis \n      using 11[simplified HOL.eq_commute] H3_ndesign[of \"\\<lfloor>pre\\<^sub>D Q\\<rfloor>\\<^sub><\" \"post\\<^sub>D Q\"]\n        unfolding Healthy_def H3_def \n        by (metis seqr_assoc)\n  qed\nqed\n\ntheorem H1_H3_eq_ndesign:\n  assumes 1:\"out\\<alpha> \\<sharp> pre\\<^sub>D(P)\"\n  shows   \"(\\<^bold>N(P)) = (\\<lfloor>pre\\<^sub>D(P)\\<rfloor>\\<^sub>< \\<turnstile>\\<^sub>n post\\<^sub>D(P))\"\nproof -\n  from 1 have f2: \"H3 P = H3 (H2 P)\"\n     by (metis H2_H3_absorb H2_H3_commute)\n  have \"\\<^bold>H P = \\<lfloor>pre\\<^sub>D P\\<rfloor>\\<^sub>< \\<turnstile>\\<^sub>n post\\<^sub>D P\"\n    using 1 by (simp add: H1_H2_eq_rdesign ndesign_def)\n  then show ?thesis\n    using f2 by (simp add: H1_H3_commute H3_ndesign)\nqed \n  \nsubsection \\<open>Conditional laws for designs\\<close> \n \nlemma if_d_true:\n  \"bif\\<^sub>D true then P else Q eif = P\"  \n  by rel_simp\n    \nlemma if_d_false:\n  \"bif\\<^sub>D false then P else Q eif = Q\"  \n  by rel_simp\n    \nlemma ifd_rdesign_pre_post:\n  assumes P_is_H:\"P is \\<^bold>H\"\n  assumes Q_is_H:\"Q is \\<^bold>H\"   \n  shows   \n   \"bif\\<^sub>D b then P else Q eif = \n    bif\\<^sub>D b then (pre\\<^sub>D P) \\<turnstile>\\<^sub>r post\\<^sub>D P else (pre\\<^sub>D Q) \\<turnstile>\\<^sub>r post\\<^sub>D Q eif\" \nproof -\n show ?thesis     \n  using rdesign_split P_is_H Q_is_H \n  by metis    \nqed\n\ntheorem rdesign_dcond:\n  \"bif\\<^sub>D b then (P\\<^sub>1 \\<turnstile>\\<^sub>r P\\<^sub>2) else (Q\\<^sub>1 \\<turnstile>\\<^sub>r Q\\<^sub>2) eif = (P\\<^sub>1 \\<triangleleft> b \\<triangleright>\\<^sub>r Q\\<^sub>1) \\<turnstile>\\<^sub>r (P\\<^sub>2 \\<triangleleft> b \\<triangleright>\\<^sub>r Q\\<^sub>2)\"\n  by (rel_auto)   \n \nlemma  if_d_H1_H2_intro:   \n  assumes P_is_H: \"P is \\<^bold>H\" \n  assumes Q_is_H:\"Q is \\<^bold>H\"  \n  shows \"bif\\<^sub>D b then P else Q eif is \\<^bold>H\"\n  apply (subst rdesign_form [OF P_is_H, THEN  HOL.sym])  \n  apply (subst rdesign_form [OF Q_is_H, THEN  HOL.sym]) \n  apply (simp add: rdesign_dcond rdesign_is_H1_H2)\n  done\n    \nlemma  if_d_H1_H3_intro: \n  assumes unrest_1: \" out\\<alpha> \\<sharp> pre\\<^sub>D P\"\n  assumes unrest_2: \"out\\<alpha> \\<sharp> pre\\<^sub>D Q\"  \n  assumes P_is_H: \"P is \\<^bold>H\" \n  assumes Q_is_H:\"Q is \\<^bold>H\"  \n  shows \"bif\\<^sub>D b then P else Q eif is \\<^bold>N\"  \n  apply (subst H1_H3_intro[OF P_is_H unrest_1, THEN ndesign_form, THEN HOL.sym])  \n  apply (subst H1_H3_intro[OF Q_is_H unrest_2, THEN ndesign_form, THEN HOL.sym])  \n  apply (simp add: ndesign_H1_H3 ndesign_dcond)\n  done  \n\nlemma stronger_if_d_seq_r_H1_H2_closed:\n  assumes 1: \"P is H1\"\n  and     2: \"Q is \\<^bold>H\"\n  shows \"(\\<lambda>X. bif\\<^sub>D b then P ;; X else Q eif) \\<in> \\<lbrakk>\\<^bold>H\\<rbrakk>\\<^sub>H \\<rightarrow> \\<lbrakk>\\<^bold>H\\<rbrakk>\\<^sub>H\"   \nproof (rule  FuncSet.Pi_I)\n  fix x :: \"('b, 'a) rel_des\"\n  assume 11: \"x \\<in> \\<lbrakk>\\<^bold>H\\<rbrakk>\\<^sub>H\"      \n  have H2_seq_idemp: \"(P ;; x::'a hrel_des) = H2 (P ;; x)\"\n    using weaker_seq_r_H1_H2_closed[OF 1 11[THEN Set.CollectD]] rdesign_split \n    by (metis (no_types) H2_rdesign)  \n  have \"Q = H2 Q\"\n    using rdesign_split 2 by (metis (no_types) H2_rdesign)\n  then show \"bif\\<^sub>D b then P ;; x else Q eif \\<in> \\<lbrakk>\\<^bold>H\\<rbrakk>\\<^sub>H\"\n    using weaker_seq_r_H1_H2_closed[OF 1 11[THEN Set.CollectD]] 2\n      by (simp add: if_d_H1_H2_intro rdesign_is_H1_H2) \nqed  \n  \nlemma stronger_if_d_seq_r_H1_H3_closed:\n  assumes 1: \"P is H1\"\n  and     2: \"Q is \\<^bold>N\"\n  shows \"(\\<lambda>X. bif\\<^sub>D b then P ;; X else Q eif) \\<in> \\<lbrakk>\\<^bold>N\\<rbrakk>\\<^sub>H \\<rightarrow> \\<lbrakk>\\<^bold>N\\<rbrakk>\\<^sub>H\"   \nproof (rule  FuncSet.Pi_I)\n  fix x :: \"('b, 'a) rel_des\"\n  assume 11: \"x \\<in> \\<lbrakk>\\<^bold>N\\<rbrakk>\\<^sub>H\"\n  have H3_seq_idemp: \"(P ;; x::'a hrel_des) = H3 (P ;; x)\"\n    using weaker_seq_r_H1_H3_closed[OF 1 11[THEN Set.CollectD]] ndesign_split \n    by (metis (no_types) H3_ndesign)  \n  have \"Q = H3 Q\"\n    using ndesign_split 2 by (metis (no_types) H3_ndesign)\n  then show \"bif\\<^sub>D b then P ;; x else Q eif \\<in> \\<lbrakk>\\<^bold>N\\<rbrakk>\\<^sub>H\"\n    apply (subst weaker_seq_r_H1_H3_closed[OF 1 11[THEN Set.CollectD], THEN ndesign_form, THEN  HOL.sym])\n    apply (subst 2[THEN ndesign_form, THEN  HOL.sym])  \n    apply (simp add: ndesign_H1_H3 ndesign_dcond)\n    done                       \nqed \n\nlemma if_d_skip_d_not_ok:\n  \"bif\\<^sub>D true then SKIP\\<^sub>D ;; (\\<not> $ok) else SKIP\\<^sub>D eif = (\\<not> $ok)\"\n  by (simp add: aext_true des_top_ndes_def ndesign_def)\n    \nlemma if_d_skip_d_true:\n  \"bif\\<^sub>D true then SKIP\\<^sub>D ;; true else SKIP\\<^sub>D eif = true\"\n  by rel_simp\n\nlemma if_d_H4_true:\n  assumes \"body is H4\"\n  shows \"bif\\<^sub>D true then body ;; true else SKIP\\<^sub>D eif = true\"\n  using assms by rel_auto\n   \nlemma if_d_mono:\n  \"mono (\\<lambda>X. bif\\<^sub>D b then P ;; X else Q eif)\"\n  by (auto intro: monoI seqr_mono cond_mono) \n  \nsubsection \\<open>Recursion laws for designs\\<close>  \n\nlemma H1_H3_mu_refine_intro:\n  assumes 1:\"P is \\<^bold>N\"\n  assumes 2:\"P \\<sqsubseteq> F P\"\n  assumes 3:\"out\\<alpha> \\<sharp> pre\\<^sub>D(P)\"  \n  assumes 4:\"`\\<lceil>\\<lfloor>pre\\<^sub>D(P:: 'a hrel_des)\\<rfloor>\\<^sub><\\<rceil>\\<^sub>D\\<^sub><  \\<Rightarrow> (\\<mu>\\<^sub>N F \\<Leftrightarrow> \\<nu>\\<^sub>N F)`\"  \n  shows   \"P \\<sqsubseteq> \\<mu>\\<^sub>N F\"\nproof -\n  from 3 H1_H3_eq_ndesign[of P]\n  have is_H1_H3_eq_ndesign:\n    \"\\<^bold>N P = \\<lfloor>pre\\<^sub>D P\\<rfloor>\\<^sub>< \\<turnstile>\\<^sub>n post\\<^sub>D P\"  \n    by simp \n  also have pre_post_ndesign_mu_refine:\"\\<dots> \\<sqsubseteq> \\<mu>\\<^sub>N F\"    \n  proof - \n    have 1:\"\\<lfloor>pre\\<^sub>D P\\<rfloor>\\<^sub>< \\<turnstile>\\<^sub>n post\\<^sub>D P \\<sqsubseteq> F (\\<lfloor>pre\\<^sub>D P\\<rfloor>\\<^sub>< \\<turnstile>\\<^sub>n post\\<^sub>D P)\"\n      using 1 2 ndesign_form[of P]\n      by simp\n    also have \"`\\<lceil>\\<lfloor>pre\\<^sub>D P\\<rfloor>\\<^sub><\\<rceil>\\<^sub>D\\<^sub>< \\<Rightarrow> \\<mu>\\<^sub>N F \\<Leftrightarrow> \\<nu>\\<^sub>N F`\"\n      using 4 by simp\n    from assms have \"(\\<lfloor>pre\\<^sub>D P\\<rfloor>\\<^sub>< \\<turnstile>\\<^sub>n post\\<^sub>D P) \\<sqsubseteq> \\<nu>\\<^sub>N F\"\n      by (simp add: 1 ndesign_H1_H3 normal_design_theory_continuous.GFP_upperbound)  \n    with assms show ?thesis\n      by (rel_auto, metis (no_types, lifting))\n  qed       \n  ultimately show ?thesis \n    by (simp add: \"1\" ndes_elim)  \nqed\n  \nlemma ndesign_mu_refine_intro:\n  assumes \"(C \\<turnstile>\\<^sub>n S) \\<sqsubseteq> F(C \\<turnstile>\\<^sub>n S)\" \"`\\<lceil>C\\<rceil>\\<^sub>D\\<^sub>< \\<Rightarrow> (\\<mu>\\<^sub>N F \\<Leftrightarrow> \\<nu>\\<^sub>N F)`\"\n  shows \"(C \\<turnstile>\\<^sub>n S) \\<sqsubseteq> \\<mu>\\<^sub>N F\"\nproof (rule H1_H3_mu_refine_intro, goal_cases)\n  case 1\n  then show ?case by (simp add: ndesign_H1_H3)\nnext\n  case 2\n  then show ?case by (simp add: assms(1))\nnext\n  case 3\n  then show ?case by (simp add: unrest_pre_out\\<alpha>)\nnext\n  case 4\n  then show ?case by (simp add: assms(2))\nqed  \n  \nsubsection \\<open>While laws for designs\\<close>\n  \ntext \\<open>In this section we introduce the algebraic laws of programming related to the while\n      statement.\\<close>\n \nlemma while_gfp_des_def_alt:\n\"(while\\<^sup>\\<top>\\<^sup>D b do body od) = (\\<nu>\\<^sub>D X \\<bullet> bif\\<^sub>D b then (body ;; X) else SKIP\\<^sub>D eif)\"\n    unfolding from_until_gfp_des_def while_gfp_des_def \n    by (simp add: skip_left_unit_design)\n      \nlemma while_lfp_des_def_alt:\n\"(while\\<^sub>\\<bottom>\\<^sub>D b do body od) = (\\<mu>\\<^sub>D X \\<bullet> bif\\<^sub>D b then (body ;; X) else SKIP\\<^sub>D eif)\"\n    unfolding from_until_lfp_des_def while_lfp_des_def \n    by (simp add: skip_left_unit_design)\n       \ntheorem while_gfp_des_unfold:\n  assumes HB: \"body is H1\"\n  shows\n  \"while\\<^sup>\\<top>\\<^sup>D b do body od = (bif\\<^sub>D b then (body ;; while\\<^sup>\\<top>\\<^sup>D b do body od) else SKIP\\<^sub>D eif)\"\nproof -\n  have m:\"mono (\\<lambda>X. bif\\<^sub>D b then (body ;; X) else SKIP\\<^sub>D eif)\"\n    by (auto intro: monoI seqr_mono cond_mono)\n  have H: \"(\\<lambda>X. bif\\<^sub>D b then (body ;; X) else SKIP\\<^sub>D eif) \\<in> \\<lbrakk>\\<^bold>H\\<rbrakk>\\<^sub>H \\<rightarrow> \\<lbrakk>\\<^bold>H\\<rbrakk>\\<^sub>H\"  \n   by (rule stronger_if_d_seq_r_H1_H2_closed[OF HB skip_d_is_H1_H2])    \n  have \"(while\\<^sup>\\<top>\\<^sup>D b do body od) = (\\<nu>\\<^sub>D X \\<bullet> bif\\<^sub>D b then (body;; X) else SKIP\\<^sub>D eif)\"\n    by (simp add: while_gfp_des_def_alt)\n  also have \"... = (bif\\<^sub>D b then (body ;; (\\<nu>\\<^sub>D X \\<bullet> bif\\<^sub>D b then (body ;; X) else SKIP\\<^sub>D eif)) else SKIP\\<^sub>D eif)\"\n    using mono_Monotone_utp_order [OF m, of \"\\<H>\\<^bsub>DES\\<^esub>\"] H\n          design_theory_continuous.GFP_weak_unfold \n    by auto\n  also have \"... = (bif\\<^sub>D b then (body ;; while\\<^sup>\\<top>\\<^sup>D b do body od) else SKIP\\<^sub>D eif)\"\n    by (simp add:while_gfp_des_def_alt)\n  finally show ?thesis .\nqed    \n\ntheorem while_lfp_des_unfold:\n  assumes HB: \"body is H1\"\n  shows \"while\\<^sub>\\<bottom>\\<^sub>D b do body od = (bif\\<^sub>D b then (body;; while\\<^sub>\\<bottom>\\<^sub>D b do body od) else SKIP\\<^sub>D eif)\"\nproof -\n  have m:\"mono (\\<lambda>X. bif\\<^sub>D b then (body ;; X) else SKIP\\<^sub>D eif)\"\n    by (auto intro: monoI seqr_mono cond_mono)\n  have H: \"(\\<lambda>X. bif\\<^sub>D b then (body ;; X) else SKIP\\<^sub>D eif) \\<in> \\<lbrakk>\\<^bold>H\\<rbrakk>\\<^sub>H \\<rightarrow> \\<lbrakk>\\<^bold>H\\<rbrakk>\\<^sub>H\"\n    by (rule stronger_if_d_seq_r_H1_H2_closed[OF HB skip_d_is_H1_H2])     \n  have \"(while\\<^sub>\\<bottom>\\<^sub>D b do body od) = (\\<mu>\\<^sub>D X \\<bullet> bif\\<^sub>D b then (body ;; X) else SKIP\\<^sub>D eif)\"\n    unfolding from_until_lfp_des_def \n    by (simp add: while_lfp_des_def_alt skip_left_unit_design)\n  also have \"... = (bif\\<^sub>D b then (body;; (\\<mu>\\<^sub>D X \\<bullet> bif\\<^sub>D b then (body ;; X) else SKIP\\<^sub>D eif)) else SKIP\\<^sub>D eif)\"\n    using mono_Monotone_utp_order [OF m, of \"\\<H>\\<^bsub>DES\\<^esub>\"] H\n          design_theory_continuous.LFP_weak_unfold \n    by auto\n  also have \"... = (bif\\<^sub>D b then (body;; while\\<^sub>\\<bottom>\\<^sub>D b do body od) else SKIP\\<^sub>D eif)\"\n    by (simp add: while_lfp_des_def_alt)\n  finally show ?thesis .\nqed\n    \ntheorem while_lfp_des_true: \n  \"while\\<^sub>\\<bottom>\\<^sub>D true do body od = (\\<mu>\\<^sub>D X \\<bullet> (body ;; X))\"\n  by (simp add: while_lfp_des_def_alt alpha)      \n\nlemma while_lfp_des_false:\n  shows \"(while\\<^sub>\\<bottom>\\<^sub>D false do body od) = SKIP\\<^sub>D\"\n  by (simp add: while_lfp_des_def_alt alpha skip_d_def \n      design_theory_continuous.LFP_const rdesign_is_H1_H2)\n         \ntheorem while_gfp_des_false: \n  \"while\\<^sup>\\<top>\\<^sup>D false do body od = SKIP\\<^sub>D\"\n by (simp add: while_gfp_des_def_alt alpha skip_d_def \n      design_theory_continuous.GFP_const rdesign_is_H1_H2)\n\ntheorem while_gfp_des_non_termination: (*because of this lemma and the lemma utp_designs.design_top we do not use gfp for capturing termination *)\n  \"while\\<^sup>\\<top>\\<^sup>D true do SKIP\\<^sub>D od = \\<top>\\<^sub>D\"\n  unfolding while_gfp_des_def_alt\nproof (rule design_theory_continuous.weak.GFP_idem [of \"(\\<lambda>X. bif\\<^sub>D true then SKIP\\<^sub>D ;; X else SKIP\\<^sub>D eif)\",\n      unfolded utp_theory_des_top_is_not_ok if_d_skip_d_not_ok] , goal_cases)\n  case 1\n  then show ?case by (simp add: H1_H2_impl_H1 if_d_H1_H2_intro skip_d_is_H1_H2 weaker_seq_r_H1_H2_closed)\nnext\n  case 2\n  then show ?case by (simp add: aext_true seqr_mono utp_theory.Mono_utp_orderI)\nnext\n  case 3\n  then show ?case  unfolding idempotent_def by (simp add: aext_true seqr_assoc)                       \nqed\n\ntheorem while_lfp_des_non_termination: \n  \"while\\<^sub>\\<bottom>\\<^sub>D true do  SKIP\\<^sub>D od = \\<bottom>\\<^sub>D\"\n  unfolding while_lfp_des_def_alt\nproof (rule design_theory_continuous.weak.LFP_idem [of \"(\\<lambda>X. bif\\<^sub>D true then SKIP\\<^sub>D ;; X else SKIP\\<^sub>D eif)\",\n      unfolded utp_theory_des_bot_is_true if_d_skip_d_true] , goal_cases)\n  case 1\n  then show ?case by (simp add: H1_H2_impl_H1 if_d_H1_H2_intro skip_d_is_H1_H2 weaker_seq_r_H1_H2_closed)\nnext\n  case 2\n  then show ?case by (simp add: aext_true seqr_mono utp_theory.Mono_utp_orderI)\nnext\n  case 3\n  then show ?case  unfolding idempotent_def by (simp add: aext_true seqr_assoc)                       \nqed  \n\n      \nsubsection \\<open>While laws for normal designs\\<close>\n\ntext \\<open>In this section we introduce the algebraic laws of programming related to the while\n      statement.\\<close>\n    \nlemma while_gfp_ndes_def_alt:\n\"(while\\<^sup>\\<top>\\<^sup>N b do body od) = (\\<nu>\\<^sub>N X \\<bullet> bif\\<^sub>D b then (body ;; X) else SKIP\\<^sub>D eif)\"\n    unfolding from_until_gfp_ndes_def while_gfp_ndes_def \n    by (simp add: skip_left_unit_ndesign)\n    \nlemma while_lfp_ndes_def_alt:\n\"(while\\<^sub>\\<bottom>\\<^sub>N b do body od) = (\\<mu>\\<^sub>N X \\<bullet> bif\\<^sub>D b then (body ;; X) else SKIP\\<^sub>D eif)\"\n    unfolding from_until_lfp_ndes_def while_lfp_ndes_def \n    by (simp add: skip_left_unit_ndesign)\n \nlemma while_gfp_ndes_is_H1_H3: \n  \"while\\<^sup>\\<top>\\<^sup>N b do body od is \\<^bold>N\"  \n  unfolding while_gfp_ndes_def_alt\n  by simp \n    \nlemma while_lfp_ndes_is_H1_H3: \n  \"while\\<^sub>\\<bottom>\\<^sub>N b do body od is \\<^bold>N\"  \n  unfolding while_lfp_ndes_def_alt\n  by simp \n    \nlemma while_gfp_ndes_is_H1_H2: \n  \"while\\<^sup>\\<top>\\<^sup>D b do body od is \\<^bold>H\"  \n  unfolding while_gfp_des_def_alt\n  by simp  \n    \nlemma while_lfp_ndes_is_H1_H2: \n  \"while\\<^sub>\\<bottom>\\<^sub>D b do body od is \\<^bold>H\"  \n  unfolding while_lfp_des_def_alt\n  by simp  \n    \ntheorem while_gfp_ndes_unfold:\n  assumes HB: \"body is H1\"\n  shows\n  \"while\\<^sup>\\<top>\\<^sup>N b do body od = (bif\\<^sub>D b then (body ;; while\\<^sup>\\<top>\\<^sup>N b do body od) else SKIP\\<^sub>D eif)\"\nproof -\n  have m:\"mono (\\<lambda>X. bif\\<^sub>D b then (body ;; X) else SKIP\\<^sub>D eif)\"\n    by (auto intro: monoI seqr_mono cond_mono)\n  have H: \"(\\<lambda>X. bif\\<^sub>D b then (body ;; X) else SKIP\\<^sub>D eif) \\<in> \\<lbrakk>\\<^bold>N\\<rbrakk>\\<^sub>H \\<rightarrow> \\<lbrakk>\\<^bold>N\\<rbrakk>\\<^sub>H\" \n    by (rule stronger_if_d_seq_r_H1_H3_closed[OF HB skip_d_is_H1_H3])          \n  have \"(while\\<^sup>\\<top>\\<^sup>N b do body od) = (\\<nu>\\<^sub>N X \\<bullet> bif\\<^sub>D b then (body;; X) else SKIP\\<^sub>D eif)\"\n    by (simp add: while_gfp_ndes_def_alt)\n  also have \"... = (bif\\<^sub>D b then (body ;; (\\<nu>\\<^sub>N X \\<bullet> bif\\<^sub>D b then (body ;; X) else SKIP\\<^sub>D eif)) else SKIP\\<^sub>D eif)\"\n    using mono_Monotone_utp_order [OF m, of \"\\<H>\\<^bsub>NDES\\<^esub>\"] H\n          normal_design_theory_continuous.GFP_weak_unfold \n    by auto\n  also have \"... = (bif\\<^sub>D b then (body ;; while\\<^sup>\\<top>\\<^sup>N b do body od) else SKIP\\<^sub>D eif)\"\n    by (simp add: while_gfp_ndes_def_alt)\n  finally show ?thesis .\nqed\n  \ntheorem while_lfp_ndes_unfold:\n  assumes HB: \"body is H1\"\n  shows\n  \"while\\<^sub>\\<bottom>\\<^sub>N b do body od = (bif\\<^sub>D b then (body;; while\\<^sub>\\<bottom>\\<^sub>N b do body od) else SKIP\\<^sub>D eif)\"\nproof -\n  have m:\"mono (\\<lambda>X. bif\\<^sub>D b then (body ;; X) else SKIP\\<^sub>D eif)\"\n    by (auto intro: monoI seqr_mono cond_mono)\n  have H: \"(\\<lambda>X. bif\\<^sub>D b then (body ;; X) else SKIP\\<^sub>D eif) \\<in> \\<lbrakk>\\<^bold>N\\<rbrakk>\\<^sub>H \\<rightarrow> \\<lbrakk>\\<^bold>N\\<rbrakk>\\<^sub>H\"\n    by (rule stronger_if_d_seq_r_H1_H3_closed[OF HB skip_d_is_H1_H3])       \n  have \"(while\\<^sub>\\<bottom>\\<^sub>N b do body od) = (\\<mu>\\<^sub>N X \\<bullet> bif\\<^sub>D b then (body ;; X) else SKIP\\<^sub>D eif)\"\n    by (simp add: while_lfp_ndes_def_alt)\n  also have \"... = (bif\\<^sub>D b then (body ;; (\\<mu>\\<^sub>N X \\<bullet> bif\\<^sub>D b then (body ;; X) else SKIP\\<^sub>D eif)) else SKIP\\<^sub>D eif)\"\n    using mono_Monotone_utp_order [OF m, of \"\\<H>\\<^bsub>NDES\\<^esub>\"] H\n          normal_design_theory_continuous.LFP_weak_unfold \n    by auto\n  also have \"... = (bif\\<^sub>D b then (body ;; while\\<^sub>\\<bottom>\\<^sub>N b do body od) else SKIP\\<^sub>D eif)\"\n    by (simp add: while_lfp_ndes_def_alt)\n  finally show ?thesis .\nqed\n    \ntheorem while_lfp_ndes_true: \n  \"while\\<^sub>\\<bottom>\\<^sub>N true do body od = (\\<mu>\\<^sub>N X \\<bullet> (body;; X))\"\n  by (simp add: while_lfp_ndes_def_alt alpha)\n \nlemma while_lfp_ndes_false:\n  \"(while\\<^sub>\\<bottom>\\<^sub>N false do body od) = SKIP\\<^sub>D\"\n  by (simp add: while_lfp_ndes_def_alt alpha skip_d_is_H1_H3  \n      normal_design_theory_continuous.LFP_const)\n\ntheorem while_gfp_ndes_false: \"while\\<^sup>\\<top>\\<^sup>N false do body od = SKIP\\<^sub>D\"\n by (simp add: while_gfp_ndes_def_alt alpha skip_d_is_H1_H3  \n      normal_design_theory_continuous.GFP_const)\n    \ntheorem while_gfp_ndes_non_termination: (*because of this lemma and the lemma utp_designs.design_top we do not use gfp for capturing termination *)\n  \"while\\<^sup>\\<top>\\<^sup>N true do SKIP\\<^sub>D od = \\<top>\\<^sub>D\"\n  unfolding while_gfp_ndes_def_alt\nproof (rule normal_design_theory_continuous.weak.GFP_idem [of \"(\\<lambda>X. bif\\<^sub>D true then SKIP\\<^sub>D ;; X else SKIP\\<^sub>D eif)\",\n      unfolded utp_theory_ndes_top_is_not_ok if_d_skip_d_not_ok] , goal_cases)\n  case 1\n  then show ?case by (simp add: aext_true skip_left_unit_ndesign) \nnext\n  case 2\n  then show ?case by (simp add: aext_true seqr_mono utp_theory.Mono_utp_orderI)\nnext\n  case 3\n  then show ?case  unfolding idempotent_def by (simp add: aext_true seqr_assoc)                       \nqed\n\ntheorem while_lfp_ndes_non_termination: \n  \"while\\<^sub>\\<bottom>\\<^sub>N true do  SKIP\\<^sub>D od = \\<bottom>\\<^sub>D\"\n  unfolding while_lfp_ndes_def_alt\nproof (rule normal_design_theory_continuous.weak.LFP_idem [of \"(\\<lambda>X. bif\\<^sub>D true then SKIP\\<^sub>D ;; X else SKIP\\<^sub>D eif)\",\n      unfolded utp_theory_ndes_bot_is_true if_d_skip_d_true] , goal_cases)\n  case 1\n  then show ?case  by (simp add: aext_true skip_left_unit_ndesign)\nnext\n  case 2\n  then show ?case by (simp add: aext_true seqr_mono utp_theory.Mono_utp_orderI)\nnext\n  case 3\n  then show ?case  unfolding idempotent_def by (simp add: aext_true seqr_assoc)                       \nqed    \n  \nlemma abort_situation_left_zero:\n  \"Q is \\<^bold>N \\<Longrightarrow> \n    ((\\<lfloor>pre\\<^sub>D P\\<rfloor>\\<^sub>< \\<and> post\\<^sub>D P wp false) \\<turnstile>\\<^sub>n false) ;; Q =  ((\\<lfloor>pre\\<^sub>D P\\<rfloor>\\<^sub>< \\<and> post\\<^sub>D P wp false) \\<turnstile>\\<^sub>n false)\"  \n  by rel_blast\n    \nlemma nested_abort_situation:\n  \"\\<mu>\\<^sub>N (\\<lambda> X . ((\\<lfloor>pre\\<^sub>D P\\<rfloor>\\<^sub>< \\<and> post\\<^sub>D P wp false) \\<turnstile>\\<^sub>n false) ;; X) = ((\\<lfloor>pre\\<^sub>D P\\<rfloor>\\<^sub>< \\<and> post\\<^sub>D P wp false) \\<turnstile>\\<^sub>n false)\"\n  apply (subst (1) normal_design_theory_continuous.LFP_healthy_comp)\n  apply (simp add: comp_def)\n  apply (subst  abort_situation_left_zero)    \n  using Healthy_Idempotent is_Ncarrier_is_ndesigns apply auto[1]\n  apply (simp add: ndesign_H1_H3 normal_design_theory_continuous.LFP_unfold utp_theory.Mono_utp_orderI)\n  done \n\nsubsection \\<open>Iteration laws for designs\\<close>\n  \ntheorem from_until_gfp_des_alt_def:\n  \"from\\<^sup>\\<top>\\<^sup>D init until exit do body od = init ;; while\\<^sup>\\<top>\\<^sup>D \\<not> exit do body od\"\n  unfolding while_gfp_des_def_alt from_until_gfp_des_def \n  by simp  \n\nlemma from_until_while_gfp_des:\n  \"from\\<^sup>\\<top>\\<^sup>D SKIP\\<^sub>D until exit do body od = while\\<^sup>\\<top>\\<^sup>D \\<not> exit do body od\"\n  unfolding from_until_gfp_des_alt_def\n  by (simp add: skip_left_unit_design while_gfp_des_def_alt)\n   \nlemma from_until_lfp_ndes_is_H1_H3:\n  \"init is H1 \\<Longrightarrow>from\\<^sub>\\<bottom>\\<^sub>N init until exit do body od is \\<^bold>N\"\n  unfolding from_until_lfp_ndes_def\n  by (simp add: weaker_seq_r_H1_H3_closed)\n\nlemma from_until_gfp_des_is_H1_H3:\n  \"init is H1 \\<Longrightarrow>from\\<^sup>\\<top>\\<^sup>N init until exit do body od is \\<^bold>N\"\n  unfolding from_until_gfp_ndes_def\n  by (simp add: weaker_seq_r_H1_H3_closed)\n    \nlemma from_until_lfp_des_is_H1_H2:\n  \"init is H1 \\<Longrightarrow> from\\<^sub>\\<bottom>\\<^sub>D init until exit do body od is \\<^bold>H\"\n   unfolding from_until_lfp_des_def\n   by (simp add: weaker_seq_r_H1_H2_closed)\n\nlemma from_until_gfp_ndes_is_H1_H2:\n  \"init is H1 \\<Longrightarrow> from\\<^sup>\\<top>\\<^sup>D init until exit do body od is \\<^bold>H\"\n   unfolding from_until_gfp_des_def\n   by (simp add: weaker_seq_r_H1_H2_closed)\n     \ntheorem from_until_gfp_des_unfold:\n  assumes HB: \"body is H1\"\n  shows \"from\\<^sup>\\<top>\\<^sup>D init until exit do body od = \n         init ;; (bif\\<^sub>D \\<not> exit then (body;; while\\<^sup>\\<top>\\<^sup>D \\<not> exit do body od) else SKIP\\<^sub>D eif)\"\n  unfolding from_until_gfp_des_alt_def using while_gfp_des_unfold[OF HB]\n  by simp\n    \ntheorem from_until_lfp_des_alt_def:\n  \"from\\<^sub>\\<bottom>\\<^sub>D init until exit do body od = init ;; while\\<^sub>\\<bottom>\\<^sub>D \\<not> exit do body od\"\n  unfolding while_lfp_des_def_alt from_until_lfp_des_def \n  by simp  \n\nlemma from_until_while_lfp_des:\n  \"from\\<^sub>\\<bottom>\\<^sub>D SKIP\\<^sub>D until exit do body od = while\\<^sub>\\<bottom>\\<^sub>D \\<not> exit do body od\"\n  unfolding from_until_lfp_des_alt_def\n  by (simp add: skip_left_unit_design while_lfp_des_def_alt)\n    \ntheorem from_until_lfp_des_unfold:\n  assumes HB: \"body is H1\"\n  shows \"from\\<^sub>\\<bottom>\\<^sub>D init until exit do body od = \n         init ;; (bif\\<^sub>D \\<not> exit then (body;; while\\<^sub>\\<bottom>\\<^sub>D \\<not> exit do body od) else SKIP\\<^sub>D eif)\"\n  unfolding from_until_lfp_des_alt_def using while_lfp_des_unfold[OF HB]\n  by simp\n\ntheorem do_while_gfp_des_alt_def:\n  \"do body while\\<^sup>\\<top>\\<^sup>D exit od = body ;; while\\<^sup>\\<top>\\<^sup>D exit do body od\"\n  unfolding  do_while_gfp_des_def from_until_gfp_des_alt_def\n  by simp  \n\ntheorem do_while_lfp_des_alt_def:\n  \"do body while\\<^sub>\\<bottom>\\<^sub>D exit od = body ;; while\\<^sub>\\<bottom>\\<^sub>D exit do body od\"\n  unfolding  do_while_lfp_des_def from_until_lfp_des_alt_def\n  by simp  \n    \nlemma do_while_gfp_des_is_H1_H2: \n  \"body is H1 \\<Longrightarrow> do body while\\<^sup>\\<top>\\<^sup>D b od is \\<^bold>H\"\n  unfolding do_while_gfp_des_def from_until_gfp_des_def\n  by (simp add: weaker_seq_r_H1_H2_closed)\n    \nlemma do_while_lfp_des_is_H1_H2: \n  \"body is H1 \\<Longrightarrow> do body while\\<^sub>\\<bottom>\\<^sub>D b od is \\<^bold>H\"\n  unfolding do_while_lfp_des_def from_until_lfp_des_def\n  by (simp add: weaker_seq_r_H1_H2_closed)  \n\nlemma do_while_gfp_ndes_is_H1_H3:\n \"body is H1 \\<Longrightarrow> do body while\\<^sup>\\<top>\\<^sup>N b od is \\<^bold>N\"\n  unfolding do_while_gfp_ndes_def from_until_gfp_ndes_def\n  by (simp add: weaker_seq_r_H1_H3_closed)\n    \nlemma do_while_lfp_ndes_is_H1_H3:\n  \"body is H1 \\<Longrightarrow> do body while\\<^sub>\\<bottom>\\<^sub>N b od is \\<^bold>N\"\n  unfolding do_while_lfp_ndes_def from_until_lfp_ndes_def\n  by (simp add: weaker_seq_r_H1_H3_closed)\n    \ntheorem do_while_gfp_des_unfold:\n  assumes HB: \"body is H1\"\n  shows \"do body while\\<^sup>\\<top>\\<^sup>D exit od = \n         body ;; (bif\\<^sub>D exit then (body;; while\\<^sup>\\<top>\\<^sup>D exit do body od) else SKIP\\<^sub>D eif)\"\n  unfolding do_while_gfp_des_alt_def using while_gfp_des_unfold[OF HB]\n  by simp\n\ntheorem do_while_lfp_des_unfold:\n  assumes HB: \"body is H1\"\n  shows \"do body while\\<^sub>\\<bottom>\\<^sub>D exit od = \n         body ;; (bif\\<^sub>D exit then (body;; while\\<^sub>\\<bottom>\\<^sub>D exit do body od) else SKIP\\<^sub>D eif)\"\n  unfolding do_while_lfp_des_alt_def using while_lfp_des_unfold[OF HB]\n  by simp    \n\ntheorem for_gfp_des_alt_def:\n  \"for\\<^sup>\\<top>\\<^sup>D (init, exit, incr) do body od = init ;; while\\<^sup>\\<top>\\<^sup>D exit do body;;incr od\"\n  unfolding  for_gfp_des_def from_until_gfp_des_alt_def\n  by simp  \n     \ntheorem for_lfp_des_alt_def:\n \"for\\<^sub>\\<bottom>\\<^sub>D (init, exit, incr) do body od = init ;; while\\<^sub>\\<bottom>\\<^sub>D exit do body;;incr od\"\n  unfolding  for_lfp_des_def from_until_lfp_des_alt_def\n  by simp  \n\nlemma for_gfp_ndes_is_H1_H2:\n  \"init is H1 \\<Longrightarrow>for\\<^sup>\\<top>\\<^sup>D (init,b,incr) do body od is \\<^bold>H\"\n  unfolding for_gfp_des_def from_until_gfp_des_def \n  by (simp add: weaker_seq_r_H1_H2_closed)  \n\nlemma for_lfp_des_is_H1_H2:\n  \"init is H1 \\<Longrightarrow>for\\<^sub>\\<bottom>\\<^sub>D (init,b,incr) do body od is \\<^bold>H\"\n  unfolding for_lfp_des_def from_until_lfp_des_def \n  by (simp add: weaker_seq_r_H1_H2_closed)  \n\nlemma for_gfp_ndes_is_H1_H3: \n  \"init is H1 \\<Longrightarrow>for\\<^sup>\\<top>\\<^sup>N (init,b,incr) do body od is \\<^bold>N\"\n  unfolding for_gfp_ndes_def from_until_gfp_ndes_def \n  by (simp add: weaker_seq_r_H1_H3_closed)  \n\nlemma for_lfp_ndes_is_H1_H3:\n  \"init is H1 \\<Longrightarrow>for\\<^sub>\\<bottom>\\<^sub>N (init,b,incr) do body od is \\<^bold>N\"\n  unfolding for_lfp_ndes_def from_until_lfp_ndes_def \n  by (simp add: weaker_seq_r_H1_H3_closed)\n    \ntheorem for_gfp_des_unfold:\n  assumes HB: \"body is H1\"\n  assumes Hinit: \"incr is H1\" \n  shows \"for\\<^sup>\\<top>\\<^sup>D (init, exit, incr) do body od = \n         init ;; (bif\\<^sub>D exit then (body;;incr;;while\\<^sup>\\<top>\\<^sup>D exit do body ;; incr od) else SKIP\\<^sub>D eif)\"\n  unfolding for_gfp_des_alt_def using while_gfp_des_unfold[of \"body ;; incr\" \"exit\", OF seq_is_H1[OF HB Hinit]] \n  by (metis seqr_assoc)\n    \ntheorem for_lfp_des_unfold:\n  assumes HB: \"body is H1\"\n  assumes Hinit: \"incr is H1\"   \n  shows\n  \"for\\<^sub>\\<bottom>\\<^sub>D (init, exit, incr) do body od = \n   init ;; (bif\\<^sub>D exit then (body;;incr;;while\\<^sub>\\<bottom>\\<^sub>D exit do body ;; incr od) else SKIP\\<^sub>D eif)\"\n  unfolding for_lfp_des_alt_def using while_lfp_des_unfold[of \"body ;; incr\" \"exit\", OF seq_is_H1[OF HB Hinit]] \n  by (metis seqr_assoc)  \n\nsubsection \\<open>Iteration laws for normal designs\\<close>\n  \ntheorem from_until_gfp_ndes_alt_def:\n  \"from\\<^sup>\\<top>\\<^sup>N init until exit do body od = init ;; while\\<^sup>\\<top>\\<^sup>N \\<not> exit do body od\"\n  unfolding while_gfp_ndes_def_alt from_until_gfp_ndes_def \n  by simp  \n\nlemma from_until_while_gfp_ndes:\n  \"from\\<^sup>\\<top>\\<^sup>N SKIP\\<^sub>D until exit do body od = while\\<^sup>\\<top>\\<^sup>N \\<not> exit do body od\"\n  unfolding from_until_gfp_ndes_alt_def\n  by (simp add: skip_left_unit_ndesign while_gfp_ndes_def_alt)\n        \ntheorem from_until_gfp_ndes_unfold:\n  assumes HB: \"body is H1\"\n  shows \"from\\<^sup>\\<top>\\<^sup>N init until exit do body od = \n         init ;; (bif\\<^sub>D \\<not> exit then (body;; while\\<^sup>\\<top>\\<^sup>N \\<not> exit do body od) else SKIP\\<^sub>D eif)\"\n  unfolding from_until_gfp_ndes_alt_def using while_gfp_ndes_unfold[OF HB]\n  by simp\n    \ntheorem from_until_lfp_ndes_alt_def:\n  \"from\\<^sub>\\<bottom>\\<^sub>N init until exit do body od = init ;; while\\<^sub>\\<bottom>\\<^sub>N \\<not> exit do body od\"\n  unfolding while_lfp_ndes_def_alt from_until_lfp_ndes_def \n  by simp  \n\nlemma from_until_while_lfp_ndes:\n  \"from\\<^sub>\\<bottom>\\<^sub>N SKIP\\<^sub>D until exit do body od = while\\<^sub>\\<bottom>\\<^sub>N \\<not> exit do body od\"\n  unfolding from_until_lfp_ndes_alt_def\n  by (simp add: skip_left_unit_ndesign while_lfp_ndes_def_alt)\n    \ntheorem from_until_lfp_ndes_unfold:\n  assumes HB: \"body is H1\"\n  shows \"from\\<^sub>\\<bottom>\\<^sub>N init until exit do body od = \n         init ;; (bif\\<^sub>D \\<not> exit then (body;; while\\<^sub>\\<bottom>\\<^sub>N \\<not> exit do body od) else SKIP\\<^sub>D eif)\"\n  unfolding from_until_lfp_ndes_alt_def using while_lfp_ndes_unfold[OF HB]\n  by simp\n\ntheorem do_while_gfp_ndes_alt_def:\n  \"do body while\\<^sup>\\<top>\\<^sup>N exit od = body ;; while\\<^sup>\\<top>\\<^sup>N exit do body od\"\n  unfolding  do_while_gfp_ndes_def from_until_gfp_ndes_alt_def\n  by simp  \n    \ntheorem do_while_gfp_ndes_unfold:\n  assumes HB: \"body is H1\"\n  shows \"do body while\\<^sup>\\<top>\\<^sup>N exit od = \n         body ;; (bif\\<^sub>D exit then (body;; while\\<^sup>\\<top>\\<^sup>N exit do body od) else SKIP\\<^sub>D eif)\"\n  unfolding do_while_gfp_ndes_alt_def using while_gfp_ndes_unfold[OF HB]\n  by simp\n\ntheorem do_while_lfp_ndes_alt_def:\n  \"do body while\\<^sub>\\<bottom>\\<^sub>N exit od = body ;; while\\<^sub>\\<bottom>\\<^sub>N exit do body od\"\n  unfolding  do_while_lfp_ndes_def from_until_lfp_ndes_alt_def\n  by simp  \n    \ntheorem do_while_lfp_ndes_unfold:\n  assumes HB: \"body is H1\"\n  shows \"do body while\\<^sub>\\<bottom>\\<^sub>N exit od = \n         body ;; (bif\\<^sub>D exit then (body;; while\\<^sub>\\<bottom>\\<^sub>N exit do body od) else SKIP\\<^sub>D eif)\"\n  unfolding do_while_lfp_ndes_alt_def using while_lfp_ndes_unfold[OF HB]\n  by simp    \n\ntheorem for_gfp_ndes_alt_def:\n  \"for\\<^sup>\\<top>\\<^sup>N (init, exit, incr) do body od = init ;; while\\<^sup>\\<top>\\<^sup>N exit do body;;incr od\"\n  unfolding  for_gfp_ndes_def from_until_gfp_ndes_alt_def\n  by simp  \n    \ntheorem for_gfp_ndes_unfold:\n  assumes HB: \"body is H1\"\n  assumes Hinit: \"incr is H1\" \n  shows \"for\\<^sup>\\<top>\\<^sup>N (init, exit, incr) do body od = \n         init ;; (bif\\<^sub>D exit then (body;;incr;;while\\<^sup>\\<top>\\<^sup>N exit do body ;; incr od) else SKIP\\<^sub>D eif)\"\n  unfolding for_gfp_ndes_alt_def using while_gfp_ndes_unfold[of \"body ;; incr\" \"exit\", OF seq_is_H1[OF HB Hinit]] \n  by (metis seqr_assoc)\n\ntheorem for_lfp_ndes_alt_def:\n \"for\\<^sub>\\<bottom>\\<^sub>N (init, exit, incr) do body od = init ;; while\\<^sub>\\<bottom>\\<^sub>N exit do body;;incr od\"\n  unfolding  for_lfp_ndes_def from_until_lfp_ndes_alt_def\n  by simp  \n    \ntheorem for_lfp_ndes_unfold:\n  assumes HB: \"body is H1\"\n  assumes Hinit: \"incr is H1\"   \n  shows\n  \"for\\<^sub>\\<bottom>\\<^sub>N (init, exit, incr) do body od = \n   init ;; (bif\\<^sub>D exit then (body;;incr;;while\\<^sub>\\<bottom>\\<^sub>N exit do body ;; incr od) else SKIP\\<^sub>D eif)\"\n  unfolding for_lfp_ndes_alt_def using while_lfp_ndes_unfold[of \"body ;; incr\" \"exit\", OF seq_is_H1[OF HB Hinit]] \n  by (metis seqr_assoc)  \n    \nsubsection \\<open>assume laws\\<close>\n\nlemma assume_d_twice[udes_comp]: \"(b\\<^sup>\\<top>\\<^sup>D;; c\\<^sup>\\<top>\\<^sup>D) = (b \\<and> c)\\<^sup>\\<top>\\<^sup>D\"\n  apply pred_simp\n  apply auto\n  apply (rel_simp)\n  apply blast\n    apply (rel_simp)\n    apply blast\ndone\n\nlemma assert_d_twice[udes_comp]: \"(b\\<^sub>\\<bottom>\\<^sub>D;; c\\<^sub>\\<bottom>\\<^sub>D) = (b \\<and> c)\\<^sub>\\<bottom>\\<^sub>D\"\n apply pred_simp\n  apply auto\n  apply (rel_simp)+\n    apply blast\n  done\n    \nsubsection \\<open>Frame and antiframe\\<close>\n  \nlemma frame_d_is_H1_H3:\n  assumes \"P is \\<^bold>N\" \n  shows \"frame\\<^sub>D a P is \\<^bold>N\"\n  using assms unfolding frame\\<^sub>D_def\n  by rel_auto  \n\nlemma antiframe_d_is_H1_H3:\n  assumes \"P is \\<^bold>N\" \n  shows \"antiframe\\<^sub>D a P is \\<^bold>N\"\n  using assms unfolding frame\\<^sub>D_def\n  by rel_auto  \n    \nlemma frame_d_assign_d_is_H4:\n \"frame\\<^sub>D a \\<langle>\\<sigma>\\<rangle>\\<^sub>D is H4\"\n   unfolding frame\\<^sub>D_def \n   by rel_auto\nend\n\n  \n\n", "meta": {"author": "git-vt", "repo": "orca", "sha": "92bda0f9cfe5cc680b9c405fc38f07a960087a36", "save_path": "github-repos/isabelle/git-vt-orca", "path": "github-repos/isabelle/git-vt-orca/orca-92bda0f9cfe5cc680b9c405fc38f07a960087a36/C-verifier/src/Midend-IVL/Isabelle-UTP-Extended/AlgebraicLaws/Algebraic_laws_design.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5039061705290806, "lm_q2_score": 0.5428632831725051, "lm_q1q2_score": 0.27355215814430095}}
{"text": "section {* \\isaheader{Generic Map Algorithms} *}\ntheory Gen_Map\nimports \"../Intf/Intf_Map\" \"../../Iterator/Iterator\"\nbegin\n  lemma map_to_set_distinct_conv:\n    assumes \"distinct tsl'\" and \"map_to_set m' = set tsl'\"\n    shows \"distinct (map fst tsl')\"\n    apply (rule ccontr)\n    apply (drule not_distinct_decomp)\n    using assms\n    apply (clarsimp elim!: map_eq_concE)\n    by (metis (hide_lams, no_types) insert_iff map_to_set_inj)\n\n\n  (* TODO: Make foldli explicit, such that it is seen by \n  iterator-optimizations! cf Gen_Set for how to do this! *)\n  lemma foldli_add: \"det_fold_map X \n    (\\<lambda>_. True) (\\<lambda>(k,v) m. op_map_update k v m) m (op ++ m)\"\n  proof (rule, goal_cases)\n    case (1 l) thus ?case\n      apply (induct l arbitrary: m) \n      apply (auto simp: map_of_distinct_upd[symmetric])\n      done\n  qed\n\n  definition gen_add\n    :: \"('s2 \\<Rightarrow> _) \\<Rightarrow> ('k \\<Rightarrow> 'v \\<Rightarrow> 's1 \\<Rightarrow> 's1) \\<Rightarrow> 's1 \\<Rightarrow> 's2 \\<Rightarrow> 's1\"\n    where \n    \"gen_add it upd A B \\<equiv> it B (\\<lambda>_. True) (\\<lambda>(k,v) m. upd k v m) A\"\n\n  lemma gen_add[autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes UPD: \"GEN_OP ins op_map_update (Rk\\<rightarrow>Rv\\<rightarrow>\\<langle>Rk,Rv\\<rangle>Rs1\\<rightarrow>\\<langle>Rk,Rv\\<rangle>Rs1)\"\n    assumes IT: \"SIDE_GEN_ALGO (is_map_to_list Rk Rv Rs2 tsl)\"\n    shows \"(gen_add (foldli o tsl) ins,op ++) \n      \\<in> (\\<langle>Rk,Rv\\<rangle>Rs1) \\<rightarrow> (\\<langle>Rk,Rv\\<rangle>Rs2) \\<rightarrow> (\\<langle>Rk,Rv\\<rangle>Rs1)\"\n    apply (intro fun_relI)\n    unfolding gen_add_def comp_def\n    apply (rule det_fold_map[OF foldli_add IT[unfolded autoref_tag_defs]])\n    apply (parametricity add: UPD[unfolded autoref_tag_defs])+\n    done\n\n  lemma foldli_restrict: \"det_fold_map X (\\<lambda>_. True) \n    (\\<lambda>(k,v) m. if P (k,v) then op_map_update k v m else m) Map.empty\n      (op_map_restrict P )\" (is \"det_fold_map _ _ ?f _ _\")\n  proof -\n    {\n      fix l m\n      have \"distinct (map fst l) \\<Longrightarrow>\n        foldli l (\\<lambda>_. True) ?f m = m ++ op_map_restrict P (map_of l)\"\n      proof (induction l arbitrary: m) \n        case Nil thus ?case by simp\n      next\n        case (Cons kv l)\n        obtain k v where [simp]: \"kv = (k,v)\" by fastforce\n        from Cons.prems have \n          DL: \"distinct (map fst l)\" and KNI: \"k \\<notin> set (map fst l)\" \n          by auto\n\n        show ?case proof (cases \"P (k,v)\")\n          case [simp]: True \n          have \"foldli (kv#l) (\\<lambda>_. True) ?f m = foldli l (\\<lambda>_. True) ?f (m(k\\<mapsto>v))\"\n            by simp\n          also from Cons.IH[OF DL] have \n            \"\\<dots> = m(k\\<mapsto>v) ++ op_map_restrict P (map_of l)\" .\n          also have \"\\<dots> = m ++ op_map_restrict P (map_of (kv#l))\"\n            using KNI\n            by (auto\n              split: option.splits\n              intro!: ext \n              simp: Map.restrict_map_def Map.map_add_def\n              simp: map_of_eq_None_iff[symmetric])\n          finally show ?thesis .\n        next\n          case [simp]: False \n          have \"foldli (kv#l) (\\<lambda>_. True) ?f m = foldli l (\\<lambda>_. True) ?f m\"\n            by simp\n          also from Cons.IH[OF DL] have \n            \"\\<dots> = m ++ op_map_restrict P (map_of l)\" .\n          also have \"\\<dots> = m ++ op_map_restrict P (map_of (kv#l))\"\n            using KNI\n            by (auto \n              intro!: ext\n              simp: Map.restrict_map_def Map.map_add_def\n              simp: map_of_eq_None_iff[symmetric]\n            )\n          finally show ?thesis .\n        qed\n      qed\n    } \n    from this[of _ Map.empty] show ?thesis\n      by (auto intro!: det_fold_mapI)\n  qed\n\n  definition gen_restrict :: \"('s1 \\<Rightarrow> _) \\<Rightarrow> _\"\n    where \"gen_restrict it upd emp P m \n    \\<equiv> it m (\\<lambda>_. True) (\\<lambda>(k,v) m. if P (k,v) then upd k v m else m) emp\"\n\n  lemma gen_restrict[autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes IT: \"SIDE_GEN_ALGO (is_map_to_list Rk Rv Rs1 tsl)\"\n    assumes INS: \n      \"GEN_OP upd op_map_update (Rk\\<rightarrow>Rv\\<rightarrow>\\<langle>Rk,Rv\\<rangle>Rs2\\<rightarrow>\\<langle>Rk,Rv\\<rangle>Rs2)\"\n    assumes EMPTY: \n      \"GEN_OP emp Map.empty (\\<langle>Rk,Rv\\<rangle>Rs2)\"\n    shows \"(gen_restrict (foldli o tsl) upd emp,op_map_restrict) \n    \\<in> (\\<langle>Rk,Rv\\<rangle>prod_rel \\<rightarrow> Id) \\<rightarrow> (\\<langle>Rk,Rv\\<rangle>Rs1) \\<rightarrow> (\\<langle>Rk,Rv\\<rangle>Rs2)\"\n    apply (intro fun_relI)\n    unfolding gen_restrict_def comp_def\n    apply (rule det_fold_map[OF foldli_restrict IT[unfolded autoref_tag_defs]])\n    using INS EMPTY unfolding autoref_tag_defs\n    apply (parametricity)+\n    done\n\n  lemma fold_map_of: \n    \"fold (\\<lambda>(k,v) s. op_map_update k v s) (rev l) Map.empty = map_of l\"\n  proof -\n    {\n      fix m\n      have \"fold (\\<lambda>(k,v) s. s(k\\<mapsto>v)) (rev l) m = m ++ map_of l\"\n        apply (induct l arbitrary: m)\n        apply auto\n        done\n    } thus ?thesis by simp\n  qed\n\n  definition gen_map_of :: \"'m \\<Rightarrow> ('k\\<Rightarrow>'v\\<Rightarrow>'m\\<Rightarrow>'m) \\<Rightarrow> _\" where \n    \"gen_map_of emp upd l \\<equiv> fold (\\<lambda>(k,v) s. upd k v s) (rev l) emp\"\n\n\n  lemma gen_map_of[autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes UPD: \"GEN_OP upd op_map_update (Rk\\<rightarrow>Rv\\<rightarrow>\\<langle>Rk,Rv\\<rangle>Rm\\<rightarrow>\\<langle>Rk,Rv\\<rangle>Rm)\"\n    assumes EMPTY: \"GEN_OP emp Map.empty (\\<langle>Rk,Rv\\<rangle>Rm)\"\n    shows \"(gen_map_of emp upd,map_of) \\<in> \\<langle>\\<langle>Rk,Rv\\<rangle>prod_rel\\<rangle>list_rel \\<rightarrow> \\<langle>Rk,Rv\\<rangle>Rm\"\n    using assms\n    apply (intro fun_relI)\n    unfolding gen_map_of_def[abs_def]\n    unfolding autoref_tag_defs\n    apply (subst fold_map_of[symmetric])\n    apply parametricity\n    done\n\n  lemma foldli_ball_aux: \n    \"distinct (map fst l) \\<Longrightarrow> foldli l (\\<lambda>x. x) (\\<lambda>x _. P x) b \n    \\<longleftrightarrow> b \\<and> op_map_ball (map_of l) P\"\n    apply (induct l arbitrary: b)\n    apply simp\n    apply (force simp: map_to_set_map_of image_def)\n    done\n  \n  lemma foldli_ball: \n    \"det_fold_map X (\\<lambda>x. x) (\\<lambda>x _. P x) True (\\<lambda>m. op_map_ball m P)\"\n    apply rule\n    using foldli_ball_aux[where b=True] by auto\n    \n  definition gen_ball :: \"('m \\<Rightarrow> _) \\<Rightarrow> _\" where\n    \"gen_ball it m P \\<equiv> it m (\\<lambda>x. x) (\\<lambda>x _. P x) True\"\n\n  lemma gen_ball[autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes IT: \"SIDE_GEN_ALGO (is_map_to_list Rk Rv Rm tsl)\"\n    shows \"(gen_ball (foldli o tsl),op_map_ball) \n    \\<in> \\<langle>Rk,Rv\\<rangle>Rm \\<rightarrow> (\\<langle>Rk,Rv\\<rangle>prod_rel \\<rightarrow> Id) \\<rightarrow> Id\"\n    apply (intro fun_relI)\n    unfolding gen_ball_def comp_def\n    apply (rule det_fold_map[OF foldli_ball IT[unfolded autoref_tag_defs]])\n    apply (parametricity)+\n    done\n\n  lemma foldli_bex_aux: \n    \"distinct (map fst l) \\<Longrightarrow> foldli l (\\<lambda>x. \\<not>x) (\\<lambda>x _. P x) b \n    \\<longleftrightarrow> b \\<or> op_map_bex (map_of l) P\"\n    apply (induct l arbitrary: b)\n    apply simp\n    apply (force simp: map_to_set_map_of image_def)\n    done\n  \n  lemma foldli_bex: \n    \"det_fold_map X (\\<lambda>x. \\<not>x) (\\<lambda>x _. P x) False (\\<lambda>m. op_map_bex m P)\"\n    apply rule\n    using foldli_bex_aux[where b=False] by auto\n\n  definition gen_bex :: \"('m \\<Rightarrow> _) \\<Rightarrow> _\" where\n    \"gen_bex it m P \\<equiv> it m (\\<lambda>x. \\<not>x) (\\<lambda>x _. P x) False\"\n\n  lemma gen_bex[autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes IT: \"SIDE_GEN_ALGO (is_map_to_list Rk Rv Rm tsl)\"\n    shows \"(gen_bex (foldli o tsl),op_map_bex) \n    \\<in> \\<langle>Rk,Rv\\<rangle>Rm \\<rightarrow> (\\<langle>Rk,Rv\\<rangle>prod_rel \\<rightarrow> Id) \\<rightarrow> Id\"\n    apply (intro fun_relI)\n    unfolding gen_bex_def comp_def\n    apply (rule det_fold_map[OF foldli_bex IT[unfolded autoref_tag_defs]])\n    apply (parametricity)+\n    done\n\n  lemma ball_isEmpty: \"op_map_isEmpty m = op_map_ball m (\\<lambda>_. False)\"\n    apply (auto intro!: ext)\n    by (metis map_to_set_simps(7) option.exhaust)\n\n  definition \"gen_isEmpty ball m \\<equiv> ball m (\\<lambda>_. False)\"\n\n  lemma gen_isEmpty[autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes BALL: \n      \"GEN_OP ball op_map_ball (\\<langle>Rk,Rv\\<rangle>Rm\\<rightarrow>(\\<langle>Rk,Rv\\<rangle>prod_rel\\<rightarrow>Id) \\<rightarrow> Id)\"\n    shows \"(gen_isEmpty ball,op_map_isEmpty) \n    \\<in> \\<langle>Rk,Rv\\<rangle>Rm \\<rightarrow> Id\"\n    apply (intro fun_relI)\n    unfolding gen_isEmpty_def using assms\n    unfolding autoref_tag_defs\n    apply -\n    apply (subst ball_isEmpty)\n    apply parametricity+\n    done\n  \n  lemma foldli_size_aux: \"distinct (map fst l) \n    \\<Longrightarrow> foldli l (\\<lambda>_. True) (\\<lambda>_ n. Suc n) n = n + op_map_size (map_of l)\"\n    apply (induct l arbitrary: n)\n    apply (auto simp: dom_map_of_conv_image_fst)\n    done\n\n  lemma foldli_size: \"det_fold_map X (\\<lambda>_. True) (\\<lambda>_ n. Suc n) 0 op_map_size\"\n    apply rule\n    using foldli_size_aux[where n=0] by simp\n\n  definition gen_size :: \"('m \\<Rightarrow> _) \\<Rightarrow> _\"\n    where \"gen_size it m \\<equiv> it m (\\<lambda>_. True) (\\<lambda>_ n. Suc n) 0\"\n\n  lemma gen_size[autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes IT: \"SIDE_GEN_ALGO (is_map_to_list Rk Rv Rm tsl)\"\n    shows \"(gen_size (foldli o tsl),op_map_size) \\<in> \\<langle>Rk,Rv\\<rangle>Rm \\<rightarrow> Id\"\n    apply (intro fun_relI)\n    unfolding gen_size_def comp_def\n    apply (rule det_fold_map[OF foldli_size IT[unfolded autoref_tag_defs]])\n    apply (parametricity)+\n    done\n  \n  lemma foldli_size_abort_aux:\n    \"\\<lbrakk>n0\\<le>m; distinct (map fst l)\\<rbrakk> \\<Longrightarrow> \n      foldli l (\\<lambda>n. n<m) (\\<lambda>_ n. Suc n) n0 = min m (n0 + card (dom (map_of l)))\"\n    apply (induct l arbitrary: n0)\n    apply (auto simp: dom_map_of_conv_image_fst)\n    done\n\n  lemma foldli_size_abort: \n    \"det_fold_map X (\\<lambda>n. n<m) (\\<lambda>_ n. Suc n) 0 (op_map_size_abort m)\"\n    apply rule\n    using foldli_size_abort_aux[where ?n0.0=0]\n    by simp\n\n  definition gen_size_abort :: \"('s \\<Rightarrow> _) \\<Rightarrow> _\" where\n    \"gen_size_abort it m s \\<equiv> it s (\\<lambda>n. n<m) (\\<lambda>_ n. Suc n) 0\"\n\n  lemma gen_size_abort[autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes IT: \"SIDE_GEN_ALGO (is_map_to_list Rk Rv Rm tsl)\"\n    shows \"(gen_size_abort (foldli o tsl),op_map_size_abort) \n      \\<in> Id \\<rightarrow> \\<langle>Rk,Rv\\<rangle>Rm \\<rightarrow> Id\"\n    apply (intro fun_relI)\n    unfolding gen_size_abort_def comp_def\n    apply (rule det_fold_map[OF foldli_size_abort \n      IT[unfolded autoref_tag_defs]])\n    apply (parametricity)+\n    done\n  \n  lemma size_abort_isSng: \"op_map_isSng s \\<longleftrightarrow> op_map_size_abort 2 s = 1\"\n    by (auto simp: dom_eq_singleton_conv min_def dest!: card_eq_SucD)\n\n  definition gen_isSng :: \"(nat \\<Rightarrow> 's \\<Rightarrow> nat) \\<Rightarrow> _\" where\n    \"gen_isSng sizea s \\<equiv> sizea 2 s = 1\"\n\n  lemma gen_isSng[autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes \"GEN_OP sizea op_map_size_abort (Id \\<rightarrow> (\\<langle>Rk,Rv\\<rangle>Rm) \\<rightarrow> Id)\"\n    shows \"(gen_isSng sizea,op_map_isSng) \n    \\<in> \\<langle>Rk,Rv\\<rangle>Rm \\<rightarrow> Id\"\n    apply (intro fun_relI)\n    unfolding gen_isSng_def using assms\n    unfolding autoref_tag_defs\n    apply -\n    apply (subst size_abort_isSng)\n    apply parametricity\n    done\n\n\n  (* TODO: Also do sel! *)\n\n  lemma foldli_pick:\n    assumes \"l\\<noteq>[]\" \n    obtains k v where \"(k,v)\\<in>set l\" \n    and \"(foldli l (case_option True (\\<lambda>_. False)) (\\<lambda>x _. Some x) None) \n      = Some (k,v)\"\n    using assms by (cases l) auto\n\n  definition gen_pick where\n    \"gen_pick it s \\<equiv> \n      (the (it s (case_option True (\\<lambda>_. False)) (\\<lambda>x _. Some x) None))\"\n\n\n\ncontext begin interpretation autoref_syn .\n\n  lemma gen_pick[autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes IT: \"SIDE_GEN_ALGO (is_map_to_list Rk Rv Rm it)\"\n    assumes NE: \"SIDE_PRECOND (m'\\<noteq>Map.empty)\"\n    assumes SREF: \"(m,m')\\<in>\\<langle>Rk,Rv\\<rangle>Rm\"\n    shows \"(RETURN (gen_pick (\\<lambda>x. foldli (it x)) m), \n      (OP op_map_pick ::: \\<langle>Rk,Rv\\<rangle>Rm\\<rightarrow>\\<langle>Rk\\<times>\\<^sub>rRv\\<rangle>nres_rel)$m')\\<in>\\<langle>Rk\\<times>\\<^sub>rRv\\<rangle>nres_rel\"\n  proof -\n    thm is_map_to_list_def is_map_to_sorted_listE\n\n    obtain tsl' where\n      [param]: \"(it m,tsl') \\<in> \\<langle>Rk\\<times>\\<^sub>rRv\\<rangle>list_rel\" \n      and IT': \"RETURN tsl' \\<le> it_to_sorted_list (\\<lambda>_ _. True) (map_to_set m')\"\n      using IT[unfolded autoref_tag_defs is_map_to_list_def] SREF\n      by (auto intro: is_map_to_sorted_listE)\n\n    from IT' NE have \"tsl'\\<noteq>[]\" and [simp]: \"m'=map_of tsl'\" \n      and DIS': \"distinct (map fst tsl')\"\n      unfolding it_to_sorted_list_def \n      apply simp_all\n      apply (metis empty_set map_to_set_empty_iff(1))\n      apply (metis map_of_map_to_set map_to_set_distinct_conv)\n      apply (metis map_to_set_distinct_conv)\n      done\n\n    then obtain k v where \"m' k = Some v\" and\n      \"(foldli tsl' (case_option True (\\<lambda>_. False)) (\\<lambda>x _. Some x) None) \n        = Some (k,v)\"\n      (is \"?fld = _\")\n      by (cases rule: foldli_pick) auto\n    moreover \n    have \"(RETURN (gen_pick (\\<lambda>x. foldli (it x)) m), RETURN (the ?fld)) \n      \\<in> \\<langle>Rk\\<times>\\<^sub>rRv\\<rangle>nres_rel\"\n      unfolding gen_pick_def\n      apply (parametricity add: the_paramR)\n      using `?fld = Some (k,v)`\n      by simp\n    ultimately show ?thesis\n      unfolding autoref_tag_defs\n      apply -\n      apply (drule nres_relD)\n      apply (rule nres_relI)\n      apply (erule ref_two_step)\n      by simp\n  qed\nend\n\n\n  definition \"gen_map_pick_remove pick del m \\<equiv> do {\n    (k,v)\\<leftarrow>pick m;\n    let m = del k m;\n    RETURN ((k,v),m)\n    }\"\n  \ncontext begin interpretation autoref_syn .\n  lemma gen_map_pick_remove\n    [unfolded gen_map_pick_remove_def, autoref_rules_raw]:\n    assumes PRIO_TAG_GEN_ALGO\n    assumes PICK: \"SIDE_GEN_OP (\n      (pick m, \n      (OP op_map_pick ::: \\<langle>Rk,Rv\\<rangle>Rm \\<rightarrow> \\<langle>Rk\\<times>\\<^sub>rRv\\<rangle>nres_rel)$m') \\<in>\n      \\<langle>Rk\\<times>\\<^sub>rRv\\<rangle>nres_rel)\"\n    assumes DEL: \"GEN_OP del op_map_delete (Rk \\<rightarrow> \\<langle>Rk,Rv\\<rangle>Rm \\<rightarrow> \\<langle>Rk,Rv\\<rangle>Rm)\"\n    assumes [param]: \"(m,m')\\<in>\\<langle>Rk,Rv\\<rangle>Rm\"\n    shows \"(gen_map_pick_remove pick del m, \n      (OP op_map_pick_remove \n        ::: \\<langle>Rk,Rv\\<rangle>Rm \\<rightarrow> \\<langle>(Rk\\<times>\\<^sub>rRv) \\<times>\\<^sub>r \\<langle>Rk,Rv\\<rangle>Rm\\<rangle>nres_rel)$m')\n      \\<in> \\<langle>(Rk\\<times>\\<^sub>rRv) \\<times>\\<^sub>r \\<langle>Rk,Rv\\<rangle>Rm\\<rangle>nres_rel\"\n  proof -\n    note [param] = \n      PICK[unfolded autoref_tag_defs] \n      DEL[unfolded autoref_tag_defs]\n\n    have \"(gen_map_pick_remove pick del m, \n      do {    \n        (k,v)\\<leftarrow>op_map_pick m';\n        let m' = op_map_delete k m';\n        RETURN ((k,v),m')\n      }) \\<in> \\<langle>(Rk\\<times>\\<^sub>rRv) \\<times>\\<^sub>r \\<langle>Rk,Rv\\<rangle>Rm\\<rangle>nres_rel\" (is \"(_,?h):_\")\n      unfolding gen_map_pick_remove_def[abs_def]\n      apply parametricity\n      done\n    also have \"?h = op_map_pick_remove m'\"\n      by (auto simp add: pw_eq_iff refine_pw_simps)\n    finally show ?thesis by simp\n  qed\nend\n\n\nend\n", "meta": {"author": "andredidier", "repo": "phd", "sha": "113f7c8b360a3914a571db13d9513e313954f4b2", "save_path": "github-repos/isabelle/andredidier-phd", "path": "github-repos/isabelle/andredidier-phd/phd-113f7c8b360a3914a571db13d9513e313954f4b2/thesis/Collections/GenCF/Gen/Gen_Map.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.2735521581443009}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      AlternativeSmallStep.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2006-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nheader  {* Alternative Small Step Semantics *}\n\ntheory AlternativeSmallStep imports HoareTotalDef\nbegin\n\n\ntext {* \nThis is the small-step semantics, which is described and used in my PhD-thesis \\cite{Schirmer-PhD}. \nIt decomposes the statement into a list of statements and finally executes the head.\nSo the redex is always the head of the list. The equivalence between termination\n(based on the big-step semantics) and the absence of infinite computations in\nthis small-step semantics follows the same lines of reasoning as for\nthe new small-step semantics. However, it is technically more involved since\nthe configurations are more complicated. Thats why I switched to the new small-step\nsemantics in the \"main trunk\". I keep this alternative version and the important\nproofs in this theory, so that one can compare both approaches.\n*}\n\n\nsubsection {*Small-Step Computation: @{text \"\\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow> (cs', css', s')\"}*}\n\ntype_synonym ('s,'p,'f) continuation = \"('s,'p,'f) com list \\<times> ('s,'p,'f) com list\"\n \ntype_synonym ('s,'p,'f) config =\n  \"('s,'p,'f)com list \\<times> ('s,'p,'f)continuation list \\<times> ('s,'f) xstate\"\n\n\n\ninductive \"step\"::\"[('s,'p,'f) body,('s,'p,'f) config,('s,'p,'f) config] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile> (_ \\<rightarrow>/ _)\" [81,81,81] 100)\n  for \\<Gamma>::\"('s,'p,'f) body\"\nwhere\n  Skip: \"\\<Gamma>\\<turnstile>(Skip#cs,css,Normal s) \\<rightarrow> (cs,css,Normal s)\"\n| Guard: \"s\\<in>g \\<Longrightarrow> \\<Gamma>\\<turnstile>(Guard f g c#cs,css,Normal s) \\<rightarrow> (c#cs,css,Normal s)\"\n  \n| GuardFault: \"s\\<notin>g \\<Longrightarrow> \\<Gamma>\\<turnstile>(Guard f g c#cs,css,Normal s) \\<rightarrow> (cs,css,Fault f)\"\n\n| FaultProp: \"\\<Gamma>\\<turnstile>(c#cs,css,Fault f) \\<rightarrow> (cs,css,Fault f)\" \n| FaultPropBlock: \"\\<Gamma>\\<turnstile>([],(nrms,abrs)#css,Fault f) \\<rightarrow> (nrms,css,Fault f)\"\n  (* FaultPropBlock: \"\\<Gamma>\\<turnstile>([],cs#css,Fault) \\<rightarrow> ([],css,Fault)\"*)\n    \n| AbruptProp:  \"\\<Gamma>\\<turnstile>(c#cs,css,Abrupt s) \\<rightarrow> (cs,css,Abrupt s)\"\n \n| ExitBlockNormal: \n    \"\\<Gamma>\\<turnstile>([],(nrms,abrs)#css,Normal s) \\<rightarrow> (nrms,css,Normal s)\"\n| ExitBlockAbrupt: \n    \"\\<Gamma>\\<turnstile>([],(nrms,abrs)#css,Abrupt s) \\<rightarrow> (abrs,css,Normal s)\"\n\n| Basic: \"\\<Gamma>\\<turnstile>(Basic f#cs,css,Normal s) \\<rightarrow> (cs,css,Normal (f s))\"\n\n| Spec: \"(s,t) \\<in> r \\<Longrightarrow> \\<Gamma>\\<turnstile>(Spec r#cs,css,Normal s) \\<rightarrow> (cs,css,Normal t)\"\n| SpecStuck: \"\\<forall>t. (s,t) \\<notin> r \\<Longrightarrow> \\<Gamma>\\<turnstile>(Spec r#cs,css,Normal s) \\<rightarrow> (cs,css,Stuck)\"\n\n| Seq: \"\\<Gamma>\\<turnstile>(Seq c\\<^sub>1 c\\<^sub>2#cs,css,Normal s) \\<rightarrow> (c\\<^sub>1#c\\<^sub>2#cs,css,Normal s)\"\n\n| CondTrue:  \"s\\<in>b \\<Longrightarrow> \\<Gamma>\\<turnstile>(Cond b c\\<^sub>1 c\\<^sub>2#cs,css,Normal s) \\<rightarrow> (c\\<^sub>1#cs,css,Normal s)\"\n| CondFalse: \"s\\<notin>b \\<Longrightarrow> \\<Gamma>\\<turnstile>(Cond b c\\<^sub>1 c\\<^sub>2#cs,css,Normal s) \\<rightarrow> (c\\<^sub>2#cs,css,Normal s)\"\n\n| WhileTrue: \"\\<lbrakk>s\\<in>b\\<rbrakk> \n              \\<Longrightarrow> \n   \\<Gamma>\\<turnstile>(While b c#cs,css,Normal s) \\<rightarrow> (c#While b c#cs,css,Normal s)\"\n| WhileFalse: \"\\<lbrakk>s\\<notin>b\\<rbrakk> \n               \\<Longrightarrow> \n               \\<Gamma>\\<turnstile>(While b c#cs,css,Normal s) \\<rightarrow> (cs,css,Normal s)\"\n\n| Call: \"\\<Gamma> p=Some bdy \\<Longrightarrow>\n         \\<Gamma>\\<turnstile>(Call p#cs,css,Normal s) \\<rightarrow> ([bdy],(cs,Throw#cs)#css,Normal s)\"\n\n| CallUndefined: \"\\<Gamma> p=None \\<Longrightarrow>\n         \\<Gamma>\\<turnstile>(Call p#cs,css,Normal s) \\<rightarrow> (cs,css,Stuck)\"\n\n| StuckProp: \"\\<Gamma>\\<turnstile>(c#cs,css,Stuck) \\<rightarrow> (cs,css,Stuck)\" \n| StuckPropBlock: \"\\<Gamma>\\<turnstile>([],(nrms,abrs)#css,Stuck) \\<rightarrow> (nrms,css,Stuck)\"\n\n| DynCom: \"\\<Gamma>\\<turnstile>(DynCom c#cs,css,Normal s) \\<rightarrow> (c s#cs,css,Normal s)\"\n\n| Throw: \"\\<Gamma>\\<turnstile>(Throw#cs,css,Normal s) \\<rightarrow> (cs,css,Abrupt s)\"\n| Catch: \"\\<Gamma>\\<turnstile>(Catch c\\<^sub>1 c\\<^sub>2#cs,css,Normal s) \\<rightarrow> ([c\\<^sub>1],(cs,c\\<^sub>2#cs)#css,Normal s)\"\n\nlemmas step_induct = step.induct [of _ \"(c,css,s)\" \"(c',css',s')\", split_format (complete), \ncase_names\nSkip Guard GuardFault FaultProp FaultPropBlock AbruptProp ExitBlockNormal ExitBlockAbrupt\nBasic Spec SpecStuck Seq CondTrue CondFalse WhileTrue WhileFalse Call CallUndefined\nStuckProp StuckPropBlock DynCom Throw Catch, induct set]\n\ninductive_cases step_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>(c#cs,css,Fault f) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>([],css,Fault f) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(c#cs,css,Stuck) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>([],css,Stuck) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(c#cs,css,Abrupt s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>([],css,Abrupt s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>([],css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Skip#cs,css,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Guard f g c#cs,css,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Basic f#cs,css,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Spec r#cs,css,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Seq c1 c2#cs,css,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Cond b c1 c2#cs,css,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(While b c#cs,css,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Call p#cs,css,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(DynCom c#cs,css,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Throw#cs,css,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Catch c1 c2#cs,css,s) \\<rightarrow> u\"\n\ninductive_cases step_Normal_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>(c#cs,css,Fault f) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>([],css,Fault f) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(c#cs,css,Stuck) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>([],css,Stuck) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>([],(nrms,abrs)#css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>([],(nrms,abrs)#css,Abrupt s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Skip#cs,css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Guard f g c#cs,css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Basic f#cs,css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Spec r#cs,css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Seq c1 c2#cs,css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Cond b c1 c2#cs,css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(While b c#cs,css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Call p#cs,css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(DynCom c#cs,css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Throw#cs,css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Catch c1 c2#cs,css,Normal s) \\<rightarrow> u\"\n\nabbreviation\n \"step_rtrancl\" :: \"[('s,'p,'f) body,('s,'p,'f) config,('s,'p,'f) config] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile> (_ \\<rightarrow>\\<^sup>*/ _)\" [81,81,81] 100)\n  where\n  \"\\<Gamma>\\<turnstile>cs0 \\<rightarrow>\\<^sup>* cs1     == (step \\<Gamma>)\\<^sup>*\\<^sup>* cs0 cs1\"\n\nabbreviation\n\n \"step_trancl\" :: \"[('s,'p,'f) body,('s,'p,'f) config,('s,'p,'f) config] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile> (_ \\<rightarrow>\\<^sup>+/ _)\" [81,81,81] 100)\n  where\n  \"\\<Gamma>\\<turnstile>cs0 \\<rightarrow>\\<^sup>+ cs1     == (step \\<Gamma>)\\<^sup>+\\<^sup>+ cs0 cs1\"\n\n\nsubsubsection {* Structural Properties of Small Step Computations *}\n\nlemma Fault_app_steps: \"\\<Gamma>\\<turnstile>(cs@xs,css,Fault f) \\<rightarrow>\\<^sup>* (xs,css,Fault f)\"\nproof (induct cs)\n  case Nil thus ?case by simp\nnext\n  case (Cons c cs)\n  have \"\\<Gamma>\\<turnstile>(c#cs@xs, css, Fault f) \\<rightarrow>\\<^sup>* (xs, css, Fault f)\"\n  proof -\n    have \"\\<Gamma>\\<turnstile>(c#cs@xs, css, Fault f) \\<rightarrow> (cs@xs, css, Fault f)\"\n      by (rule step.FaultProp)\n    also \n    have \"\\<Gamma>\\<turnstile>(cs@xs, css, Fault f) \\<rightarrow>\\<^sup>* (xs, css, Fault f)\"\n      by (rule Cons.hyps)\n    finally show ?thesis .\n  qed\n  thus ?case\n    by simp\nqed\n\nlemma Stuck_app_steps: \"\\<Gamma>\\<turnstile>(cs@xs,css,Stuck) \\<rightarrow>\\<^sup>* (xs,css,Stuck)\"\nproof (induct cs)\n  case Nil thus ?case by simp\nnext\n  case (Cons c cs)\n  have \"\\<Gamma>\\<turnstile>(c#cs@xs, css, Stuck) \\<rightarrow>\\<^sup>* (xs, css, Stuck)\"\n  proof -\n    have \"\\<Gamma>\\<turnstile>(c#cs@xs, css, Stuck) \\<rightarrow> (cs@xs, css, Stuck)\"\n      by (rule step.StuckProp)\n    also \n    have \"\\<Gamma>\\<turnstile>(cs@xs, css, Stuck) \\<rightarrow>\\<^sup>* (xs, css, Stuck)\"\n      by (rule Cons.hyps)\n    finally show ?thesis .\n  qed\n  thus ?case\n    by simp\nqed\n\ntext {* We can only append commands inside a block, if execution does not\n        enter or exit a block.\n      *}\nlemma app_step:  \n  assumes step: \"\\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow> (cs',css',t)\"\n  shows \"css=css' \\<Longrightarrow> \\<Gamma>\\<turnstile>(cs@xs,css,s) \\<rightarrow> (cs'@xs,css',t)\"\nusing step\napply induct\napply (simp_all del: fun_upd_apply,(blast intro: step.intros)+)\ndone\n\ntext {* We can append whole blocks, without interfering with the actual\n        block. Outer blocks do not influence execution of\n        inner blocks. *}\nlemma app_css_step:  \n  assumes step: \"\\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow> (cs',css',t)\"\n  shows \"\\<Gamma>\\<turnstile>(cs,css@xs,s) \\<rightarrow> (cs',css'@xs,t)\"\nusing step\napply induct\napply (simp_all del: fun_upd_apply,(blast intro: step.intros)+)\ndone\n\nML {*\n  ML_Thms.bind_thm (\"trancl_induct3\", Split_Rule.split_rule @{context}\n    (Rule_Insts.read_instantiate @{context} [((\"a\", 0), \"(ax,ay,az)\"), ((\"b\", 0), \"(bx,by,bz)\")] []\n      @{thm tranclp_induct}));\n*}\n\nlemma app_css_steps:  \n  assumes step: \"\\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow>\\<^sup>+ (cs',css',t)\"\n  shows \"\\<Gamma>\\<turnstile>(cs,css@xs,s) \\<rightarrow>\\<^sup>+ (cs',css'@xs,t)\"\napply(rule trancl_induct3 [OF step])\n apply (rule app_css_step [THEN tranclp.r_into_trancl [of \"step \\<Gamma>\"]],assumption)\napply(blast intro:app_css_step tranclp_trans)\ndone\n\nlemma step_Cons':  \n  assumes step: \"\\<Gamma>\\<turnstile>(ccs,css,s) \\<rightarrow> (cs',css',t)\"\n  shows\n  \"\\<And>c cs. ccs=c#cs \\<Longrightarrow> \\<exists>css''. css'=css''@css \\<and>\n      (if css''=[] then \\<exists>p. cs'=p@cs\n       else (\\<exists>pnorm pabr. css''=[(pnorm@cs,pabr@cs)]))\"\nusing step\nby induct force+\n\nlemma step_Cons:  \n  assumes step: \"\\<Gamma>\\<turnstile>(c#cs,css,s) \\<rightarrow> (cs',css',t)\"\n  shows \"\\<exists>pcss. css'=pcss@css \\<and>\n         (if pcss=[] then \\<exists>ps. cs'=ps@cs\n          else (\\<exists>pcs_normal pcs_abrupt. pcss=[(pcs_normal@cs,pcs_abrupt@cs)]))\"\nusing step_Cons' [OF step]\nby blast  \n\n\nlemma step_Nil':  \n  assumes step: \"\\<Gamma>\\<turnstile>(cs,asscss,s) \\<rightarrow> (cs',css',t)\"\n  shows\n  \"\\<And>ass. \\<lbrakk>cs=[]; asscss=ass@css; ass\\<noteq>Nil\\<rbrakk> \\<Longrightarrow> \n          css'=tl ass@css \\<and>\n          (case s of \n             Abrupt s' \\<Rightarrow> cs'=snd (hd ass) \\<and> t=Normal s'\n           |  _ \\<Rightarrow> cs'=fst (hd ass) \\<and> t=s)\"\nusing step\nby (induct) (fastforce simp add: neq_Nil_conv)+\n\nlemma step_Nil:  \n  assumes step: \"\\<Gamma>\\<turnstile>([],ass@css,s) \\<rightarrow> (cs',css',t)\"\n  assumes ass_not_Nil: \"ass\\<noteq>[]\"\n  shows \"css'=tl ass@css \\<and>\n          (case s of \n             Abrupt s' \\<Rightarrow> cs'=snd (hd ass) \\<and> t=Normal s'\n           |  _ \\<Rightarrow> cs'=fst (hd ass) \\<and> t=s)\"\n  using step_Nil' [OF step _ _ ass_not_Nil]\n  by simp\n\nlemma step_Nil'':  \n  assumes step: \"\\<Gamma>\\<turnstile>([],(pcs_normal,pcs_abrupt)#pcss@css,s) \\<rightarrow> (cs',pcss@css,t)\"\n  shows \"(case s of \n             Abrupt s' \\<Rightarrow> cs'=pcs_abrupt \\<and> t=Normal s'\n           |  _ \\<Rightarrow> cs'=pcs_normal \\<and> t=s)\"\n  using step_Nil' [OF step, where ass =\"(pcs_normal,pcs_abrupt)#pcss\" and css=\"css\"]\n  by (auto split: xstate.splits)\n\nlemma drop_suffix_css_step':\nassumes step: \"\\<Gamma>\\<turnstile>(cs,cssxs,s) \\<rightarrow> (cs',css'xs,t)\"\nshows \"\\<And>css css' xs. \\<lbrakk>cssxs = css@xs; css'xs=css'@xs\\<rbrakk> \n     \\<Longrightarrow> \\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow> (cs',css',t)\"\nusing step\napply induct\napply (fastforce intro: step.intros)+\ndone\n\nlemma drop_suffix_css_step:\nassumes step: \"\\<Gamma>\\<turnstile>(cs,pcss@css,s) \\<rightarrow> (cs',pcss'@css,t)\"\nshows \"\\<Gamma>\\<turnstile>(cs,pcss,s) \\<rightarrow> (cs',pcss',t)\"\nusing step by (blast intro: drop_suffix_css_step')\n\nlemma drop_suffix_hd_css_step': \n  assumes step: \"\\<Gamma>\\<turnstile> (pcs,css,s) \\<rightarrow> (cs',css'css,t)\"\n  shows \"\\<And>p ps cs pnorm pabr. \\<lbrakk>pcs=p#ps@cs; css'css=(pnorm@cs,pabr@cs)#css\\<rbrakk> \n         \\<Longrightarrow> \\<Gamma>\\<turnstile> (p#ps,css,s) \\<rightarrow> (cs',(pnorm,pabr)#css,t)\"\nusing step\nby induct (force intro: step.intros)+\n\nlemma drop_suffix_hd_css_step'': \n  assumes step: \"\\<Gamma>\\<turnstile> (p#ps@cs,css,s) \\<rightarrow> (cs',(pnorm@cs,pabr@cs)#css,t)\"\n  shows  \"\\<Gamma>\\<turnstile> (p#ps,css,s) \\<rightarrow> (cs',(pnorm,pabr)#css,t)\"\nusing drop_suffix_hd_css_step' [OF step]\nby auto\n\nlemma drop_suffix_hd_css_step: \n  assumes step: \"\\<Gamma>\\<turnstile> (p#ps@cs,css,s) \\<rightarrow> (cs',[(pnorm@ps@cs,pabr@ps@cs)]@css,t)\"\n  shows  \"\\<Gamma>\\<turnstile> (p#ps,css,s) \\<rightarrow> (cs',[(pnorm@ps,pabr@ps)]@css,t)\"\nproof -\n  from step drop_suffix_hd_css_step'' [of _ p ps cs css s cs' \"pnorm@ps\" \"pabr@ps\" t]\n  show ?thesis\n    by auto\nqed\n\nlemma drop_suffix':  \n  assumes step: \"\\<Gamma>\\<turnstile>(csxs,css,s) \\<rightarrow> (cs'xs,css',t)\"\n  shows \"\\<And>xs cs cs'. \\<lbrakk>css=css'; csxs=cs@xs; cs'xs = cs'@xs; cs\\<noteq>[] \\<rbrakk> \n         \\<Longrightarrow> \\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow> (cs',css,t)\"\nusing step\napply induct\napply (fastforce intro: step.intros simp add: neq_Nil_conv)+\ndone\n\nlemma drop_suffix: \n  assumes step: \"\\<Gamma>\\<turnstile>(c#cs@xs,css,s) \\<rightarrow> (cs'@xs,css,t)\" \n  shows \"\\<Gamma>\\<turnstile>(c#cs,css,s) \\<rightarrow> (cs',css,t)\"\n  by(rule drop_suffix' [OF step _ _ _]) auto\n\nlemma drop_suffix_same_css_step: \n  assumes step: \"\\<Gamma>\\<turnstile>(cs@xs,css,s) \\<rightarrow> (cs'@xs,css,t)\" \n  assumes not_Nil: \"cs\\<noteq>[]\"\n  shows \"\\<Gamma>\\<turnstile>(cs,xss,s) \\<rightarrow> (cs',xss,t)\"\nproof-\n  from drop_suffix' [OF step _ _ _ not_Nil]\n  have \"\\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow> (cs',css,t)\"\n    by auto\n  with drop_suffix_css_step [of _ cs \"[]\" css s cs' \"[]\" t]\n  have \"\\<Gamma>\\<turnstile> (cs, [], s) \\<rightarrow> (cs', [], t)\"\n    by auto\n  from app_css_step [OF this]\n  show ?thesis\n    by auto\nqed\n \nlemma Cons_change_css_step:\n  assumes step: \"\\<Gamma>\\<turnstile> (cs,css,s) \\<rightarrow> (cs',css'@css,t)\"\n  shows \"\\<Gamma>\\<turnstile> (cs,xss,s) \\<rightarrow> (cs',css'@xss,t)\"\nproof -\n  from step\n    drop_suffix_css_step [where cs=cs and pcss=\"[]\" and css=css and s=s\n                             and cs'=cs' and pcss'=css' and t=t]\n  have \"\\<Gamma>\\<turnstile> (cs, [], s) \\<rightarrow> (cs', css', t)\"\n    by auto\n  from app_css_step [where xs=xss, OF this]\n  show ?thesis\n    by auto\nqed\n\nlemma Nil_change_css_step:\n  assumes step: \"\\<Gamma>\\<turnstile>([],ass@css,s) \\<rightarrow> (cs',ass'@css,t)\"\n  assumes ass_not_Nil: \"ass\\<noteq>[]\"\n  shows \"\\<Gamma>\\<turnstile>([],ass@xss,s) \\<rightarrow> (cs',ass'@xss,t)\"\nproof -\n  from step drop_suffix_css_step [of _ \"[]\" ass css s cs' ass' t]\n  have \"\\<Gamma>\\<turnstile> ([], ass, s) \\<rightarrow> (cs', ass', t)\"\n    by auto\n  from app_css_step [where xs=xss, OF this]\n  show ?thesis\n    by auto\nqed\n\nsubsubsection {* Equivalence between Big and Small-Step Semantics *}\n    \nlemma exec_impl_steps:\n  assumes exec: \"\\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t\"\n  shows \"\\<And>cs css. \\<Gamma>\\<turnstile>(c#cs,css,s) \\<rightarrow>\\<^sup>* (cs,css,t)\"\nusing exec\nproof (induct)\n  case Skip thus ?case by (blast intro: step.Skip)\nnext\n  case Guard thus ?case by (blast intro: step.Guard rtranclp_trans)\nnext\n  case GuardFault thus ?case by (blast intro: step.GuardFault)\nnext\n  case FaultProp thus ?case by (blast intro: step.FaultProp)\nnext\n  case Basic thus ?case by (blast intro: step.Basic)\nnext\n  case Spec thus ?case by (blast intro: step.Spec)\nnext\n  case SpecStuck thus ?case by (blast intro: step.SpecStuck)\nnext\n  case Seq thus ?case by (blast intro: step.Seq rtranclp_trans)\nnext\n  case CondTrue thus ?case by (blast intro: step.CondTrue rtranclp_trans)\nnext\n  case CondFalse thus ?case by (blast intro: step.CondFalse rtranclp_trans)\nnext\n  case WhileTrue thus ?case by (blast intro: step.WhileTrue rtranclp_trans)\nnext\n  case WhileFalse thus ?case by (blast intro: step.WhileFalse)\nnext\n  case (Call p bdy s s' cs css)\n  have bdy: \"\\<Gamma> p = Some bdy\" by fact\n  have steps_body: \"\\<Gamma>\\<turnstile>([bdy],(cs,Throw#cs)#css,Normal s) \\<rightarrow>\\<^sup>* \n                       ([],(cs,Throw#cs)#css, s')\" by fact\n  show ?case\n  proof (cases s')\n    case (Normal s'')\n    note steps_body\n    also from Normal have \"\\<Gamma>\\<turnstile>([],(cs,Throw#cs)#css, s') \\<rightarrow> (cs,css,s')\"\n      by (auto intro: step.intros)\n    finally show ?thesis\n      using bdy\n      by (blast intro: step.Call rtranclp_trans)\n  next\n    case (Abrupt s'')\n    with steps_body \n    have \"\\<Gamma>\\<turnstile>([bdy],(cs,Throw#cs)#css,Normal s) \\<rightarrow>\\<^sup>* \n             ([],(cs,Throw#cs)#css, Abrupt s'')\" by simp\n    also have \"\\<Gamma>\\<turnstile>([],(cs,Throw#cs)#css, Abrupt s'') \\<rightarrow> (Throw#cs,css,Normal s'')\"\n      by (rule ExitBlockAbrupt)\n    also have \"\\<Gamma>\\<turnstile>(Throw#cs,css,Normal s'') \\<rightarrow> (cs,css,Abrupt s'')\"\n      by (rule Throw)\n    finally show ?thesis\n      using bdy Abrupt\n      by (auto intro: step.Call rtranclp_trans)\n  next\n    case Fault\n    note steps_body\n    also from Fault have \"\\<Gamma>\\<turnstile>([],(cs,Throw#cs)#css, s') \\<rightarrow> (cs,css,s')\"\n      by (auto intro: step.intros)\n    finally show ?thesis\n      using bdy\n      by (blast intro: step.Call rtranclp_trans)\n  next\n    case Stuck\n    note steps_body\n    also from Stuck have \"\\<Gamma>\\<turnstile>([],(cs,Throw#cs)#css, s') \\<rightarrow> (cs,css,s')\"\n      by (auto intro: step.intros)\n    finally show ?thesis\n      using bdy\n      by (blast intro: step.Call rtranclp_trans)\n  qed\nnext\n  case (CallUndefined p s cs css)\n  have undef: \"\\<Gamma> p = None\" by fact\n  hence \"\\<Gamma>\\<turnstile>(Call p # cs, css, Normal s) \\<rightarrow> (cs, css, Stuck)\"\n    by (rule step.CallUndefined)\n  thus ?case ..\nnext\n  case StuckProp thus ?case by (blast intro: step.StuckProp rtrancl_trans)\nnext\n  case DynCom thus ?case by (blast intro: step.DynCom rtranclp_trans)\nnext\n   case Throw thus ?case by (blast intro: step.Throw)\nnext\n  case AbruptProp thus ?case by (blast intro: step.AbruptProp)\nnext\n  case (CatchMatch c\\<^sub>1 s s' c\\<^sub>2 s'' cs css) \n  have steps_c1: \"\\<Gamma>\\<turnstile>([c\\<^sub>1],(cs,c\\<^sub>2#cs)#css,Normal s) \\<rightarrow>\\<^sup>* \n                    ([],(cs,c\\<^sub>2#cs)#css,Abrupt s')\" by fact\n  also\n  have \"\\<Gamma>\\<turnstile>([],(cs,c\\<^sub>2#cs)#css,Abrupt s') \\<rightarrow> (c\\<^sub>2#cs,css,Normal s')\"\n    by (rule ExitBlockAbrupt)\n  also \n  have steps_c2: \"\\<Gamma>\\<turnstile>(c\\<^sub>2#cs,css,Normal s') \\<rightarrow>\\<^sup>* (cs,css,s'')\"  by fact\n  finally\n  show \"\\<Gamma>\\<turnstile>(Catch c\\<^sub>1 c\\<^sub>2 # cs, css, Normal s) \\<rightarrow>\\<^sup>* (cs, css, s'')\"\n    by (blast intro: step.Catch rtranclp_trans)\nnext\n  case (CatchMiss c\\<^sub>1 s s' c\\<^sub>2 cs css) \n  assume notAbr: \"\\<not> isAbr s'\"\n  have steps_c1: \"\\<Gamma>\\<turnstile>([c\\<^sub>1],(cs,c\\<^sub>2#cs)#css,Normal s) \\<rightarrow>\\<^sup>* ([],(cs,c\\<^sub>2#cs)#css,s')\" by fact\n  show \"\\<Gamma>\\<turnstile>(Catch c\\<^sub>1 c\\<^sub>2 # cs, css, Normal s) \\<rightarrow>\\<^sup>* (cs, css, s')\"\n  proof (cases s')\n    case (Normal w)\n    with steps_c1\n    have \"\\<Gamma>\\<turnstile>([c\\<^sub>1],(cs,c\\<^sub>2#cs)#css,Normal s) \\<rightarrow>\\<^sup>* ([],(cs,c\\<^sub>2#cs)#css,Normal w)\"\n      by simp\n    also\n    have \"\\<Gamma>\\<turnstile>([],(cs,c\\<^sub>2#cs)#css,Normal w) \\<rightarrow> (cs,css,Normal w)\"\n      by (rule ExitBlockNormal)\n    finally show ?thesis using Normal\n      by (auto intro: step.Catch rtranclp_trans)\n  next\n    case Abrupt with notAbr show ?thesis by simp\n  next\n    case (Fault f)\n    with steps_c1\n    have \"\\<Gamma>\\<turnstile>([c\\<^sub>1],(cs,c\\<^sub>2#cs)#css,Normal s) \\<rightarrow>\\<^sup>* ([],(cs,c\\<^sub>2#cs)#css,Fault f)\"\n      by simp\n    also\n    have \"\\<Gamma>\\<turnstile>([],(cs,c\\<^sub>2#cs)#css,Fault f) \\<rightarrow> (cs,css,Fault f)\"\n      by (rule FaultPropBlock)\n    finally show ?thesis using Fault\n      by (auto intro: step.Catch rtranclp_trans)\n  next\n    case Stuck\n    with steps_c1\n    have \"\\<Gamma>\\<turnstile>([c\\<^sub>1],(cs,c\\<^sub>2#cs)#css,Normal s) \\<rightarrow>\\<^sup>* ([],(cs,c\\<^sub>2#cs)#css,Stuck)\"\n      by simp\n    also\n    have \"\\<Gamma>\\<turnstile>([],(cs,c\\<^sub>2#cs)#css,Stuck) \\<rightarrow> (cs,css,Stuck)\"\n      by (rule StuckPropBlock)\n    finally show ?thesis using Stuck\n      by (auto intro: step.Catch rtranclp_trans)\n  qed\nqed\n\n\ninductive \"execs\"::\"[('s,'p,'f) body,('s,'p,'f) com list,\n                      ('s,'p,'f) continuation list,\n                      ('s,'f) xstate,('s,'f) xstate] \\<Rightarrow> bool\"\n                   (\"_\\<turnstile> \\<langle>_,_,_\\<rangle> \\<Rightarrow> _\" [50,50,50,50,50] 50)\n  for \\<Gamma>:: \"('s,'p,'f) body\"\nwhere\n  Nil: \"\\<Gamma>\\<turnstile>\\<langle>[],[],s\\<rangle> \\<Rightarrow> s\"\n\n| ExitBlockNormal: \"\\<Gamma>\\<turnstile>\\<langle>nrms,css,Normal s\\<rangle> \\<Rightarrow> t\n                    \\<Longrightarrow>\n                    \\<Gamma>\\<turnstile>\\<langle>[],(nrms,abrs)#css,Normal s\\<rangle> \\<Rightarrow> t\"\n\n| ExitBlockAbrupt: \"\\<Gamma>\\<turnstile>\\<langle>abrs,css,Normal s\\<rangle> \\<Rightarrow> t\n                    \\<Longrightarrow>\n                    \\<Gamma>\\<turnstile>\\<langle>[],(nrms,abrs)#css,Abrupt s\\<rangle> \\<Rightarrow> t\"\n\n| ExitBlockFault: \"\\<Gamma>\\<turnstile>\\<langle>nrms,css,Fault f\\<rangle> \\<Rightarrow> t\n                    \\<Longrightarrow>\n                    \\<Gamma>\\<turnstile>\\<langle>[],(nrms,abrs)#css,Fault f\\<rangle> \\<Rightarrow> t\"\n\n| ExitBlockStuck: \"\\<Gamma>\\<turnstile>\\<langle>nrms,css,Stuck\\<rangle> \\<Rightarrow> t\n                    \\<Longrightarrow>\n                    \\<Gamma>\\<turnstile>\\<langle>[],(nrms,abrs)#css,Stuck\\<rangle> \\<Rightarrow> t\"\n\n| Cons: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t; \\<Gamma>\\<turnstile>\\<langle>cs,css,t\\<rangle> \\<Rightarrow> u\\<rbrakk> \n         \\<Longrightarrow> \n         \\<Gamma>\\<turnstile>\\<langle>c#cs,css,s\\<rangle> \\<Rightarrow> u\"\n\n\ninductive_cases execs_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>\\<langle>[],css,s\\<rangle> \\<Rightarrow> t\"\n \"\\<Gamma>\\<turnstile>\\<langle>c#cs,css,s\\<rangle> \\<Rightarrow> t\"\n\nML {*\n  ML_Thms.bind_thm (\"converse_rtrancl_induct3\", Split_Rule.split_rule @{context}\n    (Rule_Insts.read_instantiate @{context} [((\"a\", 0), \"(cs,css,s)\"), ((\"b\", 0), \"(cs',css',t)\")] []\n      @{thm converse_rtranclp_induct}));\n*}\n\nlemma execs_Fault_end: \n  assumes execs: \"\\<Gamma>\\<turnstile>\\<langle>cs,css,s\\<rangle> \\<Rightarrow> t\" shows \"s=Fault f\\<Longrightarrow> t=Fault f\"\n  using execs\n  by (induct) (auto dest: Fault_end)\n\nlemma execs_Stuck_end: \n  assumes execs: \"\\<Gamma>\\<turnstile>\\<langle>cs,css,s\\<rangle> \\<Rightarrow> t\" shows \"s=Stuck \\<Longrightarrow> t=Stuck\"\n  using execs\n  by (induct) (auto dest: Stuck_end)\n\n\ntheorem steps_impl_execs: \n  assumes steps: \"\\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow>\\<^sup>* ([],[],t)\" \n  shows \"\\<Gamma>\\<turnstile>\\<langle>cs,css,s\\<rangle> \\<Rightarrow> t\"\nusing steps\nproof (induct rule: converse_rtrancl_induct3 [consumes 1])\n  show \"\\<Gamma>\\<turnstile>\\<langle>[],[],t\\<rangle> \\<Rightarrow> t\" by (rule execs.Nil)\nnext\n  fix cs css s cs' css' w\n  assume step: \"\\<Gamma>\\<turnstile>(cs,css, s) \\<rightarrow> (cs',css', w)\" \n  assume execs: \"\\<Gamma>\\<turnstile>\\<langle>cs',css',w\\<rangle> \\<Rightarrow> t\"\n  from step \n  show \"\\<Gamma>\\<turnstile>\\<langle>cs,css,s\\<rangle> \\<Rightarrow> t\"\n  proof (cases)\n    case (Catch c1 c2 cs s)\n    with execs obtain t' where\n      exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> t'\" and\n      execs_rest: \"\\<Gamma>\\<turnstile>\\<langle>[],(cs, c2 # cs) # css,t'\\<rangle> \\<Rightarrow> t\"\n      by (clarsimp elim!: execs_elim_cases)\n    have  \"\\<Gamma>\\<turnstile>\\<langle>Catch c1 c2 # cs,css,Normal s\\<rangle> \\<Rightarrow> t\"\n    proof (cases t')\n      case (Normal t'')\n      with exec_c1 have \"\\<Gamma>\\<turnstile>\\<langle>Catch c1 c2,Normal s\\<rangle> \\<Rightarrow> t'\"\n        by (auto intro: exec.CatchMiss)\n      moreover\n      from execs_rest Normal have \"\\<Gamma>\\<turnstile>\\<langle>cs,css,t'\\<rangle> \\<Rightarrow> t\"\n        by (cases) auto\n      ultimately show ?thesis\n        by (rule execs.Cons)\n    next\n      case (Abrupt t'')\n      from execs_rest Abrupt have \"\\<Gamma>\\<turnstile>\\<langle>c2#cs,css,Normal t''\\<rangle> \\<Rightarrow> t\"\n        by (cases) auto\n      then obtain v where\n          exec_c2: \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal t''\\<rangle> \\<Rightarrow> v\" and\n          rest: \"\\<Gamma>\\<turnstile>\\<langle>cs,css,v\\<rangle> \\<Rightarrow> t\"\n        by cases\n      from exec_c1 Abrupt exec_c2\n      have \"\\<Gamma>\\<turnstile>\\<langle>Catch c1 c2,Normal s\\<rangle> \\<Rightarrow> v\"\n        by  - (rule exec.CatchMatch, auto)\n      from this rest\n      show ?thesis\n        by (rule execs.Cons)\n    next\n      case (Fault f)\n      with exec_c1 have \"\\<Gamma>\\<turnstile>\\<langle>Catch c1 c2,Normal s\\<rangle> \\<Rightarrow> Fault f\"\n        by (auto intro: exec.intros)\n      moreover from execs_rest Fault have \"\\<Gamma>\\<turnstile>\\<langle>cs,css,Fault f\\<rangle> \\<Rightarrow> t\"\n        by (cases) auto\n      ultimately show ?thesis\n        by (rule execs.Cons)\n    next\n      case Stuck\n      with exec_c1 have \"\\<Gamma>\\<turnstile>\\<langle>Catch c1 c2,Normal s\\<rangle> \\<Rightarrow> Stuck\"\n        by (auto intro: exec.intros)\n      moreover from execs_rest Stuck have \"\\<Gamma>\\<turnstile>\\<langle>cs,css,Stuck\\<rangle> \\<Rightarrow> t\"\n        by (cases) auto\n      ultimately show ?thesis\n        by (rule execs.Cons)\n    qed\n    with Catch show ?thesis by simp\n  next\n    case (Call p bdy cs s)\n    have bdy: \"\\<Gamma> p = Some bdy\" by fact\n    from Call execs obtain t' where\n      exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal s\\<rangle> \\<Rightarrow> t'\" and\n      execs_rest: \n            \"\\<Gamma>\\<turnstile>\\<langle>[],(cs,Throw#cs)#css ,t'\\<rangle> \\<Rightarrow> t\"\n       by (clarsimp elim!: execs_elim_cases)\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call p # cs,css,Normal s\\<rangle> \\<Rightarrow> t\"\n    proof (cases t')\n      case (Normal t'')\n      with exec_body bdy\n      have \"\\<Gamma>\\<turnstile>\\<langle>Call p ,Normal s\\<rangle> \\<Rightarrow> Normal t''\" \n        by (auto intro: exec.intros)\n      moreover\n      from execs_rest Normal\n      have \"\\<Gamma>\\<turnstile>\\<langle>cs,css ,Normal t''\\<rangle> \\<Rightarrow> t\" \n        by cases auto\n      ultimately show ?thesis by (rule execs.Cons)\n    next\n      case (Abrupt t'')\n      with exec_body bdy\n      have \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow> Abrupt t''\"\n        by (auto intro: exec.intros)\n      moreover\n      from execs_rest Abrupt have \n        \"\\<Gamma>\\<turnstile>\\<langle>Throw # cs,css,Normal t''\\<rangle> \\<Rightarrow> t\"\n        by (cases) auto\n      then obtain v where \n        \"\\<Gamma>\\<turnstile>\\<langle>Throw,Normal t''\\<rangle> \\<Rightarrow> v\" and \n        rest: \"\\<Gamma>\\<turnstile>\\<langle>cs,css,v\\<rangle> \\<Rightarrow> t\"\n        by (clarsimp elim!: execs_elim_cases)\n      moreover from this have \"v=Abrupt t''\"\n        by (auto elim: exec_Normal_elim_cases)\n      ultimately \n      show ?thesis by (auto intro: execs.Cons)\n    next\n      case (Fault f)\n      with exec_body bdy have \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow> Fault f\"\n        by (auto intro: exec.intros)\n      moreover from execs_rest Fault have \"\\<Gamma>\\<turnstile>\\<langle>cs,css,Fault f\\<rangle> \\<Rightarrow> t\"\n        by (cases) (auto elim: execs_elim_cases dest: Fault_end)\n      ultimately \n      show ?thesis by (rule execs.Cons)\n    next\n      case Stuck\n      with exec_body bdy have \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow> Stuck\"\n        by (auto intro: exec.intros)\n      moreover from execs_rest Stuck have \"\\<Gamma>\\<turnstile>\\<langle>cs,css,Stuck\\<rangle> \\<Rightarrow> t\"\n        by (cases) (auto elim: execs_elim_cases dest: Stuck_end)\n      ultimately \n      show ?thesis by (rule execs.Cons)\n    qed \n    with Call show ?thesis by simp\n  qed (insert execs,\n      (blast intro:execs.intros exec.intros elim!: execs_elim_cases)+)\nqed\n\ntheorem steps_impl_exec: \n  assumes steps: \"\\<Gamma>\\<turnstile>([c],[],s) \\<rightarrow>\\<^sup>* ([],[],t)\" \n  shows \"\\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t\"\nusing steps_impl_execs [OF steps]\nby (blast elim: execs_elim_cases)\n\ncorollary steps_eq_exec: \"\\<Gamma>\\<turnstile>([c],[],s) \\<rightarrow>\\<^sup>* ([],[],t) = \\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t\"\n  by (blast intro: steps_impl_exec exec_impl_steps)\n\n\nsubsection {* Infinite Computations: @{text \"inf \\<Gamma> cs css s\"}*}\n\ndefinition inf :: \n \"[('s,'p,'f) body,('s,'p,'f) com list,('s,'p,'f) continuation list,('s,'f) xstate]\n  \\<Rightarrow> bool\"\nwhere \"inf \\<Gamma> cs css s = (\\<exists>f. f 0 = (cs,css,s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f(Suc i)))\"\n\nlemma not_infI: \"\\<lbrakk>\\<And>f. \\<lbrakk>f 0 = (cs,css,s); \\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\\<rbrakk> \\<Longrightarrow> False\\<rbrakk>  \n                \\<Longrightarrow> \\<not>inf \\<Gamma> cs css s\"\n  by (auto simp add: inf_def)\n\nsubsection {* Equivalence of Termination and Absence of Infinite Computations *}\n\n\ninductive \"terminatess\":: \"[('s,'p,'f) body,('s,'p,'f) com list,\n                            ('s,'p,'f) continuation list,('s,'f) xstate] \\<Rightarrow> bool\" \n                (\"_\\<turnstile>_,_ \\<Down> _\" [60,20,60] 89)\n  for  \\<Gamma>::\"('s,'p,'f) body\"\nwhere\n   Nil: \"\\<Gamma>\\<turnstile>[],[]\\<Down>s\"\n\n|  ExitBlockNormal: \"\\<Gamma>\\<turnstile>nrms,css\\<Down>Normal s\n                     \\<Longrightarrow> \n                     \\<Gamma>\\<turnstile>[],(nrms,abrs)#css\\<Down>Normal s\"\n\n|  ExitBlockAbrupt: \"\\<Gamma>\\<turnstile>abrs,css\\<Down>Normal s\n                     \\<Longrightarrow> \n                     \\<Gamma>\\<turnstile>[],(nrms,abrs)#css\\<Down>Abrupt s\"\n\n|  ExitBlockFault: \"\\<Gamma>\\<turnstile>nrms,css\\<Down>Fault f\n                    \\<Longrightarrow> \n                    \\<Gamma>\\<turnstile>[],(nrms,abrs)#css\\<Down>Fault f\"\n\n|  ExitBlockStuck: \"\\<Gamma>\\<turnstile>nrms,css\\<Down>Stuck\n                    \\<Longrightarrow> \n                    \\<Gamma>\\<turnstile>[],(nrms,abrs)#css\\<Down>Stuck\"\n\n\n|  Cons: \"\\<lbrakk>\\<Gamma>\\<turnstile>c\\<down>s; (\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t \\<longrightarrow> \\<Gamma>\\<turnstile>cs,css\\<Down>t)\\<rbrakk>\n          \\<Longrightarrow> \n          \\<Gamma>\\<turnstile>c#cs,css\\<Down>s\"\n \ninductive_cases terminatess_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>[],css\\<Down>t\"\n \"\\<Gamma>\\<turnstile>c#cs,css\\<Down>t\"\n\nlemma terminatess_Fault: \"\\<And>cs. \\<Gamma>\\<turnstile>cs,css\\<Down>Fault f\"\nproof (induct css)\n  case Nil\n  show \"\\<Gamma>\\<turnstile>cs,[]\\<Down>Fault f\"\n  proof (induct cs)\n    case Nil show \"\\<Gamma>\\<turnstile>[],[]\\<Down>Fault f\" by (rule terminatess.Nil)\n  next\n    case (Cons c cs)\n    thus ?case\n      by (auto intro: terminatess.intros terminates.intros dest: Fault_end)\n  qed\nnext\n  case (Cons d css)\n  have hyp: \"\\<And>cs. \\<Gamma>\\<turnstile>cs,css\\<Down>Fault f\" by fact\n  obtain nrms abrs where d: \"d=(nrms,abrs)\"  by (cases d) auto\n  have \"\\<Gamma>\\<turnstile>cs,(nrms,abrs)#css\\<Down>Fault f\"\n  proof (induct cs)\n    case Nil\n    show \"\\<Gamma>\\<turnstile>[],(nrms, abrs) # css\\<Down>Fault f\"\n      by (rule terminatess.ExitBlockFault) (rule hyp)\n  next\n    case (Cons c cs)\n    have hyp1: \"\\<Gamma>\\<turnstile>cs,(nrms, abrs) # css\\<Down>Fault f\" by fact\n    show \"\\<Gamma>\\<turnstile>c#cs,(nrms, abrs)#css\\<Down>Fault f\"\n      by (auto intro: hyp1 terminatess.Cons terminates.intros dest: Fault_end)\n  qed\n  with d show ?case by simp\nqed\n\nlemma terminatess_Stuck: \"\\<And>cs. \\<Gamma>\\<turnstile>cs,css\\<Down>Stuck\"\nproof (induct css)\n  case Nil\n  show \"\\<Gamma>\\<turnstile>cs,[]\\<Down>Stuck\"\n  proof (induct cs)\n    case Nil show \"\\<Gamma>\\<turnstile>[],[]\\<Down>Stuck\" by (rule terminatess.Nil)\n  next\n    case (Cons c cs)\n    thus ?case\n      by (auto intro: terminatess.intros terminates.intros dest: Stuck_end)\n  qed\nnext\n  case (Cons d css)\n  have hyp: \"\\<And>cs. \\<Gamma>\\<turnstile>cs,css\\<Down>Stuck\" by fact\n  obtain nrms abrs where d: \"d=(nrms,abrs)\" by (cases d) auto\n  have \"\\<Gamma>\\<turnstile>cs,(nrms,abrs)#css\\<Down>Stuck\"\n  proof (induct cs)\n    case Nil\n    show \"\\<Gamma>\\<turnstile>[],(nrms, abrs) # css\\<Down>Stuck\"\n      by (rule terminatess.ExitBlockStuck) (rule hyp)\n  next\n    case (Cons c cs)\n    have hyp1: \"\\<Gamma>\\<turnstile>cs,(nrms, abrs) # css\\<Down>Stuck\" by fact\n    show \"\\<Gamma>\\<turnstile>c#cs,(nrms, abrs)#css\\<Down>Stuck\"\n      by (auto intro: hyp1 terminatess.Cons terminates.intros dest: Stuck_end)\n  qed\n  with d show ?case by simp\nqed\n\n\nlemma Basic_terminates: \"\\<Gamma>\\<turnstile>Basic f \\<down> t\"\n  by (cases t) (auto intro: terminates.intros)\n\nlemma step_preserves_terminations: \n  assumes step: \"\\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow> (cs',css',t)\" \n  shows \"\\<Gamma>\\<turnstile>cs,css\\<Down>s \\<Longrightarrow> \\<Gamma>\\<turnstile>cs',css'\\<Down>t\"\nusing step\nproof (induct)\n  case Skip thus ?case\n    by (auto elim: terminates_Normal_elim_cases terminatess_elim_cases\n             intro: exec.intros)\nnext\n  case Guard thus ?case \n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n             intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case GuardFault thus ?case\n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case FaultProp show ?case by (rule terminatess_Fault)\nnext\n  case FaultPropBlock show ?case by (rule terminatess_Fault)\nnext\n  case AbruptProp thus ?case\n    by (blast elim: terminatess_elim_cases \n              intro: terminatess.intros)\nnext\n  case ExitBlockNormal thus ?case\n    by (blast elim: terminatess_elim_cases\n              intro: terminatess.intros )\nnext\n  case ExitBlockAbrupt thus ?case\n    by (blast elim: terminatess_elim_cases\n              intro: terminatess.intros )\nnext\n  case Basic thus ?case \n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case Spec thus ?case \n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case SpecStuck thus ?case \n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case Seq thus ?case \n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case CondTrue thus ?case \n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case CondFalse thus ?case \n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case WhileTrue thus ?case\n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case WhileFalse thus ?case\n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case (Call p bdy cs css s)\n  have bdy: \"\\<Gamma> p = Some bdy\" by fact\n  from Call obtain \n    term_body: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal s\" and\n    term_rest: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow> t \\<longrightarrow> \\<Gamma>\\<turnstile>cs,css\\<Down>t\"\n    by (fastforce elim!: terminatess_elim_cases terminates_Normal_elim_cases)\n  show \"\\<Gamma>\\<turnstile>[bdy],(cs,Throw # cs)#css\\<Down>Normal s\"\n  proof (rule terminatess.Cons [OF term_body],clarsimp)\n    fix t\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal s\\<rangle> \\<Rightarrow> t\"\n    show \"\\<Gamma>\\<turnstile>[],(cs,Throw # cs) # css\\<Down>t\"\n    proof (cases t)\n      case (Normal t')\n      with exec_body bdy\n      have \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow> Normal t'\"\n        by (auto intro: exec.intros)\n      with term_rest have \"\\<Gamma>\\<turnstile>cs,css\\<Down>Normal t'\"\n        by iprover\n      with Normal show ?thesis\n        by (auto intro: terminatess.intros terminates.intros\n                 elim: exec_Normal_elim_cases)\n    next\n      case (Abrupt t')\n      with exec_body bdy\n      have \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow> Abrupt t'\"\n        by (auto intro: exec.intros)\n      with term_rest have \"\\<Gamma>\\<turnstile>cs,css\\<Down>Abrupt t'\"\n        by iprover\n      with Abrupt show ?thesis\n        by (fastforce intro: terminatess.intros terminates.intros\n                     elim: exec_Normal_elim_cases)\n    next\n      case Fault\n      thus ?thesis\n        by (iprover intro: terminatess_Fault)\n    next\n      case Stuck\n      thus ?thesis\n        by (iprover intro: terminatess_Stuck)\n    qed\n  qed\nnext\n  case CallUndefined thus ?case\n    by (iprover intro: terminatess_Stuck)\nnext\n  case StuckProp show ?case by (rule terminatess_Stuck)\nnext\n  case StuckPropBlock show ?case by (rule terminatess_Stuck)\nnext\n  case DynCom thus ?case\n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case Throw thus ?case\n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case (Catch c1 c2 cs css s) \n  then obtain \n    term_c1: \"\\<Gamma>\\<turnstile>c1 \\<down> Normal s\" and\n    term_c2: \"\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> Abrupt s' \\<longrightarrow> \\<Gamma>\\<turnstile>c2 \\<down> Normal s'\"and\n    term_rest: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>Catch c1 c2,Normal s\\<rangle> \\<Rightarrow> t \\<longrightarrow> \\<Gamma>\\<turnstile>cs,css\\<Down>t\"\n    by (clarsimp elim!: terminatess_elim_cases terminates_Normal_elim_cases)\n  show \"\\<Gamma>\\<turnstile>[c1],(cs, c2 # cs) # css\\<Down>Normal s\"\n  proof (rule terminatess.Cons [OF term_c1],clarsimp)\n    fix t\n    assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> t\" \n    show \"\\<Gamma>\\<turnstile>[],(cs, c2 # cs) # css\\<Down>t\"\n    proof (cases t)\n      case (Normal t')\n      with exec_c1 have \"\\<Gamma>\\<turnstile>\\<langle>Catch c1 c2,Normal s\\<rangle> \\<Rightarrow> t\" \n        by (auto intro: exec.intros)\n      with term_rest have \"\\<Gamma>\\<turnstile>cs,css\\<Down>t\"\n        by iprover\n      with Normal show ?thesis\n        by (iprover intro: terminatess.intros)\n    next\n      case (Abrupt t')\n      with exec_c1 term_c2 have \"\\<Gamma>\\<turnstile>c2 \\<down> Normal t'\"\n        by auto\n      moreover\n      {\n        fix w\n        assume exec_c2: \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal t'\\<rangle> \\<Rightarrow> w\" \n        have \"\\<Gamma>\\<turnstile>cs,css\\<Down>w\" \n        proof -\n          from exec_c1 Abrupt exec_c2\n          have \"\\<Gamma>\\<turnstile>\\<langle>Catch c1 c2,Normal s\\<rangle> \\<Rightarrow> w\"\n            by (auto intro: exec.intros)\n          with term_rest show ?thesis by simp\n        qed\n      }\n      ultimately\n      show ?thesis using Abrupt\n        by (auto intro: terminatess.intros)\n    next\n      case Fault thus ?thesis\n        by (iprover intro: terminatess_Fault)\n    next\n      case Stuck thus ?thesis\n        by (iprover intro: terminatess_Stuck)\n    qed\n  qed\nqed\n\n\nML {*\n  ML_Thms.bind_thm (\"rtrancl_induct3\", Split_Rule.split_rule @{context}\n    (Rule_Insts.read_instantiate @{context} [((\"a\", 0), \"(ax,ay,az)\"), ((\"b\", 0), \"(bx,by,bz)\")] []\n     @{thm rtranclp_induct}));\n*}\n\nlemma steps_preserves_terminations: \n  assumes steps: \"\\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow>\\<^sup>* (cs',css',t)\" \n  shows \"\\<Gamma>\\<turnstile>cs,css\\<Down>s \\<Longrightarrow> \\<Gamma>\\<turnstile>cs',css'\\<Down>t\"\nusing steps\nproof (induct rule: rtrancl_induct3 [consumes 1])\n  assume  \"\\<Gamma>\\<turnstile>cs,css\\<Down>s\" then show \"\\<Gamma>\\<turnstile>cs,css\\<Down>s\". \nnext\n  fix cs'' css'' w cs' css' t\n  assume \"\\<Gamma>\\<turnstile>(cs'',css'', w) \\<rightarrow> (cs',css', t)\" \"\\<Gamma>\\<turnstile>cs,css\\<Down>s \\<Longrightarrow> \\<Gamma>\\<turnstile>cs'',css''\\<Down>w\"\n         \"\\<Gamma>\\<turnstile>cs,css\\<Down>s\"\n  then show \"\\<Gamma>\\<turnstile>cs',css'\\<Down>t\"\n    by (blast dest: step_preserves_terminations)\nqed\n\ntheorem steps_preserves_termination: \n  assumes steps: \"\\<Gamma>\\<turnstile>([c],[],s) \\<rightarrow>\\<^sup>* (c'#cs',css',t)\" \n  assumes term_c: \"\\<Gamma>\\<turnstile>c\\<down>s\" \n  shows \"\\<Gamma>\\<turnstile>c'\\<down>t\"\nproof -\n  from term_c have \"\\<Gamma>\\<turnstile>[c],[]\\<Down>s\"\n    by (auto intro: terminatess.intros)\n  from steps this\n  have \"\\<Gamma>\\<turnstile>c'#cs',css'\\<Down>t\"\n    by (rule steps_preserves_terminations)\n  thus \"\\<Gamma>\\<turnstile>c'\\<down>t\"\n    by (auto elim: terminatess_elim_cases)\nqed\n\n\n\n\n\nlemma renumber':\n  assumes f: \"\\<forall>i. (a,f i) \\<in> r\\<^sup>* \\<and> (f i,f(Suc i)) \\<in> r\" \n  assumes a_b: \"(a,b) \\<in> r\\<^sup>*\" \n  shows \"b = f 0 \\<Longrightarrow> (\\<exists>f. f 0 = a \\<and> (\\<forall>i. (f i, f(Suc i)) \\<in> r))\"\nusing a_b\nproof (induct rule: converse_rtrancl_induct [consumes 1])\n  assume \"b = f 0\"\n  with f show \"\\<exists>f. f 0 = b \\<and> (\\<forall>i. (f i, f (Suc i)) \\<in> r)\"\n    by blast\nnext\n  fix a z\n  assume a_z: \"(a, z) \\<in> r\" and \"(z, b) \\<in> r\\<^sup>*\" \n  assume \"b = f 0 \\<Longrightarrow> \\<exists>f. f 0 = z \\<and> (\\<forall>i. (f i, f (Suc i)) \\<in> r)\"\n         \"b = f 0\"\n  then obtain f where f0: \"f 0 = z\" and seq: \"\\<forall>i. (f i, f (Suc i)) \\<in> r\"\n    by iprover\n  {\n    fix i have \"((\\<lambda>i. case i of 0 \\<Rightarrow> a | Suc i \\<Rightarrow> f i) i, f i) \\<in> r\"\n      using seq a_z f0\n      by (cases i) auto\n  }\n  then\n  show \"\\<exists>f. f 0 = a \\<and> (\\<forall>i. (f i, f (Suc i)) \\<in> r)\"\n    by - (rule exI [where x=\"\\<lambda>i. case i of 0 \\<Rightarrow> a | Suc i \\<Rightarrow> f i\"],simp)\nqed\n\nlemma renumber:\n \"\\<forall>i. (a,f i) \\<in> r\\<^sup>* \\<and> (f i,f(Suc i)) \\<in> r \n \\<Longrightarrow> \\<exists>f. f 0 = a \\<and> (\\<forall>i. (f i, f(Suc i)) \\<in> r)\"\n  by(blast dest:renumber')\n\nlemma not_inf_Fault': \n  assumes enum_step: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n  shows \"\\<And>k cs. f k = (cs,css,Fault m) \\<Longrightarrow> False\"\nproof (induct css)\n  case Nil\n  have f_k: \"f k = (cs,[],Fault m)\" by fact\n  have \"\\<And>k. f k = (cs,[],Fault m) \\<Longrightarrow> False\"\n  proof (induct cs)\n    case Nil \n    have \"f k = ([], [], Fault m)\" by fact\n    moreover\n    from enum_step have \"\\<Gamma>\\<turnstile>f k \\<rightarrow> f (Suc k)\"..\n    ultimately show \"False\"\n      by (fastforce elim: step_elim_cases)\n  next\n    case (Cons c cs)\n    have fk: \"f k = (c # cs, [], Fault m)\" by fact\n    from enum_step have \"\\<Gamma>\\<turnstile>f k \\<rightarrow> f (Suc k)\"..\n    with fk have \"f (Suc k) = (cs,[],Fault m)\"\n      by (fastforce elim: step_elim_cases)\n    with enum_step Cons.hyps\n    show False\n      by blast\n  qed\n  from this f_k show False by blast\nnext\n  case (Cons ds css)\n  then obtain nrms abrs where ds: \"ds=(nrms,abrs)\" by (cases ds) auto\n  have hyp: \"\\<And>k cs. f k = (cs,css,Fault m) \\<Longrightarrow> False\" by fact\n  have \"\\<And>k. f k = (cs,(nrms,abrs)#css,Fault m) \\<Longrightarrow> False\"\n  proof (induct cs)\n    case Nil\n    have fk: \"f k = ([], (nrms, abrs) # css, Fault m)\" by fact\n    from enum_step have \"\\<Gamma>\\<turnstile>f k \\<rightarrow> f (Suc k)\"..\n    with fk have \"f (Suc k) = (nrms,css,Fault m)\"\n      by (fastforce elim: step_elim_cases)\n    thus ?case\n      by (rule hyp)\n  next\n    case (Cons c cs)\n    have fk: \"f k = (c#cs, (nrms, abrs) # css, Fault m)\" by fact\n    have hyp1: \"\\<And>k. f k = (cs, (nrms, abrs) # css, Fault m) \\<Longrightarrow> False\" by fact\n    from enum_step have \"\\<Gamma>\\<turnstile>f k \\<rightarrow> f (Suc k)\"..\n    with fk have \"f (Suc k) = (cs,(nrms,abrs)#css,Fault m)\"\n      by (fastforce elim: step_elim_cases)\n    thus ?case\n      by (rule hyp1)\n  qed\n  with ds Cons.prems show False by auto\nqed\n\nlemma not_inf_Fault:\n  \"\\<not> inf \\<Gamma> cs css (Fault m)\"\napply (rule not_infI)\napply (rule_tac f=f in not_inf_Fault' )\nby auto\n\nlemma not_inf_Stuck': \n  assumes enum_step: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n  shows \"\\<And>k cs. f k = (cs,css,Stuck) \\<Longrightarrow> False\"\nproof (induct css)\n  case Nil\n  have f_k: \"f k = (cs,[],Stuck)\" by fact\n  have \"\\<And>k. f k = (cs,[],Stuck) \\<Longrightarrow> False\"\n  proof (induct cs)\n    case Nil \n    have \"f k = ([], [], Stuck)\" by fact\n    moreover\n    from enum_step have \"\\<Gamma>\\<turnstile>f k \\<rightarrow> f (Suc k)\"..\n    ultimately show \"False\"\n      by (fastforce elim: step_elim_cases)\n  next\n    case (Cons c cs)\n    have fk: \"f k = (c # cs, [], Stuck)\" by fact\n    from enum_step have \"\\<Gamma>\\<turnstile>f k \\<rightarrow> f (Suc k)\"..\n    with fk have \"f (Suc k) = (cs,[],Stuck)\"\n      by (fastforce elim: step_elim_cases)\n    with enum_step Cons.hyps\n    show False\n      by blast\n  qed\n  from this f_k show False .\nnext\n  case (Cons ds css)\n  then obtain nrms abrs where ds: \"ds=(nrms,abrs)\" by (cases ds) auto\n  have hyp: \"\\<And>k cs. f k = (cs,css,Stuck) \\<Longrightarrow> False\" by fact\n  have \"\\<And>k. f k = (cs,(nrms,abrs)#css,Stuck) \\<Longrightarrow> False\"\n  proof (induct cs)\n    case Nil\n    have fk: \"f k = ([], (nrms, abrs) # css, Stuck)\" by fact\n    from enum_step have \"\\<Gamma>\\<turnstile>f k \\<rightarrow> f (Suc k)\"..\n    with fk have \"f (Suc k) = (nrms,css,Stuck)\"\n      by (fastforce elim: step_elim_cases)\n    thus ?case\n      by (rule hyp)\n  next\n    case (Cons c cs)\n    have fk: \"f k = (c#cs, (nrms, abrs) # css, Stuck)\" by fact\n    have hyp1: \"\\<And>k. f k = (cs, (nrms, abrs) # css, Stuck) \\<Longrightarrow> False\" by fact\n    from enum_step have \"\\<Gamma>\\<turnstile>f k \\<rightarrow> f (Suc k)\"..\n    with fk have \"f (Suc k) = (cs,(nrms,abrs)#css,Stuck)\"\n      by (fastforce elim: step_elim_cases)\n    thus ?case\n      by (rule hyp1)\n  qed\n  with ds Cons.prems show False by auto\nqed\n\nlemma not_inf_Stuck:\n  \"\\<not> inf \\<Gamma> cs css Stuck\"\napply (rule not_infI)\napply (rule_tac f=f in not_inf_Stuck')\nby auto\n\nlemma last_butlast_app: \nassumes butlast: \"butlast as = xs @ butlast bs\"\nassumes not_Nil: \"bs \\<noteq> []\" \"as \\<noteq> []\"\nassumes last: \"fst (last as) = fst (last bs)\" \"snd (last as) = snd (last bs)\"\nshows \"as = xs @ bs\"\nproof -\n  from last have \"last as = last bs\"\n    by (cases \"last as\",cases \"last bs\") simp\n  moreover\n  from not_Nil have \"as = butlast as @ [last as]\" \"bs = butlast bs @ [last bs]\"\n    by auto\n  ultimately show ?thesis\n    using butlast\n    by simp\nqed\n\n\nlemma last_butlast_tl:\nassumes butlast: \"butlast bs = x # butlast as\" \nassumes not_Nil: \"bs \\<noteq> []\" \"as \\<noteq> []\" \nassumes last: \"fst (last as) = fst (last bs)\" \"snd (last as) = snd (last bs)\"\nshows \"as = tl bs\"\nproof -\n  from last have \"last as = last bs\"\n    by (cases \"last as\",cases \"last bs\") simp\n  moreover\n  from not_Nil have \"as = butlast as @ [last as]\" \"bs = butlast bs @ [last bs]\"\n    by auto\n  ultimately show ?thesis\n    using butlast\n    by simp\nqed\n\nlocale inf =\nfixes CS:: \"('s,'p,'f) config \\<Rightarrow> ('s, 'p,'f) com list\"\n  and CSS:: \"('s,'p,'f) config \\<Rightarrow> ('s, 'p,'f) continuation list\"  \n  and S:: \"('s,'p,'f) config \\<Rightarrow> ('s,'f) xstate\"  \n  defines CS_def : \"CS \\<equiv> fst\"\n  defines CSS_def : \"CSS \\<equiv> \\<lambda>c. fst (snd c)\"\n  defines S_def: \"S \\<equiv> \\<lambda>c. snd (snd c)\"\n\nlemma (in inf) steps_hd_drop_suffix:\nassumes f_0: \"f 0 = (c#cs,css,s)\"\nassumes f_step: \"\\<forall>i. \\<Gamma>\\<turnstile> f(i) \\<rightarrow> f(Suc i)\"  \nassumes not_finished: \"\\<forall>i < k. \\<not> (CS (f i) = cs \\<and> CSS (f i) = css)\"\nassumes simul: \"\\<forall>i\\<le>k.\n        (if pcss i = [] then CSS (f i)=css \\<and> CS (f i)=pcs i@cs \n                 else CS (f i)=pcs i \\<and> \n                      CSS (f i)= butlast (pcss i)@\n                              [(fst (last (pcss i))@cs,(snd (last (pcss i)))@cs)]@\n                              css)\"\ndefines \"p\\<equiv>\\<lambda>i. (pcs i, pcss i, S (f i))\"\nshows \"\\<forall>i<k. \\<Gamma>\\<turnstile> p i \\<rightarrow> p (Suc i)\"\nusing not_finished simul\nproof (induct k)\n  case 0\n  thus ?case by simp\nnext\n  case (Suc k)\n  have simul: \"\\<forall>i\\<le>Suc k.\n        (if pcss i = [] then CSS (f i)=css \\<and> CS (f i)=pcs i@cs \n                 else CS (f i)=pcs i \\<and> \n                      CSS (f i)= butlast (pcss i)@\n                              [(fst (last (pcss i))@cs,(snd (last (pcss i)))@cs)]@\n                              css)\" by fact\n  have not_finished': \"\\<forall>i < Suc k. \\<not> (CS (f i) = cs \\<and> CSS (f i) = css)\" by fact\n  with simul \n  have not_finished: \"\\<forall>i<Suc k. \\<not> (pcs i = [] \\<and> pcss i = [])\"\n    by (auto simp add: CS_def CSS_def S_def split: split_if_asm)\n  show ?case\n  proof (clarify)\n    fix i\n    assume i_le_Suc_k: \"i < Suc k\"\n    show \"\\<Gamma>\\<turnstile> p i \\<rightarrow> p (Suc i)\"\n    proof (cases \"i < k\")\n      case True\n      with not_finished' simul Suc.hyps\n      show ?thesis\n        by auto\n    next\n      case False\n      with i_le_Suc_k\n      have eq_i_k: \"i=k\"\n        by simp\n      show \"\\<Gamma>\\<turnstile>p i \\<rightarrow> p (Suc i)\"\n      proof -\n        obtain cs' css' t' where \n          f_Suc_i: \"f (Suc i) = (cs', css', t')\"\n          by (cases \"f (Suc i)\")\n        obtain cs'' css'' t'' where \n          f_i: \"f i = (cs'',css'',t'')\"\n          by (cases \"f i\")\n        from not_finished eq_i_k \n        have pcs_pcss_not_Nil: \"\\<not> (pcs i = [] \\<and> pcss i = [])\"\n          by auto\n        from simul [rule_format, of i] i_le_Suc_k f_i\n        have pcs_pcss_i:\n          \"if pcss i = [] then css''=css \\<and> cs''=pcs i@cs \n           else cs''=pcs i \\<and> \n           css''= butlast (pcss i)@\n                       [(fst (last (pcss i))@cs,(snd (last (pcss i)))@cs)]@\n                       css\"\n          by (simp add: CS_def CSS_def S_def cong: if_cong)\n        from simul [rule_format, of \"Suc i\"] i_le_Suc_k f_Suc_i \n        have pcs_pcss_Suc_i: \n        \"if pcss (Suc i) = [] then css' = css \\<and> cs' = pcs (Suc i) @ cs\n         else cs' = pcs (Suc i) \\<and>\n              css' = butlast (pcss (Suc i)) @\n               [(fst (last (pcss (Suc i))) @ cs, snd (last (pcss (Suc i))) @ cs)] @ \n               css\"\n          by (simp add: CS_def CSS_def S_def cong: if_cong)\n        show ?thesis\n        proof (cases \"pcss i = []\")\n          case True\n          note pcss_Nil = this\n          with pcs_pcss_i pcs_pcss_not_Nil obtain p ps where\n            pcs_i: \"pcs i = p#ps\" and\n            css'': \"css''=css\" and \n            cs'': \"cs''=(p#ps)@cs\"\n            by (auto simp add: neq_Nil_conv)\n          with f_i have \"f i = (p#(ps@cs),css,t'')\"\n            by simp\n          with f_Suc_i f_step [rule_format, of i]\n          have step_css: \"\\<Gamma>\\<turnstile> (p#(ps@cs),css,t'') \\<rightarrow> (cs',css',t')\"\n            by simp\n          from step_Cons' [OF this, of p \"ps@cs\"]\n          obtain css''' where\n            css''': \"css' = css''' @ css\" \n            \"if css''' = [] then \\<exists>p. cs' = p @ ps @ cs\n            else (\\<exists>pnorm pabr. css'''=[(pnorm @ ps @ cs,pabr @ ps @ cs)])\"\n            by auto\n          show ?thesis\n          proof (cases \"css''' = []\")\n            case True\n            with css'''\n            obtain p' where \n              css': \"css' = css\" and\n              cs': \"cs' = p' @ ps @ cs\"\n              by auto\n                (*from cs' css' f_Suc_i f_i [rule_format, of \"Suc k\"]\n                have p_ps_not_Nil: \"p'@ps \\<noteq> Nil\"\n                by auto*)\n            from css' cs' step_css \n            have step: \"\\<Gamma>\\<turnstile> (p#(ps@cs),css,t'') \\<rightarrow> (p'@ps@cs,css,t')\"\n              by simp\n            hence \"\\<Gamma>\\<turnstile> ((p#ps)@cs,css,t'') \\<rightarrow> ((p'@ps)@cs,css,t')\"\n              by simp\n            from drop_suffix_css_step' [OF drop_suffix_same_css_step [OF this], \n              where xs=\"css\" and css=\"[]\" and css'=\"[]\"]\n            have  \"\\<Gamma>\\<turnstile> (p#ps,[],t'') \\<rightarrow> (p'@ps,[],t')\"\n              by simp \n            moreover \n            from css' cs' pcs_pcss_Suc_i\n            obtain \"pcs (Suc i) = p'@ps\" and \"pcss (Suc i) = []\"\n              by (simp split: split_if_asm)\n            ultimately show ?thesis\n              using pcs_i pcss_Nil f_i f_Suc_i\n              by (simp add: CS_def CSS_def S_def p_def)\n          next\n            case False\n            with css'''\n            obtain pnorm pabr where \n              css': \"css'=css'''@css\"\n              \"css'''=[(pnorm @ ps @ cs,pabr @ ps @ cs)]\"\n              by auto\n            with css''' step_css \n            have \"\\<Gamma>\\<turnstile> (p#ps@cs,css,t'') \\<rightarrow> (cs',[(pnorm@ps@cs,pabr@ps@cs)]@css,t')\"\n              by simp\n            then \n            have \"\\<Gamma>\\<turnstile>(p#ps, css, t'') \\<rightarrow> (cs', [(pnorm@ps, pabr@ps)] @ css, t')\" \n              by (rule drop_suffix_hd_css_step)\n            from drop_suffix_css_step' [OF this,\n              where css=\"[]\" and xs=\"css\" and css'=\"[(pnorm@ps, pabr@ps)]\"]\n            have \"\\<Gamma>\\<turnstile> (p#ps,[],t'') \\<rightarrow> (cs',[(pnorm@ps, pabr@ps)],t')\"\n              by simp\n            moreover\n            from css' pcs_pcss_Suc_i\n            obtain \"pcs (Suc i) = cs'\" \"pcss (Suc i) = [(pnorm@ps, pabr@ps)]\"\n              apply (cases \"pcss (Suc i)\")\n              apply (auto split: split_if_asm)\n              done\n            ultimately show ?thesis\n              using pcs_i pcss_Nil f_i f_Suc_i   \n              by (simp add: p_def CS_def CSS_def S_def)\n          qed\n        next\n          case False\n          note pcss_i_not_Nil = this\n          with pcs_pcss_i obtain\n            cs'': \"cs''=pcs i\" and  \n            css'': \"css''= butlast (pcss i)@\n                            [(fst (last (pcss i))@cs,(snd (last (pcss i)))@cs)]@\n                            css\"\n            by auto\n          from f_Suc_i f_i f_step [rule_format, of i]\n          have step_i_full: \"\\<Gamma>\\<turnstile> (cs'',css'',t'') \\<rightarrow> (cs',css',t')\"\n            by simp\n          show ?thesis\n          proof (cases cs'')\n            case (Cons c' cs)\n            with step_Cons' [OF step_i_full]\n            obtain css''' where css': \"css' = css'''@css''\"\n              by auto\n            with step_i_full \n            have \"\\<Gamma>\\<turnstile> (cs'',css'',t'') \\<rightarrow> (cs',css'''@css'',t')\"\n              by simp\n            from Cons_change_css_step [OF this, where xss=\"pcss i\"] Cons cs''\n            have \"\\<Gamma>\\<turnstile> (pcs i, pcss i,t'') \\<rightarrow> (cs',css'''@pcss i,t')\"\n              by simp\n            moreover\n            from cs'' css'' css' False pcs_pcss_Suc_i\n            obtain \"pcs (Suc i) = cs'\" \"pcss (Suc i) = css'''@pcss i\"\n              apply (auto  split: split_if_asm)\n              apply (drule (4) last_butlast_app)\n              by simp\n            ultimately show ?thesis\n              using f_i f_Suc_i\n              by (simp add: p_def CS_def CSS_def S_def)\n          next\n            case Nil\n            note cs''_Nil = this\n            show ?thesis\n            proof (cases \"butlast (pcss i)\")\n              case (Cons bpcs bpcss)\n              with cs''_Nil step_i_full css''\n              have \"\\<Gamma>\\<turnstile> ([],[hd css'']@tl css'',t'') \\<rightarrow> (cs',css',t')\"\n                by simp\n              moreover\n              from step_Nil [OF this]\n              have css': \"css'=tl css''\"\n                by simp\n              ultimately have \n                step_i_full: \"\\<Gamma>\\<turnstile> ([],[hd css'']@tl css'',t'') \\<rightarrow> (cs',tl css'',t')\"\n                by simp\n              from css'' Cons pcss_i_not_Nil\n              have \"hd css'' = hd (pcss i)\"\n                by (auto simp add: neq_Nil_conv split: split_if_asm)\n              with cs'' cs''_Nil\n                Nil_change_css_step [where ass=\"[hd css'']\" and\n                css=\"tl css''\" and ass'=\"[]\" and \n                xss=\"tl (pcss i)\", simplified, OF step_i_full [simplified]]\n              have \"\\<Gamma>\\<turnstile> (pcs i,[hd (pcss i)]@tl (pcss i),t'') \\<rightarrow> (cs',tl (pcss i),t')\"\n                by simp\n              with pcss_i_not_Nil \n              have \"\\<Gamma>\\<turnstile> (pcs i,pcss i,t'') \\<rightarrow> (cs',tl (pcss i),t')\"\n                by simp\n              moreover\n              from css' css'' cs''_Nil Cons pcss_i_not_Nil pcs_pcss_Suc_i\n              obtain \"pcs (Suc i) = cs'\" \"pcss (Suc i) = tl (pcss i)\" \n                apply (clarsimp  split: split_if_asm)\n                apply (drule (4) last_butlast_tl)\n                by simp\n              ultimately show ?thesis\n                using f_i f_Suc_i\n                by (simp add: p_def CS_def CSS_def S_def)\n            next\n              case Nil\n              with css'' pcss_i_not_Nil\n              obtain pnorm pabr\n                where css'': \"css''= [(pnorm@cs,pabr@cs)]@css\" and\n                pcss_i: \"pcss i = [(pnorm,pabr)]\"\n                by (force simp add: neq_Nil_conv split: split_if_asm)\n              with cs''_Nil step_i_full\n              have \"\\<Gamma>\\<turnstile>([],[(pnorm@cs,pabr@cs)]@css,t'') \\<rightarrow> (cs',css',t')\"\n                by simp\n              from step_Nil [OF this]\n              obtain \n                css': \"css'=css\" and\n                cs': \"(case t'' of\n                         Abrupt s' \\<Rightarrow> cs' = pabr @ cs \\<and> t' = Normal s'\n                       | _ \\<Rightarrow> cs' = pnorm @ cs \\<and> t' = t'')\"\n                by (simp cong: xstate.case_cong)\n              let \"?pcs_Suc_i \" = \"(case t'' of Abrupt s' \\<Rightarrow> pabr | _ \\<Rightarrow> pnorm)\"\n              from cs'\n              have \"\\<Gamma>\\<turnstile>([],[(pnorm,pabr)],t'') \\<rightarrow> (?pcs_Suc_i,[],t')\"\n                by (auto intro: step.intros split: xstate.splits)\n              moreover\n              from css'' css' cs' pcss_i pcs_pcss_Suc_i\n              obtain \"pcs (Suc i) = ?pcs_Suc_i\" \"pcss (Suc i) = []\"\n                by (simp split: split_if_asm xstate.splits)\n              ultimately\n              show ?thesis\n                using pcss_i cs'' cs''_Nil f_i f_Suc_i\n                by (simp add: p_def CS_def CSS_def S_def)\n            qed\n          qed\n        qed\n      qed\n    qed\n  qed\nqed\n\nlemma k_steps_to_rtrancl: \n  assumes steps: \"\\<forall>i<k. \\<Gamma>\\<turnstile> p i \\<rightarrow> p (Suc i)\"\n  shows \"\\<Gamma>\\<turnstile>p 0\\<rightarrow>\\<^sup>* p k\"\nusing steps\nproof (induct k)\n  case 0 thus ?case by auto\nnext\n  case (Suc k)\n  have \"\\<forall>i<Suc k. \\<Gamma>\\<turnstile> p i \\<rightarrow> p (Suc i)\" by fact\n  then obtain\n  step_le_k: \"\\<forall>i<k. \\<Gamma>\\<turnstile> p i \\<rightarrow> p (Suc i)\" and step_k: \"\\<Gamma>\\<turnstile> p k \\<rightarrow> p (Suc k)\"\n    by auto\n  from Suc.hyps [OF step_le_k]\n  have \"\\<Gamma>\\<turnstile> p 0 \\<rightarrow>\\<^sup>* p k\".\n  also note step_k\n  finally show ?case .\nqed\n\n    \n\nlemma (in inf) steps_hd_drop_suffix_finite:\nassumes f_0: \"f 0 = (c#cs,css,s)\"\nassumes f_step: \"\\<forall>i. \\<Gamma>\\<turnstile> f(i) \\<rightarrow> f(Suc i)\"  \nassumes not_finished: \"\\<forall>i < k. \\<not> (CS (f i) = cs \\<and> CSS (f i) = css)\"\nassumes simul: \"\\<forall>i\\<le>k.\n        (if pcss i = [] then CSS (f i)=css \\<and> CS (f i)=pcs i@cs \n                 else CS (f i)=pcs i \\<and> \n                      CSS (f i)= butlast (pcss i)@\n                              [(fst (last (pcss i))@cs,(snd (last (pcss i)))@cs)]@\n                              css)\"\nshows \"\\<Gamma>\\<turnstile>([c],[],s) \\<rightarrow>\\<^sup>* (pcs k, pcss k, S (f k))\"\nproof -\n  from steps_hd_drop_suffix [OF f_0 f_step not_finished simul]\n  have \"\\<forall>i<k. \\<Gamma>\\<turnstile> (pcs i, pcss i, S (f i)) \\<rightarrow> \n                  (pcs (Suc i), pcss (Suc i), S (f (Suc i)))\".\n  from k_steps_to_rtrancl [OF this]\n  have \"\\<Gamma>\\<turnstile> (pcs 0, pcss 0, S (f 0)) \\<rightarrow>\\<^sup>* (pcs k, pcss k, S (f k))\".\n  moreover from f_0 simul [rule_format, of 0]\n  have \"(pcs 0, pcss 0, S (f 0)) = ([c],[],s)\"\n    by (auto split: split_if_asm simp add: CS_def CSS_def S_def)\n  ultimately show ?thesis by simp\nqed\n\nlemma (in inf) steps_hd_drop_suffix_infinite:\nassumes f_0: \"f 0 = (c#cs,css,s)\"\nassumes f_step: \"\\<forall>i. \\<Gamma>\\<turnstile> f(i) \\<rightarrow> f(Suc i)\"  \nassumes not_finished: \"\\<forall>i. \\<not> (CS (f i) = cs \\<and> CSS (f i) = css)\"\n(*assumes not_finished: \"\\<forall>i. \\<not> (pcs i = [] \\<and> pcss i = [])\"*)\nassumes simul: \"\\<forall>i.\n        (if pcss i = [] then CSS (f i)=css \\<and> CS (f i)=pcs i@cs \n                 else CS (f i)=pcs i \\<and> \n                      CSS (f i)= butlast (pcss i)@\n                              [(fst (last (pcss i))@cs,(snd (last (pcss i)))@cs)]@\n                              css)\"\ndefines \"p\\<equiv>\\<lambda>i. (pcs i, pcss i, S (f i))\"\nshows \"\\<Gamma>\\<turnstile> p i \\<rightarrow> p (Suc i)\"\nproof -\n  from steps_hd_drop_suffix [OF f_0 f_step, of \"Suc i\" pcss pcs] not_finished simul\n  show ?thesis\n    by (auto simp add: p_def)\nqed\n\nlemma (in inf) steps_hd_progress:\nassumes f_0: \"f 0 = (c#cs,css,s)\"\nassumes f_step: \"\\<forall>i. \\<Gamma>\\<turnstile> f(i) \\<rightarrow> f(Suc i)\"\nassumes c_unfinished: \"\\<forall>i < k. \\<not> (CS (f i) = cs \\<and> CSS (f i) = css)\"\nshows \"\\<forall>i \\<le> k. (\\<exists>pcs pcss. \n          (if pcss = [] then CSS (f i)=css \\<and> CS (f i)=pcs@cs \n           else CS (f i)=pcs  \\<and> \n                CSS (f i)= butlast pcss@\n                           [(fst (last pcss)@cs,(snd (last pcss))@cs)]@\n                           css))\"\nusing c_unfinished \nproof (induct k)\n  case 0\n  with f_0 show ?case\n    by (simp add: CSS_def CS_def)\nnext\n  case (Suc k)\n  have c_unfinished: \"\\<forall>i<Suc k. \\<not> (CS (f i) = cs \\<and> CSS (f i) = css)\" by fact\n  hence c_unfinished': \"\\<forall>i< k. \\<not> (CS (f i) = cs \\<and> CSS (f i) = css)\" by simp\n  show ?case\n  proof (clarify)\n    fix i\n    assume i_le_Suc_k: \"i \\<le> Suc k\"\n    show \"\\<exists>pcs pcss. \n          (if pcss = [] then CSS (f i)=css \\<and> CS (f i)=pcs@cs \n           else CS (f i)=pcs  \\<and> \n                CSS (f i)= butlast pcss@\n                           [(fst (last pcss)@cs,(snd (last pcss))@cs)]@\n                           css)\"\n    proof (cases \"i < Suc k\")\n      case True\n      with Suc.hyps [OF c_unfinished', rule_format, of i] c_unfinished\n      show ?thesis\n        by auto\n    next\n      case False\n      with i_le_Suc_k have eq_i_Suc_k: \"i=Suc k\"\n        by auto\n      obtain cs' css' t' where \n        f_Suc_k: \"f (Suc k) = (cs', css', t')\"\n        by (cases \"f (Suc k)\")\n      obtain cs'' css'' t'' where \n        f_k: \"f k = (cs'',css'',t'')\"\n        by (cases \"f k\")\n      with Suc.hyps [OF c_unfinished',rule_format, of k] \n      obtain pcs pcss where  \n        pcs_pcss_k: \n        \"if pcss = [] then css'' = css \\<and> cs'' = pcs @ cs\n         else cs'' = pcs \\<and>\n              css'' = butlast pcss @ \n                           [(fst (last pcss) @ cs, snd (last pcss) @ cs)] @ \n                           css\"\n        by (auto simp add: CSS_def CS_def cong: if_cong)\n      from c_unfinished [rule_format, of k] f_k pcs_pcss_k\n      have pcs_pcss_empty: \"\\<not> (pcs = [] \\<and> pcss = [])\" \n        by (auto simp add: CS_def CSS_def S_def split: split_if_asm)\n      show ?thesis\n      proof (cases \"pcss = []\")\n        case True\n        note pcss_Nil = this\n        with pcs_pcss_k pcs_pcss_empty obtain p ps where\n          pcs_i: \"pcs = p#ps\" and\n          css'': \"css''=css\" and \n          cs'': \"cs''=(p#ps)@cs\"\n          by (cases \"pcs\") auto\n        with f_k have \"f k = (p#(ps@cs),css,t'')\"\n          by simp \n        with f_Suc_k f_step [rule_format, of k]\n        have step_css: \"\\<Gamma>\\<turnstile> (p#(ps@cs),css,t'') \\<rightarrow> (cs',css',t')\"\n          by simp\n        from step_Cons' [OF this, of p \"ps@cs\"]\n        obtain css''' where\n          css''': \"css' = css''' @ css\" \n          \"if css''' = [] then \\<exists>p. cs' = p @ ps @ cs\n          else (\\<exists>pnorm pabr. css'''=[(pnorm @ ps @ cs,pabr @ ps @ cs)])\"\n          by auto\n        show ?thesis\n        proof (cases \"css''' = []\")\n          case True\n          with css'''\n          obtain p' where \n            css': \"css' = css\" and\n            cs': \"cs' = p' @ ps @ cs\"\n            by auto\n          from css' cs' f_Suc_k\n          show ?thesis\n            apply (rule_tac x=\"p'@ps\" in exI) \n            apply (rule_tac x=\"[]\" in exI)\n            apply (simp add: CSS_def CS_def eq_i_Suc_k)\n            done\n        next\n          case False\n          with css'''\n          obtain pnorm pabr where \n            css': \"css'=css'''@css\"\n            \"css'''=[(pnorm @ ps @ cs,pabr @ ps @ cs)]\"\n            by auto\n          with f_Suc_k eq_i_Suc_k\n          show ?thesis\n            apply (rule_tac x=\"cs'\" in exI)\n            apply (rule_tac x=\"[(pnorm@ps, pabr@ps)]\" in exI) \n            by (simp add: CSS_def CS_def)\n        qed\n      next\n        case False\n        note pcss_k_not_Nil = this\n        with pcs_pcss_k obtain\n          cs'': \"cs''=pcs\" and  \n          css'': \"css''= butlast pcss@\n                           [(fst (last pcss)@cs,(snd (last pcss))@cs)]@\n                           css\"\n          by auto\n        from f_Suc_k f_k f_step [rule_format, of k]\n        have step_i_full: \"\\<Gamma>\\<turnstile> (cs'',css'',t'') \\<rightarrow> (cs',css',t')\"\n          by simp \n        show ?thesis\n        proof (cases cs'')\n          case (Cons c' cs)\n          with step_Cons' [OF step_i_full]\n          obtain css''' where css': \"css' = css'''@css''\"\n            by auto\n          with cs'' css'' f_Suc_k eq_i_Suc_k pcss_k_not_Nil\n          show ?thesis\n            apply (rule_tac x=\"cs'\" in exI)\n            apply (rule_tac x=\"css'''@pcss\" in exI)\n            by (clarsimp simp add: CSS_def CS_def butlast_append)\n        next\n          case Nil\n          note cs''_Nil = this\n          show ?thesis\n          proof (cases \"butlast pcss\")\n            case (Cons bpcs bpcss)\n            with cs''_Nil step_i_full css''\n            have \"\\<Gamma>\\<turnstile> ([],[hd css'']@tl css'',t'') \\<rightarrow> (cs',css',t')\"\n              by simp\n            moreover\n            from step_Nil [OF this]\n            obtain css': \"css'=tl css''\" and\n                   cs': \"cs' = (case t'' of Abrupt s' \\<Rightarrow> snd (hd css'') \n                                 | _ \\<Rightarrow> fst (hd css''))\"\n              by (auto split: xstate.splits)\n            from css'' Cons pcss_k_not_Nil\n            have \"hd css'' = hd pcss\"\n              by (auto simp add: neq_Nil_conv split: split_if_asm)\n            with css' cs' css'' cs''_Nil Cons pcss_k_not_Nil f_Suc_k eq_i_Suc_k  \n            show ?thesis\n              apply (rule_tac x=\"cs'\" in exI)\n              apply (rule_tac x=\"tl pcss\" in exI)\n              apply (clarsimp split: xstate.splits \n                       simp add: CS_def CSS_def neq_Nil_conv split: split_if_asm)\n              done\n          next\n            case Nil\n            with css'' pcss_k_not_Nil\n            obtain pnorm pabr\n              where css'': \"css''= [(pnorm@cs,pabr@cs)]@css\" and\n              pcss_k: \"pcss = [(pnorm,pabr)]\"\n              by (force simp add: neq_Nil_conv split: split_if_asm)\n            with cs''_Nil step_i_full\n            have \"\\<Gamma>\\<turnstile>([],[(pnorm@cs,pabr@cs)]@css,t'') \\<rightarrow> (cs',css',t')\"\n              by simp\n            from step_Nil [OF this]\n            obtain \n              css': \"css'=css\" and\n              cs': \"(case t'' of\n              Abrupt s' \\<Rightarrow> cs' = pabr @ cs \\<and> t' = Normal s'\n              | _ \\<Rightarrow> cs' = pnorm @ cs \\<and> t' = t'')\"\n              by (simp cong: xstate.case_cong)\n            let \"?pcs_Suc_k \" = \"(case t'' of Abrupt s' \\<Rightarrow> pabr | _ \\<Rightarrow> pnorm)\"\n            from css'' css' cs' pcss_k f_Suc_k eq_i_Suc_k\n            show ?thesis\n              apply (rule_tac x=\"?pcs_Suc_k\" in exI)\n              apply (rule_tac x=\"[]\" in exI)\n              apply (simp split: xstate.splits add: CS_def CSS_def)\n              done\n          qed\n        qed\n      qed\n    qed\n  qed\nqed\n  \nlemma (in inf) inf_progress:\nassumes f_0: \"f 0 = (c#cs,css,s)\"\nassumes f_step: \"\\<forall>i. \\<Gamma>\\<turnstile> f(i) \\<rightarrow> f(Suc i)\"\nassumes unfinished: \"\\<forall>i. \\<not> ((CS (f i) = cs) \\<and> (CSS (f i) = css))\"\nshows \"\\<exists>pcs pcss. \n          (if pcss = [] then CSS (f i)=css \\<and> CS (f i)=pcs@cs \n           else CS (f i)=pcs  \\<and> \n                CSS (f i)= butlast pcss@\n                           [(fst (last pcss)@cs,(snd (last pcss))@cs)]@\n                           css)\"\nproof -\n  from steps_hd_progress [OF f_0 f_step, of \"i\"] unfinished\n  show ?thesis\n    by auto\nqed\n\nlemma skolemize1: \"\\<forall>x. P x \\<longrightarrow> (\\<exists>y. Q x y) \\<Longrightarrow> \\<exists>f.\\<forall>x. P x \\<longrightarrow> Q x (f x)\"\n  by (rule choice) blast\n\nlemma skolemize2: \"\\<forall>x. P x \\<longrightarrow> (\\<exists>y z. Q x y z) \\<Longrightarrow> \\<exists>f g.\\<forall>x. P x \\<longrightarrow> Q x (f x) (g x)\"\napply (drule skolemize1)\napply (erule exE)\napply (drule skolemize1)\napply fast\ndone\n\nlemma skolemize2': \"\\<forall>x.\\<exists>y z. P x y z \\<Longrightarrow> \\<exists>f g.\\<forall>x. P x (f x) (g x)\"\napply (drule choice)\napply (erule exE)\napply (drule choice)\napply fast\ndone\n\ntheorem (in inf) inf_cases:\n  fixes c::\"('s,'p,'f) com\"\n  assumes inf: \"inf \\<Gamma> (c#cs) css s\" \n  shows \"inf \\<Gamma> [c] [] s \\<or> (\\<exists>t. \\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t \\<and> inf \\<Gamma> cs css t)\"\nproof -\n  from inf obtain f where\n    f_0: \"f 0 = (c#cs,css,s)\" and\n    f_step: \"(\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i))\"\n    by (auto simp add: inf_def)\n  show ?thesis\n  proof (cases \"\\<exists>i. CS (f i) = cs \\<and> CSS (f i) = css\")\n    case True\n    def k\\<equiv>\"(LEAST i. CS (f i) = cs \\<and> CSS (f i) = css)\"\n    from True\n    obtain CS_f_k: \"CS (f k) = cs\" and CSS_f_k: \"CSS (f k) = css\" \n      apply -\n      apply (erule exE)\n      apply (drule LeastI)\n      apply (simp add: k_def)\n      done\n    have less_k_prop: \"\\<forall>i<k. \\<not> (CS (f i) = cs \\<and> CSS (f i) = css)\"\n      apply (intro allI impI)\n      apply (unfold k_def)\n      apply (drule not_less_Least)\n      apply simp\n      done\n    have \"\\<Gamma>\\<turnstile>([c], [], s) \\<rightarrow>\\<^sup>* ([],[],S (f k))\"\n    proof -\n      have \"\\<forall>i\\<le>k. \\<exists>pcs pcss. \n        (if pcss = [] then CSS (f i)=css \\<and> CS (f i)=pcs@cs \n           else CS (f i)=pcs  \\<and> \n                CSS (f i)= butlast pcss@\n                           [(fst (last pcss)@cs,(snd (last pcss))@cs)]@\n                           css)\"\n        by (rule steps_hd_progress \n        [OF f_0 f_step, where k=k, OF less_k_prop])\n      from skolemize2 [OF this] obtain pcs pcss where\n        pcs_pcss: \n            \"\\<forall>i\\<le>k. \n               (if pcss i = [] then CSS (f i)=css \\<and> CS (f i)=pcs i@cs \n                else CS (f i)=pcs i \\<and> \n                     CSS (f i)= butlast (pcss i)@\n                           [(fst (last (pcss i))@cs,(snd (last (pcss i)))@cs)]@\n                           css)\"\n        by iprover\n      from pcs_pcss [rule_format, of k] CS_f_k CSS_f_k \n      have finished: \"pcs k = []\" \"pcss k = []\"\n        by (auto simp add: CS_def CSS_def S_def split: split_if_asm)\n      from pcs_pcss\n      have simul: \"\\<forall>i\\<le>k. (if pcss i = [] then CSS (f i)=css \\<and> CS (f i)=pcs i@cs \n                   else CS (f i)=pcs i \\<and> \n                     CSS (f i)= butlast (pcss i)@\n                           [(fst (last (pcss i))@cs,(snd (last (pcss i)))@cs)]@\n                            css)\"\n        by auto\n      from steps_hd_drop_suffix_finite [OF f_0 f_step less_k_prop simul] finished\n      show ?thesis\n        by simp\n    qed\n    hence \"\\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> S (f k)\"\n      by (rule steps_impl_exec)\n    moreover\n    from CS_f_k CSS_f_k f_step\n    have \"inf \\<Gamma> cs css (S (f k))\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (i + k)\" in exI)\n      apply simp\n      apply (auto simp add: CS_def CSS_def S_def)\n      done\n    ultimately\n    have \"(\\<exists>t. \\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t \\<and> inf \\<Gamma> cs css t)\"\n      by blast\n    thus ?thesis\n      by simp\n  next\n    case False\n    hence unfinished: \"\\<forall>i. \\<not> ((CS (f i) = cs) \\<and> (CSS (f i) = css))\"\n      by simp\n    from inf_progress [OF f_0 f_step this]\n    have \"\\<forall>i. \\<exists>pcs pcss. \n          (if pcss = [] then CSS (f i)=css \\<and> CS (f i)=pcs@cs \n           else CS (f i)=pcs  \\<and> \n                CSS (f i)= butlast pcss@\n                           [(fst (last pcss)@cs,(snd (last pcss))@cs)]@\n                           css)\"\n      by auto\n    from skolemize2' [OF this] obtain pcs pcss where \n      pcs_pcss: \"\\<forall>i. \n          (if pcss i = [] then CSS (f i)=css \\<and> CS (f i)=pcs i@cs \n           else CS (f i)=pcs i  \\<and> \n                CSS (f i)= butlast (pcss i)@\n                           [(fst (last (pcss i))@cs,(snd (last (pcss i)))@cs)]@\n                           css)\"\n      by iprover\n    def \"g\" \\<equiv> \"\\<lambda>i. (pcs i, pcss i, S (f i))\"\n    from pcs_pcss [rule_format, of 0] f_0\n    have \"g 0 = ([c],[],s)\"\n      by (auto split: split_if_asm simp add: CS_def CSS_def S_def g_def)\n    moreover\n    from steps_hd_drop_suffix_infinite [OF f_0 f_step unfinished pcs_pcss]\n    have \"\\<forall>i. \\<Gamma>\\<turnstile>g i \\<rightarrow> g (Suc i)\"\n      by (simp add: g_def)\n    ultimately\n    have \"inf \\<Gamma> [c] [] s\"\n      by (auto simp add: inf_def)\n    thus ?thesis\n      by simp\n  qed\nqed\n\nlemma infE [consumes 1]:\n  assumes inf: \"inf \\<Gamma> (c#cs) css s\" \n  assumes cases: \"inf \\<Gamma> [c] [] s \\<Longrightarrow> P\"\n                 \"\\<And>t. \\<lbrakk>\\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t; inf \\<Gamma> cs css t\\<rbrakk> \\<Longrightarrow> P\"\n  shows P\nusing inf cases\napply -\napply (drule inf.inf_cases)\napply auto\ndone\n\nlemma inf_Seq: \n  \"inf \\<Gamma> (Seq c1 c2#cs) css (Normal s) = inf \\<Gamma> (c1#c2#cs) css (Normal s)\" \nproof \n  assume \"inf \\<Gamma> (Seq c1 c2 # cs) css (Normal s)\"\n  then obtain f where \n    f_0: \"f 0 = (Seq c1 c2#cs,css,Normal s)\" and\n    f_step: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    by (auto simp add: inf_def)\n  from f_step [rule_format, of 0] f_0\n  have \"f 1 = (c1#c2#cs,css,Normal s)\"\n    by (auto elim: step_Normal_elim_cases)\n  with f_step show \"inf \\<Gamma> (c1#c2#cs) css (Normal s)\"\n    apply (simp add: inf_def)\n    apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n    apply simp\n    done\nnext\n  assume \"inf \\<Gamma> (c1 # c2 # cs) css (Normal s)\"\n  then obtain f where \n    f_0: \"f 0 = (c1# c2#cs,css,Normal s)\" and\n    f_step: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    by (auto simp add: inf_def)\n  def g\\<equiv>\"\\<lambda>i. case i of 0 \\<Rightarrow> (Seq c1 c2#cs,css,Normal s) | Suc j \\<Rightarrow> f j\" \n  with f_0 have\n    \"\\<Gamma>\\<turnstile>g 0 \\<rightarrow> g (Suc 0)\"\n    by (auto intro: step.intros)\n  moreover\n  from f_step have \"\\<forall>i. i\\<noteq>0 \\<longrightarrow> \\<Gamma>\\<turnstile>g i \\<rightarrow> g (Suc i)\"\n    by (auto simp add: g_def split: nat.splits)\n  ultimately\n  show \"inf \\<Gamma> (Seq c1 c2 # cs) css (Normal s)\"\n    apply (simp add: inf_def)\n    apply (rule_tac x=g in exI)\n    apply (simp add: g_def split: nat.splits)\n    done\nqed\n \nlemma inf_WhileTrue: \n  assumes b: \"s \\<in> b\"\n  shows \"inf \\<Gamma> (While b c#cs) css (Normal s) = \n          inf \\<Gamma> (c#While b c#cs) css (Normal s)\" \nproof\n  assume \"inf \\<Gamma> (While b c # cs) css (Normal s)\"\n  then obtain f where \n    f_0: \"f 0 = (While b c#cs,css,Normal s)\" and\n    f_step: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    by (auto simp add: inf_def)\n  from b f_step [rule_format, of 0] f_0\n  have \"f 1 = (c#While b c#cs,css,Normal s)\"\n    by (auto elim: step_Normal_elim_cases)\n  with f_step show \"inf \\<Gamma> (c # While b c # cs) css (Normal s)\"\n    apply (simp add: inf_def)\n    apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n    apply simp\n    done\nnext\n  assume \"inf \\<Gamma> (c # While b c # cs) css (Normal s)\"\n  then obtain f where \n    f_0: \"f 0 = (c # While b c #cs,css,Normal s)\" and\n    f_step: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    by (auto simp add: inf_def)\n  def h\\<equiv>\"\\<lambda>i. case i of 0 \\<Rightarrow> (While b c#cs,css,Normal s) | Suc j \\<Rightarrow> f j\" \n  with b f_0 have\n    \"\\<Gamma>\\<turnstile>h 0 \\<rightarrow> h (Suc 0)\"\n    by (auto intro: step.intros)\n  moreover\n  from f_step have \"\\<forall>i. i\\<noteq>0 \\<longrightarrow> \\<Gamma>\\<turnstile>h i \\<rightarrow> h (Suc i)\"\n    by (auto simp add: h_def split: nat.splits)\n  ultimately\n  show \"inf \\<Gamma> (While b c # cs) css (Normal s)\"\n    apply (simp add: inf_def)\n    apply (rule_tac x=h in exI)\n    apply (simp add: h_def split: nat.splits)\n    done\nqed\n\nlemma inf_Catch:\n\"inf \\<Gamma> (Catch c1 c2#cs) css (Normal s) = inf \\<Gamma> [c1] ((cs,c2#cs)#css) (Normal s)\"\nproof\n  assume \"inf \\<Gamma> (Catch c1 c2#cs) css (Normal s)\"\n  then obtain f where \n    f_0: \"f 0 = (Catch c1 c2#cs,css,Normal s)\" and\n    f_step: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    by (auto simp add: inf_def)\n  from f_step [rule_format, of 0] f_0\n  have \"f 1 = ([c1],(cs,c2#cs)#css,Normal s)\"\n    by (auto elim: step_Normal_elim_cases)\n  with f_step show \"inf \\<Gamma> [c1] ((cs,c2#cs)#css) (Normal s)\"\n    apply (simp add: inf_def)\n    apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n    apply simp\n    done\nnext\n  assume \"inf \\<Gamma> [c1] ((cs,c2#cs)#css) (Normal s)\"\n  then obtain f where \n    f_0: \"f 0 = ([c1],(cs,c2#cs)#css,Normal s)\" and\n    f_step: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    by (auto simp add: inf_def)\n  def h\\<equiv>\"\\<lambda>i. case i of 0 \\<Rightarrow> (Catch c1 c2#cs,css,Normal s) | Suc j \\<Rightarrow> f j\" \n  with f_0 have\n    \"\\<Gamma>\\<turnstile>h 0 \\<rightarrow> h (Suc 0)\"\n    by (auto intro: step.intros)\n  moreover\n  from f_step have \"\\<forall>i. i\\<noteq>0 \\<longrightarrow> \\<Gamma>\\<turnstile>h i \\<rightarrow> h (Suc i)\"\n    by (auto simp add: h_def split: nat.splits)\n  ultimately\n  show \"inf \\<Gamma> (Catch c1 c2 # cs) css (Normal s)\"\n    apply (simp add: inf_def)\n    apply (rule_tac x=h in exI)\n    apply (simp add: h_def split: nat.splits)\n    done\nqed\n\ntheorem terminates_impl_not_inf: \n  assumes termi: \"\\<Gamma>\\<turnstile>c \\<down> s\"\n  shows \"\\<not>inf \\<Gamma> [c] [] s\"\nusing termi\nproof induct\n  case (Skip s) thus ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([Skip], [], Normal s)\" \n    from f_step [of 0] f_0\n    have \"f (Suc 0) = ([],[],Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step [of 1]\n    show False\n      by (auto elim: step_elim_cases)\n  qed\nnext\n  case (Basic g s) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([Basic g], [], Normal s)\" \n    from f_step [of 0] f_0\n    have \"f (Suc 0) = ([],[],Normal (g s))\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step [of 1]\n    show False\n      by (auto elim: step_elim_cases)\n  qed\nnext\n  case (Spec r s) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([Spec r], [], Normal s)\" \n    with f_step [of 0]\n    have \"\\<Gamma>\\<turnstile>([Spec r], [], Normal s) \\<rightarrow> f (Suc 0)\"\n      by simp\n    then show False\n    proof (cases)\n      fix t\n      assume \"(s, t) \\<in> r\" \"f (Suc 0) = ([], [], Normal t)\"\n      with f_step [of 1]\n      show False\n        by (auto elim: step_elim_cases)\n    next\n      assume \"\\<forall>t. (s, t) \\<notin> r\" \"f (Suc 0) = ([], [], Stuck)\"\n      with f_step [of 1]\n      show False\n        by (auto elim: step_elim_cases)\n    qed\n  qed\nnext\n  case (Guard s g c m)\n  have g: \"s \\<in> g\" by fact\n  have hyp: \"\\<not> inf \\<Gamma> [c] [] (Normal s)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([Guard m g c], [], Normal s)\" \n    from g f_step [of 0] f_0\n    have \"f (Suc 0) = ([c],[],Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step\n    have \"inf \\<Gamma> [c] [] (Normal s)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with hyp show False ..\n  qed\nnext\n  case (GuardFault s g m c)\n  have g: \"s \\<notin> g\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([Guard m g c], [], Normal s)\" \n    from g f_step [of 0] f_0\n    have \"f (Suc 0) = ([],[],Fault m)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step [of 1]\n    show False\n      by (auto elim: step_elim_cases)\n  qed\nnext\n  case (Fault c m)\n  thus ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([c], [], Fault m)\" \n    from f_step [of 0] f_0\n    have \"f (Suc 0) = ([],[],Fault m)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step [of 1]\n    show False\n      by (auto elim: step_elim_cases)\n  qed\nnext\n  case (Seq c1 s c2)\n  have hyp_c1: \"\\<not> inf \\<Gamma> [c1] [] (Normal s)\" by fact\n  have hyp_c2: \"\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> s' \\<longrightarrow> \\<Gamma>\\<turnstile>c2 \\<down> s' \\<and> \\<not> inf \\<Gamma> [c2] [] s'\" by fact\n  have \"\\<not> inf \\<Gamma> ([c1,c2]) [] (Normal s)\"\n  proof \n    assume \"inf \\<Gamma> [c1, c2] [] (Normal s)\"\n    then show False\n    proof (cases rule: infE)\n      assume \"inf \\<Gamma> [c1] [] (Normal s)\"\n      with hyp_c1 show ?thesis by simp\n    next\n      fix t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> t\" \"inf \\<Gamma> [c2] [] t\"\n      with hyp_c2 show ?thesis by simp\n    qed\n  qed\n  thus ?case\n    by (simp add: inf_Seq)\nnext\n  case (CondTrue s b c1 c2)\n  have b: \"s \\<in> b\" by fact\n  have hyp_c1: \"\\<not> inf \\<Gamma> [c1] [] (Normal s)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([Cond b c1 c2], [], Normal s)\" \n    from b f_step [of 0] f_0\n    have \"f 1 = ([c1],[],Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step\n    have \"inf \\<Gamma> [c1] [] (Normal s)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with hyp_c1 show False by simp\n  qed\nnext\n  case (CondFalse s b c2 c1)\n  have b: \"s \\<notin> b\" by fact\n  have hyp_c2: \"\\<not> inf \\<Gamma> [c2] [] (Normal s)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([Cond b c1 c2], [], Normal s)\" \n    from b f_step [of 0] f_0\n    have \"f 1 = ([c2],[],Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step\n    have \"inf \\<Gamma> [c2] [] (Normal s)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with hyp_c2 show False by simp\n  qed\nnext\n  case (WhileTrue s b c)\n  have b: \"s \\<in> b\" by fact\n  have hyp_c: \"\\<not> inf \\<Gamma> [c] [] (Normal s)\" by fact\n  have hyp_w: \"\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> s' \\<longrightarrow> \n                      \\<Gamma>\\<turnstile>While b c \\<down> s' \\<and> \\<not> inf \\<Gamma> [While b c] [] s'\" by fact\n  have \"\\<not> inf \\<Gamma> [c,While b c] [] (Normal s)\"\n  proof \n    assume \"inf \\<Gamma> [c,While b c] [] (Normal s)\"\n    from this hyp_c hyp_w show False\n      by (cases rule: infE) auto\n  qed\n  with b show ?case\n    by (simp add: inf_WhileTrue)\nnext\n  case (WhileFalse s b c)\n  have b: \"s \\<notin> b\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([While b c], [], Normal s)\" \n    from b f_step [of 0] f_0\n    have \"f (Suc 0) = ([],[],Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step [of 1]\n    show False\n      by (auto elim: step_elim_cases)\n  qed\nnext\n  case (Call p bdy s)\n  have bdy: \"\\<Gamma> p = Some bdy\" by fact\n  have hyp: \"\\<not> inf \\<Gamma> [bdy] [] (Normal s)\" by fact\n  have not_inf_bdy:\n    \"\\<not> inf \\<Gamma> [bdy] [([],[Throw])] (Normal s)\"\n  proof \n    assume \"inf \\<Gamma> [bdy] [([],[Throw])] (Normal s)\"\n    then show False\n    proof (rule infE)\n      assume \"inf \\<Gamma> [bdy] [] (Normal s)\"\n      with hyp show False by simp\n    next\n      fix t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal s\\<rangle> \\<Rightarrow> t\"\n      assume inf: \"inf \\<Gamma> [] [([], [Throw])] t\"\n      then obtain f where\n        f_0: \"f 0 = ([],[([], [Throw])],t)\" and\n        f_step: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n        by (auto simp add: inf_def)\n      show False\n      proof (cases t)\n        case (Normal t')\n        with f_0 f_step [rule_format, of 0]\n        have \"f (Suc 0) = ([],[],(Normal t'))\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step [rule_format, of \"Suc 0\"]\n        show False\n          by (auto elim: step.cases)\n      next        \n        case (Abrupt t')\n        with f_0 f_step [rule_format, of 0]\n        have \"f (Suc 0) = ([Throw],[],(Normal t'))\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step [rule_format, of \"Suc 0\"]\n        have \"f (Suc (Suc 0)) = ([],[],(Abrupt t'))\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step [rule_format, of \"Suc(Suc 0)\"]\n        show False\n          by (auto elim: step.cases)\n      next\n        case (Fault m)\n        with f_0 f_step [rule_format, of 0]\n        have \"f (Suc 0) = ([],[],Fault m)\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step [rule_format, of 1]\n        have \"f (Suc (Suc 0)) = ([],[],Fault m)\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step [rule_format, of \"Suc (Suc 0)\"]\n        show False\n          by (auto elim: step.cases)\n      next\n        case Stuck\n        with f_0 f_step [rule_format, of 0]\n        have \"f (Suc 0) = ([],[],Stuck)\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step [rule_format, of 1]\n        have \"f (Suc (Suc 0)) = ([],[],Stuck)\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step [rule_format, of \"Suc (Suc 0)\"]\n        show False\n          by (auto elim: step.cases)\n      qed\n    qed\n  qed   \n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([Call p], [], Normal s)\" \n    from bdy f_step [of 0] f_0\n    have \"f (Suc 0) = \n              ([bdy],[([],[Throw])],Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step\n    have \"inf \\<Gamma> [bdy] [([],[Throw])] (Normal s)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with not_inf_bdy\n    show False by simp\n  qed\nnext\n  case (CallUndefined p s)\n  have undef: \"\\<Gamma> p = None\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([Call p], [], Normal s)\" \n    from undef f_step [of 0] f_0\n    have \"f (Suc 0) = ([],[],Stuck)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step [rule_format, of \"Suc 0\"]\n    show False\n      by (auto elim: step_elim_cases)\n  qed\nnext\n  case (Stuck c)\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([c], [], Stuck)\" \n    from f_step [of 0] f_0\n    have \"f (Suc 0) = ([],[],Stuck)\"\n      by (auto elim: step_elim_cases)\n    with f_step [rule_format, of \"Suc 0\"]\n    show False\n      by (auto elim: step_elim_cases)\n  qed\nnext\n  case (DynCom c s)\n  have hyp: \"\\<not> inf \\<Gamma> [(c s)] [] (Normal s)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([DynCom c], [], Normal s)\" \n    from f_step [of 0] f_0\n    have \"f (Suc 0) = ([(c s)], [], Normal s)\"\n      by (auto elim: step_elim_cases)\n    with f_step have \"inf \\<Gamma> [(c s)] [] (Normal s)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with hyp\n    show False by simp\n  qed\nnext\n  case (Throw s) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([Throw], [], Normal s)\" \n    from f_step [of 0] f_0\n    have \"f (Suc 0) = ([],[],Abrupt s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step [of 1]\n    show False\n      by (auto elim: step_elim_cases)\n  qed\nnext\n  case (Abrupt c s)\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([c], [], Abrupt s)\" \n    from f_step [of 0] f_0\n    have \"f (Suc 0) = ([],[],Abrupt s)\"\n      by (auto elim: step_elim_cases)\n    with f_step [rule_format, of \"Suc 0\"]\n    show False\n      by (auto elim: step_elim_cases)\n  qed\nnext\n  case (Catch c1 s c2)\n  have hyp_c1: \"\\<not> inf \\<Gamma> [c1] [] (Normal s)\" by fact\n  have hyp_c2: \"\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> Abrupt s' \\<longrightarrow>\n                   \\<Gamma>\\<turnstile>c2 \\<down> Normal s' \\<and> \\<not> inf \\<Gamma> [c2] [] (Normal s')\" by fact\n  have \"\\<not> inf \\<Gamma> [c1] [([],[c2])] (Normal s)\"\n  proof \n    assume \"inf \\<Gamma> [c1] [([],[c2])] (Normal s)\"\n    then show False\n    proof (rule infE) \n      assume \"inf \\<Gamma> [c1] [] (Normal s)\"\n      with hyp_c1 show False by simp\n    next\n      fix t\n      assume eval: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> t\" \n      assume inf: \"inf \\<Gamma> [] [([], [c2])] t\"\n      then obtain f where\n        f_0: \"f 0 = ([],[([], [c2] )],t)\" and\n        f_step: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n        by (auto simp add: inf_def)\n      show False\n      proof (cases t)\n        case (Normal t')\n        with f_0 f_step [rule_format, of 0]\n        have \"f (Suc 0) = ([],[],Normal t')\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step [rule_format, of 1]\n        show False\n          by (auto elim: step_elim_cases)\n      next\n        case (Abrupt t')\n        with f_0 f_step [rule_format, of 0]\n        have \"f (Suc 0) = ([c2],[],Normal t')\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step eval Abrupt\n        have \"inf \\<Gamma> [c2] [] (Normal t')\"\n          apply (simp add: inf_def)\n          apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n          by simp\n        with eval hyp_c2 Abrupt show False by simp\n      next\n        case (Fault m)\n        with f_0 f_step [rule_format, of 0]\n        have \"f (Suc 0) = ([],[],Fault m)\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step [rule_format, of 1]\n        show False\n          by (auto elim: step_elim_cases)\n      next\n        case Stuck\n        with f_0 f_step [rule_format, of 0]\n        have \"f (Suc 0) = ([],[],Stuck)\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step [rule_format, of 1]\n        show False\n          by (auto elim: step_elim_cases)\n      qed\n    qed\n  qed\n  thus ?case\n    by (simp add: inf_Catch)\nqed\n\nlemma terminatess_impl_not_inf:\n assumes termi: \"\\<Gamma>\\<turnstile>cs,css\\<Down>s\" \n  shows \"\\<not>inf \\<Gamma> cs css s\"\nusing termi\nproof (induct)\n  case (Nil s)\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    hence \"\\<Gamma>\\<turnstile>f 0 \\<rightarrow> f (Suc 0)\" \n      by simp\n    moreover\n    assume \"f 0 = ([], [], s)\"\n    ultimately show False\n      by (fastforce elim: step.cases)\n  qed\nnext\n  case (ExitBlockNormal nrms css s abrs)\n  have hyp: \"\\<not> inf \\<Gamma> nrms css (Normal s)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f0: \"f 0 = ([], (nrms, abrs) # css, Normal s)\"\n    with f_step [of 0] have \"f (Suc 0) = (nrms,css,Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step have \"inf \\<Gamma> nrms css (Normal s)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp   \n    with hyp show False ..\n  qed\nnext\n  case (ExitBlockAbrupt abrs css s nrms)\n  have hyp: \"\\<not> inf \\<Gamma> abrs css (Normal s)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f0: \"f 0 = ([], (nrms, abrs) # css, Abrupt s)\"\n    with f_step [of 0] have \"f (Suc 0) = (abrs,css,Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step have \"inf \\<Gamma> abrs css (Normal s)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp   \n    with hyp show False ..\n  qed\nnext\n  case (ExitBlockFault nrms css f abrs)\n  show ?case\n    by (rule not_inf_Fault)\nnext\n  case (ExitBlockStuck nrms css abrs)\n  show ?case\n    by (rule not_inf_Stuck)\nnext\n  case (Cons c s cs css)\n  have termi_c: \"\\<Gamma>\\<turnstile>c \\<down> s\" by fact\n  have hyp: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t \\<longrightarrow> \\<Gamma>\\<turnstile>cs,css\\<Down>t \\<and> \\<not> inf \\<Gamma> cs css t\"  by fact\n  show \"\\<not> inf \\<Gamma> (c # cs) css s\"\n  proof \n    assume \"inf \\<Gamma> (c # cs) css s\"\n    thus False\n    proof (rule infE)\n      assume \"inf \\<Gamma> [c] [] s\"\n      with terminates_impl_not_inf [OF termi_c]\n      show False ..\n    next\n      fix t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t\" \"inf \\<Gamma> cs css t\"\n      with hyp show False by simp\n    qed\n  qed\nqed\n\nlemma lem:\n  \"\\<forall>y. r\\<^sup>+\\<^sup>+ a y \\<longrightarrow> P a \\<longrightarrow> P y \n   \\<Longrightarrow> ((b,a) \\<in> {(y,x). P x \\<and> r x y}\\<^sup>+) = ((b,a) \\<in> {(y,x). P x \\<and> r\\<^sup>+\\<^sup>+ x y})\"\napply(rule iffI)\n apply clarify\n apply(erule trancl_induct)\n  apply blast\n apply(blast intro:tranclp_trans)\napply clarify\napply(erule tranclp_induct)\n apply blast\napply(blast intro:trancl_trans)\ndone\n\ncorollary terminatess_impl_no_inf_chain:\n assumes terminatess: \"\\<Gamma>\\<turnstile>cs,css\\<Down>s\"\n shows \"\\<not>(\\<exists>f. f 0 = (cs,css,s) \\<and> (\\<forall>i::nat. \\<Gamma>\\<turnstile>f i \\<rightarrow>\\<^sup>+ f(Suc i)))\"\nproof -\n  have \"wf({(y,x). \\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow> y}\\<^sup>+)\"\n  proof (rule wf_trancl)\n    show \"wf {(y, x). \\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow> y}\"\n    proof (simp only: wf_iff_no_infinite_down_chain,clarify,simp)\n      fix f\n      assume \"\\<forall>i. \\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* f i \\<and> \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n      hence \"\\<exists>f. f 0 = (cs, css, s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i))\"\n        by (rule renumber [to_pred])\n      moreover from terminatess\n      have \"\\<not> (\\<exists>f. f 0 = (cs, css, s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)))\"\n        by (rule terminatess_impl_not_inf [unfolded inf_def])\n      ultimately show False\n        by simp\n    qed\n  qed\n  hence \"\\<not> (\\<exists>f. \\<forall>i. (f (Suc i), f i)\n                 \\<in> {(y, x). \\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow> y}\\<^sup>+)\"\n    by (simp add: wf_iff_no_infinite_down_chain)\n  thus ?thesis\n  proof (rule contrapos_nn)\n    assume \"\\<exists>f. f 0 = (cs, css, s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow>\\<^sup>+ f (Suc i))\"\n    then obtain f where\n      f0: \"f 0 = (cs, css, s)\" and\n      seq: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow>\\<^sup>+ f (Suc i)\"\n      by iprover\n    show \n      \"\\<exists>f. \\<forall>i. (f (Suc i), f i) \\<in> {(y, x). \\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow> y}\\<^sup>+\"\n    proof (rule exI [where x=f],rule allI)\n      fix i\n      show \"(f (Suc i), f i) \\<in> {(y, x). \\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow> y}\\<^sup>+\"\n      proof -   \n        {\n          fix i have \"\\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow>\\<^sup>* f i\"\n          proof (induct i)\n            case 0 show \"\\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* f 0\"\n              by (simp add: f0)\n          next\n            case (Suc n)\n            have \"\\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* f n\"  by fact\n            with seq show \"\\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* f (Suc n)\"\n              by (blast intro: tranclp_into_rtranclp rtranclp_trans)\n          qed\n        }\n        hence \"\\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow>\\<^sup>* f i\"\n          by iprover\n        with seq have\n          \"(f (Suc i), f i) \\<in> {(y, x). \\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow>\\<^sup>+ y}\"\n          by clarsimp\n        moreover \n        have \"\\<forall>y. \\<Gamma>\\<turnstile>f i \\<rightarrow>\\<^sup>+ y\\<longrightarrow>\\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* f i\\<longrightarrow>\\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* y\"\n          by (blast intro: tranclp_into_rtranclp rtranclp_trans)\n        ultimately \n        show ?thesis \n          by (subst lem)\n      qed\n    qed\n  qed\nqed\n\ncorollary terminates_impl_no_inf_chain:\n \"\\<Gamma>\\<turnstile>c\\<down>s \\<Longrightarrow> \\<not>(\\<exists>f. f 0 = ([c],[],s) \\<and> (\\<forall>i::nat. \\<Gamma>\\<turnstile>f i \\<rightarrow>\\<^sup>+ f(Suc i)))\"\n  by (rule terminatess_impl_no_inf_chain) (iprover intro: terminatess.intros)\n\n\ndefinition\n termi_call_steps :: \"('s,'p,'f) body \\<Rightarrow> (('s \\<times> 'p) \\<times> ('s \\<times> 'p))set\"\nwhere\n\"termi_call_steps \\<Gamma> =\n {((t,q),(s,p)). \\<Gamma>\\<turnstile>the (\\<Gamma> p)\\<down>Normal s \\<and> \n       (\\<exists>css. \\<Gamma>\\<turnstile>([the (\\<Gamma> p)],[],Normal s) \\<rightarrow>\\<^sup>+ ([the (\\<Gamma> q)],css,Normal t))}\"\n\ntext {* Sequencing computations, or more exactly continuation stacks *}\nprimrec seq:: \"(nat \\<Rightarrow> 'a list) \\<Rightarrow> nat \\<Rightarrow> 'a list\"\nwhere\n\"seq css 0 = []\" |\n\"seq css (Suc i) = css i@seq css i\"\n\n\ntheorem wf_termi_call_steps: \"wf (termi_call_steps \\<Gamma>)\"\nproof (simp only: termi_call_steps_def wf_iff_no_infinite_down_chain,\n       clarify,simp)\n  fix S\n  assume inf:\n     \"\\<forall>i. (\\<lambda>(t,q) (s,p). \\<Gamma>\\<turnstile>(the (\\<Gamma> p)) \\<down> Normal s \\<and>\n                 (\\<exists>css. \\<Gamma>\\<turnstile>([the (\\<Gamma> p)],[],Normal s) \\<rightarrow>\\<^sup>+ ([the (\\<Gamma> q)],css,Normal t)))\n           (S (Suc i)) (S i)\"\n  obtain s p where \"s = (\\<lambda>i. fst (S i))\" and \"p = (\\<lambda>i. snd (S i))\" \n    by auto\n  with inf\n  have inf':\n     \"\\<forall>i. \\<Gamma>\\<turnstile>(the (\\<Gamma> (p i))) \\<down> Normal (s i) \\<and>\n                 (\\<exists>css. \\<Gamma>\\<turnstile>([the (\\<Gamma> (p i))],[],Normal (s i)) \\<rightarrow>\\<^sup>+ \n                           ([the (\\<Gamma> (p (Suc i)))],css,Normal (s (Suc i))))\"\n    apply -\n    apply (rule allI)\n    apply (erule_tac x=i in allE)\n    apply auto\n    done\n  show False\n  proof -\n    from inf' -- {* Skolemization of css with axiom of choice *}\n    have \"\\<exists>css. \\<forall>i. \\<Gamma>\\<turnstile>(the (\\<Gamma> (p i))) \\<down> Normal (s i) \\<and>\n                 \\<Gamma>\\<turnstile>([the (\\<Gamma> (p i))],[],Normal (s i)) \\<rightarrow>\\<^sup>+ \n                           ([the (\\<Gamma> (p (Suc i)))],css i,Normal (s (Suc i)))\"\n      apply -\n      apply (rule choice)\n      by blast\n    then obtain css where\n      termi_css: \"\\<forall>i. \\<Gamma>\\<turnstile>(the (\\<Gamma> (p i))) \\<down> Normal (s i)\" and\n      step_css: \"\\<forall>i. \\<Gamma>\\<turnstile>([the (\\<Gamma> (p i))],[],Normal (s i)) \\<rightarrow>\\<^sup>+ \n                         ([the (\\<Gamma> (p (Suc i)))],css i,Normal (s (Suc i)))\"\n      by blast\n    def f == \"\\<lambda>i. ([the (\\<Gamma> (p i))], seq css i,Normal (s i)::('a,'c) xstate)\"\n    have \"f 0 = ([the (\\<Gamma> (p 0))],[],Normal (s 0))\"\n      by (simp add: f_def)\n    moreover\n    have \"\\<forall>i. \\<Gamma>\\<turnstile> (f i) \\<rightarrow>\\<^sup>+ (f (i+1))\"\n    proof \n      fix i\n      from step_css [rule_format, of i]\n      have \"\\<Gamma>\\<turnstile>([the (\\<Gamma> (p i))], [], Normal (s i)) \\<rightarrow>\\<^sup>+ \n              ([the (\\<Gamma> (p (Suc i)))], css i, Normal (s (Suc i)))\".\n      from app_css_steps [OF this,simplified]\n      have \"\\<Gamma>\\<turnstile>([the (\\<Gamma> (p i))], seq css i, Normal (s i)) \\<rightarrow>\\<^sup>+ \n              ([the (\\<Gamma> (p (Suc i)))], css i@seq css i, Normal (s (Suc i)))\".\n      thus \"\\<Gamma>\\<turnstile> (f i) \\<rightarrow>\\<^sup>+ (f (i+1))\"\n        by (simp add: f_def)\n    qed\n    moreover from termi_css [rule_format, of 0]\n    have \"\\<not> (\\<exists>f. (f 0 = ([the (\\<Gamma> (p 0))],[],Normal (s 0)) \\<and> \n                 (\\<forall>i. \\<Gamma>\\<turnstile>(f i) \\<rightarrow>\\<^sup>+ f(Suc i))))\"\n      by (rule terminates_impl_no_inf_chain)\n    ultimately show False\n      by auto\n  qed\nqed\n\ntext {* An alternative proof using Hilbert-choice instead of axiom of choice.*}\ntheorem \"wf (termi_call_steps \\<Gamma>)\"\nproof (simp only: termi_call_steps_def wf_iff_no_infinite_down_chain,\n       clarify,simp)\n  fix S\n  assume inf:\n     \"\\<forall>i. (\\<lambda>(t,q) (s,p). \\<Gamma>\\<turnstile>(the (\\<Gamma> p)) \\<down> Normal s \\<and>\n                 (\\<exists>css. \\<Gamma>\\<turnstile>([the (\\<Gamma> p)],[],Normal s) \\<rightarrow>\\<^sup>+ ([the (\\<Gamma> q)],css,Normal t)))\n           (S (Suc i)) (S i)\"\n  obtain s p where \"s = (\\<lambda>i. fst (S i))\" and \"p = (\\<lambda>i. snd (S i))\" \n    by auto\n  with inf\n  have inf':\n     \"\\<forall>i. \\<Gamma>\\<turnstile>(the (\\<Gamma> (p i))) \\<down> Normal (s i) \\<and>\n                 (\\<exists>css. \\<Gamma>\\<turnstile>([the (\\<Gamma> (p i))],[],Normal (s i)) \\<rightarrow>\\<^sup>+ \n                           ([the (\\<Gamma> (p (Suc i)))],css,Normal (s (Suc i))))\"\n    apply -\n    apply (rule allI)\n    apply (erule_tac x=i in allE)\n    apply auto\n    done\n  show \"False\"\n  proof -\n    def CSS \\<equiv> \"\\<lambda>i. (SOME css.  \n                      \\<Gamma>\\<turnstile>([the (\\<Gamma> (p i))],[], Normal (s i)) \\<rightarrow>\\<^sup>+\n                      ([the (\\<Gamma> (p (i+1)))],css,Normal (s (i+1))))\"\n    def f == \"\\<lambda>i. ([the (\\<Gamma> (p i))], seq CSS i,Normal (s i)::('a,'c) xstate)\"\n    have \"f 0 = ([the (\\<Gamma> (p 0))],[],Normal (s 0))\"\n      by (simp add: f_def)\n    moreover\n    have \"\\<forall>i. \\<Gamma>\\<turnstile> (f i) \\<rightarrow>\\<^sup>+ (f (i+1))\"\n    proof \n      fix i\n      from inf' [rule_format, of i] obtain css where\n         css: \"\\<Gamma>\\<turnstile>([the (\\<Gamma> (p i))],[],Normal (s i)) \\<rightarrow>\\<^sup>+ \n                ([the (\\<Gamma> (p (i+1)))],css,Normal (s (i+1)))\"\n        by fastforce\n      hence \"\\<Gamma>\\<turnstile>([the (\\<Gamma> (p i))], seq CSS i, Normal (s i)) \\<rightarrow>\\<^sup>+ \n                  ([the (\\<Gamma> (p (i+1)))], CSS i @ seq CSS i, Normal (s (i+1)))\"\n        apply -\n        apply (unfold CSS_def)\n        apply (rule someI2 \n              [where P=\"\\<lambda>css. \n                    \\<Gamma>\\<turnstile>([the (\\<Gamma> (p i))],[],Normal (s i))\\<rightarrow>\\<^sup>+\n                         ([the (\\<Gamma> (p (i+1)))],css, Normal (s (i+1)))\"])\n        apply (rule css)\n        apply (fastforce dest: app_css_steps)\n        done\n      thus \"\\<Gamma>\\<turnstile> (f i) \\<rightarrow>\\<^sup>+ (f (i+1))\"\n        by (simp add: f_def)\n    qed\n    moreover from inf' [rule_format, of 0]\n    have \"\\<Gamma>\\<turnstile>the (\\<Gamma> (p 0)) \\<down> Normal (s 0)\" \n      by iprover\n    then have \"\\<not> (\\<exists>f. (f 0 = ([the (\\<Gamma> (p 0))],[],Normal (s 0)) \\<and> \n                 (\\<forall>i. \\<Gamma>\\<turnstile>(f i) \\<rightarrow>\\<^sup>+ f(Suc i))))\"\n      by (rule terminates_impl_no_inf_chain)\n    ultimately show False\n      by auto\n  qed\nqed\n\nlemma not_inf_implies_wf: assumes not_inf: \"\\<not> inf \\<Gamma> cs css s\"\n  shows \"wf {(c2,c1). \\<Gamma> \\<turnstile> (cs,css,s) \\<rightarrow>\\<^sup>* c1 \\<and> \\<Gamma> \\<turnstile> c1 \\<rightarrow> c2}\"\nproof (simp only: wf_iff_no_infinite_down_chain,clarify, simp)\n  fix f\n  assume \"\\<forall>i. \\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* f i \\<and> \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n  hence \"\\<exists>f. f 0 = (cs, css, s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i))\"\n    by (rule renumber [to_pred])\n  moreover from not_inf\n  have \"\\<not> (\\<exists>f. f 0 = (cs, css, s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)))\"\n    by (unfold inf_def)\n  ultimately show False\n    by simp\nqed\n\nlemma wf_implies_termi_reach:\nassumes wf: \"wf {(c2,c1). \\<Gamma> \\<turnstile> (cs,css,s) \\<rightarrow>\\<^sup>* c1 \\<and> \\<Gamma> \\<turnstile> c1 \\<rightarrow> c2}\"\nshows \"\\<And>cs1 css1 s1. \\<lbrakk>\\<Gamma> \\<turnstile> (cs,css,s) \\<rightarrow>\\<^sup>* c1;  c1=(cs1,css1,s1)\\<rbrakk>\\<Longrightarrow> \\<Gamma>\\<turnstile>cs1,css1\\<Down>s1\"\nusing wf \nproof (induct c1, simp)\n  fix cs1 css1 s1\n  assume reach: \"\\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* (cs1, css1, s1)\"\n  assume hyp_raw: \"\\<And>y cs2 css2 s2. \\<lbrakk>\\<Gamma> \\<turnstile> (cs1,css1,s1) \\<rightarrow> (cs2,css2,s2);\n                 \\<Gamma> \\<turnstile> (cs,css,s) \\<rightarrow>\\<^sup>* (cs2,css2,s2); y=(cs2,css2,s2)\\<rbrakk> \\<Longrightarrow> \n                 \\<Gamma>\\<turnstile>cs2,css2\\<Down>s2\"\n  have hyp: \"\\<And>cs2 css2 s2. \\<lbrakk>\\<Gamma> \\<turnstile> (cs1,css1,s1) \\<rightarrow> (cs2,css2,s2)\\<rbrakk> \\<Longrightarrow> \n                 \\<Gamma>\\<turnstile>cs2,css2\\<Down>s2\"\n    apply -\n    apply (rule hyp_raw)\n    apply   assumption\n    using reach \n    apply  simp\n    apply (rule refl)\n    done\n  show \"\\<Gamma>\\<turnstile>cs1,css1\\<Down>s1\"\n  proof (cases s1)\n    case (Normal s1')\n    show ?thesis\n    proof (cases cs1)\n      case Nil\n      note cs1_Nil = this\n      show ?thesis\n      proof (cases css1)\n        case Nil\n        with cs1_Nil show ?thesis\n          by (auto intro: terminatess.intros)\n      next\n        case (Cons nrms_abrs css1')\n        then obtain nrms abrs where nrms_abrs: \"nrms_abrs=(nrms,abrs)\"\n          by (cases \"nrms_abrs\")\n        have \"\\<Gamma> \\<turnstile> ([],(nrms,abrs)#css1',Normal s1') \\<rightarrow> (nrms,css1',Normal s1')\"\n          by (rule step.intros)\n        from hyp [simplified cs1_Nil Cons nrms_abrs Normal, OF this]\n        have \"\\<Gamma>\\<turnstile>nrms,css1'\\<Down>Normal s1'\".\n        from ExitBlockNormal [OF this] cs1_Nil Cons nrms_abrs Normal\n        show ?thesis\n          by auto\n      qed\n    next\n      case (Cons c1 cs1')\n      have \"\\<Gamma>\\<turnstile>c1#cs1',css1\\<Down>Normal s1'\"\n      proof (cases c1)\n        case Skip\n        have \"\\<Gamma> \\<turnstile> (Skip#cs1',css1,Normal s1') \\<rightarrow> (cs1',css1,Normal s1')\"\n          by (rule step.intros)\n        from hyp [simplified Cons Skip Normal, OF this]\n        have \"\\<Gamma>\\<turnstile>cs1',css1\\<Down>Normal s1'\".\n        with Normal Skip show ?thesis\n          by (auto intro: terminatess.intros terminates.intros \n                  elim: exec_Normal_elim_cases)\n      next\n        case (Basic f)\n        have \"\\<Gamma> \\<turnstile> (Basic f#cs1',css1,Normal s1') \\<rightarrow> (cs1',css1,Normal (f s1'))\"\n          by (rule step.intros)\n        from hyp [simplified Cons Basic Normal, OF this]\n        have \"\\<Gamma>\\<turnstile>cs1',css1\\<Down>Normal (f s1')\".\n        with Normal Basic show ?thesis\n          by (auto intro: terminatess.intros terminates.intros \n                  elim: exec_Normal_elim_cases)\n      next\n        case (Spec r)\n        with Normal show ?thesis\n          apply simp\n          apply (rule terminatess.Cons)\n          apply  (fastforce intro: terminates.intros)\n          apply (clarify)\n          apply (erule exec_Normal_elim_cases)\n          apply  clarsimp\n          apply  (rule hyp)\n          apply  (fastforce intro: step.intros simp add: Cons Spec Normal )\n          apply (fastforce intro: terminatess_Stuck)\n          done\n      next\n        case (Seq c\\<^sub>1 c\\<^sub>2)\n        have \"\\<Gamma> \\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2#cs1',css1,Normal s1') \\<rightarrow> (c\\<^sub>1#c\\<^sub>2#cs1',css1,Normal s1')\"\n          by (rule step.intros)\n        from hyp [simplified Cons Seq Normal, OF this]\n        have \"\\<Gamma>\\<turnstile>c\\<^sub>1 # c\\<^sub>2 # cs1',css1\\<Down>Normal s1'\".\n        with Normal Seq show ?thesis\n          by (fastforce intro: terminatess.intros terminates.intros\n                   elim: terminatess_elim_cases exec_Normal_elim_cases)\n      next\n        case (Cond b c\\<^sub>1 c\\<^sub>2)\n        show ?thesis\n        proof (cases \"s1' \\<in> b\")\n          case True\n          hence \"\\<Gamma>\\<turnstile>(Cond b c\\<^sub>1 c\\<^sub>2#cs1',css1,Normal s1') \\<rightarrow> (c\\<^sub>1#cs1',css1,Normal s1')\"\n            by (rule step.intros)\n          from hyp [simplified Cons Cond Normal, OF this]\n          have \"\\<Gamma>\\<turnstile>c\\<^sub>1 # cs1',css1\\<Down>Normal s1'\".\n          with Normal Cond True show ?thesis\n            by (fastforce intro: terminatess.intros terminates.intros\n              elim: terminatess_elim_cases exec_Normal_elim_cases)\n        next\n          case False\n          hence \"\\<Gamma>\\<turnstile>(Cond b c\\<^sub>1 c\\<^sub>2#cs1',css1,Normal s1') \\<rightarrow> (c\\<^sub>2#cs1',css1,Normal s1')\"\n            by (rule step.intros)\n          from hyp [simplified Cons Cond Normal, OF this]\n          have \"\\<Gamma>\\<turnstile>c\\<^sub>2 # cs1',css1\\<Down>Normal s1'\".\n          with Normal Cond False show ?thesis\n            by (fastforce intro: terminatess.intros terminates.intros\n              elim: terminatess_elim_cases exec_Normal_elim_cases)\n        qed\n      next\n        case (While b c')\n        show ?thesis\n        proof (cases \"s1' \\<in> b\")\n          case True\n          then have \"\\<Gamma>\\<turnstile>(While b c' # cs1', css1, Normal s1') \\<rightarrow> \n                       (c' # While b c' # cs1', css1, Normal s1')\"\n            by (rule step.intros)\n          from hyp [simplified Cons While Normal, OF this]\n          have \"\\<Gamma>\\<turnstile>c' # While b c' # cs1',css1\\<Down>Normal s1'\".\n          with Cons While True Normal\n          show ?thesis\n            by (fastforce intro: terminatess.intros terminates.intros exec.intros \n                    elim: terminatess_elim_cases exec_Normal_elim_cases)\n        next\n          case False\n          then \n          have \"\\<Gamma>\\<turnstile>(While b c' # cs1', css1, Normal s1') \\<rightarrow> (cs1', css1, Normal s1')\"\n            by (rule step.intros)\n          from hyp [simplified Cons While Normal, OF this]\n          have \"\\<Gamma>\\<turnstile>cs1',css1\\<Down>Normal s1'\".\n          with Cons While False Normal\n          show ?thesis\n            by (fastforce intro: terminatess.intros terminates.intros exec.intros \n                    elim: terminatess_elim_cases exec_Normal_elim_cases)\n        qed\n      next\n        case (Call p)\n        show ?thesis\n        proof (cases \"\\<Gamma> p\")\n          case None\n          with Call Normal show ?thesis\n            by (fastforce intro: terminatess.intros terminates.intros terminatess_Stuck\n                 elim: exec_Normal_elim_cases)\n        next\n          case (Some bdy)\n          then\n          have \"\\<Gamma> \\<turnstile> (Call p#cs1',css1,Normal s1') \\<rightarrow> \n                    ([bdy],(cs1',Throw#cs1')#css1,Normal s1')\"\n            by (rule step.intros)\n          from hyp [simplified Cons Call Normal Some, OF this]\n          have \"\\<Gamma>\\<turnstile>[bdy],(cs1', Throw # cs1') # css1\\<Down>Normal s1'\".\n          with Some Call Normal show ?thesis\n            apply simp\n            apply (rule terminatess.intros)\n            apply (blast elim: terminatess_elim_cases intro: terminates.intros)\n            apply clarify\n            apply (erule terminatess_elim_cases)\n            apply (erule exec_Normal_elim_cases)\n            prefer 2\n            apply  simp\n            apply (erule_tac x=t in allE)\n            apply (case_tac t)\n            apply (auto intro: terminatess_Stuck terminatess_Fault exec.intros \n                    elim: terminatess_elim_cases exec_Normal_elim_cases)\n            done\n        qed\n      next\n        case (DynCom c')\n        have \"\\<Gamma> \\<turnstile> (DynCom c'#cs1',css1,Normal s1') \\<rightarrow> (c' s1'#cs1',css1,Normal s1')\"\n          by (rule step.intros)\n        from hyp [simplified Cons DynCom Normal, OF this]\n        have \"\\<Gamma>\\<turnstile>c' s1'#cs1',css1\\<Down>Normal s1'\".\n        with Normal DynCom show ?thesis\n          by (fastforce intro: terminatess.intros terminates.intros exec.intros \n                    elim: terminatess_elim_cases exec_Normal_elim_cases)\n      next\n        case (Guard f g c')\n        show ?thesis\n        proof (cases \"s1' \\<in> g\")\n          case True\n          then have \"\\<Gamma> \\<turnstile> (Guard f g c'#cs1',css1,Normal s1') \\<rightarrow> (c'#cs1',css1,Normal s1')\"\n            by (rule step.intros)\n          from hyp [simplified Cons Guard Normal, OF this]\n          have \"\\<Gamma>\\<turnstile>c'#cs1',css1\\<Down>Normal s1'\".\n          with Normal Guard True show ?thesis\n            by (fastforce intro: terminatess.intros terminates.intros exec.intros \n                    elim: terminatess_elim_cases exec_Normal_elim_cases)\n        next\n          case False\n          with Guard Normal show ?thesis\n            by (fastforce intro: terminatess.intros terminatess_Fault \n                                terminates.intros  \n                 elim:  exec_Normal_elim_cases)\n        qed\n      next\n        case Throw\n        have \"\\<Gamma> \\<turnstile> (Throw#cs1',css1,Normal s1') \\<rightarrow> (cs1',css1,Abrupt s1')\"\n          by (rule step.intros)\n        from hyp [simplified Cons Throw Normal, OF this]\n        have \"\\<Gamma>\\<turnstile>cs1',css1\\<Down>Abrupt s1'\".\n        with Normal Throw show ?thesis\n          by (auto intro: terminatess.intros terminates.intros \n                  elim: exec_Normal_elim_cases)\n      next\n        case (Catch c\\<^sub>1 c\\<^sub>2)\n        have \"\\<Gamma> \\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2#cs1',css1,Normal s1') \\<rightarrow> \n                  ([c\\<^sub>1], (cs1',c\\<^sub>2#cs1')# css1,Normal s1')\"\n          by (rule step.intros)\n        from hyp [simplified Cons Catch Normal, OF this]\n        have \"\\<Gamma>\\<turnstile>[c\\<^sub>1],(cs1', c\\<^sub>2 # cs1') # css1\\<Down>Normal s1'\".\n        with Normal Catch show ?thesis\n          by (fastforce intro: terminatess.intros terminates.intros exec.intros \n                    elim: terminatess_elim_cases exec_Normal_elim_cases)\n      qed       \n      with Cons Normal show ?thesis\n        by simp\n    qed\n  next\n    case (Abrupt s1')\n    show ?thesis\n    proof (cases cs1)\n      case Nil\n      note cs1_Nil = this\n      show ?thesis\n      proof (cases css1)\n        case Nil\n        with cs1_Nil show ?thesis by (auto intro: terminatess.intros)\n      next\n        case (Cons nrms_abrs css1')\n        then obtain nrms abrs where nrms_abrs: \"nrms_abrs=(nrms,abrs)\"\n          by (cases \"nrms_abrs\")\n        have \"\\<Gamma> \\<turnstile> ([],(nrms,abrs)#css1',Abrupt s1') \\<rightarrow> (abrs,css1',Normal s1')\"\n          by (rule step.intros)\n        from hyp [simplified cs1_Nil Cons nrms_abrs Abrupt, OF this]\n        have \"\\<Gamma>\\<turnstile>abrs,css1'\\<Down>Normal s1'\".\n        from ExitBlockAbrupt [OF this] cs1_Nil Cons nrms_abrs Abrupt\n        show ?thesis\n          by auto\n      qed\n    next\n      case (Cons c1 cs1')\n      have \"\\<Gamma>\\<turnstile>c1#cs1',css1\\<Down>Abrupt s1'\"\n      proof -\n        have \"\\<Gamma> \\<turnstile> (c1#cs1',css1,Abrupt s1') \\<rightarrow> (cs1',css1,Abrupt s1')\"\n          by (rule step.intros)\n        from hyp [simplified Cons Abrupt, OF this]\n        have \"\\<Gamma>\\<turnstile>cs1',css1\\<Down>Abrupt s1'\".\n        with Cons Abrupt\n        show ?thesis\n          by (fastforce intro: terminatess.intros terminates.intros exec.intros \n                    elim: terminatess_elim_cases exec_Normal_elim_cases)\n      qed\n      with Cons Abrupt show ?thesis by simp\n    qed\n  next\n    case (Fault f)\n    thus ?thesis by (auto intro: terminatess_Fault)\n  next\n    case Stuck\n    thus ?thesis by (auto intro: terminatess_Stuck)\n  qed\nqed\n\nlemma not_inf_impl_terminatess:\n  assumes not_inf: \"\\<not> inf \\<Gamma> cs css s\"\n  shows \"\\<Gamma>\\<turnstile>cs,css\\<Down>s\"\nproof -\n  from not_inf_implies_wf [OF not_inf]\n  have wf: \"wf {(c2, c1). \\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* c1 \\<and> \\<Gamma>\\<turnstile>c1 \\<rightarrow> c2}\".\n  show ?thesis\n    by (rule wf_implies_termi_reach [OF wf]) auto\nqed\n\nlemma not_inf_impl_terminates:\n  assumes not_inf: \"\\<not> inf \\<Gamma> [c] [] s\"\n  shows \"\\<Gamma>\\<turnstile>c\\<down>s\"\nproof -\n  from not_inf_impl_terminatess [OF not_inf]\n  have \"\\<Gamma>\\<turnstile>[c],[]\\<Down>s\".\n  thus ?thesis\n    by (auto elim: terminatess_elim_cases)\nqed\n\ntheorem terminatess_iff_not_inf: \n  \"\\<Gamma>\\<turnstile>cs,css\\<Down>s = (\\<not> inf \\<Gamma> cs css s)\"\n  apply rule\n  apply  (erule terminatess_impl_not_inf)\n  apply (erule not_inf_impl_terminatess)\n  done\n\ncorollary terminates_iff_not_inf: \n  \"\\<Gamma>\\<turnstile>c\\<down>s = (\\<not> inf \\<Gamma> [c] [] s)\"\n  apply (rule)\n  apply  (erule terminates_impl_not_inf)\n  apply (erule not_inf_impl_terminates)\n  done\n\nsubsection {* Completeness of Total Correctness Hoare Logic*}\n\nlemma ConseqMGT: \n  assumes modif: \"\\<forall>Z::'a. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z::'a assn) c (Q' Z),(A' Z)\"\n  assumes impl: \"\\<And>s. s \\<in> P \\<Longrightarrow> s \\<in> P' s \\<and> (\\<forall>t. t \\<in> Q' s \\<longrightarrow> t \\<in> Q) \\<and> \n                                            (\\<forall>t. t \\<in> A' s \\<longrightarrow> t \\<in> A)\"\n  shows \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nusing impl \nby - (rule conseq [OF modif],blast)\n\nlemma conseq_extract_state_indep_prop: \n  assumes state_indep_prop:\"\\<forall>s \\<in> P. R\" \n  assumes to_show: \"R \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule Conseq)\n  apply (clarify)\n  apply (rule_tac x=\"P\" in exI)\n  apply (rule_tac x=\"Q\" in exI)\n  apply (rule_tac x=\"A\" in exI)\n  using state_indep_prop to_show\n  by blast\n\n\n\n\ntext {* To prove a procedure implementation correct it suffices to assume\n       only the procedure specifications of procedures that actually\n       occur during evaluation of the body.  \n    *}\nlemma Call_lemma:\n assumes \n Call: \"\\<forall>q \\<in> dom \\<Gamma>. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> \n                 {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call q\\<down>Normal s \\<and> ((s,q),(\\<sigma>,p)) \\<in> termi_call_steps \\<Gamma>}\n                 (Call q)\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n shows \"\\<And>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>  \n              ({\\<sigma>} \\<inter> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>  \n                                 \\<Gamma>\\<turnstile>the (\\<Gamma> p)\\<down>Normal s}) \n                 the (\\<Gamma> p) \n              {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (rule conseqPre)\napply (rule Call_lemma')\napply (rule Call)\napply blast\ndone\n\nlemma Call_lemma_switch_Call_body:\n assumes \n call: \"\\<forall>q \\<in> dom \\<Gamma>. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> \n                 {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call q\\<down>Normal s \\<and> ((s,q),(\\<sigma>,p)) \\<in> termi_call_steps \\<Gamma>}\n                 (Call q)\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n assumes p_defined: \"p \\<in> dom \\<Gamma>\"\n shows \"\\<And>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>  \n              ({\\<sigma>} \\<inter> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>  \n                                 \\<Gamma>\\<turnstile>Call p\\<down>Normal s}) \n                 the (\\<Gamma> p) \n              {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (simp only: exec_Call_body' [OF p_defined] noFaultStuck_Call_body' [OF p_defined] terminates_Normal_Call_body [OF p_defined])\napply (rule conseqPre)\napply (rule Call_lemma')\napply (rule call)\napply blast\ndone\n\n\nlemma MGT_Call:\n\"\\<forall>p \\<in> dom \\<Gamma>. \\<forall>Z. \n  \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n             \\<Gamma>\\<turnstile>(Call p)\\<down>Normal s}\n           (Call p)\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (intro ballI allI)\napply (rule CallRec' [where Procs=\"dom \\<Gamma>\" and\n    P=\"\\<lambda>p Z. {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call p\\<down>Normal s}\" and\n    Q=\"\\<lambda>p Z. {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t}\" and\n    A=\"\\<lambda>p Z. {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" and\n    r=\"termi_call_steps \\<Gamma>\"\n    ]) \napply    simp\napply   simp\napply  (rule wf_termi_call_steps)\napply (intro ballI allI)\napply simp\napply (rule Call_lemma_switch_Call_body [rule_format, simplified])\napply  (rule hoaret.Asm)\napply  fastforce\napply assumption\ndone\n\n\nlemma CollInt_iff: \"{s. P s} \\<inter> {s. Q s} = {s. P s \\<and> Q s}\"\n  by auto\n\nlemma image_Un_conv: \"f ` (\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. {x p Z}) =  (\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. {f (x p Z)})\"\n  by (auto iff: not_None_eq)\n\n\ntext {* Another proof of @{text MGT_Call}, maybe a little more readable *}\nlemma \n\"\\<forall>p \\<in> dom \\<Gamma>. \\<forall>Z. \n  \\<Gamma>,{} \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n             \\<Gamma>\\<turnstile>(Call p)\\<down>Normal s}\n           (Call p)\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\nproof -\n  {\n    fix p Z \\<sigma>\n    assume defined: \"p \\<in> dom \\<Gamma>\"\n    def Specs == \"(\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. \n            {({s. s=Z \\<and> \n              \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n              \\<Gamma>\\<turnstile>Call p\\<down>Normal s},\n             p,\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})})\"\n    def Specs_wf == \"(\\<lambda>p \\<sigma>. (\\<lambda>(P,q,Q,A). \n                       (P \\<inter> {s. ((s,q),\\<sigma>,p) \\<in> termi_call_steps \\<Gamma>}, q, Q, A)) ` Specs)\"\n    have \"\\<Gamma>,Specs_wf p \\<sigma>\n            \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>({\\<sigma>} \\<inter>\n                 {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                  \\<Gamma>\\<turnstile>the (\\<Gamma> p)\\<down>Normal s}) \n                (the (\\<Gamma> p))\n               {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      apply (rule Call_lemma [rule_format])\n      apply (rule hoaret.Asm)\n      apply (clarsimp simp add: Specs_wf_def Specs_def image_Un_conv)\n      apply (rule_tac x=q in bexI)\n      apply (rule_tac x=Z in exI)\n      apply (clarsimp simp add: CollInt_iff)\n      apply auto\n      done\n    hence \"\\<Gamma>,Specs_wf p \\<sigma>\n            \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>({\\<sigma>} \\<inter>\n                 {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                  \\<Gamma>\\<turnstile>Call p\\<down>Normal s}) \n                (the (\\<Gamma> p))\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      by (simp only: exec_Call_body' [OF defined] \n                   noFaultStuck_Call_body' [OF defined] \n                  terminates_Normal_Call_body [OF defined])\n  } note bdy=this\n  show ?thesis\n    apply (intro ballI allI)\n    apply (rule hoaret.CallRec [where Specs=\"(\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. \n            {({s. s=Z \\<and> \n              \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n              \\<Gamma>\\<turnstile>Call p\\<down>Normal s},\n             p,\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})})\", \n             OF _ wf_termi_call_steps [of \\<Gamma>] refl])\n    apply fastforce\n    apply clarify\n    apply (rule conjI)\n    apply  fastforce\n    apply (rule allI)\n    apply (simp (no_asm_use) only : Un_empty_left)\n    apply (rule bdy)\n    apply auto\n    done\nqed\n\nend", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Simpl/AlternativeSmallStep.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736784220301065, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.2734034621938684}}
{"text": "theory MainTheorems\nimports PathLemmas\nbegin\n\ncontext LocalLexing begin\n\ntheorem \\<II>_is_generated_by_\\<PP>: \"\\<II> = Gen \\<PP>\"\nproof -\n  have \"wellformed_items (\\<I> (length Doc))\"\n    using wellformed_items_\\<I> by auto\n  then have \"\\<And> x. x \\<in> \\<I> (length Doc) \\<Longrightarrow> item_end x \\<le> length Doc\"\n    using wellformed_item_def wellformed_items_def by blast\n  then have \"\\<I> (length Doc) \\<subseteq> items_le (length Doc) (\\<I> (length Doc))\"\n    by (auto simp only: items_le_def)  \n  then have \"\\<I> (length Doc) = items_le (length Doc) (\\<I> (length Doc))\"\n    using items_le_is_filter by blast\n  then have \\<II>_altdef: \"\\<II> = items_le (length Doc) (\\<I> (length Doc))\" using \\<II>_def by auto\n  have \"\\<And> p. p \\<in> (\\<Q> (length Doc)) \\<Longrightarrow> charslength p \\<le> length Doc\"\n    using \\<PP>_are_doc_tokens \\<PP>_def doc_tokens_length by auto\n  then have \"\\<Q> (length Doc) \\<subseteq> paths_le (length Doc) (\\<Q> (length Doc))\"\n    by (auto simp only: paths_le_def)\n  then have \"\\<Q> (length Doc) = paths_le (length Doc) (\\<Q> (length Doc))\"\n    using paths_le_is_filter by blast\n  then have \\<PP>_altdef: \"\\<PP> = paths_le (length Doc) (\\<Q> (length Doc))\" using \\<PP>_def by auto\n  show ?thesis using \\<II>_altdef \\<PP>_altdef thmD14 by auto\nqed\n\ndefinition finished_item :: \"symbol list \\<Rightarrow> item\"\nwhere\n  \"finished_item \\<alpha> = Item (\\<SS>, \\<alpha>) (length \\<alpha>) 0 (length Doc)\"\n\nlemma item_rule_finished_item[simp]: \"item_rule (finished_item \\<alpha>) = (\\<SS>, \\<alpha>)\"\n  by (simp add: finished_item_def)\n\nlemma item_origin_finished_item[simp]: \"item_origin (finished_item \\<alpha>) = 0\"\n  by (simp add: finished_item_def)\n\nlemma item_end_finished_item[simp]: \"item_end (finished_item \\<alpha>) = length Doc\"\n  by (simp add: finished_item_def)\n\nlemma item_dot_finished_item[simp]: \"item_dot (finished_item \\<alpha>) = length \\<alpha>\"\n  by (simp add: finished_item_def)\n\nlemma item_rhs_finished_item[simp]: \"item_rhs (finished_item \\<alpha>) = \\<alpha>\"\n  by (simp add: finished_item_def)\n\nlemma item_\\<alpha>_finished_item[simp]: \"item_\\<alpha> (finished_item \\<alpha>) = \\<alpha>\"\n  by (simp add: finished_item_def item_\\<alpha>_def)\n\nlemma item_nonterminal_finished_item[simp]: \"item_nonterminal (finished_item \\<alpha>) = \\<SS>\"\n  by (simp add: finished_item_def item_nonterminal_def)\n  \nlemma Derives1_of_singleton:\n  assumes \"Derives1 [N] i r \\<alpha>\"\n  shows \"i = 0 \\<and> r = (N, \\<alpha>)\"\nproof -\n  from assms have \"i = 0\" using Derives1_bound\n    using length_Cons less_Suc0 list.size(3) by fastforce \n  then show ?thesis using assms\n    using Derives1_def append_Cons append_self_conv append_self_conv2 length_0_conv \n      list.inject by auto\nqed    \n\ndefinition pvalid_with :: \"tokens \\<Rightarrow> item \\<Rightarrow> nat \\<Rightarrow> symbol list \\<Rightarrow> bool\"\nwhere\n  \"pvalid_with p x u \\<gamma> = \n     (wellformed_tokens p \\<and>\n     wellformed_item x \\<and>\n     u \\<le> length p \\<and>\n     charslength p = item_end x \\<and>\n     charslength (take u p) = item_origin x \\<and>\n     is_derivation (terminals (take u p) @ [item_nonterminal x] @ \\<gamma>) \\<and>\n     derives (item_\\<alpha> x) (terminals (drop u p)))\"\n\nlemma pvalid_with: \"pvalid p x = (\\<exists> u \\<gamma>. pvalid_with p x u \\<gamma>)\"\n  using pvalid_def pvalid_with_def by blast\n\ntheorem Completeness:\n  assumes p_in_ll: \"p \\<in> ll\"\n  shows \"\\<exists> \\<alpha>. pvalid_with p (finished_item \\<alpha>) 0 [] \\<and> finished_item \\<alpha> \\<in> \\<II>\"\nproof -\n  have p: \"p \\<in> \\<PP> \\<and> charslength p = length Doc \\<and> terminals p \\<in> \\<L>\"\n    using p_in_ll ll_def by auto\n  then have derives_p: \"derives [\\<SS>] (terminals p)\"\n    using \\<L>_def is_derivation_def mem_Collect_eq by blast\n  then have \"\\<exists> D. Derivation [\\<SS>] D (terminals p)\"\n    by (simp add: derives_implies_Derivation)   \n  then obtain D where D: \"Derivation [\\<SS>] D (terminals p)\" by blast\n  have is_word_p: \"is_word (terminals p)\"  using leftlang p by blast\n  have not_is_word_\\<SS>: \"\\<not> (is_word [\\<SS>])\" using is_nonterminal_startsymbol is_terminal_nonterminal \n    is_word_cons by blast  \n  have \"D \\<noteq> []\" using D is_word_p not_is_word_\\<SS> using Derivation.simps(1) by force\n  then have \"\\<exists> d D'. D = d#D'\" using D Derivation.elims(2) by blast \n  then obtain d D' where d: \"D = d#D'\" by blast\n  have \"\\<exists> \\<alpha>. Derives1 [\\<SS>] (fst d) (snd d) \\<alpha> \\<and> derives \\<alpha> (terminals p)\"\n    using d D Derivation.simps(2) Derivation_implies_derives by blast \n  then obtain \\<alpha> where \\<alpha>: \"Derives1 [\\<SS>] (fst d) (snd d) \\<alpha> \\<and> derives \\<alpha> (terminals p)\" by blast\n  then have snd_d_in_\\<RR>: \"snd d \\<in> \\<RR>\" using Derives1_rule by blast \n  with \\<alpha> have snd_d: \"snd d = (\\<SS>, \\<alpha>)\" using Derives1_of_singleton by blast\n  have wellformed_p: \"wellformed_tokens p\" by (simp add: \\<PP>_wellformed p)\n  have wellformed_finished_item: \"wellformed_item (finished_item \\<alpha>)\"  \n    apply (auto simp add: wellformed_item_def)\n    using snd_d snd_d_in_\\<RR> by metis    \n  have pvalid_with: \"pvalid_with p (finished_item \\<alpha>) 0 []\" \n    apply (auto simp add: pvalid_with_def)\n    using wellformed_p apply blast\n    using wellformed_finished_item apply blast\n    using p apply (simp add: finished_item_def)\n    apply (simp add: is_derivation_def)\n    by (simp add: \\<alpha>)\n  then have \"pvalid p (finished_item \\<alpha>)\" using pvalid_def pvalid_with_def by blast \n  then have \"finished_item \\<alpha> \\<in> Gen \\<PP>\" using Gen_def mem_Collect_eq p by blast\n  then have \"finished_item \\<alpha> \\<in> \\<II>\" using \\<II>_is_generated_by_\\<PP> by blast \n  with pvalid_with show ?thesis by blast\nqed\n  \ntheorem Soundness:\n  assumes finished_item_\\<alpha>: \"finished_item \\<alpha> \\<in> \\<II>\"\n  shows \"\\<exists> p. pvalid_with p (finished_item \\<alpha>) 0 [] \\<and> p \\<in> ll\"\nproof -\n  have \"finished_item \\<alpha> \\<in> Gen \\<PP>\"\n    using \\<II>_is_generated_by_\\<PP> finished_item_\\<alpha> by auto \n  then obtain p where p: \"p \\<in> \\<PP> \\<and> pvalid p (finished_item \\<alpha>)\"\n    using Gen_implies_pvalid by blast \n  have pvalid_p_finished_item: \"pvalid  p (finished_item \\<alpha>)\" using p by blast\n  from iffD1[OF pvalid_def this, simplified] obtain r \\<gamma> where pvalid:\n    \"wellformed_tokens p \\<and>\n     wellformed_item (finished_item \\<alpha>) \\<and>\n     r \\<le> length p \\<and>\n     length (chars p) = length Doc \\<and>\n     chars (take r p) = [] \\<and>\n     is_derivation (take r (terminals p) @ \\<SS> # \\<gamma>) \\<and> derives \\<alpha> (drop r (terminals p))\"\n     by  blast\n  have \"item_rule (finished_item \\<alpha>) \\<in> \\<RR>\" using pvalid\n    using wellformed_item_def by blast\n  then have \"(\\<SS>, \\<alpha>) \\<in> \\<RR>\" by simp \n  then have is_derivation_\\<alpha>: \"is_derivation \\<alpha>\" by (simp add: is_derivation_def leftderives_rule)\n  have drop_r_p_in_\\<PP>: \"drop r p \\<in> \\<PP>\"\n    apply (rule drop_empty_tokens)\n    using p apply blast\n    using pvalid apply blast\n    using pvalid apply simp\n    by (metis append_Nil2 derives_trans is_derivation_\\<alpha> is_derivation_def \n      is_derivation_implies_admissible is_word_terminals_drop pvalid terminals_drop)\n  then have in_ll: \"drop r p \\<in> ll\"\n    apply (auto simp add: ll_def) \n    apply (metis append_Nil append_take_drop_id chars_append pvalid) \n    using is_derivation_\\<alpha> pvalid\n    by (metis (no_types, lifting) \\<L>_def derives_trans is_derivation_def \n      is_word_terminals_drop mem_Collect_eq terminals_drop)\n  have \"pvalid_with (drop r p) (finished_item \\<alpha>) 0 []\"\n    apply (auto simp add: pvalid_with_def)\n    using \\<PP>_wellformed drop_r_p_in_\\<PP> apply blast \n    using pvalid apply blast\n    apply (metis append_Nil append_take_drop_id chars_append pvalid)\n    apply (simp add: is_derivation_def)\n    using pvalid by blast\n  with in_ll show ?thesis by auto\nqed\n\nlemma is_finished_and_finished_item:\n  assumes wellformed_x: \"wellformed_item x\"\n  shows \"is_finished x = (\\<exists> \\<alpha>. x = finished_item \\<alpha>)\"\nproof -\n  {\n    assume is_finished_x: \"is_finished x\"\n    obtain \\<alpha> where \\<alpha>: \"\\<alpha> = item_rhs x\" by blast\n    have \"x = finished_item \\<alpha>\"\n      apply (rule item.expand)\n      apply auto\n      using \\<alpha> is_finished_def is_finished_x item_nonterminal_def item_rhs_def apply auto[1]\n      using \\<alpha> assms is_complete_def is_finished_def is_finished_x wellformed_item_def apply auto[1]\n      using is_finished_def is_finished_x apply blast\n      using is_finished_def is_finished_x by auto\n    then have \"\\<exists> \\<alpha>. x = finished_item \\<alpha>\" by blast\n  }\n  note left_implies_right = this\n  {\n    assume \"\\<exists> \\<alpha>. x = finished_item \\<alpha>\"\n    then obtain \\<alpha> where \\<alpha>: \"x = finished_item \\<alpha>\" by blast\n    have \"is_finished x\" by (simp add: \\<alpha> is_finished_def is_complete_def)\n  }\n  note right_implies_left = this\n  show ?thesis using left_implies_right right_implies_left by blast\nqed \n\ntheorem Correctness:\n  shows \"(ll \\<noteq> {}) = earley_recognised\"\nproof -\n  have 1: \"(ll \\<noteq> {}) = (\\<exists> \\<alpha>. finished_item \\<alpha> \\<in> \\<II>)\"\n    using Soundness Completeness ex_in_conv by fastforce\n  have 2: \"(\\<exists> \\<alpha>. finished_item \\<alpha> \\<in> \\<II>) = (\\<exists> x \\<in> \\<II>. is_finished x)\"\n    using \\<II>_def is_finished_and_finished_item wellformed_items_\\<I> wellformed_items_def by auto\n  show ?thesis using earley_recognised_def 1 2 by blast\nqed \n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/LocalLexing/MainTheorems.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.27340345524648235}}
{"text": "(*** This file is part of Lem.  eth-isabelle project just uses it.  See lem-license. ***)\n\nchapter {* Generated by Lem from list.lem. *}\n\ntheory \"Lem_list\" \n\nimports \n \t Main\n\t \"Lem_bool\" \n\t \"Lem_maybe\" \n\t \"Lem_basic_classes\" \n\t \"Lem_function\" \n\t \"Lem_tuple\" \n\t \"Lem_num\" \n\t \"Lem\"\n\nbegin \n\n \n\n(*open import Bool Maybe Basic_classes Function Tuple Num*)\n\n(*open import {coq} `Coq.Lists.List`*)\n(*open import {isabelle} `$LIB_DIR/Lem`*)\n(*open import {hol} `lemTheory` `listTheory` `rich_listTheory` `sortingTheory`*)\n\n(* ========================================================================== *)\n(* Basic list functions                                                       *)\n(* ========================================================================== *)\n\n(* The type of lists as well as list literals like [], [1;2], ... are hardcoded. \n   Thus, we can directly dive into derived definitions. *)\n\n\n(* ----------------------- *)\n(* cons                    *)\n(* ----------------------- *)\n\n(*val :: : forall 'a. 'a -> list 'a -> list 'a*)\n\n\n(* ----------------------- *)\n(* Emptyness check         *)\n(* ----------------------- *)\n\n(*val null : forall 'a. list 'a -> bool*)\n(*let null l=  match l with [] -> true | _ -> false end*)\n\n(* ----------------------- *)\n(* Length                  *)\n(* ----------------------- *)\n\n(*val length : forall 'a. list 'a -> nat*)\n(*let rec length l= \n  match l with\n    | [] -> 0\n    | x :: xs -> (Instance_Num_NumAdd_nat.+) (length xs) 1\n  end*)\n\n(* ----------------------- *)\n(* Equality                *)\n(* ----------------------- *)\n\n(*val listEqual : forall 'a. Eq 'a => list 'a -> list 'a -> bool*)\n(*val listEqualBy : forall 'a. ('a -> 'a -> bool) -> list 'a -> list 'a -> bool*)\n\nfun  listEqualBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list \\<Rightarrow> bool \"  where \n     \" listEqualBy eq ([]) ([]) = ( True )\"\n|\" listEqualBy eq ([]) (_ # _) = ( False )\"\n|\" listEqualBy eq (_ # _) ([]) = ( False )\"\n|\" listEqualBy eq (x # xs) (y # ys) = ( (eq x y \\<and> listEqualBy eq xs ys))\" \ndeclare listEqualBy.simps [simp del]\n\n\n\n(* ----------------------- *)\n(* compare                 *)\n(* ----------------------- *)\n\n(*val lexicographicCompare : forall 'a. Ord 'a => list 'a -> list 'a -> ordering*)\n(*val lexicographicCompareBy : forall 'a. ('a -> 'a -> ordering) -> list 'a -> list 'a -> ordering*)\n\nfun  lexicographicCompareBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> ordering)\\<Rightarrow> 'a list \\<Rightarrow> 'a list \\<Rightarrow> ordering \"  where \n     \" lexicographicCompareBy cmp ([]) ([]) = ( EQ )\"\n|\" lexicographicCompareBy cmp ([]) (_ # _) = ( LT )\"\n|\" lexicographicCompareBy cmp (_ # _) ([]) = ( GT )\"\n|\" lexicographicCompareBy cmp (x # xs) (y # ys) = ( (\n      (case  cmp x y of \n          LT => LT\n        | GT => GT\n        | EQ => lexicographicCompareBy cmp xs ys\n      )\n    ))\" \ndeclare lexicographicCompareBy.simps [simp del]\n\n\n(*val lexicographicLess : forall 'a. Ord 'a => list 'a -> list 'a -> bool*)\n(*val lexicographicLessBy : forall 'a. ('a -> 'a -> bool) -> ('a -> 'a -> bool) -> list 'a -> list 'a -> bool*)\nfun  lexicographicLessBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow>('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list \\<Rightarrow> bool \"  where \n     \" lexicographicLessBy less1 less_eq1 ([]) ([]) = ( False )\"\n|\" lexicographicLessBy less1 less_eq1 ([]) (_ # _) = ( True )\"\n|\" lexicographicLessBy less1 less_eq1 (_ # _) ([]) = ( False )\"\n|\" lexicographicLessBy less1 less_eq1 (x # xs) (y # ys) = ( ((less1 x y) \\<or> ((less_eq1 x y) \\<and> (lexicographicLessBy less1 less_eq1 xs ys))))\" \ndeclare lexicographicLessBy.simps [simp del]\n\n\n(*val lexicographicLessEq : forall 'a. Ord 'a => list 'a -> list 'a -> bool*)\n(*val lexicographicLessEqBy : forall 'a. ('a -> 'a -> bool) -> ('a -> 'a -> bool) -> list 'a -> list 'a -> bool*)\nfun  lexicographicLessEqBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow>('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list \\<Rightarrow> bool \"  where \n     \" lexicographicLessEqBy less1 less_eq1 ([]) ([]) = ( True )\"\n|\" lexicographicLessEqBy less1 less_eq1 ([]) (_ # _) = ( True )\"\n|\" lexicographicLessEqBy less1 less_eq1 (_ # _) ([]) = ( False )\"\n|\" lexicographicLessEqBy less1 less_eq1 (x # xs) (y # ys) = ( (less1 x y \\<or> (less_eq1 x y \\<and> lexicographicLessEqBy less1 less_eq1 xs ys)))\" \ndeclare lexicographicLessEqBy.simps [simp del]\n\n\n\ndefinition instance_Basic_classes_Ord_list_dict  :: \" 'a Ord_class \\<Rightarrow>('a list)Ord_class \"  where \n     \" instance_Basic_classes_Ord_list_dict dict_Basic_classes_Ord_a = ((|\n\n  compare_method = (lexicographicCompareBy \n  (compare_method   dict_Basic_classes_Ord_a)),\n\n  isLess_method = (lexicographicLessBy \n  (isLess_method   dict_Basic_classes_Ord_a) (isLessEqual_method   dict_Basic_classes_Ord_a)),\n\n  isLessEqual_method = (lexicographicLessEqBy \n  (isLess_method   dict_Basic_classes_Ord_a) (isLessEqual_method   dict_Basic_classes_Ord_a)),\n\n  isGreater_method = (\\<lambda> x y. (lexicographicLessBy \n  (isLess_method   dict_Basic_classes_Ord_a) (isLessEqual_method   dict_Basic_classes_Ord_a) y x)),\n\n  isGreaterEqual_method = (\\<lambda> x y. (lexicographicLessEqBy \n  (isLess_method   dict_Basic_classes_Ord_a) (isLessEqual_method   dict_Basic_classes_Ord_a) y x))|) )\"\n\n\n\n(* ----------------------- *)\n(* Append                  *)\n(* ----------------------- *)\n\n(*val ++ : forall 'a. list 'a -> list 'a -> list 'a*) (* originally append *)\n(*let rec ++ xs ys=  match xs with\n                     | [] -> ys\n                     | x :: xs' -> x :: (xs' ++ ys)\n                   end*)\n\n(* ----------------------- *)\n(* snoc                    *)\n(* ----------------------- *)\n\n(*val snoc : forall 'a. 'a -> list 'a -> list 'a*)\n(*let snoc e l=  l ++ [e]*)\n\n\n(* ----------------------- *)\n(* Reverse                 *)\n(* ----------------------- *)\n\n(* First lets define the function [reverse_append], which is\n   closely related to reverse. [reverse_append l1 l2] appends the list [l2] to the reverse of [l1].\n   This can be implemented more efficienctly than appending and is\n   used to implement reverse. *)\n\n(*val reverseAppend : forall 'a. list 'a -> list 'a -> list 'a*) (* originally named rev_append *)\n(*let rec reverseAppend l1 l2=  match l1 with \n                                | [] -> l2\n                                | x :: xs -> reverseAppend xs (x :: l2)\n                               end*)\n\n(* Reversing a list *)\n(*val reverse : forall 'a. list 'a -> list 'a*) (* originally named rev *)\n(*let reverse l=  reverseAppend l []*)\n\n(* ----------------------- *)\n(* Map                     *)\n(* ----------------------- *)\n\n(*val map_tr : forall 'a 'b. list 'b -> ('a -> 'b) -> list 'a -> list 'b*)\nfunction (sequential,domintros)  map_tr  :: \" 'b list \\<Rightarrow>('a \\<Rightarrow> 'b)\\<Rightarrow> 'a list \\<Rightarrow> 'b list \"  where \n     \" map_tr rev_acc f ([]) = ( List.rev rev_acc )\"\n|\" map_tr rev_acc f (x # xs) = ( map_tr ((f x) # rev_acc) f xs )\" \nby pat_completeness auto\n\n\n(* taken from: https://blogs.janestreet.com/optimizing-list-map/ *)\n(*val count_map : forall 'a 'b. ('a -> 'b) -> list 'a -> nat -> list 'b*)\nfunction (sequential,domintros)  count_map  :: \"('a \\<Rightarrow> 'b)\\<Rightarrow> 'a list \\<Rightarrow> nat \\<Rightarrow> 'b list \"  where \n     \" count_map f ([]) ctr = ( [])\"\n|\" count_map f (hd1 # tl1) ctr = ( f hd1 # \n    (if ctr <( 5000 :: nat) then count_map f tl1 (ctr +( 1 :: nat)) \n    else map_tr [] f tl1))\" \nby pat_completeness auto\n\n \n(*val map : forall 'a 'b. ('a -> 'b) -> list 'a -> list 'b*)\n(*let map f l=  count_map f l 0*)\n\n(* ----------------------- *)\n(* Reverse Map             *)\n(* ----------------------- *)\n\n(*val reverseMap : forall 'a 'b. ('a -> 'b) -> list 'a -> list 'b*)\n\n\n(* ========================================================================== *)\n(* Folding                                                                    *)\n(* ========================================================================== *)\n\n(* ----------------------- *)\n(* fold left               *)\n(* ----------------------- *)\n\n(*val foldl : forall 'a 'b. ('a -> 'b -> 'a) -> 'a -> list 'b -> 'a*) (* originally foldl *)\n\n(*let rec foldl f b l=  match l with\n  | []      -> b\n  | x :: xs -> foldl f (f b x) xs\nend*)\n\n\n(* ----------------------- *)\n(* fold right              *)\n(* ----------------------- *)\n\n(*val foldr : forall 'a 'b. ('a -> 'b -> 'b) -> 'b -> list 'a -> 'b*) (* originally foldr with different argument order *)\n(*let rec foldr f b l=  match l with\n  | []      -> b\n  | x :: xs -> f x (foldr f b xs)\nend*)\n\n\n(* ----------------------- *)\n(* concatenating lists     *)\n(* ----------------------- *)\n\n(*val concat : forall 'a. list (list 'a) -> list 'a*) (* before also called flatten *)\n(*let concat=  foldr (++) []*)\n\n\n(* -------------------------- *)\n(* concatenating with mapping *)\n(* -------------------------- *)\n\n(*val concatMap : forall 'a 'b. ('a -> list 'b) -> list 'a -> list 'b*)\n\n\n(* ------------------------- *)\n(* universal qualification   *)\n(* ------------------------- *)\n\n(*val all : forall 'a. ('a -> bool) -> list 'a -> bool*) (* originally for_all *)\n(*let all P l=  foldl (fun r e -> P e && r) true l*)\n\n\n\n(* ------------------------- *)\n(* existential qualification *)\n(* ------------------------- *)\n\n(*val any : forall 'a. ('a -> bool) -> list 'a -> bool*) (* originally exist *)\n(*let any P l=  foldl (fun r e -> P e || r) false l*)\n\n\n(* ------------------------- *)\n(* dest_init                 *)\n(* ------------------------- *)\n\n(* get the initial part and the last element of the list in a safe way *)\n\n(*val dest_init : forall 'a. list 'a -> maybe (list 'a * 'a)*) \n\nfun  dest_init_aux  :: \" 'a list \\<Rightarrow> 'a \\<Rightarrow> 'a list \\<Rightarrow> 'a list*'a \"  where \n     \" dest_init_aux rev_init last_elem_seen ([]) = ( (List.rev rev_init, last_elem_seen))\"\n|\" dest_init_aux rev_init last_elem_seen (x # xs) = ( dest_init_aux (last_elem_seen # rev_init) x xs )\" \ndeclare dest_init_aux.simps [simp del]\n\n\nfun dest_init  :: \" 'a list \\<Rightarrow>('a list*'a)option \"  where \n     \" dest_init ([]) = ( None )\"\n|\" dest_init (x # xs) = ( Some (dest_init_aux [] x xs))\" \ndeclare dest_init.simps [simp del]\n\n\n\n(* ========================================================================== *)\n(* Indexing lists                                                             *)\n(* ========================================================================== *)\n\n(* ------------------------- *)\n(* index / nth with maybe   *)\n(* ------------------------- *)\n\n(*val index : forall 'a. list 'a -> nat -> maybe 'a*)\n\n(*let rec index l n=  match l with \n  | []      -> Nothing\n  | x :: xs -> if (Instance_Basic_classes_Eq_nat.=) n 0 then Just x else index xs ((Instance_Num_NumMinus_nat.-)n 1)\nend*)\n\n(* ------------------------- *)\n(* findIndices               *)\n(* ------------------------- *)\n\n(* [findIndices P l] returns the indices of all elements of list [l] that satisfy predicate [P]. \n   Counting starts with 0, the result list is sorted ascendingly *)\n(*val findIndices : forall 'a. ('a -> bool) -> list 'a -> list nat*)\n\nfun  findIndices_aux  :: \" nat \\<Rightarrow>('a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow>(nat)list \"  where \n     \" findIndices_aux (i::nat) P ([]) = ( [])\"\n|\" findIndices_aux (i::nat) P (x # xs) = ( if P x then i # findIndices_aux (i +( 1 :: nat)) P xs else findIndices_aux (i +( 1 :: nat)) P xs )\" \ndeclare findIndices_aux.simps [simp del]\n\n(*let findIndices P l=  findIndices_aux 0 P l*)\n\n\n\n(* ------------------------- *)\n(* findIndex                 *)\n(* ------------------------- *)\n\n(* findIndex returns the first index of a list that satisfies a given predicate. *)\n(*val findIndex : forall 'a. ('a -> bool) -> list 'a -> maybe nat*)\n(*let findIndex P l=  match findIndices P l with\n  | [] -> Nothing\n  | x :: _ -> Just x\nend*)\n\n(* ------------------------- *)\n(* elemIndices               *)\n(* ------------------------- *)\n\n(*val elemIndices : forall 'a. Eq 'a => 'a -> list 'a -> list nat*)\n\n(* ------------------------- *)\n(* elemIndex                 *)\n(* ------------------------- *)\n\n(*val elemIndex : forall 'a. Eq 'a => 'a -> list 'a -> maybe nat*)\n\n\n(* ========================================================================== *)\n(* Creating lists                                                             *)\n(* ========================================================================== *)\n\n(* ------------------------- *)\n(* genlist                   *)\n(* ------------------------- *)\n\n(* [genlist f n] generates the list [f 0; f 1; ... (f (n-1))] *)\n(*val genlist : forall 'a. (nat -> 'a) -> nat -> list 'a*)\n\n\n(*let rec genlist f n= \n  match n with\n    | 0 -> []\n    | n' + 1 -> snoc (f n') (genlist f n')\n  end*)\n\n\n(* ------------------------- *)\n(* replicate                 *)\n(* ------------------------- *)\n\n(*val replicate : forall 'a. nat -> 'a -> list 'a*)\n(*let rec replicate n x= \n  match n with\n    | 0 -> []\n    | n' + 1 -> x :: replicate n' x\n  end*)\n\n\n(* ========================================================================== *)\n(* Sublists                                                                   *)\n(* ========================================================================== *)\n\n(* ------------------------- *)\n(* splitAt                   *)\n(* ------------------------- *)\n\n(* [splitAt n xs] returns a tuple (xs1, xs2), with append xs1 xs2 = xs and \n   length xs1 = n. If there are not enough elements \n   in [xs], the original list and the empty one are returned. *)\n(*val splitAtAcc : forall 'a. list 'a -> nat -> list 'a -> (list 'a * list 'a)*)\nfunction (sequential,domintros)  splitAtAcc  :: \" 'a list \\<Rightarrow> nat \\<Rightarrow> 'a list \\<Rightarrow> 'a list*'a list \"  where \n     \" splitAtAcc revAcc n l = ( \n  (case  l of\n      []    => (List.rev revAcc, [])\n    | x # xs => if n \\<le>( 0 :: nat) then (List.rev revAcc, l) else splitAtAcc (x # revAcc) (n-( 1 :: nat)) xs\n  ))\" \nby pat_completeness auto\n\n\n(*val splitAt : forall 'a. nat -> list 'a -> (list 'a * list 'a)*)\n(*let rec splitAt n l=  \n   splitAtAcc [] n l*)\n\n\n(* ------------------------- *)\n(* take                      *)\n(* ------------------------- *)\n\n(* take n xs returns the prefix of xs of length n, or xs itself if n > length xs *)\n(*val take : forall 'a. nat -> list 'a -> list 'a*)\n(*let take n l=  fst (splitAt n l)*)\n\n\n\n(* ------------------------- *)\n(* drop                      *)\n(* ------------------------- *)\n\n(* [drop n xs] drops the first [n] elements of [xs]. It returns the empty list, if [n] > [length xs]. *)\n(*val drop : forall 'a. nat -> list 'a -> list 'a*)\n(*let drop n l=  snd (splitAt n l)*)\n\n(* ------------------------- *)\n(* dropWhile                 *)\n(* ------------------------- *)\n\n(* [dropWhile p xs] drops the first elements of [xs] that satisfy [p]. *)\n(*val dropWhile : forall 'a. ('a -> bool) -> list 'a -> list 'a*)\nfun  dropWhile  :: \"('a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list \"  where \n     \" dropWhile p l = ( (case  l of \n    [] => []\n  | x # xs => if p x then dropWhile p xs else l\n))\" \ndeclare dropWhile.simps [simp del]\n\n\n\n(* ------------------------- *)\n(* takeWhile                 *)\n(* ------------------------- *)\n\n(* [takeWhile p xs] takes the first elements of [xs] that satisfy [p]. *)\n(*val takeWhile : forall 'a. ('a -> bool) -> list 'a -> list 'a*)\nfun  takeWhile  :: \"('a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list \"  where \n     \" takeWhile p ([]) = ( [])\"\n|\" takeWhile p (x # xs) = ( if p x then x # takeWhile p xs else [])\" \ndeclare takeWhile.simps [simp del]\n\n\n(* ------------------------- *)\n(* splitWhile                *)\n(* ------------------------- *)\n\n(*val splitWhile : forall 'a. ('a -> bool) -> list 'a -> (list 'a * list 'a)*)\ndefinition splitWhile  :: \"('a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list*'a list \"  where \n     \" splitWhile p xs = ( (takeWhile p xs, dropWhile p xs))\"\n\n\n\n(* ------------------------- *)\n(* isPrefixOf                *)\n(* ------------------------- *)\n\n(*val isPrefixOf : forall 'a. Eq 'a => list 'a -> list 'a -> bool*)\nfun  isPrefixOf  :: \" 'a list \\<Rightarrow> 'a list \\<Rightarrow> bool \"  where \n     \" isPrefixOf ([]) _ = ( True )\"\n|\" isPrefixOf (_ # _) ([]) = ( False )\"\n|\" isPrefixOf (x # xs) (y # ys) = ( (x = y) \\<and> isPrefixOf xs ys )\" \ndeclare isPrefixOf.simps [simp del]\n\n\n(* ------------------------- *)\n(* update                    *)\n(* ------------------------- *)\n(*val update : forall 'a. list 'a -> nat -> 'a -> list 'a*)\n(*let rec update l n e=  \n  match l with\n    | []      -> []\n    | x :: xs -> if (Instance_Basic_classes_Eq_nat.=) n 0 then e :: xs else x :: (update xs ((Instance_Num_NumMinus_nat.-) n 1) e)\nend*)\n\n\n\n(* ========================================================================== *)\n(* Searching lists                                                            *)\n(* ========================================================================== *)\n\n(* ------------------------- *)\n(* Membership test           *)\n(* ------------------------- *)\n\n(* The membership test, one of the basic list functions, is actually tricky for\n   Lem, because it is tricky, which equality to use. From Lem`s point of \n   perspective, we want to use the equality provided by the equality type - class.\n   This allows for example to check whether a set is in a list of sets.\n\n   However, in order to use the equality type class, elem essentially becomes\n   existential quantification over lists. For types, which implement semantic\n   equality (=) with syntactic equality, this is overly complicated. In\n   our theorem prover backend, we would end up with overly complicated, harder\n   to read definitions and some of the automation would be harder to apply.\n   Moreover, nearly all the old Lem generated code would change and require \n   (hopefully minor) adaptions of proofs.\n\n   For now, we ignore this problem and just demand, that all instances of\n   the equality type class do the right thing for the theorem prover backends.   \n*)\n\n(*val elem : forall 'a. Eq 'a => 'a -> list 'a -> bool*)\n(*val elemBy : forall 'a. ('a -> 'a -> bool) -> 'a -> list 'a -> bool*)\n\ndefinition elemBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow> 'a \\<Rightarrow> 'a list \\<Rightarrow> bool \"  where \n     \" elemBy eq e l = ( ((\\<exists> x \\<in> (set l).  (eq e) x)))\"\n\n(*let elem=  elemBy (=)*)\n\n(* ------------------------- *)\n(* Find                      *)\n(* ------------------------- *)\n(*val find : forall 'a. ('a -> bool) -> list 'a -> maybe 'a*) (* previously not of maybe type *)\n(*let rec find P l=  match l with \n  | []      -> Nothing\n  | x :: xs -> if P x then Just x else find P xs\nend*)\n\n\n(* ----------------------------- *)\n(* Lookup in an associative list *)\n(* ----------------------------- *)\n(*val lookup   : forall 'a 'b. Eq 'a              => 'a -> list ('a * 'b) -> maybe 'b*)\n(*val lookupBy : forall 'a 'b. ('a -> 'a -> bool) -> 'a -> list ('a * 'b) -> maybe 'b*)\n\n(* DPM: eta-expansion for Coq backend type-inference. *)\ndefinition lookupBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow> 'a \\<Rightarrow>('a*'b)list \\<Rightarrow> 'b option \"  where \n     \" lookupBy eq k m = ( map_option (\\<lambda> x .  snd x) (List.find (\\<lambda> (k', _) .  eq k k') m))\"\n\n\n(* ------------------------- *)\n(* filter                    *)\n(* ------------------------- *)\n(*val filter : forall 'a. ('a -> bool) -> list 'a -> list 'a*)\n(*let rec filter P l=  match l with\n                       | [] -> []\n                       | x :: xs -> if (P x) then x :: (filter P xs) else filter P xs\n                     end*)\n\n\n(* ------------------------- *)\n(* partition                 *)\n(* ------------------------- *)\n(*val partition : forall 'a. ('a -> bool) -> list 'a -> list 'a * list 'a*)\n(*let partition P l=  (filter P l, filter (fun x -> not (P x)) l)*)\n\n(*val reversePartition : forall 'a. ('a -> bool) -> list 'a -> list 'a * list 'a*)\ndefinition reversePartition  :: \"('a \\<Rightarrow> bool)\\<Rightarrow> 'a list \\<Rightarrow> 'a list*'a list \"  where \n     \" reversePartition P l = ( List.partition P (List.rev l))\"\n\n\n\n(* ------------------------- *)\n(* delete first element      *)\n(* with certain property     *)\n(* ------------------------- *)\n\n(*val deleteFirst : forall 'a. ('a -> bool) -> list 'a -> maybe (list 'a)*) \n(*let rec deleteFirst P l=  match l with\n                            | [] -> Nothing\n                            | x :: xs -> if (P x) then Just xs else Maybe.map (fun xs' -> x :: xs') (deleteFirst P xs)\n                          end*)\n\n\n(*val delete : forall 'a. Eq 'a => 'a -> list 'a -> list 'a*)\n(*val deleteBy : forall 'a. ('a -> 'a -> bool) -> 'a -> list 'a -> list 'a*)\n\ndefinition deleteBy  :: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool)\\<Rightarrow> 'a \\<Rightarrow> 'a list \\<Rightarrow> 'a list \"  where \n     \" deleteBy eq x l = ( case_option l id (delete_first (eq x) l))\"\n\n\n\n(* ========================================================================== *)\n(* Zipping and unzipping lists                                                *)\n(* ========================================================================== *)\n\n(* ------------------------- *)\n(* zip                       *)\n(* ------------------------- *)\n\n(* zip takes two lists and returns a list of corresponding pairs. If one input list is short, excess elements of the longer list are discarded. *)\n(*val zip : forall 'a 'b. list 'a -> list 'b -> list ('a * 'b)*) (* before combine *)\n(*let rec zip l1 l2=  match (l1, l2) with\n  | (x :: xs, y :: ys) -> (x, y) :: zip xs ys\n  | _ -> []\nend*)\n\n(* ------------------------- *)\n(* unzip                     *)\n(* ------------------------- *)\n\n(*val unzip: forall 'a 'b. list ('a * 'b) -> (list 'a * list 'b)*)\n(*let rec unzip l=  match l with\n  | [] -> ([], [])\n  | (x, y) :: xys -> let (xs, ys) = unzip xys in (x :: xs, y :: ys)\nend*)\n\n(* ------------------------- *)\n(* distinct elements         *)\n(* ------------------------- *)\n\n(*val allDistinct : forall 'a. Eq 'a => list 'a -> bool*)\nfun  allDistinct  :: \" 'a list \\<Rightarrow> bool \"  where \n     \" allDistinct ([]) = ( True )\"\n|\" allDistinct (x # l') = ( \\<not> (Set.member x (set l')) \\<and> allDistinct l' )\" \ndeclare allDistinct.simps [simp del]\n\n\n(* some more useful functions *)\n(*val mapMaybe : forall 'a 'b. ('a -> maybe 'b) -> list 'a -> list 'b*)\nfunction (sequential,domintros)  mapMaybe  :: \"('a \\<Rightarrow> 'b option)\\<Rightarrow> 'a list \\<Rightarrow> 'b list \"  where \n     \" mapMaybe f ([]) = ( [])\"\n|\" mapMaybe f (x # xs) = (\n      (case  f x of\n        None => mapMaybe f xs\n      | Some y => y # (mapMaybe f xs)\n      ))\" \nby pat_completeness auto\n\n\n(*val mapi : forall 'a 'b. (nat -> 'a -> 'b) -> list 'a -> list 'b*)\nfunction (sequential,domintros)  mapiAux  :: \"(nat \\<Rightarrow> 'b \\<Rightarrow> 'a)\\<Rightarrow> nat \\<Rightarrow> 'b list \\<Rightarrow> 'a list \"  where \n     \" mapiAux f (n :: nat) ([]) = ( [])\"\n|\" mapiAux f (n :: nat) (x # xs) = ( (f n x) # mapiAux f (n +( 1 :: nat)) xs )\" \nby pat_completeness auto\n\ndefinition mapi  :: \"(nat \\<Rightarrow> 'a \\<Rightarrow> 'b)\\<Rightarrow> 'a list \\<Rightarrow> 'b list \"  where \n     \" mapi f l = ( mapiAux f(( 0 :: nat)) l )\"\n\n\n(*val deletes: forall 'a. Eq 'a => list 'a -> list 'a -> list 'a*)\ndefinition deletes  :: \" 'a list \\<Rightarrow> 'a list \\<Rightarrow> 'a list \"  where \n     \" deletes xs ys = (\n  List.foldl ((\\<lambda> x y. remove1 y x)) xs ys )\"\n\n\n(* ========================================================================== *)\n(* Comments (not clean yet, please ignore the rest of the file)               *)\n(* ========================================================================== *)\n\n(* ----------------------- *)\n(* skipped from Haskell Lib*)\n(* ----------------------- \n\nintersperse :: a -> [a] -> [a]\nintercalate :: [a] -> [[a]] -> [a]\ntranspose :: [[a]] -> [[a]]\nsubsequences :: [a] -> [[a]]\npermutations :: [a] -> [[a]]\nfoldl` :: (a -> b -> a) -> a -> [b] -> aSource\nfoldl1` :: (a -> a -> a) -> [a] -> aSource\n\nand\nor\nsum\nproduct\nmaximum\nminimum\nscanl\nscanr\nscanl1\nscanr1\nAccumulating maps\n\nmapAccumL :: (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])Source\nmapAccumR :: (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])Source\n\niterate :: (a -> a) -> a -> [a]\nrepeat :: a -> [a]\ncycle :: [a] -> [a]\nunfoldr\n\n\ntakeWhile :: (a -> Bool) -> [a] -> [a]Source\ndropWhile :: (a -> Bool) -> [a] -> [a]Source\ndropWhileEnd :: (a -> Bool) -> [a] -> [a]Source\nspan :: (a -> Bool) -> [a] -> ([a], [a])Source\nbreak :: (a -> Bool) -> [a] -> ([a], [a])Source\nbreak p is equivalent to span (not . p).\nstripPrefix :: Eq a => [a] -> [a] -> Maybe [a]Source\ngroup :: Eq a => [a] -> [[a]]Source\ninits :: [a] -> [[a]]Source\ntails :: [a] -> [[a]]Source\n\n\nisPrefixOf :: Eq a => [a] -> [a] -> BoolSource\nisSuffixOf :: Eq a => [a] -> [a] -> BoolSource\nisInfixOf :: Eq a => [a] -> [a] -> BoolSource\n\n\n\nnotElem :: Eq a => a -> [a] -> BoolSource\n\nzip3 :: [a] -> [b] -> [c] -> [(a, b, c)]Source\nzip4 :: [a] -> [b] -> [c] -> [d] -> [(a, b, c, d)]Source\nzip5 :: [a] -> [b] -> [c] -> [d] -> [e] -> [(a, b, c, d, e)]Source\nzip6 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [(a, b, c, d, e, f)]Source\nzip7 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [(a, b, c, d, e, f, g)]Source\n\nzipWith :: (a -> b -> c) -> [a] -> [b] -> [c]Source\nzipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]Source\nzipWith4 :: (a -> b -> c -> d -> e) -> [a] -> [b] -> [c] -> [d] -> [e]Source\nzipWith5 :: (a -> b -> c -> d -> e -> f) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f]Source\nzipWith6 :: (a -> b -> c -> d -> e -> f -> g) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g]Source\nzipWith7 :: (a -> b -> c -> d -> e -> f -> g -> h) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [h]Source\n\n\nunzip3 :: [(a, b, c)] -> ([a], [b], [c])Source\nunzip4 :: [(a, b, c, d)] -> ([a], [b], [c], [d])Source\nunzip5 :: [(a, b, c, d, e)] -> ([a], [b], [c], [d], [e])Source\nunzip6 :: [(a, b, c, d, e, f)] -> ([a], [b], [c], [d], [e], [f])Source\nunzip7 :: [(a, b, c, d, e, f, g)] -> ([a], [b], [c], [d], [e], [f], [g])Source\n\n\nlines :: String -> [String]Source\nwords :: String -> [String]Source\nunlines :: [String] -> StringSource\nunwords :: [String] -> StringSource\nnub :: Eq a => [a] -> [a]Source\ndelete :: Eq a => a -> [a] -> [a]Source\n\n() :: Eq a => [a] -> [a] -> [a]Source\nunion :: Eq a => [a] -> [a] -> [a]Source\nintersect :: Eq a => [a] -> [a] -> [a]Source\nsort :: Ord a => [a] -> [a]Source\ninsert :: Ord a => a -> [a] -> [a]Source\n\n\nnubBy :: (a -> a -> Bool) -> [a] -> [a]Source\ndeleteBy :: (a -> a -> Bool) -> a -> [a] -> [a]Source\ndeleteFirstsBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]Source\nunionBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]Source\nintersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]Source\ngroupBy :: (a -> a -> Bool) -> [a] -> [[a]]Source\nsortBy :: (a -> a -> Ordering) -> [a] -> [a]Source\ninsertBy :: (a -> a -> Ordering) -> a -> [a] -> [a]Source\nmaximumBy :: (a -> a -> Ordering) -> [a] -> aSource\nminimumBy :: (a -> a -> Ordering) -> [a] -> aSource\ngenericLength :: Num i => [b] -> iSource\ngenericTake :: Integral i => i -> [a] -> [a]Source\ngenericDrop :: Integral i => i -> [a] -> [a]Source\ngenericSplitAt :: Integral i => i -> [b] -> ([b], [b])Source\ngenericIndex :: Integral a => [b] -> a -> bSource\ngenericReplicate :: Integral i => i -> a -> [a]Source\n\n\n*)\n\n\n(* ----------------------- *)\n(* skipped from Lem Lib    *)\n(* ----------------------- \n\n\nval for_all2 : forall 'a 'b. ('a -> 'b -> bool) -> list 'a -> list 'b -> bool\nval exists2 : forall 'a 'b. ('a -> 'b -> bool) -> list 'a -> list 'b -> bool\nval map2 : forall 'a 'b 'c. ('a -> 'b -> 'c) -> list 'a -> list 'b -> list 'c \nval rev_map2 : forall 'a 'b 'c. ('a -> 'b -> 'c) -> list 'a -> list 'b -> list 'c\nval fold_left2 : forall 'a 'b 'c. ('a -> 'b -> 'c -> 'a) -> 'a -> list 'b -> list 'c -> 'a\nval fold_right2 : forall 'a 'b 'c. ('a -> 'b -> 'c -> 'c) -> list 'a -> list 'b -> 'c -> 'c\n\n\n(* now maybe result and called lookup *)\nval assoc : forall 'a 'b. 'a -> list ('a * 'b) -> 'b\nlet inline {ocaml} assoc = Ocaml.List.assoc\n\n\nval mem_assoc : forall 'a 'b. 'a -> list ('a * 'b) -> bool\nval remove_assoc : forall 'a 'b. 'a -> list ('a * 'b) -> list ('a * 'b)\n\n\n\nval stable_sort : forall 'a. ('a -> 'a -> num) -> list 'a -> list 'a\nval fast_sort : forall 'a. ('a -> 'a -> num) -> list 'a -> list 'a\n\nval merge : forall 'a. ('a -> 'a -> num) -> list 'a -> list 'a -> list 'a\nval intersect : forall 'a. list 'a -> list 'a -> list 'a\n\n\n*)\n\n(*val     catMaybes : forall 'a. list (maybe 'a) -> list 'a*)\nfunction (sequential,domintros)  catMaybes  :: \"('a option)list \\<Rightarrow> 'a list \"  where \n     \" catMaybes ([]) = (\n        [])\"\n|\" catMaybes (None # xs') = (\n        catMaybes xs' )\"\n|\" catMaybes (Some x # xs') = (\n        x # catMaybes xs' )\" \nby pat_completeness auto\n\nend\n", "meta": {"author": "lixm", "repo": "yul-smallstep", "sha": "f71786f5158e335f7caa3311a4928c3ac97912ee", "save_path": "github-repos/isabelle/lixm-yul-smallstep", "path": "github-repos/isabelle/lixm-yul-smallstep/yul-smallstep-f71786f5158e335f7caa3311a4928c3ac97912ee/utils/Lem_list.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.5, "lm_q1q2_score": 0.2733690759923069}}
{"text": "(*<*) \n\n(* Author: Kyndylan Nienhuis *)\n\ntheory CompartmentAuthority\n\nimports \n  \"CHERI-core.CheriLemmas\"\nbegin\n\n(*>*)\nsection \\<open>Generalised permissions\\<close>\n\nrecord CompartmentAuthority = \n  SystemRegisterAccess :: bool\n  ExecutableAddresses :: \"VirtualAddress set\"\n  LoadableAddresses :: \"VirtualAddress set\"\n  CapLoadableAddresses :: \"VirtualAddress set\"\n  StorableAddresses :: \"VirtualAddress set\"\n  CapStorableAddresses :: \"VirtualAddress set\"\n  LocalCapStorableAddresses :: \"VirtualAddress set\"\n  SealableTypes :: \"ObjectType set\"\n  UnsealableTypes :: \"ObjectType set\"\n\nsubsection \\<open>Order over generalised permissions\\<close>\n\ninstantiation \"CompartmentAuthority_ext\" :: (order) order\nbegin\n\n  definition less_eq_CompartmentAuthority_ext :: \n    \"'a CompartmentAuthority_scheme \\<Rightarrow> 'a CompartmentAuthority_scheme \\<Rightarrow> bool\"\n  where \n    \"less_eq_CompartmentAuthority_ext perm\\<^sub>1 perm\\<^sub>2 \\<equiv>\n     (SystemRegisterAccess perm\\<^sub>1 \\<le> SystemRegisterAccess perm\\<^sub>2) \\<and>\n     (ExecutableAddresses perm\\<^sub>1 \\<le> ExecutableAddresses perm\\<^sub>2) \\<and>\n     (LoadableAddresses perm\\<^sub>1 \\<le> LoadableAddresses perm\\<^sub>2) \\<and>\n     (CapLoadableAddresses perm\\<^sub>1 \\<le> CapLoadableAddresses perm\\<^sub>2) \\<and>\n     (StorableAddresses perm\\<^sub>1 \\<le> StorableAddresses perm\\<^sub>2) \\<and>\n     (CapStorableAddresses perm\\<^sub>1 \\<le> CapStorableAddresses perm\\<^sub>2) \\<and>\n     (LocalCapStorableAddresses perm\\<^sub>1 \\<le> LocalCapStorableAddresses perm\\<^sub>2) \\<and>\n     (SealableTypes perm\\<^sub>1 \\<le> SealableTypes perm\\<^sub>2) \\<and>\n     (UnsealableTypes perm\\<^sub>1 \\<le> UnsealableTypes perm\\<^sub>2) \\<and>\n     (CompartmentAuthority.more perm\\<^sub>1 \\<le> CompartmentAuthority.more perm\\<^sub>2)\"\n  \n  definition less_CompartmentAuthority_ext :: \"'a CompartmentAuthority_scheme \\<Rightarrow> 'a CompartmentAuthority_scheme \\<Rightarrow> bool\" where\n    \"less_CompartmentAuthority_ext perm\\<^sub>1 perm\\<^sub>2 \\<equiv> perm\\<^sub>1 \\<le> perm\\<^sub>2 \\<and> \\<not> (perm\\<^sub>2 \\<le> perm\\<^sub>1)\"\n  \n  instance\n    by standard (auto simp: less_CompartmentAuthority_ext_def less_eq_CompartmentAuthority_ext_def)\n\nend\n\nsubsubsection \\<open>Eliminations\\<close>\n\nlemma SystemRegisterAccess_le [elim]:\n  assumes \"p \\<le> q\"\n      and \"SystemRegisterAccess p\"\n  shows \"SystemRegisterAccess q\"\nusing assms\nunfolding less_eq_CompartmentAuthority_ext_def\nby auto\n\nlemma ExecutableAddresses_le:\n  assumes \"p \\<le> q\"\n  shows \"ExecutableAddresses p \\<subseteq> ExecutableAddresses q\"\nusing assms\nunfolding less_eq_CompartmentAuthority_ext_def\nby auto\n\nlemmas ExecutableAddresses_le_subsetD [elim] =\n  subsetD[OF ExecutableAddresses_le]\n\nlemma LoadableAddresses_le:\n  assumes \"p \\<le> q\"\n  shows \"LoadableAddresses p \\<subseteq> LoadableAddresses q\"\nusing assms\nunfolding less_eq_CompartmentAuthority_ext_def\nby auto\n\nlemmas LoadableAddresses_le_subsetD [elim] =\n  subsetD[OF LoadableAddresses_le]\n\nlemma CapLoadableAddresses_le:\n  assumes \"p \\<le> q\"\n  shows \"CapLoadableAddresses p \\<subseteq> CapLoadableAddresses q\"\nusing assms\nunfolding less_eq_CompartmentAuthority_ext_def\nby auto\n\nlemmas CapLoadableAddresses_le_subsetD [elim] =\n  subsetD[OF CapLoadableAddresses_le]\n\nlemma StorableAddresses_le:\n  assumes \"p \\<le> q\"\n  shows \"StorableAddresses p \\<subseteq> StorableAddresses q\"\nusing assms\nunfolding less_eq_CompartmentAuthority_ext_def\nby auto\n\nlemmas StorableAddresses_le_subsetD [elim] =\n  subsetD[OF StorableAddresses_le]\n\nlemma CapStorableAddresses_le:\n  assumes \"p \\<le> q\"\n  shows \"CapStorableAddresses p \\<subseteq> CapStorableAddresses q\"\nusing assms\nunfolding less_eq_CompartmentAuthority_ext_def\nby auto\n\nlemmas CapStorableAddresses_le_subsetD [elim] =\n  subsetD[OF CapStorableAddresses_le]\n\nlemma LocalCapStorableAddresses_le:\n  assumes \"p \\<le> q\"\n  shows \"LocalCapStorableAddresses p \\<subseteq> LocalCapStorableAddresses q\"\nusing assms\nunfolding less_eq_CompartmentAuthority_ext_def\nby auto\n\nlemmas LocalCapStorableAddresses_le_subsetD [elim] =\n  subsetD[OF LocalCapStorableAddresses_le]\n\nlemma SealableTypes_le:\n  assumes \"p \\<le> q\"\n  shows \"SealableTypes p \\<subseteq> SealableTypes q\"\nusing assms\nunfolding less_eq_CompartmentAuthority_ext_def\nby auto\n\nlemmas SealableTypes_le_subsetD [elim] =\n  subsetD[OF SealableTypes_le]\n\nlemma UnsealableTypes_le:\n  assumes \"p \\<le> q\"\n  shows \"UnsealableTypes p \\<subseteq> UnsealableTypes q\"\nusing assms\nunfolding less_eq_CompartmentAuthority_ext_def\nby auto\n\nlemmas UnsealableTypes_le_subsetD [elim] =\n  subsetD[OF UnsealableTypes_le]\n\nsubsection \\<open>Complete lattice over generalised permissions\\<close>\n\nsubsubsection \\<open>Bottom of generalised permissions\\<close>\n\ninstantiation \"CompartmentAuthority_ext\" :: (order_bot) order_bot\nbegin\n\n  definition bot_CompartmentAuthority_ext :: \"'a CompartmentAuthority_scheme\" where\n    \"bot_CompartmentAuthority_ext = \n     \\<lparr>SystemRegisterAccess = bot,\n      ExecutableAddresses = bot,\n      LoadableAddresses = bot,\n      CapLoadableAddresses = bot,\n      StorableAddresses = bot,\n      CapStorableAddresses = bot,\n      LocalCapStorableAddresses = bot,\n      SealableTypes = bot,\n      UnsealableTypes = bot, \n      \\<dots> = bot\\<rparr>\"\n  \n  instance\n    by standard (auto simp: bot_CompartmentAuthority_ext_def less_eq_CompartmentAuthority_ext_def)\n\nend\n\nlemma bot_CompartmentAuthority_ext_simp [simp]:\n  shows \"SystemRegisterAccess bot = bot\"\n    and \"ExecutableAddresses bot = bot\"\n    and \"LoadableAddresses bot = bot\"\n    and \"CapLoadableAddresses bot = bot\"\n    and \"StorableAddresses bot = bot\"\n    and \"CapStorableAddresses bot = bot\"\n    and \"LocalCapStorableAddresses bot = bot\"\n    and \"SealableTypes bot = bot\"\n    and \"UnsealableTypes bot = bot\"\n    and \"more bot = bot\"\nunfolding bot_CompartmentAuthority_ext_def\nby simp_all\n\nsubsubsection \\<open>Top of generalised permissions\\<close>\n\ninstantiation \"CompartmentAuthority_ext\" :: (order_top) order_top\nbegin\n\n  definition top_CompartmentAuthority_ext :: \"'a CompartmentAuthority_scheme\" where\n    \"top_CompartmentAuthority_ext = \n     \\<lparr>SystemRegisterAccess = top,\n      ExecutableAddresses = top,\n      LoadableAddresses = top,\n      CapLoadableAddresses = top,\n      StorableAddresses = top,\n      CapStorableAddresses = top,\n      LocalCapStorableAddresses = top,\n      SealableTypes = top,\n      UnsealableTypes = top, \n      \\<dots> = top\\<rparr>\"\n  \n  instance\n    by standard (auto simp: top_CompartmentAuthority_ext_def less_eq_CompartmentAuthority_ext_def)\n\nend\n\nlemma top_CompartmentAuthority_ext_simp [simp]:\n  shows \"SystemRegisterAccess top = top\"\n    and \"ExecutableAddresses top = top\"\n    and \"LoadableAddresses top = top\"\n    and \"CapLoadableAddresses top = top\"\n    and \"StorableAddresses top = top\"\n    and \"CapStorableAddresses top = top\"\n    and \"LocalCapStorableAddresses top = top\"\n    and \"SealableTypes top = top\"\n    and \"UnsealableTypes top = top\"\n    and \"more top = top\"\nunfolding top_CompartmentAuthority_ext_def\nby simp_all\n\nsubsubsection \\<open>Infimum of generalised permissions\\<close>\n\ninstantiation \"CompartmentAuthority_ext\" :: (semilattice_inf) semilattice_inf\nbegin\n\n  definition inf_CompartmentAuthority_ext :: \n    \"'a CompartmentAuthority_scheme \\<Rightarrow> 'a CompartmentAuthority_scheme \\<Rightarrow> 'a CompartmentAuthority_scheme\"\n  where\n    \"inf_CompartmentAuthority_ext left right = \n     \\<lparr>SystemRegisterAccess = inf (SystemRegisterAccess left) (SystemRegisterAccess right),\n      ExecutableAddresses = inf (ExecutableAddresses left) (ExecutableAddresses right),\n      LoadableAddresses = inf (LoadableAddresses left) (LoadableAddresses right),\n      CapLoadableAddresses = inf (CapLoadableAddresses left) (CapLoadableAddresses right),\n      StorableAddresses = inf (StorableAddresses left) (StorableAddresses right),\n      CapStorableAddresses = inf (CapStorableAddresses left) (CapStorableAddresses right),\n      LocalCapStorableAddresses = inf (LocalCapStorableAddresses left) (LocalCapStorableAddresses right),\n      SealableTypes = inf (SealableTypes left) (SealableTypes right),\n      UnsealableTypes = inf (UnsealableTypes left) (UnsealableTypes right), \n      \\<dots> = inf (more left) (more right)\\<rparr>\"\n  \n  instance\n    by standard (auto simp: inf_CompartmentAuthority_ext_def less_eq_CompartmentAuthority_ext_def)\n\nend\n\nlemma inf_CompartmentAuthority_ext_simp [simp]:\n  shows \"SystemRegisterAccess (inf left right) = inf (SystemRegisterAccess left) (SystemRegisterAccess right)\"\n    and \"ExecutableAddresses (inf left right) = inf (ExecutableAddresses left) (ExecutableAddresses right)\"\n    and \"LoadableAddresses (inf left right) = inf (LoadableAddresses left) (LoadableAddresses right)\"\n    and \"CapLoadableAddresses (inf left right) = inf (CapLoadableAddresses left) (CapLoadableAddresses right)\"\n    and \"StorableAddresses (inf left right) = inf (StorableAddresses left) (StorableAddresses right)\"\n    and \"CapStorableAddresses (inf left right) = inf (CapStorableAddresses left) (CapStorableAddresses right)\"\n    and \"LocalCapStorableAddresses (inf left right) = inf (LocalCapStorableAddresses left) (LocalCapStorableAddresses right)\"\n    and \"SealableTypes (inf left right) = inf (SealableTypes left) (SealableTypes right)\"\n    and \"UnsealableTypes (inf left right) = inf (UnsealableTypes left) (UnsealableTypes right)\"\n    and \"more (inf left right) = inf (more left) (more right)\"\nunfolding inf_CompartmentAuthority_ext_def\nby simp_all\n\ninstantiation \"CompartmentAuthority_ext\" :: (Inf) Inf\nbegin\n\n  definition Inf_CompartmentAuthority_ext :: \n    \"'a CompartmentAuthority_scheme set \\<Rightarrow> 'a CompartmentAuthority_scheme\"\n  where\n    \"Inf_CompartmentAuthority_ext permSet = \n     \\<lparr>SystemRegisterAccess = Inf (SystemRegisterAccess ` permSet),\n      ExecutableAddresses = Inf (ExecutableAddresses ` permSet),\n      LoadableAddresses = Inf (LoadableAddresses ` permSet),\n      CapLoadableAddresses = Inf (CapLoadableAddresses ` permSet),\n      StorableAddresses = Inf (StorableAddresses ` permSet),\n      CapStorableAddresses = Inf (CapStorableAddresses ` permSet),\n      LocalCapStorableAddresses = Inf (LocalCapStorableAddresses ` permSet),\n      SealableTypes = Inf (SealableTypes ` permSet),\n      UnsealableTypes = Inf (UnsealableTypes ` permSet), \n      \\<dots> = Inf (more ` permSet)\\<rparr>\"\n  \n  instance by standard\n\nend\n\nlemma Inf_CompartmentAuthority_ext_simp [simp]:\n  shows \"SystemRegisterAccess (Inf permSet) = Inf (SystemRegisterAccess ` permSet)\"\n    and \"ExecutableAddresses (Inf permSet) = Inf (ExecutableAddresses ` permSet)\"\n    and \"LoadableAddresses (Inf permSet) = Inf (LoadableAddresses ` permSet)\"\n    and \"CapLoadableAddresses (Inf permSet) = Inf (CapLoadableAddresses ` permSet)\"\n    and \"StorableAddresses (Inf permSet) = Inf (StorableAddresses ` permSet)\"\n    and \"CapStorableAddresses (Inf permSet) = Inf (CapStorableAddresses ` permSet)\"\n    and \"LocalCapStorableAddresses (Inf permSet) = Inf (LocalCapStorableAddresses ` permSet)\"\n    and \"SealableTypes (Inf permSet) = Inf (SealableTypes ` permSet)\"\n    and \"UnsealableTypes (Inf permSet) = Inf (UnsealableTypes ` permSet)\"\n    and \"more (Inf permSet) = Inf (more ` permSet)\"\nunfolding Inf_CompartmentAuthority_ext_def\nby simp_all\n\nsubsubsection \\<open>Supremum of generalised permissions\\<close>\n\ninstantiation \"CompartmentAuthority_ext\" :: (semilattice_sup) semilattice_sup\nbegin\n\n  definition sup_CompartmentAuthority_ext :: \n    \"'a CompartmentAuthority_scheme \\<Rightarrow> 'a CompartmentAuthority_scheme \\<Rightarrow> 'a CompartmentAuthority_scheme\"\n  where\n    \"sup_CompartmentAuthority_ext left right = \n     \\<lparr>SystemRegisterAccess = sup (SystemRegisterAccess left) (SystemRegisterAccess right),\n      ExecutableAddresses = sup (ExecutableAddresses left) (ExecutableAddresses right),\n      LoadableAddresses = sup (LoadableAddresses left) (LoadableAddresses right),\n      CapLoadableAddresses = sup (CapLoadableAddresses left) (CapLoadableAddresses right),\n      StorableAddresses = sup (StorableAddresses left) (StorableAddresses right),\n      CapStorableAddresses = sup (CapStorableAddresses left) (CapStorableAddresses right),\n      LocalCapStorableAddresses = sup (LocalCapStorableAddresses left) (LocalCapStorableAddresses right),\n      SealableTypes = sup (SealableTypes left) (SealableTypes right),\n      UnsealableTypes = sup (UnsealableTypes left) (UnsealableTypes right), \n      \\<dots> = sup (more left) (more right)\\<rparr>\"\n  \n  instance\n    by standard (auto simp: sup_CompartmentAuthority_ext_def less_eq_CompartmentAuthority_ext_def)\n\nend\n\nlemma sup_CompartmentAuthority_ext_simp [simp]:\n  shows \"SystemRegisterAccess (sup left right) = sup (SystemRegisterAccess left) (SystemRegisterAccess right)\"\n    and \"ExecutableAddresses (sup left right) = sup (ExecutableAddresses left) (ExecutableAddresses right)\"\n    and \"LoadableAddresses (sup left right) = sup (LoadableAddresses left) (LoadableAddresses right)\"\n    and \"CapLoadableAddresses (sup left right) = sup (CapLoadableAddresses left) (CapLoadableAddresses right)\"\n    and \"StorableAddresses (sup left right) = sup (StorableAddresses left) (StorableAddresses right)\"\n    and \"CapStorableAddresses (sup left right) = sup (CapStorableAddresses left) (CapStorableAddresses right)\"\n    and \"LocalCapStorableAddresses (sup left right) = sup (LocalCapStorableAddresses left) (LocalCapStorableAddresses right)\"\n    and \"SealableTypes (sup left right) = sup (SealableTypes left) (SealableTypes right)\"\n    and \"UnsealableTypes (sup left right) = sup (UnsealableTypes left) (UnsealableTypes right)\"\n    and \"more (sup left right) = sup (more left) (more right)\"\nunfolding sup_CompartmentAuthority_ext_def\nby simp_all\n\ninstantiation \"CompartmentAuthority_ext\" :: (Sup) Sup\nbegin\n\n  definition Sup_CompartmentAuthority_ext :: \n    \"'a CompartmentAuthority_scheme set \\<Rightarrow> 'a CompartmentAuthority_scheme\"\n  where\n    \"Sup_CompartmentAuthority_ext permSet = \n     \\<lparr>SystemRegisterAccess = Sup (SystemRegisterAccess ` permSet),\n      ExecutableAddresses = Sup (ExecutableAddresses ` permSet),\n      LoadableAddresses = Sup (LoadableAddresses ` permSet),\n      CapLoadableAddresses = Sup (CapLoadableAddresses ` permSet),\n      StorableAddresses = Sup (StorableAddresses ` permSet),\n      CapStorableAddresses = Sup (CapStorableAddresses ` permSet),\n      LocalCapStorableAddresses = Sup (LocalCapStorableAddresses ` permSet),\n      SealableTypes = Sup (SealableTypes ` permSet),\n      UnsealableTypes = Sup (UnsealableTypes ` permSet), \n      \\<dots> = Sup (more ` permSet)\\<rparr>\"\n  \n  instance by standard\n\nend\n\nlemma Sup_CompartmentAuthority_ext_simp [simp]:\n  shows \"SystemRegisterAccess (Sup permSet) = Sup (SystemRegisterAccess ` permSet)\"\n    and \"ExecutableAddresses (Sup permSet) = Sup (ExecutableAddresses ` permSet)\"\n    and \"LoadableAddresses (Sup permSet) = Sup (LoadableAddresses ` permSet)\"\n    and \"CapLoadableAddresses (Sup permSet) = Sup (CapLoadableAddresses ` permSet)\"\n    and \"StorableAddresses (Sup permSet) = Sup (StorableAddresses ` permSet)\"\n    and \"CapStorableAddresses (Sup permSet) = Sup (CapStorableAddresses ` permSet)\"\n    and \"LocalCapStorableAddresses (Sup permSet) = Sup (LocalCapStorableAddresses ` permSet)\"\n    and \"SealableTypes (Sup permSet) = Sup (SealableTypes ` permSet)\"\n    and \"UnsealableTypes (Sup permSet) = Sup (UnsealableTypes ` permSet)\"\n    and \"more (Sup permSet) = Sup (more ` permSet)\"\nunfolding Sup_CompartmentAuthority_ext_def\nby simp_all\n\nsubsubsection \\<open>Bounded, distributive lattice over generalised permissions\\<close>\n\ninstantiation \"CompartmentAuthority_ext\" :: (Lattices.lattice) Lattices.lattice\nbegin  \n\n  instance by standard\n\nend\n\ninstantiation \"CompartmentAuthority_ext\" :: (bounded_lattice) bounded_lattice\nbegin  \n\n  instance by standard\n\nend\n\ninstantiation \"CompartmentAuthority_ext\" :: (distrib_lattice) distrib_lattice\nbegin\n  \n  instance\n    by standard\n       (auto simp: sup_inf_distrib1 \n                   inf_CompartmentAuthority_ext_def\n                   sup_CompartmentAuthority_ext_def)\n\nend\n\nsubsubsection \\<open>Boolean algebra over generalised permissions\\<close>\n\ninstantiation \"CompartmentAuthority_ext\" :: (boolean_algebra) boolean_algebra\nbegin\n\n  definition minus_CompartmentAuthority_ext :: \n    \"'a CompartmentAuthority_scheme \\<Rightarrow> 'a CompartmentAuthority_scheme \\<Rightarrow> 'a CompartmentAuthority_scheme\"\n  where\n    \"minus_CompartmentAuthority_ext left right = \n     \\<lparr>SystemRegisterAccess = minus (SystemRegisterAccess left) (SystemRegisterAccess right),\n      ExecutableAddresses = minus (ExecutableAddresses left) (ExecutableAddresses right),\n      LoadableAddresses = minus (LoadableAddresses left) (LoadableAddresses right),\n      CapLoadableAddresses = minus (CapLoadableAddresses left) (CapLoadableAddresses right),\n      StorableAddresses = minus (StorableAddresses left) (StorableAddresses right),\n      CapStorableAddresses = minus (CapStorableAddresses left) (CapStorableAddresses right),\n      LocalCapStorableAddresses = minus (LocalCapStorableAddresses left) (LocalCapStorableAddresses right),\n      SealableTypes = minus (SealableTypes left) (SealableTypes right),\n      UnsealableTypes = minus (UnsealableTypes left) (UnsealableTypes right), \n      \\<dots> = minus (more left) (more right)\\<rparr>\"\n\n  definition uminus_CompartmentAuthority_ext :: \n    \"'a CompartmentAuthority_scheme \\<Rightarrow> 'a CompartmentAuthority_scheme\"\n  where\n    \"uminus_CompartmentAuthority_ext perm = \n     \\<lparr>SystemRegisterAccess = uminus (SystemRegisterAccess perm),\n      ExecutableAddresses = uminus (ExecutableAddresses perm),\n      LoadableAddresses = uminus (LoadableAddresses perm),\n      CapLoadableAddresses = uminus (CapLoadableAddresses perm),\n      StorableAddresses = uminus (StorableAddresses perm),\n      CapStorableAddresses = uminus (CapStorableAddresses perm),\n      LocalCapStorableAddresses = uminus (LocalCapStorableAddresses perm),\n      SealableTypes = uminus (SealableTypes perm),\n      UnsealableTypes = uminus (UnsealableTypes perm), \n      \\<dots> = uminus (more perm)\\<rparr>\"\n  \n  instance\n    by standard\n       (auto simp: diff_eq\n                   bot_CompartmentAuthority_ext_def\n                   top_CompartmentAuthority_ext_def\n                   inf_CompartmentAuthority_ext_def \n                   sup_CompartmentAuthority_ext_def\n                   minus_CompartmentAuthority_ext_def\n                   uminus_CompartmentAuthority_ext_def)\n\nend\n\nlemma minus_CompartmentAuthority_ext_simp [simp]:\n  shows \"SystemRegisterAccess (minus left right) = minus (SystemRegisterAccess left) (SystemRegisterAccess right)\"\n    and \"ExecutableAddresses (minus left right) = minus (ExecutableAddresses left) (ExecutableAddresses right)\"\n    and \"LoadableAddresses (minus left right) = minus (LoadableAddresses left) (LoadableAddresses right)\"\n    and \"CapLoadableAddresses (minus left right) = minus (CapLoadableAddresses left) (CapLoadableAddresses right)\"\n    and \"StorableAddresses (minus left right) = minus (StorableAddresses left) (StorableAddresses right)\"\n    and \"CapStorableAddresses (minus left right) = minus (CapStorableAddresses left) (CapStorableAddresses right)\"\n    and \"LocalCapStorableAddresses (minus left right) = minus (LocalCapStorableAddresses left) (LocalCapStorableAddresses right)\"\n    and \"SealableTypes (minus left right) = minus (SealableTypes left) (SealableTypes right)\"\n    and \"UnsealableTypes (minus left right) = minus (UnsealableTypes left) (UnsealableTypes right)\"\n    and \"more (minus left right) = minus (more left) (more right)\"\nunfolding minus_CompartmentAuthority_ext_def\nby simp_all\n\nlemma uminus_CompartmentAuthority_ext_simp [simp]:\n  shows \"SystemRegisterAccess (uminus perm) = uminus (SystemRegisterAccess perm)\"\n    and \"ExecutableAddresses (uminus perm) = uminus (ExecutableAddresses perm)\"\n    and \"LoadableAddresses (uminus perm) = uminus (LoadableAddresses perm)\"\n    and \"CapLoadableAddresses (uminus perm) = uminus (CapLoadableAddresses perm)\"\n    and \"StorableAddresses (uminus perm) = uminus (StorableAddresses perm)\"\n    and \"CapStorableAddresses (uminus perm) = uminus (CapStorableAddresses perm)\"\n    and \"LocalCapStorableAddresses (uminus perm) = uminus (LocalCapStorableAddresses perm)\"\n    and \"SealableTypes (uminus perm) = uminus (SealableTypes perm)\"\n    and \"UnsealableTypes (uminus perm) = uminus (UnsealableTypes perm)\"\n    and \"more (uminus perm) = uminus (more perm)\"\nunfolding uminus_CompartmentAuthority_ext_def\nby simp_all\n\nsubsubsection \\<open>Complete lattice over generalised permissions\\<close>\n\ninstantiation \"CompartmentAuthority_ext\" :: (complete_lattice) complete_lattice\nbegin\n  \n  instance\n    proof standard\n      fix x :: \"'a CompartmentAuthority_ext\" and A \n      assume \"x \\<in> A\"\n      thus   \"less_eq (Inf A) x\"\n        unfolding Inf_CompartmentAuthority_ext_def\n        unfolding less_eq_CompartmentAuthority_ext_def\n        by (simp add: INF_lower)\n    next\n      fix z :: \"'a CompartmentAuthority_ext\" and A \n      assume \"\\<And>x. x \\<in> A \\<Longrightarrow> less_eq z x\"\n      thus   \"less_eq z (Inf A)\"\n        unfolding Inf_CompartmentAuthority_ext_def\n        unfolding less_eq_CompartmentAuthority_ext_def\n        by (auto simp: INF_greatest)\n    next\n      fix x :: \"'a CompartmentAuthority_ext\" and A \n      assume \"x \\<in> A\"\n      thus   \"less_eq x (Sup A)\"\n        unfolding Sup_CompartmentAuthority_ext_def\n        unfolding less_eq_CompartmentAuthority_ext_def\n        by (auto simp: SUP_upper)\n    next\n      fix z :: \"'a CompartmentAuthority_ext\" and A \n      assume \"\\<And>x. x \\<in> A \\<Longrightarrow> less_eq x z\"\n      thus   \"less_eq (Sup A) z\"\n        unfolding Sup_CompartmentAuthority_ext_def\n        unfolding less_eq_CompartmentAuthority_ext_def\n        by (auto simp: SUP_least)\n    next\n      show \"(Inf {}::'a CompartmentAuthority_ext) = top\"\n        unfolding Inf_CompartmentAuthority_ext_def\n        unfolding top_CompartmentAuthority_ext_def\n        by simp\n    next\n      show \"(Sup {}::'a CompartmentAuthority_ext) = bot\"\n        unfolding Sup_CompartmentAuthority_ext_def\n        unfolding bot_CompartmentAuthority_ext_def\n        by simp\n    qed\n\nend\n\nsubsubsection \\<open>Complete distributive lattice over generalised permissions\\<close>\n\ninstantiation \"CompartmentAuthority_ext\" :: (complete_distrib_lattice) complete_distrib_lattice\nbegin\n  \n  instance\n    proof standard\n      fix x :: \"'a CompartmentAuthority_ext\" and A \n      show \"sup x (Inf A) = (INF a:A. sup x a)\"\n        unfolding Inf_CompartmentAuthority_ext_def\n        unfolding sup_CompartmentAuthority_ext_def\n        using sup_Inf[where a=\"CompartmentAuthority.more x\"]\n        by simp\n    next\n      fix x :: \"'a CompartmentAuthority_ext\" and A \n      show \"inf x (Sup A) = (SUP a:A. inf x a)\"\n        unfolding Sup_CompartmentAuthority_ext_def\n        unfolding inf_CompartmentAuthority_ext_def\n        using inf_Sup[where a=\"CompartmentAuthority.more x\"]\n        by simp\n    qed\n\nend\n\nsubsubsection \\<open>Complete boolean algebra over generalised permissions\\<close>\n\ninstantiation \"CompartmentAuthority_ext\" :: (complete_boolean_algebra) complete_boolean_algebra\nbegin\n  \n  instance by standard\n\nend\n\nsubsection \\<open>Physical capability addresses\\<close>\n\ndefinition getTranslateCapAddresses :: \n  \"VirtualAddress set \\<Rightarrow> AccessType \\<Rightarrow> state \\<Rightarrow> PhysicalCapAddress set\" \nwhere\n  \"getTranslateCapAddresses addrs t s \\<equiv> \n   GetCapAddress ` getTranslateAddresses addrs t s\"\n\nlemma Commute_getTranslateCapAddresses [Commute_compositeI]: \n  assumes \"Commute (read_state (getTranslateAddresses addrs t)) m\"\n  shows \"Commute (read_state (getTranslateCapAddresses addrs t)) m\"\nusing assms\nunfolding getTranslateCapAddresses_def Commute_def\nby auto\n\nlemma getTranslateCapAddressesI [intro?]:\n  assumes \"getTranslateAddr (virtualAddress, t) s = Some physicalAddress\"\n      and \"a = GetCapAddress physicalAddress\"\n      and \"virtualAddress \\<in> addrs\"\n  shows \"a \\<in> getTranslateCapAddresses addrs t s\"\nusing assms\nunfolding getTranslateCapAddresses_def\nunfolding getTranslateAddresses_def\nby auto\n\nlemma getTranslateCapAddressesI_word_cat [elim]:\n  assumes \"getTranslateAddr (virtualAddress, t) s = Some (ExtendCapAddress a)\"\n      and \"virtualAddress \\<in> addrs\"\n  shows \"a \\<in> getTranslateCapAddresses addrs t s\"\nusing assms\nusing slice_cat1[where a=a and b=\"0::5 word\" and 'a=40]\nby (intro getTranslateCapAddressesI) (auto simp: word_size)\n\nlemma getTranslateCapAddressesE [elim]:\n  assumes \"a \\<in> getTranslateCapAddresses addrs t s\"\n  obtains virtualAddress physicalAddress\n    where \"getTranslateAddr (virtualAddress, t) s = Some physicalAddress\"\n      and \"virtualAddress \\<in> addrs\" \n      and \"a = GetCapAddress physicalAddress\"\nusing assms\nunfolding getTranslateCapAddresses_def\nby auto\n\nlemma getTranslateCapAddresses_le:\n  assumes \"addrs \\<subseteq> addrs'\"\n  shows \"getTranslateCapAddresses addrs t s \\<subseteq> getTranslateCapAddresses addrs' t s\"\nusing assms\nunfolding getTranslateCapAddresses_def\nby auto\n\nlemmas getTranslateCapAddresses_le_subsetD [elim] =\n  subsetD[OF getTranslateCapAddresses_le]\n\nlemma getTranslateCapAddresses_eqI_getTranslateAddr:\n  assumes \"\\<And>a. getTranslateAddr a s' = getTranslateAddr a s\"\n  shows \"getTranslateCapAddresses addrs t s' = getTranslateCapAddresses addrs t s\"\nusing getTranslateAddresses_eqI_getTranslateAddr[OF assms]\nunfolding getTranslateCapAddresses_def\nby simp\n\nlemma getTranslateCapAddresses_distrib_union:\n  shows \"getTranslateCapAddresses (addrs \\<union> addrs') t s =\n         (getTranslateCapAddresses addrs t s \\<union> getTranslateCapAddresses addrs' t s)\"\nunfolding getTranslateCapAddresses_def\nunfolding getTranslateAddresses_distrib_union\nby auto\n\nlemma getTranslateCapAddresses_distrib_Union:\n  shows \"getTranslateCapAddresses (\\<Union>addrsSet) t s =\n         (\\<Union>addrs\\<in>addrsSet. getTranslateCapAddresses addrs t s)\"\nunfolding getTranslateCapAddresses_def\nunfolding getTranslateAddresses_distrib_Union\nby auto\n\nsubsection \\<open>Data writable addresses\\<close>\n\ndefinition StorablePhysAddresses where\n  \"StorablePhysAddresses gperm s \\<equiv>\n   getTranslateAddresses (StorableAddresses gperm) STORE s\"\n\nlemma StorablePhysAddresses_le:\n  assumes \"p \\<le> q\"\n  shows \"StorablePhysAddresses p s \\<subseteq> StorablePhysAddresses q s\"\nusing getTranslateAddresses_le[OF StorableAddresses_le[OF assms]]\nunfolding StorablePhysAddresses_def\nby auto\n\nsubsection \\<open>Capability writable addresses\\<close>\n\ndefinition StorablePhysCapAddresses where\n  \"StorablePhysCapAddresses gperm s \\<equiv>\n   getTranslateCapAddresses (StorableAddresses gperm) STORE s\"\n\nlemma StorablePhysCapAddresses_le:\n  assumes \"p \\<le> q\"\n  shows \"StorablePhysCapAddresses p s \\<subseteq> StorablePhysCapAddresses q s\"\nusing StorableAddresses_le[OF assms]\nusing getTranslateCapAddresses_le\nunfolding StorablePhysCapAddresses_def\nby auto\n\nsubsection \\<open>Always accessible registers\\<close>\n\ndefinition RegisterIsAlwaysAccessible :: \"CapRegister \\<Rightarrow> bool\" where\n  \"RegisterIsAlwaysAccessible r \\<equiv> \n   case r of RegSpecial cd \\<Rightarrow> cd = 0 \\<or> cd = 1\n           | _ \\<Rightarrow> True\"\n\nlemma RegisterIsAlwaysAccessible_simps [simp]:\n  shows \"RegisterIsAlwaysAccessible RegPCC\"\n    and \"RegisterIsAlwaysAccessible RegBranchDelayPCC\"\n    and \"RegisterIsAlwaysAccessible RegBranchToPCC\"\n    and \"RegisterIsAlwaysAccessible (RegGeneral cd)\"\n    and \"RegisterIsAlwaysAccessible (RegSpecial 0)\"\n    and \"RegisterIsAlwaysAccessible (RegSpecial 1)\"\nunfolding RegisterIsAlwaysAccessible_def\nby simp_all\n\nsubsection \\<open>Readable locations\\<close>\n\ndefinition ReadableLocations :: \"CompartmentAuthority \\<Rightarrow> state \\<Rightarrow> CapLocation set\" where\n  \"ReadableLocations f s \\<equiv> \n   {loc. case loc of \n      LocReg r \\<Rightarrow> RegisterIsAlwaysAccessible r\n    | LocMem addr \\<Rightarrow> addr \\<in> getTranslateCapAddresses (CapLoadableAddresses f) LOAD s}\"\n\nlemma Commute_ReadableLocations [Commute_compositeI]: \n  assumes \"\\<And>addrs. Commute (read_state (getTranslateCapAddresses addrs LOAD)) m\"\n  shows \"Commute (read_state (ReadableLocations perm)) m\"\nusing assms\nunfolding ReadableLocations_def Commute_def\nby auto\n\nlemma ReadableLocations_simps [simp]:\n  shows \"(LocReg r) \\<in> ReadableLocations f s = \n         (RegisterIsAlwaysAccessible r)\"\n    and \"(LocMem addr) \\<in> ReadableLocations f s = \n         (addr \\<in> getTranslateCapAddresses (CapLoadableAddresses f) LOAD s)\"\nunfolding ReadableLocations_def\nby simp_all\n\nlemma ReadableLocations_le_subsetD [elim]:\n  assumes \"p \\<le> q\"\n      and \"loc \\<in> ReadableLocations p s\"\n  shows \"loc \\<in> ReadableLocations q s\"\nproof (cases loc)\n  case LocReg\n  thus?thesis \n    using assms by auto\nnext\n  case (LocMem a)\n  have \"CapLoadableAddresses p \\<subseteq> CapLoadableAddresses q\"\n    using assms by auto\n  from getTranslateCapAddresses_le[OF this]\n  show ?thesis\n    using LocMem assms(2)\n    by auto\nqed\n\nlemma ReadableLocations_le:\n  assumes \"p \\<le> q\"\n  shows \"ReadableLocations p s \\<subseteq> ReadableLocations q s\"\nusing ReadableLocations_le_subsetD[OF assms]\nby auto\n\nsubsection \\<open>Readable capabilities\\<close>\n\ndefinition ReadableCaps where\n  \"ReadableCaps perm s \\<equiv>\n   {getCap loc s \n    |loc. loc \\<in> ReadableLocations perm s \\<and> getTag (getCap loc s)}\"\n\nlemma ReadableCapsI [intro?]:\n  assumes \"cap = getCap loc s\"\n      and \"loc \\<in> ReadableLocations perm s\"\n      and \"getTag cap\"\n  shows \"cap \\<in> ReadableCaps perm s\"\nusing assms\nunfolding ReadableCaps_def\nby auto\n\nlemma ReadableCapsI_loc [elim!]:\n  assumes \"loc \\<in> ReadableLocations perm s\"\n      and \"getTag (getCap loc s)\"\n  shows \"getCap loc s \\<in> ReadableCaps perm s\"\nusing assms\nunfolding ReadableCaps_def\nby auto\n\nlemma ReadableCapsE_tag [elim!]:\n  assumes \"cap \\<in> ReadableCaps perm s\"\n  shows \"getTag cap\"\nusing assms\nunfolding ReadableCaps_def\nby auto\n\nlemma ReadableCapsE_loc [elim]:\n  assumes \"cap \\<in> ReadableCaps perm s\"\n  obtains loc where \"cap = getCap loc s\"\n                    \"loc \\<in> ReadableLocations perm s\"\nusing assms\nunfolding ReadableCaps_def\nby auto\n\nlemma ReadableCaps_le_subsetD [elim]:\n  assumes \"p \\<le> q\"\n      and \"cap \\<in> ReadableCaps p s\"\n  shows \"cap \\<in> ReadableCaps q s\"\nusing assms\nunfolding ReadableCaps_def\nby auto\n\nlemma ReadableCaps_le:\n  assumes \"p \\<le> q\"\n  shows \"ReadableCaps p s \\<subseteq> ReadableCaps q s\"\nusing assms\nby auto\n\nsubsection \\<open>Generalised permissions of capabilities\\<close>\n\ndefinition GetAuthority :: \"Capability \\<Rightarrow> CompartmentAuthority\" where\n  \"GetAuthority cap \\<equiv> \n   if getTag cap\n   then let perms = getPerms cap in\n         \\<lparr>SystemRegisterAccess = Access_System_Registers perms,\n          ExecutableAddresses = if Permit_Execute perms then RegionOfCap cap else {},\n          LoadableAddresses = if Permit_Load perms then RegionOfCap cap else {},\n          CapLoadableAddresses = if Permit_Load_Capability perms then RegionOfCap cap else {},\n          StorableAddresses = if Permit_Store perms then RegionOfCap cap else {},\n          CapStorableAddresses = if Permit_Store_Capability perms then RegionOfCap cap else {},\n          LocalCapStorableAddresses = if Permit_Store_Local_Capability perms then RegionOfCap cap else {},\n          SealableTypes = if Permit_Seal perms then {t. ucast t \\<in> RegionOfCap cap} else {},\n          UnsealableTypes = if Permit_Unseal perms then {t. ucast t \\<in> RegionOfCap cap} else {}\\<rparr>\n   else bot\"\n\nlemma GetAuthority_accessors:\n  shows \"SystemRegisterAccess (GetAuthority cap) = \n         (getTag cap \\<and> Access_System_Registers (getPerms cap))\"\n    and \"ExecutableAddresses (GetAuthority cap) = \n         (if getTag cap \\<and> Permit_Execute (getPerms cap) \n          then RegionOfCap cap else {})\"\n    and \"LoadableAddresses (GetAuthority cap) = \n         (if getTag cap \\<and> Permit_Load (getPerms cap) \n          then RegionOfCap cap else {})\"\n    and \"CapLoadableAddresses (GetAuthority cap) = \n         (if getTag cap \\<and> Permit_Load_Capability (getPerms cap) \n          then RegionOfCap cap else {})\"\n    and \"StorableAddresses (GetAuthority cap) = \n         (if getTag cap \\<and> Permit_Store (getPerms cap) \n          then RegionOfCap cap else {})\"\n    and \"CapStorableAddresses (GetAuthority cap) = \n         (if getTag cap \\<and> Permit_Store_Capability (getPerms cap) \n          then RegionOfCap cap else {})\"\n    and \"LocalCapStorableAddresses (GetAuthority cap) = \n         (if getTag cap \\<and> Permit_Store_Local_Capability (getPerms cap) \n          then RegionOfCap cap else {})\"\n    and \"SealableTypes (GetAuthority cap) = \n         (if getTag cap \\<and> Permit_Seal (getPerms cap) \n          then {t. ucast t \\<in> RegionOfCap cap} else {})\"\n    and \"UnsealableTypes (GetAuthority cap) = \n         (if getTag cap \\<and> Permit_Unseal (getPerms cap) \n          then {t. ucast t \\<in> RegionOfCap cap} else {})\"\nunfolding GetAuthority_def Let_def\nby simp_all\n\nlemma GetAuthority_setMember_simp [simp]:\n  shows \"GetAuthority (setSealed (cap, v1)) = GetAuthority cap\"\n    and \"GetAuthority (setType (cap, v2)) = GetAuthority cap\"\n    and \"GetAuthority (setOffset (cap, v3)) = GetAuthority cap\"\n    and \"GetAuthority (setUPerms (cap, v5)) = GetAuthority cap\"\n    and \"GetAuthority (setTag (cap, False)) = bot\"\nunfolding GetAuthority_def\nby (simp_all cong: cong)\n\nlemma GetAuthority_le [intro]:\n  assumes \"cap' \\<le> cap\"\n  shows \"GetAuthority cap' \\<le> GetAuthority cap\"\nproof (cases \"getTag cap'\")\n  case False\n  hence \"GetAuthority cap' = bot\"\n    unfolding GetAuthority_def\n    by simp\n  thus ?thesis by auto\nnext\n  case True\n  have tag: \"getTag cap\" \n  and segment: \"RegionOfCap cap' \\<subseteq> RegionOfCap cap\" \n  and perms: \"getPerms cap' \\<le> getPerms cap\"\n    using True assms\n    by auto\n  have *: \"(if b then RegionOfCap cap' else {}) \\<subseteq> \n           (if b' then RegionOfCap cap else {})\"\n     if \"RegionOfCap cap' \\<noteq> {} \\<longrightarrow> b \\<longrightarrow> b'\" for b b'\n    using segment that by auto\n  have \"(if b then ({t. ucast t \\<in> RegionOfCap cap'}::ObjectType set) else {}) \\<subseteq> \n        (if b' then {t. ucast t \\<in> RegionOfCap cap} else {})\"\n     if \"RegionOfCap cap' \\<noteq> {} \\<longrightarrow> b \\<longrightarrow> b'\" for b b'\n    using segment that by auto\n  thus ?thesis \n    using True tag perms *\n    unfolding less_eq_CompartmentAuthority_ext_def\n    unfolding less_eq_Perms_ext_alt\n    by (strong_cong_simp add: GetAuthority_accessors)\nqed\n\ndefinition GetAuthorityOfCaps where\n  \"GetAuthorityOfCaps caps \\<equiv> Sup {GetAuthority cap |cap. cap \\<in> caps}\"\n\nlemma GetAuthorityOfCaps_empty [simp]:\n  shows \"GetAuthorityOfCaps {} = bot\"\nunfolding GetAuthorityOfCaps_def\nby simp\n\nlemma GetAuthorityOfCaps_singleton [simp]:\n  shows \"GetAuthorityOfCaps {cap} = GetAuthority cap\"\nunfolding GetAuthorityOfCaps_def\nby simp\n\nlemma GetAuthorityOfCaps_accessors [simp]:\n  shows \"SystemRegisterAccess (GetAuthorityOfCaps caps) = (\\<exists>cap\\<in>caps. SystemRegisterAccess (GetAuthority cap))\"\n    and \"ExecutableAddresses (GetAuthorityOfCaps caps) = (\\<Union>cap\\<in>caps. ExecutableAddresses (GetAuthority cap))\"\n    and \"LoadableAddresses (GetAuthorityOfCaps caps) = (\\<Union>cap\\<in>caps. LoadableAddresses (GetAuthority cap))\"\n    and \"CapLoadableAddresses (GetAuthorityOfCaps caps) = (\\<Union>cap\\<in>caps. CapLoadableAddresses (GetAuthority cap))\"\n    and \"StorableAddresses (GetAuthorityOfCaps caps) = (\\<Union>cap\\<in>caps. StorableAddresses (GetAuthority cap))\"\n    and \"CapStorableAddresses (GetAuthorityOfCaps caps) = (\\<Union>cap\\<in>caps. CapStorableAddresses (GetAuthority cap))\"\n    and \"LocalCapStorableAddresses (GetAuthorityOfCaps caps) = (\\<Union>cap\\<in>caps. LocalCapStorableAddresses (GetAuthority cap))\"\n    and \"SealableTypes (GetAuthorityOfCaps caps) = (\\<Union>cap\\<in>caps. SealableTypes (GetAuthority cap))\"\n    and \"UnsealableTypes (GetAuthorityOfCaps caps) = (\\<Union>cap\\<in>caps. UnsealableTypes (GetAuthority cap))\"\n    and \"more (GetAuthorityOfCaps caps) = Sup (more ` GetAuthority ` caps)\"\nunfolding GetAuthorityOfCaps_def\nby auto\n\nlemma GetAuthorityOfCaps_subset [elim!]:\n  assumes \"caps \\<subseteq> caps'\"\n  shows \"GetAuthorityOfCaps caps \\<le> GetAuthorityOfCaps caps'\"\nusing assms\nunfolding less_eq_CompartmentAuthority_ext_def\nunfolding GetAuthorityOfCaps_def\nunfolding Sup_CompartmentAuthority_ext_def\nby auto\n\n(*<*)\nend\n(*>*)\n", "meta": {"author": "CTSRD-CHERI", "repo": "l3-cheri-mips-proofs", "sha": "239c37ad1587caf261501478bbcd1293b9ecb7b7", "save_path": "github-repos/isabelle/CTSRD-CHERI-l3-cheri-mips-proofs", "path": "github-repos/isabelle/CTSRD-CHERI-l3-cheri-mips-proofs/l3-cheri-mips-proofs-239c37ad1587caf261501478bbcd1293b9ecb7b7/properties/CompartmentAuthority.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6187804337438501, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.27329861401810696}}
{"text": "(*  Title:      HOL/Auth/n_mutualExFsm_lemma_inv__2_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mutualExFsm Protocol Case Study*} \n\ntheory n_mutualExFsm_lemma_inv__2_on_rules imports n_mutualExFsm_lemma_on_inv__2\nbegin\nsection{*All lemmas on causal relation between inv__2*}\nlemma lemma_inv__2_on_rules:\n  assumes b1: \"r \\<in> rules N\" and b2: \"(\\<exists> p__Inv0. p__Inv0\\<le>N\\<and>f=inv__2  p__Inv0)\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have c1: \"(\\<exists> i. i\\<le>N\\<and>r=n_fsm  i)\"\n  apply (cut_tac b1, auto) done\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_fsm  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_fsmVsinv__2) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "lyj238Gmail", "repo": "newParaVerifier", "sha": "5c2d49bf8e6c46c60efa53c98b0ba5c577d59618", "save_path": "github-repos/isabelle/lyj238Gmail-newParaVerifier", "path": "github-repos/isabelle/lyj238Gmail-newParaVerifier/newParaVerifier-5c2d49bf8e6c46c60efa53c98b0ba5c577d59618/examples/n_mutualExFsm/n_mutualExFsm_lemma_inv__2_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6406358685621719, "lm_q2_score": 0.42632159254749036, "lm_q1q2_score": 0.27311690372846986}}
{"text": "theory System_scheduler\n  imports ext_Complementlemma AssumeGuarantee\nbegin\n\ntype_synonym tid = real\n\ndatatype status =\n  WAIT | READY | RUNNING\n\n\ndatatype estate =\n  Sch (pool:\"(real \\<times> tid) list\") (run_now:tid) (run_prior:real)\n| Task (status:status) (entered:nat) (task_prior:real)\n| None\n\nfun sched_push :: \"tid \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate\" where\n  \"sched_push t (Sch p rn rp) s = Sch (p @ [(s (CHR ''p''), t)]) rn rp\"\n| \"sched_push t (Task st ent tp) s = undefined\"\n| \"sched_push t None s = undefined\"\n\nfun sched_assign :: \"tid \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate\" where\n  \"sched_assign t (Sch p rn rp) s = Sch p t (s (CHR ''p''))\"\n| \"sched_assign t (Task st ent tp) s = undefined\"\n| \"sched_assign t None s = undefined\"\n\nfun get_max_default :: \"real \\<times> tid \\<Rightarrow> (real \\<times> tid) list \\<Rightarrow> real \\<times> tid\" where\n  \"get_max_default (prior, t) [] = (prior, t)\"\n| \"get_max_default (prior, t) ((prior2, t2) # rest) =\n    (if prior \\<ge> prior2 then\n       get_max_default (prior, t) rest\n     else\n       get_max_default (prior2, t2) rest)\"\n\nfun get_max :: \"(real \\<times> tid) list \\<Rightarrow> real \\<times> tid\" where\n  \"get_max [] = (-1, -1)\"\n| \"get_max ((prior, t) # rest) = get_max_default (prior, t) rest\"\n\nfun del_proc :: \"(real \\<times> tid) list \\<Rightarrow> tid \\<Rightarrow> (real \\<times> tid) list\" where\n  \"del_proc [] t = []\"\n| \"del_proc ((prior, t) # rest) t2 =\n    (if t = t2 then rest\n     else (prior, t) # del_proc rest t2)\"\n\nfun sched_get_max :: \"estate \\<Rightarrow> state \\<Rightarrow> estate\" where\n  \"sched_get_max (Sch p rn rp) s =\n    (let (prior, t) = get_max p in Sch (del_proc p t) t prior)\"\n| \"sched_get_max (Task st ent tp) s = undefined\"\n| \"sched_get_max None s = undefined\"\n\nfun sched_clear :: \"estate \\<Rightarrow> state \\<Rightarrow> estate\" where\n  \"sched_clear (Sch p rn rp) s = Sch [] (-1) (-1)\"\n| \"sched_clear (Task st ent tp) s = undefined\"\n| \"sched_clear None s = undefined\"\n\nfun sched_del_proc :: \"tid \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate\" where\n  \"sched_del_proc t (Sch p rn rp) s = Sch (del_proc p t) rn rp\"\n| \"sched_del_proc t (Task st ent tp) s = undefined\"\n| \"sched_del_proc t None s = undefined\"\n\ndefinition req_ch :: \"tid \\<Rightarrow> string\" where\n  \"req_ch tid = (\n    if tid = 1 then ''reqProcessor1''\n    else if tid = 2 then ''reqProcessor2''\n    else if tid = 3 then ''reqProcessor3''\n    else undefined)\"\n\ndefinition preempt_ch :: \"tid \\<Rightarrow> string\" where\n  \"preempt_ch tid = (\n    if tid = 1 then ''preempt1''\n    else if tid = 2 then ''preempt2''\n    else if tid = 3 then ''preempt3''\n    else undefined)\"\n\ndefinition run_ch :: \"tid \\<Rightarrow> string\" where\n  \"run_ch tid = (\n    if tid = 1 then ''run1''\n    else if tid = 2 then ''run2''\n    else if tid = 3 then ''run3''\n    else undefined)\"\n\ndefinition free_ch :: \"tid \\<Rightarrow> string\" where\n  \"free_ch tid = (\n    if tid = 1 then ''free1''\n    else if tid = 2 then ''free2''\n    else if tid = 3 then ''free3''\n    else undefined)\"\n\n\ndefinition exit_ch :: \"tid \\<Rightarrow> string\" where\n  \"exit_ch tid = (\n    if tid = 1 then ''exit1''\n    else if tid = 2 then ''exit2''\n    else if tid = 3 then ''exit3''\n    else undefined)\"\n\ninductive sched_assn :: \"estate \\<Rightarrow> state \\<Rightarrow> estate tassn\" where\n  \"sched_assn (Sch p rn rp) start_s []\"\n| \"start_es = Sch p rn rp \\<Longrightarrow>\n   rp \\<ge> prior \\<Longrightarrow>\n   t \\<in> {1, 2, 3} \\<Longrightarrow>\n   In\\<^sub>t (EState (start_es, start_s)) (req_ch t) prior blk1 \\<Longrightarrow>\n   sched_assn (sched_push t start_es start_s) start_s rest \\<Longrightarrow>\n   sched_assn start_es start_s (blk1 @ rest)\"\n| \"start_es = Sch p rn rp \\<Longrightarrow>\n   rp < prior \\<Longrightarrow>\n   t \\<in> {1, 2, 3} \\<Longrightarrow>\n   In\\<^sub>t (EState (start_es, start_s)) (req_ch t) prior blk1 \\<Longrightarrow>\n   if run_now start_es \\<noteq> -1 then\n     Out\\<^sub>t (EState (start_es, start_s)) (preempt_ch (run_now start_es)) 0 blk2\n   else\n     emp\\<^sub>t blk2 \\<Longrightarrow>\n   Out\\<^sub>t (EState (sched_assign t start_es (start_s(CHR ''p'' := prior)), start_s(CHR ''p'' := prior)))\n        (run_ch t) 0 blk3 \\<Longrightarrow>\n   sched_assn (sched_assign t start_es (start_s(CHR ''p'' := prior)))\n              (start_s(CHR ''p'' := prior)) rest \\<Longrightarrow>\n   sched_assn start_es start_s (blk1 @ blk2 @ blk3 @ rest)\"\n| \"start_es = Sch p rn rp \\<Longrightarrow>\n   length p > 0 \\<Longrightarrow>\n   In\\<^sub>t (EState (start_es, start_s)) (free_ch t) 0 blk1 \\<Longrightarrow>\n   Out\\<^sub>t (EState (sched_get_max start_es start_s, start_s)) \n        (run_ch (run_now (sched_get_max start_es start_s))) 0 blk2 \\<Longrightarrow>\n   sched_assn (sched_get_max start_es start_s) start_s rest \\<Longrightarrow>\n   sched_assn start_es start_s (blk1 @ blk2 @ rest)\"\n| \"start_es = Sch p rn rp \\<Longrightarrow>\n   length p = 0 \\<Longrightarrow>\n   In\\<^sub>t (EState (start_es, start_s)) (free_ch t) 0 blk1 \\<Longrightarrow>\n   sched_assn (sched_clear start_es start_s) start_s rest \\<Longrightarrow>\n   sched_assn start_es start_s (blk1 @ rest)\"\n| \"start_es = Sch p rn rp \\<Longrightarrow>\n   In\\<^sub>t (EState (start_es, start_s)) (exit_ch t) 0 blk1 \\<Longrightarrow> \n   sched_assn (sched_del_proc t start_es start_s) start_s rest \\<Longrightarrow> \n   sched_assn start_es start_s (blk1 @ rest)\"\n\n\ndefinition dispatch_ch :: \"tid \\<Rightarrow> string\" where\n  \"dispatch_ch tid = (\n    if tid = 1 then ''dis1''\n    else if tid = 2 then ''dis2''\n    else if tid = 3 then ''dis3''\n    else undefined)\"\n\ndefinition tid_set :: \"tid set\" where \"tid_set = {1,2,3}\"\n\nlemma ch_dist:\"dispatch_ch t \\<noteq> run_ch t\" \"dispatch_ch t \\<noteq> req_ch t\" \n              \"dispatch_ch t \\<noteq> exit_ch t\" \"dispatch_ch t \\<noteq> preempt_ch t\"\n              \"dispatch_ch t \\<noteq> free_ch t\"\n              \"run_ch t \\<noteq> dispatch_ch t\" \"req_ch t \\<noteq> dispatch_ch t\" \n              \"exit_ch t \\<noteq> dispatch_ch t\" \"preempt_ch t \\<noteq> dispatch_ch t\"\n              \"free_ch t \\<noteq> dispatch_ch t\"\n              if cond:\"t\\<in>tid_set\"\n  using cond\n  unfolding dispatch_ch_def run_ch_def req_ch_def exit_ch_def preempt_ch_def free_ch_def tid_set_def \n  by auto\n\ninductive task_assn :: \"tid \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate tassn\" where\n  \"task_assn t (Task st ent tp) start_s []\"\n| \"start_es = Task WAIT ent tp \\<Longrightarrow>\n   In\\<^sub>t (EState (start_es, start_s)) (dispatch_ch t) 0 blk1 \\<Longrightarrow>\n   task_assn t (Task READY 0 tp) (start_s(CHR ''t'' := 0)) rest \\<Longrightarrow>\n   task_assn t start_es start_s (blk1 @ rest)\"\n(*\n| \"start_es = Task WAIT ent tp \\<Longrightarrow>\n   (d::real) > 0 \\<Longrightarrow>\n   blk1 = WaitBlk (ereal d) (\\<lambda>_. EState (start_es, start_s)) ({}, {dispatch_ch t}) \\<Longrightarrow>\n   task_assn t start_es start_s rest \\<Longrightarrow>\n   task_assn t start_es start_s (blk1 # rest)\"\n*)\n(*\n| \"start_es = Task READY ent tp \\<Longrightarrow>\n   init_t = start_s (CHR ''t'') \\<Longrightarrow>\n   wt \\<le> 0.045 - init_t \\<Longrightarrow>\n   Out\\<^sub>t (EState (start_es, start_s)) (req_ch t) tp blk1 \\<Longrightarrow>\n   WaitIn\\<^sub>t wt start_es (\\<lambda>t. start_s(CHR ''t'' := init_t + t)) (run_ch t) 0 ({}, {run_ch t}) blk2 \\<Longrightarrow>\n   task_assn t (Task RUNNING ent tp) (start_s(CHR ''t'' := init_t + wt)) rest \\<Longrightarrow>\n   task_assn t start_es start_s (blk1 @ blk2 @ rest)\"\n*)\n| \"start_es = Task READY ent tp \\<Longrightarrow>\n   init_t = start_s (CHR ''t'') \\<Longrightarrow>\n   wt \\<le> 0.045 - init_t \\<Longrightarrow>\n   Waitout\\<^sub>t d (\\<lambda>_ . EState (start_es, start_s)) (req_ch t) tp ({req_ch t}, {}) blk1 \\<Longrightarrow>\n   d = 0 \\<longrightarrow> Waitin\\<^sub>t wt (\\<lambda>_ . EState (start_es, start_s(CHR ''t'' := init_t + t))) (run_ch t) 0 ({}, {run_ch t}) blk2 \\<Longrightarrow>\n   d = 0 \\<longrightarrow> task_assn t (Task RUNNING ent tp) (start_s(CHR ''t'' := init_t + wt)) rest \\<Longrightarrow>\n   task_assn t start_es start_s (blk1 @ blk2 @ rest)\"\n| \"start_es = Task READY ent tp \\<Longrightarrow>\n   init_t = start_s (CHR ''t'') \\<Longrightarrow>\n   wt = 0.045 - init_t \\<Longrightarrow>\n   Out\\<^sub>t (EState (start_es, start_s)) (req_ch t) tp blk1 \\<Longrightarrow>\n   Wait\\<^sub>t wt (\\<lambda>t. EState (start_es, start_s(CHR ''t'' := init_t + t))) ({run_ch t}, {}) blk2 \\<Longrightarrow>\n   Out\\<^sub>t (EState (start_es, start_s(CHR ''t'' := 0.45))) (exit_ch t) 0 blk3 \\<Longrightarrow>\n   task_assn t (Task WAIT ent tp) (start_s(CHR ''t'' := 0.45)) rest \\<Longrightarrow>\n   task_assn t start_es start_s (blk1 @ blk2 @ blk3 @ rest)\"\n| \"start_es = Task RUNNING 1 tp \\<Longrightarrow>\n   init_t = start_s (CHR ''t'') \\<Longrightarrow>\n   init_c = start_s (CHR ''c'') \\<Longrightarrow>\n   wt \\<le> 0.045 - init_t \\<Longrightarrow>\n   wt \\<le> 0.01 - init_c \\<Longrightarrow>\n   WaitIn\\<^sub>t wt start_es (\\<lambda>t. start_s(CHR ''t'' := init_t + t, CHR ''c'' := init_c + t))\n           (preempt_ch t) 0 ({preempt_ch t}, {}) blk1 \\<Longrightarrow>\n   task_assn t (Task READY 1 tp) (start_s(CHR ''t'' := init_t + wt, CHR ''c'' := init_c + wt))\n             rest \\<Longrightarrow>\n   task_assn t start_es start_s (blk1 @ rest)\"\n| \"start_es = Task RUNNING 1 tp \\<Longrightarrow>\n   init_t = start_s (CHR ''t'') \\<Longrightarrow>\n   init_c = start_s (CHR ''c'') \\<Longrightarrow>\n   if 0.045 - init_t \\<ge> 0.01 - init_c then\n     wt = 0.01 - init_c\n   else\n     wt = 0.045 - init_t \\<Longrightarrow>\n   Wait\\<^sub>t wt (\\<lambda>t. EState (start_es, start_s(CHR ''t'' := init_t + t, CHR ''c'' := init_c + t)))\n         ({preempt_ch t}, {}) blk1 \\<Longrightarrow>\n   Out\\<^sub>t (EState (start_es, start_s(CHR ''t'' := init_t + wt, CHR ''c'' := init_c + wt)))\n        (free_ch t) 0 blk2 \\<Longrightarrow>\n   task_assn t (Task WAIT 1 tp) (start_s(CHR ''t'' := init_t + wt, CHR ''c'' := init_c + wt))\n             rest \\<Longrightarrow>\n   task_assn t start_es start_s (blk1 @ blk2 @ rest)\"\n\ninductive_cases task_assnE: \"task_assn t task_es task_s tr\"\ninductive_cases task_assn_waitE: \"task_assn t (Task WAIT x2 x3) task_s tr1\"\n\n(*\nt := 0\n(\n  <t_dot = 1 & t < 0.045>;\n  t := 0;\n  dis[tid]!\n)**\n*)\n\ninductive dispatch_assn :: \"tid \\<Rightarrow> state \\<Rightarrow> estate tassn\" where\n  \"dispatch_assn t start_s []\"\n  (* Case for finishing a period *)\n| \"init_t = start_s (CHR ''t'') \\<Longrightarrow>\n   init_t < 0.045 \\<Longrightarrow>\n   wt = 0.045 - init_t \\<Longrightarrow>\n   Wait\\<^sub>t wt (\\<lambda>t. EState (None, start_s(CHR ''t'' := init_t + t))) ({}, {}) blk1 \\<Longrightarrow>\n   Out\\<^sub>t (EState (None, start_s(CHR ''t'' := 0))) (dispatch_ch t) 0 blk2 \\<Longrightarrow>\n   dispatch_assn t (start_s(CHR ''t'' := 0)) rest \\<Longrightarrow>\n   dispatch_assn t start_s (blk1 @ blk2 @ rest)\"\n  (* Case for running part of a period \n| \"init_t = start_s (CHR ''t'') \\<Longrightarrow>\n   init_t < 0.045 \\<Longrightarrow>\n   wt < 0.045 - init_t \\<Longrightarrow>\n   wt \\<ge> 0 \\<Longrightarrow>\n   Wait\\<^sub>t wt (\\<lambda>t. EState (None, start_s(CHR ''t'' := init_t + t))) ({}, {}) blk1 \\<Longrightarrow>\n   dispatch_assn t (start_s(CHR ''t'' := init_t + wt)) rest \\<Longrightarrow>\n   dispatch_assn t start_s (blk1 @ rest)\"*)\n\ninductive task_dis_assn :: \"tid \\<Rightarrow> state \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate tassn\" where\n  \"task_dis_assn t dis_s task_es task_s []\"\n| \"task_es = Task WAIT ent tp \\<Longrightarrow>\n   dis_t = dis_s (CHR ''t'') \\<Longrightarrow>\n   wt = 0.045 - dis_t \\<Longrightarrow>\n   Wait\\<^sub>t wt (\\<lambda>t. ParState (EState (task_es, task_s))\n                          (EState (None, dis_s(CHR ''t'' := dis_t + t))))\n         ({}, {dispatch_ch t}) blk1 \\<Longrightarrow>\n   IO\\<^sub>t (dispatch_ch t) 0 blk2 \\<Longrightarrow>\n   task_dis_assn t (dis_s(CHR ''t'' := 0)) (Task READY 0 tp) (task_s(CHR ''t'' := 0))\n                 rest \\<Longrightarrow>\n   task_dis_assn t dis_s task_es task_s (blk1 @ blk2 @ rest)\"\n| \"task_es = Task READY ent tp \\<Longrightarrow>\n   init_task_t = task_s (CHR ''t'') \\<Longrightarrow>\n   dis_t = dis_s (CHR ''t'') \\<Longrightarrow>\n   wt \\<le> 0.045 - init_task_t \\<Longrightarrow>\n   Waitout\\<^sub>t d (\\<lambda>_. ParState (EState (task_es, task_s))(EState (None,dis_s(CHR ''t'' := dis_t + t)))) (req_ch t) tp ({req_ch t}, {}) blk1 \\<Longrightarrow>\n   d=0 \\<longrightarrow> Waitin\\<^sub>t wt (\\<lambda>t. ParState (EState (task_es,task_s(CHR ''t'' := init_t + t))) (EState (None, dis_s(CHR ''t'' := dis_t + t)))) (run_ch t) 0 ({}, {run_ch t}) blk2 \\<Longrightarrow>\n   d=0 \\<longrightarrow> task_dis_assn t (dis_s(CHR ''t'' := dis_t + wt)) (Task RUNNING ent tp) (task_s(CHR ''t'' := init_t + wt)) rest \\<Longrightarrow>\n   task_dis_assn t dis_s task_es task_s (blk1 @ blk2 @ rest)\"\n| \"task_es = Task READY ent tp \\<Longrightarrow>\n   init_task_t = task_s (CHR ''t'') \\<Longrightarrow>\n   init_dis_t = dis_s (CHR ''t'') \\<Longrightarrow>\n   wt = 0.045 - init_task_t \\<Longrightarrow>\n   Out\\<^sub>t (EState (task_es, task_s)) (req_ch t) tp blk1 \\<Longrightarrow>\n   Wait\\<^sub>t wt (\\<lambda>t. ParState (EState (task_es,task_s(CHR ''t'' := init_t + t))) (EState (None, dis_s(CHR ''t'' := dis_t + t)))) ({run_ch t}, {}) blk2 \\<Longrightarrow>\n   Out\\<^sub>t (EState (task_es, task_s(CHR ''t'' := 0.45))) (exit_ch t) 0 blk3 \\<Longrightarrow>\n   task_dis_assn t (dis_s(CHR ''t'' := dis_t + wt)) (Task WAIT ent tp) (task_s(CHR ''t'' := init_t + wt)) rest \\<Longrightarrow>\n   task_dis_assn t dis_s task_es task_s (blk1 @ blk2 @ blk3 @ rest)\"\n| \"task_es = Task RUNNING 1 tp \\<Longrightarrow>\n   init_t = task_s (CHR ''t'') \\<Longrightarrow>\n   init_c = task_s (CHR ''c'') \\<Longrightarrow>\n   wt \\<le> 0.045 - init_t \\<Longrightarrow>\n   wt \\<le> 0.01 - init_c \\<Longrightarrow>\n   init_dis_t = dis_s (CHR ''t'') \\<Longrightarrow>\n   Waitin\\<^sub>t wt  (\\<lambda>t. EState (task_es,task_s(CHR ''t'' := init_t + t, CHR ''c'' := init_c + t)))\n           (preempt_ch t) 0 ({preempt_ch t}, {}) blk1 \\<Longrightarrow>\n   task_dis_assn t (dis_s(CHR ''t'' := dis_t + wt)) (Task READY 1 tp) (task_s(CHR ''t'' := init_t + wt, CHR ''c'' := init_c + wt))\n             rest \\<Longrightarrow>\n   task_dis_assn t dis task_es task_s (blk1 @ rest)\"\n| \"start_es = Task RUNNING 1 tp \\<Longrightarrow>\n   init_t = task_s (CHR ''t'') \\<Longrightarrow>\n   init_c = task_s (CHR ''c'') \\<Longrightarrow>\n   if 0.045 - init_t \\<ge> 0.01 - init_c then\n     wt = 0.01 - init_c\n   else\n     wt = 0.045 - init_t \\<Longrightarrow>\n   init_dis_t = dis_s (CHR ''t'') \\<Longrightarrow>\n   Wait\\<^sub>t wt (\\<lambda>t. EState (task_es, task_s(CHR ''t'' := init_t + t, CHR ''c'' := init_c + t)))\n         ({preempt_ch t}, {}) blk1 \\<Longrightarrow>\n   Out\\<^sub>t (EState (task_es, task_s(CHR ''t'' := init_t + wt, CHR ''c'' := init_c + wt)))\n        (free_ch t) 0 blk2 \\<Longrightarrow>\n   task_dis_assn t (dis_s(CHR ''t'' := dis_t + wt)) (Task WAIT 1 tp) (task_s(CHR ''t'' := init_t + wt, CHR ''c'' := init_c + wt))\n             rest \\<Longrightarrow>\n   task_dis_assn t dis_s task_es task_s (blk1 @ blk2 @ rest)\"\n\n(*\nlemma combine_task_dis:\n  \"task_assn t task_es task_s tr1 \\<Longrightarrow>\n   dispatch_assn t' dis_s tr2 \\<Longrightarrow>\n   t \\<in> tid_set \\<Longrightarrow>\n   t = t' \\<Longrightarrow> \n   combine_blocks {dispatch_ch t} tr1 tr2 tr \\<Longrightarrow>\n   task_dis_assn t dis_s task_es task_s tr\"\nproof (induction arbitrary: tr tr2 dis_s rule: task_assn.induct)\n  case (1 t st ent tp task_s)\n  note a1 = 1\n  then show ?case\n  proof (induction arbitrary: tr rule: dispatch_assn.induct)\n    case (1 t' start_s)\n    have c1: \"tr = []\"\n      using 1 by (auto elim: sync_elims)\n    show ?case\n      apply (subst c1)\n      by (auto intro: task_dis_assn.intros)\n  next\n    case (2 init_t start_s wt blk1 t blk2 rest)\n    then show ?case\n      apply(auto simp add:wait_assn.simps out_assn.simps)\n      by (auto elim: sync_elims)\n  qed\nnext\n  case (2 task_es ent tp task_s t blk1 rest)\n  note a2 = 2\n  from a2(5,6,7,8) show ?case\n  proof (induction arbitrary: tr  rule: dispatch_assn.induct)\n    case (1 t' start_s)\n    then show ?case \n      using a2\n      apply(auto elim!: in_assn.cases)\n      by(auto elim!: sync_elims)\n  next\n    case (2 init_t start_s wt blk1' t' blk2' rest')\n    note b2 = 2\n    show ?case \n      thm b2\n      thm a2\n      using a2(2)\n      using b2(2,3,4,5) using b2(8,9,10)\n      apply (auto elim!:in_assn.cases wait_assn.cases out_assn.cases)\n      subgoal apply (auto elim!: sync_elims) done\n      subgoal premises pre for d\n      proof(cases \"(9 / 200 - init_t) > d\")\n        case True\n        then have \"ereal (9 / 200 - init_t) > ereal d\"\n          by auto\n        thm pre\n        then obtain tr' where \"tr = WaitBlk (ereal d)\n            (\\<lambda>t. ParState (EState (task_es, task_s))\n                  (EState (estate.None, start_s(CHR ''t'' := init_t + t))))\n            ({}, {dispatch_ch t'}) # tr' \"\n           \"combine_blocks {dispatch_ch t'} (InBlock (dispatch_ch t') 0 # rest)\n            (WaitBlk (ereal (9 / 200 - init_t - d))\n              (\\<lambda>t. EState (estate.None, start_s(CHR ''t'' := init_t + (t + d)))) ({}, {}) #\n             OutBlock (dispatch_ch t') 0 # rest')\n            tr'\"\n          using pre\n          apply(elim combine_blocks_waitE3) by auto\n        then show ?thesis by (auto elim!: sync_elims)\n      next\n        case False\n        note false1 = False\n        show ?thesis \n        proof (cases \"d = 9 / 200 - init_t\")\n          case True\n          then obtain tr' where tr':\"tr = WaitBlk (ereal d)\n            (\\<lambda>t. ParState (EState (task_es, task_s))\n                  (EState (estate.None, start_s(CHR ''t'' := init_t + t))))\n            ({}, {dispatch_ch t'}) # tr' \"\n           \"combine_blocks {dispatch_ch t'} (InBlock (dispatch_ch t') 0 # rest)\n            (OutBlock (dispatch_ch t') 0 # rest')\n            tr'\"\n          using pre\n          by(auto elim!: combine_blocks_waitE2) \n        then obtain tr'' where tr'':\"tr' = IOBlock (dispatch_ch t') 0 # tr'' \"\n                               \"combine_blocks {dispatch_ch t'} rest rest' tr''\"\n          apply(elim combine_blocks_pairE) by auto\n        have 1:\"Wait\\<^sub>t (9 / 200 - start_s CHR ''t'')\n      (\\<lambda>t. ParState (EState (Task WAIT ent tp, task_s))\n            (EState (estate.None, start_s(CHR ''t'' := start_s CHR ''t'' + t))))\n      ({}, {dispatch_ch t'})\n      [WaitBlk (ereal (9 / 200 - start_s CHR ''t''))\n        (\\<lambda>t. ParState (EState (Task WAIT ent tp, task_s))\n              (EState (estate.None, start_s(CHR ''t'' := start_s CHR ''t'' + t))))\n        ({}, {dispatch_ch t'})]\"\n          using b2 \n          using True pre(9) wait_assn.intros(1) by blast\n        have 2:\"IO\\<^sub>t (dispatch_ch t') 0 [IOBlock (dispatch_ch t') 0]\"\n          by (simp add: io_assn.intros)\n        have 3:\"task_dis_assn t' (start_s(CHR ''t'' := 0)) (Task READY 0 tp) (task_s(CHR ''t'' := 0))\n      tr''\"\n          using a2(4)[of \"(start_s(CHR ''t'' := 0))\" rest' tr'']\n          using a2(6,7) b2(6,9) tr'' \n          by fastforce\n        show ?thesis \n          using task_dis_assn.intros(2)[OF a2(1),of init_t start_s wt task_s t' \"[WaitBlk (ereal d)\n        (\\<lambda>t. ParState (EState (task_es, task_s))\n              (EState (estate.None, start_s(CHR ''t'' := init_t + t)))) \n        ({}, {dispatch_ch t'})]\" \"[IOBlock (dispatch_ch t') 0]\" tr'' ]\n          apply(simp add:a2 b2 True 1 2 3)\n          using tr' tr'' \n          using True a2(1) b2(1) by force\n        next\n          case False\n          then have \"(9 / 200 - init_t) < d\"\n            using false1 by auto\n          then obtain tr' where \"tr = WaitBlk (ereal (9 / 200 - init_t))\n            (\\<lambda>t. ParState (EState (task_es, task_s))\n                  (EState (estate.None, start_s(CHR ''t'' := init_t + t))))\n            ({}, {dispatch_ch t'}) # tr' \"\n           \"combine_blocks {dispatch_ch t'} (WaitBlk (ereal (9 / 200 - init_t - d))\n              (\\<lambda>t. EState (task_es, task_s)) ({}, {dispatch_ch t'}) # InBlock (dispatch_ch t') 0 # rest)\n            (OutBlock (dispatch_ch t') 0 # rest')\n            tr'\"\n          using pre\n          apply(elim combine_blocks_waitE4) apply auto \n          by (meson combine_blocks_pairE2' insertI1)\n        then show ?thesis \n          by (auto elim!: sync_elims)\n        qed\n      qed\n      subgoal\n        by (auto elim!: sync_elims)\n      subgoal premises pre for d db\n      proof (cases \"db > 9 / 200 - init_t\")\n        case True\n        thm pre\n        then obtain tr' where \"combine_blocks {dispatch_ch t'}\n     (WaitBlk (ereal db-(9 / 200 - init_t)) (\\<lambda>_. EState (task_es, task_s)) ({}, {dispatch_ch t'}) #\n      InBlock (dispatch_ch t') 0 # rest)\n     (WaitBlk (ereal d) (\\<lambda>_. EState (estate.None, start_s(CHR ''t'' := 0)))\n       ({dispatch_ch t'}, {}) #\n      OutBlock (dispatch_ch t') 0 # rest') tr'\"\n          using pre(4,6,8,10) by(auto elim: combine_blocks_waitE4)\n        then show ?thesis \n          by(auto elim!: sync_elims) \n      next\n        case False\n        note false1 = False\n        show ?thesis \n        proof (cases \"9 / 200 - init_t = db\")\n          case True\n          then obtain tr' where \"combine_blocks {dispatch_ch t'}\n     (InBlock (dispatch_ch t') 0 # rest)\n     (WaitBlk (ereal d) (\\<lambda>_. EState (estate.None, start_s(CHR ''t'' := 0)))\n       ({dispatch_ch t'}, {}) #\n      OutBlock (dispatch_ch t') 0 # rest') tr'\"\n          using pre(4,6,8,10) by(auto elim: combine_blocks_waitE2)\n        then show ?thesis \n          by(auto elim!: sync_elims) \n        next\n          case False\n          then have \"9 / 200 - init_t > db\" \n            using false1 by auto\n          then obtain tr' where \"combine_blocks {dispatch_ch t'}\n        (InBlock (dispatch_ch t') 0 # rest)\n        (WaitBlk (ereal (9 / 200 - init_t) - ereal db)\n          (\\<lambda>t. EState (estate.None, start_s(CHR ''t'' := init_t + (t + db)))) ({}, {}) #\n         WaitBlk (ereal d) (\\<lambda>_. EState (estate.None, start_s(CHR ''t'' := 0)))\n          ({dispatch_ch t'}, {}) #\n         OutBlock (dispatch_ch t') 0 # rest') tr'\"\n            using pre(4,6,8,10) by(auto elim: combine_blocks_waitE3)\n          then show ?thesis \n            by(auto elim!: sync_elims)\n        qed\n      qed\n      done\n  qed\nnext\n  case (3 task_es ent tp init_t task_s wt d t blk1 blk2 rest)\n  note a3 = 3\n  from a3(7,8,9,10) show ?case \n  proof (induction arbitrary: tr  rule: dispatch_assn.induct)\n    case (1 t' start_s)\n    note b1 = 1\n    show ?case \n      thm a3\n      thm b1\n      using b1(1,2,3)\n      using a3(4,5)\n      apply (auto elim!:in_assn.cases waitin_assn.cases waitout_assn.cases)\n                 apply (auto elim!: sync_elims)\n      apply (auto simp add: ch_dist) \n      subgoal premises pre for tra \n      proof-\n        thm pre\n        have 1:\"task_dis_assn t' start_s (Task RUNNING ent tp) (task_s(CHR ''t'' := init_t + wt)) tra\"\n          using a3(6,8,9) \n          apply(simp add: pre)\n          using dispatch_assn.intros(1)[of t' start_s]\n          using pre(8)\n          by (smt (verit, best) \"3.IH\" a3(9) b1(1) pre(4) pre(6))\n      obtain start_t where startt:\"start_t = start_s CHR ''t''\"\n        by auto\n      have 2:\"wt \\<le> 9 / 200 - task_s CHR ''t''\"\n        using a3 by auto\n      have 3:\"task_dis_assn t' start_s task_es task_s (blk1 @ blk2 @ tra)\"\n        apply(rule task_dis_assn.intros(3)[where d=0])\n              apply(rule a3(1))\n             apply(rule a3(2))\n            apply(rule startt)\n           apply(rule a3(3))\n          apply auto\n          prefer 3\n        apply(simp add:pre(6) startt)\n        apply(rule 1)\n        sorry\n      then show ?thesis using pre by auto\n    qed\n    done\n  next\n    case (2 init_t' start_s wt' blk1' t' blk2' rest')\n    note b2 = 2\n    show ?case \n      thm b2\n      thm a3\n      thm task_dis_assn.intros(3)\n      using b2(4,5,8,9,10) a3(4,5)\n      apply auto\n      subgoal premises pre \n        thm pre\n        using pre(6,7)\n        apply(auto elim!:waitout_assn.cases)\n        using task_dis_assn.intros(3)[of task_es ent tp init_t task_s init_t' start_s wt d t]\n        apply(auto simp add: a3(1,2,3) b2(1))\n        sorry\n      sorry\n      \n  qed\nnext\n  case (4 start_es ent tp init_t start_s wt t blk1 blk2 blk3 rest)\n  then show ?case sorry\nnext\n  case (5 start_es tp init_t start_s init_c wt t blk1 rest)\n  then show ?case sorry\nnext\n  case (6 start_es tp init_t start_s init_c wt t blk1 blk2 rest)\n  then show ?case sorry\nqed\n    \n*)\n\n\n(*\n\ninductive sch_task_assn :: \"estate \\<Rightarrow> state \\<Rightarrow> tid \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> state \\<Rightarrow> estate tassn\" where\n  \"sch_task_assn (Sch p rn rp) sch_s t (Task st ent tp) task_s dis_s []\"\n| \"sch_es = Sch p rn rp \\<Longrightarrow>\n   task_es = Task WAIT ent tp \\<Longrightarrow>\n   wt = 0.045 - dis_t \\<Longrightarrow>\n   Wait\\<^sub>t wt (\\<lambda>t. ParState (EState (task_es, task_s))\n                          (EState (None, dis_s(CHR ''t'' := dis_t + t))))\n         ({}, {}) blk1 \\<Longrightarrow>\n   IO\\<^sub>t (dis_ch t) 0 blk2 \\<Longrightarrow>\n   sch_task_assn sch_es sch_s t (Task READY 0 tp) (task_s(CHR ''t'' := 0)) (dis_s(CHR ''t'' := 0))\n                 rest \\<Longrightarrow>\n   sch_task_assn sch_es sch_s t task_es task_s dis_s (blk1 @ blk2 @ rest)\"\n| \"sch_es = Sch p rn rp \\<Longrightarrow>\n   task_es = Task READY ent tp \\<Longrightarrow>\n   init_task_t = task_s (CHR ''t'') \\<Longrightarrow>\n   init_dis_t = dis_s (CHR ''t'') \\<Longrightarrow>\n   rp \\<ge> f(tid) \\<Longrightarrow>\n   wt \\<le> 0.045 - init_task_t \\<Longrightarrow>\n   IO\\<^sub>t  (req_ch t) tp blk1 \\<Longrightarrow>\n   Waitin\\<^sub>t wt (\\<lambda>t. ParState (EState (task_es,task_s(CHR ''t'' := init_t + t))) (EState (None, dis_s(CHR ''t'' := dis_t + t)))) (run_ch t) 0 ({run_ch t}, {}) blk2 \\<Longrightarrow>\n   sch_task_assn \n        (sched_push t sch_es (sch_s(CHR ''p'' := f(tid)))) \n              (sch_s(CHR ''p'' := f(tid))) t  \n        (Task RUNNING ent tp) (task_s(CHR ''t'' := init_t + wt)) \n                    (dis_s(CHR ''t'' := dis_t + wt)) rest \\<Longrightarrow>\n   sch_task_assn sch_es sch_s t task_es task_s dis_s (blk1 @ blk2 @ rest)\"\n| \"sch_es = Sch p rn rp \\<Longrightarrow>\n   task_es = Task READY ent tp \\<Longrightarrow>\n   init_task_t = task_s (CHR ''t'') \\<Longrightarrow>\n   init_dis_t = dis_s (CHR ''t'') \\<Longrightarrow>\n   rp < f(tid) \\<Longrightarrow>\n   wt \\<le> 0.045 - init_task_t \\<Longrightarrow>\n   IO\\<^sub>t  (req_ch t) tp blk1 \\<Longrightarrow>\n   if run_now start_es \\<noteq> -1 then\n     Out\\<^sub>t (EState (start_es, start_s)) (preempt_ch (run_now start_es)) 0 blk2\n   else\n     emp\\<^sub>t blk2 \\<Longrightarrow>\n   IO\\<^sub>t  (run_ch t) 0  blk3 \\<Longrightarrow>\n   sch_task_assn sch_es (sch_s(CHR ''p'' := f(tid))) t  \n        (Task RUNNING ent tp) (task_s(CHR ''t'' := init_t + wt)) \n          (dis_s(CHR ''t'' := dis_t + wt)) rest \\<Longrightarrow>\n   sch_task_assn sch_es sch_s  t  task_es task_s dis_s (blk1 @ blk2 @blk3 @ rest)\"\n\n\n\n*)\n\nfun dispatch_assn' :: \"tid \\<Rightarrow> nat \\<Rightarrow> real \\<Rightarrow> state \\<Rightarrow> estate tassn\" where\n  \"dispatch_assn' t 0 pd start_s tr \\<longleftrightarrow> (emp\\<^sub>t tr)\"\n  (* Case for finishing a period *)\n| \"dispatch_assn' t (Suc k) pd start_s tr \\<longleftrightarrow> \n   wait_orig_assn (pd-start_s (CHR ''t''))\n                  (\\<lambda>t. EState (None, start_s(CHR ''t'' := start_s (CHR ''t'') + t))) ({}, {})\n   (out_orig_assn (dispatch_ch t) 0 (EState (None, start_s(CHR ''t'' := 0))) \n   (dispatch_assn' t k pd (start_s(CHR ''t'' := 0)))) tr\"\n\ndefinition up_ent_c :: \"nat \\<Rightarrow> real \\<Rightarrow> real\" where\n  \"up_ent_c ent c = (if ent = 0 then 0 else c)\"\n\nfun task_assn' :: \"tid \\<Rightarrow> nat \\<Rightarrow> real \\<Rightarrow> real \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate tassn\" where\n  \"task_assn' t 0 pd pc (Task st ent tp) start_s tr \\<longleftrightarrow> (emp\\<^sub>t tr) \"\n| \"task_assn' t (Suc k) pd pc (Task WAIT ent tp) start_s tr \\<longleftrightarrow>\n   in_vassm_assn (dispatch_ch t) {0} (EState (Task WAIT ent tp, start_s))\n   (\\<lambda>_ . task_assn' t k pd pc (Task READY 0 tp) (start_s(CHR ''t'' := 0))) tr\"\n| \"task_assn' t (Suc k) pd pc (Task READY ent tp) start_s tr \\<longleftrightarrow>\n   out_0assm_assn (req_ch t) tp \n     (waitin_tguar'_vassm'_assn {0..<pd-start_s (CHR ''t'')}\n          (\\<lambda>t . EState (Task READY ent tp, start_s(CHR ''t'' := start_s (CHR ''t'') + t)))\n          ({}, {run_ch t}) (run_ch t) {0}\n     (\\<lambda> v d'. task_assn' t k pd pc (Task RUNNING 1 tp)\n          (start_s(CHR ''t'' := start_s (CHR ''t'') + d',\n                   CHR ''c'' := (up_ent_c ent (start_s (CHR ''c''))))))) tr \\<or> \n   out_0assm_assn (req_ch t) tp \n     (wait_orig_assn (pd - start_s (CHR ''t''))\n          (\\<lambda>t. EState (Task READY ent tp, start_s(CHR ''t'' := start_s (CHR ''t'') + t)))\n          ({}, {run_ch t}) \n     (out_0assm_rdy_assn (exit_ch t) 0 ({exit_ch t},{run_ch t})\n     (task_assn' t k pd pc (Task WAIT ent tp) (start_s(CHR ''t'' := pd))))) tr \\<or>\n   out_0assm_assn (req_ch t) tp \n     (wait_orig_assn (pd - start_s (CHR ''t''))\n          (\\<lambda>t. EState (Task READY ent tp, start_s(CHR ''t'' := start_s (CHR ''t'') + t)))\n          ({}, {run_ch t}) \n     (in_0assm_rdy_assn (run_ch t) {0}  ({exit_ch t},{run_ch t})\n     (task_assn' t k pd pc (Task RUNNING 1 tp) (start_s(CHR ''t'' := pd,CHR ''c'' := up_ent_c ent (start_s (CHR ''c''))))))) tr\"\n| \"task_assn' t (Suc k) pd pc (Task RUNNING ent tp) start_s tr \\<longleftrightarrow>\n   (if ent = 1 then\n   waitin_tguar'_vassm'_assn ({0..< pd - start_s (CHR ''t'')} \n                            \\<inter> {0..< pc - start_s (CHR ''c'')})\n     (\\<lambda>t. EState (Task RUNNING 1 tp, start_s(CHR ''t'' := start_s (CHR ''t'') + t,\n                                             CHR ''c'' := start_s (CHR ''c'') + t)))\n     ({}, {preempt_ch t}) (preempt_ch t) {0} \n   (\\<lambda> v d. task_assn' t k pd pc (Task READY 1 tp)\n     (start_s(CHR ''t'' := start_s (CHR ''t'') + d,\n              CHR ''c'' := start_s (CHR ''c'') + d))) tr\n   \\<or> \n   wait_orig_assn (min (pd-start_s (CHR ''t'')) (pc-start_s (CHR ''c'')))\n     (\\<lambda>t. EState (Task RUNNING 1 tp, start_s(CHR ''t'' := start_s (CHR ''t'') + t,\n                                             CHR ''c'' := start_s (CHR ''c'') + t)))\n     ({}, {preempt_ch t}) \n   (out_0assm_srdy_assn (free_ch t) 0 ({free_ch t},{preempt_ch t})\n      (task_assn' t k pd pc (Task WAIT 1 tp) \n               (start_s(CHR ''t'' := start_s (CHR ''t'') + \n                              (min (pd-start_s (CHR ''t'')) (pc-start_s (CHR ''c''))),\n                        CHR ''c'' := start_s (CHR ''c'') + \n                              (min (pd-start_s (CHR ''t'')) (pc-start_s (CHR ''c''))))))) tr\n   else False)\"\n| \"task_assn' t n pd pc (Sch v va vb) start_s tr \\<longleftrightarrow> False\"\n| \"task_assn' t n pd pc None start_s tr \\<longleftrightarrow> False\"\n\n\nfun task_dis_assn' :: \"tid \\<Rightarrow> nat \\<Rightarrow> real \\<Rightarrow> real \\<Rightarrow> state \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate tassn\" where\n  \"task_dis_assn' t 0 pd pc dis_s (Task st ent tp) task_s tr \\<longleftrightarrow> (emp\\<^sub>t tr)\"\n| \"task_dis_assn' t (Suc k) pd pc dis_s (Task WAIT ent tp) task_s tr \\<longleftrightarrow>\n   wait_orig_assn (pd - dis_s (CHR ''t'')) \n            (\\<lambda>t. ParState (EState (Task WAIT ent tp, task_s))\n                          (EState (None, dis_s(CHR ''t'' := dis_s (CHR ''t'') + t))))\n                  ({}, {dispatch_ch t})\n   (task_dis_assn' t k pd pc (dis_s(CHR ''t'' := 0)) (Task READY 0 tp) (task_s(CHR ''t'' := 0)))tr\"\n| \"task_dis_assn' t (Suc k) pd pc dis_s (Task READY ent tp) task_s tr \\<longleftrightarrow>\n   out_0assm_assn (req_ch t) tp  \n   (waitin_tguar'_vassm'_assn {0..<pd-task_s (CHR ''t'')} \n           (\\<lambda>t. ParState (EState (Task READY ent tp, task_s(CHR ''t'' := task_s (CHR ''t'') + t))) \n                         (EState (None, dis_s(CHR ''t'' := dis_s (CHR ''t'') + t)))) \n                  ({}, {run_ch t}) (run_ch t) {0}\n   (\\<lambda> v d'. task_dis_assn' t k pd pc (dis_s(CHR ''t'' := dis_s (CHR ''t'') + d')) \n                               (Task RUNNING 1 tp) \n           (task_s(CHR ''t'' := task_s (CHR ''t'') + d',\n                   CHR ''c'' := up_ent_c ent (task_s (CHR ''c'')))))) tr \\<or> \n   out_0assm_assn (req_ch t) tp  \n   (wait_orig_assn (pd - task_s (CHR ''t'')) \n           (\\<lambda>t. ParState (EState (Task READY ent tp, task_s(CHR ''t'' := task_s (CHR ''t'') + t)))\n                         (EState (None, dis_s(CHR ''t'' := dis_s (CHR ''t'') + t)))) \n                  ({}, {run_ch t}) \n   (out_0assm_rdy_assn (exit_ch t) 0 ({dispatch_ch t, exit_ch t}, {run_ch t})\n   (task_dis_assn' t k pd pc (dis_s(CHR ''t'' := dis_s (CHR ''t'') + pd-dis_s (CHR ''t''))) \n                       (Task WAIT ent tp) (task_s(CHR ''t'' := pd))))) tr \\<or>\n   out_0assm_assn (req_ch t) tp  \n   (wait_orig_assn (pd - task_s (CHR ''t'')) \n           (\\<lambda>t. ParState (EState (Task READY ent tp, task_s(CHR ''t'' := task_s (CHR ''t'') + t)))\n                         (EState (None, dis_s(CHR ''t'' := dis_s (CHR ''t'') + t)))) \n                  ({}, {run_ch t}) \n   (in_0assm_rdy_assn (run_ch t) {0} ({dispatch_ch t, exit_ch t}, {run_ch t})\n   (task_dis_assn' t k pd pc (dis_s(CHR ''t'' := dis_s (CHR ''t'') + pd-task_s (CHR ''t''))) \n                       (Task RUNNING 1 tp) (task_s(CHR ''t'' := pd,CHR ''c'' := up_ent_c ent (task_s (CHR ''c''))))))) tr\"\n| \"task_dis_assn' t (Suc k) pd pc dis_s (Task RUNNING ent tp) task_s tr \\<longleftrightarrow>\n   (if ent = 1 then\n   waitin_tguar'_vassm'_assn ({0..< pd - task_s (CHR ''t'')} \\<inter> {0..< pc - task_s (CHR ''c'')})\n     (\\<lambda>t. ParState (EState (Task RUNNING 1 tp, task_s(CHR ''t'' := task_s (CHR ''t'') + t,\n                                             CHR ''c'' := task_s (CHR ''c'') + t)))\n                   (EState (None, dis_s(CHR ''t'' := dis_s (CHR ''t'') + t))))\n     ({}, {preempt_ch t}) (preempt_ch t) {0} \n   (\\<lambda> v d. task_dis_assn' t k pd pc (dis_s(CHR ''t'' := dis_s (CHR ''t'') + d)) (Task READY 1 tp)\n     (task_s(CHR ''t'' := task_s (CHR ''t'') + d, CHR ''c'' := task_s (CHR ''c'') + d))) tr\n   \\<or>\n   wait_orig_assn (min (pd-task_s (CHR ''t'')) (pc-task_s (CHR ''c'')))\n     (\\<lambda>t. ParState (EState (Task RUNNING 1 tp, task_s(CHR ''t'' := task_s (CHR ''t'') + t,\n                                             CHR ''c'' := task_s (CHR ''c'') + t)))\n                   (EState (None, dis_s(CHR ''t'' := dis_s (CHR ''t'') + t))))\n     ({}, {preempt_ch t}) \n   (out_0assm_srdy_assn (free_ch t) 0 ({free_ch t}, {preempt_ch t})\n      (task_dis_assn' t k pd pc (dis_s(CHR ''t'' := dis_s (CHR ''t'') + \n                   (min (pd-task_s (CHR ''t'')) (pc-task_s (CHR ''c''))))) \n                           (Task WAIT 1 tp)\n                           (task_s(CHR ''t'' := task_s (CHR ''t'') + \n                   (min (pd-task_s (CHR ''t'')) (pc-task_s (CHR ''c''))), \n                           CHR ''c'' := task_s (CHR ''c'') + \n                   (min (pd-task_s (CHR ''t'')) (pc-task_s (CHR ''c''))))))) tr\n   else False)\"\n| \"task_dis_assn' t n pd pc dis_s (Sch v va vb) task_s tr \\<longleftrightarrow> False\"\n| \"task_dis_assn' t n pd pc dis_s None task_s tr \\<longleftrightarrow> False\"\n\nthm task_assn'.induct\nthm task_assn'.simps\n\n\nlemma combine_out_0assm_wait_orig_out_orig:\n  assumes \"dh \\<notin> chs\"\n   and \"ch \\<in> chs\"\n shows \"combine_assn chs (out_0assm_assn dh v P) (wait_orig_assn d p rdy (out_orig_assn ch v' s Q))\n        \\<Longrightarrow>\\<^sub>t (out_0assm_assn dh v  \n            (combine_assn chs P (wait_orig_assn d p rdy (out_orig_assn ch v' s Q))))\"\n  apply(auto simp add:entails_tassn_def combine_assn_def)\n  subgoal for tr tr1 tr2\n    apply(cases rule: out_0assm_assn.cases[of dh v P tr1])\n      apply auto\n    subgoal for tr1'\n      apply(cases rule: wait_orig_assn.cases[of d p rdy \"(out_orig_assn ch v' s Q)\" tr2])\n        apply auto\n      subgoal\n        apply(cases rule: out_orig_assn.cases[of ch v' s Q tr2])\n          apply auto\n        subgoal for tr2'\n          using assms\n          apply(elim combine_blocks_unpairE1)\n            apply auto\n          apply(rule out_0assm_assn.intros(1))\n          by auto\n        subgoal for tr2' d\n          using assms\n          apply(elim combine_blocks_unpairE3)\n           apply auto\n          apply(rule out_0assm_assn.intros(1))\n          by auto\n        done\n      subgoal for tr2'\n        using assms\n          apply(elim combine_blocks_unpairE3)\n           apply auto\n          apply(rule out_0assm_assn.intros(1))\n          by auto\n        done\n      subgoal for d1 a b p1 tr1'\n        apply(cases rule: wait_orig_assn.cases[of d p rdy \"(out_orig_assn ch v' s Q)\" tr2])\n          apply auto\n        subgoal\n          apply(cases rule: out_orig_assn.cases[of ch v' s Q tr2])\n            apply auto\n          subgoal for tr2'\n            using assms\n            apply(auto elim:sync_elims)\n            done\n          subgoal for tr2' d2\n            apply(cases \"\\<not>compat_rdy (a,b) ({ch}, {})\")\n            subgoal\n              by(auto elim:sync_elims)\n            subgoal\n           apply(cases \"d1>d2\")\n           subgoal \n             apply(elim combine_blocks_waitE4)\n                apply auto\n             apply(rule out_0assm_assn.intros(2))\n             by auto\n           apply(cases \"d2=d1\")\n           subgoal \n             apply simp\n             apply(elim combine_blocks_waitE2)\n              apply auto\n             apply(rule out_0assm_assn.intros(2))\n             by auto\n           apply(elim combine_blocks_waitE3)\n              apply auto\n           apply(rule out_0assm_assn.intros(2))\n           by auto\n         done\n       done\n     subgoal for tr2'\n       apply(cases \"\\<not>compat_rdy (a,b) rdy\")\n            subgoal\n              by(auto elim:sync_elims)\n            subgoal\n           apply(cases \"d1>d\")\n           subgoal \n             apply(elim combine_blocks_waitE4)\n                apply auto\n             apply(rule out_0assm_assn.intros(2))\n             apply auto\n              apply (cases rdy)\n             by auto\n           apply(cases \"d=d1\")\n           subgoal \n             apply simp\n             apply(elim combine_blocks_waitE2)\n              apply auto\n             apply(rule out_0assm_assn.intros(2))\n              apply auto\n             apply(cases rdy)\n             by auto\n           apply(elim combine_blocks_waitE3)\n              apply auto\n           apply(rule out_0assm_assn.intros(2))\n            apply auto\n           apply(cases rdy)\n           by auto\n         done\n       done\n     done\n   done\n\nlemma combine_out_0assm_srdy_wait_orig_out_orig:\n  assumes \"dh \\<notin> chs\"\n   and \"ch \\<in> chs\"\n shows \"combine_assn chs (out_0assm_srdy_assn dh v rdy' P) (wait_orig_assn d p rdy (out_orig_assn ch v' s Q))\n        \\<Longrightarrow>\\<^sub>t (out_0assm_srdy_assn dh v rdy'\n            (combine_assn chs P (wait_orig_assn d p rdy (out_orig_assn ch v' s Q))))\"\n  apply(auto simp add:entails_tassn_def combine_assn_def)\n  subgoal for tr tr1 tr2\n    apply(cases rule: out_0assm_srdy_assn.cases[of dh v rdy' P tr1])\n      apply auto\n    subgoal for tr1'\n      apply(cases rule: wait_orig_assn.cases[of d p rdy \"(out_orig_assn ch v' s Q)\" tr2])\n        apply auto\n      subgoal\n        apply(cases rule: out_orig_assn.cases[of ch v' s Q tr2])\n          apply auto\n        subgoal for tr2'\n          using assms\n          apply(elim combine_blocks_unpairE1)\n            apply auto\n          apply(rule out_0assm_srdy_assn.intros(1))\n          by auto\n        subgoal for tr2' d\n          using assms\n          apply(elim combine_blocks_unpairE3)\n           apply auto\n          apply(rule out_0assm_srdy_assn.intros(1))\n          by auto\n        done\n      subgoal for tr2'\n        using assms\n          apply(elim combine_blocks_unpairE3)\n           apply auto\n          apply(rule out_0assm_srdy_assn.intros(1))\n          by auto\n        done\n      subgoal for d1 a b p1 tr1'\n        apply(cases rule: wait_orig_assn.cases[of d p rdy \"(out_orig_assn ch v' s Q)\" tr2])\n          apply auto\n        subgoal\n          apply(cases rule: out_orig_assn.cases[of ch v' s Q tr2])\n            apply auto\n          subgoal for tr2'\n            using assms\n            apply(auto elim:sync_elims)\n            done\n          subgoal for tr2' d2\n            apply(cases \"\\<not>compat_rdy (a, b) ({ch}, {})\")\n            subgoal\n              by(auto elim:sync_elims)\n            subgoal\n           apply(cases \"d1>d2\")\n           subgoal \n             apply(elim combine_blocks_waitE4)\n                apply auto\n             apply(rule out_0assm_srdy_assn.intros(2))\n             by auto\n           apply(cases \"d2=d1\")\n           subgoal \n             apply simp\n             apply(elim combine_blocks_waitE2)\n              apply auto\n             apply(rule out_0assm_srdy_assn.intros(2))\n             by auto\n           apply(elim combine_blocks_waitE3)\n              apply auto\n           apply(rule out_0assm_srdy_assn.intros(2))\n           by auto\n         done\n       done\n     subgoal for tr2'\n       apply(cases \"\\<not>compat_rdy (a,b) rdy\")\n            subgoal\n              by(auto elim:sync_elims)\n            subgoal\n           apply(cases \"d1>d\")\n           subgoal \n             apply(elim combine_blocks_waitE4)\n                apply auto\n             apply(rule out_0assm_srdy_assn.intros(2))\n             apply auto\n              apply (cases rdy)\n              apply auto\n             apply (cases rdy)\n             by auto\n           apply(cases \"d=d1\")\n           subgoal \n             apply simp\n             apply(elim combine_blocks_waitE2)\n              apply auto\n             apply(rule out_0assm_srdy_assn.intros(2))\n              apply auto\n              apply(cases rdy)\n              apply auto\n             apply (cases rdy)\n             by auto\n           apply(elim combine_blocks_waitE3)\n              apply auto\n           apply(rule out_0assm_srdy_assn.intros(2))\n            apply auto\n            apply(cases rdy)\n            apply auto\n             apply (cases rdy)\n           by auto\n         done\n       done\n     done\n   done\n\nlemma combine_in_0assm_wait_orig_out_orig:\n  assumes \"dh \\<notin> chs\"\n   and \"ch \\<in> chs\"\n shows \"combine_assn chs (in_0assm_assn dh v P) (wait_orig_assn d p rdy (out_orig_assn ch v' s Q))\n        \\<Longrightarrow>\\<^sub>t (in_0assm_assn dh v  \n            (combine_assn chs P (wait_orig_assn d p rdy (out_orig_assn ch v' s Q))))\"\n  apply(auto simp add:entails_tassn_def combine_assn_def)\n  subgoal for tr tr1 tr2\n    apply(cases rule: in_0assm_assn.cases[of dh v P tr1])\n      apply auto\n    subgoal for tr1'\n      apply(cases rule: wait_orig_assn.cases[of d p rdy \"(out_orig_assn ch v' s Q)\" tr2])\n        apply auto\n      subgoal\n        apply(cases rule: out_orig_assn.cases[of ch v' s Q tr2])\n          apply auto\n        subgoal for tr2'\n          using assms\n          apply(elim combine_blocks_unpairE1)\n            apply auto\n          apply(rule in_0assm_assn.intros(1))\n          by auto\n        subgoal for tr2' d\n          using assms\n          apply(elim combine_blocks_unpairE3)\n           apply auto\n          apply(rule in_0assm_assn.intros(1))\n          by auto\n        done\n      subgoal for tr2'\n        using assms\n          apply(elim combine_blocks_unpairE3)\n           apply auto\n          apply(rule in_0assm_assn.intros(1))\n          by auto\n        done\n      subgoal for w tr1'\n        apply(cases rule: wait_orig_assn.cases[of d p rdy \"(out_orig_assn ch v' s Q)\" tr2])\n          apply auto\n        subgoal\n        apply(cases rule: out_orig_assn.cases[of ch v' s Q tr2])\n          apply auto\n        subgoal for tr2'\n          using assms\n          apply(elim combine_blocks_unpairE1)\n            apply auto\n          apply(rule in_0assm_assn.intros(2))\n          by auto\n        subgoal for tr2' d\n          using assms\n          apply(elim combine_blocks_unpairE3)\n           apply auto\n          apply(rule in_0assm_assn.intros(2))\n          by auto\n        done\n      subgoal for tr2'\n        using assms\n          apply(elim combine_blocks_unpairE3)\n           apply auto\n          apply(rule in_0assm_assn.intros(2))\n        by auto\n      done\n      subgoal for d1 a b p1 tr1'\n        apply(cases rule: wait_orig_assn.cases[of d p rdy \"(out_orig_assn ch v' s Q)\" tr2])\n          apply auto\n        subgoal\n          apply(cases rule: out_orig_assn.cases[of ch v' s Q tr2])\n            apply auto\n          subgoal for tr2'\n            using assms\n            apply(auto elim:sync_elims)\n            done\n          subgoal for tr2' d2\n            apply(cases \"\\<not>compat_rdy (a,b) ({ch}, {})\")\n            subgoal\n              by(auto elim:sync_elims)\n            subgoal\n           apply(cases \"d1>d2\")\n           subgoal \n             apply(elim combine_blocks_waitE4)\n                apply auto\n             apply(rule in_0assm_assn.intros(3))\n             by auto\n           apply(cases \"d2=d1\")\n           subgoal \n             apply simp\n             apply(elim combine_blocks_waitE2)\n              apply auto\n             apply(rule in_0assm_assn.intros(3))\n             by auto\n           apply(elim combine_blocks_waitE3)\n              apply auto\n           apply(rule in_0assm_assn.intros(3))\n           by auto\n         done\n       done\n     subgoal for tr2'\n       apply(cases \"\\<not>compat_rdy (a,b) rdy\")\n            subgoal\n              by(auto elim:sync_elims)\n            subgoal\n           apply(cases \"d1>d\")\n           subgoal \n             apply(elim combine_blocks_waitE4)\n                apply auto\n             apply(rule in_0assm_assn.intros(3))\n             apply auto\n              apply (cases rdy)\n             by auto\n           apply(cases \"d=d1\")\n           subgoal \n             apply simp\n             apply(elim combine_blocks_waitE2)\n              apply auto\n             apply(rule in_0assm_assn.intros(3))\n              apply auto\n             apply(cases rdy)\n             by auto\n           apply(elim combine_blocks_waitE3)\n              apply auto\n           apply(rule in_0assm_assn.intros(3))\n            apply auto\n           apply(cases rdy)\n           by auto\n         done\n       done\n     done\n   done\n\nlemma combine_out_0assm_out_orig:\n  assumes \"dh \\<notin> chs\"\n   and \"ch \\<in> chs\"\n shows \"combine_assn chs (out_0assm_assn dh v P) (out_orig_assn ch v' s Q)\n        \\<Longrightarrow>\\<^sub>t (out_0assm_assn dh v  \n            (combine_assn chs P (out_orig_assn ch v' s Q)))\"\n  apply(auto simp add:entails_tassn_def combine_assn_def)\n  subgoal for tr tr1 tr2\n    apply(cases rule: out_0assm_assn.cases[of dh v P tr1])\n      apply auto\n    subgoal for tr1'\n      apply(cases rule: out_orig_assn.cases[of ch v' s Q tr2])\n          apply auto\n        subgoal for tr2'\n          using assms\n          apply(elim combine_blocks_unpairE1)\n            apply auto\n          apply(rule out_0assm_assn.intros(1))\n          by auto\n        subgoal for tr2' d\n          using assms\n          apply(elim combine_blocks_unpairE3)\n           apply auto\n          apply(rule out_0assm_assn.intros(1))\n          by auto\n        done\n      subgoal for d1 a b p1 tr1'\n        apply(cases rule: out_orig_assn.cases[of ch v' s Q tr2])\n            apply auto\n          subgoal for tr2'\n            using assms\n            apply(auto elim:sync_elims)\n            done\n          subgoal for tr2' d2\n            apply(cases \"\\<not>compat_rdy (a,b) ({ch}, {})\")\n            subgoal\n              by(auto elim:sync_elims)\n            subgoal\n           apply(cases \"d1>d2\")\n           subgoal \n             apply(elim combine_blocks_waitE4)\n                apply auto\n             apply(rule out_0assm_assn.intros(2))\n             by auto\n           apply(cases \"d2=d1\")\n           subgoal \n             apply simp\n             apply(elim combine_blocks_waitE2)\n              apply auto\n             apply(rule out_0assm_assn.intros(2))\n             by auto\n           apply(elim combine_blocks_waitE3)\n              apply auto\n           apply(rule out_0assm_assn.intros(2))\n           by auto\n         done\n       done\n       done\n     done\n\nlemma combine_in_0assm_out_orig:\n  assumes \"dh \\<notin> chs\"\n   and \"ch \\<in> chs\"\n shows \"combine_assn chs (in_0assm_assn dh v P) (out_orig_assn ch v' s Q)\n        \\<Longrightarrow>\\<^sub>t (in_0assm_assn dh v  \n            (combine_assn chs P (out_orig_assn ch v' s Q)))\"\n  apply(auto simp add:entails_tassn_def combine_assn_def)\n  subgoal for tr tr1 tr2\n    apply(cases rule: in_0assm_assn.cases[of dh v P tr1])\n      apply auto\n    subgoal for tr1'\n      apply(cases rule: out_orig_assn.cases[of ch v' s Q tr2])\n          apply auto\n        subgoal for tr2'\n          using assms\n          apply(elim combine_blocks_unpairE1)\n            apply auto\n          apply(rule in_0assm_assn.intros(1))\n          by auto\n        subgoal for tr2' d\n          using assms\n          apply(elim combine_blocks_unpairE3)\n           apply auto\n          apply(rule in_0assm_assn.intros(1))\n          by auto\n        done\n      subgoal for w tr1'\n      apply(cases rule: out_orig_assn.cases[of ch v' s Q tr2])\n          apply auto\n        subgoal for tr2'\n          using assms\n          apply(elim combine_blocks_unpairE1)\n            apply auto\n          apply(rule in_0assm_assn.intros(2))\n          by auto\n        subgoal for tr2' d\n          using assms\n          apply(elim combine_blocks_unpairE3)\n           apply auto\n          apply(rule in_0assm_assn.intros(2))\n          by auto\n        done\n      subgoal for d1 a b p1 tr1'\n        apply(cases rule: out_orig_assn.cases[of ch v' s Q tr2])\n            apply auto\n          subgoal for tr2'\n            using assms\n            apply(auto elim:sync_elims)\n            done\n          subgoal for tr2' d2\n            apply(cases \"\\<not>compat_rdy (a,b) ({ch}, {})\")\n            subgoal\n              by(auto elim:sync_elims)\n            subgoal\n           apply(cases \"d1>d2\")\n           subgoal \n             apply(elim combine_blocks_waitE4)\n                apply auto\n             apply(rule in_0assm_assn.intros(3))\n             by auto\n           apply(cases \"d2=d1\")\n           subgoal \n             apply simp\n             apply(elim combine_blocks_waitE2)\n              apply auto\n             apply(rule in_0assm_assn.intros(3))\n             by auto\n           apply(elim combine_blocks_waitE3)\n              apply auto\n           apply(rule in_0assm_assn.intros(3))\n           by auto\n         done\n       done\n       done\n   done\n\n\nlemma combine_out_0assm_rdy_out_orig:\n  assumes \"dh \\<notin> chs\"\n   and \"ch \\<in> chs\"\n shows \"combine_assn chs (out_0assm_rdy_assn dh v rdy P) (out_orig_assn ch v' s Q)\n        \\<Longrightarrow>\\<^sub>t (out_0assm_rdy_assn dh v (merge_rdy rdy ({ch}, {}))\n            (combine_assn chs P (out_orig_assn ch v' s Q)))\"\n  apply(auto simp add:entails_tassn_def combine_assn_def)\n  subgoal for tr tr1 tr2\n    apply(cases rule: out_0assm_rdy_assn.cases[of dh v rdy P tr1])\n      apply auto\n    subgoal for tr1'\n      apply(cases rule: out_orig_assn.cases[of ch v' s Q tr2])\n          apply auto\n        subgoal for tr2'\n          using assms\n          apply(elim combine_blocks_unpairE1)\n            apply auto\n          apply(rule out_0assm_rdy_assn.intros(1))\n          by auto\n        subgoal for tr2' d\n          using assms\n          apply(elim combine_blocks_unpairE3)\n           apply auto\n          apply(rule out_0assm_rdy_assn.intros(1))\n          by auto\n        done\n      subgoal for d1 p1 tr1'\n        apply(cases rule: out_orig_assn.cases[of ch v' s Q tr2])\n            apply auto\n          subgoal for tr2'\n            using assms\n            apply(auto elim:sync_elims)\n            done\n          subgoal for tr2' d2\n            apply(cases \"\\<not>compat_rdy rdy ({ch}, {})\")\n            subgoal\n              by(auto elim:sync_elims)\n            subgoal\n           apply(cases \"d1>d2\")\n           subgoal \n             apply(elim combine_blocks_waitE4)\n                apply auto\n             apply(rule out_0assm_rdy_assn.intros(2))\n             by auto\n           apply(cases \"d2=d1\")\n           subgoal \n             apply simp\n             apply(elim combine_blocks_waitE2)\n              apply auto\n             apply(rule out_0assm_rdy_assn.intros(2))\n             by auto\n           apply(elim combine_blocks_waitE3)\n              apply auto\n           apply(rule out_0assm_rdy_assn.intros(2))\n           by auto\n         done\n       done\n       done\n     done\n\nlemma combine_in_0assm_rdy_out_orig:\n  assumes \"dh \\<notin> chs\"\n   and \"ch \\<in> chs\"\n shows \"combine_assn chs (in_0assm_rdy_assn dh v rdy P) (out_orig_assn ch v' s Q)\n        \\<Longrightarrow>\\<^sub>t (in_0assm_rdy_assn dh v (merge_rdy rdy ({ch}, {}))\n            (combine_assn chs P (out_orig_assn ch v' s Q)))\"\n  apply(auto simp add:entails_tassn_def combine_assn_def)\n  subgoal for tr tr1 tr2\n    apply(cases rule: in_0assm_rdy_assn.cases[of dh v rdy P tr1])\n      apply auto\n    subgoal for tr1'\n      apply(cases rule: out_orig_assn.cases[of ch v' s Q tr2])\n          apply auto\n        subgoal for tr2'\n          using assms\n          apply(elim combine_blocks_unpairE1)\n            apply auto\n          apply(rule in_0assm_rdy_assn.intros(1))\n          by auto\n        subgoal for tr2' d\n          using assms\n          apply(elim combine_blocks_unpairE3)\n           apply auto\n          apply(rule in_0assm_rdy_assn.intros(1))\n          by auto\n        done\n      subgoal for w tr1'\n      apply(cases rule: out_orig_assn.cases[of ch v' s Q tr2])\n          apply auto\n        subgoal for tr2'\n          using assms\n          apply(elim combine_blocks_unpairE1)\n            apply auto\n          apply(rule in_0assm_rdy_assn.intros(2))\n          by auto\n        subgoal for tr2' d\n          using assms\n          apply(elim combine_blocks_unpairE3)\n           apply auto\n          apply(rule in_0assm_rdy_assn.intros(2))\n          by auto\n        done\n      subgoal for d1 p1 tr1'\n        apply(cases rule: out_orig_assn.cases[of ch v' s Q tr2])\n            apply auto\n          subgoal for tr2'\n            using assms\n            apply(auto elim:sync_elims)\n            done\n          subgoal for tr2' d2\n            apply(cases \"\\<not>compat_rdy rdy ({ch}, {})\")\n            subgoal\n              by(auto elim:sync_elims)\n            subgoal\n           apply(cases \"d1>d2\")\n           subgoal \n             apply(elim combine_blocks_waitE4)\n                apply auto\n             apply(rule in_0assm_rdy_assn.intros(3))\n              apply auto\n             apply(cases rdy)\n             by auto\n           apply(cases \"d2=d1\")\n           subgoal \n             apply simp\n             apply(elim combine_blocks_waitE2)\n              apply auto\n             apply(rule in_0assm_rdy_assn.intros(3))\n             apply auto\n             apply(cases rdy)\n             by auto\n           apply(elim combine_blocks_waitE3)\n              apply auto\n           apply(rule in_0assm_rdy_assn.intros(3))\n           apply auto\n           apply(cases rdy)\n           apply auto\n         done\n       done\n       done\n     done\n   done\n\n\nlemma combine_wait_tguar'_vassm'_wait_orig2:\n  assumes \"\\<And> s . s\\<in>S \\<Longrightarrow> s<d\"\n  and \"compat_rdy rdy1 rdy2\"\n  and \"dh \\<notin> chs\"\n  and \"ch \\<in> chs\"\n  shows \"combine_assn chs (waitin_tguar'_vassm'_assn S p1 rdy1 dh V P)\n                      (wait_orig_assn d p2 rdy2 (out_orig_assn ch v' s Q)) \\<Longrightarrow>\\<^sub>t\n         waitin_tguar'_vassm'_assn S (\\<lambda> t. ParState (p1 t) (p2 t)) (merge_rdy rdy1 rdy2) dh V\n                      (\\<lambda> v t. combine_assn chs (P v t) (wait_orig_assn (d-t) (\\<lambda> t'. p2(t'+t)) rdy2 (out_orig_assn ch v' s Q)))\"\n  unfolding entails_tassn_def combine_assn_def\n  apply auto\n  subgoal for tr tr1 tr2\n    apply(cases rule:waitin_tguar'_vassm'_assn.cases[of S p1 rdy1 dh V P tr1])\n        apply auto\n    subgoal for v tr1'\n      apply(cases rule:wait_orig_assn.cases[of d p2 rdy2 \"(out_orig_assn ch v' s Q)\" tr2])\n        apply auto\n      subgoal\n        apply(cases rule:out_orig_assn.cases[of ch v' s Q tr2])\n          apply auto\n        subgoal for tr2'\n          apply(elim combine_blocks_unpairE1)\n          using assms\n          by auto\n        subgoal for d tr2'\n          apply(elim combine_blocks_unpairE3)\n          using assms\n          by auto\n        done\n      subgoal for tr2'\n        apply(elim combine_blocks_unpairE3)\n          using assms\n           apply auto\n          subgoal for tr'\n            apply(rule waitin_tguar'_vassm'_assn.intros(1))\n            by auto\n          done\n        done\n      subgoal for d1 v tr1'\n        apply(cases rule:wait_orig_assn.cases[of d p2 rdy2 \"(out_orig_assn ch v' s Q)\" tr2])\n        using assms(1)[of d1]\n          apply auto\n        subgoal for tr2'\n          apply(elim combine_blocks_waitE3)\n          using assms\n             apply auto\n          subgoal for tr'\n            apply(elim combine_blocks_unpairE3)\n             apply auto\n            subgoal for tr''\n              apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                 apply auto\n              apply(rule exI[where x=\"tr1'\"])\n              apply auto\n              apply(rule exI[where x=\"(WaitBlk (d - d1) (\\<lambda>t. p2 (t + d1)) rdy2 # tr2')\"])\n              apply auto\n              apply(rule wait_orig_assn.intros(2))\n              by auto\n            done\n          done\n        done\n      subgoal for w tr1'\n        apply(cases rule:wait_orig_assn.cases[of d p2 rdy2 \"(out_orig_assn ch v' s Q)\" tr2])\n        apply auto\n      subgoal\n        apply(cases rule:out_orig_assn.cases[of ch v' s Q tr2])\n          apply auto\n        subgoal for tr2'\n          apply(elim combine_blocks_unpairE1)\n          using assms\n          by auto\n        subgoal for d tr2'\n          apply(elim combine_blocks_unpairE3)\n          using assms\n          by auto\n        done\n      subgoal for tr2'\n        apply(elim combine_blocks_unpairE3)\n          using assms\n           apply auto\n          subgoal for tr'\n            apply(rule waitin_tguar'_vassm'_assn.intros(3))\n            by auto\n          done\n        done\n      subgoal for d1 w tr1'\n        apply(cases rule:wait_orig_assn.cases[of d p2 rdy2 \"(out_orig_assn ch v' s Q)\" tr2])\n        using assms(1)[of d1]\n          apply auto\n        subgoal for tr2'\n          apply(elim combine_blocks_waitE3)\n          using assms\n             apply auto\n          subgoal for tr'\n            apply(elim combine_blocks_unpairE3)\n             apply auto\n            subgoal for tr''\n              apply(rule waitin_tguar'_vassm'_assn.intros(4))\n              by auto\n            done\n          done\n        done\n      done\n    done\n\n\nlemma combine_task_dis':\n  \"task_assn' t k pd pc task_es task_s tr1 \\<Longrightarrow>\n   dispatch_assn' t' kk pd dis_s tr2 \\<Longrightarrow>\n   t \\<in> tid_set \\<Longrightarrow>\n   t = t' \\<Longrightarrow>\n   task_s (CHR ''t'') = dis_s (CHR ''t'') \\<Longrightarrow>\n   combine_blocks {dispatch_ch t} tr1 tr2 tr \\<Longrightarrow>\n   task_dis_assn' t k pd pc dis_s task_es task_s tr\"\nproof(induction k arbitrary: kk task_es task_s dis_s tr1 tr2 tr)\n  case 0\n  note 0 = 0\n  then show ?case \n    apply(cases task_es)\n      apply auto\n    subgoal for st ent tp\n  proof(induction kk)\n    case 0\n    then show ?case \n      apply auto \n      subgoal premises pre\n        apply (rule combine_blocks_assn)\n           apply (rule pre(1))\n        apply(rule pre(2))\n         apply(rule pre(6))\n        by (auto elim!: sync_elims)\n      done\n  next\n    case (Suc kk)\n    then show ?case \n      apply auto \n      subgoal premises pre\n        thm pre\n        apply(rule combine_blocks_assn)\n           apply(rule pre (2))\n          apply(rule pre (3))\n         apply(rule pre (7))\n        apply(rule entails_tassn_trans)\n         apply(rule combine_emp_wait_orig5)\n        apply(rule combine_emp_out_orig1)\n        by auto\n      done\n  qed\n  done\nnext\n  case (Suc k)\n  note suc1 = Suc\n  then show ?case \n  proof(induction kk)\n    case 0\n    then show ?case \n      apply(cases task_es)\n      apply auto\n      subgoal for st ent tp\n        apply(cases st) apply simp\n        subgoal premises pre\n          thm pre\n          apply(rule combine_blocks_assn)\n             apply(rule pre(2))\n            apply(rule pre(3))\n           apply(rule pre(7))\n          apply(rule combine_in_vassm_emp1)\n          by auto\n         apply simp\n        subgoal apply(erule disjE)\n          subgoal premises pre\n            thm pre\n            apply(rule disjI1)\n            apply(rule combine_blocks_assn)\n               apply(rule pre(9))\n              apply(rule pre(2))\n             apply(rule pre(6))\n            apply(rule entails_tassn_trans)\n             apply(rule combine_out_0assm_emp2)\n            subgoal using ch_dist pre(3) by auto\n            apply(rule out_0assm_assn_tran)\n            subgoal \n              apply(rule entails_tassn_trans)\n             apply(rule combine_waitin_tguar'_vassm'_emp2)\n              subgoal using ch_dist pre(3) by auto\n              apply(rule waitin_tguar'_vassm'_assn_tran)\n              unfolding entails_tassn_def combine_assn_def\n              apply clarify\n              subgoal for v d tr tr1 tr2\n                using pre(1)[of \"(Task RUNNING (Suc 0) tp)\"\n                                \"(task_s(CHR ''t'' := task_s CHR ''t'' + d, CHR ''c'' := up_ent_c ent (task_s CHR ''c'')))\"\n                                tr1 0 \n                                \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + d))\" tr2 tr]\n                apply(subgoal_tac\"dispatch_assn' t' 0 pd (dis_s(CHR ''t'' := dis_s CHR ''t'' + d)) tr2\")\n                subgoal using pre(5) \n                  by fastforce\n                by auto\n              done\n            done\n          apply(erule disjE)\n          subgoal premises pre\n            thm pre\n            apply(rule disjI2)\n            apply(rule disjI1)\n            apply(rule combine_blocks_assn)\n              apply(rule pre(9))\n              apply(rule pre(2))\n             apply(rule pre(6))\n            apply(rule entails_tassn_trans)\n             apply(rule combine_out_0assm_emp2)\n            subgoal using ch_dist pre(3) by auto\n            apply(rule out_0assm_assn_tran)\n            subgoal \n              apply(rule entails_tassn_trans)\n               apply(rule combine_wait_orig_emp2)\n              apply(rule wait_orig_assn_tran)\n              apply(rule entails_tassn_trans)\n               apply(rule combine_out_0assm_rdy_emp2)\n              subgoal using ch_dist pre(3) by auto\n              apply(rule out_0assm_rdy_assn_tran)\n              subgoal \n                unfolding entails_tassn_def combine_assn_def\n                apply clarify\n                subgoal for tr tr1 tr2\n                  using pre(1)[of \"(Task WAIT ent tp)\" \"(task_s(CHR ''t'' := pd))\" tr1 0\n                              \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + pd - task_s CHR ''t''))\"\n                               tr2 tr]\n                  apply(subgoal_tac \"dispatch_assn' t' 0 pd (dis_s(CHR ''t'' := dis_s CHR ''t'' + pd - task_s CHR ''t''))tr2\")\n                   subgoal using pre(5) by fastforce \n                  by auto\n                done\n              done\n            done\n          subgoal premises pre\n            thm pre\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule combine_blocks_assn)\n              apply(rule pre(9))\n              apply(rule pre(2))\n             apply(rule pre(6))\n            apply(rule entails_tassn_trans)\n             apply(rule combine_out_0assm_emp2)\n            subgoal using ch_dist pre(3) by auto\n            apply(rule out_0assm_assn_tran)\n            subgoal \n              apply(rule entails_tassn_trans)\n               apply(rule combine_wait_orig_emp2)\n              apply(rule wait_orig_assn_tran)\n              apply(rule entails_tassn_trans)\n               apply(rule combine_in_0assm_rdy_emp2)\n              subgoal using ch_dist pre(3) by auto\n              apply(rule in_0assm_rdy_assn_tran)\n              subgoal \n                unfolding entails_tassn_def combine_assn_def\n                apply clarify\n                subgoal for tr tr1 tr2\n                  using pre(1)[of \"(Task RUNNING (Suc 0) tp)\" \"(task_s(CHR ''t'' := pd, CHR ''c'' := up_ent_c ent (task_s CHR ''c'')))\" tr1 0\n                              \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + pd - task_s CHR ''t''))\"\n                               tr2 tr]\n                  apply(subgoal_tac \"dispatch_assn' t' 0 pd (dis_s(CHR ''t'' := dis_s CHR ''t'' + pd - task_s CHR ''t''))tr2\")\n                   subgoal using pre(5) by fastforce \n                  by auto\n                done\n              done\n            done\n          done\n        subgoal apply simp\n          apply(cases \"ent = Suc 0\")\n          subgoal \n            apply simp\n            apply(erule disjE)\n            subgoal apply(rule disjI1)\n              subgoal premises pre\n                thm pre\n                apply(rule combine_blocks_assn)\n                   apply(rule pre(10))\n                  apply(rule pre(2))\n                apply(rule pre(6))\n                apply(rule entails_tassn_trans)\n                 apply(rule combine_waitin_tguar'_vassm'_emp2)\n                subgoal using ch_dist pre(3) by auto\n                apply(rule waitin_tguar'_vassm'_assn_tran)\n                apply clarify\n                subgoal for v d\n                  unfolding entails_tassn_def combine_assn_def\n                  apply clarify\n                  subgoal for tr tr1 tr2\n                    using pre(1)[of \"(Task READY (Suc 0) tp)\" \n                                    \"(task_s(CHR ''t'' := task_s CHR ''t'' + d, CHR ''c'' := task_s CHR ''c'' + d))\" \n                                    tr1 0 \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + d))\"\n                                    tr2 tr]\n                    apply(subgoal_tac \"dispatch_assn' t' 0 pd (dis_s(CHR ''t'' := dis_s CHR ''t'' + d)) tr2\")\n                     subgoal using pre(5) by fastforce\n                    by auto\n                  done\n                done\n              done\n            subgoal apply(rule disjI2)\n              subgoal premises pre\n                thm pre\n                apply(rule combine_blocks_assn)\n                   apply(rule pre(10))\n                  apply(rule pre(2))\n                 apply(rule pre(6))\n                apply(rule entails_tassn_trans)\n                 apply(rule combine_wait_orig_emp2)\n                apply(rule wait_orig_assn_tran)\n                subgoal \n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_out_0assm_srdy_emp2)\n                  subgoal using ch_dist pre(3) by auto\n                  apply(rule out_0assm_srdy_assn_tran)\n                  unfolding entails_tassn_def combine_assn_def\n                  apply clarify\n                  subgoal for tr tr1 tr2\n                    using pre(1)[of \"(Task WAIT (Suc 0) tp)\" \n                     \"(task_s(CHR ''t'' :=task_s CHR ''t'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                              CHR ''c'' :=task_s CHR ''c'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\"\n                     tr1 0 \"(dis_s (CHR ''t'' := dis_s CHR ''t'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\"\n                        tr2 tr]\n                    apply(subgoal_tac \"dispatch_assn' t' 0 pd \n                       (dis_s (CHR ''t'' := dis_s CHR ''t'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))) tr2\")\n                     subgoal using pre(5) by fastforce\n                    by auto\n                  done\n                done\n              done\n            done\n          subgoal by auto\n          done\n        done\n      done\n  next\n    case (Suc kk)\n    note suc2 = Suc\n    then show ?case \n      apply auto\n      apply(cases task_es)\n        apply auto\n      subgoal for st ent tp\n        apply(cases st) apply simp\n        subgoal premises pre\n          thm pre\n          apply(rule combine_blocks_assn)\n             apply(rule pre(3))\n            apply(rule pre(4))\n           apply(rule pre(8))\n          apply(rule entails_tassn_trans)\n           apply(rule combine_in_vassm_wait_orig1)\n            apply simp\n           apply simp\n          apply auto\n          apply(rule wait_orig_assn_tran)\n          apply(rule entails_tassn_trans)\n           apply(rule combine_in_vassm_out_orig1)\n            apply auto\n          unfolding entails_tassn_def combine_assn_def\n          apply clarify\n          subgoal for tr tr1 tr2\n            using pre(2)[of \"(Task READY 0 tp)\" \"(\\<lambda>a. if a = CHR ''t'' then 0 else task_s a)\" tr1\n                            kk \"(\\<lambda>a. if a = CHR ''t'' then 0 else dis_s a)\" tr2 tr]\n            by auto\n          done\n        subgoal apply simp\n          apply(erule disjE)\n          subgoal apply(rule disjI1)\n            subgoal premises pre\n              thm pre\n              apply(rule combine_blocks_assn)\n                 apply(rule pre(10))\n                apply(rule pre(3))\n               apply(rule pre(7))\n              apply(rule entails_tassn_trans)\n               apply(rule combine_out_0assm_wait_orig_out_orig)\n                subgoal using ch_dist pre by auto\n                subgoal by auto\n                apply(rule out_0assm_assn_tran)\n                apply(rule entails_tassn_trans)\n                 apply(rule combine_wait_tguar'_vassm'_wait_orig2)\n                subgoal by auto\n                subgoal by auto\n                subgoal using pre ch_dist by auto\n                subgoal by auto\n                apply auto\n                apply(rule waitin_tguar'_vassm'_assn_tran)\n                apply auto\n                unfolding combine_assn_def entails_tassn_def\n                apply auto\n                subgoal for d tr tr1 tr2\n                  thm pre(2)\n                  apply(subgoal_tac \"dispatch_assn' t' (Suc kk) pd (\\<lambda>a. if a = CHR ''t'' then dis_s CHR ''t'' + d else dis_s a) tr2\")\n                   prefer 2\n                  subgoal apply auto\n                    apply(subgoal_tac \"pd - dis_s CHR ''t'' - d = pd - (dis_s CHR ''t'' + d)\")\n                     apply auto\n                    apply(subgoal_tac \"(\\<lambda>t'. EState (estate.None,\n             \\<lambda>a. if a = CHR ''t'' then dis_s CHR ''t'' + (t' + d) else dis_s a))\n                                     = (\\<lambda>t. EState  (estate.None, \n            (\\<lambda>a. if a = CHR ''t'' then dis_s CHR ''t'' + d else dis_s a)\n            (CHR ''t'' := dis_s CHR ''t'' + d + t)))\")\n                    apply(subgoal_tac \"(\\<lambda>a. if a = CHR ''t'' then dis_s CHR ''t'' + d else dis_s a)\n          (CHR ''t'' := 0) = (\\<lambda>a. if a = CHR ''t'' then 0 else dis_s a)\")\n                      apply auto\n                    apply(rule ext)\n                    by auto\n                  subgoal premises pp\n                    thm pp\n                    apply(rule pre(2))\n                       apply(rule pp(3))\n                      apply(rule pp(6))\n                     apply auto\n                    apply(rule pp(5))\n                    done\n                  done\n                done\n              done\n            apply(erule disjE)\n            subgoal apply(rule disjI2) apply(rule disjI1)\n            subgoal premises pre\n              thm pre\n              apply(rule combine_blocks_assn)\n                 apply(rule pre(10))\n                apply(rule pre(3))\n               apply(rule pre(7))\n              apply(rule entails_tassn_trans)\n               apply(rule combine_out_0assm_wait_orig_out_orig)\n                subgoal using ch_dist pre by auto\n                subgoal by auto\n                apply(rule out_0assm_assn_tran)\n                apply(rule entails_tassn_trans)\n                 apply(rule combine_wait_orig_wait_orig2)\n                subgoal by auto\n                apply auto\n                apply(rule wait_orig_assn_tran)\n                apply(rule entails_tassn_trans)\n                 apply(rule combine_out_0assm_rdy_out_orig)\n                subgoal using pre ch_dist by auto\n                subgoal by auto\n                apply (auto del:fun_upd_apply)\n                apply(rule out_0assm_rdy_assn_tran)\n                unfolding combine_assn_def entails_tassn_def\n                apply auto\n                subgoal for tr tr1 tr2\n                  thm pre(2)\n                  apply(subgoal_tac \"dispatch_assn' t' (Suc kk) pd (\\<lambda>a. if a = CHR ''t'' then pd else dis_s a) tr2\")\n                   prefer 2 \n                  subgoal apply auto\n                    apply(subgoal_tac \" (\\<lambda>a. if a = CHR ''t'' then pd else dis_s a)(CHR ''t'' := 0) = (\\<lambda>a. if a = CHR ''t'' then 0 else dis_s a)\")\n                     apply auto\n                    apply(rule wait_orig_assn.intros(1))\n                    by auto\n                  subgoal premises pp\n                    thm pp\n                    apply(rule pre(2))\n                       apply(rule pp(1))\n                      apply(rule pp(4))\n                     apply auto\n                    apply(rule pp(3))\n                    done\n                  done\n                done\n              done\n            subgoal apply(rule disjI2) apply(rule disjI2)\n            subgoal premises pre\n              thm pre\n              apply(rule combine_blocks_assn)\n                 apply(rule pre(10))\n                apply(rule pre(3))\n               apply(rule pre(7))\n              apply(rule entails_tassn_trans)\n               apply(rule combine_out_0assm_wait_orig_out_orig)\n                subgoal using ch_dist pre by auto\n                subgoal by auto\n                apply(rule out_0assm_assn_tran)\n                apply(rule entails_tassn_trans)\n                 apply(rule combine_wait_orig_wait_orig2)\n                subgoal by auto\n                apply auto\n                apply(rule wait_orig_assn_tran)\n                apply(rule entails_tassn_trans)\n                 apply(rule combine_in_0assm_rdy_out_orig)\n                subgoal using pre ch_dist by auto\n                subgoal by auto\n                apply(auto del:fun_upd_apply)\n                apply(rule in_0assm_rdy_assn_tran)\n                unfolding combine_assn_def entails_tassn_def\n                apply auto\n                subgoal for tr tr1 tr2\n                  thm pre(2)\n                  apply(subgoal_tac \"dispatch_assn' t' (Suc kk) pd (\\<lambda>a. if a = CHR ''t'' then pd else dis_s a) tr2\")\n                   prefer 2 \n                  subgoal apply auto\n                    apply(subgoal_tac \" (\\<lambda>a. if a = CHR ''t'' then pd else dis_s a)(CHR ''t'' := 0) = (\\<lambda>a. if a = CHR ''t'' then 0 else dis_s a)\")\n                     apply auto\n                    apply(rule wait_orig_assn.intros(1))\n                    by auto\n                  subgoal premises pp\n                    thm pp\n                    apply(rule pre(2))\n                       apply(rule pp(1))\n                      apply(rule pp(4))\n                     apply auto\n                    apply(rule pp(3))\n                    done\n                  done\n                done\n              done\n            done\n          subgoal apply simp\n            apply(cases \"ent \\<noteq> Suc 0\")\n            subgoal by auto\n            apply simp\n            apply(erule disjE)\n          subgoal apply(rule disjI1)\n            subgoal premises pre\n              thm pre\n              apply(rule combine_blocks_assn)\n                 apply(rule pre(11))\n                apply(rule pre(3))\n               apply(rule pre(7))\n              apply(rule entails_tassn_trans)\n               apply(rule combine_wait_tguar'_vassm'_wait_orig2)\n              subgoal by auto\n              subgoal by auto\n              subgoal using pre ch_dist by auto\n              subgoal  by auto\n              apply auto\n              apply(rule waitin_tguar'_vassm'_assn_tran)\n              apply auto\n              unfolding combine_assn_def entails_tassn_def\n              apply auto\n              subgoal for d tr tr1 tr2\n                apply(subgoal_tac \"dispatch_assn' t' (Suc kk) pd (\\<lambda>a. if a = CHR ''t'' then dis_s CHR ''t'' + d else dis_s a) tr2\")\n                 prefer 2\n                subgoal apply auto\n                  apply(subgoal_tac \"(pd - dis_s CHR ''t'' - d) =( pd - (dis_s CHR ''t'' + d))\")\n                   apply auto\n                  apply(subgoal_tac \"(\\<lambda>t'. EState (estate.None,\n             \\<lambda>a. if a = CHR ''t'' then dis_s CHR ''t'' + (t' + d) else dis_s a)) = \n              (\\<lambda>t. EState (estate.None, (\\<lambda>a. if a = CHR ''t'' then dis_s CHR ''t'' + d else dis_s a)\n            (CHR ''t'' := dis_s CHR ''t'' + d + t)))\")\n                   apply auto\n                  apply(subgoal_tac \"(\\<lambda>a. if a = CHR ''t'' then dis_s CHR ''t'' + d else dis_s a)\n          (CHR ''t'' := 0) = (\\<lambda>a. if a = CHR ''t'' then 0 else dis_s a)\")\n                    apply auto\n                  apply(rule ext)\n                  by auto\n                subgoal premises pp\n                  thm pp\n                  apply(rule pre(2))\n                     apply(rule pp(4))\n                    apply(rule pp(7))\n                   apply auto\n                  apply(rule pp(6))\n                  done\n                done\n              done\n            done\n          subgoal apply(rule disjI2)\n            subgoal premises pre\n              thm pre\n              apply(rule combine_blocks_assn)\n              apply(rule pre(11))\n                apply(rule pre(3))\n               apply(rule pre(7))\n              apply(rule entails_tassn_trans)\n               apply(rule combine_wait_orig_wait_orig5)\n              subgoal by auto\n              subgoal by auto\n              apply auto\n              apply(rule wait_orig_assn_tran)\n              apply(rule entails_tassn_trans)\n               apply(rule combine_out_0assm_srdy_wait_orig_out_orig)\n              subgoal using pre ch_dist by auto\n              subgoal by auto\n              apply(rule out_0assm_srdy_assn_tran)\n              unfolding combine_assn_def entails_tassn_def\n              apply auto\n              subgoal for tr tr1 tr2\n                apply(subgoal_tac \"dispatch_assn' t' (Suc kk) pd (\\<lambda>a. if a = CHR ''t''\n          then dis_s CHR ''t'' +\n               min (pd - dis_s CHR ''t'') (pc - task_s CHR ''c'')\n          else dis_s a) tr2\")\n                 prefer 2\n                 subgoal\n                apply(subgoal_tac \"(pd - dis_s CHR ''t'' -\n      min (pd - dis_s CHR ''t'') (pc - task_s CHR ''c'')) = (pd -\n      (dis_s CHR ''t'' + min (pd - dis_s CHR ''t'') (pc - task_s CHR ''c'')))\")\n                    apply auto\n                   apply(subgoal_tac \"(\\<lambda>t. EState\n           (estate.None,\n            \\<lambda>a. if a = CHR ''t''\n                then dis_s CHR ''t'' +\n                     (t + min (pd - dis_s CHR ''t'') (pc - task_s CHR ''c''))\n                else dis_s a)) = (\\<lambda>t. EState\n           (estate.None,\n            (\\<lambda>a. if a = CHR ''t''\n                 then dis_s CHR ''t'' +\n                      min (pd - dis_s CHR ''t'') (pc - task_s CHR ''c'')\n                 else dis_s a)\n            (CHR ''t'' :=\n               dis_s CHR ''t'' +\n               min (pd - dis_s CHR ''t'') (pc - task_s CHR ''c'') +\n               t)))\")\n                    apply auto\n                    apply(subgoal_tac \"(\\<lambda>a. if a = CHR ''t'' then 0 else dis_s a) =\n            (\\<lambda>a. if a = CHR ''t''\n               then dis_s CHR ''t'' +\n                    min (pd - dis_s CHR ''t'') (pc - task_s CHR ''c'')\n               else dis_s a)\n          (CHR ''t'' := 0)\")\n                     apply auto\n                   apply(rule ext)\n                   by auto\n                 subgoal premises pp\n                   thm pp\n                   apply(rule pre(2))\n                      apply(rule pp(1))\n                     apply(rule pp(4))\n                    apply auto\n                   apply(rule pp(3))\n                   done\n                 done\n               done\n             done\n           done\n         done\n       done\n   qed\nqed\n\n\ninductive waitin_assms'ch_assn :: \"real set \\<Rightarrow> (real \\<Rightarrow> 'a gstate) \\<Rightarrow> rdy_info \\<Rightarrow> cname \\<Rightarrow> real set \\<Rightarrow> (real \\<Rightarrow> real \\<Rightarrow> 'a tassn) \\<Rightarrow> 'a tassn\" where\n  \"v \\<in> V \\<Longrightarrow> 0 \\<in> S \\<Longrightarrow> (P v 0) tr \\<Longrightarrow> (waitin_assms'ch_assn S p rdy ch V P) (InBlock ch v # tr)\"\n| \"v \\<in> V \\<Longrightarrow> d \\<in> S \\<Longrightarrow> d > 0 \\<Longrightarrow> (P v d) tr \\<Longrightarrow> (waitin_assms'ch_assn S p rdy ch V P)\n      (WaitBlk d (\\<lambda>\\<tau>. p \\<tau>) rdy # InBlock ch v # tr)\"\n| \"0 \\<notin> S \\<or> w \\<notin> V \\<or> dh \\<noteq> ch\\<Longrightarrow> (waitin_assms'ch_assn S p rdy ch V P) (InBlock dh w # tr)\"\n| \"d \\<notin> S \\<or> w \\<notin> V \\<or> dh \\<noteq> ch\\<Longrightarrow> d > 0 \\<Longrightarrow> (waitin_assms'ch_assn S p rdy ch V P)\n      (WaitBlk d (\\<lambda>\\<tau>. p \\<tau>) rdy # InBlock ch w # tr)\"\n\n\nlemma waitin_assms'ch_assn_tran:\nassumes \"\\<And> v d. v \\<in> V \\<and> d \\<in> S \\<Longrightarrow> P v d \\<Longrightarrow>\\<^sub>t Q v d\"\nshows \"waitin_assms'ch_assn S p rdy ch V P \\<Longrightarrow>\\<^sub>t waitin_assms'ch_assn S p rdy ch V Q\"\nunfolding entails_tassn_def\n  apply auto\n  subgoal for tr\n    apply(cases rule: waitin_assms'ch_assn.cases[of S p rdy ch V P tr])\n      apply auto\n    subgoal\n      apply(rule waitin_assms'ch_assn.intros(1))\n      using assms \n      by(auto simp add:entails_tassn_def)\n    subgoal\n      apply(rule waitin_assms'ch_assn.intros(2))\n      using assms \n      by(auto simp add:entails_tassn_def)\n    subgoal\n      apply(rule waitin_assms'ch_assn.intros(3))\n      using assms \n      by(auto simp add:entails_tassn_def)\n    subgoal\n      apply(rule waitin_assms'ch_assn.intros(3))\n      using assms \n      by(auto simp add:entails_tassn_def)\n    subgoal\n      apply(rule waitin_assms'ch_assn.intros(3))\n      using assms \n      by(auto simp add:entails_tassn_def)\n    subgoal\n      apply(rule waitin_assms'ch_assn.intros(4))\n      using assms \n      by(auto simp add:entails_tassn_def)\n    subgoal\n      apply(rule waitin_assms'ch_assn.intros(4))\n      using assms \n      by(auto simp add:entails_tassn_def)\n    subgoal\n      apply(rule waitin_assms'ch_assn.intros(4))\n      using assms \n      by(auto simp add:entails_tassn_def)\n    done\n  done\n\n\n\nlemma combine_emp_waitin_assms'ch1:\n\"ch \\<in> chs \\<Longrightarrow> combine_assn chs emp\\<^sub>t (waitin_assms'ch_assn S p rdy ch V P) \\<Longrightarrow>\\<^sub>t (waitin_assms'ch_assn S q rdy ch V (\\<lambda> v t . combine_assn chs emp\\<^sub>t (P v t)))\"\n  apply(auto simp add:entails_tassn_def combine_assn_def emp_assn_def)\n  subgoal for tr tr1 \n    apply(cases rule:waitin_assms'ch_assn.cases[of S p rdy ch V P tr1])\n        apply (auto elim!: sync_elims)\n    subgoal for w dh tr1' tr'\n      apply(rule waitin_assms'ch_assn.intros(3))\n      by auto\n    subgoal for w dh tr1' tr'\n      apply(rule waitin_assms'ch_assn.intros(3))\n      by auto\n    subgoal for w dh tr1' tr'\n      apply(rule waitin_assms'ch_assn.intros(3))\n  by auto\n  done\n  done\n\nlemma combine_emp_waitin_assms'ch2:\n\"ch \\<notin> chs \\<Longrightarrow> combine_assn chs emp\\<^sub>t (waitin_assms'ch_assn S p rdy ch V P) \\<Longrightarrow>\\<^sub>t (waitin_assms'ch_assn S q rdy ch V (\\<lambda> v t . combine_assn chs emp\\<^sub>t (P v t)))\"\n  apply(auto simp add:entails_tassn_def combine_assn_def emp_assn_def)\n  subgoal for tr tr1 \n    apply(cases rule:waitin_assms'ch_assn.cases[of S p rdy ch V P tr1])\n        apply (auto elim!: sync_elims)\n    subgoal for v tr1' tr'\n      apply(rule waitin_assms'ch_assn.intros(1))\n      by auto\n    subgoal for w dh tr1' tr'\n      apply(rule waitin_assms'ch_assn.intros(3))\n      by auto\n    subgoal for w dh tr1' tr'\n      apply(rule waitin_assms'ch_assn.intros(3))\n      by auto\n    subgoal for w dh tr1' tr'\n      apply(rule waitin_assms'ch_assn.intros(3))\n  by auto\n  done\n  done\n\nlemma combine_emp_waitin_assms'ch3:\n\"combine_assn chs emp\\<^sub>t (waitin_assms'ch_assn S p rdy ch V P) \\<Longrightarrow>\\<^sub>t (waitin_assms'ch_assn S q rdy ch V (\\<lambda> v t . combine_assn chs emp\\<^sub>t (P v t)))\"\n  apply(cases \"ch \\<in> chs\")\n  apply(rule combine_emp_waitin_assms'ch1) apply auto\n  apply(rule combine_emp_waitin_assms'ch2) by auto\n\n\nfun sched_assn' :: \"nat \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate tassn\" where\n  \"sched_assn' n None s tr \\<longleftrightarrow> False\"\n| \"sched_assn' n (Task st ent tp) s tr \\<longleftrightarrow> False\"\n| \"sched_assn' 0 (Sch p rn rp) s tr \\<longleftrightarrow> (emp\\<^sub>t tr)\"\n| \"sched_assn' (Suc k) (Sch p rn rp) s tr \\<longleftrightarrow> \n   waitin_assms'_assn UNIV (\\<lambda> t. EState(Sch p rn rp, s)) ({},{req_ch 1,req_ch 2,free_ch 1,free_ch 2,exit_ch 1,exit_ch 2})\n   (req_ch 1) {2} (\\<lambda> v d. if (v\\<le>rp) then sched_assn' k (sched_push 1 (Sch p rn rp) (s(CHR ''p'' := v))) (s(CHR ''p'' := v))\n                                     else if rn \\<noteq> -1 then out_0assm_assn (preempt_ch rn) 0 (out_0assm_assn (run_ch 1) 0 \n                                         (sched_assn' k (sched_assign 1 (Sch p rn rp) (s(CHR ''p'' := v))) (s(CHR ''p'' := v))))\n                                            else out_0assm_assn (run_ch 1) 0 \n                                         (sched_assn' k (sched_assign 1 (Sch p rn rp) (s(CHR ''p'' := v))) (s(CHR ''p'' := v)))) tr\n \\<or> waitin_assms'_assn UNIV (\\<lambda> t. EState(Sch p rn rp, s)) ({},{req_ch 1,req_ch 2,free_ch 1,free_ch 2,exit_ch 1,exit_ch 2})\n   (req_ch 2) {1} (\\<lambda> v d. if (v\\<le>rp) then sched_assn' k (sched_push 2 (Sch p rn rp) (s(CHR ''p'' := v))) (s(CHR ''p'' := v))\n                                     else if rn \\<noteq> -1 then out_0assm_assn (preempt_ch rn) 0 (out_0assm_assn (run_ch 2) 0 \n                                         (sched_assn' k (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v))) (s(CHR ''p'' := v))))\n                                            else out_0assm_assn (run_ch 2) 0 \n                                         (sched_assn' k (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v))) (s(CHR ''p'' := v)))) tr\n \\<or> waitin_assms'_assn UNIV (\\<lambda> t. EState(Sch p rn rp, s)) ({},{req_ch 1,req_ch 2,free_ch 1,free_ch 2,exit_ch 1,exit_ch 2})\n   (free_ch 1) {0} (\\<lambda> v d. if length p > 0 then out_0assm_assn (run_ch (run_now (sched_get_max (Sch p rn rp) s))) 0 \n                                          (sched_assn' k (sched_get_max (Sch p rn rp) s) s)\n                                            else \n                                          (sched_assn' k (sched_clear (Sch p rn rp) s) s)) tr\n \\<or> waitin_assms'_assn UNIV (\\<lambda> t. EState(Sch p rn rp, s)) ({},{req_ch 1,req_ch 2,free_ch 1,free_ch 2,exit_ch 1,exit_ch 2})\n   (free_ch 2) {0} (\\<lambda> v d. if length p > 0 then out_0assm_assn (run_ch (run_now (sched_get_max (Sch p rn rp) s))) 0 \n                                          (sched_assn' k (sched_get_max (Sch p rn rp) s) s)\n                                            else \n                                          (sched_assn' k (sched_clear (Sch p rn rp) s) s)) tr\n \\<or> waitin_assms'_assn UNIV (\\<lambda> t. EState(Sch p rn rp, s)) ({},{req_ch 1,req_ch 2,free_ch 1,free_ch 2,exit_ch 1,exit_ch 2})\n   (exit_ch 1) {0} (\\<lambda> v d. sched_assn' k (sched_del_proc 1 (Sch p rn rp) s) s) tr\n \\<or> waitin_assms'_assn UNIV (\\<lambda> t. EState(Sch p rn rp, s)) ({},{req_ch 1,req_ch 2,free_ch 1,free_ch 2,exit_ch 1,exit_ch 2})\n   (exit_ch 2) {0} (\\<lambda> v d. sched_assn' k (sched_del_proc 2 (Sch p rn rp) s) s) tr\"\n\ndefinition properp :: \"tid \\<Rightarrow> real \\<Rightarrow> bool\" where\n\"properp rn rp = ((rn = 1 \\<longleftrightarrow> rp = 2) \\<and> (rn = 2 \\<longleftrightarrow> rp = 1) \\<and> (rn = -1 \\<longleftrightarrow> rp = -1) \\<and> rp \\<in> {-1,1,2} \\<and> rn \\<in> {-1,1,2})\"\n\nfun properl :: \"(real \\<times> tid) list \\<Rightarrow> bool\" where\n  \"properl [] = True\"\n| \"properl ((rp,rn) # v) = (properl v \\<and> properp rn rp \\<and> rn > 0 \\<and> rn \\<noteq> 1)\"\n\nlemma properl_p1:\n\"properl (p @ [(a, b)]) = (properl p \\<and> properp b a \\<and> b > 0 \\<and> b \\<noteq> 1)\"\nproof(induction p arbitrary: a b)\n  case Nil\n  then show ?case \n    by auto\nnext\n  case (Cons c p)\n  show ?case\n    apply(cases c)\n    subgoal for ca cb\n      apply simp\n      using Cons[of a b]\n      by auto\ndone\nqed\n\nlemma properl_p2:\n\"properl p \\<Longrightarrow> properp rn rp \\<Longrightarrow> properp (snd(get_max_default (rp,rn) p)) (fst(get_max_default (rp,rn) p))\"\nproof(induction p arbitrary: rn rp)\n  case Nil\n  then show ?case \n    by auto\nnext\n  case (Cons c p)\n  then show ?case \n    apply(cases c)\n    subgoal for a b\n      by auto\n    done\nqed\n\n\nlemma properl_p3:\n\"properl p \\<Longrightarrow> properp (snd (get_max p)) (fst (get_max p)) \"\nproof(induction p)\n  case Nil\n  then show ?case \n    apply auto\n    unfolding properp_def\n    by auto\nnext\n  case (Cons c p)\n  then show ?case \n    apply(cases c)\n    subgoal for a b\n      apply auto\n      apply(rule properl_p2)\n      by auto\n    done\nqed\n\n\nlemma properl_p4:\n\"properl p \\<Longrightarrow> properl (del_proc p t)\"\nproof(induction p)\n  case Nil\n  then show ?case \n    by auto\nnext\n  case (Cons c p)\n  then show ?case \n    apply(cases c)\n    subgoal for a b\n     by auto\n    done\nqed\n\nlemma proper_getmax1':\n\"fst (get_max_default (a,b) p) < d \\<Longrightarrow> a' < d \\<Longrightarrow> fst (get_max_default (a,b) (p@[(a',b')])) < d\"\nproof(induction p arbitrary: a b)\n  case Nil\n  then show ?case \n    by auto\nnext\n  case (Cons g p)\n  then show ?case \n    apply(cases g)\n    subgoal for ga gb\n      by auto\n    done\nqed\n\nlemma proper_getmax1:\n\"fst (get_max p) < d \\<Longrightarrow> a' < d \\<Longrightarrow> fst (get_max(p@[(a',b')])) < d\"\nproof(induction p)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons g p)\n  then show ?case \n    apply (cases g)\n    subgoal for ga gb\n      apply auto\n      using proper_getmax1'\n      by auto\n    done\nqed\n\n\nlemma proper_getmax2:\n\"properl p \\<Longrightarrow> snd (get_max p) \\<noteq> 1 \\<and> (gb \\<noteq> 1 \\<longrightarrow> snd (get_max_default (ga, gb) p) \\<noteq> 1)\"\nproof(induction p arbitrary: ga gb)\n  case Nil\n  then show ?case \n    by auto\nnext\n  case (Cons h p)\n  then show ?case \n    apply (cases h)\n    subgoal for ha hb\n      by auto\n    done\nqed\n\nlemma properl_p5':\n  \"properl ((a,b)#p) \\<Longrightarrow> snd(get_max_default (a,b) p) > 0\"\nproof(induction p arbitrary: a b)\n  case Nil\n  then show ?case \n    by auto\nnext\n  case (Cons g p)\n  then show ?case \n    apply(cases g)\n    by auto\nqed\n\nlemma properl_p5:\n\"length p > 0 \\<Longrightarrow> properl p \\<Longrightarrow> properp (snd (get_max p)) (fst (get_max p)) \\<and> (snd (get_max p)) > 0 \\<and> (snd (get_max p)) \\<noteq> 1\"\nproof(induction p)\n  case Nil\n  then show ?case \n    by auto\nnext\n  case (Cons c p)\n  then show ?case \n    apply(cases c)\n    subgoal for a b\n      apply auto\n      subgoal\n      apply(rule properl_p2)\n         apply auto\n        done\n       prefer 2\n      subgoal\n        using proper_getmax2 apply auto\n        done\n      using properl_p5'[of 1 2 p] \n      apply auto\n      unfolding properp_def\n      by auto\n    done\nqed\n\n\n\ndefinition proper :: \"estate \\<Rightarrow> bool \" where\n\"proper schs = ((properp (run_now schs) (run_prior schs)) \\<and> properl (pool schs))\"\n\n\ninductive io_out0_out0 :: \"cname \\<Rightarrow> real \\<Rightarrow> cname \\<Rightarrow> real \\<Rightarrow> cname \\<Rightarrow> real \\<Rightarrow> 'a tassn \\<Rightarrow> 'a tassn\" where\n  \"io_orig_assn ch1 v1 (out_0assm_assn ch2 v2 (out_0assm_assn ch3 v3 P)) tr \\<Longrightarrow> io_out0_out0 ch1 v1 ch2 v2 ch3 v3 P tr\"\n| \"out_0orig_assn ch2 v2 (io_orig_assn ch1 v1 (out_0assm_assn ch3 v3 P)) tr \\<Longrightarrow> io_out0_out0 ch1 v1 ch2 v2 ch3 v3 P tr\"\n\n\n\nfun tdsch1' :: \"nat \\<Rightarrow> nat \\<Rightarrow> real \\<Rightarrow> real \\<Rightarrow> state \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate tassn\" where\n  \"tdsch1' 0 0 pd pc dis_s (Task st ent tp) task_s (Sch p rn rp) s tr \\<longleftrightarrow> (emp\\<^sub>t tr)\"\n| \"tdsch1' 0 (Suc kk) pd pc dis_s (Task st ent tp) task_s (Sch p rn rp) s tr \\<longleftrightarrow> \n   in_0orig_vassm'_assn \n   (req_ch 2) {1} (\\<lambda> v . if (v\\<le>rp) then tdsch1' 0 kk pd pc dis_s (Task st ent tp) task_s (sched_push 2 (Sch p rn rp) (s(CHR ''p'' := v))) (s(CHR ''p'' := v))\n                                     else if rn \\<noteq> -1 then \\<up>(rn \\<noteq> 1) \\<and>\\<^sub>t out_0assm_assn (preempt_ch rn) 0 (out_0assm_assn (run_ch 2) 0 \n                                         (tdsch1' 0 kk pd pc dis_s (Task st ent tp) task_s (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v))) (s(CHR ''p'' := v))))\n                                            else out_0assm_assn (run_ch 2) 0 \n                                         (tdsch1' 0 kk pd pc dis_s (Task st ent tp) task_s (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v))) (s(CHR ''p'' := v)))) tr\n \\<or> in_0orig_vassm'_assn\n   (free_ch 2) {0} (\\<lambda> v . if length p > 0 then out_0assm_assn (run_ch (run_now (sched_get_max (Sch p rn rp) s))) 0 \n                                          (tdsch1' 0 kk pd pc dis_s (Task st ent tp) task_s (sched_get_max (Sch p rn rp) s) s)\n                                            else \n                                          (tdsch1' 0 kk pd pc dis_s (Task st ent tp) task_s (sched_clear (Sch p rn rp) s) s)) tr\n \\<or> in_0orig_vassm'_assn\n   (exit_ch 2) {0} (\\<lambda> v . tdsch1' 0 kk pd pc dis_s (Task st ent tp) task_s (sched_del_proc 2 (Sch p rn rp) s) s) tr\"\n| \"tdsch1' (Suc k) 0 pd pc dis_s (Task WAIT ent tp) task_s (Sch p rn rp) s tr \\<longleftrightarrow> \n   (tdsch1' k 0 pd pc (dis_s(CHR ''t'' := 0)) (Task READY 0 tp) (task_s(CHR ''t'' := 0)) (Sch p rn rp) s) tr\"\n| \"tdsch1' (Suc k) 0 pd pc dis_s (Task READY ent tp) task_s (Sch p rn rp) s tr \\<longleftrightarrow> False\"\n| \"tdsch1' (Suc k) 0 pd pc dis_s (Task RUNNING ent tp) task_s (Sch p rn rp) s tr \\<longleftrightarrow> False\"\n| \"tdsch1' (Suc k) (Suc kk) pd pc dis_s (Task WAIT ent tp) task_s (Sch p rn rp) s tr \\<longleftrightarrow> \n wait_orig_assn (pd - dis_s CHR ''t'')\n     (\\<lambda>t. ParState\n           (ParState (EState (Task WAIT ent tp, task_s))\n             (EState\n               (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\n           (EState (Sch p rn rp, s)))\n     ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2, dispatch_ch 1})\n     (tdsch1' (k) (Suc kk) pd pc (dis_s(CHR ''t'' := 0)) (Task READY 0 tp) (task_s(CHR ''t'' := 0)) (Sch p rn rp) s) tr \\<or>\n waitin_tguar'_vassm'_assn {..<(pd - dis_s CHR ''t'')}\n     (\\<lambda>t. ParState\n                 (ParState (EState (Task WAIT ent tp, task_s))\n         \n          (EState\n                     (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\n                 (EState (Sch p rn rp, s)))\n     ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2, dispatch_ch 1}) (req_ch 2) {1}\n     (\\<lambda> v d. if (v\\<le>rp) then tdsch1' (Suc k) kk pd pc (dis_s(CHR ''t'' := dis_s CHR ''t'' + d)) (Task WAIT ent tp) (task_s) (sched_push 2 (Sch p rn rp) (s(CHR ''p'' := v))) (s(CHR ''p'' := v))\n                                     else if rn \\<noteq> -1 then out_0assm_assn (preempt_ch rn) 0 (out_0assm_assn (run_ch 2) 0 \n                                         (tdsch1' (Suc k) kk pd pc (dis_s(CHR ''t'' := dis_s CHR ''t'' + d)) (Task WAIT ent tp) (task_s) (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v))) (s(CHR ''p'' := v))))                                         \n                                                     else out_0assm_assn (run_ch 2) 0 \n                                         (tdsch1' (Suc k) kk pd pc (dis_s(CHR ''t'' := dis_s CHR ''t'' + d)) (Task WAIT ent tp) (task_s) (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v))) (s(CHR ''p'' := v)))) tr \\<or>\n waitin_tguar'_vassm'_assn {..<(pd - dis_s CHR ''t'')}\n     (\\<lambda>t. ParState\n                 (ParState (EState (Task WAIT ent tp, task_s))\n         \n          (EState\n                     (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\n                 (EState (Sch p rn rp, s)))\n     ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2, dispatch_ch 1}) (free_ch 2) {0}\n     (\\<lambda> v d. if length p > 0 then out_0assm_assn (run_ch (run_now (sched_get_max (Sch p rn rp) s))) 0 \n                                 (tdsch1' (Suc k) kk pd pc (dis_s(CHR ''t'' := dis_s CHR ''t'' + d)) (Task WAIT ent tp) (task_s) (sched_get_max (Sch p rn rp) s) s)\n                             else tdsch1' (Suc k) kk pd pc (dis_s(CHR ''t'' := dis_s CHR ''t'' + d)) (Task WAIT ent tp) (task_s) (sched_get_max (Sch p rn rp) s) s) tr \\<or>\n waitin_tguar'_vassm'_assn {..<(pd - dis_s CHR ''t'')}\n     (\\<lambda>t. ParState\n                 (ParState (EState (Task WAIT ent tp, task_s))\n         \n          (EState\n                     (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\n                 (EState (Sch p rn rp, s)))\n     ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2, dispatch_ch 1}) (exit_ch 2) {0}\n     (\\<lambda> v d. tdsch1' (Suc k) kk pd pc (dis_s(CHR ''t'' := dis_s CHR ''t'' + d)) (Task WAIT ent tp) task_s (Sch (del_proc p 2) rn rp) s) tr\"\n| \"tdsch1' (Suc k) (Suc kk) pd pc dis_s (Task READY ent tp) task_s (Sch p rn rp) s tr \\<longleftrightarrow> \n      (if rn \\<noteq> -1 then out_0assm_assn (preempt_ch rn) 0 \n            (tdsch1' k kk pd pc dis_s (Task RUNNING (Suc 0) tp)\n             (task_s(CHR ''c'' := up_ent_c ent (task_s CHR ''c''))) (Sch p 1 2) (s(CHR ''p'' := 2)))\n       else tdsch1' k kk pd pc dis_s (Task RUNNING (Suc 0) tp)\n             (task_s(CHR ''c'' := up_ent_c ent (task_s CHR ''c''))) (Sch p 1 2) (s(CHR ''p'' := 2))) tr \\<or>\n      in_0orig_vassm'_assn (req_ch 2) {1} (\\<lambda> v. if v \\<le> rp then (tdsch1' (Suc k) kk pd pc dis_s (Task READY ent tp) task_s (Sch (p @ [(1, 2)]) rn rp)(s(CHR ''p'' := 1))) \n                                                         else if rn \\<noteq> -1 then (out_0assm_assn (preempt_ch rn) 0 (out_0assm_assn (run_ch 2) 0 (tdsch1' (Suc k) kk pd pc dis_s (Task READY ent tp) task_s (Sch p 2 1) (s(CHR ''p'' := 1))))) \n                                                                        else (out_0assm_assn (run_ch 2) 0 (tdsch1' (Suc k) kk pd pc dis_s (Task READY ent tp) task_s (Sch p 2 1) (s(CHR ''p'' := 1))))) tr \\<or> \n      in_0orig_vassm'_assn (free_ch 2) {0} (\\<lambda> v. if length p > 0 then out_0assm_assn (run_ch (run_now (sched_get_max (Sch p rn rp) s))) 0 \n                                                                  (tdsch1' (Suc k) kk pd pc dis_s (Task READY ent tp) task_s (sched_get_max (Sch p rn rp) s) s)\n                                                                else \n                                                                  (tdsch1' (Suc k) kk pd pc dis_s (Task READY ent tp) task_s (sched_clear (Sch p rn rp) s) s)) tr \\<or>\n      in_0orig_vassm'_assn (exit_ch 2) {0} (\\<lambda> v. tdsch1' (Suc k) kk pd pc dis_s (Task READY ent tp) task_s (Sch (del_proc p 2) rn rp) s) tr\"\n|\"tdsch1' (Suc k) (Suc kk) pd pc dis_s (Task RUNNING ent tp) task_s (Sch p rn rp) s tr \\<longleftrightarrow> \n                               waitin_tguar'_vassm'_assn {..min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')} \n                                        (\\<lambda>t. ParState\n                                                  (ParState (EState (Task RUNNING ent tp, task_s\n                                                                      (CHR ''t'' := task_s CHR ''t'' + t,\n                                                                       CHR ''c'' := task_s CHR ''c'' + t)))\n                                                            (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\n                                                  (EState (Sch p rn rp, s)))\n                                        ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2, preempt_ch 1})\n                                        (req_ch 2) {1} \n                                  (\\<lambda> v d. tdsch1' (Suc k) kk pd pc (dis_s(CHR ''t'' := dis_s CHR ''t'' + d)) (Task RUNNING ent tp) \n                                        (task_s(CHR ''t'' := task_s CHR ''t'' + d,\n                                                CHR ''c'' := task_s CHR ''c'' + d)) \n                                        (Sch (p @ [(1, 2)]) 1 2) (s(CHR ''p'' := 1))) tr \\<or>\n                               waitin_tguar'_vassm'_assn {..min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')} \n                                        (\\<lambda>t. ParState\n                                                  (ParState (EState (Task RUNNING ent tp, task_s\n                                                                      (CHR ''t'' := task_s CHR ''t'' + t,\n                                                                       CHR ''c'' := task_s CHR ''c'' + t)))\n                                                            (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\n                                                  (EState (Sch p rn rp, s)))\n                                        ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2, preempt_ch 1})\n                                        (free_ch 2) {0} \n                                  (\\<lambda> v d. true\\<^sub>A ) tr \\<or>\n                               waitin_tguar'_vassm'_assn {..min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')} \n                                        (\\<lambda>t. ParState\n                                                  (ParState (EState (Task RUNNING ent tp, task_s\n                                                                      (CHR ''t'' := task_s CHR ''t'' + t,\n                                                                       CHR ''c'' := task_s CHR ''c'' + t)))\n                                                            (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\n                                                  (EState (Sch p rn rp, s)))\n                                        ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2, preempt_ch 1})\n                                        (exit_ch 2) {0} \n                                  (\\<lambda> v d. tdsch1' (Suc k) kk pd pc (dis_s(CHR ''t'' := dis_s CHR ''t'' + d)) (Task RUNNING ent tp) \n                                        (task_s(CHR ''t'' := task_s CHR ''t'' + d,\n                                                CHR ''c'' := task_s CHR ''c'' + d)) \n                                        (Sch (del_proc p 2) rn rp) s) tr \\<or>\n                               wait_orig_assn (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\n                                     (\\<lambda>t. ParState\n                                           (ParState (EState (Task RUNNING ent tp, task_s(CHR ''t'' := task_s CHR ''t'' + t, CHR ''c'' := task_s CHR ''c'' + t)))\n                                             (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\n                                           (EState (Sch p rn rp, s)))\n                                     ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2, preempt_ch 1})\n                                     (if length p > 0 then out_0assm_assn (run_ch (run_now (sched_get_max (Sch p rn rp) s))) 0 \n                                                 (tdsch1' k kk pd pc (dis_s(CHR ''t'' := dis_s CHR ''t'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                                               (Task WAIT ent tp)\n                                                               (task_s\n                                                                (CHR ''t'' := task_s CHR ''t'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                                                 CHR ''c'' := task_s CHR ''c'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))) \n                                                               (sched_get_max (Sch p rn rp) s) s)\n                                                      else \n                                                 (tdsch1' k kk pd pc (dis_s(CHR ''t'' := dis_s CHR ''t'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                                               (Task WAIT ent tp) \n                                                               (task_s\n                                                                (CHR ''t'' := task_s CHR ''t'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                                                 CHR ''c'' := task_s CHR ''c'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))) \n                                                                (sched_clear (Sch p rn rp) s) s)) tr\"\n|  \"tdsch1' k kk pd pc dis_s (Sch p rn rp) task_s schs s tr \\<longleftrightarrow> False\"\n|  \"tdsch1' k kk pd pc dis_s None task_s schs s tr \\<longleftrightarrow> False\"\n|  \"tdsch1' k kk pd pc dis_s task_es task_s (Task st ent tp) s tr \\<longleftrightarrow> False\"\n|  \"tdsch1' k kk pd pc dis_s task_es task_s None s tr \\<longleftrightarrow> False\"\n\nthm tdsch1'.simps\n\n\nlemma combine_wait_orig_waitin_assms'1:\n  assumes\"ch \\<in> chs\"\n     and \"compat_rdy rdy1 rdy2\"\n   shows \"combine_assn chs (wait_orig_assn d p1 rdy1 P) (waitin_assms'_assn UNIV p2 rdy2 ch V Q)\n     \\<Longrightarrow>\\<^sub>t wait_orig_assn d (\\<lambda> t. ParState (p1 t)(p2 t)) (merge_rdy rdy1 rdy2) \n          (combine_assn chs P (waitin_assms'_assn UNIV (\\<lambda> t. p2(t+d)) rdy2 ch V (\\<lambda> v t. Q v (t+d))))\"\n  unfolding entails_tassn_def combine_assn_def\n  apply auto\n  subgoal for tr tr1 tr2\n    apply(cases rule: wait_orig_assn.cases[of d p1 rdy1 P tr1])\n      apply auto\n    subgoal\n      apply(rule wait_orig_assn.intros(1))\n      by auto\n    subgoal for tr1'\n      apply(cases rule: waitin_assms'_assn.cases[of UNIV p2 rdy2 ch V Q tr2])\n          apply simp\n      subgoal for v tr2'\n        using assms by (auto elim!: sync_elims)\n      subgoal for  v  d' tr2'\n        apply(cases \"d>d'\")\n        subgoal\n          apply auto\n          apply(elim combine_blocks_waitE4)\n          using assms by (auto elim!: sync_elims)\n        apply(cases \"d<d'\")\n        subgoal\n          apply auto\n          apply(elim combine_blocks_waitE3)\n          using assms apply auto\n          apply(rule wait_orig_assn.intros(2))\n           apply auto\n          subgoal for tr'\n            apply(rule exI[where x=\"tr1'\"])\n            apply auto\n            apply(rule exI[where x=\"(WaitBlk (d' - d) (\\<lambda>t. p2 (t + d)) rdy2 # InBlock ch v # tr2')\"])\n            apply auto\n            apply(rule waitin_assms'_assn.intros(2))\n            by auto\n          done\n        apply auto\n        apply(elim combine_blocks_waitE2)\n          using assms apply auto\n          apply(rule wait_orig_assn.intros(2))\n           apply auto\n          subgoal for tr'\n            apply(rule exI[where x=\"tr1'\"])\n            apply auto\n            apply(rule exI[where x=\"(InBlock ch v # tr2')\"])\n            apply auto\n            apply(rule waitin_assms'_assn.intros(1))\n            by auto\n              done\n            subgoal for w tr2'\n              using assms by (auto elim!: sync_elims)\n            subgoal for d' v  tr2'\n              apply(cases \"d>d'\")\n              subgoal\n                apply auto\n                apply(elim combine_blocks_waitE4)\n                using assms apply auto\n                by (auto elim!: sync_elims)\n              apply(cases \"d<d'\")\n              subgoal\n                apply auto\n                apply(elim combine_blocks_waitE3)\n                using assms apply auto\n                apply(rule wait_orig_assn.intros(2))\n                 apply auto\n                subgoal for tr'\n                  apply(rule exI[where x=\"tr1'\"])\n                  apply auto\n                  apply(rule exI[where x=\"(WaitBlk (d' - d) (\\<lambda>t. p2 (t + d)) rdy2 # InBlock ch v # tr2')\"])\n                  apply auto\n                  apply(rule waitin_assms'_assn.intros(4))\n                  by auto\n                done\n              apply auto\n              apply(elim combine_blocks_waitE2)\n              using assms apply auto\n              apply(rule wait_orig_assn.intros(2))\n               apply auto\n              subgoal for tr'\n                apply(rule exI[where x=\"tr1'\"])\n                apply auto\n                apply(rule exI[where x=\"(InBlock ch v # tr2')\"])\n                apply auto\n                apply(rule waitin_assms'_assn.intros(3))\n                by auto\n              done\n            done\n          done\n        done\n(*\nlemma combine_io_orig_waitin_assms'1:\n  assumes\"ch \\<in> chs\"\n     and \"dh \\<notin> chs\"\n   shows \"combine_assn chs (io_orig_assn dh v P) (waitin_assms'_assn UNIV p rdy ch V Q)\n     \\<Longrightarrow>\\<^sub>t io_orig_assn dh v \n          (combine_assn chs P (waitin_assms'_assn UNIV p rdy ch V Q))\"\n  unfolding entails_tassn_def combine_assn_def\n  apply auto\n  subgoal for tr tr1 tr2\n    apply(cases rule: io_orig_assn.cases[of dh v P tr1])\n     apply auto\n    subgoal for tr1'\n      apply(cases rule: waitin_assms'_assn.cases[of UNIV p rdy ch V Q tr2])\n          apply simp\n      subgoal for w tr2'\n        apply auto\n        apply (elim combine_blocks_unpairE1)\n        using assms apply auto\n        apply(rule io_orig_assn.intros)\n        by auto\n      subgoal for w d tr2'\n        apply auto\n        apply(elim combine_blocks_unpairE3)\n        using assms apply auto\n        apply(rule io_orig_assn.intros)\n        by auto\n      subgoal for w tr2'\n        apply auto\n        apply (elim combine_blocks_unpairE1)\n        using assms apply auto\n        apply(rule io_orig_assn.intros)\n        by auto\n      subgoal for w d tr2'\n        apply auto\n        apply(elim combine_blocks_unpairE3)\n        using assms apply auto\n        apply(rule io_orig_assn.intros)\n        by auto\n      done\n    done\n  done\n*)\n\nlemma combine_wait_orig_out_0assm_rdy_out_0assm2:\n  assumes \"dh \\<notin> chs \\<and> ch \\<in> chs\"\n  shows \"combine_assn chs (wait_orig_assn d p rdy (out_0assm_rdy_assn ch v rdy' P)) (out_0assm_assn dh w Q)\n    \\<Longrightarrow>\\<^sub>t out_0assm_assn dh w (combine_assn chs (wait_orig_assn d p rdy (out_0assm_rdy_assn ch v rdy' P)) Q)\"\n  unfolding combine_assn_def entails_tassn_def\n  apply auto\n  subgoal for tr tr1 tr2\n    apply(cases rule: wait_orig_assn.cases[of  d p rdy \"(out_0assm_rdy_assn ch v rdy' P)\" tr1])\n      apply auto\n    subgoal\n      apply(cases rule: out_0assm_rdy_assn.cases[of ch v rdy' P tr1])\n      apply auto\n      subgoal for tr1'\n        apply(cases rule: out_0assm_assn.cases[of dh w Q tr2])\n          apply auto\n        subgoal for tr2'\n          apply(elim combine_blocks_unpairE1')\n          using assms\n            apply auto\n          apply(rule out_0assm_assn.intros(1))\n          by auto\n        subgoal for d2 p2 a2 b2 tr2'\n          using assms\n          by (auto elim!: sync_elims)\n        done\n      subgoal for d1 p1 tr1'\n        apply(cases rule: out_0assm_assn.cases[of dh w Q tr2])\n          apply auto\n        subgoal for tr2'\n          apply(elim combine_blocks_unpairE3')\n          using assms apply auto\n          apply(rule out_0assm_assn.intros(1))\n          by auto\n        subgoal for d2 a2 b2 p2 tr2'\n          apply(cases \"\\<not> compat_rdy rdy' (a2,b2)\")\n          subgoal\n            by (auto elim!: sync_elims)\n          apply(cases \"d2<d1\")\n          subgoal\n           apply(elim combine_blocks_waitE4)\n               apply auto\n            apply(rule out_0assm_assn.intros(2))\n             apply auto\n            apply(cases rdy')\n            by auto\n          apply(cases \"d2>d1\")\n          subgoal\n            apply(elim combine_blocks_waitE3)\n               apply auto\n            apply(rule out_0assm_assn.intros(2))\n             apply auto\n            apply(cases rdy')\n            by auto\n          apply auto\n          apply(elim combine_blocks_waitE2)\n               apply auto\n            apply(rule out_0assm_assn.intros(2))\n             apply auto\n            apply(cases rdy')\n          by auto\n        done\n      done\n    subgoal for tr1'\n      apply(cases rule: out_0assm_assn.cases[of dh w Q tr2])\n        apply auto\n      subgoal for tr2'\n        apply(elim combine_blocks_unpairE3')\n        using assms apply auto\n        apply(rule out_0assm_assn.intros(1))\n        by auto\n      subgoal for d2 a2 b2 p2 tr2'\n        apply(cases \"\\<not> compat_rdy rdy (a2,b2)\")\n          subgoal\n            by (auto elim!: sync_elims)\n          apply(cases \"d2<d\")\n          subgoal\n           apply(elim combine_blocks_waitE4)\n               apply auto\n            apply(rule out_0assm_assn.intros(2))\n             apply auto\n            apply(cases rdy)\n            by auto\n          apply(cases \"d2>d\")\n          subgoal\n            apply(elim combine_blocks_waitE3)\n               apply auto\n            apply(rule out_0assm_assn.intros(2))\n             apply auto\n            apply(cases rdy)\n            by auto\n          apply auto\n          apply(elim combine_blocks_waitE2)\n               apply auto\n            apply(rule out_0assm_assn.intros(2))\n             apply auto\n            apply(cases rdy)\n          by auto\n        done\n      done\n    done\n\n\nlemma combine_wait_orig_in_0assm_rdy_out_0assm2:\n  assumes \"dh \\<notin> chs \\<and> ch \\<in> chs\"\n  shows \"combine_assn chs (wait_orig_assn d p rdy (in_0assm_rdy_assn ch v rdy' P)) (out_0assm_assn dh w Q)\n    \\<Longrightarrow>\\<^sub>t out_0assm_assn dh w (combine_assn chs (wait_orig_assn d p rdy (in_0assm_rdy_assn ch v rdy' P)) Q)\"\n  unfolding combine_assn_def entails_tassn_def\n  apply auto\n  subgoal for tr tr1 tr2\n    apply(cases rule: wait_orig_assn.cases[of  d p rdy \"(in_0assm_rdy_assn ch v rdy' P)\" tr1])\n      apply auto\n    subgoal\n      apply(cases rule: in_0assm_rdy_assn.cases[of ch v rdy' P tr1])\n      apply auto\n      subgoal for tr1'\n        apply(cases rule: out_0assm_assn.cases[of dh w Q tr2])\n          apply auto\n        subgoal for tr2'\n          apply(elim combine_blocks_unpairE1')\n          using assms\n            apply auto\n          apply(rule out_0assm_assn.intros(1))\n          by auto\n        subgoal for d2 p2 a2 b2 tr2'\n          using assms\n          by (auto elim!: sync_elims)\n        done\n      subgoal for vv tr1'\n        apply(cases rule: out_0assm_assn.cases[of dh w Q tr2])\n          apply auto\n        subgoal for tr2'\n          apply(elim combine_blocks_unpairE1')\n          using assms\n            apply auto\n          apply(rule out_0assm_assn.intros(1))\n          by auto\n        subgoal for d2 p2 a2 b2 tr2'\n          using assms\n          by (auto elim!: sync_elims)\n        done\n      subgoal for d1 p1 tr1'\n        apply(cases rule: out_0assm_assn.cases[of dh w Q tr2])\n          apply auto\n        subgoal for tr2'\n          apply(elim combine_blocks_unpairE3')\n          using assms apply auto\n          apply(rule out_0assm_assn.intros(1))\n          by auto\n        subgoal for d2 a2 b2 p2 tr2'\n          apply(cases \"\\<not> compat_rdy rdy' (a2,b2)\")\n          subgoal\n            by (auto elim!: sync_elims)\n          apply(cases \"d2<d1\")\n          subgoal\n           apply(elim combine_blocks_waitE4)\n               apply auto\n            apply(rule out_0assm_assn.intros(2))\n             apply auto\n            apply(cases rdy')\n            by auto\n          apply(cases \"d2>d1\")\n          subgoal\n            apply(elim combine_blocks_waitE3)\n               apply auto\n            apply(rule out_0assm_assn.intros(2))\n             apply auto\n            apply(cases rdy')\n            by auto\n          apply auto\n          apply(elim combine_blocks_waitE2)\n               apply auto\n            apply(rule out_0assm_assn.intros(2))\n             apply auto\n            apply(cases rdy')\n          by auto\n        done\n      done\n    subgoal for tr1'\n      apply(cases rule: out_0assm_assn.cases[of dh w Q tr2])\n        apply auto\n      subgoal for tr2'\n        apply(elim combine_blocks_unpairE3')\n        using assms apply auto\n        apply(rule out_0assm_assn.intros(1))\n        by auto\n      subgoal for d2 a2 b2 p2 tr2'\n        apply(cases \"\\<not> compat_rdy rdy (a2,b2)\")\n          subgoal\n            by (auto elim!: sync_elims)\n          apply(cases \"d2<d\")\n          subgoal\n           apply(elim combine_blocks_waitE4)\n               apply auto\n            apply(rule out_0assm_assn.intros(2))\n             apply auto\n            apply(cases rdy)\n            by auto\n          apply(cases \"d2>d\")\n          subgoal\n            apply(elim combine_blocks_waitE3)\n               apply auto\n            apply(rule out_0assm_assn.intros(2))\n             apply auto\n            apply(cases rdy)\n            by auto\n          apply auto\n          apply(elim combine_blocks_waitE2)\n               apply auto\n            apply(rule out_0assm_assn.intros(2))\n             apply auto\n            apply(cases rdy)\n          by auto\n        done\n      done\n    done\n\nlemma combine_waitin_tguar'_vassm'_waitin_assms'1:\n  assumes \"ch1 \\<in> chs \\<and> ch2 \\<in> chs\"\n  shows \"combine_assn chs (waitin_tguar'_vassm'_assn S1 p1 rdy1 ch1 V1 P1) (waitin_assms'_assn S2 p2 rdy2 ch2 V2 P2) \\<Longrightarrow>\\<^sub>t P\"\n  unfolding combine_assn_def entails_tassn_def apply auto\n  subgoal for tr tr1 tr2\n    apply(cases rule: waitin_tguar'_vassm'_assn.cases[of S1 p1 rdy1 ch1 V1 P1 tr1])\n        apply auto\n    subgoal for v1 tr1'\n      apply(cases rule: waitin_assms'_assn.cases[of S2 p2 rdy2 ch2 V2 P2 tr2])\n          apply simp\n      subgoal for v2 tr2'\n        apply auto\n        apply(elim combine_blocks_pairE)\n        using assms by auto\n      subgoal for v2 d2 tr2'\n        using assms\n        by (auto elim!: sync_elims)\n      subgoal for v2 tr2'\n        apply auto\n        subgoal\n        apply(elim combine_blocks_pairE)\n          using assms by auto\n        subgoal\n        apply(elim combine_blocks_pairE)\n          using assms by auto\n        done\n      subgoal for d2 v2 tr2'\n        using assms\n        by (auto elim!: sync_elims)\n      done\n    subgoal for d1 v1 tr1'\n      apply(cases rule: waitin_assms'_assn.cases[of S2 p2 rdy2 ch2 V2 P2 tr2])\n          apply simp\n      subgoal for v2 tr2'\n        apply auto\n        using assms\n        by (auto elim!: sync_elims)\n      subgoal for v2 d2 tr2'\n        apply auto\n        apply(cases \"\\<not>compat_rdy rdy1 rdy2\")\n        subgoal\n          by(auto elim!: sync_elims)\n        apply(cases \"d1>d2\")\n        subgoal\n          apply(elim combine_blocks_waitE4)\n             apply auto\n          using assms\n          by(auto elim!: sync_elims)\n        apply(cases \"d1<d2\")\n        subgoal\n          apply(elim combine_blocks_waitE3)\n             apply auto\n          using assms\n          by(auto elim!: sync_elims)\n        apply auto\n        apply(elim combine_blocks_waitE2)\n             apply auto\n          using assms\n          apply(elim combine_blocks_pairE)\n          by auto\n        subgoal for w2 tr2'\n          apply auto\n          subgoal\n            using assms\n            by(auto elim!: sync_elims)\n          subgoal\n            using assms\n            by(auto elim!: sync_elims)\n          done\n        subgoal for d2 v2 tr2'\n          apply auto\n          subgoal\n            apply(cases \"\\<not>compat_rdy rdy1 rdy2\")\n            subgoal\n              by(auto elim!: sync_elims)\n            apply(cases \"d1>d2\")\n            subgoal\n              apply(elim combine_blocks_waitE4)\n                 apply auto\n              using assms\n              by(auto elim!: sync_elims)\n            apply(cases \"d1<d2\")\n            subgoal\n              apply(elim combine_blocks_waitE3)\n                 apply auto\n              using assms\n              by(auto elim!: sync_elims)\n            apply auto\n            apply(elim combine_blocks_waitE2)\n                 apply auto\n              using assms\n              apply(elim combine_blocks_pairE)\n              by auto\n          subgoal\n            apply(cases \"\\<not>compat_rdy rdy1 rdy2\")\n            subgoal\n              by(auto elim!: sync_elims)\n            apply(cases \"d1>d2\")\n            subgoal\n              apply(elim combine_blocks_waitE4)\n                 apply auto\n              using assms\n              by(auto elim!: sync_elims)\n            apply(cases \"d1<d2\")\n            subgoal\n              apply(elim combine_blocks_waitE3)\n                 apply auto\n              using assms\n              by(auto elim!: sync_elims)\n            apply auto\n            apply(elim combine_blocks_waitE2)\n                 apply auto\n              using assms\n              apply(elim combine_blocks_pairE)\n              by auto\n            done\n          done\n     subgoal for v1 tr1'\n      apply(cases rule: waitin_assms'_assn.cases[of S2 p2 rdy2 ch2 V2 P2 tr2])\n          apply simp\n      subgoal for v2 tr2'\n        apply auto\n        apply(elim combine_blocks_pairE)\n        using assms by auto\n      subgoal for v2 d2 tr2'\n        using assms\n        by (auto elim!: sync_elims)\n      subgoal for v2 tr2'\n        apply auto\n        subgoal\n        apply(elim combine_blocks_pairE)\n          using assms by auto\n        subgoal\n        apply(elim combine_blocks_pairE)\n          using assms by auto\n        done\n      subgoal for d2 v2 tr2'\n        using assms\n        by (auto elim!: sync_elims)\n      done\nsubgoal for d1 v1 tr1'\n      apply(cases rule: waitin_assms'_assn.cases[of S2 p2 rdy2 ch2 V2 P2 tr2])\n          apply simp\n      subgoal for v2 tr2'\n        apply auto\n        using assms\n        by (auto elim!: sync_elims)\n      subgoal for v2 d2 tr2'\n        apply auto\n        apply(cases \"\\<not>compat_rdy rdy1 rdy2\")\n        subgoal\n          by(auto elim!: sync_elims)\n        apply(cases \"d1>d2\")\n        subgoal\n          apply(elim combine_blocks_waitE4)\n             apply auto\n          using assms\n          by(auto elim!: sync_elims)\n        apply(cases \"d1<d2\")\n        subgoal\n          apply(elim combine_blocks_waitE3)\n             apply auto\n          using assms\n          by(auto elim!: sync_elims)\n        apply auto\n        apply(elim combine_blocks_waitE2)\n             apply auto\n          using assms\n          apply(elim combine_blocks_pairE)\n          by auto\n        subgoal for w2 tr2'\n          apply auto\n          subgoal\n            using assms\n            by(auto elim!: sync_elims)\n          subgoal\n            using assms\n            by(auto elim!: sync_elims)\n          done\n        subgoal for d2 v2 tr2'\n          apply auto\n          subgoal\n            apply(cases \"\\<not>compat_rdy rdy1 rdy2\")\n            subgoal\n              by(auto elim!: sync_elims)\n            apply(cases \"d1>d2\")\n            subgoal\n              apply(elim combine_blocks_waitE4)\n                 apply auto\n              using assms\n              by(auto elim!: sync_elims)\n            apply(cases \"d1<d2\")\n            subgoal\n              apply(elim combine_blocks_waitE3)\n                 apply auto\n              using assms\n              by(auto elim!: sync_elims)\n            apply auto\n            apply(elim combine_blocks_waitE2)\n                 apply auto\n              using assms\n              apply(elim combine_blocks_pairE)\n              by auto\n          subgoal\n            apply(cases \"\\<not>compat_rdy rdy1 rdy2\")\n            subgoal\n              by(auto elim!: sync_elims)\n            apply(cases \"d1>d2\")\n            subgoal\n              apply(elim combine_blocks_waitE4)\n                 apply auto\n              using assms\n              by(auto elim!: sync_elims)\n            apply(cases \"d1<d2\")\n            subgoal\n              apply(elim combine_blocks_waitE3)\n                 apply auto\n              using assms\n              by(auto elim!: sync_elims)\n            apply auto\n            apply(elim combine_blocks_waitE2)\n                 apply auto\n              using assms\n              apply(elim combine_blocks_pairE)\n              by auto\n            done\n          done\n        done\n      done\n   \n\n    \n\nlemma combine_blocks_emptyE'3' [sync_elims]:\n  \"combine_blocks comms [] (CommBlock ch_type2 ch2 v2 # tr2) tr \\<Longrightarrow>\n   ch2 \\<notin> comms \\<Longrightarrow> \n   (\\<And>tr'. tr = CommBlock ch_type2 ch2 v2 # tr' \\<Longrightarrow>\n           combine_blocks comms [] tr2 tr' \\<Longrightarrow> P) \\<Longrightarrow> P\"\n  by (induct rule: combine_blocks.cases, auto)\n        \ndefinition propc :: \"nat \\<Rightarrow> estate \\<Rightarrow> estate \\<Rightarrow> bool\" where\n\"propc k task_es schs = (k>0 \\<longrightarrow>(status task_es = RUNNING \\<longleftrightarrow> run_now schs = 1))\"\n\n\n\nlemma combine_taskdis_sch1':\n  \"task_dis_assn' 1 k pd pc dis_s task_es task_s tr1 \\<Longrightarrow>\n   sched_assn' kk schs s tr2 \\<Longrightarrow>\n   task_prior task_es = 2 \\<Longrightarrow>\n   propc k task_es schs \\<Longrightarrow>\n   proper schs \\<Longrightarrow>\n   combine_blocks {req_ch 1, preempt_ch 1, run_ch 1, free_ch 1, exit_ch 1} tr1 tr2 tr \\<Longrightarrow>\n   tdsch1' k kk pd pc dis_s task_es task_s schs s tr\"\n  thm nat_less_induct \n  thm less_induct\n    proof(induction \" k+kk\"  arbitrary: k kk task_es task_s dis_s schs s tr1 tr2 tr rule: less_induct)\n      case less\n      then show ?case \n        apply (cases k)\n        subgoal \n          apply (cases kk)\n          subgoal apply simp\n            apply (cases schs)\n              apply auto\n              apply (cases task_es)\n              apply auto\n              subgoal premises pre\n              thm pre\n              apply (rule combine_blocks_assn)\n                 apply(rule pre(1))\n                apply(rule pre(2))\n               apply(rule pre(5))\n              by (auto elim!: sync_elims)\n            done\n          subgoal for kk'\n            apply simp\n            apply(cases schs)\n              apply(cases task_es)\n            subgoal by auto\n            apply (simp del: tdsch1'.simps)\n            subgoal for p rn rp st ent tp\n              apply(erule disjE)\n              subgoal premises pre\n                thm pre\n                apply (rule combine_blocks_assn)\n                   apply(rule pre(2))\n                  apply(rule pre(11))\n                 apply(rule pre(6))\n                apply(rule combine_emp_waitin_assms'1)\n                by auto\n              apply(erule disjE)        \n              subgoal premises pre\n                thm pre\n                apply (simp only:tdsch1'.simps)\n                apply(rule disjI1)\n                apply (rule combine_blocks_assn)\n                   apply(rule pre(2))\n                  apply(rule pre(11))\n                 apply(rule pre(6))\n                apply(rule entails_tassn_trans)\n                 apply(rule combine_emp_waitin_assms'2)\n                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                apply(rule in_0orig_vassm'_assn_tran)\n                apply clarify\n                apply simp\n                apply(rule conjI)\n                subgoal\n                  apply clarify\n                  apply(rule conjI)\n                  subgoal apply clarify\n                    unfolding entails_tassn_def combine_assn_def\n                    apply clarify\n                    subgoal for tr tr1 tr2\n                      using pre(1)[of 0 kk' dis_s \"(Task st ent 2)\" task_s tr1 \"(Sch (p @ [(1, 2)]) rn rp)\"\" (s(CHR ''p'' := 1))\" tr2 tr]\n                      using pre(4,5,6)[unfolded pre(10)] \n                      unfolding proper_def properp_def\n                      using properl_p1 propc_def\n                      by (auto simp add: properp_def)\n                    done\n                  subgoal apply clarify\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_emp_out_0assm3)\n                    apply(rule entails_tassn_conj)\n                    subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                    apply auto\n                    apply(rule out_0assm_assn_tran)\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_emp_out_0assm2)\n                    subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                    apply(rule out_0assm_assn_tran)\n                    unfolding entails_tassn_def combine_assn_def\n                    apply clarify\n                    subgoal for tr tr1 tr2\n                      using pre(1)[of 0 kk' dis_s task_es task_s tr1 \"(Sch p 2 1)\"\"(s(CHR ''p'' := 1))\" tr2 tr]\n                      using pre(4,5,6)[unfolded pre(10)] \n                      unfolding proper_def properp_def propc_def\n                      by auto\n                    done\n                  done\n                subgoal\n                  apply clarify\n                  apply(rule conjI)\n                  subgoal apply clarify\n                    unfolding entails_tassn_def combine_assn_def\n                    apply clarify\n                    subgoal for tr tr1 tr2\n                      using pre(1)[of 0 kk' dis_s task_es task_s tr1 \"(Sch (p @ [(1, 2)]) (- 1) rp)\" \"(s(CHR ''p'' := 1))\" tr2 tr ]\n                      using pre(4,5,6)[unfolded pre(10)] \n                      unfolding proper_def properp_def\n                      by auto\n                    done\n                  apply clarify\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_emp_out_0assm2)\n                  subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                  apply(rule out_0assm_assn_tran)\n                  unfolding entails_tassn_def combine_assn_def\n                  apply clarify\n                  subgoal for tr tr1 tr2\n                    using pre(1)[of 0 kk' dis_s \"(Task st ent 2)\" task_s tr1 \"(Sch p 2 1)\" \"(s(CHR ''p'' := 1))\" tr2 tr ]\n                    using pre(4,5,6)[unfolded pre(10)] \n                    unfolding proper_def properp_def propc_def\n                    by auto\n                  done\n                done\n              apply(erule disjE)\n              subgoal premises pre\n                thm pre\n                apply (rule combine_blocks_assn)\n                   apply(rule pre(2))\n                  apply(rule pre(11))\n                 apply(rule pre(6))\n                apply(rule combine_emp_waitin_assms'1)\n                by auto\n              apply(erule disjE)\n              subgoal premises pre\n                apply(simp only:tdsch1'.simps)\n                apply(rule disjI2)\n                apply(rule disjI1)\n                apply (rule combine_blocks_assn)\n                   apply(rule pre(2))\n                  apply(rule pre(11))\n                 apply(rule pre(6))\n                apply(rule entails_tassn_trans)\n                 apply(rule combine_emp_waitin_assms'2)\n                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                apply(rule in_0orig_vassm'_assn_tran)\n                subgoal for v \n                  apply clarify\n                  apply simp\n                  apply(rule conjI)\n                  subgoal apply clarify\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_emp_out_0assm2)\n                    thm pre\n                    subgoal using pre(4,5) properl_p5[of p] unfolding proper_def properp_def\n                      apply(cases \"get_max p\")\n                      subgoal for a b\n                        apply(subgoal_tac \"b \\<noteq> 1\")\n                        subgoal\n                          by (auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                        by auto\n                      done\n                    apply(rule out_0assm_assn_tran)\n                    unfolding entails_tassn_def combine_assn_def\n                    apply auto\n                    subgoal for tr tr1 tr2\n                      using pre(1)[of 0 kk' dis_s \"(Task st ent 2)\" task_s tr1 \"(case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior)\" s tr2 tr ]\n                      using pre(4,5,6)[unfolded pre(10)] \n                      unfolding proper_def propc_def\n                      apply auto\n                      apply (cases \"get_max p\")\n                      subgoal for a b apply auto\n                        using properl_p3[of p] properl_p4[of p b]\n                        by auto\n                      done\n                    done\n                  unfolding entails_tassn_def combine_assn_def\n                  apply auto\n                  subgoal for tr tr1 tr2\n                    using pre(1)[of 0 kk' dis_s \"(Task st ent 2)\" task_s tr1 \"(Sch [] (- 1) (- 1))\" s tr2 tr]\n                    using pre(4,5,6) \n                    unfolding proper_def properp_def propc_def\n                    by auto\n                  done\n                done\n              apply(erule disjE)\n              subgoal premises pre\n                apply (rule combine_blocks_assn)\n                   apply(rule pre(2))\n                  apply(rule pre(11))\n                 apply(rule pre(6))\n                apply(rule combine_emp_waitin_assms'1)\n                by auto\n              subgoal premises pre\n                apply(simp only: tdsch1'.simps)\n                apply(rule disjI2)\n                apply(rule disjI2)\n                apply (rule combine_blocks_assn)\n                   apply(rule pre(2))\n                  apply(rule pre(11))\n                 apply(rule pre(6))\n                apply(rule entails_tassn_trans)\n                 apply(rule combine_emp_waitin_assms'2)\n                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                apply(rule in_0orig_vassm'_assn_tran)\n                apply auto\n                unfolding entails_tassn_def combine_assn_def\n                 apply auto\n                subgoal for tr tr1 tr2\n                  using pre(1)[of 0 kk' dis_s \"(Task st ent 2)\" task_s tr1 \"(Sch (del_proc p 2) rn rp)\" s tr2 tr]\n                  using pre(4,5,6)[unfolded pre(10)]\n                  unfolding proper_def propc_def\n                  using properl_p4[of p 2]\n                  by auto\n                done\n              done\n             apply auto\n            done\n          done\n        subgoal for k'\n          apply(cases kk)\n          subgoal\n            apply auto\n            apply (cases schs)\n              apply (cases task_es)\n                apply auto\n            subgoal for p rn rp st ent\n              apply (cases st)\n                apply simp\n              subgoal premises pre\n                thm pre\n                apply(rule combine_blocks_assn)\n                   apply(rule pre(2))\n                  apply(rule pre(3))\n                 apply(rule pre(6))\n                apply(rule entails_tassn_trans)\n                 apply(rule combine_wait_orig_emp5)\n                unfolding entails_tassn_def combine_assn_def\n                  apply auto\n                subgoal for tr tr1 tr2\n                  using pre(1)[of k' 0 \"(dis_s(CHR ''t'' := 0))\" \"(Task READY 0 2)\" \"(task_s(CHR ''t'' := 0))\" tr1 \"(Sch p rn rp)\" s tr2 tr]\n                  using pre(4,5) unfolding propc_def by auto\n                done\n              subgoal \n                apply simp\n                apply(erule disjE)\n                subgoal premises pre\n                thm pre\n                apply(rule combine_blocks_assn)\n                   apply(rule pre(11))\n                  apply(rule pre(2))\n                 apply(rule pre(5))\n                apply(rule combine_out_0assm_emp1)\n                by auto\n              apply(erule disjE)\n              subgoal premises pre\n                thm pre\n                apply(rule combine_blocks_assn)\n                   apply(rule pre(11))\n                   apply(rule pre(2))\n                 apply(rule pre(5))\n                apply(rule combine_out_0assm_emp1)\n                by auto\n              subgoal premises pre\n                thm pre\n                apply(rule combine_blocks_assn)\n                   apply(rule pre(11))\n                   apply(rule pre(2))\n                 apply(rule pre(5))\n                apply(rule combine_out_0assm_emp1)\n                by auto\n              done\n              apply(cases \"ent = 1\")\n               apply auto\n              subgoal premises pre\n                thm pre\n                apply(rule combine_blocks_assn)\n                   apply(rule pre(12))\n                  apply(rule pre(2))\n                 apply(rule pre(5))\n                apply(rule combine_waitin_tguar'_vassm'_emp1)\n                by auto\n              subgoal premises pre\n                thm pre\n                apply(rule combine_blocks_assn)\n                   apply(rule pre(12))\n                  apply(rule pre(2))\n                 apply(rule pre(5))\n                apply(rule entails_tassn_trans)\n                 apply(rule combine_wait_orig_emp5)\n                apply(rule combine_out_0assm_srdy_emp1)\n                by auto\n              done\n            done\n          subgoal for kk'\n            apply auto\n            apply (cases schs)\n            subgoal for p rn rp\n              apply(cases task_es)\n              subgoal by auto\n              subgoal for st ent tp\n                apply (cases st)\n                subgoal premises pre\n                  thm pre\n                  thm fun_upd_def\n                  using pre(2) pre(3)\n                  apply(simp only: pre(10,11,12))\n                  apply(simp only: task_dis_assn'.simps)\n                  apply(simp only: sched_assn'.simps)\n                  apply(erule disjE)\n                  subgoal premises pre'\n                    apply simp\n                    apply(rule disjI1)\n                    thm pre'\n                    apply(rule combine_blocks_assn)\n                       apply(rule pre'(1))\n                      apply(rule pre'(2))\n                     apply(rule pre(7))\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_wait_orig_waitin_assms'1)\n                      apply simp\n                    subgoal by auto\n                    apply (simp del: fun_upd_apply)\n                    apply(rule wait_orig_assn_tran)\n                    unfolding entails_tassn_def combine_assn_def\n                    apply auto\n                    subgoal for tr tr1 tr2\n                      apply(subgoal_tac \"sched_assn' (Suc(kk')) (Sch p rn rp) s tr2\")\n                      prefer 2\n                       apply simp\n                      using pre(1)[of k' \"(Suc(kk'))\" \"(dis_s(CHR ''t'' := 0))\" \"(Task READY 0 tp)\" \"(task_s(CHR ''t'' := 0))\" tr1 \"(Sch p rn rp)\" s tr2 tr]\n                      using pre unfolding propc_def by auto\n                    done\n                  apply(erule disjE)\n                  subgoal \n                    apply(cases rule: wait_orig_assn.cases[of \"(pd - dis_s CHR ''t'')\"\n                                                               \"(\\<lambda>t. ParState (EState (Task WAIT ent tp, task_s))\n                                                                     (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\"\n                                                               \"({}, {dispatch_ch 1})\"\n                                                               \"(task_dis_assn' 1 k' pd pc (dis_s(CHR ''t'' := 0)) (Task READY 0 tp)\n                                                                   (task_s(CHR ''t'' := 0)))\"\n                                                               tr1])\n                      apply simp\n                    subgoal\n                      using pre(7)\n                      apply simp\n                      apply(rule disjI1)\n                      apply(rule wait_orig_assn.intros(1))\n                      using pre(1)[of k' \"Suc kk'\" \"(dis_s(CHR ''t'' := 0))\" \"(Task READY 0 tp)\" \"(task_s(CHR ''t'' := 0))\" tr1 \"(Sch p rn rp)\" s tr2 tr]\n                      apply auto\n                      thm pre\n                      using pre(4,5,6,12)[unfolded pre(10,11)]\n                      unfolding propc_def\n                      by auto\n                    subgoal for tr1'\n                      apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\" \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\"\" (req_ch 2)\n                                                                           \"\"{1}\"  \"(\\<lambda>v d. if v \\<le> rp\n                                                                            then sched_assn' kk' (sched_push 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                                                  (s(CHR ''p'' := v))\n                                                                            else if rn \\<noteq> - 1\n                                                                                 then out_0assm_assn (preempt_ch rn) 0\n                                                                                       (out_0assm_assn (run_ch 2) 0\n                                                                                         (sched_assn' kk'\n                                                                                           (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                                                           (s(CHR ''p'' := v))))\n                                                                                 else out_0assm_assn (run_ch 2) 0\n                                                                                       (sched_assn' kk'\n                                                                                         (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                                                         (s(CHR ''p'' := v))))\" tr2])\n                       apply simp\n                       subgoal for v tr2'\n                          using pre(7)\n                          apply(simp del: tdsch1'.simps)\n                          apply(elim combine_blocks_unpairE3')\n                          subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                          subgoal for tr'\n                            apply simp\n                            apply(rule disjI2)\n                            apply(rule disjI1)\n                            apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                            subgoal by auto\n                            subgoal by auto\n                            apply(cases \"1\\<le>rp\")\n                            subgoal\n                              apply auto\n                              using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task WAIT ent tp)\" task_s tr1 \"(Sch (p @ [(1, 2)]) rn rp)\" \"(s(CHR ''p'' := 1))\" tr2' tr']\n                              using pre(4,5,6,12)[unfolded pre(10,11)] \n                              using properl_p1\n                              unfolding propc_def proper_def properp_def \n                              by auto\n                            apply(subgoal_tac \"rn \\<noteq> 1\")\n                               prefer 2\n                              subgoal\n                                using pre\n                                unfolding propc_def proper_def properp_def by auto\n                            apply(cases \"rn \\<noteq> - 1\")\n                            subgoal\n                              apply auto\n                              subgoal premises pre'\n                                thm pre'\n                                apply(rule combine_blocks_assn)\n                                apply(rule pre'(1))\n                                apply(rule pre'(8))\n                                 apply(rule pre'(10))\n                                apply(rule entails_tassn_trans)\n                                 apply(rule combine_wait_orig_out_0assm2)\n                                subgoal using pre' by auto\n                                subgoal using pre' using pre(6)[unfolded pre(10,11)] unfolding proper_def properp_def\n                                  by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply(rule out_0assm_assn_tran)\n                                apply(rule entails_tassn_trans)\n                                 apply(rule combine_wait_orig_out_0assm2)\n                                subgoal using pre' by auto\n                                subgoal using pre' by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply(rule out_0assm_assn_tran)\n                                unfolding entails_tassn_def combine_assn_def\n                                apply auto\n                                subgoal for tr tr1 tr2\n                                  using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task WAIT ent tp)\" task_s tr1 \"(Sch p 2 1)\" \"(s(CHR ''p'' := 1))\" tr2 tr]\n                                  using pre(4,5,6,12)[unfolded pre(10,11)] \n                                  using properl_p1\n                                  unfolding propc_def proper_def properp_def \n                                  by auto\n                                done\n                              done\n                            subgoal apply auto\n                              subgoal premises pre'\n                                thm pre'\n                                apply(rule combine_blocks_assn)\n                                apply(rule pre'(1))\n                                apply(rule pre'(8))\n                                 apply(rule pre'(10))\n                                apply(rule entails_tassn_trans)\n                                 apply(rule combine_wait_orig_out_0assm2)\n                                subgoal using pre' by auto\n                                subgoal using pre' using pre(6)[unfolded pre(10,11)] unfolding proper_def properp_def\n                                  by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply(rule out_0assm_assn_tran)\n                                unfolding entails_tassn_def combine_assn_def\n                                apply auto\n                                subgoal for tr tr1 tr2\n                                  using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task WAIT ent tp)\" task_s tr1 \"(Sch p 2 1)\" \"(s(CHR ''p'' := 1))\" tr2 tr]\n                                  using pre(4,5,6,12)[unfolded pre(10,11)] \n                                  using properl_p1\n                                  unfolding propc_def proper_def properp_def \n                                  by auto\n                                done\n                              done\n                            done\n                          done\n                        subgoal for v d tr2'\n                          using pre(7)\n                          apply(simp del: tdsch1'.simps)\n                          apply(cases \"(pd - dis_s CHR ''t'')<d\")\n                          subgoal\n                            apply(elim combine_blocks_waitE3)\n                            subgoal by auto\n                            subgoal by auto\n                            subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                            subgoal for tr'\n                              apply(simp del: tdsch1'.simps)\n                              apply simp\n                                apply(rule disjI1)\n                                  apply(subgoal_tac \"waitin_assms'_assn UNIV (\\<lambda>t. EState (Sch p rn rp, s))\n                                                       ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) (req_ch 2)\n                                                       {1}\n                                                       (\\<lambda>v d. if v \\<le> rp\n                                                              then sched_assn' kk' (sched_push 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                                    (s(CHR ''p'' := v))\n                                                              else if rn \\<noteq> - 1\n                                                                   then out_0assm_assn (preempt_ch rn) 0\n                                                                         (out_0assm_assn (run_ch 2) 0\n                                                                           (sched_assn' kk'\n                                                                             (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                                             (s(CHR ''p'' := v))))\n                                                                   else out_0assm_assn (run_ch 2) 0\n                                                                         (sched_assn' kk'\n                                                                           (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                                           (s(CHR ''p'' := v))))\n                                                                   (WaitBlk (d - (pd - dis_s CHR ''t'')) (\\<lambda>t. EState (Sch p rn rp, s))\n                                                                   ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) # InBlock (req_ch 2) 1 # tr2')\")\n                                     prefer 2\n                                  subgoal \n                                    apply(rule waitin_assms'_assn.intros(2))\n                                    subgoal by auto\n                                    subgoal by auto\n                                    subgoal by auto\n                                    subgoal by auto\n                                    done\n                                  apply(rule wait_orig_assn.intros(2))\n                                   prefer 2 subgoal by auto\n                                  using pre(1)[of k' \"(Suc kk')\" \"(dis_s(CHR ''t'' := 0))\" \"(Task READY 0 tp)\"\n                                               \"(task_s(CHR ''t'' := 0))\" tr1' \"(Sch p rn rp)\" s \"(WaitBlk (d - (pd - dis_s CHR ''t'')) (\\<lambda>t. EState (Sch p rn rp, s))\n                                                 ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) #\n                                                InBlock (req_ch 2) 1 # tr2')\" tr']\n                                  using pre(4,5,6,12)[unfolded pre(10,11)] \n                                  using properl_p1\n                                  unfolding propc_def proper_def properp_def \n                                  by auto\n                                done\n                          apply(cases \"d<(pd - dis_s CHR ''t'')\")\n                          subgoal\n                            apply(elim combine_blocks_waitE4)\n                            subgoal by auto\n                            subgoal by auto\n                            subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                            subgoal for tr'\n                              apply(elim combine_blocks_unpairE3')\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              subgoal for tr''\n                                apply simp\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by auto\n                                apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc (dis_s(CHR ''t'' := dis_s CHR ''t'' + d)) (Task WAIT ent tp)\n                                                   (task_s)\n                                                   (WaitBlk (pd - dis_s CHR ''t'' - d)\n                                                 (\\<lambda>t. ParState (EState (Task WAIT ent tp, task_s))\n                                                       (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d)))))\n                                                 ({}, {dispatch_ch 1}) #\n                                                tr1')\")\n                                 prefer 2\n                                subgoal premises pre'\n                                proof -\n                                  have a1: \"(pd - (dis_s CHR ''t'' + d)) = (pd - dis_s CHR ''t'' - d)\"\n                                    by auto\n                                  have a2: \"\\<And>t. dis_s CHR ''t'' + d + t = dis_s CHR ''t'' + (t + d)\"\n                                    by auto\n                                  show ?thesis\n                                    apply (subst a1[symmetric])\n                                    apply (subst a2[symmetric])\n                                    apply simp\n                                    apply (rule wait_orig_assn.intros(2))\n                                    using pre' by auto\n                                  qed\n                                apply(cases \"1\\<le>rp\")\n                                subgoal\n                                  apply auto\n                                  using pre(1)[of \"(Suc k')\" kk' \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + d))\" \"(Task WAIT ent tp)\"\n                                                  \"(task_s)\" \n                                                  \"(WaitBlk (pd - dis_s CHR ''t'' - d)\n                                                   (\\<lambda>t. ParState (EState (Task WAIT ent tp, task_s))\n                                                         (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d)))))\n                                                   ({}, {dispatch_ch 1}) #\n                                                  tr1')\" \"(Sch (p @ [(1, 2)]) rn rp)\"\n                                                  \"(s(CHR ''p'' := 1))\" tr2' tr'']\n                                  using pre(4,5,6,12)[unfolded pre(10,11)] \n                                  using properl_p1\n                                  unfolding propc_def proper_def properp_def \n                                  by auto\n                                apply simp\n                                apply(cases \"rn \\<noteq> - 1\")\n                                subgoal\n                                  apply auto\n                                  subgoal premises pre'\n                                    thm pre'(13)\n                                    apply(rule combine_blocks_assn)\n                                       apply(rule pre'(13))\n                                      apply(rule pre'(8))\n                                     apply(rule pre'(12))\n                                    apply(rule entails_tassn_trans)\n                                     apply(rule combine_wait_orig_out_0assm2)\n                                    subgoal using pre' by auto\n                                    subgoal using pre pre'\n                                      unfolding proper_def properp_def\n                                      by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                    apply(rule out_0assm_assn_tran)\n                                    apply(rule entails_tassn_trans)\n                                     apply(rule combine_wait_orig_out_0assm2)\n                                    subgoal using pre' by auto\n                                    subgoal using pre pre'\n                                      unfolding proper_def properp_def\n                                      by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                    apply(rule out_0assm_assn_tran)\n                                    unfolding combine_assn_def entails_tassn_def\n                                    apply auto\n                                    subgoal for tr tr1 tr2\n                                      using pre(1)[of \"(Suc k')\" kk' \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + d))\" \"(Task WAIT ent tp)\"\n                                          task_s tr1 \"(Sch p 2 1)\" \"(s(CHR ''p'' := 1))\" tr2 tr]\n                                      using pre(4,5,6,12)[unfolded pre(10,11)] \n                                      using properl_p1\n                                      unfolding propc_def proper_def properp_def \n                                      by auto\n                                    done\n                                  done\n                                apply auto\n                                subgoal premises pre'\n                                    thm pre'(13)\n                                    apply(rule combine_blocks_assn)\n                                       apply(rule pre'(13))\n                                      apply(rule pre'(8))\n                                     apply(rule pre'(12))\n                                    apply(rule entails_tassn_trans)\n                                     apply(rule combine_wait_orig_out_0assm2)\n                                    subgoal using pre' by auto\n                                    subgoal using pre pre'\n                                      unfolding proper_def properp_def\n                                      by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                    apply(rule out_0assm_assn_tran)\n                                    unfolding combine_assn_def entails_tassn_def\n                                    apply auto\n                                    subgoal for tr tr1 tr2\n                                      using pre(1)[of \"(Suc k')\" kk' \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + d))\" \"(Task WAIT ent tp)\"\n                                          task_s tr1 \"(Sch p 2 1)\" \"(s(CHR ''p'' := 1))\" tr2 tr]\n                                      using pre(4,5,6,12)[unfolded pre(10,11)] \n                                      using properl_p1\n                                      unfolding propc_def proper_def properp_def \n                                      by auto\n                                    done\n                                  done\n                                done\n                              done\n                            apply(simp del:tdsch1'.simps)\n                            apply(elim combine_blocks_waitE2)\n                            subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                            subgoal for tr'\n                              apply simp\n                              apply(rule disjI1)\n                              apply(rule wait_orig_assn.intros(2))\n                               apply auto\n                              apply(rule pre(1)[of k' \"(Suc kk')\" \"(dis_s(CHR ''t'' := 0))\" \"(Task READY 0 tp)\"\n                                  \"(task_s(CHR ''t'' := 0))\" tr1' \"(Sch p rn rp)\" s \"(InBlock (req_ch 2) 1 # tr2')\" tr'])\n                              subgoal by auto\n                              subgoal by auto\n                              subgoal apply(simp only: sched_assn'.simps)\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(rule waitin_assms'_assn.intros(1))\n                                by auto\n                              subgoal using pre by auto\n                              subgoal using pre unfolding propc_def\n                                by auto\n                              subgoal using pre unfolding proper_def properp_def by auto\n                              subgoal by auto\n                              done\n                            done\n                          subgoal for v tr2'\n                            using pre(7)\n                            apply(simp del: tdsch1'.simps)\n                            apply(elim combine_blocks_unpairE3')\n                            subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                            subgoal for tr'\n                              apply simp\n                              apply(rule disjI2)\n                              apply(rule disjI1)\n                            apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                            by auto\n                          done\n                          subgoal for d v tr2'\n                          using pre(7)\n                          apply(simp del: tdsch1'.simps)\n                          apply(cases \"(pd - dis_s CHR ''t'')<d\")\n                          subgoal\n                            apply(elim combine_blocks_waitE3)\n                            subgoal by auto\n                            subgoal by auto\n                            subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                            subgoal for tr'\n                              apply(simp del: tdsch1'.simps)\n                              apply simp\n                                apply(rule disjI1)\n                                  apply(subgoal_tac \"waitin_assms'_assn UNIV (\\<lambda>t. EState (Sch p rn rp, s))\n                                                       ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) (req_ch 2)\n                                                       {1}\n                                                       (\\<lambda>v d. if v \\<le> rp\n                                                              then sched_assn' kk' (sched_push 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                                    (s(CHR ''p'' := v))\n                                                              else if rn \\<noteq> - 1\n                                                                   then out_0assm_assn (preempt_ch rn) 0\n                                                                         (out_0assm_assn (run_ch 2) 0\n                                                                           (sched_assn' kk'\n                                                                             (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                                             (s(CHR ''p'' := v))))\n                                                                   else out_0assm_assn (run_ch 2) 0\n                                                                         (sched_assn' kk'\n                                                                           (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                                           (s(CHR ''p'' := v))))\n                                                                   (WaitBlk (d - (pd - dis_s CHR ''t'')) (\\<lambda>t. EState (Sch p rn rp, s))\n                                                                   ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) # InBlock (req_ch 2) v # tr2')\")\n                                     prefer 2\n                                  subgoal \n                                    apply(rule waitin_assms'_assn.intros(4))\n                                    by auto\n                                  apply(rule wait_orig_assn.intros(2))\n                                   prefer 2 subgoal by auto\n                                  using pre(1)[of k' \"(Suc kk')\" \"(dis_s(CHR ''t'' := 0))\" \"(Task READY 0 tp)\"\n                                               \"(task_s(CHR ''t'' := 0))\" tr1' \"(Sch p rn rp)\" s \"(WaitBlk (d - (pd - dis_s CHR ''t'')) (\\<lambda>t. EState (Sch p rn rp, s))\n                                                 ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) #\n                                                InBlock (req_ch 2) v # tr2')\" tr']\n                                  using pre(4,5,6,12)[unfolded pre(10,11)] \n                                  using properl_p1\n                                  unfolding propc_def proper_def properp_def \n                                  by auto\n                                done\n                          apply(cases \"d<(pd - dis_s CHR ''t'')\")\n                          subgoal\n                            apply(elim combine_blocks_waitE4)\n                            subgoal by auto\n                            subgoal by auto\n                            subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                            subgoal for tr'\n                              apply(elim combine_blocks_unpairE3')\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              subgoal for tr''\n                                apply simp\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                                by auto\n                              done\n                            done\n                            apply(simp del:tdsch1'.simps)\n                            apply(elim combine_blocks_waitE2)\n                            subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                            subgoal for tr'\n                              apply simp\n                              apply(rule disjI1)\n                              apply(rule wait_orig_assn.intros(2))\n                               apply auto\n                              apply(rule pre(1)[of k' \"(Suc kk')\" \"(dis_s(CHR ''t'' := 0))\" \"(Task READY 0 tp)\"\n                                  \"(task_s(CHR ''t'' := 0))\" tr1' \"(Sch p rn rp)\" s \"(InBlock (req_ch 2) v # tr2')\" tr'])\n                              subgoal by auto\n                              subgoal by auto\n                              subgoal apply(simp only: sched_assn'.simps)\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(rule waitin_assms'_assn.intros(3))\n                                by auto\n                              subgoal using pre by auto\n                              subgoal using pre unfolding propc_def\n                                by auto\n                              subgoal using pre unfolding proper_def properp_def by auto\n                              subgoal by auto\n                              done\n                            done\n                          done\n                        done\n                      apply(erule disjE)\n                  subgoal premises pre'\n                    apply simp\n                    apply(rule disjI1)\n                    thm pre'\n                    apply(rule combine_blocks_assn)\n                       apply(rule pre'(1))\n                      apply(rule pre'(2))\n                     apply(rule pre(7))\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_wait_orig_waitin_assms'1)\n                    subgoal by auto\n                    subgoal by auto\n                    apply (simp only: merge_rdy.simps)\n                    subgoal\n                      proof-\n                        have a:\"({} \\<union> {},{dispatch_ch 1} \\<union>\n                                {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) = ({},\n                                {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2, dispatch_ch 1})\"\n                          by auto\n                        have b:\"(pd - dis_s CHR ''t'') = (pd - dis_s CHR ''t'')\" by auto\n                        show ?thesis\n                          apply(subst a)\n                          apply(subst b)\n                          apply(rule wait_orig_assn_tran)\n                          unfolding entails_tassn_def combine_assn_def\n                          apply clarify\n                          subgoal for tr tr1 tr2\n                            apply(subgoal_tac \"sched_assn' (Suc(kk')) (Sch p rn rp) s tr2\")\n                             prefer 2\n                             apply simp\n                            using pre(1)[of k' \"(Suc(kk'))\" \"(dis_s(CHR ''t'' := 0))\" \"(Task READY 0 tp)\" \"(task_s(CHR ''t'' := 0))\" tr1 \"(Sch p rn rp)\" s tr2 tr]\n                            using pre unfolding propc_def by auto\n                          done\n                      qed\n                      done\n                    apply(erule disjE)\n                    subgoal\n                      apply(cases rule: wait_orig_assn.cases[of \"(pd - dis_s CHR ''t'')\"\n                                       \"(\\<lambda>t. ParState (EState (Task WAIT ent tp, task_s))\n                                             (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\"\n                                       \"({}, {dispatch_ch 1})\"\n                                       \"(task_dis_assn' 1 k' pd pc (dis_s(CHR ''t'' := 0)) (Task READY 0 tp)\n                                         (task_s(CHR ''t'' := 0)))\"\n                                       tr1])\n                        apply simp\n                      subgoal\n                        apply simp\n                        apply(rule disjI1)\n                        apply(rule wait_orig_assn.intros(1))\n                         apply auto\n                        using pre(1)[of k' \"(Suc kk')\" \"(dis_s(CHR ''t'' := 0))\" \"(Task READY 0 tp)\"\n                                      \"(task_s(CHR ''t'' := 0))\" tr1 \"(Sch p rn rp)\" s tr2 tr]\n                        using pre unfolding propc_def by auto\n                      subgoal for tr1'\n                        apply(cases rule:waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                             \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(free_ch 2)\"\n                                             \"{0}\"\n                                             \"(\\<lambda>v d. if 0 < length p\n                                                    then out_0assm_assn (run_ch (run_now (sched_get_max (Sch p rn rp) s))) 0\n                                                          (sched_assn' kk' (sched_get_max (Sch p rn rp) s) s)\n                                                    else sched_assn' kk' (sched_clear (Sch p rn rp) s) s)\" tr2])\n                            apply simp\n                        subgoal for v tr2'\n                          using pre(7)\n                          apply simp\n                          apply(rule disjI2)\n                          apply(rule disjI2)\n                          apply(rule disjI1)\n                          apply(elim combine_blocks_unpairE3')\n                          subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                          apply simp\n                          apply (rule waitin_tguar'_vassm'_assn.intros(1))\n                          subgoal by auto\n                          subgoal by auto\n                          subgoal for tr'\n                            apply(cases \"p \\<noteq> []\")\n                            subgoal\n                              apply simp\n                              subgoal premises pre'\n                                thm pre'\n                                apply(rule combine_blocks_assn)\n                                   apply(rule pre'(1))\n                                  apply(rule pre'(8))\n                                 apply(rule pre'(10))\n                                apply(rule entails_tassn_trans)\n                                 apply(rule combine_wait_orig_out_0assm2)\n                                subgoal using pre' by auto\n                                subgoal using properl_p5[of p]\n                                  using pre'(11)\n                                  using pre(6) pre(10)\n                                  unfolding proper_def properp_def\n                                  apply(cases \"get_max p\")\n                                  apply simp\n                                  by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply(rule out_0assm_assn_tran)\n                                unfolding entails_tassn_def combine_assn_def\n                                apply auto\n                                subgoal for tr tr1 tr2\n                                  apply(rule pre(1)[of \"(Suc k')\" kk' dis_s \"(Task WAIT ent tp)\" task_s tr1 \"(case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior)\" s tr2 tr])\n                                  subgoal by auto\n                                  subgoal by auto\n                                  subgoal using pre by auto\n                                  subgoal using pre by auto\n                                  subgoal using pre pre' properl_p5[of p] unfolding propc_def proper_def\n                                    apply(cases \"get_max p\") by auto\n                                  subgoal using pre pre' properl_p5[of p] properl_p4 unfolding propc_def proper_def\n                                    apply(cases \"get_max p\") by auto\n                                  subgoal by auto\n                                  done\n                                done\n                              done\n                            subgoal\n                              apply simp\n                              subgoal \n                                apply(rule pre(1)[of \"(Suc k')\" kk' dis_s \"(Task WAIT ent tp)\" task_s tr1 \"(Sch [] (- 1) (- 1))\" s tr2' tr'])\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal using pre by auto\n                                subgoal using pre unfolding propc_def by auto\n                                subgoal using pre unfolding proper_def properp_def by auto\n                                subgoal by auto\n                                done\n                              done\n                            done\n                          done\n                        subgoal for v d tr2'\n                          using pre(7)\n                          apply(simp del: tdsch1'.simps)\n                          apply(cases \"(pd - dis_s CHR ''t'')<d\")\n                          subgoal\n                            apply(elim combine_blocks_waitE3)\n                            subgoal by auto\n                            subgoal by auto\n                            subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                            subgoal for tr'\n                              apply simp\n                              apply(rule disjI1)\n                              apply(rule wait_orig_assn.intros(2))\n                               apply auto\n                              apply(rule pre(1)[of k' \"(Suc kk')\" \"(dis_s(CHR ''t'' := 0))\" \"(Task READY 0 tp)\"\n                                         \"(task_s(CHR ''t'' := 0))\" tr1' \"(Sch p rn rp)\" s \"(WaitBlk (d - (pd - dis_s CHR ''t'')) (\\<lambda>t. EState (Sch p rn rp, s))\n                                           ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) #\n                                          InBlock (free_ch 2) 0 # tr2')\" tr'])\n                              subgoal by auto\n                              subgoal by auto\n                              subgoal \n                                apply (simp only: sched_assn'.simps)\n                                apply(rule disjI2)\n                                apply(rule disjI2)\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(rule waitin_assms'_assn.intros(2))\n                                by auto\n                              subgoal using pre by auto\n                              subgoal using pre unfolding propc_def by auto\n                              subgoal using pre unfolding proper_def by auto\n                              subgoal by auto\n                              done\n                            done\n                          apply(cases \"(pd - dis_s CHR ''t'')>d\")\n                          subgoal\n                            apply(elim combine_blocks_waitE4)\n                            subgoal by auto\n                            subgoal by auto\n                            subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                            apply simp\n                            apply(rule disjI2)\n                            apply(rule disjI2)\n                            apply(rule disjI1)\n                            apply(elim combine_blocks_unpairE3')\n                            subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                            apply auto\n                            subgoal for tr'\n                              apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                              subgoal by auto\n                              subgoal by auto\n                              subgoal by auto\n                              apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc (dis_s(CHR ''t'' := dis_s CHR ''t'' + d))\n                                           (Task WAIT ent tp) task_s (WaitBlk (pd - dis_s CHR ''t'' - d)\n                                               (\\<lambda>t. ParState (EState (Task WAIT ent tp, task_s))\n                                                     (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d)))))\n                                               ({}, {dispatch_ch 1}) #\n                                              tr1')\")\n                               prefer 2\n                              subgoal premises pre'\n                                proof-\n                                have a1:\"(pd - (dis_s CHR ''t'' + d)) = (pd - dis_s CHR ''t'' - d)\"\n                                  by auto\n                                have a2:\"(\\<lambda>t. ParState (EState (Task WAIT ent tp, task_s))\n             (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + d + t)))) = \n                                         (\\<lambda>t. ParState (EState (Task WAIT ent tp, task_s))\n             (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d)))))\"\n                                  apply(rule ext)\n                                  by auto\n                                show ?thesis apply simp\n                                  apply(subst a1)\n                                  apply(subst a2)\n                                  apply(rule wait_orig_assn.intros(2))\n                                  using pre' by auto\n                              qed\n                              apply(cases \"p \\<noteq> []\")\n                              subgoal\n                                apply simp\n                                subgoal premises pre'\n                                  thm pre'\n                                  apply(rule combine_blocks_assn)\n                                     apply(rule pre'(12))\n                                  apply(rule pre'(8))\n                                 apply(rule pre'(11))\n                                apply(rule entails_tassn_trans)\n                                 apply(rule combine_wait_orig_out_0assm2)\n                                subgoal using pre' by auto\n                                subgoal using properl_p5[of p]\n                                  using pre'(13)\n                                  using pre(6) pre(10)\n                                  unfolding proper_def properp_def\n                                  apply(cases \"get_max p\")\n                                  apply simp\n                                  by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply(rule out_0assm_assn_tran)\n                                unfolding entails_tassn_def combine_assn_def\n                                apply auto\n                                subgoal for tr tr1 tr2\n                                  apply(rule pre(1)[of \"(Suc k')\" kk' \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + d))\" \"(Task WAIT ent tp)\" task_s tr1 \"(case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior)\" s tr2 tr])\n                                  subgoal by auto\n                                  subgoal by auto\n                                  subgoal using pre by auto\n                                  subgoal using pre by auto\n                                  subgoal using pre pre' properl_p5[of p] unfolding propc_def proper_def\n                                    apply(cases \"get_max p\") by auto\n                                  subgoal using pre pre' properl_p5[of p] properl_p4 unfolding propc_def proper_def\n                                    apply(cases \"get_max p\") by auto\n                                  subgoal by auto                    \n                                  done\n                                done\n                              done\n                            subgoal\n                              apply simp\n                              subgoal \n                                apply(rule pre(1)[of \"(Suc k')\" kk' \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + d))\" \"(Task WAIT ent tp)\" task_s \"(WaitBlk (pd - dis_s CHR ''t'' - d)\n                                                           (\\<lambda>t. ParState (EState (Task WAIT ent tp, task_s))\n                                                                 (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d)))))\n                                                           ({}, {dispatch_ch 1}) #\n                                                          tr1')\" \"(Sch [] (- 1) (- 1))\" s tr2' tr'])\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal using pre by auto\n                                subgoal using pre unfolding propc_def by auto\n                                subgoal using pre unfolding proper_def properp_def by auto\n                                subgoal by auto\n                                done\n                              done\n                            done\n                          done\n                        apply simp\n                        apply(rule disjI1)\n                        apply(elim combine_blocks_waitE2)\n                         apply auto\n                        apply(rule wait_orig_assn.intros(2))\n                         apply auto\n                        subgoal for tr'\n                          apply(rule pre(1)[of k' \"(Suc kk')\" \"(dis_s(CHR ''t'' := 0))\" \"(Task READY 0 tp)\"\n                                \"(task_s(CHR ''t'' := 0))\" tr1' \"(Sch p rn rp)\" s \"(InBlock (free_ch 2) 0 # tr2')\" tr'])\n                          subgoal by auto\n                          subgoal by auto\n                          subgoal \n                            apply(simp only:sched_assn'.simps)\n                            apply(rule disjI2)\n                            apply(rule disjI2)\n                            apply(rule disjI2)\n                            apply(rule disjI1)\n                            apply(rule waitin_assms'_assn.intros(1))\n                            by auto\n                          subgoal using pre by auto\n                          subgoal using pre unfolding propc_def by auto\n                          subgoal using pre unfolding proper_def by auto\n                          subgoal by auto\n                          done\n                        done\n                      subgoal for v tr2'\n                          using pre(7)\n                          apply simp\n                          apply(rule disjI2)\n                          apply(rule disjI2)\n                          apply(rule disjI1)\n                          apply(elim combine_blocks_unpairE3')\n                          subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                          apply simp\n                          apply (rule waitin_tguar'_vassm'_assn.intros(3))\n                          subgoal by auto\n                          subgoal by auto\n                          done\n                      subgoal for d v tr2'\n                          using pre(7)\n                          apply(simp del: tdsch1'.simps)\n                          apply(cases \"(pd - dis_s CHR ''t'')<d\")\n                          subgoal\n                            apply(elim combine_blocks_waitE3)\n                            subgoal by auto\n                            subgoal by auto\n                            subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                            subgoal for tr'\n                              apply simp\n                              apply(rule disjI1)\n                              apply(rule wait_orig_assn.intros(2))\n                               apply auto\n                              apply(rule pre(1)[of k' \"(Suc kk')\" \"(dis_s(CHR ''t'' := 0))\" \"(Task READY 0 tp)\"\n                                         \"(task_s(CHR ''t'' := 0))\" tr1' \"(Sch p rn rp)\" s \"(WaitBlk (d - (pd - dis_s CHR ''t'')) (\\<lambda>t. EState (Sch p rn rp, s))\n                                           ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) #\n                                          InBlock (free_ch 2) v # tr2')\" tr'])\n                              subgoal by auto\n                              subgoal by auto\n                              subgoal \n                                apply (simp only: sched_assn'.simps)\n                                apply(rule disjI2)\n                                apply(rule disjI2)\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(rule waitin_assms'_assn.intros(4))\n                                by auto\n                              subgoal using pre by auto\n                              subgoal using pre unfolding propc_def by auto\n                              subgoal using pre unfolding proper_def by auto\n                              subgoal by auto\n                              done\n                            done\n                          apply(cases \"(pd - dis_s CHR ''t'')>d\")\n                          subgoal\n                            apply(elim combine_blocks_waitE4)\n                            subgoal by auto\n                            subgoal by auto\n                            subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                            apply simp\n                            apply(rule disjI2)\n                            apply(rule disjI2)\n                            apply(rule disjI1)\n                            apply(elim combine_blocks_unpairE3')\n                            subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                            apply auto\n                            subgoal for tr'\n                              apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                              subgoal by auto\n                              subgoal by auto\n                              subgoal by auto\n                              done\n                            done\n                           apply simp\n                        apply(rule disjI1)\n                        apply(elim combine_blocks_waitE2)\n                         apply auto\n                        apply(rule wait_orig_assn.intros(2))\n                         apply auto\n                        subgoal for tr'\n                          apply(rule pre(1)[of k' \"(Suc kk')\" \"(dis_s(CHR ''t'' := 0))\" \"(Task READY 0 tp)\"\n                                \"(task_s(CHR ''t'' := 0))\" tr1' \"(Sch p rn rp)\" s \"(InBlock (free_ch 2) v # tr2')\" tr'])\n                          subgoal by auto\n                          subgoal by auto\n                          subgoal \n                            apply(simp only:sched_assn'.simps)\n                            apply(rule disjI2)\n                            apply(rule disjI2)\n                            apply(rule disjI2)\n                            apply(rule disjI1)\n                            apply(rule waitin_assms'_assn.intros(3))\n                            by auto\n                          subgoal using pre by auto\n                          subgoal using pre unfolding propc_def by auto\n                          subgoal using pre unfolding proper_def by auto\n                          subgoal by auto\n                          done\n                        done\n                      done\n                    done\n                  apply(erule disjE)\n                  subgoal premises pre'\n                    apply simp\n                    apply(rule disjI1)\n                    thm pre'\n                    apply(rule combine_blocks_assn)\n                       apply(rule pre'(1))\n                      apply(rule pre'(2))\n                     apply(rule pre(7))\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_wait_orig_waitin_assms'1)\n                    subgoal by auto\n                    subgoal by auto\n                    apply (simp only: merge_rdy.simps)\n                    subgoal\n                      proof-\n                        have a:\"({} \\<union> {},{dispatch_ch 1} \\<union>\n                                {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) = ({},\n                                {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2, dispatch_ch 1})\"\n                          by auto\n                        have b:\"(pd - dis_s CHR ''t'') = (pd - dis_s CHR ''t'')\" by auto\n                        show ?thesis\n                          apply(subst a)\n                          apply(subst b)\n                          apply(rule wait_orig_assn_tran)\n                          unfolding entails_tassn_def combine_assn_def\n                          apply clarify\n                          subgoal for tr tr1 tr2\n                            apply(subgoal_tac \"sched_assn' (Suc(kk')) (Sch p rn rp) s tr2\")\n                             prefer 2\n                             apply simp\n                            using pre(1)[of k' \"(Suc(kk'))\" \"(dis_s(CHR ''t'' := 0))\" \"(Task READY 0 tp)\" \"(task_s(CHR ''t'' := 0))\" tr1 \"(Sch p rn rp)\" s tr2 tr]\n                            using pre unfolding propc_def by auto\n                          done\n                      qed\n                      done\n                    subgoal\n                      apply(cases rule: wait_orig_assn.cases[of \"(pd - dis_s CHR ''t'')\"\n                                       \"(\\<lambda>t. ParState (EState (Task WAIT ent tp, task_s))\n                                             (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\"\n                                       \"({}, {dispatch_ch 1})\"\n                                       \"(task_dis_assn' 1 k' pd pc (dis_s(CHR ''t'' := 0)) (Task READY 0 tp)\n                                         (task_s(CHR ''t'' := 0)))\"\n                                       tr1])\n                        apply simp\n                      subgoal\n                        apply simp\n                        apply(rule disjI1)\n                        apply(rule wait_orig_assn.intros(1))\n                         apply auto\n                        using pre(1)[of k' \"(Suc kk')\" \"(dis_s(CHR ''t'' := 0))\" \"(Task READY 0 tp)\"\n                                      \"(task_s(CHR ''t'' := 0))\" tr1 \"(Sch p rn rp)\" s tr2 tr]\n                        using pre unfolding propc_def by auto\n                      subgoal for tr1'\n                        apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                             \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(exit_ch 2)\"\n                                             \"{0}\" \"(\\<lambda>v d. sched_assn' kk' (sched_del_proc 2 (Sch p rn rp) s) s)\" tr2])\n                            apply simp\n                        subgoal for v tr2'\n                          using pre(7)\n                          apply simp\n                          apply(rule disjI2)\n                          apply(rule disjI2)\n                          apply(rule disjI2)\n                          apply(elim combine_blocks_unpairE3')\n                          subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                          apply simp\n                          apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                            apply auto\n                          subgoal for tr'\n                            apply(rule pre(1)[of \"(Suc k')\" kk' dis_s \"(Task WAIT ent tp)\" task_s tr1 \"(Sch (del_proc p 2) rn rp)\" s tr2' tr'])\n                            subgoal by auto\n                            subgoal by auto\n                            subgoal by auto\n                            subgoal using pre by auto\n                            subgoal using pre unfolding propc_def by auto\n                            subgoal using pre properl_p4 unfolding proper_def properp_def by auto\n                            subgoal by auto\n                            done\n                          done\n                        subgoal for v d tr2'\n                          using pre(7)\n                          apply (simp del: tdsch1'.simps)\n                          apply(cases \"(pd - dis_s CHR ''t'')<d\")\n                          subgoal\n                            apply(elim combine_blocks_waitE3)\n                            subgoal by auto\n                            subgoal by auto\n                            subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                            apply simp\n                            apply(rule disjI1)\n                            subgoal for tr'\n                              apply(rule wait_orig_assn.intros(2))\n                               apply auto\n                              apply(rule pre(1)[of k' \"(Suc kk')\" \"(dis_s(CHR ''t'' := 0))\" \"(Task READY 0 tp)\"\n                                   \"(task_s(CHR ''t'' := 0))\" tr1'  \"(Sch p rn rp)\" s \"(WaitBlk (d - (pd - dis_s CHR ''t'')) (\\<lambda>t. EState (Sch p rn rp, s))\n                                     ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) #\n                                    InBlock (exit_ch 2) 0 # tr2')\" tr'])\n                              subgoal by auto\n                              subgoal by auto\n                              subgoal \n                                apply (simp only: sched_assn'.simps) \n                                apply(rule disjI2)+\n                                apply(rule waitin_assms'_assn.intros(2))\n                                by auto\n                              subgoal using pre by auto\n                              subgoal using pre unfolding propc_def by auto\n                              subgoal using pre properl_p4 unfolding proper_def properp_def by auto\n                              subgoal by auto\n                              done\n                            done\n                          apply(cases \"(pd - dis_s CHR ''t'')>d\")\n                          subgoal\n                            apply(elim combine_blocks_waitE4)\n                            subgoal by auto\n                            subgoal by auto\n                            subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                            apply simp\n                            apply(rule disjI2)+\n                            apply(elim combine_blocks_unpairE3')\n                            subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                            apply auto\n                            subgoal for tr'\n                              apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                                 apply auto\n                              apply(rule pre(1)[of \"(Suc k')\" kk' \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + d))\" \"(Task WAIT ent tp)\"\n                                                   task_s \"(WaitBlk (pd - dis_s CHR ''t'' - d)\n                                                     (\\<lambda>t. ParState (EState (Task WAIT ent tp, task_s))\n                                                           (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d)))))\n                                                     ({}, {dispatch_ch 1}) #\n                                                    tr1')\" \"(Sch (del_proc p 2) rn rp)\" s tr2' tr'])\n                              subgoal by auto\n                              subgoal premises pre'\n                                proof-\n                                have a1:\"(pd - (dis_s CHR ''t'' + d)) = (pd - dis_s CHR ''t'' - d)\"\n                                  by auto\n                                have a2:\"(\\<lambda>t. ParState (EState (Task WAIT ent tp, task_s))\n           (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + d + t)))) = \n                                         (\\<lambda>t. ParState (EState (Task WAIT ent tp, task_s))\n             (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d)))))\"\n                                  apply(rule ext)\n                                  by auto\n                                show ?thesis\n                                  apply simp\n                                  apply(subst a1)\n                                  apply(subst a2)\n                                  apply(rule wait_orig_assn.intros(2))\n                                  using pre' by auto\n                              qed\n                              subgoal by auto\n                              subgoal using pre by auto\n                              subgoal using pre unfolding propc_def by auto\n                              subgoal using pre properl_p4 unfolding proper_def properp_def by auto\n                              subgoal by auto\n                              done\n                            done\n                          apply simp\n                          apply(rule disjI1)\n                          apply(elim combine_blocks_waitE2)\n                          subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                          apply auto\n                          apply(rule wait_orig_assn.intros(2))\n                           apply auto\n                          subgoal for tr'\n                          apply(rule pre(1)[of k' \"(Suc kk')\" \"(dis_s(CHR ''t'' := 0))\" \"(Task READY 0 tp)\"\n                                  \"(task_s(CHR ''t'' := 0))\" tr1' \"(Sch p rn rp)\" s \"(InBlock (exit_ch 2) 0 # tr2')\" tr'])\n                            subgoal by auto\n                            subgoal by auto\n                            subgoal \n                              apply(simp only: sched_assn'.simps)\n                              apply(rule disjI2)+\n                              apply(rule waitin_assms'_assn.intros(1))\n                              by auto\n                            subgoal using pre by auto\n                            subgoal using pre unfolding propc_def by auto\n                            subgoal using pre properl_p4 unfolding proper_def properp_def by auto\n                            subgoal by auto\n                            done\n                          done\n                        subgoal for v tr2'\n                          using pre(7)\n                          apply simp\n                          apply(rule disjI2)\n                          apply(rule disjI2)\n                          apply(rule disjI2)\n                          apply(elim combine_blocks_unpairE3')\n                          subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                          apply simp\n                          apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                            by auto\n                        subgoal for d v tr2'\n                          using pre(7)\n                          apply (simp del: tdsch1'.simps)\n                          apply(cases \"(pd - dis_s CHR ''t'')<d\")\n                          subgoal\n                            apply(elim combine_blocks_waitE3)\n                            subgoal by auto\n                            subgoal by auto\n                            subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                            apply simp\n                            apply(rule disjI1)\n                            subgoal for tr'\n                              apply(rule wait_orig_assn.intros(2))\n                               apply auto\n                              apply(rule pre(1)[of k' \"(Suc kk')\" \"(dis_s(CHR ''t'' := 0))\" \"(Task READY 0 tp)\"\n                                   \"(task_s(CHR ''t'' := 0))\" tr1'  \"(Sch p rn rp)\" s \"(WaitBlk (d - (pd - dis_s CHR ''t'')) (\\<lambda>t. EState (Sch p rn rp, s))\n                                     ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) #\n                                    InBlock (exit_ch 2) v # tr2')\" tr'])\n                              subgoal by auto\n                              subgoal by auto\n                              subgoal \n                                apply (simp only: sched_assn'.simps) \n                                apply(rule disjI2)+\n                                apply(rule waitin_assms'_assn.intros(4))\n                                by auto\n                              subgoal using pre by auto\n                              subgoal using pre unfolding propc_def by auto\n                              subgoal using pre properl_p4 unfolding proper_def properp_def by auto\n                              subgoal by auto\n                              done\n                            done\n                          apply(cases \"(pd - dis_s CHR ''t'')>d\")\n                          subgoal\n                            apply(elim combine_blocks_waitE4)\n                            subgoal by auto\n                            subgoal by auto\n                            subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                            apply simp\n                            apply(rule disjI2)+\n                            apply(elim combine_blocks_unpairE3')\n                            subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                            apply auto\n                            subgoal for tr'\n                              apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                                 by auto\n                               done\n                          apply simp\n                          apply(rule disjI1)\n                          apply(elim combine_blocks_waitE2)\n                          subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                          apply auto\n                          apply(rule wait_orig_assn.intros(2))\n                           apply auto\n                          subgoal for tr'\n                          apply(rule pre(1)[of k' \"(Suc kk')\" \"(dis_s(CHR ''t'' := 0))\" \"(Task READY 0 tp)\"\n                                  \"(task_s(CHR ''t'' := 0))\" tr1' \"(Sch p rn rp)\" s \"(InBlock (exit_ch 2) v # tr2')\" tr'])\n                            subgoal by auto\n                            subgoal by auto\n                            subgoal \n                              apply(simp only: sched_assn'.simps)\n                              apply(rule disjI2)+\n                              apply(rule waitin_assms'_assn.intros(3))\n                              by auto\n                            subgoal using pre by auto\n                            subgoal using pre unfolding propc_def by auto\n                            subgoal using pre properl_p4 unfolding proper_def properp_def by auto\n                            subgoal by auto\n                            done\n                          done\n                        done\n                      done\n                    done\n                      (* part 2*)\n                  subgoal premises pre\n                      thm pre\n                   using pre(2) pre(3) pre(4) pre(7)\n                   apply(simp add: pre(10,11,12,4) del:tdsch1'.simps sched_assn'.simps)\n                   apply(erule disjE)\n                   subgoal\n                     apply(simp del:tdsch1'.simps)\n                     apply(erule disjE)\n                     subgoal premises pre'\n                       thm pre'\n                       apply (simp only:tdsch1'.simps)\n                       apply(rule disjI1)\n                       apply(rule combine_blocks_assn)\n                          apply(rule pre'(3))\n                         apply(rule pre'(4))\n                        apply(rule pre'(2))\n                       apply(rule entails_tassn_trans)\n                        apply(rule combine_out_0assm_waitin_assm'1)\n                       subgoal by auto\n                       subgoal by auto\n                       subgoal by auto\n                       apply(subgoal_tac \"rp<2 \\<and> rn\\<noteq>1\")\n                        prefer 2\n                       subgoal using pre(4,5,6,8,9,10,11,12)\n                         unfolding proper_def properp_def propc_def\n                         by auto\n                       apply (simp del: fun_upd_apply)\n                       apply(cases \"rn \\<noteq> -1\")\n                       subgoal\n                         apply (simp del: fun_upd_apply)\n                         apply(rule entails_tassn_trans)\n                          apply(rule combine_waitin_tguar'_vassm'_out_0assm2)\n                         subgoal using pre \n                           unfolding proper_def properp_def propc_def\n                           by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(rule out_0assm_assn_tran)\n                         apply(rule entails_tassn_trans)\n                          apply(rule combine_waitin_tguar'_vassm'_out_0assm1)\n                         subgoal by auto\n                         apply (simp del: fun_upd_apply)\n                         unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                         using pre(1)[of k' kk' dis_s \"(Task RUNNING (Suc 0) 2)\" \"(task_s(CHR ''c'' := up_ent_c ent (task_s CHR ''c'')))\" tr1\n                                       \"(Sch p 1 ((s(CHR ''p'' := 2)) CHR ''p''))\" \"(s(CHR ''p'' := 2))\" tr2 tr]\n                         apply auto\n                         using pre(4,5,6,12)[unfolded pre(10,11)] \n                         unfolding propc_def proper_def properp_def \n                         by auto\n                       done\n                     apply (simp del: fun_upd_apply)\n                     apply(rule entails_tassn_trans)\n                          apply(rule combine_waitin_tguar'_vassm'_out_0assm1)\n                         subgoal by auto\n                         apply (simp del: fun_upd_apply)\n                         unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           using pre(1)[of k' kk' dis_s \"(Task RUNNING (Suc 0) 2)\" \"(task_s(CHR ''c'' := up_ent_c ent (task_s CHR ''c'')))\" tr1\n                                       \"(Sch p 1 ((s(CHR ''p'' := 2)) CHR ''p''))\" \"(s(CHR ''p'' := 2))\" tr2 tr]\n                           apply auto\n                           using pre(4,5,6,12)[unfolded pre(10,11)] \n                           unfolding propc_def proper_def properp_def \n                           by auto\n                         done\n                       apply(erule disjE)\n                       subgoal premises pre'\n                         thm pre'\n                         apply (simp only:tdsch1'.simps)\n                         apply(rule disjI2)\n                         apply(rule disjI1)\n                       apply(rule combine_blocks_assn)\n                       apply(rule pre'(3))\n                         apply(rule pre'(4))\n                        apply(rule pre'(2))\n                       apply(rule entails_tassn_trans)\n                        apply(rule combine_out_0assm_waitin_assm'2)\n                       subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                       apply(rule in_0orig_vassm'_assn_tran)\n                       apply(subgoal_tac \"rp<2 \\<and> rn\\<noteq>1\")\n                        prefer 2\n                       subgoal using pre(4,5,6,8,9,10,11,12)\n                         unfolding proper_def properp_def propc_def\n                         by auto\n                       apply(cases \"1\\<le>rp\")\n                       subgoal apply (simp del: fun_upd_apply)\n                         unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc dis_s ((Task READY ent 2)) task_s tr1\")\n                            prefer 2 \n                           subgoal using pre by auto\n                           apply auto\n                           using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task READY ent 2)\" task_s tr1 \"(Sch (p @ [(1, 2)]) rn rp)\" \"(s(CHR ''p'' := 1))\" tr2 tr]\n                           using pre(4,5,6,12)[unfolded pre(10,11)] properl_p1\n                           unfolding propc_def proper_def properp_def \n                           by auto\n                         done\n                       apply (simp del: fun_upd_apply)\n                       apply (cases \"rn \\<noteq> - 1\")\n                       subgoal\n                         apply (simp del: fun_upd_apply)\n                         apply(rule entails_tassn_trans)\n                         apply(rule combine_out_0assm_out_0assm2')\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         subgoal using pre \n                           unfolding proper_def properp_def propc_def\n                           by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(rule out_0assm_assn_tran)\n                         apply(rule entails_tassn_trans)\n                         apply(rule combine_out_0assm_out_0assm2')\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         subgoal using pre \n                           unfolding proper_def properp_def propc_def\n                           by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(rule out_0assm_assn_tran)\n                         unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc dis_s ((Task READY ent 2)) task_s tr1\")\n                            prefer 2 \n                           subgoal using pre by auto\n                           apply auto\n                           using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task READY ent 2)\" task_s tr1 \"(Sch p 2 1)\" \"(s(CHR ''p'' := 1))\" tr2 tr]\n                           using pre(4,5,6,12)[unfolded pre(10,11)] properl_p1\n                           unfolding propc_def proper_def properp_def \n                           by auto\n                         done\n                       apply (simp del: fun_upd_apply)\n                         apply(rule entails_tassn_trans)\n                         apply(rule combine_out_0assm_out_0assm2')\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         subgoal using pre \n                           unfolding proper_def properp_def propc_def\n                           by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(rule out_0assm_assn_tran)\n                         unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc dis_s ((Task READY ent 2)) task_s tr1\")\n                            prefer 2 \n                           subgoal using pre by auto\n                           apply auto\n                           using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task READY ent 2)\" task_s tr1 \"(Sch p 2 1)\" \"(s(CHR ''p'' := 1))\" tr2 tr]\n                           using pre(4,5,6,12)[unfolded pre(10,11)] properl_p1\n                           unfolding propc_def proper_def properp_def \n                           by auto\n                         done\n                       apply(erule disjE)\n                        subgoal premises pre'\n                         thm pre'\n                         apply(rule combine_blocks_assn)\n                       apply(rule pre'(3))\n                         apply(rule pre'(4))\n                          apply(rule pre'(2))\n                         apply(rule combine_out_0assm_waitin_assm'3)\n                         by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                       apply(erule disjE)\n                       subgoal premises pre'\n                         thm pre'\n                         apply (simp only:tdsch1'.simps)\n                         apply(rule disjI2)\n                         apply(rule disjI2)\n                         apply(rule disjI1)\n                       apply(rule combine_blocks_assn)\n                       apply(rule pre'(3))\n                         apply(rule pre'(4))\n                        apply(rule pre'(2))\n                       apply(rule entails_tassn_trans)\n                        apply(rule combine_out_0assm_waitin_assm'2)\n                       subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                       apply(rule in_0orig_vassm'_assn_tran)\n                       apply(simp del:fun_upd_apply)\n                       apply(cases \"p \\<noteq> []\")\n                       subgoal\n                         apply(simp del:fun_upd_apply)\n                         apply(rule entails_tassn_trans)\n                         apply(rule combine_out_0assm_out_0assm2')\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         subgoal apply(cases \"get_max p\")\n                           using properl_p5[of p] pre(6,10) unfolding properp_def proper_def\n                           by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(rule out_0assm_assn_tran)\n                         unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc dis_s ((Task READY ent 2)) task_s tr1\")\n                            prefer 2 \n                           subgoal using pre by auto\n                           apply auto\n                           using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task READY ent 2)\" task_s tr1 \"(sched_get_max (Sch p rn rp) s)\" \"s\" tr2 tr]\n                           using pre(4,5,6,12)[unfolded pre(10,11)] properl_p1 \n                           unfolding propc_def proper_def\n                           apply auto\n                           apply(cases \"get_max p\")\n                           using properl_p4 properl_p5[of p]\n                           by auto\n                         done\n                       apply auto\n                       unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc dis_s ((Task READY ent 2)) task_s tr1\")\n                            prefer 2 \n                           subgoal using pre by auto\n                           apply auto\n                           using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task READY ent 2)\" task_s tr1 \"(Sch [] (- 1) (- 1))\" \"s\" tr2 tr]\n                           using pre(4,5,6,12)[unfolded pre(10,11)] properl_p1 \n                           unfolding propc_def proper_def properp_def\n                           by auto\n                         done\n                       apply(erule disjE)\n                       subgoal premises pre'\n                         thm pre'\n                          apply(rule combine_blocks_assn)\n                       apply(rule pre'(3))\n                         apply(rule pre'(4))\n                        apply(rule pre'(2))\n                         apply(rule combine_out_0assm_waitin_assm'3)\n                         by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                       subgoal premises pre'\n                         thm pre'\n                         apply (simp only:tdsch1'.simps)\n                         apply(rule disjI2)\n                         apply(rule disjI2)\n                         apply(rule disjI2)\n                       apply(rule combine_blocks_assn)\n                       apply(rule pre'(3))\n                         apply(rule pre'(4))\n                          apply(rule pre'(2))\n                         apply(rule entails_tassn_trans)\n                          apply(rule combine_out_0assm_waitin_assm'2)\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(rule in_0orig_vassm'_assn_tran)\n                         apply (simp del:fun_upd_apply)\n                         unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc dis_s ((Task READY ent 2)) task_s tr1\")\n                            prefer 2 \n                           subgoal using pre by auto\n                           apply auto\n                           using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task READY ent 2)\" task_s tr1 \"(Sch (del_proc p 2) rn rp)\" \"s\" tr2 tr]\n                           using pre(4,5,6,12)[unfolded pre(10,11)] properl_p1 properl_p4\n                           unfolding propc_def proper_def properp_def\n                           by auto\n                         done\n                       done\n                     apply(erule disjE)\n                     subgoal\n                       apply(simp del:tdsch1'.simps)\n                       apply(erule disjE)\n                       subgoal premises pre'\n                         thm pre'\n                         apply (simp only:tdsch1'.simps)\n                         apply(rule disjI1)\n                         apply(rule combine_blocks_assn)\n                       apply(rule pre'(3))\n                         apply(rule pre'(4))\n                          apply(rule pre'(2))\n                         apply(rule entails_tassn_trans)\n                          apply(rule combine_out_0assm_waitin_assm'1)\n                         subgoal by auto\n                         subgoal by auto\n                         subgoal by auto\n                         apply(subgoal_tac \"rp<2 \\<and> rn\\<noteq>1\")\n                        prefer 2\n                       subgoal using pre(4,5,6,8,9,10,11,12)\n                         unfolding proper_def properp_def propc_def\n                         by auto\n                       apply (simp del: fun_upd_apply)\n                       apply(cases \"rn \\<noteq> -1\")\n                       subgoal\n                         apply (simp del: fun_upd_apply)\n                         apply(rule entails_tassn_trans)\n                          apply(rule combine_wait_orig_out_0assm_rdy_out_0assm2)\n                         subgoal using pre \n                           unfolding proper_def properp_def propc_def\n                           by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(rule out_0assm_assn_tran)\n                         apply(rule entails_tassn_trans)                          \n                          apply(rule combine_wait_orig_out_0assm1)\n                         subgoal \n                           by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply (auto del: fun_upd_apply)\n                         apply(rule combine_out_0assm_rdy_out_0assm)\n                         by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                       apply (simp del: fun_upd_apply)\n                       apply(rule entails_tassn_trans)                          \n                        apply(rule combine_wait_orig_out_0assm1)\n                       subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                      apply (auto del: fun_upd_apply)\n                       apply(rule combine_out_0assm_rdy_out_0assm)\n                         by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                       apply(erule disjE)\n                       subgoal premises pre'\n                         thm pre'\n                         apply (simp only:tdsch1'.simps)\n                         apply(rule disjI2)\n                         apply(rule disjI1)\n                         apply(rule combine_blocks_assn)\n                       apply(rule pre'(3))\n                         apply(rule pre'(4))\n                          apply(rule pre'(2))\n                         apply(rule entails_tassn_trans)\n                          apply(rule combine_out_0assm_waitin_assm'2)\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(rule in_0orig_vassm'_assn_tran)\n                         apply(subgoal_tac \"rp<2 \\<and> rn\\<noteq>1\")\n                        prefer 2\n                       subgoal using pre(4,5,6,8,9,10,11,12)\n                         unfolding proper_def properp_def propc_def\n                         by auto\n                       apply(cases \"1\\<le>rp\")\n                       subgoal apply (simp del: fun_upd_apply)\n                         unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc dis_s ((Task READY ent 2)) task_s tr1\")\n                            prefer 2 \n                           subgoal using pre by auto\n                           apply auto\n                           using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task READY ent 2)\" task_s tr1 \"(Sch (p @ [(1, 2)]) rn rp)\" \"(s(CHR ''p'' := 1))\" tr2 tr]\n                           using pre(4,5,6,12)[unfolded pre(10,11)] properl_p1\n                           unfolding propc_def proper_def properp_def \n                           by auto\n                         done\n                       apply (simp del: fun_upd_apply)\n                       apply (cases \"rn \\<noteq> - 1\")\n                       subgoal\n                         apply (simp del: fun_upd_apply)\n                         apply(rule entails_tassn_trans)\n                         apply(rule combine_out_0assm_out_0assm2')\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         subgoal using pre \n                           unfolding proper_def properp_def propc_def\n                           by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(rule out_0assm_assn_tran)\n                         apply(rule entails_tassn_trans)\n                         apply(rule combine_out_0assm_out_0assm2')\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         subgoal using pre \n                           unfolding proper_def properp_def propc_def\n                           by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(rule out_0assm_assn_tran)\n                         unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc dis_s ((Task READY ent 2)) task_s tr1\")\n                            prefer 2 \n                           subgoal using pre by auto\n                           apply auto\n                           using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task READY ent 2)\" task_s tr1 \"(Sch p 2 1)\" \"(s(CHR ''p'' := 1))\" tr2 tr]\n                           using pre(4,5,6,12)[unfolded pre(10,11)] properl_p1\n                           unfolding propc_def proper_def properp_def \n                           by auto\n                         done\n                       apply (simp del: fun_upd_apply)\n                         apply(rule entails_tassn_trans)\n                         apply(rule combine_out_0assm_out_0assm2')\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         subgoal using pre \n                           unfolding proper_def properp_def propc_def\n                           by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(rule out_0assm_assn_tran)\n                         unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc dis_s ((Task READY ent 2)) task_s tr1\")\n                            prefer 2 \n                           subgoal using pre by auto\n                           apply auto\n                           using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task READY ent 2)\" task_s tr1 \"(Sch p 2 1)\" \"(s(CHR ''p'' := 1))\" tr2 tr]\n                           using pre(4,5,6,12)[unfolded pre(10,11)] properl_p1\n                           unfolding propc_def proper_def properp_def \n                           by auto\n                         done\n                       apply(erule disjE)\n                        subgoal premises pre'\n                         thm pre'\n                         apply(rule combine_blocks_assn)\n                       apply(rule pre'(3))\n                         apply(rule pre'(4))\n                          apply(rule pre'(2))\n                         apply(rule combine_out_0assm_waitin_assm'3)\n                         by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                       apply(erule disjE)\n                       subgoal premises pre'\n                         thm pre'\n                         apply (simp only:tdsch1'.simps)\n                         apply(rule disjI2)\n                         apply(rule disjI2)\n                         apply(rule disjI1)\n                       apply(rule combine_blocks_assn)\n                       apply(rule pre'(3))\n                         apply(rule pre'(4))\n                        apply(rule pre'(2))\n                       apply(rule entails_tassn_trans)\n                        apply(rule combine_out_0assm_waitin_assm'2)\n                       subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                       apply(rule in_0orig_vassm'_assn_tran)\n                       apply(simp del:fun_upd_apply)\n                       apply(cases \"p \\<noteq> []\")\n                       subgoal\n                         apply(simp del:fun_upd_apply)\n                         apply(rule entails_tassn_trans)\n                         apply(rule combine_out_0assm_out_0assm2')\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         subgoal apply(cases \"get_max p\")\n                           using properl_p5[of p] pre(6,10) unfolding properp_def proper_def\n                           by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(rule out_0assm_assn_tran)\n                         unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc dis_s ((Task READY ent 2)) task_s tr1\")\n                            prefer 2 \n                           subgoal using pre by auto\n                           apply auto\n                           using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task READY ent 2)\" task_s tr1 \"(sched_get_max (Sch p rn rp) s)\" \"s\" tr2 tr]\n                           using pre(4,5,6,12)[unfolded pre(10,11)] properl_p1 \n                           unfolding propc_def proper_def\n                           apply auto\n                           apply(cases \"get_max p\")\n                           using properl_p4 properl_p5[of p]\n                           by auto\n                         done\n                       apply auto\n                       unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc dis_s ((Task READY ent 2)) task_s tr1\")\n                            prefer 2 \n                           subgoal using pre by auto\n                           apply auto\n                           using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task READY ent 2)\" task_s tr1 \"(Sch [] (- 1) (- 1))\" \"s\" tr2 tr]\n                           using pre(4,5,6,12)[unfolded pre(10,11)] properl_p1 \n                           unfolding propc_def proper_def properp_def\n                           by auto\n                         done\n                       apply(erule disjE)\n                       subgoal premises pre'\n                         thm pre'\n                          apply(rule combine_blocks_assn)\n                       apply(rule pre'(3))\n                         apply(rule pre'(4))\n                        apply(rule pre'(2))\n                         apply(rule combine_out_0assm_waitin_assm'3)\n                         by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                       subgoal premises pre'\n                         thm pre'\n                         apply (simp only:tdsch1'.simps)\n                         apply(rule disjI2)\n                         apply(rule disjI2)\n                         apply(rule disjI2)\n                       apply(rule combine_blocks_assn)\n                       apply(rule pre'(3))\n                         apply(rule pre'(4))\n                          apply(rule pre'(2))\n                         apply(rule entails_tassn_trans)\n                          apply(rule combine_out_0assm_waitin_assm'2)\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(rule in_0orig_vassm'_assn_tran)\n                         apply (simp del:fun_upd_apply)\n                         unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc dis_s ((Task READY ent 2)) task_s tr1\")\n                            prefer 2 \n                           subgoal using pre by auto\n                           apply auto\n                           using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task READY ent 2)\" task_s tr1 \"(Sch (del_proc p 2) rn rp)\" \"s\" tr2 tr]\n                           using pre(4,5,6,12)[unfolded pre(10,11)] properl_p1 properl_p4\n                           unfolding propc_def proper_def properp_def\n                           by auto\n                         done\n                       done\n                     subgoal\n                       apply(simp del:tdsch1'.simps)\n                       apply(erule disjE)\n                       subgoal premises pre'\n                         thm pre'\n                         apply (simp only:tdsch1'.simps)\n                         apply(rule disjI1)\n                         apply(rule combine_blocks_assn)\n                       apply(rule pre'(3))\n                         apply(rule pre'(4))\n                          apply(rule pre'(2))\n                         apply(rule entails_tassn_trans)\n                          apply(rule combine_out_0assm_waitin_assm'1)\n                         subgoal by auto\n                         subgoal by auto\n                         subgoal by auto\n                         apply(subgoal_tac \"rp<2 \\<and> rn\\<noteq>1\")\n                        prefer 2\n                       subgoal using pre(4,5,6,8,9,10,11,12)\n                         unfolding proper_def properp_def propc_def\n                         by auto\n                       apply (simp del: fun_upd_apply)\n                       apply(cases \"rn \\<noteq> -1\")\n                       subgoal\n                         apply (simp del: fun_upd_apply)\n                         apply(rule entails_tassn_trans)\n                          apply(rule combine_wait_orig_in_0assm_rdy_out_0assm2)\n                         subgoal using pre \n                           unfolding proper_def properp_def propc_def\n                           by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(rule out_0assm_assn_tran)\n                         apply(rule entails_tassn_trans)                          \n                          apply(rule combine_wait_orig_out_0assm1)\n                         subgoal \n                           by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply (auto del: fun_upd_apply)\n                         apply(rule entails_tassn_trans)\n                          apply(rule combine_in_0assm_rdy_out_0assm)\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           apply(subgoal_tac \"pd = task_s CHR ''t''\")\n                            apply (auto del: fun_upd_apply)\n                           using pre(1)[of \"k'\" kk' dis_s \"(Task RUNNING (Suc 0) 2)\" \"(task_s(CHR ''c'' := up_ent_c ent (task_s CHR ''c'')))\" tr1 \"(Sch p 1 2)\" \"(s(CHR ''p'' := 2))\" tr2 tr]\n                           using pre(4,5,6,12)[unfolded pre(10,11)] properl_p1 \n                           unfolding propc_def proper_def properp_def\n                           by auto\n                         done\n                       apply (simp del: fun_upd_apply)\n                       apply(rule entails_tassn_trans)                          \n                        apply(rule combine_wait_orig_out_0assm1)\n                       subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                       apply (auto del: fun_upd_apply)\n                       apply(rule entails_tassn_trans)                          \n                       apply(rule combine_in_0assm_rdy_out_0assm)\n                       subgoal   by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                       unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           apply(subgoal_tac \"pd = task_s CHR ''t''\")\n                            apply (auto del: fun_upd_apply)\n                           using pre(1)[of \"k'\" kk' dis_s \"(Task RUNNING (Suc 0) 2)\" \"(task_s(CHR ''c'' := up_ent_c ent (task_s CHR ''c'')))\" tr1 \"(Sch p 1 2)\" \"(s(CHR ''p'' := 2))\" tr2 tr]\n                           using pre(4,5,6,12)[unfolded pre(10,11)] properl_p1 \n                           unfolding propc_def proper_def properp_def\n                           by auto\n                             done\n                       apply(erule disjE)\n                       subgoal premises pre'\n                         thm pre'\n                         apply (simp only:tdsch1'.simps)\n                         apply(rule disjI2)\n                         apply(rule disjI1)\n                         apply(rule combine_blocks_assn)\n                       apply(rule pre'(3))\n                         apply(rule pre'(4))\n                          apply(rule pre'(2))\n                         apply(rule entails_tassn_trans)\n                          apply(rule combine_out_0assm_waitin_assm'2)\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(rule in_0orig_vassm'_assn_tran)\n                         apply(subgoal_tac \"rp<2 \\<and> rn\\<noteq>1\")\n                        prefer 2\n                       subgoal using pre(4,5,6,8,9,10,11,12)\n                         unfolding proper_def properp_def propc_def\n                         by auto\n                       apply(cases \"1\\<le>rp\")\n                       subgoal apply (simp del: fun_upd_apply)\n                         unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc dis_s ((Task READY ent 2)) task_s tr1\")\n                            prefer 2 \n                           subgoal using pre by auto\n                           apply auto\n                           using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task READY ent 2)\" task_s tr1 \"(Sch (p @ [(1, 2)]) rn rp)\" \"(s(CHR ''p'' := 1))\" tr2 tr]\n                           using pre(4,5,6,12)[unfolded pre(10,11)] properl_p1\n                           unfolding propc_def proper_def properp_def \n                           by auto\n                         done\n                       apply (simp del: fun_upd_apply)\n                       apply (cases \"rn \\<noteq> - 1\")\n                       subgoal\n                         apply (simp del: fun_upd_apply)\n                         apply(rule entails_tassn_trans)\n                         apply(rule combine_out_0assm_out_0assm2')\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         subgoal using pre \n                           unfolding proper_def properp_def propc_def\n                           by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(rule out_0assm_assn_tran)\n                         apply(rule entails_tassn_trans)\n                         apply(rule combine_out_0assm_out_0assm2')\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         subgoal using pre \n                           unfolding proper_def properp_def propc_def\n                           by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(rule out_0assm_assn_tran)\n                         unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc dis_s ((Task READY ent 2)) task_s tr1\")\n                            prefer 2 \n                           subgoal using pre by auto\n                           apply auto\n                           using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task READY ent 2)\" task_s tr1 \"(Sch p 2 1)\" \"(s(CHR ''p'' := 1))\" tr2 tr]\n                           using pre(4,5,6,12)[unfolded pre(10,11)] properl_p1\n                           unfolding propc_def proper_def properp_def \n                           by auto\n                         done\n                       apply (simp del: fun_upd_apply)\n                         apply(rule entails_tassn_trans)\n                         apply(rule combine_out_0assm_out_0assm2')\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         subgoal using pre \n                           unfolding proper_def properp_def propc_def\n                           by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(rule out_0assm_assn_tran)\n                         unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc dis_s ((Task READY ent 2)) task_s tr1\")\n                            prefer 2 \n                           subgoal using pre by auto\n                           apply auto\n                           using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task READY ent 2)\" task_s tr1 \"(Sch p 2 1)\" \"(s(CHR ''p'' := 1))\" tr2 tr]\n                           using pre(4,5,6,12)[unfolded pre(10,11)] properl_p1\n                           unfolding propc_def proper_def properp_def \n                           by auto\n                         done\n                       apply(erule disjE)\n                        subgoal premises pre'\n                         thm pre'\n                         apply(rule combine_blocks_assn)\n                       apply(rule pre'(3))\n                         apply(rule pre'(4))\n                          apply(rule pre'(2))\n                         apply(rule combine_out_0assm_waitin_assm'3)\n                         by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                       apply(erule disjE)\n                       subgoal premises pre'\n                         thm pre'\n                         apply (simp only:tdsch1'.simps)\n                         apply(rule disjI2)\n                         apply(rule disjI2)\n                         apply(rule disjI1)\n                       apply(rule combine_blocks_assn)\n                       apply(rule pre'(3))\n                         apply(rule pre'(4))\n                        apply(rule pre'(2))\n                       apply(rule entails_tassn_trans)\n                        apply(rule combine_out_0assm_waitin_assm'2)\n                       subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                       apply(rule in_0orig_vassm'_assn_tran)\n                       apply(simp del:fun_upd_apply)\n                       apply(cases \"p \\<noteq> []\")\n                       subgoal\n                         apply(simp del:fun_upd_apply)\n                         apply(rule entails_tassn_trans)\n                         apply(rule combine_out_0assm_out_0assm2')\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         subgoal apply(cases \"get_max p\")\n                           using properl_p5[of p] pre(6,10) unfolding properp_def proper_def\n                           by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(rule out_0assm_assn_tran)\n                         unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc dis_s ((Task READY ent 2)) task_s tr1\")\n                            prefer 2 \n                           subgoal using pre by auto\n                           apply auto\n                           using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task READY ent 2)\" task_s tr1 \"(sched_get_max (Sch p rn rp) s)\" \"s\" tr2 tr]\n                           using pre(4,5,6,12)[unfolded pre(10,11)] properl_p1 \n                           unfolding propc_def proper_def\n                           apply auto\n                           apply(cases \"get_max p\")\n                           using properl_p4 properl_p5[of p]\n                           by auto\n                         done\n                       apply auto\n                       unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc dis_s ((Task READY ent 2)) task_s tr1\")\n                            prefer 2 \n                           subgoal using pre by auto\n                           apply auto\n                           using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task READY ent 2)\" task_s tr1 \"(Sch [] (- 1) (- 1))\" \"s\" tr2 tr]\n                           using pre(4,5,6,12)[unfolded pre(10,11)] properl_p1 \n                           unfolding propc_def proper_def properp_def\n                           by auto\n                         done\n                       apply(erule disjE)\n                       subgoal premises pre'\n                         thm pre'\n                          apply(rule combine_blocks_assn)\n                       apply(rule pre'(3))\n                         apply(rule pre'(4))\n                        apply(rule pre'(2))\n                         apply(rule combine_out_0assm_waitin_assm'3)\n                         by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                       subgoal premises pre'\n                         thm pre'\n                         apply (simp only:tdsch1'.simps)\n                         apply(rule disjI2)\n                         apply(rule disjI2)\n                         apply(rule disjI2)\n                       apply(rule combine_blocks_assn)\n                       apply(rule pre'(3))\n                         apply(rule pre'(4))\n                          apply(rule pre'(2))\n                         apply(rule entails_tassn_trans)\n                          apply(rule combine_out_0assm_waitin_assm'2)\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(rule in_0orig_vassm'_assn_tran)\n                         apply (simp del:fun_upd_apply)\n                         unfolding combine_assn_def entails_tassn_def\n                         apply clarify\n                         subgoal for tr tr1 tr2\n                           apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc dis_s ((Task READY ent 2)) task_s tr1\")\n                            prefer 2 \n                           subgoal using pre by auto\n                           apply auto\n                           using pre(1)[of \"(Suc k')\" kk' dis_s \"(Task READY ent 2)\" task_s tr1 \"(Sch (del_proc p 2) rn rp)\" \"s\" tr2 tr]\n                           using pre(4,5,6,12)[unfolded pre(10,11)] properl_p1 properl_p4\n                           unfolding propc_def proper_def properp_def\n                           by auto\n                         done\n                       done\n                     done\n                       (* part 3 *)\n                   subgoal premises pre\n                      thm pre\n                   using pre(2) pre(3) pre(4) pre(7)\n                   apply(simp add: pre(10,11,12,4) del:tdsch1'.simps sched_assn'.simps)\n                   apply(cases \"ent \\<noteq> Suc 0\")\n                   subgoal\n                     apply(simp del:tdsch1'.simps sched_assn'.simps)\n                     done\n                   apply(simp del:tdsch1'.simps sched_assn'.simps)\n                   apply(erule disjE)\n                   subgoal\n                     apply(simp del:tdsch1'.simps)\n                     apply(erule disjE)\n                     subgoal premises pre'\n                       thm pre'\n                       apply(rule combine_blocks_assn)\n                          apply(rule pre'(4))\n                         apply(rule pre'(5))\n                        apply(rule pre'(2))\n                       apply(rule combine_waitin_tguar'_vassm'_waitin_assms'1)\n                       by auto\n                     apply(erule disjE)\n                     subgoal\n                       apply(cases rule:waitin_tguar'_vassm'_assn.cases[of \"{0..<min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')}\"\n                           \"(\\<lambda>t. ParState\n                                 (EState\n                                   (Task RUNNING (Suc 0) 2, task_s\n                                    (CHR ''t'' := task_s CHR ''t'' + t, CHR ''c'' := task_s CHR ''c'' + t)))\n                                 (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\"\n                           \"({}, {preempt_ch 1})\" \"(preempt_ch 1)\" \"{0}\"\n                           \"(\\<lambda>v d. task_dis_assn' 1 k' pd pc (dis_s(CHR ''t'' := dis_s CHR ''t'' + d))\n                                   (Task READY (Suc 0) 2)\n                                   (task_s\n                                    (CHR ''t'' := task_s CHR ''t'' + d, CHR ''c'' := task_s CHR ''c'' + d)))\"\n                           tr1])\n                           apply simp\n                       subgoal for v1 tr1'\n                         apply(simp only: tdsch1'.simps)\n                         apply(rule disjI1)\n                         apply(cases rule:waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                 \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(req_ch 2)\"\n                                 \"{1}\"\n                                 \"(\\<lambda>v d. if v \\<le> rp\n                                        then sched_assn' kk' (sched_push 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                              (s(CHR ''p'' := v))\n                                        else if rn \\<noteq> - 1\n                                             then out_0assm_assn (preempt_ch rn) 0\n                                                   (out_0assm_assn (run_ch 2) 0\n                                                     (sched_assn' kk'\n                                                       (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                       (s(CHR ''p'' := v))))\n                                             else out_0assm_assn (run_ch 2) 0\n                                                   (sched_assn' kk'\n                                                     (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                     (s(CHR ''p'' := v))))\" tr2])\n                             apply simp\n                         subgoal for v2 tr2'\n                           apply auto\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           thm pre\n                           using pre(4,5,6,10,11,12)\n                           unfolding propc_def proper_def properp_def\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                             apply auto\n                           subgoal for tr'\n                           using pre(1)[of \"Suc k'\" kk' dis_s task_es task_s tr1 \"(Sch (p @ [(1, 2)]) 1 2)\" \"(s(CHR ''p'' := 1))\" tr2' tr']\n                           using properl_p1\n                           unfolding propc_def proper_def properp_def\n                           by auto\n                         done\n                       subgoal for v2 d2 tr2'\n                         by (auto elim!: sync_elims) \n                       subgoal for v2 tr2'\n                           apply auto\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           thm pre\n                           using pre(4,5,6,10,11,12)\n                           unfolding propc_def proper_def properp_def\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                           by auto\n                       subgoal for v2 d2 tr2'\n                         by (auto elim!: sync_elims) \n                       done\n                     subgoal for d1 v1 tr1'\n                       apply(simp only: tdsch1'.simps)\n                         apply(rule disjI1)\n                         apply(cases rule:waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                 \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(req_ch 2)\"\n                                 \"{1}\"\n                                 \"(\\<lambda>v d. if v \\<le> rp\n                                        then sched_assn' kk' (sched_push 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                              (s(CHR ''p'' := v))\n                                        else if rn \\<noteq> - 1\n                                             then out_0assm_assn (preempt_ch rn) 0\n                                                   (out_0assm_assn (run_ch 2) 0\n                                                     (sched_assn' kk'\n                                                       (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                       (s(CHR ''p'' := v))))\n                                             else out_0assm_assn (run_ch 2) 0\n                                                   (sched_assn' kk'\n                                                     (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                     (s(CHR ''p'' := v))))\" tr2])\n                           apply simp\n                       subgoal for v2 tr2'\n                         apply auto\n                         apply(elim combine_blocks_unpairE3')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           thm pre\n                           using pre(4,5,6,10,11,12)\n                           unfolding propc_def proper_def properp_def\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                             apply auto\n                           subgoal for tr'\n                           using pre(1)[of \"Suc k'\" kk' dis_s task_es task_s tr1 \"(Sch (p @ [(1, 2)]) 1 2)\" \"(s(CHR ''p'' := 1))\" tr2' tr']\n                           using properl_p1\n                           unfolding propc_def proper_def properp_def\n                           by auto\n                         done\n                       subgoal for v2 d2 tr2'\n                         apply auto\n                         apply(cases \"d1<d2\")\n                         subgoal\n                           apply(elim combine_blocks_waitE3)\n                           subgoal by auto\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           by (auto elim!: sync_elims) \n                         apply(cases \"d1>d2\")\n                         subgoal\n                           apply(elim combine_blocks_waitE4)\n                           subgoal by auto\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(elim combine_blocks_unpairE3')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                              apply auto\n                           subgoal for tr'\n                             using pre(4,5,6,10,11,12)\n                             unfolding propc_def proper_def properp_def\n                             apply auto\n                             using pre(1)[of \"(Suc k')\" kk' \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + d2))\"\n                                             \"(Task RUNNING (Suc 0) 2)\"\"(task_s(CHR ''t'' := task_s CHR ''t'' + d2, CHR ''c'' := task_s CHR ''c'' + d2))\"\n                                             \"(WaitBlk (d1 - d2)\n                                               (\\<lambda>t. ParState\n                                                     (EState\n                                                       (Task RUNNING (Suc 0) 2, task_s\n                                                        (CHR ''t'' := task_s CHR ''t'' + (t + d2),\n                                                         CHR ''c'' := task_s CHR ''c'' + (t + d2))))\n                                                     (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d2)))))\n                                               ({}, {preempt_ch 1}) #\n                                              InBlock (preempt_ch 1) 0 # tr1')\" \"(Sch (p @ [(1, 2)]) 1 2)\" \"(s(CHR ''p'' := 1))\" tr2' tr']\n                             apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc (dis_s(CHR ''t'' := dis_s CHR ''t'' + d2))\n                                                 (Task RUNNING (Suc 0) 2)\n                                                 (task_s(CHR ''t'' := task_s CHR ''t'' + d2, CHR ''c'' := task_s CHR ''c'' + d2))\n                                                 (WaitBlk (d1 - d2)\n                                                   (\\<lambda>t. ParState\n                                                         (EState\n                                                           (Task RUNNING (Suc 0) 2, task_s\n                                                            (CHR ''t'' := task_s CHR ''t'' + (t + d2),\n                                                             CHR ''c'' := task_s CHR ''c'' + (t + d2))))\n                                                         (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d2)))))\n                                                   ({}, {preempt_ch 1}) #\n                                                  InBlock (preempt_ch 1) 0 # tr1')\")\n                              prefer 2\n                             subgoal premises pre'\n                             proof-\n                               have 1:\"(\\<lambda>t. ParState\n                                     (EState\n                                       (Task RUNNING (Suc 0) 2, task_s\n                                        (CHR ''t'' := task_s CHR ''t'' + d2 + t,\n                                         CHR ''c'' := task_s CHR ''c'' + d2 + t)))\n                                     (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + d2 + t)))) =\n                                     (\\<lambda>t. ParState\n                                       (EState\n                                         (Task RUNNING (Suc 0) 2, task_s\n                                          (CHR ''t'' := task_s CHR ''t'' + (t + d2),\n                                           CHR ''c'' := task_s CHR ''c'' + (t + d2))))\n                                       (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d2)))))\"\n                                 apply(rule ext)\n                                 by auto\n                               show ?thesis\n                                 apply simp\n                                 apply(rule disjI1)\n                                 apply(subst 1) \n                                 apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                                 subgoal using pre' by auto\n                                 subgoal using pre' by auto\n                                 subgoal by auto\n                                 using pre'(7)\n                                 by auto\n                             qed\n                             subgoal premises pre'\n                               thm pre'\n                               apply(rule pre'(23))\n                               subgoal by auto\n                               subgoal using pre'(24) by auto\n                               subgoal using pre' by auto\n                               subgoal by auto\n                               subgoal unfolding propc_def\n                                 by auto\n                               subgoal \n                                 using properl_p1\n                                 unfolding proper_def properp_def \n                                 using pre' by auto\n                               subgoal using pre' by auto\n                               done\n                             done\n                           done\n                         apply auto\n                         apply(elim combine_blocks_waitE2)\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply auto\n                         apply (elim combine_blocks_unpairE1')\n                         subgoal by auto\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply auto\n                         subgoal for tr'\n                           apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                           subgoal by auto\n                           subgoal by auto\n                           subgoal by auto\n                           using pre(4,5,6,10,11,12)\n                           unfolding propc_def proper_def properp_def\n                           apply auto\n                           using pre(1)[of \"(Suc k')\" kk' \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + d2))\"\n                                             \"(Task RUNNING (Suc 0) 2)\"\"(task_s(CHR ''t'' := task_s CHR ''t'' + d2, CHR ''c'' := task_s CHR ''c'' + d2))\"\n                                             \"(InBlock (preempt_ch 1) 0 # tr1')\" \"(Sch (p @ [(1, 2)]) 1 2)\" \"(s(CHR ''p'' := 1))\" tr2' tr']\n                           apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc (dis_s(CHR ''t'' := dis_s CHR ''t'' + d2))\n                                                 (Task RUNNING (Suc 0) 2)\n                                                 (task_s(CHR ''t'' := task_s CHR ''t'' + d2, CHR ''c'' := task_s CHR ''c'' + d2))\n                                                 (InBlock (preempt_ch 1) 0 # tr1') \")\n                            prefer 2\n                           subgoal premises pre'\n                             apply simp\n                             apply(rule disjI1)\n                             apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                             using pre' by auto\n                           subgoal premises pre'\n                             thm pre'\n                             apply(rule pre'(23))\n                             subgoal by auto\n                             subgoal using pre' by auto\n                             subgoal using pre' by auto\n                             subgoal by auto\n                             subgoal unfolding propc_def\n                               by auto\n                             subgoal \n                               using properl_p1\n                               unfolding proper_def properp_def \n                               using pre' by auto\n                             subgoal using pre' by auto\n                             done\n                           done\n                         done\n                       subgoal for v2 tr2'\n                         apply auto\n                         apply(elim combine_blocks_unpairE3')\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply auto\n                         apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                         by auto\n                       subgoal for d2 v2 tr2'\n                         apply auto\n                         apply(cases \"d1<d2\")\n                         subgoal\n                           apply(elim combine_blocks_waitE3)\n                           subgoal by auto\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           by (auto elim!: sync_elims) \n                         apply(cases \"d1>d2\")\n                         subgoal\n                           apply(elim combine_blocks_waitE4)\n                           subgoal by auto\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(elim combine_blocks_unpairE3')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                           by auto\n                         apply auto\n                         apply(elim combine_blocks_waitE2)\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply auto\n                         apply (elim combine_blocks_unpairE1')\n                         subgoal by auto\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply auto\n                         apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                         by auto\n                       done\n                     subgoal for v1 tr1'\n                         apply(simp only: tdsch1'.simps)\n                         apply(rule disjI1)\n                         apply(cases rule:waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                 \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(req_ch 2)\"\n                                 \"{1}\"\n                                 \"(\\<lambda>v d. if v \\<le> rp\n                                        then sched_assn' kk' (sched_push 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                              (s(CHR ''p'' := v))\n                                        else if rn \\<noteq> - 1\n                                             then out_0assm_assn (preempt_ch rn) 0\n                                                   (out_0assm_assn (run_ch 2) 0\n                                                     (sched_assn' kk'\n                                                       (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                       (s(CHR ''p'' := v))))\n                                             else out_0assm_assn (run_ch 2) 0\n                                                   (sched_assn' kk'\n                                                     (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                     (s(CHR ''p'' := v))))\" tr2])\n                             apply simp\n                         subgoal for v2 tr2'\n                           apply auto\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           thm pre\n                           using pre(4,5,6,10,11,12)\n                           unfolding propc_def proper_def properp_def\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                             apply auto\n                           subgoal for tr'\n                           using pre(1)[of \"Suc k'\" kk' dis_s task_es task_s tr1 \"(Sch (p @ [(1, 2)]) 1 2)\" \"(s(CHR ''p'' := 1))\" tr2' tr']\n                           using properl_p1\n                           unfolding propc_def proper_def properp_def\n                           by auto\n                         done\n                       subgoal for v2 d2 tr2'\n                         by (auto elim!: sync_elims) \n                       subgoal for v2 tr2'\n                           apply auto\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           thm pre\n                           using pre(4,5,6,10,11,12)\n                           unfolding propc_def proper_def properp_def\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                           by auto\n                       subgoal for v2 d2 tr2'\n                         by (auto elim!: sync_elims) \n                       done\n                     subgoal for d1 v1 tr1'\n                       apply(simp only: tdsch1'.simps)\n                        apply(rule disjI1)\n                         apply(cases rule:waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                 \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(req_ch 2)\"\n                                 \"{1}\"\n                                 \"(\\<lambda>v d. if v \\<le> rp\n                                        then sched_assn' kk' (sched_push 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                              (s(CHR ''p'' := v))\n                                        else if rn \\<noteq> - 1\n                                             then out_0assm_assn (preempt_ch rn) 0\n                                                   (out_0assm_assn (run_ch 2) 0\n                                                     (sched_assn' kk'\n                                                       (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                       (s(CHR ''p'' := v))))\n                                             else out_0assm_assn (run_ch 2) 0\n                                                   (sched_assn' kk'\n                                                     (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                     (s(CHR ''p'' := v))))\" tr2])\n                           apply simp\n                       subgoal for v2 tr2'\n                         apply auto\n                         apply(elim combine_blocks_unpairE3')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           thm pre\n                           using pre(4,5,6,10,11,12)\n                           unfolding propc_def proper_def properp_def\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                             apply auto\n                           subgoal for tr'\n                           using pre(1)[of \"Suc k'\" kk' dis_s task_es task_s tr1 \"(Sch (p @ [(1, 2)]) 1 2)\" \"(s(CHR ''p'' := 1))\" tr2' tr']\n                           using properl_p1\n                           unfolding propc_def proper_def properp_def\n                           by auto\n                         done\n                       subgoal for v2 d2 tr2'\n                         apply auto\n                         apply(cases \"d1<d2\")\n                         subgoal\n                           apply(elim combine_blocks_waitE3)\n                           subgoal by auto\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           by (auto elim!: sync_elims) \n                         apply(cases \"d1>d2\")\n                         subgoal\n                           apply(elim combine_blocks_waitE4)\n                           subgoal by auto\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(elim combine_blocks_unpairE3')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                              apply auto\n                           subgoal for tr'\n                             using pre(4,5,6,10,11,12)\n                             unfolding propc_def proper_def properp_def\n                             apply auto\n                             using pre(1)[of \"(Suc k')\" kk' \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + d2))\"\n                                             \"(Task RUNNING (Suc 0) 2)\"\"(task_s(CHR ''t'' := task_s CHR ''t'' + d2, CHR ''c'' := task_s CHR ''c'' + d2))\"\n                                             \"(WaitBlk (d1 - d2)\n                                               (\\<lambda>t. ParState\n                                                     (EState\n                                                       (Task RUNNING (Suc 0) 2, task_s\n                                                        (CHR ''t'' := task_s CHR ''t'' + (t + d2),\n                                                         CHR ''c'' := task_s CHR ''c'' + (t + d2))))\n                                                     (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d2)))))\n                                               ({}, {preempt_ch 1}) #\n                                              InBlock (preempt_ch 1) v1 # tr1')\" \"(Sch (p @ [(1, 2)]) 1 2)\" \"(s(CHR ''p'' := 1))\" tr2' tr']\n                             apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc (dis_s(CHR ''t'' := dis_s CHR ''t'' + d2))\n                                                 (Task RUNNING (Suc 0) 2)\n                                                 (task_s(CHR ''t'' := task_s CHR ''t'' + d2, CHR ''c'' := task_s CHR ''c'' + d2))\n                                                 (WaitBlk (d1 - d2)\n                                                   (\\<lambda>t. ParState\n                                                         (EState\n                                                           (Task RUNNING (Suc 0) 2, task_s\n                                                            (CHR ''t'' := task_s CHR ''t'' + (t + d2),\n                                                             CHR ''c'' := task_s CHR ''c'' + (t + d2))))\n                                                         (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d2)))))\n                                                   ({}, {preempt_ch 1}) #\n                                                  InBlock (preempt_ch 1) v1 # tr1')\")\n                              prefer 2\n                             subgoal premises pre'\n                             proof-\n                               have 1:\"(\\<lambda>t. ParState\n                                     (EState\n                                       (Task RUNNING (Suc 0) 2, task_s\n                                        (CHR ''t'' := task_s CHR ''t'' + d2 + t,\n                                         CHR ''c'' := task_s CHR ''c'' + d2 + t)))\n                                     (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + d2 + t)))) =\n                                     (\\<lambda>t. ParState\n                                       (EState\n                                         (Task RUNNING (Suc 0) 2, task_s\n                                          (CHR ''t'' := task_s CHR ''t'' + (t + d2),\n                                           CHR ''c'' := task_s CHR ''c'' + (t + d2))))\n                                       (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d2)))))\"\n                                 apply(rule ext)\n                                 by auto\n                               show ?thesis\n                                 apply simp\n                                 apply(rule disjI1)\n                                 apply(subst 1) \n                                 apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                                 subgoal using pre' by auto\n                                 subgoal using pre' by auto\n                                 subgoal using pre'\n                                   by auto\n                                 done\n                             qed\n                             subgoal premises pre'\n                               thm pre'\n                               apply(rule pre'(22))\n                               subgoal by auto\n                               subgoal using pre' by auto\n                               subgoal using pre' by auto\n                               subgoal by auto\n                               subgoal unfolding propc_def\n                                 by auto\n                               subgoal \n                                 using properl_p1\n                                 unfolding proper_def properp_def \n                                 using pre' by auto\n                               subgoal using pre' by auto\n                               done\n                             done\n                           done\n                         apply auto\n                         apply(elim combine_blocks_waitE2)\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply auto\n                         apply (elim combine_blocks_unpairE1')\n                         subgoal by auto\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply auto\n                         subgoal for tr'\n                           apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                           subgoal by auto\n                           subgoal by auto\n                           subgoal by auto\n                           using pre(4,5,6,10,11,12)\n                           unfolding propc_def proper_def properp_def\n                           apply auto\n                           using pre(1)[of \"(Suc k')\" kk' \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + d2))\"\n                                             \"(Task RUNNING (Suc 0) 2)\"\"(task_s(CHR ''t'' := task_s CHR ''t'' + d2, CHR ''c'' := task_s CHR ''c'' + d2))\"\n                                             \"(InBlock (preempt_ch 1) v1 # tr1')\" \"(Sch (p @ [(1, 2)]) 1 2)\" \"(s(CHR ''p'' := 1))\" tr2' tr']\n                           apply(subgoal_tac \"task_dis_assn' 1 (Suc k') pd pc (dis_s(CHR ''t'' := dis_s CHR ''t'' + d2))\n                                                 (Task RUNNING (Suc 0) 2)\n                                                 (task_s(CHR ''t'' := task_s CHR ''t'' + d2, CHR ''c'' := task_s CHR ''c'' + d2))\n                                                 (InBlock (preempt_ch 1) v1 # tr1') \")\n                            prefer 2\n                           subgoal premises pre'\n                             apply simp\n                             apply(rule disjI1)\n                             apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                             using pre' by auto\n                           subgoal premises pre'\n                             thm pre'\n                             apply(rule pre'(22))\n                             subgoal by auto\n                             subgoal using pre' by auto\n                             subgoal using pre' by auto\n                             subgoal by auto\n                             subgoal unfolding propc_def\n                               by auto\n                             subgoal \n                               using properl_p1\n                               unfolding proper_def properp_def \n                               using pre' by auto\n                             subgoal using pre' by auto\n                             done\n                           done\n                         done\n                       subgoal for v2 tr2'\n                         apply auto\n                         apply(elim combine_blocks_unpairE3')\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply auto\n                         apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                         by auto\n                       subgoal for d2 v2 tr2'\n                         apply auto\n                         apply(cases \"d1<d2\")\n                         subgoal\n                           apply(elim combine_blocks_waitE3)\n                           subgoal by auto\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           by (auto elim!: sync_elims) \n                         apply(cases \"d1>d2\")\n                         subgoal\n                           apply(elim combine_blocks_waitE4)\n                           subgoal by auto\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(elim combine_blocks_unpairE3')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                           by auto\n                         apply auto\n                         apply(elim combine_blocks_waitE2)\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply auto\n                         apply (elim combine_blocks_unpairE1')\n                         subgoal by auto\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply auto\n                         apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                         by auto\n                       done\n                     done\n                   apply(erule disjE)\n                   subgoal premises pre'\n                     apply(rule combine_blocks_assn)\n                          apply(rule pre'(4))\n                         apply(rule pre'(5))\n                        apply(rule pre'(2))\n                       apply(rule combine_waitin_tguar'_vassm'_waitin_assms'1)\n                     by auto\n                   apply(erule disjE)\n                   subgoal\n                     apply(simp only: tdsch1'.simps)\n                     apply(rule disjI2)\n                     apply(rule disjI1)\n                     apply(cases rule:waitin_tguar'_vassm'_assn.cases[of \"{0..<min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')}\"\n                           \"(\\<lambda>t. ParState\n                                 (EState\n                                   (Task RUNNING (Suc 0) 2, task_s\n                                    (CHR ''t'' := task_s CHR ''t'' + t, CHR ''c'' := task_s CHR ''c'' + t)))\n                                 (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\"\n                           \"({}, {preempt_ch 1})\" \"(preempt_ch 1)\" \"{0}\"\n                           \"(\\<lambda>v d. task_dis_assn' 1 k' pd pc (dis_s(CHR ''t'' := dis_s CHR ''t'' + d))\n                                   (Task READY (Suc 0) 2)\n                                   (task_s\n                                    (CHR ''t'' := task_s CHR ''t'' + d, CHR ''c'' := task_s CHR ''c'' + d)))\"\n                           tr1])\n                           apply simp\n                       subgoal for v1 tr1'\n                         apply simp\n                         apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                                 \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(free_ch 2)\" \"{0}\" \n                                                 \"(\\<lambda>v d. if p \\<noteq> []\n                                                      then out_0assm_assn (run_ch (run_now (sched_get_max (Sch p rn rp) s))) 0\n                                                            (sched_assn' kk' (sched_get_max (Sch p rn rp) s) s)\n                                                      else sched_assn' kk' (sched_clear (Sch p rn rp) s) s)\" tr2])\n                         subgoal  by auto\n                         subgoal for v2 tr2'\n                           apply auto\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                           by(auto simp add: true_assn_def)\n                         subgoal for v2 d2 tr2'\n                           by (auto elim!: sync_elims) \n                         subgoal for v2 tr2'\n                           apply auto\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                           by auto\n                         subgoal for v2 d2 tr2'\n                           by (auto elim!: sync_elims) \n                         done\n                       subgoal for d1 v1 tr1'\n                         apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                                 \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(free_ch 2)\" \"{0}\" \n                                                 \"(\\<lambda>v d. if p \\<noteq> []\n                                                      then out_0assm_assn (run_ch (run_now (sched_get_max (Sch p rn rp) s))) 0\n                                                            (sched_assn' kk' (sched_get_max (Sch p rn rp) s) s)\n                                                      else sched_assn' kk' (sched_clear (Sch p rn rp) s) s)\" tr2])\n                         subgoal  by auto\n                         subgoal for v2 tr2'\n                           apply auto\n                           apply(elim combine_blocks_unpairE3')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                           by(auto simp add: true_assn_def)\n                         subgoal for v2 d2 tr2'\n                           apply auto\n                           apply(cases \"d1<d2\")\n                           subgoal\n                             apply(elim combine_blocks_waitE3)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             by (auto elim!: sync_elims) \n                           apply(cases \"d1>d2\")\n                           subgoal\n                             apply(elim combine_blocks_waitE4)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(elim combine_blocks_unpairE3')\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                             by(auto simp add: true_assn_def)\n                           apply auto\n                           apply(elim combine_blocks_waitE2)\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                           by(auto simp add: true_assn_def)\n                         subgoal for v2 tr2'\n                           apply auto\n                           apply(elim combine_blocks_unpairE3')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                           by(auto simp add: true_assn_def)\n                         subgoal for d2 v2 tr2'\n                           apply auto\n                           apply(cases \"d1<d2\")\n                           subgoal\n                             apply(elim combine_blocks_waitE3)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             by (auto elim!: sync_elims) \n                           apply(cases \"d1>d2\")\n                           subgoal\n                             apply(elim combine_blocks_waitE4)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(elim combine_blocks_unpairE3')\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                             by(auto simp add: true_assn_def)\n                           apply auto\n                           apply(elim combine_blocks_waitE2)\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                           by(auto simp add: true_assn_def)\n                         done\n                       subgoal for v1 tr1'\n                         apply simp\n                         apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                                 \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(free_ch 2)\" \"{0}\" \n                                                 \"(\\<lambda>v d. if p \\<noteq> []\n                                                      then out_0assm_assn (run_ch (run_now (sched_get_max (Sch p rn rp) s))) 0\n                                                            (sched_assn' kk' (sched_get_max (Sch p rn rp) s) s)\n                                                      else sched_assn' kk' (sched_clear (Sch p rn rp) s) s)\" tr2])\n                         subgoal  by auto\n                         subgoal for v2 tr2'\n                           apply auto\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                           by(auto simp add: true_assn_def)\n                         subgoal for v2 d2 tr2'\n                           by (auto elim!: sync_elims) \n                         subgoal for v2 tr2'\n                           apply auto\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                           by auto\n                         subgoal for v2 d2 tr2'\n                           by (auto elim!: sync_elims) \n                         done\n                       subgoal for d1 v1 tr1'\n                         apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                                 \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(free_ch 2)\" \"{0}\" \n                                                 \"(\\<lambda>v d. if p \\<noteq> []\n                                                      then out_0assm_assn (run_ch (run_now (sched_get_max (Sch p rn rp) s))) 0\n                                                            (sched_assn' kk' (sched_get_max (Sch p rn rp) s) s)\n                                                      else sched_assn' kk' (sched_clear (Sch p rn rp) s) s)\" tr2])\n                         subgoal  by auto\n                         subgoal for v2 tr2'\n                           apply auto\n                           apply(elim combine_blocks_unpairE3')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                           by(auto simp add: true_assn_def)\n                         subgoal for v2 d2 tr2'\n                           apply auto\n                           apply(cases \"d1<d2\")\n                           subgoal\n                             apply(elim combine_blocks_waitE3)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             by (auto elim!: sync_elims) \n                           apply(cases \"d1>d2\")\n                           subgoal\n                             apply(elim combine_blocks_waitE4)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(elim combine_blocks_unpairE3')\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                             by(auto simp add: true_assn_def)\n                           apply auto\n                           apply(elim combine_blocks_waitE2)\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                           by(auto simp add: true_assn_def)\n                         subgoal for v2 tr2'\n                           apply auto\n                           apply(elim combine_blocks_unpairE3')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                           by(auto simp add: true_assn_def)\n                         subgoal for d2 v2 tr2'\n                           apply auto\n                           apply(cases \"d1<d2\")\n                           subgoal\n                             apply(elim combine_blocks_waitE3)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             by (auto elim!: sync_elims) \n                           apply(cases \"d1>d2\")\n                           subgoal\n                             apply(elim combine_blocks_waitE4)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(elim combine_blocks_unpairE3')\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                             by(auto simp add: true_assn_def)\n                           apply auto\n                           apply(elim combine_blocks_waitE2)\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                           by(auto simp add: true_assn_def)\n                         done\n                       done\n                     apply(erule disjE)\n                     subgoal premises pre'\n                     apply(rule combine_blocks_assn)\n                          apply(rule pre'(4))\n                         apply(rule pre'(5))\n                        apply(rule pre'(2))\n                       apply(rule combine_waitin_tguar'_vassm'_waitin_assms'1)\n                       by auto\n                     subgoal\n                       apply(simp only: tdsch1'.simps)\n                       apply(rule disjI2)\n                       apply(rule disjI2)\n                       apply(rule disjI1)\n                       apply(cases rule:waitin_tguar'_vassm'_assn.cases[of \"{0..<min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')}\"\n                           \"(\\<lambda>t. ParState\n                                 (EState\n                                   (Task RUNNING (Suc 0) 2, task_s\n                                    (CHR ''t'' := task_s CHR ''t'' + t, CHR ''c'' := task_s CHR ''c'' + t)))\n                                 (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\"\n                           \"({}, {preempt_ch 1})\" \"(preempt_ch 1)\" \"{0}\"\n                           \"(\\<lambda>v d. task_dis_assn' 1 k' pd pc (dis_s(CHR ''t'' := dis_s CHR ''t'' + d))\n                                   (Task READY (Suc 0) 2)\n                                   (task_s\n                                    (CHR ''t'' := task_s CHR ''t'' + d, CHR ''c'' := task_s CHR ''c'' + d)))\"\n                           tr1])\n                           apply simp\n                       subgoal for v1 tr1'\n                         apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                         \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(exit_ch 2)\"\n                                         \"{0}\" \"(\\<lambda>v d. sched_assn' kk' (Sch (del_proc p 2) rn rp) s)\" tr2])\n                             apply simp\n                         subgoal for v2 tr2'\n                           apply auto\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                             apply auto\n                           subgoal for tr'\n                             apply(rule pre(1)[of \"(Suc k')\" kk' dis_s \"(Task RUNNING (Suc 0) 2)\" task_s \"(InBlock (preempt_ch 1) 0 # tr1')\"\n                                         \"(Sch (del_proc p 2) rn rp)\" \"s\" tr2' tr'])\n                             using pre properl_p4 unfolding proper_def properp_def propc_def\n                             by auto\n                           done\n                         subgoal for v2 d2 tr2'\n                           apply auto\n                           by (auto elim!: sync_elims) \n                         subgoal for v2 tr2'\n                           apply auto\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                           by auto\n                         subgoal for v2 d2 tr2'\n                           apply auto\n                           by (auto elim!: sync_elims) \n                         done\n                       subgoal for d1 v1 tr1'\n                         apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                         \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(exit_ch 2)\"\n                                         \"{0}\" \"(\\<lambda>v d. sched_assn' kk' (Sch (del_proc p 2) rn rp) s)\" tr2])\n                             apply simp\n                         subgoal for v2 tr2'\n                           apply auto\n                           apply(elim combine_blocks_unpairE3')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                             apply auto\n                           subgoal for tr'\n                             apply(rule pre(1)[of \"(Suc k')\" kk' dis_s \"(Task RUNNING (Suc 0) 2)\" task_s \n                                                \"(WaitBlk d1\n                                                       (\\<lambda>t. ParState\n                                                             (EState\n                                                               (Task RUNNING (Suc 0) 2, task_s\n                                                                (CHR ''t'' := task_s CHR ''t'' + t, CHR ''c'' := task_s CHR ''c'' + t)))\n                                                             (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\n                                                       ({}, {preempt_ch 1}) #\n                                                      InBlock (preempt_ch 1) 0 # tr1')\"\n                                                 \"(Sch (del_proc p 2) rn rp)\" \"s\" tr2' tr'])\n                             using pre properl_p4 unfolding proper_def properp_def propc_def\n                             by auto\n                           done\n                         subgoal for v2 d2 tr2'\n                           apply auto\n                           apply(cases \"d1<d2\")\n                           subgoal\n                             apply(elim combine_blocks_waitE3)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             by (auto elim!: sync_elims)\n                           apply(cases \"d1>d2\")\n                           subgoal\n                             apply(elim combine_blocks_waitE4)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(elim combine_blocks_unpairE3')\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                                apply auto\n                             subgoal for tr'\n                               apply(rule pre(1)[of \"(Suc k')\" kk' \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + d2))\" \"(Task RUNNING (Suc 0) 2)\" \"(task_s(CHR ''t'' := task_s CHR ''t'' + d2, CHR ''c'' := task_s CHR ''c'' + d2))\" \n                                                \"(WaitBlk (d1 - d2)\n                                                 (\\<lambda>t. ParState\n                                                       (EState\n                                                         (Task RUNNING (Suc 0) 2, task_s\n                                                          (CHR ''t'' := task_s CHR ''t'' + (t + d2),\n                                                           CHR ''c'' := task_s CHR ''c'' + (t + d2))))\n                                                       (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d2)))))\n                                                 ({}, {preempt_ch 1}) #\n                                                InBlock (preempt_ch 1) 0 # tr1')\"\n                                                 \"(Sch (del_proc p 2) rn rp)\" \"s\" tr2' tr'])\n                               subgoal by auto\n                               subgoal \n                                 apply simp\n                                 apply(rule disjI1)\n                                 apply(subgoal_tac\"(\\<lambda>t. ParState\n                                                   (EState\n                                                     (Task RUNNING (Suc 0) 2, task_s\n                                                      (CHR ''t'' := task_s CHR ''t'' + d2 + t,\n                                                       CHR ''c'' := task_s CHR ''c'' + d2 + t)))\n                                                   (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + d2 + t)))) = \n                                                    (\\<lambda>t. ParState\n                                                                 (EState\n                                                                   (Task RUNNING (Suc 0) 2, task_s\n                                                                    (CHR ''t'' := task_s CHR ''t'' + (t + d2),\n                                                                     CHR ''c'' := task_s CHR ''c'' + (t + d2))))\n                                                                 (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d2)))))\")\n                                  apply auto\n                                  apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                                 apply auto\n                                 apply(rule ext)\n                                 by auto\n                               subgoal by auto\n                               subgoal by auto\n                               subgoal using pre unfolding propc_def by auto\n                               subgoal using pre properl_p4 unfolding proper_def by auto\n                               subgoal by auto\n                               done\n                             done\n                           apply auto\n                           apply(elim combine_blocks_waitE2)\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                              apply auto\n                           subgoal for tr'\n                             apply(rule pre(1)[of \"(Suc k')\" kk' \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + d2))\" \"(Task RUNNING (Suc 0) 2)\" \"(task_s(CHR ''t'' := task_s CHR ''t'' + d2, CHR ''c'' := task_s CHR ''c'' + d2))\" \n                                                \"(InBlock (preempt_ch 1) 0 # tr1')\"\n                                                 \"(Sch (del_proc p 2) rn rp)\" \"s\" tr2' tr'])\n                             subgoal by auto\n                             subgoal apply simp\n                               apply(rule disjI1)\n                               apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                               by auto\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal using pre unfolding propc_def by auto\n                             subgoal using pre properl_p4 unfolding proper_def by auto\n                             subgoal by auto\n                             done\n                           done\n                         subgoal for v2 tr2'\n                           apply auto\n                           apply(elim combine_blocks_unpairE3')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                             by auto\n                         subgoal for d2 v2 tr2'\n                           apply auto\n                           apply(cases \"d1<d2\")\n                           subgoal\n                             apply(elim combine_blocks_waitE3)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             by (auto elim!: sync_elims)\n                           apply(cases \"d1>d2\")\n                           subgoal\n                             apply(elim combine_blocks_waitE4)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(elim combine_blocks_unpairE3')\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                                by auto\n                           apply auto\n                           apply(elim combine_blocks_waitE2)\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                           by auto\n                         done\n                       subgoal for v1 tr1'\n                         apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                         \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(exit_ch 2)\"\n                                         \"{0}\" \"(\\<lambda>v d. sched_assn' kk' (Sch (del_proc p 2) rn rp) s)\" tr2])\n                             apply simp\n                         subgoal for v2 tr2'\n                           apply auto\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                             apply auto\n                           subgoal for tr'\n                             apply(rule pre(1)[of \"(Suc k')\" kk' dis_s \"(Task RUNNING (Suc 0) 2)\" task_s \"(InBlock (preempt_ch 1) v1 # tr1')\"\n                                         \"(Sch (del_proc p 2) rn rp)\" \"s\" tr2' tr'])\n                             using pre properl_p4 unfolding proper_def properp_def propc_def\n                             by auto\n                           done\n                         subgoal for v2 d2 tr2'\n                           apply auto\n                           by (auto elim!: sync_elims) \n                         subgoal for v2 tr2'\n                           apply auto\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                           by auto\n                         subgoal for v2 d2 tr2'\n                           apply auto\n                           by (auto elim!: sync_elims) \n                         done\n                       subgoal for d1 v1 tr1'\n                         apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                         \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(exit_ch 2)\"\n                                         \"{0}\" \"(\\<lambda>v d. sched_assn' kk' (Sch (del_proc p 2) rn rp) s)\" tr2])\n                             apply simp\n                         subgoal for v2 tr2'\n                           apply auto\n                           apply(elim combine_blocks_unpairE3')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                             apply auto\n                           subgoal for tr'\n                             apply(rule pre(1)[of \"(Suc k')\" kk' dis_s \"(Task RUNNING (Suc 0) 2)\" task_s \n                                                \"(WaitBlk d1\n                                                       (\\<lambda>t. ParState\n                                                             (EState\n                                                               (Task RUNNING (Suc 0) 2, task_s\n                                                                (CHR ''t'' := task_s CHR ''t'' + t, CHR ''c'' := task_s CHR ''c'' + t)))\n                                                             (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\n                                                       ({}, {preempt_ch 1}) #\n                                                      InBlock (preempt_ch 1) v1 # tr1')\"\n                                                 \"(Sch (del_proc p 2) rn rp)\" \"s\" tr2' tr'])\n                             using pre properl_p4 unfolding proper_def properp_def propc_def\n                             by auto\n                           done\n                         subgoal for v2 d2 tr2'\n                           apply auto\n                           apply(cases \"d1<d2\")\n                           subgoal\n                             apply(elim combine_blocks_waitE3)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             by (auto elim!: sync_elims)\n                           apply(cases \"d1>d2\")\n                           subgoal\n                             apply(elim combine_blocks_waitE4)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(elim combine_blocks_unpairE3')\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                                apply auto\n                             subgoal for tr'\n                               apply(rule pre(1)[of \"(Suc k')\" kk' \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + d2))\" \"(Task RUNNING (Suc 0) 2)\" \"(task_s(CHR ''t'' := task_s CHR ''t'' + d2, CHR ''c'' := task_s CHR ''c'' + d2))\" \n                                                \"(WaitBlk (d1 - d2)\n                                                 (\\<lambda>t. ParState\n                                                       (EState\n                                                         (Task RUNNING (Suc 0) 2, task_s\n                                                          (CHR ''t'' := task_s CHR ''t'' + (t + d2),\n                                                           CHR ''c'' := task_s CHR ''c'' + (t + d2))))\n                                                       (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d2)))))\n                                                 ({}, {preempt_ch 1}) #\n                                                InBlock (preempt_ch 1) v1 # tr1')\"\n                                                 \"(Sch (del_proc p 2) rn rp)\" \"s\" tr2' tr'])\n                               subgoal by auto\n                               subgoal \n                                 apply simp\n                                 apply(rule disjI1)\n                                 apply(subgoal_tac\"(\\<lambda>t. ParState\n                                                   (EState\n                                                     (Task RUNNING (Suc 0) 2, task_s\n                                                      (CHR ''t'' := task_s CHR ''t'' + d2 + t,\n                                                       CHR ''c'' := task_s CHR ''c'' + d2 + t)))\n                                                   (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + d2 + t)))) = \n                                                    (\\<lambda>t. ParState\n                                                                 (EState\n                                                                   (Task RUNNING (Suc 0) 2, task_s\n                                                                    (CHR ''t'' := task_s CHR ''t'' + (t + d2),\n                                                                     CHR ''c'' := task_s CHR ''c'' + (t + d2))))\n                                                                 (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d2)))))\")\n                                  apply auto\n                                  apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                                 apply auto\n                                 apply(rule ext)\n                                 by auto\n                               subgoal by auto\n                               subgoal by auto\n                               subgoal using pre unfolding propc_def by auto\n                               subgoal using pre properl_p4 unfolding proper_def by auto\n                               subgoal by auto\n                               done\n                             done\n                           apply auto\n                           apply(elim combine_blocks_waitE2)\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                              apply auto\n                           subgoal for tr'\n                             apply(rule pre(1)[of \"(Suc k')\" kk' \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + d2))\" \"(Task RUNNING (Suc 0) 2)\" \"(task_s(CHR ''t'' := task_s CHR ''t'' + d2, CHR ''c'' := task_s CHR ''c'' + d2))\" \n                                                \"(InBlock (preempt_ch 1) v1 # tr1')\"\n                                                 \"(Sch (del_proc p 2) rn rp)\" \"s\" tr2' tr'])\n                             subgoal by auto\n                             subgoal apply simp\n                               apply(rule disjI1)\n                               apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                               by auto\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal using pre unfolding propc_def by auto\n                             subgoal using pre properl_p4 unfolding proper_def by auto\n                             subgoal by auto\n                             done\n                           done\n                         subgoal for v2 tr2'\n                           apply auto\n                           apply(elim combine_blocks_unpairE3')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                             by auto\n                         subgoal for d2 v2 tr2'\n                           apply auto\n                           apply(cases \"d1<d2\")\n                           subgoal\n                             apply(elim combine_blocks_waitE3)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             by (auto elim!: sync_elims)\n                           apply(cases \"d1>d2\")\n                           subgoal\n                             apply(elim combine_blocks_waitE4)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(elim combine_blocks_unpairE3')\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                                by auto\n                           apply auto\n                           apply(elim combine_blocks_waitE2)\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                           by auto\n                         done\n                       done\n                     done\n                   apply(simp del:tdsch1'.simps)\n                   apply(erule disjE)\n                   subgoal\n                     apply(cases rule: wait_orig_assn.cases[of \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"\n                                                               \"(\\<lambda>t. ParState\n                                                                     (EState\n                                                                       (Task RUNNING (Suc 0) 2, task_s\n                                                                        (CHR ''t'' := task_s CHR ''t'' + t, CHR ''c'' := task_s CHR ''c'' + t)))\n                                                                     (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\"\n                                                               \"({}, {preempt_ch 1})\"\n                                                               \"(out_0assm_srdy_assn (free_ch 1) 0 ({free_ch 1}, {preempt_ch 1})\n                                                                 (task_dis_assn' 1 k' pd pc\n                                                                   (dis_s\n                                                                    (CHR ''t'' :=\n                                                                       dis_s CHR ''t'' +\n                                                                       min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                                                   (Task WAIT (Suc 0) 2)\n                                                                   (task_s\n                                                                    (CHR ''t'' :=\n                                                                       task_s CHR ''t'' +\n                                                                       min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                                                     CHR ''c'' :=\n                                                                       task_s CHR ''c'' +\n                                                                       min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))))\" tr1])\n                       apply simp\n                     subgoal\n                       apply(cases rule: out_0assm_srdy_assn.cases[of \"(free_ch 1)\" 0 \"({free_ch 1}, {preempt_ch 1})\"\n                                       \"(task_dis_assn' 1 k' pd pc\n                                         (dis_s\n                                          (CHR ''t'' :=\n                                             dis_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                         (Task WAIT (Suc 0) 2)\n                                         (task_s\n                                          (CHR ''t'' :=\n                                             task_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                           CHR ''c'' :=\n                                             task_s CHR ''c'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))))\"tr1])\n                         apply simp\n                       subgoal for tr1'\n                         apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                   \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(req_ch 1)\"\n                                   \"{2}\"\n                                   \"(\\<lambda>v d. if v \\<le> rp\n                                          then sched_assn' kk' (sched_push 1 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                (s(CHR ''p'' := v))\n                                          else if rn \\<noteq> - 1\n                                               then out_0assm_assn (preempt_ch rn) 0\n                                                     (out_0assm_assn (run_ch 1) 0\n                                                       (sched_assn' kk'\n                                                         (sched_assign 1 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                         (s(CHR ''p'' := v))))\n                                               else out_0assm_assn (run_ch 1) 0\n                                                     (sched_assn' kk'\n                                                       (sched_assign 1 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                       (s(CHR ''p'' := v))))\"tr2])\n                             apply simp\n                         subgoal for v2 tr2'\n                           apply (simp del: tdsch1'.simps)\n                           apply(elim combine_blocks_pairE)\n                           by auto\n                         subgoal for v2 d2 tr2'\n                           apply (simp del: tdsch1'.simps)\n                           by (auto elim!: sync_elims)\n                         subgoal for v2 tr2'\n                           apply (simp del: tdsch1'.simps)\n                           apply(elim combine_blocks_pairE)\n                           by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         subgoal for v2 d2 tr2'\n                           apply (simp del: tdsch1'.simps)\n                           by (auto elim!: sync_elims)\n                         done\n                       subgoal for d1 rdy1 p1 tr1'\n                         apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                   \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(req_ch 1)\"\n                                   \"{2}\"\n                                   \"(\\<lambda>v d. if v \\<le> rp\n                                          then sched_assn' kk' (sched_push 1 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                (s(CHR ''p'' := v))\n                                          else if rn \\<noteq> - 1\n                                               then out_0assm_assn (preempt_ch rn) 0\n                                                     (out_0assm_assn (run_ch 1) 0\n                                                       (sched_assn' kk'\n                                                         (sched_assign 1 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                         (s(CHR ''p'' := v))))\n                                               else out_0assm_assn (run_ch 1) 0\n                                                     (sched_assn' kk'\n                                                       (sched_assign 1 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                       (s(CHR ''p'' := v))))\"tr2])\n                             apply simp\n                         subgoal for v2 tr2'\n                           apply auto\n                           by (auto elim!: sync_elims)\n                         subgoal for v2 d2 tr2'\n                           apply (simp del: tdsch1'.simps)\n                           apply(elim combine_blocks_waitE1)\n                           apply(cases rdy1)\n                           by auto\n                         subgoal for v2 tr2'\n                           apply auto\n                           by (auto elim!: sync_elims)\n                         subgoal for d2 v2 tr2'\n                           apply (simp del: tdsch1'.simps)\n                           apply(elim combine_blocks_waitE1)\n                           apply(cases rdy1)\n                           by auto\n                         done\n                       done\n                     subgoal for tr1'\n                     apply(cases rule: out_0assm_srdy_assn.cases[of \"(free_ch 1)\" 0 \"({free_ch 1}, {preempt_ch 1})\"\n                                       \"(task_dis_assn' 1 k' pd pc\n                                         (dis_s\n                                          (CHR ''t'' :=\n                                             dis_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                         (Task WAIT (Suc 0) 2)\n                                         (task_s\n                                          (CHR ''t'' :=\n                                             task_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                           CHR ''c'' :=\n                                             task_s CHR ''c'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))))\" tr1'])\n                         apply simp\n                       subgoal for tr1''\n                         apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                   \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(req_ch 1)\"\n                                   \"{2}\"\n                                   \"(\\<lambda>v d. if v \\<le> rp\n                                          then sched_assn' kk' (sched_push 1 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                (s(CHR ''p'' := v))\n                                          else if rn \\<noteq> - 1\n                                               then out_0assm_assn (preempt_ch rn) 0\n                                                     (out_0assm_assn (run_ch 1) 0\n                                                       (sched_assn' kk'\n                                                         (sched_assign 1 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                         (s(CHR ''p'' := v))))\n                                               else out_0assm_assn (run_ch 1) 0\n                                                     (sched_assn' kk'\n                                                       (sched_assign 1 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                       (s(CHR ''p'' := v))))\"tr2])\n                             apply simp\n                         subgoal for v2 tr2'\n                           apply auto\n                           by (auto elim!: sync_elims)\n                         subgoal for v2 d2 tr2'\n                           apply (simp del: tdsch1'.simps)\n                           apply(cases \"d2 < (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                           subgoal\n                             apply(elim combine_blocks_waitE4)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             by (auto elim!: sync_elims)\n                           apply(cases \"d2 > (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                           subgoal\n                             apply(elim combine_blocks_waitE3)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             by (auto elim!: sync_elims)\n                           apply(cases \"d2 = (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                           subgoal\n                             apply simp\n                             apply(elim combine_blocks_waitE2)\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply(elim combine_blocks_pairE)\n                             by auto\n                           by auto\n                         subgoal for v2 tr2'\n                           apply auto\n                           by (auto elim!: sync_elims)\n                         subgoal for d2 v2 tr2'\n                           apply (simp del: tdsch1'.simps)\n                           apply(cases \"d2 < (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                           subgoal\n                             apply(elim combine_blocks_waitE4)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             by (auto elim!: sync_elims)\n                           apply(cases \"d2 > (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                           subgoal\n                             apply(elim combine_blocks_waitE3)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             by (auto elim!: sync_elims)\n                           apply(cases \"d2 = (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                           subgoal\n                             apply simp\n                             apply(elim combine_blocks_waitE2)\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply(elim combine_blocks_pairE)\n                             by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           by auto\n                         done\n                       subgoal for d1 rdy1 p1 tr1''\n                         apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                   \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(req_ch 1)\"\n                                   \"{2}\"\n                                   \"(\\<lambda>v d. if v \\<le> rp\n                                          then sched_assn' kk' (sched_push 1 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                (s(CHR ''p'' := v))\n                                          else if rn \\<noteq> - 1\n                                               then out_0assm_assn (preempt_ch rn) 0\n                                                     (out_0assm_assn (run_ch 1) 0\n                                                       (sched_assn' kk'\n                                                         (sched_assign 1 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                         (s(CHR ''p'' := v))))\n                                               else out_0assm_assn (run_ch 1) 0\n                                                     (sched_assn' kk'\n                                                       (sched_assign 1 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                       (s(CHR ''p'' := v))))\"tr2])\n                             apply simp\n                         subgoal for v2 tr2'\n                           apply auto\n                           by (auto elim!: sync_elims)\n                         subgoal for v2 d2 tr2'\n                           apply (simp del: tdsch1'.simps)\n                           apply(cases \"d2 < (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                           subgoal\n                             apply(elim combine_blocks_waitE4)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             by (auto elim!: sync_elims)\n                           apply(cases \"d2 > (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                           subgoal\n                             apply(elim combine_blocks_waitE3[of \"{req_ch 1, preempt_ch 1, run_ch 1, free_ch 1, exit_ch 1}\" \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"])\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply(elim combine_blocks_waitE1)\n                             apply(cases rdy1)\n                             by auto\n                           apply(cases \"d2 = (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                           subgoal\n                             apply(simp del: tdsch1'.simps)\n                             apply(elim combine_blocks_waitE2)\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             by (auto elim!: sync_elims)\n                           by auto\n                         subgoal for v2 tr2'\n                           apply auto\n                           by (auto elim!: sync_elims)\n                         subgoal for d2 v2 tr2'\n                           apply (simp del: tdsch1'.simps)\n                           apply(cases \"d2 < (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                           subgoal\n                             apply(elim combine_blocks_waitE4)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             by (auto elim!: sync_elims)\n                           apply(cases \"d2 > (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                           subgoal\n                             apply(elim combine_blocks_waitE3[of \"{req_ch 1, preempt_ch 1, run_ch 1, free_ch 1, exit_ch 1}\" \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"])\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply(elim combine_blocks_waitE1)\n                             apply(cases rdy1)\n                             by auto\n                           apply(cases \"d2 = (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                           subgoal\n                             apply(simp del: tdsch1'.simps)\n                             apply(elim combine_blocks_waitE2)\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             by (auto elim!: sync_elims)\n                           by auto\n                         done\n                       done\n                     done\n                   apply(erule disjE)\n                   subgoal\n                     apply(cases rule:wait_orig_assn.cases[of \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"\n                                   \"(\\<lambda>t. ParState\n                                         (EState\n                                           (Task RUNNING (Suc 0) 2, task_s\n                                            (CHR ''t'' := task_s CHR ''t'' + t, CHR ''c'' := task_s CHR ''c'' + t)))\n                                         (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\"\n                                   \"({}, {preempt_ch 1})\"\n                                   \"(out_0assm_srdy_assn (free_ch 1) 0 ({free_ch 1}, {preempt_ch 1})\n                                     (task_dis_assn' 1 k' pd pc\n                                       (dis_s\n                                        (CHR ''t'' :=\n                                           dis_s CHR ''t'' +\n                                           min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                       (Task WAIT (Suc 0) 2)\n                                       (task_s\n                                        (CHR ''t'' :=\n                                           task_s CHR ''t'' +\n                                           min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                         CHR ''c'' :=\n                                           task_s CHR ''c'' +\n                                           min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))))\" tr1])\n                       apply simp\n                     subgoal\n                       apply(cases rule: out_0assm_srdy_assn.cases[of \"(free_ch 1)\" 0 \"({free_ch 1}, {preempt_ch 1})\"\n                                       \"(task_dis_assn' 1 k' pd pc\n                                         (dis_s\n                                          (CHR ''t'' :=\n                                             dis_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                         (Task WAIT (Suc 0) 2)\n                                         (task_s\n                                          (CHR ''t'' :=\n                                             task_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                           CHR ''c'' :=\n                                             task_s CHR ''c'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))))\" tr1])\n                         apply simp\n                       subgoal for tr1'\n                         apply(cases rule:waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                         \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(req_ch 2)\"\n                                         \"{1}\"\n                                         \"(\\<lambda>v d. if v \\<le> rp\n                                                then sched_assn' kk' (sched_push 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                      (s(CHR ''p'' := v))\n                                                else if rn \\<noteq> - 1\n                                                     then out_0assm_assn (preempt_ch rn) 0\n                                                           (out_0assm_assn (run_ch 2) 0\n                                                             (sched_assn' kk'\n                                                               (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                               (s(CHR ''p'' := v))))\n                                                     else out_0assm_assn (run_ch 2) 0\n                                                           (sched_assn' kk'\n                                                             (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                             (s(CHR ''p'' := v))))\" tr2])\n                             apply simp\n                         subgoal for v2 tr2'\n                           apply(simp del: tdsch1'.simps)\n                           apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                            prefer 2\n                           subgoal using pre unfolding proper_def propc_def properp_def by auto\n                           apply(simp del: tdsch1'.simps)\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           subgoal for tr'\n                             apply (simp only: tdsch1'.simps)\n                             apply(rule disjI1)\n                             apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                               apply auto\n                             apply(rule pre(1)[of \"(Suc k')\" kk' dis_s \"(Task RUNNING (Suc 0) 2)\" task_s \"(OutBlock (free_ch 1) 0 # tr1')\" \"(Sch (p @ [(1, 2)]) 1 2)\"\n                                            \"(s(CHR ''p'' := 1))\" tr2' tr'])\n                             using pre properl_p1\n                             unfolding propc_def proper_def properp_def by auto\n                           done\n                         subgoal for v2 d2 tr2'\n                           apply(simp del: tdsch1'.simps)\n                           apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                            prefer 2\n                           subgoal using pre unfolding proper_def propc_def properp_def by auto\n                           apply(simp del: tdsch1'.simps)\n                           by (auto elim!: sync_elims)\n                         subgoal for v2 tr2'\n                           apply(simp del: tdsch1'.simps)\n                           apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                            prefer 2\n                           subgoal using pre unfolding proper_def propc_def properp_def by auto\n                           apply(simp del: tdsch1'.simps)\n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           subgoal for tr'\n                             apply (simp only: tdsch1'.simps)\n                             apply(rule disjI1)\n                             apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                             by auto\n                           done\n                         subgoal for d2 v2 tr2'\n                           apply(simp del: tdsch1'.simps)\n                           apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                            prefer 2\n                           subgoal using pre unfolding proper_def propc_def properp_def by auto\n                           apply(simp del: tdsch1'.simps)\n                           by (auto elim!: sync_elims)\n                         done\n                       subgoal for d1 rdy1 p1 tr1'\n                         apply(cases rule:waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                         \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(req_ch 2)\"\n                                         \"{1}\"\n                                         \"(\\<lambda>v d. if v \\<le> rp\n                                                then sched_assn' kk' (sched_push 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                      (s(CHR ''p'' := v))\n                                                else if rn \\<noteq> - 1\n                                                     then out_0assm_assn (preempt_ch rn) 0\n                                                           (out_0assm_assn (run_ch 2) 0\n                                                             (sched_assn' kk'\n                                                               (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                               (s(CHR ''p'' := v))))\n                                                     else out_0assm_assn (run_ch 2) 0\n                                                           (sched_assn' kk'\n                                                             (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                             (s(CHR ''p'' := v))))\" tr2])\n                             apply simp\n                         subgoal for v2 tr2'\n                           apply(simp del: tdsch1'.simps)\n                           apply(elim combine_blocks_unpairE3')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                           prefer 2\n                           subgoal using pre unfolding proper_def propc_def properp_def by auto\n                           apply (simp only: tdsch1'.simps)\n                           apply(rule disjI1)\n                           apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                             apply auto\n                           subgoal for tr'\n                             apply(rule pre(1)[of \"(Suc k')\" kk' dis_s \"(Task RUNNING (Suc 0) 2)\" task_s \"(WaitBlk d1 p1 rdy1 # tr1')\"\n                                          \"(Sch (p @ [(1, 2)]) 1 2)\" \"(s(CHR ''p'' := 1))\" tr2' tr'])\n                             using pre properl_p1 unfolding proper_def properp_def propc_def by auto\n                           done\n                         subgoal for v2 d2 tr2'\n                           apply(simp del: tdsch1'.simps)\n                           apply(elim combine_blocks_waitE1)\n                           apply(cases rdy1)\n                           by auto\n                         subgoal for v2 tr2'\n                           apply(simp del: tdsch1'.simps)\n                           apply(elim combine_blocks_unpairE3')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                           prefer 2\n                           subgoal using pre unfolding proper_def propc_def properp_def by auto\n                           apply (simp only: tdsch1'.simps)\n                           apply(rule disjI1)\n                           apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                           by auto\n                         subgoal for d2 v2 tr2'\n                           apply(simp del: tdsch1'.simps)\n                           apply(elim combine_blocks_waitE1)\n                           apply(cases rdy1)\n                           by auto\n                         done\n                       done\n                     subgoal for tr1'\n                       apply(cases rule: out_0assm_srdy_assn.cases[of \"(free_ch 1)\" 0 \"({free_ch 1}, {preempt_ch 1})\"\n                                       \"(task_dis_assn' 1 k' pd pc\n                                         (dis_s\n                                          (CHR ''t'' :=\n                                             dis_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                         (Task WAIT (Suc 0) 2)\n                                         (task_s\n                                          (CHR ''t'' :=\n                                             task_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                           CHR ''c'' :=\n                                             task_s CHR ''c'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))))\" tr1'])\n                         apply simp\n                       subgoal for tr1''\n                         apply(cases rule:waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                         \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(req_ch 2)\"\n                                         \"{1}\"\n                                         \"(\\<lambda>v d. if v \\<le> rp\n                                                then sched_assn' kk' (sched_push 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                      (s(CHR ''p'' := v))\n                                                else if rn \\<noteq> - 1\n                                                     then out_0assm_assn (preempt_ch rn) 0\n                                                           (out_0assm_assn (run_ch 2) 0\n                                                             (sched_assn' kk'\n                                                               (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                               (s(CHR ''p'' := v))))\n                                                     else out_0assm_assn (run_ch 2) 0\n                                                           (sched_assn' kk'\n                                                             (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                             (s(CHR ''p'' := v))))\" tr2])\n                             apply simp\n                         subgoal for v2 tr2'\n                           apply(simp del: tdsch1'.simps)\n                           apply(elim combine_blocks_unpairE3')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                           prefer 2\n                           subgoal using pre unfolding proper_def propc_def properp_def by auto\n                           apply (simp only: tdsch1'.simps)\n                           apply(rule disjI1)\n                           apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                             apply auto\n                           subgoal for tr'\n                             apply(rule pre(1)[of \"(Suc k')\" kk' dis_s \"(Task RUNNING (Suc 0) 2)\" task_s \"tr1\"\n                                          \"(Sch (p @ [(1, 2)]) 1 2)\" \"(s(CHR ''p'' := 1))\" tr2' tr'])\n                             using pre properl_p1 unfolding proper_def properp_def propc_def by auto\n                           done\n                         subgoal for v2 d2 tr2'\n                           apply(simp del: tdsch1'.simps)\n                           apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                           prefer 2\n                           subgoal using pre unfolding proper_def propc_def properp_def by auto\n                           apply (simp only: tdsch1'.simps)\n                           apply(rule disjI1)\n                           apply(cases \"d2>(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                           subgoal\n                             apply(elim combine_blocks_waitE3)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             by (auto elim!: sync_elims)\n                           apply(cases \"d2<(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                           subgoal\n                             apply(elim combine_blocks_waitE4)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(elim combine_blocks_unpairE3')\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             subgoal for tr'\n                               apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                                  apply auto\n                               apply(rule pre(1)[of \"(Suc k')\" kk' \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + d2))\" \"(Task RUNNING (Suc 0) 2)\"\n                                               \"(task_s(CHR ''t'' := task_s CHR ''t'' + d2, CHR ''c'' := task_s CHR ''c'' + d2))\"\n                                               \"(WaitBlk (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'') - d2)\n                                                 (\\<lambda>t. ParState\n                                                       (EState\n                                                         (Task RUNNING (Suc 0) 2, task_s\n                                                          (CHR ''t'' := task_s CHR ''t'' + (t + d2),\n                                                           CHR ''c'' := task_s CHR ''c'' + (t + d2))))\n                                                       (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d2)))))\n                                                 ({}, {preempt_ch 1}) #\n                                                OutBlock (free_ch 1) 0 # tr1'')\"\n                                                \"(Sch (p @ [(1, 2)]) 1 2)\" \"(s(CHR ''p'' := 1))\" tr2' tr'])\n                               subgoal by auto\n                               subgoal premises pre' \n                                 apply simp\n                                 apply(rule disjI2)\n                                 apply(subgoal_tac \"(min (pd - (task_s CHR ''t'' + d2)) (pc - (task_s CHR ''c'' + d2))) = (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'') - d2)\")\n                                 apply(subgoal_tac \"(\\<lambda>t. ParState\n                                                     (EState\n                                                       (Task RUNNING (Suc 0) 2, task_s\n                                                        (CHR ''t'' := task_s CHR ''t'' + d2 + t,\n                                                         CHR ''c'' := task_s CHR ''c'' + d2 + t)))\n                                                     (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + d2 + t))))\n                                                  = (\\<lambda>t. ParState\n                                                     (EState\n                                                       (Task RUNNING (Suc 0) 2, task_s\n                                                        (CHR ''t'' := task_s CHR ''t'' + (t + d2),\n                                                         CHR ''c'' := task_s CHR ''c'' + (t + d2))))\n                                                     (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d2)))))\")\n                                  apply auto\n                                  apply(rule wait_orig_assn.intros(2))\n                                   apply(rule out_0assm_srdy_assn.intros(1))\n                                 subgoal using pre' by auto\n                                 subgoal using pre' by auto\n                                 apply(rule ext)\n                                 by auto\n                               subgoal by auto\n                               subgoal by auto\n                               subgoal unfolding propc_def by auto\n                               subgoal using pre properl_p1 unfolding proper_def properp_def \n                                 by auto\n                               subgoal  by auto\n                               done\n                             done\n                           apply(cases \"d2 = (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                           subgoal apply auto\n                             apply(elim combine_blocks_waitE2)\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(elim combine_blocks_unpairE1')\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             subgoal for tr'\n                               apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                                  apply auto\n                               apply(rule pre(1)[of \"(Suc k')\" kk' \"(dis_s\n                                          (CHR ''t'' :=dis_s CHR ''t'' +\n                                           min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\" \n                                         \"(Task RUNNING (Suc 0) 2)\"\n                                         \"(task_s\n                                          (CHR ''t'' :=\n                                             task_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                           CHR ''c'' :=\n                                             task_s CHR ''c'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\"\n                                               \"OutBlock (free_ch 1) 0 # tr1''\"\n                                                \"(Sch (p @ [(1, 2)]) 1 2)\" \"(s(CHR ''p'' := 1))\" tr2' tr'])\n                               subgoal by auto\n                               subgoal premises pre'\n                                 apply simp\n                                 apply(rule disjI2)\n                                 apply(subgoal_tac\"(min (pd -\n                                         (task_s CHR ''t'' +\n                                          min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                     (pc -\n                                      (task_s CHR ''c'' +\n                                       min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))) = 0\")\n                                  apply auto\n                                 apply(rule wait_orig_assn.intros(1))\n                                  apply auto\n                                 apply(rule out_0assm_srdy_assn.intros(1))\n                                 using pre' by auto\n                               subgoal by auto\n                               subgoal by auto\n                               subgoal unfolding propc_def by auto\n                               subgoal using pre properl_p1 unfolding proper_def properp_def \n                                 by auto\n                               subgoal  by auto\n                               done\n                             done\n                           by auto\n                         subgoal for v2 tr2'\n                           apply(simp del: tdsch1'.simps)\n                           apply(elim combine_blocks_unpairE3')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                           prefer 2\n                           subgoal using pre unfolding proper_def propc_def properp_def by auto\n                           apply (simp only: tdsch1'.simps)\n                           apply(rule disjI1)\n                           apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                           by auto\n                         subgoal for d2 v2 tr2'\n                           apply(simp del: tdsch1'.simps)\n                           apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                           prefer 2\n                           subgoal using pre unfolding proper_def propc_def properp_def by auto\n                           apply (simp only: tdsch1'.simps)\n                           apply(rule disjI1)\n                           apply(cases \"d2>(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                           subgoal\n                             apply(elim combine_blocks_waitE3)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             by (auto elim!: sync_elims)\n                           apply(cases \"d2<(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                           subgoal\n                             apply(elim combine_blocks_waitE4)\n                             subgoal by auto\n                             subgoal by auto\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(elim combine_blocks_unpairE3')\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             subgoal for tr'\n                               apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                             by auto\n                           done\n                         apply(cases \"d2=(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                         subgoal\n                           apply auto\n                           apply(elim combine_blocks_waitE2)\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto  \n                           apply(elim combine_blocks_unpairE1')\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           subgoal for tr'\n                               apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                             by auto\n                           done\n                         by auto\n                       done\n                     subgoal for d1 rdy1 p1 tr1''\n                       apply(cases rule:waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                         \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(req_ch 2)\"\n                                         \"{1}\"\n                                         \"(\\<lambda>v d. if v \\<le> rp\n                                                then sched_assn' kk' (sched_push 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                      (s(CHR ''p'' := v))\n                                                else if rn \\<noteq> - 1\n                                                     then out_0assm_assn (preempt_ch rn) 0\n                                                           (out_0assm_assn (run_ch 2) 0\n                                                             (sched_assn' kk'\n                                                               (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                               (s(CHR ''p'' := v))))\n                                                     else out_0assm_assn (run_ch 2) 0\n                                                           (sched_assn' kk'\n                                                             (sched_assign 2 (Sch p rn rp) (s(CHR ''p'' := v)))\n                                                             (s(CHR ''p'' := v))))\" tr2])\n                           apply simp\n                       subgoal for v2 tr2'\n                         apply(simp del: tdsch1'.simps)\n                         apply(elim combine_blocks_unpairE3')\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                         prefer 2\n                         subgoal using pre unfolding proper_def propc_def properp_def by auto\n                         apply (simp only: tdsch1'.simps)\n                         apply(rule disjI1)\n                         apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                             apply auto\n                           subgoal for tr'\n                             apply(rule pre(1)[of \"(Suc k')\" kk' dis_s \"(Task RUNNING (Suc 0) 2)\" task_s \"tr1\"\n                                          \"(Sch (p @ [(1, 2)]) 1 2)\" \"(s(CHR ''p'' := 1))\" tr2' tr'])\n                             using pre properl_p1 unfolding proper_def properp_def propc_def \n                           by auto\n                         done\n                       subgoal for v2 d2 tr2'\n                         apply(simp del: tdsch1'.simps)\n                         apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                         prefer 2\n                         subgoal using pre unfolding proper_def propc_def properp_def by auto\n                         apply (simp only: tdsch1'.simps)\n                         apply(rule disjI1)\n                         apply(cases \"d2>(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                         subgoal\n                           apply(elim combine_blocks_waitE3[of \"{req_ch 1, preempt_ch 1, run_ch 1, free_ch 1, exit_ch 1}\"\n                                                              \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"])\n                           subgoal by auto\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(elim combine_blocks_waitE1)\n                           apply(cases rdy1)\n                           by auto\n                         apply(cases \"d2<(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                         subgoal\n                           apply(elim combine_blocks_waitE4[of \"{req_ch 1, preempt_ch 1, run_ch 1, free_ch 1, exit_ch 1}\"\n                                                              \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"])\n                           subgoal by auto\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(elim combine_blocks_unpairE3')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           subgoal for tr'\n                             apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                                apply auto\n                             apply(rule pre(1)[of \"(Suc k')\" kk' \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + d2))\" \"(Task RUNNING (Suc 0) 2)\"\n                                               \"(task_s(CHR ''t'' := task_s CHR ''t'' + d2, CHR ''c'' := task_s CHR ''c'' + d2))\"\n                                               \"(WaitBlk (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'') - d2)\n                                                 (\\<lambda>t. ParState\n                                                       (EState\n                                                         (Task RUNNING (Suc 0) 2, task_s\n                                                          (CHR ''t'' := task_s CHR ''t'' + (t + d2),\n                                                           CHR ''c'' := task_s CHR ''c'' + (t + d2))))\n                                                       (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d2)))))\n                                                 ({}, {preempt_ch 1}) #\n                                                WaitBlk d1 p1 rdy1 # tr1'')\"\n                                                \"(Sch (p @ [(1, 2)]) 1 2)\" \"(s(CHR ''p'' := 1))\" tr2' tr'])\n                               subgoal by auto\n                               subgoal premises pre' \n                                 apply simp\n                                 apply(rule disjI2)\n                                 apply(subgoal_tac \"(min (pd - (task_s CHR ''t'' + d2)) (pc - (task_s CHR ''c'' + d2))) = (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'') - d2)\")\n                                 apply(subgoal_tac \"(\\<lambda>t. ParState\n                                                     (EState\n                                                       (Task RUNNING (Suc 0) 2, task_s\n                                                        (CHR ''t'' := task_s CHR ''t'' + d2 + t,\n                                                         CHR ''c'' := task_s CHR ''c'' + d2 + t)))\n                                                     (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + d2 + t))))\n                                                  = (\\<lambda>t. ParState\n                                                     (EState\n                                                       (Task RUNNING (Suc 0) 2, task_s\n                                                        (CHR ''t'' := task_s CHR ''t'' + (t + d2),\n                                                         CHR ''c'' := task_s CHR ''c'' + (t + d2))))\n                                                     (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d2)))))\")\n                                  apply auto\n                                  apply(rule wait_orig_assn.intros(2))\n                                   apply(rule out_0assm_srdy_assn.intros(2))\n                                 subgoal using pre' by auto\n                                 subgoal using pre' by auto\n                                 subgoal using pre' by auto\n                                 subgoal using pre' by auto\n                                 apply(rule ext)\n                                 by auto\n                               subgoal by auto\n                               subgoal by auto\n                               subgoal unfolding propc_def by auto\n                               subgoal using pre properl_p1 unfolding proper_def properp_def \n                                 by auto\n                               subgoal  by auto\n                               done\n                             done\n                           apply(cases \"d2 = (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                           subgoal apply auto\n                             apply(elim combine_blocks_waitE2)\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(elim combine_blocks_unpairE3')\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             subgoal for tr'\n                               apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                                  apply auto\n                               apply(rule pre(1)[of \"(Suc k')\" kk' \"(dis_s\n                                          (CHR ''t'' :=dis_s CHR ''t'' +\n                                           min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\" \n                                         \"(Task RUNNING (Suc 0) 2)\"\n                                         \"(task_s\n                                          (CHR ''t'' :=\n                                             task_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                           CHR ''c'' :=\n                                             task_s CHR ''c'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\"\n                                               \"(WaitBlk d1 p1 rdy1 # tr1'')\"\n                                                \"(Sch (p @ [(1, 2)]) 1 2)\" \"(s(CHR ''p'' := 1))\" tr2' tr'])\n                               subgoal by auto\n                               subgoal premises pre'\n                                 apply simp\n                                 apply(rule disjI2)\n                                 apply(subgoal_tac\"(min (pd -\n                                         (task_s CHR ''t'' +\n                                          min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                     (pc -\n                                      (task_s CHR ''c'' +\n                                       min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))) = 0\")\n                                  apply auto\n                                 apply(rule wait_orig_assn.intros(1))\n                                  apply auto\n                                 apply(rule out_0assm_srdy_assn.intros(2))\n                                 using pre' by auto\n                               subgoal by auto\n                               subgoal by auto\n                               subgoal unfolding propc_def by auto\n                               subgoal using pre properl_p1 unfolding proper_def properp_def \n                                 by auto\n                               subgoal  by auto\n                               done\n                             done\n                           by auto\n                       subgoal for v2 tr2'\n                         apply(simp del: tdsch1'.simps)\n                         apply(elim combine_blocks_unpairE3')\n                         subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                         apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                         prefer 2\n                         subgoal using pre unfolding proper_def propc_def properp_def by auto\n                         apply (simp only: tdsch1'.simps)\n                         apply(rule disjI1)\n                         apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                             by auto\n                       subgoal for d2 v2 tr2'\n                         apply(simp del: tdsch1'.simps)\n                         apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                         prefer 2\n                         subgoal using pre unfolding proper_def propc_def properp_def by auto\n                         apply (simp only: tdsch1'.simps)\n                         apply(rule disjI1)\n                         apply(cases \"d2>(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                         subgoal\n                           apply(elim combine_blocks_waitE3[of \"{req_ch 1, preempt_ch 1, run_ch 1, free_ch 1, exit_ch 1}\"\n                                                              \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"])\n                           subgoal by auto\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(elim combine_blocks_waitE1)\n                           apply(cases rdy1)\n                           by auto\n                         apply(cases \"d2<(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                         subgoal\n                           apply(elim combine_blocks_waitE4[of \"{req_ch 1, preempt_ch 1, run_ch 1, free_ch 1, exit_ch 1}\"\n                                                              \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"])\n                           subgoal by auto\n                           subgoal by auto\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           apply(elim combine_blocks_unpairE3')\n                           subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                           apply auto\n                           subgoal for tr'\n                             apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                                by auto\n                              done\n                           apply(cases \"d2 = (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                           subgoal apply auto\n                             apply(elim combine_blocks_waitE2)\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             apply(elim combine_blocks_unpairE3')\n                             subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                             apply auto\n                             subgoal for tr'\n                               apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                                  by auto\n                                done\n                              by auto\n                            done\n                          done\n                        done\n                      apply(erule disjE)\n                      subgoal\n                        apply(cases rule: wait_orig_assn.cases[of \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"\n                                          \"(\\<lambda>t. ParState\n                                                 (EState\n                                                   (Task RUNNING (Suc 0) 2, task_s\n                                                    (CHR ''t'' := task_s CHR ''t'' + t, CHR ''c'' := task_s CHR ''c'' + t)))\n                                                 (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\"\n                                           \"({}, {preempt_ch 1})\"\n                                           \"(out_0assm_srdy_assn (free_ch 1) 0 ({free_ch 1}, {preempt_ch 1})\n                                             (task_dis_assn' 1 k' pd pc\n                                               (dis_s\n                                                (CHR ''t'' :=\n                                                   dis_s CHR ''t'' +\n                                                   min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                               (Task WAIT (Suc 0) 2)\n                                               (task_s\n                                                (CHR ''t'' :=\n                                                   task_s CHR ''t'' +\n                                                   min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                                 CHR ''c'' :=\n                                                   task_s CHR ''c'' +\n                                                   min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))))\" tr1])\n                          apply simp\n                        subgoal\n                          apply(cases rule: out_0assm_srdy_assn.cases[of \"(free_ch 1)\" 0 \"({free_ch 1}, {preempt_ch 1})\"\n                                       \"(task_dis_assn' 1 k' pd pc\n                                         (dis_s\n                                          (CHR ''t'' :=\n                                             dis_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                         (Task WAIT (Suc 0) 2)\n                                         (task_s\n                                          (CHR ''t'' :=\n                                             task_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                           CHR ''c'' :=\n                                             task_s CHR ''c'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))))\" tr1])\n                         apply simp\n                          subgoal for tr1'\n                            apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                                               \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(free_ch 1)\"\n                                                               \"{0}\"\n                                                               \"(\\<lambda>v d. if p \\<noteq> []\n                                                                      then out_0assm_assn (run_ch (run_now (sched_get_max (Sch p rn rp) s))) 0\n                                                                            (sched_assn' kk' (sched_get_max (Sch p rn rp) s) s)\n                                                                      else sched_assn' kk' (sched_clear (Sch p rn rp) s) s)\"\n                                                               tr2])\n                                apply simp\n                            subgoal for v2 tr2'\n                              apply (simp only: tdsch1'.simps)\n                              apply(rule disjI2)+\n                              apply(elim combine_blocks_pairE)\n                                apply auto\n                              subgoal\n                                apply(rule wait_orig_assn.intros(1))\n                                apply auto\n                                apply(cases k')\n                                subgoal\n                                  apply simp\n                                  apply(simp add: emp_assn_def)\n                                  apply(cases rule: out_0assm_assn.cases[of \"(run_ch (run_now (case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior)))\" 0\n                                                                                   \"(sched_assn' kk' (case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior) s)\" tr2'])\n                                    apply auto\n                                  subgoal for tr2''\n                                    apply(elim combine_blocks_emptyE'3')\n                                    subgoal\n                                      using properl_p5[of p] pre(6,10)\n                                      unfolding proper_def properp_def\n                                      apply(cases \"get_max p\")\n                                      by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                    subgoal for tr'\n                                      apply simp\n                                      apply(rule out_0assm_assn.intros(1))\n                                      apply(rule pre(1)[of 0 kk' dis_s \"(Task WAIT (Suc 0) 2)\" task_s \"[]\" \"(case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior)\" s tr2'' tr'])\n                                      subgoal by auto\n                                      subgoal by (auto simp add: emp_assn_def)\n                                      subgoal by auto\n                                      subgoal by auto\n                                      subgoal using pre unfolding propc_def by auto\n                                      subgoal using pre properl_p5[of p] properl_p4[of p] unfolding proper_def \n                                        apply(cases \"get_max p\") by auto\n                                      subgoal by auto\n                                      done\n                                    done\n                                  subgoal\n                                    by (auto elim: sync_elims)\n                                  done\n                                subgoal for k''\n                                  apply simp\n                                  apply(cases rule: wait_orig_assn.cases[of \"(pd - dis_s CHR ''t'')\"\n                                                       \"(\\<lambda>t. ParState (EState (Task WAIT (Suc 0) 2, task_s))\n                                                             (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\"\n                                                       \"({}, {dispatch_ch 1})\"\n                                                       \"(task_dis_assn' 1 k'' pd pc (dis_s(CHR ''t'' := 0)) (Task READY 0 2)\n                                                         (task_s(CHR ''t'' := 0)))\"\n                                                       tr1' ])\n                                    apply simp\n                                  subgoal\n                                    apply(cases k'')\n                                    subgoal\n                                      apply simp\n                                      apply(simp add: emp_assn_def)\n                                      apply(cases rule: out_0assm_assn.cases[of \"(run_ch (run_now (case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior)))\" 0\n                                                                                   \"(sched_assn' kk' (case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior) s)\" tr2'])\n                                        apply auto\n                                      subgoal for tr2''\n                                        apply(elim combine_blocks_emptyE'3')\n                                        subgoal\n                                          using properl_p5[of p] pre(6,10)\n                                          unfolding proper_def properp_def\n                                          apply(cases \"get_max p\")\n                                          by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                        subgoal for tr'\n                                          apply simp\n                                          apply(rule out_0assm_assn.intros(1))\n                                          subgoal premises pre'\n                                          proof-\n                                            have a:\"(dis_s CHR ''t'') = pd\" using pre' by auto\n                                            then show ?thesis\n                                              apply(subst a)\n                                              apply(rule pre(1)[of \"(Suc 0)\" kk' dis_s \"(Task WAIT (Suc 0) 2)\" task_s \"[]\" \"(case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior)\" s tr2'' tr'])\n                                              subgoal by auto\n                                              subgoal apply auto\n                                                apply(rule wait_orig_assn.intros(1))\n                                                by(auto simp add: emp_assn_def)\n                                              subgoal using pre' by auto\n                                              subgoal by auto\n                                              subgoal using pre pre' properl_p5[of p] unfolding propc_def unfolding proper_def  apply(cases \"get_max p\") by auto\n                                              subgoal using pre pre' properl_p5[of p] properl_p4[of p] unfolding proper_def \n                                            apply(cases \"get_max p\") by auto\n                                              subgoal using pre' by auto\n                                              done\n                                          qed\n                                          done\n                                        done\n                                      subgoal\n                                        by (auto elim: sync_elims)\n                                      done\n                                    subgoal for k'''\n                                      apply simp\n                                      apply(erule disjE)\n                                      subgoal premises pre'\n                                        thm pre'\n                                        apply(rule combine_blocks_assn)\n                                           apply(rule pre'(17))\n                                          apply(rule pre'(10))\n                                         apply(rule pre'(12))\n                                        apply(rule entails_tassn_trans)\n                                         apply(rule combine_out_0assm_out_0assm2')\n                                        subgoal by auto\n                                        subgoal using pre(6,10) pre' properl_p5[of p]\n                                          unfolding proper_def properp_def\n                                          apply(cases \"get_max p\")\n                                          by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                        apply(rule out_0assm_assn_tran)\n                                        unfolding entails_tassn_def combine_assn_def\n                                        apply auto\n                                        thm pre'\n                                        subgoal for Tr Tr1 Tr2\n                                          subgoal premises pre''\n                                          proof-\n                                            have a:\"(dis_s CHR ''t'') = pd\" using pre' by auto\n                                            then show ?thesis\n                                              apply(subst a)\n                                              apply(rule pre(1)[of \"(Suc (Suc k'''))\"  kk' dis_s \"(Task WAIT (Suc 0) 2)\" task_s Tr1 \n                                                \"(case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior)\" s Tr2 Tr])\n                                              subgoal using pre' by auto\n                                              subgoal apply auto\n                                                apply(rule wait_orig_assn.intros(1))\n                                                using pre' pre'' by auto\n                                              subgoal using pre'' by auto\n                                              subgoal by auto\n                                              subgoal using pre pre' properl_p5[of p] unfolding propc_def proper_def apply(cases \"get_max p\") by auto\n                                              subgoal using pre pre' properl_p5[of p] properl_p4[of p] unfolding propc_def proper_def apply(cases \"get_max p\") by auto\n                                              subgoal using pre'' by auto\n                                              done\n                                          qed\n                                      done\n                                    done\n                                      apply(erule disjE)\n                                      subgoal premises pre'\n                                        thm pre'\n                                        apply(rule combine_blocks_assn)\n                                           apply(rule pre'(17))\n                                          apply(rule pre'(10))\n                                         apply(rule pre'(12))\n                                        apply(rule entails_tassn_trans)\n                                         apply(rule combine_out_0assm_out_0assm2')\n                                        subgoal by auto\n                                        subgoal using pre(6,10) pre' properl_p5[of p]\n                                          unfolding proper_def properp_def\n                                          apply(cases \"get_max p\")\n                                          by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                        apply(rule out_0assm_assn_tran)\n                                        unfolding entails_tassn_def combine_assn_def\n                                        apply auto\n                                        subgoal for Tr Tr1 Tr2\n                                          subgoal premises pre''\n                                          proof-\n                                            have a:\"(dis_s CHR ''t'') = pd\" using pre' by auto\n                                            then show ?thesis\n                                              apply(subst a)\n                                              apply(rule pre(1)[of \"(Suc (Suc k'''))\"  kk' dis_s \"(Task WAIT (Suc 0) 2)\" task_s Tr1 \n                                                \"(case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior)\" s Tr2 Tr])\n                                              subgoal using pre' by auto\n                                              subgoal apply auto \n                                                apply(rule wait_orig_assn.intros(1))\n                                                using pre' pre'' by auto\n                                              subgoal using pre'' by auto\n                                              subgoal by auto\n                                              subgoal using pre pre' properl_p5[of p] unfolding propc_def proper_def apply(cases \"get_max p\") by auto\n                                              subgoal using pre pre' properl_p5[of p] properl_p4[of p] unfolding propc_def proper_def apply(cases \"get_max p\") by auto\n                                              subgoal using pre'' by auto\n                                              done\n                                          qed\n                                      done\n                                    done\n                                      subgoal premises pre'\n                                        thm pre'\n                                        apply(rule combine_blocks_assn)\n                                           apply(rule pre'(17))\n                                          apply(rule pre'(10))\n                                         apply(rule pre'(12))\n                                        apply(rule entails_tassn_trans)\n                                         apply(rule combine_out_0assm_out_0assm2')\n                                        subgoal by auto\n                                        subgoal using pre(6,10) pre' properl_p5[of p]\n                                          unfolding proper_def properp_def\n                                          apply(cases \"get_max p\")\n                                          by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                        apply(rule out_0assm_assn_tran)\n                                        unfolding entails_tassn_def combine_assn_def\n                                        apply auto\n                                        subgoal for Tr Tr1 Tr2\n                                          subgoal premises pre''\n                                          proof-\n                                            have a:\"(dis_s CHR ''t'') = pd\" using pre' by auto\n                                            then show ?thesis\n                                              apply(subst a)\n                                          apply(rule pre(1)[of \"(Suc (Suc k'''))\"  kk' dis_s \"(Task WAIT (Suc 0) 2)\" task_s Tr1 \n                                                \"(case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior)\" s Tr2 Tr])\n                                          subgoal using pre' by auto\n                                          subgoal apply auto\n                                            apply(rule wait_orig_assn.intros(1))\n                                            using pre' pre'' by auto\n                                          subgoal using pre'' by auto\n                                          subgoal by auto\n                                          subgoal using pre pre' properl_p5[of p] unfolding propc_def proper_def apply(cases \"get_max p\") by auto\n                                          subgoal using pre pre' properl_p5[of p] properl_p4[of p] unfolding propc_def proper_def apply(cases \"get_max p\") by auto\n                                          subgoal using pre'' by auto\n                                          done\n                                      qed\n                                        done\n                                      done\n                                    done\n                                  done\n                                  subgoal premises pre' for tr1''\n                                    thm pre'\n                                    apply(rule combine_blocks_assn)\n                                       apply(rule pre'(8))\n                                      apply(rule pre'(10))\n                                     apply(rule pre'(12))\n                                    apply(rule entails_tassn_trans)\n                                     apply(rule combine_wait_orig_out_0assm2)\n                                    subgoal using pre' by auto\n                                    subgoal using pre(6,10) pre' properl_p5[of p]\n                                    unfolding proper_def properp_def\n                                    apply(cases \"get_max p\")\n                                    by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                    apply(rule out_0assm_assn_tran)\n                                    unfolding entails_tassn_def combine_assn_def\n                                    apply auto\n                                    subgoal for Tr Tr1 Tr2\n                                      apply(rule pre(1)[of \"(Suc k'')\" kk' dis_s \"(Task WAIT (Suc 0) 2)\" task_s Tr1 \n                                            \"(case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior)\" s Tr2 Tr])\n                                      subgoal using pre' by auto\n                                      subgoal by auto\n                                      subgoal by auto\n                                      subgoal by auto\n                                      subgoal using pre pre' properl_p5[of p] unfolding propc_def proper_def apply(cases \"get_max p\") by auto\n                                      subgoal using pre pre' properl_p5[of p] properl_p4[of p] unfolding propc_def proper_def apply(cases \"get_max p\") by auto\n                                      subgoal by auto\n                                      done\n                                    done\n                                  done\n                                done\n                              subgoal \n                                apply(rule wait_orig_assn.intros(1))\n                                 apply auto\n                                apply(rule pre(1)[of k' kk' dis_s \"(Task WAIT (Suc 0) 2)\" task_s tr1' \"(Sch [] (- 1) (- 1))\" s tr2' tr])\n                                using pre\n                                by (auto simp add:proper_def propc_def properp_def)\n                              done\n                            subgoal for v2 d2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              by (auto elim!: sync_elims)\n                            subgoal for v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_pairE) \n                              by auto                           \n                            subgoal for d2 v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              by (auto elim!: sync_elims)\n                            done\n                          subgoal for d rdy pp tr1'\n                            apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                                               \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(free_ch 1)\"\n                                                               \"{0}\"\n                                                               \"(\\<lambda>v d. if p \\<noteq> []\n                                                                      then out_0assm_assn (run_ch (run_now (sched_get_max (Sch p rn rp) s))) 0\n                                                                            (sched_assn' kk' (sched_get_max (Sch p rn rp) s) s)\n                                                                      else sched_assn' kk' (sched_clear (Sch p rn rp) s) s)\"\n                                                               tr2])\n                                apply simp\n                            subgoal for v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              by (auto elim!: sync_elims)\n                            subgoal for v2 d2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_waitE1)\n                              apply(cases rdy)\n                              by auto\n                            subgoal for v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              by (auto elim!: sync_elims)\n                            subgoal for d2 v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_waitE1)\n                              apply(cases rdy)\n                              by auto\n                            done\n                          done\n                        subgoal for tr1'\n                          apply(cases rule: out_0assm_srdy_assn.cases[of \"(free_ch 1)\" 0 \"({free_ch 1}, {preempt_ch 1})\"\n                                       \"(task_dis_assn' 1 k' pd pc\n                                         (dis_s\n                                          (CHR ''t'' :=\n                                             dis_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                         (Task WAIT (Suc 0) 2)\n                                         (task_s\n                                          (CHR ''t'' :=\n                                             task_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                           CHR ''c'' :=\n                                             task_s CHR ''c'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))))\" tr1'])\n                         apply simp\n                          subgoal for tr1''\n                            apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                                               \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(free_ch 1)\"\n                                                               \"{0}\"\n                                                               \"(\\<lambda>v d. if p \\<noteq> []\n                                                                      then out_0assm_assn (run_ch (run_now (sched_get_max (Sch p rn rp) s))) 0\n                                                                            (sched_assn' kk' (sched_get_max (Sch p rn rp) s) s)\n                                                                      else sched_assn' kk' (sched_clear (Sch p rn rp) s) s)\"\n                                                               tr2])\n                                apply simp\n                            subgoal for v2 tr2'\n                              apply (simp del: tdsch1'.simps)\n                              by (auto elim!: sync_elims)\n                            subgoal for v2 d2 tr2'\n                              apply (simp del: tdsch1'.simps)\n                              apply(cases \"d2>(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE3)\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply (simp del: tdsch1'.simps)\n                                by (auto elim!: sync_elims)\n                              apply(cases \"d2<(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE4)\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply (simp del: tdsch1'.simps)\n                                by (auto elim!: sync_elims)\n                              apply (simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_waitE2)\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              apply(elim combine_blocks_pairE)\n                              subgoal by auto\n                              subgoal by auto\n                              apply (simp only: tdsch1'.simps)\n                              apply(rule disjI2)+\n                              apply auto\n                              subgoal for tr'\n                                apply(rule wait_orig_assn.intros(2))\n                                apply auto\n                                apply(cases k')\n                                subgoal\n                                  apply simp\n                                  apply(simp add: emp_assn_def)\n                                  apply(cases rule: out_0assm_assn.cases[of \"(run_ch (run_now (case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior)))\" 0\n                                                                                   \"(sched_assn' kk' (case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior) s)\" tr2'])\n                                    apply auto\n                                  subgoal for tr2''\n                                    apply(elim combine_blocks_emptyE'3')\n                                    subgoal\n                                      using properl_p5[of p] pre(6,10)\n                                      unfolding proper_def properp_def\n                                      apply(cases \"get_max p\")\n                                      by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                    subgoal for tr''\n                                      apply simp\n                                      apply(rule out_0assm_assn.intros(1))\n                                      apply(rule pre(1)[of 0 kk' \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\" \"(Task WAIT (Suc 0) 2)\" \n                                            \"(task_s\n                                              (CHR ''t'' := task_s CHR ''t'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                               CHR ''c'' := task_s CHR ''c'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\" \n                                            \"[]\" \"(case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior)\" s tr2'' tr''])\n                                      subgoal by auto\n                                      subgoal by (auto simp add: emp_assn_def)\n                                      subgoal by auto\n                                      subgoal by auto\n                                      subgoal using pre unfolding propc_def by auto\n                                      subgoal using pre properl_p5[of p] properl_p4[of p] unfolding proper_def \n                                        apply(cases \"get_max p\") by auto\n                                      subgoal by auto\n                                      done\n                                    done\n                                  subgoal\n                                    by (auto elim: sync_elims)\n                                  done\n                                subgoal for k''\n                                  apply simp\n                                  apply(cases rule: wait_orig_assn.cases[of \"(pd - (dis_s CHR ''t'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\"\n                                                           \"(\\<lambda>t. ParState\n                                                                 (EState\n                                                                   (Task WAIT (Suc 0) 2, task_s\n                                                                    (CHR ''t'' := task_s CHR ''t'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                                                     CHR ''c'' := task_s CHR ''c'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))))\n                                                                 (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'') + t))))\"\n                                                           \"({}, {dispatch_ch 1})\"\n                                                           \"(task_dis_assn' 1 k'' pd pc (dis_s(CHR ''t'' := 0)) (Task READY 0 2)\n                                                             (task_s(CHR ''c'' := task_s CHR ''c'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''), CHR ''t'' := 0)))\"\n                                                           tr1'' ])\n                                    apply simp\n                                  subgoal\n                                    apply(cases k'')\n                                    subgoal\n                                      apply simp\n                                      apply(simp add: emp_assn_def)\n                                      apply(cases rule: out_0assm_assn.cases[of \"(run_ch (run_now (case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior)))\" 0\n                                                                                   \"(sched_assn' kk' (case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior) s)\" tr2'])\n                                        apply auto\n                                      subgoal for tr2''\n                                        apply(elim combine_blocks_emptyE'3')\n                                        subgoal\n                                          using properl_p5[of p] pre(6,10)\n                                          unfolding proper_def properp_def\n                                          apply(cases \"get_max p\")\n                                          by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                        subgoal for tr''\n                                          apply simp\n                                          apply(rule out_0assm_assn.intros(1))\n                                          apply(rule pre(1)[of \"(Suc 0)\" kk' \"(dis_s(CHR ''t'' := pd))\" \"(Task WAIT (Suc 0) 2)\" \n                                                              \"(task_s\n                                                                    (CHR ''t'' := task_s CHR ''t'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                                                     CHR ''c'' := task_s CHR ''c'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\" \n                                                              \"[]\" \"(case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior)\" s tr2'' tr''])\n                                          subgoal by auto\n                                          subgoal by auto                                \n                                          subgoal by auto\n                                          subgoal by auto\n                                          subgoal using pre properl_p5[of p] unfolding propc_def unfolding proper_def  apply(cases \"get_max p\") by auto\n                                          subgoal using pre properl_p5[of p] properl_p4[of p] unfolding proper_def \n                                            apply(cases \"get_max p\") by auto\n                                          subgoal by auto\n                                          done\n                                        done\n                                      subgoal\n                                        by (auto elim: sync_elims)\n                                      done\n                                    subgoal for k'''\n                                      apply simp\n                                      apply(erule disjE)\n                                      subgoal premises pre'\n                                        thm pre'\n                                        apply(rule combine_blocks_assn)\n                                           apply(rule pre'(21))\n                                          apply(rule pre'(11))\n                                         apply(rule pre'(13))\n                                        apply(rule entails_tassn_trans)\n                                         apply(rule combine_out_0assm_out_0assm2')\n                                        subgoal by auto\n                                        subgoal using pre(6,10) pre' properl_p5[of p]\n                                          unfolding proper_def properp_def\n                                          apply(cases \"get_max p\")\n                                          by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                        apply(rule out_0assm_assn_tran)\n                                        unfolding entails_tassn_def combine_assn_def\n                                        apply auto\n                                        subgoal for Tr Tr1 Tr2\n                                          apply(rule pre(1)[of \"(Suc (Suc k'''))\"  kk' \"(dis_s(CHR ''t'' := pd))\" \"(Task WAIT (Suc 0) 2)\" \n                                                                \"(task_s\n                                                                      (CHR ''t'' := task_s CHR ''t'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                                                       CHR ''c'' := task_s CHR ''c'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\" Tr1 \n                                                \"(case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior)\" s Tr2 Tr])\n                                          subgoal using pre' by auto\n                                          subgoal apply auto\n                                            apply(rule wait_orig_assn.intros(1))\n                                            using pre' by auto\n                                          subgoal by auto\n                                          subgoal by auto\n                                          subgoal using pre pre' properl_p5[of p] unfolding propc_def proper_def apply(cases \"get_max p\") by auto\n                                          subgoal using pre pre' properl_p5[of p] properl_p4[of p] unfolding propc_def proper_def apply(cases \"get_max p\") by auto\n                                          subgoal by auto\n                                          done\n                                        done\n                                      apply(erule disjE)\n                                      subgoal premises pre'\n                                        thm pre'\n                                        apply(rule combine_blocks_assn)\n                                           apply(rule pre'(21))\n                                          apply(rule pre'(11))\n                                         apply(rule pre'(13))\n                                        apply(rule entails_tassn_trans)\n                                         apply(rule combine_out_0assm_out_0assm2')\n                                        subgoal by auto\n                                        subgoal using pre(6,10) pre' properl_p5[of p]\n                                          unfolding proper_def properp_def\n                                          apply(cases \"get_max p\")\n                                          by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                        apply(rule out_0assm_assn_tran)\n                                        unfolding entails_tassn_def combine_assn_def\n                                        apply auto\n                                        subgoal for Tr Tr1 Tr2\n                                          apply(rule pre(1)[of \"(Suc (Suc k'''))\"  kk' \"(dis_s(CHR ''t'' := pd))\" \"(Task WAIT (Suc 0) 2)\" \n                                                                \"(task_s\n                                                                      (CHR ''t'' := task_s CHR ''t'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                                                       CHR ''c'' := task_s CHR ''c'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\" Tr1 \n                                                \"(case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior)\" s Tr2 Tr])\n                                          subgoal using pre' by auto\n                                          subgoal apply auto\n                                            apply(rule wait_orig_assn.intros(1))\n                                            using pre' by auto\n                                          subgoal by auto\n                                          subgoal by auto\n                                          subgoal using pre pre' properl_p5[of p] unfolding propc_def proper_def apply(cases \"get_max p\") by auto\n                                          subgoal using pre pre' properl_p5[of p] properl_p4[of p] unfolding propc_def proper_def apply(cases \"get_max p\") by auto\n                                          subgoal by auto\n                                          done\n                                        done\n                                      subgoal premises pre'\n                                        thm pre'\n                                        apply(rule combine_blocks_assn)\n                                           apply(rule pre'(21))\n                                          apply(rule pre'(11))\n                                         apply(rule pre'(13))\n                                        apply(rule entails_tassn_trans)\n                                         apply(rule combine_out_0assm_out_0assm2')\n                                        subgoal by auto\n                                        subgoal using pre(6,10) pre' properl_p5[of p]\n                                          unfolding proper_def properp_def\n                                          apply(cases \"get_max p\")\n                                          by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                        apply(rule out_0assm_assn_tran)\n                                        unfolding entails_tassn_def combine_assn_def\n                                        apply auto\n                                        subgoal for Tr Tr1 Tr2\n                                          apply(rule pre(1)[of \"(Suc (Suc k'''))\"  kk' \"(dis_s(CHR ''t'' := pd))\" \"(Task WAIT (Suc 0) 2)\" \n                                                                \"(task_s\n                                                                      (CHR ''t'' := task_s CHR ''t'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                                                       CHR ''c'' := task_s CHR ''c'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\" Tr1 \n                                                \"(case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior)\" s Tr2 Tr])\n                                          subgoal using pre' by auto\n                                          subgoal apply auto\n                                            apply(rule wait_orig_assn.intros(1))\n                                            using pre' by auto\n                                          subgoal by auto\n                                          subgoal by auto\n                                          subgoal using pre pre' properl_p5[of p] unfolding propc_def proper_def apply(cases \"get_max p\") by auto\n                                          subgoal using pre pre' properl_p5[of p] properl_p4[of p] unfolding propc_def proper_def apply(cases \"get_max p\") by auto\n                                          subgoal by auto\n                                          done\n                                        done\n                                      done\n                                    done\n                                  subgoal premises pre' for tr1'''\n                                    thm pre'\n                                    apply(rule combine_blocks_assn)\n                                       apply(rule pre'(8))\n                                      apply(rule pre'(11))\n                                     apply(rule pre'(13))\n                                    apply(rule entails_tassn_trans)\n                                     apply(rule combine_wait_orig_out_0assm2)\n                                    subgoal using pre' by auto\n                                    subgoal using pre(6,10) pre' properl_p5[of p]\n                                    unfolding proper_def properp_def\n                                    apply(cases \"get_max p\")\n                                    by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                    apply(rule out_0assm_assn_tran)\n                                    unfolding entails_tassn_def combine_assn_def\n                                    apply auto\n                                    subgoal for Tr Tr1 Tr2\n                                      apply(rule pre(1)[of \"(Suc k'')\" kk' \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\" \"(Task WAIT (Suc 0) 2)\" \n                                                          \"(task_s\n                                                                (CHR ''t'' := task_s CHR ''t'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                                                 CHR ''c'' := task_s CHR ''c'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\" Tr1 \n                                            \"(case get_max p of (prior, t) \\<Rightarrow> Sch (del_proc p t) t prior)\" s Tr2 Tr])\n                                      subgoal using pre' by auto\n                                      subgoal by auto\n                                      subgoal by auto\n                                      subgoal by auto\n                                      subgoal using pre pre' properl_p5[of p] unfolding propc_def proper_def apply(cases \"get_max p\") by auto\n                                      subgoal using pre pre' properl_p5[of p] properl_p4[of p] unfolding propc_def proper_def apply(cases \"get_max p\") by auto\n                                      subgoal by auto\n                                      done\n                                    done\n                                  done\n                                done\n                              subgoal for tr'\n                                apply(rule wait_orig_assn.intros(2))\n                                 apply auto\n                                apply(rule pre(1)[of k' kk' \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\" \"(Task WAIT (Suc 0) 2)\" \n                                                    \"(task_s\n                                                          (CHR ''t'' := task_s CHR ''t'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                                           CHR ''c'' := task_s CHR ''c'' + min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\" tr1'' \"(Sch [] (- 1) (- 1))\" s tr2' tr'])\n                                using pre\n                                by (auto simp add:proper_def propc_def properp_def)\n                              done\n                            subgoal for v2 tr2'\n                              apply (simp del: tdsch1'.simps)\n                              by (auto elim!: sync_elims)\n                            subgoal for d2 v2 tr2'\n                              apply (simp del: tdsch1'.simps)\n                              apply(cases \"d2>(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE3)\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply (simp del: tdsch1'.simps)\n                                by (auto elim!: sync_elims)\n                              apply(cases \"d2<(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE4)\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply (simp del: tdsch1'.simps)\n                                by (auto elim!: sync_elims)\n                              apply (simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_waitE2)\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              apply(elim combine_blocks_pairE)\n                              by auto\n                            done\n                          subgoal for d1 rdy p1 tr1''\n                            apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                                               \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(free_ch 1)\"\n                                                               \"{0}\"\n                                                               \"(\\<lambda>v d. if p \\<noteq> []\n                                                                      then out_0assm_assn (run_ch (run_now (sched_get_max (Sch p rn rp) s))) 0\n                                                                            (sched_assn' kk' (sched_get_max (Sch p rn rp) s) s)\n                                                                      else sched_assn' kk' (sched_clear (Sch p rn rp) s) s)\"\n                                                               tr2])\n                                apply simp\n                            subgoal for v2 tr2'\n                              apply (simp del: tdsch1'.simps)\n                              by (auto elim!: sync_elims)\n                            subgoal for v2 d2 tr2'\n                              apply (simp del: tdsch1'.simps)\n                              apply(cases \"d2>(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE3[of \"{req_ch 1, preempt_ch 1, run_ch 1, free_ch 1, exit_ch 1}\" \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"])\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply (simp del: tdsch1'.simps)\n                                apply(elim combine_blocks_waitE1)\n                                apply(cases rdy)\n                                by auto\n                              apply(cases \"d2<(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE4)\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply (simp del: tdsch1'.simps)\n                                by (auto elim!: sync_elims)\n                              apply (simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_waitE2)\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              by (auto elim!: sync_elims)\n                            subgoal for v2 tr2'\n                              apply (simp del: tdsch1'.simps)\n                              by (auto elim!: sync_elims)\n                            subgoal for d2 v2 tr2'\n                              apply (simp del: tdsch1'.simps)\n                              apply(cases \"d2>(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE3[of \"{req_ch 1, preempt_ch 1, run_ch 1, free_ch 1, exit_ch 1}\" \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"])\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply (simp del: tdsch1'.simps)\n                                apply(elim combine_blocks_waitE1)\n                                apply(cases rdy)\n                                by auto\n                              apply(cases \"d2<(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE4)\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply (simp del: tdsch1'.simps)\n                                by (auto elim!: sync_elims)\n                              apply (simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_waitE2)\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              by (auto elim!: sync_elims)\n                            done\n                          done\n                        done\n                      apply(erule disjE)\n                      subgoal\n                        apply(cases rule: wait_orig_assn.cases[of \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"\n                                          \"(\\<lambda>t. ParState\n                                                 (EState\n                                                   (Task RUNNING (Suc 0) 2, task_s\n                                                    (CHR ''t'' := task_s CHR ''t'' + t, CHR ''c'' := task_s CHR ''c'' + t)))\n                                                 (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\"\n                                           \"({}, {preempt_ch 1})\"\n                                           \"(out_0assm_srdy_assn (free_ch 1) 0 ({free_ch 1}, {preempt_ch 1})\n                                             (task_dis_assn' 1 k' pd pc\n                                               (dis_s\n                                                (CHR ''t'' :=\n                                                   dis_s CHR ''t'' +\n                                                   min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                               (Task WAIT (Suc 0) 2)\n                                               (task_s\n                                                (CHR ''t'' :=\n                                                   task_s CHR ''t'' +\n                                                   min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                                 CHR ''c'' :=\n                                                   task_s CHR ''c'' +\n                                                   min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))))\" tr1])\n                          apply simp\n                        subgoal\n                          apply(cases rule: out_0assm_srdy_assn.cases[of \"(free_ch 1)\" 0 \"({free_ch 1}, {preempt_ch 1})\"\n                                       \"(task_dis_assn' 1 k' pd pc\n                                         (dis_s\n                                          (CHR ''t'' :=\n                                             dis_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                         (Task WAIT (Suc 0) 2)\n                                         (task_s\n                                          (CHR ''t'' :=\n                                             task_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                           CHR ''c'' :=\n                                             task_s CHR ''c'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))))\" tr1])\n                         apply simp\n                          subgoal for tr1'\n                            apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                                             \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(free_ch 2)\"\n                                                             \"{0}\"\n                                                             \"(\\<lambda>v d. if p \\<noteq> []\n                                                                    then out_0assm_assn (run_ch (run_now (sched_get_max (Sch p rn rp) s))) 0\n                                                                          (sched_assn' kk' (sched_get_max (Sch p rn rp) s) s)\n                                                                    else sched_assn' kk' (sched_clear (Sch p rn rp) s) s)\"\n                                                             tr2])\n                                apply simp\n                            subgoal for v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_unpairE1')\n                              subgoal by auto\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              apply (simp only: tdsch1'.simps)\n                              apply(rule disjI2)\n                              apply(rule disjI1)\n                              apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                                apply auto\n                              by(auto simp add:true_assn_def)\n                            subgoal for v2 d2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              by (auto elim!: sync_elims)\n                            subgoal for v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_unpairE1')\n                              subgoal by auto\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              apply (simp only: tdsch1'.simps)\n                              apply(rule disjI2)\n                              apply(rule disjI1)\n                              apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                                by auto\n                            subgoal for d2 v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              by (auto elim!: sync_elims)\n                            done\n                          subgoal for d1 rdy1 p1 tr1'\n                            apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                                             \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(free_ch 2)\"\n                                                             \"{0}\"\n                                                             \"(\\<lambda>v d. if p \\<noteq> []\n                                                                    then out_0assm_assn (run_ch (run_now (sched_get_max (Sch p rn rp) s))) 0\n                                                                          (sched_assn' kk' (sched_get_max (Sch p rn rp) s) s)\n                                                                    else sched_assn' kk' (sched_clear (Sch p rn rp) s) s)\"\n                                                             tr2])\n                                apply simp\n                            subgoal for v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_unpairE3')\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              apply (simp only: tdsch1'.simps)\n                              apply(rule disjI2)\n                              apply(rule disjI1)\n                              apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                                apply auto\n                              by(auto simp add:true_assn_def)\n                            subgoal for d2 v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_waitE1)\n                              apply(cases rdy1)\n                              by auto\n                            subgoal for v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_unpairE3')\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              apply (simp only: tdsch1'.simps)\n                              apply(rule disjI2)\n                              apply(rule disjI1)\n                              apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                              by auto\n                            subgoal for d2 v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_waitE1)\n                              apply(cases rdy1)\n                              by auto\n                            done\n                          done\n                        subgoal for tr1'\n                          apply(cases rule: out_0assm_srdy_assn.cases[of \"(free_ch 1)\" 0 \"({free_ch 1}, {preempt_ch 1})\"\n                                       \"(task_dis_assn' 1 k' pd pc \n                                         (dis_s\n                                          (CHR ''t'' :=\n                                             dis_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                         (Task WAIT (Suc 0) 2)\n                                         (task_s\n                                          (CHR ''t'' :=\n                                             task_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                           CHR ''c'' :=\n                                             task_s CHR ''c'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))))\" tr1'])\n                         apply simp\n                          subgoal for tr1''\n                            apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                                             \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(free_ch 2)\"\n                                                             \"{0}\"\n                                                             \"(\\<lambda>v d. if p \\<noteq> []\n                                                                    then out_0assm_assn (run_ch (run_now (sched_get_max (Sch p rn rp) s))) 0\n                                                                          (sched_assn' kk' (sched_get_max (Sch p rn rp) s) s)\n                                                                    else sched_assn' kk' (sched_clear (Sch p rn rp) s) s)\"\n                                                             tr2])\n                                apply simp\n                            subgoal for v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_unpairE3')\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              apply (simp only: tdsch1'.simps)\n                              apply(rule disjI2)\n                              apply(rule disjI1)\n                              apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                                apply auto\n                              by(auto simp add:true_assn_def)\n                            subgoal for v2 d2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(cases \"d2 > (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE3)\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply simp\n                                by (auto elim!: sync_elims)\n                              apply(cases \"d2 < (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal  \n                                apply(elim combine_blocks_waitE4)\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply (simp only: tdsch1'.simps)\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(elim combine_blocks_unpairE3')\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply auto\n                                apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                                   apply auto\n                                by(auto simp add: true_assn_def)\n                              apply(cases \"d2 = (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal \n                                apply (simp only: tdsch1'.simps)\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(elim combine_blocks_waitE2)\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply(elim combine_blocks_unpairE1')\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply auto\n                                apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                                   apply auto\n                                by(auto simp add: true_assn_def)\n                              by auto\n                            subgoal for v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_unpairE3')\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              apply (simp only: tdsch1'.simps)\n                              apply(rule disjI2)\n                              apply(rule disjI1)\n                              apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                                by auto\n                            subgoal for d2 v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(cases \"d2 > (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE3)\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply simp\n                                by (auto elim!: sync_elims)\n                              apply(cases \"d2 < (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal  \n                                apply(elim combine_blocks_waitE4)\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply (simp only: tdsch1'.simps)\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(elim combine_blocks_unpairE3')\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply auto\n                                apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                                by auto\n                              apply(cases \"d2 = (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal \n                                apply (simp only: tdsch1'.simps)\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(elim combine_blocks_waitE2)\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply(elim combine_blocks_unpairE1')\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply auto\n                                apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                                by auto\n                              by auto\n                            done\n                          subgoal for d1 rdy1 p1 tr1''\n                            apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                                             \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(free_ch 2)\"\n                                                             \"{0}\"\n                                                             \"(\\<lambda>v d. if p \\<noteq> []\n                                                                    then out_0assm_assn (run_ch (run_now (sched_get_max (Sch p rn rp) s))) 0\n                                                                          (sched_assn' kk' (sched_get_max (Sch p rn rp) s) s)\n                                                                    else sched_assn' kk' (sched_clear (Sch p rn rp) s) s)\"\n                                                             tr2])\n                                apply simp\n                            subgoal for v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_unpairE3')\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              apply (simp only: tdsch1'.simps)\n                              apply(rule disjI2)\n                              apply(rule disjI1)\n                              apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                                apply auto\n                              by(auto simp add:true_assn_def)\n                            subgoal for v2 d2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(cases \"d2 > (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE3[of \"{req_ch 1, preempt_ch 1, run_ch 1, free_ch 1, exit_ch 1}\" \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"])\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply simp\n                                apply(elim combine_blocks_waitE1)\n                                apply(cases rdy1)\n                                by auto\n                              apply(cases \"d2 < (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE4[of \"{req_ch 1, preempt_ch 1, run_ch 1, free_ch 1, exit_ch 1}\" \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"])\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply (simp only: tdsch1'.simps)\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(elim combine_blocks_unpairE3')\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply auto\n                                apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                                   apply auto\n                                by (auto simp add:true_assn_def) \n                              apply(cases \"d2 = (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply (simp only: tdsch1'.simps)\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(elim combine_blocks_waitE2)\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply(elim combine_blocks_unpairE3')\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply auto\n                                apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                                   apply auto\n                                by (auto simp add:true_assn_def)\n                              by auto\n                            subgoal for v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_unpairE3')\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              apply (simp only: tdsch1'.simps)\n                              apply(rule disjI2)\n                              apply(rule disjI1)\n                              apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                                by auto\n                            subgoal for d2 v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(cases \"d2 > (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE3[of \"{req_ch 1, preempt_ch 1, run_ch 1, free_ch 1, exit_ch 1}\" \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"])\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply simp\n                                apply(elim combine_blocks_waitE1)\n                                apply(cases rdy1)\n                                by auto\n                              apply(cases \"d2 < (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE4[of \"{req_ch 1, preempt_ch 1, run_ch 1, free_ch 1, exit_ch 1}\" \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"])\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply (simp only: tdsch1'.simps)\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(elim combine_blocks_unpairE3')\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply auto\n                                apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                                by auto\n                              apply(cases \"d2 = (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply (simp only: tdsch1'.simps)\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(elim combine_blocks_waitE2)\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply(elim combine_blocks_unpairE3')\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply auto\n                                apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                                by auto\n                              by auto\n                            done\n                          done\n                        done\n                      apply(erule disjE)\n                      subgoal\n                        apply(cases rule: wait_orig_assn.cases[of \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"\n                                          \"(\\<lambda>t. ParState\n                                                 (EState\n                                                   (Task RUNNING (Suc 0) 2, task_s\n                                                    (CHR ''t'' := task_s CHR ''t'' + t, CHR ''c'' := task_s CHR ''c'' + t)))\n                                                 (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\"\n                                           \"({}, {preempt_ch 1})\"\n                                           \"(out_0assm_srdy_assn (free_ch 1) 0 ({free_ch 1}, {preempt_ch 1})\n                                             (task_dis_assn' 1 k' pd pc\n                                               (dis_s\n                                                (CHR ''t'' :=\n                                                   dis_s CHR ''t'' +\n                                                   min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                               (Task WAIT (Suc 0) 2)\n                                               (task_s\n                                                (CHR ''t'' :=\n                                                   task_s CHR ''t'' +\n                                                   min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                                 CHR ''c'' :=\n                                                   task_s CHR ''c'' +\n                                                   min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))))\" tr1])\n                          apply simp\n                        subgoal\n                          apply(cases rule: out_0assm_srdy_assn.cases[of \"(free_ch 1)\" 0 \"({free_ch 1}, {preempt_ch 1})\"\n                                       \"(task_dis_assn' 1 k' pd pc\n                                         (dis_s\n                                          (CHR ''t'' :=\n                                             dis_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                         (Task WAIT (Suc 0) 2)\n                                         (task_s\n                                          (CHR ''t'' :=\n                                             task_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                           CHR ''c'' :=\n                                             task_s CHR ''c'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))))\" tr1])\n                         apply simp\n                          subgoal for tr1'\n                            apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                                             \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(exit_ch 1)\"\n                                                             \"{0}\"\n                                                             \"(\\<lambda>v d. sched_assn' kk' (Sch (del_proc p 1) rn rp) s)\"\n                                                             tr2])\n                                apply simp\n                            subgoal for v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_pairE)\n                              subgoal by auto\n                              subgoal by auto\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              done\n                            subgoal for v2 d2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              by (auto elim!: sync_elims)\n                            subgoal for v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_pairE)\n                              subgoal by auto\n                              subgoal by auto\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              done\n                            subgoal for v2 d2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              by (auto elim!: sync_elims)\n                            done\n                          subgoal for d1 rdy1 p1 tr1'\n                            apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                                             \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(exit_ch 1)\"\n                                                             \"{0}\"\n                                                             \"(\\<lambda>v d. sched_assn' kk' (Sch (del_proc p 1) rn rp) s)\"\n                                                             tr2])\n                                apply simp\n                            subgoal for v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              by (auto elim!: sync_elims)\n                            subgoal for v2 d2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_waitE1)\n                              apply(cases rdy1)\n                              by auto\n                            subgoal for v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              by (auto elim!: sync_elims)\n                            subgoal for d2 v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_waitE1)\n                              apply(cases rdy1)\n                              by auto\n                            done\n                          done\n                        subgoal for tr1'\n                          apply(cases rule: out_0assm_srdy_assn.cases[of \"(free_ch 1)\" 0 \"({free_ch 1}, {preempt_ch 1})\"\n                                       \"(task_dis_assn' 1 k' pd pc\n                                         (dis_s\n                                          (CHR ''t'' :=\n                                             dis_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                         (Task WAIT (Suc 0) 2)\n                                         (task_s\n                                          (CHR ''t'' :=\n                                             task_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                           CHR ''c'' :=\n                                             task_s CHR ''c'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))))\" tr1'])\n                         apply simp\n                          subgoal for tr1''\n                            apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                                             \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(exit_ch 1)\"\n                                                             \"{0}\"\n                                                             \"(\\<lambda>v d. sched_assn' kk' (Sch (del_proc p 1) rn rp) s)\"\n                                                             tr2])\n                                apply simp\n                            subgoal for v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              by (auto elim!: sync_elims)\n                            subgoal for v2 d2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(cases \"d2 > (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal \n                                apply(elim combine_blocks_waitE3)\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply simp\n                                by (auto elim!: sync_elims)\n                              apply(cases \"d2 < (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE4)\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply simp\n                                by (auto elim!: sync_elims)\n                              apply(cases \"d2 = (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply simp\n                                apply(elim combine_blocks_waitE2)\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply simp\n                                apply(elim combine_blocks_pairE)\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                done\n                              by auto\n                            subgoal for v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              by (auto elim!: sync_elims)\n                            subgoal for d2 v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(cases \"d2 > (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal \n                                apply(elim combine_blocks_waitE3)\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply simp\n                                by (auto elim!: sync_elims)\n                              apply(cases \"d2 < (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE4)\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply simp\n                                by (auto elim!: sync_elims)\n                              apply(cases \"d2 = (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply simp\n                                apply(elim combine_blocks_waitE2)\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply simp\n                                apply(elim combine_blocks_pairE)\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                done\n                              by auto\n                            done\n                          subgoal for d1 rdy1 p1 tr1''\n                            apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                                             \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(exit_ch 1)\"\n                                                             \"{0}\"\n                                                             \"(\\<lambda>v d. sched_assn' kk' (Sch (del_proc p 1) rn rp) s)\"\n                                                             tr2])\n                                apply simp\n                            subgoal for v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              by (auto elim!: sync_elims)\n                            subgoal for v2 d2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(cases \"d2 > (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal \n                                apply(elim combine_blocks_waitE3[of \"{req_ch 1, preempt_ch 1, run_ch 1, free_ch 1, exit_ch 1}\" \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"])\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply simp\n                                apply(elim combine_blocks_waitE1)\n                                apply(cases rdy1)\n                                by auto\n                              apply(cases \"d2 < (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE4[of \"{req_ch 1, preempt_ch 1, run_ch 1, free_ch 1, exit_ch 1}\" \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"])\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply simp\n                                by (auto elim!: sync_elims)\n                              apply(cases \"d2 = (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply simp\n                                apply(elim combine_blocks_waitE2)\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                by (auto elim!: sync_elims)\n                              by auto\n                            subgoal for v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              by (auto elim!: sync_elims)\n                            subgoal for d2 v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(cases \"d2 > (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal \n                                apply(elim combine_blocks_waitE3[of \"{req_ch 1, preempt_ch 1, run_ch 1, free_ch 1, exit_ch 1}\" \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"])\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply simp\n                                apply(elim combine_blocks_waitE1)\n                                apply(cases rdy1)\n                                by auto\n                              apply(cases \"d2 < (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE4[of \"{req_ch 1, preempt_ch 1, run_ch 1, free_ch 1, exit_ch 1}\" \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"])\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply simp\n                                by (auto elim!: sync_elims)\n                              apply(cases \"d2 = (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply simp\n                                apply(elim combine_blocks_waitE2)\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                by (auto elim!: sync_elims)\n                              by auto\n                            done\n                          done\n                        done\n                      subgoal\n                        apply(cases rule: wait_orig_assn.cases[of \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"\n                                          \"(\\<lambda>t. ParState\n                                                 (EState\n                                                   (Task RUNNING (Suc 0) 2, task_s\n                                                    (CHR ''t'' := task_s CHR ''t'' + t, CHR ''c'' := task_s CHR ''c'' + t)))\n                                                 (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + t))))\"\n                                           \"({}, {preempt_ch 1})\"\n                                           \"(out_0assm_srdy_assn (free_ch 1) 0 ({free_ch 1}, {preempt_ch 1})\n                                             (task_dis_assn' 1 k' pd pc\n                                               (dis_s\n                                                (CHR ''t'' :=\n                                                   dis_s CHR ''t'' +\n                                                   min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                               (Task WAIT (Suc 0) 2)\n                                               (task_s\n                                                (CHR ''t'' :=\n                                                   task_s CHR ''t'' +\n                                                   min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                                 CHR ''c'' :=\n                                                   task_s CHR ''c'' +\n                                                   min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))))\" tr1])\n                          apply simp\n                        subgoal\n                          apply(cases rule: out_0assm_srdy_assn.cases[of \"(free_ch 1)\" 0 \"({free_ch 1}, {preempt_ch 1})\"\n                                       \"(task_dis_assn' 1 k' pd pc\n                                         (dis_s\n                                          (CHR ''t'' :=\n                                             dis_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                         (Task WAIT (Suc 0) 2)\n                                         (task_s\n                                          (CHR ''t'' :=\n                                             task_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                           CHR ''c'' :=\n                                             task_s CHR ''c'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))))\" tr1])\n                         apply simp\n                          subgoal for tr1'\n                            apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                                             \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(exit_ch 2)\"\n                                                             \"{0}\"\n                                                             \"(\\<lambda>v d. sched_assn' kk' (Sch (del_proc p 2) rn rp) s)\"\n                                                             tr2])\n                                apply simp\n                            subgoal for v2 tr2'\n                              apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                               prefer 2\n                              subgoal using pre unfolding proper_def propc_def properp_def by auto\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_unpairE1')\n                              subgoal by auto\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              apply (simp only: tdsch1'.simps)\n                              apply(rule disjI2)\n                              apply(rule disjI2)\n                              apply(rule disjI1)\n                              apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                                apply auto\n                              subgoal for tr'\n                                apply(rule pre(1)[of \"(Suc k')\" kk' dis_s \"(Task RUNNING (Suc 0) 2)\" task_s \"(OutBlock (free_ch 1) 0 # tr1')\" \"(Sch (del_proc p 2) 1 2)\" s tr2' tr'])\n                                using pre properl_p4 unfolding propc_def proper_def properp_def by auto\n                              done\n                            subgoal for v2 d2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              by (auto elim!: sync_elims)\n                            subgoal for v2 tr2'\n                              apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                               prefer 2\n                              subgoal using pre unfolding proper_def propc_def properp_def by auto\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_unpairE1')\n                              subgoal by auto\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              apply (simp only: tdsch1'.simps)\n                              apply(rule disjI2)\n                              apply(rule disjI2)\n                              apply(rule disjI1)\n                              apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                                by auto\n                            subgoal for d2 v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              by (auto elim!: sync_elims)\n                            done\n                          subgoal for d1 rdy1 p1 tr1'\n                            apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                                             \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(exit_ch 2)\"\n                                                             \"{0}\"\n                                                             \"(\\<lambda>v d. sched_assn' kk' (Sch (del_proc p 2) rn rp) s)\"\n                                                             tr2])\n                                apply simp\n                            subgoal for v2 tr2'\n                              apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                               prefer 2\n                              subgoal using pre unfolding proper_def propc_def properp_def by auto\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_unpairE3')\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              apply (simp only: tdsch1'.simps)\n                              apply(rule disjI2)\n                              apply(rule disjI2)\n                              apply(rule disjI1)\n                              apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                                apply auto\n                              subgoal for tr'\n                                apply(rule pre(1)[of \"(Suc k')\" kk' dis_s \"(Task RUNNING (Suc 0) 2)\" task_s \"(WaitBlk d1 p1 rdy1 # tr1')\" \"(Sch (del_proc p 2) 1 2)\" s tr2' tr'])\n                                using pre properl_p4 unfolding propc_def proper_def properp_def by auto\n                              done\n                            subgoal for v2 d2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_waitE1)\n                              apply(cases rdy1)\n                              by auto\n                            subgoal for v2 tr2'\n                              apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                               prefer 2\n                              subgoal using pre unfolding proper_def propc_def properp_def by auto\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_unpairE3')\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              apply (simp only: tdsch1'.simps)\n                              apply(rule disjI2)\n                              apply(rule disjI2)\n                              apply(rule disjI1)\n                              apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                                by auto\n                            subgoal for d2 v2 tr2'\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_waitE1)\n                              apply(cases rdy1)\n                              by auto\n                            done\n                          done\n                        subgoal for tr1'\n                          apply(cases rule: out_0assm_srdy_assn.cases[of \"(free_ch 1)\" 0 \"({free_ch 1}, {preempt_ch 1})\"\n                                       \"(task_dis_assn' 1 k' pd pc\n                                         (dis_s\n                                          (CHR ''t'' :=\n                                             dis_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                         (Task WAIT (Suc 0) 2)\n                                         (task_s\n                                          (CHR ''t'' :=\n                                             task_s CHR ''t'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''),\n                                           CHR ''c'' :=\n                                             task_s CHR ''c'' +\n                                             min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))))\" tr1'])\n                         apply simp\n                          subgoal for tr1''\n                            apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                                             \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(exit_ch 2)\"\n                                                             \"{0}\"\n                                                             \"(\\<lambda>v d. sched_assn' kk' (Sch (del_proc p 2) rn rp) s)\"\n                                                             tr2])\n                                apply simp\n                            subgoal for v2 tr2'\n                              apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                               prefer 2\n                              subgoal using pre unfolding proper_def propc_def properp_def by auto\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_unpairE3')\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              apply (simp only: tdsch1'.simps)\n                              apply(rule disjI2)\n                              apply(rule disjI2)\n                              apply(rule disjI1)\n                              apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                                apply auto\n                              subgoal for tr'\n                                apply(rule pre(1)[of \"(Suc k')\" kk' dis_s \"(Task RUNNING (Suc 0) 2)\" task_s tr1 \"(Sch (del_proc p 2) 1 2)\" s tr2' tr'])\n                              using pre properl_p4 unfolding propc_def proper_def properp_def by auto\n                              done\n                            subgoal for v2 d2 tr2'\n                              apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                               prefer 2\n                              subgoal using pre unfolding proper_def propc_def properp_def by auto\n                              apply(simp del: tdsch1'.simps)\n                              apply(cases \"d2>(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE3)\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                by (auto elim!: sync_elims)\n                              apply(cases \"d2<(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE4)\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply (simp only: tdsch1'.simps)\n                                apply(rule disjI2)\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(elim combine_blocks_unpairE3')\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply auto\n                                apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                                apply auto\n                                subgoal for tr'\n                                  apply(rule pre(1)[of \"(Suc k')\" kk' \"(dis_s(CHR ''t'' := dis_s CHR ''t'' + d2))\"\n                                                  \"(Task RUNNING (Suc 0) 2)\"\n                                                  \"(task_s(CHR ''t'' := task_s CHR ''t'' + d2, CHR ''c'' := task_s CHR ''c'' + d2))\"\n                                                  \"(WaitBlk (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'') - d2)\n                                                     (\\<lambda>t. ParState\n                                                           (EState\n                                                             (Task RUNNING (Suc 0) 2, task_s\n                                                              (CHR ''t'' := task_s CHR ''t'' + (t + d2),\n                                                               CHR ''c'' := task_s CHR ''c'' + (t + d2))))\n                                                           (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d2)))))\n                                                     ({}, {preempt_ch 1}) #\n                                                    OutBlock (free_ch 1) 0 # tr1'')\"\n                                                   \"(Sch (del_proc p 2) 1 2)\" s tr2' tr'])\n                                  subgoal by auto\n                                  subgoal premises pre'\n                                    apply simp\n                                    apply(rule disjI2)\n                                    apply(subgoal_tac\"(min (pd - (task_s CHR ''t'' + d2)) (pc - (task_s CHR ''c'' + d2))) \n                                                    = (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'') - d2)\")\n                                    apply(subgoal_tac\"(\\<lambda>t. ParState\n                                                       (EState\n                                                         (Task RUNNING (Suc 0) 2, task_s\n                                                          (CHR ''t'' := task_s CHR ''t'' + d2 + t,\n                                                           CHR ''c'' := task_s CHR ''c'' + d2 + t)))\n                                                       (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + d2 + t)))) = \n                                                      (\\<lambda>t. ParState\n                                                       (EState\n                                                         (Task RUNNING (Suc 0) 2, task_s\n                                                          (CHR ''t'' := task_s CHR ''t'' + (t + d2),\n                                                           CHR ''c'' := task_s CHR ''c'' + (t + d2))))\n                                                       (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d2)))))\")\n                                      apply simp\n                                      apply(rule wait_orig_assn.intros(2))\n                                       apply(rule out_0assm_srdy_assn.intros(1))\n                                    subgoal using pre' by auto\n                                    subgoal using pre' by auto\n                                    subgoal apply(rule ext) by auto\n                                    by auto\n                                  subgoal by auto\n                                  subgoal by auto\n                                  subgoal unfolding propc_def  by auto\n                                  subgoal using pre properl_p4 unfolding proper_def properp_def by auto\n                                  subgoal by auto\n                                  done\n                                done\n                              apply(cases \"d2=(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply (simp only: tdsch1'.simps)\n                                apply(rule disjI2)\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(elim combine_blocks_waitE2)\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply auto\n                                apply(elim combine_blocks_unpairE1')\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply auto\n                                apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                                   apply auto\n                                subgoal for tr'\n                                  apply(rule pre(1)[where ?tr1.0 = \"OutBlock (free_ch 1) 0 # tr1''\" and ?tr2.0 = tr2' and ?tr = tr'])\n                                  subgoal by auto\n                                  subgoal premises pre'\n                                    apply simp\n                                    apply(rule disjI2)\n                                    apply(subgoal_tac \"(min (pd -\n                                                       (task_s CHR ''t'' +\n                                                        min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                                   (pc -\n                                                    (task_s CHR ''c'' +\n                                                     min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))) = 0\")\n                                     apply auto\n                                    apply(rule wait_orig_assn.intros(1))\n                                     apply(rule out_0assm_srdy_assn.intros(1))\n                                    using pre' by auto\n                                  subgoal by auto\n                                  subgoal by auto\n                                  subgoal unfolding propc_def  by auto\n                                  subgoal using pre properl_p4 unfolding proper_def properp_def by auto\n                                  subgoal by auto\n                                  done\n                                done\n                              by auto\n                            subgoal for v2 tr2'\n                              apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                               prefer 2\n                              subgoal using pre unfolding proper_def propc_def properp_def by auto\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_unpairE3')\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              apply (simp only: tdsch1'.simps)\n                              apply(rule disjI2)\n                              apply(rule disjI2)\n                              apply(rule disjI1)\n                              apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                                by auto                    \n                            subgoal for d2 v2 tr2'\n                              apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                               prefer 2\n                              subgoal using pre unfolding proper_def propc_def properp_def by auto\n                              apply(simp del: tdsch1'.simps)\n                              apply(cases \"d2>(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE3)\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                by (auto elim!: sync_elims)\n                              apply(cases \"d2<(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE4)\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply (simp only: tdsch1'.simps)\n                                apply(rule disjI2)\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(elim combine_blocks_unpairE3')\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply auto\n                                apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                                by auto\n                              apply(cases \"d2=(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply (simp only: tdsch1'.simps)\n                                apply(rule disjI2)\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(elim combine_blocks_waitE2)\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply auto\n                                apply(elim combine_blocks_unpairE1')\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply auto\n                                apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                                by auto\n                              by auto\n                            done\n                          subgoal for d1 rdy1 p1 tr1''\n                            apply(cases rule: waitin_assms'_assn.cases[of UNIV \"(\\<lambda>t. EState (Sch p rn rp, s))\"\n                                                             \"({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})\" \"(exit_ch 2)\"\n                                                             \"{0}\"\n                                                             \"(\\<lambda>v d. sched_assn' kk' (Sch (del_proc p 2) rn rp) s)\"\n                                                             tr2])\n                            apply simp\n                            subgoal for v2 tr2'\n                              apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                               prefer 2\n                              subgoal using pre unfolding proper_def propc_def properp_def by auto\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_unpairE3')\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              apply (simp only: tdsch1'.simps)\n                              apply(rule disjI2)\n                              apply(rule disjI2)\n                              apply(rule disjI1)\n                              apply(rule waitin_tguar'_vassm'_assn.intros(1))\n                                apply auto\n                              subgoal for tr'\n                                apply(rule pre(1)[where ?tr1.0 = tr1 and ?tr2.0 = tr2' and ?tr = tr'])\n                                using pre properl_p4\n                                unfolding propc_def proper_def properp_def by auto\n                              done\n                            subgoal for v2 d2 tr2'\n                              apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                               prefer 2\n                              subgoal using pre unfolding proper_def propc_def properp_def by auto\n                              apply(simp del: tdsch1'.simps)\n                              apply(cases \"d2>(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE3[where ?d1.0 = \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"])\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply simp\n                                apply(elim combine_blocks_waitE1)\n                                apply(cases rdy1)\n                                by auto\n                              apply(cases \"d2<(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE4[where ?d1.0 = \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"])\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply (simp only: tdsch1'.simps)\n                                apply(rule disjI2)\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(elim combine_blocks_unpairE3')\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply auto\n                                apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                                   apply auto\n                                subgoal for tr'\n                                  apply(rule pre(1)[where ?tr1.0 = \"(WaitBlk (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'') - d2)\n                                                                     (\\<lambda>t. ParState\n                                                                           (EState\n                                                                             (Task RUNNING (Suc 0) 2, task_s\n                                                                              (CHR ''t'' := task_s CHR ''t'' + (t + d2),\n                                                                               CHR ''c'' := task_s CHR ''c'' + (t + d2))))\n                                                                           (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d2)))))\n                                                                     ({}, {preempt_ch 1}) #\n                                                                    WaitBlk d1 p1 rdy1 # tr1'')\"\n                                                     and ?tr2.0 = tr2' and ?tr = tr'])\n                                  subgoal by auto\n                                  subgoal premises pre'\n                                    apply simp\n                                    apply(rule disjI2)\n                                    apply(subgoal_tac\"(min (pd - (task_s CHR ''t'' + d2)) (pc - (task_s CHR ''c'' + d2)))\n                                                    = (min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'') - d2)\")\n                                    apply(subgoal_tac\"(\\<lambda>t. ParState\n                                                       (EState\n                                                         (Task RUNNING (Suc 0) 2, task_s\n                                                          (CHR ''t'' := task_s CHR ''t'' + d2 + t,\n                                                           CHR ''c'' := task_s CHR ''c'' + d2 + t)))\n                                                       (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + d2 + t))))\n                                                    = (\\<lambda>t. ParState\n                                                       (EState\n                                                         (Task RUNNING (Suc 0) 2, task_s\n                                                          (CHR ''t'' := task_s CHR ''t'' + (t + d2),\n                                                           CHR ''c'' := task_s CHR ''c'' + (t + d2))))\n                                                       (EState (estate.None, dis_s(CHR ''t'' := dis_s CHR ''t'' + (t + d2)))))\")\n                                    apply auto\n                                    apply(rule wait_orig_assn.intros(2))\n                                    apply(rule out_0assm_srdy_assn.intros(2))\n                                    subgoal using pre' by auto\n                                    subgoal using pre' by auto\n                                    subgoal using pre' by auto\n                                    subgoal using pre' by auto\n                                    apply(rule ext) by auto\n                                  subgoal by auto\n                                  subgoal by auto\n                                  subgoal unfolding propc_def  by auto\n                                  subgoal using pre properl_p4 unfolding proper_def properp_def by auto\n                                  subgoal by auto\n                                  done\n                                done\n                              apply(cases \"d2=(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply (simp only: tdsch1'.simps)\n                                apply(rule disjI2)\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(elim combine_blocks_waitE2)\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply auto\n                                apply(elim combine_blocks_unpairE3')\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply auto\n                                apply(rule waitin_tguar'_vassm'_assn.intros(2))\n                                   apply auto\n                                subgoal for tr'\n                                  apply(rule pre(1)[where ?tr1.0 = \"(WaitBlk d1 p1 rdy1 # tr1'')\" and ?tr2.0 = tr2' and ?tr = tr'])\n                                  subgoal by auto\n                                  subgoal premises pre'\n                                    apply simp\n                                    apply(rule disjI2)\n                                    apply(subgoal_tac\"(min (pd -\n                                                       (task_s CHR ''t'' +\n                                                        min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))\n                                                   (pc -\n                                                    (task_s CHR ''c'' +\n                                                     min (pd - task_s CHR ''t'') (pc - task_s CHR ''c'')))) = 0\")\n                                     apply auto\n                                    apply(rule wait_orig_assn.intros(1))\n                                     apply(rule out_0assm_srdy_assn.intros(2))\n                                    using pre' by auto\n                                  subgoal by auto\n                                  subgoal by auto\n                                  subgoal unfolding propc_def  by auto\n                                  subgoal using pre properl_p4 unfolding proper_def properp_def by auto\n                                  subgoal by auto\n                                  done\n                                done\n                              by auto\n                            subgoal for v2 tr2'\n                              apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                               prefer 2\n                              subgoal using pre unfolding proper_def propc_def properp_def by auto\n                              apply(simp del: tdsch1'.simps)\n                              apply(elim combine_blocks_unpairE3')\n                              subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                              apply (simp only: tdsch1'.simps)\n                              apply(rule disjI2)\n                              apply(rule disjI2)\n                              apply(rule disjI1)\n                              apply(rule waitin_tguar'_vassm'_assn.intros(3))\n                                by auto\n                            subgoal for d2 v2 tr2'\n                              apply(subgoal_tac\"rp = 2 \\<and> rn = 1\")\n                               prefer 2\n                              subgoal using pre unfolding proper_def propc_def properp_def by auto\n                              apply(simp del: tdsch1'.simps)\n                              apply(cases \"d2>(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE3[where ?d1.0 = \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"])\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply simp\n                                apply(elim combine_blocks_waitE1)\n                                apply(cases rdy1)\n                                by auto\n                              apply(cases \"d2<(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply(elim combine_blocks_waitE4[where ?d1.0 = \"(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\"])\n                                subgoal by auto\n                                subgoal by auto\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply (simp only: tdsch1'.simps)\n                                apply(rule disjI2)\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(elim combine_blocks_unpairE3')\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply auto\n                                apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                                by auto\n                              apply(cases \"d2=(min (pd - task_s CHR ''t'') (pc - task_s CHR ''c''))\")\n                              subgoal\n                                apply (simp only: tdsch1'.simps)\n                                apply(rule disjI2)\n                                apply(rule disjI2)\n                                apply(rule disjI1)\n                                apply(elim combine_blocks_waitE2)\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply auto\n                                apply(elim combine_blocks_unpairE3')\n                                subgoal by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def dispatch_ch_def)\n                                apply auto\n                                apply(rule waitin_tguar'_vassm'_assn.intros(4))\n                                   by auto\n                                 by auto\n                               done\n                             done\n                           done\n                         done\n                       done\n                     by auto\n                   by auto\n                 done\n               done\n           qed\n                                \n\nend", "meta": {"author": "bzhan", "repo": "mars", "sha": "d10e489a8ddf128a4cbac13291efdece458d732d", "save_path": "github-repos/isabelle/bzhan-mars", "path": "github-repos/isabelle/bzhan-mars/mars-d10e489a8ddf128a4cbac13291efdece458d732d/lunarlander_sl/ext1/System_scheduler.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7025300698514777, "lm_q2_score": 0.38861802670584894, "lm_q1q2_score": 0.2730158494472035}}
{"text": "theory GeneralKnowledge  (*Benzmüller, Fuenmayor & Lomfeld, 2020*)  \n  imports ValueOntology \nbegin (*** General Legal and World Knowledge (LWK) ***)\n\n(*LWK: kinds of situations addressed*)\nconsts appObject::\"\\<sigma>\"      (*appropriation of objects in general*)\nconsts appAnimal::\"\\<sigma>\"      (*appropriation of animals in general*)\nconsts appWildAnimal::\"\\<sigma>\"  (*appropriation of wild animals*)\nconsts appDomAnimal::\"\\<sigma>\"   (*appropriation of domestic animals*)\n\n(*LWK: meaning postulates for kinds of situations*)\naxiomatization where \nW1: \"\\<lfloor>(appWildAnimal \\<^bold>\\<or> appDomAnimal) \\<^bold>\\<leftrightarrow> appAnimal\\<rfloor>\" and \nW2: \"\\<lfloor>appWildAnimal \\<^bold>\\<leftrightarrow> \\<^bold>\\<not>appDomAnimal\\<rfloor>\" and \nW3: \"\\<lfloor>appWildAnimal \\<^bold>\\<rightarrow> appAnimal\\<rfloor>\"  and\nW4: \"\\<lfloor>appDomAnimal \\<^bold>\\<rightarrow> appAnimal\\<rfloor>\" and\nW5: \"\\<lfloor>appAnimal \\<^bold>\\<rightarrow> appObject\\<rfloor>\" \n(*\\<dots>further situations regarding appropriation of objects\\<dots>*)\n\n(*LWK: value preferences for kinds of situations*)\n axiomatization where \n L2: \"\\<lfloor>appWildAnimal \\<^bold>\\<rightarrow> (x\\<inverse>\\<upharpoonleft>WILL \\<^bold>\\<prec> x\\<upharpoonleft>STAB)\\<rfloor>\" and         \n L3: \"\\<lfloor>appDomAnimal  \\<^bold>\\<rightarrow> (x\\<inverse>\\<upharpoonleft>STAB \\<^bold>\\<prec> x\\<upharpoonleft>[RELI\\<oplus>RESP])\\<rfloor>\"\n(*\\<dots>further preferences\\<dots>*)\n\nlemma True nitpick[satisfy] oops (*consistency, model found*)\n\n(*LWK: general legal notions, with an existing clear definition*)\nconsts Own::\"c\\<Rightarrow>\\<sigma>\"    (*object is owned by party c*)\nconsts Poss::\"c\\<Rightarrow>\\<sigma>\"   (*party c has actual possession of object*)\nconsts Intent::\"c\\<Rightarrow>\\<sigma>\" (*party c has intention to possess object*)\n\n(*LWK: other notions with some legal relevance (e.g. 'factors')*)\nconsts Liv::\"c\\<Rightarrow>\\<sigma>\" (*party c is pursuing its livelihood*)\nconsts Mtn::\"c\\<Rightarrow>\\<sigma>\" (*party c respons. for maintenance of object*)\n\n(*LWK: meaning postulates for general notions*)\naxiomatization where\nW6: \"\\<lfloor>Poss x \\<^bold>\\<rightarrow> (\\<^bold>\\<not>Poss x\\<inverse>)\\<rfloor>\" and \nW7: \"\\<lfloor>Own x \\<^bold>\\<rightarrow> (\\<^bold>\\<not>Own x\\<inverse>)\\<rfloor>\"\n(*\\<dots>others\\<dots>*)\n\n(*LWK: conditional legal value preferences*)\n axiomatization where \nL5: \"\\<lfloor>(Poss x \\<^bold>\\<and> \\<^bold>\\<not>Mtn x\\<inverse>)  \\<^bold>\\<rightarrow> (x\\<inverse>\\<upharpoonleft>RELI \\<^bold>\\<prec> (x\\<upharpoonleft>STAB))\\<rfloor>\" and\nL6: \"\\<lfloor>(Own x \\<^bold>\\<and> Intent x \\<^bold>\\<and> Poss x\\<inverse>)  \\<^bold>\\<rightarrow> (x\\<inverse>\\<upharpoonleft>STAB \\<^bold>\\<prec> x\\<upharpoonleft>[RELI\\<oplus>WILL])\\<rfloor>\"\n(*\\<dots>others\\<dots>*)\n\n(*LWK: value preferences given certain situational factors*)\naxiomatization where \nR1: \"\\<lfloor>For x \\<^bold>\\<rightarrow> (Intent x \\<^bold>\\<leftrightarrow> \\<^bold>\\<box>\\<^sup>\\<preceq>(x\\<upharpoonleft>WILL))\\<rfloor>\" and  \nR2: \"\\<lfloor>For x \\<^bold>\\<rightarrow> (Liv x \\<^bold>\\<leftrightarrow> \\<^bold>\\<box>\\<^sup>\\<preceq>(x\\<upharpoonleft>GAIN))\\<rfloor>\" and  \nR3: \"\\<lfloor>For x \\<^bold>\\<rightarrow> (Poss x \\<^bold>\\<leftrightarrow> \\<^bold>\\<box>\\<^sup>\\<preceq>(x\\<upharpoonleft>STAB))\\<rfloor>\" and  \nR4: \"\\<lfloor>For x \\<^bold>\\<rightarrow> (Mtn x \\<^bold>\\<leftrightarrow> \\<^bold>\\<box>\\<^sup>\\<preceq>(x\\<upharpoonleft>RESP))\\<rfloor>\" and  \nR5: \"\\<lfloor>For x \\<^bold>\\<rightarrow> (Own x \\<^bold>\\<leftrightarrow> \\<^bold>\\<box>\\<^sup>\\<preceq>(x\\<upharpoonleft>RELI))\\<rfloor>\"\n(*\\<dots>others\\<dots>*)\n\nlemma True nitpick[satisfy] oops (*consistency, model found*)\nend\n\n\n", "meta": {"author": "cbenzmueller", "repo": "LogiKEy", "sha": "5c16bdeb68bf8131e24ba9c8d774d4af663cb2cf", "save_path": "github-repos/isabelle/cbenzmueller-LogiKEy", "path": "github-repos/isabelle/cbenzmueller-LogiKEy/LogiKEy-5c16bdeb68bf8131e24ba9c8d774d4af663cb2cf/Preference-Logics/vanBenthemEtAl2009/OLD/GeneralKnowledge.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953651858118, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.272972516948216}}
{"text": "(* memory_model.thy *)\n(* William Mansky *)\n(* Memory model locales for PTRANS. *)\n\ntheory memory_model\nimports \"$AFP/List-Infinite/ListInfinite\" AxiomaticModel\nbegin\n\n(*\nprint_locale \"ord\"\n\ninstantiation option :: (ord) ord\nbegin\nfun less_eq_option where\n   \"(None \\<le> None) = True\"\n | \"(None \\<le> (Some _ )) = True\"\n | \"((Some _) \\<le> None) = False\"\n | \"((Some x) \\<le> (Some y)) = (x \\<le> y)\"\n\nfun less_option where\n   \"(None < None) = False\"\n | \"(None < (Some _)) = True\"\n | \"((Some _) < None) = False\"\n | \"((Some x) < (Some y)) = (x < y)\"\n\ninstance proof qed\nend\n\nlemma map_add_dom_upd [simp]: \"dom m' = {k} \\<Longrightarrow> (m ++ m')(k \\<mapsto> v) = m(k \\<mapsto> v)\"\nby (auto intro!: ext simp add: map_add_def split: option.splits)\n\nlemma dud_set [simp]: \"{(l, v). False} = {}\"\nby simp\n\n(* Extra utility function: enumerate the elements of a set in arbitrary order. \n   Useful for memory models. Could conceivably be replaced by Eps over finite_distinct_list. *)\nthm finite_distinct_list\nfunction list_of_set where\n\"list_of_set S = (if infinite S \\<or> S = {} then [] else let a = SOME a. a \\<in> S in a # list_of_set (S - {a}))\"\nby pat_completeness auto\ntermination \napply (relation \"measure (\\<lambda>S. card S)\", auto)\napply (frule card_Diff_singleton, rule someI, simp)\napply (case_tac \"card S\", simp_all)\ndone\nlemma list_of_set_empty [simp]: \"list_of_set {} = []\"\nby simp\nlemma list_of_set_inf [simp]: \"infinite S \\<Longrightarrow> list_of_set S = []\"\nby simp\nlemma list_of_set_card [simp]: \"(list_of_set S \\<noteq> []) = (card S \\<noteq> 0)\"\nby (auto simp add: Let_def)\ndeclare list_of_set.simps [simp del]\n\nlemma set_some [simp]: \"S \\<noteq> {} \\<Longrightarrow> insert (SOME a. a \\<in> S) S = S\"\nby (metis insert_absorb not_ex_in_conv someI)\n\nlemma set_some2 [simp]: \"S \\<noteq> {} \\<Longrightarrow> (SOME a. a \\<in> S) \\<in> S\"\nby (metis not_ex_in_conv someI)\n\nlemma list_of_set_set [simp]: \"finite S \\<Longrightarrow> set (list_of_set S) = S\"\napply (induct \"card S\" arbitrary: S, simp_all)\napply (rule trans, simp add: list_of_set.simps, simp add: Let_def)\ndone\n\ncorollary list_of_set_nth: \"\\<lbrakk>list_of_set S ! i = x; i < length (list_of_set S)\\<rbrakk> \\<Longrightarrow> x \\<in> S\"\napply (subgoal_tac \"finite S\", subgoal_tac \"x \\<in> set (list_of_set S)\", simp, \n simp add: set_conv_nth, force)\napply (auto simp add: list_of_set.simps split: if_splits)\ndone\n\nlemma list_of_set_distinct [simp]: \"distinct (list_of_set S)\"\napply (induct \"card S\" arbitrary: S, clarsimp simp add: list_of_set.simps)\napply (rule_tac P=distinct in list_of_set.simps [THEN sym [THEN subst]], clarsimp simp add: Let_def)\ndone  \n\ndatatype ('thread, 'loc, 'val) access = Read 'thread 'loc 'val | Write 'thread 'loc 'val \n  | ARW 'thread 'loc 'val 'val | Alloc 'thread 'loc | Free 'thread 'loc\nprimrec get_thread where\n\"get_thread (Read t _ _) = t\" |\n\"get_thread (Write t _ _) = t\" |\n\"get_thread (ARW t _ _ _) = t\" |\n\"get_thread (Alloc t _) = t\" |\n\"get_thread (Free t _) = t\"\nprimrec get_loc where\n\"get_loc (Read _ l _) = l\" |\n\"get_loc (Write _ l _) = l\" |\n\"get_loc (ARW _ l _ _) = l\" |\n\"get_loc (Alloc _ l) = l\" |\n\"get_loc (Free _ l) = l\"\nprimrec set_thread where\n\"set_thread t' (Read t l v) = Read t' l v\" |\n\"set_thread t' (Write t l v) = Write t' l v\" |\n\"set_thread t' (ARW t l v v') = ARW t' l v v'\" |\n\"set_thread t' (Alloc t l) = Alloc t' l\" |\n\"set_thread t' (Free t l) = Free t' l\"\nlemma set_get_thread [simp]: \"set_thread (get_thread a) a = a\"\nby (case_tac a, auto)\nlemma get_set_thread [simp]: \"get_thread (set_thread t a) = t\"\nby (case_tac a, auto)\nlemma set_thread_frees [simp]: \"set_thread t' ` Free t ` S = Free t' ` S\"\nby (auto simp add: image_def)\n\nabbreviation \"get_ptrs ops \\<equiv> get_loc ` ops\"\n\n\ntype_synonym ('block, 'os) pointer = \"'block * 'os\"\ntype_synonym ('add, 'size) block_structure = \"'add * 'size\"\n\ndatatype ('add,'val,'size,'os) raw_block =\n    RawBlk \"('add, 'size) block_structure\" \"('os \\<rightharpoonup> 'val)\"\n\ntype_synonym ('add, 'val, 'size) allocation = \"(('add, 'size) block_structure) set\"\n\ntype_synonym ('add,'val,'size,'os) block_allocation = \"('add,'val,'size,'os) raw_block set\"\n\nfun get_addr_s where\n  \"get_addr_s ((addr,_)::(('add,'size) block_structure)) = addr\"\n\nfun get_size_s where\n  \"get_size_s ((_,s)::(('add,'size) block_structure)) = s\"\n\nfun get_addr where \"get_addr ( RawBlk (addr,_) _) = addr\"\n\nfun get_size where \"get_size (RawBlk(_,s) _) = s\"\n\nfun block_to_struct where \"block_to_struct (RawBlk blk _) = blk\"\n\ndeclare[[show_types = true]]\ndeclare[[show_sorts = true]]\n  \n(* locale for reasoning about blocks and the mapping of block offsets to memory locations *)\n(* FUNCTIONS *)\n(* block_s_start: partial function giving the first memory location of a \n    block_structure (if it exists) \n   block_exists: see assumptions for block existence conditions \n   block_start_os: gives the offset of a block that can be passed into block_s_ptr\n    such that the same memory location is returned as for block_s_start \n   block_s_ptr: partial function mapping offsets into a block to memory locations \n   size_to_offset: conversion between abstract types *)\n(* ASSUMPTIONS *)\n(* block_firstlast_offset: if a block exists, the start offset must be \\<le> the offset\n    returned by calling size_to_offset on the block size (corresponds to the last memory\n    location of the block.\n   pointer_inbounds_exists: For any offset into a block that is between the start \n    and end offsets (inclusive), there must be a valid mapping to a memory location for\n    that offset.\n   block_s_same_add_same_loc: Two blocks with the same starting address must also have\n    the same starting memory location.\n   block_s_ptr_monotonic: block_s_ptr is a monotonic function\n   block_s_ptr_one_to_one: block_s_ptr is a one to one function\n   block_s_start_offset: Assumes that block_start_os is a total function. There will\n    exist an offset such that block_s_ptr and block_s_start will be equal (even if\n    it is because they both return None) *)\nlocale block_structure =\n  fixes block_s_start::\"('add, 'size::ord) block_structure \\<rightharpoonup> ('loc::ord)\"\n    and block_exists::\"('add, 'size::ord) block_structure \\<Rightarrow> bool\"\n    and block_start_os :: \"('add, 'size::ord) block_structure \\<Rightarrow> ('os::{ord,plus})\"\n    and block_s_ptr::\"('add, 'size) block_structure * 'os \\<rightharpoonup> ('loc::ord)\"\n    and size_to_offset::\"'size \\<Rightarrow> 'os\"\n    and struct_to_rb::\"('add,'size) block_structure \\<Rightarrow> ('add,'val,'size,'os) raw_block\"\n  assumes block_exists_defin: \"block_exists blk = (\\<exists>x. block_s_start(blk) = (Some x))\"\n      and block_firstlast_offset:\n          \"block_exists (addr,size1) \\<Longrightarrow>\n           (block_start_os (addr,size1)) \\<le> (size_to_offset size1)\"\n      and pointer_inbounds_exists:\n          \"\\<lbrakk>block_exists (addr,size1); os \\<ge> block_start_os(addr,size1); \n            os \\<le> size_to_offset(size1)\\<rbrakk> \\<Longrightarrow>\n           \\<exists> l. (block_s_ptr ((addr,size1),os) = (Some l))\"\n      and block_s_same_add_same_loc:\n        \"\\<lbrakk>block_exists (add, size1); block_exists (add, size2)\\<rbrakk> \\<Longrightarrow>\n        block_s_start (add,size1) = block_s_start(add, size2)\"\n      and block_s_ptr_monotonic: \"\\<lbrakk>os1 < os2; block_s_ptr(blk,os1) = Some x;\n                                   block_s_ptr(blk,os2) = Some y\\<rbrakk> \\<Longrightarrow> x < y\"\n      and block_s_ptr_one_to_one: \"\\<lbrakk>block_s_ptr(blk,os1) = Some x;\n                                   block_s_ptr(blk,os2) = Some y;\n                                   (x = y)\\<rbrakk> \\<Longrightarrow> (os1 = os2)\"\n      and block_s_start_offset: \"\\<exists>os_1. block_s_ptr(blk,os_1) = block_s_start(blk)\"\n      and block_s_start_defin: \"(block_s_start blk = block_s_ptr(blk,(block_start_os blk)))\"\ncontext block_structure\nbegin\n\nfun good_block_s_ptr where\n  \"good_block_s_ptr ((start,len), os) = ((block_exists (start,len)) \\<and> \n  ((block_start_os (start,len)) \\<le> os) \\<and> (os \\<le> (size_to_offset len)))\"\n\nfun good_rb_s_pair where\n  \"good_rb_s_pair blk1 blk2 =\n  ((\\<exists> os_1. (\\<exists> os_2. ((good_block_s_ptr(blk1,os_1)) \\<and>\n                      (good_block_s_ptr(blk2,os_2)) \\<and>\n                      ((good_block_s_ptr(blk1,os_1)) = (good_block_s_ptr(blk2,os_2)))))) \\<longrightarrow>\n   (blk1 = blk2))\"\n  \nfun good_allocation where\n  \"good_allocation (alloc::('add,'val,'size) allocation) = \n  (\\<forall> rb1 \\<in> alloc. (\\<forall> rb2 \\<in> alloc. (good_rb_s_pair rb1 rb2)))\"\n  \nfun good_block_allocation where\n  \"good_block_allocation (alloc::('add,'val,'size,'os) block_allocation) =\n  good_allocation (block_to_struct ` alloc)\"\n\nlemma good_rb_s_pair_refl [simp]: \"good_rb_s_pair a a\"\napply auto\ndone\nlemma good_rb_s_pair_symm [simp]: \"good_rb_s_pair a b = good_rb_s_pair b a\"\napply auto\ndone\nlemma good_rb_s_pair_trans [simp]: \"((good_allocation alloc) \\<and> \n  (a \\<in> alloc) \\<and> (b \\<in> alloc) \\<and> (c \\<in> alloc) \\<and> \n  (good_rb_s_pair a b) \\<and> (good_rb_s_pair b c) \\<longrightarrow> good_rb_s_pair a c)\"\napply auto\ndone\nend\n\ntype_synonym ('block,'size, 'os) access_region = \"('block * 'size * 'os)\"\n\ntype_synonym ('add,'val,'size,'os) block_access_region =\n    \"(('add,'val,'size,'os) raw_block,'size,'os) access_region\"\n    \ntype_synonym ('add,'val,'size,'os) block_s_access_region =\n    \"(('add,'size) block_structure,'size,'os) access_region\"\n\nfun region_get_block where\n  \"region_get_block ((b,s,os)::('block,'size, 'os) access_region) = b\"\n   \ncontext block_structure\nbegin\n\n (* Define the set of ptr or os that are \"in\" a region *)\nfun os_in_region where\n  \"os_in_region ((b,s,os1)::('add,'val,'size,'os) block_access_region) (os2::'os) = \n    ((((block_start_os (block_to_struct b))+os1) \\<le> os2) \\<and> \n    (((block_start_os (block_to_struct b))+os1+(size_to_offset s)) \\<ge> os2))\"\n\nfun region_eq where\n  \"region_eq ((b1, s1, os1)::('add,'val,'size,'os) block_access_region)\n  ((b2, s2, os2)::('add,'val,'size,'os) block_access_region) = \n  ((block_s_ptr((block_to_struct b1),os1) = block_s_ptr((block_to_struct b2),os2))\n  \\<and> (block_s_ptr((block_to_struct b1),(os1+(size_to_offset s1))) = \n  block_s_ptr((block_to_struct b2),(os2+(size_to_offset s2)))))\"\n\nlemma region_eq_all_ptr:\n  \"region_eq (b1,s1,os1) (b2, s2, os2) \\<Longrightarrow> (\\<forall> (os_a::'os). \\<exists> (os_b::'os).\n    (((os_in_region (b1,s1,os1) os_a) \\<and> (os_in_region (b2,s2,os2) os_b))\n    \\<and> (block_s_ptr((block_to_struct b1),os_a)) = block_s_ptr((block_to_struct b2),os_b)))\"\n  oops\n   \nfun region_overlap where\n  \"region_overlap ((b1, s1, os1)::('add,'val,'size,'os) block_access_region)\n  ((b2, s2, os2)::(('add,'val,'size,'os) block_access_region)) = (\\<exists> (os_a::'os). \n  (\\<exists> (os_b::'os). ((os_a \\<ge> os1) \\<and> (os_b \\<ge> os2) \\<and> (os_a \\<le> (os1+(size_to_offset s1))) \\<and>\n  (os_b \\<le> (os2+(size_to_offset s2))) \\<and> (block_s_ptr((block_to_struct b1),os_a)) = \n  block_s_ptr((block_to_struct b2),os_b))))\"\n\nfun region_inbounds where\n  \"region_inbounds ((b, s, os)::('add,'val,'size,'os) block_access_region)\n  = (((os + (size_to_offset s)) \\<le> (size_to_offset (get_size b))) \\<and> \n  (block_start_os((block_to_struct b)) \\<le> os))\"\n  \n(* tells us if a region describes an entire block *)\nfun region_block_eq where\n  \"region_block_eq ((b, s, os)::('add,'val,'size,'os) block_access_region)\n  = ((block_start_os((block_to_struct b)) = os) \\<and> ((get_size_s(block_to_struct b)) = s))\"\nend\n\ndeclare[[show_types = true]] \ndeclare[[show_sorts = true]]\n*)\n\ncontext axiomaticModel begin\n\nterm observeMem\n\nend\n\nlocale memory_model = axiomaticModel\n  where actions =  \"actions :: (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action set\"\n    and locations = \"locations :: loc_type set\"\n    and actionIDs = \"actionIDs :: aid_type set\"\n    and times = \"times :: time_type set\"\n    and threads = \"threads :: 'tid set\"\n    and locks = \"locks :: 'lock set\"\n    and names = \"names :: 'name set\"\n    and callIDs = \"callIDs :: 'callID set\" \n  for actions locations actionIDs times threads locks names callIDs + \n  fixes free_set::\"(('tid \\<times> time_type \\<times> loc_type)\n            \\<Rightarrow> (aid_type \\<times> (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action) option)\n             \\<Rightarrow> time_type \\<Rightarrow> loc_type set\"\nand can_read::\"(('tid \\<times> time_type \\<times> loc_type)\n            \\<Rightarrow> (aid_type \\<times> (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action) option)\n            \\<Rightarrow>'tid \\<Rightarrow> time_type \\<Rightarrow> loc_type \\<Rightarrow> 'val set\"\nand update_mem::\"(('tid \\<times> time_type \\<times> loc_type)\n            \\<Rightarrow> (aid_type \\<times> (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action) option)\n                       \\<Rightarrow> time_type \\<Rightarrow> ('tid \\<times> aid_type \\<times>\n                             (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action) set\n                        \\<Rightarrow> (('tid \\<times> time_type \\<times> loc_type)\n            \\<Rightarrow> (aid_type \\<times> (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action) option) \\<Rightarrow> bool\"\nand start_mem:: \"(('tid \\<times> time_type \\<times> loc_type)\n            \\<Rightarrow> (aid_type \\<times> (aid_type, 'val, loc_type, 'lock, 'name, 'callID) action) option)\"\nassumes alloc_not_free: \"\\<lbrakk>update_mem mem time ops mem'; (tid,aid,Create l) \\<in> ops\\<rbrakk> \\<Longrightarrow> \n l \\<notin> free_set mem' time\"\n    and stays_not_free: \"\\<lbrakk>update_mem mem time ops mem'; l \\<notin> free_set mem time\\<rbrakk> \\<Longrightarrow>\n l \\<notin> free_set mem' time\"\n\n\n (*\ndatatype ('thread, 'add, 'size,'os) block_access =\n    bRead 'thread \"('add,'size,'os) block_s_access_region\" 'val\n  | bWrite 'thread \"('add,'size,'os) block_s_access_region\" 'val\n  | bARW 'thread \"('add,'size,'os) block_s_access_region\" 'val 'val\n  | bAlloc 'thread \"('add,'size) block_structure\"\n  | bFree 'thread \"('add,'size) block_structure\"\n  \ndatatype ('thread, 'block, 'region,'val) block_access =\n    bRead 'thread 'region 'val\n  | bWrite 'thread 'region 'val\n  | bARW 'thread 'region 'val 'val\n  | bAlloc 'thread 'block\n  | bFree 'thread 'block\n*)\n\n(*\nlocale block_structur =\n  fixes good_block ::\"'block \\<Rightarrow> bool\"\n    and good_region :: \"'region \\<Rightarrow> bool\"\n    and block_overlap::\"'block \\<Rightarrow> 'block \\<Rightarrow> bool\"\n    and region_overlap::\"'region \\<Rightarrow> 'region \\<Rightarrow> bool\"\n    and subblock::\"'block \\<Rightarrow> 'block \\<Rightarrow> bool\"\n    and subregion :: \"'region \\<Rightarrow> 'region \\<Rightarrow> bool\"\n    and region_get_block ::\"'region \\<Rightarrow> 'block\"\n    and block_as_region ::\"'block \\<Rightarrow> 'region\"\n    and value_fits_region :: \"'val \\<Rightarrow> 'region \\<Rightarrow> bool\"\n    and region_fits_block ::\"'region \\<Rightarrow> 'block \\<Rightarrow> bool\"\n    (* define does_not_modify later *)\n    and does_not_modify :: \"('thread, 'block, 'region,'val) block_access \n        \\<Rightarrow> 'region \\<Rightarrow>  bool\" \n   (* and get_access_region:: \"('thread, 'block, 'region,'val) block_access \\<Rightarrow> 'region\"*)\n  assumes value_fits_bigger_region :\n    \"\\<lbrakk> subregion r1 r2; value_fits_region v r1 \\<rbrakk> \\<Longrightarrow> value_fits_region v r2\"\n  and subblock_good: \"\\<lbrakk>good_block b ; subblock b' b\\<rbrakk> \\<Longrightarrow> good_block b'\"\n  and region_overlap_symm: \"region_overlap r r' \\<Longrightarrow> region_overlap r' r\"\n(*  and dummy: \"\\<exists> b. block_as_region b = block_as_region b\" *)\n\nfun (in block_structur) get_access_region::\"('thread, 'block, 'region,'val) block_access \\<Rightarrow> 'region\" where\n  \"get_access_region (bRead _ r _) = r\" |\n  \"get_access_region (bWrite _ r _) = r\" |\n  \"get_access_region (bARW _ r _ _) = r\" |\n  \"get_access_region (bAlloc _ b) = (block_as_region b)\" |\n  \"get_access_region (bFree _ b) = (block_as_region b)\"\nthm block_structur.get_access_region.simps\nthm block_structur_def\n\nlocale basic_can_do = block_structur\n  where     good_block = \"good_block :: 'block \\<Rightarrow> bool\"\n    and     good_region = \"good_region :: 'region \\<Rightarrow> bool\"\n  for       good_block \n    and     good_region +\n  fixes     can_do::\"('thread, 'block, 'region,'val) block_access list \\<Rightarrow> \n            ('thread, 'block, 'region,'val) block_access \\<Rightarrow> bool\"\n  assumes   base_allows_alloc: \"good_block b \\<Longrightarrow> (can_do [] (bAlloc t b))\"     \n    and     free_allows_alloc: \"\\<lbrakk>good_block b; can_do m (bFree t b); subblock b' b\\<rbrakk>\n            \\<Longrightarrow> (can_do ((bFree t b)#m) (bAlloc t' b'))\"\n    and     alloc_allows_free: \"\\<lbrakk>good_block b; can_do m (bAlloc t b)\\<rbrakk> \\<Longrightarrow> \n            (can_do ((bAlloc t b)#m) (bFree t b))\"\n   (* and     alloc_allows_write: \"\\<lbrakk>good_block b; can_do m (bAlloc t b); \n            region_fits_block r b\\<rbrakk> \\<Longrightarrow> \n            (can_do ((bAlloc t b)#m) (bWrite t' r v))\"*)\n    and     alloc_allows_write_same_thread: \"\\<lbrakk>good_block b; can_do m (bAlloc t b); \n            region_fits_block r b\\<rbrakk> \\<Longrightarrow> \n            (can_do ((bAlloc t b)#m) (bWrite t r v))\"\n    and     write_any_value_same_thread: \"\\<lbrakk>value_fits_region v' r; \n            (can_do m (bWrite t r v))\\<rbrakk> \\<Longrightarrow> (can_do m (bWrite t r v'))\"\n    and     not_mod_write_drop: \"\\<lbrakk>can_do m opr; does_not_modify opr r; \n            can_do (opr#m) (bWrite t r v)\\<rbrakk> \n            \\<Longrightarrow> can_do m (bWrite t r v)\"\n    and     not_mod_write_add: \"\\<lbrakk>can_do m opr; does_not_modify opr r;\n            can_do m (bWrite t r v)\\<rbrakk> \\<Longrightarrow> can_do (opr#m) (bWrite t r v)\"\n    and     write_not_read_drop: \"\\<lbrakk>can_do m (bWrite t r v); \n            \\<forall>r' v' .(region_overlap r r') \\<longrightarrow> (opr \\<noteq> (bRead t' r' v'));\n            can_do ((bWrite t r v)#m) opr\\<rbrakk> \\<Longrightarrow> can_do m opr\"\n    and     write_not_read_add: \"\\<lbrakk>can_do m (bWrite t r v); \n            \\<forall>r' v' .(region_overlap r r') \\<longrightarrow> (opr \\<noteq> (bRead t' r' v'));\n            can_do m opr\\<rbrakk> \\<Longrightarrow> can_do ((bWrite t r v)#m) opr\"\n    and     read_only_written: \"\\<lbrakk>can_do m (bWrite t r v); \n            can_do ((bWrite t r v)#m) (bRead t' r v')\\<rbrakk> \\<Longrightarrow> v = v'\"\n    and     read_written: \"can_do m (bWrite t r v) \\<Longrightarrow>\n            can_do ((bWrite t r v)#m) (bRead t' r v)\"\n    and     read_noop_drop: \"\\<lbrakk>can_do m (bRead t r v); can_do ((bRead t r v)#m) opr\\<rbrakk>\n            \\<Longrightarrow> can_do m opr\"\n    and     read_noop_add: \"\\<lbrakk>can_do m (bRead t r v); can_do m opr\\<rbrakk>\n            \\<Longrightarrow> can_do ((bRead t r v)#m) opr\"\n    and     reg_drop: \"\\<lbrakk>\\<not>(region_overlap (get_access_region opr) (get_access_region opr'));\n            can_do m opr; can_do (opr#m) opr'\\<rbrakk> \\<Longrightarrow> can_do m opr'\"\n    and     reg_add: \"\\<lbrakk>\\<not>(region_overlap (get_access_region opr) (get_access_region opr'));\n            can_do m opr; can_do m opr'\\<rbrakk> \\<Longrightarrow> can_do (opr#m) opr'\"\n    (*and     reg_comm: \"\\<lbrakk>\\<not>(region_overlap (get_access_region opr) (get_access_region opr'));\n            can_do (opr#m) opr'\\<rbrakk> \\<Longrightarrow> can_do (opr'#m) opr\"*)\n    and     prefix_closed: \"\\<lbrakk>can_do (opr#m) opr'\\<rbrakk> \\<Longrightarrow> can_do m opr\"\n\nlemma (in basic_can_do) reg_comm: \"\\<lbrakk>\\<not>(region_overlap (get_access_region opr) (get_access_region opr'));\n            can_do (opr#m) opr'\\<rbrakk> \\<Longrightarrow> can_do (opr'#m) opr\"\napply (rule reg_add)\napply (erule contrapos_nn)\napply (erule_tac r = \"(get_access_region opr')\" and r' = \"(get_access_region opr)\"\n       in region_overlap_symm)\nprefer 2\napply (erule prefix_closed)\napply (erule reg_drop)\napply (erule prefix_closed)\napply auto\ndone\n\n            \n  (* Commented out to the end\ncontext block_structure\nbegin\nprimrec block_get_thread where\n\"block_get_thread (bRead t _ _) = t\" |\n\"block_get_thread (bWrite t _ _) = t\" |\n\"block_get_thread (bARW t _ _ _) = t\" |\n\"block_get_thread (bAlloc t _) = t\" |\n\"block_get_thread (bFree t _) = t\"\nfun block_get_region where\n\"block_get_region (bRead _ r  _) = r\" |\n\"block_get_region (bWrite _ r _) = r\" |\n\"block_get_region (bARW _ r  _ _) = r\"|\n\"block_get_region (bAlloc _ b) = ((struct_to_rb b),(get_size_s b),(block_start_os(b)))\" |\n\"block_get_region (bFree _ b) = ((struct_to_rb b),(get_size_s b),(block_start_os(b)))\"\nprimrec block_get_block where\n\"block_get_block (bRead _ r _) = (region_get_block r)\" |\n\"block_get_block (bWrite _ r _) = (region_get_block r)\" |\n\"block_get_block (bARW _ r _ _) = (region_get_block r)\" |\n\"block_get_block (bAlloc _ b) = (struct_to_rb b)\" |\n\"block_get_block (bFree _ b) = (struct_to_rb b)\"\nprimrec block_set_thread where\n\"block_set_thread t' (bRead t r v) = bRead t' r v\" |\n\"block_set_thread t' (bWrite t r v) = bWrite t' r v\" |\n\"block_set_thread t' (bARW t r v v') = bARW t' r v v'\" |\n\"block_set_thread t' (bAlloc t l) = bAlloc t' l\" |\n\"block_set_thread t' (bFree t l) = bFree t' l\" \nend\n\n locale block_seq_can_do = fixes can_do::\"('thread,'add,'val,'size,'os) \n  block_access list \\<Rightarrow> ('thread,'add,'val,'size,'os) block_access \\<Rightarrow> bool\"\nassumes base_allows_alloc: \"(can_do [] (bAlloc t b))\"\n    and free_allows_alloc: \"\\<lbrakk>can_do m (bFree t b); b=b'\\<rbrakk>\n          \\<Longrightarrow> (\\<not>(can_do ((bFree t b)#m) (bFree t' b')))\"\n    and alloc_allows_write: \"\\<lbrakk>can_do m (bAlloc t b); \n          region_inbounds ((struct_to_block b),s,os)\\<rbrakk> \\<Longrightarrow> \n          (can_do ((bAlloc t b)#m) \n          (bWrite t' ((struct_to_block b),s,os) v))\"\n    and alloc_allows_alloc: \"\\<lbrakk>can_do m (bAlloc t b); b=b'\\<rbrakk> \\<Longrightarrow> \n          (\\<not>(can_do ((bAlloc t b)#m) (bAlloc t' b')))\"\n    and alloc_allows_free: \"\\<lbrakk>can_do m (bAlloc t b); b=b'\\<rbrakk> \\<Longrightarrow> \n          (can_do ((bAlloc t b)#m) (bFree t' b'))\"\n    and write_any_value: \"(can_do m (bWrite t r v)) = (can_do m (bWrite t' r v'))\"(*\n    and not_mod_write: \"\\<lbrakk>can_do m (bRead t' r' v'); can_do m (bWrite t' r' v'); \n      can_do m (bAlloc t' b); can_do m (bFree t' b); region_block_eq(b,s,os);\n      \\<not>(region_overlap r r'); \\<not>(region_overlap r (b,s,os))\\<rbrakk> \\<Longrightarrow> \n      ((can_do ((bRead t' r' v')#m) (bWrite t r v)) = \n        (can_do (m) (bWrite t r v))) \\<and> \n      ((can_do ((bWrite t' r' v')#m) (bWrite t r v)) = \n        (can_do (m) (bWrite t r v))) \\<and> \n      ((can_do ((bAlloc t' b)#m) (bWrite t r v)) = \n        (can_do (m) (bWrite t r v))) \\<and> \n      ((can_do ((bFree t' b)#m) (bWrite t r v)) = \n        (can_do (m) (bWrite t r v)))\" \n    and write_not_read: \"\\<lbrakk>can_do m (bWrite t r v);  opr \\<noteq> (bRead t' r v')\\<rbrakk> \\<Longrightarrow> \n      (can_do ((bWrite t r v)#m) opr) = (can_do m opr)\"\n    and read_written: \"\\<lbrakk>can_do m (bWrite t r v)\\<rbrakk> \\<Longrightarrow> ((can_do ((bWrite t r v)#m) \n      (bRead t' r v')) = (v = v'))\"\n    and read_noop: \"\\<lbrakk>can_do m (bRead t r v)\\<rbrakk> \\<Longrightarrow> (can_do ((bRead t r v)#m) opr = \n      can_do m opr)\"*)(*\n    and loc_drop: \"\\<lbrakk>\\<not>region_overlap((block_get_region opr) (block_get_region opr'));\n      (can_do m opr)\\<rbrakk> \\<Longrightarrow> (can_do (opr#m) opr') = (can_do m opr')\"  \n    and loc_comm: \"\\<lbrakk>\\<not>region_overlap((block_get_region opr) (block_get_region opr'))\\<rbrakk> \n      \\<Longrightarrow> (can_do (opr#m) opr') = (can_do (opr'#m) opr)\"*)\n      \nlocale block_seq_can_do_extend = block_seq_can_do +\n  assumes base_disallows_free:\"(\\<not>(can_do [] (bFree t b)))\"\n  and     free_dissallows_free:\"\\<lbrakk>can_do m (bFree t b); b=b'\\<rbrakk>\n          \\<Longrightarrow> (\\<not>(can_do ((bFree t b)#m) (bFree t' b')))\"\n \n \nlocale seq_can_do = fixes can_do::\"('thread, 'loc, 'val) access list \\<Rightarrow>\n  ('thread, 'loc, 'val) access \\<Rightarrow> bool\"\nassumes base_allows: \"(\\<not>(can_do [] (Read t l v))) \\<and> (can_do [] (Alloc t l))\n  \\<and>(\\<not>(can_do [] (Free t l)))\"\n    and free_allows: \"\\<lbrakk>can_do m (Free t l)\\<rbrakk> \\<Longrightarrow> (\\<not>(can_do ((Free t l)#m) (Read t' l v)))\n      \\<and> (can_do ((Free t l)#m) (Alloc t' l)) \\<and> (\\<not>(can_do ((Free t l)#m) (Free t' l)))\"\n    and alloc_allows: \"\\<lbrakk>can_do m (Alloc t l)\\<rbrakk> \\<Longrightarrow> (can_do ((Alloc t l)#m) (Write t l v))\n      \\<and> (\\<not>(can_do ((Alloc t l)#m) (Alloc t' l))) \\<and> (can_do ((Alloc t l)#m) (Free t l))\"\n    and write_any_value: \"(can_do m (Write t l v)) = (can_do m (Write t l v'))\"\n    and not_mod_write: \"\\<lbrakk>can_do m (Read t l v); can_do m (Write t l' v); \n      can_do m (Alloc t l'); can_do m (Free t l'); l \\<noteq> l'\\<rbrakk> \\<Longrightarrow> ((can_do ((Read t l v)#m) \n      (Write t' l v)) = (can_do (m) (Write t' l v))) \\<and> ((can_do ((Write t l' v)#m) \n      (Write t' l v)) = (can_do (m) (Write t' l v))) \\<and> ((can_do ((Alloc t l')#m) \n      (Write t' l v)) = (can_do (m) (Write t' l v))) \\<and> ((can_do ((Free t l')#m) \n      (Write t' l v)) = (can_do (m) (Write t' l v)))\" \n    and write_not_read: \"\\<lbrakk>can_do m (Write t l v);  opr \\<noteq> (Read t' l v')\\<rbrakk> \\<Longrightarrow> \n      (can_do ((Write t l v)#m) opr) = (can_do m opr)\"\n    and read_written: \"\\<lbrakk>can_do m (Write t l v)\\<rbrakk> \\<Longrightarrow> ((can_do ((Write t l v)#m) \n      (Read t' l v')) = (v = v'))\"\n    and read_noop: \"\\<lbrakk>can_do m (Read t l v)\\<rbrakk> \\<Longrightarrow> (can_do ((Read t l v)#m) a = can_do m a)\"\n    and loc_drop: \"\\<lbrakk>get_loc (opr) \\<noteq> get_loc(opr'); (can_do m opr)\\<rbrakk> \\<Longrightarrow> (can_do (opr#m) opr')\n      = (can_do m opr')\" \n    and loc_comm: \"\\<lbrakk>get_loc (opr) \\<noteq> get_loc(opr')\\<rbrakk> \\<Longrightarrow> (can_do (opr#m) opr') = \n      (can_do (opr'#m) opr)\"\n      \n    \n(* how can we define a memory as only being a \"good\" allocation? *)\n locale block_memory_model = fixes free_set::\"'memory \\<Rightarrow> 'a word set\"\nand can_read::\"'memory \\<Rightarrow> 'thread \\<Rightarrow> 'loc \\<Rightarrow> 'block set\"\nand update_mem::\"'memory \\<Rightarrow> ('thread, 'loc, 'val) block_access set \\<Rightarrow> 'memory \\<Rightarrow> bool\"\nand allocation::\"'loc allocation\"\nand start_mem::'memory\n(*and memory_max_word:: \"'loc::len word\" *) (*largest address *) (* note: we may want to condense these into one *)\nand memory_max_int:: int\nand memory_min:: int (* smallest address *)           \n(*assumes good_allocations: \"\\<lbrakk>update_mem mem ops mem'; good_allocation *)\n(*assumes good_allocation_word: \"good_allocation memory_max_word allocation\"*)\nassumes good_allocation_int: \"good_allocation (word_of_int memory_max_int) allocation\"\n\n\n\n(* TSO memory model *)\nlocale TSO = fixes undef::'val begin\n(* This isn't really a TSO-specific locale, but I might have other assumptions later.\n   More to the point, it's convenient to have a separate locale for each memory model, even if\n   they don't actually rely on separate assumptions. *)\n\nabbreviation \"free_set mem \\<equiv> UNIV - dom (fst mem)\"\ndefinition \"can_read mem t l \\<equiv> case List.find (\\<lambda>(l', v). l' = l) ((snd mem) t) of \n Some (l, v) \\<Rightarrow> {v} | None \\<Rightarrow> {v. fst mem l = Some v}\"\ndefinition \"can_read2 mem t l \\<equiv> case mem of (mem_map, bufs) \\<Rightarrow> (case List.find (\\<lambda>(l', v). l' = l) (bufs t) of \n Some (l, v) \\<Rightarrow> {v} | None \\<Rightarrow> {v. mem_map l = Some v})\"\n(* Switch to the inductive approach... sometime. *)\ninductive update_mem where \nno_atomic [intro]: \"\\<lbrakk>\\<And>t l v v'. ARW t l v v' \\<notin> ops; \\<And>t. \\<exists>up. bufs' t = up @ bufs t \\<and> \n set up = {(l, v) | l v. Write t l v \\<in> ops} \\<and> distinct up\\<rbrakk> \\<Longrightarrow> \n update_mem (mem, bufs) ops (mem |` (UNIV - {l. \\<exists>t. Free t l \\<in> ops}) ++ \n (\\<lambda>l. if \\<exists>t. Alloc t l \\<in> ops then Some undef else None), bufs')\" |\nupdate [intro]: \"\\<lbrakk>update_mem (mem, bufs) ops (mem', bufs'); bufs' t = buf @ [(l, v)]\\<rbrakk> \\<Longrightarrow>\n update_mem (mem, bufs) ops (mem'(l \\<mapsto> v), bufs'(t := buf))\" |\natomic [intro!]: \"bufs t = [] \\<Longrightarrow> update_mem (mem, bufs) {ARW t l v v'} (mem(l \\<mapsto> v'), bufs)\"\nabbreviation \"start_mem \\<equiv> (empty, \\<lambda>t. [])\"\n\nlemma alloc_not_free: \"\\<lbrakk>update_mem mem ops mem'; Alloc t l \\<in> ops; \\<forall>t. Free t l \\<notin> ops\\<rbrakk> \\<Longrightarrow> \n l \\<notin> free_set mem'\"\nby (induct rule: update_mem.induct, auto split: if_splits)\n\nlemma stays_not_free: \"\\<lbrakk>update_mem mem ops mem'; l \\<notin> free_set mem; \\<forall>t. Free t l \\<notin> ops\\<rbrakk> \\<Longrightarrow>\n l \\<notin> free_set mem'\"\nby (induct rule: update_mem.induct, auto split: if_splits)\n\nend\n\nsublocale TSO \\<subseteq> memory_model free_set can_read update_mem start_mem\nby (unfold_locales, metis alloc_not_free, metis stays_not_free)\n\ncontext TSO begin\n\nlemma update_none [intro!, simp]: \"update_mem C {} C\"\nby (cases C, cut_tac ops=\"{}\" and mem=a and bufs=b in no_atomic, auto simp add: restrict_map_def)\n\nlemma can_read_thread: \"\\<lbrakk>v \\<in> can_read (mem, b) t l; b t = b' t\\<rbrakk> \\<Longrightarrow> \n v \\<in> can_read (mem, b') t l\"\nby (auto simp add: can_read_def split: option.splits)\n\nlemma first_entry: \"\\<lbrakk>update_mem (mem, bufs) {Write t l v} (mem', bufs'); \n bufs' t = a # rest\\<rbrakk> \\<Longrightarrow> a = (l, v)\"\napply (drule_tac P=\"\\<lambda>(mem, bufs) ops (mem', bufs'). \\<forall>a rest. ops = {Write t l v} \\<and> \n bufs' t = a # rest \\<longrightarrow> a = (l, v)\" in update_mem.induct, simp_all, clarsimp)\napply (subgoal_tac \"\\<exists>up. bufs'a t = up @ bufs t \\<and> set up = {ab. t = t \\<and> (case ab of (la, va) \\<Rightarrow> \n la = l \\<and> va = v)} \\<and> distinct up\", clarify, simp+)\napply (case_tac up, simp, simp)\napply (thin_tac \"bufs'a t = ((aa, b) # resta)\", force)\napply auto\napply (cases a, auto)\ndone\n\nlemma update_map: \"update_mem (mem, bufs) {} (mem', bufs') \\<Longrightarrow>\n \\<exists>map. \\<forall>mem2. update_mem (mem2, bufs) {} (mem2 ++ map, bufs')\"\napply (drule_tac P=\"\\<lambda>(mem, bufs) ops (mem', bufs'). ops = {} \\<longrightarrow> \n (\\<exists>map. \\<forall>mem2. update_mem (mem2, bufs) {} (mem2 ++ map, bufs'))\" in update_mem.induct, auto)\napply (subgoal_tac \"bufs' = bufs\", rule_tac x=empty in exI, simp, rule ext)\napply (subgoal_tac \"\\<exists>up. bufs' x = (up @ bufs x) \\<and> set up = {(l, v). False} \\<and> distinct up\", clarify, auto)\napply (rule_tac x=\"map(l \\<mapsto> v)\" in exI, auto)\ndone\n\nlemma update_trans_rev: \"\\<lbrakk>update_mem (mem', bufs') {} (mem'', bufs'');\n update_mem (mem, bufs) ops (mem', bufs')\\<rbrakk> \\<Longrightarrow> update_mem (mem, bufs) ops (mem'', bufs'')\"\napply (drule_tac P=\"\\<lambda>(mem', bufs') ops' (mem'', bufs''). ops' = {} \\<and> update_mem (mem, bufs) ops (mem', bufs') \\<longrightarrow>\n update_mem (mem, bufs) ops (mem'', bufs'')\" in update_mem.induct, auto simp add: restrict_map_def)\napply (subgoal_tac \"bufs'a = bufsa\", simp, rule ext)\napply (subgoal_tac \"\\<exists>up. bufs'a x = up @ bufsa x \\<and> set up = {(l, v). False} \\<and> distinct up\", \n clarify, auto)\ndone\n\nlemma update_trans [trans]: \"\\<lbrakk>update_mem (mem, bufs) ops (mem', bufs');\n update_mem (mem', bufs') {} (mem'', bufs'')\\<rbrakk> \\<Longrightarrow> update_mem (mem, bufs) ops (mem'', bufs'')\"\nby (erule update_trans_rev, simp)\n\nlemma update_canonical: \"\\<lbrakk>update_mem (mem, bufs) ops (mem', bufs'); \n \\<And>t l v v'. ARW t l v v' \\<notin> ops\\<rbrakk> \\<Longrightarrow>\n \\<exists>writes bufs''. (\\<forall>t. bufs'' t = writes t @ bufs t \\<and> set (writes t) = {(l, v) | l v. Write t l v \\<in> ops} \\<and> distinct (writes t)) \\<and> \n update_mem (mem, bufs) ops (mem |` (UNIV - {l. \\<exists>t. Free t l \\<in> ops}) ++ \n (\\<lambda>l. if \\<exists>t. Alloc t l \\<in> ops then Some undef else None), bufs'') \\<and>\n update_mem (mem |` (UNIV - {l. \\<exists>t. Free t l \\<in> ops}) ++ \n (\\<lambda>l. if \\<exists>t. Alloc t l \\<in> ops then Some undef else None), bufs'') {} (mem', bufs')\"\napply (drule_tac P=\"\\<lambda>(mem, bufs) ops (mem', bufs'). (\\<forall>t l v v'. ARW t l v v' \\<notin> ops) \\<longrightarrow>\n (\\<exists>writes bufs''. (\\<forall>t. bufs'' t = writes t @ bufs t \\<and>\n set (writes t) = {(l, v) | l v. Write t l v \\<in> ops} \\<and> distinct (writes t)) \\<and> update_mem (mem, bufs) ops \n (mem |` (UNIV - {l. \\<exists>t. Free t l \\<in> ops}) ++ (\\<lambda>l. if \\<exists>t. Alloc t l \\<in> ops then Some undef else None), bufs'') \\<and>\n update_mem (mem |` (UNIV - {l. \\<exists>t. Free t l \\<in> ops}) ++ \n (\\<lambda>l. if \\<exists>t. Alloc t l \\<in> ops then Some undef else None), bufs'') {} (mem', bufs'))\" in update_mem.induct, auto)\napply (rule_tac x=\"\\<lambda>t. SOME up. bufs' t = up @ bufs t \\<and> set up = {(l, v). Write t l v \\<in> opsa} \\<and> \n distinct up\" in exI)\napply (rule_tac x=bufs' in exI)\napply (rule conjI, clarsimp)\napply (rule someI_ex, auto)\ndone\n\ncorollary update_write: \"\\<lbrakk>update_mem (mem, bufs) {Write t l v} (mem', bufs')\\<rbrakk> \\<Longrightarrow>\n update_mem (mem, bufs(t := (l, v) # bufs t)) {} (mem', bufs')\"\napply (drule update_canonical, auto)\napply (subgoal_tac \"bufs'' = bufs(t := (l, v) # bufs t)\", simp add: restrict_map_def, rule ext, \n clarsimp)\napply (erule_tac x=x in allE, rule conjI, clarsimp)\napply (case_tac \"writes t\", simp+, case_tac list, simp+)\napply clarsimp\ndone\n\nlemma update_later: \"\\<lbrakk>update_mem (mem, bufs) {} (mem', bufs')\\<rbrakk> \\<Longrightarrow>\n update_mem (mem, bufs) {Write t l v} (mem', bufs'(t := (l, v) # bufs' t))\"\napply (drule_tac P=\"\\<lambda>(mem, bufs) ops (mem', bufs'). ops = {} \\<longrightarrow> \n update_mem (mem, bufs) {Write t l v} (mem', bufs'(t := (l, v) # bufs' t))\" in update_mem.induct, auto)\napply (cut_tac ops=\"{Write t l v}\" in no_atomic, auto)\napply (drule_tac ops=\"{Write t l v}\" in update, auto)\napply (drule_tac ops=\"{Write t l v}\" and t=ta in update, auto)\nby (metis (hide_lams, no_types) fun_upd_twist)\n\nlemma update_later2: \"\\<lbrakk>update_mem (mem, bufs) {} (mem', bufs'(t := buf)); bufs' t = (l, v) # buf\\<rbrakk> \\<Longrightarrow> \n update_mem (mem, bufs) {Write t l v} (mem', bufs')\"\nby (smt fun_upd_idem_iff fun_upd_upd list.inject update_later)\n\nlemma update_past: \"\\<lbrakk>update_mem (mem, bufs) ops (mem', bufs'); t \\<notin> get_thread ` ops\\<rbrakk> \\<Longrightarrow> \n update_mem (mem, bufs(t := b @ bufs t)) ops (mem', bufs'(t := b @ bufs' t))\"\napply (drule_tac P=\"\\<lambda>(mem, bufs) ops (mem', bufs'). t \\<notin> get_thread ` ops \\<longrightarrow> \n update_mem (mem, bufs(t := b @ bufs t)) ops (mem', bufs'(t := b @ bufs' t))\" \n in update_mem.induct, auto)\napply (rule no_atomic, auto)\napply (rule_tac x=\"[]\" in exI, simp)\napply (subgoal_tac \"\\<forall>a b. Write t a b \\<notin> opsa\", subgoal_tac \"\\<exists>up. bufs' t = up @ bufs t \n \\<and> set up = {(l, v). Write t l v \\<in> opsa} \\<and> distinct up\", clarify, simp, metis, auto)\napply (metis get_thread.simps(2) imageI)\napply (drule_tac bufs=\"bufs(t := b @ bufs t)\" in update, auto)\napply (drule_tac bufs=\"bufs(t := b @ bufs t)\" and t=ta in update, auto)\napply (simp add: fun_upd_twist)\ndone\n\nlemma update_past2: \"\\<lbrakk>update_mem (mem, bufs) ops (mem', bufs'); \n \\<And>l v. Write t l v \\<notin> ops; \\<And>l v v'. ARW t l v v' \\<notin> ops\\<rbrakk> \\<Longrightarrow> \n update_mem (mem, bufs(t := b @ bufs t)) ops (mem', bufs'(t := b @ bufs' t))\"\napply (drule_tac P=\"\\<lambda>(mem, bufs) ops (mem', bufs'). (\\<forall>l v. Write t l v \\<notin> ops) \\<and> \n (\\<forall>l v v'. ARW t l v v' \\<notin> ops) \\<longrightarrow> update_mem (mem, bufs(t := b @ bufs t)) ops (mem', bufs'(t := b @ bufs' t))\" \n in update_mem.induct, auto)\napply (rule no_atomic, auto)\napply (subgoal_tac \"\\<exists>up. bufs' t = up @ bufs t \\<and> set up = {(l, v). Write t l v \\<in> opsa} \\<and> \n distinct up\", simp)\napply (metis (full_types))\napply (drule_tac bufs=\"bufs(t := b @ bufs t)\" in update, auto)\napply (drule_tac bufs=\"bufs(t := b @ bufs t)\" and t=ta in update, auto simp add: fun_upd_twist)\ndone\n\nlemma process_buffer: \"\\<lbrakk>update_mem (mem, bufs) ops (mem', bufs'); bufs' t = a @ b\\<rbrakk> \\<Longrightarrow>\n update_mem (mem, bufs) ops (mem' ++ map_of b, bufs'(t := a))\"\napply (induct b arbitrary: mem' bufs' rule: rev_induct, auto simp add: map_upd_triv)\napply (drule_tac t=t in update, auto)\napply force\ndone\n\nend\n\n(* assorted useful list lemmas*)\nlemma map_upt_zip_Suc [simp]: \"l' = map (\\<lambda>(x, n). (x, Suc n)) l \\<Longrightarrow> map (\\<lambda>((l, v), n). (l, v) # map (Pair l) (f n)) l' =\n map (\\<lambda>((l, v), n). (l, v) # map (Pair l) (f (Suc n))) l\"\nby auto\n\ndeclare map_Suc_upt [simp]\n\nlemma zip_Suc [simp]: \"zip l [Suc i..<Suc j] = map (\\<lambda>(x, n). (x, Suc n)) (zip l [i..<j])\"\nby (simp only: zip_map2 [THEN sym], simp)\n\n(* The redundant store produces buffers with redundant elements.\n   add_red is a general characterization of such buffers. *)\ndefinition \"add_red l f = \n concat (map (\\<lambda>((l, v), n). (l, v) # map (\\<lambda>v. (l, v)) (f n)) (zip l [0..<length l]))\"\n\nlemma add_red_nil [simp]: \"add_red [] f = []\"\nby (simp add: add_red_def)\n\nlemma add_red_cons [simp]: \"add_red (x # l) f = x # map (\\<lambda>v. (fst x, v)) (f 0) @ add_red l (\\<lambda>n. f (Suc n))\"\napply (auto simp add: add_red_def)\napply (case_tac \"map (\\<lambda>((l, v), n). (l, v) # map (Pair l) (f n)) (zip (x # l) ([0..<length l] @ [length l]))\", auto)\napply (case_tac \"[0..<length l] @ [length l]\", auto)\napply (case_tac \"[0..<length l] @ [length l]\", auto)\napply (case_tac \"[0..<length l] @ [length l]\", auto)\napply (cut_tac i=0 and j=\"Suc (length l)\" and x=ba and xs=list in upt_eq_Cons_conv, auto)\napply (rule_tac f=concat in arg_cong)\napply (rule map_upt_zip_Suc)\nby (metis upt_Suc_append zip_Suc)\n\nlemma add_red_app [simp]: \"add_red (l @ l') f = add_red l f @ add_red l' (\\<lambda>n. f (n + length l))\"\nby (induct l arbitrary: f, auto)\n\nlemma add_red_id [simp]: \"(\\<And>n. n < length l \\<Longrightarrow> f n = []) \\<Longrightarrow> add_red l f = l\"\nby (induct l arbitrary: f, auto)\n\nlemma find_append: \"(\\<And>x. x \\<in> set l \\<Longrightarrow> \\<not>P x) \\<Longrightarrow> List.find P (l @ l') = List.find P l'\"\nby (induct l, auto)\n\nlemma find_append2 [simp]: \"List.find P l = None \\<Longrightarrow> List.find P (l @ l') = List.find P l'\"\nby (induct l, auto)\n\nlemma find_append3 [simp]: \"List.find P l = Some x \\<Longrightarrow> List.find P (l @ l') = Some x\"\nby (induct l, auto)\n\nlemma add_red_find [simp]: \"List.find (\\<lambda>(l, v). l = x) (add_red buf f) = \n List.find (\\<lambda>(l, v). l = x) buf\"\napply (induct buf arbitrary: f, auto)\napply (rule trans, rule find_append, auto)\ndone\n\ncontext TSO begin\n\nlemma update_red: \"\\<lbrakk>update_mem (mem, bufs) ops (mem', bufs'); \\<And>t. red t = add_red (bufs t) (f t)\\<rbrakk> \\<Longrightarrow>\n \\<exists>red' f'. update_mem (mem, red) ops (mem', red') \\<and> (\\<forall>t. red' t = add_red (bufs' t) (f' t))\"\napply (drule_tac P=\"\\<lambda>(mem, bufs) ops (mem', bufs'). (\\<forall>t. red t = add_red (bufs t) (f t)) \\<longrightarrow> \n (\\<exists>red' f'. update_mem (mem, red) ops (mem', red') \\<and> (\\<forall>t. red' t = add_red (bufs' t) (f' t)))\" \n in update_mem.induct, auto)\napply (rule_tac x=\"\\<lambda>t. (SOME up. bufs' t = up @ bufsa t \\<and> set up = {(l, v). Write t l v \\<in> ops} \\<and> \n distinct up) @ red t\" in exI, auto)\napply (rule no_atomic, simp_all)\napply (cut_tac P=\"\\<lambda>up. bufs' t = up @ bufsa t \\<and> set up = {(l, v). Write t l v \\<in> ops} \\<and> \n distinct up\" in someI_ex, simp+)\napply (rule_tac x=\"\\<lambda>t n. if n < length (SOME up. bufs' t = up @ bufsa t \\<and> \n set up = {(l, v). Write t l v \\<in> ops} \\<and> distinct up) then [] else f t (n - length (SOME up. \n bufs' t = up @ bufsa t \\<and> set up = {(l, v). Write t l v \\<in> ops} \\<and> distinct up))\" in exI, clarsimp)\napply (subgoal_tac \"\\<exists>up. bufs' t = up @ bufsa t \\<and> set up = {(l, v). Write t l v \\<in> ops} \\<and> distinct up\", \n clarify, clarsimp)\napply (cut_tac P=\"\\<lambda>upa. up = upa \\<and> set upa = {(l, v). Write t l v \\<in> ops} \\<and> distinct upa\" in someI, \n force, clarsimp)\napply metis\napply (drule_tac bufs=red and t=t and a=\"add_red buf (f' t)\" in process_buffer, simp, clarsimp)\napply (subgoal_tac \"dom (map_of (map (Pair l) (f' t (length buf)))) = {l} \\<or> f' t (length buf) = []\", \n erule disjE, simp+)\napply (rule_tac x=\"red'(t := add_red buf (f' t))\" in exI, clarsimp)\napply (rule_tac x=f' in exI, simp)\napply (rule_tac x=\"red'(t := add_red buf (f' t))\" in exI, clarsimp)\napply (rule_tac x=f' in exI, simp)\napply (auto simp add: dom_map_of_conv_image_fst intro!: set_eqI)\napply (case_tac \"f' t (length buf)\", simp+)\napply (rule_tac x=red in exI, auto)+\ndone\n\nlemma update_red1: \"update_mem (mem, bufs) ops (mem', bufs') \\<Longrightarrow>\n \\<exists>f'. update_mem (mem, bufs(t := add_red (bufs t) f)) ops (mem', bufs'(t := add_red (bufs' t) f'))\"\napply (drule_tac P=\"\\<lambda>(mem, bufs) ops (mem', bufs'). \\<exists>f'. update_mem (mem, bufs(t := add_red (bufs t) f)) \n ops (mem', bufs'(t := add_red (bufs' t) f'))\" in update_mem.induct, auto)\napply (rule_tac x=\"\\<lambda>n. if n < length (SOME x. bufs' t = x @ bufs t \\<and> set x = {(l, v). Write t l v \\<in> ops} \\<and> distinct x) \n then [] else f (n - length (SOME x. bufs' t = x @ bufs t \\<and> set x = {(l, v). Write t l v \\<in> ops} \\<and> distinct x))\" \n in exI, rule no_atomic, auto)\napply (cut_tac P=\"\\<lambda>up. bufs' t = up @ bufs t \\<and> set up = {(l, v). Write t l v \\<in> ops} \\<and> \n distinct up\" in someI_ex, force, clarsimp)\napply (rule_tac x=\"SOME x. bufs' t = x @ bufs t \\<and> set x = {(l, v). Write t l v \\<in> ops} \\<and> distinct x\"\n in exI, clarsimp)\napply (rule_tac s=\"add_red ((SOME x. bufs' t = x @ bufs t \\<and> set x = {(l, v). Write t l v \\<in> ops} \\<and> distinct x) @ bufs t)\n        (\\<lambda>n. if n < length (SOME x. bufs' t = x @ bufs t \\<and> set x = {(l, v). Write t l v \\<in> ops} \\<and> distinct x) then []\n             else f (n - length (SOME x. bufs' t = x @ bufs t \\<and> set x = {(l, v). Write t l v \\<in> ops} \\<and> distinct x)))\" \n in trans, simp, simp (no_asm))\napply (drule_tac bufs=\"bufs(t := add_red (bufs t) f)\" and t=t and a=\"add_red buf f'\" in process_buffer,\n simp, clarsimp)\napply (subgoal_tac \"dom (map_of (map (Pair l) (f' (length buf)))) = {l} \\<or> f' (length buf) = []\", \n auto simp add: dom_map_of_conv_image_fst intro!: set_eqI)\napply (metis (full_types) append_Nil fst_conv imageI in_set_conv_decomp list.exhaust)\napply (drule_tac bufs=\"bufs(t := add_red (bufs t) f)\" in update, simp, force, \n force simp add: fun_upd_twist)\napply force\ndone\n\nlemma can_read_red: \"b' t = add_red (b t) f \\<Longrightarrow> can_read (mem, b') t = can_read (mem, b) t\"\nby (clarsimp intro!: ext simp add: can_read_def split: option.splits)\n\nlemma can_read_red_loc: \"\\<lbrakk>b' t = (l', v) # add_red (b t) f; l' \\<noteq> l\\<rbrakk> \\<Longrightarrow> \n can_read (mem, b') t l = can_read (mem, b) t l\"\nby (clarsimp intro!: ext simp add: can_read_def split: option.splits)\n\nend\n\n(* Sequential consistency memory model *)\nlocale SC = fixes undef::'val begin\n\nabbreviation \"free_set mem \\<equiv> UNIV - dom mem\"\nabbreviation \"can_read mem t l \\<equiv> {v. mem l = Some v}\"\ninductive update_mem where \nno_atomic [intro]: \"\\<lbrakk>\\<And>t l v v'. ARW t l v v' \\<notin> ops; \\<And>l. (\\<forall>t v. Write t l v \\<notin> ops) \\<Longrightarrow> writes l = None; \n \\<And>t l v. Write t l v \\<in> ops \\<Longrightarrow> \\<exists>t v. Write t l v \\<in> ops \\<and> writes l = Some v; finite ops\\<rbrakk> \\<Longrightarrow> \n update_mem mem ops (mem |` (UNIV - {l. \\<exists>t. Free t l \\<in> ops}) ++ \n (\\<lambda>l. if \\<exists>t. Alloc t l \\<in> ops then Some undef else None) ++ writes)\" |\natomic [intro!]: \"update_mem mem {ARW t l v v'} (mem(l \\<mapsto> v'))\"\nabbreviation \"start_mem \\<equiv> empty\"\n\nlemma update_threads: \"\\<lbrakk>update_mem mem ops mem'; \\<forall>a'\\<in>ops'. \\<exists>a\\<in>ops. \\<exists>t. a' = set_thread (t::'t) \n  (a::('t, 'l, 'val) access)\\<rbrakk> \\<Longrightarrow> update_mem mem ops' mem'\"\napply (drule_tac P=\"\\<lambda>mem ops mem'. \\<forall>ops'. (\\<forall>a'\\<in>ops'. \\<exists>a\\<in>ops. \\<exists>t. a' = set_thread t a) \\<longrightarrow>\n  update_mem mem ops' mem'\" in update_mem.induct, auto)\napply (subgoal_tac \"{l. \\<exists>t. Free t l \\<in> opsa} = {l. \\<exists>t. Free t l \\<in> ops'a} \\<and> (\\<lambda>l. if \\<exists>t. Alloc t l \\<in> \n  opsa then Some undef else None) = (\\<lambda>l. if \\<exists>t. Alloc t l \\<in> ops'a then Some undef else None)\", simp)\napply (rule no_atomic, clarsimp)\napply (thin_tac \"\\<forall>a'\\<in>ops'. \\<exists>a\\<in>ops. \\<exists>t. a' = set_thread t a\")\napply (erule_tac x=\"ARW t l v v'\" in ballE, simp_all, clarsimp)\napply (case_tac a, simp_all)\napply (subgoal_tac \"\\<forall>t v. Write t l v \\<notin> opsa\", simp, clarsimp)\noops\n\nlemma update_threads: \"update_mem mem ops mem' \\<Longrightarrow> update_mem mem (set_thread t ` ops) mem'\"\napply (drule_tac P=\"\\<lambda>mem ops mem'. update_mem mem (set_thread t ` ops) mem'\" in update_mem.induct, auto)\napply (subgoal_tac \"{l. \\<exists>t. Free t l \\<in> ops} = {l. \\<exists>ta. Free ta l \\<in> set_thread t ` ops} \\<and> (\\<lambda>l. if \n  \\<exists>t. Alloc t l \\<in> ops then Some undef else None) = (\\<lambda>l. if \\<exists>ta. Alloc ta l \\<in> set_thread t ` ops \n  then Some undef else None)\", simp)\napply (rule no_atomic, clarsimp)\napply (case_tac x, simp_all)\napply (subgoal_tac \"\\<forall>t v. Write t l v \\<notin> ops\", simp, clarsimp)\napply (erule_tac x=t in allE, erule_tac x=v in allE, force simp add: image_def)\napply (subgoal_tac \"\\<exists>t v. Write t l v \\<in> ops \\<and> writes l = Some v\", clarsimp simp add: image_def)\napply (rule_tac x=t in exI, rule_tac x=\"Write tb l va\" in bexI, simp+)\napply (clarsimp simp add: image_def)\napply (case_tac x, simp_all)\napply (auto simp add: image_def)\napply (rule_tac x=t in exI, rule bexI, simp_all)\napply (case_tac xa, simp_all, metis)\napply (rule ext, auto)\napply (rule_tac x=t in exI, rule bexI, simp_all)\napply (case_tac x, simp_all)\ndone\n\nlemma stays_not_free: \"\\<lbrakk>update_mem mem ops mem'; l \\<notin> free_set mem; \\<forall>t. Free t l \\<notin> ops\\<rbrakk> \\<Longrightarrow>\n l \\<notin> free_set mem'\"\nby (induct rule: update_mem.induct, auto split: if_splits)\n\nlemma alloc_not_free: \"\\<lbrakk>update_mem mem ops mem'; Alloc t l \\<in> ops; Free t l \\<notin> ops\\<rbrakk> \\<Longrightarrow> \n l \\<notin> free_set mem'\"\nby (induct rule: update_mem.induct, auto split: if_splits)\n\nend\n\nsublocale SC \\<subseteq> memory_model free_set can_read update_mem start_mem\nby (unfold_locales, metis alloc_not_free, metis stays_not_free)\n\ncontext SC begin\n\nlemma update_none [intro!, simp]: \"update_mem C {} C\"\nby (cut_tac no_atomic, auto simp add: restrict_map_def)\n\nlemma update_none_only [simp, dest!]: \"update_mem mem {} mem' \\<Longrightarrow> mem' = mem\"\nby (erule update_mem.cases, auto simp add: restrict_map_def map_add_def)\n\nlemma update_one_write [intro!, simp]: \"mem' = mem(l \\<mapsto> v) \\<Longrightarrow>\n update_mem mem {Write t l v} mem'\"\nby (cut_tac ops=\"{Write t l v}\" and writes=\"[l \\<mapsto> v]\" in no_atomic, auto simp add: restrict_map_def)\n\nlemma update_one_writeD [dest!, simp]: \"update_mem mem {Write t l v} mem' \\<Longrightarrow> mem' = mem(l \\<mapsto> v)\"\nby (erule update_mem.cases, auto intro!: ext simp add: map_add_def split: option.splits)\n\nlemma update_one_read [intro, simp]: \"update_mem mem {Read t l v} mem\"\nby (cut_tac ops=\"{Read t l v}\" in no_atomic, auto simp add: restrict_map_def)\n\nlemma update_one_readD [dest!, simp]: \"update_mem mem {Read t l v} mem' \\<Longrightarrow> mem' = mem\"\nby (erule update_mem.cases, auto intro!: ext simp add: restrict_map_def map_add_def)\n\nlemma update_one_alloc [intro!, simp]: \"mem' = mem(l \\<mapsto> undef) \\<Longrightarrow>\n update_mem mem {Alloc t l} mem'\"\napply (cut_tac ops=\"{Alloc t l}\" and mem=mem in no_atomic, auto simp add: restrict_map_def)\napply (subgoal_tac \"mem ++ (\\<lambda>la. if la = l then Some undef else None) = mem(l \\<mapsto> undef)\", simp,\n auto intro!: ext simp add: map_add_def)\ndone\n\nlemma update_one_allocD [dest!]: \"update_mem mem {Alloc t l} mem' \\<Longrightarrow> mem' = mem(l \\<mapsto> undef)\"\nby (erule update_mem.cases, auto simp add: restrict_map_def map_add_def)\n\nlemma update_frees [intro!, simp]: \"\\<lbrakk>mem' = mem |` (UNIV - S); finite S\\<rbrakk> \\<Longrightarrow> \n update_mem mem (Free t ` S) mem'\"\napply (cut_tac ops=\"Free t ` S\" and mem=mem in no_atomic, auto)\napply (rule subst, rule_tac f=\"update_mem mem (Free t ` S)\" in arg_cong, simp_all)\napply (auto intro!: ext simp add: map_add_def restrict_map_def, force)\ndone\n\nlemma update_freesD [dest!, simp]: \"update_mem mem (Free t ` S) mem' \\<Longrightarrow>\n mem' = mem |` (UNIV - S)\"\napply (erule update_mem.cases, auto intro!: ext simp add: map_add_def restrict_map_def \n split: option.splits)\napply (metis image_eqI)\napply (metis access.distinct(13) image_iff option.distinct(1))\napply (metis image_eqI)\nby (metis access.distinct(13) image_iff option.distinct(1))\n\nlemma update_ARW [intro!]: \"mem' = mem(l \\<mapsto> v') \\<Longrightarrow> update_mem mem {ARW t l v v'} mem'\"\nby clarsimp\n\nlemma update_ARWD [dest!]: \"update_mem mem {ARW t l v v'} mem' \\<Longrightarrow> mem' = mem(l \\<mapsto> v')\"\nby (erule update_mem.cases, auto)\n\nlemma update_past: \"\\<lbrakk>update_mem mem ops mem'; \\<And>t v. Write t l v \\<notin> ops; \n \\<And>t v v'. ARW t l v v' \\<notin> ops; \\<And>t. Free t l \\<notin> ops; \\<And>t. Alloc t l \\<notin> ops\\<rbrakk> \\<Longrightarrow>\n update_mem (mem(l := v)) ops (mem'(l := v))\"\napply (induct rule: update_mem.induct, auto)\napply (cut_tac ops=ops and mem=\"mem(l := v)\" and writes=writes in no_atomic, auto)\napply (rule_tac f1=\"update_mem (mem(l := v))\" in arg_cong2 [THEN subst], \n auto intro!: ext simp add: map_add_def restrict_map_def split: option.splits)\nby (metis atomic fun_upd_twist)\n\nend\n\nlocale undef = fixes undef::'val\nsublocale undef \\<subseteq> TSO: TSO .\nsublocale undef \\<subseteq> SC: SC .\n\ncontext undef begin\n\n(* SC can be modeled by TSO. *)\n(*\n\nlemma process_all_buffers [rule_format]: \"\\<lbrakk>update_mem (mem, bufs) ops (mem', bufs'); \n \\<forall>t. bufs' t = ma t @ mb t; finite {t. mb t \\<noteq> []}\\<rbrakk> \\<Longrightarrow>\n \\<exists>m'. update_mem (mem, bufs) ops (mem' ++ m', (\\<lambda>t. ma t)) \\<and>\n (\\<forall>l v. ((m' l = Some v) \\<longrightarrow> (\\<exists>t. map_of (mb t) l = Some v)) \\<and>\n (m' l = None \\<longrightarrow> (\\<forall>t. map_of (mb t) l = None)))\"\napply (drule_tac P=\"\\<lambda>S. \\<forall>mem' bufs' ma mb. (update_mem (mem, bufs) ops (mem', bufs') \\<and>\n (\\<forall>t. bufs' t = ma t @ mb t)) \\<and> S = {t. mb t \\<noteq> []} \\<longrightarrow> \n (\\<exists>m'. update_mem (mem, bufs) ops (mem' ++ m', (\\<lambda>t. ma t)) \\<and>\n (\\<forall>l v. ((m' l = Some v) \\<longrightarrow> (\\<exists>t. map_of (mb t) l = Some v)) \\<and>\n (m' l = None \\<longrightarrow> (\\<forall>t. map_of (mb t) l = None))))\" in finite_induct, auto)\napply (rule_tac x=empty in exI, simp)\napply (subgoal_tac \"bufs'a = maa\", simp)\napply (auto intro!: ext split: option.split)\napply (cut_tac a=x and B=F in insertI1, clarsimp)\napply (thin_tac \"\\<forall>t. bufs' t = ma t @ mb t\")\napply (drule_tac bufs'=bufs'a and t=x and a=\"ma x\" in process_buffer, auto)\napply (erule_tac x=\"mem'a ++ map_of (mb x)\" in allE, erule_tac x=\"bufs'a(x := ma x)\" in allE, \n erule_tac x=ma in allE, erule_tac x=\"mb(x := [])\" in allE, clarsimp, erule impE, force, clarsimp)\napply (rule_tac x=\"map_of (mb x) ++ m'\" in exI, auto split: if_splits, metis, metis)\napply (erule_tac x=mem' in allE, erule_tac x=bufs' in allE, simp)\ndone\n\nlemma SC_lt_update [simp, intro]: \"update_mem_SC mem ops mem' \\<Longrightarrow> \n update_mem (mem, \\<lambda>t. []) ops (mem', \\<lambda>t. [])\"\napply (erule update_mem_SC.cases, auto split: if_splits)\napply (cut_tac ops=ops and mem=mem and bufs=\"\\<lambda>t. []\" and\n bufs'=\"\\<lambda>t. list_of_set {(l, v) | l v. Write t l v \\<in> ops \\<and> writes l = Some v} @ \n list_of_set {(l, v) | l v. Write t l v \\<in> ops \\<and> writes l \\<noteq> Some v}\" in no_atomic, simp_all)\napply (subgoal_tac \"finite {(l, v). Write t l v \\<in> ops}\", auto)\napply (rule finite_vimageI, auto simp add: inj_on_def)\napply (drule_tac ma=\"\\<lambda>t. list_of_set {(l, v) | l v. Write t l v \\<in> ops \\<and> writes l = Some v}\" and \n mb=\"\\<lambda>t. list_of_set {(l, v) | l v. Write t l v \\<in> ops \\<and> writes l \\<noteq> Some v}\" in process_all_buffers)\napply (simp split: if_splits)\napply clarsimp\napply (rule_tac B=\"{t. \\<exists>a \\<in> ops. get_thread a = t}\" in finite_subset, clarsimp)\napply (clarsimp simp add: card_gt_0_iff, rule_tac x=\"Write x a b\" in bexI, simp+)\napply clarsimp\napply (drule_tac ma=\"\\<lambda>t. []\" and \n mb=\"\\<lambda>t. list_of_set {(l, v) | l v. Write t l v \\<in> ops \\<and> writes l = Some v}\" in process_all_buffers)\napply (simp split: if_splits)\napply clarsimp\napply (rule_tac B=\"{t. \\<exists>a \\<in> ops. get_thread a = t}\" in finite_subset, clarsimp)\napply (clarsimp simp add: card_gt_0_iff, rule_tac x=\"Write x a b\" in bexI, simp+)\napply clarsimp\napply (rule_tac x1=\"(mem |` (UNIV - {l. \\<exists>t. Free t l \\<in> ops}) ++ \n (\\<lambda>l. if \\<exists>t. Alloc t l \\<in> ops then Some undef else None) ++ m' ++ m'a, \\<lambda>t. case case if t \\<in> dom threads\n                       then Some (list_of_set {(l, v) |l v. Write t l v \\<in> ops \\<and> writes l = Some v} @\n                                  list_of_set {(l, v) |l v. Write t l v \\<in> ops \\<and> writes l \\<noteq> Some v})\n                       else None of\n                  None \\<Rightarrow> None | Some x \\<Rightarrow> Some (list_of_set {(l, v) |l v. Write t l v \\<in> ops \\<and> writes l = Some v}) of\n             None \\<Rightarrow> None | Some x \\<Rightarrow> Some [])\" in cong [THEN subst], simp, auto)\napply (subgoal_tac \"m' ++ m'a = writes\")\napply (metis map_add_assoc)\napply (rule ext, (erule_tac x=x in allE)+, clarsimp simp add: map_add_def split: option.split)\napply (case_tac \"writes x\", simp_all)\napply (subgoal_tac \"\\<forall>t v. Write t x v \\<notin> ops\", rule ccontr, clarsimp, erule disjE, \n clarsimp split: if_splits)\napply (drule map_of_is_SomeD)\napply (subgoal_tac \"finite {(l, v). Write t l v \\<in> ops}\", simp+)\napply (rule finite_vimageI, simp, simp add: inj_on_def)\napply (clarsimp split: if_splits)\napply (drule map_of_is_SomeD)\napply (subgoal_tac \"finite {(l, v). Write t l v \\<in> ops}\", simp+)\napply (rule finite_vimageI, simp, simp add: inj_on_def)\napply (metis not_Some_eq)\napply (subgoal_tac \"\\<exists>t. Write t x a \\<in> ops\", clarsimp)\napply (rule conjI, clarsimp)\napply (erule_tac x=t in allE)\napply (clarsimp simp add: map_of_eq_None_iff)\napply (subgoal_tac \"finite {(l, v). Write t l v \\<in> ops}\", simp+)\napply (erule notE, rule_tac x=\"(x, a)\" in image_eqI, simp+)\napply (rule finite_vimageI, simp, simp add: inj_on_def)\napply clarsimp\napply (drule map_of_is_SomeD)\napply (subgoal_tac \"finite {(l, v). Write ta l v \\<in> ops}\", simp+)\napply (rule finite_vimageI, simp, simp add: inj_on_def)\nby (metis (hide_lams, full_types) not_Some_eq option.inject)\n\nlemma make_bufs_can_read [simp]: \"can_read (mem, \\<lambda>t. []) t = can_read_SC mem t\"\nby (rule ext, simp add: can_read_def)\n(* Because can_read and update_mem are the only interfaces to the memory provided by memory_model,\n   this implies that SC refines TSO for any language.  Is there a way to make this explicit? *)\n*)\nend\n\nlocale PSO = fixes undef::'val begin\n\n(* PSO memory model *)\nabbreviation \"free_set mem \\<equiv> UNIV - dom (fst mem)\"\ndefinition \"can_read mem t l \\<equiv> case snd mem t l of v # buf \\<Rightarrow> {v}\n | [] \\<Rightarrow> {v. fst mem l = Some v}\"\ninductive update_mem where \nno_atomic [intro]: \"\\<lbrakk>\\<And>t l v v'. ARW t l v v' \\<notin> ops; \\<And>t l. \\<exists>up. bufs' t l = up @ bufs t l \\<and> \n set up = {v. Write t l v \\<in> ops} \\<and> distinct up\\<rbrakk> \\<Longrightarrow> \n update_mem (mem, bufs) ops (mem |` (UNIV - {l. \\<exists>t. Free t l \\<in> ops}) ++ \n (\\<lambda>l. if \\<exists>t. Alloc t l \\<in> ops then Some undef else None), bufs')\" |\nupdate [intro]: \"\\<lbrakk>update_mem (mem, bufs) ops (mem', bufs'); bufs' t l = buf @ [v]\\<rbrakk> \\<Longrightarrow>\n update_mem (mem, bufs) ops (mem'(l \\<mapsto> v), bufs'(t := (bufs' t)(l := buf)))\" |\natomic [intro!]: \"bufs t l = [] \\<Longrightarrow>\n update_mem (mem, bufs) {ARW t l v v'} (mem(l \\<mapsto> v'), bufs)\"\nabbreviation \"start_mem \\<equiv> (empty, \\<lambda>t l. [])\"\n\nlemma alloc_not_free: \"\\<lbrakk>update_mem mem ops mem'; Alloc t l \\<in> ops; \\<forall>t. Free t l \\<notin> ops\\<rbrakk> \\<Longrightarrow> \n l \\<notin> free_set mem'\"\nby (induct rule: update_mem.induct, auto split: if_splits)\n\nlemma stays_not_free: \"\\<lbrakk>update_mem mem ops mem'; l \\<notin> free_set mem; \\<forall>t. Free t l \\<notin> ops\\<rbrakk> \\<Longrightarrow>\n l \\<notin> free_set mem'\"\nby (induct rule: update_mem.induct, auto split: if_splits)\n\nend\n\nsublocale PSO \\<subseteq> memory_model free_set can_read update_mem start_mem\nby (unfold_locales, metis alloc_not_free, metis stays_not_free)\n\ncontext PSO begin\n\nlemma update_none [intro!, simp]: \"update_mem C {} C\"\nby (cases C, cut_tac ops=\"{}\" and mem=a and bufs=b in no_atomic, auto simp add: restrict_map_def)\n\nlemma process_buffer: \"\\<lbrakk>update_mem (mem, bufs) ops (mem', bufs'); bufs' t l = a @ v # b\\<rbrakk> \\<Longrightarrow>\n update_mem (mem, bufs) ops (mem'(l \\<mapsto> v), bufs'(t := (bufs' t)(l := a)))\"\napply (induct b arbitrary: mem' bufs' v rule: rev_induct, auto simp add: map_upd_triv)\napply (drule_tac t=t and l=l in update, simp, force)\ndone\n\nlemma update_later: \"\\<lbrakk>update_mem (mem, bufs) {} (mem', bufs')\\<rbrakk> \\<Longrightarrow>\n update_mem (mem, bufs) {Write t l v} (mem', bufs'(t := (bufs' t)(l := v # bufs' t l)))\"\napply (drule_tac P=\"\\<lambda>(mem, bufs) ops (mem', bufs'). ops = {} \\<longrightarrow> \n update_mem (mem, bufs) {Write t l v} (mem', bufs'(t := (bufs' t)(l := v # bufs' t l)))\" \n in update_mem.induct, auto)\napply (cut_tac ops=\"{Write t l v}\" in no_atomic, auto)\napply (drule_tac ops=\"{Write t l v}\" in update, auto)\napply (drule_tac ops=\"{Write t l v}\" and t=ta in update, auto simp add: fun_upd_twist)\napply (drule_tac ops=\"{Write t l v}\" and l=la in update, auto simp add: fun_upd_twist)\napply (drule_tac ops=\"{Write t l v}\" and t=ta in update, auto simp add: fun_upd_twist)\ndone\n\nlemma update_later2: \"\\<lbrakk>update_mem (mem, bufs) {} (mem', bufs'(t := (bufs' t)(l := buf))); \n bufs' t l = v # buf\\<rbrakk> \\<Longrightarrow> update_mem (mem, bufs) {Write t l v} (mem', bufs')\"\nby (smt fun_upd_idem_iff fun_upd_upd list.inject update_later)\n\nlemma update_past2: \"\\<lbrakk>update_mem (mem, bufs) ops (mem', bufs'); \n \\<And>v. Write t l v \\<notin> ops; \\<And>l v v'. ARW t l v v' \\<notin> ops\\<rbrakk> \\<Longrightarrow> \n update_mem (mem, bufs(t := (bufs t)(l := b @ bufs t l))) ops \n                (mem', bufs'(t := (bufs' t)(l := b @ bufs' t l)))\"\napply (drule_tac P=\"\\<lambda>(mem, bufs) ops (mem', bufs'). (\\<forall>v. Write t l v \\<notin> ops) \\<and> \n (\\<forall>l v v'. ARW t l v v' \\<notin> ops) \\<longrightarrow> update_mem (mem, bufs(t := (bufs t)(l := b @ bufs t l))) ops \n                (mem', bufs'(t := (bufs' t)(l := b @ bufs' t l)))\" in update_mem.induct, auto)\napply (rule no_atomic, auto)\napply (subgoal_tac \"\\<exists>up. bufs' t l = up @ bufs t l \\<and> set up = {v. Write t l v \\<in> opsa} \\<and> \n distinct up\", simp)\napply (metis (full_types))\napply (drule_tac bufs=\"bufs(t := (bufs t)(l := b @ bufs t l))\" in update, auto)\napply (drule_tac bufs=\"bufs(t := (bufs t)(l := b @ bufs t l))\" and t=ta in update, \n auto simp add: fun_upd_twist)\napply (drule_tac bufs=\"bufs(t := (bufs t)(l := b @ bufs t l))\" in update, \n auto simp add: fun_upd_twist)\napply (drule_tac bufs=\"bufs(t := (bufs t)(l := b @ bufs t l))\" and t=ta in update, \n auto simp add: fun_upd_twist)\ndone\n\nlemma update_write: \"\\<lbrakk>update_mem (mem, bufs) {Write t l v} (mem', bufs')\\<rbrakk> \\<Longrightarrow>\n update_mem (mem, bufs(t := (bufs t)(l := v # bufs t l))) {} (mem', bufs')\"\napply (drule_tac P=\"\\<lambda>(mem, bufs) ops (mem', bufs'). ops = {Write t l v} \\<longrightarrow>\n update_mem (mem, bufs(t := (bufs t)(l := v # bufs t l))) {} (mem', bufs')\" \n in update_mem.induct, auto)\napply (cut_tac ops=\"{}\" and bufs=\"bufs(t := (bufs t)(l := v # bufs t l))\" and\n bufs'=bufs' in no_atomic, simp_all)\napply (subgoal_tac \"\\<exists>up. bufs' ta la = up @ bufs ta la \\<and> set up = {va. va = v \\<and> ta = t \\<and> la = l} \\<and> \n distinct up\", clarify, auto)\napply (case_tac up, auto, case_tac list, auto)\ndone\n\nlemma update_trans_rev: \"\\<lbrakk>update_mem (mem', bufs') {} (mem'', bufs'');\n update_mem (mem, bufs) ops (mem', bufs')\\<rbrakk> \\<Longrightarrow> update_mem (mem, bufs) ops (mem'', bufs'')\"\napply (drule_tac P=\"\\<lambda>(mem', bufs') ops' (mem'', bufs''). ops' = {} \\<and> update_mem (mem, bufs) ops (mem', bufs') \\<longrightarrow>\n update_mem (mem, bufs) ops (mem'', bufs'')\" in update_mem.induct, auto simp add: restrict_map_def)\napply (subgoal_tac \"bufs'a = bufsa\", auto)\ndone\n\nend\n*)\n(* In PSO, redundant elements are added to the buffers for individual locations. *)\ndefinition \"add_red2 l f = concat (map (\\<lambda>(v, n). v # f n) (zip l [0..<length l]))\"\n\nlemma add_red2_nil [simp]: \"add_red2 [] f = []\"\nby (simp add: add_red2_def)\n\nlemma upt_0 [simp]: \"j > i \\<Longrightarrow> [i..<j] ! 0 = i\"\nby (induct i, auto)\n\nlemma add_red2_nil2 [simp]: \"(add_red2 l f = []) = (l = [])\"\napply (auto simp add: add_red2_def)\napply (case_tac l, auto)\napply (erule_tac x=\"(a, 0)\" in ballE, auto simp add: set_conv_nth)\napply (erule_tac x=0 in allE, auto)\nby (metis gr_implies_not0 le0 upt_0 upt_Suc zero_less_Suc)\n\nlemma map_upt_zip_Suc2 [simp]: \"l' = map (\\<lambda>(x, n). (x, Suc n)) l \\<Longrightarrow> map (\\<lambda>(v, n). v # f n) l' =\n map (\\<lambda>(v, n). v # f (Suc n)) l\"\nby auto\n\nlemma add_red2_cons [simp]: \"add_red2 (x # l) f = x # f 0 @ add_red2 l (\\<lambda>n. f (Suc n))\"\napply (auto simp add: add_red2_def)\napply (case_tac \"map (\\<lambda>(v, n). v # f n) (zip (x # l) ([0..<length l] @ [length l]))\", auto)\napply (case_tac \"[0..<length l] @ [length l]\", auto)\napply (case_tac \"[0..<length l] @ [length l]\", auto)\napply (case_tac \"[0..<length l] @ [length l]\", auto)\napply (cut_tac i=0 and j=\"Suc (length l)\" and x=b and xs=list in upt_eq_Cons_conv, auto)\napply (rule_tac f=concat in arg_cong)\napply (rule map_upt_zip_Suc2)\nby (metis upt_Suc_append zip_Suc)\n\nlemma add_red2_app [simp]: \"add_red2 (l @ l') f = add_red2 l f @ add_red2 l' (\\<lambda>n. f (n + length l))\"\nby (induct l arbitrary: f, auto)\n\nlemma add_red2_id [simp]: \"(\\<And>n. n < length l \\<Longrightarrow> f n = []) \\<Longrightarrow> add_red2 l f = l\"\nby (induct l arbitrary: f, auto)\n\ncontext PSO begin\n\nlemma update_red2: \"\\<lbrakk>update_mem (mem, bufs) ops (mem', bufs');\n \\<And>t l. red t l = add_red2 (bufs t l) (f t l)\\<rbrakk> \\<Longrightarrow>\n \\<exists>red' f'. update_mem (mem, red) ops (mem', red') \\<and> \n (\\<forall>t l. red' t l = add_red2 (bufs' t l) (f' t l))\"\napply (drule_tac P=\"\\<lambda>(mem, bufs) ops (mem', bufs'). (\\<forall>t l. red t l = add_red2 (bufs t l) (f t l)) \\<longrightarrow> \n (\\<exists>red' f'. update_mem (mem, red) ops (mem', red') \\<and> (\\<forall>t l. red' t l = add_red2 (bufs' t l) (f' t l)))\" \n in update_mem.induct, auto)\napply (rule_tac x=\"\\<lambda>t l. (SOME up. bufs' t l = up @ (bufsa t l) \\<and> set up = {v. Write t l v \\<in> ops} \\<and> \n distinct up) @ red t l\" in exI, auto)\napply (rule no_atomic, simp_all)\napply (cut_tac P=\"\\<lambda>up. bufs' t l = up @ bufsa t l \\<and> set up = {v. Write t l v \\<in> ops} \\<and> \n distinct up\" in someI_ex, simp+)\napply (rule_tac x=\"\\<lambda>t l n. if n < length (SOME up. bufs' t l = up @ bufsa t l \\<and> set up = \n {v. Write t l v \\<in> ops} \\<and> distinct up) then [] else f t l (n - length (SOME up. bufs' t l = \n up @ bufsa t l \\<and> set up = {v. Write t l v \\<in> ops} \\<and> distinct up))\" in exI, clarsimp)\napply (subgoal_tac \"\\<exists>up. bufs' t l = up @ bufsa t l \\<and> set up = {v. Write t l v \\<in> ops} \\<and> distinct up\", \n clarify, clarsimp)\napply (cut_tac P=\"\\<lambda>upa. up = upa \\<and> set upa = {v. Write t l v \\<in> ops} \\<and> distinct upa\" in someI, \n force, clarsimp)\napply metis\napply (drule_tac bufs=red and t=t and l=l and a=\"add_red2 buf (f' t l)\" in process_buffer, force)\napply (rule_tac x=\"red'(t := (red' t)(l := add_red2 buf (f' t l)))\" in exI, clarsimp, metis)\napply (rule_tac x=red in exI, auto)\ndone\n\nlemma update_red2_one_buf: \"\\<lbrakk>update_mem (mem, bufs) ops (mem', bufs'); \n \\<And>t'. t' \\<noteq> t \\<Longrightarrow> red t' = bufs t'; \\<And>l. red t l = add_red2 (bufs t l) (f l)\\<rbrakk> \\<Longrightarrow>\n \\<exists>red' f'. update_mem (mem, red) ops (mem', red') \\<and> (\\<forall>t'. t' \\<noteq> t \\<longrightarrow> red' t' = bufs' t') \\<and>\n (\\<forall>l. red' t l = add_red2 (bufs' t l) (f' l))\"\napply (drule_tac P=\"\\<lambda>(mem, bufs) ops (mem', bufs'). ((\\<forall>t'. t' \\<noteq> t \\<longrightarrow> red t' = bufs t') \\<and>\n (\\<forall>l. red t l = add_red2 (bufs t l) (f l))) \\<longrightarrow> (\\<exists>red' f'. update_mem (mem, red) ops (mem', red') \\<and> \n (\\<forall>t'. t' \\<noteq> t \\<longrightarrow> red' t' = bufs' t') \\<and> (\\<forall>l. red' t l = add_red2 (bufs' t l) (f' l)))\" \n in update_mem.induct, simp_all, clarsimp)\napply (rule_tac x=\"bufs'(t := \\<lambda>l. (SOME up. bufs' t l = up @ (bufsa t l) \\<and> set up = {v. Write t l v \\<in> ops} \\<and> \n distinct up) @ red t l)\" in exI, clarsimp)\napply (rule conjI, rule no_atomic, simp_all)\napply (cut_tac P=\"\\<lambda>up. bufs' t l = up @ bufsa t l \\<and> set up = {v. Write t l v \\<in> ops} \\<and> \n distinct up\" in someI_ex, simp+)\napply (rule_tac x=\"\\<lambda>l n. if n < length (SOME up. bufs' t l = up @ bufsa t l \\<and> set up = \n {v. Write t l v \\<in> ops} \\<and> distinct up) then [] else f l (n - length (SOME up. bufs' t l = \n up @ bufsa t l \\<and> set up = {v. Write t l v \\<in> ops} \\<and> distinct up))\" in exI, clarsimp)\napply (subgoal_tac \"\\<exists>up. bufs' t l = up @ bufsa t l \\<and> set up = {v. Write t l v \\<in> ops} \\<and> distinct up\", \n clarify, clarsimp)\napply (cut_tac P=\"\\<lambda>upa. up = upa \\<and> set upa = {v. Write t l v \\<in> ops} \\<and> distinct upa\" in someI, \n force, clarsimp)\napply metis\napply auto\napply (drule_tac bufs=red and t=t and l=l in process_buffer, force)\napply (rule_tac x=\"red'(t := (red' t)(l := add_red2 buf (f' l)))\" in exI, clarsimp, metis)\napply (drule_tac bufs=red and t=ta and l=l in process_buffer, force)\napply (rule_tac x=\"red'(ta := (red' ta)(l := buf))\" in exI, clarsimp, metis)\napply (rule_tac x=red in exI, auto)\napply (case_tac \"ta = t\", auto)\ndone\n\nlemma can_read_red [simp]: \"b' t l = add_red2 (b t l) f \\<Longrightarrow> \n can_read (mem, b') t l = can_read (mem, b) t l\"\nby (clarsimp intro!: ext simp add: can_read_def split: list.splits)\n\nlemma can_read_loc: \"b' t l = b t l \\<Longrightarrow> \n can_read (mem, b') t l = can_read (mem, b) t l\"\nby (clarsimp intro!: ext simp add: can_read_def split: list.splits)\n\nlemma two_part_buf [simp]: \"bufs t l = buf \\<Longrightarrow> bufs(t := (bufs t)(l := buf)) = bufs\"\nby (clarsimp intro!: ext)\n\nend\n*)\nend\n", "meta": {"author": "liyili2", "repo": "timed-relaxed-memory-model", "sha": "6d85bc75d8b04228b3e581b945e3f672395f0c66", "save_path": "github-repos/isabelle/liyili2-timed-relaxed-memory-model", "path": "github-repos/isabelle/liyili2-timed-relaxed-memory-model/timed-relaxed-memory-model-6d85bc75d8b04228b3e581b945e3f672395f0c66/memory_model.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953506426082, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.2729725100738839}}
{"text": "section \\<open>Soundness\\<close>\n\ntheory Soundness imports \"Abstract_Soundness.Finite_Proof_Soundness\" Prover Semantics begin\n\nlemma eff_sound:\n  assumes \\<open>eff r (A, B) = Some ss\\<close> \\<open>\\<forall>A B. (A, B) |\\<in>| ss \\<longrightarrow> (\\<forall>(E :: _ \\<Rightarrow> 'a). sc (E, F, G) (A, B))\\<close>\n  shows \\<open>sc (E, F, G) (A, B)\\<close>\n  using assms\nproof (induct r \\<open>(A, B)\\<close> rule: eff.induct)\n  case (5 p q)\n  then have \\<open>sc (E, F, G) (A [\\<div>] (p \\<^bold>\\<longrightarrow> q), p # B)\\<close> \\<open>sc (E, F, G) (q # A [\\<div>] (p \\<^bold>\\<longrightarrow> q), B)\\<close>\n    by (metis eff.simps(5) finsertCI option.inject option.simps(3))+\n  then show ?case\n    using \"5.prems\"(1) by (force split: if_splits)\nnext\n  case (7 t p)\n  then have \\<open>sc (E, F, G) (\\<langle>t\\<rangle>p # A, B)\\<close>\n    by (metis eff.simps(7) finsert_iff option.inject option.simps(3))\n  then show ?case\n    using \"7.prems\"(1) by (fastforce split: if_splits)\nnext\n  case (8 p)\n  let ?n = \\<open>fresh (A @ B)\\<close>\n  have A: \\<open>\\<forall>p [\\<in>] A. max_list (vars_fm p) < ?n\\<close> and B: \\<open>\\<forall>p [\\<in>] B. max_list (vars_fm p) < ?n\\<close>\n    unfolding fresh_def using max_list_vars_fms max_list_mono vars_fms_member\n    by (metis Un_iff le_imp_less_Suc set_append)+\n  from 8 have \\<open>sc (E(?n := x), F, G) (A, \\<langle>\\<^bold>#?n\\<rangle>p # B [\\<div>] \\<^bold>\\<forall>p)\\<close> for x\n    by (metis eff.simps(8) finsert_iff option.inject option.simps(3))\n  then have \\<open>(\\<forall>p [\\<in>] A. \\<lbrakk>E, F, G\\<rbrakk> p) \\<longrightarrow>\n      (\\<forall>x. \\<lbrakk>(x \\<Zsemi> \\<lambda>m. (E(?n := x)) m), F, G\\<rbrakk> p) \\<or> (\\<exists>q [\\<in>] B [\\<div>] \\<^bold>\\<forall>p. \\<lbrakk>E, F, G\\<rbrakk> q)\\<close>\n    using A B upd_vars_fm by fastforce\n  then have \\<open>(\\<forall>p [\\<in>] A. \\<lbrakk>E, F, G\\<rbrakk> p) \\<longrightarrow>\n      (\\<forall>x. \\<lbrakk>((x \\<Zsemi> E)(Suc ?n := x)), F, G\\<rbrakk> p) \\<or> (\\<exists>q [\\<in>] B [\\<div>] \\<^bold>\\<forall>p. \\<lbrakk>E, F, G\\<rbrakk> q)\\<close>\n    unfolding add_upd_commute by blast\n  moreover have \\<open>max_list (vars_fm p) < ?n\\<close>\n    using B \"8.prems\"(1) by (metis eff.simps(8) option.distinct(1) vars_fm.simps(4))\n  ultimately have \\<open>sc (E, F, G) (A, \\<^bold>\\<forall>p # (B [\\<div>] \\<^bold>\\<forall>p))\\<close>\n    by auto\n  moreover have \\<open>\\<^bold>\\<forall>p [\\<in>] B\\<close>\n    using \"8.prems\"(1) by (simp split: if_splits)\n  ultimately show ?case\n    by (metis (full_types) Diff_iff sc.simps set_ConsD set_removeAll)\nqed (fastforce split: if_splits)+\n\ninterpretation Soundness \\<open>\\<lambda>r s ss. eff r s = Some ss\\<close> rules UNIV sc\n  unfolding Soundness_def using eff_sound by fast\n\ntheorem prover_soundness:\n  assumes \\<open>tfinite t\\<close> and \\<open>wf t\\<close>\n  shows \\<open>sc (E, F, G) (fst (root t))\\<close>\n  using assms soundness by fast\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/FOL_Seq_Calc3/Soundness.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.2729037844611154}}
{"text": "theory Proof_3_2\n  imports Proofs_3\nbegin\n\n\ncontext\n  fixes s2 s0:: state\nfixes user_value pressure_value:: bool\nassumes toEnvPs2:  \"toEnvP s2 \\<and> toEnvP s0\" and extraInvs0: \"extraInv s0\" \nand vc: \" env (setVarAny s0 user_value pressure_value) \\<and>\n         getPstate (setVarAny s0 user_value pressure_value) ERROR = Controller'motionless \\<and>\n        getVarBool (setVarAny s0 user_value pressure_value) user\"\nbegin\n\nlemma VC2_R3_ind_step_aux1: \" toEnvP s2a \\<Longrightarrow>\n         substate s2 s2a \\<and>\n         substate s2a\n          (toEnv\n            (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR Controller'suspended)) \\<and>\n         s2 \\<noteq> s2a \\<Longrightarrow>\n         substate s1 s2 \\<and>\n         substate s2\n          (toEnv\n            (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR Controller'suspended)) \\<and>\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         toEnvNum s1 s2 = ERROR \\<and>\n         DELAY'TIMEOUT =\n         toEnvNum s2\n          (toEnv\n            (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR Controller'suspended)) \\<and>\n         getVarBool s1 rotation = True \\<and>\n         \\<not> getVarBool s2 user \\<and>\n         (\\<forall>s4. toEnvP s4 \\<and> substate s2 s4 \\<and> substate s4 s2a \\<and> s4 \\<noteq> s2a \\<longrightarrow>\n               getVarBool s4 rotation = True \\<and> \\<not> getVarBool s4 user) \\<longrightarrow>\n         (\\<exists>s4. toEnvP s4 \\<and>\n               substate s2a s4 \\<and>\n               substate s4\n                (toEnv\n                  (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR\n                    Controller'suspended)) \\<and>\n               toEnvNum s2 s4 \\<le> DELAY'TIMEOUT \\<and>\n               (getVarBool s4 rotation = False \\<or> getVarBool s4 user) \\<and>\n               (\\<forall>s3. toEnvP s3 \\<and> substate s2a s3 \\<and> substate s3 s4 \\<and> s3 \\<noteq> s4 \\<longrightarrow>\n                     getVarBool s3 rotation = True \\<and> \\<not> getVarBool s3 user)) \\<Longrightarrow>\n         substate s1 s2 \\<and>\n         substate s2\n          (toEnv\n            (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR Controller'suspended)) \\<and>\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         toEnvNum s1 s2 = ERROR \\<and>\n         DELAY'TIMEOUT =\n         toEnvNum s2\n          (toEnv\n            (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR Controller'suspended)) \\<and>\n         getVarBool s1 rotation = True \\<and>\n         \\<not> getVarBool s2 user \\<and>\n         (\\<forall>s4. toEnvP s4 \\<and> substate s2 s4 \\<and> substate s4 (predEnv s2a) \\<and> s4 \\<noteq> predEnv s2a \\<longrightarrow>\n               getVarBool s4 rotation = True \\<and> \\<not> getVarBool s4 user) \\<Longrightarrow>\n         \\<not> (getVarBool (predEnv s2a) rotation = False \\<or> getVarBool (predEnv s2a) user) \\<Longrightarrow>\n         toEnvP x \\<and>\n         substate s2a x \\<and>\n         substate x\n          (toEnv\n            (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR Controller'suspended)) \\<and>\n         toEnvNum s2 x \\<le> DELAY'TIMEOUT \\<and>\n         (getVarBool x rotation = False \\<or> getVarBool x user) \\<and>\n         (\\<forall>s3. toEnvP s3 \\<and> substate s2a s3 \\<and> substate s3 x \\<and> s3 \\<noteq> x \\<longrightarrow>\n               getVarBool s3 rotation = True \\<and> \\<not> getVarBool s3 user) \\<Longrightarrow>\n         \\<exists>s4. toEnvP s4 \\<and>\n              substate (predEnv s2a) s4 \\<and>\n              substate s4\n               (toEnv\n                 (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR\n                   Controller'suspended)) \\<and>\n              toEnvNum s2 s4 \\<le> DELAY'TIMEOUT \\<and>\n              (getVarBool s4 rotation = False \\<or> getVarBool s4 user) \\<and>\n              (\\<forall>s3. toEnvP s3 \\<and> substate (predEnv s2a) s3 \\<and> substate s3 s4 \\<and> s3 \\<noteq> s4 \\<longrightarrow>\n                    getVarBool s3 rotation = True \\<and> \\<not> getVarBool s3 user)\"\n  apply(rule exI[of _ x])\n  by (smt (z3) predEnv_substate predEnv_substate_imp_eq_or_substate substate_trans)\n  \nlemma VC2_R3_ind_step: \" toEnvP s2a \\<Longrightarrow>\n           substate s2 s2a \\<and>\n           substate s2a\n            (toEnv\n              (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR\n                Controller'suspended)) \\<and>\n           s2 \\<noteq> s2a \\<Longrightarrow>\n           substate s1 s2 \\<and>\n           substate s2\n            (toEnv\n              (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR\n                Controller'suspended)) \\<and>\n           toEnvP s1 \\<and>\n           toEnvP s2 \\<and>\n           toEnvNum s1 s2 = ERROR \\<and>\n           DELAY'TIMEOUT =\n           toEnvNum s2\n            (toEnv\n              (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR\n                Controller'suspended)) \\<and>\n           getVarBool s1 rotation = True \\<and>\n           \\<not> getVarBool s2 user \\<and>\n           (\\<forall>s4. toEnvP s4 \\<and> substate s2 s4 \\<and> substate s4 s2a \\<and> s4 \\<noteq> s2a \\<longrightarrow>\n                 getVarBool s4 rotation = True \\<and> \\<not> getVarBool s4 user) \\<longrightarrow>\n           (\\<exists>s4. toEnvP s4 \\<and>\n                 substate s2a s4 \\<and>\n                 substate s4\n                  (toEnv\n                    (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR\n                      Controller'suspended)) \\<and>\n                 toEnvNum s2 s4 \\<le> DELAY'TIMEOUT \\<and>\n                 (getVarBool s4 rotation = False \\<or> getVarBool s4 user) \\<and>\n                 (\\<forall>s3. toEnvP s3 \\<and> substate s2a s3 \\<and> substate s3 s4 \\<and> s3 \\<noteq> s4 \\<longrightarrow>\n                       getVarBool s3 rotation = True \\<and> \\<not> getVarBool s3 user)) \\<Longrightarrow>\n           substate s1 s2 \\<and>\n           substate s2\n            (toEnv\n              (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR\n                Controller'suspended)) \\<and>\n           toEnvP s1 \\<and>\n           toEnvP s2 \\<and>\n           toEnvNum s1 s2 = ERROR \\<and>\n           DELAY'TIMEOUT =\n           toEnvNum s2\n            (toEnv\n              (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR\n                Controller'suspended)) \\<and>\n           getVarBool s1 rotation = True \\<and>\n           \\<not> getVarBool s2 user \\<and>\n           (\\<forall>s4. toEnvP s4 \\<and> substate s2 s4 \\<and> substate s4 (predEnv s2a) \\<and> s4 \\<noteq> predEnv s2a \\<longrightarrow>\n                 getVarBool s4 rotation = True \\<and> \\<not> getVarBool s4 user) \\<longrightarrow>\n           (\\<exists>s4. toEnvP s4 \\<and>\n                 substate (predEnv s2a) s4 \\<and>\n                 substate s4\n                  (toEnv\n                    (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR\n                      Controller'suspended)) \\<and>\n                 toEnvNum s2 s4 \\<le> DELAY'TIMEOUT \\<and>\n                 (getVarBool s4 rotation = False \\<or> getVarBool s4 user) \\<and>\n                 (\\<forall>s3. toEnvP s3 \\<and> substate (predEnv s2a) s3 \\<and> substate s3 s4 \\<and> s3 \\<noteq> s4 \\<longrightarrow>\n                       getVarBool s3 rotation = True \\<and> \\<not> getVarBool s3 user))\"\n  apply(rule impI)\n  apply(cases \"(getVarBool (predEnv s2a) rotation = False \\<or> getVarBool (predEnv s2a) user)\")\n   apply(rule exI[of _ \"predEnv s2a\"])\n   apply(rule conjI)\n    apply(rule toEnvP_substate_pred_imp_toEnvP_pred[of s2])\n  using toEnvPs2 substate_eq_or_predEnv apply fast\n   apply(rule conjI)\n  using substate_refl apply fast\n   apply(rule conjI)\n  using predEnv_substate substate_trans apply fast\n   apply(rule conjI)\n    apply(rule cut_rl[of \"substate s2 (predEnv s2a) \\<and>\n substate (predEnv s2a)\n (toEnv (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR Controller'suspended))\"])\n  using toEnvNum3[of s2 \"predEnv s2a\" \n\"(toEnv (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR Controller'suspended))\"]\n     apply arith\n  using substate_eq_or_predEnv predEnv_substate substate_trans apply fast\n   apply(rule conjI)\n    apply assumption\n  using substate_asym apply fast\n  apply(rule exE[of \"\\<lambda> s4. toEnvP s4 \\<and>\n          substate s2a s4 \\<and>\n          substate s4\n           (toEnv\n             (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR Controller'suspended)) \\<and>\n          toEnvNum s2 s4 \\<le> DELAY'TIMEOUT \\<and>\n          (getVarBool s4 rotation = False \\<or> getVarBool s4 user) \\<and>\n          (\\<forall>s3. toEnvP s3 \\<and> substate s2a s3 \\<and> substate s3 s4 \\<and> s3 \\<noteq> s4 \\<longrightarrow>\n                getVarBool s3 rotation = True \\<and> \\<not> getVarBool s3 user)\"])\n  using substate_eq_or_predEnv apply blast\n  by ((rule VC2_R3_ind_step_aux1);blast)\n \nlemma VC2_R3_ind_proof:   \"toEnvP s5 \\<and>  substate s2 s5 \\<and>\n substate s5 (toEnv\n          (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR Controller'suspended))\n \\<longrightarrow> pred3 s1 s2 (toEnv\n          (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR Controller'suspended))\n s5\"\n  apply(induction rule: state_down_ind)\n  using toEnvPs2 apply simp\n   apply(simp only: pred3_def)\n   apply(rule impI)\n  apply(rule cut_rl[of \"getVarBool s0 rotation = False\"])\n    apply(rule cut_rl[of \"getVarBool s0 rotation = True \\<and> \\<not> getVarBool s0 user\"])\n     apply fast\n  apply(rule cut_rl[of \"substate s2 s0 \\<and>\n          substate s0\n           (toEnv\n             (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR Controller'suspended)) \\<and>\n          s0 \\<noteq>\n          toEnv\n           (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR Controller'suspended) \"])\n  using toEnvPs2  apply fast\n  using substate_refl toEnvNum_id apply((simp split: if_splits);auto)\n  using extraInvs0 extraInv_def vc\n   apply (smt (verit) getPstate.simps(9) predEnv.simps(9) predEnv_substate substate_eq_or_predEnv toEnvPs2)\n apply(simp only: pred3_def)\n  by ((rule VC2_R3_ind_step);fast) \nend\n\n\nlemma VC2_R3: \" (((((toEnvP s0 \\<and>\n            (\\<forall>s1 s2.\n                substate s1 s2 \\<and>\n                substate s2 s0 \\<and>\n                toEnvP s1 \\<and>\n                toEnvP s2 \\<and>\n                toEnvNum s1 s2 = ERROR \\<and>\n                DELAY'TIMEOUT \\<le> toEnvNum s2 s0 \\<and> getVarBool s1 rotation = True \\<and> \\<not> getVarBool s2 user \\<longrightarrow>\n                (\\<exists>s4. toEnvP s4 \\<and>\n                      substate s2 s4 \\<and>\n                      substate s4 s0 \\<and>\n                      toEnvNum s2 s4 \\<le> DELAY'TIMEOUT \\<and>\n                      (getVarBool s4 rotation = False \\<or> getVarBool s4 user) \\<and>\n                      (\\<forall>s3. toEnvP s3 \\<and> substate s2 s3 \\<and> substate s3 s4 \\<and> s3 \\<noteq> s4 \\<longrightarrow>\n                            getVarBool s3 rotation = True \\<and> \\<not> getVarBool s3 user)))) \\<and>\n           extraInv s0) \\<and>\n          env (setVarAny s0 user_value pressure_value)) \\<and>\n         getPstate (setVarAny s0 user_value pressure_value) ERROR = Controller'motionless) \\<and>\n        getVarBool (setVarAny s0 user_value pressure_value) user) \\<and>\n       getVarBool (setVarAny s0 user_value pressure_value) pressure \\<Longrightarrow>\n       substate s1 s2 \\<and>\n       substate s2\n        (toEnv\n          (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR Controller'suspended)) \\<and>\n       toEnvP s1 \\<and>\n       toEnvP s2 \\<and>\n       toEnvNum s1 s2 = ERROR \\<and>\n       DELAY'TIMEOUT\n       \\<le> toEnvNum s2\n           (toEnv\n             (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR Controller'suspended)) \\<and>\n       getVarBool s1 rotation = True \\<and> \\<not> getVarBool s2 user \\<longrightarrow>\n       (\\<exists>s4. toEnvP s4 \\<and>\n             substate s2 s4 \\<and>\n             substate s4\n              (toEnv\n                (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR\n                  Controller'suspended)) \\<and>\n             toEnvNum s2 s4 \\<le> DELAY'TIMEOUT \\<and>\n             (getVarBool s4 rotation = False \\<or> getVarBool s4 user) \\<and>\n             (\\<forall>s3. toEnvP s3 \\<and> substate s2 s3 \\<and> substate s3 s4 \\<and> s3 \\<noteq> s4 \\<longrightarrow>\n                   getVarBool s3 rotation = True \\<and> \\<not> getVarBool s3 user))\"\n  apply(rule impI)\n  apply(rule disjE[of \"DELAY'TIMEOUT < toEnvNum s2 (toEnv\n             (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR Controller'suspended))\"\n\"DELAY'TIMEOUT = toEnvNum s2 (toEnv\n             (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR Controller'suspended))\"])\n  using le_imp_less_or_eq apply fast\n   apply(rule cut_rl[of \"substate s2 s0 \\<and> toEnvNum s2 s0 \\<ge> DELAY'TIMEOUT\"])\n  apply(rule cut_rl[of \"(\\<exists>s4. toEnvP s4 \\<and>\n                   substate s2 s4 \\<and>\n                   substate s4 s0 \\<and>\n                   toEnvNum s2 s4 \\<le> DELAY'TIMEOUT \\<and>\n                   (getVarBool s4 rotation = False \\<or> getVarBool s4 user) \\<and>\n                   (\\<forall>s3. toEnvP s3 \\<and> substate s2 s3 \\<and> substate s3 s4 \\<and> s3 \\<noteq> s4 \\<longrightarrow>\n                         getVarBool s3 rotation = True \\<and> \\<not> getVarBool s3 user))\"])\n  apply (metis substate.simps(10) substate.simps(2) substate.simps(3) substate.simps(9))\n    apply blast\n   apply(simp split: if_splits)\n  apply(rule cut_rl[of \"pred3 s1 s2 \n (toEnv\n                (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR\n                  Controller'suspended))\ns2\"])\n   apply(simp only: pred3_def)\n   apply (smt (z3) substate_asym)\n   apply(rule mp[of \"toEnvP s2 \\<and>  substate s2 s2 \\<and>\n substate s2 (toEnv\n          (setPstate (setVarBool (setVarAny s0 user_value pressure_value) brake True) ERROR Controller'suspended))\"])\n   apply((rule VC2_R3_ind_proof);blast)\n  using substate_refl by fast\n  \n  \n\ntheorem proof_3_2: \"VC2 inv3 env s0 user_value pressure_value\"\n  apply(simp only: VC2_def inv3_def R3_def)\n  apply(rule impI)\n  apply(rule conjI)\n  apply(rule conjI)\n   apply(simp)\n   apply((rule allI);(rule allI))\n   apply((rule VC2_R3);blast)", "meta": {"author": "ivchernenko", "repo": "post_vcgenerator", "sha": "fadfff131086870a027d6bd1c78b8d5a3baf183b", "save_path": "github-repos/isabelle/ivchernenko-post_vcgenerator", "path": "github-repos/isabelle/ivchernenko-post_vcgenerator/post_vcgenerator-fadfff131086870a027d6bd1c78b8d5a3baf183b/case-studies/revolvingDoor/Proof_3_2.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6513548646660543, "lm_q2_score": 0.41869690935568665, "lm_q1q2_score": 0.2727202687294685}}
{"text": "section {*FUNCTION\\_\\_DPDA\\_OTS\\_\\_DPDA\\_OBSERVE\\_TOP\\_STACK*}\ntheory\n  FUNCTION__DPDA_OTS__DPDA_OBSERVE_TOP_STACK\n\nimports\n  PRJ_13_02__ENTRY\n\nbegin\n\ndefinition F_DPDA_OTS__get_state :: \"\n  ('state, 'stack) DT_state_and_stack_or_state\n  \\<Rightarrow> 'state\"\n  where\n    \"F_DPDA_OTS__get_state x \\<equiv>\n  case x of\n  cons_state_and_stack a b \\<Rightarrow> a\n  | cons_state a \\<Rightarrow> a\"\n\ndefinition F_DPDA_OTS__get_stack :: \"\n  ('state, 'stack) DT_state_and_stack_or_state\n  \\<Rightarrow> 'stack option\"\n  where\n    \"F_DPDA_OTS__get_stack x \\<equiv>\n  case x of\n  cons_state_and_stack a b \\<Rightarrow> Some b\n  | cons_state a \\<Rightarrow> None\"\n\ndefinition F_DPDA_OTS__is_auxiliary :: \"\n  ('state, 'stack) DT_state_and_stack_or_state\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_OTS__is_auxiliary x \\<equiv>\n  case x of\n  cons_state_and_stack a b \\<Rightarrow> True\n  | cons_state a \\<Rightarrow> False\"\n\ndefinition F_DPDA_OTS__is_main :: \"\n  ('state, 'stack) DT_state_and_stack_or_state\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_OTS__is_main x \\<equiv>\n  case x of\n  cons_state_and_stack a b \\<Rightarrow> False\n  | cons_state a \\<Rightarrow> True\"\n\nlemma F_DPDA_OTS__preserves__PDA: \"\n  valid_pda M\n  \\<Longrightarrow> F_DPDA_OTS M = N\n  \\<Longrightarrow> valid_pda N\"\n  apply(simp add: F_DPDA_OTS_def valid_pda_def valid_epda_def)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_OTS__states_def)\n   apply(rule conjI)\n    apply(simp add: F_DPDA_OTS__states_auxiliary_def)\n   apply(simp add: F_DPDA_OTS__states_main_def)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_OTS__edges_def)\n   apply(rule conjI)\n    apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def)\n   apply(simp add: F_DPDA_OTS__edges_auxiliary_main_def)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_OTS__states_auxiliary_def F_DPDA_OTS__states_def)\n   apply(force)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_OTS__marking_states_def F_DPDA_OTS__states_auxiliary_def F_DPDA_OTS__states_def)\n   apply(force)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_def valid_epda_step_label_def F_DPDA_OTS__marking_states_def F_DPDA_OTS__states_auxiliary_def F_DPDA_OTS__states_def F_DPDA_OTS__states_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n   apply(erule disjE)\n    apply(rename_tac x)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac a b)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac a b)(*strict*)\n     apply(force)\n    apply(rename_tac a b)(*strict*)\n    apply(simp add: option_to_set_def)\n    apply(simp add: may_terminated_by_def append_language_def append_alphabet_def kleene_star_def)\n    apply(case_tac \"b = epda_box M\")\n     apply(rename_tac a b)(*strict*)\n     apply(rule_tac\n      x=\"[]\"\n      in exI)\n     apply(clarsimp)\n    apply(rename_tac a b)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac xa)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_def valid_epda_step_label_def F_DPDA_OTS__marking_states_def F_DPDA_OTS__states_auxiliary_def F_DPDA_OTS__states_def F_DPDA_OTS__states_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n   apply(erule_tac\n      x=\"xa\"\n      and P=\"\\<lambda>xa. edge_src xa \\<in> epda_states M \\<and> edge_trg xa \\<in> epda_states M \\<and> option_to_set (edge_event xa) \\<subseteq> epda_events M \\<and> edge_pop xa \\<in> may_terminated_by (epda_gamma M) (epda_box M) \\<and> edge_push xa \\<in> may_terminated_by (epda_gamma M) (epda_box M) \\<and> (edge_pop xa \\<in> must_terminated_by (epda_gamma M) (epda_box M)) = (edge_push xa \\<in> must_terminated_by (epda_gamma M) (epda_box M))\"\n      in ballE)\n    apply(rename_tac xa)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac xa)(*strict*)\n   apply(clarsimp)\n   apply(rule inMap)\n   apply(rule_tac\n      x=\"((edge_src xa),(hd (edge_pop xa)))\"\n      in bexI)\n    apply(rename_tac xa)(*strict*)\n    apply(force)\n   apply(rename_tac xa)(*strict*)\n   apply(clarsimp)\n   apply(simp add: may_terminated_by_def append_language_def append_alphabet_def kleene_star_def)\n   apply(clarsimp)\n   apply(rename_tac xa a aa)(*strict*)\n   apply(erule_tac\n      x=\"xa\"\n      in ballE)\n    apply(rename_tac xa a aa)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac xa a aa)(*strict*)\n   apply(case_tac \"edge_pop xa\")\n    apply(rename_tac xa a aa)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac xa a aa ab list)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac xa a aa ab)(*strict*)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac e)(*strict*)\n  apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_def valid_epda_step_label_def F_DPDA_OTS__marking_states_def F_DPDA_OTS__states_auxiliary_def F_DPDA_OTS__states_def F_DPDA_OTS__states_main_def)\n  apply(erule disjE)\n   apply(rename_tac e)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac a b)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_def valid_epda_step_label_def F_DPDA_OTS__marking_states_def F_DPDA_OTS__states_auxiliary_def F_DPDA_OTS__states_def F_DPDA_OTS__states_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  apply(rename_tac e)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_def valid_epda_step_label_def F_DPDA_OTS__marking_states_def F_DPDA_OTS__states_auxiliary_def F_DPDA_OTS__states_def F_DPDA_OTS__states_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  done\n\ndefinition F_DPDA_OTS__epdaH_epdaH__LR__TSstructure :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_OTS__epdaH_epdaH__LR__TSstructure G1 G2 \\<equiv>\n  valid_dpda G1\n  \\<and> G2 = F_DPDA_OTS G1\"\n\ndefinition F_DPDA_OTS__epdaH_epdaH__LR__configuration1 :: \"\n  ('state, 'event, 'stack) epdaH_conf\n  \\<Rightarrow> (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epdaH_conf\"\n  where\n    \"F_DPDA_OTS__epdaH_epdaH__LR__configuration1 c \\<equiv>\n  \\<lparr>epdaH_conf_state = cons_state_and_stack (epdaH_conf_state c) (hd (epdaH_conf_stack c)),\n  epdaH_conf_history = epdaH_conf_history c,\n  epdaH_conf_stack = epdaH_conf_stack c\\<rparr>\"\n\ndefinition F_DPDA_OTS__epdaH_epdaH__LR__configurations :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epdaH_conf\n  \\<Rightarrow> (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epdaH_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_OTS__epdaH_epdaH__LR__configurations G1 G2 c1 c2 \\<equiv>\n  F_DPDA_OTS__epdaH_epdaH__LR__TSstructure G1 G2\n  \\<and> c1 \\<in> epdaH.get_accessible_configurations G1\n  \\<and> c2 = F_DPDA_OTS__epdaH_epdaH__LR__configuration1 c1\"\n\ndefinition F_DPDA_OTS__epdaH_epdaH__LR__initial_configuration :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epdaH_conf\n  \\<Rightarrow> (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epdaH_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_OTS__epdaH_epdaH__LR__initial_configuration G1 G2 c1 c2 \\<equiv>\n  F_DPDA_OTS__epdaH_epdaH__LR__TSstructure G1 G2\n  \\<and> c1 \\<in> epdaH_initial_configurations G1\n  \\<and> c2 = F_DPDA_OTS__epdaH_epdaH__LR__configuration1 c1\"\n\ndefinition F_DPDA_OTS__epdaH_epdaH__LR__effect :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epda\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_OTS__epdaH_epdaH__LR__effect G1 G2 w1 w2 \\<equiv>\n  F_DPDA_OTS__epdaH_epdaH__LR__TSstructure G1 G2\n  \\<and> w1 = w2\"\n\nlemma F_DPDA_OTS__epdaH_epdaH__LR__inst__AX_TSstructure_relation_TSstructure1_belongs: \"\n  (\\<forall>G1. Ex (F_DPDA_OTS__epdaH_epdaH__LR__TSstructure G1) \\<longrightarrow> valid_epda G1)\"\n  apply(clarsimp)\n  apply(rename_tac G1 x)(*strict*)\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__TSstructure_def)\n  apply(clarsimp)\n  apply(rename_tac G1)(*strict*)\n  apply(simp add: valid_dpda_def valid_pda_def)\n  done\n\nlemma F_DPDA_OTS__epdaH_epdaH__LR__inst__AX_TSstructure_relation_TSstructure2_belongs: \"\n  (\\<forall>G1 G2. F_DPDA_OTS__epdaH_epdaH__LR__TSstructure G1 G2 \\<longrightarrow> valid_epda G2)\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2)(*strict*)\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__TSstructure_def)\n  apply(clarsimp)\n  apply(rename_tac G1)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac G1)(*strict*)\n   prefer 2\n   apply(rule F_DPDA_OTS__preserves__PDA)\n    apply(rename_tac G1)(*strict*)\n    apply(simp add: valid_dpda_def)\n    apply(force)\n   apply(rename_tac G1)(*strict*)\n   apply(force)\n  apply(rename_tac G1)(*strict*)\n  apply(simp add: valid_pda_def)\n  done\n\ndefinition F_DPDA_OTS__epdaH_epdaH__LR__step_simulation :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epdaH_conf\n  \\<Rightarrow> ('state, 'event, 'stack) epda_step_label\n  \\<Rightarrow> ('state, 'event, 'stack) epdaH_conf\n  \\<Rightarrow> (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epdaH_conf\n  \\<Rightarrow> ((('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epda_step_label, (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epdaH_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_OTS__epdaH_epdaH__LR__step_simulation G1 G2 c1 e c1' c2 d \\<equiv>\n  let\n    ci = F_DPDA_OTS__epdaH_epdaH__LR__configuration1 c1'\n  in\n    d = der3\n          c2\n            (F_DPDA_OTS__edges_auxiliary_main_1 e)\n          (ci\\<lparr>epdaH_conf_state := cons_state (edge_trg e)\\<rparr>)\n            (F_DPDA_OTS__edges_main_auxiliary_1 (edge_trg e) (hd (epdaH_conf_stack ci)))\n          ci\"\n\ndefinition F_DPDA_OTS__epdaH_epdaH__LR__initial_simulation :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epdaH_conf\n  \\<Rightarrow> ((('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epda_step_label, (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epdaH_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_OTS__epdaH_epdaH__LR__initial_simulation G1 G2 c1 d \\<equiv>\n  d = der1 (F_DPDA_OTS__epdaH_epdaH__LR__configuration1 c1)\"\n\nlemma F_DPDA_OTS__epdaH_epdaH__LR__inst__relation_initial_simulation: \"\n  (\\<forall>G1 G2. F_DPDA_OTS__epdaH_epdaH__LR__TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaH_initial_configurations G1 \\<longrightarrow> (\\<exists>d2. epdaH.derivation_initial G2 d2 \\<and> F_DPDA_OTS__epdaH_epdaH__LR__initial_configuration G1 G2 c1 (the (get_configuration (d2 0))) \\<and> F_DPDA_OTS__epdaH_epdaH__LR__initial_simulation G1 G2 c1 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_DPDA_OTS__epdaH_epdaH__LR__configurations G1 G2 c1 (the (get_configuration (d2 n)))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__initial_simulation_def F_DPDA_OTS__epdaH_epdaH__LR__initial_configuration_def F_DPDA_OTS__epdaH_epdaH__LR__TSstructure_def)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule epdaH.derivation_initialI)\n    apply(rename_tac G1 G2 c1)(*strict*)\n    apply(rule epdaH.der1_is_derivation)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: der1_def get_configuration_def epdaH_initial_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def)\n   apply(clarsimp)\n   apply(rename_tac G1)(*strict*)\n   apply(simp add: F_DPDA_OTS__states_def der1_def get_configuration_def epdaH_initial_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def)\n   apply(rule disjI1)\n   apply(simp add: F_DPDA_OTS__states_auxiliary_def)\n   apply(force)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: F_DPDA_OTS__states_def der1_def get_configuration_def epdaH_initial_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule_tac\n      x=\"0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule der1_maximum_of_domain)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__configurations_def)\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__initial_simulation_def F_DPDA_OTS__epdaH_epdaH__LR__initial_configuration_def F_DPDA_OTS__epdaH_epdaH__LR__TSstructure_def)\n  apply(simp add: F_DPDA_OTS__states_def get_configuration_def epdaH_initial_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def)\n  apply(simp add: F_DPDA_OTS__states_def der1_def get_configuration_def epdaH_initial_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def)\n  apply(simp add: epdaH.get_accessible_configurations_def)\n  apply(rule_tac\n      x=\"der1 c1\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule epdaH.derivation_initialI)\n    apply(rename_tac G1 G2 c1)(*strict*)\n    apply(rule epdaH.der1_is_derivation)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: der1_def get_configuration_def epdaH_initial_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule_tac\n      x=\"0\"\n      in exI)\n  apply(simp add: F_DPDA_OTS__states_def get_configuration_def epdaH_initial_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def)\n  apply(simp add: F_DPDA_OTS__states_def der1_def get_configuration_def epdaH_initial_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def)\n  done\n\nlemma F_DPDA_OTS__epdaH_epdaH__LR__inst__relation_step_simulation: \"\n  (\\<forall>G1 G2. F_DPDA_OTS__epdaH_epdaH__LR__TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_DPDA_OTS__epdaH_epdaH__LR__configurations G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaH_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<exists>d2. epdaH.derivation G2 d2 \\<and> epdaH.belongs G2 d2 \\<and> the (get_configuration (d2 0)) = c2 \\<and> F_DPDA_OTS__epdaH_epdaH__LR__step_simulation G1 G2 c1 e1 c1' c2 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_DPDA_OTS__epdaH_epdaH__LR__configurations G1 G2 c1' (the (get_configuration (d2 n)))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__configurations_def Let_def F_DPDA_OTS__epdaH_epdaH__LR__step_simulation_def F_DPDA_OTS__epdaH_epdaH__LR__initial_simulation_def F_DPDA_OTS__epdaH_epdaH__LR__initial_configuration_def F_DPDA_OTS__epdaH_epdaH__LR__TSstructure_def)\n  apply(clarsimp)\n  apply(rename_tac G1 c1 e1 c1')(*strict*)\n  apply(rule context_conjI)\n   apply(rename_tac G1 c1 e1 c1')(*strict*)\n   apply(rule epdaH.der3_is_derivation)\n     apply(rename_tac G1 c1 e1 c1')(*strict*)\n     apply (metis F_DPDA_OTS__epdaH_epdaH__LR__inst__AX_TSstructure_relation_TSstructure2_belongs F_DPDA_OTS__epdaH_epdaH__LR__TSstructure_def)\n    apply(rename_tac G1 c1 e1 c1')(*strict*)\n    apply(simp (no_asm) only: epdaH_step_relation_def F_DPDA_OTS__edges_auxiliary_main_1_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def)\n    apply(rule conjI)\n     apply(rename_tac G1 c1 e1 c1')(*strict*)\n     apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def)\n     apply(rule disjI2)\n     apply(simp add: F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n     apply(rule inMap)\n     apply(rule_tac\n      x=\"e1\"\n      in bexI)\n      apply(rename_tac G1 c1 e1 c1')(*strict*)\n      apply(simp add: F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def epda_step_labels_def)\n     apply(rename_tac G1 c1 e1 c1')(*strict*)\n     apply(simp add: F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def epda_step_labels_def)\n    apply(rename_tac G1 c1 e1 c1')(*strict*)\n    apply(rule conjI)\n     apply(rename_tac G1 c1 e1 c1')(*strict*)\n     apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def epdaH_step_relation_def)\n     apply(clarsimp)\n     apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n     apply(simp add: valid_dpda_def valid_pda_def)\n     apply(clarsimp)\n     apply(erule_tac\n      x=\"e1\"\n      in ballE)\n      apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n     apply(case_tac \"edge_pop e1\")\n      apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac G1 c1 e1 c1' w a list)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1')(*strict*)\n    apply(rule conjI)\n     apply(rename_tac G1 c1 e1 c1')(*strict*)\n     apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def epdaH_step_relation_def)\n    apply(rename_tac G1 c1 e1 c1')(*strict*)\n    apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def epdaH_step_relation_def)\n   apply(rename_tac G1 c1 e1 c1')(*strict*)\n   apply(simp (no_asm) only: epdaH_step_relation_def F_DPDA_OTS__edges_auxiliary_main_1_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def)\n   apply(rule conjI)\n    apply(rename_tac G1 c1 e1 c1')(*strict*)\n    apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def)\n    apply(rule disjI1)\n    apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def)\n    apply(rule inMap)\n    apply(rule_tac\n      x=\"(edge_trg e1,hd (epdaH_conf_stack c1'))\"\n      in bexI)\n     apply(rename_tac G1 c1 e1 c1')(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1')(*strict*)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def epda_step_labels_def epdaH_step_relation_def)\n    apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n    apply(simp add: valid_dpda_def valid_pda_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"e1\"\n      in ballE)\n     apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n    apply(case_tac \"edge_pop e1\")\n     apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1' w a list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1' w a)(*strict*)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac G1 c1 e1 c1' w a)(*strict*)\n     prefer 2\n     apply(rule_tac\n      c=\"c1\"\n      in epdaH_epda_stack_is_must_terminated_by)\n      apply(rename_tac G1 c1 e1 c1' w a)(*strict*)\n      apply(force)\n     apply(rename_tac G1 c1 e1 c1' w a)(*strict*)\n     apply(force)\n    apply(rename_tac G1 c1 e1 c1' w a)(*strict*)\n    apply(simp add: valid_epda_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"e1\"\n      in ballE)\n     apply(rename_tac G1 c1 e1 c1' w a)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 c1 e1 c1' w a)(*strict*)\n    apply(simp add: valid_epda_step_label_def)\n    apply(clarsimp)\n    apply(case_tac \"edge_push e1\")\n     apply(rename_tac G1 c1 e1 c1' w a)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G1 c1 e1 c1' a)(*strict*)\n     apply(case_tac \"epdaH_conf_stack c1'\")\n      apply(rename_tac G1 c1 e1 c1' a)(*strict*)\n      apply(clarsimp)\n      apply(simp add: must_terminated_by_def may_terminated_by_def append_language_def append_alphabet_def kleene_star_def)\n     apply(rename_tac G1 c1 e1 c1' a aa list)(*strict*)\n     apply(clarsimp)\n     apply(simp add: must_terminated_by_def may_terminated_by_def append_language_def append_alphabet_def kleene_star_def)\n     apply(clarsimp)\n     apply(rename_tac G1 c1 e1 c1' a aa list ab)(*strict*)\n     apply(case_tac ab)\n      apply(rename_tac G1 c1 e1 c1' a aa list ab)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac G1 c1 e1 c1' a aa list ab ac lista)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G1 c1 e1 c1' aa list ac lista)(*strict*)\n     apply(case_tac lista)\n      apply(rename_tac G1 c1 e1 c1' aa list ac lista)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac G1 c1 e1 c1' aa list ac lista a listb)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1' w a aa list)(*strict*)\n    apply(clarsimp)\n    apply(simp add: must_terminated_by_def may_terminated_by_def append_language_def append_alphabet_def kleene_star_def)\n    apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1' w a aa list ab ac ad)(*strict*)\n    apply(erule_tac\n      P=\"[] = ac \\<and> (\\<exists>a. set a \\<subseteq> epda_gamma G1 - {epda_box G1} \\<and> aa # list = a @ [epda_box G1])\"\n      in disjE)\n     apply(rename_tac G1 c1 e1 c1' w a aa list ab ac ad)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G1 c1 e1 c1' w aa list ab ad ae)(*strict*)\n     apply(erule disjE)\n      apply(rename_tac G1 c1 e1 c1' w aa list ab ad ae)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac G1 c1 e1 c1' w aa list ab ad)(*strict*)\n      apply(case_tac ad)\n       apply(rename_tac G1 c1 e1 c1' w aa list ab ad)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac G1 c1 e1 c1' w aa list ab ad a lista)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac G1 c1 e1 c1' w aa list ab ad ae)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G1 c1 e1 c1' w aa list ab ae)(*strict*)\n     apply(case_tac e1)\n     apply(rename_tac G1 c1 e1 c1' w aa list ab ae edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1' w a aa list ab ac ad)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1' w a aa list ab ad)(*strict*)\n    apply(case_tac e1)\n    apply(rename_tac G1 c1 e1 c1' w a aa list ab ad edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G1 c1 e1 c1')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G1 c1 e1 c1')(*strict*)\n    apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def epdaH_step_relation_def F_DPDA_OTS__edges_main_auxiliary_1_def)\n   apply(rename_tac G1 c1 e1 c1')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G1 c1 e1 c1')(*strict*)\n    apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def epdaH_step_relation_def F_DPDA_OTS__edges_main_auxiliary_1_def)\n   apply(rename_tac G1 c1 e1 c1')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G1 c1 e1 c1')(*strict*)\n    apply(simp add: option_to_list_def F_DPDA_OTS_def F_DPDA_OTS__edges_def epdaH_step_relation_def F_DPDA_OTS__edges_main_auxiliary_1_def)\n   apply(rename_tac G1 c1 e1 c1')(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS_def F_DPDA_OTS__edges_def epdaH_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n   apply(case_tac \"edge_push e1 @ w\")\n    apply(rename_tac G1 c1 e1 c1' w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1')(*strict*)\n    apply(simp add: valid_dpda_def valid_pda_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"e1\"\n      in ballE)\n     apply(rename_tac G1 c1 e1 c1')(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 c1 e1 c1')(*strict*)\n    apply(case_tac \"edge_pop e1\")\n     apply(rename_tac G1 c1 e1 c1')(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1' a list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1' a)(*strict*)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac G1 c1 e1 c1' a)(*strict*)\n     prefer 2\n     apply(rule_tac\n      c=\"c1\"\n      in epdaH_epda_stack_is_must_terminated_by)\n      apply(rename_tac G1 c1 e1 c1' a)(*strict*)\n      apply(force)\n     apply(rename_tac G1 c1 e1 c1' a)(*strict*)\n     apply(force)\n    apply(rename_tac G1 c1 e1 c1' a)(*strict*)\n    apply(simp add: valid_epda_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"e1\"\n      in ballE)\n     apply(rename_tac G1 c1 e1 c1' a)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 c1 e1 c1' a)(*strict*)\n    apply(simp add: valid_epda_step_label_def)\n    apply(clarsimp)\n    apply(simp add: must_terminated_by_def may_terminated_by_def append_language_def append_alphabet_def kleene_star_def)\n   apply(rename_tac G1 c1 e1 c1' w a list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 c1 e1 c1')(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 c1 e1 c1')(*strict*)\n   apply(rule epdaH.der3_belongs)\n     apply(rename_tac G1 c1 e1 c1')(*strict*)\n     apply (metis F_DPDA_OTS__epdaH_epdaH__LR__inst__AX_TSstructure_relation_TSstructure2_belongs F_DPDA_OTS__epdaH_epdaH__LR__TSstructure_def)\n    apply(rename_tac G1 c1 e1 c1')(*strict*)\n    apply(force)\n   apply(rename_tac G1 c1 e1 c1')(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac G1 c1 e1 c1')(*strict*)\n    prefer 2\n    apply(rule_tac\n      G=\"G1\"\n      and c=\"c1\"\n      in epdaH_epda_stack_is_must_terminated_by)\n     apply(rename_tac G1 c1 e1 c1')(*strict*)\n     apply(simp add: valid_dpda_def valid_pda_def)\n    apply(rename_tac G1 c1 e1 c1')(*strict*)\n    apply(force)\n   apply(rename_tac G1 c1 e1 c1')(*strict*)\n   apply(subgoal_tac \"c1 \\<in> epdaH_configurations G1\")\n    apply(rename_tac G1 c1 e1 c1')(*strict*)\n    prefer 2\n    apply(simp add: epdaH.get_accessible_configurations_def)\n    apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1' d i)(*strict*)\n    apply(case_tac \"d i\")\n     apply(rename_tac G1 c1 e1 c1' d i)(*strict*)\n     apply(clarsimp)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac G1 c1 e1 c1' d i a)(*strict*)\n    apply(clarsimp)\n    apply(simp add: get_configuration_def)\n    apply(case_tac a)\n    apply(rename_tac G1 c1 e1 c1' d i a option b)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 c1 e1 c1' d i option)(*strict*)\n    apply(rule epdaH.belongs_configurations)\n     apply(rename_tac G1 c1 e1 c1' d i option)(*strict*)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(rename_tac G1 c1 e1 c1' d i option)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def)\n     apply(rename_tac G1 c1 e1 c1' d i option)(*strict*)\n     apply(force)\n    apply(rename_tac G1 c1 e1 c1' d i option)(*strict*)\n    apply(force)\n   apply(rename_tac G1 c1 e1 c1')(*strict*)\n   apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def)\n   apply(clarsimp)\n   apply(rename_tac G1 e1 c1' q s h)(*strict*)\n   apply(case_tac s)\n    apply(rename_tac G1 e1 c1' q s h)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 e1 c1' q h)(*strict*)\n    apply(simp add: may_terminated_by_def must_terminated_by_def kleene_star_def append_language_def)\n   apply(rename_tac G1 e1 c1' q s h a list)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 e1 c1' q h a list)(*strict*)\n   apply(simp add: F_DPDA_OTS__states_def)\n   apply(rule disjI1)\n   apply(simp add: F_DPDA_OTS__states_auxiliary_def)\n   apply(force)\n  apply(rename_tac G1 c1 e1 c1')(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 c1 e1 c1')(*strict*)\n   apply(simp add: der3_def get_configuration_def)\n  apply(rename_tac G1 c1 e1 c1')(*strict*)\n  apply(rule_tac\n      x=\"Suc(Suc 0)\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 c1 e1 c1')(*strict*)\n   apply(rule_tac der3_maximum_of_domain)\n  apply(rename_tac G1 c1 e1 c1')(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 c1 e1 c1')(*strict*)\n   apply (metis F_DPDA_OTS__epdaH_epdaH__LR__inst__AX_TSstructure_relation_TSstructure1_belongs F_DPDA_OTS__epdaH_epdaH__LR__TSstructure_def epdaH.der2_is_derivation epdaH.der2_preserves_get_accessible_configurations)\n  apply(rename_tac G1 c1 e1 c1')(*strict*)\n  apply(simp add: der3_def get_configuration_def)\n  done\n\nlemma F_DPDA_OTS__epdaH_epdaH__LR__inst__ATS_Simulation_Configuration_Weak_axioms: \"\n  ATS_Simulation_Configuration_Weak_axioms valid_epda epdaH_initial_configurations epda_step_labels epdaH_step_relation valid_epda epdaH_configurations epdaH_initial_configurations epda_step_labels epdaH_step_relation F_DPDA_OTS__epdaH_epdaH__LR__configurations F_DPDA_OTS__epdaH_epdaH__LR__initial_configuration F_DPDA_OTS__epdaH_epdaH__LR__TSstructure F_DPDA_OTS__epdaH_epdaH__LR__initial_simulation F_DPDA_OTS__epdaH_epdaH__LR__step_simulation\"\n  apply(simp add: ATS_Simulation_Configuration_Weak_axioms_def F_DPDA_OTS__epdaH_epdaH__LR__inst__relation_initial_simulation F_DPDA_OTS__epdaH_epdaH__LR__inst__relation_step_simulation F_DPDA_OTS__epdaH_epdaH__LR__inst__AX_TSstructure_relation_TSstructure1_belongs F_DPDA_OTS__epdaH_epdaH__LR__inst__AX_TSstructure_relation_TSstructure2_belongs)\n  done\n\ninterpretation \"F_DPDA_OTS__epdaH_epdaH__LR\" : ATS_Simulation_Configuration_Weak\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaH_configurations\"\n  (* initial_configurations1 *)\n  \"epdaH_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaH_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaH_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaH_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaH_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaH_configurations\"\n  (* initial_configurations2 *)\n  \"epdaH_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaH_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaH_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaH_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaH_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_DPDA_OTS__epdaH_epdaH__LR__configurations\"\n  (* relation_initial_configuration *)\n  \"F_DPDA_OTS__epdaH_epdaH__LR__initial_configuration\"\n  (* relation_effect *)\n  \"F_DPDA_OTS__epdaH_epdaH__LR__effect\"\n  (* relation_TSstructure *)\n  \"F_DPDA_OTS__epdaH_epdaH__LR__TSstructure\"\n  (* relation_initial_simulation *)\n  \"F_DPDA_OTS__epdaH_epdaH__LR__initial_simulation\"\n  (* relation_step_simulation *)\n  \"F_DPDA_OTS__epdaH_epdaH__LR__step_simulation\"\n  apply(simp add: LOCALE_DEFS epda_interpretations)\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__inst__ATS_Simulation_Configuration_Weak_axioms)\n  done\n\ndefinition F_DPDA_OTS__epdaH_epdaH__RL__TSstructure :: \"\n  (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_OTS__epdaH_epdaH__RL__TSstructure G1 G2 \\<equiv>\n  valid_dpda G2\n  \\<and> G1 = F_DPDA_OTS G2\"\n\ndefinition F_DPDA_OTS__epdaH_epdaH__LR__configuration1R :: \"\n  (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epdaH_conf\n  \\<Rightarrow> ('state, 'event, 'stack) epdaH_conf\"\n  where\n    \"F_DPDA_OTS__epdaH_epdaH__LR__configuration1R c \\<equiv>\n  \\<lparr>epdaH_conf_state = F_DPDA_OTS__get_state (epdaH_conf_state c),\n  epdaH_conf_history = epdaH_conf_history c,\n  epdaH_conf_stack = epdaH_conf_stack c\\<rparr>\"\n\ndefinition F_DPDA_OTS__epdaH_epdaH__RL__configurations :: \"\n  (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epdaH_conf\n  \\<Rightarrow> ('state, 'event, 'stack) epdaH_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_OTS__epdaH_epdaH__RL__configurations G1 G2 c1 c2 \\<equiv>\n  F_DPDA_OTS__epdaH_epdaH__RL__TSstructure G1 G2\n  \\<and> c1 \\<in> epdaH.get_accessible_configurations G1\n  \\<and> c2 = F_DPDA_OTS__epdaH_epdaH__LR__configuration1R c1\"\n\ndefinition F_DPDA_OTS__epdaH_epdaH__RL__initial_configuration :: \"\n  (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epdaH_conf\n  \\<Rightarrow> ('state, 'event, 'stack) epdaH_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_OTS__epdaH_epdaH__RL__initial_configuration G1 G2 c1 c2 \\<equiv>\n  F_DPDA_OTS__epdaH_epdaH__RL__TSstructure G1 G2\n  \\<and> c1 \\<in> epdaH_initial_configurations G1\n  \\<and> c2 = F_DPDA_OTS__epdaH_epdaH__LR__configuration1R c1\"\n\ndefinition F_DPDA_OTS__epdaH_epdaH__RL__effect :: \"\n  (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_OTS__epdaH_epdaH__RL__effect G1 G2 w1 w2 \\<equiv>\n  F_DPDA_OTS__epdaH_epdaH__RL__TSstructure G1 G2\n  \\<and> w1 = w2\"\n\nlemma F_DPDA_OTS__epdaH_epdaH__RL__inst__AX_TSstructure_relation_TSstructure1_belongs: \"\n  (\\<forall>G1. Ex (F_DPDA_OTS__epdaH_epdaH__RL__TSstructure G1) \\<longrightarrow> valid_epda G1)\"\n  apply(clarsimp)\n  apply(rename_tac G1 x)(*strict*)\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__RL__TSstructure_def)\n  apply(rename_tac G2)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac G2)(*strict*)\n   prefer 2\n   apply(rule F_DPDA_OTS__preserves__PDA)\n    apply(rename_tac G2)(*strict*)\n    apply(simp add: valid_dpda_def)\n    apply(force)\n   apply(rename_tac G2)(*strict*)\n   apply(force)\n  apply(rename_tac G2)(*strict*)\n  apply(simp add: valid_pda_def)\n  done\n\nlemma F_DPDA_OTS__epdaH_epdaH__RL__inst__AX_TSstructure_relation_TSstructure2_belongs: \"\n  (\\<forall>G1 G2. F_DPDA_OTS__epdaH_epdaH__RL__TSstructure G1 G2 \\<longrightarrow> valid_epda G2)\"\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__RL__TSstructure_def)\n  apply(clarsimp)\n  apply(rename_tac G2)(*strict*)\n  apply (metis valid_dpda_def valid_pda_def)\n  done\n\ndefinition F_DPDA_OTS__epdaH_epdaH__RL__edge :: \"\n  (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epda_step_label\n  \\<Rightarrow> ('state, 'event, 'stack) epda_step_label\"\n  where\n    \"F_DPDA_OTS__epdaH_epdaH__RL__edge e \\<equiv>\n  \\<lparr>edge_src = F_DPDA_OTS__get_state (edge_src e),\n  edge_event = edge_event e,\n  edge_pop = edge_pop e,\n  edge_push = edge_push e,\n  edge_trg = F_DPDA_OTS__get_state (edge_trg e)\\<rparr>\"\n\ndefinition F_DPDA_OTS__epdaH_epdaH__LR__step_simulationRL :: \"\n  (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epdaH_conf\n  \\<Rightarrow> (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epda_step_label\n  \\<Rightarrow> (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epdaH_conf\n  \\<Rightarrow> ('state, 'event, 'stack) epdaH_conf\n  \\<Rightarrow> (('state, 'event, 'stack) epda_step_label, ('state, 'event, 'stack) epdaH_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_OTS__epdaH_epdaH__LR__step_simulationRL G1 G2 c1 e c1' c2 d \\<equiv>\n  case epdaH_conf_state c1 of\n  cons_state_and_stack q X \\<Rightarrow>\n      d = der2\n            (F_DPDA_OTS__epdaH_epdaH__LR__configuration1R c1)\n              (F_DPDA_OTS__epdaH_epdaH__RL__edge e)\n            (F_DPDA_OTS__epdaH_epdaH__LR__configuration1R c1')\n  | cons_state q \\<Rightarrow>\n      d = der1 (F_DPDA_OTS__epdaH_epdaH__LR__configuration1R c1)\"\n\ndefinition F_DPDA_OTS__epdaH_epdaH__LR__initial_simulationRL :: \"\n  (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epdaH_conf\n  \\<Rightarrow> (('state, 'event, 'stack) epda_step_label, ('state, 'event, 'stack) epdaH_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_OTS__epdaH_epdaH__LR__initial_simulationRL G1 G2 c1 d \\<equiv>\n  d = der1 (F_DPDA_OTS__epdaH_epdaH__LR__configuration1R c1)\"\n\nlemma F_DPDA_OTS__epdaH_epdaH__RL__inst__relation_initial_simulationRL: \"\n  (\\<forall>G1 G2. F_DPDA_OTS__epdaH_epdaH__RL__TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaH_initial_configurations G1 \\<longrightarrow> (\\<exists>d2. epdaH.derivation_initial G2 d2 \\<and> F_DPDA_OTS__epdaH_epdaH__RL__initial_configuration G1 G2 c1 (the (get_configuration (d2 0))) \\<and> F_DPDA_OTS__epdaH_epdaH__LR__initial_simulationRL G1 G2 c1 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_DPDA_OTS__epdaH_epdaH__RL__configurations G1 G2 c1 (the (get_configuration (d2 n)))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__initial_simulationRL_def F_DPDA_OTS__epdaH_epdaH__RL__initial_configuration_def F_DPDA_OTS__epdaH_epdaH__RL__TSstructure_def)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule epdaH.derivation_initialI)\n    apply(rename_tac G1 G2 c1)(*strict*)\n    apply(rule epdaH.der1_is_derivation)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: der1_def get_configuration_def epdaH_initial_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def)\n   apply(clarsimp)\n   apply(rename_tac G2)(*strict*)\n   apply(simp add: F_DPDA_OTS__get_state_def)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: F_DPDA_OTS__states_def der1_def get_configuration_def epdaH_initial_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule_tac\n      x=\"0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule der1_maximum_of_domain)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__RL__configurations_def)\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__initial_simulationRL_def F_DPDA_OTS__epdaH_epdaH__RL__initial_configuration_def F_DPDA_OTS__epdaH_epdaH__RL__TSstructure_def)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   prefer 2\n   apply(simp add: F_DPDA_OTS__states_def get_configuration_def epdaH_initial_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def)\n   apply(simp add: F_DPDA_OTS__states_def der1_def get_configuration_def epdaH_initial_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: epdaH.get_accessible_configurations_def)\n  apply(rule_tac\n      x=\"der1 c1\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule epdaH.derivation_initialI)\n    apply(rename_tac G1 G2 c1)(*strict*)\n    apply(rule epdaH.der1_is_derivation)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: der1_def get_configuration_def epdaH_initial_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule_tac\n      x=\"0\"\n      in exI)\n  apply(simp add: F_DPDA_OTS__states_def get_configuration_def epdaH_initial_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def)\n  apply(simp add: F_DPDA_OTS__states_def der1_def get_configuration_def epdaH_initial_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def)\n  done\n\nlemma F_DPDA_OTS__epdaH_epdaH__RL__inst__relation_step_simulationRL: \"\n  (\\<forall>G1 G2. F_DPDA_OTS__epdaH_epdaH__RL__TSstructure G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_DPDA_OTS__epdaH_epdaH__RL__configurations G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaH_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<exists>d2. epdaH.derivation G2 d2 \\<and> epdaH.belongs G2 d2 \\<and> the (get_configuration (d2 0)) = c2 \\<and> F_DPDA_OTS__epdaH_epdaH__LR__step_simulationRL G1 G2 c1 e1 c1' c2 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_DPDA_OTS__epdaH_epdaH__RL__configurations G1 G2 c1' (the (get_configuration (d2 n)))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__RL__configurations_def Let_def F_DPDA_OTS__epdaH_epdaH__LR__step_simulationRL_def F_DPDA_OTS__epdaH_epdaH__LR__initial_simulationRL_def F_DPDA_OTS__epdaH_epdaH__RL__initial_configuration_def F_DPDA_OTS__epdaH_epdaH__RL__TSstructure_def epda_step_labels_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1 c1')(*strict*)\n  apply(subgoal_tac \"valid_epda (F_DPDA_OTS G2)\")\n   apply(rename_tac G2 c1 e1 c1')(*strict*)\n   prefer 2\n   apply (metis F_DPDA_OTS__epdaH_epdaH__LR__inst__AX_TSstructure_relation_TSstructure2_belongs F_DPDA_OTS__epdaH_epdaH__LR__TSstructure_def)\n  apply(rename_tac G2 c1 e1 c1')(*strict*)\n  apply(case_tac \"epdaH_conf_state c1\")\n   apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n   apply(clarsimp)\n   apply(rule context_conjI)\n    apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n    apply(rule epdaH.der2_is_derivation)\n    apply(simp (no_asm) only: epdaH_step_relation_def F_DPDA_OTS__edges_auxiliary_main_1_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def)\n    apply(rule conjI)\n     apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n     apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def F_DPDA_OTS__epdaH_epdaH__RL__edge_def epdaH_step_relation_def)\n     apply(clarsimp)\n     apply(rename_tac G2 c1 e1 c1' a b w)(*strict*)\n     apply(erule disjE)\n      apply(rename_tac G2 c1 e1 c1' a b w)(*strict*)\n      apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def)\n      apply(clarsimp)\n     apply(rename_tac G2 c1 e1 c1' a b w)(*strict*)\n     apply(simp add: F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n     apply(clarsimp)\n     apply(rename_tac G2 c1 c1' a b w x)(*strict*)\n     apply(simp add: F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n     apply(simp add: F_DPDA_OTS__get_state_def)\n     apply(case_tac x)\n     apply(rename_tac G2 c1 c1' a b w x edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n     apply(force)\n    apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n     apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def F_DPDA_OTS__epdaH_epdaH__RL__edge_def epdaH_step_relation_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def)\n    apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n    apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def F_DPDA_OTS__epdaH_epdaH__RL__edge_def epdaH_step_relation_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def)\n   apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n    apply(rule epdaH.der2_belongs_prime)\n      apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def)\n     apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n     apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def)\n     apply(simp add: F_DPDA_OTS__get_state_def)\n     apply(subgoal_tac \"X\" for X)\n      apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n      prefer 2\n      apply(rule_tac\n      G=\"F_DPDA_OTS G2\"\n      and c=\"c1\"\n      in epdaH_epda_stack_is_must_terminated_by)\n       apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n       apply (metis)\n      apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n      apply(force)\n     apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n     apply(subgoal_tac \"c1 \\<in> epdaH_configurations (F_DPDA_OTS G2)\")\n      apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n      prefer 2\n      apply(simp add: epdaH.get_accessible_configurations_def)\n      apply(clarsimp)\n      apply(rename_tac G2 c1 e1 c1' a b d i)(*strict*)\n      apply(case_tac \"d i\")\n       apply(rename_tac G2 c1 e1 c1' a b d i)(*strict*)\n       apply(clarsimp)\n       apply(simp add: get_configuration_def)\n      apply(rename_tac G2 c1 e1 c1' a b d i aa)(*strict*)\n      apply(clarsimp)\n      apply(simp add: get_configuration_def)\n      apply(case_tac aa)\n      apply(rename_tac G2 c1 e1 c1' a b d i aa option ba)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac G2 c1 e1 c1' a b d i option)(*strict*)\n      apply(rule epdaH.belongs_configurations)\n       apply(rename_tac G2 c1 e1 c1' a b d i option)(*strict*)\n       apply(rule epdaH.derivation_initial_belongs)\n        apply(rename_tac G2 c1 e1 c1' a b d i option)(*strict*)\n        apply (metis)\n       apply(rename_tac G2 c1 e1 c1' a b d i option)(*strict*)\n       apply(force)\n      apply(rename_tac G2 c1 e1 c1' a b d i option)(*strict*)\n      apply(force)\n     apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n     apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def F_DPDA_OTS__states_def F_DPDA_OTS__states_auxiliary_def F_DPDA_OTS__states_main_def)\n     apply(clarsimp)\n     apply(rename_tac G2 e1 c1' a b s h)(*strict*)\n     apply(erule disjE)\n      apply(rename_tac G2 e1 c1' a b s h)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac G2 e1 c1' a b s h)(*strict*)\n     apply(force)\n    apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n    apply(force)\n   apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n    apply(simp add: der2_def get_configuration_def)\n   apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n   apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n    apply(rule_tac der2_maximum_of_domain)\n   apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n    apply (metis  epdaH.der2_is_derivation epdaH.der2_preserves_get_accessible_configurations)\n   apply(rename_tac G2 c1 e1 c1' a b)(*strict*)\n   apply(simp add: der2_def get_configuration_def)\n  apply(rename_tac G2 c1 e1 c1' a)(*strict*)\n  apply(clarsimp)\n  apply(rule context_conjI)\n   apply(rename_tac G2 c1 e1 c1' a)(*strict*)\n   apply(rule epdaH.der1_is_derivation)\n  apply(rename_tac G2 c1 e1 c1' a)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 e1 c1' a)(*strict*)\n   apply(rule epdaH.der1_belongs)\n   apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def)\n   apply(simp add: F_DPDA_OTS__get_state_def)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac G2 c1 e1 c1' a)(*strict*)\n    prefer 2\n    apply(rule_tac\n      G=\"F_DPDA_OTS G2\"\n      and c=\"c1\"\n      in epdaH_epda_stack_is_must_terminated_by)\n     apply(rename_tac G2 c1 e1 c1' a)(*strict*)\n     apply (metis)\n    apply(rename_tac G2 c1 e1 c1' a)(*strict*)\n    apply(force)\n   apply(rename_tac G2 c1 e1 c1' a)(*strict*)\n   apply(subgoal_tac \"c1 \\<in> epdaH_configurations (F_DPDA_OTS G2)\")\n    apply(rename_tac G2 c1 e1 c1' a)(*strict*)\n    prefer 2\n    apply(simp add: epdaH.get_accessible_configurations_def)\n    apply(clarsimp)\n    apply(rename_tac G2 c1 e1 c1' a d i)(*strict*)\n    apply(case_tac \"d i\")\n     apply(rename_tac G2 c1 e1 c1' a d i)(*strict*)\n     apply(clarsimp)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac G2 c1 e1 c1' a d i aa)(*strict*)\n    apply(clarsimp)\n    apply(simp add: get_configuration_def)\n    apply(case_tac aa)\n    apply(rename_tac G2 c1 e1 c1' a d i aa option b)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G2 c1 e1 c1' a d i option)(*strict*)\n    apply(rule epdaH.belongs_configurations)\n     apply(rename_tac G2 c1 e1 c1' a d i option)(*strict*)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(rename_tac G2 c1 e1 c1' a d i option)(*strict*)\n      apply (metis)\n     apply(rename_tac G2 c1 e1 c1' a d i option)(*strict*)\n     apply(force)\n    apply(rename_tac G2 c1 e1 c1' a d i option)(*strict*)\n    apply(force)\n   apply(rename_tac G2 c1 e1 c1' a)(*strict*)\n   apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def F_DPDA_OTS__states_def F_DPDA_OTS__states_auxiliary_def F_DPDA_OTS__states_main_def)\n   apply(clarsimp)\n   apply(rename_tac G2 e1 c1' a s h)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac G2 e1 c1' a s h)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G2 e1 c1' a s h)(*strict*)\n   apply(force)\n  apply(rename_tac G2 c1 e1 c1' a)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 e1 c1' a)(*strict*)\n   apply(simp add: der1_def get_configuration_def)\n  apply(rename_tac G2 c1 e1 c1' a)(*strict*)\n  apply(rule_tac\n      x=\"0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 e1 c1' a)(*strict*)\n   apply(rule_tac der1_maximum_of_domain)\n  apply(rename_tac G2 c1 e1 c1' a)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G2 c1 e1 c1' a)(*strict*)\n   apply (metis  epdaH.der2_is_derivation epdaH.der2_preserves_get_accessible_configurations)\n  apply(rename_tac G2 c1 e1 c1' a)(*strict*)\n  apply(simp add: der1_def get_configuration_def)\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def epdaH_step_relation_def F_DPDA_OTS_def F_DPDA_OTS__edges_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 e1 c1' a w)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac G2 c1 e1 c1' a w)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 c1' w aa b)(*strict*)\n   apply(simp add: F_DPDA_OTS__get_state_def option_to_list_def)\n  apply(rename_tac G2 c1 e1 c1' a w)(*strict*)\n  apply(simp add: F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  apply(clarsimp)\n  apply(rename_tac G2 c1 c1' a w x)(*strict*)\n  apply(simp add: F_DPDA_OTS__get_state_def option_to_list_def)\n  apply(simp add: F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  done\n\nlemma F_DPDA_OTS__epdaH_epdaH__RL__inst__ATS_Simulation_Configuration_WeakRL_axioms: \"\n  ATS_Simulation_Configuration_Weak_axioms valid_epda epdaH_initial_configurations epda_step_labels epdaH_step_relation valid_epda epdaH_configurations epdaH_initial_configurations epda_step_labels epdaH_step_relation F_DPDA_OTS__epdaH_epdaH__RL__configurations F_DPDA_OTS__epdaH_epdaH__RL__initial_configuration F_DPDA_OTS__epdaH_epdaH__RL__TSstructure F_DPDA_OTS__epdaH_epdaH__LR__initial_simulationRL F_DPDA_OTS__epdaH_epdaH__LR__step_simulationRL\"\n  apply(simp add: ATS_Simulation_Configuration_Weak_axioms_def F_DPDA_OTS__epdaH_epdaH__RL__inst__relation_initial_simulationRL F_DPDA_OTS__epdaH_epdaH__RL__inst__relation_step_simulationRL F_DPDA_OTS__epdaH_epdaH__RL__inst__AX_TSstructure_relation_TSstructure1_belongs F_DPDA_OTS__epdaH_epdaH__RL__inst__AX_TSstructure_relation_TSstructure2_belongs)\n  done\n\ninterpretation \"F_DPDA_OTS__epdaH_epdaH__RL\" : ATS_Simulation_Configuration_Weak\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaH_configurations\"\n  (* initial_configurations1 *)\n  \"epdaH_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaH_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaH_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaH_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaH_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaH_configurations\"\n  (* initial_configurations2 *)\n  \"epdaH_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaH_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaH_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaH_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaH_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_DPDA_OTS__epdaH_epdaH__RL__configurations\"\n  (* relation_initial_configuration *)\n  \"F_DPDA_OTS__epdaH_epdaH__RL__initial_configuration\"\n  (* relation_effect *)\n  \"F_DPDA_OTS__epdaH_epdaH__RL__effect\"\n  (* relation_TSstructure *)\n  \"F_DPDA_OTS__epdaH_epdaH__RL__TSstructure\"\n  (* relation_initial_simulationRL *)\n  \"F_DPDA_OTS__epdaH_epdaH__LR__initial_simulationRL\"\n  (* relation_step_simulationRL *)\n  \"F_DPDA_OTS__epdaH_epdaH__LR__step_simulationRL\"\n  apply(simp add: LOCALE_DEFS epda_interpretations)\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__RL__inst__ATS_Simulation_Configuration_WeakRL_axioms)\n  done\n\nlemma F_DPDA_OTS__preserves__determinism: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> valid_pda R\n  \\<Longrightarrow> epdaS.is_forward_edge_deterministic_accessible R\"\n  apply(subgoal_tac \"epdaH.is_forward_edge_deterministicHist_DB_long M\")\n   prefer 2\n   apply(rule DPDA_to_epdaH_determinism)\n   apply(force)\n  apply(subgoal_tac \"epdaH.is_forward_edge_deterministicHist_DB_long R\")\n   apply (metis epda_epdaS_is_forward_edge_deterministic_accessible_equal_to_epdaH_is_forward_edge_deterministicHist_DB_long valid_pda_to_valid_epda)\n  apply(clarsimp)\n  apply(simp add: epdaH.is_forward_edge_deterministicHist_DB_long_def)\n  apply(clarsimp)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n  apply(case_tac \"d n\")\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2 a)(*strict*)\n  apply(clarsimp)\n  apply(simp add: get_configuration_def)\n  apply(case_tac a)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2 a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2 option)(*strict*)\n  apply(rename_tac e)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e)(*strict*)\n  apply(erule_tac\n      x=\"F_DPDA_OTS__epdaH_epdaH__LR__configuration1R c\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e)(*strict*)\n    prefer 2\n    apply(rule_tac\n      ?G2.0=\"M\"\n      and ?G1.0=\"F_DPDA_OTS M\"\n      and ?d1.0=\"d\"\n      and x=\"n\"\n      in F_DPDA_OTS__epdaH_epdaH__RL.ATS_Simulation_Configuration_Weak_simulation_derivation_exists)\n      apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e)(*strict*)\n      apply(simp add: F_DPDA_OTS__epdaH_epdaH__RL__TSstructure_def)\n     apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e)(*strict*)\n     apply(force)\n    apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e)(*strict*)\n    apply(force)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e d2 n2)(*strict*)\n   apply(rule_tac\n      x=\"d2\"\n      in exI)\n   apply(clarsimp)\n   apply(rule_tac\n      x=\"n2\"\n      in exI)\n   apply(simp add: F_DPDA_OTS__epdaH_epdaH__RL__configurations_def F_DPDA_OTS__epdaH_epdaH__RL__TSstructure_def)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e d2 n2)(*strict*)\n    prefer 2\n    apply(rule_tac\n      m=\"n2\"\n      in epdaH.some_position_has_details_before_max_dom)\n      apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e d2 n2)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e d2 n2)(*strict*)\n     apply(rule epdaH.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e d2 n2)(*strict*)\n    apply(force)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e d2 n2)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e d2 n2 ea ca)(*strict*)\n   apply(simp add: get_configuration_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e)(*strict*)\n  apply(case_tac \"epdaH_conf_state c\")\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n   prefer 2\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a)(*strict*)\n   apply(thin_tac \"\\<forall>c1 c2 e1 e2. (\\<exists>w1. w1 \\<in> epda_effects M \\<and> (\\<exists>w2. w2 \\<in> epda_effects M \\<and> epdaH_step_relation M (F_DPDA_OTS__epdaH_epdaH__LR__configuration1R c) e1 c1 \\<and> epdaH_step_relation M (F_DPDA_OTS__epdaH_epdaH__LR__configuration1R c) e2 c2 \\<and> epdaH_conf_history c1 = epdaH_conf_history (F_DPDA_OTS__epdaH_epdaH__LR__configuration1R c) @ w1 \\<and> epdaH_conf_history c2 = epdaH_conf_history (F_DPDA_OTS__epdaH_epdaH__LR__configuration1R c) @ w2 \\<and> (ATS_History.history_fragment_prefixes epda_effects (@) M w1 \\<subseteq> ATS_History.history_fragment_prefixes epda_effects (@) M w2 \\<or> ATS_History.history_fragment_prefixes epda_effects (@) M w2 \\<subseteq> ATS_History.history_fragment_prefixes epda_effects (@) M w1 \\<or> ATS_History.history_fragment_prefixes epda_effects (@) M w2 = ATS_History.history_fragment_prefixes epda_effects (@) M w1))) \\<longrightarrow> e1 = e2\")\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a)(*strict*)\n   apply(thin_tac \"ATS_History.history_fragment_prefixes epda_effects (@) (F_DPDA_OTS M) w1 \\<subseteq> ATS_History.history_fragment_prefixes epda_effects (@) (F_DPDA_OTS M) w2 \\<or> ATS_History.history_fragment_prefixes epda_effects (@) (F_DPDA_OTS M) w2 \\<subseteq> ATS_History.history_fragment_prefixes epda_effects (@) (F_DPDA_OTS M) w1 \\<or> ATS_History.history_fragment_prefixes epda_effects (@) (F_DPDA_OTS M) w2 = ATS_History.history_fragment_prefixes epda_effects (@) (F_DPDA_OTS M) w1\")\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a)(*strict*)\n   apply(simp add: epdaH_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac c d c1 c2 e1 e2 n e a w wa)(*strict*)\n   apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def)\n   apply(erule_tac\n      P=\"e1 \\<in> F_DPDA_OTS__edges_main_auxiliary M\"\n      in disjE)\n    apply(rename_tac c d c1 c2 e1 e2 n e a w wa)(*strict*)\n    prefer 2\n    apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n    apply(clarsimp)\n    apply(rename_tac c d c1 c2 e2 n e a w wa x)(*strict*)\n    apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n    apply(case_tac e2)\n    apply(rename_tac c d c1 c2 e2 n e a w wa x edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c d c1 c2 n e a w wa x edge_eventa edge_popa edge_pusha)(*strict*)\n    apply(case_tac c)\n    apply(rename_tac c d c1 c2 n e a w wa x edge_eventa edge_popa edge_pusha epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac c d c1 c2 e1 e2 n e a w wa)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac c d c1 c2 e1 e2 n e a w wa)(*strict*)\n    prefer 2\n    apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n    apply(clarsimp)\n    apply(rename_tac c d c1 c2 n e a w wa aa b x)(*strict*)\n    apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n   apply(rename_tac c d c1 c2 e1 e2 n e a w wa)(*strict*)\n   apply(case_tac e2)\n   apply(rename_tac c d c1 c2 e1 e2 n e a w wa edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d c1 c2 e1 n e a w wa edge_eventa edge_popa edge_pusha)(*strict*)\n   apply(case_tac c)\n   apply(rename_tac c d c1 c2 e1 n e a w wa edge_eventa edge_popa edge_pusha epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d c1 c2 e1 n e a w wa edge_eventa edge_popa edge_pusha epdaH_conf_historya)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n   apply(clarsimp)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n  apply(erule_tac\n      x=\"F_DPDA_OTS__epdaH_epdaH__LR__configuration1R c1\"\n      in allE)\n  apply(erule_tac\n      x=\"F_DPDA_OTS__epdaH_epdaH__LR__configuration1R c2\"\n      in allE)\n  apply(erule_tac\n      x=\"F_DPDA_OTS__epdaH_epdaH__RL__edge e1\"\n      in allE)\n  apply(erule_tac\n      x=\"F_DPDA_OTS__epdaH_epdaH__RL__edge e2\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n   prefer 2\n   apply(simp add: F_DPDA_OTS__epdaH_epdaH__RL__edge_def)\n   apply(clarsimp)\n   apply(case_tac e1)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n   apply(case_tac e2)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b edge_srca edge_eventa edge_popa edge_pusha edge_trga edge_srcaa edge_eventaa edge_popaa edge_pushaa edge_trgaa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d c1 c2 n w1 w2 e a b edge_src edge_trg edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n   apply(simp add: epdaH_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac c d c1 c2 n e a b edge_eventa edge_popa edge_pusha w)(*strict*)\n   apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def)\n   apply(erule_tac\n      P=\"\\<lparr>edge_src = epdaH_conf_state c, edge_event = edge_eventa, edge_pop = edge_popa, edge_push = edge_pusha, edge_trg = epdaH_conf_state c1\\<rparr> \\<in> F_DPDA_OTS__edges_main_auxiliary M\"\n      in disjE)\n    apply(rename_tac c d c1 c2 n e a b edge_eventa edge_popa edge_pusha w)(*strict*)\n    apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n    apply(clarsimp)\n   apply(rename_tac c d c1 c2 n e a b edge_eventa edge_popa edge_pusha w)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac c d c1 c2 n e a b edge_eventa edge_popa edge_pusha w)(*strict*)\n    apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n    apply(clarsimp)\n   apply(rename_tac c d c1 c2 n e a b edge_eventa edge_popa edge_pusha w)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n   apply(clarsimp)\n   apply(rename_tac c d c1 c2 n e a b edge_eventa edge_popa edge_pusha w x xa)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n   apply(clarsimp)\n   apply(rename_tac c d c1 c2 n e w x xa)(*strict*)\n   apply(case_tac c1)\n   apply(rename_tac c d c1 c2 n e w x xa epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n   apply(case_tac c2)\n   apply(rename_tac c d c1 c2 n e w x xa epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka epdaH_conf_stateaa epdaH_conf_historyaa epdaH_conf_stackaa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d n e w x xa)(*strict*)\n   apply(case_tac x)\n   apply(rename_tac c d n e w x xa edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n   apply(case_tac xa)\n   apply(rename_tac c d n e w x xa edge_srca edge_eventa edge_popa edge_pusha edge_trga edge_srcaa edge_eventaa edge_popaa edge_pushaa edge_trgaa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d n e w edge_trg edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n   apply(case_tac c)\n   apply(rename_tac c d n e w edge_trg edge_srca edge_eventa edge_popa edge_pusha edge_trga epdaH_conf_statea epdaH_conf_history epdaH_conf_stacka)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d n e w edge_trg edge_srca edge_eventa edge_popa edge_pusha edge_trga epdaH_conf_history)(*strict*)\n   apply(simp add: F_DPDA_OTS__get_state_def)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n  apply(rule_tac\n      x=\"w1\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n   apply(simp add: F_DPDA_OTS_def epda_effects_def)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n  apply(rule_tac\n      x=\"w2\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n   apply(simp add: F_DPDA_OTS_def epda_effects_def)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n   apply(thin_tac \"ATS_History.history_fragment_prefixes epda_effects (@) (F_DPDA_OTS M) w1 \\<subseteq> ATS_History.history_fragment_prefixes epda_effects (@) (F_DPDA_OTS M) w2 \\<or> ATS_History.history_fragment_prefixes epda_effects (@) (F_DPDA_OTS M) w2 \\<subseteq> ATS_History.history_fragment_prefixes epda_effects (@) (F_DPDA_OTS M) w1 \\<or> ATS_History.history_fragment_prefixes epda_effects (@) (F_DPDA_OTS M) w2 = ATS_History.history_fragment_prefixes epda_effects (@) (F_DPDA_OTS M) w1\")\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n   apply(simp add: epdaH_step_relation_def F_DPDA_OTS__epdaH_epdaH__RL__edge_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def)\n   apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def)\n   apply(clarsimp)\n   apply(rename_tac c d c1 c2 e1 e2 n e a b w wa)(*strict*)\n   apply(erule_tac\n      P=\"e1 \\<in> F_DPDA_OTS__edges_main_auxiliary M\"\n      in disjE)\n    apply(rename_tac c d c1 c2 e1 e2 n e a b w wa)(*strict*)\n    apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n    apply(clarsimp)\n    apply(rename_tac c d c1 c2 e2 n e a b w wa aa ba)(*strict*)\n    apply(case_tac e2)\n    apply(rename_tac c d c1 c2 e2 n e a b w wa aa ba edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c d c1 c2 n e a b w wa aa ba edge_event edge_pop edge_push)(*strict*)\n    apply(simp add: F_DPDA_OTS__get_state_def)\n    apply(case_tac c1)\n    apply(rename_tac c d c1 c2 n e a b w wa aa ba edge_event edge_pop edge_push epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c d c2 n e a b w wa aa ba edge_event edge_pop edge_push)(*strict*)\n    apply(case_tac c2)\n    apply(rename_tac c d c2 n e a b w wa aa ba edge_event edge_pop edge_push epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c d n e a b w wa aa ba edge_event edge_pop edge_push epdaH_conf_statea)(*strict*)\n    apply(case_tac c)\n    apply(rename_tac c d n e a b w wa aa ba edge_event edge_pop edge_push epdaH_conf_statea epdaH_conf_stateaa epdaH_conf_history epdaH_conf_stacka)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac c d c1 c2 e1 e2 n e a b w wa)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n   apply(clarsimp)\n   apply(rename_tac c d c1 c2 e2 n e a b w wa x)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n   apply(case_tac e2)\n   apply(rename_tac c d c1 c2 e2 n e a b w wa x edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d c1 c2 n e a b w wa x edge_eventa edge_popa edge_pusha)(*strict*)\n   apply(simp add: F_DPDA_OTS__get_state_def)\n   apply(case_tac c1)\n   apply(rename_tac c d c1 c2 n e a b w wa x edge_eventa edge_popa edge_pusha epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d c2 n e a b w wa x edge_eventa edge_popa edge_pusha)(*strict*)\n   apply(case_tac c2)\n   apply(rename_tac c d c2 n e a b w wa x edge_eventa edge_popa edge_pusha epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d n e a b w wa x edge_eventa edge_popa edge_pusha epdaH_conf_statea)(*strict*)\n   apply(case_tac c)\n   apply(rename_tac c d n e a b w wa x edge_eventa edge_popa edge_pusha epdaH_conf_statea epdaH_conf_stateaa epdaH_conf_history epdaH_conf_stacka)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d n e w wa x edge_eventa edge_popa edge_pusha epdaH_conf_state epdaH_conf_history)(*strict*)\n   apply(case_tac x)\n   apply(rename_tac d n e w wa x edge_eventa edge_popa edge_pusha epdaH_conf_state epdaH_conf_history edge_srca edge_eventaa edge_popaa edge_pushaa edge_trga)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n   apply(thin_tac \"ATS_History.history_fragment_prefixes epda_effects (@) (F_DPDA_OTS M) w1 \\<subseteq> ATS_History.history_fragment_prefixes epda_effects (@) (F_DPDA_OTS M) w2 \\<or> ATS_History.history_fragment_prefixes epda_effects (@) (F_DPDA_OTS M) w2 \\<subseteq> ATS_History.history_fragment_prefixes epda_effects (@) (F_DPDA_OTS M) w1 \\<or> ATS_History.history_fragment_prefixes epda_effects (@) (F_DPDA_OTS M) w2 = ATS_History.history_fragment_prefixes epda_effects (@) (F_DPDA_OTS M) w1\")\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n   apply(simp add: epdaH_step_relation_def F_DPDA_OTS__epdaH_epdaH__RL__edge_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def)\n   apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def)\n   apply(clarsimp)\n   apply(rename_tac c d c1 c2 e1 e2 n e a b w wa)(*strict*)\n   apply(erule_tac\n      P=\"e2 \\<in> F_DPDA_OTS__edges_main_auxiliary M\"\n      in disjE)\n    apply(rename_tac c d c1 c2 e1 e2 n e a b w wa)(*strict*)\n    apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n    apply(clarsimp)\n   apply(rename_tac c d c1 c2 e1 e2 n e a b w wa)(*strict*)\n   apply(case_tac e2)\n   apply(rename_tac c d c1 c2 e1 e2 n e a b w wa edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d c1 c2 e1 n e a b w wa edge_eventa edge_popa edge_pusha)(*strict*)\n   apply(simp add: F_DPDA_OTS__get_state_def)\n   apply(case_tac c1)\n   apply(rename_tac c d c1 c2 e1 n e a b w wa edge_eventa edge_popa edge_pusha epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d c2 e1 n e a b w wa edge_event edge_popa edge_push)(*strict*)\n   apply(case_tac c2)\n   apply(rename_tac c d c2 e1 n e a b w wa edge_event edge_popa edge_push epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d e1 n e a b w wa edge_event edge_popa edge_push epdaH_conf_statea)(*strict*)\n   apply(case_tac c)\n   apply(rename_tac c d e1 n e a b w wa edge_event edge_popa edge_push epdaH_conf_statea epdaH_conf_stateaa epdaH_conf_history epdaH_conf_stacka)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d e1 n e a b w wa edge_event edge_popa edge_push epdaH_conf_state epdaH_conf_history)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n   apply(clarsimp)\n   apply(rename_tac d e1 n e a b w wa edge_event edge_popa edge_push epdaH_conf_state epdaH_conf_history x)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n   apply(rename_tac d e1 n e a b w wa edge_eventa edge_popa edge_pusha epdaH_conf_state epdaH_conf_history x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d e1 n e w wa epdaH_conf_history x)(*strict*)\n   apply(case_tac x)\n   apply(rename_tac d e1 n e w wa epdaH_conf_history x edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def)\n  apply(subgoal_tac \"epda_effects M = epda_effects (F_DPDA_OTS M)\")\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n   prefer 2\n   apply(rule antisym)\n    apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b x)(*strict*)\n    apply(simp add: epda_effects_def F_DPDA_OTS_def)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n   apply(simp add: epda_effects_def F_DPDA_OTS_def)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n  apply(rule_tac\n      t=\"ATS_History.history_fragment_prefixes epda_effects (@) M w1\"\n      and s=\"ATS_History.history_fragment_prefixes epda_effects (@) (F_DPDA_OTS M) w1\"\n      in ssubst)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n   apply(simp (no_asm) add: epdaH.history_fragment_prefixes_def)\n   apply(rule antisym)\n    apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n  apply(rule_tac\n      t=\"ATS_History.history_fragment_prefixes epda_effects (@) M w2\"\n      and s=\"ATS_History.history_fragment_prefixes epda_effects (@) (F_DPDA_OTS M) w2\"\n      in ssubst)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n   apply(simp (no_asm) add: epdaH.history_fragment_prefixes_def)\n   apply(rule antisym)\n    apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac c d c1 c2 e1 e2 n w1 w2 e a b)(*strict*)\n  apply(force)\n  done\n\ntheorem F_DPDA_OTS__preserves__DPDA: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> valid_dpda R\"\n  apply(simp (no_asm) add: valid_dpda_def)\n  apply(rule context_conjI)\n   apply(rule F_DPDA_OTS__preserves__PDA)\n    apply(simp add: valid_dpda_def)\n    apply(force)\n   apply(force)\n  apply(rule F_DPDA_OTS__preserves__determinism)\n    apply(force)\n   apply(force)\n  apply(force)\n  done\n\nlemma F_DPDA_OTS__reflects__unmarked_language: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> epdaH.unmarked_language R \\<subseteq> epdaH.unmarked_language M\"\n  apply(rule subsetI)\n  apply(rename_tac x)(*strict*)\n  apply(clarsimp)\n  apply(simp add: epdaH.unmarked_language_def)\n  apply(clarsimp)\n  apply(rename_tac x d)(*strict*)\n  apply(thin_tac \"epdaH.derivation (F_DPDA_OTS M) d\")\n  apply(simp add: epdaH_unmarked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac d i e c)(*strict*)\n  apply(case_tac c)\n  apply(rename_tac d i e c epdaH_conf_state epdaH_conf_historya epdaH_conf_stack)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e epdaH_conf_state epdaH_conf_historya epdaH_conf_stack)(*strict*)\n  apply(rename_tac q h s)\n  apply(rename_tac d i e q h s)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d i e q h s)(*strict*)\n   prefer 2\n   apply(rule_tac\n      ?G2.0=\"M\"\n      and ?G1.0=\"F_DPDA_OTS M\"\n      and ?d1.0=\"d\"\n      and x=\"i\"\n      in F_DPDA_OTS__epdaH_epdaH__RL.ATS_Simulation_Configuration_Weak_simulation_derivation_exists)\n     apply(rename_tac d i e q h s)(*strict*)\n     apply(simp add: F_DPDA_OTS__epdaH_epdaH__RL__TSstructure_def)\n    apply(rename_tac d i e q h s)(*strict*)\n    apply(force)\n   apply(rename_tac d i e q h s)(*strict*)\n   apply(force)\n  apply(rename_tac d i e q h s)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e q h s d2 n2)(*strict*)\n  apply(rule_tac\n      x=\"d2\"\n      in exI)\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d i e q h s d2 n2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"n2\"\n      in epdaH.some_position_has_details_before_max_dom)\n     apply(rename_tac d i e q h s d2 n2)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac d i e q h s d2 n2)(*strict*)\n    apply(rule epdaH.derivation_initial_is_derivation)\n    apply(force)\n   apply(rename_tac d i e q h s d2 n2)(*strict*)\n   apply(force)\n  apply(rename_tac d i e q h s d2 n2)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac d i e q h s d2 n2)(*strict*)\n   apply(rule_tac\n      x=\"n2\"\n      in exI)\n   apply(clarsimp)\n   apply(rename_tac d i e q h s d2 n2 ea c)(*strict*)\n   apply(simp add: F_DPDA_OTS__epdaH_epdaH__RL__configurations_def)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def)\n  apply(rename_tac d i e q h s d2 n2)(*strict*)\n  apply(simp add: epdaH.derivation_initial_def)\n  done\n\nlemma F_DPDA_OTS__preserves__unmarked_language: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> epdaH.unmarked_language M \\<subseteq> epdaH.unmarked_language R\"\n  apply(rule subsetI)\n  apply(rename_tac x)(*strict*)\n  apply(clarsimp)\n  apply(simp add: epdaH.unmarked_language_def)\n  apply(clarsimp)\n  apply(rename_tac x d)(*strict*)\n  apply(thin_tac \"epdaH.derivation M d\")\n  apply(simp add: epdaH_unmarked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac d i e c)(*strict*)\n  apply(case_tac c)\n  apply(rename_tac d i e c epdaH_conf_state epdaH_conf_historya epdaH_conf_stack)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e epdaH_conf_state epdaH_conf_historya epdaH_conf_stack)(*strict*)\n  apply(rename_tac q h s)\n  apply(rename_tac d i e q h s)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d i e q h s)(*strict*)\n   prefer 2\n   apply(rule_tac\n      ?G1.0=\"M\"\n      and ?G2.0=\"F_DPDA_OTS M\"\n      and ?d1.0=\"d\"\n      and x=\"i\"\n      in F_DPDA_OTS__epdaH_epdaH__LR.ATS_Simulation_Configuration_Weak_simulation_derivation_exists)\n     apply(rename_tac d i e q h s)(*strict*)\n     apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__TSstructure_def)\n    apply(rename_tac d i e q h s)(*strict*)\n    apply(force)\n   apply(rename_tac d i e q h s)(*strict*)\n   apply(force)\n  apply(rename_tac d i e q h s)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e q h s d2 n2)(*strict*)\n  apply(rule_tac\n      x=\"d2\"\n      in exI)\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d i e q h s d2 n2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"n2\"\n      in epdaH.some_position_has_details_before_max_dom)\n     apply(rename_tac d i e q h s d2 n2)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac d i e q h s d2 n2)(*strict*)\n    apply(rule epdaH.derivation_initial_is_derivation)\n    apply(force)\n   apply(rename_tac d i e q h s d2 n2)(*strict*)\n   apply(force)\n  apply(rename_tac d i e q h s d2 n2)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac d i e q h s d2 n2)(*strict*)\n   apply(rule_tac\n      x=\"n2\"\n      in exI)\n   apply(clarsimp)\n   apply(rename_tac d i e q h s d2 n2 ea c)(*strict*)\n   apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__configurations_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def get_configuration_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def)\n  apply(rename_tac d i e q h s d2 n2)(*strict*)\n  apply(simp add: epdaH.derivation_initial_def)\n  done\n\ntheorem F_DPDA_OTS__equal__unmarked_language: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> epdaH.unmarked_language R = epdaH.unmarked_language M\"\n  apply(rule order_antisym)\n   apply(rule F_DPDA_OTS__reflects__unmarked_language)\n    apply(force)\n   apply(force)\n  apply(rule F_DPDA_OTS__preserves__unmarked_language)\n   apply(force)\n  apply(force)\n  done\n\nlemma F_DPDA_OTS__reflects__marked_language: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> epdaH.marked_language R \\<subseteq> epdaH.marked_language M\"\n  apply(rule subsetI)\n  apply(rename_tac x)(*strict*)\n  apply(clarsimp)\n  apply(simp add: epdaH.marked_language_def)\n  apply(clarsimp)\n  apply(rename_tac x d)(*strict*)\n  apply(thin_tac \"epdaH.derivation (F_DPDA_OTS M) d\")\n  apply(subgoal_tac \"(\\<exists>d. epdaH.derivation_initial M d \\<and> x \\<in> epdaH_marked_effect M d)\")\n   apply(rename_tac x d)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x d da)(*strict*)\n   apply(rule_tac\n      x=\"da\"\n      in exI)\n   apply(clarsimp)\n   apply(simp add: epdaH.derivation_initial_def)\n   apply(simp add: epdaH_marking_condition_def epdaH_marked_effect_def)\n   apply(clarsimp)\n   apply(rename_tac d da i ia ib e ea eb c ca cb)(*strict*)\n   apply(rule_tac\n      x=\"ib\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac x d)(*strict*)\n  apply(thin_tac \"epdaH_marking_condition (F_DPDA_OTS M) d\")\n  apply(simp add: epdaH_marked_effect_def epdaH_marking_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac d i e c)(*strict*)\n  apply(thin_tac \"\\<forall>j e' c'. i < j \\<and> d j = Some (pair e' c') \\<longrightarrow> epdaH_string_state c = epdaH_string_state c'\")\n  apply(rename_tac d i e c)(*strict*)\n  apply(thin_tac \"c \\<in> epdaH_configurations (F_DPDA_OTS M)\")\n  apply(case_tac c)\n  apply(rename_tac d i e c epdaH_conf_statea epdaH_conf_historya epdaH_conf_stack)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e epdaH_conf_statea epdaH_conf_historya epdaH_conf_stack)(*strict*)\n  apply(rename_tac q h s)\n  apply(rename_tac d i e q h s)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d i e q h s)(*strict*)\n   prefer 2\n   apply(rule_tac\n      ?G2.0=\"M\"\n      and ?G1.0=\"F_DPDA_OTS M\"\n      and ?d1.0=\"d\"\n      and x=\"i\"\n      in F_DPDA_OTS__epdaH_epdaH__RL.ATS_Simulation_Configuration_Weak_simulation_derivation_exists)\n     apply(rename_tac d i e q h s)(*strict*)\n     apply(simp add: F_DPDA_OTS__epdaH_epdaH__RL__TSstructure_def)\n    apply(rename_tac d i e q h s)(*strict*)\n    apply(force)\n   apply(rename_tac d i e q h s)(*strict*)\n   apply(force)\n  apply(rename_tac d i e q h s)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e q h s d2 n2)(*strict*)\n  apply(rule_tac\n      x=\"derivation_take d2 n2\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac d i e q h s d2 n2)(*strict*)\n   apply(rule epdaH.derivation_take_preserves_derivation_initial)\n   apply(force)\n  apply(rename_tac d i e q h s d2 n2)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d i e q h s d2 n2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"n2\"\n      in epdaH.some_position_has_details_before_max_dom)\n     apply(rename_tac d i e q h s d2 n2)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac d i e q h s d2 n2)(*strict*)\n    apply(rule epdaH.derivation_initial_is_derivation)\n    apply(force)\n   apply(rename_tac d i e q h s d2 n2)(*strict*)\n   apply(force)\n  apply(rename_tac d i e q h s d2 n2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e q h s d2 n2 ea c)(*strict*)\n  apply(rule_tac\n      x=\"n2\"\n      in exI)\n  apply(rule_tac\n      x=\"ea\"\n      in exI)\n  apply(rule_tac\n      x=\"c\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac d i e q h s d2 n2 ea c)(*strict*)\n   apply(simp add: derivation_take_def F_DPDA_OTS__epdaH_epdaH__RL__configurations_def)\n  apply(rename_tac d i e q h s d2 n2 ea c)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac d i e q h s d2 n2 ea c)(*strict*)\n   apply(simp add: derivation_take_def F_DPDA_OTS__epdaH_epdaH__RL__configurations_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_OTS__get_state_def get_configuration_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def F_DPDA_OTS_def F_DPDA_OTS__marking_states_def)\n   apply(clarsimp)\n  apply(rename_tac d i e q h s d2 n2 ea c)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac d i e q h s d2 n2 ea c)(*strict*)\n   apply(rule epdaH.belongs_configurations)\n    apply(rename_tac d i e q h s d2 n2 ea c)(*strict*)\n    apply(rule epdaH.derivation_initial_belongs)\n     apply(rename_tac d i e q h s d2 n2 ea c)(*strict*)\n     apply(simp add: valid_dpda_def valid_pda_def)\n    apply(rename_tac d i e q h s d2 n2 ea c)(*strict*)\n    apply(force)\n   apply(rename_tac d i e q h s d2 n2 ea c)(*strict*)\n   apply(force)\n  apply(rename_tac d i e q h s d2 n2 ea c)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac d i e q h s d2 n2 ea c)(*strict*)\n   apply(simp add: F_DPDA_OTS__epdaH_epdaH__RL__configurations_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_OTS__get_state_def get_configuration_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def F_DPDA_OTS_def F_DPDA_OTS__marking_states_def)\n  apply(rename_tac d i e q h s d2 n2 ea c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e q h s d2 n2 ea c j e' c')(*strict*)\n  apply(simp add: derivation_take_def F_DPDA_OTS__epdaH_epdaH__RL__configurations_def)\n  done\n\nlemma F_DPDA_OTS__preserves__marked_language: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> epdaH.marked_language M \\<subseteq> epdaH.marked_language R\"\n  apply(rule subsetI)\n  apply(rename_tac x)(*strict*)\n  apply(clarsimp)\n  apply(simp add: epdaH.marked_language_def)\n  apply(clarsimp)\n  apply(rename_tac x d)(*strict*)\n  apply(thin_tac \"epdaH.derivation M d\")\n  apply(thin_tac \"epdaH_marking_condition M d\")\n  apply(subgoal_tac \"\\<exists>d. epdaH.derivation_initial (F_DPDA_OTS M) d \\<and> x \\<in> epdaH_marked_effect (F_DPDA_OTS M) d\")\n   apply(rename_tac x d)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x d da)(*strict*)\n   apply(rule_tac\n      x=\"da\"\n      in exI)\n   apply(clarsimp)\n   apply(simp add: epdaH.derivation_initial_def)\n   apply(simp add: epdaH_marked_effect_def epdaH_marking_condition_def)\n   apply(clarsimp)\n   apply(rename_tac d da i ia e ea c ca)(*strict*)\n   apply(rule_tac\n      x=\"ia\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac x d)(*strict*)\n  apply(simp add: epdaH_marked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac d i e c)(*strict*)\n  apply(case_tac c)\n  apply(rename_tac d i e c epdaH_conf_state epdaH_conf_historya epdaH_conf_stack)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e epdaH_conf_state epdaH_conf_historya epdaH_conf_stack)(*strict*)\n  apply(rename_tac q s h)\n  apply(rename_tac d i e q s h)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d i e q s h)(*strict*)\n   prefer 2\n   apply(rule_tac\n      ?G1.0=\"M\"\n      and ?G2.0=\"F_DPDA_OTS M\"\n      and ?d1.0=\"d\"\n      and x=\"i\"\n      in F_DPDA_OTS__epdaH_epdaH__LR.ATS_Simulation_Configuration_Weak_simulation_derivation_exists)\n     apply(rename_tac d i e q s h)(*strict*)\n     apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__TSstructure_def)\n    apply(rename_tac d i e q s h)(*strict*)\n    apply(force)\n   apply(rename_tac d i e q s h)(*strict*)\n   apply(force)\n  apply(rename_tac d i e q s h)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e q s h d2 n2)(*strict*)\n  apply(rule_tac\n      x=\"derivation_take d2 n2\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac d i e q s h d2 n2)(*strict*)\n   apply(rule epdaH.derivation_take_preserves_derivation_initial)\n   apply(force)\n  apply(rename_tac d i e q s h d2 n2)(*strict*)\n  apply(rule_tac\n      x=\"n2\"\n      in exI)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d i e q s h d2 n2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"n2\"\n      in epdaH.some_position_has_details_before_max_dom)\n     apply(rename_tac d i e q s h d2 n2)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac d i e q s h d2 n2)(*strict*)\n    apply(rule epdaH.derivation_initial_is_derivation)\n    apply(force)\n   apply(rename_tac d i e q s h d2 n2)(*strict*)\n   apply(force)\n  apply(rename_tac d i e q s h d2 n2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i e q s h d2 n2 ea c)(*strict*)\n  apply(rule_tac\n      x=\"ea\"\n      in exI)\n  apply(rule_tac\n      x=\"c\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac d i e q s h d2 n2 ea c)(*strict*)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac d i e q s h d2 n2 ea c)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac d i e q s h d2 n2 ea c)(*strict*)\n   prefer 2\n   apply(rule conjI)\n    apply(rename_tac d i e q s h d2 n2 ea c)(*strict*)\n    apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__configurations_def F_DPDA_OTS__marking_states_def derivation_take_def epdaH_marking_configurations_def F_DPDA_OTS_def get_configuration_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def)\n   apply(rename_tac d i e q s h d2 n2 ea c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i e q s h d2 n2 ea c j e' c')(*strict*)\n   apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__configurations_def F_DPDA_OTS__marking_states_def derivation_take_def epdaH_marking_configurations_def F_DPDA_OTS_def get_configuration_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def)\n  apply(rename_tac d i e q s h d2 n2 ea c)(*strict*)\n  apply(simp add: epdaH_marking_configurations_def)\n  apply(rule conjI)\n   apply(rename_tac d i e q s h d2 n2 ea c)(*strict*)\n   prefer 2\n   apply(rule epdaH.belongs_configurations)\n    apply(rename_tac d i e q s h d2 n2 ea c)(*strict*)\n    apply(rule epdaH.derivation_initial_belongs)\n     apply(rename_tac d i e q s h d2 n2 ea c)(*strict*)\n     apply (metis F_DPDA_OTS__epdaH_epdaH__LR__inst__AX_TSstructure_relation_TSstructure2_belongs F_DPDA_OTS__epdaH_epdaH__LR__configurations_def)\n    apply(rename_tac d i e q s h d2 n2 ea c)(*strict*)\n    apply(force)\n   apply(rename_tac d i e q s h d2 n2 ea c)(*strict*)\n   apply(force)\n  apply(rename_tac d i e q s h d2 n2 ea c)(*strict*)\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__configurations_def F_DPDA_OTS__marking_states_def derivation_take_def epdaH_marking_configurations_def F_DPDA_OTS_def get_configuration_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def)\n  apply(clarsimp)\n  apply(rename_tac d i e q s h d2 n2 ea)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d i e q s h d2 n2 ea)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"M\"\n      in epdaH_epda_stack_is_must_terminated_by)\n    apply(rename_tac d i e q s h d2 n2 ea)(*strict*)\n    apply(simp add: valid_dpda_def valid_pda_def)\n   apply(rename_tac d i e q s h d2 n2 ea)(*strict*)\n   apply(force)\n  apply(rename_tac d i e q s h d2 n2 ea)(*strict*)\n  apply(clarsimp)\n  apply(simp add: must_terminated_by_def kleene_star_def append_language_def)\n  apply(clarsimp)\n  apply(rename_tac d i e q s d2 n2 ea a)(*strict*)\n  apply(rule inMap)\n  apply(clarsimp)\n  apply(case_tac a)\n   apply(rename_tac d i e q s d2 n2 ea a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d i e q s d2 n2 ea)(*strict*)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rename_tac d i e q s d2 n2 ea a aa list)(*strict*)\n  apply(clarsimp)\n  done\n\ntheorem F_DPDA_OTS__equal__marked_language: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> epdaH.marked_language R = epdaH.marked_language M\"\n  apply(rule order_antisym)\n   apply(rule F_DPDA_OTS__reflects__marked_language)\n    apply(force)\n   apply(force)\n  apply(rule F_DPDA_OTS__preserves__marked_language)\n   apply(force)\n  apply(force)\n  done\n\nlemma F_DPDA_OTS__topstack_equal_to_annotation: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> epdaH.derivation_initial R d\n  \\<Longrightarrow> d n = Some (pair e c)\n  \\<Longrightarrow> epdaH_conf_state c = cons_state_and_stack q X\n  \\<Longrightarrow> \\<exists>w. epdaH_conf_stack c = X # w\"\n  apply(case_tac n)\n   apply(clarsimp)\n   apply(simp add: epdaH.derivation_initial_def epdaH_initial_configurations_def)\n   apply(clarsimp)\n   apply(case_tac c)\n   apply(rename_tac epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_OTS_def)\n  apply(rename_tac nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n)\n  apply(rename_tac n)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac n)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"F_DPDA_OTS M\"\n      and d=\"d\"\n      and n=\"n\"\n      and m=\"Suc n\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac n)(*strict*)\n     apply(rule epdaH.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac n)(*strict*)\n    apply(force)\n   apply(rename_tac n)(*strict*)\n   apply(force)\n  apply(rename_tac n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n e1 e2 c1)(*strict*)\n  apply(simp add: epdaH_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac n e1 e2 c1 w)(*strict*)\n  apply(case_tac c1)\n  apply(rename_tac n e1 e2 c1 w epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n  apply(case_tac c)\n  apply(rename_tac n e1 e2 c1 w epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka epdaH_conf_stateaa epdaH_conf_historyaa epdaH_conf_stackaa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n e1 e2 w epdaH_conf_history)(*strict*)\n  apply(case_tac e2)\n  apply(rename_tac n e1 e2 w epdaH_conf_history edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n e1 w epdaH_conf_history edge_src edge_event edge_pop edge_push)(*strict*)\n  apply(rename_tac h src read pop push)\n  apply(rename_tac n e1 w h src read pop push)(*strict*)\n  apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def)\n  apply(erule disjE)\n   apply(rename_tac n e1 w h src read pop push)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_def valid_epda_step_label_def F_DPDA_OTS__marking_states_def F_DPDA_OTS__states_auxiliary_def F_DPDA_OTS__states_def F_DPDA_OTS__states_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n   apply(clarsimp)\n  apply(rename_tac n e1 w h src read pop push)(*strict*)\n  apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_def valid_epda_step_label_def F_DPDA_OTS__marking_states_def F_DPDA_OTS__states_auxiliary_def F_DPDA_OTS__states_def F_DPDA_OTS__states_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  apply(clarsimp)\n  apply(rename_tac n e1 w h src read pop push x)(*strict*)\n  apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_def valid_epda_step_label_def F_DPDA_OTS__marking_states_def F_DPDA_OTS__states_auxiliary_def F_DPDA_OTS__states_def F_DPDA_OTS__states_main_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  done\n\ndefinition corresponds_to_top_stack :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> ('state \\<Rightarrow> bool)\n  \\<Rightarrow> ('state \\<Rightarrow> 'stack option)\n  \\<Rightarrow> bool\"\n  where\n    \"corresponds_to_top_stack M valid f \\<equiv>\n  \\<forall>d n c X.\n    epdaH.derivation_initial M d\n    \\<longrightarrow> get_configuration (d n) = Some c\n    \\<longrightarrow> valid (epdaH_conf_state c)\n    \\<longrightarrow> f (epdaH_conf_state c) = Some X\n    \\<longrightarrow> (\\<exists>w. epdaH_conf_stack c = X # w)\"\n\ntheorem F_DPDA_OTS__enforces__corresponds_to_top_stack: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> corresponds_to_top_stack R F_DPDA_OTS__is_auxiliary F_DPDA_OTS__get_stack\"\n  apply(simp add: corresponds_to_top_stack_def)\n  apply(clarsimp)\n  apply(rename_tac d n c X)(*strict*)\n  apply(case_tac \"d n\")\n   apply(rename_tac d n c X)(*strict*)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d n c X a)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(case_tac a)\n  apply(rename_tac d n c X a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d n c X option)(*strict*)\n  apply(simp add: F_DPDA_OTS__is_auxiliary_def F_DPDA_OTS__get_stack_def)\n  apply(case_tac c)\n  apply(rename_tac d n c X option epdaH_conf_statea epdaH_conf_history epdaH_conf_stacka)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d n X option epdaH_conf_state epdaH_conf_history epdaH_conf_stack)(*strict*)\n  apply(rename_tac e q h s)\n  apply(rename_tac d n X e q h s)(*strict*)\n  apply(case_tac q)\n   apply(rename_tac d n X e q h s a b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d n X e h s a)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d n X e h s a)(*strict*)\n    prefer 2\n    apply(rule F_DPDA_OTS__topstack_equal_to_annotation)\n        apply(rename_tac d n X e h s a)(*strict*)\n        apply(force)\n       apply(rename_tac d n X e h s a)(*strict*)\n       apply(force)\n      apply(rename_tac d n X e h s a)(*strict*)\n      apply(force)\n     apply(rename_tac d n X e h s a)(*strict*)\n     apply(force)\n    apply(rename_tac d n X e h s a)(*strict*)\n    apply(force)\n   apply(rename_tac d n X e h s a)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d n X e q h s a)(*strict*)\n  apply(case_tac q)\n   apply(rename_tac d n X e q h s a aa b)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d n X e q h s a aa)(*strict*)\n  apply(clarsimp)\n  done\n\ndefinition state_stack_unique :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> 'state set\n  \\<Rightarrow> bool\"\n  where\n    \"state_stack_unique G Q \\<equiv>\n  \\<forall>d1 d2 e1 e2 c1 c2 n1 n2.\n    epdaH.derivation_initial G d1\n    \\<longrightarrow> epdaH.derivation_initial G d2\n    \\<longrightarrow> d1 n1 = Some (pair e1 c1)\n    \\<longrightarrow> d2 n2 = Some (pair e2 c2)\n    \\<longrightarrow> epdaH_conf_state c1 = epdaH_conf_state c2\n    \\<longrightarrow> epdaH_conf_state c1 \\<in> Q\n    \\<longrightarrow> hd (epdaH_conf_stack c1) = hd (epdaH_conf_stack c2)\"\n\nlemma F_DPDA_OTS__state_stack_unique_for_annotated_states: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> state_stack_unique R (F_DPDA_OTS__states_auxiliary M)\"\n  apply(simp add: state_stack_unique_def)\n  apply(clarsimp)\n  apply(rename_tac d1 d2 e1 e2 c1 n1 c2 n2)(*strict*)\n  apply(case_tac c1)\n  apply(rename_tac d1 d2 e1 e2 c1 n1 c2 n2 epdaH_conf_statea epdaH_conf_history epdaH_conf_stacka)(*strict*)\n  apply(case_tac c2)\n  apply(rename_tac d1 d2 e1 e2 c1 n1 c2 n2 epdaH_conf_statea epdaH_conf_history epdaH_conf_stacka epdaH_conf_stateaa epdaH_conf_historya epdaH_conf_stackaa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 d2 e1 e2 n1 n2 epdaH_conf_history epdaH_conf_stack epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n  apply(rename_tac h1 s1 q h2 s2)\n  apply(rename_tac d1 d2 e1 e2 n1 n2 h1 s1 q h2 s2)(*strict*)\n  apply(simp add: F_DPDA_OTS__states_auxiliary_def)\n  apply(clarsimp)\n  apply(rename_tac d1 d2 e1 e2 n1 n2 h1 s1 h2 s2 a b)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1 d2 e1 e2 n1 n2 h1 s1 h2 s2 a b)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"d1\"\n      and n=\"n1\"\n      in F_DPDA_OTS__topstack_equal_to_annotation)\n       apply(rename_tac d1 d2 e1 e2 n1 n2 h1 s1 h2 s2 a b)(*strict*)\n       apply(force)\n      apply(rename_tac d1 d2 e1 e2 n1 n2 h1 s1 h2 s2 a b)(*strict*)\n      apply(force)\n     apply(rename_tac d1 d2 e1 e2 n1 n2 h1 s1 h2 s2 a b)(*strict*)\n     apply(force)\n    apply(rename_tac d1 d2 e1 e2 n1 n2 h1 s1 h2 s2 a b)(*strict*)\n    apply(force)\n   apply(rename_tac d1 d2 e1 e2 n1 n2 h1 s1 h2 s2 a b)(*strict*)\n   apply(force)\n  apply(rename_tac d1 d2 e1 e2 n1 n2 h1 s1 h2 s2 a b)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1 d2 e1 e2 n1 n2 h1 s1 h2 s2 a b)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"d2\"\n      and n=\"n2\"\n      in F_DPDA_OTS__topstack_equal_to_annotation)\n       apply(rename_tac d1 d2 e1 e2 n1 n2 h1 s1 h2 s2 a b)(*strict*)\n       apply(force)\n      apply(rename_tac d1 d2 e1 e2 n1 n2 h1 s1 h2 s2 a b)(*strict*)\n      apply(force)\n     apply(rename_tac d1 d2 e1 e2 n1 n2 h1 s1 h2 s2 a b)(*strict*)\n     apply(force)\n    apply(rename_tac d1 d2 e1 e2 n1 n2 h1 s1 h2 s2 a b)(*strict*)\n    apply(force)\n   apply(rename_tac d1 d2 e1 e2 n1 n2 h1 s1 h2 s2 a b)(*strict*)\n   apply(force)\n  apply(rename_tac d1 d2 e1 e2 n1 n2 h1 s1 h2 s2 a b)(*strict*)\n  apply(force)\n  done\n\ndefinition always_applicable :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> 'state set\n  \\<Rightarrow> bool\"\n  where\n    \"always_applicable G Q \\<equiv>\n  \\<forall>d e c n.\n    epdaH.derivation_initial G d\n    \\<longrightarrow> d n = Some (pair e c)\n    \\<longrightarrow> epdaH_conf_state c \\<in> Q\n    \\<longrightarrow> (\\<forall>e \\<in> epda_delta G.\n          edge_src e = epdaH_conf_state c\n          \\<longrightarrow> (\\<exists>c'. epdaH_step_relation G c e c'))\"\n\nlemma F_DPDA_OTS__always_applicable_for_annotated_states: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> always_applicable R (F_DPDA_OTS__states_auxiliary M)\"\n  apply(simp add: always_applicable_def F_DPDA_OTS__states_auxiliary_def F_DPDA_OTS_def F_DPDA_OTS__edges_def F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  apply(clarsimp)\n  apply(rename_tac d e c n a b ea)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac d e c n a b ea)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d e c n a b ea)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d e c n a b x)(*strict*)\n  apply(simp add: always_applicable_def F_DPDA_OTS__states_auxiliary_def F_DPDA_OTS_def F_DPDA_OTS__edges_def F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  apply(clarsimp)\n  apply(rename_tac d e c n x)(*strict*)\n  apply(case_tac c)\n  apply(rename_tac d e c n x epdaH_conf_statea epdaH_conf_history epdaH_conf_stack)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d e n x epdaH_conf_history epdaH_conf_stack)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d e n x epdaH_conf_history epdaH_conf_stack)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"d\"\n      in F_DPDA_OTS__topstack_equal_to_annotation)\n       apply(rename_tac d e n x epdaH_conf_history epdaH_conf_stack)(*strict*)\n       apply(force)\n      apply(rename_tac d e n x epdaH_conf_history epdaH_conf_stack)(*strict*)\n      apply(force)\n     apply(rename_tac d e n x epdaH_conf_history epdaH_conf_stack)(*strict*)\n     apply(simp add: always_applicable_def F_DPDA_OTS__states_auxiliary_def F_DPDA_OTS_def F_DPDA_OTS__edges_def F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n    apply(rename_tac d e n x epdaH_conf_history epdaH_conf_stack)(*strict*)\n    apply(force)\n   apply(rename_tac d e n x epdaH_conf_history epdaH_conf_stack)(*strict*)\n   apply(force)\n  apply(rename_tac d e n x epdaH_conf_history epdaH_conf_stacka)(*strict*)\n  apply(simp add: valid_dpda_def valid_pda_def)\n  apply(rename_tac d e n x epdaH_conf_history epdaH_conf_stack)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d e n x epdaH_conf_history w)(*strict*)\n  apply(erule_tac\n      x=\"x\"\n      in ballE)\n   apply(rename_tac d e n x epdaH_conf_history w)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac d e n x epdaH_conf_history w)(*strict*)\n  apply(case_tac \"x\")\n  apply(rename_tac d e n x epdaH_conf_history w edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d e n epdaH_conf_history w edge_src edge_event edge_pop edge_push edge_trg)(*strict*)\n  apply(case_tac edge_pop)\n   apply(rename_tac d e n epdaH_conf_history w edge_src edge_event edge_pop edge_push edge_trg)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d e n epdaH_conf_history w edge_src edge_event edge_pop edge_push edge_trg a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d e n epdaH_conf_history w edge_src edge_event edge_push edge_trg a)(*strict*)\n  apply(rule_tac\n      x=\"\\<lparr>epdaH_conf_state = cons_state edge_trg, epdaH_conf_history = epdaH_conf_history@option_to_list edge_event, epdaH_conf_stack = edge_push@w\\<rparr>\"\n      in exI)\n  apply(rename_tac d e n epdaH_conf_history w edge_src edge_event edge_push edge_trg a)(*strict*)\n  apply(simp add: epdaH_step_relation_def)\n  apply(rule disjI2)\n  apply(rule inMap)\n  apply(rule_tac\n      x=\"\\<lparr>edge_src = edge_src, edge_event = edge_event, edge_pop = [a], edge_push = edge_push, edge_trg = edge_trg\\<rparr>\"\n      in bexI)\n   apply(rename_tac d e n epdaH_conf_history w edge_src edge_event edge_push edge_trg a)(*strict*)\n   apply(simp add: always_applicable_def F_DPDA_OTS__states_auxiliary_def F_DPDA_OTS_def F_DPDA_OTS__edges_def F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  apply(rename_tac d e n epdaH_conf_history w edge_src edge_event edge_push edge_trg a)(*strict*)\n  apply(clarsimp)\n  done\n\ndefinition always_applicable_for_auxiliary_states :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> ('state \\<Rightarrow> bool)\n  \\<Rightarrow> bool\"\n  where\n    \"always_applicable_for_auxiliary_states G F \\<equiv>\n  always_applicable G (Collect F)\"\n\ntheorem F_DPDA_OTS__enforces__always_applicable_for_auxiliary_states: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> always_applicable_for_auxiliary_states R F_DPDA_OTS__is_auxiliary\"\n  apply(subgoal_tac \"valid_pda R\")\n   apply(simp add: always_applicable_for_auxiliary_states_def)\n   apply(subgoal_tac \"always_applicable R (F_DPDA_OTS__states_auxiliary M)\")\n    prefer 2\n    apply(rule F_DPDA_OTS__always_applicable_for_annotated_states)\n     apply(force)\n    apply(force)\n   apply(simp add: always_applicable_def)\n   apply(clarsimp)\n   apply(rename_tac d e c n ea)(*strict*)\n   apply(erule_tac\n      x=\"d\"\n      in allE)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"e\"\n      in allE)\n   apply(erule_tac\n      x=\"c\"\n      in allE)\n   apply(erule impE)\n    apply(rename_tac d e c n ea)(*strict*)\n    apply(rule_tac\n      x=\"n\"\n      in exI)\n    apply(clarsimp)\n   apply(rename_tac d e c n ea)(*strict*)\n   apply(erule impE)\n    apply(rename_tac d e c n ea)(*strict*)\n    apply(case_tac c)\n    apply(rename_tac d e c n ea epdaH_conf_statea epdaH_conf_history epdaH_conf_stack)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d e n ea epdaH_conf_history epdaH_conf_stack)(*strict*)\n    apply(simp add: F_DPDA_OTS__is_auxiliary_def)\n    apply(case_tac ea)\n    apply(rename_tac d e n ea epdaH_conf_history epdaH_conf_stack edge_srca edge_event edge_pop edge_push edge_trg)(*strict*)\n    apply(case_tac edge_srca)\n     apply(rename_tac d e n ea epdaH_conf_history epdaH_conf_stack edge_srca edge_event edge_pop edge_push edge_trg a b)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac d e n epdaH_conf_history epdaH_conf_stack edge_event edge_pop edge_push edge_trg a b)(*strict*)\n     apply(simp add: valid_pda_def valid_epda_def)\n     apply(rename_tac d e n epdaH_conf_history epdaH_conf_stack edge_event edge_popa edge_push edge_trg a b)(*strict*)\n     apply(clarsimp)\n     apply(erule_tac\n      x=\"\\<lparr>edge_src = cons_state_and_stack a b, edge_event = edge_event, edge_pop = edge_popa, edge_push = edge_push, edge_trg = edge_trg\\<rparr>\"\n      and P=\"\\<lambda>a. valid_epda_step_label (F_DPDA_OTS M) a\"\n      in ballE)\n      apply(rename_tac d e n epdaH_conf_history epdaH_conf_stack edge_event edge_popa edge_push edge_trg a b)(*strict*)\n      apply(simp add: valid_epda_step_label_def)\n      apply(clarsimp)\n      apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__states_def F_DPDA_OTS__states_main_def)\n      apply(clarsimp)\n     apply(rename_tac d e n epdaH_conf_history epdaH_conf_stack edge_event edge_popa edge_push edge_trg a b)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d e n ea epdaH_conf_history epdaH_conf_stack edge_srca edge_event edge_pop edge_push edge_trg a)(*strict*)\n    apply(force)\n   apply(rename_tac d e c n ea)(*strict*)\n   apply(erule_tac\n      x=\"ea\"\n      in ballE)\n    apply(rename_tac d e c n ea)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d e c n ea)(*strict*)\n   apply(force)\n  apply (metis F_DPDA_OTS__preserves__DPDA valid_dpda_to_valid_pda)\n  done\n\ndefinition some_edge_applicable :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"some_edge_applicable G \\<equiv>\n  \\<forall>d e e' c n.\n    epdaH.derivation_initial G d\n    \\<longrightarrow> d n = Some (pair e c)\n    \\<longrightarrow> e' \\<in> epda_delta G\n    \\<longrightarrow> edge_src e' = epdaH_conf_state c\n    \\<longrightarrow> (\\<exists>e c'.\n          epdaH_step_relation G c e c'\n          \\<and> (edge_event e' = None \\<longrightarrow> edge_event e = None))\"\n\ntheorem F_DPDA_OTS__enforces__some_edge_applicable: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> valid_dpda R\n  \\<Longrightarrow> some_edge_applicable R\"\n  apply(subgoal_tac \"always_applicable R (F_DPDA_OTS__states_auxiliary M)\")\n   prefer 2\n   apply(rule F_DPDA_OTS__always_applicable_for_annotated_states)\n    apply(force)\n   apply(force)\n  apply(simp add: some_edge_applicable_def)\n  apply(clarsimp)\n  apply(rename_tac d e e' c n)(*strict*)\n  apply(case_tac c)\n  apply(rename_tac d e e' c n epdaH_conf_statea epdaH_conf_history epdaH_conf_stack)(*strict*)\n  apply(rename_tac q h s)\n  apply(rename_tac d e e' c n q h s)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d e e' c n q h s)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"F_DPDA_OTS M\"\n      and d=\"d\"\n      and n=\"n\"\n      in epdaH_epda_box_stays_at_bottom)\n     apply(rename_tac d e e' c n q h s)(*strict*)\n     apply(simp add: valid_dpda_def valid_pda_def)\n    apply(rename_tac d e e' c n q h s)(*strict*)\n    apply(force)\n   apply(rename_tac d e e' c n q h s)(*strict*)\n   apply(force)\n  apply(rename_tac d e e' c n q h s)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d e e' n h s)(*strict*)\n  apply(simp add: suffix_def)\n  apply(clarsimp)\n  apply(rename_tac d e e' n h c)(*strict*)\n  apply(subgoal_tac \"\\<lparr>epdaH_conf_state = edge_src e', epdaH_conf_history = h, epdaH_conf_stack = c @ [epda_box (F_DPDA_OTS M)]\\<rparr> \\<in> epdaH_configurations (F_DPDA_OTS M)\")\n   apply(rename_tac d e e' n h c)(*strict*)\n   prefer 2\n   apply(rule epdaH.belongs_configurations)\n    apply(rename_tac d e e' n h c)(*strict*)\n    apply(rule epdaH.derivation_initial_belongs)\n     apply(rename_tac d e e' n h c)(*strict*)\n     apply(simp add: valid_dpda_def valid_pda_def)\n    apply(rename_tac d e e' n h c)(*strict*)\n    apply(force)\n   apply(rename_tac d e e' n h c)(*strict*)\n   apply(force)\n  apply(rename_tac d e e' n h c)(*strict*)\n  apply(subgoal_tac \"e' \\<in> F_DPDA_OTS__edges_main_auxiliary M \\<or> e' \\<in> F_DPDA_OTS__edges_auxiliary_main M\")\n   apply(rename_tac d e e' n h c)(*strict*)\n   prefer 2\n   apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def)\n  apply(rename_tac d e e' n h c)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac d e e' n h c)(*strict*)\n   apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def)\n   apply(clarsimp)\n   apply(rename_tac d e n h c a b)(*strict*)\n   apply(rule_tac\n      x=\"\\<lparr>edge_src=cons_state a,edge_event=None,edge_pop=[hd(c @ [epda_box M])],edge_push=[hd(c @ [epda_box M])],edge_trg=cons_state_and_stack a (hd(c @ [epda_box M]))\\<rparr>\"\n      in exI)\n   apply(clarsimp)\n   apply(rule_tac\n      x=\"\\<lparr>epdaH_conf_state = cons_state_and_stack a (hd(c @ [epda_box M])), epdaH_conf_history = h, epdaH_conf_stack = c @ [epda_box M]\\<rparr>\"\n      in exI)\n   apply(simp add: epdaH_step_relation_def)\n   apply(rule conjI)\n    apply(rename_tac d e n h c a b)(*strict*)\n    apply(rule disjI1)\n    apply(rule inMap)\n    apply(clarsimp)\n    apply(case_tac c)\n     apply(rename_tac d e n h c a b)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac d e n h a b)(*strict*)\n     apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n    apply(rename_tac d e n h c a b aa list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d e n h a b aa list)(*strict*)\n    apply(simp add: epdaH_configurations_def valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac d e n h c a b)(*strict*)\n   apply(simp add: option_to_list_def)\n   apply(case_tac c)\n    apply(rename_tac d e n h c a b)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d e n h c a b aa list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d e e' n h c)(*strict*)\n  apply(simp add: F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def always_applicable_def)\n  apply(clarsimp)\n  apply(rename_tac d e n h c x)(*strict*)\n  apply(simp add: F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def always_applicable_def)\n  apply(erule_tac\n      x=\"d\"\n      in allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"e\"\n      in allE)\n  apply(erule_tac\n      x=\"\\<lparr>epdaH_conf_state = cons_state_and_stack (edge_src x) (hd (edge_pop x)), epdaH_conf_history = h, epdaH_conf_stack = c @ [epda_box (F_DPDA_OTS M)]\\<rparr>\"\n      in allE)\n  apply(rename_tac d e n h c x)(*strict*)\n  apply(clarsimp)\n  apply(erule impE)\n   apply(rename_tac d e n h c x)(*strict*)\n   apply(force)\n  apply(rename_tac d e n h c x)(*strict*)\n  apply(erule impE)\n   apply(rename_tac d e n h c x)(*strict*)\n   apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def)\n   apply(simp add: epdaH_configurations_def F_DPDA_OTS__states_auxiliary_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_OTS__states_def)\n   apply(simp add: epdaH_configurations_def F_DPDA_OTS__states_auxiliary_def)\n   apply(clarsimp)\n   apply(rule inMap)\n   apply(clarsimp)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"x\"\n      and P=\"\\<lambda>x. valid_epda_step_label M x\"\n      in ballE)\n    apply(rename_tac d e n h c x)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac d e n h c x)(*strict*)\n   apply(erule_tac\n      x=\"x\"\n      in ballE)\n    apply(rename_tac d e n h c x)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac d e n h c x)(*strict*)\n   apply(case_tac \"x\")\n   apply(rename_tac d e n h c x edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d e n h c edge_src edge_event edge_popa edge_push edge_trg)(*strict*)\n   apply(case_tac edge_popa)\n    apply(rename_tac d e n h c edge_src edge_event edge_popa edge_push edge_trg)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d e n h c edge_src edge_event edge_popa edge_push edge_trg a list)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d e n h c edge_src edge_event edge_push edge_trg a)(*strict*)\n   apply(simp add: valid_epda_step_label_def)\n   apply(rename_tac d e n h c edge_srca edge_eventa edge_pusha edge_trga a)(*strict*)\n   apply(clarsimp)\n   apply(simp add: may_terminated_by_def must_terminated_by_def kleene_star_def append_language_def)\n   apply(clarsimp)\n   apply(rename_tac d e n h c edge_srca edge_eventa edge_pusha edge_trga a aa ab)(*strict*)\n   apply(erule disjE)+\n       apply(rename_tac d e n h c edge_srca edge_eventa edge_pusha edge_trga a aa ab)(*strict*)\n       apply(clarsimp)+\n    apply(rename_tac d e n h c edge_srca edge_eventa edge_pusha edge_trga a aa ab)(*strict*)\n    apply(erule disjE)+\n      apply(rename_tac d e n h c edge_srca edge_eventa edge_pusha edge_trga a aa ab)(*strict*)\n      apply(clarsimp)+\n   apply(rename_tac d e n h c edge_srca edge_eventa edge_pusha edge_trga a aa ab)(*strict*)\n   apply(erule disjE)+\n      apply(rename_tac d e n h c edge_srca edge_eventa edge_pusha edge_trga a aa ab)(*strict*)\n      apply(clarsimp)+\n   apply(rename_tac d e n h c edge_srca edge_eventa edge_pusha edge_trga a aa ab)(*strict*)\n   apply(erule disjE)+\n     apply(rename_tac d e n h c edge_srca edge_eventa edge_pusha edge_trga a aa ab)(*strict*)\n     apply(clarsimp)+\n  apply(rename_tac d e n h c x)(*strict*)\n  apply(erule_tac\n      x=\"\\<lparr>edge_src = cons_state_and_stack (edge_src x) (hd (edge_pop x)), edge_event = edge_event x, edge_pop = edge_pop x, edge_push = edge_push x, edge_trg = cons_state (edge_trg x)\\<rparr>\"\n      in ballE)\n   apply(rename_tac d e n h c x)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac d e n h c x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d e n h c x xa)(*strict*)\n  apply(rule_tac\n      x=\"\\<lparr>edge_src = cons_state_and_stack (edge_src x) (hd (edge_pop x)), edge_event = edge_event x, edge_pop = edge_pop x, edge_push = edge_push x, edge_trg = cons_state (edge_trg x)\\<rparr>\"\n      in exI)\n  apply(rename_tac d e n h c x xa)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n      x=\"xa\"\n      in exI)\n  apply(clarsimp)\n  done\n\ndefinition always_applicable_for_stable_states :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"always_applicable_for_stable_states G \\<equiv>\n  always_applicable G (epda_states G - epda_nonstable_states (epda_delta G))\"\n\nlemma always_applicable__subseteq: \"\n  valid_dpda M\n  \\<Longrightarrow> Q' \\<subseteq> Q\n  \\<Longrightarrow> always_applicable R Q\n  \\<Longrightarrow> always_applicable R Q'\"\n  apply(simp add: always_applicable_def)\n  apply(clarsimp)\n  apply(rename_tac d e c n ea)(*strict*)\n  apply(erule_tac\n      x=\"d\"\n      in allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"e\"\n      in allE)\n  apply(erule_tac\n      x=\"c\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac d e c n ea)(*strict*)\n   apply(rule_tac\n      x=\"n\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac d e c n ea)(*strict*)\n  apply(erule impE)\n   apply(rename_tac d e c n ea)(*strict*)\n   apply(force)\n  apply(rename_tac d e c n ea)(*strict*)\n  apply(clarsimp)\n  done\n\ntheorem F_DPDA_OTS__enforces__always_applicable_for_stable_states: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> always_applicable_for_stable_states R\"\n  apply(simp add: always_applicable_for_stable_states_def)\n  apply(rule always_applicable__subseteq)\n    apply(force)\n   prefer 2\n   apply(rule F_DPDA_OTS__always_applicable_for_annotated_states)\n    apply(force)\n   apply(force)\n  apply(simp add: epda_nonstable_states_def F_DPDA_OTS__states_main_def F_DPDA_OTS__states_def F_DPDA_OTS_def F_DPDA_OTS__marking_states_def F_DPDA_OTS__states_auxiliary_def valid_dpda_def valid_pda_def valid_epda_def)\n  apply(clarsimp)\n  apply(rename_tac xa)(*strict*)\n  apply(thin_tac \"cons_state xa \\<notin> (\\<lambda>(x, y). cons_state_and_stack x y) ` (epda_states M \\<times> epda_gamma M)\")\n  apply(simp add: F_DPDA_OTS__edges_def F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def)\n  apply(rule_tac\n      x=\"\\<lparr>edge_src=cons_state xa,edge_event=None,edge_pop=[epda_box M],edge_push=[epda_box M],edge_trg=cons_state_and_stack xa (epda_box M)\\<rparr>\"\n      in bexI)\n   apply(rename_tac xa)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac xa)(*strict*)\n  apply(clarsimp)\n  apply(rule inMap)\n  apply(clarsimp)\n  done\n\ndefinition state_stack_unique_for_marking_states :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"state_stack_unique_for_marking_states G \\<equiv>\n  state_stack_unique G (epda_marking G)\"\n\nlemma state_stack_unique__subseteq: \"\n  valid_dpda M\n  \\<Longrightarrow> Q' \\<subseteq> Q\n  \\<Longrightarrow> state_stack_unique R Q\n  \\<Longrightarrow> state_stack_unique R Q'\"\n  apply(simp add: state_stack_unique_def)\n  apply(clarsimp)\n  apply(rename_tac d1 d2 e1 e2 c1 n1 c2 n2)(*strict*)\n  apply(erule_tac\n      x=\"d1\"\n      in allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"d2\"\n      in allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"e1\"\n      in allE)\n  apply(erule_tac\n      x=\"e2\"\n      in allE)\n  apply(erule_tac\n      x=\"c1\"\n      in allE)\n  apply(clarsimp)\n  apply(erule impE)\n   apply(rename_tac d1 d2 e1 e2 c1 n1 c2 n2)(*strict*)\n   apply(rule_tac\n      x=\"n1\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac d1 d2 e1 e2 c1 n1 c2 n2)(*strict*)\n  apply(erule_tac\n      x=\"c2\"\n      in allE)\n  apply(clarsimp)\n  apply(force)\n  done\n\ntheorem F_DPDA_OTS__enforces__state_stack_unique_for_marking_states: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> state_stack_unique_for_marking_states R\"\n  apply(simp add: state_stack_unique_for_marking_states_def)\n  apply(rule state_stack_unique__subseteq)\n    apply(force)\n   prefer 2\n   apply(rule F_DPDA_OTS__state_stack_unique_for_annotated_states)\n    apply(force)\n   apply(force)\n  apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__marking_states_def F_DPDA_OTS__states_auxiliary_def valid_dpda_def valid_pda_def valid_epda_def)\n  apply(clarsimp)\n  apply(rename_tac a b)(*strict*)\n  apply(rule inMap)\n  apply(force)\n  done\n\ndefinition state_stack_unique_for_stable_states :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"state_stack_unique_for_stable_states G \\<equiv>\n  state_stack_unique G (epda_states G - epda_nonstable_states (epda_delta G))\"\n\ntheorem F_DPDA_OTS__enforces___state_stack_unique_for_stable_states: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> state_stack_unique_for_stable_states R\"\n  apply(simp add: state_stack_unique_for_stable_states_def)\n  apply(rule state_stack_unique__subseteq)\n    apply(force)\n   prefer 2\n   apply(rule F_DPDA_OTS__state_stack_unique_for_annotated_states)\n    apply(force)\n   apply(force)\n  apply(simp add: epda_nonstable_states_def F_DPDA_OTS__states_main_def F_DPDA_OTS__states_def F_DPDA_OTS_def F_DPDA_OTS__marking_states_def F_DPDA_OTS__states_auxiliary_def valid_dpda_def valid_pda_def valid_epda_def)\n  apply(clarsimp)\n  apply(rename_tac xa)(*strict*)\n  apply(thin_tac \"cons_state xa \\<notin> (\\<lambda>(x, y). cons_state_and_stack x y) ` (epda_states M \\<times> epda_gamma M)\")\n  apply(simp add: F_DPDA_OTS__edges_def F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def)\n  apply(rule_tac\n      x=\"\\<lparr>edge_src=cons_state xa,edge_event=None,edge_pop=[epda_box M],edge_push=[epda_box M],edge_trg=cons_state_and_stack xa (epda_box M)\\<rparr>\"\n      in bexI)\n   apply(rename_tac xa)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac xa)(*strict*)\n  apply(clarsimp)\n  apply(rule inMap)\n  apply(clarsimp)\n  done\n\nlemma F_DPDA_OTS__enforces__cons_state_and_stack_cons_state_alternation: \"\n  valid_dpda G\n  \\<Longrightarrow> epdaH.derivation_initial (F_DPDA_OTS G) d\n  \\<Longrightarrow> d (n + n) = Some (pair e1 c1)\n  \\<Longrightarrow> d (Suc (n + n)) = Some (pair e2 c2)\n  \\<Longrightarrow> \\<exists>q1 A q2. epdaH_conf_state c1 = cons_state_and_stack q1 A \\<and> epdaH_conf_state c2 = cons_state q2\"\n  apply(induct n arbitrary: e1 c1 e2 c2)\n   apply(rename_tac e1 c1 e2 c2)(*strict*)\n   apply(clarsimp)\n   apply(simp add: epdaH.derivation_initial_def epdaH_initial_configurations_def F_DPDA_OTS_def)\n   apply(clarsimp)\n   apply(rename_tac c1 e2 c2)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac c1 e2 c2)(*strict*)\n    prefer 2\n    apply(rule_tac\n      n=\"0\"\n      and m=\"(Suc 0)\"\n      in epdaH.step_detail_before_some_position)\n      apply(rename_tac c1 e2 c2)(*strict*)\n      apply(force)\n     apply(rename_tac c1 e2 c2)(*strict*)\n     apply(force)\n    apply(rename_tac c1 e2 c2)(*strict*)\n    apply(force)\n   apply(rename_tac c1 e2 c2)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c1 c2 e2a)(*strict*)\n   apply(simp add: epdaH_step_relation_def der1_def get_configuration_def epdaH_initial_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def)\n   apply(clarsimp)\n   apply(rename_tac c2 e2a w)(*strict*)\n   apply(simp add: F_DPDA_OTS__get_state_def F_DPDA_OTS__edges_def)\n   apply(erule disjE)+\n    apply(rename_tac c2 e2a w)(*strict*)\n    apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n    apply(clarsimp)\n   apply(rename_tac c2 e2a w)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n   apply(clarsimp)\n   apply(rename_tac c2 w x)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  apply(rename_tac n e1 c1 e2 c2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n e1 c1 e2 c2)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac n e1 c1 e2 c2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      n=\"(n+n)\"\n      and m=\"(Suc (Suc (Suc (n + n))))\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac n e1 c1 e2 c2)(*strict*)\n     apply(rule epdaH.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac n e1 c1 e2 c2)(*strict*)\n    apply(force)\n   apply(rename_tac n e1 c1 e2 c2)(*strict*)\n   apply(force)\n  apply(rename_tac n e1 c1 e2 c2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n e1 c1 e2 c2 e1a e2a c1a c2a)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac n e1 c1 e2 c2 e1a e2a c1a c2a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      n=\"Suc(n+n)\"\n      and m=\"(Suc (Suc (Suc (n + n))))\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac n e1 c1 e2 c2 e1a e2a c1a c2a)(*strict*)\n     apply(rule epdaH.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac n e1 c1 e2 c2 e1a e2a c1a c2a)(*strict*)\n    apply(force)\n   apply(rename_tac n e1 c1 e2 c2 e1a e2a c1a c2a)(*strict*)\n   apply(force)\n  apply(rename_tac n e1 c1 e2 c2 e1a e2a c1a c2a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n c1 e2 c2 e1a e2a c1a c2a e2b)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac n c1 e2 c2 e1a e2a c1a c2a e2b)(*strict*)\n   prefer 2\n   apply(rule_tac\n      n=\"Suc(Suc(n+n))\"\n      and m=\"(Suc (Suc (Suc (n + n))))\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac n c1 e2 c2 e1a e2a c1a c2a e2b)(*strict*)\n     apply(rule epdaH.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac n c1 e2 c2 e1a e2a c1a c2a e2b)(*strict*)\n    apply(force)\n   apply(rename_tac n c1 e2 c2 e1a e2a c1a c2a e2b)(*strict*)\n   apply(force)\n  apply(rename_tac n c1 e2 c2 e1a e2a c1a c2a e2b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n c1 c2 e1a e2a c1a c2a e2b e2c)(*strict*)\n  apply(erule_tac\n      x=\"e1a\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"c1a\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"Some e2a\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"c2a\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(rename_tac n c1 c2 e1a e2a c1a c2a e2b e2c q1 q2 A)(*strict*)\n  apply(simp add: epdaH_step_relation_def der1_def get_configuration_def epdaH_initial_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def)\n  apply(simp add: F_DPDA_OTS__get_state_def F_DPDA_OTS__edges_def)\n  apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  apply(clarsimp)\n  apply(rename_tac n c1 c2 e1a e2a c1a c2a e2b e2c q1 q2 A w wa wb)(*strict*)\n  apply(erule disjE)+\n     apply(rename_tac n c1 c2 e1a e2a c1a c2a e2b e2c q1 q2 A w wa wb)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac n c1 c2 e1a e2a c1a c2a e2b e2c q1 q2 A w wa wb)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac n c1 c2 e1a e2a c1a c2a e2b e2c q1 q2 A w wa wb)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac n c1 c2 e1a e2a c1a c2a e2b e2c q1 q2 A w wa wb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n c1 c2 e1a c1a c2a e2b e2c q1 q2 A w wa wb x)(*strict*)\n  apply(erule disjE)+\n    apply(rename_tac n c1 c2 e1a c1a c2a e2b e2c q1 q2 A w wa wb x)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac n c1 c2 e1a c1a c2a e2b e2c q1 q2 A w wa wb x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n c1 c2 e1a c1a c2a q1 A w wa wb x a b xa)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  apply(rename_tac n c1 c2 e1a c1a c2a e2b e2c q1 q2 A w wa wb x)(*strict*)\n  apply(erule disjE)+\n   apply(rename_tac n c1 c2 e1a c1a c2a e2b e2c q1 q2 A w wa wb x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n c1 c2 e1a c1a c2a q1 q2 A w wa wb x xa a b)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  apply(rename_tac n c1 c2 e1a c1a c2a e2b e2c q1 q2 A w wa wb x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n c1 c2 e1a c1a c2a q1 q2 A w wa wb x xa xb)(*strict*)\n  apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  done\n\ndefinition DPDA_OTS__translate_back :: \"\n  ((('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epda_step_label, (('state, 'stack) DT_state_and_stack_or_state, 'event, 'stack) epdaH_conf) derivation\n  \\<Rightarrow> (('state, 'event, 'stack) epda_step_label, ('state, 'event, 'stack) epdaH_conf) derivation\"\n  where\n    \"DPDA_OTS__translate_back d \\<equiv>\n  \\<lambda>n.\n    if n = 0\n    then Some (pair\n                None\n                (F_DPDA_OTS__epdaH_epdaH__LR__configuration1R\n                  (case d 0 of\n                  Some (pair e c) \\<Rightarrow> c)))\n    else\n      case (d ((n + n) -Suc 0)) of\n      None \\<Rightarrow> None\n      | Some (pair e c) \\<Rightarrow>\n          Some (pair\n                  (if n = 0\n                  then None\n                  else\n                    (case e of\n                    None \\<Rightarrow> None\n                    | Some e' \\<Rightarrow> Some (F_DPDA_OTS__epdaH_epdaH__RL__edge e')))\n                  (F_DPDA_OTS__epdaH_epdaH__LR__configuration1R c))\"\n\nlemma F_DPDA_OTS__translateB__preserves__derivation: \"\n  valid_dpda G\n  \\<Longrightarrow> epdaH.derivation_initial (F_DPDA_OTS G) d\n  \\<Longrightarrow> \\<forall>n. d n \\<noteq> None\n  \\<Longrightarrow> epdaH.derivation G (DPDA_OTS__translate_back d)\"\n  apply(simp (no_asm) add: epdaH.derivation_def DPDA_OTS__translate_back_def)\n  apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(case_tac i)\n   apply(rename_tac i)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac i nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat)(*strict*)\n  apply(case_tac nat)\n   apply(rename_tac nat)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"X\" for X)\n    prefer 2\n    apply(rule_tac\n      n=\"0\"\n      and m=\"Suc 0\"\n      in epdaH.step_detail_before_some_position)\n      apply(simp add: epdaH.derivation_initial_def)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(clarsimp)\n   apply(rename_tac e1 e2 c1 c2)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac e1 e2 c1 c2)(*strict*)\n    prefer 2\n    apply(rule_tac\n      n=\"0\"\n      in F_DPDA_OTS__enforces__cons_state_and_stack_cons_state_alternation)\n       apply(rename_tac e1 e2 c1 c2)(*strict*)\n       apply(force)\n      apply(rename_tac e1 e2 c1 c2)(*strict*)\n      apply(force)\n     apply(rename_tac e1 e2 c1 c2)(*strict*)\n     apply(force)\n    apply(rename_tac e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac e1 e2 c1 c2)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac e1 e2 c1 c2 q1 q2 A)(*strict*)\n   apply(simp add: epdaH_step_relation_def der1_def get_configuration_def epdaH_initial_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def)\n   apply(clarsimp)\n   apply(rename_tac e1 e2 c1 c2 q1 q2 A w)(*strict*)\n   apply(case_tac c1)\n   apply(rename_tac e1 e2 c1 c2 q1 q2 A w epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n   apply(case_tac c2)\n   apply(rename_tac e1 e2 c1 c2 q1 q2 A w epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka epdaH_conf_stateaa epdaH_conf_historyaa epdaH_conf_stackaa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac e1 e2 q1 q2 A w epdaH_conf_history)(*strict*)\n   apply(case_tac e1)\n    apply(rename_tac e1 e2 q1 q2 A w epdaH_conf_history)(*strict*)\n    apply(case_tac e2)\n    apply(rename_tac e1 e2 q1 q2 A w epdaH_conf_history edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q1 q2 A w epdaH_conf_history edge_eventa edge_popa edge_pusha)(*strict*)\n    apply(simp add: F_DPDA_OTS__epdaH_epdaH__RL__edge_def)\n    apply(rename_tac q1 q2 A w epdaH_conf_history edge_event edge_pop edge_push)(*strict*)\n    apply(simp add: F_DPDA_OTS__get_state_def F_DPDA_OTS__edges_def)\n    apply(erule disjE)+\n     apply(rename_tac q1 q2 A w epdaH_conf_history edge_event edge_pop edge_push)(*strict*)\n     apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n     apply(clarsimp)\n    apply(rename_tac q1 q2 A w epdaH_conf_history edge_event edge_pop edge_push)(*strict*)\n    apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n    apply(clarsimp)\n    apply(rename_tac q1 q2 A w epdaH_conf_history edge_event edge_pop edge_push x)(*strict*)\n    apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n    apply(rename_tac q1 q2 A w epdaH_conf_history edge_eventa edge_popa edge_pusha x)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac w epdaH_conf_history x)(*strict*)\n    apply(case_tac x)\n    apply(rename_tac w epdaH_conf_history x edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n    apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n   apply(rename_tac e1 e2 q1 q2 A w epdaH_conf_history a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac e2 q1 q2 A w epdaH_conf_history a)(*strict*)\n   apply(simp add: F_DPDA_OTS__epdaH_epdaH__RL__edge_def)\n   apply(simp add: F_DPDA_OTS__get_state_def F_DPDA_OTS__edges_def)\n   apply(erule disjE)+\n    apply(rename_tac e2 q1 q2 A w epdaH_conf_history a)(*strict*)\n    apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n    apply(clarsimp)\n   apply(rename_tac e2 q1 q2 A w epdaH_conf_history a)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n   apply(clarsimp)\n   apply(rename_tac q1 q2 A w epdaH_conf_history a x)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n   apply(clarsimp)\n   apply(rename_tac w epdaH_conf_history a x)(*strict*)\n   apply(case_tac x)\n   apply(rename_tac w epdaH_conf_history a x edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  apply(rename_tac nat nata)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nata)(*strict*)\n  apply(rename_tac n)\n  apply(rename_tac n)(*strict*)\n  apply(case_tac \"(d (Suc (Suc (Suc (n + n)))))\")\n   apply(rename_tac n)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac n a)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac n a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      n=\"Suc (Suc (n + n))\"\n      and m=\"(Suc (Suc (Suc (n + n))))\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac n a)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n     apply(force)\n    apply(rename_tac n a)(*strict*)\n    apply(force)\n   apply(rename_tac n a)(*strict*)\n   apply(force)\n  apply(rename_tac n a)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac n a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      n=\"(Suc (n + n))\"\n      and m=\"(Suc (Suc (Suc (n + n))))\"\n      in epdaH.step_detail_before_some_position)\n     apply(rename_tac n a)(*strict*)\n     apply(simp add: epdaH.derivation_initial_def)\n     apply(force)\n    apply(rename_tac n a)(*strict*)\n    apply(force)\n   apply(rename_tac n a)(*strict*)\n   apply(force)\n  apply(rename_tac n a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n e1a e2 e2a c1 c1a c2)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac n e1a e2 e2a c1 c1a c2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      n=\"Suc n\"\n      in F_DPDA_OTS__enforces__cons_state_and_stack_cons_state_alternation)\n      apply(rename_tac n e1a e2 e2a c1 c1a c2)(*strict*)\n      apply(force)\n     apply(rename_tac n e1a e2 e2a c1 c1a c2)(*strict*)\n     apply(force)\n    apply(rename_tac n e1a e2 e2a c1 c1a c2)(*strict*)\n    apply(force)\n   apply(rename_tac n e1a e2 e2a c1 c1a c2)(*strict*)\n   apply(force)\n  apply(rename_tac n e1a e2 e2a c1 c1a c2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n e1a e2 e2a c1 c1a c2 q1 q2 A)(*strict*)\n  apply(simp add: epdaH_step_relation_def der1_def get_configuration_def epdaH_initial_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1_def F_DPDA_OTS_def epdaH_configurations_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def)\n  apply(clarsimp)\n  apply(rename_tac n e1a e2 e2a c1 c1a c2 q1 q2 A w wa)(*strict*)\n  apply(case_tac e2a)\n  apply(rename_tac n e1a e2 e2a c1 c1a c2 q1 q2 A w wa edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n  apply(case_tac c1)\n  apply(rename_tac n e1a e2 e2a c1 c1a c2 q1 q2 A w wa edge_srca edge_eventa edge_popa edge_pusha edge_trga epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka)(*strict*)\n  apply(case_tac c2)\n  apply(rename_tac n e1a e2 e2a c1 c1a c2 q1 q2 A w wa edge_srca edge_eventa edge_popa edge_pusha edge_trga epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka epdaH_conf_stateaa epdaH_conf_historyaa epdaH_conf_stackaa)(*strict*)\n  apply(case_tac c1a)\n  apply(rename_tac n e1a e2 e2a c1 c1a c2 q1 q2 A w wa edge_srca edge_eventa edge_popa edge_pusha edge_trga epdaH_conf_statea epdaH_conf_historya epdaH_conf_stacka epdaH_conf_stateaa epdaH_conf_historyaa epdaH_conf_stackaa epdaH_conf_stateb epdaH_conf_historyb epdaH_conf_stackb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n e1a e2 q1 q2 A w wa edge_srca edge_eventa edge_popa edge_pusha epdaH_conf_historyb)(*strict*)\n  apply(case_tac e2)\n  apply(rename_tac n e1a e2 q1 q2 A w wa edge_srca edge_eventa edge_popa edge_pusha epdaH_conf_historyb edge_srcaa edge_eventaa edge_popaa edge_pushaa edge_trga)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n e1a q1 q2 A w wa edge_srca edge_eventa edge_popa edge_pusha epdaH_conf_historyb edge_eventaa edge_popaa edge_pushaa)(*strict*)\n  apply(rename_tac qs r po pu h qs2 r2 po2 pu2 qt2)\n  apply(rename_tac n e1a q1 q2 A qs r po pu h qs2 r2 po2 pu2 qt2)(*strict*)\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__RL__edge_def)\n  apply(simp add: F_DPDA_OTS__get_state_def F_DPDA_OTS__edges_def)\n  apply(erule disjE)+\n    apply(rename_tac n e1a q1 q2 A qs r po pu h qs2 r2 po2 pu2 qt2)(*strict*)\n    apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n    apply(clarsimp)\n   apply(rename_tac n e1a q1 q2 A qs r po pu h qs2 r2 po2 pu2 qt2)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n   apply(clarsimp)\n  apply(rename_tac n e1a q1 q2 A qs r po pu h qs2 r2 po2 pu2 qt2)(*strict*)\n  apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  apply(clarsimp)\n  apply(rename_tac n e1a q1 q2 A qs r po pu h qs2 r2 po2 pu2 qt2 x)(*strict*)\n  apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  apply(clarsimp)\n  apply(rename_tac n e1a qs r po pu h qs2 r2 x)(*strict*)\n  apply(erule disjE)+\n   apply(rename_tac n e1a qs r po pu h qs2 r2 x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n e1a qs r r2 x)(*strict*)\n   apply(case_tac x)\n   apply(rename_tac n e1a qs r r2 x edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n e1a qs r r2 edge_src edge_event edge_pop edge_push edge_trg)(*strict*)\n   apply(simp add: option_to_list_def F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  apply(rename_tac n e1a qs r po pu h qs2 r2 x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n e1a qs r po pu h qs2 r2 x xa)(*strict*)\n  apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  done\n\nlemma F_DPDA_OTS__translateB__preserves__derivation_initial: \"\n  valid_dpda G\n  \\<Longrightarrow> epdaH.derivation_initial (F_DPDA_OTS G) d\n  \\<Longrightarrow> \\<forall>n. d n \\<noteq> None\n  \\<Longrightarrow> epdaH.derivation_initial G (DPDA_OTS__translate_back d)\"\n  apply(simp (no_asm) add: epdaH.derivation_initial_def)\n  apply(rule conjI)\n   apply(rule F_DPDA_OTS__translateB__preserves__derivation)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(simp add: DPDA_OTS__translate_back_def)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac\n      n=\"0\"\n      and m=\"Suc 0\"\n      in epdaH.step_detail_before_some_position)\n     apply(simp add: epdaH.derivation_initial_def)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac e1 e2 c1 c2)(*strict*)\n  apply(subgoal_tac \"c2 \\<in> epdaH_configurations (F_DPDA_OTS G)\")\n   apply(rename_tac e1 e2 c1 c2)(*strict*)\n   prefer 2\n   apply(rule epdaH.belongs_configurations)\n    apply(rename_tac e1 e2 c1 c2)(*strict*)\n    apply(rule epdaH.derivation_initial_belongs)\n     apply(rename_tac e1 e2 c1 c2)(*strict*)\n     apply(subgoal_tac \"X\" for X)\n      apply(rename_tac e1 e2 c1 c2)(*strict*)\n      prefer 2\n      apply(rule F_DPDA_OTS__preserves__PDA)\n       apply(rename_tac e1 e2 c1 c2)(*strict*)\n       apply(simp add: valid_dpda_def)\n       apply(force)\n      apply(rename_tac e1 e2 c1 c2)(*strict*)\n      apply(force)\n     apply(rename_tac e1 e2 c1 c2)(*strict*)\n     apply(simp add: valid_pda_def)\n    apply(rename_tac e1 e2 c1 c2)(*strict*)\n    apply(force)\n   apply(rename_tac e1 e2 c1 c2)(*strict*)\n   apply(force)\n  apply(rename_tac e1 e2 c1 c2)(*strict*)\n  apply(simp add: epdaH.derivation_initial_def)\n  apply(clarsimp)\n  apply(rename_tac e2 c1 c2)(*strict*)\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def epdaH_initial_configurations_def F_DPDA_OTS_def epdaH_configurations_def F_DPDA_OTS__states_def)\n  apply(clarsimp)\n  apply(rename_tac e2 q s h)(*strict*)\n  apply(erule_tac\n      P=\"cons_state_and_stack (epda_initial G) (epda_box G) \\<in> F_DPDA_OTS__states_auxiliary G\"\n      in disjE)\n   apply(rename_tac e2 q s h)(*strict*)\n   prefer 2\n   apply(simp add: F_DPDA_OTS__states_auxiliary_def F_DPDA_OTS__states_main_def)\n   apply(clarsimp)\n  apply(rename_tac e2 q s h)(*strict*)\n  apply(simp add: epdaH_step_relation_def F_DPDA_OTS__edges_def)\n  apply(clarsimp)\n  apply(rename_tac e2 w)(*strict*)\n  apply(erule_tac\n      P=\"e2 \\<in> F_DPDA_OTS__edges_main_auxiliary G\"\n      in disjE)\n   apply(rename_tac e2 w)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n   apply(clarsimp)\n  apply(rename_tac e2 w)(*strict*)\n  apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  apply(clarsimp)\n  apply(rename_tac w x)(*strict*)\n  apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_OTS__get_state_def F_DPDA_OTS__edges_def)\n  apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  done\n\ntheorem F_DPDA_OTS__preserves__no_livelock: \"\n  valid_dpda G\n  \\<Longrightarrow> \\<not> epdaH_livelock G\n  \\<Longrightarrow> \\<not> epdaH_livelock (F_DPDA_OTS G)\"\n  apply(simp add: epdaH_livelock_def)\n  apply(clarsimp)\n  apply(rename_tac d N)(*strict*)\n  apply(rule ccontr)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"DPDA_OTS__translate_back d\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac d N)(*strict*)\n   apply(rule F_DPDA_OTS__translateB__preserves__derivation_initial)\n     apply(rename_tac d N)(*strict*)\n     apply(force)\n    apply(rename_tac d N)(*strict*)\n    apply(force)\n   apply(rename_tac d N)(*strict*)\n   apply(force)\n  apply(rename_tac d N)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac d N)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d N n)(*strict*)\n   apply(simp add: DPDA_OTS__translate_back_def)\n   apply(case_tac n)\n    apply(rename_tac d N n)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d N n nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d N nat)(*strict*)\n   apply(case_tac \"d(Suc(nat+nat))\")\n    apply(rename_tac d N nat)(*strict*)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"Suc(nat+nat)\"\n      and P=\"\\<lambda>x. \\<exists>y. d x = Some y\"\n      in allE)\n    apply(force)\n   apply(rename_tac d N nat a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac d N nat a option b)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d N)(*strict*)\n  apply(erule_tac\n      x=\"N\"\n      and P=\"\\<lambda>N. \\<exists>n\\<ge>N. epdaH_conf_history (the (get_configuration (DPDA_OTS__translate_back d n))) \\<noteq> epdaH_conf_history (the (get_configuration (DPDA_OTS__translate_back d N)))\"\n      in allE)\n  apply(rename_tac d N)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d N n)(*strict*)\n  apply(simp add: DPDA_OTS__translate_back_def)\n  apply(case_tac n)\n   apply(rename_tac d N n)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d N n nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d N nat)(*strict*)\n  apply(case_tac N)\n   apply(rename_tac d N nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d nat)(*strict*)\n   apply(case_tac \"d 0\")\n    apply(rename_tac d nat)(*strict*)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"0\"\n      and P=\"\\<lambda>x. \\<exists>y. d x = Some y\"\n      in allE)\n    apply(force)\n   apply(rename_tac d nat a)(*strict*)\n   apply(case_tac \"d (Suc (nat + nat))\")\n    apply(rename_tac d nat a)(*strict*)\n    apply(clarsimp)\n    apply(erule_tac x=\"Suc (nat + nat)\" and P=\"\\<lambda>x. \\<exists>y. d x = Some y\"in allE)\n    apply(force)\n   apply(rename_tac d nat a aa)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac d nat a aa option b)(*strict*)\n   apply(case_tac aa)\n   apply(rename_tac d nat a aa option b optiona ba)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d nat option b optiona ba)(*strict*)\n   apply(case_tac optiona)\n    apply(rename_tac d nat option b optiona ba)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d nat option b ba)(*strict*)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac d nat option b ba)(*strict*)\n     prefer 2\n     apply(rule_tac\n      g=\"d\"\n      and n=\"Suc(nat+nat)\"\n      and m=\"Suc(nat+nat)\"\n      in epdaH.pre_some_position_is_some_position_prime)\n        apply(rename_tac d nat option b ba)(*strict*)\n        apply(rule epdaH.derivation_initial_is_derivation)\n        apply(force)\n       apply(rename_tac d nat option b ba)(*strict*)\n       apply(force)\n      apply(rename_tac d nat option b ba)(*strict*)\n      apply(force)\n     apply(rename_tac d nat option b ba)(*strict*)\n     apply(force)\n    apply(rename_tac d nat option b ba)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d nat option b optiona ba a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d nat option b ba a)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(erule_tac\n      x=\"Suc (nat+nat)\"\n      and P=\"\\<lambda>x. epdaH_conf_history (the (case d x of None \\<Rightarrow> None | Some (pair e c) \\<Rightarrow> Some c)) = epdaH_conf_history b\"\n      in allE)\n   apply(rename_tac d nat option b ba a)(*strict*)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def)\n  apply(rename_tac d N nat nata)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d nat nata)(*strict*)\n  apply(case_tac \"d (Suc (nat + nat))\")\n   apply(rename_tac d nat nata)(*strict*)\n   apply(clarsimp)\n   apply(erule_tac x=\"(Suc (nat + nat))\" and P=\"\\<lambda>x. \\<exists>y. d x = Some y\"in allE)\n   apply(force)\n  apply(rename_tac d nat nata a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac d nat nata a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d nat nata option b)(*strict*)\n  apply(case_tac \"d (Suc (nata + nata))\")\n   apply(rename_tac d nat nata option b)(*strict*)\n   apply(clarsimp)\n   apply(erule_tac x=\"(Suc (nata + nata))\" and P=\"\\<lambda>x. \\<exists>y. d x = Some y\"in allE)\n   apply(force)\n  apply(rename_tac d nat nata option b a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac d nat nata option b a optiona ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d nat nata option b optiona ba)(*strict*)\n  apply(case_tac optiona)\n   apply(rename_tac d nat nata option b optiona ba)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d nat nata option b ba)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d nat nata option b ba)(*strict*)\n    prefer 2\n    apply(rule_tac\n      g=\"d\"\n      and n=\"Suc(nata+nata)\"\n      and m=\"Suc(nata+nata)\"\n      in epdaH.pre_some_position_is_some_position_prime)\n       apply(rename_tac d nat nata option b ba)(*strict*)\n       apply(rule epdaH.derivation_initial_is_derivation)\n       apply(force)\n      apply(rename_tac d nat nata option b ba)(*strict*)\n      apply(force)\n     apply(rename_tac d nat nata option b ba)(*strict*)\n     apply(force)\n    apply(rename_tac d nat nata option b ba)(*strict*)\n    apply(force)\n   apply(rename_tac d nat nata option b ba)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d nat nata option b optiona ba a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d nat nata option b ba a)(*strict*)\n  apply(case_tac option)\n   apply(rename_tac d nat nata option b ba a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d nat nata b ba a)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d nat nata b ba a)(*strict*)\n    prefer 2\n    apply(rule_tac\n      g=\"d\"\n      and n=\"Suc(nat+nat)\"\n      and m=\"Suc(nat+nat)\"\n      in epdaH.pre_some_position_is_some_position_prime)\n       apply(rename_tac d nat nata b ba a)(*strict*)\n       apply(rule epdaH.derivation_initial_is_derivation)\n       apply(force)\n      apply(rename_tac d nat nata b ba a)(*strict*)\n      apply(force)\n     apply(rename_tac d nat nata b ba a)(*strict*)\n     apply(force)\n    apply(rename_tac d nat nata b ba a)(*strict*)\n    apply(force)\n   apply(rename_tac d nat nata b ba a)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d nat nata option b ba a aa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d nat nata b ba a aa)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(erule_tac\n      x=\"Suc (nat+nat)\"\n      and P=\"\\<lambda>x. Suc nata \\<le> x \\<longrightarrow> epdaH_conf_history (the (case d x of None \\<Rightarrow> None | Some (pair e c) \\<Rightarrow> Some c)) = epdaH_conf_history (the (case d (Suc nata) of None \\<Rightarrow> None | Some (pair e c) \\<Rightarrow> Some c))\"\n      in allE)\n  apply(rename_tac d nat nata b ba a aa)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d nat nata b ba a aa)(*strict*)\n   prefer 2\n   apply(rule_tac\n      g=\"d\"\n      and n=\"Suc nata\"\n      and m=\"Suc(nat+nat)\"\n      in epdaH.pre_some_position_is_some_position_prime)\n      apply(rename_tac d nat nata b ba a aa)(*strict*)\n      apply(rule epdaH.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac d nat nata b ba a aa)(*strict*)\n     apply(force)\n    apply(rename_tac d nat nata b ba a aa)(*strict*)\n    apply(force)\n   apply(rename_tac d nat nata b ba a aa)(*strict*)\n   apply(force)\n  apply(rename_tac d nat nata b ba a aa)(*strict*)\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def)\n  apply(clarsimp)\n  apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n   prefer 2\n   apply(rule F_DPDA_OTS__preserves__PDA)\n    apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n    apply(simp add: valid_dpda_def)\n    apply(force)\n   apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n   apply(force)\n  apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n  apply(simp add: valid_pda_def)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"d\"\n      and n=\"Suc nata\"\n      and m=\"nata\"\n      in epdaH.steps_extend_history_derivation)\n       apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n       apply(simp add: valid_dpda_def valid_pda_def)\n       apply(force)\n      apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n      apply(simp add: epdaH.derivation_initial_def)\n     apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n     prefer 2\n     apply(simp add: get_configuration_def)\n    apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n    apply(rule epdaH.belongs_configurations)\n     apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n      apply(force)\n     apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n     apply(force)\n    apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n    apply(force)\n   apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"d\"\n      and n=\"Suc (nata + nata)\"\n      and m=\"Suc (nat + nat)-Suc (nata + nata)\"\n      in epdaH.steps_extend_history_derivation)\n       apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n       apply(simp add: valid_dpda_def valid_pda_def)\n       apply(force)\n      apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n      apply(simp add: epdaH.derivation_initial_def)\n     apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n     prefer 2\n     apply(simp add: get_configuration_def)\n    apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n    apply(rule epdaH.belongs_configurations)\n     apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n     apply(rule epdaH.derivation_initial_belongs)\n      apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n      apply(force)\n     apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n     apply(force)\n    apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n    apply(force)\n   apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d nat nata b ba a aa e c)(*strict*)\n  apply(force)\n  done\n\ndefinition main_states_have_only_empty_steps :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> ('state \\<Rightarrow> bool)\n  \\<Rightarrow> bool\"\n  where\n    \"main_states_have_only_empty_steps R F \\<equiv>\n  \\<forall>q \\<in> epda_states R.\n    F q\n    \\<longrightarrow>\n      (\\<forall>e.\n        e \\<in> epda_delta R\n        \\<longrightarrow> edge_src e = q\n        \\<longrightarrow> edge_event e = None)\"\n\ntheorem F_DPDA_OTS__enforces__main_states_have_only_empty_steps: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> main_states_have_only_empty_steps R F_DPDA_OTS__is_main\"\n  apply(simp add: main_states_have_only_empty_steps_def F_DPDA_OTS__is_main_def)\n  apply(clarsimp)\n  apply(rename_tac e)(*strict*)\n  apply(case_tac \"edge_src e\")\n   apply(rename_tac e a b)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac e a)(*strict*)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def)\n  apply(erule disjE)\n   apply(rename_tac e a)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_1_def)\n   apply(clarsimp)\n  apply(rename_tac e a)(*strict*)\n  apply(simp add: F_DPDA_OTS__edges_auxiliary_main_def)\n  apply(clarsimp)\n  apply(rename_tac a x)(*strict*)\n  apply(simp add: F_DPDA_OTS__edges_auxiliary_main_1_def)\n  done\n\ndefinition main_states_have_all_empty_steps :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> ('state \\<Rightarrow> bool)\n  \\<Rightarrow> bool\"\n  where\n    \"main_states_have_all_empty_steps R F \\<equiv>\n  \\<forall>q \\<in> epda_states R.\n    F q\n    \\<longrightarrow>\n      (\\<forall>X \\<in> epda_gamma R.\n        \\<exists>e.\n          e \\<in> epda_delta R\n          \\<and> edge_src e = q\n          \\<and> edge_pop e = [X]\n          \\<and> edge_event e = None)\"\n\ntheorem F_DPDA_OTS__enforces__main_states_have_all_empty_steps: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> main_states_have_all_empty_steps R F_DPDA_OTS__is_main\"\n  apply(simp add: main_states_have_all_empty_steps_def F_DPDA_OTS__is_main_def)\n  apply(clarsimp)\n  apply(rename_tac q X)(*strict*)\n  apply(case_tac q)\n   apply(rename_tac q X a b)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac q X a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac X a)(*strict*)\n  apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def)\n  apply(rule_tac\n      x=\"\\<lparr>edge_src=cons_state a,edge_event=None,edge_pop=[X],edge_push=[X],edge_trg=cons_state_and_stack a X\\<rparr>\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac X a)(*strict*)\n   apply(rule disjI1)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_1_def)\n   apply(rule inMap)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_OTS__states_def)\n   apply(erule disjE)\n    apply(rename_tac X a)(*strict*)\n    apply(simp add: F_DPDA_OTS__states_auxiliary_def)\n    apply(clarsimp)\n   apply(rename_tac X a)(*strict*)\n   apply(simp add: F_DPDA_OTS__states_main_def)\n   apply(clarsimp)\n  apply(rename_tac X a)(*strict*)\n  apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  done\n\ndefinition executing_edge_from_auxiliary_to_main_state :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> ('state \\<Rightarrow> bool)\n  \\<Rightarrow> ('state \\<Rightarrow> bool)\n  \\<Rightarrow> bool\"\n  where\n    \"executing_edge_from_auxiliary_to_main_state R F1 F2 \\<equiv>\n  \\<forall>e.\n    e \\<in> epda_delta R\n    \\<longrightarrow> edge_event e \\<noteq> None\n    \\<longrightarrow> (F1 (edge_src e) \\<and> F2 (edge_trg e))\"\n\ntheorem F_DPDA_OTS__enforces__executing_edge_from_auxiliary_to_main_state: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> executing_edge_from_auxiliary_to_main_state R F_DPDA_OTS__is_auxiliary F_DPDA_OTS__is_main\"\n  apply(simp add: executing_edge_from_auxiliary_to_main_state_def)\n  apply(clarsimp)\n  apply(rename_tac e y)(*strict*)\n  apply(simp add: F_DPDA_OTS__is_main_def F_DPDA_OTS__is_auxiliary_def)\n  apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def)\n  apply(erule disjE)\n   apply(rename_tac e y)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_1_def)\n   apply(clarsimp)\n  apply(rename_tac e y)(*strict*)\n  apply(simp add: F_DPDA_OTS__edges_auxiliary_main_def)\n  apply(clarsimp)\n  apply(rename_tac y x)(*strict*)\n  apply(simp add: F_DPDA_OTS__edges_auxiliary_main_1_def)\n  done\n\ndefinition main_to_auxiliary_or_auxiliary_to_main :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> ('state \\<Rightarrow> bool)\n  \\<Rightarrow> bool\"\n  where\n    \"main_to_auxiliary_or_auxiliary_to_main R Fmain \\<equiv>\n  \\<forall>e \\<in> epda_delta R. Fmain (edge_src e) \\<longleftrightarrow> \\<not> Fmain (edge_trg e)\"\n\ntheorem F_DPDA_OTS__enforces__main_to_auxiliary_or_auxiliary_to_main: \"\n  valid_dpda M\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> main_to_auxiliary_or_auxiliary_to_main R F_DPDA_OTS__is_main\"\n  apply(simp add: main_to_auxiliary_or_auxiliary_to_main_def)\n  apply(clarsimp)\n  apply(rename_tac e)(*strict*)\n  apply(simp add: F_DPDA_OTS_def F_DPDA_OTS__edges_def)\n  apply(erule disjE)\n   apply(rename_tac e)(*strict*)\n   apply(simp add: F_DPDA_OTS__edges_main_auxiliary_def F_DPDA_OTS__edges_main_auxiliary_1_def)\n   apply(clarsimp)\n   apply(rename_tac a b)(*strict*)\n   apply(simp add: F_DPDA_OTS__is_main_def)\n  apply(rename_tac e)(*strict*)\n  apply(simp add: F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: F_DPDA_OTS__edges_auxiliary_main_def F_DPDA_OTS__edges_auxiliary_main_1_def)\n  apply(simp add: F_DPDA_OTS__is_main_def)\n  done\n\ntheorem F_DPDA_OTS__preserves__epdaH_reflection_to_DFA_exists: \"\n  valid_dpda M\n  \\<Longrightarrow> epdaH_reflection_to_DFA_exists M D F\n  \\<Longrightarrow> R = F_DPDA_OTS M\n  \\<Longrightarrow> epdaH_reflection_to_DFA_exists R D (F \\<circ> F_DPDA_OTS__get_state)\"\n  apply(simp add: epdaH_reflection_to_DFA_exists_def)\n  apply(clarsimp)\n  apply(rename_tac d n c)(*strict*)\n  apply(case_tac \"d n\")\n   apply(rename_tac d n c)(*strict*)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d n c a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac d n c a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d n c option b)(*strict*)\n  apply(subgoal_tac \"b=c\")\n   apply(rename_tac d n c option b)(*strict*)\n   prefer 2\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d n c option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d n c option)(*strict*)\n  apply(thin_tac \"get_configuration (Some (pair option c)) = Some c\")\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d n c option)(*strict*)\n   prefer 2\n   apply(rule_tac\n      ?G2.0=\"M\"\n      and ?G1.0=\"F_DPDA_OTS M\"\n      and ?d1.0=\"d\"\n      and x=\"n\"\n      in F_DPDA_OTS__epdaH_epdaH__RL.ATS_Simulation_Configuration_Weak_simulation_derivation_exists)\n     apply(rename_tac d n c option)(*strict*)\n     apply(simp add: F_DPDA_OTS__epdaH_epdaH__RL__TSstructure_def)\n    apply(rename_tac d n c option)(*strict*)\n    apply(force)\n   apply(rename_tac d n c option)(*strict*)\n   apply(force)\n  apply(rename_tac d n c option)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d n c option d2 n2)(*strict*)\n  apply(erule_tac\n      x=\"d2\"\n      in allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"n2\"\n      in allE)\n  apply(case_tac \"d2 n2\")\n   apply(rename_tac d n c option d2 n2)(*strict*)\n   apply(simp add: maximum_of_domain_def)\n  apply(rename_tac d n c option d2 n2 a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac d n c option d2 n2 a optiona b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d n c option d2 n2 optiona b)(*strict*)\n  apply(erule_tac\n      x=\"b\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac d n c option d2 n2 optiona b)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d n c option d2 n2 optiona b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d n c option d2 n2 optiona b d' m)(*strict*)\n  apply(rule_tac\n      x=\"d'\"\n      in exI)\n  apply(clarsimp)\n  apply(rule_tac\n      x=\"m\"\n      in exI)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_OTS__epdaH_epdaH__RL__configurations_def)\n  apply(clarsimp)\n  apply(simp add: get_configuration_def F_DPDA_OTS__epdaH_epdaH__LR__configuration1R_def)\n  done\n\ndefinition F_DPDA_OTS__SpecInput :: \"\n  (('stateA, 'stateB) DT_tuple2, 'event, 'stackA) epda\n  \\<Rightarrow> ('stateB, 'event, 'stackB) epda\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_OTS__SpecInput G D \\<equiv>\n  valid_dpda G\n  \\<and> nonblockingness_language (epdaH.unmarked_language G) (epdaH.marked_language G)\n  \\<and> \\<not> epdaH_livelock G\n  \\<and> epdaH_reflection_to_DFA_exists G D sel_tuple2_2\"\n\ndefinition F_DPDA_OTS__SpecOutput :: \"\n  (('stateA, 'stateB) DT_tuple2, 'event, 'stackA) epda\n  \\<Rightarrow> (('stateB, 'event, 'stackB) epda \\<times> 'event set)\n  \\<Rightarrow> ((('stateA, 'stateB) DT_tuple2, 'stackA) DT_state_and_stack_or_state, 'event, 'stackA) epda\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_OTS__SpecOutput Gi X Go \\<equiv>\n  case X of \n  (D, \\<Sigma>UC) \\<Rightarrow>\n    valid_dpda Go\n    \\<and> epdaH.marked_language Gi = epdaH.marked_language Go\n    \\<and> epdaH.unmarked_language Gi = epdaH.unmarked_language Go\n    \\<and> nonblockingness_language (epdaH.unmarked_language Go) (epdaH.marked_language Go)\n    \\<and> state_stack_unique_for_marking_states Go\n    \\<and> state_stack_unique_for_stable_states Go\n    \\<and> always_applicable_for_stable_states Go\n    \\<and> some_edge_applicable Go\n    \\<and> \\<not> epdaH_livelock Go\n    \\<and> epdaH_reflection_to_DFA_exists Go D (sel_tuple2_2 \\<circ> F_DPDA_OTS__get_state)\n    \\<and> corresponds_to_top_stack Go F_DPDA_OTS__is_auxiliary F_DPDA_OTS__get_stack\n    \\<and> main_states_have_only_empty_steps Go F_DPDA_OTS__is_main\n    \\<and> main_states_have_all_empty_steps Go F_DPDA_OTS__is_main\n    \\<and> executing_edge_from_auxiliary_to_main_state Go F_DPDA_OTS__is_auxiliary F_DPDA_OTS__is_main\n    \\<and> always_applicable_for_auxiliary_states Go F_DPDA_OTS__is_auxiliary\n    \\<and> main_to_auxiliary_or_auxiliary_to_main Go F_DPDA_OTS__is_main\" \n\n\ntheorem F_DPDA_OTS__SOUND: \"\n  F_DPDA_OTS__SpecInput G P\n  \\<Longrightarrow> F_DPDA_OTS__SpecOutput G (P, \\<Sigma>UC) (F_DPDA_OTS G)\"\n  apply(simp add: F_DPDA_OTS__SpecOutput_def F_DPDA_OTS__SpecInput_def)\n  apply(rule context_conjI)\n   apply (metis F_DPDA_OTS__preserves__DPDA)\n  apply(rule context_conjI)\n   apply (metis F_DPDA_OTS__equal__marked_language)\n  apply(rule context_conjI)\n   apply (metis F_DPDA_OTS__equal__unmarked_language)\n  apply(rule conjI)\n   apply(force)\n  apply(rule conjI)\n   apply (metis F_DPDA_OTS__enforces__state_stack_unique_for_marking_states)\n  apply(rule conjI)\n   apply (metis F_DPDA_OTS__enforces___state_stack_unique_for_stable_states)\n  apply(rule conjI)\n   apply(metis F_DPDA_OTS__enforces__always_applicable_for_stable_states)\n  apply(rule conjI)\n   apply(rule F_DPDA_OTS__enforces__some_edge_applicable)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(rule conjI)\n   apply(rule F_DPDA_OTS__preserves__no_livelock)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(rule F_DPDA_OTS__preserves__epdaH_reflection_to_DFA_exists)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(rule conjI)\n   apply(rule F_DPDA_OTS__enforces__corresponds_to_top_stack)\n    apply(force)\n   apply(force)\n  apply(rule conjI)\n   apply(rule F_DPDA_OTS__enforces__main_states_have_only_empty_steps)\n    apply(force)\n   apply(force)\n  apply(rule conjI)\n   apply(rule F_DPDA_OTS__enforces__main_states_have_all_empty_steps)\n    apply(force)\n   apply(force)\n  apply(rule conjI)\n   apply(rule F_DPDA_OTS__enforces__executing_edge_from_auxiliary_to_main_state)\n    apply(force)\n   apply(force)\n  apply(rule conjI)\n   apply(rule F_DPDA_OTS__enforces__always_applicable_for_auxiliary_states)\n    apply(force)\n   apply(force)\n  apply(rule F_DPDA_OTS__enforces__main_to_auxiliary_or_auxiliary_to_main)\n   apply(force)\n  apply(force)\n  done\n\nend\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_13_02/FUNCTION__DPDA_OTS__DPDA_OBSERVE_TOP_STACK.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331462646255, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.2726514902905039}}
{"text": "section {*L\\_ATS\\_Simulation\\_Configuration\\_WeakBRA*}\ntheory\n  L_ATS_Simulation_Configuration_WeakBRA\n\nimports\n  L_ATS_Simulation_Configuration_WeakDET\n\nbegin\n\nlocale ATS_Simulation_Configuration_WeakBRA =\n  ATS_Simulation_Configuration_WeakDET\n  \"TSstructure1 :: 'TSstructure1 \\<Rightarrow> bool\"\n  \"configurations1 :: 'TSstructure1 \\<Rightarrow> 'conf1 set\"\n  \"initial_configurations1 :: 'TSstructure1 \\<Rightarrow> 'conf1 set\"\n  \"step_labels1 :: 'TSstructure1 \\<Rightarrow> 'label1 set\"\n  \"step_relation1 :: 'TSstructure1 \\<Rightarrow> 'conf1 \\<Rightarrow> 'label1 \\<Rightarrow> 'conf1 \\<Rightarrow> bool\"\n  \"effects1 :: 'TSstructure1 \\<Rightarrow> 'event1 set\"\n  \"marking_condition1 :: 'TSstructure1 \\<Rightarrow> ('label1,'conf1)derivation \\<Rightarrow> bool\"\n  \"marked_effect1 :: 'TSstructure1 \\<Rightarrow> ('label1,'conf1)derivation \\<Rightarrow> 'event1 set\"\n  \"unmarked_effect1 :: 'TSstructure1 \\<Rightarrow> ('label1,'conf1)derivation \\<Rightarrow> 'event1 set\"\n  \"TSstructure2 :: 'TSstructure2 \\<Rightarrow> bool\"\n  \"configurations2 :: 'TSstructure2 \\<Rightarrow> 'conf2 set\"\n  \"initial_configurations2 :: 'TSstructure2 \\<Rightarrow> 'conf2 set\"\n  \"step_labels2 :: 'TSstructure2 \\<Rightarrow> 'label2 set\"\n  \"step_relation2 :: 'TSstructure2 \\<Rightarrow> 'conf2 \\<Rightarrow> 'label2 \\<Rightarrow> 'conf2 \\<Rightarrow> bool\"\n  \"effects2 :: 'TSstructure2 \\<Rightarrow> 'event2 set\"\n  \"marking_condition2 :: 'TSstructure2 \\<Rightarrow> ('label2,'conf2)derivation \\<Rightarrow> bool\"\n  \"marked_effect2 :: 'TSstructure2 \\<Rightarrow> ('label2,'conf2)derivation \\<Rightarrow> 'event2 set\"\n  \"unmarked_effect2 :: 'TSstructure2 \\<Rightarrow> ('label2,'conf2)derivation \\<Rightarrow> 'event2 set\"\n  \"relation_configurationLR :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'conf1 \\<Rightarrow> 'conf2 \\<Rightarrow> bool\"\n  \"relation_initial_configurationLR :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'conf1 \\<Rightarrow> 'conf2 \\<Rightarrow> bool\"\n  \"relation_effectLR :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'event1 \\<Rightarrow> 'event2 \\<Rightarrow> bool\"\n  \"relation_TSstructureLR :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> bool\"\n  \"relation_initial_simulationLR :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'conf1 \\<Rightarrow> (nat \\<Rightarrow> ('label2, 'conf2) derivation_configuration option) \\<Rightarrow> bool\"\n  \"relation_step_simulationLR :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'conf1 \\<Rightarrow> 'label1 \\<Rightarrow> 'conf1 \\<Rightarrow> 'conf2 \\<Rightarrow> (nat \\<Rightarrow> ('label2, 'conf2) derivation_configuration option) \\<Rightarrow> bool\"\n  \"relation_configurationRL :: 'TSstructure2 \\<Rightarrow> 'TSstructure1 \\<Rightarrow> 'conf2 \\<Rightarrow> 'conf1 \\<Rightarrow> bool\"\n  \"relation_initial_configurationRL :: 'TSstructure2 \\<Rightarrow> 'TSstructure1 \\<Rightarrow> 'conf2 \\<Rightarrow> 'conf1 \\<Rightarrow> bool\"\n  \"relation_effectRL :: 'TSstructure2 \\<Rightarrow> 'TSstructure1 \\<Rightarrow> 'event2 \\<Rightarrow> 'event1 \\<Rightarrow> bool\"\n  \"relation_TSstructureRL :: 'TSstructure2 \\<Rightarrow> 'TSstructure1 \\<Rightarrow> bool\"\n  \"relation_initial_simulationRL :: 'TSstructure2 \\<Rightarrow> 'TSstructure1 \\<Rightarrow> 'conf2 \\<Rightarrow> (nat \\<Rightarrow> ('label1, 'conf1) derivation_configuration option) \\<Rightarrow> bool\"\n  \"relation_step_simulationRL :: 'TSstructure2 \\<Rightarrow> 'TSstructure1 \\<Rightarrow> 'conf2 \\<Rightarrow> 'label2 \\<Rightarrow> 'conf2 \\<Rightarrow> 'conf1 \\<Rightarrow> (nat \\<Rightarrow> ('label1, 'conf1) derivation_configuration option) \\<Rightarrow> bool\"\n  \"label_relation :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'label1 \\<Rightarrow> 'label2 \\<Rightarrow> bool\"\n  for\n    TSstructure1 configurations1 initial_configurations1 step_labels1 step_relation1 effects1 marking_condition1 marked_effect1 unmarked_effect1 TSstructure2 configurations2 initial_configurations2 step_labels2 step_relation2 effects2 marking_condition2 marked_effect2 unmarked_effect2 relation_configurationLR relation_initial_configurationLR relation_effectLR relation_TSstructureLR relation_initial_simulationLR relation_step_simulationLR relation_configurationRL relation_initial_configurationRL relation_effectRL relation_TSstructureRL relation_initial_simulationRL relation_step_simulationRL label_relation\n    +\n\nassumes AX_relation_configuration_inverse: \"\n  relation_TSstructureLR G1 G2\n  \\<Longrightarrow> relation_configurationRL G2 G1 c2 c1\n  \\<Longrightarrow> relation_configurationLR G1 G2 c1 c2\"\n\nassumes AX_marking_condition_translation: \"\n  relation_TSstructureRL G2 G1\n  \\<Longrightarrow> relation_TSstructureLR G1 G2\n  \\<Longrightarrow> LR.GR.derivation_initial G2 dR\n  \\<Longrightarrow> maximum_of_domain dR nR\n  \\<Longrightarrow> dR nR = Some (pair enR cnR)\n  \\<Longrightarrow> LR.GL.derivation_initial G1 dL\n  \\<Longrightarrow> maximum_of_domain dL nL\n  \\<Longrightarrow> relation_initial_configurationRL G2 G1 c0R c0L\n  \\<Longrightarrow> relation_configurationRL G2 G1 cnR cnL\n  \\<Longrightarrow> dR 0 = Some (pair None c0R)\n  \\<Longrightarrow> dL 0 = Some (pair None c0L)\n  \\<Longrightarrow> dL nL = Some (pair enL cnL)\n  \\<Longrightarrow> LR.GL.derivation G1 dL2\n  \\<Longrightarrow> LR.GL.belongs G1 dL2\n  \\<Longrightarrow> maximum_of_domain dL2 nL2\n  \\<Longrightarrow> marking_condition1 G1 (derivation_append dL dL2 nL)\n  \\<Longrightarrow> dL2 0 = Some (pair None cnL)\n  \\<Longrightarrow> relation_configurationLR G1 G2 cnL cnR\n  \\<Longrightarrow> dL2 nL2 = Some (pair e2nL c2nL)\n  \\<Longrightarrow> LR.GR.derivation G2 d2R\n  \\<Longrightarrow> LR.GR.belongs G2 d2R\n  \\<Longrightarrow> maximum_of_domain d2R n2R\n  \\<Longrightarrow> relation_configurationLR G1 G2 c2nL cn2R\n  \\<Longrightarrow> d2R 0 = Some (pair None cnR)\n  \\<Longrightarrow> d2R n2R = Some (pair en2R cn2R)\n  \\<Longrightarrow> marking_condition2 G2 (derivation_append dR d2R nR)\"\n\ncontext ATS_Simulation_Configuration_WeakBRA begin\n\ntheorem Nonblockingness_branching_is_preserved: \"\n  relation_TSstructureRL G2 G1\n  \\<Longrightarrow> relation_TSstructureLR G1 G2\n  \\<Longrightarrow> LR.GL.Nonblockingness_branching G1\n  \\<Longrightarrow> LR.GR.Nonblockingness_branching G2\"\n  apply(simp add: LR.GR.Nonblockingness_branching_def)\n  apply(clarsimp)\n  apply(rename_tac dh n)(*strict*)\n  apply(rename_tac dR nR)\n  apply(rename_tac dR nR)(*strict*)\n  apply(subgoal_tac \"\\<exists>enR cnR. dR nR = Some (pair enR cnR)\")\n  apply(rename_tac dR nR)(*strict*)\n  prefer 2\n  apply(rule LR.GR.some_position_has_details_before_max_dom)\n  apply(rename_tac dR nR)(*strict*)\n  apply(rule LR.GR.derivation_initial_is_derivation)\n  apply(force)\n  apply(rename_tac dR nR)(*strict*)\n  apply(force)\n  apply(rename_tac dR nR)(*strict*)\n  apply(force)\n  apply(rename_tac dR nR)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac dR nR enR cnR)(*strict*)\n  apply(subgoal_tac \"\\<exists>d2 n2. LR.GL.derivation_initial G1 d2 \\<and> maximum_of_domain d2 n2 \\<and> relation_initial_configurationRL G2 G1 (the (get_configuration (dR 0))) (the (get_configuration (d2 0))) \\<and> relation_configurationRL G2 G1 cnR (the (get_configuration (d2 n2)))\")\n  apply(rename_tac dR nR enR cnR)(*strict*)\n  prefer 2\n  apply(rule RL.ATS_Simulation_Configuration_Weak_simulation_derivation_exists)\n  apply(rename_tac dR nR enR cnR)(*strict*)\n  apply(force)\n  apply(rename_tac dR nR enR cnR)(*strict*)\n  apply(force)\n  apply(rename_tac dR nR enR cnR)(*strict*)\n  apply(force)\n  apply(rename_tac dR nR enR cnR)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac dR nR enR cnR d2 n2)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(subgoal_tac \"\\<exists>c. dR 0 = Some (pair None c)\")\n  apply(rename_tac dR nR enR cnR d2 n2)(*strict*)\n   prefer 2\n   apply (metis LR.GR.derivation_initial_is_derivation LR.GR.some_position_has_details_at_0)\n  apply(rename_tac dR nR enR cnR d2 n2)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. d2 0 = Some (pair None c)\")\n   apply(rename_tac dR nR enR cnR d2 n2)(*strict*)\n   prefer 2\n   apply (metis LR.GL.derivation_initial_is_derivation LR.GL.some_position_has_details_at_0)\n  apply(rename_tac dR nR enR cnR d2 n2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac dR nR enR cnR d2 n2 c ca)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d2 n2 = Some (pair e c)\")\n   apply(rename_tac dR nR enR cnR d2 n2 c ca)(*strict*)\n   prefer 2\n   apply(rule LR.GL.some_position_has_details_before_max_dom)\n     apply(rename_tac dR nR enR cnR d2 n2 c ca)(*strict*)\n     apply(rule LR.GL.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac dR nR enR cnR d2 n2 c ca)(*strict*)\n    apply(force)\n   apply(rename_tac dR nR enR cnR d2 n2 c ca)(*strict*)\n   apply(force)\n  apply(rename_tac dR nR enR cnR d2 n2 c ca)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac dR nR enR cnR d2 n2 c ca e cb)(*strict*)\n  apply(rename_tac dL nL c0R c0L enL cnL)\n  apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL)(*strict*)\n  apply(simp add: LR.GL.Nonblockingness_branching_def)\n  apply(erule_tac\n      x=\"dL\"\n      in allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"nL\"\n      in allE)\n  apply(clarsimp)\n  apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dc x)(*strict*)\n  apply(rename_tac dL2 nL2)\n  apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. dL2 0 =Some (pair None c)\")\n   apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2)(*strict*)\n   prefer 2\n   apply (metis LR.GL.some_position_has_details_at_0)\n  apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2 c)(*strict*)\n  apply(subgoal_tac \"relation_configurationLR G1 G2 cnL cnR\")\n   apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2 c)(*strict*)\n   prefer 2\n   apply(rule AX_relation_configuration_inverse)\n    apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2 c)(*strict*)\n    apply(force)\n   apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2 c)(*strict*)\n   apply(force)\n  apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2 c)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. dL2 nL2= Some (pair e c)\")\n   apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2 c)(*strict*)\n   prefer 2\n   apply(rule LR.GL.some_position_has_details_before_max_dom)\n     apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2 c)(*strict*)\n     apply(force)\n    apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2 c)(*strict*)\n    apply(force)\n   apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2 c)(*strict*)\n   apply(force)\n  apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2 c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2 c e ca)(*strict*)\n  apply(subgoal_tac \"\\<exists>d2 n2. LR.GR.derivation G2 d2 \\<and> LR.GR.belongs G2 d2 \\<and> maximum_of_domain d2 n2 \\<and> the (get_configuration (d2 0)) = cnR \\<and> relation_configurationLR G1 G2 (the (get_configuration (dL2 0))) (the (get_configuration (d2 0))) \\<and> relation_configurationLR G1 G2 ca (the (get_configuration (d2 n2)))\")\n   apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2 c e ca)(*strict*)\n   prefer 2\n   apply(rule LR.ATS_Simulation_Configuration_Weak_simulation_derivation_exists_witness2)\n         apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2 c e ca)(*strict*)\n         apply(force)\n        apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2 c e ca)(*strict*)\n        apply(force)\n       apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2 c e ca)(*strict*)\n       apply(force)\n      apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2 c e ca)(*strict*)\n      apply(simp add: derivation_append_fit_def)\n     apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2 c e ca)(*strict*)\n     apply(simp add: derivation_append_fit_def)\n    apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2 c e ca)(*strict*)\n    apply(simp add: derivation_append_fit_def)\n    apply (metis LR.GR.belongs_configurations LR.GR.derivation_initial_belongs LR.AX_TSstructure_relation_TSstructure2_belongs)\n   apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2 c e ca)(*strict*)\n   apply(simp add: derivation_append_fit_def)\n  apply(rename_tac dR nR enR cnR dL nL c0R c0L enL cnL dL2 nL2 c e ca)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac dR nR enR dL nL c0R c0L enL cnL dL2 nL2 c e ca d2 n2)(*strict*)\n  apply(rule_tac\n      x=\"d2\"\n      in exI)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(rename_tac dR nR enR dL nL c0R c0L enL cnL dL2 nL2 c e ca d2 n2)(*strict*)\n   apply(force)\n  apply(rename_tac dR nR enR dL nL c0R c0L enL cnL dL2 nL2 c e ca d2 n2)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. d2 0 = Some (pair None c)\")\n   apply(rename_tac dR nR enR dL nL c0R c0L enL cnL dL2 nL2 c e ca d2 n2)(*strict*)\n   prefer 2\n   apply (metis LR.GR.some_position_has_details_at_0)\n  apply(rename_tac dR nR enR dL nL c0R c0L enL cnL dL2 nL2 c e ca d2 n2)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d2 n2 = Some (pair e c)\")\n   apply(rename_tac dR nR enR dL nL c0R c0L enL cnL dL2 nL2 c e ca d2 n2)(*strict*)\n   prefer 2\n   apply(rule LR.GR.some_position_has_details_before_max_dom)\n     apply(rename_tac dR nR enR dL nL c0R c0L enL cnL dL2 nL2 c e ca d2 n2)(*strict*)\n     apply(force)\n    apply(rename_tac dR nR enR dL nL c0R c0L enL cnL dL2 nL2 c e ca d2 n2)(*strict*)\n    apply(force)\n   apply(rename_tac dR nR enR dL nL c0R c0L enL cnL dL2 nL2 c e ca d2 n2)(*strict*)\n   apply(force)\n  apply(rename_tac dR nR enR dL nL c0R c0L enL cnL dL2 nL2 c e ca d2 n2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac dR nR enR dL nL c0R c0L enL cnL dL2 nL2 c e ca d2 n2 cb ea cc)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac dR nR enR dL nL c0R c0L enL cnL dL2 nL2 c e ca d2 n2 cb ea cc)(*strict*)\n   apply(simp add: derivation_append_fit_def)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac dR nR enR dL nL c0R c0L enL cnL dL2 nL2 c e ca d2 n2 cb ea cc)(*strict*)\n  apply(simp add: derivation_append_fit_def)\n  apply(clarsimp)\n  apply(rename_tac dR nR enR dL nL c0R c0L enL dL2 nL2 c e ca d2 n2 cb ea cc)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(rename_tac cnL e2nL c2nL d2R n2R cnR en2R cn2R)\n  apply(rename_tac dR nR enR dL nL c0R c0L enL dL2 nL2 cnL e2nL c2nL d2R n2R cnR en2R cn2R)(*strict*)\n  apply(rule AX_marking_condition_translation)\n                      apply(rename_tac dR nR enR dL nL c0R c0L enL dL2 nL2 cnL e2nL c2nL d2R n2R cnR en2R cn2R)(*strict*)\n                      apply(force)+\n  done\n\nend\n\nend\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_06_06/L_ATS_Simulation_Configuration_WeakBRA.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331462646254, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.27265149029050384}}
{"text": "(*  Title:      HOL/Auth/Guard/Guard_Public.thy\n    Author:     Frederic Blanqui, University of Cambridge Computer Laboratory\n    Copyright   2002  University of Cambridge\n\nLemmas on guarded messages for public protocols.\n*)\n\ntheory Guard_Public imports Guard \"../Public\" Extensions begin\n\nsubsection{*Extensions to Theory @{text Public}*}\n\ndeclare initState.simps [simp del]\n\nsubsubsection{*signature*}\n\ndefinition sign :: \"agent => msg => msg\" where\n\"sign A X == {|Agent A, X, Crypt (priK A) (Hash X)|}\"\n\nlemma sign_inj [iff]: \"(sign A X = sign A' X') = (A=A' & X=X')\"\nby (auto simp: sign_def)\n\nsubsubsection{*agent associated to a key*}\n\ndefinition agt :: \"key => agent\" where\n\"agt K == @A. K = priK A | K = pubK A\"\n\nlemma agt_priK [simp]: \"agt (priK A) = A\"\nby (simp add: agt_def)\n\nlemma agt_pubK [simp]: \"agt (pubK A) = A\"\nby (simp add: agt_def)\n\nsubsubsection{*basic facts about @{term initState}*}\n\nlemma no_Crypt_in_parts_init [simp]: \"Crypt K X ~:parts (initState A)\"\nby (cases A, auto simp: initState.simps)\n\nlemma no_Crypt_in_analz_init [simp]: \"Crypt K X ~:analz (initState A)\"\nby auto\n\nlemma no_priK_in_analz_init [simp]: \"A ~:bad\n==> Key (priK A) ~:analz (initState Spy)\"\nby (auto simp: initState.simps)\n\nlemma priK_notin_initState_Friend [simp]: \"A ~= Friend C\n==> Key (priK A) ~: parts (initState (Friend C))\"\nby (auto simp: initState.simps)\n\nlemma keyset_init [iff]: \"keyset (initState A)\"\nby (cases A, auto simp: keyset_def initState.simps)\n\nsubsubsection{*sets of private keys*}\n\ndefinition priK_set :: \"key set => bool\" where\n\"priK_set Ks == ALL K. K:Ks --> (EX A. K = priK A)\"\n\nlemma in_priK_set: \"[| priK_set Ks; K:Ks |] ==> EX A. K = priK A\"\nby (simp add: priK_set_def)\n\nlemma priK_set1 [iff]: \"priK_set {priK A}\"\nby (simp add: priK_set_def)\n\nlemma priK_set2 [iff]: \"priK_set {priK A, priK B}\"\nby (simp add: priK_set_def)\n\nsubsubsection{*sets of good keys*}\n\ndefinition good :: \"key set => bool\" where\n\"good Ks == ALL K. K:Ks --> agt K ~:bad\"\n\nlemma in_good: \"[| good Ks; K:Ks |] ==> agt K ~:bad\"\nby (simp add: good_def)\n\nlemma good1 [simp]: \"A ~:bad ==> good {priK A}\"\nby (simp add: good_def)\n\nlemma good2 [simp]: \"[| A ~:bad; B ~:bad |] ==> good {priK A, priK B}\"\nby (simp add: good_def)\n\nsubsubsection{*greatest nonce used in a trace, 0 if there is no nonce*}\n\nprimrec greatest :: \"event list => nat\"\nwhere\n  \"greatest [] = 0\"\n| \"greatest (ev # evs) = max (greatest_msg (msg ev)) (greatest evs)\"\n\nlemma greatest_is_greatest: \"Nonce n:used evs ==> n <= greatest evs\"\napply (induct evs, auto simp: initState.simps)\napply (drule used_sub_parts_used, safe)\napply (drule greatest_msg_is_greatest, arith)\nby simp\n\nsubsubsection{*function giving a new nonce*}\n\ndefinition new :: \"event list => nat\" where\n\"new evs == Suc (greatest evs)\"\n\nlemma new_isnt_used [iff]: \"Nonce (new evs) ~:used evs\"\nby (clarify, drule greatest_is_greatest, auto simp: new_def)\n\nsubsection{*Proofs About Guarded Messages*}\n\nsubsubsection{*small hack necessary because priK is defined as the inverse of pubK*}\n\nlemma pubK_is_invKey_priK: \"pubK A = invKey (priK A)\"\nby simp\n\nlemmas pubK_is_invKey_priK_substI = pubK_is_invKey_priK [THEN ssubst]\n\nlemmas invKey_invKey_substI = invKey [THEN ssubst]\n\nlemma \"Nonce n:parts {X} ==> Crypt (pubK A) X:guard n {priK A}\"\napply (rule pubK_is_invKey_priK_substI, rule invKey_invKey_substI)\nby (rule Guard_Nonce, simp+)\n\nsubsubsection{*guardedness results*}\n\nlemma sign_guard [intro]: \"X:guard n Ks ==> sign A X:guard n Ks\"\nby (auto simp: sign_def)\n\nlemma Guard_init [iff]: \"Guard n Ks (initState B)\"\nby (induct B, auto simp: Guard_def initState.simps)\n\nlemma Guard_knows_max': \"Guard n Ks (knows_max' C evs)\n==> Guard n Ks (knows_max C evs)\"\nby (simp add: knows_max_def)\n\nlemma Nonce_not_used_Guard_spies [dest]: \"Nonce n ~:used evs\n==> Guard n Ks (spies evs)\"\nby (auto simp: Guard_def dest: not_used_not_known parts_sub)\n\nlemma Nonce_not_used_Guard [dest]: \"[| evs:p; Nonce n ~:used evs;\nGets_correct p; one_step p |] ==> Guard n Ks (knows (Friend C) evs)\"\nby (auto simp: Guard_def dest: known_used parts_trans)\n\nlemma Nonce_not_used_Guard_max [dest]: \"[| evs:p; Nonce n ~:used evs;\nGets_correct p; one_step p |] ==> Guard n Ks (knows_max (Friend C) evs)\"\nby (auto simp: Guard_def dest: known_max_used parts_trans)\n\nlemma Nonce_not_used_Guard_max' [dest]: \"[| evs:p; Nonce n ~:used evs;\nGets_correct p; one_step p |] ==> Guard n Ks (knows_max' (Friend C) evs)\"\napply (rule_tac H=\"knows_max (Friend C) evs\" in Guard_mono)\nby (auto simp: knows_max_def)\n\nsubsubsection{*regular protocols*}\n\ndefinition regular :: \"event list set => bool\" where\n\"regular p == ALL evs A. evs:p --> (Key (priK A):parts (spies evs)) = (A:bad)\"\n\nlemma priK_parts_iff_bad [simp]: \"[| evs:p; regular p |] ==>\n(Key (priK A):parts (spies evs)) = (A:bad)\"\nby (auto simp: regular_def)\n\nlemma priK_analz_iff_bad [simp]: \"[| evs:p; regular p |] ==>\n(Key (priK A):analz (spies evs)) = (A:bad)\"\nby auto\n\nlemma Guard_Nonce_analz: \"[| Guard n Ks (spies evs); evs:p;\npriK_set Ks; good Ks; regular p |] ==> Nonce n ~:analz (spies evs)\"\napply (clarify, simp only: knows_decomp)\napply (drule Guard_invKey_keyset, simp+, safe)\napply (drule in_good, simp)\napply (drule in_priK_set, simp+, clarify)\napply (frule_tac A=A in priK_analz_iff_bad)\nby (simp add: knows_decomp)+\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/Auth/Guard/Guard_Public.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331319177487, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.27265148373201975}}
{"text": "\\<^marker>\\<open>creator \"Maximilian P. L. Haslbeck\"\\<close>\n\\<^marker>\\<open>contributor \"Peter Lammich\"\\<close>\nsection \\<open>More theory on NREST\\<close>\ntheory NREST_Main\n  imports NREST NREST_Type_Classes  Time_Refinement Data_Refinement\n     NREST_Backwards_Reasoning NREST_Automation\nbegin\n        \n\nparagraph \\<open>Summary\\<close>\ntext \\<open>This theory introduces more convenience lemmas on NREST\\<close>\n\n\nsubsection \\<open>Convenience Lemmas\\<close>\n\n\nlemma If_le_rule: \"(c \\<Longrightarrow> x \\<le> a) \\<Longrightarrow> (~c \\<Longrightarrow> x \\<le> b) \\<Longrightarrow> x \\<le> (if c then a else b)\"\n  by auto\n\nlemma If_le_Some_rule2: \"(c \\<Longrightarrow> x \\<le> a) \\<Longrightarrow> c \\<Longrightarrow> Some x \\<le> (if c then Some a else None)\"\n  by auto\n\nterm inres\nsubsection \\<open>Interaction between Currency Refinement and Data Refinement\\<close>\n                   \nlemma timerefine_R_cf_mono:\n  fixes R :: \"_ \\<Rightarrow> (_, enat) acost\"\n  assumes \"wfR'' R'\"\n  shows \"R\\<le>R' \\<Longrightarrow> \\<Down> S (\\<Down>\\<^sub>C R c) \\<le> \\<Down> S (\\<Down>\\<^sub>C R' c)\"\n  by (simp add: assms nrest_Rel_mono timerefine_R_mono_wfR'')\n\n\nlemma inresT_project_acost_timerefine: \"inresT (project_acost b (\\<Down>\\<^sub>C E m')) x' t \n       \\<Longrightarrow> \\<exists>t b. inresT (project_acost b m') x' t\"\n  unfolding inresT_def project_acost_def timerefine_def\n  apply(cases m'; auto simp: le_fun_def split: if_splits option.splits)\n  by (metis zero_enat_def zero_le)  \n\n\nlemma bindT_refine_conc_time:\n  fixes m :: \"('e1,('c1,enat)acost) nrest\"\n  fixes m' :: \"('e2,('c2,enat)acost) nrest\"\n  assumes \"wfR E\" \" m \\<le> \\<Down>R' (\\<Down>\\<^sub>C E m')\"\n  \"(\\<And>x x'. \\<lbrakk>(x,x')\\<in>R';  \\<exists>t b. inresT (project_acost b m) x t;  \\<exists>t b. inresT (project_acost b m') x' t;\n    nofailT m; nofailT m'\\<rbrakk> \\<Longrightarrow> f x \\<le> \\<Down> R (\\<Down>\\<^sub>C E (f' x') ))\"\nshows \"bindT m f \\<le>  \\<Down> R (\\<Down>\\<^sub>C E (bindT m' f'))\"\n  using assms\nproof -\n  term \"(\\<Down>\\<^sub>C E m')\"\n  term timerefine\n  have \"bindT m (\\<lambda>x.  (f x)) \\<le>  \\<Down> R (bindT (\\<Down>\\<^sub>C E m') (\\<lambda>x. \\<Down>\\<^sub>C E (f' x)))\"\n    apply(rule bindT_conc_acost_refine') apply(rule assms(2)) \n    apply(rule assms(3))  \n    by (auto simp: refine_pw_simps dest: inresT_project_acost_timerefine) \n  also have \"\\<dots> \\<le> \\<Down> R (\\<Down>\\<^sub>C E (bindT m' f'))\"\n    apply(rule nrest_Rel_mono)\n    apply(rule timerefine_bindT_ge) by(fact assms(1))\n  finally show ?thesis .\nqed\nlemma bindT_refine_conc_time2:\n  fixes m :: \"('e1,('c1,enat)acost) nrest\"\n  fixes m' :: \"('e2,('c2,enat)acost) nrest\"\n  assumes \"wfR'' E\" \" m \\<le> \\<Down>R' (\\<Down>\\<^sub>C E m')\"\n  \"(\\<And>x x'. \\<lbrakk>(x,x')\\<in>R';  \\<exists>t b. inresT (project_acost b m) x t;  \\<exists>t b. inresT (project_acost b m') x' t;\n    nofailT m; nofailT m'\\<rbrakk> \\<Longrightarrow> f x \\<le> \\<Down> R (\\<Down>\\<^sub>C E (f' x') ))\"\nshows \"bindT m f \\<le>  \\<Down> R (\\<Down>\\<^sub>C E (bindT m' f'))\"\n  using assms\nproof -\n  term \"(\\<Down>\\<^sub>C E m')\"\n  term timerefine\n  have \"bindT m (\\<lambda>x.  (f x)) \\<le>  \\<Down> R (bindT (\\<Down>\\<^sub>C E m') (\\<lambda>x. \\<Down>\\<^sub>C E (f' x)))\"\n    apply(rule bindT_conc_acost_refine') apply(rule assms(2)) \n    apply(rule assms(3))  \n    by (auto simp: refine_pw_simps dest: inresT_project_acost_timerefine) \n  also have \"\\<dots> \\<le> \\<Down> R (\\<Down>\\<^sub>C E (bindT m' f'))\"\n    apply(rule nrest_Rel_mono)\n    apply(rule timerefine_bindT_ge2) by(fact assms(1))\n  finally show ?thesis .\nqed\n\n\n\nlemma bindT_refine_conc_time_my:\n  fixes m :: \"('e1,('c1,enat)acost) nrest\"\n  fixes m' :: \"('e2,('c2,enat)acost) nrest\"\n  assumes \"wfR'' E\" \" m \\<le> \\<Down>R' (\\<Down>\\<^sub>C E m')\"\n  \"(\\<And>x x'. \\<lbrakk>(x,x')\\<in>R'; \\<exists>t b. inresT (project_acost b m') x' t\\<rbrakk>\n         \\<Longrightarrow> f x \\<le> \\<Down> R (\\<Down>\\<^sub>C E (f' x') ))\"\nshows \"bindT m f \\<le>  \\<Down> R (\\<Down>\\<^sub>C E (bindT m' f'))\"\n  apply(rule bindT_refine_conc_time2) using assms by auto\n\n\n\nlemma timerefine_conc_fun_ge:\n  fixes C :: \"('f, ('b, enat) acost) nrest\"\n  assumes \"wfR E\"\n  shows \"\\<Down>\\<^sub>C E (\\<Down> R C) \\<ge> \\<Down>R (\\<Down>\\<^sub>C E C)\"\n\n  unfolding conc_fun_def timerefine_def\n  apply(cases C) apply auto apply(rule le_funI)\n  apply(rule Sup_least)\n  apply (auto split: option.splits)\n  subgoal \n    by (metis (mono_tags, lifting) Sup_upper less_eq_option_Some_None mem_Collect_eq)\n  unfolding less_eq_acost_def apply auto\n  apply(rule Sum_any_mono)\n  apply(rule mult_right_mono)\n  subgoal     \n    by (metis (mono_tags, lifting) Sup_upper less_eq_option_Some mem_Collect_eq the_acost_mono)\n    apply simp\n  apply(rule wfR_finite_mult_left )\n  using assms by simp\n\n\nlemma timerefine_conc_fun_ge2:\n  fixes C :: \"('f, ('b, enat) acost) nrest\"\n  assumes \"wfR'' E\"\n  shows \"\\<Down>\\<^sub>C E (\\<Down> R C) \\<ge> \\<Down>R (\\<Down>\\<^sub>C E C)\"\n\n  unfolding conc_fun_def timerefine_def\n  apply(cases C) apply auto apply(rule le_funI)\n  apply(rule Sup_least)\n  apply (auto split: option.splits)\n  subgoal \n    by (metis (mono_tags, lifting) Sup_upper less_eq_option_Some_None mem_Collect_eq)\n  unfolding less_eq_acost_def apply auto\n  apply(rule Sum_any_mono)\n  apply(rule mult_right_mono)\n  subgoal     \n    by (metis (mono_tags, lifting) Sup_upper less_eq_option_Some mem_Collect_eq the_acost_mono)\n    apply simp\n  apply(rule wfR_finite_mult_left2 )\n  using assms by simp\n\n\nlemma timerefine_conc_fun_le2:\n  assumes \"continuous E\"\n  shows \"timerefine' E (\\<Down> R C) = \\<Down>R (timerefine' E C)\"\n  unfolding timerefine'_def conc_fun_def \n  apply(auto split: nrest.splits option.splits simp: fun_eq_iff)\n  subgoal \n    by (smt Sup_bot_conv(1) bot_option_def mem_Collect_eq) \n  subgoal premises p for x2 x2a x2b x x2c\n  proof -\n    have \"Sup {x2b a |a. (x, a) \\<in> R} = Sup {map_option E (x2 a) |a. (x, a) \\<in> R}\"\n      apply(rule arg_cong[where f=Sup])\n      using p(3)[rule_format] p(4)\n      apply auto\n      subgoal by (smt map_option_eq_Some option.exhaust) \n      subgoal by (metis not_None_eq option.simps(8) option.simps(9)) \n      done\n    also have \"\\<dots> = map_option E (Sup {x2 a |a. (x, a) \\<in> R})\" \n      apply(subst continuous_map_option[OF assms, THEN continuousD] )\n      apply(rule arg_cong[where f=Sup])\n      by auto\n    also have \"\\<dots> = map_option E (Some x2c)\"\n      using p(2)[rule_format, of x, unfolded p(4)] by simp\n    also have \"\\<dots> = Some (E x2c)\" by simp\n    finally show \"Some (E x2c) = Sup {x2b a |a. (x, a) \\<in> R}\"  by simp\n  qed\n  done \n\n(* TODO: move*)\nlemma nrest_le_formatI:\n  fixes a :: \"(_,(_,enat)acost) nrest\"\n  shows  \"a \\<le> \\<Down>Id (\\<Down>\\<^sub>C TId b) \\<Longrightarrow> a \\<le> b\"\n  by (auto simp add: timerefine_id)\n\n\nsubsection \\<open>nrest_trel\\<close>\n\ndefinition nrest_trel where \n  nrest_trel_def_internal: \"nrest_trel R E \\<equiv> {(c,a).  c \\<le> \\<Down>R (\\<Down>\\<^sub>C E a)}\"\n\n\nlemma nrest_trelD: \"(c,a)\\<in>nrest_trel R E \\<Longrightarrow> c \\<le> \\<Down>R (\\<Down>\\<^sub>C E a)\" by (simp add: nrest_trel_def_internal)\n\n  \nlemma nrest_trelI: \"c \\<le> \\<Down>R (\\<Down>\\<^sub>C E a) \\<Longrightarrow> (c,a)\\<in>nrest_trel R E\" by (simp add: nrest_trel_def_internal)\n\n\nsubsection \\<open>Type Class nrest_cost\\<close>\n\nclass nrest_cost = complete_lattice + needname_zero + nonneg + ordered_semiring + semiring_no_zero_divisors\n\n\nsubsection \\<open>Setup for refinement condition generator\\<close>\n\nlemma consume_refine:\n  fixes M :: \"('e, ('b, enat) acost) nrest\"\n  assumes \"wfR'' E\"\n  shows \"\\<lbrakk>t \\<le> timerefineA E t'; M \\<le> \\<Down> R (\\<Down>\\<^sub>C E M')\\<rbrakk> \\<Longrightarrow> NREST.consume M t \\<le> \\<Down>R (\\<Down>\\<^sub>C E (NREST.consume M' t'))\"\n  apply(subst timerefine_consume)\n  subgoal using assms .\n  apply(subst conc_fun_consume)\n  apply(rule consume_mono) by auto\n\nlemma MIf_refine:\n  fixes f :: \"(_,(string, enat) acost) nrest\"\n  shows \"struct_preserving E \\<Longrightarrow> wfR'' E \\<Longrightarrow> (b,b')\\<in>bool_rel \\<Longrightarrow> (b \\<Longrightarrow> f \\<le> \\<Down>R (\\<Down>\\<^sub>C E f'))\n           \\<Longrightarrow> (\\<not>b \\<Longrightarrow> g \\<le> \\<Down>R (\\<Down>\\<^sub>C E g')) \\<Longrightarrow>  MIf b f g  \\<le> \\<Down>R (\\<Down>\\<^sub>C E (MIf b' f' g' ))\"\n  by(auto simp: MIf_def timerefineA_update_apply_same_cost dest: struct_preservingD intro!: consume_refine)\n\n\nlemma ASSERT_D_leI[refine,refine0]: \n  fixes M :: \"(_,(_,enat)acost) nrest\"\n  shows \"\\<Phi> \\<Longrightarrow> (\\<Phi> \\<Longrightarrow> M \\<le> \\<Down>R M') \\<Longrightarrow> ASSERT \\<Phi> \\<bind> (\\<lambda>_. M) \\<le> \\<Down>R M'\"\n  by (auto)\n\nlemma ASSERT_D2_leI[refine0]: \n  fixes S' :: \"(_,(_,enat)acost) nrest\"\n  shows \"(\\<Phi> \\<Longrightarrow> S \\<le> \\<Down> R S') \\<Longrightarrow> S \\<le> \\<Down> R (do {\n                                     _ \\<leftarrow> ASSERT \\<Phi>;\n                                     S'\n                                   })\"\n  by (auto simp: pw_acost_le_iff refine_pw_simps)\n\n\nlemma ASSERT_D3_leI[refine0]: \n  fixes S' :: \"(_,(_,enat)acost) nrest\"\n  shows \"(\\<Phi> \\<Longrightarrow> S \\<le> \\<Down> R (\\<Down>\\<^sub>C E S')) \\<Longrightarrow> S \\<le> \\<Down> R (\\<Down>\\<^sub>C E (do {\n                                     _ \\<leftarrow> ASSERT \\<Phi>;\n                                     S'\n                                   }))\"\n  by (auto simp: pw_acost_le_iff refine_pw_simps)\n\n\nlemma ASSERT_D4_leI[refine0]: \n  fixes S' :: \"(_,(_,enat)acost) nrest\"\n  shows \"(\\<Phi> \\<Longrightarrow> S \\<le> \\<Down> R (\\<Down>\\<^sub>C E S')) \\<Longrightarrow> do { _ \\<leftarrow> ASSERT \\<Phi>; S } \\<le> \\<Down> R (\\<Down>\\<^sub>C E (do {\n                                     _ \\<leftarrow> ASSERT \\<Phi>;\n                                     S'\n                                   }))\"\n  by (auto simp: pw_acost_le_iff refine_pw_simps)\n\n\nlemma refine_Id[refine0]: \"S \\<le> \\<Down> Id S\"\n  by auto\n\n\nlemma refine_TId[refine0]:\n  fixes S :: \"(_,(_,enat)acost) nrest\"\n  shows  \"S \\<le> \\<Down> Id (\\<Down>\\<^sub>C TId S)\"\n  unfolding timerefine_id\n  by auto\n\n\n\n\n\nlemma SPEC_refine[refine]:\n  fixes T :: \"_ \\<Rightarrow> ((_,enat)acost)\"\n  assumes *: \"\\<And>x. \\<Phi> x \\<Longrightarrow> \\<exists>s'. \\<Phi>' s' \\<and> (x, s') \\<in> R \\<and> T x \\<le> T' s'\"\n  shows \"SPEC \\<Phi> T \\<le> \\<Down>R (SPEC \\<Phi>' T')\"\n  unfolding SPEC_def\n  by (auto simp: pw_acost_le_iff refine_pw_simps dest!: * intro: order.trans[OF _ the_acost_mono])\n\n    \nlemma SPEC_both_refine:\n  fixes T :: \"_ \\<Rightarrow> ((_,enat)acost)\"\n  assumes \"\\<And>x. \\<Phi> x \\<Longrightarrow> \\<exists>s'. \\<Phi>' s' \\<and> (x, s') \\<in> R \\<and> T x \\<le> timerefineA TR (T' s')\"\n  shows \"SPEC \\<Phi> T \\<le> \\<Down> R (\\<Down>\\<^sub>C TR (SPEC \\<Phi>' T'))\"\n  apply(rule order.trans) \n  defer\n   apply(rule nrest_Rel_mono)\n   apply(rule SPEC_timerefine[where A=\\<Phi>'])\n    prefer 3 apply(rule SPEC_refine[where T=T])\n    defer apply simp apply(rule order_refl)\n  by (fact assms)\n\nlemma ASSERT_D5_leI[refine0]: \n  fixes S' :: \"(_,(_,enat)acost) nrest\"\n  shows \"(\\<Phi> \\<Longrightarrow> \\<Down> R (\\<Down>\\<^sub>C F S) \\<le> \\<Down> R (\\<Down>\\<^sub>C E S')) \\<Longrightarrow> \\<Down> R (\\<Down>\\<^sub>C F ( do { _ \\<leftarrow> ASSERT \\<Phi>; S })) \\<le> \\<Down> R (\\<Down>\\<^sub>C E (do {\n                                     _ \\<leftarrow> ASSERT \\<Phi>;\n                                     S'\n                                   }))\"\n  by (auto simp: pw_acost_le_iff refine_pw_simps)\n\ndeclare consume_refine[refine0]\n\n\nlemma RETURNT_refine_t[refine]:\n  assumes \"(x,x')\\<in>R\"\n  shows \"RETURNT x \\<le> \\<Down>R (\\<Down>\\<^sub>C E (RETURNT x'))\"\n  apply(subst timerefine_RETURNT)\n  apply(rule RETURNT_refine) by (fact assms)\n\n\ndeclare RETURNT_refine_t[refine0]\ndeclare timerefineA_TId[refine0]\n\n\nlemma SPECT_refine_t[refine]:\n  fixes t :: \"(_,enat) acost\"\n  assumes \"(x,x')\\<in>R\"\n    and \"t\\<le> timerefineA E t'\"\n  shows \"SPECT [x\\<mapsto>t] \\<le> \\<Down>R (\\<Down>\\<^sub>C E (SPECT [x'\\<mapsto>t']))\"\n  apply(subst timerefine_SPECT_map)\n  using assms apply(auto simp: pw_acost_le_iff refine_pw_simps)\n  apply(cases t) apply (auto simp: less_eq_acost_def)\n  subgoal for b ta xa apply(rule order.trans[where b=\"xa b\"]) by auto\n  done\n\nlemma RECT_refine_t:\n  assumes M: \"mono2 body\"\n  assumes R0: \"(x,x')\\<in>R\"\n  assumes RS: \"\\<And>f f' x x'. \\<lbrakk> \\<And>x x'. (x,x')\\<in>R \\<Longrightarrow> f x \\<le>\\<Down>S (\\<Down>\\<^sub>C E (f' x')); (x,x')\\<in>R \\<rbrakk> \n    \\<Longrightarrow> body f x \\<le>\\<Down>S (\\<Down>\\<^sub>C E (body' f' x'))\"\n  shows \"RECT (\\<lambda>f x. body f x) x \\<le>\\<Down>S (\\<Down>\\<^sub>C E (RECT (\\<lambda>f' x'. body' f' x') x'))\"\n  unfolding RECT_flat_gfp_def\n  apply (clarsimp simp add: M) \n  apply (rule flatf_fixp_transfer[where \n        fp'=\"flatf_gfp body\" \n    and B'=body \n    and P=\"\\<lambda>x x'. (x',x)\\<in>R\", \n    OF _ _ flatf_ord.fixp_unfold[OF M[THEN trimonoD_flatf_ge]] R0])\n  apply simp\n  apply (simp add: trimonoD_flatf_ge)\n  by (rule RS)\n\nlemma RECT'_refine_t:\n  fixes body :: \"('b \\<Rightarrow> ('c, (char list, enat) acost) nrest)\n   \\<Rightarrow> 'b \\<Rightarrow> ('c, (char list, enat) acost) nrest\"\n  assumes M: \"mono2 body\"\n  assumes wfRE: \"wfR'' E\"\n  assumes spE: \"struct_preserving E\"\n  assumes R0: \"(x,x')\\<in>R\"\n  assumes RS: \"\\<And>f f' x x'. \\<lbrakk> \\<And>x x'. (x,x')\\<in>R \\<Longrightarrow> f x \\<le>\\<Down>S (\\<Down>\\<^sub>C E (f' x')); (x,x')\\<in>R \\<rbrakk> \n    \\<Longrightarrow> body f x \\<le>\\<Down>S (\\<Down>\\<^sub>C E (body' f' x'))\"\n  shows \"RECT' (\\<lambda>f x. body f x) x \\<le>\\<Down>S (\\<Down>\\<^sub>C E (RECT' (\\<lambda>f' x'. body' f' x') x'))\"\n  unfolding RECT'_def\n  apply(rule consume_refine[OF wfRE])\n  subgoal using spE[THEN struct_preservingD(1)] by simp\n  unfolding RECT_flat_gfp_def\n  apply (clarsimp simp add: M[THEN RECT'_unfold_aux])\n  apply (rule flatf_fixp_transfer[where \n        fp'=\"flatf_gfp ((\\<lambda>D. body (\\<lambda>x. NREST.consume (D x) (cost ''call'' 1))))\" \n    and B'=\"(\\<lambda>D. body (\\<lambda>x. NREST.consume (D x) (cost ''call'' 1)))\" \n    and P=\"\\<lambda>x x'. (x',x)\\<in>R\", \n    OF _ _ flatf_ord.fixp_unfold[OF M[THEN RECT'_unfold_aux, THEN trimonoD_flatf_ge]] R0])\n  apply simp\n  apply (simp add: trimonoD_flatf_ge)\n  apply (rule RS)\n   apply(rule consume_refine[OF wfRE])\n  subgoal using spE[THEN struct_preservingD(1)] by simp\n   apply simp apply simp\n  done\n\nlemma monadic_WHILEIT_refine_t[refine]:  \n  fixes b :: \"'c \\<Rightarrow> (bool, (char list, enat) acost) nrest\"\n  assumes wfR[simp]:  \"wfR'' E\"\n  assumes sp_E: \"struct_preserving E\"\n  assumes [refine]: \"(s',s) \\<in> R\"\n  assumes [refine]: \"\\<And>s' s. \\<lbrakk> (s',s)\\<in>R; I s \\<rbrakk> \\<Longrightarrow> I' s'\"  \n  assumes [refine]: \"\\<And>s' s. \\<lbrakk> (s',s)\\<in>R; I s; I' s' \\<rbrakk> \\<Longrightarrow> b' s' \\<le>\\<Down>bool_rel (\\<Down>\\<^sub>C E (b s))\"\n  assumes [refine]: \"\\<And>s' s. \\<lbrakk> (s',s)\\<in>R; I s; I' s'; nofailT (b s);\n                    \\<exists>t e. inresT (project_acost  e (b s)) True t \\<rbrakk> \\<Longrightarrow> f' s' \\<le>\\<Down>R (\\<Down>\\<^sub>C E (f s))\"\n  shows \"monadic_WHILEIT I' b' f' s' \\<le> \\<Down>R (\\<Down>\\<^sub>C E (monadic_WHILEIT I b f s))\"\n  unfolding monadic_WHILEIT_def unfolding MIf_def \n  apply (refine_rcg bindT_refine_conc_time2 RECT_refine_t IdI wfR struct_preservingD[OF sp_E]) \n  apply simp  \n  subgoal by refine_mono\n  apply (assumption?; auto)+\n  apply (refine_rcg consume_refine_easy bindT_refine_conc_time2 wfR struct_preservingD[OF sp_E] RETURNT_refine_t )\n       apply (assumption?; auto)+\n  apply(rule RETURNT_refine_t) \n  apply (assumption?; auto)+ \n  done\n\nlemma monadic_WHILEIT_refine':  \n  fixes b :: \"'c \\<Rightarrow> (bool, (char list, enat) acost) nrest\"\n  assumes wfR[simp]:  \"wfR'' E\"\n  assumes sp_E: \"struct_preserving E\"\n  assumes [refine]: \"(s',s) \\<in> R\"\n  assumes [refine]: \"\\<And>s' s. \\<lbrakk> (s',s)\\<in>R; I s \\<rbrakk> \\<Longrightarrow> I' s'\"  \n  assumes [refine]: \"\\<And>s' s. \\<lbrakk> (s',s)\\<in>R; I s; I' s' \\<rbrakk> \\<Longrightarrow> b' s' \\<le>\\<Down>bool_rel (\\<Down>\\<^sub>C E (b s))\"\n  assumes [refine]: \"\\<And>s' s. \\<lbrakk> (s',s)\\<in>R; I s; I' s'; inres (b s) True \\<rbrakk> \\<Longrightarrow> f' s' \\<le>\\<Down>R (\\<Down>\\<^sub>C E (f s))\"\n  shows \"monadic_WHILEIT I' b' f' s' \\<le> \\<Down>R (\\<Down>\\<^sub>C E (monadic_WHILEIT I b f s))\"\n  apply(rule monadic_WHILEIT_refine_t[OF assms(1-5)])\n  by(auto intro: assms(6) inres_if_inresT_acost)\n\nsubsection \\<open>mop call\\<close>\n\ndefinition mop_call where\n  \"mop_call m = consume m (cost ''call'' 1)\"\n\nlemma gwp_call[vcg_rules']:\n  fixes m :: \"(_,(_,enat) acost) nrest\"\n  assumes \"Some (cost ''call'' 1 + t) \\<le> gwp m Q\"\n  shows  \"Some t \\<le> gwp (mop_call m) Q\"\n  unfolding mop_call_def\n  apply(rule gwp_consume) by(rule assms)\n\nlemma mop_call_refine:\n  fixes M :: \"('e, (string, enat) acost) nrest\"\n  assumes \"wfR'' E\"\n    \"struct_preserving E\"\n  shows \"\\<lbrakk> M \\<le> \\<Down> R (\\<Down>\\<^sub>C E M')\\<rbrakk> \\<Longrightarrow> mop_call M \\<le> \\<Down>R (\\<Down>\\<^sub>C E (mop_call M'))\"\n  unfolding mop_call_def\n  apply(subst timerefine_consume)\n  subgoal using assms(1) .\n  apply(subst conc_fun_consume)\n  apply(rule consume_mono) \n  using assms(2)[THEN struct_preservingD(1)]  \n  by auto    \n\nsubsection \\<open>Shortcuts for specifications of operations\\<close>\n\n  definition \"SPECc1' c aop == (\\<lambda>a. SPECT ( [(aop a)\\<mapsto>c]))\"\n  definition \"SPECc1 name aop == (\\<lambda>a. SPECT ( [(aop a)\\<mapsto>(cost name 1)]))\"\n  definition \"SPECc2 name aop == ( (\\<lambda>a b. SPECT ( [(aop a b)\\<mapsto>(cost name 1)])))\"\n\n\nlemma RETURNT_eq_SPECc2_iff[simp]: \"RETURNTecost v \\<le> SPECc2 n f a b\n      \\<longleftrightarrow> (f a b = v)\"\n  unfolding SPECc2_def apply (auto simp: pw_acost_le_iff refine_pw_simps)\n  using zero_enat_def by(auto simp: )  \n\nlemma inres_SPECc2: \"inres (SPECc2 n op a b) t \\<longleftrightarrow> (op a b = t)\"\n  by(auto simp: inres_def SPECc2_def)\n\nlemma SPECc2_alt: \"SPECc2 name aop = ( (\\<lambda>a b. consume (RETURNT (aop a b)) (cost name 1)))\"\n  unfolding SPECc2_def consume_def by(auto simp: RETURNT_def intro!: ext)\n\nlemma SPECc1_alt: \"SPECc1 name aop = ( (\\<lambda>a. consume (RETURNT (aop a)) (cost name 1)))\"\n  unfolding SPECc1_def consume_def by(auto simp: RETURNT_def intro!: ext)\n\nlemma gwp_SPECc2:\n  assumes \"Some (t + cost c 1) \\<le> Q (op a b)\"\n  shows \"Some t \\<le> gwp (SPECc2 c op a b) Q\"\n  unfolding SPECc2_def \n  apply(refine_vcg \\<open>-\\<close>)\n  using assms by auto\n\nlemma SPECc2_refine':\n  fixes TR :: \"'h \\<Rightarrow> ('h, enat) acost\"\n  shows \"(op x y, op' x' y')\\<in>R \\<Longrightarrow> preserves_curr TR n  \\<Longrightarrow> SPECc2 n op x y \\<le> \\<Down> R (\\<Down>\\<^sub>C TR (SPECc2 n op' x' y'))\"\n  unfolding SPECc2_def    \n  apply(subst SPECT_refine_t) by (auto simp: preserves_curr_def timerefineA_cost_apply) \n  \nlemma SPECc2_refine:\n  \"(op x y, op' x' y')\\<in>R \\<Longrightarrow> cost n (1::enat) \\<le> TR n'  \\<Longrightarrow> SPECc2 n op x y \\<le> \\<Down> R (\\<Down>\\<^sub>C TR (SPECc2 n' op' x' y'))\"\n  unfolding SPECc2_def    \n  apply(subst SPECT_refine_t) apply auto\n  apply(rule order.trans) apply (simp add: )\n  apply(subst timerefineA_cost) by simp\n\n\nsubsection \\<open>normalize blocks\\<close>\n\ntext \\<open>The idea of the following tactic is to normalize all straight line blocks,\n      such that they have the form (doN { [ASSUMEs]; consumea T; [RETURNs]; FURTHER }.      \n      To that end, it assumes that most operations are unfolded and only contain consumea, RETURN\n      or consume (RETURN _) _. The RETURNs will be propagated with @{thm nres_bind_left_identity},\n      ASSERTIONs will be pulled to the front, consumeas will be shrinked and assoc rule is applied.\n\n      It then is assumed, that FURTHER statements in the concrete and abstract are in lock step.\n\n      [ Then refine_block will split products, collect and discharge ASSUME statements, \n      pay for the consumea; and then stop at a FURTHER statement.\n      One can then give \"rules\" that process the FURTHER statements. ]\n      This process is way better done by refine_rcg!\n      \n      This allows that not only lockstep refinement is possible, but that by unfolding certain\n      operations, their effects get \n        \\<close>\n\nlemma consumea_refine:\n  fixes t :: \"(_,enat) acost\"\n  shows \"((), ()) \\<in> R \\<Longrightarrow> t \\<le> timerefineA F t' \\<Longrightarrow> consumea t \\<le> \\<Down> R (\\<Down>\\<^sub>C F (consumea t'))\"\n  unfolding consumea_def\n  apply(rule SPECT_refine_t) by auto\n\nlemma consumea_Id_refine:\n  fixes t :: \"(_,enat) acost\"\n  shows \"t \\<le> timerefineA F t' \\<Longrightarrow> consumea t \\<le> \\<Down> Id (\\<Down>\\<^sub>C F (consumea t'))\"\n  unfolding consumea_def\n  apply(rule SPECT_refine_t) by auto\n    \n\nlemma swap_consumea_ASSERT: \"do { consumea t; ASSERT P; M:: ('c, ('d, enat) acost) nrest} = do {ASSERT P; consumea t; M}\"\n  apply(auto simp: pw_acost_eq_iff refine_pw_simps consumea_def)\n  apply (metis zero_enat_def zero_le)\n  using le_Suc_ex zero_enat_def by force\n\n\nlemma consumea_0_noop:\n  fixes m :: \"('b,'c::{complete_lattice,zero,monoid_add}) nrest\"\n  shows \"do { consumea 0; m } = m\"\n  apply(auto simp: consumea_def bindT_def split: nrest.splits intro!: ext) \n  subgoal for x2 x apply(cases \"x2 x\") by auto\n  done\n\nthm refine0              \n\nlemma forget_inresT_project_acos: \"\\<exists>t b. inresT (project_acost b (consumea tt)) x' t \\<Longrightarrow> True\"\n  by simp\n\nlemma forget_nofailT_consumea: \"nofailT (consumea tt) \\<Longrightarrow> True\"\n  by simp\n\nlemmas normalize_inres_precond = forget_nofailT_consumea forget_inresT_project_acos\n                                  inresT_consumea_D EX_inresT_SPECTONE_D\n\nmethod normalize_blocks = (simp only: swap_consumea_ASSERT nres_acost_bind_assoc consume_alt consumea_shrink nres_bind_left_identity)\nmethod refine_block uses rules = (drule normalize_inres_precond |split prod.splits | intro allI impI\n                                    | rule refine0 consumea_Id_refine SPECT_refine_t bindT_refine_conc_time_my rules)\nmethod refine_blocks uses rules = repeat_all_new \\<open>refine_block rules: rules\\<close>\n\n\nsubsection \\<open>Simple bind rule with inres\\<close>\n\n\nlemma bindT_refine_conc_time_my_inres:\n  fixes m :: \"('e1,('c1,enat)acost) nrest\"\n  fixes m' :: \"('e2,('c2,enat)acost) nrest\"\n  assumes \"wfR'' E\" \" m \\<le> \\<Down>R' (\\<Down>\\<^sub>C E m')\"\n  \"(\\<And>x x'. \\<lbrakk>(x,x')\\<in>R'; inres m' x'\\<rbrakk>\n         \\<Longrightarrow> f x \\<le> \\<Down> R (\\<Down>\\<^sub>C E (f' x') ))\"\nshows \"bindT m f \\<le>  \\<Down> R (\\<Down>\\<^sub>C E (bindT m' f'))\"\n  apply(rule bindT_refine_conc_time2) using assms\n  by (auto dest: inres_if_inresT_acost)\n\nlemma bindT_refine_conc_time_easy:\n  fixes m :: \"('e1,('c1,enat)acost) nrest\"\n  fixes m' :: \"('e2,('c2,enat)acost) nrest\"\n  assumes \"wfR E\" \" m \\<le> \\<Down>R' (\\<Down>\\<^sub>C E m')\"\n  \"(\\<And>x x'. \\<lbrakk>(x,x')\\<in>R' \\<rbrakk> \\<Longrightarrow> f x \\<le> \\<Down> R (\\<Down>\\<^sub>C E (f' x') ))\"\nshows \"bindT m f \\<le>  \\<Down> R (\\<Down>\\<^sub>C E (bindT m' f'))\"\n  apply(rule bindT_refine_conc_time)\n    apply fact\n   apply fact\n  apply(rule assms(3)) apply simp\n  done\n\nlemma bindT_refine_easy:\n  fixes m :: \"('e1,('c1,enat)acost) nrest\"\n  fixes m' :: \"('e2,('c2,enat)acost) nrest\"\n  assumes \"wfR'' E\" \" m \\<le> \\<Down>R' (\\<Down>\\<^sub>C E m')\"\n  \"(\\<And>x x'. \\<lbrakk>(x,x')\\<in>R'\\<rbrakk>\n         \\<Longrightarrow> f x \\<le> \\<Down> R (\\<Down>\\<^sub>C E (f' x') ))\"\nshows \"bindT m f \\<le>  \\<Down> R (\\<Down>\\<^sub>C E (bindT m' f'))\"\n  apply(rule bindT_refine_conc_time2) using assms\n  by (auto dest: inres_if_inresT_acost)\n\n\nend", "meta": {"author": "lammich", "repo": "isabelle_llvm_time", "sha": "42dd7f59998d76047bb4b6bce76d8f67b53a08b6", "save_path": "github-repos/isabelle/lammich-isabelle_llvm_time", "path": "github-repos/isabelle/lammich-isabelle_llvm_time/isabelle_llvm_time-42dd7f59998d76047bb4b6bce76d8f67b53a08b6/thys/nrest/NREST_Main.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5583269796369905, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.27262179330241804}}
{"text": "(*****************************************************************************\n * Featherweight-OCL --- A Formal Semantics for UML-OCL Version OCL 2.5\n *                       for the OMG Standard.\n *                       http://www.brucker.ch/projects/hol-testgen/\n *\n * UML_String.thy --- Library definitions.\n * This file is part of HOL-TestGen.\n *\n * Copyright (c) 2012-2015 Université Paris-Saclay, Univ. Paris-Sud, France\n *               2013-2015 IRT SystemX, France\n *\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are\n * met:\n *\n *     * Redistributions of source code must retain the above copyright\n *       notice, this list of conditions and the following disclaimer.\n *\n *     * Redistributions in binary form must reproduce the above\n *       copyright notice, this list of conditions and the following\n *       disclaimer in the documentation and/or other materials provided\n *       with the distribution.\n *\n *     * Neither the name of the copyright holders nor the names of its\n *       contributors may be used to endorse or promote products derived\n *       from this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n ******************************************************************************)\n\ntheory  UML_String\nimports \"../UML_PropertyProfiles\"\nbegin\n\nsection\\<open>Basic Type String: Operations\\<close>\n\nsubsection\\<open>Fundamental Properties on Strings: Strict Equality \\label{sec:string-strict-eq}\\<close>\n\ntext\\<open>The last basic operation belonging to the fundamental infrastructure\nof a value-type in OCL is the weak equality, which is defined similar\nto the @{typ \"('\\<AA>)Boolean\"}-case as strict extension of the strong equality:\\<close>\noverloading StrictRefEq \\<equiv> \"StrictRefEq :: [('\\<AA>)String,('\\<AA>)String] \\<Rightarrow> ('\\<AA>)Boolean\"\nbegin\n  definition StrictRefEq\\<^sub>S\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g[code_unfold] :\n    \"(x::('\\<AA>)String) \\<doteq> y \\<equiv> \\<lambda> \\<tau>. if (\\<upsilon> x) \\<tau> = true \\<tau> \\<and> (\\<upsilon> y) \\<tau> = true \\<tau>\n                                  then (x \\<triangleq> y) \\<tau>\n                                  else invalid \\<tau>\"\nend\n\ntext\\<open>Property proof in terms of @{term \"profile_bin\\<^sub>S\\<^sub>t\\<^sub>r\\<^sub>o\\<^sub>n\\<^sub>g\\<^sub>E\\<^sub>q_\\<^sub>v_\\<^sub>v\"}\\<close>\ninterpretation  StrictRefEq\\<^sub>S\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g : profile_bin\\<^sub>S\\<^sub>t\\<^sub>r\\<^sub>o\\<^sub>n\\<^sub>g\\<^sub>E\\<^sub>q_\\<^sub>v_\\<^sub>v \"\\<lambda> x y. (x::('\\<AA>)String) \\<doteq> y\" \n         by unfold_locales (auto simp: StrictRefEq\\<^sub>S\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g)\n \nsubsection\\<open>Basic String Constants\\<close>\n\ntext\\<open>Although the remaining part of this library reasons about\nintegers abstractly, we provide here as example some convenient shortcuts.\\<close>\n\ndefinition OclStringa ::\"('\\<AA>)String\" (\"\\<a>\")    where      \"\\<a> = (\\<lambda> _ . \\<lfloor>\\<lfloor>''a''\\<rfloor>\\<rfloor>)\"\ndefinition OclStringb ::\"('\\<AA>)String\" (\"\\<b>\")    where      \"\\<b> = (\\<lambda> _ . \\<lfloor>\\<lfloor>''b''\\<rfloor>\\<rfloor>)\"\ndefinition OclStringc ::\"('\\<AA>)String\" (\"\\<c>\")    where      \"\\<c> = (\\<lambda> _ . \\<lfloor>\\<lfloor>''c''\\<rfloor>\\<rfloor>)\"\ntext\\<open>Etc.\\<close>\ntext_raw\\<open>\\isatagafp\\<close>\n\nsubsection\\<open>Validity and Definedness Properties\\<close>\n\nlemma  \"\\<delta>(null::('\\<AA>)String) = false\" by simp\nlemma  \"\\<upsilon>(null::('\\<AA>)String) = true\"  by simp\n\n\n\nlemma [simp,code_unfold]: \"\\<upsilon> (\\<lambda>_. \\<lfloor>\\<lfloor>n\\<rfloor>\\<rfloor>) = true\"\nby(simp add:valid_def true_def\n               bot_fun_def bot_option_def)\n\n(* ecclectic proofs to make examples executable *)\nlemma [simp,code_unfold]: \"\\<delta> \\<a> = true\" by(simp add:OclStringa_def)\nlemma [simp,code_unfold]: \"\\<upsilon> \\<a> = true\" by(simp add:OclStringa_def)\ntext_raw\\<open>\\endisatagafp\\<close>\n\nsubsection\\<open>String Operations\\<close>\n\nsubsubsection\\<open>Definition\\<close>\ntext\\<open>Here is a common case of a built-in operation on built-in types.\nNote that the arguments must be both defined (non-null, non-bot).\\<close>\ntext\\<open>Note that we can not follow the lexis of the OCL Standard for Isabelle\ntechnical reasons; these operators are heavily overloaded in the HOL library\nthat a further overloading would lead to heavy technical buzz in this\ndocument.\n\\<close>\ndefinition OclAdd\\<^sub>S\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g ::\"('\\<AA>)String \\<Rightarrow> ('\\<AA>)String \\<Rightarrow> ('\\<AA>)String\" (infix \"+\\<^sub>s\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g\" 40)\nwhere \"x +\\<^sub>s\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g y \\<equiv> \\<lambda> \\<tau>. if (\\<delta> x) \\<tau> = true \\<tau> \\<and> (\\<delta> y) \\<tau> = true \\<tau>\n                       then \\<lfloor>\\<lfloor>concat [\\<lceil>\\<lceil>x \\<tau>\\<rceil>\\<rceil>, \\<lceil>\\<lceil>y \\<tau>\\<rceil>\\<rceil>]\\<rfloor>\\<rfloor>\n                       else invalid \\<tau> \"\ninterpretation OclAdd\\<^sub>S\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g : profile_bin\\<^sub>d_\\<^sub>d \"(+\\<^sub>s\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g)\" \"\\<lambda> x y. \\<lfloor>\\<lfloor>concat [\\<lceil>\\<lceil>x\\<rceil>\\<rceil>, \\<lceil>\\<lceil>y\\<rceil>\\<rceil>]\\<rfloor>\\<rfloor>\"\n         by unfold_locales (auto simp:OclAdd\\<^sub>S\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g_def bot_option_def null_option_def)\n         \n(* TODO : size(), concat, substring(s:string) toInteger, toReal, at(i:Integer), characters() etc. *)\n\n\nsubsubsection\\<open>Basic Properties\\<close>\n\nlemma OclAdd\\<^sub>S\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g_not_commute: \"\\<exists>X Y. (X +\\<^sub>s\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g Y) \\<noteq> (Y +\\<^sub>s\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g X)\"\n  apply(rule_tac x = \"\\<lambda>_. \\<lfloor>\\<lfloor>''b''\\<rfloor>\\<rfloor>\" in exI)\n  apply(rule_tac x = \"\\<lambda>_. \\<lfloor>\\<lfloor>''a''\\<rfloor>\\<rfloor>\" in exI)\n  apply(simp_all add:OclAdd\\<^sub>S\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g_def)\n  by(auto, drule fun_cong, auto)\n\n\nsubsection\\<open>Test Statements\\<close>\ntext\\<open>Here follows a list of code-examples, that explain the meanings\nof the above definitions by compilation to code and execution to @{term \"True\"}.\\<close>\n(*\nAssert \"\\<tau> \\<Turnstile> ( \\<nine> \\<le>\\<^sub>s\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g \\<one>\\<zero> )\"\nAssert \"\\<tau> \\<Turnstile> (( \\<four> +\\<^sub>s\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g \\<four> ) \\<le>\\<^sub>s\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g \\<one>\\<zero> )\"\nAssert \"\\<tau> |\\<noteq> (( \\<four> +\\<^sub>s\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g ( \\<four> +\\<^sub>s\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g \\<four> )) <\\<^sub>s\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g \\<one>\\<zero> )\"\nAssert \"\\<tau> \\<Turnstile> not (\\<upsilon> (null +\\<^sub>s\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g \\<one>)) \"\n*)\n\ntext\\<open>Here follows a list of code-examples, that explain the meanings\nof the above definitions by compilation to code and execution to @{term \"True\"}.\\<close>\n\n\ntext\\<open>Elementary computations on String\\<close>\n\nAssert \"\\<tau> \\<Turnstile> \\<a> <> \\<b>\"\nAssert \"\\<tau> \\<Turnstile> \\<b> <> \\<a>\"\nAssert \"\\<tau> \\<Turnstile> \\<b> \\<doteq> \\<b>\"\n\nAssert \"\\<tau> \\<Turnstile> \\<upsilon> \\<a>\"\nAssert \"\\<tau> \\<Turnstile> \\<delta> \\<a>\"\nAssert \"\\<tau> \\<Turnstile> \\<upsilon> (null::('\\<AA>)String)\"\nAssert \"\\<tau> \\<Turnstile> (invalid \\<triangleq> invalid)\"\nAssert \"\\<tau> \\<Turnstile> (null \\<triangleq> null)\"\nAssert \"\\<tau> \\<Turnstile> (\\<a> \\<triangleq> \\<a>)\"\nAssert \"\\<tau> |\\<noteq> (\\<a> \\<triangleq> \\<b>)\"\nAssert \"\\<tau> |\\<noteq> (invalid \\<triangleq> \\<b>)\"\nAssert \"\\<tau> |\\<noteq> (null \\<triangleq> \\<b>)\"\nAssert \"\\<tau> |\\<noteq> (invalid \\<doteq> (invalid::('\\<AA>)String))\" (* Without typeconstraint not executable.*)\nAssert \"\\<tau> |\\<noteq> \\<upsilon> (invalid \\<doteq> (invalid::('\\<AA>)String))\" (* Without typeconstraint not executable.*)\nAssert \"\\<tau> |\\<noteq> (invalid <> (invalid::('\\<AA>)String))\" (* Without typeconstraint not executable.*)\nAssert \"\\<tau> |\\<noteq> \\<upsilon> (invalid <> (invalid::('\\<AA>)String))\" (* Without typeconstraint not executable.*)\nAssert \"\\<tau> \\<Turnstile> (null \\<doteq> (null::('\\<AA>)String) )\" (* Without typeconstraint not executable.*)\nAssert \"\\<tau> \\<Turnstile> (null \\<doteq> (null::('\\<AA>)String) )\" (* Without typeconstraint not executable.*)\nAssert \"\\<tau> \\<Turnstile> (\\<b> \\<doteq> \\<b>)\"\nAssert \"\\<tau> |\\<noteq> (\\<b> <> \\<b>)\"\nAssert \"\\<tau> |\\<noteq> (\\<b> \\<doteq> \\<c>)\"\nAssert \"\\<tau> \\<Turnstile> (\\<b> <> \\<c>)\"\n(*Assert \"\\<tau> |\\<noteq> (\\<zero> <\\<^sub>s\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g null)\"\nAssert \"\\<tau> |\\<noteq> (\\<delta> (\\<zero> <\\<^sub>s\\<^sub>t\\<^sub>r\\<^sub>i\\<^sub>n\\<^sub>g null))\"\n*)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Featherweight_OCL/basic_types/UML_String.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6334102775181399, "lm_q2_score": 0.43014734858584286, "lm_q1q2_score": 0.2724597514414508}}
{"text": "(*  Title:      HOL/NanoJava/TypeRel.thy\n    Author:     David von Oheimb, Technische Universitaet Muenchen\n*)\n\nsection \"Type relations\"\n\ntheory TypeRel\nimports Decl\nbegin\n\ntext\\<open>Direct subclass relation\\<close>\n\ndefinition subcls1 :: \"(cname \\<times> cname) set\"\nwhere\n  \"subcls1 \\<equiv> {(C,D). C\\<noteq>Object \\<and> (\\<exists>c. class C = Some c \\<and> super c=D)}\"\n\nabbreviation\n  subcls1_syntax :: \"[cname, cname] => bool\"  (\"_ \\<prec>C1 _\" [71,71] 70)\n  where \"C \\<prec>C1 D == (C,D) \\<in> subcls1\"\nabbreviation\n  subcls_syntax  :: \"[cname, cname] => bool\" (\"_ \\<preceq>C _\"  [71,71] 70)\n  where \"C \\<preceq>C D == (C,D) \\<in> subcls1^*\"\n\n\nsubsection \"Declarations and properties not used in the meta theory\"\n\ntext\\<open>Widening, viz. method invocation conversion\\<close>\ninductive\n  widen :: \"ty => ty => bool\"  (\"_ \\<preceq> _\" [71,71] 70)\nwhere\n  refl [intro!, simp]: \"T \\<preceq> T\"\n| subcls: \"C\\<preceq>C D \\<Longrightarrow> Class C \\<preceq> Class D\"\n| null [intro!]: \"NT \\<preceq> R\"\n\nlemma subcls1D: \n  \"C\\<prec>C1D \\<Longrightarrow> C \\<noteq> Object \\<and> (\\<exists>c. class C = Some c \\<and> super c=D)\"\napply (unfold subcls1_def)\napply auto\ndone\n\nlemma subcls1I: \"\\<lbrakk>class C = Some m; super m = D; C \\<noteq> Object\\<rbrakk> \\<Longrightarrow> C\\<prec>C1D\"\napply (unfold subcls1_def)\napply auto\ndone\n\nlemma subcls1_def2: \n  \"subcls1 = \n    (SIGMA C: {C. is_class C} . {D. C\\<noteq>Object \\<and> super (the (class C)) = D})\"\napply (unfold subcls1_def is_class_def)\napply (auto split:if_split_asm)\ndone\n\nlemma finite_subcls1: \"finite subcls1\"\napply(subst subcls1_def2)\napply(rule finite_SigmaI [OF finite_is_class])\napply(rule_tac B = \"{super (the (class C))}\" in finite_subset)\napply  auto\ndone\n\ndefinition ws_prog :: \"bool\" where\n \"ws_prog \\<equiv> \\<forall>(C,c)\\<in>set Prog. C\\<noteq>Object \\<longrightarrow> \n                              is_class (super c) \\<and> (super c,C)\\<notin>subcls1^+\"\n\nlemma ws_progD: \"\\<lbrakk>class C = Some c; C\\<noteq>Object; ws_prog\\<rbrakk> \\<Longrightarrow>  \n  is_class (super c) \\<and> (super c,C)\\<notin>subcls1^+\"\napply (unfold ws_prog_def class_def)\napply (drule_tac map_of_SomeD)\napply auto\ndone\n\nlemma subcls1_irrefl_lemma1: \"ws_prog \\<Longrightarrow> subcls1^-1 \\<inter> subcls1^+ = {}\"\nby (fast dest: subcls1D ws_progD)\n\n(* irrefl_tranclI in Transitive_Closure.thy is more general *)\nlemma irrefl_tranclI': \"r^-1 Int r^+ = {} ==> !x. (x, x) ~: r^+\"\nby(blast elim: tranclE dest: trancl_into_rtrancl)\n\n\nlemmas subcls1_irrefl_lemma2 = subcls1_irrefl_lemma1 [THEN irrefl_tranclI']\n\nlemma subcls1_irrefl: \"\\<lbrakk>(x, y) \\<in> subcls1; ws_prog\\<rbrakk> \\<Longrightarrow> x \\<noteq> y\"\napply (rule irrefl_trancl_rD)\napply (rule subcls1_irrefl_lemma2)\napply auto\ndone\n\nlemmas subcls1_acyclic = subcls1_irrefl_lemma2 [THEN acyclicI]\n\nlemma wf_subcls1: \"ws_prog \\<Longrightarrow> wf (subcls1\\<inverse>)\"\nby (auto intro: finite_acyclic_wf_converse finite_subcls1 subcls1_acyclic)\n\ndefinition class_rec ::\"cname \\<Rightarrow> (class \\<Rightarrow> ('a \\<times> 'b) list) \\<Rightarrow> ('a \\<rightharpoonup> 'b)\"\nwhere\n  \"class_rec \\<equiv> wfrec (subcls1\\<inverse>) (\\<lambda>rec C f.\n     case class C of None \\<Rightarrow> undefined\n      | Some m \\<Rightarrow> (if C = Object then empty else rec (super m) f) ++ map_of (f m))\"\n\nlemma class_rec: \"\\<lbrakk>class C = Some m;  ws_prog\\<rbrakk> \\<Longrightarrow>\n class_rec C f = (if C = Object then empty else class_rec (super m) f) ++ \n                 map_of (f m)\"\napply (drule wf_subcls1)\napply (subst def_wfrec[OF class_rec_def], auto)\napply (subst cut_apply, auto intro: subcls1I)\ndone\n\n\\<comment>\\<open>Methods of a class, with inheritance and hiding\\<close>\ndefinition \"method\" :: \"cname => (mname \\<rightharpoonup> methd)\" where\n  \"method C \\<equiv> class_rec C methods\"\n\nlemma method_rec: \"\\<lbrakk>class C = Some m; ws_prog\\<rbrakk> \\<Longrightarrow>\nmethod C = (if C=Object then empty else method (super m)) ++ map_of (methods m)\"\napply (unfold method_def)\napply (erule (1) class_rec [THEN trans])\napply simp\ndone\n\n\n\\<comment>\\<open>Fields of a class, with inheritance and hiding\\<close>\ndefinition field  :: \"cname => (fname \\<rightharpoonup> ty)\" where\n  \"field C \\<equiv> class_rec C flds\"\n\nlemma flds_rec: \"\\<lbrakk>class C = Some m; ws_prog\\<rbrakk> \\<Longrightarrow>\nfield C = (if C=Object then empty else field (super m)) ++ map_of (flds m)\"\napply (unfold field_def)\napply (erule (1) class_rec [THEN trans])\napply simp\ndone\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/HOL/NanoJava/TypeRel.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6113819732941511, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.2723887262933196}}
{"text": "header {*  \\isachapter{Dynamic Slicing} \n  \\isaheader{Dynamic Program Dependence Graph} *}\n\ntheory DynPDG imports \n  \"../Basic/DynDataDependence\" \n  \"../Basic/CFGExit_wf\" \n  \"../Basic/DynStandardControlDependence\"\n  \"../Basic/DynWeakControlDependence\"\nbegin\n\nsubsection {* The dynamic PDG *}\n\nlocale DynPDG = \n  CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use state_val Exit\n  for sourcenode :: \"'edge \\<Rightarrow> 'node\" and targetnode :: \"'edge \\<Rightarrow> 'node\"\n  and kind :: \"'edge \\<Rightarrow> 'state edge_kind\" and valid_edge :: \"'edge \\<Rightarrow> bool\"\n  and Entry :: \"'node\" (\"'('_Entry'_')\") and Def :: \"'node \\<Rightarrow> 'var set\"\n  and Use :: \"'node \\<Rightarrow> 'var set\" and state_val :: \"'state \\<Rightarrow> 'var \\<Rightarrow> 'val\"\n  and Exit :: \"'node\" (\"'('_Exit'_')\") +\n  fixes dyn_control_dependence :: \"'node \\<Rightarrow> 'node \\<Rightarrow> 'edge list \\<Rightarrow> bool\" \n(\"_ controls _ via _\" [51,0,0])\n  assumes Exit_not_dyn_control_dependent:\"n controls n' via as \\<Longrightarrow> n' \\<noteq> (_Exit_)\"\n  assumes dyn_control_dependence_path:\n  \"n controls n' via as  \\<Longrightarrow> n -as\\<rightarrow>* n' \\<and> as \\<noteq> []\"\n\nbegin\n\ninductive cdep_edge :: \"'node \\<Rightarrow> 'edge list \\<Rightarrow> 'node \\<Rightarrow> bool\" \n    (\"_ -_\\<rightarrow>\\<^bsub>cd\\<^esub> _\" [51,0,0] 80)\n  and ddep_edge :: \"'node \\<Rightarrow> 'var \\<Rightarrow> 'edge list \\<Rightarrow> 'node \\<Rightarrow> bool\"\n    (\"_ -'{_'}_\\<rightarrow>\\<^bsub>dd\\<^esub> _\" [51,0,0,0] 80)\n  and DynPDG_edge :: \"'node \\<Rightarrow> 'var option \\<Rightarrow> 'edge list \\<Rightarrow> 'node \\<Rightarrow> bool\"\n\nwhere\n      -- \"Syntax\"\n  \"n -as\\<rightarrow>\\<^bsub>cd\\<^esub> n' == DynPDG_edge n None as n'\"\n  | \"n -{V}as\\<rightarrow>\\<^bsub>dd\\<^esub> n' == DynPDG_edge n (Some V) as n'\"\n\n      -- \"Rules\"\n  | DynPDG_cdep_edge:\n  \"n controls n' via as \\<Longrightarrow> n -as\\<rightarrow>\\<^bsub>cd\\<^esub> n'\"\n\n  | DynPDG_ddep_edge:\n  \"n influences V in n' via as \\<Longrightarrow> n -{V}as\\<rightarrow>\\<^bsub>dd\\<^esub> n'\"\n\n\ninductive DynPDG_path :: \"'node \\<Rightarrow> 'edge list \\<Rightarrow> 'node \\<Rightarrow> bool\"\n(\"_ -_\\<rightarrow>\\<^sub>d* _\" [51,0,0] 80) \n\nwhere DynPDG_path_Nil:\n  \"valid_node n \\<Longrightarrow> n -[]\\<rightarrow>\\<^sub>d* n\"\n\n  | DynPDG_path_Append_cdep:\n  \"\\<lbrakk>n -as\\<rightarrow>\\<^sub>d* n''; n'' -as'\\<rightarrow>\\<^bsub>cd\\<^esub> n'\\<rbrakk> \\<Longrightarrow> n -as@as'\\<rightarrow>\\<^sub>d* n'\"\n\n  | DynPDG_path_Append_ddep:\n  \"\\<lbrakk>n -as\\<rightarrow>\\<^sub>d* n''; n'' -{V}as'\\<rightarrow>\\<^bsub>dd\\<^esub> n'\\<rbrakk> \\<Longrightarrow> n -as@as'\\<rightarrow>\\<^sub>d* n'\"\n\n\nlemma DynPDG_empty_path_eq_nodes:\"n -[]\\<rightarrow>\\<^sub>d* n' \\<Longrightarrow> n = n'\"\napply - apply(erule DynPDG_path.cases) \n  apply simp\n apply(auto elim:DynPDG_edge.cases dest:dyn_control_dependence_path)\nby(auto elim:DynPDG_edge.cases simp:dyn_data_dependence_def)\n\n\nlemma DynPDG_path_cdep:\"n -as\\<rightarrow>\\<^bsub>cd\\<^esub> n' \\<Longrightarrow> n -as\\<rightarrow>\\<^sub>d* n'\"\napply(subgoal_tac \"n -[]@as\\<rightarrow>\\<^sub>d* n'\")\n apply simp\napply(rule DynPDG_path_Append_cdep, rule DynPDG_path_Nil)\nby(auto elim!:DynPDG_edge.cases dest:dyn_control_dependence_path path_valid_node)\n\nlemma DynPDG_path_ddep:\"n -{V}as\\<rightarrow>\\<^bsub>dd\\<^esub> n' \\<Longrightarrow> n -as\\<rightarrow>\\<^sub>d* n'\"\napply(subgoal_tac \"n -[]@as\\<rightarrow>\\<^sub>d* n'\")\n apply simp\napply(rule DynPDG_path_Append_ddep, rule DynPDG_path_Nil)\nby(auto elim!:DynPDG_edge.cases dest:path_valid_node simp:dyn_data_dependence_def)\n\nlemma DynPDG_path_Append:\n  \"\\<lbrakk>n'' -as'\\<rightarrow>\\<^sub>d* n'; n -as\\<rightarrow>\\<^sub>d* n''\\<rbrakk> \\<Longrightarrow> n -as@as'\\<rightarrow>\\<^sub>d* n'\"\napply(induct rule:DynPDG_path.induct)\n  apply(auto intro:DynPDG_path.intros)\n apply(rotate_tac 1,drule DynPDG_path_Append_cdep,simp+)\napply(rotate_tac 1,drule DynPDG_path_Append_ddep,simp+)\ndone\n\n\nlemma DynPDG_path_Exit:\"\\<lbrakk>n -as\\<rightarrow>\\<^sub>d* n'; n' = (_Exit_)\\<rbrakk> \\<Longrightarrow> n = (_Exit_)\"\napply(induct rule:DynPDG_path.induct)\nby(auto elim:DynPDG_edge.cases dest:Exit_not_dyn_control_dependent \n        simp:dyn_data_dependence_def)\n\n\nlemma DynPDG_path_not_inner:\n  \"\\<lbrakk>n -as\\<rightarrow>\\<^sub>d* n'; \\<not> inner_node n'\\<rbrakk> \\<Longrightarrow> n = n'\"\nproof(induct rule:DynPDG_path.induct)\n  case (DynPDG_path_Nil n)\n  thus ?case by simp\nnext\n  case (DynPDG_path_Append_cdep n as n'' as' n')\n  from `n'' -as'\\<rightarrow>\\<^bsub>cd\\<^esub> n'` `\\<not> inner_node n'` have False\n    apply -\n    apply(erule DynPDG_edge.cases) apply(auto simp:inner_node_def)\n      apply(fastforce dest:dyn_control_dependence_path path_valid_node)\n     apply(fastforce dest:dyn_control_dependence_path path_valid_node)\n    by(fastforce dest:Exit_not_dyn_control_dependent)\n  thus ?case by simp\nnext\n  case (DynPDG_path_Append_ddep n as n'' V as' n')\n  from `n'' -{V}as'\\<rightarrow>\\<^bsub>dd\\<^esub> n'` `\\<not> inner_node n'` have False\n    apply -\n    apply(erule DynPDG_edge.cases) \n    by(auto dest:path_valid_node simp:inner_node_def dyn_data_dependence_def)\n  thus ?case by simp\nqed\n\n\nlemma DynPDG_cdep_edge_CFG_path:\n  assumes \"n -as\\<rightarrow>\\<^bsub>cd\\<^esub> n'\" shows \"n -as\\<rightarrow>* n'\" and \"as \\<noteq> []\"\n  using `n -as\\<rightarrow>\\<^bsub>cd\\<^esub> n'`\n  by(auto elim:DynPDG_edge.cases dest:dyn_control_dependence_path)\n\nlemma DynPDG_ddep_edge_CFG_path:\n  assumes \"n -{V}as\\<rightarrow>\\<^bsub>dd\\<^esub> n'\" shows \"n -as\\<rightarrow>* n'\" and \"as \\<noteq> []\"\n  using `n -{V}as\\<rightarrow>\\<^bsub>dd\\<^esub> n'`\n  by(auto elim:DynPDG_edge.cases simp:dyn_data_dependence_def)\n\nlemma DynPDG_path_CFG_path:\n  \"n -as\\<rightarrow>\\<^sub>d* n' \\<Longrightarrow> n -as\\<rightarrow>* n'\"\nproof(induct rule:DynPDG_path.induct)\n  case DynPDG_path_Nil thus ?case by(rule empty_path)\nnext\n  case (DynPDG_path_Append_cdep n as n'' as' n')\n  from `n'' -as'\\<rightarrow>\\<^bsub>cd\\<^esub> n'` have \"n'' -as'\\<rightarrow>* n'\"\n    by(rule DynPDG_cdep_edge_CFG_path(1))\n  with `n -as\\<rightarrow>* n''` show ?case by(rule path_Append)\nnext\n  case (DynPDG_path_Append_ddep n as n'' V as' n')\n  from `n'' -{V}as'\\<rightarrow>\\<^bsub>dd\\<^esub> n'` have \"n'' -as'\\<rightarrow>* n'\"\n    by(rule DynPDG_ddep_edge_CFG_path(1))\n  with `n -as\\<rightarrow>* n''` show ?case by(rule path_Append)\nqed\n\n\nlemma DynPDG_path_split: \n  \"n -as\\<rightarrow>\\<^sub>d* n' \\<Longrightarrow>\n  (as = [] \\<and> n = n') \\<or> \n  (\\<exists>n'' asx asx'. (n -asx\\<rightarrow>\\<^bsub>cd\\<^esub> n'') \\<and> (n'' -asx'\\<rightarrow>\\<^sub>d* n') \\<and> \n        (as = asx@asx')) \\<or>\n  (\\<exists>n'' V asx asx'. (n -{V}asx\\<rightarrow>\\<^bsub>dd\\<^esub> n'') \\<and> (n'' -asx'\\<rightarrow>\\<^sub>d* n') \\<and> \n        (as = asx@asx'))\"\nproof(induct rule:DynPDG_path.induct)\n  case (DynPDG_path_Nil n) thus ?case by auto\nnext\n  case (DynPDG_path_Append_cdep n as n'' as' n')\n  note IH = `as = [] \\<and> n = n'' \\<or>\n    (\\<exists>nx asx asx'. n -asx\\<rightarrow>\\<^bsub>cd\\<^esub> nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx') \\<or>\n    (\\<exists>nx V asx asx'. n -{V}asx\\<rightarrow>\\<^bsub>dd\\<^esub> nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx')`\n  from IH show ?case\n  proof\n    assume \"as = [] \\<and> n = n''\"\n    with `n'' -as'\\<rightarrow>\\<^bsub>cd\\<^esub> n'` have \"valid_node n'\"\n      by(fastforce intro:path_valid_node(2) DynPDG_path_CFG_path \n                        DynPDG_path_cdep)\n    with `as = [] \\<and> n = n''` `n'' -as'\\<rightarrow>\\<^bsub>cd\\<^esub> n'`\n    have \"\\<exists>n'' asx asx'. n -asx\\<rightarrow>\\<^bsub>cd\\<^esub> n'' \\<and> n'' -asx'\\<rightarrow>\\<^sub>d* n' \\<and> as@as' = asx@asx'\"\n      by(auto intro:DynPDG_path_Nil)\n    thus ?thesis by simp\n  next\n    assume \"(\\<exists>nx asx asx'. n -asx\\<rightarrow>\\<^bsub>cd\\<^esub> nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx') \\<or>\n      (\\<exists>nx V asx asx'. n -{V}asx\\<rightarrow>\\<^bsub>dd\\<^esub> nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx')\"\n    thus ?thesis\n    proof\n      assume \"\\<exists>nx asx asx'. n -asx\\<rightarrow>\\<^bsub>cd\\<^esub> nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx'\"\n      then obtain nx asx asx' where \"n -asx\\<rightarrow>\\<^bsub>cd\\<^esub> nx\" and \"nx -asx'\\<rightarrow>\\<^sub>d* n''\"\n        and \"as = asx@asx'\" by auto\n      from `n'' -as'\\<rightarrow>\\<^bsub>cd\\<^esub> n'` have \"n'' -as'\\<rightarrow>\\<^sub>d* n'\" by(rule DynPDG_path_cdep)\n      with `nx -asx'\\<rightarrow>\\<^sub>d* n''` have \"nx -asx'@as'\\<rightarrow>\\<^sub>d* n'\"\n        by(fastforce intro:DynPDG_path_Append)\n      with `n -asx\\<rightarrow>\\<^bsub>cd\\<^esub> nx` `as = asx@asx'`\n      have \"\\<exists>n'' asx asx'. n -asx\\<rightarrow>\\<^bsub>cd\\<^esub> n'' \\<and> n'' -asx'\\<rightarrow>\\<^sub>d* n' \\<and> as@as' = asx@asx'\"\n        by auto\n      thus ?thesis by simp\n    next\n      assume \"\\<exists>nx V asx asx'. n -{V}asx\\<rightarrow>\\<^bsub>dd\\<^esub> nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx'\"\n      then obtain nx V asx asx' where \"n -{V}asx\\<rightarrow>\\<^bsub>dd\\<^esub> nx\" and \"nx -asx'\\<rightarrow>\\<^sub>d* n''\"\n        and \"as = asx@asx'\" by auto\n      from `n'' -as'\\<rightarrow>\\<^bsub>cd\\<^esub> n'` have \"n'' -as'\\<rightarrow>\\<^sub>d* n'\" by(rule DynPDG_path_cdep)\n      with `nx -asx'\\<rightarrow>\\<^sub>d* n''` have \"nx -asx'@as'\\<rightarrow>\\<^sub>d* n'\"\n        by(fastforce intro:DynPDG_path_Append)\n      with `n -{V}asx\\<rightarrow>\\<^bsub>dd\\<^esub> nx` `as = asx@asx'`\n      have \"\\<exists>n'' V asx asx'. n -{V}asx\\<rightarrow>\\<^bsub>dd\\<^esub> n'' \\<and> n'' -asx'\\<rightarrow>\\<^sub>d* n' \\<and> as@as' = asx@asx'\"\n        by auto\n      thus ?thesis by simp\n    qed\n  qed\nnext\n  case (DynPDG_path_Append_ddep n as n'' V as' n')\n  note IH = `as = [] \\<and> n = n'' \\<or>\n    (\\<exists>nx asx asx'. n -asx\\<rightarrow>\\<^bsub>cd\\<^esub> nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx') \\<or>\n    (\\<exists>nx V asx asx'. n -{V}asx\\<rightarrow>\\<^bsub>dd\\<^esub> nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx')`\n  from IH show ?case\n  proof\n    assume \"as = [] \\<and> n = n''\"\n    with `n'' -{V}as'\\<rightarrow>\\<^bsub>dd\\<^esub> n'` have \"valid_node n'\"\n      by(fastforce intro:path_valid_node(2) DynPDG_path_CFG_path \n                        DynPDG_path_ddep)\n    with `as = [] \\<and> n = n''` `n'' -{V}as'\\<rightarrow>\\<^bsub>dd\\<^esub> n'`\n    have \"\\<exists>n'' V asx asx'. n -{V}asx\\<rightarrow>\\<^bsub>dd\\<^esub> n'' \\<and> n'' -asx'\\<rightarrow>\\<^sub>d* n' \\<and> as@as' = asx@asx'\"\n      by(fastforce intro:DynPDG_path_Nil)\n    thus ?thesis by simp\n  next\n    assume \"(\\<exists>nx asx asx'. n -asx\\<rightarrow>\\<^bsub>cd\\<^esub> nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx') \\<or>\n      (\\<exists>nx V asx asx'. n -{V}asx\\<rightarrow>\\<^bsub>dd\\<^esub> nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx')\"\n    thus ?thesis\n    proof\n      assume \"\\<exists>nx asx asx'. n -asx\\<rightarrow>\\<^bsub>cd\\<^esub> nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx'\"\n      then obtain nx asx asx' where \"n -asx\\<rightarrow>\\<^bsub>cd\\<^esub> nx\" and \"nx -asx'\\<rightarrow>\\<^sub>d* n''\"\n        and \"as = asx@asx'\" by auto\n      from `n'' -{V}as'\\<rightarrow>\\<^bsub>dd\\<^esub> n'` have \"n'' -as'\\<rightarrow>\\<^sub>d* n'\" by(rule DynPDG_path_ddep)\n      with `nx -asx'\\<rightarrow>\\<^sub>d* n''` have \"nx -asx'@as'\\<rightarrow>\\<^sub>d* n'\"\n        by(fastforce intro:DynPDG_path_Append)\n      with `n -asx\\<rightarrow>\\<^bsub>cd\\<^esub> nx` `as = asx@asx'`\n      have \"\\<exists>n'' asx asx'. n -asx\\<rightarrow>\\<^bsub>cd\\<^esub> n'' \\<and> n'' -asx'\\<rightarrow>\\<^sub>d* n' \\<and> as@as' = asx@asx'\"\n        by auto\n      thus ?thesis by simp\n    next\n      assume \"\\<exists>nx V asx asx'. n -{V}asx\\<rightarrow>\\<^bsub>dd\\<^esub> nx \\<and> nx -asx'\\<rightarrow>\\<^sub>d* n'' \\<and> as = asx@asx'\"\n      then obtain nx V' asx asx' where \"n -{V'}asx\\<rightarrow>\\<^bsub>dd\\<^esub> nx\" and \"nx -asx'\\<rightarrow>\\<^sub>d* n''\"\n        and \"as = asx@asx'\" by auto\n      from `n'' -{V}as'\\<rightarrow>\\<^bsub>dd\\<^esub> n'` have \"n'' -as'\\<rightarrow>\\<^sub>d* n'\" by(rule DynPDG_path_ddep)\n      with `nx -asx'\\<rightarrow>\\<^sub>d* n''` have \"nx -asx'@as'\\<rightarrow>\\<^sub>d* n'\"\n        by(fastforce intro:DynPDG_path_Append)\n      with `n -{V'}asx\\<rightarrow>\\<^bsub>dd\\<^esub> nx` `as = asx@asx'`\n      have \"\\<exists>n'' V asx asx'. n -{V}asx\\<rightarrow>\\<^bsub>dd\\<^esub> n'' \\<and> n'' -asx'\\<rightarrow>\\<^sub>d* n' \\<and> as@as' = asx@asx'\"\n        by auto\n      thus ?thesis by simp\n    qed\n  qed\nqed\n\n\nlemma DynPDG_path_rev_cases [consumes 1,\n  case_names DynPDG_path_Nil DynPDG_path_cdep_Append DynPDG_path_ddep_Append]:\n  \"\\<lbrakk>n -as\\<rightarrow>\\<^sub>d* n'; \\<lbrakk>as = []; n = n'\\<rbrakk> \\<Longrightarrow> Q;\n    \\<And>n'' asx asx'. \\<lbrakk>n -asx\\<rightarrow>\\<^bsub>cd\\<^esub> n''; n'' -asx'\\<rightarrow>\\<^sub>d* n'; \n                       as = asx@asx'\\<rbrakk> \\<Longrightarrow> Q;\n    \\<And>V n'' asx asx'. \\<lbrakk>n -{V}asx\\<rightarrow>\\<^bsub>dd\\<^esub> n''; n'' -asx'\\<rightarrow>\\<^sub>d* n'; \n                       as = asx@asx'\\<rbrakk> \\<Longrightarrow> Q\\<rbrakk>\n  \\<Longrightarrow> Q\"\nby(blast dest:DynPDG_path_split)\n\n\n\nlemma DynPDG_ddep_edge_no_shorter_ddep_edge:\n  assumes ddep:\"n -{V}as\\<rightarrow>\\<^bsub>dd\\<^esub> n'\"\n  shows \"\\<forall>as' a as''. tl as = as'@a#as'' \\<longrightarrow> \\<not> sourcenode a -{V}a#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'\"\nproof -\n  from ddep have influence:\"n influences V in n' via as\"\n    by(auto elim!:DynPDG_edge.cases)\n  then obtain  a asx where as:\"as = a#asx\"\n    and notin:\"n \\<notin> set (sourcenodes asx)\"\n    by(auto dest:dyn_influence_source_notin_tl_edges simp:dyn_data_dependence_def)\n  from influence as\n  have imp:\"\\<forall>nx \\<in> set (sourcenodes asx). V \\<notin> Def nx\"\n    by(auto simp:dyn_data_dependence_def)\n  { fix as' a' as'' \n    assume eq:\"tl as = as'@a'#as''\"\n      and ddep':\"sourcenode a' -{V}a'#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'\"\n    from eq as notin have noteq:\"sourcenode a' \\<noteq> n\" by(auto simp:sourcenodes_def)\n    from ddep' have \"V \\<in> Def (sourcenode a')\"\n      by(auto elim!:DynPDG_edge.cases simp:dyn_data_dependence_def)\n    with eq as noteq imp have False by(auto simp:sourcenodes_def) }\n  thus ?thesis by blast\nqed\n\n\n\nlemma no_ddep_same_state:\n  assumes path:\"n -as\\<rightarrow>* n'\" and Uses:\"V \\<in> Use n'\" and preds:\"preds (kinds as) s\"\n  and no_dep:\"\\<forall>as' a as''. as = as'@a#as'' \\<longrightarrow> \\<not> sourcenode a -{V}a#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'\"\n  shows \"state_val (transfers (kinds as) s) V = state_val s V\"\nproof -\n  { fix n''\n    assume inset:\"n'' \\<in> set (sourcenodes as)\" and Defs:\"V \\<in> Def n''\"\n    hence \"\\<exists>nx \\<in> set (sourcenodes as). V \\<in> Def nx\" by auto\n    then obtain nx ns' ns'' where nodes:\"sourcenodes as = ns'@nx#ns''\"\n        and Defs':\"V \\<in> Def nx\" and notDef:\"\\<forall>nx' \\<in> set ns''. V \\<notin> Def nx'\"\n      by(fastforce elim!:rightmost_element_property)\n    from nodes obtain as' a as''\n      where as'':\"sourcenodes as'' = ns''\" and as:\"as=as'@a#as''\"\n      and source:\"sourcenode a = nx\"\n      by(fastforce elim:map_append_append_maps simp:sourcenodes_def)\n    from as path have path':\"sourcenode a -a#as''\\<rightarrow>* n'\"\n      by(fastforce dest:path_split_second)\n    from notDef as'' source\n    have \"\\<forall>n'' \\<in> set (sourcenodes as''). V \\<notin> Def n''\"\n      by(auto simp:sourcenodes_def)\n    with path' Defs' Uses source\n    have influence:\"nx influences V in n' via (a#as'')\"\n      by(simp add:dyn_data_dependence_def)\n    hence \"nx \\<notin> set (sourcenodes as'')\" by(rule dyn_influence_source_notin_tl_edges)\n    with influence source\n    have \"\\<exists>asx a'. sourcenode a' -{V}a'#asx\\<rightarrow>\\<^bsub>dd\\<^esub> n' \\<and> sourcenode a' = nx \\<and>\n          (\\<exists>asx'. a#as'' = asx'@a'#asx)\"\n      by(fastforce intro:DynPDG_ddep_edge)\n    with nodes no_dep as have False by(auto simp:sourcenodes_def) }\n  hence \"\\<forall>n \\<in> set (sourcenodes as). V \\<notin> Def n\" by auto\n  with wf path preds show ?thesis by(fastforce intro:CFG_path_no_Def_equal)\nqed\n\n\nlemma DynPDG_ddep_edge_only_first_edge:\n  \"\\<lbrakk>n -{V}a#as\\<rightarrow>\\<^bsub>dd\\<^esub> n'; preds (kinds (a#as)) s\\<rbrakk> \\<Longrightarrow> \n    state_val (transfers (kinds (a#as)) s) V = state_val (transfer (kind a) s) V\"\n  apply -\n  apply(erule DynPDG_edge.cases)\n  apply auto\n  apply(frule dyn_influence_Cons_source)\n  apply(frule dyn_influence_source_notin_tl_edges)\n  by(erule dyn_influence_only_first_edge)\n\n\nlemma Use_value_change_implies_DynPDG_ddep_edge:\n  assumes \"n -as\\<rightarrow>* n'\" and \"V \\<in> Use n'\" and \"preds (kinds as) s\" \n  and \"preds (kinds as) s'\" and \"state_val s V = state_val s' V\"\n  and \"state_val (transfers (kinds as) s) V \\<noteq> \n             state_val (transfers (kinds as) s') V\"\n  obtains as' a as'' where \"as = as'@a#as''\"\n  and \"sourcenode a -{V}a#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'\"\n  and \"state_val (transfers (kinds as) s) V = \n       state_val (transfers (kinds (as'@[a])) s) V\"\n  and \"state_val (transfers (kinds as) s') V = \n       state_val (transfers (kinds (as'@[a])) s') V\"\nproof(atomize_elim)\n  show \"\\<exists>as' a as''. as = as'@a#as'' \\<and>\n                     sourcenode a -{V}a#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n' \\<and>\n             state_val (transfers (kinds as) s) V = \n             state_val (transfers (kinds (as'@[a])) s) V \\<and>\n             state_val (transfers (kinds as) s') V = \n             state_val (transfers (kinds (as'@[a])) s') V\"\n  proof(cases \"\\<forall>as' a as''. as = as'@a#as'' \\<longrightarrow>\n                 \\<not> sourcenode a -{V}a#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'\")\n    case True\n    with `n -as\\<rightarrow>* n'` `V \\<in> Use n'` `preds (kinds as) s` `preds (kinds as) s'`\n    have \"state_val (transfers (kinds as) s) V = state_val s V\"\n      and \"state_val (transfers (kinds as) s') V = state_val s' V\"\n      by(auto intro:no_ddep_same_state)\n    with `state_val s V = state_val s' V` \n      `state_val (transfers (kinds as) s) V \\<noteq> state_val (transfers (kinds as) s') V`\n    show ?thesis by simp\n  next\n    case False\n    then obtain as' a as'' where [simp]:\"as = as'@a#as''\"\n      and \"sourcenode a -{V}a#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'\" by auto\n    from `preds (kinds as) s` have \"preds (kinds (a#as'')) (transfers (kinds as') s)\"\n      by(simp add:kinds_def preds_split)\n    with `sourcenode a -{V}a#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'` have all:\n      \"state_val (transfers (kinds (a#as'')) (transfers (kinds as') s)) V = \n       state_val (transfer (kind a) (transfers (kinds as') s)) V\"\n      by(auto dest!:DynPDG_ddep_edge_only_first_edge)\n    from `preds (kinds as) s'` \n    have \"preds (kinds (a#as'')) (transfers (kinds as') s')\"\n      by(simp add:kinds_def preds_split)\n    with `sourcenode a -{V}a#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'` have all':\n      \"state_val (transfers (kinds (a#as'')) (transfers (kinds as') s')) V = \n       state_val (transfer (kind a) (transfers (kinds as') s')) V\"\n      by(auto dest!:DynPDG_ddep_edge_only_first_edge)\n    hence eq:\"\\<And>s. transfers (kinds as) s =\n      transfers (kinds (a#as'')) (transfers (kinds as') s)\"\n      by(simp add:transfers_split[THEN sym] kinds_def)\n    with all have \"state_val (transfers (kinds as) s) V = \n                   state_val (transfers (kinds (as'@[a])) s) V\"\n      by(simp add:transfers_split kinds_def)\n    moreover\n    from eq all' have \"state_val (transfers (kinds as) s') V = \n                       state_val (transfers (kinds (as'@[a])) s') V\"\n      by(simp add:transfers_split kinds_def)\n    ultimately show ?thesis using `sourcenode a -{V}a#as''\\<rightarrow>\\<^bsub>dd\\<^esub> n'` by simp blast\n  qed\nqed\n\n\nend\n\n\nsubsection {* Instantiate dynamic PDG *}\n\nsubsubsection {* Standard control dependence *}\n\nlocale DynStandardControlDependencePDG =\n  Postdomination sourcenode targetnode kind valid_edge Entry Exit +\n  CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use state_val Exit\n  for sourcenode :: \"'edge \\<Rightarrow> 'node\" and targetnode :: \"'edge \\<Rightarrow> 'node\"\n  and kind :: \"'edge \\<Rightarrow> 'state edge_kind\" and valid_edge :: \"'edge \\<Rightarrow> bool\"\n  and Entry :: \"'node\" (\"'('_Entry'_')\") and Def :: \"'node \\<Rightarrow> 'var set\"\n  and Use :: \"'node \\<Rightarrow> 'var set\" and state_val :: \"'state \\<Rightarrow> 'var \\<Rightarrow> 'val\"\n  and Exit :: \"'node\" (\"'('_Exit'_')\")\n\nbegin\n\nlemma DynPDG_scd:\n  \"DynPDG sourcenode targetnode kind valid_edge (_Entry_) \n          Def Use state_val (_Exit_) dyn_standard_control_dependence\"\nproof(unfold_locales)\n  fix n n' as assume \"n controls\\<^sub>s n' via as\"\n  show \"n' \\<noteq> (_Exit_)\"\n  proof\n    assume \"n' = (_Exit_)\"\n    with `n controls\\<^sub>s n' via as` show False\n      by(fastforce intro:Exit_not_dyn_standard_control_dependent)\n  qed\nnext\n  fix n n' as assume \"n controls\\<^sub>s n' via as\"\n  thus \"n -as\\<rightarrow>* n' \\<and> as \\<noteq> []\"\n    by(fastforce simp:dyn_standard_control_dependence_def)\nqed\n\n\nend\n\nsubsubsection {* Weak control dependence *}\n\nlocale DynWeakControlDependencePDG = \n  StrongPostdomination sourcenode targetnode kind valid_edge Entry Exit +\n  CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use state_val Exit\n  for sourcenode :: \"'edge \\<Rightarrow> 'node\" and targetnode :: \"'edge \\<Rightarrow> 'node\"\n  and kind :: \"'edge \\<Rightarrow> 'state edge_kind\" and valid_edge :: \"'edge \\<Rightarrow> bool\"\n  and Entry :: \"'node\" (\"'('_Entry'_')\") and Def :: \"'node \\<Rightarrow> 'var set\"\n  and Use :: \"'node \\<Rightarrow> 'var set\" and state_val :: \"'state \\<Rightarrow> 'var \\<Rightarrow> 'val\"\n  and Exit :: \"'node\" (\"'('_Exit'_')\")\n\nbegin\n\n\n\n\nend\n\n\nsubsection {* Data slice *}\n\ndefinition (in CFG) empty_control_dependence :: \"'node \\<Rightarrow> 'node \\<Rightarrow> 'edge list \\<Rightarrow> bool\"\nwhere \"empty_control_dependence n n' as \\<equiv> False\"\n\nlemma (in CFGExit_wf) DynPDG_scd:\n  \"DynPDG sourcenode targetnode kind valid_edge (_Entry_)\n          Def Use state_val  (_Exit_) empty_control_dependence\"\nproof(unfold_locales)\n  fix n n' as assume \"empty_control_dependence n n' as\"\n  thus \"n' \\<noteq> (_Exit_)\" by(simp add:empty_control_dependence_def)\nnext\n  fix n n' as assume \"empty_control_dependence n n' as\"\n  thus \"n -as\\<rightarrow>* n' \\<and> as \\<noteq> []\" by(simp add:empty_control_dependence_def)\nqed\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Slicing/Dynamic/DynPDG.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6113819732941511, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.2723887262933196}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\nsection \"Additional Syntax for Word Bit Operations\"\n\ntheory Word_Syntax\nimports\n  \"HOL-Word.WordBitwise\"\n  WordBitwise_Signed\n  Hex_Words\n  Norm_Words\n  Word_Type_Syntax\nbegin\n\ntext \\<open>Additional bit and type syntax that forces word types.\\<close>\n\ntype_synonym word8 = \"8 word\"\ntype_synonym word16 = \"16 word\"\ntype_synonym word32 = \"32 word\"\ntype_synonym word64 = \"64 word\"\n\nlemma len8: \"len_of (x :: 8 itself) = 8\" by simp\nlemma len16: \"len_of (x :: 16 itself) = 16\" by simp\nlemma len32: \"len_of (x :: 32 itself) = 32\" by simp\nlemma len64: \"len_of (x :: 64 itself) = 64\" by simp\n\n\nabbreviation\n  wordNOT  :: \"'a::len0 word \\<Rightarrow> 'a word\"      (\"~~ _\" [70] 71)\nwhere\n  \"~~ x == NOT x\"\n\nabbreviation\n  wordAND  :: \"'a::len0 word \\<Rightarrow> 'a word \\<Rightarrow> 'a word\" (infixr \"&&\" 64)\nwhere\n  \"a && b == a AND b\"\n\nabbreviation\n  wordOR   :: \"'a::len0 word \\<Rightarrow> 'a word \\<Rightarrow> 'a word\" (infixr \"||\"  59)\nwhere\n  \"a || b == a OR b\"\n\nabbreviation\n  wordXOR  :: \"'a::len0 word \\<Rightarrow> 'a word \\<Rightarrow> 'a word\" (infixr \"xor\" 59)\nwhere\n  \"a xor b == a XOR b\"\n\n(* testing for presence of word_bitwise *)\nlemma \"((x :: word32) >> 3) AND 7 = (x AND 56) >> 3\"\n  by word_bitwise\n\n(* FIXME: move to Word distribution *)\nlemma bin_nth_minus_Bit0[simp]:\n  \"0 < n \\<Longrightarrow> bin_nth (numeral (num.Bit0 w)) n = bin_nth (numeral w) (n - 1)\"\n  by (cases n; simp)\n\nlemma bin_nth_minus_Bit1[simp]:\n  \"0 < n \\<Longrightarrow> bin_nth (numeral (num.Bit1 w)) n = bin_nth (numeral w) (n - 1)\"\n  by (cases n; simp)\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "tlb", "sha": "88bb017dd96c3830baed93ba62e45b45050d1417", "save_path": "github-repos/isabelle/SEL4PROJ-tlb", "path": "github-repos/isabelle/SEL4PROJ-tlb/tlb-88bb017dd96c3830baed93ba62e45b45050d1417/Word_Lib/Word_Syntax.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621765155565326, "lm_q2_score": 0.4843800842769844, "lm_q1q2_score": 0.2723071079838147}}
{"text": "subsection \\<^marker>\\<open>tag aponly\\<close> \\<open>Single Non-Empty World Structures\\<close>\n\ntheory SingleWorldStructure\n  imports ParticularStructureMorphisms\nbegin\n\nlocale single_world_particular_struct = \n    particular_struct where Typ\\<^sub>p = Typ\\<^sub>p and Typ\\<^sub>q = Typ\\<^sub>q\n  for Typ\\<^sub>p :: \\<open>'p itself\\<close> and Typ\\<^sub>q :: \\<open>'q itself\\<close> +\n  assumes\n    only_empty_and_another_world: \\<open>\\<exists>w \\<noteq> \\<emptyset>. \\<W> = {\\<emptyset>,w}\\<close>\nbegin\n\ndefinition \\<open>\\<w> \\<equiv> THE w. w \\<noteq> \\<emptyset> \\<and> w \\<in> \\<W>\\<close>\n\nlemma \\<^marker>\\<open>tag (proof) aponly\\<close> sw_non_empty_world_unique: \\<open>\\<exists>!w. w \\<noteq> \\<emptyset> \\<and> w \\<in> \\<W>\\<close>\n  using only_empty_and_another_world \n  by (metis empty_iff insert_iff)\n\nlemma \\<^marker>\\<open>tag (proof) aponly\\<close> single_world[simp,intro!]: \\<open>\\<w> \\<in> \\<W>\\<close> \\<open>\\<w> \\<noteq> \\<emptyset>\\<close>\n  by (simp only: \\<w>_def ; rule the1I2[OF sw_non_empty_world_unique] ; simp)+\n\nlemma \\<^marker>\\<open>tag (proof) aponly\\<close> sw_worlds_case[cases set]:\n  assumes \\<open>w \\<in> \\<W>\\<close>\n  obtains (empty) \\<open>w = \\<emptyset>\\<close> | (single) \\<open>w = \\<w>\\<close>\n  using assms only_empty_and_another_world single_world\n  by blast \n\nlemma \\<^marker>\\<open>tag (proof) aponly\\<close> sw_in_worlds[dest!]: \\<open>\\<lbrakk> w \\<in> \\<W> ; x \\<in> w \\<rbrakk> \\<Longrightarrow> w = \\<w> \\<and> x \\<in> \\<w>\\<close>  \n  using sw_worlds_case by auto\n\nlemma \\<^marker>\\<open>tag (proof) aponly\\<close> sw_particulars_simp[simp]: \\<open>endurants = \\<w>\\<close>\n  apply (simp only: \\<P>_def)\n  by blast\n\nlemma \\<^marker>\\<open>tag (proof) aponly\\<close> sw_worlds_simp: \\<open>\\<W> = {\\<emptyset>, \\<w>}\\<close> \n  using only_empty_and_another_world single_world(2) by blast\n\nlemma \\<^marker>\\<open>tag (proof) aponly\\<close> sw_particulars_I[iff]: \\<open>x \\<in> \\<P> \\<longleftrightarrow> x \\<in> \\<w>\\<close> \n  by (simp only: sw_particulars_simp)\n\nlemma \\<^marker>\\<open>tag (proof) aponly\\<close> sw_ed_iff[simp]: \\<open>ed x y \\<longleftrightarrow> x \\<in> \\<w> \\<and> y \\<in> \\<w>\\<close>\n  apply (simp only: ed_def ; intro iffI conjI ballI impI ; simp?)\n  by blast\n\nlemma \\<^marker>\\<open>tag (proof) aponly\\<close> sw_no_indep[simp]: \\<open>\\<not> indep x y\\<close>\n  by (simp add: indep_def)\n\n\nlemma \\<^marker>\\<open>tag (proof) aponly\\<close> sw_empty_world[simp,intro!]: \\<open>\\<emptyset> \\<in> \\<W>\\<close>   \n  by (simp add: sw_worlds_simp)\n\nend\n\nlocale single_world_pre_particular_struct_morphism =\n   pre_particular_struct_morphism where Typ\\<^sub>p\\<^sub>1 = \\<open>Typ\\<^sub>p\\<^sub>1\\<close> and Typ\\<^sub>p\\<^sub>2 = \\<open>Typ\\<^sub>p\\<^sub>2\\<close> and Typ\\<^sub>q = \\<open>Typ\\<^sub>q\\<close> +\n   src: single_world_particular_struct where \\<Gamma> = \\<open>\\<Gamma>\\<^sub>1\\<close> and Typ\\<^sub>p = \\<open>Typ\\<^sub>p\\<^sub>1\\<close> and Typ\\<^sub>q = \\<open>Typ\\<^sub>q\\<close> +\n   tgt: single_world_particular_struct where \\<Gamma> = \\<open>\\<Gamma>\\<^sub>2\\<close> and Typ\\<^sub>p = \\<open>Typ\\<^sub>p\\<^sub>2\\<close> and Typ\\<^sub>q = \\<open>Typ\\<^sub>q\\<close>\n  for\n    Typ\\<^sub>p\\<^sub>1 :: \\<open>'p\\<^sub>1 itself\\<close> and\n    Typ\\<^sub>p\\<^sub>2 :: \\<open>'p\\<^sub>2 itself\\<close> and\n    Typ\\<^sub>q :: \\<open>'q itself\\<close>  \nbegin\n\nlemma \\<^marker>\\<open>tag (proof) aponly\\<close> sw_world_corresp_iff[simp]:\n  \\<open>w\\<^sub>s \\<Leftrightarrow> w\\<^sub>t \\<longleftrightarrow> (w\\<^sub>s = \\<emptyset> \\<and> w\\<^sub>t = \\<emptyset>) \\<or> \n      (w\\<^sub>s = src.\\<w> \\<and> w\\<^sub>t = tgt.\\<w> \\<and> \\<phi> ` src.\\<w> \\<subseteq> tgt.\\<w>)\\<close>\n  apply (intro iffI conjI disjCI \n        ; (elim conjE disjE)?\n        ; simp\n        ; (elim world_corresp_E)? \n        ; (intro world_corresp_I)?\n        ; simp?)\n  subgoal by blast\n  subgoal by (metis Set.subset_empty  empty_is_image image_subsetI morph_preserves_particulars  \n              src.sw_in_worlds src.sw_particulars_simp src.sw_worlds_case \n              tgt.sw_particulars_simp tgt.sw_worlds_case)\n  subgoal by blast\n  done\n\nlemma \\<^marker>\\<open>tag (proof) aponly\\<close> sw_particular_struct_morphism_iff:\n  \\<open>particular_struct_morphism \\<Gamma>\\<^sub>1 \\<Gamma>\\<^sub>2 \\<phi> \\<longleftrightarrow> \n    \\<phi> ` src.\\<w> \\<subseteq> tgt.\\<w> \\<close>   \n    (is \\<open>?P \\<longleftrightarrow> ?Q\\<close>)\nproof\n  assume \\<open>?P\\<close>\n  then interpret phi: particular_struct_morphism \\<Gamma>\\<^sub>1 \\<Gamma>\\<^sub>2 \\<phi> by simp\n  show \\<open>?Q\\<close>\n    apply (intro conjI ballI impI subsetI ; (elim conjE imageE)? ; simp)\n    using morph_preserves_particulars by blast\nnext\n  assume A: \\<open>?Q\\<close>\n  show \\<open>?P\\<close>\n    apply (unfold_locales ; simp)\n    subgoal G1 for w\\<^sub>s\n      apply (cases w\\<^sub>s rule: src.sw_worlds_case ; simp)\n       apply (intro exI[of _ \\<emptyset>] ; simp)        \n      using A by linarith\n    subgoal G2 for w\\<^sub>t\n      apply (cases w\\<^sub>t rule: tgt.sw_worlds_case ; simp)\n      apply (intro exI[of _ \\<emptyset>] ; simp)\n      using A by linarith\n    done\nqed    \n\nend\n\nlocale single_world_particular_struct_morphism =\n    single_world_pre_particular_struct_morphism  \n      where Typ\\<^sub>p\\<^sub>1 = \\<open>Typ\\<^sub>p\\<^sub>1\\<close> and Typ\\<^sub>p\\<^sub>2 = \\<open>Typ\\<^sub>p\\<^sub>2\\<close> and Typ\\<^sub>q = \\<open>Typ\\<^sub>q\\<close> \n  for\n    Typ\\<^sub>p\\<^sub>1 :: \\<open>'p\\<^sub>1 itself\\<close> and\n    Typ\\<^sub>p\\<^sub>2 :: \\<open>'p\\<^sub>2 itself\\<close> and\n    Typ\\<^sub>q :: \\<open>'q itself\\<close>  +\n  assumes\n    image_subset: \\<open>\\<phi> ` src.\\<w> \\<subseteq> tgt.\\<w>\\<close> and\n    morph_closes_quale_assoc_1:\n      \\<open>\\<And>x\\<^sub>t y\\<^sub>t q. \\<lbrakk> x\\<^sub>t \\<in> \\<phi> ` src.\\<w> ; y\\<^sub>t \\<in> tgt.\\<w> ; q \\<in> \\<Q>\\<^sub>s ; y\\<^sub>t \\<triangleleft>\\<^sub>t x\\<^sub>t ; y\\<^sub>t \\<leadsto>\\<^sub>t q \\<rbrakk>\n            \\<Longrightarrow> y\\<^sub>t \\<in> \\<phi> ` src.\\<w>\\<close>\n\nsublocale single_world_particular_struct_morphism \\<subseteq> particular_struct_morphism\n  apply (simp only: sw_particular_struct_morphism_iff)\n  using image_subset morph_closes_quale_assoc_1 by metis\n\nend", "meta": {"author": "joaoraf", "repo": "thesis-isabelle-sources", "sha": "5930e1d4899aed5d314c7a132bbed73bfe3ee607", "save_path": "github-repos/isabelle/joaoraf-thesis-isabelle-sources", "path": "github-repos/isabelle/joaoraf-thesis-isabelle-sources/thesis-isabelle-sources-5930e1d4899aed5d314c7a132bbed73bfe3ee607/ParticularStructures/SingleWorldStructure.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621765008857981, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.27230710087760307}}
{"text": "theory \"Lowe_modified_BAN_concrete_Andrew_Secure_RPC_cert_auto\"\nimports\n  \"ESPLogic\"\nbegin\n\n(* section:  Lowe modified BAN concrete Andrew Secure RPC  *)\n\n(* text: \n  Modeled after the model in the SPORE library.\n\n  Notable differences:\n\n    1. 'succ(x)' is invertible. Hence, we just model it as a tuple ('succ',x) of\n       a global constant 'succ' and the variable x.  This means that we only\n       exploit the tagging properties of 'succ', but do not assume any\n       information hiding.\n\n    2. Instead of implicit typing, we are using explicit global constants to\n       discern messages.\n *)\n\nrole A\nwhere \"A =\n  [ Send ''1'' <| sAV ''A'', sN ''Na'' |>\n  , Recv ''2'' <| sMV ''B'',\n                  PEnc <| sC ''2'', sN ''Na'', sMV ''Kab'', sMV ''B'' |>\n                       ( sKbd (AVar ''A'') (MVar ''B'') )\n               |>\n  , Send ''3'' ( PEnc <| sC ''3'', sN ''Na'' |> ( sMV ''Kab'' ) )\n  , Recv ''4'' ( sMV ''Nb'' )\n  ]\"\n\nrole B\nwhere \"B =\n  [ Recv ''1'' <| sMV ''A'', sMV ''Na'' |>\n  , Send ''2'' <| sAV ''B'',\n                  PEnc <| sC ''2'', sMV ''Na'', sN ''Kab'', sAV ''B'' |>\n                       ( sKbd (MVar ''A'') (AVar ''B'') )\n               |>\n  , Recv ''3'' ( PEnc <| sC ''3'', sMV ''Na'' |> ( sN ''Kab'' ) )\n  , Send ''4'' ( sN ''Nb'' )\n  ]\"\n\nprotocol Andrew\nwhere \"Andrew = { A, B }\"\n\nlocale restricted_Andrew_state = Andrew_state\n\ntype_invariant Andrew_msc_typing for Andrew\nwhere \"Andrew_msc_typing = mk_typing\n  [ ((B, ''A''), (KnownT B_1))\n  , ((A, ''B''), (KnownT A_2))\n  , ((A, ''Kab''), (SumT (KnownT A_2) (NonceT B ''Kab'')))\n  , ((B, ''Na''), (KnownT B_1))\n  , ((A, ''Nb''), (KnownT A_4))\n  ]\"\n\nsublocale Andrew_state < Andrew_msc_typing_state\nproof -\n  have \"(t,r,s) : approx Andrew_msc_typing\"\n  proof(cases rule: reachable_in_approxI_ext\n        [OF Andrew_msc_typing.monoTyp, completeness_cases_rule])\n    case (A_2_B t r s tid0)\n    then interpret state: Andrew_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = A_2_B\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (A_2_Kab t r s tid0)\n    then interpret state: Andrew_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = A_2_Kab\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''2'', LN ''Na'' tid0, s(MV ''Kab'' tid0), s(MV ''B'' tid0) |}\n            ( Kbd ( s(AV ''A'' tid0) ) ( s(MV ''B'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (B_1_A t r s tid0)\n    then interpret state: Andrew_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = B_1_A\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (B_1_Na t r s tid0)\n    then interpret state: Andrew_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = B_1_Na\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  qed\n  thus \"Andrew_msc_typing_state t r s\" by unfold_locales auto\nqed\n\ntext{* Prove secrecy of long-term keys. *}\ncontext Andrew_state begin\n\n  (* This rule is unsafe in general, but OK here, \n     as we are only reasoning about static compromise. \n  *)\n  lemma static_longterm_key_reveal[dest!]:\n    \"predOrd t (LKR a) e ==> RLKR a : reveals t\"\n    by (auto intro: compr_predOrdI)\n\n  lemma longterm_private_key_secrecy:\n    assumes facts:\n      \"SK m : knows t\"\n      \"RLKR m ~: reveals t\"\n    shows \"False\"\n  using facts by (sources \"SK m\")\n\n  lemma longterm_sym_ud_key_secrecy:\n    assumes facts:\n      \"K m1 m2 : knows t\"\n      \"RLKR m1 ~: reveals t\"\n      \"RLKR m2 ~: reveals t\"\n    shows \"False\"\n  using facts by (sources \"K m1 m2\")\n\n  lemma longterm_sym_bd_key_secrecy:\n    assumes facts:\n      \"Kbd m1 m2 : knows t\"\n      \"RLKR m1 ~: reveals t\"\n      \"RLKR m2 ~: reveals t\"\n      \"m1 : Agent\"\n      \"m2 : Agent\"\n    shows \"False\"\n  proof -\n    from facts \n    have \"KShr (agents {m1, m2}) : knows t\"\n      by (auto simp: Kbd_def)\n    thus ?thesis using facts\n    proof (sources \"KShr (agents {m1, m2})\")\n    qed (auto simp: agents_def Agent_def)\n  qed\n\n  lemmas ltk_secrecy =\n    longterm_sym_ud_key_secrecy\n    longterm_sym_ud_key_secrecy[OF in_knows_predOrd1]\n    longterm_sym_bd_key_secrecy\n    longterm_sym_bd_key_secrecy[OF in_knows_predOrd1]\n    longterm_private_key_secrecy\n    longterm_private_key_secrecy[OF in_knows_predOrd1]\n\nend\n\n(* text:  \nNote the additional B identity in the second message above. It guarantees that\ndespite using a bidirectional longterm symmetric key, we have agreement on the\ninvolved roles.\n *)\n\n(* subsection:  Security Properties  *)\n\nlemma (in restricted_Andrew_state) B_sec_Kab:\n  assumes facts:\n    \"roleMap r tid0 = Some B\"\n    \"RLKR(s(AV ''B'' tid0)) ~: reveals t\"\n    \"RLKR(s(MV ''A'' tid0)) ~: reveals t\"\n    \"LN ''Kab'' tid0 : knows t\"\n  shows \"False\"\nusing facts proof(sources! \" LN ''Kab'' tid0 \")\n  case B_2_Kab note_unified facts = this facts\n  thus ?thesis by (auto dest!: ltk_secrecy)\nqed (safe?, simp_all?, insert facts, (fastforce+)?)\n\nlemma (in restricted_Andrew_state) A_sec_Kab:\n  assumes facts:\n    \"roleMap r tid0 = Some A\"\n    \"RLKR(s(AV ''A'' tid0)) ~: reveals t\"\n    \"RLKR(s(MV ''B'' tid0)) ~: reveals t\"\n    \"( tid0, A_2 ) : steps t\"\n    \"s(MV ''Kab'' tid0) : knows t\"\n  shows \"False\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''2'', LN ''Na'' tid0, s(MV ''Kab'' tid0), s(MV ''B'' tid0) |}\n                       ( Kbd ( s(AV ''A'' tid0) ) ( s(MV ''B'' tid0) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (auto dest!: ltk_secrecy)\n  next\n    case (B_2_enc tid1) note_unified facts = this facts\n    thus ?thesis by (fastforce dest: B_sec_Kab intro: event_predOrdI)\n  qed (safe?, simp_all?, insert facts, (fastforce+)?)\nqed\n\nlemma (in restricted_Andrew_state) A_noninjective_agreement:\n  assumes facts:\n    \"roleMap r tid1 = Some A\"\n    \"RLKR(s(AV ''A'' tid1)) ~: reveals t\"\n    \"RLKR(s(MV ''B'' tid1)) ~: reveals t\"\n    \"( tid1, A_2 ) : steps t\"\n  shows\n    \"(?  tid2.\n        roleMap r tid2 = Some B &\n        s(AV ''A'' tid1) = s(MV ''A'' tid2) &\n        s(MV ''B'' tid1) = s(AV ''B'' tid2) &\n        LN ''Na'' tid1 = s(MV ''Na'' tid2) &\n        s(MV ''Kab'' tid1) = LN ''Kab'' tid2)\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''2'', LN ''Na'' tid1, s(MV ''Kab'' tid1), s(MV ''B'' tid1) |}\n                       ( Kbd ( s(AV ''A'' tid1) ) ( s(MV ''B'' tid1) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (auto dest!: ltk_secrecy)\n  next\n    case (B_2_enc tid2) note_unified facts = this facts\n    thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\n  qed (safe?, simp_all?, insert facts, (fastforce+)?)\nqed\n\nlemma (in restricted_Andrew_state) B_noninjective_agreement:\n  assumes facts:\n    \"roleMap r tid1 = Some B\"\n    \"RLKR(s(AV ''B'' tid1)) ~: reveals t\"\n    \"RLKR(s(MV ''A'' tid1)) ~: reveals t\"\n    \"( tid1, B_3 ) : steps t\"\n  shows\n    \"(?  tid2.\n        roleMap r tid2 = Some A &\n        s(MV ''A'' tid1) = s(AV ''A'' tid2) &\n        s(AV ''B'' tid1) = s(MV ''B'' tid2) &\n        s(MV ''Na'' tid1) = LN ''Na'' tid2 &\n        LN ''Kab'' tid1 = s(MV ''Kab'' tid2))\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''3'', s(MV ''Na'' tid1) |} ( LN ''Kab'' tid1 ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (fastforce dest: B_sec_Kab intro: event_predOrdI)\n  next\n    case (A_3_enc tid2) note_unified facts = this facts\n    thus ?thesis proof(sources! \"\n                     Enc {| LC ''2'', LN ''Na'' tid2, LN ''Kab'' tid1, s(MV ''B'' tid2) |}\n                         ( Kbd ( s(AV ''A'' tid2) ) ( s(MV ''B'' tid2) ) ) \")\n      case fake note_unified facts = this facts\n      thus ?thesis by (fastforce dest: B_sec_Kab intro: event_predOrdI)\n    next\n      case (B_2_enc tid3) note_unified facts = this facts\n      thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\n    qed (safe?, simp_all?, insert facts, (fastforce+)?)\n  qed (safe?, simp_all?, insert facts, (fastforce+)?)\nqed\n\nend", "meta": {"author": "meiersi", "repo": "scyther-proof", "sha": "84e42366a46f66f1b090651be3bfaa3497696280", "save_path": "github-repos/isabelle/meiersi-scyther-proof", "path": "github-repos/isabelle/meiersi-scyther-proof/scyther-proof-84e42366a46f66f1b090651be3bfaa3497696280/examples/spore/isabelle-proofs/Lowe_modified_BAN_concrete_Andrew_Secure_RPC_cert_auto.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621764862150636, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.27230709377139145}}
{"text": "(* *********************************************************************\n\n    Theory LA.thy is part of a framework for modelling,\n    verification and transformation of concurrent imperative\n    programs. Copyright (c) 2021  M. Bortin\n\n    The framework is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n    For more details see the license agreement (LICENSE) you should have\n    received along with the framework.\n    \n   ******************************************************************* *)\n   \ntheory LA\nimports Prelims\nbegin\n\ntext \"highlighting the type of relations between (abstract) states\"\ntype_synonym 'a staterel = \"('a \\<times> 'a) set\"\n\n\ntext \"an auxiliary annotation structure for the parallel components\"\nrecord 's annpar =\n  ap_rely :: \"'s staterel\"\n  ap_precond :: \"'s set\"\n  ap_postcond :: \"'s set\"\n\n\nsection \"A generic imperative language\"\n\n\ndatatype 's LA =\n    Skip \n  | Basic \"'s \\<Rightarrow> 's\"\n  | Seq \"'s LA\" \"'s LA\"  \n  | Cond \"'s set\" \"'s LA\" \"'s LA\"\n  | While \"'s set\" \"'s set\" \"'s LA\" \"'s LA\" \n  | Parallel \"('s LA \\<times> 's annpar) list\"\n  | Await \"'s set\" \"'s set\" \"'s LA\"\n  | CJump \"'s set\" nat \"'s LA\"\n\n\ntext \"the unconditional jump instruction\"\ndefinition \"Jump i = CJump UNIV i Skip\"\n\n\nfun jumpfree :: \"'s LA \\<Rightarrow> bool\"\nwhere \"jumpfree Skip = True\" |\n      \"jumpfree (Basic f) = True\" |\n      \"jumpfree (Seq p1 p2) = (jumpfree p1 \\<and> jumpfree p2)\" |\n      \"jumpfree (Parallel ps) = (\\<forall>p\\<in>set ps. jumpfree (fst p))\" |\n      \"jumpfree (Cond c p1 p2) = (jumpfree p1 \\<and> jumpfree p2)\" |\n      \"jumpfree (Await c a p) = jumpfree p\" |\n      \"jumpfree (While c i p q) = (jumpfree p \\<and> jumpfree q)\" |\n      \"jumpfree _ = False\"\n\n\nlemma jumpfree_Jump[simp] :\n\"jumpfree (Jump i) = False\"\n  by(simp add: Jump_def)\n\n\ntext \"locally sequential programs\"\nfun locally_seq :: \"'s LA \\<Rightarrow> bool\"\nwhere \"locally_seq (Seq p1 p2) = (locally_seq p1 \\<and> locally_seq p2)\" |\n      \"locally_seq (Parallel ps) = False\" |\n      \"locally_seq (Cond c p1 p2) = (locally_seq p1 \\<and> locally_seq p2)\" |\n      \"locally_seq (Await c a p) = locally_seq p\" |\n      \"locally_seq (While c i p q) = (locally_seq p \\<and> locally_seq q)\" |\n      \"locally_seq (CJump C i p) = locally_seq p\" |\n      \"locally_seq _ = True\" \n\n\nlemma locally_seq_Jump[simp] :\n\"locally_seq (Jump i) = True\"\n  by(simp add: Jump_def)\n\n\n\ntext \"the set of local jumps\"\nfun ljumps :: \"'s LA \\<Rightarrow> nat set\"\nwhere \"ljumps Skip = {}\" |\n      \"ljumps (Basic f) = {}\" |\n      \"ljumps (CJump C i p) = {i} \\<union> ljumps p\" |\n      \"ljumps (Seq p1 p2) = (ljumps p1 \\<union> ljumps p2)\" |\n      \"ljumps (Parallel ps) = (\\<Union>((ljumps \\<circ> fst) ` set ps))\" |\n      \"ljumps (Cond c p1 p2) = (ljumps p1 \\<union> ljumps p2)\" |\n      \"ljumps (Await c a p) = ljumps p\" |\n      \"ljumps (While c i p q) = (ljumps p \\<union> ljumps q)\"  \n\n\nlemma ljumps_Jump[simp] :\n\"ljumps (Jump i) = {i}\"\n  by(simp add: Jump_def)\n\n\n\n\n\n\nsection \"Concrete syntax for the LA programs\"\n\nsyntax\n  \"_quote\"     :: \"'b \\<Rightarrow> ('a \\<Rightarrow> 'b)\"                (\"(\\<guillemotleft>_\\<guillemotright>)\" [0] 1000)\n  \"_antiquote\" :: \"('a \\<Rightarrow> 'b) \\<Rightarrow> 'b\"                (\"\\<acute>_\" [1000] 1000)\n  \"_Assert\"    :: \"'a \\<Rightarrow> 'a set\"                    (\"(\\<lbrace>_\\<rbrace>)\" [0] 1000)\n\ntranslations\n  \"\\<lbrace>b\\<rbrace>\" \\<rightharpoonup> \"CONST Collect \\<guillemotleft>b\\<guillemotright>\"\n\nparse_translation \\<open>\n  let\n    fun quote_tr [t] = Syntax_Trans.quote_tr @{syntax_const \"_antiquote\"} t\n      | quote_tr ts = raise TERM (\"quote_tr\", ts);\n  in [(@{syntax_const \"_quote\"}, K quote_tr)] end\n\\<close>\n\nlemma neg_Collect[simp] :\n\"- Collect P = Collect (\\<lambda>x. \\<not> P x)\"\n  by fast\n\n\nsyntax\n  \"_fst\" :: \"'a \\<times> 'b \\<Rightarrow> 'a\"  (\"_\\<^sub>,\" [60] 61)\n  \"_snd\" :: \"'a \\<times> 'b \\<Rightarrow> 'b\"  (\"_\\<^sub>.\" [60] 61)\n\n\nparse_translation \\<open>\n  let\n    fun fst_tr ((Const (@{const_syntax Pair}, _) $ p $ c)\n          :: ts) = p;\n\n    fun snd_tr ((Const (@{const_syntax Pair}, _) $ p $ c)\n          :: ts) = c;\n  in\n   [(@{syntax_const \"_fst\"}, K fst_tr),\n    (@{syntax_const \"_snd\"}, K snd_tr)]\n  end\n\\<close>\n\n\nsyntax\n  \"_Assign\"    :: \"idt \\<Rightarrow> 'b \\<Rightarrow> 's LA\"\n                   (\"(\\<acute>_ :=/ _)\" [70, 65] 61)\n\ntranslations\n  \"\\<acute>x := a\" \\<rightleftharpoons> \"(CONST Basic \\<guillemotleft>\\<acute>(_update_name x (\\<lambda>_. a))\\<guillemotright>)\"\n\nsyntax\n  \"_before\" :: \"id \\<Rightarrow> 'a\" (\"\\<ordmasculine>_\")\n  \"_after\"  :: \"id \\<Rightarrow> 'a\" (\"\\<ordfeminine>_\")\n\ntranslations\n  \"\\<ordmasculine>x\" \\<rightleftharpoons> \"x \\<acute> CONST fst\"\n  \"\\<ordfeminine>x\" \\<rightleftharpoons> \"x \\<acute> CONST snd\"\n\n\nsyntax\n  \"_Seq\"  :: \"'s LA \\<Rightarrow> 's LA \\<Rightarrow> 's LA\"\n            (\"(_;//_)\" [56, 55] 55)\n            \n\n  \"_Cond\"        :: \"'s set  \\<Rightarrow> 's LA  \\<Rightarrow> 's LA \\<Rightarrow> 's LA\"\n                    (\"(IF _//(2THEN/ (_))//(2ELSE/ (_))//FI)\" [0, 0, 0] 61)\n  \"_Cond2\"       :: \"'s set  \\<Rightarrow> 's LA  \\<Rightarrow> 's LA\"\n                    (\"(IF _//(2THEN/ (_))//FI)\" [0,0] 56)\n\n\n  \"_While_inv\"   :: \"'s set  \\<Rightarrow> 's set \\<Rightarrow> 's LA  \\<Rightarrow> 's LA  \\<Rightarrow> 's LA\"\n  (\"(WHILE _/ \\<lbrakk> inv: _/\\<rbrakk>//(2DO/ (_))//SUBSEQUENTLY _//OD)\"  [0, 0, 0, 0] 61)\n\n  \"_While\"       :: \"'s set  \\<Rightarrow> 's LA  \\<Rightarrow> 's LA \\<Rightarrow> 's LA\"\n                    (\"(WHILE _//(2DO/ (_))//SUBSEQUENTLY _//OD)\"  [0, 0, 0] 61)\n\n  \"_WhileS\"      :: \"'s set  \\<Rightarrow> 's set \\<Rightarrow> 's LA  \\<Rightarrow> 's LA\"\n                    (\"(WHILE _/ \\<lbrakk> inv: _/\\<rbrakk>//(2DO/ (_))//OD)\"  [0, 0, 0] 61)\n  \"_WhileS5\"     :: \"'s set  \\<Rightarrow> 's LA  \\<Rightarrow> 's LA\"\n                    (\"(WHILE _//(2DO/ (_))//OD)\"  [0, 0] 61)\n\n  \"_AwaitA\"       :: \"'s set  \\<Rightarrow> 's set \\<Rightarrow> 's LA  \\<Rightarrow> 's LA\"\n                    (\"(AWAIT _/ \\<lbrakk> ann: _/\\<rbrakk>//(2THEN/ (_))/ END)\"  [0,0,0] 61)\n  \"_AtomA\"        :: \"'s set  \\<Rightarrow> 's LA  \\<Rightarrow> 's LA\"\n                    (\"(\\<lbrakk> ann: _/\\<rbrakk>\\<langle>_\\<rangle>)\" [0,0] 61)\n  \"_WaitA\"        :: \"'s set  \\<Rightarrow> 's set  \\<Rightarrow> 's LA\"\n                    (\"(WAIT _/ \\<lbrakk> ann: _/\\<rbrakk> END)\" [0,0] 61)\n\n  \"_Await\"       :: \"'s set  \\<Rightarrow> 's LA  \\<Rightarrow> 's LA\"\n                    (\"(AWAIT _/ (2THEN/ (_))/ END)\"  [0,0] 61)\n  \"_Atom\"        :: \"'s set  \\<Rightarrow> 's LA  \\<Rightarrow> 's LA\"\n                    (\"(\\<langle>_\\<rangle>)\" [0] 61)\n  \"_Wait\"        :: \"'s set  \\<Rightarrow> 's LA\"\n                    (\"(WAIT _/ END)\" [0] 61)  \n\n\n  \"_Jump\"        :: \"nat \\<Rightarrow> 's LA\" (\"JUMP _/\" [0] 61)\n\n  \"_CJump\"       :: \"'s set \\<Rightarrow> nat \\<Rightarrow> 's LA \\<Rightarrow> 's LA\" \n                    (\"CJUMP _/ TO/ _//(2OTHERWISE/ (_))//END \" [0,0,0] 61)\n\n  \"_Skip\"        :: \"'s LA\" (\"SKIP\" 61)\n\n\ntranslations\n  \"p1;p2\" \\<rightleftharpoons> \"CONST Seq p1 p2\" \n\n  \"IF b THEN c1 ELSE c2 FI\" \\<rightleftharpoons> \"CONST Cond b c1 c2\"\n  \"IF b THEN c FI\" \\<rightleftharpoons> \"IF b THEN c ELSE SKIP FI\"\n\n\n  \"WHILE b \\<lbrakk>inv: i\\<rbrakk> DO p SUBSEQUENTLY q OD\" \\<rightleftharpoons> \"CONST While b i p q\"\n  \"WHILE b DO p SUBSEQUENTLY q OD\" \\<rightleftharpoons> \"WHILE b \\<lbrakk>inv: CONST UNIV\\<rbrakk> DO p SUBSEQUENTLY q OD\"\n\n  \"WHILE b \\<lbrakk>inv: i\\<rbrakk> DO p OD\" \\<rightleftharpoons> \"WHILE b \\<lbrakk>inv: i\\<rbrakk> DO p SUBSEQUENTLY SKIP OD\"\n  \"WHILE b DO p OD\" \\<rightleftharpoons> \"WHILE b DO p SUBSEQUENTLY SKIP OD\"\n\n  \"AWAIT b \\<lbrakk>ann: a\\<rbrakk> THEN c END\" \\<rightleftharpoons> \"CONST Await b a c\"\n  \"\\<lbrakk>ann: a\\<rbrakk>\\<langle>c\\<rangle>\" \\<rightleftharpoons> \"AWAIT CONST UNIV \\<lbrakk>ann: a\\<rbrakk> THEN c END\"\n  \"WAIT b \\<lbrakk>ann: a\\<rbrakk> END\" \\<rightleftharpoons> \"AWAIT b \\<lbrakk>ann: a\\<rbrakk> THEN SKIP END\"\n\n\n  \"AWAIT b THEN c END\" \\<rightleftharpoons> \"CONST Await b (CONST UNIV) c\"\n  \"\\<langle>c\\<rangle>\" \\<rightleftharpoons> \"AWAIT CONST UNIV THEN c END\"\n  \"WAIT b END\" \\<rightleftharpoons> \"AWAIT b THEN SKIP END\"\n  \"JUMP j\"  \\<rightleftharpoons> \"CONST Jump j\"\n  \"CJUMP b TO j OTHERWISE p END\" \\<rightleftharpoons> \"CONST CJump b j p\"\n  \"SKIP\" \\<rightleftharpoons> \"CONST Skip\"    \n\n\nnonterminal prgs\nsyntax\n  \"_PAR\" :: \"prgs \\<Rightarrow> 'a\"\n            (\"(INTERLEAVING-BEGIN//_//INTERLEAVING-END)\" [57] 56)\n  \"_AnnPrg\" :: \"['a, 'a, 'a, 'a] \\<Rightarrow> prgs\"\n               (\"(2 \\<lbrakk> rely: _,/ pre: _,/ post: _ \\<rbrakk>//_)\" [90, 90, 90, 60] 57)\n  \"_AnnPrgs\" :: \"['a, 'a, 'a, 'a, prgs] \\<Rightarrow> prgs\"\n                (\"(2 \\<lbrakk> rely: _,/ pre: _,/ post: _ \\<rbrakk>//_)//\\<parallel>//_\" [90, 90, 90, 60, 57] 57)\n  \"_AnnPrgScheme\" :: \"['a, 'a, 'a, 'a, 'a, 'a, 'a] \\<Rightarrow> prgs\"\n  (\"  (2SCHEME-BEGIN [_ \\<le> _ < _]//\\<lbrakk> rely: _,/ pre: _,/ post: _ \\<rbrakk>//_//SCHEME-END)\" [0,0,0,90,90,90,0] 57)\n\n  \"_Prg\" :: \"['a] \\<Rightarrow> prgs\"\n            (\"(2  _)\" [60] 57)\n  \"_Prgs\" :: \"['a, prgs] \\<Rightarrow> prgs\"\n             (\"(2  _)//\\<parallel>//_\" [60,57] 57)\n  \"_PrgScheme\" :: \"['a, 'a, 'a, 'a] \\<Rightarrow> prgs\"  \n                  (\"  (2SCHEME-BEGIN [_ \\<le> _ < _]//_//SCHEME-END)\" [0,0,0,60] 57)\n\ntranslations\n  \"_PAR ps\" \\<rightharpoonup> \"CONST Parallel ps\"\n  \"_AnnPrg r p q c\" \\<rightharpoonup> \"([(c, \\<lparr>ap_rely=r, ap_precond=p, ap_postcond=q\\<rparr>)])\"\n  \"_AnnPrgs r p q c ps\" \\<rightharpoonup> \"((c, \\<lparr>ap_rely=r, ap_precond=p, ap_postcond=q\\<rparr>) # ps)\"\n  \"_AnnPrgScheme j i k r p q c\" \\<rightharpoonup>\n    \"(CONST map (\\<lambda>i. (c, \\<lparr>ap_rely=r, ap_precond=p, ap_postcond=q\\<rparr>)) [j..<k])\"\n\n  \"_Prg c\" \\<rightharpoonup>\n    \"([(c, \\<lparr>ap_rely=CONST UNIV, ap_precond=CONST UNIV, ap_postcond=CONST UNIV\\<rparr>)])\"\n  \"_Prgs c ps\" \\<rightharpoonup>\n    \"((c, \\<lparr>ap_rely=CONST UNIV, ap_precond=CONST UNIV, ap_postcond=CONST UNIV\\<rparr>) # ps)\"\n  \"_PrgScheme j i k c\" \\<rightharpoonup>\n    \"(CONST map (\\<lambda>i. (c, \\<lparr>ap_rely=CONST UNIV, ap_precond=CONST UNIV, ap_postcond=CONST UNIV\\<rparr> )) [j..<k])\"\n\n\n\n\n\nML \\<open> \n\nfun dest_absL (x, T, body) =\n  let\n    fun name_clash (Free (y, _)) = (x = y)\n      | name_clash (t $ u) = name_clash t orelse name_clash u\n      | name_clash (Abs (_, _, t)) = name_clash t\n      | name_clash _ = false;\n  in\n    if name_clash body then\n      dest_absL (singleton (Name.variant_list [x]) x, T, body)    (*potentially slow*)\n    else (x, subst_bound (Free (x, T), body))\n  end;\n\n  fun quote_tr' f (t :: ts) =\n        Term.list_comb (f $ Syntax_Trans.quote_tr' @{syntax_const \"_antiquote\"} t, ts)\n    | quote_tr' _ _ = raise Match;\n\n  fun annquote_tr' f (r :: t :: ts) =\n        Term.list_comb (f $ r $ Syntax_Trans.quote_tr' @{syntax_const \"_antiquote\"} t, ts)\n    | annquote_tr' _ _ = raise Match;\n\n  val assert_tr' = quote_tr' (Syntax.const @{syntax_const \"_Assert\"});\n\n  fun annbexp_tr' name (r :: (Const (@{const_syntax Collect}, _) $ t) :: ts) =\n        annquote_tr' (Syntax.const name) (r :: t :: ts)\n    | annbexp_tr' name (r :: Const (@{const_syntax UNIV}, _) :: ts) =\n        annquote_tr' (Syntax.const name)\n                     (r :: Abs (\"s\", dummyT, Const (@{const_syntax True}, dummyT)) :: ts)\n    | annbexp_tr' name (r :: Const (@{const_syntax Set.empty}, _) :: ts) =\n        annquote_tr' (Syntax.const name)\n                     (r :: Abs (\"s\", dummyT, Const (@{const_syntax False}, dummyT)) :: ts)\n    | annbexp_tr' _ _ = raise Match;\n\n  fun annassign_tr' (r :: Abs (x, _, f $ k $ Bound 0) :: ts) =\n        quote_tr' (Syntax.const @{syntax_const \"_Assign\"} $ r $ Syntax_Trans.update_name_tr' f)\n          (Abs (x, dummyT, Syntax_Trans.const_abs_tr' k) :: ts)\n    | annassign_tr' _ = raise Match;\n\n  fun dest_list (Const (@{const_syntax Nil}, _)) = []\n    | dest_list (Const (@{const_syntax Cons}, _) $ x $ xs) = x :: dest_list xs\n    | dest_list xs = [xs];\n\n  fun new_Pair a b =\n    (Const (@{const_syntax Pair}, dummyT) $ a $ b)\n\n  fun dest_prod (Const (@{const_syntax Pair}, _) $ a $ b) = (a, b)\n    | dest_prod _ = raise Match;\n\n  fun dest_upt (Const (@{const_syntax upt},_) $ m $ n) = (m, n)\n    | dest_upt _ = raise Match;\n\n  fun dest_apar (Const (@{const_syntax annpar_ext}, _) $ r $ p $ q $ _) = (r, p, q)\n    | dest_apar _ = raise Match;\n\n  fun prg_tr' const aconst xs pqa =\n        let val (c, apr) = dest_prod pqa\n            val (R, P, Q) = dest_apar apr\n            fun fake (Const (@{const_syntax UNIV},_)) = true\n              | fake _ = false\n            val const' = if fake R then const else aconst\n            val ys = if fake R then [] else [R, P, Q]\n        in list_comb (Syntax.const const', xs @ ys @ [c])\n        end\n\n  fun prgs_lst_tr'\n            [Const (@{const_syntax map}, _) $ Abs (i, T, p) $ upt] =\n        let val (j, k) = dest_upt upt\n        in prg_tr' @{syntax_const \"_PrgScheme\"} @{syntax_const \"_AnnPrgScheme\"}\n                 [j, Free (i, T), k] (snd(dest_absL (i, T, p)))\n        end\n    | prgs_lst_tr' [p] =\n        prg_tr' @{syntax_const \"_Prg\"} @{syntax_const \"_AnnPrg\"} [] p\n    | prgs_lst_tr' (p :: ps)  =\n        prg_tr' @{syntax_const \"_Prgs\"} @{syntax_const \"_AnnPrgs\"} [] p $\n          prgs_lst_tr' ps \n    | prgs_lst_tr' _ = raise Match\n\n  fun Parallel_tr (cs :: _) =\n        let val cs' = dest_list cs\n        in Syntax.const @{syntax_const \"_PAR\"} $\n             prgs_lst_tr' cs' end\n    | Parallel_tr _ = raise Match;\n\n  fun Basic_tr (Abs (x, _, f $ k $ Bound 0) :: ts) =\n      quote_tr' (Syntax.const @{syntax_const \"_Assign\"} $ Syntax_Trans.update_name_tr' f)\n          (Abs (x, dummyT, Syntax_Trans.const_abs_tr' k) :: ts) \n    | Basic_tr ((f $ k) :: ts) = quote_tr' (Syntax.const @{syntax_const \"_Assign\"} $ Syntax_Trans.update_name_tr' f)\n          (k :: ts) \n    | Basic_tr _ = raise Match;\n\n\\<close>\n\nprint_translation \\<open>\n  [(@{const_syntax Collect}, K assert_tr'),\n   (@{const_syntax Basic}, K Basic_tr),\n   (@{const_syntax Parallel}, K Parallel_tr)]\n\\<close>\n\n\n\nend", "meta": {"author": "maksym-bortin", "repo": "a_framework", "sha": "df46703505efafcf1087d4461e93e502d94712ab", "save_path": "github-repos/isabelle/maksym-bortin-a_framework", "path": "github-repos/isabelle/maksym-bortin-a_framework/a_framework-df46703505efafcf1087d4461e93e502d94712ab/LA.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6442251064863697, "lm_q2_score": 0.4225046348141883, "lm_q1q2_score": 0.27218809335415517}}
{"text": "(*  Title:      JinjaThreads/J/WellType.thy\n    Author:     Tobias Nipkow, Andreas Lochbihler\n*)\n\nheader {* \\isaheader{Well-typedness of Jinja expressions} *}\n\ntheory WellType\nimports\n  Expr\n  State\n  \"../Common/ExternalCallWF\"\n  \"../Common/WellForm\"\n  \"../Common/SemiType\"\nbegin\n\ndeclare Listn.lesub_list_impl_same_size[simp del]\ndeclare listE_length [simp del]\n\ntype_synonym \n  env  = \"vname \\<rightharpoonup> ty\"\n\ninductive\n  WT :: \"(ty \\<Rightarrow> ty \\<Rightarrow> ty \\<Rightarrow> bool) \\<Rightarrow> 'addr J_prog \\<Rightarrow> env \\<Rightarrow> 'addr expr \\<Rightarrow> ty \\<Rightarrow> bool\" (\"_,_,_ \\<turnstile> _ :: _\"   [51,51,51,51]50)\n  and WTs :: \"(ty \\<Rightarrow> ty \\<Rightarrow> ty \\<Rightarrow> bool) \\<Rightarrow> 'addr J_prog \\<Rightarrow> env \\<Rightarrow> 'addr expr list \\<Rightarrow> ty list \\<Rightarrow> bool\" \n    (\"_,_,_ \\<turnstile> _ [::] _\"   [51,51,51,51]50)\n  for is_lub :: \"ty \\<Rightarrow> ty \\<Rightarrow> ty \\<Rightarrow> bool\" (\"\\<turnstile> lub'((_,/ _)') = _\" [51,51,51] 50)\n  and P :: \"'addr J_prog\"\nwhere\n\n  WTNew:\n  \"is_class P C  \\<Longrightarrow>\n  is_lub,P,E \\<turnstile> new C :: Class C\"\n\n| WTNewArray:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: Integer; is_type P (T\\<lfloor>\\<rceil>) \\<rbrakk> \\<Longrightarrow>\n  is_lub,P,E \\<turnstile> newA T\\<lfloor>e\\<rceil> :: T\\<lfloor>\\<rceil>\"\n\n| WTCast:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: T; P \\<turnstile> U \\<le> T \\<or> P \\<turnstile> T \\<le> U; is_type P U \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> Cast U e :: U\"\n\n| WTInstanceOf:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: T; P \\<turnstile> U \\<le> T \\<or> P \\<turnstile> T \\<le> U; is_type P U; is_refT U \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> e instanceof U :: Boolean\"\n\n| WTVal:\n  \"typeof v = Some T \\<Longrightarrow>\n  is_lub,P,E \\<turnstile> Val v :: T\"\n\n| WTVar:\n  \"E V = Some T \\<Longrightarrow>\n  is_lub,P,E \\<turnstile> Var V :: T\"\n\n| WTBinOp:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e1 :: T1; is_lub,P,E \\<turnstile> e2 :: T2; P \\<turnstile> T1\\<guillemotleft>bop\\<guillemotright>T2 :: T \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> e1\\<guillemotleft>bop\\<guillemotright>e2 :: T\"\n\n| WTLAss:\n  \"\\<lbrakk> E V = Some T;  is_lub,P,E \\<turnstile> e :: T';  P \\<turnstile> T' \\<le> T;  V \\<noteq> this \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> V:=e :: Void\"\n\n| WTAAcc:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> a :: T\\<lfloor>\\<rceil>; is_lub,P,E \\<turnstile> i :: Integer \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> a\\<lfloor>i\\<rceil> :: T\"\n\n| WTAAss:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> a :: T\\<lfloor>\\<rceil>; is_lub,P,E \\<turnstile> i :: Integer; is_lub,P,E \\<turnstile> e :: T'; P \\<turnstile> T' \\<le> T \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> a\\<lfloor>i\\<rceil> := e :: Void\"\n\n| WTALength:\n  \"is_lub,P,E \\<turnstile> a :: T\\<lfloor>\\<rceil> \\<Longrightarrow> is_lub,P,E \\<turnstile> a\\<bullet>length :: Integer\"\n\n| WTFAcc:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: U; class_type_of' U = \\<lfloor>C\\<rfloor>; P \\<turnstile> C sees F:T (fm) in D \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> e\\<bullet>F{D} :: T\"\n\n| WTFAss:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e\\<^sub>1 :: U; class_type_of' U = \\<lfloor>C\\<rfloor>; P \\<turnstile> C sees F:T (fm) in D; is_lub,P,E \\<turnstile> e\\<^sub>2 :: T'; P \\<turnstile> T' \\<le> T \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> e\\<^sub>1\\<bullet>F{D}:=e\\<^sub>2 :: Void\"\n\n| WTCall:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: U; class_type_of' U = \\<lfloor>C\\<rfloor>; P \\<turnstile> C sees M:Ts \\<rightarrow> T = meth in D;\n     is_lub,P,E \\<turnstile> es [::] Ts'; P \\<turnstile> Ts' [\\<le>] Ts \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> e\\<bullet>M(es) :: T\"\n\n| WTBlock:\n  \"\\<lbrakk> is_type P T;  is_lub,P,E(V \\<mapsto> T) \\<turnstile> e :: T'; case vo of None \\<Rightarrow> True | \\<lfloor>v\\<rfloor> \\<Rightarrow> \\<exists>T'. typeof v = \\<lfloor>T'\\<rfloor> \\<and> P \\<turnstile> T' \\<le> T \\<rbrakk>\n  \\<Longrightarrow>  is_lub,P,E \\<turnstile> {V:T=vo; e} :: T'\"\n\n| WTSynchronized:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> o' :: T; is_refT T; T \\<noteq> NT; is_lub,P,E \\<turnstile> e :: T' \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> sync(o') e :: T'\"\n\n-- \"Note that insync is not statically typable.\"\n\n| WTSeq:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e\\<^sub>1::T\\<^sub>1;  is_lub,P,E \\<turnstile> e\\<^sub>2::T\\<^sub>2 \\<rbrakk>\n  \\<Longrightarrow>  is_lub,P,E \\<turnstile> e\\<^sub>1;;e\\<^sub>2 :: T\\<^sub>2\"\n| WTCond:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: Boolean;  is_lub,P,E \\<turnstile> e\\<^sub>1::T\\<^sub>1;  is_lub,P,E \\<turnstile> e\\<^sub>2::T\\<^sub>2; \\<turnstile> lub(T\\<^sub>1, T\\<^sub>2) = T \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> if (e) e\\<^sub>1 else e\\<^sub>2 :: T\"\n\n| WTWhile:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: Boolean;  is_lub,P,E \\<turnstile> c::T \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> while (e) c :: Void\"\n\n| WTThrow:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: Class C; P \\<turnstile> C \\<preceq>\\<^sup>* Throwable \\<rbrakk> \\<Longrightarrow> \n  is_lub,P,E \\<turnstile> throw e :: Void\"\n\n| WTTry:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e\\<^sub>1 :: T;  is_lub,P,E(V \\<mapsto> Class C) \\<turnstile> e\\<^sub>2 :: T; P \\<turnstile> C \\<preceq>\\<^sup>* Throwable \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> try e\\<^sub>1 catch(C V) e\\<^sub>2 :: T\"\n\n| WTNil: \"is_lub,P,E \\<turnstile> [] [::] []\"\n\n| WTCons: \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: T; is_lub,P,E \\<turnstile> es [::] Ts \\<rbrakk> \\<Longrightarrow> is_lub,P,E \\<turnstile> e#es [::] T#Ts\"\n\nabbreviation WT' :: \"'addr J_prog \\<Rightarrow> env \\<Rightarrow> 'addr expr \\<Rightarrow> ty \\<Rightarrow> bool\" (\"_,_ \\<turnstile> _ :: _\" [51,51,51] 50)\nwhere \"WT' P \\<equiv> WT (TypeRel.is_lub P) P\"\n\nabbreviation WTs' :: \"'addr J_prog \\<Rightarrow> env \\<Rightarrow> 'addr expr list \\<Rightarrow> ty list \\<Rightarrow> bool\" (\"_,_ \\<turnstile> _ [::] _\" [51,51,51] 50)\nwhere \"WTs' P \\<equiv> WTs (TypeRel.is_lub P) P\"\n\ndeclare WT_WTs.intros[intro!]\n\ninductive_simps WTs_iffs [iff]:\n  \"is_lub',P,E \\<turnstile> [] [::] Ts\"\n  \"is_lub',P,E \\<turnstile> e#es [::] T#Ts\"\n  \"is_lub',P,E \\<turnstile> e#es [::] Ts\"\n\nlemma WTs_conv_list_all2: \n  fixes is_lub \n  shows \"is_lub,P,E \\<turnstile> es [::] Ts = list_all2 (WT is_lub P E) es Ts\"\nby(induct es arbitrary: Ts)(auto simp add: list_all2_Cons1 elim: WTs.cases)\n\nlemma WTs_append [iff]: \"\\<And>is_lub Ts. (is_lub,P,E \\<turnstile> es\\<^sub>1 @ es\\<^sub>2 [::] Ts) =\n  (\\<exists>Ts\\<^sub>1 Ts\\<^sub>2. Ts = Ts\\<^sub>1 @ Ts\\<^sub>2 \\<and> is_lub,P,E \\<turnstile> es\\<^sub>1 [::] Ts\\<^sub>1 \\<and> is_lub,P,E \\<turnstile> es\\<^sub>2[::]Ts\\<^sub>2)\"\nby(auto simp add: WTs_conv_list_all2 list_all2_append1 dest: list_all2_lengthD[symmetric])\n\ninductive_simps WT_iffs [iff]:\n  \"is_lub',P,E \\<turnstile> Val v :: T\"\n  \"is_lub',P,E \\<turnstile> Var V :: T\"\n  \"is_lub',P,E \\<turnstile> e\\<^sub>1;;e\\<^sub>2 :: T\\<^sub>2\"\n  \"is_lub',P,E \\<turnstile> {V:T=vo; e} :: T'\"\n\ninductive_cases WT_elim_cases[elim!]:\n  \"is_lub',P,E \\<turnstile> V :=e :: T\"\n  \"is_lub',P,E \\<turnstile> sync(o') e :: T\"\n  \"is_lub',P,E \\<turnstile> if (e) e\\<^sub>1 else e\\<^sub>2 :: T\"\n  \"is_lub',P,E \\<turnstile> while (e) c :: T\"\n  \"is_lub',P,E \\<turnstile> throw e :: T\"\n  \"is_lub',P,E \\<turnstile> try e\\<^sub>1 catch(C V) e\\<^sub>2 :: T\"\n  \"is_lub',P,E \\<turnstile> Cast D e :: T\"\n  \"is_lub',P,E \\<turnstile> e instanceof U :: T\"\n  \"is_lub',P,E \\<turnstile> a\\<bullet>F{D} :: T\"\n  \"is_lub',P,E \\<turnstile> a\\<bullet>F{D} := v :: T\"\n  \"is_lub',P,E \\<turnstile> e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2 :: T\"\n  \"is_lub',P,E \\<turnstile> new C :: T\"\n  \"is_lub',P,E \\<turnstile> newA T\\<lfloor>e\\<rceil> :: T'\"\n  \"is_lub',P,E \\<turnstile> a\\<lfloor>i\\<rceil> := e :: T\"\n  \"is_lub',P,E \\<turnstile> a\\<lfloor>i\\<rceil> :: T\"\n  \"is_lub',P,E \\<turnstile> a\\<bullet>length :: T\"\n  \"is_lub',P,E \\<turnstile> e\\<bullet>M(ps) :: T\"\n  \"is_lub',P,E \\<turnstile> sync(o') e :: T\"\n  \"is_lub',P,E \\<turnstile> insync(a) e :: T\"\n\nlemma fixes is_lub :: \"ty \\<Rightarrow> ty \\<Rightarrow> ty \\<Rightarrow> bool\" (\"\\<turnstile> lub'((_,/ _)') = _\" [51,51,51] 50)\n  assumes is_lub_unique: \"\\<And>T1 T2 T3 T4. \\<lbrakk> \\<turnstile> lub(T1, T2) = T3; \\<turnstile> lub(T1, T2) = T4 \\<rbrakk> \\<Longrightarrow> T3 = T4\"\n  shows WT_unique: \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: T; is_lub,P,E \\<turnstile> e :: T' \\<rbrakk> \\<Longrightarrow> T = T'\"\n  and WTs_unique: \"\\<lbrakk> is_lub,P,E \\<turnstile> es [::] Ts; is_lub,P,E \\<turnstile> es [::] Ts' \\<rbrakk> \\<Longrightarrow> Ts = Ts'\"\napply(induct arbitrary: T' and Ts' rule: WT_WTs.inducts)\napply blast\napply blast\napply blast\napply blast\napply fastforce\napply fastforce\napply(fastforce dest: WT_binop_fun)\napply fastforce\napply fastforce\napply fastforce\napply fastforce\napply(fastforce dest: sees_field_fun)\napply(fastforce dest: sees_field_fun)\napply(fastforce dest: sees_method_fun)\napply fastforce\napply fastforce\napply fastforce\napply(blast dest: is_lub_unique)\napply fastforce\napply fastforce\napply blast\napply fastforce\napply fastforce\ndone\n\nlemma fixes is_lub\n  shows wt_env_mono: \"is_lub,P,E \\<turnstile> e :: T \\<Longrightarrow> (\\<And>E'. E \\<subseteq>\\<^sub>m E' \\<Longrightarrow> is_lub,P,E' \\<turnstile> e :: T)\"\n  and wts_env_mono: \"is_lub,P,E \\<turnstile> es [::] Ts \\<Longrightarrow> (\\<And>E'. E \\<subseteq>\\<^sub>m E' \\<Longrightarrow> is_lub,P,E' \\<turnstile> es [::] Ts)\"\napply(induct rule: WT_WTs.inducts)\napply(simp add: WTNew)\napply(simp add: WTNewArray)\napply(fastforce simp: WTCast)\napply(fastforce simp: WTInstanceOf)\napply(fastforce simp: WTVal)\napply(simp add: WTVar map_le_def dom_def)\napply(fastforce simp: WTBinOp)\napply(force simp:map_le_def)\napply(simp add: WTAAcc)\napply(simp add: WTAAss, fastforce)\napply(simp add: WTALength, fastforce)\napply(fastforce simp: WTFAcc)\napply(fastforce simp: WTFAss del:WT_WTs.intros WT_elim_cases)\napply(fastforce)\napply(fastforce simp: map_le_def WTBlock)\napply(fastforce simp: WTSynchronized)\napply(fastforce simp: WTSeq)\napply(fastforce simp: WTCond)\napply(fastforce simp: WTWhile)\napply(fastforce simp: WTThrow)\napply(fastforce simp: WTTry map_le_def dom_def)\napply(fastforce)+\ndone\n\nlemma fixes is_lub\n  shows WT_fv: \"is_lub,P,E \\<turnstile> e :: T \\<Longrightarrow> fv e \\<subseteq> dom E\"\n  and WT_fvs: \"is_lub,P,E \\<turnstile> es [::] Ts \\<Longrightarrow> fvs es \\<subseteq> dom E\"\napply(induct rule:WT_WTs.inducts)\napply(simp_all del: fun_upd_apply)\napply fast+\ndone\n\nlemma fixes is_lub\n  shows WT_expr_locks: \"is_lub,P,E \\<turnstile> e :: T \\<Longrightarrow> expr_locks e = (\\<lambda>ad. 0)\"\n  and WTs_expr_lockss: \"is_lub,P,E \\<turnstile> es [::] Ts \\<Longrightarrow> expr_lockss es = (\\<lambda>ad. 0)\"\nby(induct rule: WT_WTs.inducts)(auto)\n\nlemma\n  fixes is_lub :: \"ty \\<Rightarrow> ty \\<Rightarrow> ty \\<Rightarrow> bool\" (\"\\<turnstile> lub'((_,/ _)') = _\" [51,51,51] 50)\n  assumes is_lub_is_type: \"\\<And>T1 T2 T3. \\<lbrakk> \\<turnstile> lub(T1, T2) = T3; is_type P T1; is_type P T2 \\<rbrakk> \\<Longrightarrow> is_type P T3\"\n  and wf: \"wf_prog wf_md P\"\n  shows WT_is_type: \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: T; ran E \\<subseteq> types P \\<rbrakk> \\<Longrightarrow> is_type P T\"\n  and WTs_is_type: \"\\<lbrakk> is_lub,P,E \\<turnstile> es [::] Ts; ran E \\<subseteq> types P \\<rbrakk> \\<Longrightarrow> set Ts \\<subseteq> types P\"\napply(induct rule: WT_WTs.inducts)\napply simp\napply simp\napply simp\napply simp\napply (simp add:typeof_lit_is_type)\napply (fastforce intro:nth_mem simp add: ran_def)\napply(simp add: WT_binop_is_type)\napply(simp)\napply(simp del: is_type_array add: is_type_ArrayD)\napply(simp)\napply(simp)\napply(simp add:sees_field_is_type[OF _ wf])\napply(simp)\napply(fastforce dest: sees_wf_mdecl[OF wf] simp:wf_mdecl_def)\napply(fastforce simp add: ran_def split: split_if_asm)\napply(simp add: is_class_Object[OF wf])\napply(simp)\napply(simp)\napply(fastforce intro: is_lub_is_type)\napply(simp)\napply(simp)\napply simp\napply simp\napply simp\ndone\n\nlemma\n  fixes is_lub1 :: \"ty \\<Rightarrow> ty \\<Rightarrow> ty \\<Rightarrow> bool\" (\"\\<turnstile>1 lub'((_,/ _)') = _\" [51,51,51] 50)\n  and is_lub2 :: \"ty \\<Rightarrow> ty \\<Rightarrow> ty \\<Rightarrow> bool\" (\"\\<turnstile>2 lub'((_,/ _)') = _\" [51,51,51] 50)\n  assumes wf: \"wf_prog wf_md P\"\n  and is_lub1_into_is_lub2: \"\\<And>T1 T2 T3. \\<lbrakk> \\<turnstile>1 lub(T1, T2) = T3; is_type P T1; is_type P T2 \\<rbrakk> \\<Longrightarrow> \\<turnstile>2 lub(T1, T2) = T3\"\n  and is_lub2_is_type: \"\\<And>T1 T2 T3. \\<lbrakk> \\<turnstile>2 lub(T1, T2) = T3; is_type P T1; is_type P T2 \\<rbrakk> \\<Longrightarrow> is_type P T3\"\n  shows WT_change_is_lub: \"\\<lbrakk> is_lub1,P,E \\<turnstile> e :: T; ran E \\<subseteq> types P \\<rbrakk> \\<Longrightarrow> is_lub2,P,E \\<turnstile> e :: T\"\n  and WTs_change_is_lub: \"\\<lbrakk> is_lub1,P,E \\<turnstile> es [::] Ts; ran E \\<subseteq> types P \\<rbrakk> \\<Longrightarrow> is_lub2,P,E \\<turnstile> es [::] Ts\"\nproof(induct rule: WT_WTs.inducts)\n  case (WTBlock U E V e' T vo)\n  from `is_type P U` `ran E \\<subseteq> types P`\n  have \"ran (E(V \\<mapsto> U)) \\<subseteq> types P\" by(auto simp add: ran_def)\n  hence \"is_lub2,P,E(V \\<mapsto> U) \\<turnstile> e' :: T\" by(rule WTBlock)\n  with `is_type P U` show ?case\n    using `case vo of None \\<Rightarrow> True | \\<lfloor>v\\<rfloor> \\<Rightarrow> \\<exists>T'. typeof v = \\<lfloor>T'\\<rfloor> \\<and> P \\<turnstile> T' \\<le> U` by auto\nnext\n  case (WTCond E e e1 T1 e2 T2 T)\n  from `ran E \\<subseteq> types P` have \"is_lub2,P,E \\<turnstile> e :: Boolean\" \"is_lub2,P,E \\<turnstile> e1 :: T1\" \"is_lub2,P,E \\<turnstile> e2 :: T2\"\n    by(rule WTCond)+\n  moreover from is_lub2_is_type wf `is_lub2,P,E \\<turnstile> e1 :: T1` `ran E \\<subseteq> types P`\n  have \"is_type P T1\" by(rule WT_is_type)\n  from is_lub2_is_type wf `is_lub2,P,E \\<turnstile> e2 :: T2` `ran E \\<subseteq> types P`\n  have \"is_type P T2\" by(rule WT_is_type)\n  with `\\<turnstile>1 lub(T1, T2) = T` `is_type P T1`\n  have \"\\<turnstile>2 lub(T1, T2) = T\" by(rule is_lub1_into_is_lub2)\n  ultimately show ?case ..\nnext\n  case (WTTry E e1 T V C e2)\n  from `ran E \\<subseteq> types P` have \"is_lub2,P,E \\<turnstile> e1 :: T\" by(rule WTTry)\n  moreover from `P \\<turnstile> C \\<preceq>\\<^sup>* Throwable` have \"is_class P C\"\n    by(rule is_class_sub_Throwable[OF wf])\n  with `ran E \\<subseteq> types P` have \"ran (E(V \\<mapsto> Class C)) \\<subseteq> types P\"\n    by(auto simp add: ran_def)\n  hence \"is_lub2,P,E(V \\<mapsto> Class C) \\<turnstile> e2 :: T\" by(rule WTTry)\n  ultimately show ?case using `P \\<turnstile> C \\<preceq>\\<^sup>* Throwable` ..\nqed auto\n\nsubsection {* Code generator setup *}\n\nlemma WTBlock_code:\n  \"\\<And>is_lub. \\<lbrakk> is_type P T; is_lub,P,E(V \\<mapsto> T) \\<turnstile> e :: T'; \n     case vo of None \\<Rightarrow> True | \\<lfloor>v\\<rfloor> \\<Rightarrow> case typeof v of None \\<Rightarrow> False | Some T' \\<Rightarrow> P \\<turnstile> T' \\<le> T \\<rbrakk>\n  \\<Longrightarrow>  is_lub,P,E \\<turnstile> {V:T=vo; e} :: T'\"\nby(auto)\n\nlemmas [code_pred_intro] =\n  WTNew WTNewArray WTCast WTInstanceOf WTVal WTVar WTBinOp WTLAss WTAAcc WTAAss WTALength WTFAcc WTFAss WTCall \ndeclare \n  WTBlock_code [code_pred_intro WTBlock']\nlemmas [code_pred_intro] =\n  WTSynchronized WTSeq WTCond WTWhile WTThrow WTTry\n  WTNil WTCons\n\ncode_pred\n  (modes:\n    (i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool) \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool, \n    (i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool) \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool)\n  [detect_switches, skip_proof]\n  WT\nproof -\n  case WT\n  from WT.prems show thesis\n  proof cases\n    case (WTBlock T V e vo)\n    thus thesis using WTBlock'[OF refl refl refl, of V T vo e] by(auto)\n  qed(assumption|erule that[OF refl refl refl]|rule refl)+\nnext\n  case WTs\n  from WTs.prems that show thesis by cases blast+\nqed\n\ninductive is_lub_sup :: \"'m prog \\<Rightarrow> ty \\<Rightarrow> ty \\<Rightarrow> ty \\<Rightarrow> bool\"\nfor P T1 T2 T3\nwhere\n  \"sup P T1 T2 = OK T3 \\<Longrightarrow> is_lub_sup P T1 T2 T3\"\n\ncode_pred\n  (modes: i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool, i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool)\n  is_lub_sup\n.\n\ndefinition WT_code :: \"'addr J_prog \\<Rightarrow> env \\<Rightarrow> 'addr expr \\<Rightarrow> ty \\<Rightarrow> bool\" (\"_,_ \\<turnstile> _ ::' _\" [51,51,51] 50)\nwhere \"WT_code P \\<equiv> WT (is_lub_sup P) P\"\n\ndefinition WTs_code :: \"'addr J_prog \\<Rightarrow> env \\<Rightarrow> 'addr expr list \\<Rightarrow> ty list \\<Rightarrow> bool\" (\"_,_ \\<turnstile> _ [::''] _\" [51,51,51] 50)\nwhere \"WTs_code P \\<equiv> WTs (is_lub_sup P) P\"\n\nlemma assumes wf: \"wf_prog wf_md P\"\n  shows WT_code_into_WT: \n  \"\\<lbrakk> P,E \\<turnstile> e ::' T; ran E \\<subseteq> types P \\<rbrakk> \\<Longrightarrow> P,E \\<turnstile> e :: T\"\n\n  and WTs_code_into_WTs:\n  \"\\<lbrakk> P,E \\<turnstile> es [::'] Ts; ran E \\<subseteq> types P \\<rbrakk> \\<Longrightarrow> P,E \\<turnstile> es [::] Ts\"\nproof -\n  assume ran: \"ran E \\<subseteq> types P\"\n  { assume wt: \"P,E \\<turnstile> e ::' T\"\n    show \"P,E \\<turnstile> e :: T\"\n      by(rule WT_change_is_lub[OF wf _ _ wt[unfolded WT_code_def] ran])(blast elim!: is_lub_sup.cases intro: sup_is_lubI[OF wf] is_lub_is_type[OF wf])+ }\n  { assume wts: \"P,E \\<turnstile> es [::'] Ts\"\n    show \"P,E \\<turnstile> es [::] Ts\"\n      by(rule WTs_change_is_lub[OF wf _ _ wts[unfolded WTs_code_def] ran])(blast elim!: is_lub_sup.cases intro: sup_is_lubI[OF wf] is_lub_is_type[OF wf])+ }\nqed\n\nlemma assumes wf: \"wf_prog wf_md P\"\n  shows WT_into_WT_code: \n  \"\\<lbrakk> P,E \\<turnstile> e :: T; ran E \\<subseteq> types P \\<rbrakk> \\<Longrightarrow> P,E \\<turnstile> e ::' T\"\n\n  and WT_into_WTs_code_OK:\n  \"\\<lbrakk> P,E \\<turnstile> es [::] Ts; ran E \\<subseteq> types P \\<rbrakk> \\<Longrightarrow> P,E \\<turnstile> es [::'] Ts\"\nproof -\n  assume ran: \"ran E \\<subseteq> types P\"\n  { assume wt: \"P,E \\<turnstile> e :: T\"\n    show \"P,E \\<turnstile> e ::' T\" unfolding WT_code_def\n      by(rule WT_change_is_lub[OF wf _ _ wt ran])(blast intro!: is_lub_sup.intros intro: is_lub_subD[OF wf] sup_is_type[OF wf] elim!: is_lub_sup.cases)+ }\n  { assume wts: \"P,E \\<turnstile> es [::] Ts\"\n    show \"P,E \\<turnstile> es [::'] Ts\" unfolding WTs_code_def\n      by(rule WTs_change_is_lub[OF wf _ _ wts ran])(blast intro!: is_lub_sup.intros intro: is_lub_subD[OF wf] sup_is_type[OF wf] elim!: is_lub_sup.cases)+ }\nqed\n\ntheorem WT_eq_WT_code:\n  assumes \"wf_prog wf_md P\"\n  and \"ran E \\<subseteq> types P\"\n  shows \"P,E \\<turnstile> e :: T \\<longleftrightarrow> P,E \\<turnstile> e ::' T\"\nusing assms by(blast intro: WT_code_into_WT WT_into_WT_code)\n\ncode_pred\n  (modes: i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool, i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool)\n  [inductify]\n  WT_code \n.\n\ncode_pred\n  (modes: i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool, i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool)\n  [inductify]\n  WTs_code \n.\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/JinjaThreads/J/WellType.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6442251064863697, "lm_q2_score": 0.42250463481418826, "lm_q1q2_score": 0.27218809335415517}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\n(* Author: Andrew Boyton, 2012\n   Maintainers: Gerwin Klein <kleing at cse.unsw.edu.au>\n                Rafal Kolanski <rafal.kolanski at nicta.com.au>\n*)\n\nchapter \"Instantiating capDL as a separation algebra.\"\n\ntheory Abstract_Separation_D\nimports\n  \"../../Sep_Tactics\"\n  Types_D\n  \"../../Map_Extra\"\nbegin\n\n(**************************************\n * Start of lemmas to move elsewhere. *\n **************************************)\n\nlemma inter_empty_not_both:\n\"\\<lbrakk>x \\<in> A; A \\<inter> B = {}\\<rbrakk> \\<Longrightarrow> x \\<notin> B\"\n  by fastforce\n\nlemma union_intersection:\n  \"A \\<inter> (A \\<union> B) = A\"\n  \"B \\<inter> (A \\<union> B) = B\"\n  \"(A \\<union> B) \\<inter> A = A\"\n  \"(A \\<union> B) \\<inter> B = B\"\n  by fastforce+\n\nlemma union_intersection1: \"A \\<inter> (A \\<union> B) = A\"\n  by (rule inf_sup_absorb)\nlemma union_intersection2: \"B \\<inter> (A \\<union> B) = B\"\n  by fastforce\n\n(* This lemma is strictly weaker than restrict_map_disj. *)\nlemma restrict_map_disj':\n  \"S \\<inter> T = {} \\<Longrightarrow> h |` S \\<bottom> h' |` T\"\n  by (auto simp: map_disj_def restrict_map_def dom_def)\n\nlemma map_add_restrict_comm:\n  \"S \\<inter> T = {} \\<Longrightarrow> h |` S ++ h' |` T = h' |` T ++ h |` S\"\n  apply (drule restrict_map_disj')\n  apply (erule map_add_com)\n  done\n\n(************************************\n * End of lemmas to move elsewhere. *\n ************************************)\n\n\n\n(* The state for separation logic has:\n   * The memory heap.\n   * A function for which objects own which fields.\n     In capDL, we say that an object either owns all of its fields, or none of them.\n   These are both taken from the cdl_state.\n *)\n\ndatatype sep_state = SepState cdl_heap cdl_ghost_state\n\n(* Functions to get the heap and the ghost_state from the sep_state. *)\nprimrec sep_heap :: \"sep_state \\<Rightarrow> cdl_heap\"\nwhere  \"sep_heap (SepState h gs) = h\"\n\nprimrec sep_ghost_state :: \"sep_state \\<Rightarrow> cdl_ghost_state\"\nwhere  \"sep_ghost_state (SepState h gs) = gs\"\n\ndefinition\n  the_set :: \"'a option set \\<Rightarrow> 'a set\"\nwhere\n  \"the_set xs = {x. Some x \\<in> xs}\"\n\nlemma the_set_union [simp]:\n  \"the_set (A \\<union> B) = the_set A \\<union> the_set B\"\n  by (fastforce simp: the_set_def)\n\nlemma the_set_inter [simp]:\n  \"the_set (A \\<inter> B) = the_set A \\<inter> the_set B\"\n  by (fastforce simp: the_set_def)\n\nlemma the_set_inter_empty:\n  \"A \\<inter> B = {} \\<Longrightarrow> the_set A \\<inter> the_set B = {}\"\n  by (fastforce simp: the_set_def)\n\n\n(* As the capDL operations mostly take the state (rather than the heap)\n * we need to redefine some of them again to take just the heap.\n *)\ndefinition\n  slots_of_heap :: \"cdl_heap \\<Rightarrow> cdl_object_id \\<Rightarrow> cdl_cap_map\"\nwhere\n  \"slots_of_heap h \\<equiv> \\<lambda>obj_id.\n  case h obj_id of\n    None \\<Rightarrow> Map.empty\n  | Some obj \\<Rightarrow> object_slots obj\"\n\n(* Adds new caps to an object. It won't overwrite on a collision. *)\ndefinition\n  add_to_slots :: \"cdl_cap_map \\<Rightarrow> cdl_object \\<Rightarrow> cdl_object\"\nwhere\n  \"add_to_slots new_val obj \\<equiv> update_slots (new_val ++ (object_slots obj)) obj\"\n\nlemma add_to_slots_assoc:\n  \"add_to_slots x (add_to_slots (y ++ z) obj) =\n   add_to_slots (x ++ y) (add_to_slots z obj)\"\n  apply (clarsimp simp: add_to_slots_def update_slots_def object_slots_def)\n  apply (fastforce simp: cdl_tcb.splits cdl_cnode.splits\n                 split: cdl_object.splits)\n  done\n\n(* Lemmas about add_to_slots, update_slots and object_slots. *)\nlemma add_to_slots_twice [simp]:\n  \"add_to_slots x (add_to_slots y a) = add_to_slots (x ++ y) a\"\n  by (fastforce simp: add_to_slots_def update_slots_def object_slots_def\n              split: cdl_object.splits)\n\nlemma slots_of_heap_empty [simp]: \"slots_of_heap Map.empty object_id = Map.empty\"\n  by (simp add: slots_of_heap_def)\n\nlemma slots_of_heap_empty2 [simp]:\n  \"h obj_id = None \\<Longrightarrow> slots_of_heap h obj_id = Map.empty\"\n  by (simp add: slots_of_heap_def)\n\nlemma update_slots_add_to_slots_empty [simp]:\n  \"update_slots Map.empty (add_to_slots new obj) = update_slots Map.empty obj\"\n  by (clarsimp simp: update_slots_def add_to_slots_def split:cdl_object.splits)\n\nlemma update_object_slots_id [simp]: \"update_slots (object_slots a) a = a\"\n  by (clarsimp simp: update_slots_def object_slots_def\n              split: cdl_object.splits)\n\nlemma update_slots_of_heap_id [simp]:\n  \"h obj_id = Some obj \\<Longrightarrow> update_slots (slots_of_heap h obj_id) obj = obj\"\n  by (clarsimp simp: update_slots_def slots_of_heap_def object_slots_def\n              split: cdl_object.splits)\n\nlemma add_to_slots_empty [simp]: \"add_to_slots Map.empty h = h\"\n  by (simp add: add_to_slots_def)\n\nlemma update_slots_eq:\n  \"update_slots a o1 = update_slots a o2 \\<Longrightarrow> update_slots b o1 = update_slots b o2\"\n  by (fastforce simp: update_slots_def cdl_tcb.splits cdl_cnode.splits\n              split: cdl_object.splits)\n\n\n\n(* If there are not two conflicting objects at a position in two states.\n * Objects conflict if their types are different or their ghost_states collide.\n *)\ndefinition\n  not_conflicting_objects :: \"sep_state \\<Rightarrow> sep_state \\<Rightarrow> cdl_object_id \\<Rightarrow> bool\"\nwhere\n  \"not_conflicting_objects state_a state_b = (\\<lambda>obj_id.\n let heap_a = sep_heap state_a;\n     heap_b = sep_heap state_b;\n     gs_a = sep_ghost_state state_a;\n     gs_b = sep_ghost_state state_b\n in case (heap_a obj_id, heap_b obj_id) of\n    (Some o1, Some o2) \\<Rightarrow> object_type o1 = object_type o2 \\<and> gs_a obj_id \\<inter> gs_b obj_id = {}\n   | _ \\<Rightarrow> True)\"\n\n\n(* \"Cleans\" slots to conform with the components. *)\ndefinition\n  clean_slots :: \"cdl_cap_map \\<Rightarrow> cdl_components \\<Rightarrow> cdl_cap_map\"\nwhere\n  \"clean_slots slots cmp \\<equiv> slots |` the_set cmp\"\n\n(* Sets the fields of an object to a \"clean\" state.\n   Because a frame's size is part of it's type, we don't reset it. *)\ndefinition\n  object_clean_fields :: \"cdl_object \\<Rightarrow> cdl_components \\<Rightarrow> cdl_object\"\nwhere\n  \"object_clean_fields obj cmp \\<equiv> if None \\<in> cmp then obj else case obj of\n    Tcb x \\<Rightarrow> Tcb (x\\<lparr>cdl_tcb_fault_endpoint := undefined\\<rparr>)\n  | CNode x \\<Rightarrow> CNode (x\\<lparr>cdl_cnode_size_bits := undefined \\<rparr>)\n  | _ \\<Rightarrow> obj\"\n\n(* Sets the slots of an object to a \"clean\" state. *)\ndefinition\n  object_clean_slots :: \"cdl_object \\<Rightarrow> cdl_components \\<Rightarrow> cdl_object\"\nwhere\n  \"object_clean_slots obj cmp \\<equiv> update_slots (clean_slots (object_slots obj) cmp) obj\"\n\n(* Sets an object to a \"clean\" state. *)\ndefinition\n  object_clean :: \"cdl_object \\<Rightarrow> cdl_components \\<Rightarrow> cdl_object\"\nwhere\n  \"object_clean obj gs \\<equiv> object_clean_slots (object_clean_fields obj gs) gs\"\n\n(* Overrides the left object with the attributes of the right, as specified by the ghost state.\n   If the components for an object are empty, then this object is treated as empty, and thus ignored.\n *)\ndefinition\n  object_add :: \"cdl_object \\<Rightarrow> cdl_object \\<Rightarrow> cdl_components \\<Rightarrow> cdl_components \\<Rightarrow> cdl_object\"\nwhere\n  \"object_add obj_a obj_b cmps_a cmps_b \\<equiv>\n  let clean_obj_a = object_clean obj_a cmps_a;\n      clean_obj_b = object_clean obj_b cmps_b\n  in if (cmps_a = {})\n     then clean_obj_b\n     else if (cmps_b = {})\n     then clean_obj_a\n     else if (None \\<in> cmps_b)\n     then (update_slots (object_slots clean_obj_a ++ object_slots clean_obj_b) clean_obj_b)\n     else (update_slots (object_slots clean_obj_a ++ object_slots clean_obj_b) clean_obj_a)\"\n\n(* Heaps are added by adding their respective objects.\n * The ghost state tells us which object's fields should be taken.\n * Adding objects of the same type adds their caps\n *   (overwrites the left with the right).\n *)\ndefinition\n  cdl_heap_add :: \"sep_state \\<Rightarrow> sep_state \\<Rightarrow> cdl_heap\"\nwhere\n  \"cdl_heap_add state_a state_b \\<equiv> \\<lambda>obj_id.\n  let\n    heap_a = sep_heap state_a;\n    heap_b = sep_heap state_b;\n    gs_a = sep_ghost_state state_a;\n    gs_b = sep_ghost_state state_b\n  in\n    case heap_b obj_id of\n      None \\<Rightarrow> heap_a obj_id\n    | Some obj_b \\<Rightarrow>\n        (case heap_a obj_id of\n           None \\<Rightarrow> heap_b obj_id\n         | Some obj_a \\<Rightarrow> Some (object_add obj_a obj_b (gs_a obj_id) (gs_b obj_id)))\"\n\n(* Heaps are added by adding their repsective objects.\n * The ghost state tells us which object's fields should be taken.\n * Adding objects of the same type adds their caps\n *   (overwrites the left with the right).\n *)\ndefinition\n  cdl_ghost_state_add :: \"sep_state \\<Rightarrow> sep_state \\<Rightarrow> cdl_ghost_state\"\nwhere\n  \"cdl_ghost_state_add state_a state_b \\<equiv> \\<lambda>obj_id.\n let heap_a = sep_heap state_a;\n     heap_b = sep_heap state_b;\n     gs_a = sep_ghost_state state_a;\n     gs_b = sep_ghost_state state_b\n in      if heap_a obj_id = None \\<and> heap_b obj_id \\<noteq> None then gs_b obj_id\n    else if heap_b obj_id = None \\<and> heap_a obj_id \\<noteq> None then gs_a obj_id\n    else gs_a obj_id \\<union> gs_b obj_id\"\n\n\n(* Adding states adds their heaps,\n *  and each objects owns whichever fields it owned in either heap.\n *)\ndefinition\n  sep_state_add :: \"sep_state \\<Rightarrow> sep_state \\<Rightarrow> sep_state\"\nwhere\n  \"sep_state_add state_a state_b \\<equiv>\n  let\n    heap_a = sep_heap state_a;\n    heap_b = sep_heap state_b;\n    gs_a = sep_ghost_state state_a;\n    gs_b = sep_ghost_state state_b\n  in\n    SepState (cdl_heap_add state_a state_b) (cdl_ghost_state_add state_a state_b)\"\n\n\n(* Heaps are disjoint if for all of their objects:\n   * the caps of their respective objects are disjoint,\n   * their respective objects don't conflict,\n   * they don't both own any of the same fields.\n*)\ndefinition\n  sep_state_disj :: \"sep_state \\<Rightarrow> sep_state \\<Rightarrow> bool\"\nwhere\n  \"sep_state_disj state_a state_b \\<equiv>\n  let\n    heap_a = sep_heap state_a;\n    heap_b = sep_heap state_b;\n    gs_a = sep_ghost_state state_a;\n    gs_b = sep_ghost_state state_b\n  in\n    \\<forall>obj_id. not_conflicting_objects state_a state_b obj_id\"\n\nlemma not_conflicting_objects_comm:\n  \"not_conflicting_objects h1 h2 obj = not_conflicting_objects h2 h1 obj\"\n  apply (clarsimp simp: not_conflicting_objects_def split:option.splits)\n  apply (fastforce simp: update_slots_def cdl_tcb.splits cdl_cnode.splits\n              split: cdl_object.splits)\n  done\n\nlemma object_clean_comm:\n  \"\\<lbrakk>object_type obj_a = object_type obj_b;\n    object_slots obj_a ++ object_slots obj_b = object_slots obj_b ++ object_slots obj_a; None \\<notin> cmp\\<rbrakk>\n  \\<Longrightarrow> object_clean (add_to_slots (object_slots obj_a) obj_b) cmp =\n      object_clean (add_to_slots (object_slots obj_b) obj_a) cmp\"\n  apply (clarsimp simp: object_type_def split: cdl_object.splits)\n  apply (clarsimp simp: object_clean_def object_clean_slots_def object_clean_fields_def\n                        add_to_slots_def object_slots_def update_slots_def\n                        cdl_tcb.splits cdl_cnode.splits\n                 split: cdl_object.splits)+\n  done\n\nlemma add_to_slots_object_slots:\n  \"object_type y = object_type z\n \\<Longrightarrow> add_to_slots (object_slots (add_to_slots (x) y)) z =\n     add_to_slots (x ++ object_slots y) z\"\n  apply (clarsimp simp: add_to_slots_def update_slots_def object_slots_def)\n  apply (fastforce simp: object_type_def cdl_tcb.splits cdl_cnode.splits\n                 split: cdl_object.splits)\n  done\n\nlemma not_conflicting_objects_empty [simp]:\n  \"not_conflicting_objects s (SepState Map.empty (\\<lambda>obj_id. {})) obj_id\"\n  by (clarsimp simp: not_conflicting_objects_def split:option.splits)\n\nlemma empty_not_conflicting_objects [simp]:\n  \"not_conflicting_objects (SepState Map.empty (\\<lambda>obj_id. {})) s obj_id\"\n  by (clarsimp simp: not_conflicting_objects_def split:option.splits)\n\nlemma not_conflicting_objects_empty_object [elim!]:\n  \"(sep_heap x) obj_id = None \\<Longrightarrow> not_conflicting_objects x y obj_id\"\n  by (clarsimp simp: not_conflicting_objects_def)\n\nlemma empty_object_not_conflicting_objects [elim!]:\n  \"(sep_heap y) obj_id = None \\<Longrightarrow> not_conflicting_objects x y obj_id\"\n  apply (drule not_conflicting_objects_empty_object [where y=x])\n  apply (clarsimp simp: not_conflicting_objects_comm)\n  done\n\nlemma cdl_heap_add_empty [simp]:\n \"cdl_heap_add (SepState h gs) (SepState Map.empty (\\<lambda>obj_id. {})) = h\"\n  by (simp add: cdl_heap_add_def)\n\nlemma empty_cdl_heap_add [simp]:\n  \"cdl_heap_add (SepState Map.empty (\\<lambda>obj_id. {})) (SepState h gs)= h\"\n  apply (simp add: cdl_heap_add_def)\n  apply (rule ext)\n  apply (clarsimp split: option.splits)\n  done\n\nlemma map_add_result_empty1: \"a ++ b = Map.empty \\<Longrightarrow> a = Map.empty\"\n  apply (subgoal_tac \"dom (a++b) = {}\")\n   apply (subgoal_tac \"dom (a) = {}\")\n    apply clarsimp\n   apply (unfold dom_map_add)[1]\n   apply clarsimp\n  apply clarsimp\n  done\n\nlemma map_add_result_empty2: \"a ++ b = Map.empty \\<Longrightarrow> b = Map.empty\"\n  apply (subgoal_tac \"dom (a++b) = {}\")\n   apply (subgoal_tac \"dom (a) = {}\")\n    apply clarsimp\n   apply (unfold dom_map_add)[1]\n   apply clarsimp\n  apply clarsimp\n  done\n\nlemma map_add_emptyE [elim!]: \"\\<lbrakk>a ++ b = Map.empty; \\<lbrakk>a = Map.empty; b = Map.empty\\<rbrakk> \\<Longrightarrow> R\\<rbrakk> \\<Longrightarrow> R\"\n  apply (frule map_add_result_empty1)\n  apply (frule map_add_result_empty2)\n  apply clarsimp\n  done\n\nlemma clean_slots_empty [simp]:\n  \"clean_slots Map.empty cmp = Map.empty\"\n  by (clarsimp simp: clean_slots_def)\n\nlemma object_type_update_slots [simp]:\n  \"object_type (update_slots slots x) = object_type x\"\n  by (clarsimp simp: object_type_def update_slots_def split: cdl_object.splits)\n\nlemma object_type_object_clean_slots [simp]:\n  \"object_type (object_clean_slots x cmp) = object_type x\"\n  by (clarsimp simp: object_clean_slots_def)\n\nlemma object_type_object_clean_fields [simp]:\n  \"object_type (object_clean_fields x cmp) = object_type x\"\n  by (clarsimp simp: object_clean_fields_def object_type_def split: cdl_object.splits)\n\nlemma object_type_object_clean [simp]:\n  \"object_type (object_clean x cmp) = object_type x\"\n  by (clarsimp simp: object_clean_def)\n\nlemma object_type_add_to_slots [simp]:\n  \"object_type (add_to_slots slots x) = object_type x\"\n  by (clarsimp simp: object_type_def add_to_slots_def update_slots_def split: cdl_object.splits)\n\nlemma object_slots_update_slots [simp]:\n  \"has_slots obj \\<Longrightarrow> object_slots (update_slots slots obj) = slots\"\n  by (clarsimp simp: object_slots_def update_slots_def has_slots_def\n              split: cdl_object.splits)\n\nlemma object_slots_update_slots_empty [simp]:\n  \"\\<not>has_slots obj \\<Longrightarrow> object_slots (update_slots slots obj) = Map.empty\"\n  by (clarsimp simp: object_slots_def update_slots_def has_slots_def\n                 split: cdl_object.splits)\n\nlemma update_slots_no_slots [simp]:\n  \"\\<not>has_slots obj \\<Longrightarrow> update_slots slots obj = obj\"\n  by (clarsimp simp: update_slots_def has_slots_def split: cdl_object.splits)\n\nlemma update_slots_update_slots [simp]:\n  \"update_slots slots (update_slots slots' obj) = update_slots slots obj\"\n  by (clarsimp simp: update_slots_def split: cdl_object.splits)\n\nlemma update_slots_same_object:\n  \"a = b \\<Longrightarrow> update_slots a obj = update_slots b obj\"\n  by (erule arg_cong)\n\nlemma object_type_has_slots:\n  \"\\<lbrakk>has_slots x; object_type x = object_type y\\<rbrakk> \\<Longrightarrow> has_slots y\"\n  by (clarsimp simp: object_type_def has_slots_def split: cdl_object.splits)\n\nlemma object_slots_object_clean_fields [simp]:\n  \"object_slots (object_clean_fields obj cmp) = object_slots obj\"\n  by (clarsimp simp: object_slots_def object_clean_fields_def split: cdl_object.splits)\n\nlemma object_slots_object_clean_slots [simp]:\n  \"object_slots (object_clean_slots obj cmp) = clean_slots (object_slots obj) cmp\"\n  by (clarsimp simp: object_clean_slots_def object_slots_def update_slots_def split: cdl_object.splits)\n\nlemma object_slots_object_clean [simp]:\n  \"object_slots (object_clean obj cmp) = clean_slots (object_slots obj) cmp\"\n  by (clarsimp simp: object_clean_def)\n\nlemma object_slots_add_to_slots [simp]:\n  \"object_type y = object_type z \\<Longrightarrow> object_slots (add_to_slots (object_slots y) z) = object_slots y ++ object_slots z\"\n  by (clarsimp simp: object_slots_def add_to_slots_def update_slots_def object_type_def split: cdl_object.splits)\n\nlemma update_slots_object_clean_slots [simp]:\n  \"update_slots slots (object_clean_slots obj cmp) = update_slots slots obj\"\n  by (clarsimp simp: object_clean_slots_def)\n\nlemma object_clean_fields_idem [simp]:\n  \"object_clean_fields (object_clean_fields obj cmp) cmp = object_clean_fields obj cmp\"\n  by (clarsimp simp: object_clean_fields_def split: cdl_object.splits)\n\nlemma object_clean_slots_idem [simp]:\n  \"object_clean_slots (object_clean_slots obj cmp) cmp = object_clean_slots obj cmp\"\n  apply (case_tac  \"has_slots obj\")\n  apply (clarsimp simp: object_clean_slots_def clean_slots_def)+\n  done\n\nlemma object_clean_fields_object_clean_slots [simp]:\n  \"object_clean_fields (object_clean_slots obj gs) gs = object_clean_slots (object_clean_fields obj gs) gs\"\n  by (clarsimp simp: object_clean_fields_def object_clean_slots_def\n                     clean_slots_def object_slots_def update_slots_def\n              split: cdl_object.splits)\n\nlemma object_clean_idem [simp]:\n  \"object_clean (object_clean obj cmp) cmp = object_clean obj cmp\"\n  by (clarsimp simp: object_clean_def)\n\nlemma has_slots_object_clean_slots:\n \"has_slots (object_clean_slots obj cmp) = has_slots obj\"\n  by (clarsimp simp: has_slots_def object_clean_slots_def update_slots_def split: cdl_object.splits)\n\nlemma has_slots_object_clean_fields:\n \"has_slots (object_clean_fields obj cmp) = has_slots obj\"\n  by (clarsimp simp: has_slots_def object_clean_fields_def split: cdl_object.splits)\n\nlemma has_slots_object_clean:\n \"has_slots (object_clean obj cmp) = has_slots obj\"\n  by (clarsimp simp: object_clean_def has_slots_object_clean_slots has_slots_object_clean_fields)\n\nlemma object_slots_update_slots_object_clean_fields [simp]:\n  \"object_slots (update_slots slots (object_clean_fields obj cmp)) = object_slots (update_slots slots obj)\"\n  apply (case_tac \"has_slots obj\")\n   apply (clarsimp simp: has_slots_object_clean_fields)+\n  done\n\nlemma object_clean_fields_update_slots [simp]:\n \"object_clean_fields (update_slots slots obj) cmp = update_slots slots (object_clean_fields obj cmp)\"\n  by (clarsimp simp: object_clean_fields_def update_slots_def split: cdl_object.splits)\n\nlemma object_clean_fields_twice [simp]:\n  \"(object_clean_fields (object_clean_fields obj cmp') cmp) = object_clean_fields obj (cmp \\<inter> cmp')\"\n  by (clarsimp simp: object_clean_fields_def split: cdl_object.splits)\n\nlemma update_slots_object_clean_fields:\n  \"\\<lbrakk>None \\<notin> cmps; None \\<notin> cmps'; object_type obj = object_type obj'\\<rbrakk>\n    \\<Longrightarrow> update_slots slots (object_clean_fields obj cmps) =\n        update_slots slots (object_clean_fields obj' cmps')\"\n  by (fastforce simp: update_slots_def object_clean_fields_def object_type_def split: cdl_object.splits)\n\nlemma object_clean_fields_no_slots:\n  \"\\<lbrakk>None \\<notin> cmps; None \\<notin> cmps'; object_type obj = object_type obj'; \\<not> has_slots obj; \\<not> has_slots obj'\\<rbrakk>\n    \\<Longrightarrow> object_clean_fields obj cmps = object_clean_fields obj' cmps'\"\n  by (fastforce simp: object_clean_fields_def object_type_def has_slots_def split: cdl_object.splits)\n\nlemma update_slots_object_clean:\n  \"\\<lbrakk>None \\<notin> cmps; None \\<notin> cmps'; object_type obj = object_type obj'\\<rbrakk>\n   \\<Longrightarrow> update_slots slots (object_clean obj cmps) = update_slots slots (object_clean obj' cmps')\"\n  apply (clarsimp simp: object_clean_def object_clean_slots_def)\n  apply (erule (2) update_slots_object_clean_fields)\n  done\n\nlemma cdl_heap_add_assoc':\n  \"\\<forall>obj_id. not_conflicting_objects x z obj_id \\<and>\n            not_conflicting_objects y z obj_id \\<and>\n            not_conflicting_objects x z obj_id \\<Longrightarrow>\n   cdl_heap_add (SepState (cdl_heap_add x y) (cdl_ghost_state_add x y)) z =\n   cdl_heap_add x (SepState (cdl_heap_add y z) (cdl_ghost_state_add y z))\"\n  apply (rule ext)\n  apply (rename_tac obj_id)\n  apply (erule_tac x=obj_id in allE)\n  apply (clarsimp simp: cdl_heap_add_def cdl_ghost_state_add_def not_conflicting_objects_def)\n  apply (simp add: Let_unfold split: option.splits)\n  apply (rename_tac obj_y obj_x obj_z)\n  apply (clarsimp simp: object_add_def clean_slots_def object_clean_def object_clean_slots_def Let_unfold)\n  apply (case_tac \"has_slots obj_z\")\n   apply (subgoal_tac \"has_slots obj_y\")\n    apply (subgoal_tac \"has_slots obj_x\")\n     apply ((clarsimp simp: has_slots_object_clean_fields has_slots_object_clean_slots has_slots_object_clean\n                           map_add_restrict union_intersection |\n            drule inter_empty_not_both |\n            erule update_slots_object_clean_fields |\n            erule object_type_has_slots, simp |\n            simp | safe)+)[3]\n   apply (subgoal_tac \"\\<not> has_slots obj_y\")\n    apply (subgoal_tac \"\\<not> has_slots obj_x\")\n     apply ((clarsimp simp: has_slots_object_clean_fields has_slots_object_clean_slots has_slots_object_clean\n                           map_add_restrict union_intersection |\n            drule inter_empty_not_both |\n            erule object_clean_fields_no_slots |\n            erule object_type_has_slots, simp |\n            simp | safe)+)\n   apply (fastforce simp: object_type_has_slots)+\n  done\n\nlemma cdl_heap_add_assoc:\n  \"\\<lbrakk>sep_state_disj x y; sep_state_disj y z; sep_state_disj x z\\<rbrakk>\n  \\<Longrightarrow> cdl_heap_add (SepState (cdl_heap_add x y) (cdl_ghost_state_add x y)) z =\n      cdl_heap_add x (SepState (cdl_heap_add y z) (cdl_ghost_state_add y z))\"\n  apply (clarsimp simp: sep_state_disj_def)\n  apply (cut_tac cdl_heap_add_assoc')\n   apply fast\n  apply fastforce\n  done\n\nlemma cdl_ghost_state_add_assoc:\n  \"cdl_ghost_state_add (SepState (cdl_heap_add x y) (cdl_ghost_state_add x y)) z =\n   cdl_ghost_state_add x (SepState (cdl_heap_add y z) (cdl_ghost_state_add y z))\"\n  apply (rule ext)\n  apply (fastforce simp: cdl_heap_add_def cdl_ghost_state_add_def Let_unfold)\n  done\n\nlemma clean_slots_map_add_comm:\n  \"cmps_a \\<inter> cmps_b = {}\n  \\<Longrightarrow> clean_slots slots_a cmps_a ++ clean_slots slots_b cmps_b =\n      clean_slots slots_b cmps_b ++ clean_slots slots_a cmps_a\"\n  apply (clarsimp simp: clean_slots_def)\n  apply (drule the_set_inter_empty)\n  apply (erule map_add_restrict_comm)\n  done\n\nlemma object_clean_all:\n  \"object_type obj_a = object_type obj_b \\<Longrightarrow> object_clean obj_b {} = object_clean obj_a {}\"\n  apply (clarsimp simp: object_clean_def object_clean_slots_def clean_slots_def the_set_def)\n  apply (rule_tac cmps'1=\"{}\" and obj'1=\"obj_a\" in trans [OF update_slots_object_clean_fields], fastforce+)\n  done\n\nlemma object_add_comm:\n  \"\\<lbrakk>object_type obj_a = object_type obj_b; cmps_a \\<inter> cmps_b = {}\\<rbrakk>\n  \\<Longrightarrow> object_add obj_a obj_b cmps_a cmps_b = object_add obj_b obj_a cmps_b cmps_a\"\n  apply (clarsimp simp: object_add_def Let_unfold)\n  apply (rule conjI | clarsimp)+\n    apply fastforce\n  apply (rule conjI | clarsimp)+\n   apply (drule_tac slots_a = \"object_slots obj_a\" and slots_b = \"object_slots obj_b\" in clean_slots_map_add_comm)\n   apply fastforce\n  apply (rule conjI | clarsimp)+\n   apply (drule_tac slots_a = \"object_slots obj_a\" and slots_b = \"object_slots obj_b\" in clean_slots_map_add_comm)\n   apply fastforce\n  apply (rule conjI | clarsimp)+\n   apply (erule object_clean_all)\n  apply (clarsimp)\n  apply (rule_tac cmps'1=cmps_b and obj'1=obj_b in trans [OF update_slots_object_clean], assumption+)\n  apply (drule_tac slots_a = \"object_slots obj_a\" and slots_b = \"object_slots obj_b\" in clean_slots_map_add_comm)\n  apply fastforce\n  done\n\nlemma sep_state_add_comm:\n  \"sep_state_disj x y \\<Longrightarrow> sep_state_add x y = sep_state_add y x\"\n  apply (clarsimp simp: sep_state_add_def sep_state_disj_def)\n  apply (rule conjI)\n   apply (case_tac x, case_tac y, clarsimp)\n   apply (rename_tac heap_a gs_a heap_b gs_b)\n   apply (clarsimp simp: cdl_heap_add_def Let_unfold)\n   apply (rule ext)\n   apply (case_tac \"heap_a obj_id\")\n    apply (case_tac \"heap_b obj_id\", simp_all add: slots_of_heap_def)\n   apply (case_tac \"heap_b obj_id\", simp_all add: slots_of_heap_def)\n   apply (rename_tac obj_a obj_b)\n   apply (erule_tac x=obj_id in allE)\n   apply (rule object_add_comm)\n    apply (clarsimp simp: not_conflicting_objects_def)\n   apply (clarsimp simp: not_conflicting_objects_def)\n  apply (rule ext, fastforce simp: cdl_ghost_state_add_def Let_unfold Un_commute)\n  done\n\nlemma add_to_slots_comm:\n  \"\\<lbrakk>object_slots y_obj \\<bottom> object_slots z_obj; update_slots Map.empty y_obj = update_slots Map.empty z_obj \\<rbrakk>\n  \\<Longrightarrow> add_to_slots (object_slots z_obj) y_obj = add_to_slots (object_slots y_obj) z_obj\"\n  by (fastforce simp: add_to_slots_def update_slots_def object_slots_def\n                     cdl_tcb.splits cdl_cnode.splits\n              dest!: map_add_com\n              split: cdl_object.splits)\n\nlemma cdl_heap_add_none1:\n  \"cdl_heap_add x y obj_id = None \\<Longrightarrow> (sep_heap x) obj_id = None\"\n  by (clarsimp simp: cdl_heap_add_def Let_unfold split:option.splits if_split_asm)\n\nlemma cdl_heap_add_none2:\n  \"cdl_heap_add x y obj_id = None \\<Longrightarrow> (sep_heap y) obj_id = None\"\n  by (clarsimp simp: cdl_heap_add_def Let_unfold split:option.splits if_split_asm)\n\nlemma object_type_object_addL:\n  \"object_type obj = object_type obj'\n  \\<Longrightarrow> object_type (object_add obj obj' cmp cmp') = object_type obj\"\n  by (clarsimp simp: object_add_def Let_unfold)\n\nlemma object_type_object_addR:\n  \"object_type obj = object_type obj'\n  \\<Longrightarrow> object_type (object_add obj obj' cmp cmp') = object_type obj'\"\n  by (clarsimp simp: object_add_def Let_unfold)\n\nlemma sep_state_add_disjL:\n  \"\\<lbrakk>sep_state_disj y z; sep_state_disj x (sep_state_add y z)\\<rbrakk> \\<Longrightarrow> sep_state_disj x y\"\n  apply (clarsimp simp: sep_state_disj_def sep_state_add_def)\n  apply (rename_tac obj_id)\n  apply (clarsimp simp: not_conflicting_objects_def)\n  apply (erule_tac x=obj_id in allE)+\n  apply (fastforce simp: cdl_heap_add_def cdl_ghost_state_add_def object_type_object_addR\n                 split: option.splits)\n  done\n\nlemma sep_state_add_disjR:\n  \"\\<lbrakk>sep_state_disj y z; sep_state_disj x (sep_state_add y z)\\<rbrakk> \\<Longrightarrow> sep_state_disj x z\"\n  apply (clarsimp simp: sep_state_disj_def sep_state_add_def)\n  apply (rename_tac obj_id)\n  apply (clarsimp simp: not_conflicting_objects_def)\n  apply (erule_tac x=obj_id in allE)+\n  apply (fastforce simp: cdl_heap_add_def cdl_ghost_state_add_def object_type_object_addR\n                 split: option.splits)\n  done\n\nlemma sep_state_add_disj:\n  \"\\<lbrakk>sep_state_disj y z; sep_state_disj x y; sep_state_disj x z\\<rbrakk> \\<Longrightarrow> sep_state_disj x (sep_state_add y z)\"\n  apply (clarsimp simp: sep_state_disj_def sep_state_add_def)\n  apply (rename_tac obj_id)\n  apply (clarsimp simp: not_conflicting_objects_def)\n  apply (erule_tac x=obj_id in allE)+\n  apply (fastforce simp: cdl_heap_add_def cdl_ghost_state_add_def object_type_object_addR\n                 split: option.splits)\n  done\n\n\n\n\n(*********************************************)\n(* Definition of separation logic for capDL. *)\n(*********************************************)\n\ninstantiation \"sep_state\" :: zero\nbegin\n  definition \"0 \\<equiv> SepState Map.empty (\\<lambda>obj_id. {})\"\n  instance ..\nend\n\ninstantiation \"sep_state\" :: stronger_sep_algebra\nbegin\n\ndefinition \"(##) \\<equiv> sep_state_disj\"\ndefinition \"(+) \\<equiv> sep_state_add\"\n\n\n\n(**********************************************\n * The proof that this is a separation logic. *\n **********************************************)\n\ninstance\n  apply intro_classes\n(* x ## 0 *)\n       apply (simp add: sep_disj_sep_state_def sep_state_disj_def zero_sep_state_def)\n(* x ## y \\<Longrightarrow> y ## x *)\n      apply (clarsimp simp: not_conflicting_objects_comm sep_disj_sep_state_def sep_state_disj_def Let_unfold\n                            map_disj_com Int_commute)\n(* x + 0 = x *)\n     apply (simp add: plus_sep_state_def sep_state_add_def zero_sep_state_def)\n     apply (case_tac x)\n     apply (clarsimp simp: cdl_heap_add_def)\n     apply (rule ext)\n     apply (clarsimp simp: cdl_ghost_state_add_def split:if_split_asm)\n(* x ## y \\<Longrightarrow> x + y = y + x *)\n    apply (clarsimp simp: plus_sep_state_def sep_disj_sep_state_def)\n    apply (erule sep_state_add_comm)\n(* (x + y) + z = x + (y + z) *)\n   apply (simp add: plus_sep_state_def sep_state_add_def)\n   apply (rule conjI)\n   apply (clarsimp simp: sep_disj_sep_state_def)\n    apply (erule (2) cdl_heap_add_assoc)\n   apply (rule cdl_ghost_state_add_assoc)\n(* x ## y + z = (x ## y \\<and> x ## z) *)\n  apply (clarsimp simp: plus_sep_state_def sep_disj_sep_state_def)\n  apply (rule iffI)\n   (* x ## y + z \\<Longrightarrow> (x ## y \\<and> x ## z) *)\n   apply (rule conjI)\n    (* x ## y + z \\<Longrightarrow> (x ## y) *)\n    apply (erule (1) sep_state_add_disjL)\n   (* x ## y + z \\<Longrightarrow> (x ## z) *)\n   apply (erule (1) sep_state_add_disjR)\n  (* x ## y + z \\<Longleftarrow> (x ## y \\<and> x ## z) *)\n  apply clarsimp\n  apply (erule (2) sep_state_add_disj)\n  done\n\nend\n\n\nend\n", "meta": {"author": "NICTA", "repo": "l4v", "sha": "3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b", "save_path": "github-repos/isabelle/NICTA-l4v", "path": "github-repos/isabelle/NICTA-l4v/l4v-3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b/lib/sep_algebra/ex/capDL/Abstract_Separation_D.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6001883735630722, "lm_q2_score": 0.4532618480153861, "lm_q1q2_score": 0.272042491358547}}
{"text": "theory Calls\n  imports \"reassembly_setup.Leviathan_Setup\"\n          \"Det_Step\"\nbegin\n\ncontext execution_context\nbegin\ntext \"To call a concrete function on a concrete state.\"\ndefinition call\\<^sub>c :: \"(state \\<Rightarrow> state) \\<Rightarrow> state \\<Rightarrow> state \\<Rightarrow> bool\"\n  where \"call\\<^sub>c f s s' \\<equiv> s' = (let s'' = f s in s''\\<lparr>regs := (regs s'')(rip := get_rip s + 5)\\<rparr>)\"\n\ntext \"To call an abstract function on an abstract state\"\ndefinition abstract\\<^sub>0 :: \"(state \\<Rightarrow> '\\<sigma>\\<^sub>C \\<times> '\\<sigma>\\<^sub>C\\<^sub>C) \\<Rightarrow> _ \\<Rightarrow> unit \\<times> '\\<sigma>\\<^sub>C \\<Rightarrow> unit \\<times> '\\<sigma>\\<^sub>C \\<Rightarrow> bool\"\n  where \"abstract\\<^sub>0 S f \\<sigma> \\<sigma>' \\<equiv> \\<exists> s s' . call\\<^sub>c f s s' \\<and> ((), \\<L> S s') = \\<sigma>' \\<and> ((), \\<L> S s) = \\<sigma>\"\n\nlemma abstract_call\\<^sub>0:\n  shows \"call\\<^sub>c f s s' \\<Longrightarrow> abstract\\<^sub>0 S f ((), \\<L> S s) ((), \\<L> S s')\"\n  by (auto simp add: call\\<^sub>c_def Let_def abstract\\<^sub>0_def)\n\ndefinition abstract\\<^sub>1\\<^sub>_\\<^sub>3\\<^sub>2 :: \"(state \\<Rightarrow> '\\<sigma>\\<^sub>C \\<times> '\\<sigma>\\<^sub>C\\<^sub>C) \\<Rightarrow> _ \\<Rightarrow> 32 word \\<Rightarrow> unit \\<times> '\\<sigma>\\<^sub>C \\<Rightarrow> unit \\<times> '\\<sigma>\\<^sub>C \\<Rightarrow> bool\"\n  where \"abstract\\<^sub>1\\<^sub>_\\<^sub>3\\<^sub>2 S f p\\<^sub>0 \\<sigma> \\<sigma>' \\<equiv> \\<exists> s s' . EDI s = p\\<^sub>0 \\<and> call\\<^sub>c f s s' \\<and> ((), \\<L> S s') = \\<sigma>' \\<and> ((), \\<L> S s) = \\<sigma>\"\n\nlemma abstract_call\\<^sub>1\\<^sub>_\\<^sub>3\\<^sub>2:\n  shows \"EDI s = p\\<^sub>0 \\<Longrightarrow> call\\<^sub>c f s s' \\<Longrightarrow> abstract\\<^sub>1\\<^sub>_\\<^sub>3\\<^sub>2 S f p\\<^sub>0 ((), \\<L> S s) ((), \\<L> S s')\"\n  by (auto simp add: call\\<^sub>c_def Let_def abstract\\<^sub>1\\<^sub>_\\<^sub>3\\<^sub>2_def)\n\ndefinition abstract\\<^sub>1\\<^sub>_\\<^sub>6\\<^sub>4 :: \"(state \\<Rightarrow> '\\<sigma>\\<^sub>C \\<times> '\\<sigma>\\<^sub>C\\<^sub>C) \\<Rightarrow> _ \\<Rightarrow> 64 word \\<Rightarrow> unit \\<times> '\\<sigma>\\<^sub>C \\<Rightarrow> unit \\<times> '\\<sigma>\\<^sub>C \\<Rightarrow> bool\"\n  where \"abstract\\<^sub>1\\<^sub>_\\<^sub>6\\<^sub>4 S f p\\<^sub>0 \\<sigma> \\<sigma>' \\<equiv> \\<exists> s s' . RDI s = p\\<^sub>0 \\<and> call\\<^sub>c f s s' \\<and> ((), \\<L> S s') = \\<sigma>' \\<and> ((), \\<L> S s) = \\<sigma>\"\n\nlemma abstract_call\\<^sub>1\\<^sub>_\\<^sub>6\\<^sub>4:\n  shows \"RDI s = p\\<^sub>0 \\<Longrightarrow> call\\<^sub>c f s s' \\<Longrightarrow> abstract\\<^sub>1\\<^sub>_\\<^sub>6\\<^sub>4 S f p\\<^sub>0 ((), \\<L> S s) ((), \\<L> S s')\"\n  by (auto simp add: call\\<^sub>c_def Let_def abstract\\<^sub>1\\<^sub>_\\<^sub>6\\<^sub>4_def)\n\ndefinition abstract\\<^sub>2\\<^sub>_\\<^sub>6\\<^sub>4\\<^sub>_\\<^sub>3\\<^sub>2 :: \"(state \\<Rightarrow> '\\<sigma>\\<^sub>C \\<times> '\\<sigma>\\<^sub>C\\<^sub>C) \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> unit \\<times> '\\<sigma>\\<^sub>C \\<Rightarrow> unit \\<times> '\\<sigma>\\<^sub>C \\<Rightarrow> bool\"\n  where \"abstract\\<^sub>2\\<^sub>_\\<^sub>6\\<^sub>4\\<^sub>_\\<^sub>3\\<^sub>2 S f p\\<^sub>0 p\\<^sub>1 \\<sigma> \\<sigma>' \\<equiv> \\<exists> s s' . RDI s = p\\<^sub>0 \\<and> ESI s = p\\<^sub>1 \\<and> call\\<^sub>c f s s' \\<and> ((), \\<L> S s') = \\<sigma>' \\<and> ((), \\<L> S s) = \\<sigma>\"\n\nlemma abstract_call\\<^sub>2\\<^sub>_\\<^sub>6\\<^sub>4\\<^sub>_\\<^sub>3\\<^sub>2:\n  shows \"RDI s = p\\<^sub>0 \\<Longrightarrow> ESI s = p\\<^sub>1 \\<Longrightarrow> call\\<^sub>c f s s' \\<Longrightarrow> abstract\\<^sub>2\\<^sub>_\\<^sub>6\\<^sub>4\\<^sub>_\\<^sub>3\\<^sub>2 S f p\\<^sub>0 p\\<^sub>1 ((), \\<L> S s) ((), \\<L> S s')\"\n  by (auto simp add: call\\<^sub>c_def Let_def abstract\\<^sub>2\\<^sub>_\\<^sub>6\\<^sub>4\\<^sub>_\\<^sub>3\\<^sub>2_def)\n\ndefinition abstract\\<^sub>2\\<^sub>_\\<^sub>3\\<^sub>2_\\<^sub>3\\<^sub>2 :: \"(state \\<Rightarrow> '\\<sigma>\\<^sub>C \\<times> '\\<sigma>\\<^sub>C\\<^sub>C) \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> unit \\<times> '\\<sigma>\\<^sub>C \\<Rightarrow> unit \\<times> '\\<sigma>\\<^sub>C \\<Rightarrow> bool\"\n  where \"abstract\\<^sub>2\\<^sub>_\\<^sub>3\\<^sub>2_\\<^sub>3\\<^sub>2 S f p\\<^sub>0 p\\<^sub>1 \\<sigma> \\<sigma>' \\<equiv> \\<exists> s s' . EDI s = p\\<^sub>0 \\<and> ESI s = p\\<^sub>1 \\<and> call\\<^sub>c f s s' \\<and> ((), \\<L> S s') = \\<sigma>' \\<and> ((), \\<L> S s) = \\<sigma>\"\n\nlemma abstract_call\\<^sub>2\\<^sub>_\\<^sub>3\\<^sub>2\\<^sub>_\\<^sub>3\\<^sub>2:\n  shows \"EDI s = p\\<^sub>0 \\<Longrightarrow> ESI s = p\\<^sub>1 \\<Longrightarrow> call\\<^sub>c f s s' \\<Longrightarrow> abstract\\<^sub>2\\<^sub>_\\<^sub>3\\<^sub>2_\\<^sub>3\\<^sub>2 S f p\\<^sub>0 p\\<^sub>1 ((), \\<L> S s) ((), \\<L> S s')\"\n  by (auto simp add: call\\<^sub>c_def Let_def abstract\\<^sub>2\\<^sub>_\\<^sub>3\\<^sub>2_\\<^sub>3\\<^sub>2_def)\n\nend\nend", "meta": {"author": "ssrg-vt", "repo": "Luce-src", "sha": "f7f1ef0fd07bba48bcb3d5e32404db6013a5f1bc", "save_path": "github-repos/isabelle/ssrg-vt-Luce-src", "path": "github-repos/isabelle/ssrg-vt-Luce-src/Luce-src-f7f1ef0fd07bba48bcb3d5e32404db6013a5f1bc/safecomp2019_artifact/current_work/isabelle/Calls.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6001883735630721, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.27204249135854697}}
{"text": "(*  File:       Loop_Composition.thy\n    Copyright   2021  Karlsruhe Institute of Technology (KIT)\n*)\n\\<^marker>\\<open>creator \"Karsten Diekhoff, Karlsruhe Institute of Technology (KIT)\"\\<close>\n\\<^marker>\\<open>contributor \"Jonas Kraemer, Karlsruhe Institute of Technology (KIT)\"\\<close>\n\\<^marker>\\<open>contributor \"Michael Kirsten, Karlsruhe Institute of Technology (KIT)\"\\<close>\n\nsection \\<open>Loop Composition\\<close>\n\ntheory Loop_Composition\n  imports \"Basic_Modules/Component_Types/Termination_Condition\"\n          \"Basic_Modules/Defer_Module\"\n          Sequential_Composition\nbegin\n\ntext\n\\<open>The loop composition uses the same module in sequence,\ncombined with a termination condition, until either\n  (1) the termination condition is met or\n  (2) no new decisions are made (i.e., a fixed point is reached).\\<close>\n\nsubsection \\<open>Definition\\<close>\n\nlemma loop_termination_helper:\n  assumes\n    not_term: \"\\<not>t (acc A p)\" and\n    subset: \"defer (acc \\<triangleright> m) A p \\<subset> defer acc A p\" and\n    not_inf: \"\\<not>infinite (defer acc A p)\"\n  shows\n    \"((acc \\<triangleright> m, m, t, A, p), (acc, m, t, A, p)) \\<in>\n        measure (\\<lambda>(acc, m, t, A, p). card (defer acc A p))\"\n  using assms psubset_card_mono\n  by auto\n\n(*\n   This function handles the accumulator for the following loop composition\n   function.\n*)\nfunction loop_comp_helper ::\n    \"'a Electoral_Module \\<Rightarrow> 'a Electoral_Module \\<Rightarrow>\n        'a Termination_Condition \\<Rightarrow> 'a Electoral_Module\" where\n  \"t (acc A p) \\<or> \\<not>((defer (acc \\<triangleright> m) A p) \\<subset> (defer acc A p)) \\<or>\n    infinite (defer acc A p) \\<Longrightarrow>\n      loop_comp_helper acc m t A p = acc A p\" |\n  \"\\<not>(t (acc A p) \\<or> \\<not>((defer (acc \\<triangleright> m) A p) \\<subset> (defer acc A p)) \\<or>\n    infinite (defer acc A p)) \\<Longrightarrow>\n      loop_comp_helper acc m t A p = loop_comp_helper (acc \\<triangleright> m) m t A p\"\nproof -\n  fix\n    P :: bool and\n    x :: \"('a Electoral_Module) \\<times> ('a Electoral_Module) \\<times>\n          ('a Termination_Condition) \\<times> 'a set \\<times> 'a Profile\"\n  assume\n    a1: \"\\<And>t acc A p m.\n          \\<lbrakk>t (acc A p) \\<or> \\<not> defer (acc \\<triangleright> m) A p \\<subset> defer acc A p \\<or>\n              infinite (defer acc A p);\n            x = (acc, m, t, A, p)\\<rbrakk> \\<Longrightarrow> P\" and\n    a2: \"\\<And>t acc A p m.\n          \\<lbrakk>\\<not> (t (acc A p) \\<or> \\<not> defer (acc \\<triangleright> m) A p \\<subset> defer acc A p \\<or>\n              infinite (defer acc A p));\n            x = (acc, m, t, A, p)\\<rbrakk> \\<Longrightarrow> P\"\n  have \"\\<exists>f A p p2 g. (g, f, p, A, p2) = x\"\n    using prod_cases5\n    by metis\n  then show P\n    using a2 a1\n    by (metis (no_types))\nnext\n  show\n    \"\\<And>t acc A p m ta acca Aa pa ma.\n       t (acc A p) \\<or> \\<not> defer (acc \\<triangleright> m) A p \\<subset> defer acc A p \\<or>\n        infinite (defer acc A p) \\<Longrightarrow>\n          ta (acca Aa pa) \\<or> \\<not> defer (acca \\<triangleright> ma) Aa pa \\<subset> defer acca Aa pa \\<or>\n          infinite (defer acca Aa pa) \\<Longrightarrow>\n           (acc, m, t, A, p) = (acca, ma, ta, Aa, pa) \\<Longrightarrow>\n              acc A p = acca Aa pa\"\n    by fastforce\nnext\n  show\n    \"\\<And>t acc A p m ta acca Aa pa ma.\n       t (acc A p) \\<or> \\<not> defer (acc \\<triangleright> m) A p \\<subset> defer acc A p \\<or>\n        infinite (defer acc A p) \\<Longrightarrow>\n          \\<not> (ta (acca Aa pa) \\<or> \\<not> defer (acca \\<triangleright> ma) Aa pa \\<subset> defer acca Aa pa \\<or>\n          infinite (defer acca Aa pa)) \\<Longrightarrow>\n           (acc, m, t, A, p) = (acca, ma, ta, Aa, pa) \\<Longrightarrow>\n              acc A p = loop_comp_helper_sumC (acca \\<triangleright> ma, ma, ta, Aa, pa)\"\n  proof -\n    fix\n      t :: \"'a Termination_Condition\" and\n      acc :: \"'a Electoral_Module\" and\n      A :: \"'a set\" and\n      p :: \"'a Profile\" and\n      m :: \"'a Electoral_Module\" and\n      ta :: \"'a Termination_Condition\" and\n      acca :: \"'a Electoral_Module\" and\n      Aa :: \"'a set\" and\n      pa :: \"'a Profile\" and\n      ma :: \"'a Electoral_Module\"\n    assume\n      a1: \"t (acc A p) \\<or> \\<not> defer (acc \\<triangleright> m) A p \\<subset> defer acc A p \\<or>\n            infinite (defer acc A p)\" and\n      a2: \"\\<not> (ta (acca Aa pa) \\<or> \\<not> defer (acca \\<triangleright> ma) Aa pa \\<subset> defer acca Aa pa \\<or>\n            infinite (defer acca Aa pa))\" and\n      \"(acc, m, t, A, p) = (acca, ma, ta, Aa, pa)\"\n    hence False\n      using a2 a1\n      by force\n  thus \"acc A p = loop_comp_helper_sumC (acca \\<triangleright> ma, ma, ta, Aa, pa)\"\n    by auto\nqed\nnext\n  show\n    \"\\<And>t acc A p m ta acca Aa pa ma.\n       \\<not> (t (acc A p) \\<or> \\<not> defer (acc \\<triangleright> m) A p \\<subset> defer acc A p \\<or>\n          infinite (defer acc A p)) \\<Longrightarrow>\n           \\<not> (ta (acca Aa pa) \\<or> \\<not> defer (acca \\<triangleright> ma) Aa pa \\<subset> defer acca Aa pa \\<or>\n            infinite (defer acca Aa pa)) \\<Longrightarrow>\n             (acc, m, t, A, p) = (acca, ma, ta, Aa, pa) \\<Longrightarrow>\n                loop_comp_helper_sumC (acc \\<triangleright> m, m, t, A, p) =\n                  loop_comp_helper_sumC (acca \\<triangleright> ma, ma, ta, Aa, pa)\"\n    by force\nqed\ntermination\nproof -\n  have f0:\n    \"\\<exists>r. wf r \\<and>\n        (\\<forall>p f (A::'a set) prof g.\n          p (f A prof) \\<or>\n          \\<not> defer (f \\<triangleright> g) A prof \\<subset> defer f A prof \\<or>\n          infinite (defer f A prof) \\<or>\n          ((f \\<triangleright> g, g, p, A, prof), (f, g, p, A, prof)) \\<in> r)\"\n    using loop_termination_helper wf_measure \"termination\"\n    by (metis (no_types))\n  hence\n    \"\\<forall>r p.\n      Ex ((\\<lambda>ra. \\<forall>f (A::'a set) prof pa g.\n            \\<exists>prof2 pb p_rel pc pd h (B::'a set) prof3 i pe.\n        \\<not> wf r \\<or>\n          loop_comp_helper_dom\n            (p::('a Electoral_Module) \\<times> (_ Electoral_Module) \\<times>\n              (_ Termination_Condition) \\<times> _ set \\<times> _ Profile) \\<or>\n          infinite (defer f A prof) \\<or>\n          pa (f A prof) \\<and>\n            wf\n              (prof2::((\n                ('a Electoral_Module) \\<times> ('a Electoral_Module) \\<times>\n                ('a Termination_Condition) \\<times> 'a set \\<times> 'a Profile) \\<times> _) set) \\<and>\n            \\<not> loop_comp_helper_dom (pb::\n                ('a Electoral_Module) \\<times> (_ Electoral_Module) \\<times>\n                (_ Termination_Condition) \\<times> _ set \\<times> _ Profile) \\<or>\n          wf p_rel \\<and> \\<not> defer (f \\<triangleright> g) A prof \\<subset> defer f A prof \\<and>\n            \\<not> loop_comp_helper_dom\n                (pc::('a Electoral_Module) \\<times> (_ Electoral_Module) \\<times>\n                  (_ Termination_Condition) \\<times> _ set \\<times> _ Profile) \\<or>\n            ((f \\<triangleright> g, g, pa, A, prof), f, g, pa, A, prof) \\<in> p_rel \\<and> wf p_rel \\<and>\n            \\<not> loop_comp_helper_dom\n                (pd::('a Electoral_Module) \\<times> (_ Electoral_Module) \\<times>\n                  (_ Termination_Condition) \\<times> _ set \\<times> _ Profile) \\<or>\n            finite (defer h B prof3) \\<and>\n            defer (h \\<triangleright> i) B prof3 \\<subset> defer h B prof3 \\<and>\n            \\<not> pe (h B prof3) \\<and>\n            ((h \\<triangleright> i, i, pe, B, prof3), h, i, pe, B, prof3) \\<notin> r)::\n          ((('a Electoral_Module) \\<times> ('a Electoral_Module) \\<times>\n            ('a Termination_Condition) \\<times> 'a set \\<times> 'a Profile) \\<times>\n            ('a Electoral_Module) \\<times> ('a Electoral_Module) \\<times>\n            ('a Termination_Condition) \\<times> 'a set \\<times> 'a Profile) set \\<Rightarrow> bool)\"\n    by metis\n  obtain\n    p_rel ::  \"((('a Electoral_Module) \\<times> ('a Electoral_Module) \\<times>\n               ('a Termination_Condition) \\<times> 'a set \\<times> 'a Profile) \\<times>\n               ('a Electoral_Module) \\<times> ('a Electoral_Module) \\<times>\n               ('a Termination_Condition) \\<times> 'a set \\<times> 'a Profile) set\" where\n      \"wf p_rel \\<and>\n        (\\<forall>p f A prof g. p (f A prof) \\<or>\n          \\<not> defer (f \\<triangleright> g) A prof \\<subset> defer f A prof \\<or>\n          infinite (defer f A prof) \\<or>\n          ((f \\<triangleright> g, g, p, A, prof), f, g, p, A, prof) \\<in> p_rel)\"\n    using f0\n    by presburger\n  thus ?thesis\n    using \"termination\"\n    by metis\nqed\n\nlemma loop_comp_code_helper[code]:\n  \"loop_comp_helper acc m t A p =\n    (if (t (acc A p) \\<or> \\<not>((defer (acc \\<triangleright> m) A p) \\<subset> (defer acc A p)) \\<or>\n      infinite (defer acc A p))\n    then (acc A p) else (loop_comp_helper (acc \\<triangleright> m) m t A p))\"\n  by simp\n\nfunction loop_composition ::\n    \"'a Electoral_Module \\<Rightarrow> 'a Termination_Condition \\<Rightarrow>\n        'a Electoral_Module\" where\n  \"t ({}, {}, A) \\<Longrightarrow>\n    loop_composition m t A p = defer_module A p\" |\n  \"\\<not>(t ({}, {}, A)) \\<Longrightarrow>\n    loop_composition m t A p = (loop_comp_helper m m t) A p\"\n  by (fastforce, simp_all)\ntermination\n  using  \"termination\" wf_empty\n  by blast\n\nabbreviation loop ::\n  \"'a Electoral_Module \\<Rightarrow> 'a Termination_Condition \\<Rightarrow> 'a Electoral_Module\"\n    (\"_ \\<circlearrowleft>\\<^sub>_\" 50) where\n  \"m \\<circlearrowleft>\\<^sub>t \\<equiv> loop_composition m t\"\n\nlemma loop_comp_code[code]:\n  \"loop_composition m t A p =\n    (if (t ({},{},A))\n    then (defer_module A p) else (loop_comp_helper m m t) A p)\"\n  by simp\n\nlemma loop_comp_helper_imp_partit:\n  assumes\n    module_m: \"electoral_module m\" and\n    profile: \"finite_profile A p\"\n  shows\n    \"electoral_module acc \\<and> (n = card (defer acc A p)) \\<Longrightarrow>\n        well_formed A (loop_comp_helper acc m t A p)\"\nproof (induct arbitrary: acc rule: less_induct)\n  case (less)\n  have\n    \"\\<forall>(f::'a set \\<Rightarrow> 'a Profile \\<Rightarrow> 'a Result) g.\n      (electoral_module f \\<and> electoral_module g) \\<longrightarrow>\n        electoral_module (f \\<triangleright> g)\"\n    by auto\n  hence \"electoral_module (acc \\<triangleright> m)\"\n    using less.prems module_m\n    by metis\n  hence wf_acc:\n    \"\\<not> t (acc A p) \\<and> \\<not> t (acc A p) \\<and>\n      defer (acc \\<triangleright> m) A p \\<subset> defer acc A p \\<and>\n      finite (defer acc A p) \\<longrightarrow>\n        well_formed A (loop_comp_helper acc m t A p)\"\n    using less.hyps less.prems loop_comp_helper.simps(2)\n          psubset_card_mono\n  by metis\n  have \"well_formed A (acc A p)\"\n    using electoral_module_def less.prems profile\n    by blast\n  thus ?case\n    using wf_acc loop_comp_helper.simps(1)\n    by (metis (no_types))\nqed\n\nsubsection \\<open>Soundness\\<close>\n\ntheorem loop_comp_sound:\n  assumes m_module: \"electoral_module m\"\n  shows \"electoral_module (m \\<circlearrowleft>\\<^sub>t)\"\n  using def_mod_sound electoral_module_def loop_composition.simps(1)\n        loop_composition.simps(2) loop_comp_helper_imp_partit m_module\n  by metis\n\nlemma loop_comp_helper_imp_no_def_incr:\n  assumes\n    module_m: \"electoral_module m\" and\n    profile: \"finite_profile A p\"\n  shows\n    \"(electoral_module acc \\<and> n = card (defer acc A p)) \\<Longrightarrow>\n        defer (loop_comp_helper acc m t) A p \\<subseteq> defer acc A p\"\nproof (induct arbitrary: acc rule: less_induct)\n  case (less)\n  have emod_acc_m: \"electoral_module (acc \\<triangleright> m)\"\n    using less.prems module_m\n    by simp\n  have \"\\<forall>A Aa. infinite (A::'a set) \\<or> \\<not> Aa \\<subset> A \\<or> card Aa < card A\"\n    using psubset_card_mono\n    by metis\n  hence\n    \"\\<not> t (acc A p) \\<and> defer (acc \\<triangleright> m) A p \\<subset> defer acc A p \\<and>\n      finite (defer acc A p) \\<longrightarrow>\n        defer (loop_comp_helper (acc \\<triangleright> m) m t) A p \\<subseteq> defer acc A p\"\n    using emod_acc_m less.hyps less.prems\n    by blast\n  hence\n    \"\\<not> t (acc A p) \\<and> defer (acc \\<triangleright> m) A p \\<subset> defer acc A p \\<and>\n        finite (defer acc A p) \\<longrightarrow>\n          defer (loop_comp_helper acc m t) A p \\<subseteq> defer acc A p\"\n    using loop_comp_helper.simps(2)\n    by (metis (no_types))\n  thus ?case\n    using eq_iff loop_comp_helper.simps(1)\n    by (metis (no_types))\nqed\n\nsubsection \\<open>Lemmata\\<close>\n\nlemma loop_comp_helper_def_lift_inv_helper:\n  assumes\n    monotone_m: \"defer_lift_invariance m\" and\n    f_prof: \"finite_profile A p\"\n  shows\n    \"(defer_lift_invariance acc \\<and> n = card (defer acc A p)) \\<longrightarrow>\n        (\\<forall>q a.\n          (a \\<in> (defer (loop_comp_helper acc m t) A p) \\<and>\n            lifted A p q a) \\<longrightarrow>\n                (loop_comp_helper acc m t) A p =\n                  (loop_comp_helper acc m t) A q)\"\nproof (induct n arbitrary: acc rule: less_induct)\n  case (less n)\n  have defer_card_comp:\n    \"defer_lift_invariance acc \\<longrightarrow>\n        (\\<forall>q a. (a \\<in> (defer (acc \\<triangleright> m) A p) \\<and> lifted A p q a) \\<longrightarrow>\n            card (defer (acc \\<triangleright> m) A p) = card (defer (acc \\<triangleright> m) A q))\"\n    using monotone_m def_lift_inv_seq_comp_help\n    by metis\n  have defer_card_acc:\n    \"defer_lift_invariance acc \\<longrightarrow>\n        (\\<forall>q a. (a \\<in> (defer (acc) A p) \\<and> lifted A p q a) \\<longrightarrow>\n            card (defer (acc) A p) = card (defer (acc) A q))\"\n    by (simp add: defer_lift_invariance_def)\n  hence defer_card_acc_2:\n    \"defer_lift_invariance acc \\<longrightarrow>\n        (\\<forall>q a. (a \\<in> (defer (acc \\<triangleright> m) A p) \\<and> lifted A p q a) \\<longrightarrow>\n            card (defer (acc) A p) = card (defer (acc) A q))\"\n    using monotone_m f_prof defer_lift_invariance_def seq_comp_def_set_trans\n    by metis\n  thus ?case\n  proof cases\n    assume card_unchanged: \"card (defer (acc \\<triangleright> m) A p) = card (defer acc A p)\"\n    with defer_card_comp defer_card_acc monotone_m\n    have\n      \"defer_lift_invariance (acc) \\<longrightarrow>\n          (\\<forall>q a. (a \\<in> (defer (acc) A p) \\<and> lifted A p q a) \\<longrightarrow>\n              (loop_comp_helper acc m t) A q = acc A q)\"\n    proof (safe)\n      fix\n        q :: \"'a Profile\" and\n        a :: \"'a\"\n      assume\n        def_card_eq:\n        \"card (defer (acc \\<triangleright> m) A p) = card (defer acc A p)\" and\n        dli_acc: \"defer_lift_invariance acc\" and\n        def_seq_lift_card:\n        \"\\<forall>q a. a \\<in> defer (acc \\<triangleright> m) A p \\<and> Profile.lifted A p q a \\<longrightarrow>\n          card (defer (acc \\<triangleright> m) A p) = card (defer (acc \\<triangleright> m) A q)\" and\n        a_in_def_acc: \"a \\<in> defer acc A p\" and\n        lifted_A: \"Profile.lifted A p q a\"\n      have emod_m: \"electoral_module m\"\n        using defer_lift_invariance_def monotone_m\n        by auto\n      have emod_acc: \"electoral_module acc\"\n        using defer_lift_invariance_def dli_acc\n        by blast\n      have acc_eq_pq: \"acc A q = acc A p\"\n        using a_in_def_acc defer_lift_invariance_def dli_acc lifted_A\n        by (metis (full_types))\n      with emod_acc emod_m\n      have\n        \"finite (defer acc A p) \\<longrightarrow>\n          loop_comp_helper acc m t A q = acc A q\"\n        using a_in_def_acc def_card_eq def_seq_lift_card\n              dual_order.strict_iff_order f_prof lifted_A\n              loop_comp_code_helper psubset_card_mono\n              seq_comp_def_set_bounded\n        by (metis (no_types))\n      thus \"loop_comp_helper acc m t A q = acc A q\"\n        using acc_eq_pq loop_comp_code_helper\n        by (metis (full_types))\n    qed\n    moreover from card_unchanged have\n      \"(loop_comp_helper acc m t) A p = acc A p\"\n      using loop_comp_helper.simps(1) order.strict_iff_order\n            psubset_card_mono\n      by metis\n    ultimately have\n      \"(defer_lift_invariance (acc \\<triangleright> m) \\<and> defer_lift_invariance acc) \\<longrightarrow>\n          (\\<forall>q a. (a \\<in> (defer (loop_comp_helper acc m t) A p) \\<and>\n              lifted A p q a) \\<longrightarrow>\n                  (loop_comp_helper acc m t) A p =\n                    (loop_comp_helper acc m t) A q)\"\n      using defer_lift_invariance_def\n      by metis\n    thus ?thesis\n      using monotone_m seq_comp_presv_def_lift_inv\n      by blast\n  next\n    assume card_changed:\n      \"\\<not> (card (defer (acc \\<triangleright> m) A p) = card (defer acc A p))\"\n    with f_prof seq_comp_def_card_bounded have card_smaller_for_p:\n      \"electoral_module (acc) \\<longrightarrow>\n          (card (defer (acc \\<triangleright> m) A p) < card (defer acc A p))\"\n      using monotone_m order.not_eq_order_implies_strict\n            defer_lift_invariance_def\n      by (metis (full_types))\n    with defer_card_acc_2 defer_card_comp\n    have card_changed_for_q:\n      \"defer_lift_invariance (acc) \\<longrightarrow>\n          (\\<forall>q a. (a \\<in> (defer (acc \\<triangleright> m) A p) \\<and> lifted A p q a) \\<longrightarrow>\n              (card (defer (acc \\<triangleright> m) A q) < card (defer acc A q)))\"\n      using defer_lift_invariance_def\n      by (metis (no_types, lifting))\n    thus ?thesis\n    proof cases\n      assume t_not_satisfied_for_p: \"\\<not> t (acc A p)\"\n      hence t_not_satisfied_for_q:\n        \"defer_lift_invariance (acc) \\<longrightarrow>\n            (\\<forall>q a. (a \\<in> (defer (acc \\<triangleright> m) A p) \\<and> lifted A p q a) \\<longrightarrow>\n                \\<not> t (acc A q))\"\n        using monotone_m f_prof defer_lift_invariance_def seq_comp_def_set_trans\n        by metis\n      from card_changed defer_card_comp defer_card_acc\n      have dli_card_def:\n        \"(defer_lift_invariance (acc \\<triangleright> m) \\<and> defer_lift_invariance (acc)) \\<longrightarrow>\n            (\\<forall>q a. (a \\<in> (defer (acc \\<triangleright> m) A p) \\<and> Profile.lifted A p q a) \\<longrightarrow>\n                card (defer (acc \\<triangleright> m) A q) \\<noteq> (card (defer acc A q)))\"\n      proof -\n        have\n          \"\\<forall>f.\n            (defer_lift_invariance f \\<or>\n              (\\<exists>A prof prof2 (a::'a).\n                f A prof \\<noteq> f A prof2 \\<and>\n                  Profile.lifted A prof prof2 a \\<and>\n                  a \\<in> defer f A prof) \\<or> \\<not> electoral_module f) \\<and>\n                  ((\\<forall>A p1 p2 b. f A p1 = f A p2 \\<or> \\<not> Profile.lifted A p1 p2 b \\<or>\n                    b \\<notin> defer f A p1) \\<and>\n                  electoral_module f \\<or> \\<not> defer_lift_invariance f)\"\n          using defer_lift_invariance_def\n          by blast\n        thus ?thesis\n          using card_changed monotone_m f_prof seq_comp_def_set_trans\n          by (metis (no_types, hide_lams))\n      qed\n      hence dli_def_subset:\n        \"defer_lift_invariance (acc \\<triangleright> m) \\<and> defer_lift_invariance (acc) \\<longrightarrow>\n            (\\<forall>q a. (a \\<in> (defer (acc \\<triangleright> m) A p) \\<and> lifted A p q a) \\<longrightarrow>\n                defer (acc \\<triangleright> m) A q \\<subset> defer acc A q)\"\n      proof -\n        {\n          fix\n            alt :: 'a and\n            prof :: \"'a Profile\"\n          have\n            \"(\\<not> defer_lift_invariance (acc \\<triangleright> m) \\<or> \\<not> defer_lift_invariance acc) \\<or>\n              (alt \\<notin> defer (acc \\<triangleright> m) A p \\<or> \\<not> lifted A p prof alt) \\<or>\n              defer (acc \\<triangleright> m) A prof \\<subset> defer acc A prof\"\n            using Profile.lifted_def dli_card_def defer_lift_invariance_def\n                  monotone_m psubsetI seq_comp_def_set_bounded\n            by (metis (no_types))\n        }\n        thus ?thesis\n          by metis\n      qed\n      with t_not_satisfied_for_p\n      have rec_step_q:\n        \"(defer_lift_invariance (acc \\<triangleright> m) \\<and> defer_lift_invariance (acc)) \\<longrightarrow>\n            (\\<forall>q a. (a \\<in> (defer (acc \\<triangleright> m) A p) \\<and> lifted A p q a) \\<longrightarrow>\n                loop_comp_helper acc m t A q =\n                  loop_comp_helper (acc \\<triangleright> m) m t A q)\"\n      proof (safe)\n        fix\n          q :: \"'a Profile\" and\n          a :: \"'a\"\n        assume\n          a_in_def_impl_def_subset:\n          \"\\<forall>q a. a \\<in> defer (acc \\<triangleright> m) A p \\<and> lifted A p q a \\<longrightarrow>\n            defer (acc \\<triangleright> m) A q \\<subset> defer acc A q\" and\n          dli_acc: \"defer_lift_invariance acc\" and\n          a_in_def_seq_acc_m: \"a \\<in> defer (acc \\<triangleright> m) A p\" and\n          lifted_pq_a: \"lifted A p q a\"\n        have defer_subset_acc:\n          \"defer (acc \\<triangleright> m) A q \\<subset> defer acc A q\"\n          using a_in_def_impl_def_subset lifted_pq_a\n                a_in_def_seq_acc_m\n          by metis\n        have \"electoral_module acc\"\n          using dli_acc defer_lift_invariance_def\n          by auto\n        hence \"finite (defer acc A q) \\<and> \\<not> t (acc A q)\"\n          using lifted_def dli_acc a_in_def_seq_acc_m\n                lifted_pq_a def_presv_fin_prof\n                t_not_satisfied_for_q\n          by metis\n        with defer_subset_acc\n        show\n          \"loop_comp_helper acc m t A q =\n            loop_comp_helper (acc \\<triangleright> m) m t A q\"\n          using loop_comp_code_helper\n          by metis\n      qed\n      have rec_step_p:\n        \"electoral_module acc \\<longrightarrow>\n            loop_comp_helper acc m t A p = loop_comp_helper (acc \\<triangleright> m) m t A p\"\n      proof (safe)\n        assume emod_acc: \"electoral_module acc\"\n        have emod_implies_defer_subset:\n          \"electoral_module m \\<longrightarrow> defer (acc \\<triangleright> m) A p \\<subseteq> defer acc A p\"\n          using emod_acc f_prof seq_comp_def_set_bounded\n          by blast\n        have card_ineq: \"card (defer (acc \\<triangleright> m) A p) < card (defer acc A p)\"\n          using card_smaller_for_p emod_acc\n          by force\n        have fin_def_limited_acc:\n          \"finite_profile (defer acc A p) (limit_profile (defer acc A p) p)\"\n          using def_presv_fin_prof emod_acc f_prof\n          by metis\n        have \"defer (acc \\<triangleright> m) A p \\<subseteq> defer acc A p\"\n          using emod_implies_defer_subset defer_lift_invariance_def monotone_m\n          by blast\n        hence \"defer (acc \\<triangleright> m) A p \\<subset> defer acc A p\"\n          using fin_def_limited_acc card_ineq card_psubset\n          by metis\n        with fin_def_limited_acc\n        show \"loop_comp_helper acc m t A p = loop_comp_helper (acc \\<triangleright> m) m t A p\"\n          using loop_comp_code_helper t_not_satisfied_for_p\n          by (metis (no_types))\n      qed\n      show ?thesis\n      proof (safe)\n        fix\n          q :: \"'a Profile\" and\n          a :: \"'a\"\n        assume\n          dli_acc: \"defer_lift_invariance acc\" and\n          n_card_acc: \"n = card (defer acc A p)\" and\n          a_in_defer_lch: \"a \\<in> defer (loop_comp_helper acc m t) A p\" and\n          a_lifted: \"Profile.lifted A p q a\"\n        hence emod_acc: \"electoral_module acc\"\n          using defer_lift_invariance_def\n          by metis\n        have \"defer_lift_invariance (acc \\<triangleright> m) \\<and> a \\<in> defer (acc \\<triangleright> m) A p\"\n          using a_in_defer_lch defer_lift_invariance_def dli_acc\n                f_prof loop_comp_helper_imp_no_def_incr monotone_m\n                rec_step_p seq_comp_presv_def_lift_inv subsetD\n          by (metis (no_types))\n        with emod_acc\n        show \"loop_comp_helper acc m t A p = loop_comp_helper acc m t A q\"\n          using a_in_defer_lch a_lifted card_smaller_for_p dli_acc\n                less.hyps n_card_acc rec_step_p rec_step_q\n          by (metis (full_types))\n      qed\n    next\n      assume \"\\<not> \\<not>t (acc A p)\"\n      with defer_lift_invariance_def\n      show ?thesis\n        using loop_comp_helper.simps(1)\n        by metis\n    qed\n  qed\nqed\n\nlemma loop_comp_helper_def_lift_inv:\n  assumes\n    monotone_m: \"defer_lift_invariance m\" and\n    monotone_acc: \"defer_lift_invariance acc\" and\n    profile: \"finite_profile A p\"\n  shows\n    \"\\<forall>q a. (lifted A p q a \\<and> a \\<in> (defer (loop_comp_helper acc m t) A p)) \\<longrightarrow>\n        (loop_comp_helper acc m t) A p = (loop_comp_helper acc m t) A q\"\n  using loop_comp_helper_def_lift_inv_helper\n        monotone_m monotone_acc profile\n  by blast\n\nlemma loop_comp_helper_def_lift_inv2:\n  assumes\n    monotone_m: \"defer_lift_invariance m\" and\n    monotone_acc: \"defer_lift_invariance acc\" and\n    finite_A_p: \"finite_profile A p\" and\n    lifted_A_pq: \"lifted A p q a\" and\n    a_in_defer_acc: \"a \\<in> defer (loop_comp_helper acc m t) A p\"\n  shows\n    \"(loop_comp_helper acc m t) A p = (loop_comp_helper acc m t) A q\"\n  using finite_A_p lifted_A_pq a_in_defer_acc\n        loop_comp_helper_def_lift_inv\n        monotone_acc monotone_m\n  by blast\n\nlemma lifted_imp_fin_prof:\n  assumes \"lifted A p q a\"\n  shows \"finite_profile A p\"\n  using assms Profile.lifted_def\n  by fastforce\n\nlemma loop_comp_helper_presv_def_lift_inv:\n  assumes\n    monotone_m: \"defer_lift_invariance m\" and\n    monotone_acc: \"defer_lift_invariance acc\"\n  shows \"defer_lift_invariance (loop_comp_helper acc m t)\"\nproof -\n  have\n    \"\\<forall>f. (defer_lift_invariance f \\<or>\n         (\\<exists>A prof prof2 (a::'a).\n            f A prof \\<noteq> f A prof2 \\<and>\n              Profile.lifted A prof prof2 a \\<and>\n              a \\<in> defer f A prof) \\<or>\n         \\<not> electoral_module f) \\<and>\n      ((\\<forall>A prof prof2 a. f A prof = f A prof2 \\<or>\n          \\<not> Profile.lifted A prof prof2 a \\<or>\n          a \\<notin> defer f A prof) \\<and>\n      electoral_module f \\<or> \\<not> defer_lift_invariance f)\"\n    using defer_lift_invariance_def\n    by blast\n  thus ?thesis\n    using electoral_module_def lifted_imp_fin_prof\n          loop_comp_helper_def_lift_inv loop_comp_helper_imp_partit\n          monotone_acc monotone_m\n    by (metis (full_types))\nqed\n\nlemma loop_comp_presv_non_electing_helper:\n  assumes\n    non_electing_m: \"non_electing m\" and\n    non_electing_acc: \"non_electing acc\" and\n    f_prof: \"finite_profile A p\" and\n    acc_defer_card: \"n = card (defer acc A p)\"\n  shows \"elect (loop_comp_helper acc m t) A p = {}\"\n  using acc_defer_card non_electing_acc\nproof (induct n arbitrary: acc rule: less_induct)\n  case (less n)\n  thus ?case\n  proof (safe)\n    fix x :: \"'a\"\n    assume\n      y_acc_no_elect:\n      \"(\\<And>y acc'. y < card (defer acc A p) \\<Longrightarrow>\n        y = card (defer acc' A p) \\<Longrightarrow> non_electing acc' \\<Longrightarrow>\n          elect (loop_comp_helper acc' m t) A p = {})\" and\n      acc_non_elect:\n      \"non_electing acc\" and\n      x_in_acc_elect:\n      \"x \\<in> elect (loop_comp_helper acc m t) A p\"\n    have\n      \"\\<forall>(f::'a set \\<Rightarrow> 'a Profile \\<Rightarrow> 'a Result) g.\n        (non_electing f \\<and> non_electing g) \\<longrightarrow>\n          non_electing (f \\<triangleright> g)\"\n      by simp\n    hence seq_acc_m_non_elect: \"non_electing (acc \\<triangleright> m)\"\n      using acc_non_elect non_electing_m\n      by blast\n    have \"\\<forall>A B. (finite (A::'a set) \\<and> B \\<subset> A) \\<longrightarrow> card B < card A\"\n      using psubset_card_mono\n      by metis\n    hence card_ineq:\n      \"\\<forall>A B. (finite (A::'a set) \\<and> B \\<subset> A) \\<longrightarrow> card B < card A\"\n      by presburger\n    have no_elect_acc: \"elect acc A p = {}\"\n      using acc_non_elect f_prof non_electing_def\n      by auto\n    have card_n_no_elect:\n      \"\\<forall>n f.\n        (n < card (defer acc A p) \\<and> n = card (defer f A p) \\<and> non_electing f) \\<longrightarrow>\n          elect (loop_comp_helper f m t) A p = {}\"\n      using y_acc_no_elect\n      by blast\n    have\n      \"\\<And>f.\n        (finite (defer acc A p) \\<and> defer f A p \\<subset> defer acc A p \\<and> non_electing f) \\<longrightarrow>\n          elect (loop_comp_helper f m t) A p = {}\"\n      using card_n_no_elect psubset_card_mono\n      by metis\n    hence f0:\n      \"(\\<not> t (acc A p) \\<and> defer (acc \\<triangleright> m) A p \\<subset> defer acc A p \\<and>\n            finite (defer acc A p)) \\<and>\n          \\<not> t (acc A p) \\<longrightarrow>\n        elect (loop_comp_helper acc m t) A p = {}\"\n      using loop_comp_code_helper seq_acc_m_non_elect\n      by (metis (no_types))\n    obtain set_func :: \"'a set \\<Rightarrow> 'a\" where\n      \"\\<forall>A. (A = {} \\<longrightarrow> (\\<forall>a. a \\<notin> A)) \\<and> (A \\<noteq> {} \\<longrightarrow> set_func A \\<in> A)\"\n      using all_not_in_conv\n      by (metis (no_types))\n    thus \"x \\<in> {}\"\n      using loop_comp_code_helper no_elect_acc x_in_acc_elect f0\n      by (metis (no_types))\n  qed\nqed\n\nlemma loop_comp_helper_iter_elim_def_n_helper:\n  assumes\n    non_electing_m: \"non_electing m\" and\n    single_elimination: \"eliminates 1 m\" and\n    terminate_if_n_left: \"\\<forall> r. ((t r) \\<longleftrightarrow> (card (defer_r r) = x))\" and\n    x_greater_zero: \"x > 0\" and\n    f_prof: \"finite_profile A p\" and\n    n_acc_defer_card: \"n = card (defer acc A p)\" and\n    n_ge_x: \"n \\<ge> x\" and\n    def_card_gt_one: \"card (defer acc A p) > 1\" and\n    acc_nonelect: \"non_electing acc\"\n  shows \"card (defer (loop_comp_helper acc m t) A p) = x\"\n  using n_ge_x def_card_gt_one acc_nonelect n_acc_defer_card\nproof (induct n arbitrary: acc rule: less_induct)\n  case (less n)\n  have subset:\n    \"(card (defer acc A p) > 1 \\<and> finite_profile A p \\<and> electoral_module acc) \\<longrightarrow>\n        defer (acc \\<triangleright> m) A p \\<subset> defer acc A p\"\n    using seq_comp_elim_one_red_def_set single_elimination\n    by blast\n  hence step_reduces_defer_set:\n    \"(card (defer acc A p) > 1 \\<and> finite_profile A p \\<and> non_electing acc) \\<longrightarrow>\n        defer (acc \\<triangleright> m) A p \\<subset> defer acc A p\"\n    using non_electing_def\n    by auto\n  thus ?case\n  proof cases\n    assume term_satisfied: \"t (acc A p)\"\n    have \"card (defer_r (loop_comp_helper acc m t A p)) = x\"\n      using loop_comp_helper.simps(1) term_satisfied terminate_if_n_left\n      by metis\n    thus ?case\n      by blast\n  next\n    assume term_not_satisfied: \"\\<not>(t (acc A p))\"\n    hence card_not_eq_x: \"card (defer acc A p) \\<noteq> x\"\n      by (simp add: terminate_if_n_left)\n    have rec_step:\n      \"(card (defer acc A p) > 1 \\<and> finite_profile A p \\<and> non_electing acc) \\<longrightarrow>\n          loop_comp_helper acc m t A p =\n              loop_comp_helper (acc \\<triangleright> m) m t A p\" (*needed for step*)\n      using loop_comp_helper.simps(2) non_electing_def def_presv_fin_prof\n            step_reduces_defer_set term_not_satisfied\n      by metis\n    thus ?case\n    proof cases\n      assume card_too_small:\n        \"card (defer acc A p) < x\"\n      thus ?thesis\n        using not_le card_too_small less.prems(1) less.prems(4) not_le\n        by (metis (no_types))\n    next\n      assume old_card_at_least_x: \"\\<not>(card (defer acc A p) < x)\"\n      obtain i where i_is_new_card: \"i = card (defer (acc \\<triangleright> m) A p)\"\n        by blast\n      with card_not_eq_x\n      have card_too_big:\n        \"card (defer acc A p) > x\"\n        using nat_neq_iff old_card_at_least_x\n        by blast\n      hence enough_leftover:\n        \"card (defer acc A p) > 1\"\n        using x_greater_zero\n        by auto\n      have \"electoral_module acc \\<longrightarrow> (defer acc A p) \\<subseteq> A\"\n        by (simp add: defer_in_alts f_prof)\n      hence step_profile:\n        \"electoral_module acc \\<longrightarrow>\n            finite_profile (defer acc A p)\n              (limit_profile (defer acc A p) p)\"\n        using f_prof limit_profile_sound\n        by auto\n      hence\n        \"electoral_module acc \\<longrightarrow>\n            card (defer m (defer acc A p)\n              (limit_profile (defer acc A p) p)) =\n                card (defer acc A p) - 1\"\n        using non_electing_m single_elimination\n              single_elim_decr_def_card2 enough_leftover\n        by blast\n      hence \"electoral_module acc \\<longrightarrow> i = card (defer acc A p) - 1\"\n        using sequential_composition.simps snd_conv i_is_new_card\n        by metis\n      hence \"electoral_module acc \\<longrightarrow> i \\<ge> x\"\n        using card_too_big\n        by linarith\n      hence new_card_still_big_enough: \"electoral_module acc \\<longrightarrow> x \\<le> i\"\n        by blast\n      have\n        \"electoral_module acc \\<and> electoral_module m \\<longrightarrow>\n            defer (acc \\<triangleright> m) A p \\<subseteq> defer acc A p\"\n        using enough_leftover f_prof subset\n        by blast\n      hence\n        \"electoral_module acc \\<and> electoral_module m \\<longrightarrow>\n            i \\<le> card (defer acc A p)\"\n        using card_mono i_is_new_card step_profile\n        by blast\n      hence i_geq_x:\n        \"electoral_module acc \\<and> electoral_module m \\<longrightarrow> (i = x \\<or> i > x)\"\n        using nat_less_le new_card_still_big_enough\n        by blast\n      thus ?thesis\n      proof cases\n        assume new_card_greater_x: \"electoral_module acc \\<longrightarrow> i > x\"\n        hence \"electoral_module acc \\<longrightarrow> 1 < card (defer (acc \\<triangleright> m) A p)\"\n          using x_greater_zero i_is_new_card\n          by linarith\n        moreover have new_card_still_big_enough2:\n          \"electoral_module acc \\<longrightarrow> x \\<le> i\" (* Needed for step *)\n          using i_is_new_card new_card_still_big_enough\n          by blast\n        moreover have\n          \"n = card (defer acc A p) \\<longrightarrow>\n              (electoral_module acc \\<longrightarrow> i < n)\" (* Needed for step *)\n          using subset step_profile enough_leftover f_prof psubset_card_mono\n                i_is_new_card\n          by blast\n        moreover have\n          \"electoral_module acc \\<longrightarrow>\n              electoral_module (acc \\<triangleright> m)\" (* Needed for step *)\n          using non_electing_def non_electing_m seq_comp_sound\n          by blast\n        moreover have non_electing_new:\n          \"non_electing acc \\<longrightarrow> non_electing (acc \\<triangleright> m)\"\n          by (simp add: non_electing_m)\n        ultimately have card_x:\n          \"(n = card (defer acc A p) \\<and> non_electing acc \\<and>\n              electoral_module acc) \\<longrightarrow>\n                  card (defer (loop_comp_helper (acc \\<triangleright> m) m t) A p) = x\"\n          using less.hyps i_is_new_card new_card_greater_x\n          by blast\n        have f1: \"loop_comp_helper acc m t A p = loop_comp_helper (acc \\<triangleright> m) m t A p\"\n          using enough_leftover f_prof less.prems(3) rec_step\n          by blast\n        have \"electoral_module acc\"\n          using less.prems(3) non_electing_def\n          by blast\n        thus ?thesis\n          using f1 card_x less.prems(3) less.prems(4)\n          by presburger\n      next\n        assume i_not_gt_x: \"\\<not>(electoral_module acc \\<longrightarrow> i > x)\"\n        hence \"electoral_module acc \\<and> electoral_module m \\<longrightarrow> i = x\"\n          using i_geq_x\n          by blast\n        hence \"electoral_module acc \\<and> electoral_module m \\<longrightarrow> t ((acc \\<triangleright> m) A p)\"\n          using i_is_new_card terminate_if_n_left\n          by blast\n        hence\n          \"electoral_module acc \\<and> electoral_module m \\<longrightarrow>\n              card (defer_r (loop_comp_helper (acc \\<triangleright> m) m t A p)) = x\"\n          using loop_comp_helper.simps(1) terminate_if_n_left\n          by metis\n        thus ?thesis\n          using i_not_gt_x dual_order.strict_iff_order i_is_new_card\n                loop_comp_helper.simps(1) new_card_still_big_enough\n                f_prof rec_step terminate_if_n_left\n                enough_leftover less.prems(3)\n          by metis\n      qed\n    qed\n  qed\nqed\n\nlemma loop_comp_helper_iter_elim_def_n:\n  assumes\n    non_electing_m: \"non_electing m\" and\n    single_elimination: \"eliminates 1 m\" and\n    terminate_if_n_left: \"\\<forall> r. ((t r) \\<longleftrightarrow> (card (defer_r r) = x))\" and\n    x_greater_zero: \"x > 0\" and\n    f_prof: \"finite_profile A p\" and\n    acc_defers_enough: \"card (defer acc A p) \\<ge> x\" and\n    non_electing_acc: \"non_electing acc\"\n  shows \"card (defer (loop_comp_helper acc m t) A p) = x\"\n  using acc_defers_enough gr_implies_not0 le_neq_implies_less\n        less_one linorder_neqE_nat loop_comp_helper.simps(1)\n        loop_comp_helper_iter_elim_def_n_helper non_electing_acc\n        non_electing_m f_prof single_elimination nat_neq_iff\n        terminate_if_n_left x_greater_zero less_le\n  by (metis (no_types, lifting))\n\nlemma iter_elim_def_n_helper:\n  assumes\n    non_electing_m: \"non_electing m\" and\n    single_elimination: \"eliminates 1 m\" and\n    terminate_if_n_left: \"\\<forall> r. ((t r) \\<longleftrightarrow> (card (defer_r r) = x))\" and\n    x_greater_zero: \"x > 0\" and\n    f_prof: \"finite_profile A p\" and\n    enough_alternatives: \"card A \\<ge> x\"\n  shows \"card (defer (m \\<circlearrowleft>\\<^sub>t) A p) = x\"\nproof cases\n  assume \"card A = x\"\n  thus ?thesis\n    by (simp add: terminate_if_n_left)\nnext\n  assume card_not_x: \"\\<not> card A = x\"\n  thus ?thesis\n  proof cases\n    assume \"card A < x\"\n    thus ?thesis\n      using enough_alternatives not_le\n      by blast\n  next\n    assume \"\\<not>card A < x\"\n    hence card_big_enough_A: \"card A > x\"\n      using card_not_x\n      by linarith\n    hence card_m: \"card (defer m A p) = card A - 1\"\n      using non_electing_m f_prof single_elimination\n            single_elim_decr_def_card2 x_greater_zero\n      by fastforce\n    hence card_big_enough_m: \"card (defer m A p) \\<ge> x\"\n      using card_big_enough_A\n      by linarith\n    hence \"(m \\<circlearrowleft>\\<^sub>t) A p = (loop_comp_helper m m t) A p\"\n      by (simp add: card_not_x terminate_if_n_left)\n    thus ?thesis\n      using card_big_enough_m non_electing_m f_prof single_elimination\n            terminate_if_n_left x_greater_zero\n            loop_comp_helper_iter_elim_def_n\n      by metis\n  qed\nqed\n\nsubsection \\<open>Composition Rules\\<close>\n\n(*The loop composition preserves defer-lift-invariance.*)\ntheorem loop_comp_presv_def_lift_inv[simp]:\n  assumes monotone_m: \"defer_lift_invariance m\"\n  shows \"defer_lift_invariance (m \\<circlearrowleft>\\<^sub>t)\"\n  unfolding defer_lift_invariance_def\nproof (safe)\n  from monotone_m\n  have \"electoral_module m\"\n    unfolding defer_lift_invariance_def\n    by simp\n  thus \"electoral_module (m \\<circlearrowleft>\\<^sub>t)\"\n    by (simp add: loop_comp_sound)\nnext\n  fix\n    A :: \"'a set\" and\n    p :: \"'a Profile\" and\n    q :: \"'a Profile\" and\n    a :: \"'a\"\n  assume\n    a_in_loop_defer: \"a \\<in> defer (m \\<circlearrowleft>\\<^sub>t) A p\" and\n    lifted_a: \"Profile.lifted A p q a\"\n  have defer_lift_loop:\n    \"\\<forall> p q a. (a \\<in> (defer (m \\<circlearrowleft>\\<^sub>t) A p) \\<and> lifted A p q a) \\<longrightarrow>\n        (m \\<circlearrowleft>\\<^sub>t) A p = (m \\<circlearrowleft>\\<^sub>t) A q\"\n    using monotone_m lifted_imp_fin_prof loop_comp_helper_def_lift_inv2\n          loop_composition.simps defer_module.simps\n    by (metis (full_types))\n  show \"(m \\<circlearrowleft>\\<^sub>t) A p = (m \\<circlearrowleft>\\<^sub>t) A q\"\n    using a_in_loop_defer lifted_a defer_lift_loop\n    by metis\nqed\n\n(*The loop composition preserves the property non-electing.*)\ntheorem loop_comp_presv_non_electing[simp]:\n  assumes non_electing_m: \"non_electing m\"\n  shows \"non_electing (m \\<circlearrowleft>\\<^sub>t)\"\n  unfolding non_electing_def\nproof (safe, simp_all)\n  show \"electoral_module (m \\<circlearrowleft>\\<^sub>t)\"\n    using loop_comp_sound non_electing_def non_electing_m\n    by metis\nnext\n    fix\n      A :: \"'a set\" and\n      p :: \"'a Profile\" and\n      x :: \"'a\"\n    assume\n      fin_A: \"finite A\" and\n      prof_A: \"profile A p\" and\n      x_elect: \"x \\<in> elect (m \\<circlearrowleft>\\<^sub>t) A p\"\n    show \"False\"\n  using def_mod_non_electing loop_comp_presv_non_electing_helper\n        non_electing_m empty_iff fin_A loop_comp_code\n        non_electing_def prof_A x_elect\n  by metis\nqed\n\ntheorem iter_elim_def_n[simp]:\n  assumes\n    non_electing_m: \"non_electing m\" and\n    single_elimination: \"eliminates 1 m\" and\n    terminate_if_n_left: \"\\<forall> r. ((t r) \\<longleftrightarrow> (card (defer_r r) = n))\" and\n    x_greater_zero: \"n > 0\"\n  shows \"defers n (m \\<circlearrowleft>\\<^sub>t)\"\nproof -\n  have\n    \"\\<forall> A p. finite_profile A p \\<and> card A \\<ge> n \\<longrightarrow>\n        card (defer (m \\<circlearrowleft>\\<^sub>t) A p) = n\"\n    using iter_elim_def_n_helper non_electing_m single_elimination\n          terminate_if_n_left x_greater_zero\n    by blast\n  moreover have \"electoral_module (m \\<circlearrowleft>\\<^sub>t)\"\n    using loop_comp_sound eliminates_def single_elimination\n    by blast\n  thus ?thesis\n    by (simp add: calculation defers_def)\nqed\n\nend\n", "meta": {"author": "ChrisMackKit", "repo": "ba-scoring-rule-reinforcement-homogeneity", "sha": "d87febd04743389ac578b332349ae446b9c55e89", "save_path": "github-repos/isabelle/ChrisMackKit-ba-scoring-rule-reinforcement-homogeneity", "path": "github-repos/isabelle/ChrisMackKit-ba-scoring-rule-reinforcement-homogeneity/ba-scoring-rule-reinforcement-homogeneity-d87febd04743389ac578b332349ae446b9c55e89/verifiedVotingRuleConstruction-master - Bevor Range/theories/Compositional_Structures/Loop_Composition.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.585101139733739, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.2720144392745758}}
{"text": "(*****************************************************************************\n * HOL-TestGen --- theorem-prover based test case generation\n *                 http://www.brucker.ch/projects/hol-testgen/\n *                                                                            \n * UPF\n * This file is part of HOL-TestGen.\n *\n * Copyright (c) 2005-2012 ETH Zurich, Switzerland\n *               2008-2015 Achim D. Brucker, Germany\n *               2009-2017 Université Paris-Sud, France\n *               2015-2017 The University of Sheffield, UK  \n *\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are\n * met:\n *\n *     * Redistributions of source code must retain the above copyright\n *       notice, this list of conditions and the following disclaimer.\n *\n *     * Redistributions in binary form must reproduce the above\n *       copyright notice, this list of conditions and the following\n *       disclaimer in the documentation and/or other materials provided\n *       with the distribution.\n *\n *     * Neither the name of the copyright holders nor the names of its\n *       contributors may be used to endorse or promote products derived\n *       from this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n ******************************************************************************)\n\nsection\\<open>The Core of the Unified Policy Framework (UPF)\\<close>\ntheory\n  UPFCore\n  imports \n    Monads\nbegin\n\n\nsubsection\\<open>Foundation\\<close>\ntext\\<open>\n  The purpose of this theory is to formalize a somewhat non-standard view\n  on the fundamental concept of a security policy which is worth outlining.\n  This view has arisen from prior experience in the modelling of network\n  (firewall) policies. Instead of regarding policies as relations on resources,\n  sets of permissions, etc., we emphasise the view that a policy is a policy\n  decision function that grants or denies access to resources, permissions, etc.\n  In other words, we model the concrete function that implements the policy\n  decision point in a system, and which represents a \"wrapper\" around the\n  business logic. An advantage of this view is that it is compatible\n  with many different policy models, enabling a uniform modelling framework to be\n  defined. Furthermore, this function is typically a large cascade of nested\n  conditionals, using conditions referring to an internal state and security\n  contexts of the system or a user. This cascade of conditionals can easily be\n  decomposed into a set of test cases similar to transformations used for binary\n  decision diagrams (BDD), and motivate equivalence class testing for unit test and \n  sequence test scenarios. From the modelling perspective, using \\HOL as\n  its input language, we will consequently use the expressive power of its\n  underlying functional  programming language, including the possibility to\n  define higher-order combinators.\n\n  In more detail, we model policies as partial functions based on input\n  data $\\alpha$ (arguments, system state, security context, ...) to output\n  data $\\beta$: \n\\<close>\n\ndatatype '\\<alpha> decision = allow '\\<alpha> | deny '\\<alpha>\n\ntype_synonym ('\\<alpha>,'\\<beta>) policy = \"'\\<alpha>  \\<rightharpoonup> '\\<beta> decision\" (infixr \"|->\" 0)\n\ntext\\<open>In the following, we introduce a number of shortcuts and alternative notations.\nThe type of policies is represented as:\\<close>\n\ntranslations (type)        \"'\\<alpha> |-> '\\<beta>\" <= (type) \"'\\<alpha>  \\<rightharpoonup> '\\<beta> decision\"\ntype_notation \"policy\" (infixr \"\\<mapsto>\" 0) \n\ntext\\<open>... allowing the notation @{typ \"'\\<alpha> \\<mapsto> '\\<beta>\"}  for the policy type and the\nalternative notations for @{term None} and @{term Some} of the \\HOL library \n@{typ \"'\\<alpha> option\"} type:\\<close>\n\nnotation    \"None\" (\"\\<bottom>\")\nnotation    \"Some\" (\"\\<lfloor>_\\<rfloor>\" 80)\n\ntext\\<open>Thus, the range of a policy may consist of @{term \"\\<lfloor>accept x\\<rfloor>\"} data,\n  of @{term \"\\<lfloor>deny x\\<rfloor>\"} data, as well as @{term \"\\<bottom>\"} modeling the undefinedness\n  of a policy, i.e. a policy is considered as a partial function. Partial \n  functions are used since we describe elementary policies by partial system \n  behaviour, which are glued together by operators such as function override and \n  functional composition. \n\\<close>\n\ntext\\<open>We define the two fundamental sets, the allow-set $Allow$ and the\n  deny-set $Deny$ (written $A$ and $D$ set for short), to characterize these\n  two main sets of the range of a policy. \n\\<close>\ndefinition Allow :: \"('\\<alpha> decision) set\"\nwhere     \"Allow = range allow\"\n\ndefinition Deny :: \"('\\<alpha> decision) set\"\nwhere     \"Deny = range deny\"\n \n\nsubsection\\<open>Policy Constructors\\<close>\ntext\\<open>\n  Most elementary policy constructors are based on the\n  update operation @{thm [source] \"Fun.fun_upd_def\"} @{thm Fun.fun_upd_def}\n  and the maplet-notation @{term \"a(x \\<mapsto> y)\"} used for @{term \"a(x:=\\<lfloor>y\\<rfloor>)\"}.\n\n  Furthermore, we add notation adopted to our problem domain:\\<close>\n\nnonterminal policylets and policylet\n\nsyntax\n  \"_policylet1\"  :: \"['a, 'a] => policylet\"                 (\"_ /\\<mapsto>\\<^sub>+/ _\")\n  \"_policylet2\"  :: \"['a, 'a] => policylet\"                 (\"_ /\\<mapsto>\\<^sub>-/ _\")\n  \"\"             :: \"policylet => policylets\"               (\"_\")\n  \"_Maplets\"     :: \"[policylet, policylets] => policylets\" (\"_,/ _\")\n  \"_Maplets\"     :: \"[policylet, policylets] => policylets\" (\"_,/ _\")\n   \"_MapUpd\"      :: \"['a |-> 'b, policylets] => 'a |-> 'b\"  (\"_/'(_')\" [900,0]900)\n  \"_emptypolicy\" :: \"'a |-> 'b\"                             (\"\\<emptyset>\")\n\ntranslations\n  \"_MapUpd m (_Maplets xy ms)\"   \\<rightleftharpoons> \"_MapUpd (_MapUpd m xy) ms\"\n  \"_MapUpd m (_policylet1 x y)\"  \\<rightleftharpoons> \"m(x := CONST Some (CONST allow y))\"\n  \"_MapUpd m (_policylet2 x y)\"  \\<rightleftharpoons> \"m(x := CONST Some (CONST deny y))\"\n  \"\\<emptyset>\"                            \\<rightleftharpoons> \"CONST Map.empty\" \n\ntext\\<open>Here are some lemmas essentially showing syntactic equivalences:\\<close>\nlemma test: \"\\<emptyset>(x\\<mapsto>\\<^sub>+a, y\\<mapsto>\\<^sub>-b) = \\<emptyset>(x \\<mapsto>\\<^sub>+ a, y \\<mapsto>\\<^sub>- b)\"   by simp\n\nlemma test2: \"p(x\\<mapsto>\\<^sub>+a,x\\<mapsto>\\<^sub>-b) = p(x\\<mapsto>\\<^sub>-b)\"   by simp\n\ntext\\<open>\n  We inherit a fairly rich theory on policy updates from Map here. Some examples are: \n\\<close>\n\nlemma pol_upd_triv1: \"t k =   \\<lfloor>allow x\\<rfloor> \\<Longrightarrow> t(k\\<mapsto>\\<^sub>+x) = t\"\n  by (rule ext) simp\n\nlemma pol_upd_triv2: \"t k = \\<lfloor>deny x\\<rfloor> \\<Longrightarrow> t(k\\<mapsto>\\<^sub>-x) = t\"\n  by (rule ext) simp\n\nlemma pol_upd_allow_nonempty: \"t(k\\<mapsto>\\<^sub>+x) \\<noteq> \\<emptyset>\" \n  by simp\n\nlemma pol_upd_deny_nonempty: \"t(k\\<mapsto>\\<^sub>-x) \\<noteq> \\<emptyset>\" \n  by simp\n\nlemma pol_upd_eqD1 : \"m(a\\<mapsto>\\<^sub>+x) = n(a\\<mapsto>\\<^sub>+y) \\<Longrightarrow> x = y\"\n  by(auto dest: map_upd_eqD1)\n\nlemma pol_upd_eqD2 : \"m(a\\<mapsto>\\<^sub>-x) = n(a\\<mapsto>\\<^sub>-y) \\<Longrightarrow> x = y\"\n  by(auto dest: map_upd_eqD1)\n\nlemma pol_upd_neq1 [simp]: \"m(a\\<mapsto>\\<^sub>+x) \\<noteq> n(a\\<mapsto>\\<^sub>-y)\"\n  by(auto dest: map_upd_eqD1)\n\n\nsubsection\\<open>Override Operators\\<close>\ntext\\<open>\n  Key operators for constructing policies are the override operators. There are four different \n  versions of them, with one of them being the override operator from the Map theory. As it is \n  common to compose policy rules in a ``left-to-right-first-fit''-manner, that one is taken as \n  default, defined by a syntax translation from the provided override operator from the Map \n  theory (which does it in reverse order).\n\\<close>\n\nsyntax\n  \"_policyoverride\"  :: \"['a \\<mapsto> 'b, 'a \\<mapsto> 'b] \\<Rightarrow> 'a \\<mapsto> 'b\" (infixl \"\\<Oplus>\" 100)\ntranslations\n  \"p \\<Oplus> q\" \\<rightleftharpoons> \"q ++ p\" \n\n\ntext\\<open>\n  Some elementary facts inherited from Map are:\n\\<close>\n\nlemma override_empty: \"p \\<Oplus> \\<emptyset> = p\" \n  by simp\n\nlemma empty_override: \"\\<emptyset> \\<Oplus> p = p\" \n  by simp\n\nlemma override_assoc: \"p1 \\<Oplus> (p2 \\<Oplus> p3) = (p1 \\<Oplus> p2) \\<Oplus> p3\" \n  by simp\n\ntext\\<open>\n  The following two operators are variants of the standard override.  For override\\_A, \n  an allow of wins over a deny. For override\\_D, the situation is dual. \n\\<close>\n\ndefinition override_A :: \"['\\<alpha>\\<mapsto>'\\<beta>, '\\<alpha>\\<mapsto>'\\<beta>] \\<Rightarrow> '\\<alpha>\\<mapsto>'\\<beta>\" (infixl \"++'_A\" 100) \nwhere  \"m2 ++_A m1 = \n          (\\<lambda>x. (case m1 x of \n                 \\<lfloor>allow a\\<rfloor> \\<Rightarrow>  \\<lfloor>allow a\\<rfloor>\n               | \\<lfloor>deny a\\<rfloor>  \\<Rightarrow> (case m2 x of \\<lfloor>allow b\\<rfloor> \\<Rightarrow> \\<lfloor>allow b\\<rfloor> \n                                            | _ \\<Rightarrow> \\<lfloor>deny a\\<rfloor>)\n               | \\<bottom> \\<Rightarrow> m2 x)\n           )\"\n\nsyntax\n  \"_policyoverride_A\"  :: \"['a \\<mapsto> 'b, 'a \\<mapsto> 'b] \\<Rightarrow> 'a \\<mapsto> 'b\" (infixl \"\\<Oplus>\\<^sub>A\" 100)\ntranslations\n  \"p \\<Oplus>\\<^sub>A q\" \\<rightleftharpoons> \"p ++_A q\"\n\nlemma override_A_empty[simp]: \"p \\<Oplus>\\<^sub>A \\<emptyset> = p\" \n  by(simp add:override_A_def)\n\nlemma empty_override_A[simp]: \"\\<emptyset> \\<Oplus>\\<^sub>A p = p\" \n  apply (rule ext)\n  apply (simp add:override_A_def)\n  subgoal for x \n    apply (case_tac \"p x\")\n     apply (simp_all)\n    subgoal for a\n      apply (case_tac a)\n       apply (simp_all)\n      done\n    done \n  done \n\n\nlemma override_A_assoc: \"p1 \\<Oplus>\\<^sub>A (p2 \\<Oplus>\\<^sub>A p3) = (p1 \\<Oplus>\\<^sub>A p2) \\<Oplus>\\<^sub>A p3\" \n  by (rule ext, simp add: override_A_def split: decision.splits  option.splits)\n\ndefinition override_D :: \"['\\<alpha>\\<mapsto>'\\<beta>, '\\<alpha>\\<mapsto>'\\<beta>] \\<Rightarrow> '\\<alpha>\\<mapsto>'\\<beta>\" (infixl \"++'_D\" 100) \nwhere \"m1 ++_D m2 = \n          (\\<lambda>x. case m2 x of \n                \\<lfloor>deny a\\<rfloor> \\<Rightarrow> \\<lfloor>deny a\\<rfloor>\n              | \\<lfloor>allow a\\<rfloor> \\<Rightarrow> (case m1 x of \\<lfloor>deny b\\<rfloor> \\<Rightarrow> \\<lfloor>deny b\\<rfloor>\n                                  | _ \\<Rightarrow> \\<lfloor>allow a\\<rfloor>)\n              | \\<bottom> \\<Rightarrow> m1 x \n           )\"\n \nsyntax\n  \"_policyoverride_D\"  :: \"['a \\<mapsto> 'b, 'a \\<mapsto> 'b] \\<Rightarrow> 'a \\<mapsto> 'b\" (infixl \"\\<Oplus>\\<^sub>D\" 100)\ntranslations\n  \"p \\<Oplus>\\<^sub>D q\" \\<rightleftharpoons> \"p ++_D q\"\n\nlemma override_D_empty[simp]: \"p \\<Oplus>\\<^sub>D \\<emptyset> = p\" \n  by(simp add:override_D_def)\n\nlemma empty_override_D[simp]: \"\\<emptyset> \\<Oplus>\\<^sub>D p = p\" \n  apply (rule ext)\n  apply (simp add:override_D_def)\n  subgoal for x \n    apply (case_tac \"p x\", simp_all)\n    subgoal for a\n      apply (case_tac a, simp_all)\n      done\n    done\n  done\n\nlemma override_D_assoc: \"p1 \\<Oplus>\\<^sub>D (p2 \\<Oplus>\\<^sub>D p3) = (p1 \\<Oplus>\\<^sub>D p2) \\<Oplus>\\<^sub>D p3\"\n  apply (rule ext)\n  apply (simp add: override_D_def split: decision.splits  option.splits)\ndone\n\nsubsection\\<open>Coercion Operators\\<close>\ntext\\<open>\n  Often, especially when combining policies of different type, it is necessary to \n  adapt the input or output domain of a policy to a more refined context. \n\\<close>                        \n\ntext\\<open>\n  An analogous for the range of a policy is defined as follows: \n\\<close>\n\ndefinition policy_range_comp :: \"['\\<beta>\\<Rightarrow>'\\<gamma>, '\\<alpha>\\<mapsto>'\\<beta>] \\<Rightarrow> '\\<alpha> \\<mapsto>'\\<gamma>\"   (infixl \"o'_f\" 55) \nwhere\n  \"f o_f p = (\\<lambda>x. case p x of\n                     \\<lfloor>allow y\\<rfloor> \\<Rightarrow> \\<lfloor>allow (f y)\\<rfloor>\n                   | \\<lfloor>deny y\\<rfloor> \\<Rightarrow> \\<lfloor>deny (f y)\\<rfloor>\n                   | \\<bottom> \\<Rightarrow> \\<bottom>)\"\n\nsyntax\n  \"_policy_range_comp\" :: \"['\\<beta>\\<Rightarrow>'\\<gamma>, '\\<alpha>\\<mapsto>'\\<beta>] \\<Rightarrow> '\\<alpha> \\<mapsto>'\\<gamma>\" (infixl \"o\\<^sub>f\" 55)\ntranslations\n  \"p o\\<^sub>f q\" \\<rightleftharpoons> \"p o_f q\"\n\nlemma policy_range_comp_strict : \"f o\\<^sub>f \\<emptyset> = \\<emptyset>\"\n  apply (rule ext)\n  apply (simp add: policy_range_comp_def)\n  done\n\n\ntext\\<open>\n  A generalized version is, where separate coercion functions are applied to the result \n  depending on the decision of the policy is as follows: \n\\<close>\n\ndefinition range_split :: \"[('\\<beta>\\<Rightarrow>'\\<gamma>)\\<times>('\\<beta>\\<Rightarrow>'\\<gamma>),'\\<alpha> \\<mapsto> '\\<beta>] \\<Rightarrow> '\\<alpha> \\<mapsto> '\\<gamma>\"\n                          (infixr \"\\<nabla>\" 100)\nwhere \"(P) \\<nabla> p = (\\<lambda>x. case p x of \n                          \\<lfloor>allow y\\<rfloor> \\<Rightarrow> \\<lfloor>allow ((fst P) y)\\<rfloor>\n                        | \\<lfloor>deny y\\<rfloor>  \\<Rightarrow> \\<lfloor>deny ((snd P) y)\\<rfloor> \n                        | \\<bottom>        \\<Rightarrow> \\<bottom>)\"\n\nlemma range_split_strict[simp]: \"P \\<nabla> \\<emptyset> = \\<emptyset>\"\n  apply (rule ext)\n  apply (simp add: range_split_def)\n  done\n\n\nlemma range_split_charn:\n  \"(f,g) \\<nabla> p = (\\<lambda>x. case p x of \n                           \\<lfloor>allow x\\<rfloor> \\<Rightarrow> \\<lfloor>allow (f x)\\<rfloor>\n                         | \\<lfloor>deny x\\<rfloor>  \\<Rightarrow> \\<lfloor>deny (g x)\\<rfloor> \n                         | \\<bottom>        \\<Rightarrow> \\<bottom>)\"\n  apply (simp add: range_split_def)\n  apply (rule ext)\n  subgoal for x \n    apply (case_tac \"p x\")\n     apply (simp_all)\n    subgoal for a\n      apply (case_tac \"a\")\n       apply (simp_all)\n      done\n    done\n  done\n\ntext\\<open>\n  The connection between these two becomes apparent if considering the following lemma:\n\\<close>\n\nlemma range_split_vs_range_compose: \"(f,f) \\<nabla> p = f o\\<^sub>f p\"\n  by(simp add: range_split_charn policy_range_comp_def)\n    \nlemma range_split_id [simp]: \"(id,id) \\<nabla> p = p\"\n  apply (rule ext)\n  apply (simp add: range_split_charn id_def)\n  subgoal for x\n    apply (case_tac \"p x\")\n     apply (simp_all)\n    subgoal for a\n      apply (case_tac \"a\")\n       apply (simp_all)\n      done\n    done \n  done \n\nlemma range_split_bi_compose [simp]: \"(f1,f2) \\<nabla> (g1,g2) \\<nabla> p = (f1 o g1,f2 o g2) \\<nabla> p\"\n  apply (rule ext)\n  apply (simp add: range_split_charn comp_def)\n  subgoal for x \n    apply (case_tac \"p x\")\n     apply (simp_all)\n    subgoal for a\n      apply (case_tac \"a\")\n       apply (simp_all)\n      done\n    done\n  done\n\ntext\\<open>\n  The next three operators are rather exotic and in most cases not used. \n\\<close>\n\ntext \\<open>\n  The following is a variant of range\\_split, where the change in the decision depends \n  on the input instead of the output. \n\\<close>\n\ndefinition dom_split2a :: \"[('\\<alpha> \\<rightharpoonup> '\\<gamma>) \\<times> ('\\<alpha> \\<rightharpoonup>'\\<gamma>),'\\<alpha> \\<mapsto> '\\<beta>] \\<Rightarrow> '\\<alpha> \\<mapsto> '\\<gamma>\"         (infixr \"\\<Delta>a\" 100)\nwhere \"P \\<Delta>a p = (\\<lambda>x. case p x of \n                          \\<lfloor>allow y\\<rfloor> \\<Rightarrow> \\<lfloor>allow (the ((fst P) x))\\<rfloor>\n                        | \\<lfloor>deny y\\<rfloor>  \\<Rightarrow>  \\<lfloor>deny (the ((snd P) x))\\<rfloor> \n                        | \\<bottom>        \\<Rightarrow> \\<bottom>)\"\n\ndefinition dom_split2 :: \"[('\\<alpha> \\<Rightarrow> '\\<gamma>) \\<times> ('\\<alpha> \\<Rightarrow>'\\<gamma>),'\\<alpha> \\<mapsto> '\\<beta>] \\<Rightarrow> '\\<alpha> \\<mapsto> '\\<gamma>\"          (infixr \"\\<Delta>\" 100)\nwhere \"P \\<Delta> p = (\\<lambda>x. case p x of \n                          \\<lfloor>allow y\\<rfloor> \\<Rightarrow> \\<lfloor>allow ((fst P) x)\\<rfloor>\n                        | \\<lfloor>deny y\\<rfloor>  \\<Rightarrow>  \\<lfloor>deny ((snd P) x)\\<rfloor>\n                        | \\<bottom>        \\<Rightarrow> \\<bottom>)\"\n\ndefinition range_split2 :: \"[('\\<alpha> \\<Rightarrow> '\\<gamma>) \\<times> ('\\<alpha> \\<Rightarrow>'\\<gamma>),'\\<alpha> \\<mapsto> '\\<beta>] \\<Rightarrow> '\\<alpha> \\<mapsto> ('\\<beta> \\<times>'\\<gamma>)\" (infixr \"\\<nabla>2\" 100)\nwhere \"P \\<nabla>2 p = (\\<lambda>x. case p x of \n                          \\<lfloor>allow y\\<rfloor> \\<Rightarrow> \\<lfloor>allow (y,(fst P) x)\\<rfloor>\n                        | \\<lfloor>deny y\\<rfloor>  \\<Rightarrow> \\<lfloor>deny (y,(snd P) x)\\<rfloor> \n                        | \\<bottom>        \\<Rightarrow> \\<bottom>)\"\n\ntext\\<open>\n  The following operator is used for transition policies only: a transition policy is transformed \n  into a state-exception monad. Such a monad can for example be used for test case generation using \n  HOL-Testgen~\\cite{brucker.ea:theorem-prover:2012}.\n\\<close>\n\ndefinition policy2MON :: \"('\\<iota>\\<times>'\\<sigma> \\<mapsto> 'o\\<times>'\\<sigma>) \\<Rightarrow> ('\\<iota> \\<Rightarrow>('o decision,'\\<sigma>) MON\\<^sub>S\\<^sub>E)\"\nwhere \"policy2MON p = (\\<lambda> \\<iota> \\<sigma>. case p (\\<iota>,\\<sigma>) of\n                              \\<lfloor>(allow (outs,\\<sigma>'))\\<rfloor> \\<Rightarrow> \\<lfloor>(allow outs, \\<sigma>')\\<rfloor>\n                            | \\<lfloor>(deny (outs,\\<sigma>'))\\<rfloor>  \\<Rightarrow> \\<lfloor>(deny outs, \\<sigma>')\\<rfloor>\n                            | \\<bottom>                  \\<Rightarrow> \\<bottom>)\"\n\nlemmas UPFCoreDefs = Allow_def Deny_def override_A_def override_D_def policy_range_comp_def \n                     range_split_def dom_split2_def map_add_def restrict_map_def\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/UPF/UPFCore.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185351961015, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.2719598375416356}}
{"text": "section {* UTP variables *}\n\ntheory utp_urel_setup\n  imports utp_lift utp_tactics\nbegin\n(*tactics are in utp_tactics*)\nconsts\n  useq   :: \"'a \\<Rightarrow> 'b \\<Rightarrow> 'c\" (infixr \";;\" 51)\n  uskip  :: \"'a\" (\"II\")\n\ndefinition in\\<alpha> :: \"('\\<alpha>, '\\<alpha> \\<times> '\\<beta>) uvar\" where\n\"in\\<alpha> = \\<lparr> lens_get = fst, lens_put = \\<lambda> (A, A') v. (v, A') \\<rparr>\"\n\ndefinition out\\<alpha> :: \"('\\<beta>, '\\<alpha> \\<times> '\\<beta>) uvar\" where\n\"out\\<alpha> = \\<lparr> lens_get = snd, lens_put = \\<lambda> (A, A') v. (A, v) \\<rparr>\"\n\ndeclare in\\<alpha>_def [urel_defs]\ndeclare out\\<alpha>_def [urel_defs]\n\nlemma var_in_alpha [simp]: \"x ;\\<^sub>L in\\<alpha> = ivar x\"\n  by (simp add: fst_lens_def in\\<alpha>_def in_var_def)\n\nlemma var_out_alpha [simp]: \"x ;\\<^sub>L out\\<alpha> = ovar x\"\n  by (simp add: out\\<alpha>_def out_var_def snd_lens_def)\n\nlemma out_alpha_in_indep [simp]:\n  \"out\\<alpha> \\<bowtie> in_var x\" \"in_var x \\<bowtie> out\\<alpha>\"\n  by (simp_all add: in_var_def out\\<alpha>_def lens_indep_def fst_lens_def lens_comp_def)\n\nlemma in_alpha_out_indep [simp]:\n  \"in\\<alpha> \\<bowtie> out_var x\" \"out_var x \\<bowtie> in\\<alpha>\"\n  by (simp_all add: in_var_def in\\<alpha>_def lens_indep_def fst_lens_def lens_comp_def)\n\ntext {* The alphabet of a relation consists of the input and output portions *}\n\nlemma alpha_in_out:\n  \"\\<Sigma> \\<approx>\\<^sub>L in\\<alpha> +\\<^sub>L out\\<alpha>\"\n  by (metis fst_lens_def fst_snd_id_lens in\\<alpha>_def lens_equiv_refl out\\<alpha>_def snd_lens_def)\n\nabbreviation usubst_rel_lift :: \"'\\<alpha> usubst \\<Rightarrow> ('\\<alpha> \\<times> '\\<beta>) usubst\" (\"\\<lceil>_\\<rceil>\\<^sub>s\") where\n\"\\<lceil>\\<sigma>\\<rceil>\\<^sub>s \\<equiv> \\<sigma> \\<oplus>\\<^sub>s in\\<alpha>\"\n\nabbreviation usubst_rel_drop :: \"('\\<alpha> \\<times> '\\<alpha>) usubst \\<Rightarrow> '\\<alpha> usubst\" (\"\\<lfloor>_\\<rfloor>\\<^sub>s\") where\n\"\\<lfloor>\\<sigma>\\<rfloor>\\<^sub>s \\<equiv> \\<sigma> \\<restriction>\\<^sub>s in\\<alpha>\"\n\n\nend\n", "meta": {"author": "git-vt", "repo": "orca", "sha": "92bda0f9cfe5cc680b9c405fc38f07a960087a36", "save_path": "github-repos/isabelle/git-vt-orca", "path": "github-repos/isabelle/git-vt-orca/orca-92bda0f9cfe5cc680b9c405fc38f07a960087a36/Archive/Programming-Languages-Semantics/WP11-C-semantics/src/IMP-Lenses/utp/utp_urel_setup.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185205547239, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.2719598305067658}}
{"text": "section \\<open>Compositional Reasoning\\<close>\n\n(*<*)\ntheory Compositional_Reasoning\nimports BD_Security\nbegin\n(*>*)\n\n\ncontext BD_Security begin\n\n\nsubsection\\<open>Preliminaries\\<close>\n\ndefinition \"disjAll \\<Delta>s s vl s1 vl1 \\<equiv> (\\<exists>\\<Delta> \\<in> \\<Delta>s. \\<Delta> s vl s1 vl1)\"\n\nlemma disjAll_simps[simp]:\n  \"disjAll {} \\<equiv> \\<lambda>_ _ _ _. False\"\n  \"disjAll (insert \\<Delta> \\<Delta>s) \\<equiv> \\<lambda>s vl s1 vl1. \\<Delta> s vl s1 vl1 \\<or> disjAll \\<Delta>s s vl s1 vl1\"\n  unfolding disjAll_def[abs_def] by auto\n\n\nlemma iaction_mono:\nassumes 1: \"iaction \\<Delta> s vl s1 vl1\" and 2: \"\\<And> s vl s1 vl1. \\<Delta> s vl s1 vl1 \\<Longrightarrow> \\<Delta>' s vl s1 vl1\"\nshows \"iaction \\<Delta>' s vl s1 vl1\"\nproof-\n  obtain a1 ou1 s1' vl1'\n  where \"step s1 a1 = (ou1, s1')\" and \"\\<phi> (Trans s1 a1 ou1 s1')\"\n  and \"consume (Trans s1 a1 ou1 s1') vl1 vl1'\" and \"\\<not> \\<gamma> (Trans s1 a1 ou1 s1')\"\n  and \"\\<Delta> s vl s1' vl1'\" using 1 unfolding iaction_def by auto\n  thus ?thesis unfolding iaction_def using 2 apply -\n  by (rule exI[of _ a1], rule exI[of _ ou1], rule exI[of _ s1'], rule exI[of _ vl1']) auto\nqed\n\nlemma match_mono:\nassumes 1: \"match \\<Delta> s s1 vl1 a ou s' vl'\" and 2: \"\\<And> s vl s1 vl1. \\<Delta> s vl s1 vl1 \\<Longrightarrow> \\<Delta>' s vl s1 vl1\"\nshows \"match \\<Delta>' s s1 vl1 a ou s' vl'\"\nproof-\n  obtain a1 ou1 s1' vl1'\n  where \"\\<Delta> s' vl' s1' vl1'\"\n  and \"step s1 a1 = (ou1, s1')\"\n  and \"consume (Trans s1 a1 ou1 s1') vl1 vl1'\"\n  and \"\\<gamma> (Trans s a ou s') = \\<gamma> (Trans s1 a1 ou1 s1')\"\n  and \"(\\<gamma> (Trans s a ou s') \\<longrightarrow> g (Trans s a ou s') = g (Trans s1 a1 ou1 s1'))\"\n  using 1 unfolding match_def by auto\n  thus ?thesis unfolding match_def using 2 apply -\n  by (rule exI[of _ a1], rule exI[of _ ou1], rule exI[of _ s1'], rule exI[of _ vl1']) auto\nqed\n\nlemma ignore_mono:\nassumes 1: \"ignore \\<Delta> s s1 vl1 a ou s' vl'\" and 2: \"\\<And> s vl s1 vl1. \\<Delta> s vl s1 vl1 \\<Longrightarrow> \\<Delta>' s vl s1 vl1\"\nshows \"ignore \\<Delta>' s s1 vl1 a ou s' vl'\"\nusing assms unfolding ignore_def by auto\n\nlemma reaction_mono:\nassumes 1: \"reaction \\<Delta> s vl s1 vl1\" and 2: \"\\<And> s vl s1 vl1. \\<Delta> s vl s1 vl1 \\<Longrightarrow> \\<Delta>' s vl s1 vl1\"\nshows \"reaction \\<Delta>' s vl s1 vl1\"\nproof\n  fix a ou s' vl'\n  assume \"step s a = (ou, s')\" and \"\\<not> T (Trans s a ou s')\" and \"consume (Trans s a ou s') vl vl'\"\n  hence \"match \\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore \\<Delta> s s1 vl1 a ou s' vl'\" (is \"?m \\<or> ?i\")\n  using 1 unfolding reaction_def by auto\n  thus \"match \\<Delta>' s s1 vl1 a ou s' vl' \\<or> ignore \\<Delta>' s s1 vl1 a ou s' vl'\" (is \"?m' \\<or> ?i'\")\n  proof\n    assume ?m from match_mono[OF this 2] show ?thesis by simp\n  next\n    assume ?i from ignore_mono[OF this 2] show ?thesis by simp\n  qed\nqed\n\n\nsubsection\\<open>Decomposition into an arbitrary network of components\\<close>\n\n(* Unwind not to itself, but to a disjunction of other relations: *)\ndefinition unwind_to where\n\"unwind_to \\<Delta> \\<Delta>s \\<equiv>\n \\<forall> s vl s1 vl1.\n   reachNT s \\<and> reach s1 \\<and> \\<Delta> s vl s1 vl1\n   \\<longrightarrow>\n   vl \\<noteq> [] \\<and> exit s (hd vl)\n   \\<or>\n   iaction (disjAll \\<Delta>s) s vl s1 vl1\n   \\<or>\n   (vl \\<noteq> [] \\<or> vl1 = []) \\<and> reaction (disjAll \\<Delta>s) s vl s1 vl1\"\n\nlemma unwind_toI[intro?]:\nassumes\n\"\\<And> s vl s1 vl1.\n   \\<lbrakk>reachNT s; reach s1; \\<Delta> s vl s1 vl1\\<rbrakk>\n   \\<Longrightarrow>\n   vl \\<noteq> [] \\<and> exit s (hd vl)\n   \\<or>\n   iaction (disjAll \\<Delta>s) s vl s1 vl1\n   \\<or>\n   (vl \\<noteq> [] \\<or> vl1 = []) \\<and> reaction (disjAll \\<Delta>s) s vl s1 vl1\"\nshows \"unwind_to \\<Delta> \\<Delta>s\"\nusing assms unfolding unwind_to_def by auto\n\n(* Decomposition: *)\nlemma unwind_dec:\nassumes ne: \"\\<And> \\<Delta>. \\<Delta> \\<in> \\<Delta>s \\<Longrightarrow> next \\<Delta> \\<subseteq> \\<Delta>s \\<and> unwind_to \\<Delta> (next \\<Delta>)\"\nshows \"unwind (disjAll \\<Delta>s)\" (is \"unwind ?\\<Delta>\")\nproof\n  fix s s1 :: 'state and vl vl1 :: \"'value list\"\n  assume r: \"reachNT s\" \"reach s1\" and \\<Delta>: \"?\\<Delta> s vl s1 vl1\"\n  then obtain \\<Delta> where \\<Delta>: \"\\<Delta> \\<in> \\<Delta>s\" and 2: \"\\<Delta> s vl s1 vl1\" unfolding disjAll_def by auto\n  let ?\\<Delta>s' = \"next \\<Delta>\"  let ?\\<Delta>' = \"disjAll ?\\<Delta>s'\"\n  have \"(vl \\<noteq> [] \\<and> exit s (hd vl)) \\<or>\n        iaction ?\\<Delta>' s vl s1 vl1 \\<or>\n        ((vl \\<noteq> [] \\<or> vl1 = []) \\<and> reaction ?\\<Delta>' s vl s1 vl1)\"\n  using 2 \\<Delta> ne r unfolding unwind_to_def by auto\n  moreover have \"\\<And> s vl s1 vl1. ?\\<Delta>' s vl s1 vl1 \\<Longrightarrow> ?\\<Delta> s vl s1 vl1\"\n  using ne[OF \\<Delta>] unfolding disjAll_def by auto\n  ultimately show\n       \"(vl \\<noteq> [] \\<and> exit s (hd vl)) \\<or>\n        iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl \\<noteq> [] \\<or> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\"\n  using iaction_mono[of ?\\<Delta>' _ _ _ _ ?\\<Delta>] reaction_mono[of ?\\<Delta>' _ _ _ _ ?\\<Delta>] by blast\nqed\n\nlemma init_dec:\nassumes \\<Delta>0: \"\\<Delta>0 \\<in> \\<Delta>s\"\nand i: \"\\<And> vl vl1. B vl vl1 \\<Longrightarrow> \\<Delta>0 istate vl istate vl1\"\nshows \"\\<forall> vl vl1. B vl vl1 \\<longrightarrow> disjAll \\<Delta>s istate vl istate vl1\"\nusing assms unfolding disjAll_def by auto\n\ntheorem unwind_dec_secure:\nassumes \\<Delta>0: \"\\<Delta>0 \\<in> \\<Delta>s\"\nand i: \"\\<And> vl vl1. B vl vl1 \\<Longrightarrow> \\<Delta>0 istate vl istate vl1\"\nand ne: \"\\<And> \\<Delta>. \\<Delta> \\<in> \\<Delta>s \\<Longrightarrow> next \\<Delta> \\<subseteq> \\<Delta>s \\<and> unwind_to \\<Delta> (next \\<Delta>)\"\nshows secure\nusing init_dec[OF \\<Delta>0 i] unwind_dec[OF ne] unwind_secure by metis\n\n\nsubsection\\<open>A customization for linear modular reasoning\\<close>\n\n(* The customization assumes that each component unwinds only into itself,\nits successor or an exit component.  *)\n\ndefinition unwind_cont where\n\"unwind_cont \\<Delta> \\<Delta>s \\<equiv>\n \\<forall> s vl s1 vl1.\n   reachNT s \\<and> reach s1 \\<and> \\<Delta> s vl s1 vl1\n   \\<longrightarrow>\n   iaction (disjAll \\<Delta>s) s vl s1 vl1\n   \\<or>\n   ((vl \\<noteq> [] \\<or> vl1 = []) \\<and> reaction (disjAll \\<Delta>s) s vl s1 vl1)\"\n\nlemma unwind_contI[intro?]:\nassumes\n\"\\<And> s vl s1 vl1.\n   \\<lbrakk>reachNT s; reach s1; \\<Delta> s vl s1 vl1\\<rbrakk>\n   \\<Longrightarrow>\n   iaction (disjAll \\<Delta>s) s vl s1 vl1\n   \\<or>\n   ((vl \\<noteq> [] \\<or> vl1 = []) \\<and> reaction (disjAll \\<Delta>s) s vl s1 vl1)\"\nshows \"unwind_cont \\<Delta> \\<Delta>s\"\nusing assms unfolding unwind_cont_def by auto\n\ndefinition unwind_exit where\n\"unwind_exit \\<Delta>e \\<equiv>\n \\<forall> s vl s1 vl1.\n   reachNT s \\<and> reach s1 \\<and> \\<Delta>e s vl s1 vl1\n   \\<longrightarrow>\n   vl \\<noteq> [] \\<and> exit s (hd vl)\"\n\nlemma unwind_exitI[intro?]:\nassumes\n\"\\<And> s vl s1 vl1.\n   \\<lbrakk>reachNT s; reach s1; \\<Delta>e s vl s1 vl1\\<rbrakk>\n   \\<Longrightarrow>\n   vl \\<noteq> [] \\<and> exit s (hd vl)\"\nshows \"unwind_exit \\<Delta>e\"\nusing assms unfolding unwind_exit_def by auto\n\nfun allConsec :: \"'a list \\<Rightarrow> ('a * 'a) set\" where\n  \"allConsec [] = {}\"\n| \"allConsec [a] = {}\"\n| \"allConsec (a # b # as) = insert (a,b) (allConsec (b#as))\"\n\n\nlemma set_allConsec:\nassumes \"\\<Delta> \\<in> set \\<Delta>s'\" and \"\\<Delta>s = \\<Delta>s' ## \\<Delta>1\"\nshows \"\\<exists> \\<Delta>2. (\\<Delta>,\\<Delta>2) \\<in> allConsec \\<Delta>s\"\nusing assms proof (induction \\<Delta>s' arbitrary: \\<Delta>s)\n  case Nil thus ?case by auto\nnext\n  case (Cons \\<Delta>3 \\<Delta>s' \\<Delta>s)\n  show ?case proof(cases \"\\<Delta> = \\<Delta>3\")\n    case True\n    show ?thesis proof(cases \\<Delta>s')\n      case Nil\n      show ?thesis unfolding \\<open>\\<Delta>s = (\\<Delta>3 # \\<Delta>s') ## \\<Delta>1\\<close> Nil True by (rule exI[of _ \\<Delta>1]) simp\n    next\n      case (Cons \\<Delta>4 \\<Delta>s'')\n      show ?thesis unfolding \\<open>\\<Delta>s = (\\<Delta>3 # \\<Delta>s') ## \\<Delta>1\\<close> Cons True by (rule exI[of _ \\<Delta>4]) simp\n    qed\n  next\n    case False hence \"\\<Delta> \\<in> set \\<Delta>s'\" using Cons by auto\n    then obtain \\<Delta>2 where \"(\\<Delta>, \\<Delta>2) \\<in> allConsec (\\<Delta>s' ## \\<Delta>1)\" using Cons by auto\n    thus ?thesis unfolding \\<open>\\<Delta>s = (\\<Delta>3 # \\<Delta>s') ## \\<Delta>1\\<close> by (intro exI[of _ \\<Delta>2]) (cases \\<Delta>s', auto)\n  qed\nqed\n\nlemma allConsec_set:\nassumes \"(\\<Delta>1,\\<Delta>2) \\<in> allConsec \\<Delta>s\"\nshows \"\\<Delta>1 \\<in> set \\<Delta>s \\<and> \\<Delta>2 \\<in> set \\<Delta>s\"\nusing assms by (induct \\<Delta>s rule: allConsec.induct) auto\n\n(* Liniar decomposition: *)\ntheorem unwind_decomp_secure:\nassumes n: \"\\<Delta>s \\<noteq> []\"\nand i: \"\\<And> vl vl1. B vl vl1 \\<Longrightarrow> hd \\<Delta>s istate vl istate vl1\"\nand c: \"\\<And> \\<Delta>1 \\<Delta>2. (\\<Delta>1,\\<Delta>2) \\<in> allConsec \\<Delta>s \\<Longrightarrow> unwind_cont \\<Delta>1 {\\<Delta>1, \\<Delta>2, \\<Delta>e}\"\nand l: \"unwind_cont (last \\<Delta>s) {last \\<Delta>s, \\<Delta>e}\"\nand e: \"unwind_exit \\<Delta>e\"\nshows secure\nproof-\n  let ?\\<Delta>0 = \"hd \\<Delta>s\"  let ?\\<Delta>s = \"insert \\<Delta>e (set \\<Delta>s)\"\n  define \"next\" where \"next \\<Delta>1 =\n    (if \\<Delta>1 = \\<Delta>e then {}\n     else if \\<Delta>1 = last \\<Delta>s then {\\<Delta>1,\\<Delta>e}\n     else {\\<Delta>1,SOME \\<Delta>2. (\\<Delta>1,\\<Delta>2) \\<in> allConsec \\<Delta>s,\\<Delta>e})\" for \\<Delta>1\n  show ?thesis\n  proof(rule unwind_dec_secure)\n    show \"?\\<Delta>0 \\<in> ?\\<Delta>s\" using n by auto\n  next\n    fix vl vl1 assume \"B vl vl1\"\n    thus \"?\\<Delta>0 istate vl istate vl1\" by fact\n  next\n    fix \\<Delta>\n    assume 1: \"\\<Delta> \\<in> ?\\<Delta>s\" show \"next \\<Delta> \\<subseteq> ?\\<Delta>s \\<and> unwind_to \\<Delta> (next \\<Delta>)\"\n    proof-\n      {assume \"\\<Delta> = \\<Delta>e\"\n       hence ?thesis using e unfolding next_def unwind_exit_def unwind_to_def by auto\n      }\n      moreover\n      {assume \"\\<Delta> = last \\<Delta>s\" and \"\\<Delta> \\<noteq> \\<Delta>e\"\n       hence ?thesis using n l unfolding next_def unwind_cont_def unwind_to_def by simp\n      }\n      moreover\n      {assume 1: \"\\<Delta> \\<in> set \\<Delta>s\" and 2: \"\\<Delta> \\<noteq> last \\<Delta>s\" \"\\<Delta> \\<noteq> \\<Delta>e\"\n       then obtain \\<Delta>' \\<Delta>s' where \\<Delta>s: \"\\<Delta>s = \\<Delta>s' ## \\<Delta>'\" and \\<Delta>: \"\\<Delta> \\<in> set \\<Delta>s'\"\n       by (metis (no_types) append_Cons append_assoc in_set_conv_decomp last_snoc rev_exhaust)\n       have \"\\<exists> \\<Delta>2. (\\<Delta>, \\<Delta>2) \\<in> allConsec \\<Delta>s\" using set_allConsec[OF \\<Delta> \\<Delta>s] .\n       hence \"(\\<Delta>, SOME \\<Delta>2. (\\<Delta>, \\<Delta>2) \\<in> allConsec \\<Delta>s) \\<in> allConsec \\<Delta>s\" by (metis (lifting) someI_ex)\n       hence ?thesis using 1 2 c unfolding next_def unwind_cont_def unwind_to_def\n       by simp (metis (no_types) allConsec_set)\n      }\n      ultimately show ?thesis using 1 by blast\n    qed\n  qed\nqed\n\nsubsection\\<open>Instances\\<close>\n\ncorollary unwind_decomp3_secure:\nassumes\ni: \"\\<And> vl vl1. B vl vl1 \\<Longrightarrow> \\<Delta>1 istate vl istate vl1\"\nand c1: \"unwind_cont \\<Delta>1 {\\<Delta>1, \\<Delta>2, \\<Delta>e}\"\nand c2: \"unwind_cont \\<Delta>2 {\\<Delta>2, \\<Delta>3, \\<Delta>e}\"\nand l: \"unwind_cont \\<Delta>3 {\\<Delta>3, \\<Delta>e}\"\nand e: \"unwind_exit \\<Delta>e\"\nshows secure\napply(rule unwind_decomp_secure[of \"[\\<Delta>1, \\<Delta>2, \\<Delta>3]\" \\<Delta>e])\nusing assms by auto\n\ncorollary unwind_decomp4_secure:\nassumes\ni: \"\\<And> vl vl1. B vl vl1 \\<Longrightarrow> \\<Delta>1 istate vl istate vl1\"\nand c1: \"unwind_cont \\<Delta>1 {\\<Delta>1, \\<Delta>2, \\<Delta>e}\"\nand c2: \"unwind_cont \\<Delta>2 {\\<Delta>2, \\<Delta>3, \\<Delta>e}\"\nand c3: \"unwind_cont \\<Delta>3 {\\<Delta>3, \\<Delta>4, \\<Delta>e}\"\nand l: \"unwind_cont \\<Delta>4 {\\<Delta>4, \\<Delta>e}\"\nand e: \"unwind_exit \\<Delta>e\"\nshows secure\napply(rule unwind_decomp_secure[of \"[\\<Delta>1, \\<Delta>2, \\<Delta>3, \\<Delta>4]\" \\<Delta>e])\nusing assms by auto\n\ncorollary unwind_decomp5_secure:\nassumes\ni: \"\\<And> vl vl1. B vl vl1 \\<Longrightarrow> \\<Delta>1 istate vl istate vl1\"\nand c1: \"unwind_cont \\<Delta>1 {\\<Delta>1, \\<Delta>2, \\<Delta>e}\"\nand c2: \"unwind_cont \\<Delta>2 {\\<Delta>2, \\<Delta>3, \\<Delta>e}\"\nand c3: \"unwind_cont \\<Delta>3 {\\<Delta>3, \\<Delta>4, \\<Delta>e}\"\nand c4: \"unwind_cont \\<Delta>4 {\\<Delta>4, \\<Delta>5, \\<Delta>e}\"\nand l: \"unwind_cont \\<Delta>5 {\\<Delta>5, \\<Delta>e}\"\nand e: \"unwind_exit \\<Delta>e\"\nshows secure\napply(rule unwind_decomp_secure[of \"[\\<Delta>1, \\<Delta>2, \\<Delta>3, \\<Delta>4, \\<Delta>5]\" \\<Delta>e])\nusing assms by auto\n\n\n\n\n(*<*)\n\nend (* context BD_Security *)\n\n\nend\n\n(*>*)\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Bounded_Deducibility_Security/Compositional_Reasoning.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.523420348936324, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.27192803161602486}}
{"text": "theory Incredible_Propositional_Tasks\nimports\n  Incredible_Completeness\n  Incredible_Propositional\nbegin\n\ncontext ND_Rules_Inst begin\nlemma eff_NatRuleI:\n  \"nat_rule rule c ants\n    \\<Longrightarrow> entail = (\\<Gamma> \\<turnstile> subst s (freshen a c))\n    \\<Longrightarrow> hyps = ((\\<lambda>ant. ((\\<lambda>p. subst s (freshen a p)) |`| a_hyps ant |\\<union>| \\<Gamma> \\<turnstile> subst s (freshen a (a_conc ant)))) |`| ants)\n    \\<Longrightarrow> (\\<And> ant f. ant |\\<in>| ants \\<Longrightarrow> f |\\<in>| \\<Gamma> \\<Longrightarrow> freshenLC a ` (a_fresh ant) \\<inter> lconsts f = {})\n    \\<Longrightarrow> (\\<And> ant. ant |\\<in>| ants \\<Longrightarrow> freshenLC a ` (a_fresh ant) \\<inter> subst_lconsts s = {})\n    \\<Longrightarrow> eff (NatRule rule) entail hyps\"\n  by (drule eff.intros(2)) simp_all\nend\n\ncontext Abstract_Task begin\nlemma  natEff_InstI:\n  \"rule = (r,c)\n  \\<Longrightarrow> c \\<in> set (consequent r)\n  \\<Longrightarrow> antec = f_antecedent r\n  \\<Longrightarrow> natEff_Inst rule c antec\"\n  by (metis natEff_Inst.intros)\nend\n\ncontext begin\n\nsubsubsection \\<open>Task 1.1\\<close>\n\ntext \\<open>This is the very first task of the Incredible Proof Machine: @{term \"A \\<longrightarrow> A\"}\\<close>\n\nabbreviation A :: \"(string,prop_funs) pform\"\n  where \"A \\<equiv> Fun (Const ''A'') []\"\n\ntext \\<open>First the task is defined as an @{term Abstract_Task}.\\<close>\n\ninterpretation task1_1: Abstract_Task\n  \"curry (SOME f. bij f):: nat \\<Rightarrow> string \\<Rightarrow> string\"\n  \"\\<lambda>_. id\"\n  \"\\<lambda>_. {}\"\n  \"closed :: (string, prop_funs) pform \\<Rightarrow> bool\"\n  subst\n  \"\\<lambda>_. {}\"\n  \"\\<lambda>_. id\"\n  \"Var undefined\"\n  antecedent\n  consequent\n  prop_rules\n  \"[A]\"\n  \"[A]\"\nby unfold_locales simp\n\ntext \\<open>Then we show, that this task has a proof within our formalization of natural deduction\n  by giving a concrete proof tree.\\<close>\n\nlemma \"task1_1.solved\"\n  unfolding task1_1.solved_def\napply clarsimp\napply (rule_tac x=\"{|A|}\" in exI)\napply clarsimp\napply (rule_tac x=\"Node ({|A|} \\<turnstile> A, Axiom) {||}\" in exI)\napply clarsimp\napply (rule conjI)\n apply (rule task1_1.wf)\n   apply (solves clarsimp)\n  apply clarsimp\n  apply (rule task1_1.eff.intros(1))\n  apply (solves simp)\n apply (solves clarsimp)\nby (auto intro: tfinite.intros)\n\n\nprint_locale Vertex_Graph\ninterpretation task1_1: Vertex_Graph task1_1.nodes task1_1.inPorts task1_1.outPorts \"{|0::nat,1|}\"\n  \"undefined(0 := Assumption A, 1 := Conclusion A)\"\n.\n\nprint_locale Pre_Port_Graph\ninterpretation task1_1: Pre_Port_Graph task1_1.nodes task1_1.inPorts task1_1.outPorts \"{|0::nat,1|}\"\n  \"undefined(0 := Assumption A, 1 := Conclusion A)\"\n  \"{((0,Reg A),(1,plain_ant A))}\"\n.\n\nprint_locale Instantiation\ninterpretation task1_1: Instantiation\n  task1_1.inPorts\n  task1_1.outPorts\n  \"undefined(0 := Assumption A, 1 := Conclusion A)\"\n  task1_1.hyps\n  task1_1.nodes\n  \"{((0,Reg A),(1,plain_ant A))}\"\n  \"{|0::nat,1|}\"\n  task1_1.labelsIn\n  task1_1.labelsOut\n  \"curry (SOME f. bij f):: nat \\<Rightarrow> string \\<Rightarrow> string\"\n  \"\\<lambda>_. id\"\n  \"\\<lambda>_. {}\"\n  \"closed :: (string, prop_funs) pform \\<Rightarrow> bool\"\n  subst\n  \"\\<lambda>_. {}\"\n  \"\\<lambda>_. id\"\n  \"Var undefined\"\n  \"id\"\n  \"undefined\"\nby unfold_locales simp\n\ndeclare One_nat_def [simp del]\n\nlemma path_one_edge[simp]:\n  \"task1_1.path v1 v2 pth \\<longleftrightarrow>\n    (v1 = 0 \\<and> v2 = 1 \\<and> pth = [((0,Reg A),(1,plain_ant A))] \\<or>\n    pth = [] \\<and> v1 = v2)\"\n  apply (cases pth)\n  apply (auto simp add: task1_1.path_cons_simp')\n  apply (rename_tac list, case_tac list, auto simp add: task1_1.path_cons_simp')+\n  done\n\ntext \\<open>Finally we can also show that there is a proof graph for this task.\\<close>\n\ninterpretation Tasked_Proof_Graph\n  \"curry (SOME f. bij f):: nat \\<Rightarrow> string \\<Rightarrow> string\"\n  \"\\<lambda>_. id\"\n  \"\\<lambda>_. {}\"\n  \"closed :: (string, prop_funs) pform \\<Rightarrow> bool\"\n  subst\n  \"\\<lambda>_. {}\"\n  \"\\<lambda>_. id\"\n  \"Var undefined\"\n  antecedent\n  consequent\n  prop_rules\n  \"[A]\"\n  \"[A]\"\n  \"{|0::nat,1|}\"\n  \"undefined(0 := Assumption A, 1 := Conclusion A)\"\n  \"{((0,Reg A),(1,plain_ant A))}\"\n  \"id\"\n  \"undefined\"\napply unfold_locales\n        apply (solves simp)\n       apply (solves clarsimp)\n      apply (solves clarsimp)\n     apply (solves clarsimp)\n    apply (solves fastforce)\n   apply (solves fastforce)\n  apply (solves \\<open>clarsimp simp add: task1_1.labelAtOut_def task1_1.labelAtIn_def\\<close>)\n apply (solves clarsimp)\napply (solves clarsimp)\ndone\n\nsubsubsection \\<open>Task 2.11\\<close>\n\ntext \\<open>This is a slightly more interesting task as it involves both our connectives: @{term \"P \\<and> Q \\<longrightarrow> R \\<Longrightarrow> P \\<longrightarrow> (Q \\<longrightarrow> R)\"}\\<close>\n\nabbreviation B :: \"(string,prop_funs) pform\"\n  where \"B \\<equiv> Fun (Const ''B'') []\"\nabbreviation C :: \"(string,prop_funs) pform\"\n  where \"C \\<equiv> Fun (Const ''C'') []\"\n\ninterpretation task2_11: Abstract_Task\n  \"curry (SOME f. bij f):: nat \\<Rightarrow> string \\<Rightarrow> string\"\n  \"\\<lambda>_. id\"\n  \"\\<lambda>_. {}\"\n  \"closed :: (string, prop_funs) pform \\<Rightarrow> bool\"\n  subst\n  \"\\<lambda>_. {}\"\n  \"\\<lambda>_. id\"\n  \"Var undefined\"\n  antecedent\n  consequent\n  prop_rules\n  \"[Fun imp [Fun and [A,B],C]]\"\n  \"[Fun imp [A,Fun imp [B,C]]]\"\nby unfold_locales simp_all\n\nabbreviation \"n_andI \\<equiv> task2_11.n_rules !! 0\"\nabbreviation \"n_andE1 \\<equiv> task2_11.n_rules !! 1\"\nabbreviation \"n_andE2 \\<equiv> task2_11.n_rules !! 2\"\nabbreviation \"n_impI \\<equiv> task2_11.n_rules !! 3\"\nabbreviation \"n_impE \\<equiv> task2_11.n_rules !! 4\"\n\nlemma n_andI [simp]: \"n_andI = (andI, Fun and [X,Y])\"\n  unfolding task2_11.n_rules_def by (simp add: prop_rules_def)\nlemma n_andE1 [simp]: \"n_andE1 = (andE, X)\"\n  unfolding task2_11.n_rules_def One_nat_def by (simp add: prop_rules_def)\nlemma n_andE2 [simp]: \"n_andE2 = (andE, Y)\"\n  unfolding task2_11.n_rules_def numeral_2_eq_2 by (simp add: prop_rules_def)\nlemma n_impI [simp]: \"n_impI = (impI, Fun imp [X,Y])\"\n  unfolding task2_11.n_rules_def numeral_3_eq_3 by (simp add: prop_rules_def)\nlemma n_impE [simp]: \"n_impE = (impE, Y)\"\nproof -\n  have \"n_impE = task2_11.n_rules !! Suc 3\" by simp\n  also have \"... = (impE, Y)\"\n  unfolding task2_11.n_rules_def numeral_3_eq_3 by (simp add: prop_rules_def)\n  finally show ?thesis .\nqed\n\n\nlemma subst_Var_eq_id [simp]: \"subst Var = id\"\n  by (rule ext) (induct_tac x; auto simp: map_idI)\n\nlemma xy_update: \"f = undefined(''X'' := x, ''Y'' := y) \\<Longrightarrow> x = f ''X'' \\<and> y = f ''Y''\" by force\nlemma y_update: \"f = undefined(''Y'':=y) \\<Longrightarrow> y = f ''Y''\" by force\n\ndeclare snth.simps(1) [simp del]\n\ntext \\<open>By interpreting @{term Solved_Task} we show that there is a proof tree for the task.\n  We get the existence of the proof graph for free by using the completeness theorem.\\<close>\n\ninterpretation task2_11: Solved_Task\n  \"curry (SOME f. bij f):: nat \\<Rightarrow> string \\<Rightarrow> string\"\n  \"\\<lambda>_. id\"\n  \"\\<lambda>_. {}\"\n  \"closed :: (string, prop_funs) pform \\<Rightarrow> bool\"\n  subst\n  \"\\<lambda>_. {}\"\n  \"\\<lambda>_. id\"\n  \"Var undefined\"\n  antecedent\n  consequent\n  prop_rules\n  \"[Fun imp [Fun and [A,B],C]]\"\n  \"[Fun imp [A,Fun imp [B,C]]]\"\napply unfold_locales\n  unfolding task2_11.solved_def\napply clarsimp\napply (rule_tac x=\"{|Fun imp [Fun and [A,B],C]|}\" in exI)\napply clarsimp\n\\<comment> \\<open>The actual proof tree for this task.\\<close>\napply (rule_tac x=\"Node ({|Fun imp [Fun and [A, B], C]|} \\<turnstile> Fun imp [A, Fun imp [B, C]],NatRule n_impI)\n  {|Node ({|Fun imp [Fun and [A, B], C], A|} \\<turnstile> Fun imp [B,C],NatRule n_impI)\n    {|Node ({|Fun imp [Fun and [A, B], C], A, B|} \\<turnstile> C,NatRule n_impE)\n      {|Node ({|Fun imp [Fun and [A, B], C], A, B|} \\<turnstile> Fun imp [Fun and [A,B], C],Axiom) {||},\n        Node ({|Fun imp [Fun and [A, B], C], A, B|} \\<turnstile> Fun and [A,B],NatRule n_andI) \n          {|Node ({|Fun imp [Fun and [A, B], C], A, B|} \\<turnstile> A,Axiom) {||},\n            Node ({|Fun imp [Fun and [A, B], C], A, B|} \\<turnstile> B,Axiom) {||}\n          |}\n      |}\n    |}\n  |}\" in exI)\napply clarsimp\napply (rule conjI)\n\n apply (rule task1_1.wf)\n   apply (solves \\<open>clarsimp; metis n_impI snth_smap snth_sset\\<close>)\n  apply clarsimp\n  apply (rule task1_1.eff_NatRuleI [unfolded propositional.freshen_def, simplified]) apply simp_all[4]\n    apply (rule task2_11.natEff_InstI)\n      apply (solves simp)\n     apply (solves simp)\n    apply (solves simp)\n   apply (intro conjI; simp; rule xy_update)\n   apply (solves simp)\n  apply (solves \\<open>fastforce simp: propositional.f_antecedent_def\\<close>)\n apply clarsimp\n\n apply (rule task1_1.wf)\n   apply (solves \\<open>clarsimp; metis n_impI snth_smap snth_sset\\<close>)\n  apply clarsimp\n  apply (rule task1_1.eff_NatRuleI [unfolded propositional.freshen_def, simplified]) apply simp_all[4]\n    apply (rule task2_11.natEff_InstI)\n      apply (solves simp)\n     apply (solves simp)\n    apply (solves simp)\n   apply (intro conjI; simp; rule xy_update)\n   apply (solves simp)\n  apply (solves \\<open>fastforce simp: propositional.f_antecedent_def\\<close>)\n apply clarsimp\n\n apply (rule task1_1.wf)\n   apply (solves \\<open>clarsimp; metis n_impE snth_smap snth_sset\\<close>)\n  apply clarsimp\n  apply (rule task1_1.eff_NatRuleI [unfolded propositional.freshen_def, simplified, where s=\"undefined(''Y'':=C,''X'':=Fun and [A,B])\"]) apply simp_all[4]\n    apply (rule task2_11.natEff_InstI)\n      apply (solves simp)\n     apply (solves simp)\n    apply (solves simp)\n   apply (solves \\<open>intro conjI; simp\\<close>)\n  apply (solves \\<open>simp add: propositional.f_antecedent_def\\<close>)\n apply (erule disjE)\n\n  apply (auto intro: task1_1.wf intro!: task1_1.eff.intros(1))[1]\n\n apply (rule task1_1.wf)\n   apply (solves \\<open>clarsimp; metis n_andI snth_smap snth_sset\\<close>)\n  apply clarsimp\n  apply (rule task1_1.eff_NatRuleI [unfolded propositional.freshen_def, simplified]) apply simp_all[4]\n    apply (rule task2_11.natEff_InstI)\n      apply (solves simp)\n     apply (solves simp)\n    apply (solves simp)\n   apply (intro conjI; simp; rule xy_update)\n   apply (solves simp)\n  apply (solves \\<open>simp add: propositional.f_antecedent_def\\<close>)\n apply clarsimp\n\n apply (erule disjE)\n  apply (solves \\<open>rule task1_1.wf; auto intro: task1_1.eff.intros(1)\\<close>)\n apply (solves \\<open>rule task1_1.wf; auto intro: task1_1.eff.intros(1)\\<close>)\n  \nby (rule tfinite.intros; auto)+\n\n\ninterpretation Tasked_Proof_Graph\n  \"curry (SOME f. bij f):: nat \\<Rightarrow> string \\<Rightarrow> string\"\n  \"\\<lambda>_. id\"\n  \"\\<lambda>_. {}\"\n  \"closed :: (string, prop_funs) pform \\<Rightarrow> bool\"\n  subst\n  \"\\<lambda>_. {}\"\n  \"\\<lambda>_. id\"\n  \"Var undefined\"\n  antecedent\n  consequent\n  prop_rules\n  \"[Fun imp [Fun and [A,B],C]]\"\n  \"[Fun imp [A,Fun imp [B,C]]]\"\n  task2_11.vertices \n  task2_11.nodeOf \n  task2_11.edges\n  task2_11.vidx\n  task2_11.inst\nby unfold_locales\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Incredible_Proof_Machine/Incredible_Propositional_Tasks.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.27189490134432603}}
{"text": "(*  Author:      Andreas Lochbihler\n    Maintainer:  Andreas Lochbihler\n*)\nheader {* Manual construction of a resumption codatatype *}\n\ntheory Resumption imports \n  \"~~/src/HOL/Library/Old_Datatype\"\nbegin\n\ntext {*\n  This theory defines the following codatatype:\n\n\\begin{verbatim}\ncodatatype ('a,'b,'c,'d) resumption =\n    Terminal 'a\n  | Linear 'b \"('a,'b,'c,'d) resumption\"\n  | Branch 'c \"'d => ('a,'b,'c,'d) resumption\"\n\\end{verbatim}\n\n*}\n\nsubsection {* Auxiliary definitions and lemmata similar to @{theory Old_Datatype} *}\n\nlemma Lim_mono: \"(\\<And>d. rs d \\<subseteq> rs' d) \\<Longrightarrow> Old_Datatype.Lim rs \\<subseteq> Old_Datatype.Lim rs'\"\nby(simp add: Lim_def) blast\n\nlemma Lim_UN1:  \"Old_Datatype.Lim (\\<lambda>x. \\<Union>y. f x y) = (\\<Union>y. Old_Datatype.Lim (\\<lambda>x. f x y))\"\nby(simp add: Old_Datatype.Lim_def) blast\n\ntext {*\n  Inverse for @{term \"Old_Datatype.Lim\"} like @{term \"Old_Datatype.Split\"} and @{term \"Old_Datatype.Case\"}\n  for @{term \"Old_Datatype.Scons\"} and @{term \"In0\"}/@{term \"In1\"}\n*}\n\ndefinition DTBranch :: \"(('b \\<Rightarrow> ('a, 'b) Old_Datatype.dtree) \\<Rightarrow> 'c) \\<Rightarrow> ('a, 'b) Old_Datatype.dtree \\<Rightarrow> 'c\"\nwhere \"DTBranch f M = (THE u. \\<exists>x. M = Old_Datatype.Lim x \\<and> u = f x)\"\n\nlemma DTBranch_Lim [simp]: \"DTBranch f (Old_Datatype.Lim M) = f M\"\nby(auto simp add: DTBranch_def dest: Lim_inject)\n\ntext {* Lemmas for @{term Old_Datatype.ntrunc} and @{term \"Old_Datatype.Lim\"} *}\n\nlemma ndepth_Push_Node_Inl_aux:\n     \"case_nat (Inl n) f k = Inr 0 \\<Longrightarrow> Suc (LEAST x. f x = Inr 0) <= k\"\napply (induct \"k\", auto)\napply (erule Least_le)\ndone\n\nlemma ndepth_Push_Node_Inl:\n  \"ndepth (Push_Node (Inl a) n) = Suc (ndepth n)\"\nusing Rep_Node[of n, unfolded Node_def]\napply(simp add: ndepth_def Push_Node_def Abs_Node_inverse[OF Node_Push_I[OF Rep_Node]])\napply(simp add: Push_def split_beta)\napply(rule Least_equality)\napply(auto elim: LeastI intro: ndepth_Push_Node_Inl_aux)\ndone\n\nlemma ntrunc_Lim [simp]: \"ntrunc (Suc k) (Old_Datatype.Lim rs) = Old_Datatype.Lim (\\<lambda>x. ntrunc k (rs x))\"\nunfolding Lim_def ntrunc_def\napply(rule equalityI)\napply clarify\napply(auto simp add: ndepth_Push_Node_Inl)\ndone\n\nsubsection {* Definition for the codatatype universe *}\n\ntext {* Constructors *}\n\ndefinition TERMINAL :: \"'a \\<Rightarrow> ('c + 'b + 'a, 'd) Old_Datatype.dtree\"\nwhere \"TERMINAL a = In0 (Old_Datatype.Leaf (Inr (Inr a)))\"\n\ndefinition LINEAR :: \"'b \\<Rightarrow> ('c + 'b + 'a, 'd) Old_Datatype.dtree \\<Rightarrow> ('c + 'b + 'a, 'd) Old_Datatype.dtree\"\n  where \"LINEAR b r = In1 (In0 (Scons (Old_Datatype.Leaf (Inr (Inl b))) r))\"\n\ndefinition BRANCH :: \"'c \\<Rightarrow> ('d \\<Rightarrow> ('c + 'b + 'a, 'd) Old_Datatype.dtree) \\<Rightarrow> ('c + 'b + 'a, 'd) Old_Datatype.dtree\"\n where \"BRANCH c rs = In1 (In1 (Scons (Old_Datatype.Leaf (Inl c)) (Old_Datatype.Lim rs)))\"\n\ntext {* case operator *}\n\ndefinition case_RESUMPTION :: \"('a \\<Rightarrow> 'e) \\<Rightarrow> ('b \\<Rightarrow> (('c + 'b + 'a, 'd) Old_Datatype.dtree) \\<Rightarrow> 'e) \\<Rightarrow> ('c \\<Rightarrow> ('d \\<Rightarrow> ('c + 'b + 'a, 'd) Old_Datatype.dtree) \\<Rightarrow> 'e) \\<Rightarrow> ('c + 'b + 'a, 'd) Old_Datatype.dtree \\<Rightarrow> 'e\"\nwhere \n  \"case_RESUMPTION t l br =\n   Old_Datatype.Case (t o inv (Old_Datatype.Leaf o Inr o Inr))\n                 (Old_Datatype.Case (Old_Datatype.Split (\\<lambda>x. l (inv (Old_Datatype.Leaf o Inr o Inl) x)))\n                                (Old_Datatype.Split (\\<lambda>x. DTBranch (br (inv (Old_Datatype.Leaf o Inl) x)))))\"\n\n\n\nlemma case_RESUMPTION_simps [simp]:\n  shows case_RESUMPTION_TERMINAL: \"case_RESUMPTION t l br (TERMINAL a) = t a\"\n  and case_RESUMPTION_LINEAR: \"case_RESUMPTION t l br (LINEAR b r) = l b r\"\n  and case_RESUMPTION_BRANCH: \"case_RESUMPTION t l br (BRANCH c rs) = br c rs\"\napply(simp_all add: case_RESUMPTION_def TERMINAL_def LINEAR_def BRANCH_def o_def)\napply(rule arg_cong) back\napply(blast intro: injI inv_f_f)\napply(rule arg_cong) back\napply(blast intro: injI inv_f_f)\napply(rule arg_cong) back\napply(blast intro: injI inv_f_f)\ndone\n\nlemma LINEAR_mono: \"r \\<subseteq> r' \\<Longrightarrow> LINEAR b r \\<subseteq> LINEAR b r'\"\nby(simp add: LINEAR_def In1_mono In0_mono Scons_mono)\n\nlemma BRANCH_mono: \"(\\<And>d. rs d \\<subseteq> rs' d) \\<Longrightarrow> BRANCH c rs \\<subseteq> BRANCH c rs'\"\nby(simp add: BRANCH_def In1_mono Scons_mono Lim_mono)\n\nlemma LINEAR_UN: \"LINEAR b (\\<Union>x. f x) = (\\<Union>x. LINEAR b (f x))\"\nby (simp add: LINEAR_def In1_UN1 In0_UN1 Scons_UN1_y)\n\nlemma BRANCH_UN: \"BRANCH b (\\<lambda>d. \\<Union>x. f d x) = (\\<Union>x. BRANCH b (\\<lambda>d. f d x))\"\nby (simp add: BRANCH_def Lim_UN1 In1_UN1 In0_UN1 Scons_UN1_y)\n\ntext {* The codatatype universe *}\n\ncoinductive_set resumption :: \"('c + 'b + 'a, 'd) Old_Datatype.dtree set\"\nwhere\nresumption_TERMINAL:\n  \"TERMINAL a \\<in> resumption\"\n| resumption_LINEAR:\n  \"r \\<in> resumption \\<Longrightarrow> LINEAR b r \\<in> resumption\"\n| resumption_BRANCH:\n  \"(\\<And>d. rs d \\<in> resumption) \\<Longrightarrow> BRANCH c rs \\<in> resumption\"\n\nsubsection {* Definition of the codatatype as a type *}\n\ntypedef ('a,'b,'c,'d) resumption = \"resumption :: ('c + 'b + 'a, 'd) Old_Datatype.dtree set\"\nproof\n  show \"TERMINAL undefined \\<in> ?resumption\" by(blast intro: resumption.intros)\nqed\n\ntext {* Constructors *}\n\ndefinition Terminal :: \"'a \\<Rightarrow> ('a,'b,'c,'d) resumption\"\nwhere \"Terminal a = Abs_resumption (TERMINAL a)\"\n\ndefinition Linear :: \"'b \\<Rightarrow> ('a,'b,'c,'d) resumption \\<Rightarrow> ('a,'b,'c,'d) resumption\"\nwhere \"Linear b r = Abs_resumption (LINEAR b (Rep_resumption r))\"\n\ndefinition Branch :: \"'c \\<Rightarrow> ('d \\<Rightarrow> ('a,'b,'c,'d) resumption) \\<Rightarrow> ('a,'b,'c,'d) resumption\"\nwhere \"Branch c rs = Abs_resumption (BRANCH c (\\<lambda>d. Rep_resumption (rs d)))\"\n\nlemma [iff]:\n  shows Terminal_not_Linear: \"Terminal a \\<noteq> Linear b r\"\n  and Linear_not_Terminal: \"Linear b R \\<noteq> Terminal a\"\n  and Termina_not_Branch: \"Terminal a \\<noteq> Branch c rs\"\n  and Branch_not_Terminal: \"Branch c rs \\<noteq> Terminal a\"\n  and Linear_not_Branch: \"Linear b r \\<noteq> Branch c rs\"\n  and Branch_not_Linear: \"Branch c rs \\<noteq> Linear b r\"\n  and Terminal_inject: \"Terminal a = Terminal a' \\<longleftrightarrow> a = a'\"\n  and Linear_inject: \"Linear b r = Linear b' r' \\<longleftrightarrow> b = b' \\<and> r = r'\"\n  and Branch_inject: \"Branch c rs = Branch c' rs' \\<longleftrightarrow> c = c' \\<and> rs = rs'\"\napply(auto simp add: Terminal_def Linear_def Branch_def simp add: Rep_resumption resumption.intros Abs_resumption_inject Rep_resumption_inject)\napply(subst (asm) fun_eq_iff, auto simp add: Rep_resumption_inject)\ndone\n\nlemma Rep_resumption_constructors:\n  shows Rep_resumption_Terminal: \"Rep_resumption (Terminal a) = TERMINAL a\"\n  and Rep_resumption_Linear: \"Rep_resumption (Linear b r) = LINEAR b (Rep_resumption r)\"\n  and Rep_resumption_Branch: \"Rep_resumption (Branch c rs) = BRANCH c (\\<lambda>d. Rep_resumption (rs d))\"\nby(simp_all add: Terminal_def Linear_def Branch_def Abs_resumption_inverse resumption.intros Rep_resumption)\n\ntext {* Case operator *}\n\ndefinition case_resumption :: \"('a \\<Rightarrow> 'e) \\<Rightarrow> ('b \\<Rightarrow> ('a,'b,'c,'d) resumption \\<Rightarrow> 'e) \\<Rightarrow>\n                            ('c \\<Rightarrow> ('d \\<Rightarrow> ('a,'b,'c,'d) resumption) \\<Rightarrow> 'e) \\<Rightarrow> ('a,'b,'c,'d) resumption \\<Rightarrow> 'e\"\nwhere [code del]:\n  \"case_resumption t l br r =\n   case_RESUMPTION t (\\<lambda>b r. l b (Abs_resumption r)) (\\<lambda>c rs. br c (\\<lambda>d. Abs_resumption (rs d))) (Rep_resumption r)\"\n\nlemma case_resumption_simps [simp, code]:\n  shows case_resumption_Terminal: \"case_resumption t l br (Terminal a) = t a\"\n  and case_resumption_Linear: \"case_resumption t l br (Linear b r) = l b r\"\n  and case_resumption_Branch: \"case_resumption t l br (Branch c rs) = br c rs\"\nby(simp_all add: Terminal_def Linear_def Branch_def case_resumption_def Abs_resumption_inverse resumption.intros Rep_resumption Rep_resumption_inverse)\n\ndeclare [[case_translation case_resumption Terminal Linear Branch]]\n\nlemma case_resumption_cert:\n  assumes \"CASE \\<equiv> case_resumption t l br\"\n  shows \"(CASE (Terminal a) \\<equiv> t a) &&& (CASE (Linear b r) \\<equiv> l b r) &&& (CASE (Branch c rs) \\<equiv> br c rs)\"\nusing assms by simp_all\n\ncode_datatype Terminal Linear Branch\n\nsetup {*\n  Code.add_case @{thm case_resumption_cert}\n*}\n\nsetup {*\n  Nitpick.register_codatatype @{typ \"('a,'b,'c,'d) resumption\"} @{const_name case_resumption}\n                              (map dest_Const [@{term Terminal}, @{term Linear}, @{term Branch}])\n*}\n\nlemma resumption_exhaust [cases type: resumption]:\n  obtains (Terminal) a where \"x = Terminal a\"\n  | (Linear) b r where \"x = Linear b r\"\n  | (Branch) c rs where \"x = Branch c rs\"\nproof(cases x)\n  case (Abs_resumption y)\n  note [simp] = `x = Abs_resumption y`\n  from `y \\<in> resumption` show thesis\n  proof(cases rule: resumption.cases)\n    case resumption_TERMINAL thus ?thesis\n      by -(rule Terminal, simp add: Terminal_def)\n  next\n    case (resumption_LINEAR r b) \n    from `r \\<in> resumption` have \"Rep_resumption (Abs_resumption r) = r\"\n      by(simp add: Abs_resumption_inverse)\n    hence \"y = LINEAR b (Rep_resumption (Abs_resumption r))\"\n      using `y = LINEAR b r` by simp\n    thus ?thesis by -(rule Linear, simp add: Linear_def)\n  next\n    case (resumption_BRANCH rs c)\n    from `\\<And>d. rs d \\<in> resumption`\n    have eq: \"rs = (\\<lambda>d. Rep_resumption (Abs_resumption (rs d)))\"\n      by(subst Abs_resumption_inverse) blast+\n    show ?thesis using `y = BRANCH c rs` \n      by -(rule Branch, simp add: Branch_def, subst eq, simp)\n  qed\nqed\n\nlemma resumption_split:\n  \"P (case_resumption t l br r) \\<longleftrightarrow> \n  (\\<forall>a. r = Terminal a \\<longrightarrow> P (t a)) \\<and>\n  (\\<forall>b r'. r = Linear b r' \\<longrightarrow> P (l b r')) \\<and>\n  (\\<forall>c rs. r = Branch c rs \\<longrightarrow> P (br c rs))\"\nby(cases r) simp_all\n\nlemma resumption_split_asm:\n  \"P (case_resumption t l br r) \\<longleftrightarrow>\n  \\<not> ((\\<exists>a. r = Terminal a \\<and> \\<not> P (t a)) \\<or>\n     (\\<exists>b r'. r = Linear b r' \\<and> \\<not> P (l b r')) \\<or>\n     (\\<exists>c rs. r = Branch c rs \\<and> \\<not> P (br c rs)))\"\nby(cases r) simp_all\n\nlemmas resumption_splits = resumption_split resumption_split_asm\n\n\ntext {* corecursion operator *}\n\ndatatype (dead 'a, dead 'b, dead 'c, dead 'd, dead 'e) resumption_corec =\n    Terminal_corec 'a\n  | Linear_corec 'b 'e\n  | Branch_corec 'c \"'d \\<Rightarrow> 'e\"\n  | Resumption_corec \"('a, 'b, 'c, 'd) resumption\"\n\nprimrec RESUMPTION_corec_aux :: \"nat \\<Rightarrow> ('e \\<Rightarrow> ('a,'b,'c,'d,'e) resumption_corec) \\<Rightarrow> 'e \\<Rightarrow> ('c + 'b + 'a,'d) Old_Datatype.dtree\"\nwhere\n  \"RESUMPTION_corec_aux 0 f e = {}\"\n| \"RESUMPTION_corec_aux (Suc n) f e =\n  (case f e of Terminal_corec a \\<Rightarrow> TERMINAL a\n            | Linear_corec b e' \\<Rightarrow> LINEAR b (RESUMPTION_corec_aux n f e')\n            | Branch_corec c es \\<Rightarrow> BRANCH c (\\<lambda>d. RESUMPTION_corec_aux n f (es d))\n            | Resumption_corec r \\<Rightarrow> Rep_resumption r)\"\n\ndefinition RESUMPTION_corec :: \"('e \\<Rightarrow> ('a,'b,'c,'d,'e) resumption_corec) \\<Rightarrow> 'e \\<Rightarrow> ('c + 'b + 'a,'d) Old_Datatype.dtree\"\nwhere\n  \"RESUMPTION_corec f e = (\\<Union>n. RESUMPTION_corec_aux n f e)\"\n\nlemma RESUMPTION_corec [nitpick_simp]:\n  \"RESUMPTION_corec f e =\n  (case f e of Terminal_corec a \\<Rightarrow> TERMINAL a\n            | Linear_corec b e' \\<Rightarrow> LINEAR b (RESUMPTION_corec f e')\n            | Branch_corec c es \\<Rightarrow> BRANCH c (\\<lambda>d. RESUMPTION_corec f (es d))\n            | Resumption_corec r \\<Rightarrow> Rep_resumption r)\"\n  (is \"?lhs = ?rhs\")\nproof\n  show \"?lhs \\<subseteq> ?rhs\" unfolding RESUMPTION_corec_def\n  proof(rule UN_least)\n    fix n\n    show \"RESUMPTION_corec_aux n f e\n        \\<subseteq> (case f e of Terminal_corec a \\<Rightarrow> TERMINAL a\n           | Linear_corec b e' \\<Rightarrow> LINEAR b (\\<Union>n. RESUMPTION_corec_aux n f e')\n           | Branch_corec c es \\<Rightarrow> BRANCH c (\\<lambda>d. \\<Union>n. RESUMPTION_corec_aux n f (es d))\n           | Resumption_corec r \\<Rightarrow> Rep_resumption r)\"\n      apply(cases n, simp_all split: resumption_corec.split)\n      by(rule conjI strip LINEAR_mono[OF UN_upper] BRANCH_mono[OF UN_upper] UNIV_I)+\n  qed\nnext\n  show \"?rhs \\<subseteq> ?lhs\" unfolding RESUMPTION_corec_def\n    apply(simp split: resumption_corec.split add: LINEAR_UN BRANCH_UN)\n    by safe(rule_tac a=\"Suc ?n\" in UN_I, rule UNIV_I, simp)+\nqed\n\nlemma RESUMPTION_corec_type: \"RESUMPTION_corec f e \\<in> resumption\"\nproof -\n  have \"\\<exists>x. RESUMPTION_corec f e = RESUMPTION_corec f x\" by blast\n  thus ?thesis\n  proof coinduct\n    case (resumption x)\n    then obtain e where x: \"x = RESUMPTION_corec f e\" by blast\n    thus ?case \n    proof(cases \"f e\")\n      case (Resumption_corec r)\n      thus ?thesis using x\n        by(cases r)(simp_all add: RESUMPTION_corec Rep_resumption_constructors Rep_resumption)\n    qed(auto simp add: RESUMPTION_corec)\n  qed\nqed\n\ntext {* corecursion operator for the resumption type *}\n\ndefinition resumption_corec :: \"('e \\<Rightarrow> ('a,'b,'c,'d,'e) resumption_corec) \\<Rightarrow> 'e \\<Rightarrow> ('a,'b,'c,'d) resumption\"\nwhere\n  \"resumption_corec f e = Abs_resumption (RESUMPTION_corec f e)\"\n\nlemma resumption_corec:\n  \"resumption_corec f e =\n  (case f e of Terminal_corec a \\<Rightarrow> Terminal a\n            | Linear_corec b e' \\<Rightarrow> Linear b (resumption_corec f e')\n            | Branch_corec c es \\<Rightarrow> Branch c (\\<lambda>d. resumption_corec f (es d))\n            | Resumption_corec r \\<Rightarrow> r)\"\nunfolding resumption_corec_def\napply(subst RESUMPTION_corec)\napply(auto split: resumption_corec.splits simp add: Terminal_def Linear_def Branch_def RESUMPTION_corec_type Abs_resumption_inverse Rep_resumption_inverse)\ndone\n\ntext {* Equality as greatest fixpoint *}\n\ncoinductive Eq_RESUMPTION :: \"('c+'b+'a, 'd) Old_Datatype.dtree \\<Rightarrow> ('c+'b+'a, 'd) Old_Datatype.dtree \\<Rightarrow> bool\"\nwhere\n  EqTERMINAL: \"Eq_RESUMPTION (TERMINAL a) (TERMINAL a)\"\n| EqLINEAR: \"Eq_RESUMPTION r r' \\<Longrightarrow> Eq_RESUMPTION (LINEAR b r) (LINEAR b r')\"\n| EqBRANCH: \"(\\<And>d. Eq_RESUMPTION (rs d) (rs' d)) \\<Longrightarrow> Eq_RESUMPTION (BRANCH c rs) (BRANCH c rs')\"\n\n\n\nlemma Eq_RESUMPTION_refl:\n  assumes \"r \\<in> resumption\"\n  shows \"Eq_RESUMPTION r r\"\nproof -\n  def r' == r\n  with assms have \"r = r' \\<and> r \\<in> resumption\" by auto\n  thus \"Eq_RESUMPTION r r'\"\n  proof(coinduct)\n    case (Eq_RESUMPTION r r')\n    hence [simp]: \"r = r'\" and \"r \\<in> resumption\" by auto\n    from `r \\<in> resumption` show ?case\n      by(cases rule: resumption.cases) auto\n  qed\nqed\n\nlemma Eq_RESUMPTION_into_resumption:\n  assumes \"Eq_RESUMPTION r r\"\n  shows \"r \\<in> resumption\"\nusing assms\nproof(coinduct)\n  case resumption thus ?case by cases auto\nqed\n\nlemma Eq_RESUMPTION_eq:\n  \"Eq_RESUMPTION r r' \\<longleftrightarrow> r = r' \\<and> r \\<in> resumption\"\nproof(rule iffI)\n  assume \"Eq_RESUMPTION r r'\"\n  hence \"\\<And>k. ntrunc k r = ntrunc k r'\" by(rule Eq_RESUMPTION_implies_ntrunc_equality)\n  hence \"r = r'\" by(rule ntrunc_equality)\n  moreover with `Eq_RESUMPTION r r'` have \"r \\<in> resumption\"\n    by(auto intro: Eq_RESUMPTION_into_resumption)\n  ultimately show \"r = r' \\<and> r \\<in> resumption\" ..\nnext\n  assume \"r = r' \\<and> r \\<in> resumption\"\n  thus \"Eq_RESUMPTION r r'\" by(blast intro: Eq_RESUMPTION_refl)\nqed\n\nlemma Eq_RESUMPTION_I [consumes 1, case_names Eq_RESUMPTION, case_conclusion Eq_RESUMPTION EqTerminal EqLinear EqBranch]:\n  assumes \"X r r'\"\n  and step: \"\\<And>r r'. X r r' \\<Longrightarrow>\n             (\\<exists>a. r = TERMINAL a \\<and> r' = TERMINAL a) \\<or>\n             (\\<exists>R R' b. r = LINEAR b R \\<and> r' = LINEAR b R' \\<and> (X R R' \\<or> Eq_RESUMPTION R R')) \\<or>\n             (\\<exists>rs rs' c. r = BRANCH c rs \\<and> r' = BRANCH c rs' \\<and> (\\<forall>d. X (rs d) (rs' d) \\<or> Eq_RESUMPTION (rs d) (rs' d)))\"\n  shows \"r = r'\"\nproof -\n  from `X r r'` have \"Eq_RESUMPTION r r'\"\n    by(coinduct)(rule step)\n  thus ?thesis by(simp add: Eq_RESUMPTION_eq)\nqed\n\nlemma resumption_equalityI [consumes 1, case_names Eq_resumption, case_conclusion Eq_resumption EqTerminal EqLinear EqBranch]:\n  assumes \"X r r'\"\n  and step: \"\\<And>r r'. X r r' \\<Longrightarrow>\n             (\\<exists>a. r = Terminal a \\<and> r' = Terminal a) \\<or>\n             (\\<exists>R R' b. r = Linear b R \\<and> r' = Linear b R' \\<and> (X R R' \\<or> R = R')) \\<or>\n             (\\<exists>rs rs' c. r = Branch c rs \\<and> r' = Branch c rs' \\<and> (\\<forall>d. X (rs d) (rs' d) \\<or> rs d = rs' d))\"\n  shows \"r = r'\"\nproof -\n  def M == \"Rep_resumption r\" and N == \"Rep_resumption r'\"\n  with `X r r'` have \"\\<exists>r r'. M = Rep_resumption r \\<and> N = Rep_resumption r' \\<and> X r r'\" by blast\n  hence \"M = N\"\n  proof(coinduct rule: Eq_RESUMPTION_I)\n    case (Eq_RESUMPTION M N)\n    then obtain r r' where [simp]: \"M = Rep_resumption r\" \"N = Rep_resumption r'\"\n      and \"X r r'\" by blast\n    { assume \"\\<exists>a. r = Terminal a \\<and> r' = Terminal a\"\n      hence ?EqTerminal by(auto simp add: Rep_resumption_constructors)\n      hence ?case .. }\n    moreover\n    { assume \"\\<exists>R R' b. r = Linear b R \\<and> r' = Linear b R' \\<and> (X R R' \\<or> R = R')\"\n      hence ?EqLinear\n        by(clarsimp simp add: Rep_resumption_constructors Eq_RESUMPTION_eq Rep_resumption_inject Rep_resumption)\n      hence ?case by blast }\n    moreover\n    { assume \"\\<exists>rs rs' c. r = Branch c rs \\<and> r' = Branch c rs' \\<and> (\\<forall>d. X (rs d) (rs' d) \\<or> rs d = rs' d)\"\n      hence ?EqBranch\n        by(clarsimp simp add: Rep_resumption_constructors Eq_RESUMPTION_eq Rep_resumption_inject Rep_resumption)\n      hence ?case by blast }\n    ultimately show ?case using step[OF `X r r'`] by blast\n  qed\n  thus ?thesis unfolding M_def N_def by(simp add: Rep_resumption_inject)\nqed\n\ntext {*\n  Finality of @{text \"resumption\"}: Uniqueness of functions defined by corecursion.\n*}\n\nlemma equals_RESUMPTION_corec:\n  assumes h: \"\\<And>x. h x = (case f x of Terminal_corec a \\<Rightarrow> TERMINAL a\n                                   | Linear_corec b x' \\<Rightarrow> LINEAR b (h x')\n                                   | Branch_corec c xs \\<Rightarrow> BRANCH c (\\<lambda>d. h (xs d))\n                                   | Resumption_corec r \\<Rightarrow> Rep_resumption r)\"\n  shows \"h = RESUMPTION_corec f\"\nproof\n  fix x\n  def h' == \"RESUMPTION_corec f\"\n  have h': \"\\<And>x. h' x = (case f x of Terminal_corec a \\<Rightarrow> TERMINAL a\n                                   | Linear_corec b x' \\<Rightarrow> LINEAR b (h' x')\n                                   | Branch_corec c xs \\<Rightarrow> BRANCH c (\\<lambda>d. h' (xs d))\n                                   | Resumption_corec r \\<Rightarrow> Rep_resumption r)\"\n    unfolding h'_def by(simp add: RESUMPTION_corec)\n  def M == \"h x\" and N == \"h' x\"\n  hence \"\\<exists>x. M = h x \\<and> N = h' x\" by blast\n  thus \"M = N\"\n  proof(coinduct rule: Eq_RESUMPTION_I)\n    case (Eq_RESUMPTION M N)\n    then obtain x where [simp]: \"M = h x\" \"N = h' x\" by blast\n    show ?case\n    proof(cases \"f x\")\n      case (Terminal_corec a)\n      with h h' have ?EqTerminal by simp\n      thus ?thesis ..\n    next\n      case (Linear_corec b x')\n      with h h' have ?EqLinear by auto\n      thus ?thesis by blast\n    next\n      case (Branch_corec c xs)\n      with h h' have ?EqBranch by auto\n      thus ?thesis by blast\n    next\n      case (Resumption_corec r)\n      thus ?thesis\n        by(cases r)(simp_all add: h h' Rep_resumption_constructors Eq_RESUMPTION_refl Rep_resumption)\n    qed\n  qed\nqed\n\nlemma equals_resumption_corec:\n  assumes h: \"\\<And>x. h x = (case f x of Terminal_corec a \\<Rightarrow> Terminal a\n                                   | Linear_corec b x' \\<Rightarrow> Linear b (h x')\n                                   | Branch_corec c xs \\<Rightarrow> Branch c (\\<lambda>d. h (xs d))\n                                   | Resumption_corec r \\<Rightarrow> r)\"\n  shows \"h = resumption_corec f\"\nproof(rule ext)\n  fix x\n  { fix x\n    from h[of x]\n    have \"Rep_resumption (h x) =\n      (case f x of Terminal_corec a \\<Rightarrow> TERMINAL a\n                | Linear_corec b x' \\<Rightarrow> LINEAR b (Rep_resumption (h x'))\n                | Branch_corec c xs \\<Rightarrow> BRANCH c (\\<lambda>d. Rep_resumption (h (xs d)))\n                | Resumption_corec r \\<Rightarrow> Rep_resumption r)\"\n      by(auto split: resumption_corec.split simp add: Rep_resumption_constructors) }\n  hence eq: \"(\\<lambda>x. Rep_resumption (h x)) = RESUMPTION_corec f\" by(rule equals_RESUMPTION_corec)\n  hence \"Abs_resumption (Rep_resumption (h x)) = Abs_resumption (RESUMPTION_corec f x)\"\n    by(subst (asm) fun_eq_iff)(auto)\n  from this[symmetric] show \"h x = resumption_corec f x\"\n    unfolding resumption_corec_def by(simp add: Rep_resumption_inverse)\nqed\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Coinductive/Examples/Resumption.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5117166047041654, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.2718286569298458}}
{"text": "(*  Title:       CoreC++\n    Author:      Daniel Wasserrab\n    Maintainer:  Daniel Wasserrab <wasserra at fmi.uni-passau.de>\n\n   Based on extracts from the Jinja theories:\n      Common/Objects.thy by David von Oheimb\n      Common/Conform.thy by David von Oheimb and Tobias Nipkow\n      Common/Exceptions.thy by Gerwin Klein and Martin Strecker\n      J/BigStep.thy by Tobias Nipkow\n      J/SmallStep.thy by Tobias Nipkow\n      J/WellTypeRT.thy by Tobias Nipkow \n*)\n\n\nheader {* \\isaheader{Heap Extension} *}\n\ntheory HeapExtension\nimports Progress\nbegin\n\nsection {* The Heap Extension *}\n\ndefinition hext :: \"heap \\<Rightarrow> heap \\<Rightarrow> bool\" (\"_ \\<unlhd> _\" [51,51] 50) where\n  \"h \\<unlhd> h'  \\<equiv>  \\<forall>a C S. h a = Some(C,S) \\<longrightarrow> (\\<exists>S'. h' a = Some(C,S'))\"\n\nlemma hextI: \"\\<forall>a C S. h a = Some(C,S) \\<longrightarrow> (\\<exists>S'. h' a = Some(C,S')) \\<Longrightarrow> h \\<unlhd> h'\"\n\napply (unfold hext_def)\napply auto\ndone\n\n\nlemma hext_objD: \"\\<lbrakk> h \\<unlhd> h'; h a = Some(C,S) \\<rbrakk> \\<Longrightarrow> \\<exists>S'. h' a = Some(C,S')\"\n\napply (unfold hext_def)\napply (force)\ndone\n\n\nlemma hext_refl [iff]: \"h \\<unlhd> h\"\n\napply (rule hextI)\napply (fast)\ndone\n\n\nlemma hext_new [simp]: \"h a = None \\<Longrightarrow> h \\<unlhd> h(a\\<mapsto>x)\"\n\napply (rule hextI)\napply (auto simp:fun_upd_apply)\ndone\n\n\nlemma hext_trans: \"\\<lbrakk> h \\<unlhd> h'; h' \\<unlhd> h'' \\<rbrakk> \\<Longrightarrow> h \\<unlhd> h''\"\n\napply (rule hextI)\napply (fast dest: hext_objD)\ndone\n\n\nlemma hext_upd_obj: \"h a = Some (C,S) \\<Longrightarrow> h \\<unlhd> h(a\\<mapsto>(C,S'))\"\n\napply (rule hextI)\napply (auto simp:fun_upd_apply)\ndone\n\n\n\nsection {* @{text\"\\<unlhd>\"} and preallocated *}\n\nlemma preallocated_hext:\n  \"\\<lbrakk> preallocated h; h \\<unlhd> h' \\<rbrakk> \\<Longrightarrow> preallocated h'\"\nby (simp add: preallocated_def hext_def)\n\n\nlemmas preallocated_upd_obj = preallocated_hext [OF _ hext_upd_obj]\nlemmas preallocated_new  = preallocated_hext [OF _ hext_new]\n\n\n\nsection {* @{text\"\\<unlhd>\"} in Small- and BigStep *}\n\nlemma red_hext_incr: \"P,E \\<turnstile> \\<langle>e,(h,l)\\<rangle> \\<rightarrow> \\<langle>e',(h',l')\\<rangle>  \\<Longrightarrow> h \\<unlhd> h'\"\n  and reds_hext_incr: \"P,E \\<turnstile> \\<langle>es,(h,l)\\<rangle> [\\<rightarrow>] \\<langle>es',(h',l')\\<rangle>  \\<Longrightarrow> h \\<unlhd> h'\"\n\nproof(induct rule:red_reds_inducts)\n  case RedNew thus ?case\n    by(fastforce dest:new_Addr_SomeD simp:hext_def split:if_splits)\nnext\n  case RedFAss thus ?case by(simp add:hext_def split:if_splits)\nqed simp_all\n\n\nlemma step_hext_incr: \"P,E \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle>  \\<Longrightarrow> hp s \\<unlhd> hp s'\"\n\nproof(induct rule:converse_rtrancl_induct2)\n  case refl thus ?case by(rule hext_refl)\nnext\n  case (step e s e'' s'')\n  have Red:\"((e, s), e'', s'') \\<in> Red P E\"\n    and hext:\"hp s'' \\<unlhd> hp s'\" by fact+\n  from Red have \"P,E \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow> \\<langle>e'',s''\\<rangle>\" by simp\n  hence \"hp s \\<unlhd> hp s''\"\n    by(cases s,cases s'')(auto dest:red_hext_incr)\n  with hext show ?case by-(rule hext_trans)\nqed\n\n\nlemma steps_hext_incr: \"P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<rightarrow>]* \\<langle>es',s'\\<rangle>  \\<Longrightarrow> hp s \\<unlhd> hp s'\"\n\nproof(induct rule:converse_rtrancl_induct2)\n  case refl thus ?case by(rule hext_refl)\nnext\n  case (step es s es'' s'')\n  have Reds:\"((es, s), es'', s'') \\<in> Reds P E\"\n    and hext:\"hp s'' \\<unlhd> hp s'\" by fact+\n  from Reds have \"P,E \\<turnstile> \\<langle>es,s\\<rangle> [\\<rightarrow>] \\<langle>es'',s''\\<rangle>\" by simp\n  hence \"hp s \\<unlhd> hp s''\"\n    by(cases s,cases s'',auto dest:reds_hext_incr)\n  with hext show ?case by-(rule hext_trans)\nqed\n\n\n\nlemma eval_hext: \"P,E \\<turnstile> \\<langle>e,(h,l)\\<rangle> \\<Rightarrow> \\<langle>e',(h',l')\\<rangle> \\<Longrightarrow> h \\<unlhd> h'\"\nand evals_hext:  \"P,E \\<turnstile> \\<langle>es,(h,l)\\<rangle> [\\<Rightarrow>] \\<langle>es',(h',l')\\<rangle> \\<Longrightarrow> h \\<unlhd> h'\"\n\nproof (induct rule:eval_evals_inducts)\n  case New thus ?case\n    by(fastforce intro!: hext_new intro:someI simp:new_Addr_def\n                split:split_if_asm simp del:fun_upd_apply)\nnext\n  case FAss thus ?case\n    by(auto simp:sym[THEN hext_upd_obj] simp del:fun_upd_apply\n            elim!: hext_trans)\nqed (auto elim!: hext_trans)\n\n\n\nsection {* @{text\"\\<unlhd>\"} and conformance *}\n\nlemma conf_hext: \"h \\<unlhd> h' \\<Longrightarrow> P,h \\<turnstile> v :\\<le> T \\<Longrightarrow> P,h' \\<turnstile> v :\\<le> T\"\nby(cases T)(induct v,auto dest: hext_objD split:split_if_asm)+\n\nlemma confs_hext: \"P,h \\<turnstile> vs [:\\<le>] Ts \\<Longrightarrow> h \\<unlhd> h' \\<Longrightarrow> P,h' \\<turnstile> vs [:\\<le>] Ts\"\nby (erule list_all2_mono, erule conf_hext, assumption)\n\nlemma fconf_hext: \"\\<lbrakk> P,h \\<turnstile> fs (:\\<le>) E; h \\<unlhd> h' \\<rbrakk> \\<Longrightarrow> P,h' \\<turnstile> fs (:\\<le>) E\"\n\napply (unfold fconf_def)\napply  (fast elim: conf_hext)\ndone\n\n\n\nlemmas fconf_upd_obj = fconf_hext [OF _ hext_upd_obj]\nlemmas fconf_new = fconf_hext [OF _ hext_new]\n\n\n\nlemma oconf_hext: \"P,h \\<turnstile> obj \\<surd> \\<Longrightarrow> h \\<unlhd> h' \\<Longrightarrow> P,h' \\<turnstile> obj \\<surd>\"\n\napply (auto simp:oconf_def)\napply (erule allE)\napply (erule_tac x=\"Cs\" in allE)\napply (erule_tac x=\"fs'\" in allE)\napply (fastforce elim:fconf_hext)\ndone\n\n\nlemmas oconf_new = oconf_hext [OF _ hext_new]\nlemmas oconf_upd_obj = oconf_hext [OF _ hext_upd_obj]\n\n\nlemma hconf_new: \"\\<lbrakk> P \\<turnstile> h \\<surd>; h a = None; P,h \\<turnstile> obj \\<surd> \\<rbrakk> \\<Longrightarrow> P \\<turnstile> h(a\\<mapsto>obj) \\<surd>\"\nby (unfold hconf_def) (auto intro: oconf_new preallocated_new)\n\nlemma \"\\<lbrakk>P \\<turnstile> h \\<surd>; h' = h(a \\<mapsto> (C, Collect (init_obj P C))); h a = None; wf_prog wf_md P\\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile> h' \\<surd>\"\napply (simp add:hconf_def oconf_def)\napply auto\n     apply (rule_tac x=\"init_class_fieldmap P (last Cs)\" in exI)\n     apply (rule init_obj.intros)\n     apply assumption\n    apply (erule init_obj.cases)\n    apply clarsimp\n    apply (erule init_obj.cases)\n    apply clarsimp\n   apply (erule_tac x=\"a\" in allE)\n   apply clarsimp\n   apply (erule init_obj.cases)\n   apply simp\n  apply (erule_tac x=\"a\" in allE)\n  apply clarsimp\n  apply (erule init_obj.cases)\n  apply clarsimp\n  apply (drule Subobj_last_isClass)\n   apply simp\n  apply (auto simp:is_class_def)\n  apply (rule fconf_init_fields)\n  apply auto\n apply (erule_tac x=\"aa\" in allE)\n apply (erule_tac x=\"aaa\" in allE)\n apply (erule_tac x=\"b\" in allE)\n apply clarsimp\n apply (rotate_tac -1)\n apply (erule_tac x=\"Cs\" in allE)\n apply (erule_tac x=\"fs'\" in allE)\n apply clarsimp thm fconf_new\n apply (erule fconf_new)\n apply simp\napply (rule preallocated_new)\napply simp_all\ndone\n\n\n\nlemma hconf_upd_obj: \n\"\\<lbrakk> P \\<turnstile> h\\<surd>; h a = Some(C,S); P,h \\<turnstile> (C,S')\\<surd> \\<rbrakk> \\<Longrightarrow> P \\<turnstile> h(a\\<mapsto>(C,S'))\\<surd>\"\nby (unfold hconf_def) (auto intro: oconf_upd_obj preallocated_upd_obj)\n\nlemma lconf_hext: \"\\<lbrakk> P,h \\<turnstile> l (:\\<le>)\\<^sub>w E; h \\<unlhd> h' \\<rbrakk> \\<Longrightarrow> P,h' \\<turnstile> l (:\\<le>)\\<^sub>w E\"\n\napply (unfold lconf_def)\napply  (fast elim: conf_hext)\ndone\n\n\n\nsection {* @{text\"\\<unlhd>\"} in the runtime type system *}\n\nlemma hext_typeof_mono: \"\\<lbrakk> h \\<unlhd> h'; P \\<turnstile> typeof\\<^bsub>h\\<^esub> v = Some T \\<rbrakk> \\<Longrightarrow> P \\<turnstile> typeof\\<^bsub>h'\\<^esub> v = Some T\"\n\napply(cases v)\n    apply simp\n   apply simp\n  apply simp\n apply simp\napply(fastforce simp:hext_def)\ndone\n\n\n\nlemma WTrt_hext_mono: \"P,E,h \\<turnstile> e : T \\<Longrightarrow> (\\<And>h'. h \\<unlhd> h' \\<Longrightarrow> P,E,h' \\<turnstile> e : T)\"\nand WTrts_hext_mono: \"P,E,h \\<turnstile> es [:] Ts \\<Longrightarrow> (\\<And>h'. h \\<unlhd> h' \\<Longrightarrow> P,E,h' \\<turnstile> es [:] Ts)\"\n\napply(induct rule: WTrt_inducts)\napply(simp add: WTrtNew)\napply(fastforce intro: WTrtDynCast)\napply(fastforce intro: WTrtStaticCast)\napply(fastforce simp: WTrtVal dest:hext_typeof_mono)\napply(simp add: WTrtVar)\napply(fastforce simp add: WTrtBinOp)\napply(fastforce simp add: WTrtLAss)\napply(fastforce simp: WTrtFAcc del:WTrt_WTrts.intros WTrt_elim_cases)\napply(simp add: WTrtFAccNT)\napply(fastforce simp: WTrtFAss del:WTrt_WTrts.intros WTrt_elim_cases)\napply(fastforce simp: WTrtFAssNT del:WTrt_WTrts.intros WTrt_elim_cases)\napply(fastforce simp: WTrtCall del:WTrt_WTrts.intros WTrt_elim_cases)\napply(fastforce simp: WTrtStaticCall del:WTrt_WTrts.intros WTrt_elim_cases)\napply(fastforce simp: WTrtCallNT del:WTrt_WTrts.intros WTrt_elim_cases)\napply(fastforce)\napply(fastforce simp add: WTrtSeq)\napply(fastforce simp add: WTrtCond)\napply(fastforce simp add: WTrtWhile)\napply(fastforce simp add: WTrtThrow)\napply(simp add: WTrtNil)\napply(simp add: WTrtCons)\ndone\n\n\n\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/CoreC++/HeapExtension.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5117166047041654, "lm_q2_score": 0.5312093733737562, "lm_q1q2_score": 0.27182865692984576}}
{"text": "(*  Title:      SSA_CFG.thy\n    Author:     Sebastian Ullrich, Denis Lohner\n*)\n\ntheory SSA_CFG\nimports Graph_path \"HOL-Library.Sublist\"\nbegin\n\nsubsection \\<open>CFG\\<close>\n\nlocale CFG_base = graph_Entry_base \\<alpha>e \\<alpha>n invar inEdges' Entry\nfor\n  \\<alpha>e :: \"'g \\<Rightarrow> ('node::linorder \\<times> 'edgeD \\<times> 'node) set\" and\n  \\<alpha>n :: \"'g \\<Rightarrow> 'node list\" and\n  invar :: \"'g \\<Rightarrow> bool\" and\n  inEdges' :: \"'g \\<Rightarrow> 'node \\<Rightarrow> ('node \\<times> 'edgeD) list\" and\n  Entry :: \"'g \\<Rightarrow> 'node\" +\nfixes \"defs\" :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'var::linorder set\"\nfixes \"uses\" :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'var set\"\nbegin\n  definition \"vars g \\<equiv> fold (\\<union>) (map (uses g) (\\<alpha>n g)) {}\"\n  definition defAss' :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'var \\<Rightarrow> bool\" where\n    \"defAss' g m v \\<longleftrightarrow> (\\<forall>ns. g \\<turnstile> Entry g-ns\\<rightarrow>m \\<longrightarrow> (\\<exists>n \\<in> set ns. v \\<in> defs g n))\"\n\n  definition defAss'Uses :: \"'g \\<Rightarrow> bool\" where\n    \"defAss'Uses g \\<equiv> \\<forall>m \\<in> set (\\<alpha>n g). \\<forall>v \\<in> uses g m. defAss' g m v\"\nend\n\nlocale CFG = CFG_base \\<alpha>e \\<alpha>n invar inEdges' Entry \"defs\" \"uses\"\n+ graph_Entry \\<alpha>e \\<alpha>n invar inEdges' Entry\nfor\n  \\<alpha>e :: \"'g \\<Rightarrow> ('node::linorder \\<times> 'edgeD \\<times> 'node) set\" and\n  \\<alpha>n :: \"'g \\<Rightarrow> 'node list\" and\n  invar :: \"'g \\<Rightarrow> bool\" and\n  inEdges' :: \"'g \\<Rightarrow> 'node \\<Rightarrow> ('node \\<times> 'edgeD) list\" and\n  Entry :: \"'g \\<Rightarrow> 'node\" and\n  \"defs\" :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'var::linorder set\" and\n  \"uses\" :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'var set\" +\nassumes defs_uses_disjoint: \"n \\<in> set (\\<alpha>n g) \\<Longrightarrow> defs g n \\<inter> uses g n = {}\"\nassumes defs_finite[simp]: \"finite (defs g n)\"\nassumes uses_in_\\<alpha>n: \"v \\<in> uses g n \\<Longrightarrow> n \\<in> set (\\<alpha>n g)\"\nassumes uses_finite[simp, intro!]: \"finite (uses g n)\"\nassumes invar[intro!]: \"invar g\"\nbegin\n  lemma vars_finite[simp]: \"finite (vars g)\"\n  by (auto simp:vars_def)\n\n  lemma Entry_no_predecessor[simp]: \"predecessors g (Entry g) = []\"\n  using Entry_unreachable\n  by (auto simp:predecessors_def)\n\n  lemma uses_in_vars[elim, simp]: \"v \\<in> uses g n \\<Longrightarrow>  v \\<in> vars g\"\n  by (auto simp add:vars_def uses_in_\\<alpha>n intro!: fold_union_elemI)\n\n  lemma varsE:\n    assumes \"v \\<in> vars g\"\n    obtains n where \"n \\<in> set (\\<alpha>n g)\" \"v \\<in> uses g n\"\n  using assms by (auto simp:vars_def elim!:fold_union_elem)\n\n  lemma defs_uses_disjoint'[simp]: \"n \\<in> set (\\<alpha>n g) \\<Longrightarrow> v \\<in> defs g n \\<Longrightarrow> v \\<in> uses g n \\<Longrightarrow> False\"\n  using defs_uses_disjoint by auto\nend\n\ncontext CFG\nbegin\n  lemma defAss'E:\n    assumes \"defAss' g m v\" \"g \\<turnstile> Entry g-ns\\<rightarrow>m\"\n    obtains n where \"n \\<in> set ns\" \"v \\<in> defs g n\"\n  using assms unfolding defAss'_def by auto\n\n  lemmas defAss'I = defAss'_def[THEN iffD2, rule_format]\n\n  lemma defAss'_extend:\n    assumes \"defAss' g m v\"\n    assumes \"g \\<turnstile> n-ns\\<rightarrow>m\" \"\\<forall>n \\<in> set (tl ns). v \\<notin> defs g n\"\n    shows \"defAss' g n v\"\n  unfolding defAss'_def proof (rule allI, rule impI)\n    fix ns'\n    assume \"g \\<turnstile> Entry g-ns'\\<rightarrow>n\"\n    with assms(2) have \"g \\<turnstile> Entry g-ns'@tl ns\\<rightarrow>m\" by auto\n    with assms(1) obtain n' where n': \"n' \\<in> set (ns'@tl ns)\" \"v \\<in> defs g n'\" by -(erule defAss'E)\n    with assms(3) have \"n' \\<notin> set (tl ns)\" by auto\n    with n' show \"\\<exists>n \\<in> set ns'. v \\<in> defs g n\" by auto\n  qed\nend\n\ntext \\<open>A CFG is well-formed if it satisfies definite assignment.\\<close>\n\nlocale CFG_wf = CFG \\<alpha>e \\<alpha>n invar inEdges' Entry \"defs\" \"uses\"\nfor\n  \\<alpha>e :: \"'g \\<Rightarrow> ('node::linorder \\<times> 'edgeD \\<times> 'node) set\" and\n  \\<alpha>n :: \"'g \\<Rightarrow> 'node list\" and\n  invar :: \"'g \\<Rightarrow> bool\" and\n  inEdges' :: \"'g \\<Rightarrow> 'node \\<Rightarrow> ('node \\<times> 'edgeD) list\" and\n  Entry::\"'g \\<Rightarrow> 'node\" and\n  \"defs\" :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'var::linorder set\" and\n  \"uses\" :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'var set\" +\nassumes def_ass_uses: \"\\<forall>m \\<in> set (\\<alpha>n g). \\<forall>v \\<in> uses g m. defAss' g m v\"\n\nsubsection \\<open>SSA CFG\\<close>\n\ntype_synonym ('node, 'val) phis = \"'node \\<times> 'val \\<rightharpoonup> 'val list\"\n\ndeclare in_set_zipE[elim]\ndeclare zip_same[simp]\n\nlocale CFG_SSA_base = CFG_base \\<alpha>e \\<alpha>n invar inEdges' Entry \"defs\" \"uses\"\nfor\n  \\<alpha>e :: \"'g \\<Rightarrow> ('node::linorder \\<times> 'edgeD \\<times> 'node) set\" and\n  \\<alpha>n :: \"'g \\<Rightarrow> 'node list\" and\n  invar :: \"'g \\<Rightarrow> bool\" and\n  inEdges' :: \"'g \\<Rightarrow> 'node \\<Rightarrow> ('node \\<times> 'edgeD) list\" and\n  Entry::\"'g \\<Rightarrow> 'node\" and\n  \"defs\" :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'val::linorder set\" and\n  \"uses\" :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'val set\" +\nfixes phis :: \"'g \\<Rightarrow> ('node, 'val) phis\"\nbegin\n  definition \"phiDefs g n \\<equiv> {v. (n,v) \\<in> dom (phis g)}\"\n  definition[code]: \"allDefs g n \\<equiv> defs g n \\<union> phiDefs g n\"\n\n  definition[code]: \"phiUses g n \\<equiv>\n    \\<Union>n' \\<in> set (successors g n). \\<Union>v' \\<in> phiDefs g n'. snd ` Set.filter (\\<lambda>(n'',v). n'' = n) (set (zip (predecessors g n') (the (phis g (n',v')))))\"\n  definition[code]: \"allUses g n \\<equiv> uses g n \\<union> phiUses g n\"\n  definition[code]: \"allVars g \\<equiv> \\<Union>n \\<in> set (\\<alpha>n g). allDefs g n \\<union> allUses g n\"\n\n  definition defAss :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'val \\<Rightarrow> bool\" where\n    \"defAss g m v \\<longleftrightarrow> (\\<forall>ns. g \\<turnstile> Entry g-ns\\<rightarrow>m \\<longrightarrow> (\\<exists>n \\<in> set ns. v \\<in> allDefs g n))\"\n\n  lemmas CFG_SSA_defs = phiDefs_def allDefs_def phiUses_def allUses_def allVars_def defAss_def\nend\n\nlocale CFG_SSA = CFG \\<alpha>e \\<alpha>n invar inEdges' Entry \"defs\" \"uses\" + CFG_SSA_base \\<alpha>e \\<alpha>n invar inEdges' Entry \"defs\" \"uses\" phis\nfor\n  \\<alpha>e :: \"'g \\<Rightarrow> ('node::linorder \\<times> 'edgeD \\<times> 'node) set\" and\n  \\<alpha>n :: \"'g \\<Rightarrow> 'node list\" and\n  invar :: \"'g \\<Rightarrow> bool\" and\n  inEdges' :: \"'g \\<Rightarrow> 'node \\<Rightarrow> ('node \\<times> 'edgeD) list\" and\n  Entry::\"'g \\<Rightarrow> 'node\" and\n  \"defs\" :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'val::linorder set\" and\n  \"uses\" :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'val set\" and\n   phis :: \"'g \\<Rightarrow> ('node, 'val) phis\" +\nassumes phis_finite: \"finite (dom (phis g))\"\nassumes phis_in_\\<alpha>n: \"phis g (n,v) = Some vs \\<Longrightarrow> n \\<in> set (\\<alpha>n g)\"\nassumes phis_wf:\n  \"phis g (n,v) = Some args \\<Longrightarrow> length (predecessors g n) = length args\"\nassumes simpleDefs_phiDefs_disjoint:             \n  \"n \\<in> set (\\<alpha>n g) \\<Longrightarrow> defs g n \\<inter> phiDefs g n = {}\"\nassumes allDefs_disjoint:\n  \"\\<lbrakk>n \\<in> set (\\<alpha>n g); m \\<in> set (\\<alpha>n g); n \\<noteq> m\\<rbrakk> \\<Longrightarrow> allDefs g n \\<inter> allDefs g m = {}\"\nbegin\n  lemma phis_disj:\n    assumes \"phis g (n,v) = Some vs\"\n    and \"phis g (n',v) = Some vs'\"\n    shows \"n = n'\" and \"vs = vs'\"\n  proof -\n    from assms have \"n \\<in> set (\\<alpha>n g)\" and \"n' \\<in> set (\\<alpha>n g)\"\n      by (auto dest: phis_in_\\<alpha>n)\n    from allDefs_disjoint [OF this] assms show \"n = n'\"\n      by (auto simp: allDefs_def phiDefs_def)\n    with assms show \"vs = vs'\" by simp\n  qed\n\n  lemma allDefs_disjoint': \"\\<lbrakk>n \\<in> set (\\<alpha>n g); m \\<in> set (\\<alpha>n g); v \\<in> allDefs g n; v \\<in> allDefs g m\\<rbrakk> \\<Longrightarrow> n = m\"\n  using allDefs_disjoint by auto\n\n  lemma phiUsesI:\n    assumes \"n' \\<in> set (\\<alpha>n g)\" \"phis g (n',v') = Some vs\" \"(n,v) \\<in> set (zip (predecessors g n') vs)\"\n    shows \"v \\<in> phiUses g n\"\n  proof-\n    from assms(3) have \"n \\<in> set (predecessors g n')\" by auto\n    hence 1: \"n' \\<in> set (successors g n)\" using assms(1) by simp\n    from assms(2) have 2: \"v' \\<in> phiDefs g n'\" by (auto simp add:phiDefs_def)\n    from assms(2) have 3: \"the (phis g (n',v')) = vs\" by simp\n    show ?thesis unfolding phiUses_def by (rule UN_I[OF 1], rule UN_I[OF 2], auto simp:image_def Set.filter_def assms(3) 3)\n  qed\n\n  lemma phiUsesE:\n    assumes \"v \\<in> phiUses g n\"\n    obtains  n' v' vs where \"n' \\<in> set (successors g n)\" \"(n,v) \\<in> set (zip (predecessors g n') vs)\" \"phis g (n', v') = Some vs\"\n  proof-\n    from assms(1) obtain n' v' where \"n'\\<in>set (successors g n)\" \"v'\\<in>phiDefs g n'\"\n      \"v \\<in> snd ` Set.filter (\\<lambda>(n'', v). n'' = n) (set (zip (predecessors g n') (the (phis g (n', v')))))\" by (auto simp:phiUses_def)\n    thus ?thesis by - (rule that[of n' \"the (phis g (n',v'))\" v'], auto simp:phiDefs_def)\n  qed\n\n  lemma defs_in_allDefs[simp]: \"v \\<in> defs g n \\<Longrightarrow> v \\<in> allDefs g n\" by (simp add:allDefs_def)\n  lemma phiDefs_in_allDefs[simp, elim]: \"v \\<in> phiDefs g n \\<Longrightarrow> v \\<in> allDefs g n\" by (simp add:allDefs_def)\n  \n\n  lemma phiDefs_finite[simp]: \"finite (phiDefs g n)\"\n  unfolding phiDefs_def\n  proof (rule finite_surj[where f=snd], rule phis_finite[where g=g])\n    have \"\\<And>x y. phis g (n,x) = Some y \\<Longrightarrow> x \\<in> snd ` dom (phis g)\" by (metis domI imageI snd_conv)\n    thus \"{v. (n, v) \\<in> dom (phis g)} \\<subseteq> snd ` dom (phis g)\" by auto\n  qed\n\n  lemma phiUses_finite[simp]:\n    assumes \"n \\<in> set (\\<alpha>n g)\"\n    shows \"finite (phiUses g n)\"\n  by (auto simp:phiUses_def Set.filter_def)\n\n  lemma allDefs_finite[simp]: \"n \\<in> set (\\<alpha>n g) \\<Longrightarrow> finite (allDefs g n)\" by (auto simp add:allDefs_def)\n  lemma allUses_finite[simp]: \"n \\<in> set (\\<alpha>n g) \\<Longrightarrow> finite (allUses g n)\" by (auto simp add:allUses_def)\n  lemma allVars_finite[simp]: \"finite (allVars g)\" by (auto simp add:allVars_def)\n\n  lemmas defAssI = defAss_def[THEN iffD2, rule_format]\n  lemmas defAssD = defAss_def[THEN iffD1, rule_format]\n\n  lemma defAss_extend:\n    assumes \"defAss g m v\"\n    assumes \"g \\<turnstile> n-ns\\<rightarrow>m\" \"\\<forall>n \\<in> set (tl ns). v \\<notin> allDefs g n\"\n    shows \"defAss g n v\"\n  unfolding defAss_def proof (rule allI, rule impI)\n    fix ns'\n    assume \"g \\<turnstile> Entry g-ns'\\<rightarrow>n\"\n    with assms(2) have \"g \\<turnstile> Entry g-ns'@tl ns\\<rightarrow>m\" by auto\n    with assms(1) obtain n' where n': \"n' \\<in> set (ns'@tl ns)\" \"v \\<in> allDefs g n'\" by (auto dest:defAssD)\n    with assms(3) have \"n' \\<notin> set (tl ns)\" by auto\n    with n' show \"\\<exists>n \\<in> set ns'. v \\<in> allDefs g n\" by auto\n  qed\n\n  lemma defAss_dominating:\n    assumes[simp]: \"n \\<in> set (\\<alpha>n g)\"\n    shows \"defAss g n v \\<longleftrightarrow> (\\<exists>m \\<in> set (\\<alpha>n g). dominates g m n \\<and> v \\<in> allDefs g m)\"\n  proof\n    assume asm: \"defAss g n v\"\n    obtain ns where ns: \"g \\<turnstile> Entry g-ns\\<rightarrow>n\" by (atomize, auto)\n    from defAssD[OF asm this] obtain m where m: \"m \\<in> set ns\" \"v \\<in> allDefs g m\" by auto\n    have \"dominates g m n\"\n    proof\n      fix ns'\n      assume ns': \"g \\<turnstile> Entry g-ns'\\<rightarrow>n\"\n      from defAssD[OF asm this] obtain m' where m': \"m' \\<in> set ns'\" \"v \\<in> allDefs g m'\" by auto\n      with m ns ns' have \"m' = m\" by - (rule allDefs_disjoint', auto)\n      with m' show \"m \\<in> set ns'\" by simp\n    qed simp\n    with m ns show \"\\<exists>m\\<in>set (\\<alpha>n g). dominates g m n \\<and> v \\<in> allDefs g m\" by auto\n  next\n    assume \"\\<exists>m \\<in> set (\\<alpha>n g). dominates g m n \\<and> v \\<in> allDefs g m\"\n    then obtain m where[simp]: \"m \\<in> set (\\<alpha>n g)\" and m: \"dominates g m n\" \"v \\<in> allDefs g m\" by auto\n    show \"defAss g n v\"\n    proof (rule defAssI)\n      fix ns\n      assume \"g \\<turnstile> Entry g-ns\\<rightarrow>n\"\n      with m(1) have \"m \\<in> set ns\" by - (rule dominates_mid, auto)\n      with m(2) show \"\\<exists>n\\<in>set ns. v \\<in> allDefs g n\" by auto\n    qed\n  qed\nend\n\nlocale CFG_SSA_wf_base = CFG_SSA_base \\<alpha>e \\<alpha>n invar inEdges' Entry \"defs\" \"uses\" phis\nfor\n  \\<alpha>e :: \"'g \\<Rightarrow> ('node::linorder \\<times> 'edgeD \\<times> 'node) set\" and\n  \\<alpha>n :: \"'g \\<Rightarrow> 'node list\" and\n  invar :: \"'g \\<Rightarrow> bool\" and\n  inEdges' :: \"'g \\<Rightarrow> 'node \\<Rightarrow> ('node \\<times> 'edgeD) list\" and\n  Entry::\"'g \\<Rightarrow> 'node\" and\n  \"defs\" :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'val::linorder set\" and\n  \"uses\" :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'val set\" and\n  phis :: \"'g \\<Rightarrow> ('node, 'val) phis\"\nbegin\n  text \\<open>Using the SSA properties, we can map every value to its unique defining node and\n    remove the @{typ 'node} parameter of the @{term phis} map.\\<close>\n\n  definition defNode :: \"'g \\<Rightarrow> 'val \\<Rightarrow> 'node\" where\n    defNode_code [code]: \"defNode g v \\<equiv> hd [n \\<leftarrow> \\<alpha>n g. v \\<in> allDefs g n]\"\n\n  abbreviation \"def_dominates g v' v \\<equiv> dominates g (defNode g v') (defNode g v)\"\n  abbreviation \"strict_def_dom g v' v \\<equiv> defNode g v' \\<noteq> defNode g v \\<and> def_dominates g v' v\"\n\n  definition \"phi g v = phis g (defNode g v,v)\"\n  definition[simp]: \"phiArg g v v' \\<equiv> \\<exists>vs. phi g v = Some vs \\<and> v' \\<in> set vs\"\n\n  definition[code]: \"isTrivialPhi g v v' \\<longleftrightarrow> v' \\<noteq> v \\<and>\n    (case phi g v of\n      Some vs \\<Rightarrow> set vs = {v,v'} \\<or> set vs = {v'}\n    | None \\<Rightarrow> False)\"\n  definition[code]: \"trivial g v \\<equiv> \\<exists>v' \\<in> allVars g. isTrivialPhi g v v'\"\n  definition[code]: \"redundant g \\<equiv> \\<exists>v \\<in> allVars g. trivial g v\"\n\n  definition \"defAssUses g \\<equiv> \\<forall>n \\<in> set (\\<alpha>n g). \\<forall>v \\<in> allUses g n. defAss g n v\"\n\n  text \\<open>'liveness' of an SSA value is defined inductively starting from simple uses so that\n    a circle of \\pf s is not considered live.\\<close>\n\n  declare [[inductive_internals]]\n  inductive liveVal :: \"'g \\<Rightarrow> 'val \\<Rightarrow> bool\"\n    for g :: 'g\n  where\n    liveSimple: \"\\<lbrakk>n \\<in> set (\\<alpha>n g); val \\<in> uses g n\\<rbrakk> \\<Longrightarrow> liveVal g val\"\n  | livePhi: \"\\<lbrakk>liveVal g v; phiArg g v v'\\<rbrakk> \\<Longrightarrow> liveVal g v'\"\n\n  definition \"pruned g = (\\<forall>n \\<in> set (\\<alpha>n g). \\<forall>val. val \\<in> phiDefs g n \\<longrightarrow> liveVal g val)\"\n\n  lemmas \"CFG_SSA_wf_defs\" = CFG_SSA_defs defNode_code phi_def isTrivialPhi_def trivial_def redundant_def liveVal_def pruned_def\nend\n\nlocale CFG_SSA_wf = CFG_SSA \\<alpha>e \\<alpha>n invar inEdges' Entry \"defs\" \"uses\" phis + CFG_SSA_wf_base \\<alpha>e \\<alpha>n invar inEdges' Entry \"defs\" \"uses\" phis\nfor\n  \\<alpha>e :: \"'g \\<Rightarrow> ('node::linorder \\<times> 'edgeD \\<times> 'node) set\" and\n  \\<alpha>n :: \"'g \\<Rightarrow> 'node list\" and\n  invar :: \"'g \\<Rightarrow> bool\" and\n  inEdges' :: \"'g \\<Rightarrow> 'node \\<Rightarrow> ('node \\<times> 'edgeD) list\" and\n  Entry::\"'g \\<Rightarrow> 'node\" and\n  \"defs\" :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'val::linorder set\" and\n  \"uses\" :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'val set\" and\n  phis :: \"'g \\<Rightarrow> ('node, 'val) phis\" +\n  assumes allUses_def_ass: \"\\<lbrakk>v \\<in> allUses g n; n \\<in> set (\\<alpha>n g)\\<rbrakk> \\<Longrightarrow> defAss g n v\"\n  assumes Entry_no_phis[simp]: \"phis g (Entry g,v) = None\"\nbegin\n  lemma allVars_in_allDefs: \"v \\<in> allVars g \\<Longrightarrow> \\<exists>n \\<in> set (\\<alpha>n g). v \\<in> allDefs g n\"\n    unfolding allVars_def\n  apply auto\n  apply (drule(1) allUses_def_ass)\n  apply (clarsimp simp: defAss_def)\n  apply (drule Entry_reaches)\n   apply auto[1]\n  by fastforce\n\n  lemma phiDefs_Entry_empty[simp]: \"phiDefs g (Entry g) = {}\"\n  by (auto simp: phiDefs_def)\n\n  lemma phi_Entry_empty[simp]: \"defNode g v = Entry g \\<Longrightarrow> phi g v = None\"\n    by (simp add:phi_def)\n\n  lemma defNode_ex1:\n    assumes \"v \\<in> allVars g\"\n    shows \"\\<exists>!n. n \\<in> set (\\<alpha>n g) \\<and> v \\<in> allDefs g n\"\n  proof (rule ex_ex1I)\n    show \"\\<exists>n. n \\<in> set (\\<alpha>n g) \\<and> v \\<in> allDefs g n\"\n    proof-\n      from assms(1) obtain n where n: \"n \\<in> set (\\<alpha>n g)\" \"v \\<in> allDefs g n \\<or> v \\<in> allUses g n\" by (auto simp:allVars_def)\n      thus ?thesis\n      proof (cases \"v \\<in> allUses g n\")\n        case True\n        from n(1) obtain ns where ns: \"g \\<turnstile> Entry g-ns\\<rightarrow>n\" by (atomize_elim, rule Entry_reaches, auto)\n        with allUses_def_ass[OF True n(1)] obtain m where m: \"m \\<in> set ns\" \"v \\<in> allDefs g m\" by - (drule defAssD, auto)\n        from ns this(1) have \"m \\<in> set (\\<alpha>n g)\" by (rule path2_in_\\<alpha>n)\n        with n(1) m show ?thesis by auto\n      qed auto\n    qed\n    show \"\\<And>n m. n \\<in> set (\\<alpha>n g) \\<and> v \\<in> allDefs g n \\<Longrightarrow> m \\<in> set (\\<alpha>n g) \\<and> v \\<in> allDefs g m \\<Longrightarrow> n = m\" using allDefs_disjoint by auto\n  qed\n\n  lemma defNode_def: \"v \\<in> allVars g \\<Longrightarrow> defNode g v = (THE n. n \\<in> set (\\<alpha>n g) \\<and> v \\<in> allDefs g n)\"\n  unfolding defNode_code by (rule the1_list[symmetric], rule defNode_ex1)\n\n  lemma defNode[simp]:\n    assumes \"v \\<in> allVars g\"\n    shows  \"(defNode g v) \\<in> set (\\<alpha>n g)\" \"v \\<in> allDefs g (defNode g v)\"\n  apply (atomize(full))\n  unfolding defNode_def[OF assms] using assms\n  by - (rule theI', rule defNode_ex1)\n\n  lemma defNode_eq[intro]:\n    assumes \"n \\<in> set (\\<alpha>n g)\" \"v \\<in> allDefs g n\"\n    shows \"defNode g v = n\"\n  apply (subst defNode_def, rule allDefs_in_allVars[OF assms(2) assms(1)])\n  by (rule the1_equality, rule defNode_ex1, rule allDefs_in_allVars[where n=n], simp_all add:assms)\n\n  lemma defNode_cases[consumes 1]:\n    assumes \"v \\<in> allVars g\"\n    obtains (simpleDef) \"v \\<in> defs g (defNode g v)\"\n          | (phi)       \"phi g v \\<noteq> None\"\n  proof (cases \"v \\<in> defs g (defNode g v)\")\n    case True\n    thus thesis by (rule simpleDef)\n  next\n    case False\n    with assms[THEN defNode(2)] show thesis\n      by - (rule phi, auto simp: allDefs_def phiDefs_def phi_def)\n  qed\n\n  lemma phi_phiDefs[simp]: \"phi g v = Some vs \\<Longrightarrow> v \\<in> phiDefs g (defNode g v)\" by (auto simp:phiDefs_def phi_def)\n\n  lemma simpleDef_not_phi:\n    assumes \"n \\<in> set (\\<alpha>n g)\" \"v \\<in> defs g n\"\n    shows \"phi g v = None\"\n  proof-\n    from assms have \"defNode g v = n\" by auto\n    with assms show ?thesis using simpleDefs_phiDefs_disjoint by (auto simp: phi_def phiDefs_def)\n  qed\n\n  lemma phi_wf: \"phi g v = Some vs \\<Longrightarrow> length (predecessors g (defNode g v)) = length vs\"\n  by (rule phis_wf) (simp add:phi_def)\n\n  lemma phi_finite: \"finite (dom (phi g))\"\n  proof-\n    let ?f = \"\\<lambda>v. (defNode g v,v)\"\n    have \"phi g = phis g \\<circ> ?f\" by (auto simp add:phi_def)\n    moreover have \"inj ?f\" by (auto intro:injI)\n    hence \"finite (dom (phis g \\<circ> ?f))\" by - (rule finite_dom_comp, auto simp add:phis_finite inj_on_def)\n    ultimately show ?thesis by simp\n  qed\n\n  lemma phiUses_exI:\n    assumes \"m \\<in> set (predecessors g n)\" \"phis g (n,v) = Some vs\" \"n \\<in> set (\\<alpha>n g)\"\n    obtains v' where \"v' \\<in> phiUses g m\" \"v' \\<in> set vs\"\n  proof-\n    from assms(1) obtain i where i: \"m = predecessors g n ! i\" \"i < length (predecessors g n)\" by (metis in_set_conv_nth)\n    with assms(2) phis_wf have[simp]: \"i < length vs\" by (auto simp add:phi_def)\n    from i assms(2,3) have \"vs ! i \\<in> phiUses g m\" by - (rule phiUsesI, auto simp add:phiUses_def phi_def set_zip)\n    thus thesis by (rule that) (auto simp add:i(2) phis_wf)\n  qed\n\n  lemma phiArg_exI:\n    assumes \"m \\<in> set (predecessors g (defNode g v))\" \"phi g v \\<noteq> None\" and[simp]: \"v \\<in> allVars g\"\n    obtains v' where \"v' \\<in> phiUses g m\" \"phiArg g v v'\"\n  proof-\n    from assms(2) obtain vs where \"phi g v = Some vs\" by auto\n    with assms(1) show thesis\n      by - (rule phiUses_exI, auto intro!:that simp: phi_def)\n  qed\n\n  lemma phiUses_exI':\n    assumes \"phiArg g p q\" and[simp]: \"p \\<in> allVars g\"\n    obtains m where \"q \\<in> phiUses g m\" \"m \\<in> set (predecessors g (defNode g p))\"\n  proof-\n    let ?n = \"defNode g p\"\n    from assms(1) obtain i vs where vs: \"phi g p = Some vs\" and i: \"q = vs ! i\" \"i < length vs\" by (metis in_set_conv_nth phiArg_def)\n    with phis_wf have[simp]: \"i < length (predecessors g ?n)\" by (auto simp add:phi_def)\n    from vs i have \"q \\<in> phiUses g (predecessors g ?n ! i)\" by - (rule phiUsesI, auto simp add:phiUses_def phi_def set_zip)\n    thus thesis by (rule that) (auto simp add:i(2) phis_wf)\n  qed\n\n  lemma phiArg_in_allVars[simp]:\n    assumes \"phiArg g v v'\"\n    shows \"v' \\<in> allVars g\"\n  proof-\n    let ?n = \"defNode g v\"\n    from assms(1) obtain vs where vs: \"phi g v = Some vs\" \"v' \\<in> set vs\" by auto\n    then obtain m where m: \"(m,v') \\<in> set (zip (predecessors g ?n) vs)\" by - (rule set_zip_leftI, rule phi_wf)\n    from vs(1) have n: \"?n \\<in> set (\\<alpha>n g)\" by (simp add: phi_def phis_in_\\<alpha>n)\n    with m have[simp]: \"m \\<in> set (\\<alpha>n g)\" by auto\n    from n m vs have \"v' \\<in> phiUses g m\" by - (rule phiUsesI, simp_all add:phi_def)\n    thus ?thesis by - (rule allUses_in_allVars, auto simp:allUses_def)\n  qed\n\n  lemma defAss_defNode:\n    assumes \"defAss g m v\" \"v \\<in> allVars g\" \"g \\<turnstile> Entry g-ns\\<rightarrow>m\"\n    shows \"defNode g v \\<in> set ns\"\n  proof-\n    from assms obtain n where n: \"n \\<in> set ns\" \"v \\<in> allDefs g n\" by (auto simp:defAss_def)\n    with assms(3) have \"n = defNode g v\" by - (rule defNode_eq[symmetric], auto)\n    with n show \"defNode g v \\<in> set ns\" by (simp add:defAss_def)\n  qed\n\n  lemma defUse_path_ex:\n    assumes \"v \\<in> allUses g m\" \"m \\<in> set (\\<alpha>n g)\"\n    obtains ns where \"g \\<turnstile> defNode g v-ns\\<rightarrow>m\" \"EntryPath g ns\"\n  proof-\n    from assms have \"defAss g m v\" by - (rule allUses_def_ass, auto)\n    moreover from assms obtain ns where ns: \"g \\<turnstile> Entry g-ns\\<rightarrow>m\" \"EntryPath g ns\"\n      by - (atomize_elim, rule Entry_reachesE, auto)\n    ultimately have \"defNode g v \\<in> set ns\" using assms(1)\n      by - (rule defAss_defNode, auto)\n    with ns(1) obtain ns' where \"g \\<turnstile> defNode g v-ns'\\<rightarrow>m\" \"suffix ns' ns\"\n      by (rule path2_split_ex', auto simp: Sublist.suffix_def)\n    thus thesis using ns(2)\n      by - (rule that, assumption, rule EntryPath_suffix, auto)\n  qed\n\n  lemma defUse_path_dominated:\n    assumes \"g \\<turnstile> defNode g v-ns\\<rightarrow>n\" \"defNode g v \\<notin> set (tl ns)\" \"v \\<in> allUses g n\" \"n' \\<in> set ns\"\n    shows \"dominates g (defNode g v) n'\"\n  proof (rule dominatesI)\n    fix es\n    assume asm: \"g \\<turnstile> Entry g-es\\<rightarrow>n'\"\n    from assms(1,4) obtain ns' where ns': \"g \\<turnstile> n'-ns'\\<rightarrow>n\" \"suffix ns' ns\"\n      by - (rule path2_split_ex, auto simp: Sublist.suffix_def)\n    from assms have \"defAss g n v\" by - (rule allUses_def_ass, auto)\n    with asm ns'(1) assms(3) have \"defNode g v \\<in> set (es@tl ns')\" by - (rule defAss_defNode, auto)\n    with suffix_tl_subset[OF ns'(2)] assms(2) show \"defNode g v \\<in> set es\" by auto\n  next\n    show \"n' \\<in> set (\\<alpha>n g)\" using assms(1,4) by auto\n  qed\n\n  lemma allUses_dominated:\n    assumes \"v \\<in> allUses g n\" \"n \\<in> set (\\<alpha>n g)\"\n    shows \"dominates g (defNode g v) n\"\n  proof-\n    from assms obtain ns where \"g \\<turnstile> defNode g v-ns\\<rightarrow>n\" \"defNode g v \\<notin> set (tl ns)\"\n      by - (rule defUse_path_ex, auto elim: simple_path2)\n    with assms(1) show ?thesis by - (rule defUse_path_dominated, auto)\n  qed\n\n  lemma phiArg_path_ex':\n    assumes \"phiArg g p q\" and[simp]: \"p \\<in> allVars g\"\n    obtains ns m where \"g \\<turnstile> defNode g q-ns\\<rightarrow>m\" \"EntryPath g ns\" \"q \\<in> phiUses g m\" \"m \\<in> set (predecessors g (defNode g p))\"\n  proof-\n    from assms obtain m where m: \"q \\<in> phiUses g m\" \"m \\<in> set (predecessors g (defNode g p))\"\n      by (rule phiUses_exI')\n    then obtain ns where \"g \\<turnstile> defNode g q-ns\\<rightarrow>m\" \"EntryPath g ns\" by - (rule defUse_path_ex, auto)\n    with m show thesis by - (rule that)\n  qed\n\n  lemma phiArg_path_ex:\n    assumes \"phiArg g p q\" and[simp]: \"p \\<in> allVars g\"\n    obtains ns where \"g \\<turnstile> defNode g q-ns\\<rightarrow>defNode g p\" \"length ns > 1\"\n    by (rule phiArg_path_ex'[OF assms], rule, auto)\n\n  lemma phiArg_tranclp_path_ex:\n    assumes \"r\\<^sup>+\\<^sup>+ p q\" \"p \\<in> allVars g\" and[simp]: \"\\<And>p q. r p q \\<Longrightarrow> phiArg g p q\"\n    obtains ns where \"g \\<turnstile> defNode g q-ns\\<rightarrow>defNode g p\" \"length ns > 1\"\n      \"\\<forall>n \\<in> set (butlast ns). \\<exists>p q m ns'. r p q \\<and> g \\<turnstile> defNode g q-ns'\\<rightarrow>m \\<and> (defNode g q) \\<notin> set (tl ns') \\<and> q \\<in> phiUses g m \\<and> m \\<in> set (predecessors g (defNode g p)) \\<and> n \\<in> set ns' \\<and> set ns' \\<subseteq> set ns \\<and> defNode g p \\<in> set ns\"\n  using assms(1,2) proof (induction rule: converse_tranclp_induct)\n    case (base p)\n    from base.hyps base.prems(2) obtain ns' m where ns': \"g \\<turnstile> defNode g q-ns'\\<rightarrow>m\" \"defNode g q \\<notin> set (tl ns')\" \"m \\<in> set (predecessors g (defNode g p))\" \"q \\<in> phiUses g m\"\n      by - (rule phiArg_path_ex', rule assms(3), auto intro: simple_path2)\n    hence ns: \"g \\<turnstile> defNode g q-ns'@[defNode g p]\\<rightarrow>defNode g p\" \"length (ns'@[defNode g p]) > 1\" by auto\n\n    show ?case\n    proof (rule base.prems(1)[OF ns, rule_format], rule exI, rule exI, rule exI, rule exI)\n      fix n\n      assume \"n \\<in> set (butlast (ns' @ [defNode g p]))\"\n      with base.hyps ns'\n      show \"r p q \\<and>\n          g \\<turnstile> defNode g q-ns'\\<rightarrow>m \\<and>\n          defNode g q \\<notin> set (tl ns') \\<and>\n          q \\<in> phiUses g m \\<and>\n          m \\<in> set (predecessors g (defNode g p)) \\<and> n \\<in> set ns' \\<and> set ns' \\<subseteq> set (ns' @ [defNode g p]) \\<and> defNode g p \\<in> set (ns' @ [defNode g p])\"\n        by auto\n    qed\n  next\n    case (step p p')\n    from step.prems(2) step.hyps(1) obtain ns'\\<^sub>2 m where ns'\\<^sub>2: \"g \\<turnstile> defNode g p'-ns'\\<^sub>2\\<rightarrow>m\" \"m \\<in> set (predecessors g (defNode g p))\" \"defNode g p' \\<notin> set (tl ns'\\<^sub>2)\" \"p' \\<in> phiUses g m\"\n      by - (rule phiArg_path_ex', rule assms(3), auto intro: simple_path2)\n    then obtain ns\\<^sub>2 where ns\\<^sub>2: \"g \\<turnstile> defNode g p'-ns\\<^sub>2\\<rightarrow>defNode g p\" \"length ns\\<^sub>2 > 1\" \"ns\\<^sub>2 = ns'\\<^sub>2@[defNode g p]\" by (atomize_elim, auto)\n\n    show thesis\n    proof (rule step.IH)\n      fix ns\n      assume ns: \"g \\<turnstile> defNode g q-ns\\<rightarrow>defNode g p'\" \"1 < length ns\"\n      assume IH: \"\\<forall>n\\<in>set (butlast ns).\n             \\<exists>p q m ns'.\n                r p q \\<and>\n                g \\<turnstile> defNode g q-ns'\\<rightarrow>m \\<and>\n                defNode g q \\<notin> set (tl ns') \\<and>\n                q \\<in> phiUses g m \\<and> m \\<in> set (predecessors g (defNode g p)) \\<and> n \\<in> set ns' \\<and> set ns' \\<subseteq> set ns \\<and> defNode g p \\<in> set ns\"\n\n      let ?path = \"ns@tl ns\\<^sub>2\"\n      have ns_ns\\<^sub>2: \"g \\<turnstile> defNode g q-?path\\<rightarrow>defNode g p\" \"1 < length ?path\" using ns ns\\<^sub>2(1,2) by auto\n      show thesis\n      proof (rule step.prems(1)[OF ns_ns\\<^sub>2, rule_format])\n        fix n\n        assume n: \"n \\<in> set (butlast ?path)\"\n        show \"\\<exists>p q m ns'a.\n          r p q \\<and>\n          g \\<turnstile> defNode g q-ns'a\\<rightarrow>m \\<and>\n          defNode g q \\<notin> set (tl ns'a) \\<and>\n          q \\<in> phiUses g m \\<and> m \\<in> set (predecessors g (defNode g p)) \\<and> n \\<in> set ns'a \\<and> set ns'a \\<subseteq> set ?path \\<and> defNode g p \\<in> set ?path\"\n        proof (cases \"n \\<in> set (butlast ns)\")\n          case True\n          with IH obtain p q m ns' where \"\n                r p q \\<and>\n                g \\<turnstile> defNode g q-ns'\\<rightarrow>m \\<and>\n                defNode g q \\<notin> set (tl ns') \\<and>\n                q \\<in> phiUses g m \\<and> m \\<in> set (predecessors g (defNode g p)) \\<and> n \\<in> set ns' \\<and> set ns' \\<subseteq> set ns \\<and> defNode g p \\<in> set ns\" by auto\n          thus ?thesis by - (rule exI, rule exI, rule exI, rule exI, auto)\n        next\n          case False\n          from ns ns\\<^sub>2 have 1: \"?path = butlast ns@ns\\<^sub>2\"\n            by - (rule concat_join[symmetric], auto simp: path2_def)\n          from ns\\<^sub>2(1) n False 1 have \"n \\<in> set (butlast ns\\<^sub>2)\" by (auto simp: butlast_append path2_not_Nil)\n          with step.hyps ns'\\<^sub>2 ns\\<^sub>2(3) show ?thesis\n            by - (subst 1, rule exI[where x=p], rule exI[where x=p'], rule exI, rule exI, auto simp: path2_not_Nil)\n        qed\n      qed\n    next\n      show \"p' \\<in> allVars g\" using step.prems(2) step.hyps(1)[THEN assms(3)] by auto\n    qed\n  qed\n\n  lemma non_dominated_predecessor:\n    assumes \"n \\<in> set (\\<alpha>n g)\" \"n \\<noteq> Entry g\"\n    obtains m where \"m \\<in> set (predecessors g n)\" \"\\<not>dominates g n m\"\n  proof-\n    obtain ns where \"g \\<turnstile> Entry g-ns\\<rightarrow>n\"\n      by (atomize_elim, rule Entry_reaches, auto simp add:assms(1))\n    then obtain ns' where ns': \"g \\<turnstile> Entry g-ns'\\<rightarrow>n\" \"n \\<notin> set (butlast ns')\"\n      by (rule simple_path2)\n    let ?m = \"last (butlast ns')\"\n    from ns'(1) assms(2) obtain m: \"g \\<turnstile> Entry g-butlast ns'\\<rightarrow>?m\" \"?m \\<in> set (predecessors g n)\"\n      by - (rule path2_unsnoc, auto)\n    with m(1) ns'(2) show thesis\n      by - (rule that, auto elim:dominatesE)\n  qed\n\n  lemmas dominates_trans'[trans, elim] = dominates_trans[OF invar]\n  lemmas strict_dom_trans'[trans, elim] = strict_dom_trans[OF invar]\n  lemmas dominates_refl'[simp] = dominates_refl[OF invar]\n  lemmas dominates_antisymm'[dest] = dominates_antisymm[OF invar]\n\n  lemma liveVal_in_allVars[simp]: \"liveVal g v \\<Longrightarrow> v \\<in> allVars g\"\n  by (induction rule: liveVal.induct, auto intro!: allUses_in_allVars)\n\n  lemma phi_no_closed_loop:\n    assumes[simp]: \"p \\<in> allVars g\" and \"phi g p = Some vs\"\n    shows \"set vs \\<noteq> {p}\"\n  proof (cases \"defNode g p = Entry g\")\n    case True\n    with assms(2) show ?thesis by auto\n  next\n    case False\n    show ?thesis\n    proof\n      assume[simp]: \"set vs = {p}\"\n      let ?n = \"defNode g p\"\n      obtain ns where ns: \"g \\<turnstile> Entry g-ns\\<rightarrow>?n\" \"?n \\<notin> set (butlast ns)\" by (rule simple_Entry_path, auto)\n      let ?m = \"last (butlast ns)\"\n      from ns False obtain m: \"g \\<turnstile> Entry g-butlast ns\\<rightarrow>?m\" \"?m \\<in> set (predecessors g ?n)\"\n        by - (rule path2_unsnoc, auto)\n      hence \"p \\<in> phiUses g ?m\" using assms(2) by - (rule phiUses_exI, auto simp:phi_def)\n      hence \"defAss g ?m p\" using m by - (rule allUses_def_ass, auto)\n      then obtain l where l: \"l \\<in> set (butlast ns)\" \"p \\<in> allDefs g l\" using m by - (drule defAssD, auto)\n      with assms(2) m have \"l = ?n\" by - (rule allDefs_disjoint', auto)\n      with ns l m show False by auto\n    qed\n  qed\n\n  lemma phis_phi: \"phis g (n, v) = Some vs \\<Longrightarrow> phi g v = Some vs\"\n  unfolding phi_def\n  apply (subst defNode_eq)\n  by (auto simp: allDefs_def phi_def phiDefs_def intro: phis_in_\\<alpha>n)\n\n  lemma trivial_phi: \"trivial g v \\<Longrightarrow> phi g v \\<noteq> None\"\n  by (auto simp: trivial_def isTrivialPhi_def split: option.splits)\n\n  lemma trivial_finite: \"finite {v. trivial g v}\"\n  by (rule finite_subset[OF _ phi_finite]) (auto dest: trivial_phi)\n\n  lemma trivial_in_allVars: \"trivial g v \\<Longrightarrow> v \\<in> allVars g\"\n  by (drule trivial_phi, auto simp: allDefs_def phiDefs_def image_def phi_def intro: phis_in_\\<alpha>n intro!: allDefs_in_allVars)\n\n  declare phiArg_def [simp del]\nend\n\nsubsection \\<open>Bundling of CFG and Equivalent SSA CFG\\<close>\n\nlocale CFG_SSA_Transformed_base = old: CFG_base \\<alpha>e \\<alpha>n invar inEdges' Entry oldDefs oldUses + CFG_SSA_wf_base \\<alpha>e \\<alpha>n invar inEdges' Entry \"defs\" \"uses\" phis\nfor\n  \\<alpha>e :: \"'g \\<Rightarrow> ('node::linorder \\<times> 'edgeD \\<times> 'node) set\" and\n  \\<alpha>n :: \"'g \\<Rightarrow> 'node list\" and\n  invar :: \"'g \\<Rightarrow> bool\" and\n  inEdges' :: \"'g \\<Rightarrow> 'node \\<Rightarrow> ('node \\<times> 'edgeD) list\" and\n  Entry::\"'g \\<Rightarrow> 'node\" and\n  oldDefs :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'var::linorder set\" and\n  oldUses :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'var set\" and\n  \"defs\" :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'val::linorder set\" and\n  \"uses\" :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'val set\" and\n  phis :: \"'g \\<Rightarrow> ('node, 'val) phis\" +\n  fixes var :: \"'g \\<Rightarrow> 'val \\<Rightarrow> 'var\"\n\nlocale CFG_SSA_Transformed = CFG_SSA_Transformed_base \\<alpha>e \\<alpha>n invar inEdges' Entry oldDefs oldUses \"defs\" \"uses\" phis var\n  + old: CFG_wf \\<alpha>e \\<alpha>n invar inEdges' Entry oldDefs oldUses + CFG_SSA_wf \\<alpha>e \\<alpha>n invar inEdges' Entry \"defs\" \"uses\" phis\nfor\n  \\<alpha>e :: \"'g \\<Rightarrow> ('node::linorder \\<times> 'edgeD \\<times> 'node) set\" and\n  \\<alpha>n :: \"'g \\<Rightarrow> 'node list\" and\n  invar :: \"'g \\<Rightarrow> bool\" and\n  inEdges' :: \"'g \\<Rightarrow> 'node \\<Rightarrow> ('node \\<times> 'edgeD) list\" and\n  Entry::\"'g \\<Rightarrow> 'node\" and\n  oldDefs :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'var::linorder set\" and\n  oldUses :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'var set\" and\n  \"defs\" :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'val::linorder set\" and\n  \"uses\" :: \"'g \\<Rightarrow> 'node \\<Rightarrow> 'val set\" and\n  phis :: \"'g \\<Rightarrow> ('node, 'val) phis\" and\n  var :: \"'g \\<Rightarrow> 'val \\<Rightarrow> 'var\" +\n  assumes oldDefs_def: \"oldDefs g n = var g ` defs g n\"\n  assumes oldUses_def: \"n \\<in> set (\\<alpha>n g) \\<Longrightarrow> oldUses g n = var g ` uses g n\"\n  assumes conventional: \"\n\\<lbrakk>g \\<turnstile> n-ns\\<rightarrow>m; n \\<notin> set (tl ns); v \\<in> allDefs g n; v \\<in> allUses g m; x \\<in> set (tl ns); v' \\<in> allDefs g x\\<rbrakk> \\<Longrightarrow> var g v' \\<noteq> var g v\"\n  assumes phis_same_var[elim]: \"phis g (n,v) = Some vs \\<Longrightarrow> v' \\<in> set vs \\<Longrightarrow> var g v' = var g v\"\n  assumes allDefs_var_disjoint: \"\\<lbrakk>n \\<in> set (\\<alpha>n g); v \\<in> allDefs g n; v' \\<in> allDefs g n; v \\<noteq> v'\\<rbrakk> \\<Longrightarrow> var g v' \\<noteq> var g v\"\nbegin\n  lemma conventional': \"\\<lbrakk>g \\<turnstile> n-ns\\<rightarrow>m; n \\<notin> set (tl ns); v \\<in> allDefs g n; v \\<in> allUses g m; v' \\<in> allDefs g x; var g v' = var g v\\<rbrakk> \\<Longrightarrow> x \\<notin> set (tl ns)\"\n    using conventional by auto\n\n  lemma conventional'': \"\\<lbrakk>g \\<turnstile> defNode g v-ns\\<rightarrow>m; defNode g v \\<notin> set (tl ns); v \\<in> allUses g m; var g v' = var g v; v \\<in> allVars g; v' \\<in> allVars g\\<rbrakk> \\<Longrightarrow> defNode g v' \\<notin> set (tl ns)\"\n    by (rule conventional'[where v=v and v'=v'], auto)\n\n  lemma phiArg_same_var: \"phiArg g p q \\<Longrightarrow> var g q = var g p\"\n    by (metis phiArg_def phi_def phis_same_var)\n\n  lemma oldDef_defAss:\n    assumes \"v \\<in> allUses g n\" \"g \\<turnstile> Entry g-ns\\<rightarrow>n\"\n    obtains m where \"m \\<in> set ns\" \"var g v \\<in> oldDefs g m\"\n  using assms proof (induction ns arbitrary: v n rule: length_induct)\n    case (1 ns)\n    from \"1.prems\"(2-) have 2: \"defNode g v \\<in> set ns\"\n      by - (rule defAss_defNode, rule allUses_def_ass, auto)\n    let ?V = \"defNode g v\"\n    from \"1.prems\"(2,3) have[simp]: \"v \\<in> allVars g\" by auto\n    thus ?case\n    proof (cases v rule: defNode_cases)\n      case simpleDef\n      with 2 show thesis by - (rule \"1.prems\"(1), auto simp: oldDefs_def)\n    next\n      case phi\n      then obtain vs where vs: \"phi g v = Some vs\" by auto\n      from \"1.prems\"(3) 2 obtain ns' where ns': \"g \\<turnstile> Entry g-ns'\\<rightarrow>?V\" \"prefix ns' ns\"\n        by (rule old.path2_split_ex, auto)\n      let ?V' = \"last (butlast ns')\"\n      from ns' phi have nontriv: \"length ns' \\<ge> 2\"\n        by - (rule old.path2_nontrivial, auto)\n      hence 3: \"g \\<turnstile> Entry g-butlast ns'\\<rightarrow>?V'\" \"?V' \\<in> set (old.predecessors g ?V)\"\n        using ns'(1) by (auto intro: old.path2_unsnoc)\n      with phi vs obtain v' where v': \"v' \\<in> phiUses g ?V'\" \"var g v' = var g v\"\n        by - (rule phiArg_exI, auto simp: phi_def phis_same_var phiArg_def)\n      show thesis\n      proof (rule \"1.IH\"[rule_format])\n        show \"length (butlast ns') < length ns\" using ns' by (cases ns', auto simp: old.path2_not_Nil2 dest: prefix_length_le)\n        show \"v' \\<in> allUses g ?V'\" using v'(1) by simp\n      next\n        fix n\n        assume \"n \\<in> set (butlast ns')\" \"var g v' \\<in> oldDefs g n\"\n        thus thesis\n          using ns'(2)[THEN set_mono_prefix] v'(2) by - (rule \"1.prems\"(1)[of n], auto dest: in_set_butlastD)\n      qed (rule 3(1))\n    qed\n  qed\n\n  lemma allDef_path_from_simpleDef:\n    assumes[simp]: \"v \\<in> allVars g\"\n    obtains n ns where \"g \\<turnstile> n-ns\\<rightarrow>defNode g v\" \"old.EntryPath g ns\" \"var g v \\<in> oldDefs g n\"\n  proof-\n    let ?V = \"defNode g v\"\n    from assms obtain ns where ns: \"g \\<turnstile> Entry g-ns\\<rightarrow>?V\" \"old.EntryPath g ns\"\n      by - (rule old.Entry_reachesE, auto)\n    from assms show thesis\n    proof (cases v rule: defNode_cases)\n      case simpleDef\n      thus thesis by - (rule that, auto simp: oldDefs_def)\n    next\n      case phi\n      then obtain vs where vs: \"phi g v = Some vs\" by auto\n      let ?V' = \"last (butlast ns)\"\n      from ns phi have nontriv: \"length ns \\<ge> 2\"\n        by - (rule old.path2_nontrivial, auto)\n      hence 3: \"g \\<turnstile> Entry g-butlast ns\\<rightarrow>?V'\" \"?V' \\<in> set (old.predecessors g ?V)\"\n        using ns(1) by (auto intro: old.path2_unsnoc)\n      with phi vs obtain v' where v': \"v' \\<in> phiUses g ?V'\" \"var g v' = var g v\"\n        by - (rule phiArg_exI, auto simp: phi_def phis_same_var phiArg_def)\n      with 3(1) obtain n where n: \"n \\<in> set (butlast ns)\" \"var g v' \\<in> oldDefs g n\"\n        by - (rule oldDef_defAss[of v' g], auto)\n      with ns obtain ns' where \"g \\<turnstile> n-ns'\\<rightarrow>?V\" \"suffix ns' ns\"\n        by - (rule old.path2_split_ex'[OF ns(1)], auto intro: in_set_butlastD simp: Sublist.suffix_def)\n      with n(2) v'(2) ns(2) show thesis\n        by - (rule that, assumption, erule old.EntryPath_suffix, auto)\n    qed\n  qed\n\n  lemma defNode_var_disjoint:\n    assumes \"p \\<in> allVars g\" \"q \\<in> allVars g\" \"p \\<noteq> q\" \"defNode g p = defNode g q\"\n    shows \"var g p \\<noteq> var g q\"\n  proof-\n    have \"q \\<in> allDefs g (defNode g p)\" using assms(2) assms(4) by (auto)\n    thus ?thesis using assms(1-3)\n      by - (rule allDefs_var_disjoint[of \"defNode g p\" g], auto)\n  qed\n\n  lemma phiArg_distinct_nodes:\n    assumes \"phiArg g p q\" \"p \\<noteq> q\" and[simp]: \"p \\<in> allVars g\"\n    shows \"defNode g p \\<noteq> defNode g q\"\n  proof\n    have \"p \\<in> allDefs g (defNode g p)\" by simp\n    moreover assume \"defNode g p = defNode g q\"\n    ultimately have \"var g p \\<noteq> var g q\" using assms\n      by - (rule defNode_var_disjoint, auto)\n    moreover\n    from assms(1) have \"var g q = var g p\" by (rule phiArg_same_var)\n    ultimately show False by simp\n  qed\n\n  lemma phiArgs_def_distinct:\n    assumes \"phiArg g p q\" \"phiArg g p r\" \"q \\<noteq> r\" \"p \\<in> allVars g\"\n    shows \"defNode g q \\<noteq> defNode g r\"\n  proof (rule)\n    assume \"defNode g q = defNode g r\"\n    hence \"var g q \\<noteq> var g r\" using assms by - (rule defNode_var_disjoint, auto)\n    thus False using phiArg_same_var[OF assms(1)] phiArg_same_var[OF assms(2)] by simp\n  qed\n\n  lemma defNode_not_on_defUse_path:\n    assumes p: \"g \\<turnstile> defNode g p-ns\\<rightarrow>n\" \"defNode g p \\<notin> set (tl ns)\" \"p \\<in> allUses g n\"\n    assumes[simp]: \"q \\<in> allVars g\" \"p \\<noteq> q\" \"var g p = var g q\"\n    shows \"defNode g q \\<notin> set ns\"\n  proof-\n    let ?P = \"defNode g p\"\n    let ?Q = \"defNode g q\"\n\n    have[simp]: \"p \\<in> allVars g\" using p(1,3) by auto\n    have \"?P \\<noteq> ?Q\" using defNode_var_disjoint[of p g q] by auto\n    moreover have \"?Q \\<notin> set (tl ns)\" using p(2,3)\n      by - (rule conventional'[OF p(1), of p q], auto)\n    ultimately show ?thesis using p(1) by (cases ns, auto simp: old.path2_def)\n  qed\n\n  lemma defUse_paths_disjoint:\n    assumes p: \"g \\<turnstile> defNode g p-ns\\<rightarrow>n\" \"defNode g p \\<notin> set (tl ns)\" \"p \\<in> allUses g n\"\n    assumes q: \"g \\<turnstile> defNode g q-ms\\<rightarrow>m\" \"defNode g q \\<notin> set (tl ms)\" \"q \\<in> allUses g m\"\n    assumes[simp]: \"p \\<noteq> q\" \"var g p = var g q\"\n    shows \"set ns \\<inter> set ms = {}\"\n  proof (rule equals0I)\n    fix y\n    assume y: \"y \\<in> set ns \\<inter> set ms\"\n\n    {\n      fix p ns n\n      assume p: \"g \\<turnstile> defNode g p-ns\\<rightarrow>n\" \"defNode g p \\<notin> set (tl ns)\" \"p \\<in> allUses g n\"\n      assume y: \"y \\<in> set ns\"\n      from p(1,3) have dom: \"old.dominates g (defNode g p) n\" by - (rule allUses_dominated, auto)\n      moreover\n      obtain ns' where \"g \\<turnstile> y-ns'\\<rightarrow>n\" \"suffix ns' ns\"\n        by (rule old.path2_split_first_last[OF p(1) y], auto)\n      ultimately have \"old.dominates g (defNode g p) y\" using suffix_tl_subset[of ns' ns] p(2)\n        by - (rule old.dominates_extend[where ms=ns'], auto)\n    }\n    with assms y have dom: \"old.dominates g (defNode g p) y\" \"old.dominates g (defNode g q) y\" by auto\n\n    {\n      fix p ns n q ms m\n      let ?P = \"defNode g p\"\n      let ?Q = \"defNode g q\"\n\n      assume p: \"g \\<turnstile> defNode g p-ns\\<rightarrow>n\" \"defNode g p \\<notin> set (tl ns)\" \"p \\<in> allUses g n\" \"old.dominates g ?P y\" \"y \\<in> set ns\"\n      assume q: \"g \\<turnstile> defNode g q-ms\\<rightarrow>m\" \"defNode g q \\<notin> set (tl ms)\" \"q \\<in> allUses g m\" \"old.dominates g ?Q y\" \"y \\<in> set ms\"\n      assume[simp]: \"p \\<noteq> q\" \"var g p = var g q\"\n      assume dom: \"old.dominates g ?P ?Q\"\n      then obtain pqs where pqs: \"g \\<turnstile> ?P-pqs\\<rightarrow>?Q\" \"?P \\<notin> set (tl pqs)\" by (rule old.dominates_path, auto intro: old.simple_path2)\n      from p obtain ns\\<^sub>2 where ns\\<^sub>2: \"g \\<turnstile> y-ns\\<^sub>2\\<rightarrow>n\" \"suffix ns\\<^sub>2 ns\" by - (rule old.path2_split_first_last, auto)\n      from q obtain ms\\<^sub>1 where ms\\<^sub>1: \"g \\<turnstile> ?Q-ms\\<^sub>1\\<rightarrow>y\" \"prefix ms\\<^sub>1 ms\" by - (rule old.path2_split_first_last, auto)\n      have \"var g q \\<noteq> var g p\"\n      proof (rule conventional[OF _ _ _ p(3)])\n        let ?path = \"(pqs@tl ms\\<^sub>1)@tl ns\\<^sub>2\"\n        show \"g \\<turnstile> ?P-?path\\<rightarrow>n\" using pqs ms\\<^sub>1 ns\\<^sub>2\n          by (auto simp del:append_assoc intro:old.path2_app)\n        have \"?P \\<notin> set (tl ns\\<^sub>2)\" using p(2) ns\\<^sub>2(2)[THEN suffix_tl_subset, THEN subsetD] by auto\n        moreover\n        have[simp]: \"q \\<in> allVars g\" \"p \\<in> allVars g\" using p q by auto\n        have \"?P \\<notin> set (tl ms)\" using q\n          by - (rule conventional'[where v'=p and v=q], auto)\n        hence \"?P \\<notin> set (tl ms\\<^sub>1)\" using ms\\<^sub>1(2)[simplified, THEN prefix_tl_subset] by auto\n        ultimately\n        show \"?P \\<notin> set (tl ?path)\" using pqs(2)\n          by - (rule notI, auto dest: subsetD[OF set_tl_append'])\n        show \"p \\<in> allDefs g (defNode g p)\" by auto\n        have \"?P \\<noteq> ?Q\" using defNode_var_disjoint[of p g q] by auto\n        hence 1: \"length pqs > 1\" using pqs by - (rule old.path2_nontriv)\n        hence \"?Q \\<in> set (tl pqs)\" using pqs unfolding old.path2_def by (auto intro:last_in_tl)\n        moreover from 1 have \"pqs \\<noteq> []\" by auto\n        ultimately show \"?Q \\<in> set (tl ?path)\" by simp\n        show \"q \\<in> allDefs g ?Q\" by simp\n      qed\n      hence False by simp\n    }\n    from this[OF p _ _ q] this[OF q _ _ p] y dom show False\n      by - (rule old.dominates_antitrans[OF _ dom], auto)\n  qed\n\n  lemma oldDefsI: \"v \\<in> defs g n \\<Longrightarrow> var g v \\<in> oldDefs g n\" by (simp add: oldDefs_def)\n \n  lemma simpleDefs_phiDefs_var_disjoint:\n    assumes \"v \\<in> phiDefs g n\" \"n \\<in> set (\\<alpha>n g)\"\n    shows \"var g v \\<notin> oldDefs g n\"\n  proof\n    from assms have[simp]: \"v \\<in> allVars g\" by auto\n    assume \"var g v \\<in> oldDefs g n\"\n    then obtain v'' where v'': \"v'' \\<in> defs g n\" \"var g v'' = var g v\"\n      by (auto simp: oldDefs_def)\n    from this(1) assms have \"v'' \\<noteq> v\"\n      using simpleDefs_phiDefs_disjoint[of n g] by (auto simp: phiArg_def)\n    with v'' assms show False\n      using allDefs_var_disjoint[of n g v'' v] by auto\n  qed\n\n  lemma liveVal_use_path: \n    assumes \"liveVal g v\"\n    obtains ns m where \"g \\<turnstile> defNode g v-ns\\<rightarrow>m\" \"var g v \\<in> oldUses g m\"\n      \"\\<And>x. x \\<in> set (tl ns) \\<Longrightarrow> var g v \\<notin> oldDefs g x\"\n  using assms proof (induction)\n    case (liveSimple m v)\n    from liveSimple.hyps have[simp]: \"v \\<in> allVars g\"\n      by - (rule allUses_in_allVars, auto)\n    from liveSimple.hyps obtain ns where ns: \"g \\<turnstile> defNode g v-ns\\<rightarrow>m\" \"defNode g v \\<notin> set (tl ns)\"\n      by - (rule defUse_path_ex, auto intro!: uses_in_allUses elim: old.simple_path2)\n    from this(1) show thesis\n    proof (rule liveSimple.prems)\n      show \"var g v \\<in> oldUses g m\" using liveSimple.hyps by (auto simp: oldUses_def)\n      {\n        fix x\n        assume asm: \"x \\<in> set (tl ns)\" \"var g v \\<in> oldDefs g x\"\n        then obtain v' where \"v' \\<in> defs g x\" \"var g v' = var g v\"\n          by (auto simp: oldDefs_def)\n        with asm liveSimple.hyps have False\n          by - (rule conventional[OF ns, of v x v', THEN notE], auto)\n      }\n      thus \"\\<And>x. x \\<in> set (tl ns) \\<Longrightarrow> var g v \\<notin> oldDefs g x\" by auto\n    qed\n  next\n    case (livePhi v v')\n    from livePhi.hyps have[simp]: \"v \\<in> allVars g\" \"v' \\<in> allVars g\" \"var g v' = var g v\"\n      by (auto intro: phiArg_same_var)\n    show thesis\n    proof (rule livePhi.IH)\n      fix ns m\n      assume asm: \"g \\<turnstile> defNode g v-ns\\<rightarrow>m\" \"var g v \\<in> oldUses g m\"\n        \"\\<And>x. x \\<in> set (tl ns) \\<Longrightarrow> var g v \\<notin> oldDefs g x\"\n      from livePhi.hyps(2) obtain ns' m' where ns': \"g \\<turnstile> defNode g v'-ns'\\<rightarrow>m'\" \"v' \\<in> phiUses g m'\"\n        \"m' \\<in> set (old.predecessors g (defNode g v))\" \"defNode g v' \\<notin> set (tl ns')\"\n        by (rule phiArg_path_ex', auto elim: old.simple_path2)\n      show thesis \n      proof (rule livePhi.prems)\n        show \"g \\<turnstile> defNode g v'-(ns'@[defNode g v])@tl ns\\<rightarrow>m\"\n        apply (rule old.path2_app)\n         apply (rule old.path2_snoc[OF ns'(1,3)])\n        by (rule asm(1))\n        show \"var g v' \\<in> oldUses g m\" using asm(2) by simp\n        {\n          fix x\n          assume asm: \"x \\<in> set (tl ns')\" \"var g v \\<in> oldDefs g x\"\n          then obtain v'' where \"v'' \\<in> defs g x\" \"var g v'' = var g v\"\n            by (auto simp: oldDefs_def)\n          with asm ns'(2) have False\n            by - (rule conventional[OF ns'(1,4), of v' x v'', THEN notE], auto)\n        }\n        then show \"\\<And>x. x \\<in> set (tl ((ns'@[defNode g v])@tl ns)) \\<Longrightarrow> var g v' \\<notin> oldDefs g x\"\n          using simpleDefs_phiDefs_var_disjoint[of v g \"defNode g v\"] livePhi.hyps(2)\n          by (auto dest!: set_tl_append'[THEN subsetD] asm(3) simp: phiArg_def)\n      qed\n    qed\n  qed\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Formal_SSA/SSA_CFG.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5312093733737562, "lm_q2_score": 0.5117166047041652, "lm_q1q2_score": 0.2718286569298457}}
{"text": "theory SINVAR_DomainHierarchyNG_impl\nimports SINVAR_DomainHierarchyNG \"../TopoS_Interface_impl\"\nbegin\n\n\nsubsubsection \\<open>SecurityInvariant DomainHierarchy List Implementation\\<close>\n\ncode_identifier code_module SINVAR_DomainHierarchyNG_impl => (Scala) SINVAR_DomainHierarchyNG\n\nfun sinvar :: \"'v list_graph \\<Rightarrow> ('v \\<Rightarrow> domainNameTrust) \\<Rightarrow> bool\" where\n  \"sinvar G nP = (\\<forall> (s, r) \\<in> set (edgesL G). (nP r) \\<sqsubseteq>\\<^sub>t\\<^sub>r\\<^sub>u\\<^sub>s\\<^sub>t (nP s))\"\n\n\ndefinition DomainHierarchyNG_sanity_check_config :: \"domainNameTrust list \\<Rightarrow> domainTree \\<Rightarrow> bool\" where\n  \"DomainHierarchyNG_sanity_check_config host_attributes tree = (\\<forall> c \\<in> set host_attributes.\n    case c of Unassigned \\<Rightarrow> True\n            | DN (level, trust) \\<Rightarrow> valid_hierarchy_pos tree level\n   )\"\n\nfun verify_globals :: \"'v list_graph \\<Rightarrow> ('v \\<Rightarrow> domainNameTrust) \\<Rightarrow> domainTree \\<Rightarrow> bool\" where\n  \"verify_globals G nP tree = (\\<forall> v \\<in> set (nodesL G). \n    case (nP v) of Unassigned \\<Rightarrow> True | DN (level, trust) \\<Rightarrow> valid_hierarchy_pos tree level\n   )\"\n\n(*TODO: to get rid of verify_globals\n  this stronger DomainHierarchyNG_sanity_check_config sanity checker checks the config\n  for all graphs!*)\nlemma \"DomainHierarchyNG_sanity_check_config c tree \\<Longrightarrow>\n    {x. \\<exists>v. nP v = x} = set c \\<Longrightarrow>\n    verify_globals G nP tree\"\n  apply(simp add: DomainHierarchyNG_sanity_check_config_def split: if_split_asm)\n  apply(clarify)\n  apply(case_tac \"nP v\")\n   apply(simp_all)\n  apply(clarify)\n  by force\n\n\ndefinition DomainHierarchyNG_offending_list:: \"'v list_graph \\<Rightarrow> ('v \\<Rightarrow> domainNameTrust) \\<Rightarrow> ('v \\<times> 'v) list list\" where\n  \"DomainHierarchyNG_offending_list G nP = (if sinvar G nP then\n    []\n   else \n    [ [e \\<leftarrow> edgesL G. case e of (s,r) \\<Rightarrow> \\<not> (nP r) \\<sqsubseteq>\\<^sub>t\\<^sub>r\\<^sub>u\\<^sub>s\\<^sub>t (nP s) ] ])\"\n\n\n\nlemma \"DomainHierarchyNG.node_props P = \n  (\\<lambda>i. case node_properties P i of None \\<Rightarrow> SINVAR_DomainHierarchyNG.default_node_properties | Some property \\<Rightarrow> property)\"\nby(fact SecurityInvariant.node_props.simps[OF TopoS_DomainHierarchyNG, of \"P\"])\n\ndefinition \"NetModel_node_props P = (\\<lambda> i. (case (node_properties P) i of Some property \\<Rightarrow> property | None \\<Rightarrow> SINVAR_DomainHierarchyNG.default_node_properties))\"\n(*\n\n(*TODO does this work?*)\nlemma[code_unfold]: \"DomainHierarchyNG.node_props P = NetModel_node_props P\"\nby(simp add: NetModel_node_props_def)\n\ndefinition \"DomainHierarchyNG_eval G P = (wf_list_graph G \\<and>\n  sinvar G (SecurityInvariant.node_props SINVAR_DomainHierarchyNG.default_node_properties P))\"\n\n\ninterpretation DomainHierarchyNG_impl:TopoS_List_Impl \n  where default_node_properties=SINVAR_DomainHierarchyNG.default_node_properties\n  and sinvar_spec=SINVAR_DomainHierarchyNG.sinvar\n  and sinvar_impl=sinvar\n  and receiver_violation=SINVAR_DomainHierarchyNG.receiver_violation\n  and offending_flows_impl=DomainHierarchyNG_offending_list\n  and node_props_impl=NetModel_node_props\n  and eval_impl=DomainHierarchyNG_eval\n apply(unfold TopoS_List_Impl_def)\n apply(rule conjI)\n  apply(simp add: TopoS_DomainHierarchyNG list_graph_to_graph_def; fail)\n apply(rule conjI)\n  apply(simp add: list_graph_to_graph_def DomainHierarchyNG_offending_set\n        DomainHierarchyNG_offending_set_def DomainHierarchyNG_offending_list_def; fail)\n apply(rule conjI)\n  apply(simp only: NetModel_node_props_def)\n  apply(metis DomainHierarchyNG.node_props.simps DomainHierarchyNG.node_props_eq_node_props_formaldef)\n apply(simp only: DomainHierarchyNG_eval_def)\n apply(intro allI)\n apply(rule TopoS_eval_impl_proofrule[OF TopoS_DomainHierarchyNG])\n apply(simp add: list_graph_to_graph_def)\ndone\n\n\nsubsubsection \\<open>DomainHierarchyNG packing\\<close>\n  definition SINVAR_LIB_DomainHierarchyNG :: \"('v::vertex, domainNameTrust) TopoS_packed\" where\n    \"SINVAR_LIB_DomainHierarchyNG \\<equiv> \n    \\<lparr> nm_name = ''DomainHierarchyNG'', \n      nm_receiver_violation = SINVAR_DomainHierarchyNG.receiver_violation,\n      nm_default = SINVAR_DomainHierarchyNG.default_node_properties, \n      nm_sinvar = sinvar,\n      nm_offending_flows = DomainHierarchyNG_offending_list, \n      nm_node_props = NetModel_node_props,\n      nm_eval = DomainHierarchyNG_eval\n      \\<rparr>\"\n  interpretation SINVAR_LIB_DomainHierarchyNG_interpretation: TopoS_modelLibrary SINVAR_LIB_DomainHierarchyNG \n      SINVAR_DomainHierarchyNG.sinvar\n    apply(unfold TopoS_modelLibrary_def SINVAR_LIB_DomainHierarchyNG_def)\n    apply(rule conjI)\n     apply(simp)\n    apply(simp)\n    by(unfold_locales)\n\n\n\n\n\n\ntext \\<open>Examples:\\<close>\ndefinition example_TUM_net :: \"string list_graph\" where\n  \"example_TUM_net \\<equiv> \\<lparr> nodesL=[''Gateway'', ''LowerSVR'', ''UpperSRV''], \n        edgesL=[\n          (''Gateway'',''LowerSVR''), (''Gateway'',''UpperSRV''), \n          (''LowerSVR'', ''Gateway''),\n          (''UpperSRV'', ''Gateway'')\n        ] \\<rparr>\"\nvalue \"wf_list_graph example_TUM_net\"\n\ndefinition example_TUM_config :: \"string \\<Rightarrow> domainNameTrust\" where\n  \"example_TUM_config \\<equiv> ((\\<lambda> e. default_node_properties)\n        (''Gateway'':= DN (''ACD''--''AISD''--Leaf, 1),\n         ''LowerSVR'':= DN (''ACD''--''AISD''--Leaf, 0),\n         ''UpperSRV'':= DN (''ACD''--Leaf, 0)\n       ))\"\n\ndefinition example_TUM_hierarchy :: \"domainTree\" where\n\"example_TUM_hierarchy \\<equiv> (Department ''ACD'' [\n           Department ''AISD'' []\n       ])\"\n\nvalue \"verify_globals example_TUM_net example_TUM_config example_TUM_hierarchy\"\nvalue \"sinvar     example_TUM_net example_TUM_config\"\n\ndefinition example_TUM_net_invalid where\n\"example_TUM_net_invalid \\<equiv> example_TUM_net\\<lparr>edgesL :=  \n    (''LowerSRV'', ''UpperSRV'')#(edgesL example_TUM_net)\\<rparr>\"\n\nvalue \"verify_globals example_TUM_net_invalid example_TUM_config example_TUM_hierarchy\"\nvalue \"sinvar     example_TUM_net_invalid example_TUM_config\"\nvalue \"DomainHierarchyNG_offending_list example_TUM_net_invalid example_TUM_config\"\n\n\nhide_const (open) NetModel_node_props\n\nhide_const (open) sinvar \n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Network_Security_Policy_Verification/Security_Invariants/SINVAR_DomainHierarchyNG_impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6926419831347361, "lm_q2_score": 0.39233683016710835, "lm_q1q2_score": 0.2717489601037421}}
{"text": "section \\<open>Algorithms on Nondeterministic Generalized Büchi Automata\\<close>\n\ntheory NGBA_Algorithms\nimports\n  NGBA_Graphs\n  NGBA_Implement\n  NBA_Combine\n  NBA_Algorithms\n  Degeneralization_Refine\nbegin\n\n  subsection \\<open>Operations\\<close>\n\n  definition op_language_empty where [simp]: \"op_language_empty A \\<equiv> NGBA.language A = {}\"\n\n  lemmas [autoref_op_pat] = op_language_empty_def[symmetric]\n\n  subsection \\<open>Implementations\\<close>\n\n  context\n  begin\n\n    interpretation autoref_syn by this\n\n    lemma ngba_g_ahs: \"ngba_g A = \\<lparr> g_V = UNIV, g_E = E_of_succ (\\<lambda> p. CAST\n      ((\\<Union> a \\<in> ngba.alphabet A. ngba.transition A a p ::: \\<langle>S\\<rangle> list_set_rel) ::: \\<langle>S\\<rangle> ahs_rel bhc)),\n      g_V0 = ngba.initial A \\<rparr>\"\n      unfolding ngba_g_def ngba.successors_alt_def CAST_def id_apply autoref_tag_defs by rule\n\n    schematic_goal ngbai_gi:\n      notes [autoref_ga_rules] = map2set_to_list\n      fixes S :: \"('statei \\<times> 'state) set\"\n      assumes [autoref_ga_rules]: \"is_bounded_hashcode S seq bhc\"\n      assumes [autoref_ga_rules]: \"is_valid_def_hm_size TYPE('statei) hms\"\n      assumes [autoref_rules]: \"(seq, HOL.eq) \\<in> S \\<rightarrow> S \\<rightarrow> bool_rel\"\n      assumes [autoref_rules]: \"(Ai, A) \\<in> \\<langle>L, S\\<rangle> ngbai_ngba_rel\"\n      shows \"(?f :: ?'a, RETURN (ngba_g A)) \\<in> ?A\"\n      unfolding ngba_g_ahs[where S = S and bhc = bhc] by (autoref_monadic (plain))\n    concrete_definition ngbai_gi uses ngbai_gi\n    lemma ngbai_gi_refine[autoref_rules]:\n      fixes S :: \"('statei \\<times> 'state) set\"\n      assumes \"SIDE_GEN_ALGO (is_bounded_hashcode S seq bhc)\"\n      assumes \"SIDE_GEN_ALGO (is_valid_def_hm_size TYPE('statei) hms)\"\n      assumes \"GEN_OP seq HOL.eq (S \\<rightarrow> S \\<rightarrow> bool_rel)\"\n      shows \"(NGBA_Algorithms.ngbai_gi seq bhc hms, ngba_g) \\<in>\n        \\<langle>L, S\\<rangle> ngbai_ngba_rel \\<rightarrow> \\<langle>unit_rel, S\\<rangle> g_impl_rel_ext\"\n      using ngbai_gi.refine[THEN RETURN_nres_relD] assms unfolding autoref_tag_defs by blast\n\n    schematic_goal ngba_nodes:\n      fixes S :: \"('statei \\<times> 'state) set\"\n      assumes [simp]: \"finite ((g_E (ngba_g A))\\<^sup>* `` g_V0 (ngba_g A))\"\n      assumes [autoref_ga_rules]: \"is_bounded_hashcode S seq bhc\"\n      assumes [autoref_ga_rules]: \"is_valid_def_hm_size TYPE('statei) hms\"\n      assumes [autoref_rules]: \"(seq, HOL.eq) \\<in> S \\<rightarrow> S \\<rightarrow> bool_rel\"\n      assumes [autoref_rules]: \"(Ai, A) \\<in> \\<langle>L, S\\<rangle> ngbai_ngba_rel\"\n      shows \"(?f :: ?'a, op_reachable (ngba_g A)) \\<in> ?R\" by autoref\n    concrete_definition ngba_nodes uses ngba_nodes\n    lemma ngba_nodes_refine[autoref_rules]:\n      fixes S :: \"('statei \\<times> 'state) set\"\n      assumes \"SIDE_PRECOND (finite (NGBA.nodes A))\"\n      assumes \"SIDE_GEN_ALGO (is_bounded_hashcode S seq bhc)\"\n      assumes \"SIDE_GEN_ALGO (is_valid_def_hm_size TYPE('statei) hms)\"\n      assumes \"GEN_OP seq HOL.eq (S \\<rightarrow> S \\<rightarrow> bool_rel)\"\n      assumes \"(Ai, A) \\<in> \\<langle>L, S\\<rangle> ngbai_ngba_rel\"\n      shows \"(NGBA_Algorithms.ngba_nodes seq bhc hms Ai,\n        (OP NGBA.nodes ::: \\<langle>L, S\\<rangle> ngbai_ngba_rel \\<rightarrow> \\<langle>S\\<rangle> ahs_rel bhc) $ A) \\<in> \\<langle>S\\<rangle> ahs_rel bhc\"\n    proof -\n      have 1: \"NGBA.nodes A = op_reachable (ngba_g A)\" by (auto simp: ngba_g_V0 ngba_g_E_rtrancl)\n      have 2: \"finite ((g_E (ngba_g A))\\<^sup>* `` g_V0 (ngba_g A))\" using assms(1) unfolding 1 by simp\n      show ?thesis using ngba_nodes.refine assms 2 unfolding autoref_tag_defs 1 by blast\n    qed\n\n    lemma ngba_igbg_ahs: \"ngba_igbg A = \\<lparr> g_V = UNIV, g_E = E_of_succ (\\<lambda> p. CAST\n      ((\\<Union> a \\<in> NGBA.alphabet A. NGBA.transition A a p ::: \\<langle>S\\<rangle> list_set_rel) ::: \\<langle>S\\<rangle> ahs_rel bhc)), g_V0 = NGBA.initial A,\n      igbg_num_acc = length (NGBA.accepting A), igbg_acc = ngba_acc (NGBA.accepting A) \\<rparr>\"\n      unfolding ngba_g_def ngba_igbg_def ngba.successors_alt_def CAST_def id_apply autoref_tag_defs\n      unfolding graph_rec.defs\n      by simp\n\n    definition \"ngba_acc_bs cs p \\<equiv> fold (\\<lambda> (k, c) bs. if c p then bs_insert k bs else bs) (List.enumerate 0 cs) (bs_empty ())\"\n\n    lemma ngba_acc_bs_empty[simp]: \"ngba_acc_bs [] p = bs_empty ()\" unfolding ngba_acc_bs_def by simp\n    lemma ngba_acc_bs_insert[simp]:\n      assumes \"c p\"\n      shows \"ngba_acc_bs (cs @ [c]) p = bs_insert (length cs) (ngba_acc_bs cs p)\"\n      using assms unfolding ngba_acc_bs_def by (simp add: enumerate_append_eq)\n    lemma ngba_acc_bs_skip[simp]:\n      assumes \"\\<not> c p\"\n      shows \"ngba_acc_bs (cs @ [c]) p = ngba_acc_bs cs p\"\n      using assms unfolding ngba_acc_bs_def by (simp add: enumerate_append_eq)\n\n    lemma ngba_acc_bs_correct[simp]: \"bs_\\<alpha> (ngba_acc_bs cs p) = ngba_acc cs p\"\n    proof (induct cs rule: rev_induct)\n      case Nil\n      show ?case unfolding ngba_acc_def by simp\n    next\n      case (snoc c cs)\n      show ?case using less_Suc_eq snoc by (cases \"c p\") (force simp: ngba_acc_def)+\n    qed\n\n    lemma ngba_acc_impl_bs[autoref_rules]: \"(ngba_acc_bs, ngba_acc) \\<in> \\<langle>S \\<rightarrow> bool_rel\\<rangle> list_rel \\<rightarrow> S \\<rightarrow> \\<langle>nat_rel\\<rangle> bs_set_rel\"\n    proof -\n      have \"(ngba_acc_bs, ngba_acc) \\<in> \\<langle>Id \\<rightarrow> bool_rel\\<rangle> list_rel \\<rightarrow> Id \\<rightarrow> \\<langle>nat_rel\\<rangle> bs_set_rel\"\n        by (auto simp: bs_set_rel_def in_br_conv)\n      also have \"(ngba_acc, ngba_acc) \\<in> \\<langle>S \\<rightarrow> bool_rel\\<rangle> list_rel \\<rightarrow> S \\<rightarrow> \\<langle>nat_rel\\<rangle> set_rel\" by parametricity\n      finally show ?thesis by simp\n    qed\n\n    schematic_goal ngbai_igbgi:\n      notes [autoref_ga_rules] = map2set_to_list\n      fixes S :: \"('statei \\<times> 'state) set\"\n      assumes [autoref_ga_rules]: \"is_bounded_hashcode S seq bhc\"\n      assumes [autoref_ga_rules]: \"is_valid_def_hm_size TYPE('statei) hms\"\n      assumes [autoref_rules]: \"(seq, HOL.eq) \\<in> S \\<rightarrow> S \\<rightarrow> bool_rel\"\n      assumes [autoref_rules]: \"(Ai, A) \\<in> \\<langle>L, S\\<rangle> ngbai_ngba_rel\"\n      shows \"(?f :: ?'a, RETURN (ngba_igbg A)) \\<in> ?A\"\n      unfolding ngba_igbg_ahs[where S = S and bhc = bhc] by (autoref_monadic (plain))\n    concrete_definition ngbai_igbgi uses ngbai_igbgi\n    lemma ngbai_igbgi_refine[autoref_rules]:\n      fixes S :: \"('statei \\<times> 'state) set\"\n      assumes \"SIDE_GEN_ALGO (is_bounded_hashcode S seq bhc)\"\n      assumes \"SIDE_GEN_ALGO (is_valid_def_hm_size TYPE('statei) hms)\"\n      assumes \"GEN_OP seq HOL.eq (S \\<rightarrow> S \\<rightarrow> bool_rel)\"\n      shows \"(NGBA_Algorithms.ngbai_igbgi seq bhc hms, ngba_igbg) \\<in>\n        \\<langle>L, S\\<rangle> ngbai_ngba_rel \\<rightarrow> igbg_impl_rel_ext unit_rel S\"\n      using ngbai_igbgi.refine[THEN RETURN_nres_relD] assms unfolding autoref_tag_defs by blast\n\n    schematic_goal ngba_language_empty:\n      fixes S :: \"('statei \\<times> 'state) set\"\n      assumes [simp]: \"igb_fr_graph (ngba_igbg A)\"\n      assumes [autoref_ga_rules]: \"is_bounded_hashcode S seq bhs\"\n      assumes [autoref_ga_rules]: \"is_valid_def_hm_size TYPE('statei) hms\"\n      assumes [autoref_rules]: \"(seq, HOL.eq) \\<in> S \\<rightarrow> S \\<rightarrow> bool_rel\"\n      assumes [autoref_rules]: \"(Ai, A) \\<in> \\<langle>L, S\\<rangle> ngbai_ngba_rel\"\n      shows \"(?f :: ?'a, do { r \\<leftarrow> op_find_lasso_spec (ngba_igbg A); RETURN (r = None)}) \\<in> ?A\"\n      by (autoref_monadic (plain))\n    concrete_definition ngba_language_empty uses ngba_language_empty\n    lemma nba_language_empty_refine[autoref_rules]:\n      fixes S :: \"('statei \\<times> 'state) set\"\n      assumes \"SIDE_PRECOND (finite (NGBA.nodes A))\"\n      assumes \"SIDE_GEN_ALGO (is_bounded_hashcode S seq bhc)\"\n      assumes \"SIDE_GEN_ALGO (is_valid_def_hm_size TYPE('statei) hms)\"\n      assumes \"GEN_OP seq HOL.eq (S \\<rightarrow> S \\<rightarrow> bool_rel)\"\n      assumes \"(Ai, A) \\<in> \\<langle>L, S\\<rangle> ngbai_ngba_rel\"\n      shows \"(NGBA_Algorithms.ngba_language_empty seq bhc hms Ai,\n        (OP op_language_empty ::: \\<langle>L, S\\<rangle> ngbai_ngba_rel \\<rightarrow> bool_rel) $ A) \\<in> bool_rel\"\n    proof -\n      have 1: \"NGBA.nodes A = op_reachable (ngba_g A)\" by (auto simp: ngba_g_V0 ngba_g_E_rtrancl)\n      have 2: \"finite ((g_E (ngba_g A))\\<^sup>* `` g_V0 (ngba_g A))\" using assms(1) unfolding 1 by simp\n      interpret igb_fr_graph \"ngba_igbg A\"\n        using 2 unfolding ngba_igbg_def ngba_g_def graph_rec.defs ngba_acc_def by unfold_locales auto\n      have \"(RETURN (NGBA_Algorithms.ngba_language_empty seq bhc hms Ai),\n        do { r \\<leftarrow> find_lasso_spec; RETURN (r = None) }) \\<in> \\<langle>bool_rel\\<rangle> nres_rel\"\n        using ngba_language_empty.refine assms igb_fr_graph_axioms by simp\n      also have \"(do { r \\<leftarrow> find_lasso_spec; RETURN (r = None) },\n        RETURN (\\<not> Ex is_lasso_prpl)) \\<in> \\<langle>bool_rel\\<rangle> nres_rel\"\n        unfolding find_lasso_spec_def by (refine_vcg) (auto split: option.splits)\n      finally have \"NGBA_Algorithms.ngba_language_empty seq bhc hms Ai \\<longleftrightarrow> \\<not> Ex is_lasso_prpl\"\n        unfolding nres_rel_comp using RETURN_nres_relD by force\n      also have \"\\<dots> \\<longleftrightarrow> \\<not> Ex is_acc_run\" using lasso_prpl_acc_run_iff by auto\n      also have \"\\<dots> \\<longleftrightarrow> NGBA.language A = {}\" using NGBA_Graphs.acc_run_language is_igb_graph by auto\n      finally show ?thesis by simp\n    qed\n\n    lemma degeneralize_alt_def: \"degeneralize A = nba\n      (ngba.alphabet A)\n      ((\\<lambda> p. (p, 0)) ` ngba.initial A)\n      (\\<lambda> a (p, k). (\\<lambda> q. (q, Degeneralization.count (ngba.accepting A) p k)) ` ngba.transition A a p)\n      (degen (ngba.accepting A))\"\n      unfolding degeneralization.degeneralize_def by auto\n\n    schematic_goal ngba_degeneralize: \"(?f :: ?'a, degeneralize) \\<in> ?R\"\n      unfolding degeneralize_alt_def\n      using degen_param[autoref_rules] count_param[autoref_rules]\n      by autoref\n    concrete_definition ngba_degeneralize uses ngba_degeneralize\n    lemmas ngba_degeneralize_refine[autoref_rules] = ngba_degeneralize.refine\n\n    schematic_goal nba_intersect':\n      assumes [autoref_rules]: \"(seq, HOL.eq) \\<in> L \\<rightarrow> L \\<rightarrow> bool_rel\"\n      shows \"(?f, intersect') \\<in> \\<langle>L, S\\<rangle> nbai_nba_rel \\<rightarrow> \\<langle>L, T\\<rangle> nbai_nba_rel \\<rightarrow> \\<langle>L, S \\<times>\\<^sub>r T\\<rangle> ngbai_ngba_rel\"\n      unfolding intersection.product_def by autoref\n    concrete_definition nba_intersect' uses nba_intersect'\n    lemma nba_intersect'_refine[autoref_rules]:\n      assumes \"GEN_OP seq HOL.eq (L \\<rightarrow> L \\<rightarrow> bool_rel)\"\n      shows \"(nba_intersect' seq, intersect') \\<in>\n        \\<langle>L, S\\<rangle> nbai_nba_rel \\<rightarrow> \\<langle>L, T\\<rangle> nbai_nba_rel \\<rightarrow> \\<langle>L, S \\<times>\\<^sub>r T\\<rangle> ngbai_ngba_rel\"\n      using nba_intersect'.refine assms unfolding autoref_tag_defs by this\n\n  end\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Transition_Systems_and_Automata/Automata/NBA/NGBA_Algorithms.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5350984286266116, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.2717293306137525}}
{"text": "(*  Title:      Imperative_HOL_Time/Ref_Time.thy\n    Author:     Maximilian P. L. Haslbeck & Bohua Zhan, TU Muenchen\n*)\n\nsection \\<open>Monadic references\\<close>\n\ntext \\<open>This theory is an adaptation of \\<open>HOL/Imperative_HOL/Array_Time.thy\\<close>,\n adding time bookkeeping.\\<close>\n\ntheory Ref_Time\nimports Array_Time\nbegin\n\ntext \\<open>\n  Imperative reference operations; modeled after their ML counterparts.\n  See \\<^url>\\<open>http://caml.inria.fr/pub/docs/manual-caml-light/node14.15.html\\<close>\n  and \\<^url>\\<open>http://www.smlnj.org/doc/Conversion/top-level-comparison.html\\<close>.\n\\<close>\n\nsubsection \\<open>Primitives\\<close>\n\ndefinition present :: \"heap \\<Rightarrow> 'a::heap ref \\<Rightarrow> bool\" where\n  \"present h r \\<longleftrightarrow> addr_of_ref r < lim h\"\n\ndefinition get :: \"heap \\<Rightarrow> 'a::heap ref \\<Rightarrow> 'a\" where\n  \"get h = from_nat \\<circ> refs h TYPEREP('a) \\<circ> addr_of_ref\"\n\ndefinition set :: \"'a::heap ref \\<Rightarrow> 'a \\<Rightarrow> heap \\<Rightarrow> heap\" where\n  \"set r x = refs_update\n    (\\<lambda>h. h(TYPEREP('a) := ((h (TYPEREP('a))) (addr_of_ref r := to_nat x))))\"\n\ndefinition alloc :: \"'a \\<Rightarrow> heap \\<Rightarrow> 'a::heap ref \\<times> heap\" where\n  \"alloc x h = (let\n     l = lim h;\n     r = Ref l\n   in (r, set r x (h\\<lparr>lim := l + 1\\<rparr>)))\"\n\ndefinition noteq :: \"'a::heap ref \\<Rightarrow> 'b::heap ref \\<Rightarrow> bool\" (infix \"=!=\" 70) where\n  \"r =!= s \\<longleftrightarrow> TYPEREP('a) \\<noteq> TYPEREP('b) \\<or> addr_of_ref r \\<noteq> addr_of_ref s\"\n\n\nsubsection \\<open>Monad operations\\<close>\n\ndefinition ref :: \"'a::heap \\<Rightarrow> 'a ref Heap\" where\n  [code del]: \"ref v = Heap_Time_Monad.heap (%h. let (r,h') = alloc v h in (r,h',1))\"\n\ndefinition lookup :: \"'a::heap ref \\<Rightarrow> 'a Heap\" (\"!_\" 61) where\n  [code del]: \"lookup r = Heap_Time_Monad.tap (\\<lambda>h. get h r)\"\n\ndefinition update :: \"'a ref \\<Rightarrow> 'a::heap \\<Rightarrow> unit Heap\" (\"_ := _\" 62) where\n  [code del]: \"update r v = Heap_Time_Monad.heap (\\<lambda>h. ((), set r v h, 1))\"\n\ndefinition change :: \"('a::heap \\<Rightarrow> 'a) \\<Rightarrow> 'a ref \\<Rightarrow> 'a Heap\" where\n  \"change f r = do {\n     x \\<leftarrow> ! r;\n     let y = f x;\n     r := y;\n     return y\n   }\"\n\n\nsubsection \\<open>Properties\\<close>\n\ntext \\<open>Primitives\\<close>\n\nlemma noteq_sym: \"r =!= s \\<Longrightarrow> s =!= r\"\n  and unequal [simp]: \"r \\<noteq> r' \\<longleftrightarrow> r =!= r'\" \\<comment> \\<open>same types!\\<close>\n  by (auto simp add: noteq_def)\n\nlemma noteq_irrefl: \"r =!= r \\<Longrightarrow> False\"\n  by (auto simp add: noteq_def)\n\nlemma present_alloc_neq: \"present h r \\<Longrightarrow> r =!= fst (alloc v h)\"\n  by (simp add: present_def alloc_def noteq_def Let_def)\n\nlemma next_fresh [simp]:\n  assumes \"(r, h') = alloc x h\"\n  shows \"\\<not> present h r\"\n  using assms by (cases h) (auto simp add: alloc_def present_def Let_def)\n\nlemma next_present [simp]:\n  assumes \"(r, h') = alloc x h\"\n  shows \"present h' r\"\n  using assms by (cases h) (auto simp add: alloc_def set_def present_def Let_def)\n\nlemma get_set_eq [simp]:\n  \"get (set r x h) r = x\"\n  by (simp add: get_def set_def)\n\nlemma get_set_neq [simp]:\n  \"r =!= s \\<Longrightarrow> get (set s x h) r = get h r\"\n  by (simp add: noteq_def get_def set_def)\n\nlemma set_same [simp]:\n  \"set r x (set r y h) = set r x h\"\n  by (simp add: set_def)\n\nlemma not_present_alloc [simp]:\n  \"\\<not> present h (fst (alloc v h))\"\n  by (simp add: present_def alloc_def Let_def)\n\nlemma set_set_swap:\n  \"r =!= r' \\<Longrightarrow> set r x (set r' x' h) = set r' x' (set r x h)\"\n  by (simp add: noteq_def set_def fun_eq_iff)\n\nlemma alloc_set:\n  \"fst (alloc x (set r x' h)) = fst (alloc x h)\"\n  by (simp add: alloc_def set_def Let_def)\n\nlemma get_alloc [simp]:\n  \"get (snd (alloc x h)) (fst (alloc x' h)) = x\"\n  by (simp add: alloc_def Let_def)\n\nlemma set_alloc [simp]:\n  \"set (fst (alloc v h)) v' (snd (alloc v h)) = snd (alloc v' h)\"\n  by (simp add: alloc_def Let_def)\n\nlemma get_alloc_neq: \"r =!= fst (alloc v h) \\<Longrightarrow> \n  get (snd (alloc v h)) r  = get h r\"\n  by (simp add: get_def set_def alloc_def Let_def noteq_def)\n\nlemma lim_set [simp]:\n  \"lim (set r v h) = lim h\"\n  by (simp add: set_def)\n\nlemma present_alloc [simp]: \n  \"present h r \\<Longrightarrow> present (snd (alloc v h)) r\"\n  by (simp add: present_def alloc_def Let_def)\n\nlemma present_set [simp]:\n  \"present (set r v h) = present h\"\n  by (simp add: present_def fun_eq_iff)\n\nlemma noteq_I:\n  \"present h r \\<Longrightarrow> \\<not> present h r' \\<Longrightarrow> r =!= r'\"\n  by (auto simp add: noteq_def present_def)\n\n\ntext \\<open>Monad operations\\<close>\n\nlemma execute_ref [execute_simps]:\n  \"execute (ref v) h = Some (let (r,h') = alloc v h in (r,h',1))\"\n  by (simp add: ref_def execute_simps)\n\nlemma success_refI [success_intros]:\n  \"success (ref v) h\"\n  by (auto intro: success_intros simp add: ref_def)\n\nlemma effect_refI [effect_intros]:\n  assumes \"(r, h') = alloc v h\" \"n=1\"\n  shows \"effect (ref v) h h' r n\"\n  apply (rule effectI) apply (insert assms, simp add:  execute_simps)\n  by (metis case_prod_conv) \n\nlemma effect_refE [effect_elims]:\n  assumes \"effect (ref v) h h' r n\" \n  obtains \"get h' r = v\" and \"present h' r\" and \"\\<not> present h r\" and \"n=1\"\n  using assms apply (rule effectE) apply (simp add: execute_simps)\n  by (metis (no_types, lifting) Ref_Time.alloc_def Ref_Time.get_set_eq fst_conv next_fresh next_present prod.case_eq_if snd_conv)\n\nlemma execute_lookup [execute_simps]:\n  \"Heap_Time_Monad.execute (lookup r) h = Some (get h r, h, 1)\"\n  by (simp add: lookup_def execute_simps)\n\nlemma success_lookupI [success_intros]:\n  \"success (lookup r) h\"\n  by (auto intro: success_intros  simp add: lookup_def)\n\nlemma effect_lookupI [effect_intros]:\n  assumes \"h' = h\" \"x = get h r\" \"n=1\"\n  shows \"effect (!r) h h' x n\"\n  by (rule effectI) (insert assms, simp add: execute_simps)\n\nlemma effect_lookupE [effect_elims]:\n  assumes \"effect (!r) h h' x n\"\n  obtains \"h' = h\" \"x = get h r\" \"n=1\"\n  using assms by (rule effectE) (simp add: execute_simps)\n\nlemma execute_update [execute_simps]:\n  \"Heap_Time_Monad.execute (update r v) h = Some ((), set r v h, 1)\"\n  by (simp add: update_def execute_simps)\n\nlemma success_updateI [success_intros]:\n  \"success (update r v) h\"\n  by (auto intro: success_intros  simp add: update_def)\n\nlemma effect_updateI [effect_intros]:\n  assumes \"h' = set r v h\" \"n=1\"\n  shows \"effect (r := v) h h' x n\"\n  by (rule effectI) (insert assms, simp add: execute_simps)\n\nlemma effect_updateE [effect_elims]:\n  assumes \"effect (r' := v) h h' r n\"\n  obtains \"h' = set r' v h\" \"n=1\"\n  using assms by (rule effectE) (simp add: execute_simps)\n\nlemma execute_change [execute_simps]:\n  \"Heap_Time_Monad.execute (change f r) h = Some (f (get h r), set r (f (get h r)) h, 3)\"\n  by (simp add: change_def bind_def Let_def execute_simps)\n\nlemma success_changeI [success_intros]:\n  \"success (change f r) h\"\n  by (auto intro!: success_intros effect_intros simp add: change_def)\n\nlemma effect_changeI [effect_intros]: \n  assumes \"h' = set r (f (get h r)) h\" \"x = f (get h r)\" \"n=3\"\n  shows \"effect (change f r) h h' x n\"\n  by (rule effectI) (insert assms, simp add: execute_simps)  \n\nlemma effect_changeE [effect_elims]:\n  assumes \"effect (change f r') h h' r n\"\n  obtains \"h' = set r' (f (get h r')) h\" \"r = f (get h r')\" \"n=3\"\n  using assms by (rule effectE) (simp add: execute_simps)\n\nlemma lookup_chain:\n  \"(!r \\<then> f) = wait 1 \\<then> f\"\n  by (rule Heap_eqI) (auto simp add: lookup_def execute_simps intro: execute_bind)\n\n(* this one is wrong! \nlemma update_change [code]:\n  \"r := e = change (\\<lambda>_. e) r \\<then> return ()\"\n  by (rule Heap_eqI) (simp add: change_def lookup_chain)\n*)\n\ntext \\<open>Non-interaction between imperative arrays and imperative references\\<close>\n\nlemma array_get_set [simp]:\n  \"Array_Time.get (set r v h) = Array_Time.get h\"\n  by (simp add: Array_Time.get_def set_def fun_eq_iff)\n\nlemma get_update [simp]:\n  \"get (Array_Time.update a i v h) r = get h r\"\n  by (simp add: get_def Array_Time.update_def Array_Time.set_def)\n\nlemma alloc_update:\n  \"fst (alloc v (Array_Time.update a i v' h)) = fst (alloc v h)\"\n  by (simp add: Array_Time.update_def Array_Time.get_def Array_Time.set_def alloc_def Let_def)\n\nlemma update_set_swap:\n  \"Array_Time.update a i v (set r v' h) = set r v' (Array_Time.update a i v h)\"\n  by (simp add: Array_Time.update_def Array_Time.get_def Array_Time.set_def set_def)\n\nlemma length_alloc [simp]: \n  \"Array_Time.length (snd (alloc v h)) a = Array_Time.length h a\"\n  by (simp add: Array_Time.length_def Array_Time.get_def alloc_def set_def Let_def)\n\nlemma array_get_alloc [simp]: \n  \"Array_Time.get (snd (alloc v h)) = Array_Time.get h\"\n  by (simp add: Array_Time.get_def alloc_def set_def Let_def fun_eq_iff)\n\nlemma present_update [simp]: \n  \"present (Array_Time.update a i v h) = present h\"\n  by (simp add: Array_Time.update_def Array_Time.set_def fun_eq_iff present_def)\n\nlemma array_present_set [simp]:\n  \"Array_Time.present (set r v h) = Array_Time.present h\"\n  by (simp add: Array_Time.present_def set_def fun_eq_iff)\n\nlemma array_present_alloc [simp]:\n  \"Array_Time.present h a \\<Longrightarrow> Array_Time.present (snd (alloc v h)) a\"\n  by (simp add: Array_Time.present_def alloc_def Let_def)\n\nlemma set_array_set_swap:\n  \"Array_Time.set a xs (set r x' h) = set r x' (Array_Time.set a xs h)\"\n  by (simp add: Array_Time.set_def set_def)\n\nhide_const (open) present get set alloc noteq lookup update change\n\n\nsubsection \\<open>Code generator setup\\<close>\n\ntext \\<open>Intermediate operation avoids invariance problem in \\<open>Scala\\<close> (similar to value restriction)\\<close>\n\ndefinition ref' where\n  [code del]: \"ref' = ref\"\n\n\n\n\ntext \\<open>SML / Eval\\<close>\n\ncode_printing type_constructor ref \\<rightharpoonup> (SML) \"_/ ref\"\ncode_printing type_constructor ref \\<rightharpoonup> (Eval) \"_/ Unsynchronized.ref\"\ncode_printing constant Ref \\<rightharpoonup> (SML) \"raise/ (Fail/ \\\"bare Ref\\\")\"\ncode_printing constant ref' \\<rightharpoonup> (SML) \"(fn/ ()/ =>/ ref/ _)\"\ncode_printing constant ref' \\<rightharpoonup> (Eval) \"(fn/ ()/ =>/ Unsynchronized.ref/ _)\"\ncode_printing constant Ref_Time.lookup \\<rightharpoonup> (SML) \"(fn/ ()/ =>/ !/ _)\"\ncode_printing constant Ref_Time.update \\<rightharpoonup> (SML) \"(fn/ ()/ =>/ _/ :=/ _)\"\ncode_printing constant \"HOL.equal :: 'a ref \\<Rightarrow> 'a ref \\<Rightarrow> bool\" \\<rightharpoonup> (SML) infixl 6 \"=\"\n\ncode_reserved Eval Unsynchronized\n\n\ntext \\<open>OCaml\\<close>\n\ncode_printing type_constructor ref \\<rightharpoonup> (OCaml) \"_/ ref\"\ncode_printing constant Ref \\<rightharpoonup> (OCaml) \"failwith/ \\\"bare Ref\\\"\"\ncode_printing constant ref' \\<rightharpoonup> (OCaml) \"(fun/ ()/ ->/ ref/ _)\"\ncode_printing constant Ref_Time.lookup \\<rightharpoonup> (OCaml) \"(fun/ ()/ ->/ !/ _)\"\ncode_printing constant Ref_Time.update \\<rightharpoonup> (OCaml) \"(fun/ ()/ ->/ _/ :=/ _)\"\ncode_printing constant \"HOL.equal :: 'a ref \\<Rightarrow> 'a ref \\<Rightarrow> bool\" \\<rightharpoonup> (OCaml) infixl 4 \"=\"\n\ncode_reserved OCaml ref\n\n\ntext \\<open>Haskell\\<close>\n\ncode_printing type_constructor ref \\<rightharpoonup> (Haskell) \"Heap.STRef/ Heap.RealWorld/ _\"\ncode_printing constant Ref \\<rightharpoonup> (Haskell) \"error/ \\\"bare Ref\\\"\"\ncode_printing constant ref' \\<rightharpoonup> (Haskell) \"Heap.newSTRef\"\ncode_printing constant Ref_Time.lookup \\<rightharpoonup> (Haskell) \"Heap.readSTRef\"\ncode_printing constant Ref_Time.update \\<rightharpoonup> (Haskell) \"Heap.writeSTRef\"\ncode_printing constant \"HOL.equal :: 'a ref \\<Rightarrow> 'a ref \\<Rightarrow> bool\" \\<rightharpoonup> (Haskell) infix 4 \"==\"\ncode_printing class_instance ref :: HOL.equal \\<rightharpoonup> (Haskell) -\n\n\ntext \\<open>Scala\\<close>\n\ncode_printing type_constructor ref \\<rightharpoonup> (Scala) \"!Ref[_]\"\ncode_printing constant Ref \\<rightharpoonup> (Scala) \"!sys.error(\\\"bare Ref\\\")\"\ncode_printing constant ref' \\<rightharpoonup> (Scala) \"('_: Unit)/ =>/ Ref((_))\"\ncode_printing constant Ref_Time.lookup \\<rightharpoonup> (Scala) \"('_: Unit)/ =>/ Ref.lookup((_))\"\ncode_printing constant Ref_Time.update \\<rightharpoonup> (Scala) \"('_: Unit)/ =>/ Ref.update((_), (_))\"\ncode_printing constant \"HOL.equal :: 'a ref \\<Rightarrow> 'a ref \\<Rightarrow> bool\" \\<rightharpoonup> (Scala) infixl 5 \"==\"\n\nend\n", "meta": {"author": "bzhan", "repo": "Imperative_HOL_Time", "sha": "09f9bc7a7cf177d3adf1e9ce6adae09a85ebe5ec", "save_path": "github-repos/isabelle/bzhan-Imperative_HOL_Time", "path": "github-repos/isabelle/bzhan-Imperative_HOL_Time/Imperative_HOL_Time-09f9bc7a7cf177d3adf1e9ce6adae09a85ebe5ec/Ref_Time.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.27172933061375243}}
{"text": "(* Author: Pascal Stoop, ETH Zurich\n   Author: Andreas Lochbihler, Digital Asset *)\n\nsection \\<open>Lazy types in generated code\\<close>\n\ntheory Code_Lazy\nimports Case_Converter\nkeywords\n  \"code_lazy_type\"\n  \"activate_lazy_type\"\n  \"deactivate_lazy_type\"\n  \"activate_lazy_types\"\n  \"deactivate_lazy_types\"\n  \"print_lazy_types\" :: thy_decl\nbegin\n\ntext \\<open>\n  This theory and the CodeLazy tool described in \\<^cite>\\<open>\"LochbihlerStoop2018\"\\<close>.\n\n  It hooks into Isabelle's code generator such that the generated code evaluates a user-specified\n  set of type constructors lazily, even in target languages with eager evaluation.\n  The lazy type must be algebraic, i.e., values must be built from constructors and a\n  corresponding case operator decomposes them. Every datatype and codatatype is algebraic\n  and thus eligible for lazification.\n\\<close>\n\nsubsection \\<open>The type \\<open>lazy\\<close>\\<close>\n\ntypedef 'a lazy = \"UNIV :: 'a set\" ..\nsetup_lifting type_definition_lazy\nlift_definition delay :: \"(unit \\<Rightarrow> 'a) \\<Rightarrow> 'a lazy\"  is \"\\<lambda>f. f ()\" .\nlift_definition force :: \"'a lazy \\<Rightarrow> 'a\" is \"\\<lambda>x. x\" .\n\ncode_datatype delay\nlemma force_delay [code]: \"force (delay f) = f ()\" by transfer (rule refl)\nlemma delay_force: \"delay (\\<lambda>_. force s) = s\" by transfer (rule refl)\n\ndefinition termify_lazy2 :: \"'a :: typerep lazy \\<Rightarrow> term\"\n  where \"termify_lazy2 x =\n  Code_Evaluation.App (Code_Evaluation.Const (STR ''Code_Lazy.delay'') (TYPEREP((unit \\<Rightarrow> 'a) \\<Rightarrow> 'a lazy)))\n    (Code_Evaluation.Const (STR ''Pure.dummy_pattern'') (TYPEREP((unit \\<Rightarrow> 'a))))\"\n\ndefinition termify_lazy ::\n  \"(String.literal \\<Rightarrow> 'typerep \\<Rightarrow> 'term) \\<Rightarrow>\n   ('term \\<Rightarrow> 'term \\<Rightarrow> 'term) \\<Rightarrow>\n   (String.literal \\<Rightarrow> 'typerep \\<Rightarrow> 'term \\<Rightarrow> 'term) \\<Rightarrow>\n   'typerep \\<Rightarrow> ('typerep \\<Rightarrow> 'typerep \\<Rightarrow> 'typerep) \\<Rightarrow> ('typerep \\<Rightarrow> 'typerep) \\<Rightarrow>\n   ('a \\<Rightarrow> 'term) \\<Rightarrow> 'typerep \\<Rightarrow> 'a :: typerep lazy \\<Rightarrow> 'term \\<Rightarrow> term\"\n  where \"termify_lazy _ _ _ _ _ _ _ _ x _ = termify_lazy2 x\"\n\ndeclare [[code drop: \"Code_Evaluation.term_of :: _ lazy \\<Rightarrow> _\"]]\n\nlemma term_of_lazy_code [code]:\n  \"Code_Evaluation.term_of x \\<equiv>\n   termify_lazy\n     Code_Evaluation.Const Code_Evaluation.App Code_Evaluation.Abs\n     TYPEREP(unit) (\\<lambda>T U. typerep.Typerep (STR ''fun'') [T, U]) (\\<lambda>T. typerep.Typerep (STR ''Code_Lazy.lazy'') [T])\n     Code_Evaluation.term_of TYPEREP('a) x (Code_Evaluation.Const (STR '''') (TYPEREP(unit)))\"\n  for x :: \"'a :: {typerep, term_of} lazy\"\n  by (rule term_of_anything)\n\ntext \\<open>\n  The implementations of \\<^typ>\\<open>_ lazy\\<close> using language primitives cache forced values.\n\n  Term reconstruction for lazy looks into the lazy value and reconstructs it to the depth it has been evaluated.\n  This is not done for Haskell as we do not know of any portable way to inspect whether a lazy value\n  has been evaluated to or not.\n\\<close>\n\ncode_printing code_module Lazy \\<rightharpoonup> (SML)\n\\<open>signature LAZY =\nsig\n  type 'a lazy;\n  val lazy : (unit -> 'a) -> 'a lazy;\n  val force : 'a lazy -> 'a;\n  val peek : 'a lazy -> 'a option\n  val termify_lazy : \n   (string -> 'typerep -> 'term) -> \n   ('term -> 'term -> 'term) -> \n   (string -> 'typerep -> 'term -> 'term) ->\n   'typerep -> ('typerep -> 'typerep -> 'typerep) -> ('typerep -> 'typerep) ->\n   ('a -> 'term) -> 'typerep -> 'a lazy -> 'term -> 'term;\nend;\n\nstructure Lazy : LAZY = \nstruct\n\ndatatype 'a content =\n   Delay of unit -> 'a\n | Value of 'a \n | Exn of exn;\n\ndatatype 'a lazy = Lazy of 'a content ref;\n\nfun lazy f = Lazy (ref (Delay f));\n\nfun force (Lazy x) = case !x of\n   Delay f => (\n     let val res = f (); val _ = x := Value res; in res end\n     handle exn => (x := Exn exn; raise exn))\n  | Value x => x\n  | Exn exn => raise exn;\n\nfun peek (Lazy x) = case !x of\n    Value x => SOME x\n  | _ => NONE;\n\nfun termify_lazy const app abs unitT funT lazyT term_of T x _ =\n  app (const \"Code_Lazy.delay\" (funT (funT unitT T) (lazyT T))) \n    (case peek x of SOME y => abs \"_\" unitT (term_of y)\n     | _ => const \"Pure.dummy_pattern\" (funT unitT T));\n\nend;\\<close> for type_constructor lazy constant delay force termify_lazy\n| type_constructor lazy \\<rightharpoonup> (SML) \"_ Lazy.lazy\"\n| constant delay \\<rightharpoonup> (SML) \"Lazy.lazy\"\n| constant force \\<rightharpoonup> (SML) \"Lazy.force\"\n| constant termify_lazy \\<rightharpoonup> (SML) \"Lazy.termify'_lazy\"\n\ncode_reserved SML Lazy\n\ncode_printing \\<comment> \\<open>For code generation within the Isabelle environment, we reuse the thread-safe\n  implementation of lazy from \\<^file>\\<open>~~/src/Pure/Concurrent/lazy.ML\\<close>\\<close>\n  code_module Lazy \\<rightharpoonup> (Eval) \\<open>\\<close> for constant undefined\n| type_constructor lazy \\<rightharpoonup> (Eval) \"_ Lazy.lazy\"\n| constant delay \\<rightharpoonup> (Eval) \"Lazy.lazy\"\n| constant force \\<rightharpoonup> (Eval) \"Lazy.force\"\n| code_module Termify_Lazy \\<rightharpoonup> (Eval)\n\\<open>structure Termify_Lazy = struct\nfun termify_lazy\n  (_: string -> typ -> term) (_: term -> term -> term)  (_: string -> typ -> term -> term)\n  (_: typ) (_: typ -> typ -> typ) (_: typ -> typ)\n  (term_of: 'a -> term) (T: typ) (x: 'a Lazy.lazy) (_: term) =\n  Const (\"Code_Lazy.delay\", (HOLogic.unitT --> T) --> Type (\"Code_Lazy.lazy\", [T])) $\n  (case Lazy.peek x of\n    SOME (Exn.Res x) => absdummy HOLogic.unitT (term_of x)\n  | _ => Const (\"Pure.dummy_pattern\", HOLogic.unitT --> T));\nend;\\<close> for constant termify_lazy\n| constant termify_lazy \\<rightharpoonup> (Eval) \"Termify'_Lazy.termify'_lazy\"\n\ncode_reserved Eval Termify_Lazy\n\ncode_printing\n  type_constructor lazy \\<rightharpoonup> (OCaml) \"_ Lazy.t\"\n| constant delay \\<rightharpoonup> (OCaml) \"Lazy.from'_fun\"\n| constant force \\<rightharpoonup> (OCaml) \"Lazy.force\"\n| code_module Termify_Lazy \\<rightharpoonup> (OCaml)\n\\<open>module Termify_Lazy : sig\n  val termify_lazy :\n   (string -> 'typerep -> 'term) ->\n   ('term -> 'term -> 'term) ->\n   (string -> 'typerep -> 'term -> 'term) ->\n   'typerep -> ('typerep -> 'typerep -> 'typerep) -> ('typerep -> 'typerep) ->\n   ('a -> 'term) -> 'typerep -> 'a Lazy.t -> 'term -> 'term\nend = struct\n\nlet termify_lazy const app abs unitT funT lazyT term_of ty x _ =\n  app (const \"Code_Lazy.delay\" (funT (funT unitT ty) (lazyT ty)))\n    (if Lazy.is_val x then abs \"_\" unitT (term_of (Lazy.force x))\n     else const \"Pure.dummy_pattern\" (funT unitT ty));;\n\nend;;\\<close> for constant termify_lazy\n| constant termify_lazy \\<rightharpoonup> (OCaml) \"Termify'_Lazy.termify'_lazy\"\n\ncode_reserved OCaml Lazy Termify_Lazy\n\n\ncode_printing\n  code_module Lazy \\<rightharpoonup> (Haskell) \\<open>\nmodule Lazy(Lazy, delay, force) where\n\nnewtype Lazy a = Lazy a\ndelay f = Lazy (f ())\nforce (Lazy x) = x\\<close> for type_constructor lazy constant delay force\n| type_constructor lazy \\<rightharpoonup> (Haskell) \"Lazy.Lazy _\"\n| constant delay \\<rightharpoonup> (Haskell) \"Lazy.delay\"\n| constant force \\<rightharpoonup> (Haskell) \"Lazy.force\"\n\ncode_reserved Haskell Lazy\n\ncode_printing\n  code_module Lazy \\<rightharpoonup> (Scala) \n\\<open>object Lazy {\n  final class Lazy[A] (f: Unit => A) {\n    var evaluated = false;\n    lazy val x: A = f(())\n\n    def get() : A = {\n      evaluated = true;\n      return x\n    }\n  }\n\n  def force[A] (x: Lazy[A]) : A = {\n    return x.get()\n  }\n\n  def delay[A] (f: Unit => A) : Lazy[A] = {\n    return new Lazy[A] (f)\n  }\n\n  def termify_lazy[Typerep, Term, A] (\n    const: String => Typerep => Term,\n    app: Term => Term => Term,\n    abs: String => Typerep => Term => Term,\n    unitT: Typerep,\n    funT: Typerep => Typerep => Typerep,\n    lazyT: Typerep => Typerep,\n    term_of: A => Term,\n    ty: Typerep,\n    x: Lazy[A],\n    dummy: Term) : Term = {\n    if (x.evaluated)\n      app(const(\"Code_Lazy.delay\")(funT(funT(unitT)(ty))(lazyT(ty))))(abs(\"_\")(unitT)(term_of(x.get())))\n    else\n      app(const(\"Code_Lazy.delay\")(funT(funT(unitT)(ty))(lazyT(ty))))(const(\"Pure.dummy_pattern\")(funT(unitT)(ty)))\n  }\n}\\<close> for type_constructor lazy constant delay force termify_lazy\n| type_constructor lazy \\<rightharpoonup> (Scala) \"Lazy.Lazy[_]\"\n| constant delay \\<rightharpoonup> (Scala) \"Lazy.delay\"\n| constant force \\<rightharpoonup> (Scala) \"Lazy.force\"\n| constant termify_lazy \\<rightharpoonup> (Scala) \"Lazy.termify'_lazy\"\n\ncode_reserved Scala Lazy\n\ntext \\<open>Make evaluation with the simplifier respect \\<^term>\\<open>delay\\<close>s.\\<close>\n\nlemma delay_lazy_cong: \"delay f = delay f\" by simp\nsetup \\<open>Code_Simp.map_ss (Simplifier.add_cong @{thm delay_lazy_cong})\\<close>        \n\nsubsection \\<open>Implementation\\<close>\n\nML_file \\<open>code_lazy.ML\\<close>\n\nsetup \\<open>\n  Code_Preproc.add_functrans (\"lazy_datatype\", Code_Lazy.transform_code_eqs)\n\\<close>\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/Library/Code_Lazy.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.27172933061375243}}
{"text": "(*  Title:       BDD\n    Author:      Veronika Ortner and Norbert Schirmer, 2004\n    Maintainer:  Norbert Schirmer,  norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  \nNormalizeTotalProof.thy\n\nCopyright (C) 2004-2008 Veronika Ortner and Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nheader {* Proof of Procedure Normalize *}\ntheory NormalizeTotalProof imports LevellistProof ShareReduceRepListProof \n                        RepointProof begin\n\nhide_const (open) DistinctTreeProver.set_of tree.Node tree.Tip\n\nlemma  (in Normalize_impl) Normalize_modifies:\n  shows\n   \"\\<forall>\\<sigma>. \\<Gamma>\\<turnstile>{\\<sigma>} \\<acute>p :== PROC Normalize (\\<acute>p) \n     {t. t may_only_modify_globals \\<sigma> in [rep,mark,low,high,next]}\"\n  apply (hoare_rule HoarePartial.ProcRec1)\n  apply (vcg spec=modifies)\n  done\n\nlemma (in Normalize_impl) Normalize_spec: \n  shows \"\\<forall>\\<sigma> pret prebdt. \\<Gamma>\\<turnstile>\\<^sub>t\n  \\<lbrace>\\<sigma>. Dag \\<acute>p \\<acute>low \\<acute>high pret \\<and> ordered pret \\<acute>var \\<and> \n   \\<acute>p \\<noteq> Null \\<and> (\\<forall>n. n \\<in> set_of pret \\<longrightarrow> \\<acute>mark n = \\<acute>mark \\<acute>p) \\<and> \n   bdt pret \\<acute>var = Some prebdt\\<rbrace>  \n  \\<acute>p :== PROC Normalize(\\<acute>p)\n  \\<lbrace>(\\<forall>pt. pt \\<notin> set_of pret \n    \\<longrightarrow> \\<^bsup>\\<sigma>\\<^esup>rep pt = \\<acute>rep pt \\<and> \\<^bsup>\\<sigma>\\<^esup>low pt = \\<acute>low pt \\<and> \\<^bsup>\\<sigma>\\<^esup>high pt = \\<acute>high pt \\<and> \n        \\<^bsup>\\<sigma>\\<^esup>mark pt = \\<acute>mark pt \\<and> \\<^bsup>\\<sigma>\\<^esup>next pt = \\<acute>next pt) \\<and> \n  (\\<exists>postt. Dag \\<acute>p \\<acute>low \\<acute>high postt \\<and> reduced postt \\<and> \n  shared postt \\<^bsup>\\<sigma>\\<^esup>var \\<and> ordered postt \\<^bsup>\\<sigma>\\<^esup>var \\<and>\n  set_of postt \\<subseteq> set_of pret \\<and> \n  (\\<exists>postbdt.  bdt postt \\<^bsup>\\<sigma>\\<^esup>var = Some postbdt \\<and> prebdt \\<sim> postbdt)) \\<and> \n  (\\<forall> no. no \\<in> set_of pret \\<longrightarrow> \\<acute>mark no = (\\<not> \\<^bsup>\\<sigma>\\<^esup>mark \\<^bsup>\\<sigma>\\<^esup>p)) \\<rbrace>\"\n  apply (hoare_rule HoareTotal.ProcNoRec1)\n  apply (hoare_rule anno=\"\n    \\<acute>levellist :==replicate (\\<acute>p\\<rightarrow>\\<acute>var + 1) Null;;\n    \\<acute>levellist :== CALL Levellist (\\<acute>p, (\\<not> \\<acute>p\\<rightarrow>\\<acute>mark) , \\<acute>levellist);;\n    (ANNO (\\<tau>,ll). \\<lbrace>\\<tau>. Levellist \\<acute>levellist \\<acute>next ll \\<and>\n                   Dag \\<^bsup>\\<sigma>\\<^esup>p \\<^bsup>\\<sigma>\\<^esup>low \\<^bsup>\\<sigma>\\<^esup>high pret \\<and> ordered pret \\<^bsup>\\<sigma>\\<^esup>var \\<and> \\<^bsup>\\<sigma>\\<^esup>p \\<noteq> Null \\<and> \n                 (bdt pret \\<^bsup>\\<sigma>\\<^esup>var  = Some prebdt) \\<and> \n                 wf_ll pret ll \\<^bsup>\\<sigma>\\<^esup>var \\<and> \n                 length \\<acute>levellist = ((\\<^bsup>\\<sigma>\\<^esup>p \\<rightarrow> \\<^bsup>\\<sigma>\\<^esup>var) + 1) \\<and> \n                 wf_marking pret \\<^bsup>\\<sigma>\\<^esup>mark \\<acute>mark (\\<not> \\<^bsup>\\<sigma>\\<^esup>mark \\<^bsup>\\<sigma>\\<^esup>p) \\<and> \n                 (\\<forall>pt. pt \\<notin> set_of pret \\<longrightarrow> \\<^bsup>\\<sigma>\\<^esup>next pt = \\<acute>next pt) \\<and>\n                 \\<acute>low = \\<^bsup>\\<sigma>\\<^esup>low \\<and> \\<acute>high = \\<^bsup>\\<sigma>\\<^esup>high  \\<and>  \\<acute>p = \\<^bsup>\\<sigma>\\<^esup>p \\<and> \\<acute>rep = \\<^bsup>\\<sigma>\\<^esup>rep \\<and> \n                 \\<acute>var = \\<^bsup>\\<sigma>\\<^esup>var\\<rbrace> \n    \\<acute>n :==0;;\n    WHILE (\\<acute>n < length \\<acute>levellist) \n    INV \\<lbrace>Levellist \\<acute>levellist \\<acute>next ll \\<and>\n         Dag \\<^bsup>\\<sigma>\\<^esup>p \\<^bsup>\\<sigma>\\<^esup>low \\<^bsup>\\<sigma>\\<^esup>high pret \\<and> ordered pret \\<^bsup>\\<sigma>\\<^esup>var \\<and> \\<^bsup>\\<sigma>\\<^esup>p \\<noteq> Null \\<and> \n         (bdt pret \\<^bsup>\\<sigma>\\<^esup>var  = Some prebdt) \\<and> wf_ll pret ll \\<^bsup>\\<sigma>\\<^esup>var  \\<and> \n         length \\<^bsup>\\<tau>\\<^esup>levellist = ((\\<^bsup>\\<sigma>\\<^esup>p \\<rightarrow> \\<^bsup>\\<sigma>\\<^esup>var) + 1) \\<and> \n         wf_marking pret \\<^bsup>\\<sigma>\\<^esup>mark \\<^bsup>\\<tau>\\<^esup>mark (\\<not> \\<^bsup>\\<sigma>\\<^esup>mark \\<^bsup>\\<sigma>\\<^esup>p) \\<and>\n         \\<^bsup>\\<tau>\\<^esup>low = \\<^bsup>\\<sigma>\\<^esup>low \\<and> \\<^bsup>\\<tau>\\<^esup>high = \\<^bsup>\\<sigma>\\<^esup>high  \\<and>  \\<^bsup>\\<tau>\\<^esup>p = \\<^bsup>\\<sigma>\\<^esup>p \\<and> \\<^bsup>\\<tau>\\<^esup>rep = \\<^bsup>\\<sigma>\\<^esup>rep  \\<and> \\<^bsup>\\<tau>\\<^esup>var = \\<^bsup>\\<sigma>\\<^esup>var \\<and>\n         \\<acute>n \\<le> length  \\<^bsup>\\<tau>\\<^esup>levellist \\<and>\n         (\\<forall>pt i. (pt \\<notin> set_of pret \\<or> (\\<acute>n <= i \\<and> pt \\<in> set (ll ! i) \\<and>\n                  i <length \\<^bsup>\\<tau>\\<^esup>levellist ) \n                  \\<longrightarrow> \\<^bsup>\\<sigma>\\<^esup>rep pt = \\<acute>rep pt)) \\<and> \n         \\<acute>rep ` Nodes \\<acute>n ll \\<subseteq> Nodes \\<acute>n ll \\<and> \n         (\\<forall>no \\<in> Nodes \\<acute>n ll.\n            no\\<rightarrow>\\<acute>rep\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>var <= no\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>var \\<and> \n            (\\<exists>not nort. Dag (\\<acute>rep no) (\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>low ) (\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>high ) nort \\<and>\n               Dag no \\<^bsup>\\<sigma>\\<^esup>low \\<^bsup>\\<sigma>\\<^esup>high not \\<and> reduced nort \\<and> \n               ordered nort \\<^bsup>\\<sigma>\\<^esup>var \\<and> set_of nort \\<subseteq> \\<acute>rep ` Nodes \\<acute>n ll \\<and> \n               (\\<forall> no \\<in> set_of nort. \\<acute>rep no = no) \\<and> \n               (\\<exists>nobdt norbdt. bdt not \\<^bsup>\\<sigma>\\<^esup>var = Some nobdt \\<and> \n                  bdt nort \\<^bsup>\\<sigma>\\<^esup>var = Some norbdt \\<and> nobdt \\<sim> norbdt))) \\<and>\n         (\\<forall>t1 t2. \n             t1\\<in>Dags (\\<acute>rep `(Nodes \\<acute>n ll))(\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>low )(\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>high)\\<and>\n             t2\\<in>Dags (\\<acute>rep `(Nodes \\<acute>n ll))(\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>low )(\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>high)\n             \\<longrightarrow> \n             isomorphic_dags_eq t1 t2  \\<^bsup>\\<sigma>\\<^esup>var) \\<and>\n         \\<acute>levellist = \\<^bsup>\\<tau>\\<^esup>levellist \\<and> \\<acute>next = \\<^bsup>\\<tau>\\<^esup>next \\<and> \\<acute>mark = \\<^bsup>\\<tau>\\<^esup>mark \\<and> \\<acute>low = \\<^bsup>\\<sigma>\\<^esup>low \\<and> \n         \\<acute>high = \\<^bsup>\\<sigma>\\<^esup>high  \\<and> \\<acute>p = \\<^bsup>\\<sigma>\\<^esup>p \\<and>  \\<acute>var = \\<^bsup>\\<sigma>\\<^esup>var \\<rbrace>\n    VAR MEASURE (length \\<acute>levellist - \\<acute>n)\n    DO\n    CALL ShareReduceRepList(\\<acute>levellist ! \\<acute>n);;\n    \\<acute>n :==\\<acute>n + 1\n    OD\n    \\<lbrace>(\\<exists>postnormt. Dag (\\<acute>rep \\<^bsup>\\<sigma>\\<^esup>p) (\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>low ) (\\<acute>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>high ) postnormt \\<and> \n      reduced postnormt \\<and> shared postnormt \\<^bsup>\\<sigma>\\<^esup>var \\<and> \n      ordered postnormt \\<^bsup>\\<sigma>\\<^esup>var \\<and> set_of postnormt \\<subseteq> set_of pret \\<and> \n      (\\<exists>postnormbdt. bdt postnormt \\<^bsup>\\<sigma>\\<^esup>var = Some postnormbdt \\<and> prebdt \\<sim> postnormbdt) \\<and>\n      (\\<forall> no \\<in> set_of postnormt. (\\<acute>rep no = no))) \\<and> \n      ordered pret \\<^bsup>\\<sigma>\\<^esup>var  \\<and> \\<^bsup>\\<sigma>\\<^esup>p \\<noteq> Null \\<and> \n      (\\<forall> pt. pt \\<notin> set_of pret \\<longrightarrow> \\<^bsup>\\<sigma>\\<^esup>rep pt = \\<acute>rep pt) \\<and> \n      \\<acute>levellist = \\<^bsup>\\<tau>\\<^esup>levellist \\<and> \\<acute>next = \\<^bsup>\\<tau>\\<^esup>next \\<and> \\<acute>mark = \\<^bsup>\\<tau>\\<^esup>mark \\<and> \\<acute>low = \\<^bsup>\\<sigma>\\<^esup>low \\<and> \\<acute>high = \\<^bsup>\\<sigma>\\<^esup>high \\<and>\n      \\<acute>p = \\<^bsup>\\<sigma>\\<^esup>p \\<and> (\\<forall> no. no \\<in> set_of pret \\<longrightarrow> \\<acute>mark no = (\\<not> \\<^bsup>\\<sigma>\\<^esup>mark \\<^bsup>\\<sigma>\\<^esup>p)) \\<rbrace>)\n    ;;\n    \\<acute>p :== CALL Repoint (\\<acute>p)\"\n    in HoareTotal.annotateI)\n  apply (vcg spec=spec_total)\n  prefer 2\n    (*from precondition of inner spec to invariant *)\n  apply    (simp add: Nodes_def null_comp_def)\n    (*from inner spec to postcondition *) \n  apply   (rule_tac x=pret in exI)\n  apply   clarify\n  apply   (rule conjI)\n  apply    clarsimp\n  apply    (case_tac i)\n  apply     simp\n  apply    simp\n  apply   (rule conjI)\n  apply    simp\n  apply   (rule conjI)\n  apply    simp\n  apply   (rule conjI)\n  apply    simp\n  apply   clarify\n  apply   (simp (no_asm_use) only: simp_thms) \n  apply   (rule_tac x=\"ll\" in exI)\n  apply   (rule conjI)\n  apply    assumption\n  apply   clarify\n  apply   (simp only: simp_thms triv_forall_equality True_implies_equals) \n  apply   (rule_tac x=postnormt in exI)\n  apply   (rule conjI)\n  apply    simp\n  apply   (rule conjI)\n  apply    simp\n  apply   clarify\n  apply   (simp (no_asm_simp))\n  prefer 2\n    (*while-while-Fall: while nb und Schleifenbdg gelten \\<longrightarrow> while (nb+1)*)\n  apply   clarify\n  apply   (simp only: simp_thms triv_forall_equality True_implies_equals)\n  apply   (rule_tac x=\"ll!n\" in exI)\n  apply   (rule conjI)\n  apply   (simp add: Levellist_def)\n  prefer 3\n    (*while-end-Fall: INV nb gilt und Schleifenbdg falsch \\<longrightarrow> Nachbdg while*)\n  apply   (clarify)\n  apply   (simp (no_asm_use) only: simp_thms triv_forall_equality True_implies_equals) \nproof -\n  -- {* End of while (invariant + false condition) to end of inner SPEC *}\n  fix var p rep mark vara lowa higha pa levellista repa marka nexta varb ll  \n    nb pret prebdt  and low :: \"ref \\<Rightarrow> ref\" and \n    high :: \"ref \\<Rightarrow> ref\" and repb :: \"ref \\<Rightarrow> ref\"\n  assume ll: \"Levellist levellista nexta ll\"\n  assume wf_lla: \"wf_ll pret ll var\"\n  assume length_lla: \"length levellista = var p + 1\"\n  assume ord_pret: \"ordered pret var\"\n  assume pnN: \" p \\<noteq> Null\"\n  assume rep_repb_nc: \n    \"\\<forall>pt i. pt \\<notin> set_of pret \\<or> nb \\<le> i \\<and> pt \\<in> set (ll ! i) \\<and> \n    i < length levellista \n    \\<longrightarrow> rep pt = repb pt\"\n\n  assume wf_marking_prop: \" wf_marking pret mark marka (\\<not> mark p)\"\n  assume pret_dag: \"Dag p low high pret\"\n  assume prebdt: \"bdt pret var = Some prebdt\"\n  assume not_nbslla: \"\\<not> nb < length levellista\"\n  assume nb_le_lla: \" nb \\<le> length levellista\"\n  \n  assume normalize_prop: \"\\<forall>no\\<in>Nodes nb ll.\n    var (repb no) \\<le> var no \\<and>\n    (\\<exists>not nort. Dag (repb no) (repb \\<propto> low) (repb \\<propto> high) nort \\<and>\n    Dag no low high not \\<and> reduced nort \\<and> ordered nort var \\<and> \n    set_of nort \\<subseteq> repb ` Nodes nb ll \\<and> \n    (\\<forall>no\\<in>set_of nort. repb no = no) \\<and> \n    (\\<exists>nobdt norbdt. bdt not var = Some nobdt \\<and> \n    bdt nort var = Some norbdt \\<and> nobdt \\<sim> norbdt))\"\n  assume repbNodes_in_Nodes: \" repb ` Nodes nb ll \\<subseteq> Nodes nb ll\"\n  assume shared_mult_dags: \n    \"\\<forall>t1 t2. t1 \\<in> Dags (repb ` Nodes nb ll) (repb \\<propto> low) (repb \\<propto> high) \\<and> \n    t2 \\<in> Dags (repb ` Nodes nb ll) (repb \\<propto> low) (repb \\<propto> high) \n    \\<longrightarrow> isomorphic_dags_eq t1 t2 var\"\n  show \"(\\<exists>postnormt. Dag (repb p) (repb \\<propto> low) (repb \\<propto> high) postnormt \\<and>\n    reduced postnormt \\<and> shared postnormt var \\<and>\n    ordered postnormt var \\<and> set_of postnormt \\<subseteq> set_of pret \\<and> \n    (\\<exists>postnormbdt. \n    bdt postnormt var = Some postnormbdt \\<and> prebdt \\<sim> postnormbdt) \\<and> \n    (\\<forall> no \\<in> set_of postnormt. repb no = no)) \\<and>\n    ordered pret var \\<and> p \\<noteq> Null \\<and> \n    (\\<forall>pt. pt \\<notin> set_of pret \\<longrightarrow> rep pt = repb pt) \\<and>  \n    (\\<forall>no. no \\<in> set_of pret \\<longrightarrow> marka no = (\\<not> mark p))\"\n\n  proof -\n    from ll have length_ll_eq: \"length levellista = length ll\"\n      by (simp add: Levellist_length)\n    from rep_repb_nc have rep_nc_post: \"\\<forall>pt. pt \\<notin> set_of pret \\<longrightarrow> rep pt = repb pt\"\n      by auto\n    from pnN pret_dag obtain lt rt where pret_def: \"pret = Node lt p rt\"\n      by auto\n    from wf_marking_prop pret_def \n    have marking_inverted: \"(\\<forall>no. no \\<in> set_of pret \\<longrightarrow> marka no = (\\<not> mark p))\"\n      by (simp add: wf_marking_def)\n    from not_nbslla nb_le_lla have nb_length_lla: \"nb = length levellista\"\n      by simp\n    with length_lla have varp_s_nb: \"var p < nb\"\n      by simp\n    from pret_def have p_in_pret: \"p \\<in> set_of pret\"\n      by simp\n    with wf_lla have \"p \\<in> set (ll ! (var p))\" \n      by (simp add: wf_ll_def)\n    with varp_s_nb have p_in_Nodes: \"p \\<in> Nodes nb ll\"\n      by (auto simp add: Nodes_def)\n    with normalize_prop obtain not nort where\n      varrepno_varno: \" var (repb p) \\<le> var p\" and\n      nort_dag: \"Dag (repb p) (repb \\<propto> low) (repb \\<propto> high) nort\" and\n      not_dag: \" Dag p low high not\" and\n      red_nort: \"reduced nort\" and\n      ord_nort: \"ordered nort var\" and\n      nort_in_repNodes: \" set_of nort \\<subseteq> repb ` Nodes nb ll\" and\n      nort_repb: \"(\\<forall>no\\<in>set_of nort. repb no = no)\" and\n      bdt_prop: \"\\<exists>nobdt norbdt. bdt not var = Some nobdt \\<and> bdt nort var = Some norbdt \\<and>\n      nobdt \\<sim> norbdt\"\n      by auto\n    \n    from wf_lla nb_length_lla have Nodes_in_pret: \"Nodes nb ll \\<subseteq> set_of pret\"\n      apply -\n      apply (rule Nodes_in_pret)\n      apply (auto simp add: length_ll_eq)\n      done\n    from pret_dag wf_lla nb_length_lla have \"Null \\<notin> Nodes nb ll\"\n      apply -\n      apply (rule Null_notin_Nodes)\n      apply (auto simp add: length_ll_eq)\n      done\n    with p_in_Nodes repbNodes_in_Nodes have rp_nNull: \"repb p \\<noteq> Null\"\n      by auto\n    with nort_dag have nort_nTip: \"nort\\<noteq> Tip\"\n      by auto\n    have \"\\<exists>postnormt. Dag (repb p) (repb \\<propto> low) (repb \\<propto> high) postnormt \\<and>\n      reduced postnormt \\<and> shared postnormt var \\<and>\n      ordered postnormt var \\<and> set_of postnormt \\<subseteq> set_of pret \\<and> \n      (\\<exists>postnormbdt.  \n      bdt postnormt var = Some postnormbdt \\<and> prebdt \\<sim> postnormbdt) \\<and> \n      (\\<forall>no \\<in> set_of postnormt. repb no = no)\"\n    proof (rule_tac x=nort in exI)\n      from nort_in_repNodes repbNodes_in_Nodes Nodes_in_pret \n      have nort_in_pret: \"set_of nort \\<subseteq> set_of pret\"\n        by blast\n      from not_dag pret_dag have not_pret: \"not = pret\"\n        by (simp add: Dag_unique)\n      with bdt_prop prebdt have pret_bdt_prop: \n        \"\\<exists>postnormbdt.\n        bdt nort var = Some postnormbdt \\<and> prebdt \\<sim> postnormbdt\"\n        by auto\n      from shared_mult_dags have \"shared nort var\"\n      proof (auto simp add: shared_def isomorphic_dags_eq_def)\n        fix st1 st2 bdt1\n        assume shared_imp: \n          \"\\<forall>t1 t2. t1\\<in>Dags (repb ` Nodes nb ll) (repb \\<propto> low) (repb \\<propto> high) \\<and> \n          t2 \\<in> Dags (repb ` Nodes nb ll) (repb \\<propto> low) (repb \\<propto> high)\n          \\<longrightarrow>\n          (\\<exists>bdt1. bdt t1 var = Some bdt1 \\<and> bdt t2 var = Some bdt1) \\<longrightarrow> t1 = t2\"\n        assume st1_nort: \" st1 \\<le> nort\"\n        assume st2_nort: \"st2 \\<le> nort\"\n        assume bdt_st1: \"bdt st1 var = Some bdt1\"\n        assume bdt_st2: \" bdt st2 var = Some bdt1\"\n        from nort_in_repNodes nort_dag nort_nTip \n        have nort_in_DagsrNodes: \n          \"nort \\<in> Dags (repb `(Nodes nb ll)) (repb \\<propto> low) (repb \\<propto> high)\"\n          apply -\n          apply (rule DagsI)\n          apply auto\n          done\n        show \"st1 = st2\"\n        proof (cases st1)\n          case Tip\n          note st1_Tip=this\n          with bdt_st1 bdt_st2 show ?thesis\n            by auto\n        next\n          case (Node lst1 st1p rst1)\n          note st1_Node=this\n          then have st1_nTip: \"st1 \\<noteq> Tip\"\n            by simp\n          show ?thesis\n          proof (cases st2)\n            case Tip\n            with bdt_st1 bdt_st2 show ?thesis\n              by auto\n          next\n            case (Node lst2 st2p rst2)\n            note st2_Node=this\n            then have st2_nTip: \"st2 \\<noteq> Tip\"\n              by simp \n            from nort_in_DagsrNodes st1_nort ord_nort wf_lla st1_nTip \n            have st1_in_Dags: \n              \"st1 \\<in> Dags (repb ` Nodes nb ll) (repb \\<propto> low) (repb \\<propto> high)\"\n              apply -\n              apply (rule Dags_subdags)\n              apply auto\n              done\n            from nort_in_DagsrNodes st2_nort ord_nort wf_lla  st2_nTip \n            have st2_in_Dags: \n              \"st2 \\<in> Dags (repb ` Nodes nb ll) (repb \\<propto> low) (repb \\<propto> high)\"\n              apply -\n              apply (rule Dags_subdags) \n              apply auto\n              done\n            from st1_in_Dags st2_in_Dags bdt_st1 bdt_st2 shared_imp show \"st1=st2\"\n              by simp\n          qed\n        qed\n      qed\n      with nort_dag red_nort ord_nort nort_in_pret pret_bdt_prop nort_repb \n      show \"Dag (repb p) (repb \\<propto> low) (repb \\<propto> high) nort \\<and>\n        reduced nort \\<and> shared nort var \\<and> ordered nort var \\<and> \n        set_of nort \\<subseteq> set_of pret \\<and> \n        (\\<exists>postnormbdt. \n        bdt nort var = Some postnormbdt \\<and> prebdt \\<sim> postnormbdt) \\<and> \n        (\\<forall>no \\<in> set_of nort.  repb no = no)\"\n        apply -\n        apply (intro conjI)\n        apply assumption+\n        done\n    qed\n    with wf_lla length_lla ord_pret pnN rep_nc_post marking_inverted\n    show ?thesis\n      by simp\n  qed\nnext\n  -- {* From postcondition inner SPEC to final postcondition *}\n  fix var low high p rep levellist marka \"next\" \n    nexta lowb highb pb levellista ll repa pret prebdt \n    and mark::\"ref\\<Rightarrow>bool\" and postnormt postnormbdt\n  assume ll: \"Levellist levellista nexta ll\"\n  assume repoint_spec: \n         \"Dag pb lowb highb postnormt\"\n         \"\\<forall>pt. pt \\<notin> set_of postnormt \\<longrightarrow> low pt = lowb pt \\<and> high pt = highb pt\"\n  assume pret_dag: \"Dag p low high pret\"\n  assume ord_pret: \"ordered pret var\"\n  assume pnN: \" p \\<noteq> Null\"\n  assume onemark_pret: \n    \"\\<forall>n. n \\<in> set_of pret \\<longrightarrow> mark n = mark p\" (is \"\\<forall>n. ?in_pret n \\<longrightarrow> ?eq_mark_p n\")\n  assume pret_bdt: \" bdt pret var = Some prebdt\"\n  \n  assume  wf_ll: \"wf_ll pret ll var\"  and\n    length_ll:\"length levellist =var p + 1\" and\n    wf_marking_ll: \"wf_marking pret mark marka (\\<not> mark p)\"\n  assume  \n    postnormt_dag: \"Dag (repa p) (repa \\<propto> low) (repa \\<propto> high) postnormt\" and\n    reduced_postnormt: \"reduced postnormt\" and\n    shared_postnormt: \"shared postnormt var\" and\n    ordered_postnormt: \"ordered postnormt var\" and\n    subset_pret: \"set_of postnormt \\<subseteq> set_of pret\"and\n    sim_bdt: \"bdt postnormt var = Some postnormbdt\" \"prebdt \\<sim> postnormbdt\"  and\n    postdag_repa: \"\\<forall>no \\<in> set_of postnormt. repa no = no\" and\n    rep_eq: \"\\<forall>pt. pt \\<notin> set_of pret \\<longrightarrow> rep pt = repa pt\"  and\n    pret_marked: \"\\<forall>no. no \\<in> set_of pret \\<longrightarrow> marka no = (\\<not> mark p)\"\n  assume unmodif_next: \"\\<forall>p. p \\<notin> set_of pret \\<longrightarrow> next p = nexta p\"\n  show \"(\\<forall>pt. pt \\<notin> set_of pret \n    \\<longrightarrow> low pt = lowb pt \\<and> high pt = highb pt \\<and> \n    mark pt = marka pt ) \"\n\n  proof -\n    from ll have length_ll_eq: \"length levellista = length ll\"\n      by (simp add: Levellist_length)\n    from repoint_spec  pnN subset_pret\n    have repoint_nc: \"(\\<forall>pt. pt \\<notin> set_of pret \n      \\<longrightarrow> low pt = lowb pt \\<and> high pt = highb pt) \\<and> Dag pb lowb highb postnormt\"\n      by auto\n    then have lowhigh_b_eq: \"\\<forall>pt. pt \\<notin> set_of pret \n      \\<longrightarrow> low pt = lowb pt \\<and> high pt = highb pt\"\n      by fastforce\n    from wf_marking_ll pret_dag pnN \n    have mark_b_eq: \"\\<forall>pt. pt \\<notin> set_of pret \\<longrightarrow> mark pt = marka pt\"\n      apply -\n      apply (simp add: wf_marking_def)\n      apply (split dag.splits)\n      apply  simp\n      apply (rule allI)\n      apply (rule impI)\n      apply (elim conjE)\n      apply (erule_tac x=pt in allE)\n      apply fastforce\n      done\n    with lowhigh_b_eq rep_eq unmodif_next\n    have pret_nc: \"\\<forall>pt. pt \\<notin> set_of pret \n      \\<longrightarrow> rep pt = repa pt \\<and> low pt = lowb pt \\<and> high pt = highb pt \\<and> \n      mark pt = marka pt \\<and> next pt = nexta pt\"\n      by blast\n(*    from repoint_nc have rept_dag: \"Dag pb lowb highb postnormt\"\n      by simp\n    with reduced_postnormt shared_postnormt ordered_postnormt subset_pret sim_bdt \n      pret_bdt \n    have post_same_prop: \n      \"\\<exists>postt. Dag pb lowb highb postt \\<and> reduced postt \\<and>\n      shared postt var \\<and> ordered postt var \\<and> set_of postt \\<subseteq> set_of pret \\<and>\n      (\\<exists>postbdt. bdt postt var = Some postbdt \\<and> prebdt \\<sim> postbdt)\" \n      apply -\n      apply (rule_tac x=postnormt in exI)\n      apply fastforce\n      done*)\n    from pret_nc  \n    show ?thesis\n      by fastforce\n  qed\nnext\n  -- {* invariant to invariant *}\n  fix var low high p rep mark pret prebdt levellist ll \"next\" marka n repc \n    and repb :: \"ref \\<Rightarrow> ref\"  \n  assume ll: \"Levellist levellist next ll\"\n  assume pret_dag: \"Dag p low high pret\"\n  assume ord_pret: \" ordered pret var\"\n  assume pnN: \"p \\<noteq> Null\"\n  assume prebdt_pret: \"bdt pret var = Some prebdt\"\n  assume wf_ll: \"wf_ll pret ll var\"\n  assume lll: \"length levellist = var p + 1\"\n  assume n_Suc_var_p: \"n < var p + 1\"\n  assume wf_marking_m_ma: \"wf_marking pret mark marka (\\<not> mark p)\"\n\n(*  assume rep_nc: \" \\<forall>pt. pt \\<notin> set_of pret \\<or> \n    (\\<exists>i. n \\<le> i \\<and> pt \\<in> set (ll ! i) \\<and> i < var p + 1) \n    \\<longrightarrow> rep pt = repb pt\" *)\n  assume rep_nc:      \"\\<forall>pt i.\n           pt \\<notin> set_of pret \\<or> n \\<le> i \\<and> pt \\<in> set (ll ! i) \\<and> i < var p + 1 \\<longrightarrow>\n           rep pt = repb pt\"\n  assume repbNodes_in_Nodes: \"repb ` Nodes n ll \\<subseteq> Nodes n ll\"\n  assume\n    normalize_prop: \"\\<forall>no\\<in>Nodes n ll.\n    var (repb no) \\<le> var no \\<and>\n    (\\<exists>not nort. Dag (repb no) (repb \\<propto> low) (repb \\<propto> high) nort \\<and>\n    Dag no low high not \\<and> reduced nort \\<and> ordered nort var \\<and>\n    set_of nort \\<subseteq> repb ` Nodes n ll \\<and>\n    (\\<forall>no\\<in>set_of nort. repb no = no) \\<and>\n    (\\<exists>nobdt. bdt not var = Some nobdt \\<and> \n    (\\<exists>norbdt. bdt nort var = Some norbdt \\<and> \n    nobdt \\<sim> norbdt)))\" \n  assume \n    isomorphic_dags_eq: \n    \"\\<forall>t1 t2. t1 \\<in> Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high)\\<and>\n    t2 \\<in> Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high) \n    \\<longrightarrow> isomorphic_dags_eq t1 t2 var\"\n  show \"(\\<forall>no\\<in>set (ll ! n).\n              no \\<noteq> Null \\<and>\n              (low no = Null) = (high no = Null) \\<and>\n              low no \\<notin> set (ll ! n) \\<and>\n              high no \\<notin> set (ll ! n) \\<and>\n              isLeaf_pt no low high = (var no \\<le> 1) \\<and>\n              (low no \\<noteq> Null \\<longrightarrow> repb (low no) \\<noteq> Null) \\<and> (repb \\<propto> low) no \\<notin> set (ll ! n)) \\<and>\n          (\\<forall>no1\\<in>set (ll ! n). \\<forall>no2\\<in>set (ll ! n). var no1 = var no2) \\<and>\n          (\\<forall>repa. (\\<forall>no. no \\<notin> set (ll ! n) \\<longrightarrow> repb no = repa no) \\<and>\n                  (\\<forall>no\\<in>set (ll ! n).\n                      repa no \\<noteq> Null \\<and>\n                      (if (repa \\<propto> low) no = (repa \\<propto> high) no \\<and> low no \\<noteq> Null\n                       then repa no = (repa \\<propto> low) no\n                       else repa no \\<in> set (ll ! n) \\<and>\n                            repa (repa no) = repa no \\<and>\n                            (\\<forall>no1\\<in>set (ll ! n).\n                                ((repa \\<propto> high) no1 = (repa \\<propto> high) no \\<and>\n                                 (repa \\<propto> low) no1 = (repa \\<propto> low) no) =\n                                (repa no = repa no1)))) \\<longrightarrow>\n                  var p + 1 - (n + 1) < var p + 1 - n \\<and>\n                  n + 1 \\<le> var p + 1 \\<and>\n                  (\\<forall>pt i. pt \\<notin> set_of pret \\<or> (n + 1 \\<le> i \\<and> pt \\<in> set (ll ! i) \\<and> i < var p + 1) \\<longrightarrow>\n                        rep pt = repa pt) \\<and>\n                  repa ` Nodes (n + 1) ll \\<subseteq> Nodes (n + 1) ll \\<and>\n                  (\\<forall>no\\<in>Nodes (n + 1) ll.\n                      var (repa no) \\<le> var no \\<and>\n                      (\\<exists>not nort.\n                          Dag (repa no) (repa \\<propto> low) (repa \\<propto> high) nort \\<and>\n                          Dag no low high not \\<and>\n                          reduced nort \\<and>\n                          ordered nort var \\<and>\n                          set_of nort \\<subseteq> repa ` Nodes (n + 1) ll \\<and>\n                          (\\<forall>no\\<in>set_of nort. repa no = no) \\<and>\n                          (\\<exists>nobdt.\n                              bdt not var = Some nobdt \\<and>\n                              (\\<exists>norbdt. bdt nort var = Some norbdt \\<and> nobdt \\<sim> norbdt)))) \\<and>\n                  (\\<forall>t1 t2.\n                      t1 \\<in> Dags (repa ` Nodes (n + 1) ll) (repa \\<propto> low) (repa \\<propto> high) \\<and>\n                      t2 \\<in> Dags (repa ` Nodes (n + 1) ll) (repa \\<propto> low) (repa \\<propto> high) \\<longrightarrow>\n                      isomorphic_dags_eq t1 t2 var))\"\n  proof -\n    from ll have length_ll_eq: \"length levellist = length ll\"\n      by (simp add: Levellist_length)\n    from n_Suc_var_p lll have nsll: \"n < length levellist\" by simp\n    hence nseqll: \"n \\<le> length levellist\" by simp\n    have srrl_precond: \"(\\<forall>no \\<in> set (ll ! n).\n      no \\<noteq> Null \\<and>\n      (low no = Null) = (high no = Null) \\<and>\n      low no \\<notin> set (ll ! n) \\<and>\n      high no \\<notin> set (ll ! n) \\<and> \n      isLeaf_pt no low high = (var no \\<le> 1) \\<and> \n      (low no \\<noteq> Null \\<longrightarrow> repb (low no) \\<noteq> Null) \\<and> \n      (repb \\<propto> low) no \\<notin> set (ll ! n))\"\n    proof (intro ballI)\n      fix no\n      assume no_in_lln: \"no \\<in> set (ll ! n)\"\n      with wf_ll nsll have no_in_pret_var: \"no \\<in> set_of pret \\<and> var no = n\"\n        by (simp add: wf_ll_def length_ll_eq)\n      with pret_dag have no_nNull: \"no \\<noteq> Null\"\n        apply -\n        apply (rule set_of_nn)\n        apply auto\n        done\n      from pret_dag prebdt_pret no_in_pret_var \n      have balanced_no: \"(low no = Null) = (high no = Null)\"\n        apply -\n        apply (erule conjE)\n        apply (rule_tac p=p and low=low in balanced_bdt)\n        apply auto\n        done\n      have low_no_notin_lln: \"low no \\<notin> set (ll ! n)\"\n      proof (cases \"low no = Null\")\n        case True\n        note lno_Null=this\n        with balanced_no have hno_Null: \"high no = Null\"\n          by simp\n        show ?thesis\n        proof (cases \"low no \\<in> set (ll ! n)\") \n          case True\n          with wf_ll nsll have \"low no \\<in> set_of pret \\<and> var (low no) = n\"\n            by (auto simp add: wf_ll_def length_ll_eq)\n          with pret_dag have \"low no \\<noteq> Null\"\n            apply -\n            apply (rule set_of_nn)\n            apply auto\n            done\n          with lno_Null show ?thesis\n            by simp\n        next\n          assume lno_notin_lln: \"low no \\<notin> set (ll ! n)\"\n          then show ?thesis\n            by simp\n        qed\n      next\n        assume lno_nNull: \"low no \\<noteq> Null\"\n        with balanced_no have hno_nNull: \"high no \\<noteq> Null\"\n          by simp\n        with lno_nNull pret_dag ord_pret no_in_pret_var \n        have var_children_smaller: \"var (low no) < var no \\<and> var (high no) < var no\" \n          apply -\n          apply (rule var_ordered_children)\n          apply auto\n          done\n        show ?thesis\n        proof (cases \"low no \\<in> set (ll ! n)\")\n          case True\n          with wf_ll nsll have \"low no \\<in> set_of pret \\<and> var (low no) = n\"\n            by (simp add: wf_ll_def length_ll_eq)\n          with var_children_smaller no_in_pret_var show ?thesis\n            by simp\n        next\n          assume \"low no \\<notin> set (ll ! n)\"\n          thus ?thesis\n            by simp\n        qed\n      qed\n      have high_no_notin_lln: \"high no \\<notin> set (ll ! n)\"\n      proof (cases \"high no = Null\")\n        case True\n        note hno_Null=this\n        with balanced_no have lno_Null: \"low no = Null\"\n          by simp\n        show ?thesis\n        proof (cases \"high no \\<in> set (ll ! n)\") \n          case True\n          with wf_ll nsll have \"high no \\<in> set_of pret \\<and> var (high no) = n\"\n            by (auto simp add: wf_ll_def length_ll_eq)\n          with pret_dag have \"high no \\<noteq> Null\"\n            apply -\n            apply (rule set_of_nn)\n            apply auto\n            done\n          with hno_Null show ?thesis\n            by simp\n        next\n          assume hno_notin_lln: \"high no \\<notin> set (ll ! n)\"\n          then show ?thesis\n            by simp\n        qed\n      next\n        assume hno_nNull: \"high no \\<noteq> Null\"\n        with balanced_no have lno_nNull: \"low no \\<noteq> Null\"\n          by simp\n        with hno_nNull pret_dag ord_pret no_in_pret_var \n        have var_children_smaller: \"var (low no) < var no \\<and> var (high no) < var no\" \n          apply -\n          apply (rule var_ordered_children)\n          apply auto\n          done\n        show ?thesis\n        proof (cases \"high no \\<in> set (ll ! n)\")\n          case True\n          with wf_ll nsll have \"high no \\<in> set_of pret \\<and> var (high no) = n\"\n            by (simp add: wf_ll_def length_ll_eq)\n          with var_children_smaller no_in_pret_var show ?thesis\n            by simp\n        next\n          assume \"high no \\<notin> set (ll ! n)\"\n          thus ?thesis\n            by simp\n        qed\n      qed \n      from no_in_pret_var pret_dag no_nNull obtain not where \n        no_dag_ex: \"Dag no low high not\"\n        apply -\n        apply (rotate_tac 2)\n        apply (drule subnode_dag_cons)\n        apply (auto simp del: Dag_Ref)\n        done\n      with pret_dag prebdt_pret no_in_pret_var obtain nobdt \n        where nobdt_ex: \n        \"bdt not var = Some nobdt\"\n        apply -\n        apply (drule subbdt_ex_dag_def)\n        apply auto\n        done\n      have isLeaf_var: \"isLeaf_pt no low high = (var no \\<le> 1)\"\n      proof\n        assume no_isLeaf: \"isLeaf_pt no low high\"\n        from nobdt_ex no_dag_ex no_isLeaf show \"var no \\<le> 1\"\n          apply -\n          apply (rule bdt_Some_Leaf_var_le_1)\n          apply auto\n          done\n      next\n        assume varno_le_1: \"var no \\<le> 1\"\n        show \"isLeaf_pt no low high\"\n        proof (cases \"var no = 0\")\n          case True\n          with nobdt_ex no_nNull no_dag_ex have \"not = Node Tip no Tip\" \n            apply -\n            apply (drule bdt_Some_var0_Zero)\n            apply auto\n            done\n          with no_dag_ex show \"isLeaf_pt no low high\"\n            by (simp add: isLeaf_pt_def)\n        next\n          assume \"var no \\<noteq> 0\"\n          with varno_le_1 have \"var no = 1\"\n            by simp\n          with nobdt_ex no_nNull no_dag_ex have \"not = Node Tip no Tip\"\n            apply -\n            apply (drule bdt_Some_var1_One)\n            apply auto\n            done\n          with no_dag_ex show \"isLeaf_pt no low high\"\n            by (simp add: isLeaf_pt_def)\n        qed\n      qed\n      have repb_low_nNull: \"(low no \\<noteq> Null \\<longrightarrow> repb (low no) \\<noteq> Null)\"\n      proof\n        assume lno_nNull: \"low no \\<noteq> Null\"\n        with no_nNull no_in_pret_var pret_dag have lno_in_pret: \"low no \\<in> set_of pret\"\n          apply -\n          apply (rule_tac low=low in subelem_set_of_low)\n          apply auto\n          done\n        from lno_nNull balanced_no have hno_nNull: \"high no \\<noteq> Null\"\n          by simp\n        with lno_nNull pret_dag ord_pret no_in_pret_var \n        have var_children_smaller: \"var (low no) < var no \\<and> var (high no) < var no\" \n          apply -\n          apply (rule var_ordered_children)\n          apply auto\n          done \n        with no_in_pret_var have var_lno_l_n: \"var (low no) <n\"\n          by simp\n        with wf_ll lno_in_pret nsll have \"low no \\<in> set (ll ! (var (low no)))\"\n          by (simp add: wf_ll_def length_ll_eq)\n        with lno_in_pret var_lno_l_n have \"low no \\<in> Nodes n ll\"\n          apply (simp add: Nodes_def)\n          apply (rule_tac x=\"var (low no)\" in exI)\n          apply simp\n          done\n        hence \"repb (low no) \\<in> repb ` Nodes n ll\"\n          by simp\n        with repbNodes_in_Nodes have repb_lno_in_Nodes: \n          \"repb (low no) \\<in> Nodes n ll\"\n          by blast\n        from pret_dag wf_ll nsll have \"Null \\<notin> Nodes n ll\"\n          apply -\n          apply (rule Null_notin_Nodes)\n          apply (auto simp add: length_ll_eq)\n          done \n        with repb_lno_in_Nodes show \"repb (low no) \\<noteq> Null\"\n          by auto\n      qed\n      have Null_notin_lln: \"Null \\<notin> set (ll ! n)\"\n      proof (cases \"Null \\<in> set (ll ! n)\")\n        case True\n        with wf_ll nsll have \"Null \\<in> set_of pret \\<and> var (Null) = n\" \n          by (simp add: wf_ll_def length_ll_eq)\n        with pret_dag have \"Null \\<noteq> Null\"\n          apply -\n          apply (rule set_of_nn)\n          apply auto\n          done\n        thus ?thesis\n          by auto\n      next\n        assume \"Null \\<notin> set (ll ! n)\"\n        thus ?thesis\n          by simp\n      qed\n      have \"(repb \\<propto> low) no \\<notin> set (ll ! n)\"\n      proof (cases \"low no = Null\")  \n        case True\n        with Null_notin_lln show ?thesis\n          by (simp add: null_comp_def)\n      next\n        assume lno_nNull: \"low no \\<noteq> Null\"\n        with no_nNull no_in_pret_var pret_dag have lno_in_pret: \"low no \\<in> set_of pret\"\n          apply -\n          apply (rule_tac low=low in subelem_set_of_low)\n          apply auto\n          done\n        from lno_nNull have propto_eq_comp: \"(repb \\<propto> low) no = repb (low no)\"\n          by (simp add: null_comp_def)\n        from lno_nNull balanced_no have hno_nNull: \"high no \\<noteq> Null\"\n          by simp\n        with lno_nNull pret_dag ord_pret no_in_pret_var \n        have var_children_smaller: \"var (low no) < var no \\<and> var (high no) < var no\" \n          apply -\n          apply (rule var_ordered_children)\n          apply auto\n          done \n        with no_in_pret_var have var_lno_l_n: \"var (low no) <n\"\n          by simp\n        with wf_ll lno_in_pret nsll have \"low no \\<in> set (ll ! (var (low no)))\"\n          by (simp add: wf_ll_def length_ll_eq)\n        with lno_in_pret var_lno_l_n have lno_in_Nodes_n: \"low no \\<in> Nodes n ll\"\n          apply (simp add: Nodes_def)\n          apply (rule_tac x=\"var (low no)\" in exI)\n          apply simp\n          done\n        hence \"repb (low no) \\<in> repb ` Nodes n ll\"\n          by simp\n        with  repbNodes_in_Nodes have repb_lno_in_Nodes: \n          \"repb (low no) \\<in> Nodes n ll\"\n          by blast\n        with lno_in_Nodes_n normalize_prop have \"var (repb (low no)) \\<le> var (low no)\" \n          by auto\n        with var_lno_l_n have var_rep_lno_l_n: \" var (repb (low no)) < n\"\n          by simp\n        with repb_lno_in_Nodes have \"\\<exists> k < n. repb (low no) \\<in> set (ll ! k)\"\n          by (auto simp add: Nodes_def)\n        with wf_ll propto_eq_comp nsll show \" (repb \\<propto> low) no \\<notin> set (ll ! n)\"\n          apply -\n          apply (erule exE)\n          apply (rule_tac i=k and j=n in no_in_one_ll)\n          apply (auto simp add: length_ll_eq)\n          done\n      qed\n      with no_nNull balanced_no low_no_notin_lln high_no_notin_lln isLeaf_var repb_low_nNull\n      show \" no \\<noteq> Null \\<and>\n        (low no = Null) = (high no = Null) \\<and>\n        low no \\<notin> set (ll ! n) \\<and> high no \\<notin> set (ll ! n) \\<and> \n        isLeaf_pt no low high = (var no \\<le> 1) \\<and> \n        (low no \\<noteq> Null \\<longrightarrow> repb (low no) \\<noteq> Null) \\<and> \n        (repb \\<propto> low) no \\<notin> set (ll ! n)\"\n        by auto\n    qed\n    have all_nodes_same_var: \"\\<forall>no1 \\<in> set (ll ! n). \\<forall>no2 \\<in> set (ll ! n). var no1 = var no2\"\n    proof (intro ballI impI)\n      fix no1 no2\n      assume \"no1 \\<in> set (ll ! n)\"\n      with wf_ll nsll have var_lln_i: \"var no1 = n\"\n        by (simp add: wf_ll_def length_ll_eq)\n      assume \"no2 \\<in> set (ll ! n)\"\n      with wf_ll nsll have \"var no2 = n\"\n        by (simp add: wf_ll_def length_ll_eq)\n      with var_lln_i show \" var no1 = var no2\"\n        by simp\n    qed\n    have  \"(\\<forall>repa. (\\<forall>no. no \\<notin> set (ll ! n) \\<longrightarrow> repb no = repa no) \\<and>\n                  (\\<forall>no\\<in>set (ll ! n).\n                      repa no \\<noteq> Null \\<and>\n                      (if (repa \\<propto> low) no = (repa \\<propto> high) no \\<and> low no \\<noteq> Null\n                       then repa no = (repa \\<propto> low) no\n                       else repa no \\<in> set (ll ! n) \\<and>\n                            repa (repa no) = repa no \\<and>\n                            (\\<forall>no1\\<in>set (ll ! n).\n                                ((repa \\<propto> high) no1 = (repa \\<propto> high) no \\<and>\n                                 (repa \\<propto> low) no1 = (repa \\<propto> low) no) =\n                                (repa no = repa no1)))) \\<longrightarrow>\n                  var p + 1 - (n + 1) < var p + 1 - n \\<and>\n                  n + 1 \\<le> var p + 1 \\<and>\n                  (\\<forall>pt i. pt \\<notin> set_of pret \\<or> (n + 1 \\<le> i \\<and> pt \\<in> set (ll ! i) \\<and> i < var p + 1) \\<longrightarrow>\n                        rep pt = repa pt) \\<and>\n                  repa ` Nodes (n + 1) ll \\<subseteq> Nodes (n + 1) ll \\<and>\n                  (\\<forall>no\\<in>Nodes (n + 1) ll.\n                      var (repa no) \\<le> var no \\<and>\n                      (\\<exists>not nort.\n                          Dag (repa no) (repa \\<propto> low) (repa \\<propto> high) nort \\<and>\n                          Dag no low high not \\<and>\n                          reduced nort \\<and>\n                          ordered nort var \\<and>\n                          set_of nort \\<subseteq> repa ` Nodes (n + 1) ll \\<and>\n                          (\\<forall>no\\<in>set_of nort. repa no = no) \\<and>\n                          (\\<exists>nobdt.\n                              bdt not var = Some nobdt \\<and>\n                              (\\<exists>norbdt. bdt nort var = Some norbdt \\<and> nobdt \\<sim> norbdt)))) \\<and>\n                  (\\<forall>t1 t2.\n                      t1 \\<in> Dags (repa ` Nodes (n + 1) ll) (repa \\<propto> low) (repa \\<propto> high) \\<and>\n                      t2 \\<in> Dags (repa ` Nodes (n + 1) ll) (repa \\<propto> low) (repa \\<propto> high) \\<longrightarrow>\n                      isomorphic_dags_eq t1 t2 var))\"\n      (is \"(\\<forall>repc. ?srrl_post repc \\<longrightarrow> ?norm_inv repc) \") \n    proof (intro allI impI, elim conjE)\n      fix repc\n      assume repbc_nc: \"\\<forall>no. no \\<notin> set (ll ! n) \\<longrightarrow> repb no = repc no\"\n      assume rep_prop: \" \\<forall>no\\<in>set (ll ! n).\n        repc no \\<noteq> Null \\<and>\n               (if (repc \\<propto> low) no = (repc \\<propto> high) no \\<and> low no \\<noteq> Null\n                then repc no = (repc \\<propto> low) no\n                else repc no \\<in> set (ll ! n) \\<and>\n                     repc (repc no) = repc no \\<and>\n                     (\\<forall>no1\\<in>set (ll ! n).\n                         ((repc \\<propto> high) no1 = (repc \\<propto> high) no \\<and>\n                          (repc \\<propto> low) no1 = (repc \\<propto> low) no) =\n                         (repc no = repc no1)))\"\n      show \"?norm_inv repc\"\n      proof -\n        from n_Suc_var_p have termi: \"var p + 1 - (n + 1) < var p + 1 - n\"\n          by arith\n        from wf_ll repbc_nc nsll \n        have Nodes_n_rep_nc: \"\\<forall>p. p \\<in> Nodes n ll \\<longrightarrow> repb p = repc p\"\n          apply -\n          apply (rule allI)\n          apply (rule impI)\n          apply (simp add: Nodes_def)\n          apply (erule exE)\n          apply (erule_tac x=p in allE)\n          apply (drule_tac i=k and j=n in no_in_one_ll)\n          apply (auto simp add: length_ll_eq)\n          done\n        from repbNodes_in_Nodes \n        have Nodes_n_rep_in_Nodesn: \n          \"\\<forall> p. p \\<in> Nodes n ll \\<longrightarrow> repb p \\<in> Nodes n ll\"\n          by auto\n        from wf_ll nsll have \"Nodes n ll \\<subseteq> set_of pret\"\n          apply -\n          apply (rule Nodes_in_pret)\n          apply (auto simp add: length_ll_eq)\n          done\n        with Nodes_n_rep_in_Nodesn  \n        have Nodes_n_rep_in_pret: \"\\<forall>p. p \\<in> Nodes n ll \\<longrightarrow> repb p \\<in> set_of pret\"\n          apply -\n          apply (intro allI impI)\n          apply blast\n          done\n        have Nodes_repbc_Dags_eq: \"\\<forall>p t. p \\<in> Nodes n ll \n          \\<longrightarrow> Dag (repb p) (repb \\<propto> low) (repb \\<propto> high) t = \n          Dag (repc p) (repc \\<propto> low) (repc \\<propto> high) t\"\n        proof (intro allI impI)\n          fix p t\n          assume p_in_Nodes: \" p \\<in> Nodes n ll\"\n          then have repp_nc: \"repb p = repc p\"\n            by (rule Nodes_n_rep_nc [rule_format])\n          from p_in_Nodes normalize_prop obtain nort where\n            nort_repb_dag: \"Dag (repb p) (repb \\<propto> low) (repb \\<propto> high) nort\" and\n            nort_in_repbNodes: \"set_of nort \\<subseteq> repb ` Nodes n ll\"\n            apply -\n            apply (erule_tac x=p in ballE)\n            prefer 2\n            apply auto\n            done\n          from nort_in_repbNodes repbNodes_in_Nodes \n          have nort_in_Nodesn: \"set_of nort \\<subseteq> Nodes n ll\"\n            by blast\n          from pret_dag wf_ll nsll have \"Null \\<notin> Nodes n ll\"\n            apply -\n            apply (rule Null_notin_Nodes)\n            apply (auto simp add: length_ll_eq)\n            done\n          with p_in_Nodes repbNodes_in_Nodes have repp_nNull: \"repb p \\<noteq> Null\"\n            by auto\n          from nort_repb_dag repp_nc \n          have nort_repbc_dag: \"Dag (repc p) (repb \\<propto> low) (repb \\<propto> high) nort\"\n            by simp\n          from nort_in_Nodesn have \"\\<forall>x \\<in> set_of nort. x \\<in> Nodes n ll\"\n            apply -\n            apply (rule ballI)\n            apply blast\n            done\n          with wf_ll nsll  have \"\\<forall>x \\<in> set_of nort. x \\<in> set_of pret \\<and> var x < n\"\n            apply -\n            apply (rule ballI)\n            apply (rule wf_ll_Nodes_pret)\n            apply (auto simp add: length_ll_eq)\n            done\n          with pret_dag prebdt_pret nort_repbc_dag ord_pret wf_ll  nsll repbc_nc \n          have \n            \"\\<forall> x \\<in> set_of nort. (repc \\<propto> low) x = (repb \\<propto> low) x \\<and> \n            (repc \\<propto> high) x = (repb \\<propto> high) x\"\n            apply -\n            apply (rule nort_null_comp)\n            apply (auto simp add: length_ll_eq)\n            done\n          with nort_repbc_dag repp_nc \n          have \"Dag (repc p) (repb \\<propto> low) (repb \\<propto> high) nort = \n            Dag (repc p) (repc \\<propto> low) (repc \\<propto> high) nort\"\n            apply -\n            apply (rule heaps_eq_Dag_eq)\n            apply (rule ballI)\n            apply (erule_tac x=x in ballE)\n            apply (elim conjE)\n            apply (rule conjI)\n            apply auto\n            done\n          with nort_repbc_dag repp_nc show \n            \"Dag (repb p) (repb \\<propto> low) (repb \\<propto> high) t = \n            Dag (repc p) (repc \\<propto> low) (repc \\<propto> high) t\"\n            apply auto\n            apply (rotate_tac 2)\n            apply (frule_tac Dag_unique)\n            apply (rotate_tac 1)\n            apply simp\n            apply simp\n            apply (frule Dag_unique)\n            apply (rotate_tac 3)\n            apply simp\n            apply simp\n            done\n        qed\n        from rep_prop have repbc_changes: \"\\<forall>no\\<in>set (ll ! n).\n          repc no \\<noteq> Null \\<and>\n          (if (repc \\<propto> low) no = (repc \\<propto> high) no \\<and> low no \\<noteq> Null \n          then repc no = (repc \\<propto> low) no\n          else repc no \\<in> set (ll ! n) \\<and> repc (repc no) = repc no \\<and> \n          (\\<forall>no1\\<in>set (ll ! n). ((repc \\<propto> high) no1 = (repc \\<propto> high) no \\<and> \n          (repc \\<propto> low) no1 = (repc \\<propto> low) no) = (repc no = repc no1)))\"\n          by blast\n        from nsll lll  have n_var_prop: \"n + 1 <= var p + 1\"\n          by simp\n        from rep_nc have Sucn_repb_nc: \"(\\<forall>pt. pt \\<notin> set_of pret \\<or> \n          (\\<exists>i. n + 1 \\<le> i \\<and> pt \\<in> set (ll ! i) \\<and> i < var p + 1)  \n          \\<longrightarrow> rep pt = repb pt)\" \n          apply -\n          apply (intro allI impI)\n          apply (erule_tac x=pt in allE)\n          apply auto\n          apply (rule_tac x=\"i\" in exI)\n          apply auto\n          done\n        have repc_nc: \n          \"(\\<forall>pt. pt \\<notin> set_of pret \\<or> \n          (\\<exists>i. n + 1 \\<le> i \\<and> pt \\<in> set (ll ! i) \\<and> i < var p + 1) \n          \\<longrightarrow> rep pt = repc pt)\" \n        proof (intro allI impI)\n          fix pt \n          assume pt_notin_lower_ll: \"pt \\<notin> set_of pret \\<or> \n            (\\<exists>i. n + 1 \\<le> i \\<and> pt \\<in> set (ll ! i) \\<and> i < var p + 1)\"\n          show \"rep pt = repc pt\"\n          proof (cases \"pt \\<notin> set_of pret\")\n            case True\n            with wf_ll nsll have \"pt \\<notin> set (ll ! n)\"\n              apply (simp add: wf_ll_def length_ll_eq)\n              apply (case_tac \"pt \\<in> set (ll ! n)\")\n              apply (subgoal_tac \"pt \\<in> set_of pret\")\n              apply (auto)\n              done\n            with repbc_nc have \"repb pt = repc pt\"\n              by auto\n            with Sucn_repb_nc True show ?thesis\n              by auto\n          next\n            assume pt_in_pret: \"\\<not> pt \\<notin> set_of pret\"\n            with pt_notin_lower_ll have pt_in_higher_ll: \n              \"\\<exists>i. n + 1 \\<le> i \\<and> pt \\<in> set (ll ! i) \\<and> i < var p + 1\"\n              by simp\n            with nsll wf_ll lll have pt_notin_lln: \"pt \\<notin> set (ll ! n)\"\n              apply -\n              apply (erule exE)\n              apply (rule_tac i=i and j=n in no_in_one_ll)\n              apply (auto simp add: length_ll_eq)\n              done\n            with repbc_nc have \"repb pt = repc pt\"\n              by auto\n            with Sucn_repb_nc pt_in_higher_ll show ?thesis\n              by auto \n          qed\n        qed\n        from wf_ll nsll  \n        have Nodesn_notin_lln: \"\\<forall>no \\<in> Nodes n ll. no \\<notin> set (ll ! n)\"\n          apply (simp add: Nodes_def)\n          apply clarify\n          apply (drule no_in_one_ll)\n          apply (auto simp add: length_ll_eq)\n          done\n        with repbc_nc  \n        have Nodesn_repnc: \"\\<forall>no \\<in> Nodes n ll. repb no = repc no\"\n          apply -\n          apply (rule ballI)\n          apply (erule_tac x=no in allE)\n          apply simp\n          done\n        then have repbNodes_repcNodes: \n          \"repb `(Nodes n ll) = repc `(Nodes n ll)\"\n          apply -\n          apply rule\n          apply blast\n          apply rule\n          apply (erule imageE)\n          apply (erule_tac x=xa in ballE)\n          prefer 2\n          apply simp\n          apply rule\n          apply auto\n          done\n        have repcNodes_in_Nodes: \n          \"repc ` Nodes (n + 1) ll \\<subseteq> Nodes (n + 1) ll\"\n        proof\n          fix x\n          assume x_in_repcNodesSucn: \" x \\<in> repc ` Nodes (n + 1) ll\"\n          show \"x \\<in> Nodes (n + 1) ll\"\n          proof (cases \"x \\<in> repc `Nodes n ll\")\n            case True\n            with repbNodes_repcNodes repbNodes_in_Nodes have \"x \\<in> Nodes n ll\" \n              by auto\n            with Nodes_subset show ?thesis \n              by auto\n          next\n            assume \" x \\<notin> repc `Nodes n ll\"\n            with x_in_repcNodesSucn have x_in_repclln: \"x \\<in> repc `set (ll ! n)\"\n              apply (auto simp add: Nodes_def)\n              apply (case_tac \"k<n\")\n              apply auto\n              apply (case_tac \"k = n\")\n              apply simp\n              apply arith\n              done\n            from x_in_repclln show ?thesis\n            proof (elim imageE)\n              fix y\n              assume x_repcy: \"x = repc y\"\n              assume y_in_repclln: \"y \\<in> set (ll ! n)\"\n              from rep_prop y_in_repclln  obtain\n                repcy_nNull: \"repc y \\<noteq> Null\" and\n                red_prop: \"(repc \\<propto> low) y = (repc \\<propto> high) y \\<and> \n                low y \\<noteq> Null \\<longrightarrow> repc y = (repc \\<propto> high) y\" and\n                share_prop: \"((repc \\<propto> low) y = (repc \\<propto> high) y \\<longrightarrow> low y = Null) \n                \\<longrightarrow> repc y \\<in> set (ll ! n) \\<and> repc (repc y) = repc y \\<and> \n                (\\<forall>no1\\<in>set (ll ! n). \n                ((repc \\<propto> high) no1 = (repc \\<propto> high) y \\<and> \n                (repc \\<propto> low) no1 = (repc \\<propto> low) y) = (repc y = repc no1))\"\n                using [[simp_depth_limit = 4]]\n                by auto\n              from wf_ll nsll  y_in_repclln obtain\n                y_in_pret: \"y \\<in> set_of pret\" and\n                vary_n: \"var y = n\"\n                by (auto simp add: wf_ll_def length_ll_eq)\n              from y_in_pret pret_dag have y_nNull: \"y \\<noteq> Null\"\n                apply -\n                apply (rule set_of_nn)\n                apply auto\n                done\n              show \"x \\<in> Nodes (n + 1) ll\"\n              proof (cases \"low y = Null\")\n                case True\n                from pret_dag prebdt_pret True y_in_pret \n                have highy_Null: \"high y = Null\"\n                  apply -\n                  apply (drule balanced_bdt)\n                  apply auto\n                  done\n                with share_prop True obtain \n                  repcy_in_llb: \"repc y \\<in> set (ll ! n)\" and\n                  rry_ry: \" repc (repc y) = repc y\" and\n                  y_other_node_prop: \"\\<forall>no1\\<in>set (ll ! n). \n                  ((repc \\<propto> high) no1 = (repc \\<propto> high) y \\<and> \n                  (repc \\<propto> low) no1 = (repc \\<propto> low) y) = (repc y = repc no1)\"\n                  by simp\n                from repcy_in_llb  x_repcy show ?thesis\n                  by (auto simp add: Nodes_def)\n              next\n                assume lowy_nNull: \"low y \\<noteq> Null\"\n                with pret_dag prebdt_pret y_in_pret \n                have highy_nNull: \"high y \\<noteq> Null\"\n                  apply -\n                  apply (drule balanced_bdt)\n                  apply auto\n                  done\n                show ?thesis\n                proof (cases \"(repc \\<propto> low) y = (repc \\<propto> high) y\")\n                  case True\n                  with red_prop lowy_nNull have \"repc y = (repc \\<propto> high) y\"\n                    by auto\n                  with highy_nNull have red_repc_y: \"repc y = repc (high y)\"\n                    by (simp add: null_comp_def)\n                  from pret_dag ord_pret y_in_pret lowy_nNull  highy_nNull \n                  \n                  have \"var (low y) < var y \\<and> var (high y) < var y\"\n                    apply -\n                    apply (rule var_ordered_children) \n                    apply auto\n                    done\n                  with  vary_n have varhighy: \"var (high y) < n\"\n                    by auto\n                  from y_in_pret y_nNull highy_nNull pret_dag  \n                  have \"high y \\<in> set_of pret\" \n                    apply -\n                    apply (drule subelem_set_of_high)\n                    apply auto\n                    done\n                  with wf_ll varhighy have \"high y \\<in> Nodes n ll\"\n                    by (auto simp add: wf_ll_def Nodes_def)\n                  with red_repc_y have \"repc y \\<in> repc `Nodes n ll\"\n                    by simp\n                  with x_repcy have \"x \\<in> repc `Nodes n ll\"\n                    by simp\n                  with repbNodes_repcNodes repbNodes_in_Nodes \n                  have \"x \\<in> Nodes n ll\" \n                    by auto\n                  with Nodes_subset show ?thesis \n                    by auto\n                next\n                  assume \"(repc \\<propto> low) y \\<noteq> (repc \\<propto> high) y\"\n                  with share_prop obtain \n                    repcy_in_llbn: \"repc y \\<in> set (ll ! n)\" and\n                    rry_ry: \"repc (repc y) = repc y\" and \n                    y_other_node_share: \"\\<forall>no1\\<in>set (ll ! n). \n                    ((repc \\<propto> high) no1 = (repc \\<propto> high) y \\<and> \n                    (repc \\<propto> low) no1 = (repc \\<propto> low) y) = (repc y = repc no1)\"\n                    by auto\n                  with repcy_in_llbn  x_repcy have \"x \\<in> set (ll ! n)\"\n                    by auto\n                  then show ?thesis\n                    by (auto simp add: Nodes_def)\n                qed\n              qed\n            qed\n          qed\n        qed\n        have \"(\\<forall>no\\<in>Nodes (n + 1) ll.\n          var (repc no) \\<le> var no \\<and> \n          (\\<exists>not nort. Dag (repc no) (repc \\<propto> low) (repc \\<propto> high) nort \\<and>\n          Dag no low high not \\<and>\n          reduced nort \\<and> ordered nort var \\<and> \n          set_of nort \\<subseteq> repc ` Nodes (n + 1) ll \\<and> \n          (\\<forall>no\\<in>set_of nort. repc no = no) \\<and>\n          (\\<exists>nobdt. bdt not var = Some nobdt \\<and> \n          (\\<exists>norbdt. bdt nort var = Some norbdt \\<and> nobdt \\<sim> norbdt))))\"\n          (is \"\\<forall>no\\<in>Nodes (n + 1) ll. ?Q i no\")\n        proof (intro ballI)\n          fix no\n          assume no_in_Nodes: \"no \\<in> Nodes (n + 1) ll\"\n          from wf_ll no_in_Nodes nsll  have no_in_pret: \"no \\<in> set_of pret\"\n            apply (simp add: wf_ll_def Nodes_def length_ll_eq)\n            apply (erule conjE)\n            apply (thin_tac \"\\<forall>q. q \\<in> set_of pret \\<longrightarrow> q \\<in> set (ll ! var q)\")\n            apply (erule exE)\n            apply (erule_tac x=k in allE)\n            apply (erule impE)\n            apply arith\n            apply (erule_tac x=no in ballE)\n            apply auto\n            done\n          from pret_dag no_in_pret have nonNull: \"no\\<noteq> Null\" \n            apply -\n            apply (rule set_of_nn [rule_format])\n            apply auto\n            done  \n          show \"?Q i no\"\n          proof (cases \"no \\<in> Nodes n ll\")\n            case True\n            note no_in_Nodesn=this\n            with wf_ll nsll  no_in_Nodes \n            have no_notin_llbn: \"no \\<notin> set (ll ! n)\"\n              apply -\n              apply (simp add: Nodes_def length_ll_eq)\n              apply (elim exE)\n              apply (drule_tac ?i=ka and ?j=n in no_in_one_ll)\n              apply arith\n              apply simp\n              apply auto\n              done\n            with repbc_nc have repb_no_eq_repc_no: \"repb no = repc no\" \n              by simp\n            from repbc_nc no_in_Nodes no_notin_llbn normalize_prop True \n            have varrep_eq_var: \"var (repc no) \\<le> var no\" \n              apply -\n              apply (erule_tac x=no in ballE)\n              prefer 2\n              apply simp\n              apply (erule_tac x=no in allE)\n              apply simp\n              done\n            moreover\n            from True normalize_prop no_in_Nodes obtain not nort where\n              nort_dag: \"Dag (repb no) (repb \\<propto> low) (repb \\<propto> high) nort\" and\n              ord_nort: \"ordered nort var\" and\n              subset_nort_not:  \"set_of nort \\<subseteq> repb `(Nodes n ll)\" and\n              not_dag:  \" Dag no low high not\" and\n              red_nort: \"reduced nort\" and \n              nort_repb: \"(\\<forall>no\\<in>set_of nort. repb no = no)\" and\n              bdt_prop: \"\\<exists>nobdt norbdt. bdt not var = Some nobdt \\<and> \n              bdt nort var = Some norbdt \\<and> nobdt \\<sim> norbdt\" \n              by blast\n            moreover\n            from Nodesn_notin_lln repbc_nc nort_repb subset_nort_not repbNodes_in_Nodes \n            have nort_repc: \n              \"(\\<forall>no\\<in>set_of nort. repc no = no)\"\n              apply auto\n              apply (subgoal_tac \"no \\<in> Nodes n ll\")\n              apply fastforce\n              apply blast\n              done\n            moreover\n            from nort_dag have nortnodesnN: \"(\\<forall>no. no \\<in> set_of nort \\<longrightarrow> no \\<noteq> Null)\"\n              apply -\n              apply (rule allI)\n              apply (rule impI)\n              apply (rule set_of_nn)\n              apply auto\n              done\n            moreover  \n            have \"Dag (repc no) (repc \\<propto> low) (repc \\<propto> high) nort\"\n            proof -\n              from no_notin_llbn repbc_nc have repbc_no: \"repc no = repb no\"\n                by fastforce\n              with nort_dag \n              have nortrepbc_dag: \"Dag (repc no) (repb \\<propto> low) (repb \\<propto> high) nort\"\n                by simp\n              from wf_ll nseqll have \"Nodes n ll \\<subseteq> set_of pret\"\n                apply -\n                apply (rule Nodes_levellist_subset_t)\n                apply assumption+\n                apply (simp add: length_ll_eq)\n                done\n              with repbNodes_in_Nodes subset_nort_not \n              have subset_nort_pret:  \"set_of nort \\<subseteq> set_of pret\"\n                by simp\n              have vxsn_in_pret: \"\\<forall> x \\<in> set_of nort. var x < n \\<and> x \\<in> set_of pret\"\n              proof (rule ballI)\n                fix x\n                assume x_in_nort: \"x \\<in> set_of nort\"\n                from x_in_nort subset_nort_not repbNodes_in_Nodes \n                have \"x \\<in> Nodes n ll\"\n                  by blast\n                with wf_ll nsll  have xsn: \"var x < n\"\n                  apply (simp add: wf_ll_def Nodes_def length_ll_eq)\n                  apply (erule conjE)\n                  apply (thin_tac \" \\<forall>q. q \\<in> set_of pret \\<longrightarrow> q \\<in> set (ll ! var q)\")\n                  apply (erule exE)\n                  apply (erule_tac x=k in allE)\n                  apply (erule impE)\n                  apply arith\n                  apply (erule_tac x=x in ballE)\n                  apply auto\n                  done\n                from x_in_nort subset_nort_pret have x_in_pret: \"x \\<in> set_of pret\"\n                  by blast\n                with xsn show \"var x < n \\<and> x \\<in> set_of pret\" by simp\n              qed\n              with pret_dag prebdt_pret nortrepbc_dag ord_pret wf_ll  nsll \n                repbc_nc \n              have \"\\<forall> x \\<in> set_of nort. ((repc \\<propto> low) x = (repb \\<propto> low) x \\<and> \n                (repc \\<propto> high) x = (repb \\<propto> high) x)\"\n                apply -\n                apply (rule nort_null_comp)\n                apply (auto simp add: length_ll_eq)\n                done\n              with nort_dag \n              have \"Dag (repc no) (repc \\<propto> low) (repc \\<propto> high) nort = \n                Dag (repc no) (repb \\<propto> low) (repb \\<propto> high) nort\"\n                apply -\n                apply (rule heaps_eq_Dag_eq)\n                apply simp\n                done\n              with nortrepbc_dag show ?thesis\n                by simp\n            qed\n            moreover \n            have \"set_of nort \\<subseteq> repc `(Nodes (n + 1) ll)\"\n            proof -\n              have Nodesn_in_NodesSucn: \"Nodes n ll \\<subseteq> Nodes (n + 1) ll\"\n                by (simp add: Nodes_def set_split)\n              then have repbNodesn_in_repbNodesSucn: \n                \"repb `(Nodes n ll) \\<subseteq> repb `(Nodes (n + 1) ll)\"\n                by blast\n              from wf_ll nsll  \n              have Nodes_n_notin_lln: \"\\<forall>no \\<in> Nodes n ll. no \\<notin> set (ll ! n)\"\n                apply (simp add: Nodes_def length_ll_eq)\n                apply clarify\n                apply (drule no_in_one_ll)\n                apply auto\n                done\n              with repbc_nc  have \"\\<forall>no \\<in> Nodes n ll. repb no = repc no\"\n                apply -\n                apply (rule ballI)\n                apply (erule_tac x=no in allE)\n                apply simp\n                done\n              then have repbNodes_repcNodes: \n                \"repb `(Nodes n ll) = repc `(Nodes n ll)\"\n                apply -\n                apply rule\n                apply blast\n                apply rule\n                apply (erule imageE)\n                apply (erule_tac x=xa in ballE)\n                prefer 2\n                apply simp\n                apply rule\n                apply auto\n                done\n              from Nodesn_in_NodesSucn \n              have \"repc `(Nodes n ll) \\<subseteq> repc `(Nodes (n + 1) ll)\"\n                by blast\n              with repbNodes_repcNodes subset_nort_not repbNodesn_in_repbNodesSucn \n              show ?thesis by simp\n            qed\n            ultimately show ?thesis \n              by blast\n          next\n            assume \" no \\<notin> Nodes n ll\"\n            with no_in_Nodes  have no_in_llbn: \"no \\<in> set (ll ! n)\"\n              apply (simp add: Nodes_def)\n              apply (erule exE)\n              apply (erule_tac x=k in allE)\n              apply (case_tac \"k<n\")\n              apply simp\n              apply simp\n              apply (elim conjE)\n              apply (case_tac \"k=n\")\n              apply simp\n              apply arith\n              done\n            with wf_ll  nsll have varno: \"var no = n\"\n              by (simp add: wf_ll_def length_ll_eq)\n            from repbc_changes no_in_llbn \n            have repbcno_changes: \"repc no \\<noteq> Null \\<and>\n              ((repc \\<propto> low) no = (repc \\<propto> high) no \\<and> low no \\<noteq> Null \n              \\<longrightarrow> repc no = (repc \\<propto> high) no) \\<and>\n              (((repc \\<propto> low) no = (repc \\<propto> high) no \\<longrightarrow> low no = Null) \n              \\<longrightarrow> repc no \\<in> set (ll ! n)  \\<and> repc (repc no) = repc no \\<and> \n              (\\<forall>no1\\<in>set (ll ! n). ((repc \\<propto> high) no1 = (repc \\<propto> high) no \\<and>\n              (repc \\<propto> low) no1 = (repc \\<propto> low) no) = (repc no = repc no1)))\"\n              (is \"?rnonN \\<and> ?repreduce \\<and> ?repshare\")\n              using [[simp_depth_limit=4]]\n              by (simp split: split_if)\n            then obtain \n              rnonN: \"?rnonN\" and\n              repreduce: \"?repreduce\" and\n              repshare: \"?repshare\"\n              by blast\n            have repcn_normalize: \"var (repc no) \\<le> var no \\<and>\n              (\\<exists>not nort. Dag (repc no) (repc \\<propto> low) (repc \\<propto> high) nort \\<and>\n              Dag no low high not \\<and> reduced nort \\<and> ordered nort var \\<and>\n              set_of nort \\<subseteq> repc ` Nodes (n + 1) ll \\<and>\n              (\\<forall>no\\<in>set_of nort. repc no = no) \\<and>\n              (\\<exists>nobdt. bdt not var = Some nobdt \\<and> \n              (\\<exists>norbdt. bdt nort var = Some norbdt \\<and> nobdt \\<sim> norbdt)))\"\n              (is \"?varrep \\<and> ?repcn_prop\" \n                is \"?varrep \\<and> \n                (\\<exists>not nort. ?nort_dag nort \\<and> ?not_dag not \\<and> ?red nort \\<and> \n                ?ord nort \\<and> ?nort_in_Nodes nort \\<and> ?repcno_no_n nort \\<and> ?bdt_equ not nort)\")\n            proof (cases \"high no = Null\")\n              case True\n              note highnoNull=this\n              with pret_dag prebdt_pret no_in_pret   \n              have lownoNull: \"low no = Null\"\n                apply -\n                apply (drule balanced_bdt)\n                apply assumption+\n                apply simp\n                done\n              with repshare have repcnoinlln:\"repc no \\<in> set (ll ! n)\"\n                by simp\n              with wf_ll  nsll have varrno_n: \"var (repc no) = n\"\n                by (simp add: wf_ll_def length_ll_eq)\n              with varno have varrep: \"?varrep\"\n                by simp\n              from wf_ll  nsll no_in_llbn varrno_n \n              have varrno_varno: \"var (repc no) = var no\"\n                by (simp add: wf_ll_def length_ll_eq)\n              from wf_ll  nsll repcnoinlln \n              have rno_in_pret: \"repc no \\<in> set_of pret\" \n                by (simp add: wf_ll_def length_ll_eq)\n              from repcnoinlln repshare lownoNull \n              have reprep_eq_rep: \"repc (repc no) = repc no\" \n                by simp\n              with repcnoinlln repshare lownoNull \n              have repchildreneq: \n                \"((repc \\<propto> high) (repc no) = (repc \\<propto> high) no \\<and> \n                (repc \\<propto> low) (repc no) = (repc \\<propto> low) no)\"\n                by simp\n              have repcn_prop: \"?repcn_prop\"\n                apply -         \n                apply (rule_tac x=\"(Node Tip no Tip)\" in exI)\n                apply (rule_tac x=\"(Node Tip (repc no) Tip)\" in exI)\n                apply (intro conjI)\n                apply simp\n                prefer 3\n                apply simp\n                prefer 3\n                apply simp\n              proof -\n                from pret_dag pnN rno_in_pret have rnonN: \"repc no \\<noteq> Null\"\n                  apply (case_tac \"repc no = Null\")\n                  apply auto\n                  done\n                from highnoNull repchildreneq \n                have rhighNull: \"(repc \\<propto> high) (repc no) = Null\" \n                  by (simp add: null_comp_def)\n                from lownoNull repchildreneq \n                have rlowNull: \"(repc \\<propto> low) (repc no) = Null\" \n                  by (simp add: null_comp_def)\n                with rhighNull rnonN   \n                show \"repc no \\<noteq> Null \\<and> (repc \\<propto> low) (repc no) = Null \\<and> \n                  (repc \\<propto> high) (repc no) = Null\"\n                  by simp\n              next\n                from nonNull lownoNull highnoNull   \n                show \"?not_dag (Node Tip no Tip)\"\n                  by simp\n              next\n                from no_in_Nodes \n                show \"set_of (Node Tip (repc no) Tip) \\<subseteq>  repc ` Nodes (n + 1) ll\"\n                  by simp\n              next\n                show \"\\<forall>no\\<in>set_of (Node Tip (repc no) Tip). repc no = no\"\n                proof \n                  fix pt\n                  assume pt_in_repcLeaf: \"pt \\<in> set_of (Node Tip (repc no) Tip)\"\n                  with reprep_eq_rep show \"repc pt = pt\"\n                    by simp\n                qed\n              next\n                show \"?bdt_equ (Node Tip no Tip) (Node Tip (repc no) Tip)\"\n                proof (cases \"var no = 0\")\n                  case True \n                  note vno_Null=this\n                  then have nobdt: \"bdt (Node Tip no Tip) var = Some Zero\" by simp\n                  from varrep  vno_Null have varrno: \"var (repc no) = 0\" by simp\n                  then have norbdt: \"bdt (Node Tip (repc no) Tip) var = Some Zero\" by simp\n                  from nobdt norbdt vno_Null varrno show ?thesis\n                    by (simp add: cong_eval_def)\n                next\n                  assume vno_not_Null: \"var no \\<noteq> 0\"\n                  show ?thesis\n                  proof (cases \"var no = 1\")\n                    case True\n                    note vno_One=this\n                    then have nobdt: \"bdt (Node Tip no Tip) var = Some One\" by simp\n                    from varrno_varno vno_One \n                    have \"bdt (Node Tip (repc no) Tip) var = Some One\" by simp \n                    with nobdt show ?thesis by (auto simp add: cong_eval_def)\n                  next\n                    assume vno_nOne: \"var no \\<noteq> 1\"\n                    with vno_not_Null have onesvno: \"1 < var no\" by simp\n                    from nonNull lownoNull highnoNull   \n                    have no_dag: \"Dag no low high (Node Tip no Tip)\"\n                      by simp \n                    with pret_dag no_in_pret have not_in_pret: \"(Node Tip no Tip) \\<le> pret\"\n                      by (metis set_of_subdag)\n                    with prebdt_pret have \"\\<exists>bdt2. bdt (Node Tip no Tip) var = Some bdt2\"\n                      by (metis subbdt_ex)\n                    with onesvno show ?thesis \n                      by simp\n                  qed\n                qed\n              qed\n              with varrep reprep_eq_rep show ?thesis by simp\n            next\n              assume hno_nNull: \"high no \\<noteq> Null\"\n              with pret_dag prebdt_pret no_in_pret   have lno_nNull: \"low no \\<noteq> Null\"\n                by (metis balanced_bdt)\n                  (*-------------------normalize_prop fuer (high no)------------------------*)\n              \n              from no_in_pret nonNull hno_nNull pret_dag  \n              have hno_in_pret: \"high no \\<in> set_of pret\"\n                by (metis subelem_set_of_high)\n              with wf_ll \n              have hno_in_ll: \"high no \\<in> set (ll ! (var (high no)))\" \n                by (simp add: wf_ll_def)\n              from pret_dag ord_pret  no_in_pret lno_nNull hno_nNull \n              \n              have varhnos_varno: \"var (high no) < var no\"\n                by (metis var_ordered_children)\n              with varno have varhnos_n: \"var (high no) < n\" by simp\n              with hno_in_ll have hno_in_Nodesn: \"high no \\<in> Nodes n ll\"\n                apply (simp add: Nodes_def)\n                apply (rule_tac x=\"var (high no)\" in exI)\n                apply simp\n                done\n              from wf_ll nsll hno_in_ll   varhnos_n \n              have \"high no \\<notin> set (ll ! n)\"\n                apply -\n                apply (rule no_in_one_ll)\n                apply (auto simp add: length_ll_eq)\n                done\n              with repbc_nc have repb_repc_high: \"repb (high no) = repc (high no)\" by simp\n              with normalize_prop hno_in_Nodesn varhnos_varno varno \n              have high_normalize: \"var (repc (high no)) \\<le> var (high no) \\<and>\n                (\\<exists>not nort. Dag (repc (high no)) (repb \\<propto> low) (repb \\<propto> high) nort \\<and>\n                Dag (high no) low high not \\<and> reduced nort \\<and>\n                ordered nort var \\<and> set_of nort \\<subseteq> repb `(Nodes n ll) \\<and>\n                (\\<forall>no\\<in>set_of nort. repb no = no) \\<and>\n                (\\<exists>nobdt norbdt. bdt not var = Some nobdt \\<and> bdt nort var = \n                Some norbdt \\<and> nobdt \\<sim> norbdt))\"\n                (is \"?varrep_high \\<and> \n                  (\\<exists>not nort. ?repbchigh_dag nort \\<and> ?high_dag not \\<and> \n                  ?redhigh nort \\<and> ?ordhigh nort \\<and> ?rephigh_in_Nodes nort \\<and> \n                  ?repbno_no nort \\<and> ?highdd_prop not nort)\"\n                  is \"?varrep_high \\<and> ?not_nort_prop\")\n                apply simp\n                apply (erule_tac x=\"high no\" in ballE)\n                apply (simp del: Dag_Ref)\n                apply simp\n                done\n              then have varrep_high: \"?varrep_high\" by simp\n              from varhnos_n varrep_high have varrephno_s_n: \n                \"var (repc (high no)) < n\"\n                by simp\n              from Nodes_subset \n              have \"Nodes n ll \\<subseteq> Nodes (Suc n) ll\"\n                by auto\n              with hno_in_Nodesn repcNodes_in_Nodes \n              have \"repc (high no) \\<in> Nodes (Suc n) ll\"\n                apply simp\n                apply blast\n                done\n              with wf_ll nsll  have \"repc (high no) \\<in> set_of pret\"\n                apply (simp add: wf_ll_def Nodes_def length_ll_eq)\n                apply (elim conjE exE)\n                apply (thin_tac \" \\<forall>q. q \\<in> set_of pret \\<longrightarrow> q \\<in> set (ll ! var q)\")\n                apply (erule_tac x=k in allE)\n                apply (erule impE)\n                apply simp\n                apply (erule_tac x=\"repc (high no)\" in ballE)\n                apply auto\n                done\n              with wf_ll varrephno_s_n \n              have \"\\<exists> k<n. repc (high no) \\<in> set (ll ! k)\"\n                by (auto simp add: wf_ll_def)\n              with wf_ll nsll  have \"repc (high no) \\<notin> set (ll ! n)\"\n                apply -\n                apply (erule exE)\n                apply (rule_tac i=k and j=n in no_in_one_ll)\n                apply (auto simp add: length_ll_eq)\n                done\n              with repbc_nc \n              have repbchigh_idem: \"repb (repc (high no)) = repc (repc (high no))\"\n                by auto\n              from high_normalize \n              have not_nort_prop_high: \"?not_nort_prop\" by (simp del: Dag_Ref)\n              from not_nort_prop_high obtain hnot where high_dag: \"?high_dag hnot\"\n                by auto\n              from wf_ll nsll  \n              have \"\\<forall>no \\<in> Nodes n ll. no \\<notin> set (ll ! n)\"\n                apply (simp add: Nodes_def length_ll_eq)\n                apply clarify\n                apply (drule no_in_one_ll)\n                apply auto\n                done\n              with repbc_nc  have \"\\<forall>no \\<in> Nodes n ll. repb no = repc no\"\n                apply -\n                apply (rule ballI)\n                apply (erule_tac x=no in allE)\n                apply simp\n                done\n              then \n              have repbNodes_repcNodes: \n                \"repb `(Nodes n ll) = repc `(Nodes n ll)\"\n                apply -\n                apply rule\n                apply blast\n                apply rule\n                apply (erule imageE)\n                apply (erule_tac x=xa in ballE)\n                prefer 2\n                apply simp\n                apply rule\n                apply auto\n                done\n              then have repcNodes_repbNodes: \n                \"repc `(Nodes n ll) = repb `(Nodes n ll)\"\n                by simp\n              from pret_dag nsll  wf_ll \n              have null_notin_Nodesn: \"Null \\<notin> Nodes n ll\"\n                apply -\n                apply (rule Null_notin_Nodes)\n                apply (auto simp add: length_ll_eq)\n                done\n              from hno_in_Nodesn have \"repc (high no) \\<in> repc `(Nodes n ll)\"\n                by blast\n              with repbNodes_in_Nodes repcNodes_repbNodes \n              have \"repc (high no) \\<in> Nodes n ll\"\n                apply simp\n                apply blast\n                done\n              with null_notin_Nodesn have rhn_nNull: \"repc (high no) \\<noteq> Null\"\n                by auto\n\n                  (*-------------------normalize_prop fuer (low no)--------------------------*)\n\n              from no_in_pret nonNull lno_nNull pret_dag  \n              have lno_in_pret: \"low no \\<in> set_of pret\"\n                by (rule subelem_set_of_low)\n              with wf_ll \n              have lno_in_ll: \"low no \\<in> set (ll ! (var (low no)))\" \n                by (simp add: wf_ll_def)\n              from pret_dag ord_pret  no_in_pret lno_nNull hno_nNull  \n              have varlnos_varno: \"var (low no) < var no\"\n                apply -\n                apply (drule var_ordered_children)\n                apply assumption+\n                apply auto\n                done\n              with varno have varlnos_n: \"var (low no) < n\" by simp\n              with lno_in_ll have lno_in_Nodesn: \"low no \\<in> Nodes n ll\"\n                apply (simp add: Nodes_def)\n                apply (rule_tac x=\"var (low no)\" in exI)\n                apply simp\n                done\n              from varlnos_n wf_ll nsll lno_in_ll   \n              have \"low no \\<notin> set (ll ! n)\"\n                apply -\n                apply (rule no_in_one_ll)\n                apply (auto simp add: length_ll_eq)\n                done\n              with repbc_nc have repb_repc_low: \"repb (low no) = repc (low no)\" by simp\n              with normalize_prop lno_in_Nodesn varlnos_varno varno \n              have low_normalize: \"var (repc (low no)) \\<le> var (low no) \\<and>\n                (\\<exists>not nort. Dag (repc (low no)) (repb \\<propto> low) (repb \\<propto> high) nort \\<and>\n                Dag (low no) low high not \\<and> reduced nort \\<and> ordered nort var \\<and>\n                set_of nort \\<subseteq> repb `(Nodes n ll) \\<and>\n                (\\<forall>no\\<in>set_of nort. repb no = no) \\<and>\n                (\\<exists>nobdt norbdt. bdt not var = Some nobdt \\<and> bdt nort var = Some norbdt \\<and> \n                nobdt \\<sim> norbdt))\"\n                (is \"?varrep_low \\<and> \n                  (\\<exists>not nort. ?repbclow_dag nort \\<and> ?low_dag not \\<and> ?redhigh nort \\<and> \n                  ?ordhigh nort \\<and> ?replow_in_Nodes nort  \\<and> ?low_repno_no nort \n                  \\<and> ?lowdd_prop not nort)\"\n                  is \"?varrep_low \\<and> ?not_nort_prop_low\")\n                apply simp\n                apply (erule_tac x=\"low no\" in ballE)\n                apply (simp del: Dag_Ref)\n                apply simp\n                done\n              then have varrep_low: \"?varrep_low\" by simp\n              from low_normalize have not_nort_prop_low: \"?not_nort_prop_low\" \n                by (simp del: Dag_Ref)\n              from lno_in_Nodesn have \"repc (low no) \\<in> repc `(Nodes n ll)\"\n                by blast\n              with repbNodes_in_Nodes repcNodes_repbNodes \n              have \"repc (low no) \\<in> Nodes n ll\"\n                apply simp\n                apply blast\n                done\n              with null_notin_Nodesn have rln_nNull: \"repc (low no) \\<noteq> Null\"\n                by auto\n\n              \n              show ?thesis\n              proof (cases \"repc (low no) = repc (high no)\")\n                case True\n                note red_case=this\n                with repreduce lno_nNull hno_nNull \n                have rno_eq_hrno: \"repc no = repc (high no)\" \n                  by (simp add: null_comp_def)\n                from varhnos_varno rno_eq_hrno varrep_high have varrep: \"?varrep\" by simp\n                from not_nort_prop_high not_nort_prop_low have repcn_prop: \"?repcn_prop\"\n                  apply -\n                  apply (elim exE)\n                  apply (rename_tac rnot lnot rnort lnort )\n                  apply (rule_tac x=\"(Node lnot no rnot)\" in exI)\n                  apply (rule_tac x=rnort in exI)\n                  apply (elim conjE)\n                  apply (intro conjI)\n                  prefer 7\n                  apply (elim exE)\n                  apply (rename_tac rnot lnot rnort lnort rnobdt lnobdt rnorbdt lnorbdt)\n                  apply (elim conjE)\n                  apply (case_tac  \"Suc 0 < var no\")\n                  apply (rule_tac x=\"(Bdt_Node lnobdt (var no) rnobdt)\" in exI)\n                  apply (rule conjI)\n                  prefer 2\n                  apply (rule_tac x=rnorbdt in exI)\n                  apply (rule conjI)\n                proof -\n                  fix rnot lnot rnort lnort\n                  assume highnort_dag: \n                    \"Dag (repc (high no)) (repb \\<propto> low) (repb \\<propto> high) rnort\"\n                  assume ord_nort: \" ordered rnort var\"\n                  assume rnort_in_repNodes: \" set_of rnort \\<subseteq>  repb ` Nodes n ll\"\n                  from rnort_in_repNodes repbNodes_in_Nodes \n                  have nort_in_Nodes: \"set_of rnort \\<subseteq> Nodes n ll\"\n                    by blast\n                  from varhnos_n varrep_high \n                  have vrhnos_n: \"var (repc (high no)) < n\" by simp\n                  from rhn_nNull highnort_dag \n                  have \"\\<exists>lno rno. rnort = Node lno (repc (high no)) rno\" by fastforce\n                  with highnort_dag rhn_nNull have \"root rnort = repc (high no)\" by auto\n                  with ord_nort have \"\\<forall>x \\<in> set_of rnort. var x <= var (repc (high no))\"\n                    apply -\n                    apply (rule ballI)\n                    apply (drule ordered_set_of)\n                    apply auto\n                    done\n                  with vrhnos_n have vxsn: \"\\<forall>x \\<in> set_of rnort. var x < n\" \n                    by fastforce\n                  from nort_in_Nodes have \"\\<forall>x \\<in> set_of rnort. x \\<in> Nodes n ll\" \n                    by auto\n                  with wf_ll nsll  \n                  have x_in_pret: \"\\<forall>x \\<in> set_of rnort. x \\<in> set_of pret\"\n                    apply -\n                    apply (rule ballI)\n                    apply (drule wf_ll_Nodes_pret)\n                    apply (auto simp add: length_ll_eq)\n                    done\n                  from vxsn x_in_pret \n                  have vxsn_in_nort: \"\\<forall>x \\<in> set_of rnort. var x <n \\<and> x \\<in> set_of pret\"\n                    by auto\n                  with pret_dag prebdt_pret highnort_dag ord_pret wf_ll  nsll \n                    repbc_nc \n                  have \"\\<forall>x \\<in> set_of rnort. (repc \\<propto> low) x = (repb \\<propto> low) x \\<and> \n                    (repc \\<propto> high) x = (repb \\<propto> high) x\"\n                    apply -\n                    apply (rule nort_null_comp)\n                    apply (auto simp add: length_ll_eq)\n                    done\n                  with rno_eq_hrno \n                  have \"Dag (repc no) (repc \\<propto> low) (repc \\<propto> high) rnort = \n                    Dag (repc no) (repb \\<propto> low) (repb \\<propto> high) rnort\"\n                    apply -\n                    apply (rule heaps_eq_Dag_eq)\n                    apply simp\n                    done\n                  with highnort_dag rno_eq_hrno \n                  show \"Dag (repc no) (repc \\<propto> low) (repc \\<propto> high) rnort\" by simp\n                next\n                  fix rnot lnot rnort lnort\n                  assume lnot_dag: \"Dag (low no) low high lnot\"\n                  assume rnot_dag: \"Dag (high no) low high rnot\"\n                  with lnot_dag   nonNull \n                  show \"Dag no low high (Node lnot no rnot)\" by simp\n                next\n                  fix rnot lnot rnort lnort\n                  assume \" reduced rnort\"\n                  then show \"reduced rnort\" by simp\n                next\n                  fix rnort\n                  assume \"ordered rnort var\"\n                  then show \"ordered rnort var\" by simp\n                next\n                  fix rnort\n                  assume rnort_in_Nodes: \" set_of rnort \\<subseteq> repb ` Nodes n ll\"\n                  have \"Nodes n ll \\<subseteq> Nodes (n + 1) ll\" \n                    by (simp add: Nodes_def set_split) \n                  then have \"repc ` Nodes n ll \\<subseteq> repc ` Nodes (n + 1) ll\"\n                    by blast\n                  with rnort_in_Nodes repbNodes_repcNodes \n                  show \" set_of rnort \\<subseteq> repc ` Nodes (n + 1) ll\" \n                    by (simp add: Nodes_def)\n                next\n                  fix rnort rnorbdt\n                  assume \" bdt rnort var = Some rnorbdt\"\n                  then show \" bdt rnort var = Some rnorbdt\" by simp\n                next\n                  fix rnot lnot rnort lnort rnobdt lnobdt rnorbdt lnorbdt\n                  assume rcongeval: \"rnobdt \\<sim> rnorbdt\"\n                  assume lnort_dag: \n                    \"Dag (repc (low no)) (repb \\<propto> low) (repb \\<propto> high) lnort\"\n                  assume rnort_dag: \n                    \"Dag (repc (high no)) (repb \\<propto> low) (repb \\<propto> high) rnort\"\n                  assume lnorbdt_def: \" bdt lnort var = Some lnorbdt\"\n                  assume rnorbdt_def: \" bdt rnort var = Some rnorbdt\"\n                  assume lcongeval:\"lnobdt \\<sim> lnorbdt\"\n                  from red_case lnort_dag rnort_dag \n                  have lnort_rnort: \"lnort = rnort\" \n                    by (simp add: Dag_unique del: Dag_Ref)\n                  with lnorbdt_def lcongeval rnorbdt_def \n                  have lnobdt_rnorbdt: \"lnobdt \\<sim> rnorbdt\" by simp\n                  with rcongeval have \"lnobdt \\<sim> rnobdt\" \n                    apply -\n                    apply (rule cong_eval_trans)\n                    apply (auto simp add: cong_eval_sym)\n                    done\n                  then have \" Bdt_Node lnobdt (var no) rnobdt \\<sim> rnobdt\"\n                    apply -\n                    apply (simp add: cong_eval_sym [rule_format])\n                    apply (rule cong_eval_child_high)\n                    apply assumption\n                    done\n                  with rcongeval show \"Bdt_Node lnobdt (var no) rnobdt \\<sim> rnorbdt\"\n                    apply -\n                    apply (rotate_tac 1)\n                    apply (rule cong_eval_trans)\n                    apply auto\n                    done\n                next\n                  fix lnot rnot lnobdt rnobdt\n                  assume lnot_dag: \"Dag (low no) low high lnot\"\n                  assume rnot_dag: \" Dag (high no) low high rnot\"\n                  assume lnobdt_def: \" bdt lnot var = Some lnobdt\"\n                  assume rnobdt_def: \" bdt rnot var = Some rnobdt\"\n                  assume onesvarno: \" Suc 0 < var no\"\n                  with rnobdt_def lnot_dag rnot_dag lnobdt_def \n                  show \"bdt (Node lnot no rnot) var = \n                    Some (Bdt_Node lnobdt (var no) rnobdt)\" \n                    by simp\n                next\n                  fix rnot lnot rnort lnort rnobdt lnobdt rnorbdt lnorbdt\n                  assume lnobdt_def: \" bdt lnot var = Some lnobdt\"\n                  assume rnobdt_def: \" bdt rnot var = Some rnobdt\"\n                  assume rnorbdt_def: \" bdt rnort var = Some rnorbdt\"\n                  assume cong_rno_rnor: \" rnobdt \\<sim> rnorbdt\"\n                  assume lnot_dag: \"Dag (low no) low high lnot\"\n                  assume rnot_dag: \"Dag (high no) low high rnot\"\n                  assume \"\\<not> Suc 0 < var no\"\n                  then have varnoseq1: \"var no = 0 \\<or> var no = 1\" by auto\n                  show \"\\<exists>nobdt. bdt (Node lnot no rnot) var = Some nobdt \\<and> \n                    (\\<exists>norbdt. bdt rnort var = Some norbdt \\<and> nobdt \\<sim> norbdt)\"\n                  proof (cases \"var no = 0\")\n                    case True\n                    note vnoNull=this\n                    with pret_dag ord_pret no_in_pret lno_nNull hno_nNull  \n                    show ?thesis\n                      apply -\n                      apply (drule var_ordered_children)\n                      apply auto\n                      done\n                  next\n                    assume \"var no \\<noteq> 0\"\n                    with varnoseq1 have vnoOne: \"var no = 1\" by simp\n                    from pret_dag  ord_pret no_in_pret lno_nNull hno_nNull  \n                      vnoOne \n                    have vlvrNull: \"var (low no) = 0 \\<and> var (high no) = 0\"\n                      apply -\n                      apply (drule var_ordered_children)\n                      apply auto\n                      done\n                    then have vlNull: \"var (low no) = 0\" by simp\n                    from vlvrNull have vrNull: \"var (high no) = 0\" by simp\n                    from lnobdt_def lnot_dag vlNull  lno_nNull \n                    have lnobdt_Zero: \"lnobdt = Zero\"\n                      apply -\n                      apply (drule bdt_Some_var0_Zero)\n                      apply auto\n                      done\n                    from rnobdt_def rnot_dag vrNull  hno_nNull \n                    have rnobdt_Zero: \"rnobdt = Zero\"\n                      apply -\n                      apply (drule bdt_Some_var0_Zero)\n                      apply auto\n                      done\n                    from lnobdt_Zero lnobdt_def have \"bdt lnot var = Some Zero\" by simp\n                    with lnot_dag vlNull  \n                    have lnot_Node: \"lnot = (Node Tip (low no) Tip)\"\n                      by auto\n                    from rnobdt_Zero rnobdt_def rnot_dag vrNull  \n                    have rnot_Node: \"rnot = (Node Tip (high no) Tip)\" \n                      by auto\n                    from pret_dag no_in_pret obtain not where \n                      not_ex: \"Dag no low high not\"\n                      apply -\n                      apply (drule dag_setof_exD)\n                      apply auto\n                      done\n                    with pret_dag no_in_pret have not_ex_in_pret: \"not <= pret\" \n                      apply -\n                      apply (rule set_of_subdag)\n                      apply auto\n                      done\n                    from not_ex lnot_dag rnot_dag   nonNull \n                    have not_def: \"not = (Node lnot no rnot)\" \n                      by (simp add: Dag_unique del: Dag_Ref)\n                    with not_ex_in_pret prebdt_pret \n                    have nobdt_ex: \"\\<exists>nobdt. bdt (Node lnot no rnot) var = Some nobdt\"\n                      apply -\n                      apply (rule subbdt_ex)\n                      apply auto\n                      done\n                    then obtain nobdt where \n                      nobdt_def: \"bdt (Node lnot no rnot) var = Some nobdt\" by auto\n                    from not_def have \"root not = no\" by simp\n                    with nobdt_def vnoOne not_def have \"not = (Node Tip no Tip)\"\n                      apply -\n                      apply (drule bdt_Some_var1_One)\n                      apply auto\n                      done\n                    with not_def have \"rnot = Tip\" by simp\n                    with rnot_Node show ?thesis by simp\n                  qed\n                next\n                  fix rnot lnot rnort lnort\n                  assume rnort_in_repb_Nodesn: \"set_of rnort \\<subseteq> repb ` Nodes n ll\"\n                  assume rnort_repb_no: \"\\<forall>no\\<in>set_of rnort. repb no = no\"\n                  from repbNodes_in_Nodes rnort_in_repb_Nodesn \n                  have rnort_in_Nodesn: \"set_of rnort \\<subseteq> Nodes n ll\"\n                    by blast\n                  show \"\\<forall>no\\<in>set_of rnort. repc no = no\"\n                  proof\n                    fix pt\n                    assume pt_in_rnort: \" pt \\<in> set_of rnort\"\n                    with rnort_in_Nodesn have \"pt \\<in> Nodes n ll\" \n                      by blast\n                    with Nodesn_notin_lln have \"pt \\<notin> set (ll ! n)\"\n                      by auto\n                    with repbc_nc have \"repb pt = repc pt\"\n                      by auto\n                    with rnort_repb_no pt_in_rnort show \"repc pt = pt\"\n                      by auto\n                  qed\n                qed\n                with varrep show ?thesis by simp\n              next\n                assume share_case_cond: \"repc (low no) \\<noteq> repc (high no)\"\n                with lno_nNull hno_nNull \n                have share_case_cond_propto: \"(repc \\<propto> low) no \\<noteq> (repc \\<propto> high) no\"\n                  by (simp add: null_comp_def)\n                with repshare obtain \n                  rno_in_llbn: \"repc no \\<in> set (ll ! n)\" and\n                  rrno_eq_rno: \"repc (repc no) = repc no\" and\n                  twonodes_in_llbn_prop: \"(\\<forall>no1\\<in>set (ll ! n). \n                  ((repc \\<propto> high) no1 = (repc \\<propto> high) no \\<and> \n                  (repc \\<propto> low) no1 = (repc \\<propto> low) no) = (repc no = repc no1))\"\n                  by auto\n                from wf_ll rno_in_llbn  nsll \n                have varrepno_n: \"var (repc no) = n\" \n                  by (simp add: wf_ll_def length_ll_eq)\n                with varno have varrep: \"?varrep\" \n                  by simp\n                from not_nort_prop_high not_nort_prop_low have repcn_prop: \"?repcn_prop\"\n                  apply-\n                  apply (elim exE)\n                  apply (rename_tac rnot lnot rnort lnort)\n                  apply (rule_tac x=\"Node lnot no rnot\" in exI)\n                  apply (rule_tac x=\"Node lnort (repc no) rnort\" in exI)\n                  apply (elim conjE)\n                  apply (intro conjI)\n                  prefer 7\n                  apply (elim exE)\n                  apply (rename_tac rnot lnot rnort lnort rnobdt lnobdt rnorbdt lnorbdt)\n                  apply (elim conjE)\n                  apply (case_tac  \"Suc 0 < var no\")\n                  apply (rule_tac x=\"(Bdt_Node lnobdt (var no) rnobdt)\" in exI)\n                  apply (rule conjI)\n                  prefer 2\n                  apply (rule_tac x=\"(Bdt_Node lnorbdt (var (repc no)) rnorbdt)\" in exI)\n                  apply (rule conjI)\n                proof -\n                  fix rnot lnot rnort lnort\n                  assume rnort_dag: \n                    \"Dag (repc (high no)) (repb \\<propto> low) (repb \\<propto> high) rnort\"\n                  assume lnort_dag: \n                    \"Dag (repc (low no)) (repb \\<propto> low) (repb \\<propto> high) lnort\"\n                  assume rnort_in_repNodes: \"set_of rnort \\<subseteq> repb ` Nodes n ll\"\n                  assume lnort_in_repNodes: \"set_of lnort \\<subseteq> repb ` Nodes n ll\"\n                  from rnort_in_repNodes repbNodes_in_Nodes \n                  have rnort_in_Nodes: \"set_of rnort \\<subseteq> Nodes n ll\"\n                    by simp\n                  from lnort_in_repNodes repbNodes_in_Nodes \n                  have lnort_in_Nodes: \"set_of lnort \\<subseteq> Nodes n ll\"\n                    by simp\n                  from rnort_in_Nodes \n                  have rnortx_in_Nodes: \"\\<forall> x \\<in> set_of rnort. x \\<in> Nodes n ll\"\n                    by blast\n                  with wf_ll nsll  \n                  have \"\\<forall> x \\<in> set_of rnort. x \\<in> set_of pret \\<and> var x < n\"\n                    apply -\n                    apply (rule ballI)\n                    apply (rule wf_ll_Nodes_pret)\n                    apply (auto simp add: length_ll_eq)\n                    done\n                  with pret_dag prebdt_pret rnort_dag ord_pret wf_ll  nsll \n                    repbc_nc \n                  have \"\\<forall>x \\<in> set_of rnort. (repc \\<propto> low) x = (repb \\<propto> low) x \\<and> \n                    (repc \\<propto> high) x = (repb \\<propto> high) x\"\n                    apply -\n                    apply (rule nort_null_comp)\n                    apply (auto simp add: length_ll_eq)\n                    done\n                  then have \"Dag (repc (high no)) (repc \\<propto> low) (repc \\<propto> high) rnort = \n                    Dag (repc (high no)) (repb \\<propto> low) (repb \\<propto> high) rnort\" \n                    apply -\n                    apply (rule heaps_eq_Dag_eq)\n                    apply assumption\n                    done\n                  with rnort_dag \n                  have rnort_dag_repc: \n                    \"Dag (repc (high no)) (repc \\<propto> low) (repc \\<propto> high) rnort\" \n                    by simp\n                  from lnort_in_Nodes \n                  have lnortx_in_Nodes: \"\\<forall>x \\<in> set_of lnort. x \\<in> Nodes n ll\"\n                    by blast\n                  with wf_ll nsll  \n                  have \"\\<forall> x \\<in> set_of lnort. x \\<in> set_of pret \\<and> var x < n\"\n                    apply -\n                    apply (rule ballI)\n                    apply (rule wf_ll_Nodes_pret)\n                    apply (auto simp add: length_ll_eq)\n                    done\n                  with pret_dag prebdt_pret lnort_dag ord_pret wf_ll  nsll \n                    repbc_nc \n                  have \"\\<forall> x \\<in> set_of lnort. (repc \\<propto> low) x = (repb \\<propto> low) x \\<and> \n                    (repc \\<propto> high) x = (repb \\<propto> high) x\"\n                    apply -\n                    apply (rule nort_null_comp)\n                    apply (auto simp add: length_ll_eq)\n                    done\n                  then have \n                    \"Dag (repc (low no)) (repc \\<propto> low) (repc \\<propto> high) lnort = \n                    Dag (repc (low no)) (repb \\<propto> low) (repb \\<propto> high) lnort\" \n                    apply -\n                    apply (rule heaps_eq_Dag_eq)\n                    apply assumption\n                    done\n                  with lnort_dag \n                  have lnort_dag_repc: \n                    \"Dag (repc (low no)) (repc \\<propto> low) (repc \\<propto> high) lnort\" \n                    by simp\n                  from lno_nNull hno_nNull   \n                  have propto_comp: \"(repc \\<propto> low) no = repc (low no) \\<and> \n                    (repc \\<propto> high) no = repc (high no)\" \n                    by (simp add: null_comp_def)\n                  from rno_in_llbn twonodes_in_llbn_prop rrno_eq_rno \n                  have \"(repc \\<propto> high) (repc no) = (repc \\<propto> high) no \\<and> \n                    (repc \\<propto> low) (repc no) = (repc \\<propto> low) no\"\n                    by simp\n                  with propto_comp lnort_dag_repc rnort_dag_repc lno_nNull hno_nNull \n                    rnonN   \n                  show \"Dag(repc no)(repc \\<propto> low)(repc \\<propto> high)(Node lnort (repc no) rnort)\"\n                    by auto\n                next\n                  fix rnot lnot rnort lnort\n                  assume rnot_dag: \"Dag (high no) low high rnot\"\n                  assume lnot_dag: \"Dag (low no) low high lnot\"\n                  with rnot_dag nonNull   \n                  show \"Dag no low high (Node lnot no rnot)\" \n                    by simp\n                next\n                  fix rnort lnort\n                  assume rnort_dag: \n                    \"Dag (repc (high no)) (repb \\<propto> low) (repb \\<propto> high) rnort\"\n                  assume lnort_dag: \n                    \"Dag (repc (low no)) (repb \\<propto> low) (repb \\<propto> high) lnort\"\n                  assume red_rnort: \"reduced rnort\"\n                  assume red_lnort: \" reduced lnort\"\n                  from rhn_nNull rnort_dag obtain lrnort rrnort where \n                    rnort_Node: \"rnort = (Node lrnort (repc (high no)) rrnort)\"\n                    by auto\n                  from rln_nNull lnort_dag obtain llnort rlnort where \n                    lnort_Node: \"lnort = (Node llnort (repc (low no)) rlnort)\"\n                    by auto\n                  from twonodes_in_llbn_prop rrno_eq_rno rno_in_llbn hno_nNull lno_nNull \n                  have \"((repc \\<propto> high) (repc no)) = repc (high no) \\<and> \n                    ((repc \\<propto> low) (repc no)) = repc (low no)\"\n                    apply -\n                    apply (erule_tac x=\"repc no\" in ballE)\n                    apply (auto simp add: null_comp_def)\n                    done\n                  with share_case_cond \n                  have \"((repc \\<propto> high) (repc no)) \\<noteq> ((repc \\<propto> low) (repc no))\"\n                    by auto\n                  with red_lnort red_rnort rnort_Node lnort_Node share_case_cond \n                  show \"reduced (Node lnort (repc no) rnort)\"\n                    apply -\n                    apply (rule_tac lp=\"repc (low no)\" and rp=\"repc (high no)\" and \n                      llt=llnort and rlt = rlnort and lrt=lrnort and rrt=rrnort \n                      in reduced_children_parent)\n                    apply auto\n                    done\n                next\n                  fix lnort rnort\n                  assume lnort_dag: \n                    \"Dag (repc (low no)) (repb \\<propto> low) (repb \\<propto> high) lnort\"\n                  assume ord_lnort: \"ordered lnort var\"\n                  assume rnort_dag: \n                    \"Dag (repc (high no)) (repb \\<propto> low) (repb \\<propto> high) rnort\"\n                  assume ord_rnort: \" ordered rnort var\"\n                  assume lnort_in_repNodes: \"set_of lnort \\<subseteq> repb `Nodes n ll\"\n                  assume rnort_in_repNodes: \"set_of rnort \\<subseteq> repb `Nodes n ll\"\n                  from lnort_in_repNodes repbNodes_in_Nodes \n                  have lnort_in_Nodes: \"set_of lnort \\<subseteq> Nodes n ll\"\n                    by simp\n                  from rnort_in_repNodes repbNodes_in_Nodes \n                  have rnort_in_Nodes: \"set_of rnort \\<subseteq> Nodes n ll\"\n                    by simp\n\n                  from rhn_nNull rnort_dag obtain lrnort rrnort where \n                    rnort_Node: \"rnort = (Node lrnort (repc (high no)) rrnort)\"\n                    by auto\n                  from rln_nNull lnort_dag obtain llnort rlnort where \n                    lnort_Node: \"lnort = (Node llnort (repc (low no)) rlnort)\"\n                    by auto\n                  from lnort_dag rln_nNull lnort_in_Nodes \n                  have \"repc (low no) \\<in> set_of lnort\" \n                    by auto\n                  with lnort_in_Nodes \n                  have \"repc (low no) \\<in> Nodes n ll\"\n                    by blast\n                  with wf_ll nsll  \n                  have vrlno_sn: \"var (repc (low no)) < n\"\n                    apply -\n                    apply (drule wf_ll_Nodes_pret)\n                    apply (auto simp add: length_ll_eq)\n                    done\n                  from rnort_dag rhn_nNull rnort_in_Nodes \n                  have \"repc (high no) \\<in> set_of rnort\" \n                    by auto\n                  with rnort_in_Nodes \n                  have \"repc (high no) \\<in> Nodes n ll\"\n                    by blast\n                  with wf_ll nsll  have vrhno_sn: \"var (repc (high no)) < n\"\n                    apply -\n                    apply (drule wf_ll_Nodes_pret)\n                    apply (auto simp add: length_ll_eq)\n                    done\n                  with varrepno_n vrlno_sn lnort_dag ord_lnort rnort_dag rnort_Node \n                    lnort_Node ord_rnort \n                  show \"ordered (Node lnort (repc no) rnort) var\"\n                    by auto\n                next\n                  fix lnort rnort\n                  assume lnort_in_Nodes: \"set_of lnort \\<subseteq> repb `Nodes n ll\"\n                  assume rnort_in_Nodes: \"set_of rnort \\<subseteq> repb `Nodes n ll\"\n                  from lnort_in_Nodes repbNodes_repcNodes \n                  have lnort_in_repcNodes: \"set_of lnort \\<subseteq> repc `Nodes n ll\"\n                    by simp\n                  from rnort_in_Nodes repbNodes_repcNodes \n                  have rnort_in_repcNodes: \"set_of rnort \\<subseteq> repc `Nodes n ll\"\n                    by simp\n                  have nNodessubset: \"Nodes n ll \\<subseteq> Nodes (n+1) ll\"\n                    by (simp add: Nodes_subset)\n                  then have repc_Nodes_subset:\n                    \"repc `Nodes n ll \\<subseteq> repc `Nodes (n+1) ll\"\n                    by blast\n                  from no_in_Nodes have \"repc no \\<in> repc `Nodes (n+1) ll\"\n                    by blast\n                  with repc_Nodes_subset lnort_in_repcNodes rnort_in_repcNodes \n                  show \"set_of (Node lnort (repc no) rnort) \\<subseteq> \n                    repc `Nodes (n + 1) ll\"\n                    apply simp\n                    apply blast\n                    done\n                next\n                  fix rnot lnot rnort lnort rnobdt lnobdt rnorbdt lnorbdt\n                  assume lnobdt_def: \" bdt lnot var = Some lnobdt\"\n                  assume rnobdt_def: \" bdt rnot var = Some rnobdt\"\n                  assume rnorbdt_def: \" bdt rnort var = Some rnorbdt\"\n                  assume cong_rno_rnor: \" rnobdt \\<sim> rnorbdt\"\n                  assume lnot_dag: \"Dag (low no) low high lnot\"\n                  assume rnot_dag: \"Dag (high no) low high rnot\"\n                  assume \"\\<not> Suc 0 < var no\"\n                  then have varnoseq1: \"var no = 0 \\<or> var no = 1\" by auto\n                  show \"\\<exists>nobdt. bdt (Node lnot no rnot) var = Some nobdt \\<and> \n                    (\\<exists>norbdt. bdt (Node lnort (repc no) rnort) var = Some norbdt \\<and> \n                    nobdt \\<sim> norbdt)\"\n                  proof (cases \"var no = 0\")\n                    case True\n                    note vnoNull=this\n                    with pret_dag ord_pret no_in_pret lno_nNull hno_nNull  \n                    show ?thesis\n                      apply -\n                      apply (drule var_ordered_children)\n                      apply auto\n                      done\n                  next\n                    assume \"var no \\<noteq> 0\"\n                    with varnoseq1 have vnoOne: \"var no = 1\" by simp\n                    from pret_dag  ord_pret no_in_pret lno_nNull hno_nNull  \n                      vnoOne \n                    have vlvrNull: \"var (low no) = 0 \\<and> var (high no) = 0\"\n                      apply -\n                      apply (drule var_ordered_children)\n                      apply auto\n                      done\n                    then have vlNull: \"var (low no) = 0\" by simp\n                    from vlvrNull have vrNull: \"var (high no) = 0\" by simp\n                    from lnobdt_def lnot_dag vlNull  lno_nNull \n                    have lnobdt_Zero: \"lnobdt = Zero\"\n                      apply -\n                      apply (drule bdt_Some_var0_Zero)\n                      apply auto\n                      done\n                    from rnobdt_def rnot_dag vrNull  hno_nNull \n                    have rnobdt_Zero: \"rnobdt = Zero\"\n                      apply -\n                      apply (drule bdt_Some_var0_Zero)\n                      apply auto\n                      done\n                    from lnobdt_Zero lnobdt_def \n                    have \"bdt lnot var = Some Zero\" by simp\n                    with lnot_dag vlNull  \n                    have lnot_Node: \"lnot = (Node Tip (low no) Tip)\"\n                      by auto\n                    from rnobdt_Zero rnobdt_def rnot_dag vrNull  \n                    have rnot_Node: \"rnot = (Node Tip (high no) Tip)\" \n                      by auto\n                    from pret_dag no_in_pret obtain not \n                      where not_ex: \"Dag no low high not\"\n                      apply -\n                      apply (drule dag_setof_exD)\n                      apply auto\n                      done\n                    with pret_dag no_in_pret have not_ex_in_pret: \"not <= pret\" \n                      apply -\n                      apply (rule set_of_subdag)\n                      apply auto\n                      done\n                    from not_ex lnot_dag rnot_dag   nonNull \n                    have not_def: \"not = (Node lnot no rnot)\" \n                      by (simp add: Dag_unique del: Dag_Ref)\n                    with not_ex_in_pret prebdt_pret \n                    have nobdt_ex: \"\\<exists> nobdt. bdt (Node lnot no rnot) var = Some nobdt\"\n                      apply -\n                      apply (rule subbdt_ex)\n                      apply auto\n                      done\n                    then obtain nobdt where \n                      nobdt_def: \"bdt (Node lnot no rnot) var = Some nobdt\" by auto\n                    from not_def have \"root not = no\" by simp\n                    with nobdt_def vnoOne not_def \n                    have \"not = (Node Tip no Tip)\"\n                      apply -\n                      apply (drule bdt_Some_var1_One)\n                      apply auto\n                      done\n                    with not_def have \"rnot = Tip\" by simp\n                    with rnot_Node show ?thesis by simp\n                  qed\n                next\n                  fix lnot rnot lnobdt rnobdt\n                  assume lnot_dag: \"Dag (low no) low high lnot\"\n                  assume rnot_dag: \" Dag (high no) low high rnot\"\n                  assume lnobdt_def: \" bdt lnot var = Some lnobdt\"\n                  assume rnobdt_def: \" bdt rnot var = Some rnobdt\"\n                  assume onesvarno: \" Suc 0 < var no\"\n                  with rnobdt_def lnot_dag rnot_dag lnobdt_def \n                  show \"bdt (Node lnot no rnot) var = \n                    Some (Bdt_Node lnobdt (var no) rnobdt)\" by simp\n                next\n                  fix rnot lnot rnort lnort rnobdt lnobdt rnorbdt lnorbdt\n                  assume rnort_dag: \n                    \"Dag (repc (high no)) (repb \\<propto> low) (repb \\<propto> high) rnort\"\n                  assume lnort_dag: \n                    \"Dag (repc (low no)) (repb \\<propto> low) (repb \\<propto> high) lnort\"\n                  assume rnorbdt_def: \" bdt rnort var = Some rnorbdt\"\n                  assume lnorbdt_def: \"bdt lnort var = Some lnorbdt\"\n                  assume varno_bOne: \"Suc 0 < var no\"\n                  with varno have \"Suc 0 < n\" by simp\n                  with varrepno_n have \"Suc 0 < var (repc no)\" by simp\n                  with rnorbdt_def lnorbdt_def \n                  show \"bdt (Node lnort (repc no) rnort) var = \n                    Some (Bdt_Node lnorbdt (var (repc no)) rnorbdt)\"\n                    by simp\n                next\n                  fix rnobdt lnobdt rnorbdt lnorbdt \n                  assume lcong_eval: \"lnobdt \\<sim> lnorbdt\"\n                  assume rcong_eval: \" rnobdt \\<sim> rnorbdt\"\n                  from varno varrepno_n have \"var (repc no) = var no\" by simp\n                  with lcong_eval rcong_eval \n                  show \"Bdt_Node lnobdt (var no) rnobdt \\<sim> \n                    Bdt_Node lnorbdt (var (repc no)) rnorbdt\"\n                    apply (unfold cong_eval_def)\n                    apply (rule ext)\n                    by simp\n                next\n                  fix rnot lnot rnort lnort\n                  assume lnort_repb: \"\\<forall>no\\<in>set_of lnort. repb no = no\"\n                  assume rnort_repb: \"\\<forall>no\\<in>set_of rnort. repb no = no\"\n                  assume rnort_in_repb_Nodesn: \"set_of rnort \\<subseteq> repb ` Nodes n ll\"\n                  assume lnort_in_repb_Nodesn: \"set_of lnort \\<subseteq> repb ` Nodes n ll\"\n                  from repbNodes_in_Nodes rnort_in_repb_Nodesn \n                  have rnort_in_Nodesn: \"set_of rnort \\<subseteq> Nodes n ll\"\n                    by blast\n                  from repbNodes_in_Nodes lnort_in_repb_Nodesn \n                  have lnort_in_Nodesn: \"set_of lnort \\<subseteq> Nodes n ll\"\n                    by blast\n                  have rnort_repc: \"\\<forall>no\\<in>set_of rnort. repc no = no\"\n                  proof\n                    fix pt\n                    assume pt_in_rnort: \" pt \\<in> set_of rnort\"\n                    with rnort_in_Nodesn have \"pt \\<in> Nodes n ll\" \n                      by blast\n                    with Nodesn_notin_lln have \"pt \\<notin> set (ll ! n)\"\n                      by auto\n                    with repbc_nc have \"repb pt = repc pt\"\n                      by auto\n                    with rnort_repb pt_in_rnort show \"repc pt = pt\"\n                      by auto\n                  qed\n                  have lnort_repc: \"\\<forall>no\\<in>set_of lnort. repc no = no\"\n                  proof\n                    fix pt\n                    assume pt_in_lnort: \" pt \\<in> set_of lnort\"\n                    with lnort_in_Nodesn have \"pt \\<in> Nodes n ll\" \n                      by blast\n                    with Nodesn_notin_lln have \"pt \\<notin> set (ll ! n)\"\n                      by auto\n                    with repbc_nc have \"repb pt = repc pt\"\n                      by auto\n                    with lnort_repb pt_in_lnort show \"repc pt = pt\"\n                      by auto\n                  qed\n                  show \"\\<forall>no\\<in>set_of (Node lnort (repc no) rnort). repc no = no\"\n                  proof\n                    fix pt\n                    assume pt_in_rept: \"pt \\<in> set_of (Node lnort (repc no) rnort)\"\n                    show \"repc pt = pt\"\n                    proof (cases \"pt \\<in> set_of lnort\")\n                      case True\n                      with lnort_repc show ?thesis\n                        by auto\n                    next\n                      assume pt_notin_lnort: \"pt \\<notin> set_of lnort\"\n                      show ?thesis\n                      proof (cases \"pt \\<in> set_of rnort\")\n                        case True\n                        with rnort_repc show ?thesis\n                          by auto\n                      next \n                        assume pt_notin_rnort: \"pt \\<notin> set_of rnort\"\n                        with pt_notin_lnort pt_in_rept have \"pt = repc no\"\n                          by simp\n                        with rrno_eq_rno show \"repc pt = pt\"\n                          by simp\n                      qed\n                    qed\n                  qed\n                qed\n                \n                with varrep rrno_eq_rno show ?thesis by simp\n              qed\n            qed\n            with rnonN show ?thesis by simp\n          qed\n        qed\n        note while_while_prop=this\n        from wf_ll nsll  \n        have \"\\<forall>no \\<in> Nodes n ll. no \\<notin> set (ll ! n)\"\n          apply (simp add: Nodes_def length_ll_eq)\n          apply clarify\n          apply (drule no_in_one_ll)\n          apply auto\n          done\n        with repbc_nc  have \"\\<forall>no \\<in> Nodes n ll. repb no = repc no\"\n          apply -\n          apply (rule ballI)\n          apply (erule_tac x=no in allE)\n          apply simp\n          done\n        then have repbNodes_repcNodes: \n          \"repb `(Nodes n ll) = repc `(Nodes n ll)\"\n          apply -\n          apply rule\n          apply blast\n          apply rule\n          apply (erule imageE)\n          apply (erule_tac x=xa in ballE)\n          prefer 2\n          apply simp\n          apply rule\n          apply auto\n          done\n        then have repcNodes_repbNodes: \n          \"repc `(Nodes n ll) = repb `(Nodes n ll)\"\n          by simp\n        have repbc_dags_eq: \n          \"Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high) = \n          Dags (repb  ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high)\"\n          apply -\n          apply rule\n          apply rule\n          apply (erule Dags.cases)\n          apply (rule DagsI)\n          prefer 4\n          apply rule\n          apply (erule Dags.cases)\n          apply (rule DagsI)\n        proof -\n          fix x p t\n          assume t_in_repcNodes: \"set_of t \\<subseteq> repc ` Nodes n ll\"\n          assume x_t: \"x=t\"\n          with t_in_repcNodes repcNodes_repbNodes \n          show \"set_of x \\<subseteq> repb ` Nodes n ll\" \n            by simp\n        next\n          fix x p t\n          assume t_in_repcNodes: \"set_of t \\<subseteq> repc ` Nodes n ll\"\n          assume t_dag: \"Dag p (repc \\<propto> low) (repc \\<propto> high) t\"\n          assume t_nTip: \" t \\<noteq> Tip\"\n          assume x_t: \"x=t\"\n          from t_nTip t_dag have \"p \\<noteq> Null\"\n            apply -\n            apply (case_tac \"p=Null\")\n            apply auto\n            done\n          with t_nTip t_dag obtain lt rt where t_Node: \"t=Node lt p rt\"\n            by auto\n          from t_in_repcNodes t_dag t_nTip t_Node obtain q where \n            rq_p: \"repc q = p\" and q_in_Nodes: \"q \\<in> Nodes n ll\"\n            apply simp\n            apply (elim conjE)\n            apply (erule imageE)\n            apply auto\n            done\n          from q_in_Nodes have \"repb q = repc q\"\n            by (rule Nodes_n_rep_nc [rule_format])\n          with rq_p have repbq_p: \"repb q = p\" by simp\n          from q_in_Nodes \n          have \"Dag (repb q) (repb \\<propto> low) (repb \\<propto> high) t = \n            Dag (repc q) (repc \\<propto> low) (repc \\<propto> high) t\"\n            by (rule Nodes_repbc_Dags_eq [rule_format])\n          with t_dag rq_p have \"Dag (repb q) (repb \\<propto> low) (repb \\<propto> high) t\" by simp\n          with repbq_p x_t show \"Dag p (repb \\<propto> low) (repb \\<propto> high) x\"\n            by simp\n        next\n          fix x p t\n          assume t_in_repcNodes: \"set_of t \\<subseteq> repb ` Nodes n ll\"\n          assume x_t: \"x=t\"\n          with t_in_repcNodes repbNodes_repcNodes \n          show \"set_of x \\<subseteq> repc ` Nodes n ll\" \n            by simp\n        next\n          fix x p t\n          assume t_in_repcNodes: \"set_of t \\<subseteq> repb ` Nodes n ll\"\n          assume t_dag: \"Dag p (repb \\<propto> low) (repb \\<propto> high) t\"\n          assume t_nTip: \" t \\<noteq> Tip\"\n          assume x_t: \"x=t\"\n          from t_nTip t_dag have \"p \\<noteq> Null\"\n            apply -\n            apply (case_tac \"p=Null\")\n            apply auto\n            done\n          with t_nTip t_dag obtain lt rt where t_Node: \"t=Node lt p rt\"\n            by auto\n          from t_in_repcNodes t_dag t_nTip t_Node obtain q where \n            rq_p: \"repb q = p\" and q_in_Nodes: \"q \\<in> Nodes n ll\"\n            apply simp\n            apply (elim conjE)\n            apply (erule imageE)\n            apply auto\n            done\n          from q_in_Nodes have \"repb q = repc q\"\n            by (rule Nodes_n_rep_nc [rule_format])\n          with rq_p have repbq_p: \"repc q = p\" by simp\n          from q_in_Nodes \n          have \"Dag (repb q) (repb \\<propto> low) (repb \\<propto> high) t = \n            Dag (repc q) (repc \\<propto> low) (repc \\<propto> high) t\"\n            by (rule Nodes_repbc_Dags_eq [rule_format])\n          with t_dag rq_p have \"Dag (repc q) (repc \\<propto> low) (repc \\<propto> high) t\" by simp\n          with repbq_p x_t show \"Dag p (repc \\<propto> low) (repc \\<propto> high) x\"\n            by simp\n        next\n          fix x p and t :: \"dag\"\n          assume x_t: \"x = t\"\n          assume t_nTip: \" t \\<noteq> Tip\"\n          with x_t show \"x\\<noteq> Tip\" by simp\n        next\n          fix x p and t :: \"dag\"\n          assume x_t: \"x = t\"\n          assume t_nTip: \" t \\<noteq> Tip\"\n          with x_t show \"x\\<noteq> Tip\" by simp\n        qed\n        from pret_dag wf_ll nsll \n        have null_notin_Nodes_Suc_n: \"Null \\<notin> Nodes (Suc n) ll\"\n          by  - (rule Null_notin_Nodes,auto simp add: length_ll_eq)\n        { fix t1 t2\n          assume t1_in_DagsNodesn: \n            \"t1 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume t2_notin_DagsNodesn: \n            \"t2 \\<notin> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume t2_in_DagsNodesSucn: \n            \"t2 \\<in> Dags (repc ` Nodes (Suc n) ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume isomorphic_dags_eq_asm: \n            \"\\<forall>t1 t2. t1 \\<in> Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high) \n            \\<and> t2 \\<in> Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high) \n            \\<longrightarrow> isomorphic_dags_eq t1 t2 var\"\n          assume repbc_Dags: \n            \"Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high) = \n            Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high)\"\n          from t1_in_DagsNodesn repbc_Dags \n          have t1_repb_subnode: \n            \"t1 \\<in> Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high)\" \n            by simp\n          from t2_in_DagsNodesSucn \n          have t2_in_DagsNodesSucn: \n            \"t2 \\<in> Dags (repc ` Nodes (Suc n) ll) (repc \\<propto> low) (repc \\<propto> high)\" \n            by simp\n          from repbNodes_in_Nodes repbNodes_repcNodes \n          have repcNodesn_in_Nodesn: \"repc `Nodes n ll \\<subseteq> Nodes n ll\"\n            by simp\n          from t1_in_DagsNodesn obtain q where \n            Dag_q_Nodes_n: \n            \"Dag (repc q) (repc \\<propto> low) (repc \\<propto> high) t1 \\<and> q \\<in> Nodes n ll\"\n          proof (elim Dags.cases)\n            fix p t\n            assume t1_t: \"t1 = t\"\n            assume t_in_repcNodesn: \"set_of t \\<subseteq> repc ` Nodes n ll\"\n            assume t_dag: \"Dag p (repc \\<propto> low) (repc \\<propto> high) t\"\n            assume t_nTip: \" t \\<noteq> Tip\"\n            assume obtain_prop: \"\\<And>q. Dag (repc q) (repc \\<propto> low) (repc \\<propto> high) t1 \\<and> \n              q \\<in> Nodes n ll \\<Longrightarrow> ?thesis\"\n            from t_nTip t_dag have \"p \\<noteq> Null\"\n              apply -\n              apply (case_tac \"p=Null\")\n              apply auto\n              done\n            with t_nTip t_dag obtain lt rt where t_Node: \"t=Node lt p rt\"\n              by auto\n            from t_in_repcNodesn t_dag t_nTip t_Node obtain k where \n              rk_p: \"repc k = p\" and k_in_Nodes: \"k \\<in> Nodes n ll\"\n              apply simp\n              apply (elim conjE)\n              apply (erule imageE)\n              apply auto\n              done\n            with t1_t t_dag obtain_prop rk_p k_in_Nodes show ?thesis\n              by auto\n          qed\n          with wf_ll  nsll  have varq_sn: \"(var q < n)\"         \n            apply (simp add: Nodes_def)\n            apply (elim conjE)\n            apply (erule exE)\n            apply (simp add: wf_ll_def length_ll_eq)\n            apply (elim conjE)\n            apply (thin_tac \" \\<forall>q. q \\<in> set_of pret \\<longrightarrow> q \\<in> set (ll ! var q)\")\n            apply (erule_tac x=k in allE)\n            apply auto\n            done\n          from Dag_q_Nodes_n have q_in_Nodesn: \"q \\<in> Nodes n ll\"\n            by simp\n          then have \"\\<exists> k<n. q \\<in> set (ll ! k)\"\n            by (simp add: Nodes_def)\n          with wf_ll nsll  have \"q \\<notin> set (ll ! n)\"\n            apply -\n            apply (erule exE)\n            apply (rule_tac i=k and j=n in no_in_one_ll)\n            apply (auto simp add: length_ll_eq)\n            done\n          with repbc_nc  have repbc_q: \"repc q = repb q\"\n            apply -\n            apply (erule_tac x=q in allE)\n            apply auto\n            done\n          from normalize_prop q_in_Nodesn have \"var (repb q) <= var q\"\n            apply -\n            apply (erule_tac x=q in ballE)\n            apply auto\n            done\n          with repbc_q have var_repc_q: \"var (repc q) <= var q\"\n            by simp\n          with varq_sn have var_repc_q_n: \"var (repc q) < n\"\n            by simp\n          \n          from Nodes_subset Dag_q_Nodes_n while_while_prop \n          have ord_t1_var_rep: \"ordered t1 var \\<and> var (repc q) <= var q\" \n            apply (elim conjE)\n            apply (erule_tac x=q in ballE)\n            apply auto\n            done\n          then have ord_t1: \"ordered t1 var\" by simp\n          from ord_t1_var_rep have varrep_q: \"var (repc q) <= var q\" by simp\n          from t2_in_DagsNodesSucn have ord_t2: \"ordered t2 var\"\n          proof (elim Dags.cases)\n            fix p t\n            assume t_in_repcNodes: \"set_of t \\<subseteq> repc ` Nodes (Suc n) ll\"\n            assume t_nTip: \" t \\<noteq> Tip\"\n            assume t2t: \"t2 = t\"\n            assume t_dag: \"Dag p (repc \\<propto> low) (repc \\<propto> high) t\"\n            from t_in_repcNodes have x_in_repcNodesSucn:  \n              \"\\<forall>x. x \\<in> set_of t \\<longrightarrow> x \\<in> repc ` Nodes (Suc n) ll\" \n              apply -\n              apply auto\n              done\n            from t_nTip t_dag have \"p \\<noteq> Null\"\n              apply -\n              apply (case_tac \"p=Null\")\n              apply auto\n              done\n            with t_nTip t_dag obtain lt rt where t_Node: \"t=Node lt p rt\"\n              by auto\n            then have \"p \\<in> set_of t\"\n              by auto\n            with x_in_repcNodesSucn have \"p \\<in> repc ` Nodes (Suc n) ll\"\n              by simp\n            then obtain a where repca_p: \"p=repc a\" and \n              a_in_NodesSucn: \"a \\<in> Nodes (Suc n) ll\"\n              by auto\n            with repca_p while_while_prop t_dag t2t show ?thesis\n              apply -\n              apply (erule_tac x=a in ballE)\n              apply (elim conjE exE)\n              apply (subgoal_tac \"nort = t\") \n              prefer 2\n              apply (simp add: Dag_unique)\n              apply auto\n              done\n          qed\n          from while_while_prop have while_prop_part: \n            \"\\<forall>no \\<in> Nodes (Suc n) ll. \n            var (repc no) <= var no\"\n            by auto\n          from while_while_prop have rep_rep_nort: \n            \"\\<forall>no\\<in>Nodes (n + 1) ll. (\\<exists>nort. Dag (repc no) (repc \\<propto> low) (repc \\<propto> high) nort \\<and> \n            (\\<forall>no\\<in>set_of nort. repc no = no))\"\n            by auto\n          from repcNodes_in_Nodes null_notin_Nodes_Suc_n \n          have \"\\<forall>no \\<in> Nodes (n+1) ll. repc no \\<noteq> Null\"\n            by auto\n          with rep_rep_nort have \"\\<forall> no \\<in> Nodes (n+1) ll. repc (repc no) = (repc no)\"\n            apply -\n            apply (rule ballI)\n            apply (erule_tac x=no in ballE)\n            prefer 2\n            apply simp\n            apply (erule_tac x=no in ballE)\n            apply (erule exE)\n            apply (subgoal_tac \"repc no \\<in> set_of nort\")\n            apply (elim conjE)\n            apply (erule_tac x=\"repc no\" in ballE)\n            apply simp\n            apply simp\n            apply (simp)\n            apply (elim conjE)\n            apply (thin_tac \"\\<forall>no\\<in>set_of nort. repc no = no\")\n            apply auto\n            done\n          with t2_in_DagsNodesSucn t2_notin_DagsNodesn ord_t2 while_prop_part \n            wf_ll nsll  repcNodes_in_Nodes obtain a where\n            t2_repc_dag: \"Dag (repc a) (repc \\<propto> low) (repc \\<propto> high) t2\" and\n            a_in_lln: \"a \\<in> set (ll ! n)\"\n            apply -\n            apply (drule restrict_root_Node)\n            apply (auto simp add: length_ll_eq)\n            done\n          with wf_ll nsll  have a_in_pret: \"a \\<in> set_of pret\" \n            by (simp add: wf_ll_def length_ll_eq)\n          from wf_ll nsll  a_in_lln have vara_n: \"var a = n\" \n            by (simp add: wf_ll_def length_ll_eq)\n          from a_in_lln rep_prop  obtain\n            repp_nNull: \" repc a \\<noteq> Null\" and\n            repp_reduce: \"(repc \\<propto> low) a = (repc \\<propto> high) a \\<and> low a \\<noteq> Null \n            \\<longrightarrow> repc a = (repc \\<propto> high) a\" and\n            repp_share: \"((repc \\<propto> low) a = (repc \\<propto> high) a \\<longrightarrow> low a = Null) \n            \\<longrightarrow> repc a \\<in> set (ll ! n) \\<and>\n            repc (repc a) = repc a \\<and> \n            (\\<forall>no1\\<in>set (ll ! n). ((repc \\<propto> high) no1 = (repc \\<propto> high) a \\<and> \n            (repc \\<propto> low) no1 = (repc \\<propto> low) a) = (repc a = repc no1))\"\n            using [[simp_depth_limit=4]]\n            by auto\n          from t2_repc_dag a_in_lln repp_nNull obtain lt2 rt2 where \n            t2_Node: \"t2 = (Node lt2 (repc a) rt2)\"\n            by auto\n          have \"isomorphic_dags_eq t1 t2 var\"\n          proof (cases \"(repc \\<propto> low) a = (repc \\<propto> high) a \\<and> low a \\<noteq> Null\")\n            case True\n            note red=this\n            then have red_case: \"(repc \\<propto> low) a = (repc \\<propto> high) a\"\n              by simp\n            from red have low_nNull: \"low a \\<noteq> Null\"\n              by simp\n            with pret_dag prebdt_pret a_in_pret have highp_nNull: \"high a \\<noteq> Null\" \n              apply -\n              apply (drule balanced_bdt)\n              apply auto\n              done\n            from pret_dag ord_pret a_in_pret low_nNull highp_nNull \n            have var_children_smaller: \"var (low a) < var a \\<and> var (high a) < var a\"\n              apply -\n              apply (rule var_ordered_children)\n              apply auto\n              done\n            from pret_dag a_in_pret have a_nNull: \"a \\<noteq> Null\" \n              apply -\n              apply (rule set_of_nn [rule_format])\n              apply auto\n              done\n            with a_in_pret highp_nNull pret_dag have \"high a \\<in> set_of pret\" \n              apply -\n              apply (drule subelem_set_of_high)\n              apply auto\n              done\n            with wf_ll have \"high a \\<in> set (ll ! (var (high a)))\" \n              by (simp add: wf_ll_def)\n            with a_in_lln t2_repc_dag var_children_smaller vara_n \n            have \"\\<exists> k<n. (high a) \\<in> set (ll ! k)\"\n              by auto\n            then have higha_in_Nodesn: \"(high a) \\<in> Nodes n ll\"\n              by (simp add: Nodes_def)\n            then have rhigha_in_rNodesn: \"repc (high a) \\<in> repc ` Nodes n ll\"\n              by simp\n            from higha_in_Nodesn normalize_prop obtain rt where \n              rt_dag:  \"Dag (repb (high a)) (repb \\<propto> low) (repb \\<propto> high) rt\" and\n              rt_in_repbNort: \"set_of rt \\<subseteq> repb `Nodes n ll\"\n              apply -\n              apply (erule_tac x=\"high a\" in ballE)\n              apply auto\n              done\n            from rt_in_repbNort repbNodes_repcNodes \n            have rt_in_repcNodesn: \"set_of rt \\<subseteq> repc `Nodes n ll\"\n              by blast\n            from rt_dag higha_in_Nodesn \n            have repcrt_dag: \"Dag (repc (high a)) (repc \\<propto> low) (repc \\<propto> high) rt\"\n              apply -\n              apply (drule Nodes_repbc_Dags_eq [rule_format])\n              apply auto\n              done\n            have rt_nTip: \"rt \\<noteq> Tip\"\n            proof -\n              have \"repc (high a) \\<noteq> Null\"\n              proof -\n                note rhigha_in_rNodesn\n                also have \"repc `Nodes n ll \\<subseteq> repc `Nodes (Suc n) ll\"\n                  using Nodes_subset \n                  by blast\n                also have \"\\<dots> \\<subseteq> Nodes (Suc n) ll\"\n                  using repcNodes_in_Nodes\n                  by simp\n                finally show ?thesis\n                  using null_notin_Nodes_Suc_n\n                  by auto\n              qed\n              with repcrt_dag show ?thesis by auto\n            qed\n            from a_nNull a_in_pret low_nNull pret_dag have \"low a \\<in> set_of pret\" \n              apply -\n              apply (drule subelem_set_of_low)\n              apply auto\n              done\n            with wf_ll have \"low a \\<in> set (ll ! (var (low a)))\" \n              by (simp add: wf_ll_def)\n            with a_in_lln t2_repc_dag var_children_smaller vara_n \n            have \"\\<exists>k<n. (low a) \\<in> set (ll ! k)\"\n              by auto\n            then have \"(low a) \\<in> Nodes n ll\"\n              by (simp add: Nodes_def)\n            then have rlow_in_rNodesn: \"repc (low a) \\<in> repc ` Nodes n ll\"\n              by simp\n            show ?thesis\n            proof -\n              from repp_reduce low_nNull  highp_nNull  red_case \n              have repc_p_def: \"repc a = repc (high a)\" \n                by (simp add: null_comp_def)\n              with rt_in_repcNodesn repcrt_dag rhigha_in_rNodesn a_in_lln t2_repc_dag\n                repc_p_def  rt_nTip \n              have t2_in_Dags_Nodesn: \n                \"t2 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n                apply -\n                apply (rule DagsI)\n                apply simp\n                apply (subgoal_tac \"t2=rt\")\n                apply (auto simp add: Dag_unique)\n                done\n              from t1_in_DagsNodesn t2_in_Dags_Nodesn repbc_dags_eq isomorphic_dags_eq_asm \n              show shared_t1_t2: \"isomorphic_dags_eq t1 t2 var\"\n                apply -\n                apply (erule_tac x=t1 in allE)\n                apply (erule_tac x=t2 in allE)\n                apply simp\n                done\n            qed\n          next\n            assume share: \" \\<not> ((repc \\<propto> low) a = (repc \\<propto> high) a \\<and> low a \\<noteq> Null)\"\n            then\n            have share: \"(repc \\<propto> low) a \\<noteq> (repc \\<propto> high) a \\<or> low a = Null\"\n              using [[simp_depth_limit=1]]\n              by simp\n            with repp_share obtain \n              ra_in_llbn: \"repc a \\<in> set (ll ! n)\" and \n              rra_ra: \"repc (repc a) = repc a\" and\n              two_nodes_share: \"(\\<forall>no1\\<in>set (ll ! n). \n              ((repc \\<propto> high) no1 = (repc \\<propto> high) a \\<and> \n              (repc \\<propto> low) no1 = (repc \\<propto> low) a) = (repc a = repc no1))\"\n              using [[simp_depth_limit=3]]\n              by simp\n            from wf_ll ra_in_llbn  nsll have var_repc_a_n: \"var (repc a) = n\" \n              by (auto simp add: wf_ll_def length_ll_eq)\n            show ?thesis\n            proof (auto simp add: isomorphic_dags_eq_def)\n              fix bdt1\n              assume bdt_t1: \"bdt t1 var = Some bdt1\"\n              assume bdt_t2: \"bdt t2 var = Some bdt1\"\n              show \"t1 = t2\"\n              proof (cases t1)\n                case Tip\n                with bdt_t1 show ?thesis\n                  by simp\n              next\n                case (Node lt1 p1 rt1)\n                note t1_Node=this\n                with Dag_q_Nodes_n have \"p1=(repc q)\"\n                  by simp\n                with t2_Node bdt_t1 bdt_t2 t1_Node have \"var (repc q) = var (repc a)\"\n                  apply -\n                  apply (rule same_bdt_var)\n                  apply auto\n                  done\n                with var_repc_q_n var_repc_a_n show ?thesis\n                  by simp\n              qed\n            qed\n          qed }\n        note mixed_Dags_case = this\n        from repbc_dags_eq isomorphic_dags_eq \n        have dags_shared: \n          \"\\<forall>t1 t2. t1 \\<in> Dags (repc ` Nodes (Suc n) ll)(repc \\<propto> low)(repc \\<propto> high)\\<and>\n          t2 \\<in> Dags (repc ` Nodes (Suc n) ll) (repc \\<propto> low) (repc \\<propto> high) \n          \\<longrightarrow> isomorphic_dags_eq t1 t2 var\"\n          apply -\n          apply (rule Dags_Nodes_cases)\n          apply (rule isomorphic_dags_eq_sym)\n        proof -\n          fix t1 t2\n          assume t1_in_Dagsn: \n            \"t1 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume t2_in_Dagsn: \n            \"t2 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume isomorphic_dags_eq_asm: \n            \"\\<forall>t1 t2. t1 \\<in> Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high) \\<and>\n            t2 \\<in> Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high) \n            \\<longrightarrow> isomorphic_dags_eq t1 t2 var\"\n          assume repb_repc_Dags: \n            \"Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high) = \n            Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high)\"\n          with t1_in_Dagsn t2_in_Dagsn isomorphic_dags_eq_asm \n          show \"isomorphic_dags_eq t1 t2 var\" by simp\n        next\n          fix t1 t2\n          assume t1_in_DagsNodesn: \n            \"t1 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume t2_notin_DagsNodesn: \n            \"t2 \\<notin> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume t2_in_DagsNodesSucn: \n            \"t2 \\<in> Dags (repc ` Nodes (Suc n) ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume isomorphic_dags_eq_asm: \n            \"\\<forall>t1 t2. t1 \\<in> Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high) \\<and>\n            t2 \\<in> Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high) \n            \\<longrightarrow> isomorphic_dags_eq t1 t2 var\"\n          assume repbc_Dags: \n            \"Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high) = \n            Dags (repb ` Nodes n ll) (repb \\<propto> low) (repb \\<propto> high)\"\n          from t1_in_DagsNodesn t2_notin_DagsNodesn t2_in_DagsNodesSucn \n            isomorphic_dags_eq_asm repbc_Dags\n          show \"isomorphic_dags_eq t1 t2 var\"\n            apply -\n            apply (rule mixed_Dags_case)\n            apply auto\n            done\n        next\n          fix t1 t2\n          assume t1_in_DagsNodesSucn: \n            \"t1 \\<in> Dags (repc ` Nodes (Suc n) ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume t1_notin_DagsNodesn: \n            \"t1 \\<notin> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume t2_in_DagsNodesSucn: \n            \"t2 \\<in> Dags (repc ` Nodes (Suc n) ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          assume t2_notin_DagsNodesn: \n            \"t2 \\<notin> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n          \n          \n            (* ab hier gehts um t1 *)\n          from t1_in_DagsNodesSucn have ord_t1: \"ordered t1 var\"\n          proof (elim Dags.cases)\n            fix p t\n            assume t_in_repcNodes: \"set_of t \\<subseteq> repc ` Nodes (Suc n) ll\"\n            assume t_nTip: \" t \\<noteq> Tip\"\n            assume t2t: \"t1 = t\"\n            assume t_dag: \"Dag p (repc \\<propto> low) (repc \\<propto> high) t\"\n            from t_in_repcNodes \n            have x_in_repcNodesSucn:  \n              \"\\<forall> x. x \\<in> set_of t \\<longrightarrow> x \\<in> repc ` Nodes (Suc n) ll\" \n              apply -\n              apply auto\n              done\n            from t_nTip t_dag have \"p \\<noteq> Null\"\n              apply -\n              apply (case_tac \"p=Null\")\n              apply auto\n              done\n            with t_nTip t_dag obtain lt rt where t_Node: \"t=Node lt p rt\"\n              by auto\n            then have \"p \\<in> set_of t\"\n              by auto\n            with x_in_repcNodesSucn have \"p \\<in> repc ` Nodes (Suc n) ll\"\n              by simp\n            then obtain a where \n              repca_p: \"p=repc a\" and a_in_NodesSucn: \"a \\<in> Nodes (Suc n) ll\"\n              by auto\n            with repca_p while_while_prop t_dag t2t show ?thesis\n              apply -\n              apply (erule_tac x=a in ballE)\n              apply (elim conjE exE)\n              apply (subgoal_tac \"nort = t\") \n              prefer 2\n              apply (simp add: Dag_unique)\n              apply auto\n              done\n          qed\n          from while_while_prop \n          have while_prop_part: \"\\<forall>no \\<in> Nodes (Suc n) ll. \n            var (repc no) <= var no\"\n            by auto\n          from while_while_prop have rep_rep_nort: \n            \"\\<forall>no\\<in>Nodes (n + 1) ll. \n               (\\<exists>nort. Dag (repc no) (repc \\<propto> low) (repc \\<propto> high) nort \\<and> \n               (\\<forall>no\\<in>set_of nort. repc no = no))\"\n            by auto\n          from repcNodes_in_Nodes null_notin_Nodes_Suc_n \n          have \"\\<forall> no \\<in> Nodes (n+1) ll. repc no \\<noteq> Null\"\n            by auto\n          with rep_rep_nort \n          have rep_rep_no:  \"\\<forall>no \\<in> Nodes (n+1) ll. repc (repc no) = (repc no)\"\n            apply -\n            apply (rule ballI)\n            apply (erule_tac x=no in ballE)\n            prefer 2\n            apply simp\n            apply (erule_tac x=no in ballE)\n            apply (erule exE)\n            apply (subgoal_tac \"repc no \\<in> set_of nort\")\n            apply (elim conjE)\n            apply (erule_tac x=\"repc no\" in ballE)\n            apply simp\n            apply simp\n            apply (simp)\n            apply (elim conjE)\n            apply (thin_tac \"\\<forall>no\\<in>set_of nort. repc no = no\")\n            apply auto\n            done\n          with t1_in_DagsNodesSucn t1_notin_DagsNodesn ord_t1 while_prop_part wf_ll \n            nsll  repcNodes_in_Nodes obtain a1 where\n            t1_repc_dag: \"Dag (repc a1) (repc \\<propto> low) (repc \\<propto> high) t1\" and\n            a1_in_lln: \"a1 \\<in> set (ll ! n)\"\n            apply -\n            apply (drule restrict_root_Node)\n            apply (auto simp add: length_ll_eq)\n            done\n          with wf_ll nsll  have a1_in_pret: \"a1 \\<in> set_of pret\" \n            by (simp add: wf_ll_def length_ll_eq)\n          from wf_ll nsll  a1_in_lln have vara1_n: \"var a1 = n\" \n            by (simp add: wf_ll_def length_ll_eq)\n          from a1_in_lln rep_prop  obtain\n            repa1_nNull: \" repc a1 \\<noteq> Null\" and\n            repa1_reduce: \"(repc \\<propto> low) a1 = (repc \\<propto> high) a1 \\<and> low a1 \\<noteq> Null \n            \\<longrightarrow> repc a1 = (repc \\<propto> high) a1\" and\n            repa1_share: \"((repc \\<propto> low) a1 = (repc \\<propto> high) a1 \\<longrightarrow> low a1 = Null) \n            \\<longrightarrow> repc a1 \\<in> set (ll ! n) \\<and> repc (repc a1) = repc a1 \\<and> \n            (\\<forall>no1\\<in>set (ll ! n). ((repc \\<propto> high) no1 = (repc \\<propto> high) a1 \\<and> \n            (repc \\<propto> low) no1 = (repc \\<propto> low) a1) = (repc a1 = repc no1))\"\n            using [[simp_depth_limit=4]]\n            by auto\n          from t1_repc_dag a1_in_lln repa1_nNull obtain lt1 rt1 where \n            t1_Node: \"t1 = (Node lt1 (repc a1) rt1)\"\n            by auto\n\n\n\n              (* ab hier gehts um t2 *)\n          from t2_in_DagsNodesSucn have ord_t2: \"ordered t2 var\"\n          proof (elim Dags.cases)\n            fix p t\n            assume t_in_repcNodes: \"set_of t \\<subseteq> repc ` Nodes (Suc n) ll\"\n            assume t_nTip: \" t \\<noteq> Tip\"\n            assume t2t: \"t2 = t\"\n            assume t_dag: \"Dag p (repc \\<propto> low) (repc \\<propto> high) t\"\n            from t_in_repcNodes \n            have x_in_repcNodesSucn:  \n              \"\\<forall> x. x \\<in> set_of t \\<longrightarrow> x \\<in> repc ` Nodes (Suc n) ll\" \n              apply -\n              apply auto\n              done\n            from t_nTip t_dag have \"p \\<noteq> Null\"\n              apply -\n              apply (case_tac \"p=Null\")\n              apply auto\n              done\n            with t_nTip t_dag obtain lt rt where t_Node: \"t=Node lt p rt\"\n              by auto\n            then have \"p \\<in> set_of t\"\n              by auto\n            with x_in_repcNodesSucn have \"p \\<in> repc ` Nodes (Suc n) ll\"\n              by simp\n            then obtain a where \n              repca_p: \"p=repc a\" and a_in_NodesSucn: \"a \\<in> Nodes (Suc n) ll\"\n              by auto\n            with repca_p while_while_prop t_dag t2t show ?thesis\n              apply -\n              apply (erule_tac x=a in ballE)\n              apply (elim conjE exE)\n              apply (subgoal_tac \"nort = t\") \n              prefer 2\n              apply (simp add: Dag_unique)\n              apply auto\n              done\n          qed\n          from rep_rep_no t2_in_DagsNodesSucn t2_notin_DagsNodesn ord_t2 while_prop_part wf_ll \n            nsll  repcNodes_in_Nodes obtain a2 where\n            t2_repc_dag: \"Dag (repc a2) (repc \\<propto> low) (repc \\<propto> high) t2\" and\n            a2_in_lln: \"a2 \\<in> set (ll ! n)\"\n            apply -\n            apply (drule restrict_root_Node)\n            apply (auto simp add: length_ll_eq)\n            done\n          with wf_ll nsll  have a2_in_pret: \"a2 \\<in> set_of pret\" \n            by (simp add: wf_ll_def length_ll_eq)\n          from wf_ll nsll  a2_in_lln have vara2_n: \"var a2 = n\" \n            by (simp add: wf_ll_def length_ll_eq)\n          from a2_in_lln rep_prop  obtain\n            repa2_nNull: \" repc a2 \\<noteq> Null\" and\n            repa2_reduce: \"(repc \\<propto> low) a2 = (repc \\<propto> high) a2 \\<and> low a2 \\<noteq> Null \n            \\<longrightarrow> repc a2 = (repc \\<propto> high) a2\" and\n            repa2_share: \"((repc \\<propto> low) a2 = (repc \\<propto> high) a2 \\<longrightarrow> low a2 = Null) \n            \\<longrightarrow> repc a2 \\<in> set (ll ! n) \\<and> repc (repc a2) = repc a2 \\<and> \n            (\\<forall>no1\\<in>set (ll ! n). ((repc \\<propto> high) no1 = (repc \\<propto> high) a2 \\<and> \n            (repc \\<propto> low) no1 = (repc \\<propto> low) a2) = (repc a2 = repc no1))\"\n            using [[simp_depth_limit = 4]]\n            by auto\n          from t2_repc_dag a2_in_lln repa2_nNull obtain lt2 rt2 where \n            t2_Node: \"t2 = (Node lt2 (repc a2) rt2)\"\n            by auto\n          show \"isomorphic_dags_eq t1 t2 var\"\n          proof (cases \"(repc \\<propto> low) a1 = (repc \\<propto> high) a1 \\<and> low a1 \\<noteq> Null\")\n            case True\n            note t1_red_cond=this              \n            with t1_red_cond have t1_red_case: \"(repc \\<propto> low) a1 = (repc \\<propto> high) a1\"\n              by simp\n            from t1_red_cond have lowa1_nNull: \"low a1 \\<noteq> Null\"\n              by simp\n            with pret_dag prebdt_pret a1_in_pret have higha1_nNull: \"high a1 \\<noteq> Null\" \n              apply -\n              apply (drule balanced_bdt)\n              apply auto\n              done\n            from pret_dag ord_pret a1_in_pret lowa1_nNull higha1_nNull \n            have var_children_smaller_a1: \"var (low a1) < var a1 \\<and> var (high a1) < var a1\"\n              apply -\n              apply (rule var_ordered_children)\n              apply auto\n              done\n            from pret_dag a1_in_pret have a1_nNull: \"a1 \\<noteq> Null\" \n              apply -\n              apply (rule set_of_nn [rule_format])\n              apply auto\n              done\n            with a1_in_pret higha1_nNull pret_dag have \"high a1 \\<in> set_of pret\" \n              apply -\n              apply (drule subelem_set_of_high)\n              apply auto\n              done\n            with wf_ll have \"high a1 \\<in> set (ll ! (var (high a1)))\" \n              by (simp add: wf_ll_def)\n            with a1_in_lln t1_repc_dag var_children_smaller_a1 vara1_n \n            have \"\\<exists>k<n. (high a1) \\<in> set (ll ! k)\"\n              by auto\n            then have higha1_in_Nodesn: \"(high a1) \\<in> Nodes n ll\"\n              by (simp add: Nodes_def)\n            then have rhigha1_in_rNodesn: \"repc (high a1) \\<in> repc ` Nodes n ll\"\n              by simp\n            from higha1_in_Nodesn normalize_prop obtain rt1 where \n              rt1_dag:  \"Dag (repb (high a1)) (repb \\<propto> low) (repb \\<propto> high) rt1\" and\n              rt1_in_repbNort: \"set_of rt1 \\<subseteq> repb `Nodes n ll\"\n              apply -\n              apply (erule_tac x=\"high a1\" in ballE)\n              apply auto\n              done\n            from rt1_in_repbNort repbNodes_repcNodes \n            have rt1_in_repcNodesn: \"set_of rt1 \\<subseteq> repc `Nodes n ll\"\n              by blast\n            from rt1_dag higha1_in_Nodesn \n            have repcrt1_dag: \"Dag (repc (high a1)) (repc \\<propto> low) (repc \\<propto> high) rt1\"\n              apply -\n              apply (drule Nodes_repbc_Dags_eq [rule_format])\n              apply auto\n              done\n            have rt1_nTip: \"rt1 \\<noteq> Tip\"\n            proof -\n              have \"repc (high a1) \\<noteq> Null\"\n              proof -\n                note rhigha1_in_rNodesn\n                also have \"repc `Nodes n ll \\<subseteq> repc `Nodes (Suc n) ll\"\n                  using Nodes_subset \n                  by blast\n                also have \"\\<dots> \\<subseteq> Nodes (Suc n) ll\"\n                  using repcNodes_in_Nodes\n                  by simp\n                finally show ?thesis\n                  using null_notin_Nodes_Suc_n\n                  by auto\n              qed\n              with repcrt1_dag show ?thesis by auto\n            qed\n            from repa1_reduce lowa1_nNull  higha1_nNull  t1_red_case \n            have repc_a1_def: \"repc a1 = repc (high a1)\" \n              by (simp add: null_comp_def)\n            with rt1_in_repcNodesn repcrt1_dag rhigha1_in_rNodesn a1_in_lln \n              t1_repc_dag repc_a1_def  rt1_nTip \n            have t1_in_Dags_Nodesn: \n              \"t1 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n              apply -\n              apply (rule DagsI)\n              apply simp\n              apply (subgoal_tac \"t1=rt1\")\n              apply (auto simp add: Dag_unique)\n              done\n            show ?thesis\n            proof (cases \"(repc \\<propto> low) a2 = (repc \\<propto> high) a2 \\<and> low a2 \\<noteq> Null\")\n              case True\n              note t2_red_cond=this              \n              with t2_red_cond have t2_red_case: \"(repc \\<propto> low) a2 = (repc \\<propto> high) a2\"\n                by simp\n              from t2_red_cond have lowa2_nNull: \"low a2 \\<noteq> Null\"\n                by simp\n              with pret_dag prebdt_pret a2_in_pret have higha2_nNull: \"high a2 \\<noteq> Null\" \n                apply -\n                apply (drule balanced_bdt)\n                apply auto\n                done\n              from pret_dag ord_pret a2_in_pret lowa2_nNull higha2_nNull \n              have var_children_smaller_a2: \n                \"var (low a2) < var a2 \\<and> var (high a2) < var a2\"\n                apply -\n                apply (rule var_ordered_children)\n                apply auto\n                done\n              from pret_dag a2_in_pret have a2_nNull: \"a2 \\<noteq> Null\" \n                apply -\n                apply (rule set_of_nn [rule_format])\n                apply auto\n                done\n              with a2_in_pret higha2_nNull pret_dag have \"high a2 \\<in> set_of pret\" \n                apply -\n                apply (drule subelem_set_of_high)\n                apply auto\n                done\n              with wf_ll have \"high a2 \\<in> set (ll ! (var (high a2)))\" \n                by (simp add: wf_ll_def)\n              with a2_in_lln t2_repc_dag var_children_smaller_a2 vara2_n \n              have \"\\<exists> k<n. (high a2) \\<in> set (ll ! k)\"\n                by auto\n              then have higha2_in_Nodesn: \"(high a2) \\<in> Nodes n ll\"\n                by (simp add: Nodes_def)\n              then have rhigha2_in_rNodesn: \"repc (high a2) \\<in> repc ` Nodes n ll\"\n                by simp\n              from higha2_in_Nodesn normalize_prop obtain rt2 where \n                rt2_dag:  \"Dag (repb (high a2)) (repb \\<propto> low) (repb \\<propto> high) rt2\" and\n                rt2_in_repbNort: \"set_of rt2 \\<subseteq> repb `Nodes n ll\"\n                apply -\n                apply (erule_tac x=\"high a2\" in ballE)\n                apply auto\n                done\n              from rt2_in_repbNort repbNodes_repcNodes \n              have rt2_in_repcNodesn: \"set_of rt2 \\<subseteq> repc `Nodes n ll\"\n                by blast\n              from rt2_dag higha2_in_Nodesn \n              have repcrt2_dag: \"Dag (repc (high a2)) (repc \\<propto> low) (repc \\<propto> high) rt2\"\n                apply -\n                apply (drule Nodes_repbc_Dags_eq [rule_format])\n                apply auto\n                done\n              have rt2_nTip: \"rt2 \\<noteq> Tip\"\n              proof -\n                have \"repc (high a2) \\<noteq> Null\"\n                proof -\n                  note rhigha2_in_rNodesn\n                  also have \"repc `Nodes n ll \\<subseteq> repc `Nodes (Suc n) ll\"\n                    using Nodes_subset \n                    by blast\n                  also have \"\\<dots> \\<subseteq> Nodes (Suc n) ll\"\n                    using repcNodes_in_Nodes\n                    by simp\n                  finally show ?thesis\n                    using null_notin_Nodes_Suc_n\n                    by auto\n                qed\n                with repcrt2_dag show ?thesis by auto\n              qed\n              from repa2_reduce lowa2_nNull  higha2_nNull  t2_red_case \n              have repc_a2_def: \"repc a2 = repc (high a2)\" \n                by (simp add: null_comp_def)\n              with rt2_in_repcNodesn repcrt2_dag rhigha2_in_rNodesn a2_in_lln \n                t2_repc_dag repc_a2_def  rt2_nTip \n              have t2_in_Dags_Nodesn: \n                \"t2 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n                apply -\n                apply (rule DagsI)\n                apply simp\n                apply (subgoal_tac \"t2=rt2\")\n                apply (auto simp add: Dag_unique)\n                done\n              from isomorphic_dags_eq t1_in_Dags_Nodesn t2_in_Dags_Nodesn repbc_dags_eq \n              show ?thesis\n                by auto\n            next\n              assume t2_share_cond: \n                \"\\<not> ((repc \\<propto> low) a2 = (repc \\<propto> high) a2 \\<and> low a2 \\<noteq> Null)\"\n              from t1_in_Dags_Nodesn t2_notin_DagsNodesn t2_in_DagsNodesSucn \n                isomorphic_dags_eq repbc_dags_eq\n              show ?thesis\n                apply -\n                apply (rule mixed_Dags_case)\n                apply auto\n                done\n            qed\n          next\n            assume t1_share_cond: \n              \"\\<not>((repc \\<propto> low) a1 = (repc \\<propto> high) a1 \\<and> low a1 \\<noteq> Null)\"\n            with repa1_share obtain\n              repca1_in_llbn: \"repc a1 \\<in> set (ll ! n)\" and \n              reprepa1: \"repc (repc a1) = repc a1\" and\n              twonodes_llbn_a1: \n              \"(\\<forall>no1\\<in>set (ll ! n). ((repc \\<propto> high) no1 = (repc \\<propto> high) a1 \\<and> \n              (repc \\<propto> low) no1 = (repc \\<propto> low) a1) = (repc a1 = repc no1))\"\n              using [[simp_depth_limit=2]]\n              by auto\n            show ?thesis\n            proof (cases \"(repc \\<propto> low) a2 = (repc \\<propto> high) a2 \\<and> low a2 \\<noteq> Null\")\n              case True\n              note t2_red_cond=this              \n              with t2_red_cond have t2_red_case: \"(repc \\<propto> low) a2 = (repc \\<propto> high) a2\"\n                by simp\n              from t2_red_cond have lowa2_nNull: \"low a2 \\<noteq> Null\"\n                by simp\n              with pret_dag prebdt_pret a2_in_pret have higha2_nNull: \"high a2 \\<noteq> Null\" \n                apply -\n                apply (drule balanced_bdt)\n                apply auto\n                done\n              from pret_dag ord_pret a2_in_pret lowa2_nNull higha2_nNull \n              have var_children_smaller_a2: \n                \"var (low a2) < var a2 \\<and> var (high a2) < var a2\"\n                apply -\n                apply (rule var_ordered_children)\n                apply auto\n                done\n              from pret_dag a2_in_pret have a2_nNull: \"a2 \\<noteq> Null\" \n                apply -\n                apply (rule set_of_nn [rule_format])\n                apply auto\n                done\n              with a2_in_pret higha2_nNull pret_dag have \"high a2 \\<in> set_of pret\" \n                apply -\n                apply (drule subelem_set_of_high)\n                apply auto\n                done\n              with wf_ll \n              have \"high a2 \\<in> set (ll ! (var (high a2)))\" \n                by (simp add: wf_ll_def)\n              with a2_in_lln t2_repc_dag var_children_smaller_a2 vara2_n \n              have \"\\<exists> k<n. (high a2) \\<in> set (ll ! k)\"\n                by auto\n              then have higha2_in_Nodesn: \"(high a2) \\<in> Nodes n ll\"\n                by (simp add: Nodes_def)\n              then have rhigha2_in_rNodesn: \"repc (high a2) \\<in> repc ` Nodes n ll\"\n                by simp\n              from higha2_in_Nodesn normalize_prop obtain rt2 where \n                rt2_dag:  \"Dag (repb (high a2)) (repb \\<propto> low) (repb \\<propto> high) rt2\" and\n                rt2_in_repbNort: \"set_of rt2 \\<subseteq> repb `Nodes n ll\"\n                apply -\n                apply (erule_tac x=\"high a2\" in ballE)\n                apply auto\n                done\n              from rt2_in_repbNort repbNodes_repcNodes \n              have rt2_in_repcNodesn: \"set_of rt2 \\<subseteq> repc `Nodes n ll\"\n                by blast\n              from rt2_dag higha2_in_Nodesn \n              have repcrt2_dag: \"Dag (repc (high a2)) (repc \\<propto> low) (repc \\<propto> high) rt2\"\n                apply -\n                apply (drule Nodes_repbc_Dags_eq [rule_format])\n                apply auto\n                done\n              have rt2_nTip: \"rt2 \\<noteq> Tip\"\n              proof -\n                have \"repc (high a2) \\<noteq> Null\"\n                proof -\n                  note rhigha2_in_rNodesn\n                  also have \"repc `Nodes n ll \\<subseteq> repc `Nodes (Suc n) ll\"\n                    using Nodes_subset \n                    by blast\n                  also have \"\\<dots> \\<subseteq> Nodes (Suc n) ll\"\n                    using repcNodes_in_Nodes\n                    by simp\n                  finally show ?thesis\n                    using null_notin_Nodes_Suc_n\n                    by auto\n                qed\n                with repcrt2_dag show ?thesis by auto\n              qed\n              from repa2_reduce lowa2_nNull  higha2_nNull  t2_red_case \n              have repc_a2_def: \"repc a2 = repc (high a2)\" \n                by (simp add: null_comp_def)\n              with rt2_in_repcNodesn repcrt2_dag rhigha2_in_rNodesn a2_in_lln \n                t2_repc_dag repc_a2_def  rt2_nTip \n              have t2_in_Dags_Nodesn: \n                \"t2 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n                apply -\n                apply (rule DagsI)\n                apply simp\n                apply (subgoal_tac \"t2=rt2\")\n                apply (auto simp add: Dag_unique)\n                done\n              from t2_in_Dags_Nodesn t1_notin_DagsNodesn t1_in_DagsNodesSucn \n                isomorphic_dags_eq repbc_dags_eq \n              have \"isomorphic_dags_eq t2 t1 var\"\n                apply -\n                apply (rule mixed_Dags_case)\n                apply auto\n                done\n              then show ?thesis\n                by (simp add: isomorphic_dags_eq_sym)\n            next\n              assume t2_shared_cond: \n                \"\\<not> ((repc \\<propto> low) a2 = (repc \\<propto> high) a2 \\<and> low a2 \\<noteq> Null)\"\n              with repa2_share obtain\n                repca2_in_llbn: \"repc a2 \\<in> set (ll ! n)\" and \n                reprepa2: \"repc (repc a2) = repc a2\" and\n                twonodes_llbn_a2: \"(\\<forall>no1\\<in>set (ll ! n). \n                ((repc \\<propto> high) no1 = (repc \\<propto> high) a2 \\<and> \n                (repc \\<propto> low) no1 = (repc \\<propto> low) a2) = (repc a2 = repc no1))\"\n                using [[simp_depth_limit=2]]\n                by auto \n              from twonodes_llbn_a2 a1_in_lln  \n              have share_a1_a2: \n                \"((repc \\<propto> high) a1 = (repc \\<propto> high) a2 \\<and> \n                (repc \\<propto> low) a1 = (repc \\<propto> low) a2) = (repc a2 = repc a1)\"\n                by auto\n              from twonodes_llbn_a1 repca1_in_llbn reprepa1   \n              have children_repc_eq_a1: \"(repc \\<propto> high) (repc a1) = (repc \\<propto> high) a1 \\<and> \n                (repc \\<propto> low) (repc a1) = (repc \\<propto> low) a1\"\n                by auto\n              from twonodes_llbn_a2 repca2_in_llbn reprepa2  \n              have children_repc_eq_a2: \"(repc \\<propto> high) (repc a2) = (repc \\<propto> high) a2 \\<and> \n                (repc \\<propto> low) (repc a2) = (repc \\<propto> low) a2\"\n                by auto\n              from  t1_Node t2_Node show ?thesis\n              proof (clarsimp simp add: isomorphic_dags_eq_def)\n                fix bdt1\n                assume t1_bdt: \"bdt (Node lt1 (repc a1) rt1) var = Some bdt1\"\n                assume t2_bdt: \"bdt (Node lt2 (repc a2) rt2) var = Some bdt1\"\n                show \"lt1 = lt2 \\<and> repc a1 = repc a2 \\<and> rt1 = rt2\"\n                proof (cases bdt1)\n                  case Zero\n                  with t1_bdt t1_Node obtain\n                    lt1_Tip: \"lt1 = Tip\" and\n                    rt1_Tip: \"rt1 = Tip\"\n                    by simp\n                  from Zero t2_bdt t2_Node obtain \n                    lt2_Tip: \"lt2 = Tip\" and\n                    rt2_Tip: \"rt2 = Tip\"\n                    by simp\n                  from t1_repc_dag t1_Node lt1_Tip have \"(repc \\<propto> low) (repc a1) = Null\" \n                    by simp\n                  with children_repc_eq_a1  \n                  have repc_low_a1_Null: \"(repc \\<propto> low) a1 = Null\"\n                    by simp\n                  from t1_repc_dag t1_Node rt1_Tip \n                  have \"(repc \\<propto> high) (repc a1) = Null\"\n                    by simp\n                  with children_repc_eq_a1  \n                  have repc_high_a1_Null: \"(repc \\<propto> high) a1 = Null\"\n                    by simp\n                  from t2_repc_dag t2_Node lt2_Tip have \"(repc \\<propto> low) (repc a2) = Null\" \n                    by simp\n                  with children_repc_eq_a2  \n                  have repc_low_a2_Null: \"(repc \\<propto> low) a2 = Null\"\n                    by simp\n                  from t2_repc_dag t2_Node rt2_Tip \n                  have \"(repc \\<propto> high) (repc a2) = Null\"\n                    by simp\n                  with children_repc_eq_a2  \n                  have repc_high_a2_Null: \"(repc \\<propto> high) a2 = Null\"\n                    by simp\n                  with share_a1_a2   repc_low_a1_Null repc_high_a1_Null \n                    repc_low_a2_Null repc_high_a2_Null\n                  have \"repc a2 = repc a1\"\n                    by auto\n                  with lt1_Tip rt1_Tip lt2_Tip rt2_Tip show ?thesis\n                    by auto\n                next\n                  case One\n                  with t1_bdt t1_Node obtain\n                    lt1_Tip: \"lt1 = Tip\" and\n                    rt1_Tip: \"rt1 = Tip\"\n                    by simp\n                  from One t2_bdt t2_Node obtain \n                    lt2_Tip: \"lt2 = Tip\" and\n                    rt2_Tip: \"rt2 = Tip\"\n                    by simp\n                  from t1_repc_dag t1_Node lt1_Tip have \"(repc \\<propto> low) (repc a1) = Null\" \n                    by simp\n                  with children_repc_eq_a1  \n                  have repc_low_a1_Null: \"(repc \\<propto> low) a1 = Null\"\n                    by simp\n                  from t1_repc_dag t1_Node rt1_Tip have \"(repc \\<propto> high) (repc a1) = Null\"\n                    by simp\n                  with children_repc_eq_a1  \n                  have repc_high_a1_Null: \"(repc \\<propto> high) a1 = Null\"\n                    by simp\n                  from t2_repc_dag t2_Node lt2_Tip have \"(repc \\<propto> low) (repc a2) = Null\" \n                    by simp\n                  with children_repc_eq_a2  \n                  have repc_low_a2_Null: \"(repc \\<propto> low) a2 = Null\"\n                    by simp\n                  from t2_repc_dag t2_Node rt2_Tip have \"(repc \\<propto> high) (repc a2) = Null\"\n                    by simp\n                  with children_repc_eq_a2  \n                  have repc_high_a2_Null: \"(repc \\<propto> high) a2 = Null\"\n                    by simp\n                  with share_a1_a2   repc_low_a1_Null repc_high_a1_Null \n                    repc_low_a2_Null repc_high_a2_Null\n                  have \"repc a2 = repc a1\"\n                    by auto\n                  with lt1_Tip rt1_Tip lt2_Tip rt2_Tip show ?thesis\n                    by auto\n                next\n                  case (Bdt_Node lbdt v rbdt)\n                  note bdt_Node_case=this\n                  with t1_bdt t1_Node obtain\n                    lbdt_def_lt1: \"bdt lt1 var = Some lbdt\" and\n                    rbdt_def_rt1: \"bdt rt1 var = Some rbdt\"\n                    by auto\n                  from t2_bdt bdt_Node_case t2_Node obtain\n                    lbdt_def_lt2: \"bdt lt2 var = Some lbdt\" and\n                    rbdt_def_rt2: \"bdt rt2 var = Some rbdt\"\n                    by auto\n                  from lbdt_def_lt1 t1_Node t1_repc_dag children_repc_eq_a1  \n                  have \"(repc \\<propto> low) a1 \\<noteq> Null\"\n                    by auto\n                  then have low_a1_nNull: \"(low a1) \\<noteq> Null\" \n                    by (auto simp: null_comp_def)\n                  from rbdt_def_rt1 t1_Node t1_repc_dag children_repc_eq_a1  \n                  have \"(repc \\<propto> high) a1 \\<noteq> Null\"\n                    by auto\n                  then have high_a1_nNull: \"(high a1) \\<noteq> Null\" \n                    by (auto simp: null_comp_def)\n                  from lbdt_def_lt2 t2_Node t2_repc_dag children_repc_eq_a2  \n                  have \"(repc \\<propto> low) a2 \\<noteq> Null\"\n                    by auto\n                  then have low_a2_nNull: \"(low a2) \\<noteq> Null\" \n                    by (auto simp: null_comp_def)\n                  from rbdt_def_rt2 t2_Node t2_repc_dag children_repc_eq_a2  \n                  have \"(repc \\<propto> high) a2 \\<noteq> Null\"\n                    by auto\n                  then have high_a2_nNull: \"(high a2) \\<noteq> Null\" \n                    by (auto simp: null_comp_def)\n\n                      (*hier gehts um t1*)\n                  from pret_dag ord_pret a1_in_pret low_a1_nNull high_a1_nNull \n                  have var_children_smaller_a1: \n                    \"var (low a1) < var a1 \\<and> var (high a1) < var a1\"\n                    apply -\n                    apply (rule var_ordered_children)\n                    apply auto\n                    done\n                  from pret_dag a1_in_pret have a1_nNull: \"a1 \\<noteq> Null\" \n                    apply -\n                    apply (rule set_of_nn [rule_format])\n                    apply auto\n                    done\n                  \n                      (*hier gehts um rt1 *)\n                  with a1_in_pret high_a1_nNull pret_dag have \"high a1 \\<in> set_of pret\" \n                    apply -\n                    apply (drule subelem_set_of_high)\n                    apply auto\n                    done\n                  with wf_ll \n                  have \"high a1 \\<in> set (ll ! (var (high a1)))\" \n                    by (simp add: wf_ll_def)\n                  with a1_in_lln t1_repc_dag var_children_smaller_a1 vara1_n \n                  have \"\\<exists> k<n. (high a1) \\<in> set (ll ! k)\"\n                    by auto\n                  then have higha1_in_Nodesn: \"(high a1) \\<in> Nodes n ll\"\n                    by (simp add: Nodes_def)\n                  then have rhigha1_in_rNodesn: \n                    \"repc (high a1) \\<in> repc ` Nodes n ll\"\n                    by simp\n                  from higha1_in_Nodesn normalize_prop obtain rt1h where\n                    rt1_dag:  \"Dag (repb (high a1)) (repb \\<propto> low) (repb \\<propto> high) rt1h\" and\n                    rt1_in_repbNort: \"set_of rt1h \\<subseteq> repb `Nodes n ll\"\n                    apply -\n                    apply (erule_tac x=\"high a1\" in ballE)\n                    apply auto\n                    done\n                  from rt1_in_repbNort repbNodes_repcNodes \n                  have rt1_in_repcNodesn: \"set_of rt1h \\<subseteq> repc `Nodes n ll\"\n                    by blast\n                  from rt1_dag higha1_in_Nodesn \n                  have repcrt1_dag: \n                    \"Dag (repc (high a1)) (repc \\<propto> low) (repc \\<propto> high) rt1h\"\n                    apply -\n                    apply (drule Nodes_repbc_Dags_eq [rule_format])\n                    apply auto\n                    done\n                  from t1_Node t1_repc_dag high_a1_nNull children_repc_eq_a1 \n                  have \"Dag (repc (high a1)) (repc \\<propto> low) (repc \\<propto> high) rt1\"\n                    by (auto simp add: null_comp_def)\n                  with repcrt1_dag have rt1h_rt1: \"rt1h = rt1\" by (simp add: Dag_unique)\n                  have rt1_nTip: \"rt1 \\<noteq> Tip\"\n                  proof -\n                    have \"repc (high a1) \\<noteq> Null\"\n                    proof -\n                      note rhigha1_in_rNodesn\n                      also have \n                        \"repc `Nodes n ll \\<subseteq> repc `Nodes (Suc n) ll\"\n                        using Nodes_subset \n                        by blast\n                      also have \"\\<dots> \\<subseteq> Nodes (Suc n) ll\"\n                        using repcNodes_in_Nodes\n                        by simp\n                      finally show ?thesis\n                        using null_notin_Nodes_Suc_n\n                        by auto\n                    qed\n                    with repcrt1_dag rt1h_rt1 show ?thesis by auto\n                  qed\n                  with rt1_in_repcNodesn repcrt1_dag rhigha1_in_rNodesn a1_in_lln \n                    t1_repc_dag  rt1h_rt1 \n                  have rt1_in_Dags_Nodesn: \n                    \"rt1 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n                    apply -\n                    apply (rule DagsI)\n                    apply auto\n                    done \n\n                  \n                      (*hier gehts um lt1 *)\n                  from a1_nNull a1_in_pret low_a1_nNull pret_dag \n                  have \"low a1 \\<in> set_of pret\"\n                    apply -\n                    apply (drule subelem_set_of_low)\n                    apply auto\n                    done\n                  with wf_ll have \n                    \"low a1 \\<in> set (ll ! (var (low a1)))\" by (simp add: wf_ll_def)\n                  with a1_in_lln t1_repc_dag var_children_smaller_a1 vara1_n \n                  have \"\\<exists> k<n. (low a1) \\<in> set (ll ! k)\"\n                    by auto\n                  then have lowa1_in_Nodesn: \"(low a1) \\<in> Nodes n ll\"\n                    by (simp add: Nodes_def)\n                  then have rlowa1_in_rNodesn: \"repc (low a1) \\<in> repc ` Nodes n ll\"\n                    by simp\n                  from lowa1_in_Nodesn normalize_prop obtain lt1h where\n                    lt1_dag:  \"Dag (repb (low a1)) (repb \\<propto> low) (repb \\<propto> high) lt1h\" and\n                    lt1_in_repbNort: \"set_of lt1h \\<subseteq> repb `Nodes n ll\"\n                    apply -\n                    apply (erule_tac x=\"low a1\" in ballE)\n                    apply auto\n                    done\n                  from lt1_in_repbNort repbNodes_repcNodes \n                  have lt1_in_repcNodesn: \"set_of lt1h \\<subseteq> repc `Nodes n ll\"\n                    by blast\n                  from lt1_dag lowa1_in_Nodesn \n                  have repclt1_dag: \"Dag (repc (low a1)) (repc \\<propto> low) (repc \\<propto> high) lt1h\"\n                    apply -\n                    apply (drule Nodes_repbc_Dags_eq [rule_format])\n                    apply auto\n                    done\n                  from t1_Node t1_repc_dag low_a1_nNull children_repc_eq_a1 \n                  have \"Dag (repc (low a1)) (repc \\<propto> low) (repc \\<propto> high) lt1\"\n                    by (auto simp add: null_comp_def)\n                  with repclt1_dag have lt1h_lt1: \"lt1h = lt1\" by (simp add: Dag_unique)\n                  have lt1_nTip: \"lt1 \\<noteq> Tip\"\n                  proof -\n                    have \"repc (low a1) \\<noteq> Null\"\n                    proof -\n                      note rlowa1_in_rNodesn\n                      also have \n                        \"repc `Nodes n ll \\<subseteq> repc `Nodes (Suc n) ll\"\n                        using Nodes_subset \n                        by blast\n                      also have \"\\<dots> \\<subseteq> Nodes (Suc n) ll\"\n                        using repcNodes_in_Nodes\n                        by simp\n                      finally show ?thesis\n                        using null_notin_Nodes_Suc_n\n                        by auto\n                    qed\n                    with repclt1_dag lt1h_lt1 show ?thesis by auto\n                  qed\n                  with lt1_in_repcNodesn repclt1_dag rlowa1_in_rNodesn a1_in_lln \n                    t1_repc_dag  lt1h_lt1 \n                  have lt1_in_Dags_Nodesn: \n                    \"lt1 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n                    apply -\n                    apply (rule DagsI)\n                    apply auto\n                    done \n                  \n                  \n                      (*hier gehts um t2*)\n                  from pret_dag ord_pret a2_in_pret low_a2_nNull high_a2_nNull \n                  have var_children_smaller_a2: \n                    \"var (low a2) < var a2 \\<and> var (high a2) < var a2\"\n                    apply -\n                    apply (rule var_ordered_children)\n                    apply auto\n                    done\n                  from pret_dag a2_in_pret have a2_nNull: \"a2 \\<noteq> Null\" \n                    apply -\n                    apply (rule set_of_nn [rule_format])\n                    apply auto\n                    done\n                  \n                      (*hier gehts um rt1 *)\n                  with a2_in_pret high_a2_nNull pret_dag have \"high a2 \\<in> set_of pret\" \n                    apply -\n                    apply (drule subelem_set_of_high)\n                    apply auto\n                    done\n                  with wf_ll have \"high a2 \\<in> set (ll ! (var (high a2)))\" \n                    by (simp add: wf_ll_def)\n                  with a2_in_lln t2_repc_dag var_children_smaller_a2 vara2_n \n                  have \"\\<exists> k<n. (high a2) \\<in> set (ll ! k)\"\n                    by auto\n                  then have higha2_in_Nodesn: \"(high a2) \\<in> Nodes n ll\"\n                    by (simp add: Nodes_def)\n                  then have rhigha2_in_rNodesn: \n                    \"repc (high a2) \\<in> repc ` Nodes n ll\"\n                    by simp\n                  from higha2_in_Nodesn normalize_prop obtain rt2h where\n                    rt2_dag:  \"Dag (repb (high a2)) (repb \\<propto> low) (repb \\<propto> high) rt2h\" and\n                    rt2_in_repbNort: \"set_of rt2h \\<subseteq> repb `Nodes n ll\"\n                    apply -\n                    apply (erule_tac x=\"high a2\" in ballE)\n                    apply auto\n                    done\n                  from rt2_in_repbNort repbNodes_repcNodes \n                  have rt2_in_repcNodesn: \"set_of rt2h \\<subseteq> repc `Nodes n ll\"\n                    by blast\n                  from rt2_dag higha2_in_Nodesn \n                  have repcrt2_dag: \n                    \"Dag (repc (high a2)) (repc \\<propto> low) (repc \\<propto> high) rt2h\"\n                    apply -\n                    apply (drule Nodes_repbc_Dags_eq [rule_format])\n                    apply auto\n                    done\n                  from t2_Node t2_repc_dag high_a2_nNull children_repc_eq_a2 \n                  have \"Dag (repc (high a2)) (repc \\<propto> low) (repc \\<propto> high) rt2\"\n                    by (auto simp add: null_comp_def)\n                  with repcrt2_dag have rt2h_rt2: \"rt2h = rt2\" by (simp add: Dag_unique)\n                  have rt2_nTip: \"rt2 \\<noteq> Tip\"\n                  proof -\n                    have \"repc (high a2) \\<noteq> Null\"\n                    proof -\n                      note rhigha2_in_rNodesn\n                      also have \n                        \"repc `Nodes n ll \\<subseteq> repc `Nodes (Suc n) ll\"\n                        using Nodes_subset \n                        by blast\n                      also have \"\\<dots> \\<subseteq> Nodes (Suc n) ll\"\n                        using repcNodes_in_Nodes\n                        by simp\n                      finally show ?thesis\n                        using null_notin_Nodes_Suc_n\n                        by auto\n                    qed\n                    with repcrt2_dag rt2h_rt2 show ?thesis by auto\n                  qed\n                  with rt2_in_repcNodesn repcrt2_dag rhigha2_in_rNodesn a2_in_lln \n                    t2_repc_dag  rt2h_rt2 \n                  have rt2_in_Dags_Nodesn: \n                    \"rt2 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n                    apply -\n                    apply (rule DagsI)\n                    apply auto\n                    done \n\n                  \n                      (*hier gehts um lt2 *)\n                  from a2_nNull a2_in_pret low_a2_nNull pret_dag \n                  have \"low a2 \\<in> set_of pret\"\n                    apply -\n                    apply (drule subelem_set_of_low)\n                    apply auto\n                    done\n                  with wf_ll have \"low a2 \\<in> set (ll ! (var (low a2)))\" \n                    by (simp add: wf_ll_def)\n                  with a2_in_lln t2_repc_dag var_children_smaller_a2 vara2_n \n                  have \"\\<exists> k<n. (low a2) \\<in> set (ll ! k)\"\n                    by auto\n                  then have lowa2_in_Nodesn: \"(low a2) \\<in> Nodes n ll\"\n                    by (simp add: Nodes_def)\n                  then have rlowa2_in_rNodesn: \"repc (low a2) \\<in> repc ` Nodes n ll\"\n                    by simp\n                  from lowa2_in_Nodesn normalize_prop obtain lt2h where\n                    lt2_dag:  \"Dag (repb (low a2)) (repb \\<propto> low) (repb \\<propto> high) lt2h\" and\n                    lt2_in_repbNort: \"set_of lt2h \\<subseteq> repb `Nodes n ll\"\n                    apply -\n                    apply (erule_tac x=\"low a2\" in ballE)\n                    apply auto\n                    done\n                  from lt2_in_repbNort repbNodes_repcNodes \n                  have lt2_in_repcNodesn: \"set_of lt2h \\<subseteq> repc `Nodes n ll\"\n                    by blast\n                  from lt2_dag lowa2_in_Nodesn \n                  have repclt2_dag: \"Dag (repc (low a2)) (repc \\<propto> low) (repc \\<propto> high) lt2h\"\n                    apply -\n                    apply (drule Nodes_repbc_Dags_eq [rule_format])\n                    apply auto\n                    done\n                  from t2_Node t2_repc_dag low_a2_nNull children_repc_eq_a2 \n                  have \"Dag (repc (low a2)) (repc \\<propto> low) (repc \\<propto> high) lt2\"\n                    by (auto simp add: null_comp_def)\n                  with repclt2_dag have lt2h_lt2: \"lt2h = lt2\" by (simp add: Dag_unique)\n                  have lt2_nTip: \"lt2 \\<noteq> Tip\"\n                  proof -\n                    have \"repc (low a2) \\<noteq> Null\"\n                    proof -\n                      note rlowa2_in_rNodesn\n                      also have \n                        \"repc `Nodes n ll \\<subseteq> repc `Nodes (Suc n) ll\"\n                        using Nodes_subset \n                        by blast\n                      also have \"\\<dots> \\<subseteq> Nodes (Suc n) ll\"\n                        using repcNodes_in_Nodes\n                        by simp\n                      finally show ?thesis\n                        using null_notin_Nodes_Suc_n\n                        by auto\n                    qed\n                    with repclt2_dag lt2h_lt2 show ?thesis by auto\n                  qed\n                  with lt2_in_repcNodesn repclt2_dag rlowa2_in_rNodesn a2_in_lln \n                    t2_repc_dag  lt2h_lt2 \n                  have lt2_in_Dags_Nodesn: \n                    \"lt2 \\<in> Dags (repc ` Nodes n ll) (repc \\<propto> low) (repc \\<propto> high)\"\n                    apply -\n                    apply (rule DagsI)\n                    apply auto\n                    done \n                  \n                  \n                  from isomorphic_dags_eq lt1_in_Dags_Nodesn lt2_in_Dags_Nodesn repbc_dags_eq \n                  have shared_lt1_lt2: \"isomorphic_dags_eq lt1 lt2 var\"\n                    by auto\n                  from isomorphic_dags_eq rt1_in_Dags_Nodesn rt2_in_Dags_Nodesn repbc_dags_eq \n                  have shared_rt1_rt2: \"isomorphic_dags_eq rt1 rt2 var\"\n                    by auto\n                  \n                  from shared_lt1_lt2 lbdt_def_lt1 lbdt_def_lt2 have lt1_lt2: \"lt1 = lt2\"\n                    by (auto simp add: isomorphic_dags_eq_def)\n                  then have root_lt1_lt2: \"root lt1 = root lt2\"\n                    by auto\n                  from lt1_nTip t1_repc_dag t1_Node have \"(repc \\<propto> low) (repc a1) \\<noteq> Null\"\n                    by auto\n                  with lt1_nTip t1_repc_dag t1_Node obtain llt1 lt1p rlt1 where \n                    lt1_Node: \"lt1 = Node llt1 lt1p rlt1\"\n                    by auto\n                  with t1_repc_dag t1_Node children_repc_eq_a1 lt1_nTip \n                  have root_lt1: \"root lt1 = (repc \\<propto> low) a1\"\n                    by auto\n                  from lt2_nTip t2_repc_dag t2_Node have \"(repc \\<propto> low) (repc a2) \\<noteq> Null\"\n                    by auto\n                  with lt2_nTip t2_repc_dag t2_Node obtain llt2 lt2p rlt2 where \n                    lt2_Node: \"lt2 = Node llt2 lt2p rlt2\"\n                    by auto\n                  with t2_repc_dag t2_Node children_repc_eq_a2 lt2_nTip \n                  have root_lt2: \"root lt2 = (repc \\<propto> low) a2\"\n                    by auto\n                  from root_lt1_lt2 root_lt2 root_lt1 \n                  have low_a1_a2: \"(repc \\<propto> low) a1 = (repc \\<propto> low) a2\"\n                    by auto\n                  from shared_rt1_rt2 rbdt_def_rt1 rbdt_def_rt2 have rt1_rt2: \"rt1 = rt2\"\n                    by (auto simp add: isomorphic_dags_eq_def)\n                  then have root_rt1_rt2: \"root rt1 = root rt2\"\n                    by auto\n                  from rt1_nTip t1_repc_dag t1_Node have \"(repc \\<propto> high) (repc a1) \\<noteq> Null\"\n                    by auto\n                  with rt1_nTip t1_repc_dag t1_Node obtain lrt1 rt1p rrt1 where \n                    rt1_Node: \"rt1 = Node lrt1 rt1p rrt1\"\n                    by auto\n                  with t1_repc_dag t1_Node children_repc_eq_a1 rt1_nTip \n                  have root_rt1: \"root rt1 = (repc \\<propto> high) a1\"\n                    by auto\n                  from rt2_nTip t2_repc_dag t2_Node \n                  have \"(repc \\<propto> high) (repc a2) \\<noteq> Null\"\n                    by auto\n                  with rt2_nTip t2_repc_dag t2_Node obtain lrt2 rt2p rrt2 where \n                    rt2_Node: \"rt2 = Node lrt2 rt2p rrt2\"\n                    by auto\n                  with t2_repc_dag t2_Node children_repc_eq_a2 rt2_nTip \n                  have root_rt2: \"root rt2 = (repc \\<propto> high) a2\"\n                    by auto\n                  from root_rt1_rt2 root_rt2 root_rt1 \n                  have high_a1_a2: \"(repc \\<propto> high) a1 = (repc \\<propto> high) a2\"\n                    by auto\n                  from low_a1_a2 high_a1_a2 share_a1_a2   \n                  have \"repc a1 = repc a2\"\n                    by auto\n                  with lt1_lt2 rt1_rt2 show ?thesis\n                    by auto\n                qed\n              qed\n            qed\n          qed\n        qed\n        from termi dags_shared while_while_prop repcNodes_in_Nodes repc_nc n_var_prop \n          wf_marking_m_ma  \n        show ?thesis\n          by auto\n      qed\n    qed\n    with srrl_precond all_nodes_same_var \n    show ?thesis\n      apply -\n      apply (intro conjI)\n      apply assumption+\n      done\n  qed\nqed\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/BDD/NormalizeTotalProof.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.27172933061375243}}
{"text": "(* \n   Title: The pi-calculus   \n   Author/Maintainer: Jesper Bengtson (jebe.dk), 2012\n*)\ntheory Weak_Early_Sim\n  imports Weak_Early_Semantics Strong_Early_Sim_Pres\nbegin\n\ndefinition weakSimulation :: \"pi \\<Rightarrow> (pi \\<times> pi) set \\<Rightarrow> pi \\<Rightarrow> bool\" (\"_ \\<leadsto><_> _\" [80, 80, 80] 80)\n  where \"P \\<leadsto><Rel> Q \\<equiv> (\\<forall>a x Q'. Q \\<longmapsto>a<\\<nu>x> \\<prec> Q' \\<and> x \\<sharp> P \\<longrightarrow> (\\<exists>P'. P \\<Longrightarrow>a<\\<nu>x> \\<prec> P' \\<and> (P', Q') \\<in> Rel)) \\<and>\n                       (\\<forall>\\<alpha> Q'. Q \\<longmapsto>\\<alpha> \\<prec> Q' \\<longrightarrow> (\\<exists>P'. P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P' \\<and> (P', Q') \\<in> Rel))\"\n\n\n\n  assumes \"P \\<leadsto><A> P'\"\n  and     \"A \\<subseteq> B\"\n\n  shows \"P \\<leadsto><B> P'\"\nusing assms\nby(simp add: weakSimulation_def) blast\n\nlemma simCasesCont[consumes 1, case_names Bound Free]:\n  fixes P   :: pi\n  and   Q   :: pi\n  and   Rel :: \"(pi \\<times> pi) set\"\n  and   C   :: \"'a::fs_name\"\n\n  assumes Eqvt:  \"eqvt Rel\"\n  and     Bound: \"\\<And>a x Q'. \\<lbrakk>Q \\<longmapsto> a<\\<nu>x> \\<prec> Q'; x \\<sharp> P; x \\<sharp> Q; x \\<noteq> a; x \\<sharp> C\\<rbrakk> \\<Longrightarrow> \\<exists>P'. P \\<Longrightarrow>a<\\<nu>x> \\<prec> P' \\<and> (P', Q') \\<in> Rel\"\n  and     Free:  \"\\<And>\\<alpha> Q'. Q \\<longmapsto> \\<alpha> \\<prec> Q' \\<Longrightarrow> \\<exists>P'. P \\<Longrightarrow>\\<^sup>^ \\<alpha> \\<prec> P' \\<and> (P', Q') \\<in> Rel\"\n\n  shows \"P \\<leadsto><Rel> Q\"\nproof(auto simp add: weakSimulation_def)\n  fix a x Q'\n  assume QTrans: \"Q \\<longmapsto> a<\\<nu>x> \\<prec> Q'\" and \"x \\<sharp> P\"\n  obtain c::name where \"c \\<sharp> P\" and \"c \\<sharp> Q\" and \"c \\<noteq> a\" and \"c \\<sharp> Q'\" and \"c \\<sharp> C\" and \"c \\<noteq> x\"\n    by(generate_fresh \"name\") auto\n\n  from QTrans `c \\<sharp> Q'` have \"Q \\<longmapsto> a<\\<nu>c> \\<prec> ([(x, c)] \\<bullet> Q')\" by(simp add: alphaBoundOutput)\n  then obtain P' where PTrans: \"P \\<Longrightarrow>a<\\<nu>c> \\<prec> P'\" and P'RelQ': \"(P', [(x, c)] \\<bullet> Q') \\<in> Rel\"\n    using `c \\<sharp> P` `c \\<sharp> Q` `c \\<noteq> a` `c \\<sharp> C`\n    by(drule_tac Bound) auto\n\n  from PTrans `x \\<sharp> P` `c \\<noteq> x` have \"P \\<Longrightarrow>a<\\<nu>x> \\<prec> ([(x, c)] \\<bullet> P')\"\n    by(force intro: weakTransitionAlpha simp add: name_swap)\n  moreover from Eqvt P'RelQ' have \"([(x, c)] \\<bullet> P', [(x, c)] \\<bullet> [(x, c)] \\<bullet> Q') \\<in> Rel\"\n    by(rule eqvtRelI)\n  hence \"([(x, c)] \\<bullet> P', Q') \\<in> Rel\" by simp\n  ultimately show \"\\<exists>P'. P \\<Longrightarrow>a<\\<nu>x> \\<prec> P' \\<and> (P', Q') \\<in> Rel\"\n    by blast\nnext\n  fix \\<alpha> Q'\n  assume \"Q \\<longmapsto>\\<alpha> \\<prec> Q'\"\n  thus \"\\<exists>P'. P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P' \\<and> (P', Q') \\<in> Rel\"\n    by(rule Free)\nqed\n\nlemma simCases[case_names Bound Free]:\n  fixes P   :: pi\n  and   Q   :: pi\n  and   Rel :: \"(pi \\<times> pi) set\"\n  and   C   :: \"'a::fs_name\"\n\n  assumes \"\\<And>Q' a x. \\<lbrakk>Q \\<longmapsto> a<\\<nu>x> \\<prec> Q'; x \\<sharp> P\\<rbrakk> \\<Longrightarrow> \\<exists>P'. P \\<Longrightarrow>a<\\<nu>x> \\<prec> P' \\<and> (P', Q') \\<in> Rel\"\n  and     \"\\<And>Q' \\<alpha>. Q \\<longmapsto> \\<alpha> \\<prec> Q' \\<Longrightarrow> \\<exists>P'. P \\<Longrightarrow>\\<^sup>^ \\<alpha> \\<prec> P' \\<and> (P', Q') \\<in> Rel\"\n\n  shows \"P \\<leadsto><Rel> Q\"\nusing assms\nby(auto simp add: weakSimulation_def)\n\nlemma simE:\n  fixes P   :: pi\n  and   Rel :: \"(pi \\<times> pi) set\"\n  and   Q   :: pi\n  and   a   :: name\n  and   x   :: name\n  and   Q'  :: pi\n\n  assumes \"P \\<leadsto><Rel> Q\"\n\n  shows \"Q \\<longmapsto>a<\\<nu>x> \\<prec> Q' \\<Longrightarrow> x \\<sharp> P \\<Longrightarrow> \\<exists>P'. P \\<Longrightarrow>a<\\<nu>x> \\<prec> P' \\<and> (P', Q') \\<in> Rel\"\n  and   \"Q \\<longmapsto>\\<alpha> \\<prec> Q' \\<Longrightarrow> \\<exists>P'. P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P' \\<and> (P', Q') \\<in> Rel\"\nusing assms by(simp add: weakSimulation_def)+\n\nlemma weakSimTauChain:\n  fixes P   :: pi\n  and   Rel :: \"(pi \\<times> pi) set\"\n  and   Rel' :: \"(pi \\<times> pi) set\"\n  and   Q   :: pi\n  and   Q'  :: pi\n\n  assumes QChain: \"Q \\<Longrightarrow>\\<^sub>\\<tau> Q'\"\n  and     PRelQ: \"(P, Q) \\<in> Rel\"\n  and     PSimQ: \"\\<And>R S. (R, S) \\<in> Rel \\<Longrightarrow> R \\<leadsto><Rel> S\"\n\n  shows \"\\<exists>P'. P \\<Longrightarrow>\\<^sub>\\<tau> P' \\<and> (P', Q') \\<in> Rel\"\nproof -\n  from QChain show ?thesis\n  proof(induct rule: tauChainInduct)\n    case id\n    moreover have \"P \\<Longrightarrow>\\<^sub>\\<tau> P\" by simp\n    ultimately show ?case using PSimQ PRelQ by blast\n  next\n    case(ih Q' Q'')\n    have \"\\<exists>P'. P \\<Longrightarrow>\\<^sub>\\<tau> P' \\<and> (P', Q') \\<in> Rel\" by fact\n    then obtain P' where PChain: \"P \\<Longrightarrow>\\<^sub>\\<tau> P'\" and P'Rel'Q': \"(P', Q') \\<in> Rel\" by blast\n    from P'Rel'Q' have \"P' \\<leadsto><Rel> Q'\" by(rule PSimQ)\n    moreover have Q'Trans: \"Q' \\<longmapsto>\\<tau> \\<prec> Q''\" by fact\n    ultimately obtain P'' where P'Trans: \"P' \\<Longrightarrow>\\<^sup>^\\<tau> \\<prec> P''\" and P''RelQ'': \"(P'', Q'') \\<in> Rel\"\n      by(blast dest: simE)\n    from P'Trans have \"P' \\<Longrightarrow>\\<^sub>\\<tau> P''\" by simp\n    with PChain have \"P \\<Longrightarrow>\\<^sub>\\<tau> P''\" by auto\n    with P''RelQ'' show ?case by blast\n  qed\nqed\n\nlemma simE2:\n  fixes P   :: pi\n  and   Rel :: \"(pi \\<times> pi) set\"\n  and   Q   :: pi\n  and   a   :: name\n  and   x   :: name\n  and   Q'  :: pi\n\n  assumes Sim: \"\\<And>R S. (R, S) \\<in> Rel \\<Longrightarrow> R \\<leadsto><Rel> S\"\n  and     Eqvt: \"eqvt Rel\"\n  and     PRelQ: \"(P, Q) \\<in> Rel\"\n\n  shows \"Q \\<Longrightarrow>a<\\<nu>x> \\<prec> Q' \\<Longrightarrow> x \\<sharp> P \\<Longrightarrow> \\<exists>P'. P \\<Longrightarrow>a<\\<nu>x> \\<prec> P' \\<and> (P', Q') \\<in> Rel\"\n  and   \"Q \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> Q' \\<Longrightarrow> \\<exists>P'. P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P' \\<and> (P', Q') \\<in> Rel\"\nproof -\n  assume QTrans: \"Q \\<Longrightarrow>a<\\<nu>x> \\<prec> Q'\" and \"x \\<sharp> P\"\n  from QTrans obtain Q'' Q''' where QChain: \"Q \\<Longrightarrow>\\<^sub>\\<tau> Q'''\"\n                                and Q'''Trans: \"Q''' \\<longmapsto>a<\\<nu>x> \\<prec> Q''\"\n                                and Q''Chain: \"Q'' \\<Longrightarrow>\\<^sub>\\<tau> Q'\"\n    by(blast dest: transitionE)\n\n  from QChain PRelQ Sim obtain P''' where PChain: \"P \\<Longrightarrow>\\<^sub>\\<tau> P'''\" and P'''RelQ''': \"(P''', Q''') \\<in> Rel\" \n    by(blast dest: weakSimTauChain)\n\n  from PChain `x \\<sharp> P` have \"x \\<sharp> P'''\" by(rule freshChain)\n      \n  from P'''RelQ''' have \"P''' \\<leadsto><Rel> Q'''\" by(rule Sim)\n  with Q'''Trans `x \\<sharp> P'''` obtain P'' where P'''Trans: \"P''' \\<Longrightarrow>a<\\<nu>x> \\<prec> P''\"\n                                         and P''RelQ'': \"(P'', Q'') \\<in> Rel\"\n    by(blast dest: simE)\n\n  from Q''Chain P''RelQ'' Sim obtain P' where P''Chain: \"P'' \\<Longrightarrow>\\<^sub>\\<tau> P'\" and P'RelQ': \"(P', Q') \\<in> Rel\"\n    by(blast dest: weakSimTauChain)\n  from PChain P'''Trans P''Chain  have \"P \\<Longrightarrow>a<\\<nu>x> \\<prec> P'\"\n    by(blast dest: Weak_Early_Step_Semantics.chainTransitionAppend)\n  with P'RelQ' show \"\\<exists>P'. P \\<Longrightarrow>a<\\<nu>x> \\<prec> P' \\<and> (P', Q') \\<in> Rel\" by blast\nnext\n  assume \"Q \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> Q'\"\n  thus \"\\<exists>P'. P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P' \\<and> (P', Q') \\<in> Rel\"\n  proof(induct rule: transitionCases)\n    case Step\n    have \"Q \\<Longrightarrow>\\<alpha> \\<prec> Q'\" by fact\n    then obtain Q'' Q''' where QChain: \"Q \\<Longrightarrow>\\<^sub>\\<tau> Q''\" \n                           and Q''Trans: \"Q'' \\<longmapsto>\\<alpha> \\<prec> Q'''\"\n                           and Q'''Chain: \"Q''' \\<Longrightarrow>\\<^sub>\\<tau> Q'\"\n      by(blast dest: transitionE)\n\n    from QChain PRelQ Sim have \"\\<exists>P''. P \\<Longrightarrow>\\<^sub>\\<tau> P'' \\<and> (P'', Q'') \\<in> Rel\"\n      by(rule weakSimTauChain)\n    then obtain P'' where PChain: \"P \\<Longrightarrow>\\<^sub>\\<tau> P''\" and P''RelQ'': \"(P'', Q'') \\<in> Rel\" by blast\n    from P''RelQ'' have \"P'' \\<leadsto><Rel> Q''\" by(rule Sim)\n    with Q''Trans obtain P''' where P''Trans: \"P'' \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P'''\"\n                                and P'''RelQ''': \"(P''', Q''') \\<in> Rel\"\n      by(blast dest: simE)\n    \n    have \"\\<exists>P'. P''' \\<Longrightarrow>\\<^sub>\\<tau> P' \\<and> (P', Q') \\<in> Rel\" using Q'''Chain P'''RelQ''' Sim\n      by(rule weakSimTauChain)\n    then obtain P' where P'''Chain: \"P''' \\<Longrightarrow>\\<^sub>\\<tau> P'\" and P'RelQ': \"(P', Q') \\<in> Rel\" by blast\n    \n    from PChain P''Trans P'''Chain have \"P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P'\"\n      by(blast dest: chainTransitionAppend)\n    with P'RelQ' show ?case by blast\n  next\n    case Stay\n    have \"P \\<Longrightarrow>\\<^sup>^\\<tau> \\<prec> P\" by simp\n    thus ?case using PRelQ by blast\n  qed\nqed\n\nlemma eqvtI:\n  fixes P    :: pi\n  and   Q    :: pi\n  and   Rel  :: \"(pi \\<times> pi) set\"\n  and   perm :: \"name prm\"\n\n  assumes PSimQ: \"P \\<leadsto><Rel> Q\"\n  and     RelRel': \"Rel \\<subseteq> Rel'\"\n  and     EqvtRel': \"eqvt Rel'\"\n\n  shows \"(perm \\<bullet> P) \\<leadsto><Rel'> (perm \\<bullet> Q)\"\nproof(induct rule: simCases)\n  case(Bound Q' a x)\n  have xFreshP: \"x \\<sharp> perm \\<bullet> P\" by fact\n  have QTrans: \"(perm \\<bullet> Q) \\<longmapsto> a<\\<nu>x> \\<prec> Q'\" by fact\n\n  hence \"(rev perm \\<bullet> (perm \\<bullet> Q)) \\<longmapsto> rev perm \\<bullet> (a<\\<nu>x> \\<prec> Q')\" by(rule eqvts)\n  hence \"Q \\<longmapsto> (rev perm \\<bullet> a)<\\<nu>(rev perm \\<bullet> x)> \\<prec> (rev perm \\<bullet> Q')\" \n    by(simp add: name_rev_per)\n  moreover from xFreshP have \"(rev perm \\<bullet> x) \\<sharp> P\" by(simp add: name_fresh_left)\n  ultimately obtain P' where PTrans: \"P \\<Longrightarrow>(rev perm \\<bullet> a)<\\<nu>(rev perm \\<bullet> x)> \\<prec> P'\"\n                         and P'RelQ': \"(P', rev perm \\<bullet> Q') \\<in> Rel\" using PSimQ\n    by(blast dest: simE)\n  \n  from PTrans have \"(perm \\<bullet> P) \\<Longrightarrow>(perm \\<bullet> rev perm \\<bullet> a)<\\<nu>(perm \\<bullet> rev perm \\<bullet> x)> \\<prec> perm \\<bullet> P'\" \n    by(rule eqvts)\n  hence \"(perm \\<bullet> P) \\<Longrightarrow>a<\\<nu>x> \\<prec> (perm \\<bullet> P')\" by(simp add: name_per_rev)\n  moreover from P'RelQ' RelRel' have \"(P', rev perm \\<bullet> Q') \\<in> Rel'\" by blast\n  with EqvtRel' have \"(perm \\<bullet> P', perm \\<bullet> (rev perm \\<bullet> Q')) \\<in> Rel'\"\n    by(rule eqvtRelI)\n  hence \"(perm \\<bullet> P', Q') \\<in> Rel'\" by(simp add: name_per_rev)\n  ultimately show ?case by blast\nnext\n  case(Free Q' \\<alpha>)\n  have QTrans: \"(perm \\<bullet> Q) \\<longmapsto> \\<alpha> \\<prec> Q'\" by fact\n\n  hence \"(rev perm \\<bullet> (perm \\<bullet> Q)) \\<longmapsto> rev perm \\<bullet> (\\<alpha> \\<prec> Q')\" by(rule eqvts)\n  hence \"Q \\<longmapsto> (rev perm \\<bullet> \\<alpha>) \\<prec> (rev perm \\<bullet> Q')\"  by(simp add: name_rev_per)\n  with PSimQ obtain P' where PTrans: \"P \\<Longrightarrow>\\<^sup>^ (rev perm \\<bullet> \\<alpha>) \\<prec> P'\"\n                         and PRel: \"(P', (rev perm \\<bullet> Q')) \\<in> Rel\"\n    by(blast dest: simE)\n\n  from PTrans have \"(perm \\<bullet> P) \\<Longrightarrow>\\<^sup>^ (perm \\<bullet> rev perm \\<bullet> \\<alpha>) \\<prec> perm \\<bullet> P'\"\n    by(rule Weak_Early_Semantics.eqvtI)\n  hence L1: \"(perm \\<bullet> P) \\<Longrightarrow>\\<^sup>^ \\<alpha> \\<prec> (perm \\<bullet> P')\" by(simp add: name_per_rev)\n  from PRel EqvtRel' RelRel'  have \"((perm \\<bullet> P'), (perm \\<bullet> (rev perm \\<bullet> Q'))) \\<in> Rel'\"\n    by(force intro: eqvtRelI)\n  hence \"((perm \\<bullet> P'), Q') \\<in> Rel'\" by(simp add: name_per_rev)\n  with L1 show ?case by blast\nqed\n\n(*****************Reflexivity and transitivity*********************)\n\nlemma reflexive:\n  fixes P   :: pi\n  and   Rel :: \"(pi \\<times> pi) set\"\n\n  assumes \"Id \\<subseteq> Rel\"\n\n  shows \"P \\<leadsto><Rel> P\"\nusing assms\nby(auto intro: Weak_Early_Step_Semantics.singleActionChain\n   simp add: weakSimulation_def weakFreeTransition_def)\n\n\n\n  assumes QSimR: \"Q \\<leadsto><Rel'> R\"\n  and     Eqvt: \"eqvt Rel\"\n  and     Eqvt'': \"eqvt Rel''\"\n  and     Trans: \"Rel O Rel' \\<subseteq> Rel''\"\n  and     Sim: \"\\<And>S T. (S, T) \\<in> Rel \\<Longrightarrow> S \\<leadsto><Rel> T\"\n  and     PRelQ: \"(P, Q) \\<in> Rel\"\n\n  shows \"P \\<leadsto><Rel''> R\"\nproof -\n  from Eqvt'' show ?thesis\n  proof(induct rule: simCasesCont[where C=Q])\n    case(Bound a x R')\n    have RTrans: \"R \\<longmapsto>a<\\<nu>x> \\<prec> R'\" by fact\n    from `x \\<sharp> Q` QSimR RTrans obtain Q' where QTrans: \"Q \\<Longrightarrow>a<\\<nu>x> \\<prec> Q'\"\n                                          and Q'Rel'R': \"(Q', R') \\<in> Rel'\"\n      by(blast dest: simE)\n\n    from Sim Eqvt PRelQ QTrans `x \\<sharp> P` \n    obtain P' where PTrans: \"P \\<Longrightarrow>a<\\<nu>x> \\<prec> P'\" and P'RelQ': \"(P', Q') \\<in> Rel\"\n      by(drule_tac simE2) auto\n(*      by(blast dest: simE2)*)\n    moreover from P'RelQ' Q'Rel'R' Trans have \"(P', R') \\<in> Rel''\" by blast\n    ultimately show ?case by blast\n  next\n    case(Free \\<alpha> R')\n    have RTrans: \"R \\<longmapsto> \\<alpha> \\<prec> R'\" by fact\n    with QSimR obtain Q' where QTrans: \"Q \\<Longrightarrow>\\<^sup>^ \\<alpha> \\<prec> Q'\" and Q'RelR': \"(Q', R') \\<in> Rel'\"\n      by(blast dest: simE)\n    from Sim Eqvt PRelQ QTrans have \"\\<exists>P'. P \\<Longrightarrow>\\<^sup>^ \\<alpha> \\<prec> P' \\<and> (P', Q') \\<in> Rel\"\n      by(blast intro: simE2)\n    then obtain P' where PTrans: \"P \\<Longrightarrow>\\<^sup>^ \\<alpha> \\<prec> P'\" and P'RelQ': \"(P', Q') \\<in> Rel\" by blast\n    from P'RelQ' Q'RelR' Trans have \"(P', R') \\<in> Rel''\" by blast\n    with PTrans show ?case by blast\n  qed\nqed\n\nlemma strongAppend:\n  fixes P     :: pi\n  and   Q     :: pi\n  and   R     :: pi\n  and   Rel   :: \"(pi \\<times> pi) set\"\n  and   Rel'  :: \"(pi \\<times> pi) set\"\n  and   Rel'' :: \"(pi \\<times> pi) set\"\n\n  assumes PSimQ: \"P \\<leadsto><Rel> Q\"\n  and     QSimR: \"Q \\<leadsto>[Rel'] R\"\n  and     Eqvt'': \"eqvt Rel''\"\n  and     Trans: \"Rel O Rel' \\<subseteq> Rel''\"\n\n  shows \"P \\<leadsto><Rel''> R\"\nproof -\n  from Eqvt'' show ?thesis\n  proof(induct rule: simCasesCont[where C=Q])\n    case(Bound a x R')\n    have RTrans: \"R \\<longmapsto>a<\\<nu>x> \\<prec> R'\" by fact\n    from QSimR RTrans `x \\<sharp> Q` obtain Q' where QTrans: \"Q \\<longmapsto>a<\\<nu>x> \\<prec> Q'\"\n                                          and Q'Rel'R': \"(Q', R') \\<in> Rel'\"\n      by(blast dest: Strong_Early_Sim.elim)\n\n    with PSimQ QTrans `x \\<sharp> P` obtain P' where PTrans: \"P \\<Longrightarrow>a<\\<nu>x> \\<prec> P'\" and P'RelQ': \"(P', Q') \\<in> Rel\" \n      by(blast dest: simE)\n    moreover from P'RelQ' Q'Rel'R' Trans have \"(P', R') \\<in> Rel''\" by blast\n    ultimately show ?case by blast\n  next\n    case(Free \\<alpha> R')\n    have RTrans: \"R \\<longmapsto> \\<alpha> \\<prec> R'\" by fact\n    with QSimR obtain Q' where QTrans: \"Q \\<longmapsto>\\<alpha> \\<prec> Q'\" and Q'RelR': \"(Q', R') \\<in> Rel'\"\n      by(blast dest: Strong_Early_Sim.elim)\n    from PSimQ QTrans obtain P' where PTrans: \"P \\<Longrightarrow>\\<^sup>^ \\<alpha> \\<prec> P'\" and P'RelQ': \"(P', Q') \\<in> Rel\"\n      by(blast dest: simE)\n    from P'RelQ' Q'RelR' Trans have \"(P', R') \\<in> Rel''\" by blast\n    with PTrans show ?case by blast\n  qed\nqed\n\nlemma strongSimWeakSim:\n  fixes P   :: pi\n  and   Q   :: pi\n  and   Rel :: \"(pi \\<times> pi) set\"\n\n  assumes PSimQ: \"P \\<leadsto>[Rel] Q\"\n\n  shows \"P \\<leadsto><Rel> Q\"\nproof(induct rule: simCases)\n  case(Bound Q' a x)\n  have \"Q \\<longmapsto>a<\\<nu>x> \\<prec> Q'\" by fact\n  with PSimQ `x \\<sharp> P` obtain P' where PTrans: \"P \\<longmapsto>a<\\<nu>x> \\<prec> P'\" and P'RelQ': \"(P', Q') \\<in> Rel\"\n    by(blast dest: Strong_Early_Sim.elim)\n  from PTrans have \"P \\<Longrightarrow>a<\\<nu>x> \\<prec>  P'\"\n    by(force intro: Weak_Early_Step_Semantics.singleActionChain simp add: weakFreeTransition_def)\n  with P'RelQ' show ?case by blast\nnext\n  case(Free Q' \\<alpha>)\n  have \"Q \\<longmapsto>\\<alpha> \\<prec> Q'\" by fact\n  with PSimQ obtain P' where PTrans: \"P \\<longmapsto>\\<alpha> \\<prec> P'\" and P'RelQ': \"(P', Q') \\<in> Rel\"\n    by(blast dest: Strong_Early_Sim.elim)\n  from PTrans have \"P \\<Longrightarrow>\\<^sup>^\\<alpha> \\<prec> P'\" by(rule Weak_Early_Semantics.singleActionChain)\n  with P'RelQ' show ?case by blast\nqed\n\nend", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Pi_Calculus/Weak_Early_Sim.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5078118642792044, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.27172933061375243}}
{"text": "theory InferSound\n  imports InferDef\nbegin\n\n    (* ##### inference correctness lemma 1 *)\n\nlemma ivl_const_main: \"\\<lbrakk> dir_sol_sat t_sub p_sub c_list; const_scheme x ds tau c_list ds'\\<rbrakk> \\<Longrightarrow> full_subst_type t_sub p_sub tau_n tau \\<in> const_type x\"\n  apply (case_tac x)\n              apply (auto)\n              apply (simp_all add: full_subst_type_def)\n              apply (simp_all add: pure_fun_s_def)\n              apply (simp_all add: pure_fun_def)\n              apply (simp_all add: unlim_def)\n        apply (simp_all add: is_own_def)\n      apply (auto)\n  done\n    \nlemma ivl_op_main: \"full_subst_type t_sub p_sub tau_n (op_scheme x) = op_type x\"\n  apply (case_tac x)\n       apply (auto)\n       apply (simp_all add: full_subst_type_def)\n       apply (simp_all add: pure_fun_s_def)\n       apply (simp_all add: pure_fun_def)\n  done\n  \nlemma ivl_pair_ih: \"\\<lbrakk> \\<And>env tau r_s r_x r_m c_list ds ds'.\n           \\<lbrakk>infer_type env ds e tau r_s r_x r_m c_list ds'; dir_sol_sat t_sub p_sub c_list\\<rbrakk>\n           \\<Longrightarrow> well_typed (dir_subst_tenv (fill_tsub t_sub tau_n) env) (dir_subst_penv t_sub p_sub r_s) e (full_subst_type t_sub p_sub tau_n tau)\n                (diff_use_env (dir_subst_penv t_sub p_sub r_s) (dir_subst_penv t_sub p_sub r_m))\n                (diff_use_env (dir_subst_penv t_sub p_sub r_x) (dir_subst_penv t_sub p_sub r_m));\n  infer_type env ds e tau r_s r_x r_m c_list ds'; dir_sol_sat t_sub p_sub c_list\\<rbrakk> \\<Longrightarrow>\n  well_typed (dir_subst_tenv (fill_tsub t_sub tau_n) env) (dir_subst_penv t_sub p_sub r_s) e (full_subst_type t_sub p_sub tau_n tau)\n                (diff_use_env (dir_subst_penv t_sub p_sub r_s) (dir_subst_penv t_sub p_sub r_m))\n                (diff_use_env (dir_subst_penv t_sub p_sub r_x) (dir_subst_penv t_sub p_sub r_m))\"    \n  apply (auto)\n  done\n    \nlemma ivl_if_ih: \"\\<lbrakk> \\<And>env tau r_s r_x r_m c_list ds ds'.\n           \\<lbrakk>infer_type env ds e tau r_s r_x r_m c_list ds'; dir_sol_sat t_sub p_sub c_list\\<rbrakk>\n           \\<Longrightarrow> well_typed (dir_subst_tenv (fill_tsub t_sub tau_n) env) (dir_subst_penv t_sub p_sub r_s) e (full_subst_type t_sub p_sub tau_n tau)\n                (diff_use_env (dir_subst_penv t_sub p_sub r_s) (dir_subst_penv t_sub p_sub r_m))\n                (diff_use_env (dir_subst_penv t_sub p_sub r_x) (dir_subst_penv t_sub p_sub r_m));\n  infer_type env ds e tau r_s r_x r_m c_list ds'; dir_sol_sat t_sub p_sub c_list \\<rbrakk> \\<Longrightarrow>\n  well_typed (dir_subst_tenv (fill_tsub t_sub tau_n) env) (dir_subst_penv t_sub p_sub r_s) e (full_subst_type t_sub p_sub tau_n tau)\n                (diff_use_env (dir_subst_penv t_sub p_sub r_s) (dir_subst_penv t_sub p_sub r_m))\n                (diff_use_env (dir_subst_penv t_sub p_sub r_x) (dir_subst_penv t_sub p_sub r_m))\"    \n  apply (auto)\n  done\n    \nlemma ivl_lam_ih: \"\\<lbrakk> \\<And>env tau r_s r_x r_m c_list ds ds'.\n           \\<lbrakk>infer_type env ds e tau r_s r_x r_m c_list ds'; dir_sol_sat t_sub p_sub c_list\\<rbrakk>\n           \\<Longrightarrow> well_typed (dir_subst_tenv (fill_tsub t_sub tau_n) env) (dir_subst_penv t_sub p_sub r_s) e (full_subst_type t_sub p_sub tau_n tau)\n                (diff_use_env (dir_subst_penv t_sub p_sub r_s) (dir_subst_penv t_sub p_sub r_m))\n                (diff_use_env (dir_subst_penv t_sub p_sub r_x) (dir_subst_penv t_sub p_sub r_m));\n   infer_type env ds e tau r_s r_x r_m c_list ds'; dir_sol_sat t_sub p_sub c_list \\<rbrakk> \\<Longrightarrow>\n  well_typed (dir_subst_tenv (fill_tsub t_sub tau_n) env) (dir_subst_penv t_sub p_sub r_s) e (full_subst_type t_sub p_sub tau_n tau)\n                (diff_use_env (dir_subst_penv t_sub p_sub r_s) (dir_subst_penv t_sub p_sub r_m))\n                (diff_use_env (dir_subst_penv t_sub p_sub r_x) (dir_subst_penv t_sub p_sub r_m))\"  \n  apply (auto)\n  done\n    \nlemma ivl_app_ih: \"\\<lbrakk> \\<And>env tau r_s r_x r_m c_list ds ds'.\n           \\<lbrakk>infer_type env ds e tau r_s r_x r_m c_list ds'; dir_sol_sat t_sub p_sub c_list\\<rbrakk>\n           \\<Longrightarrow> well_typed (dir_subst_tenv (fill_tsub t_sub tau_n) env) (dir_subst_penv t_sub p_sub r_s) e (full_subst_type t_sub p_sub tau_n tau)\n                (diff_use_env (dir_subst_penv t_sub p_sub r_s) (dir_subst_penv t_sub p_sub r_m))\n                (diff_use_env (dir_subst_penv t_sub p_sub r_x) (dir_subst_penv t_sub p_sub r_m));\n   infer_type env ds e tau r_s r_x r_m c_list ds'; dir_sol_sat t_sub p_sub c_list\\<rbrakk> \\<Longrightarrow>\n  well_typed (dir_subst_tenv (fill_tsub t_sub tau_n) env) (dir_subst_penv t_sub p_sub r_s) e (full_subst_type t_sub p_sub tau_n tau)\n                (diff_use_env (dir_subst_penv t_sub p_sub r_s) (dir_subst_penv t_sub p_sub r_m))\n                (diff_use_env (dir_subst_penv t_sub p_sub r_x) (dir_subst_penv t_sub p_sub r_m))\"    \n  apply (auto)\n  done\n    \nlemma ivl_var_leq_perm: \"\\<lbrakk> req_type tau_n = Prim \\<rbrakk> \\<Longrightarrow>\n  leq_perm (end_req_perm (full_subst_type t_sub p_sub tau_n (VarScheme b)))\n      (dir_subst_penv t_sub p_sub (one_var_env (owner_name x) (XType b)) (owner_name x))\"\n  apply (simp add: full_subst_type_def)\n  apply (simp add: end_req_perm_def)\n  apply (simp add: dir_subst_penv_def)\n  apply (simp add: one_var_env_def)\n  apply (case_tac \"t_sub b\")\n   apply (auto)\n  apply (case_tac \"req_type a\")\n    apply (auto)\n  done\n \nlemma dir_aff_leq: \"\\<lbrakk> dir_subst_type t_sub p_sub tau_v tau; aff_leq (req_type tau) r \\<rbrakk> \\<Longrightarrow>\n  aff_leq (req_type (full_subst_type_f t_sub p_sub tau_n tau_v)) r\"\n  apply (induct tau_v)\n         apply (auto)\n  done\n \nlemma dir_subst_type_eq: \"\\<lbrakk> dir_subst_type t_sub p_sub tau_v tau \\<rbrakk> \\<Longrightarrow> full_subst_type t_sub p_sub tau_n tau_v = tau\"    \n  apply (induct tau_v arbitrary: tau)\n         apply (auto)\n         apply (simp_all add: full_subst_type_def)\n  done\n    \nlemma mini_disj_lift_use_env_rev: \"\\<lbrakk> mini_disj_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> mini_disj_use_env r_x (lift_use_env r_s r)\"    \n  apply (case_tac r)\n    apply (auto)\n  apply (simp add: mini_disj_use_env_def)\n  done\n  \nlemma infer_valid_left: \"\\<lbrakk> infer_type env ds e tau r_s r_x r_m c_list ds'; dir_sol_sat t_sub p_sub c_list; req_type tau_n = Prim \\<rbrakk> \\<Longrightarrow>\n  well_typed (dir_subst_tenv (fill_tsub t_sub tau_n) env) (dir_subst_penv t_sub p_sub r_s) e (full_subst_type t_sub p_sub tau_n tau)\n    (diff_use_env (dir_subst_penv t_sub p_sub r_s) (dir_subst_penv t_sub p_sub r_m)) (diff_use_env (dir_subst_penv t_sub p_sub r_x) (dir_subst_penv t_sub p_sub r_m))\"\n  apply (induct e arbitrary: env tau r_s r_x r_m c_list ds ds')\n        apply (auto)\n    (* const case *)\n             apply (rule_tac ivl_const_main)\n              apply (simp_all)\n            apply (rule_tac self_diff_leq_use_env)\n           apply (rule_tac id_leq_use_env)\n    (* op case *)\n          apply (rule_tac ivl_op_main)\n         apply (rule_tac self_diff_leq_use_env)\n        apply (rule_tac id_leq_use_env)\n    (* var case *)\n       apply (simp add: dir_subst_tenv_def)\n       apply (simp add: fill_tsub_def)\n       apply (case_tac \"t_sub a\")\n        apply (auto)\n        apply (simp add: full_subst_type_def)\n       apply (simp add: full_subst_type_def)\n      apply (simp add: fill_tsub_def)\n      apply (cut_tac x=\"owner_name x\" and tau=\"full_subst_type t_sub p_sub tau_n (VarScheme b)\" and\n        r_s=\"dir_subst_penv t_sub p_sub (one_var_env (owner_name x) (XType b))\" in ereq_leq_use_envx)\n       apply (rule_tac ivl_var_leq_perm)\n       apply (auto)\n      apply (rule_tac x=\"dir_subst_penv t_sub p_sub (one_var_env (owner_name x) (XType b))\" in exI)\n      apply (rule_tac x=\"full_subst_type t_sub p_sub tau_n (VarScheme b)\" in exI)\n      apply (simp add: full_subst_type_def)\n      apply (simp add: dir_subst_tenv_def)\n      apply (auto)\n           apply (case_tac \"t_sub b\")\n            apply (auto)\n          apply (case_tac x)\n           apply (auto)\n         apply (rule_tac dist_diff_leq_use_env_gen)\n         apply (rule_tac id_leq_use_env)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (simp_all)\n       apply (rule_tac id_leq_use_env)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac id_leq_use_env)\n      apply (rule_tac dist_diff_leq_use_env_gen)\n       apply (simp)\n      apply (rule_tac self_comp_leq_use_env2)\n    (* pair case. exepected type *)\n    (* - prelim: solution satisfaction *)(*\n     apply (cut_tac ?cl2.0=\"semi_disj_crn r_m2 (lift_var_env r_x1 (SVar p)) d @ semi_disj_crn r_m1 (comp_var_env r_s2 (lift_var_env r_x2 (SVar p))) d @ cl1 @ cl2\" in sol_sat_append2)\n      apply (auto)\n     apply (cut_tac ?cl2.0=\"semi_disj_crn r_m1 (comp_var_env r_s2 (lift_var_env r_x2 (SVar p))) d @ cl1 @ cl2\" in sol_sat_append2)\n      apply (auto)*)\n     apply (simp add: full_subst_type_def)\n     apply (cut_tac ?cl2.0=\"semi_disj_crn r_m2 r_x1 d @ semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2\" in sol_sat_append2)\n      apply (auto)\n     apply (cut_tac ?cl2.0=\"semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2\" in sol_sat_append2)\n      apply (auto)\n     apply (cut_tac ?cl2.0=\"cl1 @ cl2\" in sol_sat_append2)\n      apply (auto)\n    (* - prelim: initial disjointness statements *)\n     apply (cut_tac r_x=\"r_m2\" and r_s=\"r_x1\" in sol_sat_mini_disj_use_env)\n        apply (rule_tac sol_sat_append1)\n        apply (auto)\n       apply (rule_tac r_s=\"comp_var_env (comp_var_env r_s1 (lift_var_env r_x1 (SVar p))) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))\" in finite_sub_dom)\n        apply (simp)\n       apply (rule_tac comp_sub_dom2)\n       apply (rule_tac comp_sub_dom1)\n       apply (rule_tac infer_m_sub_dom)\n       apply (simp)\n      apply (rule_tac r_s=\"comp_var_env (comp_var_env r_s1 (lift_var_env r_x1 (SVar p))) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))\" in finite_sub_dom)\n       apply (simp)\n      apply (rule_tac comp_sub_dom1)\n      apply (rule_tac comp_sub_dom2)\n      apply (rule_tac lift_sub_dom2)\n      apply (rule_tac id_sub_dom)\n     apply (cut_tac r_x=\"r_m1\" and r_s=\"r_s2\" in sol_sat_mini_disj_use_env)\n        apply (rule_tac sol_sat_append1)\n        apply (auto)\n       apply (rule_tac r_s=\"comp_var_env (comp_var_env r_s1 (lift_var_env r_x1 (SVar p))) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))\" in finite_sub_dom)\n        apply (simp)\n       apply (rule_tac comp_sub_dom1)\n       apply (rule_tac comp_sub_dom1)\n       apply (rule_tac infer_m_sub_dom)\n       apply (simp)\n      apply (rule_tac r_s=\"comp_var_env (comp_var_env r_s1 (lift_var_env r_x1 (SVar p))) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))\" in finite_sub_dom)\n       apply (simp)\n      apply (rule_tac comp_sub_dom2)\n      apply (rule_tac comp_sub_dom1)\n      apply (rule_tac id_sub_dom)\n     apply (cut_tac r_x=\"lift_var_env r_x1 (SVar p)\" and r_s=\"lift_var_env r_x2 (SVar p)\" in sol_sat_disj_use_env)\n        apply (rule_tac sol_sat_append1)\n        apply (auto)\n       apply (rule_tac r_s=\"comp_var_env (comp_var_env r_s1 (lift_var_env r_x1 (SVar p))) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))\" in finite_sub_dom)\n        apply (simp)\n       apply (rule_tac comp_sub_dom1)\n       apply (rule_tac comp_sub_dom2)\n       apply (rule_tac id_sub_dom)\n      apply (rule_tac r_s=\"comp_var_env (comp_var_env r_s1 (lift_var_env r_x1 (SVar p))) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))\" in finite_sub_dom)\n       apply (simp)\n      apply (rule_tac comp_sub_dom2)\n      apply (rule_tac comp_sub_dom2)\n      apply (rule_tac id_sub_dom)\n(*\n     apply (cut_tac r_x=\"comp_var_env r_s1 (lift_var_env r_x1 (SVar p))\" and r_s=\"comp_var_env r_s2 (lift_var_env r_x2 (SVar p))\" and d=\"d\" in sol_sat_disj_use_env)\n        apply (rule_tac ?cl2.0=\"cl1 @ cl2\" in sol_sat_append1)\n        apply (simp)\n       apply (rule_tac r_s=\"comp_var_env (comp_var_env r_s1 (lift_var_env r_x1 (SVar p))) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))\" in finite_sub_dom)\n        apply (simp)\n       apply (rule_tac comp_sub_dom1)\n       apply (rule_tac id_sub_dom)\n      apply (rule_tac r_s=\"comp_var_env (comp_var_env r_s1 (lift_var_env r_x1 (SVar p))) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))\" in finite_sub_dom)\n       apply (simp)\n      apply (rule_tac comp_sub_dom2)\n      apply (rule_tac id_sub_dom)*)    \n    (* - expected permission environments *)\n     apply (rule_tac x=\"diff_use_env (dir_subst_penv t_sub p_sub (comp_var_env (comp_var_env r_s1 (lift_var_env r_x1 (SVar p)))\n        (comp_var_env r_s2 (lift_var_env r_x2 (SVar p))))) (dir_subst_penv t_sub p_sub r_m1)\" in exI)\n     apply (rule_tac x=\"diff_use_env (dir_subst_penv t_sub p_sub (comp_var_env (comp_var_env r_s1 (lift_var_env r_x1 (SVar p)))\n        (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))))\n        (dir_subst_penv t_sub p_sub (comp_var_env r_m1 r_m2))\" in exI)\n     apply (rule_tac x=\"diff_use_env (dir_subst_penv t_sub p_sub r_x1) (dir_subst_penv t_sub p_sub r_m1)\" in exI)\n     apply (auto)\n    (* - induction for e1 *)\n      apply (cut_tac env=\"env\" and ds=\"ds\" and e=\"e1\" and tau=\"t1\" and r_s=\"r_s1\" and r_x=\"r_x1\" and r_m=\"r_m1\" and\n        c_list=\"cl1\" and ds'=\"ds2\" and t_sub=\"t_sub\" and p_sub=\"p_sub\" and tau_n=\"tau_n\" in ivl_pair_ih)\n         apply (auto)\n        apply (simp add: full_subst_type_def)\n       apply (rule_tac sol_sat_append1)\n       apply (simp)\n    (* > remove [S2 + lift(X2, p)] using the precision lemma *)\n      apply (simp add: comp_sol_subst_penv)\n      apply (rule_tac well_typed_comp_perms_prec)\n(*\n    (* > get into form [(S1 + lift(X1, p)) - M1] + [(S2 + lift(X2, p)) - M1] *)\n      apply (simp add: comp_sol_subst_penv)\n      apply (rule_tac t=\"diff_use_env\n              (comp_use_env (comp_use_env (dir_subst_penv t_sub p_sub r_s1) (dir_subst_penv t_sub p_sub (lift_var_env r_x1 (SVar p))))\n                (comp_use_env (dir_subst_penv t_sub p_sub r_s2) (dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p)))))\n              (dir_subst_penv t_sub p_sub r_m1)\" and\n        s=\"comp_use_env (diff_use_env (comp_use_env (dir_subst_penv t_sub p_sub r_s1) (dir_subst_penv t_sub p_sub (lift_var_env r_x1 (SVar p))))\n              (dir_subst_penv t_sub p_sub r_m1))\n                (diff_use_env (comp_use_env (dir_subst_penv t_sub p_sub r_s2) (dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p))))\n              (dir_subst_penv t_sub p_sub r_m1))\" in subst)\n       apply (rule_tac dist_diff_comp_use_env)\n    (* > increase [(S2 + lift(X2, p)) - M1] to (S2 + lift(X2, p)) *)\n      apply (rule_tac r_c=\"comp_use_env\n              (diff_use_env (comp_use_env (dir_subst_penv t_sub p_sub r_s1) (dir_subst_penv t_sub p_sub (lift_var_env r_x1 (SVar p))))\n                (dir_subst_penv t_sub p_sub r_m1))\n              (comp_use_env (dir_subst_penv t_sub p_sub r_s2) (dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p))))\" in well_typed_decr_end_perm)\n    (* > remove (S2 + lift(X2, p)) from the start + end perms *)\n        apply (rule_tac well_typed_comp_perms)*)\n    (* > transform [(S1 + lift(X1, p)) - M1] into (S1 - M1) + lift(X1 - M1, p) *)\n       apply (rule_tac t=\"dir_subst_penv t_sub p_sub (lift_var_env r_x1 (SVar p))\" and\n              s=\"lift_use_env (dir_subst_penv t_sub p_sub r_x1) (sol_subst_perm p_sub (SVar p))\" in subst)\n        apply (rule_tac lift_sol_subst_penv)\n       apply (simp_all)\n      apply (rule_tac t=\"diff_use_env (comp_use_env (dir_subst_penv t_sub p_sub r_s1) (lift_use_env (dir_subst_penv t_sub p_sub r_x1) (p_sub p))) (dir_subst_penv t_sub p_sub r_m1)\"\n          and s=\"comp_use_env (diff_use_env (dir_subst_penv t_sub p_sub r_s1) (dir_subst_penv t_sub p_sub r_m1))\n            (diff_use_env (lift_use_env (dir_subst_penv t_sub p_sub r_x1) (p_sub p)) (dir_subst_penv t_sub p_sub r_m1))\" in subst)\n       apply (rule_tac dist_diff_comp_use_env)\n      apply (simp add: lift_diff_use_env)\n    (* > remove lifts and cancel X1 *)\n      apply (rule_tac well_typed_comp_lift_perms)\n       apply (cut_tac r_s=\"dir_subst_penv t_sub p_sub r_s1\" and r_x=\"dir_subst_penv t_sub p_sub r_x1\" in cancel_comp_use_env2)\n        apply (rule_tac env=\"env\" and e=\"e1\" and c_list=\"cl1\" in infer_x_leq_use_env)\n        apply (auto)\n       apply (cut_tac r_s=\"diff_use_env (dir_subst_penv t_sub p_sub r_s1) (dir_subst_penv t_sub p_sub r_m1)\" and\n          r_x=\"diff_use_env (dir_subst_penv t_sub p_sub r_x1) (dir_subst_penv t_sub p_sub r_m1)\" in cancel_comp_use_env2)\n        apply (rule_tac dist_diff_leq_use_env)\n        apply (rule_tac env=\"env\" and e=\"e1\" and c_list=\"cl1\" in infer_x_leq_use_env)\n        apply (auto)\n    (* - proof of bound changes *)\n       apply (simp add: full_subst_type_def)\n      apply (rule_tac self_diff_leq_use_env)\n(*\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac self_comp_leq_use_env1)\n       apply (rule_tac comp_leq_use_env2)\n       apply (rule_tac self_diff_leq_use_env)\n      apply (rule_tac comp_leq_use_env1)\n      apply (rule_tac dist_diff_leq_use_env)\n      apply (rule_tac comp_leq_use_env2)\n      apply (rule_tac lift_leq_var_env)\n      apply (rule_tac id_leq_use_env)*)\n    (* - induction for e2. *)\n     apply (rule_tac x=\"diff_use_env (dir_subst_penv t_sub p_sub r_x2) (dir_subst_penv t_sub p_sub r_m2)\" in exI)\n     apply (cut_tac env=\"env\" and ds=\"ds2\" and e=\"e2\" and tau=\"t2\" and r_s=\"r_s2\" and r_x=\"r_x2\" and r_m=\"r_m2\" and\n        c_list=\"cl2\" and ds'=\"ds3\" and t_sub=\"t_sub\" and p_sub=\"p_sub\" and tau_n=\"tau_n\" in ivl_pair_ih)\n        apply (auto)\n            apply (simp add: full_subst_type_def)\n           apply (rule_tac sol_sat_append2)\n           apply (simp)\n          apply (simp add: comp_sol_subst_penv)\n    (* > reduce end perms *)\n          apply (rule_tac ?r_s2.0=\"diff_use_env (diff_use_env (comp_use_env\n              (comp_use_env (dir_subst_penv t_sub p_sub r_s1) (dir_subst_penv t_sub p_sub (lift_var_env r_x1 (SVar p))))\n              (comp_use_env (dir_subst_penv t_sub p_sub r_s2) (dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p))))) (dir_subst_penv t_sub p_sub r_m2))\n              (dir_subst_penv t_sub p_sub r_m1)\" and rx=\"diff_use_env (diff_use_env (dir_subst_penv t_sub p_sub r_x2)\n              (dir_subst_penv t_sub p_sub r_m2)) (dir_subst_penv t_sub p_sub r_m1)\" in well_typed_simul_end_perm)\n    (*\n           apply (rule_tac ?r_s2.0=\"diff_use_env (comp_use_env (comp_use_env (dir_subst_penv t_sub p_sub r_s1) (dir_subst_penv t_sub p_sub (lift_var_env r_x1 (SVar p))))\n              (diff_use_env (comp_use_env (dir_subst_penv t_sub p_sub r_s2) (dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p)))) (dir_subst_penv t_sub p_sub r_m2)))\n              (dir_subst_penv t_sub p_sub r_m1)\" and rx=\"diff_use_env (diff_use_env (dir_subst_penv t_sub p_sub r_x2)\n              (dir_subst_penv t_sub p_sub r_m2)) (dir_subst_penv t_sub p_sub r_m1)\" in well_typed_simul_end_perm)*)\n             apply (rule_tac well_typed_diff_perms)\n              apply (rule_tac well_typed_comp_perms_prec2)\n    (* - unroll lifts *)\n               apply (rule_tac t=\"dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p))\" and\n                s=\"lift_use_env (dir_subst_penv t_sub p_sub r_x2) (sol_subst_perm p_sub (SVar p))\" in subst)\n                apply (rule_tac lift_sol_subst_penv)\n               apply (rule_tac t=\"diff_use_env (comp_use_env (dir_subst_penv t_sub p_sub r_s2) (lift_use_env (dir_subst_penv t_sub p_sub r_x2) (sol_subst_perm p_sub (SVar p))))\n                (dir_subst_penv t_sub p_sub r_m2)\" and s=\"comp_use_env (diff_use_env (dir_subst_penv t_sub p_sub r_s2) (dir_subst_penv t_sub p_sub r_m2))\n                (diff_use_env (lift_use_env (dir_subst_penv t_sub p_sub r_x2) (sol_subst_perm p_sub (SVar p))) (dir_subst_penv t_sub p_sub r_m2))\" in subst)\n                apply (rule_tac dist_diff_comp_use_env)\n               apply (simp add: lift_diff_use_env)\n               apply (rule_tac well_typed_comp_lift_perms)\n    (* - cancellations *)\n                apply (cut_tac r_s=\"dir_subst_penv t_sub p_sub r_s2\" and r_x=\"dir_subst_penv t_sub p_sub r_x2\" in cancel_comp_use_env2)\n                 apply (rule_tac env=\"env\" and e=\"e2\" and c_list=\"cl2\" in infer_x_leq_use_env)\n                 apply (auto)\n                apply (cut_tac r_s=\"diff_use_env (dir_subst_penv t_sub p_sub r_s2) (dir_subst_penv t_sub p_sub r_m2)\" and\n                    r_x=\"diff_use_env (dir_subst_penv t_sub p_sub r_x2) (dir_subst_penv t_sub p_sub r_m2)\" in cancel_comp_use_env2)\n                 apply (rule_tac dist_diff_leq_use_env)\n                 apply (rule_tac env=\"env\" and e=\"e2\" and c_list=\"cl2\" in infer_x_leq_use_env)\n                apply (auto)\n               apply (simp add: full_subst_type_def)\n               apply (rule_tac self_diff_leq_use_env)\n    (* - disjointness used to remove r_s1 *)(*\n              apply (rule_tac comm_disj_use_env)\n              apply (simp)*)\n    (* - proving that r_m1 can be subtracted out *)\n             apply (simp add: own_env_vars_def)\n             apply (case_tac \"dir_subst_penv t_sub p_sub r_s2 x = NoPerm\")\n              apply (cut_tac e=\"e2\" and ?r_s1.0=\"dir_subst_penv t_sub p_sub r_s2\" and x=\"x\" in well_typed_no_npv_use)\n                apply (auto)(*\n             apply (case_tac \"dir_subst_penv t_sub p_sub r_s1 x \\<noteq> OwnPerm\")\n              apply (cut_tac r_x=\"dir_subst_penv t_sub p_sub r_m1\" and r_s=\"dir_subst_penv t_sub p_sub r_s1\" and x=\"x\" in leq_use_no_own)\n                apply (simp)\n               apply (rule_tac c_list=\"cl1\" in infer_m_leq_use_env)\n               apply (auto)\n             apply (cut_tac r_x=\"dir_subst_penv t_sub p_sub r_s1\" and r_s=\"comp_use_env (dir_subst_penv t_sub p_sub r_s1) (dir_subst_penv t_sub p_sub (lift_var_env r_x1 (SVar p)))\"\n                and r_ex=\"dir_subst_penv t_sub p_sub r_s2\" in disj_leq_use_env1)\n               apply (rule_tac r_s=\"comp_use_env (dir_subst_penv t_sub p_sub r_s2) (dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p)))\" in disj_leq_use_env2)\n                apply (simp)\n               apply (rule_tac self_comp_leq_use_env1)\n              apply (rule_tac self_comp_leq_use_env1)\n             apply (simp add: disj_use_env_def)*)\n             apply (simp add: mini_disj_use_env_def)\n    (* - end perm bounds correctness *)\n            apply (rule_tac lhs_flip_use_env)\n            apply (rule_tac lhs_unroll_dcl_use_env)\n            apply (rule_tac id_leq_use_env)\n    (*\n            apply (rule_tac dist_diff_leq_use_env)\n            apply (rule_tac dist_diff_leq_use_env)\n            apply (rule_tac lhs_dist_dcl_use_env)\n            apply (rule_tac dist_comp_leq_use_env)\n    apply (rule_tac self_diff_leq_use_env)\n             apply (rule_tac comp_leq_use_env1)\n             apply (rule_tac self_diff_leq_use_env)\n            apply (rule_tac self_comp_leq_use_env2)*)\n           apply (rule_tac rhs_unroll_dcl_use_env)\n           apply (rule_tac dist_diff_leq_use_env)\n           apply (rule_tac mini_disj_diff_leq_use_env2)\n            apply (rule_tac comp_leq_use_env2)\n            apply (rule_tac comp_leq_use_env2)\n            apply (rule_tac lift_leq_var_env)\n            apply (rule_tac id_leq_use_env)\n           apply (rule_tac r_s=\"dir_subst_penv t_sub p_sub r_s2\" in mini_disj_leq_use_env2)\n            apply (simp)\n           apply (rule_tac infer_x_leq_use_env)\n           apply (simp)(*\n            apply (rule_tac r_s=\"comp_use_env (dir_subst_penv t_sub p_sub r_s1) (dir_subst_penv t_sub p_sub (lift_var_env r_x1 (SVar p)))\" in disj_leq_use_env1)\n             apply (rule_tac r_s=\"comp_use_env (dir_subst_penv t_sub p_sub r_s2) (dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p)))\" in disj_leq_use_env2)\n              apply (simp)\n             apply (rule_tac comp_leq_use_env2)\n             apply (rule_tac lift_leq_var_env)\n             apply (rule_tac id_leq_use_env)\n            apply (rule_tac comp_leq_use_env1)\n            apply (rule_tac e=\"e1\" and c_list=\"cl1\" in infer_m_leq_use_env)\n            apply (simp)\n           apply (rule_tac comp_leq_use_env2)\n           apply (rule_tac comp_leq_use_env2)\n           apply (rule_tac lift_leq_var_env)\n           apply (rule_tac id_leq_use_env)*)\n          apply (rule_tac self_diff_leq_use_env)\n      (* - native permission bound constraint e1 *)\n         apply (rule_tac t=\"lift_use_env (diff_use_env (dir_subst_penv t_sub p_sub r_x1) (dir_subst_penv t_sub p_sub r_m1)) (p_sub p)\" and\n          s=\"diff_use_env (lift_use_env (dir_subst_penv t_sub p_sub r_x1) (p_sub p)) (dir_subst_penv t_sub p_sub r_m1)\" in subst)\n          apply (rule_tac lift_diff_use_env)\n         apply (simp add: comp_sol_subst_penv)\n         apply (rule_tac rhs_unroll_dcl_use_env)\n         apply (rule_tac mini_disj_diff_leq_use_env2)\n          apply (simp add: lift_sol_subst_penvx)\n          apply (rule_tac dist_diff_leq_use_env)\n          apply (rule_tac comp_leq_use_env1)\n          apply (rule_tac self_comp_leq_use_env2)\n         apply (rule_tac r_s=\"lift_use_env (dir_subst_penv t_sub p_sub r_x1) (p_sub p)\" in mini_disj_leq_use_env2)\n          apply (rule_tac mini_disj_lift_use_env_rev)\n          apply (simp)\n         apply (rule_tac self_diff_leq_use_env)(*      \n          apply (rule_tac r_s=\"comp_use_env (dir_subst_penv t_sub p_sub r_s2) (dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p)))\" in disj_leq_use_env1)\n           apply (rule_tac r_s=\"comp_use_env (dir_subst_penv t_sub p_sub r_s1) (dir_subst_penv t_sub p_sub (lift_var_env r_x1 (SVar p)))\" in disj_leq_use_env2)\n            apply (rule_tac comm_disj_use_env)\n            apply (simp)\n           apply (simp add: lift_sol_subst_penvx)\n           apply (rule_tac diff_leq_use_env)\n           apply (rule_tac self_comp_leq_use_env2)\n          apply (rule_tac comp_leq_use_env1)\n          apply (rule_tac c_list=\"cl2\" in infer_m_leq_use_env)\n          apply (simp)\n         apply (rule_tac dist_diff_leq_use_env)\n         apply (simp add: lift_sol_subst_penvx)\n         apply (rule_tac comp_leq_use_env1)\n         apply (rule_tac self_comp_leq_use_env2)*)\n      (* - native permission bound constraint e2 *)\n        apply (rule_tac t=\"lift_use_env (diff_use_env (dir_subst_penv t_sub p_sub r_x2) (dir_subst_penv t_sub p_sub r_m2)) (p_sub p)\" and\n          s=\"diff_use_env (lift_use_env (dir_subst_penv t_sub p_sub r_x2) (p_sub p)) (dir_subst_penv t_sub p_sub r_m2)\" in subst)\n         apply (rule_tac lift_diff_use_env)\n        apply (simp add: comp_sol_subst_penv)\n        apply (rule_tac rhs_unroll_dcl_use_env)\n        apply (rule_tac dist_diff_leq_use_env)\n        apply (rule_tac mini_disj_diff_leq_use_env2)\n         apply (simp add: lift_sol_subst_penvx)\n         apply (rule_tac comp_leq_use_env2)\n         apply (rule_tac self_comp_leq_use_env2)\n        apply (rule_tac mini_disj_lift_use_env_rev)\n        apply (rule_tac r_s=\"dir_subst_penv t_sub p_sub r_s2\" in mini_disj_leq_use_env2)\n         apply (simp)\n        apply (rule_tac infer_x_leq_use_env)\n        apply (simp)(*\n         apply (rule_tac r_s=\"comp_use_env (dir_subst_penv t_sub p_sub r_s2) (dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p)))\" in disj_leq_use_env2)\n          apply (rule_tac r_s=\"comp_use_env (dir_subst_penv t_sub p_sub r_s1) (dir_subst_penv t_sub p_sub (lift_var_env r_x1 (SVar p)))\" in disj_leq_use_env1)\n           apply (simp)\n          apply (rule_tac comp_leq_use_env1)\n          apply (rule_tac c_list=\"cl1\" in infer_m_leq_use_env)\n          apply (simp)\n         apply (simp add: lift_sol_subst_penvx)\n         apply (rule_tac self_comp_leq_use_env2)\n        apply (rule_tac comp_leq_use_env2)\n        apply (simp add: lift_sol_subst_penvx)\n        apply (rule_tac self_comp_leq_use_env2)*)\n    (* - affinity requirements *)\n       apply (rule_tac max_aff_leq)\n        apply (rule_tac dir_aff_leq)\n         apply (simp_all)\n       apply (rule_tac tau=\"tau_xa\" in dir_aff_leq)\n        apply (simp_all)\n    (* - disjointness requirement *)\n      apply (rule_tac r_s=\"dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p))\" in disj_leq_use_env2)\n       apply (rule_tac r_s=\"dir_subst_penv t_sub p_sub (lift_var_env r_x1 (SVar p))\" in disj_leq_use_env1)\n        apply (simp)\n       apply (rule_tac t=\"dir_subst_penv t_sub p_sub (lift_var_env r_x1 (SVar p))\" and\n          s=\"lift_use_env (dir_subst_penv t_sub p_sub r_x1) (p_sub p)\" in subst)\n        apply (rule_tac lift_sol_subst_penvx)\n       apply (rule_tac dist_lift_leq_use_env)\n       apply (rule_tac self_diff_leq_use_env)\n      apply (rule_tac t=\"dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p))\" and\n          s=\"lift_use_env (dir_subst_penv t_sub p_sub r_x2) (p_sub p)\" in subst)\n       apply (rule_tac lift_sol_subst_penvx)\n      apply (rule_tac dist_lift_leq_use_env)\n      apply (rule_tac self_diff_leq_use_env)\n(*\n      apply (rule_tac r_s=\"comp_use_env (dir_subst_penv t_sub p_sub r_s2) (dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p)))\" in disj_leq_use_env2)\n       apply (rule_tac r_s=\"comp_use_env (dir_subst_penv t_sub p_sub r_s1) (dir_subst_penv t_sub p_sub (lift_var_env r_x1 (SVar p)))\" in disj_leq_use_env1)\n        apply (simp add: comp_sol_subst_penv)\n       apply (rule_tac t=\"dir_subst_penv t_sub p_sub (lift_var_env r_x1 (SVar p))\" and\n          s=\"lift_use_env (dir_subst_penv t_sub p_sub r_x1) (p_sub p)\" in subst)\n        apply (rule_tac lift_sol_subst_penvx)\n       apply (rule_tac comp_leq_use_env2)\n       apply (rule_tac dist_lift_leq_use_env)\n       apply (rule_tac self_diff_leq_use_env)\n      apply (rule_tac comp_leq_use_env2)\n      apply (rule_tac t=\"dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p))\" and\n          s=\"lift_use_env (dir_subst_penv t_sub p_sub r_x2) (p_sub p)\" in subst)\n       apply (rule_tac lift_sol_subst_penvx)\n      apply (rule_tac dist_lift_leq_use_env)\n      apply (rule_tac self_diff_leq_use_env)*)\n    (* - final existential *)\n     apply (rule_tac x=\"dir_subst_penv t_sub p_sub (comp_var_env r_m1 r_m2)\" in exI)\n     apply (auto)\n        apply (rule_tac rhs_diff_leq_use_env)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac dist_diff_leq_use_env)\n       apply (rule_tac if_zero_leq_var_env)\n       apply (rule_tac dist_comp_leq_var_env)\n        apply (rule_tac comp_leq_var_env1)\n        apply (rule_tac comp_leq_var_env2)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac comp_leq_var_env2)\n       apply (rule_tac comp_leq_var_env2)\n       apply (rule_tac id_leq_use_env)\n      apply (rule_tac dist_comp_leq_var_env)\n       apply (rule_tac comp_leq_var_env1)\n       apply (rule_tac comp_leq_var_env1)\n       apply (rule_tac c_list=\"cl1\" in infer_m_leq_use_env)\n       apply (auto)\n      apply (rule_tac comp_leq_var_env2)\n      apply (rule_tac comp_leq_var_env1)\n      apply (rule_tac c_list=\"cl2\" in infer_m_leq_use_env)\n      apply (simp)\n     apply (simp add: pair_req_def)\n     apply (auto)\n      apply (rule_tac leq_empty_use_env)\n     apply (case_tac \"sol_subst_perm p_sub (SVar p) = NoPerm\")\n      apply (simp)\n     apply (simp add: if_zero_pos_var_env)\n     apply (rule_tac dist_diff_leq_use_env)\n     apply (simp add: comp_sol_subst_penv)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac comp_leq_use_env1)\n      apply (rule_tac t=\"dir_subst_penv t_sub p_sub (lift_var_env r_x1 (SVar p))\" and\n        s=\"lift_use_env (dir_subst_penv t_sub p_sub r_x1) (p_sub p)\" in subst)\n       apply (rule_tac lift_sol_subst_penvx)\n      apply (rule_tac dist_lift_leq_use_env)\n      apply (rule_tac self_diff_leq_use_env)\n     apply (rule_tac comp_leq_use_env2)\n     apply (rule_tac t=\"dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p))\" and\n        s=\"lift_use_env (dir_subst_penv t_sub p_sub r_x2) (p_sub p)\" in subst)\n      apply (rule_tac lift_sol_subst_penvx)\n     apply (rule_tac dist_lift_leq_use_env)\n     apply (rule_tac self_diff_leq_use_env)\n    (* if case. prelim: satisfiability sub-constraints *)\n    apply (cut_tac p_sub=\"p_sub\" and ?cl2.0=\"cl1 @ cl2 @ cl3\" in sol_sat_append2)\n     apply (simp)\n    apply (cut_tac p_sub=\"p_sub\" and ?cl2.0=\"cl2 @ cl3\" in sol_sat_append2)\n     apply (simp)\n    (* - prelim: disjointness constraints *)\n    apply (cut_tac p_sub=\"p_sub\" and r_x=\"r_m1\" and r_s=\"comp_var_env r_s2 r_s3\" in sol_sat_mini_disj_use_env)\n       apply (rule_tac sol_sat_append1)\n       apply (simp)\n      apply (rule_tac r_s=\"comp_var_env r_s1 (comp_var_env r_s2 r_s3)\" in finite_sub_dom)\n       apply (simp)\n      apply (rule_tac comp_sub_dom1)\n      apply (rule_tac infer_m_sub_dom)\n      apply (auto)\n     apply (rule_tac r_s=\"comp_var_env r_s1 (comp_var_env r_s2 r_s3)\" in finite_sub_dom)\n      apply (simp)\n     apply (rule_tac comp_sub_dom2)\n     apply (rule_tac id_sub_dom)\n    (* - induction on e1 *)\n    apply (rule_tac x=\"diff_use_env (dir_subst_penv t_sub p_sub r_x1) (dir_subst_penv t_sub p_sub r_m1)\" in exI)\n    apply (rule_tac x=\"diff_use_env (dir_subst_penv t_sub p_sub (comp_var_env r_s1 (comp_var_env r_s2 r_s3))) (dir_subst_penv t_sub p_sub r_m1)\" in exI)\n    apply (auto)\n     apply (rule_tac t=\"dir_subst_penv t_sub p_sub (comp_var_env r_s1 (comp_var_env r_s2 r_s3))\"\n      and s=\"comp_use_env (dir_subst_penv t_sub p_sub r_s1) (dir_subst_penv t_sub p_sub (comp_var_env r_s2 r_s3))\" in subst)\n      apply (simp add: comp_sol_subst_penv)\n    apply (cut_tac env=\"env\" and ds=\"ds\" and e=\"e1\" and tau=\"t1\" and r_s=\"r_s1\" and r_x=\"r_x1\" and r_m=\"r_m1\" and\n        c_list=\"cl1\" and ds'=\"ds2\" and t_sub=\"t_sub\" and p_sub=\"p_sub\" and tau_n=\"tau_n\" in ivl_if_ih)\n        apply (auto)\n      apply (rule_tac sol_sat_append1)\n      apply (simp)\n     apply (rule_tac well_typed_comp_perms_prec)\n     apply (case_tac t1)\n            apply (auto)\n      apply (simp add: full_subst_type_def)\n     apply (simp add: full_subst_type_def)\n    (* - induction on e2 *)\n    apply (rule_tac x=\"diff_use_env (dir_subst_penv t_sub p_sub r_x2) (dir_subst_penv t_sub p_sub (comp_var_env r_m1 (comp_var_env r_m2 r_m3)))\" in exI)\n    apply (auto)\n     apply (simp add: comp_sol_subst_penv)\n     apply (cut_tac env=\"env\" and ds=\"ds2\" and e=\"e2\" and tau=\"t2\" and r_s=\"r_s2\" and r_x=\"r_x2\" and r_m=\"r_m2\" and\n        c_list=\"cl2\" and ds'=\"ds3\" and t_sub=\"t_sub\" and p_sub=\"p_sub\" and tau_n=\"tau_n\" in ivl_if_ih)\n        apply (auto)\n      apply (rule_tac sol_sat_append1)\n      apply (simp)\n     apply (rule_tac ?r_s2.0=\"diff_use_env (diff_use_env (comp_use_env (diff_use_env (dir_subst_penv t_sub p_sub r_s1)\n        (dir_subst_penv t_sub p_sub r_m1)) (comp_use_env (dir_subst_penv t_sub p_sub r_s2) (dir_subst_penv t_sub p_sub r_s3)))\n        (dir_subst_penv t_sub p_sub r_m2)) (dir_subst_penv t_sub p_sub r_m3)\" and rx=\"diff_use_env (diff_use_env (dir_subst_penv t_sub p_sub r_x2)\n        (dir_subst_penv t_sub p_sub r_m2)) (dir_subst_penv t_sub p_sub r_m3)\" in well_typed_simul_end_perm)\n        apply (rule_tac ?r_s1.0=\"comp_use_env (diff_use_env (dir_subst_penv t_sub p_sub r_s1) (dir_subst_penv t_sub p_sub r_m1))\n          (comp_use_env (dir_subst_penv t_sub p_sub r_s2) (dir_subst_penv t_sub p_sub r_s3))\" in well_typed_incr_start_perm)\n         apply (rule_tac well_typed_diff_end_perm)\n          apply (rule_tac well_typed_comp_perms_prec2)\n          apply (rule_tac well_typed_comp_perms_prec)\n          apply (simp_all)\n         apply (rule_tac comp_leq_use_env2)\n         apply (rule_tac comp_leq_use_env2)\n         apply (rule_tac infer_m_leq_use_env)\n         apply (auto)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (rule_tac dist_diff_leq_use_env)\n         apply (rule_tac self_comp_leq_use_env1)\n        apply (rule_tac rhs_dist_dcl_use_env)\n        apply (rule_tac comp_leq_use_env2)\n        apply (rule_tac mini_disj_diff_leq_use_env2)\n         apply (rule_tac id_leq_use_env)\n        apply (simp)\n       apply (rule_tac lhs_dist_dcl_use_env)\n       apply (rule_tac rhs_fold_dcl_use_env)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac lhs_unroll_dcl_use_env)\n        apply (rule_tac dist_diff_leq_use_env)\n        apply (rule_tac self_comp_leq_use_env1)\n       apply (rule_tac dist_diff_leq_use_env_gen)\n        apply (rule_tac self_comp_leq_use_env2)\n       apply (rule_tac self_comp_leq_use_env2)\n      apply (rule_tac dist_diff_leq_use_env)\n      apply (rule_tac comp_leq_use_env2)\n      apply (rule_tac comp_leq_use_env1)\n      apply (rule_tac c_list=\"cl2\" in infer_x_leq_use_env)\n      apply (simp)\n     apply (rule_tac lhs_fold_dcl_use_env)\n     apply (rule_tac rhs_unroll_dcl_use_env)\n     apply (rule_tac dist_diff_leq_use_env)\n     apply (rule_tac mini_disj_diff_leq_use_env2)\n      apply (rule_tac id_leq_use_env)\n     apply (rule_tac r_s=\"comp_use_env (dir_subst_penv t_sub p_sub r_s2) (dir_subst_penv t_sub p_sub r_s3)\" in mini_disj_leq_use_env2)\n      apply (simp)\n     apply (rule_tac comp_leq_use_env1)\n     apply (rule_tac c_list=\"cl2\" in infer_x_leq_use_env)\n     apply (simp)\n      (* - induction on e3 *)\n    apply (rule_tac x=\"diff_use_env (dir_subst_penv t_sub p_sub r_x3) (dir_subst_penv t_sub p_sub (comp_var_env r_m1 (comp_var_env r_m2 r_m3)))\" in exI)\n    apply (auto)\n     apply (simp add: comp_sol_subst_penv)\n     apply (cut_tac env=\"env\" and ds=\"ds3\" and e=\"e3\" and tau=\"t3\" and r_s=\"r_s3\" and r_x=\"r_x3\" and r_m=\"r_m3\" and\n        c_list=\"cl3\" and ds'=\"ds'\" and t_sub=\"t_sub\" and p_sub=\"p_sub\" and tau_n=\"tau_n\" in ivl_if_ih)\n        apply (auto)\n      apply (rule_tac sol_sat_append2)\n      apply (simp)\n     apply (rule_tac ?r_s2.0=\"diff_use_env (diff_use_env (comp_use_env (diff_use_env (dir_subst_penv t_sub p_sub r_s1)\n        (dir_subst_penv t_sub p_sub r_m1)) (comp_use_env (dir_subst_penv t_sub p_sub r_s2) (dir_subst_penv t_sub p_sub r_s3)))\n        (dir_subst_penv t_sub p_sub r_m3)) (dir_subst_penv t_sub p_sub r_m2)\" and rx=\"diff_use_env (diff_use_env (dir_subst_penv t_sub p_sub r_x3)\n        (dir_subst_penv t_sub p_sub r_m3)) (dir_subst_penv t_sub p_sub r_m2)\" in well_typed_simul_end_perm)\n        apply (rule_tac ?r_s1.0=\"comp_use_env (diff_use_env (dir_subst_penv t_sub p_sub r_s1) (dir_subst_penv t_sub p_sub r_m1))\n          (comp_use_env (dir_subst_penv t_sub p_sub r_s2) (dir_subst_penv t_sub p_sub r_s3))\" in well_typed_incr_start_perm)\n         apply (rule_tac well_typed_diff_end_perm)\n          apply (rule_tac well_typed_comp_perms_prec2)\n          apply (rule_tac well_typed_comp_perms_prec2)\n          apply (simp add: dir_subst_type_eq)\n         apply (rule_tac comp_leq_use_env2)\n         apply (rule_tac comp_leq_use_env1)\n         apply (rule_tac infer_m_leq_use_env)\n         apply (auto)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (rule_tac dist_diff_leq_use_env)\n         apply (rule_tac self_comp_leq_use_env1)\n        apply (rule_tac mini_disj_diff_leq_use_env2)\n         apply (rule_tac self_comp_leq_use_env2)\n        apply (simp)\n       apply (rule_tac lhs_dist_dcl_use_env)\n       apply (rule_tac rhs_fold_dcl_use_env)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac lhs_unroll_dcl_use_env)\n        apply (rule_tac dist_diff_leq_use_env_gen)\n         apply (rule_tac self_comp_leq_use_env1)\n        apply (simp add: comm_comp_use_env)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac dist_diff_leq_use_env_gen)\n        apply (rule_tac self_comp_leq_use_env2)\n       apply (simp add: comm_comp_use_env)\n       apply (rule_tac self_comp_leq_use_env2)\n      apply (rule_tac dist_diff_leq_use_env)\n      apply (rule_tac comp_leq_use_env2)\n      apply (rule_tac comp_leq_use_env2)\n      apply (rule_tac infer_x_leq_use_env)\n      apply (auto)\n     apply (rule_tac lhs_fold_dcl_use_env)\n     apply (simp add: comm_comp_use_env)\n     apply (rule_tac rhs_unroll_dcl_use_env)\n     apply (rule_tac dist_diff_leq_use_env_gen)\n      apply (rule_tac mini_disj_diff_leq_use_env2)\n       apply (rule_tac id_leq_use_env)\n      apply (rule_tac r_s=\"comp_use_env (dir_subst_penv t_sub p_sub r_s2) (dir_subst_penv t_sub p_sub r_s3)\" in mini_disj_leq_use_env2)\n       apply (simp)\n      apply (rule_tac comp_leq_use_env2)\n      apply (rule_tac infer_x_leq_use_env)\n      apply (auto)\n     apply (rule_tac id_leq_use_env)\n    apply (simp add: dist_diff_comp_use_env)\n    apply (simp add: comp_sol_subst_penv)\n    (* lam case *)\n   apply (simp add: full_subst_type_def)\n   apply (rule_tac x=\"dir_subst_penv t_sub p_sub (rem_var_env r_s' (Var x1a))\" in exI)\n   apply (auto)\n    (* - induction on e *)\n      apply (cut_tac env=\"add_env env (Var x1a) a\" and ds=\"insert a ds\" and e=\"e\" and tau=\"t2\" and r_s=\"r_s'\" and r_x=\"r_x'\" and r_m=\"r_m'\" and\n        c_list=\"cl\" and ds'=\"ds2\" and t_sub=\"t_sub\" and p_sub=\"p_sub\" and tau_n=\"tau_n\" in ivl_lam_ih)\n         apply (auto)\n        apply (simp add: full_subst_type_def)\n       apply (rule_tac sol_sat_append2)\n       apply (simp)\n      apply (rule_tac x=\"diff_use_env (dir_subst_penv t_sub p_sub r_x') (dir_subst_penv t_sub p_sub r_m')\" in exI)\n      apply (rule_tac x=\"diff_use_env (dir_subst_penv t_sub p_sub r_s') (dir_subst_penv t_sub p_sub r_m')\" in exI)\n      apply (simp add: rem_sol_subst_penv)\n      apply (rule_tac ?r_s1.0=\"add_use_env (rem_use_env (dir_subst_penv t_sub p_sub r_s') (Var x1a)) (Var x1a)\n        (dir_subst_permx t_sub p_sub (r_s' (Var x1a)))\" in well_typed_incr_start_perm)\n       apply (case_tac \"dir_subst_permx t_sub p_sub (r_s' (Var x1a)) \\<noteq> (dir_subst_penv t_sub p_sub r_s') (Var x1a)\")\n        apply (simp add: dir_subst_penv_def)\n       apply (simp add: add_rem_use_env)\n       apply (cut_tac t_sub=\"t_sub\" and tau_n=\"tau_n\" and x=\"x1a\" and env=\"env\" and a=\"a\" and p_sub=\"p_sub\" in add_sol_subst_tenv)\n       apply (simp add: full_subst_type_def)\n      apply (rule_tac dist_add_leq_use_env_gen)\n       apply (rule_tac id_leq_use_env)\n      apply (simp)\n     apply (rule_tac sol_sat_aff_use_envx)\n      apply (rule_tac sol_sat_append1)\n      apply (simp_all)\n    apply (rule_tac id_leq_use_env)\n   apply (rule_tac x=\"empty_use_env\" in exI)\n   apply (auto)\n      apply (simp add: subst_empty_var_env)\n      apply (rule_tac id_leq_use_env)\n     apply (rule_tac id_leq_use_env)\n    apply (rule_tac leq_empty_use_env)\n   apply (simp add: subst_empty_var_env)\n   apply (rule_tac id_leq_use_env)\n    (* app case. prelim: satisfiability constraints *)\n  apply (cut_tac p_sub=\"p_sub\" and ?cl2.0=\"semi_disj_crn r_m2 r_x1 d @ semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2\" in sol_sat_append2)\n   apply (simp)\n  apply (cut_tac p_sub=\"p_sub\" and ?cl2.0=\"semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2\" in sol_sat_append2)\n   apply (simp)\n  apply (cut_tac p_sub=\"p_sub\" and ?cl2.0=\"cl1 @ cl2\" in sol_sat_append2)\n   apply (simp)\n    (* - prelim: disjointness constraints *)\n  apply (cut_tac p_sub=\"p_sub\" in sol_sat_disj_use_env)\n     apply (rule_tac sol_sat_append1)\n     apply (simp)\n    apply (rule_tac r_s=\"comp_var_env (comp_var_env r_s1 r_x1) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))\" in finite_sub_dom)\n     apply (simp)\n    apply (rule_tac comp_sub_dom1)\n    apply (rule_tac comp_sub_dom2)\n    apply (rule_tac id_sub_dom)\n   apply (rule_tac r_s=\"comp_var_env (comp_var_env r_s1 r_x1) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))\" in finite_sub_dom)\n    apply (simp)\n   apply (rule_tac comp_sub_dom2)\n   apply (rule_tac comp_sub_dom2)\n   apply (rule_tac id_sub_dom)\n    (* - prelim: semi-disjointness constraint 1 *)\n  apply (cut_tac r_x=\"r_m2\" and r_s=\"r_x1\" and p_sub=\"p_sub\" in sol_sat_mini_disj_use_env)\n     apply (rule_tac sol_sat_append1)\n     apply (simp)\n      apply (rule_tac r_s=\"comp_var_env (comp_var_env r_s1 r_x1) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))\" in finite_sub_dom)\n       apply (simp)\n      apply (rule_tac comp_sub_dom2)\n      apply (rule_tac comp_sub_dom1)\n      apply (rule_tac infer_m_sub_dom)\n      apply (simp)\n     apply (rule_tac r_s=\"comp_var_env (comp_var_env r_s1 r_x1) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))\" in finite_sub_dom)\n      apply (simp)\n     apply (rule_tac comp_sub_dom1)\n     apply (rule_tac comp_sub_dom2)\n     apply (rule_tac id_sub_dom)\n    (* - prelim: semi-disjointness constraint 2 *)\n  apply (cut_tac r_x=\"r_m1\" and r_s=\"r_s2\" and p_sub=\"p_sub\" in sol_sat_mini_disj_use_env)\n     apply (rule_tac sol_sat_append1)\n     apply (simp)\n      apply (rule_tac r_s=\"comp_var_env (comp_var_env r_s1 r_x1) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))\" in finite_sub_dom)\n       apply (simp)\n      apply (rule_tac comp_sub_dom1)\n      apply (rule_tac comp_sub_dom1)\n      apply (rule_tac infer_m_sub_dom)\n      apply (simp)\n     apply (rule_tac r_s=\"comp_var_env (comp_var_env r_s1 r_x1) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))\" in finite_sub_dom)\n      apply (simp)\n     apply (rule_tac comp_sub_dom2)\n     apply (rule_tac comp_sub_dom1)\n     apply (rule_tac id_sub_dom)   \n    (* - prelim: inequalities *)(*\n  apply (cut_tac c_list=\"cl1\" and r_m=\"r_m1\" and r_s=\"r_s1\" and t_sub=\"t_sub\" and p_sub=\"p_sub\" in infer_m_leq_use_env)\n   apply (simp)\n  apply (cut_tac r_x=\"r_m2\" and r_s=\"r_s2\" and r=\"SVar p\" and t_sub=\"t_sub\" and p_sub=\"p_sub\" in lift_leq_var_env)\n   apply (rule_tac c_list=\"cl2\" in infer_m_leq_use_env)\n   apply (simp)*)\n  apply (cut_tac c_list=\"cl1\" and r_x=\"r_x1\" and r_s=\"r_s1\" and t_sub=\"t_sub\" and p_sub=\"p_sub\" in infer_x_leq_use_env)\n   apply (simp)\n  apply (cut_tac c_list=\"cl2\" and r_x=\"r_x2\" and r_s=\"r_s2\" and t_sub=\"t_sub\" and p_sub=\"p_sub\" in infer_x_leq_use_env)\n   apply (simp)\n  apply (cut_tac r_x=\"r_x2\" and r_s=\"r_s2\" and r=\"SVar p\" in lift_leq_var_env)\n    apply (simp)\n    (* - existentials *)\n  apply (rule_tac x=\"full_subst_type t_sub p_sub tau_n t1\" in exI)\n  apply (rule_tac x=\"sol_subst_perm p_sub (SVar p)\" in exI)\n  apply (rule_tac x=\"sol_subst_aff p_sub (AffVar q)\" in exI)\n  apply (rule_tac x=\"diff_use_env (dir_subst_penv t_sub p_sub (comp_var_env (comp_var_env r_s1 r_x1)\n      (comp_var_env r_s2 (lift_var_env r_x2 (SVar p))))) (dir_subst_penv t_sub p_sub r_m1)\" in exI)\n  apply (rule_tac x=\"diff_use_env (dir_subst_penv t_sub p_sub r_x1) (dir_subst_penv t_sub p_sub r_m1)\" in exI)\n  apply (auto)\n    (* - induction for e1. *)\n  apply (simp add: comp_sol_subst_penv)\n   apply (cut_tac env=\"env\" and ds=\"ds\" and e=\"e1\" and tau=\"tau_f\" and r_s=\"r_s1\" and r_x=\"r_x1\" and r_m=\"r_m1\" and\n        c_list=\"cl1\" and ds'=\"ds2\" and t_sub=\"t_sub\" and p_sub=\"p_sub\" and tau_n=\"tau_n\" in ivl_app_ih)\n      apply (auto)\n    apply (rule_tac sol_sat_append1)\n    apply (simp)\n   apply (rule_tac well_typed_comp_perms_prec)\n   apply (rule_tac well_typed_comp_perms_prec)\n   apply (simp add: dir_subst_type_eq)\n    (* - induction for e2. *)\n  apply (rule_tac x=\"diff_use_env (dir_subst_penv t_sub p_sub r_x2) (dir_subst_penv t_sub p_sub r_m2)\" in exI)\n  apply (rule_tac x=\"diff_use_env (diff_use_env (dir_subst_penv t_sub p_sub (comp_var_env (comp_var_env r_s1 r_x1)\n      (comp_var_env r_s2 (lift_var_env r_x2 (SVar p))))) (dir_subst_penv t_sub p_sub r_m1)) (dir_subst_penv t_sub p_sub r_m2)\" in exI)\n  apply (auto)\n   apply (simp add: comp_sol_subst_penv)\n   apply (cut_tac env=\"env\" and ds=\"ds2\" and e=\"e2\" and tau=\"t1\" and r_s=\"r_s2\" and r_x=\"r_x2\" and r_m=\"r_m2\" and\n        c_list=\"cl2\" and ds'=\"ds3\" and t_sub=\"t_sub\" and p_sub=\"p_sub\" and tau_n=\"tau_n\" in ivl_app_ih)\n      apply (auto)\n    apply (rule_tac sol_sat_append2)\n    apply (simp) \n   apply (rule_tac r_c=\"diff_use_env (comp_use_env (diff_use_env (comp_use_env (dir_subst_penv t_sub p_sub r_s1) (dir_subst_penv t_sub p_sub r_x1))\n      (dir_subst_penv t_sub p_sub r_m1)) (comp_use_env (dir_subst_penv t_sub p_sub r_s2) (dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p)))))\n                (dir_subst_penv t_sub p_sub r_m2)\" in well_typed_decr_end_perm)\n     apply (rule_tac ?r_s1.0=\"comp_use_env (diff_use_env (comp_use_env (dir_subst_penv t_sub p_sub r_s1) (dir_subst_penv t_sub p_sub r_x1))\n      (dir_subst_penv t_sub p_sub r_m1)) (comp_use_env (dir_subst_penv t_sub p_sub r_s2) (dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p))))\" in well_typed_incr_start_perm)\n      apply (rule_tac well_typed_comp_perms_prec2)\n      apply (rule_tac well_typed_comp_perms_prec)\n      apply (simp)\n     apply (rule_tac rhs_dist_dcl_use_env)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac self_comp_leq_use_env1)\n     apply (rule_tac comp_leq_use_env2)\n     apply (rule_tac mini_disj_diff_leq_use_env)\n      apply (rule_tac id_leq_use_env)\n     apply (rule_tac mini_disj_comp_use_env_alt)\n      apply (simp)\n     apply (rule_tac t=\"dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p))\" and\n        s=\"lift_use_env (dir_subst_penv t_sub p_sub r_x2) (sol_subst_perm p_sub (SVar p))\" in subst)\n      apply (rule_tac lift_sol_subst_penv)\n     apply (rule_tac mini_disj_lift_use_env_rev)\n     apply (rule_tac r_s=\"dir_subst_penv t_sub p_sub r_s2\" in mini_disj_leq_use_env2)\n      apply (simp_all)\n    apply (rule_tac dist_diff_leq_use_env)\n    apply (rule_tac lhs_dist_dcl_use_env)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (rule_tac self_comp_leq_use_env1)\n    apply (rule_tac comp_leq_use_env2)\n    apply (rule_tac self_diff_leq_use_env)\n   apply (rule_tac dist_diff_leq_use_env)\n   apply (rule_tac mini_disj_diff_leq_use_env2)\n    apply (rule_tac comp_leq_use_env2)\n    apply (rule_tac comp_leq_use_env2)\n    apply (rule_tac lift_leq_var_env)\n    apply (rule_tac id_leq_use_env)\n   apply (rule_tac r_s=\"dir_subst_penv t_sub p_sub r_s2\" in mini_disj_leq_use_env2)\n    apply (simp_all)\n    (* - final existentials. *)\n  apply (rule_tac x=\"dir_subst_penv t_sub p_sub (comp_var_env (comp_var_env r_m1 r_x1) (comp_var_env r_m2 (lift_var_env r_x2 (SVar p))))\" in exI)\n  apply (simp add: comp_sol_subst_penv)\n  apply (auto)\n    (* - end permission bound *)\n       apply (rule_tac rhs_fold_dcl_use_env)\n       apply (rule_tac rhs_fold_dcl_use_env)\n       apply (rule_tac dist_diff_leq_use_env_gen)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac t=\"dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p))\" and\n        s=\"lift_use_env (dir_subst_penv t_sub p_sub r_x2) (sol_subst_perm p_sub (SVar p))\" in subst)\n        apply (rule_tac lift_sol_subst_penv)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac comp_leq_use_env1)\n        apply (rule_tac self_comp_leq_use_env1)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac comp_leq_use_env2)\n        apply (rule_tac self_comp_leq_use_env1)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (rule_tac comp_leq_use_env1)\n         apply (rule_tac comp_leq_use_env2)\n         apply (rule_tac self_diff_leq_use_env)\n        apply (rule_tac comp_leq_use_env2)\n        apply (rule_tac comp_leq_use_env2)\n        apply (auto)\n        apply (rule_tac dist_lift_leq_use_env)\n        apply (rule_tac self_diff_leq_use_env)\n       apply (rule_tac id_leq_use_env)\n    (* - subtractability bound *)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (rule_tac mini_disj_diff_leq_use_env2)\n        apply (rule_tac dist_diff_leq_use_env)\n        apply (rule_tac comp_leq_use_env1)\n        apply (rule_tac self_comp_leq_use_env2)\n       apply (rule_tac r_s=\"dir_subst_penv t_sub p_sub r_x1\" in mini_disj_leq_use_env2)\n        apply (simp)\n       apply (rule_tac self_diff_leq_use_env)\n      apply (rule_tac t=\"lift_use_env (diff_use_env (dir_subst_penv t_sub p_sub r_x2) (dir_subst_penv t_sub p_sub r_m2)) (p_sub p)\"\n        and s=\"diff_use_env (lift_use_env (dir_subst_penv t_sub p_sub r_x2) (p_sub p)) (dir_subst_penv t_sub p_sub r_m2)\" in subst)\n       apply (rule_tac lift_diff_use_env)\n      apply (rule_tac dist_diff_leq_use_env)\n       apply (rule_tac t=\"dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p))\" and\n        s=\"lift_use_env (dir_subst_penv t_sub p_sub r_x2) (sol_subst_perm p_sub (SVar p))\" in subst)\n       apply (rule_tac lift_sol_subst_penv)\n      apply (auto)\n      apply (rule_tac mini_disj_diff_leq_use_env2)\n       apply (rule_tac comp_leq_use_env2)\n       apply (rule_tac self_comp_leq_use_env2)\n      apply (rule_tac mini_disj_lift_use_env_rev)\n      apply (rule_tac r_s=\"dir_subst_penv t_sub p_sub r_s2\" in mini_disj_leq_use_env2)\n       apply (simp)\n      apply (rule_tac infer_x_leq_use_env)\n      apply (simp)\n    (* - disjointness *)\n     apply (rule_tac r_s=\"dir_subst_penv t_sub p_sub r_x1\" in disj_leq_use_env1)\n      apply (rule_tac r_s=\"dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p))\" in disj_leq_use_env2)\n       apply (simp)\n      apply (rule_tac t=\"dir_subst_penv t_sub p_sub (lift_var_env r_x2 (SVar p))\" and\n        s=\"lift_use_env (dir_subst_penv t_sub p_sub r_x2) (sol_subst_perm p_sub (SVar p))\" in subst)\n       apply (rule_tac lift_sol_subst_penv)\n      apply (auto)\n      apply (rule_tac dist_lift_leq_use_env)\n      apply (rule_tac self_diff_leq_use_env)\n     apply (rule_tac self_diff_leq_use_env)\n    (* - relative bound *)\n    apply (rule_tac dist_diff_leq_use_env)\n    apply (rule_tac if_zero_leq_var_env)\n    apply (simp add: comp_sol_subst_penv)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (rule_tac comp_leq_use_env1)\n     apply (rule_tac self_comp_leq_use_env2)\n    apply (rule_tac comp_leq_use_env2)\n    apply (rule_tac self_comp_leq_use_env2)\n    (* - subtractant bound *)\n   apply (rule_tac dist_comp_leq_use_env)\n    apply (rule_tac comp_leq_use_env1)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (rule_tac comp_leq_use_env1)\n     apply (rule_tac c_list=\"cl1\" in infer_m_leq_use_env)\n     apply (auto)\n    apply (rule_tac self_comp_leq_use_env2)\n   apply (rule_tac dist_comp_leq_use_env)\n    apply (rule_tac comp_leq_use_env2)\n    apply (rule_tac comp_leq_use_env1)\n    apply (rule_tac c_list=\"cl2\" in infer_m_leq_use_env)\n    apply (auto)\n   apply (rule_tac comp_leq_use_env2)\n   apply (rule_tac self_comp_leq_use_env2)\n    (* - requirements bound *)\n  apply (simp add: app_req_def)\n  apply (auto)\n   apply (rule_tac leq_empty_use_env)\n  apply (rule_tac dist_diff_leq_use_env_gen)\n   apply (case_tac \"dir_subst_permx t_sub p_sub (XType a) = NoPerm\")\n    apply (case_tac \"req_type (full_subst_type t_sub p_sub tau_n (VarScheme a))\")\n      apply (auto)\n     apply (simp add: full_subst_type_def)\n    apply (simp add: full_subst_type_def)\n   apply (simp add: if_zero_pos_var_env)\n   apply (simp add: comp_sol_subst_penv)\n   apply (rule_tac dist_comp_leq_use_env)\n    apply (rule_tac comp_leq_use_env1)\n    apply (rule_tac self_diff_leq_use_env)\n   apply (rule_tac comp_leq_use_env2)\n   apply (rule_tac diff_leq_use_env)\n   apply (rule_tac lift_leq_var_env)\n   apply (rule_tac id_leq_use_env)\n  apply (rule_tac self_comp_leq_use_env2) \n  done\n\nend", "meta": {"author": "anon-ef", "repo": "perm_lang_ef2", "sha": "0fcb6e4c175193cc7b94f297a8aaa605f502d711", "save_path": "github-repos/isabelle/anon-ef-perm_lang_ef2", "path": "github-repos/isabelle/anon-ef-perm_lang_ef2/perm_lang_ef2-0fcb6e4c175193cc7b94f297a8aaa605f502d711/perm_ref/InferSound.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6261241772283034, "lm_q2_score": 0.4339814648038986, "lm_q1q2_score": 0.2717262875826749}}
{"text": "(*  Title:       Isabelle Collections Library\n    Author:      Andreas Lochbihler <andreas dot lochbihler at kit.edu>\n    Maintainer:  Andreas Lochbihler <andreas dot lochbihler at kit.edu>\n*)\nheader {* \\isaheader{Array-based hash map implementation} *}\ntheory ArrayHashMap_Impl imports \n  \"../../Lib/HashCode\"\n  \"../../Lib/Diff_Array\"\n  \"../gen_algo/ListGA\"\n  \"ListMapImpl\"\n  \"../../Iterator/Array_Iterator\"\nbegin\n\ntext {*  Misc. *}\n\nsetup Locale_Code.open_block\ninterpretation a_idx_it!: \n  idx_iteratei_loc list_of_array \"\\<lambda>_. True\" array_length array_get\n  apply unfold_locales\n  apply (case_tac [!] s) [2]\n  apply auto\n  done\nsetup Locale_Code.close_block\n\n(*\nlemma idx_iteratei_aux_array_get_Array_conv_nth:\n  \"idx_iteratei_aux array_get sz i (Array xs) c f \\<sigma> = idx_iteratei_aux op ! sz i xs c f \\<sigma>\"\napply(induct get\\<equiv>\"op ! :: 'b list \\<Rightarrow> nat \\<Rightarrow> 'b\" sz i xs c f \\<sigma> rule: idx_iteratei_aux.induct)\napply(subst (1 2) idx_iteratei_aux.simps)\napply simp\ndone\n\nlemma idx_iteratei_array_get_Array_conv_nth:\n  \"idx_iteratei array_get array_length (Array xs) = idx_iteratei nth length xs\"\nby(simp add: idx_iteratei_def fun_eq_iff idx_iteratei_aux_array_get_Array_conv_nth)\n\nlemma idx_iteratei_aux_nth_conv_foldli_drop:\n  fixes xs :: \"'b list\"\n  assumes \"i \\<le> length xs\"\n  shows \"idx_iteratei_aux op ! (length xs) i xs c f \\<sigma> = foldli (drop (length xs - i) xs) c f \\<sigma>\"\nusing assms\nproof(induct get\\<equiv>\"op ! :: 'b list \\<Rightarrow> nat \\<Rightarrow> 'b\" sz\\<equiv>\"length xs\" i xs c f \\<sigma> rule: idx_iteratei_aux.induct)\n  case (1 i l c f \\<sigma>)\n  show ?case\n  proof(cases \"i = 0 \\<or> \\<not> c \\<sigma>\")\n    case True thus ?thesis\n      by(subst idx_iteratei_aux.simps)(auto)\n  next\n    case False\n    hence i: \"i > 0\" and c: \"c \\<sigma>\" by auto\n    hence \"idx_iteratei_aux op ! (length l) i l c f \\<sigma> = idx_iteratei_aux op ! (length l) (i - 1) l c f (f (l ! (length l - i)) \\<sigma>)\"\n      by(subst idx_iteratei_aux.simps) simp\n    also have \"\\<dots> = foldli (drop (length l - (i - 1)) l) c f (f (l ! (length l - i)) \\<sigma>)\"\n      using `i \\<le> length l` i c by -(rule 1, auto)\n    also from `i \\<le> length l` i\n    have \"drop (length l - i) l = (l ! (length l - i)) # drop (length l - (i - 1)) l\"\n      by(subst Cons_nth_drop_Suc[symmetric])(simp_all, metis Suc_eq_plus1_left add_diff_assoc)\n    hence \"foldli (drop (length l - (i - 1)) l) c f (f (l ! (length l - i)) \\<sigma>) = foldli (drop (length l - i) l) c f \\<sigma>\"\n      using c by simp\n    finally show ?thesis .\n  qed\nqed\n\nlemma idx_iteratei_nth_length_conv_foldli: \"idx_iteratei nth length = foldli\"\nby(rule ext)+(simp add: idx_iteratei_def idx_iteratei_aux_nth_conv_foldli_drop)\n*)\n\nsubsection {* Type definition and primitive operations *}\n\ndefinition load_factor :: nat -- \"in percent\"\n  where \"load_factor = 75\"\n\ntext {*\n  We do not use @{typ \"('k, 'v) assoc_list\"} for the buckets but plain lists of key-value pairs.\n  This speeds up rehashing because we then do not have to go through the abstract operations.\n*}\n\ndatatype ('key, 'val) hashmap =\n  HashMap \"('key \\<times> 'val) list array\" \"nat\"\n\nsubsection {* Operations *}\n\ndefinition new_hashmap_with :: \"nat \\<Rightarrow> ('key :: hashable, 'val) hashmap\"\nwhere \"\\<And>size. new_hashmap_with size = HashMap (new_array [] size) 0\"\n\ndefinition ahm_empty :: \"unit \\<Rightarrow> ('key :: hashable, 'val) hashmap\"\nwhere \"ahm_empty \\<equiv> \\<lambda>_. new_hashmap_with (def_hashmap_size TYPE('key))\"\n\ndefinition bucket_ok :: \"nat \\<Rightarrow> nat \\<Rightarrow> (('key :: hashable) \\<times> 'val) list \\<Rightarrow> bool\"\nwhere \"bucket_ok len h kvs = (\\<forall>k \\<in> fst ` set kvs. bounded_hashcode_nat len k = h)\"\n\ndefinition ahm_invar_aux :: \"nat \\<Rightarrow> (('key :: hashable) \\<times> 'val) list array \\<Rightarrow> bool\"\nwhere\n  \"ahm_invar_aux n a \\<longleftrightarrow>\n  (\\<forall>h. h < array_length a \\<longrightarrow> bucket_ok (array_length a) h (array_get a h) \\<and> distinct (map fst (array_get a h))) \\<and>\n  array_foldl (\\<lambda>_ n kvs. n + size kvs) 0 a = n \\<and>\n  array_length a > 1\"\n\n\nprimrec ahm_invar :: \"('key :: hashable, 'val) hashmap \\<Rightarrow> bool\"\nwhere \"ahm_invar (HashMap a n) = ahm_invar_aux n a\"\n\ndefinition ahm_\\<alpha>_aux :: \"(('key :: hashable) \\<times> 'val) list array \\<Rightarrow> 'key \\<Rightarrow> 'val option\"\nwhere [simp]: \"ahm_\\<alpha>_aux a k = map_of (array_get a (bounded_hashcode_nat (array_length a) k)) k\"\n\nprimrec ahm_\\<alpha> :: \"('key :: hashable, 'val) hashmap \\<Rightarrow> 'key \\<Rightarrow> 'val option\"\nwhere\n  \"ahm_\\<alpha> (HashMap a _) = ahm_\\<alpha>_aux a\"\n\ndefinition ahm_lookup :: \"'key \\<Rightarrow> ('key :: hashable, 'val) hashmap \\<Rightarrow> 'val option\"\nwhere \"ahm_lookup k hm  = ahm_\\<alpha> hm k\"\n\nprimrec ahm_iteratei_aux :: \"((('key :: hashable) \\<times> 'val) list array) \\<Rightarrow> ('key \\<times> 'val, '\\<sigma>) set_iterator\"\nwhere \"ahm_iteratei_aux (Array xs) c f = foldli (concat xs) c f\"\n\nprimrec ahm_iteratei :: \"(('key :: hashable, 'val) hashmap) \\<Rightarrow> (('key \\<times> 'val), '\\<sigma>) set_iterator\"\nwhere\n  \"ahm_iteratei (HashMap a n) = ahm_iteratei_aux a\"\n\ndefinition ahm_rehash_aux' :: \"nat \\<Rightarrow> 'key \\<times> 'val \\<Rightarrow> (('key :: hashable) \\<times> 'val) list array \\<Rightarrow> ('key \\<times> 'val) list array\"\nwhere\n  \"ahm_rehash_aux' n kv a =\n   (let h = bounded_hashcode_nat n (fst kv)\n    in array_set a h (kv # array_get a h))\"\n\ndefinition ahm_rehash_aux :: \"(('key :: hashable) \\<times> 'val) list array \\<Rightarrow> nat \\<Rightarrow> ('key \\<times> 'val) list array\"\nwhere\n  \"ahm_rehash_aux a sz = ahm_iteratei_aux a (\\<lambda>x. True) (ahm_rehash_aux' sz) (new_array [] sz)\"\n\nprimrec ahm_rehash :: \"('key :: hashable, 'val) hashmap \\<Rightarrow> nat \\<Rightarrow> ('key, 'val) hashmap\"\nwhere \"ahm_rehash (HashMap a n) sz = HashMap (ahm_rehash_aux a sz) n\"\n\nprimrec hm_grow :: \"('key :: hashable, 'val) hashmap \\<Rightarrow> nat\"\nwhere \"hm_grow (HashMap a n) = 2 * array_length a + 3\"\n\nprimrec ahm_filled :: \"('key :: hashable, 'val) hashmap \\<Rightarrow> bool\"\nwhere \"ahm_filled (HashMap a n) = (array_length a * load_factor \\<le> n * 100)\"\n\nprimrec ahm_update_aux :: \"('key :: hashable, 'val) hashmap \\<Rightarrow> 'key \\<Rightarrow> 'val \\<Rightarrow> ('key, 'val) hashmap\"\nwhere\n  \"ahm_update_aux (HashMap a n) k v = \n  (let h = bounded_hashcode_nat (array_length a) k;\n       m = array_get a h;\n       insert = map_of m k = None\n   in HashMap (array_set a h (AList.update k v m)) (if insert then n + 1 else n))\"\n\ndefinition ahm_update :: \"'key \\<Rightarrow> 'val \\<Rightarrow> ('key :: hashable, 'val) hashmap \\<Rightarrow> ('key, 'val) hashmap\"\nwhere\n  \"ahm_update k v hm = \n   (let hm' = ahm_update_aux hm k v\n    in (if ahm_filled hm' then ahm_rehash hm' (hm_grow hm') else hm'))\"\n\nprimrec ahm_delete :: \"'key \\<Rightarrow> ('key :: hashable, 'val) hashmap \\<Rightarrow> ('key, 'val) hashmap\"\nwhere\n  \"ahm_delete k (HashMap a n) =\n  (let h = bounded_hashcode_nat (array_length a) k;\n       m = array_get a h;\n       deleted = (map_of m k \\<noteq> None)\n   in HashMap (array_set a h (AList.delete k m)) (if deleted then n - 1 else n))\"\n\n\nlemma hm_grow_gt_1 [iff]:\n  \"Suc 0 < hm_grow hm\"\nby(cases hm)(simp)\n\nlemma bucket_ok_Nil [simp]: \"bucket_ok len h [] = True\"\nby(simp add: bucket_ok_def)\n\nlemma bucket_okD:\n  \"\\<lbrakk> bucket_ok len h xs; (k, v) \\<in> set xs \\<rbrakk>\n  \\<Longrightarrow> bounded_hashcode_nat len k = h\"\nby(auto simp add: bucket_ok_def)\n\nlemma bucket_okI:\n  \"(\\<And>k. k \\<in> fst ` set kvs \\<Longrightarrow> bounded_hashcode_nat len k = h) \\<Longrightarrow> bucket_ok len h kvs\"\nby(simp add: bucket_ok_def)\n\n\nsubsection {* @{term ahm_invar} *}\n\nlemma ahm_invar_auxE:\n  assumes \"ahm_invar_aux n a\"\n  obtains \"\\<forall>h. h < array_length a \\<longrightarrow> bucket_ok (array_length a) h (array_get a h) \\<and> distinct (map fst (array_get a h))\"\n  and \"n = array_foldl (\\<lambda>_ n kvs. n + length kvs) 0 a\" and \"array_length a > 1\"\nusing assms unfolding ahm_invar_aux_def by blast\n\nlemma ahm_invar_auxI:\n  \"\\<lbrakk> \\<And>h. h < array_length a \\<Longrightarrow> bucket_ok (array_length a) h (array_get a h);\n     \\<And>h. h < array_length a \\<Longrightarrow> distinct (map fst (array_get a h));\n     n = array_foldl (\\<lambda>_ n kvs. n + length kvs) 0 a; array_length a > 1 \\<rbrakk>\n  \\<Longrightarrow> ahm_invar_aux n a\"\nunfolding ahm_invar_aux_def by blast\n\nlemma ahm_invar_distinct_fst_concatD:\n  assumes inv: \"ahm_invar_aux n (Array xs)\"\n  shows \"distinct (map fst (concat xs))\"\nproof -\n  { fix h\n    assume \"h < length xs\"\n    with inv have \"bucket_ok (length xs) h (xs ! h)\" \"distinct (map fst (xs ! h))\"\n      by(simp_all add: ahm_invar_aux_def) }\n  note no_junk = this\n\n  show ?thesis unfolding map_concat\n  proof(rule distinct_concat')\n    have \"distinct [x\\<leftarrow>xs . x \\<noteq> []]\" unfolding distinct_conv_nth\n    proof(intro allI ballI impI)\n      fix i j\n      assume \"i < length [x\\<leftarrow>xs . x \\<noteq> []]\" \"j < length [x\\<leftarrow>xs . x \\<noteq> []]\" \"i \\<noteq> j\"\n      from filter_nth_ex_nth[OF `i < length [x\\<leftarrow>xs . x \\<noteq> []]`]\n      obtain i' where \"i' \\<ge> i\" \"i' < length xs\" and ith: \"[x\\<leftarrow>xs . x \\<noteq> []] ! i = xs ! i'\" \n        and eqi: \"[x\\<leftarrow>take i' xs . x \\<noteq> []] = take i [x\\<leftarrow>xs . x \\<noteq> []]\" by blast\n      from filter_nth_ex_nth[OF `j < length [x\\<leftarrow>xs . x \\<noteq> []]`]\n      obtain j' where \"j' \\<ge> j\" \"j' < length xs\" and jth: \"[x\\<leftarrow>xs . x \\<noteq> []] ! j = xs ! j'\"\n        and eqj: \"[x\\<leftarrow>take j' xs . x \\<noteq> []] = take j [x\\<leftarrow>xs . x \\<noteq> []]\" by blast\n      show \"[x\\<leftarrow>xs . x \\<noteq> []] ! i \\<noteq> [x\\<leftarrow>xs . x \\<noteq> []] ! j\"\n      proof\n        assume \"[x\\<leftarrow>xs . x \\<noteq> []] ! i = [x\\<leftarrow>xs . x \\<noteq> []] ! j\"\n        hence eq: \"xs ! i' = xs ! j'\" using ith jth by simp\n        from `i < length [x\\<leftarrow>xs . x \\<noteq> []]`\n        have \"[x\\<leftarrow>xs . x \\<noteq> []] ! i \\<in> set [x\\<leftarrow>xs . x \\<noteq> []]\" by(rule nth_mem)\n        with ith have \"xs ! i' \\<noteq> []\" by simp\n        then obtain kv where \"kv \\<in> set (xs ! i')\" by(fastforce simp add: neq_Nil_conv)\n        with no_junk[OF `i' < length xs`] have \"bounded_hashcode_nat (length xs) (fst kv) = i'\"\n          by(simp add: bucket_ok_def)\n        moreover from eq `kv \\<in> set (xs ! i')` have \"kv \\<in> set (xs ! j')\" by simp\n        with no_junk[OF `j' < length xs`] have \"bounded_hashcode_nat (length xs) (fst kv) = j'\"\n          by(simp add: bucket_ok_def)\n        ultimately have [simp]: \"i' = j'\" by simp\n        from `i < length [x\\<leftarrow>xs . x \\<noteq> []]` have \"i = length (take i [x\\<leftarrow>xs . x \\<noteq> []])\" by simp\n        also from eqi eqj have \"take i [x\\<leftarrow>xs . x \\<noteq> []] = take j [x\\<leftarrow>xs . x \\<noteq> []]\" by simp\n        finally show False using `i \\<noteq> j` `j < length [x\\<leftarrow>xs . x \\<noteq> []]` by simp\n      qed\n    qed\n    moreover have \"inj_on (map fst) {x \\<in> set xs. x \\<noteq> []}\"\n    proof(rule inj_onI)\n      fix x y\n      assume \"x \\<in> {x \\<in> set xs. x \\<noteq> []}\" \"y \\<in> {x \\<in> set xs. x \\<noteq> []}\" \"map fst x = map fst y\"\n      hence \"x \\<in> set xs\" \"y \\<in> set xs\" \"x \\<noteq> []\" \"y \\<noteq> []\" by auto\n      from `x \\<in> set xs` obtain i where \"xs ! i = x\" \"i < length xs\" unfolding set_conv_nth by fastforce\n      from `y \\<in> set xs` obtain j where \"xs ! j = y\" \"j < length xs\" unfolding set_conv_nth by fastforce\n      from `x \\<noteq> []` obtain k v x' where \"x = (k, v) # x'\" by(cases x) auto\n      with no_junk[OF `i < length xs`] `xs ! i = x`\n      have \"bounded_hashcode_nat (length xs) k = i\" by(auto simp add: bucket_ok_def)\n      moreover from `map fst x = map fst y` `x = (k, v) # x'` obtain v' where \"(k, v') \\<in> set y\" by fastforce\n      with no_junk[OF `j < length xs`] `xs ! j = y`\n      have \"bounded_hashcode_nat (length xs) k = j\" by(auto simp add: bucket_ok_def)\n      ultimately have \"i = j\" by simp\n      with `xs ! i = x` `xs ! j = y` show \"x = y\" by simp\n    qed\n    ultimately show \"distinct [ys\\<leftarrow>map (map fst) xs . ys \\<noteq> []]\"\n      by(simp add: filter_map o_def distinct_map)\n  next\n    fix ys\n    assume \"ys \\<in> set (map (map fst) xs)\"\n    thus \"distinct ys\" by(clarsimp simp add: set_conv_nth)(rule no_junk)\n  next\n    fix ys zs\n    assume \"ys \\<in> set (map (map fst) xs)\" \"zs \\<in> set (map (map fst) xs)\" \"ys \\<noteq> zs\"\n    then obtain ys' zs' where [simp]: \"ys = map fst ys'\" \"zs = map fst zs'\" \n      and \"ys' \\<in> set xs\" \"zs' \\<in> set xs\" by auto\n    have \"fst ` set ys' \\<inter> fst ` set zs' = {}\"\n    proof(rule equals0I)\n      fix k\n      assume \"k \\<in> fst ` set ys' \\<inter> fst ` set zs'\"\n      then obtain v v' where \"(k, v) \\<in> set ys'\" \"(k, v') \\<in> set zs'\" by(auto)\n      from `ys' \\<in> set xs` obtain i where \"xs ! i = ys'\" \"i < length xs\" unfolding set_conv_nth by fastforce\n      with `(k, v) \\<in> set ys'` have \"bounded_hashcode_nat (length xs) k = i\" by(auto dest: no_junk bucket_okD)\n      moreover\n      from `zs' \\<in> set xs` obtain j where \"xs ! j = zs'\" \"j < length xs\" unfolding set_conv_nth by fastforce\n      with `(k, v') \\<in> set zs'` have \"bounded_hashcode_nat (length xs) k = j\" by(auto dest: no_junk bucket_okD)\n      ultimately have \"i = j\" by simp\n      with `xs ! i = ys'` `xs ! j = zs'` have \"ys' = zs'\" by simp\n      with `ys \\<noteq> zs` show False by simp\n    qed\n    thus \"set ys \\<inter> set zs = {}\" by simp\n  qed\nqed\n\nsubsection {* @{term \"ahm_\\<alpha>\"} *}\n\nlemma finite_dom_ahm_\\<alpha>_aux:\n  assumes \"ahm_invar_aux n a\"\n  shows \"finite (dom (ahm_\\<alpha>_aux a))\"\nproof -\n  have \"dom (ahm_\\<alpha>_aux a) \\<subseteq> (\\<Union>h \\<in> range (bounded_hashcode_nat (array_length a) :: 'a \\<Rightarrow> nat). dom (map_of (array_get a h)))\"\n    by(force simp add: dom_map_of_conv_image_fst ahm_\\<alpha>_aux_def dest: map_of_SomeD)\n  moreover have \"finite \\<dots>\"\n  proof(rule finite_UN_I)\n    from `ahm_invar_aux n a` have \"array_length a > 1\" by(simp add: ahm_invar_aux_def)\n    hence \"range (bounded_hashcode_nat (array_length a) :: 'a \\<Rightarrow> nat) \\<subseteq> {0..<array_length a}\"\n      by(auto simp add: bounded_hashcode_nat_bounds)\n    thus \"finite (range (bounded_hashcode_nat (array_length a) :: 'a \\<Rightarrow> nat))\"\n      by(rule finite_subset) simp\n  qed(rule finite_dom_map_of)\n  ultimately show ?thesis by(rule finite_subset)\nqed\n\nlemma ahm_\\<alpha>_aux_conv_map_of_concat:\n  assumes inv: \"ahm_invar_aux n (Array xs)\"\n  shows \"ahm_\\<alpha>_aux (Array xs) = map_of (concat xs)\"\nproof\n  fix k\n  show \"ahm_\\<alpha>_aux (Array xs) k = map_of (concat xs) k\"\n  proof(cases \"map_of (concat xs) k\")\n    case None\n    hence \"k \\<notin> fst ` set (concat xs)\" by(simp add: map_of_eq_None_iff)\n    hence \"k \\<notin> fst ` set (xs ! bounded_hashcode_nat (length xs) k)\"\n    proof(rule contrapos_nn)\n      assume \"k \\<in> fst ` set (xs ! bounded_hashcode_nat (length xs) k)\"\n      then obtain v where \"(k, v) \\<in> set (xs ! bounded_hashcode_nat (length xs) k)\" by auto\n      moreover from inv have \"bounded_hashcode_nat (length xs) k < length xs\"\n        by(simp add: bounded_hashcode_nat_bounds ahm_invar_aux_def)\n      ultimately show \"k \\<in> fst ` set (concat xs)\"\n        by(force intro: rev_image_eqI)\n    qed\n    thus ?thesis unfolding None by(simp add: map_of_eq_None_iff)\n  next\n    case (Some v)\n    hence \"(k, v) \\<in> set (concat xs)\" by(rule map_of_SomeD)\n    then obtain ys where \"ys \\<in> set xs\" \"(k, v) \\<in> set ys\"\n      unfolding set_concat by blast\n    from `ys \\<in> set xs` obtain i j where \"i < length xs\" \"xs ! i = ys\"\n      unfolding set_conv_nth by auto\n    with inv `(k, v) \\<in> set ys`\n    show ?thesis unfolding Some\n      by(force dest: bucket_okD simp add: ahm_invar_aux_def)\n  qed\nqed\n\nlemma ahm_invar_aux_card_dom_ahm_\\<alpha>_auxD:\n  assumes inv: \"ahm_invar_aux n a\"\n  shows \"card (dom (ahm_\\<alpha>_aux a)) = n\"\nproof(cases a)\n  case (Array xs)[simp]\n  from inv have \"card (dom (ahm_\\<alpha>_aux (Array xs))) = card (dom (map_of (concat xs)))\"\n    by(simp add: ahm_\\<alpha>_aux_conv_map_of_concat)\n  also from inv have \"distinct (map fst (concat xs))\"\n    by(simp add: ahm_invar_distinct_fst_concatD)\n  hence \"card (dom (map_of (concat xs))) = length (concat xs)\"\n    by(rule card_dom_map_of)\n  also have \"length (concat xs) = foldl op + 0 (map length xs)\"\n    by (simp add: length_concat foldl_conv_fold add.commute fold_plus_listsum_rev)\n  also from inv\n  have \"\\<dots> = n\" unfolding foldl_map by(simp add: ahm_invar_aux_def array_foldl_foldl)\n  finally show ?thesis by(simp)\nqed\n\nlemma finite_dom_ahm_\\<alpha>:\n  \"ahm_invar hm \\<Longrightarrow> finite (dom (ahm_\\<alpha> hm))\"\nby(cases hm)(auto intro: finite_dom_ahm_\\<alpha>_aux)\n\nlemma finite_map_ahm_\\<alpha>_aux:\n  \"finite_map ahm_\\<alpha>_aux (ahm_invar_aux n)\"\nby(unfold_locales)(rule finite_dom_ahm_\\<alpha>_aux)\n\nlemma finite_map_ahm_\\<alpha>:\n  \"finite_map ahm_\\<alpha> ahm_invar\"\nby(unfold_locales)(rule finite_dom_ahm_\\<alpha>)\n\nsubsection {* @{term ahm_empty} *}\n\nlemma ahm_invar_aux_new_array:\n  assumes \"n > 1\"\n  shows \"ahm_invar_aux 0 (new_array [] n)\"\nproof -\n  have \"foldl (\\<lambda>b (k, v). b + length v) 0 (zip [0..<n] (replicate n [])) = 0\"\n    by(induct n)(simp_all add: replicate_Suc_conv_snoc del: replicate_Suc)\n  with assms show ?thesis by(simp add: ahm_invar_aux_def array_foldl_new_array)\nqed\n\nlemma ahm_invar_new_hashmap_with:\n  \"n > 1 \\<Longrightarrow> ahm_invar (new_hashmap_with n)\"\nby(auto simp add: ahm_invar_def new_hashmap_with_def intro: ahm_invar_aux_new_array)\n\nlemma ahm_\\<alpha>_new_hashmap_with:\n  \"n > 1 \\<Longrightarrow> ahm_\\<alpha> (new_hashmap_with n) = empty\"\nby(simp add: new_hashmap_with_def bounded_hashcode_nat_bounds fun_eq_iff)\n\nlemma ahm_invar_ahm_empty [simp]: \"ahm_invar (ahm_empty ())\"\nusing def_hashmap_size[where ?'a = 'a]\nby(auto intro: ahm_invar_new_hashmap_with simp add: ahm_empty_def)\n\nlemma ahm_empty_correct [simp]: \"ahm_\\<alpha> (ahm_empty ()) = Map.empty\"\nusing def_hashmap_size[where ?'a = 'a]\nby(auto intro: ahm_\\<alpha>_new_hashmap_with simp add: ahm_empty_def)\n\nlemma ahm_empty_impl: \"map_empty ahm_\\<alpha> ahm_invar ahm_empty\"\nby(unfold_locales)(auto)\n\nsubsection {* @{term \"ahm_lookup\"} *}\n\nlemma ahm_lookup_impl: \"map_lookup ahm_\\<alpha> ahm_invar ahm_lookup\"\nby(unfold_locales)(simp add: ahm_lookup_def)\n\nsubsection {* @{term \"ahm_iteratei\"} *}\n\nlemma ahm_iteratei_aux_impl:\n  assumes invar_m: \"ahm_invar_aux n m\"\n  shows \"map_iterator (ahm_iteratei_aux m) (ahm_\\<alpha>_aux m)\"\nproof -\n  obtain ms where m_eq[simp]: \"m = Array ms\" by (cases m)\n\n  from ahm_invar_distinct_fst_concatD[of n ms] invar_m\n  have dist: \"distinct (map fst (concat ms))\" by simp\n\n  show \"map_iterator (ahm_iteratei_aux m) (ahm_\\<alpha>_aux m)\" \n    using  set_iterator_foldli_correct[of \"concat ms\"] dist\n    by (simp add: ahm_\\<alpha>_aux_conv_map_of_concat[OF invar_m[unfolded m_eq]]\n                  ahm_iteratei_aux_def map_to_set_map_of[OF dist] distinct_map)\nqed \n\nlemma ahm_iteratei_correct:\n  assumes invar_hm: \"ahm_invar hm\"\n  shows \"map_iterator (ahm_iteratei hm) (ahm_\\<alpha> hm)\"\nproof -\n  obtain A n where hm_eq [simp]: \"hm = HashMap A n\" by(cases hm)\n\n  from ahm_iteratei_aux_impl[of n A] invar_hm\n    show map_it: \"map_iterator (ahm_iteratei hm) (ahm_\\<alpha> hm)\" by simp \nqed\n\nlemma ahm_iteratei_aux_code [code]:\n  \"ahm_iteratei_aux a c f \\<sigma> = a_idx_it.idx_iteratei a c (\\<lambda>x. foldli x c f) \\<sigma>\"\nproof(cases a)\n  case (Array xs)[simp]\n\n  have \"ahm_iteratei_aux a c f \\<sigma> = foldli (concat xs) c f \\<sigma>\" by simp\n  also have \"\\<dots> = foldli xs c (\\<lambda>x. foldli x c f) \\<sigma>\" by (simp add: foldli_concat)\n  thm a_idx_it.idx_iteratei_correct\n  also have \"\\<dots> = a_idx_it.idx_iteratei a c (\\<lambda>x. foldli x c f) \\<sigma>\"\n    by (simp add: a_idx_it.idx_iteratei_correct)\n  finally show ?thesis .\nqed\nsubsection {* @{term \"ahm_rehash\"} *}\n\nlemma array_length_ahm_rehash_aux':\n  \"array_length (ahm_rehash_aux' n kv a) = array_length a\"\nby(simp add: ahm_rehash_aux'_def Let_def)\n\nlemma ahm_rehash_aux'_preserves_ahm_invar_aux:\n  assumes inv: \"ahm_invar_aux n a\"\n  and fresh: \"k \\<notin> fst ` set (array_get a (bounded_hashcode_nat (array_length a) k))\"\n  shows \"ahm_invar_aux (Suc n) (ahm_rehash_aux' (array_length a) (k, v) a)\"\n  (is \"ahm_invar_aux _ ?a\")\nproof(rule ahm_invar_auxI)\n  fix h\n  assume \"h < array_length ?a\"\n  hence hlen: \"h < array_length a\" by(simp add: array_length_ahm_rehash_aux')\n  with inv have bucket: \"bucket_ok (array_length a) h (array_get a h)\"\n    and dist: \"distinct (map fst (array_get a h))\"\n    by(auto elim: ahm_invar_auxE)\n  let ?h = \"bounded_hashcode_nat (array_length a) k\"\n  from hlen bucket show \"bucket_ok (array_length ?a) h (array_get ?a h)\"\n    by(cases \"h = ?h\")(auto simp add: ahm_rehash_aux'_def Let_def array_length_ahm_rehash_aux' array_get_array_set_other dest: bucket_okD intro!: bucket_okI)\n  from dist hlen fresh\n  show \"distinct (map fst (array_get ?a h))\"\n    by(cases \"h = ?h\")(auto simp add: ahm_rehash_aux'_def Let_def array_get_array_set_other)\nnext\n  let ?f = \"\\<lambda>n kvs. n + length kvs\"\n  { fix n :: nat and xs :: \"('a \\<times> 'b) list list\"\n    have \"foldl ?f n xs = n + foldl ?f 0 xs\"\n      by(induct xs arbitrary:  rule: rev_induct) simp_all }\n  note fold = this\n  let ?h = \"bounded_hashcode_nat (array_length a) k\"\n\n  obtain xs where a [simp]: \"a = Array xs\" by(cases a)\n  from inv have [simp]: \"bounded_hashcode_nat (length xs) k < length xs\"\n    by(simp add: ahm_invar_aux_def bounded_hashcode_nat_bounds)\n  have xs: \"xs = take ?h xs @ (xs ! ?h) # drop (Suc ?h) xs\" by(simp add: Cons_nth_drop_Suc)\n  from inv have \"n = array_foldl (\\<lambda>_ n kvs. n + length kvs) 0 a\"\n    by(auto elim: ahm_invar_auxE)\n  hence \"n = foldl ?f 0 (take ?h xs) + length (xs ! ?h) + foldl ?f 0 (drop (Suc ?h) xs)\"\n    by(simp add: array_foldl_foldl)(subst xs, simp, subst (1 2 3 4) fold, simp)\n  thus \"Suc n = array_foldl (\\<lambda>_ n kvs. n + length kvs) 0 ?a\"\n    by(simp add: ahm_rehash_aux'_def Let_def array_foldl_foldl foldl_list_update)(subst (1 2 3 4) fold, simp)\nnext\n  from inv have \"1 < array_length a\" by(auto elim: ahm_invar_auxE)\n  thus \"1 < array_length ?a\" by(simp add: array_length_ahm_rehash_aux')\nqed\n\ndeclare [[coercion_enabled = false]]\n\nlemma ahm_rehash_aux_correct:\n  fixes a :: \"(('key :: hashable) \\<times> 'val) list array\"\n  assumes inv: \"ahm_invar_aux n a\"\n  and \"sz > 1\"\n  shows \"ahm_invar_aux n (ahm_rehash_aux a sz)\" (is \"?thesis1\")\n  and \"ahm_\\<alpha>_aux (ahm_rehash_aux a sz) = ahm_\\<alpha>_aux a\" (is \"?thesis2\")\nproof -\n  (*interpret ahm!: map_iterator \"ahm_\\<alpha>_aux\" \"ahm_invar_aux n\" \"ahm_iteratei_aux\"\n    by(rule ahm_iteratei_aux_impl)*)\n  let ?a = \"ahm_rehash_aux a sz\"\n  let ?I = \"\\<lambda>it a'. ahm_invar_aux (n - card it) a' \\<and> array_length a' = sz \\<and> (\\<forall>k. if k \\<in> it then ahm_\\<alpha>_aux a' k = None else ahm_\\<alpha>_aux a' k = ahm_\\<alpha>_aux a k)\"\n  have \"?I {} ?a \\<or> (\\<exists>it\\<subseteq>dom (ahm_\\<alpha>_aux a). it \\<noteq> {} \\<and> \\<not> True \\<and> ?I it ?a)\"\n    unfolding ahm_rehash_aux_def\n\n  proof (rule map_iterator_rule_P[OF ahm_iteratei_aux_impl[OF inv], where\n      c = \"\\<lambda>_. True\" and f=\"ahm_rehash_aux' sz\" and ?\\<sigma>0.0 = \"new_array [] sz\"\n      and I=\"?I\"]\n    )\n\n    from inv have \"card (dom (ahm_\\<alpha>_aux a)) = n\" by(rule ahm_invar_aux_card_dom_ahm_\\<alpha>_auxD)\n    moreover from `1 < sz` have \"ahm_invar_aux 0 (new_array ([] :: ('key \\<times> 'val) list) sz)\"\n      by(rule ahm_invar_aux_new_array)\n    moreover {\n      fix k\n      assume \"k \\<notin> dom (ahm_\\<alpha>_aux a)\"\n      hence \"ahm_\\<alpha>_aux a k = None\" by auto\n      moreover have \"bounded_hashcode_nat sz k < sz\" using `1 < sz`\n        by(simp add: bounded_hashcode_nat_bounds)\n      ultimately have \"ahm_\\<alpha>_aux (new_array [] sz) k = ahm_\\<alpha>_aux a k\" by simp }\n    ultimately show \"?I (dom (ahm_\\<alpha>_aux a)) (new_array [] sz)\"\n      by(auto simp add: bounded_hashcode_nat_bounds[OF `1 < sz`])\n  next\n    fix k :: 'key\n      and v :: 'val\n      and it a'\n    assume \"k \\<in> it\" \"ahm_\\<alpha>_aux a k = Some v\" \n      and it_sub: \"it \\<subseteq> dom (ahm_\\<alpha>_aux a)\"\n      and I: \"?I it a'\"\n    from I have inv': \"ahm_invar_aux (n - card it) a'\" \n      and a'_eq_a: \"\\<And>k. k \\<notin> it \\<Longrightarrow> ahm_\\<alpha>_aux a' k = ahm_\\<alpha>_aux a k\" \n      and a'_None: \"\\<And>k. k \\<in> it \\<Longrightarrow> ahm_\\<alpha>_aux a' k = None\"\n      and [simp]: \"sz = array_length a'\" by(auto split: split_if_asm)\n    from it_sub finite_dom_ahm_\\<alpha>_aux[OF inv] have \"finite it\" by(rule finite_subset)\n    moreover with `k \\<in> it` have \"card it > 0\" by(auto simp add: card_gt_0_iff)\n    moreover from finite_dom_ahm_\\<alpha>_aux[OF inv] it_sub\n    have \"card it \\<le> card (dom (ahm_\\<alpha>_aux a))\" by(rule card_mono)\n    moreover have \"\\<dots> = n\" using inv\n      by(simp add: ahm_invar_aux_card_dom_ahm_\\<alpha>_auxD)\n    ultimately have \"n - card (it - {k}) = (n - card it) + 1\" using `k \\<in> it` by auto\n    moreover from `k \\<in> it` have \"ahm_\\<alpha>_aux a' k = None\" by(rule a'_None)\n    hence \"k \\<notin> fst ` set (array_get a' (bounded_hashcode_nat (array_length a') k))\"\n      by(simp add: map_of_eq_None_iff)\n    ultimately have \"ahm_invar_aux (n - card (it - {k})) (ahm_rehash_aux' sz (k, v) a')\"\n      using inv' by(auto intro: ahm_rehash_aux'_preserves_ahm_invar_aux)\n    moreover have \"array_length (ahm_rehash_aux' sz (k, v) a') = sz\"\n      by(simp add: array_length_ahm_rehash_aux')\n    moreover {\n      fix k'\n      assume \"k' \\<in> it - {k}\"\n      with bounded_hashcode_nat_bounds[OF `1 < sz`, of k'] a'_None[of k']\n      have \"ahm_\\<alpha>_aux (ahm_rehash_aux' sz (k, v) a') k' = None\"\n        by(cases \"bounded_hashcode_nat sz k = bounded_hashcode_nat sz k'\")(auto simp add: array_get_array_set_other ahm_rehash_aux'_def Let_def)\n    } moreover {\n      fix k'\n      assume \"k' \\<notin> it - {k}\"\n      with bounded_hashcode_nat_bounds[OF `1 < sz`, of k'] bounded_hashcode_nat_bounds[OF `1 < sz`, of k] a'_eq_a[of k'] `k \\<in> it`\n      have \"ahm_\\<alpha>_aux (ahm_rehash_aux' sz (k, v) a') k' = ahm_\\<alpha>_aux a k'\"\n        unfolding ahm_rehash_aux'_def Let_def using `ahm_\\<alpha>_aux a k = Some v`\n        by(cases \"bounded_hashcode_nat sz k = bounded_hashcode_nat sz k'\")(case_tac [!] \"k' = k\", simp_all add: array_get_array_set_other) }\n    ultimately show \"?I (it - {k}) (ahm_rehash_aux' sz (k, v) a')\" by simp\n  qed auto\n  thus ?thesis1 ?thesis2 unfolding ahm_rehash_aux_def\n    by(auto intro: ext)\nqed\n\nlemma ahm_rehash_correct:\n  fixes hm :: \"('key :: hashable, 'val) hashmap\"\n  assumes inv: \"ahm_invar hm\"\n  and \"sz > 1\"\n  shows \"ahm_invar (ahm_rehash hm sz)\" \"ahm_\\<alpha> (ahm_rehash hm sz) = ahm_\\<alpha> hm\"\nusing assms\nby -(case_tac [!] hm, auto intro: ahm_rehash_aux_correct)\n\nsubsection {* @{term ahm_update} *}\n\nlemma ahm_update_aux_correct:\n  assumes inv: \"ahm_invar hm\"\n  shows \"ahm_invar (ahm_update_aux hm k v)\" (is ?thesis1)\n  and \"ahm_\\<alpha> (ahm_update_aux hm k v) = (ahm_\\<alpha> hm)(k \\<mapsto> v)\" (is ?thesis2)\nproof -\n  obtain a n where [simp]: \"hm = HashMap a n\" by(cases hm)\n\n  let ?h = \"bounded_hashcode_nat (array_length a) k\"\n  let ?a' = \"array_set a ?h (AList.update k v (array_get a ?h))\"\n  let ?n' = \"if map_of (array_get a ?h) k = None then n + 1 else n\"\n\n  have \"ahm_invar (HashMap ?a' ?n')\" unfolding ahm_invar.simps\n  proof(rule ahm_invar_auxI)\n    fix h\n    assume \"h < array_length ?a'\"\n    hence \"h < array_length a\" by simp\n    with inv have \"bucket_ok (array_length a) h (array_get a h)\"\n      by(auto elim: ahm_invar_auxE)\n    thus \"bucket_ok (array_length ?a') h (array_get ?a' h)\"\n      using `h < array_length a`\n      apply(cases \"h = bounded_hashcode_nat (array_length a) k\")\n      apply(fastforce intro!: bucket_okI simp add: dom_update array_get_array_set_other dest: bucket_okD del: imageE elim: imageE)+\n      done\n    from `h < array_length a` inv have \"distinct (map fst (array_get a h))\"\n      by(auto elim: ahm_invar_auxE)\n    with `h < array_length a`\n    show \"distinct (map fst (array_get ?a' h))\"\n      by(cases \"h = bounded_hashcode_nat (array_length a) k\")(auto simp add: array_get_array_set_other intro: distinct_update)\n  next\n    obtain xs where a [simp]: \"a = Array xs\" by(cases a)\n\n    let ?f = \"\\<lambda>n kvs. n + length kvs\"\n    { fix n :: nat and xs :: \"('a \\<times> 'b) list list\"\n      have \"foldl ?f n xs = n + foldl ?f 0 xs\"\n        by(induct xs arbitrary:  rule: rev_induct) simp_all }\n    note fold = this\n\n    from inv have [simp]: \"bounded_hashcode_nat (length xs) k < length xs\"\n      by(simp add: ahm_invar_aux_def bounded_hashcode_nat_bounds)\n    have xs: \"xs = take ?h xs @ (xs ! ?h) # drop (Suc ?h) xs\" by(simp add: Cons_nth_drop_Suc)\n    from inv have \"n = array_foldl (\\<lambda>_ n kvs. n + length kvs) 0 a\"\n      by(auto elim: ahm_invar_auxE)\n    hence \"n = foldl ?f 0 (take ?h xs) + length (xs ! ?h) + foldl ?f 0 (drop (Suc ?h) xs)\"\n      by(simp add: array_foldl_foldl)(subst xs, simp, subst (1 2 3 4) fold, simp)\n    thus \"?n' = array_foldl (\\<lambda>_ n kvs. n + length kvs) 0 ?a'\"\n      apply(simp add: ahm_rehash_aux'_def Let_def array_foldl_foldl foldl_list_update map_of_eq_None_iff)\n      apply(subst (1 2 3 4 5 6 7 8) fold)\n      apply(simp add: length_update)\n      done\n  next\n    from inv have \"1 < array_length a\" by(auto elim: ahm_invar_auxE)\n    thus \"1 < array_length ?a'\" by simp\n  qed\n  moreover have \"ahm_\\<alpha> (ahm_update_aux hm k v) = ahm_\\<alpha> hm(k \\<mapsto> v)\"\n  proof\n    fix k'\n    from inv have \"1 < array_length a\" by(auto elim: ahm_invar_auxE)\n    with bounded_hashcode_nat_bounds[OF this, of k]\n    show \"ahm_\\<alpha> (ahm_update_aux hm k v) k' = (ahm_\\<alpha> hm(k \\<mapsto> v)) k'\"\n      by(cases \"bounded_hashcode_nat (array_length a) k = bounded_hashcode_nat (array_length a) k'\")(auto simp add: Let_def update_conv array_get_array_set_other)\n  qed\n  ultimately show ?thesis1 ?thesis2 by(simp_all add: Let_def)\nqed\n\nlemma ahm_update_correct:\n  assumes inv: \"ahm_invar hm\"\n  shows \"ahm_invar (ahm_update k v hm)\"\n  and \"ahm_\\<alpha> (ahm_update k v hm) = (ahm_\\<alpha> hm)(k \\<mapsto> v)\"\nusing assms\nby(simp_all add: ahm_update_def Let_def ahm_rehash_correct ahm_update_aux_correct)\n\nlemma ahm_update_impl:\n  \"map_update ahm_\\<alpha> ahm_invar ahm_update\"\nby(unfold_locales)(simp_all add: ahm_update_correct)\n\nsubsection {* @{term \"ahm_delete\"} *}\n\nlemma ahm_delete_correct:\n  assumes inv: \"ahm_invar hm\"\n  shows \"ahm_invar (ahm_delete k hm)\" (is \"?thesis1\")\n  and \"ahm_\\<alpha> (ahm_delete k hm) = (ahm_\\<alpha> hm) |` (- {k})\" (is \"?thesis2\")\nproof -\n  obtain a n where hm [simp]: \"hm = HashMap a n\" by(cases hm)\n\n  let ?h = \"bounded_hashcode_nat (array_length a) k\"\n  let ?a' = \"array_set a ?h (AList.delete k (array_get a ?h))\"\n  let ?n' = \"if map_of (array_get a (bounded_hashcode_nat (array_length a) k)) k = None then n else n - 1\"\n  \n  have \"ahm_invar_aux ?n' ?a'\"\n  proof(rule ahm_invar_auxI)\n    fix h\n    assume \"h < array_length ?a'\"\n    hence \"h < array_length a\" by simp\n    with inv have \"bucket_ok (array_length a) h (array_get a h)\"\n      and \"1 < array_length a\" \n      and \"distinct (map fst (array_get a h))\" by(auto elim: ahm_invar_auxE)\n    thus \"bucket_ok (array_length ?a') h (array_get ?a' h)\"\n      and \"distinct (map fst (array_get ?a' h))\"\n      using bounded_hashcode_nat_bounds[of \"array_length a\" k] \n      by-(case_tac [!] \"h = bounded_hashcode_nat (array_length a) k\", auto simp add: array_get_array_set_other set_delete_conv intro!: bucket_okI dest: bucket_okD intro: distinct_delete)\n  next\n    obtain xs where a [simp]: \"a = Array xs\" by(cases a)\n\n    let ?f = \"\\<lambda>n kvs. n + length kvs\"\n    { fix n :: nat and xs :: \"('a \\<times> 'b) list list\"\n      have \"foldl ?f n xs = n + foldl ?f 0 xs\"\n        by(induct xs arbitrary:  rule: rev_induct) simp_all }\n    note fold = this\n\n    from inv have [simp]: \"bounded_hashcode_nat (length xs) k < length xs\"\n      by(simp add: ahm_invar_aux_def bounded_hashcode_nat_bounds)\n    from inv have \"distinct (map fst (array_get a ?h))\" by(auto elim: ahm_invar_auxE)\n    moreover\n    have xs: \"xs = take ?h xs @ (xs ! ?h) # drop (Suc ?h) xs\" by(simp add: Cons_nth_drop_Suc)\n    from inv have \"n = array_foldl (\\<lambda>_ n kvs. n + length kvs) 0 a\"\n      by(auto elim: ahm_invar_auxE)\n    hence \"n = foldl ?f 0 (take ?h xs) + length (xs ! ?h) + foldl ?f 0 (drop (Suc ?h) xs)\"\n      by(simp add: array_foldl_foldl)(subst xs, simp, subst (1 2 3 4) fold, simp)\n    ultimately show \"?n' = array_foldl (\\<lambda>_ n kvs. n + length kvs) 0 ?a'\"\n      apply(simp add: array_foldl_foldl foldl_list_update map_of_eq_None_iff)\n      apply(subst (1 2 3 4 5 6 7 8) fold)\n      apply(auto simp add: length_distinct in_set_conv_nth)\n      done\n  next\n    from inv show \"1 < array_length ?a'\" by(auto elim: ahm_invar_auxE)\n  qed\n  thus \"?thesis1\" by(auto simp add: Let_def)\n\n  have \"ahm_\\<alpha>_aux ?a' = ahm_\\<alpha>_aux a |` (- {k})\"\n  proof\n    fix k' :: 'a\n    from inv have \"bounded_hashcode_nat (array_length a) k < array_length a\"\n      by(auto elim: ahm_invar_auxE simp add: bounded_hashcode_nat_bounds)\n    thus \"ahm_\\<alpha>_aux ?a' k' = (ahm_\\<alpha>_aux a |` (- {k})) k'\"\n      by(cases \"?h = bounded_hashcode_nat (array_length a) k'\")(auto simp add: restrict_map_def array_get_array_set_other delete_conv)\n  qed\n  thus ?thesis2 by(simp add: Let_def)\nqed\n\nlemma ahm_delete_impl:\n  \"map_delete ahm_\\<alpha> ahm_invar ahm_delete\"\nby(unfold_locales)(blast intro: ahm_delete_correct)+\n\nhide_const (open) HashMap ahm_empty bucket_ok ahm_invar ahm_\\<alpha> ahm_lookup\n  ahm_iteratei ahm_rehash hm_grow ahm_filled ahm_update ahm_delete\nhide_type (open) hashmap\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Collections/ICF/impl/ArrayHashMap_Impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6150878414043814, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.2716676956608397}}
{"text": "theory Post_Visibility_Traceback\n  imports Traceback_Intro\nbegin\n\nconsts PID :: postID\nconsts VIS :: vis\n\nsubsection \\<open>Tracing Back Post Visibility Status\\<close>\n\ntext \\<open>We prove the following traceback property:\nIf, at some point \\<open>t\\<close> on a system trace, the visibility of a post \\<open>PID\\<close>\nhas a value \\<open>VIS\\<close>, then one of the following holds:\n\\begin{itemize}\n\\item Either \\<open>VIS\\<close> is \\<open>FriendV\\<close> (i.e., friends-only) which is the default at post creation\n\\item Or the post's owner had issued a successful ``update visibility'' action setting the visibility to \\<open>VIS\\<close>,\nand no other successful update actions to \\<open>PID\\<close>'s visibility occur\nbetween the time of that action and \\<open>t\\<close>.\n\\end{itemize}\n\nThis will be captured in the predicate \\<open>proper\\<close>, and the main theorem states that \\<open>proper tr\\<close>\nholds for any trace \\<open>tr\\<close> that leads to post \\<open>PID\\<close> acquiring visibility \\<open>VIS\\<close>.\n\\<close>\n\n\ntext \\<open>\\<open>SNC uidd trn\\<close> means\n``The transaction \\<open>trn\\<close> is a successful post creation by user \\<open>uidd\\<close>'' \\<close>\n\nfun SNC :: \"userID \\<Rightarrow> (state,act,out) trans \\<Rightarrow> bool\" where\n\"SNC uidd (Trans s (Cact (cPost uid p pid tit)) ou s') = (ou = outOK \\<and> (uid,pid) = (uidd,PID))\"\n|\n\"SNC uidd _ = False\"\n\n\ntext \\<open>\\<open>SNVU uidd vvs trn\\<close> means\n\"The transaction \\<open>trn\\<close> is a successful post visibility update for \\<open>PID\\<close>, by user \\<open>uidd\\<close>, to value \\<open>vvs\\<close>'' \\<close>\n\nfun SNVU :: \"userID \\<Rightarrow> vis \\<Rightarrow> (state,act,out) trans \\<Rightarrow> bool\" where\n\"SNVU uidd vvs (Trans s (Uact (uVisPost uid p pid vs)) ou s') =\n   (ou = outOK \\<and> (uid,pid) = (uidd,PID) \\<and> vs = vvs)\"\n|\n\"SNVU uidd vvis _ = False\"\n\ndefinition proper :: \"(state,act,out) trans trace \\<Rightarrow> bool\" where\n\"proper tr \\<equiv>\n VIS = FriendV\n \\<or>\n (\\<exists> uid tr1 trn tr2 trnn tr3.\n    tr = tr1 @ trn # tr2 @ trnn # tr3 \\<and>\n    SNC uid trn \\<and> SNVU uid VIS trnn \\<and> (\\<forall> vis. never (SNVU uid vis) tr3))\"\n\n(*  *)\n\ndefinition proper1 :: \"(state,act,out) trans trace \\<Rightarrow> bool\" where\n\"proper1 tr \\<equiv>\n \\<exists> tr2 trnn tr3.\n    tr = tr2 @ trnn # tr3 \\<and>\n    SNVU (owner (srcOf trnn) PID) VIS trnn\"\n\nlemma not_never_ex:\nassumes \"\\<not> never P xs\"\nshows \"\\<exists> xs1 x xs2. xs = xs1 @ x # xs2 \\<and> P x \\<and> never P xs2\"\nusing assms proof(induct xs rule: rev_induct)\n  case (Nil)\n  thus ?case unfolding list_all_iff empty_iff by auto\nnext\n  case (snoc y ys)\n  show ?case\n  proof(cases \"P y\")\n    case True thus ?thesis using snoc\n    apply(intro exI[of _ ys]) apply(intro exI[of _ y] exI[of _ \"[]\"]) by auto\n  next\n    case False then obtain xs1 x xs2 where \"ys = xs1 @ x # xs2 \\<and> P x \\<and> never P xs2\"\n    using snoc by auto\n    thus ?thesis using snoc False\n    apply(intro exI[of _ xs1]) apply(intro exI[of _ x] exI[of _ \"xs2 ## y\"]) by auto\n  qed\nqed\n\nlemma SNVU_postIDs:\nassumes \"validTrans trn\" and \"SNVU uid vs trn\"\nshows \"PID \\<in>\\<in> postIDs (srcOf trn)\"\nproof(cases trn)\n  case (Trans s a ou s')\n  then show ?thesis\n    using assms\n    by (cases \"a\") (auto simp: all_defs elim: step_elims)\nqed\n\nlemma SNVU_visib:\nassumes \"validTrans trn\" and \"SNVU uid vs trn\"\nshows \"vis (tgtOf trn) PID = vs\"\nproof(cases trn)\n  case (Trans s a ou s')\n  then show ?thesis\n    using assms\n    by (cases \"a\") (auto simp: all_defs elim: step_elims)\nqed\n\nlemma owner_validTrans:\nassumes \"validTrans trn\" and \"PID \\<in>\\<in> postIDs (srcOf trn)\"\nshows \"owner (srcOf trn) PID = owner (tgtOf trn) PID\"\nproof(cases trn)\n  case (Trans s a ou s')\n  then show ?thesis\n    using assms\n    by (cases \"a\") (auto simp: all_defs elim: step_elims)\nqed\n\nlemma owner_valid:\nassumes \"valid tr\" and \"PID \\<in>\\<in> postIDs (srcOf (hd tr))\"\nshows \"owner (srcOf (hd tr)) PID = owner (tgtOf (last tr)) PID\"\nusing assms using owner_validTrans IDs_mono validTrans by induct auto\n\nlemma SNVU_vis_validTrans:\nassumes \"validTrans trn\" and \"PID \\<in>\\<in> postIDs (srcOf trn)\"\nand \"\\<forall> vs. \\<not> SNVU (owner (srcOf trn) PID) vs trn\"\nshows \"vis (srcOf trn) PID = vis (tgtOf trn) PID\"\nproof(cases trn)\n  case (Trans s a ou s')\n  then show ?thesis\n    using assms\n    by (cases \"a\") (auto simp: all_defs elim: step_elims)\nqed\n\nlemma SNVU_vis_valid:\nassumes \"valid tr\" and \"PID \\<in>\\<in> postIDs (srcOf (hd tr))\"\nand \"\\<forall> vis. never (SNVU (owner (srcOf (hd tr)) PID) vis) tr\"\nshows \"vis (srcOf (hd tr)) PID = vis (tgtOf (last tr)) PID\"\nusing assms proof induct\n  case (Singl)\n  thus ?case using SNVU_vis_validTrans by auto\nnext\n  case (Cons trn tr)\n  have n: \"PID \\<in>\\<in> postIDs (srcOf (hd tr))\"\n  using Cons by (simp add: IDs_mono(2) validTrans)\n  have v: \"\\<forall> vis. never (SNVU (owner (srcOf (hd tr)) PID) vis) tr\"\n  using Cons by (simp add: owner_validTrans)\n  have \"vis (srcOf trn) PID = vis (srcOf (hd tr)) PID\"\n  using Cons SNVU_vis_validTrans by auto\n  also have \"... = vis (tgtOf (last tr)) PID\"\n  using n v Cons(4) by auto\n  finally show ?case using Cons by auto\nqed\n\nlemma proper1_never:\nassumes vtr: \"valid tr\" and PID: \"PID \\<in>\\<in> postIDs (srcOf (hd tr))\"\nand tr: \"proper1 tr\" and v: \"vis (tgtOf (last tr)) PID = VIS\"\nshows \"\\<exists> tr2 trnn tr3.\n    tr = tr2 @ trnn # tr3 \\<and>\n    SNVU (owner (srcOf trnn) PID) VIS trnn \\<and> (\\<forall> vis. never (SNVU (owner (srcOf trnn) PID) vis) tr3)\"\nproof-\n  obtain tr2 trnn tr3 where\n  tr: \"tr = tr2 @ trnn # tr3\" and SNVU: \"SNVU (owner (srcOf trnn) PID) VIS trnn\"\n  using tr unfolding proper1_def by auto\n  define uid where \"uid \\<equiv> owner (srcOf trnn) PID\"\n  show ?thesis\n  proof(cases \"never (\\<lambda> trn. \\<exists> vis. SNVU uid vis trn) tr3\")\n    case True thus ?thesis using tr SNVU unfolding uid_def list_all_iff by blast\n  next\n    case False\n    from not_never_ex[OF this] obtain tr3a tr3n tr3b vs where tr3: \"tr3 = tr3a @ tr3n # tr3b\"\n    and SNVUtr3n: \"SNVU uid vs tr3n\" and n: \"\\<forall> vs. never (SNVU uid vs) tr3b\"\n    unfolding list_all_iff by blast\n    have trnn: \"validTrans trnn\" and\n    tr3n: \"validTrans tr3n\" and vtr3: \"valid tr3\" using tr unfolding tr tr3\n    by (metis Nil_is_append_conv append_self_conv2 list.distinct(1) tr tr3 valid_ConsE valid_append vtr)+\n    hence PID_trnn: \"PID \\<in>\\<in> postIDs (srcOf trnn)\" and\n    PID_tr3n: \"PID \\<in>\\<in> postIDs (srcOf tr3n)\" using SNVU_postIDs SNVU SNVUtr3n by auto\n    have vvv: \"valid (trnn # tr3a @ [tr3n])\"\n    using vtr unfolding tr tr3\n    by (smt Nil_is_append_conv append_self_conv2 hd_append2 list.distinct(1) list.sel(1)\n        valid_Cons_iff valid_append)\n    hence PID_tr3n': \"PID \\<in>\\<in> postIDs (tgtOf tr3n)\" using tr3n SNVUtr3n\n    by (simp add: IDs_mono(2) PID_tr3n validTrans)\n    from owner_valid[OF vvv] PID_trnn\n    have 000: \"owner (tgtOf tr3n) PID = uid\" unfolding uid_def by simp\n    hence 0: \"owner (srcOf tr3n) PID = uid\" using PID_tr3n owner_validTrans tr3n by blast\n    have 00: \"vs = vis (tgtOf tr3n) PID\" using SNVUtr3n tr3n SNVU_visib by auto\n    have vis: \"vs = VIS\"\n    proof(cases \"tr3b = []\")\n      case True\n      thus ?thesis using v 00 unfolding tr tr3 by simp\n    next\n      case False\n      hence tgt: \"tgtOf tr3n = srcOf (hd tr3b)\" and tr3b: \"valid tr3b\" using vtr3 unfolding tr3\n      apply (metis valid_append list.distinct(2) self_append_conv2 valid_ConsE)\n      by (metis False append_self_conv2 list.distinct(1) tr3 valid_Cons_iff valid_append vtr3)\n      show ?thesis unfolding 00 tgt\n        using v False PID_tr3n'\n        using SNVU_vis_valid[OF tr3b _ n[unfolded 000[symmetric] tgt]]\n      unfolding tr tr3 tgt by simp\n    qed\n    show ?thesis apply(intro exI[of _ \"tr2 @ trnn # tr3a\"])\n    apply(intro exI[of _ tr3n] exI[of _ tr3b])\n    using SNVUtr3n n unfolding tr tr3 0 vis by simp\n  qed\nqed\n\n\n(* *)\n\nlemma SNVU_validTrans:\nassumes \"validTrans trn\"\nand \"PID \\<in>\\<in> postIDs (srcOf trn)\"\nand \"vis (srcOf trn) PID \\<noteq> VIS\"\nand \"vis (tgtOf trn) PID = VIS\"\nshows \"SNVU (owner (srcOf trn) PID) VIS trn\"\nproof(cases trn)\n  case (Trans s a ou s')\n  then show ?thesis\n    using assms\n    by (cases \"a\") (auto simp: all_defs elim: step_elims)\nqed\n\nlemma valid_mono_postID:\nassumes \"valid tr\"\nand \"PID \\<in>\\<in> postIDs (srcOf (hd tr))\"\nshows \"PID \\<in>\\<in> postIDs (tgtOf (last tr))\"\nusing assms proof induct\n  case (Singl trn)\n  then show ?case using IDs_mono(2) by (cases trn) auto\nnext\n  case (Cons trn tr)\n  then show ?case using IDs_mono(2) by (cases trn) auto\nqed\n\nlemma proper1_valid:\nassumes V: \"VIS \\<noteq> FriendV\"\nand a: \"valid tr\"\n\"PID \\<in>\\<in> postIDs (srcOf (hd tr))\"\n\"vis (srcOf (hd tr)) PID \\<noteq> VIS\"\n\"vis (tgtOf (last tr)) PID = VIS\"\nshows \"proper1 tr\"\nusing a unfolding valid_valid2 proof induct\n  case (Singl trn)\n  then show ?case unfolding proper1_def using SNVU_validTrans\n  by (intro exI[of _ \"owner (srcOf trn) PID\"] exI[of _ \"[]\"] exI[of _ trn]) auto\nnext\n  case (Rcons tr trn)\n  hence \"PID \\<in>\\<in> postIDs (srcOf (hd tr))\" using Rcons by simp\n  from valid_mono_postID[OF \\<open>valid2 tr\\<close>[unfolded valid2_valid] this]\n  have \"PID \\<in>\\<in> postIDs (tgtOf (last tr))\" by simp\n  hence 0: \"PID \\<in>\\<in> postIDs (srcOf trn)\" using Rcons by simp\n  show ?case\n  proof(cases \"vis (srcOf trn) PID = VIS\")\n    case False\n    hence \"SNVU (owner (srcOf trn) PID) VIS trn\"\n    apply (intro SNVU_validTrans) using 0 Rcons by auto\n    thus ?thesis unfolding proper1_def\n    by (intro exI[of _ tr] exI[of _ trn] exI[of _ \"[]\"]) auto\n  next\n    case True\n    hence \"proper1 tr\" using Rcons by auto\n    then obtain trr trnn tr3 where\n    tr: \"tr = trr @ trnn # tr3\" and SNVU: \"SNVU (owner (srcOf trnn) PID) VIS trnn\"\n    unfolding proper1_def using V by auto\n    have \"vis (tgtOf trn) PID = VIS\" using Rcons.prems by auto\n    thus ?thesis\n    using SNVU V unfolding proper1_def tr\n    by(intro exI[of _ trr] exI[of _ trnn] exI[of _ \"tr3 ## trn\"]) auto\n  qed\nqed\n\nlemma istate_postIDs:\n\"\\<not> PID \\<in>\\<in> postIDs istate\"\nunfolding istate_def by simp\n\n\n(* *)\n\ndefinition proper2 :: \"(state,act,out) trans trace \\<Rightarrow> bool\" where\n\"proper2 tr \\<equiv>\n \\<exists> uid tr1 trn tr2.\n    tr = tr1 @ trn # tr2 \\<and> SNC uid trn\"\n\nlemma SNC_validTrans:\nassumes \"VIS \\<noteq> FriendV\" and \"validTrans trn\"\nand \"\\<not> PID \\<in>\\<in> postIDs (srcOf trn)\"\nand \"PID \\<in>\\<in> postIDs (tgtOf trn)\"\nshows \"\\<exists> uid. SNC uid trn\"\nproof(cases trn)\n  case (Trans s a ou s')\n  then show ?thesis\n    using assms\n    by (cases \"a\") (auto simp: all_defs elim: step_elims)\nqed\n\nlemma proper2_valid:\nassumes V: \"VIS \\<noteq> FriendV\"\nand a: \"valid tr\"\n\"\\<not> PID \\<in>\\<in> postIDs (srcOf (hd tr))\"\n\"PID \\<in>\\<in> postIDs (tgtOf (last tr))\"\nshows \"proper2 tr\"\nusing a unfolding valid_valid2 proof induct\n  case (Singl trn)\n  then obtain uid where \"SNC uid trn\" using SNC_validTrans V by auto\n  thus ?case unfolding proper2_def using SNC_validTrans\n  by (intro exI[of _ uid] exI[of _ \"[]\"]  exI[of _ trn]) auto\nnext\n  case (Rcons tr trn)\n  show ?case\n  proof(cases \"PID \\<in>\\<in> postIDs (srcOf trn)\")\n    case False\n    then obtain uid where \"SNC uid trn\"\n    using Rcons SNC_validTrans V by auto\n    thus ?thesis unfolding proper2_def\n    apply - apply (intro exI[of _ uid] exI[of _ tr]) by (intro exI[of _ trn] exI[of _ \"[]\"]) auto\n  next\n    case True\n    hence \"proper2 tr\" using Rcons by auto\n    then obtain uid tr1 trnn tr2 where\n    tr: \"tr = tr1 @ trnn # tr2\" and SFRC: \"SNC uid trnn\"\n    unfolding proper2_def by auto\n    have \"PID \\<in>\\<in> postIDs (tgtOf trn)\" using V Rcons.prems by auto\n    show ?thesis using SFRC unfolding proper2_def tr\n    apply - apply (intro exI[of _ uid] exI[of _ tr1])\n    by (intro exI[of _ trnn] exI[of _ \"tr2 ## trn\"]) simp\n  qed\nqed\n\nlemma proper2_valid_istate:\nassumes V: \"VIS \\<noteq> FriendV\"\nand a: \"valid tr\"\n\"srcOf (hd tr) = istate\"\n\"PID \\<in>\\<in> postIDs (tgtOf (last tr))\"\nshows \"proper2 tr\"\nusing proper2_valid assms istate_postIDs by auto\n\n(* *)\n\nlemma SNC_visPost:\nassumes \"VIS \\<noteq> FriendV\"\nand \"validTrans trn\" \"SNC uid trn\" and \"reach (srcOf trn)\"\nshows \"vis (tgtOf trn) PID \\<noteq> VIS\"\nproof(cases trn)\n  case (Trans s a ou s')\n  then show ?thesis\n    using assms\n    apply (cases \"a\") apply (auto simp: all_defs elim: step_elims)\n    subgoal for x2 apply(cases x2)\n      using reach_not_postIDs_vis_FriendV\n      by (auto simp: all_defs elim: step_elims) .\nqed\n\nlemma SNC_postIDs:\nassumes \"validTrans trn\" and \"SNC uid trn\"\nshows \"PID \\<in>\\<in> postIDs (tgtOf trn)\"\nproof(cases trn)\n  case (Trans s a ou s')\n  then show ?thesis\n    using assms\n    by (cases \"a\") (auto simp: all_defs elim: step_elims)\nqed\n\nlemma SNC_owner:\nassumes \"validTrans trn\" and \"SNC uid trn\"\nshows \"uid = owner (tgtOf trn) PID\"\nproof(cases trn)\n  case (Trans s a ou s')\n  then show ?thesis\n    using assms\n    by (cases \"a\") (auto simp: all_defs elim: step_elims)\nqed\n\ntheorem post_accountability:\nassumes v: \"valid tr\" and i: \"srcOf (hd tr) = istate\"\nand PIDin: \"PID \\<in>\\<in> postIDs (tgtOf (last tr))\"\nand PID: \"vis (tgtOf (last tr)) PID = VIS\"\nshows \"proper tr\"\nproof(cases \"VIS = FriendV\")\n  case True thus ?thesis unfolding proper_def by auto\nnext\n  case False\n  have \"proper2 tr\" using proper2_valid_istate[OF False v i PIDin] .\n  then obtain uid tr1 trn trr where\n  tr: \"tr = tr1 @ trn # trr\" and SNC: \"SNC uid trn\" unfolding proper2_def by auto\n  hence trn: \"validTrans trn\" and r: \"reach (srcOf trn)\" using v unfolding tr\n    apply (metis list.distinct(2) self_append_conv2 valid_ConsE valid_append)\n    by (metis (mono_tags, lifting) append_Cons hd_append i list.sel(1) reach.simps tr v valid_append valid_init_reach)\n  hence N: \"PID \\<in>\\<in> postIDs (tgtOf trn)\" \"vis (tgtOf trn) PID \\<noteq> VIS\"\n  using SNC_postIDs SNC_visPost False SNC by auto\n  hence trrNE: \"trr \\<noteq> []\" and 1: \"last tr = last trr\" using PID unfolding tr by auto\n  hence trr_v: \"valid trr\" using v unfolding tr\n  by (metis valid_Cons_iff append_self_conv2 list.distinct(1) valid_append)\n  have 0: \"tgtOf trn = srcOf (hd trr)\" using v trrNE unfolding tr\n  by (metis valid_append list.distinct(2) self_append_conv2 valid_ConsE)\n  have \"proper1 trr\" using proper1_valid[OF False trr_v N[unfolded 0] PID[unfolded 1]] .\n  from proper1_never[OF trr_v N(1)[unfolded 0] this PID[unfolded 1]] obtain tr2 trnn tr3 where\n  trr: \"trr = tr2 @ trnn # tr3\" and SNVU: \"SNVU (owner (srcOf trnn) PID) VIS trnn\"\n  and vis: \"\\<forall> vis. never (SNVU (owner (srcOf trnn) PID) vis) tr3\" by auto\n  have 00: \"srcOf (hd (tr2 @ [trnn])) = tgtOf trn\" using v unfolding tr trr\n  by (metis \"0\" append_self_conv2 hd_append2 list.sel(1) trr)\n  have trnn: \"validTrans trnn\" using trr_v unfolding trr\n  by (metis valid_Cons_iff append_self_conv2 list.distinct(1) valid_append)\n  have vv: \"valid (tr2 @ [trnn])\"\n  using v unfolding tr trr\n  by (smt Nil_is_append_conv append_self_conv2 hd_append2 list.distinct(1) list.sel(1)\n        valid_Cons_iff valid_append)\n  have \"uid = owner (tgtOf trn) PID\" using SNC trn SNC_owner by auto\n  also have \"... = owner (tgtOf trnn) PID\"\n  using owner_valid[OF vv] N(1) unfolding 00 by simp\n  also have \"... = owner (srcOf trnn) PID\"\n  using SNVU trnn SNVU_postIDs owner_validTrans by auto\n  finally have uid: \"uid = owner (srcOf trnn) PID\" .\n  show ?thesis unfolding proper_def\n  apply(rule disjI2)\n  apply(intro exI[of _ uid] exI[of _ tr1])\n  apply(rule exI[of _ trn], rule exI[of _ tr2])\n  apply(intro exI[of _ trnn] exI[of _ tr3])\n  using SNC SNVU vis unfolding tr trr uid by auto\nqed\n\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/CoSMed/Traceback_Properties/Post_Visibility_Traceback.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5389832354982647, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.2715969781793041}}
{"text": "section {* Reactive designs *}\n\ntheory utp_rea_designs\n  imports utp_reactive\nbegin\n\nsubsection {* Preliminaries *} \n\ntext {* R3 as presented in the UTP book and related publications is not sensitive to state, although\n  reactive designs often need this property. Thus is is necessary to use a modification of R3\n  from Butterfield et al. (2009) that explicitly states that intermediate\n  waiting states do not propogate final state variables. In order to do this we need an additional\n  observational variable that capture the program state that we call $st$. *}\n\nalphabet 's rsp_vars = \"'t rp_vars\" +\n  st :: 's\n\ntype_synonym ('s,'t,'\\<alpha>) rsp = \"('t, ('s, '\\<alpha>) rsp_vars_scheme) rp\"\ntype_synonym ('s,'t,'\\<alpha>,'\\<beta>) rel_rsp  = \"(('s,'t,'\\<alpha>) rsp, ('s,'t,'\\<beta>) rsp) rel\"\ntype_synonym ('s,'t,'\\<alpha>) hrel_rsp  = \"('s,'t,'\\<alpha>) rsp hrel\"\n\ntranslations\n  (type) \"('s,'t,'\\<alpha>) rsp\" <= (type) \"('t, ('s, '\\<alpha>) rsp_vars_scheme) rp_vars_ext des\"\n  (type) \"('s,'t,'\\<alpha>,'\\<beta>) rel_rp\" <= (type) \"(('s,'t,'\\<alpha>) rsp, (_,_,'\\<beta>) rsp) rel\"\n\nnotation rsp_vars_child_lens\\<^sub>a (\"\\<Sigma>\\<^sub>s\")\nnotation rsp_vars_child_lens (\"\\<Sigma>\\<^sub>S\")\n\nabbreviation lift_state_rel (\"\\<lceil>_\\<rceil>\\<^sub>S\")\nwhere \"\\<lceil>P\\<rceil>\\<^sub>S \\<equiv> P \\<oplus>\\<^sub>p (st \\<times>\\<^sub>L st)\"\n\nabbreviation lift_state_pre (\"\\<lceil>_\\<rceil>\\<^sub>S\\<^sub><\")\nwhere \"\\<lceil>p\\<rceil>\\<^sub>S\\<^sub>< \\<equiv> \\<lceil>\\<lceil>p\\<rceil>\\<^sub><\\<rceil>\\<^sub>S\"\n\nsyntax\n  \"_svid_st_alpha\"  :: \"svid\" (\"\\<Sigma>\\<^sub>S\")\n\ntranslations\n  \"_svid_st_alpha\" => \"CONST rsp_vars_child_lens\"\n\ninterpretation alphabet_state:\n  lens_interp \"\\<lambda>(ok, wait, tr, r). (ok, wait, tr, st\\<^sub>v r, more r)\"\napply (unfold_locales)\napply (rule injI)\napply (clarsimp)\ndone\n\ninterpretation alphabet_state_rel: lens_interp \"\\<lambda>(ok, ok', wait, wait', tr, tr', r, r').\n  (ok, ok', wait, wait', tr, tr', st\\<^sub>v r, st\\<^sub>v r', more r, more r')\"\napply (unfold_locales)\napply (rule injI)\napply (clarsimp)\ndone\n\nlemma st'_unrest_st_lift_pred [unrest]:\n  \"$st\\<acute> \\<sharp> \\<lceil>a\\<rceil>\\<^sub>S\\<^sub><\"\n  by (pred_auto)\n\nsubsection {* Healthiness conditions *}\n\ntext {* The fundamental healthiness conditions of reactive designs are $RD1$ and $RD2$ which\n  are essentially modifications of H1 and H2 from the theory of designs, viewed through\n  the prism of reactive processes. *}\n\ndefinition [upred_defs]: \"RD1(P) = (P \\<or> (\\<not> $ok \\<and> $tr \\<le>\\<^sub>u $tr\\<acute>))\"\ndefinition [upred_defs]: \"RD2(P) = H2(P)\"\n\ntext {* RD2 is just H2 since the type system will automatically have J identifying the reactive\n        variables as required. *}\n\nlemma RD1_idem: \"RD1(RD1(P)) = RD1(P)\"\n  by (rel_auto)\n\nlemma RD1_Idempotent: \"Idempotent RD1\"\n  by (simp add: Idempotent_def RD1_idem)\n\nlemma RD1_mono: \"P \\<sqsubseteq> Q \\<Longrightarrow> RD1(P) \\<sqsubseteq> RD1(Q)\"\n  by (rel_auto)\n\nlemma RD1_Monotonic: \"Monotonic RD1\"\n  using Monotonic_def RD1_mono by blast\n  \nlemma RD1_Continuous: \"Continuous RD1\"\n  unfolding Continuous_def SUP_def apply rel_simp\n  unfolding  SUP_def  \n  apply transfer apply auto \ndone\n\n\nlemma RD2_idem: \"RD2(RD2(P)) = RD2(P)\"\n  by (simp add: H2_idem RD2_def)\n\nlemma RD2_Idempotent: \"Idempotent RD2\"\n  by (simp add: Idempotent_def RD2_idem)\n\nlemma RD2_mono: \"P \\<sqsubseteq> Q \\<Longrightarrow> RD2(P) \\<sqsubseteq> RD2(Q)\"\n  by (simp add: H2_def RD2_def seqr_mono)\n\nlemma RD2_Monotonic: \"Monotonic RD2\"\n  using Monotonic_def RD2_mono by blast\n\nlemma RD2_Continuous: \"Continuous RD2\"\n  apply (rel_auto)\n  unfolding  SUP_def apply rel_simp\n  unfolding  SUP_def INF_def\n  apply transfer apply force \n  apply rel_simp\n  unfolding  SUP_def INF_def\n  apply transfer apply force\n  apply rel_simp\n  unfolding  SUP_def INF_def\n  apply transfer \n  apply rel_simp\n   unfolding  SUP_def INF_def\n  apply transfer apply force\ndone\n\n\nlemma RD1_RD2_commute: \"RD1(RD2(P)) = RD2(RD1(P))\"\n  by (rel_auto)\n\nlemma RD1_R1_commute: \"RD1(R1(P)) = R1(RD1(P))\"\n  by (rel_auto)\n\nlemma RD1_R2c_commute: \"RD1(R2c(P)) = R2c(RD1(P))\"\n  by (rel_auto)\n\nlemma RD1_via_R1: \"R1(H1(P)) = RD1(R1(P))\"\n  by (rel_auto)\n     \ndefinition skip_rea :: \"('t::ordered_cancel_monoid_diff, '\\<alpha>) hrel_rp\" (\"II\\<^sub>r\") where\nskip_rea_def [urel_defs]: \"II\\<^sub>r = (II \\<or> (\\<not> $ok \\<and> $tr \\<le>\\<^sub>u $tr\\<acute>))\"\n\ndefinition skip_srea :: \"('s, 't::ordered_cancel_monoid_diff, '\\<alpha>) hrel_rsp\" (\"II\\<^sub>R\") where\nskip_srea_def [urel_defs]: \"II\\<^sub>R = ((\\<exists> $st \\<bullet> II\\<^sub>r) \\<triangleleft> $wait \\<triangleright> II\\<^sub>r)\"\n  \ndefinition R3c_def [upred_defs]: \"R3c(P) = (II\\<^sub>r \\<triangleleft> $wait \\<triangleright> P)\"\n\ndefinition R3h_def [upred_defs]: \"R3h(P) = ((\\<exists> $st \\<bullet> II\\<^sub>r) \\<triangleleft> $wait \\<triangleright> P)\"\n\nlemma R3c_idem: \"R3c(R3c(P)) = R3c(P)\"\n  by (rel_auto)\n\nlemma R3c_Idempotent: \"Idempotent R3c\"\n  by (simp add: Idempotent_def R3c_idem)\n\nlemma R3c_mono: \"P \\<sqsubseteq> Q \\<Longrightarrow> R3c(P) \\<sqsubseteq> R3c(Q)\"\n  by (rel_auto)\n\nlemma R3c_Monotonic: \"Monotonic R3c\"\n  by (simp add: Monotonic_def R3c_mono)\n\nlemma R3c_Continuous: \"Continuous R3c\"\n  unfolding Continuous_def SUP_def\n  apply rel_simp+ \n  unfolding SUP_def  \n  apply transfer apply auto\ndone\n\nlemma R3h_idem: \"R3h(R3h(P)) = R3h(P)\"\n  by (rel_auto)\n\nlemma R3h_Idempotent: \"Idempotent R3h\"\n  by (simp add: Idempotent_def R3h_idem)\n\nlemma R3h_mono: \"P \\<sqsubseteq> Q \\<Longrightarrow> R3h(P) \\<sqsubseteq> R3h(Q)\"\n  by (rel_auto)\n\nlemma R3h_Monotonic: \"Monotonic R3h\"\n  by (simp add: Monotonic_def R3h_mono)\n\nlemma R3h_Continuous: \"Continuous R3h\"\n  by (rel_auto)\n\nlemma R3h_inf: \"R3h(P \\<sqinter> Q) = R3h(P) \\<sqinter> R3h(Q)\"\n  by (rel_auto)\n\nlemma R3h_UINF:\n  \"A \\<noteq> {} \\<Longrightarrow> R3h(\\<Sqinter> i \\<in> A \\<bullet> P(i)) = (\\<Sqinter> i \\<in> A \\<bullet> R3h(P(i)))\"\n  by (rel_auto)\n\nlemma R3h_cond: \"R3h(P \\<triangleleft> b \\<triangleright> Q) = (R3h(P) \\<triangleleft> b \\<triangleright> R3h(Q))\"\n  by (rel_auto)\n\nlemma R3c_via_RD1_R3: \"RD1(R3(P)) = R3c(RD1(P))\"\n  by (rel_auto)\n\nlemma R3c_RD1_def: \"P is RD1 \\<Longrightarrow> R3c(P) = RD1(R3(P))\"\n  by (simp add: Healthy_if R3c_via_RD1_R3)\n\nlemma RD1_R3c_commute: \"RD1(R3c(P)) = R3c(RD1(P))\"\n  by (rel_auto)\n\nlemma RD2_R3c_commute: \"RD2(R3c(P)) = R3c(RD2(P))\"\n  by (rel_auto)\n\nlemma R1_R3c_commute: \"R1(R3c(P)) = R3c(R1(P))\"\n  by (rel_auto)\n\nlemma R2c_R3c_commute: \"R2c(R3c(P)) = R3c(R2c(P))\"\n  apply (rel_auto) using minus_zero_eq by blast+\n\nlemma R1_R3h_commute: \"R1(R3h(P)) = R3h(R1(P))\"\n  by (rel_auto)\n\nlemma R2c_R3h_commute: \"R2c(R3h(P)) = R3h(R2c(P))\"\n  apply (rel_auto) using minus_zero_eq by blast+\n\nlemma RD1_R3h_commute: \"RD1(R3h(P)) = R3h(RD1(P))\"\n  by (rel_auto)\n\nlemma RD2_R3h_commute: \"RD2(R3h(P)) = R3h(RD2(P))\"\n  by (rel_auto)\n\nlemma R3c_cancels_R3: \"R3c(R3(P)) = R3c(P)\"\n  by (rel_auto)\n\nlemma R3_cancels_R3c: \"R3(R3c(P)) = R3(P)\"\n  by (rel_auto)\n\nlemma R3h_cancels_R3c: \"R3h(R3c(P)) = R3h(P)\"\n  by (rel_auto)\n\nlemma skip_rea_RD1_skip: \"II\\<^sub>r = RD1(II)\"\n  by (rel_auto)\n\nlemma R1_skip_rea: \"R1(II\\<^sub>r) = II\\<^sub>r\"\n  by (rel_auto)\n\nlemma skip_rea_form: \"II\\<^sub>r = (II \\<triangleleft> $ok \\<triangleright> R1(true))\"\n  by (rel_auto)\n\nlemma R2c_skip_rea: \"R2c II\\<^sub>r = II\\<^sub>r\"\n  by (simp add: skip_rea_def R2c_and R2c_disj R2c_skip_r R2c_not R2c_ok R2c_tr'_ge_tr)\n\ndefinition RH :: \"('t::ordered_cancel_monoid_diff,'\\<alpha>) hrel_rp \\<Rightarrow> ('t,'\\<alpha>) hrel_rp\" (\"\\<^bold>R\")\nwhere [upred_defs]: \"RH(P) = R1(R2c(R3c(P)))\"\n\ndefinition RHS :: \"('s,'t::ordered_cancel_monoid_diff,'\\<alpha>) hrel_rsp \\<Rightarrow> ('s,'t,'\\<alpha>) hrel_rsp\" (\"\\<^bold>R\\<^sub>s\")\nwhere [upred_defs]: \"RHS(P) = R1(R2c(R3h(P)))\"\n\ndefinition RD :: \"('t::ordered_cancel_monoid_diff,'\\<alpha>) hrel_rp \\<Rightarrow> ('t,'\\<alpha>) hrel_rp\"\nwhere [upred_defs]: \"RD(P) = RD1(RD2(RP(P)))\"\n\ndefinition SRD :: \"('s,'t::ordered_cancel_monoid_diff,'\\<alpha>) hrel_rsp \\<Rightarrow> ('s,'t,'\\<alpha>) hrel_rsp\"\nwhere [upred_defs]: \"SRD(P) = RD1(RD2(RHS(P)))\"\n\nlemma RH_comp: \"RH = R1 \\<circ> R2c \\<circ> R3c\"\n  by (auto simp add: RH_def)\n\nlemma RHS_comp: \"RHS = R1 \\<circ> R2c \\<circ> R3h\"\n  by (auto simp add: RHS_def)\n\nlemma RD_comp: \"RD = RD1 \\<circ> RD2 \\<circ> RP\"\n  by (auto simp add: RD_def)\n\nlemma SRD_comp: \"SRD = RD1 \\<circ> RD2 \\<circ> RHS\"\n  by (auto simp add: SRD_def)\n\nlemma RH_idem: \"\\<^bold>R(\\<^bold>R(P)) = \\<^bold>R(P)\"\n  by (simp add: R1_R2c_commute R1_R3c_commute R1_idem R2c_R3c_commute R2c_idem R3c_idem RH_def)\n\nlemma RH_Idempotent: \"Idempotent \\<^bold>R\"\n  by (simp add: Idempotent_def RH_idem)\n\nlemma RH_Monotonic: \"Monotonic \\<^bold>R\"\n  by (metis Monotonic_def R1_Monotonic R2c_Monotonic R3c_mono RH_def)\n\nlemma RH_Continuous: \"Continuous \\<^bold>R\"\n  by (simp add: Continuous_comp R1_Continuous R2c_Continuous R3c_Continuous RH_comp)\n\nlemma RHS_idem: \"\\<^bold>R\\<^sub>s(\\<^bold>R\\<^sub>s(P)) = \\<^bold>R\\<^sub>s(P)\"\n  by (simp add: R1_R2c_is_R2 R1_R3h_commute R2_idem R2c_R3h_commute R3h_idem RHS_def)\n\nlemma RHS_Idempotent: \"Idempotent \\<^bold>R\\<^sub>s\"\n  by (simp add: Idempotent_def RHS_idem)\n\nlemma RHS_Monotonic: \"Monotonic \\<^bold>R\\<^sub>s\"\n  by (simp add: Monotonic_def R1_R2c_is_R2 R2_mono R3h_mono RHS_def)\n\nlemma RHS_mono: \"P \\<sqsubseteq> Q \\<Longrightarrow> \\<^bold>R\\<^sub>s(P) \\<sqsubseteq> \\<^bold>R\\<^sub>s(Q)\"\n  using Monotonic_def RHS_Monotonic by blast\n\nlemma RHS_Continuous: \"Continuous \\<^bold>R\\<^sub>s\"\n  by (simp add: Continuous_comp R1_Continuous R2c_Continuous R3h_Continuous RHS_comp)\n\nlemma RHS_inf: \"\\<^bold>R\\<^sub>s(P \\<sqinter> Q) = \\<^bold>R\\<^sub>s(P) \\<sqinter> \\<^bold>R\\<^sub>s(Q)\"\n  using Continuous_Disjunctous Disjunctuous_def RHS_Continuous by auto\n\nlemma RHS_INF:\n  \"A \\<noteq> {} \\<Longrightarrow> \\<^bold>R\\<^sub>s(\\<Sqinter> i \\<in> A \\<bullet> P(i)) = (\\<Sqinter> i \\<in> A \\<bullet> \\<^bold>R\\<^sub>s(P(i)))\"\n  by (simp add: RHS_def R3h_UINF R2c_USUP R1_USUP)\n\nlemma RHS_cond: \"\\<^bold>R\\<^sub>s(P \\<triangleleft> b \\<triangleright> Q) = (\\<^bold>R\\<^sub>s(P) \\<triangleleft> R2c b \\<triangleright> \\<^bold>R\\<^sub>s(Q))\"\n  by (simp add: RHS_def R3h_cond R2c_condr R1_cond)\n\nlemma RD_alt_def: \"RD(P) = RD1(RD2(\\<^bold>R(P)))\"\n  by (simp add: R3c_via_RD1_R3 RD1_R1_commute RD1_R2c_commute RD1_R3c_commute RD1_RD2_commute RH_def RD_def RP_def)\n\nlemma RD1_RH_commute: \"RD1(\\<^bold>R(P)) = \\<^bold>R(RD1(P))\"\n  by (simp add: RD1_R1_commute RD1_R2c_commute RD1_R3c_commute RH_def)\n\nlemma RD2_RH_commute: \"RD2(\\<^bold>R(P)) = \\<^bold>R(RD2(P))\"\n  by (metis R1_H2_commute R2c_H2_commute RD2_R3c_commute RD2_def RH_def)\n\nlemma RD_idem: \"RD(RD(P)) = RD(P)\"\n  by (simp add: RD_alt_def RD1_RH_commute RD2_RH_commute RD1_RD2_commute RD2_idem RD1_idem RH_idem)\n\nlemma RD_Monotonic: \"Monotonic RD\"\n  by (metis Monotonic_def RD1_mono RD2_Monotonic RD_alt_def RH_Monotonic)\n\nlemma RD_Continuous: \"Continuous RD\"\n  by (simp add: Continuous_comp RD1_Continuous RD2_Continuous RD_comp RP_Continuous)\n\nlemma R3_RD_RP: \"R3(RD(P)) = RP(RD1(RD2(P)))\"\n  by (metis (no_types, lifting) R1_R2c_is_R2 R2_R3_commute R3_cancels_R3c RD1_RH_commute RD2_RH_commute RD_alt_def RH_def RP_def)\n\nlemma RD1_RHS_commute: \"RD1(\\<^bold>R\\<^sub>s(P)) = \\<^bold>R\\<^sub>s(RD1(P))\"\n  by (simp add: RD1_R1_commute RD1_R2c_commute RD1_R3h_commute RHS_def)\n\nlemma RD2_RHS_commute: \"RD2(\\<^bold>R\\<^sub>s(P)) = \\<^bold>R\\<^sub>s(RD2(P))\"\n  by (metis R1_H2_commute R2c_H2_commute RD2_R3h_commute RD2_def RHS_def)\n\nlemma SRD_idem: \"SRD(SRD(P)) = SRD(P)\"\n  by (simp add: RD1_RD2_commute RD1_RHS_commute RD1_idem RD2_RHS_commute RD2_idem RHS_idem SRD_def)\n\nlemma SRD_Monotonic: \"Monotonic SRD\"\n  by (metis Monotonic_def RD1_mono RD2_Monotonic RHS_Monotonic SRD_def)\n\nlemma SRD_Continuous: \"Continuous SRD\"\n  by (simp add: Continuous_comp RD1_Continuous RD2_Continuous RHS_Continuous SRD_comp)\n\ntypedecl RDES\ntypedecl SRDES\n\nabbreviation \"RDES \\<equiv> UTHY(RDES, ('t::ordered_cancel_monoid_diff,'\\<alpha>) rp)\"\nabbreviation \"SRDES \\<equiv> UTHY(SRDES, ('s,'t::ordered_cancel_monoid_diff,'\\<alpha>) rsp)\"\n\noverloading\n  rdes_hcond   == \"utp_hcond :: (RDES, ('t::ordered_cancel_monoid_diff,'\\<alpha>) rp) uthy \\<Rightarrow> (('t,'\\<alpha>) rp \\<times> ('t,'\\<alpha>) rp) health\"\n  srdes_hcond   == \"utp_hcond :: (SRDES, ('s,'t::ordered_cancel_monoid_diff,'\\<alpha>) rsp) uthy \\<Rightarrow> (('s,'t,'\\<alpha>) rsp \\<times> ('s,'t,'\\<alpha>) rsp) health\"\nbegin\n  definition rdes_hcond :: \"(RDES, ('t::ordered_cancel_monoid_diff,'\\<alpha>) rp) uthy \\<Rightarrow> (('t,'\\<alpha>) rp \\<times> ('t,'\\<alpha>) rp) health\" where\n  [upred_defs]: \"rdes_hcond T = RD\"\n  definition srdes_hcond :: \"(SRDES, ('s,'t::ordered_cancel_monoid_diff,'\\<alpha>) rsp) uthy \\<Rightarrow> (('s,'t,'\\<alpha>) rsp \\<times> ('s,'t,'\\<alpha>) rsp) health\" where\n  [upred_defs]: \"srdes_hcond T = SRD\"\nend\n\ninterpretation rdes_theory: utp_theory \"UTHY(RDES, ('t::ordered_cancel_monoid_diff,'\\<alpha>) rp)\"\n  by (unfold_locales, simp_all add: rdes_hcond_def RD_idem)\n\ninterpretation rdes_theory_continuous: utp_theory_continuous \"UTHY(RDES, ('t::ordered_cancel_monoid_diff,'\\<alpha>) rp)\"\n  rewrites \"\\<And> P. P \\<in> carrier (uthy_order RDES) \\<longleftrightarrow> P is RD\"\n  and \"carrier (uthy_order RDES) \\<rightarrow> carrier (uthy_order RDES) \\<equiv> \\<lbrakk>RD\\<rbrakk>\\<^sub>H \\<rightarrow> \\<lbrakk>RD\\<rbrakk>\\<^sub>H\"\n  and \"le (uthy_order RDES) = op \\<sqsubseteq>\"\n  and \"eq (uthy_order RDES) = op =\"\n  by (unfold_locales, simp_all add: rdes_hcond_def RD_Continuous)\n\ninterpretation rdes_rea_galois:\n  galois_connection \"(RDES \\<leftarrow>\\<langle>RD1 \\<circ> RD2,R3\\<rangle>\\<rightarrow> REA)\"\nproof (simp add: mk_conn_def, rule galois_connectionI', simp_all add: utp_partial_order rdes_hcond_def rea_hcond_def)\n  show \"R3 \\<in> \\<lbrakk>RD\\<rbrakk>\\<^sub>H \\<rightarrow> \\<lbrakk>RP\\<rbrakk>\\<^sub>H\"\n    by (metis (no_types, lifting) Healthy_def' Pi_I R3_RD_RP RP_idem mem_Collect_eq)\n  show \"RD1 \\<circ> RD2 \\<in> \\<lbrakk>RP\\<rbrakk>\\<^sub>H \\<rightarrow> \\<lbrakk>RD\\<rbrakk>\\<^sub>H\"\n    by (simp add: Pi_iff Healthy_def, metis RD_def RD_idem)\n  show \"isotone (utp_order RD) (utp_order RP) R3\"\n    by (simp add: R3_Monotonic isotone_utp_orderI)\n  show \"isotone (utp_order RP) (utp_order RD) (RD1 \\<circ> RD2)\"\n    by (simp add: Monotonic_comp RD1_Monotonic RD2_Monotonic isotone_utp_orderI)\n  fix P :: \"('a, 'b) hrel_rp\"\n  assume \"P is RD\"\n  thus \"P \\<sqsubseteq> RD1 (RD2 (R3 P))\"\n    by (metis Healthy_if R3_RD_RP RD_def RP_idem eq_iff)\nnext\n  fix P :: \"('a, 'b) hrel_rp\"\n  assume a: \"P is RP\"\n  thus \"R3 (RD1 (RD2 P)) \\<sqsubseteq> P\"\n  proof -\n    have \"R3 (RD1 (RD2 P)) = RP (RD1 (RD2(P)))\"\n      by (metis Healthy_if R3_RD_RP RD_def a)\n    moreover have \"RD1(RD2(P)) \\<sqsubseteq> P\"\n      by (rel_auto)\n    ultimately show ?thesis\n      by (metis Healthy_if RP_mono a)\n  qed\nqed\n\ninterpretation rdes_rea_retract:\n  retract \"(RDES \\<leftarrow>\\<langle>RD1 \\<circ> RD2,R3\\<rangle>\\<rightarrow> REA)\"\n  by (unfold_locales, simp_all add: mk_conn_def utp_partial_order rdes_hcond_def rea_hcond_def)\n     (metis Healthy_if R3_RD_RP RD_def RP_idem eq_refl)\n\ninterpretation srdes_theory: utp_theory \"UTHY(SRDES, ('s,'t::ordered_cancel_monoid_diff,'\\<alpha>) rsp)\"\n  by (unfold_locales, simp_all add: srdes_hcond_def SRD_idem)\n\ninterpretation srdes_theory_continuous: utp_theory_continuous \"UTHY(SRDES, ('s,'t::ordered_cancel_monoid_diff,'\\<alpha>) rsp)\"\n  rewrites \"\\<And> P. P \\<in> carrier (uthy_order SRDES) \\<longleftrightarrow> P is SRD\"\n  and \"P is \\<H>\\<^bsub>SRDES\\<^esub> \\<longleftrightarrow> P is SRD\"\n  and \"carrier (uthy_order SRDES) \\<rightarrow> carrier (uthy_order SRDES) \\<equiv> \\<lbrakk>SRD\\<rbrakk>\\<^sub>H \\<rightarrow> \\<lbrakk>SRD\\<rbrakk>\\<^sub>H\"\n  and \"le (uthy_order SRDES) = op \\<sqsubseteq>\"\n  and \"eq (uthy_order SRDES) = op =\"\n  by (unfold_locales, simp_all add: srdes_hcond_def SRD_Continuous)\n\nlemma SRD_healths:\n  assumes \"P is SRD\"\n  shows \"P is R1\" \"P is R2\" \"P is R3h\" \"P is RD1\" \"P is RD2\"\n  apply (metis Healthy_def R1_idem RD1_RHS_commute RD2_RHS_commute RHS_def SRD_def assms)\n  apply (metis Healthy_def R1_R2c_is_R2 R2_idem RD1_RHS_commute RD2_RHS_commute RHS_def SRD_def assms)\n  apply (metis Healthy_def R1_R3h_commute R2c_R3h_commute R3h_idem RD1_R3h_commute RD2_R3h_commute RHS_def SRD_def assms)\n  apply (metis Healthy_def' RD1_idem SRD_def assms)\n  apply (metis Healthy_def' RD1_RD2_commute RD2_idem SRD_def assms)\ndone\n\nlemma SRD_intro:\n  assumes \"P is R1\" \"P is R2\" \"P is R3h\" \"P is RD1\" \"P is RD2\"\n  shows \"P is SRD\"\n  by (metis Healthy_def R1_R2c_is_R2 RHS_def SRD_def assms(2) assms(3) assms(4) assms(5))\n\nlemma R2_skip_rea: \"R2(II\\<^sub>r) = II\\<^sub>r\"\n  by (metis R1_R2c_is_R2 R1_skip_rea R2c_skip_rea)\n\nlemma skip_srea_form: \"II\\<^sub>R = ((\\<exists> $st \\<bullet> II) \\<triangleleft> $wait \\<triangleright> II) \\<triangleleft> $ok \\<triangleright> R1(true)\"\n  by (rel_auto)\n    \nlemma R2c_skip_srea: \"R2c(II\\<^sub>R) = II\\<^sub>R\"\n  apply (rel_auto) using minus_zero_eq by blast+\n\nlemma R3h_form: \"R3h(P) = II\\<^sub>R \\<triangleleft> $wait \\<triangleright> P\"\n  by (rel_auto)\n    \nlemma R3c_semir_form:\n  \"(R3c(P) ;; R3c(R1(Q))) = R3c(P ;; R3c(R1(Q)))\"\n  by (rel_simp, safe, auto intro: order_trans)\n\nlemma R3h_semir_form:\n  \"(R3h(P) ;; R3h(R1(Q))) = R3h(P ;; R3h(R1(Q)))\"\n  by (rel_simp, safe, auto intro: order_trans, blast+)\n\nlemma R3c_seq_closure:\n  assumes \"P is R3c\" \"Q is R3c\" \"Q is R1\"\n  shows \"(P ;; Q) is R3c\"\n  by (metis Healthy_def' R3c_semir_form assms)\n\nlemma R3h_seq_closure:\n  assumes \"P is R3h\" \"Q is R3h\" \"Q is R1\"\n  shows \"(P ;; Q) is R3h\"\n  by (metis Healthy_def' R3h_semir_form assms)\n\nlemma R3c_R3_left_seq_closure:\n  assumes \"P is R3\" \"Q is R3c\"\n  shows \"(P ;; Q) is R3c\"\nproof -\n  have \"(P ;; Q) = ((P ;; Q)\\<lbrakk>true/$wait\\<rbrakk> \\<triangleleft> $wait \\<triangleright> (P ;; Q))\"\n    by (metis cond_var_split cond_var_subst_right in_var_uvar wait_vwb_lens)\n  also have \"... = (((II \\<triangleleft> $wait \\<triangleright> P) ;; Q)\\<lbrakk>true/$wait\\<rbrakk> \\<triangleleft> $wait \\<triangleright> (P ;; Q))\"\n    by (metis Healthy_def' R3_def assms(1))\n  also have \"... = ((II\\<lbrakk>true/$wait\\<rbrakk> ;; Q) \\<triangleleft> $wait \\<triangleright> (P ;; Q))\"\n    by (subst_tac)\n  also have \"... = (((II \\<and> $wait\\<acute>) ;; Q) \\<triangleleft> $wait \\<triangleright> (P ;; Q))\"\n    by (metis (no_types, lifting) cond_def conj_pos_var_subst seqr_pre_var_out skip_var utp_pred.inf_left_idem wait_vwb_lens)\n  also have \"... = ((II\\<lbrakk>true/$wait\\<acute>\\<rbrakk> ;; Q\\<lbrakk>true/$wait\\<rbrakk>) \\<triangleleft> $wait \\<triangleright> (P ;; Q))\"\n    by (metis seqr_pre_transfer seqr_right_one_point true_alt_def uovar_convr upred_eq_true utp_rel.unrest_ouvar vwb_lens_mwb wait_vwb_lens)\n  also have \"... = ((II\\<lbrakk>true/$wait\\<acute>\\<rbrakk> ;; (II\\<^sub>r \\<triangleleft> $wait \\<triangleright> Q)\\<lbrakk>true/$wait\\<rbrakk>) \\<triangleleft> $wait \\<triangleright> (P ;; Q))\"\n    by (metis Healthy_def' R3c_def assms(2))\n  also have \"... = ((II\\<lbrakk>true/$wait\\<acute>\\<rbrakk> ;; II\\<^sub>r\\<lbrakk>true/$wait\\<rbrakk>) \\<triangleleft> $wait \\<triangleright> (P ;; Q))\"\n    by (subst_tac)\n  also have \"... = (((II \\<and> $wait\\<acute>) ;; II\\<^sub>r) \\<triangleleft> $wait \\<triangleright> (P ;; Q))\"\n    by (metis seqr_pre_transfer seqr_right_one_point true_alt_def uovar_convr upred_eq_true utp_rel.unrest_ouvar vwb_lens_mwb wait_vwb_lens)\n  also have \"... = ((II ;; II\\<^sub>r) \\<triangleleft> $wait \\<triangleright> (P ;; Q))\"\n    by (simp add: cond_def seqr_pre_transfer utp_rel.unrest_ouvar)\n  also have \"... = (II\\<^sub>r \\<triangleleft> $wait \\<triangleright> (P ;; Q))\"\n    by simp\n  also have \"... = R3c(P ;; Q)\"\n    by (simp add: R3c_def)\n  finally show ?thesis\n    by (simp add: Healthy_def')\nqed\n\nlemma R3c_cases: \"R3c(P) = ((II \\<triangleleft> $ok \\<triangleright> R1(true)) \\<triangleleft> $wait \\<triangleright> P)\"\n  by (rel_auto)\n\nlemma R3h_cases: \"R3h(P) = (((\\<exists> $st \\<bullet> II) \\<triangleleft> $ok \\<triangleright> R1(true)) \\<triangleleft> $wait \\<triangleright> P)\"\n  by (rel_auto)\n\nlemma R3c_subst_wait: \"R3c(P) = R3c(P \\<^sub>f)\"\n  by (simp add: R3c_def cond_var_subst_right)\n\nlemma R3h_subst_wait: \"R3h(P) = R3h(P \\<^sub>f)\"\n  by (simp add: R3h_cases cond_var_subst_right)\n\nlemma skip_rea_R1_lemma: \"II\\<^sub>r = R1($ok \\<Rightarrow> II)\"\n  by (rel_auto)\n\nsubsection {* Reactive design form *}\n\nlemma RD1_algebraic_intro:\n  assumes\n    \"P is R1\" \"(R1(true\\<^sub>h) ;; P) = R1(true\\<^sub>h)\" \"(II\\<^sub>r ;; P) = P\"\n  shows \"P is RD1\"\nproof -\n  have \"P = (II\\<^sub>r ;; P)\"\n    by (simp add: assms(3))\n  also have \"... = (R1($ok \\<Rightarrow> II) ;; P)\"\n    by (simp add: skip_rea_R1_lemma)\n  also have \"... = (((\\<not> $ok \\<and> R1(true)) ;; P) \\<or> P)\"\n    by (metis (no_types, lifting) R1_def seqr_left_unit seqr_or_distl skip_rea_R1_lemma skip_rea_def utp_pred.inf_top_left utp_pred.sup_commute)\n  also have \"... = (((R1(\\<not> $ok) ;; R1(true\\<^sub>h)) ;; P) \\<or> P)\"\n    by (rel_auto, metis order.trans)\n  also have \"... = ((R1(\\<not> $ok) ;; (R1(true\\<^sub>h) ;; P)) \\<or> P)\"\n    by (simp add: seqr_assoc)\n  also have \"... = ((R1(\\<not> $ok) ;; R1(true\\<^sub>h)) \\<or> P)\"\n    by (simp add: assms(2))\n  also have \"... = (R1(\\<not> $ok) \\<or> P)\"\n    by (rel_auto)\n  also have \"... = RD1(P)\"\n    by (rel_auto)\n  finally show ?thesis\n    by (simp add: Healthy_def)\nqed\n\ntheorem RD1_left_zero:\n  assumes \"P is R1\" \"P is RD1\"\n  shows \"(R1(true) ;; P) = R1(true)\"\nproof -\n  have \"(R1(true) ;; R1(RD1(P))) = R1(true)\"\n    by (rel_auto)\n  thus ?thesis\n    by (simp add: Healthy_if assms(1) assms(2))\nqed\n\ntheorem RD1_left_unit:\n  assumes \"P is R1\" \"P is RD1\"\n  shows \"(II\\<^sub>r ;; P) = P\"\nproof -\n  have \"(II\\<^sub>r ;; R1(RD1(P))) = R1(RD1(P))\"\n    by (rel_auto)\n  thus ?thesis\n    by (simp add: Healthy_if assms(1) assms(2))\nqed\n\nlemma RD1_alt_def:\n  assumes \"P is R1\"\n  shows \"RD1(P) = (P \\<triangleleft> $ok \\<triangleright> R1(true))\"\nproof -\n  have \"RD1(R1(P)) = (R1(P) \\<triangleleft> $ok \\<triangleright> R1(true))\"\n    by (rel_auto)\n  thus ?thesis\n    by (simp add: Healthy_if assms)\nqed\n\ntheorem RD1_algebraic:\n  assumes \"P is R1\"\n  shows \"P is RD1 \\<longleftrightarrow> (R1(true\\<^sub>h) ;; P) = R1(true\\<^sub>h) \\<and> (II\\<^sub>r ;; P) = P\"\n  using RD1_algebraic_intro RD1_left_unit RD1_left_zero assms by blast\n\nlemma RD1_reactive_design: \"RD1(\\<^bold>R(P \\<turnstile> Q)) = \\<^bold>R(P \\<turnstile> Q)\"\n  by (rel_auto)\n\nlemma RD2_reactive_design:\n  assumes \"$ok\\<acute> \\<sharp> P\" \"$ok\\<acute> \\<sharp> Q\"\n  shows \"RD2(\\<^bold>R(P \\<turnstile> Q)) = \\<^bold>R(P \\<turnstile> Q)\"\n  using assms\n  by (metis H2_design RD2_RH_commute RD2_def)\n\nlemma RD1_st_reactive_design: \"RD1(\\<^bold>R\\<^sub>s(P \\<turnstile> Q)) = \\<^bold>R\\<^sub>s(P \\<turnstile> Q)\"\n  by (rel_auto)\n\nlemma RD2_st_reactive_design:\n  assumes \"$ok\\<acute> \\<sharp> P\" \"$ok\\<acute> \\<sharp> Q\"\n  shows \"RD2(\\<^bold>R\\<^sub>s(P \\<turnstile> Q)) = \\<^bold>R\\<^sub>s(P \\<turnstile> Q)\"\n  using assms\n  by (metis H2_design RD2_RHS_commute RD2_def)\n\nlemma wait_false_design:\n  \"(P \\<turnstile> Q) \\<^sub>f = ((P \\<^sub>f) \\<turnstile> (Q \\<^sub>f))\"\n  by (rel_auto)\n\nlemma RD_RH_design_form:\n  \"RD(P) = \\<^bold>R((\\<not> P\\<^sup>f\\<^sub>f) \\<turnstile> P\\<^sup>t\\<^sub>f)\"\nproof -\n  have \"RD(P) = RD1(RD2(R1(R2c(R3c(P)))))\"\n    by (simp add: RD_alt_def RH_def)\n  also have \"... = RD1(H2(R1(R2s(R3c(P)))))\"\n    by (simp add: R1_R2s_R2c RD2_def)\n  also have \"... = RD1(R1(H2(R2s(R3c(P)))))\"\n    by (simp add: R1_H2_commute)\n  also have \"... = R1(H1(R1(H2(R2s(R3c(P))))))\"\n    by (simp add: R1_idem RD1_via_R1)\n  also have \"... = R1(H1(H2(R2s(R3c(R1(P))))))\"\n    by (simp add: R1_H2_commute R1_R2c_commute R1_R2s_R2c R1_R3c_commute RD1_via_R1)\n  also have \"... = R1(R2s(H1(H2(R3c(R1(P))))))\"\n    by (simp add: R2s_H1_commute R2s_H2_commute)\n  also have \"... = R1(R2s(H1(R3c(H2(R1(P))))))\"\n    by (metis RD2_R3c_commute RD2_def)\n  also have \"... = R2(R1(H1(R3c(H2(R1(P))))))\"\n    by (metis R1_R2_commute R1_idem R2_def)\n  also have \"... = R2(R3c(R1(\\<^bold>H(R1(P)))))\"\n    by (simp add: R1_R3c_commute RD1_R3c_commute RD1_via_R1)\n  also have \"... = RH(\\<^bold>H(R1(P)))\"\n    by (metis R1_R2s_R2c R1_R3c_commute R2_R1_form RH_def)\n  also have \"... = RH(\\<^bold>H(P))\"\n    by (simp add: R1_H2_commute R1_R2c_commute R1_R3c_commute R1_idem RD1_via_R1 RH_def)\n  also have \"... = RH((\\<not> P\\<^sup>f) \\<turnstile> P\\<^sup>t)\"\n    by (simp add: H1_H2_eq_design)\n  also have \"... = \\<^bold>R((\\<not> P\\<^sup>f\\<^sub>f) \\<turnstile> P\\<^sup>t\\<^sub>f)\"\n    by (metis (no_types, lifting) R3c_subst_wait RH_def subst_not wait_false_design)\n  finally show ?thesis .\nqed\n\nlemma RD_reactive_design:\n  assumes \"P is RD\"\n  shows \"\\<^bold>R((\\<not> P\\<^sup>f\\<^sub>f) \\<turnstile> P\\<^sup>t\\<^sub>f) = P\"\n  by (metis RD_RH_design_form Healthy_def' assms)\n\nlemma RD_RH_design:\n  assumes \"$ok\\<acute> \\<sharp> P\" \"$ok\\<acute> \\<sharp> Q\"\n  shows \"RD(\\<^bold>R(P \\<turnstile> Q)) = \\<^bold>R(P \\<turnstile> Q)\"\n  by (simp add: RD1_reactive_design RD2_reactive_design RD_alt_def RH_idem assms(1) assms(2))\n\nlemma RH_design_is_RD:\n  assumes \"$ok\\<acute> \\<sharp> P\" \"$ok\\<acute> \\<sharp> Q\"\n  shows \"\\<^bold>R(P \\<turnstile> Q) is RD\"\n  by (simp add: RD_RH_design Healthy_def' assms(1) assms(2))\n\nlemma SRD_RH_design_form:\n  \"SRD(P) = \\<^bold>R\\<^sub>s((\\<not> P\\<^sup>f\\<^sub>f) \\<turnstile> P\\<^sup>t\\<^sub>f)\"\nproof -\n  have \"SRD(P) = R1(R2c(R3h(RD1(RD2(R1(P))))))\"\n    by (metis (no_types, lifting) R1_H2_commute R1_R2c_commute R1_R3h_commute R1_idem R2c_H2_commute RD1_R1_commute RD1_R2c_commute RD1_R3h_commute RD2_R3h_commute RD2_def RHS_def SRD_def)\n  also have \"... = R1(R2s(R3h(\\<^bold>H(P))))\"\n    by (metis (no_types, lifting) R1_H2_commute R1_R2c_is_R2 R1_R3h_commute R2_R1_form RD1_via_R1 RD2_def)\n  also have \"... = \\<^bold>R\\<^sub>s(\\<^bold>H(P))\"\n    by (simp add: R1_R2s_R2c RHS_def)\n  also have \"... = \\<^bold>R\\<^sub>s((\\<not> P\\<^sup>f) \\<turnstile> P\\<^sup>t)\"\n    by (simp add: H1_H2_eq_design)\n  also have \"... = \\<^bold>R\\<^sub>s((\\<not> P\\<^sup>f\\<^sub>f) \\<turnstile> P\\<^sup>t\\<^sub>f)\"\n    by (metis (no_types, lifting) R3h_subst_wait RHS_def subst_not wait_false_design)\n  finally show ?thesis .\nqed\n\nlemma SRD_reactive_design:\n  assumes \"P is SRD\"\n  shows \"\\<^bold>R\\<^sub>s((\\<not> P\\<^sup>f\\<^sub>f) \\<turnstile> P\\<^sup>t\\<^sub>f) = P\"\n  by (metis SRD_RH_design_form Healthy_def' assms)\n\nlemma SRD_RH_design:\n  assumes \"$ok\\<acute> \\<sharp> P\" \"$ok\\<acute> \\<sharp> Q\"\n  shows \"SRD(\\<^bold>R\\<^sub>s(P \\<turnstile> Q)) = \\<^bold>R\\<^sub>s(P \\<turnstile> Q)\"\n  by (simp add: RD1_st_reactive_design RD2_st_reactive_design RHS_idem SRD_def assms(1) assms(2))\n\nlemma RHS_design_is_SRD:\n  assumes \"$ok\\<acute> \\<sharp> P\" \"$ok\\<acute> \\<sharp> Q\"\n  shows \"\\<^bold>R\\<^sub>s(P \\<turnstile> Q) is SRD\"\n  by (simp add: Healthy_def' SRD_RH_design assms(1) assms(2))\n\nlemma SRD_RHS_H1_H2: \"SRD(P) = \\<^bold>R\\<^sub>s(\\<^bold>H(P))\"\n  by (metis (no_types, lifting) H1_H2_eq_design R3h_subst_wait RHS_def SRD_RH_design_form subst_not wait_false_design)\n\nsubsection {* Reactive design composition laws *}\n\ntheorem R1_design_composition:\n  fixes P Q :: \"('t::ordered_cancel_monoid_diff,'\\<alpha>,'\\<beta>) rel_rp\"\n  and R S :: \"('t,'\\<beta>,'\\<gamma>) rel_rp\"\n  assumes \"$ok\\<acute> \\<sharp> P\" \"$ok\\<acute> \\<sharp> Q\" \"$ok \\<sharp> R\" \"$ok \\<sharp> S\"\n  shows\n  \"(R1(P \\<turnstile> Q) ;; R1(R \\<turnstile> S)) =\n   R1((\\<not> (R1(\\<not> P) ;; R1(true)) \\<and> \\<not> (R1(Q) ;; R1(\\<not> R))) \\<turnstile> (R1(Q) ;; R1(S)))\"\nproof -\n  have \"(R1(P \\<turnstile> Q) ;; R1(R \\<turnstile> S)) = (\\<^bold>\\<exists> ok\\<^sub>0 \\<bullet> (R1(P \\<turnstile> Q))\\<lbrakk>\\<guillemotleft>ok\\<^sub>0\\<guillemotright>/$ok\\<acute>\\<rbrakk> ;; (R1(R \\<turnstile> S))\\<lbrakk>\\<guillemotleft>ok\\<^sub>0\\<guillemotright>/$ok\\<rbrakk>)\"\n    using seqr_middle ok_vwb_lens by blast\n  also from assms have \"... = (\\<^bold>\\<exists> ok\\<^sub>0 \\<bullet> R1(($ok \\<and> P) \\<Rightarrow> (\\<guillemotleft>ok\\<^sub>0\\<guillemotright> \\<and> Q)) ;; R1((\\<guillemotleft>ok\\<^sub>0\\<guillemotright>  \\<and> R) \\<Rightarrow> ($ok\\<acute> \\<and> S)))\"\n    by (simp add: design_def R1_def usubst unrest)\n  also from assms have \"... = ((R1(($ok \\<and> P) \\<Rightarrow> (true \\<and> Q)) ;; R1((true \\<and> R) \\<Rightarrow> ($ok\\<acute> \\<and> S)))\n                             \\<or> (R1(($ok \\<and> P) \\<Rightarrow> (false \\<and> Q)) ;; R1((false \\<and> R) \\<Rightarrow> ($ok\\<acute> \\<and> S))))\"\n    by (simp add: false_alt_def true_alt_def)\n  also from assms have \"... = ((R1(($ok \\<and> P) \\<Rightarrow> Q) ;; R1(R \\<Rightarrow> ($ok\\<acute> \\<and> S)))\n                             \\<or> (R1(\\<not> ($ok \\<and> P)) ;; R1(true)))\"\n    by simp\n  also from assms have \"... = ((R1(\\<not> $ok \\<or> \\<not> P \\<or> Q) ;; R1(\\<not> R \\<or> ($ok\\<acute> \\<and> S)))\n                             \\<or> (R1(\\<not> $ok \\<or> \\<not> P) ;; R1(true)))\"\n    by (simp add: impl_alt_def utp_pred.sup.assoc)\n  also from assms have \"... = (((R1(\\<not> $ok \\<or> \\<not> P) \\<or> R1(Q)) ;; R1(\\<not> R \\<or> ($ok\\<acute> \\<and> S)))\n                               \\<or> (R1(\\<not> $ok \\<or> \\<not> P) ;; R1(true)))\"\n    by (simp add: R1_disj utp_pred.disj_assoc)\n  also from assms have \"... = ((R1(\\<not> $ok \\<or> \\<not> P) ;; R1(\\<not> R \\<or> ($ok\\<acute> \\<and> S)))\n                               \\<or> (R1(Q) ;; R1(\\<not> R \\<or> ($ok\\<acute> \\<and> S)))\n                               \\<or> (R1(\\<not> $ok \\<or> \\<not> P) ;; R1(true)))\"\n    by (simp add: seqr_or_distl utp_pred.sup.assoc)\n  also from assms have \"... = ((R1(Q) ;; R1(\\<not> R \\<or> ($ok\\<acute> \\<and> S)))\n                               \\<or> (R1(\\<not> $ok \\<or> \\<not> P) ;; R1(true)))\"\n    by (rel_blast)\n  also from assms have \"... = ((R1(Q) ;; (R1(\\<not> R) \\<or> R1(S) \\<and> $ok\\<acute>))\n                               \\<or> (R1(\\<not> $ok \\<or> \\<not> P) ;; R1(true)))\"\n    by (simp add: R1_disj R1_extend_conj utp_pred.inf_commute)\n  also have \"... = ((R1(Q) ;; (R1(\\<not> R) \\<or> R1(S) \\<and> $ok\\<acute>))\n                  \\<or> ((R1(\\<not> $ok) :: ('t,'\\<alpha>,'\\<beta>) rel_rp) ;; R1(true))\n                  \\<or> (R1(\\<not> P) ;; R1(true)))\"\n    by (simp add: R1_disj seqr_or_distl)\n  also have \"... = ((R1(Q) ;; (R1(\\<not> R) \\<or> R1(S) \\<and> $ok\\<acute>))\n                  \\<or> (R1(\\<not> $ok))\n                  \\<or> (R1(\\<not> P) ;; R1(true)))\"\n  proof -\n    have \"((R1(\\<not> $ok) :: ('t,'\\<alpha>,'\\<beta>) rel_rp) ;; R1(true)) =\n           (R1(\\<not> $ok) :: ('t,'\\<alpha>,'\\<gamma>) rel_rp)\"\n      by (rel_auto)\n    thus ?thesis\n      by simp\n  qed\n  also have \"... = ((R1(Q) ;; (R1(\\<not> R) \\<or> (R1(S \\<and> $ok\\<acute>))))\n                  \\<or> R1(\\<not> $ok)\n                  \\<or> (R1(\\<not> P) ;; R1(true)))\"\n    by (simp add: R1_extend_conj)\n  also have \"... = ( (R1(Q) ;; (R1 (\\<not> R)))\n                   \\<or> (R1(Q) ;; (R1(S \\<and> $ok\\<acute>)))\n                   \\<or> R1(\\<not> $ok)\n                   \\<or> (R1(\\<not> P) ;; R1(true)))\"\n    by (simp add: seqr_or_distr utp_pred.sup.assoc)\n  also have \"... = R1( (R1(Q) ;; (R1 (\\<not> R)))\n                     \\<or> (R1(Q) ;; (R1(S \\<and> $ok\\<acute>)))\n                     \\<or> (\\<not> $ok)\n                     \\<or> (R1(\\<not> P) ;; R1(true)))\"\n    by (simp add: R1_disj R1_seqr)\n  also have \"... = R1( (R1(Q) ;; (R1 (\\<not> R)))\n                     \\<or> ((R1(Q) ;; R1(S)) \\<and> $ok\\<acute>)\n                     \\<or> (\\<not> $ok)\n                     \\<or> (R1(\\<not> P) ;; R1(true)))\"\n    by (rel_blast)\n  also have \"... = R1(\\<not>($ok \\<and> \\<not> (R1(\\<not> P) ;; R1(true)) \\<and> \\<not> (R1(Q) ;; (R1 (\\<not> R))))\n                     \\<or>  ((R1(Q) ;; R1(S)) \\<and> $ok\\<acute>))\"\n    by (rel_blast)\n  also have \"... = R1(($ok \\<and> \\<not> (R1(\\<not> P) ;; R1(true)) \\<and> \\<not> (R1(Q) ;; (R1 (\\<not> R))))\n                      \\<Rightarrow> ($ok\\<acute> \\<and> (R1(Q) ;; R1(S))))\"\n    by (simp add: impl_alt_def utp_pred.inf_commute)\n  also have \"... = R1((\\<not> (R1(\\<not> P) ;; R1(true)) \\<and> \\<not> (R1(Q) ;; R1(\\<not> R))) \\<turnstile> (R1(Q) ;; R1(S)))\"\n    by (simp add: design_def)\n  finally show ?thesis .\nqed\n\ndefinition [upred_defs]: \"R3c_pre(P) = (true \\<triangleleft> $wait \\<triangleright> P)\"\n\ndefinition [upred_defs]: \"R3c_post(P) = (\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> P)\"\n\ndefinition [upred_defs]: \"R3h_post(P) = ((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> P)\"\n\nlemma R3c_pre_conj: \"R3c_pre(P \\<and> Q) = (R3c_pre(P) \\<and> R3c_pre(Q))\"\n  by (rel_auto)\n\nlemma R3c_pre_seq:\n  \"(true ;; Q) = true \\<Longrightarrow> R3c_pre(P ;; Q) = (R3c_pre(P) ;; Q)\"\n  by (rel_auto)\n\nlemma R2s_st'_eq_st:\n  \"R2s($st\\<acute> =\\<^sub>u $st) = ($st\\<acute> =\\<^sub>u $st)\"\n  by (rel_auto)\n\nlemma R2c_st'_eq_st:\n  \"R2c($st\\<acute> =\\<^sub>u $st) = ($st\\<acute> =\\<^sub>u $st)\"\n  by (rel_auto)\n\nlemma R2s_design: \"R2s(P \\<turnstile> Q) = (R2s(P) \\<turnstile> R2s(Q))\"\n  by (simp add: R2s_def design_def usubst)\n\nlemma R2c_design: \"R2c(P \\<turnstile> Q) = (R2c(P) \\<turnstile> R2c(Q))\"\n  by (simp add: design_def impl_alt_def R2c_disj R2c_not R2c_ok R2c_and R2c_ok')\n\nlemma R1_R3c_design:\n  \"R1(R3c(P \\<turnstile> Q)) = R1(R3c_pre(P) \\<turnstile> R3c_post(Q))\"\n  by (rel_auto)\n\nlemma R1_R3h_design:\n  \"R1(R3h(P \\<turnstile> Q)) = R1(R3c_pre(P) \\<turnstile> R3h_post(Q))\"\n  by (rel_auto)\n\nlemma unrest_ok_R2s [unrest]: \"$ok \\<sharp> P \\<Longrightarrow> $ok \\<sharp> R2s(P)\"\n  by (simp add: R2s_def unrest)\n\nlemma unrest_ok'_R2s [unrest]: \"$ok\\<acute> \\<sharp> P \\<Longrightarrow> $ok\\<acute> \\<sharp> R2s(P)\"\n  by (simp add: R2s_def unrest)\n\nlemma unrest_ok_R2c [unrest]: \"$ok \\<sharp> P \\<Longrightarrow> $ok \\<sharp> R2c(P)\"\n  by (simp add: R2c_def unrest)\n\nlemma unrest_ok'_R2c [unrest]: \"$ok\\<acute> \\<sharp> P \\<Longrightarrow> $ok\\<acute> \\<sharp> R2c(P)\"\n  by (simp add: R2c_def unrest)\n\nlemma unrest_ok_R3c_pre [unrest]: \"$ok \\<sharp> P \\<Longrightarrow> $ok \\<sharp> R3c_pre(P)\"\n  by (simp add: R3c_pre_def cond_def unrest)\n\nlemma unrest_ok'_R3c_pre [unrest]: \"$ok\\<acute> \\<sharp> P \\<Longrightarrow> $ok\\<acute> \\<sharp> R3c_pre(P)\"\n  by (simp add: R3c_pre_def cond_def unrest)\n\nlemma unrest_ok_R3c_post [unrest]: \"$ok \\<sharp> P \\<Longrightarrow> $ok \\<sharp> R3c_post(P)\"\n  by (simp add: R3c_post_def cond_def unrest)\n\nlemma unrest_ok_R3c_post' [unrest]: \"$ok\\<acute> \\<sharp> P \\<Longrightarrow> $ok\\<acute> \\<sharp> R3c_post(P)\"\n  by (simp add: R3c_post_def cond_def unrest)\n\nlemma unrest_ok_R3h_post [unrest]: \"$ok \\<sharp> P \\<Longrightarrow> $ok \\<sharp> R3h_post(P)\"\n  by (simp add: R3h_post_def cond_def unrest)\n\nlemma unrest_ok_R3h_post' [unrest]: \"$ok\\<acute> \\<sharp> P \\<Longrightarrow> $ok\\<acute> \\<sharp> R3h_post(P)\"\n  by (simp add: R3h_post_def cond_def unrest)\n\nlemma R3c_R1_design_composition:\n  assumes \"$ok\\<acute> \\<sharp> P\" \"$ok\\<acute> \\<sharp> Q\" \"$ok \\<sharp> R\" \"$ok \\<sharp> S\"\n  shows \"(R3c(R1(P \\<turnstile> Q)) ;; R3c(R1(R \\<turnstile> S))) =\n       R3c(R1((\\<not> (R1(\\<not> P) ;; R1(true)) \\<and> \\<not> ((R1(Q) \\<and> \\<not> $wait\\<acute>) ;; R1(\\<not> R)))\n       \\<turnstile> (R1(Q) ;; (\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> R1(S)))))\"\nproof -\n  have 1:\"(\\<not> (R1 (\\<not> R3c_pre P) ;; R1 true)) = (R3c_pre (\\<not> (R1 (\\<not> P) ;; R1 true)))\"\n    by (rel_auto)\n  have 2:\"(\\<not> (R1 (R3c_post Q) ;; R1 (\\<not> R3c_pre R))) = R3c_pre(\\<not> ((R1 Q \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R)))\"\n    by (rel_auto)\n  have 3:\"(R1 (R3c_post Q) ;; R1 (R3c_post S)) = R3c_post (R1 Q ;; (\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> R1 S))\"\n    by (rel_auto)\n  show ?thesis\n    apply (simp add: R3c_semir_form R1_R3c_commute[THEN sym] R1_R3c_design unrest )\n    apply (subst R1_design_composition)\n    apply (simp_all add: unrest assms R3c_pre_conj 1 2 3)\n  done\nqed\n\nlemma R3h_R1_design_composition:\n  assumes \"$ok\\<acute> \\<sharp> P\" \"$ok\\<acute> \\<sharp> Q\" \"$ok \\<sharp> R\" \"$ok \\<sharp> S\"\n  shows \"(R3h(R1(P \\<turnstile> Q)) ;; R3h(R1(R \\<turnstile> S))) =\n       R3h(R1((\\<not> (R1(\\<not> P) ;; R1(true)) \\<and> \\<not> ((R1(Q) \\<and> \\<not> $wait\\<acute>) ;; R1(\\<not> R)))\n       \\<turnstile> (R1(Q) ;; ((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1(S)))))\"\nproof -\n  have 1:\"(\\<not> (R1 (\\<not> R3c_pre P) ;; R1 true)) = (R3c_pre (\\<not> (R1 (\\<not> P) ;; R1 true)))\"\n   by (rel_auto, blast+)\n  have 2:\"(\\<not> (R1 (R3h_post Q) ;; R1 (\\<not> R3c_pre R))) = R3c_pre(\\<not> ((R1 Q \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R)))\"\n    by (rel_auto, blast+)\n  have 3:\"(R1 (R3h_post Q) ;; R1 (R3h_post S)) = R3h_post (R1 Q ;; ((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1 S))\"\n    by (rel_auto, blast+)\n  show ?thesis\n    apply (simp add: R3h_semir_form R1_R3h_commute[THEN sym] R1_R3h_design unrest )\n    apply (subst R1_design_composition)\n    apply (simp_all add: unrest assms R3c_pre_conj 1 2 3)\n  done\nqed\n\nlemma R1_des_lift_skip: \"R1(\\<lceil>II\\<rceil>\\<^sub>D) = \\<lceil>II\\<rceil>\\<^sub>D\"\n  by (rel_auto)\n\nlemma R2s_subst_wait_true [usubst]:\n  \"(R2s(P))\\<lbrakk>true/$wait\\<rbrakk> = R2s(P\\<lbrakk>true/$wait\\<rbrakk>)\"\n  by (simp add: R2s_def usubst unrest)\n\nlemma R2s_subst_wait'_true [usubst]:\n  \"(R2s(P))\\<lbrakk>true/$wait\\<acute>\\<rbrakk> = R2s(P\\<lbrakk>true/$wait\\<acute>\\<rbrakk>)\"\n  by (simp add: R2s_def usubst unrest)\n\nlemma R2_subst_wait_true [usubst]:\n  \"(R2(P))\\<lbrakk>true/$wait\\<rbrakk> = R2(P\\<lbrakk>true/$wait\\<rbrakk>)\"\n  by (simp add: R2_def R1_def R2s_def usubst unrest)\n\nlemma R2_subst_wait'_true [usubst]:\n  \"(R2(P))\\<lbrakk>true/$wait\\<acute>\\<rbrakk> = R2(P\\<lbrakk>true/$wait\\<acute>\\<rbrakk>)\"\n  by (simp add: R2_def R1_def R2s_def usubst unrest)\n\nlemma R2_subst_wait_false [usubst]:\n  \"(R2(P))\\<lbrakk>false/$wait\\<rbrakk> = R2(P\\<lbrakk>false/$wait\\<rbrakk>)\"\n  by (simp add: R2_def R1_def R2s_def usubst unrest)\n\nlemma R2_subst_wait'_false [usubst]:\n  \"(R2(P))\\<lbrakk>false/$wait\\<acute>\\<rbrakk> = R2(P\\<lbrakk>false/$wait\\<acute>\\<rbrakk>)\"\n  by (simp add: R2_def R1_def R2s_def usubst unrest)\n\nlemma R2_des_lift_skip:\n  \"R2(\\<lceil>II\\<rceil>\\<^sub>D) = \\<lceil>II\\<rceil>\\<^sub>D\"\n  apply (rel_auto) using minus_zero_eq by blast\n\nlemma R2c_R2s_absorb: \"R2c(R2s(P)) = R2s(P)\"\n  by (rel_auto)\n\nlemma R2_design_composition:\n  assumes \"$ok\\<acute> \\<sharp> P\" \"$ok\\<acute> \\<sharp> Q\" \"$ok \\<sharp> R\" \"$ok \\<sharp> S\"\n  shows \"(R2(P \\<turnstile> Q) ;; R2(R \\<turnstile> S)) =\n       R2((\\<not> (R1 (\\<not> R2c P) ;; R1 true) \\<and> \\<not> (R1 (R2c Q) ;; R1 (\\<not> R2c R))) \\<turnstile> (R1 (R2c Q) ;; R1 (R2c S)))\"\n  apply (simp add: R2_R2c_def R2c_design R1_design_composition assms unrest R2c_not R2c_and R2c_disj R1_R2c_commute[THEN sym] R2c_idem R2c_R1_seq)\n  apply (metis (no_types, lifting) R2c_R1_seq R2c_not R2c_true)\ndone\n\nlemma RH_design_composition:\n  assumes \"$ok\\<acute> \\<sharp> P\" \"$ok\\<acute> \\<sharp> Q\" \"$ok \\<sharp> R\" \"$ok \\<sharp> S\"\n  shows \"(RH(P \\<turnstile> Q) ;; RH(R \\<turnstile> S)) =\n       RH((\\<not> (R1 (\\<not> R2s P) ;; R1 true) \\<and> \\<not> ((R1 (R2s Q) \\<and> (\\<not> $wait\\<acute>)) ;; R1 (\\<not> R2s R))) \\<turnstile>\n                       (R1 (R2s Q) ;; (\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> R1 (R2s S))))\"\nproof -\n  have 1: \"R2c (R1 (\\<not> R2s P) ;; R1 true) = (R1 (\\<not> R2s P) ;; R1 true)\"\n  proof -\n    have 1:\"(R1 (\\<not> R2s P) ;; R1 true) = (R1(R2 (\\<not> P) ;; R2 true))\"\n      by (rel_auto)\n    have \"R2c(R1(R2 (\\<not> P) ;; R2 true)) = R2c(R1(R2 (\\<not> P) ;; R2 true))\"\n      using R2c_not by blast\n    also have \"... = R2(R2 (\\<not> P) ;; R2 true)\"\n      by (metis R1_R2c_commute R1_R2c_is_R2)\n    also have \"... = (R2 (\\<not> P) ;; R2 true)\"\n      by (simp add: R2_seqr_distribute)\n    also have \"... = (R1 (\\<not> R2s P) ;; R1 true)\"\n      by (simp add: R2_def R2s_not R2s_true)\n    finally show ?thesis\n      by (simp add: 1)\n  qed\n\n  have 2:\"R2c ((R1 (R2s Q) \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s R)) = ((R1 (R2s Q) \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s R))\"\n  proof -\n    have \"((R1 (R2s Q) \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s R)) = R1 (R2 (Q \\<and> \\<not> $wait\\<acute>) ;; R2 (\\<not> R))\"\n      by (rel_auto)\n    hence \"R2c ((R1 (R2s Q) \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s R)) = (R2 (Q \\<and> \\<not> $wait\\<acute>) ;; R2 (\\<not> R))\"\n      by (metis R1_R2c_commute R1_R2c_is_R2 R2_seqr_distribute)\n    also have \"... = ((R1 (R2s Q) \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s R))\"\n      by (rel_auto)\n    finally show ?thesis .\n  qed\n\n  have 3:\"R2c((R1 (R2s Q) ;; (\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> R1 (R2s S)))) = (R1 (R2s Q) ;; (\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> R1 (R2s S)))\"\n  proof -\n    have \"R2c(((R1 (R2s Q))\\<lbrakk>true/$wait\\<acute>\\<rbrakk> ;; (\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> R1 (R2s S))\\<lbrakk>true/$wait\\<rbrakk>))\n          = ((R1 (R2s Q))\\<lbrakk>true/$wait\\<acute>\\<rbrakk> ;; (\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> R1 (R2s S))\\<lbrakk>true/$wait\\<rbrakk>)\"\n    proof -\n      have \"R2c(((R1 (R2s Q))\\<lbrakk>true/$wait\\<acute>\\<rbrakk> ;; (\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> R1 (R2s S))\\<lbrakk>true/$wait\\<rbrakk>)) =\n            R2c(R1 (R2s (Q\\<lbrakk>true/$wait\\<acute>\\<rbrakk>)) ;; \\<lceil>II\\<rceil>\\<^sub>D\\<lbrakk>true/$wait\\<rbrakk>)\"\n        by (simp add: usubst cond_unit_T R1_def R2s_def)\n      also have \"... = R2c(R2(Q\\<lbrakk>true/$wait\\<acute>\\<rbrakk>) ;; R2(\\<lceil>II\\<rceil>\\<^sub>D\\<lbrakk>true/$wait\\<rbrakk>))\"\n        by (metis R2_def R2_des_lift_skip R2_subst_wait_true)\n      also have \"... = (R2(Q\\<lbrakk>true/$wait\\<acute>\\<rbrakk>) ;; R2(\\<lceil>II\\<rceil>\\<^sub>D\\<lbrakk>true/$wait\\<rbrakk>))\"\n        using R2c_seq by blast\n      also have \"... = ((R1 (R2s Q))\\<lbrakk>true/$wait\\<acute>\\<rbrakk> ;; (\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> R1 (R2s S))\\<lbrakk>true/$wait\\<rbrakk>)\"\n        apply (simp add: usubst R2_des_lift_skip)\n        apply (metis R2_def R2_des_lift_skip R2_subst_wait'_true R2_subst_wait_true)\n      done\n      finally show ?thesis .\n    qed\n    moreover have \"R2c(((R1 (R2s Q))\\<lbrakk>false/$wait\\<acute>\\<rbrakk> ;; (\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> R1 (R2s S))\\<lbrakk>false/$wait\\<rbrakk>))\n          = ((R1 (R2s Q))\\<lbrakk>false/$wait\\<acute>\\<rbrakk> ;; (\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> R1 (R2s S))\\<lbrakk>false/$wait\\<rbrakk>)\"\n      by (simp add: usubst cond_unit_F)\n         (metis (no_types, hide_lams) R1_wait'_false R1_wait_false R2_def R2_subst_wait'_false R2_subst_wait_false R2c_seq)\n    ultimately show ?thesis\n    proof -\n      have \"\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> R1 (R2s S) = R2 (\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> S)\"\n        by (simp add: R1_R2c_is_R2 R1_R2s_R2c R2_condr' R2_des_lift_skip R2s_wait)\n      then show ?thesis\n        by (simp add: R1_R2c_is_R2 R1_R2s_R2c R2c_seq)\n    qed\n  qed\n\n  have \"(R1(R2s(R3c(P \\<turnstile> Q))) ;; R1(R2s(R3c(R \\<turnstile> S)))) =\n        ((R3c(R1(R2s(P) \\<turnstile> R2s(Q)))) ;; R3c(R1(R2s(R) \\<turnstile> R2s(S))))\"\n    by (metis (no_types, hide_lams) R1_R2s_R2c R1_R3c_commute R2c_R3c_commute R2s_design)\n  also have \"... = R3c (R1 ((\\<not> (R1 (\\<not> R2s P) ;; R1 true) \\<and> \\<not> ((R1 (R2s Q) \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s R))) \\<turnstile>\n                       (R1 (R2s Q) ;; (\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> R1 (R2s S)))))\"\n    by (simp add: R3c_R1_design_composition assms unrest)\n  also have \"... = R3c(R1(R2c((\\<not> (R1 (\\<not> R2s P) ;; R1 true) \\<and> \\<not> ((R1 (R2s Q) \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s R))) \\<turnstile>\n                              (R1 (R2s Q) ;; (\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> R1 (R2s S))))))\"\n    by (simp add: R2c_design R2c_and R2c_not 1 2 3)\n  finally show ?thesis\n    by (simp add: R1_R2s_R2c R1_R3c_commute R2c_R3c_commute RH_def)\nqed\n\nlemma R2_st_ex: \"R2 (\\<exists> $st \\<bullet> P) = (\\<exists> $st \\<bullet> R2(P))\"\n  by (rel_auto)\n\nlemma RHS_design_composition:\n  assumes \"$ok\\<acute> \\<sharp> P\" \"$ok\\<acute> \\<sharp> Q\" \"$ok \\<sharp> R\" \"$ok \\<sharp> S\"\n  shows \"(\\<^bold>R\\<^sub>s(P \\<turnstile> Q) ;; \\<^bold>R\\<^sub>s(R \\<turnstile> S)) =\n       \\<^bold>R\\<^sub>s((\\<not> (R1 (\\<not> R2s P) ;; R1 true) \\<and> \\<not> ((R1 (R2s Q) \\<and> (\\<not> $wait\\<acute>)) ;; R1 (\\<not> R2s R))) \\<turnstile>\n                       (R1 (R2s Q) ;; ((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1 (R2s S))))\"\nproof -\n  have 1: \"R2c (R1 (\\<not> R2s P) ;; R1 true) = (R1 (\\<not> R2s P) ;; R1 true)\"\n  proof -\n    have 1:\"(R1 (\\<not> R2s P) ;; R1 true) = (R1(R2 (\\<not> P) ;; R2 true))\"\n      by (rel_auto, blast)\n    have \"R2c(R1(R2 (\\<not> P) ;; R2 true)) = R2c(R1(R2 (\\<not> P) ;; R2 true))\"\n      using R2c_not by blast\n    also have \"... = R2(R2 (\\<not> P) ;; R2 true)\"\n      by (metis R1_R2c_commute R1_R2c_is_R2)\n    also have \"... = (R2 (\\<not> P) ;; R2 true)\"\n      by (simp add: R2_seqr_distribute)\n    also have \"... = (R1 (\\<not> R2s P) ;; R1 true)\"\n      by (simp add: R2_def R2s_not R2s_true)\n    finally show ?thesis\n      by (simp add: 1)\n  qed\n\n  have 2:\"R2c ((R1 (R2s Q) \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s R)) = ((R1 (R2s Q) \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s R))\"\n  proof -\n    have \"((R1 (R2s Q) \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s R)) = R1 (R2 (Q \\<and> \\<not> $wait\\<acute>) ;; R2 (\\<not> R))\"\n      by (rel_auto, blast+)\n    hence \"R2c ((R1 (R2s Q) \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s R)) = (R2 (Q \\<and> \\<not> $wait\\<acute>) ;; R2 (\\<not> R))\"\n      by (metis (no_types, lifting) R1_R2c_commute R1_R2c_is_R2 R2_seqr_distribute)\n    also have \"... = ((R1 (R2s Q) \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s R))\"\n      by (rel_auto, blast+)\n    finally show ?thesis .\n  qed\n\n  have 3:\"R2c((R1 (R2s Q) ;; ((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1 (R2s S)))) =\n          (R1 (R2s Q) ;; ((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1 (R2s S)))\"\n  proof -\n    have \"R2c(((R1 (R2s Q))\\<lbrakk>true/$wait\\<acute>\\<rbrakk> ;; ((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1 (R2s S))\\<lbrakk>true/$wait\\<rbrakk>))\n          = ((R1 (R2s Q))\\<lbrakk>true/$wait\\<acute>\\<rbrakk> ;; ((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1 (R2s S))\\<lbrakk>true/$wait\\<rbrakk>)\"\n    proof -\n      have \"R2c(((R1 (R2s Q))\\<lbrakk>true/$wait\\<acute>\\<rbrakk> ;; ((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1 (R2s S))\\<lbrakk>true/$wait\\<rbrakk>)) =\n            R2c(R1 (R2s (Q\\<lbrakk>true/$wait\\<acute>\\<rbrakk>)) ;; (\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D)\\<lbrakk>true/$wait\\<rbrakk>)\"\n        by (simp add: usubst cond_unit_T R1_def R2s_def)\n      also have \"... = R2c(R2(Q\\<lbrakk>true/$wait\\<acute>\\<rbrakk>) ;; R2((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D)\\<lbrakk>true/$wait\\<rbrakk>))\"\n        by (metis (no_types, lifting) R2_def R2_des_lift_skip R2_subst_wait_true R2_st_ex)\n      also have \"... = (R2(Q\\<lbrakk>true/$wait\\<acute>\\<rbrakk>) ;; R2((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D)\\<lbrakk>true/$wait\\<rbrakk>))\"\n        using R2c_seq by blast\n      also have \"... = ((R1 (R2s Q))\\<lbrakk>true/$wait\\<acute>\\<rbrakk> ;; ((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1 (R2s S))\\<lbrakk>true/$wait\\<rbrakk>)\"\n        apply (simp add: usubst R2_des_lift_skip)\n        apply (metis (no_types) R2_def R2_des_lift_skip R2_st_ex R2_subst_wait'_true R2_subst_wait_true)\n      done\n      finally show ?thesis .\n    qed\n    moreover have \"R2c(((R1 (R2s Q))\\<lbrakk>false/$wait\\<acute>\\<rbrakk> ;; ((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1 (R2s S))\\<lbrakk>false/$wait\\<rbrakk>))\n          = ((R1 (R2s Q))\\<lbrakk>false/$wait\\<acute>\\<rbrakk> ;; ((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1 (R2s S))\\<lbrakk>false/$wait\\<rbrakk>)\"\n      by (simp add: usubst)\n         (metis (no_types, lifting) R1_wait'_false R1_wait_false R2_R1_form R2_subst_wait'_false R2_subst_wait_false R2c_seq)\n    ultimately show ?thesis\n      by (smt R2_R1_form R2_condr' R2_des_lift_skip R2_st_ex R2c_seq R2s_wait)\n  qed\n\n  have \"(R1(R2s(R3h(P \\<turnstile> Q))) ;; R1(R2s(R3h(R \\<turnstile> S)))) =\n        ((R3h(R1(R2s(P) \\<turnstile> R2s(Q)))) ;; R3h(R1(R2s(R) \\<turnstile> R2s(S))))\"\n    by (metis (no_types, hide_lams) R1_R2s_R2c R1_R3h_commute R2c_R3h_commute R2s_design)\n  also have \"... = R3h (R1 ((\\<not> (R1 (\\<not> R2s P) ;; R1 true) \\<and> \\<not> ((R1 (R2s Q) \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s R))) \\<turnstile>\n                       (R1 (R2s Q) ;; ((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1 (R2s S)))))\"\n    by (simp add: R3h_R1_design_composition assms unrest)\n  also have \"... = R3h(R1(R2c((\\<not> (R1 (\\<not> R2s P) ;; R1 true) \\<and> \\<not> ((R1 (R2s Q) \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s R))) \\<turnstile>\n                              (R1 (R2s Q) ;; ((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1 (R2s S))))))\"\n    by (simp add: R2c_design R2c_and R2c_not 1 2 3)\n  finally show ?thesis\n    by (simp add: R1_R2s_R2c R1_R3h_commute R2c_R3h_commute RHS_def)\nqed\n\nlemma RHS_R2s_design_composition:\n  assumes\n    \"$ok\\<acute> \\<sharp> P\" \"$ok\\<acute> \\<sharp> Q\" \"$ok \\<sharp> R\" \"$ok \\<sharp> S\"\n    \"P is R2s\" \"Q is R2s\" \"R is R2s\" \"S is R2s\"\n  shows \"(\\<^bold>R\\<^sub>s(P \\<turnstile> Q) ;; \\<^bold>R\\<^sub>s(R \\<turnstile> S)) =\n       \\<^bold>R\\<^sub>s((\\<not> (R1 (\\<not> P) ;; R1 true) \\<and> \\<not> ((R1 Q \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R))) \\<turnstile>\n                       (R1 Q ;; ((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1 S)))\"\nproof -\n  have f1: \"R2s P = P\"\n    by (meson Healthy_def assms(5))\n  have f2: \"R2s Q = Q\"\n    by (meson Healthy_def assms(6))\n  have f3: \"R2s R = R\"\n    by (meson Healthy_def assms(7))\n  have \"R2s S = S\"\n    by (meson Healthy_def assms(8))\n  then show ?thesis\n    using f3 f2 f1 by (simp add: RHS_design_composition assms(1) assms(2) assms(3) assms(4))\nqed\n\nlemma RH_design_export_R1: \"\\<^bold>R(P \\<turnstile> Q) = \\<^bold>R(P \\<turnstile> R1(Q))\"\n  by (rel_auto)\n\nlemma RH_design_export_R2s: \"\\<^bold>R(P \\<turnstile> Q) = \\<^bold>R(P \\<turnstile> R2s(Q))\"\n  by (rel_auto)\n\nlemma RH_design_export_R2c: \"\\<^bold>R(P \\<turnstile> Q) = \\<^bold>R(P \\<turnstile> R2c(Q))\"\n  by (rel_auto)\n\nlemma RHS_design_export_R1: \"\\<^bold>R\\<^sub>s(P \\<turnstile> Q) = \\<^bold>R\\<^sub>s(P \\<turnstile> R1(Q))\"\n  by (rel_auto)\n\nlemma RHS_design_export_R2s: \"\\<^bold>R\\<^sub>s(P \\<turnstile> Q) = \\<^bold>R\\<^sub>s(P \\<turnstile> R2s(Q))\"\n  by (rel_auto)\n\nlemma RHS_design_export_R2c: \"\\<^bold>R\\<^sub>s(P \\<turnstile> Q) = \\<^bold>R\\<^sub>s(P \\<turnstile> R2c(Q))\"\n  by (rel_auto)\n\nlemma RHS_design_export_R2: \"\\<^bold>R\\<^sub>s(P \\<turnstile> Q) = \\<^bold>R\\<^sub>s(P \\<turnstile> R2(Q))\"\n  by (rel_auto)\n\nlemma RHS_design_ok_wait: \"\\<^bold>R\\<^sub>s(P\\<lbrakk>true,false/$ok,$wait\\<rbrakk> \\<turnstile> Q\\<lbrakk>true,false/$ok,$wait\\<rbrakk>) = \\<^bold>R\\<^sub>s(P \\<turnstile> Q)\"\n  by (rel_auto)\n\nsubsection {* Reactive design triples *}\n\ndefinition wait'_cond ::\n  \"('t::ordered_cancel_monoid_diff,'\\<alpha>,'\\<beta>) rel_rp \\<Rightarrow> ('t,'\\<alpha>,'\\<beta>) rel_rp \\<Rightarrow> ('t,'\\<alpha>,'\\<beta>) rel_rp\" (infixr \"\\<diamondop>\" 65) where\n[upred_defs]: \"P \\<diamondop> Q = (P \\<triangleleft> $wait\\<acute> \\<triangleright> Q)\"\n\nlemma wait'_cond_unrest [unrest]:\n  \"\\<lbrakk> out_var wait \\<bowtie> x; x \\<sharp> P; x \\<sharp> Q \\<rbrakk> \\<Longrightarrow> x \\<sharp> (P \\<diamondop> Q)\"\n  by (simp add: wait'_cond_def unrest)\n\nlemma wait'_cond_subst [usubst]:\n  \"$wait\\<acute> \\<sharp> \\<sigma> \\<Longrightarrow> \\<sigma> \\<dagger> (P \\<diamondop> Q) = (\\<sigma> \\<dagger> P) \\<diamondop> (\\<sigma> \\<dagger> Q)\"\n  by (simp add: wait'_cond_def usubst unrest)\n\nlemma wait'_cond_left_false: \"false \\<diamondop> P = (\\<not> $wait\\<acute> \\<and> P)\"\n  by (rel_auto)\n\nlemma wait'_cond_seq: \"((P \\<diamondop> Q) ;; R) = ((P ;; ($wait \\<and> R)) \\<or> (Q ;; (\\<not>$wait \\<and> R)))\"\n  by (simp add: wait'_cond_def cond_def seqr_or_distl, rel_blast)\n\nlemma wait'_cond_true: \"(P \\<diamondop> Q \\<and> $wait\\<acute>) = (P \\<and> $wait\\<acute>)\"\n  by (rel_auto)\n\nlemma wait'_cond_false: \"(P \\<diamondop> Q \\<and> (\\<not>$wait\\<acute>)) = (Q \\<and> (\\<not>$wait\\<acute>))\"\n  by (rel_auto)\n\nlemma wait'_cond_idem: \"P \\<diamondop> P = P\"\n  by (rel_auto)\n\nlemma wait'_cond_conj_exchange:\n  \"((P \\<diamondop> Q) \\<and> (R \\<diamondop> S)) = (P \\<and> R) \\<diamondop> (Q \\<and> S)\"\n  by (rel_auto)\n\nlemma subst_wait'_cond_true [usubst]: \"(P \\<diamondop> Q)\\<lbrakk>true/$wait\\<acute>\\<rbrakk> = P\\<lbrakk>true/$wait\\<acute>\\<rbrakk>\"\n  by (rel_auto)\n\nlemma subst_wait'_cond_false [usubst]: \"(P \\<diamondop> Q)\\<lbrakk>false/$wait\\<acute>\\<rbrakk> = Q\\<lbrakk>false/$wait\\<acute>\\<rbrakk>\"\n  by (rel_auto)\n\nlemma subst_wait'_left_subst: \"(P\\<lbrakk>true/$wait\\<acute>\\<rbrakk> \\<diamondop> Q) = (P \\<diamondop> Q)\"\n  by (rel_auto)\n\nlemma subst_wait'_right_subst: \"(P \\<diamondop> Q\\<lbrakk>false/$wait\\<acute>\\<rbrakk>) = (P \\<diamondop> Q)\"\n  by (rel_auto)\n\nlemma wait'_cond_split: \"P\\<lbrakk>true/$wait\\<acute>\\<rbrakk> \\<diamondop> P\\<lbrakk>false/$wait\\<acute>\\<rbrakk> = P\"\n  by (simp add: wait'_cond_def cond_var_split)\n\nlemma wait_cond'_assoc: \"P \\<diamondop> Q \\<diamondop> R = P \\<diamondop> R\"\n  by (rel_auto)\n\nlemma wait_cond'_shadow: \"(P \\<diamondop> Q) \\<diamondop> R = P \\<diamondop> Q \\<diamondop> R\"\n  by (rel_auto)\n\nlemma wait_cond'_conj: \"P \\<diamondop> (Q \\<and> (R \\<diamondop> S)) = P \\<diamondop> (Q \\<and> S)\"\n  by (rel_auto)\n\nlemma R1_wait'_cond: \"R1(P \\<diamondop> Q) = R1(P) \\<diamondop> R1(Q)\"\n  by (rel_auto)\n\nlemma R2s_wait'_cond: \"R2s(P \\<diamondop> Q) = R2s(P) \\<diamondop> R2s(Q)\"\n  by (simp add: wait'_cond_def R2s_def R2s_def usubst)\n\nlemma R2_wait'_cond: \"R2(P \\<diamondop> Q) = R2(P) \\<diamondop> R2(Q)\"\n  by (simp add: R2_def R2s_wait'_cond R1_wait'_cond)\n\nlemma RH_design_peri_R1: \"\\<^bold>R(P \\<turnstile> R1(Q) \\<diamondop> R) = \\<^bold>R(P \\<turnstile> Q \\<diamondop> R)\"\n  by (metis (no_types, lifting) R1_idem R1_wait'_cond RH_design_export_R1)\n\nlemma RH_design_post_R1: \"\\<^bold>R(P \\<turnstile> Q \\<diamondop> R1(R)) = \\<^bold>R(P \\<turnstile> Q \\<diamondop> R)\"\n  by (metis R1_wait'_cond RH_design_export_R1 RH_design_peri_R1)\n\nlemma RH_design_peri_R2s: \"\\<^bold>R(P \\<turnstile> R2s(Q) \\<diamondop> R) = \\<^bold>R(P \\<turnstile> Q \\<diamondop> R)\"\n  by (metis (no_types, lifting) R2s_idem R2s_wait'_cond RH_design_export_R2s)\n\nlemma RH_design_post_R2s: \"\\<^bold>R(P \\<turnstile> Q \\<diamondop> R2s(R)) = \\<^bold>R(P \\<turnstile> Q \\<diamondop> R)\"\n  by (metis (no_types, lifting) R2s_idem R2s_wait'_cond RH_design_export_R2s)\n\nlemma RH_design_peri_R2c: \"\\<^bold>R(P \\<turnstile> R2c(Q) \\<diamondop> R) = \\<^bold>R(P \\<turnstile> Q \\<diamondop> R)\"\n  by (metis R1_R2s_R2c RH_design_peri_R1 RH_design_peri_R2s)\n\nlemma RHS_design_peri_R1: \"\\<^bold>R\\<^sub>s(P \\<turnstile> R1(Q) \\<diamondop> R) = \\<^bold>R\\<^sub>s(P \\<turnstile> Q \\<diamondop> R)\"\n  by (metis (no_types, lifting) R1_idem R1_wait'_cond RHS_design_export_R1)\n\nlemma RHS_design_post_R1: \"\\<^bold>R\\<^sub>s(P \\<turnstile> Q \\<diamondop> R1(R)) = \\<^bold>R\\<^sub>s(P \\<turnstile> Q \\<diamondop> R)\"\n  by (metis R1_wait'_cond RHS_design_export_R1 RHS_design_peri_R1)\n\nlemma RHS_design_peri_R2s: \"\\<^bold>R\\<^sub>s(P \\<turnstile> R2s(Q) \\<diamondop> R) = \\<^bold>R\\<^sub>s(P \\<turnstile> Q \\<diamondop> R)\"\n  by (metis (no_types, lifting) R2s_idem R2s_wait'_cond RHS_design_export_R2s)\n\nlemma RHS_design_post_R2s: \"\\<^bold>R\\<^sub>s(P \\<turnstile> Q \\<diamondop> R2s(R)) = \\<^bold>R\\<^sub>s(P \\<turnstile> Q \\<diamondop> R)\"\n  by (metis R2s_wait'_cond RHS_design_export_R2s RHS_design_peri_R2s)\n\nlemma RHS_design_peri_R2c: \"\\<^bold>R\\<^sub>s(P \\<turnstile> R2c(Q) \\<diamondop> R) = \\<^bold>R\\<^sub>s(P \\<turnstile> Q \\<diamondop> R)\"\n  by (metis R1_R2s_R2c RHS_design_peri_R1 RHS_design_peri_R2s)\n\nlemma RH_design_lemma1:\n  \"RH(P \\<turnstile> (R1(R2c(Q)) \\<or> R) \\<diamondop> S) = RH(P \\<turnstile> (Q \\<or> R) \\<diamondop> S)\"\n  by (metis (no_types, lifting) R1_R2c_is_R2 R1_R2s_R2c R2_R1_form R2_disj R2c_idem RH_design_peri_R1 RH_design_peri_R2s)\n\nlemma RHS_design_lemma1:\n  \"RHS(P \\<turnstile> (R1(R2c(Q)) \\<or> R) \\<diamondop> S) = RHS(P \\<turnstile> (Q \\<or> R) \\<diamondop> S)\"\n  by (metis (no_types, lifting) R1_R2c_is_R2 R1_R2s_R2c R2_R1_form R2_disj R2c_idem RHS_design_peri_R1 RHS_design_peri_R2s)\n\ntheorem RH_tri_design_composition:\n  assumes \"$ok\\<acute> \\<sharp> P\" \"$ok\\<acute> \\<sharp> Q\\<^sub>1\" \"$ok\\<acute> \\<sharp> Q\\<^sub>2\" \"$ok \\<sharp> R\" \"$ok \\<sharp> S\\<^sub>1\" \"$ok \\<sharp> S\\<^sub>2\"\n           \"$wait\\<acute> \\<sharp> Q\\<^sub>2\" \"$wait \\<sharp> S\\<^sub>1\" \"$wait \\<sharp> S\\<^sub>2\"\n  shows \"(RH(P \\<turnstile> Q\\<^sub>1 \\<diamondop> Q\\<^sub>2) ;; RH(R \\<turnstile> S\\<^sub>1 \\<diamondop> S\\<^sub>2)) =\n       RH((\\<not> (R1 (\\<not> R2s P) ;; R1 true) \\<and> \\<not> ((R1 (R2s Q\\<^sub>2) \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s R))) \\<turnstile>\n                       ((Q\\<^sub>1 \\<or> (R1 (R2s Q\\<^sub>2) ;; R1 (R2s S\\<^sub>1))) \\<diamondop> ((R1 (R2s Q\\<^sub>2) ;; R1 (R2s S\\<^sub>2)))))\"\nproof -\n  have 1:\"(\\<not> ((R1 (R2s (Q\\<^sub>1 \\<diamondop> Q\\<^sub>2)) \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s R))) =\n        (\\<not> ((R1 (R2s Q\\<^sub>2) \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s R)))\"\n    by (metis (no_types, hide_lams) R1_extend_conj R2s_conj R2s_not R2s_wait' wait'_cond_false)\n  have 2: \"(R1 (R2s (Q\\<^sub>1 \\<diamondop> Q\\<^sub>2)) ;; (\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> R1 (R2s (S\\<^sub>1 \\<diamondop> S\\<^sub>2)))) =\n                 ((R1 (R2s Q\\<^sub>1) \\<or> (R1 (R2s Q\\<^sub>2) ;; R1 (R2s S\\<^sub>1))) \\<diamondop> (R1 (R2s Q\\<^sub>2) ;; R1 (R2s S\\<^sub>2)))\"\n  proof -\n    have \"(R1 (R2s Q\\<^sub>1) ;; ($wait \\<and> (\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> R1 (R2s S\\<^sub>1) \\<diamondop> R1 (R2s S\\<^sub>2))))\n                       = (R1 (R2s Q\\<^sub>1) \\<and> $wait\\<acute>)\"\n    proof -\n      have \"(R1 (R2s Q\\<^sub>1) ;; ($wait \\<and> (\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> R1 (R2s S\\<^sub>1) \\<diamondop> R1 (R2s S\\<^sub>2))))\n           = (R1 (R2s Q\\<^sub>1) ;; ($wait \\<and> \\<lceil>II\\<rceil>\\<^sub>D))\"\n        by (rel_auto)\n      also have \"... = ((R1 (R2s Q\\<^sub>1) ;; \\<lceil>II\\<rceil>\\<^sub>D) \\<and> $wait\\<acute>)\"\n        by (rel_auto)\n      also from assms(2) have \"... = ((R1 (R2s Q\\<^sub>1)) \\<and> $wait\\<acute>)\"\n        by (simp add: lift_des_skip_dr_unit_unrest unrest)\n      finally show ?thesis .\n    qed\n\n    moreover have \"(R1 (R2s Q\\<^sub>2) ;; (\\<not> $wait \\<and> (\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> R1 (R2s S\\<^sub>1) \\<diamondop> R1 (R2s S\\<^sub>2))))\n                  = ((R1 (R2s Q\\<^sub>2)) ;; (R1 (R2s S\\<^sub>1) \\<diamondop> R1 (R2s S\\<^sub>2)))\"\n    proof -\n      have \"(R1 (R2s Q\\<^sub>2) ;; (\\<not> $wait \\<and> (\\<lceil>II\\<rceil>\\<^sub>D \\<triangleleft> $wait \\<triangleright> R1 (R2s S\\<^sub>1) \\<diamondop> R1 (R2s S\\<^sub>2))))\n            = (R1 (R2s Q\\<^sub>2) ;; (\\<not> $wait \\<and> (R1 (R2s S\\<^sub>1) \\<diamondop> R1 (R2s S\\<^sub>2))))\"\n        by (metis (no_types, lifting) cond_def conj_disj_not_abs utp_pred.double_compl utp_pred.inf.left_idem utp_pred.sup_assoc utp_pred.sup_inf_absorb)\n\n      also have \"... = ((R1 (R2s Q\\<^sub>2))\\<lbrakk>false/$wait\\<acute>\\<rbrakk> ;; (R1 (R2s S\\<^sub>1) \\<diamondop> R1 (R2s S\\<^sub>2))\\<lbrakk>false/$wait\\<rbrakk>)\"\n        by (metis false_alt_def seqr_right_one_point upred_eq_false wait_vwb_lens)\n\n      also have \"... = ((R1 (R2s Q\\<^sub>2)) ;; (R1 (R2s S\\<^sub>1) \\<diamondop> R1 (R2s S\\<^sub>2)))\"\n        by (simp add: wait'_cond_def usubst unrest assms)\n\n      finally show ?thesis .\n    qed\n\n    moreover\n    have \"((R1 (R2s Q\\<^sub>1) \\<and> $wait\\<acute>) \\<or> ((R1 (R2s Q\\<^sub>2)) ;; (R1 (R2s S\\<^sub>1) \\<diamondop> R1 (R2s S\\<^sub>2))))\n          = (R1 (R2s Q\\<^sub>1) \\<or> (R1 (R2s Q\\<^sub>2) ;; R1 (R2s S\\<^sub>1))) \\<diamondop> ((R1 (R2s Q\\<^sub>2) ;; R1 (R2s S\\<^sub>2)))\"\n      by (simp add: wait'_cond_def cond_seq_right_distr cond_and_T_integrate unrest)\n\n    ultimately show ?thesis\n      by (simp add: R2s_wait'_cond R1_wait'_cond wait'_cond_seq)\n  qed\n\n  show ?thesis\n    apply (subst RH_design_composition)\n    apply (simp_all add: assms)\n    apply (simp add: assms wait'_cond_def unrest)\n    apply (simp add: assms wait'_cond_def unrest)\n    apply (simp add: 1 2)\n    apply (simp add: R1_R2s_R2c RH_design_lemma1)\n  done\nqed\n\nlemma ex_conj_contr_left: \"x \\<sharp> P \\<Longrightarrow> (\\<exists> x \\<bullet> P \\<and> Q) = (P \\<and> (\\<exists> x \\<bullet> Q))\"\n  by (pred_auto)\n\nlemma ex_conj_contr_right: \"x \\<sharp> Q \\<Longrightarrow> (\\<exists> x \\<bullet> P \\<and> Q) = ((\\<exists> x \\<bullet> P) \\<and> Q)\"\n  by (pred_auto)\n\nlemma R1_R2c_ex_st: \"R1 (R2c (\\<exists> $st\\<acute> \\<bullet> Q\\<^sub>1)) = (\\<exists> $st\\<acute> \\<bullet> R1 (R2c Q\\<^sub>1))\"\n  by (rel_auto)\n\ndefinition wpR (infix \"wp\\<^sub>R\" 60)\nwhere [upred_defs]: \"P wp\\<^sub>R Q = (\\<not> (P ;; R1(\\<not> Q)))\"\n\nlemma wpR_true [wp]: \"P wp\\<^sub>R true = true\"\n  by (rel_auto)\n\nlemma wpR_seq [wp]:\n  \"Q is R1 \\<Longrightarrow>(P ;; Q) wp\\<^sub>R R = P wp\\<^sub>R (Q wp\\<^sub>R R)\"\n  by (simp add: wpR_def, metis (no_types, hide_lams) Healthy_def' R1_seqr seqr_assoc)\n\ntheorem RHS_tri_design_composition:\n  assumes \"$ok\\<acute> \\<sharp> P\" \"$ok\\<acute> \\<sharp> Q\\<^sub>1\" \"$ok\\<acute> \\<sharp> Q\\<^sub>2\" \"$ok \\<sharp> R\" \"$ok \\<sharp> S\\<^sub>1\" \"$ok \\<sharp> S\\<^sub>2\"\n          \"$wait \\<sharp> R\" \"$wait\\<acute> \\<sharp> Q\\<^sub>2\" \"$wait \\<sharp> S\\<^sub>1\" \"$wait \\<sharp> S\\<^sub>2\"\n  shows \"(\\<^bold>R\\<^sub>s(P \\<turnstile> Q\\<^sub>1 \\<diamondop> Q\\<^sub>2) ;; \\<^bold>R\\<^sub>s(R \\<turnstile> S\\<^sub>1 \\<diamondop> S\\<^sub>2)) =\n       \\<^bold>R\\<^sub>s((\\<not> (R1 (\\<not> R2s P) ;; R1 true) \\<and> \\<not> (R1(R2s Q\\<^sub>2) ;; R1 (\\<not> R2s R))) \\<turnstile>\n                       (((\\<exists> $st\\<acute> \\<bullet> Q\\<^sub>1) \\<or> (R1 (R2s Q\\<^sub>2) ;; R1 (R2s S\\<^sub>1))) \\<diamondop> ((R1 (R2s Q\\<^sub>2) ;; R1 (R2s S\\<^sub>2)))))\"\nproof -\n  have 1:\"(\\<not> ((R1 (R2s (Q\\<^sub>1 \\<diamondop> Q\\<^sub>2)) \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s R))) =\n        (\\<not> ((R1 (R2s Q\\<^sub>2) \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s R)))\"\n    by (metis (no_types, hide_lams) R1_extend_conj R2s_conj R2s_not R2s_wait' wait'_cond_false)\n  have 2: \"(R1 (R2s (Q\\<^sub>1 \\<diamondop> Q\\<^sub>2)) ;; ((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1 (R2s (S\\<^sub>1 \\<diamondop> S\\<^sub>2)))) =\n                 (((\\<exists> $st\\<acute> \\<bullet> R1 (R2s Q\\<^sub>1)) \\<or> (R1 (R2s Q\\<^sub>2) ;; R1 (R2s S\\<^sub>1))) \\<diamondop> (R1 (R2s Q\\<^sub>2) ;; R1 (R2s S\\<^sub>2)))\"\n  proof -\n    have \"(R1 (R2s Q\\<^sub>1) ;; ($wait \\<and> ((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1 (R2s S\\<^sub>1) \\<diamondop> R1 (R2s S\\<^sub>2))))\n                       = (\\<exists> $st\\<acute> \\<bullet> ((R1 (R2s Q\\<^sub>1)) \\<and> $wait\\<acute>))\"\n    proof -\n      have \"(R1 (R2s Q\\<^sub>1) ;; ($wait \\<and> ((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1 (R2s S\\<^sub>1) \\<diamondop> R1 (R2s S\\<^sub>2))))\n           = (R1 (R2s Q\\<^sub>1) ;; ($wait \\<and> (\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D)))\"\n        by (rel_auto, blast)\n      also have \"... = ((R1 (R2s Q\\<^sub>1) ;; (\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D)) \\<and> $wait\\<acute>)\"\n        by (rel_auto)\n      also from assms(2) have \"... = (\\<exists> $st\\<acute> \\<bullet> ((R1 (R2s Q\\<^sub>1)) \\<and> $wait\\<acute>))\"\n        by (rel_auto, blast)\n      finally show ?thesis .\n    qed\n\n    moreover have \"(R1 (R2s Q\\<^sub>2) ;; (\\<not> $wait \\<and> ((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1 (R2s S\\<^sub>1) \\<diamondop> R1 (R2s S\\<^sub>2))))\n                  = ((R1 (R2s Q\\<^sub>2)) ;; (R1 (R2s S\\<^sub>1) \\<diamondop> R1 (R2s S\\<^sub>2)))\"\n    proof -\n      have \"(R1 (R2s Q\\<^sub>2) ;; (\\<not> $wait \\<and> ((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1 (R2s S\\<^sub>1) \\<diamondop> R1 (R2s S\\<^sub>2))))\n            = (R1 (R2s Q\\<^sub>2) ;; (\\<not> $wait \\<and> (R1 (R2s S\\<^sub>1) \\<diamondop> R1 (R2s S\\<^sub>2))))\"\n        by (metis (no_types, lifting) cond_def conj_disj_not_abs utp_pred.double_compl utp_pred.inf.left_idem utp_pred.sup_assoc utp_pred.sup_inf_absorb)\n\n      also have \"... = ((R1 (R2s Q\\<^sub>2))\\<lbrakk>false/$wait\\<acute>\\<rbrakk> ;; (R1 (R2s S\\<^sub>1) \\<diamondop> R1 (R2s S\\<^sub>2))\\<lbrakk>false/$wait\\<rbrakk>)\"\n        by (metis false_alt_def seqr_right_one_point upred_eq_false wait_vwb_lens)\n\n      also have \"... = ((R1 (R2s Q\\<^sub>2)) ;; (R1 (R2s S\\<^sub>1) \\<diamondop> R1 (R2s S\\<^sub>2)))\"\n        by (simp add: wait'_cond_def usubst unrest assms)\n\n      finally show ?thesis .\n    qed\n\n    moreover\n    have \"((R1 (R2s Q\\<^sub>1) \\<and> $wait\\<acute>) \\<or> ((R1 (R2s Q\\<^sub>2)) ;; (R1 (R2s S\\<^sub>1) \\<diamondop> R1 (R2s S\\<^sub>2))))\n          = (R1 (R2s Q\\<^sub>1) \\<or> (R1 (R2s Q\\<^sub>2) ;; R1 (R2s S\\<^sub>1))) \\<diamondop> ((R1 (R2s Q\\<^sub>2) ;; R1 (R2s S\\<^sub>2)))\"\n      by (simp add: wait'_cond_def cond_seq_right_distr cond_and_T_integrate unrest)\n\n    ultimately show ?thesis\n      by (simp add: R2s_wait'_cond R1_wait'_cond wait'_cond_seq ex_conj_contr_right unrest)\n         (simp add: cond_and_T_integrate cond_seq_right_distr unrest_var wait'_cond_def)\n  qed\n\n  from assms(7,8) have 3: \"(R1 (R2s Q\\<^sub>2) \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s R) = R1 (R2s Q\\<^sub>2) ;; R1 (\\<not> R2s R)\"\n    by (rel_auto, blast, meson)\n\n  show ?thesis\n    apply (subst RHS_design_composition)\n    apply (simp_all add: assms)\n    apply (simp add: assms wait'_cond_def unrest)\n    apply (simp add: assms wait'_cond_def unrest)\n    apply (simp add: 1 2 3)\n    apply (simp add: R1_R2s_R2c RHS_design_lemma1)\n    apply (metis R1_R2c_ex_st RHS_design_lemma1)\n  done\nqed\n\nlemma R1_R2s_R1_true_lemma:\n  \"R1(R2s(R1 (\\<not> R2s P) ;; R1 true)) = R1(R2s((\\<not> P) ;; R1 true))\"\n  by (rel_auto)\n\nlemma R2c_healthy_R2s: \"P is R2c \\<Longrightarrow> R1(R2s(P)) = R1(P)\"\n  by (simp add: Healthy_def R1_R2s_R2c)\n\ntheorem RHS_tri_design_composition_wp:\n  assumes \"$ok\\<acute> \\<sharp> P\" \"$ok\\<acute> \\<sharp> Q\\<^sub>1\" \"$ok\\<acute> \\<sharp> Q\\<^sub>2\" \"$ok \\<sharp> R\" \"$ok \\<sharp> S\\<^sub>1\" \"$ok \\<sharp> S\\<^sub>2\"\n          \"$wait \\<sharp> R\" \"$wait\\<acute> \\<sharp> Q\\<^sub>2\" \"$wait \\<sharp> S\\<^sub>1\" \"$wait \\<sharp> S\\<^sub>2\"\n          \"P is R2c\" \"Q\\<^sub>1 is R1\" \"Q\\<^sub>1 is R2c\" \"Q\\<^sub>2 is R1\" \"Q\\<^sub>2 is R2c\"\n          \"R is R2c\" \"S\\<^sub>1 is R1\" \"S\\<^sub>1 is R2c\" \"S\\<^sub>2 is R1\" \"S\\<^sub>2 is R2c\"\n  shows \"\\<^bold>R\\<^sub>s(P \\<turnstile> Q\\<^sub>1 \\<diamondop> Q\\<^sub>2) ;; \\<^bold>R\\<^sub>s(R \\<turnstile> S\\<^sub>1 \\<diamondop> S\\<^sub>2) =\n          \\<^bold>R\\<^sub>s((R1(\\<not> P) wp\\<^sub>R false \\<and> Q\\<^sub>2 wp\\<^sub>R R) \\<turnstile> (((\\<exists> $st\\<acute> \\<bullet> Q\\<^sub>1) \\<sqinter> (Q\\<^sub>2 ;; S\\<^sub>1)) \\<diamondop> (Q\\<^sub>2 ;; S\\<^sub>2)))\"\n  apply (simp add: RHS_tri_design_composition assms wpR_def Healthy_if R2c_healthy_R2s disj_upred_def)\n  apply (metis (no_types, hide_lams) Healthy_if R1_R2c_is_R2 R1_negate_R1 R2_def assms(11) assms(16))\ndone\n\ntext {* Syntax for pre-, post-, and periconditions *}\n\nabbreviation \"pre\\<^sub>s  \\<equiv> [$ok \\<mapsto>\\<^sub>s true, $ok\\<acute> \\<mapsto>\\<^sub>s false, $wait \\<mapsto>\\<^sub>s false]\"\nabbreviation \"cmt\\<^sub>s  \\<equiv> [$ok \\<mapsto>\\<^sub>s true, $ok\\<acute> \\<mapsto>\\<^sub>s true, $wait \\<mapsto>\\<^sub>s false]\"\nabbreviation \"peri\\<^sub>s \\<equiv> [$ok \\<mapsto>\\<^sub>s true, $ok\\<acute> \\<mapsto>\\<^sub>s true, $wait \\<mapsto>\\<^sub>s false, $wait\\<acute> \\<mapsto>\\<^sub>s true]\"\nabbreviation \"post\\<^sub>s \\<equiv> [$ok \\<mapsto>\\<^sub>s true, $ok\\<acute> \\<mapsto>\\<^sub>s true, $wait \\<mapsto>\\<^sub>s false, $wait\\<acute> \\<mapsto>\\<^sub>s false]\"\n\nabbreviation \"npre\\<^sub>R(P) \\<equiv> pre\\<^sub>s \\<dagger> P\"\n\ndefinition [upred_defs]: \"pre\\<^sub>R(P)  = (\\<not> (npre\\<^sub>R(P)))\"\ndefinition [upred_defs]: \"cmt\\<^sub>R(P)  = (cmt\\<^sub>s \\<dagger> P)\"\ndefinition [upred_defs]: \"peri\\<^sub>R(P) = (peri\\<^sub>s \\<dagger> P)\"\ndefinition [upred_defs]: \"post\\<^sub>R(P) = (post\\<^sub>s \\<dagger> P)\"\n\nlemma ok_pre_unrest [unrest]: \"$ok \\<sharp> pre\\<^sub>R P\"\n  by (simp add: pre\\<^sub>R_def unrest usubst)\n\nlemma ok_peri_unrest [unrest]: \"$ok \\<sharp> peri\\<^sub>R P\"\n  by (simp add: peri\\<^sub>R_def unrest usubst)\n\nlemma ok_post_unrest [unrest]: \"$ok \\<sharp> post\\<^sub>R P\"\n  by (simp add: post\\<^sub>R_def unrest usubst)\n\nlemma ok_cmt_unrest [unrest]: \"$ok \\<sharp> cmt\\<^sub>R P\"\n  by (simp add: cmt\\<^sub>R_def unrest usubst)\n\nlemma ok'_pre_unrest [unrest]: \"$ok\\<acute> \\<sharp> pre\\<^sub>R P\"\n  by (simp add: pre\\<^sub>R_def unrest usubst)\n\nlemma ok'_peri_unrest [unrest]: \"$ok\\<acute> \\<sharp> peri\\<^sub>R P\"\n  by (simp add: peri\\<^sub>R_def unrest usubst)\n\nlemma ok'_post_unrest [unrest]: \"$ok\\<acute> \\<sharp> post\\<^sub>R P\"\n  by (simp add: post\\<^sub>R_def unrest usubst)\n\nlemma ok'_cmt_unrest [unrest]: \"$ok\\<acute> \\<sharp> cmt\\<^sub>R P\"\n  by (simp add: cmt\\<^sub>R_def unrest usubst)\n\nlemma wait_pre_unrest [unrest]: \"$wait \\<sharp> pre\\<^sub>R P\"\n  by (simp add: pre\\<^sub>R_def unrest usubst)\n\nlemma wait_peri_unrest [unrest]: \"$wait \\<sharp> peri\\<^sub>R P\"\n  by (simp add: peri\\<^sub>R_def unrest usubst)\n\nlemma wait_post_unrest [unrest]: \"$wait \\<sharp> post\\<^sub>R P\"\n  by (simp add: post\\<^sub>R_def unrest usubst)\n\nlemma wait_cmt_unrest [unrest]: \"$wait \\<sharp> cmt\\<^sub>R P\"\n  by (simp add: cmt\\<^sub>R_def unrest usubst)\n\nlemma wait'_peri_unrest [unrest]: \"$wait\\<acute> \\<sharp> peri\\<^sub>R P\"\n  by (simp add: peri\\<^sub>R_def unrest usubst)\n\nlemma wait'_post_unrest [unrest]: \"$wait\\<acute> \\<sharp> post\\<^sub>R P\"\n  by (simp add: post\\<^sub>R_def unrest usubst)\n\nlemma pre\\<^sub>s_design: \"pre\\<^sub>s \\<dagger> (P \\<turnstile> Q) = (\\<not> pre\\<^sub>s \\<dagger> P)\"\n  by (simp add: design_def pre\\<^sub>R_def usubst)\n\nlemma peri\\<^sub>s_design: \"peri\\<^sub>s \\<dagger> (P \\<turnstile> Q \\<diamondop> R) = peri\\<^sub>s \\<dagger> (P \\<Rightarrow> Q)\"\n  by (simp add: design_def usubst wait'_cond_def)\n\nlemma post\\<^sub>s_design: \"post\\<^sub>s \\<dagger> (P \\<turnstile> Q \\<diamondop> R) = post\\<^sub>s \\<dagger> (P \\<Rightarrow> R)\"\n  by (simp add: design_def usubst wait'_cond_def)\n\nlemma cmt\\<^sub>s_design: \"cmt\\<^sub>s \\<dagger> (P \\<turnstile> Q) = cmt\\<^sub>s \\<dagger> (P \\<Rightarrow> Q)\"\n  by (simp add: design_def usubst wait'_cond_def)\n\nlemma pre\\<^sub>s_R1 [usubst]: \"pre\\<^sub>s \\<dagger> R1(P) = R1(pre\\<^sub>s \\<dagger> P)\"\n  by (simp add: R1_def usubst)\n\nlemma pre\\<^sub>s_R2c [usubst]: \"pre\\<^sub>s \\<dagger> R2c(P) = R2c(pre\\<^sub>s \\<dagger> P)\"\n  by (simp add: R2c_def R2s_def usubst)\n\nlemma peri\\<^sub>s_R1 [usubst]: \"peri\\<^sub>s \\<dagger> R1(P) = R1(peri\\<^sub>s \\<dagger> P)\"\n  by (simp add: R1_def usubst)\n\nlemma peri\\<^sub>s_R2c [usubst]: \"peri\\<^sub>s \\<dagger> R2c(P) = R2c(peri\\<^sub>s \\<dagger> P)\"\n  by (simp add: R2c_def R2s_def usubst)\n\nlemma post\\<^sub>s_R1 [usubst]: \"post\\<^sub>s \\<dagger> R1(P) = R1(post\\<^sub>s \\<dagger> P)\"\n  by (simp add: R1_def usubst)\n\nlemma post\\<^sub>s_R2c [usubst]: \"post\\<^sub>s \\<dagger> R2c(P) = R2c(post\\<^sub>s \\<dagger> P)\"\n  by (simp add: R2c_def R2s_def usubst)\n\nlemma cmt\\<^sub>s_R1 [usubst]: \"cmt\\<^sub>s \\<dagger> R1(P) = R1(cmt\\<^sub>s \\<dagger> P)\"\n  by (simp add: R1_def usubst)\n\nlemma cmt\\<^sub>s_R2c [usubst]: \"cmt\\<^sub>s \\<dagger> R2c(P) = R2c(cmt\\<^sub>s \\<dagger> P)\"\n  by (simp add: R2c_def R2s_def usubst)\n\nlemma pre_wait_false:\n  \"pre\\<^sub>R(P\\<lbrakk>false/$wait\\<rbrakk>) = pre\\<^sub>R(P)\"\n  by (rel_auto)\n\nlemma cmt_wait_false:\n  \"cmt\\<^sub>R(P\\<lbrakk>false/$wait\\<rbrakk>) = cmt\\<^sub>R(P)\"\n  by (rel_auto)\n\nlemma subst_tr_pre [usubst]:\n  \"\\<lbrakk> $ok \\<sharp> v; $ok\\<acute> \\<sharp> v; $wait \\<sharp> v \\<rbrakk> \\<Longrightarrow> (pre\\<^sub>R P)\\<lbrakk>v/$tr\\<rbrakk> = pre\\<^sub>R (P\\<lbrakk>v/$tr\\<rbrakk>)\"\n  by (rel_auto)\n\nlemma subst_tr_peri [usubst]:\n  \"\\<lbrakk> $ok \\<sharp> v; $ok\\<acute> \\<sharp> v; $wait \\<sharp> v; $wait\\<acute> \\<sharp> v \\<rbrakk> \\<Longrightarrow> (peri\\<^sub>R P)\\<lbrakk>v/$tr\\<rbrakk> = peri\\<^sub>R (P\\<lbrakk>v/$tr\\<rbrakk>)\"\n  by (rel_auto)\n\nlemma subst_tr_post [usubst]:\n  \"\\<lbrakk> $ok \\<sharp> v; $ok\\<acute> \\<sharp> v; $wait \\<sharp> v; $wait\\<acute> \\<sharp> v \\<rbrakk> \\<Longrightarrow> (post\\<^sub>R P)\\<lbrakk>v/$tr\\<rbrakk> = post\\<^sub>R (P\\<lbrakk>v/$tr\\<rbrakk>)\"\n  by (rel_auto)\n\nlemma rea_pre_RHS_design: \"pre\\<^sub>R(\\<^bold>R\\<^sub>s(P \\<turnstile> Q)) = (\\<not> R1(R2c(pre\\<^sub>s \\<dagger> (\\<not> P))))\"\n  by (simp add: RHS_def usubst R3h_def pre\\<^sub>R_def pre\\<^sub>s_design)\n\nlemma rea_cmt_RHS_design: \"cmt\\<^sub>R(\\<^bold>R\\<^sub>s(P \\<turnstile> Q)) = R1(R2c(cmt\\<^sub>s \\<dagger> (P \\<Rightarrow> Q)))\"\n  by (simp add: RHS_def usubst R3h_def cmt\\<^sub>R_def cmt\\<^sub>s_design)\n\nlemma rea_peri_RHS_design: \"peri\\<^sub>R(\\<^bold>R\\<^sub>s(P \\<turnstile> Q \\<diamondop> R)) = R1(R2c(peri\\<^sub>s \\<dagger> (P \\<Rightarrow> Q)))\"\n  by (simp add:RHS_def usubst peri\\<^sub>R_def R3h_def peri\\<^sub>s_design)\n\nlemma rea_post_RHS_design: \"post\\<^sub>R(\\<^bold>R\\<^sub>s(P \\<turnstile> Q \\<diamondop> R)) = R1(R2c(post\\<^sub>s \\<dagger> (P \\<Rightarrow> R)))\"\n  by (simp add:RHS_def usubst post\\<^sub>R_def R3h_def post\\<^sub>s_design)\n\nlemma wait'_cond_peri_post_cmt:\n  \"peri\\<^sub>R P \\<diamondop> post\\<^sub>R P = cmt\\<^sub>R P\"\n  by (rel_auto, (metis (full_types))+)\n\nlemma rdes_export_cmt: \"\\<^bold>R\\<^sub>s(P \\<turnstile> cmt\\<^sub>s \\<dagger> Q) = \\<^bold>R\\<^sub>s(P \\<turnstile> Q)\"\n  by (rel_auto)\n\nlemma rdes_export_pre: \"\\<^bold>R\\<^sub>s((P\\<lbrakk>true,false/$ok,$wait\\<rbrakk>) \\<turnstile> Q) = \\<^bold>R\\<^sub>s(P \\<turnstile> Q)\"\n  by (rel_auto)\n\nlemma RHS_design_pre_post_form:\n  \"\\<^bold>R\\<^sub>s((\\<not> P\\<^sup>f\\<^sub>f) \\<turnstile> P\\<^sup>t\\<^sub>f) = \\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> cmt\\<^sub>R(P))\"\nproof -\n  have \"\\<^bold>R\\<^sub>s((\\<not> P\\<^sup>f\\<^sub>f) \\<turnstile> P\\<^sup>t\\<^sub>f) = \\<^bold>R\\<^sub>s((\\<not> P\\<^sup>f\\<^sub>f)\\<lbrakk>true/$ok\\<rbrakk> \\<turnstile> P\\<^sup>t\\<^sub>f\\<lbrakk>true/$ok\\<rbrakk>)\"\n    by (simp add: design_subst_ok)\n  also have \"... = \\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> cmt\\<^sub>R(P))\"\n    by (simp add: pre\\<^sub>R_def cmt\\<^sub>R_def usubst)\n  finally show ?thesis .\nqed\n\nlemma SRD_as_reactive_design:\n  \"SRD(P) = \\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> cmt\\<^sub>R(P))\"\n  by (simp add: RHS_design_pre_post_form SRD_RH_design_form)\n\nlemma SRD_reactive_design_alt:\n  assumes \"P is SRD\"\n  shows \"\\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> cmt\\<^sub>R(P)) = P\"\nproof -\n  have \"\\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> cmt\\<^sub>R(P)) = \\<^bold>R\\<^sub>s((\\<not> P\\<^sup>f\\<^sub>f) \\<turnstile> P\\<^sup>t\\<^sub>f)\"\n    by (simp add: RHS_design_pre_post_form)\n  thus ?thesis\n    by (simp add: SRD_reactive_design assms)\nqed\n\nlemma SRD_reactive_tri_design_lemma:\n  \"SRD(P) = \\<^bold>R\\<^sub>s((\\<not> P\\<^sup>f\\<^sub>f) \\<turnstile> P\\<^sup>t\\<^sub>f\\<lbrakk>true/$wait\\<acute>\\<rbrakk> \\<diamondop> P\\<^sup>t\\<^sub>f\\<lbrakk>false/$wait\\<acute>\\<rbrakk>)\"\n  by (simp add: SRD_RH_design_form wait'_cond_split)\n\nlemma SRD_as_reactive_tri_design:\n  \"SRD(P) = \\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> peri\\<^sub>R(P) \\<diamondop> post\\<^sub>R(P))\"\nproof -\n  have \"SRD(P) = \\<^bold>R\\<^sub>s((\\<not> P\\<^sup>f\\<^sub>f) \\<turnstile> P\\<^sup>t\\<^sub>f\\<lbrakk>true/$wait\\<acute>\\<rbrakk> \\<diamondop> P\\<^sup>t\\<^sub>f\\<lbrakk>false/$wait\\<acute>\\<rbrakk>)\"\n    by (simp add: SRD_RH_design_form wait'_cond_split)\n  also have \"... = \\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> peri\\<^sub>R(P) \\<diamondop> post\\<^sub>R(P))\"\n    apply (simp add: usubst)\n    apply (subst design_subst_ok_ok'[THEN sym])\n    apply (simp add: pre\\<^sub>R_def peri\\<^sub>R_def post\\<^sub>R_def usubst unrest)\n  done\n  finally show ?thesis .\nqed\n\nlemma SRD_reactive_tri_design:\n  assumes \"P is SRD\"\n  shows \"\\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> peri\\<^sub>R(P) \\<diamondop> post\\<^sub>R(P)) = P\"\n  by (metis Healthy_if SRD_as_reactive_tri_design assms)\n\nlemma RHS_tri_design_is_SRD:\n  assumes \"$ok\\<acute> \\<sharp> P\" \"$ok\\<acute> \\<sharp> Q\" \"$ok\\<acute> \\<sharp> R\"\n  shows \"\\<^bold>R\\<^sub>s(P \\<turnstile> Q \\<diamondop> R) is SRD\"\n  by (rule RHS_design_is_SRD, simp_all add: unrest assms)\n\nlemma R1_neg_R2s_pre_RHS:\n  assumes \"P is SRD\"\n  shows \"R1 (\\<not> R2s(pre\\<^sub>R(P))) = (\\<not> (pre\\<^sub>R(P)))\"\nproof -\n  have \"(\\<not> pre\\<^sub>R(P)) = (\\<not> pre\\<^sub>R(\\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> peri\\<^sub>R(P) \\<diamondop> post\\<^sub>R(P))))\"\n    by (simp add: SRD_reactive_tri_design assms)\n  also have \"... = R1(R2s(\\<not> pre\\<^sub>R(\\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> peri\\<^sub>R(P) \\<diamondop> post\\<^sub>R(P)))))\"\n    by (rel_auto)\n  also have \"... = R1 (\\<not> R2s(pre\\<^sub>R(\\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> peri\\<^sub>R(P) \\<diamondop> post\\<^sub>R(P)))))\"\n    by (simp add: R2s_not)\n  also have \"... = R1 (\\<not> R2s(pre\\<^sub>R(P)))\"\n    by (simp add: SRD_reactive_tri_design assms)\n  finally show ?thesis ..\nqed\n\nlemma R1_R2s_cmt_SRD:\n  assumes \"P is SRD\"\n  shows \"R1(R2s(cmt\\<^sub>R(P))) = cmt\\<^sub>R(P)\"\n  by (metis (no_types, hide_lams) Healthy_def R1_R2s_R2c R2_def R2_idem SRD_as_reactive_design assms rea_cmt_RHS_design)\n\nlemma R1_R2s_peri_SRD:\n  assumes \"P is SRD\"\n  shows \"R1(R2s(peri\\<^sub>R(P))) = peri\\<^sub>R(P)\"\n  by (metis (no_types, hide_lams) Healthy_def R1_R2s_R2c R2_def R2_idem RHS_def SRD_RH_design_form assms peri\\<^sub>R_def peri\\<^sub>s_R1 peri\\<^sub>s_R2c)\n\nlemma R1_R2s_post_SRD:\n  assumes \"P is SRD\"\n  shows \"R1(R2s(post\\<^sub>R(P))) = post\\<^sub>R(P)\"\n  by (metis (no_types, hide_lams) Healthy_def R1_R2s_R2c R2_def R2_idem RHS_def SRD_RH_design_form assms post\\<^sub>R_def post\\<^sub>s_R1 post\\<^sub>s_R2c)\n\nlemma RHS_pre_lemma: \"(\\<^bold>R\\<^sub>s P)\\<^sup>f\\<^sub>f = R1(R2c(P\\<^sup>f\\<^sub>f))\"\n  by (rel_auto)\n\nlemma RHS_design_neg_R1_pre:\n  \"\\<^bold>R\\<^sub>s ((\\<not> R1 P) \\<turnstile> R) = \\<^bold>R\\<^sub>s ((\\<not> P) \\<turnstile> R)\"\n  by (rel_auto)\n\nlemma RHS_design_conj_neg_R1_pre:\n  \"\\<^bold>R\\<^sub>s (((\\<not> R1 P) \\<and> Q) \\<turnstile> R) = \\<^bold>R\\<^sub>s (((\\<not> P) \\<and> Q) \\<turnstile> R)\"\n  by (rel_auto)\n\nlemma RHS_design_R2c_pre:\n  \"\\<^bold>R\\<^sub>s(R2c(P) \\<turnstile> Q) = \\<^bold>R\\<^sub>s(P \\<turnstile> Q)\"\n  by (rel_auto)\n\nlemma UINF_R1_neg_R2s_pre_RHS:\n  assumes \"A \\<subseteq> \\<lbrakk>SRD\\<rbrakk>\\<^sub>H\"\n  shows \"(\\<Sqinter> P \\<in> A \\<bullet> R1 (\\<not> R2s (pre\\<^sub>R P))) = (\\<Sqinter> P \\<in> A \\<bullet> \\<not> (pre\\<^sub>R P))\"\n  by (rule UINF_cong[of A], metis (no_types, lifting) Ball_Collect R1_neg_R2s_pre_RHS assms)\n\nlemma USUP_R1_R2s_cmt_SRD:\n  assumes \"A \\<subseteq> \\<lbrakk>SRD\\<rbrakk>\\<^sub>H\"\n  shows \"(\\<Squnion> P \\<in> A \\<bullet> R1 (R2s (cmt\\<^sub>R P))) = (\\<Squnion> P \\<in> A \\<bullet> cmt\\<^sub>R P)\"\n  by (rule USUP_cong[of A], metis (mono_tags, lifting) Ball_Collect R1_R2s_cmt_SRD assms)\n\nlemma UINF_R1_R2s_cmt_SRD:\n  assumes \"A \\<subseteq> \\<lbrakk>SRD\\<rbrakk>\\<^sub>H\"\n  shows \"(\\<Sqinter> P \\<in> A \\<bullet> R1 (R2s (cmt\\<^sub>R P))) = (\\<Sqinter> P \\<in> A \\<bullet> cmt\\<^sub>R P)\"\n  by (rule UINF_cong[of A], metis (mono_tags, lifting) Ball_Collect R1_R2s_cmt_SRD assms)\n\nlemma SRD_composition:\n  assumes \"P is SRD\" \"Q is SRD\"\n  shows \"(P ;; Q) = \\<^bold>R\\<^sub>s ((\\<not> ((\\<not> pre\\<^sub>R P) ;; R1 true) \\<and> \\<not> (post\\<^sub>R P ;; (\\<not> pre\\<^sub>R Q))) \\<turnstile>\n                       ((\\<exists> $st\\<acute> \\<bullet> peri\\<^sub>R P) \\<or> (post\\<^sub>R P ;; peri\\<^sub>R Q)) \\<diamondop> (post\\<^sub>R P ;; post\\<^sub>R Q))\"\nproof -\n  have \"(P ;; Q) = (\\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> peri\\<^sub>R(P) \\<diamondop> post\\<^sub>R(P)) ;; \\<^bold>R\\<^sub>s(pre\\<^sub>R(Q) \\<turnstile> peri\\<^sub>R(Q) \\<diamondop> post\\<^sub>R(Q)))\"\n    by (simp add: SRD_reactive_tri_design assms(1) assms(2))\n  also from assms have \"... = \\<^bold>R\\<^sub>s ((\\<not> ((\\<not> pre\\<^sub>R P) ;; R1 true) \\<and> \\<not> (post\\<^sub>R P ;; (\\<not> pre\\<^sub>R Q))) \\<turnstile>\n        ((\\<exists> $st\\<acute> \\<bullet> peri\\<^sub>R P) \\<or> (post\\<^sub>R P ;; peri\\<^sub>R Q)) \\<diamondop> (post\\<^sub>R P ;; post\\<^sub>R Q))\"\n    by (simp add: RHS_tri_design_composition unrest R1_R2s_peri_SRD R1_R2s_post_SRD R1_neg_R2s_pre_RHS)\n  finally show ?thesis .\nqed\n\nlemma SRD_composition_wp:\n  assumes \"P is SRD\" \"Q is SRD\"\n  shows \"(P ;; Q) = \\<^bold>R\\<^sub>s (((\\<not> pre\\<^sub>R P) wp\\<^sub>R false \\<and> post\\<^sub>R P wp\\<^sub>R pre\\<^sub>R Q) \\<turnstile>\n                       ((\\<exists> $st\\<acute> \\<bullet> peri\\<^sub>R P) \\<or> (post\\<^sub>R P ;; peri\\<^sub>R Q)) \\<diamondop> (post\\<^sub>R P ;; post\\<^sub>R Q))\"\n  using assms\n  by (simp add: SRD_composition wpR_def, metis (no_types, lifting) R1_idem R1_neg_R2s_pre_RHS)\n\nlemma SRD_seqr_closure:\n  assumes \"P is SRD\" \"Q is SRD\"\n  shows \"(P ;; Q) is SRD\"\nproof -\n  have \"(P ;; Q) = \\<^bold>R\\<^sub>s ((\\<not> ((\\<not> pre\\<^sub>R P) ;; R1 true) \\<and> \\<not> (post\\<^sub>R P ;; (\\<not> pre\\<^sub>R Q))) \\<turnstile>\n                       ((\\<exists> $st\\<acute> \\<bullet> peri\\<^sub>R P) \\<or> (post\\<^sub>R P ;; peri\\<^sub>R Q)) \\<diamondop> (post\\<^sub>R P ;; post\\<^sub>R Q))\"\n    by (simp add: SRD_composition assms(1) assms(2))\n  also have \"... is SRD\"\n    by (simp add: RHS_design_is_SRD add: unrest)\n  finally show ?thesis .\nqed\n\nsubsection {* Reactive design signature *}\n  \nlemma srdes_skip_def: \"II\\<^sub>R = \\<^bold>R\\<^sub>s(true \\<turnstile> ($tr\\<acute> =\\<^sub>u $tr \\<and> \\<not> $wait\\<acute> \\<and> \\<lceil>II\\<rceil>\\<^sub>R))\"\n  apply (rel_auto) using minus_zero_eq by blast+\n\ntext {* This additional healthiness condition is analogous to H3 *}\n\ndefinition [upred_defs]: \"RD3(P) = P ;; II\\<^sub>R\"\n\ndefinition assigns_rea :: \"'s usubst \\<Rightarrow> ('s, 't::ordered_cancel_monoid_diff, '\\<alpha>) hrel_rsp\" (\"\\<langle>_\\<rangle>\\<^sub>R\") where\n[upred_defs]: \"assigns_rea \\<sigma> = \\<^bold>R\\<^sub>s(true \\<turnstile> ($tr\\<acute> =\\<^sub>u $tr \\<and> \\<not> $wait\\<acute> \\<and> \\<lceil>\\<langle>\\<sigma>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>S \\<and> $\\<Sigma>\\<^sub>S\\<acute> =\\<^sub>u $\\<Sigma>\\<^sub>S))\"\n\nabbreviation Chaos :: \"('s,'t::ordered_cancel_monoid_diff,'\\<alpha>) hrel_rsp\" where\n\"Chaos \\<equiv> \\<^bold>\\<bottom>\\<^bsub>SRDES\\<^esub>\"\n\nabbreviation Miracle :: \"('s,'t::ordered_cancel_monoid_diff,'\\<alpha>) hrel_rsp\" where\n\"Miracle \\<equiv> \\<^bold>\\<top>\\<^bsub>SRDES\\<^esub>\"\n\nlemma Chaos_def: \"Chaos = \\<^bold>R\\<^sub>s(false \\<turnstile> true)\"\nproof -\n  have \"Chaos = SRD(true)\"\n    by (metis srdes_hcond_def srdes_theory_continuous.healthy_bottom)\n  also have \"... = \\<^bold>R\\<^sub>s(\\<^bold>H(true))\"\n    by (simp add: SRD_RHS_H1_H2)\n  also have \"... = \\<^bold>R\\<^sub>s(false \\<turnstile> true)\"\n    by (metis H1_design H2_true design_false_pre)\n  finally show ?thesis .\nqed\n\nlemma Miracle_def: \"Miracle = \\<^bold>R\\<^sub>s(true \\<turnstile> false)\"\nproof -\n  have \"Miracle = SRD(false)\"\n    by (metis srdes_hcond_def srdes_theory_continuous.healthy_top)\n  also have \"... = \\<^bold>R\\<^sub>s(\\<^bold>H(false))\"\n    by (simp add: SRD_RHS_H1_H2)\n  also have \"... = \\<^bold>R\\<^sub>s(true \\<turnstile> false)\"\n    by (metis (no_types, lifting) H1_H2_eq_design p_imp_p subst_impl subst_not utp_pred.compl_bot_eq utp_pred.compl_top_eq)\n  finally show ?thesis .\nqed\n\nthm srdes_theory_continuous.weak.bottom_lower\nthm srdes_theory_continuous.weak.top_higher\nthm srdes_theory_continuous.meet_bottom\nthm srdes_theory_continuous.meet_top\n\nlemma Miracle_left_zero:\n  assumes \"P is SRD\"\n  shows \"Miracle ;; P = Miracle\"\nproof -\n  have \"Miracle ;; P = \\<^bold>R\\<^sub>s(true \\<turnstile> false) ;; \\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> cmt\\<^sub>R(P))\"\n    by (simp add: Miracle_def SRD_reactive_design_alt assms)\n  also have \"... = \\<^bold>R\\<^sub>s(true \\<turnstile> false)\"\n    by (simp add: RHS_design_composition unrest R1_false R2s_false R2s_true)\n  also have \"... = Miracle\"\n    by (simp add: Miracle_def)\n  finally show ?thesis .\nqed\n\nlemma Chaos_left_zero:\n  assumes \"P is SRD\"\n  shows \"(Chaos ;; P) = Chaos\"\nproof -\n  have \"Chaos ;; P = \\<^bold>R\\<^sub>s(false \\<turnstile> true) ;; \\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> cmt\\<^sub>R(P))\"\n    by (simp add: Chaos_def SRD_reactive_design_alt assms)\n  also have \"... = \\<^bold>R\\<^sub>s ((\\<not> R1 true \\<and> \\<not> (R1 true \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s (pre\\<^sub>R P))) \\<turnstile>\n                       (R1 true ;; (\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1 (R2s (cmt\\<^sub>R P))))\"\n    by (simp add: RHS_design_composition unrest R2s_false R2s_true R1_false R1_true_comp)\n  also have \"... = \\<^bold>R\\<^sub>s ((false \\<and> \\<not> (R1 true \\<and> \\<not> $wait\\<acute>) ;; R1 (\\<not> R2s (pre\\<^sub>R P))) \\<turnstile>\n                       (R1 true ;; (\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> R1 (R2s (cmt\\<^sub>R P))))\"\n    by (simp add: RHS_design_conj_neg_R1_pre)\n  also have \"... = \\<^bold>R\\<^sub>s(true)\"\n    by (simp add: design_false_pre)\n  also have \"... = \\<^bold>R\\<^sub>s(false \\<turnstile> true)\"\n    by (simp add: design_def)\n  also have \"... = Chaos\"\n    by (simp add: Chaos_def)\n  finally show ?thesis .\nqed\n\nlemma assigns_rea_RHS_tri_des:\n  \"\\<langle>\\<sigma>\\<rangle>\\<^sub>R = \\<^bold>R\\<^sub>s(true \\<turnstile> false \\<diamondop> ($tr\\<acute> =\\<^sub>u $tr \\<and> \\<lceil>\\<langle>\\<sigma>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>S \\<and> $\\<Sigma>\\<^sub>S\\<acute> =\\<^sub>u $\\<Sigma>\\<^sub>S))\"\n  by (rel_auto)\n\nlemma preR_Miracle: \"pre\\<^sub>R(Miracle) = true\"\n  by (simp add: Miracle_def, rel_auto)\n\nlemma periR_Miracle: \"peri\\<^sub>R(Miracle) = false\"\n  by (simp add: Miracle_def, rel_auto)\n\nlemma postR_Miracle: \"post\\<^sub>R(Miracle) = false\"\n  by (simp add: Miracle_def, rel_auto)\n\nlemma preR_srdes_skip: \"pre\\<^sub>R(II\\<^sub>R) = true\"\n  by (rel_auto)\n\nlemma periR_srdes_skip: \"peri\\<^sub>R(II\\<^sub>R) = false\"\n  by (rel_auto)\n\nlemma postR_srdes_skip: \"post\\<^sub>R(II\\<^sub>R) = ($tr\\<acute> =\\<^sub>u $tr \\<and> \\<lceil>II\\<rceil>\\<^sub>R)\"\n  by (rel_auto) \n\nlemma preR_assigns_rea: \"pre\\<^sub>R(\\<langle>\\<sigma>\\<rangle>\\<^sub>R) = true\"\n  by (simp add: assigns_rea_def rea_pre_RHS_design usubst R2c_false R1_false)\n\nlemma periR_assigns_rea: \"peri\\<^sub>R(\\<langle>\\<sigma>\\<rangle>\\<^sub>R) = false\"\n  by (simp add: assigns_rea_RHS_tri_des rea_peri_RHS_design usubst R2c_false R1_false)\n\nlemma postR_assigns_rea: \"post\\<^sub>R(\\<langle>\\<sigma>\\<rangle>\\<^sub>R) = ($tr\\<acute> =\\<^sub>u $tr \\<and> \\<lceil>\\<langle>\\<sigma>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>S \\<and> $\\<Sigma>\\<^sub>S\\<acute> =\\<^sub>u $\\<Sigma>\\<^sub>S)\"\n  apply (rel_auto) using minus_zero_eq by blast\n\nlemma RHS_design_choice: \"\\<^bold>R\\<^sub>s(P\\<^sub>1 \\<turnstile> Q\\<^sub>1) \\<sqinter> \\<^bold>R\\<^sub>s(P\\<^sub>2 \\<turnstile> Q\\<^sub>2) = \\<^bold>R\\<^sub>s((P\\<^sub>1 \\<and> P\\<^sub>2) \\<turnstile> (Q\\<^sub>1 \\<or> Q\\<^sub>2))\"\n  by (metis RHS_inf design_choice)\n\nlemma RHS_tri_design_choice: \"\\<^bold>R\\<^sub>s(P\\<^sub>1 \\<turnstile> P\\<^sub>2 \\<diamondop> P\\<^sub>3) \\<sqinter> \\<^bold>R\\<^sub>s(Q\\<^sub>1 \\<turnstile> Q\\<^sub>2 \\<diamondop> Q\\<^sub>3) = \\<^bold>R\\<^sub>s((P\\<^sub>1 \\<and> Q\\<^sub>1) \\<turnstile> (P\\<^sub>2 \\<or> Q\\<^sub>2) \\<diamondop> (P\\<^sub>3 \\<or> Q\\<^sub>3))\"\n  apply (simp add: RHS_design_choice)\n  apply (rule cong[of \"\\<^bold>R\\<^sub>s\" \"\\<^bold>R\\<^sub>s\"])\n  apply (simp)\n  apply (rel_auto)\ndone\n\nlemma RHS_design_USUP:\n  assumes \"A \\<noteq> {}\"\n  shows \"(\\<Sqinter> i \\<in> A \\<bullet> \\<^bold>R\\<^sub>s(P(i) \\<turnstile> Q(i))) = \\<^bold>R\\<^sub>s((\\<Squnion> i \\<in> A \\<bullet> P(i)) \\<turnstile> (\\<Sqinter> i \\<in> A \\<bullet> Q(i)))\"\n  by (subst RHS_INF[OF assms, THEN sym], simp add: design_USUP assms)\n\nlemma SRD_left_unit:\n  assumes \"P is SRD\"\n  shows \"II\\<^sub>R ;; P = P\"\nproof -\n  have \"II\\<^sub>R ;; P = \\<^bold>R\\<^sub>s(true \\<turnstile> ($tr\\<acute> =\\<^sub>u $tr \\<and> \\<not> $wait\\<acute> \\<and> \\<lceil>II\\<rceil>\\<^sub>R)) ;; \\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> cmt\\<^sub>R(P))\"\n    by (simp add: SRD_reactive_design_alt assms srdes_skip_def)\n  also have \"... =  \\<^bold>R\\<^sub>s ((\\<not> (($tr\\<acute> =\\<^sub>u $tr \\<and> \\<not> $wait\\<acute> \\<and> \\<lceil>II\\<rceil>\\<^sub>R) \\<and> \\<not> $wait\\<acute>) ;; (\\<not> pre\\<^sub>R P)) \\<turnstile>\n                        (($tr\\<acute> =\\<^sub>u $tr \\<and> \\<not> $wait\\<acute> \\<and> \\<lceil>II\\<rceil>\\<^sub>R) ;; (\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> cmt\\<^sub>R P))\"\n    by (simp add: RHS_design_composition unrest R2s_true R1_false R1_R2s_cmt_SRD R2s_wait' R2s_not\n                  R1_neg_R2s_pre_RHS assms R2s_conj R1_extend_conj R1_R2s_tr'_eq_tr R2s_lift_rea)\n  also have \"... =  \\<^bold>R\\<^sub>s (pre\\<^sub>R P \\<turnstile>\n                        (($tr\\<acute> =\\<^sub>u $tr \\<and> \\<not> $wait\\<acute> \\<and> \\<lceil>II\\<rceil>\\<^sub>R) ;; (\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> cmt\\<^sub>R P))\"\n    by (rule cong[of \"\\<^bold>R\\<^sub>s\" \"\\<^bold>R\\<^sub>s\"], simp, rel_auto)\n  also have \"... =  \\<^bold>R\\<^sub>s (pre\\<^sub>R P \\<turnstile> (($tr\\<acute> =\\<^sub>u $tr \\<and> \\<lceil>II\\<rceil>\\<^sub>R) ;; cmt\\<^sub>R P))\"\n    by (rule cong[of \"\\<^bold>R\\<^sub>s\" \"\\<^bold>R\\<^sub>s\"], simp, rel_auto)\n  also have \"... =  \\<^bold>R\\<^sub>s (pre\\<^sub>R P \\<turnstile> cmt\\<^sub>R P)\"\n    by (rule cong[of \"\\<^bold>R\\<^sub>s\" \"\\<^bold>R\\<^sub>s\"], simp, rel_auto)\n  finally show ?thesis\n    by (simp add: SRD_reactive_design_alt assms)\nqed\n\nlemma SRD_right_unit_lemma:\n  assumes \"P is SRD\"\n  shows \"P ;; II\\<^sub>R = \\<^bold>R\\<^sub>s ((\\<not> (\\<not> pre\\<^sub>R P) ;; R1 true) \\<turnstile> ((\\<exists> $st\\<acute> \\<bullet> cmt\\<^sub>R P) \\<triangleleft> $wait\\<acute> \\<triangleright> cmt\\<^sub>R P))\"\nproof -\n  have \"P ;; II\\<^sub>R = \\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> cmt\\<^sub>R(P)) ;; \\<^bold>R\\<^sub>s(true \\<turnstile> ($tr\\<acute> =\\<^sub>u $tr \\<and> \\<not> $wait\\<acute> \\<and> \\<lceil>II\\<rceil>\\<^sub>R))\"\n    by (simp add: SRD_reactive_design_alt assms srdes_skip_def)\n  also have \"... = \\<^bold>R\\<^sub>s ((\\<not> (\\<not> pre\\<^sub>R P) ;; R1 true) \\<turnstile>\n                       (cmt\\<^sub>R P ;; (\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D) \\<triangleleft> $wait \\<triangleright> ($tr\\<acute> =\\<^sub>u $tr \\<and> \\<not> $wait\\<acute> \\<and> \\<lceil>II\\<rceil>\\<^sub>R)))\"\n    by (simp add: RHS_design_composition unrest R2s_true R1_false R1_R2s_cmt_SRD R2s_wait' R2s_not\n                  R1_neg_R2s_pre_RHS assms R2s_conj R1_extend_conj R1_R2s_tr'_eq_tr R2s_lift_rea)\n  also have \"... = \\<^bold>R\\<^sub>s ((\\<not> (\\<not> pre\\<^sub>R P) ;; R1 true) \\<turnstile> ((\\<exists> $st\\<acute> \\<bullet> cmt\\<^sub>R P) \\<triangleleft> $wait\\<acute> \\<triangleright> cmt\\<^sub>R P))\"\n    by (rule cong[of \"\\<^bold>R\\<^sub>s\" \"\\<^bold>R\\<^sub>s\"], simp, rel_auto)\n  finally show ?thesis .\nqed\n\nlemma SRD_right_unit_tri_lemma:\n  assumes \"P is SRD\"\n  shows \"P ;; II\\<^sub>R = \\<^bold>R\\<^sub>s ((\\<not> (\\<not> pre\\<^sub>R P) ;; R1 true) \\<turnstile> ((\\<exists> $st\\<acute> \\<bullet> peri\\<^sub>R(P)) \\<diamondop> post\\<^sub>R P))\"\nproof -\n  have \"((\\<exists> $st\\<acute> \\<bullet> cmt\\<^sub>R P) \\<triangleleft> $wait\\<acute> \\<triangleright> cmt\\<^sub>R P) = (\\<exists> $st\\<acute> \\<bullet> peri\\<^sub>R P) \\<diamondop> post\\<^sub>R P\"\n    by (rel_auto)\n  thus ?thesis\n    by (simp add: SRD_right_unit_lemma assms)\nqed\n\nlemma SRD_srdes_skip: \"II\\<^sub>R is SRD\"\n  by (simp add: srdes_skip_def RHS_design_is_SRD unrest)\n\nlemma srdes_skip_tri_design: \"II\\<^sub>R = \\<^bold>R\\<^sub>s(true \\<turnstile> false \\<diamondop> ($tr\\<acute> =\\<^sub>u $tr \\<and> \\<lceil>II\\<rceil>\\<^sub>R))\"\n  by (simp add: srdes_skip_def, rel_auto)\n  \nlemma SRD_right_Chaos_lemma:\n  assumes \"P is SRD\"\n  shows \"P ;; Chaos = \\<^bold>R\\<^sub>s ((\\<not> (\\<not> pre\\<^sub>R P) ;; R1 true \\<and> \\<not> (cmt\\<^sub>R P \\<and> \\<not> $wait\\<acute>) ;; R1 true) \\<turnstile> ((\\<exists> $st\\<acute> \\<bullet> cmt\\<^sub>R P) \\<and> $wait\\<acute>))\"\nproof -\n  have \"P ;; Chaos = \\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> cmt\\<^sub>R(P)) ;; \\<^bold>R\\<^sub>s(false \\<turnstile> false)\"\n    by (simp add: Chaos_def SRD_reactive_design_alt assms design_false_pre)\n  also have \"... = \\<^bold>R\\<^sub>s ((\\<not> (\\<not> pre\\<^sub>R P) ;; R1 true \\<and> \\<not> (cmt\\<^sub>R P \\<and> \\<not> $wait\\<acute>) ;; R1 true) \\<turnstile> (cmt\\<^sub>R P ;; ($wait \\<and> (\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D))))\"\n    by (simp add: RHS_design_composition unrest R2s_true R1_false R1_R2s_cmt_SRD R2s_wait' R2s_false R2s_not\n                  R1_neg_R2s_pre_RHS assms R2s_conj R1_extend_conj R1_R2s_tr'_eq_tr R2s_lift_rea)\n       (simp add: cond_def)\n  also have \"... = \\<^bold>R\\<^sub>s ((\\<not> (\\<not> pre\\<^sub>R P) ;; R1 true \\<and> \\<not> (cmt\\<^sub>R P \\<and> \\<not> $wait\\<acute>) ;; R1 true) \\<turnstile> ((\\<exists> $st\\<acute> \\<bullet> cmt\\<^sub>R P) \\<and> $wait\\<acute>))\"\n    by (rule cong[of \"\\<^bold>R\\<^sub>s\" \"\\<^bold>R\\<^sub>s\"], simp, rel_auto)\n  finally show ?thesis .\nqed\n\nlemma SRD_right_Chaos_tri_lemma:\n  assumes \"P is SRD\"\n  shows \"P ;; Chaos = \\<^bold>R\\<^sub>s ((\\<not> (\\<not> pre\\<^sub>R P) ;; R1 true \\<and> \\<not> (post\\<^sub>R P ;; R1 true)) \\<turnstile> ((\\<exists> $st\\<acute> \\<bullet> peri\\<^sub>R P) \\<diamondop> false))\"\nproof -\n  have \"(\\<not> (cmt\\<^sub>R P \\<and> \\<not> $wait\\<acute>) ;; R1 true) = (\\<not> (post\\<^sub>R P ;; R1 true\\<^sub>h))\"\n    by (rel_auto, blast)\n  moreover have \"((\\<exists> $st\\<acute> \\<bullet> cmt\\<^sub>R P) \\<and> $wait\\<acute>) = (\\<exists> $st\\<acute> \\<bullet> peri\\<^sub>R P) \\<diamondop> false\"\n    by (rel_auto)\n  ultimately show ?thesis\n    by (simp add: SRD_right_Chaos_lemma[OF assms])\nqed\n \nlemma SRD_right_Miracle_lemma:\n  assumes \"P is SRD\"\n  shows \"P ;; Miracle = \\<^bold>R\\<^sub>s ((\\<not> (\\<not> pre\\<^sub>R P) ;; R1 true) \\<turnstile> ((\\<exists> $st\\<acute> \\<bullet> cmt\\<^sub>R P) \\<and> $wait\\<acute>))\"\nproof -\n  have \"P ;; Miracle = \\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> cmt\\<^sub>R(P)) ;; \\<^bold>R\\<^sub>s(true \\<turnstile> false)\"\n    by (simp add: Miracle_def SRD_reactive_design_alt assms design_false_pre)\n  also have \"... = \\<^bold>R\\<^sub>s ((\\<not> (\\<not> pre\\<^sub>R P) ;; R1 true) \\<turnstile> (cmt\\<^sub>R P ;; ($wait \\<and> (\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>D))))\"\n    by (simp add: RHS_design_composition unrest R2s_true R1_false R1_R2s_cmt_SRD R2s_wait' R2s_false R2s_not\n                  R1_neg_R2s_pre_RHS assms R2s_conj R1_extend_conj R1_R2s_tr'_eq_tr R2s_lift_rea)\n       (simp add: cond_def)\n  also have \"... = \\<^bold>R\\<^sub>s ((\\<not> (\\<not> pre\\<^sub>R P) ;; R1 true) \\<turnstile> ((\\<exists> $st\\<acute> \\<bullet> cmt\\<^sub>R P) \\<and> $wait\\<acute>))\"\n    by (rule cong[of \"\\<^bold>R\\<^sub>s\" \"\\<^bold>R\\<^sub>s\"], simp, rel_auto)\n  finally show ?thesis .\nqed\n\nlemma SRD_right_Miracle_tri_lemma:\n  assumes \"P is SRD\"\n  shows \"P ;; Miracle = \\<^bold>R\\<^sub>s ((\\<not> (\\<not> pre\\<^sub>R P) ;; R1 true) \\<turnstile> (\\<exists> $st\\<acute> \\<bullet> peri\\<^sub>R P) \\<diamondop> false)\"\n  by (simp add: SRD_right_Miracle_lemma[OF assms], rule cong[of \"\\<^bold>R\\<^sub>s\" \"\\<^bold>R\\<^sub>s\"], simp, rel_auto)\n  \ntext {* Properties about healthiness condition RD3 *}\n\nlemma RD3_idem: \"RD3(RD3(P)) = RD3(P)\"\nproof -\n  have a: \"II\\<^sub>R ;; II\\<^sub>R = II\\<^sub>R\"\n    by (simp add: SRD_left_unit SRD_srdes_skip)\n  show ?thesis\n    by (simp add: RD3_def seqr_assoc[THEN sym] a)\nqed\n\nlemma RD3_Idempotent: \"Idempotent RD3\"\n  by (simp add: Idempotent_def RD3_idem)\n\nlemma RD3_continuous: \"RD3(\\<Sqinter>A) = (\\<Sqinter>P\\<in>A. RD3(P))\"\n  by (simp add: RD3_def seq_Sup_distr)\n\nlemma RD3_Continuous: \"Continuous RD3\"\n  by (simp add: Continuous_def RD3_continuous)\n\nlemma RD3_right_subsumes_RD2: \"RD2(RD3(P)) = RD3(P)\"\nproof -\n  have a:\"II\\<^sub>R ;; J = II\\<^sub>R\"\n    by (rel_auto)\n  show ?thesis\n    by (metis (no_types, hide_lams) H2_def RD2_def RD3_def a seqr_assoc)\nqed\n\nlemma RD3_left_subsumes_RD2: \"RD3(RD2(P)) = RD3(P)\"\nproof -\n  have a:\"J ;; II\\<^sub>R = II\\<^sub>R\"\n    by (rel_simp, safe, blast+)\n  show ?thesis\n    by (metis (no_types, hide_lams) H2_def RD2_def RD3_def a seqr_assoc)\nqed\n\nlemma RD3_implies_RD2: \"P is RD3 \\<Longrightarrow> P is RD2\"\n  by (metis Healthy_def RD3_right_subsumes_RD2)\n\nlemma RD3_intro_pre:\n  assumes \"P is SRD\" \"(\\<not> pre\\<^sub>R(P)) ;; R1(true) = (\\<not> pre\\<^sub>R(P))\" \"$st\\<acute> \\<sharp> peri\\<^sub>R(P)\"\n  shows \"P is RD3\"\nproof -\n  have \"RD3(P) = \\<^bold>R\\<^sub>s ((\\<not> (\\<not> pre\\<^sub>R P) ;; R1 true) \\<turnstile> (\\<exists> $st\\<acute> \\<bullet> peri\\<^sub>R P) \\<diamondop> post\\<^sub>R P)\"\n    by (simp add: RD3_def SRD_right_unit_tri_lemma assms)\n  also have \"... = \\<^bold>R\\<^sub>s ((\\<not> (\\<not> pre\\<^sub>R P) ;; R1 true) \\<turnstile> peri\\<^sub>R P \\<diamondop> post\\<^sub>R P)\"\n    by (simp add: assms(3) ex_unrest)\n  also have \"... = \\<^bold>R\\<^sub>s ((\\<not> (\\<not> pre\\<^sub>R P) ;; R1 true) \\<turnstile> cmt\\<^sub>R P)\"\n    by (simp add: wait'_cond_peri_post_cmt)\n  also have \"... = \\<^bold>R\\<^sub>s (pre\\<^sub>R P \\<turnstile> cmt\\<^sub>R P)\"\n    by (simp add: assms(2))\n  finally show ?thesis\n    by (metis Healthy_def SRD_as_reactive_design assms(1))\nqed\n\nlemma RHS_tri_design_right_unit_lemma:\n  assumes \"$ok\\<acute> \\<sharp> P\" \"$ok\\<acute> \\<sharp> Q\" \"$ok\\<acute> \\<sharp> R\" \"$wait\\<acute> \\<sharp> R\"\n  shows \"\\<^bold>R\\<^sub>s(P \\<turnstile> Q \\<diamondop> R) ;; II\\<^sub>R = \\<^bold>R\\<^sub>s((\\<not> (\\<not> P) ;; R1 true) \\<turnstile> ((\\<exists> $st\\<acute> \\<bullet> Q) \\<diamondop> R))\"\nproof -\n  have \"\\<^bold>R\\<^sub>s(P \\<turnstile> Q \\<diamondop> R) ;; II\\<^sub>R = \\<^bold>R\\<^sub>s(P \\<turnstile> Q \\<diamondop> R) ;; \\<^bold>R\\<^sub>s(true \\<turnstile> false \\<diamondop> ($tr\\<acute> =\\<^sub>u $tr \\<and> \\<lceil>II\\<rceil>\\<^sub>R))\"\n    by (simp add: srdes_skip_tri_design)\n  also have \"... = \\<^bold>R\\<^sub>s ((\\<not> R1 (\\<not> R2s P) ;; R1 true) \\<turnstile> (\\<exists> $st\\<acute> \\<bullet> Q) \\<diamondop> (R1 (R2s R) ;; R1 (R2s ($tr\\<acute> =\\<^sub>u $tr \\<and> \\<lceil>II\\<rceil>\\<^sub>R))))\"\n    by (simp_all add: RHS_tri_design_composition assms unrest R2s_true R1_false R2s_false)\n  also have \"... = \\<^bold>R\\<^sub>s ((\\<not> R1 (\\<not> R2s P) ;; R1 true) \\<turnstile> (\\<exists> $st\\<acute> \\<bullet> Q) \\<diamondop> R1 (R2s R))\"\n  proof -\n    from assms(3,4) have \"(R1 (R2s R) ;; R1 (R2s ($tr\\<acute> =\\<^sub>u $tr \\<and> \\<lceil>II\\<rceil>\\<^sub>R))) = R1 (R2s R)\"\n      by (rel_auto, metis (no_types, lifting) minus_zero_eq, meson order_refl ordered_cancel_monoid_diff_class.diff_cancel)\n    thus ?thesis\n      by simp\n  qed\n  also have \"... = \\<^bold>R\\<^sub>s((\\<not> (\\<not> P) ;; R1 true) \\<turnstile> ((\\<exists> $st\\<acute> \\<bullet> Q) \\<diamondop> R))\"\n    by (metis (no_types, lifting) R1_R2s_R1_true_lemma R1_R2s_R2c R2c_not RHS_design_R2c_pre RHS_design_neg_R1_pre RHS_design_post_R1 RHS_design_post_R2s)\n  finally show ?thesis .\nqed\n\nlemma RHS_tri_design_RD3_intro:\n  assumes\n    \"$ok\\<acute> \\<sharp> P\" \"$ok\\<acute> \\<sharp> Q\" \"$ok\\<acute> \\<sharp> R\" \"$st\\<acute> \\<sharp> Q\"  \"$wait\\<acute> \\<sharp> R\"\n    \"(\\<not> P) ;; R1(true) = (\\<not> P)\"\n  shows \"\\<^bold>R\\<^sub>s(P \\<turnstile> Q \\<diamondop> R) is RD3\"\n  apply (simp add: Healthy_def RD3_def)\n  apply (subst RHS_tri_design_right_unit_lemma)\n  apply (simp_all add:assms ex_unrest)\ndone\n\ntext {* RD3 reactive designs are those whose assumption can be written as a conjunction of a\n  precondition on (undashed) program variables, and a negated statement about the trace. The latter\n  allows us to state that certain events must not occur in the trace -- which are effectively safety\n  properties. *}\n\nlemma R1_right_unit_lemma:\n  \"\\<lbrakk> out\\<alpha> \\<sharp> b; out\\<alpha> \\<sharp> e \\<rbrakk> \\<Longrightarrow> (b \\<or> $tr ^\\<^sub>u e \\<le>\\<^sub>u $tr\\<acute>) ;; R1(true) = (b \\<or> $tr ^\\<^sub>u e \\<le>\\<^sub>u $tr\\<acute>)\"\n  by (rel_auto, blast, metis (no_types, lifting) dual_order.trans)\n\nlemma RHS_tri_design_RD3_intro_form:\n  assumes\n    \"out\\<alpha> \\<sharp> b\" \"out\\<alpha> \\<sharp> e\" \"$ok\\<acute> \\<sharp> Q\" \"$st\\<acute> \\<sharp> Q\" \"$ok\\<acute> \\<sharp> R\" \"$wait\\<acute> \\<sharp> R\"\n  shows \"\\<^bold>R\\<^sub>s((b \\<and> \\<not> $tr ^\\<^sub>u e \\<le>\\<^sub>u $tr\\<acute>) \\<turnstile> Q \\<diamondop> R) is RD3\"\n  apply (rule RHS_tri_design_RD3_intro)\n  apply (simp_all add: assms unrest)\n  apply (simp add: R1_right_unit_lemma assms(1) assms(2) unrest_not)\ndone\n\ndefinition NSRD :: \"('s,'t::ordered_cancel_monoid_diff,'\\<alpha>) hrel_rsp \\<Rightarrow> ('s,'t,'\\<alpha>) hrel_rsp\"\nwhere [upred_defs]: \"NSRD = RD1 \\<circ> RD3 \\<circ> RHS\"\n\nlemma RD1_RD3_commute: \"RD1(RD3(P)) = RD3(RD1(P))\"\n  by (rel_auto, blast+)\n\nlemma NSRD_is_SRD: \"P is NSRD \\<Longrightarrow> P is SRD\"\n  by (simp add: Healthy_def NSRD_def SRD_def, metis Healthy_def RD1_RD3_commute RD2_RHS_commute RD3_def RD3_right_subsumes_RD2 SRD_def SRD_idem SRD_seqr_closure SRD_srdes_skip)\n\nlemma NSRD_Idempotent: \"Idempotent NSRD\"\n  by (clarsimp simp add: Idempotent_def NSRD_def, metis (no_types, hide_lams) Healthy_def RD1_RD3_commute RD3_def RD3_idem RD3_left_subsumes_RD2 SRD_def SRD_idem SRD_seqr_closure SRD_srdes_skip)\n\nlemma NSRD_Continuous: \"Continuous NSRD\"\n  by (simp add: Continuous_comp NSRD_def RD1_Continuous RD3_Continuous RHS_Continuous)\n\nlemma NSRD_form:\n  \"NSRD(P) = \\<^bold>R\\<^sub>s((\\<not> (\\<not> pre\\<^sub>R(P)) ;; R1 true) \\<turnstile> ((\\<exists> $st\\<acute> \\<bullet> peri\\<^sub>R(P)) \\<diamondop> post\\<^sub>R(P)))\"\nproof -\n  have \"NSRD(P) = RD3(SRD(P))\"\n    by (metis (no_types, lifting) NSRD_def RD1_RD3_commute RD3_left_subsumes_RD2 SRD_def comp_def)\n  also have \"... = RD3(\\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> peri\\<^sub>R(P) \\<diamondop> post\\<^sub>R(P)))\"\n    by (simp add: SRD_as_reactive_tri_design)\n  also have \"... = \\<^bold>R\\<^sub>s(pre\\<^sub>R(P) \\<turnstile> peri\\<^sub>R(P) \\<diamondop> post\\<^sub>R(P)) ;; II\\<^sub>R\"\n    by (simp add: RD3_def)\n  also have \"... = \\<^bold>R\\<^sub>s((\\<not> (\\<not> pre\\<^sub>R(P)) ;; R1 true) \\<turnstile> ((\\<exists> $st\\<acute> \\<bullet> peri\\<^sub>R(P)) \\<diamondop> post\\<^sub>R(P)))\"\n    by (simp add: RHS_tri_design_right_unit_lemma unrest)\n  finally show ?thesis .\nqed\n\nlemma NSRD_healthy_form:\n  assumes \"P is NSRD\"\n  shows \"\\<^bold>R\\<^sub>s((\\<not> (\\<not> pre\\<^sub>R(P)) ;; R1 true) \\<turnstile> ((\\<exists> $st\\<acute> \\<bullet> peri\\<^sub>R(P)) \\<diamondop> post\\<^sub>R(P))) = P\"\n  by (metis Healthy_def NSRD_form assms)\n\nlemma NSRD_intro:\n  assumes \"P is SRD\" \"(\\<not> pre\\<^sub>R(P)) ;; R1(true) = (\\<not> pre\\<^sub>R(P))\" \"$st\\<acute> \\<sharp> peri\\<^sub>R(P)\"\n  shows \"P is NSRD\"\nproof -\n  have \"NSRD(P) = \\<^bold>R\\<^sub>s((\\<not> (\\<not> pre\\<^sub>R(P)) ;; R1 true) \\<turnstile> ((\\<exists> $st\\<acute> \\<bullet> peri\\<^sub>R(P)) \\<diamondop> post\\<^sub>R(P)))\"\n    by (simp add: NSRD_form)\n  also have \"... = \\<^bold>R\\<^sub>s(pre\\<^sub>R P \\<turnstile> peri\\<^sub>R P \\<diamondop> post\\<^sub>R P)\"\n    by (simp add: assms ex_unrest)\n  also have \"... = P\"\n    by (simp add: SRD_reactive_tri_design assms(1))\n  finally show ?thesis\n    using Healthy_def by blast\nqed\n\nlemma SRD_RD3_implies_NSRD:\n  \"\\<lbrakk> P is SRD; P is RD3 \\<rbrakk> \\<Longrightarrow> P is NSRD\"\n  by (metis (no_types, lifting) Healthy_def NSRD_def RHS_idem SRD_healths(4) SRD_reactive_design comp_apply)\n\nlemma NSRD_neg_pre_unit:\n  assumes \"P is NSRD\"\n  shows \"(\\<not> pre\\<^sub>R(P)) ;; R1(true) = (\\<not> pre\\<^sub>R(P))\"\nproof -\n  have \"(\\<not> pre\\<^sub>R(P)) = (\\<not> pre\\<^sub>R(\\<^bold>R\\<^sub>s((\\<not> (\\<not> pre\\<^sub>R(P)) ;; R1 true) \\<turnstile> ((\\<exists> $st\\<acute> \\<bullet> peri\\<^sub>R(P)) \\<diamondop> post\\<^sub>R(P)))))\"\n    by (simp add: NSRD_healthy_form assms)\n  also have \"... = R1 (R2c ((\\<not> pre\\<^sub>R P) ;; R1 true))\"\n    by (simp add: rea_pre_RHS_design usubst unrest)\n  also have \"... = ((\\<not> pre\\<^sub>R P) ;; R1 true)\"\n    by (metis R1_seqr R2_R2c_def R2_def R2c_seq R2s_true calculation)\n  finally show ?thesis ..\nqed\n\nlemma NSRD_st'_unrest_peri:\n  assumes \"P is NSRD\"\n  shows \"$st\\<acute> \\<sharp> peri\\<^sub>R(P)\"\nproof -\n  have \"peri\\<^sub>R(P) = peri\\<^sub>R(\\<^bold>R\\<^sub>s((\\<not> (\\<not> pre\\<^sub>R(P)) ;; R1 true) \\<turnstile> ((\\<exists> $st\\<acute> \\<bullet> peri\\<^sub>R(P)) \\<diamondop> post\\<^sub>R(P))))\"\n    by (simp add: NSRD_healthy_form assms)\n  also have \"... = R1 (R2c (\\<not> (\\<not> pre\\<^sub>R P) ;; R1 true \\<Rightarrow> (\\<exists> $st\\<acute> \\<bullet> peri\\<^sub>R P)))\"\n    by (simp add: rea_peri_RHS_design usubst unrest)\n  also have \"$st\\<acute> \\<sharp> ...\"\n    by (simp add: R1_def R2c_def unrest)\n  finally show ?thesis .\nqed\n\nlemma NSRD_wait'_unrest_pre:\n  assumes \"P is NSRD\"\n  shows \"$wait\\<acute> \\<sharp> pre\\<^sub>R(P)\"\nproof -\n  have \"pre\\<^sub>R(P) = pre\\<^sub>R(\\<^bold>R\\<^sub>s((\\<not> (\\<not> pre\\<^sub>R(P)) ;; R1 true) \\<turnstile> ((\\<exists> $st\\<acute> \\<bullet> peri\\<^sub>R(P)) \\<diamondop> post\\<^sub>R(P))))\"\n    by (simp add: NSRD_healthy_form assms)\n  also have \"... = (\\<not> R1 (R2c ((\\<not> pre\\<^sub>R P) ;; R1 true)))\"\n    by (simp add: rea_pre_RHS_design usubst unrest)\n  also have \"$wait\\<acute> \\<sharp> ...\"\n    by (simp add: R1_def R2c_def unrest)\n  finally show ?thesis .\nqed\n\nlemma NSRD_st'_unrest_pre:\n  assumes \"P is NSRD\"\n  shows \"$st\\<acute> \\<sharp> pre\\<^sub>R(P)\"\nproof -\n  have \"pre\\<^sub>R(P) = pre\\<^sub>R(\\<^bold>R\\<^sub>s((\\<not> (\\<not> pre\\<^sub>R(P)) ;; R1 true) \\<turnstile> ((\\<exists> $st\\<acute> \\<bullet> peri\\<^sub>R(P)) \\<diamondop> post\\<^sub>R(P))))\"\n    by (simp add: NSRD_healthy_form assms)\n  also have \"... = (\\<not> R1 (R2c ((\\<not> pre\\<^sub>R P) ;; R1 true)))\"\n    by (simp add: rea_pre_RHS_design usubst unrest)\n  also have \"$st\\<acute> \\<sharp> ...\"\n    by (simp add: R1_def R2c_def unrest)\n  finally show ?thesis .\nqed\n\nlemma NSRD_iff:\n  \"P is NSRD \\<longleftrightarrow> ((P is SRD) \\<and> (\\<not> pre\\<^sub>R(P)) ;; R1(true) = (\\<not> pre\\<^sub>R(P)) \\<and> ($st\\<acute> \\<sharp> peri\\<^sub>R(P)))\"\n  by (meson NSRD_intro NSRD_is_SRD NSRD_neg_pre_unit NSRD_st'_unrest_peri)\n\nlemma NSRD_composition_wp:\n  assumes \"P is NSRD\" \"Q is SRD\"\n  shows \"P ;; Q =\n         \\<^bold>R\\<^sub>s ((pre\\<^sub>R P \\<and> post\\<^sub>R P wp\\<^sub>R pre\\<^sub>R Q) \\<turnstile> (peri\\<^sub>R P \\<or> (post\\<^sub>R P ;; peri\\<^sub>R Q)) \\<diamondop> (post\\<^sub>R P ;; post\\<^sub>R Q))\"\n  by (simp add: SRD_composition_wp assms NSRD_is_SRD wpR_def NSRD_neg_pre_unit NSRD_st'_unrest_peri ex_unrest)\n\nlemma RHS_tri_normal_design_composition:\n  assumes\n    \"$ok\\<acute> \\<sharp> P\" \"$ok\\<acute> \\<sharp> Q\\<^sub>1\" \"$ok\\<acute> \\<sharp> Q\\<^sub>2\" \"$ok \\<sharp> R\" \"$ok \\<sharp> S\\<^sub>1\" \"$ok \\<sharp> S\\<^sub>2\"\n    \"$wait \\<sharp> R\" \"$wait\\<acute> \\<sharp> Q\\<^sub>2\" \"$wait \\<sharp> S\\<^sub>1\" \"$wait \\<sharp> S\\<^sub>2\"\n    \"P is R2c\" \"Q\\<^sub>1 is R1\" \"Q\\<^sub>1 is R2c\" \"Q\\<^sub>2 is R1\" \"Q\\<^sub>2 is R2c\"\n    \"R is R2c\" \"S\\<^sub>1 is R1\" \"S\\<^sub>1 is R2c\" \"S\\<^sub>2 is R1\" \"S\\<^sub>2 is R2c\"\n    \"R1 (\\<not> P) ;; R1(true) = (\\<not> P)\" \"$st\\<acute> \\<sharp> Q\\<^sub>1\"\n  shows \"\\<^bold>R\\<^sub>s(P \\<turnstile> Q\\<^sub>1 \\<diamondop> Q\\<^sub>2) ;; \\<^bold>R\\<^sub>s(R \\<turnstile> S\\<^sub>1 \\<diamondop> S\\<^sub>2)\n         = \\<^bold>R\\<^sub>s((P \\<and> Q\\<^sub>2 wp\\<^sub>R R) \\<turnstile> (Q\\<^sub>1 \\<sqinter> (Q\\<^sub>2 ;; S\\<^sub>1)) \\<diamondop> (Q\\<^sub>2 ;; S\\<^sub>2))\"\nproof -\n  have \"\\<^bold>R\\<^sub>s(P \\<turnstile> Q\\<^sub>1 \\<diamondop> Q\\<^sub>2) ;; \\<^bold>R\\<^sub>s(R \\<turnstile> S\\<^sub>1 \\<diamondop> S\\<^sub>2) =\n        \\<^bold>R\\<^sub>s ((R1 (\\<not> P) wp\\<^sub>R false \\<and> Q\\<^sub>2 wp\\<^sub>R R) \\<turnstile> ((\\<exists> $st\\<acute> \\<bullet> Q\\<^sub>1) \\<sqinter> (Q\\<^sub>2 ;; S\\<^sub>1)) \\<diamondop> (Q\\<^sub>2 ;; S\\<^sub>2))\"\n    by (simp_all add: RHS_tri_design_composition_wp assms unrest)\n  also have \"... = \\<^bold>R\\<^sub>s((P \\<and> Q\\<^sub>2 wp\\<^sub>R R) \\<turnstile> (Q\\<^sub>1 \\<sqinter> (Q\\<^sub>2 ;; S\\<^sub>1)) \\<diamondop> (Q\\<^sub>2 ;; S\\<^sub>2))\"\n    by (simp add: assms wpR_def ex_unrest)\n  finally show ?thesis .\nqed\n\nlemma NSRD_right_Miracle_tri_lemma:\n  assumes \"P is NSRD\"\n  shows \"P ;; Miracle = \\<^bold>R\\<^sub>s (pre\\<^sub>R P \\<turnstile> peri\\<^sub>R P \\<diamondop> false)\"\n  by (metis (no_types, lifting) Healthy_if NSRD_iff RD3_def RHS_tri_design_RD3_intro \n            RHS_tri_design_right_unit_lemma SRD_right_Miracle_tri_lemma assms ok'_peri_unrest \n            ok'_pre_unrest periR_srdes_skip postR_Miracle wait'_post_unrest)\n\nlemma Miracle_right_zero_law:\n  assumes \"$ok\\<acute> \\<sharp> P\"\n  shows \"\\<^bold>R\\<^sub>s(true \\<turnstile> false \\<diamondop> P) ;; Miracle = Miracle\"\nproof -\n  have \"\\<^bold>R\\<^sub>s(true \\<turnstile> false \\<diamondop> P) is SRD\"\n    by (simp add: RHS_tri_design_is_SRD assms unrest_false unrest_true)\n  hence \"\\<^bold>R\\<^sub>s(true \\<turnstile> false \\<diamondop> P) is NSRD\"\n    by (rule NSRD_intro, (rel_auto)+)\n  thus ?thesis\n    by (simp add: NSRD_right_Miracle_tri_lemma rea_pre_RHS_design rea_peri_RHS_design usubst R2c_false R1_false)\n       (simp add: Miracle_def wait'_cond_idem)\nqed\n\nlemma NSRD_right_Chaos_tri_lemma:\n  assumes \"P is NSRD\"\n  shows \"P ;; Chaos = \\<^bold>R\\<^sub>s ((pre\\<^sub>R P \\<and> \\<not> (post\\<^sub>R P ;; R1 true)) \\<turnstile> peri\\<^sub>R P \\<diamondop> false)\"\n  by (simp add: SRD_right_Chaos_tri_lemma[OF NSRD_is_SRD[OF assms]] \n                NSRD_neg_pre_unit NSRD_st'_unrest_peri assms ex_unrest)\n  \nlemma assigns_rea_id: \"\\<langle>id\\<rangle>\\<^sub>R = II\\<^sub>R\"\n  by (simp add: srdes_skip_def, rel_auto)\n    \nlemma SRD_assigns_rea [closure]: \"\\<langle>\\<sigma>\\<rangle>\\<^sub>R is SRD\"\n  by (simp add: assigns_rea_def RHS_design_is_SRD unrest)\n\nlemma RD3_assigns_rea: \"\\<langle>\\<sigma>\\<rangle>\\<^sub>R is RD3\"\n  by (rule RD3_intro_pre, simp_all add: SRD_assigns_rea preR_assigns_rea periR_assigns_rea unrest)\n\nlemma NSRD_assigns_rea [closure]: \"\\<langle>\\<sigma>\\<rangle>\\<^sub>R is NSRD\"\n  by (simp add: NSRD_iff SRD_assigns_rea periR_assigns_rea preR_assigns_rea unrest_false)\n\nlemma assigns_rea_comp: \"\\<langle>\\<sigma>\\<rangle>\\<^sub>R ;; \\<langle>\\<rho>\\<rangle>\\<^sub>R = \\<langle>\\<rho> \\<circ> \\<sigma>\\<rangle>\\<^sub>R\"\nproof -\n  have a: \"(($tr\\<acute> =\\<^sub>u $tr \\<and> \\<lceil>\\<langle>\\<sigma>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>S \\<and> $\\<Sigma>\\<^sub>S\\<acute> =\\<^sub>u $\\<Sigma>\\<^sub>S) ;; ($tr\\<acute> =\\<^sub>u $tr \\<and> \\<lceil>\\<langle>\\<rho>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>S \\<and> $\\<Sigma>\\<^sub>S\\<acute> =\\<^sub>u $\\<Sigma>\\<^sub>S)) =\n        ($tr\\<acute> =\\<^sub>u $tr \\<and> \\<lceil>\\<langle>\\<rho> \\<circ> \\<sigma>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>S \\<and> $\\<Sigma>\\<^sub>S\\<acute> =\\<^sub>u $\\<Sigma>\\<^sub>S)\"\n    by (rel_auto)\n  have \"\\<langle>\\<sigma>\\<rangle>\\<^sub>R ;; \\<langle>\\<rho>\\<rangle>\\<^sub>R = \\<^bold>R\\<^sub>s (true \\<turnstile> false \\<diamondop> ($tr\\<acute> =\\<^sub>u $tr \\<and> \\<lceil>\\<langle>\\<rho> \\<circ> \\<sigma>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>S \\<and> $\\<Sigma>\\<^sub>S\\<acute> =\\<^sub>u $\\<Sigma>\\<^sub>S))\"\n    by (simp add: NSRD_composition_wp closure preR_assigns_rea periR_assigns_rea postR_assigns_rea wp a)\n  also have \"... = \\<langle>\\<rho> \\<circ> \\<sigma>\\<rangle>\\<^sub>R\"\n    by (simp add: assigns_rea_RHS_tri_des)\n  finally show ?thesis .\nqed\n\ntext {* Stateful reactive designs are left unital *}\n\noverloading\n  srdes_unit == \"utp_unit :: (SRDES, ('s,'t::ordered_cancel_monoid_diff,'\\<alpha>) rsp) uthy \\<Rightarrow> ('s,'t,'\\<alpha>) hrel_rsp\"\nbegin\n  definition srdes_unit :: \"(SRDES, ('s,'t::ordered_cancel_monoid_diff,'\\<alpha>) rsp) uthy \\<Rightarrow> ('s,'t,'\\<alpha>) hrel_rsp\" where\n  \"srdes_unit T = II\\<^sub>R\"\nend\n\ninterpretation srdes_left_unital: utp_theory_left_unital SRDES\n  by (unfold_locales, simp_all add: srdes_hcond_def srdes_unit_def SRD_seqr_closure SRD_srdes_skip SRD_left_unit)\n\ntext {* Stateful reactive designs and assignment *}\n\noverloading\n  srdes_pvar == \"pvar :: (SRDES, ('s,'t::ordered_cancel_monoid_diff,'\\<alpha>) rsp) uthy \\<Rightarrow> 's \\<Longrightarrow> ('s,'t,'\\<alpha>) rsp\"\n  srdes_pvar_assigns == \"pvar_assigns :: (SRDES, ('s,'t::ordered_cancel_monoid_diff,'\\<alpha>) rsp) uthy \\<Rightarrow> 's usubst \\<Rightarrow> ('s,'t,'\\<alpha>) hrel_rsp\"\nbegin\n  definition srdes_pvar ::\n    \"(SRDES, ('s,'t::ordered_cancel_monoid_diff,'\\<alpha>) rsp) uthy \\<Rightarrow> 's \\<Longrightarrow> ('s,'t,'\\<alpha>) rsp\" where\n  [upred_defs]: \"srdes_pvar T = st\"\n  definition srdes_pvar_assigns ::\n    \"(SRDES, ('s,'t::ordered_cancel_monoid_diff,'\\<alpha>) rsp) uthy \\<Rightarrow> 's usubst \\<Rightarrow> ('s,'t,'\\<alpha>) hrel_rsp\" where\n  [upred_defs]: \"srdes_pvar_assigns T \\<sigma> = \\<langle>\\<sigma>\\<rangle>\\<^sub>R\"\nend\n\ninterpretation srdes_local_var: utp_local_var \"UTHY(SRDES, ('s,'t::ordered_cancel_monoid_diff,'\\<alpha>) rsp)\" \"TYPE('s)\"\nproof -\n  interpret vw: vwb_lens \"pvar SRDES :: 's \\<Longrightarrow> ('s,'t,'\\<alpha>) rsp\"\n    by (simp add: srdes_pvar_def)\n  show \"utp_local_var TYPE('s) UTHY(SRDES, ('s,'t,'\\<alpha>) rsp)\"\n  proof\n    show \"\\<And>\\<sigma>::'s \\<Rightarrow> 's. \\<^bold>\\<langle>\\<sigma>\\<^bold>\\<rangle>\\<^bsub>UTHY(SRDES, ('s,'t,'\\<alpha>) rsp)\\<^esub> is \\<H>\\<^bsub>SRDES\\<^esub>\"\n      by (simp add: srdes_pvar_assigns_def srdes_hcond_def SRD_assigns_rea)\n    show \"\\<And>(\\<sigma>::'s \\<Rightarrow> 's) \\<rho>. \\<^bold>\\<langle>\\<sigma>\\<^bold>\\<rangle>\\<^bsub>UTHY(SRDES, ('s,'t,'\\<alpha>) rsp)\\<^esub> ;; \\<^bold>\\<langle>\\<rho>\\<^bold>\\<rangle>\\<^bsub>SRDES\\<^esub> = \\<^bold>\\<langle>\\<rho> \\<circ> \\<sigma>\\<^bold>\\<rangle>\\<^bsub>SRDES\\<^esub>\"\n      by (simp add: srdes_pvar_assigns_def assigns_rea_comp)\n    show \"\\<^bold>\\<langle>id::'s \\<Rightarrow> 's\\<^bold>\\<rangle>\\<^bsub>UTHY(SRDES, ('s,'t,'\\<alpha>) rsp)\\<^esub> = \\<I>\\<I>\\<^bsub>SRDES\\<^esub>\"\n      by (simp add: srdes_pvar_assigns_def srdes_unit_def assigns_rea_id)\n  qed\nqed\n\nsubsection {* Reactive design parallel-by-merge *}\n\ndefinition [upred_defs]: \"nil\\<^sub>r\\<^sub>m = (nil\\<^sub>m \\<triangleleft> $0-ok \\<and> $1-ok \\<triangleright> ($tr\\<^sub>< \\<le>\\<^sub>u $tr\\<acute>))\"\n\ntext {* @{term \"nil\\<^sub>r\\<^sub>m\"} is the parallel system which does nothing if the parallel predicates have both\n  terminated ($0.ok \\wedge 1.ok$), and otherwise guarantees only the merged trace gets longer. *}\n\ndefinition [upred_defs]: \"div\\<^sub>m = ($tr \\<le>\\<^sub>u $0-tr\\<acute> \\<and> $tr \\<le>\\<^sub>u $1-tr\\<acute> \\<and> $\\<Sigma>\\<^sub><\\<acute> =\\<^sub>u $\\<Sigma>)\"\n\ntext {* @{term \"div\\<^sub>m\"} is the parallel system where both sides traces get longer than the initial\n  trace and identifies the before values of the variables. *}\n\ndefinition [upred_defs]: \"wait\\<^sub>m = (((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>0) \\<and> (\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>1) \\<and> $\\<Sigma>\\<^sub><\\<acute> =\\<^sub>u $\\<Sigma>)\\<lbrakk>true,true/$ok,$wait\\<rbrakk>)\"\n\ntext {* @{term \"wait\\<^sub>m\"} is the parallel system where ok and wait are both true and all other variables\n  are identified, except for the state which is hidden in both the left and right.*}\n\ntext {* R3h implicitly depends on RD1, and therefore it requires that both sides be RD1. We also\n  require that both sides are R3c, and that @{term \"wait\\<^sub>m\"} is a quasi-unit, and @{term \"div\\<^sub>m\"} yields\n  divergence. *}\n\nlemma st_U0_alpha: \"\\<lceil>\\<exists> $st \\<bullet> II\\<rceil>\\<^sub>0 = (\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>0)\"\n  by (rel_auto)\n\nlemma st_U1_alpha: \"\\<lceil>\\<exists> $st \\<bullet> II\\<rceil>\\<^sub>1 = (\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>1)\"\n  by (rel_auto)\n\nlemma U0_skip: \"\\<lceil>II\\<rceil>\\<^sub>0 = ($0-\\<Sigma>\\<acute> =\\<^sub>u $\\<Sigma>)\"\n  by (rel_auto)\n\nlemma U1_skip: \"\\<lceil>II\\<rceil>\\<^sub>1 = ($1-\\<Sigma>\\<acute> =\\<^sub>u $\\<Sigma>)\"\n  by (rel_auto)\n\nlemma R3h_par_by_merge:\n  assumes\n    \"P is R1\" \"Q is R1\" \"P is RD1\" \"Q is RD1\" \"P is R3h\" \"Q is R3h\"\n    \"(wait\\<^sub>m ;; M) = ((\\<exists> $st \\<bullet> II)\\<lbrakk>true,true/$ok,$wait\\<rbrakk>)\" \"(div\\<^sub>m ;; M) = R1(true)\"\n  shows \"(P \\<parallel>\\<^bsub>M\\<^esub> Q) is R3h\"\nproof -\n  have \"(P \\<parallel>\\<^bsub>M\\<^esub> Q) = (((P \\<parallel>\\<^bsub>M\\<^esub> Q)\\<lbrakk>true/$ok\\<rbrakk> \\<triangleleft> $ok \\<triangleright> (P \\<parallel>\\<^bsub>M\\<^esub> Q)\\<lbrakk>false/$ok\\<rbrakk>)\\<lbrakk>true/$wait\\<rbrakk> \\<triangleleft> $wait \\<triangleright> (P \\<parallel>\\<^bsub>M\\<^esub> Q))\"\n    by (simp add: cond_idem cond_var_subst_left cond_var_subst_right)\n  also have \"... = (((P \\<parallel>\\<^bsub>M\\<^esub> Q)\\<lbrakk>true,true/$ok,$wait\\<rbrakk> \\<triangleleft> $ok \\<triangleright> (P \\<parallel>\\<^bsub>M\\<^esub> Q)\\<lbrakk>false/$ok\\<rbrakk>)\\<lbrakk>true/$wait\\<rbrakk> \\<triangleleft> $wait \\<triangleright> (P \\<parallel>\\<^bsub>M\\<^esub> Q))\"\n    by (rel_auto)\n  also have \"... = (((P \\<parallel>\\<^bsub>M\\<^esub> Q)\\<lbrakk>true,true/$ok,$wait\\<rbrakk> \\<triangleleft> $ok \\<triangleright> (P \\<parallel>\\<^bsub>M\\<^esub> Q)\\<lbrakk>false/$ok\\<rbrakk>) \\<triangleleft> $wait \\<triangleright> (P \\<parallel>\\<^bsub>M\\<^esub> Q))\"\n    by (simp add: cond_var_subst_left)\n  also have \"... = (((\\<exists> $st \\<bullet> II)\\<lbrakk>true,true/$ok,$wait\\<rbrakk> \\<triangleleft> $ok \\<triangleright> R1(true)) \\<triangleleft> $wait \\<triangleright> (P \\<parallel>\\<^bsub>M\\<^esub> Q))\"\n  proof -\n    have \"(P \\<parallel>\\<^bsub>M\\<^esub> Q)\\<lbrakk>false/$ok\\<rbrakk> = R1(true)\"\n    proof -\n      have \"(P \\<parallel>\\<^bsub>M\\<^esub> Q)\\<lbrakk>false/$ok\\<rbrakk> = ((P \\<triangleleft> $ok \\<triangleright> R1(true)) \\<parallel>\\<^bsub>M\\<^esub> (Q \\<triangleleft> $ok \\<triangleright> R1(true)))\\<lbrakk>false/$ok\\<rbrakk>\"\n        by (metis RD1_alt_def Healthy_if assms)\n      also have \"... = (R1(true) \\<parallel>\\<^bsub>M\\<lbrakk>false/$ok\\<^sub><\\<rbrakk>\\<^esub> R1(true))\"\n        by (rel_auto, metis, metis)\n      also have \"... = (div\\<^sub>m ;; M)\\<lbrakk>false/$ok\\<rbrakk>\"\n        by (rel_auto, metis, metis)\n      also have \"... = (R1(true))\\<lbrakk>false/$ok\\<rbrakk>\"\n        by (simp add: assms(8))\n      also have \"... = (R1(true))\"\n        by (rel_auto)\n      finally show ?thesis\n        by simp\n    qed\n    moreover have \"(P \\<parallel>\\<^bsub>M\\<^esub> Q)\\<lbrakk>true,true/$ok,$wait\\<rbrakk> = (\\<exists> $st \\<bullet> II)\\<lbrakk>true,true/$ok,$wait\\<rbrakk>\"\n    proof -\n      have \"(P \\<parallel>\\<^bsub>M\\<^esub> Q)\\<lbrakk>true,true/$ok,$wait\\<rbrakk> = (P\\<lbrakk>true,true/$ok,$wait\\<rbrakk> \\<parallel>\\<^bsub>M\\<^esub> Q\\<lbrakk>true,true/$ok,$wait\\<rbrakk>)\\<lbrakk>true,true/$ok,$wait\\<rbrakk>\"\n        by (rel_auto)\n      also have \"... = ((((\\<exists> $st \\<bullet> II) \\<triangleleft> $ok \\<triangleright> R1(true)) \\<triangleleft> $wait \\<triangleright> P)\\<lbrakk>true,true/$ok,$wait\\<rbrakk> \\<parallel>\\<^bsub>M\\<^esub> (((\\<exists> $st \\<bullet> II) \\<triangleleft> $ok \\<triangleright> R1(true)) \\<triangleleft> $wait \\<triangleright> Q)\\<lbrakk>true,true/$ok,$wait\\<rbrakk>)\\<lbrakk>true,true/$ok,$wait\\<rbrakk>\"\n        by (metis Healthy_def' R3h_cases assms(5) assms(6))\n      also have \"... = ((\\<exists> $st \\<bullet> II)\\<lbrakk>true,true/$ok,$wait\\<rbrakk> \\<parallel>\\<^bsub>M\\<^esub> (\\<exists> $st \\<bullet> II)\\<lbrakk>true,true/$ok,$wait\\<rbrakk>)\\<lbrakk>true,true/$ok,$wait\\<rbrakk>\"\n        by (subst_tac)\n      also have \"... = ((\\<exists> $st \\<bullet> II) \\<parallel>\\<^bsub>M\\<^esub> (\\<exists> $st \\<bullet> II))\\<lbrakk>true,true/$ok,$wait\\<rbrakk>\"\n        by (simp add: par_by_merge_def usubst)\n      also have \"... = (((\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>0) \\<and> (\\<exists> $st \\<bullet> \\<lceil>II\\<rceil>\\<^sub>1) \\<and> $\\<Sigma>\\<^sub><\\<acute> =\\<^sub>u $\\<Sigma>) ;; M)\\<lbrakk>true,true/$ok,$wait\\<rbrakk>\"\n        by (simp add: par_by_merge_def U0_as_alpha U1_as_alpha alpha st_U0_alpha st_U1_alpha skip\\<^sub>m_def)\n      also have \"... = (wait\\<^sub>m ;; M)\\<lbrakk>true,true/$ok,$wait\\<rbrakk>\"\n        by (rel_auto)\n      also have \"... = (\\<exists> $st \\<bullet> II)\\<lbrakk>true,true/$ok,$wait\\<rbrakk>\"\n        by (simp add: assms usubst)\n      finally show ?thesis .\n    qed\n    ultimately show ?thesis by simp\n  qed\n  also have \"... = (((\\<exists> $st \\<bullet> II) \\<triangleleft> $ok \\<triangleright> R1(true)) \\<triangleleft> $wait \\<triangleright> (P \\<parallel>\\<^bsub>M\\<^esub> Q))\"\n    by (rel_auto)\n  also have \"... = R3h(P \\<parallel>\\<^bsub>M\\<^esub> Q)\"\n    by (simp add: R3h_cases)\n  finally show ?thesis\n    by (simp add: Healthy_def')\nqed\n\nlemma RD1_par_by_merge:\n  assumes \"P is R1\" \"Q is R1\" \"P is RD1\" \"Q is RD1\" \"M is R1m\" \"(div\\<^sub>m ;; M) = R1(true)\"\n  shows \"(P \\<parallel>\\<^bsub>M\\<^esub> Q) is RD1\"\nproof -\n  have \"(P \\<parallel>\\<^bsub>M\\<^esub> Q) = ((P \\<parallel>\\<^bsub>M\\<^esub> Q) \\<triangleleft> $ok \\<triangleright> (P \\<parallel>\\<^bsub>M\\<^esub> Q)\\<lbrakk>false/$ok\\<rbrakk>)\"\n    by (simp add: cond_idem cond_var_subst_right)\n  also have \"... = ((P \\<parallel>\\<^bsub>M\\<^esub> Q) \\<triangleleft> $ok \\<triangleright> R1(true))\"\n  proof -\n    have \"(P \\<parallel>\\<^bsub>M\\<^esub> Q)\\<lbrakk>false/$ok\\<rbrakk> = ((P \\<triangleleft> $ok \\<triangleright> R1(true)) \\<parallel>\\<^bsub>M\\<^esub> (Q \\<triangleleft> $ok \\<triangleright> R1(true)))\\<lbrakk>false/$ok\\<rbrakk>\"\n      by (metis RD1_alt_def Healthy_if assms)\n    also have \"... = (R1(true) \\<parallel>\\<^bsub>M\\<lbrakk>false/$ok\\<^sub><\\<rbrakk>\\<^esub> R1(true))\"\n      by (rel_auto, metis, metis)\n    also have \"... = (div\\<^sub>m ;; M)\\<lbrakk>false/$ok\\<rbrakk>\"\n      by (rel_auto, metis, metis)\n    also have \"... = (R1(true))\\<lbrakk>false/$ok\\<rbrakk>\"\n      by (simp add: assms(6))\n    also have \"... = (R1(true))\"\n      by (rel_auto)\n    finally show ?thesis\n      by simp\n  qed\n  finally show ?thesis\n    by (metis RD1_alt_def Healthy_def R1_par_by_merge assms(5))\nqed\n\nlemma RD2_par_by_merge:\n  assumes \"M is RD2\"\n  shows \"(P \\<parallel>\\<^bsub>M\\<^esub> Q) is RD2\"\nproof -\n  have \"(P \\<parallel>\\<^bsub>M\\<^esub> Q) = ((P \\<parallel>\\<^sub>s Q) ;; M)\"\n    by (simp add: par_by_merge_def)\n  also from assms have \"... = ((P \\<parallel>\\<^sub>s Q) ;; (M ;; J))\"\n    by (simp add: Healthy_def' RD2_def H2_def)\n  also from assms have \"... = (((P \\<parallel>\\<^sub>s Q) ;; M) ;; J)\"\n    by (meson seqr_assoc)\n  also from assms have \"... = RD2(P \\<parallel>\\<^bsub>M\\<^esub> Q)\"\n    by (simp add: RD2_def H2_def par_by_merge_def)\n  finally show ?thesis\n    by (simp add: Healthy_def')\nqed\n\nsubsection {* Simple parallel composition *}\n\ndefinition rea_design_par ::\n  \"('s, 't::ordered_cancel_monoid_diff, '\\<alpha>) hrel_rsp \\<Rightarrow> ('s, 't, '\\<alpha>) hrel_rsp \\<Rightarrow> ('s, 't, '\\<alpha>) hrel_rsp\" (infixr \"\\<parallel>\\<^sub>R\" 85)\nwhere [upred_defs]: \"P \\<parallel>\\<^sub>R Q = \\<^bold>R\\<^sub>s((pre\\<^sub>R(P)  \\<and> pre\\<^sub>R(Q)) \\<turnstile> (cmt\\<^sub>R(P) \\<and> cmt\\<^sub>R(Q)))\"\n\nlemma RHS_design_par:\n  assumes\n    \"$ok\\<acute> \\<sharp> P\\<^sub>1\" \"$ok\\<acute> \\<sharp> P\\<^sub>2\"\n  shows \"\\<^bold>R\\<^sub>s(P\\<^sub>1 \\<turnstile> Q\\<^sub>1) \\<parallel>\\<^sub>R \\<^bold>R\\<^sub>s(P\\<^sub>2 \\<turnstile> Q\\<^sub>2) = \\<^bold>R\\<^sub>s((P\\<^sub>1 \\<and> P\\<^sub>2) \\<turnstile> (Q\\<^sub>1 \\<and> Q\\<^sub>2))\"\nproof -\n  have \"\\<^bold>R\\<^sub>s(P\\<^sub>1 \\<turnstile> Q\\<^sub>1) \\<parallel>\\<^sub>R \\<^bold>R\\<^sub>s(P\\<^sub>2 \\<turnstile> Q\\<^sub>2) =\n        \\<^bold>R\\<^sub>s(P\\<^sub>1\\<lbrakk>true,false/$ok,$wait\\<rbrakk> \\<turnstile> Q\\<^sub>1\\<lbrakk>true,false/$ok,$wait\\<rbrakk>) \\<parallel>\\<^sub>R \\<^bold>R\\<^sub>s(P\\<^sub>2\\<lbrakk>true,false/$ok,$wait\\<rbrakk> \\<turnstile> Q\\<^sub>2\\<lbrakk>true,false/$ok,$wait\\<rbrakk>)\"\n    by (simp add: RHS_design_ok_wait)\n\n  also from assms\n  have \"... =\n        \\<^bold>R\\<^sub>s((\\<not> R1 (R2c (\\<not> P\\<^sub>1)) \\<and> \\<not> R1 (R2c (\\<not> P\\<^sub>2)))\\<lbrakk>true,false/$ok,$wait\\<rbrakk> \\<turnstile>\n           (R1 (R2c (P\\<^sub>1 \\<Rightarrow> Q\\<^sub>1)) \\<and> R1 (R2c (P\\<^sub>2 \\<Rightarrow> Q\\<^sub>2)))\\<lbrakk>true,false/$ok,$wait\\<rbrakk>)\"\n      apply (simp add: rea_design_par_def rea_pre_RHS_design rea_cmt_RHS_design usubst unrest assms)\n      apply (rule cong[of \"\\<^bold>R\\<^sub>s\" \"\\<^bold>R\\<^sub>s\"], simp)\n      using assms apply (rel_auto)\n  done\n  also have \"... =\n        \\<^bold>R\\<^sub>s((\\<not> R2c (\\<not> P\\<^sub>1) \\<and> \\<not> R2c (\\<not> P\\<^sub>2)) \\<turnstile>\n           (R1 (R2s (P\\<^sub>1 \\<Rightarrow> Q\\<^sub>1)) \\<and> R1 (R2s (P\\<^sub>2 \\<Rightarrow> Q\\<^sub>2))))\"\n    by (metis (no_types, lifting) R1_R2s_R2c R1_disj RHS_design_neg_R1_pre RHS_design_ok_wait utp_pred.compl_sup)\n  also have \"... =\n        \\<^bold>R\\<^sub>s((P\\<^sub>1 \\<and> P\\<^sub>2) \\<turnstile> (R1 (R2s (P\\<^sub>1 \\<Rightarrow> Q\\<^sub>1)) \\<and> R1 (R2s (P\\<^sub>2 \\<Rightarrow> Q\\<^sub>2))))\"\n    by (simp add: R2c_R3h_commute R2c_and R2c_design R2c_idem R2c_not RHS_def)\n  also have \"... = \\<^bold>R\\<^sub>s((P\\<^sub>1 \\<and> P\\<^sub>2) \\<turnstile> ((P\\<^sub>1 \\<Rightarrow> Q\\<^sub>1) \\<and> (P\\<^sub>2 \\<Rightarrow> Q\\<^sub>2)))\"\n    by (metis (no_types, lifting) R1_conj R2s_conj RHS_design_export_R1 RHS_design_export_R2s)\n  also have \"... = \\<^bold>R\\<^sub>s((P\\<^sub>1 \\<and> P\\<^sub>2) \\<turnstile> (Q\\<^sub>1 \\<and> Q\\<^sub>2))\"\n    by (rule cong[of \"\\<^bold>R\\<^sub>s\" \"\\<^bold>R\\<^sub>s\"], simp, rel_auto)\n  finally show ?thesis .\nqed\n\nlemma RHS_tri_design_par:\n  assumes \"$ok\\<acute> \\<sharp> P\\<^sub>1\" \"$ok\\<acute> \\<sharp> P\\<^sub>2\"\n  shows \"\\<^bold>R\\<^sub>s(P\\<^sub>1 \\<turnstile> Q\\<^sub>1 \\<diamondop> R\\<^sub>1) \\<parallel>\\<^sub>R \\<^bold>R\\<^sub>s(P\\<^sub>2 \\<turnstile> Q\\<^sub>2 \\<diamondop> R\\<^sub>2) = \\<^bold>R\\<^sub>s((P\\<^sub>1 \\<and> P\\<^sub>2) \\<turnstile> (Q\\<^sub>1 \\<and> Q\\<^sub>2) \\<diamondop> (R\\<^sub>1 \\<and> R\\<^sub>2))\"\n  by (simp add: RHS_design_par assms unrest wait'_cond_conj_exchange)\nend", "meta": {"author": "git-vt", "repo": "orca", "sha": "92bda0f9cfe5cc680b9c405fc38f07a960087a36", "save_path": "github-repos/isabelle/git-vt-orca", "path": "github-repos/isabelle/git-vt-orca/orca-92bda0f9cfe5cc680b9c405fc38f07a960087a36/Archive/Programming-Languages-Semantics/WP11-C-semantics/src/IMP-Lenses/theories/utp_rea_designs.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.5389832206876841, "lm_q1q2_score": 0.2715969707161612}}
{"text": "(*  Title:       Isabelle Collections Library\n    Author:      Peter Lammich <peter dot lammich at uni-muenster.de>\n    Maintainer:  Peter Lammich <peter dot lammich at uni-muenster.de>\n*)\nsection \\<open>\\isaheader{Map Implementation by Associative Lists}\\<close>\ntheory ListMapImpl\nimports \n  \"../spec/MapSpec\" \n  \"../../Lib/Assoc_List\" \n  \"../gen_algo/MapGA\"\nbegin\ntext_raw \\<open>\\label{thy:ListMapImpl}\\<close>\n\n(*@impl Map\n  @type 'a lm\n  @abbrv lm,l\n  Maps implemented by associative lists. If you need efficient \n  @{text \"insert_dj\"} operation, you should use list sets with explicit \n  invariants (lmi).\n*)\n\ntype_synonym ('k,'v) lm = \"('k,'v) assoc_list\"\n\ndefinition [icf_rec_def]: \"lm_basic_ops \\<equiv> \\<lparr>\n  bmap_op_\\<alpha> = Assoc_List.lookup,\n  bmap_op_invar = \\<lambda>_. True,\n  bmap_op_empty = (\\<lambda>_::unit. Assoc_List.empty),\n  bmap_op_lookup = (\\<lambda>k m. Assoc_List.lookup m k),\n  bmap_op_update = Assoc_List.update,\n  bmap_op_update_dj = Assoc_List.update,\n  bmap_op_delete = Assoc_List.delete,\n  bmap_op_list_it = Assoc_List.iteratei\n\\<rparr>\"\n\nsetup Locale_Code.open_block\ninterpretation lm_basic: StdBasicMapDefs lm_basic_ops .\ninterpretation lm_basic: StdBasicMap lm_basic_ops\n  apply unfold_locales\n  apply (simp_all add: icf_rec_unf \n    Assoc_List.lookup_empty' Assoc_List.iteratei_correct map_upd_eq_restrict)\n  done\nsetup Locale_Code.close_block\n\ndefinition [icf_rec_def]: \"lm_ops \\<equiv> lm_basic.dflt_ops\"\nsetup Locale_Code.open_block\ninterpretation lm: StdMapDefs lm_ops .\ninterpretation lm: StdMap lm_ops \n  unfolding lm_ops_def\n  by (rule lm_basic.dflt_ops_impl)\ninterpretation lm: StdMap_no_invar lm_ops \n  by unfold_locales (simp add: icf_rec_unf)\nsetup Locale_Code.close_block\n\nsetup \\<open>ICF_Tools.revert_abbrevs \"lm\"\\<close>\n\nlemma pi_lm[proper_it]: \n  \"proper_it' Assoc_List.iteratei Assoc_List.iteratei\"\n  unfolding Assoc_List.iteratei_def[abs_def]\n  by (intro icf_proper_iteratorI proper_it'I)\n\ninterpretation pi_lm: proper_it_loc Assoc_List.iteratei Assoc_List.iteratei\n  apply unfold_locales\n  apply (rule pi_lm)\n  done\n\nlemma pi_lm'[proper_it]: \n  \"proper_it' lm.iteratei lm.iteratei\"\n  unfolding lm.iteratei_def[abs_def]\n  by (intro icf_proper_iteratorI proper_it'I)\n\ninterpretation pi_lm': proper_it_loc lm.iteratei lm.iteratei\n  apply unfold_locales\n  apply (rule pi_lm')\n  done\n\n\ntext \\<open>Code generator test\\<close>\ndefinition \"test_codegen \\<equiv> (\n  lm.add ,\n  lm.add_dj ,\n  lm.ball ,\n  lm.bex ,\n  lm.delete ,\n  lm.empty ,\n  lm.isEmpty ,\n  lm.isSng ,\n  lm.iterate ,\n  lm.iteratei ,\n  lm.list_it ,\n  lm.lookup ,\n  lm.restrict ,\n  lm.sel ,\n  lm.size ,\n  lm.size_abort ,\n  lm.sng ,\n  lm.to_list ,\n  lm.to_map ,\n  lm.update ,\n  lm.update_dj)\"\n\nexport_code test_codegen checking SML\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Evaluation/Collections/ICF/impl/ListMapImpl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.538983220687684, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.2715969707161611}}
{"text": "section \\<open>Array of Array Lists\\<close>\ntheory Array_of_Array_List\nimports LLVM_DS_Array_List\nbegin\n\n\nsubsection \\<open>Arrays that own their Elements\\<close>\n\n\n  definition \"idxe_map l i \\<equiv> if i<length l then Some (l!i) else None\"\n\n  lemma idxe_map_empty[simp]: \"idxe_map [] = Map.empty\" unfolding idxe_map_def by auto\n  \n  lemma idxe_map_dom[simp]: \"dom (idxe_map l) = {0..<length l}\" unfolding idxe_map_def by (auto split: if_splits)\n  \n  lemma le_idxe_map_updI: \"i<length l \\<Longrightarrow> m \\<subseteq>\\<^sub>m idxe_map l \\<Longrightarrow> m(i\\<mapsto>l!i) \\<subseteq>\\<^sub>m idxe_map l\"\n    unfolding idxe_map_def map_le_def by (auto split: if_splits)\n    \n  lemma le_idxe_map_delD: \"m \\<subseteq>\\<^sub>m idxe_map l \\<Longrightarrow> m(i:=None) \\<subseteq>\\<^sub>m idxe_map (l[i:=x])\"\n    unfolding idxe_map_def map_le_def by (auto split: if_splits)\n    \n  lemma le_idxe_map_delD': \"m \\<subseteq>\\<^sub>m idxe_map l \\<Longrightarrow> m(i:=None) \\<subseteq>\\<^sub>m idxe_map l\"\n    unfolding idxe_map_def map_le_def by (auto split: if_splits)\n    \n  lemma le_idxe_mapD: \"m \\<subseteq>\\<^sub>m idxe_map l \\<Longrightarrow> i<length l \\<Longrightarrow> m i = Some xi \\<Longrightarrow> l!i = xi\"  \n    unfolding idxe_map_def map_le_def \n    apply (clarsimp split: if_splits) by (metis domI option.inject)\n    \n    \n  definition \"nao_assn A R \\<equiv> mk_assn (\\<lambda>xss a. EXS xs. \n       \\<upharpoonleft>narray_assn xs a \n    ** \\<up>(length xs = length xss) \n    ** \\<up>(R \\<subseteq>\\<^sub>m idxe_map xs)\n    ** (\\<Union>*i\\<in>{0..<length xss} - dom R. \\<upharpoonleft>A (xss!i) (xs!i))  \n  )\"\n\n  definition [llvm_inline]: \"nao_new TYPE('a::llvm_rep) n \\<equiv> narray_new TYPE('a) n\"\n\n  \n  lemma nao_repl_init_aux: \n    assumes [fri_rules]: \"\\<box> \\<turnstile> \\<upharpoonleft>A x init\"\n    shows \"\\<box> \\<turnstile> (\\<Union>*i\\<in>{0..<n::nat}. \\<upharpoonleft>A x init)\"  \n    unfolding vcg_tag_defs\n    apply (induction n)\n    subgoal by simp\n    subgoal for n \n    proof (simp add: atLeast0_lessThan_Suc del: replicate_Suc, goal_cases)\n      case 1 note [fri_rules] = 1(1)\n      show ?case by (rule ENTAILSD) vcg\n    qed    \n    done\n  \n  \n  lemma nao_new_init_rl:\n    assumes \"\\<box> \\<turnstile> \\<upharpoonleft>A x init\"\n    shows \"llvm_htriple (\\<upharpoonleft>snat.assn n ni) (nao_new TYPE('a::llvm_rep) ni) (\\<lambda>a. \\<upharpoonleft>(nao_assn A Map.empty) (replicate n x) a)\"\n    unfolding nao_assn_def nao_new_def\n    supply [fri_rules] = nao_repl_init_aux[OF assms]\n    by vcg\n\n  definition [llvm_code, llvm_inline]: \"nao_nth a i \\<equiv> array_nth a i\"  \n  \n  lemma nao_nth_aux: \n    assumes \"i<length xs\" \"i\\<notin>R\"  \n    shows \"sep_set_img ({0..<length xs} - R) P \n        = (P i ** sep_set_img ({0..<length xs} - insert i R) P)\"\n  proof -\n    from assms have 1: \"{0..<length xs} - R = insert i ({0..<length xs} - insert i R)\" by auto\n    show ?thesis\n      by (subst 1) auto\n  qed    \n  \n  lemma ndomIff: \"i\\<notin>dom m \\<longleftrightarrow> m i = None\" by auto\n  \n  lemma nao_nth_rule[vcg_rules]: \"llvm_htriple \n    (\\<upharpoonleft>(nao_assn A R) xs a ** \\<upharpoonleft>snat.assn i ii ** \\<up>(i<length xs \\<and> i\\<notin>dom R)) \n    (nao_nth a ii) \n    (\\<lambda>xi. \\<upharpoonleft>(nao_assn A (R(i\\<mapsto>xi))) xs a ** \\<upharpoonleft>A (xs!i) xi)\"\n    unfolding nao_assn_def nao_nth_def\n    supply fri_red_img[fri_red_rules]\n    supply nao_nth_aux[simp]\n    supply ndomIff[simp] le_idxe_map_updI[simp]\n    by vcg\n    \n    \n  definition [llvm_code, llvm_inline]: \"nao_upd a i x \\<equiv> array_upd a i x\"   \n\n  lemma nao_upd_aux: \n    fixes I xs\n    defines \"I \\<equiv> {0..<length xs}\"\n    assumes \"i\\<in>I\" \"i\\<in>R\" and [simp]: \"length xsi = length xs\"\n    shows \"(\\<Union>*j\\<in>I - (R - {i}). \\<upharpoonleft>A (xs[i := x] ! j) (xsi[i := xi] ! j)) = (\\<upharpoonleft>A x xi ** (\\<Union>*j\\<in>I - R. \\<upharpoonleft>A (xs ! j) (xsi ! j)))\"\n  proof -\n    from assms have 1: \"I - (R - {i}) = insert i (I-R)\" by auto\n    from assms have [simplified,simp]: \"i\\<notin>I-R\" by auto\n    have [simp]: \"i<length xs\" using \\<open>i\\<in>I\\<close> unfolding I_def by auto\n    have [simp]: \"j\\<in>I-R \\<Longrightarrow> i\\<noteq>j\" for j using \\<open>i\\<in>R\\<close> by auto\n    show ?thesis apply (subst 1) by simp\n  qed  \n          \n  term restrict_map\n  \n  lemma nao_upd_rule[vcg_rules]: \"llvm_htriple\n    (\\<upharpoonleft>(nao_assn A R) xs a ** \\<upharpoonleft>A x xi ** \\<upharpoonleft>snat.assn i ii ** \\<up>(i<length xs \\<and> i\\<in>dom R))\n    (nao_upd a ii xi)\n    (\\<lambda>a'. \\<up>(a'=a) ** \\<upharpoonleft>(nao_assn A (R(i:=None))) (xs[i:=x]) a)\"\n    unfolding nao_assn_def nao_upd_def\n    supply nao_upd_aux[simp] le_idxe_map_delD[simp] domI[simp]\n    by vcg\n  \n  definition [llvm_code, llvm_inline]: \"nao_rejoin a i \\<equiv> return ()\"  \n  \n  lemma nao_rejoin_aux: \"i<length xs \\<Longrightarrow> {0..<length xs} - (dom R - {i}) = insert i ({0..<length xs} - dom R)\" by auto\n  \n  lemma nao_rejoin_rule[vcg_rules]: \"llvm_htriple \n    (\\<upharpoonleft>(nao_assn A R) xs a ** \\<upharpoonleft>A x xi ** \\<up>(x=xs!i) ** \\<upharpoonleft>snat.assn i ii ** \\<up>(i<length xs \\<and> R i = Some xi))\n    (nao_rejoin a ii)\n    (\\<lambda>_. \\<upharpoonleft>(nao_assn A (R(i:=None))) xs a)\"\n    unfolding nao_rejoin_def nao_assn_def\n    supply [simp] = le_idxe_map_delD' nao_rejoin_aux domI le_idxe_mapD\n    by vcg\n  \n  \n  definition [llvm_inline]: \"nao_open a \\<equiv> return ()\"  \n    \n  lemma nao_open_rl[vcg_rules]: \"llvm_htriple (\\<upharpoonleft>(nao_assn A R) xss a) (nao_open a) (\\<lambda>_. \n    EXS xs. \n       \\<upharpoonleft>narray_assn xs a \n    ** \\<up>(length xs = length xss) \n    ** \\<up>(R \\<subseteq>\\<^sub>m idxe_map xs)\n    ** (\\<Union>*i\\<in>{0..<length xss} - dom R. \\<upharpoonleft>A (xss!i) (xs!i))  \n  )\"\n    unfolding nao_open_def nao_assn_def by vcg\n  \n  \n      \n  definition [llvm_inline]: \"nao_free free a len \\<equiv> doM {\n    llc_while \n      (\\<lambda>i. ll_icmp_slt i len)\n      (\\<lambda>i. doM {\n        x \\<leftarrow> nao_nth a i;\n        free x;\n        i \\<leftarrow> ll_add i (signed_nat 1);\n        return i\n      })\n      (signed_nat 0);\n      \n    nao_open a;\n    narray_free a\n  }\"\n    \n  definition \"iseg_map n f (i::nat) \\<equiv> if i<n then Some (f i) else None\"\n  lemma iseg_mapZ[simp]: \"iseg_map 0 f = Map.empty\" unfolding iseg_map_def by (intro ext) (auto)\n  \n  lemma iseg_map_upd_end_eq: \"iseg_map n f(n \\<mapsto> x) = iseg_map (Suc n) (f(n:=x))\" \n    apply (intro ext)\n    by (auto simp: iseg_map_def restrict_map_def)\n    \n  lemma iseg_map_dom[simp]: \"dom (iseg_map n f) = {0..<n}\"  \n    by (auto simp: iseg_map_def split: if_splits)\n    \n  lemma nao_free_rl:\n    assumes [vcg_rules]: \"\\<And>x xi. llvm_htriple (\\<upharpoonleft>A x xi) (free xi) (\\<lambda>_. \\<box>)\"\n    shows \"llvm_htriple \n      (\\<upharpoonleft>(nao_assn A Map.empty) xs a ** \\<upharpoonleft>snat.assn l li ** \\<up>(l = length xs)) \n      (nao_free free a li) \n      (\\<lambda>_. \\<box>)\"  \n    unfolding nao_free_def\n    apply (rewrite annotate_llc_while[where \n      I=\"\\<lambda>ii t. EXS f i. \\<upharpoonleft>snat.assn i ii ** \\<upharpoonleft>(nao_assn A (iseg_map i f)) xs a ** \\<up>(i\\<le>length xs) ** \\<up>\\<^sub>!(t = length xs - i)\"\n      and R=\"less_than\"]\n      )\n    supply [simp] = iseg_map_upd_end_eq \n    apply vcg_monadify\n    by vcg\n\n\n  subsection \\<open>Array of Array Lists\\<close>        \n\n  type_synonym ('ll,'a,'l) array_array_list = \"'ll word \\<times> ('a,'l) array_list ptr\"\n\n  definition \"aal_assn \\<equiv> mk_assn (\\<lambda>xs (ni,a). \n    \\<upharpoonleft>snat.assn (length xs) ni ** \\<upharpoonleft>(nao_assn arl_assn Map.empty) xs a)\"\n\n  abbreviation \"aal_assn' TYPE('ll::len2) TYPE('a::llvm_rep) TYPE('l::len2) \\<equiv> aal_assn :: (_,('ll,'a,'l) array_array_list) dr_assn\"\n      \n  \n  definition [llvm_code,llvm_inline]: \"aal_new_raw n \\<equiv> doM {\n    a\\<leftarrow>nao_new TYPE(('a::llvm_rep,'l::len2) array_list) n;\n    return (n,a)\n  }\"\n  \n  (*abbreviation \"aal_new TYPE('ll::len2) TYPE('a::llvm_rep) TYPE('l::len2) n \\<equiv> aal_new_raw n :: ('ll,'a,'l) array_array_list llM\"*)\n\n  lemma snat_z_z_init[fri_rules]: \"\\<box> \\<turnstile> \\<upharpoonleft>\\<^sub>psnat.assn 0 0\"\n    unfolding snat.assn_def \n    by (auto simp: snat_invar_def sep_algebra_simps)  \n    \n  lemma narray_assn_null_init[fri_rules]: \"\\<box> \\<turnstile> \\<upharpoonleft>narray_assn [] null\"  \n    unfolding narray_assn_def\n    by (auto simp: sep_algebra_simps)\n   \n  thm fri_rules  \n    \n  lemma arl_init: \"PRECOND (SOLVE_AUTO (4<LENGTH('l))) \n    \\<Longrightarrow> \\<box> \\<turnstile> \\<upharpoonleft>arl_assn [] (init::('a::llvm_rep,'l::len2) array_list)\"  \n    unfolding arl_assn_def arl_assn'_def vcg_tag_defs\n    apply simp \n    apply (rule ENTAILSD)\n    apply vcg\n    done\n\n  lemma aal_new_rl[vcg_rules]: \"llvm_htriple \n    (\\<upharpoonleft>snat.assn n ni ** \\<up>(4<LENGTH('l::len2))) \n    (aal_new_raw ni)\n    (\\<lambda>p. \\<upharpoonleft>(aal_assn' TYPE('ll::len2) TYPE('a::llvm_rep) TYPE('l::len2)) (replicate n []) p)\n    \"\n    unfolding aal_assn_def aal_new_raw_def\n    supply [vcg_rules] = nao_new_init_rl[OF arl_init]\n    by vcg\n    \n  definition aal_push_back :: \"('l::len2,'a::llvm_rep,'ll::len2) array_array_list \\<Rightarrow> 'li::len word \\<Rightarrow> 'a \\<Rightarrow> ('l,'a,'ll) array_array_list llM\"\n    where [llvm_code, llvm_inline]: \"aal_push_back na i x \\<equiv> doM {\n    let (n,a) = na;\n    aa \\<leftarrow> nao_nth a i;\n    aa \\<leftarrow> arl_push_back aa x;\n    a \\<leftarrow> nao_upd a i aa;\n    return (n,a)\n  }\"  \n\n  lemma aal_push_back_rl[vcg_rules]:\n    fixes a :: \"('ll::len2,'a::llvm_rep,'l::len2) array_array_list\"\n    shows \"llvm_htriple \n      (\\<upharpoonleft>aal_assn xss a ** \\<upharpoonleft>snat.assn i ii ** \\<up>(i<length xss \\<and> length (xss!i) + 1 < max_snat LENGTH('l)))\n      (aal_push_back a ii x)\n      (\\<lambda>a. \\<upharpoonleft>aal_assn (xss[i:=(xss!i) @ [x]]) a)\n    \"\n    unfolding aal_assn_def aal_push_back_def\n    by vcg\n    \n  definition [llvm_code, llvm_inline]: \"aal_pop_back na i \\<equiv> doM {\n    let (n,a) = na;\n    aa \\<leftarrow> nao_nth a i;\n    (r,aa) \\<leftarrow> arl_pop_back aa;\n    a \\<leftarrow> nao_upd a i aa;\n    return (r,(n,a))\n  }\"\n\n  lemma aal_pop_back_rl[vcg_rules]:\n    fixes a :: \"('ll::len2,'a::llvm_rep,'l::len2) array_array_list\"\n    shows \"llvm_htriple \n      (\\<upharpoonleft>aal_assn xss a ** \\<upharpoonleft>snat.assn i ii ** \\<up>(i<length xss \\<and> xss!i \\<noteq> []))\n      (aal_pop_back a ii)\n      (\\<lambda>(x,a). \\<upharpoonleft>aal_assn (xss[i:=butlast (xss!i)]) a ** \\<up>(x = last (xss!i)))\n    \"\n    unfolding aal_assn_def aal_pop_back_def\n    by vcg\n      \n    \n  definition [llvm_code, llvm_inline]: \"aal_idx na i j \\<equiv> doM {\n    let (n,a) = na;\n    aa \\<leftarrow> nao_nth a i;\n    r \\<leftarrow> arl_nth aa j;\n    nao_rejoin a i;\n    return r\n  }\"    \n    \n  lemma aal_idx_rl[vcg_rules]: \"llvm_htriple \n    (\\<upharpoonleft>aal_assn xss a ** \\<upharpoonleft>snat.assn i ii ** \\<upharpoonleft>snat.assn j jj ** \\<up>(i<length xss \\<and> j<length (xss!i)))\n    (aal_idx a ii jj)\n    (\\<lambda>x. \\<upharpoonleft>aal_assn xss a ** \\<up>(x = xss!i!j))\"\n    unfolding aal_assn_def aal_idx_def\n    by vcg\n    \n  definition [llvm_code, llvm_inline]: \"aal_upd na i j x \\<equiv> doM {\n    let (n,a) = na;\n    aa \\<leftarrow> nao_nth a i;\n    aa \\<leftarrow> arl_upd aa j x;\n    a \\<leftarrow> nao_upd a i aa;\n    return (n,a)\n  }\"\n\n  lemma aal_upd_rl[vcg_rules]:\n    fixes a :: \"('ll::len2,'a::llvm_rep,'l::len2) array_array_list\"\n    shows \"llvm_htriple \n      (\\<upharpoonleft>aal_assn xss a ** \\<upharpoonleft>snat.assn i ii ** \\<upharpoonleft>snat.assn j jj ** \\<up>(i<length xss \\<and> j < length (xss!i)))\n      (aal_upd a ii jj x)\n      (\\<lambda>a. \\<upharpoonleft>aal_assn (xss[i:=(xss!i)[j:=x]]) a)\n    \"\n    unfolding aal_assn_def aal_upd_def\n    by vcg\n      \n    \n    \n    \n    \n  definition [llvm_code, llvm_inline]: \"aal_llen na i \\<equiv> doM {\n    let (n,a) = na;\n    aa \\<leftarrow> nao_nth a i;\n    r \\<leftarrow> arl_len aa;\n    nao_rejoin a i;\n    return r\n  }\"    \n    \n  lemma aal_llen_rl[vcg_rules]: \"llvm_htriple \n    (\\<upharpoonleft>aal_assn xss a ** \\<upharpoonleft>snat.assn i ii ** \\<up>(i<length xss))\n    (aal_llen a ii)\n    (\\<lambda>xi. EXS x. \\<upharpoonleft>aal_assn xss a **\\<upharpoonleft>snat.assn x xi ** \\<up>(x = length (xss!i)))\"\n    unfolding aal_assn_def aal_llen_def\n    by vcg\n    \n  definition [llvm_code, llvm_inline]: \"aal_len na \\<equiv> doM {\n    let (n,a) = na;\n    return n\n  }\" \n  \n  lemma aal_len_rl[vcg_rules]: \"llvm_htriple\n    (\\<upharpoonleft>aal_assn xss a)\n    (aal_len a)\n    (\\<lambda>ni. \\<upharpoonleft>aal_assn xss a ** \\<upharpoonleft>snat.assn (length xss) ni)\"\n    unfolding aal_len_def aal_assn_def \n    by vcg\n\n  definition [llvm_code, llvm_inline]: \"aal_take na i l \\<equiv> doM {\n    let (n,a) = na;\n    aa \\<leftarrow> nao_nth a i;\n    aa \\<leftarrow> arl_take l aa;\n    a \\<leftarrow> nao_upd a i aa;\n    return (n,a)\n  }\" \n\n  lemma aal_take_rl[vcg_rules]: \"llvm_htriple\n    (\\<upharpoonleft>aal_assn xss a ** \\<upharpoonleft>snat.assn i ii ** \\<upharpoonleft>snat.assn l li ** \\<up>(i<length xss \\<and> l \\<le> length (xss!i)))\n    (aal_take a ii li)\n    (\\<lambda>a. \\<upharpoonleft>aal_assn (xss[i := take l (xss!i)]) a)\"\n    unfolding aal_assn_def aal_take_def\n    by vcg\n        \n    \n  definition [llvm_code]: \"aal_free na \\<equiv> doM {\n    let (n,a) = na;\n    nao_free arl_free a n\n  }\"\n  \n  \n  lemma aal_free_rl[vcg_rules]: \"llvm_htriple \n    (\\<upharpoonleft>aal_assn xss a) \n    (aal_free a) \n    (\\<lambda>_. \\<box>)\"\n    unfolding aal_assn_def aal_free_def\n    supply [vcg_rules] = nao_free_rl[OF arl_free_rule] \n    by vcg\n    \n    \n    \n  export_llvm\n    \"aal_new_raw :: 64 word \\<Rightarrow> (64,8 word,64) array_array_list llM\"\n    \"aal_push_back :: (64,8 word,64) array_array_list \\<Rightarrow> 64 word \\<Rightarrow> 8 word \\<Rightarrow> (64,8 word,64) array_array_list llM\"  \n    \"aal_pop_back :: (64,8 word,64) array_array_list \\<Rightarrow> 64 word \\<Rightarrow> (8 word \\<times> (64,8 word,64) array_array_list) llM\"  \n    \"aal_idx :: (64,8 word,64) array_array_list \\<Rightarrow> 64 word \\<Rightarrow> 64 word \\<Rightarrow> 8 word llM\"  \n    \"aal_upd :: (64,8 word,64) array_array_list \\<Rightarrow> 64 word \\<Rightarrow> 64 word \\<Rightarrow> 8 word \\<Rightarrow> (64,8 word,64) array_array_list llM\"  \n    \"aal_llen :: (64,8 word,64) array_array_list \\<Rightarrow> 64 word \\<Rightarrow> 64 word llM\"  \n    \"aal_len :: (64,8 word,64) array_array_list \\<Rightarrow> 64 word llM\"  \n    \"aal_free :: (64,8 word,64) array_array_list \\<Rightarrow> unit llM\"  \n    \"aal_take :: (64,8 word,64) array_array_list \\<Rightarrow> 64 word \\<Rightarrow> 64 word \\<Rightarrow> ((64,8 word,64) array_array_list) llM\"  \n    \n\nend\n", "meta": {"author": "lammich", "repo": "isabelle_llvm", "sha": "6be37a9c3cae74a1134dbef2979e312abb5f7f42", "save_path": "github-repos/isabelle/lammich-isabelle_llvm", "path": "github-repos/isabelle/lammich-isabelle_llvm/isabelle_llvm-6be37a9c3cae74a1134dbef2979e312abb5f7f42/thys/ds/Array_of_Array_List.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526660244837, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.2715801847316539}}
{"text": "(*  Title:       BDD\n\n    Author:      Veronika Ortner and Norbert Schirmer, 2004\n    Maintainer:  Norbert Schirmer,  norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  \nShareRepProof.thy\n\nCopyright (C) 2004-2008 Veronika Ortner and Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nheader {*Proof of Procedure ShareRep*}\ntheory ShareRepProof imports ProcedureSpecs \"../Simpl/HeapList\" begin\n\nlemma (in ShareRep_impl) ShareRep_modifies:\n  shows \"\\<forall>\\<sigma>. \\<Gamma>\\<turnstile>{\\<sigma>}  PROC ShareRep (\\<acute>nodeslist, \\<acute>p) \n             {t. t may_only_modify_globals \\<sigma> in [rep]}\"\n  apply (hoare_rule HoarePartial.ProcRec1)\n  apply (vcg spec=modifies)\n  done\n\n\nlemma hd_filter_cons: \n\"\\<And> i. \\<lbrakk> P (xs ! i) p; i < length xs; \\<forall> no \\<in> set (take i xs). \\<not> P no p; \\<forall> a b.  P a b = P b a\\<rbrakk>\n  \\<Longrightarrow> xs ! i = hd (filter (P p) xs)\"\napply (induct xs)\napply simp\napply (case_tac \"P a p\")\napply simp\napply (case_tac i)\napply simp\napply simp\napply (case_tac i)\napply simp\napply auto\ndone\n\nlemma (in ShareRep_impl) ShareRep_spec_total:\nshows \n  \"\\<forall>\\<sigma> ns. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t \n  \\<lbrace>\\<sigma>. List \\<acute>nodeslist \\<acute>next ns \\<and>\n     (\\<forall>no \\<in> set ns. no \\<noteq> Null  \\<and> \n       ((no\\<rightarrow>\\<acute>low = Null) = (no\\<rightarrow>\\<acute>high = Null)) \\<and>\n       (isLeaf_pt \\<acute>p \\<acute>low \\<acute>high \\<longrightarrow> isLeaf_pt no \\<acute>low \\<acute>high) \\<and>\n       no\\<rightarrow>\\<acute>var = \\<acute>p\\<rightarrow>\\<acute>var) \\<and> \n       \\<acute>p \\<in> set ns\\<rbrace> \n  PROC ShareRep (\\<acute>nodeslist, \\<acute>p)\n  \\<lbrace> (\\<^bsup>\\<sigma>\\<^esup>p \\<rightarrow> \\<acute>rep = hd (filter (\\<lambda> sn. repNodes_eq sn \\<^bsup>\\<sigma>\\<^esup>p \\<^bsup>\\<sigma>\\<^esup>low \\<^bsup>\\<sigma>\\<^esup>high \\<^bsup>\\<sigma>\\<^esup>rep) ns)) \\<and>\n    (\\<forall>pt.  pt \\<noteq> \\<^bsup>\\<sigma>\\<^esup>p \\<longrightarrow> pt\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>rep = pt\\<rightarrow>\\<acute>rep) \\<and> \n    (\\<^bsup>\\<sigma>\\<^esup>p\\<rightarrow>\\<acute>rep\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>var = \\<^bsup>\\<sigma>\\<^esup>p \\<rightarrow> \\<^bsup>\\<sigma>\\<^esup>var)\\<rbrace>\"\napply (hoare_rule HoareTotal.ProcNoRec1)\napply (hoare_rule anno=  \n  \"IF (isLeaf_pt \\<acute>p \\<acute>low \\<acute>high) \n   THEN \\<acute>p \\<rightarrow> \\<acute>rep :== \\<acute>nodeslist\n   ELSE\n     WHILE (\\<acute>nodeslist \\<noteq> Null)  \n     INV \\<lbrace>\\<exists>prx sfx. List \\<acute>nodeslist \\<acute>next sfx \\<and> ns=prx@sfx \\<and> \n           \\<not> isLeaf_pt \\<acute>p \\<acute>low \\<acute>high \\<and>\n           (\\<forall>no \\<in> set ns. no \\<noteq> Null \\<and> \n             ((no\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>low = Null) = (no\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>high = Null)) \\<and>\n             (isLeaf_pt \\<^bsup>\\<sigma>\\<^esup>p \\<^bsup>\\<sigma>\\<^esup>low \\<^bsup>\\<sigma>\\<^esup>high \\<longrightarrow> isLeaf_pt no \\<^bsup>\\<sigma>\\<^esup>low \\<^bsup>\\<sigma>\\<^esup>high) \\<and>\n             no\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>var = \\<^bsup>\\<sigma>\\<^esup>p\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>var) \\<and> \n        \\<^bsup>\\<sigma>\\<^esup>p \\<in> set ns \\<and> \n        ((\\<exists>pt \\<in> set prx.  repNodes_eq pt \\<^bsup>\\<sigma>\\<^esup>p \\<^bsup>\\<sigma>\\<^esup>low \\<^bsup>\\<sigma>\\<^esup>high \\<^bsup>\\<sigma>\\<^esup>rep) \n         \\<longrightarrow> \\<acute>rep  \\<^bsup>\\<sigma>\\<^esup>p =  hd (filter (\\<lambda> sn. repNodes_eq sn \\<^bsup>\\<sigma>\\<^esup>p \\<^bsup>\\<sigma>\\<^esup>low \\<^bsup>\\<sigma>\\<^esup>high \\<^bsup>\\<sigma>\\<^esup>rep) prx) \\<and>\n             (\\<forall>pt. pt \\<noteq> \\<^bsup>\\<sigma>\\<^esup>p \\<longrightarrow> pt\\<rightarrow>\\<^bsup>\\<sigma>\\<^esup>rep = pt\\<rightarrow>\\<acute>rep)) \\<and>\n        ((\\<forall>pt \\<in> set prx.  \\<not> repNodes_eq pt \\<^bsup>\\<sigma>\\<^esup>p \\<^bsup>\\<sigma>\\<^esup>low \\<^bsup>\\<sigma>\\<^esup>high \\<^bsup>\\<sigma>\\<^esup>rep) \\<longrightarrow>  \\<^bsup>\\<sigma>\\<^esup>rep = \\<acute>rep) \\<and>\n        (\\<acute>nodeslist \\<noteq> Null \\<longrightarrow> \n           (\\<forall>pt \\<in> set prx. \\<not> repNodes_eq pt \\<^bsup>\\<sigma>\\<^esup>p \\<^bsup>\\<sigma>\\<^esup>low \\<^bsup>\\<sigma>\\<^esup>high \\<^bsup>\\<sigma>\\<^esup>rep)) \\<and>  \n        (\\<acute>p = \\<^bsup>\\<sigma>\\<^esup>p \\<and> \\<acute>high = \\<^bsup>\\<sigma>\\<^esup>high \\<and> \\<acute>low = \\<^bsup>\\<sigma>\\<^esup>low)\\<rbrace>\n     VAR MEASURE (length (list \\<acute>nodeslist \\<acute>next))  \n     DO\n       IF (repNodes_eq \\<acute>nodeslist \\<acute>p \\<acute>low \\<acute>high \\<acute>rep)\n       THEN \\<acute>p\\<rightarrow>\\<acute>rep :== \\<acute>nodeslist;; \\<acute>nodeslist :== Null\n       ELSE \\<acute>nodeslist :== \\<acute>nodeslist\\<rightarrow>\\<acute>next\n       FI\n     OD\n  FI\" in HoareTotal.annotateI)\napply vcg\nusing  [[simp_depth_limit = 2]]\napply   (rule conjI)\napply    clarify\napply    (simp (no_asm_use))\nprefer 2\napply    clarify\napply    (rule_tac x=\"[]\" in exI)\napply    (rule_tac x=ns in exI)\napply    (simp (no_asm_use))\nprefer 2\napply   clarify\napply   (rule conjI)\napply    clarify\napply    (rule conjI)\napply     (clarsimp simp add: List_list) (* solving termination contraint *)\napply    (simp (no_asm_use))\napply    (rule conjI)\napply    assumption\nprefer 2\napply    clarify\napply    (simp (no_asm_use))\napply    (rule conjI)\napply    (clarsimp simp add: List_list) (* solving termination constraint *)\napply    (simp only: List_not_Null simp_thms triv_forall_equality)\napply    clarify\napply    (simp only: triv_forall_equality)\napply    (rename_tac sfx)\napply    (rule_tac x=\"prx@[nodeslist]\" in exI)\napply    (rule_tac x=\"sfx\" in exI)\napply    (rule conjI)\napply     assumption\napply    (rule conjI)\napply     simp\nprefer 4\napply   (elim exE conjE)\napply   (simp (no_asm_use))\napply   hypsubst\nusing  [[simp_depth_limit = 100]]\nproof -\n  (* IF-THEN to postcondition *)\n  fix ns var low high rep \"next\" p nodeslist\n  assume ns: \"List nodeslist next ns\"\n  assume no_prop:  \"\\<forall>no\\<in>set ns.\n           no \\<noteq> Null \\<and>\n           (low no = Null) = (high no = Null) \\<and>\n           (isLeaf_pt p low high \\<longrightarrow> isLeaf_pt no low high) \\<and> var no = var p\"\n  assume p_in_ns: \"p \\<in> set ns\" \n  assume p_Leaf: \"isLeaf_pt p low high\"\n  show \"nodeslist = hd [sn\\<leftarrow>ns . repNodes_eq sn p low high rep] \\<and>\n        var nodeslist = var p\"\n  proof -\n    from p_in_ns no_prop have p_not_Null: \"p\\<noteq>Null\"\n      using [[simp_depth_limit=2]]\n      by auto\n    from p_in_ns have \"ns \\<noteq> []\"\n      by (cases ns) auto\n    with ns obtain ns' where ns': \"ns = nodeslist#ns'\" \n      by (cases \"nodeslist=Null\") auto\n    with no_prop p_Leaf obtain \n      \"isLeaf_pt nodeslist low high\" and\n      var_eq: \"var nodeslist = var p\" and\n      \"nodeslist\\<noteq>Null\"\n      using [[simp_depth_limit=2]]\n      by auto\n    with p_not_Null p_Leaf have \"repNodes_eq nodeslist p low high rep\"\n      by (simp add: repNodes_eq_def isLeaf_pt_def null_comp_def)\n    with ns' var_eq\n    show ?thesis\n      by simp\n  qed\nnext\n  (* From invariant to postcondition *)\n  fix var::\"ref\\<Rightarrow>nat\" and low high rep repa p prx sfx \"next\"\n  assume sfx: \"List Null next sfx\"\n  assume p_in_ns: \"p \\<in> set (prx @ sfx)\"\n  assume no_props: \"\\<forall>no\\<in>set (prx @ sfx).\n           no \\<noteq> Null \\<and>\n           (low no = Null) = (high no = Null) \\<and>\n           (isLeaf_pt p low high \\<longrightarrow> isLeaf_pt no low high) \\<and> var no = var p\"\n  assume match_prx: \"(\\<exists>pt\\<in>set prx. repNodes_eq pt p low high rep) \\<longrightarrow>\n                       repa p = hd [sn\\<leftarrow>prx . repNodes_eq sn p low high rep] \\<and>\n                      (\\<forall>pt. pt \\<noteq> p \\<longrightarrow> rep pt = repa pt)\"\n  show \"repa p = hd [sn\\<leftarrow>prx @ sfx . repNodes_eq sn p low high rep] \\<and>\n          (\\<forall>pt. pt \\<noteq> p \\<longrightarrow> rep pt = repa pt) \\<and> var (repa p) = var p\"\n  proof -\n    from sfx\n    have sfx_Nil: \"sfx=[]\"\n      by simp\n    with p_in_ns have ex_match: \"(\\<exists>pt\\<in>set prx. repNodes_eq pt p low high rep)\"\n      apply -\n      apply (rule_tac x=p in bexI)\n      apply  (simp add: repNodes_eq_def)\n      apply simp\n      done\n    hence not_empty: \"[sn\\<leftarrow>prx . repNodes_eq sn p low high rep] \\<noteq> []\"\n      apply -\n      apply (erule bexE)\n      apply (rule filter_not_empty)\n      apply auto\n      done\n    from ex_match match_prx obtain\n      found: \"repa p = hd [sn\\<leftarrow>prx . repNodes_eq sn p low high rep]\" and\n      unmodif: \"\\<forall>pt. pt \\<noteq> p \\<longrightarrow> rep pt = repa pt\"\n      by blast\n    from hd_filter_in_list [OF not_empty] found\n    have \"repa p \\<in> set prx\"\n      by simp\n    with no_props\n    have \"var (repa p) = var p\"\n      using [[simp_depth_limit=2]]\n      by simp\n    with found unmodif sfx_Nil\n    show ?thesis\n      by simp\n  qed\nnext\n  (* Invariant to invariant; ELSE part *)\n  fix var low high p repa \"next\" nodeslist prx sfx\n  assume nodeslist_not_Null: \"nodeslist \\<noteq> Null\" \n  assume p_no_Leaf: \"\\<not> isLeaf_pt p low high\"\n  assume no_props: \"\\<forall>no\\<in>set prx \\<union> set (nodeslist # sfx).\n           no \\<noteq> Null \\<and> (low no = Null) = (high no = Null) \\<and> var no = var p\"\n  assume p_in_ns: \"p \\<in> set prx \\<or> p \\<in> set (nodeslist # sfx)\"\n  assume match_prx: \"(\\<exists>pt\\<in>set prx. repNodes_eq pt p low high repa) \\<longrightarrow>\n            repa p = hd [sn\\<leftarrow>prx . repNodes_eq sn p low high repa]\"\n  assume nomatch_prx: \"\\<forall>pt\\<in>set prx. \\<not> repNodes_eq pt p low high repa\"\n  assume nomatch_nodeslist: \"\\<not> repNodes_eq nodeslist p low high repa\"\n  assume sfx: \"List (next nodeslist) next sfx\"\n  show \"(\\<forall>no\\<in>set prx \\<union> set (nodeslist # sfx).\n              no \\<noteq> Null \\<and> (low no = Null) = (high no = Null) \\<and> var no = var p) \\<and>\n        ((\\<exists>pt\\<in>set (prx @ [nodeslist]). repNodes_eq pt p low high repa) \\<longrightarrow>\n           repa p = hd [sn\\<leftarrow>prx @ [nodeslist] . repNodes_eq sn p low high repa]) \\<and>\n        (next nodeslist \\<noteq> Null \\<longrightarrow>\n            (\\<forall>pt\\<in>set (prx @ [nodeslist]). \\<not> repNodes_eq pt p low high repa))\"\n  proof -\n    from nomatch_prx nomatch_nodeslist\n    have \"((\\<exists>pt\\<in>set (prx @ [nodeslist]). repNodes_eq pt p low high repa) \\<longrightarrow>\n           repa p = hd [sn\\<leftarrow>prx @ [nodeslist] . repNodes_eq sn p low high repa])\" \n      by auto\n    moreover\n    from nomatch_prx nomatch_nodeslist\n    have \"(next nodeslist \\<noteq> Null \\<longrightarrow>\n            (\\<forall>pt\\<in>set (prx @ [nodeslist]). \\<not> repNodes_eq pt p low high repa))\"\n      by auto\n    ultimately show ?thesis\n      using no_props\n      by (intro conjI)\n  qed\nnext\n  (* Invariant to invariant: THEN part *)\n  fix var low high p repa \"next\" nodeslist prx sfx\n  assume nodeslist_not_Null: \"nodeslist \\<noteq> Null\" \n  assume sfx: \"List nodeslist next sfx\" \n  assume p_not_Leaf: \"\\<not> isLeaf_pt p low high\"\n  assume no_props: \"\\<forall>no\\<in>set prx \\<union> set sfx.\n           no \\<noteq> Null \\<and>\n           (low no = Null) = (high no = Null) \\<and>\n           (isLeaf_pt p low high \\<longrightarrow> isLeaf_pt no low high) \\<and> var no = var p\"\n  assume p_in_ns: \"p \\<in> set prx \\<or> p \\<in> set sfx\"\n  assume match_prx: \"(\\<exists>pt\\<in>set prx. repNodes_eq pt p low high repa) \\<longrightarrow>\n        repa p = hd [sn\\<leftarrow>prx . repNodes_eq sn p low high repa]\"\n  assume nomatch_prx: \"\\<forall>pt\\<in>set prx. \\<not> repNodes_eq pt p low high repa\"\n  assume match: \"repNodes_eq nodeslist p low high repa\"\n  show \"(\\<forall>no\\<in>set prx \\<union> set sfx.\n              no \\<noteq> Null \\<and>\n              (low no = Null) = (high no = Null) \\<and>\n              (isLeaf_pt p low high \\<longrightarrow> isLeaf_pt no low high) \\<and> var no = var p) \\<and>\n        (p \\<in> set prx \\<or> p \\<in> set sfx) \\<and>\n        ((\\<exists>pt\\<in>set prx \\<union> set sfx. repNodes_eq pt p low high repa) \\<longrightarrow>\n           nodeslist =\n           hd ([sn\\<leftarrow>prx . repNodes_eq sn p low high repa] @\n               [sn\\<leftarrow>sfx . repNodes_eq sn p low high repa])) \\<and>\n        ((\\<forall>pt\\<in>set prx \\<union> set sfx. \\<not> repNodes_eq pt p low high repa) \\<longrightarrow>\n           repa = repa(p := nodeslist))\"\n  proof -\n    from nodeslist_not_Null sfx\n    obtain sfx' where sfx': \"sfx=nodeslist#sfx'\"\n      by (cases \"nodeslist=Null\") auto\n    from nomatch_prx match sfx'\n    have hd: \"hd ([sn\\<leftarrow>prx . repNodes_eq sn p low high repa] @\n               [sn\\<leftarrow>sfx . repNodes_eq sn p low high repa]) = nodeslist\"\n      by simp\n    from match sfx'\n    have triv: \"((\\<forall>pt\\<in>set prx \\<union> set sfx. \\<not> repNodes_eq pt p low high repa) \\<longrightarrow>\n           repa = repa(p := nodeslist))\" \n      by simp\n    show ?thesis\n      apply (rule conjI)\n      apply (rule no_props)\n      apply (intro conjI)\n      apply   (rule p_in_ns)\n      apply  (simp add: hd)\n      apply (rule triv)\n      done\n  qed\nqed\n\nend", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/BDD/ShareRepProof.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526514141572, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.2715801777686696}}
{"text": "(*  Title:      JinjaDCI/J/TypeSafe.thy\n\n    Author:     Tobias Nipkow, Susannah Mansky\n    Copyright   2003 Technische Universitaet Muenchen, 2019-20 UIUC\n\n    Based on the Jinja theory J/TypeSafe.thy by Tobias Nipkow\n*)\n\nsection \\<open> Type Safety Proof \\<close>\n\ntheory TypeSafe\nimports Progress BigStep SmallStep JWellForm\nbegin\n\n(* here because it requires well-typing def *)\nlemma red_shext_incr: \"P \\<turnstile> \\<langle>e,(h,l,sh),b\\<rangle> \\<rightarrow> \\<langle>e',(h',l',sh'),b'\\<rangle>\n  \\<Longrightarrow> (\\<And>E T. P,E,h,sh \\<turnstile> e : T \\<Longrightarrow> sh \\<unlhd>\\<^sub>s sh')\"\n  and reds_shext_incr: \"P \\<turnstile> \\<langle>es,(h,l,sh),b\\<rangle> [\\<rightarrow>] \\<langle>es',(h',l',sh'),b'\\<rangle>\n  \\<Longrightarrow> (\\<And>E Ts. P,E,h,sh \\<turnstile> es [:] Ts \\<Longrightarrow> sh \\<unlhd>\\<^sub>s sh')\"\n(*<*)\nproof(induct rule:red_reds_inducts) qed(auto simp: shext_def)\n(*>*)\n\nlemma wf_types_clinit:\nassumes wf:\"wf_prog wf_md P\" and ex: \"class P C = Some a\" and proc: \"sh C = \\<lfloor>(sfs, Processing)\\<rfloor>\"\nshows \"P,E,h,sh \\<turnstile> C\\<bullet>\\<^sub>sclinit([]) : Void\"\nproof -\n  from ex obtain D fs ms where \"a = (D,fs,ms)\" by(cases a)\n  then have sP: \"(C, D, fs, ms) \\<in> set P\" using ex map_of_SomeD[of P C a] by(simp add: class_def)\n  then have \"wf_clinit ms\" using assms by(unfold wf_prog_def wf_cdecl_def, auto)\n  then obtain pns body where sm: \"(clinit, Static, [], Void, pns, body) \\<in> set ms\"\n    by(unfold wf_clinit_def) auto\n  then have \"P \\<turnstile> C sees clinit,Static:[] \\<rightarrow> Void = (pns,body) in C\"\n    using mdecl_visible[OF wf sP sm] by simp\n  then show ?thesis using WTrtSCall proc by simp\nqed\n\nsubsection\\<open>Basic preservation lemmas\\<close>\n\ntext\\<open> First some easy preservation lemmas. \\<close>\n\ntheorem red_preserves_hconf:\n  \"P \\<turnstile> \\<langle>e,(h,l,sh),b\\<rangle> \\<rightarrow> \\<langle>e',(h',l',sh'),b'\\<rangle> \\<Longrightarrow> (\\<And>T E. \\<lbrakk> P,E,h,sh \\<turnstile> e : T; P \\<turnstile> h \\<surd> \\<rbrakk> \\<Longrightarrow> P \\<turnstile> h' \\<surd>)\"\nand reds_preserves_hconf:\n  \"P \\<turnstile> \\<langle>es,(h,l,sh),b\\<rangle> [\\<rightarrow>] \\<langle>es',(h',l',sh'),b'\\<rangle> \\<Longrightarrow> (\\<And>Ts E. \\<lbrakk> P,E,h,sh \\<turnstile> es [:] Ts; P \\<turnstile> h \\<surd> \\<rbrakk> \\<Longrightarrow> P \\<turnstile> h' \\<surd>)\"\n(*<*)\nproof (induct rule:red_reds_inducts)\n  case (RedNew h a C FDTs h' l sh es)\n  have new: \"new_Addr h = Some a\" and fields: \"P \\<turnstile> C has_fields FDTs\"\n   and h': \"h' = h(a\\<mapsto>blank P C)\"\n   and hconf: \"P \\<turnstile> h \\<surd>\" by fact+\n  from new have None: \"h a = None\" by(rule new_Addr_SomeD)\n  moreover have \"P,h \\<turnstile> blank P C \\<surd>\"\n    using fields by(rule oconf_blank)\n  ultimately show \"P \\<turnstile> h' \\<surd>\" using h' by(fast intro: hconf_new[OF hconf])\nnext\n  case (RedFAss C F t D h a fs v l sh b')\n  let ?fs' = \"fs((F,D)\\<mapsto>v)\"\n  have hconf: \"P \\<turnstile> h \\<surd>\" and ha: \"h a = Some(C,fs)\"\n   and wt: \"P,E,h,sh \\<turnstile> addr a\\<bullet>F{D}:=Val v : T\" by fact+\n  from wt ha obtain TF Tv where typeofv: \"typeof\\<^bsub>h\\<^esub> v = Some Tv\"\n    and has: \"P \\<turnstile> C has F,NonStatic:TF in D\"\n    and sub: \"P \\<turnstile> Tv \\<le> TF\" by auto\n  have \"P,h \\<turnstile> (C, ?fs') \\<surd>\"\n  proof (rule oconf_fupd[OF has])\n    show \"P,h \\<turnstile> (C, fs) \\<surd>\" using hconf ha by(simp add:hconf_def)\n    show \"P,h \\<turnstile> v :\\<le> TF\" using sub typeofv by(simp add:conf_def)\n  qed\n  with hconf ha show \"P \\<turnstile> h(a\\<mapsto>(C, ?fs')) \\<surd>\"  by (rule hconf_upd_obj)\nqed(auto elim: WTrt.cases)\n(*>*)\n\n\ntheorem red_preserves_lconf:\n  \"P \\<turnstile> \\<langle>e,(h,l,sh),b\\<rangle> \\<rightarrow> \\<langle>e',(h',l',sh'),b'\\<rangle> \\<Longrightarrow>\n  (\\<And>T E. \\<lbrakk> P,E,h,sh \\<turnstile> e:T; P,h \\<turnstile> l (:\\<le>) E \\<rbrakk> \\<Longrightarrow> P,h' \\<turnstile> l' (:\\<le>) E)\"\nand reds_preserves_lconf:\n  \"P \\<turnstile> \\<langle>es,(h,l,sh),b\\<rangle> [\\<rightarrow>] \\<langle>es',(h',l',sh'),b'\\<rangle> \\<Longrightarrow>\n  (\\<And>Ts E. \\<lbrakk> P,E,h,sh \\<turnstile> es[:]Ts; P,h \\<turnstile> l (:\\<le>) E \\<rbrakk> \\<Longrightarrow> P,h' \\<turnstile> l' (:\\<le>) E)\"\n(*<*)\nproof(induct rule:red_reds_inducts)\n  case RedNew thus ?case\n    by(fast intro:lconf_hext red_hext_incr[OF red_reds.RedNew])\nnext\n  case RedLAss thus ?case by(fastforce elim: lconf_upd simp:conf_def)\nnext\n  case RedFAss thus ?case\n    by(fast intro:lconf_hext red_hext_incr[OF red_reds.RedFAss])\nnext\n  case (InitBlockRed e h l V v sh b e' h' l' sh' b' v' T T')\n  have red: \"P \\<turnstile> \\<langle>e, (h, l(V\\<mapsto>v),sh),b\\<rangle> \\<rightarrow> \\<langle>e',(h', l',sh'),b'\\<rangle>\"\n   and IH: \"\\<And>T E . \\<lbrakk> P,E,h,sh \\<turnstile> e:T; P,h \\<turnstile> l(V\\<mapsto>v) (:\\<le>) E \\<rbrakk>\n                     \\<Longrightarrow> P,h' \\<turnstile> l' (:\\<le>) E\"\n   and l'V: \"l' V = Some v'\" and lconf: \"P,h \\<turnstile> l (:\\<le>) E\"\n   and wt: \"P,E,h,sh \\<turnstile> {V:T := Val v; e} : T'\" by fact+\n  from lconf_hext[OF lconf red_hext_incr[OF red]]\n  have \"P,h' \\<turnstile> l (:\\<le>) E\" .\n  moreover from IH lconf wt have \"P,h' \\<turnstile> l' (:\\<le>) E(V\\<mapsto>T)\"\n    by(auto simp del: fun_upd_apply simp: fun_upd_same lconf_upd2 conf_def)\n  ultimately show \"P,h' \\<turnstile> l'(V := l V) (:\\<le>) E\"\n    by (fastforce simp:lconf_def split:if_split_asm)\nnext\n  case (BlockRedNone e h l V sh b e' h' l' sh' b' T T')\n  have red: \"P \\<turnstile> \\<langle>e,(h, l(V := None),sh),b\\<rangle> \\<rightarrow> \\<langle>e',(h', l',sh'),b'\\<rangle>\"\n   and IH: \"\\<And>E T. \\<lbrakk> P,E,h,sh \\<turnstile> e : T; P,h \\<turnstile> l(V:=None) (:\\<le>) E \\<rbrakk>\n                   \\<Longrightarrow> P,h' \\<turnstile> l' (:\\<le>) E\"\n   and lconf: \"P,h \\<turnstile> l (:\\<le>) E\" and wt: \"P,E,h,sh \\<turnstile> {V:T; e} : T'\" by fact+\n  from lconf_hext[OF lconf red_hext_incr[OF red]]\n  have \"P,h' \\<turnstile> l (:\\<le>) E\" .\n  moreover have \"P,h' \\<turnstile> l' (:\\<le>) E(V\\<mapsto>T)\"\n    by(rule IH, insert lconf wt, auto simp:lconf_def)\n  ultimately show \"P,h' \\<turnstile> l'(V := l V) (:\\<le>) E\"\n    by (fastforce simp:lconf_def split:if_split_asm)\nnext\n  case (BlockRedSome e h l V sh b e' h' l' sh' b' v T T')\n  have red: \"P \\<turnstile> \\<langle>e,(h, l(V := None),sh),b\\<rangle> \\<rightarrow> \\<langle>e',(h', l',sh'),b'\\<rangle>\"\n   and IH: \"\\<And>E T. \\<lbrakk>P,E,h,sh \\<turnstile> e : T; P,h \\<turnstile> l(V:=None) (:\\<le>) E\\<rbrakk>\n                   \\<Longrightarrow> P,h' \\<turnstile> l' (:\\<le>) E\"\n   and lconf: \"P,h \\<turnstile> l (:\\<le>) E\" and wt: \"P,E,h,sh \\<turnstile> {V:T; e} : T'\" by fact+\n  from lconf_hext[OF lconf red_hext_incr[OF red]]\n  have \"P,h' \\<turnstile> l (:\\<le>) E\" .\n  moreover have \"P,h' \\<turnstile> l' (:\\<le>) E(V\\<mapsto>T)\"\n    by(rule IH, insert lconf wt, auto simp:lconf_def)\n  ultimately show \"P,h' \\<turnstile> l'(V := l V) (:\\<le>) E\"\n    by (fastforce simp:lconf_def split:if_split_asm)\nqed(auto elim: WTrt.cases)\n(*>*)\n\n\ntheorem red_preserves_shconf:\n  \"P \\<turnstile> \\<langle>e,(h,l,sh),b\\<rangle> \\<rightarrow> \\<langle>e',(h',l',sh'),b'\\<rangle> \\<Longrightarrow> (\\<And>T E. \\<lbrakk> P,E,h,sh \\<turnstile> e : T; P,h \\<turnstile>\\<^sub>s sh \\<surd> \\<rbrakk> \\<Longrightarrow> P,h' \\<turnstile>\\<^sub>s sh' \\<surd>)\"\nand reds_preserves_shconf:\n  \"P \\<turnstile> \\<langle>es,(h,l,sh),b\\<rangle> [\\<rightarrow>] \\<langle>es',(h',l',sh'),b'\\<rangle> \\<Longrightarrow> (\\<And>Ts E. \\<lbrakk> P,E,h,sh \\<turnstile> es [:] Ts; P,h \\<turnstile>\\<^sub>s sh \\<surd> \\<rbrakk> \\<Longrightarrow> P,h' \\<turnstile>\\<^sub>s sh' \\<surd>)\"\n(*<*)\nproof (induct rule:red_reds_inducts)\n  case (RedNew h a C FDTs h' l sh es)\n  have new: \"new_Addr h = Some a\"\n   and h': \"h' = h(a\\<mapsto>blank P C)\"\n   and shconf: \"P,h \\<turnstile>\\<^sub>s sh \\<surd>\" by fact+\n  from new have None: \"h a = None\" by(rule new_Addr_SomeD)\n  then show \"P,h' \\<turnstile>\\<^sub>s sh \\<surd>\" using h' by(fast intro: shconf_hnew[OF shconf])\nnext\n  case (RedFAss C F t D h a fs v l sh b)\n  let ?fs' = \"fs((F,D)\\<mapsto>v)\"\n  have shconf: \"P,h \\<turnstile>\\<^sub>s sh \\<surd>\" and ha: \"h a = Some(C,fs)\" by fact+\n  then show \"P,h(a\\<mapsto>(C, ?fs')) \\<turnstile>\\<^sub>s sh \\<surd>\" by (rule shconf_hupd_obj)\nnext\n  case (RedSFAss C F t D sh sfs i sfs' v sh' h l)\n  let ?sfs' = \"sfs(F\\<mapsto>v)\"\n  have shconf: \"P,h \\<turnstile>\\<^sub>s sh \\<surd>\" and shD: \"sh D = \\<lfloor>(sfs, i)\\<rfloor>\"\n    and wt: \"P,E,h,sh \\<turnstile> C\\<bullet>\\<^sub>sF{D} := Val v : T\" by fact+\n  from wt obtain TF Tv where typeofv: \"typeof\\<^bsub>h\\<^esub> v = Some Tv\"\n    and has: \"P \\<turnstile> C has F,Static:TF in D\"\n    and sub: \"P \\<turnstile> Tv \\<le> TF\" by (auto elim: WTrt.cases)\n  have has': \"P \\<turnstile> D has F,Static:TF in D\" using has by(rule has_field_idemp)\n  have \"P,h,D \\<turnstile>\\<^sub>s ?sfs' \\<surd>\"\n  proof (rule soconf_fupd[OF has'])\n    show \"P,h,D \\<turnstile>\\<^sub>s sfs \\<surd>\" using shconf shD by(simp add:shconf_def)\n    show \"P,h \\<turnstile> v :\\<le> TF\" using sub typeofv by(simp add:conf_def)\n  qed\n  with shconf have \"P,h \\<turnstile>\\<^sub>s sh(D\\<mapsto>(?sfs',i)) \\<surd>\" by (rule shconf_upd_obj)\n  then show ?case using RedSFAss.hyps(3) RedSFAss.hyps(4) by blast\nnext\n  case (InitNoneRed sh C C' Cs e h l)\n  let ?sfs' = \"sblank P C\"\n  have \"P,h \\<turnstile>\\<^sub>s sh(C \\<mapsto> (?sfs', Prepared)) \\<surd>\"\n  proof(rule shconf_upd_obj)\n    show \"P,h \\<turnstile>\\<^sub>s sh \\<surd>\" using InitNoneRed by simp\n    show \"P,h,C \\<turnstile>\\<^sub>s sblank P C \\<surd>\" by (metis has_field_def soconf_def soconf_sblank)\n  qed\n  then show ?case by blast\nnext\n  case (InitObjectRed sh C sfs sh' C' Cs e h l)\n  have sh': \"sh' = sh(C \\<mapsto> (sfs, Processing))\" by fact\n  have \"P,h \\<turnstile>\\<^sub>s sh(C \\<mapsto> (sfs, Processing)) \\<surd>\"\n  proof(rule shconf_upd_obj)\n    show \"P,h \\<turnstile>\\<^sub>s sh \\<surd>\" using InitObjectRed by simp\n    moreover have \"sh C = \\<lfloor>(sfs, Prepared)\\<rfloor>\" using InitObjectRed by simp\n    ultimately show \"P,h,C \\<turnstile>\\<^sub>s sfs \\<surd>\" using shconfD by blast\n  qed\n  then show ?case using sh' by blast\nnext\n  case (InitNonObjectSuperRed sh C sfs D a b sh' C' Cs e h l)\n  have sh': \"sh' = sh(C \\<mapsto> (sfs, Processing))\" by fact\n  have \"P,h \\<turnstile>\\<^sub>s sh(C \\<mapsto> (sfs, Processing)) \\<surd>\"\n  proof(rule shconf_upd_obj)\n    show \"P,h \\<turnstile>\\<^sub>s sh \\<surd>\" using InitNonObjectSuperRed by simp\n    moreover have \"sh C = \\<lfloor>(sfs, Prepared)\\<rfloor>\" using InitNonObjectSuperRed by simp\n    ultimately show \"P,h,C \\<turnstile>\\<^sub>s sfs \\<surd>\" using shconfD by blast\n  qed\n  then show ?case using sh' by blast\nnext\n  case (RedRInit sh C sfs i sh' C' Cs e v h l)\n  have sh': \"sh' = sh(C \\<mapsto> (sfs, Done))\" by fact\n  have \"P,h \\<turnstile>\\<^sub>s sh(C \\<mapsto> (sfs, Done)) \\<surd>\"\n  proof(rule shconf_upd_obj)\n    show \"P,h \\<turnstile>\\<^sub>s sh \\<surd>\" using RedRInit by simp\n    moreover have \"sh C = \\<lfloor>(sfs, i)\\<rfloor>\" using RedRInit by simp\n    ultimately show \"P,h,C \\<turnstile>\\<^sub>s sfs \\<surd>\" using shconfD by blast\n  qed\n  then show ?case using sh' by blast\nnext\n  case (RInitInitThrow sh C sfs i sh' a D Cs e h l)\n  have sh': \"sh' = sh(C \\<mapsto> (sfs, Error))\" by fact\n  have \"P,h \\<turnstile>\\<^sub>s sh(C \\<mapsto> (sfs, Error)) \\<surd>\"\n  proof(rule shconf_upd_obj)\n    show \"P,h \\<turnstile>\\<^sub>s sh \\<surd>\" using RInitInitThrow by simp\n    moreover have \"sh C = \\<lfloor>(sfs, i)\\<rfloor>\" using RInitInitThrow by simp\n    ultimately show \"P,h,C \\<turnstile>\\<^sub>s sfs \\<surd>\" using shconfD by blast\n  qed\n  then show ?case using sh' by blast\nnext\n  case (RInitThrow sh C sfs i sh' a e' h l)\n  have sh': \"sh' = sh(C \\<mapsto> (sfs, Error))\" by fact\n  have \"P,h \\<turnstile>\\<^sub>s sh(C \\<mapsto> (sfs, Error)) \\<surd>\"\n  proof(rule shconf_upd_obj)\n    show \"P,h \\<turnstile>\\<^sub>s sh \\<surd>\" using RInitThrow by simp\n    moreover have \"sh C = \\<lfloor>(sfs, i)\\<rfloor>\" using RInitThrow by simp\n    ultimately show \"P,h,C \\<turnstile>\\<^sub>s sfs \\<surd>\" using shconfD by blast\n  qed\n  then show ?case using sh' by blast\nqed(auto elim: WTrt.cases)\n(*>*)\n\n\n\n\nlemma Seq_bconf_preserve_aux:\nassumes \"P \\<turnstile> \\<langle>e,(h, l, sh),b\\<rangle> \\<rightarrow> \\<langle>e',(h', l', sh'),b'\\<rangle>\" and \"P,sh \\<turnstile>\\<^sub>b (e;; e\\<^sub>2,b) \\<surd>\"\n  and \"P,sh \\<turnstile>\\<^sub>b (e::expr,b) \\<surd> \\<longrightarrow> P,sh' \\<turnstile>\\<^sub>b (e'::expr,b') \\<surd>\"\nshows \"P,sh' \\<turnstile>\\<^sub>b (e';;e\\<^sub>2,b') \\<surd>\"\nproof(cases \"val_of e\")\n  case None show ?thesis\n  proof(cases \"lass_val_of e\")\n    case lNone: None show ?thesis\n    proof(cases \"lass_val_of e'\")\n      case lNone': None\n      then show ?thesis using None assms lNone\n        by(auto dest: val_of_spec simp: bconf_def option.distinct(1))\n    next\n      case (Some a)\n      then show ?thesis using None assms lNone by(auto dest: lass_val_of_spec simp: bconf_def)\n    qed\n  next\n    case (Some a)\n    then show ?thesis using None assms by(auto dest: lass_val_of_spec)\n  qed\nnext\n  case (Some a)\n  then show ?thesis using assms by(auto dest: val_of_spec)\nqed\n\ntheorem red_preserves_bconf:\n  \"P \\<turnstile> \\<langle>e,(h,l,sh),b\\<rangle> \\<rightarrow> \\<langle>e',(h',l',sh'),b'\\<rangle> \\<Longrightarrow> iconf sh e \\<Longrightarrow> P,sh \\<turnstile>\\<^sub>b (e,b) \\<surd> \\<Longrightarrow> P,sh' \\<turnstile>\\<^sub>b (e',b') \\<surd>\"\nand reds_preserves_bconf:\n  \"P \\<turnstile> \\<langle>es,(h,l,sh),b\\<rangle> [\\<rightarrow>] \\<langle>es',(h',l',sh'),b'\\<rangle> \\<Longrightarrow> iconfs sh es \\<Longrightarrow> P,sh \\<turnstile>\\<^sub>b (es,b) \\<surd> \\<Longrightarrow> P,sh' \\<turnstile>\\<^sub>b (es',b') \\<surd>\"\n(*<*)\nproof (induct rule:red_reds_inducts)\n  case (CastRed e a a b b e' a a b b' C) then show ?case\n  proof(cases b') qed(simp, simp add: bconf_def)\nnext\n  case (BinOpRed1 e h l sh b e' h' l' sh' b' bop e\\<^sub>2) show ?case\n  proof(cases b')\n    case True with BinOpRed1 val_of_spec show ?thesis\n    proof(cases \"val_of e\") qed(simp,fast)\n  next\n    case False then show ?thesis by (simp add: bconf_def)\n  qed\nnext\ncase (BinOpRed2 e a a b b e' a a b b' v\\<^sub>1 bop) then show ?case\n  proof(cases b') qed(simp, simp add: bconf_def)\nnext\n  case (LAssRed e a a b b e' a a b b' V) then show ?case\n  proof(cases b') qed(simp, simp add: bconf_def)\nnext\n  case (FAccRed e a a b b e' a a b b' F D) then show ?case\n  proof(cases b') qed(simp, simp add: bconf_def)\nnext\n  case (RedSFAccNonStatic C F t D h l sh b) then show ?case\n    using has_field_fun[of P C F NonStatic] by (auto simp: bconf_def)\nnext\n  case (FAssRed1 e h l sh b e' h' l' sh' b' F D e\\<^sub>2) show ?case\n  proof(cases b')\n    case True with FAssRed1 val_of_spec show ?thesis\n    proof(cases \"val_of e'\")qed((simp,fast)+)\n  next\n    case False then show ?thesis by(simp add: bconf_def)\n  qed\nnext\n  case (FAssRed2 e a a b b e' a a b b' v F D) then show ?case\n  proof(cases b') qed(simp, simp add: bconf_def)\nnext\n  case (SFAssRed e h l sh b e' h' l' sh' b' C F D) then show ?case\n  proof(cases b') qed(fastforce simp: bconf_def val_no_step)+\nnext\n  case (RedSFAssNonStatic C F t D v a a b b) then show ?case\n    using has_field_fun[of P C F NonStatic] by (auto simp: bconf_def)\nnext\n  case (CallObj e h l sh b e' h' l' sh' b' M es) show ?case\n  proof(cases b')\n    case True with CallObj val_of_spec show ?thesis\n    proof(cases \"val_of e'\")qed((simp,fast)+)\n  next\n    case False then show ?thesis by(simp add: bconf_def)\n  qed\nnext\n  case (CallParams es a a b b es' a a b b' v M) then show ?case\n  proof(cases b') qed(simp, simp add: bconf_def)\nnext\n  case (SCallParams es h l sh b es' h' l' sh' b' C M) show ?case\n  proof(cases b')\n    case b': True show ?thesis\n    proof(cases \"map_vals_of es'\")\n      case None\n      then show ?thesis using SCallParams b' vals_no_step\n      proof(cases \"map_vals_of es\")qed(clarsimp,fast)\n    next\n      case f: Some\n      then show ?thesis using SCallParams b' vals_no_step\n      proof(cases \"map_vals_of es\")qed(clarsimp,fast)\n    qed\n  next\n    case False then show ?thesis by(simp add: bconf_def)\n  qed\nnext\n  case (SCallInitDoneRed C M Ts T pns body D sh sfs vs h l)\n    then show ?case by(auto simp: bconf_def initPD_def) (rule_tac x=D in exI, auto)+\nnext\n  case (RedSCallNonStatic C M Ts T a b D vs h l sh b) then show ?case\n    using sees_method_fun[of P C M NonStatic] by (auto simp: bconf_def)\nnext\n  case (BlockRedNone e h l V sh b e' h' l' sh' b' T) show ?case\n  proof(cases \"assigned V e'\")\n    case True\n    then obtain v e2 where \"e' = V := Val v;;e2\" by(clarsimp simp: assigned_def)\n    then show ?thesis using BlockRedNone by(clarsimp simp: bconf_def)\n  next\n    case False then show ?thesis using BlockRedNone by simp\n  qed\nnext\n  case (BlockRedSome e h l V sh b e' h' l' sh' b' v T) then show ?case\n  proof(cases b') qed(simp, simp add: bconf_def)\nnext\n  case (InitBlockRed e h l V v sh b e' h' l' sh' b' v' T) show ?case\n  proof(cases b')\n    case True\n    then show ?thesis using InitBlockRed by (simp add: assigned_def)\n  next\n    case False then show ?thesis by(simp add: bconf_def)\n  qed\nnext\n  case (RedBlock V T u)\n  then have \"\\<not>assigned V (Val u)\" by(clarsimp simp: assigned_def)\n  then show ?case using RedBlock by(simp add: bconf_def)\nnext\n  case (SeqRed e h l sh b e' h' l' sh' b' e\\<^sub>2)\n  have \"iconf sh e\"\n  proof(cases \"lass_val_of e\")\n    case (Some a) show ?thesis by(rule lass_val_of_iconf[OF Some])\n  next\n    case None then show ?thesis using SeqRed by(auto dest: val_of_spec)\n  qed\n  then show ?case using SeqRed Seq_bconf_preserve_aux by simp\nnext\n  case (CondRed e a a b b e' a a b b' e\\<^sub>1 e\\<^sub>2) then show ?case\n  proof(cases b') qed(simp, simp add: bconf_def)\nnext\n  case (ThrowRed e a a b b e' a a b b') then show ?case\n  proof(cases b') qed(simp, simp add: bconf_def)\nnext\n  case (TryRed e a a b b e' a a b b' C V e\\<^sub>2) then show ?case\n  proof(cases b') qed(simp, simp add: bconf_def)\nnext\n  case (ListRed1 e h l sh b e' h' l' sh' b' es)\n  with val_of_spec show ?case\n  proof(cases b') qed((clarsimp,fast),simp add: bconfs_def)\nnext\n  case (RedInit C b' e X Y b b'')\n  then show ?case\n   by(auto simp: bconf_def icheck_ss_exp icheck_init_class icheck_curr_init)\nnext\n  case (RInitRed e a a b b e' a a b b' C Cs e\\<^sub>0) then show ?case\n  proof(cases b') qed(simp, simp add: bconf_def)\nnext\n  case (BlockThrow V T a)\n  then have \"\\<not>assigned V (Throw a)\" by(simp add: assigned_def)\n  then show ?case using BlockThrow by simp\nqed(simp_all, auto simp: bconf_def initPD_def)\n(*>*)\n\ntext\\<open> Preservation of definite assignment more complex and requires a\nfew lemmas first. \\<close>\n\n\n\n\nlemma red_lA_incr: \"P \\<turnstile> \\<langle>e,(h,l,sh),b\\<rangle> \\<rightarrow> \\<langle>e',(h',l',sh'),b'\\<rangle>\n   \\<Longrightarrow> \\<lfloor>dom l\\<rfloor> \\<squnion> \\<A> e \\<sqsubseteq>  \\<lfloor>dom l'\\<rfloor> \\<squnion> \\<A> e'\"\nand reds_lA_incr: \"P \\<turnstile> \\<langle>es,(h,l,sh),b\\<rangle> [\\<rightarrow>] \\<langle>es',(h',l',sh'),b'\\<rangle>\n   \\<Longrightarrow> \\<lfloor>dom l\\<rfloor> \\<squnion> \\<A>s es \\<sqsubseteq>  \\<lfloor>dom l'\\<rfloor> \\<squnion> \\<A>s es'\"\n(*<*)\nproof(induct rule:red_reds_inducts)\n  case TryRed then show ?case\n    by(simp del:fun_upd_apply add:hyperset_defs)\n      (blast dest:red_lcl_incr)+\nnext\n  case BinOpRed1 then show ?case\n    by(auto simp del:fun_upd_apply simp:hyperset_defs)\nnext\n  case BinOpRed2 then show ?case\n    by(auto simp del:fun_upd_apply simp:hyperset_defs)\nnext\n  case LAssRed then show ?case\n    by(auto simp del:fun_upd_apply simp:hyperset_defs)\nnext\n  case FAssRed1 then show ?case\n    by(auto simp del:fun_upd_apply simp:hyperset_defs)\nnext\n  case FAssRed2 then show ?case\n    by(auto simp del:fun_upd_apply simp:hyperset_defs)\nnext\n  case CallObj then show ?case\n    by(auto simp del:fun_upd_apply simp:hyperset_defs)\nnext\n  case CallParams then show ?case\n    by(auto simp del:fun_upd_apply simp:hyperset_defs)\nnext\n  case BlockRedNone then show ?case\n    by(auto simp del:fun_upd_apply simp:hyperset_defs)\nnext\n  case BlockRedSome then show ?case\n    by(auto simp del:fun_upd_apply simp:hyperset_defs)\nnext\n  case InitBlockRed then show ?case\n    by(auto simp del:fun_upd_apply simp:hyperset_defs)\nnext\n  case SeqRed then show ?case\n    by(auto simp del:fun_upd_apply simp:hyperset_defs)\nnext\n  case CondRed then show ?case\n    by(auto simp del:fun_upd_apply simp:hyperset_defs)\nnext\n  case RedCondT then show ?case\n    by(auto simp del:fun_upd_apply simp:hyperset_defs)\nnext\n  case RedCondF then show ?case\n    by(auto simp del:fun_upd_apply simp:hyperset_defs)\nnext\n  case ListRed1 then show ?case\n    by(auto simp del:fun_upd_apply simp:hyperset_defs)\nnext\n  case ListRed2 then show ?case\n    by(auto simp del:fun_upd_apply simp:hyperset_defs)\nqed (simp_all del:fun_upd_apply add:hyperset_defs)\n(*>*)\n\ntext\\<open> Now preservation of definite assignment. \\<close>\n\nlemma assumes wf: \"wf_J_prog P\"\nshows red_preserves_defass:\n  \"P \\<turnstile> \\<langle>e,(h,l,sh),b\\<rangle> \\<rightarrow> \\<langle>e',(h',l',sh'),b'\\<rangle> \\<Longrightarrow> \\<D> e \\<lfloor>dom l\\<rfloor> \\<Longrightarrow> \\<D> e' \\<lfloor>dom l'\\<rfloor>\"\nand \"P \\<turnstile> \\<langle>es,(h,l,sh),b\\<rangle> [\\<rightarrow>] \\<langle>es',(h',l',sh'),b'\\<rangle> \\<Longrightarrow> \\<D>s es \\<lfloor>dom l\\<rfloor> \\<Longrightarrow> \\<D>s es' \\<lfloor>dom l'\\<rfloor>\"\n(*<*)\nproof (induct rule:red_reds_inducts)\n  case BinOpRed1 thus ?case by (auto elim!: D_mono[OF red_lA_incr])\nnext\n  case FAssRed1 thus ?case by (auto elim!: D_mono[OF red_lA_incr])\nnext\n  case CallObj thus ?case by (auto elim!: Ds_mono[OF red_lA_incr])\nnext\n  case RedCall thus ?case\n    by (auto dest!:sees_wf_mdecl[OF wf] simp:wf_mdecl_def hyperset_defs elim!:D_mono')\nnext\n  case RedSCall thus ?case\n    by (auto dest!:sees_wf_mdecl[OF wf] simp:wf_mdecl_def hyperset_defs elim!:D_mono')\nnext\n  case SCallInitRed\n  then show ?case by(auto simp:hyperset_defs Ds_Vals)\nnext\n  case InitBlockRed thus ?case\n    by(auto simp:hyperset_defs elim!:D_mono' simp del:fun_upd_apply)\nnext\n  case BlockRedNone thus ?case\n    by(auto simp:hyperset_defs elim!:D_mono' simp del:fun_upd_apply)\nnext\n  case BlockRedSome thus ?case\n    by(auto simp:hyperset_defs elim!:D_mono' simp del:fun_upd_apply)\nnext\n  case SeqRed thus ?case by (auto elim!: D_mono[OF red_lA_incr])\nnext\n  case CondRed thus ?case by (auto elim!: D_mono[OF red_lA_incr])\nnext\n  case TryRed thus ?case\n    by (fastforce dest:red_lcl_incr intro:D_mono' simp:hyperset_defs)\nnext\n  case ListRed1 thus ?case by (auto elim!: Ds_mono[OF red_lA_incr])\nnext\n  case RedWhile thus ?case by(auto simp:hyperset_defs elim!:D_mono')\nnext\n  case RedInit then show ?case by (auto intro: D_mono' simp: hyperset_defs)\nnext\n  case (RInitRed e h l sh b e' h' l' sh' b' C Cs e\\<^sub>0)\n  then show ?case by(auto simp:hyperset_defs dest:red_lcl_incr elim!:D_mono')\nqed(auto simp:hyperset_defs)\n(*>*)\n\n\ntext\\<open> Combining conformance of heap, static heap, and local variables: \\<close>\n\ndefinition sconf :: \"J_prog \\<Rightarrow> env \\<Rightarrow> state \\<Rightarrow> bool\"   (\"_,_ \\<turnstile> _ \\<surd>\"   [51,51,51]50)\nwhere\n  \"P,E \\<turnstile> s \\<surd>  \\<equiv>  let (h,l,sh) = s in P \\<turnstile> h \\<surd> \\<and> P,h \\<turnstile> l (:\\<le>) E \\<and> P,h \\<turnstile>\\<^sub>s sh \\<surd>\"\n\nlemma red_preserves_sconf:\n  \"\\<lbrakk> P \\<turnstile> \\<langle>e,s,b\\<rangle> \\<rightarrow> \\<langle>e',s',b'\\<rangle>; P,E,hp s,shp s \\<turnstile> e : T; P,E \\<turnstile> s \\<surd> \\<rbrakk> \\<Longrightarrow> P,E \\<turnstile> s' \\<surd>\"\n(*<*)\nby(fastforce intro:red_preserves_hconf red_preserves_lconf red_preserves_shconf\n            simp add:sconf_def)\n(*>*)\n\nlemma reds_preserves_sconf:\n  \"\\<lbrakk> P \\<turnstile> \\<langle>es,s,b\\<rangle> [\\<rightarrow>] \\<langle>es',s',b'\\<rangle>; P,E,hp s,shp s \\<turnstile> es [:] Ts; P,E \\<turnstile> s \\<surd> \\<rbrakk> \\<Longrightarrow> P,E \\<turnstile> s' \\<surd>\"\n(*<*)\nby(fastforce intro:reds_preserves_hconf reds_preserves_lconf reds_preserves_shconf\n            simp add:sconf_def)\n(*>*)\n\n\nsubsection \"Subject reduction\"\n\nlemma wt_blocks:\n \"\\<And>E. \\<lbrakk> length Vs = length Ts; length vs = length Ts \\<rbrakk> \\<Longrightarrow>\n       (P,E,h,sh \\<turnstile> blocks(Vs,Ts,vs,e) : T) =\n       (P,E(Vs[\\<mapsto>]Ts),h,sh \\<turnstile> e:T \\<and> (\\<exists>Ts'. map (typeof\\<^bsub>h\\<^esub>) vs = map Some Ts' \\<and> P \\<turnstile> Ts' [\\<le>] Ts))\"\n(*<*)\nproof(induct Vs Ts vs e rule:blocks_induct)\n  case (1 V Vs T Ts v vs e)\n  then show ?case by(force simp add:rel_list_all2_Cons2)\nqed simp_all\n(*>*)\n\ntheorem assumes wf: \"wf_J_prog P\"\nshows subject_reduction2: \"P \\<turnstile> \\<langle>e,(h,l,sh),b\\<rangle> \\<rightarrow> \\<langle>e',(h',l',sh'),b'\\<rangle> \\<Longrightarrow>\n  (\\<And>E T. \\<lbrakk> P,E \\<turnstile> (h,l,sh) \\<surd>; iconf sh e; P,E,h,sh \\<turnstile> e:T \\<rbrakk>\n           \\<Longrightarrow> \\<exists>T'. P,E,h',sh' \\<turnstile> e':T' \\<and> P \\<turnstile> T' \\<le> T)\"\nand subjects_reduction2: \"P \\<turnstile> \\<langle>es,(h,l,sh),b\\<rangle> [\\<rightarrow>] \\<langle>es',(h',l',sh'),b'\\<rangle> \\<Longrightarrow>\n  (\\<And>E Ts. \\<lbrakk> P,E \\<turnstile> (h,l,sh) \\<surd>; iconfs sh es; P,E,h,sh \\<turnstile> es [:] Ts \\<rbrakk>\n            \\<Longrightarrow> \\<exists>Ts'. P,E,h',sh' \\<turnstile> es' [:] Ts' \\<and> P \\<turnstile> Ts' [\\<le>] Ts)\"\n(*<*)\nproof (induct rule:red_reds_inducts)\n  case RedNew then show ?case by (auto simp: blank_def)\nnext\n  case RedNewFail thus ?case\n    by (unfold sconf_def hconf_def) (fastforce elim!:typeof_OutOfMemory)\nnext\n  case CastRed thus ?case\n    by(clarsimp simp:is_refT_def)\n      (blast intro: widens_trans dest!:widen_Class[THEN iffD1])\nnext\n  case RedCastFail thus ?case\n    by (unfold sconf_def hconf_def)  (fastforce elim!:typeof_ClassCast)\nnext\n  case (BinOpRed1 e\\<^sub>1 h l sh b e\\<^sub>1' h' l' sh' b' bop e\\<^sub>2)\n  have red: \"P \\<turnstile> \\<langle>e\\<^sub>1,(h,l,sh),b\\<rangle> \\<rightarrow> \\<langle>e\\<^sub>1',(h',l',sh'),b'\\<rangle>\"\n   and IH: \"\\<And>E T. \\<lbrakk>P,E \\<turnstile> (h,l,sh) \\<surd>; iconf sh e\\<^sub>1; P,E,h,sh \\<turnstile> e\\<^sub>1:T\\<rbrakk>\n                 \\<Longrightarrow> \\<exists>U. P,E,h',sh' \\<turnstile> e\\<^sub>1' : U \\<and> P \\<turnstile> U \\<le> T\"\n   and conf: \"P,E \\<turnstile> (h,l,sh) \\<surd>\" and iconf: \"iconf sh (e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2)\"\n   and wt: \"P,E,h,sh \\<turnstile> e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2 : T\" by fact+\n  have val: \"val_of e\\<^sub>1 = None\" using red iconf val_no_step by auto\n  then have iconf1: \"iconf sh e\\<^sub>1\" and nsub_RI2: \"\\<not>sub_RI e\\<^sub>2\" using iconf by simp+\n  have \"P,E,h',sh' \\<turnstile> e\\<^sub>1' \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2 : T\"\n  proof (cases bop)\n    assume [simp]: \"bop = Eq\"\n    from wt obtain T\\<^sub>1 T\\<^sub>2 where [simp]: \"T = Boolean\"\n      and wt\\<^sub>1: \"P,E,h,sh \\<turnstile> e\\<^sub>1 : T\\<^sub>1\" and wt\\<^sub>2: \"P,E,h,sh \\<turnstile> e\\<^sub>2 : T\\<^sub>2\" by auto\n    show ?thesis\n      using WTrt_hext_shext_mono[OF wt\\<^sub>2 red_hext_incr[OF red] red_shext_incr[OF red wt\\<^sub>1] nsub_RI2]\n        IH[OF conf iconf1 wt\\<^sub>1] by auto\n  next\n    assume  [simp]: \"bop = Add\"\n    from wt have [simp]: \"T = Integer\"\n      and wt\\<^sub>1: \"P,E,h,sh \\<turnstile> e\\<^sub>1 : Integer\" and wt\\<^sub>2: \"P,E,h,sh \\<turnstile> e\\<^sub>2 : Integer\"\n      by auto\n    show ?thesis\n      using WTrt_hext_shext_mono[OF wt\\<^sub>2 red_hext_incr[OF red] red_shext_incr[OF red wt\\<^sub>1] nsub_RI2]\n        IH[OF conf iconf1 wt\\<^sub>1] by auto\n  qed\n  thus ?case by auto\nnext\n  case (BinOpRed2 e\\<^sub>2 h l sh b e\\<^sub>2' h' l' sh' b' v\\<^sub>1 bop)\n  have red: \"P \\<turnstile> \\<langle>e\\<^sub>2,(h,l,sh),b\\<rangle> \\<rightarrow> \\<langle>e\\<^sub>2',(h',l',sh'),b'\\<rangle>\"\n   and IH: \"\\<And>E T. \\<lbrakk>P,E \\<turnstile> (h,l,sh) \\<surd>; iconf sh e\\<^sub>2; P,E,h,sh \\<turnstile> e\\<^sub>2:T\\<rbrakk>\n                 \\<Longrightarrow> \\<exists>U. P,E,h',sh' \\<turnstile> e\\<^sub>2' : U \\<and> P \\<turnstile> U \\<le> T\"\n   and conf: \"P,E \\<turnstile> (h,l,sh) \\<surd>\" and iconf: \"iconf sh (Val v\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2)\"\n   and wt: \"P,E,h,sh \\<turnstile> (Val v\\<^sub>1) \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2 : T\" by fact+\n  have iconf2: \"iconf sh e\\<^sub>2\" using iconf by simp\n  have \"P,E,h',sh' \\<turnstile> (Val v\\<^sub>1) \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2' : T\"\n  proof (cases bop)\n    assume [simp]: \"bop = Eq\"\n    from wt obtain T\\<^sub>1 T\\<^sub>2 where [simp]: \"T = Boolean\"\n      and wt\\<^sub>1: \"P,E,h,sh \\<turnstile> Val v\\<^sub>1 : T\\<^sub>1\" and wt\\<^sub>2: \"P,E,h,sh \\<turnstile> e\\<^sub>2:T\\<^sub>2\" by auto\n    show ?thesis\n      using IH[OF conf iconf2 wt\\<^sub>2] WTrt_hext_mono[OF wt\\<^sub>1 red_hext_incr[OF red]]\n      by auto\n  next\n    assume  [simp]: \"bop = Add\"\n    from wt have [simp]: \"T = Integer\"\n      and wt\\<^sub>1: \"P,E,h,sh \\<turnstile> Val v\\<^sub>1 : Integer\" and wt\\<^sub>2: \"P,E,h,sh \\<turnstile> e\\<^sub>2 : Integer\"\n      by auto\n    show ?thesis\n      using IH[OF conf iconf2 wt\\<^sub>2] WTrt_hext_mono[OF wt\\<^sub>1 red_hext_incr[OF red]]\n      by auto\n  qed\n  thus ?case by auto\nnext\n  case (RedBinOp bop) thus ?case\n  proof (cases bop)\n    case Eq thus ?thesis using RedBinOp by auto\n  next\n    case Add thus ?thesis using RedBinOp by auto\n  qed\nnext\n  case RedVar thus ?case by (fastforce simp:sconf_def lconf_def conf_def)\nnext\n  case (LAssRed e h l sh b e' h' l' sh' b' V)\n  obtain Te where Te: \"P,E,h,sh \\<turnstile> e : Te \\<and> P \\<turnstile> Te \\<le> the(E V)\" using LAssRed.prems(3) by auto\n  then have wide: \"P \\<turnstile> Te \\<le> the(E V)\" using LAssRed by simp\n  then have \"\\<exists>T'. P,E,h',sh' \\<turnstile> e' : T' \\<and> P \\<turnstile> T' \\<le> Te\"\n    using LAssRed.hyps(2) LAssRed.prems(1,2) Te widen_trans[OF _ wide] by auto\n  then obtain T' where wt: \"P,E,h',sh' \\<turnstile> e' : T' \\<and> P \\<turnstile> T' \\<le> Te\" by clarsimp\n  have \"P,E,h',sh' \\<turnstile> V:=e' : Void\" using LAssRed wt widen_trans[OF _ wide] by auto\n  then show ?case using LAssRed by(rule_tac x = Void in exI) auto\nnext\n  case (FAccRed e h l sh b e' h' l' sh' b' F D)\n  have IH: \"\\<And>E T. \\<lbrakk>P,E \\<turnstile> (h,l,sh) \\<surd>; iconf sh e; P,E,h,sh \\<turnstile> e : T\\<rbrakk>\n                 \\<Longrightarrow> \\<exists>U. P,E,h',sh' \\<turnstile> e' : U \\<and> P \\<turnstile> U \\<le> T\"\n   and conf: \"P,E \\<turnstile> (h,l,sh) \\<surd>\" and iconf: \"iconf sh (e\\<bullet>F{D})\"\n   and wt: \"P,E,h,sh \\<turnstile> e\\<bullet>F{D} : T\" by fact+\n  have iconf': \"iconf sh e\" using iconf by simp+\n  \\<comment> \\<open>The goal: ?case = @{prop ?case}\\<close>\n  \\<comment> \\<open>Now distinguish the two cases how wt can have arisen.\\<close>\n  { fix C assume wte: \"P,E,h,sh \\<turnstile> e : Class C\"\n             and has: \"P \\<turnstile> C has F,NonStatic:T in D\"\n    from IH[OF conf iconf' wte]\n    obtain U where wte': \"P,E,h',sh' \\<turnstile> e' : U\" and UsubC: \"P \\<turnstile> U \\<le> Class C\"\n      by auto\n    \\<comment> \\<open>Now distinguish what @{term U} can be.\\<close>\n    { assume \"U = NT\" hence ?case using wte'\n        by(blast intro:WTrtFAccNT widen_refl) }\n    moreover\n    { fix C' assume U: \"U = Class C'\" and C'subC: \"P \\<turnstile> C' \\<preceq>\\<^sup>* C\"\n      from has_field_mono[OF has C'subC] wte' U\n      have ?case by(blast intro:WTrtFAcc) }\n    ultimately have ?case using UsubC by(simp add: widen_Class) blast }\n  moreover\n  { assume \"P,E,h,sh \\<turnstile> e : NT\"\n    hence \"P,E,h',sh' \\<turnstile> e' : NT\" using IH[OF conf iconf'] by fastforce\n    hence ?case  by(fastforce intro:WTrtFAccNT widen_refl) }\n  ultimately show ?case using wt by blast\nnext\n  case RedFAcc thus ?case\n    by(fastforce simp:sconf_def hconf_def oconf_def conf_def has_field_def\n                dest:has_fields_fun)\nnext\n  case RedFAccNull thus ?case\n    by(fastforce intro: widen_refl WTThrow[OF WTVal] elim!: typeof_NullPointer\n                simp: sconf_def hconf_def)\nnext\n  case RedSFAccNone then show ?case\n    by(fastforce intro: WTrtThrow[OF WTrtVal] elim!: typeof_NoSuchFieldError\n      simp: sconf_def hconf_def)\nnext\n  case RedFAccStatic then show ?case\n    by(fastforce intro: WTrtThrow[OF WTrtVal] elim!: typeof_IncompatibleClassChangeError\n      simp: sconf_def hconf_def)\nnext\n  case (RedSFAcc C F t D sh sfs i v h l es)\n  then have \"P \\<turnstile> C has F,Static:T in D\" by fast\n  then have dM: \"P \\<turnstile> D has F,Static:T in D\" by(rule has_field_idemp)\n  then show ?case using RedSFAcc by(fastforce simp:sconf_def shconf_def soconf_def conf_def)\nnext\n  case SFAccInitDoneRed then show ?case by (meson widen_refl)\nnext\n  case (SFAccInitRed C F t D sh h l E T)\n  have \"is_class P D\" using SFAccInitRed.hyps(1) by(rule has_field_is_class')\n  then have \"P,E,h,sh \\<turnstile> INIT D ([D],False) \\<leftarrow> C\\<bullet>\\<^sub>sF{D} : T \\<and> P \\<turnstile> T \\<le> T\"\n    using SFAccInitRed WTrtInit[OF SFAccInitRed.prems(3)] by clarsimp\n  then show ?case by(rule exI)\nnext\n  case RedSFAccNonStatic then show ?case\n    by(fastforce intro: WTrtThrow[OF WTrtVal] elim!: typeof_IncompatibleClassChangeError\n      simp: sconf_def hconf_def)\nnext\n  case (FAssRed1 e h l sh b e' h' l' sh' b' F D e\\<^sub>2)\n  have red: \"P \\<turnstile> \\<langle>e,(h,l,sh),b\\<rangle> \\<rightarrow> \\<langle>e',(h',l',sh'),b'\\<rangle>\"\n   and IH: \"\\<And>E T. \\<lbrakk>P,E \\<turnstile> (h,l,sh) \\<surd>; iconf sh e; P,E,h,sh \\<turnstile> e : T\\<rbrakk>\n                 \\<Longrightarrow> \\<exists>U. P,E,h',sh' \\<turnstile> e' : U \\<and> P \\<turnstile> U \\<le> T\"\n   and conf: \"P,E \\<turnstile> (h,l,sh) \\<surd>\" and iconf: \"iconf sh (e\\<bullet>F{D} := e\\<^sub>2)\"\n   and wt: \"P,E,h,sh \\<turnstile> e\\<bullet>F{D}:=e\\<^sub>2 : T\" by fact+\n  have val: \"val_of e = None\" using red iconf val_no_step by auto\n  then have iconf': \"iconf sh e\" and nsub_RI2: \"\\<not>sub_RI e\\<^sub>2\" using iconf by simp+\n  from wt have void: \"T = Void\" by blast\n  \\<comment> \\<open>We distinguish if @{term e} has type @{term NT} or a Class type\\<close>\n  \\<comment> \\<open>Remember ?case = @{term ?case}\\<close>\n  { assume wt':\"P,E,h,sh \\<turnstile> e : NT\"\n    hence \"P,E,h',sh' \\<turnstile> e' : NT\" using IH[OF conf iconf'] by fastforce\n    moreover obtain T\\<^sub>2 where \"P,E,h,sh \\<turnstile> e\\<^sub>2 : T\\<^sub>2\" using wt by auto\n    from this red_hext_incr[OF red] red_shext_incr[OF red wt'] nsub_RI2 have  \"P,E,h',sh' \\<turnstile> e\\<^sub>2 : T\\<^sub>2\"\n      by(rule WTrt_hext_shext_mono)\n    ultimately have ?case using void by(blast intro!:WTrtFAssNT)\n  }\n  moreover\n  { fix C TF T\\<^sub>2 assume wt\\<^sub>1: \"P,E,h,sh \\<turnstile> e : Class C\" and wt\\<^sub>2: \"P,E,h,sh \\<turnstile> e\\<^sub>2 : T\\<^sub>2\"\n    and has: \"P \\<turnstile> C has F,NonStatic:TF in D\" and sub: \"P \\<turnstile> T\\<^sub>2 \\<le> TF\"\n    obtain U where wt\\<^sub>1': \"P,E,h',sh' \\<turnstile> e' : U\" and UsubC: \"P \\<turnstile> U \\<le> Class C\"\n      using IH[OF conf iconf' wt\\<^sub>1] by blast\n    have wt\\<^sub>2': \"P,E,h',sh' \\<turnstile> e\\<^sub>2 : T\\<^sub>2\"\n      by(rule WTrt_hext_shext_mono[OF wt\\<^sub>2 red_hext_incr[OF red] red_shext_incr[OF red wt\\<^sub>1] nsub_RI2])\n    \\<comment> \\<open>Is @{term U} the null type or a class type?\\<close>\n    { assume \"U = NT\" with wt\\<^sub>1' wt\\<^sub>2' void have ?case\n        by(blast intro!:WTrtFAssNT) }\n    moreover\n    { fix C' assume UClass: \"U = Class C'\" and \"subclass\": \"P \\<turnstile> C' \\<preceq>\\<^sup>* C\"\n      have \"P,E,h',sh' \\<turnstile> e' : Class C'\" using wt\\<^sub>1' UClass by auto\n      moreover have \"P \\<turnstile> C' has F,NonStatic:TF in D\"\n        by(rule has_field_mono[OF has \"subclass\"])\n      ultimately have ?case using wt\\<^sub>2' sub void by(blast intro:WTrtFAss) }\n    ultimately have ?case using UsubC by(auto simp add:widen_Class) }\n  ultimately show ?case using wt by blast\nnext\n  case (FAssRed2 e\\<^sub>2 h l sh b e\\<^sub>2' h' l' sh' b' v F D)\n  have red: \"P \\<turnstile> \\<langle>e\\<^sub>2,(h,l,sh),b\\<rangle> \\<rightarrow> \\<langle>e\\<^sub>2',(h',l',sh'),b'\\<rangle>\"\n   and IH: \"\\<And>E T. \\<lbrakk>P,E \\<turnstile> (h,l,sh) \\<surd>; iconf sh e\\<^sub>2; P,E,h,sh \\<turnstile> e\\<^sub>2 : T\\<rbrakk>\n                 \\<Longrightarrow> \\<exists>U. P,E,h',sh' \\<turnstile> e\\<^sub>2' : U \\<and> P \\<turnstile> U \\<le> T\"\n   and conf: \"P,E \\<turnstile> (h,l,sh) \\<surd>\" and iconf: \"iconf sh (Val v\\<bullet>F{D} := e\\<^sub>2)\"\n   and wt: \"P,E,h,sh \\<turnstile> Val v\\<bullet>F{D}:=e\\<^sub>2 : T\" by fact+\n  have iconf2: \"iconf sh e\\<^sub>2\" using iconf by simp\n  from wt have [simp]: \"T = Void\" by auto\n  from wt show ?case\n  proof (rule WTrt_elim_cases)\n    fix C TF T\\<^sub>2\n    assume wt\\<^sub>1: \"P,E,h,sh \\<turnstile> Val v : Class C\"\n      and has: \"P \\<turnstile> C has F,NonStatic:TF in D\"\n      and wt\\<^sub>2: \"P,E,h,sh \\<turnstile> e\\<^sub>2 : T\\<^sub>2\" and TsubTF: \"P \\<turnstile> T\\<^sub>2 \\<le> TF\"\n    have wt\\<^sub>1': \"P,E,h',sh' \\<turnstile> Val v : Class C\"\n      using WTrt_hext_mono[OF wt\\<^sub>1 red_hext_incr[OF red]] by auto\n    obtain T\\<^sub>2' where wt\\<^sub>2': \"P,E,h',sh' \\<turnstile> e\\<^sub>2' : T\\<^sub>2'\" and T'subT: \"P \\<turnstile> T\\<^sub>2' \\<le> T\\<^sub>2\"\n      using IH[OF conf iconf2 wt\\<^sub>2] by blast\n    have \"P,E,h',sh' \\<turnstile> Val v\\<bullet>F{D}:=e\\<^sub>2' : Void\"\n      by(rule WTrtFAss[OF wt\\<^sub>1' has wt\\<^sub>2' widen_trans[OF T'subT TsubTF]])\n    thus ?case by auto\n  next\n    fix T\\<^sub>2 assume null: \"P,E,h,sh \\<turnstile> Val v : NT\" and wt\\<^sub>2: \"P,E,h,sh \\<turnstile> e\\<^sub>2 : T\\<^sub>2\"\n    from null have \"v = Null\" by simp\n    moreover\n    obtain T\\<^sub>2' where \"P,E,h',sh' \\<turnstile> e\\<^sub>2' : T\\<^sub>2' \\<and> P \\<turnstile> T\\<^sub>2' \\<le> T\\<^sub>2\"\n      using IH[OF conf iconf2 wt\\<^sub>2] by blast\n    ultimately show ?thesis by(fastforce intro:WTrtFAssNT)\n  qed\nnext\n  case RedFAss thus ?case by(auto simp del:fun_upd_apply)\nnext\n  case RedFAssNull thus ?case\n    by(fastforce intro: WTThrow[OF WTVal] elim!:typeof_NullPointer simp:sconf_def hconf_def)\nnext\n  case RedFAssStatic then show ?case \n    by(fastforce intro: WTrtThrow[OF WTrtVal] elim!: typeof_IncompatibleClassChangeError\n      simp: sconf_def hconf_def)\nnext\n  case (SFAssRed e h l sh b e' h' l' sh' b' C F D E T)\n  have IH: \"\\<And>E T. \\<lbrakk>P,E \\<turnstile> (h,l,sh) \\<surd>; iconf sh e; P,E,h,sh \\<turnstile> e : T\\<rbrakk>\n                 \\<Longrightarrow> \\<exists>U. P,E,h',sh' \\<turnstile> e' : U \\<and> P \\<turnstile> U \\<le> T\"\n   and conf: \"P,E \\<turnstile> (h,l,sh) \\<surd>\" and iconf: \"iconf sh (C\\<bullet>\\<^sub>sF{D} := e)\"\n   and wt: \"P,E,h,sh \\<turnstile> C\\<bullet>\\<^sub>sF{D}:=e : T\" by fact+\n  have iconf': \"iconf sh e\" using iconf by simp\n  from wt have [simp]: \"T = Void\" by auto\n  from wt show ?case\n  proof (rule WTrt_elim_cases)\n    fix TF T1\n    assume has: \"P \\<turnstile> C has F,Static:TF in D\"\n      and wt1: \"P,E,h,sh \\<turnstile> e : T1\" and TsubTF: \"P \\<turnstile> T1 \\<le> TF\"\n    obtain T' where wt1': \"P,E,h',sh' \\<turnstile> e' : T'\" and T'subT: \"P \\<turnstile> T' \\<le> T1\"\n      using IH[OF conf iconf' wt1] by blast\n    have \"P,E,h',sh' \\<turnstile> C\\<bullet>\\<^sub>sF{D}:=e' : Void\"\n      by(rule WTrtSFAss[OF wt1' has widen_trans[OF T'subT TsubTF]])\n    thus ?case by auto\n  qed\nnext\n  case SFAssInitDoneRed then show ?case by (meson widen_refl)\nnext\n  case (SFAssInitRed C F t D sh v h l E T)\n  have \"is_class P D\" using SFAssInitRed.hyps(1) by(rule has_field_is_class')\n  then have \"P,E,h,sh \\<turnstile> INIT D ([D],False) \\<leftarrow> C\\<bullet>\\<^sub>sF{D} := Val v : T \\<and> P \\<turnstile> T \\<le> T\"\n    using SFAssInitRed WTrtInit[OF SFAssInitRed.prems(3)] by clarsimp\n  then show ?case by(rule exI)\nnext\n  case RedSFAssNone then show ?case\n    by(fastforce intro: WTrtThrow[OF WTrtVal] elim!: typeof_NoSuchFieldError\n      simp: sconf_def hconf_def)\nnext\n  case RedSFAssNonStatic then show ?case\n    by(fastforce intro: WTrtThrow[OF WTrtVal] elim!: typeof_IncompatibleClassChangeError\n      simp: sconf_def hconf_def)\nnext\n  case (CallObj e h l sh b e' h' l' sh' b' M es)\n  have red: \"P \\<turnstile> \\<langle>e,(h,l,sh),b\\<rangle> \\<rightarrow> \\<langle>e',(h',l',sh'),b'\\<rangle>\"\n   and IH: \"\\<And>E T. \\<lbrakk>P,E \\<turnstile> (h,l,sh) \\<surd>; iconf sh e; P,E,h,sh \\<turnstile> e : T\\<rbrakk>\n                 \\<Longrightarrow> \\<exists>U. P,E,h',sh' \\<turnstile> e' : U \\<and> P \\<turnstile> U \\<le> T\"\n   and conf: \"P,E \\<turnstile> (h,l,sh) \\<surd>\" and iconf: \"iconf sh (e\\<bullet>M(es))\"\n   and wt: \"P,E,h,sh \\<turnstile> e\\<bullet>M(es) : T\" by fact+\n  have val: \"val_of e = None\" using red iconf val_no_step by auto\n  then have iconf': \"iconf sh e\" and nsub_RIs: \"\\<not>sub_RIs es\" using iconf by simp+\n  \\<comment> \\<open>We distinguish if @{term e} has type @{term NT} or a Class type\\<close>\n  \\<comment> \\<open>Remember ?case = @{term ?case}\\<close>\n  { assume wt':\"P,E,h,sh \\<turnstile> e:NT\"\n    hence \"P,E,h',sh' \\<turnstile> e' : NT\" using IH[OF conf iconf'] by fastforce\n    moreover\n    fix Ts assume wtes: \"P,E,h,sh \\<turnstile> es [:] Ts\"\n    have \"P,E,h',sh' \\<turnstile> es [:] Ts\"\n      by(rule WTrts_hext_shext_mono[OF wtes red_hext_incr[OF red] red_shext_incr[OF red wt'] nsub_RIs])\n    ultimately have ?case by(blast intro!:WTrtCallNT) }\n  moreover\n  { fix C D Ts Us pns body\n    assume wte: \"P,E,h,sh \\<turnstile> e : Class C\"\n      and \"method\": \"P \\<turnstile> C sees M,NonStatic:Ts\\<rightarrow>T = (pns,body) in D\"\n      and wtes: \"P,E,h,sh \\<turnstile> es [:] Us\" and subs: \"P \\<turnstile> Us [\\<le>] Ts\"\n    obtain U where wte': \"P,E,h',sh' \\<turnstile> e' : U\" and UsubC: \"P \\<turnstile> U \\<le> Class C\"\n      using IH[OF conf iconf' wte] by blast\n    \\<comment> \\<open>Is @{term U} the null type or a class type?\\<close>\n    { assume \"U = NT\"\n      moreover have \"P,E,h',sh' \\<turnstile> es [:] Us\"\n        by(rule WTrts_hext_shext_mono[OF wtes red_hext_incr[OF red] red_shext_incr[OF red wte] nsub_RIs])\n      ultimately have ?case using wte' by(blast intro!:WTrtCallNT) }\n    moreover\n    { fix C' assume UClass: \"U = Class C'\" and \"subclass\": \"P \\<turnstile> C' \\<preceq>\\<^sup>* C\"\n      have \"P,E,h',sh' \\<turnstile> e' : Class C'\" using wte' UClass by auto\n      moreover obtain Ts' T' pns' body' D'\n        where method': \"P \\<turnstile> C' sees M,NonStatic:Ts'\\<rightarrow>T' = (pns',body') in D'\"\n        and subs': \"P \\<turnstile> Ts [\\<le>] Ts'\" and sub': \"P \\<turnstile> T' \\<le> T\"\n        using Call_lemma[OF \"method\" \"subclass\" wf] by fast\n      moreover have \"P,E,h',sh' \\<turnstile> es [:] Us\"\n        by(rule WTrts_hext_shext_mono[OF wtes red_hext_incr[OF red] red_shext_incr[OF red wte] nsub_RIs])\n      ultimately have ?case\n        using subs by(blast intro:WTrtCall rtrancl_trans widens_trans) }\n    ultimately have ?case using UsubC by(auto simp add:widen_Class) }\n  ultimately show ?case using wt by auto\nnext\n  case (CallParams es h l sh b es' h' l' sh' b' v M)\n  have reds: \"P \\<turnstile> \\<langle>es,(h,l,sh),b\\<rangle> [\\<rightarrow>] \\<langle>es',(h',l',sh'),b'\\<rangle>\"\n   and IH: \"\\<And>E Ts. \\<lbrakk>P,E \\<turnstile> (h,l,sh) \\<surd>; iconfs sh es; P,E,h,sh \\<turnstile> es [:] Ts\\<rbrakk>\n                 \\<Longrightarrow> \\<exists>Us. P,E,h',sh' \\<turnstile> es' [:] Us \\<and> P \\<turnstile> Us [\\<le>] Ts\"\n   and conf: \"P,E \\<turnstile> (h,l,sh) \\<surd>\" and iconf: \"iconf sh (Val v\\<bullet>M(es))\"\n   and wt: \"P,E,h,sh \\<turnstile> Val v\\<bullet>M(es) : T\" by fact+\n  have iconfs: \"iconfs sh es\" using iconf by simp\n  from wt show ?case\n  proof (rule WTrt_elim_cases)\n    fix C D Ts Us pns body\n    assume wte: \"P,E,h,sh \\<turnstile> Val v : Class C\"\n      and \"P \\<turnstile> C sees M,NonStatic:Ts\\<rightarrow>T = (pns,body) in D\"\n      and wtes: \"P,E,h,sh \\<turnstile> es [:] Us\" and \"P \\<turnstile> Us [\\<le>] Ts\"\n    moreover have \"P,E,h',sh' \\<turnstile> Val v : Class C\"\n      using WTrt_hext_mono[OF wte reds_hext_incr[OF reds]] by auto\n    moreover\n    obtain Us' where \"P,E,h',sh' \\<turnstile> es' [:] Us' \\<and> P \\<turnstile> Us' [\\<le>] Us\"\n      using IH[OF conf iconfs wtes] by blast\n    ultimately show ?thesis by(blast intro:WTrtCall widens_trans)\n  next\n    fix Us\n    assume null: \"P,E,h,sh \\<turnstile> Val v : NT\" and wtes: \"P,E,h,sh \\<turnstile> es [:] Us\"\n    from null have \"v = Null\" by simp\n    moreover\n    obtain Us' where \"P,E,h',sh' \\<turnstile> es' [:] Us' \\<and> P \\<turnstile> Us' [\\<le>] Us\"\n      using IH[OF conf iconfs wtes] by blast\n    ultimately show ?thesis by(fastforce intro:WTrtCallNT)\n  qed\nnext\n  case (RedCall h a C fs M Ts T pns body D vs l sh b E T')\n  have hp: \"h a = Some(C,fs)\"\n   and \"method\": \"P \\<turnstile> C sees M,NonStatic: Ts\\<rightarrow>T = (pns,body) in D\"\n   and wt: \"P,E,h,sh \\<turnstile> addr a\\<bullet>M(map Val vs) : T'\" by fact+\n  obtain Ts' where wtes: \"P,E,h,sh \\<turnstile> map Val vs [:] Ts'\"\n    and subs: \"P \\<turnstile> Ts' [\\<le>] Ts\" and T'isT: \"T' = T\"\n    using wt \"method\" hp by (auto dest:sees_method_fun)\n  from wtes subs have length_vs: \"length vs = length Ts\"\n    by(fastforce simp:list_all2_iff dest!:WTrts_same_length)\n  from sees_wf_mdecl[OF wf \"method\"] obtain T''\n    where wtabody: \"P,[this#pns [\\<mapsto>] Class D#Ts] \\<turnstile> body :: T''\"\n    and T''subT: \"P \\<turnstile> T'' \\<le> T\" and length_pns: \"length pns = length Ts\"\n    by(fastforce simp:wf_mdecl_def simp del:map_upds_twist)\n  from wtabody have \"P,Map.empty(this#pns [\\<mapsto>] Class D#Ts),h,sh \\<turnstile> body : T''\"\n    by(rule WT_implies_WTrt)\n  hence \"P,E(this#pns [\\<mapsto>] Class D#Ts),h,sh \\<turnstile> body : T''\"\n    by(rule WTrt_env_mono) simp\n  hence \"P,E,h,sh \\<turnstile> blocks(this#pns, Class D#Ts, Addr a#vs, body) : T''\"\n  using wtes subs hp sees_method_decl_above[OF \"method\"] length_vs length_pns\n    by(fastforce simp add:wt_blocks rel_list_all2_Cons2)\n  with T''subT T'isT show ?case by blast\nnext\n  case RedCallNull thus ?case\n    by(fastforce intro: WTThrow[OF WTVal] elim!:typeof_NullPointer simp: sconf_def hconf_def)\nnext\n  case RedCallStatic then show ?case \n    by(fastforce intro: WTrtThrow[OF WTrtVal] elim!: typeof_IncompatibleClassChangeError\n      simp: sconf_def hconf_def)\nnext\n  case (SCallParams es h l sh b es' h' l' sh' b' C M)\n  have IH: \"\\<And>E Ts. \\<lbrakk>P,E \\<turnstile> (h,l,sh) \\<surd>; iconfs sh es; P,E,h,sh \\<turnstile> es [:] Ts\\<rbrakk>\n                 \\<Longrightarrow> \\<exists>Us. P,E,h',sh' \\<turnstile> es' [:] Us \\<and> P \\<turnstile> Us [\\<le>] Ts\"\n   and conf: \"P,E \\<turnstile> (h,l,sh) \\<surd>\" and iconf: \"iconf sh (C\\<bullet>\\<^sub>sM(es))\"\n   and wt: \"P,E,h,sh \\<turnstile> C\\<bullet>\\<^sub>sM(es) : T\" by fact+\n  have iconfs: \"iconfs sh es\" using iconf by simp\n  from wt show ?case\n  proof (rule WTrt_elim_cases)\n    fix D Ts Us pns body sfs vs\n    assume method: \"P \\<turnstile> C sees M,Static:Ts\\<rightarrow>T = (pns,body) in D\"\n      and wtes: \"P,E,h,sh \\<turnstile> es [:] Us\" and us: \"P \\<turnstile> Us [\\<le>] Ts\"\n      and clinit: \"M = clinit \\<longrightarrow> sh D = \\<lfloor>(sfs,Processing)\\<rfloor> \\<and> es = map Val vs\"\n    obtain Us' where es': \"P,E,h',sh' \\<turnstile> es' [:] Us'\" and us': \"P \\<turnstile> Us' [\\<le>] Us\"\n      using IH[OF conf iconfs wtes] by blast\n    show ?thesis\n    proof(cases \"M = clinit\")\n      case True then show ?thesis using clinit SCallParams.hyps(1) by blast\n    next\n      case False\n      then show ?thesis using es' method us us' by(blast intro:WTrtSCall widens_trans)\n    qed\n  qed\nnext\n  case (RedSCall C M Ts T pns body D vs h l sh E T')\n  have \"method\": \"P \\<turnstile> C sees M,Static: Ts\\<rightarrow>T = (pns,body) in D\"\n   and wt: \"P,E,h,sh \\<turnstile> C\\<bullet>\\<^sub>sM(map Val vs) : T'\" by fact+\n  obtain Ts' where wtes: \"P,E,h,sh \\<turnstile> map Val vs [:] Ts'\"\n    and subs: \"P \\<turnstile> Ts' [\\<le>] Ts\" and T'isT: \"T' = T\"\n    using wt \"method\" map_Val_eq by(auto dest:sees_method_fun)+\n  from wtes subs have length_vs: \"length vs = length Ts\"\n    by(fastforce simp:list_all2_iff dest!:WTrts_same_length)\n  from sees_wf_mdecl[OF wf \"method\"] obtain T''\n    where wtabody: \"P,[pns [\\<mapsto>] Ts] \\<turnstile> body :: T''\"\n    and T''subT: \"P \\<turnstile> T'' \\<le> T\" and length_pns: \"length pns = length Ts\"\n    by(fastforce simp:wf_mdecl_def simp del:map_upds_twist)\n  from wtabody have \"P,Map.empty(pns [\\<mapsto>] Ts),h,sh \\<turnstile> body : T''\"\n    by(rule WT_implies_WTrt)\n  hence \"P,E(pns [\\<mapsto>] Ts),h,sh \\<turnstile> body : T''\"\n    by(rule WTrt_env_mono) simp\n  hence \"P,E,h,sh \\<turnstile> blocks(pns, Ts, vs, body) : T''\"\n  using wtes subs sees_method_decl_above[OF \"method\"] length_vs length_pns\n    by(fastforce simp add:wt_blocks rel_list_all2_Cons2)\n  with T''subT T'isT show ?case by blast\nnext\n  case SCallInitDoneRed then show ?case by (meson widen_refl)\nnext\n  case (SCallInitRed C F Ts t pns body D sh v h l E T)\n  have \"is_class P D\" using SCallInitRed.hyps(1) by(rule sees_method_is_class')\n  then have \"P,E,h,sh \\<turnstile> INIT D ([D],False) \\<leftarrow> C\\<bullet>\\<^sub>sF(map Val v) : T \\<and> P \\<turnstile> T \\<le> T\"\n    using SCallInitRed WTrtInit[OF SCallInitRed.prems(3)] by clarsimp\n  then show ?case by(rule exI)\nnext\n  case RedSCallNone then show ?case\n    by(fastforce intro: WTrtThrow[OF WTrtVal] elim!: typeof_NoSuchMethodError\n      simp: sconf_def hconf_def)\nnext\n  case RedSCallNonStatic then show ?case \n    by(fastforce intro: WTrtThrow[OF WTrtVal] elim!: typeof_IncompatibleClassChangeError\n      simp: sconf_def hconf_def)\nnext\n  case BlockRedNone thus ?case\n    by(auto simp del:fun_upd_apply)(fastforce simp:sconf_def lconf_def)\nnext\n  case (BlockRedSome e h l V sh b e' h' l' sh' b' v T E Te)\n  have red: \"P \\<turnstile> \\<langle>e,(h,l(V:=None),sh),b\\<rangle> \\<rightarrow> \\<langle>e',(h',l',sh'),b'\\<rangle>\"\n   and IH: \"\\<And>E T. \\<lbrakk>P,E \\<turnstile> (h,l(V:=None),sh) \\<surd>; iconf sh e; P,E,h,sh \\<turnstile> e : T\\<rbrakk>\n                   \\<Longrightarrow> \\<exists>T'. P,E,h',sh' \\<turnstile> e' : T' \\<and> P \\<turnstile> T' \\<le> T\"\n   and Some: \"l' V = Some v\" and conf: \"P,E \\<turnstile> (h,l,sh) \\<surd>\"\n   and iconf: \"iconf sh {V:T; e}\"\n   and wt: \"P,E,h,sh \\<turnstile> {V:T; e} : Te\" by fact+\n  obtain Te' where IH': \"P,E(V\\<mapsto>T),h',sh' \\<turnstile> e' : Te' \\<and> P \\<turnstile> Te' \\<le> Te\"\n    using IH conf iconf wt by(fastforce simp:sconf_def lconf_def)\n  have \"P,h' \\<turnstile> l' (:\\<le>) E(V\\<mapsto>T)\" using conf wt\n    by(fastforce intro:red_preserves_lconf[OF red] simp:sconf_def lconf_def)\n  hence \"P,h' \\<turnstile> v :\\<le> T\" using Some by(fastforce simp:lconf_def)\n  with IH' show ?case\n    by(fastforce simp:sconf_def conf_def fun_upd_same simp del:fun_upd_apply)\nnext\n  case (InitBlockRed e h l V v sh b e' h' l' sh' b' v' T E T')\n  have red: \"P \\<turnstile> \\<langle>e, (h,l(V\\<mapsto>v),sh),b\\<rangle> \\<rightarrow> \\<langle>e',(h',l',sh'),b'\\<rangle>\"\n   and IH: \"\\<And>E T. \\<lbrakk>P,E \\<turnstile> (h,l(V\\<mapsto>v),sh) \\<surd>; iconf sh e; P,E,h,sh \\<turnstile> e : T\\<rbrakk>\n                    \\<Longrightarrow> \\<exists>U. P,E,h',sh' \\<turnstile> e' : U \\<and> P \\<turnstile> U \\<le> T\"\n   and v': \"l' V = Some v'\" and conf: \"P,E \\<turnstile> (h,l,sh) \\<surd>\"\n   and iconf: \"iconf sh {V:T; V:=Val v;; e}\"\n   and wt: \"P,E,h,sh \\<turnstile> {V:T := Val v; e} : T'\" by fact+\n  from wt obtain T\\<^sub>1 where wt\\<^sub>1: \"typeof\\<^bsub>h\\<^esub> v = Some T\\<^sub>1\"\n    and T1subT: \"P \\<turnstile> T\\<^sub>1 \\<le> T\" and wt\\<^sub>2: \"P,E(V\\<mapsto>T),h,sh \\<turnstile> e : T'\" by auto\n  have lconf\\<^sub>2: \"P,h \\<turnstile> l(V\\<mapsto>v) (:\\<le>) E(V\\<mapsto>T)\" using conf wt\\<^sub>1 T1subT\n    by(simp add:sconf_def lconf_upd2 conf_def)\n  have \"\\<exists>T\\<^sub>1'. typeof\\<^bsub>h'\\<^esub> v' = Some T\\<^sub>1' \\<and> P \\<turnstile> T\\<^sub>1' \\<le> T\"\n    using v' red_preserves_lconf[OF red wt\\<^sub>2 lconf\\<^sub>2]\n    by(fastforce simp:lconf_def conf_def)\n  with IH conf iconf lconf\\<^sub>2 wt\\<^sub>2 show ?case by (fastforce simp add:sconf_def)\nnext\n  case (SeqRed e h l sh b e' h' l' sh' b' e\\<^sub>2)\n  then have val: \"val_of e = None\" by (simp add: val_no_step)\n  show ?case\n  proof(cases \"lass_val_of e\")\n    case None\n    then show ?thesis\n      using SeqRed val by(auto elim: WTrt_hext_shext_mono[OF _ red_hext_incr red_shext_incr])\n  next\n    case (Some a)\n    have \"sh = sh'\" using SeqRed lass_val_of_spec[OF Some] by auto\n    then show ?thesis using SeqRed val Some\n      by(auto intro: lass_val_of_iconf[OF Some] elim: WTrt_hext_mono[OF _ red_hext_incr])\n  qed\nnext\n  case CondRed thus ?case\n    by auto (blast intro:WTrt_hext_shext_mono[OF _ red_hext_incr red_shext_incr])+\nnext\n  case ThrowRed thus ?case\n    by(auto simp:is_refT_def)(blast dest:widen_Class[THEN iffD1])+\nnext\n  case RedThrowNull thus ?case\n    by(fastforce intro: WTThrow[OF WTVal] elim!:typeof_NullPointer simp:sconf_def hconf_def)\nnext\n  case TryRed thus ?case\n    by auto (blast intro:widen_trans WTrt_hext_shext_mono[OF _ red_hext_incr red_shext_incr])\nnext\n  case RedTryFail thus ?case\n    by(fastforce intro: WTrtThrow[OF WTrtVal] simp:sconf_def hconf_def)\nnext\n  case (ListRed1 e h l sh b e' h' l' sh' b' es)\n    then have val: \"val_of e = None\" by(simp add: val_no_step)\n    obtain U Us where Ts: \"Ts = U # Us\" using ListRed1 by auto\n    then have nsub_RI: \"\\<not> sub_RIs es\" and wts: \"P,E,h,sh \\<turnstile> es [:] Us\" and wt: \"P,E,h,sh \\<turnstile> e : U\"\n     and IH: \"\\<And>E T. \\<lbrakk>P,E \\<turnstile> (h, l, sh) \\<surd>; P,E,h,sh \\<turnstile> e : T\\<rbrakk> \\<Longrightarrow> \\<exists>T'. P,E,h',sh' \\<turnstile> e' : T' \\<and> P \\<turnstile> T' \\<le> T\"\n      using ListRed1 val by auto\n    obtain T' where\n    \"\\<forall>E0 E1. (\\<exists>T2. P,E1,h',sh' \\<turnstile> e' : T2 \\<and> P \\<turnstile> T2 \\<le> E0) = (P,E1,h',sh' \\<turnstile> e' : T' E0 E1 \\<and> P \\<turnstile> T' E0 E1 \\<le> E0)\"\n      by moura\n    then have disj: \"\\<forall>E t. \\<not> P,E \\<turnstile> (h, l, sh) \\<surd> \\<or> \\<not> P,E,h,sh \\<turnstile> e : t \\<or> P,E,h',sh' \\<turnstile> e' : T' t E \\<and> P \\<turnstile> T' t E \\<le> t\"\n      using IH by presburger\n    have \"P,E,h',sh' \\<turnstile> es [:] Us\"\n      using nsub_RI wts wt by (metis (no_types) ListRed1.hyps(1) WTrts_hext_shext_mono red_hext_incr red_shext_incr)\n    then have \"\\<exists>ts. (\\<exists>t tsa. ts = t # tsa \\<and> P,E,h',sh' \\<turnstile> e' : t \\<and> P,E,h',sh' \\<turnstile> es [:] tsa) \\<and> P \\<turnstile> ts [\\<le>] (U # Us)\"\n      using disj wt ListRed1.prems(1) by blast\n    then show ?case using Ts by auto\nnext\n  case ListRed2 thus ?case\n    by(fastforce dest: hext_typeof_mono[OF reds_hext_incr])\nnext\n  case (InitNoneRed sh C C' Cs e h l b)\n  then have sh: \"sh \\<unlhd>\\<^sub>s sh(C \\<mapsto> (sblank P C, Prepared))\" by(simp add: shext_def)\n  have wt: \"P,E,h,sh(C \\<mapsto> (sblank P C, Prepared)) \\<turnstile> INIT C' (C # Cs,False) \\<leftarrow> e : T\"\n      using InitNoneRed WTrt_shext_mono[OF _ sh] by fastforce\n  then show ?case by(rule_tac x = T in exI) (simp add: fun_upd_def)\nnext\n  case (RedInitDone sh C sfs C' Cs e h l b)\n  then have \"P,E,h,sh \\<turnstile> INIT C' (Cs,True) \\<leftarrow> e : T\" by auto (metis Nil_tl list.set_sel(2))\n  then show ?case by(rule_tac x = T in exI) simp\nnext\n  case (RedInitProcessing sh C sfs C' Cs e h l b)\n  then have \"P,E,h,sh \\<turnstile> INIT C' (Cs,True) \\<leftarrow> e : T\" by auto (metis Nil_tl list.set_sel(2))+\n  then show ?case by(rule_tac x = T in exI) simp\nnext\n  case RedInitError then show ?case\n    by(fastforce intro: WTrtThrow[OF WTrtVal] elim!: typeof_NoClassDefFoundError\n      simp: sconf_def hconf_def)\nnext\n  case (InitObjectRed sh C sfs sh' C' Cs e h l b)\n  then have sh: \"sh \\<unlhd>\\<^sub>s sh(Object \\<mapsto> (sfs, Processing))\" by(simp add: shext_def)\n  have \"P,E,h,sh' \\<turnstile> INIT C' (C # Cs,True) \\<leftarrow> e : T\"\n    using InitObjectRed WTrt_shext_mono[OF _ sh] by auto\n  then show ?case by(rule_tac x = T in exI) (simp add: fun_upd_def)\nnext\n  case (InitNonObjectSuperRed sh C sfs D fs ms sh' C' Cs e h l b)\n  then have sh: \"sh \\<unlhd>\\<^sub>s sh(C \\<mapsto> (sfs, Processing))\" by(simp add: shext_def)\n  then have cd: \"is_class P D\" using InitNonObjectSuperRed class_wf wf wf_cdecl_supD by blast\n  have sup': \"supercls_lst P (C # Cs)\" using InitNonObjectSuperRed.prems(3) by auto\n  then have sup: \"supercls_lst P (D # C # Cs)\"\n    using supercls_lst_app[of P C Cs D] subcls1I[OF InitNonObjectSuperRed.hyps(3,2)] by auto\n  have \"distinct (C # Cs)\" using InitNonObjectSuperRed.prems(3) by auto\n  then have dist: \"distinct (D # C # Cs)\"\n    using wf_supercls_distinct_app[OF wf InitNonObjectSuperRed.hyps(2-3) sup'] by simp\n  have \"P,E,h,sh' \\<turnstile> INIT C' (D # C # Cs,False) \\<leftarrow> e : T\"\n    using InitNonObjectSuperRed WTrt_shext_mono[OF _ sh] cd sup dist by auto\n  then show ?case by(rule_tac x = T in exI) simp\nnext\n  case (RedInitRInit C' C Cs e' h l sh b E T)\n  then obtain a sfs where C: \"class P C = \\<lfloor>a\\<rfloor>\" and proc: \"sh C = \\<lfloor>(sfs, Processing)\\<rfloor>\"\n    using WTrtInit by(auto simp: is_class_def)\n  then have T': \"P,E,h,sh \\<turnstile> C\\<bullet>\\<^sub>sclinit([]) : Void\" using wf_types_clinit[OF wf C] by simp\n  have \"P,E,h,sh \\<turnstile> RI (C,C\\<bullet>\\<^sub>sclinit([])) ; Cs \\<leftarrow> e' : T\"\n    using RedInitRInit by(auto intro: T')\n  then show ?case by(rule_tac x = T in exI) simp\nnext\n  case (RInitRed e h l sh b e' h' l' sh' b' C Cs e\\<^sub>0 E T)\n  then have \"(\\<And>E T. P,E \\<turnstile> (h, l, sh) \\<surd> \\<Longrightarrow> P,E,h,sh \\<turnstile> e : T \\<Longrightarrow> \\<exists>T'. P,E,h',sh' \\<turnstile> e' : T' \\<and> P \\<turnstile> T' \\<le> T)\"\n    by auto\n  then have \"\\<exists>T'. P,E,h',sh' \\<turnstile> e' : T'\" using RInitRed by blast\n  then obtain T' where e': \"P,E,h',sh' \\<turnstile> e' : T'\" by auto\n  have wt\\<^sub>0: \"P,E,h',sh' \\<turnstile> e\\<^sub>0 : T\"\n   using RInitRed by simp (auto intro: WTrt_hext_shext_mono[OF _ red_hext_incr red_shext_incr])\n  have nip: \"\\<forall>C' \\<in> set (C#Cs). not_init C' e' \\<and> (\\<exists>sfs. sh' C' = \\<lfloor>(sfs, Processing)\\<rfloor>)\"\n   using RInitRed red_proc_pres[OF wf_prog_wwf_prog[OF wf]] by auto\n  have shC: \"\\<exists>sfs. sh' C = \\<lfloor>(sfs, Processing)\\<rfloor> \\<or> sh' C = \\<lfloor>(sfs, Error)\\<rfloor> \\<and> e' = THROW NoClassDefFoundError\"\n    using RInitRed red_proc_pres[OF wf_prog_wwf_prog[OF wf] RInitRed.hyps(1)] by blast\n  have \"P,E,h',sh' \\<turnstile> RI (C,e') ; Cs \\<leftarrow> e\\<^sub>0 : T\" using RInitRed e' wt\\<^sub>0 nip shC by auto\n  then show ?case by(rule_tac x = T in exI) simp\nnext\n  case (RedRInit sh C sfs i sh' C' Cs v e h l b)\n  then have sh: \"sh \\<unlhd>\\<^sub>s sh(C \\<mapsto> (sfs, Done))\" by(auto simp: shext_def)\n  have wt: \"P,E,h,sh(C \\<mapsto> (sfs, Done)) \\<turnstile> e : T\"\n    using RedRInit WTrt_shext_mono[OF _ sh] by auto\n  have shC: \"\\<forall>C' \\<in> set(tl Cs). \\<exists>sfs. sh C' = \\<lfloor>(sfs, Processing)\\<rfloor>\" using RedRInit by(cases Cs, auto)\n  have \"P,E,h,sh' \\<turnstile> INIT C' (Cs,True) \\<leftarrow> e : T\" using RedRInit wt shC by(cases Cs, auto)\n  then show ?case by(rule_tac x = T in exI) simp\nnext\n  case (SCallThrowParams es vs e es' C M h l sh b)\n    then show ?case using map_Val_nthrow_neq[of _ vs e es'] by fastforce\nnext\n  case (RInitInitThrow sh C sfs i sh' a D Cs e h l b)\n  then have sh: \"sh \\<unlhd>\\<^sub>s sh(C \\<mapsto> (sfs, Error))\" by(auto simp: shext_def)\n  have wt: \"P,E,h,sh(C \\<mapsto> (sfs, Error)) \\<turnstile> e : T\"\n   using RInitInitThrow WTrt_shext_mono[OF _ sh] by clarsimp\n  then have \"P,E,h,sh' \\<turnstile> RI (D,Throw a) ; Cs \\<leftarrow> e : T\" using RInitInitThrow by auto\n  then show ?case by(rule_tac x = T in exI) simp\nqed fastforce+ (* esp all Throw propagation rules except RInitInit are dealt with here *)\n(*>*)\n\n\ncorollary subject_reduction:\n  \"\\<lbrakk> wf_J_prog P; P \\<turnstile> \\<langle>e,s,b\\<rangle> \\<rightarrow> \\<langle>e',s',b'\\<rangle>; P,E \\<turnstile> s \\<surd>; iconf (shp s) e; P,E,hp s,shp s \\<turnstile> e:T \\<rbrakk>\n  \\<Longrightarrow> \\<exists>T'. P,E,hp s',shp s' \\<turnstile> e':T' \\<and> P \\<turnstile> T' \\<le> T\"\n(*<*)by(cases s, cases s', fastforce dest:subject_reduction2)(*>*)\n\ncorollary subjects_reduction:\n  \"\\<lbrakk> wf_J_prog P; P \\<turnstile> \\<langle>es,s,b\\<rangle> [\\<rightarrow>] \\<langle>es',s',b'\\<rangle>; P,E \\<turnstile> s \\<surd>; iconfs (shp s) es; P,E,hp s,shp s \\<turnstile> es[:]Ts \\<rbrakk>\n  \\<Longrightarrow> \\<exists>Ts'. P,E,hp s',shp s' \\<turnstile> es'[:]Ts' \\<and> P \\<turnstile> Ts' [\\<le>] Ts\"\n(*<*)by(cases s, cases s', fastforce dest:subjects_reduction2)(*>*)\n\n\nsubsection \\<open> Lifting to @{text\"\\<rightarrow>*\"} \\<close>\n\ntext\\<open> Now all these preservation lemmas are first lifted to the transitive\nclosure \\dots \\<close>\n\nlemma Red_preserves_sconf:\nassumes wf: \"wf_J_prog P\" and Red: \"P \\<turnstile> \\<langle>e,s,b\\<rangle> \\<rightarrow>* \\<langle>e',s',b'\\<rangle>\"\nshows \"\\<And>T. \\<lbrakk> P,E,hp s,shp s \\<turnstile> e : T; iconf (shp s) e; P,E \\<turnstile> s \\<surd> \\<rbrakk> \\<Longrightarrow> P,E \\<turnstile> s' \\<surd>\"\n(*<*)\nusing Red\nproof (induct rule:converse_rtrancl_induct3)\n  case refl show ?case by fact\nnext\n  case (step e s b e' s' b')\n  obtain h l sh h' l' sh' where s:\"s = (h,l,sh)\" and s':\"s' = (h',l',sh')\"\n    by(cases s, cases s')\n  then have \"P \\<turnstile> \\<langle>e,(h,l,sh),b\\<rangle> \\<rightarrow> \\<langle>e',(h',l',sh'),b'\\<rangle>\" using step.hyps(1) by simp\n  then have iconf': \"iconf (shp s') e'\" using red_preserves_iconf[OF wf_prog_wwf_prog[OF wf]]\n    step.prems(2) s s' by simp\n  thus ?case using step\n    by(blast intro:red_preserves_sconf dest: subject_reduction[OF wf])\nqed\n(*>*)\n\nlemma Red_preserves_iconf:\nassumes wf: \"wwf_J_prog P\" and Red: \"P \\<turnstile> \\<langle>e,s,b\\<rangle> \\<rightarrow>* \\<langle>e',s',b'\\<rangle>\"\nshows \"iconf (shp s) e \\<Longrightarrow> iconf (shp s') e'\"\n(*<*)\nusing Red\nproof (induct rule:converse_rtrancl_induct3)\n  case refl show ?case by fact\nnext\n  case (step e s b e' s' b')\n  thus ?case using wf step by(cases s, cases s', simp) (blast intro:red_preserves_iconf)\nqed\n(*>*)\n\nlemma Reds_preserves_iconf:\nassumes wf: \"wwf_J_prog P\" and Red: \"P \\<turnstile> \\<langle>es,s,b\\<rangle> [\\<rightarrow>]* \\<langle>es',s',b'\\<rangle>\"\nshows \"iconfs (shp s) es \\<Longrightarrow> iconfs (shp s') es'\"\n(*<*)\nusing Red\nproof (induct rule:converse_rtrancl_induct3)\n  case refl show ?case by fact\nnext\n  case (step e s b e' s' b')\n  thus ?case using wf step by(cases s, cases s', simp) (blast intro:reds_preserves_iconf)\nqed\n(*>*)\n\nlemma Red_preserves_bconf:\nassumes wf: \"wwf_J_prog P\" and Red: \"P \\<turnstile> \\<langle>e,s,b\\<rangle> \\<rightarrow>* \\<langle>e',s',b'\\<rangle>\"\nshows \"iconf (shp s) e \\<Longrightarrow> P,(shp s) \\<turnstile>\\<^sub>b (e,b) \\<surd> \\<Longrightarrow> P,(shp s') \\<turnstile>\\<^sub>b (e'::expr,b') \\<surd>\"\n(*<*)\nusing Red\nproof (induct rule:converse_rtrancl_induct3)\n  case refl show ?case by fact\nnext\n  case (step e s1 b e' s2 b')\n  then have \"iconf (shp s2) e'\" using step red_preserves_iconf[OF wf]\n   by(cases s1, cases s2) auto\n  thus ?case using step by(cases s1, cases s2, simp) (blast intro:red_preserves_bconf)\nqed\n(*>*)\n\nlemma Reds_preserves_bconf:\nassumes wf: \"wwf_J_prog P\" and Red: \"P \\<turnstile> \\<langle>es,s,b\\<rangle> [\\<rightarrow>]* \\<langle>es',s',b'\\<rangle>\"\nshows \"iconfs (shp s) es \\<Longrightarrow> P,(shp s) \\<turnstile>\\<^sub>b (es,b) \\<surd> \\<Longrightarrow> P,(shp s') \\<turnstile>\\<^sub>b (es'::expr list,b') \\<surd>\"\n(*<*)\nusing Red\nproof (induct rule:converse_rtrancl_induct3)\n  case refl show ?case by fact\nnext\n  case (step es s1 b es' s2 b')\n  then have \"iconfs (shp s2) es'\" using step reds_preserves_iconf[OF wf]\n   by(cases s1, cases s2) auto\n  thus ?case using step by(cases s1, cases s2, simp) (blast intro:reds_preserves_bconf)\nqed\n(*>*)\n\nlemma Red_preserves_defass:\nassumes wf: \"wf_J_prog P\" and reds: \"P \\<turnstile> \\<langle>e,s,b\\<rangle> \\<rightarrow>* \\<langle>e',s',b'\\<rangle>\"\nshows \"\\<D> e \\<lfloor>dom(lcl s)\\<rfloor> \\<Longrightarrow> \\<D> e' \\<lfloor>dom(lcl s')\\<rfloor>\"\nusing reds\nproof (induct rule:converse_rtrancl_induct3)\n  case refl thus ?case .\nnext\n  case (step e s b e' s' b') thus ?case\n    by(cases s,cases s')(auto dest:red_preserves_defass[OF wf])\nqed\n\n\nlemma Red_preserves_type:\nassumes wf: \"wf_J_prog P\" and Red: \"P \\<turnstile> \\<langle>e,s,b\\<rangle> \\<rightarrow>* \\<langle>e',s',b'\\<rangle>\"\nshows \"!!T. \\<lbrakk> P,E \\<turnstile> s\\<surd>; iconf (shp s) e; P,E,hp s,shp s \\<turnstile> e:T \\<rbrakk>\n    \\<Longrightarrow> \\<exists>T'. P \\<turnstile> T' \\<le> T \\<and> P,E,hp s',shp s' \\<turnstile> e':T'\"\n(*<*)\nusing Red\nproof (induct rule:converse_rtrancl_induct3)\n  case refl thus ?case by blast\nnext\n  case step thus ?case\n    by(blast intro:widen_trans red_preserves_sconf Red_preserves_iconf[OF wf_prog_wwf_prog[OF wf]]\n             dest:subject_reduction[OF wf])\nqed\n(*>*)\n\n\nsubsection \"The final polish\"\n\ntext\\<open> The above preservation lemmas are now combined and packed nicely. \\<close>\n\ndefinition wf_config :: \"J_prog \\<Rightarrow> env \\<Rightarrow> state \\<Rightarrow> expr \\<Rightarrow> ty \\<Rightarrow> bool\"   (\"_,_,_ \\<turnstile> _ : _ \\<surd>\"   [51,0,0,0,0]50)\nwhere\n  \"P,E,s \\<turnstile> e:T \\<surd>  \\<equiv>  P,E \\<turnstile> s \\<surd> \\<and> iconf (shp s) e \\<and> P,E,hp s,shp s \\<turnstile> e:T\"\n\ntheorem Subject_reduction: assumes wf: \"wf_J_prog P\"\nshows \"P \\<turnstile> \\<langle>e,s,b\\<rangle> \\<rightarrow> \\<langle>e',s',b'\\<rangle> \\<Longrightarrow> P,E,s \\<turnstile> e : T \\<surd>\n       \\<Longrightarrow> \\<exists>T'. P,E,s' \\<turnstile> e' : T' \\<surd> \\<and> P \\<turnstile> T' \\<le> T\"\n(*<*)\nby(cases s, cases s')\n  (force simp: wf_config_def\n         elim:red_preserves_sconf red_preserves_iconf[OF wf_prog_wwf_prog[OF wf]]\n         dest:subject_reduction[OF wf])\n(*>*)\n\n\ntheorem Subject_reductions:\nassumes wf: \"wf_J_prog P\" and reds: \"P \\<turnstile> \\<langle>e,s,b\\<rangle> \\<rightarrow>* \\<langle>e',s',b'\\<rangle>\"\nshows \"\\<And>T. P,E,s \\<turnstile> e:T \\<surd> \\<Longrightarrow> \\<exists>T'. P,E,s' \\<turnstile> e':T' \\<surd> \\<and> P \\<turnstile> T' \\<le> T\"\n(*<*)\nusing reds\nproof (induct rule:converse_rtrancl_induct3)\n  case refl thus ?case by blast\nnext\n  case step thus ?case\n    by(blast dest:Subject_reduction[OF wf] intro:widen_trans)\nqed\n(*>*)\n\n\ncorollary Progress: assumes wf: \"wf_J_prog P\"\nshows \"\\<lbrakk> P,E,s  \\<turnstile> e : T \\<surd>; \\<D> e \\<lfloor>dom(lcl s)\\<rfloor>; P,shp s \\<turnstile>\\<^sub>b (e,b) \\<surd>; \\<not> final e \\<rbrakk>\n   \\<Longrightarrow> \\<exists>e' s' b'. P \\<turnstile> \\<langle>e,s,b\\<rangle> \\<rightarrow> \\<langle>e',s',b'\\<rangle>\"\n(*<*)\nusing progress[OF wf_prog_wwf_prog[OF wf]]\nby(cases b) (auto simp:wf_config_def sconf_def)\n(*>*)\n\ncorollary TypeSafety:\nfixes s::state and e::expr\nassumes wf: \"wf_J_prog P\" and sconf: \"P,E \\<turnstile> s \\<surd>\" and wt: \"P,E \\<turnstile> e::T\"\n  and \\<D>: \"\\<D> e \\<lfloor>dom(lcl s)\\<rfloor>\"\n  and iconf: \"iconf (shp s) e\" and bconf: \"P,(shp s) \\<turnstile>\\<^sub>b (e,b) \\<surd>\"\n  and steps: \"P \\<turnstile> \\<langle>e,s,b\\<rangle> \\<rightarrow>* \\<langle>e',s',b'\\<rangle>\"\n  and nstep: \"\\<not>(\\<exists>e'' s'' b''. P \\<turnstile> \\<langle>e',s',b'\\<rangle> \\<rightarrow> \\<langle>e'',s'',b''\\<rangle>)\"\nshows \"(\\<exists>v. e' = Val v \\<and> P,hp s' \\<turnstile> v :\\<le> T) \\<or>\n      (\\<exists>a. e' = Throw a \\<and> a \\<in> dom(hp s'))\"\n(*<*)\nproof -\n  have wwf: \"wwf_J_prog P\" by(rule wf_prog_wwf_prog[OF wf])\n  have wfc: \"P,E,s \\<turnstile> e:T \\<surd>\" using WT_implies_WTrt[OF wt] sconf iconf\n    by(simp add:wf_config_def)\n  obtain T' where wfc': \"P,E,s' \\<turnstile> e' : T' \\<surd>\" and T': \"P \\<turnstile> T' \\<le> T\"\n    using Subject_reductions[OF wf steps wfc] by clarsimp\n  have \\<D>': \"\\<D> e' \\<lfloor>dom (lcl s')\\<rfloor>\"\n    by(rule Red_preserves_defass[OF wf steps \\<D>])\n  have bconf': \"P,(shp s') \\<turnstile>\\<^sub>b (e',b') \\<surd>\"\n    by(rule Red_preserves_bconf[OF wwf steps iconf bconf])\n  have fin': \"final e'\" using Progress[OF wf wfc' \\<D>' bconf'] nstep by blast\n  then show ?thesis using wfc wfc' T'\n    by(fastforce simp:wf_config_def final_def conf_def)\nqed\n(*>*)\n\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/JinjaDCI/J/TypeSafe.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526514141571, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.27158017776866955}}
{"text": "theory TickTock_UntimedPrefix\n  imports TickTock_Prefix TickTock_ExtChoice TickTock_Basic_Ops\nbegin\n\nsubsection \\<open>Instantaneous (Untimed) Prefix\\<close>\n\ndefinition UntimedPrefixTT :: \"'e \\<Rightarrow> 'e ttprocess \\<Rightarrow> 'e ttprocess\" (infixr \"\\<rightarrow>\\<^sub>U\" 61) where\n  \"e \\<rightarrow>\\<^sub>U P = (e \\<rightarrow>\\<^sub>C P \\<box>\\<^sub>C STOP\\<^sub>U)\"\n\nlemma UntimedPrefixTT_def2:\n  \"e \\<rightarrow>\\<^sub>U P = {t. t = [] \\<or> (\\<exists> X. Event e \\<notin> X \\<and> t = [[X]\\<^sub>R]) \\<or> (\\<exists> \\<sigma>\\<in>P. t = [[Event e]\\<^sub>E] @ \\<sigma>)}\"\n  unfolding UntimedPrefixTT_def PrefixTT_def ExtChoiceTT_def UntimedStopTT_def\nproof (safe, simp_all)\n  fix \\<sigma>\n  assume \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C []\" \"\\<sigma> \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\"\n  then show \"\\<sigma> = []\"\n    by (erule_tac x=\\<sigma> in ballE, simp_all add: tt_prefix_antisym tt_prefix_refl tocks_tt_subset2 tt_subset_refl)\nnext\n  fix \\<sigma>\n  assume \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C []\" \"\\<sigma> \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\"\n  then show \"\\<sigma> = []\"\n    by (erule_tac x=\\<sigma> in ballE, simp_all add: tt_prefix_antisym tt_prefix_refl tocks_tt_subset2 tt_subset_refl)\nnext\n  fix sa X\n  assume \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C sa @ [[X]\\<^sub>R] \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C []\" \"sa \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\"\n  then show \"sa \\<noteq> [] \\<Longrightarrow> False\"\n    apply (erule_tac x=sa in ballE, simp add: tt_prefix_antisym tt_prefix_concat)\n    using tocks_tt_subset2 tt_subset_refl by blast\nnext\n  fix \\<rho> \\<sigma> \\<tau> :: \"'a tttrace\" and X :: \"'a ttevent set\"\n  assume \"\\<rho> @ \\<tau> = [[X]\\<^sub>R]\" \"\\<rho> \\<in> tocks UNIV\"\n  then show \"\\<rho> = []\"\n    by (cases \\<rho> rule:ttWF.cases, auto simp add: notin_tocks)\nnext\n  fix \\<rho> \\<sigma> \\<tau> :: \"'a tttrace\" and X :: \"'a ttevent set\"\n  assume \"\\<rho> @ \\<tau> = [[X]\\<^sub>R]\" \"\\<rho> \\<in> tocks UNIV\"\n  then show \"\\<rho> = []\"\n    by (cases \\<rho> rule:ttWF.cases, auto simp add: notin_tocks)\nnext\n  fix \\<rho> \\<sigma> \\<tau> :: \"'a tttrace\" and X :: \"'a ttevent set\"\n  assume \"\\<rho> @ \\<tau> = [[X]\\<^sub>R]\" \"\\<rho> \\<in> tocks UNIV\"\n  then show \"\\<rho> = []\"\n    by (cases \\<rho> rule:ttWF.cases, auto simp add: notin_tocks)\nnext\n  fix \\<rho> \\<sigma> \\<tau> :: \"'a tttrace\" and X :: \"'a ttevent set\"\n  assume \"\\<rho> @ \\<tau> = [[X]\\<^sub>R]\" \"\\<rho> \\<in> tocks UNIV\"\n  then show \"\\<rho> = []\"\n    by (cases \\<rho> rule:ttWF.cases, auto simp add: notin_tocks)\nnext\n  fix \\<rho> \\<sigma> \\<tau> :: \"'a tttrace\" and X :: \"'a ttevent set\"\n  assume \"\\<rho> @ \\<tau> = [[X]\\<^sub>R]\" \"\\<rho> \\<in> tocks UNIV\"\n  then show \"\\<rho> = []\"\n    by (cases \\<rho> rule:ttWF.cases, auto simp add: notin_tocks)\nnext\n  fix \\<rho> \\<sigma> \\<tau> :: \"'a tttrace\" and X :: \"'a ttevent set\"\n  assume \"\\<rho> @ \\<tau> = [[X]\\<^sub>R]\" \"\\<rho> \\<in> tocks UNIV\"\n  then show \"\\<rho> = []\"\n    by (cases \\<rho> rule:ttWF.cases, auto simp add: notin_tocks)\nnext\n  fix \\<rho> \\<sigma> \\<tau> :: \"'a tttrace\" and X :: \"'a ttevent set\"\n  assume \"\\<rho> @ \\<tau> = [[X]\\<^sub>R]\" \"\\<rho> \\<in> tocks UNIV\"\n  then show \"\\<rho> = []\"\n    by (cases \\<rho> rule:ttWF.cases, auto simp add: notin_tocks)\nnext\n  fix \\<rho> \\<sigma> \\<tau> :: \"'a tttrace\" and X :: \"'a ttevent set\"\n  assume \"\\<rho> @ \\<tau> = [[X]\\<^sub>R]\" \"\\<rho> \\<in> tocks UNIV\"\n  then show \"\\<rho> = []\"\n    by (cases \\<rho> rule:ttWF.cases, auto simp add: notin_tocks)\nnext\n  fix \\<rho> \\<sigma> \\<tau> :: \"'a tttrace\" and X :: \"'a ttevent set\"\n  assume \\<rho>_\\<sigma>_in_tocks: \"\\<rho> @ \\<sigma> \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\"\n  assume \\<rho>_longest_tocks_sigma: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n  assume \"\\<rho> @ \\<tau> = [[X]\\<^sub>R]\" \"\\<rho> \\<in> tocks UNIV\"\n  then have \"\\<rho> = []\"\n    by (cases \\<rho> rule:ttWF.cases, auto simp add: notin_tocks)\n  then have \"\\<sigma> \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e} \\<and> \\<rho> = []\"\n    using \\<rho>_\\<sigma>_in_tocks by auto\n  then show \"\\<sigma> = []\"\n    by (metis (full_types) \\<rho>_longest_tocks_sigma append_Nil self_extension_tt_prefix tocks_tt_subset2 tt_prefix_refl tt_subset_refl)\nnext\n  fix \\<rho> \\<sigma> \\<tau> s :: \"'a tttrace\" and X Xa :: \"'a ttevent set\"\n  assume \\<rho>_longest_tocks_\\<sigma>: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C s @ [[Xa]\\<^sub>R] \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<rho>_in_tocks: \"\\<rho> \\<in> tocks UNIV\" and s_in_tocks: \"s \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\"\n  assume \\<rho>_\\<tau>_def: \"\\<rho> @ \\<tau> = [[X]\\<^sub>R]\" and \\<rho>_\\<sigma>_def: \"\\<rho> @ \\<sigma> = s @ [[Xa]\\<^sub>R]\"\n\n  have \"\\<rho> = []\"\n    using \\<rho>_in_tocks \\<rho>_\\<tau>_def by (induct \\<rho> rule:ttWF.induct, auto simp add: notin_tocks)\n  then have \"s = []\"\n    by (metis (full_types) \\<rho>_longest_tocks_\\<sigma> neq_Nil_conv s_in_tocks tocks_subset top_greatest tt_prefix.simps(3) tt_prefix_concat)\n  then show \"s \\<noteq> [] \\<Longrightarrow> \\<sigma> = []\"\n    by auto\nnext\n  fix \\<rho> \\<sigma> \\<tau> :: \"'a tttrace\" and X :: \"'a ttevent set\"\n  assume \\<rho>_longest_tocks_\\<tau>: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C [[X]\\<^sub>R] \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<tau>_refusal_imp_\\<sigma>_refusal: \"\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<rho>_in_tocks: \"\\<rho> \\<in> tocks UNIV\" and \\<rho>_\\<sigma>_in_tocks: \"\\<rho> @ \\<sigma> \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\"\n  assume \\<rho>_\\<tau>_def: \"\\<rho> @ \\<tau> = [[X]\\<^sub>R]\"\n\n  have \\<rho>_empty: \"\\<rho> = []\"\n    using \\<rho>_\\<tau>_def \\<rho>_in_tocks append_eq_Cons_conv in_tocks_last by fastforce\n  then have \\<tau>_refusal: \"\\<tau> = [[X]\\<^sub>R]\"\n    using \\<rho>_\\<tau>_def by auto\n  then obtain Y where \\<sigma>_refusal: \"\\<sigma> = [[Y]\\<^sub>R]\"\n    using \\<tau>_refusal_imp_\\<sigma>_refusal by auto\n  then have \"[[X]\\<^sub>R] \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\"\n    using \\<rho>_\\<sigma>_in_tocks end_refusal_notin_tocks by blast\n  then have False\n    using refusal_notin_tocks by blast\n  then show \"\\<tau> = []\"\n    by auto\nnext\n  fix \\<rho> \\<sigma> \\<tau> :: \"'a tttrace\" and X :: \"'a ttevent set\"\n  assume \\<rho>_longest_tocks_\\<tau>: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C [[X]\\<^sub>R] \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<tau>_refusal_imp_\\<sigma>_refusal: \"\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<rho>_in_tocks: \"\\<rho> \\<in> tocks UNIV\" and \\<rho>_\\<sigma>_in_tocks: \"\\<rho> @ \\<sigma> \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\"\n  assume \\<rho>_\\<tau>_def: \"\\<rho> @ \\<tau> = [[X]\\<^sub>R]\"\n\n  have \\<rho>_empty: \"\\<rho> = []\"\n    using \\<rho>_\\<tau>_def \\<rho>_in_tocks append_eq_Cons_conv in_tocks_last by fastforce\n  then have \\<tau>_refusal: \"\\<tau> = [[X]\\<^sub>R]\"\n    using \\<rho>_\\<tau>_def by auto\n  then obtain Y where \\<sigma>_refusal: \"\\<sigma> = [[Y]\\<^sub>R]\"\n    using \\<tau>_refusal_imp_\\<sigma>_refusal by auto\n  then have \"[[X]\\<^sub>R] \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\"\n    using \\<rho>_\\<sigma>_in_tocks end_refusal_notin_tocks by blast\n  then have False\n    using refusal_notin_tocks by blast\n  then show \"\\<tau> = []\"\n    by auto\nnext\n  fix \\<rho> \\<sigma> \\<tau> :: \"'a tttrace\" and X :: \"'a ttevent set\"\n  assume \\<rho>_longest_tocks_\\<tau>: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C [[X]\\<^sub>R] \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<tau>_refusal_imp_\\<sigma>_refusal: \"\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<rho>_in_tocks: \"\\<rho> \\<in> tocks UNIV\" and \\<rho>_\\<sigma>_in_tocks: \"\\<rho> @ \\<sigma> \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\"\n  assume \\<rho>_\\<tau>_def: \"\\<rho> @ \\<tau> = [[X]\\<^sub>R]\"\n\n  have \\<rho>_empty: \"\\<rho> = []\"\n    using \\<rho>_\\<tau>_def \\<rho>_in_tocks append_eq_Cons_conv in_tocks_last by fastforce\n  then have \\<tau>_refusal: \"\\<tau> = [[X]\\<^sub>R]\"\n    using \\<rho>_\\<tau>_def by auto\n  then obtain Y where \\<sigma>_refusal: \"\\<sigma> = [[Y]\\<^sub>R]\"\n    using \\<tau>_refusal_imp_\\<sigma>_refusal by auto\n  then have \"[[X]\\<^sub>R] \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\"\n    using \\<rho>_\\<sigma>_in_tocks end_refusal_notin_tocks by blast\n  then have False\n    using refusal_notin_tocks by blast\n  then show \"\\<sigma> = []\"\n    by auto\nnext\n  fix \\<rho> \\<sigma> \\<tau> s :: \"'a tttrace\" and X Xa :: \"'a ttevent set\"\n  assume \\<rho>_longest_tocks_\\<tau>: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C [[X]\\<^sub>R] \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<tau>_refusal_imp_\\<sigma>_refusal: \"\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<rho>_in_tocks: \"\\<rho> \\<in> tocks UNIV\" and \\<rho>_\\<sigma>_in_tocks: \"s \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\"\n  assume \\<rho>_\\<tau>_def: \"\\<rho> @ \\<tau> = [[X]\\<^sub>R]\" and \\<rho>_\\<sigma>_def: \"\\<rho> @ \\<sigma> = s @ [[Xa]\\<^sub>R]\"\n  assume e_in_X: \"Event e \\<in> X\" and e_in_Xa: \"Event e \\<notin> Xa\"\n\n  have \\<rho>_empty: \"\\<rho> = []\"\n    using \\<rho>_\\<tau>_def \\<rho>_in_tocks append_eq_Cons_conv in_tocks_last by fastforce\n  have \\<tau>_refusal: \"\\<tau> = [[X]\\<^sub>R]\"\n    using \\<rho>_empty \\<rho>_\\<tau>_def by auto\n  have \\<sigma>_refusal: \"\\<sigma> = [[Xa]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Xa) \\<or> e = Tock)\"\n    using \\<rho>_\\<sigma>_def \\<tau>_refusal \\<tau>_refusal_imp_\\<sigma>_refusal by auto\n  then have \"Event e \\<in> Xa\"\n    using e_in_X by blast\n  then have \"False\"\n    using e_in_Xa by blast\n  then show \"\\<tau> = []\"\n    by auto\nnext\n  fix \\<sigma> s \\<sigma>' :: \"'a tttrace\"\n  assume \\<rho>_longest_tocks_\\<sigma>: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C s @ [Event e]\\<^sub>E # \\<sigma>' \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C []\"\n  assume s_in_tocks: \"s \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\"\n  assume \\<rho>_\\<sigma>_assm: \"\\<forall>\\<sigma>\\<in>P. s @ [Event e]\\<^sub>E # \\<sigma>' \\<noteq> [Event e]\\<^sub>E # \\<sigma>\"\n  assume \\<sigma>'_in_P: \"\\<sigma>' \\<in> P\"\n\n  have \"s = []\"\n    by (meson \\<rho>_longest_tocks_\\<sigma> s_in_tocks tocks_subset top_greatest tt_prefix.simps(1) tt_prefix_antisym tt_prefix_concat)\n  then show \"False\"\n    using \\<rho>_\\<sigma>_assm \\<sigma>'_in_P by blast\nnext\n  fix \\<rho> \\<sigma> \\<tau> s \\<sigma>' :: \"'a tttrace\" and X :: \"'a ttevent set\"\n  assume \\<rho>_longest_tocks_\\<sigma>: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C s @ [Event e]\\<^sub>E # \\<sigma>' \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<rho>_in_tocks: \"\\<rho> \\<in> tocks UNIV\" and  s_in_tocks: \"s \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\"\n  assume \\<rho>_\\<tau>_def: \"\\<rho> @ \\<tau> = [[X]\\<^sub>R]\"\n  assume \\<rho>_\\<sigma>_assm: \"\\<forall>\\<sigma>\\<in>P. s @ [Event e]\\<^sub>E # \\<sigma>' \\<noteq> [Event e]\\<^sub>E # \\<sigma>\"\n  assume \\<sigma>'_in_P: \"\\<sigma>' \\<in> P\"\n\n  have \"\\<rho> = []\"\n    by (metis Cons_eq_append_conv \\<rho>_\\<tau>_def \\<rho>_in_tocks append_Nil2 append_is_Nil_conv refusal_notin_tocks)\n  then have \"s = []\"\n    by (metis (mono_tags) \\<rho>_longest_tocks_\\<sigma> s_in_tocks tocks_subset top_greatest tt_prefix.simps(1) tt_prefix_antisym tt_prefix_concat)\n  then show \" \\<sigma> = []\"\n    using \\<rho>_\\<sigma>_assm \\<sigma>'_in_P by blast\nnext\n  fix \\<rho> \\<sigma> \\<tau> s \\<sigma>' :: \"'a tttrace\" and X :: \"'a ttevent set\"\n  assume \\<rho>_longest_tocks_\\<sigma>: \"\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C s @ [Event e]\\<^sub>E # \\<sigma>' \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>\"\n  assume \\<rho>_in_tocks: \"\\<rho> \\<in> tocks UNIV\" and  s_in_tocks: \"s \\<in> tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}\"\n  assume \\<tau>_refusal_imp_\\<sigma>_refusal: \"\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))\"\n  assume \\<rho>_\\<tau>_def: \"\\<rho> @ \\<tau> = [[X]\\<^sub>R]\" and \\<rho>_\\<sigma>_def: \"\\<rho> @ \\<sigma> = s @ [Event e]\\<^sub>E # \\<sigma>'\" \n  assume \\<sigma>'_in_P: \"\\<sigma>' \\<in> P\"\n\n  have \\<rho>_empty: \"\\<rho> = []\"\n    by (metis Cons_eq_append_conv \\<rho>_\\<tau>_def \\<rho>_in_tocks append_Nil2 append_is_Nil_conv refusal_notin_tocks)\n  then have \"s = []\"\n    by (metis (mono_tags) \\<rho>_longest_tocks_\\<sigma> s_in_tocks tocks_subset top_greatest tt_prefix.simps(1) tt_prefix_antisym tt_prefix_concat)\n  also have \"\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R]\"\n    using \\<rho>_\\<tau>_def \\<rho>_empty \\<tau>_refusal_imp_\\<sigma>_refusal by auto\n  then have False\n    using calculation \\<rho>_\\<sigma>_def by (simp add: \\<rho>_empty)\n  then show \"\\<tau> = []\"\n    by blast\nnext\n  show \"\\<exists>\\<rho>\\<in>tocks UNIV.\n       \\<exists>\\<sigma>. ((\\<exists>s\\<in>tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}. \\<rho> @ \\<sigma> = s \\<or> (\\<exists>X. Tock \\<notin> X \\<and> Event e \\<notin> X \\<and> \\<rho> @ \\<sigma> = s @ [[X]\\<^sub>R])) \\<or>\n            (\\<exists>s\\<in>tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}. \\<rho> @ \\<sigma> = s \\<or> (\\<exists>\\<sigma>'\\<in>P. \\<rho> @ \\<sigma> = s @ [Event e]\\<^sub>E # \\<sigma>'))) \\<and>\n           (\\<exists>\\<tau>. (\\<rho> = [] \\<and> \\<tau> = [] \\<or> (\\<exists>X. \\<rho> @ \\<tau> = [[X]\\<^sub>R])) \\<and>\n                (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                (\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                (\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and> (\\<rho> = [] \\<and> \\<sigma> = [] \\<or> \\<rho> = [] \\<and> \\<tau> = []))\"\n    by (rule_tac x=\"[]\" in bexI, rule_tac x=\"[]\" in exI, auto simp add: tocks.intros)\nnext\n  fix X\n  assume \"Event e \\<notin> X\"\n  then show \"\\<exists>\\<rho>\\<in>tocks UNIV.\n            \\<exists>\\<sigma>. ((\\<exists>s\\<in>tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}. \\<rho> @ \\<sigma> = s \\<or> (\\<exists>X. Tock \\<notin> X \\<and> Event e \\<notin> X \\<and> \\<rho> @ \\<sigma> = s @ [[X]\\<^sub>R])) \\<or>\n                 (\\<exists>s\\<in>tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}. \\<rho> @ \\<sigma> = s \\<or> (\\<exists>\\<sigma>'\\<in>P. \\<rho> @ \\<sigma> = s @ [Event e]\\<^sub>E # \\<sigma>'))) \\<and>\n                (\\<exists>\\<tau>. (\\<rho> = [] \\<and> \\<tau> = [] \\<or> (\\<exists>X. \\<rho> @ \\<tau> = [[X]\\<^sub>R])) \\<and>\n                     (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                     (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                     (\\<forall>X. \\<sigma> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                     (\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and> ([[X]\\<^sub>R] = \\<rho> @ \\<sigma> \\<or> [[X]\\<^sub>R] = \\<rho> @ \\<tau>))\"\n    apply (rule_tac x=\"[]\" in bexI, auto)\n    apply (rule_tac x=\"[[{x\\<in>X. x \\<noteq> Tock}]\\<^sub>R]\" in exI, safe, simp_all add: tocks.intros)\n    apply (rule_tac x=\"[[X]\\<^sub>R]\" in exI, auto)\n    using refusal_notin_tocks tt_prefix_notfront_is_whole by force+\nnext\n  fix \\<sigma>\n  assume \"\\<sigma> \\<in> P\"\n  then show \"\\<exists>\\<rho>\\<in>tocks UNIV.\n            \\<exists>\\<sigma>'. ((\\<exists>s\\<in>tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}. \\<rho> @ \\<sigma>' = s \\<or> (\\<exists>X. Tock \\<notin> X \\<and> Event e \\<notin> X \\<and> \\<rho> @ \\<sigma>' = s @ [[X]\\<^sub>R])) \\<or>\n                  (\\<exists>s\\<in>tocks {x. x \\<noteq> Tock \\<and> x \\<noteq> Event e}. \\<rho> @ \\<sigma>' = s \\<or> (\\<exists>\\<sigma>\\<in>P. \\<rho> @ \\<sigma>' = s @ [Event e]\\<^sub>E # \\<sigma>))) \\<and>\n                 (\\<exists>\\<tau>. (\\<rho> = [] \\<and> \\<tau> = [] \\<or> (\\<exists>X. \\<rho> @ \\<tau> = [[X]\\<^sub>R])) \\<and>\n                      (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<sigma>' \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                      (\\<forall>\\<rho>'\\<in>tocks UNIV. \\<rho>' \\<le>\\<^sub>C \\<rho> @ \\<tau> \\<longrightarrow> \\<rho>' \\<le>\\<^sub>C \\<rho>) \\<and>\n                      (\\<forall>X. \\<sigma>' = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<tau> = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                      (\\<forall>X. \\<tau> = [[X]\\<^sub>R] \\<longrightarrow> (\\<exists>Y. \\<sigma>' = [[Y]\\<^sub>R] \\<and> (\\<forall>e. (e \\<in> X) = (e \\<in> Y) \\<or> e = Tock))) \\<and>\n                      ([Event e]\\<^sub>E # \\<sigma> = \\<rho> @ \\<sigma>' \\<or> [Event e]\\<^sub>E # \\<sigma> = \\<rho> @ \\<tau>))\"\n    apply (rule_tac x=\"[]\" in bexI, auto)\n    apply (rule_tac x=\"[Event e]\\<^sub>E # \\<sigma>\" in exI, safe, simp_all add: tocks.intros)\n    apply (erule_tac x=\"[]\" in ballE, safe, simp_all add: tocks.intros, blast)\n    by (rule_tac x=\"[]\" in exI, auto, metis tocks.simps tt_prefix.simps(2) tt_prefix_refl ttobs.simps(4))\nqed\n\nend", "meta": {"author": "UoY-RoboStar", "repo": "tick-tock-CSP", "sha": "7186d2e7f70116589850112a7353bc521372c913", "save_path": "github-repos/isabelle/UoY-RoboStar-tick-tock-CSP", "path": "github-repos/isabelle/UoY-RoboStar-tick-tock-CSP/tick-tock-CSP-7186d2e7f70116589850112a7353bc521372c913/TickTock/TickTock_UntimedPrefix.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6370307944803832, "lm_q2_score": 0.4263215925474903, "lm_q1q2_score": 0.27157998280467}}
{"text": "theory GeneralKnowledge imports ValueOntology (** Benzmüller, Fuenmayor & Lomfeld, 2021 **)  \nbegin (*** General Legal and World Knowledge (LWK) ***)\n(*LWK: kinds of situations addressed*)\nconsts appObject::\\<sigma>  appAnimal::\\<sigma> (*appropriation of objects/animals in general*)\n       appWildAnimal::\\<sigma>  appDomAnimal::\\<sigma> (*appropriation of wild/domestic animals*)\n(*LWK: postulates for kinds of situations*)\naxiomatization where \n W1: \"\\<lfloor>appAnimal \\<^bold>\\<rightarrow> appObject\\<rfloor>\" and\n W2: \"\\<lfloor>\\<^bold>\\<not>(appWildAnimal \\<^bold>\\<and> appDomAnimal)\\<rfloor>\" and \n W3: \"\\<lfloor>appWildAnimal \\<^bold>\\<rightarrow> appAnimal\\<rfloor>\"  and\n W4: \"\\<lfloor>appDomAnimal \\<^bold>\\<rightarrow> appAnimal\\<rfloor>\"\n(*LWK: (prima facie) value preferences for kinds of situations*)\naxiomatization where \n R1: \"\\<lfloor>appAnimal \\<^bold>\\<rightarrow> ([STAB\\<^sup>p] \\<^bold>\\<prec> [STAB\\<^sup>d])\\<rfloor>\" and  \n R2: \"\\<lfloor>appWildAnimal \\<^bold>\\<rightarrow> ([WILL\\<^sup>x\\<inverse>] \\<^bold>\\<prec> [STAB\\<^sup>x])\\<rfloor>\" and         \n R3: \"\\<lfloor>appDomAnimal  \\<^bold>\\<rightarrow> ([STAB\\<^sup>x\\<inverse>] \\<^bold>\\<prec> [RELI\\<^sup>x\\<^bold>\\<oplus>RESP\\<^sup>x])\\<rfloor>\"\n(*LWK: domain vocabulary*)\ntypedecl e    (*declares new type for 'entities'*)\nconsts \n  Animal::\"e\\<Rightarrow>\\<sigma>\" Domestic::\"e\\<Rightarrow>\\<sigma>\" Fox::\"e\\<Rightarrow>\\<sigma>\" Parrot::\"e\\<Rightarrow>\\<sigma>\" Pet::\"e\\<Rightarrow>\\<sigma>\" FreeRoaming::\"e\\<Rightarrow>\\<sigma>\" \n(*LWK: domain knowledge (about animals)*)\naxiomatization where \n W5: \"\\<lfloor>\\<^bold>\\<forall>a. Fox a \\<^bold>\\<rightarrow> Animal a\\<rfloor>\"  and  \n W6: \"\\<lfloor>\\<^bold>\\<forall>a. Parrot a \\<^bold>\\<rightarrow> Animal a\\<rfloor>\" and\n W7: \"\\<lfloor>\\<^bold>\\<forall>a. (Animal a \\<^bold>\\<and> FreeRoaming a \\<^bold>\\<and> \\<^bold>\\<not>Pet a) \\<^bold>\\<rightarrow> \\<^bold>\\<not>Domestic a\\<rfloor>\" and\n W8: \"\\<lfloor>\\<^bold>\\<forall>a. Animal a \\<^bold>\\<and> Pet a \\<^bold>\\<rightarrow> Domestic a\\<rfloor>\"\n(*LWK: legally-relevant, situational 'factors'*)\nconsts Own::\"c\\<Rightarrow>\\<sigma>\"    (*object is owned by party c*)\n       Poss::\"c\\<Rightarrow>\\<sigma>\"   (*party c has actual possession of object*)\n       Intent::\"c\\<Rightarrow>\\<sigma>\" (*party c has intention to possess object*)\n       Mal::\"c\\<Rightarrow>\\<sigma>\" (*party c acts out of malice*)\n       Mtn::\"c\\<Rightarrow>\\<sigma>\" (*party c respons. for maintenance of object*)\n(*LWK: meaning postulates for general notions*)\naxiomatization where\n W9: \"\\<lfloor>Poss x \\<^bold>\\<rightarrow> (\\<^bold>\\<not>Poss x\\<inverse>)\\<rfloor>\" and \n W10: \"\\<lfloor>Own x \\<^bold>\\<rightarrow> (\\<^bold>\\<not>Own x\\<inverse>)\\<rfloor>\"\n(*LWK: conditional value preferences, e.g. from precedents*)\naxiomatization where \n R4: \"\\<lfloor>(Mal x\\<inverse> \\<^bold>\\<and> Own x)  \\<^bold>\\<rightarrow> ([STAB\\<^sup>x\\<inverse>] \\<^bold>\\<prec> [RESP\\<^sup>x\\<^bold>\\<oplus>RELI\\<^sup>x])\\<rfloor>\"\n(*LWK: relate values, outcomes and situational 'factors'*)\naxiomatization where \n F1: \"Promotes (Intent x) (For x) WILL\\<^sup>x\" and\n F2: \"Promotes (Mal x) (For x\\<inverse>) RESP\\<^sup>x\" and  \n F3: \"Promotes (Poss x) (For x) STAB\\<^sup>x\" and\n F4: \"Promotes (Mtn x) (For x) RESP\\<^sup>x\" and  \n F5: \"Promotes (Own x) (For x) RELI\\<^sup>x\"\n(*Theory is consistent, (non-trivial) model found*)\nlemma True nitpick[satisfy,card \\<iota>=4] oops\nend\n\n", "meta": {"author": "cbenzmueller", "repo": "LogiKEy", "sha": "5c16bdeb68bf8131e24ba9c8d774d4af663cb2cf", "save_path": "github-repos/isabelle/cbenzmueller-LogiKEy", "path": "github-repos/isabelle/cbenzmueller-LogiKEy/LogiKEy-5c16bdeb68bf8131e24ba9c8d774d4af663cb2cf/Preference-Logics/EncodingLegalBalancing/GeneralKnowledge.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318337259584, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.2714025177952416}}
{"text": "(*  Title:      HOL/HOLCF/IOA/NTP/Abschannel.thy\n    Author:     Olaf Müller\n*)\n\nsection {* The (faulty) transmission channel (both directions) *}\n\ntheory Abschannel\nimports IOA Action\nbegin\n\ndatatype 'a abs_action = S 'a | R 'a\n\ndefinition\n  ch_asig :: \"'a abs_action signature\" where\n  \"ch_asig = (UN b. {S(b)}, UN b. {R(b)}, {})\"\n\ndefinition\n  ch_trans :: \"('a abs_action, 'a multiset)transition set\" where\n  \"ch_trans =\n    {tr. let s = fst(tr);\n             t = snd(snd(tr))\n         in\n         case fst(snd(tr))\n           of S(b) => t = addm s b |\n              R(b) => count s b ~= 0 & t = delm s b}\"\n\ndefinition\n  ch_ioa :: \"('a abs_action, 'a multiset)ioa\" where\n  \"ch_ioa = (ch_asig, {{|}}, ch_trans,{},{})\"\n\ndefinition\n  rsch_actions :: \"'m action => bool abs_action option\" where\n  \"rsch_actions (akt) =\n          (case akt of\n           S_msg(m) => None |\n            R_msg(m) => None |\n           S_pkt(packet) => None |\n            R_pkt(packet) => None |\n            S_ack(b) => Some(S(b)) |\n            R_ack(b) => Some(R(b)) |\n           C_m_s =>  None  |\n           C_m_r =>  None |\n           C_r_s =>  None  |\n           C_r_r(m) => None)\"\n\ndefinition\n  srch_actions :: \"'m action =>(bool * 'm) abs_action option\" where\n  \"srch_actions (akt) =\n          (case akt of\n           S_msg(m) => None |\n            R_msg(m) => None |\n           S_pkt(p) => Some(S(p)) |\n            R_pkt(p) => Some(R(p)) |\n            S_ack(b) => None |\n            R_ack(b) => None |\n           C_m_s => None |\n           C_m_r => None |\n           C_r_s => None |\n           C_r_r(m) => None)\"\n\ndefinition\n  srch_ioa :: \"('m action, 'm packet multiset)ioa\" where\n  \"srch_ioa = rename ch_ioa srch_actions\"\n\ndefinition\n  rsch_ioa :: \"('m action, bool multiset)ioa\" where\n  \"rsch_ioa = rename ch_ioa rsch_actions\"\n\ndefinition\n  srch_asig :: \"'m action signature\" where\n  \"srch_asig = asig_of(srch_ioa)\"\n\ndefinition\n  rsch_asig :: \"'m action signature\" where\n  \"rsch_asig = asig_of(rsch_ioa)\"\n\ndefinition\n  srch_wfair :: \"('m action)set set\" where\n  \"srch_wfair = wfair_of(srch_ioa)\"\ndefinition\n  srch_sfair :: \"('m action)set set\" where\n  \"srch_sfair = sfair_of(srch_ioa)\"\ndefinition\n  rsch_sfair :: \"('m action)set set\" where\n  \"rsch_sfair = sfair_of(rsch_ioa)\"\ndefinition\n  rsch_wfair :: \"('m action)set set\" where\n  \"rsch_wfair = wfair_of(rsch_ioa)\"\n\ndefinition\n  srch_trans :: \"('m action, 'm packet multiset)transition set\" where\n  \"srch_trans = trans_of(srch_ioa)\"\ndefinition\n  rsch_trans :: \"('m action, bool multiset)transition set\" where\n  \"rsch_trans = trans_of(rsch_ioa)\"\n\n\nlemmas unfold_renaming =\n  srch_asig_def rsch_asig_def rsch_ioa_def srch_ioa_def ch_ioa_def\n  ch_asig_def srch_actions_def rsch_actions_def rename_def rename_set_def asig_of_def\n  actions_def srch_trans_def rsch_trans_def ch_trans_def starts_of_def\n  trans_of_def asig_projections\n\nlemma in_srch_asig: \n     \"S_msg(m) ~: actions(srch_asig)        &     \n       R_msg(m) ~: actions(srch_asig)        &     \n       S_pkt(pkt) : actions(srch_asig)    &     \n       R_pkt(pkt) : actions(srch_asig)    &     \n       S_ack(b) ~: actions(srch_asig)     &     \n       R_ack(b) ~: actions(srch_asig)     &     \n       C_m_s ~: actions(srch_asig)           &     \n       C_m_r ~: actions(srch_asig)           &     \n       C_r_s ~: actions(srch_asig)  & C_r_r(m) ~: actions(srch_asig)\"\n  by (simp add: unfold_renaming)\n\nlemma in_rsch_asig: \n      \"S_msg(m) ~: actions(rsch_asig)         &  \n       R_msg(m) ~: actions(rsch_asig)         &  \n       S_pkt(pkt) ~: actions(rsch_asig)    &  \n       R_pkt(pkt) ~: actions(rsch_asig)    &  \n       S_ack(b) : actions(rsch_asig)       &  \n       R_ack(b) : actions(rsch_asig)       &  \n       C_m_s ~: actions(rsch_asig)            &  \n       C_m_r ~: actions(rsch_asig)            &  \n       C_r_s ~: actions(rsch_asig)            &  \n       C_r_r(m) ~: actions(rsch_asig)\"\n  by (simp add: unfold_renaming)\n\nlemma srch_ioa_thm: \"srch_ioa =  \n    (srch_asig, {{|}}, srch_trans,srch_wfair,srch_sfair)\"\napply (simp (no_asm) add: srch_asig_def srch_trans_def asig_of_def trans_of_def wfair_of_def sfair_of_def srch_wfair_def srch_sfair_def)\napply (simp (no_asm) add: unfold_renaming)\ndone\n\nlemma rsch_ioa_thm: \"rsch_ioa =  \n     (rsch_asig, {{|}}, rsch_trans,rsch_wfair,rsch_sfair)\"\napply (simp (no_asm) add: rsch_asig_def rsch_trans_def asig_of_def trans_of_def wfair_of_def sfair_of_def rsch_wfair_def rsch_sfair_def)\napply (simp (no_asm) add: unfold_renaming)\ndone\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/HOLCF/IOA/NTP/Abschannel.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318337259583, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.27140251779524155}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\n(* License: BSD, terms see file ./LICENSE *)\n\ntheory ArrayAssertion\n\nimports\n  \"$L4V_ARCH/ArchArraysMemInstance\"\n  \"StructSupport\"\n\nbegin\n\nlemma array_tag_n_eq:\n  \"(array_tag_n n :: ('a :: c_type['b :: finite]) field_desc typ_desc) =\n  TypDesc (TypAggregate\n    (map (\\<lambda>n. DTPair (adjust_ti (typ_info_t TYPE('a)) (\\<lambda>x. index x n)\n            (\\<lambda>x f. Arrays.update f n x)) (replicate n CHR ''1'')) [0..<n]))\n  (typ_name (typ_uinfo_t TYPE('a)) @ ''_array_'' @ nat_to_bin_string (card (UNIV :: 'b :: finite set)))\"\n  apply (induct n)\n   apply (simp add: typ_info_array array_tag_def eval_nat_numeral array_tag_n.simps empty_typ_info_def)\n   apply (simp add: typ_info_array array_tag_def eval_nat_numeral array_tag_n.simps empty_typ_info_def)\n   apply (simp add: ti_typ_combine_def Let_def)\n   done\n\nlemma typ_info_array':\n  \"typ_info_t TYPE ('a :: c_type['b :: finite]) =\n  TypDesc (TypAggregate\n    (map (\\<lambda>n. DTPair (adjust_ti (typ_info_t TYPE('a)) (\\<lambda>x. index x n)\n            (\\<lambda>x f. Arrays.update f n x)) (replicate n CHR ''1'')) [0..<(card (UNIV :: 'b :: finite set))]))\n  (typ_name (typ_uinfo_t TYPE('a)) @ ''_array_'' @ nat_to_bin_string (card (UNIV :: 'b :: finite set)))\"\n  by (simp add: typ_info_array array_tag_def array_tag_n_eq)\n\ndefinition\n  \"uinfo_array_tag_n_m (v :: 'a itself) n m = TypDesc\n    (TypAggregate (map (\\<lambda>i. DTPair (typ_uinfo_t TYPE('a)) (replicate i CHR ''1'')) [0 ..< n]))\n    (typ_name (typ_uinfo_t TYPE('a :: c_type)) @ ''_array_'' @ nat_to_bin_string m)\"\n\nlemma map_td_list_map:\n  \"map_td_list f = map (map_td_pair f)\"\n  by (rule ext, rename_tac x) (induct_tac x, simp_all)\n\nlemma uinfo_array_tag_n_m_eq:\n  \"n \\<le> CARD('b)\n    \\<Longrightarrow> export_uinfo (array_tag_n n :: (('a :: wf_type)['b :: finite]) field_desc typ_desc)\n        = uinfo_array_tag_n_m TYPE ('a) n (CARD('b))\"\n  apply (clarsimp simp: uinfo_array_tag_n_m_def array_tag_n_eq map_td_list_map\n                        o_def adjust_ti_def map_td_map typ_uinfo_t_def export_uinfo_def)\n  apply (fastforce intro: map_td_extI simp: field_norm_blah)\n  done\n\nlemma typ_uinfo_array_tag_n_m_eq:\n  \"typ_uinfo_t TYPE (('a :: wf_type)['b :: finite])\n        = uinfo_array_tag_n_m TYPE ('a) (CARD('b)) (CARD('b))\"\n  by (simp add: typ_uinfo_t_def typ_info_array array_tag_def uinfo_array_tag_n_m_eq)\n\ntext \\<open>Alternative to h_t_valid for arrays. This allows reasoning\nabout arrays of variable width.\\<close>\ndefinition h_t_array_valid :: \"heap_typ_desc \\<Rightarrow> ('a :: c_type) ptr \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"h_t_array_valid htd ptr n = valid_footprint htd (ptr_val ptr) (uinfo_array_tag_n_m TYPE ('a) n n)\"\n\ntext \\<open>Assertion that pointer p is within an array that continues for at least n more elements.\\<close>\ndefinition\n  \"array_assertion (p :: ('a :: c_type) ptr) n htd\n    = (\\<exists>q i j. h_t_array_valid htd q j\n        \\<and> p = CTypesDefs.ptr_add q (int i) \\<and> i < j \\<and> i + n \\<le> j)\"\n\nlemma array_assertion_shrink_right:\n  \"array_assertion p n htd \\<Longrightarrow> n' \\<le> n \\<Longrightarrow> array_assertion p n' htd\"\n  by (fastforce simp: array_assertion_def)\n\nlemma array_assertion_shrink_leftD:\n  \"array_assertion p n htd \\<Longrightarrow> j < n \\<Longrightarrow> array_assertion (CTypesDefs.ptr_add p (int j)) (n - j) htd\"\n  apply (clarsimp simp: array_assertion_def)\n  apply (rule exI, rule_tac x=\"i + j\" in exI, rule exI, erule conjI)\n  apply (simp add: CTypesDefs.ptr_add_def field_simps)\n  done\n\nlemma array_assertion_shrink_leftI:\n  \"array_assertion (CTypesDefs.ptr_add p (- (int j))) (n + j) htd\n    \\<Longrightarrow> n \\<noteq> 0 \\<Longrightarrow> array_assertion p n htd\"\n  apply (drule_tac j=j in array_assertion_shrink_leftD, simp)\n  apply (simp add: CTypesDefs.ptr_add_def)\n  done\n\nlemma h_t_array_valid:\n  \"h_t_valid htd gd (p :: (('a :: wf_type)['b :: finite]) ptr)\n    \\<Longrightarrow> h_t_array_valid htd (ptr_coerce p :: 'a ptr) (CARD('b))\"\n  by (clarsimp simp: h_t_valid_def h_t_array_valid_def typ_uinfo_array_tag_n_m_eq)\n\nlemma array_ptr_valid_array_assertionD:\n  \"h_t_valid htd gd (p :: (('a :: wf_type)['b :: finite]) ptr)\n    \\<Longrightarrow> array_assertion (ptr_coerce p :: 'a ptr) (CARD('b)) htd\"\n  apply (clarsimp simp: array_assertion_def dest!: h_t_array_valid)\n  apply (fastforce intro: exI[where x=0])\n  done\n\nlemma array_ptr_valid_array_assertionI:\n  \"h_t_valid htd gd (q :: (('a :: wf_type)['b :: finite]) ptr)\n    \\<Longrightarrow> q = ptr_coerce p\n    \\<Longrightarrow> n \\<le> CARD('b)\n    \\<Longrightarrow> array_assertion (p :: 'a ptr) n htd\"\n  by (auto dest: array_ptr_valid_array_assertionD\n           simp: array_assertion_shrink_right)\n\ntext \\<open>Derived from array_assertion, an appropriate assertion for performing\na pointer addition, or for dereferencing a pointer addition (the strong case).\n\nIn either case, there must be an array connecting the two ends of the pointer\ntransition, with the caveat that the last address can be just out of the array\nif the pointer is not dereferenced, thus the strong/weak distinction.\n\nIf the pointer doesn't actually move, nothing is learned.\n\\<close>\ndefinition ptr_add_assertion :: \"('a :: c_type) ptr \\<Rightarrow> int \\<Rightarrow> bool \\<Rightarrow> heap_typ_desc \\<Rightarrow> bool\" where\n  \"ptr_add_assertion ptr offs strong htd \\<equiv>\n    offs = 0 \\<or>\n    array_assertion (if offs < 0 then CTypesDefs.ptr_add ptr offs else ptr)\n                    (if offs < 0 then nat (- offs) else if strong then Suc (nat offs) else nat offs)\n                    htd\"\n\nlemma ptr_add_assertion_positive:\n  \"offs \\<ge> 0 \\<Longrightarrow> ptr_add_assertion ptr offs strong htd\n    = (offs = 0 \\<or> array_assertion ptr (case strong of True \\<Rightarrow> Suc (nat offs)\n        | False \\<Rightarrow> nat offs) htd)\"\n  by (simp add: ptr_add_assertion_def)\n\nlemma ptr_add_assertion_negative:\n  \"offs < 0 \\<Longrightarrow> ptr_add_assertion ptr offs strong htd\n    = array_assertion (CTypesDefs.ptr_add ptr offs) (nat (- offs)) htd\"\n  by (simp add: ptr_add_assertion_def)\n\nlemma ptr_add_assertion_uint[simp]:\n  \"ptr_add_assertion ptr (uint offs) strong htd\n    = (offs = 0 \\<or> array_assertion ptr\n        (case strong of True \\<Rightarrow> Suc (unat offs) | False \\<Rightarrow> unat offs) htd)\"\n  by (simp add: ptr_add_assertion_positive uint_0_iff unat_def\n         split: bool.split)\n\ntext \\<open>Ignore char and void pointers. The C standard specifies that arithmetic on\nchar and void pointers doesn't create any special checks.\\<close>\n\ndefinition ptr_add_assertion' :: \"('a :: c_type) ptr \\<Rightarrow> int \\<Rightarrow> bool \\<Rightarrow> heap_typ_desc \\<Rightarrow> bool\" where\n  \"ptr_add_assertion' ptr offs strong htd =\n     (typ_uinfo_t TYPE('a) = typ_uinfo_t TYPE(word8)\n      \\<or> typ_uinfo_t TYPE ('a) = typ_uinfo_t TYPE(unit)\n      \\<or> ptr_add_assertion ptr offs strong htd)\"\n\n(* Useful for clearing away these assumptions. *)\nlemma td_diff_from_typ_name:\n  \"typ_name td \\<noteq> typ_name td' \\<Longrightarrow> td \\<noteq> td'\"\n  by clarsimp\n\nlemma typ_name_void:\n  \"typ_name (typ_uinfo_t TYPE(unit)) = ''unit''\"\n by (simp add: typ_uinfo_t_def)\n\nlemmas ptr_add_assertion' = ptr_add_assertion'_def td_diff_from_typ_name typ_name_void\n\ntext \\<open>Mechanism for retyping a range of memory to a non-constant array size.\\<close>\n\ndefinition ptr_arr_retyps :: \"nat \\<Rightarrow> ('a :: c_type) ptr \\<Rightarrow> heap_typ_desc \\<Rightarrow> heap_typ_desc\" where\n  \"ptr_arr_retyps n p \\<equiv>\n    htd_update_list (ptr_val p)\n        (map (\\<lambda>i. list_map (typ_slice_t (uinfo_array_tag_n_m TYPE('a) n n) i))\n             [0..<n * size_of TYPE('a)])\"\n\nlemma ptr_arr_retyps_to_retyp:\n  \"n = CARD('b :: finite)\n    \\<Longrightarrow> ptr_arr_retyps n (p :: ('c :: wf_type) ptr) = ptr_retyp (ptr_coerce p :: ('c['b]) ptr)\"\n  by (auto simp: ptr_arr_retyps_def ptr_retyp_def typ_slices_def typ_uinfo_array_tag_n_m_eq)\n\nend\n", "meta": {"author": "CompSoftVer", "repo": "CSim2", "sha": "b09a4d77ea089168b1805db5204ac151df2b9eff", "save_path": "github-repos/isabelle/CompSoftVer-CSim2", "path": "github-repos/isabelle/CompSoftVer-CSim2/CSim2-b09a4d77ea089168b1805db5204ac151df2b9eff/CParser/tools/c-parser/umm_heap/ArrayAssertion.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.603931819468636, "lm_q2_score": 0.4493926344647597, "lm_q1q2_score": 0.271402511388106}}
{"text": "theory combine2\n  imports combine1\nbegin\n\ndefinition proper' :: \"estate \\<Rightarrow> bool \" where\n\"proper' schs = ((properp (run_now schs) (run_prior schs)) \\<and> (pool schs) = [])\"\n\ndefinition propc' :: \"nat \\<Rightarrow> estate \\<Rightarrow> estate \\<Rightarrow> bool\" where\n\"propc' k schs task_es = (k>0 \\<longrightarrow>(status task_es = RUNNING \\<longleftrightarrow> run_now schs = 2))\"\n\n\n\nfun combine2 :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> estate ext_state \\<Rightarrow> estate ext_state \\<Rightarrow> estate ext_state \\<Rightarrow> estate tassn\" where\n  \"combine2 0 k1 k2 (Sch p rn rp,ss) (Task st1 ent1 tp1,ts1) (Task st2 ent2 tp2,ts2) = emp\\<^sub>t\"\n| \"combine2 (Suc k) 0 0 (Sch p rn rp, ss) (Task st1 ent1 tp1, ts1) (Task st2 ent2 tp2, ts2)  = false\\<^sub>A\"\n| \"combine2 (Suc k) 0 (Suc k2) (Sch p rn rp, ss) (Task st1 ent1 tp1, ts1) (Task WAIT ent2 tp2, ts2) = \n   (\\<up> (9 / 200 - ts2 T = 0) \\<and>\\<^sub>t combine2 (Suc k) 0 k2 (Sch p rn rp, ss) (Task st1 ent1 tp1, ts1) (Task READY ezero tp2, ts2(T:=0)))\"\n| \"combine2 (Suc k) 0 (Suc k2) (Sch p rn rp, ss) (Task st1 ent1 tp1, ts1) (Task READY ent2 tp2, ts2) = (\n     (\\<up> (rn = -1) \\<and>\\<^sub>t (combine2 k 0 k2 (Sch p 2 1, ss(Pr := 1)) (Task st1 ent1 tp1, ts1) (Task RUNNING ent2 tp2, ts2(T := ts2 T, F := 0))))\n  \\<or>\\<^sub>t (\\<up> (k > 0 \\<and> 9 / 200 - ts2 T = 0) \\<and>\\<^sub>t (combine2 (k-1) 0 k2 (Sch p rn rp, ss(Pr := 1, G := 0)) (Task st1 ent1 tp1, ts1) (Task WAIT ent2 tp2, ts2(T := 9 / 200)))))\"\n| \"combine2 (Suc k) 0 (Suc k2) (Sch p rn rp, ss) (Task st1 ent1 tp1, ts1) (Task RUNNING ent2 tp2, ts2) = \n     combine2 k 0 k2 (Sch [] (- 1) (- 1), ss(G := 0)) (Task st1 ent1 tp1, ts1) (Task WAIT eone tp2, ts2(C := C_upd ent2 (ts2 C)))\"\n| \"combine2 (Suc k) (Suc k1) 0 (Sch p rn rp, ss) (Task WAIT ent1 tp1, ts1) (Task st2 ent2 tp2, ts2) = \n   (\\<up> (9 / 200 - ts1 T = 0) \\<and>\\<^sub>t combine2 (Suc k) k1 0 (Sch p rn rp, ss) (Task READY ezero tp1, ts1(T:=0)) (Task st2 ent2 tp2, ts2))\"\n| \"combine2 (Suc k) (Suc k1) 0 (Sch p rn rp, ss) (Task READY ent1 tp1, ts1) (Task st2 ent2 tp2, ts2) = \n   (\\<up> (rn = -1) \\<and>\\<^sub>t combine2 k k1 0 (Sch p 1 2, ss(Pr := 2)) (Task RUNNING ent1 tp1, ts1(F := 0)) (Task st2 ent2 tp2, ts2))\"\n| \"combine2 (Suc k) (Suc k1) 0 (Sch p rn rp, ss) (Task RUNNING ent1 tp1, ts1) (Task st2 ent2 tp2, ts2) = \n     combine2 k k1 0 (Sch [] (- 1) (- 1), ss(G := 0)) (Task WAIT eone tp1, ts1(C := C_upd ent1 (ts1 C))) (Task st2 ent2 tp2, ts2)\"\n| \"combine2 (Suc k) (Suc k1) (Suc k2) (Sch p rn rp, ss) (Task WAIT ent1 tp1, ts1) (Task WAIT ent2 tp2, ts2) = (\n  (\\<up> (ts1 T = ts2 T) \\<and>\\<^sub>t Wait\\<^sub>t (9 / 200 - ts1 T)\n      (\\<lambda>t. ParState (ParState (EState (Sch p rn rp, ss))\n              (EState (Task WAIT ent1 tp1, ts1(T := ts1 T + t))))\n              (EState (Task WAIT ent2 tp2, ts2(T := ts2 T + t))))\n      ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) @\\<^sub>t\n      (combine2 (Suc k) k1 k2 (Sch p rn rp, ss) (Task READY ezero tp1, ts1(T := 0)) (Task READY ezero tp2, ts2(T := 0))))\n\\<or>\\<^sub>t (\\<up> (ts2 T < ts1 T) \\<and>\\<^sub>t Wait\\<^sub>t (9 / 200 - ts1 T)\n     (\\<lambda>t. ParState (ParState (EState (Sch p rn rp, ss))\n              (EState (Task WAIT ent1 2, ts1(T := ts1 T + t))))\n              (EState (Task WAIT ent2 1, ts2(T := ts2 T + t))))\n     ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) @\\<^sub>t\n      (combine2 (Suc k) k1 (Suc k2) (Sch p rn rp, ss) (Task READY ezero 2, ts1(T := 0)) (Task WAIT ent2 tp2, ts2(T:=ts2 T + (0.045 - ts1 T)))))\n\\<or>\\<^sub>t (\\<up> (ts1 T < ts2 T) \\<and>\\<^sub>t Wait\\<^sub>t (9 / 200 - ts2 T)\n     (\\<lambda>t. ParState (ParState (EState (Sch p rn rp, ss))\n             (EState (Task WAIT ent1 2, ts1(T := ts1 T + t))))\n             (EState (Task WAIT ent2 1, ts2(T := ts2 T + t))))\n     ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) @\\<^sub>t\n    (combine2 (Suc k) (Suc k1) k2 (Sch p rn rp, ss) (Task WAIT ent1 tp1, ts1(T:=ts1 T + (0.045 - ts2 T))) (Task READY ezero tp2, ts2(T := 0))))\n)\"\n| \"combine2 (Suc k) (Suc k1) (Suc k2) (Sch p rn rp, ss) (Task WAIT ent1 tp1, ts1) (Task READY ent2 tp2, ts2) = (\n  (\\<up> (9 / 200 - ts1 T = 0) \\<and>\\<^sub>t (combine2 (Suc k) k1 (Suc k2) (Sch p rn rp, ss) (Task READY ezero tp1, ts1(T := 0)) (Task READY ent2 tp2, ts2)))\n\\<or>\\<^sub>t(\\<up> (9 / 200 - ts1 T > 0) \\<and>\\<^sub>t (combine2 k (Suc k1) k2 (Sch p 2 1, ss(Pr := 1)) (Task WAIT ent1 tp1, ts1) (Task RUNNING ent2 tp2, ts2(F := 0))))\n)\"\n| \"combine2 (Suc k) (Suc k1) (Suc k2) (Sch p rn rp, ss) (Task WAIT ent1 tp1, ts1) (Task RUNNING ent2 tp2, ts2) = (\n  (\\<up> (min (45 / 10 ^ 3 - ts2 T) (2 / 10\\<^sup>2 - C_upd ent2 (ts2 C)) \\<ge> (9 / 200 - ts1 T))\n   \\<and>\\<^sub>t  Wait\\<^sub>t (9 / 200 - ts1 T)\n        (\\<lambda>t. ParState (ParState (EState (Sch p rn rp, ss))\n                (EState (Task WAIT ent1 tp1, ts1(T := ts1 T + t))))\n                (EState (Task RUNNING eone tp2, ts2(T := ts2 T + t, C := C_upd ent2 (ts2 C) + t))))\n        ({},{preempt_ch 2, req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1,exit_ch 2}) @\\<^sub>t \n    combine2 (Suc k) k1 (Suc k2) (Sch p rn rp, ss) (Task READY ezero tp1, ts1(T := 0)) (Task RUNNING eone tp2, ts2(T:= ts2 T + (9 / 200 - ts1 T), C:= C_upd ent2 (ts2 C) + (9 / 200 - ts1 T))))\n\\<or>\\<^sub>t(\\<up> (min (45 / 10 ^ 3 - ts2 T) (2 / 10\\<^sup>2 - C_upd ent2 (ts2 C)) < (9 / 200 - ts1 T))\n   \\<and>\\<^sub>t  Wait\\<^sub>t (min (9 / 200 - ts2 T) (1 / 50 - C_upd ent2 (ts2 C)))\n     (\\<lambda>t. ParState(ParState (EState (Sch p rn rp, ss))\n             (EState (Task WAIT ent1 tp1, ts1(T := ts1 T + t))))\n             (EState(Task RUNNING eone tp2, ts2(T := ts2 T + t, C := C_upd ent2 (ts2 C) + t))))\n     ({},{preempt_ch 2, req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) @\\<^sub>t \n    (combine2 k (Suc k1) k2 (Sch [] (- 1) (- 1), ss(G := 0)) \n     (Task WAIT ent1 tp1, ts1(T := ts1 T + min (9 / 200 - ts2 T) (1 / 50 - C_upd ent2 (ts2 C))))\n     (Task WAIT eone tp2, ts2(T := ts2 T + min (9 / 200 - ts2 T) (1 / 50 - C_upd ent2 (ts2 C)),\n         C := C_upd ent2 (ts2 C) + min (9 / 200 - ts2 T) (1 / 50 - C_upd ent2 (ts2 C))))))\n)\"\n| \"combine2 (Suc k) (Suc k1) (Suc k2) (Sch p rn rp, ss) (Task READY ent1 tp1, ts1) (Task WAIT ent2 tp2, ts2) = (\n  (\\<up> (9 / 200 - ts2 T = 0) \\<and>\\<^sub>t (combine2 (Suc k) (Suc k1) k2 (Sch p rn rp, ss) (Task READY ent1 tp1, ts1) (Task READY ezero tp2, ts2(T := 0))))\n\\<or>\\<^sub>t(\\<up> (9 / 200 - ts2 T > 0) \\<and>\\<^sub>t (combine2 k k1 (Suc k2) (Sch p 1 2, ss(Pr := 2)) (Task RUNNING ent1 tp1, ts1(F := 0)) (Task WAIT ent2 tp2, ts2)))\n)\"\n| \"combine2 (Suc k) (Suc k1) (Suc k2) (Sch p rn rp, ss) (Task READY ent1 tp1, ts1) (Task READY ent2 tp2, ts2) = (\n   combine2 k k1 (Suc k2) (Sch p 1 2, ss(Pr := 2)) (Task RUNNING ent1 tp1, ts1(F := 0)) (Task READY ent2 tp2, ts2)\n\\<or>\\<^sub>t combine2 k (Suc k1) k2 (Sch p 2 1, ss(Pr := 1)) (Task READY ent1 tp1, ts1) (Task RUNNING ent2 tp2, ts2(F := 0))\n)\"\n| \"combine2 (Suc k) (Suc k1) (Suc k2) (Sch p rn rp, ss) (Task READY ent1 tp1, ts1) (Task RUNNING ent2 tp2, ts2) = (\n  (combine2 k k1 k2 (Sch p 1 2, ss(Pr := 2)) (Task RUNNING ent1 tp1, ts1(F := 0)) (Task READY eone tp2, ts2(C := C_upd ent2 (ts2 C), F := 0)))\n\\<or>\\<^sub>t(\\<up> (min (9 / 200 - ts2 T) (1 / 50 - C_upd ent2 (ts2 C)) = 0) \\<and>\\<^sub>t\n    combine2 k k1 k2 (Sch p 1 2, ss(Pr := 2)) (Task RUNNING ent1 tp1, ts1(F := 0))(Task WAIT eone tp2, ts2(C := C_upd ent2 (ts2 C), F := 0)))\n\\<or>\\<^sub>t(\\<up> (min (9 / 200 - ts2 T) (1 / 50 - C_upd ent2 (ts2 C)) = 0) \\<and>\\<^sub>t    \n    combine2 k (Suc k1) k2 (Sch [] (- 1) (- 1), ss(G := 0)) (Task READY ent1 tp1, ts1) (Task WAIT eone tp2, ts2(C := C_upd ent2 (ts2 C))))\n)\"\n| \"combine2 (Suc k) (Suc k1) (Suc k2) (Sch p rn rp, ss) (Task RUNNING ent1 tp1, ts1) (Task WAIT ent2 tp2, ts2) = (\n  (\\<up> (min (9 / 200 - ts1 T) (1 / 100 - C_upd ent1 (ts1 C)) \\<ge> (9 / 200 - ts2 T)) \n        \\<and>\\<^sub>t Wait\\<^sub>t (9 / 200 - ts2 T)\n     (\\<lambda>t. ParState(ParState (EState (Sch p rn rp, ss))\n             (EState(Task RUNNING eone tp1, ts1(T := ts1 T + t, C := C_upd ent1 (ts1 C) + t))))\n             (EState (Task WAIT ent2 tp2, ts2(T := ts2 T + t))))\n     ({},{preempt_ch 1, req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) @\\<^sub>t\n   combine2 (Suc k) (Suc k1) k2 (Sch p rn rp, ss) (Task RUNNING eone tp1, ts1(T:= ts1 T + (9 / 200 - ts2 T), C:= C_upd ent1 (ts1 C) + (9 / 200 - ts2 T))) (Task READY ezero tp2, ts2(T := 0)))\n\\<or>\\<^sub>t(\\<up> ((9 / 200 - ts2 T) > min (9 / 200 - ts1 T) (1 / 100 - C_upd ent1 (ts1 C))) \n        \\<and>\\<^sub>t Wait\\<^sub>t (min (9 / 200 - ts1 T) (1 / 100 - C_upd ent1 (ts1 C)))\n     (\\<lambda>t. ParState(ParState (EState (Sch p rn rp, ss))\n             (EState(Task RUNNING eone tp1, ts1(T := ts1 T + t, C := C_upd ent1 (ts1 C) + t))))\n             (EState (Task WAIT ent2 tp2, ts2(T := ts2 T + t))))\n     ({},{preempt_ch 1, req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) @\\<^sub>t\n(combine2 k k1 (Suc k2) (Sch [] (- 1) (- 1), ss(G := 0))\n       (Task WAIT eone tp1, ts1(T := ts1 T + min (9 / 200 - ts1 T) (1 / 100 - C_upd ent1 (ts1 C)),\n         C := C_upd ent1 (ts1 C) + min (9 / 200 - ts1 T) (1 / 100 - C_upd ent1 (ts1 C))))\n       (Task WAIT ent2 tp2, ts2(T:= ts2 T + min (9 / 200 - ts1 T) (1 / 100 - C_upd ent1 (ts1 C))))))\n)\"\n| \"combine2 (Suc k) (Suc k1) (Suc k2) (Sch p rn rp, ss) (Task RUNNING ent1 tp1, ts1) (Task READY ent2 tp2, ts2) = (\n   (\\<up> (min (9 / 200 - ts1 T) (1 / 100 - C_upd ent1 (ts1 C)) = 0) \\<and>\\<^sub>t\n       (combine2 k k1 (Suc k2) (Sch [] (- 1) (- 1), ss(G := 0)) (Task WAIT eone tp1, ts1(C := C_upd ent1 (ts1 C))) (Task READY ent2 tp2, ts2)))\n\\<or>\\<^sub>t (\\<up> (min (9 / 200 - ts1 T) (1 / 100 - C_upd ent1 (ts1 C)) \\<le> 9 / 200 - ts2 T \\<and> k > 0) \\<and>\\<^sub>t\n    Wait\\<^sub>t (min (9 / 200 - ts1 T) (1 / 100 - C_upd ent1 (ts1 C)))\n     (\\<lambda>t. ParState(ParState (EState (Sch [(1, 2)] 1 2, ss(Pr := 1)))\n             (EState (Task RUNNING eone tp1, ts1(T := ts1 T + t, C := C_upd ent1 (ts1 C) + t))))\n             (EState (Task READY ent2 tp2, ts2(T := ts2 T + t))))\n     ({}, {run_ch 2, preempt_ch 1, req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) @\\<^sub>t \n     (combine2 (k-1) k1 k2 (Sch [] 2 1, ss(Pr := 1, G := 0))\n       (Task WAIT eone tp1, ts1\n        (T := ts1 T + min (9 / 200 - ts1 T) (1 / 100 - C_upd ent1 (ts1 C)),\n         C := C_upd ent1 (ts1 C) + min (9 / 200 - ts1 T) (1 / 100 - C_upd ent1 (ts1 C))))\n       (Task RUNNING ent2 tp2, ts2(T := ts2 T + min (9 / 200 - ts1 T) (1 / 100 - C_upd ent1 (ts1 C)), F := 0))))\n\\<or>\\<^sub>t (\\<up> (min (9 / 200 - ts1 T) (1 / 100 - C_upd ent1 (ts1 C)) \\<ge> 9 / 200 - ts2 T \\<and> k > 0) \\<and>\\<^sub>t\n    Wait\\<^sub>t (9 / 200 - ts2 T)\n     (\\<lambda>t. ParState\n           (ParState (EState (Sch [(1, 2)] 1 2, ss(Pr := 1)))\n             (EState (Task RUNNING eone tp1, ts1(T := ts1 T + t, C := C_upd ent1 (ts1 C) + t))))\n           (EState (Task READY ent2 tp2, ts2(T := ts2 T + t))))\n     ({}, {run_ch 2, preempt_ch 1, req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) @\\<^sub>t\n     (combine2 (k-1) (Suc k1) k2 (Sch [] 1 2, ss(Pr := 1, G := 0))\n       (Task RUNNING eone tp1, ts1(T := ts1 T + (9 / 200 - ts2 T), C := C_upd ent1 (ts1 C) + (9 / 200 - ts2 T)))\n       (Task WAIT ent2 tp2, ts2(T := 9 / 200))))\n)\"\n| \"combine2 (Suc k) (Suc k1) (Suc k2) (Sch p rn rp, ss) (Task RUNNING ent1 tp1, ts1) (Task RUNNING ent2 tp2, ts2) = false\\<^sub>A\"\n\n\nlemma combine_assn_in0_emp:\n  \"ch \\<in> chs \\<Longrightarrow> combine_assn chs (in_0assn ch v @\\<^sub>t P) emp\\<^sub>t = false\\<^sub>A\"\n  unfolding combine_assn_def\n  apply (rule ext)\n  apply (auto simp add: false_assn_def emp_assn_def join_assn_def elim!: in_0assn.cases)\n  by (auto elim: sync_elims)\n\nlemma combine_assn_in0_wait:\n  \"ch \\<in> chs \\<Longrightarrow> combine_assn chs (in_0assn ch v @\\<^sub>t P) (wait_assn d p rdy @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t\n   \\<up>(d\\<le>0) \\<and>\\<^sub>t combine_assn chs (in_0assn ch v @\\<^sub>t P) Q\"\n  unfolding combine_assn_def entails_tassn_def join_assn_def apply auto\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule:in_0assn.cases[of ch v])\n     apply auto\n    apply(cases rule:wait_assn.cases[of d p rdy])\n      apply auto\n    subgoal by (auto elim: sync_elims)\n    apply(rule exI[where x=\"(InBlock ch v # tr2a)\"])\n    by auto\n  done\n\nlemma combine_assn_in0_out:\n\"ch1\\<in>chs \\<and> ch2\\<in>chs \\<Longrightarrow>\ncombine_assn chs (in_0assn ch1 v1 @\\<^sub>t P) (out_assn s ch2 v2 @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t\n\\<up>(ch1=ch2 \\<and> v1 =v2) \\<and>\\<^sub>t combine_assn chs P Q\"\n  unfolding combine_assn_def entails_tassn_def join_assn_def\n  apply auto\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule: in_0assn.cases[of ch1 v1 tr1a])\n     apply auto\n    apply(cases rule: out_assn.cases[of s ch2 v2 tr1b])\n      apply auto\n    subgoal\n      apply(elim combine_blocks_pairE)\n      by auto\n    by (auto elim: sync_elims)\n  done\n\nlemma combine_assn_in0_outrdy:\n\"ch1\\<in>chs \\<and> ch2\\<in>chs \\<Longrightarrow>\ncombine_assn chs (in_0assn ch1 v1 @\\<^sub>t P) (outrdy_assn s ch2 v2 rdy @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t\n\\<up>(ch1=ch2 \\<and> v1 =v2) \\<and>\\<^sub>t combine_assn chs P Q\"\n  unfolding combine_assn_def entails_tassn_def join_assn_def\n  apply auto\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule: in_0assn.cases[of ch1 v1 tr1a])\n     apply auto\n    apply(cases rule: outrdy_assn.cases[of s ch2 v2 rdy tr1b])\n      apply auto\n    subgoal\n      apply(elim combine_blocks_pairE)\n      by auto\n    by (auto elim: sync_elims)\n  done\n\nlemma combine_assn_in0_inrdy:\n\"ch1\\<in>chs \\<and> ch2\\<in>chs \\<Longrightarrow>\ncombine_assn chs (in_0assn ch1 v1 @\\<^sub>t P) (inrdy_assn s ch2 v2 rdy @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t R\"\n  unfolding combine_assn_def entails_tassn_def join_assn_def\n  apply auto\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule: in_0assn.cases[of ch1 v1 tr1a])\n     apply auto\n    apply(cases rule: inrdy_assn.cases[of s ch2 v2 rdy tr1b])\n      apply auto\n    subgoal\n      apply(elim combine_blocks_pairE)\n      by auto\n    by (auto elim: sync_elims)\n  done\n\n\nlemma combine_assn_in0_waitin:\n\"ch1\\<in>chs \\<and> ch2\\<in>chs \\<Longrightarrow>\ncombine_assn chs (in_0assn ch1 v1 @\\<^sub>t P) (waitin_assn d p ch2 v2 rdy @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t R\"\n  unfolding combine_assn_def entails_tassn_def join_assn_def\n  apply auto\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule: in_0assn.cases[of ch1 v1 tr1a])\n     apply auto\n    apply(cases rule: waitin_assn.cases[of d p ch2 v2 rdy tr1b])\n      apply auto\n    subgoal\n      by (auto elim: sync_elims)\n    subgoal\n      apply(elim combine_blocks_pairE)\n      by auto\n    done\n  done\n\nlemma combine_assn_out0_emp:\n  \"ch \\<in> chs \\<Longrightarrow> combine_assn chs (out_0assn ch v @\\<^sub>t P) emp\\<^sub>t = false\\<^sub>A\"\n  unfolding combine_assn_def\n  apply (rule ext)\n  apply (auto simp add: false_assn_def emp_assn_def join_assn_def elim!: out_0assn.cases)\n  by (auto elim: sync_elims)\n\nlemma combine_assn_out0_inrdy:\n\"ch1\\<in>chs \\<and> ch2\\<in>chs \\<Longrightarrow>\ncombine_assn chs (out_0assn ch1 v1 @\\<^sub>t P) (inrdy_assn s ch2 v2 rdy @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t\n\\<up>(ch1=ch2 \\<and> v1 =v2) \\<and>\\<^sub>t combine_assn chs P Q\"\n  unfolding combine_assn_def entails_tassn_def join_assn_def\n  apply auto\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule: out_0assn.cases[of ch1 v1 tr1a])\n     apply auto\n    apply(cases rule: inrdy_assn.cases[of s ch2 v2 rdy tr1b])\n      apply auto\n    subgoal\n      apply(elim combine_blocks_pairE)\n      by auto\n    by (auto elim: sync_elims)\n  done\n\n\nlemma combine_assn_out0_outrdy:\n\"ch1\\<in>chs \\<and> ch2\\<in>chs \\<Longrightarrow>\ncombine_assn chs (out_0assn ch1 v1 @\\<^sub>t P) (outrdy_assn s ch2 v2 rdy @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t R\"\n  unfolding combine_assn_def entails_tassn_def join_assn_def\n  apply auto\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule: out_0assn.cases[of ch1 v1 tr1a])\n     apply auto\n    apply(cases rule: outrdy_assn.cases[of s ch2 v2 rdy tr1b])\n      apply auto\n    subgoal\n      apply(elim combine_blocks_pairE)\n      by auto\n    by (auto elim: sync_elims)\n  done\n\nlemma combine_assn_out0_waitin:\n\"ch1\\<in>chs \\<and> ch2\\<in>chs \\<Longrightarrow>\ncombine_assn chs (out_0assn ch1 v1 @\\<^sub>t P) (waitin_assn d p ch2 v2 rdy @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t \n  \\<up>(ch1=ch2 \\<and> v1 =v2 \\<and> d\\<le>0) \\<and>\\<^sub>t combine_assn chs P Q\"\n  unfolding combine_assn_def entails_tassn_def join_assn_def\n  apply auto\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule: out_0assn.cases[of ch1 v1 tr1a])\n     apply auto\n    apply(cases rule: waitin_assn.cases[of d p ch2 v2 rdy tr1b])\n      apply auto\n    subgoal\n      by (auto elim: sync_elims)\n    subgoal\n      apply(elim combine_blocks_pairE)\n      by auto\n    done\n  done\n\n\nlemma combine_assn_wait_wait2:\n\"compat_rdy rdy1 rdy2 \\<and> d1 = d2 \\<and> d1\\<ge>0 \\<Longrightarrow>\ncombine_assn chs (wait_assn d1 p1 rdy1 @\\<^sub>t P) (wait_assn d2 p2 rdy2 @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t\nwait_assn d1 (\\<lambda> t. ParState (p1 t) (p2 t)) (merge_rdy rdy1 rdy2) @\\<^sub>t combine_assn chs P Q\"\nunfolding combine_assn_def entails_tassn_def join_assn_def\n  apply auto\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule:wait_assn.cases[of d2 p1 rdy1 tr1a])\n      apply auto\n    subgoal\n     apply(cases rule:wait_assn.cases[of d2 p2 rdy2 tr1b])\n        apply auto\n      apply(elim combine_blocks_waitE2)\n       apply auto\n      apply(rule exI[where x=\"[WaitBlk d2 (\\<lambda>t. ParState (p1 t) (p2 t)) (merge_rdy rdy1 rdy2)]\"])\n      apply auto\n      apply(rule) by auto\n    by(auto simp add:emp_assn_def)\n  done\n\n\nlemma combine_assn_wait_wait3:\n\"compat_rdy rdy1 rdy2 \\<and> d1 < d2 \\<and> d1\\<ge>0 \\<Longrightarrow>\ncombine_assn chs (wait_assn d1 p1 rdy1 @\\<^sub>t P) (wait_assn d2 p2 rdy2 @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t\nwait_assn d1 (\\<lambda> t. ParState (p1 t) (p2 t)) (merge_rdy rdy1 rdy2) @\\<^sub>t combine_assn chs P (wait_assn (d2-d1) (\\<lambda> t. p2(t+d1)) rdy2 @\\<^sub>t Q)\"\nunfolding combine_assn_def entails_tassn_def join_assn_def\n  apply auto\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule:wait_assn.cases[of d1 p1 rdy1 tr1a])\n      apply auto\n    subgoal\n     apply(cases rule:wait_assn.cases[of d2 p2 rdy2 tr1b])\n        apply auto\n      subgoal\n      apply(elim combine_blocks_waitE3)\n       apply auto\n      apply(rule exI[where x=\"[WaitBlk d1 (\\<lambda>t. ParState (p1 t) (p2 t)) (merge_rdy rdy1 rdy2)]\"])\n      apply auto\n         apply(rule) \n         apply auto\n        apply(rule exI[where x= tr2a])\n        apply auto\n        apply(rule exI[where x=\"(WaitBlk (d2 - d1) (\\<lambda>t. p2 (t + d1)) rdy2 # tr2b)\"])\n        apply auto\n        apply(rule exI[where x=\"[WaitBlk (d2 - d1) (\\<lambda>t. p2 (t + d1)) rdy2]\"])\n        apply auto\n        apply(rule) by auto\n      done\n    by(auto simp add:emp_assn_def)\n  done\n\nlemma combine_assn_wait_wait3':\n\"compat_rdy rdy1 rdy2 \\<and> d1 \\<le> d2 \\<and> d1\\<ge>0 \\<Longrightarrow>\ncombine_assn chs (wait_assn d1 p1 rdy1 @\\<^sub>t P) (wait_assn d2 p2 rdy2 @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t\nwait_assn d1 (\\<lambda> t. ParState (p1 t) (p2 t)) (merge_rdy rdy1 rdy2) @\\<^sub>t combine_assn chs P (wait_assn (d2-d1) (\\<lambda> t. p2(t+d1)) rdy2 @\\<^sub>t Q)\"\n  apply(cases \"d1=d2\")\n  subgoal \n    apply auto\n    apply(rule combine_assn_wait_wait2)\n    by auto\n  apply(rule combine_assn_wait_wait3)\n  by auto\n\n\nlemma combine_assn_wait_wait4:\n\"compat_rdy rdy1 rdy2 \\<and> d1 > d2 \\<and> d2\\<ge>0 \\<Longrightarrow>\ncombine_assn chs (wait_assn d1 p1 rdy1 @\\<^sub>t P) (wait_assn d2 p2 rdy2 @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t\nwait_assn d2 (\\<lambda> t. ParState (p1 t) (p2 t)) (merge_rdy rdy1 rdy2) @\\<^sub>t combine_assn chs (wait_assn (d1-d2) (\\<lambda> t. p1(t+d2)) rdy1 @\\<^sub>t P) Q\"\nunfolding combine_assn_def entails_tassn_def join_assn_def\n  apply auto\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule:wait_assn.cases[of d2 p2 rdy2 tr1b])\n      apply auto\n    subgoal\n     apply(cases rule:wait_assn.cases[of d1 p1 rdy1 tr1a])\n        apply auto\n      subgoal\n      apply(elim combine_blocks_waitE4)\n       apply auto\n      apply(rule exI[where x=\"[WaitBlk d2 (\\<lambda>t. ParState (p1 t) (p2 t)) (merge_rdy rdy1 rdy2)]\"])\n      apply auto\n         apply(rule) \n         apply auto\n        apply(rule exI[where x=\"(WaitBlk (d1 - d2) (\\<lambda>t. p1 (t + d2)) rdy1 # tr2a)\"])\n        apply auto\n         apply(rule exI[where x=\"[WaitBlk (d1 - d2) (\\<lambda>t. p1 (t + d2)) rdy1]\"])\n        apply auto\n        apply(rule) by auto\n      done\n    by(auto simp add:emp_assn_def)\n  done\n\nlemma combine_assn_wait_wait4':\n\"compat_rdy rdy1 rdy2 \\<and> d1 \\<ge> d2 \\<and> d2\\<ge>0 \\<Longrightarrow>\ncombine_assn chs (wait_assn d1 p1 rdy1 @\\<^sub>t P) (wait_assn d2 p2 rdy2 @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t\nwait_assn d2 (\\<lambda> t. ParState (p1 t) (p2 t)) (merge_rdy rdy1 rdy2) @\\<^sub>t combine_assn chs (wait_assn (d1-d2) (\\<lambda> t. p1(t+d2)) rdy1 @\\<^sub>t P) Q\"\n  apply(cases \"d1=d2\")\n  subgoal\n    apply auto\n    apply(rule combine_assn_wait_wait2)\n    by auto\n  apply(rule combine_assn_wait_wait4)\n  by auto\n\nlemma combine_assn_wait_wait5:\n\"compat_rdy rdy1 rdy2 \\<and> d1 \\<ge> 0 \\<and> d2\\<ge> 0 \\<Longrightarrow>\ncombine_assn chs (wait_assn d1 p1 rdy1 @\\<^sub>t P) (wait_assn d2 p2 rdy2 @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t\n   (\\<up>(d1=d2) \\<and>\\<^sub>t wait_assn d1 (\\<lambda> t. ParState (p1 t) (p2 t)) (merge_rdy rdy1 rdy2) @\\<^sub>t combine_assn chs P Q)\n\\<or>\\<^sub>t (\\<up>(d1<d2) \\<and>\\<^sub>t wait_assn d1 (\\<lambda> t. ParState (p1 t) (p2 t)) (merge_rdy rdy1 rdy2) @\\<^sub>t combine_assn chs P (wait_assn (d2-d1) (\\<lambda> t. p2(t+d1)) rdy2 @\\<^sub>t Q))\n\\<or>\\<^sub>t (\\<up>(d1>d2) \\<and>\\<^sub>t wait_assn d2 (\\<lambda> t. ParState (p1 t) (p2 t)) (merge_rdy rdy1 rdy2) @\\<^sub>t combine_assn chs (wait_assn (d1-d2) (\\<lambda> t. p1(t+d2)) rdy1 @\\<^sub>t P) Q)\"\n  apply(cases \"d1>d2\")\n  subgoal apply auto\n    apply(rule entails_tassn_disjI2)\n    apply(rule entails_tassn_disjI2)\n    apply(rule combine_assn_wait_wait4)\n    by auto\n  apply(cases \"d1<d2\")\n  subgoal apply auto\n    apply(rule entails_tassn_disjI2)\n    apply(rule entails_tassn_disjI1)\n    apply(rule combine_assn_wait_wait3)\n    by auto\n  apply auto\n  apply(rule entails_tassn_disjI1)\n  apply(rule combine_assn_wait_wait2)\n  by auto\n\nlemma combine_assn_waitin_wait:\n  assumes \"ch \\<in> chs \\<and> compat_rdy rdy1 rdy2 \\<and> d1\\<ge>0 \\<and> d2\\<ge>0\"\n  shows \"combine_assn chs (waitin_assn d1 p1 ch v rdy1 @\\<^sub>t P)(Wait\\<^sub>t d2 p2 rdy2 @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t \n      \\<up>(d2\\<le>d1) \\<and>\\<^sub>t   Wait\\<^sub>t d2 (\\<lambda> t. ParState (p1 t) (p2 t)) (merge_rdy rdy1 rdy2) \n                @\\<^sub>t (combine_assn chs (waitin_assn (d1-d2) (\\<lambda> t. p1(t+d2)) ch v rdy1 @\\<^sub>t P) Q)\"\n  unfolding combine_assn_def\n  using assms\n  apply (auto simp add: entails_tassn_def join_assn_def)\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule: waitin_assn.cases[of d1 p1 ch v rdy1 tr1a])\n      apply auto\n    subgoal\n      apply(cases rule: wait_assn.cases[of d2 p2 rdy2 tr1b])\n        apply auto\n        subgoal using assms\n        apply(cases \"d2<d1\")\n        subgoal\n          apply (auto elim!: combine_blocks_waitE4)\n          apply(rule exI[where x=\"[WaitBlk d2 (\\<lambda>t. ParState (p1 t) (p2 t)) (merge_rdy rdy1 rdy2)]\"])\n          apply auto\n          subgoal apply rule by auto\n          apply(rule exI[where x=\"(WaitBlk (d1 - d2) (\\<lambda>t. p1 (t + d2)) rdy1 # InBlock ch v # tr2a)\"])\n          apply auto\n          apply(rule exI[where x=\"WaitBlk (d1 - d2) (\\<lambda>t. p1 (t + d2)) rdy1 # [InBlock ch v]\"])\n          apply auto\n          apply(rule )\n          by auto\n        apply(cases \"d2>d1\")\n        subgoal\n          apply (auto elim!: combine_blocks_waitE3)\n          by (auto elim:combine_blocks_pairE2)\n        apply(cases \"d2=d1\")\n        subgoal\n          apply (auto elim!: combine_blocks_waitE2)\n          apply(rule exI[where x=\"[WaitBlk d1 (\\<lambda>t. ParState (p1 t) (p2 t)) (merge_rdy rdy1 rdy2)]\"])\n          apply auto\n          subgoal apply(rule) by auto\n          apply(rule exI[where x=\"(InBlock ch v # tr2a)\"])\n          apply auto\n          apply(rule exI[where x=\"[InBlock ch v]\"])\n          apply auto\n          apply(rule)\n          by auto\n        by auto\n      subgoal\n        apply(auto simp add:emp_assn_def)\n        apply(rule exI[where x=\"(WaitBlk d1 p1 rdy1 # InBlock ch v # tr2a)\"])\n        by auto\n      done\n    subgoal\n      apply(cases rule: wait_assn.cases[of d2 p2 rdy2 tr1b])\n        apply auto\n      subgoal\n        by (auto elim: sync_elims)\n      subgoal\n        apply(auto simp add:emp_assn_def)\n        apply(rule exI[where x=\"(InBlock ch v # tr2a)\"])\n        by auto\n      done\n    done\n  done\n\nlemma combine_assn_wait_waitin:\n  assumes \"ch \\<in> chs \\<and> compat_rdy rdy2 rdy1 \\<and> d1\\<ge>0 \\<and> d2\\<ge>0\"\n  shows \"combine_assn chs (Wait\\<^sub>t d2 p2 rdy2 @\\<^sub>t Q) (waitin_assn d1 p1 ch v rdy1 @\\<^sub>t P) \\<Longrightarrow>\\<^sub>t \n      \\<up>(d2\\<le>d1) \\<and>\\<^sub>t   Wait\\<^sub>t d2 (\\<lambda> t. ParState (p2 t) (p1 t)) (merge_rdy rdy2 rdy1) \n                @\\<^sub>t (combine_assn chs Q (waitin_assn (d1-d2) (\\<lambda> t. p1(t+d2)) ch v rdy1 @\\<^sub>t P))\"\n  unfolding combine_assn_def\n  using assms\n  apply (auto simp add: entails_tassn_def join_assn_def)\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule: waitin_assn.cases[of d1 p1 ch v rdy1 tr1b])\n      apply auto\n    subgoal\n      apply(cases rule: wait_assn.cases[of d2 p2 rdy2 tr1a])\n        apply auto\n        subgoal using assms\n        apply(cases \"d2<d1\")\n        subgoal\n          apply (auto elim!: combine_blocks_waitE3)\n          apply(rule exI[where x=\"[WaitBlk d2 (\\<lambda>t. ParState (p2 t) (p1 t)) (merge_rdy rdy2 rdy1)]\"])\n          apply auto\n          subgoal apply rule by auto\n          apply(rule exI[where x=tr2a])\n          apply auto\n          apply(rule exI[where x=\"(WaitBlk (d1 - d2) (\\<lambda>t. p1 (t + d2)) rdy1 # InBlock ch v # tr2b)\"])\n          apply auto\n          apply(rule exI[where x=\"WaitBlk (d1 - d2) (\\<lambda>t. p1 (t + d2)) rdy1 # [InBlock ch v]\"])\n          apply auto\n          apply(rule )\n          by auto\n        apply(cases \"d2>d1\")\n        subgoal\n          apply (auto elim!: combine_blocks_waitE4)\n          by (auto elim:combine_blocks_pairE2')\n        apply(cases \"d2=d1\")\n        subgoal\n          apply (auto elim!: combine_blocks_waitE2)\n          apply(rule exI[where x=\"[WaitBlk d1 (\\<lambda>t. ParState (p2 t) (p1 t)) (merge_rdy rdy2 rdy1)]\"])\n          apply auto\n          subgoal apply(rule) by auto\n          apply(rule exI[where x=tr2a])\n          apply auto\n          apply(rule exI[where x=\"(InBlock ch v # tr2b)\"])\n          apply auto\n          apply(rule exI[where x=\"[InBlock ch v]\"])\n          apply auto\n          apply(rule)\n          by auto\n        by auto\n      subgoal\n        apply(auto simp add:emp_assn_def)\n        apply(rule exI[where x=\"tr2a\"])\n        apply auto\n        apply(rule exI[where x=\"(WaitBlk d1 p1 rdy1 # InBlock ch v # tr2b)\"])\n        by auto\n      done\n    subgoal\n      apply(cases rule: wait_assn.cases[of d2 p2 rdy2 tr1a])\n        apply auto\n      subgoal\n        by (auto elim: sync_elims)\n      subgoal\n        apply(auto simp add:emp_assn_def)\n        apply(rule exI[where x=\"tr2a\"])\n        apply auto\n        apply(rule exI[where x=\"(InBlock ch v # tr2b)\"])\n        by auto\n      done\n    done\n  done\n\n\nlemma combine_assn_wait_out:\n  assumes \"ch\\<in>chs \\<and> ch \\<in> snd rdy\"\n  shows \"combine_assn chs (wait_assn d p rdy @\\<^sub>t P) (out_assn s ch v @\\<^sub>t Q)\n      \\<Longrightarrow>\\<^sub>t \\<up>(d\\<le>0) \\<and>\\<^sub>t combine_assn chs P (out_assn s ch v @\\<^sub>t Q)\"\n  unfolding combine_assn_def\n  using assms\n  apply (auto simp add: entails_tassn_def join_assn_def)\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule: wait_assn.cases[of d p rdy tr1a])\n      apply auto\n    apply(cases rule:out_assn.cases[of s ch v tr1b])\n      apply auto\n    subgoal\n      by (auto elim: sync_elims)\n    apply(elim combine_blocks_waitE1)\n    apply(cases rdy)\n    by auto\n  done\n\nlemma combine_assn_wait_outrdy:\n  assumes \"ch\\<in>chs \\<and> \\<not> compat_rdy rdy rdy'\"\n  shows \"combine_assn chs (wait_assn d p rdy @\\<^sub>t P) (outrdy_assn s ch v rdy'@\\<^sub>t Q)\n      \\<Longrightarrow>\\<^sub>t \\<up>(d\\<le>0) \\<and>\\<^sub>t combine_assn chs P (outrdy_assn s ch v rdy' @\\<^sub>t Q)\"\n  unfolding combine_assn_def\n  using assms\n  apply (auto simp add: entails_tassn_def join_assn_def)\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule: wait_assn.cases[of d p rdy tr1a])\n      apply auto\n    apply(cases rule:outrdy_assn.cases[of s ch v rdy' tr1b])\n      apply auto\n    subgoal\n      by (auto elim: sync_elims)\n    apply(elim combine_blocks_waitE1)\n    by auto\n  done\n\nlemma combine_assn_wait_inrdy:\n  assumes \"ch\\<in>chs \\<and> \\<not> compat_rdy rdy rdy'\"\n  shows \"combine_assn chs (wait_assn d p rdy @\\<^sub>t P) (inrdy_assn s ch v rdy'@\\<^sub>t Q)\n      \\<Longrightarrow>\\<^sub>t \\<up>(d\\<le>0) \\<and>\\<^sub>t combine_assn chs P (inrdy_assn s ch v rdy' @\\<^sub>t Q)\"\n  unfolding combine_assn_def\n  using assms\n  apply (auto simp add: entails_tassn_def join_assn_def)\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule: wait_assn.cases[of d p rdy tr1a])\n      apply auto\n    apply(cases rule:inrdy_assn.cases[of s ch v rdy' tr1b])\n      apply auto\n    subgoal\n      by (auto elim: sync_elims)\n    apply(elim combine_blocks_waitE1)\n    by auto\n  done\n\nlemma combine_assn_waitin_out:\n  assumes \"ch\\<in>chs \\<and> ch \\<in> snd rdy\"\n  shows \"combine_assn chs (waitin_assn d p ch v rdy @\\<^sub>t P) (out_assn s' ch v' @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t\n           \\<up>(v=v' \\<and> d\\<le>0) \\<and>\\<^sub>t combine_assn chs P Q\"\n  unfolding combine_assn_def entails_tassn_def join_assn_def\n  using assms\n  apply auto\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule:waitin_assn.cases[of d p ch v rdy tr1a])\n      apply auto\n    subgoal \n      apply(cases rule:out_assn.cases[of s' ch v' tr1b])\n      apply auto\n      subgoal\n        by(auto elim:combine_blocks_pairE2')\n      subgoal for d\n        apply(elim combine_blocks_waitE1)\n        apply(cases rdy)\n        by auto\n      done\n    subgoal\n      apply(cases rule:out_assn.cases[of s' ch v' tr1b])\n        apply auto\n      subgoal\n        apply (auto elim!: combine_blocks_pairE)\n        by blast\n      subgoal for d\n        by(auto elim:combine_blocks_pairE2)\n      done\n    done\n  done\n\n\nlemma combine_assn_waitin_out'':\n  assumes \"ch1\\<in>chs \\<and> ch2\\<in>chs \\<and> ch1\\<noteq>ch2\"\n  shows \"combine_assn chs (waitin_assn d p ch1 v rdy @\\<^sub>t P) (out_assn s' ch2 v' @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t\n           R\"\n  unfolding combine_assn_def entails_tassn_def join_assn_def\n  using assms\n  apply auto\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule:waitin_assn.cases[of d p ch1 v rdy tr1a])\n      apply auto\n      subgoal \n        apply(cases rule:out_assn.cases[of s' ch2 v' tr1b])\n        apply auto\n        subgoal\n          by (auto elim!: sync_elims)\n        subgoal for d2\n          apply(cases \"\\<not> compat_rdy rdy ({ch2}, {})\")\n          subgoal by (auto elim!: sync_elims)\n          apply(cases \"d<d2\")\n          subgoal\n            apply(elim combine_blocks_waitE3)\n            by (auto elim!: sync_elims)\n          apply(cases \"d>d2\")\n          subgoal\n            apply(elim combine_blocks_waitE4)\n            by (auto elim!: sync_elims)\n          apply auto\n          apply(elim combine_blocks_waitE2)\n          by (auto elim!: combine_blocks_pairE)\n        done\n      subgoal\n      apply(cases rule:out_assn.cases[of s' ch2 v' tr1b])\n        apply auto\n        subgoal\n          by (auto elim!: combine_blocks_pairE)\n        subgoal\n          by (auto elim!: sync_elims)\n        done\n      done\n    done\n\n\nlemma combine_assn_out0_waitin1:\n  assumes \"ch2\\<in>chs \\<and> ch1\\<in>chs\"\n  shows \"combine_assn chs (out_0assn ch2 v2 @\\<^sub>t P)(waitin_assn d p ch1 v1 rdy @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t\n         \\<up>(ch1 = ch2 \\<and> v1 = v2 \\<and> d\\<le>0) \\<and>\\<^sub>t combine_assn chs P Q\"\n  unfolding combine_assn_def entails_tassn_def join_assn_def\n  using assms\n  apply auto\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule:out_0assn.cases[of ch2 v2 tr1a])\n     apply auto\n    apply(cases rule:waitin_assn.cases[of d p ch1 v1 rdy tr1b])\n      apply auto\n    subgoal \n      by(auto elim!: combine_blocks_pairE2)\n    subgoal\n      apply(auto elim!: combine_blocks_pairE)\n      by blast\n    done\n  done\n\n\nlemma combine_assn_waitp_waitin':\n  assumes \"ch1\\<in>chs \\<and> \\<not>compat_rdy rdy1 rdy2\"\n  shows \"combine_assn chs (wait_passn rdy1 @\\<^sub>t P)(waitin_assn d p ch1 v1 rdy2 @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t\n         R\"\n  unfolding combine_assn_def entails_tassn_def join_assn_def true_assn_def\n  using assms\n  apply auto\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule:wait_passn.cases[of rdy1 tr1a])\n     apply auto\n    subgoal for dd pp\n      apply(cases rule:waitin_assn.cases[of d p ch1 v1 rdy2 tr1b])\n        apply auto\n      subgoal\n        apply(elim combine_blocks_waitE1)\n        by auto\n      subgoal\n        by (auto elim!: sync_elims)\n    done\n  done\n  done\n\n\nlemma combine_assn_waitin_waitin:\n  assumes \"ch1\\<in>chs \\<and> ch2\\<in>chs\"\n  shows \"combine_assn chs (waitin_assn d1 p1 ch1 v1 rdy1 @\\<^sub>t P) (waitin_assn d2 p2 ch2 v2 rdy2 @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t R\"\n  unfolding entails_tassn_def combine_assn_def join_assn_def\n  using assms\n  apply auto\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule:waitin_assn.cases[of d1 p1 ch1 v1 rdy1])\n      apply auto\n    subgoal \n      apply(cases rule:waitin_assn.cases[of d2 p2 ch2 v2 rdy2])\n        apply auto\n      subgoal \n        apply(cases \"\\<not> compat_rdy rdy1 rdy2\")\n        subgoal by (auto elim!: sync_elims)\n        apply(cases \"d1<d2\")\n        subgoal\n          apply(elim combine_blocks_waitE3)\n             apply auto\n          by (auto elim!: sync_elims)\n        apply(cases \"d1>d2\")\n        subgoal\n          apply(elim combine_blocks_waitE4)\n             apply auto\n          by (auto elim!: sync_elims)\n        apply auto\n        apply(elim combine_blocks_waitE2)\n        apply auto\n        apply(elim combine_blocks_pairE)\n        by auto\n      subgoal\n        by (auto elim!: sync_elims)\n      done\n      subgoal\n      apply(cases rule:waitin_assn.cases[of d2 p2 ch2 v2 rdy2])\n        apply auto\n      subgoal\n        by (auto elim!: sync_elims)\n      subgoal\n        apply(elim combine_blocks_pairE)\n        by auto\n      done\n      done\n    done\n\n\n\nlemma combine_assn_waitin_outrdy:\n  assumes \"ch1\\<in>chs \\<and> ch2\\<in>chs \\<and> \\<not>compat_rdy rdy1 rdy2\"\n  shows \"combine_assn chs (waitin_assn d p ch1 v1 rdy1 @\\<^sub>t P)(outrdy_assn s2 ch2 v2 rdy2 @\\<^sub>t Q)\n         \\<Longrightarrow>\\<^sub>t \\<up>(ch1 = ch2 \\<and> v1= v2 \\<and> d \\<le> 0) \\<and>\\<^sub>t combine_assn chs P Q\"\n  unfolding entails_tassn_def combine_assn_def join_assn_def\n  using assms\n  apply auto\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule:waitin_assn.cases[of d p ch1 v1 rdy1 tr1a])\n      apply auto\n    subgoal\n      apply(cases rule:outrdy_assn.cases[of s2 ch2 v2 rdy2 tr1b])\n        apply auto\n      by (auto elim!: sync_elims)\n    subgoal\n      apply(cases rule:outrdy_assn.cases[of s2 ch2 v2 rdy2 tr1b])\n        apply auto\n      subgoal\n        apply(auto elim!: combine_blocks_pairE)\n        by blast\n      by (auto elim!: sync_elims)\n    done\n  done\n\n\nlemma combine_assn_waitin_inrdy:\n  assumes \"ch1\\<in>chs \\<and> ch2\\<in>chs\"\n  shows \"combine_assn chs (waitin_assn d1 p1 ch1 v1 rdy1 @\\<^sub>t P) (inrdy_assn s ch2 v2 rdy2 @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t R\"\n  unfolding entails_tassn_def combine_assn_def join_assn_def\n  using assms\n  apply auto\n  subgoal for tr tr1a tr2a tr1b tr2b\n    apply(cases rule:waitin_assn.cases[of d1 p1 ch1 v1 rdy1])\n      apply auto\n    subgoal \n      apply(cases rule:inrdy_assn.cases[of s ch2 v2 rdy2])\n        apply auto\n      subgoal\n        by (auto elim!: sync_elims)\n      subgoal for d2\n        apply(cases \"\\<not> compat_rdy rdy1 rdy2\")\n        subgoal by (auto elim!: sync_elims)\n        apply(cases \"d1<d2\")\n        subgoal\n          apply(elim combine_blocks_waitE3)\n             apply auto\n          by (auto elim!: sync_elims)\n        apply(cases \"d1>d2\")\n        subgoal\n          apply(elim combine_blocks_waitE4)\n             apply auto\n          by (auto elim!: sync_elims)\n        apply auto\n        apply(elim combine_blocks_waitE2)\n        apply auto\n        apply(elim combine_blocks_pairE)\n        by auto\n      done\n      subgoal\n      apply(cases rule:inrdy_assn.cases[of s ch2 v2 rdy2 tr1b])\n          apply auto\n        subgoal\n        apply(elim combine_blocks_pairE)\n        by auto\n      subgoal\n        by (auto elim!: sync_elims)\n      done\n      done\n    done\n\n\nlemma combine_SCH_T1_T2:\n\"propc k1 (Sch p rn rp) (Task st1 ent1 2) \\<Longrightarrow>\n propc' k2 (Sch p rn rp) (Task st2 ent2 1) \\<Longrightarrow>\n   proper' (Sch p rn rp) \\<Longrightarrow>\n   inv_s ts1 \\<Longrightarrow>\n   inv_s' ts2 \\<Longrightarrow>\n combine_assn {req_ch 2, preempt_ch 2, run_ch 2, free_ch 2, exit_ch 2} \n (combine1 k k1 (Sch p rn rp,ss) (Task st1 ent1 2,ts1)) (T2_tr k2 (Task st2 ent2 1,ts2)) \\<Longrightarrow>\\<^sub>t\n combine2 k k1 k2 (Sch p rn rp,ss) (Task st1 ent1 2,ts1) (Task st2 ent2 1,ts2)\"\nproof(induction \" k+k1+k2\"  arbitrary: k1 k2 k p rn rp ss ts1 st1 ent1 ts2 st2 ent2 rule: less_induct)\n  case less\n  then show ?case \n    apply(cases k)\n    subgoal\n      apply(cases k1)\n      subgoal\n        apply(cases k2)\n        subgoal\n          by auto\n        subgoal for k2'\n          apply auto\n          apply(cases st2)\n            apply simp\n            subgoal premises pre\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_emp_wait')\n              apply(rule entails_tassn_trans[where Q =\"combine2 0 0 k2' (Sch p rn rp,ss) (Task st1 ent1 2,ts1) (Task READY ezero 1, ts2(T := 0))\"])\n              apply(rule entails_tassn_trans)\n               prefer 2\n               apply(rule pre(1))\n              subgoal by auto\n              subgoal using pre(2) unfolding propc_def by auto\n              subgoal using pre(3) unfolding propc'_def by auto\n              subgoal using pre(4) unfolding proper'_def by auto\n              subgoal using pre(5) unfolding inv_s_def by auto\n              subgoal using pre(6) unfolding inv_s'_def by auto\n              by auto\n            apply simp\n            subgoal premises pre\n              apply(rule combine_or_right)\n              subgoal\n                apply(rule combine_assn_ex_pre_right')+\n                apply(rule combine_assn_pure_pre_right')\n                by(simp add:combine_assn_emp_out)\n              by(simp add:combine_assn_emp_out)\n            apply simp\n            subgoal premises pre\n              apply(rule combine_or_right)\n              subgoal\n                apply(rule combine_assn_ex_pre_right')+\n                apply(rule combine_assn_pure_pre_right')\n                apply(simp add: combine_assn_emp_waitin)\n                done\n              subgoal\n                apply(rule entails_tassn_trans)\n                 apply(rule combine_assn_emp_wait')\n                apply(rule combine_or_right)\n                subgoal\n                  by(simp add: combine_assn_emp_outrdy)\n                apply(rule combine_assn_ex_pre_right')\n                by(simp add: combine_assn_emp_inrdy)\n              done\n            done\n          done\n        subgoal for k1'\n          apply(cases k2)\n          subgoal\n            apply(cases st1)\n              apply simp\n            subgoal premises pre\n              apply(rule entails_tassn_trans[where Q=\"combine2 0 k1' 0 (Sch p rn rp, ss) (Task READY ezero 2, ts1(T := 0)) (Task st2 ent2 1,ts2)\"])\n              apply(rule entails_tassn_trans)\n               prefer 2\n               apply(rule pre(1))\n              subgoal by auto\n              subgoal using pre(2) unfolding propc_def by auto\n              subgoal using pre(3) unfolding propc'_def by auto\n              subgoal using pre(4) unfolding proper'_def by auto\n              subgoal using pre(5) unfolding inv_s_def by auto\n              subgoal using pre(6) unfolding inv_s'_def by auto\n              by auto\n             apply simp\n            subgoal premises pre\n              by(auto simp add: combine_assn_def entails_tassn_def false_assn_def)\n            apply simp\n            subgoal premises pre\n              by(auto simp add: combine_assn_def entails_tassn_def false_assn_def)\n            done\n          subgoal for k2'\n            apply simp\n            apply(cases st1)\n            subgoal\n              apply(cases st2)\n                apply simp\n              subgoal premises pre\n                apply(cases k1')\n                subgoal apply auto\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_emp_wait')\n                  apply(rule entails_tassn_trans[where Q=\"combine2 0 k1' k2' (Sch p rn rp, ss) (Task READY ezero 2, ts1(T := 0)) (Task READY ezero 1, ts2(T := 0))\"])\n                   apply(rule entails_tassn_trans)\n                    prefer 2\n                    apply(rule pre(1))\n                  subgoal by auto\n                  subgoal using pre(2) unfolding propc_def by auto\n                  subgoal using pre(3) unfolding propc'_def by auto\n                  subgoal using pre(4) unfolding proper'_def by auto\n                  subgoal using pre(5) unfolding inv_s_def by auto\n                using pre(6) unfolding inv_s'_def by auto\n              subgoal for k1''\n                by (auto simp add:combine_assn_def entails_tassn_def false_assn_def)\n              done\n             apply simp\n            subgoal premises pre\n              apply(cases \"k1'\")\n              subgoal apply simp\n                apply(rule combine_or_right)\n                subgoal\n                 apply(rule combine_assn_ex_pre_right')+\n                apply(rule combine_assn_pure_pre_right')\n                  by(simp add: combine_assn_emp_out)\n                by(simp add: combine_assn_emp_out)\n              subgoal for nt1''\n                apply simp\n                by (auto simp add:combine_assn_def entails_tassn_def false_assn_def)\n              done\n            apply simp\n            subgoal premises pre\n              apply(cases k1')\n              subgoal apply simp\n                apply(rule combine_or_right)\n                subgoal\n                apply(rule combine_assn_ex_pre_right')+\n                  apply(rule combine_assn_pure_pre_right')\n                  apply(simp add: combine_assn_emp_waitin)\n                  done\n                subgoal\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_emp_wait')\n                  apply(rule combine_or_right)\n                  subgoal\n                    by(simp add: combine_assn_emp_outrdy)\n                  apply(rule combine_assn_ex_pre_right')\n                  by(simp add: combine_assn_emp_inrdy)\n                done\n              subgoal for nt1''\n                apply simp\n                by (auto simp add:combine_assn_def entails_tassn_def false_assn_def)\n              done\n            done\n          apply simp\n          subgoal\n            by (auto simp add:combine_assn_def entails_tassn_def false_assn_def)\n          apply simp\n          subgoal\n            by (auto simp add:combine_assn_def entails_tassn_def false_assn_def)\n          done\n        done\n      done\n    subgoal for k'\n      apply(cases k1)\n      subgoal\n        apply(cases k2)\n        subgoal\n         apply(simp only:combine1.simps T2_tr.simps)\n          subgoal premises pre\n            apply(rule combine_or_left)\n            subgoal\n              by(simp add: combine_assn_in0_emp)\n            apply(rule combine_or_left)\n            subgoal\n              apply(rule combine_assn_ex_pre_left')+\n              apply(rule combine_assn_pure_pre_left')\n              by(simp add: combine_assn_in0_emp)\n            apply(rule combine_or_left)\n            subgoal\n              apply(rule combine_assn_ex_pre_left')+\n              by(simp add: combine_assn_in0_emp)\n            subgoal\n              apply(rule combine_assn_ex_pre_left')+\n              by(simp add: combine_assn_in0_emp)\n            done\n          done\n        subgoal for k2'\n          apply(simp only:combine1.simps)\n          apply(cases st2)\n            apply(simp only:T2_tr.simps)\n          subgoal premises pre\n            apply(rule combine_or_left)\n            subgoal\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_in0_wait)\n              subgoal by auto\n              unfolding combine2.simps\n              apply(rule entails_tassn_conj)\n              subgoal\n                apply auto\n                using pre(6) unfolding inv_s'_def by auto\n              apply(simp only:pure_assn_entails)\n              apply(rule impI)\n              apply(rule entails_tassn_trans)\n               prefer 2\n              apply(rule pre(1))\n              subgoal by auto\n              subgoal using pre(2) unfolding propc_def by auto\n              subgoal using pre(3) unfolding propc'_def by auto\n              subgoal using pre(4) unfolding proper'_def by auto\n              subgoal using pre(5) unfolding inv_s_def by auto\n              subgoal using pre(6) unfolding inv_s'_def by auto\n              apply(rule combine_assn_left_tran)\n              unfolding combine1.simps\n              apply(rule entails_tassn_disjI1)\n              by auto\n            apply(rule combine_or_left)\n            subgoal\n              apply(rule combine_assn_ex_pre_left')+\n              apply(rule combine_assn_pure_pre_left')\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_in0_wait)\n              subgoal by auto\n              unfolding combine2.simps\n              apply(rule entails_tassn_conj)\n              subgoal\n                apply auto\n                using pre(6) unfolding inv_s'_def by auto\n              apply(simp only:pure_assn_entails)\n              apply(rule impI)\n              apply(rule entails_tassn_trans)\n               prefer 2\n              apply(rule pre(1))\n              subgoal by auto\n              subgoal using pre(2) unfolding propc_def by auto\n              subgoal using pre(3) unfolding propc'_def by auto\n              subgoal using pre(4) unfolding proper'_def by auto\n              subgoal using pre(5) unfolding inv_s_def by auto\n              subgoal using pre(6) unfolding inv_s'_def by auto\n              apply(rule combine_assn_left_tran)\n              unfolding combine1.simps\n              apply(rule entails_tassn_disjI2)\n              apply(rule entails_tassn_disjI1)\n              subgoal for v\n              apply(rule entails_tassn_exI[where x= v])\n              by auto\n            done\n          apply(rule combine_or_left)\n            subgoal\n              apply(rule combine_assn_ex_pre_left')+\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_in0_wait)\n              subgoal by auto\n              unfolding combine2.simps\n              apply(rule entails_tassn_conj)\n              subgoal\n                apply auto\n                using pre(6) unfolding inv_s'_def by auto\n              apply(simp only:pure_assn_entails)\n              apply(rule impI)\n              apply(rule entails_tassn_trans)\n               prefer 2\n              apply(rule pre(1))\n              subgoal by auto\n              subgoal using pre(2) unfolding propc_def by auto\n              subgoal using pre(3) unfolding propc'_def by auto\n              subgoal using pre(4) unfolding proper'_def by auto\n              subgoal using pre(5) unfolding inv_s_def by auto\n              subgoal using pre(6) unfolding inv_s'_def by auto\n              apply(rule combine_assn_left_tran)\n              unfolding combine1.simps\n              apply(rule entails_tassn_disjI2)\n              apply(rule entails_tassn_disjI2)\n              apply(rule entails_tassn_disjI1)\n              subgoal for v\n              apply(rule entails_tassn_exI[where x= v])\n              by auto\n            done\n          subgoal\n              apply(rule combine_assn_ex_pre_left')+\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_in0_wait)\n              subgoal by auto\n              unfolding combine2.simps\n              apply(rule entails_tassn_conj)\n              subgoal\n                apply auto\n                using pre(6) unfolding inv_s'_def by auto\n              apply(simp only:pure_assn_entails)\n              apply(rule impI)\n              apply(rule entails_tassn_trans)\n               prefer 2\n              apply(rule pre(1))\n              subgoal by auto\n              subgoal using pre(2) unfolding propc_def by auto\n              subgoal using pre(3) unfolding propc'_def by auto\n              subgoal using pre(4) unfolding proper'_def by auto\n              subgoal using pre(5) unfolding inv_s_def by auto\n              subgoal using pre(6) unfolding inv_s'_def by auto\n              apply(rule combine_assn_left_tran)\n              unfolding combine1.simps\n              apply(rule entails_tassn_disjI2)\n              apply(rule entails_tassn_disjI2)\n              apply(rule entails_tassn_disjI2)\n              subgoal for v\n              apply(rule entails_tassn_exI[where x= v])\n              by auto\n            done\n          done\n         apply(simp only:T2_tr.simps)\n        subgoal premises pre\n          apply(rule combine_or_left)\n          subgoal\n            apply(rule combine_or_right)\n            subgoal\n              apply(rule combine_assn_ex_pre_right')+\n              apply(rule combine_assn_pure_pre_right')\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_in0_out)\n              subgoal by auto\n              apply(cases \"rp\\<ge>1\")\n              subgoal for v tt \n                apply auto\n                apply(cases k')\n                subgoal apply simp\n                  by(simp add: combine_assn_emp_waitin)\n                subgoal for ns''\n                  apply(simp only: combine1.simps)\n                  apply(rule combine_or_left)\n                  subgoal\n                    apply simp\n                    by(simp add: combine_assn_in0_waitin)\n                  apply(rule combine_or_left)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_left')+\n                    apply(rule combine_assn_pure_pre_left')\n                    by(simp add: combine_assn_in0_waitin)\n                  apply(rule combine_or_left)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_left')+\n                    by(simp add: combine_assn_in0_waitin)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_left')+\n                    by(simp add: combine_assn_in0_waitin)\n                  done\n                done\n              subgoal for v tt \n                apply simp\n                apply(rule combine_assn_pure_pre_left')\n                apply(rule entails_tassn_trans)\n                 apply(rule combine_assn_out0_waitin)\n                subgoal by auto\n                apply auto\n                apply(subgoal_tac\"rn =-1\")\n                 prefer 2\n                subgoal\n                  using pre(4) unfolding proper'_def properp_def by auto\n                apply auto\n                apply(rule entails_tassn_disjI1)\n                apply(rule entails_tassn_trans)\n                 prefer 2\n                 apply(rule pre(1))\n                subgoal by auto\n                subgoal using pre(2) unfolding propc_def by auto\n                subgoal using pre(3) unfolding propc'_def by auto \n                subgoal using pre(4) unfolding proper'_def properp_def by auto\n                subgoal using pre(5) unfolding inv_s_def by auto\n                subgoal using pre(6) unfolding inv_s'_def by auto\n                by auto\n              done\n            subgoal\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_in0_out)\n              subgoal by auto\n              apply(cases \"1\\<le>rp\")\n              subgoal \n                apply auto\n                apply(cases k')\n                subgoal\n                  apply auto\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_emp_wait')\n                  apply(rule combine_or_right)\n                  subgoal\n                    by(auto simp add:combine_assn_emp_outrdy)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_right')\n                    by(auto simp add:combine_assn_emp_inrdy)\n                  done\n                subgoal for k''\n                  apply simp\n                  apply(rule combine_or_left)\n                  subgoal\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_assn_in0_wait)\n                    subgoal by auto\n                    apply auto\n                    apply(rule combine_or_right)\n                    subgoal\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_in0_outrdy)\n                      subgoal by auto\n                      by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                    subgoal\n                      apply(rule combine_assn_ex_pre_right')\n                      apply(rule combine_assn_in0_inrdy)\n                      by auto\n                    done\n                  apply(rule combine_or_left)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_left')+\n                    apply(rule combine_assn_pure_pre_left')\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_assn_in0_wait)\n                    subgoal by auto\n                    apply auto\n                    apply(rule combine_or_right)\n                    subgoal\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_in0_outrdy)\n                      subgoal by auto\n                      by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                    subgoal\n                      apply(rule combine_assn_ex_pre_right')\n                      apply(rule combine_assn_in0_inrdy)\n                      by auto\n                    done\n                  apply(rule combine_or_left)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_left')+\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_assn_in0_wait)\n                    subgoal by auto\n                    apply auto\n                    apply(rule combine_or_right)\n                    subgoal\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_in0_outrdy)\n                      subgoal by auto\n                      by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                    subgoal\n                      apply(rule combine_assn_ex_pre_right')\n                      apply(rule combine_assn_in0_inrdy)\n                      by auto\n                    done\n                  subgoal\n                    apply(rule combine_assn_ex_pre_left')+\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_assn_in0_wait)\n                    subgoal by auto\n                    apply auto\n                    apply(rule combine_or_right)\n                    subgoal for v\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_in0_outrdy)\n                      subgoal by auto\n                      apply auto\n                      apply(rule entails_tassn_disjI2)\n                      apply(subgoal_tac\"9 \\<ge> ts2 T * 200 \\<and> p = []\")\n                       prefer 2\n                      subgoal\n                        using pre(6,4) unfolding inv_s'_def proper'_def\n                        by auto\n                      apply auto\n                      apply(rule entails_tassn_trans)\n                       prefer 2\n                       apply(rule pre(1))\n                      subgoal by auto\n                      subgoal using pre(2) unfolding propc_def by auto\n                      subgoal using pre(3) unfolding propc'_def by auto \n                      subgoal using pre(4) unfolding proper'_def properp_def by auto\n                      subgoal using pre(5) unfolding inv_s_def by auto\n                      subgoal using pre(6) unfolding inv_s'_def by auto\n                      by auto\n                    subgoal\n                      apply(rule combine_assn_ex_pre_right')\n                      apply(rule combine_assn_in0_inrdy)\n                      by auto\n                    done\n                  done\n                done\n              apply auto\n              subgoal\n                apply(rule combine_assn_pure_pre_left')\n                    apply(rule entails_tassn_trans)\n                apply(rule combine_assn_out0_wait'')\n                subgoal by auto\n                apply auto\n                apply(rule combine_or_right)\n                subgoal\n                  apply(rule combine_assn_out0_outrdy)\n                  by auto\n                subgoal\n                  apply(rule combine_assn_ex_pre_right')\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_out0_inrdy)\n                  subgoal by auto\n                  apply auto\n                  apply(rule entails_tassn_disjI1)\n                  apply(subgoal_tac\"rn =-1 \\<and> 9 \\<ge> ts2 T * 200\")\n                   prefer 2\n                  subgoal\n                    using pre(4,6) unfolding proper'_def properp_def inv_s'_def by auto\n                  apply auto\n                  apply(rule entails_tassn_trans)\n                   prefer 2\n                   apply(rule pre(1))\n                  subgoal by auto\n                  subgoal using pre(2) unfolding propc_def by auto\n                  subgoal using pre(3) unfolding propc'_def by auto \n                  subgoal using pre(4) unfolding proper'_def properp_def by auto\n                  subgoal using pre(5) unfolding inv_s_def by auto\n                  subgoal using pre(6) unfolding inv_s'_def by auto\n                  apply(subgoal_tac\"ts2(F := 0) = ts2(T := 9 / 200, F := 0)\")\n                  by(auto simp add:T_def F_def)\n                done\n              done\n            done\n          apply(rule combine_or_left)\n          subgoal\n            apply(rule combine_assn_ex_pre_left')+\n            apply(rule combine_assn_pure_pre_left')\n            apply(rule combine_or_right)\n            subgoal for v\n              apply(rule combine_assn_ex_pre_right')+\n              apply(rule combine_assn_pure_pre_right')\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_in0_out)\n              by auto\n            subgoal\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_in0_out)\n              by auto\n            done\n          apply(rule combine_or_left)\n          subgoal\n            apply(rule combine_assn_ex_pre_left')+\n            apply(rule combine_or_right)\n            subgoal for v\n              apply(rule combine_assn_ex_pre_right')+\n              apply(rule combine_assn_pure_pre_right')\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_in0_out)\n              by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n            subgoal\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_in0_out)\n              by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)                    \n            done\n          subgoal\n            apply(rule combine_assn_ex_pre_left')+\n            apply(rule combine_or_right)\n            subgoal for v\n              apply(rule combine_assn_ex_pre_right')+\n              apply(rule combine_assn_pure_pre_right')\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_in0_out)\n              by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n            subgoal\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_in0_out)\n              by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)                    \n            done\n          done\n        apply(simp only:T2_tr.simps)\n        subgoal premises pre\n          apply(rule combine_or_left)\n          subgoal\n            apply(rule combine_or_right)\n            subgoal\n              apply(rule combine_assn_ex_pre_right')+\n              apply(rule combine_assn_pure_pre_right')\n              apply(rule combine_assn_in0_waitin)\n              by auto\n            subgoal\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_in0_wait)\n              subgoal by auto\n              apply(simp only:pure_assn_entails)\n              apply(rule impI)\n              apply(rule combine_or_right)\n              subgoal\n               apply(rule entails_tassn_trans)\n                 apply(rule combine_assn_in0_outrdy)\n                by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n              subgoal\n                apply(rule combine_assn_ex_pre_right')+\n                apply(rule combine_assn_in0_inrdy)\n                by auto\n              done\n            done\n          apply(rule combine_or_left)\n          subgoal\n            apply(rule combine_assn_ex_pre_left')+\n            apply(rule combine_assn_pure_pre_left')\n            apply(rule combine_or_right)\n            subgoal\n              apply(rule combine_assn_ex_pre_right')+\n              apply(rule combine_assn_pure_pre_right')\n              apply(rule combine_assn_in0_waitin)\n              by auto\n            subgoal\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_in0_wait)\n              subgoal by auto\n              apply(simp only:pure_assn_entails)\n              apply(rule impI)\n              apply(rule combine_or_right)\n              subgoal\n               apply(rule entails_tassn_trans)\n                 apply(rule combine_assn_in0_outrdy)\n                by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n              subgoal\n                apply(rule combine_assn_ex_pre_right')+\n                apply(rule combine_assn_in0_inrdy)\n                by auto\n              done\n            done\n          apply(rule combine_or_left)\n          subgoal\n            apply(rule combine_assn_ex_pre_left')+\n            apply(rule combine_or_right)\n            subgoal\n              apply(rule combine_assn_ex_pre_right')+\n              apply(rule combine_assn_pure_pre_right')\n              apply(rule combine_assn_in0_waitin)\n              by auto\n            subgoal for v\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_in0_wait)\n              subgoal by auto\n              apply(simp only:pure_assn_entails)\n              apply(rule impI)\n              apply(rule combine_or_right)\n              subgoal\n               apply(rule entails_tassn_trans)\n                 apply(rule combine_assn_in0_outrdy)\n                subgoal by auto\n                apply(subgoal_tac\"p=[]\")\n                 prefer 2\n                subgoal using pre(4) unfolding proper'_def by auto\n                apply auto\n                apply(subgoal_tac\"min (9 / 200 - ts2 T) (1 / 50 - C_upd ent2 (ts2 C)) = 0\")\n                 prefer 2\n                subgoal using pre(6) unfolding inv_s'_def C_upd_def\n                  apply(cases ent2) by auto\n                apply auto\n                apply(rule entails_tassn_trans)\n                   prefer 2\n                   apply(rule pre(1))\n                  subgoal by auto\n                  subgoal using pre(2) unfolding propc_def by auto\n                  subgoal using pre(3) unfolding propc'_def by auto \n                  subgoal using pre(4) unfolding proper'_def properp_def by auto\n                  subgoal using pre(5) unfolding inv_s_def by auto\n                  subgoal using pre(6) unfolding inv_s'_def by auto\n                  by auto\n              subgoal\n                apply(rule combine_assn_ex_pre_right')+\n                apply(rule combine_assn_in0_inrdy)\n                by auto\n              done\n            done\n          subgoal\n            apply(rule combine_assn_ex_pre_left')+\n            apply(rule combine_or_right)\n            subgoal\n              apply(rule combine_assn_ex_pre_right')+\n              apply(rule combine_assn_pure_pre_right')\n              apply(rule combine_assn_in0_waitin)\n              by auto\n            subgoal\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_in0_wait)\n              subgoal by auto\n              apply(simp only:pure_assn_entails)\n              apply(rule impI)\n              apply(rule combine_or_right)\n              subgoal\n               apply(rule entails_tassn_trans)\n                 apply(rule combine_assn_in0_outrdy)\n                by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n              subgoal\n                apply(rule combine_assn_ex_pre_right')+\n                apply(rule combine_assn_in0_inrdy)\n                by auto\n              done\n            done\n          done\n        done\n      done\n    subgoal for k1'\n      apply(cases k2)\n      subgoal\n        apply(simp only:T2_tr.simps)\n        apply(cases st1)\n          apply(simp only:combine1.simps)\n        subgoal premises pre\n          apply(rule combine_or_left)\n          subgoal\n            apply(rule entails_tassn_trans)\n             apply(rule combine_assn_wait_emp'')\n            apply auto\n            apply(subgoal_tac\"9 \\<ge> ts1 T * 200\")\n             prefer 2\n            subgoal using pre(5) unfolding inv_s_def by auto\n            apply auto\n            apply(rule entails_tassn_trans)\n             prefer 2\n             apply(rule pre(1))\n            subgoal by auto\n            subgoal using pre(2) unfolding propc_def by auto\n            subgoal using pre(3) unfolding propc'_def by auto \n            subgoal using pre(4) unfolding proper'_def properp_def by auto\n            subgoal using pre(5) unfolding inv_s_def by auto\n            subgoal using pre(6) unfolding inv_s'_def by auto\n            by auto\n          apply(rule combine_or_left)\n          subgoal\n            apply(rule combine_assn_ex_pre_left')+\n            apply(rule combine_assn_pure_pre_left')\n            apply(auto simp add: combine_assn_waitin_emp)\n            done\n          apply(rule combine_or_left)\n          subgoal\n            apply(rule combine_assn_ex_pre_left')+\n            apply(rule combine_assn_pure_pre_left')\n            apply(auto simp add: combine_assn_waitin_emp)\n            done\n          apply(rule combine_or_left)\n          subgoal\n            apply(rule combine_assn_ex_pre_left')+\n            apply(rule combine_assn_pure_pre_left')\n            apply(auto simp add: combine_assn_waitin_emp)\n            done\n          subgoal\n            apply(rule combine_assn_ex_pre_left')+\n            apply(rule combine_assn_pure_pre_left')\n            apply(auto simp add: combine_assn_waitin_emp)\n            done\n          done\n         apply(simp only:combine1.simps)\n        subgoal premises pre\n          apply(rule combine_or_left)\n          subgoal\n            apply(cases \"rn = 2\")\n            subgoal\n              apply auto\n              apply(rule combine_or_left)\n              subgoal\n                by(auto simp add: combine_assn_out0_emp)\n              apply(rule combine_or_left)\n              subgoal\n                by(auto simp add: combine_assn_waitp_emp)\n              subgoal\n                by(auto simp add: combine_assn_waitp_emp)\n              done\n            apply auto\n            apply(subgoal_tac \"rn=-1\")\n             prefer 2\n            subgoal using pre(2,4) unfolding proper'_def propc_def properp_def by auto\n            apply auto\n            apply(rule entails_tassn_trans)\n             prefer 2\n             apply(rule pre(1))\n            subgoal by auto\n            subgoal using pre(2) unfolding propc_def by auto\n            subgoal using pre(3) unfolding propc'_def by auto \n            subgoal using pre(4) unfolding proper'_def properp_def by auto\n            subgoal using pre(5) unfolding inv_s_def by auto\n            subgoal using pre(6) unfolding inv_s'_def by auto\n            by auto\n          apply(rule combine_or_left)\n          subgoal\n            by(auto simp add: combine_assn_in0_emp)\n          apply(rule combine_or_left)\n          subgoal\n            apply(rule combine_assn_ex_pre_left')+\n            apply(rule combine_assn_pure_pre_left')\n            by(auto simp add: combine_assn_in0_emp)\n          apply(rule combine_or_left)\n          subgoal\n            apply(rule combine_assn_ex_pre_left')+\n            by(auto simp add: combine_assn_in0_emp)\n          subgoal\n            apply(rule combine_assn_ex_pre_left')+\n            by(auto simp add: combine_assn_in0_emp)\n          done\n        apply(simp only:combine1.simps)\n        subgoal premises pre\n          apply(rule combine_or_left)\n          subgoal\n            apply(subgoal_tac\"p = [] \\<and> min (45 / 10 ^ 3 - ts1 T) (1 / 10\\<^sup>2 - C_upd ent1 (ts1 C)) \\<ge>0\")\n             prefer 2\n            subgoal using pre(4,5) unfolding proper'_def inv_s_def C_upd_def \n              apply(cases ent1) by auto\n            apply auto\n            apply(rule entails_tassn_trans)\n             apply(rule combine_assn_wait_emp'')\n            apply auto\n            apply(subgoal_tac \"min (9 / 200 - ts1 T) (1 / 100 - C_upd ent1 (ts1 C)) = 0\")\n            prefer 2\n            subgoal using pre(4,5) unfolding proper'_def inv_s_def C_upd_def \n              apply(cases ent1) by auto\n            apply auto\n            apply(rule entails_tassn_trans)\n             prefer 2\n             apply(rule pre(1))\n            subgoal by auto\n            subgoal using pre(2) unfolding propc_def by auto\n            subgoal using pre(3) unfolding propc'_def by auto \n            subgoal using pre(4) unfolding proper'_def properp_def by auto\n            subgoal using pre(5) unfolding inv_s_def by auto\n            subgoal using pre(6) unfolding inv_s'_def by auto\n            by auto\n          apply(rule combine_or_left)\n          subgoal\n            apply(rule combine_assn_ex_pre_left')+\n            apply(rule combine_assn_pure_pre_left')\n            by(auto simp add: combine_assn_waitin_emp)\n          apply(rule combine_or_left)\n          subgoal\n            apply(rule combine_assn_ex_pre_left')+\n            apply(rule combine_assn_pure_pre_left')\n            by(auto simp add: combine_assn_waitin_emp)\n          apply(rule combine_or_left)\n          subgoal\n            apply(rule combine_assn_ex_pre_left')+\n            apply(rule combine_assn_pure_pre_left')\n            by(auto simp add: combine_assn_waitin_emp)\n          subgoal\n            apply(rule combine_assn_ex_pre_left')+\n            apply(rule combine_assn_pure_pre_left')\n            by(auto simp add: combine_assn_waitin_emp)\n          done\n        done\n\n\n\n      subgoal for k2'\n        apply(cases st1)\n        subgoal\n          apply(cases st2)\n            apply(simp only:combine1.simps T2_tr.simps)\n          subgoal premises pre\n            apply(rule combine_or_left)\n            subgoal\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_wait_wait5)\n              subgoal using pre(5,6) unfolding inv_s_def inv_s'_def\n                by auto\n              apply auto\n              apply(rule entails_tassn_disjE)\n              subgoal\n                apply auto\n                apply(rule entails_tassn_disjI1)\n                apply(rule entails_tassn_cancel_left)\n                apply(rule entails_tassn_trans)\n                 prefer 2\n                 apply(rule pre(1))\n                subgoal by auto\n                subgoal using pre(2) unfolding propc_def by auto\n                subgoal using pre(3) unfolding propc'_def by auto \n                subgoal using pre(4) unfolding proper'_def properp_def by auto\n                subgoal using pre(5) unfolding inv_s_def by auto\n                subgoal using pre(6) unfolding inv_s'_def by auto\n                by auto\n              apply(rule entails_tassn_disjE)\n              subgoal\n                apply auto\n                apply(rule entails_tassn_disjI2)\n                apply(rule entails_tassn_disjI1)\n                apply(rule entails_tassn_cancel_left)\n                apply(rule entails_tassn_trans)\n                 prefer 2\n                 apply(rule pre(1))\n                subgoal by auto\n                subgoal using pre(2) unfolding propc_def by auto\n                subgoal using pre(3) unfolding propc'_def by auto \n                subgoal using pre(4) unfolding proper'_def properp_def by auto\n                subgoal using pre(5) unfolding inv_s_def by auto\n                subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                apply(rule combine_assn_right_tran)\n                unfolding T2_tr.simps\n                apply auto\n                apply(subgoal_tac\"(\\<lambda>t. EState (Task WAIT ent2 1, ts2(T := ts2 T + (9 / 200 - ts1 T) + t))) = (\\<lambda>t. EState (Task WAIT ent2 1, ts2(T := ts2 T + (t + (9 / 200 - ts1 T)))))\")\n                 apply auto\n                apply(rule ext)\n                by auto\n              subgoal\n                apply auto\n                apply(rule entails_tassn_disjI2)\n                apply(rule entails_tassn_disjI2)\n                apply(rule entails_tassn_cancel_left)\n                apply(rule entails_tassn_trans)\n                 prefer 2\n                 apply(rule pre(1))\n                subgoal by auto\n                subgoal using pre(2) unfolding propc_def by auto\n                subgoal using pre(3) unfolding propc'_def by auto \n                subgoal using pre(4) unfolding proper'_def properp_def by auto\n                subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                apply(rule combine_assn_left_tran)\n                unfolding T2_tr.simps\n                apply auto\n                apply(rule entails_tassn_disjI1)\n                apply(subgoal_tac\"(\\<lambda>t. ParState (EState (Sch p rn rp, ss))\n           (EState (Task WAIT ent1 2, ts1(T := ts1 T + (9 / 200 - ts2 T) + t)))) =\n                                   (\\<lambda>t. ParState (EState (Sch p rn rp, ss))\n           (EState (Task WAIT ent1 2, ts1(T := ts1 T + (t + (9 / 200 - ts2 T))))))\")\n                 apply auto\n                apply(rule ext)\n                by auto\n              done\n            apply(rule combine_or_left)\n            subgoal\n              apply(subgoal_tac\"0 \\<le> 9 / 200 - ts1 T \\<and> 0 \\<le> 9 / 200 - ts2 T\")\n               prefer 2\n              subgoal using pre(5,6) unfolding inv_s_def inv_s'_def by auto\n              apply(rule combine_assn_ex_pre_left')+\n              apply(rule combine_assn_pure_pre_left')\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_waitin_wait)\n              subgoal by auto\n              unfolding combine2.simps\n              apply(rule entails_tassn_disjI2)+\n              apply(rule entails_tassn_conj)\n              subgoal by auto\n              apply(simp only:pure_assn_entails)\n              apply(rule impI)\n              apply(rule entails_tassn_cancel_both)\n              subgoal for tt by auto\n              apply(rule entails_tassn_trans)\n                 prefer 2\n                 apply(rule pre(1))\n                subgoal by auto\n                subgoal using pre(2) unfolding propc_def by auto\n                subgoal using pre(3) unfolding propc'_def by auto \n                subgoal using pre(4) unfolding proper'_def properp_def by auto\n                subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                apply(rule combine_assn_left_tran)\n                unfolding combine1.simps\n                apply(rule entails_tassn_disjI2)\n                apply(rule entails_tassn_disjI1)\n                subgoal for tt\n                  apply(rule entails_tassn_exI[where x=\"(tt - (9 / 200 - ts2 T))\"])\n                  apply(rule entails_tassn_conj)\n                  subgoal by auto\n                  apply(rule entails_tassn_cancel_both)\n                  subgoal \n                    apply(subgoal_tac \"(\\<lambda>t. ParState (EState (Sch p rn rp, ss))\n           (EState\n             (Task WAIT ent1 2, ts1\n              (T := ts1 T + (45 / 10 ^ 3 - ts2 T),\n               T := (ts1(T := ts1 T + (45 / 10 ^ 3 - ts2 T))) T + t)))) = \n            (\\<lambda>t. ParState (EState (Sch p rn rp, ss))\n           (EState (Task WAIT ent1 2, ts1(T := ts1 T + (t + (9 / 200 - ts2 T))))))\")\n                     apply auto\n                    apply(rule ext)\n                    apply auto\n                    done\n                  by auto\n                done\n              apply(rule combine_or_left)\n              subgoal\n              apply(subgoal_tac\"0 \\<le> 9 / 200 - ts1 T \\<and> 0 \\<le> 9 / 200 - ts2 T\")\n               prefer 2\n              subgoal using pre(5,6) unfolding inv_s_def inv_s'_def by auto\n              apply(rule combine_assn_ex_pre_left')+\n              apply(rule combine_assn_pure_pre_left')\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_waitin_wait)\n              subgoal by auto\n              unfolding combine2.simps\n              apply(rule entails_tassn_disjI2)+\n              apply(rule entails_tassn_conj)\n              subgoal by auto\n              apply(simp only:pure_assn_entails)\n              apply(rule impI)\n              apply(rule entails_tassn_cancel_both)\n              subgoal for tt by auto\n              apply(rule entails_tassn_trans)\n                 prefer 2\n                 apply(rule pre(1))\n                subgoal by auto\n                subgoal using pre(2) unfolding propc_def by auto\n                subgoal using pre(3) unfolding propc'_def by auto \n                subgoal using pre(4) unfolding proper'_def properp_def by auto\n                subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                apply(rule combine_assn_left_tran)\n                unfolding combine1.simps\n                apply(rule entails_tassn_disjI2)\n                apply(rule entails_tassn_disjI2)\n                apply(rule entails_tassn_disjI1)\n                subgoal for tt v\n                  apply(rule entails_tassn_exI[where x=\"(tt - (9 / 200 - ts2 T))\"])\n                  apply(rule entails_tassn_exI[where x=v])\n                  apply(rule entails_tassn_conj)\n                  subgoal by auto\n                  apply(rule entails_tassn_cancel_both)\n                  subgoal \n                    apply(subgoal_tac \"(\\<lambda>t. ParState (EState (Sch p rn rp, ss))\n           (EState\n             (Task WAIT ent1 2, ts1\n              (T := ts1 T + (45 / 10 ^ 3 - ts2 T),\n               T := (ts1(T := ts1 T + (45 / 10 ^ 3 - ts2 T))) T + t)))) = \n            (\\<lambda>t. ParState (EState (Sch p rn rp, ss))\n           (EState (Task WAIT ent1 2, ts1(T := ts1 T + (t + (9 / 200 - ts2 T))))))\")\n                     apply auto\n                    apply(rule ext)\n                    apply auto\n                    done\n                  by auto\n                done\n              apply(rule combine_or_left)\n              subgoal\n              apply(subgoal_tac\"0 \\<le> 9 / 200 - ts1 T \\<and> 0 \\<le> 9 / 200 - ts2 T\")\n               prefer 2\n              subgoal using pre(5,6) unfolding inv_s_def inv_s'_def by auto\n              apply(rule combine_assn_ex_pre_left')+\n              apply(rule combine_assn_pure_pre_left')\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_waitin_wait)\n              subgoal by auto\n              unfolding combine2.simps\n              apply(rule entails_tassn_disjI2)+\n              apply(rule entails_tassn_conj)\n              subgoal by auto\n              apply(simp only:pure_assn_entails)\n              apply(rule impI)\n              apply(rule entails_tassn_cancel_both)\n              subgoal for tt by auto\n              apply(rule entails_tassn_trans)\n                 prefer 2\n                 apply(rule pre(1))\n                subgoal by auto\n                subgoal using pre(2) unfolding propc_def by auto\n                subgoal using pre(3) unfolding propc'_def by auto \n                subgoal using pre(4) unfolding proper'_def properp_def by auto\n                subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                apply(rule combine_assn_left_tran)\n                unfolding combine1.simps\n                apply(rule entails_tassn_disjI2)\n                apply(rule entails_tassn_disjI2)\n                apply(rule entails_tassn_disjI2)\n                apply(rule entails_tassn_disjI1)\n                subgoal for tt v\n                  apply(rule entails_tassn_exI[where x=\"(tt - (9 / 200 - ts2 T))\"])\n                  apply(rule entails_tassn_exI[where x=v])\n                  apply(rule entails_tassn_conj)\n                  subgoal by auto\n                  apply(rule entails_tassn_cancel_both)\n                  subgoal \n                    apply(subgoal_tac \"(\\<lambda>t. ParState (EState (Sch p rn rp, ss))\n           (EState\n             (Task WAIT ent1 2, ts1\n              (T := ts1 T + (45 / 10 ^ 3 - ts2 T),\n               T := (ts1(T := ts1 T + (45 / 10 ^ 3 - ts2 T))) T + t)))) = \n            (\\<lambda>t. ParState (EState (Sch p rn rp, ss))\n           (EState (Task WAIT ent1 2, ts1(T := ts1 T + (t + (9 / 200 - ts2 T))))))\")\n                     apply auto\n                    apply(rule ext)\n                    apply auto\n                    done\n                  by auto\n                done\n              subgoal\n              apply(subgoal_tac\"0 \\<le> 9 / 200 - ts1 T \\<and> 0 \\<le> 9 / 200 - ts2 T\")\n               prefer 2\n              subgoal using pre(5,6) unfolding inv_s_def inv_s'_def by auto\n              apply(rule combine_assn_ex_pre_left')+\n              apply(rule combine_assn_pure_pre_left')\n              apply(rule entails_tassn_trans)\n               apply(rule combine_assn_waitin_wait)\n              subgoal by auto\n              unfolding combine2.simps\n              apply(rule entails_tassn_disjI2)+\n              apply(rule entails_tassn_conj)\n              subgoal by auto\n              apply(simp only:pure_assn_entails)\n              apply(rule impI)\n              apply(rule entails_tassn_cancel_both)\n              subgoal for tt by auto\n              apply(rule entails_tassn_trans)\n                 prefer 2\n                 apply(rule pre(1))\n                subgoal by auto\n                subgoal using pre(2) unfolding propc_def by auto\n                subgoal using pre(3) unfolding propc'_def by auto \n                subgoal using pre(4) unfolding proper'_def properp_def by auto\n                subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                apply(rule combine_assn_left_tran)\n                unfolding combine1.simps\n                apply(rule entails_tassn_disjI2)\n                apply(rule entails_tassn_disjI2)\n                apply(rule entails_tassn_disjI2)\n                apply(rule entails_tassn_disjI2)\n                subgoal for tt v\n                  apply(rule entails_tassn_exI[where x=\"(tt - (9 / 200 - ts2 T))\"])\n                  apply(rule entails_tassn_exI[where x=v])\n                  apply(rule entails_tassn_conj)\n                  subgoal by auto\n                  apply(rule entails_tassn_cancel_both)\n                  subgoal \n                    apply(subgoal_tac \"(\\<lambda>t. ParState (EState (Sch p rn rp, ss))\n           (EState\n             (Task WAIT ent1 2, ts1\n              (T := ts1 T + (45 / 10 ^ 3 - ts2 T),\n               T := (ts1(T := ts1 T + (45 / 10 ^ 3 - ts2 T))) T + t)))) = \n            (\\<lambda>t. ParState (EState (Sch p rn rp, ss))\n           (EState (Task WAIT ent1 2, ts1(T := ts1 T + (t + (9 / 200 - ts2 T))))))\")\n                     apply auto\n                    apply(rule ext)\n                    apply auto\n                    done\n                  by auto\n                done\n              done\n\n\n\n\n\n             apply(simp only:combine1.simps T2_tr.simps)\n            subgoal premises pre\n              apply(cases \"(9 / 200 - ts1 T) = 0\")\n              subgoal\n                apply simp\n                apply(rule entails_tassn_disjI1)\n                apply(rule combine_or_left)\n                subgoal\n                  apply(rule entails_tassn_trans)\n                   prefer 2\n                   apply(rule pre(1))\n                  subgoal by auto\n                  subgoal using pre(2) unfolding propc_def by auto\n                  subgoal using pre(3) unfolding propc'_def by auto \n                  subgoal using pre(4) unfolding proper'_def properp_def by auto\n                  subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                  subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                  apply(rule combine_assn_right_tran)\n                  by auto\n                apply(rule combine_or_left)\n                subgoal\n                  apply(rule combine_assn_ex_pre_left')+\n                  apply(rule combine_assn_pure_pre_left')\n                  by auto\n                apply(rule combine_or_left)\n                subgoal\n                  apply(rule combine_assn_ex_pre_left')+\n                  apply(rule combine_assn_pure_pre_left')\n                  by auto\n                apply(rule combine_or_left)\n                subgoal\n                  apply(rule combine_assn_ex_pre_left')+\n                  apply(rule combine_assn_pure_pre_left')\n                  by auto\n                subgoal\n                  apply(rule combine_assn_ex_pre_left')+\n                  apply(rule combine_assn_pure_pre_left')\n                  by auto\n                done\n              apply(subgoal_tac\"9 / 200 - ts1 T >0\")\n               prefer 2\n                subgoal using pre(5) unfolding inv_s_def by auto\n                apply auto\n                apply(rule entails_tassn_disjI2)\n              apply(rule combine_or_left)\n              subgoal\n                apply(rule combine_or_right)\n                subgoal\n                  apply(rule combine_assn_ex_pre_right')+\n                  apply(rule combine_assn_pure_pre_right')\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_wait_out)\n                  by auto\n                subgoal\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_wait_out)\n                  by auto\n                done\n              apply(rule combine_or_left)\n              subgoal\n                apply(subgoal_tac\"rp = -1\")\n                 prefer 2\n                subgoal\n                  using pre(2,3,4) unfolding propc_def propc'_def proper'_def properp_def by auto\n                apply(rule combine_assn_ex_pre_left')+\n                apply(rule combine_assn_pure_pre_left')\n                apply(rule combine_or_right)\n                subgoal for tt\n                  apply(rule combine_assn_ex_pre_right')+\n                  apply(rule combine_assn_pure_pre_right')\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_waitin_out)\n                  subgoal by auto\n                  apply auto\n                  apply(rule combine_or_left)\n                  subgoal for v tta\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_assn_out0_waitin1)\n                    subgoal by auto\n                    apply auto\n                    apply(rule entails_tassn_trans)\n                     prefer 2\n                     apply(rule pre(1))\n                    subgoal by auto\n                    subgoal using pre(2) unfolding propc_def by auto\n                    subgoal using pre(3) unfolding propc'_def by auto \n                    subgoal using pre(4) unfolding proper'_def properp_def by auto\n                    subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                    subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                    by auto\n                  subgoal for v tta\n                    apply(rule combine_assn_waitp_waitin')\n                    by auto\n                  done\n                subgoal for tt\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_waitin_out)\n                  subgoal by auto\n                  apply auto\n                  apply(rule combine_or_left)\n                  subgoal\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_assn_out0_wait'')\n                    subgoal by auto\n                    apply auto\n                    apply(subgoal_tac\"9 = ts2 T * 200\")\n                     prefer 2\n                    subgoal using pre(6) unfolding inv_s'_def by auto\n                    apply auto\n                    apply(rule combine_or_right)\n                    subgoal\n                      apply(rule combine_assn_out0_outrdy)\n                      by auto\n                    subgoal\n                      apply(rule combine_assn_ex_pre_right')\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_out0_inrdy)\n                       apply auto\n                      apply(rule entails_tassn_trans)\n                       prefer 2\n                       apply(rule pre(1))\n                      subgoal by auto\n                      subgoal using pre(2) unfolding propc_def by auto\n                      subgoal using pre(3) unfolding propc'_def by auto \n                      subgoal using pre(4) unfolding proper'_def properp_def by auto\n                      subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                      subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                      apply(subgoal_tac\"ts2(F := 0) = ts2(T := 9 / 200, F := 0)\")\n                      by auto\n                    done\n                  subgoal\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_assn_waitp_wait'')\n                     apply auto\n                    apply(rule combine_or_right)\n                    subgoal\n                      apply(rule combine_assn_waitp_outrdy')\n                      by auto\n                    subgoal\n                      apply(rule combine_assn_ex_pre_right')\n                      apply(rule combine_assn_waitp_inrdy')\n                      by auto\n                    done\n                  done\n                done\n              apply(rule combine_or_left)\n              subgoal\n                apply(rule combine_assn_ex_pre_left')+\n                apply(rule combine_assn_pure_pre_left')\n                apply(rule combine_or_right)\n                subgoal for tt v\n                  apply(rule combine_assn_ex_pre_right')+\n                  apply(rule combine_assn_pure_pre_right')\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_waitin_out)\n                  by auto\n                subgoal\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_waitin_out)\n                  by auto\n                done\n              apply(rule combine_or_left)\n              subgoal\n                apply(rule combine_assn_ex_pre_left')+\n                apply(rule combine_assn_pure_pre_left')\n                apply(rule combine_or_right)\n                subgoal for tt v\n                  apply(rule combine_assn_ex_pre_right')+\n                  apply(rule combine_assn_pure_pre_right')\n                  apply(rule combine_assn_waitin_out'')\n                  by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                subgoal\n                  apply(rule combine_assn_waitin_out'')\n                  by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                done\n             subgoal\n                apply(rule combine_assn_ex_pre_left')+\n                apply(rule combine_assn_pure_pre_left')\n                apply(rule combine_or_right)\n                subgoal for tt v\n                  apply(rule combine_assn_ex_pre_right')+\n                  apply(rule combine_assn_pure_pre_right')\n                  apply(rule combine_assn_waitin_out'')\n                  by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                subgoal\n                  apply(rule combine_assn_waitin_out'')\n                  by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                done\n              done\n\n\n\n              apply(simp only:combine1.simps T2_tr.simps)\n            subgoal premises pre\n              apply(subgoal_tac\"(9 / 200 - ts1 T)\\<ge>0 \\<and> min (45 / 10 ^ 3 - ts2 T) (2 / 10\\<^sup>2 - C_upd ent2 (ts2 C)) \\<ge>0\")\n               prefer 2\n              subgoal using pre(5,6) unfolding inv_s_def inv_s'_def C_upd_def C_def T_def\n                apply(cases ent2) by auto\n              apply(cases \"min (45 / 10 ^ 3 - ts2 T) (2 / 10\\<^sup>2 - C_upd ent2 (ts2 C)) \\<ge> (9 / 200 - ts1 T)\")\n              subgoal\n                unfolding combine2.simps\n                apply(rule entails_tassn_disjI1)\n                apply(rule combine_or_left)\n                subgoal\n                  apply(rule combine_or_right)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_right')+\n                    apply(rule combine_assn_pure_pre_right')\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_assn_wait_waitin)\n                    subgoal by auto\n                    apply auto\n                    apply(rule entails_tassn_cancel_left)\n                    apply(rule entails_tassn_trans)\n                       prefer 2\n                       apply(rule pre(1))\n                      subgoal by auto\n                      subgoal using pre(2) unfolding propc_def by auto\n                      subgoal using pre(3) unfolding propc'_def by auto \n                      subgoal using pre(4) unfolding proper'_def properp_def by auto\n                      subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                      subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                      apply(rule combine_assn_right_tran)\n                      unfolding T2_tr.simps\n                      apply(rule entails_tassn_disjI1)\n                      subgoal for v tt\n                        apply(rule entails_tassn_exI[where x=v])\n                        apply(rule entails_tassn_exI[where x=\"tt - (9 / 200 - ts1 T)\"])\n                        apply (auto simp add:T_def C_def)\n                        apply(rule entails_tassn_cancel_right)\n                        apply(subgoal_tac\"(\\<lambda>t. EState\n           (Task RUNNING eone 1, ts2\n            (CHR ''t'' := ts2 CHR ''t'' + (9 / 200 - ts1 CHR ''t'') + t,\n             CHR ''c'' := C_upd ent2 (ts2 CHR ''c'') + (9 / 200 - ts1 CHR ''t'') + t))) =\n                                          (\\<lambda>t. EState\n           (Task RUNNING eone 1, ts2\n            (CHR ''t'' := ts2 CHR ''t'' + (t + (9 / 200 - ts1 CHR ''t'')),\n             CHR ''c'' := C_upd ent2 (ts2 CHR ''c'') + (t + (9 / 200 - ts1 CHR ''t'')))))\")\n                         apply auto\n                        apply(rule ext)\n                        by auto\n                      done\n                    subgoal\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_wait_wait3')\n                       apply auto\n                      apply(rule entails_tassn_cancel_left)\n                      apply(rule entails_tassn_trans)\n                       prefer 2\n                       apply(rule pre(1))\n                      subgoal by auto\n                      subgoal using pre(2) unfolding propc_def by auto\n                      subgoal using pre(3) unfolding propc'_def by auto \n                      subgoal using pre(4) unfolding proper'_def properp_def by auto\n                      subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                      subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                      apply(rule combine_assn_right_tran)\n                      unfolding T2_tr.simps\n                      apply(rule entails_tassn_disjI2)\n                      apply(auto simp add:C_def T_def)\n                      apply(rule entails_tassn_cancel_both)\n                      subgoal premises pre'\n                      proof-\n                        have 1:\"(min (ts1 CHR ''t'' - ts2 CHR ''t'')\n                                    (ts1 CHR ''t'' - C_upd ent2 (ts2 CHR ''c'') - 1 / 40)) =\n                (min (9 / 200 - ts2 CHR ''t'') (1 / 50 - C_upd ent2 (ts2 CHR ''c'')) -\n                          (9 / 200 - ts1 CHR ''t''))\"\n                          by auto\n                        have 2:\"(\\<lambda>\\<tau>. EState\n           (Task RUNNING eone 1, ts2\n            (CHR ''t'' := ts2 CHR ''t'' + (9 / 200 - ts1 CHR ''t'') + \\<tau>,\n             CHR ''c'' := C_upd ent2 (ts2 CHR ''c'') + (9 / 200 - ts1 CHR ''t'') + \\<tau>))) =\n                                  (\\<lambda>t. EState\n           (Task RUNNING eone 1, ts2\n            (CHR ''t'' := ts2 CHR ''t'' + (t + (9 / 200 - ts1 CHR ''t'')),\n             CHR ''c'' := C_upd ent2 (ts2 CHR ''c'') + (t + (9 / 200 - ts1 CHR ''t'')))))\"\n                          apply(rule ext)\n                          by auto\n                        show ?thesis\n                          by(simp add:1 2)\n                      qed\n                      apply(subgoal_tac \"ts2\n      (CHR ''t'' :=\n         ts2 CHR ''t'' + (9 / 200 - ts1 CHR ''t'') +\n         min (ts1 CHR ''t'' - ts2 CHR ''t'')\n          (ts1 CHR ''t'' - C_upd ent2 (ts2 CHR ''c'') - 1 / 40),\n       CHR ''c'' :=\n         C_upd ent2 (ts2 CHR ''c'') + (9 / 200 - ts1 CHR ''t'') +\n         min (ts1 CHR ''t'' - ts2 CHR ''t'')\n          (ts1 CHR ''t'' - C_upd ent2 (ts2 CHR ''c'') - 1 / 40)) = \nts2\n       (CHR ''t'' :=\n          ts2 CHR ''t'' +\n          min (9 / 200 - ts2 CHR ''t'') (1 / 50 - C_upd ent2 (ts2 CHR ''c'')),\n        CHR ''c'' :=\n          C_upd ent2 (ts2 CHR ''c'') +\n          min (9 / 200 - ts2 CHR ''t'') (1 / 50 - C_upd ent2 (ts2 CHR ''c'')))\")\n                       apply auto\n                      apply(rule ext)\n                      by auto\n                    done\n                  apply(rule combine_or_left)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_left')+\n                    apply(rule combine_assn_pure_pre_left')\n                    apply(rule combine_or_right)\n                    subgoal for tt\n                      apply(rule combine_assn_ex_pre_right')+\n                      apply(rule combine_assn_pure_pre_right')\n                      apply(rule combine_assn_waitin_waitin)\n                      by auto\n                    subgoal for tt\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_waitin_wait)\n                      by auto\n                    done\n                  apply(rule combine_or_left)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_left')+\n                    apply(rule combine_assn_pure_pre_left')\n                    apply(rule combine_or_right)\n                    subgoal for tt\n                      apply(rule combine_assn_ex_pre_right')+\n                      apply(rule combine_assn_pure_pre_right')\n                      apply(rule combine_assn_waitin_waitin)\n                      by auto\n                    subgoal for tt\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_waitin_wait)\n                      by auto\n                    done\n                  apply(rule combine_or_left)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_left')+\n                    apply(rule combine_assn_pure_pre_left')\n                    apply(rule combine_or_right)\n                    subgoal for tt\n                      apply(rule combine_assn_ex_pre_right')+\n                      apply(rule combine_assn_pure_pre_right')\n                      apply(rule combine_assn_waitin_waitin)\n                      by auto\n                    subgoal for tt\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_waitin_wait)\n                      by auto\n                    done\n                  subgoal\n                    apply(rule combine_assn_ex_pre_left')+\n                    apply(rule combine_assn_pure_pre_left')\n                    apply(rule combine_or_right)\n                    subgoal for tt\n                      apply(rule combine_assn_ex_pre_right')+\n                      apply(rule combine_assn_pure_pre_right')\n                      apply(rule combine_assn_waitin_waitin)\n                      by auto\n                    subgoal for tt\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_waitin_wait)\n                      by auto\n                    done\n                  done\n                subgoal\n                  apply(subgoal_tac\"min (45 / 10 ^ 3 - ts2 T) (2 / 10\\<^sup>2 - C_upd ent2 (ts2 C)) < 9 / 200 - ts1 T\")\n                   prefer 2\n                  subgoal by auto\n                  unfolding combine2.simps\n                  apply(rule entails_tassn_disjI2)\n                  apply(rule combine_or_left)\n                  subgoal\n                    apply(rule combine_or_right)\n                    subgoal\n                      apply(rule combine_assn_ex_pre_right')+\n                      apply(rule combine_assn_pure_pre_right')\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_wait_waitin)\n                      by auto\n                    subgoal \n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_wait_wait4)\n                      subgoal by auto\n                      apply(rule entails_tassn_conj)\n                      subgoal by auto\n                      apply(rule entails_tassn_cancel_both)\n                      subgoal by auto\n                      apply(rule combine_or_right)\n                      subgoal\n                        apply(rule entails_tassn_trans)\n                         apply(rule combine_assn_wait_outrdy)\n                        by auto\n                      subgoal\n                        apply(rule combine_assn_ex_pre_right')+\n                        apply(rule entails_tassn_trans)\n                         apply(rule combine_assn_wait_inrdy)\n                        by auto\n                      done\n                    done\n                  apply(rule combine_or_left)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_left')+\n                    apply(rule combine_assn_pure_pre_left')\n                    apply(rule combine_or_right)\n                    subgoal\n                      apply(rule combine_assn_ex_pre_right')+\n                      apply(rule combine_assn_pure_pre_right')\n                      apply(rule combine_assn_waitin_waitin)\n                      by auto\n                    subgoal for tt\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_waitin_wait)\n                      subgoal by auto\n                      apply(rule entails_tassn_conj)\n                      subgoal by auto\n                      apply(simp only:pure_assn_entails)\n                      apply(rule impI)\n                      apply(rule entails_tassn_cancel_both)\n                      subgoal by auto\n                      apply(rule combine_or_right)\n                      subgoal\n                        apply(rule entails_tassn_trans)\n                         apply(rule combine_assn_waitin_outrdy)\n                        by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                      subgoal\n                        apply(rule combine_assn_ex_pre_right')+\n                        apply(rule combine_assn_waitin_inrdy)\n                        by auto\n                      done\n                    done   \n                  apply(rule combine_or_left)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_left')+\n                    apply(rule combine_assn_pure_pre_left')\n                    apply(rule combine_or_right)\n                    subgoal\n                      apply(rule combine_assn_ex_pre_right')+\n                      apply(rule combine_assn_pure_pre_right')\n                      apply(rule combine_assn_waitin_waitin)\n                      by auto\n                    subgoal for tt\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_waitin_wait)\n                      subgoal by auto\n                      apply(rule entails_tassn_conj)\n                      subgoal by auto\n                      apply(simp only:pure_assn_entails)\n                      apply(rule impI)\n                      apply(rule entails_tassn_cancel_both)\n                      subgoal by auto\n                      apply(rule combine_or_right)\n                      subgoal\n                        apply(rule entails_tassn_trans)\n                         apply(rule combine_assn_waitin_outrdy)\n                        by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                      subgoal\n                        apply(rule combine_assn_ex_pre_right')+\n                        apply(rule combine_assn_waitin_inrdy)\n                        by auto\n                      done\n                    done\n                  apply(rule combine_or_left)\n                  subgoal \n                    apply(rule combine_assn_ex_pre_left')+\n                    apply(rule combine_assn_pure_pre_left')\n                    apply(rule combine_or_right)\n                    subgoal\n                      apply(rule combine_assn_ex_pre_right')+\n                      apply(rule combine_assn_pure_pre_right')\n                      apply(rule combine_assn_waitin_waitin)\n                      by auto\n                    subgoal for tt v\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_waitin_wait)\n                      subgoal by auto\n                      apply(rule entails_tassn_conj)\n                      subgoal by auto\n                      apply(simp only:pure_assn_entails)\n                      apply(rule impI)\n                      apply(rule entails_tassn_cancel_both)\n                      subgoal by auto\n                      apply(rule combine_or_right)\n                      subgoal\n                        apply(rule entails_tassn_trans)\n                         apply(rule combine_assn_waitin_outrdy)\n                        subgoal by auto\n                        apply(subgoal_tac\"p=[]\")\n                         prefer 2\n                        subgoal using pre(4) unfolding proper'_def by auto\n                        apply simp\n                        apply(rule impI)\n                        apply(rule entails_tassn_trans)\n                         prefer 2\n                         apply(rule pre(1))\n                        subgoal by auto\n                        subgoal using pre(2) unfolding propc_def by auto\n                        subgoal using pre(3) unfolding propc'_def by auto \n                        subgoal using pre(4) unfolding proper'_def properp_def by auto\n                        subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                        subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                        apply(subgoal_tac\"min (9 / 200 - ts2 T) (1 / 50 - C_upd ent2 (ts2 C)) = tt\")\n                        by auto\n                      subgoal\n                        apply(rule combine_assn_ex_pre_right')+\n                        apply(rule combine_assn_waitin_inrdy)\n                        by auto\n                      done\n                    done\n                  subgoal\n                    apply(rule combine_assn_ex_pre_left')+\n                    apply(rule combine_assn_pure_pre_left')\n                    apply(rule combine_or_right)\n                    subgoal\n                      apply(rule combine_assn_ex_pre_right')+\n                      apply(rule combine_assn_pure_pre_right')\n                      apply(rule combine_assn_waitin_waitin)\n                      by auto\n                    subgoal for tt\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_waitin_wait)\n                      subgoal by auto\n                      apply(rule entails_tassn_conj)\n                      subgoal by auto\n                      apply(simp only:pure_assn_entails)\n                      apply(rule impI)\n                      apply(rule entails_tassn_cancel_both)\n                      subgoal by auto\n                      apply(rule combine_or_right)\n                      subgoal\n                        apply(rule entails_tassn_trans)\n                         apply(rule combine_assn_waitin_outrdy)\n                        by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                      subgoal\n                        apply(rule combine_assn_ex_pre_right')+\n                        apply(rule combine_assn_waitin_inrdy)\n                        by auto\n                      done\n                    done\n                  done\n                done\n              done\n\n\n\n            subgoal\n          apply(cases st2)           \n            apply(simp only:combine1.simps T2_tr.simps)\n              subgoal premises pre\n                apply(cases \"(9 / 200 - ts2 T) = 0\")\n                subgoal\n                  unfolding combine2.simps\n                  apply(rule entails_tassn_disjI1)\n                  apply(rule entails_tassn_conj)\n                  subgoal by auto\n                  apply(rule entails_tassn_trans)\n                   prefer 2\n                   apply(rule pre(1))\n                  subgoal by auto\n                  subgoal using pre(2) unfolding propc_def by auto\n                  subgoal using pre(3) unfolding propc'_def by auto \n                  subgoal using pre(4) unfolding proper'_def properp_def by auto\n                  subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                  subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                  apply(rule combine_assn_both_tran)\n                   apply auto\n                  done\n                subgoal\n                  unfolding combine2.simps\n                  apply(rule entails_tassn_disjI2)\n                  apply(subgoal_tac \"0 < 9 / 200 - ts2 T \\<and> rn = -1 \\<and> rp = -1 \\<and> p =[]\")\n                   prefer 2\n                  subgoal using pre(2,3,4,6) unfolding propc_def propc'_def proper'_def properp_def inv_s'_def \n                    by auto\n                  apply auto\n                  apply(rule combine_or_left)\n                  subgoal\n                    apply(rule entails_tassn_trans)\n                     prefer 2\n                     apply(rule pre(1))\n                    subgoal by auto\n                    subgoal using pre(2) unfolding propc_def by auto\n                    subgoal using pre(3) unfolding propc'_def by auto \n                    subgoal using pre(4) unfolding proper'_def properp_def by auto\n                    subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                    subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                    by auto\n                  apply(rule combine_or_left)\n                  subgoal\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_assn_in0_wait)\n                    by auto\n                  apply(rule combine_or_left)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_left')+\n                    apply(rule combine_assn_pure_pre_left')\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_assn_in0_wait)\n                    by auto\n                  apply(rule combine_or_left)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_left')+\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_assn_in0_wait)\n                    by auto\n                  subgoal\n                    apply(rule combine_assn_ex_pre_left')+\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_assn_in0_wait)\n                    by auto\n                  done\n                done\n\n\n\n\n\n               apply(simp only:combine1.simps T2_tr.simps)\n              subgoal premises pre\n                apply(subgoal_tac \"rn = -1 \\<and> rp = -1 \\<and> p =[]\")\n                   prefer 2\n                  subgoal using pre(2,3,4,6) unfolding propc_def propc'_def proper'_def properp_def inv_s'_def \n                    by auto\n                  apply auto\n                  apply(rule combine_or_left)\n                  subgoal\n                    apply(rule entails_tassn_disjI1)\n                    apply(rule entails_tassn_trans)\n                     prefer 2\n                     apply(rule pre(1))\n                    subgoal by auto\n                    subgoal using pre(2) unfolding propc_def by auto\n                    subgoal using pre(3) unfolding propc'_def by auto \n                    subgoal using pre(4) unfolding proper'_def properp_def by auto\n                    subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                    subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                    by auto\n                  apply(rule combine_or_left)\n                  subgoal\n                    apply(rule entails_tassn_disjI2)\n                    apply(rule combine_or_right)\n                    subgoal\n                      apply(rule combine_assn_ex_pre_right')+\n                      apply(rule combine_assn_pure_pre_right')\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_in0_out)\n                      subgoal by auto\n                      apply auto\n                      apply(rule combine_or_left)\n                      subgoal for v tt\n                        apply(rule entails_tassn_trans)\n                         apply(rule combine_assn_out0_waitin)\n                        subgoal by auto\n                        apply auto\n                        apply(rule entails_tassn_trans)\n                         prefer 2\n                         apply(rule pre(1))\n                        subgoal by auto\n                        subgoal using pre(2) unfolding propc_def by auto\n                        subgoal using pre(3) unfolding propc'_def by auto \n                        subgoal using pre(4) unfolding proper'_def properp_def by auto\n                        subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                        subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                        by auto\n                      subgoal for v tt\n                        apply(rule combine_assn_waitp_waitin')\n                        by auto\n                      done\n                    subgoal\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_in0_out)\n                      subgoal by auto\n                      apply auto\n                      apply(rule combine_or_left)\n                       apply(rule entails_tassn_trans)\n                        apply(rule combine_assn_out0_wait'')\n                        apply auto\n                       apply(rule combine_or_right)\n                      subgoal\n                        apply(rule combine_assn_out0_outrdy)\n                        by auto\n                      subgoal\n                        apply(rule combine_assn_ex_pre_right')+\n                        apply(rule entails_tassn_trans)\n                         apply(rule combine_assn_out0_inrdy)\n                         apply auto\n                        apply(rule entails_tassn_trans)\n                         prefer 2\n                         apply(rule pre(1))\n                        subgoal by auto\n                        subgoal using pre(2) unfolding propc_def by auto\n                        subgoal using pre(3) unfolding propc'_def by auto \n                        subgoal using pre(4) unfolding proper'_def properp_def by auto\n                        subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                        subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                        apply(subgoal_tac\"ts2(F := 0) = ts2(T := 9 / 200, F := 0)\")\n                         apply auto\n                        using pre(6) unfolding inv_s'_def T_def F_def\n                        by auto\n                      subgoal\n                        apply(rule entails_tassn_trans)\n                         apply(rule combine_assn_waitp_wait'')\n                         apply auto\n                        apply(rule combine_or_right)\n                        subgoal\n                          apply(rule combine_assn_waitp_outrdy')\n                          by auto\n                        subgoal\n                          apply(rule combine_assn_ex_pre_right')+\n                          apply(rule combine_assn_waitp_inrdy')\n                          by auto\n                        done\n                      done\n                    done\n                  apply(rule combine_or_left)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_left')+\n                    apply(rule combine_assn_pure_pre_left')\n                    apply(rule combine_or_right)\n                    subgoal for v\n                      apply(rule combine_assn_ex_pre_right')+\n                      apply(rule combine_assn_pure_pre_right')\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_in0_out)\n                      by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                    subgoal\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_in0_out)\n                      by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                    done\n                  apply(rule combine_or_left)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_left')+\n                    apply(rule combine_or_right)\n                    subgoal for v\n                      apply(rule combine_assn_ex_pre_right')+\n                      apply(rule combine_assn_pure_pre_right')\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_in0_out)\n                      by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                    subgoal\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_in0_out)\n                      by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                    done\n                  subgoal\n                    apply(rule combine_assn_ex_pre_left')+\n                    apply(rule combine_or_right)\n                    subgoal for v\n                      apply(rule combine_assn_ex_pre_right')+\n                      apply(rule combine_assn_pure_pre_right')\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_in0_out)\n                      by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                    subgoal\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_in0_out)\n                      by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                    done\n                  done\n\n\n\n\n                apply(simp only:combine1.simps T2_tr.simps)\n                subgoal premises pre\n                  apply(rule combine_or_left)\n                  subgoal\n                   apply(subgoal_tac \"rn = 2\")\n                    prefer 2 \n                  subgoal using pre(3) unfolding propc'_def by auto\n                  apply(rule combine_or_right)\n                  subgoal\n                    apply simp\n                    apply(rule combine_assn_ex_pre_right')+\n                    apply(rule combine_assn_pure_pre_right')\n                    apply(rule combine_or_left)\n                    subgoal for v tt\n                      apply(rule entails_tassn_disjI1)\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_out0_waitin)\n                      apply auto\n                      apply(rule entails_tassn_trans)\n                         prefer 2\n                         apply(rule pre(1))\n                      subgoal by auto\n                      subgoal using pre(2) unfolding propc_def by auto\n                      subgoal using pre(3) unfolding propc'_def by auto \n                      subgoal using pre(4) unfolding proper'_def properp_def by auto\n                      subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                      subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                      by auto\n                    apply(rule combine_or_left)\n                    subgoal for v tt\n                      apply(rule combine_assn_waitp_waitin')\n                      by auto\n                    subgoal for v tt\n                      apply(rule combine_assn_waitp_waitin')\n                      by auto\n                    done\n                  apply simp\n                  subgoal\n                    apply(rule combine_or_left)\n                    subgoal\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_out0_wait'')\n                       apply auto\n                      apply(rule combine_or_right)\n                      subgoal\n                        apply(rule combine_assn_out0_outrdy)\n                        by auto\n                      subgoal\n                        apply(rule entails_tassn_disjI2)\n                        apply(rule entails_tassn_disjI1)\n                        apply(rule combine_assn_ex_pre_right')+\n                        apply(rule entails_tassn_trans)\n                         apply(rule combine_assn_out0_inrdy)\n                         apply auto\n                        apply(subgoal_tac\"min (9 / 200 - ts2 T) (1 / 50 - C_upd ent2 (ts2 C)) = 0\")\n                         prefer 2\n                        subgoal using pre(6) unfolding inv_s'_def  C_upd_def C_def T_def\n                          apply(cases ent2) by auto\n                        apply auto\n                        apply(rule entails_tassn_trans)\n                         prefer 2\n                         apply(rule pre(1))\n                        subgoal by auto\n                        subgoal using pre(2) unfolding propc_def by auto\n                        subgoal using pre(3) unfolding propc'_def by auto \n                        subgoal using pre(4) unfolding proper'_def properp_def by auto\n                        subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                        subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                        by auto\n                      done\n                    apply(rule combine_or_left)\n                    subgoal\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_waitp_wait'')\n                       apply auto\n                      apply(rule combine_or_right)\n                      subgoal\n                        apply(rule combine_assn_waitp_outrdy')\n                        by auto\n                      subgoal\n                        apply(rule combine_assn_ex_pre_right')+\n                        apply(rule combine_assn_waitp_inrdy')\n                        by auto\n                      done\n                    subgoal\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_waitp_wait'')\n                       apply auto\n                      apply(rule combine_or_right)\n                      subgoal\n                        apply(rule combine_assn_waitp_outrdy')\n                        by auto\n                      subgoal\n                        apply(rule combine_assn_ex_pre_right')+\n                        apply(rule combine_assn_waitp_inrdy')\n                        by auto\n                      done\n                    done\n                  done\n                apply(rule combine_or_left)\n                subgoal\n                  apply(rule combine_or_right)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_right')+\n                    apply(rule combine_assn_pure_pre_right')\n                    apply(rule combine_assn_in0_waitin)\n                    by auto\n                  subgoal\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_assn_in0_wait)\n                    subgoal by auto\n                    apply(simp only:pure_assn_entails)\n                    apply(rule impI)\n                    apply(rule combine_or_right)\n                    subgoal\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_in0_outrdy)\n                      by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                    subgoal\n                      apply(rule combine_assn_ex_pre_right')+\n                      apply(rule combine_assn_in0_inrdy)\n                      by auto\n                    done\n                  done\n                apply(rule combine_or_left)\n                subgoal\n                  apply(rule combine_assn_ex_pre_left')+\n                    apply(rule combine_assn_pure_pre_left')\n                  apply(rule combine_or_right)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_right')+\n                    apply(rule combine_assn_pure_pre_right')\n                    apply(rule combine_assn_in0_waitin)\n                    by auto\n                  subgoal\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_assn_in0_wait)\n                    subgoal by auto\n                    apply(simp only:pure_assn_entails)\n                    apply(rule impI)\n                    apply(rule combine_or_right)\n                    subgoal\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_in0_outrdy)\n                      by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                    subgoal\n                      apply(rule combine_assn_ex_pre_right')+\n                      apply(rule combine_assn_in0_inrdy)\n                      by auto\n                    done\n                  done\n                apply(rule combine_or_left)\n                subgoal\n                  apply(rule combine_assn_ex_pre_left')+\n                    apply(rule combine_or_right)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_right')+\n                    apply(rule combine_assn_pure_pre_right')\n                    apply(rule combine_assn_in0_waitin)\n                    by auto\n                  subgoal for v\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_assn_in0_wait)\n                    subgoal by auto\n                    apply(simp only:pure_assn_entails)\n                    apply(rule impI)\n                    apply(rule combine_or_right)\n                    subgoal\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_in0_outrdy)\n                      subgoal by auto\n                      apply(subgoal_tac\"p = [] \\<and> min (45 / 10 ^ 3 - ts2 T) (2 / 10\\<^sup>2 - C_upd ent2 (ts2 C)) = 0\")\n                       prefer 2\n                      subgoal using pre(4,6) unfolding proper'_def inv_s'_def C_upd_def C_def T_def\n                        apply(cases ent2) by auto\n                      apply auto\n                      apply(rule entails_tassn_disjI2)\n                      apply(rule entails_tassn_disjI2)\n                      apply(rule entails_tassn_trans)\n                         prefer 2\n                         apply(rule pre(1))\n                        subgoal by auto\n                        subgoal using pre(2) unfolding propc_def by auto\n                        subgoal using pre(3) unfolding propc'_def by auto \n                        subgoal using pre(4) unfolding proper'_def properp_def by auto\n                        subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                        subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                        by auto\n                      subgoal\n                      apply(rule combine_assn_ex_pre_right')+\n                      apply(rule combine_assn_in0_inrdy)\n                      by auto\n                    done\n                  done\n                subgoal\n                  apply(rule combine_assn_ex_pre_left')+\n                    apply(rule combine_or_right)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_right')+\n                    apply(rule combine_assn_pure_pre_right')\n                    apply(rule combine_assn_in0_waitin)\n                    by auto\n                  subgoal\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_assn_in0_wait)\n                    subgoal by auto\n                    apply(simp only:pure_assn_entails)\n                    apply(rule impI)\n                    apply(rule combine_or_right)\n                    subgoal\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_in0_outrdy)\n                      by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                    subgoal\n                      apply(rule combine_assn_ex_pre_right')+\n                      apply(rule combine_assn_in0_inrdy)\n                      by auto\n                    done\n                  done\n                done\n              done\n\n            \n            \n            \n            \n            \n            \n            apply(cases st2)\n              apply(simp only:combine1.simps T2_tr.simps)\n            subgoal premises pre\n              apply(subgoal_tac \"(min (45 / 10 ^ 3 - ts1 T) (1 / 10\\<^sup>2 - C_upd ent1 (ts1 C))) \\<ge>0 \\<and> (9 / 200 - ts2 T) \\<ge> 0 \\<and> p=[]\")\n               prefer 2\n              subgoal using pre(4,5,6) unfolding inv_s_def inv_s'_def C_upd_def T_def C_def proper'_def\n                apply(cases ent1) by auto\n              apply(cases \"(min (45 / 10 ^ 3 - ts1 T) (1 / 10\\<^sup>2 - C_upd ent1 (ts1 C))) \\<ge> (9 / 200 - ts2 T)\")\n              subgoal\n                unfolding combine2.simps\n                apply(rule entails_tassn_disjI1)\n                apply(rule combine_or_left)\n                subgoal\n                  apply simp\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_wait_wait4')\n                  subgoal by auto\n                  apply auto\n                  apply(rule entails_tassn_cancel_left)\n                  apply(rule entails_tassn_trans)\n                   prefer 2\n                   apply(rule pre(1))\n                  subgoal by auto\n                  subgoal using pre(2) unfolding propc_def by auto\n                  subgoal using pre(3) unfolding propc'_def by auto \n                  subgoal using pre(4) unfolding proper'_def properp_def by auto\n                  subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                  subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                  apply(rule combine_assn_left_tran)\n                  unfolding combine1.simps\n                  apply(rule entails_tassn_disjI1)\n                  apply(auto simp add:T_def C_def)\n                  apply(rule entails_tassn_cancel_both)\n                  subgoal premises pre'\n                  proof-\n                    have 1:\"(min (ts2 CHR ''t'' - ts1 CHR ''t'')\n                    (ts2 CHR ''t'' - C_upd ent1 (ts1 CHR ''c'') - 7 / 200)) = \n                    (min (9 / 200 - ts1 CHR ''t'') (1 / 100 - C_upd ent1 (ts1 CHR ''c'')) -\n                  (9 / 200 - ts2 CHR ''t''))\"\n                      by auto\n                    have 2:\" (\\<lambda>t. ParState (EState (Sch [] rn rp, ss))\n           (EState\n             (Task RUNNING eone 2, ts1\n              (CHR ''t'' := ts1 CHR ''t'' + (9 / 200 - ts2 CHR ''t'') + t,\n               CHR ''c'' :=\n                 C_upd ent1 (ts1 CHR ''c'') + (9 / 200 - ts2 CHR ''t'') + t)))) =\n              (\\<lambda>t. ParState (EState (Sch [] rn rp, ss))\n           (EState\n             (Task RUNNING eone 2, ts1\n              (CHR ''t'' := ts1 CHR ''t'' + (t + (9 / 200 - ts2 CHR ''t'')),\n               CHR ''c'' :=\n                 C_upd ent1 (ts1 CHR ''c'') + (t + (9 / 200 - ts2 CHR ''t''))))))\"\n                      apply(rule ext)\n                      by auto\n                    show ?thesis\n                      by(simp add: 1 2)\n                  qed\n                  subgoal premises pre'\n                  proof-\n                    have \"ts1\n      (CHR ''t'' :=\n         ts1 CHR ''t'' + (9 / 200 - ts2 CHR ''t'') +\n         min (ts2 CHR ''t'' - ts1 CHR ''t'')\n          (ts2 CHR ''t'' - C_upd ent1 (ts1 CHR ''c'') - 7 / 200),\n       CHR ''c'' :=\n         C_upd ent1 (ts1 CHR ''c'') + (9 / 200 - ts2 CHR ''t'') +\n         min (ts2 CHR ''t'' - ts1 CHR ''t'')\n          (ts2 CHR ''t'' - C_upd ent1 (ts1 CHR ''c'') - 7 / 200)) = ts1\n      (CHR ''t'' :=\n         ts1 CHR ''t'' +\n         min (9 / 200 - ts1 CHR ''t'') (1 / 100 - C_upd ent1 (ts1 CHR ''c'')),\n       CHR ''c'' :=\n         C_upd ent1 (ts1 CHR ''c'') +\n         min (9 / 200 - ts1 CHR ''t'') (1 / 100 - C_upd ent1 (ts1 CHR ''c'')))\"\n                      apply (rule ext)\n                      by auto\n                    then show ?thesis\n                      by auto\n                  qed\n                  done\n                apply(rule combine_or_left)\n                subgoal\n                  apply(rule combine_assn_ex_pre_left')+\n                  apply(rule combine_assn_pure_pre_left')\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_waitin_wait)\n                   apply auto\n                  apply(rule entails_tassn_cancel_left)\n                  apply(rule entails_tassn_trans)\n                   prefer 2\n                   apply(rule pre(1))\n                  subgoal by auto\n                  subgoal using pre(2) unfolding propc_def by auto\n                  subgoal using pre(3) unfolding propc'_def by auto \n                  subgoal using pre(4) unfolding proper'_def properp_def by auto\n                  subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                  subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                  apply(rule combine_assn_left_tran)\n                  unfolding combine1.simps\n                  apply(rule entails_tassn_disjI2)\n                  apply(rule entails_tassn_disjI1)\n                  subgoal for t\n                    apply(rule entails_tassn_exI[where x=\"(t - (9 / 200 - ts2 T))\"])\n                    apply(auto simp add:T_def C_def)\n                    apply(rule entails_tassn_cancel_right)\n                    apply(subgoal_tac\"\n              (\\<lambda>t. ParState (EState (Sch [] rn rp, ss))\n           (EState\n             (Task RUNNING eone 2, ts1\n              (CHR ''t'' := ts1 CHR ''t'' + (9 / 200 - ts2 CHR ''t'') + t,\n               CHR ''c'' :=\n                 C_upd ent1 (ts1 CHR ''c'') + (9 / 200 - ts2 CHR ''t'') + t)))) =\n              (\\<lambda>t. ParState (EState (Sch [] rn rp, ss))\n           (EState\n             (Task RUNNING eone 2, ts1\n              (CHR ''t'' := ts1 CHR ''t'' + (t + (9 / 200 - ts2 CHR ''t'')),\n               CHR ''c'' :=\n                 C_upd ent1 (ts1 CHR ''c'') + (t + (9 / 200 - ts2 CHR ''t''))))))\")\n                     apply auto\n                    apply(rule ext)\n                    by auto\n                  done\n                apply(rule combine_or_left)\n                subgoal\n                  apply(rule combine_assn_ex_pre_left')+\n                  apply(rule combine_assn_pure_pre_left')+\n                  apply auto\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_waitin_wait)\n                   apply auto\n                  apply(rule entails_tassn_cancel_left)\n                  apply(rule entails_tassn_trans)\n                   prefer 2\n                   apply(rule pre(1))\n                  subgoal by auto\n                  subgoal using pre(2) unfolding propc_def by auto\n                  subgoal using pre(3) unfolding propc'_def by auto \n                  subgoal using pre(4) unfolding proper'_def properp_def by auto\n                  subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                  subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                  apply(rule combine_assn_left_tran)\n                  unfolding combine1.simps\n                  apply(rule entails_tassn_disjI2)\n                  apply(rule entails_tassn_disjI2)\n                  apply(rule entails_tassn_disjI1)\n                  subgoal for t v\n                    apply(rule entails_tassn_exI[where x= \"(t - (9 / 200 - ts2 T))\"])\n                    apply(rule entails_tassn_exI[where x=v])\n                    apply (auto simp add:T_def C_def)\n                    apply(rule entails_tassn_cancel_right)\n                    apply(subgoal_tac\"\n              (\\<lambda>t. ParState (EState (Sch [] rn rp, ss))\n           (EState\n             (Task RUNNING eone 2, ts1\n              (CHR ''t'' := ts1 CHR ''t'' + (9 / 200 - ts2 CHR ''t'') + t,\n               CHR ''c'' :=\n                 C_upd ent1 (ts1 CHR ''c'') + (9 / 200 - ts2 CHR ''t'') + t)))) =\n              (\\<lambda>t. ParState (EState (Sch [] rn rp, ss))\n           (EState\n             (Task RUNNING eone 2, ts1\n              (CHR ''t'' := ts1 CHR ''t'' + (t + (9 / 200 - ts2 CHR ''t'')),\n               CHR ''c'' :=\n                 C_upd ent1 (ts1 CHR ''c'') + (t + (9 / 200 - ts2 CHR ''t''))))))\")\n                     apply auto\n                    apply(rule ext)\n                    by auto\n                  done\n                apply(rule combine_or_left)\n                subgoal\n                  apply(rule combine_assn_ex_pre_left')+\n                  apply(rule combine_assn_pure_pre_left')+\n                  apply auto\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_waitin_wait)\n                   apply auto\n                  apply(rule entails_tassn_cancel_left)\n                  apply(rule entails_tassn_trans)\n                   prefer 2\n                   apply(rule pre(1))\n                  subgoal by auto\n                  subgoal using pre(2) unfolding propc_def by auto\n                  subgoal using pre(3) unfolding propc'_def by auto \n                  subgoal using pre(4) unfolding proper'_def properp_def by auto\n                  subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                  subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                  apply(rule combine_assn_left_tran)\n                  unfolding combine1.simps\n                  apply(rule entails_tassn_disjI2)\n                  apply(rule entails_tassn_disjI2)\n                  apply(rule entails_tassn_disjI2)\n                  apply(rule entails_tassn_disjI1)\n                  subgoal for t v\n                    apply(rule entails_tassn_exI[where x= \"(t - (9 / 200 - ts2 T))\"])\n                    apply(rule entails_tassn_exI[where x=v])\n                    apply (auto simp add:T_def C_def)\n                    apply(rule entails_tassn_cancel_right)\n                    apply(subgoal_tac\"\n              (\\<lambda>t. ParState (EState (Sch [] rn rp, ss))\n           (EState\n             (Task RUNNING eone 2, ts1\n              (CHR ''t'' := ts1 CHR ''t'' + (9 / 200 - ts2 CHR ''t'') + t,\n               CHR ''c'' :=\n                 C_upd ent1 (ts1 CHR ''c'') + (9 / 200 - ts2 CHR ''t'') + t)))) =\n              (\\<lambda>t. ParState (EState (Sch [] rn rp, ss))\n           (EState\n             (Task RUNNING eone 2, ts1\n              (CHR ''t'' := ts1 CHR ''t'' + (t + (9 / 200 - ts2 CHR ''t'')),\n               CHR ''c'' :=\n                 C_upd ent1 (ts1 CHR ''c'') + (t + (9 / 200 - ts2 CHR ''t''))))))\")\n                     apply auto\n                    apply(rule ext)\n                    by auto\n                  done\n                subgoal\n                  apply(rule combine_assn_ex_pre_left')+\n                  apply(rule combine_assn_pure_pre_left')+\n                  apply auto\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_waitin_wait)\n                   apply auto\n                  apply(rule entails_tassn_cancel_left)\n                  apply(rule entails_tassn_trans)\n                   prefer 2\n                   apply(rule pre(1))\n                  subgoal by auto\n                  subgoal using pre(2) unfolding propc_def by auto\n                  subgoal using pre(3) unfolding propc'_def by auto \n                  subgoal using pre(4) unfolding proper'_def properp_def by auto\n                  subgoal using pre(5) unfolding inv_s_def by (auto simp add:T_def C_def)\n                  subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                  apply(rule combine_assn_left_tran)\n                  unfolding combine1.simps\n                  apply(rule entails_tassn_disjI2)\n                  apply(rule entails_tassn_disjI2)\n                  apply(rule entails_tassn_disjI2)\n                  apply(rule entails_tassn_disjI2)\n                  subgoal for t v\n                    apply(rule entails_tassn_exI[where x= \"(t - (9 / 200 - ts2 T))\"])\n                    apply(rule entails_tassn_exI[where x=v])\n                    apply (auto simp add:T_def C_def)\n                    apply(rule entails_tassn_cancel_right)\n                    apply(subgoal_tac\"\n              (\\<lambda>t. ParState (EState (Sch [] rn rp, ss))\n           (EState\n             (Task RUNNING eone 2, ts1\n              (CHR ''t'' := ts1 CHR ''t'' + (9 / 200 - ts2 CHR ''t'') + t,\n               CHR ''c'' :=\n                 C_upd ent1 (ts1 CHR ''c'') + (9 / 200 - ts2 CHR ''t'') + t)))) =\n              (\\<lambda>t. ParState (EState (Sch [] rn rp, ss))\n           (EState\n             (Task RUNNING eone 2, ts1\n              (CHR ''t'' := ts1 CHR ''t'' + (t + (9 / 200 - ts2 CHR ''t'')),\n               CHR ''c'' :=\n                 C_upd ent1 (ts1 CHR ''c'') + (t + (9 / 200 - ts2 CHR ''t''))))))\")\n                     apply auto\n                    apply(rule ext)\n                    by auto\n                  done\n                done\n              subgoal\n                unfolding combine2.simps\n                apply(rule entails_tassn_disjI2)\n                apply(subgoal_tac\"9 / 200 - ts2 T > min (45 / 10 ^ 3 - ts1 T) (1 / 10\\<^sup>2 - C_upd ent1 (ts1 C))\")\n                 prefer 2 subgoal by auto\n                apply simp\n                apply(rule combine_or_left)\n                subgoal\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_wait_wait3)\n                  subgoal by auto\n                  apply(rule entails_tassn_cancel_both)\n                  subgoal by auto\n                  apply(rule entails_tassn_trans)\n                   prefer 2\n                   apply(rule pre(1))\n                  subgoal by auto\n                  subgoal using pre(2) unfolding propc_def by auto\n                  subgoal using pre(3) unfolding propc'_def by auto \n                  subgoal using pre(4) unfolding proper'_def properp_def by auto\n                  subgoal using pre(5,6) unfolding inv_s_def inv_s'_def apply(cases \"(9 / 200 - ts1 T) \\<le>(1 / 100 - C_upd ent1 (ts1 C))\") by auto\n                  subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                  apply(rule combine_assn_right_tran)\n                  unfolding T2_tr.simps\n                  apply(rule entails_tassn_cancel_both)\n                  subgoal premises pre'\n                  proof-\n                    have 1:\"(9 / 200 - (ts2 T + min (9 / 200 - ts1 T) (1 / 100 - C_upd ent1 (ts1 C)))) = (9 / 200 - ts2 T - min (9 / 200 - ts1 T) (1 / 100 - C_upd ent1 (ts1 C)))\"\n                      by auto\n                    have 2:\"(\\<lambda>t. EState\n           (Task WAIT ent2 1, ts2\n            (T := ts2 T + min (9 / 200 - ts1 T) (1 / 100 - C_upd ent1 (ts1 C)) + t)))\n                          = (\\<lambda>t. EState\n           (Task WAIT ent2 1, ts2\n            (T := ts2 T + (t + min (9 / 200 - ts1 T) (1 / 100 - C_upd ent1 (ts1 C))))))\"\n                      apply (rule ext)\n                      by auto\n                    show ?thesis \n                      by (auto simp add:1 2)\n                  qed\n                  by auto\n                apply(rule combine_or_left)\n                subgoal\n                  apply(rule combine_assn_ex_pre_left')+\n                  apply(rule combine_assn_pure_pre_left')+\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_waitin_wait)\n                  subgoal by auto\n                  by auto\n                apply(rule combine_or_left)\n                subgoal\n                  apply(rule combine_assn_ex_pre_left')+\n                  apply(rule combine_assn_pure_pre_left')+\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_waitin_wait)\n                  subgoal by auto\n                  by auto\n                apply(rule combine_or_left)\n                subgoal\n                  apply(rule combine_assn_ex_pre_left')+\n                  apply(rule combine_assn_pure_pre_left')+\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_waitin_wait)\n                  subgoal by auto\n                  by auto\n                subgoal\n                  apply(rule combine_assn_ex_pre_left')+\n                  apply(rule combine_assn_pure_pre_left')+\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_waitin_wait)\n                  subgoal by auto\n                  by auto\n                done\n              done\n\n\n\n\n\n\n\n\n             apply(simp only:combine1.simps T2_tr.simps)\n            subgoal premises pre\n              apply(subgoal_tac\"p=[] \\<and> min (45 / 10 ^ 3 - ts1 T) (1 / 10\\<^sup>2 - C_upd ent1 (ts1 C)) \\<ge> 0 \\<and> (9 / 200 - ts2 T) \\<ge>0\")\n               prefer 2 \n              subgoal using pre(4,5,6) unfolding proper'_def inv_s_def inv_s'_def C_upd_def by auto\n              apply simp\n              apply(rule combine_or_left)\n              subgoal\n                apply(rule combine_or_right)\n                subgoal\n                  apply(rule combine_assn_ex_pre_right')+\n                  apply(rule combine_assn_pure_pre_right')\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_wait_out)\n                  subgoal by auto\n                  apply auto\n                  apply(rule entails_tassn_disjI1)\n                  apply(subgoal_tac\"min (45 / 10 ^ 3 - ts1 T) (1 / 10\\<^sup>2 - C_upd ent1 (ts1 C)) = 0\")\n                    prefer 2 subgoal by auto\n                  apply auto\n                  apply(rule entails_tassn_trans)\n                   prefer 2\n                   apply(rule pre(1))\n                  subgoal by auto\n                  subgoal using pre(2) unfolding propc_def by auto\n                  subgoal using pre(3) unfolding propc'_def by auto \n                  subgoal using pre(4) unfolding proper'_def properp_def by auto\n                  subgoal using pre(5,6) unfolding inv_s_def inv_s'_def apply(cases \"(9 / 200 - ts1 T) \\<le>(1 / 100 - C_upd ent1 (ts1 C))\") by auto\n                  subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                  apply(rule combine_assn_right_tran)\n                  unfolding T2_tr.simps\n                  apply(rule entails_tassn_disjI1)\n                  subgoal for v tt\n                    apply(rule entails_tassn_exI[where x=v])            \n                    apply(rule entails_tassn_exI[where x=tt])\n                    by auto\n                  done\n                subgoal\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_wait_out)\n                  subgoal by auto\n                  apply auto\n                  apply(subgoal_tac\"min (45 / 10 ^ 3 - ts1 T) (1 / 10\\<^sup>2 - C_upd ent1 (ts1 C)) = 0\")\n                    prefer 2 subgoal by auto\n                  apply auto\n                  apply(rule entails_tassn_disjI1)\n                  apply(rule entails_tassn_trans)\n                   prefer 2\n                   apply(rule pre(1))\n                  subgoal by auto\n                  subgoal using pre(2) unfolding propc_def by auto\n                  subgoal using pre(3) unfolding propc'_def by auto \n                  subgoal using pre(4) unfolding proper'_def properp_def by auto\n                  subgoal using pre(5,6) unfolding inv_s_def inv_s'_def apply(cases \"(9 / 200 - ts1 T) \\<le>(1 / 100 - C_upd ent1 (ts1 C))\") by auto\n                  subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                  apply(rule combine_assn_right_tran)\n                  unfolding T2_tr.simps\n                  apply(rule entails_tassn_disjI2)\n                  by auto\n                done\n              apply(rule combine_or_left)\n              subgoal\n                apply(rule combine_assn_ex_pre_left')+\n                apply(rule combine_assn_pure_pre_left')\n                apply auto\n                apply(rule combine_or_right)\n                subgoal for t\n                  apply(rule combine_assn_ex_pre_right')+\n                  apply(rule combine_assn_pure_pre_right')\n                  apply(rule entails_tassn_trans)\n                   apply(rule combine_assn_waitin_out)\n                  subgoal by auto\n                  apply auto\n                  apply(cases k')\n                  subgoal apply simp unfolding false_assn_def combine_assn_def entails_tassn_def\n                    by auto\n                  subgoal for v tt k''\n                    apply (simp add: T_def C_def)\n                    apply(rule combine_or_left)\n                    subgoal\n                      apply(rule entails_tassn_trans)\n                       apply(rule combine_assn_wait_waitin)\n                      subgoal by auto\n                      apply auto\n                      apply(rule entails_tassn_disjI2)\n                      apply(rule entails_tassn_disjI1)\n                      apply(rule entails_tassn_cancel_left)\n                      apply(rule combine_or_left)\n                      subgoal\n                        apply(rule entails_tassn_trans)\n                         apply(rule combine_assn_out0_waitin)\n                        subgoal by auto\n                        apply auto\n                        apply(subgoal_tac\"min (9 / 200 - ts1 CHR ''t'') (1 / 100 - C_upd ent1 (ts1 CHR ''c'')) = tt\")\n                         prefer 2 subgoal by auto\n                        apply auto\n                        apply(rule entails_tassn_trans)\n                         prefer 2\n                         apply(rule pre(1))\n                        subgoal by auto\n                        subgoal using pre(2) unfolding propc_def by auto\n                        subgoal using pre(3) unfolding propc'_def by auto \n                        subgoal using pre(4) unfolding proper'_def properp_def by auto\n                        subgoal using pre(5,6) unfolding inv_s_def inv_s'_def \n                          apply(cases \"(9 / 200 - ts1 T) \\<le>(1 / 100 - C_upd ent1 (ts1 C))\") \n                          unfolding T_def C_def by auto\n                        subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                        by auto\n                      apply(rule combine_or_left)\n                      subgoal\n                        apply(rule combine_assn_waitp_waitin')\n                        by auto\n                      subgoal\n                        apply(rule combine_assn_waitp_waitin')\n                        by auto\n                      done\n                      apply(rule combine_or_left)\n                      subgoal\n                        apply(rule combine_assn_ex_pre_left')+\n                        apply(rule combine_assn_pure_pre_left')\n                        apply auto\n                        apply(rule combine_assn_waitin_waitin)\n                        by auto\n                      apply(rule combine_or_left)\n                      subgoal\n                        apply(rule combine_assn_ex_pre_left')+\n                        apply(rule combine_assn_pure_pre_left')\n                        apply auto\n                        apply(rule combine_assn_waitin_waitin)\n                        by auto\n                      apply(rule combine_or_left)\n                      subgoal\n                        apply(rule combine_assn_ex_pre_left')+\n                        apply(rule combine_assn_pure_pre_left')\n                        apply auto\n                        apply(rule combine_assn_waitin_waitin)\n                        by auto\n                      subgoal\n                        apply(rule combine_assn_ex_pre_left')+\n                        apply(rule combine_assn_pure_pre_left')\n                        apply auto\n                        apply(rule combine_assn_waitin_waitin)\n                        by auto\n                      done\n                    done\n                  subgoal\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_assn_waitin_out)\n                    subgoal by auto\n                    apply auto\n                    apply(cases k')\n                    subgoal apply simp unfolding false_assn_def combine_assn_def entails_tassn_def\n                      by auto\n                    subgoal for k''\n                      apply(auto simp add: T_def C_def)\n                      apply(rule combine_or_left)\n                      subgoal\n                        apply(cases \"(min (9 / 200 - ts1 CHR ''t'') (1 / 100 - C_upd ent1 (ts1 CHR ''c''))) < (9 / 200 - ts2 CHR ''t'')\")\n                        subgoal\n                          apply(rule entails_tassn_trans)\n                           apply(rule combine_assn_wait_wait3)\n                          subgoal by auto\n                          apply auto\n                          apply(rule entails_tassn_disjI2)\n                          apply(rule entails_tassn_disjI1)\n                          apply(rule entails_tassn_cancel_left)\n                          apply(rule combine_or_left)\n                          subgoal \n                            apply(rule combine_assn_out0_wait)\n                            by auto\n                          apply(rule combine_or_left)\n                          subgoal\n                            apply(rule combine_assn_waitp_wait')\n                            by auto\n                          subgoal\n                            apply(rule combine_assn_waitp_wait')\n                            by auto\n                          done\n                        apply(cases \" (9 / 200 - ts2 CHR ''t'') = (min (9 / 200 - ts1 CHR ''t'') (1 / 100 - C_upd ent1 (ts1 CHR ''c'')))\")\n                        subgoal\n                          apply simp\n                          apply(rule entails_tassn_trans)\n                           apply(rule combine_assn_wait_wait2)\n                          subgoal by auto\n                          apply auto\n                          apply(rule entails_tassn_disjI2)\n                          apply(rule entails_tassn_disjI1)\n                          apply(rule entails_tassn_cancel_left)\n                          apply(rule combine_or_left)\n                          subgoal \n                            apply(rule combine_or_right)\n                            subgoal\n                              apply(rule combine_assn_out0_outrdy)\n                              by auto\n                            subgoal\n                              apply(rule combine_assn_ex_pre_right')+\n                              apply(rule entails_tassn_trans)\n                               apply(rule combine_assn_out0_inrdy)\n                              subgoal by auto\n                              apply auto\n                              apply(rule entails_tassn_trans)\n                               prefer 2\n                               apply(rule pre(1))\n                              subgoal by auto\n                              subgoal using pre(2) unfolding propc_def by auto\n                              subgoal using pre(3) unfolding propc'_def by auto \n                              subgoal using pre(4) unfolding proper'_def properp_def by auto\n                              subgoal using pre(5,6) unfolding inv_s_def inv_s'_def \n                                apply(cases \"(9 / 200 - ts1 T) \\<le>(1 / 100 - C_upd ent1 (ts1 C))\") \n                                unfolding T_def C_def by auto\n                              subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                              apply(subgoal_tac \"ts2(CHR ''t'' := ts2 CHR ''t'' + min (9 / 200 - ts1 CHR ''t'') (1 / 100 - C_upd ent1 (ts1 CHR ''c'')), F := 0) = ts2(CHR ''t'' := 9 / 200, F := 0)\")\n                              by auto\n                            done\n                          apply(rule combine_or_left)\n                          subgoal\n                            apply(rule combine_or_right)\n                            subgoal\n                              apply(rule combine_assn_waitp_outrdy')\n                              by auto\n                            subgoal\n                              apply(rule combine_assn_ex_pre_right')+\n                              apply(rule combine_assn_waitp_inrdy')\n                              by auto\n                            done\n                            subgoal\n                            apply(rule combine_or_right)\n                            subgoal\n                              apply(rule combine_assn_waitp_outrdy')\n                              by auto\n                            subgoal\n                              apply(rule combine_assn_ex_pre_right')+\n                              apply(rule combine_assn_waitp_inrdy')\n                              by auto\n                            done\n                          done\n                        apply(cases \"(min (9 / 200 - ts1 CHR ''t'') (1 / 100 - C_upd ent1 (ts1 CHR ''c''))) > (9 / 200 - ts2 CHR ''t'')\")\n                        subgoal\n                          apply(rule entails_tassn_trans)\n                           apply(rule combine_assn_wait_wait4)\n                          subgoal by auto\n                          apply auto\n                          apply(rule entails_tassn_disjI2)\n                          apply(rule entails_tassn_disjI2)\n                          apply(rule entails_tassn_cancel_left)\n                          apply(rule combine_or_right)\n                          subgoal\n                            apply(rule entails_tassn_trans)\n                            apply(rule combine_assn_wait_outrdy)\n                            by auto\n                          subgoal\n                            apply(rule combine_assn_ex_pre_right')+\n                            apply(rule entails_tassn_trans)\n                            apply(rule combine_assn_wait_inrdy)\n                            by auto\n                          done\n                        by auto\n                      apply(rule combine_or_left)\n                      subgoal\n                        apply(rule combine_assn_ex_pre_left')+\n                        apply(rule combine_assn_pure_pre_left')\n                        apply auto\n                        apply(rule entails_tassn_trans)\n                         apply(rule combine_assn_waitin_wait)\n                        subgoal by auto\n                        apply auto\n                        apply(rule entails_tassn_disjI2)\n                        apply(rule entails_tassn_disjI2)\n                        apply(rule entails_tassn_cancel_left)\n                        apply(rule combine_or_right)\n                        subgoal\n                          apply(rule entails_tassn_trans)\n                           apply(rule combine_assn_waitin_outrdy)\n                          by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                        subgoal\n                          apply(rule combine_assn_ex_pre_right')+\n                          apply(rule combine_assn_waitin_inrdy)\n                          by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                        done\n                      apply(rule combine_or_left)\n                      subgoal\n                        apply(rule combine_assn_ex_pre_left')+\n                        apply(rule combine_assn_pure_pre_left')\n                        apply auto\n                        apply(rule entails_tassn_trans)\n                         apply(rule combine_assn_waitin_wait)\n                        subgoal by auto\n                        apply auto\n                        apply(rule entails_tassn_disjI2)\n                        apply(rule entails_tassn_disjI2)\n                        apply(rule entails_tassn_cancel_left)\n                        apply(rule combine_or_right)\n                        subgoal\n                          apply(rule entails_tassn_trans)\n                           apply(rule combine_assn_waitin_outrdy)\n                          by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                        subgoal\n                          apply(rule combine_assn_ex_pre_right')+\n                          apply(rule combine_assn_waitin_inrdy)\n                          by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                        done\n                      apply(rule combine_or_left)\n                      subgoal\n                        apply(rule combine_assn_ex_pre_left')+\n                        apply(rule combine_assn_pure_pre_left')\n                        apply auto\n                        apply(rule entails_tassn_trans)\n                         apply(rule combine_assn_waitin_wait)\n                        subgoal by auto\n                        apply auto\n                        apply(rule entails_tassn_disjI2)\n                        apply(rule entails_tassn_disjI2)\n                        apply(rule entails_tassn_cancel_left)\n                        apply(rule combine_or_right)\n                        subgoal\n                          apply(rule entails_tassn_trans)\n                           apply(rule combine_assn_waitin_outrdy)\n                          by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                        subgoal\n                          apply(rule combine_assn_ex_pre_right')+\n                          apply(rule combine_assn_waitin_inrdy)\n                          by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                        done\n                      subgoal\n                        apply(rule combine_assn_ex_pre_left')+\n                        apply(rule combine_assn_pure_pre_left')\n                        apply auto\n                        apply(rule entails_tassn_trans)\n                         apply(rule combine_assn_waitin_wait)\n                        subgoal by auto\n                        apply auto\n                        apply(rule entails_tassn_disjI2)\n                        apply(rule entails_tassn_disjI2)\n                        apply(rule entails_tassn_cancel_left)\n                        apply(rule combine_or_right)\n                        subgoal for tt v\n                          apply(rule entails_tassn_trans)\n                           apply(rule combine_assn_waitin_outrdy)\n                          subgoal by auto\n                          apply auto\n                          apply(rule entails_tassn_trans)\n                           prefer 2\n                           apply(rule pre(1))\n                          subgoal by auto\n                          subgoal using pre(2) unfolding propc_def by auto\n                          subgoal using pre(3) unfolding propc'_def by auto \n                          subgoal using pre(4) unfolding proper'_def properp_def by auto\n                          subgoal using pre(5,6) unfolding inv_s_def inv_s'_def \n                            apply(cases \"(9 / 200 - ts1 T) \\<le>(1 / 100 - C_upd ent1 (ts1 C))\") \n                            unfolding T_def C_def by auto\n                          subgoal using pre(5,6) unfolding inv_s'_def inv_s_def by(auto simp add:T_def C_def)\n                          by auto\n                        subgoal\n                          apply(rule combine_assn_ex_pre_right')+\n                          apply(rule combine_assn_waitin_inrdy)\n                          by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                        done\n                      done\n                    done\n                  done\n                apply(rule combine_or_left)\n                subgoal\n                  apply(rule combine_assn_ex_pre_left')+\n                  apply(rule combine_assn_pure_pre_left')\n                  apply auto\n                  apply(rule combine_or_right)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_right')+\n                    apply(rule combine_assn_pure_pre_right')\n                    apply auto\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_assn_waitin_out)\n                    by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                  subgoal\n                    apply(rule entails_tassn_trans)\n                     apply(rule combine_assn_waitin_out)\n                    by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                  done\n                apply(rule combine_or_left)\n                subgoal\n                  apply(rule combine_assn_ex_pre_left')+\n                  apply(rule combine_assn_pure_pre_left')\n                  apply auto\n                  apply(rule combine_or_right)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_right')+\n                    apply(rule combine_assn_pure_pre_right')\n                    apply auto\n                    apply(rule combine_assn_waitin_out'')\n                    by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                  subgoal\n                    apply(rule combine_assn_waitin_out'')\n                    by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                  done\n                subgoal\n                  apply(rule combine_assn_ex_pre_left')+\n                  apply(rule combine_assn_pure_pre_left')\n                  apply auto\n                  apply(rule combine_or_right)\n                  subgoal\n                    apply(rule combine_assn_ex_pre_right')+\n                    apply(rule combine_assn_pure_pre_right')\n                    apply auto\n                    apply(rule combine_assn_waitin_out'')\n                    by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                  subgoal\n                    apply(rule combine_assn_waitin_out'')\n                    by(auto simp add: req_ch_def preempt_ch_def run_ch_def free_ch_def exit_ch_def)\n                  done\n                done\n\n              apply(simp only:combine1.simps T2_tr.simps)\n              subgoal \n                unfolding propc_def propc'_def by auto\n              done\n            done\n          done\n        done\n    qed\n\n\n\n\n\n\n\n\n\n\n\nend", "meta": {"author": "AgHHL", "repo": "lics2023", "sha": "e2ea9c15a8c0e1bf658679274ee87f30baf4abc3", "save_path": "github-repos/isabelle/AgHHL-lics2023", "path": "github-repos/isabelle/AgHHL-lics2023/lics2023-e2ea9c15a8c0e1bf658679274ee87f30baf4abc3/case2/combine2.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.672331699179286, "lm_q2_score": 0.40356685373537454, "lm_q1q2_score": 0.2713307885043428}}
{"text": "section {* Independence of IMAP Commands *}\n\ntext\\<open>In this section we show that two concurrent operations that reference to the same tag must be \nidentical.\\<close>\n\ntheory\n  \"IMAP-proof-independent\"\n  imports\n    \"IMAP-def\"\n    \"IMAP-proof-helpers\"  \nbegin\n\nlemma (in imap) Broadcast_Expunge_Deliver_prefix_closed:\n  assumes \"xs @ [Broadcast (i, Expunge e mo i)] prefix of j\"\n  shows \"Deliver (mo, Append mo e) \\<in> set xs \\<or> \n    (\\<exists> mo2 . Deliver (mo, Store e mo2 mo) \\<in> set xs)\"\nproof -  \n  obtain y where \"apply_operations xs = Some y\"\n    using assms broadcast_only_valid_msgs by blast\n  moreover hence \"mo \\<in> snd (y e)\"\n    using broadcast_only_valid_msgs[of xs \"(i, Expunge e mo i)\" j] \n      valid_behaviours_def[of y \"(i, Expunge e mo i)\"] assms by auto\n  ultimately show ?thesis\n    using assms Deliver_added_files apply_operations_added_files by blast\nqed\n\nlemma (in imap) Broadcast_Store_Deliver_prefix_closed:\n  assumes \"xs @ [Broadcast (i, Store e mo i)] prefix of j\"\n  shows \"Deliver (mo, Append mo e) \\<in> set xs \\<or> \n    (\\<exists> mo2 . Deliver (mo, Store e mo2 mo) \\<in> set xs)\"\nproof -  \n  obtain y where \"apply_operations xs = Some y\"\n    using assms broadcast_only_valid_msgs by blast\n  moreover hence \"mo \\<in> snd (y e)\"\n    using broadcast_only_valid_msgs[of xs \"(i, Store e mo i)\" j] \n      valid_behaviours_def[of y \"(i, Store e mo i)\"] assms by auto\n  ultimately show ?thesis\n    using assms Deliver_added_files apply_operations_added_files by blast\nqed\n\nlemma (in imap) Deliver_added_ids:\n  assumes \"xs prefix of j\"\n    and \"i \\<in> set (added_ids xs e)\"\n  shows \"Deliver (i, Create i e) \\<in> set xs \\<or> \n    (\\<exists> mo . Deliver (i, Expunge e mo i) \\<in> set xs)\"\n  using assms proof (induct xs rule: rev_induct, clarsimp)\n  case (snoc x xs) thus ?case\n  proof (cases x, force)\n    case X: (Deliver e')\n    moreover obtain a b where \"e' = (a, b)\" by force\n    ultimately show ?thesis\n      using snoc apply (case_tac b; clarify)\n          apply (simp, metis added_ids_Deliver_Create_diff_collapse \n          added_ids_Deliver_Create_same_collapse empty_iff list.set(1) set_ConsD create_id_valid \n          in_set_conv_decomp prefix_of_appendD, force)\n      using append_id_valid apply (simp, metis (no_types, lifting)  prefix_of_appendD, simp, metis \n          Un_iff added_ids_Deliver_Expunge_diff_collapse added_ids_Deliver_Expunge_same_collapse \n          empty_iff expunge_id_valid list.set(1) list.set_intros(1) prefix_of_appendD set_ConsD \n          set_append)\n      by (simp, blast)\n  qed\nqed\n\nlemma (in imap) Broadcast_Deliver_prefix_closed:\n  assumes \"xs @ [Broadcast (r, Delete ix e)] prefix of j\"\n    and \"i \\<in> ix\"\n  shows \"Deliver (i, Create i e) \\<in> set xs \\<or> \n    Deliver (i, Append i e) \\<in> set xs \\<or> \n    (\\<exists> mo . Deliver (i, Expunge e mo i) \\<in> set xs) \\<or> \n    (\\<exists> mo . Deliver (i, Store e mo i) \\<in> set xs)\"\nproof -  \n  obtain y where \"apply_operations xs = Some y\"\n    using assms broadcast_only_valid_msgs by blast\n  moreover hence \"ix = fst (y e) \\<union> snd (y e)\"\n    by (metis (mono_tags, lifting) assms(1) broadcast_only_valid_msgs operation.case(2)\n        option.simps(1) valid_behaviours_def case_prodD)\n  ultimately show ?thesis\n    using assms Deliver_added_ids apply_operations_added_ids\n    by (metis Deliver_added_files Un_iff apply_operations_added_files le_iff_sup prefix_of_appendD)\nqed\n\nlemma (in imap) concurrent_create_delete_independent_technical:\n  assumes \"i \\<in> is\"\n    and \"xs prefix of j\"\n    and \"(i, Create i e) \\<in> set (node_deliver_messages xs)\" \n    and \"(ir, Delete is e) \\<in> set (node_deliver_messages xs)\"\n  shows \"hb (i, Create i e) (ir, Delete is e)\"\nproof -\n  have f1: \"Deliver (i, Create i e) \\<in> set (history j)\"\n    using assms prefix_msg_in_history by blast\n  obtain pre k where P: \"pre@[Broadcast (ir, Delete is e)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast\n  hence f2: \"Deliver (i, Create i e) \\<in> set pre \\<or> \n                  Deliver (i, Append i e) \\<in> set pre \\<or> \n                  (\\<exists> mo . Deliver (i, Expunge e mo i) \\<in> set pre) \\<or> \n                  (\\<exists> mo . Deliver (i, Store e mo i) \\<in> set pre)\"\n    using Broadcast_Deliver_prefix_closed assms by auto\n  have f3: \"Deliver (i, Append i e) \\<notin> set pre\" using f1 P \n    by (metis (full_types) Pair_inject fst_conv network.delivery_has_a_cause network.msg_id_unique \n        network_axioms operation.simps(9) prefix_elem_to_carriers prefix_of_appendD)\n  have f4: \"\\<forall> mo . Deliver (i, Expunge e mo i) \\<notin> set pre\" using f1 P\n    by (metis delivery_has_a_cause fst_conv msg_id_unique old.prod.inject operation.simps(11)\n        prefix_elem_to_carriers prefix_of_appendD)\n  have \"\\<forall> mo . Deliver (i, Store e mo i) \\<notin> set pre\" using f1 P\n    by (metis delivery_has_a_cause fst_conv msg_id_unique old.prod.inject operation.simps(13)\n        prefix_elem_to_carriers prefix_of_appendD) \n  thus ?thesis using f2 f3 f4  P events_in_local_order hb_deliver by blast\nqed\n\nlemma (in imap) concurrent_store_expunge_independent_technical:\n  assumes \"xs prefix of j\"\n    and \"(i, Store e mo i) \\<in> set (node_deliver_messages xs)\" \n    and \"(r, Expunge e i r) \\<in> set (node_deliver_messages xs)\"\n  shows \"hb (i, Store e mo i) (r, Expunge e i r)\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (r, Expunge e i r)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast\n  moreover hence f1: \"Deliver (i, Append i e) \\<in> set pre \\<or> \n  (\\<exists> mo2 . Deliver (i, Store e mo2 i) \\<in> set pre)\"\n    using Broadcast_Expunge_Deliver_prefix_closed assms(1) by auto\n  hence f2: \"Deliver (i, Append i e) \\<notin> set (history k)\"\n    by (metis Pair_inject assms(1) assms(2) fst_conv msg_id_unique network.delivery_has_a_cause \n        network_axioms operation.distinct(17) prefix_msg_in_history)\n  from f1 obtain mo2 :: 'a where\n    \"Deliver (i, Store e mo2 i) \\<in> set (history k)\" using f2\n    using calculation prefix_elem_to_carriers by blast  \n  hence \"Deliver (i, Store e mo i) \\<in> set (history k)\" using assms f1 f2 P \n    by (metis fst_conv msg_id_unique network.delivery_has_a_cause network_axioms \n        prefix_msg_in_history)    \n  then show ?thesis\n    using hb.intros(2) events_in_local_order f1 f2 P\n    by (metis delivery_has_a_cause fst_conv msg_id_unique node_histories.prefix_of_appendD \n        node_histories_axioms prefix_elem_to_carriers)\nqed\n\nlemma (in imap) concurrent_store_expunge_independent_technical2:\n  assumes \"xs prefix of j\"\n    and \"(i, Store e1 mo2 i) \\<in> set (node_deliver_messages xs)\" \n    and \"(r, Expunge e mo r) \\<in> set (node_deliver_messages xs)\"\n  shows \"mo2 \\<noteq> r\"\nproof -\n  obtain oid :: \"'a \\<times> ('a, 'b) operation \\<Rightarrow> nat\" where\n    oid: \"\\<forall>p n. Deliver p \\<notin> set (history n) \\<or> Broadcast p \\<in> set (history (oid p))\"\n    by (metis (no_types) delivery_has_a_cause)\n  hence f1: \"Broadcast (r, Expunge e mo r) \\<in> set (history (oid (r, Expunge e mo r)))\"\n    using assms(1) assms(3) prefix_msg_in_history by blast\n  obtain k :: \"'a \\<Rightarrow> 'b \\<Rightarrow> ('a \\<times> ('a, 'b) operation) event list \\<Rightarrow> 'a\" where k: \n    \"\\<forall>i e pre. (\\<exists>mo. Deliver (i, Store e mo i) \\<in> set pre) = \n    (Deliver (i, Store e (k i e pre) i) \\<in> set pre)\"\n    by moura\n  obtain pre :: \"nat \\<Rightarrow> ('a \\<times> ('a, 'b) operation) event \\<Rightarrow> ('a \\<times> ('a, 'b) operation) event list\" \n    where pre: \"\\<forall>k op1. (\\<exists>op2. op2 @ [op1] prefix of k) = (pre k op1 @ [op1] prefix of k)\"\n    by moura\n  hence f2: \"\\<forall>e n. e \\<notin> set (history n) \\<or> pre n e @ [e] prefix of n\"\n    using events_before_exist by simp\n  hence f3: \"pre (oid (i, Store e1 mo2 i)) (Broadcast (i, Store e1 mo2 i))\n  prefix of oid (i, Store e1 mo2 i)\"\n    using oid  assms(1) assms(2) prefix_msg_in_history by blast\n  have f4: \"Deliver (r, Append r e1) \\<notin> set (history (oid (i, Store e1 mo2 i)))\"\n    by (metis (no_types) oid f1 fst_conv msg_id_unique old.prod.inject operation.distinct(15))\n  have \"Deliver (r, Store e1 (k r e1 (pre (oid (i, Store e1 mo2 i)) \n  (Broadcast (i, Store e1 mo2 i)))) r) \\<notin> set (history (oid (i, Store e1 mo2 i)))\"\n    by (metis (no_types) oid f1 fst_conv msg_id_unique old.prod.inject operation.distinct(19))\n  thus ?thesis using oid k f2 f3 f4 assms\n    by (metis (no_types, lifting) Broadcast_Store_Deliver_prefix_closed \n        network.prefix_msg_in_history network_axioms prefix_elem_to_carriers)\nqed\n\nlemma (in imap) concurrent_store_delete_independent_technical:\n  assumes \"i \\<in> is\"\n    and \"xs prefix of j\"\n    and \"(i, Store e mo i) \\<in> set (node_deliver_messages xs)\" \n    and \"(ir, Delete is e) \\<in> set (node_deliver_messages xs)\"\n  shows \"hb (i, Store e mo i) (ir, Delete is e)\"\nproof -\n  have f1: \"Deliver (i, Store e mo i) \\<in> set (history j)\" using assms prefix_msg_in_history by auto\n  obtain pre k where P: \"pre@[Broadcast (ir, Delete is e)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast\n  hence f2: \"Deliver (i, Create i e) \\<in> set pre \\<or> \n  Deliver (i, Append i e) \\<in> set pre \\<or>\n  (\\<exists> mo . Deliver (i, Expunge e mo i) \\<in> set pre) \\<or> \n  (\\<exists> mo . Deliver (i, Store e mo i) \\<in> set pre)\"  \n    using Broadcast_Deliver_prefix_closed assms(1) by auto    \n  have f3: \"Deliver (i, Create i e) \\<notin> set pre\" using f1 P \n    by (metis Pair_inject delivery_has_a_cause fst_conv msg_id_unique operation.distinct(7) \n        prefix_elem_to_carriers prefix_of_appendD)\n  have f4: \"Deliver (i, Append i e) \\<notin> set pre\" using f1 P\n    by (metis delivery_has_a_cause fst_conv msg_id_unique operation.distinct(17) \n        prefix_elem_to_carriers prefix_of_appendD prod.inject)\n  have \"\\<forall> mo . Deliver (i, Expunge e mo i) \\<notin> set pre\" using f1 P\n    by (metis Pair_inject delivery_has_a_cause fst_conv msg_id_unique operation.simps(25) \n        prefix_elem_to_carriers prefix_of_appendD)\n  hence \"Deliver (i, Store e mo i) \\<in> set pre\" using f1 f2 f3 f4 P\n    by (metis delivery_has_a_cause fst_conv msg_id_unique node_histories.prefix_of_appendD \n        node_histories_axioms prefix_elem_to_carriers)     \n  thus ?thesis using P events_in_local_order hb_deliver by blast\nqed\n\nlemma (in imap) concurrent_append_delete_independent_technical:\n  assumes \"i \\<in> is\"\n    and \"xs prefix of j\"\n    and \"(i, Append i e) \\<in> set (node_deliver_messages xs)\" \n    and \"(ir, Delete is e) \\<in> set (node_deliver_messages xs)\"\n  shows \"hb (i, Append i e) (ir, Delete is e)\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (ir, Delete is e)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast\n  hence f1: \"Deliver (i, Create i e) \\<in> set pre \\<or> \n  Deliver (i, Append i e) \\<in> set pre \\<or> \n  (\\<exists> mo . Deliver (i, Expunge e mo i) \\<in> set pre) \\<or> \n  (\\<exists> mo . Deliver (i, Store e mo i) \\<in> set pre)\"\n    using Broadcast_Deliver_prefix_closed assms(1) by auto\n  hence \"Deliver (i, Append i e) \\<in> set pre\" using assms P f1\n    by (metis (no_types, hide_lams) delivery_has_a_cause events_in_local_order fst_conv \n        hb_broadcast_exists1 hb_deliver msg_id_unique prefix_msg_in_history)\n  thus ?thesis using P events_in_local_order hb_deliver by blast\nqed\n\nlemma (in imap) concurrent_append_expunge_independent_technical:\n  assumes \"i = mo\"\n    and \"xs prefix of j\"\n    and \"(i, Append i e) \\<in> set (node_deliver_messages xs)\" \n    and \"(r, Expunge e mo r) \\<in> set (node_deliver_messages xs)\"\n  shows \"hb (i, Append i e) (r, Expunge e mo r)\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (r, Expunge e mo r)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast\n  hence f1: \"Deliver (mo, Append mo e) \\<in> set pre \\<or> \n  (\\<exists> mo2 . Deliver (mo, Store e mo2 mo) \\<in> set pre)\"\n    using Broadcast_Expunge_Deliver_prefix_closed assms(1) by auto\n  hence \"(\\<forall> mo2 . Deliver (mo, Store e mo2 mo) \\<notin> set pre)\" using P assms \n  proof -\n    have \"Deliver (mo, Append mo e) \\<in> set (history j)\"\n      using assms(1) assms(2) assms(3) prefix_msg_in_history by blast\n    thus ?thesis\n      by (metis (no_types) P Pair_inject delivery_has_a_cause fst_conv msg_id_unique \n          operation.simps(23) prefix_elem_to_carriers prefix_of_appendD)\n  qed\n  thus ?thesis\n    using hb.intros(2) events_in_local_order assms(1) P f1 by blast\nqed\n\nlemma (in imap) concurrent_append_store_independent_technical:\n  assumes \"i = mo\"\n    and \"xs prefix of j\"\n    and \"(i, Append i e) \\<in> set (node_deliver_messages xs)\" \n    and \"(r, Store e mo r) \\<in> set (node_deliver_messages xs)\"\n  shows \"hb (i, Append i e) (r, Store e mo r)\"\nproof -\n  obtain pre k where \"pre@[Broadcast (r, Store e mo r)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast\n  moreover hence f1: \"Deliver (mo, Append mo e) \\<in> set pre \\<or> \n  (\\<exists> mo2 . Deliver (mo, Store e mo2 mo) \\<in> set pre)\"\n    using Broadcast_Store_Deliver_prefix_closed assms(1) by auto\n  have f2: \"Deliver (i, Append i e) \\<in> set (history j)\"\n    by (meson assms network.prefix_msg_in_history network_axioms)\n  then show ?thesis using assms f1 \n    by (metis  calculation delivery_has_a_cause events_in_local_order fst_conv hb_deliver \n        msg_id_unique node_histories.prefix_of_appendD node_histories_axioms \n        prefix_elem_to_carriers)\nqed\n\nlemma (in imap) concurrent_expunge_delete_independent_technical:\n  assumes \"i \\<in> is\"\n    and \"xs prefix of j\"\n    and \"(i, Expunge e mo i) \\<in> set (node_deliver_messages xs)\" \n    and \"(ir, Delete is e) \\<in> set (node_deliver_messages xs)\"\n  shows \"hb (i, Expunge e mo i) (ir, Delete is e)\"\nproof -\n  obtain pre k where \"pre@[Broadcast (ir, Delete is e)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast\n  moreover hence A: \"Deliver (i, Create i e) \\<in> set pre \\<or> \n  Deliver (i, Append i e) \\<in> set pre \\<or> \n  (\\<exists> mo . Deliver (i, Expunge e mo i) \\<in> set pre) \\<or> \n  (\\<exists> mo . Deliver (i, Store e mo i) \\<in> set pre)\"\n    using Broadcast_Deliver_prefix_closed assms(1) by auto      \n  hence \"Deliver (i, Expunge e mo i) \\<in> set pre\" using assms\n  proof -\n    have f1: \"\\<And>e. e \\<notin> set pre \\<or> e \\<in> set (history k)\"\n      using calculation prefix_elem_to_carriers by blast\n    have f2: \"Deliver (i, Expunge e mo i) \\<in> set (history j)\"\n      by (meson assms network.prefix_msg_in_history network_axioms)\n    then show ?thesis using f1 A \n      by (metis (no_types, lifting) fst_conv msg_id_unique network.delivery_has_a_cause \n          network_axioms)\n  qed     \n  ultimately show ?thesis\n    using hb.intros(2) events_in_local_order by blast\nqed\n\nlemma (in imap) concurrent_store_store_independent_technical:\n  assumes \"xs prefix of j\"\n    and \"(i, Store e mo i) \\<in> set (node_deliver_messages xs)\" \n    and \"(r, Store e i r) \\<in> set (node_deliver_messages xs)\"\n  shows \"hb (i, Store e mo i) (r, Store e i r)\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (r, Store e i r)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast\n  hence f1: \"\\<forall>e. e \\<notin> set pre \\<or> e \\<in> set (history k)\"\n    using prefix_elem_to_carriers by blast\n  have f2: \"Deliver (i, Append i e) \\<in> set pre \\<or> (\\<exists> mo2 . Deliver (i, Store e mo2 i) \\<in> set pre)\"\n    using Broadcast_Store_Deliver_prefix_closed assms(1) P by auto     \n  hence \"Deliver (i, Store e mo i) \\<in> set pre\" using assms f1 \n    by (metis delivery_has_a_cause fst_conv msg_id_unique prefix_msg_in_history)\n  then show ?thesis\n    using hb.intros(2) events_in_local_order P by blast\nqed\n\nlemma (in imap) expunge_delete_tag_causality:\n  assumes \"i \\<in> is\"\n    and \"xs prefix of j\"\n    and \"(i, Expunge e1 mo i) \\<in> set (node_deliver_messages xs)\" \n    and \"(ir, Delete is e2) \\<in> set (node_deliver_messages xs)\" \n    and \"pre@[Broadcast (ir, Delete is e2)] prefix of k\"\n  shows \"Deliver (i, Expunge e2 mo i) \\<in> set (history k)\"\nproof- \n  have f1: \"Deliver (i, Append i e2) \\<notin> set (history k)\" using assms\n    by (metis fst_conv msg_id_unique network.delivery_has_a_cause network_axioms old.prod.inject \n        operation.distinct(15) prefix_msg_in_history)\n  have f2: \"Deliver (i, Create i e2) \\<notin> set (history k)\" using assms\n    by (metis fst_conv msg_id_unique network.delivery_has_a_cause network_axioms old.prod.inject \n        operation.distinct(5) prefix_msg_in_history)\n  have f3: \"\\<forall> mo. Deliver (i, Store e2 mo i) \\<notin> set (history k)\" using assms\n    by (metis Pair_inject fst_conv msg_id_unique network.delivery_has_a_cause network_axioms \n        operation.simps(25) prefix_msg_in_history)\n  hence \"\\<exists> mo1. Deliver (i, Expunge e2 mo1 i) \\<in> set (history k)\" using assms f1 f2 \n    by (meson imap.Broadcast_Deliver_prefix_closed imap_axioms node_histories.prefix_of_appendD \n        node_histories_axioms prefix_elem_to_carriers)\n  then obtain mo1 :: 'a where\n    \"Deliver (i, Expunge e2 mo1 i) \\<in> set (history k)\" by blast\n  then show ?thesis  using assms f1 f2 f3\n    by (metis fst_conv msg_id_unique network.delivery_has_a_cause network_axioms old.prod.inject \n        operation.inject(4) prefix_msg_in_history)\nqed\n\nlemma (in imap) expunge_delete_ids_imply_messages_same:\n  assumes \"i \\<in> is\"\n    and \"xs prefix of j\"\n    and \"(i, Expunge e1 mo i) \\<in> set (node_deliver_messages xs)\" \n    and \"(ir, Delete is e2) \\<in> set (node_deliver_messages xs)\"\n  shows \"e1 = e2\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (ir, Delete is e2)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast  \n  hence \"Deliver (i, Expunge e2 mo i) \\<in> set (history k)\" using assms expunge_delete_tag_causality\n    by blast\n  then show ?thesis using assms\n    by (metis delivery_has_a_cause fst_conv network.msg_id_unique network_axioms \n        operation.inject(4) prefix_msg_in_history prod.inject)\nqed\n\nlemma (in imap) store_delete_ids_imply_messages_same:\n  assumes \"i \\<in> is\"\n    and \"xs prefix of j\"\n    and \"(i, Store e1 mo i) \\<in> set (node_deliver_messages xs)\" \n    and \"(ir, Delete is e2) \\<in> set (node_deliver_messages xs)\"\n  shows \"e1 = e2\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (ir, Delete is e2)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast \n  have f1: \"Deliver (i, Append i e2) \\<notin> set (history k)\" using assms\n    by (metis fst_conv msg_id_unique network.delivery_has_a_cause network_axioms old.prod.inject \n        operation.distinct(17) prefix_msg_in_history)\n  have f2: \"\\<forall> mo. Deliver (i, Expunge e2 mo i) \\<notin> set (history k)\" using assms\n    by (metis Pair_inject fst_conv msg_id_unique network.delivery_has_a_cause network_axioms \n        operation.distinct(19) prefix_msg_in_history)\n  have f3: \"Deliver (i, Create i e2) \\<notin> set (history k)\" using assms\n    by (metis fst_conv msg_id_unique network.delivery_has_a_cause network_axioms old.prod.inject \n        operation.distinct(8) prefix_msg_in_history)\n  hence \"(\\<exists> mo1. Deliver (i, Store e2 mo1 i) \\<in> set pre)\" using assms P f1 f2 imap_axioms \n    by (meson imap.Broadcast_Deliver_prefix_closed prefix_elem_to_carriers prefix_of_appendD)\n  then obtain mo1 :: 'a where\n    f3: \"Deliver (i, Store e2 mo1 i) \\<in> set pre\" by blast\n  then have f4: \"Deliver (i, Store e2 mo1 i) \\<in> set (history k)\"\n    using P prefix_elem_to_carriers by blast \n  hence \"Deliver (i, Store e2 mo i) \\<in> set pre\" using f2 f3 assms \n    by (metis fst_conv msg_id_unique network.delivery_has_a_cause network_axioms old.prod.inject \n        operation.inject(5) prefix_msg_in_history)\n  moreover have \"Deliver(i, Store e1 mo i) \\<in> set (history j)\"\n    using assms(2) assms(3) prefix_msg_in_history by blast \n  ultimately show ?thesis using f4\n    by (metis delivery_has_a_cause fst_conv msg_id_unique old.prod.inject operation.inject(5))\nqed\n\nlemma (in imap) create_delete_ids_imply_messages_same:\n  assumes \"i \\<in> is\"\n    and \"xs prefix of j\"\n    and \"(i, Create i e1) \\<in> set (node_deliver_messages xs)\" \n    and \"(ir, Delete is e2) \\<in> set (node_deliver_messages xs)\"\n  shows \"e1 = e2\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (ir, Delete is e2)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast\n  have f1: \"Deliver (i, Append i e2) \\<notin> set (history k)\"\n    by (metis assms(2) assms(3) delivery_has_a_cause fst_conv network.msg_id_unique \n        network.prefix_msg_in_history network_axioms operation.distinct(3) prod.inject)\n  have f2: \"\\<forall> mo. Deliver (i, Expunge e2 mo i) \\<notin> set (history k)\"\n    by (metis assms(2) assms(3) fst_conv msg_id_unique network.delivery_has_a_cause network_axioms \n        old.prod.inject operation.distinct(5) prefix_msg_in_history)\n  have f3: \"\\<forall> mo. Deliver (i, Store e2 mo i) \\<notin> set (history k)\"\n    by (metis Pair_inject assms(2) assms(3) delivery_has_a_cause fst_conv msg_id_unique \n        operation.distinct(7) prefix_msg_in_history)\n  hence \"Deliver (i, Create i e2) \\<in> set pre\" using assms P f2 f1 imap_axioms\n    by (meson imap.Broadcast_Deliver_prefix_closed  prefix_elem_to_carriers prefix_of_appendD)\n  then show ?thesis using f1 f2 f3\n    by (metis (no_types, lifting) P assms(2) assms(3) delivery_has_a_cause fst_conv msg_id_unique \n        node_histories.prefix_of_appendD node_histories_axioms old.prod.inject operation.inject(1) \n        prefix_elem_to_carriers prefix_msg_in_history)\nqed\n\nlemma (in imap) append_delete_ids_imply_messages_same:\n  assumes \"i \\<in> is\"\n    and \"xs prefix of j\"\n    and \"(i, Append i e1) \\<in> set (node_deliver_messages xs)\" \n    and \"(ir, Delete is e2) \\<in> set (node_deliver_messages xs)\"\n  shows \"e1 = e2\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (ir, Delete is e2)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast  \n  hence f1: \"\\<forall>e. e \\<notin> set pre \\<or> e \\<in> set (history k)\" using prefix_elem_to_carriers by blast\n  have f2: \"Deliver (i, Create i e2) \\<notin> set pre\" using P f1\n    by (metis assms(2) assms(3) fst_conv msg_id_unique network.delivery_has_a_cause network_axioms \n        old.prod.inject operation.distinct(3) prefix_msg_in_history)\n  moreover have \"\\<forall> mo. Deliver (i, Expunge e2 mo i) \\<notin> set pre\" using P f1\n    by (metis Pair_inject assms(2) assms(3) fst_conv msg_id_unique network.delivery_has_a_cause \n        network_axioms operation.distinct(15) prefix_msg_in_history)\n  moreover have \"\\<forall> mo. Deliver (i, Store e2 mo i) \\<notin> set pre\" using P f1\n    by (metis Pair_inject assms(2) assms(3) fst_conv msg_id_unique network.delivery_has_a_cause \n        network_axioms operation.simps(23) prefix_msg_in_history)\n  moreover hence \"Deliver (i, Append i e2) \\<in> set pre\" \n    using P calculation(3) f2 assms(1) calculation(2) Broadcast_Deliver_prefix_closed by blast\n  moreover have \"Deliver (i, Append i e1) \\<in> set (history j)\"\n    using assms(2) assms(3) prefix_msg_in_history by blast\n  ultimately show ?thesis using assms \n    by (metis f1 msg_id_unique network.delivery_has_a_cause network_axioms old.prod.inject \n        operation.inject(3) prod.sel(1))\nqed\n\nlemma (in imap) append_expunge_ids_imply_messages_same:\n  assumes \"i = mo\"\n    and \"xs prefix of j\"\n    and \"(i, Append i e1) \\<in> set (node_deliver_messages xs)\" \n    and \"(r, Expunge e2 mo r) \\<in> set (node_deliver_messages xs)\"\n  shows \"e1 = e2\"\nproof -\n  obtain pre k where \"pre@[Broadcast (r, Expunge e2 mo r)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast  \n  moreover hence \"Deliver (mo, Append mo e2) \\<in> set pre \\<or> \n  (\\<exists> mo2 . Deliver (mo, Store e2 mo2 mo) \\<in> set pre)\"\n    using Broadcast_Expunge_Deliver_prefix_closed assms(1)\n    by (meson imap.Broadcast_Deliver_prefix_closed imap_axioms)      \n  hence \"Deliver (i, Append i e2) \\<in> set pre\" using assms\n    by (metis (no_types, lifting) calculation delivery_has_a_cause fst_conv hb_broadcast_exists1 \n        msg_id_unique network.hb_deliver network.prefix_msg_in_history network_axioms \n        node_histories.events_in_local_order node_histories_axioms operation.distinct(17) \n        prod.inject)     \n  moreover have \"Deliver (i, Append i e1) \\<in> set (history j)\"\n    using assms(2) assms(3) prefix_msg_in_history by blast\n  ultimately show ?thesis\n    by (metis (no_types, lifting) fst_conv network.delivery_has_a_cause network.msg_id_unique \n        network_axioms operation.inject(3) prefix_elem_to_carriers prefix_of_appendD prod.inject)\nqed\n\nlemma (in imap) append_store_ids_imply_messages_same:\n  assumes \"i = mo\"\n    and \"xs prefix of j\"\n    and \"(i, Append i e1) \\<in> set (node_deliver_messages xs)\" \n    and \"(r, Store e2 mo r) \\<in> set (node_deliver_messages xs)\"\n  shows \"e1 = e2\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (r, Store e2 mo r)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast  \n  moreover hence A: \"Deliver (mo, Append mo e2) \\<in> set pre \\<or> \n  (\\<exists> mo2 . Deliver (mo, Store e2 mo2 mo) \\<in> set pre)\"\n    using Broadcast_Store_Deliver_prefix_closed assms(1)\n    by (meson imap.Broadcast_Deliver_prefix_closed imap_axioms)\n  have f1: \"Deliver (i, Append i e1) \\<in> set (history j)\"\n    using assms(2) assms(3) prefix_msg_in_history by blast\n  hence \"Deliver (i, Append i e2) \\<in> set pre\" using assms P A\n    by (metis Pair_inject assms(1) calculation delivery_has_a_cause fst_conv msg_id_unique \n        operation.simps(23) prefix_elem_to_carriers prefix_of_appendD)\n  then show ?thesis using f1\n    by (metis calculation delivery_has_a_cause fst_conv msg_id_unique \n        node_histories.prefix_of_appendD node_histories_axioms operation.inject(3) \n        prefix_elem_to_carriers prod.inject)\nqed\n\nlemma (in imap) expunge_store_ids_imply_messages_same:\n  assumes \"xs prefix of j\"\n    and \"(i, Store e1 mo i) \\<in> set (node_deliver_messages xs)\" \n    and \"(r, Expunge e2 i r) \\<in> set (node_deliver_messages xs)\"\n  shows \"e1 = e2\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (r, Expunge e2 i r)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast \n  hence pprefix: \"pre prefix of k\"\n    using P by blast\n  have A: \"Deliver (i, Append i e2) \\<in> set pre \\<or> \n  (\\<exists> mo2 . Deliver (i, Store e2 mo2 i) \\<in> set pre)\"\n    using Broadcast_Expunge_Deliver_prefix_closed assms(1) P by blast      \n  have \"Deliver (i, Store e2 mo i) \\<in> set pre\" using assms A P\n  proof -\n    obtain op1 :: \"'a \\<times> ('a, 'b) operation \\<Rightarrow> nat\" where\n      f1: \"Broadcast (i, Store e1 mo i) \\<in> set (history (op1 (i, Store e1 mo i)))\"\n      by (meson assms(1) assms(2) delivery_has_a_cause prefix_msg_in_history)\n    then show ?thesis \n      using f1 A pprefix delivery_has_a_cause network.msg_id_unique network_axioms \n        node_histories.prefix_to_carriers node_histories_axioms \n      by fastforce\n  qed\n  moreover have \"Deliver (i, Store e1 mo i) \\<in> set (history j)\"\n    using assms(1) assms(2) prefix_msg_in_history by auto\n  ultimately show ?thesis using assms P\n    by (metis delivery_has_a_cause fst_conv msg_id_unique operation.inject(5) \n        prefix_elem_to_carriers prefix_of_appendD prod.inject) \nqed\n\nlemma (in imap) store_store_ids_imply_messages_same:\n  assumes \"xs prefix of j\"\n    and \"(i, Store e1 mo i) \\<in> set (node_deliver_messages xs)\" \n    and \"(r, Store e2 i r) \\<in> set (node_deliver_messages xs)\"\n  shows \"e1 = e2\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (r, Store e2 i r)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast  \n  moreover hence A: \"Deliver (i, Append i e2) \\<in> set pre \\<or>\n    (\\<exists> mo2 . Deliver (i, Store e2 mo2 i) \\<in> set pre)\"\n    using Broadcast_Store_Deliver_prefix_closed assms(1) by blast\n  have \"\\<forall>e. e \\<notin> set pre \\<or> e \\<in> set (history k)\"\n    using calculation prefix_elem_to_carriers by auto\n  hence \"Deliver (i, Store e2 mo i) \\<in> set pre\" \n    by (metis A assms(1) assms(2) delivery_has_a_cause fst_conv msg_id_unique \n        operation.distinct(17) operation.inject(5) prefix_msg_in_history prod.inject)\n  moreover have \"Deliver (i, Store e1 mo i) \\<in> set (history j)\"\n    using assms(1) assms(2) prefix_msg_in_history by auto\n  ultimately show ?thesis using assms\n    by (metis Pair_inject delivery_has_a_cause msg_id_unique operation.simps(5) \n        prefix_elem_to_carriers prefix_of_appendD prod.sel(1))\nqed \n\nend\n", "meta": {"author": "go-pluto", "repo": "verification", "sha": "db28e53a61b1522752473372a9f013ff0694464b", "save_path": "github-repos/isabelle/go-pluto-verification", "path": "github-repos/isabelle/go-pluto-verification/verification-db28e53a61b1522752473372a9f013ff0694464b/thys/IMAP-CRDT/IMAP-proof-independent.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.2712334235359007}}
{"text": "(*  Title:       Abstract Rewriting\n    Author:      Christian Sternagel <christian.sternagel@uibk.ac.at>\n                 Rene Thiemann       <rene.tiemann@uibk.ac.at>\n    Maintainer:  Christian Sternagel and Rene Thiemann\n    License:     LGPL\n*)\n\n(*\nCopyright 2010 Christian Sternagel and René Thiemann\n\nThis file is part of IsaFoR/CeTA.\n\nIsaFoR/CeTA is free software: you can redistribute it and/or modify it under the\nterms of the GNU Lesser General Public License as published by the Free Software\nFoundation, either version 3 of the License, or (at your option) any later\nversion.\n\nIsaFoR/CeTA is distributed in the hope that it will be useful, but WITHOUT ANY\nWARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A\nPARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public License along\nwith IsaFoR/CeTA. If not, see <http://www.gnu.org/licenses/>.\n*)\n\nheader {* Relative Rewriting *}\n\ntheory Relative_Rewriting\nimports Abstract_Rewriting\nbegin\n\ntext {*Considering a relation @{term R} relative to another relation @{term S}, i.e.,\n@{term R}-steps may be preceded and followd by arbitrary many @{term S}-steps.*}\nabbreviation (input) relto :: \"'a rel \\<Rightarrow> 'a rel \\<Rightarrow> 'a rel\" where\n  \"relto R S \\<equiv> S^* O R O S^*\"\n\ndefinition SN_rel_on :: \"'a rel \\<Rightarrow> 'a rel \\<Rightarrow> 'a set \\<Rightarrow> bool\" where\n  \"SN_rel_on R S \\<equiv> SN_on (relto R S)\"\n\ndefinition SN_rel_on_alt :: \"'a rel \\<Rightarrow> 'a rel \\<Rightarrow> 'a set \\<Rightarrow> bool\" where\n  \"SN_rel_on_alt R S T = (\\<forall>f. chain (R \\<union> S) f \\<and> f 0 \\<in> T \\<longrightarrow> \\<not> (INFM j. (f j, f (Suc j)) \\<in> R))\"\n\nabbreviation SN_rel :: \"'a rel \\<Rightarrow> 'a rel \\<Rightarrow> bool\" where\n  \"SN_rel R S \\<equiv> SN_rel_on R S UNIV\"\n\nabbreviation SN_rel_alt :: \"'a rel \\<Rightarrow> 'a rel \\<Rightarrow> bool\" where\n  \"SN_rel_alt R S \\<equiv> SN_rel_on_alt R S UNIV\"\n\n\nlemma steps_preserve_SN_on_relto:\n  assumes steps: \"(a, b) \\<in> (R \\<union> S)^*\"\n    and SN: \"SN_on (relto R S) {a}\"\n  shows \"SN_on (relto R S) {b}\"\nproof -\n  let ?RS = \"relto R S\"\n  have \"(R \\<union> S)^* \\<subseteq> S^* \\<union> ?RS^*\" by regexp\n  with steps have \"(a,b) \\<in> S^* \\<or> (a,b) \\<in> ?RS^*\" by auto\n  thus ?thesis\n  proof\n    assume \"(a,b) \\<in> ?RS^*\"\n    from steps_preserve_SN_on[OF this SN] show ?thesis .\n  next\n    assume Ssteps: \"(a,b) \\<in> S^*\"\n    show ?thesis\n    proof\n      fix f\n      assume \"f 0 \\<in> {b}\" and \"chain ?RS f\"\n      hence f0: \"f 0 = b\" and steps: \"\\<And>i. (f i, f (Suc i)) \\<in> ?RS\" by auto\n      let ?g = \"\\<lambda> i. if i = 0 then a else f i\"\n      have \"\\<not> SN_on ?RS {a}\" unfolding SN_on_def not_not\n      proof (rule exI[of _ ?g], intro conjI allI)\n        fix i\n        show \"(?g i, ?g (Suc i)) \\<in> ?RS\"\n        proof (cases i)\n          case (Suc j)\n          show ?thesis using steps[of i] unfolding Suc by simp\n        next\n          case 0\n          from steps[of 0, unfolded f0] Ssteps have steps: \"(a,f (Suc 0)) \\<in> S^* O ?RS\" by auto\n          have \"(a,f (Suc 0)) \\<in> ?RS\" \n            by (rule set_mp[OF _ steps], regexp)\n          thus ?thesis unfolding 0 by simp\n        qed\n      qed simp\n      with SN show False by simp\n    qed\n  qed\nqed\n\nlemma SN_rel_on_imp_SN_rel_on_alt: \"SN_rel_on R S T \\<Longrightarrow> SN_rel_on_alt R S T\"\nproof (unfold SN_rel_on_def)\n  assume SN: \"SN_on (relto R S) T\"\n  show ?thesis\n  proof (unfold SN_rel_on_alt_def, intro allI impI)\n    fix f\n    assume steps: \"chain (R \\<union> S) f \\<and> f 0 \\<in> T\"\n    with SN have SN: \"SN_on (relto R S) {f 0}\" \n      and steps: \"\\<And> i. (f i, f (Suc i)) \\<in> R \\<union> S\" unfolding SN_defs by auto\n    obtain r where  r: \"\\<And> j. r j \\<equiv>  (f j, f (Suc j)) \\<in> R\" by auto\n    show \"\\<not> (INFM j. (f j, f (Suc j)) \\<in> R)\"\n    proof (rule ccontr)\n      assume \"\\<not> ?thesis\"\n      hence ih: \"infinitely_many r\" unfolding infinitely_many_def r by blast\n      obtain r_index where \"r_index = infinitely_many.index r\" by simp\n      with infinitely_many.index_p[OF ih] infinitely_many.index_ordered[OF ih] infinitely_many.index_not_p_between[OF ih] \n      have r_index: \"\\<And> i. r (r_index i) \\<and> r_index i < r_index (Suc i) \\<and> (\\<forall> j. r_index i < j \\<and> j < r_index (Suc i) \\<longrightarrow> \\<not> r j)\" by auto\n      obtain g where g: \"\\<And> i. g i \\<equiv> f (r_index i)\" ..\n      {\n        fix i\n        let ?ri = \"r_index i\"\n        let ?rsi = \"r_index (Suc i)\"\n        from r_index have isi: \"?ri < ?rsi\" by auto\n        obtain ri rsi where ri: \"ri = ?ri\" and rsi: \"rsi = ?rsi\" by auto\n        with r_index[of i] steps have inter: \"\\<And> j. ri < j \\<and> j < rsi \\<Longrightarrow> (f j, f (Suc j)) \\<in> S\" unfolding r by auto\n        from ri isi rsi have risi: \"ri < rsi\" by simp                      \n        {\n          fix n\n          assume \"Suc n \\<le> rsi - ri\"\n          hence \"(f (Suc ri), f (Suc (n + ri))) \\<in> S^*\"\n          proof (induct n, simp)\n            case (Suc n)\n            hence stepps: \"(f (Suc ri), f (Suc (n+ri))) \\<in> S^*\" by simp\n            have \"(f (Suc (n+ri)), f (Suc (Suc n + ri))) \\<in> S\"\n              using inter[of \"Suc n + ri\"] Suc(2) by auto\n            with stepps show ?case by simp\n          qed\n        }\n        from this[of \"rsi - ri - 1\"] risi have \n          \"(f (Suc ri), f rsi) \\<in> S^*\" by simp\n        with ri rsi have ssteps: \"(f (Suc ?ri), f ?rsi) \\<in> S^*\" by simp\n        with r_index[of i] have \"(f ?ri, f ?rsi) \\<in> R O S^*\" unfolding r by auto\n        hence \"(g i, g (Suc i)) \\<in> S^* O R O S^*\" using rtrancl_refl unfolding g by auto        \n      } \n      hence nSN: \"\\<not> SN_on (S^* O R O S^*) {g 0}\" unfolding SN_defs by blast\n      have SN: \"SN_on (S^* O R O S^*) {f (r_index 0)}\"\n      proof (rule steps_preserve_SN_on_relto[OF _ SN])\n        show \"(f 0, f (r_index 0)) \\<in> (R \\<union> S)^*\"\n          unfolding rtrancl_fun_conv\n          by (rule exI[of _ f], rule exI[of _ \"r_index 0\"], insert steps, auto)\n      qed\n      with nSN show False unfolding g ..\n    qed\n  qed\nqed\n        \nlemma SN_rel_on_alt_imp_SN_rel_on: \"SN_rel_on_alt R S T \\<Longrightarrow> SN_rel_on R S T\"\nproof (unfold SN_rel_on_def)\n  assume SN: \"SN_rel_on_alt R S T\"\n  show \"SN_on (relto R S) T\"\n  proof\n    fix f\n    assume start: \"f 0 \\<in> T\" and  \"chain (relto R S) f\"\n    hence steps: \"\\<And> i. (f i, f (Suc i)) \\<in> S^* O R O S^*\" by auto\n    let ?prop = \"\\<lambda> i ai bi. (f i, bi) \\<in> S^* \\<and> (bi, ai) \\<in> R \\<and> (ai, f (Suc (i))) \\<in> S^*\"\n    {\n      fix i\n      from steps obtain bi ai where \"?prop i ai bi\" by blast\n      hence \"\\<exists> ai bi. ?prop i ai bi\" by blast\n    }\n    hence \"\\<forall> i. \\<exists> bi ai. ?prop i ai bi\" by blast\n    from choice[OF this] obtain b where \"\\<forall> i. \\<exists> ai. ?prop i ai (b i)\" by blast\n    from choice[OF this] obtain a where steps: \"\\<And> i. ?prop i (a i) (b i)\" by blast\n    from steps[of 0] have fa0: \"(f 0, a 0) \\<in> S^* O R\" by auto\n    let ?prop = \"\\<lambda> i li. (b i, a i) \\<in> R \\<and> (\\<forall> j < length li. ((a i # li) ! j, (a i # li) ! Suc j) \\<in> S) \\<and> last (a i # li) = b (Suc i)\"\n    {\n      fix i\n      from steps[of i] steps[of \"Suc i\"] have \"(a i, f (Suc i)) \\<in> S^*\" and \"(f (Suc i), b (Suc i)) \\<in> S^*\" by auto\n      from rtrancl_trans[OF this] steps[of i] have R: \"(b i, a i) \\<in> R\" and S: \"(a i, b (Suc i)) \\<in> S^*\" by blast+\n      from S[unfolded rtrancl_list_conv] obtain li where \"last (a i # li) = b (Suc i) \\<and> (\\<forall> j < length li. ((a i # li) ! j, (a i # li) ! Suc j) \\<in> S)\" ..\n      with R have \"?prop i li\" by blast\n      hence \"\\<exists> li. ?prop i li\" ..\n    }\n    hence \"\\<forall> i. \\<exists> li. ?prop i li\" ..\n    from choice[OF this] obtain l where steps: \"\\<And> i. ?prop i (l i)\" by auto\n    let ?p = \"\\<lambda> i. ?prop i (l i)\"\n    from steps have steps: \"\\<And> i. ?p i\" by blast\n    let ?l = \"\\<lambda> i. a i # l i\"    \n    let ?l' = \"\\<lambda> i. length (?l i)\"\n    let ?g = \"\\<lambda> i. inf_concat_simple ?l' i\"\n    obtain g where g: \"\\<And> i. g i = (let (ii,jj) = ?g i in ?l ii ! jj)\" by auto   \n    have g0: \"g 0 = a 0\" unfolding g Let_def by simp\n    with fa0 have fg0: \"(f 0, g 0) \\<in> S^* O R\" by auto\n    have fg0: \"(f 0, g 0) \\<in> (R \\<union> S)^*\"\n      by (rule set_mp[OF _ fg0], regexp)\n    have len: \"\\<And> i j n. ?g n = (i,j) \\<Longrightarrow> j < length (?l i)\"\n    proof -\n      fix i j n\n      assume n: \"?g n = (i,j)\"\n      show \"j < length (?l i)\" \n      proof (cases n)\n        case 0\n        with n have \"j = 0\" by auto\n        thus ?thesis by simp\n      next\n        case (Suc nn)\n        obtain ii jj where nn: \"?g nn = (ii,jj)\" by (cases \"?g nn\", auto)\n        show ?thesis \n        proof (cases \"Suc jj < length (?l ii)\")\n          case True\n          with nn Suc have \"?g n = (ii, Suc jj)\" by auto\n          with n True show ?thesis by simp\n        next\n          case False \n          with nn Suc have \"?g n = (Suc ii, 0)\" by auto\n          with n show ?thesis by simp\n        qed\n      qed\n    qed      \n    have gsteps: \"\\<And> i. (g i, g (Suc i)) \\<in> R \\<union> S\"\n    proof -\n      fix n\n      obtain i j where n: \"?g n = (i, j)\" by (cases \"?g n\", auto)\n      show \"(g n, g (Suc n)) \\<in> R \\<union> S\"\n      proof (cases \"Suc j < length (?l i)\")\n        case True\n        with n have \"?g (Suc n) = (i, Suc j)\" by auto\n        with n have gn: \"g n = ?l i ! j\" and gsn: \"g (Suc n) = ?l i ! (Suc j)\" unfolding g by auto\n        thus ?thesis using steps[of i] True by auto\n      next\n        case False\n        with n have \"?g (Suc n) = (Suc i, 0)\" by auto\n        with n have gn: \"g n = ?l i ! j\" and gsn: \"g (Suc n) = a (Suc i)\" unfolding g by auto\n        from gn len[OF n] False have \"j = length (?l i) - 1\" by auto\n        with gn have gn: \"g n = last (?l i)\" using last_conv_nth[of \"?l i\"] by auto\n        from gn gsn show ?thesis using steps[of i] steps[of \"Suc i\"] by auto\n      qed\n    qed\n    have infR:  \"INFM j. (g j, g (Suc j)) \\<in> R\" unfolding INFM_nat_le\n    proof\n      fix n\n      obtain i j where n: \"?g n = (i,j)\" by (cases \"?g n\", auto)\n      from len[OF n] have j: \"j < ?l' i\" .\n      let ?k = \"?l' i - 1 - j\"\n      obtain k where k: \"k = j + ?k\" by auto\n      from j k have k2: \"k = ?l' i - 1\" and k3: \"j + ?k < ?l' i\" by auto\n      from inf_concat_simple_add[OF n, of ?k, OF k3] \n      have gnk: \"?g (n + ?k) = (i, k)\" by (simp only: k)\n      hence \"g (n + ?k) = ?l i ! k\" unfolding g by auto\n      hence gnk2: \"g (n + ?k) = last (?l i)\" using last_conv_nth[of \"?l i\"] k2 by auto\n      from k2 gnk have \"?g (Suc (n+?k)) = (Suc i, 0)\" by auto\n      hence gnsk2: \"g (Suc (n+?k)) = a (Suc i)\" unfolding g by auto\n      from steps[of i] steps[of \"Suc i\"] have main: \"(g (n+?k), g (Suc (n+?k))) \\<in> R\" \n        by (simp only: gnk2 gnsk2)\n      show \"\\<exists> j \\<ge> n. (g j, g (Suc j)) \\<in> R\" \n        by (rule exI[of _ \"n + ?k\"], auto simp: main[simplified])\n    qed\n    from fg0[unfolded rtrancl_fun_conv] obtain gg n where start: \"gg 0 = f 0\" \n      and n: \"gg n = g 0\" and steps: \"\\<And> i. i < n \\<Longrightarrow> (gg i, gg (Suc i)) \\<in> R \\<union> S\" by auto\n    let ?h = \"\\<lambda> i. if i < n then gg i else g (i - n)\"\n    obtain h where h: \"h = ?h\" by auto\n    {\n      fix i\n      assume i: \"i \\<le> n\"\n      have \"h i = gg i\" using i unfolding h\n        by (cases \"i < n\", auto simp: n)\n    } note gg = this\n    from gg[of 0]  `f 0 \\<in> T` have h0: \"h 0 \\<in> T\" unfolding start by auto\n    {\n      fix i\n      have \"(h i, h (Suc i)) \\<in> R \\<union> S\"\n      proof (cases \"i < n\")\n        case True\n        from steps[of i] gg[of i] gg[of \"Suc i\"] True show ?thesis by auto\n      next\n        case False\n        hence \"i = n + (i - n)\" by auto\n        then obtain k where i: \"i = n + k\" by auto\n        from gsteps[of k] show ?thesis unfolding h i by simp\n      qed\n    } note hsteps = this\n    from SN[unfolded SN_rel_on_alt_def, rule_format, OF conjI[OF allI[OF hsteps] h0]]\n    have \"\\<not> (INFM j. (h j, h (Suc j)) \\<in> R)\" .\n    moreover have \"INFM j. (h j, h (Suc j)) \\<in> R\" unfolding INFM_nat_le\n    proof (rule)\n      fix m\n      from infR[unfolded INFM_nat_le, rule_format, of m]\n      obtain i where i: \"i \\<ge> m\" and g: \"(g i, g (Suc i)) \\<in> R\" by auto\n      show \"\\<exists> n \\<ge> m. (h n , h (Suc n)) \\<in> R\"\n        by (rule exI[of _ \"i + n\"], unfold h, insert g i, auto)\n    qed\n    ultimately show False ..\n  qed\nqed\n\n\nlemma SN_rel_on_conv: \"SN_rel_on = SN_rel_on_alt\"\n  by (intro ext) (blast intro: SN_rel_on_imp_SN_rel_on_alt SN_rel_on_alt_imp_SN_rel_on)\n\nlemmas SN_rel_defs = SN_rel_on_def SN_rel_on_alt_def\n\nlemma SN_rel_on_alt_r_empty : \"SN_rel_on_alt {} S T\"\n  unfolding SN_rel_defs by auto\n\nlemma SN_rel_on_alt_s_empty : \"SN_rel_on_alt R {} = SN_on R\"\n  by (intro ext, unfold SN_rel_defs SN_defs, auto)\n\nlemma SN_rel_on_mono':\n  assumes R: \"R \\<subseteq> R'\" and S: \"S \\<subseteq> R' \\<union> S'\" and SN: \"SN_rel_on R' S' T\"\n  shows \"SN_rel_on R S T\"\nproof -\n  note conv = SN_rel_on_conv SN_rel_on_alt_def INFM_nat_le\n  show ?thesis unfolding conv\n  proof(intro allI impI)\n    fix f\n    assume \"chain (R \\<union> S) f \\<and> f 0 \\<in> T\"\n    with R S have \"chain (R' \\<union> S') f \\<and> f 0 \\<in> T\" by auto\n    from SN[unfolded conv, rule_format, OF this]\n    show \"\\<not> (\\<forall> m. \\<exists> n \\<ge> m. (f n, f (Suc n)) \\<in> R)\" using R by auto\n  qed\nqed\n\nlemma relto_mono:\n  assumes \"R \\<subseteq> R'\" and \"S \\<subseteq> S'\"\n  shows \"relto R S \\<subseteq> relto R' S'\"\n  using assms rtrancl_mono by blast\n\nlemma SN_rel_on_mono:\n  assumes R: \"R \\<subseteq> R'\" and S: \"S \\<subseteq> S'\"\n    and SN: \"SN_rel_on R' S' T\"\n  shows \"SN_rel_on R S T\"\n  using SN\n  unfolding SN_rel_on_def using SN_on_mono[OF _ relto_mono[OF R S]] by blast\n\nlemmas SN_rel_on_alt_mono = SN_rel_on_mono[unfolded SN_rel_on_conv]\n\nlemma SN_rel_on_imp_SN_on:\n  assumes \"SN_rel_on R S T\" shows  \"SN_on R T\"\nproof\n  fix f\n  assume \"chain R f\"\n  and f0: \"f 0 \\<in> T\"\n  hence \"\\<And>i. (f i, f (Suc i)) \\<in> relto R S\" by blast\n  thus False using assms f0 unfolding SN_rel_on_def SN_defs by blast\nqed\n\n\n\nlemma SN_rel_on_Id:\n  shows \"SN_rel_on R (S \\<union> Id) T = SN_rel_on R S T\"\n  unfolding SN_rel_on_def by (simp only: relto_Id)\n\nlemma SN_rel_on_empty[simp]: \"SN_rel_on R {} T = SN_on R T\"\n  unfolding SN_rel_on_def by auto\n\nlemma SN_rel_on_ideriv: \"SN_rel_on R S T = (\\<not> (\\<exists> as. ideriv R S as \\<and> as 0 \\<in> T))\" (is \"?L = ?R\")\nproof\n  assume ?L\n  show ?R\n  proof\n    assume \"\\<exists> as. ideriv R S as \\<and> as 0 \\<in> T\"\n    then obtain as where id: \"ideriv R S as\" and T: \"as 0 \\<in> T\" by auto\n    note id = id[unfolded ideriv_def]\n    from `?L`[unfolded SN_rel_on_conv SN_rel_on_alt_def, THEN spec[of _ as]]\n      id T obtain i where i: \"\\<And> j. j \\<ge> i \\<Longrightarrow> (as j, as (Suc j)) \\<notin> R\" by auto\n    with id[unfolded INFM_nat, THEN conjunct2, THEN spec[of _ \"Suc i\"]] show False by auto\n  qed\nnext\n  assume ?R\n  show ?L\n    unfolding SN_rel_on_conv SN_rel_on_alt_def\n  proof(intro allI impI)\n    fix as\n    assume \"chain (R \\<union> S) as \\<and> as 0 \\<in> T\"\n    with `?R`[unfolded ideriv_def] have \"\\<not> (INFM i. (as i, as (Suc i)) \\<in> R)\" by auto\n    from this[unfolded INFM_nat] obtain i where i: \"\\<And>j. i < j \\<Longrightarrow> (as j, as (Suc j)) \\<notin> R\" by auto\n    show \"\\<not> (INFM j. (as j, as (Suc j)) \\<in> R)\" unfolding INFM_nat using i by blast\n  qed\nqed\n\nlemma SN_rel_to_SN_rel_alt: \"SN_rel R S \\<Longrightarrow> SN_rel_alt R S\"\nproof (unfold SN_rel_on_def)\n  assume SN: \"SN (relto R S)\"\n  show ?thesis\n  proof (unfold SN_rel_on_alt_def, intro allI impI)\n    fix f\n    presume steps: \"chain (R \\<union> S) f\"\n    obtain r where  r: \"\\<And>j. r j \\<equiv>  (f j, f (Suc j)) \\<in> R\" by auto\n    show \"\\<not> (INFM j. (f j, f (Suc j)) \\<in> R)\"\n    proof (rule ccontr)\n      assume \"\\<not> ?thesis\"\n      hence ih: \"infinitely_many r\" unfolding infinitely_many_def r by blast\n      obtain r_index where \"r_index = infinitely_many.index r\" by simp\n      with infinitely_many.index_p[OF ih] infinitely_many.index_ordered[OF ih] infinitely_many.index_not_p_between[OF ih] \n      have r_index: \"\\<And> i. r (r_index i) \\<and> r_index i < r_index (Suc i) \\<and> (\\<forall> j. r_index i < j \\<and> j < r_index (Suc i) \\<longrightarrow> \\<not> r j)\" by auto\n      obtain g where g: \"\\<And> i. g i \\<equiv> f (r_index i)\" ..\n      {\n        fix i\n        let ?ri = \"r_index i\"\n        let ?rsi = \"r_index (Suc i)\"\n        from r_index have isi: \"?ri < ?rsi\" by auto\n        obtain ri rsi where ri: \"ri = ?ri\" and rsi: \"rsi = ?rsi\" by auto\n        with r_index[of i] steps have inter: \"\\<And> j. ri < j \\<and> j < rsi \\<Longrightarrow> (f j, f (Suc j)) \\<in> S\" unfolding r by auto\n        from ri isi rsi have risi: \"ri < rsi\" by simp                      \n        {\n          fix n\n          assume \"Suc n \\<le> rsi - ri\"\n          hence \"(f (Suc ri), f (Suc (n + ri))) \\<in> S^*\"\n          proof (induct n, simp)\n            case (Suc n)\n            hence stepps: \"(f (Suc ri), f (Suc (n+ri))) \\<in> S^*\" by simp\n            have \"(f (Suc (n+ri)), f (Suc (Suc n + ri))) \\<in> S\"\n              using inter[of \"Suc n + ri\"] Suc(2) by auto\n            with stepps show ?case by simp\n          qed\n        }\n        from this[of \"rsi - ri - 1\"] risi have \n          \"(f (Suc ri), f rsi) \\<in> S^*\" by simp\n        with ri rsi have ssteps: \"(f (Suc ?ri), f ?rsi) \\<in> S^*\" by simp\n        with r_index[of i] have \"(f ?ri, f ?rsi) \\<in> R O S^*\" unfolding r by auto\n        hence \"(g i, g (Suc i)) \\<in> S^* O R O S^*\" using rtrancl_refl unfolding g by auto           \n      } \n      hence \"\\<not> SN (S^* O R O S^*)\" unfolding SN_defs by blast\n      with SN show False by simp\n    qed\n  qed simp\nqed\n\nlemma SN_rel_alt_to_SN_rel : \"SN_rel_alt R S \\<Longrightarrow> SN_rel R S\"\nproof (unfold SN_rel_on_def)\n  assume SN: \"SN_rel_alt R S\"\n  show \"SN (relto R S)\"\n  proof\n    fix f\n    assume \"chain (relto R S) f\"\n    hence steps: \"\\<And>i. (f i, f (Suc i)) \\<in> S^* O R O S^*\" by auto\n    let ?prop = \"\\<lambda> i ai bi. (f i, bi) \\<in> S^* \\<and> (bi, ai) \\<in> R \\<and> (ai, f (Suc (i))) \\<in> S^*\"\n    {\n      fix i\n      from steps obtain bi ai where \"?prop i ai bi\" by blast\n      hence \"\\<exists> ai bi. ?prop i ai bi\" by blast\n    }\n    hence \"\\<forall> i. \\<exists> bi ai. ?prop i ai bi\" by blast\n    from choice[OF this] obtain b where \"\\<forall> i. \\<exists> ai. ?prop i ai (b i)\" by blast\n    from choice[OF this] obtain a where steps: \"\\<And> i. ?prop i (a i) (b i)\" by blast\n    let ?prop = \"\\<lambda> i li. (b i, a i) \\<in> R \\<and> (\\<forall> j < length li. ((a i # li) ! j, (a i # li) ! Suc j) \\<in> S) \\<and> last (a i # li) = b (Suc i)\"\n    {\n      fix i\n      from steps[of i] steps[of \"Suc i\"] have \"(a i, f (Suc i)) \\<in> S^*\" and \"(f (Suc i), b (Suc i)) \\<in> S^*\" by auto\n      from rtrancl_trans[OF this] steps[of i] have R: \"(b i, a i) \\<in> R\" and S: \"(a i, b (Suc i)) \\<in> S^*\" by blast+\n      from S[unfolded rtrancl_list_conv] obtain li where \"last (a i # li) = b (Suc i) \\<and> (\\<forall> j < length li. ((a i # li) ! j, (a i # li) ! Suc j) \\<in> S)\" ..\n      with R have \"?prop i li\" by blast\n      hence \"\\<exists> li. ?prop i li\" ..\n    }\n    hence \"\\<forall> i. \\<exists> li. ?prop i li\" ..\n    from choice[OF this] obtain l where steps: \"\\<And> i. ?prop i (l i)\" by auto\n    let ?p = \"\\<lambda> i. ?prop i (l i)\"\n    from steps have steps: \"\\<And> i. ?p i\" by blast\n    let ?l = \"\\<lambda> i. a i # l i\"    \n    let ?l' = \"\\<lambda> i. length (?l i)\"\n    let ?g = \"\\<lambda> i. inf_concat_simple ?l' i\"\n    obtain g where g: \"\\<And> i. g i = (let (ii,jj) = ?g i in ?l ii ! jj)\" by auto    \n    have len: \"\\<And> i j n. ?g n = (i,j) \\<Longrightarrow> j < length (?l i)\"\n    proof -\n      fix i j n\n      assume n: \"?g n = (i,j)\"\n      show \"j < length (?l i)\" \n      proof (cases n)\n        case 0\n        with n have \"j = 0\" by auto\n        thus ?thesis by simp\n      next\n        case (Suc nn)\n        obtain ii jj where nn: \"?g nn = (ii,jj)\" by (cases \"?g nn\", auto)\n        show ?thesis \n        proof (cases \"Suc jj < length (?l ii)\")\n          case True\n          with nn Suc have \"?g n = (ii, Suc jj)\" by auto\n          with n True show ?thesis by simp\n        next\n          case False \n          with nn Suc have \"?g n = (Suc ii, 0)\" by auto\n          with n show ?thesis by simp\n        qed\n      qed\n    qed      \n    have gsteps: \"\\<And> i. (g i, g (Suc i)) \\<in> R \\<union> S\"\n    proof -\n      fix n\n      obtain i j where n: \"?g n = (i, j)\" by (cases \"?g n\", auto)\n      show \"(g n, g (Suc n)) \\<in> R \\<union> S\"\n      proof (cases \"Suc j < length (?l i)\")\n        case True\n        with n have \"?g (Suc n) = (i, Suc j)\" by auto\n        with n have gn: \"g n = ?l i ! j\" and gsn: \"g (Suc n) = ?l i ! (Suc j)\" unfolding g by auto\n        thus ?thesis using steps[of i] True by auto\n      next\n        case False\n        with n have \"?g (Suc n) = (Suc i, 0)\" by auto\n        with n have gn: \"g n = ?l i ! j\" and gsn: \"g (Suc n) = a (Suc i)\" unfolding g by auto\n        from gn len[OF n] False have \"j = length (?l i) - 1\" by auto\n        with gn have gn: \"g n = last (?l i)\" using last_conv_nth[of \"?l i\"] by auto\n        from gn gsn show ?thesis using steps[of i] steps[of \"Suc i\"] by auto\n      qed\n    qed\n    have infR:  \"INFM j. (g j, g (Suc j)) \\<in> R\" unfolding INFM_nat_le\n    proof\n      fix n\n      obtain i j where n: \"?g n = (i,j)\" by (cases \"?g n\", auto)\n      from len[OF n] have j: \"j < ?l' i\" .\n      let ?k = \"?l' i - 1 - j\"\n      obtain k where k: \"k = j + ?k\" by auto\n      from j k have k2: \"k = ?l' i - 1\" and k3: \"j + ?k < ?l' i\" by auto\n      from inf_concat_simple_add[OF n, of ?k, OF k3] \n      have gnk: \"?g (n + ?k) = (i, k)\" by (simp only: k)\n      hence \"g (n + ?k) = ?l i ! k\" unfolding g by auto\n      hence gnk2: \"g (n + ?k) = last (?l i)\" using last_conv_nth[of \"?l i\"] k2 by auto\n      from k2 gnk have \"?g (Suc (n+?k)) = (Suc i, 0)\" by auto\n      hence gnsk2: \"g (Suc (n+?k)) = a (Suc i)\" unfolding g by auto\n      from steps[of i] steps[of \"Suc i\"] have main: \"(g (n+?k), g (Suc (n+?k))) \\<in> R\" \n        by (simp only: gnk2 gnsk2)\n      show \"\\<exists> j \\<ge> n. (g j, g (Suc j)) \\<in> R\" \n        by (rule exI[of _ \"n + ?k\"], auto simp: main[simplified])\n    qed\n    from SN[unfolded SN_rel_on_alt_def] gsteps infR show False by blast\n  qed\nqed\n\nlemma SN_rel_alt_r_empty : \"SN_rel_alt {} S\"\n  unfolding SN_rel_defs by auto\n\nlemma SN_rel_alt_s_empty : \"SN_rel_alt R {} = SN R\"\n  unfolding SN_rel_defs SN_defs by auto\n\nlemma SN_rel_mono':\n  \"R \\<subseteq> R' \\<Longrightarrow> S \\<subseteq> R' \\<union> S' \\<Longrightarrow> SN_rel R' S' \\<Longrightarrow> SN_rel R S\"\n  unfolding SN_rel_on_conv SN_rel_defs INFM_nat_le by fast\n\nlemma SN_rel_mono:\n  assumes R: \"R \\<subseteq> R'\" and S: \"S \\<subseteq> S'\" and SN: \"SN_rel R' S'\"\n  shows \"SN_rel R S\"\n  using SN unfolding SN_rel_defs using SN_subset[OF _ relto_mono[OF R S]] by blast\n\nlemmas SN_rel_alt_mono = SN_rel_mono[unfolded SN_rel_on_conv]\n\nlemma SN_rel_imp_SN : assumes \"SN_rel R S\" shows  \"SN R\"\nproof\n  fix f\n  assume \"\\<forall> i. (f i, f (Suc i)) \\<in> R\"\n  hence \"\\<And> i. (f i, f (Suc i)) \\<in> relto R S\" by blast  \n  thus False using assms unfolding SN_rel_defs SN_defs by fast\nqed\n\nlemma relto_trancl_conv : \"(relto R S)^+ = ((R \\<union> S))^* O R O ((R \\<union> S))^*\" by regexp\n\nlemma SN_rel_Id:\n  shows \"SN_rel R (S \\<union> Id) = SN_rel R S\"\n  unfolding SN_rel_defs by (simp only: relto_Id)\n\nlemma relto_rtrancl: \"relto R (S^*) = relto R S\" by regexp\n\nlemma SN_rel_empty[simp]: \"SN_rel R {} = SN R\"\n  unfolding SN_rel_defs by auto\n\nlemma SN_rel_ideriv: \"SN_rel R S = (\\<not> (\\<exists> as. ideriv R S as))\" (is \"?L = ?R\")\nproof\n  assume ?L\n  show ?R\n  proof\n    assume \"\\<exists> as. ideriv R S as\"\n    then obtain as where id: \"ideriv R S as\" by auto\n    note id = id[unfolded ideriv_def]\n    from `?L`[unfolded SN_rel_on_conv SN_rel_defs, THEN spec[of _ as]]\n      id obtain i where i: \"\\<And> j. j \\<ge> i \\<Longrightarrow> (as j, as (Suc j)) \\<notin> R\" by auto\n    with id[unfolded INFM_nat, THEN conjunct2, THEN spec[of _ \"Suc i\"]] show False by auto\n  qed\nnext\n  assume ?R\n  show ?L\n    unfolding SN_rel_on_conv SN_rel_defs\n  proof (intro allI impI)\n    fix as\n    presume \"chain (R \\<union> S) as\"\n    with `?R`[unfolded ideriv_def] have \"\\<not> (INFM i. (as i, as (Suc i)) \\<in> R)\" by auto\n    from this[unfolded INFM_nat] obtain i where i: \"\\<And> j. i < j \\<Longrightarrow> (as j, as (Suc j)) \\<notin> R\" by auto\n    show \"\\<not> (INFM j. (as j, as (Suc j)) \\<in> R)\" unfolding INFM_nat using i by blast\n  qed simp\nqed\n\nlemma SN_rel_map:\n  fixes R Rw R' Rw' :: \"'a rel\" \n  defines A: \"A \\<equiv> R' \\<union> Rw'\"\n  assumes SN: \"SN_rel R' Rw'\" \n  and R: \"\\<And>s t. (s,t) \\<in> R \\<Longrightarrow> (f s, f t) \\<in> A^* O R' O A^*\"\n  and Rw: \"\\<And>s t. (s,t) \\<in> Rw \\<Longrightarrow> (f s, f t) \\<in> A^*\"\n  shows \"SN_rel R Rw\"\n  unfolding SN_rel_defs\nproof\n  fix g\n  assume steps: \"chain (relto R Rw) g\"\n  let ?f = \"\\<lambda>i. (f (g i))\"\n  obtain h where h: \"h = ?f\" by auto\n  {\n    fix i\n    let ?m = \"\\<lambda> (x,y). (f x, f y)\"\n    {\n      fix s t\n      assume \"(s,t) \\<in> Rw^*\"\n      hence \"?m (s,t) \\<in> A^*\"\n      proof (induct)\n        case base show ?case by simp\n      next\n        case (step t u)\n        from Rw[OF step(2)] step(3)\n        show ?case by auto\n      qed\n    } note Rw = this\n    from steps have \"(g i, g (Suc i)) \\<in> relto R Rw\" ..\n    from this\n    obtain s t where gs: \"(g i,s) \\<in> Rw^*\" and st: \"(s,t) \\<in> R\" and tg: \"(t, g (Suc i)) \\<in> Rw^*\" by auto\n    from Rw[OF gs] R[OF st] Rw[OF tg]\n    have step: \"(?f i, ?f (Suc i)) \\<in> A^* O (A^* O R' O A^*) O A^*\"\n      by auto\n    have \"(?f i, ?f (Suc i)) \\<in> A^* O R' O A^*\"\n      by (rule set_mp[OF _ step], regexp)\n    hence \"(h i, h (Suc i)) \\<in> (relto R' Rw')^+\"\n      unfolding A h relto_trancl_conv .\n  }\n  hence \"\\<not> SN ((relto R' Rw')^+)\" by auto\n  with SN_imp_SN_trancl[OF SN[unfolded SN_rel_on_def]]\n  show False by simp\nqed\n\ndatatype SN_rel_ext_type = top_s | top_ns | normal_s | normal_ns\n\nfun SN_rel_ext_step :: \"'a rel \\<Rightarrow> 'a rel \\<Rightarrow> 'a rel \\<Rightarrow> 'a rel \\<Rightarrow> SN_rel_ext_type \\<Rightarrow> 'a rel\" where\n  \"SN_rel_ext_step P Pw R Rw top_s = P\"\n| \"SN_rel_ext_step P Pw R Rw top_ns = Pw\"\n| \"SN_rel_ext_step P Pw R Rw normal_s = R\"\n| \"SN_rel_ext_step P Pw R Rw normal_ns = Rw\"\n\n(* relative termination with four relations as required in DP-framework *)\ndefinition SN_rel_ext :: \"'a rel \\<Rightarrow> 'a rel \\<Rightarrow> 'a rel \\<Rightarrow> 'a rel \\<Rightarrow> ('a \\<Rightarrow> bool) \\<Rightarrow> bool\" where\n  \"SN_rel_ext P Pw R Rw M \\<equiv> (\\<not> (\\<exists>f t. \n    (\\<forall> i. (f i, f (Suc i)) \\<in> SN_rel_ext_step P Pw R Rw (t i))\n    \\<and> (\\<forall> i. M (f i))\n    \\<and> (INFM i. t i \\<in> {top_s,top_ns})\n    \\<and> (INFM i. t i \\<in> {top_s,normal_s})))\"\n\nlemma SN_rel_ext_trans:\n  fixes P Pw R Rw :: \"'a rel\" and M :: \"'a \\<Rightarrow> bool\"\n  defines M': \"M' \\<equiv> {(s,t). M t}\"\n  defines A: \"A \\<equiv> (P \\<union> Pw \\<union> R \\<union> Rw) \\<inter> M'\"\n  assumes \"SN_rel_ext P Pw R Rw M\" \n  shows \"SN_rel_ext (A^* O (P \\<inter> M') O A^*) (A^* O ((P \\<union> Pw) \\<inter> M') O A^*) (A^* O ((P \\<union> R) \\<inter> M') O A^*) (A^*) M\" (is \"SN_rel_ext ?P ?Pw ?R ?Rw M\")\nproof (rule ccontr)\n  let ?relt = \"SN_rel_ext_step ?P ?Pw ?R ?Rw\"\n  let ?rel = \"SN_rel_ext_step P Pw R Rw\" \n  assume \"\\<not> ?thesis\"\n  from this[unfolded SN_rel_ext_def]\n  obtain f ty\n    where steps: \"\\<And> i. (f i, f (Suc i)) \\<in> ?relt (ty i)\" \n    and min: \"\\<And> i. M (f i)\"\n    and inf1: \"INFM i. ty i \\<in> {top_s, top_ns}\"\n    and inf2: \"INFM i. ty i \\<in> {top_s, normal_s}\"\n    by auto\n  let ?Un = \"\\<lambda> tt. \\<Union> (?rel ` tt)\"\n  let ?UnM = \"\\<lambda> tt. (\\<Union> (?rel ` tt)) \\<inter> M'\"\n  let ?A = \"?UnM {top_s,top_ns,normal_s,normal_ns}\"\n  let ?P' = \"?UnM {top_s}\"\n  let ?Pw' = \"?UnM {top_s,top_ns}\"\n  let ?R' = \"?UnM {top_s,normal_s}\"\n  let ?Rw' = \"?UnM {top_s,top_ns,normal_s,normal_ns}\"\n  have A: \"A = ?A\" unfolding A by auto\n  have P: \"(P \\<inter> M') = ?P'\" by auto\n  have Pw: \"(P \\<union> Pw) \\<inter> M' = ?Pw'\" by auto\n  have R: \"(P \\<union> R) \\<inter> M' = ?R'\" by auto\n  have Rw: \"A = ?Rw'\" unfolding A ..\n  {\n    fix s t tt\n    assume m: \"M s\" and st: \"(s,t) \\<in> ?UnM tt\"\n    hence \"\\<exists> typ \\<in> tt. (s,t) \\<in> ?rel typ \\<and> M s \\<and> M t\" unfolding M' by auto\n  } note one_step = this\n  let ?seq = \"\\<lambda> s t g n ty. s = g 0 \\<and> t = g n \\<and> (\\<forall> i < n. (g i, g (Suc i)) \\<in> ?rel (ty i)) \\<and> (\\<forall> i \\<le> n. M (g i))\"\n  {\n    fix s t\n    assume m: \"M s\" and st: \"(s,t) \\<in> A^*\"\n    from st[unfolded rtrancl_fun_conv]\n    obtain g n where g0: \"g 0 = s\" and gn: \"g n = t\" and steps: \"\\<And> i. i < n \\<Longrightarrow> (g i, g (Suc i)) \\<in> ?A\" unfolding A by auto\n    {\n      fix i\n      assume \"i \\<le> n\"\n      have \"M (g i)\"\n      proof (cases i)\n        case 0\n        show ?thesis unfolding 0 g0 by (rule m)\n      next\n        case (Suc j)\n        with `i \\<le> n` have \"j < n\" by auto\n        from steps[OF this] show ?thesis unfolding Suc M' by auto\n      qed\n    } note min = this\n    {\n      fix i\n      assume i: \"i < n\" hence i': \"i \\<le> n\" by auto\n      from i' one_step[OF min steps[OF i]]\n      have \"\\<exists> ty. (g i, g (Suc i)) \\<in> ?rel ty\" by blast\n    }\n    hence \"\\<forall> i. (\\<exists> ty. i < n \\<longrightarrow> (g i, g (Suc i)) \\<in> ?rel ty)\" by auto\n    from choice[OF this]\n    obtain tt where steps: \"\\<And> i. i < n \\<Longrightarrow> (g i, g (Suc i)) \\<in> ?rel (tt i)\" by auto\n    from g0 gn steps min\n    have \"?seq s t g n tt\" by auto\n    hence \"\\<exists> g n tt. ?seq s t g n tt\" by blast\n  } note A_steps = this\n  let ?seqtt = \"\\<lambda> s t tt g n ty. s = g 0 \\<and> t = g n \\<and> n > 0 \\<and> (\\<forall> i<n. (g i, g (Suc i)) \\<in> ?rel (ty i)) \\<and> (\\<forall> i \\<le> n. M (g i)) \\<and> (\\<exists> i < n. ty i \\<in> tt)\"\n  {\n    fix s t tt\n    assume m: \"M s\" and st: \"(s,t) \\<in> A^* O ?UnM tt O A^*\"\n    then obtain u v where su: \"(s,u) \\<in> A^*\" and uv: \"(u,v) \\<in> ?UnM tt\" and vt: \"(v,t) \\<in> A^*\"\n      by auto\n    from A_steps[OF m su] obtain g1 n1 ty1 where seq1: \"?seq s u g1 n1 ty1\" by auto\n    from uv have \"M v\" unfolding M' by auto\n    from A_steps[OF this vt] obtain g2 n2 ty2 where seq2: \"?seq v t g2 n2 ty2\" by auto\n    from seq1 have \"M u\" by auto\n    from one_step[OF this uv] obtain ty where ty: \"ty \\<in> tt\" and uv: \"(u,v) \\<in> ?rel ty\" by auto\n    let ?g = \"\\<lambda> i. if i \\<le> n1 then g1 i else g2 (i - (Suc n1))\"\n    let ?ty = \"\\<lambda> i. if i < n1 then ty1 i else if i = n1 then ty else ty2 (i - (Suc n1))\"\n    let ?n = \"Suc (n1 + n2)\"\n    have ex: \"\\<exists> i < ?n. ?ty i \\<in> tt\"\n      by (rule exI[of _ n1], simp add: ty)\n    have steps: \"\\<forall> i < ?n. (?g i, ?g (Suc i)) \\<in> ?rel (?ty i)\"\n    proof (intro allI impI)\n      fix i\n      assume \"i < ?n\"\n      show \"(?g i, ?g (Suc i)) \\<in> ?rel (?ty i)\"\n      proof (cases \"i \\<le> n1\")\n        case True\n        with seq1 seq2 uv show ?thesis by auto\n      next\n        case False\n        hence \"i = Suc n1 + (i - Suc n1)\" by auto\n        then obtain k where i: \"i = Suc n1 + k\" by auto\n        with `i < ?n` have \"k < n2\" by auto\n        thus ?thesis using seq2 unfolding i by auto\n      qed\n    qed\n    from steps seq1 seq2 ex \n    have seq: \"?seqtt s t tt ?g ?n ?ty\" by auto\n    have \"\\<exists> g n ty. ?seqtt s t tt g n ty\" \n      by (intro exI, rule seq)\n  } note A_tt_A = this\n  let ?tycon = \"\\<lambda> ty1 ty2 tt ty' n. ty1 = ty2 \\<longrightarrow> (\\<exists>i < n. ty' i \\<in> tt)\"\n  let ?seqt = \"\\<lambda> i ty g n ty'. f i = g 0 \\<and> f (Suc i) = g n \\<and> (\\<forall> j < n. (g j, g (Suc j)) \\<in> ?rel (ty' j)) \\<and> (\\<forall> j \\<le> n. M (g j)) \n                \\<and> (?tycon (ty i) top_s {top_s} ty' n)\n                \\<and> (?tycon (ty i) top_ns {top_s,top_ns} ty' n)\n                \\<and> (?tycon (ty i) normal_s {top_s,normal_s} ty' n)\"\n  {\n    fix i\n    have \"\\<exists> g n ty'. ?seqt i ty g n ty'\"\n    proof (cases \"ty i\")\n      case top_s\n      from steps[of i, unfolded top_s] \n      have \"(f i, f (Suc i)) \\<in> ?P\" by auto\n      from A_tt_A[OF min this[unfolded P]]\n      show ?thesis unfolding top_s by auto\n    next\n      case top_ns\n      from steps[of i, unfolded top_ns] \n      have \"(f i, f (Suc i)) \\<in> ?Pw\" by auto\n      from A_tt_A[OF min this[unfolded Pw]]\n      show ?thesis unfolding top_ns by auto\n    next\n      case normal_s\n      from steps[of i, unfolded normal_s] \n      have \"(f i, f (Suc i)) \\<in> ?R\" by auto\n      from A_tt_A[OF min this[unfolded R]]\n      show ?thesis unfolding normal_s by auto\n    next\n      case normal_ns\n      from steps[of i, unfolded normal_ns] \n      have \"(f i, f (Suc i)) \\<in> ?Rw\" by auto\n      from A_steps[OF min this]\n      show ?thesis unfolding normal_ns by auto\n    qed\n  }\n  hence \"\\<forall> i. \\<exists> g n ty'. ?seqt i ty g n ty'\" by auto\n  from choice[OF this] obtain g where \"\\<forall> i. \\<exists> n ty'. ?seqt i ty (g i) n ty'\" by auto\n  from choice[OF this] obtain n where \"\\<forall> i. \\<exists> ty'. ?seqt i ty (g i) (n i) ty'\" by auto\n  from choice[OF this] obtain ty' where \"\\<forall> i. ?seqt i ty (g i) (n i) (ty' i)\" by auto\n  hence partial: \"\\<And> i. ?seqt i ty (g i) (n i) (ty' i)\" ..\n  (* it remains to concatenate all these finite sequences to an infinite one *)\n  let ?ind = \"inf_concat n\"\n  let ?g = \"\\<lambda> k. (\\<lambda> (i,j). g i j) (?ind k)\"\n  let ?ty = \"\\<lambda> k. (\\<lambda> (i,j). ty' i j) (?ind k)\"\n  have inf: \"INFM i. 0 < n i\"\n    unfolding INFM_nat_le\n  proof (intro allI)\n    fix m\n    from inf1[unfolded INFM_nat_le]\n    obtain k where k: \"k \\<ge> m\" and ty: \"ty k \\<in> {top_s, top_ns}\" by auto\n    show \"\\<exists> k \\<ge> m. 0 < n k\"\n    proof (intro exI conjI, rule k)\n      from partial[of k] ty show \"0 < n k\" by (cases \"n k\", auto)\n    qed\n  qed\n  note bounds = inf_concat_bounds[OF inf]\n  note inf_Suc = inf_concat_Suc[OF inf]\n  note inf_mono = inf_concat_mono[OF inf]\n  have \"\\<not> SN_rel_ext P Pw R Rw M\"\n    unfolding SN_rel_ext_def simp_thms\n  proof (rule exI[of _ ?g], rule exI[of _ ?ty], intro conjI allI)\n    fix k\n    obtain i j where ik: \"?ind k = (i,j)\" by force\n    from bounds[OF this] have j: \"j < n i\" by auto\n    show \"M (?g k)\" unfolding ik using partial[of i] j by auto\n  next\n    fix k\n    obtain i j where ik: \"?ind k = (i,j)\" by force\n    from bounds[OF this] have j: \"j < n i\" by auto\n    from partial[of i] j have step: \"(g i j, g i (Suc j)) \\<in> ?rel (ty' i j)\" by auto\n    obtain i' j' where isk: \"?ind (Suc k) = (i',j')\" by force\n    have i'j': \"g i' j' = g i (Suc j)\"\n    proof (rule inf_Suc[OF _ ik isk])\n      fix i\n      from partial[of i]\n      have \"g i (n i) = f (Suc i)\" by simp\n      also have \"... = g (Suc i) 0\" using partial[of \"Suc i\"] by simp\n      finally show \"g i (n i) = g (Suc i) 0\" .\n    qed\n    show \"(?g k, ?g (Suc k)) \\<in> ?rel (?ty k)\"\n      unfolding ik isk split i'j'\n      by (rule step)\n  next\n    show \"INFM i. ?ty i \\<in> {top_s, top_ns}\"\n      unfolding INFM_nat_le\n    proof (intro allI)\n      fix k\n      obtain i j where ik: \"?ind k = (i,j)\" by force      \n      from inf1[unfolded INFM_nat] obtain i' where i': \"i' > i\" and ty: \"ty i' \\<in> {top_s, top_ns}\" by auto\n      from partial[of i'] ty obtain j' where j': \"j' < n i'\" and ty': \"ty' i' j' \\<in> {top_s, top_ns}\" by auto      \n      from inf_concat_surj[of _ n, OF j'] obtain k' where ik': \"?ind k' = (i',j')\" ..        \n      from inf_mono[OF ik ik' i'] have k: \"k \\<le> k'\" by simp\n      show \"\\<exists> k' \\<ge> k. ?ty k' \\<in> {top_s, top_ns}\"\n        by (intro exI conjI, rule k, unfold ik' split, rule ty')\n    qed\n  next\n    show \"INFM i. ?ty i \\<in> {top_s, normal_s}\"\n      unfolding INFM_nat_le\n    proof (intro allI)\n      fix k\n      obtain i j where ik: \"?ind k = (i,j)\" by force      \n      from inf2[unfolded INFM_nat] obtain i' where i': \"i' > i\" and ty: \"ty i' \\<in> {top_s, normal_s}\" by auto\n      from partial[of i'] ty obtain j' where j': \"j' < n i'\" and ty': \"ty' i' j' \\<in> {top_s, normal_s}\" by auto\n      from inf_concat_surj[of _ n, OF j'] obtain k' where ik': \"?ind k' = (i',j')\" ..\n      from inf_mono[OF ik ik' i'] have k: \"k \\<le> k'\" by simp\n      show \"\\<exists> k' \\<ge> k. ?ty k' \\<in> {top_s, normal_s}\"\n        by (intro exI conjI, rule k, unfold ik' split, rule ty')\n    qed\n  qed\n  with assms show False by auto\nqed\n\n\nlemma SN_rel_ext_map: fixes P Pw R Rw P' Pw' R' Rw' :: \"'a rel\" and M M' :: \"'a \\<Rightarrow> bool\"\n  defines Ms: \"Ms \\<equiv> {(s,t). M' t}\"\n  defines A: \"A \\<equiv> (P' \\<union> Pw' \\<union> R' \\<union> Rw') \\<inter> Ms\"\n  assumes SN: \"SN_rel_ext P' Pw' R' Rw' M'\" \n  and P: \"\\<And> s t. M s \\<Longrightarrow> M t \\<Longrightarrow> (s,t) \\<in> P \\<Longrightarrow> (f s, f t) \\<in> (A^* O (P' \\<inter> Ms) O A^*) \\<and> I t\"\n  and Pw: \"\\<And> s t. M s \\<Longrightarrow> M t \\<Longrightarrow> (s,t) \\<in> Pw \\<Longrightarrow> (f s, f t) \\<in> (A^* O ((P' \\<union> Pw') \\<inter> Ms) O A^*) \\<and> I t\"\n  and R: \"\\<And> s t. I s \\<Longrightarrow> M s \\<Longrightarrow> M t \\<Longrightarrow> (s,t) \\<in> R \\<Longrightarrow> (f s, f t) \\<in> (A^* O ((P' \\<union> R') \\<inter> Ms) O A^*) \\<and> I t\"\n  and Rw: \"\\<And> s t. I s \\<Longrightarrow> M s \\<Longrightarrow> M t \\<Longrightarrow> (s,t) \\<in> Rw \\<Longrightarrow> (f s, f t) \\<in> A^* \\<and> I t\"\n  shows \"SN_rel_ext P Pw R Rw M\" \nproof -\n  note SN = SN_rel_ext_trans[OF SN]\n  let ?P = \"(A^* O (P' \\<inter> Ms) O A^*)\"\n  let ?Pw = \"(A^* O ((P' \\<union> Pw') \\<inter> Ms) O A^*)\"\n  let ?R = \"(A^* O ((P' \\<union> R') \\<inter> Ms) O A^*)\"\n  let ?Rw = \"A^*\"\n  let ?relt = \"SN_rel_ext_step ?P ?Pw ?R ?Rw\"\n  let ?rel = \"SN_rel_ext_step P Pw R Rw\" \n  show ?thesis \n  proof (rule ccontr)\n    assume \"\\<not> ?thesis\"\n    from this[unfolded SN_rel_ext_def]\n    obtain g ty\n      where steps: \"\\<And> i. (g i, g (Suc i)) \\<in> ?rel (ty i)\" \n      and min: \"\\<And> i. M (g i)\"\n      and inf1: \"INFM i. ty i \\<in> {top_s, top_ns}\"\n      and inf2: \"INFM i. ty i \\<in> {top_s, normal_s}\"\n      by auto\n    from inf1[unfolded INFM_nat] obtain k where k: \"ty k \\<in> {top_s, top_ns}\" by auto\n    let ?k = \"Suc k\"\n    let ?i = \"shift id ?k\"\n    let ?f = \"\\<lambda> i. f (shift g ?k i)\"\n    let ?ty = \"shift ty ?k\"\n    {\n      fix i\n      assume ty: \"ty i \\<in> {top_s,top_ns}\"\n      note m = min[of i] \n      note ms = min[of \"Suc i\"]\n      from P[OF m ms]\n        Pw[OF m ms]\n        steps[of i]\n        ty\n      have \"(f (g i), f (g (Suc i))) \\<in> ?relt (ty i) \\<and> I (g (Suc i))\"\n        by (cases \"ty i\", auto)\n    } note stepsP = this\n    {\n      fix i\n      assume I: \"I (g i)\"\n      note m = min[of i] \n      note ms = min[of \"Suc i\"]\n      from P[OF m ms]\n        Pw[OF m ms]\n        R[OF I m ms]\n        Rw[OF I m ms]\n        steps[of i]\n      have \"(f (g i), f (g (Suc i))) \\<in> ?relt (ty i) \\<and> I (g (Suc i))\"\n        by (cases \"ty i\", auto)\n    } note stepsI = this\n    {\n      fix i\n      have \"I (g (?i i))\"\n      proof (induct i)\n        case 0\n        show ?case using stepsP[OF k] by simp\n      next\n        case (Suc i)\n        from stepsI[OF Suc] show ?case by simp\n      qed\n    } note I = this\n    have \"\\<not> SN_rel_ext ?P ?Pw ?R ?Rw M'\"\n      unfolding SN_rel_ext_def simp_thms\n    proof (rule exI[of _ ?f], rule exI[of _ ?ty], intro allI conjI)\n      fix i\n      show \"(?f i, ?f (Suc i)) \\<in> ?relt (?ty i)\"\n        using stepsI[OF I[of i]] by auto\n    next\n      show \"INFM i. ?ty i \\<in> {top_s, top_ns}\"\n        unfolding Infm_shift[of \"\\<lambda>i. i \\<in> {top_s,top_ns}\" ty ?k]\n        by (rule inf1)\n    next\n      show \"INFM i. ?ty i \\<in> {top_s, normal_s}\"\n        unfolding Infm_shift[of \"\\<lambda>i. i \\<in> {top_s,normal_s}\" ty ?k]\n        by (rule inf2)\n    next\n      fix i\n      have A: \"A \\<subseteq> Ms\" unfolding A by auto\n      from rtrancl_mono[OF this] have As: \"A^* \\<subseteq> Ms^*\" by auto\n      have PM: \"?P \\<subseteq> Ms^* O Ms O Ms^*\" using As by auto\n      have PwM: \"?Pw \\<subseteq> Ms^* O Ms O Ms^*\" using As by auto\n      have RM: \"?R \\<subseteq> Ms^* O Ms O Ms^*\" using As by auto\n      have RwM: \"?Rw \\<subseteq> Ms^*\" using As by auto\n      from PM PwM RM have \"?P \\<union> ?Pw \\<union> ?R \\<subseteq> Ms^* O Ms O Ms^*\" (is \"?PPR \\<subseteq> _\") by auto\n      also have \"... \\<subseteq> Ms^+\" by regexp\n      also have \"... = Ms\"\n      proof\n        have \"Ms^+ \\<subseteq> Ms^* O Ms\" by regexp\n        also have \"... \\<subseteq> Ms\" unfolding Ms by auto\n        finally show \"Ms^+ \\<subseteq> Ms\" .\n      qed regexp\n      finally have PPR: \"?PPR \\<subseteq> Ms\" .\n      show \"M' (?f i)\"\n      proof (induct i)\n        case 0\n        from stepsP[OF k] k\n        have \"(f (g k), f (g (Suc k))) \\<in> ?PPR\" by (cases \"ty k\", auto)\n        with PPR show ?case unfolding Ms by simp blast\n      next\n        case (Suc i)\n        show ?case\n        proof (cases \"?ty i = normal_ns\")\n          case False\n          hence \"?ty i \\<in> {top_s,top_ns,normal_s}\"\n            by (cases \"?ty i\", auto)\n          with stepsI[OF I[of i]] have \"(?f i, ?f (Suc i)) \\<in> ?PPR\"\n            by auto\n          from set_mp[OF PPR this] have \"(?f i, ?f (Suc i)) \\<in> Ms\" .\n          thus ?thesis unfolding Ms by auto\n        next\n          case True\n          with stepsI[OF I[of i]] have \"(?f i, ?f (Suc i)) \\<in> ?Rw\" by auto\n          with RwM have mem: \"(?f i, ?f (Suc i)) \\<in> Ms^*\" by auto\n          thus ?thesis\n          proof (cases)\n            case base\n            with Suc show ?thesis by simp\n          next\n            case step\n            thus ?thesis unfolding Ms by simp\n          qed\n        qed\n      qed\n    qed\n    with SN\n    show False unfolding A Ms by simp\n  qed\nqed\n\n(* and a version where it is assumed that f always preserves M and that R' and Rw' preserve M' *)\nlemma SN_rel_ext_map_min: fixes P Pw R Rw P' Pw' R' Rw' :: \"'a rel\" and M M' :: \"'a \\<Rightarrow> bool\"\n  defines Ms: \"Ms \\<equiv> {(s,t). M' t}\"\n  defines A: \"A \\<equiv> P' \\<inter> Ms \\<union> Pw' \\<inter> Ms \\<union> R' \\<union> Rw'\"\n  assumes SN: \"SN_rel_ext P' Pw' R' Rw' M'\" \n  and M: \"\\<And> t. M t \\<Longrightarrow> M' (f t)\"\n  and M': \"\\<And> s t. M' s \\<Longrightarrow> (s,t) \\<in> R' \\<union> Rw' \\<Longrightarrow> M' t\"\n  and P: \"\\<And> s t. M s \\<Longrightarrow> M t \\<Longrightarrow> M' (f s) \\<Longrightarrow> M' (f t) \\<Longrightarrow> (s,t) \\<in> P \\<Longrightarrow> (f s, f t) \\<in> (A^* O (P' \\<inter> Ms) O A^*) \\<and> I t\"\n  and Pw: \"\\<And> s t. M s \\<Longrightarrow> M t \\<Longrightarrow> M' (f s) \\<Longrightarrow> M' (f t) \\<Longrightarrow> (s,t) \\<in> Pw \\<Longrightarrow> (f s, f t) \\<in> (A^* O (P' \\<inter> Ms \\<union> Pw' \\<inter> Ms) O A^*) \\<and> I t\"\n  and R: \"\\<And> s t. I s \\<Longrightarrow> M s \\<Longrightarrow> M t \\<Longrightarrow> M' (f s) \\<Longrightarrow> M' (f t) \\<Longrightarrow> (s,t) \\<in> R \\<Longrightarrow> (f s, f t) \\<in> (A^* O (P' \\<inter> Ms \\<union> R') O A^*) \\<and> I t\"\n  and Rw: \"\\<And> s t. I s \\<Longrightarrow> M s \\<Longrightarrow> M t \\<Longrightarrow> M' (f s) \\<Longrightarrow> M' (f t) \\<Longrightarrow> (s,t) \\<in> Rw \\<Longrightarrow> (f s, f t) \\<in> A^* \\<and> I t\"\n  shows \"SN_rel_ext P Pw R Rw M\"  \nproof -\n  let ?Ms = \"{(s,t). M' t}\"\n  let ?A = \"(P' \\<union> Pw' \\<union> R' \\<union> Rw') \\<inter> ?Ms\"\n  {\n    fix s t\n    assume s: \"M' s\" and \"(s,t) \\<in> A\" \n    with M'[OF s, of t] have \"(s,t) \\<in> ?A \\<and> M' t\" unfolding Ms A by auto\n  } note Aone = this\n  {\n    fix s t\n    assume s: \"M' s\" and steps: \"(s,t) \\<in> A^*\"\n    from steps have \"(s,t) \\<in> ?A^* \\<and> M' t\"\n    proof (induct)\n      case base from s show ?case by simp\n    next\n      case (step t u)\n      note one = Aone[OF step(3)[THEN conjunct2] step(2)] \n      from step(3) one\n      have steps: \"(s,u) \\<in> ?A^* O ?A\" by blast      \n      have \"(s,u) \\<in> ?A^*\" \n        by (rule set_mp[OF _ steps], regexp)\n      with one show ?case by simp\n    qed\n  } note Amany = this      \n  let ?P = \"(A^* O (P' \\<inter> Ms) O A^*)\"\n  let ?Pw = \"(A^* O (P' \\<inter> Ms \\<union> Pw' \\<inter> Ms) O A^*)\"\n  let ?R = \"(A^* O (P' \\<inter> Ms \\<union> R') O A^*)\"\n  let ?Rw = \"A^*\"\n  let ?P' = \"(?A^* O (P' \\<inter> ?Ms) O ?A^*)\"\n  let ?Pw' = \"(?A^* O ((P' \\<union> Pw') \\<inter> ?Ms) O ?A^*)\"\n  let ?R' = \"(?A^* O ((P' \\<union> R') \\<inter> ?Ms) O ?A^*)\"\n  let ?Rw' = \"?A^*\"\n  show ?thesis \n  proof (rule SN_rel_ext_map[OF SN])\n    fix s t\n    assume s: \"M s\" and t: \"M t\" and step: \"(s,t) \\<in> P\"\n    from P[OF s t M[OF s] M[OF t] step]\n    have \"(f s, f t) \\<in> ?P\" and I: \"I t\"  by auto\n    then obtain u v where su: \"(f s, u) \\<in> A^*\" and uv: \"(u,v) \\<in> P' \\<inter> Ms\"\n      and vt: \"(v,f t) \\<in> A^*\" by auto\n    from Amany[OF M[OF s] su] have su: \"(f s, u) \\<in> ?A^*\" and u: \"M' u\" by auto\n    from uv have v: \"M' v\" unfolding Ms by auto\n    from Amany[OF v vt] have vt: \"(v, f t) \\<in> ?A^*\" by auto\n    from su uv vt I \n    show \"(f s, f t) \\<in> ?P' \\<and> I t\" unfolding Ms by auto\n  next\n    fix s t\n    assume s: \"M s\" and t: \"M t\" and step: \"(s,t) \\<in> Pw\"\n    from Pw[OF s t M[OF s] M[OF t] step]\n    have \"(f s, f t) \\<in> ?Pw\" and I: \"I t\"  by auto\n    then obtain u v where su: \"(f s, u) \\<in> A^*\" and uv: \"(u,v) \\<in> P' \\<inter> Ms \\<union> Pw' \\<inter> Ms\"\n      and vt: \"(v,f t) \\<in> A^*\" by auto\n    from Amany[OF M[OF s] su] have su: \"(f s, u) \\<in> ?A^*\" and u: \"M' u\" by auto\n    from uv have uv: \"(u,v) \\<in> (P' \\<union> Pw') \\<inter> ?Ms\" and v: \"M' v\" unfolding Ms \n      by auto\n    from Amany[OF v vt] have vt: \"(v, f t) \\<in> ?A^*\" by auto\n    from su uv vt I \n    show \"(f s, f t) \\<in> ?Pw' \\<and> I t\"  by auto\n  next\n    fix s t\n    assume I: \"I s\" and s: \"M s\" and t: \"M t\" and step: \"(s,t) \\<in> R\"\n    from R[OF I s t M[OF s] M[OF t] step]\n    have \"(f s, f t) \\<in> ?R\" and I: \"I t\"  by auto\n    then obtain u v where su: \"(f s, u) \\<in> A^*\" and uv: \"(u,v) \\<in> P' \\<inter> Ms \\<union> R'\"\n      and vt: \"(v,f t) \\<in> A^*\" by auto\n    from Amany[OF M[OF s] su] have su: \"(f s, u) \\<in> ?A^*\" and u: \"M' u\" by auto\n    from uv M'[OF u, of v] have uv: \"(u,v) \\<in> (P' \\<union> R') \\<inter> ?Ms\" and v: \"M' v\" unfolding Ms \n      by auto\n    from Amany[OF v vt] have vt: \"(v, f t) \\<in> ?A^*\" by auto\n    from su uv vt I \n    show \"(f s, f t) \\<in> ?R' \\<and> I t\"  by auto\n  next\n    fix s t\n    assume I: \"I s\" and s: \"M s\" and t: \"M t\" and step: \"(s,t) \\<in> Rw\"\n    from Rw[OF I s t M[OF s] M[OF t] step]\n    have steps: \"(f s, f t) \\<in> ?Rw\" and I: \"I t\"  by auto\n    from Amany[OF M[OF s] steps] I\n    show \"(f s, f t) \\<in> ?Rw' \\<and> I t\"  by auto\n  qed\nqed\n\n(*OLD PART*)\nlemma SN_relto_imp_SN_rel: \"SN (relto R S) \\<Longrightarrow> SN_rel R S\"\nproof -\n  assume SN: \"SN (relto R S)\"\n  show ?thesis\n  proof (simp only: SN_rel_on_conv SN_rel_defs, intro allI impI)\n    fix f\n    presume steps: \"chain (R \\<union> S) f\"\n    obtain r where  r: \"\\<And> j. r j \\<equiv>  (f j, f (Suc j)) \\<in> R\" by auto\n    show \"\\<not> (INFM j. (f j, f (Suc j)) \\<in> R)\"\n    proof (rule ccontr)\n      assume \"\\<not> ?thesis\"\n      hence ih: \"infinitely_many r\" unfolding infinitely_many_def r INFM_nat_le by blast\n      obtain r_index where \"r_index = infinitely_many.index r\" by simp\n      with infinitely_many.index_p[OF ih] infinitely_many.index_ordered[OF ih] infinitely_many.index_not_p_between[OF ih] \n      have r_index: \"\\<And> i. r (r_index i) \\<and> r_index i < r_index (Suc i) \\<and> (\\<forall> j. r_index i < j \\<and> j < r_index (Suc i) \\<longrightarrow> \\<not> r j)\" by auto\n      obtain g where g: \"\\<And> i. g i \\<equiv> f (r_index i)\" ..\n      {\n        fix i\n        let ?ri = \"r_index i\"\n        let ?rsi = \"r_index (Suc i)\"\n        from r_index have isi: \"?ri < ?rsi\" by auto\n        obtain ri rsi where ri: \"ri = ?ri\" and rsi: \"rsi = ?rsi\" by auto\n        with r_index[of i] steps have inter: \"\\<And> j. ri < j \\<and> j < rsi \\<Longrightarrow> (f j, f (Suc j)) \\<in> S\" unfolding r by auto\n        from ri isi rsi have risi: \"ri < rsi\" by simp                      \n        {\n          fix n\n          assume \"Suc n \\<le> rsi - ri\"\n          hence \"(f (Suc ri), f (Suc (n + ri))) \\<in> S^*\"\n          proof (induct n, simp)\n            case (Suc n)\n            hence stepps: \"(f (Suc ri), f (Suc (n+ri))) \\<in> S^*\" by simp\n            have \"(f (Suc (n+ri)), f (Suc (Suc n + ri))) \\<in> S\"\n              using inter[of \"Suc n + ri\"] Suc(2) by auto\n            with stepps show ?case by simp\n          qed\n        }\n        from this[of \"rsi - ri - 1\"] risi have \n          \"(f (Suc ri), f rsi) \\<in> S^*\" by simp\n        with ri rsi have ssteps: \"(f (Suc ?ri), f ?rsi) \\<in> S^*\" by simp\n        with r_index[of i] have \"(f ?ri, f ?rsi) \\<in> R O S^*\" unfolding r by auto\n        hence \"(g i, g (Suc i)) \\<in> S^* O R O S^*\" using rtrancl_refl unfolding g by auto           \n      } \n      hence \"\\<not> SN (S^* O R O S^*)\" unfolding SN_defs by blast\n      with SN show False by simp\n    qed\n  qed simp\nqed\n\n(*FIXME: move*)\n\n\nfun choice :: \"(nat \\<Rightarrow> 'a list) \\<Rightarrow> nat \\<Rightarrow> (nat \\<times> nat)\" where\n  \"choice f 0 = (0,0)\"\n| \"choice f (Suc n) = (let (i, j) = choice f n in \n    if Suc j < length (f i) \n      then (i, Suc j)\n      else (Suc i, 0))\"\n        \nlemma SN_rel_imp_SN_relto : \"SN_rel R S \\<Longrightarrow> SN (relto R S)\"\nproof -\n  assume SN: \"SN_rel R S\"\n  show \"SN (relto R S)\"\n  proof\n    fix f\n    assume  \"\\<forall> i. (f i, f (Suc i)) \\<in> relto R S\"\n    hence steps: \"\\<And> i. (f i, f (Suc i)) \\<in> S^* O R O S^*\" by auto\n    let ?prop = \"\\<lambda> i ai bi. (f i, bi) \\<in> S^* \\<and> (bi, ai) \\<in> R \\<and> (ai, f (Suc (i))) \\<in> S^*\"\n    {\n      fix i\n      from steps obtain bi ai where \"?prop i ai bi\" by blast\n      hence \"\\<exists> ai bi. ?prop i ai bi\" by blast\n    }\n    hence \"\\<forall> i. \\<exists> bi ai. ?prop i ai bi\" by blast\n    from choice[OF this] obtain b where \"\\<forall> i. \\<exists> ai. ?prop i ai (b i)\" by blast\n    from choice[OF this] obtain a where steps: \"\\<And> i. ?prop i (a i) (b i)\" by blast\n    let ?prop = \"\\<lambda> i li. (b i, a i) \\<in> R \\<and> (\\<forall> j < length li. ((a i # li) ! j, (a i # li) ! Suc j) \\<in> S) \\<and> last (a i # li) = b (Suc i)\"\n    {\n      fix i\n      from steps[of i] steps[of \"Suc i\"] have \"(a i, f (Suc i)) \\<in> S^*\" and \"(f (Suc i), b (Suc i)) \\<in> S^*\" by auto\n      from rtrancl_trans[OF this] steps[of i] have R: \"(b i, a i) \\<in> R\" and S: \"(a i, b (Suc i)) \\<in> S^*\" by blast+\n      from S[unfolded rtrancl_list_conv] obtain li where \"last (a i # li) = b (Suc i) \\<and> (\\<forall> j < length li. ((a i # li) ! j, (a i # li) ! Suc j) \\<in> S)\" ..\n      with R have \"?prop i li\" by blast\n      hence \"\\<exists> li. ?prop i li\" ..\n    }\n    hence \"\\<forall> i. \\<exists> li. ?prop i li\" ..\n    from choice[OF this] obtain l where steps: \"\\<And> i. ?prop i (l i)\" by auto\n    let ?p = \"\\<lambda> i. ?prop i (l i)\"\n    from steps have steps: \"\\<And> i. ?p i\" by blast\n    let ?l = \"\\<lambda> i. a i # l i\"\n    let ?g = \"\\<lambda> i. choice (\\<lambda> j. ?l j) i\"\n    obtain g where g: \"\\<And> i. g i = (let (ii,jj) = ?g i in ?l ii ! jj)\" by auto\n    have len: \"\\<And> i j n. ?g n = (i,j) \\<Longrightarrow> j < length (?l i)\"\n    proof -\n      fix i j n\n      assume n: \"?g n = (i,j)\"\n      show \"j < length (?l i)\" \n      proof (cases n)\n        case 0\n        with n have \"j = 0\" by auto\n        thus ?thesis by simp\n      next\n        case (Suc nn)\n        obtain ii jj where nn: \"?g nn = (ii,jj)\" by (cases \"?g nn\", auto)\n        show ?thesis \n        proof (cases \"Suc jj < length (?l ii)\")\n          case True\n          with nn Suc have \"?g n = (ii, Suc jj)\" by auto\n          with n True show ?thesis by simp\n        next\n          case False \n          with nn Suc have \"?g n = (Suc ii, 0)\" by auto\n          with n show ?thesis by simp\n        qed\n      qed\n    qed      \n    have gsteps: \"\\<And> i. (g i, g (Suc i)) \\<in> R \\<union> S\"\n    proof -\n      fix n\n      obtain i j where n: \"?g n = (i, j)\" by (cases \"?g n\", auto)\n      show \"(g n, g (Suc n)) \\<in> R \\<union> S\"\n      proof (cases \"Suc j < length (?l i)\")\n        case True\n        with n have \"?g (Suc n) = (i, Suc j)\" by auto\n        with n have gn: \"g n = ?l i ! j\" and gsn: \"g (Suc n) = ?l i ! (Suc j)\" unfolding g by auto\n        thus ?thesis using steps[of i] True by auto\n      next\n        case False\n        with n have \"?g (Suc n) = (Suc i, 0)\" by auto\n        with n have gn: \"g n = ?l i ! j\" and gsn: \"g (Suc n) = a (Suc i)\" unfolding g by auto\n        from gn len[OF n] False have \"j = length (?l i) - 1\" by auto\n        with gn have gn: \"g n = last (?l i)\" using last_conv_nth[of \"?l i\"] by auto\n        from gn gsn show ?thesis using steps[of i] steps[of \"Suc i\"] by auto\n      qed\n    qed\n    have infR:  \"\\<forall> n. \\<exists> j \\<ge> n. (g j, g (Suc j)) \\<in> R\" \n    proof\n      fix n\n      obtain i j where n: \"?g n = (i,j)\" by (cases \"?g n\", auto)\n      from len[OF n] have j: \"j \\<le> length (?l i) - 1\" by simp\n      let ?k = \"length (?l i) - 1 - j\"\n      obtain k where k: \"k = j + ?k\" by auto\n      from j k have k2: \"k = length (?l i) - 1\" and k3: \"j + ?k < length (?l i)\" by auto\n      {\n        fix n i j k l\n        assume n: \"choice l n = (i,j)\" and \"j + k < length (l i)\"\n        hence \"choice l (n + k) = (i, j + k)\"\n          by (induct k arbitrary: j, simp, auto)\n      }\n      from this[OF n, of ?k, OF k3]\n      have gnk: \"?g (n + ?k) = (i, k)\" by (simp only: k)\n      hence \"g (n + ?k) = ?l i ! k\" unfolding g by auto\n      hence gnk2: \"g (n + ?k) = last (?l i)\" using last_conv_nth[of \"?l i\"] k2 by auto\n      from k2 gnk have \"?g (Suc (n+?k)) = (Suc i, 0)\" by auto\n      hence gnsk2: \"g (Suc (n+?k)) = a (Suc i)\" unfolding g by auto\n      from steps[of i] steps[of \"Suc i\"] have main: \"(g (n+?k), g (Suc (n+?k))) \\<in> R\" \n        by (simp only: gnk2 gnsk2)\n      show \"\\<exists> j \\<ge> n. (g j, g (Suc j)) \\<in> R\" \n        by (rule exI[of _ \"n + ?k\"], auto simp: main[simplified])\n    qed      \n    from SN[simplified SN_rel_on_conv SN_rel_defs] gsteps infR show False\n      unfolding INFM_nat_le by fast\n  qed\nqed\n\nhide_const choice\n\nlemma SN_relto_SN_rel_conv: \"SN (relto R S) = SN_rel R S\"\n  by (blast intro: SN_relto_imp_SN_rel SN_rel_imp_SN_relto)\n\nlemma SN_rel_empty1: \"SN_rel {} S\"\n  unfolding SN_rel_defs by auto\n\nlemma SN_rel_empty2: \"SN_rel R {} = SN R\"\n  unfolding SN_rel_defs SN_defs by auto\n\nlemma SN_relto_mono:\n  assumes R: \"R \\<subseteq> R'\" and S: \"S \\<subseteq> S'\"\n  and SN: \"SN (relto R' S')\"\n  shows \"SN (relto R S)\"\n  using SN SN_subset[OF _ relto_mono[OF R S]] by blast\n\nlemma SN_relto_imp_SN:\n  assumes \"SN (relto R S)\" shows \"SN R\"\nproof\n  fix f\n  assume \"\\<forall>i. (f i, f (Suc i)) \\<in> R\"\n  hence \"\\<And>i. (f i, f (Suc i)) \\<in> relto R S\" by blast\n  thus False using assms unfolding SN_defs by force\nqed\n\nlemma SN_relto_Id:\n  \"SN (relto R (S \\<union> Id)) = SN (relto R S)\"\n  by (simp only: relto_Id)\n\n\ntext {*Termination inheritance by transitivity (see, e.g., Geser's thesis).*}\n\nlemma trans_subset_SN:\n  assumes \"trans R\" and \"R \\<subseteq> (r \\<union> s)\" and \"SN r\" and \"SN s\"\n  shows \"SN R\"\nproof\n  fix f :: \"nat \\<Rightarrow> 'a\"\n  assume \"f 0 \\<in> UNIV\"\n    and chain: \"chain R f\"\n  have *: \"\\<And>i j. i < j \\<Longrightarrow> (f i, f j) \\<in> r \\<union> s\"\n    using assms and chain_imp_trancl [OF chain] by auto\n  let ?M = \"{i. \\<forall>j>i. (f i, f j) \\<notin> r}\"\n  show False\n  proof (cases \"finite ?M\")\n    let ?n = \"Max ?M\"\n    assume \"finite ?M\"\n    with Max_ge have \"\\<forall>i\\<in>?M. i \\<le> ?n\" by simp\n    then have \"\\<forall>k\\<ge>Suc ?n. \\<exists>k'>k. (f k, f k') \\<in> r\" by auto\n    with steps_imp_chainp [of \"Suc ?n\" \"\\<lambda>x y. (x, y) \\<in> r\"] and assms\n      show False by auto\n  next\n    assume \"infinite ?M\"\n    then have \"INFM j. j \\<in> ?M\" by (simp add: Inf_many_def)\n    then interpret infinitely_many \"\\<lambda>i. i \\<in> ?M\" by (unfold_locales) assumption\n    def [simp]: g \\<equiv> \"index\"\n    have \"\\<forall>i. (f (g i), f (g (Suc i))) \\<in> s\"\n    proof\n      fix i\n      have less: \"g i < g (Suc i)\" using index_ordered_less [of i \"Suc i\"] by simp\n      have \"g i \\<in> ?M\" using index_p by simp\n      then have \"(f (g i), f (g (Suc i))) \\<notin> r\" using less by simp\n      moreover have \"(f (g i), f (g (Suc i))) \\<in> r \\<union> s\" using * [OF less] by simp\n      ultimately show \"(f (g i), f (g (Suc i))) \\<in> s\" by blast\n    qed\n    with `SN s` show False by (auto simp: SN_defs)\n  qed\nqed\n\nlemma SN_Un_conv:\n  assumes \"trans (r \\<union> s)\"\n  shows \"SN (r \\<union> s) \\<longleftrightarrow> SN r \\<and> SN s\"\n    (is \"SN ?r \\<longleftrightarrow> ?rhs\")\nproof\n  assume \"SN (r \\<union> s)\" thus \"SN r \\<and> SN s\"\n    using SN_subset[of ?r] by blast\nnext\n  assume \"SN r \\<and> SN s\"\n  with trans_subset_SN[OF assms subset_refl] show \"SN ?r\" by simp\nqed\n\nlemma SN_relto_Un:\n  \"SN (relto (R \\<union> S) Q) \\<longleftrightarrow> SN (relto R (S \\<union> Q)) \\<and> SN (relto S Q)\"\n    (is \"SN ?a \\<longleftrightarrow> SN ?b \\<and> SN ?c\")\nproof -\n  have eq: \"?a^+ = ?b^+ \\<union> ?c^+\" by regexp\n  from SN_Un_conv[of \"?b^+\" \"?c^+\", unfolded eq[symmetric]]\n    show ?thesis unfolding SN_trancl_SN_conv by simp\nqed\n\nlemma SN_relto_split:\n  assumes \"SN (relto r (s \\<union> q2) \\<union> relto q1 (s \\<union> q2))\" (is \"SN ?a\")\n    and \"SN (relto s q2)\" (is \"SN ?b\")\n  shows \"SN (relto r (q1 \\<union> q2) \\<union> relto s (q1 \\<union> q2))\" (is \"SN ?c\")\nproof -\n  have \"?c^+ \\<subseteq> ?a^+ \\<union> ?b^+\" by regexp\n  from trans_subset_SN[OF _ this, unfolded SN_trancl_SN_conv, OF _ assms]\n    show ?thesis by simp\nqed\n\nend", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Abstract-Rewriting/Relative_Rewriting.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.2712334235359007}}
{"text": "(*\n   Title: Theory  Secrecy.thy\n   Author:    Maria Spichkova <maria.spichkova at rmit.edu.au>, 2014\n*)\n\nsection \\<open>Secrecy: Definitions and properties\\<close>\n\ntheory Secrecy\nimports Secrecy_types inout ListExtras\nbegin\n\n\\<comment> \\<open>Encryption, decryption, signature creation and signature verification functions\\<close>\n\\<comment> \\<open>For these functions we define only their signatures and general axioms,\\<close>\n\\<comment> \\<open>because in order to reason effectively, we view them as abstract functions and\\<close>\n\\<comment> \\<open>abstract from their implementation details\\<close> \nconsts \n  Enc  :: \"Keys \\<Rightarrow> Expression list \\<Rightarrow> Expression list\"\n  Decr :: \"Keys \\<Rightarrow> Expression list \\<Rightarrow> Expression list\"\n  Sign :: \"Keys \\<Rightarrow> Expression list \\<Rightarrow> Expression list\"\n  Ext   :: \"Keys \\<Rightarrow> Expression list \\<Rightarrow> Expression list\"\n\n\\<comment> \\<open>Axioms on relations between encription and decription keys\\<close>\naxiomatization\n   EncrDecrKeys :: \"Keys  \\<Rightarrow> Keys \\<Rightarrow> bool\"\nwhere\nExtSign: \n \"EncrDecrKeys K1 K2 \\<longrightarrow> (Ext K1 (Sign K2 E)) = E\"  and\nDecrEnc:\n \"EncrDecrKeys K1 K2 \\<longrightarrow> (Decr K2 (Enc K1 E)) = E\"\n\n\\<comment> \\<open>Set of private keys of a component\\<close>\nconsts\n specKeys :: \"specID \\<Rightarrow> Keys set\"\n\\<comment> \\<open>Set of unguessable values used by a component\\<close>\nconsts \n specSecrets :: \"specID \\<Rightarrow> Secrets set\"\n\n\\<comment> \\<open>Join set of private keys and unguessable values used by a component\\<close>\ndefinition\n  specKeysSecrets :: \"specID \\<Rightarrow> KS set\"\nwhere\n \"specKeysSecrets C \\<equiv>\n  {y .  \\<exists> x. y = (kKS x)  \\<and> (x \\<in> (specKeys C))} \\<union>\n  {z .  \\<exists> s. z = (sKS s)  \\<and> (s \\<in> (specSecrets C))}\"\n\n\\<comment> \\<open>Predicate defining that a list of expression items does not contain\\<close>\n\\<comment> \\<open>any private key  or unguessable value used by a component\\<close>\ndefinition\n  notSpecKeysSecretsExpr :: \"specID \\<Rightarrow>  Expression list \\<Rightarrow> bool\"\nwhere\n     \"notSpecKeysSecretsExpr P e \\<equiv>\n     (\\<forall> x. (kE x) mem e \\<longrightarrow> (kKS x) \\<notin> specKeysSecrets P) \\<and>\n     (\\<forall> y. (sE y) mem e \\<longrightarrow> (sKS y) \\<notin> specKeysSecrets P)\"\n\n\\<comment> \\<open>If a component is a composite one, the set of its private keys\\<close> \n\\<comment> \\<open>is a union of the subcomponents' sets of the private keys\\<close>\ndefinition\n  correctCompositionKeys ::  \"specID \\<Rightarrow> bool\"\nwhere\n  \"correctCompositionKeys x \\<equiv>\n    subcomponents x \\<noteq> {} \\<longrightarrow> \n    specKeys x =  \\<Union> (specKeys ` (subcomponents x))\" \n\n\\<comment> \\<open>If a component is a composite one, the set of its unguessable values\\<close> \n\\<comment> \\<open>is a union of the subcomponents' sets of the unguessable values\\<close>\ndefinition\n  correctCompositionSecrets ::  \"specID \\<Rightarrow> bool\"\nwhere\n  \"correctCompositionSecrets x \\<equiv>\n    subcomponents x \\<noteq> {} \\<longrightarrow> \n    specSecrets x =  \\<Union> (specSecrets ` (subcomponents x))\" \n\n\\<comment> \\<open>If a component is a composite one, the set of its private keys and\\<close> \n\\<comment> \\<open>unguessable values is a union of the corresponding sets of its subcomponents\\<close>\ndefinition\n  correctCompositionKS ::  \"specID \\<Rightarrow> bool\"\nwhere\n  \"correctCompositionKS x \\<equiv>\n    subcomponents x \\<noteq> {} \\<longrightarrow> \n    specKeysSecrets x =  \\<Union> (specKeysSecrets ` (subcomponents x))\" \n\n\\<comment> \\<open>Predicate defining set of correctness properties of the component's\\<close>\n\\<comment> \\<open>interface  and relations on its private keys and unguessable values\\<close>\ndefinition\n  correctComponentSecrecy  ::  \"specID \\<Rightarrow> bool\"\nwhere \n  \"correctComponentSecrecy x \\<equiv> \n    correctCompositionKS x \\<and> \n    correctCompositionSecrets x \\<and> \n    correctCompositionKeys x \\<and> \n    correctCompositionLoc x \\<and>\n    correctCompositionIn x \\<and>\n    correctCompositionOut x \\<and> \n    correctInOutLoc x\"\n\n\\<comment> \\<open>Predicate exprChannel I E defines whether the expression item E can be sent via the channel I\\<close>    \nconsts\n exprChannel :: \"chanID \\<Rightarrow> Expression \\<Rightarrow> bool\"\n\n\\<comment> \\<open>Predicate eoutM sP M E defines whether the component sP may eventually\\<close>\n\\<comment> \\<open>output an expression E if there exists a time interval t of\\<close> \n\\<comment> \\<open>an output channel which contains this expression E\\<close>\ndefinition\n  eout :: \"specID  \\<Rightarrow> Expression \\<Rightarrow> bool\"\nwhere\n \"eout sP E \\<equiv> \n  \\<exists> (ch :: chanID). ((ch \\<in> (out sP)) \\<and> (exprChannel ch E))\"\n\n\\<comment> \\<open>Predicate eout sP E defines whether the component sP may eventually\\<close>\n\\<comment> \\<open>output an expression E via subset of channels M,\\<close>\n\\<comment> \\<open>which is a subset of output channels of sP,\\<close>\n\\<comment> \\<open>and if there exists a time interval t of\\<close> \n\\<comment> \\<open>an output channel which contains this expression E\\<close>\ndefinition\n  eoutM :: \"specID  \\<Rightarrow> chanID set \\<Rightarrow> Expression \\<Rightarrow> bool\"\nwhere\n \"eoutM sP M E \\<equiv> \n  \\<exists> (ch :: chanID). ((ch \\<in> (out sP)) \\<and> (ch \\<in> M) \\<and> (exprChannel ch E))\"\n\n\\<comment> \\<open>Predicate ineM sP M E defines whether a component sP may eventually\\<close>\n\\<comment> \\<open>get an expression E  if there exists a time interval t of\\<close> \n\\<comment> \\<open>an input stream  which contains this expression E\\<close>\ndefinition\n  ine :: \"specID  \\<Rightarrow> Expression \\<Rightarrow> bool\"\nwhere\n \"ine sP E \\<equiv> \n  \\<exists> (ch :: chanID). ((ch \\<in> (ins sP)) \\<and> (exprChannel ch E))\"\n\n\\<comment> \\<open>Predicate ine sP E defines whether a component sP may eventually\\<close>\n\\<comment> \\<open>get an expression E via subset of channels M,\\<close>\n\\<comment> \\<open>which is a subset of input channels of sP,\\<close>\n\\<comment> \\<open>and if there exists a time interval t of\\<close> \n\\<comment> \\<open>an input stream  which contains this expression E\\<close>\ndefinition\n  ineM :: \"specID  \\<Rightarrow> chanID set \\<Rightarrow> Expression \\<Rightarrow> bool\"\nwhere\n \"ineM sP M E \\<equiv> \n  \\<exists> (ch :: chanID). ((ch \\<in> (ins sP)) \\<and> (ch \\<in> M) \\<and> (exprChannel ch E))\"\n\n\\<comment> \\<open>This predicate defines whether an input channel ch of a component sP\\<close>\n\\<comment> \\<open>is the only one input channel of this component\\<close>\n\\<comment> \\<open>via which it may eventually output an expression E\\<close>\ndefinition\n  out_exprChannelSingle :: \"specID  \\<Rightarrow> chanID \\<Rightarrow> Expression \\<Rightarrow> bool\"\nwhere\n \"out_exprChannelSingle sP ch E \\<equiv> \n  (ch \\<in> (out sP)) \\<and>  \n  (exprChannel ch E)  \\<and>\n  (\\<forall> (x :: chanID) (t :: nat). ((x \\<in> (out sP)) \\<and> (x \\<noteq> ch) \\<longrightarrow> \\<not> exprChannel x E))\"\n\n\\<comment> \\<open>This predicate  yields true if only the channels from the set chSet,\\<close>\n\\<comment> \\<open>which is a subset of input channels of the  component sP,\\<close>\n\\<comment> \\<open>may eventually output an expression E\\<close>\ndefinition\n out_exprChannelSet :: \"specID  \\<Rightarrow> chanID set \\<Rightarrow> Expression \\<Rightarrow> bool\"\nwhere\n \"out_exprChannelSet sP chSet E \\<equiv> \n   ((\\<forall> (x ::chanID). ((x \\<in> chSet) \\<longrightarrow> ((x \\<in> (out sP)) \\<and> (exprChannel x E))))\n   \\<and>\n   (\\<forall> (x :: chanID). ((x \\<notin> chSet) \\<and> (x \\<in> (out sP)) \\<longrightarrow> \\<not> exprChannel x E)))\"\n\n\\<comment> \\<open>This redicate defines whether\\<close>\n\\<comment> \\<open>an input channel ch of a component sP is the only one input channel\\<close>\n\\<comment> \\<open>of this component via which it may eventually get an expression E\\<close>\ndefinition\n ine_exprChannelSingle :: \"specID  \\<Rightarrow> chanID \\<Rightarrow> Expression \\<Rightarrow> bool\"\nwhere\n \"ine_exprChannelSingle sP ch E \\<equiv> \n  (ch \\<in> (ins sP)) \\<and>\n  (exprChannel ch E)  \\<and>\n  (\\<forall> (x :: chanID) (t :: nat). (( x \\<in> (ins sP)) \\<and> (x \\<noteq> ch) \\<longrightarrow> \\<not> exprChannel x E))\"\n\n\\<comment> \\<open>This predicate yields true if the component sP may eventually\\<close>\n\\<comment> \\<open>get an expression E only via the channels from the set chSet,\\<close>\n\\<comment> \\<open>which is a subset of input channels of sP\\<close>\ndefinition\n ine_exprChannelSet :: \"specID  \\<Rightarrow> chanID set \\<Rightarrow> Expression \\<Rightarrow> bool\"\nwhere\n \"ine_exprChannelSet sP chSet E \\<equiv> \n   ((\\<forall> (x ::chanID). ((x \\<in> chSet) \\<longrightarrow> ((x \\<in> (ins sP)) \\<and> (exprChannel x E))))\n   \\<and>\n   (\\<forall> (x :: chanID). ((x \\<notin> chSet) \\<and> ( x \\<in> (ins sP)) \\<longrightarrow> \\<not> exprChannel x E)))\"\n\n\\<comment> \\<open>If a list of expression items does not contain any private key\\<close>\n\\<comment> \\<open>or unguessable value of a component P, then the first element\\<close> \n\\<comment> \\<open>of the list is neither a private key nor unguessable value of P\\<close>\nlemma notSpecKeysSecretsExpr_L1:\nassumes \"notSpecKeysSecretsExpr P (a # l)\"\nshows    \"notSpecKeysSecretsExpr P [a]\"\nusing assms by (simp add: notSpecKeysSecretsExpr_def)\n\n\\<comment> \\<open>If a list of expression items does not contain any private key\\<close>\n\\<comment> \\<open>or unguessable value of a component P, then this list without its first\\<close> \n\\<comment> \\<open>element does not contain them too\\<close>\nlemma notSpecKeysSecretsExpr_L2:\nassumes \"notSpecKeysSecretsExpr P (a # l)\"\nshows    \"notSpecKeysSecretsExpr P l\" \nusing assms by (simp add: notSpecKeysSecretsExpr_def)\n\n\\<comment> \\<open>If a channel belongs to the set of input channels of a component P\\<close>\n\\<comment> \\<open>and does not belong to the set of local channels of the compositon of P and Q\\<close> \n\\<comment> \\<open>then it belongs to the set of input channels of this composition\\<close>\nlemma correctCompositionIn_L1:\nassumes \"subcomponents PQ = {P,Q}\" \n       and \"correctCompositionIn PQ\" \n       and \"ch \\<notin> loc PQ\"\n       and \"ch \\<in> ins P\" \nshows    \"ch \\<in> ins PQ\"\nusing assms by (simp add: correctCompositionIn_def)\n\n\\<comment> \\<open>If a channel belongs to the set of input channels of the compositon of P and Q\\<close>\n\\<comment> \\<open>then it belongs to the set of input channels either of P or of Q\\<close>\nlemma correctCompositionIn_L2:\nassumes \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionIn PQ\" \n       and \"ch \\<in> ins PQ\" \nshows    \"(ch \\<in> ins P) \\<or> (ch \\<in> ins Q)\" \nusing assms by (simp add: correctCompositionIn_def)\n\nlemma ineM_L1:\nassumes \"ch \\<in> M\" \n       and \"ch \\<in> ins P\"\n       and \"exprChannel ch E\"\nshows    \"ineM P M E\"\nusing assms by (simp add: ineM_def, blast)\n\nlemma ineM_ine:\nassumes \"ineM P M E\"\nshows    \"ine P E\"\nusing assms by (simp add: ineM_def ine_def, blast)\n\nlemma not_ine_ineM:\nassumes \"\\<not> ine P E\"\nshows    \"\\<not> ineM P M E\"\nusing assms by (simp add: ineM_def ine_def)\n\nlemma eoutM_eout:\nassumes \"eoutM P M E\"\nshows    \"eout P E\"\nusing assms by (simp add: eoutM_def eout_def, blast)\n\nlemma not_eout_eoutM:\nassumes \"\\<not> eout P E\"\nshows    \"\\<not> eoutM P M E\"\nusing assms by (simp add: eoutM_def eout_def)\n\nlemma correctCompositionKeys_subcomp1:\nassumes \"correctCompositionKeys C\"\n        and \"x \\<in> subcomponents C\" \n        and \"xb \\<in> specKeys C\"\nshows \"\\<exists> x \\<in> subcomponents C. (xb \\<in> specKeys x)\"\nusing assms by (simp add: correctCompositionKeys_def, auto)\n\nlemma correctCompositionSecrets_subcomp1:\nassumes \"correctCompositionSecrets C\" \n        and \"x \\<in> subcomponents C\"\n        and \"s \\<in> specSecrets C\"\nshows  \"\\<exists> x \\<in> subcomponents C. (s \\<in> specSecrets x)\"\nusing assms by (simp add: correctCompositionSecrets_def, auto)\n\nlemma correctCompositionKeys_subcomp2:\nassumes \"correctCompositionKeys C\"\n       and \"xb \\<in> subcomponents C\"\n       and \"xc \\<in> specKeys xb\"\nshows \"xc \\<in> specKeys C\"\nusing assms by (simp add: correctCompositionKeys_def, auto)\n\nlemma correctCompositionSecrets_subcomp2:\nassumes \"correctCompositionSecrets C\"\n        and \"xb \\<in> subcomponents C\"\n        and \"xc \\<in> specSecrets xb\"\nshows     \"xc \\<in> specSecrets C\"\nusing assms by (simp add: correctCompositionSecrets_def, auto)\n\nlemma correctCompKS_Keys:\nassumes \"correctCompositionKS C\"\nshows    \"correctCompositionKeys C\"\nproof (cases \"subcomponents C = {}\")\n  assume \"subcomponents C = {}\"\n  from this and assms show ?thesis\n  by (simp add: correctCompositionKeys_def)\nnext\n  assume \"subcomponents C \\<noteq> {}\"\n  from this and assms show ?thesis \n  by (simp add: correctCompositionKS_def \n                correctCompositionKeys_def\n                specKeysSecrets_def, blast)\nqed\n\nlemma correctCompKS_Secrets:\nassumes \"correctCompositionKS C\"\nshows    \"correctCompositionSecrets C\"\nproof (cases \"subcomponents C = {}\")\n  assume \"subcomponents C = {}\"\n  from this and assms show ?thesis\n  by (simp add: correctCompositionSecrets_def)\nnext\n  assume \"subcomponents C \\<noteq> {}\"\n  from this and assms show ?thesis \n  by (simp add: correctCompositionKS_def \n                correctCompositionSecrets_def\n                specKeysSecrets_def, blast)\nqed\n\nlemma correctCompKS_KeysSecrets:\nassumes \"correctCompositionKeys C\"\n        and \"correctCompositionSecrets C\"\nshows    \"correctCompositionKS C\"\nproof (cases \"subcomponents C = {}\")\n  assume \"subcomponents C = {}\"\n  from this and assms show ?thesis\n  by (simp add: correctCompositionKS_def)\nnext\n  assume \"subcomponents C \\<noteq> {}\"\n  from this and assms show ?thesis \n  by (simp add: correctCompositionKS_def \n                correctCompositionKeys_def \n                correctCompositionSecrets_def\n                specKeysSecrets_def, blast)\nqed \n\nlemma correctCompositionKS_subcomp1:\nassumes \"correctCompositionKS C\"\n       and h1:\"x \\<in> subcomponents C\"\n       and \"xa \\<in> specKeys C\"\nshows    \"\\<exists> y \\<in> subcomponents C. (xa \\<in> specKeys y)\"\nproof (cases \"subcomponents C = {}\")\n  assume \"subcomponents C = {}\"\n  from this and h1 show ?thesis by simp \nnext\n  assume \"subcomponents C \\<noteq> {}\"\n  from this and assms show ?thesis \n  by (simp add: correctCompositionKS_def specKeysSecrets_def, blast) \nqed\n\nlemma correctCompositionKS_subcomp2:\nassumes \"correctCompositionKS C\"\n        and h1:\"x \\<in> subcomponents C\"\n        and \"xa \\<in> specSecrets C\"\nshows    \"\\<exists> y \\<in> subcomponents C. xa \\<in> specSecrets y\"\nproof (cases \"subcomponents C = {}\")\n  assume \"subcomponents C = {}\"\n  from this and h1 show ?thesis by simp \nnext\n  assume \"subcomponents C \\<noteq> {}\"\n  from this and assms show ?thesis \n  by (simp add: correctCompositionKS_def specKeysSecrets_def, blast)\nqed\n\nlemma correctCompositionKS_subcomp3:\nassumes \"correctCompositionKS C\"\n       and \"x \\<in> subcomponents C\"\n       and \"xa \\<in> specKeys x\"\nshows    \"xa \\<in> specKeys C\"\nusing assms \nby (simp add: correctCompositionKS_def specKeysSecrets_def, auto)\n\nlemma correctCompositionKS_subcomp4:\nassumes \"correctCompositionKS C\"\n        and \"x \\<in> subcomponents C\"\n        and \"xa \\<in> specSecrets x\" \nshows     \"xa \\<in> specSecrets C\"\nusing assms \nby (simp add: correctCompositionKS_def specKeysSecrets_def, auto)\n\nlemma correctCompositionKS_PQ:\nassumes \"subcomponents PQ = {P, Q}\"\n       and \"correctCompositionKS PQ\" \n       and \"ks \\<in> specKeysSecrets PQ\"\nshows    \"ks \\<in> specKeysSecrets P \\<or> ks \\<in> specKeysSecrets Q\"\nusing assms by (simp add: correctCompositionKS_def)\n\nlemma correctCompositionKS_neg1:\nassumes \"subcomponents PQ = {P, Q}\"\n       and \"correctCompositionKS PQ\" \n       and \"ks \\<notin> specKeysSecrets P\"\n       and \"ks \\<notin> specKeysSecrets Q\"\nshows    \"ks \\<notin> specKeysSecrets PQ\"\nusing assms by (simp add: correctCompositionKS_def)\n\nlemma correctCompositionKS_negP:\nassumes \"subcomponents PQ = {P, Q}\"\n        and \"correctCompositionKS PQ\" \n        and \"ks \\<notin> specKeysSecrets PQ\" \nshows     \"ks \\<notin> specKeysSecrets P\"\nusing assms by (simp add: correctCompositionKS_def)\n\nlemma correctCompositionKS_negQ:\nassumes \"subcomponents PQ = {P, Q}\"\n        and \"correctCompositionKS PQ\" \n        and \"ks \\<notin> specKeysSecrets PQ\" \nshows     \"ks \\<notin> specKeysSecrets Q\"\nusing assms by (simp add: correctCompositionKS_def)\n\nlemma out_exprChannelSingle_Set:\nassumes \"out_exprChannelSingle P ch E\"\nshows    \"out_exprChannelSet P {ch} E\"\nusing assms \nby (simp add: out_exprChannelSingle_def out_exprChannelSet_def)\n\nlemma out_exprChannelSet_Single:\nassumes \"out_exprChannelSet P {ch} E\"\nshows    \"out_exprChannelSingle P ch E\"\nusing assms\nby (simp add: out_exprChannelSingle_def out_exprChannelSet_def)\n\nlemma ine_exprChannelSingle_Set:\nassumes \"ine_exprChannelSingle P ch E\"\n  shows \"ine_exprChannelSet P {ch} E\"\nusing assms \nby (simp add: ine_exprChannelSingle_def ine_exprChannelSet_def)\n\nlemma ine_exprChannelSet_Single:\nassumes \"ine_exprChannelSet P {ch} E\"\nshows    \"ine_exprChannelSingle P ch E\"\nusing assms \nby (simp add: ine_exprChannelSingle_def ine_exprChannelSet_def)\n\nlemma ine_ins_neg1:\nassumes \"\\<not> ine P m\" \n       and \"exprChannel x m\"\nshows    \"x \\<notin> ins P\"\nusing assms by (simp add: ine_def, auto)\n\ntheorem TBtheorem1a:\nassumes \"ine PQ E\" \n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionIn PQ\"\nshows \"ine P E  \\<or> ine Q E\"\nusing assms \nby (simp add: ine_def correctCompositionIn_def, auto)\n\ntheorem TBtheorem1b:\nassumes \"ineM PQ M E\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionIn PQ\" \nshows    \"ineM P M E \\<or> ineM Q M E\"\nusing assms by (simp add: ineM_def correctCompositionIn_def, auto)\n\ntheorem TBtheorem2a:\nassumes \"eout PQ E\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionOut PQ\"\nshows    \"eout P E \\<or> eout Q E\"\nusing assms by (simp add: eout_def correctCompositionOut_def, auto)\n\ntheorem TBtheorem2b:\nassumes \"eoutM PQ M E\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionOut PQ\"\nshows    \"eoutM P M E \\<or> eoutM Q M E\"\nusing assms by (simp add: eoutM_def correctCompositionOut_def, auto)\n\nlemma correctCompositionIn_prop1:\nassumes \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionIn PQ\"\n       and \"x \\<in> (ins PQ)\"\nshows   \"(x \\<in> (ins P)) \\<or> (x \\<in> (ins Q))\" \nusing assms by (simp add: correctCompositionIn_def)\n\nlemma correctCompositionOut_prop1:\nassumes \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionOut PQ\"\n       and \"x \\<in> (out PQ)\"\nshows    \"(x \\<in> (out P)) \\<or> (x \\<in> (out Q))\" \nusing assms by (simp add: correctCompositionOut_def)\n\ntheorem TBtheorem3a:\nassumes \"\\<not> (ine P E)\"\n       and \"\\<not> (ine Q E)\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionIn PQ\"\nshows    \"\\<not> (ine PQ E)\"\nusing assms by (simp add: ine_def correctCompositionIn_def, auto )\n\ntheorem TBlemma3b:\nassumes h1:\"\\<not> (ineM P M E)\"\n       and h2:\"\\<not> (ineM Q M E)\"\n       and subPQ:\"subcomponents PQ = {P,Q}\"\n       and cCompI:\"correctCompositionIn PQ\"\n       and chM:\"ch \\<in> M\" \n       and chPQ:\"ch \\<in> ins PQ\"\n       and eCh:\"exprChannel ch E\"\nshows \"False\"\nproof (cases \"ch \\<in> ins P\")\n  assume a1:\"ch \\<in> ins P\"\n  from a1 and chM and eCh have \"ineM P M E\" by (simp add: ineM_L1)\n  from this and h1 show ?thesis by simp\nnext\n  assume a2:\"ch \\<notin> ins P\" \n  from subPQ and cCompI and chPQ have \"(ch \\<in> ins P) \\<or> (ch \\<in> ins Q)\"\n    by (simp add: correctCompositionIn_L2)\n  from this and a2 have \"ch \\<in> ins Q\" by simp \n  from this and chM and eCh have \"ineM Q M E\" by (simp add: ineM_L1)\n  from this and h2 show ?thesis by simp\nqed\n\ntheorem TBtheorem3b:\nassumes \"\\<not> (ineM P M E)\"\n       and \"\\<not> (ineM Q M E)\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionIn PQ\"\nshows    \"\\<not> (ineM PQ M E)\"\nusing assms by (metis TBtheorem1b)    \n\ntheorem TBtheorem4a_empty:\nassumes \"(ine P E) \\<or> (ine Q E)\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionIn PQ\"\n       and \"loc PQ = {}\"\nshows    \"ine PQ E\"\nusing assms by (simp add: ine_def correctCompositionIn_def, auto)\n\ntheorem TBtheorem4a_P:\nassumes \"ine P E\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionIn PQ\"\n       and \"\\<exists> ch. (ch \\<in> (ins P) \\<and> exprChannel ch E \\<and> ch \\<notin> (loc PQ))\"\nshows    \"ine PQ E\"\nusing assms by (simp add: ine_def correctCompositionIn_def, auto) \n\ntheorem TBtheorem4b_P:\nassumes \"ineM P M E\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionIn PQ\"\n       and \"\\<exists> ch. ((ch \\<in> (ins Q)) \\<and> (exprChannel ch E) \\<and> \n                        (ch \\<notin> (loc PQ)) \\<and> (ch \\<in> M))\"\nshows    \"ineM PQ M E\"\nusing assms by (simp add: ineM_def correctCompositionIn_def, auto) \n\ntheorem TBtheorem4a_PQ:\nassumes \"(ine P E) \\<or> (ine Q E)\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionIn PQ\"\n       and \"\\<exists> ch. (((ch \\<in> (ins P)) \\<or> (ch \\<in> (ins Q) )) \\<and> \n                         (exprChannel ch E) \\<and>  (ch \\<notin> (loc PQ)))\"\nshows    \"ine PQ E\"\nusing assms by (simp add: ine_def correctCompositionIn_def, auto) \n\ntheorem TBtheorem4b_PQ:\nassumes \"(ineM P M E) \\<or> (ineM Q M E)\" \n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionIn PQ\"\n       and \"\\<exists> ch. (((ch \\<in> (ins P)) \\<or> (ch \\<in> (ins Q) )) \\<and> \n                         (ch \\<in> M) \\<and> (exprChannel ch E) \\<and>  (ch \\<notin> (loc PQ)))\"\nshows     \"ineM PQ M E\"\nusing assms by (simp add: ineM_def correctCompositionIn_def, auto) \n\ntheorem TBtheorem4a_notP1:\nassumes \"ine P E\"\n       and \"\\<not> ine Q E\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionIn PQ\" \n       and \"\\<exists> ch. ((ine_exprChannelSingle P ch E) \\<and> (ch \\<in> (loc PQ)))\"\nshows    \"\\<not> ine PQ E\"\nusing assms \nby (simp add: ine_def correctCompositionIn_def \n                     ine_exprChannelSingle_def, auto) \n\ntheorem TBtheorem4b_notP1:\nassumes \"ineM P M E\"\n       and \"\\<not> ineM Q M E\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionIn PQ\"  \n       and \"\\<exists> ch. ((ine_exprChannelSingle P ch E) \\<and> (ch \\<in> M) \n                     \\<and> (ch \\<in> (loc PQ)))\"\nshows    \"\\<not> ineM PQ M E\"\nusing assms\nby (simp add: ineM_def correctCompositionIn_def \n                     ine_exprChannelSingle_def, auto) \n\ntheorem TBtheorem4a_notP2:\nassumes \"\\<not> ine Q E\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionIn PQ\" \n       and \"ine_exprChannelSet P ChSet E\"\n       and \"\\<forall> (x ::chanID). ((x \\<in> ChSet) \\<longrightarrow> (x \\<in> (loc PQ)))\" \nshows    \"\\<not> ine PQ E\"\nusing assms \nby (simp add: ine_def correctCompositionIn_def \n                     ine_exprChannelSet_def, auto) \n\ntheorem TBtheorem4b_notP2:\nassumes \"\\<not> ineM Q M E\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionIn PQ\"\n       and \"ine_exprChannelSet P ChSet E\"\n       and \"\\<forall> (x ::chanID). ((x \\<in> ChSet) \\<longrightarrow> (x \\<in> (loc PQ)))\"\nshows    \"\\<not> ineM PQ M E\"\nusing assms \nby (simp add: ineM_def correctCompositionIn_def \n                     ine_exprChannelSet_def, auto) \n\ntheorem TBtheorem4a_notPQ:\nassumes \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionIn PQ\"\n       and \"ine_exprChannelSet P ChSetP E\"\n       and \"ine_exprChannelSet Q ChSetQ E\"\n       and \"\\<forall> (x ::chanID). ((x \\<in> ChSetP) \\<longrightarrow> (x \\<in> (loc PQ)))\"\n       and \"\\<forall> (x ::chanID). ((x \\<in> ChSetQ) \\<longrightarrow> (x \\<in> (loc PQ)))\"\nshows    \"\\<not> ine PQ E\"\nusing assms \nby (simp add: ine_def correctCompositionIn_def \n                     ine_exprChannelSet_def, auto)\n\nlemma ineM_Un1:\nassumes \"ineM P A E\"\nshows    \"ineM P (A Un B) E\"\nusing assms by (simp add: ineM_def, auto)\n\n\n\nlemma ine_nonempty_exprChannelSet:\nassumes \"ine_exprChannelSet P ChSet E\"\n       and \"ChSet \\<noteq> {}\"\nshows    \"ine P E \"\nusing assms by (simp add: ine_def ine_exprChannelSet_def, auto)\n\nlemma ine_empty_exprChannelSet:\nassumes \"ine_exprChannelSet P ChSet E\"\n       and \"ChSet = {}\"\nshows    \"\\<not> ine P E\"\nusing assms by (simp add: ine_def ine_exprChannelSet_def)\n\ntheorem TBtheorem5a_empty:\nassumes \"(eout P E) \\<or> (eout Q E)\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionOut PQ\"\n       and \"loc PQ = {}\"\nshows    \"eout PQ E\"\nusing assms by (simp add: eout_def correctCompositionOut_def, auto)\n\ntheorem TBtheorem45a_P:\nassumes \"eout P E\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionOut PQ\"\n       and \"\\<exists> ch. ((ch \\<in> (out P)) \\<and> (exprChannel ch E) \\<and> \n                        (ch \\<notin> (loc PQ)))\"\nshows    \"eout PQ E\"\nusing assms by (simp add: eout_def correctCompositionOut_def, auto)\n\ntheorem TBtheore54b_P:\nassumes \"eoutM P M E\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionOut PQ\" \n       and \"\\<exists> ch. ((ch \\<in> (out Q)) \\<and> (exprChannel ch E) \\<and> \n                        (ch \\<notin> (loc PQ)) \\<and> (ch \\<in> M) )\"\nshows    \"eoutM PQ M E\"\nusing assms by (simp add: eoutM_def correctCompositionOut_def, auto)\n\ntheorem TBtheorem5a_PQ:\nassumes \"(eout P E) \\<or> (eout Q E)\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionOut PQ\"\n       and \"\\<exists> ch. (((ch \\<in> (out P)) \\<or> (ch \\<in> (out Q) )) \\<and> \n                        (exprChannel ch E) \\<and>  (ch \\<notin> (loc PQ)))\"\nshows    \"eout PQ E\"\nusing assms by (simp add: eout_def correctCompositionOut_def, auto)\n\ntheorem TBtheorem5b_PQ:\nassumes \"(eoutM P M E) \\<or> (eoutM Q M E)\" \n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionOut PQ\"\n       and \"\\<exists> ch. (((ch \\<in> (out P)) \\<or> (ch \\<in> (out Q) )) \\<and> (ch \\<in> M) \n                      \\<and> (exprChannel ch E) \\<and>  (ch \\<notin> (loc PQ)))\"\nshows    \"eoutM PQ M E\"\nusing assms by (simp add: eoutM_def correctCompositionOut_def, auto) \n\ntheorem TBtheorem5a_notP1:\nassumes \"eout P E\"\n       and \"\\<not> eout Q E\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionOut PQ\"\n       and \"\\<exists> ch. ((out_exprChannelSingle P ch E) \\<and> (ch \\<in> (loc PQ)))\"\nshows    \"\\<not> eout PQ E\"\nusing assms \nby (simp add: eout_def correctCompositionOut_def \n                      out_exprChannelSingle_def, auto) \n\ntheorem TBtheorem5b_notP1:\nassumes \"eoutM P M E\"\n       and \"\\<not> eoutM Q M E\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionOut PQ\"\n       and \"\\<exists> ch. ((out_exprChannelSingle P ch E) \\<and> (ch \\<in> M) \n                   \\<and> (ch \\<in> (loc PQ)))\"\nshows    \"\\<not> eoutM PQ M E\"\nusing assms \nby (simp add: eoutM_def correctCompositionOut_def \n                     out_exprChannelSingle_def, auto) \n\ntheorem TBtheorem5a_notP2:\nassumes \"\\<not> eout Q E\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionOut PQ\" \n       and \"out_exprChannelSet P ChSet E\"\n       and \"\\<forall> (x ::chanID). ((x \\<in> ChSet) \\<longrightarrow> (x \\<in> (loc PQ)))\"\nshows    \"\\<not> eout PQ E\"\nusing assms\nby (simp add: eout_def correctCompositionOut_def \n                     out_exprChannelSet_def, auto)\n\ntheorem TBtheorem5b_notP2:\nassumes \"\\<not> eoutM Q M E\"\n       and \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionOut PQ\"\n       and \"out_exprChannelSet P ChSet E\"\n       and \"\\<forall> (x ::chanID). ((x \\<in> ChSet) \\<longrightarrow> (x \\<in> (loc PQ)))\" \nshows    \"\\<not> eoutM PQ M E\"\nusing assms\nby (simp add: eoutM_def correctCompositionOut_def \n                     out_exprChannelSet_def, auto)\n\ntheorem TBtheorem5a_notPQ:\nassumes \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionOut PQ\"\n       and \"out_exprChannelSet P ChSetP E\"\n       and \"out_exprChannelSet Q ChSetQ E\"\n       and \"\\<forall> (x ::chanID). ((x \\<in> ChSetP) \\<longrightarrow> (x \\<in> (loc PQ)))\"\n       and \"\\<forall> (x ::chanID). ((x \\<in> ChSetQ) \\<longrightarrow> (x \\<in> (loc PQ)))\"\nshows    \"\\<not> eout PQ E\"\nusing assms\nby (simp add: eout_def correctCompositionOut_def \n                     out_exprChannelSet_def, auto) \n\ntheorem TBtheorem5b_notPQ:\nassumes \"subcomponents PQ = {P,Q}\"\n       and \"correctCompositionOut PQ\"\n       and \"out_exprChannelSet P ChSetP E\"\n       and \"out_exprChannelSet Q ChSetQ E\"\n       and \"M = ChSetP \\<union> ChSetQ\"\n       and \"\\<forall> (x ::chanID). ((x \\<in> ChSetP) \\<longrightarrow> (x \\<in> (loc PQ)))\"\n       and \"\\<forall> (x ::chanID). ((x \\<in> ChSetQ) \\<longrightarrow> (x \\<in> (loc PQ)))\"\nshows    \"\\<not> eoutM PQ M E\"\nusing assms \nby (simp add: eoutM_def correctCompositionOut_def \n                     out_exprChannelSet_def, auto) \n\nend \n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/CryptoBasedCompositionalProperties/Secrecy.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.4186969093556866, "lm_q1q2_score": 0.27123111174267006}}
{"text": "(*  Title:      Mapping_Exts.thy\n    Author:     Denis Lohner, Sebastian Ullrich\n*)\n\nsubsection \"Mapping Extensions\"\n\ntext {* Some lifted definition on mapping and efficient implementations. *}\n\ntheory Mapping_Exts\nimports \"~~/src/HOL/Library/Mapping\" FormalSSA_Misc\nbegin\n\nlift_definition mapping_delete_all :: \"('a \\<Rightarrow> bool) \\<Rightarrow> ('a,'b) mapping \\<Rightarrow> ('a,'b) mapping\"\n  is \"\\<lambda>P m x. if (P x) then None else m x\" .\nlift_definition map_keys :: \"('a \\<Rightarrow> 'b) \\<Rightarrow> ('a,'c) mapping \\<Rightarrow> ('b,'c) mapping\"\n  is \"\\<lambda>f m x. if f -` {x} \\<noteq> {} then m (THE k. f -` {x} = {k}) else None\" .\nlift_definition map_values :: \"('a \\<Rightarrow> 'b \\<Rightarrow> 'c option) \\<Rightarrow> ('a,'b) mapping \\<Rightarrow> ('a,'c) mapping\"\n  is \"\\<lambda>f m x. Option.bind (m x) (f x)\" .\nlift_definition restrict_mapping :: \"('a \\<Rightarrow> 'b) \\<Rightarrow> 'a set \\<Rightarrow> ('a, 'b) mapping\"\n  is \"\\<lambda>f. restrict_map (Some \\<circ> f)\" .\nlift_definition mapping_add :: \"('a, 'b) mapping \\<Rightarrow> ('a, 'b) mapping \\<Rightarrow> ('a, 'b) mapping\"\n  is \"op ++\" .\n\ndefinition \"mmap = Mapping.map id\"\n\nlemma lookup_map_keys: \"Mapping.lookup (map_keys f m) x = (if f -` {x} \\<noteq> {} then Mapping.lookup m (THE k. f -` {x} = {k}) else None)\"\napply transfer ..\n\nlemma Mapping_Mapping_lookup [simp, code_unfold]: \"Mapping.Mapping (Mapping.lookup m) = m\" by transfer simp\ndeclare Mapping.lookup.abs_eq[simp]\n\nlemma Mapping_eq_lookup: \"m = m' \\<longleftrightarrow> Mapping.lookup m = Mapping.lookup m'\" by transfer simp\n\nlemma map_of_map_if_conv:\n  \"map_of (map (\\<lambda>k. (k, f k)) xs) x = (if (x \\<in> set xs) then Some (f x) else None)\"\n  by (clarsimp simp: map_of_map_restrict)\n\nlemma Mapping_lookup_map: \"Mapping.lookup (Mapping.map f g m) a = map_option g (Mapping.lookup m (f a))\"\n  by transfer simp\n\nlemma Mapping_lookup_map_default: \"Mapping.lookup (Mapping.map_default k d f m) k' = (if k = k'\n  then (Some \\<circ> f) (case Mapping.lookup m k of None \\<Rightarrow> d | Some x \\<Rightarrow> x)\n  else Mapping.lookup m k')\"\n  unfolding Mapping.map_default_def Mapping.default_def\n  by transfer auto\n\nlemma Mapping_lookup_mapping_add: \"Mapping.lookup (mapping_add m1 m2) k =\n  case_option (Mapping.lookup m1 k) Some (Mapping.lookup m2 k)\"\n  by transfer (simp add: map_add_def)\n\nlemma Mapping_lookup_map_values: \"Mapping.lookup (map_values f m) k =\n  Option.bind (Mapping.lookup m k) (f k)\"\n  by transfer simp\n\nlemma lookup_fold_update [simp]: \"Mapping.lookup (fold (\\<lambda>n. Mapping.update n (g n)) xs m) x\n  = (if (x \\<in> set xs) then Some (g x) else Mapping.lookup m x)\"\n  by transfer (rule fold_update_conv)\n\nlemma mapping_eq_iff: \"m1 = m2 \\<longleftrightarrow> (\\<forall>k. Mapping.lookup m1 k = Mapping.lookup m2 k)\"\n  by transfer auto\n\nlemma lookup_delete: \"Mapping.lookup (Mapping.delete k m) k' = (if k = k' then None else Mapping.lookup m k')\"\n  by transfer auto\n\nlemma keys_map_values: \"Mapping.keys (map_values f m) = Mapping.keys m - {k\\<in>Mapping.keys m. f k (the (Mapping.lookup m k)) = None}\"\n  by transfer (auto simp: Option.bind_def split: option.splits)\n\nlemma map_default_eq: \"Mapping.map_default k v f m = m \\<longleftrightarrow> (\\<exists>v. Mapping.lookup m k = Some v \\<and> f v = v)\"\n  apply (clarsimp simp: Mapping.map_default_def Mapping.default_def)\n  by transfer' (auto simp: fun_eq_iff split: if_splits)\n\nlemma lookup_update_cases: \"Mapping.lookup (Mapping.update k v m) k' = (if k=k' then Some v else Mapping.lookup m k')\"\nby (cases \"k=k'\", simp_all add: Mapping.lookup_update Mapping.lookup_update_neq)\n\nend\n", "meta": {"author": "lohner", "repo": "FormalSSA", "sha": "34253ae0ea0db6ef78b644f41ab5e9d0bde6c32e", "save_path": "github-repos/isabelle/lohner-FormalSSA", "path": "github-repos/isabelle/lohner-FormalSSA/FormalSSA-34253ae0ea0db6ef78b644f41ab5e9d0bde6c32e/Mapping_Exts.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736784074525098, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.27116830409672554}}
{"text": "section \\<open>Verification Condition Testing\\<close>\n\ntheory utp_hoare_total\n  imports algebraic_laws_designs\nbegin\nnamed_theorems hoare_total\n\nsubsection {*Hoare triple definition*}\n\ndefinition hoare_rd :: \"'\\<alpha> cond \\<Rightarrow> ('f,'\\<alpha>) hrel_cp \\<Rightarrow> '\\<alpha> cond \\<Rightarrow> bool\" (\"\\<lbrace>_\\<rbrace>_\\<lbrace>_\\<rbrace>\\<^sub>D\") where\n[upred_defs]:\"\\<lbrace>p\\<rbrace>Q\\<lbrace>r\\<rbrace>\\<^sub>D = \n  ((\\<lceil>p\\<rceil>\\<^sub>C\\<^sub>< \\<and> $ok \\<and> \\<not>$abrupt \\<and> \\<not>$stuck \\<and> \\<not>$fault \\<and> $fault_tr =\\<^sub>u \\<guillemotleft>None\\<guillemotright> \\<Rightarrow> \n    \\<lceil>r\\<rceil>\\<^sub>C\\<^sub>> \\<and> $ok\\<acute> \\<and> \\<not>$abrupt\\<acute> \\<and> \\<not>$stuck\\<acute> \\<and> \\<not>$fault\\<acute> \\<and> $fault_tr\\<acute> =\\<^sub>u \\<guillemotleft>None\\<guillemotright>) \\<sqsubseteq> Q)\"\n\nlemma hoare_true_t [hoare_total]:\n  assumes \"$ok \\<sharp> C\" \"$abrupt \\<sharp> C\" \"$stuck \\<sharp> C\" \"$fault \\<sharp> C\" \"$fault_tr \\<sharp> C\"\n          \"$ok\\<acute> \\<sharp> C\" \"$abrupt\\<acute> \\<sharp> C\" \"$stuck\\<acute> \\<sharp> C\" \"$fault\\<acute> \\<sharp> C\" \"$fault_tr\\<acute> \\<sharp> C\"\n  shows \"\\<lbrace>p\\<rbrace>C\\<lbrace>true\\<rbrace>\\<^sub>D\"\n oops\n\nlemma hoare_false_t [hoare_total]: \"\\<lbrace>false\\<rbrace>C\\<lbrace>q\\<rbrace>\\<^sub>D\"\n  by rel_auto\n\nsubsection {*Precondition strengthening*}\n\nlemma hoare_pre_str_t[hoare_total]:\n  assumes \"`p\\<^sub>1 \\<Rightarrow> p\\<^sub>2`\" and \"\\<lbrace>p\\<^sub>2\\<rbrace>C\\<lbrace>q\\<rbrace>\\<^sub>D\"\n  shows \"\\<lbrace>p\\<^sub>1\\<rbrace>C\\<lbrace>q\\<rbrace>\\<^sub>D\" \n  by (insert assms) rel_auto\n\nsubsection {*Post-condition weakening*}\n\nlemma hoare_post_weak_t[hoare_total]:\n  assumes \"\\<lbrace>p\\<rbrace>C\\<lbrace>q\\<^sub>2\\<rbrace>\\<^sub>D\" and \"`q\\<^sub>2 \\<Rightarrow> q\\<^sub>1`\"\n  shows \"\\<lbrace>p\\<rbrace>C\\<lbrace>q\\<^sub>1\\<rbrace>\\<^sub>D\" \n by (insert assms) rel_auto\n\nsubsection {*Hoare and assertion logic*}\n\nlemma hoare_r_conj_t [hoare_total]: \n  assumes\"\\<lbrace>p\\<rbrace>C\\<lbrace>r\\<rbrace>\\<^sub>D\" and \"\\<lbrace>p\\<rbrace>C\\<lbrace>s\\<rbrace>\\<^sub>D\"  \n  shows \"\\<lbrace>p\\<rbrace>C\\<lbrace>r \\<and> s\\<rbrace>\\<^sub>D\"\n  by (insert assms) rel_auto\n\nsubsection {*Hoare SKIP*}\n\nlemma skip_hoare_r_t [hoare_total]: \"\\<lbrace>p\\<rbrace>SKIP\\<lbrace>p\\<rbrace>\\<^sub>D\"\n  by rel_auto\n\nsubsection {*Hoare for assignment*}\n\nlemma assigns_hoare_r_t [hoare_total]: \n  assumes\"`p \\<Rightarrow> \\<sigma> \\<dagger> q`\" \n  shows  \"\\<lbrace>p\\<rbrace>\\<langle>\\<sigma>\\<rangle>\\<^sub>C\\<lbrace>q\\<rbrace>\\<^sub>D\"\n  by (insert assms) rel_auto\n\nlemma assigns_hoare_r'_t [hoare_total]: \"\\<lbrace>\\<sigma> \\<dagger> p\\<rbrace>\\<langle>\\<sigma>\\<rangle>\\<^sub>C\\<lbrace>p\\<rbrace>\\<^sub>D\"\n  by rel_auto\n\nsubsection {*Hoare for Sequential Composition*}\n\nlemma seq_hoare_r_t [hoare_total]: \n  assumes\"\\<lbrace>p\\<rbrace>C\\<^sub>1\\<lbrace>s\\<rbrace>\\<^sub>D\" and \"\\<lbrace>s\\<rbrace>C\\<^sub>2\\<lbrace>r\\<rbrace>\\<^sub>D\" \n  shows\"\\<lbrace>p\\<rbrace>C\\<^sub>1 ;; C\\<^sub>2\\<lbrace>r\\<rbrace>\\<^sub>D\"\n  by (insert assms, rel_auto) metis+ \n\nsubsection {*Hoare for Conditional*}\n\nlemma cond_hoare_r_t [hoare_total]: \n  assumes \"\\<lbrace>b \\<and> p\\<rbrace>C\\<^sub>1\\<lbrace>q\\<rbrace>\\<^sub>D\" and \"\\<lbrace>\\<not>b \\<and> p\\<rbrace>C\\<^sub>2\\<lbrace>q\\<rbrace>\\<^sub>D\" \n  shows \"\\<lbrace>p\\<rbrace>C\\<^sub>1 \\<triangleleft> \\<lceil>b\\<rceil>\\<^sub>C\\<^sub>< \\<triangleright> C\\<^sub>2\\<lbrace>q\\<rbrace>\\<^sub>D\"\n  by (insert assms, rel_auto) metis+ \n\nsubsection {*Hoare for assert*}\n\nlemma assert_hoare_r_t [hoare_total]: \n  assumes \"\\<lbrace>c \\<and> p\\<rbrace>SKIP\\<lbrace>q\\<rbrace>\\<^sub>D\" and \"\\<lbrace>\\<not>c \\<and> p\\<rbrace>\\<bottom>\\<^sub>D\\<lbrace>q\\<rbrace>\\<^sub>D\" \n  shows \"\\<lbrace>p\\<rbrace> c\\<^sub>\\<bottom>\\<^sub>C \\<lbrace>q\\<rbrace>\\<^sub>D\"\n  by (insert assms) rel_blast\n\nsubsection {*Hoare for assume*}\n\nlemma assume_hoare_r_t [hoare_total]: \n  assumes \"\\<lbrace>c \\<and> p\\<rbrace>SKIP\\<lbrace>q\\<rbrace>\\<^sub>D\" and \"\\<lbrace>\\<not>c \\<and> p\\<rbrace>\\<top>\\<^sub>D\\<lbrace>q\\<rbrace>\\<^sub>D\" \n  shows \"\\<lbrace>p\\<rbrace>c\\<^sup>\\<top>\\<^sup>C\\<lbrace>q\\<rbrace>\\<^sub>D\"\n  by (insert assms) rel_blast\n\nsubsection {*Hoare for While-loop*}\n\nlemma while_hoare_r_t [hoare_total]:\n  assumes \"\\<lbrace>p \\<and> b \\<rbrace> C\\<lbrace>p\\<rbrace>\\<^sub>D\"\n  shows \"\\<lbrace>p\\<rbrace>while b do C od\\<lbrace>\\<not>b \\<and> p\\<rbrace>\\<^sub>D\"\n  using assms\n  by (simp add: While_def hoare_rd_def, rule_tac lfp_lowerbound)(rel_blast) \n\n\nlemma while_hoare_r'_t [hoare_total]:\n  assumes \"\\<lbrace>p \\<and> b\\<rbrace>C\\<lbrace>p\\<rbrace>\\<^sub>D\" and \"`p \\<and> \\<not>b \\<Rightarrow> q`\"\n  shows \"\\<lbrace>p\\<rbrace>while b do C od\\<lbrace>q\\<rbrace>\\<^sub>D\"\n  using assms\n  by (metis hoare_post_weak_t while_hoare_r_t inf_commute)\n\nlemma while_invr_hoare_r_t [hoare_total]:\n  assumes \"\\<lbrace>p \\<and> b\\<rbrace>C\\<lbrace>p\\<rbrace>\\<^sub>D\" and \"`pre \\<Rightarrow> p`\" and \"`(\\<not>b \\<and> p) \\<Rightarrow> post`\"\n  shows \"\\<lbrace>pre\\<rbrace>while b invr p do C od\\<lbrace>post\\<rbrace>\\<^sub>D\"\n  by (metis assms hoare_pre_str_t while_hoare_r'_t While_inv_def inf_commute)\n\nend", "meta": {"author": "git-vt", "repo": "orca", "sha": "92bda0f9cfe5cc680b9c405fc38f07a960087a36", "save_path": "github-repos/isabelle/git-vt-orca", "path": "github-repos/isabelle/git-vt-orca/orca-92bda0f9cfe5cc680b9c405fc38f07a960087a36/Archive/Programming-Languages-Semantics/WP11-C-semantics/src/orca/hoare/utp_hoare_total.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5506073655352404, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.2710024127569286}}
{"text": "theory MDEAK_examples_completeness\nimports Main MDEAK_Core_SE MDEAK_SE MDEAK_examples\nbegin\n\nlemma c1_f: \"\\<turnstile>d (a \\<triangle>\\<^sub>0 ((p)\\<^sub>F) )\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M ((a \\<triangle>\\<^sub>0 \\<top>) \\<and>\\<^sub>F ((p)\\<^sub>F))\\<^sub>S\\<^sub>F\\<^sub>M\"\nproof - \n  have \"\\<turnstile>d (a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangle>\\<^sub>0\\<^sub>S ((p)\\<^sub>F)\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M ((p)\\<^sub>F)\\<^sub>S\\<^sub>F\\<^sub>M\"\n    by (simp add: Atom)\n  then have \"\\<turnstile>d (a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangle>\\<^sub>0\\<^sub>S I\\<^sub>S \\<turnstile>\\<^sub>F\\<^sub>M (a \\<triangle>\\<^sub>0 \\<top>)\\<^sub>S\\<^sub>F\\<^sub>M\"\n    by (simp add: Fdiam0_R Id_fa Top_R)\n  then have \"\\<turnstile>d (a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangle>\\<^sub>0\\<^sub>S (I\\<^sub>S ;\\<^sub>S ((p)\\<^sub>F)\\<^sub>S\\<^sub>F\\<^sub>M) \\<turnstile>\\<^sub>F\\<^sub>M ((a \\<triangle>\\<^sub>0 \\<top>) \\<and>\\<^sub>F ((p)\\<^sub>F))\\<^sub>S\\<^sub>F\\<^sub>M\"\n    by (simp add: And_R Mon_fdiam0 \\<open>\\<turnstile>d a \\<^sub>S\\<^sub>F\\<^sub>A \\<triangle>\\<^sub>0\\<^sub>S p \\<^sub>F \\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M p \\<^sub>F \\<^sub>S\\<^sub>F\\<^sub>M\\<close>)\n  then have \"\\<turnstile>d ((p)\\<^sub>F)\\<^sub>S\\<^sub>F\\<^sub>M  \\<turnstile>\\<^sub>F\\<^sub>M (a)\\<^sub>S\\<^sub>F\\<^sub>A \\<unrhd>\\<^sub>0\\<^sub>S ((a \\<triangle>\\<^sub>0 \\<top>) \\<and>\\<^sub>F ((p)\\<^sub>F))\\<^sub>S\\<^sub>F\\<^sub>M\"\n    using DH_fdiam0_f D_IL1_f I_1L_b by blast\n  then show ?thesis\n    by (simp add: DH_fdiam0_b Fdiam0_L)\nqed\n\nlemma c1_b: \"\\<turnstile>d ((a \\<triangle>\\<^sub>0 \\<top>) \\<and>\\<^sub>F (p)\\<^sub>F)\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a \\<triangle>\\<^sub>0 (p)\\<^sub>F)\\<^sub>S\\<^sub>F\\<^sub>M\"\nproof - \n  have \"\\<turnstile>d (a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangle>\\<^sub>0\\<^sub>S (((a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangleq>\\<^sub>0\\<^sub>S ((p)\\<^sub>F)\\<^sub>S\\<^sub>F\\<^sub>M) ;\\<^sub>S (\\<top>)\\<^sub>S\\<^sub>F\\<^sub>M ) \\<turnstile>\\<^sub>F\\<^sub>M (a \\<triangle>\\<^sub>0 (p)\\<^sub>F)\\<^sub>S\\<^sub>F\\<^sub>M\"\n    by (simp add: Atom D_IR1_b Fdiam0_R Id_fa W_2L)\n  then show ?thesis\n    using And_L Conj_fdiam0 D_IR1_b D_IR1_f E_L Fdiam0_L by blast\nqed\n\nlemma c2_f: \"\\<turnstile>d (a \\<rhd>\\<^sub>0 (p)\\<^sub>F)\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M ((a \\<triangle>\\<^sub>0 \\<top>) \\<rightarrow>\\<^sub>F (p)\\<^sub>F)\\<^sub>S\\<^sub>F\\<^sub>M\"\nproof - \n  have \"\\<turnstile>d (a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangleq>\\<^sub>0\\<^sub>S (a \\<rhd>\\<^sub>0 (p)\\<^sub>F)\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a)\\<^sub>S\\<^sub>F\\<^sub>A \\<unrhd>\\<^sub>0\\<^sub>S ((p)\\<^sub>F)\\<^sub>S\\<^sub>F\\<^sub>M\"\n    by (simp add: Atom DH_bdiam0_b Fbox0_L Id_fa)\n  then show ?thesis\n    by (simp add: DH_fdiam0_b D_IR1_b D_IR1_f E_L FS_bbox0 Fdiam0_L ImpR_R W_2L)\nqed\n\nlemma c2_b: \"\\<turnstile>d ((a \\<triangle>\\<^sub>0 \\<top>) \\<rightarrow>\\<^sub>F (p)\\<^sub>F)\\<^sub>S\\<^sub>F\\<^sub>M  \\<turnstile>\\<^sub>F\\<^sub>M (a \\<rhd>\\<^sub>0 (p)\\<^sub>F)\\<^sub>S\\<^sub>F\\<^sub>M\"\nsledgehammer\nproof - \n  have \"\\<turnstile>d ((a \\<triangle>\\<^sub>0 \\<top>) \\<rightarrow>\\<^sub>F (p)\\<^sub>F)\\<^sub>S\\<^sub>F\\<^sub>M  \\<turnstile>\\<^sub>F\\<^sub>M (a)\\<^sub>S\\<^sub>F\\<^sub>A \\<rhd>\\<^sub>0\\<^sub>S (I\\<^sub>S \\<rightarrow>\\<^sub>S ((p)\\<^sub>F)\\<^sub>S\\<^sub>F\\<^sub>M)\"\n    by (simp add: Atom FS_fbox0 Fdiam0_R Id_fa ImpR_L Top_R)\n  then show ?thesis\n    using DH_bdiam0_b DH_bdiam0_f D_IL1_f D_IR1_b Fbox0_R I_1L_b by blast\nqed\n\nlemma c3: \"\\<turnstile>d (a \\<triangle>\\<^sub>0 \\<top>)\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a \\<triangle>\\<^sub>0 \\<top>)\\<^sub>S\\<^sub>F\\<^sub>M\"\nby (simp add: AderivesA)\n\nlemma c4_f: \"\\<turnstile>d (a \\<rhd>\\<^sub>0 \\<bottom>)\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M ((a \\<triangle>\\<^sub>0 \\<top>) \\<rightarrow>\\<^sub>F \\<bottom>)\\<^sub>S\\<^sub>F\\<^sub>M\"\nproof -\n  have f1: \"\\<forall>f fa. \\<not> \\<turnstile>d f \\<turnstile>\\<^sub>F\\<^sub>M I\\<^sub>S \\<or> \\<turnstile>d f \\<turnstile>\\<^sub>F\\<^sub>M fa\"\n    by (metis IW_R)\n  have f2: \"\\<forall>f fa fb. \\<not> \\<turnstile>d f \\<turnstile>\\<^sub>F\\<^sub>M fa \\<rightarrow>\\<^sub>S fb \\<or> \\<turnstile>d fa ;\\<^sub>S f \\<turnstile>\\<^sub>F\\<^sub>M fb\"\n    by (metis D_IR1_b)\n  have f3: \"\\<forall>f fa fb. \\<not> \\<turnstile>d f ;\\<^sub>S fa \\<turnstile>\\<^sub>F\\<^sub>M fb \\<or> \\<turnstile>d fa ;\\<^sub>S f \\<turnstile>\\<^sub>F\\<^sub>M fb\"\n    by (metis E_L)\n  have f4: \"\\<forall>f fa fb. \\<not> \\<turnstile>d f ;\\<^sub>S fa \\<turnstile>\\<^sub>F\\<^sub>M fb \\<or> \\<turnstile>d fa \\<turnstile>\\<^sub>F\\<^sub>M f \\<rightarrow>\\<^sub>S fb\"\n    by (metis D_IR1_f)\n  have \"\\<turnstile>d (a \\<rhd>\\<^sub>0 \\<bottom>) \\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M a \\<^sub>S\\<^sub>F\\<^sub>A \\<rhd>\\<^sub>0\\<^sub>S I\\<^sub>S\"\n    by (meson Bot_L Fbox0_L Id_fa)\n  then have \"\\<turnstile>d a \\<^sub>S\\<^sub>F\\<^sub>A \\<triangleq>\\<^sub>0\\<^sub>S (a \\<rhd>\\<^sub>0 \\<bottom>) \\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M I\\<^sub>S\"\n    by (metis DH_bdiam0_b)\n  then have \"\\<turnstile>d \\<top> \\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M a \\<^sub>S\\<^sub>F\\<^sub>A \\<unrhd>\\<^sub>0\\<^sub>S ((a \\<rhd>\\<^sub>0 \\<bottom>) \\<^sub>S\\<^sub>F\\<^sub>M \\<rightarrow>\\<^sub>S \\<bottom> \\<^sub>S\\<^sub>F\\<^sub>M)\"\n    using f4 f3 f2 f1 by (meson FS_bbox0)\n  then have \"\\<turnstile>d a \\<^sub>S\\<^sub>F\\<^sub>A \\<triangle>\\<^sub>0\\<^sub>S \\<top> \\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a \\<rhd>\\<^sub>0 \\<bottom>) \\<^sub>S\\<^sub>F\\<^sub>M \\<rightarrow>\\<^sub>S \\<bottom> \\<^sub>S\\<^sub>F\\<^sub>M\"\n    by (metis DH_fdiam0_b)\n  then have \"\\<turnstile>d (a \\<triangle>\\<^sub>0 \\<top>) \\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a \\<rhd>\\<^sub>0 \\<bottom>) \\<^sub>S\\<^sub>F\\<^sub>M \\<rightarrow>\\<^sub>S \\<bottom> \\<^sub>S\\<^sub>F\\<^sub>M\"\n    by (metis Fdiam0_L)\n  then have \"\\<turnstile>d (a \\<rhd>\\<^sub>0 \\<bottom>) \\<^sub>S\\<^sub>F\\<^sub>M ;\\<^sub>S (a \\<triangle>\\<^sub>0 \\<top>) \\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M \\<bottom> \\<^sub>S\\<^sub>F\\<^sub>M\"\n    using f2 by metis\n  then have \"\\<turnstile>d (a \\<triangle>\\<^sub>0 \\<top>) \\<^sub>S\\<^sub>F\\<^sub>M ;\\<^sub>S (a \\<rhd>\\<^sub>0 \\<bottom>) \\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M \\<bottom> \\<^sub>S\\<^sub>F\\<^sub>M\"\n    using f3 by meson\n  then have \"\\<turnstile>d (a \\<rhd>\\<^sub>0 \\<bottom>) \\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a \\<triangle>\\<^sub>0 \\<top>) \\<^sub>S\\<^sub>F\\<^sub>M \\<rightarrow>\\<^sub>S \\<bottom> \\<^sub>S\\<^sub>F\\<^sub>M\"\n    using f4 by metis\n  then show ?thesis\n    by (metis ImpR_R)\nqed\n(*by (meson Bot_L DH_bdiam2_b DH_fdiam2_b D_IR1_b D_IR1_f E_L FS_bbox2 Fbox2_L Fdiam2_L IW_R Id_ag ImpR_R)*)\n\nlemma c4_b: \"\\<turnstile>d ((a \\<triangle>\\<^sub>0 \\<top>) \\<rightarrow>\\<^sub>F \\<bottom>)\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a \\<rhd>\\<^sub>0 \\<bottom>)\\<^sub>S\\<^sub>F\\<^sub>M\"\nproof - \n  have \"\\<turnstile>d ((a \\<triangle>\\<^sub>0 \\<top>) \\<rightarrow>\\<^sub>F \\<bottom>)\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a)\\<^sub>S\\<^sub>F\\<^sub>A \\<rhd>\\<^sub>0\\<^sub>S (I\\<^sub>S \\<rightarrow>\\<^sub>S (\\<bottom>)\\<^sub>S\\<^sub>F\\<^sub>M)\"\n    using Bot_L FS_fbox0 Fdiam0_R IW_R Id_fa ImpR_L Top_R by blast\n  then show ?thesis\n    using DH_bdiam0_b DH_bdiam0_f D_IL1_f D_IR1_b Fbox0_R I_1L_b by blast\nqed\n\nlemma c5_f: \"\\<turnstile>d (a \\<triangle>\\<^sub>0 \\<bottom>)\\<^sub>S\\<^sub>F\\<^sub>M  \\<turnstile>\\<^sub>F\\<^sub>M (\\<bottom>)\\<^sub>S\\<^sub>F\\<^sub>M\"\nusing Bot_L DH_fdiam0_b Fdiam0_L IW_R by blast\n\nlemma c5_b: \"\\<turnstile>d (\\<bottom>)\\<^sub>S\\<^sub>F\\<^sub>M  \\<turnstile>\\<^sub>F\\<^sub>M (a \\<triangle>\\<^sub>0 \\<bottom>)\\<^sub>S\\<^sub>F\\<^sub>M\"\nusing [[simp_trace_new mode=full]] \nby (simp add: Bot_L IW_R)\n\nlemma c6_f: \"\\<turnstile>d (a \\<rhd>\\<^sub>0 \\<top>)\\<^sub>S\\<^sub>F\\<^sub>M  \\<turnstile>\\<^sub>F\\<^sub>M (\\<top>)\\<^sub>S\\<^sub>F\\<^sub>M\"\nusing [[simp_trace_new mode=full]] \nby (simp add: IW_L Top_R)\n\nlemma c6_b: \"\\<turnstile>d (\\<top>)\\<^sub>S\\<^sub>F\\<^sub>M  \\<turnstile>\\<^sub>F\\<^sub>M (a \\<rhd>\\<^sub>0 \\<top>)\\<^sub>S\\<^sub>F\\<^sub>M\"\nusing [[simp_trace_new mode=full]] \nby (simp add: DH_bdiam0_f Fbox0_R IW_L Top_R)\n\nlemma c7_f: \"\\<turnstile>d (a \\<rhd>\\<^sub>0 (A \\<and>\\<^sub>F B))\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M ((a \\<rhd>\\<^sub>0 A) \\<and>\\<^sub>F (a \\<rhd>\\<^sub>0 B))\\<^sub>S\\<^sub>F\\<^sub>M\"\nproof - \n  have f1:  \"\\<turnstile>d (a \\<rhd>\\<^sub>0 (A \\<and>\\<^sub>F B))\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a \\<rhd>\\<^sub>0 A)\\<^sub>S\\<^sub>F\\<^sub>M\"\n    by (simp add: AderivesA And_L D_IR1_b Fbox0_L Fbox0_R Id_fa W_2L)\n  have f2: \"\\<turnstile>d (a \\<rhd>\\<^sub>0 (A \\<and>\\<^sub>F B))\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a \\<rhd>\\<^sub>0 B)\\<^sub>S\\<^sub>F\\<^sub>M\"\n    by (simp add: AderivesA And_L D_IL1_b Fbox0_L Fbox0_R Id_fa W_1L)\n  show ?thesis\n    using And_R C_L f1 f2 by blast\nqed  \n\nlemma c7_b: \"\\<turnstile>d ((a \\<rhd>\\<^sub>0 A) \\<and>\\<^sub>F (a \\<rhd>\\<^sub>0 B))\\<^sub>S\\<^sub>F\\<^sub>M  \\<turnstile>\\<^sub>F\\<^sub>M (a \\<rhd>\\<^sub>0 (A \\<and>\\<^sub>F B))\\<^sub>S\\<^sub>F\\<^sub>M\"\nproof -\n  have \"\\<turnstile>d (a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangleq>\\<^sub>0\\<^sub>S (a \\<rhd>\\<^sub>0 A)\\<^sub>S\\<^sub>F\\<^sub>M  \\<turnstile>\\<^sub>F\\<^sub>M (A)\\<^sub>S\\<^sub>F\\<^sub>M\"\n    by (simp add: AderivesA DH_bdiam0_b Fbox0_L Id_fa)\n  then show ?thesis\n    by (simp add: AderivesA And_L And_R DH_bdiam0_b DH_bdiam0_f Fbox0_L Fbox0_R Id_fa Mon_bdiam0)\nqed\n\nlemma c8_f: \"\\<turnstile>d (a \\<triangle>\\<^sub>0 (A \\<and>\\<^sub>F B))\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M ((a \\<triangle>\\<^sub>0 A) \\<and>\\<^sub>F (a \\<triangle>\\<^sub>0 B))\\<^sub>S\\<^sub>F\\<^sub>M\"\nby (metis And_L And_R C_L D_IL1_b D_IR1_b Fdiam0_L Fdiam0_R Id_fa W_1L W_2L AderivesA)\n\n(*lemma c8_f_simple: \"\\<turnstile>d (a \\<triangle>\\<^sub>2 ((A)\\<^sub>F \\<and>\\<^sub>F (B)\\<^sub>F))\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M ((a \\<triangle>\\<^sub>2 (A)\\<^sub>F) \\<and>\\<^sub>F (a \\<triangle>\\<^sub>2 (B)\\<^sub>F) )\\<^sub>S\\<^sub>F\\<^sub>M\"\nby (metis And_L And_R C_L D_IL1_b D_IR1_b Fdiam2_L Fdiam2_R Id_ag Id_fm W_1L W_2L)*)\n\nlemma c8_b: \"\\<turnstile>d ((a \\<triangle>\\<^sub>0 A) \\<and>\\<^sub>F (a \\<triangle>\\<^sub>0 B))\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a \\<triangle>\\<^sub>0 (A \\<and>\\<^sub>F B))\\<^sub>S\\<^sub>F\\<^sub>M\"\nproof -\n  have \"\\<turnstile>d (a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangleq>\\<^sub>0\\<^sub>S (((a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangle>\\<^sub>0\\<^sub>S (A)\\<^sub>S\\<^sub>F\\<^sub>M) ;\\<^sub>S ((a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangle>\\<^sub>0\\<^sub>S (B)\\<^sub>S\\<^sub>F\\<^sub>M)) \\<turnstile>\\<^sub>F\\<^sub>M (A \\<and>\\<^sub>F B)\\<^sub>S\\<^sub>F\\<^sub>M\"\n    by (simp add: AderivesA And_R Balance Conj_fdiam0 DH_bdiam0_b)\n  then show ?thesis\n    by (simp add: And_L Conj_bdiam0 Conj_fdiam0 D_IL1_b D_IL1_f E_L Fdiam0_L Fdiam0_R Id_fa)\nqed\n\nlemma c9_f: \"\\<turnstile>d (a \\<triangle>\\<^sub>0 (A \\<or>\\<^sub>F B))\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M ((a \\<triangle>\\<^sub>0 A) \\<or>\\<^sub>F (a \\<triangle>\\<^sub>0 B))\\<^sub>S\\<^sub>F\\<^sub>M\"\nproof -\n  have \"\\<turnstile>d (A)\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a)\\<^sub>S\\<^sub>F\\<^sub>A \\<unrhd>\\<^sub>0\\<^sub>S (a \\<triangle>\\<^sub>0 A)\\<^sub>S\\<^sub>F\\<^sub>M\"\n    by (simp add: AderivesA DH_fdiam0_f Fdiam0_R Id_fa)\n  then show ?thesis\n    by (simp add: AderivesA DH_fdiam0_b DH_fdiam0_f Fdiam0_L Fdiam0_R Id_fa Mon_bbox0 Or_L Or_R)\nqed\n\nlemma c9_b: \"\\<turnstile>d ((a \\<triangle>\\<^sub>0 A) \\<or>\\<^sub>F (a \\<triangle>\\<^sub>0 B))\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a \\<triangle>\\<^sub>0 (A \\<or>\\<^sub>F B))\\<^sub>S\\<^sub>F\\<^sub>M\"\nproof -\n  have f1: \"\\<turnstile>d (a \\<triangle>\\<^sub>0 A)\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a \\<triangle>\\<^sub>0 (A \\<or>\\<^sub>F B))\\<^sub>S\\<^sub>F\\<^sub>M \"\n    by (simp add: AderivesA D_IR2_b Fdiam0_L Fdiam0_R Id_fa Or_R W_2R)\n  have f2: \"\\<turnstile>d (a \\<triangle>\\<^sub>0 B)\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a \\<triangle>\\<^sub>0 (A \\<or>\\<^sub>F B))\\<^sub>S\\<^sub>F\\<^sub>M \"\n    by (simp add: AderivesA D_IL2_b Fdiam0_L Fdiam0_R Id_fa Or_R W_1R)\n  show ?thesis\n    using C_R Or_L f1 f2 by blast\nqed\n  \nlemma c10_f: \"\\<turnstile>d (a \\<rhd>\\<^sub>0 (A \\<or>\\<^sub>F B))\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a \\<triangle>\\<^sub>0 \\<top>)\\<^sub>S\\<^sub>F\\<^sub>M \\<rightarrow>\\<^sub>S ((a \\<triangle>\\<^sub>0 A) \\<or>\\<^sub>F (a \\<triangle>\\<^sub>0 B))\\<^sub>S\\<^sub>F\\<^sub>M\"\nsledgehammer\nproof - \n  have \"\\<turnstile>d (a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangle>\\<^sub>0\\<^sub>S (A \\<or>\\<^sub>F B)\\<^sub>S\\<^sub>F\\<^sub>M  \\<turnstile>\\<^sub>F\\<^sub>M ((a \\<triangle>\\<^sub>0 A) \\<or>\\<^sub>F (a \\<triangle>\\<^sub>0 B))\\<^sub>S\\<^sub>F\\<^sub>M \"\n    by (simp add: AderivesA DH_fdiam0_b DH_fdiam0_f Fdiam0_R Id_fa Mon_bbox0 Or_L Or_R)\n  then show ?thesis\n    by (simp add: DH_bdiam0_b DH_fdiam0_b DH_fdiam0_f D_IR1_b D_IR1_f E_L FS_bbox0 Fbox0_L Fdiam0_L W_2L derivable.intros(3))\nqed\n\nlemma c10_b: \"\\<turnstile>d (a \\<triangle>\\<^sub>0 \\<top>)\\<^sub>S\\<^sub>F\\<^sub>M \\<rightarrow>\\<^sub>S ((a \\<triangle>\\<^sub>0 A) \\<or>\\<^sub>F (a \\<triangle>\\<^sub>0 B))\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a \\<rhd>\\<^sub>0 (A \\<or>\\<^sub>F B))\\<^sub>S\\<^sub>F\\<^sub>M\"\nby (meson DH_bdiam0_f DH_fdiam0_f FS_bdiam0 Fbox0_R Fdiam0_R IW_L Id_fa Top_R W_2R)\n\nlemma c11_f: \"\\<turnstile>d (a \\<triangle>\\<^sub>0 (A \\<rightarrow>\\<^sub>F B))\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M ((a \\<triangle>\\<^sub>0 \\<top>) \\<and>\\<^sub>F ((a \\<triangle>\\<^sub>0 A)  \\<rightarrow>\\<^sub>F (a \\<triangle>\\<^sub>0 B)))\\<^sub>S\\<^sub>F\\<^sub>M\"\nproof - \n  have \"\\<turnstile>d (a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangle>\\<^sub>0\\<^sub>S (A \\<rightarrow>\\<^sub>F B)\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (((a \\<triangle>\\<^sub>0 A)  \\<rightarrow>\\<^sub>F (a \\<triangle>\\<^sub>0 B)))\\<^sub>S\\<^sub>F\\<^sub>M\"\n    by (simp add: AderivesA Balance Conj_fdiam0 DH_bdiam0_b D_IR1_b D_IR1_f Fdiam0_L Fdiam0_R Id_fa ImpR_L ImpR_R)\n  then show ?thesis\n    by (meson And_R C_L Fdiam0_L Fdiam0_R IW_L Id_fa Top_R)\nqed\n\nlemma c11_b: \"\\<turnstile>d ((a \\<triangle>\\<^sub>0 \\<top>) \\<and>\\<^sub>F ((a \\<triangle>\\<^sub>0 A) \\<rightarrow>\\<^sub>F (a \\<triangle>\\<^sub>0 B)))\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a \\<triangle>\\<^sub>0 (A \\<rightarrow>\\<^sub>F B))\\<^sub>S\\<^sub>F\\<^sub>M\"\nproof - \n  have \"\\<turnstile>d (a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangle>\\<^sub>0\\<^sub>S ((a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangleq>\\<^sub>0\\<^sub>S ((a \\<triangle>\\<^sub>0 A) \\<rightarrow>\\<^sub>F (a \\<triangle>\\<^sub>0 B))\\<^sub>S\\<^sub>F\\<^sub>M) \\<turnstile>\\<^sub>F\\<^sub>M (a \\<triangle>\\<^sub>0 (A \\<rightarrow>\\<^sub>F B))\\<^sub>S\\<^sub>F\\<^sub>M\"\n    by (simp add: AderivesA Balance DH_bdiam0_b FS_fbox0 Fdiam0_L Fdiam0_R Id_fa ImpR_L ImpR_R)\n  then show ?thesis\n    by (simp add: And_L DH_fdiam0_b DH_fdiam0_f D_IR1_b E_L FS_bbox0 Fdiam0_L W_2L)\nqed\n\nlemma c12_f: \"\\<turnstile>d (a \\<rhd>\\<^sub>0 (A \\<rightarrow>\\<^sub>F B))\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M ((a \\<triangle>\\<^sub>0 A) \\<rightarrow>\\<^sub>F (a \\<triangle>\\<^sub>0 B))\\<^sub>S\\<^sub>F\\<^sub>M\"\nproof -\n  have \"\\<turnstile>d (a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangleq>\\<^sub>0\\<^sub>S (a \\<rhd>\\<^sub>0 (A \\<rightarrow>\\<^sub>F B))\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a)\\<^sub>S\\<^sub>F\\<^sub>A \\<unrhd>\\<^sub>0\\<^sub>S (((a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangle>\\<^sub>0\\<^sub>S (A)\\<^sub>S\\<^sub>F\\<^sub>M) \\<rightarrow>\\<^sub>S (a \\<triangle>\\<^sub>0 B)\\<^sub>S\\<^sub>F\\<^sub>M)\"\n    by (simp add: AderivesA Balance DH_bdiam0_b DH_fdiam0_f FS_bbox0 Fbox0_L Fdiam0_R Id_fa ImpR_L)\n  then show ?thesis\n    by (simp add: Conj_fdiam0 DH_fdiam0_b D_IR1_b D_IR1_f E_L Fdiam0_L ImpR_R Mon_fdiam0)\nqed\n\nlemma c12_b: \"\\<turnstile>d ((a \\<triangle>\\<^sub>0 A) \\<rightarrow>\\<^sub>F (a \\<triangle>\\<^sub>0 B))\\<^sub>S\\<^sub>F\\<^sub>M  \\<turnstile>\\<^sub>F\\<^sub>M (a \\<rhd>\\<^sub>0 (A \\<rightarrow>\\<^sub>F B))\\<^sub>S\\<^sub>F\\<^sub>M\"\nby (simp add: AderivesA Balance DH_bdiam0_b DH_bdiam0_f FS_fbox0 Fbox0_R Fdiam0_L Fdiam0_R Id_fa ImpR_L ImpR_R)\n\nlemma c13: \"\\<turnstile>d ((a \\<triangle>\\<^sub>0 \\<top>) \\<and>\\<^sub>F (ag \\<triangle>\\<^sub>2 ((ag \\<triangleq>\\<^sub>3 a) \\<triangle>\\<^sub>1 A)))\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a \\<triangle>\\<^sub>0 (ag \\<triangle>\\<^sub>2 A))\\<^sub>S\\<^sub>F\\<^sub>M \"\nproof - \n  have \"\\<turnstile>d (A)\\<^sub>S\\<^sub>F\\<^sub>M  \\<turnstile>\\<^sub>F\\<^sub>M (ag)\\<^sub>S\\<^sub>A\\<^sub>G \\<unrhd>\\<^sub>2\\<^sub>S ((a)\\<^sub>S\\<^sub>F\\<^sub>A \\<unrhd>\\<^sub>0\\<^sub>S (a \\<triangle>\\<^sub>0 ( ag \\<triangle>\\<^sub>2 A))\\<^sub>S\\<^sub>F\\<^sub>M)\"\n    by (simp add: AderivesA DH_fdiam0_f DH_fdiam2_f Fdiam0_R Fdiam2_R Id_ag Id_fa)\n  then have \"\\<turnstile>d ((ag \\<triangleq>\\<^sub>3 a) \\<triangle>\\<^sub>1 A)\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (ag)\\<^sub>S\\<^sub>A\\<^sub>G \\<unrhd>\\<^sub>2\\<^sub>S (((a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangle>\\<^sub>0\\<^sub>S I\\<^sub>S) \\<rightarrow>\\<^sub>S (a \\<triangle>\\<^sub>0 (ag \\<triangle>\\<^sub>2 A))\\<^sub>S\\<^sub>F\\<^sub>M)\"\n    using Bdiam3_L DH_bla1_b DH_bla1_f DH_fdiam1_b Fdiam1_L Swapin_R by blast\n  then show ?thesis\n    by (meson And_L DH_fdiam0_b DH_fdiam0_f DH_fdiam2_b D_IL1_b D_IL1_f D_IR1_b Fdiam0_L Fdiam2_L IW_L)\nqed\n\nlemma c14: \"\\<turnstile>d (a \\<rhd>\\<^sub>0 (ag \\<rhd>\\<^sub>2 A))\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M ((a \\<triangle>\\<^sub>0 \\<top>) \\<rightarrow>\\<^sub>F (ag \\<rhd>\\<^sub>2 ((ag \\<triangleq>\\<^sub>3  a) \\<rhd>\\<^sub>1 A )))\\<^sub>S\\<^sub>F\\<^sub>M\"\nproof - \n  have \"\\<turnstile>d ((ag)\\<^sub>S\\<^sub>A\\<^sub>G \\<triangleq>\\<^sub>3\\<^sub>S (a)\\<^sub>S\\<^sub>F\\<^sub>A) \\<triangleq>\\<^sub>1\\<^sub>S ((ag)\\<^sub>S\\<^sub>A\\<^sub>G \\<triangleq>\\<^sub>2\\<^sub>S (((a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangle>\\<^sub>0\\<^sub>S I\\<^sub>S) ;\\<^sub>S (a \\<rhd>\\<^sub>0 (ag \\<rhd>\\<^sub>2 A))\\<^sub>S\\<^sub>F\\<^sub>M)) \\<turnstile>\\<^sub>F\\<^sub>M (A)\\<^sub>S\\<^sub>F\\<^sub>M\"\n    by (simp add: AderivesA DH_bdiam0_b DH_bdiam2_b Fbox0_L Fbox2_L Id_ag Id_fa Swapin_L)\n  then show ?thesis\n    by (meson Bdiam3_L DH_bdiam1_f DH_bdiam2_f DH_fdiam0_b DH_fdiam0_f DH_wla1_b DH_wla1_f D_IL1_b D_IL1_f D_IR1_f Fbox1_R Fbox2_R Fdiam0_L IW_L ImpR_R)\nqed\n\nlemma c15: \"\\<turnstile>d (a \\<triangle>\\<^sub>0 (ag \\<rhd>\\<^sub>2 A))\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M ((a \\<triangle>\\<^sub>0 \\<top>) \\<and>\\<^sub>F (ag \\<rhd>\\<^sub>2 ((ag \\<triangleq>\\<^sub>3 a) \\<rhd>\\<^sub>1 A )))\\<^sub>S\\<^sub>F\\<^sub>M\"\nproof -\n  have \"\\<turnstile>d (ag)\\<^sub>S\\<^sub>A\\<^sub>G \\<triangleq>\\<^sub>2\\<^sub>S ((a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangleq>\\<^sub>0\\<^sub>S ((a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangle>\\<^sub>0\\<^sub>S (ag \\<rhd>\\<^sub>2 A)\\<^sub>S\\<^sub>F\\<^sub>M)) \\<turnstile>\\<^sub>F\\<^sub>M (A)\\<^sub>S\\<^sub>F\\<^sub>M\"\n    by (simp add: AderivesA Balance DH_bdiam0_b DH_bdiam2_b Fbox2_L Id_ag)\n  then have \"\\<turnstile>d (ag \\<triangleq>\\<^sub>3 a)\\<^sub>S\\<^sub>A\\<^sub>C \\<triangleq>\\<^sub>1\\<^sub>S ((ag)\\<^sub>S\\<^sub>A\\<^sub>G \\<triangleq>\\<^sub>2\\<^sub>S (((a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangle>\\<^sub>0\\<^sub>S I\\<^sub>S) ;\\<^sub>S ((a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangle>\\<^sub>0\\<^sub>S (ag \\<rhd>\\<^sub>2 A)\\<^sub>S\\<^sub>F\\<^sub>M))) \\<turnstile>\\<^sub>F\\<^sub>M (A)\\<^sub>S\\<^sub>F\\<^sub>M\"\n    using Bdiam3_L DH_wla1_b DH_wla1_f Swapin_L \\<open>\\<turnstile>d ag \\<^sub>S\\<^sub>A\\<^sub>G \\<triangleq>\\<^sub>2\\<^sub>S (a \\<^sub>S\\<^sub>F\\<^sub>A \\<triangleq>\\<^sub>0\\<^sub>S (a \\<^sub>S\\<^sub>F\\<^sub>A \\<triangle>\\<^sub>0\\<^sub>S (ag \\<rhd>\\<^sub>2 A) \\<^sub>S\\<^sub>F\\<^sub>M)) \\<turnstile>\\<^sub>F\\<^sub>M A \\<^sub>S\\<^sub>F\\<^sub>M\\<close> by blast\n  then show ?thesis\n    by (metis And_R DH_bdiam1_f DH_bdiam2_f DH_fdiam0_b DH_fdiam0_f D_IL1_f Fbox1_R Fbox2_R Fdiam0_L Fdiam0_R I_1L_b Id_fa Mon_fdiam0 Top_R)\nqed\n\nlemma c16: \"\\<turnstile>d ((a \\<triangle>\\<^sub>0 \\<top>) \\<and>\\<^sub>F (ag \\<rhd>\\<^sub>2 ((ag \\<triangleq>\\<^sub>3 a) \\<rhd>\\<^sub>1 A)))\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (a \\<triangle>\\<^sub>0 (ag \\<rhd>\\<^sub>2 A))\\<^sub>S\\<^sub>F\\<^sub>M\"\nproof -\n  have \"\\<turnstile>d (a)\\<^sub>S\\<^sub>F\\<^sub>A \\<triangleq>\\<^sub>0\\<^sub>S (ag \\<rhd>\\<^sub>2 ((ag \\<triangleq>\\<^sub>3 a) \\<rhd>\\<^sub>1 A ))\\<^sub>S\\<^sub>F\\<^sub>M \\<turnstile>\\<^sub>F\\<^sub>M (ag \\<rhd>\\<^sub>2 A)\\<^sub>S\\<^sub>F\\<^sub>M\"\n    by (meson AderivesA Bdiam3_R DH_bdiam1_b DH_bdiam2_b DH_bdiam2_f Fbox1_L Fbox2_L Fbox2_R Id_ag Id_fa Swapout_L)\n  then show ?thesis\n    by (simp add: And_L DH_fdiam0_b DH_fdiam0_f D_IR1_b E_L FS_bbox0 Fdiam0_L Fdiam0_R Id_fa W_2L)\nqed", "meta": {"author": "NikolasTzimoulis", "repo": "MultitypeDEL", "sha": "073462621e6c6b94a97141c7fbc1554544f2d554", "save_path": "github-repos/isabelle/NikolasTzimoulis-MultitypeDEL", "path": "github-repos/isabelle/NikolasTzimoulis-MultitypeDEL/MultitypeDEL-073462621e6c6b94a97141c7fbc1554544f2d554/MDEAK_examples_completeness.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926666143433998, "lm_q2_score": 0.45713671682749485, "lm_q1q2_score": 0.2709296702542089}}
{"text": "(*  Title:      ZF/UNITY/ClientImpl.thy\n    Author:     Sidi O Ehmety, Cambridge University Computer Laboratory\n    Copyright   2002  University of Cambridge\n\nDistributed Resource Management System:  Client Implementation.\n*)\n\ntheory ClientImpl imports AllocBase Guar begin\n\nabbreviation \"ask \\<equiv> Var(Nil)\" (* input history:  tokens requested *)\nabbreviation \"giv \\<equiv> Var([0])\" (* output history: tokens granted *)\nabbreviation \"rel \\<equiv> Var([1])\" (* input history: tokens released *)\nabbreviation \"tok \\<equiv> Var([2])\" (* the number of available tokens *)\n\naxiomatization where\n  type_assumes:\n  \"type_of(ask) = list(tokbag) \\<and> type_of(giv) = list(tokbag) \\<and>\n   type_of(rel) = list(tokbag) \\<and> type_of(tok) = nat\" and\n  default_val_assumes:\n  \"default_val(ask) = Nil \\<and> default_val(giv) = Nil \\<and>\n   default_val(rel) = Nil \\<and> default_val(tok) = 0\"\n\n\n(*Array indexing is translated to list indexing as A[n] \\<equiv> nth(n-1,A). *)\n\ndefinition\n (** Release some client_tokens **)\n    \"client_rel_act \\<equiv>\n     {\\<langle>s,t\\<rangle> \\<in> state*state.\n      \\<exists>nrel \\<in> nat. nrel = length(s`rel) \\<and>\n                   t = s(rel:=(s`rel)@[nth(nrel, s`giv)]) \\<and>\n                   nrel < length(s`giv) \\<and>\n                   nth(nrel, s`ask) \\<le> nth(nrel, s`giv)}\"\n\n  (** Choose a new token requirement **)\n  (** Including t=s suppresses fairness, allowing the non-trivial part\n      of the action to be ignored **)\ndefinition\n  \"client_tok_act \\<equiv> {\\<langle>s,t\\<rangle> \\<in> state*state. t=s |\n                     t = s(tok:=succ(s`tok mod NbT))}\"\n\ndefinition\n  \"client_ask_act \\<equiv> {\\<langle>s,t\\<rangle> \\<in> state*state. t=s | (t=s(ask:=s`ask@[s`tok]))}\"\n\ndefinition\n  \"client_prog \\<equiv>\n   mk_program({s \\<in> state. s`tok \\<le> NbT \\<and> s`giv = Nil \\<and>\n                       s`ask = Nil \\<and> s`rel = Nil},\n                    {client_rel_act, client_tok_act, client_ask_act},\n                   \\<Union>G \\<in> preserves(lift(rel)) Int\n                         preserves(lift(ask)) Int\n                         preserves(lift(tok)).  Acts(G))\"\n\n\ndeclare type_assumes [simp] default_val_assumes [simp]\n(* This part should be automated *)\n\nlemma ask_value_type [simp,TC]: \"s \\<in> state \\<Longrightarrow> s`ask \\<in> list(nat)\"\n  unfolding state_def\napply (drule_tac a = ask in apply_type, auto)\ndone\n\nlemma giv_value_type [simp,TC]: \"s \\<in> state \\<Longrightarrow> s`giv \\<in> list(nat)\"\n  unfolding state_def\napply (drule_tac a = giv in apply_type, auto)\ndone\n\nlemma rel_value_type [simp,TC]: \"s \\<in> state \\<Longrightarrow> s`rel \\<in> list(nat)\"\n  unfolding state_def\napply (drule_tac a = rel in apply_type, auto)\ndone\n\nlemma tok_value_type [simp,TC]: \"s \\<in> state \\<Longrightarrow> s`tok \\<in> nat\"\n  unfolding state_def\napply (drule_tac a = tok in apply_type, auto)\ndone\n\n(** The Client Program **)\n\nlemma client_type [simp,TC]: \"client_prog \\<in> program\"\n  unfolding client_prog_def\napply (simp (no_asm))\ndone\n\ndeclare client_prog_def [THEN def_prg_Init, simp]\ndeclare client_prog_def [THEN def_prg_AllowedActs, simp]\ndeclare client_prog_def [program]\n\ndeclare  client_rel_act_def [THEN def_act_simp, simp]\ndeclare  client_tok_act_def [THEN def_act_simp, simp]\ndeclare  client_ask_act_def [THEN def_act_simp, simp]\n\nlemma client_prog_ok_iff:\n  \"\\<forall>G \\<in> program. (client_prog ok G) \\<longleftrightarrow>\n   (G \\<in> preserves(lift(rel)) \\<and> G \\<in> preserves(lift(ask)) \\<and>\n    G \\<in> preserves(lift(tok)) \\<and>  client_prog \\<in> Allowed(G))\"\nby (auto simp add: ok_iff_Allowed client_prog_def [THEN def_prg_Allowed])\n\nlemma client_prog_preserves:\n    \"client_prog:(\\<Inter>x \\<in> var-{ask, rel, tok}. preserves(lift(x)))\"\napply (rule Inter_var_DiffI, force)\napply (rule ballI)\napply (rule preservesI, safety, auto)\ndone\n\n\nlemma preserves_lift_imp_stable:\n     \"G \\<in> preserves(lift(ff)) \\<Longrightarrow> G \\<in> stable({s \\<in> state. P(s`ff)})\"\napply (drule preserves_imp_stable)\napply (simp add: lift_def)\ndone\n\nlemma preserves_imp_prefix:\n     \"G \\<in> preserves(lift(ff))\n      \\<Longrightarrow> G \\<in> stable({s \\<in> state. \\<langle>k, s`ff\\<rangle> \\<in> prefix(nat)})\"\nby (erule preserves_lift_imp_stable)\n\n(*Safety property 1 \\<in> ask, rel are increasing: (24) *)\nlemma client_prog_Increasing_ask_rel:\n\"client_prog: program guarantees Incr(lift(ask)) \\<inter> Incr(lift(rel))\"\n  unfolding guar_def\napply (auto intro!: increasing_imp_Increasing\n            simp add: client_prog_ok_iff Increasing.increasing_def preserves_imp_prefix)\napply (safety, force, force)+\ndone\n\ndeclare nth_append [simp] append_one_prefix [simp]\n\nlemma NbT_pos2: \"0<NbT\"\napply (cut_tac NbT_pos)\napply (rule Ord_0_lt, auto)\ndone\n\n(*Safety property 2 \\<in> the client never requests too many tokens.\nWith no Substitution Axiom, we must prove the two invariants simultaneously. *)\n\nlemma ask_Bounded_lemma:\n\"\\<lbrakk>client_prog ok G; G \\<in> program\\<rbrakk>\n      \\<Longrightarrow> client_prog \\<squnion> G \\<in>\n              Always({s \\<in> state. s`tok \\<le> NbT}  \\<inter>\n                      {s \\<in> state. \\<forall>elt \\<in> set_of_list(s`ask). elt \\<le> NbT})\"\napply (rotate_tac -1)\napply (auto simp add: client_prog_ok_iff)\napply (rule invariantI [THEN stable_Join_Always2], force)\n prefer 2\n apply (fast intro: stable_Int preserves_lift_imp_stable, safety)\napply (auto dest: ActsD)\napply (cut_tac NbT_pos)\napply (rule NbT_pos2 [THEN mod_less_divisor])\napply (auto dest: ActsD preserves_imp_eq simp add: set_of_list_append)\ndone\n\n(* Export version, with no mention of tok in the postcondition, but\n  unfortunately tok must be declared local.*)\nlemma client_prog_ask_Bounded:\n    \"client_prog \\<in> program guarantees\n                   Always({s \\<in> state. \\<forall>elt \\<in> set_of_list(s`ask). elt \\<le> NbT})\"\napply (rule guaranteesI)\napply (erule ask_Bounded_lemma [THEN Always_weaken], auto)\ndone\n\n(*** Towards proving the liveness property ***)\n\nlemma client_prog_stable_rel_le_giv:\n    \"client_prog \\<in> stable({s \\<in> state. <s`rel, s`giv> \\<in> prefix(nat)})\"\nby (safety, auto)\n\nlemma client_prog_Join_Stable_rel_le_giv:\n\"\\<lbrakk>client_prog \\<squnion> G \\<in> Incr(lift(giv)); G \\<in> preserves(lift(rel))\\<rbrakk>\n    \\<Longrightarrow> client_prog \\<squnion> G \\<in> Stable({s \\<in> state. <s`rel, s`giv> \\<in> prefix(nat)})\"\napply (rule client_prog_stable_rel_le_giv [THEN Increasing_preserves_Stable])\napply (auto simp add: lift_def)\ndone\n\nlemma client_prog_Join_Always_rel_le_giv:\n     \"\\<lbrakk>client_prog \\<squnion> G \\<in> Incr(lift(giv)); G \\<in> preserves(lift(rel))\\<rbrakk>\n    \\<Longrightarrow> client_prog \\<squnion> G  \\<in> Always({s \\<in> state. <s`rel, s`giv> \\<in> prefix(nat)})\"\nby (force intro!: AlwaysI client_prog_Join_Stable_rel_le_giv)\n\nlemma def_act_eq:\n     \"A \\<equiv> {\\<langle>s, t\\<rangle> \\<in> state*state. P(s, t)} \\<Longrightarrow> A={\\<langle>s, t\\<rangle> \\<in> state*state. P(s, t)}\"\nby auto\n\nlemma act_subset: \"A={\\<langle>s,t\\<rangle> \\<in> state*state. P(s, t)} \\<Longrightarrow> A<=state*state\"\nby auto\n\nlemma transient_lemma:\n\"client_prog \\<in>\n  transient({s \\<in> state. s`rel = k \\<and> \\<langle>k, h\\<rangle> \\<in> strict_prefix(nat)\n   \\<and> <h, s`giv> \\<in> prefix(nat) \\<and> h pfixGe s`ask})\"\napply (rule_tac act = client_rel_act in transientI)\napply (simp (no_asm) add: client_prog_def [THEN def_prg_Acts])\napply (simp (no_asm) add: client_rel_act_def [THEN def_act_eq, THEN act_subset])\napply (auto simp add: client_prog_def [THEN def_prg_Acts] domain_def)\napply (rule ReplaceI)\napply (rule_tac x = \"x (rel:= x`rel @ [nth (length (x`rel), x`giv) ]) \" in exI)\napply (auto intro!: state_update_type app_type length_type nth_type, auto)\napply (blast intro: lt_trans2 prefix_length_le strict_prefix_length_lt)\napply (blast intro: lt_trans2 prefix_length_le strict_prefix_length_lt)\napply (simp (no_asm_use) add: gen_prefix_iff_nth)\napply (subgoal_tac \"h \\<in> list(nat)\")\n apply (simp_all (no_asm_simp) add: prefix_type [THEN subsetD, THEN SigmaD1])\napply (auto simp add: prefix_def Ge_def)\napply (drule strict_prefix_length_lt)\napply (drule_tac x = \"length (x`rel) \" in spec)\napply auto\napply (simp (no_asm_use) add: gen_prefix_iff_nth)\napply (auto simp add: id_def lam_def)\ndone\n\nlemma strict_prefix_is_prefix:\n    \"\\<langle>xs, ys\\<rangle> \\<in> strict_prefix(A) \\<longleftrightarrow>  \\<langle>xs, ys\\<rangle> \\<in> prefix(A) \\<and> xs\\<noteq>ys\"\n  unfolding strict_prefix_def id_def lam_def\napply (auto dest: prefix_type [THEN subsetD])\ndone\n\nlemma induct_lemma:\n\"\\<lbrakk>client_prog \\<squnion> G \\<in> Incr(lift(giv)); client_prog ok G; G \\<in> program\\<rbrakk>\n  \\<Longrightarrow> client_prog \\<squnion> G \\<in>\n  {s \\<in> state. s`rel = k \\<and> \\<langle>k,h\\<rangle> \\<in> strict_prefix(nat)\n   \\<and> <h, s`giv> \\<in> prefix(nat) \\<and> h pfixGe s`ask}\n        \\<longmapsto>w {s \\<in> state. <k, s`rel> \\<in> strict_prefix(nat)\n                          \\<and> <s`rel, s`giv> \\<in> prefix(nat) \\<and>\n                                  <h, s`giv> \\<in> prefix(nat) \\<and>\n                h pfixGe s`ask}\"\napply (rule single_LeadsTo_I)\n prefer 2 apply simp\napply (frule client_prog_Increasing_ask_rel [THEN guaranteesD])\napply (rotate_tac [3] 2)\napply (auto simp add: client_prog_ok_iff)\napply (rule transient_lemma [THEN Join_transient_I1, THEN transient_imp_leadsTo, THEN leadsTo_imp_LeadsTo, THEN PSP_Stable, THEN LeadsTo_weaken])\napply (rule Stable_Int [THEN Stable_Int, THEN Stable_Int])\napply (erule_tac f = \"lift (giv) \" and a = \"s`giv\" in Increasing_imp_Stable)\napply (simp (no_asm_simp))\napply (erule_tac f = \"lift (ask) \" and a = \"s`ask\" in Increasing_imp_Stable)\napply (simp (no_asm_simp))\napply (erule_tac f = \"lift (rel) \" and a = \"s`rel\" in Increasing_imp_Stable)\napply (simp (no_asm_simp))\napply (erule client_prog_Join_Stable_rel_le_giv, blast, simp_all)\n prefer 2\n apply (blast intro: sym strict_prefix_is_prefix [THEN iffD2] prefix_trans prefix_imp_pfixGe pfixGe_trans)\napply (auto intro: strict_prefix_is_prefix [THEN iffD1, THEN conjunct1]\n                   prefix_trans)\ndone\n\nlemma rel_progress_lemma:\n\"\\<lbrakk>client_prog \\<squnion> G  \\<in> Incr(lift(giv)); client_prog ok G; G \\<in> program\\<rbrakk>\n  \\<Longrightarrow> client_prog \\<squnion> G  \\<in>\n     {s \\<in> state. <s`rel, h> \\<in> strict_prefix(nat)\n           \\<and> <h, s`giv> \\<in> prefix(nat) \\<and> h pfixGe s`ask}\n                      \\<longmapsto>w {s \\<in> state. <h, s`rel> \\<in> prefix(nat)}\"\napply (rule_tac f = \"\\<lambda>x \\<in> state. length(h) #- length(x`rel)\"\n       in LessThan_induct)\napply (auto simp add: vimage_def)\n prefer 2 apply (force simp add: lam_def)\napply (rule single_LeadsTo_I)\n prefer 2 apply simp\napply (subgoal_tac \"h \\<in> list(nat)\")\n prefer 2 apply (blast dest: prefix_type [THEN subsetD])\napply (rule induct_lemma [THEN LeadsTo_weaken])\n    apply (simp add: length_type lam_def)\napply (auto intro: strict_prefix_is_prefix [THEN iffD2]\n            dest: common_prefix_linear  prefix_type [THEN subsetD])\napply (erule swap)\napply (rule imageI)\n apply (force dest!: simp add: lam_def)\napply (simp add: length_type lam_def, clarify)\napply (drule strict_prefix_length_lt)+\napply (drule less_imp_succ_add, simp)+\napply clarify\napply simp\napply (erule diff_le_self [THEN ltD])\ndone\n\nlemma progress_lemma:\n\"\\<lbrakk>client_prog \\<squnion> G \\<in> Incr(lift(giv)); client_prog ok G; G \\<in> program\\<rbrakk>\n \\<Longrightarrow> client_prog \\<squnion> G\n       \\<in> {s \\<in> state. <h, s`giv> \\<in> prefix(nat) \\<and> h pfixGe s`ask}\n         \\<longmapsto>w  {s \\<in> state. <h, s`rel> \\<in> prefix(nat)}\"\napply (rule client_prog_Join_Always_rel_le_giv [THEN Always_LeadsToI],\n       assumption)\napply (force simp add: client_prog_ok_iff)\napply (rule LeadsTo_weaken_L)\napply (rule LeadsTo_Un [OF rel_progress_lemma\n                           subset_refl [THEN subset_imp_LeadsTo]])\napply (auto intro: strict_prefix_is_prefix [THEN iffD2]\n            dest: common_prefix_linear prefix_type [THEN subsetD])\ndone\n\n(*Progress property: all tokens that are given will be released*)\nlemma client_prog_progress:\n\"client_prog \\<in> Incr(lift(giv))  guarantees\n      (\\<Inter>h \\<in> list(nat). {s \\<in> state. <h, s`giv> \\<in> prefix(nat) \\<and>\n              h pfixGe s`ask} \\<longmapsto>w {s \\<in> state. <h, s`rel> \\<in> prefix(nat)})\"\napply (rule guaranteesI)\napply (blast intro: progress_lemma, auto)\ndone\n\nlemma client_prog_Allowed:\n     \"Allowed(client_prog) =\n      preserves(lift(rel)) \\<inter> preserves(lift(ask)) \\<inter> preserves(lift(tok))\"\napply (cut_tac v = \"lift (ask)\" in preserves_type)\napply (auto simp add: Allowed_def client_prog_def [THEN def_prg_Allowed]\n                      cons_Int_distrib safety_prop_Acts_iff)\ndone\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/ZF/UNITY/ClientImpl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926665999540698, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.2709296636763177}}
{"text": "section{*HBD Translation Algorithms that use Feedback Composition*}\n\n(* Was: AlgorithmFeedback.thy *)\n\ntheory HBDTranslationsUsingFeedback imports HBDTranslationProperties \"Refinement\"\nbegin\n  \ncontext BaseOperationVars\nbegin\n\n  (*The nondeterministic Algorithm that uses the feedback, serial, and parallel operations*)\n  definition \"TranslateHBD = \n    while_stm (\\<lambda> As . length As > 1)(\n      [:As \\<leadsto> As' . \\<exists> Bs Cs . 1 < length Bs \\<and> perm As (Bs @ Cs) \\<and> As' = FB (Parallel_list Bs) # Cs:]\n      \\<sqinter>\n      [:As \\<leadsto> As' . \\<exists> A B Bs . perm As (A # B # Bs) \\<and> As' = (FB (FB A ;; FB B)) # Bs:]\n     )\n   o [-(\\<lambda> As . FB(As ! 0))-]\"\n\n\n  \n\n  definition \"invariant As_init n As = (length As = n \\<and> io_distinct As \\<and>  in_out_equiv (FB (Parallel_list As)) (FB (Parallel_list As_init)) \\<and> n \\<ge> 1)\"\n\n  lemma io_diagram_Parallel_list: \"\\<forall> A \\<in> set As . io_diagram A \\<Longrightarrow> distinct (concat (map Out As)) \\<Longrightarrow> io_diagram (Parallel_list As)\"\n    proof (induction As)\n    case Nil\n    from Nil show ?case by simp\n    next\n    case (Cons A As)\n    show ?case\n      apply (simp)\n      apply (rule io_diagram_Parallel)\n      using Cons(2) apply simp\n      using Cons apply simp\n      using Cons(3) apply auto\n      by (simp add: Out_Parallel)\n    qed\n\n  lemma io_diagram_Parallel_list_a: \"io_distinct As \\<Longrightarrow> io_diagram (Parallel_list As)\"\n    apply (rule_tac io_diagram_Parallel_list)\n    by (simp_all add: io_distinct_def)\n\n\n  thm Parallel_list_cons\n\n  thm Parallel_assoc_gen\n\n  thm ParallelId_left\n  thm io_diagram_Parallel_list\n\nlemma Parallel_list_append: \"\\<forall> A \\<in> set As . io_diagram A \\<Longrightarrow> distinct (concat (map Out As)) \\<Longrightarrow> \\<forall> A \\<in> set Bs . io_diagram A \n      \\<Longrightarrow> distinct (concat (map Out Bs))\\<Longrightarrow> \n      Parallel_list (As @ Bs) = Parallel_list As ||| Parallel_list Bs\"\n    proof (induction As)\n      case Nil\n      from Nil show ?case\n        apply (simp )\n        apply (subst ParallelId_left, simp_all)\n        by (rule io_diagram_Parallel_list, simp_all)\n      next\n      case (Cons A As)\n      from Cons show ?case\n        apply simp\n        apply (subst Parallel_assoc_gen, simp_all)\n        apply (rule io_diagram_Parallel_list, simp_all)\n        by (rule io_diagram_Parallel_list, simp_all)\n    qed\n       \n  primrec sequence :: \"nat \\<Rightarrow> nat list\" where\n    \"sequence 0 = []\" |\n    \"sequence (Suc n) = sequence n @ [n]\"\n\n  lemma \"sequence (Suc (Suc 0)) = [0,1]\"\n    by auto\n\n  lemma in_out_equiv_io_diagram[simp]: \"in_out_equiv A B \\<Longrightarrow> io_diagram B \\<Longrightarrow> io_diagram A\"\n    apply (unfold io_diagram_def)\n    apply (simp add:  in_out_equiv_def, safe)\n    using dist_perm perm_sym apply blast\n    using dist_perm perm_sym by blast\n\n  thm comp_parallel_distrib\n\n  lemma in_out_equiv_Parallel_cong_right: \"io_diagram A \\<Longrightarrow> io_diagram C \\<Longrightarrow> set (Out A) \\<inter> set (Out B) = {} \\<Longrightarrow> in_out_equiv B C \n    \\<Longrightarrow> in_out_equiv (A ||| B) (A ||| C)\"\n    proof -\n      assume \"io_diagram A\"\n      from this have [simp]: \"TVs (In A) = TI (Trs A)\" and [simp]: \" TVs (Out A) = TO (Trs A)\" and [simp]: \"distinct (In A)\" and [simp]: \"distinct (Out A)\"\n        by (unfold io_diagram_def, simp_all)\n      assume A: \"io_diagram C\"\n      from this have [simp]: \"TVs (In C) = TI (Trs C)\" and [simp]: \" TVs (Out C) = TO (Trs C)\" and [simp]: \"distinct (In C)\" and [simp]: \"distinct (Out C)\"\n        by (unfold io_diagram_def, simp_all)\n      assume \"set (Out A) \\<inter> set (Out B) = {}\"\n      assume B: \"in_out_equiv B C\"\n      from this have [simp]: \"perm (In B) (In C)\" and [simp]: \"perm (Out B) (Out C)\" and [simp]: \"Trs B = [In B \\<leadsto> In C] oo Trs C oo [Out C \\<leadsto> Out B]\"\n        by (simp_all add: in_out_equiv_def)\n\n      from A and B have \"io_diagram B\"\n        by simp\n      from this have [simp]: \"TVs (In B) = TI (Trs B)\" and [simp]: \" TVs (Out B) = TO (Trs B)\" and [simp]: \"distinct (In B)\" and [simp]: \"distinct (Out B)\"\n        by (unfold io_diagram_def, simp_all)\n\n      have [simp]: \"[In A \\<oplus> In B \\<leadsto> In A \\<oplus> In C] oo ([In A \\<oplus> In C \\<leadsto> In A @ In C] oo (parallel (Trs A) (Trs C))) oo [Out A @ Out C \\<leadsto> Out A @ Out B] = \n        [In A \\<oplus> In B \\<leadsto> In A \\<oplus> In C] oo [In A \\<oplus> In C \\<leadsto> In A @ In C] oo parallel (Trs A) (Trs C) oo [Out A @ Out C \\<leadsto> Out A @ Out B]\"\n        by (simp add: comp_assoc)\n      have [simp]: \"... = [In A \\<oplus> In B \\<leadsto> In A @ In C] oo parallel (Trs A) (Trs C) oo [Out A @ Out C \\<leadsto> Out A @ Out B]\"\n         by (subst switch_comp, simp_all)\n      have \"[In A \\<oplus> In B \\<leadsto> In A @ In B] oo parallel (Trs A) ([In B \\<leadsto> In C] oo Trs C oo [Out C \\<leadsto> Out B]) \n          = [In A \\<oplus> In B \\<leadsto> In A @ In B] oo parallel ([In A \\<leadsto> In A] oo Trs A oo [Out A \\<leadsto> Out A]) ([In B \\<leadsto> In C] oo Trs C oo [Out C \\<leadsto> Out B])\"\n        by simp\n      also have \"... = [In A \\<oplus> In B \\<leadsto> In A @ In B] oo (\n                    parallel [In A \\<leadsto> In A] [In B \\<leadsto> In C] oo parallel (Trs A) (Trs C) oo parallel [Out A \\<leadsto> Out A] [Out C \\<leadsto> Out B])\"\n        apply (subst comp_parallel_distrib [THEN sym])\n        apply simp_all [2]\n        apply (subst comp_parallel_distrib [THEN sym])\n        by simp_all\n      also have \" ... =  [In A \\<oplus> In B \\<leadsto> In A @ In B] oo (\n                   parallel [In A \\<leadsto> In A] [In B \\<leadsto> In C] oo parallel (Trs A) (Trs C) oo[Out A @ Out C \\<leadsto> Out A @ Out B])\"\n        by (metis \\<open>distinct (Out A)\\<close> \\<open>distinct (Out C)\\<close> \\<open>perm (Out B) (Out C)\\<close> \\<open>set (Out A) \\<inter> set (Out B) = {}\\<close> distinct_append order_refl par_switch perm_set_eq)\n      also have \"... = [In A \\<oplus> In B \\<leadsto> In A @ In B] oo parallel [In A \\<leadsto> In A] [In B \\<leadsto> In C] \n        oo parallel (Trs A) (Trs C) oo[Out A @ Out C \\<leadsto> Out A @ Out B]\"\n        apply (subst comp_assoc, simp_all)\n        apply (subst comp_assoc)\n        apply (subst TI_par)\n        using TI_switch TO_switch TVs_append apply presburger\n        apply simp\n        apply (subst comp_assoc)\n        using TI_comp TI_par TI_switch TO_par TO_switch TVs_append \\<open>TVs (In A) = TI (Trs A)\\<close> \\<open>TVs (In C) = TI (Trs C)\\<close> apply presburger\n        apply simp\n        by (subst comp_assoc, simp_all)\n\n     also have \"... = [In A \\<oplus> In B \\<leadsto> In A @ In C] oo parallel (Trs A) (Trs C) oo[Out A @ Out C \\<leadsto> Out A @ Out B]\"\n      by (simp add: Trs_Parallel_list_aux_b)\n        \n      finally show \"in_out_equiv (A ||| B) (A ||| C)\"\n        by (simp add: in_out_equiv_def Parallel_def)\n    qed\n\n  lemma perm_map: \"perm x y \\<Longrightarrow> perm (map f x) (map f y)\"\n    by (simp add: perm_mset)\n\n\n  lemma distinct_concat_perm: \"\\<And> Y . distinct (concat X) \\<Longrightarrow> perm X Y \\<Longrightarrow> distinct (concat Y)\"\n    proof (induction X)\n      case Nil\n      from Nil show ?case by simp\n      next\n      case (Cons a X)\n      from Cons(3) obtain A B where [simp]: \"Y = A @ a #B\" and [simp]: \"perm X (A @ B)\"\n        by (simp add: split_perm, blast)\n      from Cons(1) have \"distinct (concat X) \\<Longrightarrow> perm X (A @ B) \\<Longrightarrow> distinct (concat (A @ B)) \"\n        by blast\n      from this and Cons(2) have A: \"distinct (concat (A @ B))\" by simp\n      from Cons(2) have \"distinct (concat X)\" by simp\n      from Cons(2) have [simp]: \"distinct a\" by simp\n      have \"set (X) = set (A @ B)\"\n        using \\<open>perm X (A @ B)\\<close> perm_set_eq by blast\n      from this and Cons(2) show ?case\n        using A apply simp\n        by auto\n    qed\n\n  lemma distinct_Par_equiv_a: \"\\<And> Bs . \\<forall> A \\<in> set As . io_diagram A \\<Longrightarrow> distinct (concat (map Out As)) \\<Longrightarrow> perm As Bs \\<Longrightarrow>\n      in_out_equiv (Parallel_list As) (Parallel_list Bs)\"\n      \n    proof (induction As)\n      case Nil\n      from  \\<open>perm [] Bs\\<close> show ?case\n      apply (simp)\n      by (rule in_out_equiv_refl, simp)\n      next\n      case (Cons A As)\n      have \"A \\<in> set Bs\"\n        using Cons.prems(3) perm_set_eq by fastforce\n      from this obtain Cs Ds where A: \"Bs = Cs @ A # Ds\"\n        by (metis split_list)\n\n      have [simp]: \" perm As (Ds @ Cs)\"\n        using Cons(4) and A\n          by (simp add: perm_mset)\n\n        have [simp]: \"\\<forall> A \\<in> set Cs . io_diagram A\"\n          using A Cons.prems(1) Cons.prems(3) perm_set_eq by fastforce\n      have [simp]: \"\\<forall> A \\<in> set Ds . io_diagram A\"\n          using A Cons.prems(1) Cons.prems(3) perm_set_eq by fastforce\n      have B: \"distinct (concat (map Out Bs))\"\n        apply (rule distinct_concat_perm)\n        apply (rule  Cons(3))\n        apply (rule perm_map)\n        using Cons(4) by simp\n      from this and A have [simp]: \"distinct (concat (map Out Cs))\"\n        by simp\n      from B and A have [simp]: \"distinct (concat (map Out Ds))\"\n        by simp\n      have [simp]: \"io_diagram A\"\n        using Cons(2) by simp\n      from this have [simp]: \"distinct (Out A)\"\n        by (unfold io_diagram_def, simp)\n      have [simp]: \" io_diagram (Parallel_list Ds)\"\n        by (rule io_diagram_Parallel_list, simp_all)\n      have [simp]: \"io_diagram (Parallel_list Cs)\"\n        by (rule io_diagram_Parallel_list, simp_all)\n      have [simp]: \"set (Out A) \\<inter> set (Out (Parallel_list As)) = {}\"\n        using Cons(3) by (simp add: Out_Parallel)\n      have [simp]: \"\\<forall> A \\<in> set As . io_diagram A\"\n        using Cons(2) by simp\n      have [simp]:\"distinct (concat (map Out As))\"\n        using Cons(3) by simp\n\n      from B and A have [simp]: \"set (Out A) \\<inter> (\\<Union>a\\<in>set Ds. set (Out a)) = {}\"\n        by simp\n      have [simp]: \"set (Out A) \\<inter> set (Out (Parallel_list Ds)) = {}\"\n        by (simp add: Out_Parallel)\n\n      from B and A have [simp]: \"set (Out (Parallel_list Ds)) \\<inter> set (Out (Parallel_list Cs)) = {}\"\n        by (simp add: Out_Parallel, auto)\n\n      from B and A have [simp]: \"set (Out (Parallel_list Cs)) \\<inter> set (Out A) = {}\"\n        by (simp add: Out_Parallel)\n\n     from B and A have [simp]: \"set (Out (Parallel_list Cs)) \\<inter> set (Out (Parallel_list Ds)) = {}\"\n        by (simp add: Out_Parallel)\n\n     from B and A have [simp]:\"(set (Out A) \\<union> set (Out (Parallel_list Ds))) \\<inter> set (Out (Parallel_list Cs)) = {}\"\n        by (simp add: Out_Parallel, auto)\n      have [simp]:\"io_diagram (A ||| Parallel_list Ds)\"\n        by (rule io_diagram_Parallel, simp_all)\n      from Cons(1)\n        have \"in_out_equiv (Parallel_list As) (Parallel_list (Ds @ Cs))\"\n        by simp\n      from this have [simp]: \"in_out_equiv (Parallel_list As) (Parallel_list Ds ||| (Parallel_list Cs))\"\n        by (simp add: Parallel_list_append)\n      have [simp]:\"io_diagram (Parallel_list Ds ||| Parallel_list Cs)\"\n        by (rule io_diagram_Parallel, simp_all)\n      have [simp]: \"io_diagram (Parallel_list As)\"\n        by (rule io_diagram_Parallel_list, simp_all)\n      have [simp]: \"io_diagram (A ||| Parallel_list As)\"\n        by (rule io_diagram_Parallel, simp_all)\n      have [simp]: \"io_diagram (A ||| Parallel_list Ds ||| Parallel_list Cs)\"\n        by (rule io_diagram_Parallel, simp_all)\n      have [simp]: \"io_diagram (Parallel_list Cs ||| (A ||| Parallel_list Ds))\"\n        by (rule io_diagram_Parallel, simp_all)\n\n       from A show ?case\n        apply (simp_all add: Parallel_list_append)\n        apply (rule_tac B = \"(A ||| Parallel_list Ds) ||| Parallel_list Cs\" in in_out_equiv_tran, simp_all)\n        apply (subst Parallel_assoc_gen, simp_all)\n        apply (rule in_out_equiv_Parallel_cong_right, simp_all)\n        by (rule in_out_equiv_Parallel, simp_all)\n    qed\n\n  thm distinct_concat_perm\n  thm perm_map\n\n  lemma distinct_FB: \"distinct (In A) \\<Longrightarrow> distinct (In (FB A))\"\n    by (simp add: FB_def Let_def)\n\n  lemma io_distinct_FB_cat: \"io_distinct (A # Cs) \\<Longrightarrow> io_distinct (FB A # Cs)\"\n    apply (simp add: io_distinct_def)\n    apply safe\n    apply (simp_all add: FB_def Let_def set_diff) [4]\n    apply auto [2]\n    by (rule Type_ok_FB, simp)\n\n  lemma io_distinct_perm: \"io_distinct As \\<Longrightarrow> perm As Bs \\<Longrightarrow> io_distinct Bs\"\n    apply (simp add: io_distinct_def)\n    apply safe\n    apply (rule distinct_concat_perm)\n    apply (simp_all)\n    apply (rule perm_map, simp)\n    apply (rule_tac X = \"map Out As\" in distinct_concat_perm, simp_all)\n     apply (rule perm_map, simp)\n      using perm_set_eq by blast\n\n  lemma [simp]: \"distinct (concat X) \\<Longrightarrow> op_list [] (\\<oplus>) (X) = concat X\"\n    apply (induction X, simp_all)\n    by (simp add: addvars_distinct)\n\n  lemma [simp]: \"io_distinct As \\<Longrightarrow> perm As (Bs @ Cs) \\<Longrightarrow> io_distinct (FB (Parallel_list Bs) # Cs)\"\n    apply (rule io_distinct_FB_cat)\n    apply (drule_tac Bs = \"Bs @ Cs\" in io_distinct_perm, simp_all)\n    apply (simp add: io_distinct_def In_Parallel Out_Parallel)\n    apply safe\n    by (rule io_diagram_Parallel_list, simp_all)\n\n  lemma io_distinct_append_a: \"io_distinct As \\<Longrightarrow> perm As (Bs @ Cs) \\<Longrightarrow> io_distinct Bs\"\n    apply (drule_tac Bs = \"Bs @ Cs\" in io_distinct_perm, simp_all)\n    by (simp add: io_distinct_def)\n\n  lemma io_distinct_append_b: \"io_distinct As \\<Longrightarrow> perm As (Bs @ Cs) \\<Longrightarrow> io_distinct Cs\"\n    apply (drule_tac Bs = \"Bs @ Cs\" in io_distinct_perm, simp_all)\n    by (simp add: io_distinct_def)\n\n  lemma [simp]: \"io_distinct As \\<Longrightarrow> perm As (Bs @ Cs) \\<Longrightarrow> io_diagram (FB (FB (Parallel_list Bs) ||| Parallel_list Cs))\"\n    apply (rule Type_ok_FB)\n    apply (rule io_diagram_Parallel)\n    apply (rule Type_ok_FB)\n    apply (drule io_distinct_append_a, simp_all)\n    apply (simp add: io_diagram_Parallel_list_a)\n    apply (drule io_distinct_append_b, simp_all)\n    apply (simp add: io_diagram_Parallel_list_a)\n    apply (subgoal_tac \" set (Out ((Parallel_list Bs))) \\<inter> set (Out (Parallel_list Cs)) = {}\")\n    apply (subgoal_tac \"set (Out (FB (Parallel_list Bs))) \\<subseteq> set (Out ((Parallel_list Bs)))\")\n    apply auto [1]\n    apply (simp add: FB_def Let_def)\n    apply (simp add: Out_Parallel)\n    apply (drule io_distinct_perm, simp_all)\n    by (simp add: io_distinct_def)\n\n  lemma [simp]: \"io_distinct As \\<Longrightarrow> io_diagram (FB (Parallel_list As))\"\n    apply (rule Type_ok_FB)\n    by (simp add: io_diagram_Parallel_list_a)\n\n  lemma io_distinct_set_In[simp]: \" io_distinct x \\<Longrightarrow>  perm x (A # B # Bs) \\<Longrightarrow> set (In A) \\<inter> set (In B) = {}\"\n    apply (drule io_distinct_perm, simp_all)\n    by (simp add: io_distinct_def)\n\n  lemma io_distinct_set_Out[simp]: \" io_distinct x \\<Longrightarrow>  perm x (A # B # Bs) \\<Longrightarrow> set (Out A) \\<inter> set (Out B) = {}\"\n    apply (drule io_distinct_perm, simp_all)\n    by (simp add: io_distinct_def)\n\n  lemma distinct_Par_equiv_b: \"io_distinct As  \\<Longrightarrow> perm As (Bs @ Cs) \\<Longrightarrow> in_out_equiv (FB (FB (Parallel_list Bs) ||| Parallel_list Cs)) (FB (Parallel_list As))\"\n    proof -\n      assume [simp]: \"io_distinct As\"\n      assume [simp]: \"perm As (Bs @ Cs)\"\n      have [simp]: \"io_diagram (Parallel_list Bs)\"\n        apply (rule io_diagram_Parallel_list_a)\n        by (rule_tac As = As and Cs = Cs in io_distinct_append_a, simp_all)\n      have [simp]: \"io_diagram (FB (Parallel_list Bs))\"\n        by (rule Type_ok_FB, simp)\n      have [simp]: \"io_diagram (Parallel_list Cs)\"\n        apply (rule io_diagram_Parallel_list_a)\n        by (rule_tac As = As and Bs = Bs in io_distinct_append_b, simp_all)\n      have [simp]: \"(\\<Union>a\\<in>set Bs. set (Out a)) \\<inter> (\\<Union>a\\<in>set Cs. set (Out a)) = {}\"\n        apply (cut_tac As = As and Bs = \"Bs @ Cs\" in io_distinct_perm, simp_all)\n        by (simp add: io_distinct_def)\n      have Aa[simp]: \"set (In (Parallel_list Bs)) \\<inter> set (In (Parallel_list Cs)) = {}\"\n        apply (simp add: In_Parallel)\n        apply (cut_tac As = As and Bs = \"Bs @ Cs\" in io_distinct_perm, simp_all)\n        by (simp add: io_distinct_def)\n      have Ab[simp]: \"set (Out (Parallel_list Bs)) \\<inter> set (Out (Parallel_list Cs)) = {}\"\n        by (simp add: Out_Parallel)\n      have [simp]: \"set (In (FB (Parallel_list Bs))) \\<inter> set (In (Parallel_list Cs)) = {}\"\n        apply (subgoal_tac \"set (In ((Parallel_list Bs))) \\<inter> set (In (Parallel_list Cs)) = {}\")\n        apply (subgoal_tac \"set (In (FB (Parallel_list Bs))) \\<subseteq> set (In ((Parallel_list Bs)))\")\n        apply (auto simp del: Aa) [1]\n        by (auto simp add: FB_def Let_def set_diff)\n \n      have [simp]: \"set (Out (FB (Parallel_list Bs))) \\<inter> set (Out (Parallel_list Cs)) = {}\"\n        apply (subgoal_tac \"set (Out ((Parallel_list Bs))) \\<inter> set (Out (Parallel_list Cs)) = {}\")\n        apply (subgoal_tac \"set (Out (FB (Parallel_list Bs))) \\<subseteq> set (Out ((Parallel_list Bs)))\")\n        apply (auto simp del: Ab) [1]\n        by (auto simp add: FB_def Let_def set_diff)\n\n      have [simp]:\"Ball (set Bs) io_diagram\"\n        apply (cut_tac As = As and Bs = Bs and Cs = Cs in io_distinct_append_a, simp_all)\n        by (simp add: io_distinct_def)\n      have [simp]:\"Ball (set Cs) io_diagram\"\n        apply (cut_tac As = As and Bs = Bs and Cs = Cs in io_distinct_append_b, simp_all)\n        by (simp add: io_distinct_def)\n      have [simp]:\" distinct (concat (map Out Bs))\"\n        apply (cut_tac As = As and Bs = Bs and Cs = Cs in io_distinct_append_a, simp_all)\n        by (simp add: io_distinct_def)\n      have [simp]:\"distinct (concat (map Out Cs))\"\n        apply (cut_tac As = As and Bs = Bs and Cs = Cs in io_distinct_append_b, simp_all)\n        by (simp add: io_distinct_def)\n      have [simp]:\"io_diagram (Parallel_list As)\"\n        by (simp add: io_diagram_Parallel_list_a)\n      have A: \"FB (FB (Parallel_list Bs) ;; FB (Parallel_list Cs)) = FB (Parallel_list Bs ||| Parallel_list Cs)\"\n        by (subst FeedbackSerial, simp_all)\n      show ?thesis\n        apply (subst FeedbackSerial, simp_all)\n        apply (subst FB_idemp, simp_all)\n        apply (simp add:  A)\n        apply (subst Parallel_list_append [THEN sym], simp_all)\n        apply (rule in_out_equiv_FB, simp_all)\n        apply (rule distinct_Par_equiv_a, simp_all)\n        apply auto [1]\n        by (simp add: perm_sym)\n   qed\n\n\n  lemma distinct_Par_equiv: \"io_distinct As_init \\<Longrightarrow> Suc 0 \\<le> length As_init \\<Longrightarrow>\n    length As = w \\<Longrightarrow> io_distinct As \\<Longrightarrow> in_out_equiv (FB (Parallel_list As)) (FB (Parallel_list As_init)) \\<Longrightarrow>\n    Suc 0 < w \\<Longrightarrow> Suc 0 < length Bs \\<Longrightarrow> perm As (Bs @ Cs) \\<Longrightarrow> \n      io_distinct (FB (Parallel_list Bs) # Cs) \\<and> in_out_equiv (FB (FB (Parallel_list Bs) ||| Parallel_list Cs)) (FB (Parallel_list As_init))\"\n    apply simp\n    apply (rule_tac B = \"FB (Parallel_list As)\" in in_out_equiv_tran, simp_all)\n    by (rule distinct_Par_equiv_b, simp_all)\n\nlemma AAAA_x[simp]: \"io_distinct As_init \\<Longrightarrow> Suc 0 \\<le> length As_init \\<Longrightarrow> invariant As_init w x \\<Longrightarrow> Suc 0 < length x \\<Longrightarrow> Suc 0 < length Bs \n        \\<Longrightarrow> perm x (Bs @ Cs) \n        \\<Longrightarrow> invariant As_init (Suc (length Cs)) (FB (Parallel_list Bs) # Cs)\"\n    by (simp add: invariant_def, safe, simp_all add: distinct_Par_equiv)\n\n  term \"{1,2,3} - {2,3}\"\n\n  thm ParallelId_right\n\n  lemma [simp]: \"io_distinct As_init \\<Longrightarrow>\n                Suc 0 \\<le> length As_init \\<Longrightarrow> invariant As_init w x \\<Longrightarrow> Suc 0 < length x \\<Longrightarrow> perm x (A # B # Bs) \n                \\<Longrightarrow> invariant As_init (Suc (length Bs)) (FB (FB A ;; FB B) # Bs)\"\n     apply (subst FeedbackSerial [THEN sym])\n     apply (simp_all add: invariant_def)\n     apply (drule perm_set_eq, simp add: io_distinct_def) \n     apply (drule perm_set_eq, simp add: io_distinct_def)\n     apply (rule io_distinct_set_In, simp_all)\n     apply (rule io_distinct_set_Out, simp_all)\n     apply (cut_tac Bs = \"[A,B]\" and Cs = Bs and w = w in AAAA_x, simp_all)\n     apply (simp add: invariant_def)\n     apply (simp add: invariant_def)\n     apply (subst (asm) ParallelId_right, simp_all)\n     apply (drule perm_set_eq, simp add: io_distinct_def) \n     apply (subst (asm) ParallelId_right, simp_all)\n     by (drule perm_set_eq, simp add: io_distinct_def) \n\n  lemma [simp]: \"io_distinct As_init \\<Longrightarrow> Suc 0 \\<le> length As_init \\<Longrightarrow>\n         Hoare (invariant As_init w \\<sqinter> (\\<lambda>As. Suc 0 < length As)) \n          [:As\\<leadsto>As'.\\<exists>Bs. Suc 0 < length Bs \\<and> (\\<exists>Cs. perm As (Bs @ Cs) \\<and> As' = FB (Parallel_list Bs) # Cs):] (Sup_less (invariant As_init) w)\"\n     apply (rule hoare_demonic, safe)\n     apply (simp add: Sup_less_def)\n     apply (rule_tac x = \"invariant As_init (Suc (length Cs))\" in exI, safe)\n     apply (rule_tac x = \"(Suc (length Cs))\" in exI, simp_all)\n     apply (simp add: invariant_def, safe)\n     by (drule perm_length, simp)\n\n  lemma [simp]: \"io_distinct As_init \\<Longrightarrow> Suc 0 \\<le> length As_init \\<Longrightarrow>\n         Hoare (invariant As_init w \\<sqinter> (\\<lambda>As. Suc 0 < length As)) \n          [:As\\<leadsto>As'.\\<exists>A B Bs. perm As (A # B # Bs) \\<and> As' = FB (FB A ;; FB B) # Bs:] (Sup_less (invariant As_init) w)\"\n     apply (rule hoare_demonic, safe)\n     apply (simp add: Sup_less_def)\n     apply (rule_tac x = \"invariant As_init (Suc (length Bs))\" in exI, safe)\n     apply (rule_tac x = \"(Suc (length Bs))\" in exI, simp_all)\n     apply (simp add: invariant_def, safe)\n     apply (drule perm_length, simp)\n     done\n\n  theorem CorrectnessTranslateHBD: \"io_distinct As_init \\<Longrightarrow> length As_init \\<ge> 1 \\<Longrightarrow> \n    Hoare (io_distinct \\<sqinter> (\\<lambda> As . As = As_init)) TranslateHBD (\\<lambda> S . in_out_equiv S (FB (Parallel_list As_init)))\"\n    apply (simp add: TranslateHBD_def)\n    apply (simp add: hoare_sequential)\n    apply (rule_tac x = \"\\<lambda> As . in_out_equiv (FB (As ! 0)) (FB (Parallel_list As_init))\" in exI)\n    apply simp\n    apply (rule_tac p = \"invariant As_init\" in hoare_while_a, simp_all)\n    apply (simp add: hoare_choice, safe)\n    apply (simp_all add: invariant_def, safe)\n    apply (rule in_out_equiv_refl)\n    apply (rule Type_ok_FB)\n    apply (rule io_diagram_Parallel_list_a, simp)\n    apply (case_tac x, simp)\n    apply clarify\n    proof -\n      fix a list\n      assume B: \"in_out_equiv (FB (Parallel_list (a # list))) (FB (Parallel_list As_init))\"\n      assume A: \"io_distinct (a # list)\"\n      assume \"Suc 0 = length (a # list)\"\n      from this have [simp]: \"list = []\"\n        by simp\n      from A have [simp]: \"io_diagram a\"\n        by (simp add: io_distinct_def)\n      have [simp]: \"FB (Parallel_list (a # list)) = FB a\"\n        by simp\n      from B show \"in_out_equiv (FB ((a # list) ! 0)) (FB (Parallel_list As_init))\"\n        by simp\n    qed\n end\n  \nend", "meta": {"author": "hbd-translation", "repo": "TranslateHBD", "sha": "c040d1ce04e4eb163832adea9a7f66566519ffd9", "save_path": "github-repos/isabelle/hbd-translation-TranslateHBD", "path": "github-repos/isabelle/hbd-translation-TranslateHBD/TranslateHBD-c040d1ce04e4eb163832adea9a7f66566519ffd9/HBDTranslationsUsingFeedback.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6187804337438501, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.270916614685136}}
{"text": "header {* \\isaheader{CFG well-formedness} *}\n\ntheory CFG_wf imports CFG begin\n\nlocale CFG_wf = CFG sourcenode targetnode kind valid_edge Entry \n    get_proc get_return_edges procs Main\n  for sourcenode :: \"'edge \\<Rightarrow> 'node\" and targetnode :: \"'edge \\<Rightarrow> 'node\"\n  and kind :: \"'edge \\<Rightarrow> ('var,'val,'ret,'pname) edge_kind\" \n  and valid_edge :: \"'edge \\<Rightarrow> bool\"\n  and Entry :: \"'node\" (\"'('_Entry'_')\")  and get_proc :: \"'node \\<Rightarrow> 'pname\"\n  and get_return_edges :: \"'edge \\<Rightarrow> 'edge set\"\n  and procs :: \"('pname \\<times> 'var list \\<times> 'var list) list\" and Main :: \"'pname\" +\n  fixes Def::\"'node \\<Rightarrow> 'var set\"\n  fixes Use::\"'node \\<Rightarrow> 'var set\"\n  fixes ParamDefs::\"'node \\<Rightarrow> 'var list\"\n  fixes ParamUses::\"'node \\<Rightarrow> 'var set list\"\n  assumes Entry_empty:\"Def (_Entry_) = {} \\<and> Use (_Entry_) = {}\"\n  and ParamUses_call_source_length:\n    \"\\<lbrakk>valid_edge a; kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs; (p,ins,outs) \\<in> set procs\\<rbrakk>\n    \\<Longrightarrow> length(ParamUses (sourcenode a)) = length ins\"\n  and distinct_ParamDefs:\"valid_edge a \\<Longrightarrow> distinct (ParamDefs (targetnode a))\"\n  and ParamDefs_return_target_length:\n    \"\\<lbrakk>valid_edge a; kind a = Q'\\<hookleftarrow>\\<^bsub>p\\<^esub>f'; (p,ins,outs) \\<in> set procs\\<rbrakk>\n    \\<Longrightarrow> length(ParamDefs (targetnode a)) = length outs\"\n  and ParamDefs_in_Def:\n    \"\\<lbrakk>valid_node n; V \\<in> set (ParamDefs n)\\<rbrakk> \\<Longrightarrow> V \\<in> Def n\"\n  and ins_in_Def:\n    \"\\<lbrakk>valid_edge a; kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs; (p,ins,outs) \\<in> set procs; V \\<in> set ins\\<rbrakk>\n    \\<Longrightarrow> V \\<in> Def (targetnode a)\"\n  and call_source_Def_empty:\n    \"\\<lbrakk>valid_edge a; kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\\<rbrakk> \\<Longrightarrow> Def (sourcenode a) = {}\"\n  and ParamUses_in_Use:\n    \"\\<lbrakk>valid_node n; V \\<in> Union (set (ParamUses n))\\<rbrakk> \\<Longrightarrow> V \\<in> Use n\"\n  and outs_in_Use:\n    \"\\<lbrakk>valid_edge a; kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f; (p,ins,outs) \\<in> set procs; V \\<in> set outs\\<rbrakk> \n    \\<Longrightarrow> V \\<in> Use (sourcenode a)\"\n  and CFG_intra_edge_no_Def_equal:\n    \"\\<lbrakk>valid_edge a; V \\<notin> Def (sourcenode a); intra_kind (kind a); pred (kind a) s\\<rbrakk>\n    \\<Longrightarrow> state_val (transfer (kind a) s) V = state_val s V\"\n  and CFG_intra_edge_transfer_uses_only_Use:\n    \"\\<lbrakk>valid_edge a; \\<forall>V \\<in> Use (sourcenode a). state_val s V = state_val s' V;\n      intra_kind (kind a); pred (kind a) s; pred (kind a) s'\\<rbrakk>\n    \\<Longrightarrow> \\<forall>V \\<in> Def (sourcenode a). state_val (transfer (kind a) s) V =\n                                state_val (transfer (kind a) s') V\"\n  and CFG_edge_Uses_pred_equal:\n    \"\\<lbrakk>valid_edge a; pred (kind a) s; snd (hd s) = snd (hd s');\n      \\<forall>V \\<in> Use (sourcenode a). state_val s V = state_val s' V; length s = length s'\\<rbrakk>\n    \\<Longrightarrow> pred (kind a) s'\"\n  and CFG_call_edge_length:\n    \"\\<lbrakk>valid_edge a; kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs; (p,ins,outs) \\<in> set procs\\<rbrakk>\n    \\<Longrightarrow> length fs = length ins\"\n  and CFG_call_determ:\n    \"\\<lbrakk>valid_edge a; kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs; valid_edge a'; kind a' = Q':r'\\<hookrightarrow>\\<^bsub>p'\\<^esub>fs';\n      sourcenode a = sourcenode a'; pred (kind a) s; pred (kind a') s\\<rbrakk>\n    \\<Longrightarrow> a = a'\"\n  and CFG_call_edge_params:\n    \"\\<lbrakk>valid_edge a; kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs; i < length ins; \n      (p,ins,outs) \\<in> set procs; pred (kind a) s; pred (kind a) s';\n      \\<forall>V \\<in> (ParamUses (sourcenode a))!i. state_val s V = state_val s' V\\<rbrakk>\n    \\<Longrightarrow> (params fs (fst (hd s)))!i = (params fs (fst (hd s')))!i\"  \n  and CFG_return_edge_fun:\n    \"\\<lbrakk>valid_edge a; kind a = Q'\\<hookleftarrow>\\<^bsub>p\\<^esub>f'; (p,ins,outs) \\<in> set procs\\<rbrakk>\n     \\<Longrightarrow> f' vmap vmap' = vmap'(ParamDefs (targetnode a) [:=] map vmap outs)\"\n  and deterministic:\"\\<lbrakk>valid_edge a; valid_edge a'; sourcenode a = sourcenode a';\n    targetnode a \\<noteq> targetnode a'; intra_kind (kind a); intra_kind (kind a')\\<rbrakk> \n    \\<Longrightarrow> \\<exists>Q Q'. kind a = (Q)\\<^sub>\\<surd> \\<and> kind a' = (Q')\\<^sub>\\<surd> \\<and> \n             (\\<forall>s. (Q s \\<longrightarrow> \\<not> Q' s) \\<and> (Q' s \\<longrightarrow> \\<not> Q s))\"\n\nbegin\n\n\nlemma CFG_equal_Use_equal_call:\n  assumes \"valid_edge a\" and \"kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\" and \"valid_edge a'\"\n  and \"kind a' = Q':r'\\<hookrightarrow>\\<^bsub>p'\\<^esub>fs'\" and \"sourcenode a = sourcenode a'\"\n  and \"pred (kind a) s\" and \"pred (kind a') s'\" \n  and \"snd (hd s) = snd (hd s')\" and \"length s = length s'\"\n  and \"\\<forall>V \\<in> Use (sourcenode a). state_val s V = state_val s' V\"\n  shows \"a = a'\"\nproof -\n  from `valid_edge a` `pred (kind a) s` `snd (hd s) = snd (hd s')`\n    `\\<forall>V \\<in> Use (sourcenode a). state_val s V = state_val s' V` `length s = length s'`\n  have \"pred (kind a) s'\" by(rule CFG_edge_Uses_pred_equal)\n  with `valid_edge a` `kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs` `valid_edge a'` `kind a' = Q':r'\\<hookrightarrow>\\<^bsub>p'\\<^esub>fs'`\n    `sourcenode a = sourcenode a'` `pred (kind a') s'`\n  show ?thesis by -(rule CFG_call_determ)\nqed\n\n\nlemma CFG_call_edge_param_in:\n  assumes \"valid_edge a\" and \"kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\" and \"i < length ins\"\n  and \"(p,ins,outs) \\<in> set procs\" and \"pred (kind a) s\" and \"pred (kind a) s'\"\n  and \"\\<forall>V \\<in> (ParamUses (sourcenode a))!i. state_val s V = state_val s' V\"\n  shows \"state_val (transfer (kind a) s) (ins!i) = \n         state_val (transfer (kind a) s') (ins!i)\"\nproof -\n  from assms have params:\"(params fs (fst (hd s)))!i = (params fs (fst (hd s')))!i\"\n    by(rule CFG_call_edge_params)\n  from `valid_edge a` `kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs` `(p,ins,outs) \\<in> set procs`\n  have [simp]:\"(THE ins. \\<exists>outs. (p,ins,outs) \\<in> set procs) = ins\"\n    by(rule formal_in_THE)\n  from `pred (kind a) s` obtain cf cfs where [simp]:\"s = cf#cfs\" by(cases s) auto\n  from `pred (kind a) s'` obtain cf' cfs' where [simp]:\"s' = cf'#cfs'\"\n    by(cases s') auto\n  from `kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs`\n  have eqs:\"fst (hd (transfer (kind a) s)) = (empty(ins [:=] params fs (fst cf)))\"\n    \"fst (hd (transfer (kind a) s')) = (empty(ins [:=] params fs (fst cf')))\"\n    by simp_all\n  from `valid_edge a` `kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs` `(p,ins,outs) \\<in> set procs`\n  have \"length fs = length ins\" by(rule CFG_call_edge_length)\n  from `(p,ins,outs) \\<in> set procs` have \"distinct ins\" by(rule distinct_formal_ins)\n  with `i < length ins` `length fs = length ins`\n  have \"(empty(ins [:=] params fs (fst cf))) (ins!i) = (params fs (fst cf))!i\"\n    \"(empty(ins [:=] params fs (fst cf'))) (ins!i) = (params fs (fst cf'))!i\"\n    by(fastforce intro:fun_upds_nth)+\n  with eqs `kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs` params\n  show ?thesis by simp\nqed\n\n\nlemma CFG_call_edge_no_param:\n  assumes \"valid_edge a\" and \"kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\" and \"V \\<notin> set ins\"\n  and \"(p,ins,outs) \\<in> set procs\" and \"pred (kind a) s\"\n  shows \"state_val (transfer (kind a) s) V = None\"\nproof -\n  from `valid_edge a` `kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs` `(p,ins,outs) \\<in> set procs`\n  have [simp]:\"(THE ins. \\<exists>outs. (p,ins,outs) \\<in> set procs) = ins\"\n    by(rule formal_in_THE)\n  from `pred (kind a) s` obtain cf cfs where [simp]:\"s = cf#cfs\" by(cases s) auto\n  from `V \\<notin> set ins` have \"(empty(ins [:=] params fs (fst cf))) V = None\"\n    by(auto dest:fun_upds_notin)\n  with `kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs` show ?thesis by simp\nqed\n\n\n\nlemma CFG_return_edge_param_out:\n  assumes \"valid_edge a\" and \"kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\" and \"i < length outs\"\n  and \"(p,ins,outs) \\<in> set procs\" and \"state_val s (outs!i) = state_val s' (outs!i)\"\n  and \"s = cf#cfx#cfs\" and \"s' = cf'#cfx'#cfs'\"\n  shows \"state_val (transfer (kind a) s) ((ParamDefs (targetnode a))!i) =\n         state_val (transfer (kind a) s') ((ParamDefs (targetnode a))!i)\"\nproof -\n  from `valid_edge a` `kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f` `(p,ins,outs) \\<in> set procs`\n  have [simp]:\"(THE outs. \\<exists>ins. (p,ins,outs) \\<in> set procs) = outs\"\n    by(rule formal_out_THE)\n  from `valid_edge a` `kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f` `(p,ins,outs) \\<in> set procs` `s = cf#cfx#cfs`\n  have transfer:\"fst (hd (transfer (kind a) s)) = \n    (fst cfx)(ParamDefs (targetnode a) [:=] map (fst cf) outs)\"\n    by(fastforce intro:CFG_return_edge_fun)\n  from `valid_edge a` `kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f` `(p,ins,outs) \\<in> set procs` `s' = cf'#cfx'#cfs'`\n  have transfer':\"fst (hd (transfer (kind a) s')) = \n    (fst cfx')(ParamDefs (targetnode a) [:=] map (fst cf') outs)\"\n    by(fastforce intro:CFG_return_edge_fun)\n  from `state_val s (outs!i) = state_val s' (outs!i)` `i < length outs`\n    `s = cf#cfx#cfs` `s' = cf'#cfx'#cfs'`\n  have \"(fst cf) (outs!i) = (fst cf') (outs!i)\" by simp\n  from `valid_edge a` have \"distinct (ParamDefs (targetnode a))\"\n    by(fastforce intro:distinct_ParamDefs)\n  from `valid_edge a` `kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f` `(p,ins,outs) \\<in> set procs`\n  have \"length(ParamDefs (targetnode a)) = length outs\"\n    by(fastforce intro:ParamDefs_return_target_length)\n  with `i < length outs` `distinct (ParamDefs (targetnode a))`\n  have \"(fst cfx)(ParamDefs (targetnode a) [:=] map (fst cf) outs)\n    ((ParamDefs (targetnode a))!i) = (map (fst cf) outs)!i\" \n    and \"(fst cfx')(ParamDefs (targetnode a) [:=] map (fst cf') outs)\n             ((ParamDefs (targetnode a))!i) = (map (fst cf') outs)!i\"\n    by(fastforce intro:fun_upds_nth)+\n  with transfer transfer' `(fst cf) (outs!i) = (fst cf') (outs!i)` `i < length outs`\n  show ?thesis by simp\nqed\n\n\nlemma CFG_slp_no_Def_equal:\n  assumes \"n -as\\<rightarrow>\\<^bsub>sl\\<^esub>* n'\" and \"valid_edge a\" and \"a' \\<in> get_return_edges a\"\n  and \"V \\<notin> set (ParamDefs (targetnode a'))\" and \"preds (kinds (a#as@[a'])) s\"\n  shows \"state_val (transfers (kinds (a#as@[a'])) s) V = state_val s V\"\nproof -\n  from `valid_edge a` `a' \\<in> get_return_edges a` \n  obtain Q r p fs where \"kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\"\n    by(fastforce dest!:only_call_get_return_edges)\n  with `valid_edge a` `a' \\<in> get_return_edges a` obtain Q' f' where \"kind a' = Q'\\<hookleftarrow>\\<^bsub>p\\<^esub>f'\"\n    by(fastforce dest!:call_return_edges)\n  from `valid_edge a` `a' \\<in> get_return_edges a` have \"valid_edge a'\"\n    by(rule get_return_edges_valid)\n  from `preds (kinds (a#as@[a'])) s` obtain cf cfs where [simp]:\"s = cf#cfs\"\n    by(cases s,auto simp:kinds_def)\n  from `valid_edge a` `kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs` obtain ins outs \n    where \"(p,ins,outs) \\<in> set procs\" by(fastforce dest!:callee_in_procs)\n  from `kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs` obtain cfx where \"transfer (kind a) s = cfx#cf#cfs\"\n    by simp\n  moreover\n  from `n -as\\<rightarrow>\\<^bsub>sl\\<^esub>* n'` obtain cfx' \n    where \"transfers (kinds as) (cfx#cf#cfs) = cfx'#cf#cfs\"\n    by(fastforce elim:slp_callstack_length_equal)\n  moreover\n  from `kind a' = Q'\\<hookleftarrow>\\<^bsub>p\\<^esub>f'` `valid_edge a'` `(p,ins,outs) \\<in> set procs`\n  have \"fst (hd (transfer (kind a') (cfx'#cf#cfs))) = \n    (fst cf)(ParamDefs (targetnode a') [:=] map (fst cfx') outs)\"\n    by(simp,simp only:formal_out_THE,fastforce intro:CFG_return_edge_fun)\n  ultimately have \"fst (hd (transfers (kinds (a#as@[a'])) s)) = \n    (fst cf)(ParamDefs (targetnode a') [:=] map (fst cfx') outs)\"\n    by(simp add:kinds_def transfers_split)\n  with `V \\<notin> set (ParamDefs (targetnode a'))` show ?thesis\n    by(simp add:fun_upds_notin)\nqed\n\n\n\nlemma [dest!]: \"V \\<in> Use (_Entry_) \\<Longrightarrow> False\"\nby(simp add:Entry_empty)\n\nlemma [dest!]: \"V \\<in> Def (_Entry_) \\<Longrightarrow> False\"\nby(simp add:Entry_empty)\n\n\nlemma CFG_intra_path_no_Def_equal:\n  assumes \"n -as\\<rightarrow>\\<^sub>\\<iota>* n'\" and \"\\<forall>n \\<in> set (sourcenodes as). V \\<notin> Def n\"\n  and \"preds (kinds as) s\"\n  shows \"state_val (transfers (kinds as) s) V = state_val s V\"\nproof -\n  from `n -as\\<rightarrow>\\<^sub>\\<iota>* n'` have \"n -as\\<rightarrow>* n'\" and \"\\<forall>a \\<in> set as. intra_kind (kind a)\"\n    by(simp_all add:intra_path_def)\n  from this `\\<forall>n \\<in> set (sourcenodes as). V \\<notin> Def n` `preds (kinds as) s`\n  have \"state_val (transfers (kinds as) s) V = state_val s V\"\n  proof(induct arbitrary:s rule:path.induct)\n    case (empty_path n)\n    thus ?case by(simp add:sourcenodes_def kinds_def)\n  next\n    case (Cons_path n'' as n' a n)\n    note IH = `\\<And>s. \\<lbrakk>\\<forall>a\\<in>set as. intra_kind (kind a); \n                    \\<forall>n\\<in>set (sourcenodes as). V \\<notin> Def n; preds (kinds as) s\\<rbrakk> \n      \\<Longrightarrow> state_val (transfers (kinds as) s) V = state_val s V`\n    from `preds (kinds (a#as)) s` have \"pred (kind a) s\"\n      and \"preds (kinds as) (transfer (kind a) s)\" by(simp_all add:kinds_def)\n    from `\\<forall>n\\<in>set (sourcenodes (a#as)). V \\<notin> Def n`\n    have noDef:\"V \\<notin> Def (sourcenode a)\" \n      and all:\"\\<forall>n\\<in>set (sourcenodes as). V \\<notin> Def n\"\n      by(auto simp:sourcenodes_def)\n    from `\\<forall>a\\<in>set (a#as). intra_kind (kind a)`\n    have \"intra_kind (kind a)\" and all':\"\\<forall>a\\<in>set as. intra_kind (kind a)\"\n      by auto\n    from `valid_edge a` noDef `intra_kind (kind a)` `pred (kind a) s`\n    have \"state_val (transfer (kind a) s) V = state_val s V\"\n     by -(rule CFG_intra_edge_no_Def_equal)\n    with IH[OF all' all `preds (kinds as) (transfer (kind a) s)`] show ?case\n      by(simp add:kinds_def)\n  qed\n  thus ?thesis by blast\nqed\n\n\nlemma slpa_preds:\n  \"\\<lbrakk>same_level_path_aux cs as; s = cfsx@cf#cfs; s' = cfsx@cf#cfs'; \n    length cfs = length cfs'; \\<forall>a \\<in> set as. valid_edge a; length cs = length cfsx; \n    preds (kinds as) s\\<rbrakk>\n  \\<Longrightarrow> preds (kinds as) s'\"\nproof(induct arbitrary:s s' cf cfsx rule:slpa_induct)\n  case (slpa_empty cs) thus ?case by(simp add:kinds_def)\nnext\n  case (slpa_intra cs a as)\n  note IH = `\\<And>s s' cf cfsx. \\<lbrakk>s = cfsx@cf#cfs; s' = cfsx@cf#cfs';\n    length cfs = length cfs'; \\<forall>a \\<in> set as. valid_edge a; length cs = length cfsx; \n    preds (kinds as) s\\<rbrakk> \\<Longrightarrow> preds (kinds as) s'`\n  from `\\<forall>a\\<in>set (a#as). valid_edge a` have \"valid_edge a\"\n    and \"\\<forall>a \\<in> set as. valid_edge a\" by simp_all\n  from `preds (kinds (a#as)) s` have \"pred (kind a) s\"\n    and \"preds (kinds as) (transfer (kind a) s)\" by(simp_all add:kinds_def)\n  show ?case\n  proof(cases cfsx)\n    case Nil\n    with `length cs = length cfsx` have \"length cs = length []\" by simp\n    from Nil `s = cfsx@cf#cfs` `s' = cfsx@cf#cfs'` `intra_kind (kind a)` \n    obtain cfx where \"transfer (kind a) s = []@cfx#cfs\"\n      and \"transfer (kind a) s' = []@cfx#cfs'\"\n      by(cases \"kind a\",auto simp:kinds_def intra_kind_def)\n    from IH[OF this `length cfs = length cfs'` `\\<forall>a \\<in> set as. valid_edge a`\n      `length cs = length []` `preds (kinds as) (transfer (kind a) s)`]\n    have \"preds (kinds as) (transfer (kind a) s')\" .\n    moreover\n    from Nil `valid_edge a` `pred (kind a) s` `s = cfsx@cf#cfs` `s' = cfsx@cf#cfs'`\n      `length cfs = length cfs'`\n    have \"pred (kind a) s'\" by(fastforce intro:CFG_edge_Uses_pred_equal)\n    ultimately show ?thesis by(simp add:kinds_def)\n  next\n    case (Cons x xs)\n    with `s = cfsx@cf#cfs` `s' = cfsx@cf#cfs'` `intra_kind (kind a)`\n    obtain cfx where \"transfer (kind a) s = (cfx#xs)@cf#cfs\"\n      and \"transfer (kind a) s' = (cfx#xs)@cf#cfs'\"\n      by(cases \"kind a\",auto simp:kinds_def intra_kind_def)\n    from IH[OF this `length cfs = length cfs'` `\\<forall>a \\<in> set as. valid_edge a` _ \n      `preds (kinds as) (transfer (kind a) s)`] `length cs = length cfsx` Cons\n    have \"preds (kinds as) (transfer (kind a) s')\" by simp\n    moreover\n    from Cons `valid_edge a` `pred (kind a) s` `s = cfsx@cf#cfs` `s' = cfsx@cf#cfs'`\n      `length cfs = length cfs'` \n    have \"pred (kind a) s'\" by(fastforce intro:CFG_edge_Uses_pred_equal)\n    ultimately show ?thesis by(simp add:kinds_def)\n  qed\nnext\n  case (slpa_Call cs a as Q r p fs)\n  note IH = `\\<And>s s' cf cfsx. \\<lbrakk>s = cfsx@cf#cfs; s' = cfsx@cf#cfs';\n    length cfs = length cfs'; \\<forall>a \\<in> set as. valid_edge a; length (a#cs) = length cfsx;\n    preds (kinds as) s\\<rbrakk> \\<Longrightarrow> preds (kinds as) s'`\n  from `\\<forall>a\\<in>set (a#as). valid_edge a` have \"valid_edge a\"\n    and \"\\<forall>a \\<in> set as. valid_edge a\" by simp_all\n  from `preds (kinds (a#as)) s` have \"pred (kind a) s\"\n    and \"preds (kinds as) (transfer (kind a) s)\" by(simp_all add:kinds_def)\n  from `kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs` `s = cfsx@cf#cfs` `s' = cfsx@cf#cfs'` obtain cfx\n    where \"transfer (kind a) s = (cfx#cfsx)@cf#cfs\"\n    and \"transfer (kind a) s' = (cfx#cfsx)@cf#cfs'\" by(cases cfsx) auto\n  from IH[OF this `length cfs = length cfs'` `\\<forall>a \\<in> set as. valid_edge a` _ \n    `preds (kinds as) (transfer (kind a) s)`] `length cs = length cfsx`\n  have \"preds (kinds as) (transfer (kind a) s')\" by simp\n  moreover\n  from `valid_edge a` `pred (kind a) s` `s = cfsx@cf#cfs` `s' = cfsx@cf#cfs'`\n    `length cfs = length cfs'` have \"pred (kind a) s'\" \n    by(cases cfsx)(auto intro:CFG_edge_Uses_pred_equal)\n  ultimately show ?case by(simp add:kinds_def)\nnext\n  case (slpa_Return cs a as Q p f c' cs')\n  note IH = `\\<And>s s' cf cfsx. \\<lbrakk>s = cfsx@cf#cfs; s' = cfsx@cf#cfs';\n    length cfs = length cfs'; \\<forall>a \\<in> set as. valid_edge a; length cs' = length cfsx; \n    preds (kinds as) s\\<rbrakk> \\<Longrightarrow> preds (kinds as) s'`\n  from `\\<forall>a\\<in>set (a#as). valid_edge a` have \"valid_edge a\"\n    and \"\\<forall>a \\<in> set as. valid_edge a\" by simp_all\n  from `preds (kinds (a#as)) s` have \"pred (kind a) s\"\n    and \"preds (kinds as) (transfer (kind a) s)\" by(simp_all add:kinds_def)\n  show ?case\n  proof(cases cs')\n    case Nil\n    with `cs = c'#cs'` `s = cfsx@cf#cfs` `s' = cfsx@cf#cfs'`\n      `length cs = length cfsx` \n    obtain cf' where \"s = cf'#cf#cfs\" and \"s' = cf'#cf#cfs'\" by(cases cfsx) auto\n    with `kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f` obtain cf'' where \"transfer (kind a) s = []@cf''#cfs\"\n      and \"transfer (kind a) s' = []@cf''#cfs'\" by auto\n    from IH[OF this `length cfs = length cfs'` `\\<forall>a \\<in> set as. valid_edge a` _ \n      `preds (kinds as) (transfer (kind a) s)`] Nil\n    have \"preds (kinds as) (transfer (kind a) s')\" by simp\n    moreover\n    from `valid_edge a` `pred (kind a) s` `s = cfsx@cf#cfs` `s' = cfsx@cf#cfs'`\n      `length cfs = length cfs'`  have \"pred (kind a) s'\" \n      by(cases cfsx)(auto intro:CFG_edge_Uses_pred_equal)\n    ultimately show ?thesis by(simp add:kinds_def)\n  next\n    case (Cons cx csx)\n    with `cs = c'#cs'` `length cs = length cfsx` `s = cfsx@cf#cfs` `s' = cfsx@cf#cfs'`\n    obtain x x' xs where \"s = (x#x'#xs)@cf#cfs\" and \"s' = (x#x'#xs)@cf#cfs'\"\n      and \"length xs = length csx\"\n      by(cases cfsx,auto,case_tac list,fastforce+)\n    with `kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f` obtain cf' where \"transfer (kind a) s = (cf'#xs)@cf#cfs\"\n      and \"transfer (kind a) s' = (cf'#xs)@cf#cfs'\"\n      by fastforce\n    from IH[OF this `length cfs = length cfs'` `\\<forall>a \\<in> set as. valid_edge a` _ \n      `preds (kinds as) (transfer (kind a) s)`] Cons `length xs = length csx`\n    have \"preds (kinds as) (transfer (kind a) s')\" by simp\n    moreover\n    from `valid_edge a` `pred (kind a) s` `s = cfsx@cf#cfs` `s' = cfsx@cf#cfs'`\n      `length cfs = length cfs'`  have \"pred (kind a) s'\" \n      by(cases cfsx)(auto intro:CFG_edge_Uses_pred_equal)\n    ultimately show ?thesis by(simp add:kinds_def)\n  qed\nqed\n\n\nlemma slp_preds:\n  assumes \"n -as\\<rightarrow>\\<^bsub>sl\\<^esub>* n'\" and \"preds (kinds as) (cf#cfs)\" \n  and \"length cfs = length cfs'\"\n  shows \"preds (kinds as) (cf#cfs')\"\nproof -\n  from `n -as\\<rightarrow>\\<^bsub>sl\\<^esub>* n'` have \"n -as\\<rightarrow>* n'\" and \"same_level_path_aux [] as\"\n    by(simp_all add:slp_def same_level_path_def)\n  from `n -as\\<rightarrow>* n'` have \"\\<forall>a \\<in> set as. valid_edge a\" by(rule path_valid_edges)\n  with `same_level_path_aux [] as` `preds (kinds as) (cf#cfs)` \n    `length cfs = length cfs'`\n  show ?thesis by(fastforce elim!:slpa_preds)\nqed\nend\n\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/HRB-Slicing/StaticInter/CFG_wf.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6187804337438501, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.270916614685136}}
{"text": "(*<*)\ntheory Paxos_Proofs\nimports Three_Step_MRU \"../HO_Transition_System\" Heard_Of.Majorities \"../Quorums\" Paxos_Defs\nbegin\n(*>*)\n\nsubsection \\<open>Proofs\\<close>\n\ntype_synonym p_TS_state = \"(nat \\<times> (process \\<Rightarrow> (val pstate)))\"\n\ndefinition Paxos_TS ::\n  \"(round \\<Rightarrow> process HO)\n  \\<Rightarrow> (round \\<Rightarrow> process HO)\n  \\<Rightarrow> (round \\<Rightarrow> process)\n  \\<Rightarrow> p_TS_state TS\"\nwhere\n  \"Paxos_TS HOs SHOs crds = CHO_to_TS Paxos_Alg HOs SHOs (K o crds)\"\n\nlemmas Paxos_TS_defs = Paxos_TS_def CHO_to_TS_def Paxos_Alg_def CHOinitConfig_def\n  Paxos_initState_def\n\ndefinition Paxos_trans_step where\n  \"Paxos_trans_step HOs SHOs crds nxt_f snd_f stp \\<equiv> \\<Union>r \\<mu>.\n    {((r, cfg), (Suc r, cfg'))|cfg cfg'. three_step r = stp  \\<and> (\\<forall>p.\n      \\<mu> p \\<in> get_msgs (snd_f r) cfg (HOs r) (SHOs r) p\n      \\<and> nxt_f r p (cfg p) (\\<mu> p) (crds r) (cfg' p)\n    )}\"\n\nlemma three_step_less_D:\n  \"0 < three_step r \\<Longrightarrow> three_step r = 1 \\<or> three_step r = 2\"\n  by(unfold three_step_def, arith)\n\nlemma Paxos_trans:\n  \"CSHO_trans_alt Paxos_sendMsg Paxos_nextState HOs SHOs (K \\<circ> crds) = \n  Paxos_trans_step HOs SHOs crds next0 send0 0\n  \\<union> Paxos_trans_step HOs SHOs crds next1 send1 1\n  \\<union> Paxos_trans_step HOs SHOs crds next2 send2 2\n  \"\nproof(rule equalityI)\n  show \"CSHO_trans_alt Paxos_sendMsg Paxos_nextState HOs SHOs (K \\<circ> crds)\n    \\<subseteq> Paxos_trans_step HOs SHOs crds next0 send0 0 \\<union>\n       Paxos_trans_step HOs SHOs crds next1 send1 1 \\<union>\n       Paxos_trans_step HOs SHOs crds next2 send2 2\"\n  by(force simp add: CSHO_trans_alt_def Paxos_sendMsg_def Paxos_nextState_def \n    Paxos_trans_step_def K_def dest!: three_step_less_D)\nnext\n  show \"Paxos_trans_step HOs SHOs crds next0 send0 0 \\<union>\n    Paxos_trans_step HOs SHOs crds next1 send1 1 \\<union>\n    Paxos_trans_step HOs SHOs crds next2 send2 2\n    \\<subseteq> CSHO_trans_alt Paxos_sendMsg Paxos_nextState HOs SHOs (K \\<circ> crds)\"\n  by(force simp add: CSHO_trans_alt_def Paxos_sendMsg_def Paxos_nextState_def \n    Paxos_trans_step_def K_def)\nqed\n\ntype_synonym rHO = \"nat \\<Rightarrow> process HO\"\n\nsubsubsection \\<open>Refinement\\<close>\n(******************************************************************************)\n\ndefinition coord_vote_to_set :: \"nat \\<Rightarrow> (process \\<Rightarrow> (val pstate)) \\<Rightarrow> val set\" where\n  \"coord_vote_to_set r sc \\<equiv> (let v = pstate.commt (sc (coord r)) in \n      if v = None \n          then {}\n          else {the v})\"\n\ndefinition paxos_ref_rel :: \"(three_step_mru_state \\<times> p_TS_state)set\" where\n  \"paxos_ref_rel = {(sa, (r, sc)).\n    opt_mru_state.next_round sa = r\n    \\<and> opt_mru_state.decisions sa = pstate.decide o sc\n    \\<and> opt_mru_state.mru_vote sa = pstate.mru_vote o sc\n    \\<and> (three_step r = Suc 0 \\<longrightarrow> three_step_mru_state.candidates sa = coord_vote_to_set r sc)\n  }\"\n\nlemma mru_vote_evolution0:\n  \"\\<forall>p. next0 r p (s p) (msgs p) (crd p) (s' p) \\<Longrightarrow> mru_vote o s' = mru_vote o s\"\n  apply(rule_tac[!] ext, rename_tac x, erule_tac[!] x=x in allE)\n  by(auto simp add: next0_def next2_def Let_def)\n\nlemma mru_vote_evolution2:\n  \"\\<forall>p. next2 r p (s p) (msgs p) (crd p) (s' p) \\<Longrightarrow> mru_vote o s' = mru_vote o s\"\n  apply(rule_tac[!] ext, rename_tac x, erule_tac[!] x=x in allE)\n  by(auto simp add: next0_def next2_def Let_def)\n\nlemma decide_evolution:\n  \"\\<forall>p. next0 r p (s p) (msgs p) (crd p) (s' p) \\<Longrightarrow> decide o s = decide o s'\"\n  \"\\<forall>p. next1 r p (s p) (msgs p) (crd p) (s' p) \\<Longrightarrow> decide o s = decide o s'\"\n  apply(rule_tac[!] ext, rename_tac x, erule_tac[!] x=x in allE)\n  by(auto simp add: next0_def next1_def Let_def)\n\nlemma msgs_mru_vote: \n  assumes\n  \"\\<mu> (coord r) \\<in> get_msgs (send0 r) cfg (HOs r) (HOs r) (coord r)\" (is \"\\<mu> ?p \\<in> _\")\n  shows \"((msgs_to_lvs (\\<mu> ?p)) |` HOs r ?p) = (mru_vote o cfg) |` HOs r ?p\" using assms\n  by(auto simp add: get_msgs_benign send0_def restrict_map_def msgs_to_lvs_def\n      mru_vote_to_msg_def map_comp_def intro!: ext split: option.split)\n\nlemma step0_ref:\n  \"{paxos_ref_rel} \n    (\\<Union>r C. majorities.opt_mru_step0 r C), \n    Paxos_trans_step HOs HOs crds next0 send0 0 {> paxos_ref_rel}\"\nproof(clarsimp simp add: PO_rhoare_defs Paxos_trans_step_def all_conj_distrib)\n  fix r sa sc sc' \\<mu>\n  assume R: \"(sa, (r, sc)) \\<in> paxos_ref_rel\"\n    and r: \"three_step r = 0\"\n    and \\<mu>: \"\\<forall>p. \\<mu> p \\<in> get_msgs (send0 r) sc (HOs r) (HOs r) p\"\n        and nxt: \"\\<forall>p. next0 r p (sc p) (\\<mu> p) (crds r) (sc' p)\"\n  note \\<mu>nxt = \\<mu> nxt\n  from r have same_coord: \"coord (Suc r) = coord r\"\n    by(auto simp add: three_step_phase_Suc intro: coord_phase)\n  define C where \"C = coord_vote_to_set (Suc r) sc'\"\n  have guard: \"\\<forall>cand\\<in>C. \\<exists>Q. majorities.opt_mru_guard (mru_vote \\<circ> sc) Q cand\"\n  proof\n    fix cand\n    assume cand: \"cand \\<in> C\"\n    hence Some: \"commt (sc' (coord r)) = Some cand\" using nxt[THEN spec, where x=\"coord r\"]\n      by(auto simp add: C_def coord_vote_to_set_def Let_def same_coord)\n\n    let ?Q = \"HOs r (coord r)\"\n    let ?lvs0 = \"mru_vote o sc\"\n\n    have \"?Q \\<in> majs\" using Some \\<mu>nxt[THEN spec, where x=\"coord r\"]\n      by(auto simp add: Let_def majs_def next0_def same_coord get_msgs_dom)\n    moreover have\n      \"map_option snd (option_Max_by fst (ran (?lvs |` ?Q))) \\<in> {None, Some cand}\"\n      using Some nxt[THEN spec, where x=\"coord r\"]\n      msgs_mru_vote[where HOs=HOs and \\<mu>=\\<mu>, OF \\<mu>[THEN spec, where x=\"coord r\"]] \n      get_msgs_dom[OF \\<mu>[THEN spec, of \"coord r\"]]\n      by(auto simp add: next0_def Let_def split: option.split_asm)\n    ultimately have \"majorities.opt_mru_guard ?lvs0 ?Q cand\"\n      by(auto simp add: majorities.opt_mru_guard_def Let_def majorities.opt_mru_vote_def)\n    thus \"\\<exists>Q. majorities.opt_mru_guard ?lvs0 Q cand\"\n      by blast\n  qed\n\n  define sa' where \"sa' = sa\\<lparr>\n      next_round := Suc r,\n      candidates := C\n    \\<rparr>\"\n  have \"(sa, sa') \\<in> majorities.opt_mru_step0 r C\" using R r nxt guard\n    by(auto simp add: majorities.opt_mru_step0_def sa'_def paxos_ref_rel_def)\n  moreover have \"(sa', (Suc r, sc')) \\<in> paxos_ref_rel\" using R nxt\n    apply(auto simp add: sa'_def paxos_ref_rel_def intro!:\n      mru_vote_evolution0[OF nxt, symmetric] decide_evolution(1)[OF nxt])\n       apply(auto simp add: Let_def C_def o_def intro!: ext)\n    done\n  ultimately show \n    \"\\<exists>sa'. (\\<exists>r C. (sa, sa') \\<in> majorities.opt_mru_step0 r C) \n        \\<and> (sa', Suc r, sc') \\<in> paxos_ref_rel\"\n    by blast\nqed\n\nlemma step1_ref:\n  \"{paxos_ref_rel} \n    (\\<Union>r S v. majorities.opt_mru_step1 r S v), \n    Paxos_trans_step HOs HOs crds next1 send1 (Suc 0) {> paxos_ref_rel}\"\nproof(clarsimp  simp add: PO_rhoare_defs Paxos_trans_step_def all_conj_distrib)\n  fix r sa sc sc' \\<mu>\n  assume R: \"(sa, (r, sc)) \\<in> paxos_ref_rel\"\n    and r: \"three_step r = Suc 0\"\n    and \\<mu>: \"\\<forall>p. \\<mu> p \\<in> get_msgs (send1 r) sc (HOs r) (HOs r) p\"\n        and nxt: \"\\<forall>p. next1 r p (sc p) (\\<mu> p) (crds r) (sc' p)\"\n  note \\<mu>nxt = \\<mu> nxt\n\n  define v where \"v = the (commt (sc (coord r)))\"\n  define S where \"S = {p. coord r \\<in> HOs r p \\<and> commt (sc (coord r)) \\<noteq> None}\"\n  define sa' where \"sa' = sa\\<lparr> next_round := Suc r, \n    opt_mru_state.mru_vote := opt_mru_state.mru_vote sa ++ const_map (three_phase r, v) S\n  \\<rparr>\"\n  have \"(sa, sa') \\<in> majorities.opt_mru_step1 r S v\" using r R \n    by(clarsimp simp add: majorities.opt_mru_step1_def sa'_def  S_def v_def \n      coord_vote_to_set_def paxos_ref_rel_def)\n  moreover have \"(sa', (Suc r, sc')) \\<in> paxos_ref_rel\" using r R\n  proof-\n    have \"mru_vote o sc' = ((mru_vote \\<circ> sc) ++ const_map (three_phase r, v) S)\"\n    proof(rule ext, simp)\n      fix p\n      show \"mru_vote (sc' p) = ((mru_vote \\<circ> sc) ++ const_map (three_phase r, v) S) p\"\n        using \\<mu>nxt[THEN spec, of p]\n        by(auto simp add: get_msgs_benign next1_def send1_def S_def v_def map_add_def \n          const_map_is_None const_map_is_Some restrict_map_def isVote_def split: option.split)\n    qed\n    thus ?thesis using R r nxt\n      by(force simp add: paxos_ref_rel_def sa'_def three_step_Suc intro: decide_evolution)\n  qed      \n  ultimately show \n    \"\\<exists>sa'. (\\<exists>r S v. (sa, sa') \\<in> majorities.opt_mru_step1 r S v) \n        \\<and> (sa', Suc r, sc') \\<in> paxos_ref_rel\"\n    by blast\nqed\n\n\n\n  define dec_f\n    where \"dec_f p = (if decide (sc' p) \\<noteq> decide (sc p) then decide (sc' p) else None)\" for p\n\n  have dec_f: \"(decide \\<circ> sc) ++ dec_f = decide \\<circ> sc'\"\n  proof\n    fix p\n    show \"((decide \\<circ> sc) ++ dec_f) p = (decide \\<circ> sc') p\" using nxt[THEN spec, of p]\n      by(auto simp add: map_add_def dec_f_def next2_def split: option.split intro!: ext)\n  qed\n\n  define sa' where \"sa' = sa\\<lparr>\n    next_round := Suc r,\n    decisions := decisions sa ++ dec_f\n  \\<rparr>\"\n\n  have \"(sa', (Suc r, sc')) \\<in> paxos_ref_rel\" using R r nxt\n    by(auto simp add: paxos_ref_rel_def sa'_def dec_f three_step_Suc \n      mru_vote_evolution2[OF nxt])\n  moreover have \"(sa, sa') \\<in> majorities.opt_mru_step2 r dec_f\" using r R\n  proof-\n    define sc_r_votes where \"sc_r_votes p = (if (\\<exists>v. mru_vote (sc p) = Some (three_phase r, v))\n        then map_option snd (mru_vote (sc p))\n        else None)\" for p\n    have sc_r_votes: \"sc_r_votes = majorities.r_votes sa r\" using R r\n      by(auto simp add: paxos_ref_rel_def sc_r_votes_def majorities.r_votes_def intro!: ext)\n    have \"majorities.step2_d_guard dec_f sc_r_votes\"\n    proof(clarsimp simp add: majorities.step2_d_guard_def)\n      fix p v\n      assume d_f_p: \"dec_f p = Some v\"\n      let ?Qv = \"votes_rcvd (\\<mu> p)\"\n      have Qv: \"card ?Qv > N div 2\" \n        \"v = the_rcvd_vote (\\<mu> p)\" using nxt[THEN spec, of p] d_f_p\n        by(auto simp add: next2_def dec_f_def)\n\n      hence \"v \\<in> snd ` votes_rcvd (\\<mu> p)\"\n        by(fastforce simp add: the_rcvd_vote_def ex_in_conv[symmetric]\n          dest!: card_gt_0_iff[THEN iffD1, OF le_less_trans[OF le0]] elim!: imageI intro: someI)\n      moreover have \"?Qv = map_graph (sc_r_votes) \\<inter> (HOs r p \\<times> UNIV)\" using \\<mu>[THEN spec, of p]\n        by(auto simp add: get_msgs_benign send2_def restrict_map_def votes_rcvd_def\n          sc_r_votes_def image_def split: option.split_asm)\n      ultimately show \"v \\<in> ran sc_r_votes \\<and> dom sc_r_votes \\<in> majs\" using Qv(1)\n        by(auto simp add: majs_def inj_on_def map_graph_def fun_graph_def sc_r_votes_def\n          the_rcvd_vote_def majs_def intro: ranI\n          elim!: less_le_trans intro!: card_inj_on_le[where f=fst])\n    qed\n\n    thus ?thesis using r R\n      by(auto simp add: majorities.opt_mru_step2_def sa'_def paxos_ref_rel_def sc_r_votes)\n  qed\n\n  ultimately show \n    \"\\<exists>sa'. (\\<exists>r dec_f. (sa, sa') \\<in> majorities.opt_mru_step2 r dec_f) \n        \\<and> (sa', Suc r, sc') \\<in> paxos_ref_rel\"\n    by blast\n\nqed\n\nlemma Paxos_Refines_ThreeStep_MRU:\n  \"PO_refines paxos_ref_rel \n    majorities.ts_mru_TS (Paxos_TS HOs HOs crds)\"\nproof(rule refine_basic)\n  show \"init (Paxos_TS HOs HOs crds) \\<subseteq> paxos_ref_rel `` init majorities.ts_mru_TS\"\n    by(auto simp add: Paxos_TS_defs majorities.ts_mru_TS_def paxos_ref_rel_def \n      majorities.ts_mru_init_def)\nnext\n  show \n    \"{paxos_ref_rel} TS.trans majorities.ts_mru_TS, \n      TS.trans (Paxos_TS HOs HOs crds) {> paxos_ref_rel}\"\n    apply(simp add: majorities.ts_mru_TS_defs Paxos_TS_defs)\n    apply(auto simp add: CHO_trans_alt Paxos_trans intro!: step0_ref step1_ref step2_ref)\n    done\nqed\n\nsubsubsection \\<open>Termination\\<close>\n(******************************************************************************)\n\ntheorem Paxos_termination:\n  assumes run: \"CHORun Paxos_Alg rho HOs crds\"\n      and commR: \"\\<forall>r. CHOcommPerRd Paxos_M r (HOs r) (crds r)\"\n      and commG: \"CHOcommGlobal Paxos_M HOs crds\"\n  shows \"\\<exists>r v. decide (rho r p) = Some v\"\nproof -\n  from commG obtain ph c where \n    HOs:\n       \"coord (nr_steps*ph) = c\n         \\<and> card (HOs (nr_steps*ph) c) > N div 2\n         \\<and> (\\<forall>p. c \\<in> HOs (nr_steps*ph+1) p)\n         \\<and> (\\<forall>p. card (HOs (nr_steps*ph+2) p) > N div 2)\"\n    by(auto simp add: Paxos_CHOMachine_def Paxos_commGlobal_def)\n\n  \\<comment> \\<open>The tedious bit: obtain three consecutive rounds linked by send/next functions\\<close>\n  define r0 where \"r0 = nr_steps * ph\"\n  define cfg0 where \"cfg0 = rho r0\"\n  define r1 where \"r1 = Suc r0\"\n  define cfg1 where \"cfg1 = rho r1\"\n  define r2 where \"r2 = Suc r1\"\n  define cfg2 where \"cfg2 = rho r2\"\n  define cfg3 where \"cfg3 = rho (Suc r2)\"\n\n  from   \n    run[simplified CHORun_def, THEN CSHORun_step, THEN spec, where x=\"r0\"] \n    run[simplified CHORun_def, THEN CSHORun_step, THEN spec, where x=\"r1\"]\n    run[simplified CHORun_def, THEN CSHORun_step, THEN spec, where x=\"r2\"] \n    obtain \\<mu>0 \\<mu>1 \\<mu>2 where\n    send0: \"\\<forall>p. \\<mu>0 p \\<in> get_msgs (send0 r0) cfg0 (HOs r0) (HOs r0) p\"\n    and three_step0: \"\\<forall>p. next0 r0 p (cfg0 p) (\\<mu>0 p) (crds (Suc r0) p) (cfg1 p)\"\n    and send1: \"\\<forall>p. \\<mu>1 p \\<in> get_msgs (send1 r1) cfg1 (HOs r1) (HOs r1) p\"\n    and three_step1: \"\\<forall>p. next1 r1 p (cfg1 p) (\\<mu>1 p) (crds (Suc r1) p) (cfg2 p)\"\n    and send2: \"\\<forall>p. \\<mu>2 p \\<in> get_msgs (send2 r2) cfg2 (HOs r2) (HOs r2) p\"\n    and three_step2: \"\\<forall>p. next2 r2 p (cfg2 p) (\\<mu>2 p) (crds (Suc r2) p) (cfg3 p)\"\n    apply(auto simp add: Paxos_Alg_def three_step_def Paxos_nextState_def Paxos_sendMsg_def all_conj_distrib\n      r0_def r1_def r2_def\n      cfg0_def cfg1_def cfg2_def cfg3_def mod_Suc\n      )\n    done\n    \n  \\<comment> \\<open>The proof: the coordinator hears enough messages in r0 and thus selects a value.\\<close>\n\n  from HOs three_step0[THEN spec, of c] send0[THEN spec, of c]\n    have \n    \"commt (cfg1 c) \\<noteq> None\"\n    by(auto simp add: next0_def Let_def r0_def get_msgs_dom)\n\n  then obtain dec_v where dec_v: \"commt (cfg1 c) = Some dec_v\"\n    by (metis option.collapse)\n\n  have step_r0: \"three_step r0 = 0\"\n    by(auto simp add: r0_def three_step_def)\n  hence same_coord: \n    \"coord r1 = coord r0\"\n    \"coord r2 = coord r0\"\n    by(auto simp add: three_step_phase_Suc r2_def r1_def r0_def intro!: coord_phase)\n\n  \\<comment> \\<open>All processes hear from the coordinator, and thus set their vote to @{term dec_v}.\\<close>  \n  hence all_vote: \"\\<forall>p. mru_vote (cfg2 p) = Some (three_phase r2, dec_v)\"\n    using HOs three_step1 send1 step_r0 dec_v\n    by(auto simp add: next1_def Let_def get_msgs_benign send1_def restrict_map_def isVote_def\n      r2_def r1_def r0_def[symmetric] same_coord[simplified r2_def r1_def] three_step_phase_Suc)\n\n  \\<comment> \\<open>And finally, everybody will also decide @{term dec_v}.\\<close>\n  have all_decide: \"\\<forall>p. decide (cfg3 p) = Some dec_v\"\n  proof\n    fix p\n    have \"votes_rcvd (\\<mu>2 p) = HOs r2 p \\<times> {dec_v}\" using send2[THEN spec, where x=p] all_vote\n      by(auto simp add: send2_def get_msgs_benign votes_rcvd_def restrict_map_def image_def o_def)\n\n    moreover from HOs have \"N div 2 < card (HOs r2 p)\"\n      by(auto simp add: r2_def r1_def r0_def)\n\n    moreover then have \"HOs r2 p \\<noteq> {}\"\n      by (metis card_empty less_nat_zero_code)\n    ultimately show \"decide (cfg3 p) = Some dec_v\" \n    using three_step2[THEN spec, where x=p] send2[THEN spec, where x=p] all_vote\n      by(auto simp add: next2_def send2_def Let_def get_msgs_benign \n        the_rcvd_vote_def restrict_map_def image_def o_def)\n  qed\n    \n  thus ?thesis \n    by(auto simp add: cfg3_def)\n\nqed\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Consensus_Refined/MRU/Paxos_Proofs.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297746074044134, "lm_q2_score": 0.43014734858584286, "lm_q1q2_score": 0.27089587758169853}}
{"text": "theory Events\n  imports\nMain\nIntegers\nFloats\nAST\nGlobalenvs\nbegin\n\nsection \\<open>Events and traces\\<close>\n\n(** The observable behaviour of programs is stated in terms of\n  input/output events, which represent the actions of the program\n  that the external world can observe.  CompCert leaves much flexibility as to\n  the exact content of events: the only requirement is that they\n  do not expose memory states nor pointer values\n  (other than pointers to global variables), because these\n  are not preserved literally during compilation.  For concreteness,\n  we use the following type for events.  Each event represents either:\n\n- A system call (e.g. an input/output operation), recording the\n  name of the system call, its parameters, and its result.\n\n- A volatile load from a global memory location, recording the chunk\n  and address being read and the value just read.\n\n- A volatile store to a global memory location, recording the chunk\n  and address being written and the value stored there.\n\n- An annotation, recording the text of the annotation and the values\n  of the arguments.\n\n  The values attached to these events are of the following form.\n  As mentioned above, we do not expose pointer values directly.\n  Pointers relative to a global variable are shown with the name\n  of the variable instead of the block identifier.\n*)\n\ndatatype eventval =\n  EVint m_int\n| EVlong m_int64\n| EVfloat float64\n| EVsingle float32\n| EVptr_global AST.ident m_ptrofs\n\ndatatype event =\n  Event_syscall string \"eventval list\" eventval\n| Event_vload memory_chunk AST.ident m_ptrofs eventval\n| Event_vstore memory_chunk AST.ident m_ptrofs eventval\n| Event_annot string \"eventval list\"\n\n(** The dynamic semantics for programs collect traces of events.\n  Traces are of two kinds: finite (type [trace]) or infinite (type [traceinf]). *)\n\ntype_synonym trace = \"event list\"\nabbreviation E0 :: trace where \"E0 \\<equiv> []\"\n\ncodatatype traceinf = Econsinf event traceinf\n\nfun Eappinf :: \"trace \\<Rightarrow> traceinf \\<Rightarrow> traceinf\" where\n  \"Eappinf [] T = T\"\n| \"Eappinf (ev # evs) T = Econsinf ev (Eappinf evs T)\"\n\nsection \\<open>Relating values and event values\\<close>\n\ncontext\n  fixes ge :: Senv_t\nbegin\n\n(** Validity *)\n\nfun eventval_valid :: \"eventval \\<Rightarrow> bool\" where\n  \"eventval_valid (EVint _) = True\"\n| \"eventval_valid (EVlong _) = True\"\n| \"eventval_valid (EVfloat _) = True\"\n| \"eventval_valid (EVsingle _) = True\"\n| \"eventval_valid (EVptr_global ident ofs) = (Senv.public_symbol ge ident = True)\"\n\nfun eventval_type :: \"eventval \\<Rightarrow> type\" where\n  \"eventval_type (EVint _) = Tint\"\n| \"eventval_type (EVlong _) = Tlong\"\n| \"eventval_type (EVfloat _) = Tfloat\"\n| \"eventval_type (EVsingle _) = Tsingle\"\n| \"eventval_type (EVptr_global ident ofs) = Tptr\"\n\nend\n\n(** Compatibility with memory injections *)\n\ndefinition symbols_inject :: \"(block \\<Rightarrow> (block * Z) option) \\<Rightarrow> Senv_t \\<Rightarrow> Senv_t \\<Rightarrow> bool\" where\n  \"symbols_inject f ge1 ge2 \\<equiv>\n    (\\<forall> ident. Senv.public_symbol ge2 ident = Senv.public_symbol ge1 ident)\n  \\<and> (\\<forall> ident b1 b2 delta.\n       f b1 = Some(b2, delta) \\<longrightarrow> Senv.find_symbol ge1 ident = Some b1 \\<longrightarrow>\n       delta = 0 \\<and> Senv.find_symbol ge2 ident = Some b2)\n  \\<and> (\\<forall> ident b1.\n       Senv.public_symbol ge1 ident = True \\<longrightarrow> Senv.find_symbol ge1 ident = Some b1 \\<longrightarrow>\n       (\\<exists> b2. f b1 = Some(b2, 0) \\<and> Senv.find_symbol ge2 ident = Some b2))\n  \\<and> (\\<forall> b1 b2 delta.\n       f b1 = Some(b2, delta) \\<longrightarrow>\n       Senv.block_is_volatile ge2 b2 = Senv.block_is_volatile ge1 b1)\"\n\nsection \\<open>Matching traces\\<close>\n\ncontext\n  fixes ge :: Senv_t\nbegin\n\n(** Matching between traces corresponding to single transitions.\n  Arguments (provided by the program) must be equal.\n  Results (provided by the outside world) can vary as long as they\n  can be converted safely to values. *)\n\ninductive match_traces :: \"trace \\<Rightarrow> trace \\<Rightarrow> bool\" where\n    match_traces_E0:\n      \"match_traces [] []\"\n  | match_traces_syscall:\n      \"eventval_valid ge res1 \\<Longrightarrow> eventval_valid ge res2 \\<Longrightarrow> eventval_type res1 = eventval_type res2 \\<Longrightarrow>\n      match_traces (Event_syscall ident args res1 # []) (Event_syscall ident args res2 # [])\"\n  | match_traces_vload:\n      \"eventval_valid ge res1 \\<Longrightarrow> eventval_valid ge res2 \\<Longrightarrow> eventval_type res1 = eventval_type res2 \\<Longrightarrow>\n      match_traces (Event_vload chunk ident ofs res1 # []) (Event_vload chunk ident ofs res2 # [])\"\n  | match_traces_vstore:\n      \"match_traces (Event_vstore chunk ident ofs a # []) (Event_vstore chunk ident ofs a # [])\"\n  | match_traces_annot:\n      \"match_traces (Event_annot ident args # []) (Event_annot ident args # [])\"\n\nend\n\nsection \\<open>Semantics of external functions\\<close>\n\n(** For each external function, its behavior is defined by a predicate relating:\n- the global symbol environment\n- the values of the arguments passed to this function\n- the memory state before the call\n- the result value of the call\n- the memory state after the call\n- the trace generated by the call (can be empty).\n*)\n\ntype_synonym extcall_sem = \"Senv_t \\<Rightarrow> val list \\<Rightarrow> mem \\<Rightarrow> trace \\<Rightarrow> val \\<Rightarrow> mem \\<Rightarrow> bool\"\n\n(** We now specify the expected properties of this predicate. *)\n\ndefinition loc_out_of_bounds :: \"mem \\<Rightarrow> block \\<Rightarrow> Z \\<Rightarrow> bool\" where\n  \"loc_out_of_bounds m b ofs \\<equiv> ~Mem.perm m b ofs Max Nonempty\"\n\ndefinition loc_not_writable :: \"mem \\<Rightarrow> block \\<Rightarrow> Z \\<Rightarrow> bool\" where\n  \"loc_not_writable m b ofs \\<equiv> ~Mem.perm m b ofs Max Writable\"\n\ndefinition loc_unmapped :: \"meminj \\<Rightarrow> block \\<Rightarrow> Z \\<Rightarrow> bool\" where\n  \"loc_unmapped f b ofs \\<equiv> f b = None\"\n\ndefinition loc_out_of_reach :: \"meminj \\<Rightarrow> mem \\<Rightarrow> block \\<Rightarrow> Z \\<Rightarrow> bool\" where\n  \"loc_out_of_reach f m b ofs \\<equiv>\n    \\<forall> b0 delta.\n    f b0 = Some(b, delta) \\<longrightarrow> ~Mem.perm m b0 (ofs - delta) Max Nonempty\"\n\ndefinition inject_separated :: \"meminj \\<Rightarrow> meminj \\<Rightarrow> mem \\<Rightarrow> mem \\<Rightarrow> bool\" where\n  \"inject_separated f f' m1 m2 \\<equiv>\n    \\<forall> b1 b2 delta.\n    f b1 = None \\<longrightarrow> f' b1 = Some(b2, delta) \\<longrightarrow>\n    ~Mem.valid_block m1 b1 \\<and> ~Mem.valid_block m2 b2\"\n\ncontext\n  fixes sem :: extcall_sem\n  fixes sg :: signature\nbegin\n\nnamed_theorems extcall_properties_defs'\n\n(** The return value of an external call must agree with its signature. *)\ndefinition [extcall_properties_defs']: \"ec_well_typed \\<equiv>\n  (\\<forall> ge vargs m1 t vres m2.\n    sem ge vargs m1 t vres m2 \\<longrightarrow>\n    Val.has_rettype vres (sig_res sg))\"\n\n(** The semantics is invariant under change of global environment that preserves symbols. *)\ndefinition [extcall_properties_defs']: \"ec_symbols_preserved \\<equiv>\n  (\\<forall> ge1 ge2 vargs m1 t vres m2.\n    Senv.equiv ge1 ge2 \\<longrightarrow>\n    sem ge1 vargs m1 t vres m2 \\<longrightarrow>\n    sem ge2 vargs m1 t vres m2)\"\n\n(** External calls cannot invalidate memory blocks.  (Remember that\n  freeing a block does not invalidate its block identifier.) *)\ndefinition [extcall_properties_defs']: \"ec_valid_block \\<equiv>\n  (\\<forall> ge vargs m1 t vres m2 b.\n    sem ge vargs m1 t vres m2 \\<longrightarrow>\n    Mem.valid_block m1 b \\<longrightarrow> Mem.valid_block m2 b)\"\n\n(** External calls cannot increase the max permissions of a valid block.\n    They can decrease the max permissions, e.g. by freeing. *)\ndefinition [extcall_properties_defs']: \"ec_max_perm \\<equiv>\n  (\\<forall> ge vargs m1 t vres m2 b ofs p.\n    sem ge vargs m1 t vres m2 \\<longrightarrow>\n    Mem.valid_block m1 b \\<longrightarrow> Mem.perm m2 b ofs Max p \\<longrightarrow> Mem.perm m1 b ofs Max p)\"\n\n(** External call cannot modify memory unless they have [Max, Writable]\n   permissions. *)\ndefinition [extcall_properties_defs']: \"ec_readonly \\<equiv>\n  (\\<forall> ge vargs m1 t vres m2 b ofs n bytes.\n    sem ge vargs m1 t vres m2 \\<longrightarrow>\n    Mem.valid_block m1 b \\<longrightarrow>\n    Mem.loadbytes m2 b ofs n = Some bytes \\<longrightarrow>\n    (\\<forall> i ofs. ofs <= i \\<and> i < ofs + n \\<longrightarrow> ~Mem.perm m1 b i Max Writable) \\<longrightarrow>\n    Mem.loadbytes m1 b ofs n = Some bytes)\"\n\n(** External calls must commute with memory extensions, in the\n  following sense. *)\ndefinition [extcall_properties_defs']: \"ec_mem_extends \\<equiv>\n  (\\<forall> ge vargs m1 t vres m2 m1' vargs'.\n    sem ge vargs m1 t vres m2 \\<longrightarrow>\n    Mem.extends m1 m1' \\<longrightarrow>\n    Val.lessdef_list vargs vargs' \\<longrightarrow>\n    (\\<exists> vres'. \\<exists> m2'.\n       sem ge vargs' m1' t vres' m2'\n    \\<and> Val.lessdef vres vres'\n    \\<and> Mem.extends m2 m2'\n    \\<and> Mem.unchanged_on (loc_out_of_bounds m1) m1' m2'))\"\n\n(** External calls must commute with memory injections,\n  in the following sense. *)\ndefinition [extcall_properties_defs']: \"ec_mem_inject \\<equiv>\n  (\\<forall> ge1 ge2 vargs m1 t vres m2 f m1' vargs'.\n    symbols_inject f ge1 ge2 \\<longrightarrow>\n    sem ge1 vargs m1 t vres m2 \\<longrightarrow>\n    Mem.inject f m1 m1' \\<longrightarrow>\n    Val.inject_list f vargs vargs' \\<longrightarrow>\n    (\\<exists> f' vres' m2'.\n       sem ge2 vargs' m1' t vres' m2'\n    \\<and> Val.inject f' vres vres'\n    \\<and> Mem.inject f' m2 m2'\n    \\<and> Mem.unchanged_on (loc_unmapped f) m1 m2\n    \\<and> Mem.unchanged_on (loc_out_of_reach f m1) m1' m2'\n    \\<and> inject_incr f f'\n    \\<and> inject_separated f f' m1 m1'))\"\n\n(** External calls produce at most one event. *)\ndefinition [extcall_properties_defs']: \"ec_trace_length \\<equiv>\n  (\\<forall> ge vargs m t vres m'.\n    sem ge vargs m t vres m' \\<longrightarrow> (length t \\<le> 1))\"\n\n(** External calls must be receptive to changes of traces by another, matching trace. *)\ndefinition [extcall_properties_defs']: \"ec_receptive \\<equiv>\n  (\\<forall> ge vargs m t1 vres1 m1 t2.\n    sem ge vargs m t1 vres1 m1 \\<longrightarrow> match_traces ge t1 t2 \\<longrightarrow>\n    (\\<exists> vres2. \\<exists> m2. sem ge vargs m t2 vres2 m2))\"\n\n(** External calls must be deterministic up to matching between traces. *)\ndefinition [extcall_properties_defs']: \"ec_determ \\<equiv>\n  (\\<forall> ge vargs m t1 vres1 m1 t2 vres2 m2.\n    sem ge vargs m t1 vres1 m1 \\<longrightarrow> sem ge vargs m t2 vres2 m2 \\<longrightarrow>\n    match_traces ge t1 t2 \\<and> (t1 = t2 \\<longrightarrow> vres1 = vres2 \\<and> m1 = m2))\"\n\ninductive extcall_properties where\n  \"\\<lbrakk> ec_well_typed;\n    ec_symbols_preserved;\n    ec_valid_block;\n    ec_max_perm;\n    ec_readonly;\n    ec_mem_extends;\n    ec_mem_inject;\n    ec_trace_length;\n    ec_receptive;\n    ec_determ \\<rbrakk> \\<Longrightarrow>\n  extcall_properties\"\n\nlemmas extcall_properties_def = extcall_properties_defs' extcall_properties.simps[simplified]\nend\n\nsubsection \\<open>Semantics of dynamic memory allocation (malloc)\\<close>\n\ninductive extcall_malloc_sem :: \"Senv_t \\<Rightarrow> val list \\<Rightarrow> mem \\<Rightarrow> trace \\<Rightarrow> val \\<Rightarrow> mem \\<Rightarrow> bool\" where\n    extcall_malloc_sem_intro:\n      \"Mem.alloc m (- size_chunk Mptr) (Int64.unsigned sz) = (m', b) \\<Longrightarrow>\n      Mem.store Mptr m' b (- size_chunk Mptr) (Vptrofs sz) = Some m'' \\<Longrightarrow>\n      extcall_malloc_sem ge [Vptrofs sz] m E0 (Vptr b 0) m''\"\n\nlemma extcall_malloc_unchanged_on:\n  assumes \"Mem.mem_invariants m\"\n  assumes \"extcall_malloc_sem ge vargs m t vres m''\"\n  shows \"extcall_malloc_sem ge vargs m t vres m'' \\<and> Mem.unchanged_on P m m''\"\n  apply (simp add: assms(2))\n  using assms(2)\nproof (cases rule: extcall_malloc_sem.cases)\n  case (extcall_malloc_sem_intro sz m' b)\n\n  from \\<open>Mem.alloc m (- size_chunk Mptr) (Int64.unsigned sz) = (m', b)\\<close>\n  have b'b: \"\\<And>b'. Mem.valid_block m b' \\<Longrightarrow> b' \\<noteq> b\"\n    using Mem.alloc_valid_block(2) by auto\n\n  have unchanged1: \"Mem.unchanged_on P m m'\"\n    using Mem.alloc_unchanged_on assms(1) local.extcall_malloc_sem_intro(4) by auto\n\n  from \\<open>Mem.store Mptr m' b (- size_chunk Mptr) (Vptrofs sz) = Some m''\\<close>\n  have unchanged2: \"Mem.unchanged_on (\\<lambda>b ofs. P b ofs \\<and> Mem.valid_block m b) m' m''\"\n    apply (rule Mem.store_unchanged_on)\n    using b'b by simp\n\n  note rule = Mem.unchanged_on_trans[OF assms(1), OF unchanged1 unchanged2]\n\n  then show \"Mem.unchanged_on P m m''\"\n    by simp\nqed\n\nlemma extcall_malloc_ok:\n  \"extcall_properties extcall_malloc_sem\n                     (mksignature (Tptr # []) (Tret Tptr) cc_default)\"\n  unfolding extcall_properties_def\n  apply (safe elim!: extcall_malloc_sem.cases intro: extcall_malloc_sem_intro)\nproof (goal_cases)\n  case (1 ge vargs m1 t vres m2 m sz m' b m'' gea)\n  then show ?case\n    by (simp add: signature.defs)\nnext\n  case (2 ge1 ge2 vargs m1 t vres m2 m sz m' b m'' ge)\n  then show ?case\n    using \"2\"(2) \"2\"(3) extcall_malloc_sem_intro by blast\nnext\n  case (3 ge vargs m1 t vres m2 b m sz m' ba m'' gea)\n\n  then show ?case\n    by (meson Mem'.alloc_valid_block(1) Mem'.store_valid_block)\nnext\n  case (4 ge vargs m1 t vres m2 b ofs p m sz m' ba m'' gea)\n\n  then show ?case\n    by (meson Mem.alloc_max_perm Mem.store_max_perm)\nnext\n  case (5 ge vargs m1 t vres m2 b ofs n bytes m sz m' ba m'' gea)\n  then show ?case sorry\nnext\n  case (6 ge vargs m1 t vres m2 m1' vargs' m sz m' b m'' gea)\n  then show ?case sorry\nnext\n  case (7 ge1 ge2 vargs m1 t vres m2 f m1' vargs' m sz m' b m'' ge)\n  then show ?case sorry\nnext\n  case (8 ge vargs m t vres m' ma sz m'a b m'' gea)\nthen show ?case sorry\nnext\n  case (9 ge vargs m t1 vres1 m1 t2 ma sz m' b m'' gea)\n  then show ?case sorry\nnext\n  case (10 ge vargs m t1 vres1 m1 t2 vres2 m2 ma sz m' b m'' gea mb sza m'a ba m''a geb)\n  then show ?case sorry\nnext\n  case (11 ge vargs m t1 vres1 m1 t2 vres2 m2 ma sz m' b m'' gea mb sza m'a ba m''a geb)\n  then show ?case sorry\nnext\n  case (12 ge vargs m t1 vres1 m1 t2 vres2 m2 ma sz m' b m'' gea mb sza m'a ba m''a geb)\n  then show ?case sorry\nqed\n\nsubsection \\<open>Semantics of dynamic memory deallocation (free)\\<close>\n\ninductive extcall_free_sem :: \"Senv_t \\<Rightarrow> val list \\<Rightarrow> mem \\<Rightarrow> trace \\<Rightarrow> val \\<Rightarrow> mem \\<Rightarrow> bool\" where\n    extcall_free_sem_ptr:\n      \"Mem.load Mptr m b (Int64.unsigned lo - size_chunk Mptr) = Some (Vptrofs sz) \\<Longrightarrow>\n      Int64.unsigned sz > 0 \\<Longrightarrow>\n      Mem.free m b (Int64.unsigned lo - size_chunk Mptr) (Int64.unsigned lo + Int64.unsigned sz) = Some m' \\<Longrightarrow>\n      extcall_free_sem ge (Vptr b lo # []) m E0 Vundef m'\"\n  | extcall_free_sem_null:\n      \"extcall_free_sem ge (Vnullptr # []) m E0 Vundef m\"\n\nlemma extcall_free_ok:\n  \"extcall_properties extcall_free_sem\n                     (mksignature (Tptr # []) (Tvoid) cc_default)\"\n  sorry\n\nsubsection \\<open>Semantics of [memcpy] operations\\<close>\n\ninductive extcall_memcpy_sem :: \"Z \\<Rightarrow> Z \\<Rightarrow> Senv_t \\<Rightarrow> val list \\<Rightarrow> mem \\<Rightarrow> trace \\<Rightarrow> val \\<Rightarrow> mem \\<Rightarrow> bool\" where\n    extcall_memcpy_sem_intro:\n      \"al = 1 \\<or> al = 2 \\<or> al = 4 \\<or> al = 8 \\<Longrightarrow> sz \\<ge> 0 \\<Longrightarrow> (al dvd sz) \\<Longrightarrow>\n      (sz > 0 \\<Longrightarrow> (al dvd Int64.unsigned osrc)) \\<Longrightarrow>\n      (sz > 0 \\<Longrightarrow> (al dvd Int64.unsigned odst)) \\<Longrightarrow>\n      bsrc \\<noteq> bdst \\<or> Int64.unsigned osrc = Int64.unsigned odst\n                   \\<or> Int64.unsigned osrc + sz <= Int64.unsigned odst\n                   \\<or> Int64.unsigned odst + sz <= Int64.unsigned osrc \\<Longrightarrow>\n      Mem.loadbytes m bsrc (Int64.unsigned osrc) sz = Some bytes \\<Longrightarrow>\n      Mem.storebytes m bdst (Int64.unsigned odst) bytes = Some m' \\<Longrightarrow>\n      extcall_memcpy_sem sz al ge (Vptr bdst odst # Vptr bsrc osrc # []) m E0 Vundef m'\"\n\nlemma extcall_memcpy_ok:\n  \"extcall_properties (extcall_memcpy_sem sz al)\n                     (mksignature (Tptr # Tptr # []) (Tvoid) cc_default)\"\n  sorry\n\n(** Combining the semantics given above for the various kinds of external calls,\n  we define the predicate [external_call] that relates:\n- the external function being invoked\n- the values of the arguments passed to this function\n- the memory state before the call\n- the result value of the call\n- the memory state after the call\n- the trace generated by the call (can be empty).\n\nThis predicate is used in the semantics of all CompCert languages. *)\n\ninductive extcall_dummy_sem :: \"extcall_sem\" where\n    extcall_dummy_sem_intro: \"extcall_dummy_sem ge args m E0 sp m\"\n\nfun external_call :: \"external_function \\<Rightarrow> extcall_sem\" where\n(* TODO: not implemented for now\n  \"external_call (EF_external name sg) = external_functions_sem name sg\"\n| \"external_call (EF_builtin name sg) = builtin_or_external_sem name sg\"\n| \"external_call (EF_runtime name sg) = builtin_or_external_sem name sg\"\n| \"external_call (EF_vload chunk) = volatile_load_sem chunk\"\n| \"external_call (EF_vstore chunk) = volatile_store_sem chunk\" *)\n  \"external_call EF_malloc = extcall_malloc_sem\"\n| \"external_call EF_free = extcall_free_sem\"\n| \"external_call (EF_memcpy sz al) = extcall_memcpy_sem sz al\"\n(* TODO: not implemented for now\n| \"external_call (EF_annot kind txt targs) = extcall_annot_sem txt targs\"\n| \"external_call (EF_annot_val kind txt targ) = extcall_annot_val_sem txt targ\"\n| \"external_call (EF_inline_asm txt sg clb) = inline_assembly_sem txt sg\"\n| \"external_call (EF_debug kind txt targs) = extcall_debug_sem\" *)\n\nlemmas extcall_simps =\n  extcall_malloc_sem.simps extcall_free_sem.simps extcall_memcpy_sem.simps\nlemmas extcall_intros =\n  extcall_malloc_sem.intros extcall_free_sem.intros extcall_memcpy_sem.intros\n\nlemmas external_call_intros = extcall_intros[folded external_call.simps]\n\nlemma external_call_spec:\n  \"extcall_properties (external_call ef) (ef_sig ef)\"\n  apply (cases ef)\n  using extcall_malloc_ok extcall_free_ok extcall_memcpy_ok\n  by auto\n\ndefinition \"external_call_well_typed_gen ef \\<equiv> ec_well_typed (external_call ef) (ef_sig ef)\"\ndefinition \"external_call_symbols_preserved ef \\<equiv> ec_symbols_preserved (external_call ef)\"\ndefinition \"external_call_valid_block ef \\<equiv> ec_valid_block (external_call ef)\"\ndefinition \"external_call_max_perm ef \\<equiv> ec_max_perm (external_call ef)\"\ndefinition \"external_call_readonly ef \\<equiv> ec_readonly (external_call ef)\"\ndefinition \"external_call_mem_extends ef \\<equiv> ec_mem_extends (external_call ef)\"\ndefinition \"external_call_mem_inject_gen ef \\<equiv> ec_mem_inject (external_call ef)\"\ndefinition \"external_call_trace_length ef \\<equiv> ec_trace_length (external_call ef)\"\ndefinition \"external_call_receptive ef \\<equiv> ec_receptive (external_call ef)\"\ndefinition \"external_call_determ ef \\<equiv> ec_determ (external_call ef)\"\n\n(** Corollaries of [external_call_determ]. *)\n\nlemma external_call_match_traces:\n  assumes \"external_call ef ge vargs m t1 vres1 m1\"\n  assumes \"external_call ef ge vargs m t2 vres2 m2\"\n  shows \"match_traces ge t1 t2\"\nproof -\n  have \"external_call_determ ef\"\n    unfolding external_call_determ_def\n    using extcall_properties.cases external_call_spec by auto\n\n  then show ?thesis\n    unfolding external_call_determ_def ec_determ_def\n    using assms by simp\nqed\n\nlemma external_call_deterministic:\n  assumes \"external_call ef ge vargs m t vres1 m1\"\n  assumes \"external_call ef ge vargs m t vres2 m2\"\n  shows \"vres1 = vres2 \\<and> m1 = m2\"\nproof -\n  have \"external_call_determ ef\"\n    unfolding external_call_determ_def\n    using extcall_properties.cases external_call_spec by auto\n\n  then show ?thesis\n    unfolding external_call_determ_def ec_determ_def\n    using assms by simp\nqed\n\nsection \\<open>Additions\\<close>\n\n(* modeling results of deterministic external_calls *)\ndefinition external_call_result :: \"external_function \\<Rightarrow> Senv_t \\<Rightarrow> val list \\<Rightarrow> mem \\<Rightarrow> (event list \\<times> val \\<times> mem) option\" where\n  \"external_call_result ef ge vargs m \\<equiv>\n    if \\<exists>t vres m'. external_call ef ge vargs m t vres m'\n    then Some (THE (t, vres, m'). external_call ef ge vargs m t vres m')\n    else None\"\n\ndeclare external_call_result_def[code del]\n\nlemma external_call_resultI:\n  assumes \"\\<And>t vres m'. external_call ef ge vargs m t vres m' \\<Longrightarrow> res_fun ge vargs m = Some (t, vres, m')\"\n  assumes \"(\\<And>t vres m'. \\<not>external_call ef ge vargs m t vres m') \\<Longrightarrow> res_fun ge vargs m = None\"\n  shows \"external_call_result ef ge vargs m = res_fun ge vargs m\"\n  unfolding external_call_result_def\n  apply (split if_splits)\n  by (smt (z3) Collect_cong The_split_eq assms(1) assms(2) case_prodE case_prodI in_rel_Collect_case_prod_eq option.inject)\n\nprint_statement extcall_malloc_sem.simps[simplified]\n\nlemma extcall_malloc_result:\n  notes align_Mptr = align_dvd_size_mult[of Mptr \"-1\"]\n  notes store_valid = Mem.store_after_alloc[OF _ _ _ align_Mptr]\n  shows\n    \"external_call_result EF_malloc ge [Vptrofs sz] m =\n      (case Mem.alloc m (- size_chunk Mptr) (Int64.unsigned sz) of (m', b) \\<Rightarrow>\n      (case Mem.store Mptr m' b (- size_chunk Mptr) (Vptrofs sz) of Some m'' \\<Rightarrow>\n      Some (E0, Vptr b 0, m'') | _ \\<Rightarrow> None))\"\n  apply (rule external_call_resultI; split prod.splits; split option.splits)\n   apply (simp)\n   apply (erule extcall_malloc_sem.cases)\n  unfolding Vptrofs_def\n   apply force\n  using Vptrofs_def extcall_malloc_sem_intro by fastforce\n\nprint_statement extcall_free_sem.simps[simplified]\n\nlemma extcall_free_result:\n  shows\n    \"external_call_result EF_free ge vargs m =\n      (if vargs = [Vnullptr] then Some (E0, Vundef, m) else\n      (case vargs of [Vptr b lo] \\<Rightarrow>\n      (case Mem.load Mptr m b (Int64.unsigned lo - size_chunk Mptr) of Some (Vlong sz) \\<Rightarrow>\n      (if Int64.unsigned sz = 0 then None else\n      (case Mem.free m b (Int64.unsigned lo - size_chunk Mptr) (Int64.unsigned lo + Int64.unsigned sz) of Some m' \\<Rightarrow>\n      Some (E0, Vundef, m') | _ \\<Rightarrow> None)) | _ \\<Rightarrow> None) | _ \\<Rightarrow> None))\"\n  apply (rule external_call_resultI)\n   apply (auto elim!: extcall_free_sem.cases split: option.splits val.splits if_splits list.splits simp: Vptrofs_def Vnullptr_def)\n   apply (metis Vnullptr_def extcall_free_sem_null)\n  apply (simp add: extcall_free_sem.simps)\n  unfolding Vptrofs_def Vnullptr_def\n  by (metis linorder_neqE_linordered_idom uint_lt_0)\n\nprint_statement extcall_memcpy_sem.simps[simplified]\n\nlemma extcall_memcpy_result:\n  shows\n    \"external_call_result (EF_memcpy sz al) ge vargs m =\n      (case vargs of [Vptr bdst odst, Vptr bsrc osrc] \\<Rightarrow>\n      (if a2 = 1 \\<or> a2 = 2 \\<or> a2 = 4 \\<or> a2 = 8 then\n      (if 0 \\<le> sz \\<or> (al dvd sz) then\n      (if 0 < a1 \\<longrightarrow> a2 dvd Int64.unsigned osrc then\n      (if 0 < a1 \\<longrightarrow> a2 dvd Int64.unsigned odst then\n      (if bsrc = bdst \\<longrightarrow>\n          Int64.unsigned osrc = Int64.unsigned odst \\<or>\n          Int64.unsigned osrc + a1 \\<le> Int64.unsigned odst \\<or>\n          Int64.unsigned odst + a1 \\<le> Int64.unsigned osrc then\n      (case Mem.loadbytes m bsrc (Int64.unsigned osrc) sz of Some bytes \\<Rightarrow>\n      (case Mem.storebytes m bdst (Int64.unsigned odst) bytes of Some m' \\<Rightarrow>\n      Some (E0, Vundef, m') | _ \\<Rightarrow> None) | _ \\<Rightarrow> None) else None) else None) else None) else None) else None) | _ \\<Rightarrow> None)\"\nproof -\n  {\n    fix osrc odst bsrc bdst bytes m'\n\n    assume [simp]: \"vargs = [Vptr bdst odst, Vptr bsrc osrc]\"\n    assume [iff]: \"a2 = 1 \\<or> a2 = 2 \\<or> a2 = 4 \\<or> a2 = 8\"\n    assume sz[iff]: \"0 \\<le> sz \\<or> (al dvd sz)\"\n    assume [iff]: \"0 < a1 \\<longrightarrow> a2 dvd Int64.unsigned osrc\"\n    assume [iff]: \"0 < a1 \\<longrightarrow> a2 dvd Int64.unsigned odst\"\n    assume [iff]: \"bsrc = bdst \\<longrightarrow>\n          Int64.unsigned osrc = Int64.unsigned odst \\<or>\n          Int64.unsigned osrc + a1 \\<le> Int64.unsigned odst \\<or>\n          Int64.unsigned odst + a1 \\<le> Int64.unsigned osrc\"\n\n    assume bytes[simp]: \"Mem.loadbytes m bsrc (Int64.unsigned osrc) sz = Some bytes\"\n    assume m'[simp]: \"Mem.storebytes m bdst (Int64.unsigned odst) bytes = Some m'\"\n\n    have bytes_len[simp]: \"length bytes = nat sz\"\n      using Mem.loadbytes_len[OF bytes]\n      by simp\n\n    have sz_0[iff]: \"sz = 0 \\<Longrightarrow> m' = m\"\n      using Mem.storebytes_0 Mem.loadbytes_0 bytes m' by auto\n\n    then have ?thesis\n      apply (simp)\n      sorry\n  }\n\n  then show ?thesis\n    sorry\n\nqed\n\nsubsection \\<open>Determinism\\<close>\n\n(*\n  all external calls are guaranteed to be deterministic modulo their trace;\n  so extcalls not generating a trace are fully deterministic\n*)\n\ndefinition \"determ_extfun ef \\<equiv>\n  \\<forall>ge vargs m t vres m'. (external_call ef ge vargs m t vres m' \\<longrightarrow> t = E0)\"\n\n(* for now, all the external functions we implement are deterministic *)\nlemma determ_extfun[iff]: \"determ_extfun ef\"\n  unfolding determ_extfun_def\n  apply (cases ef)\n  by (auto elim: extcall_malloc_sem.cases extcall_free_sem.cases extcall_memcpy_sem.cases)\n\nlemma determ_extfun_notrace:\n  \"determ_extfun ef \\<Longrightarrow> external_call ef ge vargs m t vres m' \\<Longrightarrow> t = E0\"\n  unfolding determ_extfun_def\n  by blast\n\nlemma extcall_determ:\n  assumes \"determ_extfun ef\"\n  assumes \"external_call ef ge vargs m t vres m'\"\n  shows \"external_call ef ge vargs m t' vres' m'' \\<Longrightarrow> t' = t \\<and> vres' = vres \\<and> m'' = m'\"\n  using determ_extfun_notrace[OF assms]\n  using assms(1) assms(2) determ_extfun_notrace external_call_deterministic by blast\n\nsubsection \\<open>Equivalance\\<close>\n\nlemma extcall_result_equiv:\n  assumes \"determ_extfun ef\"\n  shows\n    \"external_call ef ge vargs m t vres m' \\<longleftrightarrow> external_call_result ef ge vargs m = Some (t, vres, m')\"\n  unfolding external_call_result_def\n  apply standard\n  using extcall_determ apply auto[1]\n  apply (auto split: if_splits)\n  by (smt (verit, ccfv_threshold) assms case_prodD case_prodE case_prodI extcall_determ theI')\n\nsubsection \\<open>Deterministic world\\<close>\n\nlocale deterministic_world\nbegin\nlemmas extcall_determ = extcall_determ[OF determ_extfun]\nlemmas extcall_result_equiv = extcall_result_equiv[OF determ_extfun]\nend\n\nend", "meta": {"author": "mckirk", "repo": "Isabelle_Cminor", "sha": "76ae3d8bb8f84fefdf67f028f2db08020a79ceb1", "save_path": "github-repos/isabelle/mckirk-Isabelle_Cminor", "path": "github-repos/isabelle/mckirk-Isabelle_Cminor/Isabelle_Cminor-76ae3d8bb8f84fefdf67f028f2db08020a79ceb1/theory/compcert/Events.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.27073872122213755}}
{"text": "theory Simple_Network_Language_Model_Checking\n  imports TA_Library.Temporal_Logics Simple_Network_Language_Impl_Refine\n    Uppaal_Networks.UPPAAL_Model_Checking TA_Library.Abstract_Term\nbegin\n\nsection \\<open>Product Bisimulation\\<close>\n\nno_notation State_Networks.step_sn (\"_ \\<turnstile> \\<langle>_, _, _\\<rangle> \\<rightarrow>\\<^bsub>_\\<^esub> \\<langle>_, _, _\\<rangle>\" [61,61,61,61,61] 61)\n\ntext \\<open>\n  We have proved the necessary theorems already but we need to lift it to\n  the case where delay and action transitions are strictly alternating.\n\\<close>\ninductive step_u' ::\n  \"('a, 's, 'c, 't :: time, 'x, 'v :: linorder) nta \\<Rightarrow> 's list \\<Rightarrow> ('x \\<rightharpoonup> 'v) \\<Rightarrow> ('c, 't) cval\n  \\<Rightarrow> 's list \\<Rightarrow> ('x \\<rightharpoonup> 'v) \\<Rightarrow> ('c, 't) cval \\<Rightarrow> bool\"\n(\"_ \\<turnstile> \\<langle>_, _, _\\<rangle> \\<rightarrow> \\<langle>_, _, _\\<rangle>\" [61,61,61,61] 61) where\n  \"A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow> \\<langle>L'', s'', u''\\<rangle>\" if\n  \"A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>Del\\<^esub> \\<langle>L', s', u'\\<rangle>\"\n  \"a \\<noteq> Del\"\n  \"A \\<turnstile> \\<langle>L', s', u'\\<rangle> \\<rightarrow>\\<^bsub>a\\<^esub> \\<langle>L'', s'', u''\\<rangle>\"\n\ninductive_cases step'_elims: \"A \\<turnstile>' \\<langle>(L, s), u\\<rangle> \\<rightarrow> \\<langle>(L', s'), u'\\<rangle>\"\n\ninductive_cases step_u'_elims: \"A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow> \\<langle>L', s', u'\\<rangle>\"\n\ntheorem Bisimulation_Invariant_strong_intro:\n  fixes A :: \"'a \\<Rightarrow> 'a \\<Rightarrow> bool\"\n    and P :: \"'a \\<Rightarrow> bool\"\n    and B :: \"'a \\<Rightarrow> 'a \\<Rightarrow> bool\"\n  assumes \"\\<And>a b. A a b \\<Longrightarrow> P a \\<Longrightarrow> B a b\"\n    and \"\\<And>a b. B a b \\<Longrightarrow> P a \\<Longrightarrow> A a b\"\n    and \"\\<And>a b. P a \\<Longrightarrow> A a b \\<Longrightarrow> P b\"\n  shows \"Bisimulation_Invariant A B (=) P P\"\n  apply standard\n  subgoal A for a b a'\n    by (blast intro: assms)\n  subgoal B for a b a'\n    by (blast intro: assms)\n  subgoal C for a b\n    by (rule assms)\n  subgoal D for a b\n    by (rule C, assumption) (rule assms)\n  done\n\ncontext Prod_TA_Defs\nbegin\n\ndefinition\n  \"all_prop L s = (L \\<in> states \\<and> bounded bounds s)\"\n\nlemma all_prop_boundedD[dest]:\n  \"bounded bounds s\" if \"all_prop L s\"\n  using that unfolding all_prop_def ..\n\nlemma all_prop_statesD[dest]:\n  \"L \\<in> states\" if \"all_prop L s\"\n  using that unfolding all_prop_def ..\n\nend (* Prod TA Defs *)\n\n\ncontext Prod_TA\nbegin\n\nlemma prod_action_step_not_eq_delay:\n  \"a \\<noteq> Del\" if \"prod_ta \\<turnstile> \\<langle>(L, s), u\\<rangle> \\<rightarrow>\\<^bsub>a\\<^esub> \\<langle>(L', s'), u'\\<rangle>\"\n  using that\n  apply cases\n  unfolding trans_of_def\n  unfolding prod_ta_def trans_prod_def\n  by (auto simp: trans_int_def trans_bin_def trans_broad_def)\n\nend\n\nlocale Prod_TA_urge =\n  Prod_TA + assumes urgency_removed: \"\\<forall>N \\<in> set (fst (snd A)). urgent N = {}\"\nbegin\n\nlemma prod_all_prop_inv:\n  \"all_prop L' s'\" if \"all_prop L s\" \"prod_ta \\<turnstile> \\<langle>(L, s), u\\<rangle> \\<rightarrow> \\<langle>(L', s'), u'\\<rangle>\"\n  using that unfolding all_prop_def\n  by (auto elim: bounded_inv states_inv simp: step_iff[symmetric, OF _ _ urgency_removed])\n\nlemma prod_all_prop_inv':\n  \"all_prop L' s'\" if \"all_prop L s\" \"prod_ta \\<turnstile>' \\<langle>(L, s), u\\<rangle> \\<rightarrow> \\<langle>(L', s'), u'\\<rangle>\"\n  using that by (auto intro: prod_all_prop_inv elim!: step'_elims)\n\ninterpretation prod_bisim:\n  Bisimulation_Invariant\n  \"(\\<lambda> (L, s, u) (L', s', u'). prod_ta \\<turnstile>' \\<langle>(L, s), u\\<rangle> \\<rightarrow> \\<langle>(L', s'), u'\\<rangle>)\"\n  \"(\\<lambda> (L, s, u) (L', s', u'). A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow> \\<langle>L', s', u'\\<rangle>)\"\n  \"(=)\"\n  \"(\\<lambda> (L, s, u). all_prop L s)\"\n  \"(\\<lambda> (L, s, u). all_prop L s)\"\n  apply (rule Bisimulation_Invariant_strong_intro; clarsimp)\n  subgoal\n    by (auto intro: step_u'.intros simp: all_prop_def\n             dest: action_sound prod_action_step_not_eq_delay delay_sound[OF _ _ _ urgency_removed]\n             elim!: step'_elims)\n  subgoal\n    by (auto 4 4 dest: prod_all_prop_inv action_complete elim: delay_complete elim!: step_u'_elims)\n  subgoal\n    by (rule prod_all_prop_inv')\n  done\n\nlemmas prod_bisim_intro = prod_bisim.Bisimulation_Invariant_axioms\n\nend (* Prod TA *)\n\n\nsection \\<open>The final semantics\\<close>\n\ntext \\<open>State formulas\\<close>\ndatatype ('n, 's, 'a, 'b) sexp =\n  true |\n  \\<comment> \\<open>Boolean connectives\\<close>\n  not \"('n, 's, 'a, 'b) sexp\" | \"and\" \"('n, 's, 'a, 'b) sexp\" \"('n, 's, 'a, 'b) sexp\" |\n  or \"('n, 's, 'a, 'b) sexp\" \"('n, 's, 'a, 'b) sexp\" | imply \"('n, 's, 'a, 'b) sexp\" \"('n, 's, 'a, 'b) sexp\" |\n  \\<comment> \\<open>Does var \\<open>a\\<close> equal \\<open>x\\<close>?\\<close>\n  eq 'a 'b |\n  le 'a 'b |\n  lt 'a 'b |\n  ge 'a 'b |\n  gt 'a 'b |\n  \\<comment> \\<open>Is procces \\<open>i\\<close> in location \\<open>l\\<close>?\\<close>\n  loc 'n 's\n\ndatatype ('n, 's, 'a, 'b) formula =\n  EX \"('n, 's, 'a, 'b) sexp\" | EG \"('n, 's, 'a, 'b) sexp\"\n| AX \"('n, 's, 'a, 'b) sexp\" | AG \"('n, 's, 'a, 'b) sexp\"\n| Leadsto \"('n, 's, 'a, 'b) sexp\" \"('n, 's, 'a, 'b) sexp\"\n\nfun check_sexp :: \"(nat, 's, 'a, 'b :: linorder) sexp \\<Rightarrow> 's list \\<Rightarrow> ('a \\<Rightarrow> 'b) \\<Rightarrow> bool\" where\n  \"check_sexp sexp.true _ _ \\<longleftrightarrow> True\" |\n  \"check_sexp (not e) L s \\<longleftrightarrow> \\<not> check_sexp e L s\" |\n  \"check_sexp (and e1 e2) L s \\<longleftrightarrow> check_sexp e1 L s \\<and> check_sexp e2 L s\" |\n  \"check_sexp (sexp.or e1 e2) L s \\<longleftrightarrow> check_sexp e1 L s \\<or> check_sexp e2 L s\" |\n  \"check_sexp (imply e1 e2) L s \\<longleftrightarrow> check_sexp e1 L s \\<longrightarrow> check_sexp e2 L s\" |\n  \"check_sexp (eq i x) L s \\<longleftrightarrow> s i = x\" |\n  \"check_sexp (le i x) L s \\<longleftrightarrow> s i \\<le> x\" |\n  \"check_sexp (lt i x) L s \\<longleftrightarrow> s i < x\" |\n  \"check_sexp (ge i x) L s \\<longleftrightarrow> s i \\<ge> x\" |\n  \"check_sexp (gt i x) L s \\<longleftrightarrow> s i > x\" |\n  \"check_sexp (loc i x) L s \\<longleftrightarrow> L ! i = x\"\n\nfun locs_of_sexp :: \"('n, 's, 'a, 'b) sexp \\<Rightarrow> 'n set\" where\n  \"locs_of_sexp (not e) = locs_of_sexp e\" |\n  \"locs_of_sexp (and e1 e2) = locs_of_sexp e1 \\<union> locs_of_sexp e2\" |\n  \"locs_of_sexp (sexp.or e1 e2) = locs_of_sexp e1 \\<union> locs_of_sexp e2\" |\n  \"locs_of_sexp (imply e1 e2) = locs_of_sexp e1 \\<union> locs_of_sexp e2\" |\n  \"locs_of_sexp (loc i x) = {i}\" |\n  \"locs_of_sexp _ = {}\"\n\nfun vars_of_sexp :: \"('n, 's, 'a, 'b) sexp \\<Rightarrow> 'a set\" where\n  \"vars_of_sexp (not e) = vars_of_sexp e\" |\n  \"vars_of_sexp (and e1 e2) = vars_of_sexp e1 \\<union> vars_of_sexp e2\" |\n  \"vars_of_sexp (sexp.or e1 e2) = vars_of_sexp e1 \\<union> vars_of_sexp e2\" |\n  \"vars_of_sexp (imply e1 e2) = vars_of_sexp e1 \\<union> vars_of_sexp e2\" |\n  \"vars_of_sexp (eq i x) = {i}\" |\n  \"vars_of_sexp (lt i x) = {i}\" |\n  \"vars_of_sexp (le i x) = {i}\" |\n  \"vars_of_sexp (ge i x) = {i}\" |\n  \"vars_of_sexp (gt i x) = {i}\" |\n  \"vars_of_sexp _ = {}\"\n\nfun locs_of_formula :: \"('n, 's, 'a, 'b) formula \\<Rightarrow> 'n set\" where\n  \"locs_of_formula (formula.EX \\<phi>) = locs_of_sexp \\<phi>\" |\n  \"locs_of_formula (EG \\<phi>) = locs_of_sexp \\<phi>\" |\n  \"locs_of_formula (AX \\<phi>) = locs_of_sexp \\<phi>\" |\n  \"locs_of_formula (AG \\<phi>) = locs_of_sexp \\<phi>\" |\n  \"locs_of_formula (Leadsto \\<phi> \\<psi>) = locs_of_sexp \\<phi> \\<union> locs_of_sexp \\<psi>\"\n\nfun vars_of_formula :: \"('n, 's, 'a, 'b) formula \\<Rightarrow> 'a set\" where\n  \"vars_of_formula (formula.EX \\<phi>) = vars_of_sexp \\<phi>\" |\n  \"vars_of_formula (EG \\<phi>) = vars_of_sexp \\<phi>\" |\n  \"vars_of_formula (AX \\<phi>) = vars_of_sexp \\<phi>\" |\n  \"vars_of_formula (AG \\<phi>) = vars_of_sexp \\<phi>\" |\n  \"vars_of_formula (Leadsto \\<phi> \\<psi>) = vars_of_sexp \\<phi> \\<union> vars_of_sexp \\<psi>\"\n\nfun hd_of_formula :: \"(nat, 's, 'a, 'b) formula \\<Rightarrow> 's list \\<Rightarrow> ('a \\<Rightarrow> 'b :: linorder) \\<Rightarrow> bool\" where\n  \"hd_of_formula (formula.EX \\<phi>) L s = check_sexp \\<phi> L s\" |\n  \"hd_of_formula (EG \\<phi>) L s = check_sexp \\<phi> L s\" |\n  \"hd_of_formula (AX \\<phi>) L s = Not (check_sexp \\<phi> L s)\" |\n  \"hd_of_formula (AG \\<phi>) L s = Not (check_sexp \\<phi> L s)\" |\n  \"hd_of_formula (Leadsto \\<phi> _) L s = check_sexp \\<phi> L s\"\n\ndefinition models (\"_,_ \\<Turnstile> _\" [61,61] 61) where\n  \"A,a\\<^sub>0 \\<Turnstile> \\<Phi> \\<equiv> (case \\<Phi> of\n    formula.EX \\<phi> \\<Rightarrow>\n      Graph_Defs.Ex_ev\n        (\\<lambda> (L, s, u) (L', s', u'). A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow> \\<langle>L', s', u'\\<rangle>)\n        (\\<lambda> (L, s, _). check_sexp \\<phi> L (the o s))\n  | formula.EG \\<phi> \\<Rightarrow>\n      Graph_Defs.Ex_alw\n        (\\<lambda> (L, s, u) (L', s', u'). A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow> \\<langle>L', s', u'\\<rangle>)\n        (\\<lambda> (L, s, _). check_sexp \\<phi> L (the o s))\n  | formula.AX \\<phi> \\<Rightarrow>\n      Graph_Defs.Alw_ev\n        (\\<lambda> (L, s, u) (L', s', u'). A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow> \\<langle>L', s', u'\\<rangle>)\n        (\\<lambda> (L, s, _). check_sexp \\<phi> L (the o s))\n  | formula.AG \\<phi> \\<Rightarrow>\n      Graph_Defs.Alw_alw\n        (\\<lambda> (L, s, u) (L', s', u'). A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow> \\<langle>L', s', u'\\<rangle>)\n        (\\<lambda> (L, s, _). check_sexp \\<phi> L (the o s))\n  | formula.Leadsto \\<phi> \\<psi> \\<Rightarrow>\n      Graph_Defs.leadsto\n        (\\<lambda> (L, s, u) (L', s', u'). A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow> \\<langle>L', s', u'\\<rangle>)\n        (\\<lambda> (L, s, _). check_sexp \\<phi> L (the o s))\n        (\\<lambda> (L, s, _). check_sexp \\<psi> L (the o s))\n  ) a\\<^sub>0\"\n\nlemmas models_iff = models_def[unfolded Graph_Defs.Ex_alw_iff Graph_Defs.Alw_alw_iff]\n\ndefinition prop_of where\n  \"prop_of \\<phi> = PropC (\\<lambda>(L, s, _). check_sexp \\<phi> L (the o s))\"\n\nfun ctl_of where\n  \"ctl_of (formula.EX \\<phi>) = ctl_formula.EX (prop_of \\<phi>)\"\n| \"ctl_of (formula.EG \\<phi>) = ctl_formula.EG (prop_of \\<phi>)\"\n| \"ctl_of (formula.AX \\<phi>) = ctl_formula.AX (prop_of \\<phi>)\"\n| \"ctl_of (formula.AG \\<phi>) = ctl_formula.AG (prop_of \\<phi>)\"\n| \"ctl_of (formula.Leadsto \\<phi> \\<psi>) =\n  ctl_formula.AG (ctl_formula.ImpliesC (prop_of \\<phi>) (ctl_formula.AX (prop_of \\<psi>)))\"\n\ncontext\n  fixes A :: \"('a, 's, 'c, 't :: time, 'x, 'v :: linorder) nta\"\nbegin\n\ninterpretation Graph_Defs \"\\<lambda> (L, s, u) (L', s', u'). A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow> \\<langle>L', s', u'\\<rangle>\" .\n\nlemma models_ctl_iff:\n  \"A,a\\<^sub>0 \\<Turnstile> \\<Phi> \\<longleftrightarrow> models_ctl (ctl_of \\<Phi>) a\\<^sub>0\"\n  by (cases \\<Phi>) (simp_all add: models_def prop_of_def leadsto_def)\n\nend\n\nfun check_sexpi :: \"(nat, 's, nat, int) sexp \\<Rightarrow> 's list \\<Rightarrow> int list \\<Rightarrow> bool\" where\n  \"check_sexpi sexp.true _ _ \\<longleftrightarrow> True\" |\n  \"check_sexpi (not e) L s \\<longleftrightarrow> \\<not> check_sexpi e L s\" |\n  \"check_sexpi (and e1 e2) L s \\<longleftrightarrow> check_sexpi e1 L s \\<and> check_sexpi e2 L s\" |\n  \"check_sexpi (sexp.or e1 e2) L s \\<longleftrightarrow> check_sexpi e1 L s \\<or> check_sexpi e2 L s\" |\n  \"check_sexpi (imply e1 e2) L s \\<longleftrightarrow> check_sexpi e1 L s \\<longrightarrow> check_sexpi e2 L s\" |\n  \"check_sexpi (eq i x) L s \\<longleftrightarrow> s ! i = x\" |\n  \"check_sexpi (le i x) L s \\<longleftrightarrow> s ! i \\<le> x\" |\n  \"check_sexpi (lt i x) L s \\<longleftrightarrow> s ! i < x\" |\n  \"check_sexpi (ge i x) L s \\<longleftrightarrow> s ! i \\<ge> x\" |\n  \"check_sexpi (gt i x) L s \\<longleftrightarrow> s ! i > x\" |\n  \"check_sexpi (loc i x) L s \\<longleftrightarrow> L ! i = x\"\n\nfun hd_of_formulai :: \"(nat, 's, nat, int) formula \\<Rightarrow> 's list \\<Rightarrow> int list \\<Rightarrow> bool\" where\n  \"hd_of_formulai (formula.EX \\<phi>) L s = check_sexpi \\<phi> L s\" |\n  \"hd_of_formulai (EG \\<phi>) L s = check_sexpi \\<phi> L s\" |\n  \"hd_of_formulai (AX \\<phi>) L s = Not (check_sexpi \\<phi> L s)\" |\n  \"hd_of_formulai (AG \\<phi>) L s = Not (check_sexpi \\<phi> L s)\" |\n  \"hd_of_formulai (Leadsto \\<phi> _) L s = check_sexpi \\<phi> L s\"\n\n\n\n(* XXX Stop locale constant unfolding in simplifier *)\nlemma all_prop_weak_cong[cong]:\n  \"Prod_TA_Defs.all_prop A = Prod_TA_Defs.all_prop A\" for A\n  by(rule HOL.refl)\nlemma equiv'_weak_cong[cong]:\n  \"Bisimulation_Invariant.equiv' R P Q = Bisimulation_Invariant.equiv' R P Q\" for R P Q\n  by (rule HOL.refl)\nlemma equiv'_weak_cong2[cong]:\n  \"Simulation_Invariant.equiv' R P Q = Simulation_Invariant.equiv' R P Q\" for R P Q\n  by (rule HOL.refl)\nlemma models_ctl_weak_cong[cong]:\n  \"Graph_Defs.models_ctl E = Graph_Defs.models_ctl E\" for E\n  by (rule HOL.refl)\nlemma models_path_weak_cong[cong]:\n  \"Graph_Defs.models_path E = Graph_Defs.models_path E\" for E\n  by (rule HOL.refl)\nlemma models_state_weak_cong[cong]:\n  \"Graph_Defs.models_state E = Graph_Defs.models_state E\" for E\n  by (rule HOL.refl)\nlemma models_ltl_weak_cong[cong]:\n  \"Graph_Defs.models_ltlc E = Graph_Defs.models_ltlc E\" for E\n  by (rule HOL.refl)\nlemma models_weak_cong[cong]:\n  \"models E = models E\"\n  for E by (rule HOL.refl)\n\n\n\n\nsection \\<open>Instantiating the Model Checking Locale\\<close>\n\nlocale Simple_Network_Impl_nat_urge =\n  Simple_Network_Impl_nat + assumes no_urgency: \"\\<forall> (_, U, _, _) \\<in> set automata. U = []\"\n\ntext \\<open>\n  This locale certifies that a given local clock ceiling is correct.\n  Moreover, we certify that the vector of initial locations has outgoing transitions for\n  each automaton, and that all variables of the initial state are in bounds.\n\\<close>\nlocale Simple_Network_Impl_nat_ceiling_start_state =\n  Simple_Network_Impl_nat_urge +\n  fixes k :: \"nat list list list\"\n    and L\\<^sub>0 :: \"nat list\"\n    and s\\<^sub>0 :: \"(nat \\<times> int) list\"\n    and formula :: \"(nat, nat, nat, int) formula\"\n    and show_clock :: \"nat \\<Rightarrow> string\"\n    and show_state :: \"nat list \\<times> int list \\<Rightarrow> string\"\n  assumes k_ceiling:\n    \"\\<forall>i < n_ps. \\<forall>(l, g) \\<in> set ((snd o snd o snd) (automata ! i)).\n      \\<forall>(x, m) \\<in> collect_clock_pairs g. m \\<le> int (k ! i ! l ! x)\"\n    \"\\<forall>i < n_ps. \\<forall>(l, _, g, _) \\<in> set ((fst o snd o snd) (automata ! i)).\n      (\\<forall>(x, m) \\<in> collect_clock_pairs g. m \\<le> int (k ! i ! l ! x))\"\n  and k_resets:\n    \"\\<forall>i < n_ps. \\<forall> (l, b, g, a, upd, r, l') \\<in> set ((fst o snd o snd) (automata ! i)).\n       \\<forall>c \\<in> {0..<m+1} - set r. k ! i ! l' ! c \\<le> k ! i ! l ! c\"\n  and k_length:\n    \"length k = n_ps\" \"\\<forall> i < n_ps. length (k ! i) = num_states i\"\n    \"\\<forall> xs \\<in> set k. \\<forall> xxs \\<in> set xs. length xxs = m + 1\"\n  and k_0:\n    \"\\<forall>i < n_ps. \\<forall>l < num_states i. k ! i ! l ! 0 = 0\"\n  and inv_unambiguous:\n    \"\\<forall>(_, _, _, inv) \\<in> set automata. distinct (map fst inv)\"\n  and s\\<^sub>0_bounded: \"bounded bounds (map_of s\\<^sub>0)\"\n  and L\\<^sub>0_len: \"length L\\<^sub>0 = n_ps\"\n  and L\\<^sub>0_has_trans: \"\\<forall>i < n_ps. L\\<^sub>0 ! i \\<in> fst ` set ((fst o snd o snd) (automata ! i))\"\n  and vars_of_formula: \"vars_of_formula formula \\<subseteq> {0..<n_vs}\"\n  (* and num_states_length: \"\\<forall>i<n_ps. num_states i = length (fst (snd (automata ! i)))\" *)\nbegin\n\ntext \\<open>\nThe ceiling \\<open>k\\<close> is correct for each individual automaton in the network.\nWe now construct a ceiling for the product automaton:\n\\<close>\ndefinition\n  \"k_fun l c \\<equiv>\n    if (c > 0 \\<and> c \\<le> m) \\<and> fst l \\<in> states then Max {k ! i ! (fst l ! i) ! c | i . i < n_ps} else 0\"\n\nlemma (in -) default_map_of_distinct:\n  \"(k, default_map_of x xs k) \\<in> set xs \\<union> {(k, x)}\" if \"distinct (map fst xs)\"\n  unfolding default_map_of_alt_def by clarsimp (simp add: map_of_eq_Some_iff[OF that])\n\nlemma N_inv:\n  \"(L ! i, inv (N i) (L ! i)) \\<in> set ((snd o snd o snd) (automata ! i)) \\<union> {(L ! i, [])}\"\n  if \"i < n_ps\"\n  unfolding N_def comp_def fst_conv snd_conv inv_def\n  using that\n  apply (subst nth_map)\n   apply (simp add: n_ps_def; fail)\n  apply (clarsimp split: prod.split simp: automaton_of_def)\n  subgoal for _ _ _ xs\n    using default_map_of_distinct[of xs \"L ! i\" \"[]\"] inv_unambiguous that\n    by (auto dest!: nth_mem simp: n_ps_def)\n  done\n\nlemma (in -) subset_nat_0_atLeastLessThan_conv:\n  \"S \\<subseteq> {0..<n::nat} \\<longleftrightarrow> (\\<forall> x \\<in> S. x < n)\"\n  by auto\n\nlemma k_ceiling_rule:\n  \"m \\<le> int (k ! i ! l ! x)\"\n  if \"i < n_ps\" \"(l, b, g, xx) \\<in> set ((fst o snd o snd) (automata ! i))\"\n     \"(x, m) \\<in> collect_clock_pairs g\"\n  for i l x g xx\n  using that k_ceiling(2) by fastforce\n\nlemma k_ceiling_1:\n  \"\\<forall>s. \\<forall>L \\<in> states. \\<forall>(x,m) \\<in> clkp_set prod_ta (L, s). m \\<le> k_fun (L, s) x\"\nproof safe\n  fix L s c x\n  assume \\<open>L \\<in> states\\<close> \\<open>(c, x) \\<in> Closure.clkp_set prod_ta (L, s)\\<close>\n  have \"0 < c\" \"c \\<le> m\"\n  proof -\n    from \\<open>(c, x) \\<in> _\\<close> have \"(c, x) \\<in> Timed_Automata.clkp_set prod_ta\"\n      unfolding TA_clkp_set_unfold by auto\n    with clock_range show \"0 < c\" \"c \\<le> m\"\n      by auto\n  qed\n  with \\<open>L \\<in> _\\<close> have \"k_fun (L, s) c = Max {k ! i ! (L ! i) ! c | i . i < n_ps}\"\n    unfolding k_fun_def by auto\n  have Max_aux: \"x \\<le> int (Max {k ! i ! (L ! i) ! c |i. i < n_ps})\"\n    if \"x \\<le> int (k ! p ! (L ! p) ! c)\" \"p < n_ps\" for p\n  proof -\n    from \\<open>p < n_ps \\<close> have \"k ! p ! (L ! p) ! c \\<le> Max {k ! i ! (L ! i) ! c |i. i < n_ps}\"\n      by (intro Max_ge) auto\n    with \\<open>x \\<le> _\\<close> show ?thesis\n      by simp\n  qed\n  from \\<open>(c, x) \\<in> _\\<close> show \\<open>x \\<le> k_fun (L, s) c\\<close>\n    unfolding clkp_set_def\n  proof safe\n    assume \\<open>(c, x) \\<in> Closure.collect_clki (inv_of prod_ta) (L, s)\\<close>\n    then show \\<open>x \\<le> k_fun (L, s) c\\<close>\n      using k_ceiling(1) unfolding collect_clki_def \\<open>k_fun (L, s) c = _\\<close>\n      by (force intro: Max_aux dest: N_inv simp: prod_inv_def collect_clock_pairs_def k_fun_def)\n  next\n    assume \\<open>(c, x) \\<in> Closure.collect_clkt (trans_of prod_ta) (L, s)\\<close>\n    then show \\<open>x \\<le> k_fun (L, s) c\\<close>\n      unfolding collect_clkt_def \\<open>k_fun (L, s) c = _\\<close>\n      apply (clarsimp simp: trans_prod_def collect_clock_pairs_def k_fun_def)\n      apply safe\n      subgoal\n        using k_ceiling(2) unfolding trans_int_def\n        apply (clarsimp simp: mem_trans_N_iff L_len subset_nat_0_atLeastLessThan_conv)\n        apply (fastforce intro!: Max_aux simp: collect_clock_pairs_def)\n        done\n      subgoal\n        using k_ceiling(2) unfolding trans_bin_def\n        apply (clarsimp simp: mem_trans_N_iff L_len subset_nat_0_atLeastLessThan_conv)\n        apply (erule disjE)\n         apply (force intro!: Max_aux simp: collect_clock_pairs_def)+\n        done\n      subgoal\n        using k_ceiling(2) unfolding trans_broad_def\n        apply (clarsimp simp: mem_trans_N_iff L_len subset_nat_0_atLeastLessThan_conv)\n        apply (erule disjE)\n         apply (fastforce intro!: Max_aux simp: collect_clock_pairs_def)\n        apply (erule bexE)\n        apply (force intro!: Max_aux simp: collect_clock_pairs_def)\n        done\n      done\n  qed\nqed\n\nlemma k_fun_mono':\n  \"k_fun (L, s) c \\<le> k_fun (L', s') c\" if\n  \"\\<forall>i < n_ps. k ! i ! (L ! i) ! c \\<le> k ! i ! (L' ! i) ! c\" \"L \\<in> states\" \"L' \\<in> states\"\n  using that unfolding k_fun_def\n  apply clarsimp\n  apply (cases \"n_ps = 0\")\n   apply (simp; fail)\n  apply (rule Max.boundedI)\n    apply (simp; fail)\n   apply blast\n  apply safe\n  subgoal for _ i\n    by - (rule order.trans[where b = \"k ! i ! (L' ! i) ! c\"], auto intro: Max_ge)\n  done\n\nlemma k_fun_mono:\n  \\<open>Max {k ! i ! (L ! i) ! c | i . i < n_ps} \\<le> Max {k ! i ! (L' ! i) ! c | i . i < n_ps}\\<close>\n  if \\<open>\\<forall>i < n_ps. k ! i ! (L ! i) ! c \\<le> k ! i ! (L' ! i) ! c\\<close>\n  apply (cases \"n_ps = 0\")\n   apply (simp; fail)\n  apply (rule Max.boundedI)\n    apply (simp; fail)\n   apply blast\n  apply safe\n  subgoal for _ i\n    using that by - (rule order.trans[where b = \"k ! i ! (L' ! i) ! c\"], auto intro: Max_ge)\n  done\n\nlemma (in -) fold_upds_aux1:\n  \"fold (\\<lambda>p L. L[p := g p]) ps xs ! i = xs ! i\" if \\<open>i \\<notin> set ps\\<close>\n  using that by (induction ps arbitrary: xs) auto\n\nlemma (in -) fold_upds_aux2:\n  \"fold (\\<lambda>p L. L[p := g p]) ps xs ! i = g i\" if \\<open>distinct ps\\<close> \\<open>i \\<in> set ps\\<close> \\<open>i < length xs\\<close>\n  using that by (induction ps arbitrary: xs) (auto simp: fold_upds_aux1)\n\nlemma (in -) fold_upds_aux_length:\n  \"length (fold (\\<lambda>p L. L[p := g p]) ps xs) = length xs\"\n  by (induction ps arbitrary: xs) auto\n\n(* XXX Duplication *)\nlemma (in -) state_set_eq[simp]:\n  \"Simulation_Graphs_TA.state_set A = state_set (trans_of A)\"\n  unfolding Simulation_Graphs_TA.state_set_def state_set_def trans_of_def ..\n\nlemma prod_ta_step_statesD:\n  assumes \"prod_ta \\<turnstile> (L, s) \\<longrightarrow>\\<^bsup>g,a,r\\<^esup> (L', s')\"\n  shows \"L \\<in> states\" \"L' \\<in> states\"\n  using assms state_set_states by (fastforce dest: state_setI1 state_setI2)+\n\nlemma k_ceiling_2:\n  \"\\<forall>l g a r l'. \\<forall> c \\<le> m. prod_ta \\<turnstile> l \\<longrightarrow>\\<^bsup>g,a,r\\<^esup> l' \\<and> c \\<notin> set r \\<longrightarrow> k_fun l' c \\<le> k_fun l c\"\nproof safe\n  fix L s g a r L' s' c\n  assume A: \\<open>c \\<le> m\\<close> \\<open>prod_ta \\<turnstile> (L, s) \\<longrightarrow>\\<^bsup>g,a,r\\<^esup> (L', s')\\<close> \\<open>c \\<notin> set r\\<close>\n  then have \"L \\<in> states\" \"L' \\<in> states\"\n    by - (rule prod_ta_step_statesD, assumption)+\n  from A have \\<open>Max {k ! i ! (L' ! i) ! c | i . i < n_ps} \\<le> Max {k ! i ! (L ! i) ! c | i . i < n_ps}\\<close>\n    apply simp\n    unfolding trans_prod_def\n    apply auto\n    subgoal\n      using k_resets\n      unfolding trans_int_def\n      apply clarsimp\n      apply (rule k_fun_mono)\n      apply (clarsimp simp: mem_trans_N_iff L_len subset_nat_0_atLeastLessThan_conv)\n      subgoal for b f p aa l' i\n        by (cases \"p = i\"; force simp add: L_len)\n      done\n    subgoal\n      using k_resets\n      unfolding trans_bin_def\n      apply clarsimp\n      apply (rule k_fun_mono)\n      apply (clarsimp simp: mem_trans_N_iff L_len subset_nat_0_atLeastLessThan_conv)\n      subgoal for _ _ p q b1 g1 f1 r1 l1' b2 g2 f2 r2 l2' i\n        by (cases \"p = i\"; cases \"q = i\"; force simp add: L_len)\n      done\n    subgoal\n      using k_resets\n      unfolding trans_broad_def\n      apply clarsimp\n      apply (rule k_fun_mono)\n      apply (clarsimp simp: mem_trans_N_iff L_len subset_nat_0_atLeastLessThan_conv)\n      subgoal premises prems for s'a aa p b ga f ra l' bs gs fs rs ls' ps i\n      proof (cases \"p = i\")\n        case True\n        with \\<open>p \\<notin> _\\<close> \\<open>i < _\\<close> \\<open>L \\<in> states\\<close> have \"(fold (\\<lambda>p L. L[p := ls' p]) ps L)[p := l'] ! i = l'\"\n          by (simp add: L_len fold_upds_aux_length)\n        with prems \\<open>p = i\\<close> show ?thesis\n          by (fastforce simp add: L_len)\n      next\n        case False\n        then have *: \"(fold (\\<lambda>p L. L[p := ls' p]) ps L)[p := l'] ! i\n          = fold (\\<lambda>p L. L[p := ls' p]) ps L ! i\"\n          by simp\n        show ?thesis\n        proof (cases \"i \\<in> set ps\")\n          case True\n          then have **: \"fold (\\<lambda>p L. L[p := ls' p]) ps L ! i = ls' i\"\n            using \\<open>distinct ps\\<close> \\<open>i < n_ps\\<close> \\<open>L \\<in> states\\<close> by (auto simp: fold_upds_aux2)\n          moreover have\n            \"(L ! i, bs i, gs i, In aa, fs i, rs i, ls' i) \\<in> set (fst (snd (snd (automata ! i))))\"\n            using \\<open>p \\<noteq> i\\<close> True prems by fast\n          moreover have \"c\\<in>{0..<Suc m} - set (rs i)\"\n            using \\<open>p \\<noteq> i\\<close> True prems by force\n          ultimately show ?thesis\n            using prems(2) \\<open>i < n_ps\\<close> by (auto 4 3 simp add: *)\n        next\n          case False\n          with \\<open>p \\<noteq> i\\<close> show ?thesis\n            by (simp add: fold_upds_aux1)\n        qed\n      qed\n      done\n    done\n  with \\<open>L \\<in> states\\<close> \\<open>L' \\<in> states\\<close> \\<open>c \\<le> m\\<close> show \"k_fun (L', s') c \\<le> k_fun (L, s) c\"\n    by (auto simp: k_fun_def)\nqed\n\n\n\nabbreviation F where \"F \\<equiv> \\<lambda>(L, s). hd_of_formula formula L (the o s)\"\nabbreviation \"Fi \\<equiv> \\<lambda>(L, s). hd_of_formulai formula L s\"\n\nlemma (in Simple_Network_Impl_nat) check_sexp_check_sexpi:\n  \"check_sexp e L (the o s) \\<longleftrightarrow> check_sexpi e L s'\"\n  if \"state_rel s s'\" \"vars_of_sexp e \\<subseteq> {0..<n_vs}\"\n  using that unfolding state_rel_def by (induction e) auto\n\nlemma (in Simple_Network_Impl_nat) hd_of_formula_hd_of_formulai:\n  \"hd_of_formula \\<phi> L (the o s) \\<longleftrightarrow> hd_of_formulai \\<phi> L s'\"\n  if \"state_rel s s'\" \"vars_of_formula \\<phi> \\<subseteq> {0..<n_vs}\"\n  using that by (induction \\<phi>) (auto simp: check_sexp_check_sexpi)\n\nlemma F_Fi:\n  \"F l \\<longleftrightarrow> Fi l'\" if \"(l', l) \\<in> loc_rel\"\n  using vars_of_formula that unfolding loc_rel_def by clarsimp (erule hd_of_formula_hd_of_formulai)\n\n\nabbreviation \"l\\<^sub>0 \\<equiv> (L\\<^sub>0, map_of s\\<^sub>0)\"\nabbreviation \"s\\<^sub>0i \\<equiv> map (the o map_of s\\<^sub>0) [0..<n_vs]\"\nabbreviation \"l\\<^sub>0i \\<equiv> (L\\<^sub>0, s\\<^sub>0i)\"\n\nlemma state_rel_start:\n  \"state_rel (map_of s\\<^sub>0) s\\<^sub>0i\"\n  using s\\<^sub>0_bounded unfolding state_rel_def bounded_def dom_bounds_eq by auto\n\nlemma statesI:\n  \"L \\<in> states\" if \"length L = n_ps\" \"\\<forall>i<n_ps. L ! i \\<in> fst ` set (fst (snd (snd (automata ! i))))\"\n  using that unfolding states_def by (auto 4 3 simp: mem_trans_N_iff[symmetric])\n\nlemma L\\<^sub>0_states[simp, intro]:\n  \"L\\<^sub>0 \\<in> states\"\n  using L\\<^sub>0_has_trans L\\<^sub>0_len by (auto intro: statesI)\n\nlemma l\\<^sub>0_states'[simp, intro]:\n  \"l\\<^sub>0 \\<in> states'\"\n  using state_rel_start s\\<^sub>0_bounded unfolding states'_def state_rel_def by auto\n\nprint_locale Reachability_Problem_Defs\n\nsublocale reach: Reachability_Problem_Defs\n  prod_ta\n  l\\<^sub>0\n  m\n  k_fun\n  F\n  .\n\nlemma (in -) collect_clkt_state_setI:\n  assumes \"(x, d) \\<in> Closure.collect_clkt (trans_of A) l\"\n  shows \"l \\<in> state_set (trans_of A)\" \"l \\<in> Simulation_Graphs_TA.state_set A\"\n  using assms unfolding collect_clkt_def by (auto simp: state_set_def)\n\nlemma clkp_set_statesD:\n  fixes x d\n  assumes \"(x, d)\\<in>Closure.clkp_set prod_ta (L, s)\"\n  shows \"L \\<in> states\"\n  using assms\n  unfolding clkp_set_def collect_clki_def\n  apply safe\n  subgoal\n    apply simp\n    unfolding prod_inv_def\n    unfolding collect_clock_pairs_def\n    apply auto\n    done\n  apply (drule collect_clkt_state_setI)\n  using state_set_states by auto\n\nsublocale reach1: Reachability_Problem\n  prod_ta\n  l\\<^sub>0\n  m\n  k_fun\n  F\n  apply standard\n  subgoal\n    apply safe\n    using k_ceiling_1\n    subgoal for L s x m\n      apply (cases \"L \\<in> states\")\n       apply blast\n      apply (auto dest: clkp_set_statesD simp: k_fun_def)\n      done\n    done\n  subgoal\n    apply safe\n    subgoal for L s g a r L' s' c\n      apply (cases \"c \\<le> m\")\n      using k_ceiling_2\n       apply force\n      apply (auto simp: k_fun_def)\n      done\n    done\n  subgoal\n    by (simp add: k_fun_def)\n  subgoal\n    by (simp add: k_fun_def)\n  done\n\nlemma states'_superset:\n  \"{l\\<^sub>0} \\<union> Normalized_Zone_Semantics_Impl_Refine.state_set trans_prod \\<subseteq> states'\"\n  (is \"{l\\<^sub>0} \\<union> ?S \\<subseteq> states'\")\nproof -\n  have \"?S \\<subseteq> states'\"\n  proof clarsimp\n    fix L s\n    assume \"(L, s) \\<in> ?S\"\n    then have \"L \\<in> states\"\n      using state_set_states[unfolded trans_of_prod state_set_eq] by blast\n    moreover have \"bounded bounds s\"\n      using \\<open>(L, s) \\<in> _\\<close>\n      unfolding state_set_def\n      unfolding trans_prod_def\n      unfolding trans_int_def trans_bin_def trans_broad_def\n      by auto\n    ultimately show \"(L, s) \\<in> states'\"\n      by (auto simp: states'_alt_def)\n  qed\n  then show ?thesis\n    by simp\nqed\n\n\n\ndefinition \"k_i \\<equiv> IArray (map (IArray o (map (IArray o map int))) k)\"\n\ndefinition\n  \"k_impl \\<equiv> \\<lambda>(l, _). IArray (map (\\<lambda> c. Max {k_i !! i !! (l ! i) !! c | i. i < n_ps}) [0..<m+1])\"\n\n(* XXX Duplication with UPPAAL_State_Networks_Impl_Refine *)\nlemma Max_int_commute:\n  \"int (Max S) = Max (int ` S)\" if \"finite S\" \"S \\<noteq> {}\"\n  apply (rule mono_Max_commute)\n    apply rule\n  using that by auto\n\nlemma (in Simple_Network_Impl_nat) n_ps_gt_0: \"n_ps > 0\"\n  using length_automata_eq_n_ps non_empty by auto\n\nlemma statesD:\n  \"L ! i \\<in> fst ` set (fst (snd (snd (automata ! i))))\n \\<or> L ! i \\<in> (snd o snd o snd o snd o snd o snd) ` set (fst (snd (snd (automata ! i))))\"\n  if \"L \\<in> states\" \"length L = n_ps\" \"i < n_ps\"\n  using that unfolding states_def\n  apply auto\n  apply -\n  apply (elim allE impE, assumption)\n  apply auto\n   apply (force simp: mem_trans_N_iff)+\n  done\n\nlemma k_impl_k_fun:\n  \"k_impl (L, s) = IArray (map (k_fun (L, s)) [0..<m+1])\" if \"L \\<in> states\"\nproof -\n  define k_i2 where \"k_i2 i c = k_i !! i !! (L ! i) !! c\" for i c\n  have k_i2_k: \"k_i2 i c = k ! i ! (L ! i) ! c\" if \"i < n_ps\" \"c \\<le> m\" for i c\n  proof -\n    have \"i < length k\"\n      by (simp add: k_length(1) that(1))\n    moreover have \"L ! i < length (k ! i)\"\n      using L_i_len[OF _ \\<open>L \\<in> states\\<close>] k_length(2) \\<open>i < n_ps\\<close> by auto\n    moreover have \"c < length (k ! i ! (L ! i))\"\n      using k_length(3) \\<open>c \\<le> m\\<close> \\<open>i < length k\\<close> \\<open>L ! i < length (k ! i)\\<close> by (auto dest: nth_mem)\n    ultimately show ?thesis\n      unfolding k_i2_def k_i_def by simp\n  qed\n  have k_impl_alt_def: \"k_impl (L, s) = IArray (map (\\<lambda> c. Max {k_i2 i c | i. i < n_ps}) [0..<m+1])\"\n    unfolding k_impl_def k_i2_def by auto\n  (* XXX more general pattern? *)\n  have Max_cong: \"Max {f i | i. i < n_ps} = Max {g i | i. i < n_ps}\"\n    if \"\\<And> i. i < n_ps \\<Longrightarrow> f i = g i\" for f g :: \"nat \\<Rightarrow> int\"\n    by (rule arg_cong[where f = Max]) (force simp: that)\n  from that n_ps_gt_0 show ?thesis\n    unfolding k_impl_alt_def\n    unfolding k_i2_def[symmetric]\n    apply (clarsimp simp: k_fun_def k_i2_k cong: Max_cong)\n    apply safe\n    subgoal\n      by (subst Max_int_commute; force simp: setcompr_eq_image image_comp comp_def)\n    subgoal\n      using k_0 L_i_len[OF _ \\<open>L \\<in> states\\<close>] by (intro linorder_class.Max_eqI) auto\n    subgoal\n      by (subst Max_int_commute; force simp: setcompr_eq_image image_comp comp_def)\n    done\nqed\n\n\nsublocale impl: Reachability_Problem_Impl\n  where trans_fun = trans_from\n  and inv_fun = inv_fun\n  and F_fun = Fi\n  and ceiling = k_impl\n  and A = prod_ta\n  and l\\<^sub>0 = l\\<^sub>0\n  and l\\<^sub>0i = l\\<^sub>0i\n  and F = \"PR_CONST F\"\n  and n = m\n  and k = k_fun\n  and trans_impl = trans_impl\n  and states' = states'\n  and loc_rel = loc_rel\n  apply standard\n\n(* trans_from *)\n  subgoal\n    unfolding trans_of_prod by (rule trans_from_correct)\n\n(* trans_impl *)\n  subgoal\n    apply (rule trans_from_refine)\n    done\n\n(* inv_fun *)\n  subgoal\n    unfolding trans_of_prod\n    by (rule set_mp[OF _ inv_fun_inv_of'[where R = loc_rel and S = \"{(s, s'). state_rel s' s}\"]])\n       (auto simp: loc_rel_def)\n\n(* state set *)\n  subgoal\n    using states'_superset by simp\n\n(* loc_rel l\\<^sub>0 l\\<^sub>0i*)\n  subgoal\n    using state_rel_start unfolding loc_rel_def by auto\n\n(* loc_rel left unique *)\n  subgoal for l li li'\n    unfolding trans_of_prod by (rule state_rel_left_unique)\n\n(* loc_rel right unique *)\n  subgoal for l l' li\n    unfolding trans_of_prod by (rule state_rel_right_unique)\n\n(* ceiling *)\n  subgoal\n    unfolding inv_rel_def using L\\<^sub>0_states\n    by (auto simp: loc_rel_def state_rel_def reach.k'_def k_fun_def k_impl_k_fun)\n\n(* F_fun *)\n  subgoal\n    unfolding inv_rel_def by (clarsimp dest!: F_Fi)\n\n  done\n\nend (* Simple_Network_Impl_nat_ceiling_start_state *)\n\nno_notation UPPAAL_Model_Checking.models (\"_,_ \\<Turnstile>\\<^sub>_ _\" [61,61] 61)\n\n\ncontext Reachability_Problem_Impl\nbegin\n\nlemma F_reachable_correct:\n  \"op.F_reachable\n  \\<longleftrightarrow> (\\<exists>l'. \\<forall>u\\<^sub>0. (\\<forall>c \\<in> {1..n}. u\\<^sub>0 c = 0) \\<longrightarrow> (\\<exists> u'. conv_A A \\<turnstile>' \\<langle>l\\<^sub>0, u\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>l', u'\\<rangle> \\<and> F l'))\"\n  using E_op''.E_from_op_reachability_check[symmetric] reachability_check_new\n  unfolding E_op_F_reachable E_op''.F_reachable_def E_op''.reachable_def\n  unfolding F_rel_def by auto\n\nlemma E_op''_F_reachable_correct:\n  \"E_op''.F_reachable\n  \\<longleftrightarrow> (\\<exists>l'. \\<forall>u\\<^sub>0. (\\<forall>c \\<in> {1..n}. u\\<^sub>0 c = 0) \\<longrightarrow> (\\<exists> u'. conv_A A \\<turnstile>' \\<langle>l\\<^sub>0, u\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>l', u'\\<rangle> \\<and> F l'))\"\n  using E_op''.E_from_op_reachability_check[symmetric] reachability_check_new\n  unfolding E_op_F_reachable E_op''.F_reachable_def E_op''.reachable_def\n  unfolding F_rel_def by auto\n\nlemma Ex_ev_impl_hnr:\n  assumes \"\\<forall>u\\<^sub>0. (\\<forall>c \\<in> {1..n}. u\\<^sub>0 c = 0) \\<longrightarrow> \\<not> deadlock (l\\<^sub>0, u\\<^sub>0)\"\n  shows\n    \"\n  (uncurry0\n    (pw_impl (return \\<circ> fst) state_copy_impl tracei subsumes_impl a\\<^sub>0_impl F_impl succs_impl\n      emptiness_check_impl),\n   uncurry0 (SPEC (\\<lambda>r. (r \\<longleftrightarrow> (\\<forall>u\\<^sub>0. (\\<forall>c \\<in> {1..n}. u\\<^sub>0 c = 0) \\<longrightarrow> Ex_ev (\\<lambda>(l, _). F l) (l\\<^sub>0, u\\<^sub>0))))))\n  \\<in> unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a bool_assn\"\nproof -\n  interpret Bisimulation_Invariant\n    \"(\\<lambda>(l, u) (l', u'). conv_A A \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow> \\<langle>l', u'\\<rangle>)\"\n    \"(\\<lambda>(l, u) (l', u'). conv_A A \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow> \\<langle>l', u'\\<rangle>)\"\n    \"(\\<lambda>(l, u) (l', u'). l' = l \\<and> (\\<forall> c. c \\<in> clk_set (conv_A A) \\<longrightarrow> u c = u' c))\"\n    \"(\\<lambda>_. True)\" \"(\\<lambda>_. True)\"\n    apply (rule ta_bisimulation)\n    done\n  define spec where \"spec = (\\<forall>u\\<^sub>0. (\\<forall>c \\<in> {1..n}. u\\<^sub>0 c = 0) \\<longrightarrow> Ex_ev (\\<lambda>(l, _). F l) (l\\<^sub>0, u\\<^sub>0))\"\n  have *: \"E_op''.F_reachable \\<longleftrightarrow> spec\"\n    unfolding spec_def\n    unfolding E_op''_F_reachable_correct\n  proof safe\n    fix l' :: \\<open>'s\\<close> and u\\<^sub>0 :: \\<open>nat \\<Rightarrow> real\\<close>\n    assume\n      \\<open>\\<forall>u\\<^sub>0. (\\<forall>c\\<in>{1..n}. u\\<^sub>0 c = 0) \\<longrightarrow> (\\<exists>u'. conv_A A \\<turnstile>' \\<langle>l\\<^sub>0, u\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>l', u'\\<rangle> \\<and> F l')\\<close> and\n      \\<open>\\<forall>c\\<in>{1..n}. u\\<^sub>0 c = 0\\<close>\n    then show \\<open>Ex_ev (\\<lambda>(l, _). F l) (l\\<^sub>0, u\\<^sub>0)\\<close>\n      using assms by (subst Ex_ev; unfold reaches_steps'[symmetric]) blast+\n  next\n    assume \\<open>\\<forall>u\\<^sub>0. (\\<forall>c\\<in>{1..n}. u\\<^sub>0 c = 0) \\<longrightarrow> Ex_ev (\\<lambda>(l, _). F l) (l\\<^sub>0, u\\<^sub>0)\\<close>\n    then have \"Ex_ev (\\<lambda>(l, _). F l) (l\\<^sub>0, \\<lambda>_. 0)\"\n      by auto\n    then obtain l' u' where \"conv_A A \\<turnstile>' \\<langle>l\\<^sub>0, (\\<lambda>_. 0)\\<rangle> \\<rightarrow>* \\<langle>l', u'\\<rangle> \\<and> F l'\"\n      apply (subst (asm) Ex_ev)\n      using assms\n      unfolding reaches_steps'[symmetric]\n      by auto\n    then show \\<open>\\<exists>l'. \\<forall>u\\<^sub>0. (\\<forall>c\\<in>{1..n}. u\\<^sub>0 c = 0) \\<longrightarrow> (\\<exists>u'. conv_A A \\<turnstile>' \\<langle>l\\<^sub>0, u\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>l', u'\\<rangle> \\<and> F l')\\<close>\n    proof (inst_existentials l', clarsimp, unfold reaches_steps'[symmetric])\n      fix u\\<^sub>0 :: \\<open>nat \\<Rightarrow> real\\<close>\n      assume \\<open>reaches (l\\<^sub>0, \\<lambda>_. 0) (l', u')\\<close> and \\<open>F l'\\<close> and \\<open>\\<forall>c\\<in>{Suc 0..n}. u\\<^sub>0 c = 0\\<close>\n      then have \"equiv' (l\\<^sub>0, \\<lambda>_. 0) (l\\<^sub>0, u\\<^sub>0)\"\n        unfolding equiv'_def using clocks_I[of \"\\<lambda>_. 0\" u\\<^sub>0] by auto\n      with \\<open>reaches _ _\\<close> show \\<open>\\<exists>u'. reaches (l\\<^sub>0, u\\<^sub>0) (l', u')\\<close>\n        by - (drule (1) bisim.A_B.simulation_reaches, unfold equiv'_def, auto)\n    qed\n  qed\n  show ?thesis\n    unfolding spec_def[symmetric] using pw_impl_hnr_F_reachable[to_hnr, unfolded hn_refine_def]\n    by sepref_to_hoare (sep_auto simp: *)\nqed\n\nend (* Reachability Problem Impl *)\n\n\n\n\n\n\n\n\n\n\n\ncontext Simple_Network_Impl_nat_urge\nbegin\n\nsublocale conv: Prod_TA_urge\n  \"(set broadcast, map (Simple_Network_Language.conv_A o automaton_of) automata, map_of bounds')\"\n  by standard\n     (use no_urgency in \\<open>auto simp: Simple_Network_Language.conv_A_def automaton_of_def urgent_def\\<close>)\n\nabbreviation \"A \\<equiv> (set broadcast, map automaton_of automata, map_of bounds')\"\n\ninterpretation conv_eq_bisim:\n  Bisimulation_Invariant\n  \"(\\<lambda>(l, u) (l', u'). conv_A prod_ta \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow> \\<langle>l', u'\\<rangle>)\"\n  \"(\\<lambda>(L, s, u) (L', s', u'). conv.prod_ta   \\<turnstile>' \\<langle>(L, s), u\\<rangle> \\<rightarrow> \\<langle>(L', s'), u'\\<rangle>)\"\n  \"(\\<lambda>((L, s), u) (L', s', u'). L = L' \\<and> u = u' \\<and> s = s')\"\n  \"(\\<lambda>((L, s), u). conv.all_prop L s)\"\n  \"(\\<lambda>(L, s, u). conv.all_prop L s)\"\nproof goal_cases\n  case 1\n  interpret Bisimulation_Invariant\n  \"(\\<lambda>(L, s, u) (L', s', u'). conv_A prod_ta \\<turnstile>' \\<langle>(L, s), u\\<rangle> \\<rightarrow> \\<langle>(L', s'), u'\\<rangle>)\"\n  \"(\\<lambda>(L, s, u) (L', s', u'). conv.prod_ta   \\<turnstile>' \\<langle>(L, s), u\\<rangle> \\<rightarrow> \\<langle>(L', s'), u'\\<rangle>)\"\n  \"(=)\"\n  \"(\\<lambda>(L, s, u). conv.all_prop L s)\"\n  \"(\\<lambda>(L, s, u). conv.all_prop L s)\"\n  by (rule Bisimulation_Invariant_strong_intro)\n     (auto simp: conv_prod_ta elim: conv.prod_all_prop_inv')\n  show ?case\n    by standard (auto simp: conv_prod_ta elim: conv.prod_all_prop_inv')\nqed\n\ninterpretation Bisimulation_Invariant\n  \"(\\<lambda>(l, u) (l', u'). conv_A prod_ta \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow> \\<langle>l', u'\\<rangle>)\"\n  \"(\\<lambda>(L, s, u) (L', s', u'). Simple_Network_Language.conv A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow> \\<langle>L', s', u'\\<rangle>)\"\n  \"(\\<lambda>((L, s), u) (L', s', u'). L = L' \\<and> u = u' \\<and> s = s')\"\n  \"(\\<lambda>((L, s), u). conv.all_prop L s)\"\n  \"(\\<lambda>(L, s, u). conv.all_prop L s)\"\n  unfolding conv_alt_def\n  apply (rule Bisimulation_Invariant_sim_replace, rule Bisimulation_Invariant_composition)\n    apply (rule conv_eq_bisim.Bisimulation_Invariant_axioms conv.prod_bisim_intro)+\n  apply auto\n  done\n\nlemmas prod_bisim = Bisimulation_Invariant_axioms\n\nlemmas deadlock_iff = deadlock_iff\n\nlemma conv_all_prop:\n  \"conv.all_prop = all_prop\"\n  unfolding conv.all_prop_def all_prop_def by simp\n\nthm Ex_ev_iff\nthm CTL_compatible[THEN rel_funD, symmetric]\n\ndefinition prop_of2 where\n  \"prop_of2 \\<phi> = PropC (\\<lambda>((L, s), _). check_sexp \\<phi> L (the o s))\"\n\nfun ctl_of2 where\n  \"ctl_of2 (formula.EX \\<phi>) = ctl_formula.EX (prop_of2 \\<phi>)\"\n| \"ctl_of2 (formula.EG \\<phi>) = ctl_formula.EG (prop_of2 \\<phi>)\"\n| \"ctl_of2 (formula.AX \\<phi>) = ctl_formula.AX (prop_of2 \\<phi>)\"\n| \"ctl_of2 (formula.AG \\<phi>) = ctl_formula.AG (prop_of2 \\<phi>)\"\n| \"ctl_of2 (formula.Leadsto \\<phi> \\<psi>) =\n  ctl_formula.AG (ctl_formula.ImpliesC (prop_of2 \\<phi>) (ctl_formula.AX (prop_of2 \\<psi>)))\"\n\nlemma models_correct:\n  \"Simple_Network_Language.conv A,(L\\<^sub>0, s\\<^sub>0, u\\<^sub>0) \\<Turnstile> \\<Phi> = (case \\<Phi> of\n    formula.EX \\<phi> \\<Rightarrow>\n      Graph_Defs.Ex_ev\n        (\\<lambda> (l, u) (l', u'). conv_A prod_ta \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow> \\<langle>l', u'\\<rangle>)\n        (\\<lambda> ((L, s), _). check_sexp \\<phi> L (the o s))\n  | formula.EG \\<phi> \\<Rightarrow>\n      Not o Graph_Defs.Alw_ev\n        (\\<lambda> (l, u) (l', u'). conv_A prod_ta \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow> \\<langle>l', u'\\<rangle>)\n        (\\<lambda> ((L, s), _). \\<not> check_sexp \\<phi> L (the o s))\n  | formula.AX \\<phi> \\<Rightarrow>\n      Graph_Defs.Alw_ev\n        (\\<lambda> (l, u) (l', u'). conv_A prod_ta \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow> \\<langle>l', u'\\<rangle>)\n        (\\<lambda> ((L, s), _). check_sexp \\<phi> L (the o s))\n  | formula.AG \\<phi> \\<Rightarrow>\n      Not o Graph_Defs.Ex_ev\n        (\\<lambda> (l, u) (l', u'). conv_A prod_ta \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow> \\<langle>l', u'\\<rangle>)\n        (\\<lambda> ((L, s), _). \\<not> check_sexp \\<phi> L (the o s))\n  | formula.Leadsto \\<phi> \\<psi> \\<Rightarrow>\n      Graph_Defs.leadsto\n        (\\<lambda> (l, u) (l', u'). conv_A prod_ta \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow> \\<langle>l', u'\\<rangle>)\n        (\\<lambda> ((L, s), _). check_sexp \\<phi> L (the o s))\n        (\\<lambda> ((L, s), _). check_sexp \\<psi> L (the o s))\n  ) ((L\\<^sub>0, s\\<^sub>0), u\\<^sub>0)\n  \" if \"L\\<^sub>0 \\<in> states\" \"Simple_Network_Language.bounded bounds s\\<^sub>0\"\nproof -\n  have *: \"((Not \\<circ>\\<circ> case_prod) (\\<lambda>(L, s) _. check_sexp \\<phi> L (the o s)))\n    = (\\<lambda>((L, s), _). \\<not> check_sexp \\<phi> L (the o s))\"\n    for \\<phi> by (auto simp: comp_def)\n  have \"rel_ctl_formula compatible (ctl_of2 \\<Phi>) (ctl_of \\<Phi>)\"\n    by (cases \\<Phi>; simp add: prop_of_def prop_of2_def rel_fun_def A_B.equiv'_def)\n  moreover have \"A_B.equiv' ((L\\<^sub>0, s\\<^sub>0), u\\<^sub>0) (L\\<^sub>0, s\\<^sub>0, u\\<^sub>0)\"\n    unfolding A_B.equiv'_def unfolding conv_all_prop all_prop_def using that by simp\n  ultimately show ?thesis\n    apply (subst models_ctl_iff)\n    apply (subst CTL_compatible[THEN rel_funD, symmetric])\n      apply assumption+\n    apply (cases \\<Phi>; simp add:\n        Graph_Defs.models_ctl.simps prop_of2_def\n        Graph_Defs.Ex_alw_iff Graph_Defs.Alw_alw_iff Graph_Defs.leadsto_def *)\n    done\nqed\n\nend (* Simple_Network_Impl_nat *)\n\ncontext Simple_Network_Impl_nat_ceiling_start_state\nbegin\n\ndefinition Alw_ev_checker where\n  \"Alw_ev_checker = dfs_map_impl'\n     (impl.succs_P_impl' Fi) impl.a\\<^sub>0_impl impl.subsumes_impl (return \\<circ> fst)\n     impl.state_copy_impl\"\n\ndefinition leadsto_checker where\n  \"leadsto_checker \\<psi> = do {\n      r \\<leftarrow> leadsto_impl\n      impl.state_copy_impl (impl.succs_P_impl' (\\<lambda> (L, s). \\<not> check_sexpi \\<psi> L s))\n      impl.a\\<^sub>0_impl impl.subsumes_impl (return \\<circ> fst)\n      impl.succs_impl' impl.emptiness_check_impl impl.F_impl\n      (impl.Q_impl (\\<lambda> (L, s). \\<not> check_sexpi \\<psi> L s))\n      impl.tracei;\n      return (\\<not> r)\n    }\"\n\ndefinition\n  \"reachability_checker \\<equiv>\n     pw_impl\n      (return o fst) impl.state_copy_impl impl.tracei impl.subsumes_impl impl.a\\<^sub>0_impl impl.F_impl\n      impl.succs_impl impl.emptiness_check_impl\"\n\ndefinition model_checker where\n  \"model_checker = (\n  case formula of\n    formula.EX _ \\<Rightarrow> reachability_checker |\n    formula.AG _ \\<Rightarrow> do {\n      r \\<leftarrow> reachability_checker;\n      return (\\<not> r)\n    } |\n    formula.AX _ \\<Rightarrow> do {\n      r \\<leftarrow> if PR_CONST F l\\<^sub>0\n      then Alw_ev_checker\n      else return False;\n      return (\\<not> r)\n    } |\n    formula.EG _ \\<Rightarrow>\n      if PR_CONST F l\\<^sub>0\n      then Alw_ev_checker\n      else return False |\n    formula.Leadsto _ \\<psi> \\<Rightarrow> leadsto_checker \\<psi>\n  )\n  \"\n\nabbreviation \"u\\<^sub>0 \\<equiv> (\\<lambda> _. 0 :: real)\"\n\nlemma all_prop_start:\n  \"all_prop L\\<^sub>0 (map_of s\\<^sub>0)\"\n  using L\\<^sub>0_states s\\<^sub>0_bounded unfolding all_prop_def ..\n\nlemma deadlock_start_iff:\n  \"Graph_Defs.deadlock\n   (\\<lambda>(L, s, u) (L', s', u'). Simple_Network_Language.conv A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow> \\<langle>L', s', u'\\<rangle>) (L\\<^sub>0, (map_of s\\<^sub>0), u\\<^sub>0)\n  \\<longleftrightarrow> reach.deadlock (l\\<^sub>0, u\\<^sub>0)\"\n  using all_prop_start by (subst deadlock_iff[symmetric]) (auto simp: conv_all_prop)\n\nlemma F_Fi':\n  \"check_sexp \\<psi> L (the o s) \\<longleftrightarrow> check_sexpi \\<psi> L' s'\"\n  if \"((L', s'), (L, s)) \\<in> loc_rel\" \"formula = Leadsto \\<phi> \\<psi>\"\n  using vars_of_formula that unfolding loc_rel_def by (auto elim!: check_sexp_check_sexpi)\n\ntheorem model_check':\n  \"(uncurry0 model_checker,\n    uncurry0 (\n      SPEC (\\<lambda>r.\n  \\<not> Graph_Defs.deadlock\n    (\\<lambda>(L, s, u) (L', s', u').\n      Simple_Network_Language.conv A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow> \\<langle>L', s', u'\\<rangle>) (L\\<^sub>0, (map_of s\\<^sub>0), u\\<^sub>0)\n      \\<longrightarrow> r = (Simple_Network_Language.conv A,(L\\<^sub>0, (map_of s\\<^sub>0), u\\<^sub>0) \\<Turnstile> formula)\n      )\n    )\n   )\n  \\<in> unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a bool_assn\"\nproof -\n  define protect where\n    \"protect = ((\\<lambda>(l, u) (l', u'). conv_A prod_ta \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow> \\<langle>l', u'\\<rangle>))\"\n\n  have start: \"l\\<^sub>0 \\<in> Normalized_Zone_Semantics_Impl_Refine.state_set trans_prod\"\n    if \"\\<not> Graph_Defs.deadlock protect (l\\<^sub>0, \\<lambda>_. 0)\"\n    using that unfolding protect_def by (rule impl.init_state_in_state_set[simplified])\n\n  interpret ta_bisim: Bisimulation_Invariant\n    \"(\\<lambda>(l, u) (l', u'). conv_A prod_ta \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow> \\<langle>l', u'\\<rangle>)\"\n    \"(\\<lambda>(l, u) (l', u'). conv_A prod_ta \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow> \\<langle>l', u'\\<rangle>)\"\n    \"(\\<lambda>(l, u) (l', u'). l' = l \\<and> (\\<forall> c. c \\<in> clk_set (conv_A prod_ta) \\<longrightarrow> u c = u' c))\"\n    \"(\\<lambda>_. True)\" \"(\\<lambda>_. True)\"\n    by (rule ta_bisimulation[of \"conv_A prod_ta\"])\n\n  let ?\\<phi>1 = \"\\<lambda>\\<phi>. \\<lambda>(p, _). case p of (L, s) \\<Rightarrow> \\<not> check_sexp \\<phi> L (the \\<circ> s)\"\n  let ?\\<phi>2 = \"\\<lambda>\\<phi>. \\<lambda>(p, _). case p of (L, s) \\<Rightarrow> check_sexp \\<phi> L (the \\<circ> s)\"\n\n  have start_sim:\n    \"ta_bisim.A_B.equiv' (l\\<^sub>0, u) (l\\<^sub>0, \\<lambda>_. 0)\" \"ta_bisim.A_B.equiv' (l\\<^sub>0, \\<lambda>_. 0) (l\\<^sub>0, u)\"\n    if \"\\<forall>c\\<in>{Suc 0..m}. u c = 0\" for u\n    using impl.clocks_I[of u \"\\<lambda>_. 0\"] that unfolding ta_bisim.A_B.equiv'_def by auto\n\n  have compatibleI: \"\\<phi> a = \\<phi> b\"\n    if \"ta_bisim.A_B.equiv' a b\" \"\\<And> l u u'. \\<phi> (l, u) = \\<phi> (l, u')\" for a b \\<phi>\n    using that unfolding ta_bisim.A_B.equiv'_def by auto\n\n  have bisims:\n    \"(\\<forall>u\\<^sub>0. (\\<forall>c\\<in>{Suc 0..m}. u\\<^sub>0 c = 0) \\<longrightarrow> reach.Ex_ev (?\\<phi>1 \\<phi>) (l\\<^sub>0, u\\<^sub>0))\n    \\<longleftrightarrow> reach.Ex_ev (?\\<phi>1 \\<phi>) (l\\<^sub>0, u\\<^sub>0)\"\n    \"(\\<forall>u\\<^sub>0. (\\<forall>c\\<in>{Suc 0..m}. u\\<^sub>0 c = 0) \\<longrightarrow> reach.Ex_ev (?\\<phi>2 \\<phi>) (l\\<^sub>0, u\\<^sub>0))\n    \\<longleftrightarrow> reach.Ex_ev (?\\<phi>2 \\<phi>) (l\\<^sub>0, u\\<^sub>0)\"\n    \"(\\<forall>u\\<^sub>0. (\\<forall>c\\<in>{Suc 0..m}. u\\<^sub>0 c = 0) \\<longrightarrow> reach.Alw_ev (?\\<phi>1 \\<phi>) (l\\<^sub>0, u\\<^sub>0))\n    \\<longleftrightarrow> reach.Alw_ev (?\\<phi>1 \\<phi>) (l\\<^sub>0, u\\<^sub>0)\"\n    \"(\\<forall>u\\<^sub>0. (\\<forall>c\\<in>{Suc 0..m}. u\\<^sub>0 c = 0) \\<longrightarrow> reach.Alw_ev (?\\<phi>2 \\<phi>) (l\\<^sub>0, u\\<^sub>0))\n    \\<longleftrightarrow> reach.Alw_ev (?\\<phi>2 \\<phi>) (l\\<^sub>0, u\\<^sub>0)\"\n    \"(\\<forall>u\\<^sub>0. (\\<forall>c\\<in>{Suc 0..m}. u\\<^sub>0 c = 0) \\<longrightarrow> reach.leadsto (?\\<phi>2 \\<phi>) (?\\<phi>2 \\<psi>) (l\\<^sub>0, u\\<^sub>0))\n    \\<longleftrightarrow> reach.leadsto (?\\<phi>2 \\<phi>) (?\\<phi>2 \\<psi>) (l\\<^sub>0, u\\<^sub>0)\"\n    for \\<phi> \\<psi>\n        apply auto\n    subgoal for u\n      using start_sim\n      by (subst (asm) ta_bisim.Ex_ev_iff[of \"?\\<phi>1 \\<phi>\" \"?\\<phi>1 \\<phi>\"]) (erule compatibleI, auto)\n    subgoal for u\n      using start_sim\n      by (subst (asm) ta_bisim.Ex_ev_iff[of \"?\\<phi>2 \\<phi>\" \"?\\<phi>2 \\<phi>\"]) (erule compatibleI, auto)\n    subgoal for u\n      using start_sim\n      by (subst (asm) ta_bisim.Alw_ev_iff[of \"?\\<phi>1 \\<phi>\" \"?\\<phi>1 \\<phi>\"]) (erule compatibleI, auto)\n    subgoal for u\n      using start_sim\n      by (subst (asm) ta_bisim.Alw_ev_iff[of \"?\\<phi>2 \\<phi>\" \"?\\<phi>2 \\<phi>\"]) (erule compatibleI, auto)\n    subgoal for u\n      using start_sim\n      by (subst (asm) ta_bisim.Leadsto_iff[of \"?\\<phi>2 \\<phi>\" \"?\\<phi>2 \\<phi>\" \"?\\<phi>2 \\<psi>\" \"?\\<phi>2 \\<psi>\"])\n        ((erule compatibleI)?; auto)+\n    done\n\n  have deadlock_bisim:\n    \"(\\<forall>u\\<^sub>0. (\\<forall>c\\<in>{1..m}. u\\<^sub>0 c = 0) \\<longrightarrow> \\<not> reach.deadlock (l\\<^sub>0, u\\<^sub>0))\n    \\<longleftrightarrow> \\<not> Graph_Defs.deadlock protect (l\\<^sub>0, \\<lambda>_. 0)\"\n    unfolding protect_def\n    apply (safe; clarsimp)\n    apply (drule start_sim(2))\n    apply (subst (asm) ta_bisim.deadlock_iff)\n    unfolding ta_bisim.A_B.equiv'_def\n    by auto\n\n  have *****:\n    \"return True = (return False \\<bind> return o Not)\"\n    by auto\n\n  show ?thesis\n    unfolding deadlock_start_iff\n    using models_correct[OF L\\<^sub>0_states s\\<^sub>0_bounded]\n    unfolding protect_def[symmetric]\n    apply (simp split del: if_split)\n    apply sepref_to_hoare\n    apply sep_auto\n    unfolding model_checker_def Alw_ev_checker_def leadsto_checker_def reachability_checker_def\n    apply (cases formula; simp)\n\n    subgoal\n      apply (cases \"Graph_Defs.deadlock protect (l\\<^sub>0, \\<lambda>_. 0)\")\n      subgoal\n        using impl.pw_impl_hnr_F_reachable[to_hnr, unfolded hn_refine_def]\n        by (sep_auto elim!: cons_post_rule)\n      subgoal\n        using impl.Ex_ev_impl_hnr[unfolded deadlock_bisim, to_hnr, unfolded hn_refine_def]\n        by (sep_auto simp: pure_def protect_def bisims)\n      done\n\n    subgoal premises prems for \\<phi>\n    proof -\n      have *: \"(\\<lambda>(l, u). \\<not> F l) = ((\\<lambda>(p, _). case p of (L, s) \\<Rightarrow> \\<not> check_sexp \\<phi> L (the \\<circ> s)))\"\n        using prems by auto\n      show ?thesis\n        using impl.Alw_ev_impl_hnr[to_hnr, unfolded hn_refine_def] prems start\n        unfolding PR_CONST_def * protect_def\n        by (sep_auto elim!: cons_post_rule simp: pure_def bisims)\n    qed\n\n    subgoal premises prems for \\<phi>\n    proof -\n      have *: \"(\\<lambda>(l, u). \\<not> F l) = ((\\<lambda>(p, _). case p of (L, s) \\<Rightarrow> check_sexp \\<phi> L (the \\<circ> s)))\"\n        using prems by auto\n      show ?thesis\n        apply intros\n        subgoal\n          using impl.Alw_ev_impl_hnr[to_hnr, unfolded hn_refine_def] prems start\n          unfolding PR_CONST_def * protect_def\n          apply simp\n          unfolding *****\n          apply (erule bind_rule)\n          apply (sep_auto simp: pure_def bisims(2-))\n          done\n        subgoal\n          using impl.Alw_ev_impl_hnr[to_hnr, unfolded hn_refine_def] prems start\n          unfolding PR_CONST_def * protect_def\n          apply (sep_auto elim!: cons_post_rule simp: pure_def bisims(2-))\n          done\n        done\n    qed\n\n    subgoal\n      apply (cases \"Graph_Defs.deadlock protect (l\\<^sub>0, \\<lambda>_. 0)\")\n      subgoal\n        using impl.pw_impl_hnr_F_reachable[to_hnr, unfolded hn_refine_def]\n        by (sep_auto elim!: cons_post_rule)\n      subgoal\n        using impl.Ex_ev_impl_hnr[unfolded deadlock_bisim, to_hnr, unfolded hn_refine_def]\n        apply (sep_auto simp: pure_def protect_def bisims)\n        done\n      done\n\n    subgoal premises prems for \\<phi> \\<psi>\n    proof -\n      have *: \"(\\<lambda>(l, u). F l) = ((\\<lambda>(p, _). case p of (L, s) \\<Rightarrow> check_sexp \\<phi> L (the \\<circ> s)))\"\n        using prems by auto\n      have **:\"(\\<lambda>(L, s). \\<not> check_sexpi \\<psi> L s, \\<lambda>(L, s). \\<not> check_sexp \\<psi> L (the \\<circ> s))\n               \\<in> inv_rel loc_rel states'\"\n        unfolding trans_of_prod using prems by (auto simp: F_Fi' inv_rel_def)\n      have ****: \"(\\<lambda>(l, u). \\<not> (case l of (L, s) \\<Rightarrow> \\<not> check_sexp \\<psi> L (the \\<circ> s)))\n      = (\\<lambda>(l, u). (case l of (L, s) \\<Rightarrow> check_sexp \\<psi> L (the \\<circ> s)))\"\n        by auto\n      show ?thesis\n        apply (cases \"reach.deadlock (l\\<^sub>0, \\<lambda>_. 0)\")\n        subgoal\n          using impl.leadsto_impl_hnr'[OF **, to_hnr, unfolded hn_refine_def]\n          unfolding protect_def \\<open>formula = _\\<close> by (sep_auto simp: pure_def)\n        using impl.leadsto_impl_hnr[unfolded deadlock_bisim, to_hnr, unfolded hn_refine_def, OF **]\n          prems start\n        unfolding PR_CONST_def * protect_def by (sep_auto simp: pure_def bisims ****)\n    qed\n    done\nqed\n\n\nsubsection \\<open>Extracting an efficient implementation\\<close>\n\nlemma reachability_checker_alt_def':\n  \"reachability_checker \\<equiv>\n    do {\n      x \\<leftarrow> do {\n        let key = return \\<circ> fst;\n        let sub = impl.subsumes_impl;\n        let copy = impl.state_copy_impl;\n        let start = impl.a\\<^sub>0_impl;\n        let final = impl.F_impl;\n        let succs =  impl.succs_impl;\n        let empty = impl.emptiness_check_impl;\n        let trace = impl.tracei;\n        pw_impl key copy trace sub start final succs empty\n      };\n      _ \\<leftarrow> return ();\n      return x\n    }\"\n  unfolding reachability_checker_def by simp\n\nlemma Alw_ev_checker_alt_def':\n  \"Alw_ev_checker \\<equiv>\n    do {\n      x \\<leftarrow> let\n        key = return \\<circ> fst;\n        sub = impl.subsumes_impl;\n        copy = impl.state_copy_impl;\n        start = impl.a\\<^sub>0_impl;\n        succs =  impl.succs_P_impl' Fi\n      in dfs_map_impl' succs start sub key copy;\n      _ \\<leftarrow> return ();\n      return x\n    }\"\n  unfolding Alw_ev_checker_def by simp\n\nlemma leadsto_checker_alt_def':\n  \"leadsto_checker \\<psi> \\<equiv>\n    do {\n      r \\<leftarrow> let\n        key = return \\<circ> fst;\n        sub = impl.subsumes_impl;\n        copy = impl.state_copy_impl;\n        start = impl.a\\<^sub>0_impl;\n        final = impl.F_impl;\n        final' = (impl.Q_impl (\\<lambda>(L, s). \\<not> check_sexpi \\<psi> L s));\n        succs =  impl.succs_P_impl' (\\<lambda>(L, s). \\<not> check_sexpi \\<psi> L s);\n        succs' =  impl.succs_impl';\n        empty = impl.emptiness_check_impl;\n        trace = impl.tracei\n      in\n        leadsto_impl copy succs start sub key succs' empty final final' trace;\n      return (\\<not> r)\n    }\"\n  unfolding leadsto_checker_def by simp\n\ntheorem k_impl_alt_def:\n  \"k_impl = (\\<lambda>(l, s). IArray (map (\\<lambda>c. MAX i \\<in> {0..<n_ps}. k_i !! i !! (l ! i) !! c) [0..<m + 1]))\"\nproof -\n  have \"{i. i < p} = {0..<p}\" for p :: nat\n    by auto\n  then show ?thesis\n    unfolding k_impl_def setcompr_eq_image by simp\nqed\n\ndefinition\n  \"trans_map_inner \\<equiv> map (\\<lambda>i. union_map_of (fst (snd (snd (automata ! i))))) [0..<n_ps]\"\n\nlemma trans_map_alt_def:\n  \"trans_map i j = (case (IArray trans_map_inner !! i) j of None \\<Rightarrow> [] | Some xs \\<Rightarrow> xs)\"\n  if \"i < n_ps\"\n  using that unfolding trans_map_inner_def trans_map_def by (auto simp: n_ps_def)\n\nschematic_goal succs_impl_alt_def:\n  \"impl.succs_impl \\<equiv> ?impl\"\n  unfolding impl.succs_impl_def\n  apply (abstract_let impl.E_op''_impl E_op''_impl)\n  unfolding impl.E_op''_impl_def fw_impl'_int\n  apply (abstract_let trans_impl trans_impl)\n  unfolding trans_impl_def\n  apply (abstract_let int_trans_impl int_trans_impl)\n  apply (abstract_let bin_trans_from_impl bin_trans_impl)\n  apply (abstract_let broad_trans_from_impl broad_trans_impl)\n  unfolding int_trans_impl_def bin_trans_from_impl_def broad_trans_from_impl_def\n  apply (abstract_let trans_in_broad_grouped trans_in_broad_grouped)\n  apply (abstract_let trans_out_broad_grouped trans_out_broad_grouped)\n  apply (abstract_let trans_in_map trans_in_map)\n  apply (abstract_let trans_out_map trans_out_map)\n  apply (abstract_let int_trans_from_all_impl int_trans_from_all_impl)\n  unfolding int_trans_from_all_impl_def\n  apply (abstract_let int_trans_from_vec_impl int_trans_from_vec_impl)\n  unfolding int_trans_from_vec_impl_def\n  apply (abstract_let int_trans_from_loc_impl int_trans_from_loc_impl)\n  unfolding int_trans_from_loc_impl_def\n  apply (abstract_let trans_i_map trans_i_map)\n  unfolding trans_out_broad_grouped_def trans_out_broad_map_def\n  unfolding trans_in_broad_grouped_def trans_in_broad_map_def\n  unfolding trans_in_map_def trans_out_map_def\n  unfolding trans_i_map_def\n  apply (abstract_let trans_map trans_map)\n  apply (abstract_let \"inv_fun :: nat list \\<times> int list \\<Rightarrow> _\" inv_fun)\n  unfolding inv_fun_alt_def\n  apply (abstract_let invs2 invs)\n  unfolding invs2_def\n  unfolding k_impl_alt_def\n  apply (abstract_let k_i k_i) (* Could be killed *)\n  apply (abstract_let n_ps n_ps)\n  by (rule Pure.reflexive)\n\nschematic_goal succs_P_impl_alt_def:\n  \"impl.succs_P_impl Pi \\<equiv> ?impl\"\n  if \"(Pi, P) \\<in> inv_rel loc_rel states'\"\n  for P Pi\n  unfolding impl.succs_P_impl_def[OF that]\n  apply (abstract_let impl.E_op''_impl E_op''_impl)\n  unfolding impl.E_op''_impl_def fw_impl'_int\n  apply (abstract_let \"trans_impl\" trans_impl)\n  unfolding trans_impl_def\n  apply (abstract_let \"int_trans_impl\" int_trans_impl)\n  apply (abstract_let \"bin_trans_from_impl\" bin_trans_impl)\n  apply (abstract_let \"broad_trans_from_impl\" broad_trans_impl)\n  unfolding int_trans_impl_def bin_trans_from_impl_def broad_trans_from_impl_def\n  apply (abstract_let trans_in_broad_grouped trans_in_broad_grouped)\n  apply (abstract_let trans_out_broad_grouped trans_out_broad_grouped)\n  apply (abstract_let trans_in_map trans_in_map)\n  apply (abstract_let trans_out_map trans_out_map)\n  apply (abstract_let int_trans_from_all_impl int_trans_from_all_impl)\n  unfolding int_trans_from_all_impl_def\n  apply (abstract_let int_trans_from_vec_impl int_trans_from_vec_impl)\n  unfolding int_trans_from_vec_impl_def\n  apply (abstract_let int_trans_from_loc_impl int_trans_from_loc_impl)\n  unfolding int_trans_from_loc_impl_def\n  apply (abstract_let trans_i_map trans_i_map)\n  unfolding trans_out_broad_grouped_def trans_out_broad_map_def\n  unfolding trans_in_broad_grouped_def trans_in_broad_map_def\n  unfolding trans_in_map_def trans_out_map_def\n  unfolding trans_i_map_def\n  apply (abstract_let trans_map trans_map)\n  apply (abstract_let \"inv_fun :: nat list \\<times> int list \\<Rightarrow> _\" inv_fun)\n  unfolding inv_fun_alt_def\n  apply (abstract_let invs2 invs)\n  unfolding invs2_def\n  unfolding k_impl_alt_def\n  apply (abstract_let k_i k_i) (* Could be killed *)\n  apply (abstract_let n_ps n_ps)\n  by (rule Pure.reflexive)\n\n\n(* XXX These implementations contain unnecessary list reversals *)\nlemmas succs_P'_impl_alt_def =\n  impl.succs_P_impl'_def[OF impl.F_fun, unfolded succs_P_impl_alt_def[OF impl.F_fun]]\n\nschematic_goal Alw_ev_checker_alt_def:\n  \"Alw_ev_checker \\<equiv> ?impl\"\n  unfolding Alw_ev_checker_alt_def'\n  unfolding succs_P'_impl_alt_def\n  unfolding k_impl_alt_def k_i_def\n  (* The following are just to unfold things that should have been defined in a defs locale *)\n  unfolding impl.E_op''_impl_def impl.abstr_repair_impl_def impl.abstra_repair_impl_def\n  unfolding\n    impl.start_inv_check_impl_def impl.unbounded_dbm_impl_def\n    impl.unbounded_dbm'_def\n  unfolding impl.init_dbm_impl_def impl.a\\<^sub>0_impl_def\n  unfolding impl.F_impl_def\n  unfolding impl.subsumes_impl_def\n  unfolding impl.emptiness_check_impl_def\n  unfolding impl.state_copy_impl_def\n  by (rule Pure.reflexive)\n\nlemma \\<psi>_compatibleI:\n  \"(\\<lambda>(L, s). \\<not> check_sexpi \\<psi> L s, \\<lambda>(L, s). \\<not> check_sexp \\<psi> L (the \\<circ> s)) \\<in> inv_rel loc_rel states'\"\n  if \"formula = Leadsto \\<phi> \\<psi>\"\n  using F_Fi'[OF _ that] unfolding inv_rel_def by auto\n\nlemma Q_impl_alt_def:\n  \"impl.Q_impl (\\<lambda>(L, s). \\<not> check_sexpi \\<psi> L s) \\<equiv>\n  \\<lambda>xi. return (case xi of (a1, a2) \\<Rightarrow> (\\<lambda>(L, s). \\<not> check_sexpi \\<psi> L s) a1)\"\n  if \"formula = Leadsto \\<phi> \\<psi>\"\n  by (intro impl.Q_impl_def[where Q = \"\\<lambda>(L, s). \\<not> check_sexp \\<psi> L (the o s)\"] \\<psi>_compatibleI[OF that])\n\nschematic_goal leadsto_checker_alt_def:\n  \"leadsto_checker \\<psi> \\<equiv> ?impl\" if \"formula = Leadsto \\<phi> \\<psi>\"\n  unfolding leadsto_checker_alt_def'\n  unfolding Q_impl_alt_def[OF that] impl.F_impl_def\n  unfolding impl.succs_P_impl'_def[OF \\<psi>_compatibleI[OF that]]\n  unfolding succs_P_impl_alt_def[OF \\<psi>_compatibleI[OF that]]\n  unfolding impl.succs_impl'_def succs_impl_alt_def\n  unfolding k_impl_alt_def k_i_def\n  (* The following are just to unfold things that should have been defined in a defs locale *)\n  unfolding impl.E_op''_impl_def impl.abstr_repair_impl_def impl.abstra_repair_impl_def\n  unfolding\n    impl.start_inv_check_impl_def impl.unbounded_dbm_impl_def\n    impl.unbounded_dbm'_def\n  unfolding impl.init_dbm_impl_def impl.a\\<^sub>0_impl_def\n  unfolding impl.F_impl_def\n  unfolding impl.subsumes_impl_def\n  unfolding impl.emptiness_check_impl_def\n  unfolding impl.state_copy_impl_def\n  by (rule Pure.reflexive)\n\nschematic_goal reachability_checker_alt_def:\n  \"reachability_checker \\<equiv> ?impl\"\n  unfolding reachability_checker_alt_def'\n  unfolding succs_impl_alt_def\n  unfolding k_impl_alt_def k_i_def\n  (* The following are just to unfold things that should have been defined in a defs locale *)\n  unfolding impl.E_op''_impl_def impl.abstr_repair_impl_def impl.abstra_repair_impl_def\n  unfolding\n    impl.start_inv_check_impl_def impl.unbounded_dbm_impl_def\n    impl.unbounded_dbm'_def\n  unfolding impl.init_dbm_impl_def impl.a\\<^sub>0_impl_def\n  unfolding impl.F_impl_def\n  unfolding impl.subsumes_impl_def\n  unfolding impl.emptiness_check_impl_def\n  unfolding impl.state_copy_impl_def\n  by (rule Pure.reflexive)\n\nend (* Simple_Network_Impl_nat_ceiling_start_state *)\n\nconcrete_definition reachability_checker\n  uses Simple_Network_Impl_nat_ceiling_start_state.reachability_checker_alt_def\n\nconcrete_definition Alw_ev_checker\n  uses Simple_Network_Impl_nat_ceiling_start_state.Alw_ev_checker_alt_def\n\nconcrete_definition leadsto_checker\n  uses Simple_Network_Impl_nat_ceiling_start_state.leadsto_checker_alt_def\n\ncontext Simple_Network_Impl_nat_ceiling_start_state\nbegin\n\nlemma model_checker_unfold_leadsto:\n  \"model_checker = (\n  case formula of Simple_Network_Language_Model_Checking.formula.EX xa \\<Rightarrow> reachability_checker\n    | Simple_Network_Language_Model_Checking.formula.EG xa \\<Rightarrow>\n      if PR_CONST F l\\<^sub>0 then Alw_ev_checker else return False\n    | Simple_Network_Language_Model_Checking.formula.AX xa \\<Rightarrow>\n      (if PR_CONST F l\\<^sub>0 then Alw_ev_checker else return False) \\<bind> (\\<lambda>r. return (\\<not> r))\n    | Simple_Network_Language_Model_Checking.formula.AG xa \\<Rightarrow>\n      reachability_checker \\<bind> (\\<lambda>r. return (\\<not> r))\n    | Simple_Network_Language_Model_Checking.formula.Leadsto \\<phi> \\<psi> \\<Rightarrow>\n      Simple_Network_Language_Model_Checking.leadsto_checker\n        broadcast bounds' automata m num_states num_actions k L\\<^sub>0 s\\<^sub>0 formula \\<psi> show_clock show_state)\n\"\n  unfolding model_checker_def\n  using leadsto_checker.refine[OF Simple_Network_Impl_nat_ceiling_start_state_axioms]\n  by (simp split: formula.split)\n\nlemmas model_checker_def_refined = model_checker_unfold_leadsto[unfolded\n    reachability_checker.refine[OF Simple_Network_Impl_nat_ceiling_start_state_axioms]\n    Alw_ev_checker.refine[OF Simple_Network_Impl_nat_ceiling_start_state_axioms]\n  ]\n\nend (* Simple_Network_Impl_nat_ceiling_start_state *)\n\nconcrete_definition model_checker uses\n  Simple_Network_Impl_nat_ceiling_start_state.model_checker_def_refined\n\ndefinition precond_mc where\n  \"precond_mc\n    show_clock show_state broadcast bounds' automata m num_states num_actions k L\\<^sub>0 s\\<^sub>0 formula \\<equiv>\n    if Simple_Network_Impl_nat_ceiling_start_state\n      broadcast bounds' automata m num_states num_actions k L\\<^sub>0 s\\<^sub>0 formula\n    then\n      model_checker\n        broadcast bounds' automata m num_states num_actions k L\\<^sub>0 s\\<^sub>0 formula show_clock show_state\n      \\<bind> (\\<lambda> x. return (Some x))\n    else return None\"\n\n\nabbreviation N where\n  \"N broadcast automata bounds \\<equiv>\n  Simple_Network_Language.conv\n    (set broadcast, map automaton_of automata, map_of bounds)\"\n\ndefinition has_deadlock where\n  \"has_deadlock A a\\<^sub>0 \\<equiv>\n    Graph_Defs.deadlock (\\<lambda> (L, s, u) (L', s', u'). A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow> \\<langle>L', s', u'\\<rangle>) a\\<^sub>0\"\n\ntheorem model_check:\n  \"<emp> precond_mc\n    show_clock show_state broadcast bounds automata m num_states num_actions k L\\<^sub>0 s\\<^sub>0 formula\n    <\\<lambda> Some r \\<Rightarrow> \\<up>(\n        Simple_Network_Impl_nat_ceiling_start_state\n          broadcast bounds automata m num_states num_actions k L\\<^sub>0 s\\<^sub>0 formula \\<and>\n        (\\<not> has_deadlock (N broadcast automata bounds) (L\\<^sub>0, map_of s\\<^sub>0, \\<lambda>_ . 0) \\<longrightarrow>\n          r = N broadcast automata bounds,(L\\<^sub>0, map_of s\\<^sub>0, \\<lambda>_ . 0) \\<Turnstile> formula\n        ))\n     | None \\<Rightarrow> \\<up>(\\<not> Simple_Network_Impl_nat_ceiling_start_state\n        broadcast bounds automata m num_states num_actions k L\\<^sub>0 s\\<^sub>0 formula)\n    >\\<^sub>t\"\nproof -\n  define A where \"A \\<equiv> N broadcast automata bounds\"\n  define check where \"check \\<equiv> A,(L\\<^sub>0, map_of s\\<^sub>0, \\<lambda>_ . 0) \\<Turnstile> formula\"\n  note [sep_heap_rules] =\n    Simple_Network_Impl_nat_ceiling_start_state.model_check'[\n      to_hnr, unfolded hn_refine_def,\n      of broadcast bounds automata m num_states num_actions k L\\<^sub>0 s\\<^sub>0 formula,\n      unfolded UPPAAL_Reachability_Problem_precompiled_defs.init_def,\n      folded A_def check_def has_deadlock_def,\n      simplified\n      ]\n  show ?thesis\n    unfolding A_def[symmetric] check_def[symmetric]\n    unfolding precond_mc_def\n    by (sep_auto simp: model_checker.refine[symmetric] pure_def)\nqed\n\nend (* Theory *)", "meta": {"author": "wimmers", "repo": "munta", "sha": "62cb1a4a4dbcfcf62c365e90faba15b0012d5a12", "save_path": "github-repos/isabelle/wimmers-munta", "path": "github-repos/isabelle/wimmers-munta/munta-62cb1a4a4dbcfcf62c365e90faba15b0012d5a12/Simple_Networks/Simple_Network_Language_Model_Checking.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.607663184043154, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.2707318958474127}}
{"text": "(*  Title:      HOL/Auth/n_mutualEx_lemma_invs_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mutualEx Protocol Case Study*} \n\ntheory n_mutualEx_lemma_invs_on_rules imports n_mutualEx_lemma_inv__1_on_rules n_mutualEx_lemma_inv__2_on_rules n_mutualEx_lemma_inv__3_on_rules n_mutualEx_lemma_inv__4_on_rules n_mutualEx_lemma_inv__5_on_rules\nbegin\nlemma invs_on_rules:\n  assumes a1: \"f \\<in> invariants N\" and a2: \"r \\<in> rules N\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have b1: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__1  p__Inv3 p__Inv4)\\<or>\n    (\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__2  p__Inv4)\\<or>\n    (\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__3  p__Inv3 p__Inv4)\\<or>\n    (\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__4  p__Inv4)\\<or>\n    (\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__5  p__Inv3 p__Inv4)\"\n  apply (cut_tac a1, auto) done\n    moreover {\n      assume c1: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__1  p__Inv3 p__Inv4)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__1_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__2  p__Inv4)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__2_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__3  p__Inv3 p__Inv4)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__3_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__4  p__Inv4)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__4_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__5  p__Inv3 p__Inv4)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__5_on_rules) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "paraVerifier", "repo": "paraVerifier", "sha": "5de62b433a160bf8d714e0a5085a38b9dd8899f0", "save_path": "github-repos/isabelle/paraVerifier-paraVerifier", "path": "github-repos/isabelle/paraVerifier-paraVerifier/paraVerifier-5de62b433a160bf8d714e0a5085a38b9dd8899f0/proof_scripts/mutualEx/n_mutualEx_lemma_invs_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631698328917, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.27073188951632116}}
{"text": "(* \n   Title: The pi-calculus   \n   Author/Maintainer: Jesper Bengtson (jebe.dk), 2012\n*)\ntheory Weak_Early_Step_Sim_Pres\n  imports Weak_Early_Step_Sim\nbegin\n\nlemma tauPres:\n  fixes P    :: pi\n  and   Q    :: pi\n  and   Rel  :: \"(pi \\<times> pi) set\"\n  and   Rel' :: \"(pi \\<times> pi) set\"\n\n  assumes PRelQ: \"(P, Q) \\<in> Rel\"\n\n  shows \"\\<tau>.(P) \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> \\<tau>.(Q)\"\nproof(induct rule: simCases)\n  case(Bound a x Q')\n  have \"\\<tau>.(Q) \\<longmapsto>a<\\<nu>x> \\<prec> Q'\" by fact\n  hence False by(induct rule: tauCases', auto)\n  thus ?case by simp\nnext\n  case(Free \\<alpha> Q')\n  have \"\\<tau>.(Q) \\<longmapsto>(\\<alpha> \\<prec> Q')\" by fact\n  thus ?case\n  proof(induct rule: tauCases', auto simp add: pi.inject residual.inject)\n    have \"\\<tau>.(P) \\<Longrightarrow> \\<tau> \\<prec> P\" by(rule Weak_Early_Step_Semantics.Tau)\n    with PRelQ show \"\\<exists>P'. \\<tau>.(P) \\<Longrightarrow> \\<tau> \\<prec> P' \\<and> (P', Q) \\<in> Rel\" by blast\n  qed\nqed\n\nlemma inputPres:\n  fixes P    :: pi\n  and   x    :: name\n  and   Q    :: pi\n  and   a    :: name\n  and   Rel  :: \"(pi \\<times> pi) set\"\n\n  assumes PRelQ: \"\\<forall>y. (P[x::=y], Q[x::=y]) \\<in> Rel\"\n  and     Eqvt: \"eqvt Rel\"\n\n  shows \"a<x>.P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> a<x>.Q\"\nusing Eqvt\nproof(induct rule: simCasesCont[where C=\"(x, a, P, Q)\"])\n  case(Bound b y Q')\n  from `y \\<sharp> (x, a, P, Q)` have \"y \\<noteq> x\" \"y \\<noteq> a\" \"y \\<sharp> P\" \"y \\<sharp> Q\" by simp+\n  from `a<x>.Q \\<longmapsto>b<\\<nu>y> \\<prec> Q'` `y \\<noteq> a` `y \\<noteq> x` `y \\<sharp> Q` show ?case\n    by(erule_tac inputCases') auto\nnext\n  case(Free \\<alpha> Q')\n  from `a<x>.Q \\<longmapsto> \\<alpha> \\<prec> Q'`\n  show ?case\n  proof(induct rule: inputCases)\n    case(cInput u)\n    have \"a<x>.P \\<Longrightarrow>(a<u>) \\<prec> (P[x::=u])\"\n      by(rule Weak_Early_Step_Semantics.Input)\n    moreover from PRelQ have \"(P[x::=u], Q[x::=u]) \\<in> Rel\" by auto\n    ultimately show ?case by blast\n  qed\nqed\n\nlemma outputPres:\n  fixes P    :: pi\n  and   Q    :: pi\n  and   a    :: name\n  and   b    :: name\n  and   Rel  :: \"(pi \\<times> pi) set\"\n  and   Rel' :: \"(pi \\<times> pi) set\"\n\n  assumes PRelQ: \"(P, Q) \\<in> Rel\"\n\n  shows \"a{b}.P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> a{b}.Q\"\nproof(induct rule: simCases)\n  case(Bound c x Q')\n  have \"a{b}.Q \\<longmapsto>c<\\<nu>x> \\<prec> Q'\" by fact\n  hence False by(induct rule: outputCases', auto)\n  thus ?case by simp\nnext\n  case(Free \\<alpha> Q')\n  have \"a{b}.Q \\<longmapsto>\\<alpha> \\<prec> Q'\" by fact\n  thus \"\\<exists>P'. a{b}.P \\<Longrightarrow> \\<alpha> \\<prec> P' \\<and> (P', Q') \\<in> Rel\"\n  proof(induct rule: outputCases', auto simp add: pi.inject residual.inject)\n    have \"a{b}.P \\<Longrightarrow> a[b] \\<prec> P\" by(rule Weak_Early_Step_Semantics.Output)\n    with PRelQ show \"\\<exists>P'. a{b}.P \\<Longrightarrow> a[b] \\<prec> P' \\<and> (P', Q) \\<in> Rel\" by blast\n  qed\nqed\n\n\n\n  assumes PSimQ: \"P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\n  and     RelRel': \"Rel \\<subseteq> Rel'\"\n\n  shows \"[a\\<frown>b]P \\<leadsto>\\<guillemotleft>Rel'\\<guillemotright> [a\\<frown>b]Q\"\nproof(induct rule: simCases)\n  case(Bound c x Q')\n  have \"x \\<sharp> [a\\<frown>b]P\" by fact\n  hence xFreshP: \"(x::name) \\<sharp> P\" by simp\n  have \"[a\\<frown>b]Q \\<longmapsto>c<\\<nu>x> \\<prec> Q'\" by fact\n  thus ?case\n  proof(induct rule: matchCases)\n    case Match\n    have \"Q \\<longmapsto>c<\\<nu>x> \\<prec> Q'\" by fact\n    with PSimQ xFreshP obtain P' where PTrans: \"P \\<Longrightarrow>c<\\<nu>x> \\<prec> P'\"\n                                   and P'RelQ': \"(P', Q') \\<in> Rel\"\n      by(blast dest: simE)\n    from PTrans have \"[a\\<frown>a]P \\<Longrightarrow>c<\\<nu>x> \\<prec> P'\" by(rule Weak_Early_Step_Semantics.Match)\n    moreover from P'RelQ' RelRel' have \"(P', Q') \\<in> Rel'\" by blast\n    ultimately show ?case by blast\n  qed\nnext\n  case(Free \\<alpha> Q')\n  have \"[a\\<frown>b]Q \\<longmapsto>\\<alpha> \\<prec> Q'\" by fact\n  thus ?case\n  proof(induct rule: matchCases)\n    case Match\n    have \"Q \\<longmapsto> \\<alpha> \\<prec> Q'\" by fact\n    with PSimQ obtain P' where PTrans: \"P \\<Longrightarrow>\\<alpha> \\<prec> P'\" and PRel: \"(P', Q') \\<in> Rel\"\n      by(blast dest: simE)\n    from PTrans have \"[a\\<frown>a]P \\<Longrightarrow>\\<alpha> \\<prec> P'\" by(rule Weak_Early_Step_Semantics.Match)\n    with RelRel' PRel show ?case by blast\n  qed\nqed\n\nlemma mismatchPres:\n  fixes P    :: pi\n  and   Q    :: pi\n  and   a    :: name\n  and   b    :: name\n  and   Rel  :: \"(pi \\<times> pi) set\"\n  and   Rel' :: \"(pi \\<times> pi) set\"\n\n  assumes PSimQ: \"P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\n  and     RelRel': \"Rel \\<subseteq> Rel'\"\n\n  shows \"[a\\<noteq>b]P \\<leadsto>\\<guillemotleft>Rel'\\<guillemotright> [a\\<noteq>b]Q\"\nproof(induct rule: simCases)\n  case(Bound c x Q')\n  have \"x \\<sharp> [a\\<noteq>b]P\" by fact\n  hence xFreshP: \"(x::name) \\<sharp> P\" by simp\n  have \"[a\\<noteq>b]Q \\<longmapsto>c<\\<nu>x> \\<prec> Q'\" by fact\n  thus ?case\n  proof(induct rule: mismatchCases)\n    case Mismatch\n    have aineqb: \"a \\<noteq> b\" by fact\n    have \"Q \\<longmapsto>c<\\<nu>x> \\<prec> Q'\" by fact\n    with PSimQ xFreshP obtain P' where PTrans: \"P \\<Longrightarrow>c<\\<nu>x> \\<prec> P'\"\n                                   and P'RelQ': \"(P', Q') \\<in> Rel\"\n      by(blast dest: simE)\n    from PTrans aineqb have \"[a\\<noteq>b]P \\<Longrightarrow>c<\\<nu>x> \\<prec> P'\" by(rule Weak_Early_Step_Semantics.Mismatch)\n    moreover from P'RelQ' RelRel' have \"(P', Q') \\<in> Rel'\" by blast\n    ultimately show ?case by blast\n  qed\nnext\n  case(Free \\<alpha> Q')\n  have \"[a\\<noteq>b]Q \\<longmapsto>\\<alpha> \\<prec> Q'\" by fact\n  thus ?case\n  proof(induct rule: mismatchCases)\n    case Mismatch\n    have \"Q \\<longmapsto>\\<alpha> \\<prec> Q'\" by fact\n    with PSimQ obtain P' where PTrans: \"P \\<Longrightarrow>\\<alpha> \\<prec> P'\" and PRel: \"(P', Q') \\<in> Rel\"\n      by(blast dest: simE)\n    from PTrans `a \\<noteq> b` have \"[a\\<noteq>b]P \\<Longrightarrow>\\<alpha> \\<prec> P'\" by(rule Weak_Early_Step_Semantics.Mismatch)\n    with RelRel' PRel show ?case by blast\n  qed\nqed\n\nlemma sumPres:\n  fixes P :: pi\n  and   Q :: pi\n  and   R :: pi\n\n  assumes PSimQ: \"P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\n  and     RelRel': \"Rel \\<subseteq> Rel'\"\n  and     C: \"Id \\<subseteq> Rel'\"\n\n  shows \"P \\<oplus> R \\<leadsto>\\<guillemotleft>Rel'\\<guillemotright> Q \\<oplus> R\"\nproof(induct rule: simCases)\n  case(Bound a x Q')\n  have \"x \\<sharp> P \\<oplus> R\" by fact\n  hence xFreshP: \"(x::name) \\<sharp> P\" and xFreshR: \"x \\<sharp> R\" by simp+\n  have \"Q \\<oplus> R \\<longmapsto>a<\\<nu>x> \\<prec> Q'\" by fact\n  thus ?case\n  proof(induct rule: sumCases)\n    case Sum1\n    have \"Q \\<longmapsto>a<\\<nu>x> \\<prec> Q'\" by fact\n    with xFreshP PSimQ obtain P' where PTrans: \"P \\<Longrightarrow>a<\\<nu>x> \\<prec> P'\" and P'RelQ': \"(P', Q') \\<in> Rel\"\n      by(blast dest: simE)\n    from PTrans have \"P \\<oplus> R \\<Longrightarrow>a<\\<nu>x> \\<prec> P'\" by(rule Weak_Early_Step_Semantics.Sum1)\n    moreover from P'RelQ' RelRel' have \"(P', Q') \\<in> Rel'\" by blast\n    ultimately show ?case by blast\n  next\n    case Sum2\n    from `R \\<longmapsto>a<\\<nu>x> \\<prec> Q'` have \"P \\<oplus> R \\<longmapsto>a<\\<nu>x> \\<prec> Q'\" by(rule Early_Semantics.Sum2)\n    hence \"P \\<oplus> R \\<Longrightarrow>a<\\<nu>x> \\<prec> Q'\" by(rule Weak_Early_Step_Semantics.singleActionChain)\n    moreover from C have \"(Q', Q') \\<in> Rel'\" by blast\n    ultimately show ?case by blast\n  qed\nnext\n  case(Free \\<alpha> Q')\n  have \"Q \\<oplus> R \\<longmapsto>\\<alpha> \\<prec> Q'\" by fact\n  thus ?case\n  proof(induct rule: sumCases)\n    case Sum1\n    have \"Q \\<longmapsto>\\<alpha> \\<prec> Q'\" by fact\n    with PSimQ obtain P' where PTrans: \"P \\<Longrightarrow>\\<alpha> \\<prec> P'\" and PRel: \"(P', Q') \\<in> Rel\" \n      by(blast dest: simE)\n    from PTrans have \"P \\<oplus> R \\<Longrightarrow>\\<alpha> \\<prec> P'\" by(rule Weak_Early_Step_Semantics.Sum1)\n    with RelRel' PRel show ?case by blast\n  next\n    case Sum2\n    from `R \\<longmapsto>\\<alpha> \\<prec> Q'` have \"P \\<oplus> R \\<longmapsto>\\<alpha> \\<prec> Q'\" by(rule Early_Semantics.Sum2)\n    hence \"P \\<oplus> R \\<Longrightarrow>\\<alpha> \\<prec> Q'\" by(rule Weak_Early_Step_Semantics.singleActionChain)\n    moreover from C have \"(Q', Q') \\<in> Rel'\" by blast\n    ultimately show ?case by blast\n  qed\nqed\n      \nlemma parPres:\n  fixes P     :: pi\n  and   Q     :: pi\n  and   R     :: pi\n  and   T     :: pi\n  and   Rel   :: \"(pi \\<times> pi) set\"\n  and   Rel'  :: \"(pi \\<times> pi) set\"\n  and   Rel'' :: \"(pi \\<times> pi) set\"\n  \n  assumes PSimQ:    \"P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\n  and     PRelQ:    \"(P, Q) \\<in> Rel\"\n  and     Par:      \"\\<And>S T U. (S, T) \\<in> Rel \\<Longrightarrow> (S \\<parallel> U, T \\<parallel> U) \\<in> Rel'\"\n  and     Res:      \"\\<And>S T x. (S, T) \\<in> Rel' \\<Longrightarrow> (<\\<nu>x>S, <\\<nu>x>T) \\<in> Rel'\"\n\n  shows \"P \\<parallel> R \\<leadsto>\\<guillemotleft>Rel'\\<guillemotright> Q \\<parallel> R\"\nproof -\n  show ?thesis\n  proof(induct rule: simCases)\n    case(Bound a x Q')\n    have \"x \\<sharp> P \\<parallel> R\" by fact\n    hence xFreshP: \"x \\<sharp> P\" and xFreshR: \"x \\<sharp> R\" by simp+\n    have \"Q \\<parallel> R \\<longmapsto>a<\\<nu>x> \\<prec> Q'\" by fact\n    thus ?case\n    proof(induct rule: parCasesB)\n      case(cPar1 Q')\n      have QTrans: \"Q \\<longmapsto> a<\\<nu>x> \\<prec> Q'\" by fact\n      from xFreshP PSimQ QTrans obtain P' where PTrans:\"P \\<Longrightarrow> a<\\<nu>x> \\<prec> P'\"\n                                            and P'RelQ': \"(P', Q') \\<in> Rel\"\n        by(blast dest: simE)\n      from PTrans xFreshR have \"P \\<parallel> R \\<Longrightarrow> a<\\<nu>x> \\<prec> (P' \\<parallel> R)\" by(rule Weak_Early_Step_Semantics.Par1B)\n      moreover from P'RelQ' have \"(P' \\<parallel> R, Q' \\<parallel> R) \\<in> Rel'\" by(rule Par)\n      ultimately show ?case by blast\n    next\n      case(cPar2 R')\n      from `R \\<longmapsto> a<\\<nu>x> \\<prec> R'` `x \\<sharp> P` have \"P \\<parallel> R \\<longmapsto>a<\\<nu>x> \\<prec> (P \\<parallel> R')\"\n        by(rule Early_Semantics.Par2B)\n      hence \"P \\<parallel> R \\<Longrightarrow> a<\\<nu>x> \\<prec> (P \\<parallel> R')\" by(rule Weak_Early_Step_Semantics.singleActionChain)\n      moreover from PRelQ have \"(P \\<parallel> R', Q \\<parallel>  R') \\<in> Rel'\" by(rule Par)\n      ultimately show ?case by blast\n    qed\n  next\n    case(Free \\<alpha> QR')\n    have \"Q \\<parallel> R \\<longmapsto> \\<alpha> \\<prec> QR'\" by fact\n    thus ?case\n    proof(induct rule: parCasesF[of _ _ _ _ _ \"(P, R)\"])\n      case(cPar1 Q')\n      have \"Q \\<longmapsto> \\<alpha> \\<prec> Q'\" by fact\n      with PSimQ obtain P' where PTrans: \"P \\<Longrightarrow> \\<alpha> \\<prec> P'\" and PRel: \"(P', Q') \\<in> Rel\"\n        by(blast dest: simE)\n      from PTrans have Trans: \"P \\<parallel> R \\<Longrightarrow> \\<alpha> \\<prec> P' \\<parallel> R\" by(rule Weak_Early_Step_Semantics.Par1F)\n      moreover from PRel have \"(P' \\<parallel> R, Q' \\<parallel> R) \\<in> Rel'\" by(blast intro: Par)\n      ultimately show ?case by blast\n    next\n      case(cPar2 R')\n      from `R \\<longmapsto>\\<alpha> \\<prec> R'` have \"P \\<parallel> R \\<longmapsto>\\<alpha> \\<prec> (P \\<parallel> R')\"\n        by(rule Early_Semantics.Par2F)\n      hence \"P \\<parallel> R \\<Longrightarrow>\\<alpha> \\<prec> (P \\<parallel> R')\" by(rule Weak_Early_Step_Semantics.singleActionChain)\n      moreover from PRelQ have \"(P \\<parallel> R', Q \\<parallel>  R') \\<in> Rel'\" by(rule Par)\n      ultimately show ?case by blast\n    next\n      case(cComm1 Q' R' a b)\n      have QTrans: \"Q \\<longmapsto> a<b> \\<prec> Q'\" and RTrans: \"R \\<longmapsto> a[b] \\<prec> R'\" by fact+\n\n      from PSimQ QTrans obtain P' where PTrans: \"P \\<Longrightarrow>a<b> \\<prec> P'\"\n                                    and P'RelQ': \"(P', Q') \\<in> Rel\"\n        by(blast dest: simE)\n      from RTrans have \"R \\<Longrightarrow>a[b] \\<prec> R'\" by(rule Weak_Early_Step_Semantics.singleActionChain)\n      with PTrans have \"P \\<parallel> R \\<Longrightarrow> \\<tau> \\<prec> P' \\<parallel> R'\" by(rule Weak_Early_Step_Semantics.Comm1)\n      moreover from P'RelQ' have \"(P' \\<parallel> R', Q' \\<parallel> R') \\<in> Rel'\" by(rule Par)\n      ultimately show ?case by blast\n    next\n      case(cComm2 Q' R' a b)\n      have QTrans: \"Q \\<longmapsto>a[b] \\<prec> Q'\" and RTrans: \"R \\<longmapsto>a<b> \\<prec> R'\" by fact+\n      \n      from PSimQ QTrans obtain P' where PTrans: \"P \\<Longrightarrow>a[b] \\<prec> P'\"\n                                    and P'RelQ': \"(P', Q') \\<in> Rel\"\n        by(blast dest: simE)\n      \n      from RTrans have \"R \\<Longrightarrow>a<b> \\<prec> R'\" by(rule Weak_Early_Step_Semantics.singleActionChain)\n      with PTrans have \"P \\<parallel> R \\<Longrightarrow> \\<tau> \\<prec> P' \\<parallel> R'\" by(rule Weak_Early_Step_Semantics.Comm2)\n      moreover from P'RelQ' have \"(P' \\<parallel> R', Q' \\<parallel> R') \\<in> Rel'\" by(rule Par)\n      ultimately show ?case by blast\n    next\n      case(cClose1 Q' R' a x)\n      have QTrans: \"Q \\<longmapsto>a<x> \\<prec> Q'\" and RTrans: \"R \\<longmapsto>a<\\<nu>x> \\<prec> R'\" by fact+\n      have \"x \\<sharp> (P, R)\" by fact\n      hence xFreshP: \"x \\<sharp> P\" and xFreshR: \"x \\<sharp> R\" by(simp add: fresh_prod)+\n      \n      from PSimQ QTrans obtain P' where PTrans: \"P \\<Longrightarrow>a<x> \\<prec> P'\"\n                                    and P'RelQ': \"(P', Q') \\<in> Rel\"\n        by(blast dest: simE)\n      \n      from RTrans have \"R \\<Longrightarrow>a<\\<nu>x> \\<prec> R'\" by(rule Weak_Early_Step_Semantics.singleActionChain)\n      with PTrans have Trans: \"P \\<parallel> R \\<Longrightarrow> \\<tau> \\<prec> <\\<nu>x>(P' \\<parallel> R')\" using `x \\<sharp> P`\n        by(rule Weak_Early_Step_Semantics.Close1)\n      moreover from P'RelQ' have \"(<\\<nu>x>(P' \\<parallel> R'), <\\<nu>x>(Q' \\<parallel> R')) \\<in> Rel'\"\n        by(blast intro: Par Res)\n      ultimately show ?case by blast\n    next\n      case(cClose2 Q' R' a x)\n      have QTrans: \"Q \\<longmapsto>a<\\<nu>x> \\<prec> Q'\" and RTrans: \"R \\<longmapsto>a<x> \\<prec> R'\" by fact+\n      have \"x \\<sharp> (P, R)\" by fact\n      hence xFreshR: \"x \\<sharp> R\" and xFreshP: \"x \\<sharp> P\" by(simp add: fresh_prod)+\n\n      from PSimQ QTrans xFreshP obtain P' where PTrans: \"P \\<Longrightarrow>a<\\<nu>x> \\<prec> P'\"\n                                            and P'RelQ': \"(P', Q') \\<in> Rel\"\n        by(blast dest: simE)\n      \n      from RTrans have \"R \\<Longrightarrow>a<x> \\<prec> R'\" by(rule Weak_Early_Step_Semantics.singleActionChain)\n      with PTrans have Trans: \"P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> <\\<nu>x>(P' \\<parallel> R')\" using `x \\<sharp> R`\n        by(rule Weak_Early_Step_Semantics.Close2)\n      moreover from P'RelQ' have \"(<\\<nu>x>(P' \\<parallel> R'), <\\<nu>x>(Q' \\<parallel> R')) \\<in> Rel'\"\n        by(blast intro: Par Res)\n      ultimately show ?case by blast\n    qed\n  qed\nqed\n\n\n\n  assumes PSimQ: \"P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\n  and     C1: \"\\<And>R S x. (R, S) \\<in> Rel \\<Longrightarrow> (<\\<nu>x>R, <\\<nu>x>S) \\<in> Rel'\"\n  and     RelRel': \"Rel \\<subseteq> Rel'\"\n  and     EqvtRel: \"eqvt Rel\"\n  and     EqvtRel': \"eqvt Rel'\"\n\n  shows \"<\\<nu>x>P \\<leadsto>\\<guillemotleft>Rel'\\<guillemotright> <\\<nu>x>Q\"\nproof -\n  from EqvtRel' show ?thesis\n  proof(induct rule: simCasesCont[of _ \"(P, x)\"])\n    case(Bound a y Q')\n    have Trans: \"<\\<nu>x>Q \\<longmapsto>a<\\<nu>y> \\<prec> Q'\" by fact\n    have \"y \\<sharp> (P, x)\" by fact\n    hence yineqx: \"y \\<noteq> x\" and yFreshP: \"y \\<sharp> P\" by(simp add: fresh_prod)+\n    from Trans yineqx show ?case\n    proof(induct rule: resCasesB)\n      case(Open Q')\n      have QTrans: \"Q \\<longmapsto>a[x] \\<prec> Q'\" and aineqx: \"a \\<noteq> x\" by fact+\n\n      from PSimQ QTrans obtain P' where PTrans: \"P \\<Longrightarrow>a[x] \\<prec> P'\"\n                                    and P'RelQ': \"(P', Q') \\<in> Rel\"\n        by(blast dest: simE)\n\n      from PTrans aineqx have \"<\\<nu>x>P \\<Longrightarrow>a<\\<nu>x> \\<prec> P'\" by(rule Weak_Early_Step_Semantics.Open)\n      hence \"<\\<nu>x>P \\<Longrightarrow>a<\\<nu>y> \\<prec> ([(y, x)] \\<bullet> P')\" using `y \\<sharp> P` `y \\<noteq> x`\n        by(force simp add: weakTransitionAlpha abs_fresh name_swap)\n\n      moreover from EqvtRel P'RelQ' RelRel' have \"([(y, x)] \\<bullet> P', [(y, x)] \\<bullet> Q') \\<in> Rel'\"\n        by(blast intro: eqvtRelI)\n      ultimately show ?case by blast\n    next\n      case(Res Q')\n      have QTrans: \"Q \\<longmapsto>a<\\<nu>y> \\<prec> Q'\" and xineqa: \"x \\<noteq> a\" by fact+\n\n      from PSimQ yFreshP QTrans obtain P' where PTrans: \"P \\<Longrightarrow>a<\\<nu>y> \\<prec> P'\"\n                                            and P'RelQ': \"(P', Q') \\<in> Rel\"\n        by(blast dest: simE)\n      from PTrans xineqa yineqx yFreshP have ResTrans: \"<\\<nu>x>P \\<Longrightarrow>a<\\<nu>y> \\<prec> (<\\<nu>x>P')\"\n        by(blast intro: Weak_Early_Step_Semantics.ResB)\n      moreover from P'RelQ' have \"((<\\<nu>x>P'), (<\\<nu>x>Q')) \\<in> Rel'\"\n        by(rule C1)\n      ultimately show ?case by blast\n    qed\n  next\n    case(Free \\<alpha> Q')\n    have QTrans: \"<\\<nu>x>Q \\<longmapsto> \\<alpha> \\<prec> Q'\" by fact\n    have \"\\<exists>c::name. c \\<sharp> (P, Q, Q', \\<alpha>)\" by(blast intro: name_exists_fresh)\n    then obtain c::name where cFreshQ: \"c \\<sharp> Q\" and cFreshAlpha: \"c \\<sharp> \\<alpha>\" and cFreshQ': \"c \\<sharp> Q'\" and cFreshP: \"c \\<sharp> P\"\n      by(force simp add: fresh_prod)\n    from cFreshP have \"<\\<nu>x>P = <\\<nu>c>([(x, c)] \\<bullet> P)\" by(simp add: alphaRes)\n    moreover have \"\\<exists>P'.<\\<nu>c>([(x, c)] \\<bullet> P) \\<Longrightarrow> \\<alpha> \\<prec> P' \\<and> (P', Q') \\<in> Rel'\"\n    proof -\n      from QTrans cFreshQ have \"<\\<nu>c>([(x, c)] \\<bullet> Q) \\<longmapsto>\\<alpha> \\<prec> Q'\" by(simp add: alphaRes)\n      moreover have \"c \\<sharp> \\<alpha>\" by(rule cFreshAlpha)\n      moreover from PSimQ EqvtRel have \"([(x, c)] \\<bullet> P) \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> ([(x, c)] \\<bullet> Q)\"\n        by(blast intro: eqvtI)\n      ultimately show ?thesis\n        apply(induct rule: resCasesF, auto simp add: residual.inject pi.inject name_abs_eq)\n        by(blast intro: Weak_Early_Step_Semantics.ResF C1 dest: simE)\n    qed\n\n    ultimately show ?case by force\n  qed\nqed\n\nlemma resChainI:\n  fixes P   :: pi\n  and   Q   :: pi\n  and   Rel :: \"(pi \\<times> pi) set\"\n  and   lst :: \"name list\"\n\n  assumes eqvtRel: \"eqvt Rel\"\n  and     Res:     \"\\<And>R S x. (R, S) \\<in> Rel \\<Longrightarrow> (<\\<nu>x>R, <\\<nu>x>S) \\<in> Rel\"\n  and     PRelQ:   \"P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\n\n  shows \"(resChain lst) P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> (resChain lst) Q\"\nproof -\n  show ?thesis\n  proof(induct lst) (* Base case *)\n    from PRelQ show \"resChain [] P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> resChain [] Q\" by simp\n  next (* Inductive step *)\n    fix a lst\n    assume IH: \"(resChain lst P) \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> (resChain lst Q)\"\n    moreover from Res have \"\\<And>P Q a. (P, Q) \\<in> Rel \\<Longrightarrow> (<\\<nu>a>P, <\\<nu>a>Q) \\<in> Rel\"\n      by simp\n    moreover have \"Rel \\<subseteq> Rel\" by simp\n    ultimately have \"<\\<nu>a>(resChain lst P) \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> <\\<nu>a>(resChain lst Q)\" using eqvtRel\n      by(rule_tac resPres)\n\n    thus \"resChain (a # lst) P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> resChain (a # lst) Q\"\n      by simp\n  qed\nqed\n\n\n\n  shows \"!P \\<leadsto>\\<guillemotleft>bangRel Rel'\\<guillemotright> !Q\"\nproof -\n  let ?Sim = \"\\<lambda>P Rs. (\\<forall>a x Q'. Rs = a<\\<nu>x> \\<prec> Q' \\<longrightarrow> x \\<sharp> P \\<longrightarrow> (\\<exists>P'. P \\<Longrightarrow>a<\\<nu>x> \\<prec> P' \\<and> (P', Q') \\<in> bangRel Rel')) \\<and>\n                     (\\<forall>\\<alpha> Q'. Rs = \\<alpha> \\<prec> Q' \\<longrightarrow> (\\<exists>P'. P \\<Longrightarrow>\\<alpha> \\<prec> P' \\<and> (P', Q') \\<in> bangRel Rel'))\"\n  from eqvtRel have EqvtBangRel: \"eqvt(bangRel Rel')\" by(rule eqvtBangRel)\n  from C1 have BRelRel': \"\\<And>P Q. (P, Q) \\<in> bangRel Rel \\<Longrightarrow> (P, Q) \\<in> bangRel Rel'\"\n    by(auto intro: bangRelSubset)\n\n  {\n    fix Pa Rs\n    assume \"!Q \\<longmapsto> Rs\" and \"(Pa, !Q) \\<in> bangRel Rel\"\n    hence \"?Sim Pa Rs\" using PRelQ \n    proof(nominal_induct avoiding: Pa P rule: bangInduct)\n      case(Par1B a x Q' Pa P)\n      have QTrans: \"Q \\<longmapsto> a<\\<nu>x> \\<prec> Q'\" by fact\n      have \"(Pa, Q \\<parallel> !Q) \\<in> bangRel Rel\" and \"x \\<sharp> Pa\" by fact+\n      thus \"?Sim Pa (a<\\<nu>x> \\<prec> (Q' \\<parallel> !Q))\"\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" by fact\n        have PBRQ: \"(R, !Q) \\<in> bangRel Rel\" by fact\n        have \"x \\<sharp> P \\<parallel> R\" by fact\n        hence xFreshP: \"x \\<sharp> P\" and xFreshR: \"x \\<sharp> R\" by simp+\n        show ?case \n        proof(auto simp add: residual.inject alpha')\n          from PRelQ have \"P \\<leadsto>\\<guillemotleft>Rel'\\<guillemotright> Q\" by(rule Sim)\n\n          with QTrans xFreshP obtain P' where PTrans: \"P \\<Longrightarrow>a<\\<nu>x> \\<prec> P'\" and P'RelQ': \"(P', Q') \\<in> Rel'\"\n            by(blast dest: simE)\n\n          from PTrans xFreshR have \"P \\<parallel> R \\<Longrightarrow>a<\\<nu>x> \\<prec> (P' \\<parallel> R)\"\n            by(force intro: Weak_Early_Step_Semantics.Par1B)\n          moreover from P'RelQ' PBRQ BRelRel' have \"(P' \\<parallel> R, Q' \\<parallel> !Q) \\<in> bangRel Rel'\" by(blast intro: Rel.BRPar)\n          ultimately show \"\\<exists>P'. P \\<parallel> R \\<Longrightarrow>a<\\<nu>x> \\<prec> P' \\<and> (P', Q' \\<parallel> !Q) \\<in> bangRel Rel'\" by blast\n        next\n          fix y\n          assume \"(y::name) \\<sharp> Q'\" and \"y \\<sharp> P\" and \"y \\<sharp> R\" and \"y \\<sharp> Q\"\n          from QTrans `y \\<sharp> Q'` have \"Q \\<longmapsto>a<\\<nu>y> \\<prec> ([(x, y)] \\<bullet> Q')\"\n            by(simp add: alphaBoundOutput)\n          moreover from PRelQ have \"P \\<leadsto>\\<guillemotleft>Rel'\\<guillemotright> Q\" by(rule Sim)\n          ultimately obtain P' where PTrans: \"P \\<Longrightarrow>a<\\<nu>y> \\<prec> P'\" and P'RelQ': \"(P', [(x, y)] \\<bullet> Q') \\<in> Rel'\"\n            using `y \\<sharp> P`\n            by(blast dest: simE)\n          from PTrans `y \\<sharp> R` have \"P \\<parallel> R \\<Longrightarrow>a<\\<nu>y> \\<prec> (P' \\<parallel> R)\" by(force intro: Weak_Early_Step_Semantics.Par1B)\n          moreover from P'RelQ' PBRQ BRelRel' have \"(P' \\<parallel> R, ([(x, y)] \\<bullet> Q') \\<parallel> !Q) \\<in> bangRel Rel'\" by(metis Rel.BRPar)\n          with `x \\<sharp> Q` `y \\<sharp> Q` have \"(P' \\<parallel> R, ([(y, x)] \\<bullet> Q') \\<parallel> !([(y, x)] \\<bullet> Q)) \\<in> bangRel Rel'\"\n            by(simp add: name_fresh_fresh name_swap)\n          ultimately show \"\\<exists>P'. P \\<parallel> R \\<Longrightarrow>a<\\<nu>y> \\<prec> P' \\<and> (P', ([(y, x)] \\<bullet> Q') \\<parallel> !([(y, x)] \\<bullet> Q)) \\<in> bangRel Rel'\"\n            by blast\n        qed\n      qed\n    next\n      case(Par1F \\<alpha> Q' Pa P)\n      have QTrans: \"Q \\<longmapsto>\\<alpha> \\<prec> Q'\" by fact\n      have \"(Pa, Q \\<parallel> !Q) \\<in> bangRel Rel\" by fact\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and BR: \"(R, !Q) \\<in> bangRel Rel\" by fact+\n        show ?case\n        proof(auto simp add: residual.inject)\n          from PRelQ have \"P \\<leadsto>\\<guillemotleft>Rel'\\<guillemotright> Q\" by(rule Sim)\n          with QTrans obtain P' where PTrans: \"P \\<Longrightarrow>\\<alpha> \\<prec> P'\" and RRel: \"(P', Q') \\<in> Rel'\"\n            by(blast dest: simE)\n          \n          from PTrans have \"P \\<parallel> R \\<Longrightarrow>\\<alpha> \\<prec> P' \\<parallel> R\" by(rule Weak_Early_Step_Semantics.Par1F)\n          moreover from RRel BR BRelRel' have \"(P' \\<parallel> R, Q' \\<parallel> !Q) \\<in> bangRel Rel'\" by(metis Rel.BRPar)\n          ultimately show \"\\<exists>P'. P \\<parallel> R \\<Longrightarrow>\\<alpha> \\<prec> P' \\<and> (P', Q' \\<parallel> !Q) \\<in> bangRel Rel'\" by blast\n        qed\n      qed\n    next\n      case(Par2B a x Q' Pa P)\n      hence IH: \"\\<And>Pa. (Pa, !Q) \\<in> bangRel Rel \\<Longrightarrow> ?Sim Pa (a<\\<nu>x> \\<prec> Q')\" by simp\n      have \"(Pa, Q \\<parallel> !Q) \\<in> bangRel Rel\" and \"x \\<sharp> Pa\" by fact+\n      thus \"?Sim Pa (a<\\<nu>x> \\<prec> (Q \\<parallel> Q'))\"\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBRQ: \"(R, !Q) \\<in> bangRel Rel\" by fact+\n        have \"x \\<sharp> P \\<parallel> R\" by fact\n        hence xFreshP: \"x \\<sharp> P\" and xFreshR: \"x \\<sharp> R\" by simp+\n\n        from EqvtBangRel show \"?Sim (P \\<parallel> R) (a<\\<nu>x> \\<prec> (Q \\<parallel> Q'))\"\n        proof(auto simp add: residual.inject alpha')\n          from RBRQ have \"?Sim R (a<\\<nu>x> \\<prec> Q')\" by(rule IH)\n          with xFreshR obtain R' where RTrans: \"R \\<Longrightarrow>a<\\<nu>x> \\<prec> R'\" and R'BRQ': \"(R', Q') \\<in> (bangRel Rel')\"\n            by(metis simE)\n          from RTrans xFreshP have \"P \\<parallel> R \\<Longrightarrow>a<\\<nu>x> \\<prec> (P \\<parallel> R')\" by(auto intro: Weak_Early_Step_Semantics.Par2B)\n          moreover from PRelQ R'BRQ' C1 have \"(P \\<parallel> R', Q \\<parallel> Q') \\<in> (bangRel Rel')\" by(blast dest: Rel.BRPar)\n          ultimately show \"\\<exists>P'. P \\<parallel> R \\<Longrightarrow>a<\\<nu>x> \\<prec> P' \\<and> (P', Q \\<parallel> Q') \\<in> bangRel Rel'\" by blast\n        next\n          fix y\n          assume \"(y::name) \\<sharp> Q\" and \"y \\<sharp> Q'\" and \"y \\<sharp> P\" and \"y \\<sharp> R\"\n          from RBRQ have \"?Sim R (a<\\<nu>x> \\<prec> Q')\" by(rule IH)\n          with `y \\<sharp> Q'` have \"?Sim R (a<\\<nu>y> \\<prec> ([(x, y)] \\<bullet> Q'))\" by(simp add: alphaBoundOutput)\n          with `y \\<sharp> R` obtain R' where RTrans: \"R \\<Longrightarrow>a<\\<nu>y> \\<prec> R'\" and R'BRQ': \"(R', ([(x, y)] \\<bullet> Q')) \\<in> (bangRel Rel')\"\n            by(metis simE)\n          from RTrans `y \\<sharp> P` have \"P \\<parallel> R \\<Longrightarrow>a<\\<nu>y> \\<prec> (P \\<parallel> R')\" by(auto intro: Weak_Early_Step_Semantics.Par2B)\n          moreover from PRelQ R'BRQ' C1 have \"(P \\<parallel> R', Q \\<parallel> ([(x, y)] \\<bullet> Q')) \\<in> (bangRel Rel')\" by(blast dest: Rel.BRPar)\n          with `y \\<sharp> Q` `x \\<sharp> Q` have \"(P \\<parallel> R', ([(y, x)] \\<bullet> Q) \\<parallel> ([(y, x)] \\<bullet> Q')) \\<in> (bangRel Rel')\"\n            by(simp add: name_swap name_fresh_fresh)\n          ultimately show \"\\<exists>P'. P \\<parallel> R \\<Longrightarrow>a<\\<nu>y> \\<prec> P' \\<and> (P', ([(y, x)] \\<bullet> Q) \\<parallel> ([(y, x)] \\<bullet> Q')) \\<in> bangRel Rel'\" by blast\n        qed\n      qed\n    next\n      case(Par2F \\<alpha> Q' Pa P)\n      hence IH: \"\\<And>Pa. (Pa, !Q) \\<in> bangRel Rel \\<Longrightarrow> ?Sim Pa (\\<alpha> \\<prec> Q')\" by simp\n      have \"(Pa, Q \\<parallel> !Q) \\<in> bangRel Rel\" by fact\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBRQ: \"(R, !Q) \\<in> bangRel Rel\" by fact+\n        show ?case\n        proof(auto simp add: residual.inject)\n          from RBRQ IH have \"\\<exists>R'. R \\<Longrightarrow>\\<alpha> \\<prec> R' \\<and> (R', Q') \\<in> bangRel Rel'\"\n            by(metis simE)\n          then obtain R' where RTrans: \"R \\<Longrightarrow>\\<alpha> \\<prec> R'\" and R'RelQ': \"(R', Q') \\<in> bangRel Rel'\"\n            by blast\n\n          from RTrans have \"P \\<parallel> R \\<Longrightarrow>\\<alpha> \\<prec> P \\<parallel> R'\" by(rule Weak_Early_Step_Semantics.Par2F)\n          moreover from PRelQ R'RelQ' C1 have \"(P \\<parallel> R', Q \\<parallel> Q') \\<in> bangRel Rel'\" by(blast dest: Rel.BRPar)\n          ultimately show \" \\<exists>P'. P \\<parallel> R \\<Longrightarrow>\\<alpha> \\<prec> P' \\<and> (P', Q \\<parallel> Q') \\<in> bangRel Rel'\" by blast\n        qed\n      qed\n    next\n      case(Comm1 a Q' b Q'' Pa P)\n      hence IH: \"\\<And>Pa. (Pa, !Q) \\<in> bangRel Rel \\<Longrightarrow> ?Sim Pa (a[b] \\<prec> Q'')\" by simp\n      have QTrans: \"Q \\<longmapsto>a<b> \\<prec> Q'\" by fact\n      have \"(Pa, Q \\<parallel> !Q) \\<in> bangRel Rel\" by fact\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBRQ: \"(R, !Q) \\<in> bangRel Rel\" by fact+\n        show ?case\n        proof(auto simp add: residual.inject)\n          from PRelQ have \"P \\<leadsto>\\<guillemotleft>Rel'\\<guillemotright> Q\" by(rule Sim)\n          with QTrans obtain P' where PTrans: \"P \\<Longrightarrow>a<b> \\<prec> P'\" and P'RelQ': \"(P', Q') \\<in> Rel'\"\n            by(blast dest: simE)\n          \n          from IH RBRQ have RTrans: \"\\<exists>R'. R \\<Longrightarrow>a[b] \\<prec> R' \\<and> (R', Q'') \\<in> bangRel Rel'\"\n            by(metis simE)\n          then obtain R' where RTrans: \"R \\<Longrightarrow>a[b] \\<prec> R'\" and R'RelQ'': \"(R', Q'') \\<in> bangRel Rel'\"\n            by blast\n          \n          from PTrans RTrans have \"P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> P' \\<parallel> R'\" by(rule Weak_Early_Step_Semantics.Comm1)\n          moreover from P'RelQ' R'RelQ'' have \"(P' \\<parallel> R', Q' \\<parallel> Q'') \\<in> bangRel Rel'\" by(rule Rel.BRPar)\n          ultimately show \"\\<exists>P'. P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> P' \\<and> (P', Q' \\<parallel> Q'') \\<in> bangRel Rel'\" by blast\n        qed\n      qed\n    next\n      case(Comm2 a b Q' Q'')\n      hence IH: \"\\<And>Pa. (Pa, !Q) \\<in> bangRel Rel \\<Longrightarrow> ?Sim Pa (a<b> \\<prec> Q'')\" by simp\n      have QTrans: \"Q \\<longmapsto> a[b] \\<prec> Q'\" by fact\n      have \"(Pa, Q \\<parallel> !Q) \\<in> bangRel Rel\" by fact\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBRQ: \"(R, !Q) \\<in> bangRel Rel\" by fact+\n        show ?case\n        proof(auto simp add: residual.inject)\n          from PRelQ have \"P \\<leadsto>\\<guillemotleft>Rel'\\<guillemotright> Q\" by(rule Sim)\n          with QTrans obtain P' where PTrans: \"P \\<Longrightarrow>a[b] \\<prec> P'\" and P'RelQ': \"(P', Q') \\<in> Rel'\"\n            by(blast dest: simE)\n\n          from IH RBRQ have RTrans: \"\\<exists>R'. R \\<Longrightarrow>a<b> \\<prec> R' \\<and> (R', Q'') \\<in> bangRel Rel'\"\n            by(metis simE)\n          then obtain R' where RTrans: \"R \\<Longrightarrow>a<b> \\<prec> R'\" and R'RelQ'': \"(R', Q'') \\<in> bangRel Rel'\"\n            by blast\n\n          from PTrans RTrans have \"P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> P' \\<parallel> R'\" by(rule Weak_Early_Step_Semantics.Comm2)\n          moreover from P'RelQ' R'RelQ'' have \"(P' \\<parallel> R', Q' \\<parallel> Q'') \\<in> bangRel Rel'\" by(rule Rel.BRPar)\n          ultimately show \"\\<exists>P'. P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> P' \\<and> (P', Q' \\<parallel> Q'') \\<in> bangRel Rel'\" by blast\n        qed\n      qed\n    next\n      case(Close1 a x Q' Q'' Pa P)\n      hence IH: \"\\<And>Pa. (Pa, !Q) \\<in> bangRel Rel \\<longrightarrow> ?Sim Pa (a<\\<nu>x> \\<prec> Q'')\" by simp\n      have QTrans: \"Q \\<longmapsto> a<x> \\<prec> Q'\" by fact\n      have xFreshQ: \"x \\<sharp> Q\" by fact\n      have \"(Pa, Q \\<parallel> !Q) \\<in> bangRel Rel\" by fact\n      moreover have xFreshPa: \"x \\<sharp> Pa\" by fact\n      ultimately show ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBRQ: \"(R, !Q) \\<in> bangRel Rel\" by fact+\n        have \"x \\<sharp> P \\<parallel> R\" by fact\n        hence xFreshP: \"x \\<sharp> P\" and xFreshR: \"x \\<sharp> R\" by simp+\n        show ?case\n        proof(auto simp add: residual.inject)\n          from PRelQ have \"P \\<leadsto>\\<guillemotleft>Rel'\\<guillemotright> Q\" by(rule Sim)\n          with QTrans xFreshP obtain P' where PTrans: \"P \\<Longrightarrow>a<x> \\<prec> P'\" and P'RelQ': \"(P', Q') \\<in> Rel'\"\n             by(blast dest: simE)\n\n           from RBRQ xFreshR IH have \"\\<exists>R'. R \\<Longrightarrow>a<\\<nu>x> \\<prec> R' \\<and> (R', Q'') \\<in> bangRel Rel'\"\n             by(metis simE)\n           then obtain R' where RTrans: \"R \\<Longrightarrow>a<\\<nu>x> \\<prec> R'\" and R'RelQ'': \"(R', Q'') \\<in> bangRel Rel'\"\n             by blast\n\n           from PTrans RTrans xFreshP have \"P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> <\\<nu>x>(P' \\<parallel> R')\"\n             by(rule Weak_Early_Step_Semantics.Close1)   \n           moreover from P'RelQ' R'RelQ'' have \"(<\\<nu>x>(P' \\<parallel> R'), <\\<nu>x>(Q' \\<parallel> Q'')) \\<in> bangRel Rel'\"\n             by(force intro: Rel.BRPar BRRes)\n           ultimately show \"\\<exists>P'. P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> P' \\<and> (P', <\\<nu>x>(Q' \\<parallel> Q'')) \\<in> bangRel Rel'\" by blast\n         qed\n      qed\n    next\n      case(Close2 a x Q' Q'' Pa P)\n      hence IH: \"\\<And>Pa. (Pa, !Q) \\<in> bangRel Rel \\<Longrightarrow> ?Sim Pa (a<x> \\<prec> Q'')\" by simp\n      have QTrans: \"Q \\<longmapsto> a<\\<nu>x> \\<prec> Q'\" by fact\n      have xFreshQ: \"x \\<sharp> Q\" by fact\n      have \"(Pa, Q \\<parallel> !Q) \\<in> bangRel Rel\" and \"x \\<sharp> Pa\" by fact+\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBRQ: \"(R, !Q) \\<in> bangRel Rel\" by fact+\n        have \"x \\<sharp> P \\<parallel> R\" by fact\n        hence xFreshP: \"x \\<sharp> P\" and xFreshR: \"x \\<sharp> R\" by simp+\n        show ?case\n        proof(auto simp add: residual.inject)\n          from PRelQ have \"P \\<leadsto>\\<guillemotleft>Rel'\\<guillemotright> Q\" by(rule Sim)\n          with QTrans xFreshP obtain P' where PTrans: \"P \\<Longrightarrow>a<\\<nu>x> \\<prec> P'\" and P'RelQ': \"(P', Q') \\<in> Rel'\"\n            by(blast dest: simE)\n\n          from RBRQ IH have \"\\<exists>R'.  R \\<Longrightarrow>a<x> \\<prec> R' \\<and> (R', Q'') \\<in> bangRel Rel'\"\n            by auto\n          then obtain R' where RTrans: \"R \\<Longrightarrow>a<x> \\<prec> R'\" and R'RelQ'': \"(R', Q'') \\<in> bangRel Rel'\"\n            by blast\n\n          from PTrans RTrans xFreshR have \"P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> <\\<nu>x>(P' \\<parallel> R')\"\n            by(rule Weak_Early_Step_Semantics.Close2)    \n          moreover from P'RelQ' R'RelQ'' have \"(<\\<nu>x>(P' \\<parallel> R'), <\\<nu>x>(Q' \\<parallel> Q'')) \\<in> bangRel Rel'\"\n            by(force intro: Rel.BRPar BRRes)\n          ultimately show \"\\<exists>P'. P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> P' \\<and> (P', <\\<nu>x>(Q' \\<parallel> Q'')) \\<in> bangRel Rel'\" by blast\n        qed\n      qed\n    next\n      case(Bang Rs Pa P)\n      hence IH: \"\\<And>Pa. (Pa, Q \\<parallel> !Q) \\<in> bangRel Rel \\<Longrightarrow> ?Sim Pa Rs\" by simp\n      have \"(Pa, !Q) \\<in> bangRel Rel\" by fact\n      thus ?case\n      proof(induct rule: BRBangCases)\n        case(BRBang P)\n        have PRelQ: \"(P, Q) \\<in> Rel\" by fact\n        hence \"(!P, !Q) \\<in> bangRel Rel\" by(rule Rel.BRBang)\n        with PRelQ have \"(P \\<parallel> !P, Q \\<parallel> !Q) \\<in> bangRel Rel\" by(rule BRPar)\n        with IH have \"?Sim (P \\<parallel> !P) Rs\" by simp\n        thus ?case by(force intro: Weak_Early_Step_Semantics.Bang)\n      qed\n    qed\n  }\n\n  moreover from PRelQ have \"(!P, !Q) \\<in> bangRel Rel\" by(rule BRBang) \n  ultimately show ?thesis by(auto simp add: weakStepSimulation_def)\nqed\n(*\nlemma bangPres:\n  fixes P    :: pi\n  and   Q    :: pi\n  and   Rel  :: \"(pi \\<times> pi) set\"\n  and   Rel' :: \"(pi \\<times> pi) set\"\n \n  assumes PRelQ:      \"(P, Q) \\<in> Rel\"\n  and     Sim:        \"\\<And>P Q. (P, Q) \\<in> Rel \\<Longrightarrow> P \\<leadsto><Rel'> Q\"\n  and     RelRel':    \"\\<And>P Q. (P, Q) \\<in> Rel \\<Longrightarrow> (P, Q) \\<in> Rel'\"\n  and     eqvtRel':   \"eqvt Rel'\"\n\n  shows \"!P \\<leadsto><bangRel Rel'> !Q\"\nproof -\n  from eqvtRel' have EqvtBangRel': \"eqvt (bangRel Rel')\" by(rule eqvtBangRel)\n  from RelRel' have BRelRel': \"\\<And>P Q. (P, Q) \\<in> bangRel Rel \\<Longrightarrow> (P, Q) \\<in> bangRel Rel'\"\n    by(auto intro: bangRelSubset)\n  have \"\\<And>Rs P. \\<lbrakk>!Q \\<longmapsto> Rs; (P, !Q) \\<in> bangRel Rel\\<rbrakk> \\<Longrightarrow> weakSimStepAct P Rs P (bangRel Rel')\"\n  proof -\n    fix Rs P\n    assume \"!Q \\<longmapsto> Rs\" and \"(P, !Q) \\<in> bangRel Rel\"\n    thus \"weakSimStepAct P Rs P (bangRel Rel')\"\n    proof(nominal_induct avoiding: P rule: bangInduct)\n      case(Par1B a x Q')\n      have QTrans: \"Q \\<longmapsto>a<\\<nu>x> \\<prec> Q'\" and xFreshQ: \"x \\<sharp> Q\" by fact\n      have \"(P, Q \\<parallel> !Q) \\<in> bangRel Rel\" and \"x \\<sharp> P\" by fact\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBangRelT: \"(R, !Q) \\<in> bangRel Rel\" by fact\n        have \"x \\<sharp> P \\<parallel> R\" by fact\n        hence xFreshP: \"x \\<sharp> P\" and xFreshR: \"x \\<sharp> R\" by simp+\n        from PRelQ have PSimQ: \"P \\<leadsto><Rel'> Q\" by(rule Sim)\n        from EqvtBangRel' show ?case\n        proof(induct rule: simActBoundCases)\n          case BoundOutput\n          with PSimQ QTrans xFreshP obtain P' where PTrans: \"P \\<Longrightarrow>a<\\<nu>x> \\<prec> P'\"\n                                                and P'RelQ': \"(P', Q') \\<in> Rel'\"\n            by(blast dest: simE)\n          from PTrans xFreshR have \"P \\<parallel> R \\<Longrightarrow>a<\\<nu>x>\\<prec> (P' \\<parallel> R)\"\n            by(rule Weak_Early_Step_Semantics.Par1B)\n          moreover from P'RelQ' RBangRelT have \"(P' \\<parallel> R, Q' \\<parallel> !Q) \\<in> bangRel Rel'\"\n            by(blast intro: Rel.BRPar BRelRel')\n          ultimately show ?case by blast\n        qed\n      qed\n    next\n      case(Par1F \\<alpha> Q' P)\n      have QTrans: \"Q \\<longmapsto>\\<alpha> \\<prec> Q'\" by fact\n      have \"(P, Q \\<parallel> !Q) \\<in> bangRel Rel\" by fact\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBangRelQ: \"(R, !Q) \\<in> bangRel Rel\" by fact\n        show ?case\n        proof(induct rule: simActFreeCases)\n          case Der\n          from PRelQ have \"P \\<leadsto><Rel'> Q\" by(rule Sim)\n          with QTrans obtain P' where PTrans: \"P \\<Longrightarrow>\\<alpha> \\<prec> P'\" and P'RelQ': \"(P', Q') \\<in> Rel'\"\n            by(blast dest: simE)\n\n          from PTrans have \"P \\<parallel> R \\<Longrightarrow>\\<alpha> \\<prec> P' \\<parallel> R\" by(rule Weak_Early_Step_Semantics.Par1F)\n          moreover from P'RelQ' RBangRelQ have \"(P' \\<parallel> R, Q' \\<parallel> !Q) \\<in> bangRel Rel'\"\n            by(blast intro: Rel.BRPar BRelRel')\n          ultimately show ?case by blast\n        qed\n      qed\n    next\n      case(Par2B a x Q' P)\n      have IH: \"\\<And>P. (P, !Q) \\<in> bangRel Rel \\<Longrightarrow> weakSimStepAct P (a<\\<nu>x> \\<prec> Q') P (bangRel Rel')\" by fact\n      have xFreshQ: \"x \\<sharp> Q\" by fact\n      have \"(P, Q \\<parallel> !Q) \\<in> bangRel Rel\" and \"x \\<sharp> P\" by fact\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBangRelQ: \"(R, !Q) \\<in> bangRel Rel\" by fact\n        have \"x \\<sharp> P \\<parallel> R\" by fact\n        hence xFreshP: \"x \\<sharp> P\" and xFreshR: \"x \\<sharp> R\" by simp+\n        from EqvtBangRel' show ?case\n        proof(induct rule: simActBoundCases)\n          case BoundOutput\n          with IH RBangRelQ have \"weakSimStepAct R (a<\\<nu>x> \\<prec> Q') R (bangRel Rel')\" by blast\n          with xFreshR obtain R' where RTrans: \"R \\<Longrightarrow>a<\\<nu>x> \\<prec> R'\"\n                                   and R'BangRelQ': \"(R', Q') \\<in> bangRel Rel'\"\n            by(simp add: weakSimStepAct_def, blast)\n          \n          from RTrans xFreshP have \"P \\<parallel> R \\<Longrightarrow>a<\\<nu>x> \\<prec> (P \\<parallel> R')\"\n            by(auto intro: Weak_Early_Step_Semantics.Par2B)\n          moreover from PRelQ R'BangRelQ' have \"(P \\<parallel> R', Q \\<parallel> Q') \\<in> (bangRel Rel')\"\n            by(blast intro: Rel.BRPar RelRel')\n          ultimately show ?case by blast\n        qed\n      qed\n    next\n      case(Par2F \\<alpha> Q' P)\n      have IH: \"\\<And>P. (P, !Q) \\<in> bangRel Rel \\<Longrightarrow> weakSimStepAct P (\\<alpha> \\<prec> Q') P (bangRel Rel')\" by fact\n      have \"(P, Q \\<parallel> !Q) \\<in> bangRel Rel\" by fact\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBangRelQ: \"(R, !Q) \\<in> bangRel Rel\" by fact\n        show ?case\n        proof(induct rule: simActFreeCases)\n          case Der\n          from RBangRelQ have \"weakSimStepAct R (\\<alpha> \\<prec> Q') R (bangRel Rel')\" by(rule IH)\n          then obtain R' where RTrans: \"R \\<Longrightarrow>\\<alpha> \\<prec> R'\" and R'RelQ': \"(R', Q') \\<in> (bangRel Rel')\"\n            by(simp add: weakSimStepAct_def, blast)\n\n          from RTrans have \"P \\<parallel> R \\<Longrightarrow>\\<alpha> \\<prec> P \\<parallel> R'\" by(rule Weak_Early_Step_Semantics.Par2F)\n          moreover from PRelQ R'RelQ' have \"(P \\<parallel> R', Q \\<parallel> Q') \\<in> (bangRel Rel')\" \n            by(blast intro: Rel.BRPar RelRel')\n          ultimately show ?case by blast\n        qed\n      qed\n    next\n      case(Comm1 a Q' b Q'' P)\n      have QTrans: \"Q \\<longmapsto> a<b> \\<prec> Q'\" by fact\n      have IH: \"\\<And>P. (P, !Q) \\<in> bangRel Rel \\<Longrightarrow> weakSimStepAct P (a[b] \\<prec> Q'') P (bangRel Rel')\" by fact\n      have \"(P, Q \\<parallel> !Q) \\<in> bangRel Rel\" by fact\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBangRelQ: \"(R, !Q) \\<in> bangRel Rel\" by fact\n        show ?case\n        proof(induct rule: simActFreeCases)\n          case Der\n          from PRelQ have \"P \\<leadsto><Rel'> Q\" by(rule Sim)\n          with QTrans obtain P' where PTrans: \"P \\<Longrightarrow>a<b> \\<prec> P'\" and P'RelQ': \"(P', Q') \\<in> Rel'\"\n            by(blast dest: simE)\n\n          from RBangRelQ have \"weakSimStepAct R (a[b] \\<prec> Q'') R (bangRel Rel')\" by(rule IH)\n          then obtain R' where RTrans: \"R \\<Longrightarrow>a[b] \\<prec> R'\"\n                           and R'RelQ'': \"(R', Q'') \\<in> (bangRel Rel')\"\n            by(simp add: weakSimStepAct_def, blast)\n        \n          from PTrans RTrans have \"P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> (P' \\<parallel> R')\"\n            by(rule Weak_Early_Step_Semantics.Comm1)\n          moreover from P'RelQ' R'RelQ'' have \"(P' \\<parallel> R', Q' \\<parallel> Q'') \\<in> (bangRel Rel')\"\n            by(rule Rel.BRPar)\n          ultimately show ?case by blast\n        qed\n      qed\n    next\n      case(Comm2 a b Q' Q'' P)\n      have QTrans: \"Q \\<longmapsto>a[b] \\<prec> Q'\" by fact\n      have IH: \"\\<And>P. (P, !Q) \\<in> bangRel Rel \\<Longrightarrow> weakSimStepAct P (a<b> \\<prec> Q'') P (bangRel Rel')\" by fact\n      have \"(P, Q \\<parallel> !Q) \\<in> bangRel Rel\" by fact\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBangRelQ: \"(R, !Q) \\<in> bangRel Rel\" by fact+\n        show ?case\n        proof(induct rule: simActFreeCases)\n          case Der\n          from PRelQ have \"P \\<leadsto><Rel'> Q\" by(rule Sim)\n          with QTrans obtain P' where PTrans: \"P \\<Longrightarrow>a[b] \\<prec> P'\" and P'RelQ': \"(P', Q') \\<in> Rel'\"\n            by(blast dest: simE)\n\n          from RBangRelQ have \"weakSimStepAct R (a<b> \\<prec> Q'') R (bangRel Rel')\" by(rule IH)\n          then obtain R' where RTrans: \"R \\<Longrightarrow>a<b> \\<prec> R'\" and R'BangRelQ'': \"(R', Q'') \\<in> (bangRel Rel')\"\n            by(simp add: weakSimStepAct_def, blast)\n        \n          from PTrans RTrans have \"P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> (P' \\<parallel> R')\"\n            by(rule Weak_Early_Step_Semantics.Comm2)\n          moreover from P'RelQ' R'BangRelQ'' have \"(P' \\<parallel> R', Q' \\<parallel> Q'') \\<in> (bangRel Rel')\"\n            by(rule Rel.BRPar)\n          ultimately show ?case by blast\n        qed\n      qed\n    next\n      case(Close1 a x Q' Q'' P)\n      have QTrans: \"Q \\<longmapsto> a<x> \\<prec> Q'\" by fact\n      have IH: \"\\<And>P. (P, !Q) \\<in> bangRel Rel \\<Longrightarrow> weakSimStepAct P (a<\\<nu>x> \\<prec> Q'') P (bangRel Rel')\" by fact\n      have \"(P, Q \\<parallel> !Q) \\<in> bangRel Rel\" and \"x \\<sharp> P\" by fact\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBangRelQ: \"(R, !Q) \\<in> bangRel Rel\" by fact\n        have \"x \\<sharp> P \\<parallel> R\" by fact\n        hence xFreshR: \"x \\<sharp> R\" and xFreshP: \"x \\<sharp> P\" by simp+\n        show ?case\n        proof(induct rule: simActFreeCases)\n          case Der\n          from PRelQ have \"P \\<leadsto><Rel'> Q\" by(rule Sim)\n          with QTrans obtain P' where PTrans: \"P \\<Longrightarrow>a<x> \\<prec> P'\" and P'RelQ': \"(P', Q') \\<in> Rel'\"\n            by(blast dest: simE)\n          \n          from RBangRelQ have \"weakSimStepAct R (a<\\<nu>x> \\<prec> Q'') R (bangRel Rel')\" by(rule IH)\n          with xFreshR obtain R' where RTrans: \"R \\<Longrightarrow>a<\\<nu>x> \\<prec> R'\"\n                                   and R'RelQ'': \"(R', Q'') \\<in> (bangRel Rel')\"\n            by(simp add: weakSimStepAct_def, blast)\n        \n          from PTrans RTrans xFreshP xFreshR have \"P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> <\\<nu>x>(P' \\<parallel> R')\"\n            by(rule Weak_Early_Step_Semantics.Close1)\n          moreover from P'RelQ' R'RelQ'' have \"(<\\<nu>x>(P' \\<parallel> R'), <\\<nu>x>(Q' \\<parallel> Q'')) \\<in> (bangRel Rel')\"\n            by(force intro: Rel.BRPar Rel.BRRes)\n          ultimately show ?case by blast\n        qed\n      qed\n    next\n      case(Close2 a x Q' Q'' P)\n      have QTrans: \"Q \\<longmapsto> a<\\<nu>x> \\<prec> Q'\" by fact\n      have IH: \"\\<And>P. (P, !Q) \\<in> bangRel Rel \\<Longrightarrow> weakSimStepAct P (a<x> \\<prec> Q'') P (bangRel Rel')\" by fact\n      have \"(P, Q \\<parallel> !Q) \\<in> bangRel Rel\" and \"x \\<sharp> P\" by fact\n      thus ?case\n      proof(induct rule: BRParCases)\n        case(BRPar P R)\n        have PRelQ: \"(P, Q) \\<in> Rel\" and RBangRelQ: \"(R, !Q) \\<in> bangRel Rel\" by fact\n        have \"x \\<sharp> P \\<parallel> R\" by fact\n        hence xFreshP: \"x \\<sharp> P\" and xFreshR: \"x \\<sharp> R\" by simp+\n        show ?case\n        proof(induct rule: simActFreeCases)\n          case Der\n          from PRelQ have \"P \\<leadsto><Rel'> Q\" by(rule Sim)\n          with QTrans xFreshP obtain P' where PTrans: \"P \\<Longrightarrow>a<\\<nu>x> \\<prec> P'\"\n                                          and P'RelQ': \"(P', Q') \\<in> Rel'\"\n            by(blast dest: simE)\n\n          from RBangRelQ have \"weakSimStepAct R (a<x> \\<prec> Q'') R (bangRel Rel')\" by(rule IH)\n          with xFreshR obtain R' where RTrans: \"R \\<Longrightarrow>a<x> \\<prec> R'\"\n                                       and R'RelQ'': \"(R', Q'') \\<in> (bangRel Rel')\"\n            by(simp add: weakSimStepAct_def, blast)\n        \n          from PTrans RTrans xFreshP xFreshR have \"P \\<parallel> R \\<Longrightarrow>\\<tau> \\<prec> <\\<nu>x>(P' \\<parallel> R')\"\n            by(rule Weak_Early_Step_Semantics.Close2)\n          moreover from P'RelQ' R'RelQ'' have \"(<\\<nu>x>(P' \\<parallel> R'), <\\<nu>x>(Q' \\<parallel> Q'')) \\<in> (bangRel Rel')\"\n            by(force intro: Rel.BRPar Rel.BRRes)\n          ultimately show ?case by blast\n        qed\n      qed\n    next\n      case(Bang Rs)\n      have IH: \"\\<And>P. (P, Q \\<parallel> !Q) \\<in> bangRel Rel \\<Longrightarrow> weakSimStepAct P Rs P (bangRel Rel')\" by fact\n      have \"(P, !Q) \\<in> bangRel Rel\" by fact\n      thus ?case\n      proof(induct rule: BRBangCases)\n        case(BRBang P)\n        have PRelQ: \"(P, Q) \\<in> Rel\" by fact\n        hence \"(!P, !Q) \\<in> bangRel Rel\" by(rule Rel.BRBang)\n        with PRelQ have \"(P \\<parallel> !P, Q \\<parallel> !Q) \\<in> bangRel Rel\" by(rule Rel.BRPar)\n        hence \"weakSimStepAct (P \\<parallel> !P) Rs (P \\<parallel> !P) (bangRel Rel')\" by(rule IH)\n        thus ?case\n        proof(simp (no_asm) add: weakSimStepAct_def, auto)\n          fix Q' a x\n          assume \"weakSimStepAct (P \\<parallel> !P) (a<\\<nu>x> \\<prec> Q') (P \\<parallel> !P) (bangRel Rel')\" and \"x \\<sharp> P\"\n          then obtain P' where PTrans: \"(P \\<parallel> !P) \\<Longrightarrow>a<\\<nu>x> \\<prec> P'\"\n                           and P'RelQ': \"(P', Q') \\<in> (bangRel Rel')\"\n            by(simp add: weakSimStepAct_def, blast)\n          from PTrans have \"!P \\<Longrightarrow>a<\\<nu>x> \\<prec> P'\"\n            by(force intro: Weak_Early_Step_Semantics.Bang simp add: weakTransition_def)\n          with P'RelQ' show \"\\<exists>P'. !P \\<Longrightarrow>a<\\<nu>x> \\<prec> P' \\<and> (P', Q') \\<in> (bangRel Rel')\" by blast\n        next\n          fix Q' \\<alpha>\n          assume \"weakSimStepAct (P \\<parallel> !P) (\\<alpha> \\<prec> Q') (P \\<parallel> !P) (bangRel Rel')\"\n          then obtain P' where PTrans: \"(P \\<parallel> !P) \\<Longrightarrow>\\<alpha> \\<prec> P'\"\n                           and P'RelQ': \"(P', Q') \\<in> (bangRel Rel')\"\n            by(simp add: weakSimStepAct_def, blast)\n          from PTrans have \"!P \\<Longrightarrow>\\<alpha> \\<prec> P'\" by(rule Weak_Early_Step_Semantics.Bang)\n          with P'RelQ' show \"\\<exists>P'. !P \\<Longrightarrow>\\<alpha> \\<prec> P' \\<and> (P', Q') \\<in> (bangRel Rel')\" by blast\n        qed\n      qed\n    qed\n  qed\n  moreover from PRelQ have \"(!P, !Q) \\<in> bangRel Rel\" by(rule Rel.BRBang)\n  ultimately show ?thesis by(simp add: simDef)\nqed\n*)\nend", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Pi_Calculus/Weak_Early_Step_Sim_Pres.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953797290153, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.27072442093692567}}
{"text": "theory SNS_IAS_Eduroam_Spoofing\nimports \n  \"../../Primitive_Matchers/Parser\"\nbegin\n\n\nsection\\<open>Example: Eduroam and sns.ias Firewall Script\\<close>\n\ndefinition \"everything_but_my_ip = all_but_those_ips [(ipv4addr_of_dotdecimal (131,159,207,206), 32)]\"\n\n\ntext\\<open>Incoming: everything but my IP\\<close>\ndefinition \"ipassignment_incoming = [(Iface ''wlan0'', everything_but_my_ip), (Iface ''lo'', [(0,0)])]\"\n\nlemma \"ipassmt_sanity_nowildcards (map_of ipassignment_incoming)\" by eval\n\ntext\\<open>Outgoing: only my IP\\<close>\ndefinition \"ipassignment_outgoing = [(Iface ''wlan0'',  [(ipv4addr_of_dotdecimal (131,159,207,206), 32)]), (Iface ''lo'', [(0,0)])]\"\n\nlemma \"ipassmt_sanity_nowildcards (map_of ipassignment_outgoing)\" by eval\n\nparse_iptables_save eduroam_fw=\"eduroam_iptables-save\"\n\nthm eduroam_fw_def\nthm eduroam_fw_INPUT_default_policy_def\n\nvalue[code] \"debug_ipassmt_ipv4 ipassignment_incoming (unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw))\"\n\nvalue[code] \"unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw)\"\n\nvalue[code] \"collect_ifaces (unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw))\"\n\n\nlemma \"ipassmt_sanity_defined (unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw)) (map_of_ipassmt ipassignment_incoming)\" by eval\nlemma \"ipassmt_sanity_defined (unfold_ruleset_OUTPUT eduroam_fw_OUTPUT_default_policy (map_of_string_ipv4 eduroam_fw)) (map_of_ipassmt ipassignment_outgoing)\" by eval\n\n\nvalue[code] \"debug_ipassmt_ipv4 ipassignment_incoming (unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw))\"\nvalue[code] \"debug_ipassmt_ipv4 ipassignment_outgoing (unfold_ruleset_OUTPUT eduroam_fw_OUTPUT_default_policy (map_of_string_ipv4 eduroam_fw))\"\n\n\ntext\\<open>The ruleset\\<close>\nlemma \"check_simple_fw_preconditions (upper_closure (packet_assume_new (unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw))))\" by eval\nvalue[code] \"map simple_rule_ipv4_toString (to_simple_firewall (upper_closure (packet_assume_new (unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw)))))\"\nlemma \"simple_fw_valid (to_simple_firewall (upper_closure (packet_assume_new (unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw)))))\" by eval\nlemma \"simple_fw_valid (to_simple_firewall (lower_closure (packet_assume_new (unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw)))))\" by eval\n\n\ntext\\<open>We do not need to call things such as @{const transform_optimize_dnf_strict} because the\n     firewall already is in @{const normalized_nnf_match} (required for @{const no_spoofing_iface})\\<close>\nlemma \"transform_optimize_dnf_strict (unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw)) =\n          unfold_ruleset_INPUT action.Drop (map_of_string_ipv4 eduroam_fw)\" by eval\n\ntext\\<open>The ruleset prevents spoofed incoming packets\\<close>\nlemma \"no_spoofing_iface (Iface ''wlan0'')\n        (map_of_ipassmt ipassignment_incoming) (unfold_ruleset_INPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw))\" by eval\n\n\ntext\\<open>Ruleset does not prevent that I'm spoofing (which is not necessary anyways since I need root right to spoof, which \n      would also enable me to deactivate the firewall). This is only a one-user laptop!\\<close>\n\nlemma \"transform_optimize_dnf_strict (unfold_ruleset_OUTPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw)) =\n        unfold_ruleset_OUTPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw)\" by eval\n\nlemma \"\\<not> no_spoofing_iface (Iface ''wlan0'')\n        (map_of_ipassmt ipassignment_outgoing) (unfold_ruleset_OUTPUT eduroam_fw_INPUT_default_policy (map_of_string_ipv4 eduroam_fw))\" by eval\n\n\nend", "meta": {"author": "diekmann", "repo": "Iptables_Semantics", "sha": "e0a2516bd885708fce875023b474ae341cbdee29", "save_path": "github-repos/isabelle/diekmann-Iptables_Semantics", "path": "github-repos/isabelle/diekmann-Iptables_Semantics/Iptables_Semantics-e0a2516bd885708fce875023b474ae341cbdee29/thy/Iptables_Semantics/Examples/sns.ias.edu/SNS_IAS_Eduroam_Spoofing.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953651858118, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.27072441411920817}}
{"text": "section \\<open>Two-Step Observing Quorums Model\\<close>\n\ntheory Two_Step_Observing\nimports \"../Observing_Quorums_Opt\" \"../Two_Steps\"\nbegin\n\ntext \\<open>To make the coming proofs of concrete algorithms easier, in this model we split \n  the @{term olv_round} into two steps.\\<close>\n\nsubsection \\<open>Model definition\\<close>\n(******************************************************************************)\nrecord tso_state = opt_obsv_state +\n  r_votes :: \"process \\<Rightarrow> val option\"\n\ncontext mono_quorum\nbegin\n\ndefinition tso_round0 \n  :: \"round \\<Rightarrow> process set \\<Rightarrow> val \\<Rightarrow> (tso_state \\<times> tso_state)set\"\n  where\n  \"tso_round0 r S v \\<equiv> {(s, s').\n    \\<comment> \\<open>guards\\<close>\n    r = next_round s\n    \\<and> two_step r = 0\n    \\<and> (S \\<noteq> {} \\<longrightarrow> opt_obs_safe (last_obs s) v)\n    \\<comment> \\<open>actions\\<close>\n    \\<and> s' = s\\<lparr>\n      next_round := Suc r\n      , r_votes := const_map v S\n    \\<rparr>\n  }\"\n\ndefinition obs_guard :: \"(process, val)map \\<Rightarrow> (process, val)map \\<Rightarrow> bool\" where\n  \"obs_guard r_obs r_v \\<equiv> \\<forall>p.\n    (\\<forall>v. r_obs p = Some v \\<longrightarrow> (\\<exists>q. r_v q = Some v))\n    \\<and> (dom r_v \\<in> Quorum \\<longrightarrow> (\\<exists>q \\<in> dom r_v. r_obs p = r_v q))\"\n\ndefinition tso_round1 \n  :: \"round \\<Rightarrow> (process, val)map \\<Rightarrow> (process, val)map \\<Rightarrow> (tso_state \\<times> tso_state)set\" \n  where\n  \"tso_round1 r r_decisions r_obs \\<equiv> {(s, s').\n    \\<comment> \\<open>guards\\<close>\n    r = next_round s\n    \\<and> two_step r = 1\n    \\<and> d_guard r_decisions (r_votes s)\n    \\<and> obs_guard r_obs (r_votes s)\n    \\<comment> \\<open>actions\\<close>\n    \\<and> s' = s\\<lparr>\n      next_round := Suc r\n      , decisions := decisions s ++ r_decisions\n      , last_obs := last_obs s ++ r_obs\n    \\<rparr>\n  }\"\n\ndefinition tso_init where\n  \"tso_init = { \\<lparr> next_round = 0, decisions = Map.empty, last_obs = Map.empty, r_votes = Map.empty \\<rparr> }\"\n\ndefinition tso_trans :: \"(tso_state \\<times> tso_state) set\" where\n  \"tso_trans = (\\<Union>r S v. tso_round0 r S v) \\<union> (\\<Union>r d_f o_f. tso_round1 r d_f o_f) \\<union> Id\"\n\ndefinition tso_TS :: \"tso_state TS\" where\n  \"tso_TS = \\<lparr> init = tso_init, trans = tso_trans \\<rparr>\"\n\nlemmas tso_TS_defs = tso_TS_def tso_init_def tso_trans_def\n\nsubsection \\<open>Refinement\\<close>\n(******************************************************************************)\n\ndefinition basic_rel :: \"(opt_obsv_state \\<times> tso_state)set\" where\n  \"basic_rel = {(sa, sc).\n    next_round sa = two_phase (next_round sc)\n    \\<and> last_obs sc = last_obs sa\n    \\<and> decisions sc = decisions sa\n  }\"\n\ndefinition step0_rel :: \"(opt_obsv_state \\<times> tso_state)set\" where\n  \"step0_rel = basic_rel\"\n\ndefinition step1_add_rel :: \"(opt_obsv_state \\<times> tso_state)set\" where\n  \"step1_add_rel = {(sa, sc). \\<exists>S v.\n    r_votes sc = const_map v S\n    \\<and> (S \\<noteq> {} \\<longrightarrow> opt_obs_safe (last_obs sc) v)\n  }\"\n\ndefinition step1_rel :: \"(opt_obsv_state \\<times> tso_state)set\" where\n  \"step1_rel = basic_rel \\<inter> step1_add_rel\"\n\ndefinition tso_ref_rel :: \"(opt_obsv_state \\<times> tso_state)set\" where\n  \"tso_ref_rel \\<equiv> {(sa, sc).\n    (two_step (next_round sc) = 0 \\<longrightarrow> (sa, sc) \\<in> step0_rel)\n    \\<and> (two_step (next_round sc) = 1 \\<longrightarrow> \n        (sa, sc) \\<in> step1_rel\n        \\<and> (\\<exists>sc' r S v. (sc', sc) \\<in> tso_round0 r S v \\<and> (sa, sc') \\<in> step0_rel))\n  }\"\n\nlemma const_map_equality:\n  \"(const_map v S = const_map v' S') = (S = S' \\<and> (S = {} \\<or> v = v'))\"\n  apply(simp add: const_map_def restrict_map_def)\n  by (metis equals0D option.distinct(2) option.inject subsetI subset_antisym)\n\nlemma rhoare_skipI:\n  \"\\<lbrakk> \\<And>sa sc sc'. \\<lbrakk> (sa, sc) \\<in> Pre; (sc, sc') \\<in> Tc \\<rbrakk> \\<Longrightarrow> (sa, sc') \\<in> Post \\<rbrakk> \\<Longrightarrow> {Pre} Id, Tc {>Post}\"\n  by(auto simp add: PO_rhoare_defs)\n\nlemma tso_round0_refines:\n  \"{tso_ref_rel} Id, tso_round0 r S v {>tso_ref_rel}\"\n  apply(rule rhoare_skipI)\n  apply(auto simp add: tso_ref_rel_def basic_rel_def step1_rel_def \n     step1_add_rel_def  step0_rel_def tso_round0_def const_map_equality conj_disj_distribR\n     ex_disj_distrib two_step_phase_Suc)\n  done\n\nlemma tso_round1_refines:\n  \"{tso_ref_rel} \\<Union>r S v dec_f Ob. olv_round r S v dec_f Ob, tso_round1 r dec_f o_f {>tso_ref_rel}\"\nproof(clarsimp simp add: PO_rhoare_defs)\n  fix sa sc and sc'\n  assume\n    R: \"(sa, sc) \\<in> tso_ref_rel\" \n    and step1: \"(sc, sc') \\<in> tso_round1 r dec_f o_f\"\n\n  hence step_r: \"two_step r = 1\" and r_next: \"next_round sc = r\" by (auto simp add: tso_round1_def)\n  then obtain r0 sc0 S0 v0 where \n    R0: \"(sa, sc0) \\<in> step0_rel\" and step0: \"(sc0, sc) \\<in> tso_round0 r0 S0 v0\"\n    using R\n    by(auto simp add: tso_ref_rel_def) \n\n  from step_r r_next R obtain S v where\n    v: \"r_votes sc = const_map v S\"\n    and safe: \"S \\<noteq> {} \\<longrightarrow> opt_obs_safe (last_obs sc) v\"\n    by(auto simp add: tso_ref_rel_def step1_rel_def step1_add_rel_def)\n\n  define sa' where \"sa' = sa\\<lparr> \n      next_round := Suc (next_round sa)\n      , decisions := decisions sa ++ dec_f\n      , last_obs := last_obs sa ++ const_map v (dom o_f)\n    \\<rparr>\"\n\n  have \"S \\<in> Quorum \\<longrightarrow> dom o_f = UNIV\" using step1 v\n    by(auto simp add: tso_round1_def obs_guard_def const_map_def)\n  moreover have \"o_f \\<noteq> Map.empty \\<longrightarrow> S \\<noteq> {}\" using step1 v\n    by(auto simp add: tso_round1_def obs_guard_def dom_const_map)\n  ultimately have \n    abs_step: \n    \"(sa, sa') \\<in> olv_round (next_round sa) S v dec_f (dom o_f)\" using R safe v step_r r_next step1\n    by(clarsimp simp add: tso_ref_rel_def step1_rel_def basic_rel_def sa'_def \n      olv_round_def tso_round1_def)\n\n  from v have post_rel: \"(sa', sc') \\<in> tso_ref_rel\" using R step1\n    apply(clarsimp simp add: tso_round0_def tso_round1_def \n      step0_rel_def basic_rel_def  sa'_def tso_ref_rel_def two_step_phase_Suc o_def\n      const_map_is_Some const_map_is_None const_map_equality obs_guard_def \n      intro!: arg_cong2[where f=map_add, OF refl])\n    apply(auto simp add: const_map_def restrict_map_def intro!: ext)\n    done\n\n  from abs_step post_rel show \n    \"\\<exists>sa'. (\\<exists>r' S' w dec_f' Ob'. (sa, sa') \\<in> olv_round r' S' w dec_f' Ob') \\<and> (sa', sc') \\<in> tso_ref_rel\"\n    by blast\nqed\n  \nlemma TS_Observing_Refines:\n  \"PO_refines tso_ref_rel olv_TS tso_TS\"\n  apply(auto simp add: PO_refines_def olv_TS_defs tso_TS_defs \n    intro!: tso_round0_refines tso_round1_refines)\n  apply(auto simp add: tso_ref_rel_def step0_rel_def basic_rel_def tso_init_def quorum_for_def \n    dest: empty_not_quorum)\n  done\n\nsubsection \\<open>Invariants\\<close>\n(******************************************************************************)\n\ndefinition TSO_inv1 where\n  \"TSO_inv1 = {s. two_step (next_round s) = Suc 0 \\<longrightarrow>\n    (\\<exists>v. \\<forall>p w. r_votes s p = Some w \\<longrightarrow> w = v)}\"\n\nlemmas TSO_inv1I = TSO_inv1_def [THEN setc_def_to_intro, rule_format]\nlemmas TSO_inv1E [elim] = TSO_inv1_def [THEN setc_def_to_elim, rule_format]\nlemmas TSO_inv1D = TSO_inv1_def [THEN setc_def_to_dest, rule_format]\n\ndefinition TSO_inv2 where\n  \"TSO_inv2 = {s. two_step (next_round s) = Suc 0 \\<longrightarrow>\n    (\\<forall>p v. (r_votes s p = Some v \\<longrightarrow> (\\<exists>q. last_obs s q \\<in> {None, Some v})))}\"\n\nlemmas TSO_inv2I = TSO_inv2_def [THEN setc_def_to_intro, rule_format]\nlemmas TSO_inv2E [elim] = TSO_inv2_def [THEN setc_def_to_elim, rule_format]\nlemmas TSO_inv2D = TSO_inv2_def [THEN setc_def_to_dest, rule_format]\n\nsubsubsection \\<open>Proofs of invariants\\<close>\n(******************************************************************************)\n\nlemma TSO_inv1_inductive:\n  \"init tso_TS \\<subseteq> TSO_inv1\"\n  \"{TSO_inv1} TS.trans tso_TS {> TSO_inv1}\"\n  by(auto simp add: TSO_inv1_def tso_TS_defs PO_hoare_def \n    tso_round0_def tso_round1_def const_map_is_Some two_step_phase_Suc)\n  \nlemma TSO_inv1_invariant:\n  \"reach tso_TS \\<subseteq> TSO_inv1\"\n  by(intro inv_rule_basic TSO_inv1_inductive)\n\nlemma TSO_inv2_inductive:\n  \"init tso_TS \\<subseteq> TSO_inv2\"\n  \"{TSO_inv2} TS.trans tso_TS {> TSO_inv2}\"\n  by(auto simp add: TSO_inv2_def tso_TS_defs PO_hoare_def \n    opt_obs_safe_def tso_round0_def tso_round1_def const_map_is_Some two_step_phase_Suc)\n  \nlemma TSO_inv2_invariant:\n  \"reach tso_TS \\<subseteq> TSO_inv2\"\n  by(intro inv_rule_basic TSO_inv2_inductive)\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Consensus_Refined/Observing/Two_Step_Observing.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953651858117, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.2707244141192081}}
{"text": "theory DataRefinementMore\nimports AbstractSepreftime\nbegin\n\nsubsection \\<open>Data Refinement\\<close>\n\n\nlemma \"{(1,2),(2,4)}``{1,2}={2,4}\" by auto\n\n\ndefinition conc_fun (\"\\<Down>\") where\n  \"conc_fun R m \\<equiv> case m of FAILi \\<Rightarrow> FAILT | REST X \\<Rightarrow> REST (\\<lambda>c. Sup {X a| a. (c,a)\\<in>R})\"\n                                                                  (* ^- not so sure here *)\ndefinition abs_fun (\"\\<Up>\") where\n  \"abs_fun R m \\<equiv> case m of FAILi \\<Rightarrow> FAILT \n    | REST X \\<Rightarrow> if dom X\\<subseteq>Domain R then REST (\\<lambda>a. Sup {X c| c. (c,a)\\<in>R}) else FAILT\"\n                                                (* ^- not so sure here *)\nlemma \n  conc_fun_FAIL[simp]: \"\\<Down>R FAILT = FAILT\" and\n  conc_fun_RES: \"\\<Down>R (REST X) = REST (\\<lambda>c. Sup {X a| a. (c,a)\\<in>R})\"\n  unfolding conc_fun_def by (auto split: nrest.split)\n\n(* \nlemma conc_fun_RES_sv: \"single_valued R \\<Longrightarrow> \n  \\<Down>R (REST X) = REST (\\<lambda>c. if c\\<in>Dom R then Some (X Sup {X a| a. (c,a)\\<in>R})\"\n*)\n\nlemma nrest_Rel_mono:\n  fixes A :: \"('a,'b::complete_lattice) nrest\"\n  shows \"A \\<le> B \\<Longrightarrow> \\<Down> R A \\<le> \\<Down> R B\"\n  unfolding conc_fun_def\n  apply (auto split: nrest.split simp: le_fun_def)  \n  by (smt complete_lattice_class.Sup_mono mem_Collect_eq)   \n\n\n\nlemma datarefine_timerefine_commute1:\n  assumes \"wfR R'\"\n  shows \"\\<Down> R (timerefine R' m) \\<le> timerefine R' (\\<Down> R m)\"\n  unfolding conc_fun_def timerefine_def\n  apply(cases m) apply auto apply(rule le_funI)\n  apply(rule Sup_least)\n  apply (auto split: option.splits)\n  subgoal \n    by (metis (mono_tags, lifting) Sup_upper less_eq_option_Some_None mem_Collect_eq)\n  apply(rule le_funI)\n  apply(rule Sum_any_mono)\n  apply(rule mult_right_mono)\n  subgoal  \n    by (metis (mono_tags, lifting) Sup_upper le_funE less_eq_option_Some mem_Collect_eq)  \n   apply simp\n  apply(rule wfR_finite_mult_left )\n  using assms by simp\n\n\n\nlemma datarefine_timerefine_commute2: \n  assumes \"wfR R'\" and sv: \"single_valued R\"\n  shows \"\\<Down> R (timerefine R' m) \\<ge> timerefine R' (\\<Down> R m)\"\n    unfolding conc_fun_def timerefine_def\n    apply(cases m) apply auto  apply(rule le_funI)\n    subgoal for x2 x\n    proof (cases \"\\<exists>a. (x, a) \\<in> R\")\n      case True\n      from sv have k: \"\\<And>a. (x, a) \\<in> R \\<longleftrightarrow> (a = (THE a. (x,a)\\<in>R))\"\n        unfolding single_valued_def apply auto \n        subgoal           by (simp add: the_equality)   \n        subgoal apply(rule theI') using True by auto \n        done      \n      show ?thesis apply(subst k) apply simp\n        apply(subst (2) k) by simp\n    next\n      case False\n      then show ?thesis by (auto split: option.splits simp: bot_option_def)  \n    qed \n    done \n\nexperiment\nbegin\n\ndefinition \"m = REST [0\\<mapsto>(\\<lambda>_.0)(1:=1), 1\\<mapsto>(\\<lambda>_.0)(0:=1)]\"\n\ndefinition \"R = {(0::nat,1::nat),(1,1),(1,0),(1,0)}\"\n\nterm \"(\\<lambda>_.0)(x:=y)\"\n\ndefinition \"R' = (\\<lambda>_.0)(0::nat:=(\\<lambda>_.0)(0:=1),1:=(\\<lambda>_.0)(0:=1::enat))\"\n\nlemma *: \"Sum_any (\\<lambda>ac. (if ac = Suc 0 then 1 else 0) * R' ac cc)\n      = R' 1 cc\" sorry \nlemma **: \"Sum_any (\\<lambda>ac. (if ac = 0 then 1 else 0) * R' ac cc)\n      = R' 0 cc\" sorry \n\nlemma \"\\<Down> R (timerefine R' m) = SPECT G\"\n  unfolding conc_fun_def timerefine_def m_def R_def apply auto\n  apply(rule ext) unfolding ** * apply auto\n  unfolding R'_def  apply auto sorry\n    \n\nlemma \" (timerefine R' (\\<Down> R m)) = SPECT G2\"\n  unfolding conc_fun_def timerefine_def m_def R_def apply auto\n  apply(rule ext) unfolding ** * \n  unfolding R'_def    oops\n\nend\n\n           \nlemma datarefine_timerefine_commute: \n  assumes \"wfR R'\" and sv: \"single_valued R\"\n  shows \"\\<Down> R (timerefine R' m) = timerefine R' (\\<Down> R m)\"\n  apply(rule antisym)\n  subgoal using assms datarefine_timerefine_commute1 by metis\n  subgoal using assms datarefine_timerefine_commute2  by metis\n  done\n\n\nlemma pw_conc_nofail[refine_pw_simps]: \n  \"nofailT (\\<Down>R S) = nofailT S\"\n  by (cases S) (auto simp: conc_fun_RES)\n\nlemma \"single_valued A \\<Longrightarrow> single_valued B \\<Longrightarrow> single_valued (A O B)\"\n  by (simp add: single_valued_relcomp)\n\nlemma Sup_enatoption_less2: \" Sup X = Some \\<infinity> \\<Longrightarrow> (\\<exists>x. Some x \\<in> X \\<and> enat t < x)\"\n  using Sup_enat_less2\n  by (metis Sup_option_def in_these_eq option.distinct(1) option.sel)\n\nlemma pw_conc_inres[refine_pw_simps]:\n  \"inresT (\\<Down>R S') s t = (nofailT S' \n  \\<longrightarrow> ((\\<exists>s'. (s,s')\\<in>R \\<and> inresT S' s' t) \\<comment> \\<open> \\<and> (\\<forall>s' t'. (s,s')\\<in>R \\<longrightarrow> inresT S' s' t' \\<longrightarrow> t' \\<le> t )\\<close> ))\"\n  apply (cases S')\n  subgoal by simp\n  subgoal  for m'\n    apply rule\n    subgoal \n      apply (auto simp: conc_fun_RES  )\n      subgoal for t' \n        apply(cases t')\n         apply auto\n        subgoal for n apply(auto dest!: Sup_finite_enat) \n          subgoal for a apply(rule exI[where x=a]) apply auto\n            apply(rule exI[where x=\"enat n\"]) by auto  \n          done\n        subgoal apply(drule Sup_enatoption_less2[where t=t])\n          apply auto subgoal for x a apply(rule exI[where x=a]) apply auto\n            apply(rule exI[where x=x]) by auto \n          done\n        done\n      done\n    subgoal \n      apply (auto simp: conc_fun_RES)\n      by (smt Sup_upper dual_order.trans le_some_optE mem_Collect_eq)\n    done\n  done \n\nlemma bindT_refine':\n  fixes R' :: \"('a\\<times>'b) set\" and R::\"('c\\<times>'d) set\"\n  assumes R1: \"M \\<le> \\<Down> R' M'\"\n  assumes R2: \"\\<And>x x' t . \\<lbrakk> (x,x')\\<in>R'; inresT M x t; inresT M' x' t;\n    nofailT M; nofailT M'\n  \\<rbrakk> \\<Longrightarrow> f x \\<le> \\<Down> R (f' x')\"\n  shows \"bindT M (\\<lambda>x. f x) \\<le> \\<Down> R (bindT M' (\\<lambda>x'. f' x'))\"\n  using assms\n  apply (simp add: pw_le_iff refine_pw_simps)\n  by blast \n\nexperiment\nbegin\n\n\n\n\nlemma bindT_refine'':\n  fixes R' :: \"('a\\<times>'b) set\" and R::\"('c\\<times>'d) set\"\n  assumes R1: \"M \\<le> \\<Down> R' M'\"\n  assumes R2: \"\\<And>x x' t . \\<lbrakk> (x,x')\\<in>R'    \n  \\<rbrakk> \\<Longrightarrow> f x \\<le> \\<Down> R (f' x')\"\n  shows \"bindT M (\\<lambda>x. f x) \\<le> \\<Down> R (bindT M' (\\<lambda>x'. f' x'))\" \n  sorry\n\n\nthm bindT_refine'' bindT_mono_under_timerefine\n\nlemma \n  assumes \"wfR tR\" and sv: \"single_valued R\" and sv: \"single_valued R'\"\n  assumes R1: \"M \\<le> (timerefine tR (\\<Down> R'  M'))\"\n  assumes R2: \"\\<And>x x' t . \\<lbrakk> (x,x')\\<in>R' \\<rbrakk> \\<Longrightarrow> f x \\<le> (timerefine tR ( \\<Down> R  (f' x')))\"\n  shows \"bindT M (\\<lambda>x. f x) \\<le> (timerefine tR (\\<Down> R  (bindT M' (\\<lambda>x'. f' x'))))\"\n  apply(subst datarefine_timerefine_commute[symmetric, OF assms(1,2)])\n\n  apply(rule order.trans)\n   defer apply(rule nrest_Rel_mono) apply(subst timerefine_bindT_ge[OF assms(1)]) apply simp\n  apply(rule bindT_refine''[where R'=R'])\n  apply(rule order.trans[OF R1])\n   apply(subst datarefine_timerefine_commute[  OF assms(1,3)]) apply simp\n  apply(rule order.trans[OF R2]) apply simp\n  apply(subst datarefine_timerefine_commute[  OF assms(1,2)]) apply simp\n  done\n\n\nlemma \n  assumes \"wfR tR\" \n  assumes R1: \"M \\<le> (\\<Down> R'(timerefine tR   M'))\"\n  assumes R2: \"\\<And>x x' t . \\<lbrakk> (x,x')\\<in>R' \\<rbrakk> \\<Longrightarrow> f x \\<le> ( \\<Down> R (timerefine tR  (f' x')))\"\n  shows \"bindT M (\\<lambda>x. f x) \\<le> (\\<Down> R (timerefine tR   (bindT M' (\\<lambda>x'. f' x'))))\" \n  apply(rule order.trans)\n   defer apply(rule nrest_Rel_mono) apply(subst timerefine_bindT_ge[OF assms(1)]) apply simp\n  apply(rule bindT_refine''[where R'=R'])\n  apply(rule R1) \n  apply(rule R2) by simp \n\n\n\n    \n  \n\n                     \n\n\nend\n\n\n\n\n\nsubsubsection \\<open>Examples\\<close>\n\ndefinition Rset where \"Rset = { (c,a)| c a. set c = a}\"\n                                     \nlemma \"RETURNT [1,2,3] \\<le> \\<Down>Rset (RETURNT {1,2,3})\"\n  unfolding conc_fun_def RETURNT_def Rset_def\n  apply simp unfolding le_fun_def by auto\n\nlemma \"RETURNT [1,2,3] \\<le> \\<Down>Rset (RETURNT {1,2,3})\"\n  unfolding conc_fun_def RETURNT_def Rset_def\n  apply simp unfolding le_fun_def by auto\n\n\ndefinition Reven where \"Reven = { (c,a)| c a. even c = a}\"\n\nlemma \"RETURNT 3 \\<le> \\<Down>Reven (RETURNT False)\"\n  unfolding conc_fun_def RETURNT_def Reven_def\n  apply simp unfolding le_fun_def by auto\n\nlemma \"m \\<le> \\<Down>Id m\"\n  unfolding conc_fun_def RETURNT_def \n  apply (cases m) by auto\n\n\nlemma \"m \\<le> \\<Down>{} m \\<longleftrightarrow> (m=FAILT \\<or> m = SPECT bot)\"\n  unfolding conc_fun_def RETURNT_def \n  apply (cases m) apply auto by (metis bot.extremum dual_order.antisym le_funI)\n\n\nlemma abs_fun_simps[simp]: \n  \"\\<Up>R FAILT = FAILT\"\n  \"dom X\\<subseteq>Domain R \\<Longrightarrow> \\<Up>R (REST X) = REST (\\<lambda>a. Sup {X c| c. (c,a)\\<in>R})\"\n  \"\\<not>(dom X\\<subseteq>Domain R) \\<Longrightarrow> \\<Up>R (REST X) = FAILT\"\n  unfolding abs_fun_def by (auto  split: nrest.split)\n\nterm single_valued\n \ncontext fixes R assumes SV: \"single_valued R\" begin\n\n\nlemma \n  fixes m :: \"'b \\<Rightarrow> enat option\"\n  shows\n  Sup_sv: \"(c, a') \\<in> R \\<Longrightarrow>  Sup {m a| a. (c,a) \\<in> R} = m a'\"\nproof -\n  assume \"(c,a') \\<in> R\"\n  with SV have singleton: \"{m a| a. (c,a) \\<in> R} = {m a'}\" by(auto dest: single_valuedD) \n  show ?thesis unfolding singleton by simp\nqed \n\nlemma indomD: \" M c = Some y \\<Longrightarrow> dom M \\<subseteq> Domain R \\<Longrightarrow> (\\<exists>a. (c,a)\\<in>R)\"\n  by auto\n\nlemma conc_abs_swap: \"m' \\<le> \\<Down>R m \\<longleftrightarrow> \\<Up>R m' \\<le> m\"\n  apply rule\n  subgoal (* <-- *)\n  unfolding conc_fun_def abs_fun_def using SV\n  apply (auto split: nrest.splits) \n  subgoal for M M'\n    apply (auto simp add: le_fun_def)  \n    sorry (* by (smt Sup_least antisym le_cases mem_Collect_eq single_valuedD)  *)\n  subgoal \n    by (smt Collect_cong Domain.DomainI domI domIff empty_Sup empty_def le_map_dom_mono set_rev_mp)    \n  done\n\n  subgoal (* \\<longrightarrow> *)\n    unfolding conc_fun_def abs_fun_def using SV\n    apply(auto split: nrest.splits if_splits)\n    apply (auto simp add: le_fun_def)\n    subgoal for M M' c\n      apply(cases \"M c = None\")\n       apply auto apply(frule indomD) apply simp\n      apply(auto) sorry(*\n      apply(simp only: Sup_sv)\n       \n      by (me tis (mono_tags, lifting) Sup_le_iff mem_Collect_eq) *)\n    done\n  done\n\nlemma \n  fixes m :: \"'b \\<Rightarrow> enat option\"\n  shows\n  Inf_sv: \"(c, a') \\<in> R \\<Longrightarrow>  Inf {m a| a. (c,a) \\<in> R} = m a'\"\nproof -\n  assume \"(c,a') \\<in> R\"\n  with SV have singleton: \"{m a| a. (c,a) \\<in> R} = {m a'}\" by(auto dest: single_valuedD) \n  show ?thesis unfolding singleton by simp\nqed \n\nlemma ac_galois: \"galois_connection (\\<Up>R) (\\<Down>R)\"\n  apply (unfold_locales)\n  by (rule conc_abs_swap)\n\n\nlemma \n  fixes m :: \"'b \\<Rightarrow> enat option\"\n  shows \n  Sup_some_svD: \"Sup {m a |a. (c, a) \\<in> R} = Some t' \\<Longrightarrow> (\\<exists>a. (c,a)\\<in>R \\<and> m a = Some t')\"\n  using SV by (smt Sup_le_iff dual_order.antisym less_eq_option_Some_None mem_Collect_eq order_refl single_valued_def)\n \n\nend \n\n\nlemma pw_abs_nofail[refine_pw_simps]: \n  \"nofailT (\\<Up>R M) \\<longleftrightarrow> (nofailT M \\<and> (\\<forall>x. (\\<exists>t. inresT M x t) \\<longrightarrow> x\\<in>Domain R))\"\n  apply (cases M)\n  apply simp\n  apply (auto simp: abs_fun_simps abs_fun_def)\n  by (metis zero_enat_def zero_le)\n\n(*\nlemma pw_abs_inres[refine_pw_simps]: \n  \"(\\<exists>t. inresT (\\<Up>R M) a t) \\<longleftrightarrow> (nofailT (\\<Up>R M) \\<longrightarrow> (\\<exists>c. (\\<exists>t. inresT M c t) \\<and> (c,a)\\<in>R))\"\n  apply (cases M)\n   apply simp\n  apply rule\n  subgoal for m\n    apply (auto simp: abs_fun_def) (*    *)\n    sorry\n  subgoal for m\n    sorry\n  done\n*)\n\nlemma pw_conc_nofail[refine_pw_simps]: \n  \"nofailT (\\<Down>R S) = nofailT S\"\n  by (cases S) (auto simp: conc_fun_RES)\n\nlemma \"single_valued A \\<Longrightarrow> single_valued B \\<Longrightarrow> single_valued (A O B)\"\n  by (simp add: single_valued_relcomp)\n\nlemma Sup_enatoption_less2: \" Sup X = Some \\<infinity> \\<Longrightarrow> (\\<exists>x. Some x \\<in> X \\<and> enat t < x)\"\n  using Sup_enat_less2\n  by (metis Sup_option_def in_these_eq option.distinct(1) option.sel)\n\nlemma pw_conc_inres[refine_pw_simps]:\n  \"inresT (\\<Down>R S') s t = (nofailT S' \n  \\<longrightarrow> ((\\<exists>s'. (s,s')\\<in>R \\<and> inresT S' s' t) \\<comment> \\<open> \\<and> (\\<forall>s' t'. (s,s')\\<in>R \\<longrightarrow> inresT S' s' t' \\<longrightarrow> t' \\<le> t ) \\<close> ))\"\n  apply (cases S')\n  subgoal by simp\n  subgoal  for m'\n    apply rule\n    subgoal \n      apply (auto simp: conc_fun_RES  )\n      subgoal for t' \n        apply(cases t')\n         apply auto\n        subgoal for n apply(auto dest!: Sup_finite_enat) \n          subgoal for a apply(rule exI[where x=a]) apply auto\n            apply(rule exI[where x=\"enat n\"]) by auto  \n          done\n        subgoal apply(drule Sup_enatoption_less2[where t=t])\n          apply auto subgoal for x a apply(rule exI[where x=a]) apply auto\n            apply(rule exI[where x=x]) by auto \n          done\n        done\n      done\n    subgoal \n      apply (auto simp: conc_fun_RES)\n      by (smt Sup_upper dual_order.trans le_some_optE mem_Collect_eq)\n    done\n  done \n(*\nlemma pw_conc_inres_sv:\n  \"single_valued R \\<Longrightarrow> inresT (\\<Down>R S') s t = (nofailT S' \n  \\<longrightarrow> (\\<exists>s'. (s,s')\\<in>R \\<and> inresT S' s' t))\"\n  apply (cases S')\n  subgoal by simp\n  subgoal  for m'\n    apply rule\n    subgoal \n      by (auto simp: conc_fun_RES dest!: Sup_some_svD)        \n    subgoal \n      by (auto simp: conc_fun_RES Sup_sv )  \n    done\n  done *)\n\nlemma \n  fixes m :: \"'a \\<Rightarrow> enat option\"\n  shows\n  \"single_valued R \\<Longrightarrow> Sup {m a| a. (c,a) \\<in> R} = None \\<longleftrightarrow> c \\<notin> Domain R\"\n  apply rule\n  subgoal oops\n\n(*\nlemma pw_abs_inre: \n  \"inresT (\\<Up>R M) a t \\<longleftrightarrow> (nofailT (\\<Up>R M) \\<longrightarrow> (\\<exists>c. inresT M c t \\<and> (c,a)\\<in>R))\"\n  apply (cases M)\n  apply simp\n  apply (auto simp: abs_fun_def)\n  done*)\n\n(*\nlemma pw_conc_inres:\n  \"inresT (\\<Down>R S') s t = (nofailT S' \n  \\<longrightarrow> (\\<exists>s'. (s,s')\\<in>R \\<and> inresT S' s' t))\"\n  apply (cases S')\n  subgoal by simp\n  subgoal  for m'\n    apply rule\n    subgoal \n      apply (auto simp: conc_fun_RES) sorry\n    subgoal \n      apply (auto simp: conc_fun_RES) sorry\n    done\n  oops *)\n\nlemma sv_the: \"single_valued R \\<Longrightarrow> (c,a) \\<in> R \\<Longrightarrow> (THE a. (c, a) \\<in> R) = a\"\n  by (simp add: single_valued_def the_equality)\n\nlemma\n  conc_fun_RES_sv:\n  assumes SV: \"single_valued R\"\n  shows \"\\<Down>R (REST X) = REST (\\<lambda>c. if c\\<in>Domain R then X (THE a. (c,a)\\<in>R) else None )\"\n  unfolding conc_fun_def\n  apply(auto split: nrest.split)\n  apply(rule ext)\n  apply auto\n  subgoal using  SV  by (auto simp: Sup_sv sv_the)\n  subgoal by (smt Collect_cong Domain.DomainI empty_Sup empty_def)\n  done\n\n\nlemma conc_fun_mono[simp, intro!]: \n  shows \"mono (\\<Down>R)\"\n  apply rule \n  apply (simp add: pw_le_iff)\n  by (auto simp: refine_pw_simps) \n\n\nlemma conc_fun_R_mono:\n  assumes \"R \\<subseteq> R'\" \n  shows \"\\<Down>R M \\<le> \\<Down>R' M\"\n  using assms\n  by (auto simp: pw_le_iff refine_pw_simps)\n\n\n\nlemma SupSup_2: \"Sup {m a |a. (c, a) \\<in> R O S} =  Sup {m a |a b. (b,a)\\<in>S \\<and> (c,b)\\<in>R }\"\nproof -\n  have i: \"\\<And>a. (c,a) \\<in> R O S \\<longleftrightarrow> (\\<exists>b. (b,a)\\<in>S \\<and> (c,b)\\<in>R)\" by auto\n  have \"Sup {m a |a. (c, a) \\<in> R O S} = Sup {m a |a. (\\<exists>b. (b,a)\\<in>S \\<and> (c,b)\\<in>R)}\" \n      unfolding i by auto\n    also have \"...  = Sup {m a |a b. (b,a)\\<in>S \\<and> (c,b)\\<in>R}\" by auto\n    finally show ?thesis .\n  qed\n\nlemma \n  fixes m :: \"'a \\<Rightarrow> enat option\"\n  shows SupSup: \"Sup {Sup {m aa |aa. P a aa c} |a. Q a c} = Sup {m aa |a aa. P a aa c \\<and> Q a c}\"\n  apply(rule antisym)\n   subgoal apply(rule Sup_least)\n     by (auto intro: Sup_subset_mono)\n   subgoal \n     unfolding Sup_le_iff apply auto\n     by (smt Sup_upper Sup_upper2 mem_Collect_eq)\n   done \n\nlemma \n  fixes m :: \"'a \\<Rightarrow> enat option\"\n  shows \n    SupSup_1: \"Sup {Sup {m aa |aa. (a, aa) \\<in> S} |a. (c, a) \\<in> R} = Sup {m aa |a aa. (a,aa)\\<in>S \\<and> (c,a)\\<in>R}\"\n  by(rule SupSup)\n\n\nlemma conc_fun_chain:\n  shows \"\\<Down>R (\\<Down>S M) = \\<Down>(R O S) M\"\n  apply(cases M)\n  subgoal by simp\n  apply simp\n  apply(simp only: conc_fun_RES)\n  apply auto apply (rule ext)  unfolding SupSup_1 SupSup_2 by meson \n\nlemma conc_fun_chain_sv:\n  assumes SVR: \"single_valued R\" and SVS: \"single_valued S\"\n  shows \"\\<Down>R (\\<Down>S M) = \\<Down>(R O S) M\"\n  apply(cases M)\n  subgoal by simp\n  apply simp\n  using SVS apply(simp only: conc_fun_RES_sv)\n  using SVR apply(simp only: conc_fun_RES_sv)\n  using single_valued_relcomp[OF SVR SVS] apply(simp only: conc_fun_RES_sv)\n  apply (auto split: nrest.split)\n  apply (rule ext) apply auto\n    apply(auto simp add: sv_the)  \n  apply(subst sv_the) by auto\n\n\nlemma conc_Id[simp]: \"\\<Down>Id = id\"\n  unfolding conc_fun_def [abs_def] by (auto split: nrest.split)\n\n                                 \nlemma conc_fun_fail_iff[simp]: \n  \"\\<Down>R S = FAILT \\<longleftrightarrow> S=FAILT\"\n  \"FAILT = \\<Down>R S \\<longleftrightarrow> S=FAILT\"\n  by (auto simp add: pw_eq_iff refine_pw_simps)\n\nlemma conc_trans[trans]:\n  assumes A: \"C \\<le> \\<Down>R B\" and B: \"B \\<le> \\<Down>R' A\" \n  shows \"C \\<le> \\<Down>R (\\<Down>R' A)\"\n  using assms by (fastforce simp: pw_le_iff refine_pw_simps)\n\nlemma conc_trans_sv:\n  assumes SV: \"single_valued R\" \"single_valued R'\"\n    and A: \"C \\<le> \\<Down>R B\" and B: \"B \\<le> \\<Down>R' A\" \n  shows \"C \\<le> \\<Down>R (\\<Down>R' A)\"\n  using assms by (fastforce simp: pw_le_iff refine_pw_simps)\n\ntext \\<open>WARNING: The order of the single statements is important here!\\<close>\nlemma conc_trans_additional[trans]:\n  assumes \"single_valued R\"\n  shows\n  \"\\<And>A B C. A\\<le>\\<Down>R  B \\<Longrightarrow> B\\<le>    C \\<Longrightarrow> A\\<le>\\<Down>R  C\"\n  \"\\<And>A B C. A\\<le>\\<Down>Id B \\<Longrightarrow> B\\<le>\\<Down>R  C \\<Longrightarrow> A\\<le>\\<Down>R  C\"\n  \"\\<And>A B C. A\\<le>\\<Down>R  B \\<Longrightarrow> B\\<le>\\<Down>Id C \\<Longrightarrow> A\\<le>\\<Down>R  C\"\n\n  \"\\<And>A B C. A\\<le>\\<Down>Id B \\<Longrightarrow> B\\<le>\\<Down>Id C \\<Longrightarrow> A\\<le>    C\"\n  \"\\<And>A B C. A\\<le>\\<Down>Id B \\<Longrightarrow> B\\<le>    C \\<Longrightarrow> A\\<le>    C\"\n  \"\\<And>A B C. A\\<le>    B \\<Longrightarrow> B\\<le>\\<Down>Id C \\<Longrightarrow> A\\<le>    C\"\n  using assms conc_trans[where R=R and R'=Id]\n  by (auto intro: order_trans)\n\n\n\nlemma RETURNT_refine:\n  assumes \"(x,x')\\<in>R\"\n  shows \"RETURNT x \\<le> \\<Down>R (RETURNT x')\"\n  using assms\n  by (auto simp: RETURNT_def conc_fun_RES le_fun_def Sup_upper)  \n\n(*\nthm bindT_refine'\nlemma bindT_refine'2:\n  fixes R' :: \"('a\\<times>'b) set\" and R::\"('c\\<times>'d) set\"\n  assumes R1: \"M \\<le> \\<Down> R' M'\"\n  assumes R2: \"\\<And>x x' t . \\<lbrakk> (x,x')\\<in>R'; inresT M x t; inresT M' x' t;\n    nofailT M; nofailT M'\n  \\<rbrakk> \\<Longrightarrow> f x \\<le> \\<Down> R (f' x')\"\n  shows \"bindT M (\\<lambda>x. f x) \\<le> \\<Down> R (bindT M' (\\<lambda>x'. f' x'))\"\n  using assms\n  apply (simp add: pw_le_iff refine_pw_simps)  \n  by blast*)\n\nlemma bindT_refine:\n  fixes R' :: \"('a\\<times>'b) set\" and R::\"('c\\<times>'d) set\"\n  assumes R1: \"M \\<le> \\<Down> R' M'\"\n  assumes R2: \"\\<And>x x'. \\<lbrakk> (x,x')\\<in>R' \\<rbrakk> \n    \\<Longrightarrow> f x \\<le> \\<Down> R (f' x')\"\n  shows \"bindT M (\\<lambda>x. f x) \\<le> \\<Down> R (bind M' (\\<lambda>x'. f' x'))\"\n  apply (rule bindT_refine') using assms by auto\n\nsubsection \\<open>WHILET refine\\<close>\n\nlemma RECT_refine:\n  assumes M: \"mono2 body\"\n  assumes R0: \"(x,x')\\<in>R\"\n  assumes RS: \"\\<And>f f' x x'. \\<lbrakk> \\<And>x x'. (x,x')\\<in>R \\<Longrightarrow> f x \\<le>\\<Down>S (f' x'); (x,x')\\<in>R \\<rbrakk> \n    \\<Longrightarrow> body f x \\<le>\\<Down>S (body' f' x')\"\n  shows \"RECT (\\<lambda>f x. body f x) x \\<le>\\<Down>S (RECT (\\<lambda>f' x'. body' f' x') x')\"\n  unfolding RECT_flat_gfp_def\n  apply (clarsimp simp add: M) \n  apply (rule flatf_fixp_transfer[where \n        fp'=\"flatf_gfp body\" \n    and B'=body \n    and P=\"\\<lambda>x x'. (x',x)\\<in>R\", \n    OF _ _ flatf_ord.fixp_unfold[OF M[THEN trimonoD_flatf_ge]] R0])\n  apply simp\n  apply (simp add: trimonoD_flatf_ge)\n  by (rule RS)\n\n                                         \nlemma WHILET_refine:\n  assumes R0: \"(x,x')\\<in>R\"\n  assumes COND_REF: \"\\<And>x x'. \\<lbrakk> (x,x')\\<in>R \\<rbrakk> \\<Longrightarrow> b x = b' x'\"\n  assumes STEP_REF: \n    \"\\<And>x x'. \\<lbrakk> (x,x')\\<in>R; b x; b' x' \\<rbrakk> \\<Longrightarrow> f x \\<le> \\<Down>R (f' x')\"\n  shows \"whileT b f x \\<le> \\<Down>R (whileT b' f' x')\"\n  unfolding whileT_def apply(rule RECT_refine)\n    subgoal by(refine_mono)  \n     apply (fact R0)\n    by(auto simp: COND_REF STEP_REF RETURNT_refine intro: bindT_refine[where R'=R])  \n\nlemma \n  assumes a: \"\\<And>m n c a. c\\<in>Domain R \\<Longrightarrow> \\<exists>a. SPECT (n c) \\<le>  SPECT (m a)\"\n  shows \"(SPECT n) \\<le> \\<Down> R (SPECT m)\"\n  using a  apply auto  \n    unfolding conc_fun_def apply (auto split: nrest.split) \n      unfolding le_fun_def apply auto\n    proof -\n      fix c \n      assume \"(\\<And>c n m. c \\<in> Domain R \\<Longrightarrow> \\<exists>a. \\<forall>x. n c x \\<le> m a x)\"\n      oops\n\nlemma SPECT_refines_conc_fun':\n  assumes a: \"\\<And>m c.  M = SPECT m\n          \\<Longrightarrow> c \\<in> dom n \\<Longrightarrow> (\\<exists>a. (c,a)\\<in>R \\<and> n c \\<le> m a)\"\n  shows \"SPECT n \\<le> \\<Down> R M\"\nproof - \n  show ?thesis\n    unfolding conc_fun_def apply (auto split: nrest.split) \n    subgoal for m unfolding le_fun_def apply auto\n    proof -\n      fix c\n      assume m: \"M = SPECT m\"\n      show \"n c \\<le> Sup {m a |a. (c, a) \\<in> R} \"\n      proof (cases \"c \\<in> dom n\")\n        case True\n        with m a obtain a where k: \"(c,a)\\<in>R\" \"n c \\<le> m a\" by blast \n        show ?thesis apply(rule  Sup_upper2) using k by auto\n      next\n        case False\n        then show ?thesis \n          by (simp add: domIff)\n      qed \n    qed\n    done\nqed\n\nlemma SPECT_refines_conc_fun:\n  assumes a: \"\\<And>m c. (\\<exists>a. (c,a)\\<in>R \\<and> n c \\<le> m a)\"\n  shows \"SPECT n \\<le> \\<Down> R (SPECT m)\"\n  apply(rule SPECT_refines_conc_fun') using a by auto\n\n\nlemma SPECT_refines_conc_fun_sv:\n  assumes \"single_valued R\" \n    and a: \"dom n \\<subseteq> Domain R\"\n    and \"\\<And>c. c \\<in> dom n \\<Longrightarrow> n c \\<le> (THE a. (c,a)\\<in>R)\"\n  shows \"SPECT n \\<le> \\<Down> R (SPECT m)\"\n  apply(rule SPECT_refines_conc_fun') using a\n  using indomD[OF assms(1) _ a] domIff\n  oops\n\n\n\n\nlemma conc_fun_br: \"\\<Down> (br \\<alpha> I1) (SPECT (emb I2 t))\n        = (SPECT (emb (\\<lambda>x. I1 x \\<and> I2 (\\<alpha> x)) t))\"\n  unfolding conc_fun_RES  apply auto apply(rule ext)    \n    using Sup_Some by (auto simp: emb'_def br_def bot_option_def Sup_option_def) \n\nend", "meta": {"author": "maxhaslbeck", "repo": "Sepreftime", "sha": "c1c987b45ec886d289ba215768182ac87b82f20d", "save_path": "github-repos/isabelle/maxhaslbeck-Sepreftime", "path": "github-repos/isabelle/maxhaslbeck-Sepreftime/Sepreftime-c1c987b45ec886d289ba215768182ac87b82f20d/moreCurr/DataRefinementMore.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6406358411176238, "lm_q2_score": 0.42250463481418826, "lm_q1q2_score": 0.270671612100282}}
{"text": "(*  Title:      HOL/Auth/n_mutualEx_lemma_inv__5_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mutualEx Protocol Case Study*} \n\ntheory n_mutualEx_lemma_inv__5_on_rules imports n_mutualEx_lemma_on_inv__5\nbegin\nsection{*All lemmas on causal relation between inv__5*}\nlemma lemma_inv__5_on_rules:\n  assumes b1: \"r \\<in> rules N\" and b2: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__5  p__Inv3 p__Inv4)\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have c1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n  apply (cut_tac b1, auto) done\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_TryVsinv__5) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_CritVsinv__5) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_ExitVsinv__5) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_IdleVsinv__5) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "paraVerifier", "repo": "paraVerifier", "sha": "5de62b433a160bf8d714e0a5085a38b9dd8899f0", "save_path": "github-repos/isabelle/paraVerifier-paraVerifier", "path": "github-repos/isabelle/paraVerifier-paraVerifier/paraVerifier-5de62b433a160bf8d714e0a5085a38b9dd8899f0/proof_scripts/mutualEx/n_mutualEx_lemma_inv__5_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6959583124210896, "lm_q2_score": 0.3886180267058489, "lm_q1q2_score": 0.27046194604261653}}
{"text": "(*******************************************************************************\n \n  Project: IsaNet\n\n  Author:  Tobias Klenze, ETH Zurich <tobias.klenze@inf.ethz.ch>\n           Christoph Sprenger, ETH Zurich <sprenger@inf.ethz.ch>\n  Version: JCSPaper.1.0\n  Isabelle Version: Isabelle2021-1\n\n  Copyright (c) 2022 Tobias Klenze, Christoph Sprenger\n  Licence: Mozilla Public License 2.0 (MPL) / BSD-3-Clause (dual license)\n\n*******************************************************************************)\n\nchapter\\<open>Abstract, and Concrete Parametrized Models\\<close>\ntext\\<open>This is the core of our verification -- the abstract and parametrized models that cover a wide\nrange of protocols.\\<close>\nsection\\<open>Network model\\<close>\ntheory Network_Model\n  imports\n    \"infrastructure/Agents\"\n    \"infrastructure/Tools\"\n    \"infrastructure/Take_While\"\nbegin\n\ntext\\<open>@{term \"as\"} is already defined as a type synonym for nat.\\<close>\ntype_synonym ifs = nat\n\ntext\\<open>The authenticated hop information consists of the interface identifiers UpIF, DownIF and an\nidentifier of the AS to which the hop information belongs. Furthermore, this record is extensible \nand can include additional authenticated hop information (aahi).\\<close>\nrecord ahi = \n  UpIF :: \"ifs option\"\n  DownIF :: \"ifs option\"\n  ASID :: as\n\ntype_synonym 'aahi ahis = \"'aahi ahi_scheme\"\n\nlocale network_model = compromised + \n  fixes\n   auth_seg0 :: \"('ainfo \\<times> 'aahi ahi_scheme list) set\" \n   and tgtas :: \"as \\<Rightarrow> ifs \\<Rightarrow> as option\"\n   and tgtif :: \"as \\<Rightarrow> ifs \\<Rightarrow> ifs option\"\nbegin\n\nsubsection \\<open>Interface check\\<close>\n(******************************************************************************)\n\ntext \\<open>Check if the interfaces of two adjacent hop fields match. If both hops are compromised we also\ninterpret the link as valid.\\<close>\nfun if_valid :: \"'aahi ahis option \\<Rightarrow> 'aahi ahis => 'aahi ahis option \\<Rightarrow> bool\" where\n  \"if_valid None hf _ \\<comment> \\<open>this is the case for the leaf AS\\<close>\n    = True\"\n| \"if_valid (Some hf1) (hf2) _\n    = ((\\<exists>downif . DownIF hf2 = Some downif \\<and> \n        tgtas (ASID hf2) downif = Some (ASID hf1) \\<and>\n        tgtif (ASID hf2) downif = UpIF hf1)\n      \\<or> ASID hf1 \\<in> bad \\<and> ASID hf2 \\<in> bad)\"\n\ntext \\<open>makes sure that: the segment is terminated, i.e. the first AS's HF has Eo = None\\<close>\nfun terminated :: \"'aahi ahis list \\<Rightarrow> bool\" where\n  \"terminated (hf#xs) \\<longleftrightarrow> DownIF hf = None \\<or> ASID hf \\<in> bad\"\n| \"terminated [] = True\" (* we allow this as a special case*)\n\ntext \\<open>makes sure that: the segment is rooted, i.e. the last HF has UpIF = None\\<close>\nfun rooted :: \"'aahi ahis list \\<Rightarrow> bool\" where\n  \"rooted [hf] \\<longleftrightarrow> UpIF hf = None \\<or> ASID hf \\<in> bad\"\n| \"rooted (hf#xs) = rooted xs\"\n| \"rooted [] = True\" (* we allow this as a special case*)\n\nabbreviation ifs_valid where \n  \"ifs_valid pre l nxt \\<equiv> TW.holds if_valid pre l nxt\"\n\nabbreviation ifs_valid_prefix where \n  \"ifs_valid_prefix pre l nxt \\<equiv> TW.takeW if_valid pre l nxt\"\n\nabbreviation ifs_valid_None where \n  \"ifs_valid_None l \\<equiv> ifs_valid None l None\"\n\nabbreviation ifs_valid_None_prefix where \n  \"ifs_valid_None_prefix l \\<equiv> ifs_valid_prefix None l None\"\n\nlemma strip_ifs_valid_prefix:\n  \"pfragment ainfo l auth_seg0 \\<Longrightarrow> pfragment ainfo (ifs_valid_prefix pre l nxt) auth_seg0\"\n  by (auto elim: pfragment_prefix' intro: TW.takeW_prefix)\n\n\ntext\\<open>Given the AS and an interface identifier of a channel, obtain the AS and interface at the other\nend of the same channel.\\<close>\nabbreviation rev_link :: \"as \\<Rightarrow> ifs \\<Rightarrow> as option \\<times> ifs option\" where \n  \"rev_link a1 i1 \\<equiv> (tgtas a1 i1, tgtif a1 i1)\"\n\nend\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/IsaNet/Network_Model.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331462646254, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.2703403900935352}}
{"text": "(*  Author: Tobias Nipkow  *)\n\nsection \"Completeness of Archive Test\"\n\ntheory ArchCompProps\nimports TameEnumProps ArchCompAux\nbegin\nlemma mgp_pre_iso_test: \"minGraphProps g \\<Longrightarrow> pre_iso_test(fgraph g)\"\napply(simp add:pre_iso_test_def fgraph_def image_def)\napply(rule conjI) apply(blast dest: mgp_vertices_nonempty[symmetric])\napply(rule conjI) apply(blast intro:minGraphProps)\napply(drule minGraphProps11)\napply(simp add:normFaces_def normFace_def verticesFrom_def minVertex_def\n               rotate_min_def o_def)\ndone\n\ncorollary iso_test_correct:\n \"\\<lbrakk> pre_iso_test Fs\\<^sub>1; pre_iso_test Fs\\<^sub>2 \\<rbrakk> \\<Longrightarrow>\n  iso_test Fs\\<^sub>1 Fs\\<^sub>2 = (Fs\\<^sub>1 \\<simeq> Fs\\<^sub>2)\"\nby(simp add:pre_iso_test_def iso_correct inj_on_rotate_min_iff[symmetric]\n            distinct_map nof_vertices_def length_remdups_concat)\n\nlemma trie_all_eq_set_of_trie:\n  \"invar_trie t \\<Longrightarrow> all_trie (list_all P) t = (\\<forall>v \\<in> set_tries t. P v)\"\nby(simp add: all_trie_eq_ran set_tries_eq_ran)\n\nlemma samet_imp_iso_seteq:\nassumes pre1: \"\\<And>gs g. gsopt = Some gs \\<Longrightarrow> g \\<in> set_tries gs \\<Longrightarrow> pre_iso_test g\"\nand pre2: \"\\<And>g. g \\<in> set arch \\<Longrightarrow> pre_iso_test g\"\nand inv: \"\\<And>gs. gsopt = Some gs \\<Longrightarrow> invar_trie gs\"\nand same: \"samet gsopt arch\"\nshows \"\\<exists>gs. gsopt = Some gs \\<and> set_tries gs =\\<^sub>\\<simeq> set arch\"\nproof -\n  obtain gs where [simp]: \"gsopt = Some gs\" and test1: \"\\<And>g. g \\<in> set_tries gs \\<Longrightarrow>\n    \\<exists>h \\<in> set arch. iso_test g h\" and test2: \"\\<And>g. g \\<in> set arch \\<Longrightarrow>\n    \\<exists>h \\<in> set_tries gs. iso_test g h\"\n    using same inv\n    by(force simp: samet_def trie_all_eq_set_of_trie invar_of_list all_tries_def\n      split:option.splits\n      dest: in_set_lookup_of_listD in_set_lookup_set_triesD)\n  have \"set_tries gs \\<subseteq>\\<^sub>\\<simeq> set arch\"\n  proof (auto simp:qle_gr.defs)\n    fix g assume g: \"g \\<in> set_tries gs\"\n    obtain h where h: \"h \\<in> set arch\" and test: \"iso_test g h\"\n      using test1[OF g] by blast\n    thus \"\\<exists>h\\<in>set arch. g \\<simeq> h\"\n      using h pre1[OF _ g] pre2[OF h] by (auto simp:iso_test_correct)\n  qed\n  moreover\n  have \"set arch \\<subseteq>\\<^sub>\\<simeq> set_tries gs\"\n  proof (auto simp:qle_gr.defs)\n    fix g assume g: \"g \\<in> set arch\"\n    obtain h where h: \"h \\<in> set_tries gs\" and test: \"iso_test g h\"\n      using test2[OF g] by blast\n    thus \"\\<exists>h \\<in> set_tries gs. g \\<simeq> h\"\n      using h pre1[OF _ h] pre2[OF g] by (auto simp:iso_test_correct)\n  qed\n  ultimately show ?thesis by (auto simp: qle_gr.seteq_qle_def)\nqed\n\nlemma samet_imp_iso_subseteq:\nassumes pre1: \"\\<And>gs g. gsopt = Some gs \\<Longrightarrow> g \\<in> set_tries gs \\<Longrightarrow> pre_iso_test g\"\nand pre2: \"\\<And>g. g \\<in> set arch \\<Longrightarrow> pre_iso_test g\"\nand inv: \"\\<And>gs. gsopt = Some gs \\<Longrightarrow> invar_trie gs\"\nand same: \"samet gsopt arch\"\nshows \"\\<exists>gs. gsopt = Some gs \\<and> set_tries gs \\<subseteq>\\<^sub>\\<simeq> set arch\"\nusing qle_gr.seteq_qle_def assms samet_imp_iso_seteq by metis\n\nglobal_interpretation set_mod_trie:\n  set_mod_maps \"Trie None []\" update_trie lookup_tries invar_trie \"(\\<simeq>)\" iso_test pre_iso_test hash\n  defines insert_mod_trie = \"set_mod_maps.insert_mod update_trie lookup_tries iso_test hash\"\n  and worklist_tree_coll_trie = \"set_modulo.worklist_tree_coll (Trie None []) insert_mod_trie\"\n  and worklist_tree_coll_aux_trie = \"set_modulo.worklist_tree_coll_aux insert_mod_trie\"\n  and insert_mod2_trie = \"set_modulo.insert_mod2 insert_mod_trie\"\n  by standard (simp_all add: iso_test_correct)\n\ndefinition enum_filter_finals ::\n  \"(graph \\<Rightarrow> graph list) \\<Rightarrow> graph list\n   \\<Rightarrow> (nat,nat fgraph) tries option\" where\n\"enum_filter_finals succs = set_mod_trie.worklist_tree_coll succs final fgraph\"\n\ndefinition tameEnumFilter :: \"nat \\<Rightarrow> (nat,nat fgraph)tries option\" where\n\"tameEnumFilter p = enum_filter_finals (next_tame p) [Seed p]\"\n\nlemma TameEnum_tameEnumFilter:\n  \"tameEnumFilter p = Some t \\<Longrightarrow>  set_tries t  =\\<^sub>\\<simeq> fgraph ` TameEnum\\<^bsub>p\\<^esub>\"\napply(auto simp: tameEnumFilter_def TameEnumP_def enum_filter_finals_def)\napply(drule set_mod_trie.worklist_tree_coll_equiv[OF _ inv_inv_next_tame])\napply (auto simp: set_of_conv inv_Seed mgp_pre_iso_test RTranCl_conv)\ndone\n\nlemma tameEnumFilter_subseteq_TameEnum:\n  \"tameEnumFilter p = Some t \\<Longrightarrow> set_tries t \\<subseteq> fgraph ` TameEnum\\<^bsub>p\\<^esub>\"\nby(auto simp add:tameEnumFilter_def TameEnumP_def enum_filter_finals_def\n     set_of_conv inv_Seed mgp_pre_iso_test RTranCl_conv\n     dest!: set_mod_trie.worklist_tree_coll_subseteq[OF _ inv_inv_next_tame])\n\n\nlemma inv_tries_tameEnumFilter:\n  \"tameEnumFilter p = Some t \\<Longrightarrow> invar_trie t\"\nunfolding tameEnumFilter_def enum_filter_finals_def\nby(erule set_mod_trie.worklist_tree_coll_inv)\n\ntheorem combine_evals_filter:\n \"\\<forall>g \\<in> set arch. pre_iso_test g \\<Longrightarrow> samet (tameEnumFilter p) arch\n  \\<Longrightarrow> fgraph ` TameEnum\\<^bsub>p\\<^esub> \\<subseteq>\\<^sub>\\<simeq> set arch\"\napply(subgoal_tac \"\\<exists>t. tameEnumFilter p = Some t \\<and> set_tries t \\<subseteq>\\<^sub>\\<simeq> set arch\")\n apply(metis TameEnum_tameEnumFilter qle_gr.seteq_qle_def qle_gr.subseteq_qle_trans)\napply(fastforce intro!: samet_imp_iso_subseteq\n  dest: inv_tries_tameEnumFilter tameEnumFilter_subseteq_TameEnum mgp_TameEnum mgp_pre_iso_test)\ndone\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Flyspeck-Tame/ArchCompProps.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331462646254, "lm_q2_score": 0.4532618480153861, "lm_q1q2_score": 0.27034039009353517}}
{"text": "(*  Title:      JinjaThreads/Framework/FWLock.thy\n    Author:     Andreas Lochbihler\n*)\n\nheader {* \\isaheader{All about a managing a single lock} *}\n\ntheory FWLock\nimports\n  FWState\nbegin\n\nfun has_locks :: \"'t lock \\<Rightarrow> 't \\<Rightarrow> nat\" where\n  \"has_locks None t = 0\"\n| \"has_locks \\<lfloor>(t', n)\\<rfloor> t = (if t = t' then Suc n else 0)\"\n\nlemma has_locks_iff: \n  \"has_locks l t = n \\<longleftrightarrow>\n  (l = None \\<and> n = 0) \\<or> \n  (\\<exists>n'. l = \\<lfloor>(t, n')\\<rfloor> \\<and> Suc n' = n) \\<or> (\\<exists>t' n'. l = \\<lfloor>(t', n')\\<rfloor> \\<and> t' \\<noteq> t \\<and> n = 0)\"\nby(cases l, auto)\n\nlemma has_locksE:\n  \"\\<lbrakk> has_locks l t = n;\n     \\<lbrakk> l = None; n = 0 \\<rbrakk> \\<Longrightarrow> P;\n     \\<And>n'. \\<lbrakk> l = \\<lfloor>(t, n')\\<rfloor>; Suc n' = n \\<rbrakk> \\<Longrightarrow> P;\n     \\<And>t' n'. \\<lbrakk> l = \\<lfloor>(t', n')\\<rfloor>; t' \\<noteq> t; n = 0 \\<rbrakk> \\<Longrightarrow> P \\<rbrakk>\n  \\<Longrightarrow> P\"\nby(auto simp add: has_locks_iff split: split_if_asm prod.split_asm)\n\n\ninductive may_lock :: \"'t lock \\<Rightarrow> 't \\<Rightarrow> bool\" where\n  \"may_lock None t\"\n| \"may_lock \\<lfloor>(t, n)\\<rfloor> t\"\n\nlemma may_lock_iff [code]:\n  \"may_lock l t = (case l of None \\<Rightarrow> True | \\<lfloor>(t', n)\\<rfloor> \\<Rightarrow> t = t')\"\nby(auto intro: may_lock.intros elim: may_lock.cases)\n\nlemma may_lockI:\n  \"l = None \\<or> (\\<exists>n. l = \\<lfloor>(t, n)\\<rfloor>) \\<Longrightarrow> may_lock l t\"\nby(cases l, auto intro: may_lock.intros)\n\nlemma may_lockE [consumes 1, case_names None Locked]:\n  \"\\<lbrakk> may_lock l t; l = None \\<Longrightarrow> P; \\<And>n. l = \\<lfloor>(t, n)\\<rfloor>  \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P\"\nby(auto elim: may_lock.cases)\n\nlemma may_lock_may_lock_t_eq:\n  \"\\<lbrakk> may_lock l t; may_lock l t' \\<rbrakk> \\<Longrightarrow> (l = None) \\<or> (t = t')\"\nby(auto elim!: may_lockE)\n\nabbreviation has_lock :: \"'t lock \\<Rightarrow> 't \\<Rightarrow> bool\"\nwhere \"has_lock l t \\<equiv> 0 < has_locks l t\"\n\nlemma has_locks_Suc_has_lock:\n  \"has_locks l t = Suc n \\<Longrightarrow> has_lock l t\"\nby(auto)\n\nlemmas has_lock_has_locks_Suc = gr0_implies_Suc[where n = \"has_locks l t\"]\n\nlemma has_lock_has_locks_conv:\n  \"has_lock l t \\<longleftrightarrow> (\\<exists>n. has_locks l t = (Suc n))\"\nby(auto intro: has_locks_Suc_has_lock has_lock_has_locks_Suc)\n\n\n\nlemma has_lock_may_lock_t_eq:\n  \"\\<lbrakk> has_lock l t; may_lock l t' \\<rbrakk> \\<Longrightarrow> t = t'\"\nby(auto elim!: may_lockE split: split_if_asm)\n\nlemma has_locks_has_locks_t_eq: \n  \"\\<lbrakk>has_locks l t = Suc n; has_locks l t' = Suc n'\\<rbrakk> \\<Longrightarrow> t = t'\"\nby(auto elim: has_locksE)\n\nlemma has_lock_has_lock_t_eq:\n  \"\\<lbrakk> has_lock l t; has_lock l t' \\<rbrakk> \\<Longrightarrow> t = t'\"\nunfolding has_lock_has_locks_conv\nby(auto intro: has_locks_has_locks_t_eq)\n\nlemma not_may_lock_conv:\n  \"\\<not> may_lock l t \\<longleftrightarrow> (\\<exists>t'. t' \\<noteq> t \\<and> has_lock l t')\"\nby(cases l, auto intro: may_lock.intros elim: may_lockE)\n\n\n\n(* State update functions for locking *)\n\nfun lock_lock :: \"'t lock \\<Rightarrow> 't \\<Rightarrow> 't lock\" where\n  \"lock_lock None t = \\<lfloor>(t, 0)\\<rfloor>\"\n| \"lock_lock \\<lfloor>(t', n)\\<rfloor> t = \\<lfloor>(t', Suc n)\\<rfloor>\"\n\nfun unlock_lock :: \"'t lock \\<Rightarrow> 't lock\" where\n  \"unlock_lock None = None\"\n| \"unlock_lock \\<lfloor>(t, n)\\<rfloor> = (case n of 0 \\<Rightarrow> None | Suc n' \\<Rightarrow> \\<lfloor>(t, n')\\<rfloor>)\"\n\nfun release_all :: \"'t lock \\<Rightarrow> 't \\<Rightarrow> 't lock\" where\n  \"release_all None t = None\"\n| \"release_all \\<lfloor>(t', n)\\<rfloor> t = (if t = t' then None else \\<lfloor>(t', n)\\<rfloor>)\"\n\nfun acquire_locks :: \"'t lock \\<Rightarrow> 't \\<Rightarrow> nat \\<Rightarrow> 't lock\" where\n  \"acquire_locks L t 0 = L\"\n| \"acquire_locks L t (Suc m) = acquire_locks (lock_lock L t) t m\"\n\nlemma acquire_locks_conv:\n  \"acquire_locks L t n = (case L of None \\<Rightarrow> (case n of 0 \\<Rightarrow> None | Suc m \\<Rightarrow> \\<lfloor>(t, m)\\<rfloor>) | \\<lfloor>(t', m)\\<rfloor> \\<Rightarrow> \\<lfloor>(t', n + m)\\<rfloor>)\"\nby(induct n arbitrary: L)(auto)\n\nlemma lock_lock_ls_Some:\n  \"\\<exists>t' n. lock_lock l t = \\<lfloor>(t', n)\\<rfloor>\"\nby(cases l, auto)\n\nlemma unlock_lock_SomeD:\n  \"unlock_lock l = \\<lfloor>(t', n)\\<rfloor> \\<Longrightarrow> l = \\<lfloor>(t', Suc n)\\<rfloor>\"\nby(cases l, auto split: nat.split_asm)\n\nlemma has_locks_Suc_lock_lock_has_locks_Suc_Suc:\n  \"has_locks l t = Suc n \\<Longrightarrow> has_locks (lock_lock l t) t = Suc (Suc n)\"\nby(auto elim!: has_locksE)\n\nlemma has_locks_lock_lock_conv [simp]:\n  \"may_lock l t \\<Longrightarrow> has_locks (lock_lock l t) t = Suc (has_locks l t)\"\nby(auto elim: may_lockE)\n\nlemma has_locks_release_all_conv [simp]:\n  \"has_locks (release_all l t) t = 0\"\nby(cases l, auto split: split_if_asm)\n\nlemma may_lock_lock_lock_conv [simp]: \"may_lock (lock_lock l t) t = may_lock l t\"\nby(cases l, auto elim!: may_lock.cases intro: may_lock.intros)\n\nlemma has_locks_acquire_locks_conv [simp]:\n  \"may_lock l t \\<Longrightarrow> has_locks (acquire_locks l t n) t = has_locks l t + n\"\nby(induct n arbitrary: l, auto)\n\nlemma may_lock_unlock_lock_conv [simp]:\n  \"has_lock l t \\<Longrightarrow> may_lock (unlock_lock l) t = may_lock l t\"\nby(cases l)(auto split: split_if_asm nat.splits elim!: may_lock.cases intro: may_lock.intros)\n\nlemma may_lock_release_all_conv [simp]:\n  \"may_lock (release_all l t) t = may_lock l t\"\nby(cases l, auto split: split_if_asm intro!: may_lockI elim: may_lockE)\n\nlemma may_lock_t_may_lock_unlock_lock_t: \n  \"may_lock l t \\<Longrightarrow> may_lock (unlock_lock l) t\"\nby(auto intro: may_lock.intros elim!: may_lockE split: nat.split)\n\n\nlemma may_lock_has_locks_lock_lock_0: \n  \"\\<lbrakk>may_lock l t'; t \\<noteq> t'\\<rbrakk> \\<Longrightarrow> has_locks (lock_lock l t') t = 0\"\nby(auto elim!: may_lock.cases)\n\n\n\nlemma has_lock_lock_lock_unlock_lock_id [simp]:\n  \"has_lock l t \\<Longrightarrow> lock_lock (unlock_lock l) t = l\"\nby(cases l)(auto split: split_if_asm nat.split)\n\nlemma may_lock_unlock_lock_lock_lock_id [simp]:\n  \"may_lock l t \\<Longrightarrow> unlock_lock (lock_lock l t) = l\"\nby(cases l) auto\n\n\nlemma may_lock_has_locks_0:\n  \"\\<lbrakk> may_lock l t; t \\<noteq> t' \\<rbrakk> \\<Longrightarrow> has_locks l t' = 0\"\nby(auto elim!: may_lockE)\n\n\nfun upd_lock :: \"'t lock \\<Rightarrow> 't \\<Rightarrow> lock_action \\<Rightarrow> 't lock\"\nwhere\n  \"upd_lock l t Lock = lock_lock l t\"\n| \"upd_lock l t Unlock = unlock_lock l\"\n| \"upd_lock l t UnlockFail = l\"\n| \"upd_lock l t ReleaseAquire = release_all l t\"\n\nfun upd_locks :: \"'t lock \\<Rightarrow> 't \\<Rightarrow> lock_action list \\<Rightarrow> 't lock\"\nwhere\n  \"upd_locks l t [] = l\"\n| \"upd_locks l t (L # Ls) = upd_locks (upd_lock l t L) t Ls\"\n\nlemma upd_locks_append [simp]:\n  \"upd_locks l t (Ls @ Ls') = upd_locks (upd_locks l t Ls) t Ls'\"\nby(induct Ls arbitrary: l, auto)\n\nlemma upd_lock_Some_thread_idD:\n  assumes ul: \"upd_lock l t L = \\<lfloor>(t', n)\\<rfloor>\"\n  and tt': \"t \\<noteq> t'\"\n  shows \"\\<exists>n. l = \\<lfloor>(t', n)\\<rfloor>\"\nproof(cases L)\n  case Lock\n  with ul tt' show ?thesis\n    by(cases l, auto)\nnext\n  case Unlock\n  with ul tt' show ?thesis\n    by(auto dest: unlock_lock_SomeD)\nnext\n  case UnlockFail\n  with ul show ?thesis by(simp)\nnext\n  case ReleaseAcquire\n  with ul show ?thesis\n    by(cases l, auto split: split_if_asm)\nqed\n\n\nlemma has_lock_upd_lock_implies_has_lock:\n  \"\\<lbrakk> has_lock (upd_lock l t L) t'; t \\<noteq> t' \\<rbrakk> \\<Longrightarrow> has_lock l t'\"\nby(cases l L rule: option.exhaust[case_product lock_action.exhaust])(auto split: split_if_asm nat.split_asm)\n\nlemma has_lock_upd_locks_implies_has_lock:\n  \"\\<lbrakk> has_lock (upd_locks l t Ls) t'; t \\<noteq> t' \\<rbrakk> \\<Longrightarrow> has_lock l t'\"\nby(induct l t Ls rule: upd_locks.induct)(auto intro: has_lock_upd_lock_implies_has_lock)\n\n(* Preconditions for lock actions *)\n\nfun lock_action_ok :: \"'t lock \\<Rightarrow> 't \\<Rightarrow> lock_action \\<Rightarrow> bool\" where\n  \"lock_action_ok l t Lock = may_lock l t\"\n| \"lock_action_ok l t Unlock = has_lock l t\"\n| \"lock_action_ok l t UnlockFail = (\\<not> has_lock l t)\"\n| \"lock_action_ok l t ReleaseAcquire = True\"\n\nfun lock_actions_ok :: \"'t lock \\<Rightarrow> 't \\<Rightarrow> lock_action list \\<Rightarrow> bool\" where\n  \"lock_actions_ok l t [] = True\"\n| \"lock_actions_ok l t (L # Ls) = (lock_action_ok l t L \\<and> lock_actions_ok (upd_lock l t L) t Ls)\"\n\nlemma lock_actions_ok_append [simp]:\n  \"lock_actions_ok l t (Ls @ Ls') \\<longleftrightarrow> lock_actions_ok l t Ls \\<and> lock_actions_ok (upd_locks l t Ls) t Ls'\"\nby(induct Ls arbitrary: l) auto\n\nlemma not_lock_action_okE [consumes 1, case_names Lock Unlock UnlockFail]:\n  \"\\<lbrakk> \\<not> lock_action_ok l t L;\n     \\<lbrakk> L = Lock; \\<not> may_lock l t \\<rbrakk> \\<Longrightarrow> Q;\n     \\<lbrakk> L = Unlock; \\<not> has_lock l t \\<rbrakk> \\<Longrightarrow> Q;\n     \\<lbrakk> L = UnlockFail; has_lock l t \\<rbrakk> \\<Longrightarrow> Q\\<rbrakk>\n  \\<Longrightarrow> Q\"\nby(cases L) auto\n\nlemma may_lock_upd_lock_conv [simp]:\n  \"lock_action_ok l t L \\<Longrightarrow> may_lock (upd_lock l t L) t = may_lock l t\"\nby(cases L) auto\n\nlemma may_lock_upd_locks_conv [simp]:\n  \"lock_actions_ok l t Ls \\<Longrightarrow> may_lock (upd_locks l t Ls) t = may_lock l t\"\nby(induct l t Ls rule: upd_locks.induct) simp_all\n\nlemma lock_actions_ok_Lock_may_lock:\n  \"\\<lbrakk> lock_actions_ok l t Ls; Lock \\<in> set Ls \\<rbrakk> \\<Longrightarrow> may_lock l t\"\nby(induct l t Ls rule: lock_actions_ok.induct) auto\n\nlemma has_locks_lock_lock_conv' [simp]:\n  \"\\<lbrakk> may_lock l t'; t \\<noteq> t' \\<rbrakk> \\<Longrightarrow> has_locks (lock_lock l t') t = has_locks l t\"\nby(cases l)(auto elim: may_lock.cases)\n\nlemma has_locks_unlock_lock_conv' [simp]:\n  \"\\<lbrakk> has_lock l t'; t \\<noteq> t' \\<rbrakk> \\<Longrightarrow> has_locks (unlock_lock l) t = has_locks l t\"\nby(cases l)(auto split: split_if_asm nat.split)\n\nlemma has_locks_release_all_conv' [simp]:\n  \"t \\<noteq> t' \\<Longrightarrow> has_locks (release_all l t') t = has_locks l t\"\nby(cases l) auto\n\nlemma has_locks_acquire_locks_conv' [simp]:\n  \"\\<lbrakk> may_lock l t; t \\<noteq> t' \\<rbrakk> \\<Longrightarrow> has_locks (acquire_locks l t n) t' = has_locks l t'\"\nby(induct l t n rule: acquire_locks.induct) simp_all\n\nlemma lock_action_ok_has_locks_upd_lock_eq_has_locks [simp]:\n  \"\\<lbrakk> lock_action_ok l t' L; t \\<noteq> t' \\<rbrakk> \\<Longrightarrow> has_locks (upd_lock l t' L) t = has_locks l t\"\nby(cases L) auto\n\nlemma lock_actions_ok_has_locks_upd_locks_eq_has_locks [simp]:\n  \"\\<lbrakk> lock_actions_ok l t' Ls; t \\<noteq> t' \\<rbrakk> \\<Longrightarrow> has_locks (upd_locks l t' Ls) t = has_locks l t\"\nby(induct l t' Ls rule: upd_locks.induct) simp_all\n\nlemma has_lock_acquire_locks_implies_has_lock:\n  \"\\<lbrakk> has_lock (acquire_locks l t n) t'; t \\<noteq> t' \\<rbrakk> \\<Longrightarrow> has_lock l t'\"\n unfolding acquire_locks_conv\n by(cases n)(auto split: split_if_asm)\n\nlemma has_lock_has_lock_acquire_locks:\n  \"has_lock l T \\<Longrightarrow> has_lock (acquire_locks l t n) T\"\n  unfolding acquire_locks_conv\n  by(auto)\n\n\nfun lock_actions_ok' :: \"'t lock \\<Rightarrow> 't \\<Rightarrow> lock_action list \\<Rightarrow> bool\" where\n  \"lock_actions_ok' l t [] = True\"\n| \"lock_actions_ok' l t (L#Ls) = ((L = Lock \\<and> \\<not> may_lock l t) \\<or>\n                                  lock_action_ok l t L \\<and> lock_actions_ok' (upd_lock l t L) t Ls)\"\n\nlemma lock_actions_ok'_iff:\n  \"lock_actions_ok' l t las \\<longleftrightarrow> \n   lock_actions_ok l t las \\<or> (\\<exists>xs ys. las = xs @ Lock # ys \\<and> lock_actions_ok l t xs \\<and> \\<not> may_lock (upd_locks l t xs) t)\"\nproof(induct l t las rule: lock_actions_ok.induct)\n  case (2 L t LA LAS)\n  show ?case\n  proof(cases \"LA = Lock \\<and> \\<not> may_lock L t\")\n    case True\n    hence \"(\\<exists>ys. Lock # LAS = [] @ Lock # ys) \\<and> lock_actions_ok L t [] \\<and> \\<not> may_lock (upd_locks L t []) t\"\n      by(simp)\n    with True show ?thesis by(simp (no_asm))(blast)\n  next\n    case False\n    with 2 show ?thesis\n      by(fastforce simp add: Cons_eq_append_conv elim: allE[where x=\"LA # xs\" for xs])\n  qed\nqed simp\n\nlemma lock_actions_ok'E[consumes 1, case_names ok Lock]:\n  \"\\<lbrakk> lock_actions_ok' l t las;\n     lock_actions_ok l t las \\<Longrightarrow> P;\n     \\<And>xs ys. \\<lbrakk> las = xs @ Lock # ys; lock_actions_ok l t xs; \\<not> may_lock (upd_locks l t xs) t \\<rbrakk> \\<Longrightarrow> P \\<rbrakk> \n  \\<Longrightarrow> P\"\nby(auto simp add: lock_actions_ok'_iff)\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/JinjaThreads/Framework/FWLock.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5813030906443133, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.2702487202847485}}
{"text": "(*\n * Copyright 2014, General Dynamics C4 Systems\n *\n * This software may be distributed and modified according to the terms of\n * the GNU General Public License version 2. Note that NO WARRANTY is provided.\n * See \"LICENSE_GPLv2.txt\" for details.\n *\n * @TAG(GD_GPL)\n *)\n\n(* Title:   Confinement_S\n * Description: confinement proof of the security model\n *)\n\ntheory Confine_S\nimports System_S\nbegin\n\n(* These translate Create into all_rights *)\ndefinition\n  extra_rights :: \"cap \\<Rightarrow> cap\" where\n  \"extra_rights c \\<equiv>\n  if (Create \\<in> rights c)\n  then c\\<lparr>rights := all_rights\\<rparr>\n  else c\"\n\n\nlemma extra_rights_idem [simp]:\n  \"(extra_rights (extra_rights c)) = (extra_rights c)\"\n  apply (clarsimp simp add: extra_rights_def)\n  done\n\nlemma extra_rights_image_idem [simp]:\n  \"(extra_rights ` (extra_rights ` S)) = (extra_rights ` S)\"\n  by (rule set_eqI) (simp add: image_iff)\n\nlemma extra_rights_empty_rights_ident [simp]:\n   \"extra_rights \\<lparr> target = e, rights = {} \\<rparr> = \\<lparr> target = e, rights = {} \\<rparr>\"\n  by (simp add: extra_rights_def)\n\nlemma entity_extra_rights [simp]:\n  \"target (extra_rights c) = target c\"\n  by (simp add: extra_rights_def)\n\nlemma rights_extra_rights:\n  \"rights (extra_rights c) =\n   (if Create \\<in> (rights c)\n    then all_rights\n    else rights c)\"\n  by (simp add: extra_rights_def)\n\n(* The following two definitions both translate Create into all_rights *)\n\n(* A cap is in a set, or a cap with more access is. *)\ndefinition\n  cap_in_caps :: \"cap \\<Rightarrow> cap set \\<Rightarrow> bool\" (infix \"\\<in>cap\" 50) where\n  \"c \\<in>cap C \\<equiv> \\<exists>c' \\<in> C. target c = target c' \\<and> rights (extra_rights c) \\<subseteq> rights (extra_rights c')\"\n\nabbreviation not_cap_in_caps where\n  \"not_cap_in_caps x A \\<equiv> ~ (x \\<in>cap A)\" -- \"non-membership\"\n\nnotation (input) cap_in_caps (infix \":cap\" 50)\nnotation (latex output)  cap_in_caps (infix \"\\<in>\\<^sub>c\\<^sub>a\\<^sub>p\" 50)\n\nnotation\n  not_cap_in_caps  (\"op \\<notin>cap\") and\n  not_cap_in_caps  (\"(_/ \\<notin>cap _)\" [51, 51] 50)\n\nnotation (latex output)\n  not_cap_in_caps  (\"op \\<notin>\\<^sub>c\\<^sub>a\\<^sub>p\") and\n  not_cap_in_caps  (infix \"\\<notin>\\<^sub>c\\<^sub>a\\<^sub>p\" 50)\n\n(* A set of caps \"caps\" have less (or equal) access to an entity as \"cap\" does. *)\ndefinition\n  caps_dominated_by :: \"cap set \\<Rightarrow> cap \\<Rightarrow> bool\" (infix \"\\<le>cap\" 50) where\n  \"caps \\<le>cap cap \\<equiv> \\<forall>cap' \\<in> caps. target cap' = target cap \\<longrightarrow> rights (extra_rights cap') \\<subseteq> rights (extra_rights cap)\"\n\nnotation (input) caps_dominated_by (infix \"<=cap\" 50)\nnotation (latex output) caps_dominated_by (infix \"\\<unlhd>\\<^sub>c\\<^sub>a\\<^sub>p\" 50)\n\ndefinition\n  shares_caps :: \"state \\<Rightarrow> entity_id \\<Rightarrow> entity_id \\<Rightarrow> bool\" where\n  \"shares_caps s e\\<^sub>x e\\<^sub>y \\<equiv> \\<exists>e\\<^sub>i . (e\\<^sub>x, e\\<^sub>i) \\<in> store_connected s \\<and> (e\\<^sub>y, e\\<^sub>i) \\<in> store_connected s\"\n\ndefinition\n  leak :: \"state \\<Rightarrow> entity_id \\<Rightarrow> entity_id \\<Rightarrow> bool\" (\"_ \\<turnstile> _ \\<rightarrow> _\") where\n  \"leak s e\\<^sub>x e\\<^sub>y \\<equiv> take_cap e\\<^sub>x \\<in>cap caps_of s e\\<^sub>y \\<or> grant_cap e\\<^sub>y \\<in>cap caps_of s e\\<^sub>x \\<or> shares_caps s e\\<^sub>x e\\<^sub>y\"\n\n\ndefinition\n  directly_tgs_connected :: \"state \\<Rightarrow> (entity_id \\<times> entity_id) set\" where\n  \"directly_tgs_connected s \\<equiv> {(e\\<^sub>x, e\\<^sub>y). leak s e\\<^sub>x e\\<^sub>y \\<or> leak s e\\<^sub>y e\\<^sub>x}\"\n\nlemma directly_tgs_connected_def2:\n  \"(e\\<^sub>x, e\\<^sub>y) \\<in> directly_tgs_connected s = (leak s e\\<^sub>x e\\<^sub>y \\<or> leak s e\\<^sub>y e\\<^sub>x)\"\n  by (simp add: directly_tgs_connected_def)\n\nabbreviation\n  in_directly_tgs_connected :: \"state \\<Rightarrow> entity_id \\<Rightarrow> entity_id \\<Rightarrow> bool\" (\"_ \\<turnstile> _ \\<leftrightarrow> _\" [60,0,60] 61)\nwhere\n  \"s \\<turnstile> x \\<leftrightarrow> y \\<equiv> (x,y) \\<in> directly_tgs_connected s\"\n\ndefinition\n  tgs_connected :: \"state \\<Rightarrow> (entity_id \\<times> entity_id) set\" where\n  \"tgs_connected s \\<equiv> (directly_tgs_connected s)\\<^sup>*\"\n\nabbreviation\n  in_tgs_connected :: \"state \\<Rightarrow> entity_id \\<Rightarrow> entity_id \\<Rightarrow> bool\" (\"_ \\<turnstile> _ \\<leftrightarrow>* _\" [60,0,60] 61)\nwhere\n  \"s \\<turnstile> x \\<leftrightarrow>* y == (x,y) \\<in> tgs_connected s\"\n\nnotation (latex output)\n  in_tgs_connected (\"_ \\<turnstile> _ \\<leftrightarrow>\\<^sup>* _\" [60,0,60] 61)\n\ntranslations\n  \"\\<not> (s \\<turnstile> x \\<leftrightarrow> y)\" <= \"(x,y) \\<notin> CONST directly_tgs_connected s\"\n  \"\\<not> (s \\<turnstile> x \\<leftrightarrow>* y)\" <= \"(x,y) \\<notin> CONST tgs_connected s\"\n\nlemma shares_caps_sym [simp]:\n \"shares_caps s y x = shares_caps s x y\"\n  by (auto simp: shares_caps_def)\n\nlemma directly_tgs_connected_def4:\n  \"s \\<turnstile> e\\<^sub>x \\<leftrightarrow> e\\<^sub>y = (take_cap e\\<^sub>x \\<in>cap caps_of s e\\<^sub>y \\<or> take_cap e\\<^sub>y \\<in>cap caps_of s e\\<^sub>x \\<or>\n                  grant_cap e\\<^sub>y \\<in>cap caps_of s e\\<^sub>x \\<or> grant_cap e\\<^sub>x \\<in>cap caps_of s e\\<^sub>y \\<or>\n                  shares_caps s e\\<^sub>x e\\<^sub>y)\"\n  by (auto simp: directly_tgs_connected_def leak_def)\n\n(* Note: e\\<^sub>0 is unused. *)\ndefinition\n  generalOperation ::\n  \"entity_id \\<Rightarrow> entity_id \\<Rightarrow> cap \\<Rightarrow> right set \\<Rightarrow> modify_state\" where\n  \"generalOperation e\\<^sub>0 e\\<^sub>1 c r s \\<equiv>\n  s (e\\<^sub>1 \\<mapsto> Entity ( insert (diminish r (extra_rights c)) (direct_caps_of s e\\<^sub>1) ))\"\n\nlemma is_entity_general [simp]:\n  \"is_entity s e\\<^sub>1 \\<Longrightarrow> is_entity (generalOperation e\\<^sub>0 e\\<^sub>1 c r s) e' = is_entity s e'\"\n  by (simp add: is_entity_def generalOperation_def)\n\ndefinition\n  make_entity :: \"entity_id \\<Rightarrow> modify_state\" where\n  \"make_entity n s \\<equiv>\n  s (n \\<mapsto> null_entity)\"\n\nlemma direct_caps_of_store_connected_eq:\n  \"\\<forall> e. direct_caps_of s e = direct_caps_of s' e\n  \\<Longrightarrow> store_connected s = store_connected s'\"\n  by (simp add: store_connected_def store_connected_direct_def\n                direct_caps_of_def)\n\nlemma direct_caps_of_caps_of_eq:\n  \"\\<forall> e. direct_caps_of s e = direct_caps_of s' e \\<Longrightarrow> caps_of s e = caps_of s' e\"\n  by (simp add: caps_of_def store_connected_def store_connected_direct_def\n                direct_caps_of_def)\n\nlemma direct_caps_of_caps_of_eq2:\n  \"\\<lbrakk>\\<forall> e. direct_caps_of s e = direct_caps_of s' e; c \\<in>cap caps_of s e\\<rbrakk> \\<Longrightarrow> c \\<in>cap caps_of s' e\"\n  apply (drule direct_caps_of_caps_of_eq)\n  apply (simp add: cap_in_caps_def)\n  by auto\n\nlemma direct_caps_of_directly_tgs_connected_eq:\n  \"\\<forall> e. direct_caps_of s e = direct_caps_of s' e \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow> y = s' \\<turnstile> x \\<leftrightarrow> y\"\n  apply (simp add: directly_tgs_connected_def4 shares_caps_def)\n  apply rule\n   apply (erule disjE, drule (1) direct_caps_of_caps_of_eq2, clarsimp)+\n   apply (drule direct_caps_of_store_connected_eq, clarsimp)\n  apply (erule disjE, drule direct_caps_of_caps_of_eq2 [rotated, where s=s' and s'=s], simp+)+\n  apply (drule direct_caps_of_store_connected_eq, simp)\n  done\n\nlemma direct_caps_of_make_entity:\n  \"\\<not> is_entity s n \\<Longrightarrow> direct_caps_of (make_entity n s) e = direct_caps_of s e\"\n  by (simp add: direct_caps_of_def make_entity_def is_entity_def\n                null_entity_def)\n\nlemma caps_of_make_entity:\n  \"\\<not> is_entity s n \\<Longrightarrow> caps_of (make_entity n s) e = caps_of s e\"\n  apply (rule direct_caps_of_caps_of_eq)\n  apply clarsimp\n  apply (erule direct_caps_of_make_entity)\n  done\n\nlemma caps_of_make_entity2:\n  \"\\<lbrakk>\\<not> is_entity s n; c \\<in> caps_of (make_entity n s) e\\<rbrakk> \\<Longrightarrow> c \\<in> caps_of s e\"\n  apply (drule caps_of_make_entity)\n  apply fastforce\n  done\n\nlemma directly_tgs_connected_make_entity:\n \"\\<not> is_entity s n \\<Longrightarrow> make_entity n s \\<turnstile> x \\<leftrightarrow> y = s \\<turnstile> x \\<leftrightarrow> y\"\n  apply (rule direct_caps_of_directly_tgs_connected_eq)\n  apply clarsimp\n  apply (drule (1) direct_caps_of_make_entity)\n  done\n\nlemma directly_tgs_connected_make_entity2:\n \"\\<lbrakk>\\<not> is_entity s n; make_entity n s \\<turnstile> x \\<leftrightarrow> y\\<rbrakk> \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow> y\"\n  apply (drule directly_tgs_connected_make_entity)\n  apply fastforce\n  done\n\nlemma diminish_extra_rights [simp]:\n  \"diminish (rights c) (extra_rights c) = c\"\n  by (simp add: diminish_def all_rights_def rights_extra_rights)\n\nlemma diminish_extra_rights2 [simp]:\n  \"diminish (r \\<inter> rights c) (extra_rights c) = diminish r c\"\n  apply (simp add: diminish_def extra_rights_def all_rights_def)\n  apply (simp add: Int_commute)\n  apply (subgoal_tac \"rights c \\<inter> (r \\<inter> rights c) = r \\<inter> rights c\")\n   apply simp\n  apply fastforce\n  done\n\nlemma create_general_helper:\n  \"Create \\<in> rights c\\<^sub>2 \\<Longrightarrow>\n   \\<lparr>target = target c\\<^sub>2, rights = UNIV\\<rparr> = c\\<^sub>2\\<lparr>rights := UNIV\\<rparr>\"\n  by auto\n\nlemma extra_rights_full_cap [simp]:\n  \"extra_rights (full_cap e) = full_cap e\"\n  by (simp add: extra_rights_def)\n\nlemma create_general_alt:\n  \"createOperation e c\\<^sub>1 c\\<^sub>2 s =\n   make_entity (target c\\<^sub>2)\n               (generalOperation  e (target c\\<^sub>1) (full_cap (target c\\<^sub>2)) (all_rights) s)\"\n  by (simp add: createOperation_def generalOperation_def make_entity_def)\n\nlemma create_general:\n  \"Create \\<in> rights c\\<^sub>2 \\<Longrightarrow> createOperation e c\\<^sub>1 c\\<^sub>2 s =\n   make_entity (target c\\<^sub>2)\n               (generalOperation  e (target c\\<^sub>1) c\\<^sub>2 (all_rights) s)\"\n  by (simp add: createOperation_def generalOperation_def make_entity_def\n                full_cap_def all_rights_def diminish_def\n                extra_rights_def create_general_helper null_entity_def)\n\nlemma take_general:\n  \"takeOperation e c\\<^sub>1 c\\<^sub>2 r s =\n   generalOperation (target c\\<^sub>1) e c\\<^sub>2 (r \\<inter> rights c\\<^sub>2) s\"\n  by (simp add: takeOperation_def generalOperation_def)\n\nlemma grant_general:\n  \"grantOperation e c\\<^sub>1 c\\<^sub>2 r s =\n   generalOperation e (target c\\<^sub>1) c\\<^sub>2 (r \\<inter> rights c\\<^sub>2) s\"\n  by (simp add: grantOperation_def generalOperation_def)\n\nlemma copy_general:\n  \"copyOperation e c\\<^sub>1 c\\<^sub>2 r s =\n   generalOperation e (target c\\<^sub>1) c\\<^sub>2 (r \\<inter> rights c\\<^sub>2) s\"\n  by (simp add: copyOperation_def generalOperation_def)\n\n(* Lemmas on the directly_tgs_connected predicate *)\nlemma directly_tgs_connected_comm:\n  \"s \\<turnstile> x \\<leftrightarrow> y \\<Longrightarrow> s \\<turnstile> y \\<leftrightarrow> x\"\n  by(auto simp: directly_tgs_connected_def)\n\nlemma tgs_connected_refl [simp]:\n  \"s \\<turnstile> x \\<leftrightarrow>* x\"\n  by (metis tgs_connected_def rtrancl.rtrancl_refl)\n\nlemma tgs_connected_comm:\n  \"s \\<turnstile> x \\<leftrightarrow>* y \\<Longrightarrow> s \\<turnstile> y \\<leftrightarrow>* x\"\n  apply(simp add: tgs_connected_def)\n  apply(erule rtrancl_induct, simp)\n  apply(case_tac \"s \\<turnstile> z \\<leftrightarrow> y\")\n   apply(simp add: directly_tgs_connected_comm)\n  apply(simp add: directly_tgs_connected_comm)\n  done\n\nlemma tgs_connected_comm_eq:\n  \"s \\<turnstile> x \\<leftrightarrow>* y = s \\<turnstile> y \\<leftrightarrow>* x\"\n  by (metis tgs_connected_comm)\n\nlemmas tgs_connected_trans =\n       rtrancl_trans [where r=\"directly_tgs_connected s\", simplified tgs_connected_def[symmetric]]\n\nlemmas directly_tgs_connected_rtrancl_into_rtrancl =\n       rtrancl_into_rtrancl [where r=\"directly_tgs_connected s\", simplified tgs_connected_def[symmetric]]\n\nlemma take_caps_directly_tgs_connected:\n  \"\\<lbrakk>c \\<in> caps_of s e; Take \\<in> rights c\\<rbrakk> \\<Longrightarrow> s \\<turnstile> e \\<leftrightarrow> target c\"\n  by (auto simp: directly_tgs_connected_def leak_def take_cap_def cap_in_caps_def extra_rights_def all_rights_def)\n\nlemma grant_caps_directly_tgs_connected:\n  \"\\<lbrakk>c \\<in> caps_of s e; Grant \\<in> rights c\\<rbrakk> \\<Longrightarrow> s \\<turnstile> e \\<leftrightarrow> target c\"\n  by (auto simp: directly_tgs_connected_def leak_def grant_cap_def cap_in_caps_def extra_rights_def all_rights_def)\n\nlemma create_caps_directly_tgs_connected:\n  \"\\<lbrakk>c \\<in> caps_of s e; Create \\<in> rights c\\<rbrakk> \\<Longrightarrow> s \\<turnstile> e \\<leftrightarrow> target c\"\n  by (auto simp: directly_tgs_connected_def leak_def cap_in_caps_def rights_extra_rights all_rights_def)\n\nlemma store_connected_directly_tgs_connected:\n  \"(x, y) \\<in> store_connected s \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow> y\"\n  by (auto simp: directly_tgs_connected_def leak_def shares_caps_def store_connected_def)\n\n(* Lemmas on caps *)\n\nlemma cap_in_caps_insert [simp]:\n  \"c \\<in>cap insert c' S = (target c = target c' \\<and>\n  rights (extra_rights c) \\<subseteq> rights (extra_rights c') \\<or> c \\<in>cap S)\"\n  by (simp add: cap_in_caps_def)\n\nlemma cap_in_caps_singleton [simp]:\n  \"c \\<in>cap {c'} = (target c = target c' \\<and> rights (extra_rights c) \\<subseteq> rights (extra_rights c'))\"\n  by (simp add: cap_in_caps_def)\n\nlemma not_in [simp]:\n  \"{} \\<le>cap c\"\n  by(simp add: caps_dominated_by_def)\n\nlemma extra_rights_diminish:\n  \"x \\<in> rights (extra_rights (diminish r c))\n   \\<Longrightarrow> x \\<in> rights (extra_rights c)\"\n  by (auto simp: rights_extra_rights all_rights_def split:if_split_asm)\n\n(* Lemmas on system operations *)\n\ndefinition\n  in_store_connected :: \"state \\<Rightarrow> entity_id \\<Rightarrow> entity_id \\<Rightarrow> bool\" where\n  \"in_store_connected s x y \\<equiv> (x, y) \\<in> store_connected s\"\n\n(* Lemmas about the general operation *)\n\nlemma direct_caps_of_generalOp:\n  \"direct_caps_of (generalOperation e\\<^sub>0 e\\<^sub>1 c r s) e =\n  (if e = e\\<^sub>1\n   then insert (diminish r (extra_rights c)) (direct_caps_of s (e\\<^sub>1))\n   else direct_caps_of s e)\"\n  by (clarsimp simp: generalOperation_def direct_caps_of_def split:option.splits)\n\nlemma direct_caps_of_generalOp2:\n  \"\\<lbrakk>c' \\<in> direct_caps_of (generalOperation e\\<^sub>0 e\\<^sub>1 c r s) x\\<rbrakk> \\<Longrightarrow>\n   c' \\<in> direct_caps_of s x \\<or> (c' \\<in>cap {c} \\<and> x = e\\<^sub>1)\"\n  apply (clarsimp simp: direct_caps_of_generalOp extra_rights_diminish\n           split:if_split_asm)\n  apply (drule extra_rights_diminish)\n  by simp\n\nlemma store_connected_direct_generalOp:\n  \"\\<lbrakk>(x, y) \\<in> store_connected_direct (generalOperation e\\<^sub>0 e\\<^sub>1 c r s)\\<rbrakk> \\<Longrightarrow>\n   (x, y) \\<in> store_connected_direct s \\<or>\n   (x = e\\<^sub>1 \\<and> y = target c \\<and> Store \\<in> rights (extra_rights c))\"\n  by (auto simp: store_connected_direct_def direct_caps_of_generalOp all_rights_def\n          split: if_split_asm)\n\nlemma store_connected_generalOp:\n  \"\\<lbrakk>(x, y) \\<in> store_connected (generalOperation e\\<^sub>0 e\\<^sub>1 c r s)\\<rbrakk> \\<Longrightarrow>\n   (x, y) \\<in> store_connected s \\<or>\n   ((x, e\\<^sub>1) \\<in> store_connected s \\<and>\n   (e\\<^sub>1, target c) \\<in> store_connected_direct (generalOperation e\\<^sub>0 e\\<^sub>1 c r s) \\<and>\n   (target c, y) \\<in> store_connected s)\"\n  apply (unfold store_connected_def)\n  apply (erule rtrancl_induct)\n   apply clarsimp\n  apply (clarsimp)\n  apply (fold store_connected_def)\n  apply (subgoal_tac \"(y, z) \\<in> store_connected_direct s\")\n   apply (clarsimp simp: store_connected_def)\n   apply (erule disjE)\n    apply fastforce\n   apply clarsimp\n   apply (erule notE)\n   apply fastforce\n  apply (frule store_connected_direct_generalOp)\n  apply (clarsimp simp: store_connected_def)\n  done\n\n\nlemma store_connected_generalOp_not_new:\n  \"\\<lbrakk>(e\\<^sub>1, target c) \\<in> store_connected_direct (generalOperation e\\<^sub>0 e\\<^sub>1 c r s);\n   c \\<in> caps_of s e\\<^sub>0\\<rbrakk> \\<Longrightarrow>\n   (e\\<^sub>1, target c) \\<in> store_connected_direct s \\<or>\n   (e\\<^sub>0, target c) \\<in> store_connected s \\<or>\n   Create \\<in> rights c\"\n  apply (drule store_connected_direct_generalOp)\n  apply (clarsimp simp: rights_extra_rights split:if_split_asm)\n   apply (drule (1) store_caps_store_connected, simp)\n  done\n\nlemma store_connected_generalOp2:\n  \"\\<lbrakk>(x, y) \\<in> store_connected (generalOperation e\\<^sub>0 e\\<^sub>1 c r s);\n   c \\<in> caps_of s e\\<^sub>0; s \\<turnstile> e\\<^sub>0 \\<leftrightarrow> e\\<^sub>1\\<rbrakk> \\<Longrightarrow>\n   s \\<turnstile> x \\<leftrightarrow>* y\"\n  apply (drule store_connected_generalOp)\n  apply (erule disjE)\n   apply (simp add: tgs_connected_def)\n   apply (drule store_connected_directly_tgs_connected, simp)\n  apply clarsimp\n  apply (drule store_connected_directly_tgs_connected [where x=x and y=e\\<^sub>1])\n  apply (drule store_connected_directly_tgs_connected [where x=\"target c\" and y=y])\n  apply (drule (1) store_connected_generalOp_not_new)\n  apply (erule disjE)\n   apply (drule store_connected_direct_in_store_connected)\n   apply (drule store_connected_directly_tgs_connected [where x=e\\<^sub>1 and y=\"target c\"])\n   apply (simp add: tgs_connected_def)\n  apply (drule directly_tgs_connected_comm [where x=\"e\\<^sub>0\" and y=\"e\\<^sub>1\"])\n  apply (erule disjE)\n   apply (drule store_connected_directly_tgs_connected [where x=e\\<^sub>0 and y=\"target c\"])\n   apply (simp add: tgs_connected_def)\n  apply (drule (1) create_caps_directly_tgs_connected)\n  apply (simp add: tgs_connected_def)\n  done\n\nlemma shares_caps_of_generalOp:\n  \"\\<lbrakk>shares_caps (generalOperation e\\<^sub>0 e\\<^sub>1 c r s) x y;\n   c \\<in> caps_of s e\\<^sub>0; s \\<turnstile> e\\<^sub>0 \\<leftrightarrow> e\\<^sub>1\\<rbrakk>\n  \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow>* y\"\n  apply (clarsimp simp: shares_caps_def)\n  apply (frule (2) store_connected_generalOp2 [where x=x])\n  apply (drule (2) store_connected_generalOp2 [where x=y])\n  apply (drule tgs_connected_comm [where x=y])\n  apply (simp add: tgs_connected_def)\n  done\n\nlemma caps_of_generalOp:\n  \"\\<lbrakk>c' \\<in> caps_of (generalOperation e\\<^sub>0 e\\<^sub>1 c r s) x;\n   c \\<in> caps_of s e\\<^sub>0; s \\<turnstile> e\\<^sub>0 \\<leftrightarrow> e\\<^sub>1\\<rbrakk>\n  \\<Longrightarrow> \\<exists>z. (x,z) \\<in> tgs_connected s \\<and> c' \\<in>cap caps_of s z\"\n  apply (simp add: caps_of_def[where e=x])\n  apply clarsimp\n  apply (frule (2) store_connected_generalOp2)\n  apply (drule direct_caps_of_generalOp2)\n  apply (erule disjE)\n   apply (drule direct_cap_in_cap)\n   apply (fastforce simp: cap_in_caps_def)\n  apply (subgoal_tac \"s \\<turnstile> x \\<leftrightarrow>* e\\<^sub>0\")\n   apply (subgoal_tac \"c' \\<in>cap caps_of s e\\<^sub>0\")\n    apply fastforce\n   apply (fastforce simp: cap_in_caps_def)\n  apply clarsimp\n  apply (drule directly_tgs_connected_comm [where x=\"e\\<^sub>0\" and y=\"e\\<^sub>1\"])\n  apply (simp add: tgs_connected_def)\n  done\n\nlemma take_cap_generalOp:\n  \"\\<lbrakk>take_cap y \\<in>cap caps_of (generalOperation e\\<^sub>0 e\\<^sub>1 c r s) x;\n   c \\<in> caps_of s e\\<^sub>0; s \\<turnstile> e\\<^sub>0 \\<leftrightarrow> e\\<^sub>1\\<rbrakk>\n  \\<Longrightarrow> \\<exists>z.  s \\<turnstile> x \\<leftrightarrow>* z \\<and> take_cap y \\<in>cap caps_of s z\"\n  apply (simp add: cap_in_caps_def)\n  apply clarsimp\n  apply (drule (2) caps_of_generalOp)\n  apply (fastforce simp: cap_in_caps_def)\n  done\n\nlemma grant_cap_generalOp:\n  \"\\<lbrakk>grant_cap y \\<in>cap caps_of (generalOperation e\\<^sub>0 e\\<^sub>1 c r s) x;\n   c \\<in> caps_of s e\\<^sub>0; s \\<turnstile> e\\<^sub>0 \\<leftrightarrow> e\\<^sub>1\\<rbrakk>\n  \\<Longrightarrow> \\<exists>z.  s \\<turnstile> x \\<leftrightarrow>* z \\<and> grant_cap y \\<in>cap caps_of s z\"\n  apply (simp add: cap_in_caps_def)\n  apply clarsimp\n  apply (drule (2) caps_of_generalOp)\n  apply (fastforce simp: cap_in_caps_def)\n  done\n\nlemma take_cap_generalOp2:\n  \"\\<lbrakk>take_cap y \\<in>cap caps_of (generalOperation e\\<^sub>0 e\\<^sub>1 c r s) x;\n   c \\<in> caps_of s e\\<^sub>0; s \\<turnstile> e\\<^sub>0 \\<leftrightarrow> e\\<^sub>1\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in> tgs_connected s\"\n  apply (drule (2) take_cap_generalOp)\n  apply clarsimp\n  apply (subgoal_tac \"s \\<turnstile> z \\<leftrightarrow> y\")\n   apply (simp add: tgs_connected_def)\n  apply (simp add: directly_tgs_connected_def leak_def)\n  done\n\nlemma grant_cap_generalOp2:\n  \"\\<lbrakk>grant_cap y \\<in>cap caps_of (generalOperation e\\<^sub>0 e\\<^sub>1 c r s) x;\n   c \\<in> caps_of s e\\<^sub>0; s \\<turnstile> e\\<^sub>0 \\<leftrightarrow> e\\<^sub>1\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in> tgs_connected s\"\n  apply (drule (2) grant_cap_generalOp)\n  apply clarsimp\n  apply (subgoal_tac \"s \\<turnstile> z \\<leftrightarrow> y\")\n   apply (simp add: tgs_connected_def)\n  apply (simp add: directly_tgs_connected_def leak_def)\n  done\n\nlemma generalOp_directly_tgs_connected:\n \"\\<lbrakk>generalOperation e\\<^sub>0 e\\<^sub>1 c r s \\<turnstile> x \\<leftrightarrow> y;\n   c \\<in> caps_of s e\\<^sub>0; s \\<turnstile> e\\<^sub>0 \\<leftrightarrow> e\\<^sub>1\\<rbrakk>\n  \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow>* y\"\n  apply (simp add: directly_tgs_connected_def [where s=\"generalOperation e\\<^sub>0 e\\<^sub>1 c r s\"] leak_def)\n  apply safe\n       apply (rule tgs_connected_comm)\n       apply (drule (3) take_cap_generalOp2)\n      apply (drule (3) grant_cap_generalOp2)\n     apply (erule (2) shares_caps_of_generalOp)\n    apply (drule (3) take_cap_generalOp2)\n   apply (rule tgs_connected_comm)\n   apply (drule (3) grant_cap_generalOp2)\n  apply (erule (2) shares_caps_of_generalOp)\n  done\n\n\n\n(* results from general operation *)\n\nlemma create_legal_directly_tgs_connected:\n  \"legal (SysCreate e c\\<^sub>1 c\\<^sub>2) s \\<Longrightarrow> s  \\<turnstile> target c\\<^sub>1 \\<leftrightarrow> e\"\n  apply clarsimp\n  apply (rule directly_tgs_connected_comm)\n  apply (drule (1) create_caps_directly_tgs_connected)\n  apply (drule (1) store_caps_store_connected)\n  apply (drule (1) store_connected_directly_tgs_connected)\n  done\n\nlemma take_legal_directly_tgs_connected:\n  \"legal (SysTake e c\\<^sub>1 c\\<^sub>2 r) s \\<Longrightarrow> s  \\<turnstile> target c\\<^sub>1 \\<leftrightarrow> e\"\n  apply clarsimp\n  apply (rule directly_tgs_connected_comm)\n  apply (drule (2) take_caps_directly_tgs_connected)\n  done\n\nlemma grant_legal_directly_tgs_connected:\n  \"legal (SysGrant e c\\<^sub>1 c\\<^sub>2 r) s \\<Longrightarrow> s \\<turnstile> e \\<leftrightarrow> target c\\<^sub>1\"\n  apply clarsimp\n  apply (drule (2) grant_caps_directly_tgs_connected)\n  done\n\nlemma copy_legal_directly_tgs_connected:\n  \"legal (SysCopy e c\\<^sub>1 c\\<^sub>2 r) s \\<Longrightarrow> s \\<turnstile> e \\<leftrightarrow> target c\\<^sub>1\"\n  apply clarsimp\n  apply (drule (1) store_caps_store_connected)\n  apply (drule (1) store_connected_directly_tgs_connected)\n  done\n\nlemma caps_of_create:\n  \"\\<lbrakk>c' \\<in> caps_of (createOperation e c\\<^sub>1 c\\<^sub>2 s) x; legal (SysCreate e c\\<^sub>1 c\\<^sub>2) s\\<rbrakk>\n  \\<Longrightarrow> \\<exists>z. (x,z) \\<in> tgs_connected s \\<and> c' \\<in>cap caps_of s z\"\n  apply (frule create_legal_directly_tgs_connected)\n  apply (clarsimp simp: create_general)\n  apply (drule caps_of_make_entity2 [rotated], clarsimp)\n  apply (drule (1) caps_of_generalOp)\n   apply (drule (2) directly_tgs_connected_comm)\n  done\n\nlemma caps_of_take:\n  \"\\<lbrakk>c' \\<in> caps_of (takeOperation e c\\<^sub>1 c\\<^sub>2 r s) x; legal (SysTake e c\\<^sub>1 c\\<^sub>2 r) s\\<rbrakk>\n  \\<Longrightarrow> \\<exists>z. (x,z) \\<in> tgs_connected s \\<and> c' \\<in>cap caps_of s z\"\n  apply (frule take_legal_directly_tgs_connected)\n  apply (clarsimp simp: take_general)\n  apply (drule (2) caps_of_generalOp)\n   apply (drule (1) directly_tgs_connected_comm)\n  done\n\nlemma caps_of_grant:\n  \"\\<lbrakk>c' \\<in> caps_of (grantOperation e c\\<^sub>1 c\\<^sub>2 r s) x; legal (SysGrant e c\\<^sub>1 c\\<^sub>2 r) s\\<rbrakk>\n  \\<Longrightarrow> \\<exists>z. (x,z) \\<in> tgs_connected s \\<and> c' \\<in>cap caps_of s z\"\n  apply (frule grant_legal_directly_tgs_connected)\n  apply (clarsimp simp: grant_general)\n  apply (drule (2) caps_of_generalOp)\n   apply (drule (1) directly_tgs_connected_comm)\n  done\n\nlemma caps_of_copy:\n  \"\\<lbrakk>c' \\<in> caps_of (copyOperation e c\\<^sub>1 c\\<^sub>2 r s) x; legal (SysCopy e c\\<^sub>1 c\\<^sub>2 r) s\\<rbrakk>\n  \\<Longrightarrow> \\<exists>z. (x,z) \\<in> tgs_connected s \\<and> c' \\<in>cap caps_of s z\"\n  apply (frule copy_legal_directly_tgs_connected)\n  apply (clarsimp simp: copy_general)\n  apply (drule (2) caps_of_generalOp)\n   apply (drule (1) directly_tgs_connected_comm)\n  done\n\nlemma create_directly_tgs_connected:\n \"\\<lbrakk>createOperation e c\\<^sub>1 c\\<^sub>2 s \\<turnstile> x \\<leftrightarrow> y; legal (SysCreate e c\\<^sub>1 c\\<^sub>2) s\\<rbrakk>\n  \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow>* y\"\n  apply (frule create_legal_directly_tgs_connected)\n  apply (clarsimp simp: create_general)\n  apply (drule directly_tgs_connected_make_entity2 [rotated], clarsimp)\n  apply (drule (1) generalOp_directly_tgs_connected)\n   apply (drule (2) directly_tgs_connected_comm)\n  done\n\nlemma take_directly_tgs_connected:\n \"\\<lbrakk>takeOperation e c\\<^sub>1 c\\<^sub>2 r s \\<turnstile> x \\<leftrightarrow> y; legal (SysTake e c\\<^sub>1 c\\<^sub>2 r) s\\<rbrakk>\n  \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow>* y\"\n  apply (frule take_legal_directly_tgs_connected)\n  apply (clarsimp simp: take_general)\n  apply (drule (3) generalOp_directly_tgs_connected)\n  done\n\nlemma grant_directly_tgs_connected:\n \"\\<lbrakk>grantOperation e c\\<^sub>1 c\\<^sub>2 r s \\<turnstile> x \\<leftrightarrow> y; legal (SysGrant e c\\<^sub>1 c\\<^sub>2 r) s\\<rbrakk>\n  \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow>* y\"\n  apply (frule grant_legal_directly_tgs_connected)\n  apply (clarsimp simp: grant_general)\n  apply (drule (3) generalOp_directly_tgs_connected)\n  done\n\nlemma copy_directly_tgs_connected:\n \"\\<lbrakk>copyOperation e c\\<^sub>1 c\\<^sub>2 r s \\<turnstile> x \\<leftrightarrow> y; legal (SysCopy e c\\<^sub>1 c\\<^sub>2 r) s\\<rbrakk>\n  \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow>* y\"\n  apply (frule copy_legal_directly_tgs_connected)\n  apply (clarsimp simp: copy_general)\n  apply (drule (3) generalOp_directly_tgs_connected)\n  done\n\n\n\nlemma create_conTrans:\n  \"\\<lbrakk>s' \\<in> step cmd s; (x, y) \\<in> directly_tgs_connected s'; cmd = (SysCreate e c\\<^sub>1 c\\<^sub>2)\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in> tgs_connected s\"\n  apply(clarsimp simp: step_def split: if_split_asm)\n   apply (erule disjE, fastforce simp: tgs_connected_def, clarsimp)\n   apply (drule create_directly_tgs_connected, clarsimp, assumption)\n  apply (simp add: tgs_connected_def)\n  done\n\nlemma take_conTrans:\n  \"\\<lbrakk>s' \\<in> step cmd s; (x, y) \\<in> directly_tgs_connected s'; cmd = (SysTake e c\\<^sub>1 c\\<^sub>2 r)\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in> tgs_connected s\"\n  apply(clarsimp simp: step_def split: if_split_asm)\n   apply (erule disjE, fastforce simp: tgs_connected_def, clarsimp)\n   apply (drule take_directly_tgs_connected, clarsimp, assumption)\n  apply (simp add: tgs_connected_def)\n  done\n\nlemma grant_conTrans:\n  \"\\<lbrakk>s' \\<in> step cmd s; (x, y) \\<in> directly_tgs_connected s'; cmd = (SysGrant e c\\<^sub>1 c\\<^sub>2 r)\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in> tgs_connected s\"\n  apply(clarsimp simp: step_def split: if_split_asm)\n   apply (erule disjE, fastforce simp: tgs_connected_def, clarsimp)\n   apply (drule grant_directly_tgs_connected, clarsimp, assumption)\n  apply (simp add: tgs_connected_def)\n  done\n\nlemma copy_conTrans:\n  \"\\<lbrakk>s' \\<in> step cmd s; (x, y) \\<in> directly_tgs_connected s'; cmd = (SysCopy e c\\<^sub>1 c\\<^sub>2 r)\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in> tgs_connected s\"\n  apply(clarsimp simp: step_def split: if_split_asm)\n   apply (erule disjE, fastforce simp: tgs_connected_def, clarsimp)\n   apply (drule copy_directly_tgs_connected, clarsimp, assumption)\n  apply (simp add: tgs_connected_def)\n  done\n\n(* Lemmas about destroy *)\n\nlemma direct_caps_of_destroy:\n  \"c \\<in> direct_caps_of (s(e := None)) x \\<Longrightarrow> c \\<in> direct_caps_of s x\"\n  by (simp add: direct_caps_of_def split: option.splits split: if_split_asm)\n\nlemma store_connected_destroy:\n \"(x, y) \\<in> store_connected (s(e := None)) \\<Longrightarrow> (x, y) \\<in> store_connected s\"\n  apply (simp add: store_connected_def)\n  apply (erule rtrancl_induct)\n   apply simp\n  apply (fold store_connected_def)\n  apply (subgoal_tac \"(y,z) \\<in> store_connected_direct s\")\n   apply (fastforce simp: store_connected_def)\n  apply (simp add: store_connected_direct_def)\n  apply clarsimp\n  by (metis direct_caps_of_destroy)\n\nlemma shares_caps_destroy:\n  \"shares_caps (destroyOperation e c s) x y\n  \\<Longrightarrow> shares_caps s x y\"\n  apply (clarsimp simp: shares_caps_def destroyOperation_def)\n  apply (frule store_connected_destroy [where x=x])\n  apply (drule store_connected_destroy [where x=y])\n  by auto\n\nlemma caps_of_destroy:\n  \"c \\<in> caps_of (destroyOperation e' c' s) e \\<Longrightarrow>\n  c \\<in> caps_of s e\"\n  apply (clarsimp simp add: destroyOperation_def caps_of_def)\n  apply (rule_tac x=x in exI)\n  apply (drule direct_caps_of_destroy)\n  apply simp\n  apply (erule store_connected_destroy)\n  done\n\nlemma destroy_directly_tgs_connected:\n  \"\\<lbrakk>s' \\<in> step (SysDestroy e c) s; (x, y) \\<in> directly_tgs_connected s'\\<rbrakk> \\<Longrightarrow>\n  (x, y) \\<in> directly_tgs_connected s\"\n  apply(clarsimp simp: step_def split: if_split_asm)\n  apply(erule disjE, simp)\n  apply(simp add: directly_tgs_connected_def leak_def)\n  apply (erule disjE)\n   apply(fastforce simp add: cap_in_caps_def dest!: caps_of_destroy)\n  apply (erule disjE)\n   apply(fastforce simp add: cap_in_caps_def dest!: caps_of_destroy)\n  apply (erule disjE)\n   apply (drule shares_caps_destroy, simp)\n  apply (erule disjE)\n   apply(fastforce simp add: cap_in_caps_def dest!: caps_of_destroy)\n  apply (erule disjE)\n   apply(fastforce simp add: cap_in_caps_def dest!: caps_of_destroy)\n  apply (drule shares_caps_destroy, simp)\n  done\n\nlemma destroy_conTrans:\n  \"\\<lbrakk>s' \\<in> step cmd s; (x, y) \\<in> directly_tgs_connected s'; cmd = (SysDestroy e c)\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in>  directly_tgs_connected s\"\n  by(auto dest!: destroy_directly_tgs_connected)\n\n\n(* lemmas about remove *)\n\nlemma direct_caps_of_remove:\n  \"c \\<in> direct_caps_of (removeOperation e c\\<^sub>1 c\\<^sub>2 s) x \\<Longrightarrow>\n  c \\<in> direct_caps_of s x\"\n  by (clarsimp simp: removeOperation_simpler direct_caps_of_def\n              split: option.splits if_split_asm)\n\nlemma direct_caps_of_remove_eq:\n  \"direct_caps_of (removeOperation e c\\<^sub>1 c\\<^sub>2 s) x =\n  ( if   is_entity s (target c\\<^sub>1) \\<and> x = target c\\<^sub>1\n   then  direct_caps_of s (target c\\<^sub>1) - {c\\<^sub>2}\n   else  direct_caps_of s x )\"\n  by(simp add: direct_caps_of_def is_entity_def removeOperation_def)\n\nlemma store_connected_remove [rule_format]:\n  \"(x, y) \\<in> store_connected (s(e \\<mapsto> Entity C')) \\<Longrightarrow>\n  s e = Some (Entity C) \\<longrightarrow> C' \\<subseteq> C \\<longrightarrow> (x, y) \\<in> store_connected s\"\n  apply (unfold store_connected_def)\n  apply (erule rtrancl_induct)\n   apply simp\n  apply clarsimp\n  apply (subgoal_tac \"(y,z) \\<in> store_connected_direct s\")\n   apply (erule rtrancl_trans)\n   apply fastforce\n  apply (fold store_connected_def)\n  apply (clarsimp simp add: store_connected_direct_def)\n  apply (fastforce simp: direct_caps_of_def\n                  split: option.splits if_split_asm)\n  done\n\nlemma caps_of_remove:\n  \"c \\<in> caps_of (removeOperation e c\\<^sub>1 c\\<^sub>2 s) x \\<Longrightarrow>\n  c \\<in> caps_of s x\"\n  apply (clarsimp simp: caps_of_def)\n  apply (rule_tac x=xa in exI)\n  apply (drule direct_caps_of_remove)\n  apply (simp add: removeOperation_simpler\n            split: option.splits)\n  apply (erule (1) store_connected_remove)\n  apply blast\n  done\n\n(* Might equal either  \"caps s (target c\\<^sub>1) - {c\\<^sub>2}\" or \"caps s x\" depending if the caps are duplicated.*)\nlemma caps_of_remove2:\n  \"caps_of (removeOperation e c\\<^sub>1 c\\<^sub>2 s) x \\<subseteq> caps_of s x\"\n  apply(simp add: caps_of_def is_entity_def removeOperation_def direct_caps_of_def)\n  apply (clarsimp split: if_split_asm)\n   apply (auto dest!: store_connected_remove)\n  done\n\nlemma shares_caps_remove:\n  \"shares_caps (removeOperation e c\\<^sub>1 c\\<^sub>2 s) x y\n  \\<Longrightarrow> shares_caps s x y\"\n  apply (clarsimp simp: shares_caps_def removeOperation_simpler\n                 split:option.splits)\n  apply (frule (1) store_connected_remove [where x=x], clarsimp)\n  apply (drule (1) store_connected_remove [where x=y], clarsimp)\n  by auto\n\nlemma remove_directly_tgs_connected:\n  \"\\<lbrakk>s' \\<in> step (SysRemove e c\\<^sub>1 c\\<^sub>2) s; (x, y) \\<in> directly_tgs_connected s'\\<rbrakk> \\<Longrightarrow>\n  (x, y) \\<in> directly_tgs_connected s\"\n  apply(simp add: step_def split: if_split_asm)\n  apply(erule disjE, simp)\n  apply(simp add: directly_tgs_connected_def leak_def)\n  apply(simp add: cap_in_caps_def)\n  apply(clarsimp)\n  apply safe\n     prefer 3\n     apply (drule shares_caps_remove, simp)\n    prefer 5\n    apply (drule shares_caps_remove, simp)\n   apply(auto dest!: caps_of_remove)\n  done\n\nlemma remove_conTrans:\n  \"\\<lbrakk>s' \\<in> step cmd s; (x, y) \\<in> directly_tgs_connected s'; cmd = (SysRemove e c\\<^sub>1 c\\<^sub>2)\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in>  directly_tgs_connected s\"\n  by(auto dest!: remove_directly_tgs_connected)\n\nlemma direct_caps_of_removeSet:\n  \"c' \\<in> direct_caps_of (removeSetOperation e c C s) x \\<Longrightarrow>\n  c' \\<in> direct_caps_of s x\"\n  by (clarsimp simp: removeSetOperation_simpler direct_caps_of_def\n              split: option.splits if_split_asm)\n\nlemma caps_of_removeSet:\n  \"c' \\<in> caps_of (removeSetOperation e c C s) x \\<Longrightarrow>\n  c' \\<in> caps_of s x\"\n  apply (clarsimp simp: caps_of_def)\n  apply (rule_tac x=xa in exI)\n  apply (drule direct_caps_of_removeSet)\n  apply (simp add: removeSetOperation_simpler split: option.splits)\n  apply (erule (1) store_connected_remove)\n  apply blast\n  done\n\nlemma shares_caps_removeSet:\n  \"shares_caps (removeSetOperation e c C s) x y\n  \\<Longrightarrow> shares_caps s x y\"\n  apply (clarsimp simp: shares_caps_def removeSetOperation_simpler split:option.splits)\n  apply (frule (1) store_connected_remove [where x=x], clarsimp)\n  apply (drule (1) store_connected_remove [where x=y], clarsimp)\n  by auto\n\nlemma removeSet_connected:\n  \" \\<lbrakk>s' \\<in> step (SysRemoveSet e c C) s; s' \\<turnstile> x \\<leftrightarrow> y\\<rbrakk> \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow> y\"\n  apply(simp add: step_def split: if_split_asm)\n  apply(erule disjE, simp)\n  apply(simp add: directly_tgs_connected_def leak_def)\n  apply(simp add: cap_in_caps_def)\n  apply(clarsimp)\n  apply safe\n     prefer 3\n     apply (drule shares_caps_removeSet, simp)\n    prefer 5\n    apply (drule shares_caps_removeSet, simp)\n   apply (auto dest!: caps_of_removeSet)\n  done\n\nlemma removeSet_conTrans:\n  \"\\<lbrakk>s' \\<in> step cmd s; s' \\<turnstile> x \\<leftrightarrow> y; cmd = (SysRemoveSet n c C)\\<rbrakk>\n  \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow> y\"\n  by(auto dest!: removeSet_connected)\n\n(* lemmas about revoke *)\nlemma direct_caps_of_removeSetOfCaps:\n  \"c' \\<in> direct_caps_of (removeSetOfCaps cap_map s) x \\<Longrightarrow>\n  c' \\<in> direct_caps_of s x\"\n  by (clarsimp simp: removeSetOfCaps_def direct_caps_of_def\n              split: option.splits if_split_asm)\nthm store_connected_remove\n\nlemma store_connected_removeSetOfCaps:\n  \"(x, y) \\<in> store_connected (\\<lambda>e. if is_entity s e\n                                 then Some (Entity (direct_caps_of s e - cap_map e))\n                                 else None) \\<Longrightarrow>\n    (x, y) \\<in> store_connected s\"\n  apply (unfold store_connected_def)\n  apply (erule rtrancl_induct)\n   apply simp\n  apply (subgoal_tac \"(y,z) \\<in> store_connected_direct s\")\n   apply (erule rtrancl_trans)\n   apply fastforce\n  apply (fold store_connected_def)\n  apply (clarsimp simp add: store_connected_direct_def)\n  apply (fastforce simp: direct_caps_of_def\n                  split: option.splits if_split_asm)\n  done\n\nlemma caps_of_removeSetOfCaps:\n  \"c' \\<in> caps_of (removeSetOfCaps cap_map s) x \\<Longrightarrow>\n  c' \\<in> caps_of s x\"\n  apply (clarsimp simp: caps_of_def)\n  apply (rule_tac x=xa in exI)\n  apply (drule direct_caps_of_removeSetOfCaps)\n  apply (simp add: removeSetOfCaps_def split: option.splits)\n  apply (erule store_connected_removeSetOfCaps)\n  done\n\nlemma caps_of_revoke:\n  \"\\<lbrakk>s' \\<in> revokeOperation sub c\\<^sub>1 s ;  c \\<in> caps_of s' e \\<rbrakk>\n  \\<Longrightarrow> c \\<in> caps_of s e\"\n  apply (clarsimp simp: revokeOperation_def\n                 split: if_split_asm)\n  apply (drule (1) caps_of_removeSetOfCaps)\n  done\n\nlemma direct_caps_of_revoke:\n  \"\\<lbrakk>s' \\<in> revokeOperation e c s; c' \\<in> direct_caps_of s' x\\<rbrakk>\n   \\<Longrightarrow> c' \\<in> direct_caps_of s x\"\n  apply (clarsimp simp: revokeOperation_def\n                 split: if_split_asm)\n  apply (drule (1) direct_caps_of_removeSetOfCaps)\n  done\n\nlemma store_connected_revoke:\n \"\\<lbrakk>(x, y) \\<in> store_connected s'; s' \\<in> revokeOperation e c s\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in> store_connected s\"\n  apply (simp add: store_connected_def)\n  apply (erule rtrancl_induct)\n   apply simp\n  apply (fold store_connected_def)\n  apply (subgoal_tac \"(y,z) \\<in> store_connected_direct s\")\n   apply (fastforce simp: store_connected_def)\n  apply (clarsimp simp: store_connected_direct_def)\n  apply (metis direct_caps_of_revoke)\n  done\n\nlemma shares_caps_revoke:\n  \"\\<lbrakk>shares_caps s' x y; s' \\<in> revokeOperation e c s\\<rbrakk>\n  \\<Longrightarrow> shares_caps s x y\"\n  apply (clarsimp simp: shares_caps_def)\n  apply (frule (1) store_connected_revoke [where x=x])\n  apply (drule (1) store_connected_revoke [where x=y])\n  by auto\n\nlemma removeOperation_entity_ids [simp]:\n  \"is_entity (removeOperation e c c' s) e' = is_entity s e'\"\n  by (simp add: is_entity_def removeOperation_def)\n\nlemma removeSetOfCaps_entity_ids [simp]:\n  \"is_entity (removeSetOfCaps cap_map s) e' = is_entity s e'\"\n  by (simp add: is_entity_def removeSetOfCaps_def)\n\nlemma revoke_entities:\n  \"s' \\<in> revokeOperation sub c\\<^sub>1 s \\<Longrightarrow> is_entity s' e = is_entity s e\"\n  by (clarsimp simp: revokeOperation_def split: if_split_asm)\n\nlemma revoke_directly_tgs_connected:\n  \"\\<lbrakk>s' \\<in> step (SysRevoke n c\\<^sub>1) s; (x, y) \\<in> directly_tgs_connected s'\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in>  directly_tgs_connected s\"\n  apply (simp add: step_def split: if_split_asm)\n  apply (erule disjE, simp)\n  apply (simp add: directly_tgs_connected_def leak_def)\n  apply (erule disjE)\n   apply(auto simp add: cap_in_caps_def dest!: caps_of_revoke)[1]\n  apply (erule disjE)\n   apply(auto simp add: cap_in_caps_def dest!: caps_of_revoke)[1]\n  apply (erule disjE)\n   apply (drule (1) shares_caps_revoke, simp)\n  apply (erule disjE)\n   apply(auto simp add: cap_in_caps_def dest!: caps_of_revoke)[1]\n  apply (erule disjE)\n   apply(auto simp add: cap_in_caps_def dest!: caps_of_revoke)[1]\n  apply (drule (1) shares_caps_revoke, simp)\n  done\n\nlemma revoke_conTrans:\n  \"\\<lbrakk>s' \\<in> step cmd s; (x, y) \\<in> directly_tgs_connected s'; cmd = (SysRevoke n c\\<^sub>1)\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in>  directly_tgs_connected s\"\n  by(auto dest!: revoke_directly_tgs_connected)\n\n\n\n(* lemmas about grant *)\n\nlemma is_entity_grant [simp]:\n  \"is_entity s (target c\\<^sub>1) \\<Longrightarrow>\n  is_entity (grantOperation e c\\<^sub>1 c\\<^sub>2 r s) e' = is_entity s e'\"\n  by (simp add: is_entity_def grantOperation_def)\n\nlemma is_entity_destroy:\n  \"is_entity (destroyOperation e' c s) e \\<Longrightarrow> is_entity s e\"\n  by (simp add: destroyOperation_def is_entity_def split: if_split_asm)\n\n\n(********************************************\n ********************************************\n ***** Connected transitively preserved *****\n ********************************************\n ********************************************)\n\nlemma connected_tgs_connected:\n  \"\\<lbrakk>s' \\<in> step cmd s; (e\\<^sub>x, e\\<^sub>y) \\<in> directly_tgs_connected s'\\<rbrakk> \\<Longrightarrow>\n  (e\\<^sub>x, e\\<^sub>y) \\<in> tgs_connected s\"\n  apply(case_tac \"(e\\<^sub>x, e\\<^sub>y) \\<in> directly_tgs_connected s\")\n   apply(simp add: tgs_connected_def)\n   apply(case_tac cmd)\n         apply(rule create_conTrans, fastforce+)\n        apply(rule take_conTrans, fastforce+)\n       apply(rule grant_conTrans, fastforce+)\n      apply(frule copy_conTrans, fastforce+)\n     apply(frule remove_conTrans, fastforce+)\n    apply(frule removeSet_conTrans, fastforce+)\n   apply(frule revoke_conTrans, fastforce+)\n  apply(frule destroy_conTrans, fastforce+)\n  done\n\nlemma tgs_connected_preserved_step:\n  \"\\<lbrakk>s' \\<in> step cmd s; s' \\<turnstile> x \\<leftrightarrow>* z\\<rbrakk> \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow>* z\"\n  thm rtrancl_induct [where r=\"directly_tgs_connected s'\" and a=x and b=z and P=\"\\<lambda>z. (x, z) \\<in> (directly_tgs_connected s)\\<^sup>*\", simplified,\n                      simplified tgs_connected_def [symmetric]]\n  apply(erule rtrancl_induct [where r=\"directly_tgs_connected s'\",\n                              simplified tgs_connected_def [symmetric]], simp)\n  apply(case_tac \"s \\<turnstile> y \\<leftrightarrow>* z\")\n   apply (erule (1) tgs_connected_trans)\n  apply (simp add: connected_tgs_connected)\n  done\n\nlemma leakImplyConnected:\n  \"leak s\\<^sub>i e\\<^sub>x e\\<^sub>i \\<Longrightarrow> (e\\<^sub>x, e\\<^sub>i) \\<in> directly_tgs_connected s\\<^sub>i\"\n by(simp add: directly_tgs_connected_def)\n\nlemma leakImplyConnectedTrans:\n  \"leak s\\<^sub>i e\\<^sub>x e\\<^sub>i \\<Longrightarrow> (e\\<^sub>x, e\\<^sub>i) \\<in> tgs_connected s\\<^sub>i\"\n  by(simp add: tgs_connected_def, frule leakImplyConnected, auto)\n\n\nlemma tgs_connected_preserved [rule_format]:\n  \"\\<forall>s'. s' \\<in> execute cmds s \\<longrightarrow>\n    s' \\<turnstile> x \\<leftrightarrow>* y \\<longrightarrow>\n    s \\<turnstile> x \\<leftrightarrow>* y\"\n  apply(induct_tac cmds, simp)\n  apply clarsimp\n  apply(rename_tac cmd cmds s'' s')\n  apply(erule_tac x=s' in allE)\n  apply(simp add: tgs_connected_preserved_step)\n  done\n\nlemma leak_conTrans [rule_format]:\n  \"\\<lbrakk>s \\<in> execute cmds s\\<^sub>0; leak s x y\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in> tgs_connected s\\<^sub>0\"\n  by (auto intro: leakImplyConnectedTrans tgs_connected_preserved)\n\nlemma leakage_rule:\n  \"\\<lbrakk>s' \\<in> execute cmds s; \\<not> s \\<turnstile> x \\<leftrightarrow>* y\\<rbrakk> \\<Longrightarrow> \\<not> (s' \\<turnstile> x \\<rightarrow> y)\"\n  by(auto simp add: leak_conTrans)\n\n\n\n\n(*******************************************\n *******************************************\n *****      Authority confinement     *****\n *******************************************\n *******************************************)\n\nlemma caps_of_op:\n  \"\\<lbrakk>s' \\<in> step cmd s; c' \\<in> caps_of s' x\\<rbrakk>\n  \\<Longrightarrow> \\<exists>z. s \\<turnstile> x \\<leftrightarrow>* z \\<and> c' \\<in>cap caps_of s z\"\n  apply (simp add: step_def split:if_split_asm)\n   prefer 2\n   apply (fastforce simp: cap_in_caps_def tgs_connected_def rights_extra_rights)\n  apply (erule disjE)\n   apply (fastforce simp: cap_in_caps_def tgs_connected_def rights_extra_rights)\n  apply (case_tac cmd)\n         apply (simp add: caps_of_create)\n        apply (simp add: caps_of_take)\n       apply (simp add: caps_of_grant)\n      apply (simp add: caps_of_copy)\n     apply (clarsimp, drule caps_of_remove)\n     apply (fastforce simp: cap_in_caps_def tgs_connected_def rights_extra_rights)\n    apply (clarsimp, drule caps_of_removeSet)\n    apply (fastforce simp: cap_in_caps_def tgs_connected_def rights_extra_rights)\n   apply (clarsimp, drule (1) caps_of_revoke)\n   apply (fastforce simp: cap_in_caps_def tgs_connected_def rights_extra_rights)\n  apply (clarsimp, drule caps_of_destroy)\n  apply (fastforce simp: cap_in_caps_def tgs_connected_def rights_extra_rights)\n  done\n\nlemma authority_confinement_induct_step:\n  \"\\<lbrakk>s' \\<in> step cmd s;\n    \\<forall>e\\<^sub>i. s \\<turnstile> e\\<^sub>x \\<leftrightarrow>* e\\<^sub>i \\<longrightarrow> caps_of s e\\<^sub>i \\<le>cap c\\<rbrakk>\n  \\<Longrightarrow> caps_of s' e\\<^sub>x \\<le>cap c\"\n  apply (clarsimp simp: caps_dominated_by_def)\n  apply (drule (1) caps_of_op)\n  apply (fastforce simp: cap_in_caps_def)\n  done\n\nlemma authority_confinement_helper:\n  \"s' \\<in> execute cmds s \\<longrightarrow>\n   (\\<forall>e\\<^sub>i. s \\<turnstile> e\\<^sub>x \\<leftrightarrow>* e\\<^sub>i \\<longrightarrow> caps_of s e\\<^sub>i \\<le>cap c) \\<longrightarrow>\n   (\\<forall>e\\<^sub>i. s' \\<turnstile> e\\<^sub>x \\<leftrightarrow>* e\\<^sub>i \\<longrightarrow> caps_of s' e\\<^sub>i \\<le>cap c)\"\nproof (induct cmds arbitrary: s')\ncase Nil\n  show ?case by clarsimp\nnext\ncase (Cons cmd cmds s')\nshow ?case\n  apply clarsimp\n  apply (rule authority_confinement_induct_step, assumption)\n  apply clarsimp\n  apply (rule Cons.hyps[rule_format], simp_all)\n  apply (drule(1) tgs_connected_preserved_step)\n  apply (simp add: tgs_connected_def)\n  done\nqed\n\nlemma authority_confinement:\n  \"\\<lbrakk>s' \\<in> execute cmds s;\n    \\<forall>e\\<^sub>i. s \\<turnstile> e\\<^sub>x \\<leftrightarrow>* e\\<^sub>i \\<longrightarrow> caps_of s e\\<^sub>i \\<le>cap c\\<rbrakk>\n  \\<Longrightarrow> caps_of s' e\\<^sub>x \\<le>cap c\"\n  by (erule authority_confinement_helper [rule_format, where e\\<^sub>x=e\\<^sub>x], simp_all)\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/l4v/spec/take-grant/Confine_S.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6757646140788307, "lm_q2_score": 0.399811640739795, "lm_q1q2_score": 0.2701785591087517}}
{"text": "theory proof_state_facts\nimports program_proof_rules_loops\nbegin\n\n\nlemma ps_wellFormed_to_wf:\n  assumes wf: \"proof_state_wellFormed S\"\n  obtains CS where \"proof_state_rel S CS\" and \"state_wellFormed CS\"\n  using local.wf proof_state_rel_wf proof_state_wellFormed_def by blast\n\n\nlemma ps_wellFormed_state_causality:\n  assumes wf: \"proof_state_wellFormed S\"\n  shows \"causallyConsistent (happensBefore S) (ps_vis S)\"\n  by (smt FieldI1 FieldI2 Un_iff causallyConsistent_def disjoint_iff_not_equal local.wf proof_state_rel_facts(1) proof_state_rel_hb proof_state_rel_vis proof_state_wellFormed_def proof_state_wellFormed_disjoint_happensBefore_localCalls updateHb_simp2 wf_vis_downwards_closed2)\n\n\nlemma ps_wellFormed_state_hb_trans:\n  assumes wf: \"proof_state_wellFormed S\"\n  shows \"trans (happensBefore S)\"\n  by (smt FieldI2 disjoint_iff_not_equal happensBefore_transitive local.wf proof_state_rel_facts(1) proof_state_rel_hb proof_state_wellFormed_def proof_state_wellFormed_disjoint_happensBefore_localCalls trans_def updateHb_simp2)\n\nlemma ps_localCalls_no_origin:\n  assumes wf: \"proof_state_wellFormed S\"\n    and \"c \\<in> set (ps_localCalls S)\"\n  shows \"callOrigin S c = None\"\n  by (meson assms(2) disjoint_iff_not_equal domIff local.wf proof_state_rel_callOrigin_localCalls_disjoint ps_wellFormed_to_wf)\n\nlemma ps_not_localCalls_not_tx:\n  assumes wf: \"proof_state_wellFormed S\"\n    and \"c \\<notin> set (ps_localCalls S)\"\n    and \"ps_tx S \\<triangleq> tx\"\n  shows \"callOrigin S c \\<noteq> Some tx\"\n  by (metis (mono_tags, lifting) assms(2) assms(3) local.wf map_update_all_get mem_Collect_eq option.simps(5) proof_state_rel_callOrigin proof_state_rel_localCalls ps_wellFormed_to_wf)\n\n\nlemma rel_callOrigin_vis:\n  assumes rel: \"proof_state_rel S CS\"\n    and \"c \\<in> ps_vis S\"\n  shows \"callOrigin CS c = callOrigin S c\" \nproof -\n  have co: \"callOrigin CS = map_update_all (callOrigin S) (ps_localCalls S) (the (ps_tx S))\"\n    using proof_state_rel_def rel by blast\n  show ?thesis\n    using `c \\<in> ps_vis S`\n    by (metis Set.set_insert co disjoint_insert(1) map_update_all_get proof_state_rel_vis_localCalls_disjoint rel)\nqed\n\nlemma rel_callOrigin_ls:\n  assumes rel: \"proof_state_rel S CS\"\n    and \"c \\<in> set (ps_localCalls S)\"\n  shows \"callOrigin CS c = ps_tx S\"\n  using assms(2) map_update_all_Some_same proof_state_rel_callOrigin proof_state_wellFormed_localCalls rel show_proof_state_wellFormed by fastforce \n\nlemma rel_callOrigin_ls_rev:\n  assumes rel: \"proof_state_rel S CS\"\n    and \"callOrigin CS c \\<triangleq> tx\"\n    and \"ps_tx S \\<triangleq> tx\"\n  shows \"c \\<in> set (ps_localCalls S)\"\n  by (metis (no_types, lifting) assms(2) assms(3) map_update_all_get proof_state_rel_callOrigin ps_not_localCalls_not_tx rel show_proof_state_wellFormed)\n\n\n\nlemma rel_callOrigin_vis2:\n  assumes  rel: \"proof_state_rel S CS\"\n    and sameOrigin: \"callOrigin S c = callOrigin S c'\"\n    and \\<open>c \\<in> ps_vis S\\<close>\n  shows \"callOrigin CS c = callOrigin CS c'\"\n  by (metis (no_types, lifting) assms(3) map_update_all_get option.distinct(1) proof_state_rel_callOrigin proof_state_rel_calls proof_state_rel_wf proof_state_wellFormed_vis_subset_calls' ps_localCalls_no_origin rel rel_callOrigin_vis sameOrigin show_proof_state_wellFormed wf_callOrigin_and_calls)\n\n\nlemma ps_wellFormed_state_transaction_consistent1:\n  assumes wf: \"proof_state_wellFormed S\"\n    and c_vis: \"c\\<in>ps_vis S\"\n    and sameOrigin: \"callOrigin S c = callOrigin S c'\"\n  shows \"c'\\<in>ps_vis S\"\nproof (rule ps_wellFormed_to_wf[OF wf])\n  fix CS\n  assume rel: \"proof_state_rel S CS\"\n    and CS_wf: \"state_wellFormed CS\"\n\n  have vis: \"visibleCalls CS (ps_i S) \\<triangleq> (ps_vis S \\<union> set (ps_localCalls S))\"\n    by (simp add: proof_state_rel_vis rel)\n\n  have \"c' \\<in> (ps_vis S \\<union> set (ps_localCalls S))\"\n    using CS_wf vis\n  proof (rule wellFormed_state_transaction_consistent(2))\n    show \"c \\<in> ps_vis S \\<union> set (ps_localCalls S)\"\n      by (simp add: c_vis)\n    show \"callOrigin CS c = callOrigin CS c'\"\n      by (smt CS_wf \\<open>c \\<in> ps_vis S \\<union> set (ps_localCalls S)\\<close> c_vis disjoint_iff_not_equal in_dom local.wf map_update_all_None map_update_all_get proof_state_rel_callOrigin proof_state_rel_vis_localCalls_disjoint ps_localCalls_no_origin rel sameOrigin vis wellFormed_callOrigin_dom wellFormed_visibleCallsSubsetCalls_h(2))\n  qed\n\n  show \"c' \\<in> ps_vis S\"\n    by (metis CS_wf UnE \\<open>c' \\<in> ps_vis S \\<union> set (ps_localCalls S)\\<close> c_vis local.wf ps_localCalls_no_origin rel rel_callOrigin_vis rel_callOrigin_vis2 sameOrigin vis wellFormed_callOrigin_dom3 wellFormed_visibleCallsSubsetCalls2)\n\nqed\n\n\nlemma rel_callOrigin_different:\n  assumes a0: \"callOrigin S x \\<noteq> callOrigin S y\"\n    and wf: \"proof_state_wellFormed S\"\n    and rel: \"proof_state_rel S CS\"\n  shows \"callOrigin CS x \\<noteq> callOrigin CS y\"\n  by (smt a0 empty_iff empty_set local.wf map_update_all_get option.exhaust_sel proof_state_rel_callOrigin proof_state_wellFormed_localCalls ps_localCalls_no_origin ps_not_localCalls_not_tx rel)\n\nlemma rel_callOrigin_same:\n  assumes \"callOrigin S x \\<triangleq> xtx\"\n    and a1: \"callOrigin S x = callOrigin S x'\"\n    and  wf: \"proof_state_wellFormed S\"\n    and rel: \"proof_state_rel S CS\"\n  shows \"callOrigin CS x = callOrigin CS x'\"\n  by (metis (no_types, lifting) \\<open>callOrigin S x \\<triangleq> xtx\\<close> a1 local.wf map_update_all_get option.simps(3) proof_state_rel_callOrigin ps_localCalls_no_origin rel)\n\nlemma rel_noCallOrigin_noHappensBefore:\n  assumes \"callOrigin S x = None\"\n    and rel: \"proof_state_rel S CS\"\n    and  wf: \"proof_state_wellFormed S\"\n  shows \"(x,y) \\<notin> happensBefore S\"\n  by (metis (no_types, lifting) FieldI1 assms(1) disjoint_iff_not_equal domIff local.wf map_update_all_None proof_state_rel_calls proof_state_rel_facts(4) proof_state_rel_happensBefore_localCalls_disjoint proof_state_rel_wf proof_state_wellFormed_happensBefore_subset_calls rel subsetD wellFormed_callOrigin_dom)\n\nlemma rel_noCallOrigin_noHappensBefore_r:\n  assumes \"callOrigin S x = None\"\n    and rel: \"proof_state_rel S CS\"\n    and  wf: \"proof_state_wellFormed S\"\n  shows \"(y,x) \\<notin> happensBefore S\"\n  by (metis (no_types, lifting) FieldI2 assms(1) disjoint_iff_not_equal domIff local.wf map_update_all_None proof_state_rel_calls proof_state_rel_facts(4) proof_state_rel_wf proof_state_wellFormed_disjoint_happensBefore_localCalls proof_state_wellFormed_happensBefore_subset_calls rel subsetD wellFormed_callOrigin_dom)\n\n\nlemma ps_wellFormed_state_transaction_consistent_hb:\n  assumes wf: \"proof_state_wellFormed S\"\n    and a0: \"callOrigin S x \\<noteq> callOrigin S y\"\n    and a1: \"callOrigin S x = callOrigin S x'\"\n    and a2: \"callOrigin S y = callOrigin S y'\"\n  shows \"(x,y) \\<in> happensBefore S \\<longleftrightarrow> (x', y') \\<in> happensBefore S\"\nproof (rule ps_wellFormed_to_wf[OF wf])\n  fix CS\n  assume  rel: \"proof_state_rel S CS\"\n    and CS_wf: \"state_wellFormed CS\"\n\n  {\n    fix xtx ytx\n    assume \"callOrigin S x \\<triangleq> xtx\" \n      and \"callOrigin S y \\<triangleq> ytx\"\n\n\n    have \"((x, y) \\<in> happensBefore CS) = ((x', y') \\<in> happensBefore CS)\"\n      using CS_wf\n    proof (rule wellFormed_state_transaction_consistent(3))\n      show \"callOrigin CS x \\<noteq> callOrigin CS y\"\n        using a0 local.wf rel rel_callOrigin_different by blast\n      show \"callOrigin CS x = callOrigin CS x'\"\n        using \\<open>callOrigin S x \\<triangleq> xtx\\<close> a1 local.wf rel rel_callOrigin_same by blast\n      show \"callOrigin CS y = callOrigin CS y'\"\n        using \\<open>callOrigin S y \\<triangleq> ytx\\<close> a2 local.wf rel rel_callOrigin_same by blast\n    qed\n\n\n    hence \"((x, y) \\<in> happensBefore S) \\<longleftrightarrow> ((x', y') \\<in> happensBefore S)\"\n      by (metis \\<open>callOrigin S y \\<triangleq> ytx\\<close> a2 local.wf option.simps(3) proof_state_rel_hb ps_localCalls_no_origin rel updateHb_simp2)\n  }\n  moreover\n  {\n    assume \"callOrigin S x = None\" \n    hence \"(x,y) \\<notin> happensBefore S\"\n      using local.wf rel rel_noCallOrigin_noHappensBefore by blast\n    have \"callOrigin S x' = None\"\n      using \\<open>callOrigin S x = None\\<close> a1 by auto \n    hence \"(x',y') \\<notin> happensBefore S\"\n      using local.wf rel rel_noCallOrigin_noHappensBefore by blast\n    hence \"((x, y) \\<in> happensBefore S) \\<longleftrightarrow> ((x', y') \\<in> happensBefore S)\"\n      using \\<open>(x, y) \\<notin> happensBefore S\\<close> by blast\n  }\n  moreover\n  {\n    assume \"callOrigin S y = None\" \n    hence \"(x,y) \\<notin> happensBefore S\"\n      using local.wf rel rel_noCallOrigin_noHappensBefore_r by blast\n    have \"callOrigin S y' = None\"\n      using \\<open>callOrigin S y = None\\<close> a2 by auto \n    hence \"(x',y') \\<notin> happensBefore S\"\n      using local.wf rel rel_noCallOrigin_noHappensBefore_r by blast\n    hence \"((x, y) \\<in> happensBefore S) \\<longleftrightarrow> ((x', y') \\<in> happensBefore S)\"\n      using \\<open>(x, y) \\<notin> happensBefore S\\<close> by blast\n  }\n  ultimately show ?thesis\n    by blast\nqed\n\n\n\n\nlemma ps_wellFormed_state_consistent_snapshot:\nassumes wf: \"proof_state_wellFormed S\"\nassumes noTx: \"\\<And>c tx. ps_tx S \\<triangleq> tx \\<Longrightarrow> callOrigin S c \\<noteq> Some tx\" \nshows \"consistentSnapshotH (calls S) (happensBefore S) (callOrigin S) (\\<lambda>x. Some Committed) (ps_vis S)\"\n  by (simp add: local.wf proof_state_wellFormed_vis_subset_calls ps_wellFormed_state_causality ps_wellFormed_state_transaction_consistent1 show_consistentSnapshot show_transactionConsistent)\n\n\nlemma ps_wf_happensBefore_irrefl:\nassumes wf: \"proof_state_wellFormed S\"\nshows \"irrefl (happensBefore S)\"\n  by (metis (no_types, hide_lams) happensBefore_irrefl  irrefl_def local.wf proof_state_rel_hb ps_wellFormed_to_wf updateHb_simp_distinct2)\n\n\nlemma ps_wf_happensBefore_acyclic:\nassumes wf: \"proof_state_wellFormed S\"\nshows \"acyclic (happensBefore S)\"\n  by (simp add: acyclic_irrefl local.wf ps_wf_happensBefore_irrefl ps_wellFormed_state_hb_trans)\n\n\n\n\nlemma ps_wf_vis_downwards_closed:\n  assumes wf: \"proof_state_wellFormed S\"\n    and \"(x,y) \\<in> happensBefore S\"\n    and \"y\\<in>ps_vis S\"\n  shows \"x\\<in>ps_vis S\"\n  by (meson assms(2) assms(3) causallyConsistent_def local.wf ps_wellFormed_state_causality)\n\n\n\n\n\nlemma ps_wf_happensBefore_txns_left: \n  assumes wf: \"proof_state_wellFormed S\"\n  assumes \"(x,y) \\<in> happensBefore S\"\n    and \"callOrigin S x = callOrigin S x'\"\n    and \"callOrigin S x \\<noteq> callOrigin S y\"\n  shows \"(x',y) \\<in> happensBefore S\"\n  using assms(2) assms(3) assms(4) local.wf ps_wellFormed_state_transaction_consistent_hb by blast\n\n\n\n\nlemma causallyConsistent_downwards_closure:\nassumes wf: \"proof_state_wellFormed S\"\nshows \"causallyConsistent (happensBefore S) (cs \\<down> happensBefore S)\"\n  by (smt causallyConsistent_def downwardsClosure_in local.wf ps_wellFormed_state_hb_trans transD)\n\n\n\n\nlemma ps_wf_current_tx_not_before_others: \n  assumes wf: \"proof_state_wellFormed S\"\n    and \"ps_tx S \\<triangleq> tx\"\n    and \"callOrigin S x \\<triangleq> tx\"\n    and \"callOrigin S y \\<noteq> Some tx\"\n  shows \"(x,y) \\<notin> happensBefore S\"\n  by (meson assms(2) assms(3) domI domIff local.wf ps_localCalls_no_origin ps_not_localCalls_not_tx)\n\n\n\n(*\nlemma ps_i_callOriginI_notI1:\n  assumes \"proof_state_wellFormed S_pre\" \n    and \"invocOp S_pre i = None\" \n  shows \"i_callOriginI S_pre c \\<noteq> Some i\"\n\n  by (metis (no_types, lifting) assms(1) assms(2) i_callOriginI_h_def option.case_eq_if option.simps(3) proof_state_rel_invocOp proof_state_rel_txOrigin proof_state_rel_wf proof_state_wellFormed_def wf_no_invocation_no_origin)\n*)\n(*\nlemma ps_i_callOriginI_notI2:\n  assumes \"proof_state_wellFormed S_pre\" \n    and \"i_callOriginI S_pre c = Some i\" \n  shows \"invocOp S_pre i \\<noteq> None\"\n  using assms(1) assms(2) ps_i_callOriginI_notI1 by auto\n*)\n\nlemma ps_wellFormed_current_transaction_origin:     \n  assumes \"proof_state_wellFormed S\"\n    and \"ps_tx S \\<triangleq> tx\"\n  shows \"txOrigin S tx = None\"\n  using assms(1) assms(2) proof_state_rel_txOriginNone proof_state_wellFormed_def by blast\n\n\nlemma ps_wellFormed_ls_visibleCalls_callOrigin:     \n  assumes \"proof_state_wellFormed S\"\n    and \"callOrigin S c \\<triangleq> tx\"\n    and \"txOrigin S tx \\<triangleq> ps_i S\"\n  shows \"c \\<in> ps_vis S\"\n  by (metis assms(1) assms(2) assms(3) i_callOriginI_h_simp proof_state_rel_see_my_updates ps_wellFormed_to_wf)\n\n\n\n\nlemma ps_wf_queryspec:\n  assumes wf: \"proof_state_wellFormed S\"\n    and \"calls S c \\<triangleq> Call op r\"\n    and \"prevCalls = {c'. (c',c)\\<in>updateHb (happensBefore S) (ps_vis S) (ps_localCalls S)}\"\n    and \"ctxt = getContextH (calls S |` prevCalls) (updateHb (happensBefore S) (ps_vis S) (ps_localCalls S) |r prevCalls) (Some prevCalls)\"\n  shows \"querySpec (ps_prog S) op ctxt r\"\nproof (rule ps_wellFormed_to_wf[OF wf])\n  fix CS\n  assume rel: \"proof_state_rel S CS\"\n    and CS_wf: \"state_wellFormed CS\"\n\n  have \"querySpec (prog CS) op ctxt r\"\n    using CS_wf\n  proof (rule wf_queryspec)\n    show \"calls CS c \\<triangleq> Call op r\"\n      using assms(2) proof_state_rel_calls rel by fastforce\n    show \"prevCalls = {c'. (c', c) \\<in> happensBefore CS}\"\n      using assms(3) proof_state_rel_hb rel by force\n    show \"ctxt = getContextH (calls CS |` prevCalls) (happensBefore CS |r prevCalls) (Some prevCalls)\"\n      using assms(4) proof_state_rel_calls proof_state_rel_hb rel by fastforce\n  qed\n\n\n  thus \"querySpec (ps_prog S) op ctxt r\"\n    using proof_state_rel_prog rel by force\nqed\n  \nlemma ps_growing_no_localCalls1:\n  assumes \"ps_growing S S' t\"\n  shows \"ps_localCalls S = []\"\n  using assms  by (auto simp add: ps_growing_def)\n\nlemma ps_growing_no_localCalls2:\n  assumes \"ps_growing S S' t\"\n  shows \"ps_localCalls S' = []\"\n  using assms  by (auto simp add: ps_growing_def)\n\nlemma ps_growing_no_tx1:\n  assumes \"ps_growing S S' t\"\n  shows \"ps_tx S = None\"\n  using assms  by (auto simp add: ps_growing_def)\n\nlemma ps_growing_no_tx2:\n  assumes \"ps_growing S S' t\"\n  shows \"ps_tx S' \\<triangleq> t\"\n  using assms  by (auto simp add: ps_growing_def)\n\n\nlemma ps_growing_rule:\n  assumes \"ps_growing S S' t\"\n    and \"\\<And>CS CS'.\n       \\<lbrakk>proof_state_rel S CS; proof_state_rel S' CS';\n        state_monotonicGrowth (ps_i S) CS\n         (CS'\\<lparr>txStatus := (txStatus CS')(t := None),\n                txOrigin := (txOrigin CS')(t := None),\n                currentTx := (currentTx CS')(ps_i S := None),\n                localState := (localState CS')(ps_i S := localState CS (ps_i S)),\n                visibleCalls := (visibleCalls CS')(ps_i S := visibleCalls CS (ps_i S))\\<rparr>)\\<rbrakk>\n       \\<Longrightarrow> P\"\n  shows P\n  using assms by (auto simp add: ps_growing_def)\n\n\nlemma ps_monotonicGrowth_txOrigin_i:\n  assumes \"ps_growing S S' tx\"\n    and \"t \\<noteq> tx\"\n  shows \"txOrigin S' t \\<triangleq> ps_i S \\<longleftrightarrow> txOrigin S t \\<triangleq> ps_i S\"\n  using assms(1) proof (rule ps_growing_rule)\n  fix CS CS'\n  assume rel1: \"proof_state_rel S CS\"\n    and rel2: \"proof_state_rel S' CS'\"\n    and g: \"state_monotonicGrowth (ps_i S) CS          (CS'\\<lparr>txStatus := (txStatus CS')(tx := None),                 txOrigin := (txOrigin CS')(tx := None),                 currentTx := (currentTx CS')(ps_i S := None),                 localState := (localState CS')(ps_i S := localState CS (ps_i S)),                 visibleCalls := (visibleCalls CS')(ps_i S := visibleCalls CS (ps_i S))\\<rparr>)\"\n\n  from state_monotonicGrowth_txOrigin_i[OF g, where t=t, simplified]\n  have \"txOrigin CS' t \\<triangleq> ps_i S \\<longleftrightarrow> txOrigin CS t \\<triangleq> ps_i S\"\n    by (simp add: `t \\<noteq> tx`)\n\n  thus \"txOrigin S' t \\<triangleq> ps_i S = txOrigin S t \\<triangleq> ps_i S\"\n    unfolding proof_state_rel_txOrigin[OF rel1] proof_state_rel_txOrigin[OF rel2]\n    by (metis (no_types, lifting) assms(1) assms(2) fun_upd_other option.case_eq_if option.sel ps_growing_no_tx1 ps_growing_no_tx2)\nqed\n\n\nlemma ps_monotonicGrowth_no_new_calls_before_existing1:\n  assumes \"ps_growing S' S t\"\n    and \"c2\\<in>dom (calls S')\"\n    and \"ps_vis S' = ps_vis S\"\n  shows \"(c1,c2)\\<in>happensBefore S \\<longleftrightarrow> (c1,c2)\\<in>happensBefore S'\"\n  using assms(1) proof (rule ps_growing_rule)\n  fix CS CS'\n  assume rel1: \"proof_state_rel S' CS\"\n    and rel2: \"proof_state_rel S CS'\"\n    and g: \"state_monotonicGrowth (ps_i S') CS          (CS'\\<lparr>txStatus := (txStatus CS')(t := None),                 txOrigin := (txOrigin CS')(t := None),                 currentTx := (currentTx CS')(ps_i S' := None),                 localState := (localState CS')(ps_i S' := localState CS (ps_i S')),                 visibleCalls := (visibleCalls CS')(ps_i S' := visibleCalls CS (ps_i S'))\\<rparr>)\"\n\n  from state_monotonicGrowth_no_new_calls_before_existing1[OF g, simplified, of c2 c1]\n  have \"((c1, c2) \\<in> happensBefore CS') \\<longleftrightarrow> ((c1, c2) \\<in> happensBefore CS)\"\n    using assms(2) proof_state_rel_calls rel1 by fastforce\n\n  hence \"((c1, c2) \\<in> updateHb (happensBefore S) (ps_vis S) (ps_localCalls S)) \n    \\<longleftrightarrow>  ((c1, c2) \\<in> updateHb (happensBefore S') (ps_vis S') (ps_localCalls S'))\"\n    unfolding proof_state_rel_hb[OF rel1] proof_state_rel_hb[OF rel2] .\n\n  thus \"((c1, c2) \\<in> happensBefore S) = ((c1, c2) \\<in> happensBefore S')\"\n    by (metis assms(1) ps_growing_no_localCalls1 ps_growing_no_localCalls2 single_invocation_correctness.updateHb_nil)\nqed\n\nlemma ps_monotonicGrowth_no_new_calls_before_existing: \n  assumes \"ps_growing S' S t\"\n    and \"calls S' c = None\"\n    and \"calls S c \\<triangleq> x\"\n    and \"calls S' c' \\<triangleq> y\"\n  shows \"(c,c') \\<notin> happensBefore S'\"\n  using assms\n  by (meson FieldI1 domIff proof_state_wellFormed_happensBefore_subset_calls ps_growing_rule show_proof_state_wellFormed subset_h1)\n\n\nlemma ps_monotonicGrowth_txOrigin: \n  assumes \"ps_growing S' S tx\" \n    and \"txOrigin S' t \\<triangleq> i'\"\n    and \"tx \\<noteq> t\"\n  shows \"txOrigin S t \\<triangleq> i'\"\n  using assms(1) proof (rule ps_growing_rule)\n  fix CS CS'\n  assume rel1: \"proof_state_rel S' CS\"\n    and rel2: \"proof_state_rel S CS'\"\n    and g: \"state_monotonicGrowth (ps_i S') CS          (CS'\\<lparr>txStatus := (txStatus CS')(tx := None),                 txOrigin := (txOrigin CS')(tx := None),                 currentTx := (currentTx CS')(ps_i S' := None),                 localState := (localState CS')(ps_i S' := localState CS (ps_i S')),                 visibleCalls := (visibleCalls CS')(ps_i S' := visibleCalls CS (ps_i S'))\\<rparr>)\"\n\n  have \"txOrigin CS t \\<triangleq> i'\"\n    using assms(1) assms(2) proof_state_rel_txOrigin ps_growing_no_tx1 rel1 by fastforce\n\n\n  from state_monotonicGrowth_txOrigin[OF g `txOrigin CS t \\<triangleq> i'`]\n  have \"txOrigin CS' t \\<triangleq> i'\"\n    using assms(3) by auto\n\n\n  thus \"txOrigin S t \\<triangleq> i'\"\n    using assms(1) assms(3) proof_state_rel_txOrigin ps_growing_no_tx2 rel2 by fastforce\nqed\n\n\nlemma ps_monotonicGrowth_calls:\n  assumes \"ps_growing S' S tx\"\n    and \"calls S' c \\<triangleq> info\"\n  shows \"calls S c \\<triangleq> info\"\n  using assms(1) proof (rule ps_growing_rule)\n  fix CS CS'\n  assume rel1: \"proof_state_rel S' CS\"\n    and rel2: \"proof_state_rel S CS'\"\n    and g: \"state_monotonicGrowth (ps_i S') CS          (CS'\\<lparr>txStatus := (txStatus CS')(tx := None),                 txOrigin := (txOrigin CS')(tx := None),                 currentTx := (currentTx CS')(ps_i S' := None),                 localState := (localState CS')(ps_i S' := localState CS (ps_i S')),                 visibleCalls := (visibleCalls CS')(ps_i S' := visibleCalls CS (ps_i S'))\\<rparr>)\"\n\n  have \"calls CS c \\<triangleq> info\"\n    using assms(2) proof_state_rel_calls rel1 by force\n\n\n  from state_monotonicGrowth_calls[OF g `calls CS c \\<triangleq> info`]\n  show \"calls S c \\<triangleq> info\"\n    using proof_state_rel_calls rel2 by fastforce\nqed\n\nlemma ps_monotonicGrowth_happensBefore:\n  assumes \"ps_growing S' S tx\"\n  and \"c2\\<in>dom (calls S')\"\nshows \"((c1,c2)\\<in>happensBefore S \\<longleftrightarrow> (c1,c2)\\<in>happensBefore S')\"\n  using assms(1) proof (rule ps_growing_rule)\n  fix CS CS'\n  assume rel1: \"proof_state_rel S' CS\"\n    and rel2: \"proof_state_rel S CS'\"\n    and g: \"state_monotonicGrowth (ps_i S') CS          (CS'\\<lparr>txStatus := (txStatus CS')(tx := None),                 txOrigin := (txOrigin CS')(tx := None),                 currentTx := (currentTx CS')(ps_i S' := None),                 localState := (localState CS')(ps_i S' := localState CS (ps_i S')),                 visibleCalls := (visibleCalls CS')(ps_i S' := visibleCalls CS (ps_i S'))\\<rparr>)\"\n\n  have \"c2 \\<in> dom (calls CS)\"\n    using assms(2) proof_state_rel_calls rel1 by fastforce\n\n  have \"ps_localCalls S' = []\"\n    using assms(1) ps_growing_no_localCalls1 by blast\n\n\n  from state_monotonicGrowth_happensBefore[OF g `c2 \\<in> dom (calls CS)`, simplified]\n  have \"((c1, c2) \\<in> happensBefore CS') = ((c1, c2) \\<in> happensBefore CS)\" .\n\n  thus ?thesis\n    using \\<open>ps_localCalls S' = []\\<close> assms(1) proof_state_rel_facts(3) ps_growing_no_localCalls2 rel1 rel2 by fastforce\nqed\n\nlemma ps_monotonicGrowth_callOrigin:\n  assumes \"ps_growing S' S tx\"\n    and \"callOrigin S' c \\<triangleq> t\"\n  shows \"callOrigin S c \\<triangleq> t\"\n  using assms(1) proof (rule ps_growing_rule)\n  fix CS CS'\n  assume rel1: \"proof_state_rel S' CS\"\n    and rel2: \"proof_state_rel S CS'\"\n    and g: \"state_monotonicGrowth (ps_i S') CS          (CS'\\<lparr>txStatus := (txStatus CS')(tx := None),                 txOrigin := (txOrigin CS')(tx := None),                 currentTx := (currentTx CS')(ps_i S' := None),                 localState := (localState CS')(ps_i S' := localState CS (ps_i S')),                 visibleCalls := (visibleCalls CS')(ps_i S' := visibleCalls CS (ps_i S'))\\<rparr>)\"\n\n  have \"callOrigin CS c \\<triangleq> t\"\n    using assms(1) assms(2) proof_state_rel_callOrigin ps_growing_no_localCalls1 rel1 by fastforce\n\n\n  from state_monotonicGrowth_callOrigin[OF g `callOrigin CS c \\<triangleq> t`]\n  show \"callOrigin S c \\<triangleq> t\"\n    using assms(1) proof_state_rel_callOrigin ps_growing_no_localCalls2 rel2 by fastforce\nqed\n\nlemma ps_monotonicGrowth_callOrigin2:\n  assumes \"ps_growing S' S t\"\n  shows \"callOrigin S c = None \\<Longrightarrow> callOrigin S' c = None\"\n  by (metis assms option.exhaust ps_monotonicGrowth_callOrigin)\n  \n\nlemma ps_monotonicGrowth_knownIds:\n  assumes \"ps_growing S' S tx\"\n  shows \"knownIds S' \\<subseteq> knownIds S\"\n  using assms(1) proof (rule ps_growing_rule)\n  fix CS CS'\n  assume rel1: \"proof_state_rel S' CS\"\n    and rel2: \"proof_state_rel S CS'\"\n    and g: \"state_monotonicGrowth (ps_i S') CS          (CS'\\<lparr>txStatus := (txStatus CS')(tx := None),                 txOrigin := (txOrigin CS')(tx := None),                 currentTx := (currentTx CS')(ps_i S' := None),                 localState := (localState CS')(ps_i S' := localState CS (ps_i S')),                 visibleCalls := (visibleCalls CS')(ps_i S' := visibleCalls CS (ps_i S'))\\<rparr>)\"\n\n  from state_monotonicGrowth_knownIds[OF g, simplified]\n  have \"knownIds CS \\<subseteq> knownIds CS'\" .\n\n  thus \"knownIds S' \\<subseteq> knownIds S\"\n    using proof_state_rel_knownIds rel1 rel2 by auto\nqed\n\n\n\nlemma ps_monotonicGrowth_invocOp:\n  assumes \"ps_growing S' S tx\"\n    and \"invocOp S' s \\<triangleq> info\"\n  shows \"invocOp S s \\<triangleq> info\"\n  using assms(1) proof (rule ps_growing_rule)\n  fix CS CS'\n  assume rel1: \"proof_state_rel S' CS\"\n    and rel2: \"proof_state_rel S CS'\"\n    and g: \"state_monotonicGrowth (ps_i S') CS          (CS'\\<lparr>txStatus := (txStatus CS')(tx := None),                 txOrigin := (txOrigin CS')(tx := None),                 currentTx := (currentTx CS')(ps_i S' := None),                 localState := (localState CS')(ps_i S' := localState CS (ps_i S')),                 visibleCalls := (visibleCalls CS')(ps_i S' := visibleCalls CS (ps_i S'))\\<rparr>)\"\n\n  have \"invocOp CS s \\<triangleq> info\"\n    using assms(2) proof_state_rel_invocOp rel1 by force\n\n\n  from state_monotonicGrowth_invocOp[OF g `invocOp CS s \\<triangleq> info`, simplified]\n  show ?thesis\n    using proof_state_rel_invocOp rel2 by fastforce\nqed\n\nlemma ps_growing_same_i:\nassumes \"ps_growing S' S tx\"\nshows \"ps_i S = ps_i S'\"\n  using assms ps_growing_def by blast\n\n\n\nlemma ps_monotonicGrowth_invocOp_i:\n  assumes \"ps_growing S' S tx\"\n  shows \"invocOp S (ps_i S) = invocOp S' (ps_i S)\"\n  using assms(1) proof (rule ps_growing_rule)\n  fix CS CS'\n  assume rel1: \"proof_state_rel S' CS\"\n    and rel2: \"proof_state_rel S CS'\"\n    and g: \"state_monotonicGrowth (ps_i S') CS          (CS'\\<lparr>txStatus := (txStatus CS')(tx := None),                 txOrigin := (txOrigin CS')(tx := None),                 currentTx := (currentTx CS')(ps_i S' := None),                 localState := (localState CS')(ps_i S' := localState CS (ps_i S')),                 visibleCalls := (visibleCalls CS')(ps_i S' := visibleCalls CS (ps_i S'))\\<rparr>)\"\n\n  from state_monotonicGrowth_invocOp_i[OF g]\n  have \"invocOp CS' (ps_i S') = invocOp CS (ps_i S')\" by simp\n  thus ?thesis\n    by (metis (no_types, lifting) assms proof_state_rel_invocOp ps_growing_same_i rel1 rel2)\nqed\n\nlemma ps_monotonicGrowth_invocRes:\n  assumes \"ps_growing S' S tx\"\n    and \"invocRes S' s \\<triangleq> info\"\n  shows \"invocRes S s \\<triangleq> info\"\n  using assms(1) proof (rule ps_growing_rule)\n  fix CS CS'\n  assume rel1: \"proof_state_rel S' CS\"\n    and rel2: \"proof_state_rel S CS'\"\n    and g: \"state_monotonicGrowth (ps_i S') CS          (CS'\\<lparr>txStatus := (txStatus CS')(tx := None),                 txOrigin := (txOrigin CS')(tx := None),                 currentTx := (currentTx CS')(ps_i S' := None),                 localState := (localState CS')(ps_i S' := localState CS (ps_i S')),                 visibleCalls := (visibleCalls CS')(ps_i S' := visibleCalls CS (ps_i S'))\\<rparr>)\"\n\n  have \"invocRes CS s \\<triangleq> info\"\n    using assms(2) proof_state_rel_invocRes rel1 by fastforce\n\n\n  from state_monotonicGrowth_invocRes[OF g `invocRes CS s \\<triangleq> info`, simplified]\n  have \"invocRes CS' s \\<triangleq> info\" .\n  thus ?thesis\n    using proof_state_rel_invocRes rel2 by force\nqed\n\n\n\nlemma ps_monotonicGrowth_invocRes_i:\n  assumes \"ps_growing S' S t\"\n  shows \"invocRes S' (ps_i S') = invocRes S (ps_i S')\"\n  by (smt assms proof_state_rel_invocRes proof_state_rel_ls proof_state_rel_wf ps_growing_rule ps_growing_same_i wf_localState_noReturn)\n\n\n\nlemma ps_monotonicGrowth_prog:\n  assumes \"ps_growing S' S t\"\n  shows \"ps_prog S = ps_prog S'\"\n  using assms ps_growing_def by blast\n\nlemma ps_monotonicGrowth_invocOp2:\n  assumes \"ps_growing S' S t\"\n  shows \"(invocOp S' \\<subseteq>\\<^sub>m invocOp S) \"\n  using assms map_le_def ps_monotonicGrowth_invocOp by fastforce\n\n  \n\n\nlemma ps_monotonicGrowth_current_transactions_fixed:\n  assumes \"ps_growing S S' t\"\n    and \"ps_tx S \\<triangleq> tx\"\n  shows \"callOrigin S c \\<triangleq> tx \\<longleftrightarrow> callOrigin S' c \\<triangleq> tx\"\n  using assms(1) assms(2) ps_growing_no_tx1 by force\n\n\n\nend", "meta": {"author": "peterzeller", "repo": "repliss-isabelle", "sha": "f43744678cc9c5a4684e8bd0e9c83510bae1d9a4", "save_path": "github-repos/isabelle/peterzeller-repliss-isabelle", "path": "github-repos/isabelle/peterzeller-repliss-isabelle/repliss-isabelle-f43744678cc9c5a4684e8bd0e9c83510bae1d9a4/proof_state_facts.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6224593312018546, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.2701358123358359}}
{"text": ";;; -*- syntax: common-lisp; package: KEIM; base: 10; mode: LISP -*-\n;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;\n;;                                                                          ;;\n;;   Copyright (C) 1996 by AG Siekmann, Fachbereich Informatik,             ;;\n;;   Universitaet des Saarlandes, Saarbruecken, Germany.                    ;;\n;;   All rights reserved.                                                   ;;\n;;   For information about this program, write to:                          ;;\n;;     OMEGA Project                                                         ;;\n;;     AG Siekmann/FB Informatik                                            ;;\n;;     Universitaet des Saarlandes                                          ;;\n;;     Postfach 1150                                                        ;;\n;;     D-66041 Saarbruecken                                                 ;;\n;;     Germany                                                              ;;\n;;   electronic mail: keim@cs.uni-sb.de                                     ;;\n;;                                                                          ;;\n;;   The author makes no representations about the suitability of this      ;;\n;;   software for any purpose.  It is provided \"AS IS\" without express or   ;;\n;;   implied warranty.  In particular, it must be understood that this      ;;\n;;   software is an experimental version, and is not suitable for use in    ;;\n;;   any safety-critical application, and the author denies a license for   ;;\n;;   such use.                                                              ;;\n;;                                                                          ;;\n;;   You may use, copy, modify and distribute this software for any         ;;\n;;   noncommercial and non-safety-critical purpose.  Use of this software   ;;\n;;   in a commercial product is not included under this license.  You must  ;;\n;;   maintain this copyright statement in all copies of this software that  ;;\n;;   you modify or distribute.                                              ;;\n;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;\n\n(in-package :omega)\n\n\n(th~deftheorem submodule-property\n\t       (in module)\n\t       (conclusion\n\t\t(all-types aa bb\n\t\t (forall (lam (M (o bb))\n\t\t  (forall (lam (madd (bb bb bb))\n\t\t   (forall (lam (R (o aa))\n\t\t    (forall (lam (radd (aa aa aa))\n\t\t     (forall (lam (rmul (aa aa aa))\n\t\t      (forall (lam (rmmul (bb bb aa))\n\t\t       (forall (lam (A (o bb))\n\t\t\t (implies (and (and (module M madd R radd rmul rmmul)\n\t\t\t\t\t    (subset A M))\n\t\t\t\t       (and (closed-under A madd)\n\t\t\t\t\t    (and (in (group-unit M madd) A)\n\t\t\t\t\t\t (and (forall-sort (lam (m1 bb)\n\t\t\t\t\t\t       (forall-sort (lam (m2 bb)\n\t\t\t\t\t\t\t(in (madd m1 ((group-inverse M madd) m2)) A))\n\t\t\t\t\t\t\t\t    A))\n\t\t\t\t\t\t\t\t   A)\n\t\t\t\t\t\t      (forall-sort (lam (r1 aa)\n\t\t\t\t\t\t       (forall-sort (lam (m1 bb)\n\t\t\t\t\t\t\t(in (rmmul r1 m1) A))\n\t\t\t\t\t\t\t\t    A))\n\t\t\t\t\t\t\t\t   R)))))\n\t\t\t\t  (submodule A M madd R radd rmul rmmul)))))))))))))))))))\n", "meta": {"author": "theoremprover-museum", "repo": "OMEGA", "sha": "b95b25f8bb16847a2e18d106510446a175f7145a", "save_path": "github-repos/isabelle/theoremprover-museum-OMEGA", "path": "github-repos/isabelle/theoremprover-museum-OMEGA/OMEGA-b95b25f8bb16847a2e18d106510446a175f7145a/theories/module/module-theorems.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6224593312018545, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.27013581233583583}}
{"text": "section \"A simpler version with no clock parameter and factored-out matching\"\n\ntheory Big_Step_Unclocked\nimports\n  Semantic_Extras\n  Big_Step_Determ\nbegin\n\ninductive\n\nevaluate_list  :: \" (v)sem_env \\<Rightarrow> 'ffi state \\<Rightarrow>(exp)list \\<Rightarrow> 'ffi state*(((v)list),(v))result \\<Rightarrow> bool \"\n      and\nevaluate  :: \" (v)sem_env \\<Rightarrow> 'ffi state \\<Rightarrow> exp \\<Rightarrow> 'ffi state*((v),(v))result \\<Rightarrow> bool \"  where\n\n\"lit\" : \" \\<And> env l s.\n\nevaluate env s (Lit l) (s, Rval (Litv l))\"\n\n|\n\n\"raise1\" : \" \\<And> env e s1 s2 v1.\nevaluate s1 env e (s2, Rval v1)\n==>\nevaluate s1 env (Raise e) (s2, Rerr (Rraise v1))\"\n\n|\n\n\"raise2\" : \" \\<And> env e s1 s2 err.\nevaluate s1 env e (s2, Rerr err)\n==>\nevaluate s1 env (Raise e) (s2, Rerr err)\"\n\n|\n\n\"handle1\" : \" \\<And> s1 s2 env e v1 pes.\nevaluate s1 env e (s2, Rval v1)\n==>\nevaluate s1 env (Handle e pes) (s2, Rval v1)\"\n\n|\n\n\"handle2\" : \" \\<And> s1 s2 env e pes v1 bv.\nevaluate env s1 e (s2, Rerr (Rraise v1)) \\<Longrightarrow>\nmatch_result env s2 v1 pes v1 = Rval (e', env') \\<Longrightarrow>\nevaluate (env \\<lparr> sem_env.v := nsAppend (alist_to_ns env') (sem_env.v env) \\<rparr>) s2 e' bv\n==>\nevaluate env s1 (Handle e pes) bv \"\n\n|\n\n\"handle2b\" : \" \\<And> s1 s2 env e pes v1.\nevaluate env s1 e (s2, Rerr (Rraise v1)) \\<Longrightarrow>\nmatch_result env s2 v1 pes v1 = Rerr err\n==>\nevaluate env s1 (Handle e pes) (s2, Rerr err)\"\n\n|\n\n\"handle3\" : \" \\<And> s1 s2 env e pes a.\nevaluate env s1 e (s2, Rerr (Rabort a))\n==>\nevaluate env s1 (Handle e pes) (s2, Rerr (Rabort a))\"\n\n|\n\n\"con1\" : \" \\<And> env cn es vs s s' v1.\ndo_con_check(c   env) cn (List.length es) \\<Longrightarrow>\nbuild_conv(c   env) cn (List.rev vs) = Some v1 \\<Longrightarrow>\nevaluate_list env s (List.rev es) (s', Rval vs)\n==>\nevaluate env s (Con cn es) (s', Rval v1)\"\n\n|\n\n\"con2\" : \" \\<And> env cn es s.\n\\<not> (do_con_check(c   env) cn (List.length es))\n==>\nevaluate env s (Con cn es) (s, Rerr (Rabort Rtype_error))\"\n\n|\n\n\"con3\" : \" \\<And> env cn es err s s'.\ndo_con_check(c   env) cn (List.length es) \\<Longrightarrow>\nevaluate_list env s (List.rev es) (s', Rerr err)\n==>\nevaluate env s (Con cn es) (s', Rerr err)\"\n\n|\n\n\"var1\" : \" \\<And> env n v1 s.\nnsLookup(sem_env.v   env) n = Some v1\n==>\nevaluate env s (Var n) (s, Rval v1)\"\n\n|\n\n\"var2\" : \" \\<And> env n s.\nnsLookup(sem_env.v   env) n = None\n==>\nevaluate env s (Var n) (s, Rerr (Rabort Rtype_error))\"\n\n|\n\n\"fn\" : \" \\<And> env n e s.\n\nevaluate env s (Fun n e) (s, Rval (Closure env n e))\"\n\n|\n\n\"app1\" : \" \\<And> env es vs env' e bv s1 s2.\nevaluate_list env s1 (List.rev es) (s2, Rval vs) \\<Longrightarrow>\ndo_opapp (List.rev vs) = Some (env', e) \\<Longrightarrow>\nevaluate env' s2 e bv\n==>\nevaluate env s1 (App Opapp es) bv \"\n\n|\n\n\"app3\" : \" \\<And> env es vs s1 s2.\nevaluate_list env s1 (List.rev es) (s2, Rval vs) \\<Longrightarrow>\n(do_opapp (List.rev vs) = None)\n==>\nevaluate env s1 (App Opapp es) (s2, Rerr (Rabort Rtype_error))\"\n\n|\n\n\"app4\" : \" \\<And> env op0 es vs res s1 s2 refs' ffi'.\nevaluate_list env s1 (List.rev es) (s2, Rval vs) \\<Longrightarrow>\ndo_app ((refs   s2),(ffi   s2)) op0 (List.rev vs) = Some ((refs',ffi'), res) \\<Longrightarrow>\nop0 \\<noteq> Opapp\n==>\nevaluate env s1 (App op0 es) (( s2 (| refs := refs', ffi :=ffi' |)), res)\"\n\n|\n\n\"app5\" : \" \\<And> env op0 es vs s1 s2.\nevaluate_list env s1 (List.rev es) (s2, Rval vs) \\<Longrightarrow>\ndo_app ((refs   s2),(ffi   s2)) op0 (List.rev vs) = None \\<Longrightarrow>\nop0 \\<noteq> Opapp\n==>\nevaluate env s1 (App op0 es) (s2, Rerr (Rabort Rtype_error))\"\n\n|\n\n\"app6\" : \" \\<And> env op0 es err s1 s2.\nevaluate_list env s1 (List.rev es) (s2, Rerr err)\n==>\nevaluate env s1 (App op0 es) (s2, Rerr err)\"\n\n|\n\n\"log1\" : \" \\<And> env op0 e1 e2 v1 e' bv s1 s2.\nevaluate env s1 e1 (s2, Rval v1) \\<Longrightarrow>\ndo_log op0 v1 e2 = Some (Exp e') \\<Longrightarrow>\nevaluate env s2 e' bv\n==>\nevaluate env s1 (Log op0 e1 e2) bv \"\n\n|\n\n\"log2\" : \" \\<And> env op0 e1 e2 v1 bv s1 s2.\nevaluate env s1 e1 (s2, Rval v1) \\<Longrightarrow>\n(do_log op0 v1 e2 = Some (Val bv))\n==>\nevaluate env s1 (Log op0 e1 e2) (s2, Rval bv)\"\n\n|\n\n\"log3\" : \" \\<And> env op0 e1 e2 v1 s1 s2.\nevaluate env s1 e1 (s2, Rval v1) \\<Longrightarrow>\n(do_log op0 v1 e2 = None)\n==>\nevaluate env s1 (Log op0 e1 e2) (s2, Rerr (Rabort Rtype_error))\"\n\n|\n\n\"log4\" : \" \\<And> env op0 e1 e2 err s s'.\nevaluate env s e1 (s', Rerr err)\n==>\nevaluate env s (Log op0 e1 e2) (s', Rerr err)\"\n\n|\n\n\"if1\" : \" \\<And> env e1 e2 e3 v1 e' bv s1 s2.\nevaluate env s1 e1 (s2, Rval v1) \\<Longrightarrow>\ndo_if v1 e2 e3 = Some e' \\<Longrightarrow>\nevaluate env s2 e' bv\n==>\nevaluate env s1 (If e1 e2 e3) bv \"\n\n|\n\n\"if2\" : \" \\<And> env e1 e2 e3 v1 s1 s2.\nevaluate env s1 e1 (s2, Rval v1) \\<Longrightarrow>\n(do_if v1 e2 e3 = None)\n==>\nevaluate env s1 (If e1 e2 e3) (s2, Rerr (Rabort Rtype_error))\"\n\n|\n\n\"if3\" : \" \\<And> env e1 e2 e3 err s s'.\nevaluate env s e1 (s', Rerr err)\n==>\nevaluate env s (If e1 e2 e3) (s', Rerr err)\"\n\n|\n\n\"mat1\" : \" \\<And> env e pes v1 bv s1 s2.\nevaluate env s1 e (s2, Rval v1) \\<Longrightarrow>\nmatch_result env s2 v1 pes Bindv = Rval (e', env') \\<Longrightarrow>\nevaluate (env \\<lparr> sem_env.v := nsAppend (alist_to_ns env') (sem_env.v env) \\<rparr>) s2 e' bv\n==>\nevaluate env s1 (Mat e pes) bv \"\n\n|\n\n\"mat1b\" : \" \\<And> env e pes v1 s1 s2.\nevaluate env s1 e (s2, Rval v1) \\<Longrightarrow>\nmatch_result env s2 v1 pes Bindv = Rerr err\n==>\nevaluate env s1 (Mat e pes) (s2, Rerr err)\"\n\n|\n\n\"mat2\" : \" \\<And> env e pes err s s'.\nevaluate env s e (s', Rerr err)\n==>\nevaluate env s (Mat e pes) (s', Rerr err)\"\n\n|\n\n\"let1\" : \" \\<And> env n e1 e2 v1 bv s1 s2.\nevaluate env s1 e1 (s2, Rval v1) \\<Longrightarrow>\nevaluate ( env (| sem_env.v := (nsOptBind n v1(sem_env.v   env)) |)) s2 e2 bv\n==>\nevaluate env s1 (Let n e1 e2) bv \"\n\n|\n\n\"let2\" : \" \\<And> env n e1 e2 err s s'.\nevaluate env s e1 (s', Rerr err)\n==>\nevaluate env s (Let n e1 e2) (s', Rerr err)\"\n\n|\n\n\"letrec1\" : \" \\<And> env funs e bv s.\ndistinct (List.map ( \\<lambda>x .\n  (case  x of (x,y,z) => x )) funs) \\<Longrightarrow>\nevaluate ( env (| sem_env.v := (build_rec_env funs env(sem_env.v   env)) |)) s e bv\n==>\nevaluate env s (Letrec funs e) bv \"\n\n|\n\n\"letrec2\" : \" \\<And> env funs e s.\n\\<not> (distinct (List.map ( \\<lambda>x .\n  (case  x of (x,y,z) => x )) funs))\n==>\nevaluate env s (Letrec funs e) (s, Rerr (Rabort Rtype_error))\"\n\n|\n\n\"tannot\" : \" \\<And> env e t0 s bv.\nevaluate env s e bv\n==>\nevaluate env s (Tannot e t0) bv \"\n\n|\n\n\"locannot\" : \" \\<And> env e l s bv.\nevaluate env s e bv\n==>\nevaluate env s (Lannot e l) bv \"\n\n|\n\n\"empty\" : \" \\<And> env s.\n\nevaluate_list env s [] (s, Rval [])\"\n\n|\n\n\"cons1\" : \" \\<And> env e es v1 vs s1 s2 s3.\nevaluate env s1 e (s2, Rval v1) \\<Longrightarrow>\nevaluate_list env s2 es (s3, Rval vs)\n==>\nevaluate_list env s1 (e # es) (s3, Rval (v1 # vs))\"\n\n|\n\n\"cons2\" : \" \\<And> env e es err s s'.\nevaluate env s e (s', Rerr err)\n==>\nevaluate_list env s (e # es) (s', Rerr err)\"\n\n|\n\n\"cons3\" : \" \\<And> env e es v1 err s1 s2 s3.\nevaluate env s1 e (s2, Rval v1) \\<Longrightarrow>\nevaluate_list env s2 es (s3, Rerr err)\n==>\nevaluate_list env s1 (e # es) (s3, Rerr err)\"\n\nlemma unclocked_sound:\n  \"evaluate_list v s es bv \\<Longrightarrow> BigStep.evaluate_list False v s es bv\"\n  \"evaluate v s e bv' \\<Longrightarrow> BigStep.evaluate False v s e bv'\"\nproof (induction rule: evaluate_list_evaluate.inducts)\n  case (handle2 e' env' s1 s2 env e pes v1 bv)\n  show ?case\n    apply (rule BigStep.handle2, intro conjI)\n    apply fact\n    apply (rule match_result_sound_val)\n    apply fact+\n    done\nnext\n  case (handle2b err s1 s2 env e pes v1)\n  show ?case\n    apply (rule BigStep.handle2, intro conjI)\n    apply fact\n    apply (rule match_result_sound_err)\n    apply fact\n    done\nnext\n  case (mat1 e' env' env e pes v1 bv s1 s2)\n  show ?case\n    apply (rule BigStep.mat1, fold Bindv_def, intro conjI)\n    apply fact\n    apply (rule match_result_sound_val)\n    apply fact+\n    done\nnext\n  case (mat1b err env e pes v1 s1 s2)\n  show ?case\n    apply (rule BigStep.mat1, fold Bindv_def, intro conjI)\n    apply fact\n    apply (rule match_result_sound_err)\n    apply fact\n    done\nqed (fastforce simp: all_distinct_alt_def[symmetric] intro: evaluate_match_evaluate_list_evaluate.intros)+\n\ncontext begin\n\nprivate lemma unclocked_complete0:\n  \"BigStep.evaluate_match ck env s v0 pes err_v (s', bv) \\<Longrightarrow> \\<not> ck \\<Longrightarrow> (\n    case bv of\n        Rval v \\<Rightarrow>\n          \\<exists>e env'.\n            match_result env s v0 pes err_v = Rval (e, env') \\<and>\n            evaluate (env \\<lparr> sem_env.v := nsAppend (alist_to_ns env') (sem_env.v env) \\<rparr>) s e (s', Rval v)\n      | Rerr err \\<Rightarrow>\n          (match_result env s v0 pes err_v = Rerr err) \\<or>\n          (\\<exists>e env'.\n            match_result env s v0 pes err_v = Rval (e, env') \\<and>\n            evaluate (env \\<lparr> sem_env.v := nsAppend (alist_to_ns env') (sem_env.v env) \\<rparr>) s e (s', Rerr err)))\"\n  \"BigStep.evaluate_list ck v s es (s', bv0) \\<Longrightarrow> \\<not> ck \\<Longrightarrow> evaluate_list v s es (s', bv0)\"\n  \"BigStep.evaluate ck v s e (s', bv) \\<Longrightarrow> \\<not> ck \\<Longrightarrow> evaluate v s e (s', bv)\"\nproof (induction rule: evaluate_induct)\n  case (handle2 ck s1 s2 env e pes v1 s3 bv)\n  show ?case\n    proof (cases bv)\n      case (Rval v)\n      with handle2 obtain e env' where\n        \"match_result env s2 v1 pes v1 = Rval (e, env')\"\n        \"evaluate (env \\<lparr> sem_env.v := nsAppend (alist_to_ns env') (sem_env.v env) \\<rparr>) s2 e (s3, Rval v)\"\n        by auto\n\n      show ?thesis\n        unfolding \\<open>bv = _\\<close>\n        apply (rule evaluate_list_evaluate.handle2)\n        using handle2 apply blast\n        by fact+\n    next\n      case (Rerr err)\n      with handle2 consider\n        (match_err) \"match_result env s2 v1 pes v1 = Rerr err\" |\n        (eval_err) e env' where\n          \"match_result env s2 v1 pes v1 = Rval (e, env')\"\n          \"evaluate (env \\<lparr> sem_env.v := nsAppend (alist_to_ns env') (sem_env.v env) \\<rparr>) s2 e (s3, Rerr err)\"\n        by auto\n      then show ?thesis\n        proof cases\n          case match_err\n          then have \"evaluate_match ck env s2 v1 pes v1 (s2, Rerr err)\"\n            by (metis match_result_sound_err)\n          moreover have \"evaluate_match ck env s2 v1 pes v1 (s3, Rerr err)\"\n            using handle2 unfolding \\<open>bv = _\\<close> by blast\n          ultimately have \"s2 = s3\"\n            by (metis evaluate_determ fst_conv)\n\n          show ?thesis\n            unfolding \\<open>bv = _\\<close>\n            apply (rule evaluate_list_evaluate.handle2b)\n            using handle2 unfolding \\<open>s2 = _\\<close> apply blast\n            using match_err unfolding \\<open>s2 = _\\<close> .\n        next\n          case eval_err\n          show ?thesis\n            unfolding \\<open>bv = _\\<close>\n            apply (rule evaluate_list_evaluate.handle2)\n            using handle2 apply blast\n            by fact+\n        qed\n    qed\nnext\n  case (mat1 ck env e pes v1 s3 v' s1 s2)\n  then show ?case\n    (* this is the same proof as above, but with less Isar and more apply *)\n    apply (auto split: result.splits simp: Bindv_def[symmetric])\n    subgoal by (rule evaluate_list_evaluate.mat1) auto\n    subgoal\n      apply (frule match_result_sound_err)\n      apply (subgoal_tac \"s2 = s3\")\n      apply (rule evaluate_list_evaluate.mat1b)\n      apply force\n      apply force\n      apply (drule evaluate_determ)\n      apply assumption\n      by auto\n    subgoal by (rule evaluate_list_evaluate.mat1) auto\n    done\nnext\n  case (mat_cons1 ck env env' v1 p pes e a b err_v s)\n  then show ?case\n    by (auto split: result.splits)\nnext\n  case (mat_cons2 ck env v1 p e pes a b s err_v)\n  then show ?case\n    by (auto split: result.splits)\nqed (fastforce simp: all_distinct_alt_def intro: evaluate_list_evaluate.intros)+\n\nlemma unclocked_complete:\n  \"BigStep.evaluate_list False v s es bv' \\<Longrightarrow> evaluate_list v s es bv'\"\n  \"BigStep.evaluate False v s e bv \\<Longrightarrow> evaluate v s e bv\"\napply (cases bv'; metis unclocked_complete0)\napply (cases bv; metis unclocked_complete0)\ndone\n\nend\n\nlemma unclocked_eq:\n  \"evaluate_list = BigStep.evaluate_list False\"\n  \"evaluate = BigStep.evaluate False\"\nby (auto intro: unclocked_sound unclocked_complete intro!: ext)\n\n\n\nend", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/CakeML/Big_Step_Unclocked.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621765008857981, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.2701138219752063}}
{"text": "(*  Title:      HOL/Auth/Guard/P2.thy\n    Author:     Frederic Blanqui, University of Cambridge Computer Laboratory\n    Copyright   2002  University of Cambridge\n\nFrom G. Karjoth, N. Asokan and C. Gulcu\n\"Protecting the computation results of free-roaming agents\"\nMobiles Agents 1998, LNCS 1477.\n*)\n\nsection\\<open>Protocol P2\\<close>\n\ntheory P2 imports Guard_Public List_Msg begin\n\nsubsection\\<open>Protocol Definition\\<close>\n\n\ntext\\<open>Like P1 except the definitions of \\<open>chain\\<close>, \\<open>shop\\<close>,\n  \\<open>next_shop\\<close> and \\<open>nonce\\<close>\\<close>\n\nsubsubsection\\<open>offer chaining:\nB chains his offer for A with the head offer of L for sending it to C\\<close>\n\ndefinition chain :: \"agent => nat => agent => msg => agent => msg\" where\n\"chain B ofr A L C ==\nlet m1= sign B (Nonce ofr) in\nlet m2= Hash \\<lbrace>head L, Agent C\\<rbrace> in\n\\<lbrace>Crypt (pubK A) m1, m2\\<rbrace>\"\n\ndeclare Let_def [simp]\n\nlemma chain_inj [iff]: \"(chain B ofr A L C = chain B' ofr' A' L' C')\n= (B=B' & ofr=ofr' & A=A' & head L = head L' & C=C')\"\nby (auto simp: chain_def Let_def)\n\nlemma Nonce_in_chain [iff]: \"Nonce ofr:parts {chain B ofr A L C}\"\nby (auto simp: chain_def sign_def)\n\nsubsubsection\\<open>agent whose key is used to sign an offer\\<close>\n\nfun shop :: \"msg => msg\" where\n\"shop \\<lbrace>Crypt K \\<lbrace>B,ofr,Crypt K' H\\<rbrace>,m2\\<rbrace> = Agent (agt K')\"\n\nlemma shop_chain [simp]: \"shop (chain B ofr A L C) = Agent B\"\nby (simp add: chain_def sign_def)\n\nsubsubsection\\<open>nonce used in an offer\\<close>\n\nfun nonce :: \"msg => msg\" where\n\"nonce \\<lbrace>Crypt K \\<lbrace>B,ofr,CryptH\\<rbrace>,m2\\<rbrace> = ofr\"\n\nlemma nonce_chain [simp]: \"nonce (chain B ofr A L C) = Nonce ofr\"\nby (simp add: chain_def sign_def)\n\nsubsubsection\\<open>next shop\\<close>\n\nfun next_shop :: \"msg => agent\" where\n\"next_shop \\<lbrace>m1,Hash \\<lbrace>headL,Agent C\\<rbrace>\\<rbrace> = C\"\n\nlemma \"next_shop (chain B ofr A L C) = C\"\nby (simp add: chain_def sign_def)\n\nsubsubsection\\<open>anchor of the offer list\\<close>\n\ndefinition anchor :: \"agent => nat => agent => msg\" where\n\"anchor A n B == chain A n A (cons nil nil) B\"\n\nlemma anchor_inj [iff]:\n     \"(anchor A n B = anchor A' n' B') = (A=A' & n=n' & B=B')\"\nby (auto simp: anchor_def)\n\nlemma Nonce_in_anchor [iff]: \"Nonce n:parts {anchor A n B}\"\nby (auto simp: anchor_def)\n\nlemma shop_anchor [simp]: \"shop (anchor A n B) = Agent A\"\nby (simp add: anchor_def)\n\nsubsubsection\\<open>request event\\<close>\n\ndefinition reqm :: \"agent => nat => nat => msg => agent => msg\" where\n\"reqm A r n I B == \\<lbrace>Agent A, Number r, cons (Agent A) (cons (Agent B) I),\ncons (anchor A n B) nil\\<rbrace>\"\n\nlemma reqm_inj [iff]: \"(reqm A r n I B = reqm A' r' n' I' B')\n= (A=A' & r=r' & n=n' & I=I' & B=B')\"\nby (auto simp: reqm_def)\n\nlemma Nonce_in_reqm [iff]: \"Nonce n:parts {reqm A r n I B}\"\nby (auto simp: reqm_def)\n\ndefinition req :: \"agent => nat => nat => msg => agent => event\" where\n\"req A r n I B == Says A B (reqm A r n I B)\"\n\nlemma req_inj [iff]: \"(req A r n I B = req A' r' n' I' B')\n= (A=A' & r=r' & n=n' & I=I' & B=B')\"\nby (auto simp: req_def)\n\nsubsubsection\\<open>propose event\\<close>\n\ndefinition prom :: \"agent => nat => agent => nat => msg => msg =>\nmsg => agent => msg\" where\n\"prom B ofr A r I L J C == \\<lbrace>Agent A, Number r,\napp (J, del (Agent B, I)), cons (chain B ofr A L C) L\\<rbrace>\"\n\nlemma prom_inj [dest]: \"prom B ofr A r I L J C = prom B' ofr' A' r' I' L' J' C'\n==> B=B' & ofr=ofr' & A=A' & r=r' & L=L' & C=C'\"\nby (auto simp: prom_def)\n\nlemma Nonce_in_prom [iff]: \"Nonce ofr:parts {prom B ofr A r I L J C}\"\nby (auto simp: prom_def)\n\ndefinition pro :: \"agent => nat => agent => nat => msg => msg =>\n                  msg => agent => event\" where\n\"pro B ofr A r I L J C == Says B C (prom B ofr A r I L J C)\"\n\nlemma pro_inj [dest]: \"pro B ofr A r I L J C = pro B' ofr' A' r' I' L' J' C'\n==> B=B' & ofr=ofr' & A=A' & r=r' & L=L' & C=C'\"\nby (auto simp: pro_def dest: prom_inj)\n\nsubsubsection\\<open>protocol\\<close>\n\ninductive_set p2 :: \"event list set\"\nwhere\n\n  Nil: \"[]:p2\"\n\n| Fake: \"[| evsf:p2; X:synth (analz (spies evsf)) |] ==> Says Spy B X # evsf : p2\"\n\n| Request: \"[| evsr:p2; Nonce n ~:used evsr; I:agl |] ==> req A r n I B # evsr : p2\"\n\n| Propose: \"[| evsp:p2; Says A' B \\<lbrace>Agent A,Number r,I,cons M L\\<rbrace>:set evsp;\n  I:agl; J:agl; isin (Agent C, app (J, del (Agent B, I)));\n  Nonce ofr ~:used evsp |] ==> pro B ofr A r I (cons M L) J C # evsp : p2\"\n\nsubsubsection\\<open>valid offer lists\\<close>\n\ninductive_set\n  valid :: \"agent => nat => agent => msg set\"\n  for A :: agent and  n :: nat and B :: agent\nwhere\n  Request [intro]: \"cons (anchor A n B) nil:valid A n B\"\n\n| Propose [intro]: \"L:valid A n B\n  ==> cons (chain (next_shop (head L)) ofr A L C) L:valid A n B\"\n\nsubsubsection\\<open>basic properties of valid\\<close>\n\nlemma valid_not_empty: \"L:valid A n B ==> EX M L'. L = cons M L'\"\nby (erule valid.cases, auto)\n\nlemma valid_pos_len: \"L:valid A n B ==> 0 < len L\"\nby (erule valid.induct, auto)\n\nsubsubsection\\<open>list of offers\\<close>\n\nfun offers :: \"msg => msg\"\nwhere\n  \"offers (cons M L) = cons \\<lbrace>shop M, nonce M\\<rbrace> (offers L)\"\n| \"offers other = nil\"\n\n\nsubsection\\<open>Properties of Protocol P2\\<close>\n\ntext\\<open>same as \\<open>P1_Prop\\<close> except that publicly verifiable forward\nintegrity is replaced by forward privacy\\<close>\n\nsubsection\\<open>strong forward integrity:\nexcept the last one, no offer can be modified\\<close>\n\nlemma strong_forward_integrity: \"ALL L. Suc i < len L\n--> L:valid A n B --> repl (L,Suc i,M):valid A n B --> M = ith (L,Suc i)\"\napply (induct i)\n(* i = 0 *)\napply clarify\napply (frule len_not_empty, clarsimp)\napply (frule len_not_empty, clarsimp)\napply (ind_cases \"\\<lbrace>x,xa,l'a\\<rbrace>:valid A n B\" for x xa l'a)\napply (ind_cases \"\\<lbrace>x,M,l'a\\<rbrace>:valid A n B\" for x l'a)\napply (simp add: chain_def)\n(* i > 0 *)\napply clarify\napply (frule len_not_empty, clarsimp)\napply (ind_cases \"\\<lbrace>x,repl(l',Suc na,M)\\<rbrace>:valid A n B\" for x l' na)\napply (frule len_not_empty, clarsimp)\napply (ind_cases \"\\<lbrace>x,l'\\<rbrace>:valid A n B\" for x l')\nby (drule_tac x=l' in spec, simp, blast)\n\nsubsection\\<open>insertion resilience:\nexcept at the beginning, no offer can be inserted\\<close>\n\nlemma chain_isnt_head [simp]: \"L:valid A n B ==>\nhead L ~= chain (next_shop (head L)) ofr A L C\"\nby (erule valid.induct, auto simp: chain_def sign_def anchor_def)\n\nlemma insertion_resilience: \"ALL L. L:valid A n B --> Suc i < len L\n--> ins (L,Suc i,M) ~:valid A n B\"\napply (induct i)\n(* i = 0 *)\napply clarify\napply (frule len_not_empty, clarsimp)\napply (ind_cases \"\\<lbrace>x,l'\\<rbrace>:valid A n B\" for x l', simp)\napply (ind_cases \"\\<lbrace>x,M,l'\\<rbrace>:valid A n B\" for x l', clarsimp)\napply (ind_cases \"\\<lbrace>head l',l'\\<rbrace>:valid A n B\" for l', simp, simp)\n(* i > 0 *)\napply clarify\napply (frule len_not_empty, clarsimp)\napply (ind_cases \"\\<lbrace>x,l'\\<rbrace>:valid A n B\" for x l')\napply (frule len_not_empty, clarsimp)\napply (ind_cases \"\\<lbrace>x,ins(l',Suc na,M)\\<rbrace>:valid A n B\" for x l' na)\napply (frule len_not_empty, clarsimp)\nby (drule_tac x=l' in spec, clarsimp)\n\nsubsection\\<open>truncation resilience:\nonly shop i can truncate at offer i\\<close>\n\nlemma truncation_resilience: \"ALL L. L:valid A n B --> Suc i < len L\n--> cons M (trunc (L,Suc i)):valid A n B --> shop M = shop (ith (L,i))\"\napply (induct i)\n(* i = 0 *)\napply clarify\napply (frule len_not_empty, clarsimp)\napply (ind_cases \"\\<lbrace>x,l'\\<rbrace>:valid A n B\" for x l')\napply (frule len_not_empty, clarsimp)\napply (ind_cases \"\\<lbrace>M,l'\\<rbrace>:valid A n B\" for l')\napply (frule len_not_empty, clarsimp, simp)\n(* i > 0 *)\napply clarify\napply (frule len_not_empty, clarsimp)\napply (ind_cases \"\\<lbrace>x,l'\\<rbrace>:valid A n B\" for x l')\napply (frule len_not_empty, clarsimp)\nby (drule_tac x=l' in spec, clarsimp)\n\nsubsection\\<open>declarations for tactics\\<close>\n\ndeclare knows_Spy_partsEs [elim]\ndeclare Fake_parts_insert [THEN subsetD, dest]\ndeclare initState.simps [simp del]\n\nsubsection\\<open>get components of a message\\<close>\n\nlemma get_ML [dest]: \"Says A' B \\<lbrace>A,R,I,M,L\\<rbrace>:set evs ==>\nM:parts (spies evs) & L:parts (spies evs)\"\nby blast\n\nsubsection\\<open>general properties of p2\\<close>\n\nlemma reqm_neq_prom [iff]:\n\"reqm A r n I B ~= prom B' ofr A' r' I' (cons M L) J C\"\nby (auto simp: reqm_def prom_def)\n\nlemma prom_neq_reqm [iff]:\n\"prom B' ofr A' r' I' (cons M L) J C ~= reqm A r n I B\"\nby (auto simp: reqm_def prom_def)\n\nlemma req_neq_pro [iff]: \"req A r n I B ~= pro B' ofr A' r' I' (cons M L) J C\"\nby (auto simp: req_def pro_def)\n\nlemma pro_neq_req [iff]: \"pro B' ofr A' r' I' (cons M L) J C ~= req A r n I B\"\nby (auto simp: req_def pro_def)\n\nlemma p2_has_no_Gets: \"evs:p2 ==> ALL A X. Gets A X ~:set evs\"\nby (erule p2.induct, auto simp: req_def pro_def)\n\nlemma p2_is_Gets_correct [iff]: \"Gets_correct p2\"\nby (auto simp: Gets_correct_def dest: p2_has_no_Gets)\n\nlemma p2_is_one_step [iff]: \"one_step p2\"\nby (unfold one_step_def, clarify, ind_cases \"ev#evs:p2\" for ev evs, auto)\n\nlemma p2_has_only_Says' [rule_format]: \"evs:p2 ==>\nev:set evs --> (EX A B X. ev=Says A B X)\"\nby (erule p2.induct, auto simp: req_def pro_def)\n\nlemma p2_has_only_Says [iff]: \"has_only_Says p2\"\nby (auto simp: has_only_Says_def dest: p2_has_only_Says')\n\nlemma p2_is_regular [iff]: \"regular p2\"\napply (simp only: regular_def, clarify)\napply (erule_tac p2.induct)\napply (simp_all add: initState.simps knows.simps pro_def prom_def\nreq_def reqm_def anchor_def chain_def sign_def)\nby (auto dest: no_Key_in_agl no_Key_in_appdel parts_trans)\n\nsubsection\\<open>private keys are safe\\<close>\n\nlemma priK_parts_Friend_imp_bad [rule_format,dest]:\n     \"[| evs:p2; Friend B ~= A |]\n      ==> (Key (priK A):parts (knows (Friend B) evs)) --> (A:bad)\"\napply (erule p2.induct)\napply (simp_all add: initState.simps knows.simps pro_def prom_def\n                req_def reqm_def anchor_def chain_def sign_def) \napply (blast dest: no_Key_in_agl)\napply (auto del: parts_invKey disjE  dest: parts_trans\n            simp add: no_Key_in_appdel)\ndone\n\nlemma priK_analz_Friend_imp_bad [rule_format,dest]:\n     \"[| evs:p2; Friend B ~= A |]\n==> (Key (priK A):analz (knows (Friend B) evs)) --> (A:bad)\"\nby auto\n\nlemma priK_notin_knows_max_Friend:\n     \"[| evs:p2; A ~:bad; A ~= Friend C |]\n      ==> Key (priK A) ~:analz (knows_max (Friend C) evs)\"\napply (rule not_parts_not_analz, simp add: knows_max_def, safe)\napply (drule_tac H=\"spies' evs\" in parts_sub)\napply (rule_tac p=p2 in knows_max'_sub_spies', simp+)\napply (drule_tac H=\"spies evs\" in parts_sub)\nby (auto dest: knows'_sub_knows [THEN subsetD] priK_notin_initState_Friend)\n\nsubsection\\<open>general guardedness properties\\<close>\n\nlemma agl_guard [intro]: \"I:agl ==> I:guard n Ks\"\nby (erule agl.induct, auto)\n\nlemma Says_to_knows_max'_guard: \"[| Says A' C \\<lbrace>A'',r,I,L\\<rbrace>:set evs;\nGuard n Ks (knows_max' C evs) |] ==> L:guard n Ks\"\nby (auto dest: Says_to_knows_max')\n\nlemma Says_from_knows_max'_guard: \"[| Says C A' \\<lbrace>A'',r,I,L\\<rbrace>:set evs;\nGuard n Ks (knows_max' C evs) |] ==> L:guard n Ks\"\nby (auto dest: Says_from_knows_max')\n\nlemma Says_Nonce_not_used_guard: \"[| Says A' B \\<lbrace>A'',r,I,L\\<rbrace>:set evs;\nNonce n ~:used evs |] ==> L:guard n Ks\"\nby (drule not_used_not_parts, auto)\n\nsubsection\\<open>guardedness of messages\\<close>\n\nlemma chain_guard [iff]: \"chain B ofr A L C:guard n {priK A}\"\nby (case_tac \"ofr=n\", auto simp: chain_def sign_def)\n\nlemma chain_guard_Nonce_neq [intro]: \"n ~= ofr\n==> chain B ofr A' L C:guard n {priK A}\"\nby (auto simp: chain_def sign_def)\n\nlemma anchor_guard [iff]: \"anchor A n' B:guard n {priK A}\"\nby (case_tac \"n'=n\", auto simp: anchor_def)\n\nlemma anchor_guard_Nonce_neq [intro]: \"n ~= n'\n==> anchor A' n' B:guard n {priK A}\"\nby (auto simp: anchor_def)\n\nlemma reqm_guard [intro]: \"I:agl ==> reqm A r n' I B:guard n {priK A}\"\nby (case_tac \"n'=n\", auto simp: reqm_def)\n\nlemma reqm_guard_Nonce_neq [intro]: \"[| n ~= n'; I:agl |]\n==> reqm A' r n' I B:guard n {priK A}\"\nby (auto simp: reqm_def)\n\nlemma prom_guard [intro]: \"[| I:agl; J:agl; L:guard n {priK A} |]\n==> prom B ofr A r I L J C:guard n {priK A}\"\nby (auto simp: prom_def)\n\nlemma prom_guard_Nonce_neq [intro]: \"[| n ~= ofr; I:agl; J:agl;\nL:guard n {priK A} |] ==> prom B ofr A' r I L J C:guard n {priK A}\"\nby (auto simp: prom_def)\n\nsubsection\\<open>Nonce uniqueness\\<close>\n\nlemma uniq_Nonce_in_chain [dest]: \"Nonce k:parts {chain B ofr A L C} ==> k=ofr\"\nby (auto simp: chain_def sign_def)\n\nlemma uniq_Nonce_in_anchor [dest]: \"Nonce k:parts {anchor A n B} ==> k=n\"\nby (auto simp: anchor_def chain_def sign_def)\n\nlemma uniq_Nonce_in_reqm [dest]: \"[| Nonce k:parts {reqm A r n I B};\nI:agl |] ==> k=n\"\nby (auto simp: reqm_def dest: no_Nonce_in_agl)\n\nlemma uniq_Nonce_in_prom [dest]: \"[| Nonce k:parts {prom B ofr A r I L J C};\nI:agl; J:agl; Nonce k ~:parts {L} |] ==> k=ofr\"\nby (auto simp: prom_def dest: no_Nonce_in_agl no_Nonce_in_appdel)\n\nsubsection\\<open>requests are guarded\\<close>\n\nlemma req_imp_Guard [rule_format]: \"[| evs:p2; A ~:bad |] ==>\nreq A r n I B:set evs --> Guard n {priK A} (spies evs)\"\napply (erule p2.induct, simp)\napply (simp add: req_def knows.simps, safe)\napply (erule in_synth_Guard, erule Guard_analz, simp)\nby (auto simp: req_def pro_def dest: Says_imp_knows_Spy)\n\nlemma req_imp_Guard_Friend: \"[| evs:p2; A ~:bad; req A r n I B:set evs |]\n==> Guard n {priK A} (knows_max (Friend C) evs)\"\napply (rule Guard_knows_max')\napply (rule_tac H=\"spies evs\" in Guard_mono)\napply (rule req_imp_Guard, simp+)\napply (rule_tac B=\"spies' evs\" in subset_trans)\napply (rule_tac p=p2 in knows_max'_sub_spies', simp+)\nby (rule knows'_sub_knows)\n\nsubsection\\<open>propositions are guarded\\<close>\n\nlemma pro_imp_Guard [rule_format]: \"[| evs:p2; B ~:bad; A ~:bad |] ==>\npro B ofr A r I (cons M L) J C:set evs --> Guard ofr {priK A} (spies evs)\"\napply (erule p2.induct) (* +3 subgoals *)\n(* Nil *)\napply simp\n(* Fake *)\napply (simp add: pro_def, safe) (* +4 subgoals *)\n(* 1 *)\napply (erule in_synth_Guard, drule Guard_analz, simp, simp)\n(* 2 *)\napply simp\n(* 3 *)\napply (simp, simp add: req_def pro_def, blast)\n(* 4 *)\napply (simp add: pro_def)\napply (blast dest: prom_inj Says_Nonce_not_used_guard Nonce_not_used_Guard)\n(* 5 *)\napply simp\napply safe (* +1 subgoal *)\napply (simp add: pro_def)\napply (blast dest: prom_inj Says_Nonce_not_used_guard)\n(* 6 *)\napply (simp add: pro_def)\napply (blast dest: Says_imp_knows_Spy)\n(* Request *)\napply (simp add: pro_def)\napply (blast dest: prom_inj Says_Nonce_not_used_guard Nonce_not_used_Guard)\n(* Propose *)\napply simp\napply safe (* +1 subgoal *)\n(* 1 *)\napply (simp add: pro_def)\napply (blast dest: prom_inj Says_Nonce_not_used_guard)\n(* 2 *)\napply (simp add: pro_def)\nby (blast dest: Says_imp_knows_Spy)\n\nlemma pro_imp_Guard_Friend: \"[| evs:p2; B ~:bad; A ~:bad;\npro B ofr A r I (cons M L) J C:set evs |]\n==> Guard ofr {priK A} (knows_max (Friend D) evs)\"\napply (rule Guard_knows_max')\napply (rule_tac H=\"spies evs\" in Guard_mono)\napply (rule pro_imp_Guard, simp+)\napply (rule_tac B=\"spies' evs\" in subset_trans)\napply (rule_tac p=p2 in knows_max'_sub_spies', simp+)\nby (rule knows'_sub_knows)\n\nsubsection\\<open>data confidentiality:\nno one other than the originator can decrypt the offers\\<close>\n\nlemma Nonce_req_notin_spies: \"[| evs:p2; req A r n I B:set evs; A ~:bad |]\n==> Nonce n ~:analz (spies evs)\"\nby (frule req_imp_Guard, simp+, erule Guard_Nonce_analz, simp+)\n\nlemma Nonce_req_notin_knows_max_Friend: \"[| evs:p2; req A r n I B:set evs;\nA ~:bad; A ~= Friend C |] ==> Nonce n ~:analz (knows_max (Friend C) evs)\"\napply (clarify, frule_tac C=C in req_imp_Guard_Friend, simp+)\napply (simp add: knows_max_def, drule Guard_invKey_keyset, simp+)\nby (drule priK_notin_knows_max_Friend, auto simp: knows_max_def)\n\nlemma Nonce_pro_notin_spies: \"[| evs:p2; B ~:bad; A ~:bad;\npro B ofr A r I (cons M L) J C:set evs |] ==> Nonce ofr ~:analz (spies evs)\"\nby (frule pro_imp_Guard, simp+, erule Guard_Nonce_analz, simp+)\n\nlemma Nonce_pro_notin_knows_max_Friend: \"[| evs:p2; B ~:bad; A ~:bad;\nA ~= Friend D; pro B ofr A r I (cons M L) J C:set evs |]\n==> Nonce ofr ~:analz (knows_max (Friend D) evs)\"\napply (clarify, frule_tac A=A in pro_imp_Guard_Friend, simp+)\napply (simp add: knows_max_def, drule Guard_invKey_keyset, simp+)\nby (drule priK_notin_knows_max_Friend, auto simp: knows_max_def)\n\nsubsection\\<open>forward privacy:\nonly the originator can know the identity of the shops\\<close>\n\nlemma forward_privacy_Spy: \"[| evs:p2; B ~:bad; A ~:bad;\npro B ofr A r I (cons M L) J C:set evs |]\n==> sign B (Nonce ofr) ~:analz (spies evs)\"\nby (auto simp:sign_def dest: Nonce_pro_notin_spies)\n\nlemma forward_privacy_Friend: \"[| evs:p2; B ~:bad; A ~:bad; A ~= Friend D;\npro B ofr A r I (cons M L) J C:set evs |]\n==> sign B (Nonce ofr) ~:analz (knows_max (Friend D) evs)\"\nby (auto simp:sign_def dest:Nonce_pro_notin_knows_max_Friend )\n\nsubsection\\<open>non repudiability: an offer signed by B has been sent by B\\<close>\n\nlemma Crypt_reqm: \"[| Crypt (priK A) X:parts {reqm A' r n I B}; I:agl |] ==> A=A'\"\nby (auto simp: reqm_def anchor_def chain_def sign_def dest: no_Crypt_in_agl)\n\nlemma Crypt_prom: \"[| Crypt (priK A) X:parts {prom B ofr A' r I L J C};\nI:agl; J:agl |] ==> A=B | Crypt (priK A) X:parts {L}\"\napply (simp add: prom_def anchor_def chain_def sign_def)\nby (blast dest: no_Crypt_in_agl no_Crypt_in_appdel)\n\nlemma Crypt_safeness: \"[| evs:p2; A ~:bad |] ==> Crypt (priK A) X:parts (spies evs)\n--> (EX B Y. Says A B Y:set evs & Crypt (priK A) X:parts {Y})\"\napply (erule p2.induct)\n(* Nil *)\napply simp\n(* Fake *)\napply clarsimp\napply (drule_tac P=\"%G. Crypt (priK A) X:G\" in parts_insert_substD, simp)\napply (erule disjE)\napply (drule_tac K=\"priK A\" in Crypt_synth, simp+, blast, blast)\n(* Request *)\napply (simp add: req_def, clarify)\napply (drule_tac P=\"%G. Crypt (priK A) X:G\" in parts_insert_substD, simp)\napply (erule disjE)\napply (frule Crypt_reqm, simp, clarify)\napply (rule_tac x=B in exI, rule_tac x=\"reqm A r n I B\" in exI, simp, blast)\n(* Propose *)\napply (simp add: pro_def, clarify)\napply (drule_tac P=\"%G. Crypt (priK A) X:G\" in parts_insert_substD, simp)\napply (rotate_tac -1, erule disjE)\napply (frule Crypt_prom, simp, simp)\napply (rotate_tac -1, erule disjE)\napply (rule_tac x=C in exI)\napply (rule_tac x=\"prom B ofr Aa r I (cons M L) J C\" in exI, blast)\napply (subgoal_tac \"cons M L:parts (spies evsp)\")\napply (drule_tac G=\"{cons M L}\" and H=\"spies evsp\" in parts_trans, blast, blast)\napply (drule Says_imp_spies, rotate_tac -1, drule parts.Inj)\napply (drule parts.Snd, drule parts.Snd, drule parts.Snd)\nby auto\n\nlemma Crypt_Hash_imp_sign: \"[| evs:p2; A ~:bad |] ==>\nCrypt (priK A) (Hash X):parts (spies evs)\n--> (EX B Y. Says A B Y:set evs & sign A X:parts {Y})\"\napply (erule p2.induct)\n(* Nil *)\napply simp\n(* Fake *)\napply clarsimp\napply (drule_tac P=\"%G. Crypt (priK A) (Hash X):G\" in parts_insert_substD)\napply simp\napply (erule disjE)\napply (drule_tac K=\"priK A\" in Crypt_synth, simp+, blast, blast)\n(* Request *)\napply (simp add: req_def, clarify)\napply (drule_tac P=\"%G. Crypt (priK A) (Hash X):G\" in parts_insert_substD)\napply simp\napply (erule disjE)\napply (frule Crypt_reqm, simp+)\napply (rule_tac x=B in exI, rule_tac x=\"reqm Aa r n I B\" in exI)\napply (simp add: reqm_def sign_def anchor_def no_Crypt_in_agl)\napply (simp add: chain_def sign_def, blast)\n(* Propose *)\napply (simp add: pro_def, clarify)\napply (drule_tac P=\"%G. Crypt (priK A) (Hash X):G\" in parts_insert_substD)\napply simp\napply (rotate_tac -1, erule disjE)\napply (simp add: prom_def sign_def no_Crypt_in_agl no_Crypt_in_appdel)\napply (simp add: chain_def sign_def)\napply (rotate_tac -1, erule disjE)\napply (rule_tac x=C in exI)\napply (rule_tac x=\"prom B ofr Aa r I (cons M L) J C\" in exI)\napply (simp add: prom_def chain_def sign_def)\napply (erule impE) \napply (blast dest: get_ML parts_sub) \napply (blast del: MPair_parts)+\ndone\n\nlemma sign_safeness: \"[| evs:p2; A ~:bad |] ==> sign A X:parts (spies evs)\n--> (EX B Y. Says A B Y:set evs & sign A X:parts {Y})\"\napply (clarify, simp add: sign_def, frule parts.Snd)\napply (blast dest: Crypt_Hash_imp_sign [unfolded sign_def])\ndone\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/HOL/Auth/Guard/P2.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621765008857981, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.2701138219752063}}
{"text": "(*\n * Copyright 2014, General Dynamics C4 Systems\n *\n * SPDX-License-Identifier: GPL-2.0-only\n *)\n\ntheory KHeapPre_AI\nimports \"./$L4V_ARCH/Machine_AI\"\nbegin\n\nprimrec\n  same_caps :: \"Structures_A.kernel_object \\<Rightarrow> Structures_A.kernel_object \\<Rightarrow> bool\"\nwhere\n  \"same_caps val (CNode sz cs)       = (val = CNode sz cs)\"\n| \"same_caps val (TCB tcb)           = (\\<exists>tcb'. val = TCB tcb'\n                                         \\<and> (\\<forall>(getF, t) \\<in> ran tcb_cap_cases. getF tcb' = getF tcb))\"\n| \"same_caps val (Endpoint ep)       = is_ep val\"\n| \"same_caps val (Notification ntfn) = is_ntfn val\"\n| \"same_caps val (ArchObj ao)        = (\\<exists>ao'. val = ArchObj ao')\"\n\n\nlemma same_caps_more_simps[simp]:\n \"same_caps (CNode sz cs) val       = (val = CNode sz cs)\"\n \"same_caps (TCB tcb)     val       = (\\<exists>tcb'. val = TCB tcb'\n                                         \\<and> (\\<forall>(getF, t) \\<in> ran tcb_cap_cases. getF tcb' = getF tcb))\"\n \"same_caps (Endpoint ep) val       = is_ep val\"\n \"same_caps (Notification ntfn) val = is_ntfn val\"\n \"same_caps (ArchObj ao) val        = (\\<exists>ao'. val = ArchObj ao')\"\n by (cases val, (fastforce simp: is_obj_defs)+)+\n\nlemma dmo_return [simp]:\n  \"do_machine_op (return x) = return x\"\n  by (simp add: do_machine_op_def select_f_def return_def gets_def get_def\n                bind_def modify_def put_def)\n\nlemma get_object_sp:\n  \"\\<lbrace>P\\<rbrace> get_object p \\<lbrace>\\<lambda>r. P and ko_at r p\\<rbrace>\"\n  apply (simp add: get_object_def)\n  apply wp\n  apply (auto simp add: obj_at_def)\n  done\n\ndefinition non_arch_obj :: \"kernel_object \\<Rightarrow> bool\" where\n  \"non_arch_obj \\<equiv> \\<lambda>ko. \\<forall>ako. ko \\<noteq> ArchObj ako\"\n\nlemma non_arch_objs[intro]:\n  \"non_arch_obj (Endpoint ep)\"\n  \"non_arch_obj (CNode sz cnode_contents)\"\n  \"non_arch_obj (TCB tcb)\"\n  \"non_arch_obj (Notification notification)\"\n  by (auto simp add: non_arch_obj_def)\n\ndefinition arch_obj_pred :: \"(kernel_object \\<Rightarrow> bool) \\<Rightarrow> bool\" where\n  \"arch_obj_pred P \\<equiv>\n    \\<forall>ko ko'. non_arch_obj ko \\<longrightarrow> non_arch_obj ko' \\<longrightarrow>\n      P ko = P ko'\"\n\nlemma arch_obj_predE:\n  \"\\<lbrakk>arch_obj_pred P; non_arch_obj ko; non_arch_obj ko'\\<rbrakk> \\<Longrightarrow> P ko = P ko'\"\n  apply (unfold arch_obj_pred_def)\n  apply (erule allE[where ?x=\"ko\"])\n  apply (erule allE[where ?x=\"ko'\"])\n  by blast\n\nlemmas arch_obj_pred_defs = non_arch_obj_def arch_obj_pred_def\n\nlemma arch_obj_pred_a_type[intro, simp]: \"arch_obj_pred (\\<lambda>ko. a_type ko = AArch T)\"\n  by (auto simp add: arch_obj_pred_defs a_type_def split: kernel_object.splits)\n\nlemma\n  arch_obj_pred_arch_obj_l[intro, simp]: \"arch_obj_pred (\\<lambda>ko. ArchObj ako = ko)\" and\n  arch_obj_pred_arch_obj_r[intro, simp]: \"arch_obj_pred (\\<lambda>ko. ko = ArchObj ako)\"\n  by (auto simp add: arch_obj_pred_defs)\n\nlemma arch_obj_pred_fun_lift: \"arch_obj_pred (\\<lambda>ko. F (arch_obj_fun_lift P N ko))\"\n  by (simp add: arch_obj_pred_defs)\n\nlemmas arch_obj_pred_fun_lift_id[simp]\n  = arch_obj_pred_fun_lift[where F=id, simplified]\n\nlemmas arch_obj_pred_fun_lift_k[intro]\n  = arch_obj_pred_fun_lift[where F=\"K R\" for R, simplified]\n\nlemmas arch_obj_pred_fun_lift_el[simp]\n  = arch_obj_pred_fun_lift[where F=\"\\<lambda> S. x \\<in> S\" for x, simplified]\n\nlemma arch_obj_pred_const_conjI[intro]:\n  \"arch_obj_pred P \\<Longrightarrow>\n    arch_obj_pred P' \\<Longrightarrow>\n    arch_obj_pred (\\<lambda>ko. P ko \\<and> P' ko)\"\n  apply (simp only: arch_obj_pred_def)\n  apply blast\n  done\n\nlemma arch_obj_pred_fI:\n  \"(\\<And>x. arch_obj_pred (P x)) \\<Longrightarrow> arch_obj_pred (\\<lambda>ko. f (\\<lambda>x :: 'a :: type. P x ko))\"\n  apply (simp only: arch_obj_pred_def)\n  apply (intro allI impI)\n  apply (rule arg_cong[where f=f])\n  by blast\n\ndeclare\n  arch_obj_pred_fI[where f=All, intro]\n  arch_obj_pred_fI[where f=Ex, intro]\n\nlocale arch_only_obj_pred =\n  fixes P :: \"kernel_object \\<Rightarrow> bool\"\n  assumes arch_only: \"arch_obj_pred P\"\n\nlemma set_object_typ_at [wp]:\n  \"\\<lbrace>\\<lambda>s. P (typ_at T p' s)\\<rbrace>\n  set_object p ko \\<lbrace>\\<lambda>rv s. P (typ_at T p' s)\\<rbrace>\"\n  apply (simp add: set_object_def get_object_def)\n  apply wp\n  apply clarsimp\n  apply (erule rsubst [where P=P])\n  apply (clarsimp simp: obj_at_def)\n  done\n\nlemma set_object_neg_ko:\n  \"\\<lbrace>not ko_at ko' p' and K (p = p' \\<longrightarrow> ko \\<noteq> ko')\\<rbrace>\n  set_object p ko\n  \\<lbrace>\\<lambda>_ s. \\<not> ko_at ko' p' s\\<rbrace>\"\n  apply (simp add: set_object_def get_object_def)\n  apply wp\n  apply (simp add: pred_neg_def obj_at_def)\n  done\n\nlemma get_tcb_SomeD: \"get_tcb t s = Some v \\<Longrightarrow> kheap s t = Some (TCB v)\"\n  apply (case_tac \"kheap s t\", simp_all add: get_tcb_def)\n  apply (case_tac a, simp_all)\n  done\n\nlemma get_tcb_at: \"tcb_at t s \\<Longrightarrow> (\\<exists>tcb. get_tcb t s = Some tcb)\"\n  by (simp add: tcb_at_def)\n\nlemma typ_at_same_type:\n  assumes \"typ_at T p s\" \"a_type k = a_type ko\" \"kheap s p' = Some ko\"\n  shows \"typ_at T p (s\\<lparr>kheap := kheap s(p' \\<mapsto> k)\\<rparr>)\"\n  using assms\n  by (clarsimp simp: obj_at_def)\n\n\nlemma hoare_to_pure_kheap_upd:\n  assumes hoare[rule_format]:\n    \"\\<And>f. (\\<And>P p T. \\<lbrace>\\<lambda>s. P (typ_at (AArch T) p s)\\<rbrace>\n      f \\<lbrace>\\<lambda>r s. P (typ_at (AArch T) p s)\\<rbrace>) \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>_. P\\<rbrace>\"\n  assumes typ_eq: \"a_type k = a_type ko\"\n  assumes valid: \"P (s :: ('z :: state_ext) state)\"\n  assumes at: \"ko_at ko p s\"\n  shows \"P (s\\<lparr>kheap := kheap s(p \\<mapsto> k)\\<rparr>)\"\n  apply (rule use_valid[where f=\"\n      do\n        s' <- get;\n        assert (s' = s);\n        (modify (\\<lambda>s. s\\<lparr>kheap := kheap s(p \\<mapsto> k)\\<rparr>));\n        return undefined\n      od\", OF _ hoare valid])\n  apply (fastforce simp add: simpler_modify_def get_def bind_def\n                             assert_def return_def[abs_def] fail_def)[1]\n  apply wp\n  apply (insert typ_eq at)\n  apply clarsimp\n  apply (erule_tac P=P in rsubst)\n  by (auto simp add: obj_at_def a_type_def split: kernel_object.splits if_splits)\n\nlemma set_object_wp:\n  \"\\<lbrace>\\<lambda>s. Q (s\\<lparr> kheap := kheap s (p \\<mapsto> v)\\<rparr>) \\<rbrace> set_object p v \\<lbrace>\\<lambda>_. Q\\<rbrace>\"\n  apply (simp add: set_object_def get_object_def)\n  apply wp\n  apply blast\n  done\n\nlemma get_object_wp:\n  \"\\<lbrace>\\<lambda>s. \\<forall>ko. ko_at ko p s \\<longrightarrow> Q ko s\\<rbrace> get_object p \\<lbrace>Q\\<rbrace>\"\n  apply (clarsimp simp: get_object_def)\n  apply wp\n  apply (clarsimp simp: obj_at_def)\n  done\n\n(* FIXME: move *)\nlemma hoare_strengthen_pre_via_assert_forward:\n  assumes pos: \"\\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  assumes rel: \"\\<And>s. S s \\<Longrightarrow> P s \\<or> N s\"\n  assumes neg: \"\\<lbrace> N \\<rbrace> f \\<lbrace> \\<bottom>\\<bottom> \\<rbrace>\"\n  shows \"\\<lbrace> S \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  apply (rule hoare_weaken_pre)\n   apply (rule hoare_strengthen_post)\n    apply (rule hoare_vcg_disj_lift[OF pos neg])\n   apply simp\n  apply (erule rel)\n  done\n\nlemma hoare_set_object_weaken_pre:\n  assumes \"\\<lbrace>P\\<rbrace> set_object p v \\<lbrace>\\<lambda>_. Q\\<rbrace>\"\n  shows \"\\<lbrace>\\<lambda>s. \\<forall>ko. ko_at ko p s \\<longrightarrow> (a_type v = a_type ko) \\<longrightarrow> P s\\<rbrace>\n         set_object p v\n         \\<lbrace>\\<lambda>_. Q\\<rbrace>\"\n  apply (rule hoare_strengthen_pre_via_assert_forward\n                [OF assms, where N=\"\\<lambda>s. \\<forall>ko. ko_at ko p s \\<longrightarrow> a_type ko \\<noteq> a_type v\"])\n  apply fastforce\n  apply (simp add: set_object_def)\n  apply (rule hoare_seq_ext[OF _ get_object_sp])\n  apply (rule hoare_seq_ext[OF _ assert_sp])\n  apply (fastforce intro: hoare_weaken_pre[OF hoare_pre_cont])\n  done\n\nlemmas set_object_wp_strong = hoare_set_object_weaken_pre[OF set_object_wp]\n\nend\n", "meta": {"author": "NICTA", "repo": "l4v", "sha": "3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b", "save_path": "github-repos/isabelle/NICTA-l4v", "path": "github-repos/isabelle/NICTA-l4v/l4v-3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b/proof/invariant-abstract/KHeapPre_AI.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.63341024983754, "lm_q2_score": 0.42632159254749025, "lm_q1q2_score": 0.27003646644664375}}
{"text": "(*  Title:       Jive Data and Store Model\n    Author:      Norbert Schirmer <schirmer at informatik.tu-muenchen.de>  and  \n                 Nicole Rauch <rauch at informatik.uni-kl.de>, 2005\n    Maintainer:  Nicole Rauch <rauch at informatik.uni-kl.de>\n    License:     LGPL\n*)\n\nsection \\<open>The Direct Subtype Relation of Java Types\\<close>\n\ntheory DirectSubtypes\nimports \"../Isabelle/JavaType\"\nbegin\n\ntext \\<open>\nIn this theory, we formalize the direct subtype relations of the Java types (as defined\nin Sec. \\ref{java_typeid_definitions}) that appear in the program to be verified. Thus, this\ntheory has to be generated for each program.\n\\label{direct_subtype_relations}\n\\<close>\n\ntext \\<open>We have the following type hierarchy:\n\\begin{center}\n\\includegraphics[width=13cm]{TypeHierarchy}\n\\end{center}\nWe need to describe all direct subtype relations of this  type hierarchy.\nAs you can see in the picture, all unnecessary direct subtype relations can be\nignored, e.g. the subclass relation between CounterImpl and Object, because it is \nadded\ntransitively by the widening relation of types (see Sec. \\ref{widening_subtypes}).\n\\<close>\n\ntext \\<open>\nWe have to specify the direct subtype relation between\n\\begin{itemize}\n\\item each ``leaf'' class or interface and its subtype \\texttt{NullT}\n\\item each ``root'' class or interface and its supertype \\texttt{Object}\n\\item each two types that are direct subtypes as specified in the code by\n\\texttt{extends} or \\texttt{implements}\n\\item each array type of a primitive type and its subtype \\texttt{NullT}\n\\item each array type of a primitive type and its supertype \\texttt{Object}\n\\item each array type of a ``leaf'' class or interface and its subtype \\texttt{NullT}\n\\item the array type \\texttt{Object[]} and its supertype \\texttt{Object}\n\\item two array types if their element types are in a subtype hierarchy\n\\end{itemize}\n\\<close>\n\ndefinition direct_subtype :: \"(Javatype * Javatype) set\" where\n\"direct_subtype =\n{ (NullT, AClassT Dummy),\n  (NullT, CClassT UndoCounter), \n  (NullT, CClassT NullPointerException),\n  (NullT, CClassT ClassCastException),\n\n  (AClassT Dummy, CClassT Object),\n  (InterfaceT Counter, CClassT Object),\n  (CClassT Exception, CClassT Object), \n\n  (CClassT UndoCounter, CClassT CounterImpl), \n  (CClassT CounterImpl, InterfaceT Counter),\n  (CClassT NullPointerException, CClassT Exception),\n  (CClassT ClassCastException, CClassT Exception),\n\n  (NullT, ArrT BoolAT),\n  (NullT, ArrT IntgAT),\n  (NullT, ArrT ShortAT),\n  (NullT, ArrT ByteAT),\n  (ArrT BoolAT,  CClassT Object),\n  (ArrT IntgAT,  CClassT Object),\n  (ArrT ShortAT, CClassT Object),\n  (ArrT ByteAT,  CClassT Object),\n\n  (NullT, ArrT (AClassAT Dummy)),\n  (NullT, ArrT (CClassAT UndoCounter)),\n  (NullT, ArrT (CClassAT NullPointerException)),\n  (NullT, ArrT (CClassAT ClassCastException)),\n\n  (ArrT (CClassAT Object),      CClassT Object),\n\n  (ArrT (AClassAT Dummy),       ArrT (CClassAT Object)),\n  (ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)), \n  (ArrT (InterfaceAT Counter),  ArrT (CClassAT Object)),\n  (ArrT (CClassAT Exception),   ArrT (CClassAT Object)), \n  (ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)), \n  (ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)),\n  (ArrT (CClassAT ClassCastException),   ArrT (CClassAT Exception))\n}\"\n\ntext \\<open>This lemma is used later in the Simplifier.\\<close>\n\nlemma direct_subtype:\n  \"(NullT, AClassT Dummy) \\<in> direct_subtype\"\n  \"(NullT, CClassT UndoCounter) \\<in> direct_subtype\" \n  \"(NullT, CClassT NullPointerException) \\<in> direct_subtype\"\n  \"(NullT, CClassT ClassCastException) \\<in> direct_subtype\"\n\n  \"(AClassT Dummy, CClassT Object) \\<in> direct_subtype\"\n  \"(InterfaceT Counter, CClassT Object) \\<in> direct_subtype\"\n  \"(CClassT Exception, CClassT Object) \\<in> direct_subtype\" \n\n  \"(CClassT UndoCounter, CClassT CounterImpl) \\<in> direct_subtype\" \n  \"(CClassT CounterImpl, InterfaceT Counter) \\<in> direct_subtype\"\n  \"(CClassT NullPointerException, CClassT Exception) \\<in> direct_subtype\"\n  \"(CClassT ClassCastException, CClassT Exception) \\<in> direct_subtype\"\n\n  \"(NullT, ArrT BoolAT) \\<in> direct_subtype\"\n  \"(NullT, ArrT IntgAT) \\<in> direct_subtype\"\n  \"(NullT, ArrT ShortAT) \\<in> direct_subtype\"\n  \"(NullT, ArrT ByteAT) \\<in> direct_subtype\"\n  \"(ArrT BoolAT,  CClassT Object) \\<in> direct_subtype\"\n  \"(ArrT IntgAT,  CClassT Object) \\<in> direct_subtype\"\n  \"(ArrT ShortAT, CClassT Object) \\<in> direct_subtype\"\n  \"(ArrT ByteAT,  CClassT Object) \\<in> direct_subtype\"\n\n  \"(NullT, ArrT (AClassAT Dummy)) \\<in> direct_subtype\"\n  \"(NullT, ArrT (CClassAT UndoCounter)) \\<in> direct_subtype\"\n  \"(NullT, ArrT (CClassAT NullPointerException)) \\<in> direct_subtype\"\n  \"(NullT, ArrT (CClassAT ClassCastException)) \\<in> direct_subtype\"\n\n  \"(ArrT (CClassAT Object),      CClassT Object) \\<in> direct_subtype\"\n\n  \"(ArrT (AClassAT Dummy),       ArrT (CClassAT Object)) \\<in> direct_subtype\"\n  \"(ArrT (CClassAT CounterImpl), ArrT (InterfaceAT Counter)) \\<in> direct_subtype\" \n  \"(ArrT (InterfaceAT Counter),  ArrT (CClassAT Object)) \\<in> direct_subtype\"\n  \"(ArrT (CClassAT Exception),   ArrT (CClassAT Object)) \\<in> direct_subtype\" \n  \"(ArrT (CClassAT UndoCounter), ArrT (CClassAT CounterImpl)) \\<in> direct_subtype\" \n  \"(ArrT (CClassAT NullPointerException), ArrT (CClassAT Exception)) \\<in> direct_subtype\"\n  \"(ArrT (CClassAT ClassCastException),   ArrT (CClassAT Exception)) \\<in> direct_subtype\"\n  by (simp_all add: direct_subtype_def)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/JiveDataStoreModel/Isa_Counter/DirectSubtypes.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6113819874558604, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.27003092000884227}}
{"text": "theory MMU_Instants_TLB\nimports\n  TLBJ.Simp_Lemmas\n  TLBJ.ARM_Monadic\n                            \nbegin\n\nrecord non_det_tlb_state = state + \n           non_det_tlb :: \"unit tlb\"\n\nrecord det_tlb_state = state + \n           det_tlb :: \"unit tlb\"\n\nrecord sat_tlb_state = state + \n           sat_tlb :: \"unit tlb\"\n\nrecord set_tlb_state = state + \n           set_tlb :: \"vaddr set\"\n\n\ndefinition \n  typ_non_det_tlb :: \"'a non_det_tlb_state_scheme \\<Rightarrow> unit tlb state_scheme\"\nwhere\n  \"typ_non_det_tlb s =  state.extend (state.truncate s) (non_det_tlb s)\"\n\ndefinition \n  typ_det_tlb :: \"'a det_tlb_state_scheme \\<Rightarrow> unit tlb state_scheme\"\nwhere\n  \"typ_det_tlb s =  state.extend (state.truncate s) (det_tlb s)\"\n\ndefinition \n  typ_sat_tlb :: \"'a sat_tlb_state_scheme \\<Rightarrow> unit tlb state_scheme\"\nwhere\n  \"typ_sat_tlb s =  state.extend (state.truncate s) (sat_tlb s)\"\n\ndefinition \n  typ_set_tlb :: \"'a set_tlb_state_scheme \\<Rightarrow> vaddr set state_scheme\"\nwhere\n  \"typ_set_tlb s =  state.extend (state.truncate s) (set_tlb s)\"\n\n\nlemma non_det_tlb_more [simp]:\n  \"state.more (typ_non_det_tlb s) = non_det_tlb s\"\n  by (clarsimp simp: typ_non_det_tlb_def state.defs)\n\n\nlemma det_tlb_more [simp]:\n  \"state.more (typ_det_tlb s) = det_tlb s\"\n  by (clarsimp simp: typ_det_tlb_def state.defs)\n\n\nlemma sat_tlb_more [simp]:\n  \"state.more (typ_sat_tlb s) = sat_tlb s\"\n  by (clarsimp simp: typ_sat_tlb_def state.defs)\n\n\nlemma set_tlb_more [simp]:\n  \"state.more (typ_set_tlb s) = set_tlb s\"\n  by (clarsimp simp: typ_set_tlb_def state.defs)\n\n\nlemma non_det_tlb_truncate [simp]:\n  \"state.truncate (typ_non_det_tlb s') = state.truncate s'\"\n  by (clarsimp simp: typ_non_det_tlb_def state.defs)\n\nlemma det_tlb_truncate [simp]:\n  \"state.truncate (typ_det_tlb s') = state.truncate s'\"\n  by (clarsimp simp: typ_det_tlb_def state.defs)\n\nlemma sat_tlb_truncate [simp]:\n  \"state.truncate (typ_sat_tlb s') = state.truncate s'\"\n  by (clarsimp simp: typ_sat_tlb_def state.defs)\n\nlemma set_tlb_truncate [simp]:\n  \"state.truncate (typ_set_tlb s') = state.truncate s'\"\n  by (clarsimp simp: typ_set_tlb_def state.defs)\n\nlemma typ_non_det_prim_parameter [simp]:\n  \"TTBR0 (typ_non_det_tlb s) =  TTBR0 s \\<and> MEM (typ_non_det_tlb s) = MEM s \\<and> exception (typ_non_det_tlb s) = exception s\"\n  by (clarsimp simp: typ_non_det_tlb_def  state.defs)\n\n\nlemma typ_det_prim_parameter [simp]:\n  \"TTBR0 (typ_det_tlb s) =  TTBR0 s \\<and> MEM (typ_det_tlb s) = MEM s \\<and> exception (typ_det_tlb s) = exception s\"\n  by (clarsimp simp: typ_det_tlb_def  state.defs)\n\n\nlemma typ_sat_prim_parameter [simp]:\n  \"TTBR0 (typ_sat_tlb s) =  TTBR0 s \\<and> MEM (typ_sat_tlb s) = MEM s \\<and> exception (typ_sat_tlb s) = exception s\"\n  by (clarsimp simp: typ_sat_tlb_def  state.defs)\n\n\nlemma typ_set_prim_parameter [simp]:\n  \"TTBR0 (typ_set_tlb s) =  TTBR0 s \\<and> MEM (typ_set_tlb s) = MEM s \\<and> exception (typ_set_tlb s) = exception s\"\n  by (clarsimp simp: typ_set_tlb_def  state.defs)\n\n\nabbreviation\n  \"consistent (s:: unit tlb_entry set state_scheme) \\<equiv>\n               consistent0  (lookup' (state.more s)) (pt_walk () (MEM s) (TTBR0 s))\"\n\n\ndefinition\n  saturated :: \"unit tlb_entry set state_scheme \\<Rightarrow> bool\"\nwhere\n  \"saturated s  \\<equiv> the ` {e\\<in>pt_walk () (MEM s) (TTBR0 s) ` UNIV. \\<not>is_fault e} \\<subseteq> state.more s\"\n\n\ndefinition \n  tlb_rel_det :: \"unit tlb_entry set state_scheme \\<Rightarrow> unit tlb_entry set state_scheme \\<Rightarrow> bool\"\nwhere                                                                \n  \"tlb_rel_det s t \\<equiv> state.truncate s = state.truncate t \\<and>  state.more s \\<subseteq> state.more t\"\n\ndefinition \n  tlb_rel_sat :: \"unit tlb_entry set state_scheme \\<Rightarrow> unit tlb_entry set state_scheme \\<Rightarrow> bool\"\nwhere                                                                \n  \"tlb_rel_sat s t \\<equiv> state.truncate s = state.truncate t \\<and>  state.more s \\<subseteq> state.more t  \\<and>  saturated t\"\n\n\ndefinition \n   inconsistent_vaddrs :: \"unit tlb_entry set state_scheme \\<Rightarrow>  vaddr set\"\nwhere                                                        \n  \"inconsistent_vaddrs s  \\<equiv>  {va. lookup' (state.more s) va = Incon}\"\n\n\n\ndefinition                              \n   incoherrent_vaddrs :: \"unit tlb_entry set state_scheme \\<Rightarrow>  vaddr set\"\nwhere                                                         \n  \"incoherrent_vaddrs s  \\<equiv> {va. \\<exists>x. lookup' (state.more s) va = Hit x \\<and> is_fault (pt_walk () (MEM s) (TTBR0 s) va)} \"\n\n\ndefinition                              \n   incon_addrs :: \"unit tlb_entry set state_scheme \\<Rightarrow>  vaddr set\"\nwhere                                                         \n  \"incon_addrs s  \\<equiv>  inconsistent_vaddrs s \\<union> incoherrent_vaddrs s\"\n\n\ndefinition \n  tlb_rel_abs :: \"unit tlb_entry set state_scheme  \\<Rightarrow> vaddr set state_scheme \\<Rightarrow> bool\"\nwhere                                                                \n\"tlb_rel_abs s t \\<equiv>  state.truncate s = state.truncate t \\<and> incon_addrs s \\<subseteq> state.more t \\<and> saturated s\" \n\n\ndeclare return_def [simp add]\ndeclare bind_def [simp add]\ndeclare read_state_def [simp add]\ndeclare update_state_def [simp add]\ndeclare extend_state_def [simp add]\ndeclare trim_state_def [simp add]\n\nlemma tlb_rel_detD:\n  \"tlb_rel_det s t \\<Longrightarrow>  MEM t = MEM s \\<and> TTBR0 t = TTBR0 s \\<and> state.more s \\<subseteq> state.more t  \\<and>  exception t = exception s\"\n  by (clarsimp simp: tlb_rel_det_def state.defs)\n\nlemma tlb_rel_satD:\n  \"tlb_rel_sat s t \\<Longrightarrow> MEM t = MEM s \\<and> TTBR0 t = TTBR0 s \\<and> state.more s \\<subseteq> state.more t \\<and> exception t = exception s  \\<and> saturated t\"\n  by (clarsimp simp: tlb_rel_sat_def state.defs)\n\nlemma tlb_rel_det_consistent:\n  \"\\<lbrakk> tlb_rel_det s t; consistent t va \\<rbrakk> \\<Longrightarrow> consistent s va\"\n   by (insert tlb_rel_detD [of s t] , clarsimp ,drule tlb_mono [of _ _ \"va\"] ,auto simp: consistent0_def less_eq_lookup_type)\n\n\nlemma tlb_rel_sat_consistent:\n  \"\\<lbrakk> tlb_rel_sat s t; consistent t va \\<rbrakk> \\<Longrightarrow> consistent s va\"\n   by (insert tlb_rel_satD [of s t] , clarsimp ,drule tlb_mono [of _ _ \"va\"] ,auto simp: consistent0_def less_eq_lookup_type)\n\nlemma sat_state_tlb:\n  \"saturated s  \\<Longrightarrow> state.more s = state.more s \\<union> the ` {e \\<in> range (pt_walk () (MEM s) (TTBR0 s)). \\<not> is_fault e}\"\n  by (fastforce simp: saturated_def)\n\n\nlemma saturated_tlb_pde:\n  \"saturated (typ_sat_tlb s) \\<Longrightarrow> (sat_tlb s) = sat_tlb s \\<union> the ` {e\\<in>pt_walk ()  (MEM s) (TTBR0 s) ` UNIV. \\<not>is_fault e}\"\n apply (clarsimp simp:  saturated_def fst_def) apply (cases s ; clarsimp)  by blast\n\n\nlemma sat_miss_fault:\n  \"\\<lbrakk> saturated (typ_sat_tlb s); lookup' (sat_tlb s)   va = Miss \\<rbrakk> \\<Longrightarrow> \n           is_fault (pt_walk () (MEM s) (TTBR0 s) va)\"\n  apply (subgoal_tac \" lookup' ((sat_tlb s)  \\<union> the ` {e \\<in> range (pt_walk ()   (MEM s) (TTBR0 s)). \\<not> is_fault e})   va = Miss\")\n   apply (thin_tac \"lookup' ((sat_tlb s))   va = Miss\")\n   apply (drule lookup_miss_union)\n   apply clarsimp\n   apply (drule lookup_miss_is_fault)\n   apply clarsimp\n  using  sat_state_tlb by force\n\n\nlemma saturatd_lookup_hit_no_fault:\n  \"\\<lbrakk>saturated (typ_sat_tlb s); \n    lookup' (sat_tlb s)   b = Hit x; \\<not> is_fault (pt_walk ()  (MEM s) (TTBR0 s) b)\\<rbrakk> \\<Longrightarrow>\n                       x = the (pt_walk ()   (MEM s) (TTBR0 s) b)\"\n  apply (subgoal_tac \"lookup'(sat_tlb s \\<union> \n                              the ` {e \\<in> range (pt_walk ()   (MEM s) (TTBR0 s)). \\<not> is_fault e})   (  b) = Hit x\")\n   prefer 2\n   apply (drule sat_state_tlb, clarsimp simp: state.defs)\n  apply (drule lookup_hit_miss_or_hit')\n  apply (erule disjE)\n   apply (clarsimp simp: lookup_range_pt_walk_hit)\n  apply (frule lookup_range_fault_pt_walk)\n  apply (drule_tac x = b in bspec; clarsimp simp: lookup_hit_entry_range)\n  done\n\nlemma saturated_tlb:\n  \"saturated (typ_sat_tlb s) \\<Longrightarrow> sat_tlb s = sat_tlb s \\<union> the ` {e\\<in>pt_walk ()   (MEM s) (TTBR0 s) ` UNIV. \\<not>is_fault e} \"\n apply (clarsimp simp:  saturated_def fst_def) apply (cases s ; clarsimp)  by blast\n\n\nlemma write_mem_eq_TLB:\n  \"\\<lbrakk> write'mem1 (val, va, sz) s = ((), s') \\<rbrakk>  \\<Longrightarrow> state.more s' = state.more s\"\n   by (clarsimp simp: write'mem1_def raise'exception_def split: if_split_asm)\n\n\nlemma write_same_mem:\n  \"\\<lbrakk> write'mem1 (val, va, sz) s = ((), s') ; write'mem1 (val, va, sz) t = ((), t') ;\n      MEM s = MEM t\\<rbrakk>  \\<Longrightarrow>  MEM s' = MEM t'\"\n  by (clarsimp simp: write'mem1_def raise'exception_def split:if_split_asm)\n\nlemma write_same_mem_excep:\n  \"\\<lbrakk> write'mem1 (val, pa, sz) s = ((), s') ; write'mem1 (val, pa, sz) t = ((), t') ;\n      MEM s = MEM t ; exception s = exception t \\<rbrakk>  \\<Longrightarrow> exception s' = exception t'\"\n   by (clarsimp simp: write'mem1_def raise'exception_def split:if_split_asm)\n\n\nlemma write_mem_rel:\n  \"\\<lbrakk> write'mem1 (val, va, sz) s = ((), s') \\<rbrakk>  \\<Longrightarrow> s' = s \\<lparr> MEM:= MEM s' , exception:= exception s' \\<rparr>\"\n   by (clarsimp simp: write'mem1_def raise'exception_def split: if_split_asm)\n\nlemma not_member_incon_consistent:\n  \"\\<lbrakk>va \\<notin>  incon_addrs (typ_sat_tlb s) ; saturated (typ_sat_tlb s) \\<rbrakk> \\<Longrightarrow> \n                                       consistent (typ_sat_tlb s) va\"\n  apply (clarsimp simp: incon_addrs_def inconsistent_vaddrs_def incoherrent_vaddrs_def consistent0_def)\n  apply (erule disjE)\n   apply (rule conjI)\n    apply (meson lookup_type.exhaust )\n   apply (meson lookup_type.exhaust) \n  using not_miss_incon_hit saturatd_lookup_hit_no_fault by blast\n  \n\nlemma tlb_rel_abs_consistent [simp]:\n  \"\\<lbrakk>va \\<notin> set_tlb t ;   tlb_rel_abs  (typ_sat_tlb s) (typ_set_tlb t)  \\<rbrakk>  \\<Longrightarrow> \n           consistent (typ_sat_tlb s) va \" \n  apply (rule not_member_incon_consistent ; clarsimp simp: tlb_rel_abs_def) \n  by blast\n\n\nlemma tlb_rel_absD:\n  \"tlb_rel_abs s t \\<Longrightarrow> MEM t = MEM s \\<and> TTBR0 t = TTBR0 s  \\<and>  saturated s \\<and> \n                        incon_addrs s  \\<subseteq> state.more t \\<and> exception t = exception s\"\n  by (clarsimp simp: tlb_rel_abs_def state.defs)\n\n\n(*      ARM Monadic Simplification Lemmas     *)\n\nlemma mem1_exception:\n  \"mem1 p s = (val, t) \\<Longrightarrow>  t = s\\<lparr>exception := exception t\\<rparr>\"\n  apply (clarsimp simp: mem1_def)\n  apply (cases \"MEM s p\")\n   apply (clarsimp simp: raise'exception_def split: if_split_asm)\n  apply clarsimp\ndone\n\n\nlemma mem1_read_exception:\n  \"mem_read1 (a, sz) b = (val, r) \\<Longrightarrow> r = b \\<lparr>exception := exception r\\<rparr>\"\n  apply (clarsimp simp: mem_read1_def)\n  apply (clarsimp split: if_split_asm)\n      apply (case_tac \"mem1 (a r+ 0) b\" , clarsimp)\n      apply (clarsimp simp: mem1_exception)\n     apply (case_tac \"mem1 (a r+ 1) b\" , clarsimp)\n     apply (case_tac \"mem1 (a r+ 0) ba\", clarsimp)\n     apply (drule mem1_exception)\n     apply (drule mem1_exception)\n     apply (cases b, case_tac ba, cases r ,clarsimp)\n    apply (case_tac \"mem1 (a r+ 3) b\" , clarsimp)\n    apply (case_tac \"mem1 (a r+ 2) ba\", clarsimp)\n    apply (case_tac \"mem1 (a r+ 1) baa\", clarsimp)\n    apply (case_tac \"mem1 (a r+ 0) bb\", clarsimp)\n    apply (drule mem1_exception)\n    apply (drule mem1_exception)\n    apply (drule mem1_exception)\n    apply (drule mem1_exception)\n    apply (cases b, case_tac ba, case_tac baa, case_tac bb , cases r ,clarsimp)\n   apply (case_tac \"mem1 (a r+ 7) b\" , clarsimp)\n   apply (case_tac \"mem1 (a r+ 6) ba\", clarsimp)\n   apply (case_tac \"mem1 (a r+ 5) baa\", clarsimp)\n   apply (case_tac \"mem1 (a r+ 4) bb\", clarsimp)\n   apply (case_tac \"mem1 (a r+ 3) bc\", clarsimp)\n   apply (case_tac \"mem1 (a r+ 2) bd\", clarsimp)\n   apply (case_tac \"mem1 (a r+ 1) be\", clarsimp)\n   apply (case_tac \"mem1 (a r+ 0) bf\", clarsimp)\n   apply (drule mem1_exception)\n   apply (drule mem1_exception)\n   apply (drule mem1_exception)\n   apply (drule mem1_exception)\n   apply (drule mem1_exception)\n   apply (drule mem1_exception)\n   apply (drule mem1_exception)\n   apply (drule mem1_exception)\n   apply (cases b, case_tac ba, case_tac baa, case_tac bb ,case_tac bc ,\n                   case_tac bd ,  case_tac be ,  case_tac bf , cases r ,clarsimp)\n  apply (clarsimp simp: raise'exception_def split:if_split_asm)\ndone\n\nlemma write_mem_state_trun_equal:\n  \"\\<lbrakk>  write'mem1 (val, pa, sz) s = ((), s'); write'mem1 (val, pa, sz) t = ((), t'); \n     state.truncate s = state.truncate t \\<rbrakk>  \\<Longrightarrow> state.truncate s' = state.truncate t'\"\n  apply (frule write_mem_rel)\n  apply rotate_tac\n  apply (frule write_mem_rel)\n  apply (subgoal_tac \"MEM s' = MEM t' \\<and> exception s' = exception t'\")\n   apply clarsimp\n   apply (cases s, cases t, cases s', cases t', clarsimp simp: state.defs)\n  apply (cases s, cases t, cases s', cases t', clarsimp simp: state.defs)\n  apply (clarsimp simp: write'mem1_def Let_def state.defs raise'exception_def split:if_split_asm)\n  done\n\nlemma write_mem1_eq_ASID_TTBR0:\n  \"\\<lbrakk> write'mem1 (val, va, sz) s = ((), s') \\<rbrakk>  \\<Longrightarrow> TTBR0 s' = TTBR0 s\"\n   by (clarsimp simp: write'mem1_def raise'exception_def split: if_split_asm)\n\nlemma tlb_sat_set_mem1 [simp]:\n  \"sat_tlb (snd (mem1 ps s)) = sat_tlb s\"\n  by (simp add: mem1_def raise'exception_def split: option.splits)\n\n\n\nconsts tlb_evict :: \"'a state_scheme \\<Rightarrow> 'a\"\n\n\ninstantiation non_det_tlb_state_ext :: (type) mmu       \nbegin\n  definition                          \n  \"(mmu_translate va :: ('a non_det_tlb_state_scheme \\<Rightarrow> _))\n = do {\n     update_state (\\<lambda>s. s\\<lparr> non_det_tlb := non_det_tlb s - tlb_evict (typ_non_det_tlb s) \\<rparr>);\n     mem   <- read_state MEM;\n     ttbr0 <- read_state TTBR0;\n     tlb   <- read_state non_det_tlb;\n          case lookup' tlb va of \n               Hit entry \\<Rightarrow> return (va_to_pa va entry)\n          |    Miss \\<Rightarrow> \n                   do { \n                       let entry = pt_walk () mem ttbr0 va;\n                       if is_fault entry \n                       then raise'exception (PAGE_FAULT ''more info'')\n                       else do {\n                                   update_state (\\<lambda>s. s\\<lparr> non_det_tlb := non_det_tlb s \\<union>  {the entry} \\<rparr>);\n                                   return (va_to_pa va (the entry)) } }\n          |    Incon \\<Rightarrow> raise'exception (IMPLEMENTATION_DEFINED ''set on fire'') \n   }\"\n\nthm mmu_translate_non_det_tlb_state_ext_def                    \n\ndefinition\n \"(mmu_read_size  :: (vaddr \\<times> nat \\<Rightarrow>  'a non_det_tlb_state_scheme \\<Rightarrow> bool list \\<times>  'a non_det_tlb_state_scheme))\n  \\<equiv> \\<lambda>(va,size). do {\n                     pa  \\<leftarrow> mmu_translate va :: ('a non_det_tlb_state_scheme \\<Rightarrow> _);\n                     mem_read1 (pa , size)\n  }\"\n\ndefinition   \n  \"(mmu_write_size  :: (bool list \\<times> vaddr \\<times> nat \\<Rightarrow> 'a non_det_tlb_state_scheme \\<Rightarrow> unit \\<times> 'a non_det_tlb_state_scheme))\n   \\<equiv> \\<lambda>(value, va, size). do {\n     pa <- mmu_translate va :: ('a non_det_tlb_state_scheme \\<Rightarrow> _);\n     exception <- read_state exception;\n     if exception = NoException \n       then  write'mem1 (value, pa, size)\n       else return ()\n  }\"\n(* print_context *)                      \n\n\ndefinition\n  \"(update_TTBR0 r :: ('a non_det_tlb_state_scheme \\<Rightarrow> _))  = \ndo {\n    update_state (\\<lambda>s. s\\<lparr> TTBR0 := r \\<rparr>)\n  } \"\n\ndefinition   \n  \"(flush f :: ('a non_det_tlb_state_scheme \\<Rightarrow> _))  \\<equiv> \n           case f of FlushTLB \\<Rightarrow> update_state (\\<lambda>s. s\\<lparr> non_det_tlb := {} \\<rparr>)\n                  | Flushvarange vset \\<Rightarrow> do {\n                                         update_state (\\<lambda>s. s\\<lparr> non_det_tlb := flush_tlb_vset (non_det_tlb s) vset \\<rparr>)}\"\n \n  instance ..\nend\n\n               \ninstantiation det_tlb_state_ext :: (_) mmu       \nbegin\n  definition                          \n  \"(mmu_translate va :: ('a det_tlb_state_scheme \\<Rightarrow> _))\n = do {\n     mem   <- read_state MEM;\n     ttbr0 <- read_state TTBR0;\n     tlb   <- read_state det_tlb;\n          case lookup' tlb va of \n               Hit entry \\<Rightarrow> return (va_to_pa va entry)\n          |    Miss \\<Rightarrow> \n                   do { \n                       let entry = pt_walk () mem ttbr0 va;\n                       if is_fault entry \n                       then raise'exception (PAGE_FAULT ''more info'')\n                       else do {\n                                   update_state (\\<lambda>s. s\\<lparr> det_tlb := det_tlb s \\<union>  {the entry} \\<rparr>);\n                                   return (va_to_pa va (the entry)) } }\n          |    Incon \\<Rightarrow> raise'exception (IMPLEMENTATION_DEFINED ''set on fire'') \n   }\"\n\nthm mmu_translate_non_det_tlb_state_ext_def                    \n\ndefinition\n \"(mmu_read_size  :: (vaddr \\<times> nat \\<Rightarrow>  'a det_tlb_state_scheme \\<Rightarrow> bool list \\<times>  'a det_tlb_state_scheme))\n  \\<equiv> \\<lambda>(va,size). do {\n                     pa  \\<leftarrow> mmu_translate va :: ('a det_tlb_state_scheme \\<Rightarrow> _);\n                     mem_read1 (pa , size)\n  }\"\n\ndefinition   \n  \"(mmu_write_size  :: (bool list \\<times> vaddr \\<times> nat \\<Rightarrow> 'a det_tlb_state_scheme \\<Rightarrow> unit \\<times> 'a det_tlb_state_scheme))\n   \\<equiv> \\<lambda>(value, va, size). do {\n     pa <- mmu_translate va :: ('a det_tlb_state_scheme \\<Rightarrow> _);\n     exception <- read_state exception;\n     if exception = NoException \n       then  write'mem1 (value, pa, size)\n       else return ()\n  }\"\n(* print_context *)                      \n\n\ndefinition\n  \"(update_TTBR0 r :: ('a det_tlb_state_scheme \\<Rightarrow> _))  = \ndo {\n    update_state (\\<lambda>s. s\\<lparr> TTBR0 := r \\<rparr>)\n  } \"\n\ndefinition   \n  \"(flush f :: ('a det_tlb_state_scheme \\<Rightarrow> _))  \\<equiv> \n           case f of FlushTLB \\<Rightarrow> update_state (\\<lambda>s. s\\<lparr> det_tlb := {} \\<rparr>)\n                  | Flushvarange vset \\<Rightarrow> do {\n                                         update_state (\\<lambda>s. s\\<lparr> det_tlb := flush_tlb_vset (det_tlb s) vset \\<rparr>)}\"\n \n  instance ..\nend\n\n\n\ninstantiation sat_tlb_state_ext :: (_) mmu       \nbegin\n  definition                          \n  \"(mmu_translate va :: ('a sat_tlb_state_scheme \\<Rightarrow> _))\n = do {\n     mem   <- read_state MEM;\n     ttbr0 <- read_state TTBR0;\n     let tlb_new = the ` {e\\<in>pt_walk () mem ttbr0 ` UNIV. \\<not>is_fault e};\n     tlb   <- read_state sat_tlb;\n     let sat_tlb' = tlb \\<union> tlb_new;\n     update_state (\\<lambda>s. s\\<lparr> sat_tlb := sat_tlb' \\<rparr>);\n          case lookup' sat_tlb' va of \n               Hit entry \\<Rightarrow> return (va_to_pa va entry)\n          |    Miss \\<Rightarrow> raise'exception (PAGE_FAULT ''more info'') \n          |    Incon \\<Rightarrow> raise'exception (IMPLEMENTATION_DEFINED ''set on fire'') \n   }\"\n\nthm mmu_translate_non_det_tlb_state_ext_def                    \n\ndefinition\n \"(mmu_read_size  :: (vaddr \\<times> nat \\<Rightarrow>  'a sat_tlb_state_scheme \\<Rightarrow> bool list \\<times>  'a sat_tlb_state_scheme))\n  \\<equiv> \\<lambda>(va,size). do {\n                     pa  \\<leftarrow> mmu_translate va :: ('a sat_tlb_state_scheme \\<Rightarrow> _);\n                     mem_read1 (pa , size)\n  }\"\n\ndefinition   \n  \"(mmu_write_size  :: (bool list \\<times> vaddr \\<times> nat \\<Rightarrow> 'a sat_tlb_state_scheme \\<Rightarrow> unit \\<times> 'a sat_tlb_state_scheme))\n   \\<equiv> \\<lambda>(value, va, size). do {\n      ttbr0 <- read_state TTBR0;\n      pa <- mmu_translate va :: ('a sat_tlb_state_scheme \\<Rightarrow> _);\n      tlb   <- read_state sat_tlb;\n      exception <- read_state exception;\n      if exception = NoException \n       then  do {\n                 write'mem1 (value, pa, size);\n                 mem'  <- read_state MEM;\n                 let tlb_new = the ` {e\\<in>pt_walk () mem' ttbr0 ` UNIV. \\<not>is_fault e};\n                 update_state (\\<lambda>s. s\\<lparr> sat_tlb := tlb \\<union> tlb_new \\<rparr>) }\n       else return ()\n  }\"\n(* print_context *)                      \n\n\ndefinition\n  \"(update_TTBR0 r :: ('a sat_tlb_state_scheme \\<Rightarrow> _))  = \ndo {\n      update_state (\\<lambda>s. s\\<lparr> TTBR0 := r \\<rparr>);\n      mem   <- read_state MEM;\n      let all_entries = the ` {e\\<in>pt_walk () mem r ` UNIV. \\<not>is_fault e};\n      tlb   <- read_state sat_tlb;\n      update_state (\\<lambda>s. s\\<lparr> sat_tlb := tlb \\<union> all_entries \\<rparr>)}\"\n\ndefinition   \n  \"(flush f :: ('a sat_tlb_state_scheme \\<Rightarrow> _))  \\<equiv> \n           case f of FlushTLB \\<Rightarrow> do {update_state (\\<lambda>s. s\\<lparr> sat_tlb := {} \\<rparr>);\n                                     mem   <- read_state MEM;\n                                     ttbr0 <- read_state TTBR0;\n                                     let tlb_new = the ` {e\\<in>pt_walk () mem ttbr0 ` UNIV. \\<not>is_fault e};\n                                     update_state (\\<lambda>s. s\\<lparr> sat_tlb := tlb_new \\<rparr>)}\n                  | Flushvarange vset \\<Rightarrow>  do {\n                                     mem   <- read_state MEM;\n                                     ttbr0 <- read_state TTBR0;\n                                     let tlb_new = the ` {e\\<in>pt_walk () mem ttbr0 ` UNIV. \\<not>is_fault e};\n                                     tlb_pde     <- read_state sat_tlb;\n                                     update_state (\\<lambda>s. s\\<lparr> sat_tlb := flush_tlb_vset tlb_pde vset \\<union> tlb_new \\<rparr>)}\"\n\n  instance ..\nend\n\n(*definition\n  ptable_comp :: \"(vaddr \\<Rightarrow> pt_walk_typ) \\<Rightarrow> (vaddr \\<Rightarrow> pt_walk_typ) \\<Rightarrow> vaddr set\"\nwhere\n  \"ptable_comp walk walk'  \\<equiv> {va. \\<not>(walk va \\<preceq> walk' va)}\"\n*)\n\ndefinition\n  ptable_comp :: \"(vaddr \\<Rightarrow> unit tlb_entry option) \\<Rightarrow> (vaddr \\<Rightarrow> unit tlb_entry option) \\<Rightarrow> vaddr set\"\nwhere\n  \"ptable_comp wlk wlk'  \\<equiv> {va. \\<not> is_fault (wlk va) \\<and> \\<not> is_fault (wlk' va) \\<and> wlk va \\<noteq> wlk' va \\<or> \n                                 \\<not> is_fault (wlk va) \\<and> is_fault (wlk' va)}\"\n\n\ndefinition\n  incon_comp :: \" heap \\<Rightarrow> heap \\<Rightarrow> paddr \\<Rightarrow> paddr \\<Rightarrow> vaddr set\"\nwhere\n  \"incon_comp  hp hp' rt rt' \\<equiv> ptable_comp (pt_walk () hp rt) (pt_walk () hp' rt')\"\n\n\ninstantiation set_tlb_state_ext :: (_) mmu       \nbegin\n  definition                          \n  \"(mmu_translate va :: ('a set_tlb_state_scheme \\<Rightarrow> _))\n = do {\n     mem   <- read_state MEM;\n     ttbr0 <- read_state TTBR0;\n     incon_vaddrs <- read_state set_tlb;\n     if  va \\<in> incon_vaddrs\n       then raise'exception (IMPLEMENTATION_DEFINED ''set on fire'')\n       else let entry = pt_walk () mem ttbr0 va in \n             if is_fault entry\n              then raise'exception (PAGE_FAULT ''more info'')\n              else return (va_to_pa va (the entry))\n    }\"\n\n                    \n\ndefinition\n \"(mmu_read_size  :: (vaddr \\<times> nat \\<Rightarrow>  'a set_tlb_state_scheme \\<Rightarrow> bool list \\<times>  'a set_tlb_state_scheme))\n  \\<equiv> \\<lambda>(va,size). do {\n                     pa  \\<leftarrow> mmu_translate va :: ('a set_tlb_state_scheme \\<Rightarrow> _);\n                     mem_read1 (pa , size)\n  }\"\n\ndefinition   \n  \"(mmu_write_size  :: (bool list \\<times> vaddr \\<times> nat \\<Rightarrow> 'a set_tlb_state_scheme \\<Rightarrow> unit \\<times> 'a set_tlb_state_scheme))\n   \\<equiv> \\<lambda>(value, va, size). do {\n      ttbr0 <- read_state TTBR0;\n      mem   <- read_state MEM; \n      paddr <- mmu_translate va :: ('a set_tlb_state_scheme \\<Rightarrow> _);\n      incon_vaddrs <- read_state set_tlb; \n      exception <- read_state exception;\n      if exception = NoException \n        then  do {\n                   write'mem1 (value, paddr, size);\n                   mem' <- read_state MEM; \n                   let ptable_comp = incon_comp mem mem' ttbr0 ttbr0;\n                   let incon_vaddrs_new    = incon_vaddrs \\<union>  ptable_comp;\n                   update_state (\\<lambda>s. s\\<lparr> set_tlb :=  incon_vaddrs_new \\<rparr>)\n            }\n        else return ()\n   }\"\n                     \n\ndefinition\n  \"(update_TTBR0 r :: ('a set_tlb_state_scheme \\<Rightarrow> _))  = \ndo {\n      ttbr0   <- read_state TTBR0;\n      update_state (\\<lambda>s. s\\<lparr> TTBR0 := r \\<rparr>);\n      incon_vaddrs   <- read_state set_tlb;\n      mem    <- read_state MEM;\n       let ptable_comp = incon_comp mem mem ttbr0 r; \n       let incon_vaddrs_new = incon_vaddrs \\<union>  ptable_comp;\n      update_state (\\<lambda>s. s\\<lparr> set_tlb := incon_vaddrs_new \\<rparr>)\n}\"\n\n\ndefinition   \n  \"(flush f :: ('a set_tlb_state_scheme \\<Rightarrow> _))  \\<equiv> \n           case f of FlushTLB \\<Rightarrow> update_state (\\<lambda>s. s\\<lparr> set_tlb := {} \\<rparr>)\n                  | Flushvarange vset \\<Rightarrow> do {\n                       incon_vaddrs   <- read_state set_tlb;\n                        update_state (\\<lambda>s. s\\<lparr> set_tlb := incon_vaddrs -vset\\<rparr>)}\"\n\n  instance ..\nend\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "tlb", "sha": "88bb017dd96c3830baed93ba62e45b45050d1417", "save_path": "github-repos/isabelle/SEL4PROJ-tlb", "path": "github-repos/isabelle/SEL4PROJ-tlb/tlb-88bb017dd96c3830baed93ba62e45b45050d1417/TLB_No_ASID/MMU_Instants_TLB.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6113819732941511, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.27003091375399757}}
{"text": "theory IICF_MS_Array_List\nimports \n  \"../Intf/IICF_List\" \n  Separation_Logic_Imperative_HOL.Array_Blit\n  \"../../../Separation_Logic_Imperative_HOL/Examples/Default_Insts\"\nbegin\n\n  type_synonym 'a ms_array_list = \"'a Heap.array \\<times> nat\"\n\n  definition \"is_ms_array_list ms l \\<equiv> \\<lambda>(a,n). \\<exists>\\<^sub>Al'. a \\<mapsto>\\<^sub>a l' * \\<up>(n \\<le> length l' \\<and> l = take n l' \\<and> ms=length l')\"\n\n  lemma is_ms_array_list_prec[safe_constraint_rules]: \"precise (is_ms_array_list ms)\"\n    unfolding is_ms_array_list_def[abs_def]\n    apply(rule preciseI)\n    apply(simp split: prod.splits) \n  \tusing preciseD snga_prec by fastforce\n\n  definition \"marl_empty_sz maxsize \\<equiv> do {\n    a \\<leftarrow> Array.new maxsize default;\n    return (a,0)\n  }\"\n\n  definition \"marl_append \\<equiv> \\<lambda>(a,n) x. do {\n      a \\<leftarrow> Array.upd n x a;\n      return (a,n+1)\n  }\"\n\n  definition marl_length :: \"'a::heap ms_array_list \\<Rightarrow> nat Heap\" where\n    \"marl_length \\<equiv> \\<lambda>(a,n). return (n)\"\n\n  definition marl_is_empty :: \"'a::heap ms_array_list \\<Rightarrow> bool Heap\" where\n    \"marl_is_empty \\<equiv> \\<lambda>(a,n). return (n=0)\"\n\n  definition marl_last :: \"'a::heap ms_array_list \\<Rightarrow> 'a Heap\" where\n    \"marl_last \\<equiv> \\<lambda>(a,n). do {\n      Array.nth a (n - 1)\n    }\"\n\n  definition marl_butlast :: \"'a::heap ms_array_list \\<Rightarrow> 'a ms_array_list Heap\" where\n    \"marl_butlast \\<equiv> \\<lambda>(a,n). do {\n      return (a,n - 1)\n    }\"\n\n  definition marl_get :: \"'a::heap ms_array_list \\<Rightarrow> nat \\<Rightarrow> 'a Heap\" where\n    \"marl_get \\<equiv> \\<lambda>(a,n) i. Array.nth a i\"\n\n  definition marl_set :: \"'a::heap ms_array_list \\<Rightarrow> nat \\<Rightarrow> 'a \\<Rightarrow> 'a ms_array_list Heap\" where\n    \"marl_set \\<equiv> \\<lambda>(a,n) i x. do { a \\<leftarrow> Array.upd i x a; return (a,n)}\"\n\n  lemma marl_empty_sz_rule[sep_heap_rules]: \"< emp > marl_empty_sz N <is_ms_array_list N []>\"\n    by (sep_auto simp: marl_empty_sz_def is_ms_array_list_def)\n\n  lemma marl_append_rule[sep_heap_rules]: \"length l < N \\<Longrightarrow>\n    < is_ms_array_list N l a > \n      marl_append a x \n    <\\<lambda>a. is_ms_array_list N (l@[x]) a >\\<^sub>t\"  \n    by (sep_auto \n      simp: marl_append_def is_ms_array_list_def take_update_last \n      split: prod.splits)\n    \n  lemma marl_length_rule[sep_heap_rules]: \"\n    <is_ms_array_list N l a> \n      marl_length a\n    <\\<lambda>r. is_ms_array_list N l a * \\<up>(r=length l)>\"\n    by (sep_auto simp: marl_length_def is_ms_array_list_def)\n    \n  lemma marl_is_empty_rule[sep_heap_rules]: \"\n    <is_ms_array_list N l a> \n      marl_is_empty a\n    <\\<lambda>r. is_ms_array_list N l a * \\<up>(r\\<longleftrightarrow>(l=[]))>\"\n    by (sep_auto simp: marl_is_empty_def is_ms_array_list_def)\n\n  lemma marl_last_rule[sep_heap_rules]: \"\n    l\\<noteq>[] \\<Longrightarrow>\n    <is_ms_array_list N l a> \n      marl_last a\n    <\\<lambda>r. is_ms_array_list N l a * \\<up>(r=last l)>\"\n    by (sep_auto simp: marl_last_def is_ms_array_list_def last_take_nth_conv)\n    \n  lemma marl_butlast_rule[sep_heap_rules]: \"\n    l\\<noteq>[] \\<Longrightarrow>\n    <is_ms_array_list N l a> \n      marl_butlast a\n    <is_ms_array_list N (butlast l)>\\<^sub>t\"\n    by (sep_auto \n      split: prod.splits\n      simp: marl_butlast_def is_ms_array_list_def butlast_take)\n\n  lemma marl_get_rule[sep_heap_rules]: \"\n    i<length l \\<Longrightarrow>\n    <is_ms_array_list N l a> \n      marl_get a i\n    <\\<lambda>r. is_ms_array_list N l a * \\<up>(r=l!i)>\"\n    by (sep_auto simp: marl_get_def is_ms_array_list_def split: prod.split)\n\n  lemma marl_set_rule[sep_heap_rules]: \"\n    i<length l \\<Longrightarrow>\n    <is_ms_array_list N l a> \n      marl_set a i x\n    <is_ms_array_list N (l[i:=x])>\"\n    by (sep_auto simp: marl_set_def is_ms_array_list_def split: prod.split)\n\n  definition \"marl_assn N A \\<equiv> hr_comp (is_ms_array_list N) (\\<langle>the_pure A\\<rangle>list_rel)\"\n  lemmas [safe_constraint_rules] = CN_FALSEI[of is_pure \"marl_assn N A\" for N A]\n\ncontext \n  notes [fcomp_norm_unfold] = marl_assn_def[symmetric]\n  notes [intro!] = hfrefI hn_refineI[THEN hn_refine_preI]\n  notes [simp] = pure_def hn_ctxt_def invalid_assn_def\nbegin  \n\n  definition [simp]: \"op_marl_empty_sz (N::nat) \\<equiv> op_list_empty\"\n  context fixes N :: nat begin\n    sepref_register \"PR_CONST (op_marl_empty_sz N)\"\n  end\n\n  \n\n  lemma marl_fold_custom_empty_sz: \n    \"op_list_empty = op_marl_empty_sz N\"\n    \"mop_list_empty = RETURN (op_marl_empty_sz N)\"\n    \"[] = op_marl_empty_sz N\"\n    by auto\n\n  lemma marl_empty_hnr_aux: \"(uncurry0 (marl_empty_sz N), uncurry0 (RETURN op_list_empty)) \\<in> unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a is_ms_array_list N\"\n    by sep_auto\n  lemmas marl_empty_hnr = marl_empty_hnr_aux[FCOMP op_list_empty.fref[of \"the_pure A\" for A]]\n  lemmas marl_empty_hnr_mop = marl_empty_hnr[FCOMP mk_mop_rl0_np[OF mop_list_empty_alt]]\n\n  lemma marl_empty_sz_hnr[sepref_fr_rules]:\n    \"(uncurry0 (marl_empty_sz N), uncurry0 (RETURN (PR_CONST (op_marl_empty_sz N)))) \\<in> unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a marl_assn N A\"\n    using marl_empty_hnr\n    by simp\n\n  lemma marl_append_hnr_aux: \"(uncurry marl_append,uncurry (RETURN oo op_list_append)) \\<in> [\\<lambda>(l,_). length l<N]\\<^sub>a ((is_ms_array_list N)\\<^sup>d *\\<^sub>a id_assn\\<^sup>k) \\<rightarrow> is_ms_array_list N\"\n    by sep_auto\n  lemmas marl_append_hnr[sepref_fr_rules] = marl_append_hnr_aux[FCOMP op_list_append.fref]\n  lemmas marl_append_hnr_mop[sepref_fr_rules] = marl_append_hnr[FCOMP mk_mop_rl2_np[OF mop_list_append_alt]]\n\n  lemma marl_length_hnr_aux: \"(marl_length,RETURN o op_list_length) \\<in> (is_ms_array_list N)\\<^sup>k \\<rightarrow>\\<^sub>a nat_assn\"\n    by sep_auto\n  lemmas marl_length_hnr[sepref_fr_rules] = marl_length_hnr_aux[FCOMP op_list_length.fref[of \"the_pure A\" for A]]\n  lemmas marl_length_hnr_mop[sepref_fr_rules] = marl_length_hnr[FCOMP mk_mop_rl1_np[OF mop_list_length_alt]]\n\n  lemma marl_is_empty_hnr_aux: \"(marl_is_empty,RETURN o op_list_is_empty) \\<in> (is_ms_array_list N)\\<^sup>k \\<rightarrow>\\<^sub>a bool_assn\"\n    by sep_auto\n  lemmas marl_is_empty_hnr[sepref_fr_rules] = marl_is_empty_hnr_aux[FCOMP op_list_is_empty.fref[of \"the_pure A\" for A]]\n  lemmas marl_is_empty_hnr_mop[sepref_fr_rules] = marl_is_empty_hnr[FCOMP mk_mop_rl1_np[OF mop_list_is_empty_alt]]\n\n  lemma marl_last_hnr_aux: \"(marl_last,RETURN o op_list_last) \\<in> [\\<lambda>x. x\\<noteq>[]]\\<^sub>a (is_ms_array_list N)\\<^sup>k \\<rightarrow> id_assn\"\n    by sep_auto\n  lemmas marl_last_hnr[sepref_fr_rules] = marl_last_hnr_aux[FCOMP op_list_last.fref]\n  lemmas marl_last_hnr_mop[sepref_fr_rules] = marl_last_hnr[FCOMP mk_mop_rl1[OF mop_list_last_alt]]\n\n  lemma marl_butlast_hnr_aux: \"(marl_butlast,RETURN o op_list_butlast) \\<in> [\\<lambda>x. x\\<noteq>[]]\\<^sub>a (is_ms_array_list N)\\<^sup>d \\<rightarrow> (is_ms_array_list N)\"\n    by sep_auto\n  lemmas marl_butlast_hnr[sepref_fr_rules] = marl_butlast_hnr_aux[FCOMP op_list_butlast.fref[of \"the_pure A\" for A]]\n  lemmas marl_butlast_hnr_mop[sepref_fr_rules] = marl_butlast_hnr[FCOMP mk_mop_rl1[OF mop_list_butlast_alt]]\n\n  lemma marl_get_hnr_aux: \"(uncurry marl_get,uncurry (RETURN oo op_list_get)) \\<in> [\\<lambda>(l,i). i<length l]\\<^sub>a ((is_ms_array_list N)\\<^sup>k *\\<^sub>a nat_assn\\<^sup>k) \\<rightarrow> id_assn\"\n    by sep_auto\n  lemmas marl_get_hnr[sepref_fr_rules] = marl_get_hnr_aux[FCOMP op_list_get.fref]\n  lemmas marl_get_hnr_mop[sepref_fr_rules] = marl_get_hnr[FCOMP mk_mop_rl2[OF mop_list_get_alt]]\n\n  lemma marl_set_hnr_aux: \"(uncurry2 marl_set,uncurry2 (RETURN ooo op_list_set)) \\<in> [\\<lambda>((l,i),_). i<length l]\\<^sub>a ((is_ms_array_list N)\\<^sup>d *\\<^sub>a nat_assn\\<^sup>k *\\<^sub>a id_assn\\<^sup>k) \\<rightarrow> (is_ms_array_list N)\"\n    by sep_auto\n  lemmas marl_set_hnr[sepref_fr_rules] = marl_set_hnr_aux[FCOMP op_list_set.fref]\n  lemmas marl_set_hnr_mop[sepref_fr_rules] = marl_set_hnr[FCOMP mk_mop_rl3[OF mop_list_set_alt]]\n\nend\n\ncontext\n  fixes N :: nat\n  assumes N_sz: \"N>10\"\nbegin\n\nschematic_goal \"hn_refine (emp) (?c::?'c Heap) ?\\<Gamma>' ?R (do {\n  let x = op_marl_empty_sz N;\n  RETURN (x@[1::nat])\n})\"  \n  using N_sz\n  by sepref\n\nend\n\nschematic_goal \"hn_refine (emp) (?c::?'c Heap) ?\\<Gamma>' ?R (do {\n  let x = op_list_empty;\n  RETURN (x@[1::nat])\n})\"  \n  apply (subst marl_fold_custom_empty_sz[where N=10])\n  apply sepref\n  done\n\nend\n", "meta": {"author": "maxhaslbeck", "repo": "Sepreftime", "sha": "c1c987b45ec886d289ba215768182ac87b82f20d", "save_path": "github-repos/isabelle/maxhaslbeck-Sepreftime", "path": "github-repos/isabelle/maxhaslbeck-Sepreftime/Sepreftime-c1c987b45ec886d289ba215768182ac87b82f20d/Refine_Imperative_HOL/IICF/Impl/IICF_MS_Array_List.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.519521321952093, "lm_q2_score": 0.5195213219520929, "lm_q1q2_score": 0.2699024039628502}}
{"text": "(* \n   Title: The pi-calculus   \n   Author/Maintainer: Jesper Bengtson (jebe.dk), 2012\n*)\ntheory Weak_Early_Bisim_Pres\n  imports Strong_Early_Bisim_Pres Weak_Early_Sim_Pres Weak_Early_Bisim_SC Weak_Early_Bisim\nbegin\n\n(************ Preservation rules ************)\n\nlemma tauPres:\n  fixes P :: pi\n  and   Q :: pi\n\n  assumes \"P \\<approx> Q\"\n\n  shows \"\\<tau>.(P) \\<approx> \\<tau>.(Q)\"\nproof -\n  let ?X = \"{(\\<tau>.(P), \\<tau>.(Q)) | P Q. P \\<approx> Q}\"\n  from `P \\<approx> Q` have \"(\\<tau>.(P), \\<tau>.(Q)) \\<in> ?X\" by auto\n  thus ?thesis\n  proof(coinduct rule: weakBisimCoinduct)\n    case(cSim P Q)\n    thus ?case\n      by(force intro: Weak_Early_Sim_Pres.tauPres)\n  next\n    case(cSym P Q)\n    thus ?case by(force dest: Weak_Early_Bisim.symetric simp add: pi.inject)\n  qed\nqed\n\nlemma outputPres:\n  fixes P :: pi\n  and   Q :: pi\n  and   a :: name\n  and   b :: name\n\n  assumes \"P \\<approx> Q\"\n\n  shows \"a{b}.P \\<approx> a{b}.Q\"\nproof -\n  let ?X = \"{(a{b}.(P), a{b}.(Q)) | P Q a b. P \\<approx> Q}\"\n  from `P \\<approx> Q` have \"(a{b}.(P), a{b}.(Q)) \\<in> ?X\" by auto\n  thus ?thesis\n  proof(coinduct rule: weakBisimCoinduct)\n    case(cSim P Q)\n    thus ?case\n      by(force intro: Weak_Early_Sim_Pres.outputPres)\n  next\n    case(cSym P Q)\n    thus ?case by(force dest: Weak_Early_Bisim.symetric simp add: pi.inject)\n  qed\nqed\n\nlemma inputPres:\n  fixes P :: pi\n  and   Q :: pi\n  and   a :: name\n  and   x :: name\n\n  assumes PSimQ: \"\\<forall>y. P[x::=y] \\<approx> Q[x::=y]\"\n  \n  shows \"a<x>.P \\<approx> a<x>.Q\"\nproof -\n  let ?X = \"{(a<x>.P, a<x>.Q) | a x P Q. \\<forall>y. P[x::=y] \\<approx> Q[x::=y]}\"\n  {\n    fix axP axQ p\n    assume \"(axP, axQ) \\<in> ?X\"\n    then obtain a x P Q where A: \"\\<forall>y. P[x::=y] \\<approx> Q[x::=y]\" and B: \"axP = a<x>.P\" and C: \"axQ = a<x>.Q\"\n      by auto\n    have \"\\<And>y. ((p::name prm) \\<bullet> P)[(p \\<bullet> x)::=y] \\<approx> (p \\<bullet> Q)[(p \\<bullet> x)::=y]\"\n    proof -\n      fix y\n      from A have \"P[x::=(rev p \\<bullet> y)] \\<approx> Q[x::=(rev p \\<bullet> y)]\"\n        by blast\n      hence \"(p \\<bullet> (P[x::=(rev p \\<bullet> y)])) \\<approx> p \\<bullet> (Q[x::=(rev p \\<bullet> y)])\"\n        by(rule eqvts)\n      thus \"(p \\<bullet> P)[(p \\<bullet> x)::=y] \\<approx> (p \\<bullet> Q)[(p \\<bullet> x)::=y]\"\n        by(simp add: eqvts pt_pi_rev[OF pt_name_inst, OF at_name_inst])\n    qed\n    hence \"((p::name prm) \\<bullet> axP, p \\<bullet> axQ) \\<in> ?X\" using B C\n      by auto\n  }\n  hence \"eqvt ?X\" by(simp add: eqvt_def)\n\n  from PSimQ have \"(a<x>.P, a<x>.Q) \\<in> ?X\" by auto\n  thus ?thesis\n  proof(coinduct rule: weakBisimCoinduct)\n    case(cSim P Q)\n    thus ?case using `eqvt ?X`\n      by(force intro: Weak_Early_Sim_Pres.inputPres)\n  next\n    case(cSym P Q)\n    thus ?case\n      by(blast dest: weakBisimE)\n  qed\nqed\n\n\n\n  shows \"<\\<nu>x>P \\<approx> <\\<nu>x>Q\"\nproof -\n  let ?X = \"{(<\\<nu>x>P, <\\<nu>x>Q) | x P Q. P \\<approx> Q}\"\n  from `P \\<approx> Q` have \"(<\\<nu>x>P, <\\<nu>x>Q) \\<in> ?X\" by blast\n  thus ?thesis\n  proof(coinduct rule: weakBisimCoinduct)\n    case(cSim xP xQ)\n    {\n      fix P Q x\n      assume \"P \\<approx> Q\"\n      hence \"P \\<leadsto><weakBisim> Q\" by(rule weakBisimE)\n      moreover have \"\\<And>P Q x. P \\<approx> Q \\<Longrightarrow> (<\\<nu>x>P, <\\<nu>x>Q) \\<in> ?X \\<union> weakBisim\" by blast\n      moreover have \"weakBisim \\<subseteq> ?X \\<union> weakBisim\" by blast\n      moreover have \"eqvt weakBisim\" by simp\n      moreover have \"eqvt (?X \\<union> weakBisim)\"\n        by(auto simp add: eqvt_def dest: Weak_Early_Bisim.eqvtI)+\n      ultimately have \"<\\<nu>x>P \\<leadsto><(?X \\<union> weakBisim)> <\\<nu>x>Q\"\n        by(rule Weak_Early_Sim_Pres.resPres)\n    }\n    with `(xP, xQ) \\<in> ?X` show ?case by blast\n  next\n    case(cSym xP xQ)\n    thus ?case by(blast dest: Weak_Early_Bisim.symetric)\n  qed\nqed\n\n\n\n  assumes \"P \\<approx> Q\"\n\n  shows \"[a\\<frown>b]P \\<approx> [a\\<frown>b]Q\"\nproof -\n  let ?X = \"{([a\\<frown>b]P, [a\\<frown>b]Q) | a b P Q. P \\<approx> Q}\"\n  from `P \\<approx> Q` have \"([a\\<frown>b]P, [a\\<frown>b]Q) \\<in> ?X\" by blast\n  thus ?thesis\n  proof(coinduct rule: weakBisimCoinduct)\n    case(cSim abP abQ)\n    {\n      fix P Q a b\n      assume \"P \\<approx> Q\"\n      hence \"P \\<leadsto><weakBisim> Q\" by(rule weakBisimE)\n      moreover have \"weakBisim \\<subseteq> (?X \\<union> weakBisim)\" by blast\n      moreover have \"\\<And>P Q a. P \\<approx> Q \\<Longrightarrow> [a\\<frown>a]P \\<approx> Q\"\n        by (metis (full_types) strongBisimWeakBisim Strong_Early_Bisim_SC.matchId Weak_Early_Bisim.transitive)\n      ultimately have\"[a\\<frown>b]P \\<leadsto><(?X \\<union> weakBisim)> [a\\<frown>b]Q\" \n        by(rule Weak_Early_Sim_Pres.matchPres)\n    }\n    with `(abP, abQ) \\<in> ?X` show ?case by blast\n  next\n    case(cSym abP abQ)\n    thus ?case by(blast dest: Weak_Early_Bisim.symetric)\n  qed\nqed\n\nlemma mismatchPres:\n  fixes P :: pi\n  and   Q :: pi\n  and   a :: name\n  and   b :: name\n\n  assumes \"P \\<approx> Q\"\n\n  shows \"[a\\<noteq>b]P \\<approx> [a\\<noteq>b]Q\"\nproof -\n  let ?X = \"{([a\\<noteq>b]P, [a\\<noteq>b]Q)| a b P Q. P \\<approx> Q}\"\n  from `P \\<approx> Q` have \"([a\\<noteq>b]P, [a\\<noteq>b]Q) \\<in> ?X\" by blast\n  thus ?thesis\n  proof(coinduct rule: weakBisimCoinduct)\n    case(cSim abP abQ)\n    {\n      fix P Q a b\n      assume \"P \\<approx> Q\"\n      hence \"P \\<leadsto><weakBisim> Q\" by(rule weakBisimE)\n      moreover have \"weakBisim \\<subseteq> (?X \\<union> weakBisim)\" by blast\n      moreover have \"\\<And>P Q a b. \\<lbrakk>P \\<approx> Q; a \\<noteq> b\\<rbrakk> \\<Longrightarrow> [a\\<noteq>b]P \\<approx> Q\"\n        by (metis (full_types) strongBisimWeakBisim Strong_Early_Bisim_SC.mismatchId Weak_Early_Bisim.transitive)\n      ultimately have \"[a\\<noteq>b]P \\<leadsto><(?X \\<union> weakBisim)> [a\\<noteq>b]Q\"\n        by(rule Weak_Early_Sim_Pres.mismatchPres) \n    }\n    with `(abP, abQ) \\<in> ?X` show ?case by blast\n  next\n    case(cSym abP abQ)\n    thus ?case by(blast dest: Weak_Early_Bisim.symetric)\n  qed\nqed\n\nlemma parPres:\n  fixes P :: pi\n  and   Q :: pi\n  and   R :: pi\n\n  assumes \"P \\<approx> Q\"\n\n  shows \"P \\<parallel> R \\<approx> Q \\<parallel> R\"\nproof -\n  let ?X = \"{(resChain lst (P \\<parallel> R), resChain lst (Q \\<parallel> R)) | lst P R Q. P \\<approx> Q}\"\n  have BC: \"\\<And>P Q. P \\<parallel> Q = resChain [] (P \\<parallel> Q)\" by auto\n  from `P \\<approx> Q` have \"(P \\<parallel> R, Q \\<parallel> R) \\<in> ?X\" by(blast intro: BC)\n  thus ?thesis\n  proof(coinduct rule: weakBisimCoinduct)\n    case(cSym PR QR)\n    {\n      fix P Q R lst\n      assume \"P \\<approx> Q\"\n      moreover hence \"P \\<leadsto><weakBisim> Q\" by(rule weakBisimE)\n      moreover have \"\\<And>P Q R. P \\<approx> Q \\<Longrightarrow> (P \\<parallel> R, Q \\<parallel> R) \\<in> ?X\" using BC\n        by blast\n      moreover {\n        fix PR QR x\n        assume \"(PR, QR) \\<in> ?X\"\n        then obtain lst P Q R where \"P \\<approx> Q\" and A: \"PR = resChain lst (P \\<parallel> R)\" and B: \"QR = resChain lst (Q \\<parallel> R)\"\n          by auto\n        from A have \"<\\<nu>x>PR = resChain (x#lst) (P \\<parallel> R)\" by auto\n        moreover from B have \"<\\<nu>x>QR = resChain (x#lst) (Q \\<parallel> R)\" by auto\n        ultimately have \"(<\\<nu>x>PR, <\\<nu>x>QR) \\<in> ?X\" using `P \\<approx> Q`\n          by blast\n      }\n      note Res = this\n      ultimately have \"P \\<parallel> R \\<leadsto><?X> Q \\<parallel> R\"\n        by(rule_tac Weak_Early_Sim_Pres.parPres)\n      moreover have \"eqvt ?X\"\n        by(auto simp add: eqvt_def) (blast intro: eqvts)\n      ultimately have \"resChain lst (P \\<parallel> R) \\<leadsto><?X> resChain lst (Q \\<parallel> R)\" using Res\n        by(rule_tac Weak_Early_Sim_Pres.resChainI)\n      hence \"resChain lst (P \\<parallel> R) \\<leadsto><(?X \\<union> weakBisim)> resChain lst (Q \\<parallel> R)\"\n        by(force intro: Weak_Early_Sim.monotonic)\n    }\n    with `(PR, QR) \\<in> ?X` show \"PR \\<leadsto><(?X \\<union> weakBisim)> QR\"\n      by blast\n  next\n    case(cSym PR QR)\n    thus ?case by(blast dest: Weak_Early_Bisim.symetric)\n  qed\nqed\n\n\n\n  assumes PBisimQ: \"P \\<approx> Q\"\n\n  shows \"!P \\<approx> !Q\"\nproof -\n  let ?X = \"(bangRel weakBisim)\"\n  let ?Y = \"Strong_Early_Bisim.bisim O (bangRel weakBisim) O Strong_Early_Bisim.bisim\"\n\n  from Weak_Early_Bisim.eqvt Strong_Early_Bisim.eqvt have eqvtY: \"eqvt ?Y\" by(blast intro: eqvtBangRel)\n  have XsubY: \"?X \\<subseteq> ?Y\" by(auto intro: Strong_Early_Bisim.reflexive)\n\n  have RelStay: \"\\<And>P Q. (P \\<parallel> !P, Q) \\<in> ?Y \\<Longrightarrow> (!P, Q) \\<in> ?Y\"\n  proof(auto)\n    fix P Q R T\n    assume PBisimQ: \"P \\<parallel> !P \\<sim>\\<^sub>e Q\" \n       and QBRR: \"(Q, R) \\<in> bangRel weakBisim\"\n       and RBisimT: \"R \\<sim>\\<^sub>e T\"\n    have \"!P \\<sim>\\<^sub>e Q\" \n    proof -\n      have \"!P \\<sim>\\<^sub>e P \\<parallel> !P\" by(rule Strong_Early_Bisim_SC.bangSC)\n      thus ?thesis using PBisimQ by(rule Strong_Early_Bisim.transitive)\n    qed\n    with QBRR RBisimT show \"(!P, T) \\<in> ?Y\" by blast\n  qed\n \n  have ParCompose: \"\\<And>P Q R T. \\<lbrakk>P \\<approx> Q; (R, T) \\<in> ?Y\\<rbrakk> \\<Longrightarrow> (P \\<parallel> R, Q \\<parallel> T) \\<in> ?Y\"\n  proof -\n    fix P Q R T\n    assume PBisimQ: \"P \\<approx> Q\"\n       and RYT:     \"(R, T) \\<in> ?Y\"\n    thus \"(P \\<parallel> R, Q \\<parallel> T) \\<in> ?Y\"\n    proof(auto)\n      fix T' R'\n      assume T'BisimT: \"T' \\<sim>\\<^sub>e T\" and RBisimR': \"R \\<sim>\\<^sub>e R'\"\n         and R'BRT': \"(R', T') \\<in> bangRel weakBisim\"\n      have \"P \\<parallel> R \\<sim>\\<^sub>e P \\<parallel> R'\"\n      proof -\n        from RBisimR' have \"R \\<parallel> P \\<sim>\\<^sub>e R' \\<parallel> P\" by(rule Strong_Early_Bisim_Pres.parPres)\n        moreover have \"P \\<parallel> R \\<sim>\\<^sub>e R \\<parallel> P\" and \"R' \\<parallel> P \\<sim>\\<^sub>e P \\<parallel> R'\" by(rule Strong_Early_Bisim_SC.parSym)+\n        ultimately show ?thesis by(blast intro: Strong_Early_Bisim.transitive)\n      qed\n      moreover from PBisimQ R'BRT' have \"(P \\<parallel> R', Q \\<parallel> T') \\<in> bangRel weakBisim\" by(rule BRPar)\n      moreover have \"Q \\<parallel> T' \\<sim>\\<^sub>e Q \\<parallel> T\"\n      proof -\n        from T'BisimT have \"T' \\<parallel> Q \\<sim>\\<^sub>e T \\<parallel> Q\" by(rule Strong_Early_Bisim_Pres.parPres)\n        moreover have \"Q \\<parallel> T' \\<sim>\\<^sub>e T' \\<parallel> Q\" and \"T \\<parallel> Q \\<sim>\\<^sub>e Q \\<parallel> T\" by(rule Strong_Early_Bisim_SC.parSym)+\n        ultimately show ?thesis by(blast intro: Strong_Early_Bisim.transitive)\n      qed\n      ultimately show ?thesis by blast\n    qed\n  qed\n\n  have ResCong: \"\\<And>P Q x. (P, Q) \\<in> ?Y \\<Longrightarrow> (<\\<nu>x>P, <\\<nu>x>Q) \\<in> ?Y\"\n    by(auto intro: BRRes Strong_Early_Bisim_Pres.resPres transitive)\n\n  have Sim: \"\\<And>P Q. (P, Q) \\<in> ?X \\<Longrightarrow> P \\<leadsto><?Y> Q\"\n  proof -\n    fix P Q\n    assume \"(P, Q) \\<in> ?X\"\n    thus \"P \\<leadsto><?Y> Q\"\n    proof(induct)\n      case(BRBang P Q)\n      have \"P \\<approx> Q\" by fact\n      moreover hence \"P \\<leadsto><weakBisim> Q\" by(blast dest: weakBisimE)\n      moreover have \"\\<And>P Q. P \\<approx> Q \\<Longrightarrow> P \\<leadsto><weakBisim> Q\" by(blast dest: weakBisimE)\n      moreover from Strong_Early_Bisim.eqvt Weak_Early_Bisim.eqvt have \"eqvt ?Y\" by(blast intro: eqvtBangRel)\n\n      ultimately show \"!P \\<leadsto><?Y> !Q\" using ParCompose ResCong RelStay XsubY\n        by(rule_tac Weak_Early_Sim_Pres.bangPres, simp_all)\n    next\n      case(BRPar P Q R T)\n      have PBiSimQ: \"P \\<approx> Q\" by fact\n      moreover have RBangRelT: \"(R, T) \\<in> ?X\" by fact\n      have RSimT: \"R \\<leadsto><?Y> T\" by fact\n      moreover from PBiSimQ  have \"P \\<leadsto><weakBisim> Q\" by(blast dest: weakBisimE)\n      moreover from RBangRelT have \"(R, T) \\<in> ?Y\" by(blast intro: Strong_Early_Bisim.reflexive)\n      ultimately show \"P \\<parallel> R \\<leadsto><?Y> Q \\<parallel> T\" using ParCompose ResCong eqvt eqvtY\n        by(rule_tac Weak_Early_Sim_Pres.parCompose)\n    next\n      case(BRRes P Q x)\n      have \"P \\<leadsto><?Y> Q\" by fact\n      thus \"<\\<nu>x>P \\<leadsto><?Y> <\\<nu>x>Q\" using ResCong eqvtY XsubY\n        by(rule_tac Weak_Early_Sim_Pres.resPres, simp_all)\n    qed\n  qed\n\n  from PBisimQ have \"(!P, !Q) \\<in> ?X\" by(rule BRBang)\n  moreover from Weak_Early_Bisim.eqvt have \"eqvt (bangRel weakBisim)\" by(rule eqvtBangRel)\n  ultimately show ?thesis\n    apply(coinduct rule: Weak_Early_Bisim.transitive_coinduct_weak)\n    apply(blast intro: Sim)\n    by(blast dest: bangRelSymetric Weak_Early_Bisim.symetric intro: Strong_Early_Bisim.reflexive)\nqed\n\n\n\nend", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Pi_Calculus/Weak_Early_Bisim_Pres.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.519521321952093, "lm_q2_score": 0.5195213219520929, "lm_q1q2_score": 0.2699024039628502}}
{"text": "(*  Title: L3_Lib.thy\n    Original author: Anthony Fox, University of Cambridge\n    Contributions by: Kyndylan Nienhuis <kyndylan@mutlus.nl>\n\nL3 operations.\n*)\n\ntheory L3_Lib\nimports \"$ISABELLE_HOME/src/HOL/Word/Word\"\n        \"$ISABELLE_HOME/src/HOL/Library/Code_Target_Numeral\"\n        \"$ISABELLE_HOME/src/HOL/Library/Code_Char\"\nbegin\n\n(* basic state Monad *)\n\ndefinition \"return = Pair\"\n\ndefinition bind :: \"('state \\<Rightarrow> ('a \\<times> 'state)) \\<Rightarrow>\n                    ('a \\<Rightarrow> 'state \\<Rightarrow> ('b \\<times> 'state)) \\<Rightarrow>\n                    ('state \\<Rightarrow> ('b \\<times> 'state))\" where\n  \"bind f g = (\\<lambda>s. let (a, s') = f s in g a s')\"\n\ndefinition read_state :: \"('state \\<Rightarrow> 'a) \\<Rightarrow> 'state \\<Rightarrow> 'a \\<times> 'state\" where\n  \"read_state f = (\\<lambda>s. (f s, s))\"\n\ndefinition update_state :: \"('state \\<Rightarrow> 'state) \\<Rightarrow> 'state \\<Rightarrow> unit \\<times> 'state\" where\n  \"update_state f = (\\<lambda>s. ((), f s))\"\n\ndefinition extend_state :: \"'b \\<Rightarrow> ('b \\<times> 'state \\<Rightarrow> 'a \\<times> 'b \\<times> 'state) \\<Rightarrow> 'state \\<Rightarrow> 'a \\<times> 'state\" where\n  \"extend_state v f = (\\<lambda>s. let (a, s') = f (v, s) in (a, snd s'))\"\n\ndefinition trim_state :: \"('state \\<Rightarrow> 'a \\<times> 'state) \\<Rightarrow> 'b \\<times> 'state \\<Rightarrow> 'a \\<times> 'b \\<times> 'state\" where\n  \"trim_state f = (\\<lambda>(s1, s2). let (a, s') = f s2 in (a, s1, s'))\"\n\nfun foreach_loop :: \"'a list \\<times> ('a \\<Rightarrow> 'state \\<Rightarrow> unit \\<times> 'state) \\<Rightarrow> 'state \\<Rightarrow> unit \\<times> 'state\" where\n  \"foreach_loop ([], _) = return ()\" |\n  \"foreach_loop (h # t, a) = bind (a h) (\\<lambda>u. foreach_loop (t, a))\"\n\nfunction for_loop :: \"nat \\<times> nat \\<times> (nat \\<Rightarrow> 'state \\<Rightarrow> unit \\<times> 'state) \\<Rightarrow> 'state \\<Rightarrow> unit \\<times> 'state\" where\n  \"for_loop (i, j, a) =\n   (if i = j then\n      a i\n    else\n      bind (a i) (\\<lambda>u. for_loop ((if i < j then i + 1 else i - 1), j, a)))\"\n  by auto\n  termination by (relation \"measure (\\<lambda>(i, j, _). if i < j then j - i else i - j)\") auto\n\n(* Because there are no constraints on i, j and a on the left-hand side of the definition, every\noccurrence of for_loop can be simplified by for_loop.simps, and since the definition is recursive\nthe simplifier might diverge. For this reason we remove for_loop.simps from the simp set. *)\n\ndeclare for_loop.simps [simp del]\n\n(* Monad laws *)\n\nlemma bind_left_identity [simp]:\n  shows \"bind (return a) f = f a\"\nunfolding return_def bind_def\nby auto\n\nlemma bind_right_identity [simp]:\n  shows \"bind m return = m\"\nunfolding return_def bind_def\nby auto\n\nlemma bind_associativity:\n  shows \"bind (bind m f) g = bind m (\\<lambda>a. bind (f a) g)\" \n        (is \"?l = ?r\")\nproof\n  fix s\n  show \"?l s = ?r s\"\n    unfolding return_def bind_def \n    by (cases \"m s\") auto\nqed\n\n(* Projections *)\n\nlemma project_return [simp]:\n  shows \"fst (return a s) = a\"\n    and \"snd (return a s) = s\"\nunfolding return_def\nby auto\n\nlemma project_read_state [simp]:\n  shows \"fst (read_state f s) = f s\"\n    and \"snd (read_state f s) = s\"\nunfolding read_state_def\nby auto\n\nlemma project_update_state [simp]:\n  shows \"fst (update_state f s) = ()\"\n    and \"snd (update_state f s) = f s\"\nunfolding update_state_def\nby auto\n\n(* Other monad simplifications *)\n\nlemma read_state_constant [simp]:\n  shows \"read_state (\\<lambda>s. a) = return a\" \nunfolding read_state_def return_def\n..\n\nlemma update_state_id [simp]:\n  shows \"update_state (\\<lambda>s. s) = return ()\" \nunfolding update_state_def return_def\n..\n\nlemma foreach_loop_return [simp]:\n  shows \"foreach_loop (l, \\<lambda>_. return a) = return ()\"\nby (induct l) simp_all\n\nlemma extend_state_return [simp]:\n  shows \"extend_state v (return a) = return a\"\nunfolding extend_state_def return_def\nby simp\n\nlemma extend_state_trim_state [simp]:\n  shows \"extend_state v (trim_state m) = m\" \n        (is \"?l = ?r\")\nproof\n  fix s\n  show \"?l s = ?r s\"\n    unfolding extend_state_def trim_state_def\n    by (cases \"m s\") auto\nqed\n\n(* extra character operations *)\n\ndefinition Ord :: \"char \\<Rightarrow> nat\" where\n   \"Ord c = (case c of Char nh nl \\<Rightarrow> \n             nat_of_nibble nh * 16 + nat_of_nibble nl)\"\n\ndefinition Chr :: \"nat \\<Rightarrow> char\" where\n   \"Chr n = Char (nibble_of_nat (n div 16)) (nibble_of_nat n)\"\n\ndefinition is_lower :: \"char \\<Rightarrow> bool\" where\n   \"is_lower c = (Ord (CHR ''a'') \\<le> Ord c \\<and> Ord c \\<le> Ord (CHR ''z''))\"\n\ndefinition is_upper :: \"char \\<Rightarrow> bool\" where\n   \"is_upper c = (Ord (CHR ''A'') \\<le> Ord c \\<and> Ord c \\<le> Ord (CHR ''Z''))\"\n\ndefinition is_space :: \"char \\<Rightarrow> bool\" where\n   \"is_space c = (Ord (CHR '' '') = Ord c \\<or> 9 \\<le> Ord c \\<and> Ord c \\<le> 13)\"\n\ndefinition is_digit :: \"char \\<Rightarrow> bool\" where\n   \"is_digit c = (Ord (CHR ''0'') \\<le> Ord c \\<and> Ord c \\<le> Ord (CHR ''9''))\"\n\ndefinition is_hex_digit :: \"char \\<Rightarrow> bool\" where\n   \"is_hex_digit c = (is_digit c \\<or> Ord (CHR ''a'') \\<le> Ord c \\<and> Ord c \\<le> Ord (CHR ''f'') \\<or>\n                                   Ord (CHR ''A'') \\<le> Ord c \\<and> Ord c \\<le> Ord (CHR ''F''))\"\n\ndefinition is_alpha :: \"char \\<Rightarrow> bool\" where\n   \"is_alpha c = (is_lower c \\<or> is_upper c)\"\n\ndefinition is_alpha_num :: \"char \\<Rightarrow> bool\" where\n   \"is_alpha_num c = (is_alpha c \\<or> is_digit c)\"\n\ndefinition to_lower :: \"char \\<Rightarrow> char\" where\n   \"to_lower c = (if is_upper c then Chr (Ord c + 32) else c)\"\n\ndefinition to_upper :: \"char \\<Rightarrow> char\" where\n   \"to_upper c = (if is_lower c then Chr (Ord c - 32) else c)\"\n\n(* numeric strings *)\n\nfun list_to_nat :: \"nat \\<Rightarrow> nat list \\<Rightarrow> nat\" where\n  \"list_to_nat _ [] = 0\" |\n  \"list_to_nat base (h # t) = h mod base + base * list_to_nat base t\"\n\nfun nat_to_list :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat list\" where\n  \"nat_to_list base n =\n   (if n < base \\<or> base < 2 then [n mod base] else n mod base # nat_to_list base (n div base))\"\n\n(* Because there are no constraints on n on the left-hand side of the definition, every occurrence\nof nat_to_list can be simplified by nat_to_list.simps, and since the definition is recursive the\nsimplifier might diverge. For this reason we remove nat_to_list.simps from the simp set. *)\n\ndeclare nat_to_list.simps [simp del]\n\ndefinition hex :: \"nat \\<Rightarrow> char\" where\n  \"hex n = (if n = 0 then CHR ''0''\n            else if n = 1 then CHR ''1''\n            else if n = 2 then CHR ''2''\n            else if n = 3 then CHR ''3''\n            else if n = 4 then CHR ''4''\n            else if n = 5 then CHR ''5''\n            else if n = 6 then CHR ''6''\n            else if n = 7 then CHR ''7''\n            else if n = 8 then CHR ''8''\n            else if n = 9 then CHR ''9''\n            else if n = 10 then CHR ''A''\n            else if n = 11 then CHR ''B''\n            else if n = 12 then CHR ''C''\n            else if n = 13 then CHR ''D''\n            else if n = 14 then CHR ''E''\n            else if n = 15 then CHR ''F''\n            else undefined)\"\n\ndefinition unhex :: \"char \\<Rightarrow> nat\" where\n  \"unhex c = (if c = CHR ''0'' then 0\n              else if c = CHR ''1'' then 1\n              else if c = CHR ''2'' then 2\n              else if c = CHR ''3'' then 3\n              else if c = CHR ''4'' then 4\n              else if c = CHR ''5'' then 5\n              else if c = CHR ''6'' then 6\n              else if c = CHR ''7'' then 7\n              else if c = CHR ''8'' then 8\n              else if c = CHR ''9'' then 9\n              else if c = CHR ''a'' \\<or> c = CHR ''A'' then 10\n              else if c = CHR ''b'' \\<or> c = CHR ''B'' then 11\n              else if c = CHR ''c'' \\<or> c = CHR ''C'' then 12\n              else if c = CHR ''d'' \\<or> c = CHR ''D'' then 13\n              else if c = CHR ''e'' \\<or> c = CHR ''E'' then 14\n              else if c = CHR ''f'' \\<or> c = CHR ''F'' then 15\n              else undefined)\"\n\ndefinition string_to_nat :: \"nat \\<Rightarrow> string \\<Rightarrow> nat\" where\n  \"string_to_nat base s = list_to_nat base (map unhex (rev s))\"\n\ndefinition nat_to_string :: \"nat \\<Rightarrow> nat \\<Rightarrow> string\" where\n  \"nat_to_string base n = rev (map hex (nat_to_list base n))\"\n\ndefinition \"bin_string_to_nat \\<equiv> string_to_nat 2\"\ndefinition \"nat_to_bin_string \\<equiv> nat_to_string 2\"\ndefinition \"dec_string_to_nat \\<equiv> string_to_nat 10\"\ndefinition \"nat_to_dec_string \\<equiv> nat_to_string 10\"\ndefinition \"hex_string_to_nat \\<equiv> string_to_nat 16\"\ndefinition \"nat_to_hex_string \\<equiv> nat_to_string 16\"\n\ndefinition nat_from_bin_string :: \"string \\<Rightarrow> nat option\" where\n  \"nat_from_bin_string s =\n   (if s \\<noteq> '''' \\<and> list_all (\\<lambda>c. c = CHR ''0'' \\<or> c = CHR ''1'') s then\n      Some (bin_string_to_nat s)\n    else None)\"\n\ndefinition nat_from_dec_string :: \"string \\<Rightarrow> nat option\" where\n  \"nat_from_dec_string s =\n   (if s \\<noteq> '''' \\<and> list_all is_digit s then Some (dec_string_to_nat s) else None)\"\n\ndefinition nat_from_hex_string :: \"string \\<Rightarrow> nat option\" where\n  \"nat_from_hex_string s =\n   (if s \\<noteq> '''' \\<and> list_all is_hex_digit s then Some (hex_string_to_nat s) else None)\"\n\ndefinition dec_string_to_int :: \"string \\<Rightarrow> int\" where\n  \"dec_string_to_int r = \n   (case r of []    \\<Rightarrow> 0 |\n              h # t \\<Rightarrow> (if h = CHR ''-'' \\<or> h = CHR ''~'' \n                        then -int (dec_string_to_nat t)\n                        else  int (dec_string_to_nat r)))\"\n\ndefinition int_to_dec_string :: \"int \\<Rightarrow> string\" where\n  \"int_to_dec_string i =\n   (if i < 0 then CHR ''~'' # nat_to_dec_string (nat (-i)) else nat_to_dec_string (nat i))\"\n\ndefinition string_to_bool :: \"string \\<Rightarrow> bool\" where\n  \"string_to_bool s = (if s = ''true'' then True\n                       else if s = ''false'' then False\n                       else undefined)\"\n\ndefinition string_to_char :: \"string \\<Rightarrow> char\" where\n  \"string_to_char s = (case s of [c] \\<Rightarrow> c | _ \\<Rightarrow> undefined)\"\n\n(* extra Nat operation *)\n\nfun log2 :: \"nat \\<Rightarrow> nat\" where\n  \"log2 n = (if n = 0 then undefined else if n = 1 then 0 else Suc (log2 (n div 2)))\"\n\n(* Because there are no constraints on n on the left-hand side of the definition, every occurrence\nof log2 can be simplified by log2.simps, and since the definition is recursive the simplifier might\ndiverge. For this reason we remove log2.simps from the simp set. *)\n\ndeclare log2.simps [simp del]\n\nlemma log2_bounds:\n  assumes \"n \\<noteq> 0\"\n  shows   \"2 ^ (log2 n) \\<le> n\"\n    and   \"n < 2 ^ (Suc (log2 n))\"\nproof -\n  -- \"The induction works better if we prove one goal instead of two goals\"\n  have \"2 ^ (log2 n) \\<le> n \\<and> n < 2 ^ (Suc (log2 n))\"\n    using assms\n    proof (induct \"log2 n\" arbitrary: n)\n      case 0\n      hence \"n = 1\" \n        by (simp add: log2.simps) (meson nat.simps(3))\n      thus ?case by (simp add: log2.simps)\n    next\n      case (Suc k)\n      show ?case\n        proof (cases \"n = 1\")\n          case True\n          thus ?thesis by (simp add: log2.simps)\n        next\n          case False\n          hence \"1 < n\" using Suc(3) by simp\n          hence \"(n div 2) \\<noteq> 0\" by auto\n          have log2: \"log2 n = Suc (log2 (n div 2))\"\n            using `1 < n` by (simp add: log2.simps)\n          hence \"k = log2 (n div 2)\" using Suc(2) by simp\n          note Suc(1)[OF this `(n div 2) \\<noteq> 0`]\n          thus ?thesis\n            using log2 by auto\n        qed\n    qed\n  thus \"2 ^ (log2 n) \\<le> n\" \"n < 2 ^ (Suc (log2 n))\" by auto\nqed\n\nlemma log2_unat_bounds:\n  fixes x :: \"('a :: len) word\"\n  assumes \"x \\<noteq> 0\"\n  shows \"log2 (unat x) < len_of TYPE('a)\"\nproof -\n  have \"unat x \\<noteq> 0\" \n    using assms \n    by (simp add: unat_eq_zero)\n  have \"unat x < 2 ^ len_of TYPE('a)\"\n    by simp\n  note le_less_trans[OF log2_bounds(1)[OF `unat x \\<noteq> 0`] this]\n  thus ?thesis by auto\nqed\n\n(* extra int operations *)\n\ndefinition quot :: \"int \\<Rightarrow> int \\<Rightarrow> int\" (infixl \"quot\" 70) where\n  \"i quot j = (if j = 0 then undefined\n               else if 0 < j then if 0 \\<le> i then i div j else -(-i div j)\n               else if 0 \\<le> i then -(i div -j)\n               else -i div -j)\"\n\ndefinition rem :: \"int \\<Rightarrow> int \\<Rightarrow> int\" (infixl \"rem\" 70) where\n  \"i rem j = (if j = 0 then undefined else i - i quot j * j)\"\n\ndefinition quot_rem :: \"int * int \\<Rightarrow> int * int\" where\n  \"quot_rem p = (case p of (i, j) \\<Rightarrow> (i div j, i rem j))\"\n\n(* extra option operations *)\n\ndefinition is_some :: \"'a option \\<Rightarrow> bool\" where\n  \"is_some x = (case x of Some _ \\<Rightarrow> True | _ \\<Rightarrow> False)\"\n\nlemma is_some_alt:\n  shows \"is_some x = (x \\<noteq> None)\"\nunfolding is_some_def \nusing option.disc_eq_case(2) \nby auto\n\nlemma is_some_simps [simp]:\n  shows \"\\<not> (is_some None)\"\n    and \"is_some (Some x)\"\nunfolding is_some_def by simp_all\n\n(* extra list operations *)\n\nfun splitl :: \"('a \\<Rightarrow> bool) \\<Rightarrow> 'a list \\<Rightarrow> 'a list \\<times> 'a list\" where\n  \"splitl _ [] = ([], [])\" |\n  \"splitl P (h # t) = (if P h then let (l, r) = splitl P t in (h # l, r) else ([], h # t))\"\n\ndefinition splitr :: \"('a \\<Rightarrow> bool) \\<Rightarrow> 'a list \\<Rightarrow> 'a list \\<times> 'a list\" where\n  \"splitr P x = (let (l, r) = splitl P (rev x) in (rev r, rev l))\"\n\ndefinition pad_left :: \"'a \\<Rightarrow> nat \\<Rightarrow> 'a list \\<Rightarrow> 'a list\" where\n  \"pad_left c n s = replicate (n - length s) c @ s\"\n\ndefinition pad_right :: \"'a \\<Rightarrow> nat \\<Rightarrow> 'a list \\<Rightarrow> 'a list\" where\n  \"pad_right c n s = s @ replicate (n - length s) c\"\n\nfun index_find :: \"nat \\<Rightarrow> 'a \\<times> 'a list \\<Rightarrow> nat option\" where\n  \"index_find _ (_, []) = None\" |\n  \"index_find i (v, h # t) = (if v = h then Some i else index_find (Suc i) (v, t))\"\n\ndefinition \"index_of = index_find 0\"\n\ndefinition remove :: \"'a list * 'a list \\<Rightarrow> 'a list\" where\n  \"remove p = (case p of (l1, l2) \\<Rightarrow> filter (\\<lambda>x. x \\<notin> set l1) l2)\"\n\ndefinition remove_except :: \"'a list * 'a list \\<Rightarrow> 'a list\" where\n  \"remove_except p = (case p of (l1, l2) \\<Rightarrow> filter (\\<lambda>x. x \\<in> set l1) l2)\"\n\nfun remove_duplicates :: \"'a list \\<Rightarrow> 'a list\" where\n  \"remove_duplicates [] = []\" |\n  \"remove_duplicates (h # t) = (if h \\<in> set t then remove_duplicates t else h # remove_duplicates t)\"\n\nlemma splitl_length:\n  shows \"length (fst (splitl P l)) + length (snd (splitl P l)) = length l\"\nby (induct l, auto simp add: case_prod_beta)\n\nlemma splitl_fst_length [simp]:\n  shows \"length (fst (splitl P x)) \\<le> length x\"\nusing splitl_length \nby (metis order_refl trans_le_add1)\n\nlemma splitl_snd_length [simp]:\n  shows \"length (snd (splitl P x)) \\<le> length x\"\nusing splitl_length \nby (metis order_refl trans_le_add2)\n\nlemma pad_left_length [simp]:\n  shows \"length (pad_left e n l) = max (length l) n\"\nunfolding pad_left_def\nby auto \n\nlemma pad_right_length [simp]:\n  shows \"length (pad_right e n l) = max (length l) n\"\nunfolding pad_right_def\nby auto\n\nlemma pad_left_nth:\n  shows \"pad_left e n l ! m = \n         (if m < n - List.length l \n          then e \n          else l ! (m - (n - List.length l)))\"\nunfolding pad_left_def nth_append\nby simp\n\n(* extra string operations *)\n\nlemma fields_termination_lem [simp]:\n  assumes \"a \\<noteq> []\" and \"length a \\<le> length c\"\n  shows \"length a - b < Suc (length c)\"\n  by (simp add: assms(2) le_imp_less_Suc less_imp_diff_less)\n\nfunction (sequential) tokens :: \"(char \\<Rightarrow> bool) \\<Rightarrow> string \\<Rightarrow> string list\" where\n  \"tokens _ '''' = []\" |\n  \"tokens P x =\n   (let (l, r) = splitl (\\<lambda>e. ~P e) x in if l = [] then tokens P (tl r) else l # tokens P r)\"\n  by pat_completeness auto\n  termination tokens\n  apply (relation \"measure (length o snd)\")\n  apply auto\n  apply (case_tac \"~ P v\", auto simp add: case_prod_beta le_imp_less_Suc)\n  apply (case_tac \"~ P v\", auto simp add: case_prod_beta le_imp_less_Suc)\n  done\n\nfunction (sequential) fields :: \"(char \\<Rightarrow> bool) \\<Rightarrow> string \\<Rightarrow> string list\" where\n  \"fields _ '''' = [[]]\" |\n  \"fields P x =\n   (let (l, r) = splitl (\\<lambda>e. ~P e) x in if l = [] then [] # fields P (tl r)\n                                        else if r = [] then [l]\n                                        else l # fields P (tl r))\"\n  by pat_completeness auto\n  termination fields\n  apply (relation \"measure (length o snd)\")\n  apply auto\n  apply (case_tac \"~ P v\", auto simp add: case_prod_beta le_imp_less_Suc)\n  apply (case_tac \"~ P v\", auto simp add: case_prod_beta)\n  done\n\n(* bit-string operations - extends Bool_List_Representation.thy *)\n\ndefinition nat_to_bitstring :: \"nat \\<Rightarrow> bool list\" where\n  \"nat_to_bitstring n = \n   (if n = 0 then [False] else bin_to_bl (log2 n + 1) (int n))\"\n\ndefinition \"bitstring_to_nat = nat o bl_to_bin\"\n\ndefinition fixwidth :: \"nat \\<Rightarrow> bool list \\<Rightarrow> bool list\" where\n  \"fixwidth n v = (let l = length v in if l < n then pad_left False n v else drop (l - n) v)\"\n\ndefinition bitwise :: \"(bool \\<Rightarrow> bool \\<Rightarrow> bool) \\<Rightarrow> bool list \\<Rightarrow> bool list \\<Rightarrow> bool list\" where\n  \"bitwise f v1 v2 =\n   (let m = max (length v1) (length v2) in map (case_prod f) (zip (fixwidth m v1) (fixwidth m v2)))\"\n\ndefinition \"bor  = bitwise (op \\<or>)\"\ndefinition \"band = bitwise (op \\<and>)\"\ndefinition \"bxor = bitwise (op \\<noteq>)\"\n\ndefinition bitstring_shiftl :: \"bool list \\<Rightarrow> nat \\<Rightarrow> bool list\" where\n  \"bitstring_shiftl v m = pad_right False (length v + m) v\"\n\ndefinition bitstring_shiftr :: \"bool list \\<Rightarrow> nat \\<Rightarrow> bool list\" where\n  \"bitstring_shiftr v m = take (length v - m) v\"\n\ndefinition bitstring_field :: \"nat \\<Rightarrow> nat \\<Rightarrow> bool list \\<Rightarrow> bool list\" where\n  \"bitstring_field h l v = fixwidth (Suc h - l) (bitstring_shiftr v l)\"\n\ndefinition bitstring_rotate :: \"bool list \\<Rightarrow> nat \\<Rightarrow> bool list\" where\n  \"bitstring_rotate v m =\n   (let l = length v in\n    let x = m mod l in\n      if l = 0 \\<or> x = 0 then v else bitstring_field (x - 1) 0 v @ bitstring_field (l - 1) x v)\"\n\ndefinition bitstring_test_bit :: \"bool list \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"bitstring_test_bit v n = (bitstring_field n n v = [True])\"\n\ndefinition bitstring_modify ::  \"(nat \\<times> bool \\<Rightarrow> bool) \\<times> bool list \\<Rightarrow> bool list\" where\n  \"bitstring_modify p = (case p of (f, l) \\<Rightarrow> map f (zip (rev (upt 0 (length l))) l))\"\n\ndefinition bitstring_field_insert :: \"nat \\<Rightarrow> nat \\<Rightarrow> bool list \\<Rightarrow> bool list \\<Rightarrow> bool list\" where\n  \"bitstring_field_insert h l v1 v2 =\n   bitstring_modify (\\<lambda>(i, b). if l \\<le> i \\<and> i \\<le> h then bitstring_test_bit v1 (i - l) else b, v2)\"\n\nlemma nat_to_bitstring_zero [simp]:\n  shows \"nat_to_bitstring 0 = [False]\"\nunfolding nat_to_bitstring_def by simp\n\n(* We do not add the following rule to the simp set, because n occurs twice at the right hand side,\nand therefore the state might not become simpler when applying this rule. *)\n\nlemma nat_to_bitstring_length:\n  shows \"length (nat_to_bitstring n) = (if n = 0 then 1 else log2 n + 1)\"\nunfolding nat_to_bitstring_def\nby (simp del: bin_to_bl_def)\n\nlemma fixwidth_length [simp]:\n  shows \"length (fixwidth n l) = n\"\nunfolding fixwidth_def Let_def\nby auto\n\nlemma bitwise_length [simp]:\n  shows \"length (bitwise f v1 v2) = max (length v1) (length v2)\"\nunfolding bitwise_def Let_def\nby auto\n\n(* extra word operations *)\n\ndefinition unsigned_min :: \"'a::len word \\<times> 'a::len word \\<Rightarrow> 'a::len word\" where\n  \"unsigned_min p = (case p of (w1, w2) \\<Rightarrow> (if w1 \\<le> w2 then w1 else w2))\"\n\ndefinition unsigned_max :: \"'a::len word \\<times> 'a::len word \\<Rightarrow> 'a::len word\" where\n  \"unsigned_max p = (case p of (w1, w2) \\<Rightarrow> (if w1 \\<le> w2 then w2 else w1))\"\n\ndefinition word_log2 :: \"'a::len word \\<Rightarrow> 'a::len word\" where\n  \"word_log2 w = of_nat (log2 (unat w))\"\n\ndefinition word_quot :: \"'a::len word \\<Rightarrow> 'a::len word \\<Rightarrow> 'a::len word\" where\n  \"word_quot i j = of_int (sint i quot sint j)\"\n\ndefinition word_rem :: \"'a::len word \\<Rightarrow> 'a::len word \\<Rightarrow> 'a::len word\" where\n  \"word_rem i j = of_int (sint i rem sint j)\"\n\ndefinition word_modify :: \"(nat \\<times> bool \\<Rightarrow> bool) \\<times> 'a::len word \\<Rightarrow> 'a::len word\" where\n  \"word_modify p = (case p of (f, w) \\<Rightarrow> of_bl (bitstring_modify (f, to_bl w)))\"\n\ndefinition word_bit_field_insert :: \"nat \\<Rightarrow> nat \\<Rightarrow> 'a::len word \\<Rightarrow> 'b::len word \\<Rightarrow> 'b::len word\" where\n  \"word_bit_field_insert h l w1 w2 =\n   word_modify (\\<lambda>(i, b). if l \\<le> i \\<and> i \\<le> h then test_bit w1 (i - l) else b, w2)\"\n\ndefinition word_bits :: \"nat \\<Rightarrow> nat \\<Rightarrow> 'a::len word \\<Rightarrow> 'a::len word\" where\n  \"word_bits h l w = (w >> l) AND mask (Suc h - l)\"\n\ndefinition word_extract :: \"nat \\<Rightarrow> nat \\<Rightarrow> 'a::len word \\<Rightarrow> 'b::len word\" where\n  \"word_extract h l w = ucast (word_bits h l w)\"\n\ndefinition word_replicate :: \"nat \\<Rightarrow> 'a::len word \\<Rightarrow> 'b::len word\" where\n  \"word_replicate n a = word_rcat (replicate n a)\"\n\n(* floating-point stubs *)\n\ndatatype ieee_rounding =\n  roundTiesToEven | roundTowardPositive | roundTowardNegative | roundTowardZero\n\ndatatype ieee_compare = LT | EQ | GT | UN\n\nconsts\n  fp32_abs :: \"32 word \\<Rightarrow> 32 word\"\n  fp32_add :: \"ieee_rounding \\<Rightarrow> 32 word \\<Rightarrow> 32 word \\<Rightarrow> 32 word\"\n  fp32_compare :: \"32 word \\<Rightarrow> 32 word \\<Rightarrow> ieee_compare\"\n  fp32_div :: \"ieee_rounding \\<Rightarrow> 32 word \\<Rightarrow> 32 word \\<Rightarrow> 32 word\"\n  fp32_equal :: \"32 word \\<Rightarrow> 32 word \\<Rightarrow> bool\"\n  fp32_from_int :: \"ieee_rounding \\<Rightarrow> int \\<Rightarrow> 32 word\"\n  fp32_greater :: \"32 word \\<Rightarrow> 32 word \\<Rightarrow> bool\"\n  fp32_greater_equal :: \"32 word \\<Rightarrow> 32 word \\<Rightarrow> bool\"\n  fp32_is_finite :: \"32 word \\<Rightarrow> bool\"\n  fp32_is_nan :: \"32 word \\<Rightarrow> bool\"\n  fp32_is_normal :: \"32 word \\<Rightarrow> bool\"\n  fp32_is_subnormal :: \"32 word \\<Rightarrow> bool\"\n  fp32_less :: \"32 word \\<Rightarrow> 32 word \\<Rightarrow> bool\"\n  fp32_less_equal :: \"32 word \\<Rightarrow> 32 word \\<Rightarrow> bool\"\n  fp32_mul :: \"ieee_rounding \\<Rightarrow> 32 word \\<Rightarrow> 32 word \\<Rightarrow> 32 word\"\n  fp32_mul_add :: \"ieee_rounding \\<Rightarrow> 32 word \\<Rightarrow> 32 word \\<Rightarrow> 32 word \\<Rightarrow> 32 word\"\n  fp32_mul_sub :: \"ieee_rounding \\<Rightarrow> 32 word \\<Rightarrow> 32 word \\<Rightarrow> 32 word \\<Rightarrow> 32 word\"\n  fp32_neg_inf :: \"32 word\"\n  fp32_neg_zero :: \"32 word\"\n  fp32_negate :: \"32 word \\<Rightarrow> 32 word\"\n  fp32_pos_inf :: \"32 word\"\n  fp32_pos_zero :: \"32 word\"\n  fp32_sqrt :: \"ieee_rounding \\<Rightarrow> 32 word \\<Rightarrow> 32 word\"\n  fp32_sub :: \"ieee_rounding \\<Rightarrow> 32 word \\<Rightarrow> 32 word \\<Rightarrow> 32 word\"\n  fp32_to_int :: \"ieee_rounding \\<Rightarrow> 32 word \\<Rightarrow> int option\"\n\nconsts\n  fp64_abs :: \"64 word \\<Rightarrow> 64 word\"\n  fp64_add :: \"ieee_rounding \\<Rightarrow> 64 word \\<Rightarrow> 64 word \\<Rightarrow> 64 word\"\n  fp64_compare :: \"64 word \\<Rightarrow> 64 word \\<Rightarrow> ieee_compare\"\n  fp64_div :: \"ieee_rounding \\<Rightarrow> 64 word \\<Rightarrow> 64 word \\<Rightarrow> 64 word\"\n  fp64_equal :: \"64 word \\<Rightarrow> 64 word \\<Rightarrow> bool\"\n  fp64_from_int :: \"ieee_rounding \\<Rightarrow> int \\<Rightarrow> 64 word\"\n  fp64_greater :: \"64 word \\<Rightarrow> 64 word \\<Rightarrow> bool\"\n  fp64_greater_equal :: \"64 word \\<Rightarrow> 64 word \\<Rightarrow> bool\"\n  fp64_is_finite :: \"64 word \\<Rightarrow> bool\"\n  fp64_is_nan :: \"64 word \\<Rightarrow> bool\"\n  fp64_is_normal :: \"64 word \\<Rightarrow> bool\"\n  fp64_is_subnormal :: \"64 word \\<Rightarrow> bool\"\n  fp64_less :: \"64 word \\<Rightarrow> 64 word \\<Rightarrow> bool\"\n  fp64_less_equal :: \"64 word \\<Rightarrow> 64 word \\<Rightarrow> bool\"\n  fp64_mul :: \"ieee_rounding \\<Rightarrow> 64 word \\<Rightarrow> 64 word \\<Rightarrow> 64 word\"\n  fp64_mul_add :: \"ieee_rounding \\<Rightarrow> 64 word \\<Rightarrow> 64 word \\<Rightarrow> 64 word \\<Rightarrow> 64 word\"\n  fp64_mul_sub :: \"ieee_rounding \\<Rightarrow> 64 word \\<Rightarrow> 64 word \\<Rightarrow> 64 word \\<Rightarrow> 64 word\"\n  fp64_neg_inf :: \"64 word\"\n  fp64_neg_zero :: \"64 word\"\n  fp64_negate :: \"64 word \\<Rightarrow> 64 word\"\n  fp64_pos_inf :: \"64 word\"\n  fp64_pos_zero :: \"64 word\"\n  fp64_sqrt :: \"ieee_rounding \\<Rightarrow> 64 word \\<Rightarrow> 64 word\"\n  fp64_sub :: \"ieee_rounding \\<Rightarrow> 64 word \\<Rightarrow> 64 word \\<Rightarrow> 64 word\"\n  fp64_to_int :: \"ieee_rounding \\<Rightarrow> 64 word \\<Rightarrow> int option\"\n\nconsts\n  fp32_to_fp64 :: \"32 word \\<Rightarrow> 64 word\"\n  fp64_to_fp32 :: \"ieee_rounding \\<Rightarrow> 64 word \\<Rightarrow> 32 word\"\n\ncode_printing\n    constant \"fp32_abs\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => raise Fail \\\"fp32'_abs\\\")\"\n      and (OCaml) \"!(fun '_ -> failwith \\\"fp32'_abs\\\")\"\n      and (Haskell) \"!(\\\\ '_ -> error \\\"fp32'_abs\\\")\"\n  | constant \"fp32_add\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => fn '_ => raise Fail \\\"fp32'_add\\\")\"\n      and (OCaml) \"!(fun '_ '_ '_ -> failwith \\\"fp32'_add\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ '_ -> error \\\"fp32'_add\\\")\"\n  | constant \"fp32_compare\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => raise Fail \\\"fp32'_compare\\\")\"\n      and (OCaml) \"!(fun '_ '_ -> failwith \\\"fp32'_compare\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ -> error \\\"fp32'_compare\\\")\"\n  | constant \"fp32_div\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => fn '_ => raise Fail \\\"fp32'_div\\\")\"\n      and (OCaml) \"!(fun '_ '_ '_ -> failwith \\\"fp32'_div\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ '_ -> error \\\"fp32'_div\\\")\"\n  | constant \"fp32_equal\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => raise Fail \\\"fp32'_equal\\\")\"\n      and (OCaml) \"!(fun '_ '_ -> failwith \\\"fp32'_equal\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ -> error \\\"fp32'_equal\\\")\"\n  | constant \"fp32_from_int\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => raise Fail \\\"fp32'_from'_int\\\")\"\n      and (OCaml) \"!(fun '_ '_ -> failwith \\\"fp32'_from'_int\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ -> error \\\"fp32'_from'_int\\\")\"\n  | constant \"fp32_greater\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => raise Fail \\\"fp32'_greater\\\")\"\n      and (OCaml) \"!(fun '_ '_ -> failwith \\\"fp32'_greater\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ -> error \\\"fp32'_greater\\\")\"\n  | constant \"fp32_greater_equal\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => raise Fail \\\"fp32'_greater'_equal\\\")\"\n      and (OCaml) \"!(fun '_ '_ -> failwith \\\"fp32'_greater'_equal\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ -> error \\\"fp32'_greater'_equal\\\")\"\n  | constant \"fp32_is_finite\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => raise Fail \\\"fp32'_is'_finite\\\")\"\n      and (OCaml) \"!(fun '_ -> failwith \\\"fp32'_is'_finite\\\")\"\n      and (Haskell) \"!(\\\\ '_ -> error \\\"fp32'_is'_finite\\\")\"\n  | constant \"fp32_is_nan\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => raise Fail \\\"fp32'_is'_nan\\\")\"\n      and (OCaml) \"!(fun '_ -> failwith \\\"fp32'_is'_nan\\\")\"\n      and (Haskell) \"!(\\\\ '_ -> error \\\"fp32'_is'_nan\\\")\"\n  | constant \"fp32_is_normal\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => raise Fail \\\"fp32'_is'_normal\\\")\"\n      and (OCaml) \"!(fun '_ -> failwith \\\"fp32'_is'_normal\\\")\"\n      and (Haskell) \"!(\\\\ '_ -> error \\\"fp32'_is'_normal\\\")\"\n  | constant \"fp32_is_subnormal\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => raise Fail \\\"fp32'_is'_subnormal\\\")\"\n      and (OCaml) \"!(fun '_ -> failwith \\\"fp32'_is'_subnormal\\\")\"\n      and (Haskell) \"!(\\\\ '_ -> error \\\"fp32'_is'_subnormal\\\")\"\n  | constant \"fp32_less\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => raise Fail \\\"fp32'_less\\\")\"\n      and (OCaml) \"!(fun '_ '_ -> failwith \\\"fp32'_less\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ -> error \\\"fp32'_less\\\")\"\n  | constant \"fp32_less_equal\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => raise Fail \\\"fp32'_less'_equal\\\")\"\n      and (OCaml) \"!(fun '_ '_ -> failwith \\\"fp32'_less'_equal\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ -> error \\\"fp32'_less'_equal\\\")\"\n  | constant \"fp32_mul\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => fn '_ => raise Fail \\\"fp32'_mul\\\")\"\n      and (OCaml) \"!(fun '_ '_ '_ -> failwith \\\"fp32'_mul\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ '_ -> error \\\"fp32'_mul\\\")\"\n  | constant \"fp32_mul_add\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => fn '_ => fn '_ => raise Fail \\\"fp32'_mul'_add\\\")\"\n      and (OCaml) \"!(fun '_ '_ '_ '_ -> failwith \\\"fp32'_mul'_add\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ '_ '_ -> error \\\"fp32'_mul'_add\\\")\"\n  | constant \"fp32_mul_sub\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => fn '_ => fn '_ => raise Fail \\\"fp32'_mul'_sub\\\")\"\n      and (OCaml) \"!(fun '_ '_ '_ '_ -> failwith \\\"fp32'_mul'_sub\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ '_ '_ -> error \\\"fp32'_mul'_sub\\\")\"\n  | constant \"fp32_neg_inf\" \\<rightharpoonup>\n      (SML) \"!(raise Fail \\\"fp32'_neg'_inf\\\")\"\n      and (OCaml) \"!(failwith \\\"fp32'_neg'_inf\\\")\"\n      and (Haskell) \"!(error \\\"fp32'_neg'_inf\\\")\"\n  | constant \"fp32_neg_zero\" \\<rightharpoonup>\n      (SML) \"!(raise Fail \\\"fp32'_neg'_zero\\\")\"\n      and (OCaml) \"!(failwith \\\"fp32'_neg'_zero\\\")\"\n      and (Haskell) \"!(error \\\"fp32'_neg'_zero\\\")\"\n  | constant \"fp32_negate\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => raise Fail \\\"fp32'_negate\\\")\"\n      and (OCaml) \"!(fun '_ -> failwith \\\"fp32'_negate\\\")\"\n      and (Haskell) \"!(\\\\ '_ -> error \\\"fp32'_negate\\\")\"\n  | constant \"fp32_pos_inf\" \\<rightharpoonup>\n      (SML) \"!(raise Fail \\\"fp32'_pos'_inf\\\")\"\n      and (OCaml) \"!(failwith \\\"fp32'_pos'_inf\\\")\"\n      and (Haskell) \"!(error \\\"fp32'_pos'_inf\\\")\"\n  | constant \"fp32_pos_zero\" \\<rightharpoonup>\n      (SML) \"!(raise Fail \\\"fp32'_pos'_zero\\\")\"\n      and (OCaml) \"!(failwith \\\"fp32'_pos'_zero\\\")\"\n      and (Haskell) \"!(error \\\"fp32'_pos'_zero\\\")\"\n  | constant \"fp32_sqrt\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => raise Fail \\\"fp32'_sqrt\\\")\"\n      and (OCaml) \"!(fun '_ '_ -> failwith \\\"fp32'_sqrt\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ -> error \\\"fp32'_sqrt\\\")\"\n  | constant \"fp32_sub\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => fn '_ => raise Fail \\\"fp32'_sub\\\")\"\n      and (OCaml) \"!(fun '_ '_ '_ -> failwith \\\"fp32'_sub\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ '_ -> error \\\"fp32'_sub\\\")\"\n  | constant \"fp32_to_int\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => raise Fail \\\"fp32'_to'_int\\\")\"\n      and (OCaml) \"!(fun '_ '_ -> failwith \\\"fp32'_to'_int\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ -> error \\\"fp32'_to'_int\\\")\"\n  | constant \"fp64_abs\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => raise Fail \\\"fp64'_abs\\\")\"\n      and (OCaml) \"!(fun '_ -> failwith \\\"fp64'_abs\\\")\"\n      and (Haskell) \"!(\\\\ '_ -> error \\\"fp64'_abs\\\")\"\n  | constant \"fp64_add\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => fn '_ => raise Fail \\\"fp64'_add\\\")\"\n      and (OCaml) \"!(fun '_ '_ '_ -> failwith \\\"fp64'_add\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ '_ -> error \\\"fp64'_add\\\")\"\n  | constant \"fp64_compare\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => raise Fail \\\"fp64'_compare\\\")\"\n      and (OCaml) \"!(fun '_ '_ -> failwith \\\"fp64'_compare\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ -> error \\\"fp64'_compare\\\")\"\n  | constant \"fp64_div\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => fn '_ => raise Fail \\\"fp64'_div\\\")\"\n      and (OCaml) \"!(fun '_ '_ '_ -> failwith \\\"fp64'_div\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ '_ -> error \\\"fp64'_div\\\")\"\n  | constant \"fp64_equal\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => raise Fail \\\"fp64'_equal\\\")\"\n      and (OCaml) \"!(fun '_ '_ -> failwith \\\"fp64'_equal\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ -> error \\\"fp64'_equal\\\")\"\n  | constant \"fp64_from_int\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => raise Fail \\\"fp64'_from'_int\\\")\"\n      and (OCaml) \"!(fun '_ '_ -> failwith \\\"fp64'_from'_int\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ -> error \\\"fp64'_from'_int\\\")\"\n  | constant \"fp64_greater\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => raise Fail \\\"fp64'_greater\\\")\"\n      and (OCaml) \"!(fun '_ '_ -> failwith \\\"fp64'_greater\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ -> error \\\"fp64'_greater\\\")\"\n  | constant \"fp64_greater_equal\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => raise Fail \\\"fp64'_greater'_equal\\\")\"\n      and (OCaml) \"!(fun '_ '_ -> failwith \\\"fp64'_greater'_equal\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ -> error \\\"fp64'_greater'_equal\\\")\"\n  | constant \"fp64_is_finite\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => raise Fail \\\"fp64'_is'_finite\\\")\"\n      and (OCaml) \"!(fun '_ -> failwith \\\"fp64'_is'_finite\\\")\"\n      and (Haskell) \"!(\\\\ '_ -> error \\\"fp64'_is'_finite\\\")\"\n  | constant \"fp64_is_nan\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => raise Fail \\\"fp64'_is'_nan\\\")\"\n      and (OCaml) \"!(fun '_ -> failwith \\\"fp64'_is'_nan\\\")\"\n      and (Haskell) \"!(\\\\ '_ -> error \\\"fp64'_is'_nan\\\")\"\n  | constant \"fp64_is_normal\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => raise Fail \\\"fp64'_is'_normal\\\")\"\n      and (OCaml) \"!(fun '_ -> failwith \\\"fp64'_is'_normal\\\")\"\n      and (Haskell) \"!(\\\\ '_ -> error \\\"fp64'_is'_normal\\\")\"\n  | constant \"fp64_is_subnormal\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => raise Fail \\\"fp64'_is'_subnormal\\\")\"\n      and (OCaml) \"!(fun '_ -> failwith \\\"fp64'_is'_subnormal\\\")\"\n      and (Haskell) \"!(\\\\ '_ -> error \\\"fp64'_is'_subnormal\\\")\"\n  | constant \"fp64_less\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => raise Fail \\\"fp64'_less\\\")\"\n      and (OCaml) \"!(fun '_ '_ -> failwith \\\"fp64'_less\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ -> error \\\"fp64'_less\\\")\"\n  | constant \"fp64_less_equal\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => raise Fail \\\"fp64'_less'_equal\\\")\"\n      and (OCaml) \"!(fun '_ '_ -> failwith \\\"fp64'_less'_equal\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ -> error \\\"fp64'_less'_equal\\\")\"\n  | constant \"fp64_mul\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => fn '_ => raise Fail \\\"fp64'_mul\\\")\"\n      and (OCaml) \"!(fun '_ '_ '_ -> failwith \\\"fp64'_mul\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ '_ -> error \\\"fp64'_mul\\\")\"\n  | constant \"fp64_mul_add\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => fn '_ => fn '_ => raise Fail \\\"fp64'_mul'_add\\\")\"\n      and (OCaml) \"!(fun '_ '_ '_ '_ -> failwith \\\"fp64'_mul'_add\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ '_ '_ -> error \\\"fp64'_mul'_add\\\")\"\n  | constant \"fp64_mul_sub\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => fn '_ => fn '_ => raise Fail \\\"fp64'_mul'_sub\\\")\"\n      and (OCaml) \"!(fun '_ '_ '_ '_ -> failwith \\\"fp64'_mul'_sub\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ '_ '_ -> error \\\"fp64'_mul'_sub\\\")\"\n  | constant \"fp64_neg_inf\" \\<rightharpoonup>\n      (SML) \"!(raise Fail \\\"fp64'_neg'_inf\\\")\"\n      and (OCaml) \"!(failwith \\\"fp64'_neg'_inf\\\")\"\n      and (Haskell) \"!(error \\\"fp64'_neg'_inf\\\")\"\n  | constant \"fp64_neg_zero\" \\<rightharpoonup>\n      (SML) \"!(raise Fail \\\"fp64'_neg'_zero\\\")\"\n      and (OCaml) \"!(failwith \\\"fp64'_neg'_zero\\\")\"\n      and (Haskell) \"!(error \\\"fp64'_neg'_zero\\\")\"\n  | constant \"fp64_negate\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => raise Fail \\\"fp64'_negate\\\")\"\n      and (OCaml) \"!(fun '_ -> failwith \\\"fp64'_negate\\\")\"\n      and (Haskell) \"!(\\\\ '_ -> error \\\"fp64'_negate\\\")\"\n  | constant \"fp64_pos_inf\" \\<rightharpoonup>\n      (SML) \"!(raise Fail \\\"fp64'_pos'_inf\\\")\"\n      and (OCaml) \"!(failwith \\\"fp64'_pos'_inf\\\")\"\n      and (Haskell) \"!(error \\\"fp64'_pos'_inf\\\")\"\n  | constant \"fp64_pos_zero\" \\<rightharpoonup>\n      (SML) \"!(raise Fail \\\"fp64'_pos'_zero\\\")\"\n      and (OCaml) \"!(failwith \\\"fp64'_pos'_zero\\\")\"\n      and (Haskell) \"!(error \\\"fp64'_pos'_zero\\\")\"\n  | constant \"fp64_sqrt\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => raise Fail \\\"fp64'_sqrt\\\")\"\n      and (OCaml) \"!(fun '_ '_ -> failwith \\\"fp64'_sqrt\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ -> error \\\"fp64'_sqrt\\\")\"\n  | constant \"fp64_sub\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => fn '_ => raise Fail \\\"fp64'_sub\\\")\"\n      and (OCaml) \"!(fun '_ '_ '_ -> failwith \\\"fp64'_sub\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ '_ -> error \\\"fp64'_sub\\\")\"\n  | constant \"fp64_to_int\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => raise Fail \\\"fp64'_to'_int\\\")\"\n      and (OCaml) \"!(fun '_ '_ -> failwith \\\"fp64'_to'_int\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ -> error \\\"fp64'_to'_int\\\")\"\n  | constant \"fp32_to_fp64\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => raise Fail \\\"fp32'_to'_fp64\\\")\"\n      and (OCaml) \"!(fun '_ -> failwith \\\"fp32'_to'_fp64\\\")\"\n      and (Haskell) \"!(\\\\ '_ -> error \\\"fp32'_to'_fp64\\\")\"\n  | constant \"fp64_to_fp32\" \\<rightharpoonup>\n      (SML) \"!(fn '_ => fn '_ => raise Fail \\\"fp64'_to'_fp32\\\")\"\n      and (OCaml) \"!(fun '_ '_ -> failwith \\\"fp64'_to'_fp32\\\")\"\n      and (Haskell) \"!(\\\\ '_ '_ -> error \\\"fp64'_to'_fp32\\\")\"\n\nend\n", "meta": {"author": "acjf3", "repo": "acjf3.github.io", "sha": "6e5713c36c4fb0a87a2c366ca4f6a15acb710195", "save_path": "github-repos/isabelle/acjf3-acjf3.github.io", "path": "github-repos/isabelle/acjf3-acjf3.github.io/acjf3.github.io-6e5713c36c4fb0a87a2c366ca4f6a15acb710195/l3/isabelle/2015/L3_Lib.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.519521307073646, "lm_q2_score": 0.5195213219520929, "lm_q1q2_score": 0.26990239623317974}}
{"text": "theory Typeclass_Hierarchy\nimports Setup\nbegin\n\nsection \\<open>Introduction\\<close>\n\ntext \\<open>\n  The {Isabelle/HOL} type-class hierarchy entered the stage\n  in a quite ancient era -- first related \\<^emph>\\<open>NEWS\\<close> entries date\n  back to release {Isabelle99-1}.  Since then, there have been\n  ongoing modifications and additions, leading to ({Isabelle2016})\n  more than 180 type-classes.  This sheer complexity makes access\n  and understanding of that type-class hierarchy difficult and\n  involved, let alone maintenance.\n\n  The purpose of this primer is to shed some light on this,\n  not only on the mere ingredients, but also on the design\n  principles which have evolved and proven useful over time.\n\\<close>\n\nsection \\<open>Foundations\\<close>\n\nsubsection \\<open>Locales and type classes\\<close>\n\ntext \\<open>\n  Some familiarity with the Isabelle module system is assumed:\n  defining locales and type-classes, interpreting locales and\n  instantiating type-classes, adding relationships between\n  locales (@{command sublocale}) and type-classes\n  (@{command subclass}).  Handy introductions are the\n  respective tutorials \\cite{isabelle-locale}\n  \\cite{isabelle-classes}.\n\\<close>\n\nsubsection \\<open>Strengths and restrictions of type classes\\<close>\n\ntext \\<open>\n  The primary motivation for using type classes in {Isabelle/HOL}\n  always have been numerical types, which form an inclusion chain:\n  \n  \\begin{center}\n    @{typ nat} @{text \\<sqsubset>} @{typ int} @{text \\<sqsubset>} @{typ rat}\n      @{text \\<sqsubset>} @{typ real} @{text \\<sqsubset>} @{typ complex}\n  \\end{center}\n\n  \\noindent The inclusion @{text \\<sqsubset>} means that any value of the numerical\n  type to the left hand side mathematically can be transferred\n  to the numerical type on the right hand side.\n\n  How to accomplish this given the quite restrictive type system\n  of {Isabelle/HOL}?  Paulson \\cite{paulson-numerical} explains\n  that each numerical type has some characteristic properties\n  which define an characteristic algebraic structure;  @{text \\<sqsubset>}\n  then corresponds to specialization of the corresponding\n  characteristic algebraic structures.  These algebraic structures\n  are expressed using algebraic type classes and embeddings\n  of numerical types into them:\n\n  \\begin{center}\\begin{tabular}{lccc}\n    @{term of_nat} @{text \"::\"}  & @{typ nat}  & @{text \\<Rightarrow>} & @{typ [source] \"'a::semiring_1\"} \\\\\n                                 & @{text \\<sqinter>}   &            & @{text \\<up>} \\\\\n    @{term of_int} @{text \"::\"}  & @{typ int}  & @{text \\<Rightarrow>} & @{typ [source] \"'a::ring_1\"} \\\\\n                                 & @{text \\<sqinter>}   &            & @{text \\<up>} \\\\\n    @{term of_rat} @{text \"::\"}  & @{typ rat}  & @{text \\<Rightarrow>} & @{typ [source] \"'a::field_char_0\"} \\\\\n                                 & @{text \\<sqinter>}   &            & @{text \\<up>} \\\\\n    @{term of_real} @{text \"::\"} & @{typ real} & @{text \\<Rightarrow>} & @{typ [source] \"'a::real_algebra_1\"} \\\\\n                                 & @{text \\<sqinter>} \\\\\n                                 & @{typ complex}\n  \\end{tabular}\\end{center}\n\n  \\noindent @{text \"d \\<leftarrow> c\"} means that @{text c} is subclass of @{text d}.\n  Hence each characteristic embedding @{text of_num} can transform\n  any value of type @{text num} to any numerical type further\n  up in the inclusion chain.\n\n  This canonical example exhibits key strengths of type classes:\n\n    \\<^item> Sharing of operations and facts among different\n      types, hence also sharing of notation and names: there\n      is only one plus operation using infix syntax @{text \"+\"},\n      only one zero written @{text 0}, and neutrality\n      (@{thm (frugal_sorts) add_0_left [all, no_vars]} and\n      @{thm (frugal_sorts) add_0_right [all, no_vars]})\n      is referred to\n      uniformly by names @{fact add_0_left} and @{fact add_0_right}.\n\n    \\<^item> Proof tool setups are shared implicitly:\n      @{fact add_0} and @{fact add_0_right} are simplification\n      rules by default.\n\n    \\<^item> Hence existing proofs about particular numerical\n      types are often easy to generalize to algebraic structures,\n      given that they do not depend on specific properties of\n      those numerical types.\n\n  Considerable restrictions include:\n\n    \\<^item> Type class operations are restricted to one\n      type parameter; this is insufficient e.g. for expressing\n      a unified power operation adequately (see \\secref{sec:power}).\n\n    \\<^item> Parameters are fixed over the whole type class\n      hierarchy and cannot be refined in specific situations:\n      think of integral domains with a predicate @{term is_unit};\n      for natural numbers, this degenerates to the much simpler\n      @{term [source] \"HOL.equal (1::nat)\"} but facts\n      refer to @{term is_unit} nonetheless.\n\n    \\<^item> Type classes are not apt for meta-theory.  There\n      is no practically usable way to express that the units\n      of an integral domain form a multiplicative group using\n      type classes.  But see session @{text \"HOL-Algebra\"}\n      which provides locales with an explicit carrier.\n\\<close>\n\n\nsubsection \\<open>Navigating the hierarchy\\<close>\n\ntext \\<open>\n  An indispensable tool to inspect the class hierarchy is\n  @{command class_deps} which displays the graph of classes,\n  optionally showing the logical content for each class also.\n  Optional parameters restrict the graph to a particular segment\n  which is useful to get a graspable view.  See\n  the Isar reference manual \\cite{isabelle-isar-ref} for details.\n\\<close>\n\n\nsection \\<open>The hierarchy\\<close>\n\nsubsection \\<open>Syntactic type classes \\label{sec:syntactic-type-class}\\<close>\n\ntext \\<open>\n  At the top of the hierarchy there are a couple of syntactic type\n  classes, ie. classes with operations but with no axioms,\n  most notably:\n\n    \\<^item> @{command class} @{class plus} with @{term [source] \"(a::'a::plus) + b\"}\n\n    \\<^item> @{command class} @{class zero} with @{term [source] \"0::'a::zero\"}\n\n    \\<^item> @{command class} @{class times} with @{term [source] \"(a::'a::times) * b\"}\n\n    \\<^item> @{command class} @{class one} with @{term [source] \"1::'a::one\"}\n\n  \\noindent Before the introduction of the @{command class} statement in\n  Isabelle \\cite{Haftmann-Wenzel:2006:classes} it was impossible\n  to define operations with associated axioms in the same class,\n  hence there were always pairs of syntactic and logical type\n  classes.  This restriction is lifted nowadays, but there are\n  still reasons to maintain syntactic type classes:\n\n    \\<^item> Syntactic type classes allow generic notation to be used\n      regardless of a particular logical interpretation; e.g.\n      although multiplication @{text \"*\"} is usually associative,\n      there are examples where it is not (e.g. octonions), and\n      leaving @{text \"*\"} without axioms allows to re-use this\n      syntax by means of type class instantiation also for such\n      exotic examples.\n\n    \\<^item> Type classes might share operations but not necessarily\n      axioms on them, e.g. @{term gcd} (see \\secref{sec:gcd}).\n      Hence their common base is a syntactic type class.\n\n  \\noindent However syntactic type classes should only be used with striking\n  cause.  Otherwise there is risk for confusion if the notation\n  suggests properties which do not hold without particular\n  constraints.  This can be illustrated using numerals\n  (see \\secref{sec:numerals}):  @{lemma \"2 + 2 = 4\" by simp} is\n  provable without further ado, and this also meets the typical\n  expectation towards a numeral notation;  in more ancient releases\n  numerals were purely syntactic and @{prop \"2 + 2 = 4\"} was\n  not provable without particular type constraints.\n\\<close>\n\n\nsubsection \\<open>Additive and multiplicative semigroups and monoids\\<close>\n\ntext \\<open>\n  In common literature, notation for semigroups and monoids\n  is either multiplicative @{text \"(*, 1)\"} or additive\n  @{text \"(+, 0)\"} with underlying properties isomorphic.\n  In {Isabelle/HOL}, this is accomplished using the following\n  abstract setup:\n\n    \\<^item> A @{locale semigroup} introduces an abstract binary\n      associative operation.\n\n    \\<^item> A @{locale monoid} is an extension of @{locale semigroup}\n      with a neutral element.\n\n    \\<^item> Both @{locale semigroup} and @{locale monoid} provide\n      dedicated syntax for their operations @{text \"(\\<^bold>*, \\<^bold>1)\"}.\n      This syntax is not visible on the global theory level\n      but only for abstract reasoning inside the respective\n      locale.\n\n    \\<^item> Concrete global syntax is added building on existing\n      syntactic type classes \\secref{sec:syntactic-type-class}\n      using the following classes:\n\n        \\<^item> @{command class} @{class semigroup_mult} = @{class times}\n\n        \\<^item> @{command class} @{class monoid_mult} = @{class one} + @{class semigroup_mult}\n\n        \\<^item> @{command class} @{class semigroup_add} = @{class plus}\n\n        \\<^item> @{command class} @{class monoid_add} = @{class zero} + @{class semigroup_add}\n\n      Locales @{locale semigroup} and @{locale monoid} are\n      interpreted (using @{command sublocale}) into their\n      corresponding type classes, with prefixes @{text add}\n      and @{text mult}; hence facts derived in @{locale semigroup}\n      and @{locale monoid} are propagated simultaneously to\n      \\<^emph>\\<open>both\\<close> using a consistent naming policy, ie.\n\n        \\<^item> @{fact semigroup.assoc}: @{thm (frugal_sorts) semigroup.assoc [all, no_vars]}\n\n        \\<^item> @{fact mult.assoc}: @{thm (frugal_sorts) mult.assoc [all, no_vars]}\n\n        \\<^item> @{fact add.assoc}: @{thm (frugal_sorts) add.assoc [all, no_vars]}\n\n        \\<^item> @{fact monoid.right_neutral}: @{thm (frugal_sorts) monoid.right_neutral [all, no_vars]}\n\n        \\<^item> @{fact mult.right_neutral}: @{thm (frugal_sorts) mult.right_neutral [all, no_vars]}\n\n        \\<^item> @{fact add.right_neutral}: @{thm (frugal_sorts) add.right_neutral [all, no_vars]}\n\n    \\<^item> Note that the syntax in @{locale semigroup} and @{locale monoid}\n      is bold; this avoids clashes when writing properties\n      inside one of these locales in presence of that global\n      concrete type class syntax.\n\n  \\noindent That hierarchy extends in a straightforward manner\n  to abelian semigroups and commutative monoids\\footnote{The\n  designation \\<^emph>\\<open>abelian\\<close> is quite standard concerning\n  (semi)groups, but not for monoids}:\n\n    \\<^item> Locales @{locale abel_semigroup} and @{locale comm_monoid}\n      add commutativity as property.\n\n    \\<^item> Concrete syntax emerges through\n\n        \\<^item> @{command class} @{class ab_semigroup_add} = @{class semigroup_add}\n\n        \\<^item> @{command class} @{class ab_semigroup_mult} = @{class semigroup_mult}\n\n        \\<^item> @{command class} @{class comm_monoid_add} = @{class zero} + @{class ab_semigroup_add}\n\n        \\<^item> @{command class} @{class comm_monoid_mult} = @{class one} + @{class ab_semigroup_mult}\n  \n      and corresponding interpretation of the locales above, yielding\n\n        \\<^item> @{fact abel_semigroup.commute}: @{thm (frugal_sorts) abel_semigroup.commute [all, no_vars]}\n\n        \\<^item> @{fact mult.commute}: @{thm (frugal_sorts) mult.commute [all, no_vars]}\n\n        \\<^item> @{fact add.commute}: @{thm (frugal_sorts) add.commute [all, no_vars]}\n\\<close>\n\nparagraph \\<open>Named collection of theorems\\<close>\n\ntext \\<open>\n  Locale interpretation interacts smoothly with named collections of\n  theorems as introduced by command @{command named_theorems}.  In our\n  example, rules concerning associativity and commutativity are no\n  simplification rules by default since they desired orientation may\n  vary depending on the situation.  However, there is a collection\n  @{fact ac_simps} where facts @{fact abel_semigroup.assoc},\n  @{fact abel_semigroup.commute} and @{fact abel_semigroup.left_commute}\n  are declared as members.  Due to interpretation, also\n  @{fact mult.assoc}, @{fact mult.commute} and @{fact mult.left_commute}\n  are also members of @{fact ac_simps}, as any corresponding facts\n  stemming from interpretation of @{locale abel_semigroup}.\n  Hence adding @{fact ac_simps} to the simplification rules for\n  a single method call uses all associativity and commutativity\n  rules known by means of interpretation.\n\\<close>\n\n\nsubsection \\<open>Additive and multiplicative groups\\<close>\n\ntext \\<open>\n  The hierarchy for inverse group operations takes into account\n  that there are weaker algebraic structures with only a partially\n  inverse operation.  E. g. the natural numbers have bounded\n  subtraction @{term \"m - (n::nat)\"} which is only an inverse\n  operation if @{term \"m \\<ge> (n::nat)\"};  unary minus @{text \"-\"}\n  is pointless on the natural numbers.\n\n  Hence for both additive and multiplicative notation there\n  are syntactic classes for inverse operations, both unary\n  and binary:\n\n    \\<^item> @{command class} @{class minus} with @{term [source] \"(a::'a::minus) - b\"}\n\n    \\<^item> @{command class} @{class uminus} with @{term [source] \"- a::'a::uminus\"}\n\n    \\<^item> @{command class} @{class divide} with @{term [source] \"(a::'a::divide) div b\"}\n\n    \\<^item> @{command class} @{class inverse} = @{class divide} with @{term [source] \"inverse a::'a::inverse\"}\n        \\\\ and @{term [source] \"(a::'a::inverse) / b\"}\n\n  \\noindent Here @{class inverse} specializes the ``partial'' syntax\n  @{term [source] \"a div b\"} to the more specific\n  @{term [source] \"a / b\"}. \n\n  Semantic properties are added by\n\n    \\<^item> @{command class} @{class cancel_ab_semigroup_add} = @{class ab_semigroup_add} + @{class minus}\n\n    \\<^item> @{command class} @{class cancel_comm_monoid_add} = @{class cancel_ab_semigroup_add} + @{class comm_monoid_add}\n\n  \\noindent which specify a minimal binary partially inverse operation as\n\n    \\<^item> @{fact add_diff_cancel_left'}: @{thm (frugal_sorts) add_diff_cancel_left' [all, no_vars]}\n\n    \\<^item> @{fact diff_diff_add}: @{thm (frugal_sorts) diff_diff_add [all, no_vars]}\n\n  \\noindent which in turn allow to derive facts like\n\n    \\<^item> @{fact add_left_imp_eq}: @{thm (frugal_sorts) add_left_imp_eq [all, no_vars]}\n\n  \\noindent The total inverse operation is established as follows:\n\n    \\<^item> Locale @{locale group} extends the abstract hierarchy with\n      the inverse operation.\n\n    \\<^item> The concrete additive inverse operation emerges through\n\n      \\<^item> @{command class} @{class group_add} = @{class minus} + @{class uminus} + @{class monoid_add} (in @{theory Groups}) \\\\\n\n      \\<^item> @{command class} @{class ab_group_add} = @{class minus} + @{class uminus} + @{class comm_monoid_add} (in @{theory Groups})\n\n      and corresponding interpretation of locale @{locale group}, yielding e.g.\n\n      \\<^item> @{fact group.left_inverse}: @{thm (frugal_sorts) group.left_inverse [all, no_vars]}\n\n      \\<^item> @{fact add.left_inverse}: @{thm (frugal_sorts) add.left_inverse [all, no_vars]}\n\n  \\noindent There is no multiplicative counterpart.  Why?  In rings,\n  the multiplicative group excludes the zero element, hence\n  the inverse operation is not total.  See further \\secref{sec:rings}.\n\\<close>\n\nparagraph \\<open>Mitigating against redundancy by default simplification rules\\<close>\n\ntext \\<open>\n  Inverse operations imposes some redundancy on the type class\n  hierarchy: in a group with a total inverse operation, the\n  unary operation is simpler and more primitive than the binary\n  one; but we cannot eliminate the binary one in favour of\n  a mere syntactic abbreviation since the binary one is vital\n  to express a partial inverse operation.\n\n  This is mitigated by providing suitable default simplification\n  rules: expression involving the unary inverse operation are\n  simplified to binary inverse operation whenever appropriate.\n  The rationale is that simplification is a central device in\n  explorative proving, where proof obligation remaining after certain\n  default proof steps including simplification are inspected\n  to get an idea what is missing to finish a proof.  When\n  preferable normal forms are encoded into\n  default simplification rules, proof obligations after simplification\n  are normalized and hence more proof-friendly.\n\\<close>\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/Doc/Typeclass_Hierarchy/Typeclass_Hierarchy.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.523420348936324, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.2698859562062589}}
{"text": "section \\<open>Implementation of Heaps by Arrays\\<close>\ntheory IICF_Impl_Heapmap\nimports \n  IICF_Abs_Heapmap \n  \"../IICF_Array\" \n  \"../IICF_Array_List\" \n  \"../IICF_Indexed_Array_List\"\nbegin\n\n  term hfref\n\n  \n  find_theorems INTF_OF_REL\n\n  lemma intf_of_b_rel[synth_rules]: \"INTF_OF_REL R I \\<Longrightarrow> INTF_OF_REL (b_rel R P) I\" by simp\n\n  lemma b_assn_intf[intf_of_assn]: \"intf_of_assn V I \\<Longrightarrow> intf_of_assn (b_assn V P) I\"\n    by simp\n  \n  \n  (* TODO: Move *)\n  lemma mk_free_b_assn[sepref_frame_free_rules]:\n    assumes \"MK_FREE A f\"  \n    shows \"MK_FREE (b_assn A P) f\"  \n  proof -\n    note [vcg_rules] = assms[THEN MK_FREED]\n    show ?thesis by rule vcg\n  qed\n  \n  \n  (* TODO: Move *)\n    \n    \n  (*  \n  type_synonym 'a iam1 = \"'a list\"\n\n  definition iam1_rel :: \"nat \\<Rightarrow> ('a iam1 \\<times> (nat\\<rightharpoonup>'a)) set\"\n    where \"iam1_rel N \\<equiv> br (\\<lambda>xs i. if i<length xs then Some (xs!i) else None) (\\<lambda>xs. length xs = N)\"\n\n  definition iam1_init :: \"nat \\<Rightarrow> 'a \\<Rightarrow> 'a iam1 nres\" where \"iam1_init N v \\<equiv> RETURN (replicate N v)\"\n  definition iam1_lookup :: \"nat \\<Rightarrow> 'a iam1 \\<Rightarrow> 'a nres\" \n    where \"iam1_lookup k m \\<equiv> mop_list_get m k\"\n    \n  definition iam1_update :: \"nat \\<Rightarrow> 'a \\<Rightarrow> 'a iam1 \\<Rightarrow> 'a iam1 nres\"\n    where \"iam1_update k v m \\<equiv> mop_list_set m k v\"\n  \n  (*definition abs_iam_empty :: \"nat \\<Rightarrow> (nat \\<rightharpoonup> 'a) nres\" \n    where \"abs_iam_empty (N::nat) \\<equiv> RETURN Map.empty\"\n  *)\n    \n  sepref_decl_op iam_init: \"\\<lambda>(N::nat) (v::'a). \\<lambda>k. if k<N then Some v else None\" :: \"nat_rel \\<rightarrow> V \\<rightarrow> \\<langle>nat_rel,V\\<rangle> map_rel\"\n    apply (rule frefI)\n    apply parametricity\n    by (auto simp: map_rel_def)\n  \n  lemma iam1_empty_refine: \"(uncurry iam1_init,uncurry mop_iam_init) \n    \\<in> [\\<lambda>(N',v). N'=N]\\<^sub>f nat_rel \\<times>\\<^sub>r Id \\<rightarrow> \\<langle>iam1_rel N\\<rangle>nres_rel\"\n    unfolding iam1_init_def \n    by (auto intro!: frefI nres_relI simp: iam1_rel_def in_br_conv fun_eq_iff)\n  \n  lemma iam1_lookup_refine: \n    \"(iam1_lookup, mop_map_the_lookup) \\<in> nbn_rel N \\<rightarrow> iam1_rel N \\<rightarrow> \\<langle>Id\\<rangle>nres_rel\"\n    unfolding iam1_lookup_def \n    apply (refine_vcg frefI)\n    by (auto simp: iam1_rel_def in_br_conv)\n    \n  lemma iam1_update_refine:\n    \"(iam1_update, mop_map_update) \n      \\<in> nbn_rel N \\<rightarrow>Id \\<rightarrow> iam1_rel N \\<rightarrow> \\<langle>iam1_rel N\\<rangle>nres_rel\"\n    unfolding iam1_update_def \n    apply (refine_vcg frefI)\n    by (auto simp: iam1_rel_def in_br_conv fun_eq_iff)\n    \n  \n    \n    \n  context\n    fixes L :: \"'l::len2 itself\"  \n    (*notes [fcomp_norm_unfold] = snatb_rel_def[symmetric]*)\n  begin\n    \n    private abbreviation (input) \"iam2_assn \\<equiv> array_assn id_assn\"\n  \n    definition \"iam_assn N V \\<equiv> hr_comp \n      (hr_comp iam2_assn (iam1_rel N))\n      (\\<langle>nat_rel, the_pure V\\<rangle>map_rel)\"\n    lemmas [fcomp_norm_unfold] = iam_assn_def[symmetric]\n  \n\n    lemma iam_assn_intf[intf_of_assn]: \"intf_of_assn V TYPE('v) \\<Longrightarrow> intf_of_assn (iam_assn N V) (TYPE((nat,'v)i_map))\"\n      by simp\n        \n    sepref_definition iam_init_impl is \"uncurry iam1_init\"\n      :: \"(snat_assn' TYPE('l))\\<^sup>k *\\<^sub>a id_assn\\<^sup>k \\<rightarrow>\\<^sub>a iam2_assn\"\n      unfolding iam1_init_def\n      apply (subst array_fold_custom_replicate)\n      by sepref\n    sepref_decl_impl (ismop) iam_init_impl.refine[FCOMP iam1_empty_refine] by auto\n\n    sepref_definition iam_lookup_impl is \"uncurry iam1_lookup\" \n      :: \"(snat_assn' TYPE('l))\\<^sup>k *\\<^sub>a iam2_assn\\<^sup>k \\<rightarrow>\\<^sub>a id_assn\"\n      unfolding iam1_lookup_def\n      by sepref\n    sepref_decl_impl (ismop) iam_lookup_impl.refine[FCOMP iam1_lookup_refine] \n      uses mop_map_the_lookup.fref[where K=Id] .\n                                                            \n    sepref_definition iam_update_impl is \"uncurry2 iam1_update\"  \n      :: \"(snat_assn' TYPE('l))\\<^sup>k *\\<^sub>a id_assn\\<^sup>k *\\<^sub>a iam2_assn\\<^sup>d \\<rightarrow>\\<^sub>a iam2_assn\"\n      unfolding iam1_update_def\n      by sepref\n    sepref_decl_impl (ismop) iam_update_impl.refine[FCOMP iam1_update_refine] \n      uses mop_map_update.fref[where K=Id] .\n  \n  end    \n\n  *)\n\n  type_synonym 'a iam1 = \"'a list\"\n\n  definition iam1_rel :: \"nat \\<Rightarrow> ('a iam1 \\<times> (nat\\<rightharpoonup>'a)) set\"\n    where \"iam1_rel N \\<equiv> {(xs,m). length xs = N \\<and> dom m \\<subseteq> {0..<N} \\<and> (\\<forall>k v. m k = Some v \\<longrightarrow> v=xs!k)}\"\n\n  definition iam1_init :: \"nat \\<Rightarrow> 'a::llvm_rep iam1 nres\" where \"iam1_init N \\<equiv> RETURN (replicate N init)\"\n  definition iam1_lookup :: \"nat \\<Rightarrow> 'a iam1 \\<Rightarrow> 'a nres\" \n    where \"iam1_lookup k m \\<equiv> mop_list_get m k\"\n    \n  definition iam1_update :: \"nat \\<Rightarrow> 'a \\<Rightarrow> 'a iam1 \\<Rightarrow> 'a iam1 nres\"\n    where \"iam1_update k v m \\<equiv> mop_list_set m k v\"\n  \n  sepref_decl_op iam_empty: \"\\<lambda>(N::nat). Map.empty :: nat \\<rightharpoonup> _\" :: \"nat_rel \\<rightarrow> \\<langle>nat_rel,V\\<rangle> map_rel\" .\n  \n  lemma iam_fold_custom_empty:\n    \"op_map_empty = op_iam_empty N\"\n    \"Map.empty = op_iam_empty N\"\n    \"mop_map_empty = mop_iam_empty N\"\n    by auto\n  \n  \n  lemma iam1_empty_refine: \"(iam1_init,mop_iam_empty) \n    \\<in> [\\<lambda>N'. N'=N]\\<^sub>f nat_rel \\<rightarrow> \\<langle>iam1_rel N\\<rangle>nres_rel\"\n    unfolding iam1_init_def\n    by (auto intro!: frefI nres_relI simp: iam1_rel_def in_br_conv fun_eq_iff)\n  \n  lemma iam1_lookup_refine: \n    \"(iam1_lookup, mop_map_the_lookup) \\<in> nbn_rel N \\<rightarrow> iam1_rel N \\<rightarrow> \\<langle>Id\\<rangle>nres_rel\"\n    apply (clarsimp simp: iam1_lookup_def)\n    apply (refine_vcg)\n    apply (auto simp: iam1_rel_def in_br_conv)\n    done\n    \n  lemma iam1_update_refine:\n    \"(iam1_update, mop_map_update) \n      \\<in> nbn_rel N \\<rightarrow>Id \\<rightarrow> iam1_rel N \\<rightarrow> \\<langle>iam1_rel N\\<rangle>nres_rel\"\n    unfolding iam1_update_def \n    apply (refine_vcg frefI)\n    by (auto simp: iam1_rel_def in_br_conv fun_eq_iff)\n    \n  \n    \n  context\n    fixes L :: \"'l::len2 itself\"  \n    (*notes [fcomp_norm_unfold] = snatb_rel_def[symmetric]*)\n  begin\n    \n    private abbreviation (input) \"iam2_assn \\<equiv> array_assn id_assn\"\n  \n    definition \"iam_assn N V \\<equiv> hr_comp \n      (hr_comp iam2_assn (iam1_rel N))\n      (\\<langle>nat_rel, the_pure V\\<rangle>map_rel)\"\n    lemmas [fcomp_norm_unfold] = iam_assn_def[symmetric]\n  \n\n    lemma iam_assn_intf[intf_of_assn]: \"intf_of_assn V TYPE('v) \\<Longrightarrow> intf_of_assn (iam_assn N V) (TYPE((nat,'v)i_map))\"\n      by simp\n        \n    sepref_definition iam_init_impl [llvm_inline] is \"iam1_init\"\n      :: \"(snat_assn' TYPE('l))\\<^sup>k \\<rightarrow>\\<^sub>a iam2_assn\"\n      unfolding iam1_init_def\n      supply [sepref_import_param] = IdI[of init]\n      apply (subst array_fold_custom_replicate)\n      by sepref\n      \n    sepref_decl_impl (ismop,no_register) iam_empty: iam_init_impl.refine[FCOMP iam1_empty_refine] by auto\n    \n    sepref_definition iam_lookup_impl [llvm_inline] is \"uncurry iam1_lookup\" \n      :: \"(snat_assn' TYPE('l))\\<^sup>k *\\<^sub>a iam2_assn\\<^sup>k \\<rightarrow>\\<^sub>a id_assn\"\n      unfolding iam1_lookup_def\n      by sepref\n    sepref_decl_impl (ismop) iam_lookup_impl.refine[FCOMP iam1_lookup_refine] \n      uses mop_map_the_lookup.fref[where K=Id] .\n                                                            \n    sepref_definition iam_update_impl [llvm_inline] is \"uncurry2 iam1_update\"  \n      :: \"(snat_assn' TYPE('l))\\<^sup>k *\\<^sub>a id_assn\\<^sup>k *\\<^sub>a iam2_assn\\<^sup>d \\<rightarrow>\\<^sub>a iam2_assn\"\n      unfolding iam1_update_def\n      by sepref\n    sepref_decl_impl (ismop) iam_update_impl.refine[FCOMP iam1_update_refine] \n      uses mop_map_update.fref[where K=Id] .\n  \n  end    \n  \n  \n            find_theorems \"?x[_:=_] = ?x\"\n\n  \n  type_synonym ('v) iam = \"'v ptr\"\n  \n  schematic_goal [sepref_frame_free_rules]: \"MK_FREE (iam_assn N V) (?fr)\"\n    unfolding iam_assn_def\n    by sepref_dbg_side\n  \n  xxx, ctd here: Explicit parameterization on N. Use dependent relation for constructors!  \n    \n\n  locale hm_impl = hmstruct prio for prio :: \"'e \\<Rightarrow> 'p::linorder\" +\n    fixes prio_assn :: \"'p \\<Rightarrow> 'pi::llvm_rep \\<Rightarrow> assn\"\n      and elem_assn :: \"'e \\<Rightarrow> 'ei::llvm_rep \\<Rightarrow> assn\"\n      and prio_impl le_prio_impl lt_prio_impl\n      and ltype :: \"'l::len2 itself\"\n    assumes prio_is_pure[safe_constraint_rules]: \"is_pure prio_assn\"\n    assumes elem_is_pure[safe_constraint_rules]: \"is_pure elem_assn\"  \n    assumes prio_impl_refine[sepref_fr_rules]: \"(prio_impl, RETURN o prio)\\<in>elem_assn\\<^sup>k \\<rightarrow>\\<^sub>a prio_assn\"\n    assumes le_prio_impl_refine[sepref_fr_rules]: \n      \"(uncurry le_prio_impl, uncurry (RETURN oo (\\<le>))) \\<in> prio_assn\\<^sup>k *\\<^sub>a prio_assn\\<^sup>k \\<rightarrow>\\<^sub>a bool1_assn\"\n    assumes lt_prio_impl_refine[sepref_fr_rules]: \n      \"(uncurry lt_prio_impl, uncurry (RETURN oo (<))) \\<in> prio_assn\\<^sup>k *\\<^sub>a prio_assn\\<^sup>k \\<rightarrow>\\<^sub>a bool1_assn\"\n      \n    fixes N :: nat      \n    (*  \n    fixes N :: nat (*defines \"N\\<equiv>LENGTH('l)\"*)\n    assumes N_bound: \"N<max_snat LENGTH('l)\"\n    assumes L_bound: \"4<LENGTH('l)\"\n    *)\n    (*assumes N_def: \"N = LENGTH ('l)\"*)\n    (*assumes l_len[simp,arith]: \"4 < LENGTH('l)\"*)\n  begin\n    \n    abbreviation \"idx_assn \\<equiv> snatb_assn' TYPE('l) N\"\n    abbreviation \"idx1_assn \\<equiv> snatb_assn' TYPE('l) (Suc N)\"\n\n    sepref_register prio\n\n    sepref_register \"(\\<le>) :: 'p \\<Rightarrow> 'p \\<Rightarrow> bool\"\n    sepref_register \"(<) :: 'p \\<Rightarrow> 'p \\<Rightarrow> bool\"\n    \n    lemma l_len_bound[simp,arith]: \"4<LENGTH('l) \\<Longrightarrow> 16 \\<le> max_snat LENGTH('l)\"\n      unfolding max_snat_def\n    proof -\n      assume \"4<LENGTH('l)\"\n      hence \"4\\<le>LENGTH('l)-1\" by simp\n      hence \"(2::nat)^4 \\<le> 2^(LENGTH('l)-1)\" \n        by (rule power_increasing) auto\n      thus \"(16::nat) \\<le> 2^(LENGTH('l)-1)\" by auto\n    qed\n    \n    lemmas [sepref_frame_free_rules] = \n      mk_free_is_pure[OF prio_is_pure]\n      mk_free_is_pure[OF elem_is_pure]\n    \n    definition \"hm2_assn \\<equiv> b_assn (ial_assn' TYPE('l) N \\<times>\\<^sub>a iam_assn N elem_assn) (\\<lambda>_. 4<LENGTH('l) \\<and> N<max_snat LENGTH('l))\"\n      \n    lemma hm2_assn_rdomp_boundsI: \"rdomp hm2_assn (ag, bq) \\<Longrightarrow> 4<LENGTH('l) \\<and> N<max_snat LENGTH('l)\"\n      unfolding hm2_assn_def by auto\n    \n    \n    find_theorems iam_assn\n    \n    sepref_definition hm_append_impl is \"uncurry2 hm_append_op\"\n      :: \"hm2_assn\\<^sup>d*\\<^sub>aidx_assn\\<^sup>k*\\<^sub>aelem_assn\\<^sup>k \\<rightarrow>\\<^sub>a hm2_assn\"\n      apply (rule hfref_with_rdomI)\n      unfolding hm_append_op_def hm2_assn_def\n      by sepref\n      \n    lemmas [sepref_fr_rules] = hm_append_impl.refine\n      \n    sepref_definition hm_length_impl is \"RETURN o hm_length\" :: \"hm2_assn\\<^sup>k \\<rightarrow>\\<^sub>a snatb_assn' TYPE('l) (N+1)\"\n      apply (rule hfref_with_rdomI)\n      unfolding hm_length_def hm2_assn_def\n      by sepref\n      \n    lemmas [sepref_fr_rules] = hm_length_impl.refine\n      \n    term hm2_assn  \n    sepref_register hm_key_of_op  \n    sepref_definition hm_key_of_impl is \"uncurry hm_key_of_op\" :: \"hm2_assn\\<^sup>k *\\<^sub>a idx1_assn\\<^sup>d \\<rightarrow>\\<^sub>a idx_assn\"\n      apply (rule hfref_with_rdomI)\n      unfolding hm_key_of_op_def hm2_assn_def\n      apply (annot_snat_const \"TYPE('l)\")\n      by sepref\n    lemmas [sepref_fr_rules] = hm_key_of_impl.refine\n      \n    (* Optimization *)\n    definition \"hm_the_lookup_op' k hm \\<equiv> do {\n      let (pq,ml) = hm;\n      (*ASSERT (heapmap_\\<alpha> (hm_impl1_\\<alpha> hm) k \\<noteq> None \\<and> hm_impl1_invar hm);*)\n      v \\<leftarrow> mop_map_the_lookup k ml;\n      RETURN v\n    }\"\n    lemma hm_the_lookup_op'_refine: \n      \"(hm_the_lookup_op', hm_the_lookup_op) \\<in> nat_rel \\<rightarrow> Id \\<rightarrow> \\<langle>Id\\<rangle>nres_rel\"\n      apply (intro fun_relI nres_relI)\n      unfolding hm_the_lookup_op'_def hm_the_lookup_op_def\n      apply refine_vcg\n      apply (auto)\n      apply (auto simp: heapmap_\\<alpha>_def hmr_invar_def restrict_map_def split: if_split_asm)\n      done\n\n    sepref_definition hm_the_lookup_impl is \"uncurry hm_the_lookup_op'\" :: \"idx_assn\\<^sup>k*\\<^sub>ahm2_assn\\<^sup>k \\<rightarrow>\\<^sub>a elem_assn\"\n      apply (rule hfref_with_rdomI)\n      unfolding hm_the_lookup_op'_def hm2_assn_def Let_def\n      by sepref\n    lemmas hm_the_lookup_impl_refine[sepref_fr_rules] \n      = hm_the_lookup_impl.refine[FCOMP hm_the_lookup_op'_refine]\n\n    sepref_definition hm_val_of_impl is \"uncurry hm_val_of_op\" :: \"hm2_assn\\<^sup>k*\\<^sub>aidx1_assn\\<^sup>k \\<rightarrow>\\<^sub>a elem_assn\"  \n      unfolding hm_val_of_op_def\n      by sepref\n    lemmas [sepref_fr_rules] = hm_val_of_impl.refine\n      \n    sepref_register hm_prio_of_op\n    sepref_definition hm_prio_of_impl is \"uncurry (PR_CONST hm_prio_of_op)\" :: \"hm2_assn\\<^sup>k*\\<^sub>aidx1_assn\\<^sup>k \\<rightarrow>\\<^sub>a prio_assn\"  \n      unfolding hm_prio_of_op_def PR_CONST_def\n      by sepref\n    lemmas [sepref_fr_rules] = hm_prio_of_impl.refine\n      \n    definition \"parent_valid h i \\<equiv> hm_valid h (h.parent i)\"\n    definition \"parent_valid' h i \\<equiv> i>(1::nat)\"\n    \n    lemma valid_parent_pat[def_pat_rules]: \"hm_valid$h$(h.parent$i) \\<equiv> parent_valid$h$i\"\n      unfolding parent_valid_def autoref_tag_defs by simp\n    \n    lemma parent_valid'_refine: \"(uncurry parent_valid',uncurry parent_valid) \\<in> [\\<lambda>(h,i). hm_valid h i]\\<^sub>f Id\\<times>\\<^sub>rId\\<rightarrow>Id\"\n      apply rule\n      unfolding hm_valid_def parent_valid_def parent_valid'_def hm_length_def h.parent_def \n      by auto\n    \n    sepref_definition parent_valid_impl is \"uncurry (RETURN oo parent_valid')\" :: \"hm2_assn\\<^sup>k*\\<^sub>aidx1_assn\\<^sup>d \\<rightarrow>\\<^sub>a bool1_assn\" \n      unfolding parent_valid'_def\n      apply (annot_snat_const \"TYPE('l)\")\n      by sepref\n    lemmas [sepref_fr_rules] = parent_valid_impl.refine[FCOMP parent_valid'_refine]\n    \n    sepref_definition hm_exch_impl is \"uncurry2 hm_exch_op\" :: \"hm2_assn\\<^sup>d*\\<^sub>aidx1_assn\\<^sup>d*\\<^sub>aidx1_assn\\<^sup>d \\<rightarrow>\\<^sub>a hm2_assn\"\n      apply (rule hfref_with_rdomI)\n      unfolding hm_exch_op_def hm2_assn_def\n      apply (annot_snat_const \"TYPE('l)\")\n      supply [simp] = hm_valid_def\n      by sepref\n    lemmas [sepref_fr_rules] = hm_exch_impl.refine\n    \n    (* TODO: Move *)\n    lemma hfref_bassn_resI:\n      assumes \"\\<And>xs. \\<lbrakk>rdomp (fst As) xs; C xs\\<rbrakk> \\<Longrightarrow> a xs \\<le>\\<^sub>n SPEC P\"\n      assumes \"(c,a)\\<in>[C]\\<^sub>a As \\<rightarrow> R\"\n      shows \"(c,a)\\<in>[C]\\<^sub>a As \\<rightarrow> b_assn R P\"\n      apply rule\n      apply (rule hn_refine_preI)\n      apply (rule hn_refine_cons[rotated])\n      apply (rule hn_refine_augment_res)\n      apply (rule assms(2)[to_hnr, unfolded hn_ctxt_def autoref_tag_defs])\n      apply simp\n      apply (rule assms(1))\n      apply (auto simp: rdomp_def sep_algebra_simps)\n      done\n    \n    sepref_definition parent_impl is \"RETURN o h.parent\" :: \"[\\<lambda>_. 4<LENGTH('l)]\\<^sub>aidx1_assn\\<^sup>d \\<rightarrow> idx1_assn\"\n      unfolding h.parent_def\n      apply (rule hfref_bassn_resI)\n      subgoal by auto\n      apply (annot_snat_const \"TYPE('l)\")\n      by sepref\n      \n    lemmas [sepref_fr_rules] = parent_impl.refine    \n    \n    find_theorems hm_swim_op\n    sepref_register h.parent hm_exch_op\n    \n    (* TODO: Very specialized workaround lemma, to work around invalid-recombination\n      problem for case that B is pure. DUP in IICF_Heap_Impl.thy\n    *)    \n    lemma workaround_invalid_recombine_pure3: \"is_pure B \\<Longrightarrow> hn_ctxt (invalid_assn A \\<times>\\<^sub>a invalid_assn B) ax px \\<turnstile> hn_invalid (A \\<times>\\<^sub>a B) ax px\"\n      unfolding hn_ctxt_def invalid_assn_def prod_assn_def entails_def\n      by (auto split: prod.split elim!: is_pureE \n        simp: sep_algebra_simps pure_part_pure_conj_eq)\n      argo\n    \n    find_theorems is_pure b_assn  \n    \n    sepref_register hm_swim_op\n    sepref_definition hm_swim_impl is \"uncurry (PR_CONST hm_swim_op)\" :: \"hm2_assn\\<^sup>d*\\<^sub>aidx1_assn\\<^sup>k \\<rightarrow>\\<^sub>a hm2_assn\"\n      unfolding hm_swim_op_def PR_CONST_def\n      (* TODO: Workaround/Hack *)\n      supply X[sepref_frame_match_rules] = workaround_invalid_recombine_pure3[where B=\"snatb_assn _\", simplified]\n      supply [simp] = hm2_assn_rdomp_boundsI\n      by sepref\n    lemmas [sepref_fr_rules] = hm_swim_impl.refine\n    \n    sepref_register hm_insert_op\n    sepref_definition hm_insert_impl is \"uncurry2 (PR_CONST hm_insert_op)\" \n      :: \"idx_assn\\<^sup>k*\\<^sub>aelem_assn\\<^sup>k*\\<^sub>ahm2_assn\\<^sup>d \\<rightarrow>\\<^sub>a hm2_assn\"\n      unfolding hm_insert_op_def PR_CONST_def\n      by sepref\n    lemmas [sepref_fr_rules] = hm_insert_impl.refine\n    \n    lemma rewr_2kleN: \"2*k \\<le> n \\<longleftrightarrow> k \\<le> n div 2\" for k :: nat by auto\n      \n    sepref_definition hm_has_child_impl is \"uncurry (RETURN oo hm_has_child_op)\" :: \"hm2_assn\\<^sup>k*\\<^sub>aidx1_assn\\<^sup>d \\<rightarrow>\\<^sub>a bool1_assn\"\n      unfolding hm_has_child_op_def\n      apply (rewrite rewr_2kleN)\n      supply [simp,dest] = hm2_assn_rdomp_boundsI\n      apply (annot_snat_const \"TYPE('l)\")\n      by sepref\n      \n    lemmas [sepref_fr_rules] = hm_has_child_impl.refine    \n\n    sepref_definition hm_left_child_impl is \"RETURN o hm_left_child_op\" :: \"[\\<lambda>i. 2*i\\<le>N \\<and> N<max_snat LENGTH('l) \\<and> 4<LENGTH('l)]\\<^sub>a idx1_assn\\<^sup>d \\<rightarrow> idx1_assn\"\n      unfolding hm_left_child_op_def\n      apply (rule hfref_bassn_resI)\n      subgoal by auto\n      apply (annot_snat_const \"TYPE('l)\")\n      by sepref\n    lemmas [sepref_fr_rules] = hm_left_child_impl.refine  \n\n    lemma rewr_kp1len: \"k+1 \\<le> n \\<longleftrightarrow> k<(n::nat)\" by auto\n    \n    sepref_definition hm_has_next_child_impl is \"uncurry (RETURN oo hm_has_next_child_op)\" :: \"hm2_assn\\<^sup>k*\\<^sub>aidx1_assn\\<^sup>d \\<rightarrow>\\<^sub>a bool1_assn\"\n      unfolding hm_has_next_child_op_def\n      apply (rewrite rewr_kp1len)\n      by sepref\n    lemmas [sepref_fr_rules] = hm_has_next_child_impl.refine    \n\n    sepref_definition hm_next_child_impl is \"RETURN o hm_next_child_op\" :: \"[\\<lambda>i. i<N \\<and> N<max_snat LENGTH('l) \\<and> 4<LENGTH('l)]\\<^sub>a idx1_assn\\<^sup>d \\<rightarrow> idx1_assn\"\n      unfolding hm_next_child_op_def\n      apply (rule hfref_bassn_resI)\n      subgoal by auto\n      apply (annot_snat_const \"TYPE('l)\")\n      by sepref\n    lemmas [sepref_fr_rules] = hm_next_child_impl.refine  \n    \n    lemma sink_sepref_aux1: \"\\<lbrakk> a2' \\<le> l div 2; (ae, l) \\<in> snat_rel' TYPE('l)\\<rbrakk>\n       \\<Longrightarrow> 2 * a2' < max_snat LENGTH('l)\"\n       by (simp add: le_less_trans rewr_2kleN snat_rel_imp_less_max_snat)\n       \n    (* TODO: Move *)    \n    lemma rdomp_ial_len: \"rdomp (ial_assn N) xs \\<Longrightarrow> length xs \\<le> N\"   \n      unfolding ial_assn_def\n      apply (auto simp: rdomp_hrcomp_conv ial_rel1_def in_br_conv)\n      by (metis (full_types) ial_invar.l_len ial_invar_def list_rel_imp_same_length)\n       \n    lemma sink_sepref_aux2: \"\\<lbrakk>hm_has_child_op (ag, bq) a2'; rdomp hm2_assn (ag, bq)\\<rbrakk>\n       \\<Longrightarrow> 2 * a2' \\<le> N\"   \n      unfolding hm_has_child_op_def hm2_assn_def hm_length_def \n      by (auto dest: rdomp_ial_len)\n       \n    lemma sink_sepref_aux3: \"\\<lbrakk>hm_has_next_child_op (ag, bq) i; rdomp hm2_assn (ag, bq)\\<rbrakk> \\<Longrightarrow> i<N\"  \n      unfolding hm_has_next_child_op_def hm2_assn_def hm_length_def \n      by (auto dest: rdomp_ial_len)\n      \n       \n    sepref_register hm_sink_op\n    sepref_definition hm_sink_impl is \"uncurry (PR_CONST hm_sink_op)\" :: \"hm2_assn\\<^sup>d*\\<^sub>aidx1_assn\\<^sup>k \\<rightarrow>\\<^sub>a hm2_assn\"\n      unfolding hm_sink_op_def PR_CONST_def\n      supply [simp] = hm_length_def\n      supply [simp] = snat_rel_imp_less_max_snat \n        sink_sepref_aux1 sink_sepref_aux2 sink_sepref_aux3\n      supply X[sepref_frame_match_rules] = workaround_invalid_recombine_pure3[where B=\"snatb_assn _\", simplified]\n      supply [simp,dest] = hm2_assn_rdomp_boundsI\n      by sepref\n    lemmas [sepref_fr_rules] = hm_sink_impl.refine\n      \n    sepref_register hm_repair_op  \n    sepref_definition hm_repair_impl is \"uncurry (PR_CONST hm_repair_op)\" :: \"hm2_assn\\<^sup>d*\\<^sub>aidx1_assn\\<^sup>k \\<rightarrow>\\<^sub>a hm2_assn\"\n      unfolding hm_repair_op_def PR_CONST_def\n      by sepref\n    lemmas [sepref_fr_rules] = hm_repair_impl.refine\n      \n    sepref_definition hm_is_empty_impl is \"hm_is_empty_op\" :: \"hm2_assn\\<^sup>k \\<rightarrow>\\<^sub>a bool1_assn\"\n      unfolding hm_is_empty_op_def\n      apply (annot_snat_const \"TYPE('l)\")\n      by sepref\n    \n    (* Cannot do lookup, unless we have option type! \n      \\<rightarrow> Do contains_key and the_lookup instead!\n    sepref_definition hm_lookup_impl is \"uncurry hm_lookup\" :: \"hm2_assn\\<^sup>k*\\<^sub>aidx_assn\\<^sup>k \\<rightarrow>\\<^sub>a elem_assn\"\n    *)  \n      \n    sepref_register hm_contains_key_op\n    sepref_definition hm_contains_key_impl is \"uncurry (PR_CONST hm_contains_key_op)\" :: \"idx_assn\\<^sup>k *\\<^sub>a hm2_assn\\<^sup>k \\<rightarrow>\\<^sub>a bool1_assn\"\n      apply (rule hfref_with_rdomI)\n      unfolding hm_contains_key_op_def hm2_assn_def PR_CONST_def\n      by sepref\n    lemmas [sepref_fr_rules] = hm_contains_key_impl.refine  \n      \n    lemma hm_index_impl_aux1: \"\\<lbrakk>b \\<in> set a1'; rdomp (ial_assn N) a1'; N<max_snat LENGTH('l)\\<rbrakk>\n       \\<Longrightarrow> Suc (index a1' b) < max_snat LENGTH('l)\"  \n      by (meson index_less less_trans_Suc rdomp_ial_len)\n      \n    sepref_definition hm_index_impl is \"uncurry hm_index_op\" :: \"hm2_assn\\<^sup>k*\\<^sub>aidx_assn\\<^sup>d\\<rightarrow>\\<^sub>aidx1_assn\"  \n      unfolding hm_index_op_def hm2_assn_def\n      apply (rule hfref_bassn_resI)\n      subgoal \n        apply (clarsimp simp: uncurry_def) \n        apply refine_vcg \n        by (auto simp: heapmap_\\<alpha>_def restrict_map_eq rdomp_ial_len)\n      supply [simp] = heapmap_\\<alpha>_def restrict_map_eq hm_index_impl_aux1\n      apply (rule hfref_with_rdomI)\n      apply (annot_snat_const \"TYPE('l)\")\n      by sepref\n    lemmas [sepref_fr_rules] = hm_index_impl.refine  \n      \n    term hm_update_op\n    sepref_definition hm_update_impl is \"uncurry2 hm_update_op\" :: \"hm2_assn\\<^sup>d*\\<^sub>aidx1_assn\\<^sup>d*\\<^sub>aelem_assn\\<^sup>k \\<rightarrow>\\<^sub>a hm2_assn\"\n      unfolding hm_update_op_def hm2_assn_def\n      apply (rule hfref_with_rdomI)\n      supply [simp] = hm_valid_def\n      apply (annot_snat_const \"TYPE('l)\")\n      by sepref\n    lemmas [sepref_fr_rules] = hm_update_impl.refine\n    \n    sepref_register hm_decrease_key_op\n    sepref_definition hm_decrease_key_impl is \"uncurry2 (PR_CONST hm_decrease_key_op)\" :: \"idx_assn\\<^sup>k *\\<^sub>a elem_assn\\<^sup>k *\\<^sub>a hm2_assn\\<^sup>d \\<rightarrow>\\<^sub>a hm2_assn \"\n      unfolding hm_decrease_key_op_def PR_CONST_def\n      by sepref\n    lemmas [sepref_fr_rules] = hm_decrease_key_impl.refine\n          \n    sepref_register hm_increase_key_op\n    sepref_definition hm_increase_key_impl is \"uncurry2 (PR_CONST hm_increase_key_op)\" :: \"idx_assn\\<^sup>k *\\<^sub>a elem_assn\\<^sup>k *\\<^sub>a hm2_assn\\<^sup>d \\<rightarrow>\\<^sub>a hm2_assn \"\n      unfolding hm_increase_key_op_def PR_CONST_def\n      by sepref\n    lemmas [sepref_fr_rules] = hm_increase_key_impl.refine\n\n    sepref_register hm_change_key_op\n    sepref_definition hm_change_key_impl is \"uncurry2 (PR_CONST hm_change_key_op)\" :: \"idx_assn\\<^sup>k *\\<^sub>a elem_assn\\<^sup>k *\\<^sub>a hm2_assn\\<^sup>d \\<rightarrow>\\<^sub>a hm2_assn \"\n      unfolding hm_change_key_op_def PR_CONST_def\n      by sepref\n    lemmas [sepref_fr_rules] = hm_change_key_impl.refine\n        \n    sepref_register hm_set_op\n    sepref_definition hm_set_impl is \"uncurry2 (PR_CONST hm_set_op)\" :: \"idx_assn\\<^sup>k*\\<^sub>aelem_assn\\<^sup>k*\\<^sub>ahm2_assn\\<^sup>d \\<rightarrow>\\<^sub>a hm2_assn\"\n      unfolding hm_set_op_def PR_CONST_def\n      by sepref\n    lemmas [sepref_fr_rules] = hm_set_impl.refine\n          \n    lemma hm_pop_min_impl_aux1: \n      \"\\<lbrakk>hm_valid (pq, m) (Suc 0); rdomp hm2_assn (pq, m)\\<rbrakk> \\<Longrightarrow> 0<N\"\n      by (cases pq; auto simp: hm2_assn_def hm_valid_def hm_length_def dest!: rdomp_ial_len)  \n    \n      \n    sepref_register hm_butlast_op  \n    sepref_definition hm_butlast_impl is \"hm_butlast_op\" :: \"hm2_assn\\<^sup>d \\<rightarrow>\\<^sub>a hm2_assn\"\n      unfolding hm_butlast_op_def hm2_assn_def\n      apply (rule hfref_with_rdomI)\n      apply (annot_snat_const \"TYPE('l)\")\n      by sepref\n    lemmas [sepref_fr_rules] = hm_butlast_impl.refine      \n      \n    sepref_register hm_pop_min_op\n    sepref_definition hm_pop_min_impl is \"PR_CONST hm_pop_min_op\" :: \"hm2_assn\\<^sup>d \\<rightarrow>\\<^sub>a (idx_assn \\<times>\\<^sub>a elem_assn) \\<times>\\<^sub>a hm2_assn\"\n      unfolding hm_pop_min_op_def PR_CONST_def\n      supply [simp] = hm_pop_min_impl_aux1\n      apply (annot_snat_const \"TYPE('l)\")\n      by sepref\n    lemmas [sepref_fr_rules] = hm_pop_min_impl.refine      \n    \n    sepref_register hm_remove_op \n    sepref_definition hm_remove_impl is \"uncurry (PR_CONST hm_remove_op)\" :: \"idx_assn\\<^sup>k *\\<^sub>a hm2_assn\\<^sup>d \\<rightarrow>\\<^sub>a hm2_assn\"\n      unfolding hm_remove_op_def PR_CONST_def\n      (* TODO Hack/Workaround: Prevents b_assn to be degraded when comparing.\n        Deeper problem to fix: Do not degrade b_assn, even if operation is on basic assn!\n      *)\n      apply (rewrite at \"if \\<hole>\\<noteq>_ then _ else _\" fold_COPY)\n      by sepref\n    lemmas [sepref_fr_rules] = hm_remove_impl.refine\n    \n    sepref_register hm_peek_min_op\n    sepref_definition hm_peek_min_impl is \"hm_peek_min_op\" :: \"hm2_assn\\<^sup>k \\<rightarrow>\\<^sub>a idx_assn\\<times>\\<^sub>aelem_assn\"\n      unfolding hm_peek_min_op_def hm_kv_of_op_def\n      supply [simp] = hm_pop_min_impl_aux1\n      apply (annot_snat_const \"TYPE('l)\")\n      by sepref\n    lemmas [sepref_fr_rules] = hm_peek_min_impl.refine\n\n    \n    (* sepref_decl_op hm_empty: \"op_map_empty\" :: \"\\<langle>Id,Id\\<rangle>map_rel\" .*)\n    \n    definition [simp]: \"mop_hm_empty (NN::nat) \\<equiv> mop_map_empty\"\n    sepref_register \"mop_hm_empty N\" :: \"('a,'b) i_map nres\"\n\n    lemma fold_custom_hm_empty:\n      \"RETURN Map.empty = mop_hm_empty N\"\n      \"mop_map_empty = mop_hm_empty N\"\n      by auto\n        \n    context\n      fixes Ni\n      assumes NiREF: \"(Ni,N)\\<in>snat_rel' TYPE('l)\"\n      assumes BOUND: \"4<LENGTH('l)\"\n      notes [[sepref_register_adhoc N]]\n      notes [sepref_import_param] = NiREF\n    begin\n      lemma hm_empty_impl_aux: \"N < max_snat LENGTH('l)\"\n        using NiREF\n        using snat_rel_imp_less_max_snat by blast\n \n    \n      sepref_definition hm_empty_impl is \"uncurry0 hm_empty_op\" :: \"unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a hm2_assn\"\n        unfolding hm_empty_op_def hm_empty_op_def hm2_assn_def\n        apply (rule hfref_with_rdomI)\n        apply (rewrite iam_fold_custom_empty[where N=N])\n        apply (rewrite ial_fold_custom_empty[where N=N])\n        supply [sepref_fr_rules] = iam_empty_hnr_mop[where N=N]\n        supply [sepref_fr_rules] = ial_empty_hnr[where N=N]\n        supply [simp] = hm_empty_impl_aux BOUND\n        by sepref\n    end    \n    \n    lemma hm_empty_op_aref': \"(hm_empty_op, PR_CONST (mop_hm_empty N))\\<in>\\<langle>heapmap_rel\\<rangle>nres_rel\"\n      using hm_empty_op_aref by auto\n      \n    lemma mop_hm_empty_fref: \n      \"(uncurry0 (PR_CONST (mop_hm_empty N)), uncurry0 (PR_CONST (mop_hm_empty N)))\\<in>unit_rel \\<rightarrow>\\<^sub>f \\<langle>\\<langle>Id,Id\\<rangle>map_rel\\<rangle>nres_rel\" \n      by (auto intro!: frefI nres_relI)\n      \n    \n    (*      \n    sepref_decl_op hm_empty: \"\\<lambda>_::nat. op_map_empty\" :: \"nat_rel \\<rightarrow> \\<langle>Id,Id\\<rangle>map_rel\" .\n    definition \"hm_empty' (NN::nat) \\<equiv> hm_empty_op\"\n    sepref_register hm_empty'\n\n    lemma fold_custom_hm_empty:\n      \"RETURN Map.empty = mop_hm_empty N\"\n      \"mop_map_empty = mop_hm_empty N\"\n      by auto\n    \n    lemma hm_empty'_aref: \"(hm_empty',mop_hm_empty)\\<in>nat_rel \\<rightarrow> \\<langle>heapmap_rel\\<rangle>nres_rel\"\n      unfolding hm_empty'_def mop_hm_empty_def\n      using hm_empty_op_aref by auto\n    \n      sepref_definition hm_empty_impl is \"hm_empty'\" :: \"[\\<lambda>NN. NN=N]\\<^sub>a idx_assn\\<^sup>k \\<rightarrow> hm2_assn\"\n        unfolding hm_empty'_def hm_empty_op_def hm2_assn_def\n        apply (rule hfref_with_rdomI)\n        apply (rewrite iam_fold_custom_empty[where N=N])\n        apply (rewrite ial_fold_custom_empty[where N=N])\n        supply [sepref_fr_rules] = iam_empty_hnr_mop[where N=N]\n        supply [sepref_fr_rules] = ial_empty_hnr[where N=N]\n        supply [[sepref_register_adhoc N]]\n        by sepref\n        \n    end    \n    *)\n    \n    \n    definition \"hm12_assn \\<equiv> hr_comp hm2_assn heapmap_rel\"\n    \n    context \n      notes [fcomp_norm_unfold] = hm12_assn_def[symmetric]\n    begin\n    \n      lemmas hm_empty_ref12 = hm_empty_impl.refine[FCOMP hm_empty_op_aref']\n      lemmas hm_insert_ref12 = hm_insert_impl.refine[unfolded PR_CONST_def, FCOMP hm_insert_op_aref]\n      lemmas hm_is_empty_ref12 = hm_is_empty_impl.refine[FCOMP hm_is_empty_op_aref]\n      lemmas hm_the_lookup_ref12 = hm_the_lookup_impl_refine[FCOMP hm_the_lookup_op_aref]\n      lemmas hm_contains_key_ref12 = hm_contains_key_impl.refine[unfolded PR_CONST_def, FCOMP hm_contains_key_op_aref]\n      lemmas hm_decrease_key_ref12 = hm_decrease_key_impl.refine[unfolded PR_CONST_def, FCOMP hm_decrease_key_op_aref]\n      lemmas hm_increase_key_ref12 = hm_increase_key_impl.refine[unfolded PR_CONST_def, FCOMP hm_increase_key_op_aref]\n      lemmas hm_change_key_ref12 = hm_change_key_impl.refine[unfolded PR_CONST_def, FCOMP hm_change_key_op_aref]\n      lemmas hm_set_ref12 = hm_set_impl.refine[unfolded PR_CONST_def, FCOMP hm_set_op_aref]\n      lemmas hm_pop_min_ref12 = hm_pop_min_impl.refine[unfolded PR_CONST_def, FCOMP hm_pop_min_op_aref]\n      lemmas hm_remove_ref12 = hm_remove_impl.refine[unfolded PR_CONST_def, FCOMP hm_remove_op_aref]\n      lemmas hm_peek_min_ref12 = hm_peek_min_impl.refine[FCOMP hm_peek_min_op_aref]\n            \n    end\n\n    definition \"hm_assn \\<equiv> hr_comp hm12_assn (\\<langle>nat_rel, Id\\<rangle>map_rel)\"\n    context\n      notes [fcomp_norm_unfold] = hm_assn_def[symmetric]\n    begin\n      lemmas hm_empty_hnr = hm_empty_ref12[FCOMP mop_hm_empty_fref]\n      \n      sepref_decl_impl (ismop) hm_insert_ref12 uses mop_map_update_new.fref[where K=Id and V=Id] .\n      sepref_decl_impl (ismop) hm_is_empty_ref12 uses mop_map_is_empty.fref[where K=Id and V=Id] .\n      sepref_decl_impl (ismop) hm_the_lookup_ref12 uses mop_map_the_lookup.fref[where K=Id and V=Id] .\n      sepref_decl_impl (ismop) hm_contains_key_ref12 uses mop_map_contains_key.fref[where K=Id and V=Id] .\n      sepref_decl_impl (ismop) hm_decrease_key_ref12 uses mop_pm_decrease_key.fref[where K=Id and V=Id] .\n      sepref_decl_impl (ismop) hm_increase_key_ref12 uses mop_pm_increase_key.fref[where K=Id and V=Id] .\n      sepref_decl_impl (ismop) hm_change_key_ref12 uses mop_map_update_ex.fref[where K=Id and V=Id] .\n      sepref_decl_impl (ismop) hm_set_ref12 uses mop_map_update.fref[where K=Id and V=Id] .\n      sepref_decl_impl (ismop) hm_pop_min_ref12 uses mop_pm_pop_min.fref[where K=Id and V=Id] .\n      sepref_decl_impl (ismop) hm_remove_ref12 uses mop_map_delete_ex.fref[where K=Id and V=Id] .\n      sepref_decl_impl (ismop) hm_peek_min_ref12 uses mop_pm_peek_min.fref[where K=Id and V=Id] .\n    end    \n        \n  end      \n\n    \n  global_interpretation \n    HM: hm_impl id \"snat_assn' TYPE('l)\" \"snat_assn' TYPE('l)\" return ll_icmp_sle ll_icmp_slt \"TYPE('l::len2)\" N for N\n    defines \n           hm_empty_impl = HM.hm_empty_impl\n       and hm_append_impl = HM.hm_append_impl\n       and hm_insert_impl = HM.hm_insert_impl\n       and hm_length_impl = HM.hm_length_impl\n       and hm_swim_impl = HM.hm_swim_impl\n       and hm_sink_impl = HM.hm_sink_impl\n       and hm_is_empty_impl = HM.hm_is_empty_impl\n       and hm_the_lookup_impl = HM.hm_the_lookup_impl\n       and hm_contains_key_impl = HM.hm_contains_key_impl\n       and hm_decrease_key_impl = HM.hm_decrease_key_impl\n       and hm_increase_key_impl = HM.hm_increase_key_impl\n       and hm_change_key_impl = HM.hm_change_key_impl\n       and hm_parent_impl = HM.parent_impl\n       and hm_parent_valid_impl = HM.parent_valid_impl\n       and hm_next_child_impl = HM.hm_next_child_impl\n       and hm_has_next_child_impl = HM.hm_has_next_child_impl\n       and hm_left_child_impl = HM.hm_left_child_impl\n       and hm_has_child_impl = HM.hm_has_child_impl\n       and hm_repair_impl = HM.hm_repair_impl\n       and hm_set_impl = HM.hm_set_impl\n       and hm_pop_min_impl = HM.hm_pop_min_impl\n       and hm_remove_impl = HM.hm_remove_impl\n       and hm_peek_min_impl = HM.hm_peek_min_impl\n       \n       and hm_exch_impl = HM.hm_exch_impl\n       and hm_update_impl = HM.hm_update_impl\n       and hm_index_impl = HM.hm_index_impl\n       and hm_prio_of_impl = HM.hm_prio_of_impl\n       and hm_val_of_impl = HM.hm_val_of_impl\n       and hm_key_of_impl = HM.hm_key_of_impl\n       and hm_butlast_impl = HM.hm_butlast_impl\n    \n    \n    apply unfold_locales\n    apply (rule pure_pure)\n    apply sepref\n    apply sepref\n    apply sepref\n    done\n\n  type_synonym 'l heapmap = \"'l ial \\<times> 'l word iam\"  \n\n  schematic_goal [sepref_frame_free_rules]: \"MK_FREE (HM.hm_assn N) (?fr)\"\n    unfolding HM.hm_assn_def HM.hm12_assn_def HM.hm2_assn_def\n    by sepref_dbg_side_keep\n    \n  \n      \n  concrete_definition hm_empty_impl' is HM.hm_empty_impl_def\n  \n  lemma hm_empty_hnr: \"\\<lbrakk>(Ni, N) \\<in> snat_rel' TYPE('l); 4 < LENGTH('l::len2)\\<rbrakk>\n    \\<Longrightarrow> (uncurry0 (hm_empty_impl' Ni), uncurry0 (PR_CONST (HM.mop_hm_empty N)))\n    \\<in> unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a HM.hm_assn N\"\n    using hm_empty_impl'.refine HM.hm_empty_hnr by metis\n        \n  lemmas [llvm_code,llvm_inline] = \n    HM.hm_append_impl_def\n    HM.hm_is_empty_impl_def\n    HM.hm_length_impl_def\n    HM.hm_the_lookup_impl_def\n    HM.hm_contains_key_impl_def\n    HM.parent_impl_def\n    HM.parent_valid_impl_def\n    HM.hm_prio_of_impl_def\n    HM.hm_val_of_impl_def\n    HM.hm_key_of_impl_def\n    HM.hm_next_child_impl_def\n    HM.hm_has_next_child_impl_def\n    HM.hm_left_child_impl_def\n    HM.hm_has_child_impl_def\n    HM.hm_butlast_impl_def\n\n    \n  lemmas [llvm_code] = \n    HM.hm_insert_impl_def\n    HM.hm_decrease_key_impl_def\n    HM.hm_increase_key_impl_def\n    HM.hm_change_key_impl_def\n    HM.hm_swim_impl_def\n    HM.hm_sink_impl_def\n    HM.hm_exch_impl_def\n    HM.hm_update_impl_def\n    HM.hm_index_impl_def\n    HM.hm_repair_impl_def\n    HM.hm_set_impl_def\n    HM.hm_pop_min_impl_def\n    HM.hm_remove_impl_def\n    HM.hm_peek_min_impl_def\n    hm_empty_impl'_def\n    \n\n  term HM.hm_prio_of_impl  \n  thm HM.hm_prio_of_impl_def\n    \n    \n  export_llvm\n    \"hm_empty_impl' :: _ \\<Rightarrow> 32 heapmap llM\"\n    \"hm_append_impl:: _ \\<Rightarrow> 32 word \\<Rightarrow> _\"\n    \"hm_is_empty_impl :: 32 heapmap \\<Rightarrow> _\"\n    \"hm_the_lookup_impl :: _ \\<Rightarrow> 32 heapmap \\<Rightarrow> _\"\n    \"hm_contains_key_impl :: _ \\<Rightarrow> 32 heapmap \\<Rightarrow> _\"\n    \"hm_decrease_key_impl :: _ \\<Rightarrow> _ \\<Rightarrow> 32 heapmap \\<Rightarrow> _\"\n    \"hm_increase_key_impl :: _ \\<Rightarrow> _ \\<Rightarrow> 32 heapmap \\<Rightarrow> _\"\n    \"hm_change_key_impl :: _ \\<Rightarrow> _ \\<Rightarrow> 32 heapmap \\<Rightarrow> _\"\n    \"hm_set_impl :: _ \\<Rightarrow> _ \\<Rightarrow> 32 heapmap \\<Rightarrow> _\"\n    \"hm_pop_min_impl :: 32 heapmap \\<Rightarrow> _\"\n    \"hm_remove_impl :: _ \\<Rightarrow> 32 heapmap \\<Rightarrow> _\"\n    \"hm_peek_min_impl :: 32 heapmap \\<Rightarrow> _\"\n    file \"heapmap.ll\"\n    \n    \n\n  context \n    fixes N Ni\n    assumes NiREF: \"(Ni,N)\\<in>snat_rel' TYPE(32)\"\n    notes [sepref_import_param] = NiREF\n    notes [[sepref_register_adhoc N]]\n  begin\n  \n    definition \"snatb (x::nat) \\<equiv> x\"\n    lemma snatb_hnr: \"(return,RETURN o snatb) \\<in> [\\<lambda>x. x<N]\\<^sub>a snat_assn\\<^sup>k \\<rightarrow> snatb_assn N\"\n      unfolding snatb_def\n      by sepref_to_hoare vcg\n  \n    definition \"heapmap_test \\<equiv> do {\n      ASSERT (42<N);\n      m \\<leftarrow> HM.mop_hm_empty N;\n      m \\<leftarrow> mop_map_update (snatb 7)  (snatb 3) m;\n      m \\<leftarrow> mop_map_update (snatb 6)  (snatb 2) m;\n      m \\<leftarrow> mop_map_update (snatb 16) (snatb 1) m;\n      (k,v) \\<leftarrow> mop_pm_peek_min id m;\n      RETURN k\n    }\"\n  \n    sepref_definition heapmap_test_impl_aux is \"uncurry0 heapmap_test\" :: \"unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a snat_assn' TYPE(32)\"\n      unfolding heapmap_test_def\n      supply [simp] = max_snat_def\n      supply [sepref_fr_rules] = hm_empty_hnr[OF NiREF] snatb_hnr\n      apply (annot_snat_const \"TYPE(32)\")\n      by sepref\n  \n  end\n\n  concrete_definition heapmap_test_impl is heapmap_test_impl_aux_def\n  declare heapmap_test_impl_def[llvm_code]\n  \n  export_llvm heapmap_test_impl\n  \n  lemma \"(heapmap_test_impl_aux, heapmap_test) \\<in> snat_assn\\<^sup>k \\<rightarrow>\\<^sub>a snat_assn\"\n    apply rule\n    apply (rule hn_refine_preI)\n    using heapmap_test_impl_aux.refine[to_hnr]\n    by (simp add: pure_def pred_lift_extract_simps sep_algebra_simps)\n  \n    \n  xxx, ctd here: Just added support for dependent result relation.\n  \n  Test this first on simple data structure, e.g., MS_Array_List!\n    \n    \n  \nend    \n", "meta": {"author": "lammich", "repo": "isabelle_llvm", "sha": "6be37a9c3cae74a1134dbef2979e312abb5f7f42", "save_path": "github-repos/isabelle/lammich-isabelle_llvm", "path": "github-repos/isabelle/lammich-isabelle_llvm/isabelle_llvm-6be37a9c3cae74a1134dbef2979e312abb5f7f42/thys-2018/sepref/IICF/Impl/Heaps/IICF_Impl_Heapmap.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.2698366209481967}}
{"text": "theory ITree_Iteration\n  imports ITree_Divergence ITree_Deadlock\nbegin\n\nsubsection \\<open> Iteration \\<close>\n\ntext \\<open> For now we support only basic tail-recursive iteration. \\<close>\n\ncorec iterate :: \"('s \\<Rightarrow> bool) \\<Rightarrow> ('e, 's) htree \\<Rightarrow> ('e, 's) htree\" where\n\"iterate b P s = (if (b s) then (P s \\<bind> (\\<tau> \\<circ> (iterate b P))) else Ret s)\"\n\nabbreviation \"loop \\<equiv> iterate (\\<lambda> s. True)\"\n\nabbreviation \"iter P \\<equiv> loop (\\<lambda> _. P) ()\"\n\nlemma iterate_cond_false [simp]:\n  \"\\<not> (b s) \\<Longrightarrow> iterate b P s = Ret s\"\n  by (simp add: iterate.code)\n\nlemma iterate_body_nonterminates:\n  assumes \"nonterminating (P s)\" \"b s\"\n  shows \"nonterminating (iterate b P s)\"\n  by (simp add: assms iterate.code)\n\nlemma loop_unfold: \"loop P = P ;; (\\<tau> \\<circ> loop P)\"\n  by (simp add: seq_itree_def kleisli_comp_def fun_eq_iff iterate.code)\n\nlemma loop_Ret: \"loop Ret = (\\<lambda> s. diverge)\"\n  by (metis Sil_nfp_stabilises bind_Ret comp_apply diverges_then_diverge iterate.code)\n\nlemma iterate_Ret_dest:\n  \"Ret x = iterate b P s \\<Longrightarrow> (\\<not> (b s) \\<and> x = s)\"\n  apply (cases \"P s\")\n  apply (metis bind_Ret comp_apply iterate.code itree.distinct(1) itree.sel(1))\n  apply (metis bind_itree.disc_iff(1) iterate.code itree.disc(2) itree.discI(1) itree.inject(1))\n  apply (metis bind_Vis iterate.code itree.distinct(3) itree.inject(1))\n  done\n\nlemma iterate_RetE:\n  assumes \"iterate b P s = Ret x\" \"\\<lbrakk> \\<not> (b s); x = s \\<rbrakk> \\<Longrightarrow> Q\"\n  shows Q\n  by (metis assms iterate_Ret_dest)\n\nlemma iterate_RetE':\n  assumes \"Ret x = iterate b P s\" \"\\<lbrakk> \\<not> (b s); x = s \\<rbrakk> \\<Longrightarrow> Q\"\n  shows Q\n  by (metis assms iterate_Ret_dest)\n\nlemma iterate_Sil_dest: \n  \"\\<tau> P' = iterate b P s \\<Longrightarrow> (b s \\<and> ((\\<exists> s'. P s = Ret s' \\<and> P' = iterate b P s') \\<or> (\\<exists> P''. P s = \\<tau> P'' \\<and> P' = (P'' \\<bind> \\<tau> \\<circ> iterate b P))))\"\n  apply (cases \"P s\")\n  apply (simp_all)\n  apply (metis bind_Ret comp_apply iterate.code itree.distinct(1) itree.sel(2))\n  apply (metis bind_Sil iterate.code itree.distinct(1) itree.inject(2))\n  apply (metis bind_Vis iterate.code itree.distinct(1) itree.distinct(5))\n  done\n\nlemma iterate_SilE [elim, consumes 1, case_names initial continue]:\n  assumes \"\\<tau> P = iterate b Q s\"\n    \"\\<And> P'. \\<lbrakk> b s; Q s = \\<tau> P'; P = (P' \\<bind> \\<tau> \\<circ> iterate b Q) \\<rbrakk> \\<Longrightarrow> R\"\n    \"\\<And> s'. \\<lbrakk> b s; Q s = Ret s'; P = iterate b Q s' \\<rbrakk> \\<Longrightarrow> R\"\n  shows R\n  by (metis assms iterate_Sil_dest)\n\nlemma iterate_Vis_dest:\n  \"Vis F = iterate b Q s \\<Longrightarrow> b s \\<and> (\\<exists> G. Q s = Vis G \\<and> F = (map_pfun (\\<lambda> x. bind_itree x (\\<tau> \\<circ> iterate b Q)) G))\"\n  apply (cases \"Q s\")\n  apply (simp_all)\n  apply (metis bind_Ret comp_apply iterate.code itree.simps(7) itree.simps(9))\n  apply (metis bind_Sil iterate.code itree.distinct(3) itree.distinct(5))\n  apply (metis bind_Vis iterate.code itree.inject(3) itree.simps(7))\n  done\n\nlemma iterate_VisE:\n  assumes \"Vis F = iterate b Q s\"\n    \"\\<And> G. \\<lbrakk> b s; Q s = Vis G; F = (map_pfun (\\<lambda> x. bind_itree x (\\<tau> \\<circ> iterate b Q)) G) \\<rbrakk> \\<Longrightarrow> R\"\n  shows R\n  by (metis assms(1) assms(2) iterate_Vis_dest)\n\nlemma iterate_VisE'[consumes 1, case_names body]:\n  assumes \"iterate b Q s = Vis F\"\n    \"\\<And> G. \\<lbrakk> b s; Q s = Vis G; F = (map_pfun (\\<lambda> x. bind_itree x (\\<tau> \\<circ> iterate b Q)) G) \\<rbrakk> \\<Longrightarrow> R\"\n  shows R\n  by (metis assms(1) assms(2) iterate_Vis_dest)\n\nlemma iterate_trace_to:\n  assumes \"P s \\<midarrow>es \\<leadsto> Ret s'\" \"b s\"\n  shows \"iterate b P s \\<midarrow>es\\<leadsto> iterate b P s'\"\nproof -\n  have \"(P s \\<bind> \\<tau> \\<circ> iterate b P) \\<midarrow>es\\<leadsto> (Ret s' \\<bind> \\<tau> \\<circ> iterate b P)\"\n    by (meson assms(1) trace_to_bind_left)\n  thus ?thesis\n    by (auto simp add: iterate.code assms)\nqed\n\nlemma iterate_term_once:\n  assumes \"P s \\<midarrow>es \\<leadsto> Ret s'\" \"b s\" \"\\<not> b s'\"\n  shows \"iterate b P s \\<midarrow>es\\<leadsto> Ret s'\"\n  by (metis assms(1) assms(2) assms(3) iterate.code iterate_trace_to)\n\nsubsection \\<open> Power \\<close>\n\noverloading\n  itreepow \\<equiv> \"compow :: nat \\<Rightarrow> ('e, 's) htree \\<Rightarrow> ('e, 's) htree\"\nbegin\n\nfun itreepow :: \"nat \\<Rightarrow> ('e, 's) htree \\<Rightarrow> ('e, 's) htree\" where\n\"itreepow 0 P = Ret\" |\n\"itreepow (Suc n) P = P ;; itreepow n P\"\n\nend\n\nsubsection \\<open> Chains \\<close>\n\ntype_synonym ('e, 's) chain = \"('e list \\<times> 's) list\"\n\ninductive itree_chain :: \"'s \\<Rightarrow> ('e, 's) htree \\<Rightarrow> ('e list \\<times> 's) list \\<Rightarrow> 's \\<Rightarrow> bool\" (\"_ \\<turnstile> _ \\<midarrow>_\\<leadsto>\\<^sup>* _\" [55, 0, 0, 55] 55) where\nchain_Nil [intro]: \"s \\<turnstile> P \\<midarrow>[]\\<leadsto>\\<^sup>* s\" |\nchain_step [intro]: \"\\<lbrakk> P(s) \\<midarrow>tr\\<leadsto> \\<checkmark> s\\<^sub>0; s\\<^sub>0 \\<turnstile> P \\<midarrow>chn\\<leadsto>\\<^sup>* s\\<^sub>1 \\<rbrakk> \\<Longrightarrow> s \\<turnstile> P \\<midarrow>(tr, s\\<^sub>0) # chn\\<leadsto>\\<^sup>* s\\<^sub>1\"\n\ninductive_cases\n  chain_stepE [elim]: \"s \\<turnstile> P \\<midarrow>(tr, s\\<^sub>0) # chn\\<leadsto>\\<^sup>* s\\<^sub>1\"\n\nlemma chain_last: \"\\<lbrakk> s \\<turnstile> P \\<midarrow>chn\\<leadsto>\\<^sup>* s'; chn \\<noteq> [] \\<rbrakk> \\<Longrightarrow> snd (last chn) = s'\"\n  by (induct rule: itree_chain.induct, auto)\n     (metis itree_chain.simps list.discI)\n\nlemma chain_appendI: \"\\<lbrakk> s \\<turnstile> P \\<midarrow>tr\\<^sub>1\\<leadsto>\\<^sup>* s\\<^sub>0; s\\<^sub>0 \\<turnstile> P \\<midarrow>tr\\<^sub>2\\<leadsto>\\<^sup>* s' \\<rbrakk> \\<Longrightarrow> s \\<turnstile> P \\<midarrow>tr\\<^sub>1 @ tr\\<^sub>2\\<leadsto>\\<^sup>* s'\"\n  by (induct rule: itree_chain.induct, auto simp add: chain_step)\n\nlemma chain_appendD: \"s \\<turnstile> P \\<midarrow>tr\\<^sub>1 @ tr\\<^sub>2\\<leadsto>\\<^sup>* s' \\<Longrightarrow> \\<exists> s\\<^sub>0. s \\<turnstile> P \\<midarrow>tr\\<^sub>1\\<leadsto>\\<^sup>* s\\<^sub>0 \\<and> s\\<^sub>0 \\<turnstile> P \\<midarrow>tr\\<^sub>2\\<leadsto>\\<^sup>* s'\"\n  apply (induct tr\\<^sub>1 arbitrary: s s')\n  apply (simp)\n  using chain_Nil apply fastforce\n  apply (simp)\n  apply (case_tac a)\n  apply (meson chain_step chain_stepE)\n  done  \n\nlemma chain_append_iff: \"s \\<turnstile> P \\<midarrow>tr\\<^sub>1 @ tr\\<^sub>2\\<leadsto>\\<^sup>* s' \\<longleftrightarrow> (\\<exists> s\\<^sub>0. s \\<turnstile> P \\<midarrow>tr\\<^sub>1\\<leadsto>\\<^sup>* s\\<^sub>0 \\<and> s\\<^sub>0 \\<turnstile> P \\<midarrow>tr\\<^sub>2\\<leadsto>\\<^sup>* s')\"\n  by (meson chain_appendD chain_appendI)\n\ndefinition chain_states :: \"('e, 's) chain \\<Rightarrow> 's set\" where\n\"chain_states chn = set (map snd chn)\"\n\nlemma chain_states_Nil [simp]: \"chain_states [] = {}\" by (simp add: chain_states_def)\nlemma chain_states_Cons [simp]: \"chain_states ((tr, s) # chn) = insert s (chain_states chn)\"\n  by (auto simp add: chain_states_def)\n\ndefinition chain_trace :: \"('e, 's) chain \\<Rightarrow> 'e list\" where\n\"chain_trace chn = concat (map fst chn)\"\n\nlemma chain_trace_Nil [simp]: \"chain_trace [] = []\" by (simp add: chain_trace_def)\nlemma chain_trace_Cons [simp]: \"chain_trace ((tr, s) # chn) = tr @ chain_trace chn\"\n  by (simp add: chain_trace_def)\n\nlemma chain_first_step: \"\\<lbrakk> s \\<turnstile> P \\<midarrow>chn\\<leadsto>\\<^sup>* s'; chn \\<noteq> [] \\<rbrakk> \\<Longrightarrow> P s \\<midarrow>fst (hd chn)\\<leadsto> \\<checkmark> (snd (hd chn))\"\n  by (metis chain_stepE list.collapse prod.collapse)\n\nlemma chain_steps: \"\\<lbrakk> s \\<turnstile> P \\<midarrow>chn\\<leadsto>\\<^sup>* s'; length chn > 1; i < length chn - 1 \\<rbrakk> \\<Longrightarrow> P (snd (chn ! i)) \\<midarrow>fst (chn ! Suc i)\\<leadsto> \\<checkmark> (snd (chn ! Suc i))\"\nproof (induct arbitrary: i rule: itree_chain.induct)\n  case (chain_Nil s P)\n  then show ?case by simp\nnext\n  case (chain_step P s tr s\\<^sub>0 chn s\\<^sub>1)\n  then show ?case\n  proof (cases \"i = 0\")\n    case True\n    with chain_step show ?thesis\n      by (simp, metis chain_first_step hd_conv_nth)\n  next\n    case False\n    with chain_step gr0_conv_Suc show ?thesis\n      by fastforce\n  qed\nqed\n\nlemma chain_stated_indexed: \"(\\<forall>s\\<in>chain_states chn. B s) \\<longleftrightarrow> (\\<forall> i<length chn. B (snd (chn ! i)))\"\n  by (auto simp add: chain_states_def, metis in_set_conv_nth snd_eqD)\n\nfun itree_term_chain :: \n  \"_ \\<times> 's \\<Rightarrow> ('e, 's) htree \\<Rightarrow> 'e list \\<Rightarrow> 's \\<Rightarrow> bool\" (\"_ \\<turnstile> _ \\<midarrow>_\\<leadsto>\\<^sub>\\<checkmark> _\" [55, 0, 0, 55] 55)\n  where \"(b, s) \\<turnstile> P \\<midarrow>tr\\<leadsto>\\<^sub>\\<checkmark> s' \\<longleftrightarrow> (\\<exists> chn s\\<^sub>0 tr\\<^sub>0. b s \\<and> s \\<turnstile> P \\<midarrow>chn\\<leadsto>\\<^sup>* s\\<^sub>0 \\<and> (\\<forall>s\\<in>chain_states chn. b s) \\<and> P s\\<^sub>0 \\<midarrow>tr\\<^sub>0\\<leadsto> \\<checkmark> s' \\<and> tr = chain_trace chn @ tr\\<^sub>0)\"\n\ndeclare itree_term_chain.simps [simp del]\n\nlemma term_chain_step:\n  assumes \"b s\" \"P(s) \\<midarrow>tr\\<^sub>0\\<leadsto> \\<checkmark> s\\<^sub>0\" \"(b, s\\<^sub>0) \\<turnstile> P \\<midarrow>tr\\<^sub>1\\<leadsto>\\<^sub>\\<checkmark> s'\"\n  shows \"(b, s) \\<turnstile> P \\<midarrow>tr\\<^sub>0 @ tr\\<^sub>1\\<leadsto>\\<^sub>\\<checkmark> s'\"\nproof -\n  obtain chn s\\<^sub>1 tr\\<^sub>2 where chn: \"b s\\<^sub>0\" \"s\\<^sub>0 \\<turnstile> P \\<midarrow>chn\\<leadsto>\\<^sup>* s\\<^sub>1\" \"\\<forall>s\\<in>chain_states chn. b s\" \"P s\\<^sub>1 \\<midarrow>tr\\<^sub>2\\<leadsto> \\<checkmark> s'\" \"tr\\<^sub>1 = chain_trace chn @ tr\\<^sub>2\"\n    by (metis assms(3) itree_term_chain.simps)\n  have chn': \"s \\<turnstile> P \\<midarrow>(tr\\<^sub>0, s\\<^sub>0) # chn\\<leadsto>\\<^sup>* s\\<^sub>1\"\n    by (simp add: assms(2) chain_step chn(2))\n  show ?thesis\n    apply (simp add: itree_term_chain.simps assms)\n    apply (rule_tac x=\"(tr\\<^sub>0, s\\<^sub>0) # chn\" in exI)\n    apply (rule_tac x=\"s\\<^sub>1\" in exI)\n    apply (simp_all add: chn chn')\n    done\nqed\n\nlemma iterate_transition_chain:\n  assumes \"s \\<turnstile> P \\<midarrow>chn\\<leadsto>\\<^sup>* s'\" \"b s\" \"\\<forall> s\\<^sub>0\\<in>chain_states chn. b s\\<^sub>0\"\n  shows \"iterate b P s \\<midarrow>chain_trace chn\\<leadsto> iterate b P s'\"\nusing assms\nproof (induct s P chn s' rule: itree_chain.induct)\n  case (chain_Nil s P)\n  then show ?case by auto\nnext\n  case (chain_step P s tr s\\<^sub>0 chn s\\<^sub>1)\n  then show ?case \n    by simp\n       (meson iterate_trace_to trace_to_trans)\nqed\n\nlemma final_state_in_chain: \"\\<lbrakk> s \\<turnstile> P \\<midarrow>chn\\<leadsto>\\<^sup>* s'; chn \\<noteq> [] \\<rbrakk> \\<Longrightarrow> s' \\<in> chain_states chn\"\n  by (drule chain_last, simp, auto simp add: chain_states_def)\n\nlemma iterate_chain_terminates:\n  assumes \"b s\" \"(b, s) \\<turnstile> P \\<midarrow>tr\\<leadsto>\\<^sub>\\<checkmark> s'\" \"\\<not> b s'\"\n  shows \"iterate b P s \\<midarrow>tr\\<leadsto> \\<checkmark> s'\"\nproof -\n  obtain chn s\\<^sub>0 tr\\<^sub>0 where P: \"s \\<turnstile> P \\<midarrow>chn\\<leadsto>\\<^sup>* s\\<^sub>0\" \"\\<forall>s\\<in>chain_states chn. b s\" \"P s\\<^sub>0 \\<midarrow>tr\\<^sub>0\\<leadsto> \\<checkmark> s'\" \"tr = chain_trace chn @ tr\\<^sub>0\"\n    using assms\n    by (simp add: itree_term_chain.simps, auto)\n\n  have 1: \"iterate b P s \\<midarrow>chain_trace chn\\<leadsto> iterate b P s\\<^sub>0\"\n    by (simp add: P(1) P(2) assms(1) iterate_transition_chain)\n  have 2: \"iterate b P s\\<^sub>0 \\<midarrow>tr\\<^sub>0\\<leadsto> \\<checkmark> s'\"\n  proof -\n    have \"b s\\<^sub>0\"\n      by (metis P(1) P(2) assms(1) final_state_in_chain itree_chain.cases list.discI)\n    thus ?thesis\n      by (simp add: P(3) assms(3) iterate_term_once)\n  qed\n  show ?thesis\n    using \"1\" \"2\" P(4) trace_to_trans by blast\nqed\n\n\nlemmas disj_cases[consumes 1, case_names disj1 disj2] = disjE\n\nlemma bind_extra_tauE:\n  assumes \n    \"(P \\<bind> \\<tau> \\<circ> \\<checkmark>) \\<midarrow>tr\\<leadsto> P'\"\n    \"\\<And>P\\<^sub>0. \\<lbrakk> P \\<midarrow>tr\\<leadsto> P\\<^sub>0; P' = P\\<^sub>0 \\<bind> \\<tau> \\<circ> \\<checkmark> \\<rbrakk> \\<Longrightarrow> thesis\"\n    \"\\<And>x. \\<lbrakk> P \\<midarrow>tr\\<leadsto> Ret x; P' = Ret x \\<rbrakk> \\<Longrightarrow> thesis\"\n  shows thesis\n  using assms\n  by (auto elim!: trace_to_bindE)\n     (metis Ret_trns bind_Ret comp_apply self_append_conv trace_to_SilE)\n\ntext \\<open> The next theorem states is a general law for extracting chains from prefixed iterations. \n  We adopt the prefixed pattern (@{term \"Q \\<bind> iterate b B\"} so that the inductive proof goes through.\n  Whenever @{term \"(Q \\<bind> iterate b B) \\<midarrow>tr\\<leadsto> R\"} there are two possibilities. (1) The prefix @{term Q}\n  performs the transition, and @{term \"iterate b B\"} is the continuation. (2) The prefix @{term Q}\n  terminates in a state @{term \"s\"}, having done a prefix of the trace, and then there is a chain of \n  iterations of the loop body. Finally, it is possible that the body makes partial progress, leading\n  to another continuation. The overall trace is consists of (a) the trace contributed by @{term Q};\n  (b) the trace contributed in the chain; and (c) the trace contributed by partial execution of\n  they body @{term B}.\n \\<close>\n\ntheorem prefixed_iterate_chain:\n  fixes B :: \"('e, 's) htree\"\n  assumes \"(Q \\<bind> iterate b B) \\<midarrow>tr\\<leadsto> R\"\n  shows \"(\\<exists> Q'. Q \\<midarrow>tr\\<leadsto> Q' \\<and> R = Q' \\<bind> iterate b B)\n         \\<or> (\\<exists> s chn s\\<^sub>0 tr\\<^sub>0 tr\\<^sub>1 P' n. \n              Q \\<midarrow>tr\\<^sub>0\\<leadsto> \\<checkmark> s \\<and> b s \\<and> s \\<turnstile> B \\<midarrow>chn\\<leadsto>\\<^sup>* s\\<^sub>0 \\<and> (\\<forall> s\\<in>chain_states chn. b s) \\<and> B s\\<^sub>0 \\<midarrow>tr\\<^sub>1\\<leadsto> P' \n            \\<and> tr = tr\\<^sub>0 @ chain_trace chn @ tr\\<^sub>1 \n            \\<and> R = P' \\<bind> Sils n \\<circ> iterate b B \\<and> n \\<le> 1)\"\n  using assms\n\\<comment> \\<open> We begin the proof by induction on the transition relation. This leads to three top-level\n  cases corresponding to the three possible ways a transition is constructed in the inductive predicate. \\<close>\nproof (induct \"Q \\<bind> iterate b B\" tr R arbitrary: Q rule: trace_to.induct)\n  \\<comment> \\<open> If the transition is empty, and so @{term \"R = Q \\<bind> iterate b B\"}, then the proof is trivial. \\<close>\n  case trace_to_Nil\n  then show ?case\n    by blast\nnext\n  text \\<open> If the transition is a @{term \"\\<tau>\"} then we need to further determine whether it originates\n    in @{term Q} or in the loop @{term \"iterate b B\"}. \\<close>\n  case (trace_to_Sil P tr P')\n  have \"\\<tau> P = Q \\<bind> iterate b B\"\n    by (simp add: trace_to_Sil.hyps(3))\n  thus ?case\n  \\<comment> \\<open> We split on these two possibilities below. \\<close>\n  proof (cases rule: bind_SilE')\n    case (initial Q\\<^sub>0)\n    note Q_def = this(1) and P_def = this(2)\n    from trace_to_Sil.hyps(2)[of Q\\<^sub>0, OF initial(2)] show ?thesis\n    \\<comment> \\<open> If it originates in @{term Q}, we need to further split the inductive hypotheses. Either\n         the remainder of @{term Q} (@{term Q\\<^sub>0}) can reach @{term R}, or else the loop body has\n         executed, and so there is a chain. \\<close>\n    proof (cases rule: disj_cases)\n      case disj1\n      then show ?thesis\n        using trace_to_Sil P_def Q_def by blast\n    next\n      case disj2\n      then obtain s s\\<^sub>0 ::\"'s\" and chn::\"('e,'s) chain\" and tr\\<^sub>0 tr\\<^sub>1 :: \"'e list\" and B' :: \"('e, 's) itree\" and n :: nat\n        where steps: \"Q\\<^sub>0 \\<midarrow>tr\\<^sub>0\\<leadsto> \\<checkmark> s\" \"b s\" \"s \\<turnstile> B \\<midarrow>chn\\<leadsto>\\<^sup>* s\\<^sub>0\" \"\\<forall> s\\<in>chain_states chn. b s\" \"B s\\<^sub>0 \\<midarrow>tr\\<^sub>1\\<leadsto> B'\" \n                     \"tr = tr\\<^sub>0 @ chain_trace chn @ tr\\<^sub>1\" \"P' = B' \\<bind> Sils n \\<circ> iterate b B\" \"n \\<le> 1\"\n        by blast\n        \n      show ?thesis\n        apply (simp add: Q_def P_def)\n        apply (rule_tac disjI2)\n        apply (rule_tac x=\"s\" in exI)\n        apply (rule_tac x=\"chn\" in exI)\n        apply (rule_tac x=\"s\\<^sub>0\" in exI)\n        apply (rule_tac x=\"tr\\<^sub>0\" in exI)\n        apply (simp add: steps)\n        using steps(5) steps(8) apply auto\n        done\n    qed\n  next\n    case (continue s)\n    note defs = this\n    with defs(2) show ?thesis\n    \\<comment> \\<open> If the @{term \\<tau>} originates in the loop, then again we need two cases: (1) it originates\n         in the first execution of body, or (2) some further iterations. \\<close>\n    proof (cases rule: iterate_SilE)\n      case (continue s') \n      with trace_to_Sil(2)[of \"Ret s' :: ('e, 's) itree\", simplified, OF continue(3)] show ?thesis\n      proof (cases rule: disj_cases)\n        case disj1\n        with continue show ?thesis\n          apply (simp add: defs)\n          apply (rule_tac disjI2)\n          apply (rule_tac x=\"[]\" in exI)\n          apply (rule_tac x=\"s\" in exI)\n          apply (auto)\n          apply (metis Sils.simps(1) bot_nat_0.extremum)\n          done\n      next\n        case disj2\n        then obtain chn s\\<^sub>0 tr\\<^sub>1 P'' n where P'': \"b s'\" \"s' \\<turnstile> B \\<midarrow>chn\\<leadsto>\\<^sup>* s\\<^sub>0\" \"\\<forall> s\\<in>chain_states chn. b s\" \"B s\\<^sub>0 \\<midarrow>tr\\<^sub>1\\<leadsto> P''\" \"tr = chain_trace chn @ tr\\<^sub>1\" \"P' = P'' \\<bind> Sils n \\<circ> iterate b B\" \"n \\<le> 1\"\n          by auto\n        with continue show ?thesis\n          apply (simp add: defs)\n          apply (rule_tac disjI2)\n          apply (rule_tac x=\"([], s') # chn\" in exI)\n          apply (rule_tac x=\"s\\<^sub>0\" in exI)\n          apply auto\n          done\n      qed\n    next\n      \\<comment> \\<open> The prefix terminated in state @{term s}, and body @{term B} made partial progress. \\<close>\n      case (initial P\\<^sub>0)\n      hence P: \"P = P\\<^sub>0 \\<bind> \\<tau> \\<circ> \\<checkmark> \\<bind> iterate b B\"\n        by (simp add: bind_itree_assoc[THEN sym] comp_def)\n      from trace_to_Sil(2)[of \"P\\<^sub>0 \\<bind> Sil \\<circ> Ret\", OF P] initial(1)\n      show ?thesis\n      proof (cases rule: disj_cases)\n        case disj1\n        with initial(1,2) show ?thesis \n          apply (simp add: defs)\n          apply (rule disjI2)\n          apply (rule_tac x=\"[]\" in exI)\n          apply (rule_tac x=\"s\" in exI)\n          apply (auto)\n          apply (erule bind_extra_tauE)\n           apply (simp)\n           apply (rule_tac x=\"P\\<^sub>0'\" in exI)\n           apply (auto simp add: bind_itree_assoc[THEN sym] comp_def)\n           apply (rule_tac x=\"1\" in exI)\n          apply simp\n          apply (metis Sils.simps(1) bind_Ret bot_nat_0.extremum trace_to.trace_to_Sil)\n          done\n      next\n        case disj2\n        then obtain s\\<^sub>0 chn s\\<^sub>1 tr\\<^sub>0 tr\\<^sub>1 P'' n\n          where P\\<^sub>0: \"(P\\<^sub>0 \\<bind> \\<tau> \\<circ> \\<checkmark>) \\<midarrow>tr\\<^sub>0\\<leadsto> \\<checkmark> s\\<^sub>0\" \"b s\\<^sub>0\" \"s\\<^sub>0 \\<turnstile> B \\<midarrow>chn\\<leadsto>\\<^sup>* s\\<^sub>1\" \"\\<forall> s\\<in>chain_states chn. b s\"\n                    \"B s\\<^sub>1 \\<midarrow>tr\\<^sub>1\\<leadsto> P''\" \"tr = tr\\<^sub>0 @ chain_trace chn @ tr\\<^sub>1\" \"P' = P'' \\<bind> Sils n \\<circ> iterate b B\" \"n \\<le> 1\"\n          by auto\n        then show ?thesis\n          apply (simp add: defs)\n          apply (rule_tac disjI2)\n          apply auto\n          using initial(1) apply fastforce\n          apply (rule_tac x=\"(tr\\<^sub>0, s\\<^sub>0) # chn\" in exI)\n          apply (rule_tac x=\"s\\<^sub>1\" in exI)\n          apply auto\n           apply (simp add: chain_step initial(2) trace_to_post_Sil_iff)\n          done\n      qed\n    qed\n  qed\nnext\n  case (trace_to_Vis e F tr P')\n  hence \"Vis F = Q \\<bind> iterate b B\" by simp\n  thus ?case\n  proof (cases rule: bind_VisE')\n    case (initial F')\n    have F: \"F(e)\\<^sub>p = F'(e)\\<^sub>p \\<bind> iterate b B\"\n      using initial(2) trace_to_Vis.hyps(1) by auto\n\n    from trace_to_Vis(3)[of \"F'(e)\\<^sub>p\", OF F] show ?thesis\n    proof (cases rule: disj_cases)\n      case disj1\n      then show ?thesis\n        using initial(1) initial(2) trace_to_Vis.hyps(1) by auto\n    next\n      case disj2\n      then show ?thesis\n        by (metis append_Cons initial(1) initial(2) pdom_map_pfun trace_to.trace_to_Vis trace_to_Vis.hyps(1)) \n    qed\n  next\n    case (continue s)\n    from continue(2) show ?thesis\n    proof (cases rule: iterate_VisE')\n      case (body G)\n      hence \"F(e)\\<^sub>p = G(e)\\<^sub>p \\<bind> \\<tau> \\<circ> iterate b B\"\n        using trace_to_Vis.hyps(1) by auto\n      hence F: \"F(e)\\<^sub>p = G(e)\\<^sub>p \\<bind> \\<tau> \\<circ> \\<checkmark> \\<bind> iterate b B\"\n        by (simp add: bind_itree_assoc[THEN sym] comp_def)\n      from trace_to_Vis(3)[of \"G(e)\\<^sub>p \\<bind> Sil \\<circ> Ret\", OF F] show ?thesis\n      proof (cases rule: disj_cases)\n        case disj1\n        then obtain Q' where \"(G(e)\\<^sub>p \\<bind> \\<tau> \\<circ> \\<checkmark>) \\<midarrow>tr\\<leadsto> Q'\" \"P' = Q' \\<bind> iterate b B\"\n          by auto\n        with trace_to_Vis(1) continue(1) body show ?thesis\n          apply (simp)\n          apply (rule_tac x=\"[]\" in exI)\n          apply (rule_tac x=\"s\" in exI)\n          apply auto\n          apply (erule bind_extra_tauE)\n           apply (rule_tac x=\"P\\<^sub>0\" in exI)\n           apply auto\n           apply (rule_tac x=\"1\" in exI)\n          apply (simp add: bind_itree_assoc[THEN sym] comp_def)\n          apply (metis Sils.simps(1) bind_Ret bot_nat_0.extremum comp_eq_dest_lhs)\n        done\n      next\n        case disj2\n        then obtain s\\<^sub>0 chn s\\<^sub>1 tr\\<^sub>0 tr\\<^sub>1 P'' n \n          where G: \"(G(e)\\<^sub>p \\<bind> \\<tau> \\<circ> \\<checkmark>) \\<midarrow>tr\\<^sub>0\\<leadsto> \\<checkmark> s\\<^sub>0\" \"b s\\<^sub>0\" \n          and chn: \"s\\<^sub>0 \\<turnstile> B \\<midarrow>chn\\<leadsto>\\<^sup>* s\\<^sub>1\" \"\\<forall> s\\<in>chain_states chn. b s\" \"B s\\<^sub>1 \\<midarrow>tr\\<^sub>1\\<leadsto> P''\" \"tr = tr\\<^sub>0 @ chain_trace chn @ tr\\<^sub>1\" and P': \"P' = P'' \\<bind> Sils n \\<circ> iterate b B\" \"n \\<le> 1\"\n          by auto\n        from G trace_to_Vis(1,2) continue(1) body P' chn show ?thesis\n          apply (simp)\n          apply (erule bind_extra_tauE)\n          apply (rule_tac x=\"(e # tr, s\\<^sub>0) # chn\" in exI)\n          apply (rule_tac x=\"s\\<^sub>1\" in exI)\n          apply auto\n          apply (rule_tac x=\"(e # tr\\<^sub>0, s\\<^sub>0) # chn\" in exI)\n          apply (rule_tac x=\"s\\<^sub>1\" in exI)\n          apply auto\n          done\n      qed \n    qed\n  qed\nqed\n\nlemma iterate_chain [consumes 1, case_names iterates terms]:\n  assumes \n    \"iterate b B s \\<midarrow>tr\\<leadsto> R\"\n    \"\\<And> chn s\\<^sub>0 tr\\<^sub>0 P' n. \n        \\<lbrakk> b s;\n          s \\<turnstile> B \\<midarrow>chn\\<leadsto>\\<^sup>* s\\<^sub>0; \n          \\<forall> s\\<in>chain_states chn. b s;\n          B s\\<^sub>0 \\<midarrow>tr\\<^sub>0\\<leadsto> P';\n          tr = chain_trace chn @ tr\\<^sub>0; \n          R = P' \\<bind> Sils n \\<circ> iterate b B; \n          n \\<le> 1\n        \\<rbrakk> \\<Longrightarrow> P\"\n    \"\\<lbrakk> \\<not> b s; tr = []; R = \\<checkmark> s \\<rbrakk> \\<Longrightarrow> P\"\n  shows P\nproof (cases \"b s\")\n  case True\n  show ?thesis\n    using prefixed_iterate_chain[of \"\\<checkmark> s\", simplified, OF assms(1)]\n  proof (cases rule: disj_cases)\n    case disj1\n    then show ?thesis\n      by (rule_tac assms(2)[of \"[]\" s \"[]\" \"B s\" 1, simplified], auto simp add: iterate.code comp_def assms True)\n  next\n    case disj2\n    then show ?thesis\n      using assms(2) by force\n  qed \nnext\n  case False\n  thus ?thesis\n    using assms(1) assms(3) by force\nqed\n\nlemma iterate_terminates_chain:\n  assumes \n    \"iterate b B s \\<midarrow>tr\\<leadsto> \\<checkmark> s'\"\n    \"\\<lbrakk> b s; (b, s) \\<turnstile> B \\<midarrow>tr\\<leadsto>\\<^sub>\\<checkmark> s'; \\<not> b s' \\<rbrakk> \\<Longrightarrow> P\"\n    \"\\<lbrakk> \\<not> b s; tr = []; s' = s \\<rbrakk> \\<Longrightarrow> P\"\n  shows P\n  using assms\nproof (cases rule: iterate_chain)\n  case (iterates chn s\\<^sub>0 tr\\<^sub>0 P' n)\n  hence P': \"P' = \\<checkmark> s'\" \"\\<not> b s'\"\n    by (auto elim!: bind_RetE', metis Ret_Sils_iff iterate_RetE')+\n  then show ?thesis\n    by (metis assms(2) iterates(1-5) itree_term_chain.simps)\nnext\n  case terms\n  then show ?thesis\n    using assms(3) by fastforce\nqed\n\nlemma iterate_term_chain_iff:\n  \"iterate b B s \\<midarrow>tr\\<leadsto> \\<checkmark> s' \\<longleftrightarrow> \n   ((\\<not> b s \\<and> s = s' \\<and> tr = []) \\<or> (b s \\<and> (b, s) \\<turnstile> B \\<midarrow>tr\\<leadsto>\\<^sub>\\<checkmark> s' \\<and> \\<not> b s'))\"\nproof (cases \"b s\")\n  case True\n  then show ?thesis\n    by (metis iterate_chain_terminates iterate_terminates_chain)\nnext\n  case False\n  then show ?thesis\n    by force \nqed\n\ntext \\<open> If @{term P} is an invariant of a chain for process @{term C}, then the invariant holds\n  for every element of the looped process @{term C}. \\<close>\n\nlemma chain_invariant:\n  assumes \n    \"B s\" \"P s\"\n    \"\\<And> s s'. \\<lbrakk> B s; P s; s' \\<in> \\<^bold>R(C s) \\<rbrakk> \\<Longrightarrow> P s'\"\n    \"s \\<turnstile> C \\<midarrow>chn\\<leadsto>\\<^sup>* s'\"\n    \"\\<forall> s\\<^sub>0\\<in>chain_states chn. B s\\<^sub>0\"\n  shows \"\\<forall> s\\<^sub>0\\<in>chain_states chn. P s\\<^sub>0\"\nproof -\n  have \"\\<forall>i<length chn. P (snd (chn ! i))\"\n  proof (clarify)\n    fix i\n    assume i: \"i < length chn\"\n    thus \"P (snd (chn ! i))\"\n    proof (induct i)\n      case 0\n      hence \"C s \\<midarrow>fst (chn ! 0)\\<leadsto> \\<checkmark> (snd (chn ! 0))\"\n        by (metis assms(4) chain_first_step hd_conv_nth length_greater_0_conv)\n      thus ?case\n        by (meson assms(1) assms(2) assms(3) retvals_traceI)\n    next\n      case (Suc i)\n      hence \"C (snd (chn ! i)) \\<midarrow>fst (chn ! Suc i)\\<leadsto> \\<checkmark> (snd (chn ! Suc i))\"\n        using assms(4) chain_steps by fastforce        \n      moreover have \"P (snd (chn ! i))\"\n        by (simp add: Suc.hyps Suc.prems Suc_lessD)\n      moreover have \"B (snd (chn ! i))\"\n        by (simp add: Suc.prems Suc_lessD assms(5) chain_states_def)\n      ultimately show ?case\n        by (meson assms(3) retvals_traceI)\n    qed\n  qed\n  thus ?thesis\n    by (simp add: chain_stated_indexed)\nqed\n\nlemma chain_invariant_simple:\n  assumes \n    \"P s\"\n    \"\\<And> s s'. \\<lbrakk> P s; s' \\<in> \\<^bold>R(C s) \\<rbrakk> \\<Longrightarrow> P s'\"\n    \"s \\<turnstile> C \\<midarrow>chn\\<leadsto>\\<^sup>* s'\"\n  shows \"\\<forall> s\\<^sub>0\\<in>chain_states chn. P s\\<^sub>0\"\n  using assms\n  by (rule_tac chain_invariant[of \"\\<lambda> s. True\" s P C chn s'], auto)\n\ntext \\<open> We can establish termination, as usual, with an variant function. Here, ``terminates'' means \n  that an ITree may terminate. \\<close>\n\ndefinition terminates :: \"('e, 's) itree \\<Rightarrow> bool\" where\n\"terminates P = (\\<exists> tr s'. P \\<midarrow>tr\\<leadsto> \\<checkmark> s')\"\n\nlemma terminates_Ret: \"terminates (\\<checkmark> s')\"\n  by (simp add: terminates_def)\n\nlemma terminates_Sil: \"terminates (Sil P) = terminates P\"\n  by (simp add: terminates_def)\n\nlemma terminates_Sils: \"terminates (Sils n P) = terminates P\"\n  by (simp add: terminates_def)\n\nlemma terminates_bind:\n  assumes \"terminates P\" \"\\<And> v. v \\<in> \\<^bold>R(P) \\<Longrightarrow> terminates(Q v)\"\n  shows \"terminates (P \\<bind> Q)\"\n  by (meson assms(1) assms(2) retvals_traceI terminates_def trace_to_bind)\n\nlemma not_terminates_diverge:\n  \"terminates diverge = False\"\n  by (meson diverge_no_Ret_trans terminates_def)\n\ntext \\<open> A terminating pure ITree is divergence free \\<close>\n\nlemma terminates_pure_implies_div_free:\n  assumes \"pure_itree P\" \"terminates P\"\n  shows \"div_free P\"\n  by (metis Sils_diverge assms div_free_is_no_divergence no_divergence_def not_terminates_diverge pure_itree_def trace_to_Nil_Sils)\n\ntext \\<open> The following theorem using both a variant @{term V} and invariant @{term I} to establish\n  termination. \\<close>\n\nlemma wellorder_variant_term_chain:\n  fixes V :: \"'s \\<Rightarrow> 'a::wellorder\" and I :: \"'s \\<Rightarrow> bool\"\n  assumes \n    \"\\<And> s\\<^sub>0. \\<lbrakk> b s\\<^sub>0; I s\\<^sub>0 \\<rbrakk> \\<Longrightarrow> terminates (B s\\<^sub>0)\"\n    \"\\<And> s\\<^sub>0 s\\<^sub>1 tr. \\<lbrakk> b s\\<^sub>0; I s\\<^sub>0; B(s\\<^sub>0) \\<midarrow>tr\\<leadsto> \\<checkmark> s\\<^sub>1 \\<rbrakk> \\<Longrightarrow> I s\\<^sub>1\"\n    \"\\<And> s\\<^sub>0 s\\<^sub>1 tr. \\<lbrakk> b s\\<^sub>0; I s\\<^sub>0; B(s\\<^sub>0) \\<midarrow>tr\\<leadsto> \\<checkmark> s\\<^sub>1 \\<rbrakk> \\<Longrightarrow> V(s\\<^sub>1) < V(s\\<^sub>0)\"\n  shows \"\\<lbrakk> I s; b s \\<rbrakk> \\<Longrightarrow> \\<exists> tr s'. (b, s) \\<turnstile> B \\<midarrow>tr\\<leadsto>\\<^sub>\\<checkmark> s' \\<and> \\<not> b s'\"\nproof (induct \"V(s)\" arbitrary: s rule: less_induct)\n  case (less s\\<^sub>0)\n  obtain s\\<^sub>1 tr\\<^sub>0 where B_next: \"B(s\\<^sub>0) \\<midarrow>tr\\<^sub>0\\<leadsto> \\<checkmark> s\\<^sub>1\"\n    by (meson assms(1) less.prems(1) less.prems(2) terminates_def)\n  have inv: \"I s\\<^sub>1\"\n    using B_next assms(2) less.prems(1) less.prems(2) by presburger\n  have dec: \"V(s\\<^sub>1) < V(s\\<^sub>0)\"\n    using B_next assms(3) less.prems(1) less.prems(2) by force\n  show ?case\n  proof (cases \"b s\\<^sub>1\")\n    case True\n    obtain tr\\<^sub>1 s' where chain: \"(b, s\\<^sub>1) \\<turnstile> B \\<midarrow>tr\\<^sub>1\\<leadsto>\\<^sub>\\<checkmark> s' \\<and> \\<not> b s'\"\n      using True dec inv less.hyps by presburger\n    then show ?thesis\n      by (meson B_next less.prems term_chain_step) \n  next\n    case False\n    then show ?thesis\n      by (metis B_next iterate_term_chain_iff iterate_term_once less.prems(2)) \n  qed  \nqed\n\nlemma terminates_iterate_wellorder_variant:\n  fixes V :: \"'s \\<Rightarrow> 'a::wellorder\" and I :: \"'s \\<Rightarrow> bool\"\n  assumes \n    \"\\<And> s\\<^sub>0. \\<lbrakk> b s\\<^sub>0; I s\\<^sub>0 \\<rbrakk> \\<Longrightarrow> terminates (B s\\<^sub>0)\"\n    \"\\<And> s\\<^sub>0 s\\<^sub>1 tr. \\<lbrakk> b s\\<^sub>0; I s\\<^sub>0; B(s\\<^sub>0) \\<midarrow>tr\\<leadsto> \\<checkmark> s\\<^sub>1 \\<rbrakk> \\<Longrightarrow> I s\\<^sub>1\"\n    \"\\<And> s\\<^sub>0 s\\<^sub>1 tr. \\<lbrakk> b s\\<^sub>0; I s\\<^sub>0; B(s\\<^sub>0) \\<midarrow>tr\\<leadsto> \\<checkmark> s\\<^sub>1 \\<rbrakk> \\<Longrightarrow> V(s\\<^sub>1) < V(s\\<^sub>0)\"\n    \"I s\"\n  shows \"terminates (iterate b B s)\"\nproof (cases \"b s\")\n  case True\n  have \"\\<exists> tr s'. (b, s) \\<turnstile> B \\<midarrow>tr\\<leadsto>\\<^sub>\\<checkmark> s' \\<and> \\<not> b s'\"\n    by (rule wellorder_variant_term_chain[of b I B V], simp_all add: assms True)\n  then show ?thesis\n    by (metis iterate_term_chain_iff terminates_def)\n  next\n  case False\n  then show ?thesis\n    by (simp add: terminates_def)\nqed\n\ntext \\<open> Generalised deadlock freedom check for loops. If @{term P} is sufficient establish deadlock\n  freedom of @{term C}, and @{term P} is an invariant of @{term C}, which holds also in the initial\n  state @{term s}, then @{term \"loop C s\"} is also deadlock free. \\<close>\n\nlemma deadlock_free_loop:\n  assumes cond_dlockf: \"\\<And> s. P s \\<Longrightarrow> deadlock_free (C s)\" \n  and invariant: \"\\<And> s s'. \\<lbrakk> P s; s' \\<in> \\<^bold>R(C s) \\<rbrakk> \\<Longrightarrow> P s'\"\n  and initial: \"P s\"\n  shows \"deadlock_free (loop C s)\"\nproof (simp add: deadlock_free_def deadlock_def, clarify)\n  fix tr \n  assume \"loop C s \\<midarrow>tr\\<leadsto> Vis {\\<mapsto>}\"\n  thus False\n  proof (cases rule: iterate_chain)\n    case (iterates chn s\\<^sub>0 tr\\<^sub>0 P' n)\n    with initial invariant have \"\\<forall> s\\<in>chain_states chn. P s\"\n      by (rule_tac chain_invariant_simple[where s=\"s\" and C=\"C\" and s'=\"s\\<^sub>0\"], auto)\n    hence dlckf_C_s\\<^sub>0: \"deadlock_free (C s\\<^sub>0)\"\n      by (metis cond_dlockf final_state_in_chain initial iterates(2) itree_chain.cases list.distinct(1))\n    with iterates(6) show False\n    proof (cases rule: bind_VisE')\n      case (initial F')\n      then show ?thesis\n        by (metis deadlock_def deadlock_free_def dlckf_C_s\\<^sub>0 iterates(4) pdom_empty_iff_dom_empty pdom_map_pfun)\n    next\n      case (continue s')\n      have \"loop C s' = Vis {\\<mapsto>}\"\n        by (metis comp_apply continue(2) deadlock_def deadlock_trace_to trace_of_Sils)\n      then show ?thesis\n        by (metis (no_types, lifting) \\<open>\\<forall>s\\<in>chain_states chn. P s\\<close> cond_dlockf continue(1) deadlock_def deadlock_free_def deadlock_trace_to final_state_in_chain initial invariant iterate_VisE iterates(2) iterates(4) itree_chain.simps list.distinct(1) pdom_empty_iff_dom_empty pdom_map_pfun pdom_zero retvals_traceI)\n    qed\n  next\n    case terms\n    then show ?thesis\n      by blast\n  qed\nqed\n    \n\nend", "meta": {"author": "isabelle-utp", "repo": "interaction-trees", "sha": "90510d119364f534d2ab61daf2f274060f0a040e", "save_path": "github-repos/isabelle/isabelle-utp-interaction-trees", "path": "github-repos/isabelle/isabelle-utp-interaction-trees/interaction-trees-90510d119364f534d2ab61daf2f274060f0a040e/ITree_Iteration.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5117166047041654, "lm_q2_score": 0.5273165233795671, "lm_q1q2_score": 0.2698366209481967}}
{"text": "(* Copyright 2021 (C) Mihails Milehins *)\n\nsection\\<open>Comma categories\\<close>\ntheory CZH_ECAT_Comma\n  imports \n    CZH_ECAT_NTCF\n    CZH_ECAT_Simple\nbegin\n\n\n\nsubsection\\<open>Background\\<close>\n\nnamed_theorems cat_comma_cs_simps\nnamed_theorems cat_comma_cs_intros\n\n\n\nsubsection\\<open>Comma category\\<close>\n\n\nsubsubsection\\<open>Definition and elementary properties\\<close>\n\n\ntext\\<open>\nSee Exercise 1.3.vi in \\<^cite>\\<open>\"riehl_category_2016\"\\<close> or \nChapter II-6 in \\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>.\n\\<close>\n\ndefinition cat_comma_Obj :: \"V \\<Rightarrow> V \\<Rightarrow> V\"\n  where \"cat_comma_Obj \\<GG> \\<HH> \\<equiv> set\n    {\n      [a, b, f]\\<^sub>\\<circ> | a b f.\n        a \\<in>\\<^sub>\\<circ> \\<GG>\\<lparr>HomDom\\<rparr>\\<lparr>Obj\\<rparr> \\<and>\n        b \\<in>\\<^sub>\\<circ> \\<HH>\\<lparr>HomDom\\<rparr>\\<lparr>Obj\\<rparr> \\<and>\n        f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<GG>\\<lparr>HomCod\\<rparr>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\n    }\"\n\nlemma small_cat_comma_Obj[simp]: \n  \"small\n    {\n      [a, b, f]\\<^sub>\\<circ> | a b f.\n        a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr> \\<and> b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr> \\<and> f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\n    }\"\n  (is \\<open>small ?abfs\\<close>)\nproof-\n  define Q where\n    \"Q i = (if i = 0 then \\<AA>\\<lparr>Obj\\<rparr> else if i = 1\\<^sub>\\<nat> then \\<BB>\\<lparr>Obj\\<rparr> else \\<CC>\\<lparr>Arr\\<rparr>)\" \n    for i\n  have \"?abfs \\<subseteq> elts (\\<Prod>\\<^sub>\\<circ>i\\<in>\\<^sub>\\<circ> set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}. Q i)\"\n    unfolding Q_def\n  proof\n    (\n      intro subsetI, \n      unfold mem_Collect_eq, \n      elim exE conjE, \n      intro vproductI; \n      simp only:\n    )\n    fix a b f show \"\\<D>\\<^sub>\\<circ> [a, b, f]\\<^sub>\\<circ> = set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}\"\n      by (simp add: three nat_omega_simps)\n  qed (force simp: nat_omega_simps)+\n  then show \"small ?abfs\" by (rule down)\nqed\n\ndefinition cat_comma_Hom :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V\"\n  where \"cat_comma_Hom \\<GG> \\<HH> A B \\<equiv> set\n    {\n      [A, B, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ> | g h.\n        A \\<in>\\<^sub>\\<circ> cat_comma_Obj \\<GG> \\<HH> \\<and>\n        B \\<in>\\<^sub>\\<circ> cat_comma_Obj \\<GG> \\<HH> \\<and>\n        g : A\\<lparr>0\\<rparr> \\<mapsto>\\<^bsub>\\<GG>\\<lparr>HomDom\\<rparr>\\<^esub> B\\<lparr>0\\<rparr> \\<and>\n        h : A\\<lparr>1\\<^sub>\\<nat>\\<rparr> \\<mapsto>\\<^bsub>\\<HH>\\<lparr>HomDom\\<rparr>\\<^esub> B\\<lparr>1\\<^sub>\\<nat>\\<rparr> \\<and>\n        B\\<lparr>2\\<^sub>\\<nat>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<GG>\\<lparr>HomCod\\<rparr>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> =\n         \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<GG>\\<lparr>HomCod\\<rparr>\\<^esub> A\\<lparr>2\\<^sub>\\<nat>\\<rparr>\n    }\"\n\nlemma small_cat_comma_Hom[simp]: \"small\n  {\n    [A, B, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ> | g h.\n      A \\<in>\\<^sub>\\<circ> cat_comma_Obj \\<GG> \\<HH> \\<and>\n      B \\<in>\\<^sub>\\<circ> cat_comma_Obj \\<GG> \\<HH> \\<and>\n      g : A\\<lparr>0\\<rparr> \\<mapsto>\\<^bsub>\\<AA>\\<^esub> B\\<lparr>0\\<rparr> \\<and>\n      h : A\\<lparr>1\\<^sub>\\<nat>\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> B\\<lparr>1\\<^sub>\\<nat>\\<rparr> \\<and>\n      B\\<lparr>2\\<^sub>\\<nat>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> A\\<lparr>2\\<^sub>\\<nat>\\<rparr>\n  }\"\n  (is \\<open>small ?abf_a'b'f'_gh\\<close>)\nproof-\n  define Q where\n    \"Q i =\n      (\n        if i = 0\n        then cat_comma_Obj \\<GG> \\<HH> \n        else if i = 1\\<^sub>\\<nat> then cat_comma_Obj \\<GG> \\<HH> else \\<AA>\\<lparr>Arr\\<rparr> \\<times>\\<^sub>\\<bullet> \\<BB>\\<lparr>Arr\\<rparr>\n      )\"\n    for i\n  have \"?abf_a'b'f'_gh \\<subseteq> elts (\\<Prod>\\<^sub>\\<circ>i\\<in>\\<^sub>\\<circ> set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}. Q i)\"\n    unfolding Q_def\n  proof\n    (\n      intro subsetI, \n      unfold mem_Collect_eq, \n      elim exE conjE,\n      intro vproductI; \n      simp only:\n    )\n    fix a b f show \"\\<D>\\<^sub>\\<circ> [a, b, f]\\<^sub>\\<circ> = ZFC_in_HOL.set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}\"\n      by (simp add: three nat_omega_simps)\n  qed (force simp : nat_omega_simps)+\n  then show \"small ?abf_a'b'f'_gh\" by (rule down)\nqed\n\ndefinition cat_comma_Arr :: \"V \\<Rightarrow> V \\<Rightarrow> V\"\n  where \"cat_comma_Arr \\<GG> \\<HH> \\<equiv>\n    (\n      \\<Union>\\<^sub>\\<circ>A\\<in>\\<^sub>\\<circ>cat_comma_Obj \\<GG> \\<HH>. \\<Union>\\<^sub>\\<circ>B\\<in>\\<^sub>\\<circ>cat_comma_Obj \\<GG> \\<HH>.\n        cat_comma_Hom \\<GG> \\<HH> A B\n    )\"\n\ndefinition cat_comma_composable :: \"V \\<Rightarrow> V \\<Rightarrow> V\"\n  where \"cat_comma_composable \\<GG> \\<HH> \\<equiv> set\n    {\n      [[B, C, G]\\<^sub>\\<circ>, [A, B, F]\\<^sub>\\<circ>]\\<^sub>\\<circ> | A B C G F.\n        [B, C, G]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> cat_comma_Arr \\<GG> \\<HH> \\<and> [A, B, F]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> cat_comma_Arr \\<GG> \\<HH>\n    }\"\n\nlemma small_cat_comma_composable[simp]:\n  shows \"small\n    {\n      [[B, C, G]\\<^sub>\\<circ>, [A, B, F]\\<^sub>\\<circ>]\\<^sub>\\<circ> | A B C G F.\n        [B, C, G]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> cat_comma_Arr \\<GG> \\<HH> \\<and> [A, B, F]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> cat_comma_Arr \\<GG> \\<HH>\n    }\"\n  (is \\<open>small ?S\\<close>)\nproof(rule down)\n  show \"?S \\<subseteq> elts (cat_comma_Arr \\<GG> \\<HH> \\<times>\\<^sub>\\<bullet> cat_comma_Arr \\<GG> \\<HH>)\" by auto\nqed\n\ndefinition cat_comma :: \"V \\<Rightarrow> V \\<Rightarrow> V\" (\\<open>(_ \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F _)\\<close> [1000, 1000] 999)\n  where \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH> =\n    [\n      cat_comma_Obj \\<GG> \\<HH>,\n      cat_comma_Arr \\<GG> \\<HH>,\n      (\\<lambda>F\\<in>\\<^sub>\\<circ>cat_comma_Arr \\<GG> \\<HH>. F\\<lparr>0\\<rparr>),\n      (\\<lambda>F\\<in>\\<^sub>\\<circ>cat_comma_Arr \\<GG> \\<HH>. F\\<lparr>1\\<^sub>\\<nat>\\<rparr>),\n      (\n        \\<lambda>GF\\<in>\\<^sub>\\<circ>cat_comma_composable \\<GG> \\<HH>.\n          [\n            GF\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>0\\<rparr>,\n            GF\\<lparr>0\\<rparr>\\<lparr>1\\<^sub>\\<nat>\\<rparr>,\n            [\n              GF\\<lparr>0\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr>\\<lparr>0\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<GG>\\<lparr>HomDom\\<rparr>\\<^esub> GF\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr>\\<lparr>0\\<rparr>,\n              GF\\<lparr>0\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr>\\<lparr>1\\<^sub>\\<nat>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<HH>\\<lparr>HomDom\\<rparr>\\<^esub> GF\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr>\\<lparr>1\\<^sub>\\<nat>\\<rparr>\n            ]\\<^sub>\\<circ>\n          ]\\<^sub>\\<circ>\n      ),\n      (\n        \\<lambda>A\\<in>\\<^sub>\\<circ>cat_comma_Obj \\<GG> \\<HH>.\n          [A, A, [\\<GG>\\<lparr>HomDom\\<rparr>\\<lparr>CId\\<rparr>\\<lparr>A\\<lparr>0\\<rparr>\\<rparr>, \\<HH>\\<lparr>HomDom\\<rparr>\\<lparr>CId\\<rparr>\\<lparr>A\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<rparr>]\\<^sub>\\<circ>]\\<^sub>\\<circ>\n      )\n    ]\\<^sub>\\<circ>\"\n\n\ntext\\<open>Components.\\<close>\n\nlemma cat_comma_components:\n  shows \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr> = cat_comma_Obj \\<GG> \\<HH>\"\n    and \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr> = cat_comma_Arr \\<GG> \\<HH>\"\n    and \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Dom\\<rparr> = (\\<lambda>F\\<in>\\<^sub>\\<circ>cat_comma_Arr \\<GG> \\<HH>. F\\<lparr>0\\<rparr>)\"\n    and \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Cod\\<rparr> = (\\<lambda>F\\<in>\\<^sub>\\<circ>cat_comma_Arr \\<GG> \\<HH>. F\\<lparr>1\\<^sub>\\<nat>\\<rparr>)\"\n    and \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Comp\\<rparr> =\n      (\n        \\<lambda>GF\\<in>\\<^sub>\\<circ>cat_comma_composable \\<GG> \\<HH>.\n          [\n            GF\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>0\\<rparr>,\n            GF\\<lparr>0\\<rparr>\\<lparr>1\\<^sub>\\<nat>\\<rparr>,\n            [\n              GF\\<lparr>0\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr>\\<lparr>0\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<GG>\\<lparr>HomDom\\<rparr>\\<^esub> GF\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr>\\<lparr>0\\<rparr>,\n              GF\\<lparr>0\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr>\\<lparr>1\\<^sub>\\<nat>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<HH>\\<lparr>HomDom\\<rparr>\\<^esub> GF\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr>\\<lparr>1\\<^sub>\\<nat>\\<rparr>\n            ]\\<^sub>\\<circ>\n          ]\\<^sub>\\<circ>\n      )\"\n    and \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>CId\\<rparr> =\n      (\n        \\<lambda>A\\<in>\\<^sub>\\<circ>cat_comma_Obj \\<GG> \\<HH>.\n          [A, A, [\\<GG>\\<lparr>HomDom\\<rparr>\\<lparr>CId\\<rparr>\\<lparr>A\\<lparr>0\\<rparr>\\<rparr>, \\<HH>\\<lparr>HomDom\\<rparr>\\<lparr>CId\\<rparr>\\<lparr>A\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<rparr>]\\<^sub>\\<circ>]\\<^sub>\\<circ>\n      )\"\n  unfolding cat_comma_def dg_field_simps by (simp_all add: nat_omega_simps)\n\ncontext\n  fixes \\<alpha> \\<AA> \\<BB> \\<CC> \\<GG> \\<HH>\n  assumes \\<GG>: \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \\<HH>: \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\nbegin\n\ninterpretation \\<GG>: is_functor \\<alpha> \\<AA> \\<CC> \\<GG> by (rule \\<GG>)\ninterpretation \\<HH>: is_functor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule \\<HH>)\n\nlemma cat_comma_Obj_def':\n  \"cat_comma_Obj \\<GG> \\<HH> \\<equiv> set\n    {\n      [a, b, f]\\<^sub>\\<circ> | a b f.\n        a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr> \\<and> b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr> \\<and> f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\n    }\"\n  unfolding cat_comma_Obj_def cat_cs_simps by simp\n\nlemma cat_comma_Hom_def':\n  \"cat_comma_Hom \\<GG> \\<HH> A B \\<equiv> set\n    {\n      [A, B, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ> | g h.\n        A \\<in>\\<^sub>\\<circ> cat_comma_Obj \\<GG> \\<HH> \\<and>\n        B \\<in>\\<^sub>\\<circ> cat_comma_Obj \\<GG> \\<HH> \\<and>\n        g : A\\<lparr>0\\<rparr> \\<mapsto>\\<^bsub>\\<AA>\\<^esub> B\\<lparr>0\\<rparr> \\<and>\n        h : A\\<lparr>1\\<^sub>\\<nat>\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> B\\<lparr>1\\<^sub>\\<nat>\\<rparr> \\<and>\n        B\\<lparr>2\\<^sub>\\<nat>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> A\\<lparr>2\\<^sub>\\<nat>\\<rparr>\n    }\"\n  unfolding cat_comma_Hom_def cat_cs_simps by simp\n\nlemma cat_comma_components':\n  shows \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr> = cat_comma_Obj \\<GG> \\<HH>\"\n    and \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr> = cat_comma_Arr \\<GG> \\<HH>\"\n    and \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Dom\\<rparr> = (\\<lambda>F\\<in>\\<^sub>\\<circ>cat_comma_Arr \\<GG> \\<HH>. F\\<lparr>0\\<rparr>)\"\n    and \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Cod\\<rparr> = (\\<lambda>F\\<in>\\<^sub>\\<circ>cat_comma_Arr \\<GG> \\<HH>. F\\<lparr>1\\<^sub>\\<nat>\\<rparr>)\"\n    and \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Comp\\<rparr> =\n      (\n        \\<lambda>GF\\<in>\\<^sub>\\<circ>cat_comma_composable \\<GG> \\<HH>.\n          [\n            GF\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>0\\<rparr>,\n            GF\\<lparr>0\\<rparr>\\<lparr>1\\<^sub>\\<nat>\\<rparr>,\n            [\n              GF\\<lparr>0\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr>\\<lparr>0\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> GF\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr>\\<lparr>0\\<rparr>,\n              GF\\<lparr>0\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr>\\<lparr>1\\<^sub>\\<nat>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> GF\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr>\\<lparr>1\\<^sub>\\<nat>\\<rparr>\n            ]\\<^sub>\\<circ>\n          ]\\<^sub>\\<circ>\n      )\"\n    and \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>CId\\<rparr> =\n      (\\<lambda>A\\<in>\\<^sub>\\<circ>cat_comma_Obj \\<GG> \\<HH>. [A, A, [\\<AA>\\<lparr>CId\\<rparr>\\<lparr>A\\<lparr>0\\<rparr>\\<rparr>, \\<BB>\\<lparr>CId\\<rparr>\\<lparr>A\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<rparr>]\\<^sub>\\<circ>]\\<^sub>\\<circ>)\"\n  unfolding cat_comma_components cat_cs_simps by simp_all\n\nend\n\n\nsubsubsection\\<open>Objects\\<close>\n\nlemma cat_comma_ObjI[cat_comma_cs_intros]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"A = [a, b, f]\\<^sub>\\<circ>\"\n    and \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n    and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" \n    and \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n  shows \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n  using assms(4-6) \n  unfolding cat_comma_Obj_def'[OF assms(1,2)] assms(3) cat_comma_components \n  by simp\n\nlemma cat_comma_ObjD[dest]:\n  assumes \"[a, b, f]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n    and \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n    and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" \n    and \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n  using assms\n  unfolding \n    cat_comma_components'[OF assms(2,3)] cat_comma_Obj_def'[OF assms(2,3)] \n  by auto\n\nlemma cat_comma_ObjE[elim]:\n  assumes \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n    and \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  obtains a b f where \"A = [a, b, f]\\<^sub>\\<circ>\"\n    and \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n    and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" \n    and \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n  using assms\n  unfolding \n    cat_comma_components'[OF assms(2,3)] cat_comma_Obj_def'[OF assms(2,3)] \n  by auto\n\n\nsubsubsection\\<open>Arrows\\<close>\n\nlemma cat_comma_HomI[cat_comma_cs_intros]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"F = [A, B, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n    and \"A = [a, b, f]\\<^sub>\\<circ>\"\n    and \"B = [a', b', f']\\<^sub>\\<circ>\"\n    and \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n    and \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n    and \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n    and \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n    and \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\n  shows \"F \\<in>\\<^sub>\\<circ> cat_comma_Hom \\<GG> \\<HH> A B\"\n  using assms(1,2,6-10)\n  unfolding cat_comma_Hom_def'[OF assms(1,2)] assms(3-5)\n  by \n    (\n      intro in_set_CollectI exI conjI small_cat_comma_Hom, \n      unfold cat_comma_components'(1,2)[OF assms(1,2), symmetric],\n      (\n        cs_concl \n          cs_simp: cat_comma_cs_simps \n          cs_intro: cat_cs_intros cat_comma_cs_intros\n      )+\n    )\n    (clarsimp simp: nat_omega_simps)+\n\nlemma cat_comma_HomE[elim]:\n  assumes \"F \\<in>\\<^sub>\\<circ> cat_comma_Hom \\<GG> \\<HH> A B\"\n    and \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  obtains a b f a' b' f' g h\n    where \"F = [A, B, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and \"A = [a, b, f]\\<^sub>\\<circ>\"\n      and \"B = [a', b', f']\\<^sub>\\<circ>\"\n      and \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n      and \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n      and \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n      and \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n      and \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\n  using assms(1) \n  by \n    (\n      unfold\n        cat_comma_components'[OF assms(2,3)] cat_comma_Hom_def'[OF assms(2,3)],\n      elim in_small_setE; \n      (unfold mem_Collect_eq, elim exE conjE cat_comma_ObjE[OF _ assms(2,3)])?,\n      insert that,\n      all\\<open>\n        (unfold cat_comma_components'(1,2)[OF assms(2,3), symmetric],\n        elim cat_comma_ObjE[OF _ assms(2,3)]) | -\n        \\<close>\n    )\n    (auto simp: nat_omega_simps)\n\nlemma cat_comma_HomD[dest]:\n  assumes \"[[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> cat_comma_Hom \\<GG> \\<HH> A B\"\n    and \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n    and \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n    and \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n    and \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n    and \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\n  using assms(1) by (force elim!: cat_comma_HomE[OF _ assms(2,3)])+\n\nlemma cat_comma_ArrI[cat_comma_cs_intros]: \n  assumes \"F \\<in>\\<^sub>\\<circ> cat_comma_Hom \\<GG> \\<HH> A B\"\n    and \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n    and \"B \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n  shows \"F \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n  using assms \n  unfolding cat_comma_components cat_comma_Arr_def \n  by (intro vifunionI)\n\nlemma cat_comma_ArrE[elim]:\n  assumes \"F \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n  obtains A B \n    where \"F \\<in>\\<^sub>\\<circ> cat_comma_Hom \\<GG> \\<HH> A B\"\n      and \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n      and \"B \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n  using assms unfolding cat_comma_components cat_comma_Arr_def by auto\n\nlemma cat_comma_ArrD[dest]: \n  assumes \"[A, B, F]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n    and \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"[A, B, F]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> cat_comma_Hom \\<GG> \\<HH> A B\"\n    and \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n    and \"B \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\nproof-\n  from assms obtain C D \n    where \"[A, B, F]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> cat_comma_Hom \\<GG> \\<HH> C D\"\n      and \"C \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n      and \"D \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n    by (elim cat_comma_ArrE)\n  moreover from cat_comma_HomE[OF this(1) assms(2,3)] have \"A = C\" and \"B = D\"\n    by auto\n  ultimately show \"[A, B, F]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> cat_comma_Hom \\<GG> \\<HH> A B\"\n    and \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n    and \"B \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n    by auto\nqed\n\n\nsubsubsection\\<open>Domain\\<close>\n\nlemma cat_comma_Dom_vsv[cat_comma_cs_intros]: \"vsv (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Dom\\<rparr>)\"\n  unfolding cat_comma_components by simp\n\nlemma cat_comma_Dom_vdomain[cat_comma_cs_simps]:\n  \"\\<D>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Dom\\<rparr>) = \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n  unfolding cat_comma_components by simp\n\nlemma cat_comma_Dom_app[cat_comma_cs_simps]:\n  assumes \"ABF = [A, B, F]\\<^sub>\\<circ>\" and \"ABF \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n  shows \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Dom\\<rparr>\\<lparr>ABF\\<rparr> = A\"\n  using assms(2) unfolding assms(1) cat_comma_components by simp\n\nlemma cat_comma_Dom_vrange:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"\\<R>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Dom\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\nproof(rule vsv.vsv_vrange_vsubset)\n  fix ABF assume \"ABF \\<in>\\<^sub>\\<circ> \\<D>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Dom\\<rparr>)\"\n  then have \"ABF \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\" \n    by (cs_prems cs_shallow cs_simp: cat_comma_cs_simps)\n  then obtain A B \n    where ABF: \"ABF \\<in>\\<^sub>\\<circ> cat_comma_Hom \\<GG> \\<HH> A B\"\n      and A: \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n      and B: \"B \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n    by auto\n  from this(1) obtain a b f a' b' f' g h\n    where \"ABF = [A, B, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and \"A = [a, b, f]\\<^sub>\\<circ>\"\n      and \"B = [a', b', f']\\<^sub>\\<circ>\"\n      and \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n      and \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n      and \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n      and \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n      and \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\n    by (elim cat_comma_HomE[OF _ assms(1,2)])\n  from ABF this A B show \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Dom\\<rparr>\\<lparr>ABF\\<rparr> \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n    by \n      (\n        cs_concl cs_shallow \n          cs_simp: cat_comma_cs_simps cs_intro: cat_comma_cs_intros\n      )\nqed (auto intro: cat_comma_cs_intros)\n\n\nsubsubsection\\<open>Codomain\\<close>\n\nlemma cat_comma_Cod_vsv[cat_comma_cs_intros]: \"vsv (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Cod\\<rparr>)\"\n  unfolding cat_comma_components by simp\n\nlemma cat_comma_Cod_vdomain[cat_comma_cs_simps]:\n  \"\\<D>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Cod\\<rparr>) = \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n  unfolding cat_comma_components by simp\n\nlemma cat_comma_Cod_app[cat_comma_cs_simps]:\n  assumes \"ABF = [A, B, F]\\<^sub>\\<circ>\" and \"ABF \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n  shows \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Cod\\<rparr>\\<lparr>ABF\\<rparr> = B\"\n  using assms(2)\n  unfolding assms(1) cat_comma_components\n  by (simp add: nat_omega_simps)\n\nlemma cat_comma_Cod_vrange:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"\\<R>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Cod\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\nproof(rule vsv.vsv_vrange_vsubset)\n  fix ABF assume \"ABF \\<in>\\<^sub>\\<circ> \\<D>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Cod\\<rparr>)\"\n  then have \"ABF \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\" \n    by (cs_prems cs_shallow cs_simp: cat_comma_cs_simps)\n  then obtain A B \n    where F: \"ABF \\<in>\\<^sub>\\<circ> cat_comma_Hom \\<GG> \\<HH> A B\"\n      and A: \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n      and B: \"B \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n    by auto\n  from this(1) obtain a b f a' b' f' g h\n    where \"ABF = [A, B, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and \"A = [a, b, f]\\<^sub>\\<circ>\"\n      and \"B = [a', b', f']\\<^sub>\\<circ>\"\n      and \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n      and \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n      and \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n      and \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n      and \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\n    by (elim cat_comma_HomE[OF _ assms(1,2)])\n  from F this A B show \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Cod\\<rparr>\\<lparr>ABF\\<rparr> \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n    by \n      (\n        cs_concl cs_shallow \n          cs_simp: cat_comma_cs_simps cs_intro: cat_comma_cs_intros\n      )\nqed (auto intro: cat_comma_cs_intros)\n\n\nsubsubsection\\<open>Arrow with a domain and a codomain\\<close>\n\nlemma cat_comma_is_arrI[cat_comma_cs_intros]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"ABF = [A, B, F]\\<^sub>\\<circ>\"\n    and \"A = [a, b, f]\\<^sub>\\<circ>\"\n    and \"B = [a', b', f']\\<^sub>\\<circ>\"\n    and \"F = [g, h]\\<^sub>\\<circ>\"\n    and \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n    and \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n    and \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n    and \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n    and \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\n  shows \"ABF : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\"\nproof(intro is_arrI)\n  interpret \\<GG>: is_functor \\<alpha> \\<AA> \\<CC> \\<GG> by (rule assms(1))\n  interpret \\<HH>: is_functor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule assms(2))\n  from assms(7-11) show \"ABF \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n    unfolding assms(3-6)\n    by \n      (\n        cs_concl  \n          cs_simp: cat_comma_cs_simps \n          cs_intro: cat_cs_intros cat_comma_cs_intros\n      )\n  with assms(7-11) show \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Dom\\<rparr>\\<lparr>ABF\\<rparr> = A\" \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Cod\\<rparr>\\<lparr>ABF\\<rparr> = B\"\n    unfolding assms(3-6) by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps)+\nqed\n\nlemma cat_comma_is_arrD[dest]:\n  assumes \"[[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ> :\n    [a, b, f]\\<^sub>\\<circ> \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> [a', b', f']\\<^sub>\\<circ>\"\n    and \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n    and \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n    and \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n    and \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n    and \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\nproof-\n  note F_is_arrD = is_arrD[OF assms(1)]\n  note F_cat_comma_ArrD = cat_comma_ArrD[OF F_is_arrD(1) assms(2,3)]\n  show \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n    and \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n    and \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n    and \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n    and \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\n    by (intro cat_comma_HomD[OF F_cat_comma_ArrD(1) assms(2,3)])+    \nqed\n\nlemma cat_comma_is_arrE[elim]:\n  assumes \"ABF : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\"\n    and \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  obtains a b f a' b' f' g h\n    where \"ABF = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and \"A = [a, b, f]\\<^sub>\\<circ>\"\n      and \"B = [a', b', f']\\<^sub>\\<circ>\"\n      and \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n      and \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n      and \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n      and \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n      and \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\nproof-\n  note F_is_arrD = is_arrD[OF assms(1)]\n  from F_is_arrD(1) obtain C D \n    where \"ABF \\<in>\\<^sub>\\<circ> cat_comma_Hom \\<GG> \\<HH> C D\"\n      and \"C \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\" \n      and \"D \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n    by auto\n  from this(1) obtain a b f a' b' f' g h\n    where F_def: \"ABF = [C, D, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and \"C = [a, b, f]\\<^sub>\\<circ>\"\n      and \"D = [a', b', f']\\<^sub>\\<circ>\"\n      and \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n      and \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n      and \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n      and \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n      and \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\n     by (elim cat_comma_HomE[OF _ assms(2,3)])\n  with that show ?thesis \n    by (metis F_is_arrD(1,2,3) cat_comma_Cod_app cat_comma_Dom_app)\nqed\n\n\nsubsubsection\\<open>Composition\\<close>\n\nlemma cat_comma_composableI:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"ABCGF = [BCG, ABF]\\<^sub>\\<circ>\"\n    and \"BCG : B \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> C\"\n    and \"ABF : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\"\n  shows \"ABCGF \\<in>\\<^sub>\\<circ> cat_comma_composable \\<GG> \\<HH>\"\nproof-\n  from assms(1,2,5) obtain a b f a' b' f' gh \n    where ABF_def: \"ABF = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, gh]\\<^sub>\\<circ>\"\n      and \"A = [a, b, f]\\<^sub>\\<circ>\"\n      and  \"B = [a', b', f']\\<^sub>\\<circ>\"\n    by auto\n  with assms(1,2,4) obtain a'' b'' f'' g'h' \n    where BCG_def: \"BCG = [[a', b', f']\\<^sub>\\<circ>, [a'', b'', f'']\\<^sub>\\<circ>, g'h']\\<^sub>\\<circ>\"\n      and \"B = [a', b', f']\\<^sub>\\<circ>\"\n      and \"C = [a'', b'', f'']\\<^sub>\\<circ>\"\n    by auto\n  from is_arrD(1)[OF assms(4)] have \"BCG \\<in>\\<^sub>\\<circ> cat_comma_Arr \\<GG> \\<HH>\"\n    unfolding cat_comma_components'(2)[OF assms(1,2)].\n  moreover from is_arrD(1)[OF assms(5)] have \"ABF \\<in>\\<^sub>\\<circ> cat_comma_Arr \\<GG> \\<HH>\"\n    unfolding cat_comma_components'(2)[OF assms(1,2)].\n  ultimately show ?thesis \n    unfolding assms(3) ABF_def BCG_def cat_comma_composable_def \n    by simp\nqed\n\nlemma cat_comma_composableE[elim]:\n  assumes \"ABCGF \\<in>\\<^sub>\\<circ> cat_comma_composable \\<GG> \\<HH>\"\n    and \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  obtains BCG ABF A B C\n    where \"ABCGF = [BCG, ABF]\\<^sub>\\<circ>\"\n      and \"BCG : B \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> C\"\n      and \"ABF : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\"\nproof-\n  from assms(1) obtain A B C G F \n    where ABCGF_def: \"ABCGF = [[B, C, G]\\<^sub>\\<circ>, [A, B, F]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and BCG: \"[B, C, G]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n      and ABF: \"[A, B, F]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n    unfolding cat_comma_composable_def\n    by (auto simp: cat_comma_components'[OF assms(2,3)])  \n  note BCG = cat_comma_ArrD[OF BCG assms(2,3)]\n    and ABF = cat_comma_ArrD[OF ABF assms(2,3)]\n  from ABF(1) assms(2,3) obtain a b f a' b' f' g h\n    where \"[A, B, F]\\<^sub>\\<circ> = [A, B, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and A_def: \"A = [a, b, f]\\<^sub>\\<circ>\"\n      and B_def: \"B = [a', b', f']\\<^sub>\\<circ>\"\n      and F_def: \"F = [g, h]\\<^sub>\\<circ>\"\n      and g: \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n      and h: \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n      and f: \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n      and f': \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n      and [cat_comma_cs_simps]: \n        \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\n    by auto\n  with BCG(1) assms(2,3) obtain a'' b'' f'' g' h'\n    where g'h'_def: \"[B, C, G]\\<^sub>\\<circ> = [B, C, [g', h']\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and C_def: \"C = [a'', b'', f'']\\<^sub>\\<circ>\"\n      and G_def: \"G = [g', h']\\<^sub>\\<circ>\"\n      and g': \"g' : a' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a''\"\n      and h': \"h' : b' \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b''\"\n      and f'': \"f'' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a''\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b''\\<rparr>\"\n      and [cat_comma_cs_simps]: \n        \"f'' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g'\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f'\"\n    by auto  \n  from F_def have \"F = [g, h]\\<^sub>\\<circ>\" by simp\n  from assms(2,3) g h f f' g' h' f'' have \n    \"[B, C, G]\\<^sub>\\<circ> : B \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> C\"\n    unfolding ABCGF_def F_def G_def A_def B_def C_def\n    by \n      (\n        cs_concl cs_shallow \n          cs_simp: cat_comma_cs_simps cs_intro: cat_comma_is_arrI\n      )+\n  moreover from assms(2,3) g h f f' g' h' f'' have \n    \"[A, B, F]\\<^sub>\\<circ> : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\"\n    unfolding ABCGF_def F_def G_def A_def B_def C_def\n    by \n      (\n        cs_concl cs_shallow \n          cs_simp: cat_comma_cs_simps cs_intro: cat_comma_is_arrI\n      )+\n  ultimately show ?thesis using that ABCGF_def by auto\nqed\n\nlemma cat_comma_Comp_vsv[cat_comma_cs_intros]: \"vsv (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Comp\\<rparr>)\"\n  unfolding cat_comma_components by auto\n\nlemma cat_comma_Comp_vdomain[cat_comma_cs_simps]: \n  \"\\<D>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Comp\\<rparr>) = cat_comma_composable \\<GG> \\<HH>\"\n  unfolding cat_comma_components by auto\n\nlemma cat_comma_Comp_app[cat_comma_cs_simps]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"G = [B, C, [g', h']\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n    and \"F = [A, B, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n    and \"G : B \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> C\" \n    and \"F : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\"\n  shows \"G \\<circ>\\<^sub>A\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> F = [A, C, [g' \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> g, h' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n  using assms(1,2,5,6)\n  unfolding cat_comma_components'[OF assms(1,2)] assms(3,4)\n  by (*slow*)\n    (\n      cs_concl \n        cs_simp: omega_of_set V_cs_simps vfsequence_simps\n        cs_intro: nat_omega_intros V_cs_intros cat_comma_composableI TrueI\n    )\n\nlemma cat_comma_Comp_is_arr[cat_comma_cs_intros]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"BCG : B \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> C\" \n    and \"ABF : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\"\n  shows \"BCG \\<circ>\\<^sub>A\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> ABF : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> C\"\nproof-\n  interpret \\<GG>: is_functor \\<alpha> \\<AA> \\<CC> \\<GG> by (rule assms(1))\n  interpret \\<HH>: is_functor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule assms(2))\n  from assms(1,2,4) obtain a b f a' b' f' g h\n    where ABF_def: \"ABF = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and A_def: \"A = [a, b, f]\\<^sub>\\<circ>\"\n      and B_def: \"B = [a', b', f']\\<^sub>\\<circ>\"\n      and g: \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n      and h: \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n      and f: \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n      and f': \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n      and [symmetric, cat_cs_simps]: \n        \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\n    by auto\n  with assms(1,2,3) obtain a'' b'' f'' g' h'\n    where BCG_def: \"BCG = [[a', b', f']\\<^sub>\\<circ>, [a'', b'', f'']\\<^sub>\\<circ>, [g', h']\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and C_def: \"C = [a'', b'', f'']\\<^sub>\\<circ>\"\n      and g': \"g' : a' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a''\"\n      and h': \"h' : b' \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b''\"\n      and f'': \"f'' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a''\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b''\\<rparr>\"\n      and [cat_cs_simps]: \"f'' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g'\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f'\"\n    by auto (*slow*)\n  from g' have \\<GG>g': \"\\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g'\\<rparr> : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a''\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  note [cat_cs_simps] = \n    category.cat_assoc_helper[\n      where \\<CC>=\\<CC> and h=f'' and g=\\<open>\\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g'\\<rparr>\\<close> and q=\\<open>\\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f'\\<close>\n      ]\n    category.cat_assoc_helper[\n      where \\<CC>=\\<CC> and h=f and g=\\<open>\\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr>\\<close> and q=\\<open>f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr>\\<close>\n      ]\n  from assms(1,2,3,4) g h f f' g' h' f'' show ?thesis\n    unfolding ABF_def BCG_def A_def B_def C_def\n    by (intro cat_comma_is_arrI[OF assms(1,2)])\n      (\n        cs_concl cs_shallow\n          cs_simp: cat_cs_simps cat_comma_cs_simps cs_intro: cat_cs_intros\n      )+\nqed\n\n\nsubsubsection\\<open>Identity\\<close>\n\nlemma cat_comma_CId_vsv[cat_comma_cs_intros]: \"vsv (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>CId\\<rparr>)\"\n  unfolding cat_comma_components by simp\n\nlemma cat_comma_CId_vdomain[cat_comma_cs_simps]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"\\<D>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>CId\\<rparr>) = \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n  unfolding cat_comma_components'[OF assms(1,2)] by simp\n\nlemma cat_comma_CId_app[cat_comma_cs_simps]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"A = [a, b ,f]\\<^sub>\\<circ>\"\n    and \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>CId\\<rparr>\\<lparr>A\\<rparr> = [A, A, [\\<AA>\\<lparr>CId\\<rparr>\\<lparr>a\\<rparr>, \\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\nproof-\n  from assms(4)[unfolded assms(3), unfolded cat_comma_components'[OF assms(1,2)]]\n  have \"[a, b, f]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> cat_comma_Obj \\<GG> \\<HH>\".\n  then show ?thesis\n    unfolding cat_comma_components'(6)[OF assms(1,2)] assms(3)\n    by (simp add: nat_omega_simps)\nqed\n\n\nsubsubsection\\<open>\\<open>Hom\\<close>-set\\<close>\n\nlemma cat_comma_Hom:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n    and \"B \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n  shows \"Hom (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>) A B = cat_comma_Hom \\<GG> \\<HH> A B\"\nproof(intro vsubset_antisym vsubsetI, unfold in_Hom_iff)\n  fix ABF assume \"ABF : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\"\n  with assms(1,2) show \"ABF \\<in>\\<^sub>\\<circ> cat_comma_Hom \\<GG> \\<HH> A B\"\n    by (elim cat_comma_is_arrE[OF _ assms(1,2)], intro cat_comma_HomI) force+\nnext\n  fix ABF assume \"ABF \\<in>\\<^sub>\\<circ> cat_comma_Hom \\<GG> \\<HH> A B\"\n  with assms(1,2) show \"ABF : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\"\n    by (elim cat_comma_HomE[OF _ assms(1,2)], intro cat_comma_is_arrI) force+\nqed\n\n\nsubsubsection\\<open>Comma category is a category\\<close>\n\nlemma category_cat_comma[cat_comma_cs_intros]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"category \\<alpha> (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>)\"\nproof-\n\n  interpret \\<GG>: is_functor \\<alpha> \\<AA> \\<CC> \\<GG> by (rule assms(1))\n  interpret \\<FF>: is_functor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule assms(2))\n\n  show ?thesis\n  proof(rule categoryI')\n\n    show \"vfsequence (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>)\" unfolding cat_comma_def by auto\n    show \"vcard (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>) = 6\\<^sub>\\<nat>\"\n      unfolding cat_comma_def by (simp add: nat_omega_simps)\n    show \"\\<R>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Dom\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n      by (rule cat_comma_Dom_vrange[OF assms])\n    show \"\\<R>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Cod\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n      by (rule cat_comma_Cod_vrange[OF assms])\n    show \"(GF \\<in>\\<^sub>\\<circ> \\<D>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Comp\\<rparr>)) \\<longleftrightarrow>\n      (\\<exists>g f b c a. GF = [g, f]\\<^sub>\\<circ> \\<and> g : b \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> c \\<and> f : a \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> b)\"\n      for GF\n    proof(intro iffI; (elim exE conjE)?; (simp only: cat_comma_Comp_vdomain)?)\n      assume prems: \"GF \\<in>\\<^sub>\\<circ> cat_comma_composable \\<GG> \\<HH>\"\n      with assms obtain G F abf a'b'f' a''b''f'' \n        where \"GF = [G, F]\\<^sub>\\<circ>\"\n          and \"G : a'b'f' \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> a''b''f''\"\n          and \"F : abf \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> a'b'f'\"\n        by auto\n      with assms show \"\\<exists>g f b c a.\n        GF = [g, f]\\<^sub>\\<circ> \\<and> g : b \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> c \\<and> f : a \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> b\"\n        by auto\n    qed (use assms in \\<open>cs_concl cs_shallow cs_intro: cat_comma_composableI\\<close>)\n    from assms show \"\\<D>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>CId\\<rparr>) = \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n      by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps)\n    from assms show \"G \\<circ>\\<^sub>A\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> F : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> C\"\n      if \"G : B \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> C\" and \"F : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\"\n      for B C G A F\n      using that by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)\n    from assms show \n      \"H \\<circ>\\<^sub>A\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> G \\<circ>\\<^sub>A\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> F =\n        H \\<circ>\\<^sub>A\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> (G \\<circ>\\<^sub>A\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> F)\"\n      if \"H : C \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> D\"\n        and \"G : B \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> C\"\n        and \"F : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\"\n      for C D H B G A F\n      using assms that\n    proof-\n      from that(3) assms obtain a b f a' b' f' g h\n        where F_def: \"F = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n          and A_def: \"A = [a, b, f]\\<^sub>\\<circ>\"\n          and B_def: \"B = [a', b', f']\\<^sub>\\<circ>\"\n          and g: \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n          and h: \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n          and f: \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n          and f': \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n          and [cat_cs_simps]: \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\n        by auto\n      with that(2) assms obtain a'' b'' f'' g' h'\n        where G_def: \"G = [[a', b', f']\\<^sub>\\<circ>, [a'', b'', f'']\\<^sub>\\<circ>, [g', h']\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n          and C_def: \"C = [a'', b'', f'']\\<^sub>\\<circ>\"\n          and g': \"g' : a' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a''\"\n          and h': \"h' : b' \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b''\"\n          and f'': \"f'' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a''\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b''\\<rparr>\"\n          and [cat_cs_simps]: \n            \"f'' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g'\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f'\"\n        by auto (*slow*)\n      with that(1) assms obtain a''' b''' f''' g'' h''\n        where H_def: \"H = [[a'', b'', f'']\\<^sub>\\<circ>, [a''', b''', f''']\\<^sub>\\<circ>, [g'', h'']\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n          and D_def: \"D = [a''', b''', f''']\\<^sub>\\<circ>\"\n          and g'': \"g'' : a'' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'''\"\n          and h'': \"h'' : b'' \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'''\"\n          and f''': \"f''' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'''\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'''\\<rparr>\"\n          and [cat_cs_simps]: \n            \"f''' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g''\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h''\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f''\"\n        by auto (*slow*)      \n      note [cat_cs_simps] =\n        category.cat_assoc_helper[\n          where \\<CC>=\\<CC>\n            and h=f''\n            and g=\\<open>\\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g'\\<rparr>\\<close>\n            and q=\\<open>\\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f'\\<close>\n          ]\n        category.cat_assoc_helper[\n          where \\<CC>=\\<CC>\n            and h=f''\n            and g=\\<open>\\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g'\\<rparr>\\<close>\n            and q=\\<open>\\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f'\\<close>\n          ]\n        category.cat_assoc_helper[\n          where \\<CC>=\\<CC> \n            and h=f''' \n            and g=\\<open>\\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g''\\<rparr>\\<close> \n            and q=\\<open>\\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h''\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f''\\<close>\n          ]\n      from assms that g h f f' g' h' f'' g'' h''  f''' show ?thesis\n        unfolding F_def G_def H_def A_def B_def C_def D_def\n        by\n          (\n            cs_concl cs_shallow\n              cs_simp: cat_cs_simps cat_comma_cs_simps \n              cs_intro: cat_cs_intros cat_comma_cs_intros\n          )\n    qed\n\n    show \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>CId\\<rparr>\\<lparr>A\\<rparr> : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> A\"\n      if \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\" for A\n      using that\n      by (elim cat_comma_ObjE[OF _ assms(1)]; (simp only:)?) \n        (\n          cs_concl cs_shallow\n            cs_simp: cat_cs_simps cat_comma_cs_simps \n            cs_intro: cat_cs_intros cat_comma_cs_intros\n        )+\n\n    show \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>CId\\<rparr>\\<lparr>B\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> F = F\"\n      if \"F : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\" for A B F\n      using that \n      by (elim cat_comma_is_arrE[OF _ assms]; (simp only:)?)\n        (\n          cs_concl cs_shallow\n            cs_simp: cat_cs_simps cat_comma_cs_simps \n            cs_intro: cat_cs_intros cat_comma_cs_intros\n        )+\n\n    show \"F \\<circ>\\<^sub>A\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>CId\\<rparr>\\<lparr>B\\<rparr> = F\"\n      if \"F : B \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> C\" for B C F\n      using that \n      by (elim cat_comma_is_arrE[OF _ assms]; (simp only:)?)\n        (\n          cs_concl \n            cs_simp: cat_cs_simps cat_comma_cs_simps \n            cs_intro: cat_cs_intros cat_comma_cs_intros\n        )+\n\n    show \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr> \\<subseteq>\\<^sub>\\<circ> Vset \\<alpha>\"\n    proof(intro vsubsetI, elim cat_comma_ObjE[OF _ assms])\n      fix F a b f assume prems: \n        \"F = [a, b, f]\\<^sub>\\<circ>\" \n        \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n        \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n        \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n      from prems(2-4) show \"F \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n        unfolding prems(1) by (cs_concl cs_intro: cat_cs_intros V_cs_intros) \n    qed\n\n    show \"(\\<Union>\\<^sub>\\<circ>a\\<in>\\<^sub>\\<circ>A. \\<Union>\\<^sub>\\<circ>b\\<in>\\<^sub>\\<circ>B. Hom (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>) a b) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n      if \"A \\<subseteq>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n        and \"B \\<subseteq>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n        and \"A \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n        and \"B \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n      for A B\n    proof-\n\n      define A0 where \"A0 = \\<R>\\<^sub>\\<circ> (\\<lambda>F\\<in>\\<^sub>\\<circ>A. F\\<lparr>0\\<rparr>)\"\n      define A1 where \"A1 = \\<R>\\<^sub>\\<circ> (\\<lambda>F\\<in>\\<^sub>\\<circ>A. F\\<lparr>1\\<^sub>\\<nat>\\<rparr>)\"\n      define B0 where \"B0 = \\<R>\\<^sub>\\<circ> (\\<lambda>F\\<in>\\<^sub>\\<circ>B. F\\<lparr>0\\<rparr>)\"\n      define B1 where \"B1 = \\<R>\\<^sub>\\<circ> (\\<lambda>F\\<in>\\<^sub>\\<circ>B. F\\<lparr>1\\<^sub>\\<nat>\\<rparr>)\"\n\n      define A0B0 where \"A0B0 = (\\<Union>\\<^sub>\\<circ>a\\<in>\\<^sub>\\<circ>A0. \\<Union>\\<^sub>\\<circ>b\\<in>\\<^sub>\\<circ>B0. Hom \\<AA> a b)\"\n      define A1B1 where \"A1B1 = (\\<Union>\\<^sub>\\<circ>a\\<in>\\<^sub>\\<circ>A1. \\<Union>\\<^sub>\\<circ>b\\<in>\\<^sub>\\<circ>B1. Hom \\<BB> a b)\"\n\n      have A0B0: \"A0B0 \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n        unfolding A0B0_def\n      proof(rule \\<GG>.HomDom.cat_Hom_vifunion_in_Vset; (intro vsubsetI)?)\n        show \"A0 \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n          unfolding A0_def\n        proof(intro vrange_vprojection_in_VsetI that(3))\n          fix F assume \"F \\<in>\\<^sub>\\<circ> A\"\n          with that(1) have \"F \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\" by auto\n          with assms obtain a b f where F_def: \"F = [a, b, f]\\<^sub>\\<circ>\" by auto\n          show \"vsv F\" unfolding F_def by auto\n          show \"0 \\<in>\\<^sub>\\<circ> \\<D>\\<^sub>\\<circ> F\" unfolding F_def by simp\n        qed auto\n        show \"B0 \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n          unfolding B0_def\n        proof(intro vrange_vprojection_in_VsetI that(4))\n          fix F assume \"F \\<in>\\<^sub>\\<circ> B\"\n          with that(2) have \"F \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\" by auto\n          with assms obtain a b f where F_def: \"F = [a, b, f]\\<^sub>\\<circ>\" by auto\n          show \"vsv F\" unfolding F_def by auto\n          show \"0 \\<in>\\<^sub>\\<circ> \\<D>\\<^sub>\\<circ> F\" unfolding F_def by simp\n        qed auto\n      next\n        fix a assume \"a \\<in>\\<^sub>\\<circ> A0\"\n        with that(1) obtain F \n          where a_def: \"a = F\\<lparr>0\\<rparr>\" and \"F \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\" \n          unfolding A0_def by force\n        with assms obtain b f where \"F = [a, b, f]\\<^sub>\\<circ>\" and \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" by auto\n        then show \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" unfolding a_def by simp\n      next\n        fix a assume \"a \\<in>\\<^sub>\\<circ> B0\"\n        with that(2) obtain F \n          where a_def: \"a = F\\<lparr>0\\<rparr>\" and \"F \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\" \n          unfolding B0_def by force\n        with assms obtain b f where \"F = [a, b, f]\\<^sub>\\<circ>\" and \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" by auto\n        then show \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" unfolding a_def by simp\n      qed\n\n      have A1B1: \"A1B1 \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n        unfolding A1B1_def\n      proof(rule \\<FF>.HomDom.cat_Hom_vifunion_in_Vset; (intro vsubsetI)?)\n        show \"A1 \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n          unfolding A1_def\n        proof(intro vrange_vprojection_in_VsetI that(3))\n          fix F assume \"F \\<in>\\<^sub>\\<circ> A\"\n          with that(1) have \"F \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\" by auto\n          with assms obtain a b f where F_def: \"F = [a, b, f]\\<^sub>\\<circ>\" by auto\n          show \"vsv F\" unfolding F_def by auto\n          show \"1\\<^sub>\\<nat> \\<in>\\<^sub>\\<circ> \\<D>\\<^sub>\\<circ> F\" unfolding F_def by (simp add: nat_omega_simps)\n        qed auto\n        show \"B1 \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n          unfolding B1_def\n        proof(intro vrange_vprojection_in_VsetI that(4))\n          fix F assume \"F \\<in>\\<^sub>\\<circ> B\"\n          with that(2) have \"F \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\" by auto\n          with assms obtain a b f where F_def: \"F = [a, b, f]\\<^sub>\\<circ>\" by auto\n          show \"vsv F\" unfolding F_def by auto\n          show \"1\\<^sub>\\<nat> \\<in>\\<^sub>\\<circ> \\<D>\\<^sub>\\<circ> F\" unfolding F_def by (simp add: nat_omega_simps)\n        qed auto\n      next\n        fix b assume \"b \\<in>\\<^sub>\\<circ> A1\"\n        with that(1) obtain F \n          where b_def: \"b = F\\<lparr>1\\<^sub>\\<nat>\\<rparr>\" and \"F \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\" \n          unfolding A1_def by force\n        with assms obtain a f where \"F = [a, b, f]\\<^sub>\\<circ>\" and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" \n          by (auto simp: nat_omega_simps)\n        then show \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" unfolding b_def by simp\n      next\n        fix b assume \"b \\<in>\\<^sub>\\<circ> B1\"\n        with that(2) obtain F \n          where b_def: \"b = F\\<lparr>1\\<^sub>\\<nat>\\<rparr>\" and \"F \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\" \n          unfolding B1_def by force\n        with assms obtain a f where \"F = [a, b, f]\\<^sub>\\<circ>\" and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" \n          by (auto simp: nat_omega_simps)\n        then show \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" unfolding b_def by simp\n      qed\n      \n      define Q where \n        \"Q i = (if i = 0 then A else if i = 1\\<^sub>\\<nat> then B else (A0B0 \\<times>\\<^sub>\\<bullet> A1B1))\" \n        for i\n      have \n        \"(\\<Union>\\<^sub>\\<circ>a\\<in>\\<^sub>\\<circ>A. \\<Union>\\<^sub>\\<circ>b\\<in>\\<^sub>\\<circ>B.\n          Hom (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>) a b) \\<subseteq>\\<^sub>\\<circ> (\\<Prod>\\<^sub>\\<circ>i\\<in>\\<^sub>\\<circ> set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}. Q i)\"\n      proof\n        (\n          intro vsubsetI,\n          elim vifunionE,\n          unfold in_Hom_iff,\n          intro vproductI ballI\n        )\n        fix abf a'b'f' F assume prems: \n          \"abf \\<in>\\<^sub>\\<circ> A\" \"a'b'f' \\<in>\\<^sub>\\<circ> B\" \"F : abf \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> a'b'f'\"\n        from prems(3) assms obtain a b f a' b' f' g h\n          where F_def: \"F = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n            and abf_def: \"abf = [a, b, f]\\<^sub>\\<circ>\"\n            and a'b'f'_def: \"a'b'f' = [a', b', f']\\<^sub>\\<circ>\"\n            and g: \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n            and h: \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n            and \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n            and \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n            and \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\n          by auto\n        have gh: \"[g, h]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> A0B0 \\<times>\\<^sub>\\<bullet> A1B1\"\n          unfolding A0B0_def A1B1_def \n        proof\n          (\n            intro ftimesI2 vifunionI, \n            unfold in_Hom_iff A0_def B0_def A1_def B1_def\n          )\n          from prems(1) show \"a \\<in>\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<lambda>F\\<in>\\<^sub>\\<circ>A. F\\<lparr>0\\<rparr>)\"\n            by (intro vsv.vsv_vimageI2'[where a=abf]) (simp_all add: abf_def)\n          from prems(2) show \"a' \\<in>\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<lambda>F\\<in>\\<^sub>\\<circ>B. F\\<lparr>0\\<rparr>)\"\n            by (intro vsv.vsv_vimageI2'[where a=a'b'f']) \n              (simp_all add: a'b'f'_def)\n          from prems(1) show \"b \\<in>\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<lambda>F\\<in>\\<^sub>\\<circ>A. F\\<lparr>1\\<^sub>\\<nat>\\<rparr>)\"\n            by (intro vsv.vsv_vimageI2'[where a=abf]) \n              (simp_all add: nat_omega_simps abf_def)\n          from prems(2) show \"b' \\<in>\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<lambda>F\\<in>\\<^sub>\\<circ>B. F\\<lparr>1\\<^sub>\\<nat>\\<rparr>)\"\n            by (intro vsv.vsv_vimageI2'[where a=a'b'f']) \n              (simp_all add: nat_omega_simps a'b'f'_def)\n        qed (intro g h)+\n        show \"vsv F\" unfolding F_def by auto\n        show \"\\<D>\\<^sub>\\<circ> F = set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}\"\n          by (simp add: F_def three nat_omega_simps)\n        fix i assume \"i \\<in>\\<^sub>\\<circ> set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}\"\n        then consider \\<open>i = 0\\<close> | \\<open>i = 1\\<^sub>\\<nat>\\<close> | \\<open>i = 2\\<^sub>\\<nat>\\<close> by auto\n        from this prems show \"F\\<lparr>i\\<rparr> \\<in>\\<^sub>\\<circ> Q i\" \n          by cases\n            (simp_all add: F_def Q_def gh abf_def a'b'f'_def nat_omega_simps)\n      qed\n      moreover have \"(\\<Prod>\\<^sub>\\<circ>i\\<in>\\<^sub>\\<circ> set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}. Q i) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n      proof(rule Limit_vproduct_in_VsetI)\n        show \"set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>} \\<in>\\<^sub>\\<circ> Vset \\<alpha>\" \n          by (cs_concl cs_shallow cs_intro: V_cs_intros)\n        from A0B0 A1B1 assms(1,2) that(3,4) show \n          \"Q i \\<in>\\<^sub>\\<circ> Vset \\<alpha>\" if \"i \\<in>\\<^sub>\\<circ> set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}\" \n          for i \n          by (simp_all add: Q_def Limit_ftimes_in_VsetI nat_omega_simps)\n      qed auto\n      ultimately show \"(\\<Union>\\<^sub>\\<circ>a\\<in>\\<^sub>\\<circ>A. \\<Union>\\<^sub>\\<circ>b\\<in>\\<^sub>\\<circ>B. Hom (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>) a b) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\" by auto\n    qed\n  qed (auto simp: cat_comma_cs_simps intro: cat_comma_cs_intros)\n\nqed\n\n\nsubsubsection\\<open>Tiny comma category\\<close>\n\nlemma tiny_category_cat_comma[cat_comma_cs_intros]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"tiny_category \\<alpha> (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>)\"\nproof-\n\n  interpret \\<GG>: is_tm_functor \\<alpha> \\<AA> \\<CC> \\<GG> by (rule assms(1))\n  interpret \\<HH>: is_tm_functor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule assms(2))\n  note \\<GG> = \\<GG>.is_functor_axioms \n    and \\<HH> = \\<HH>.is_functor_axioms\n  interpret category \\<alpha> \\<open>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_comma_cs_intros)\n\n  show ?thesis\n  proof(intro tiny_categoryI' category_cat_comma)\n    have vrange_\\<GG>: \"\\<R>\\<^sub>\\<circ> (\\<GG>\\<lparr>ObjMap\\<rparr>) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n      by (simp add: vrange_in_VsetI \\<GG>.tm_cf_ObjMap_in_Vset)\n    moreover have vrange_\\<HH>: \"\\<R>\\<^sub>\\<circ> (\\<HH>\\<lparr>ObjMap\\<rparr>) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n      by (simp add: vrange_in_VsetI \\<HH>.tm_cf_ObjMap_in_Vset)\n    ultimately have UU_Hom_in_Vset:\n      \"(\\<Union>\\<^sub>\\<circ>a\\<in>\\<^sub>\\<circ>\\<R>\\<^sub>\\<circ> (\\<GG>\\<lparr>ObjMap\\<rparr>). \\<Union>\\<^sub>\\<circ>b\\<in>\\<^sub>\\<circ>\\<R>\\<^sub>\\<circ> (\\<HH>\\<lparr>ObjMap\\<rparr>). Hom \\<CC> a b) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n      using \\<GG>.cf_ObjMap_vrange \\<HH>.cf_ObjMap_vrange \n      by (auto intro: \\<GG>.HomCod.cat_Hom_vifunion_in_Vset) \n    define Q where\n      \"Q i =\n        (\n          if i = 0\n          then \\<AA>\\<lparr>Obj\\<rparr>\n          else\n            if i = 1\\<^sub>\\<nat>\n            then \\<BB>\\<lparr>Obj\\<rparr>\n            else (\\<Union>\\<^sub>\\<circ>a\\<in>\\<^sub>\\<circ>\\<R>\\<^sub>\\<circ> (\\<GG>\\<lparr>ObjMap\\<rparr>). \\<Union>\\<^sub>\\<circ>b\\<in>\\<^sub>\\<circ>\\<R>\\<^sub>\\<circ> (\\<HH>\\<lparr>ObjMap\\<rparr>). Hom \\<CC> a b)\n        )\" \n      for i\n    have \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr> \\<subseteq>\\<^sub>\\<circ> (\\<Prod>\\<^sub>\\<circ>i\\<in>\\<^sub>\\<circ> set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}. Q i)\"\n    proof(intro vsubsetI)\n      fix A assume \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n      then obtain a b f\n        where A_def: \"A = [a, b, f]\\<^sub>\\<circ>\"\n          and a: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n          and b: \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n          and f: \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n        by (elim cat_comma_ObjE[OF _ \\<GG> \\<HH>])\n      from f have f:\n        \"f \\<in>\\<^sub>\\<circ> (\\<Union>\\<^sub>\\<circ>a\\<in>\\<^sub>\\<circ>\\<R>\\<^sub>\\<circ> (\\<GG>\\<lparr>ObjMap\\<rparr>). \\<Union>\\<^sub>\\<circ>b\\<in>\\<^sub>\\<circ>\\<R>\\<^sub>\\<circ> (\\<HH>\\<lparr>ObjMap\\<rparr>). Hom \\<CC> a b)\"\n        by (intro vifunionI, unfold in_Hom_iff)\n          (\n            simp_all add: \n              a b \n              \\<HH>.ObjMap.vsv_vimageI2 \n              \\<HH>.cf_ObjMap_vdomain \n              \\<GG>.ObjMap.vsv_vimageI2 \n              \\<GG>.cf_ObjMap_vdomain\n          )\n      show \"A \\<in>\\<^sub>\\<circ> (\\<Prod>\\<^sub>\\<circ>i\\<in>\\<^sub>\\<circ> set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}. Q i)\"\n      proof(intro vproductI, unfold Ball_def; (intro allI impI)?)\n        show \"\\<D>\\<^sub>\\<circ> A = set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}\"\n          unfolding A_def by (simp add: three nat_omega_simps)\n        fix i assume \"i \\<in>\\<^sub>\\<circ> set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}\"\n        then consider \\<open>i = 0\\<close> | \\<open>i = 1\\<^sub>\\<nat>\\<close> | \\<open>i = 2\\<^sub>\\<nat>\\<close> by auto\n        from this a b f show \"A\\<lparr>i\\<rparr> \\<in>\\<^sub>\\<circ> Q i\"\n          unfolding A_def Q_def by cases (simp_all add: nat_omega_simps)\n      qed (auto simp: A_def)\n    qed\n    moreover have \"(\\<Prod>\\<^sub>\\<circ>i\\<in>\\<^sub>\\<circ> set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}. Q i) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n    proof(rule Limit_vproduct_in_VsetI)\n      show \"set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>} \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n        unfolding three[symmetric] by simp\n      from this show \"Q i \\<in>\\<^sub>\\<circ> Vset \\<alpha>\" if \"i \\<in>\\<^sub>\\<circ> set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}\" for i\n        using that assms(1,2) UU_Hom_in_Vset  \n        by \n          (\n            simp_all add:\n              Q_def \n              \\<GG>.HomDom.tiny_cat_Obj_in_Vset \n              \\<HH>.HomDom.tiny_cat_Obj_in_Vset \n              nat_omega_simps\n          )\n    qed auto\n    ultimately show [simp]: \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr> \\<in>\\<^sub>\\<circ> Vset \\<alpha>\" by auto \n    define Q where\n      \"Q i =\n        (\n          if i = 0\n          then \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\n          else\n            if i = 1\\<^sub>\\<nat>\n            then \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\n            else \\<AA>\\<lparr>Arr\\<rparr> \\<times>\\<^sub>\\<bullet> \\<BB>\\<lparr>Arr\\<rparr>\n        )\" \n    for i\n    have \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr> \\<subseteq>\\<^sub>\\<circ> (\\<Prod>\\<^sub>\\<circ>i\\<in>\\<^sub>\\<circ> set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}. Q i)\"\n    proof(intro vsubsetI)\n      fix F assume \"F \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n      then obtain abf a'b'f' where F: \"F : abf \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> a'b'f'\"\n        by (auto intro: is_arrI)\n      with assms obtain a b f a' b' f' g h\n        where F_def: \"F = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n          and abf_def: \"abf = [a, b, f]\\<^sub>\\<circ>\"\n          and a'b'f'_def: \"a'b'f' = [a', b', f']\\<^sub>\\<circ>\"\n          and g: \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n          and h: \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n          and \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n          and \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n          and \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\n        by auto\n      from g h have \"[g, h]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Arr\\<rparr> \\<times>\\<^sub>\\<bullet> \\<BB>\\<lparr>Arr\\<rparr>\" by auto      \n      show \"F \\<in>\\<^sub>\\<circ> (\\<Prod>\\<^sub>\\<circ>i\\<in>\\<^sub>\\<circ> set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}. Q i)\"\n      proof(intro vproductI, unfold Ball_def; (intro allI impI)?)\n        show \"\\<D>\\<^sub>\\<circ> F = set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}\"\n          by (simp add: F_def three nat_omega_simps)\n        fix i assume \"i \\<in>\\<^sub>\\<circ> set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}\"\n        then consider \\<open>i = 0\\<close> | \\<open>i = 1\\<^sub>\\<nat>\\<close> | \\<open>i = 2\\<^sub>\\<nat>\\<close> by auto\n        from this F g h show \"F\\<lparr>i\\<rparr> \\<in>\\<^sub>\\<circ> Q i\"\n          unfolding Q_def F_def abf_def[symmetric] a'b'f'_def[symmetric]\n          by cases (auto simp: nat_omega_simps)\n      qed (auto simp: F_def)\n    qed\n    moreover have \"(\\<Prod>\\<^sub>\\<circ>i\\<in>\\<^sub>\\<circ> set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}. Q i) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n    proof(rule Limit_vproduct_in_VsetI)\n      show \"set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>} \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n        by (simp add: three[symmetric] nat_omega_simps)\n      moreover have \"\\<AA>\\<lparr>Arr\\<rparr> \\<times>\\<^sub>\\<bullet> \\<BB>\\<lparr>Arr\\<rparr> \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n        by \n          (\n            auto intro!: \n              Limit_ftimes_in_VsetI \n              \\<GG>.\\<Z>_\\<beta> \\<Z>_def \n              \\<GG>.HomDom.tiny_cat_Arr_in_Vset \n              \\<HH>.HomDom.tiny_cat_Arr_in_Vset\n          )\n      ultimately show \"Q i \\<in>\\<^sub>\\<circ> Vset \\<alpha>\" if \"i \\<in>\\<^sub>\\<circ> set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}\" for i\n        using that assms(1,2) UU_Hom_in_Vset  \n        by \n          (\n            simp_all add:\n              Q_def\n              \\<GG>.HomDom.tiny_cat_Obj_in_Vset \n              \\<HH>.HomDom.tiny_cat_Obj_in_Vset \n              nat_omega_simps\n          )\n    qed auto\n    ultimately show \"\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr> \\<in>\\<^sub>\\<circ> Vset \\<alpha>\" by auto\n  qed (rule \\<GG>, rule \\<HH>)\n\nqed\n\n\n\nsubsection\\<open>Opposite comma category functor\\<close>\n\n\nsubsubsection\\<open>Background\\<close>\n\n\ntext\\<open>\nSee \\<^cite>\\<open>\"noauthor_wikipedia_2001\"\\<close>\\footnote{\n\\url{https://en.wikipedia.org/wiki/Opposite_category}\n} for background information.\n\\<close>\n\n\nsubsubsection\\<open>Object flip\\<close>\n\ndefinition op_cf_commma_obj_flip :: \"V \\<Rightarrow> V \\<Rightarrow> V\"\n  where \"op_cf_commma_obj_flip \\<GG> \\<HH> =\n    (\\<lambda>A\\<in>\\<^sub>\\<circ>(\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>Obj\\<rparr>. [A\\<lparr>1\\<^sub>\\<nat>\\<rparr>, A\\<lparr>0\\<rparr>, A\\<lparr>2\\<^sub>\\<nat>\\<rparr>]\\<^sub>\\<circ>)\"\n\n\ntext\\<open>Elementary properties.\\<close>\n\nmk_VLambda op_cf_commma_obj_flip_def\n  |vsv op_cf_commma_obj_flip_vsv[cat_comma_cs_intros]|\n  |vdomain op_cf_commma_obj_flip_vdomain[cat_comma_cs_simps]|\n  |app op_cf_commma_obj_flip_app'|\n\nlemma op_cf_commma_obj_flip_app[cat_comma_cs_simps]:\n  assumes \"A = [a, b, f]\\<^sub>\\<circ>\" and \"A \\<in>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>Obj\\<rparr>\"\n  shows \"op_cf_commma_obj_flip \\<GG> \\<HH>\\<lparr>A\\<rparr> = [b, a, f]\\<^sub>\\<circ>\"\n  using assms unfolding op_cf_commma_obj_flip_def by (simp add: nat_omega_simps)\n\nlemma op_cf_commma_obj_flip_v11[cat_comma_cs_intros]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"v11 (op_cf_commma_obj_flip \\<GG> \\<HH>)\"\nproof(rule vsv.vsv_valeq_v11I, unfold op_cf_commma_obj_flip_vdomain)\n  fix A B assume prems:\n    \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n    \"B \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n    \"op_cf_commma_obj_flip \\<GG> \\<HH>\\<lparr>A\\<rparr> = op_cf_commma_obj_flip \\<GG> \\<HH>\\<lparr>B\\<rparr>\"\n  from prems(1,2) assms obtain a b f a' b' f' \n    where A_def: \"A = [a, b, f]\\<^sub>\\<circ>\" \n      and B_def: \"B = [a', b', f']\\<^sub>\\<circ>\"\n    by (elim cat_comma_ObjE[OF _ assms])\n  from prems(3,1,2) show \"A = B\"\n    by (simp_all add: A_def B_def op_cf_commma_obj_flip_app nat_omega_simps)\nqed (auto intro: op_cf_commma_obj_flip_vsv)\n\nlemma op_cf_commma_obj_flip_vrange[cat_comma_cs_simps]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"\\<R>\\<^sub>\\<circ> (op_cf_commma_obj_flip \\<GG> \\<HH>) = (op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\\<lparr>Obj\\<rparr>\"\nproof(intro vsubset_antisym)\n  interpret \\<GG>: is_functor \\<alpha> \\<AA> \\<CC> \\<GG> by (rule assms(1))\n  interpret \\<HH>: is_functor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule assms(2))\n  show \"\\<R>\\<^sub>\\<circ> (op_cf_commma_obj_flip \\<GG> \\<HH>) \\<subseteq>\\<^sub>\\<circ> (op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\\<lparr>Obj\\<rparr>\"\n  proof\n    (\n      intro vsv.vsv_vrange_vsubset op_cf_commma_obj_flip_vsv, \n      unfold cat_comma_cs_simps\n    )\n    fix A assume \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n    then obtain a b f\n      where A_def: \"A = [a, b, f]\\<^sub>\\<circ>\"\n        and a: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n        and b: \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n        and f: \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n      by (elim cat_comma_ObjE[OF _ assms])\n    from a b f show \n      \"op_cf_commma_obj_flip \\<GG> \\<HH>\\<lparr>A\\<rparr> \\<in>\\<^sub>\\<circ> (op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\\<lparr>Obj\\<rparr>\"\n      unfolding A_def\n      by \n        (\n          cs_concl cs_shallow\n            cs_simp: cat_comma_cs_simps cat_op_simps \n            cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros\n        )\n  qed\n  show \"(op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\\<lparr>Obj\\<rparr> \\<subseteq>\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (op_cf_commma_obj_flip \\<GG> \\<HH>)\"\n  proof(intro vsubsetI)\n    fix B assume \"B \\<in>\\<^sub>\\<circ> (op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\\<lparr>Obj\\<rparr>\"\n    then obtain a b f\n      where B_def: \"B = [b, a, f]\\<^sub>\\<circ>\"\n        and b: \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n        and a: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n        and f: \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n      by \n        (\n          elim cat_comma_ObjE[\n            OF _ \\<HH>.is_functor_op \\<GG>.is_functor_op, unfolded cat_op_simps\n            ]\n        )\n    from a b f have B_def: \"B = op_cf_commma_obj_flip \\<GG> \\<HH>\\<lparr>a, b, f\\<rparr>\\<^sub>\\<bullet>\"\n      by \n        (\n          cs_concl cs_shallow \n            cs_simp: cat_comma_cs_simps B_def\n            cs_intro: cat_cs_intros cat_comma_cs_intros\n        )\n    from a b f have \"[a, b, f]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<D>\\<^sub>\\<circ> (op_cf_commma_obj_flip \\<GG> \\<HH>)\"\n      by \n        (\n          cs_concl cs_shallow\n            cs_simp: cat_comma_cs_simps\n            cs_intro: cat_cs_intros cat_comma_cs_intros\n        )\n    with op_cf_commma_obj_flip_vsv show \"B \\<in>\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (op_cf_commma_obj_flip \\<GG> \\<HH>)\"\n      unfolding B_def by auto\n  qed\nqed\n\n\nsubsubsection\\<open>Definition and elementary properties\\<close>\n\ndefinition op_cf_comma :: \"V \\<Rightarrow> V \\<Rightarrow> V\"\n  where \"op_cf_comma \\<GG> \\<HH> =\n    [\n      op_cf_commma_obj_flip \\<GG> \\<HH>,\n      (\n        \\<lambda>ABF\\<in>\\<^sub>\\<circ>(\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>Arr\\<rparr>.\n          [\n            op_cf_commma_obj_flip \\<GG> \\<HH>\\<lparr>ABF\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<rparr>,\n            op_cf_commma_obj_flip \\<GG> \\<HH>\\<lparr>ABF\\<lparr>0\\<rparr>\\<rparr>,\n            [ABF\\<lparr>2\\<^sub>\\<nat>\\<rparr>\\<lparr>1\\<^sub>\\<nat>\\<rparr>, ABF\\<lparr>2\\<^sub>\\<nat>\\<rparr>\\<lparr>0\\<^sub>\\<nat>\\<rparr>]\\<^sub>\\<circ>\n          ]\\<^sub>\\<circ>\n      ),\n      op_cat (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>),\n      (op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\n    ]\\<^sub>\\<circ>\"\n\n\ntext\\<open>Components.\\<close>\n\nlemma op_cf_comma_components:\n  shows [cat_comma_cs_simps]: \n      \"op_cf_comma \\<GG> \\<HH>\\<lparr>ObjMap\\<rparr> = op_cf_commma_obj_flip \\<GG> \\<HH>\"\n    and \"op_cf_comma \\<GG> \\<HH>\\<lparr>ArrMap\\<rparr> =\n      (\n        \\<lambda>ABF\\<in>\\<^sub>\\<circ>(\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>Arr\\<rparr>.\n          [\n            op_cf_commma_obj_flip \\<GG> \\<HH>\\<lparr>ABF\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<rparr>,\n            op_cf_commma_obj_flip \\<GG> \\<HH>\\<lparr>ABF\\<lparr>0\\<rparr>\\<rparr>,\n            [ABF\\<lparr>2\\<^sub>\\<nat>\\<rparr>\\<lparr>1\\<^sub>\\<nat>\\<rparr>, ABF\\<lparr>2\\<^sub>\\<nat>\\<rparr>\\<lparr>0\\<^sub>\\<nat>\\<rparr>]\\<^sub>\\<circ>\n          ]\\<^sub>\\<circ>\n      )\"\n    and [cat_comma_cs_simps]: \n      \"op_cf_comma \\<GG> \\<HH>\\<lparr>HomDom\\<rparr> = op_cat (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>)\"\n    and [cat_comma_cs_simps]: \n      \"op_cf_comma \\<GG> \\<HH>\\<lparr>HomCod\\<rparr> = (op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\"\n  unfolding op_cf_comma_def dghm_field_simps by (simp_all add: nat_omega_simps)\n\n\nsubsubsection\\<open>Arrow map\\<close>\n\nmk_VLambda op_cf_comma_components(2)\n  |vsv op_cf_comma_ArrMap_vsv[cat_comma_cs_intros]|\n  |vdomain op_cf_comma_ArrMap_vdomain[cat_comma_cs_simps]|\n  |app op_cf_comma_ArrMap_app'|\n\nlemma op_cf_comma_ArrMap_app[cat_comma_cs_simps]:\n  assumes \"ABF = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n    and \"ABF \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n  shows \"op_cf_comma \\<GG> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>ABF\\<rparr> =\n    [\n      op_cf_commma_obj_flip \\<GG> \\<HH>\\<lparr>a', b', f'\\<rparr>\\<^sub>\\<bullet>,\n      op_cf_commma_obj_flip \\<GG> \\<HH>\\<lparr>a, b, f\\<rparr>\\<^sub>\\<bullet>,\n      [h, g]\\<^sub>\\<circ>\n    ]\\<^sub>\\<circ>\"\n  using assms(2) by (simp add: assms(1) op_cf_comma_ArrMap_app' nat_omega_simps)\n\nlemma op_cf_comma_ArrMap_v11[cat_comma_cs_intros]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"v11 (op_cf_comma \\<GG> \\<HH>\\<lparr>ArrMap\\<rparr>)\"\nproof\n  (\n    rule vsv.vsv_valeq_v11I, \n    unfold op_cf_comma_ArrMap_vdomain,\n    intro op_cf_comma_ArrMap_vsv\n  )\n  interpret \\<GG>: is_functor \\<alpha> \\<AA> \\<CC> \\<GG> by (rule assms(1))\n  interpret \\<HH>: is_functor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule assms(2))\n  interpret \\<GG>\\<HH>: category \\<alpha> \\<open>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_comma_cs_intros)\n  fix ABF ABF' assume prems:\n    \"ABF \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n    \"ABF' \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n    \"op_cf_comma \\<GG> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>ABF\\<rparr> = op_cf_comma \\<GG> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>ABF'\\<rparr>\"\n  from prems(1) obtain A B where ABF: \"ABF : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\" by auto\n  from prems(2) obtain A' B' where ABF': \"ABF' : A' \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B'\" by auto\n  from ABF obtain a b f a' b' f' g h \n    where ABF_def: \"ABF = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and A_def: \"A = [a, b, f]\\<^sub>\\<circ>\"\n      and B_def: \"B = [a', b', f']\\<^sub>\\<circ>\"\n      and \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n      and \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n      and \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n      and \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n      and \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\n    by (elim cat_comma_is_arrE[OF _ assms])\n  from ABF' obtain a'' b'' f'' a''' b''' f''' g' h' \n    where ABF'_def: \"ABF' = [[a'', b'', f'']\\<^sub>\\<circ>, [a''', b''', f''']\\<^sub>\\<circ>, [g', h']\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and A'_def: \"A' = [a'', b'', f'']\\<^sub>\\<circ>\"\n      and B'_def: \"B' = [a''', b''', f''']\\<^sub>\\<circ>\"\n      and \"g' : a'' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'''\"\n      and \"h' : b'' \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'''\"\n      and \"f'' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a''\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b''\\<rparr>\"\n      and \"f''' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'''\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'''\\<rparr>\"\n      and \"f''' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g'\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f''\"\n    by (elim cat_comma_is_arrE[OF _ assms])\n  from ABF ABF' have abf:\n    \"[a, b, f]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>Obj\\<rparr>\"\n    \"[a', b', f']\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>Obj\\<rparr>\"\n    \"[a'', b'', f'']\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>Obj\\<rparr>\"\n    \"[a''', b''', f''']\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>Obj\\<rparr>\"\n    unfolding ABF_def ABF'_def A_def B_def A'_def B'_def by auto\n  note v11_injective = v11.v11_injective[\n      OF op_cf_commma_obj_flip_v11, OF assms, unfolded cat_comma_cs_simps\n      ]\n  from \n    prems(3,1,2) assms \n    op_cf_commma_obj_flip_v11 \n    v11_injective[OF abf(1,3)] \n    v11_injective[OF abf(2,4)] \n  show \"ABF = ABF'\"\n    by \n      (\n        simp_all add: \n          ABF_def ABF'_def op_cf_comma_ArrMap_app' nat_omega_simps \n      )\nqed\n\nlemma op_cf_comma_ArrMap_is_arr:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"ABF : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\"\n  shows \"op_cf_comma \\<GG> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>ABF\\<rparr> :\n    op_cf_commma_obj_flip \\<GG> \\<HH>\\<lparr>B\\<rparr> \\<mapsto>\\<^bsub>(op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\\<^esub> \n    op_cf_commma_obj_flip \\<GG> \\<HH>\\<lparr>A\\<rparr>\"\nproof-\n  interpret \\<GG>: is_functor \\<alpha> \\<AA> \\<CC> \\<GG> by (rule assms(1))\n  interpret \\<HH>: is_functor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule assms(2))\n  interpret \\<GG>\\<HH>: category \\<alpha> \\<open>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<close> \n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_comma_cs_intros)\n  from assms(3) obtain a b f a' b' f' g h\n    where ABF_def: \"ABF = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and A_def: \"A = [a, b, f]\\<^sub>\\<circ>\"\n      and B_def: \"B = [a', b', f']\\<^sub>\\<circ>\"\n      and g: \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n      and h: \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n      and f: \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n      and f': \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n      and f'g_hf: \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\n    by (elim cat_comma_is_arrE[OF _ assms(1,2)])\n  from g h f f' f'g_hf show ?thesis\n    unfolding ABF_def A_def B_def\n    by \n      (\n        cs_concl \n          cs_simp: cat_cs_simps cat_comma_cs_simps cat_op_simps\n          cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros\n      )\nqed\n\nlemma op_cf_comma_ArrMap_is_arr':\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"ABF : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\"\n    and \"A' = op_cf_commma_obj_flip \\<GG> \\<HH>\\<lparr>B\\<rparr>\"\n    and \"B' = op_cf_commma_obj_flip \\<GG> \\<HH>\\<lparr>A\\<rparr>\"\n  shows \"op_cf_comma \\<GG> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>ABF\\<rparr> : A' \\<mapsto>\\<^bsub>(op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\\<^esub> B'\"\n  using assms(1-3) unfolding assms(4,5) by (intro op_cf_comma_ArrMap_is_arr)\n\nlemma op_cf_comma_ArrMap_vrange[cat_comma_cs_simps]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"\\<R>\\<^sub>\\<circ> (op_cf_comma \\<GG> \\<HH>\\<lparr>ArrMap\\<rparr>) = (op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\\<lparr>Arr\\<rparr>\"\nproof-\n  interpret \\<GG>: is_functor \\<alpha> \\<AA> \\<CC> \\<GG> by (rule assms(1))\n  interpret \\<HH>: is_functor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule assms(2))\n  interpret \\<GG>\\<HH>: category \\<alpha> \\<open>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_comma_cs_intros)\n  interpret op_\\<GG>\\<HH>: category \\<alpha> \\<open>(op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros cat_op_intros)\n  show ?thesis\n  proof(intro vsubset_antisym)\n    show \"\\<R>\\<^sub>\\<circ> (op_cf_comma \\<GG> \\<HH>\\<lparr>ArrMap\\<rparr>) \\<subseteq>\\<^sub>\\<circ> (op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\\<lparr>Arr\\<rparr>\"\n    proof\n      (\n        intro vsv.vsv_vrange_vsubset op_cf_comma_ArrMap_vsv, \n        unfold cat_comma_cs_simps\n      )\n      fix ABF assume prems: \"ABF \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n      then obtain A B where ABF: \"ABF : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\" by auto\n      from op_cf_comma_ArrMap_is_arr[OF assms this] show \n        \"op_cf_comma \\<GG> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>ABF\\<rparr> \\<in>\\<^sub>\\<circ> (op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\\<lparr>Arr\\<rparr>\"\n        by auto\n    qed\n    show \"(op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\\<lparr>Arr\\<rparr> \\<subseteq>\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (op_cf_comma \\<GG> \\<HH>\\<lparr>ArrMap\\<rparr>)\"\n    proof(intro vsubsetI)\n      fix ABF assume prems: \"ABF \\<in>\\<^sub>\\<circ> (op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\\<lparr>Arr\\<rparr>\"\n      then obtain A B where ABF: \"ABF : A \\<mapsto>\\<^bsub>(op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\\<^esub> B\" \n        by auto\n      then obtain a b f a' b' f' g h\n        where ABF_def: \"ABF = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n          and A_def: \"A = [a, b, f]\\<^sub>\\<circ>\"\n          and B_def: \"B = [a', b', f']\\<^sub>\\<circ>\"\n          and g: \"g : a' \\<mapsto>\\<^bsub>\\<BB>\\<^esub> a\"\n          and h: \"h : b' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b\"\n          and f: \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n          and f': \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr>\" \n          and f'g_hf: \"f' \\<circ>\\<^sub>A\\<^bsub>op_cat \\<CC>\\<^esub> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>op_cat \\<CC>\\<^esub> f\"\n        by \n          (\n            elim cat_comma_is_arrE[\n              OF _ \\<HH>.is_functor_op \\<GG>.is_functor_op, unfolded cat_op_simps\n              ]\n          )\n      from f'g_hf g h f f' have gf'_fh:\n        \"\\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f' = f \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr>\"\n        by \n          (\n            cs_prems cs_shallow \n              cs_simp: cat_op_simps cs_intro: cat_cs_intros cat_op_intros\n          )\n      with g h f f' have \n        \"[[b', a', f']\\<^sub>\\<circ>, [b, a, f]\\<^sub>\\<circ>, [h, g]\\<^sub>\\<circ>]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<D>\\<^sub>\\<circ> (op_cf_comma \\<GG> \\<HH>\\<lparr>ArrMap\\<rparr>)\"\n        \"ABF = op_cf_comma \\<GG> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>[b', a', f']\\<^sub>\\<circ>, [b, a, f]\\<^sub>\\<circ>, [h, g]\\<^sub>\\<circ>\\<rparr>\\<^sub>\\<bullet>\"\n        by\n          (\n            cs_concl \n              cs_simp: cat_cs_simps cat_comma_cs_simps ABF_def\n              cs_intro: cat_cs_intros cat_comma_cs_intros\n          )+\n      with op_cf_comma_ArrMap_vsv show \"ABF \\<in>\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (op_cf_comma \\<GG> \\<HH>\\<lparr>ArrMap\\<rparr>)\"\n        by auto\n    qed\n  qed\nqed\n\n\nsubsubsection\\<open>Opposite comma category functor is an isomorphism of categories\\<close>\n\nlemma op_cf_comma_is_iso_functor:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"op_cf_comma \\<GG> \\<HH> : \n    op_cat (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>) \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<alpha>\\<^esub> (op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\"\nproof-\n  interpret \\<GG>: is_functor \\<alpha> \\<AA> \\<CC> \\<GG> by (rule assms(1))\n  interpret \\<HH>: is_functor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule assms(2))\n  show ?thesis\n  proof(intro is_iso_functorI' is_functorI')\n    show \"vfsequence (op_cf_comma \\<GG> \\<HH>)\"\n      unfolding op_cf_comma_def by simp\n    show \"vcard (op_cf_comma \\<GG> \\<HH>) = 4\\<^sub>\\<nat>\"\n      unfolding op_cf_comma_def by (simp add: nat_omega_simps)\n    from assms show \"op_cf_comma \\<GG> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>ABF\\<rparr> :\n      op_cf_comma \\<GG> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> \\<mapsto>\\<^bsub>(op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\\<^esub>\n      op_cf_comma \\<GG> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>B\\<rparr>\"\n      if \"ABF : A \\<mapsto>\\<^bsub>op_cat (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>)\\<^esub> B\" for A B ABF\n      using that\n      unfolding cat_op_simps\n      by \n        (\n          cs_concl cs_shallow\n            cs_intro: op_cf_comma_ArrMap_is_arr' cs_simp: cat_comma_cs_simps\n        )\n    show\n      \"op_cf_comma \\<GG> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>G \\<circ>\\<^sub>A\\<^bsub>op_cat (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>)\\<^esub> F\\<rparr> =\n        op_cf_comma \\<GG> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>G\\<rparr> \\<circ>\\<^sub>A\\<^bsub>(op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\\<^esub>\n          op_cf_comma \\<GG> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr>\"\n      if \"G : B \\<mapsto>\\<^bsub>op_cat (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>)\\<^esub> C\" \n        and \"F : A \\<mapsto>\\<^bsub>op_cat (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>)\\<^esub> B\"\n      for B C G A F\n    proof-\n      note G = that(1)[unfolded cat_op_simps]\n      note F = that(2)[unfolded cat_op_simps]\n      from assms G obtain a b f a' b' f' g h\n        where G_def: \"G = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n          and C_def: \"C = [a, b, f]\\<^sub>\\<circ>\"\n          and B_def: \"B = [a', b', f']\\<^sub>\\<circ>\"\n          and g: \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n          and h: \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n          and f: \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n          and f': \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n          and [symmetric, cat_comma_cs_simps]: \n            \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\n        by auto\n      with assms F obtain a'' b'' f'' g' h'\n        where F_def: \"F = [[a', b', f']\\<^sub>\\<circ>, [a'', b'', f'']\\<^sub>\\<circ>, [g', h']\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n          and A_def: \"A = [a'', b'', f'']\\<^sub>\\<circ>\"\n          and g': \"g' : a' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a''\"\n          and h': \"h' : b' \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b''\"\n          and f'': \"f'' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a''\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b''\\<rparr>\"\n          and [cat_comma_cs_simps]: \n            \"f'' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g'\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f'\"\n        by auto (*slow*)\n      note [cat_comma_cs_simps] = \n        category.cat_assoc_helper[\n          where \\<CC>=\\<CC> and h=f'' and g=\\<open>\\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g'\\<rparr>\\<close> and q=\\<open>\\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f'\\<close>\n          ]\n      from assms that g h f f' g' h' f' f'' show ?thesis\n        unfolding cat_op_simps G_def C_def B_def F_def A_def\n        by\n          (\n            cs_concl \n              cs_simp: cat_cs_simps cat_comma_cs_simps cat_op_simps\n              cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros\n          )\n    qed\n    show \n      \"op_cf_comma \\<GG> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>op_cat (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>CId\\<rparr>\\<lparr>C\\<rparr>\\<rparr> =\n        (op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\\<lparr>CId\\<rparr>\\<lparr>op_cf_comma \\<GG> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>C\\<rparr>\\<rparr>\"\n      if \"C \\<in>\\<^sub>\\<circ> op_cat (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>Obj\\<rparr>\" for C\n    proof-\n      from that[unfolded cat_op_simps] assms obtain a b f \n        where C_def: \"C = [a, b, f]\\<^sub>\\<circ>\"\n          and a: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n          and b: \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n          and f: \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n        by auto\n      from a b f that show ?thesis\n        unfolding cat_op_simps C_def\n        by\n          (\n            cs_concl cs_shallow\n              cs_simp: cat_cs_simps cat_comma_cs_simps cat_op_simps\n              cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros\n          )\n    qed\n  qed\n    (\n      cs_concl cs_shallow\n        cs_simp: cat_cs_simps cat_comma_cs_simps cat_op_simps\n        cs_intro: V_cs_intros cat_cs_intros cat_comma_cs_intros cat_op_intros\n    )+\nqed\n\nlemma op_cf_comma_is_iso_functor'[cat_comma_cs_intros]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<AA>' = op_cat (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>)\"\n    and \"\\<BB>' = (op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\"\n  shows \"op_cf_comma \\<GG> \\<HH> : \\<AA>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<alpha>\\<^esub> \\<BB>'\"\n  using assms(1,2) unfolding assms(3,4) by (rule op_cf_comma_is_iso_functor)\n\nlemma op_cf_comma_is_functor:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"op_cf_comma \\<GG> \\<HH> :\n    op_cat (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>) \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> (op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\"\n  by (rule is_iso_functorD(1)[OF op_cf_comma_is_iso_functor[OF assms]])\n\nlemma op_cf_comma_is_functor'[cat_comma_cs_intros]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<AA>' = op_cat (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>)\"\n    and \"\\<BB>' = (op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (op_cf \\<GG>)\"\n  shows \"op_cf_comma \\<GG> \\<HH> : \\<AA>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>'\"\n  using assms(1,2) unfolding assms(3,4) by (rule op_cf_comma_is_functor)\n\n\n\nsubsection\\<open>Projections for a comma category\\<close>\n\n\nsubsubsection\\<open>Definitions and elementary properties\\<close>\n\n\ntext\\<open>See Chapter II-6 in \\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>.\\<close>\n\ndefinition cf_comma_proj_left :: \"V \\<Rightarrow> V \\<Rightarrow> V\" (\\<open>(_ \\<^sub>C\\<^sub>F\\<Sqinter> _)\\<close> [1000, 1000] 999)\n  where \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH> =\n    [\n      (\\<lambda>a\\<in>\\<^sub>\\<circ>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>. a\\<lparr>0\\<rparr>),\n      (\\<lambda>f\\<in>\\<^sub>\\<circ>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>. f\\<lparr>2\\<^sub>\\<nat>\\<rparr>\\<lparr>0\\<rparr>),\n      \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>,\n      \\<GG>\\<lparr>HomDom\\<rparr>\n    ]\\<^sub>\\<circ>\"\n\ndefinition cf_comma_proj_right :: \"V \\<Rightarrow> V \\<Rightarrow> V\" (\\<open>(_ \\<Sqinter>\\<^sub>C\\<^sub>F _)\\<close> [1000, 1000] 999)\n  where \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH> =\n    [\n      (\\<lambda>a\\<in>\\<^sub>\\<circ>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>. a\\<lparr>1\\<^sub>\\<nat>\\<rparr>),\n      (\\<lambda>f\\<in>\\<^sub>\\<circ>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>. f\\<lparr>2\\<^sub>\\<nat>\\<rparr>\\<lparr>1\\<^sub>\\<nat>\\<rparr>),\n      \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>,\n      \\<HH>\\<lparr>HomDom\\<rparr>\n    ]\\<^sub>\\<circ>\"\n\n\ntext\\<open>Components.\\<close>\n\nlemma cf_comma_proj_left_components:\n  shows \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ObjMap\\<rparr> = (\\<lambda>a\\<in>\\<^sub>\\<circ>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>. a\\<lparr>0\\<rparr>)\"\n    and \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ArrMap\\<rparr> = (\\<lambda>f\\<in>\\<^sub>\\<circ>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>. f\\<lparr>2\\<^sub>\\<nat>\\<rparr>\\<lparr>0\\<rparr>)\"\n    and \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>HomDom\\<rparr> = \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\"\n    and \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>HomCod\\<rparr> = \\<GG>\\<lparr>HomDom\\<rparr>\"\n  unfolding cf_comma_proj_left_def dghm_field_simps\n  by (simp_all add: nat_omega_simps)\n\nlemma cf_comma_proj_right_components:\n  shows \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ObjMap\\<rparr> = (\\<lambda>a\\<in>\\<^sub>\\<circ>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>. a\\<lparr>1\\<^sub>\\<nat>\\<rparr>)\"\n    and \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ArrMap\\<rparr> = (\\<lambda>f\\<in>\\<^sub>\\<circ>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>. f\\<lparr>2\\<^sub>\\<nat>\\<rparr>\\<lparr>1\\<^sub>\\<nat>\\<rparr>)\"\n    and \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>HomDom\\<rparr> = \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\"\n    and \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>HomCod\\<rparr> = \\<HH>\\<lparr>HomDom\\<rparr>\"\n  unfolding cf_comma_proj_right_def dghm_field_simps\n  by (simp_all add: nat_omega_simps)\n\ncontext\n  fixes \\<alpha> \\<AA> \\<BB> \\<CC> \\<GG> \\<HH>\n  assumes \\<GG>: \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \\<HH>: \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\nbegin\n\ninterpretation \\<GG>: is_functor \\<alpha> \\<AA> \\<CC> \\<GG> by (rule \\<GG>)\ninterpretation \\<HH>: is_functor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule \\<HH>)\n\nlemmas cf_comma_proj_left_components' = \n  cf_comma_proj_left_components[of \\<GG> \\<HH>, unfolded \\<GG>.cf_HomDom]\n\nlemmas cf_comma_proj_right_components' = \n  cf_comma_proj_right_components[of \\<GG> \\<HH>, unfolded \\<HH>.cf_HomDom]\n\nlemmas [cat_comma_cs_simps] = \n  cf_comma_proj_left_components'(3,4)\n  cf_comma_proj_right_components'(3,4)\n\nend\n\n\nsubsubsection\\<open>Object map\\<close>\n\nmk_VLambda cf_comma_proj_left_components(1)\n  |vsv cf_comma_proj_left_ObjMap_vsv[cat_comma_cs_intros]|\n  |vdomain cf_comma_proj_left_ObjMap_vdomain[cat_comma_cs_simps]|\n\nmk_VLambda cf_comma_proj_right_components(1)\n  |vsv cf_comma_proj_right_ObjMap_vsv[cat_comma_cs_intros]|\n  |vdomain cf_comma_proj_right_ObjMap_vdomain[cat_comma_cs_simps]|\n\nlemma cf_comma_proj_left_ObjMap_app[cat_comma_cs_simps]:\n  assumes \"A = [a, b, f]\\<^sub>\\<circ>\" and \"[a, b, f]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> = a\"\n  using assms(2) unfolding assms(1) cf_comma_proj_left_components by simp\n\nlemma cf_comma_proj_right_ObjMap_app[cat_comma_cs_simps]:\n  assumes \"A = [a, b, f]\\<^sub>\\<circ>\" and \"[a, b, f]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> = b\"\n  using assms(2)\n  unfolding assms(1) cf_comma_proj_right_components \n  by (simp add: nat_omega_simps)\n\nlemma cf_comma_proj_left_ObjMap_vrange:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"\\<R>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ObjMap\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\nproof(rule vsv.vsv_vrange_vsubset, unfold cat_comma_cs_simps)\n  fix A assume prems: \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n  with assms obtain a b f where A_def: \"A = [a, b, f]\\<^sub>\\<circ>\" and a: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n    by auto\n  from assms prems a show \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n    unfolding A_def by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps)\nqed (auto intro: cat_comma_cs_intros)  \n\nlemma cf_comma_proj_right_ObjMap_vrange:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"\\<R>\\<^sub>\\<circ> (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ObjMap\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\nproof(rule vsv.vsv_vrange_vsubset, unfold cat_comma_cs_simps)\n  fix A assume prems: \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n  with assms obtain a b f where A_def: \"A = [a, b, f]\\<^sub>\\<circ>\" and b: \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n    by auto\n  from assms prems b show \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n    unfolding A_def by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps)\nqed (auto intro: cat_comma_cs_intros)  \n\n\nsubsubsection\\<open>Arrow map\\<close>\n\nmk_VLambda cf_comma_proj_left_components(2)\n  |vsv cf_comma_proj_left_ArrMap_vsv[cat_comma_cs_intros]|\n  |vdomain cf_comma_proj_left_ArrMap_vdomain[cat_comma_cs_simps]|\n\nmk_VLambda cf_comma_proj_right_components(2)\n  |vsv cf_comma_proj_right_ArrMap_vsv[cat_comma_cs_intros]|\n  |vdomain cf_comma_proj_right_ArrMap_vdomain[cat_comma_cs_simps]|\n\nlemma cf_comma_proj_left_ArrMap_app[cat_comma_cs_simps]:\n  assumes \"ABF = [A, B, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\" and \"[A, B, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n  shows \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>ABF\\<rparr> = g\"\n  using assms(2)\n  unfolding assms(1) cf_comma_proj_left_components \n  by (simp add: nat_omega_simps)\n\nlemma cf_comma_proj_right_ArrMap_app[cat_comma_cs_simps]:\n  assumes \"ABF = [A, B, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\" \n    and \"[A, B, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n  shows \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>ABF\\<rparr> = h\"\n  using assms(2)\n  unfolding assms(1) cf_comma_proj_right_components \n  by (simp add: nat_omega_simps)\n\nlemma cf_comma_proj_left_ArrMap_vrange:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"\\<R>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ArrMap\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<AA>\\<lparr>Arr\\<rparr>\"\nproof(rule vsv.vsv_vrange_vsubset, unfold cat_comma_cs_simps)\n  from assms interpret category \\<alpha> \\<open>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)\n  fix F assume prems: \"F \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n  then obtain A B where \"F : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\" by auto\n  with assms obtain a b f a' b' f' g h\n    where F_def: \"F = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and g: \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n    by auto\n  from assms prems g show \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr> \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Arr\\<rparr>\"\n    unfolding F_def \n    by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps cs_intro: cat_cs_intros)\nqed (auto intro: cat_comma_cs_intros)  \n\nlemma cf_comma_proj_right_ArrMap_vrange:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"\\<R>\\<^sub>\\<circ> (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ArrMap\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<BB>\\<lparr>Arr\\<rparr>\"\nproof(rule vsv.vsv_vrange_vsubset, unfold cat_comma_cs_simps)\n  from assms interpret category \\<alpha> \\<open>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)\n  fix F assume prems: \"F \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n  then obtain A B where F: \"F : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\" by auto\n  with assms obtain a b f a' b' f' g h\n    where F_def: \"F = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and h: \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n    by auto\n  from assms prems h show \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr> \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Arr\\<rparr>\"\n    unfolding F_def \n    by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps cs_intro: cat_cs_intros)\nqed (auto intro: cat_comma_cs_intros)  \n\n\nsubsubsection\\<open>Projections for a comma category are functors\\<close>\n\nlemma cf_comma_proj_left_is_functor:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH> : \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\nproof-\n  interpret \\<GG>: is_functor \\<alpha> \\<AA> \\<CC> \\<GG> by (rule assms(1))\n  interpret \\<HH>: is_functor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule assms(2))\n  from assms interpret \\<GG>\\<HH>: category \\<alpha> \\<open>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)\n  show ?thesis\n  proof(rule is_functorI')\n    show \"vfsequence (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>)\"\n      unfolding cf_comma_proj_left_def by auto\n    show \"vcard (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>) = 4\\<^sub>\\<nat>\"\n      unfolding cf_comma_proj_left_def by (simp add: nat_omega_simps)\n    from assms show \"\\<R>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ObjMap\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n      by (rule cf_comma_proj_left_ObjMap_vrange)\n    show \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr> : \\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> \\<mapsto>\\<^bsub>\\<AA>\\<^esub> \\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>B\\<rparr>\"\n      if \"F : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\" for A B F\n    proof-\n      from assms that obtain a b f a' b' f' g h\n        where F_def: \"F = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n          and A_def: \"A = [a, b, f]\\<^sub>\\<circ>\"\n          and B_def: \"B = [a', b', f']\\<^sub>\\<circ>\"\n          and g: \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n        by auto\n      from that g show \n        \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr> : \\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> \\<mapsto>\\<^bsub>\\<AA>\\<^esub> \\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>B\\<rparr>\"\n        unfolding F_def A_def B_def\n        by (cs_concl cs_simp: cat_comma_cs_simps cs_intro: cat_cs_intros)\n    qed\n    show \n      \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>G \\<circ>\\<^sub>A\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> F\\<rparr> =\n        \\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>G\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> \\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr>\"\n      if \"G : B \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> C\" and \"F : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\" for B C G A F\n    proof-\n      from assms that(2) obtain a b f a' b' f' g h\n        where F_def: \"F = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n          and A_def: \"A = [a, b, f]\\<^sub>\\<circ>\"\n          and B_def: \"B = [a', b', f']\\<^sub>\\<circ>\"\n          and g: \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n          and h: \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n          and f: \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n          and f': \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n          and [cat_cs_simps]: \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\n        by auto\n      with that(1) assms obtain a'' b'' f'' g' h'\n        where G_def: \"G = [[a', b', f']\\<^sub>\\<circ>, [a'', b'', f'']\\<^sub>\\<circ>, [g', h']\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n          and C_def: \"C = [a'', b'', f'']\\<^sub>\\<circ>\"\n          and g': \"g' : a' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a''\"\n          and h': \"h' : b' \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b''\"\n          and f'': \"f'' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a''\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b''\\<rparr>\"\n          and [cat_cs_simps]: \"f'' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g'\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f'\"\n        by auto (*slow*)\n      note [cat_cs_simps] = \n        category.cat_assoc_helper\n          [\n            where \\<CC>=\\<CC> \n              and h=f'' \n              and g=\\<open>\\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g'\\<rparr>\\<close> \n              and q=\\<open>\\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f'\\<close>\n          ]\n        category.cat_assoc_helper\n          [\n            where \\<CC>=\\<CC> \n              and h=f \n              and g=\\<open>\\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr>\\<close> \n              and q=\\<open>f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr>\\<close>\n          ]\n      from assms that g g' h h' f f' f'' show ?thesis\n        unfolding F_def G_def A_def B_def C_def\n        by\n          (\n            cs_concl cs_shallow\n              cs_simp: cat_cs_simps cat_comma_cs_simps\n              cs_intro: cat_comma_cs_intros cat_cs_intros\n          )\n    qed\n    show \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>CId\\<rparr>\\<lparr>A\\<rparr>\\<rparr> = \\<AA>\\<lparr>CId\\<rparr>\\<lparr>\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr>\\<rparr>\"\n      if \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\" for A\n    proof-\n      from assms that obtain a b f \n        where A_def: \"A = [a, b, f]\\<^sub>\\<circ>\"\n          and \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n          and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" \n          and \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n        by auto\n      from assms that this(2-4) show ?thesis\n        unfolding A_def\n        by\n          (\n            cs_concl cs_shallow\n              cs_simp: cat_cs_simps cat_comma_cs_simps \n              cs_intro: cat_comma_cs_intros cat_cs_intros\n          )\n    qed\n  qed \n    (\n      use assms in \n        \\<open>\n          cs_concl cs_shallow\n            cs_simp: cat_comma_cs_simps\n            cs_intro: cat_cs_intros cat_comma_cs_intros\n        \\<close>\n    )+\nqed\n\nlemma cf_comma_proj_left_is_functor'[cat_comma_cs_intros]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<AA>' = \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\"\n  shows \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH> : \\<AA>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n  using assms(1,2) unfolding assms(3) by (rule cf_comma_proj_left_is_functor)\n\nlemma cf_comma_proj_right_is_functor:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH> : \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\nproof-\n  interpret \\<GG>: is_functor \\<alpha> \\<AA> \\<CC> \\<GG> by (rule assms(1))\n  interpret \\<HH>: is_functor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule assms(2))\n  from assms interpret \\<GG>\\<HH>: category \\<alpha> \\<open>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)\n  show ?thesis\n  proof(rule is_functorI')\n    show \"vfsequence (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>)\"\n      unfolding cf_comma_proj_right_def by auto\n    show \"vcard (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>) = 4\\<^sub>\\<nat>\"\n      unfolding cf_comma_proj_right_def by (simp add: nat_omega_simps)\n    from assms show \"\\<R>\\<^sub>\\<circ> (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ObjMap\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n      by (rule cf_comma_proj_right_ObjMap_vrange)\n    show \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr> : \\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>B\\<rparr>\"\n      if \"F : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\" for A B F\n    proof-\n      from assms that obtain a b f a' b' f' g h\n        where F_def: \"F = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n          and A_def: \"A = [a, b, f]\\<^sub>\\<circ>\"\n          and B_def: \"B = [a', b', f']\\<^sub>\\<circ>\"\n          and h: \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n        by auto\n      from that h show \n        \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr> : \\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>B\\<rparr>\"\n        unfolding F_def A_def B_def\n        by (cs_concl cs_simp: cat_comma_cs_simps cs_intro: cat_cs_intros)\n    qed\n    show \n      \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>G \\<circ>\\<^sub>A\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> F\\<rparr> =\n        \\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>G\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr>\"\n      if \"G : B \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> C\" and \"F : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\" for B C G A F\n    proof-\n      from assms that(2) obtain a b f a' b' f' g h\n        where F_def: \"F = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n          and A_def: \"A = [a, b, f]\\<^sub>\\<circ>\"\n          and B_def: \"B = [a', b', f']\\<^sub>\\<circ>\"\n          and g: \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n          and h: \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n          and f: \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n          and f': \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n          and [cat_cs_simps]: \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\n        by auto\n      with that(1) assms obtain a'' b'' f'' g' h'\n        where G_def: \"G = [[a', b', f']\\<^sub>\\<circ>, [a'', b'', f'']\\<^sub>\\<circ>, [g', h']\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n          and C_def: \"C = [a'', b'', f'']\\<^sub>\\<circ>\"\n          and g': \"g' : a' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a''\"\n          and h': \"h' : b' \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b''\"\n          and f'': \"f'' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a''\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b''\\<rparr>\"\n          and [cat_cs_simps]: \"f'' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g'\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f'\"\n        by auto (*slow*)\n      note [cat_cs_simps] = \n        category.cat_assoc_helper\n          [\n            where \\<CC>=\\<CC> \n              and h=f'' \n              and g=\\<open>\\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g'\\<rparr>\\<close> \n              and q=\\<open>\\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f'\\<close>\n          ]\n        category.cat_assoc_helper\n          [\n            where \\<CC>=\\<CC> \n              and h=f \n              and g=\\<open>\\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr>\\<close> \n              and q=\\<open>f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr>\\<close>\n          ]\n      from assms that g g' h h' f f' f'' show ?thesis\n        unfolding F_def G_def A_def B_def C_def\n        by \n          (\n            cs_concl cs_shallow\n              cs_simp: cat_cs_simps cat_comma_cs_simps\n              cs_intro: cat_comma_cs_intros cat_cs_intros\n          )\n    qed\n    show \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>CId\\<rparr>\\<lparr>A\\<rparr>\\<rparr> = \\<BB>\\<lparr>CId\\<rparr>\\<lparr>\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr>\\<rparr>\"\n      if \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\" for A\n    proof-\n      from assms that obtain a b f \n        where A_def: \"A = [a, b, f]\\<^sub>\\<circ>\"\n          and \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n          and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" \n          and \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n        by auto\n      from assms that this(2-4) show ?thesis\n        unfolding A_def\n        by\n          (\n            cs_concl cs_shallow\n              cs_simp: cat_cs_simps cat_comma_cs_simps\n              cs_intro: cat_comma_cs_intros cat_cs_intros\n          )\n    qed\n  qed \n    (\n      use assms in\n        \\<open>\n          cs_concl cs_shallow\n            cs_simp: cat_comma_cs_simps\n            cs_intro: cat_cs_intros cat_comma_cs_intros\n        \\<close>\n    )+\nqed\n\nlemma cf_comma_proj_right_is_functor'[cat_comma_cs_intros]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<AA>' = \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\"\n  shows \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH> : \\<AA>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  using assms(1,2) unfolding assms(3) by (rule cf_comma_proj_right_is_functor)\n\n\nsubsubsection\\<open>Opposite projections for a comma category\\<close>\n\nlemma op_cf_comma_proj_left: \n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"op_cf (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>) = (op_cf \\<HH>) \\<Sqinter>\\<^sub>C\\<^sub>F (op_cf \\<GG>) \\<circ>\\<^sub>C\\<^sub>F op_cf_comma \\<GG> \\<HH>\"\nproof-\n  interpret \\<GG>: is_functor \\<alpha> \\<AA> \\<CC> \\<GG> by (rule assms(1))\n  interpret \\<HH>: is_functor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule assms(2))\n  interpret \\<GG>\\<HH>: category \\<alpha> \\<open>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_comma_cs_intros)\n  show \"op_cf (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>) = (op_cf \\<HH>) \\<Sqinter>\\<^sub>C\\<^sub>F (op_cf \\<GG>) \\<circ>\\<^sub>C\\<^sub>F op_cf_comma \\<GG> \\<HH>\"\n  proof(rule cf_eqI)\n    show \"op_cf (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>) : op_cat (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>) \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_cat \\<AA>\"\n      by \n        (\n          cs_concl cs_shallow \n            cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros\n        )\n    then have ObjMap_dom_lhs: \"\\<D>\\<^sub>\\<circ> (op_cf (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>)\\<lparr>ObjMap\\<rparr>) = \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n      and ArrMap_dom_lhs: \"\\<D>\\<^sub>\\<circ> (op_cf (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>)\\<lparr>ArrMap\\<rparr>) = \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n      by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps cat_op_simps)+\n    show \"(op_cf \\<HH>) \\<Sqinter>\\<^sub>C\\<^sub>F (op_cf \\<GG>) \\<circ>\\<^sub>C\\<^sub>F op_cf_comma \\<GG> \\<HH> :\n      op_cat (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>) \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_cat \\<AA>\"\n      by (cs_concl cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros)\n    then have ObjMap_dom_rhs:\n      \"\\<D>\\<^sub>\\<circ> (((op_cf \\<HH>) \\<Sqinter>\\<^sub>C\\<^sub>F (op_cf \\<GG>) \\<circ>\\<^sub>C\\<^sub>F op_cf_comma \\<GG> \\<HH>)\\<lparr>ObjMap\\<rparr>) =\n        \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n      and ArrMap_dom_rhs: \n        \"\\<D>\\<^sub>\\<circ> (((op_cf \\<HH>) \\<Sqinter>\\<^sub>C\\<^sub>F (op_cf \\<GG>) \\<circ>\\<^sub>C\\<^sub>F op_cf_comma \\<GG> \\<HH>)\\<lparr>ArrMap\\<rparr>) =\n          \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n      by (cs_concl cs_simp: cat_cs_simps cat_op_simps)+\n    show\n      \"op_cf (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>)\\<lparr>ObjMap\\<rparr> =\n        ((op_cf \\<HH>) \\<Sqinter>\\<^sub>C\\<^sub>F (op_cf \\<GG>) \\<circ>\\<^sub>C\\<^sub>F op_cf_comma \\<GG> \\<HH>)\\<lparr>ObjMap\\<rparr>\"\n    proof(rule vsv_eqI, unfold ObjMap_dom_lhs ObjMap_dom_rhs)\n      fix A assume \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n      with assms obtain a b f \n        where A_def: \"A = [a, b, f]\\<^sub>\\<circ>\"\n          and a: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n          and b: \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n          and f: \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n        by auto\n      from a b f show \n        \"op_cf (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>)\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> =\n          ((op_cf \\<HH>) \\<Sqinter>\\<^sub>C\\<^sub>F (op_cf \\<GG>) \\<circ>\\<^sub>C\\<^sub>F op_cf_comma \\<GG> \\<HH>)\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr>\"\n        unfolding A_def\n        by\n          (\n            cs_concl cs_shallow\n              cs_simp: cat_cs_simps cat_comma_cs_simps cat_op_simps\n              cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros\n          )\n    qed\n      (\n        cs_concl cs_shallow\n          cs_simp: cat_op_simps\n          cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros\n      )+\n    show \n      \"op_cf (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>)\\<lparr>ArrMap\\<rparr> =\n        ((op_cf \\<HH>) \\<Sqinter>\\<^sub>C\\<^sub>F (op_cf \\<GG>) \\<circ>\\<^sub>C\\<^sub>F op_cf_comma \\<GG> \\<HH>)\\<lparr>ArrMap\\<rparr>\"\n    proof(rule vsv_eqI, unfold ArrMap_dom_lhs ArrMap_dom_rhs)\n      fix ABF assume \"ABF \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n      then obtain A B where \"ABF : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\" by auto\n      with assms obtain a b f a' b' f' g h\n        where ABF_def: \"ABF = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n          and A_def: \"A = [a, b, f]\\<^sub>\\<circ>\"\n          and B_def: \"B = [a', b', f']\\<^sub>\\<circ>\"\n          and g: \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n          and h: \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n          and f: \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n          and f': \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n          and [symmetric, cat_cs_simps]: \n            \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\n        by auto\n      from g h f f' show \"op_cf (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>)\\<lparr>ArrMap\\<rparr>\\<lparr>ABF\\<rparr> =\n        ((op_cf \\<HH>) \\<Sqinter>\\<^sub>C\\<^sub>F (op_cf \\<GG>) \\<circ>\\<^sub>C\\<^sub>F op_cf_comma \\<GG> \\<HH>)\\<lparr>ArrMap\\<rparr>\\<lparr>ABF\\<rparr>\"\n        unfolding ABF_def A_def B_def\n        by\n          (\n            cs_concl \n              cs_simp: cat_cs_simps cat_comma_cs_simps cat_op_simps\n              cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros\n          )\n    qed \n      (\n        cs_concl cs_shallow\n          cs_simp: cat_op_simps\n          cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros\n      )+\n  qed simp_all\nqed\n\nlemma op_cf_comma_proj_right:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"op_cf (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>) = (op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<Sqinter> (op_cf \\<GG>) \\<circ>\\<^sub>C\\<^sub>F op_cf_comma \\<GG> \\<HH>\"\nproof-\n  interpret \\<GG>: is_functor \\<alpha> \\<AA> \\<CC> \\<GG> by (rule assms(1))\n  interpret \\<HH>: is_functor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule assms(2))\n  interpret \\<GG>\\<HH>: category \\<alpha> \\<open>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<close>\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_comma_cs_intros)\n  show \"op_cf (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>) = (op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<Sqinter> (op_cf \\<GG>) \\<circ>\\<^sub>C\\<^sub>F op_cf_comma \\<GG> \\<HH>\"\n  proof(rule cf_eqI)\n    show \"op_cf (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>) : op_cat (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>) \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_cat \\<BB>\"\n      by \n        (\n          cs_concl cs_shallow \n            cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros\n        )\n    then have ObjMap_dom_lhs: \"\\<D>\\<^sub>\\<circ> (op_cf (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>ObjMap\\<rparr>) = \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n      and ArrMap_dom_lhs: \"\\<D>\\<^sub>\\<circ> (op_cf (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>ArrMap\\<rparr>) = \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n      by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps cat_op_simps)+\n    show \"(op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<Sqinter> (op_cf \\<GG>) \\<circ>\\<^sub>C\\<^sub>F op_cf_comma \\<GG> \\<HH> :\n      op_cat (\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>) \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_cat \\<BB>\"\n      by (cs_concl cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros)\n    then have ObjMap_dom_rhs:\n      \"\\<D>\\<^sub>\\<circ> (((op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<Sqinter> (op_cf \\<GG>) \\<circ>\\<^sub>C\\<^sub>F op_cf_comma \\<GG> \\<HH>)\\<lparr>ObjMap\\<rparr>) =\n        \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n      and ArrMap_dom_rhs:\n        \"\\<D>\\<^sub>\\<circ> (((op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<Sqinter> (op_cf \\<GG>) \\<circ>\\<^sub>C\\<^sub>F op_cf_comma \\<GG> \\<HH>)\\<lparr>ArrMap\\<rparr>) =\n          \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n      by (cs_concl cs_simp: cat_cs_simps cat_op_simps)+\n    show\n      \"op_cf (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>ObjMap\\<rparr> =\n        ((op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<Sqinter> (op_cf \\<GG>) \\<circ>\\<^sub>C\\<^sub>F op_cf_comma \\<GG> \\<HH>)\\<lparr>ObjMap\\<rparr>\"\n    proof(rule vsv_eqI, unfold ObjMap_dom_lhs ObjMap_dom_rhs)\n      fix A assume prems: \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\"\n      with assms obtain a b f \n        where A_def: \"A = [a, b, f]\\<^sub>\\<circ>\"\n          and a: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n          and b: \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n          and f: \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n        by auto\n      from a b f show\n        \"op_cf (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> =\n          ((op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<Sqinter> (op_cf \\<GG>) \\<circ>\\<^sub>C\\<^sub>F op_cf_comma \\<GG> \\<HH>)\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr>\"\n        unfolding A_def\n        by\n          (\n            cs_concl cs_shallow\n              cs_simp: cat_cs_simps cat_comma_cs_simps cat_op_simps\n              cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros\n          )\n    qed\n      (\n        cs_concl cs_shallow\n          cs_simp: cat_op_simps\n          cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros\n      )+\n    show \n      \"op_cf (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>ArrMap\\<rparr> =\n        ((op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<Sqinter> (op_cf \\<GG>) \\<circ>\\<^sub>C\\<^sub>F op_cf_comma \\<GG> \\<HH>)\\<lparr>ArrMap\\<rparr>\"\n    proof(rule vsv_eqI, unfold ArrMap_dom_lhs ArrMap_dom_rhs)\n      fix ABF assume prems: \"ABF \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\"\n      then obtain A B where ABF: \"ABF : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\" by auto\n      with assms obtain a b f a' b' f' g h\n        where ABF_def: \"ABF = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n          and A_def: \"A = [a, b, f]\\<^sub>\\<circ>\"\n          and B_def: \"B = [a', b', f']\\<^sub>\\<circ>\"\n          and g: \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n          and h: \"h : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b'\"\n          and f: \"f : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n          and f': \"f' : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n          and [symmetric, cat_cs_simps]: \n            \"f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\n        by auto\n      from g h f f' show \"op_cf (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>ArrMap\\<rparr>\\<lparr>ABF\\<rparr> =\n        ((op_cf \\<HH>) \\<^sub>C\\<^sub>F\\<Sqinter> (op_cf \\<GG>) \\<circ>\\<^sub>C\\<^sub>F op_cf_comma \\<GG> \\<HH>)\\<lparr>ArrMap\\<rparr>\\<lparr>ABF\\<rparr>\"\n        unfolding ABF_def A_def B_def\n        by\n          (\n            cs_concl \n              cs_simp: cat_cs_simps cat_comma_cs_simps cat_op_simps\n              cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros\n          )\n    qed \n      (\n        cs_concl cs_shallow\n          cs_simp: cat_op_simps\n          cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros\n      )+\n  qed simp_all\nqed\n\n\nsubsubsection\\<open>Projections for a tiny comma category\\<close>\n\nlemma cf_comma_proj_left_is_tm_functor:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH> : \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\nproof(intro is_tm_functorI')\n\n  interpret \\<GG>: is_tm_functor \\<alpha> \\<AA> \\<CC> \\<GG> by (rule assms(1))\n  interpret \\<HH>: is_tm_functor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule assms(2))\n\n  show \\<Pi>_\\<GG>\\<HH>: \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH> : \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_comma_cs_intros)\n\n  interpret \\<Pi>_\\<GG>\\<HH>: is_functor \\<alpha> \\<open>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<close> \\<AA> \\<open>\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<close>\n    by (rule \\<Pi>_\\<GG>\\<HH>)\n  interpret \\<GG>\\<HH>: tiny_category \\<alpha> \\<open>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<close> \n    by (cs_concl cs_shallow cs_intro: cat_small_cs_intros cat_comma_cs_intros)\n\n  show \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ObjMap\\<rparr> \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n  proof(rule vbrelation.vbrelation_Limit_in_VsetI)\n    show \"\\<R>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ObjMap\\<rparr>) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n    proof-\n      note \\<Pi>_\\<GG>\\<HH>.cf_ObjMap_vrange\n      moreover have \"\\<AA>\\<lparr>Obj\\<rparr> \\<in>\\<^sub>\\<circ> Vset \\<alpha>\" by (intro cat_small_cs_intros)\n      ultimately show ?thesis by auto\n    qed\n  qed (auto simp: cf_comma_proj_left_components intro: cat_small_cs_intros)\n\n  show \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ArrMap\\<rparr> \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n  proof(rule vbrelation.vbrelation_Limit_in_VsetI)\n    show \"\\<R>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ArrMap\\<rparr>) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n    proof-\n      note \\<Pi>_\\<GG>\\<HH>.cf_ArrMap_vrange\n      moreover have \"\\<AA>\\<lparr>Arr\\<rparr> \\<in>\\<^sub>\\<circ> Vset \\<alpha>\" by (intro cat_small_cs_intros)\n      ultimately show ?thesis by auto\n    qed\n  qed (auto simp: cf_comma_proj_left_components intro: cat_small_cs_intros)\n\nqed\n\nlemma cf_comma_proj_left_is_tm_functor'[cat_comma_cs_intros]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<GG>\\<HH> = \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\"\n  shows \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH> : \\<GG>\\<HH> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n  using assms(1,2) unfolding assms(3) by (rule cf_comma_proj_left_is_tm_functor)\n\nlemma cf_comma_proj_right_is_tm_functor:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH> : \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\nproof(intro is_tm_functorI')\n\n  interpret \\<GG>: is_tm_functor \\<alpha> \\<AA> \\<CC> \\<GG> by (rule assms(1))\n  interpret \\<HH>: is_tm_functor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule assms(2))\n\n  show \\<Pi>_\\<GG>\\<HH>: \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH> : \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_comma_cs_intros)\n\n  interpret \\<Pi>_\\<GG>\\<HH>: is_functor \\<alpha> \\<open>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<close> \\<BB> \\<open>\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<close>\n    by (rule \\<Pi>_\\<GG>\\<HH>)\n  interpret \\<GG>\\<HH>: tiny_category \\<alpha> \\<open>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<close> \n    by (cs_concl cs_shallow cs_intro: cat_small_cs_intros cat_comma_cs_intros)\n\n  show \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ObjMap\\<rparr> \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n  proof(rule vbrelation.vbrelation_Limit_in_VsetI)\n    show \"\\<R>\\<^sub>\\<circ> (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ObjMap\\<rparr>) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n    proof-\n      note \\<Pi>_\\<GG>\\<HH>.cf_ObjMap_vrange\n      moreover have \"\\<BB>\\<lparr>Obj\\<rparr> \\<in>\\<^sub>\\<circ> Vset \\<alpha>\" by (intro cat_small_cs_intros)\n      ultimately show ?thesis by auto\n    qed\n  qed (auto simp: cf_comma_proj_right_components intro: cat_small_cs_intros)\n\n  show \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ArrMap\\<rparr> \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n  proof(rule vbrelation.vbrelation_Limit_in_VsetI)\n    show \"\\<R>\\<^sub>\\<circ> (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ArrMap\\<rparr>) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n    proof-\n      note \\<Pi>_\\<GG>\\<HH>.cf_ArrMap_vrange\n      moreover have \"\\<BB>\\<lparr>Arr\\<rparr> \\<in>\\<^sub>\\<circ> Vset \\<alpha>\" by (intro cat_small_cs_intros)\n      ultimately show ?thesis by auto\n    qed\n  qed (auto simp: cf_comma_proj_right_components intro: cat_small_cs_intros)\n\nqed\n\nlemma cf_comma_proj_right_is_tm_functor'[cat_comma_cs_intros]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<GG>\\<HH> = \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\"\n  shows \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH> : \\<GG>\\<HH> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  using assms(1,2) unfolding assms(3) by (rule cf_comma_proj_right_is_tm_functor)\n\n\nlemma cf_comp_cf_comma_proj_left_is_tm_functor[cat_comma_cs_intros]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\"\n  shows \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH> \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\nproof(intro is_tm_functorI')\n\n  interpret \\<GG>: is_functor \\<alpha> \\<AA> \\<CC> \\<GG> by (rule assms(1))\n  interpret \\<HH>: is_functor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule assms(2))\n  interpret \\<FF>: is_tm_functor \\<alpha> \\<JJ> \\<open>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<close> \\<FF> by (rule assms(3))\n  interpret \\<GG>\\<HH>: is_functor \\<alpha> \\<open>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<close> \\<AA> \\<open>\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<close>\n    by (rule cf_comma_proj_left_is_functor[OF assms(1-2)])\n\n  show \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH> \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n    by (cs_concl cs_intro: cat_cs_intros cat_comma_cs_intros)\n\n  show \"(\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH> \\<circ>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ObjMap\\<rparr> \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n    unfolding dghm_comp_components\n  proof(rule vbrelation.vbrelation_Limit_in_VsetI)\n    show \"vbrelation (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ObjMap\\<rparr> \\<circ>\\<^sub>\\<circ> \\<FF>\\<lparr>ObjMap\\<rparr>)\" by auto\n    show \"Limit \\<alpha>\" by auto\n    show \"\\<D>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ObjMap\\<rparr> \\<circ>\\<^sub>\\<circ> \\<FF>\\<lparr>ObjMap\\<rparr>) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n      by\n        (\n          cs_concl \n            cs_simp: V_cs_simps cat_cs_simps\n            cs_intro: \\<FF>.cf_ObjMap_vrange cat_small_cs_intros\n        )\n    show \"\\<R>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ObjMap\\<rparr> \\<circ>\\<^sub>\\<circ> \\<FF>\\<lparr>ObjMap\\<rparr>) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n      unfolding vrange_vcomp\n    proof-\n      have \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ObjMap\\<rparr> `\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ObjMap\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ObjMap\\<rparr>))))\"\n      proof(intro vsubsetI)\n        fix A assume prems: \"A \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ObjMap\\<rparr> `\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ObjMap\\<rparr>)\"\n        then obtain abf \n          where abf_in_\\<FF>: \"abf \\<in>\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ObjMap\\<rparr>)\"\n            and \\<GG>\\<HH>_abf: \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ObjMap\\<rparr>\\<lparr>abf\\<rparr> = A\"\n          by auto\n        with \\<FF>.ObjMap.vrange_atD obtain j \n          where \"j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr>\" and \\<FF>j: \"\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>j\\<rparr> = abf\"\n          by (force simp: \\<FF>.cf_ObjMap_vdomain)\n        from abf_in_\\<FF> \\<FF>.cf_ObjMap_vrange have abf_in_\\<GG>\\<HH>: \n          \"abf \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\" \n          by auto\n        then obtain a b f where abf_def: \"abf = [a, b, f]\\<^sub>\\<circ>\"\n          by (elim cat_comma_ObjE[OF _ assms(1,2)])\n        have \"a \\<in>\\<^sub>\\<circ> \\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ObjMap\\<rparr>))))\"\n        proof(intro VUnionI)\n          from abf_in_\\<FF> show \"[a, b, f]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ObjMap\\<rparr>)\"\n            unfolding abf_def by auto\n          show \"\\<langle>0, a\\<rangle> \\<in>\\<^sub>\\<circ> [a, b, f]\\<^sub>\\<circ>\" by auto\n          show \"set {0, a} \\<in>\\<^sub>\\<circ> \\<langle>0, a\\<rangle>\" unfolding vpair_def by simp\n        qed auto\n        with abf_in_\\<GG>\\<HH> show \"A \\<in>\\<^sub>\\<circ> \\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<R>\\<^sub>\\<circ>(\\<FF>\\<lparr>ObjMap\\<rparr>))))\"\n          unfolding \\<GG>\\<HH>_abf[symmetric] abf_def\n          by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps)\n      qed\n      moreover have \"\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ObjMap\\<rparr>)))) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n        by (intro VUnion_in_VsetI vrange_in_VsetI[OF \\<FF>.tm_cf_ObjMap_in_Vset])\n      ultimately show \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ObjMap\\<rparr> `\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ObjMap\\<rparr>) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\" by auto\n    qed\n  qed\n\n  show \"(\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH> \\<circ>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ArrMap\\<rparr> \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n    unfolding dghm_comp_components\n  proof(rule vbrelation.vbrelation_Limit_in_VsetI)\n    show \"vbrelation (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ArrMap\\<rparr> \\<circ>\\<^sub>\\<circ> \\<FF>\\<lparr>ArrMap\\<rparr>)\" by auto\n    show \"Limit \\<alpha>\" by auto\n    show \"\\<D>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ArrMap\\<rparr> \\<circ>\\<^sub>\\<circ> \\<FF>\\<lparr>ArrMap\\<rparr>) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n      by\n        (\n          cs_concl\n            cs_simp: V_cs_simps cat_cs_simps\n            cs_intro: \\<FF>.cf_ArrMap_vrange cat_small_cs_intros\n        )\n    show \"\\<R>\\<^sub>\\<circ> (\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ArrMap\\<rparr> \\<circ>\\<^sub>\\<circ> \\<FF>\\<lparr>ArrMap\\<rparr>) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n      unfolding vrange_vcomp\n    proof-\n      have \n        \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ArrMap\\<rparr> `\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ArrMap\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \n          \\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ArrMap\\<rparr>)))))))\"\n      proof(intro vsubsetI)\n        fix F assume prems: \"F \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ArrMap\\<rparr> `\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ArrMap\\<rparr>)\"\n        then obtain ABF \n          where ABF_in_\\<FF>: \"ABF \\<in>\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ArrMap\\<rparr>)\"\n            and \\<GG>\\<HH>_ABF: \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>ABF\\<rparr> = F\"\n          by auto\n        with \\<FF>.ArrMap.vrange_atD obtain k \n          where \"k \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Arr\\<rparr>\" and \\<FF>j: \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>k\\<rparr> = ABF\"\n          by (force simp: \\<FF>.cf_ArrMap_vdomain)\n        then obtain i j where \"k : i \\<mapsto>\\<^bsub>\\<JJ>\\<^esub> j\" by auto\n        from ABF_in_\\<FF> \\<FF>.cf_ArrMap_vrange have ABF_in_\\<GG>\\<HH>: \n          \"ABF \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\" \n          by auto\n        then obtain A B where \"ABF : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\" by auto\n        with assms obtain a b f a' b' f' g h\n          where ABF_def: \"ABF = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n          by (elim cat_comma_is_arrE[OF _ assms(1,2)])\n        have \"g \\<in>\\<^sub>\\<circ> \\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ArrMap\\<rparr>)))))))\"\n        proof(intro VUnionI)\n          from ABF_in_\\<FF> show \n            \"[[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ArrMap\\<rparr>)\"\n            unfolding ABF_def by auto\n          show \"\\<langle>2\\<^sub>\\<nat>, [g, h]\\<^sub>\\<circ>\\<rangle> \\<in>\\<^sub>\\<circ> [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n            by (auto simp: nat_omega_simps)\n          show \"set {2\\<^sub>\\<nat>, [g, h]\\<^sub>\\<circ>} \\<in>\\<^sub>\\<circ> \\<langle>2\\<^sub>\\<nat>, [g, h]\\<^sub>\\<circ>\\<rangle>\"\n            unfolding vpair_def by auto\n          show \"[g, h]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> set {2\\<^sub>\\<nat>, [g, h]\\<^sub>\\<circ>}\" by simp\n          show \"\\<langle>0, g\\<rangle> \\<in>\\<^sub>\\<circ> [g, h]\\<^sub>\\<circ>\" by auto\n          show \"set {0, g} \\<in>\\<^sub>\\<circ> \\<langle>0, g\\<rangle>\" unfolding vpair_def by auto\n        qed auto\n        with ABF_in_\\<GG>\\<HH> show \"F \\<in>\\<^sub>\\<circ> \\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ArrMap\\<rparr>)))))))\"\n          unfolding \\<GG>\\<HH>_ABF[symmetric] ABF_def\n          by (cs_concl cs_simp: cat_cs_simps cat_comma_cs_simps)\n      qed\n      moreover have \"\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ArrMap\\<rparr>))))))) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n        by (intro VUnion_in_VsetI vrange_in_VsetI[OF \\<FF>.tm_cf_ArrMap_in_Vset])\n      ultimately show \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter> \\<HH>\\<lparr>ArrMap\\<rparr> `\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ArrMap\\<rparr>) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\" by auto\n    qed\n  qed\n\nqed\n\nlemma cf_comp_cf_comma_proj_right_is_tm_functor[cat_comma_cs_intros]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \n    and \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\"\n  shows \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH> \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\nproof(intro is_tm_functorI')\n\n  interpret \\<GG>: is_functor \\<alpha> \\<AA> \\<CC> \\<GG> by (rule assms(1))\n  interpret \\<HH>: is_functor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule assms(2))\n  interpret \\<FF>: is_tm_functor \\<alpha> \\<JJ> \\<open>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<close> \\<FF> by (rule assms(3))\n  interpret \\<GG>\\<HH>: is_functor \\<alpha> \\<open>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<close> \\<BB> \\<open>\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<close>\n    by (rule cf_comma_proj_right_is_functor[OF assms(1-2)])\n\n  show \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH> \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: cat_cs_intros cat_comma_cs_intros)\n\n  show \"(\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH> \\<circ>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ObjMap\\<rparr> \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n    unfolding dghm_comp_components\n  proof(rule vbrelation.vbrelation_Limit_in_VsetI)\n    show \"vbrelation (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ObjMap\\<rparr> \\<circ>\\<^sub>\\<circ> \\<FF>\\<lparr>ObjMap\\<rparr>)\" by auto\n    show \"Limit \\<alpha>\" by auto\n    show \"\\<D>\\<^sub>\\<circ> (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ObjMap\\<rparr> \\<circ>\\<^sub>\\<circ> \\<FF>\\<lparr>ObjMap\\<rparr>) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n      by\n        (\n          cs_concl \n            cs_simp: V_cs_simps cat_cs_simps\n            cs_intro: \\<FF>.cf_ObjMap_vrange cat_small_cs_intros\n        )\n    show \"\\<R>\\<^sub>\\<circ> (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ObjMap\\<rparr> \\<circ>\\<^sub>\\<circ> \\<FF>\\<lparr>ObjMap\\<rparr>) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n      unfolding vrange_vcomp\n    proof-\n      have \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ObjMap\\<rparr> `\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ObjMap\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ObjMap\\<rparr>))))\"\n      proof(intro vsubsetI)\n        fix A assume prems: \"A \\<in>\\<^sub>\\<circ> (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>ObjMap\\<rparr> `\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ObjMap\\<rparr>)\"\n        then obtain abf \n          where abf_in_\\<FF>: \"abf \\<in>\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ObjMap\\<rparr>)\"\n            and \\<GG>\\<HH>_abf: \"(\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>)\\<lparr>ObjMap\\<rparr>\\<lparr>abf\\<rparr> = A\"\n          by (auto simp: cf_comma_proj_right_ObjMap_vsv)\n        with \\<FF>.ObjMap.vrange_atD obtain j \n          where \"j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr>\" and \\<FF>j: \"\\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>j\\<rparr> = abf\"\n          by (force simp: \\<FF>.cf_ObjMap_vdomain)\n        from abf_in_\\<FF> \\<FF>.cf_ObjMap_vrange have abf_in_\\<GG>\\<HH>: \n          \"abf \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Obj\\<rparr>\" \n          by auto\n        then obtain a b f where abf_def: \"abf = [a, b, f]\\<^sub>\\<circ>\"\n          by (elim cat_comma_ObjE[OF _ assms(1,2)])\n        have \"b \\<in>\\<^sub>\\<circ> \\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ObjMap\\<rparr>))))\"\n        proof(intro VUnionI)\n          from abf_in_\\<FF> show \"[a, b, f]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ObjMap\\<rparr>)\"\n            unfolding abf_def by auto\n          show \"\\<langle>1\\<^sub>\\<nat>, b\\<rangle> \\<in>\\<^sub>\\<circ> [a, b, f]\\<^sub>\\<circ>\" by (auto simp: nat_omega_simps)\n          show \"set {1\\<^sub>\\<nat>, b} \\<in>\\<^sub>\\<circ> \\<langle>1\\<^sub>\\<nat>, b\\<rangle>\" unfolding vpair_def by simp\n        qed auto\n        with abf_in_\\<GG>\\<HH> show \"A \\<in>\\<^sub>\\<circ> \\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<R>\\<^sub>\\<circ>(\\<FF>\\<lparr>ObjMap\\<rparr>))))\"\n          unfolding \\<GG>\\<HH>_abf[symmetric] abf_def\n          by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps)\n      qed\n      moreover have \"\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ObjMap\\<rparr>)))) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n        by (intro VUnion_in_VsetI vrange_in_VsetI[OF \\<FF>.tm_cf_ObjMap_in_Vset])\n      ultimately show \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ObjMap\\<rparr> `\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ObjMap\\<rparr>) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\" by auto\n    qed\n  qed\n\n  show \"(\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH> \\<circ>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ArrMap\\<rparr> \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n    unfolding dghm_comp_components\n  proof(rule vbrelation.vbrelation_Limit_in_VsetI)\n    show \"vbrelation (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ArrMap\\<rparr> \\<circ>\\<^sub>\\<circ> \\<FF>\\<lparr>ArrMap\\<rparr>)\" by auto\n    show \"Limit \\<alpha>\" by auto\n    show \"\\<D>\\<^sub>\\<circ> (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ArrMap\\<rparr> \\<circ>\\<^sub>\\<circ> \\<FF>\\<lparr>ArrMap\\<rparr>) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n      by\n        (\n          cs_concl \n            cs_simp: V_cs_simps cat_cs_simps\n            cs_intro: \\<FF>.cf_ArrMap_vrange cat_small_cs_intros\n        )\n    show \"\\<R>\\<^sub>\\<circ> (\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ArrMap\\<rparr> \\<circ>\\<^sub>\\<circ> \\<FF>\\<lparr>ArrMap\\<rparr>) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n      unfolding vrange_vcomp\n    proof-\n      have \n        \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ArrMap\\<rparr> `\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ArrMap\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \n          \\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ArrMap\\<rparr>)))))))\"\n      proof(intro vsubsetI)\n        fix F assume prems: \"F \\<in>\\<^sub>\\<circ> \\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ArrMap\\<rparr> `\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ArrMap\\<rparr>)\"\n        then obtain ABF \n          where ABF_in_\\<FF>: \"ABF \\<in>\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ArrMap\\<rparr>)\"\n            and \\<GG>\\<HH>_ABF: \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ArrMap\\<rparr>\\<lparr>ABF\\<rparr> = F\"\n          by (auto simp: cf_comma_proj_right_ArrMap_vsv)\n        with \\<FF>.ArrMap.vrange_atD obtain k \n          where \"k \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Arr\\<rparr>\" and \\<FF>j: \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>k\\<rparr> = ABF\"\n          by (force simp: \\<FF>.cf_ArrMap_vdomain)\n        then obtain i j where \"k : i \\<mapsto>\\<^bsub>\\<JJ>\\<^esub> j\" by auto\n        from ABF_in_\\<FF> \\<FF>.cf_ArrMap_vrange have ABF_in_\\<GG>\\<HH>: \n          \"ABF \\<in>\\<^sub>\\<circ> \\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>Arr\\<rparr>\" \n          by auto\n        then obtain A B where \"ABF : A \\<mapsto>\\<^bsub>\\<GG> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<HH>\\<^esub> B\" by auto\n        with assms obtain a b f a' b' f' g h\n          where ABF_def: \"ABF = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n          by (elim cat_comma_is_arrE[OF _ assms(1,2)])\n        have \"h \\<in>\\<^sub>\\<circ> \\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ArrMap\\<rparr>)))))))\"\n        proof(intro VUnionI)\n          from ABF_in_\\<FF> show \n            \"[[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ArrMap\\<rparr>)\"\n            unfolding ABF_def by auto\n          show \"\\<langle>2\\<^sub>\\<nat>, [g, h]\\<^sub>\\<circ>\\<rangle> \\<in>\\<^sub>\\<circ> [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n            by (auto simp: nat_omega_simps)\n          show \"set {2\\<^sub>\\<nat>, [g, h]\\<^sub>\\<circ>} \\<in>\\<^sub>\\<circ> \\<langle>2\\<^sub>\\<nat>, [g, h]\\<^sub>\\<circ>\\<rangle>\"\n            unfolding vpair_def by auto\n          show \"[g, h]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> set {2\\<^sub>\\<nat>, [g, h]\\<^sub>\\<circ>}\" by simp\n          show \"\\<langle>1\\<^sub>\\<nat>, h\\<rangle> \\<in>\\<^sub>\\<circ> [g, h]\\<^sub>\\<circ>\" by (auto simp: nat_omega_simps)\n          show \"set {1\\<^sub>\\<nat>, h} \\<in>\\<^sub>\\<circ> \\<langle>1\\<^sub>\\<nat>, h\\<rangle>\" unfolding vpair_def by auto\n        qed auto\n        with ABF_in_\\<GG>\\<HH> show \"F \\<in>\\<^sub>\\<circ> \\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ArrMap\\<rparr>)))))))\"\n          unfolding \\<GG>\\<HH>_ABF[symmetric] ABF_def\n          by (cs_concl cs_shallow cs_simp: cat_cs_simps cat_comma_cs_simps)\n      qed\n      moreover have \"\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<Union>\\<^sub>\\<circ>(\\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ArrMap\\<rparr>))))))) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\"\n        by (intro VUnion_in_VsetI vrange_in_VsetI[OF \\<FF>.tm_cf_ArrMap_in_Vset])\n      ultimately show \"\\<GG> \\<Sqinter>\\<^sub>C\\<^sub>F \\<HH>\\<lparr>ArrMap\\<rparr> `\\<^sub>\\<circ> \\<R>\\<^sub>\\<circ> (\\<FF>\\<lparr>ArrMap\\<rparr>) \\<in>\\<^sub>\\<circ> Vset \\<alpha>\" by auto\n    qed\n  qed\n\nqed\n\n\n\nsubsection\\<open>Comma categories constructed from a functor and an object\\<close>\n\n\nsubsubsection\\<open>Definitions and elementary properties\\<close>\n\n\ntext\\<open>See Chapter II-6 in \\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>.\\<close>\n\ndefinition cat_cf_obj_comma :: \"V \\<Rightarrow> V \\<Rightarrow> V\" (\\<open>(_ \\<^sub>C\\<^sub>F\\<down> _)\\<close> [1000, 1000] 999)\n  where \"\\<FF> \\<^sub>C\\<^sub>F\\<down> b \\<equiv> \\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (cf_const (cat_1 0 0) (\\<FF>\\<lparr>HomCod\\<rparr>) b)\"\n\ndefinition cat_obj_cf_comma :: \"V \\<Rightarrow> V \\<Rightarrow> V\" (\\<open>(_ \\<down>\\<^sub>C\\<^sub>F _)\\<close> [1000, 1000] 999)\n  where \"b \\<down>\\<^sub>C\\<^sub>F \\<FF> \\<equiv> (cf_const (cat_1 0 0) (\\<FF>\\<lparr>HomCod\\<rparr>) b) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<FF>\"\n\n\ntext\\<open>Alternative forms of the definitions.\\<close>\n\nlemma (in is_functor) cat_cf_obj_comma_def:\n  \"\\<FF> \\<^sub>C\\<^sub>F\\<down> b = \\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (cf_const (cat_1 0 0) \\<BB> b)\" \n  unfolding cat_cf_obj_comma_def cf_HomCod ..\n\nlemma (in is_functor) cat_obj_cf_comma_def:\n  \"b \\<down>\\<^sub>C\\<^sub>F \\<FF> = (cf_const (cat_1 0 0) \\<BB> b) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<FF>\" \n  unfolding cat_obj_cf_comma_def cf_HomCod ..\n\n\ntext\\<open>Size.\\<close>\n\nlemma small_cat_cf_obj_comma_Obj[simp]: \n  \"small {[a, 0, f]\\<^sub>\\<circ> | a f. a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr> \\<and> f : x \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>}\"\n  (is \\<open>small ?afs\\<close>)\nproof-\n  define Q where \n    \"Q i = (if i = 0 then \\<AA>\\<lparr>Obj\\<rparr> else if i = 1\\<^sub>\\<nat> then set {0} else \\<CC>\\<lparr>Arr\\<rparr>)\" \n    for i\n  have \"?afs \\<subseteq> elts (\\<Prod>\\<^sub>\\<circ>i\\<in>\\<^sub>\\<circ> set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}. Q i)\"\n    unfolding Q_def\n  proof\n    (\n      intro subsetI, \n      unfold mem_Collect_eq, \n      elim exE conjE, \n      intro vproductI; \n      simp only:\n    )\n    fix a f show \"\\<D>\\<^sub>\\<circ> [a, 0, f]\\<^sub>\\<circ> = set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}\"\n      by (simp add: three nat_omega_simps)\n  qed (force simp: nat_omega_simps)+\n  then show \"small ?afs\" by (rule down)\nqed\n\nlemma small_cat_obj_cf_comma_Obj[simp]: \n  \"small {[0, b, f]\\<^sub>\\<circ> | b f. b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr> \\<and> f : x \\<mapsto>\\<^bsub>\\<CC>\\<^esub> \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>}\"\n  (is \\<open>small ?bfs\\<close>)\nproof-\n  define Q where\n    \"Q i = (if i = 0 then set {0} else if i = 1\\<^sub>\\<nat> then \\<BB>\\<lparr>Obj\\<rparr> else \\<CC>\\<lparr>Arr\\<rparr>)\" \n    for i\n  have \"?bfs \\<subseteq> elts (\\<Prod>\\<^sub>\\<circ>i\\<in>\\<^sub>\\<circ> set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}. Q i)\"\n    unfolding Q_def\n  proof\n    (\n      intro subsetI, \n      unfold mem_Collect_eq, \n      elim exE conjE, \n      intro vproductI; \n      simp only:\n    )\n    fix a b f show \"\\<D>\\<^sub>\\<circ> [0, b, f]\\<^sub>\\<circ> = set {0, 1\\<^sub>\\<nat>, 2\\<^sub>\\<nat>}\"\n      by (simp add: three nat_omega_simps)\n  qed (force simp: nat_omega_simps)+\n  then show \"small ?bfs\" by (rule down)\nqed\n\n\n\nsubsubsection\\<open>Objects\\<close>\n\nlemma (in is_functor) cat_cf_obj_comma_ObjI[cat_comma_cs_intros]:\n  assumes \"A = [a, 0, f]\\<^sub>\\<circ>\" and \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" and \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n  shows \"A \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\n  using assms(2,3)\n  unfolding assms(1)\n  by\n    (\n      cs_concl \n        cs_simp: cat_cs_simps cat_cf_obj_comma_def \n        cs_intro: cat_cs_intros vempty_is_zet cat_comma_ObjI\n    )\n\nlemmas [cat_comma_cs_intros] = is_functor.cat_cf_obj_comma_ObjI\n\nlemma (in is_functor) cat_obj_cf_comma_ObjI[cat_comma_cs_intros]:\n  assumes \"A = [0, a, f]\\<^sub>\\<circ>\" and \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" and \"f : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n  shows \"A \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n  using assms(2,3)\n  unfolding assms(1)\n  by\n    (\n      cs_concl \n        cs_simp: cat_cs_simps cat_obj_cf_comma_def \n        cs_intro: vempty_is_zet cat_cs_intros cat_comma_ObjI\n    )\n\nlemmas [cat_comma_cs_intros] = is_functor.cat_obj_cf_comma_ObjI\n\nlemma (in is_functor) cat_cf_obj_comma_ObjD[dest]:\n  assumes \"[a, b', f]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\" and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" and \"b' = 0\" and \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\nproof-\n  from assms(2) have \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  note obj = cat_comma_ObjD[\n      OF assms(1)[unfolded cat_cf_obj_comma_def] is_functor_axioms this\n      ]\n  from obj[unfolded cat_1_components] have [cat_cs_simps]: \"b' = 0\" by simp\n  moreover have \"cf_const (cat_1 0 0) \\<BB> b\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr> = b\"\n    by (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  ultimately show \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \"b' = 0\" \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n    using obj by auto\nqed\n\nlemmas [dest] = is_functor.cat_cf_obj_comma_ObjD[rotated 1]\n\nlemma (in is_functor) cat_obj_cf_comma_ObjD[dest]:\n  assumes \"[b', a, f]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\" and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" and \"b' = 0\" and \"f : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\nproof-\n  from assms(2) have \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  note obj = cat_comma_ObjD[\n      OF assms(1)[unfolded cat_obj_cf_comma_def] this is_functor_axioms\n      ]\n  from obj[unfolded cat_1_components] have [cat_cs_simps]: \"b' = 0\" by simp\n  moreover have \"cf_const (cat_1 0 0) \\<BB> b\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr> = b\"\n    by (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  ultimately show \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \"b' = 0\" \"f : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n    using obj by auto\nqed\n\nlemmas [dest] = is_functor.cat_obj_cf_comma_ObjD[rotated 1]\n\nlemma (in is_functor) cat_cf_obj_comma_ObjE[elim]:\n  assumes \"A \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\" and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  obtains a f \n    where \"A = [a, 0, f]\\<^sub>\\<circ>\" \n      and \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n      and \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\nproof-\n  from assms(2) have \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  from assms(1)[unfolded cat_cf_obj_comma_def] is_functor_axioms this \n  obtain a b' f \n    where \"A = [a, b', f]\\<^sub>\\<circ>\"\n      and a: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n      and b': \"b' \\<in>\\<^sub>\\<circ> cat_1 0 0\\<lparr>Obj\\<rparr>\" \n      and f: \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> cf_const (cat_1 0 0) \\<BB> b\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n    by auto\n  moreover from b' have [cat_cs_simps]: \"b' = 0\"\n    unfolding cat_1_components by auto\n  moreover have \"cf_const (cat_1 0 0) \\<BB> b\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr> = b\"\n    by (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  ultimately show ?thesis using that by auto\nqed\n\nlemmas [elim] = is_functor.cat_cf_obj_comma_ObjE[rotated 1]\n\nlemma (in is_functor) cat_obj_cf_comma_ObjE[elim]:\n  assumes \"A \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\" and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  obtains a f \n    where \"A = [0, a, f]\\<^sub>\\<circ>\"\n      and \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n      and \"f : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\nproof-\n  from assms(2) have \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  from assms(1)[unfolded cat_obj_cf_comma_def] is_functor_axioms this \n  obtain a b' f \n    where A_def: \"A = [b', a, f]\\<^sub>\\<circ>\"\n      and a: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n      and b': \"b' \\<in>\\<^sub>\\<circ> cat_1 0 0\\<lparr>Obj\\<rparr>\" \n      and f: \"f : cf_const (cat_1 0 0) \\<BB> b\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n    by auto\n  moreover from b' have [cat_cs_simps]: \"b' = 0\" \n    unfolding cat_1_components by auto\n  moreover have \"cf_const (cat_1 0 0) \\<BB> b\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr> = b\"\n    by (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  ultimately show ?thesis using that by auto\nqed\n\nlemmas [elim] = is_functor.cat_obj_cf_comma_ObjE[rotated 1]\n\n\nsubsubsection\\<open>Arrows\\<close>\n\nlemma (in is_functor) cat_cf_obj_comma_ArrI[cat_comma_cs_intros]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" \n    and \"F = [A, B, [g, 0]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n    and \"A = [a, 0, f]\\<^sub>\\<circ>\"\n    and \"B = [a', 0, f']\\<^sub>\\<circ>\"\n    and \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n    and \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n    and \"f' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n    and \"f' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = f\"\n  shows \"F \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Arr\\<rparr>\"\n  unfolding cat_cf_obj_comma_def\nproof(intro cat_comma_ArrI cat_comma_HomI)\n  show \"\\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\" by (cs_concl cs_shallow cs_intro: cat_cs_intros)\n  from assms(1) show const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  from vempty_is_zet show 0: \"0 : 0 \\<mapsto>\\<^bsub>cat_1 0 0\\<^esub> 0\"\n    by \n      (\n        cs_concl cs_shallow \n          cs_simp: cat_cs_simps cat_1_CId_app cs_intro: cat_cs_intros\n      )\n  from assms(6) show \n    \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> cf_const (cat_1 0 0) \\<BB> b\\<lparr>ObjMap\\<rparr>\\<lparr>0\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  from assms(7) show \n    \"f' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> cf_const (cat_1 0 0) \\<BB> b\\<lparr>ObjMap\\<rparr>\\<lparr>0\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  from 0 assms(6) show \n    \"f' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = cf_const (cat_1 0 0) \\<BB> b\\<lparr>ArrMap\\<rparr>\\<lparr>0\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f\"\n    by \n      (\n        cs_concl cs_shallow \n          cs_simp: cat_cs_simps assms(8) cs_intro: cat_cs_intros\n      )\n  from const assms(5,6) show \"A \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (cf_const (cat_1 0 0) \\<BB> b)\\<lparr>Obj\\<rparr>\"\n    by (fold cat_cf_obj_comma_def)\n      (cs_concl cs_simp: assms(3) cs_intro: cat_cs_intros cat_comma_cs_intros)\n  from const assms(5,7) show \"B \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (cf_const (cat_1 0 0) \\<BB> b)\\<lparr>Obj\\<rparr>\"\n    by (fold cat_cf_obj_comma_def)\n      (\n        cs_concl cs_shallow \n          cs_simp: assms(4) cs_intro: cat_cs_intros cat_comma_cs_intros\n      )\nqed (intro assms)+\n\nlemmas [cat_comma_cs_intros] = is_functor.cat_cf_obj_comma_ArrI\n\nlemma (in is_functor) cat_obj_cf_comma_ArrI[cat_comma_cs_intros]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" \n    and \"F = [A, B, [0, g]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n    and \"A = [0, a, f]\\<^sub>\\<circ>\"\n    and \"B = [0, a', f']\\<^sub>\\<circ>\"\n    and \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n    and \"f : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n    and \"f' : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \"\n    and \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f = f'\"\n  shows \"F \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>\"\n  unfolding cat_obj_cf_comma_def\nproof(intro cat_comma_ArrI cat_comma_HomI)\n  show \"\\<FF> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\" by (cs_concl cs_shallow cs_intro: cat_cs_intros)\n  from assms(1) show const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  from vempty_is_zet show 0: \"0 : 0 \\<mapsto>\\<^bsub>cat_1 0 0\\<^esub> 0\"\n    by (cs_concl cs_shallow cs_simp: cat_1_CId_app cs_intro: cat_cs_intros)\n  from assms(6) show \n    \"f : cf_const (cat_1 0 0) \\<BB> b\\<lparr>ObjMap\\<rparr>\\<lparr>0\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  from assms(7) show \n    \"f' : cf_const (cat_1 0 0) \\<BB> b\\<lparr>ObjMap\\<rparr>\\<lparr>0\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  from 0 assms(7) show \n    \"f' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> cf_const (cat_1 0 0) \\<BB> b\\<lparr>ArrMap\\<rparr>\\<lparr>0\\<rparr> = \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f\"\n    by \n      (\n        cs_concl cs_shallow \n          cs_simp: cat_cs_simps assms(8) cs_intro: cat_cs_intros\n      )\n  from const assms(5,6) show \"A \\<in>\\<^sub>\\<circ> (cf_const (cat_1 0 0) \\<BB> b) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n    by (fold cat_obj_cf_comma_def)\n      (cs_concl cs_simp: assms(3) cs_intro: cat_cs_intros cat_comma_cs_intros)\n  from const assms(5,7) show \"B \\<in>\\<^sub>\\<circ> (cf_const (cat_1 0 0) \\<BB> b) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n    by (fold cat_obj_cf_comma_def)\n      (\n        cs_concl cs_shallow \n          cs_simp: assms(4) cs_intro: cat_cs_intros cat_comma_cs_intros\n      )\nqed (intro assms)+\n\nlemmas [cat_comma_cs_intros] = is_functor.cat_obj_cf_comma_ArrI\n\nlemma (in is_functor) cat_cf_obj_comma_ArrE[elim]:\n  assumes \"F \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Arr\\<rparr>\" and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  obtains A B a f a' f' g\n    where \"F = [A, B, [g, 0]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and \"A = [a, 0, f]\\<^sub>\\<circ>\"\n      and \"B = [a', 0, f']\\<^sub>\\<circ>\"\n      and \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n      and \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n      and \"f' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n      and \"f' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = f\"\n      and \"A \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\n      and \"B \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\nproof-\n  from cat_comma_ArrE[OF assms(1)[unfolded cat_cf_obj_comma_def]] \n  obtain A B \n    where F: \"F \\<in>\\<^sub>\\<circ> cat_comma_Hom \\<FF> (cf_const (cat_1 0 0) \\<BB> b) A B\"\n      and A: \"A \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (cf_const (cat_1 0 0) \\<BB> b)\\<lparr>Obj\\<rparr>\"\n      and B: \"B \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F (cf_const (cat_1 0 0) \\<BB> b)\\<lparr>Obj\\<rparr>\"\n    by auto\n  from assms(2) have const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  from F obtain a b'' f a' b' f' g h\n    where F_def: \"F = [A, B, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and A_def: \"A = [a, b'', f]\\<^sub>\\<circ>\"\n      and B_def: \"B = [a', b', f']\\<^sub>\\<circ>\"\n      and g: \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n      and h: \"h : b'' \\<mapsto>\\<^bsub>cat_1 0 0\\<^esub> b'\"\n      and f: \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> cf_const (cat_1 0 0) \\<BB> b\\<lparr>ObjMap\\<rparr>\\<lparr>b''\\<rparr>\"\n      and f': \"f' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> cf_const (cat_1 0 0) \\<BB> b\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n      and f_def: \n        \"f' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = cf_const (cat_1 0 0) \\<BB> b\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f\"\n    by (elim cat_comma_HomE[OF _ is_functor_axioms const]) blast\n  note hb'b'' = cat_1_is_arrD[OF h]\n  from F_def have F_def: \"F = [A, B, [g, 0]\\<^sub>\\<circ>]\\<^sub>\\<circ>\" \n    unfolding hb'b'' by simp\n  from A_def have A_def: \"A = [a, 0, f]\\<^sub>\\<circ>\"\n    unfolding hb'b'' by simp\n  from B_def have B_def: \"B = [a', 0, f']\\<^sub>\\<circ>\"\n    unfolding hb'b'' by simp\n  from f have f: \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n    unfolding hb'b'' \n    by (cs_prems cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  from f' have f': \"f' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n    unfolding hb'b'' \n    by (cs_prems cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  from f_def f f' g h have f_def: \"f' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = f\"\n    unfolding hb'b'' \n    by (cs_prems cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  from \n    that F_def A_def B_def g f f' f_def  \n    B[folded cat_cf_obj_comma_def] A[folded cat_cf_obj_comma_def]\n  show ?thesis\n    by blast\nqed\n\nlemmas [elim] = is_functor.cat_cf_obj_comma_ArrE[rotated 1]\n\nlemma (in is_functor) cat_obj_cf_comma_ArrE[elim]:\n  assumes \"F \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>\" and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  obtains A B a f a' f' g\n    where \"F = [A, B, [0, g]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and \"A = [0, a, f]\\<^sub>\\<circ>\"\n      and \"B = [0, a', f']\\<^sub>\\<circ>\"\n      and \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n      and \"f : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n      and \"f' : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr>\"\n      and \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f = f'\"\n      and \"A \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n      and \"B \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\nproof-\n  from cat_comma_ArrE[OF assms(1)[unfolded cat_obj_cf_comma_def]] \n  obtain A B \n    where F: \"F \\<in>\\<^sub>\\<circ> cat_comma_Hom (cf_const (cat_1 0 0) \\<BB> b) \\<FF> A B\"\n      and A: \"A \\<in>\\<^sub>\\<circ> (cf_const (cat_1 0 0) \\<BB> b) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n      and B: \"B \\<in>\\<^sub>\\<circ> (cf_const (cat_1 0 0) \\<BB> b) \\<^sub>C\\<^sub>F\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n    by auto\n  from assms(2) have const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  from F obtain a b'' f a' b' f' h g \n    where F_def: \"F = [A, B, [h, g]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and A_def: \"A = [b', a, f]\\<^sub>\\<circ>\"\n      and B_def: \"B = [b'', a', f']\\<^sub>\\<circ>\"\n      and h: \"h : b' \\<mapsto>\\<^bsub>cat_1 0 0\\<^esub> b''\"\n      and g: \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n      and f: \"f : cf_const (cat_1 0 0) \\<BB> b\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n      and f': \"f' : cf_const (cat_1 0 0) \\<BB> b\\<lparr>ObjMap\\<rparr>\\<lparr>b''\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr>\"\n      and f'_def: \n        \"f' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> cf_const (cat_1 0 0) \\<BB> b\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> = \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f\"\n    by (elim cat_comma_HomE[OF _ const is_functor_axioms]) blast\n  note hb'b'' = cat_1_is_arrD[OF h]\n  from F_def have F_def: \"F = [A, B, [0, g]\\<^sub>\\<circ>]\\<^sub>\\<circ>\" \n    unfolding hb'b'' by simp\n  from A_def have A_def: \"A = [0, a, f]\\<^sub>\\<circ>\" unfolding hb'b'' by simp\n  from B_def have B_def: \"B = [0, a', f']\\<^sub>\\<circ>\" unfolding hb'b'' by simp\n  from f have f: \"f : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n    unfolding hb'b'' \n    by (cs_prems cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  from f' have f': \"f' : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr>\"\n    unfolding hb'b'' \n    by (cs_prems cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  from f'_def f f' g h have f'_def[symmetric]: \"f' = \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f\"\n    unfolding hb'b'' \n    by (cs_prems cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  from \n    that F_def A_def B_def g f f' f'_def  \n    A[folded cat_obj_cf_comma_def] B[folded cat_obj_cf_comma_def] \n  show ?thesis\n    by blast\nqed\n\nlemmas [elim] = is_functor.cat_obj_cf_comma_ArrE\n\nlemma (in is_functor) cat_cf_obj_comma_ArrD[dest]: \n  assumes \"[[a, b', f]\\<^sub>\\<circ>, [a', b'', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Arr\\<rparr>\" \n    and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"b' = 0\"\n    and \"b'' = 0\"\n    and \"h = 0\"\n    and \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n    and \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n    and \"f' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n    and \"f' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = f\"\n    and \"[a, b', f]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\n    and \"[a', b'', f']\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\n  using cat_cf_obj_comma_ArrE[OF assms] by auto\n\nlemmas [dest] = is_functor.cat_cf_obj_comma_ArrD[rotated 1]\n\nlemma (in is_functor) cat_obj_cf_comma_ArrD[dest]: \n  assumes \"[[b', a, f]\\<^sub>\\<circ>, [b'', a', f']\\<^sub>\\<circ>, [h, g]\\<^sub>\\<circ>]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>\"\n    and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"b' = 0\"\n    and \"b'' = 0\"\n    and \"h = 0\"\n    and \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n    and \"f : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n    and \"f' : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr>\"\n    and \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f = f'\"\n    and \"[b', a, f]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n    and \"[b'', a', f']\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n  using cat_obj_cf_comma_ArrE[OF assms] by auto\n\nlemmas [dest] = is_functor.cat_obj_cf_comma_ArrD\n\n\nsubsubsection\\<open>Domain\\<close>\n\nlemma cat_cf_obj_comma_Dom_vsv[cat_comma_cs_intros]: \"vsv (\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Dom\\<rparr>)\"\n  unfolding cat_cf_obj_comma_def cat_comma_components by simp\n\nlemma cat_cf_obj_comma_Dom_vdomain[cat_comma_cs_simps]:\n  \"\\<D>\\<^sub>\\<circ> (\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Dom\\<rparr>) = \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Arr\\<rparr>\"\n  unfolding cat_cf_obj_comma_def cat_comma_components by simp\n\nlemma cat_cf_obj_comma_Dom_app[cat_comma_cs_simps]:\n  assumes \"ABF = [A, B, F]\\<^sub>\\<circ>\" and \"ABF \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Arr\\<rparr>\"\n  shows \"\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Dom\\<rparr>\\<lparr>ABF\\<rparr> = A\"\n  using assms(2) \n  unfolding assms(1) cat_cf_obj_comma_def cat_comma_components \n  by simp\n\nlemma (in is_functor) cat_cf_obj_comma_Dom_vrange:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<R>\\<^sub>\\<circ> (\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Dom\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\nproof-  \n  from assms have const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  show ?thesis\n    by \n      (\n        rule cat_comma_Dom_vrange[\n          OF is_functor_axioms const, folded cat_cf_obj_comma_def\n          ]\n      )\nqed\n\nlemma cat_obj_cf_comma_Dom_vsv[cat_comma_cs_intros]: \"vsv (b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Dom\\<rparr>)\"\n  unfolding cat_obj_cf_comma_def cat_comma_components by simp\n\nlemma cat_obj_cf_comma_Dom_vdomain[cat_comma_cs_simps]:\n  \"\\<D>\\<^sub>\\<circ> (b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Dom\\<rparr>) = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>\"\n  unfolding cat_obj_cf_comma_def cat_comma_components by simp\n\nlemma cat_obj_cf_comma_Dom_app[cat_comma_cs_simps]:\n  assumes \"ABF = [A, B, F]\\<^sub>\\<circ>\" and \"ABF \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>\"\n  shows \"b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Dom\\<rparr>\\<lparr>ABF\\<rparr> = A\"\n  using assms(2)\n  unfolding assms(1) cat_obj_cf_comma_def cat_comma_components \n  by simp\n\nlemma (in is_functor) cat_obj_cf_comma_Dom_vrange:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<R>\\<^sub>\\<circ> (b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Dom\\<rparr>) \\<subseteq>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\nproof-  \n  from assms have const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  show ?thesis\n    by \n      (\n        rule cat_comma_Dom_vrange[\n          OF const is_functor_axioms, folded cat_obj_cf_comma_def\n          ]\n      )\nqed\n\n\nsubsubsection\\<open>Codomain\\<close>\n\nlemma cat_cf_obj_comma_Cod_vsv[cat_comma_cs_intros]: \"vsv (\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Cod\\<rparr>)\"\n  unfolding cat_cf_obj_comma_def cat_comma_components by simp\n\nlemma cat_cf_obj_comma_Cod_vdomain[cat_comma_cs_simps]:\n  \"\\<D>\\<^sub>\\<circ> (\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Cod\\<rparr>) = \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Arr\\<rparr>\"\n  unfolding cat_cf_obj_comma_def cat_comma_components by simp\n\nlemma cat_cf_obj_comma_Cod_app[cat_comma_cs_simps]:\n  assumes \"ABF = [A, B, F]\\<^sub>\\<circ>\" and \"ABF \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Arr\\<rparr>\"\n  shows \"\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Cod\\<rparr>\\<lparr>ABF\\<rparr> = B\"\n  using assms(2) \n  unfolding assms(1) cat_cf_obj_comma_def cat_comma_components \n  by (simp add: nat_omega_simps)\n\nlemma (in is_functor) cat_cf_obj_comma_Cod_vrange:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<R>\\<^sub>\\<circ> (\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Cod\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\nproof-  \n  from assms have const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  show ?thesis\n    by \n      (\n        rule cat_comma_Cod_vrange[\n          OF is_functor_axioms const, folded cat_cf_obj_comma_def\n          ]\n      )\nqed\n\nlemma cat_obj_cf_comma_Cod_vsv[cat_comma_cs_intros]: \"vsv (b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Cod\\<rparr>)\"\n  unfolding cat_obj_cf_comma_def cat_comma_components by simp\n\nlemma cat_obj_cf_comma_Cod_vdomain[cat_comma_cs_simps]:\n  \"\\<D>\\<^sub>\\<circ> (b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Cod\\<rparr>) = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>\"\n  unfolding cat_obj_cf_comma_def cat_comma_components by simp\n\nlemma cat_obj_cf_comma_Cod_app[cat_comma_cs_simps]:\n  assumes \"ABF = [A, B, F]\\<^sub>\\<circ>\" and \"ABF \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>\"\n  shows \"b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Cod\\<rparr>\\<lparr>ABF\\<rparr> = B\"\n  using assms(2)\n  unfolding assms(1) cat_obj_cf_comma_def cat_comma_components \n  by (simp add: nat_omega_simps)\n\nlemma (in is_functor) cat_obj_cf_comma_Cod_vrange:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<R>\\<^sub>\\<circ> (b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Dom\\<rparr>) \\<subseteq>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\nproof-  \n  from assms have const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  show ?thesis\n    by \n      (\n        rule cat_comma_Dom_vrange[\n          OF const is_functor_axioms, folded cat_obj_cf_comma_def\n          ]\n      )\nqed\n\n\nsubsubsection\\<open>Arrow with a domain and a codomain\\<close>\n\nlemma (in is_functor) cat_cf_obj_comma_is_arrI[cat_comma_cs_intros]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n    and \"ABF = [A, B, F]\\<^sub>\\<circ>\"\n    and \"A = [a, 0, f]\\<^sub>\\<circ>\"\n    and \"B = [a', 0, f']\\<^sub>\\<circ>\"\n    and \"F = [g, 0]\\<^sub>\\<circ>\"\n    and \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n    and \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n    and \"f' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n    and \"f' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = f\"\n  shows \"ABF : A \\<mapsto>\\<^bsub>\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<^esub> B\"\nproof(intro is_arrI)\n  from assms(1,6,7,8) show \"ABF \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Arr\\<rparr>\"\n    by \n      (\n        cs_concl cs_shallow \n          cs_simp: assms(2,3,4,5,9) cs_intro: cat_comma_cs_intros\n      )\n  with assms(2) show \"\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Dom\\<rparr>\\<lparr>ABF\\<rparr> = A\" \"\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Cod\\<rparr>\\<lparr>ABF\\<rparr> = B\"\n    by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps)+\nqed\n\nlemmas [cat_comma_cs_intros] = is_functor.cat_cf_obj_comma_is_arrI\n\nlemma (in is_functor) cat_obj_cf_comma_is_arrI[cat_comma_cs_intros]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n    and \"ABF = [A, B, F]\\<^sub>\\<circ>\"\n    and \"A = [0, a, f]\\<^sub>\\<circ>\"\n    and \"B = [0, a', f']\\<^sub>\\<circ>\"\n    and \"F = [0, g]\\<^sub>\\<circ>\"\n    and \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n    and \"f : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n    and \"f' : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr>\"\n    and \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f = f'\"\n  shows \"ABF : A \\<mapsto>\\<^bsub>b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<^esub> B\"\nproof(intro is_arrI)\n  from assms(1,6,7,8) show \"ABF \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>\"\n    by \n      (\n        cs_concl cs_shallow \n          cs_simp: assms(2,3,4,5,9) cs_intro: cat_comma_cs_intros\n      )\n  with assms(2) show \"b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Dom\\<rparr>\\<lparr>ABF\\<rparr> = A\" \"b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Cod\\<rparr>\\<lparr>ABF\\<rparr> = B\"\n    by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps)+\nqed\n\nlemmas [cat_comma_cs_intros] = is_functor.cat_obj_cf_comma_is_arrI\n\nlemma (in is_functor) cat_cf_obj_comma_is_arrD[dest]:\n  assumes \"[[a, b', f]\\<^sub>\\<circ>, [a', b'', f']\\<^sub>\\<circ>, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ> :\n    [a, b', f]\\<^sub>\\<circ> \\<mapsto>\\<^bsub>\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<^esub> [a', b'', f']\\<^sub>\\<circ>\"\n    and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"b' = 0\"\n    and \"b'' = 0\"\n    and \"h = 0\"\n    and \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n    and \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n    and \"f' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n    and \"f' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = f\"\n    and \"[a, b', f]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\n    and \"[a', b'', f']\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\n  by (intro cat_cf_obj_comma_ArrD[OF is_arrD(1)[OF assms(1)] assms(2)])+\n\nlemma (in is_functor) cat_obj_cf_comma_is_arrD[dest]:\n  assumes \"[[b', a, f]\\<^sub>\\<circ>, [b'', a', f']\\<^sub>\\<circ>, [h, g]\\<^sub>\\<circ>]\\<^sub>\\<circ> :\n    [b', a, f]\\<^sub>\\<circ> \\<mapsto>\\<^bsub>b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<^esub> [b'', a', f']\\<^sub>\\<circ>\"\n    and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"b' = 0\"\n    and \"b'' = 0\"\n    and \"h = 0\"\n    and \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n    and \"f : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n    and \"f' : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr>\"\n    and \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f = f'\"\n    and \"[b', a, f]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n    and \"[b'', a', f']\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n  by (intro cat_obj_cf_comma_ArrD[OF is_arrD(1)[OF assms(1)] assms(2)])+\n\nlemmas [dest] = is_functor.cat_obj_cf_comma_is_arrD\n\nlemma (in is_functor) cat_cf_obj_comma_is_arrE[elim]:\n  assumes \"ABF : A \\<mapsto>\\<^bsub>\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<^esub> B\" and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  obtains a f a' f' g \n    where \"ABF = [[a, 0, f]\\<^sub>\\<circ>, [a', 0, f']\\<^sub>\\<circ>, [g, 0]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and \"A = [a, 0, f]\\<^sub>\\<circ>\"\n      and \"B = [a', 0, f']\\<^sub>\\<circ>\"\n      and \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n      and \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n      and \"f' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n      and \"f' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = f\"\n      and \"A \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\n      and \"B \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\nproof-\n  note ABF = is_arrD[OF assms(1)]\n  from ABF(1) obtain C D a f a' f' g \n    where ABF_def: \"ABF = [C, D, [g, 0]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and C_def: \"C = [a, 0, f]\\<^sub>\\<circ>\"\n      and D_def: \"D = [a', 0, f']\\<^sub>\\<circ>\"\n      and g: \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n      and f: \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n      and f': \"f' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n      and f_def: \"f' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = f\" \n      and C: \"C \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\" \n      and D: \"D \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\n    by (elim cat_cf_obj_comma_ArrE[OF _ assms(2)])\n  from ABF(2) assms(2) C_def D_def g f f' f_def have [simp]: \"C = A\"\n    unfolding ABF_def \n    by \n      ( \n        cs_prems cs_shallow \n          cs_simp: cat_comma_cs_simps cs_intro: cat_comma_cs_intros\n      )\n  from ABF(3) assms(2) C_def D_def g f f' f_def have [simp]: \"D = B\"\n    unfolding ABF_def \n    by \n      (\n        cs_prems cs_shallow \n          cs_simp: cat_comma_cs_simps cs_intro: cat_comma_cs_intros\n      )\n  from that ABF_def C_def D_def g f f' f_def C D show ?thesis by auto\nqed\n\nlemmas [elim] = is_functor.cat_cf_obj_comma_is_arrE\n\nlemma (in is_functor) cat_obj_cf_comma_is_arrE[elim]:\n  assumes \"ABF : A \\<mapsto>\\<^bsub>b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<^esub> B\" and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  obtains a f a' f' g\n    where \"ABF = [[0, a, f]\\<^sub>\\<circ>, [0, a', f']\\<^sub>\\<circ>, [0, g]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and \"A = [0, a, f]\\<^sub>\\<circ>\"\n      and \"B = [0, a', f']\\<^sub>\\<circ>\"\n      and \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n      and \"f : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n      and \"f' : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr>\"\n      and \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f = f'\"\n      and \"A \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n      and \"B \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\nproof-\n  note ABF = is_arrD[OF assms(1)]\n  from ABF(1) obtain C D a f a' f' g \n    where ABF_def: \"ABF = [C, D, [0, g]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n      and C_def: \"C = [0, a, f]\\<^sub>\\<circ>\"\n      and D_def: \"D = [0, a', f']\\<^sub>\\<circ>\"\n      and g: \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n      and f: \"f : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n      and f': \"f' : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr>\"\n      and f'_def: \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f = f'\" \n      and C: \"C \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\" \n      and D: \"D \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n    by (elim cat_obj_cf_comma_ArrE[OF _ assms(2)])\n  from ABF(2) assms(2) C_def D_def g f f' f'_def have [simp]: \"C = A\"\n    unfolding ABF_def \n    by \n      (\n        cs_prems cs_shallow \n          cs_simp: cat_comma_cs_simps cs_intro: cat_comma_cs_intros\n      )\n  from ABF(3) assms(2) C_def D_def g f f' f'_def have [simp]: \"D = B\"\n    unfolding ABF_def \n    by \n      (\n        cs_prems cs_shallow \n          cs_simp: cat_comma_cs_simps cs_intro: cat_comma_cs_intros\n      )\n  from that ABF_def C_def D_def g f f' f'_def C D show ?thesis by auto\nqed\n\nlemmas [elim] = is_functor.cat_obj_cf_comma_is_arrE\n\n\nsubsubsection\\<open>Composition\\<close>\n\nlemma cat_cf_obj_comma_Comp_vsv[cat_comma_cs_intros]: \"vsv (\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Comp\\<rparr>)\"\n  unfolding cat_cf_obj_comma_def \n  by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)\n\nlemma cat_obj_cf_comma_Comp_vsv[cat_comma_cs_intros]: \"vsv (b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Comp\\<rparr>)\"\n  unfolding cat_obj_cf_comma_def \n  by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)\n\nlemma (in is_functor) cat_cf_obj_comma_Comp_app[cat_comma_cs_simps]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" \n    and \"BCG = [B, C, [g', h']\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n    and \"ABF = [A, B, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n    and \"BCG : B \\<mapsto>\\<^bsub>\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<^esub> C\" \n    and \"ABF : A \\<mapsto>\\<^bsub>\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<^esub> B\"\n  shows \"BCG \\<circ>\\<^sub>A\\<^bsub>\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<^esub> ABF = [A, C, [g' \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> g, 0]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\nproof-\n  from assms(1) have const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  from assms(4) obtain a f a' f' g\n    where BCG_def: \"BCG = [[a, 0, f]\\<^sub>\\<circ>, [a', 0, f']\\<^sub>\\<circ>, [g, 0]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n    by (elim cat_cf_obj_comma_is_arrE[OF _ assms(1)])\n  from assms(5) obtain a f a' f' g\n    where ABF_def: \"ABF = [[a, 0, f]\\<^sub>\\<circ>, [a', 0, f']\\<^sub>\\<circ>, [g, 0]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n    by (elim cat_cf_obj_comma_is_arrE[OF _ assms(1)])\n  from assms(2)[unfolded BCG_def] assms(3)[unfolded ABF_def] have [cat_cs_simps]:\n    \"h' = 0\" \"h = 0\"\n    by simp_all\n  have \"h' \\<circ>\\<^sub>A\\<^bsub>cat_1 0 0\\<^esub> h = 0\" by (cs_concl cs_shallow cs_simp: cat_cs_simps)\n  show ?thesis\n    by \n      (\n        rule cat_comma_Comp_app\n          [\n            OF \n              is_functor_axioms \n              const \n              assms(2,3) \n              assms(4)[unfolded cat_cf_obj_comma_def] \n              assms(5)[unfolded cat_cf_obj_comma_def],\n            folded cat_cf_obj_comma_def,\n            unfolded cat_cs_simps\n          ]\n      )\nqed\n\nlemma (in is_functor) cat_obj_cf_comma_Comp_app[cat_comma_cs_simps]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n    and \"BCG = [B, C, [h', g']\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n    and \"ABF = [A, B, [h, g]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n    and \"BCG : B \\<mapsto>\\<^bsub>b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<^esub> C\" \n    and \"ABF : A \\<mapsto>\\<^bsub>b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<^esub> B\"\n  shows \"BCG \\<circ>\\<^sub>A\\<^bsub>b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<^esub> ABF = [A, C, [0, g' \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> g]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\nproof-\n  from assms(1) have const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  from assms(4) obtain a f a' f' g\n    where BCG_def: \"BCG = [[0, a, f]\\<^sub>\\<circ>, [0, a', f']\\<^sub>\\<circ>, [0, g]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n    by (elim cat_obj_cf_comma_is_arrE[OF _ assms(1)])\n  from assms(5) obtain a f a' f' g\n    where ABF_def: \"ABF = [[0, a, f]\\<^sub>\\<circ>, [0, a', f']\\<^sub>\\<circ>, [0, g]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n    by (elim cat_obj_cf_comma_is_arrE[OF _ assms(1)])\n  from assms(2)[unfolded BCG_def] assms(3)[unfolded ABF_def] have [cat_cs_simps]:\n    \"h' = 0\" \"h = 0\"\n    by simp_all\n  have \"h' \\<circ>\\<^sub>A\\<^bsub>cat_1 0 0\\<^esub> h = 0\" by (cs_concl cs_shallow cs_simp: cat_cs_simps) \n  show ?thesis\n    by \n      (\n        rule cat_comma_Comp_app\n          [\n            OF \n              const \n              is_functor_axioms\n              assms(2,3) \n              assms(4)[unfolded cat_obj_cf_comma_def] \n              assms(5)[unfolded cat_obj_cf_comma_def],\n            folded cat_obj_cf_comma_def,\n            unfolded cat_cs_simps\n          ]\n      )\nqed\n\nlemma (in is_functor) cat_cf_obj_comma_Comp_is_arr[cat_comma_cs_intros]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" \n    and \"BCG : B \\<mapsto>\\<^bsub>\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<^esub> C\" \n    and \"ABF : A \\<mapsto>\\<^bsub>\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<^esub> B\"\n  shows \"BCG \\<circ>\\<^sub>A\\<^bsub>\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<^esub> ABF : A \\<mapsto>\\<^bsub>\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<^esub> C\"\nproof-\n  from assms(1) have const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  show ?thesis\n    by \n      (\n        rule cat_comma_Comp_is_arr\n          [\n            OF \n              is_functor_axioms \n              const \n              assms(2)[unfolded cat_cf_obj_comma_def]\n              assms(3)[unfolded cat_cf_obj_comma_def],\n            folded cat_cf_obj_comma_def\n          ]\n      )\nqed\n\nlemma (in is_functor) cat_obj_cf_comma_Comp_is_arr[cat_comma_cs_intros]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" \n    and \"BCG : B \\<mapsto>\\<^bsub>b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<^esub> C\" \n    and \"ABF : A \\<mapsto>\\<^bsub>b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<^esub> B\"\n  shows \"BCG \\<circ>\\<^sub>A\\<^bsub>b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<^esub> ABF : A \\<mapsto>\\<^bsub>b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<^esub> C\"\nproof-\n  from assms(1) have const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  show ?thesis\n    by \n      (\n        rule cat_comma_Comp_is_arr\n          [\n            OF \n              const \n              is_functor_axioms \n              assms(2)[unfolded cat_obj_cf_comma_def]\n              assms(3)[unfolded cat_obj_cf_comma_def],\n            folded cat_obj_cf_comma_def\n          ]\n      )\nqed\n\n\nsubsubsection\\<open>Identity\\<close>\n\nlemma cat_cf_obj_comma_CId_vsv[cat_comma_cs_intros]: \"vsv (\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>CId\\<rparr>)\"\n  unfolding cat_cf_obj_comma_def \n  by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)\n\nlemma cat_obj_cf_comma_CId_vsv[cat_comma_cs_intros]: \"vsv (b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>CId\\<rparr>)\"\n  unfolding cat_obj_cf_comma_def \n  by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)\n\nlemma (in is_functor) cat_cf_obj_comma_CId_vdomain[cat_comma_cs_simps]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<D>\\<^sub>\\<circ> (\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>CId\\<rparr>) = \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\nproof-\n  from assms(1) have const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  show ?thesis\n    by \n      (\n        rule cat_comma_CId_vdomain[\n          OF is_functor_axioms const, folded cat_cf_obj_comma_def\n          ]\n      )\nqed\n\nlemma (in is_functor) cat_obj_cf_comma_CId_vdomain[cat_comma_cs_simps]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<D>\\<^sub>\\<circ> (b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>CId\\<rparr>) = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\nproof-\n  from assms(1) have const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  show \"\\<D>\\<^sub>\\<circ> (b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>CId\\<rparr>) = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n    by \n      (\n        rule cat_comma_CId_vdomain[\n          OF const is_functor_axioms, folded cat_obj_cf_comma_def\n          ]\n      )\nqed\n\nlemma (in is_functor) cat_cf_obj_comma_CId_app[cat_comma_cs_simps]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" and \"A = [a, b', f]\\<^sub>\\<circ>\" and \"A \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\n  shows \"\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>CId\\<rparr>\\<lparr>A\\<rparr> = [A, A, [\\<AA>\\<lparr>CId\\<rparr>\\<lparr>a\\<rparr>, 0]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\nproof-\n  from assms(1) have const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  from assms(3,2) have b'_def: \"b' = 0\"\n    by (auto elim: cat_cf_obj_comma_ObjE[OF _ assms(1)])\n  have [cat_cs_simps]: \"cat_1 0 0\\<lparr>CId\\<rparr>\\<lparr>b'\\<rparr> = 0\" \n    unfolding cat_1_components b'_def by simp\n  show ?thesis\n    by \n      ( \n        rule cat_comma_CId_app\n          [\n            OF \n              is_functor_axioms \n              const\n              assms(2,3)[unfolded cat_cf_obj_comma_def],  \n            unfolded cat_cf_obj_comma_def[symmetric] cat_cs_simps\n          ]\n        )\nqed\n\nlemma (in is_functor) cat_obj_cf_comma_CId_app[cat_comma_cs_simps]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" and \"A = [b', a, f]\\<^sub>\\<circ>\" and \"A \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n  shows \"b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>CId\\<rparr>\\<lparr>A\\<rparr> = [A, A, [0, \\<AA>\\<lparr>CId\\<rparr>\\<lparr>a\\<rparr>]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\nproof-\n  from assms(1) have const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  from assms(3,2) have b'_def: \"b' = 0\"\n    by (auto elim: cat_obj_cf_comma_ObjE[OF _ assms(1)])\n  have [cat_cs_simps]: \"cat_1 0 0\\<lparr>CId\\<rparr>\\<lparr>b'\\<rparr> = 0\" \n    unfolding cat_1_components b'_def by simp\n  show ?thesis\n    by \n      ( \n        rule cat_comma_CId_app\n          [\n            OF \n              const\n              is_functor_axioms \n              assms(2,3)[unfolded cat_obj_cf_comma_def],  \n            unfolded cat_obj_cf_comma_def[symmetric] cat_cs_simps\n          ]\n        )\nqed\n\n\nsubsubsection\\<open>\nComma categories constructed from a functor and an object are categories\n\\<close>\n\nlemma (in is_functor) category_cat_cf_obj_comma[cat_comma_cs_intros]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"category \\<alpha> (\\<FF> \\<^sub>C\\<^sub>F\\<down> b)\"\nproof-\n  from assms(1) have const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  show ?thesis\n    by \n      (\n        rule category_cat_comma[\n          OF is_functor_axioms const, folded cat_cf_obj_comma_def\n          ]\n      )\nqed\n\nlemmas [cat_comma_cs_intros] = is_functor.category_cat_cf_obj_comma\n\nlemma (in is_functor) category_cat_obj_cf_comma[cat_comma_cs_intros]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"category \\<alpha> (b \\<down>\\<^sub>C\\<^sub>F \\<FF>)\"\nproof-\n  from assms(1) have const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_cs_intros)\n  show ?thesis\n    by \n      (\n        rule category_cat_comma[\n          OF const is_functor_axioms, folded cat_obj_cf_comma_def\n          ]\n      )\nqed\n\nlemmas [cat_comma_cs_intros] = is_functor.category_cat_obj_cf_comma\n\n\nsubsubsection\\<open>Tiny comma categories constructed from a functor and an object\\<close>\n\nlemma (in is_tm_functor) tiny_category_cat_cf_obj_comma[cat_comma_cs_intros]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"tiny_category \\<alpha> (\\<FF> \\<^sub>C\\<^sub>F\\<down> b)\"\nproof-\n  from assms(1) have const: \n    \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_small_cs_intros cat_cs_intros)\n  show ?thesis\n    by \n      (\n        rule tiny_category_cat_comma[\n          OF is_tm_functor_axioms const, folded cat_cf_obj_comma_def\n          ]\n      )\nqed\n\nlemma (in is_tm_functor) tiny_category_cat_obj_cf_comma[cat_comma_cs_intros]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"tiny_category \\<alpha> (b \\<down>\\<^sub>C\\<^sub>F \\<FF>)\"\nproof-\n  from assms(1) have const: \n    \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: vempty_is_zet cat_small_cs_intros cat_cs_intros)\n  show ?thesis\n    by \n      (\n        rule tiny_category_cat_comma[\n          OF const is_tm_functor_axioms, folded cat_obj_cf_comma_def\n          ]\n      )\nqed\n\n\n\nsubsection\\<open>\nOpposite comma category functors for the comma categories\nconstructed from a functor and an object\n\\<close>\n\n\nsubsubsection\\<open>Definitions and elementary properties\\<close>\n\ndefinition op_cf_obj_comma :: \"V \\<Rightarrow> V \\<Rightarrow> V\"\n  where \"op_cf_obj_comma \\<FF> b =\n    op_cf_comma \\<FF> (cf_const (cat_1 0 0) (\\<FF>\\<lparr>HomCod\\<rparr>) b)\"\n\ndefinition op_obj_cf_comma :: \"V \\<Rightarrow> V \\<Rightarrow> V\"\n  where \"op_obj_cf_comma b \\<FF> =\n    op_cf_comma (cf_const (cat_1 0 0) (\\<FF>\\<lparr>HomCod\\<rparr>) b) \\<FF>\"\n\n\ntext\\<open>Alternative forms of the definitions.\\<close>\n\nlemma (in is_functor) op_cf_obj_comma_def: \n  \"op_cf_obj_comma \\<FF> b = op_cf_comma \\<FF> (cf_const (cat_1 0 0) \\<BB> b)\"\n  unfolding op_cf_obj_comma_def cat_cs_simps by simp\n\nlemma (in is_functor) op_obj_cf_comma_def:\n  \"op_obj_cf_comma b \\<FF> = op_cf_comma (cf_const (cat_1 0 0) \\<BB> b) \\<FF>\"\n  unfolding op_obj_cf_comma_def cat_cs_simps by simp\n\n\nsubsubsection\\<open>Object map\\<close>\n\nlemma op_cf_obj_comma_ObjMap_vsv[cat_comma_cs_intros]:\n  \"vsv (op_cf_obj_comma \\<FF> b\\<lparr>ObjMap\\<rparr>)\"\n  unfolding op_cf_obj_comma_def\n  by \n    (\n      cs_concl cs_shallow \n        cs_simp: cat_comma_cs_simps cs_intro: cat_comma_cs_intros\n    )\n\nlemma op_obj_cf_comma_ObjMap_vsv[cat_comma_cs_intros]:\n  \"vsv (op_obj_cf_comma b \\<FF>\\<lparr>ObjMap\\<rparr>)\"\n  unfolding op_obj_cf_comma_def\n  by\n    (\n      cs_concl cs_shallow \n        cs_simp: cat_comma_cs_simps cs_intro: cat_comma_cs_intros\n    )\n\nlemma (in is_functor) op_cf_obj_comma_ObjMap_vdomain[cat_comma_cs_simps]:\n  \"\\<D>\\<^sub>\\<circ> (op_cf_obj_comma \\<FF> b\\<lparr>ObjMap\\<rparr>) = \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\n  unfolding op_cf_obj_comma_def\n  by \n    (\n      cs_concl cs_shallow \n        cs_simp: cat_comma_cs_simps cat_cf_obj_comma_def[symmetric]\n    )\n\nlemma (in is_functor) op_obj_cf_comma_ObjMap_vdomain[cat_comma_cs_simps]:\n  \"\\<D>\\<^sub>\\<circ> (op_obj_cf_comma b \\<FF>\\<lparr>ObjMap\\<rparr>) = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n  unfolding op_obj_cf_comma_def\n  by \n    (\n      cs_concl cs_shallow \n        cs_simp: cat_comma_cs_simps cat_obj_cf_comma_def[symmetric]\n    )\n\nlemma (in is_functor) op_cf_obj_comma_ObjMap_app[cat_comma_cs_simps]:\n  assumes \"A = [a, 0, f]\\<^sub>\\<circ>\" and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" and \"A \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\n  shows \"op_cf_obj_comma \\<FF> b\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> = [0, a, f]\\<^sub>\\<circ>\"\nproof-\n  have a: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" and f: \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n    by (intro cat_cf_obj_comma_ObjD[OF assms(3)[unfolded assms(1)] assms(2)])+\n  from assms(2) a f show ?thesis\n    using assms(2)\n    unfolding assms(1) op_cf_obj_comma_def\n    by\n      (\n        cs_concl \n          cs_simp: cat_cs_simps cat_comma_cs_simps\n          cs_intro: V_cs_intros cat_cs_intros cat_comma_cs_intros\n      )\nqed\n\nlemma (in is_functor) op_obj_cf_comma_ObjMap_app[cat_comma_cs_simps]:\n  assumes \"A = [0, a, f]\\<^sub>\\<circ>\" and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" and \"A \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n  shows \"op_obj_cf_comma b \\<FF> \\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> = [a, 0, f]\\<^sub>\\<circ>\"\nproof-\n  have a: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" and f: \"f : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n    by (intro cat_obj_cf_comma_ObjD[OF assms(3)[unfolded assms(1)] assms(2)])+\n  from assms(2) a f show ?thesis\n    using assms(2)\n    unfolding assms(1) op_obj_cf_comma_def\n    by\n      (\n        cs_concl \n          cs_simp: cat_cs_simps cat_comma_cs_simps\n          cs_intro: V_cs_intros cat_cs_intros cat_comma_cs_intros\n      )\nqed\n\n\nsubsubsection\\<open>Arrow map\\<close>\n\nlemma op_cf_obj_comma_ArrMap_vsv[cat_comma_cs_intros]:\n  \"vsv (op_cf_obj_comma \\<FF> b\\<lparr>ArrMap\\<rparr>)\"\n  unfolding op_cf_obj_comma_def\n  by \n    (\n      cs_concl cs_shallow \n        cs_simp: cat_comma_cs_simps cs_intro: cat_comma_cs_intros\n    )\n\nlemma op_obj_cf_comma_ArrMap_vsv[cat_comma_cs_intros]:\n  \"vsv (op_obj_cf_comma b \\<FF>\\<lparr>ArrMap\\<rparr>)\"\n  unfolding op_obj_cf_comma_def\n  by \n    (\n      cs_concl cs_shallow \n        cs_simp: cat_comma_cs_simps cs_intro: cat_comma_cs_intros\n    )\n\nlemma (in is_functor) op_cf_obj_comma_ArrMap_vdomain[cat_comma_cs_simps]:\n  \"\\<D>\\<^sub>\\<circ> (op_cf_obj_comma \\<FF> b\\<lparr>ArrMap\\<rparr>) = \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Arr\\<rparr>\"\n  unfolding op_cf_obj_comma_def\n  by \n    (\n      cs_concl cs_shallow \n        cs_simp: cat_comma_cs_simps cat_cf_obj_comma_def[symmetric]\n    )\n\nlemmas [cat_comma_cs_simps] = is_functor.op_cf_obj_comma_ArrMap_vdomain\n\nlemma (in is_functor) op_obj_cf_comma_ArrMap_vdomain[cat_comma_cs_simps]:\n  \"\\<D>\\<^sub>\\<circ> (op_obj_cf_comma b \\<FF>\\<lparr>ArrMap\\<rparr>) = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>\"\n  unfolding op_obj_cf_comma_def\n  by \n    (\n      cs_concl cs_shallow \n        cs_simp: cat_comma_cs_simps cat_obj_cf_comma_def[symmetric] \n    )\n\nlemmas [cat_comma_cs_simps] = is_functor.op_obj_cf_comma_ArrMap_vdomain\n\nlemma (in is_functor) op_cf_obj_comma_ArrMap_app[cat_comma_cs_simps]:\n  assumes \"ABF = [[a, 0, f]\\<^sub>\\<circ>, [a', 0, f']\\<^sub>\\<circ>, [g, 0]\\<^sub>\\<circ>]\\<^sub>\\<circ>\" \n    and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" \n    and \"ABF \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Arr\\<rparr>\"\n  shows \"op_cf_obj_comma \\<FF> b\\<lparr>ArrMap\\<rparr>\\<lparr>ABF\\<rparr> = [[0, a', f']\\<^sub>\\<circ>, [0, a, f]\\<^sub>\\<circ>, [0, g]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\nproof-\n  from assms(3) have g: \"g : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n    and f: \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n    and f': \"f' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n    and [cat_comma_cs_simps]: \"f' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>g\\<rparr> = f\"\n    by (intro cat_cf_obj_comma_ArrD[OF assms(3)[unfolded assms(1)] assms(2)])+\n  from assms(2) g f f' show ?thesis\n    unfolding assms(1) op_cf_obj_comma_def\n    by\n      (\n        cs_concl \n          cs_simp: cat_cs_simps cat_comma_cs_simps cat_1_CId_app\n          cs_intro: V_cs_intros cat_cs_intros cat_comma_cs_intros cat_1_is_arrI\n      )\nqed\n\nlemmas [cat_comma_cs_simps] = is_functor.op_cf_obj_comma_ArrMap_app\n\nlemma (in is_functor) op_obj_cf_comma_ArrMap_app[cat_comma_cs_simps]:\n  assumes \"ABF = [[0, a, f]\\<^sub>\\<circ>, [0, a', f']\\<^sub>\\<circ>, [0, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\" \n    and \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" \n    and \"ABF \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>\"\n  shows \"op_obj_cf_comma b \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>ABF\\<rparr> = [[a', 0, f']\\<^sub>\\<circ>, [a, 0, f]\\<^sub>\\<circ>, [h, 0]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\nproof-\n  from assms(3) have h: \"h : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n    and f: \"f : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n    and f': \"f' : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr>\"\n    and [cat_comma_cs_simps]: \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f = f'\"\n    by (intro cat_obj_cf_comma_ArrD[OF assms(3)[unfolded assms(1)] assms(2)])+\n  from assms(2) h f f' show ?thesis\n    unfolding assms(1) op_obj_cf_comma_def\n    by\n      (\n        cs_concl \n          cs_simp: cat_cs_simps cat_comma_cs_simps cat_1_CId_app\n          cs_intro: V_cs_intros cat_cs_intros cat_comma_cs_intros cat_1_is_arrI\n      )\nqed\n\nlemmas [cat_comma_cs_simps] = is_functor.op_obj_cf_comma_ArrMap_app\n\n\nsubsubsection\\<open>\nOpposite comma category functors for the comma categories\nconstructed from a functor and an object are isomorphisms of categories\n\\<close>\n\nlemma (in is_functor) op_cf_obj_comma_is_iso_functor:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"op_cf_obj_comma \\<FF> b : op_cat (\\<FF> \\<^sub>C\\<^sub>F\\<down> b) \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<alpha>\\<^esub> b \\<down>\\<^sub>C\\<^sub>F (op_cf \\<FF>)\"\nproof-\n  from assms have cf_const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_simp: cat_cs_simps cs_intro: V_cs_intros cat_cs_intros)\n  note cat_obj_cf_comma_def = \n    is_functor.cat_obj_cf_comma_def[\n      OF is_functor_op, unfolded cat_op_simps\n      ]\n  show ?thesis\n    by \n      (\n        rule op_cf_comma_is_iso_functor\n          [\n            OF is_functor_axioms cf_const, \n            folded cat_cf_obj_comma_def op_cf_obj_comma_def,\n            unfolded cat_op_simps, \n            folded cat_obj_cf_comma_def\n          ]\n      )\nqed\n\nlemma (in is_functor) op_cf_obj_comma_is_iso_functor'[cat_comma_cs_intros]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n    and \"\\<AA>' = op_cat (\\<FF> \\<^sub>C\\<^sub>F\\<down> b)\"\n    and \"\\<BB>' = b \\<down>\\<^sub>C\\<^sub>F (op_cf \\<FF>)\"\n  shows \"op_cf_obj_comma \\<FF> b : \\<AA>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<alpha>\\<^esub> \\<BB>'\"\n  using assms(1) unfolding assms(2,3) by (rule op_cf_obj_comma_is_iso_functor)\n\nlemmas [cat_comma_cs_intros] = is_functor.op_cf_obj_comma_is_iso_functor'\n\nlemma (in is_functor) op_cf_obj_comma_is_functor:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"op_cf_obj_comma \\<FF> b : op_cat (\\<FF> \\<^sub>C\\<^sub>F\\<down> b) \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> b \\<down>\\<^sub>C\\<^sub>F (op_cf \\<FF>)\"\n  by (rule is_iso_functorD(1)[OF op_cf_obj_comma_is_iso_functor[OF assms]])\n\nlemma (in is_functor) op_cf_obj_comma_is_functor'[cat_comma_cs_intros]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n    and \"\\<AA>' = op_cat (\\<FF> \\<^sub>C\\<^sub>F\\<down> b)\"\n    and \"\\<BB>' = b \\<down>\\<^sub>C\\<^sub>F (op_cf \\<FF>)\"\n  shows \"op_cf_obj_comma \\<FF> b : \\<AA>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>'\"\n  using assms(1) unfolding assms(2,3) by (rule op_cf_obj_comma_is_functor)\n\nlemmas [cat_comma_cs_intros] = is_functor.op_cf_obj_comma_is_functor'\n\nlemma (in is_functor) op_obj_cf_comma_is_iso_functor:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"op_obj_cf_comma b \\<FF> : op_cat (b \\<down>\\<^sub>C\\<^sub>F \\<FF>) \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<alpha>\\<^esub> (op_cf \\<FF>) \\<^sub>C\\<^sub>F\\<down> b\"\nproof-\n  from assms have cf_const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_simp: cat_cs_simps cs_intro: V_cs_intros cat_cs_intros)\n  note cat_cf_obj_comma_def = \n    is_functor.cat_cf_obj_comma_def[\n      OF is_functor_op, unfolded cat_op_simps\n      ]\n  show ?thesis\n    by\n      (\n        rule op_cf_comma_is_iso_functor\n          [\n            OF cf_const is_functor_axioms,\n            folded cat_obj_cf_comma_def op_obj_cf_comma_def,\n            unfolded cat_op_simps,\n            folded cat_cf_obj_comma_def\n          ]\n      )\nqed\n\nlemma (in is_functor) op_obj_cf_comma_is_iso_functor'[cat_comma_cs_intros]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n    and \"\\<AA>' = op_cat (b \\<down>\\<^sub>C\\<^sub>F \\<FF>)\"\n    and \"\\<BB>' = (op_cf \\<FF>) \\<^sub>C\\<^sub>F\\<down> b\"\n  shows \"op_obj_cf_comma b \\<FF> : \\<AA>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<alpha>\\<^esub> \\<BB>'\"\n  using assms(1) unfolding assms(2,3) by (rule op_obj_cf_comma_is_iso_functor)\n  \nlemmas [cat_comma_cs_intros] = is_functor.op_obj_cf_comma_is_iso_functor'\n\nlemma (in is_functor) op_obj_cf_comma_is_functor:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"op_obj_cf_comma b \\<FF> : op_cat (b \\<down>\\<^sub>C\\<^sub>F \\<FF>) \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> (op_cf \\<FF>) \\<^sub>C\\<^sub>F\\<down> b\"\n  by (rule is_iso_functorD(1)[OF op_obj_cf_comma_is_iso_functor[OF assms]])\n\nlemma (in is_functor) op_obj_cf_comma_is_functor'[cat_comma_cs_intros]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n    and \"\\<AA>' = op_cat (b \\<down>\\<^sub>C\\<^sub>F \\<FF>)\"\n    and \"\\<BB>' = (op_cf \\<FF>) \\<^sub>C\\<^sub>F\\<down> b\"\n  shows \"op_obj_cf_comma b \\<FF> : \\<AA>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>'\"\n  using assms(1) unfolding assms(2,3) by (rule op_obj_cf_comma_is_functor)\n\n\n\nsubsection\\<open>\nProjections for comma categories constructed from a functor and an object\n\\<close>\n\n\nsubsubsection\\<open>Definitions and elementary properties\\<close>\n\ndefinition cf_cf_obj_comma_proj :: \"V \\<Rightarrow> V \\<Rightarrow> V\" (\\<open>(_ \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O _)\\<close> [1000, 1000] 999)\n  where \"\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b \\<equiv> \\<FF> \\<^sub>C\\<^sub>F\\<Sqinter> (cf_const (cat_1 0 0) (\\<FF>\\<lparr>HomCod\\<rparr>) b)\"\n\ndefinition cf_obj_cf_comma_proj :: \"V \\<Rightarrow> V \\<Rightarrow> V\" (\\<open>(_ \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F _)\\<close> [1000, 1000] 999)\n  where \"b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF> \\<equiv> (cf_const (cat_1 0 0) (\\<FF>\\<lparr>HomCod\\<rparr>) b) \\<Sqinter>\\<^sub>C\\<^sub>F \\<FF>\"\n\n\ntext\\<open>Alternative forms of the definitions.\\<close>\n\nlemma (in is_functor) cf_cf_obj_comma_proj_def:\n  \"\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b = \\<FF> \\<^sub>C\\<^sub>F\\<Sqinter> (cf_const (cat_1 0 0) \\<BB> b)\" \n  unfolding cf_cf_obj_comma_proj_def cf_HomCod..\n\nlemma (in is_functor) cf_obj_cf_comma_proj_def: \n  \"b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF> = (cf_const (cat_1 0 0) \\<BB> b) \\<Sqinter>\\<^sub>C\\<^sub>F \\<FF>\" \n  unfolding cf_obj_cf_comma_proj_def cf_HomCod..\n\n\ntext\\<open>Components.\\<close>\n\nlemma (in is_functor) cf_cf_obj_comma_proj_components[cat_comma_cs_simps]: \n  shows \"\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b\\<lparr>HomDom\\<rparr> = \\<FF> \\<^sub>C\\<^sub>F\\<down> b\"\n    and \"\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b\\<lparr>HomCod\\<rparr> = \\<AA>\"\n  unfolding \n    cf_cf_obj_comma_proj_def \n    cf_comma_proj_left_components \n    cat_cf_obj_comma_def[symmetric]\n    cat_cs_simps \n  by simp_all\n\nlemmas [cat_comma_cs_simps] = is_functor.cf_cf_obj_comma_proj_components\n\nlemma (in is_functor) cf_obj_cf_comma_proj_components[cat_comma_cs_simps]: \n  shows \"b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>HomDom\\<rparr> = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\"\n    and \"b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>HomCod\\<rparr> = \\<AA>\"\n  unfolding \n    cf_obj_cf_comma_proj_def \n    cf_comma_proj_right_components \n    cat_obj_cf_comma_def[symmetric]\n    cat_cs_simps \n  by simp_all\n\nlemmas [cat_comma_cs_simps] = is_functor.cf_obj_cf_comma_proj_components\n\n\nsubsubsection\\<open>Object map\\<close>\n\nlemma cf_cf_obj_comma_proj_ObjMap_vsv[cat_comma_cs_intros]: \n  \"vsv (\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b\\<lparr>ObjMap\\<rparr>)\"\n  unfolding cf_cf_obj_comma_proj_def\n  by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)\n\nlemma cf_obj_cf_comma_proj_ObjMap_vsv[cat_comma_cs_intros]: \n  \"vsv (b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr>)\"\n  unfolding cf_obj_cf_comma_proj_def\n  by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)\n\nlemma (in is_functor) cf_cf_obj_comma_proj_ObjMap_vdomain[cat_comma_cs_simps]: \n  \"\\<D>\\<^sub>\\<circ> (\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b\\<lparr>ObjMap\\<rparr>) = \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\n  unfolding cf_cf_obj_comma_proj_def cf_comma_proj_left_ObjMap_vdomain\n  unfolding \n    cf_cf_obj_comma_proj_def[symmetric] \n    cf_comma_proj_left_components[symmetric]\n    cat_comma_cs_simps\n  by simp\n\nlemmas [cat_comma_cs_simps] = is_functor.cf_cf_obj_comma_proj_ObjMap_vdomain\n\nlemma (in is_functor) cf_obj_cf_comma_proj_ObjMap_vdomain[cat_comma_cs_simps]: \n  \"\\<D>\\<^sub>\\<circ> (b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr>) = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n  unfolding cf_obj_cf_comma_proj_def cf_comma_proj_right_ObjMap_vdomain\n  unfolding \n    cf_obj_cf_comma_proj_def[symmetric] \n    cf_comma_proj_right_components[symmetric]\n    cat_comma_cs_simps\n  by simp\n\nlemmas [cat_comma_cs_simps] = is_functor.cf_obj_cf_comma_proj_ObjMap_vdomain\n\nlemma (in is_functor) cf_cf_obj_comma_proj_ObjMap_app[cat_comma_cs_simps]:\n  assumes \"A = [a, b', f]\\<^sub>\\<circ>\" and \"[a, b', f]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\n  shows \"\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> = a\"\n  by \n    (\n      rule cf_comma_proj_left_ObjMap_app[\n        OF assms(1) assms(2)[unfolded cat_cf_obj_comma_def], \n        folded cf_cf_obj_comma_proj_def\n        ]\n    )\n\nlemmas [cat_comma_cs_simps] = is_functor.cf_cf_obj_comma_proj_ObjMap_app\n\nlemma (in is_functor) cf_obj_cf_comma_proj_ObjMap_app[cat_comma_cs_simps]:\n  assumes \"A = [b', a, f]\\<^sub>\\<circ>\" and \"[b', a, f]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n  shows \"b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> = a\"\n  by \n    (\n      rule cf_comma_proj_right_ObjMap_app[\n        OF assms(1) assms(2)[unfolded cat_obj_cf_comma_def], \n        folded cf_obj_cf_comma_proj_def\n        ]\n    )\n\nlemmas [cat_comma_cs_simps] = is_functor.cf_obj_cf_comma_proj_ObjMap_app\n\n\nsubsubsection\\<open>Arrow map\\<close>\n\nlemma cf_cf_obj_comma_proj_ArrMap_vsv[cat_comma_cs_intros]: \n  \"vsv (\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b\\<lparr>ArrMap\\<rparr>)\"\n  unfolding cf_cf_obj_comma_proj_def\n  by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)\n\nlemma cf_obj_cf_comma_proj_ArrMap_vsv[cat_comma_cs_intros]: \n  \"vsv (b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ArrMap\\<rparr>)\"\n  unfolding cf_obj_cf_comma_proj_def\n  by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)\n\nlemma (in is_functor) cf_cf_obj_comma_proj_ArrMap_vdomain[cat_comma_cs_simps]: \n  \"\\<D>\\<^sub>\\<circ> (\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b\\<lparr>ArrMap\\<rparr>) = \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Arr\\<rparr>\"\n  unfolding cf_cf_obj_comma_proj_def cf_comma_proj_left_ArrMap_vdomain\n  unfolding \n    cf_cf_obj_comma_proj_def[symmetric] \n    cf_comma_proj_left_components[symmetric]\n    cat_comma_cs_simps\n  by simp\n\nlemmas [cat_comma_cs_simps] = is_functor.cf_cf_obj_comma_proj_ObjMap_vdomain\n\nlemma (in is_functor) cf_obj_cf_comma_proj_ArrMap_vdomain[cat_comma_cs_simps]:\n  \"\\<D>\\<^sub>\\<circ> (b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ArrMap\\<rparr>) = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>\"\n  unfolding cf_obj_cf_comma_proj_def cf_comma_proj_right_ArrMap_vdomain\n  unfolding \n    cf_obj_cf_comma_proj_def[symmetric] \n    cf_comma_proj_right_components[symmetric]\n    cat_comma_cs_simps\n  by simp\n\nlemmas [cat_comma_cs_simps] = is_functor.cf_obj_cf_comma_proj_ArrMap_vdomain\n\nlemma (in is_functor) cf_cf_obj_comma_proj_ArrMap_app[cat_comma_cs_simps]:\n  assumes \"ABF = [A, B, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\" \n    and \"[A, B, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Arr\\<rparr>\"\n  shows \"\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b\\<lparr>ArrMap\\<rparr>\\<lparr>ABF\\<rparr> = g\"\n  by \n    (\n      rule cf_comma_proj_left_ArrMap_app[\n        OF assms(1) assms(2)[unfolded cat_cf_obj_comma_def], \n        folded cf_cf_obj_comma_proj_def\n        ]\n    )\n\nlemmas [cat_comma_cs_simps] = is_functor.cf_cf_obj_comma_proj_ArrMap_app\n\nlemma (in is_functor) cf_obj_cf_comma_proj_ArrMap_app[cat_comma_cs_simps]:\n  assumes \"ABF = [A, B, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\" \n    and \"[A, B, [g, h]\\<^sub>\\<circ>]\\<^sub>\\<circ> \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>\"\n  shows \"b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>ABF\\<rparr> = h\"\n  by \n    (\n      rule cf_comma_proj_right_ArrMap_app[\n        OF assms(1) assms(2)[unfolded cat_obj_cf_comma_def], \n        folded cf_obj_cf_comma_proj_def\n        ]\n    )\n\nlemmas [cat_comma_cs_simps] = is_functor.cf_obj_cf_comma_proj_ArrMap_app\n\n\nsubsubsection\\<open>Projections for a comma category are functors\\<close>\n\nlemma (in is_functor) cf_cf_obj_comma_proj_is_functor:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b : \\<FF> \\<^sub>C\\<^sub>F\\<down> b \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\nproof-\n  from assms have const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: V_cs_intros cat_cs_intros)\n  show ?thesis\n    by \n      (\n        rule cf_comma_proj_left_is_functor[\n          OF is_functor_axioms const,\n          folded cf_cf_obj_comma_proj_def cat_cf_obj_comma_def\n          ]\n      )\nqed\n\nlemma (in is_functor) cf_cf_obj_comma_proj_is_functor'[cat_comma_cs_intros]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" and \"\\<AA>' = \\<FF> \\<^sub>C\\<^sub>F\\<down> b\"\n  shows \"\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b : \\<AA>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n  using assms(1) unfolding assms(2) by (rule cf_cf_obj_comma_proj_is_functor)\n\nlemmas [cat_comma_cs_intros] = is_functor.cf_cf_obj_comma_proj_is_functor'\n\nlemma (in is_functor) cf_obj_cf_comma_proj_is_functor:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF> : b \\<down>\\<^sub>C\\<^sub>F \\<FF> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\nproof-\n  from assms have const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: V_cs_intros cat_cs_intros)\n  show ?thesis\n    by \n      (\n        rule cf_comma_proj_right_is_functor[\n          OF const is_functor_axioms,\n          folded cf_obj_cf_comma_proj_def cat_obj_cf_comma_def\n          ]\n      )\nqed\n\nlemma (in is_functor) cf_obj_cf_comma_proj_is_functor'[cat_comma_cs_intros]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" and \"\\<AA>' = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\"\n  shows \"b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF> : \\<AA>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n  using assms(1) unfolding assms(2) by (rule cf_obj_cf_comma_proj_is_functor)\n\nlemmas [cat_comma_cs_intros] = is_functor.cf_obj_cf_comma_proj_is_functor'\n\n\nsubsubsection\\<open>\nOpposite projections for comma categories constructed from a functor \nand an object\n\\<close>\n\nlemma (in is_functor) op_cf_cf_obj_comma_proj: \n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"op_cf (\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b) = b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F (op_cf \\<FF>) \\<circ>\\<^sub>C\\<^sub>F op_cf_obj_comma \\<FF> b\"\nproof-\n  from assms have cf_const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_simp: cat_cs_simps cs_intro: V_cs_intros cat_cs_intros)\n  show ?thesis\n    by\n      (\n        rule op_cf_comma_proj_left\n          [\n            OF is_functor_axioms cf_const,\n            unfolded cat_op_simps,\n            folded \n              cf_cf_obj_comma_proj_def\n              op_cf_obj_comma_def\n              is_functor.cf_obj_cf_comma_proj_def[\n                OF is_functor_op, unfolded cat_op_simps\n                ]\n          ]\n      )\nqed\n\nlemma (in is_functor) op_cf_obj_cf_comma_proj:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"op_cf (b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF>) = (op_cf \\<FF>) \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b \\<circ>\\<^sub>C\\<^sub>F op_obj_cf_comma b \\<FF>\"\nproof-\n  from assms have cf_const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_simp: cat_cs_simps cs_intro: V_cs_intros cat_cs_intros)\n  show ?thesis\n    by \n      (\n        rule op_cf_comma_proj_right\n          [\n            OF cf_const is_functor_axioms,\n            unfolded cat_op_simps,\n            folded\n              cf_obj_cf_comma_proj_def\n              op_obj_cf_comma_def\n              is_functor.cf_cf_obj_comma_proj_def[\n                OF is_functor_op, unfolded cat_op_simps\n                ]\n          ]\n      )\nqed\n\n\nsubsubsection\\<open>Projections for a tiny comma category\\<close>\n\nlemma (in is_tm_functor) cf_cf_obj_comma_proj_is_tm_functor:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b : \\<FF> \\<^sub>C\\<^sub>F\\<down> b \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\nproof-\n  from assms have const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: V_cs_intros cat_small_cs_intros cat_cs_intros)\n  show ?thesis\n    by \n      (\n        rule cf_comma_proj_left_is_tm_functor[\n          OF is_tm_functor_axioms const,\n          folded cf_cf_obj_comma_proj_def cat_cf_obj_comma_def\n          ]\n      )\nqed\n\nlemma (in is_tm_functor) cf_cf_obj_comma_proj_is_tm_functor'[cat_comma_cs_intros]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" and \"\\<FF>b = \\<FF> \\<^sub>C\\<^sub>F\\<down> b\"\n  shows \"\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b : \\<FF>b \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n  using assms(1) unfolding assms(2) by (rule cf_cf_obj_comma_proj_is_tm_functor)\n\nlemmas [cat_comma_cs_intros] = is_tm_functor.cf_cf_obj_comma_proj_is_tm_functor'\n\nlemma (in is_tm_functor) cf_obj_cf_comma_proj_is_tm_functor:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF> : b \\<down>\\<^sub>C\\<^sub>F \\<FF> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\nproof-\n  from assms have const: \"cf_const (cat_1 0 0) \\<BB> b : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    by (cs_concl cs_intro: V_cs_intros cat_small_cs_intros cat_cs_intros)\n  show ?thesis\n    by \n      (\n        rule cf_comma_proj_right_is_tm_functor[\n          OF const is_tm_functor_axioms,\n          folded cf_obj_cf_comma_proj_def cat_obj_cf_comma_def\n          ]\n      )\nqed\n\nlemma (in is_tm_functor) cf_obj_cf_comma_proj_is_tm_functor'[cat_comma_cs_intros]:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" and \"\\<AA>' = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\"\n  shows \"b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF> : \\<AA>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n  using assms(1) unfolding assms(2) by (rule cf_obj_cf_comma_proj_is_tm_functor)\n\nlemmas [cat_comma_cs_intros] = is_tm_functor.cf_obj_cf_comma_proj_is_tm_functor'\n\nlemma cf_comp_cf_cf_obj_comma_proj_is_tm_functor[cat_comma_cs_intros]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \n    and \"\\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<GG> \\<^sub>C\\<^sub>F\\<down> c\"\n    and \"c \\<in>\\<^sub>\\<circ> \\<CC>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<GG> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O c \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\nproof-\n  interpret \\<GG>: is_functor \\<alpha> \\<AA> \\<CC> \\<GG> by (rule assms(1))\n  from assms(3) have cf_const: \"cf_const (cat_1 0 0) \\<CC> c : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    by (cs_concl cs_simp: cat_cs_simps cs_intro: V_cs_intros cat_cs_intros)\n  show ?thesis\n    by \n      (\n        rule cf_comp_cf_comma_proj_left_is_tm_functor\n          [\n            OF assms(1) _ assms(2)[unfolded cat_cf_obj_comma_def],\n            unfolded cat_cs_simps,\n            OF cf_const, \n            folded \\<GG>.cf_cf_obj_comma_proj_def\n          ]\n      )\nqed\n\nlemma cf_comp_cf_obj_cf_comma_proj_is_tm_functor[cat_comma_cs_intros]:\n  assumes \"\\<HH> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \n    and \"\\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> c \\<down>\\<^sub>C\\<^sub>F \\<HH>\"\n    and \"c \\<in>\\<^sub>\\<circ> \\<CC>\\<lparr>Obj\\<rparr>\"\n  shows \"c \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<HH> \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\nproof-\n  interpret \\<HH>: is_functor \\<alpha> \\<BB> \\<CC> \\<HH> by (rule assms(1))\n  from assms(3) have cf_const: \"cf_const (cat_1 0 0) \\<CC> c : cat_1 0 0 \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    by (cs_concl cs_simp: cat_cs_simps cs_intro: V_cs_intros cat_cs_intros)\n  show ?thesis\n    by \n      (\n        rule cf_comp_cf_comma_proj_right_is_tm_functor\n          [\n            OF _ assms(1) assms(2)[unfolded cat_obj_cf_comma_def], \n            unfolded cat_cs_simps,\n            OF cf_const, \n            folded \\<HH>.cf_obj_cf_comma_proj_def\n          ]\n      )\nqed\n\n\n\nsubsection\\<open>Comma functors\\<close>\n\n\nsubsubsection\\<open>Definition and elementary properties\\<close>\n\n\ntext\\<open>See Theorem 1 in Chapter X-3 in \\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>.\\<close>\n\ndefinition cf_arr_cf_comma :: \"V \\<Rightarrow> V \\<Rightarrow> V\" \n  (\\<open>(_ \\<^sub>A\\<down>\\<^sub>C\\<^sub>F _)\\<close> [1000, 1000] 999)\n  where \"g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF> =\n    [\n      (\\<lambda>A\\<in>\\<^sub>\\<circ>(\\<FF>\\<lparr>HomCod\\<rparr>\\<lparr>Cod\\<rparr>\\<lparr>g\\<rparr>) \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>. [0, A\\<lparr>1\\<^sub>\\<nat>\\<rparr>, A\\<lparr>2\\<^sub>\\<nat>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<FF>\\<lparr>HomCod\\<rparr>\\<^esub> g]\\<^sub>\\<circ>),\n      (\n        \\<lambda>F\\<in>\\<^sub>\\<circ>(\\<FF>\\<lparr>HomCod\\<rparr>\\<lparr>Cod\\<rparr>\\<lparr>g\\<rparr>) \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>.\n          [\n            [0, F\\<lparr>0\\<rparr>\\<lparr>1\\<^sub>\\<nat>\\<rparr>, F\\<lparr>0\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<FF>\\<lparr>HomCod\\<rparr>\\<^esub> g]\\<^sub>\\<circ>,\n            [0, F\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>1\\<^sub>\\<nat>\\<rparr>, F\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<FF>\\<lparr>HomCod\\<rparr>\\<^esub> g]\\<^sub>\\<circ>,\n            F\\<lparr>2\\<^sub>\\<nat>\\<rparr>\n          ]\\<^sub>\\<circ>\n      ),\n      (\\<FF>\\<lparr>HomCod\\<rparr>\\<lparr>Cod\\<rparr>\\<lparr>g\\<rparr>) \\<down>\\<^sub>C\\<^sub>F \\<FF>,\n      (\\<FF>\\<lparr>HomCod\\<rparr>\\<lparr>Dom\\<rparr>\\<lparr>g\\<rparr>) \\<down>\\<^sub>C\\<^sub>F \\<FF>\n    ]\\<^sub>\\<circ>\"\n\ndefinition cf_cf_arr_comma :: \"V \\<Rightarrow> V \\<Rightarrow> V\" \n  (\\<open>(_ \\<^sub>C\\<^sub>F\\<down>\\<^sub>A _)\\<close> [1000, 1000] 999)\n  where \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g =\n    [\n      (\\<lambda>A\\<in>\\<^sub>\\<circ>\\<FF> \\<^sub>C\\<^sub>F\\<down> (\\<FF>\\<lparr>HomCod\\<rparr>\\<lparr>Dom\\<rparr>\\<lparr>g\\<rparr>)\\<lparr>Obj\\<rparr>. [A\\<lparr>0\\<rparr>, 0, g \\<circ>\\<^sub>A\\<^bsub>\\<FF>\\<lparr>HomCod\\<rparr>\\<^esub> A\\<lparr>2\\<^sub>\\<nat>\\<rparr>]\\<^sub>\\<circ>),\n      (\n        \\<lambda>F\\<in>\\<^sub>\\<circ>\\<FF> \\<^sub>C\\<^sub>F\\<down> (\\<FF>\\<lparr>HomCod\\<rparr>\\<lparr>Dom\\<rparr>\\<lparr>g\\<rparr>)\\<lparr>Arr\\<rparr>.\n          [\n            [F\\<lparr>0\\<rparr>\\<lparr>0\\<rparr>, 0, g \\<circ>\\<^sub>A\\<^bsub>\\<FF>\\<lparr>HomCod\\<rparr>\\<^esub> F\\<lparr>0\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr>]\\<^sub>\\<circ>,\n            [F\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>0\\<rparr>, 0, g \\<circ>\\<^sub>A\\<^bsub>\\<FF>\\<lparr>HomCod\\<rparr>\\<^esub> F\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr>]\\<^sub>\\<circ>,\n            F\\<lparr>2\\<^sub>\\<nat>\\<rparr>\n          ]\\<^sub>\\<circ>\n      ),\n      \\<FF> \\<^sub>C\\<^sub>F\\<down> (\\<FF>\\<lparr>HomCod\\<rparr>\\<lparr>Dom\\<rparr>\\<lparr>g\\<rparr>),\n      \\<FF> \\<^sub>C\\<^sub>F\\<down> (\\<FF>\\<lparr>HomCod\\<rparr>\\<lparr>Cod\\<rparr>\\<lparr>g\\<rparr>)\n    ]\\<^sub>\\<circ>\"\n\n\ntext\\<open>Components.\\<close>\n\nlemma cf_arr_cf_comma_components:\n  shows \"g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr> =\n    (\\<lambda>A\\<in>\\<^sub>\\<circ>(\\<FF>\\<lparr>HomCod\\<rparr>\\<lparr>Cod\\<rparr>\\<lparr>g\\<rparr>) \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>. [0, A\\<lparr>1\\<^sub>\\<nat>\\<rparr>, A\\<lparr>2\\<^sub>\\<nat>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<FF>\\<lparr>HomCod\\<rparr>\\<^esub> g]\\<^sub>\\<circ>)\"\n    and \"g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ArrMap\\<rparr> =\n      (\n        \\<lambda>F\\<in>\\<^sub>\\<circ>(\\<FF>\\<lparr>HomCod\\<rparr>\\<lparr>Cod\\<rparr>\\<lparr>g\\<rparr>) \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>.\n          [\n            [0, F\\<lparr>0\\<rparr>\\<lparr>1\\<^sub>\\<nat>\\<rparr>, F\\<lparr>0\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<FF>\\<lparr>HomCod\\<rparr>\\<^esub> g]\\<^sub>\\<circ>,\n            [0, F\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>1\\<^sub>\\<nat>\\<rparr>, F\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<FF>\\<lparr>HomCod\\<rparr>\\<^esub> g]\\<^sub>\\<circ>,\n            F\\<lparr>2\\<^sub>\\<nat>\\<rparr>\n          ]\\<^sub>\\<circ>\n      )\"\n    and \"g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>HomDom\\<rparr> = (\\<FF>\\<lparr>HomCod\\<rparr>\\<lparr>Cod\\<rparr>\\<lparr>g\\<rparr>) \\<down>\\<^sub>C\\<^sub>F \\<FF>\"\n    and \"g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>HomCod\\<rparr> = (\\<FF>\\<lparr>HomCod\\<rparr>\\<lparr>Dom\\<rparr>\\<lparr>g\\<rparr>) \\<down>\\<^sub>C\\<^sub>F \\<FF>\"\n  unfolding cf_arr_cf_comma_def dghm_field_simps \n  by (simp_all add: nat_omega_simps)\n\nlemma cf_cf_arr_comma_components:\n  shows \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>ObjMap\\<rparr> =\n    (\\<lambda>A\\<in>\\<^sub>\\<circ>\\<FF> \\<^sub>C\\<^sub>F\\<down> (\\<FF>\\<lparr>HomCod\\<rparr>\\<lparr>Dom\\<rparr>\\<lparr>g\\<rparr>)\\<lparr>Obj\\<rparr>. [A\\<lparr>0\\<rparr>, 0, g \\<circ>\\<^sub>A\\<^bsub>\\<FF>\\<lparr>HomCod\\<rparr>\\<^esub> A\\<lparr>2\\<^sub>\\<nat>\\<rparr>]\\<^sub>\\<circ>)\"\n    and \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>ArrMap\\<rparr> =\n      (\n        \\<lambda>F\\<in>\\<^sub>\\<circ>\\<FF> \\<^sub>C\\<^sub>F\\<down> (\\<FF>\\<lparr>HomCod\\<rparr>\\<lparr>Dom\\<rparr>\\<lparr>g\\<rparr>)\\<lparr>Arr\\<rparr>.\n          [\n            [F\\<lparr>0\\<rparr>\\<lparr>0\\<rparr>, 0, g \\<circ>\\<^sub>A\\<^bsub>\\<FF>\\<lparr>HomCod\\<rparr>\\<^esub> F\\<lparr>0\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr>]\\<^sub>\\<circ>,\n            [F\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>0\\<rparr>, 0, g \\<circ>\\<^sub>A\\<^bsub>\\<FF>\\<lparr>HomCod\\<rparr>\\<^esub> F\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr>]\\<^sub>\\<circ>,\n            F\\<lparr>2\\<^sub>\\<nat>\\<rparr>\n          ]\\<^sub>\\<circ>\n      )\"\n    and \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>HomDom\\<rparr> = \\<FF> \\<^sub>C\\<^sub>F\\<down> (\\<FF>\\<lparr>HomCod\\<rparr>\\<lparr>Dom\\<rparr>\\<lparr>g\\<rparr>)\"\n    and \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>HomCod\\<rparr> = \\<FF> \\<^sub>C\\<^sub>F\\<down> (\\<FF>\\<lparr>HomCod\\<rparr>\\<lparr>Cod\\<rparr>\\<lparr>g\\<rparr>)\"\n  unfolding cf_cf_arr_comma_def dghm_field_simps \n  by (simp_all add: nat_omega_simps)\n\ncontext is_functor\nbegin\n\nlemma cf_arr_cf_comma_components':\n  assumes \"g : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c'\"\n  shows \"g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr> = (\\<lambda>A\\<in>\\<^sub>\\<circ>c' \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>. [0, A\\<lparr>1\\<^sub>\\<nat>\\<rparr>, A\\<lparr>2\\<^sub>\\<nat>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> g]\\<^sub>\\<circ>)\"\n    and \"g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ArrMap\\<rparr> =\n      (\n        \\<lambda>F\\<in>\\<^sub>\\<circ>c' \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>.\n          [\n            [0, F\\<lparr>0\\<rparr>\\<lparr>1\\<^sub>\\<nat>\\<rparr>, F\\<lparr>0\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> g]\\<^sub>\\<circ>,\n            [0, F\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>1\\<^sub>\\<nat>\\<rparr>, F\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> g]\\<^sub>\\<circ>,\n            F\\<lparr>2\\<^sub>\\<nat>\\<rparr>\n          ]\\<^sub>\\<circ>\n      )\"\n    and [cat_comma_cs_simps]: \"g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>HomDom\\<rparr> = c' \\<down>\\<^sub>C\\<^sub>F \\<FF>\"\n    and [cat_comma_cs_simps]: \"g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>HomCod\\<rparr> = c \\<down>\\<^sub>C\\<^sub>F \\<FF>\"\n  using assms\n  unfolding cf_arr_cf_comma_components\n  by (simp_all add: cat_cs_simps)\n\nlemma cf_cf_arr_comma_components':\n  assumes \"g : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c'\"\n  shows \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>ObjMap\\<rparr> = (\\<lambda>A\\<in>\\<^sub>\\<circ>\\<FF> \\<^sub>C\\<^sub>F\\<down> c\\<lparr>Obj\\<rparr>. [A\\<lparr>0\\<rparr>, 0, g \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> A\\<lparr>2\\<^sub>\\<nat>\\<rparr>]\\<^sub>\\<circ>)\"\n    and \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>ArrMap\\<rparr> =\n      (\n        \\<lambda>F\\<in>\\<^sub>\\<circ>\\<FF> \\<^sub>C\\<^sub>F\\<down> c\\<lparr>Arr\\<rparr>.\n          [\n            [F\\<lparr>0\\<rparr>\\<lparr>0\\<rparr>, 0, g \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> F\\<lparr>0\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr>]\\<^sub>\\<circ>,\n            [F\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>0\\<rparr>, 0, g \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> F\\<lparr>1\\<^sub>\\<nat>\\<rparr>\\<lparr>2\\<^sub>\\<nat>\\<rparr>]\\<^sub>\\<circ>,\n            F\\<lparr>2\\<^sub>\\<nat>\\<rparr>\n          ]\\<^sub>\\<circ>\n      )\"\n    and [cat_comma_cs_simps]: \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>HomDom\\<rparr> = \\<FF> \\<^sub>C\\<^sub>F\\<down> c\"\n    and [cat_comma_cs_simps]: \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>HomCod\\<rparr> = \\<FF> \\<^sub>C\\<^sub>F\\<down> c'\"\n  using assms\n  unfolding cf_cf_arr_comma_components\n  by (simp_all add: cat_cs_simps)\n\nend\n\nlemmas [cat_comma_cs_simps] = is_functor.cf_arr_cf_comma_components'(3,4)\nlemmas [cat_comma_cs_simps] = is_functor.cf_cf_arr_comma_components'(3,4)\n\n\nsubsubsection\\<open>Object map\\<close>\n\nmk_VLambda cf_arr_cf_comma_components(1)[unfolded VLambda_vid_on[symmetric]]\n  |vsv cf_arr_cf_comma_ObjMap_vsv[cat_comma_cs_intros]|\n\nmk_VLambda cf_cf_arr_comma_components(1)[unfolded VLambda_vid_on[symmetric]]\n  |vsv cf_cf_arr_comma_ObjMap_vsv[cat_comma_cs_intros]|\n\ncontext is_functor\nbegin\n\ncontext \n  fixes g c c'\n  assumes g: \"g : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c'\"\nbegin\n\nmk_VLambda \n  cf_arr_cf_comma_components'(1)[OF g, unfolded VLambda_vid_on[symmetric]]\n  |vdomain cf_arr_cf_comma_ObjMap_vdomain[cat_comma_cs_simps]|\n\nmk_VLambda\n  cf_cf_arr_comma_components'(1)[OF g, unfolded VLambda_vid_on[symmetric]]\n  |vdomain cf_cf_arr_comma_ObjMap_vdomain[cat_comma_cs_simps]|\n\nend\n\nend\n\nlemmas [cat_comma_cs_simps] = is_functor.cf_arr_cf_comma_ObjMap_vdomain\nlemmas [cat_comma_cs_simps] = is_functor.cf_cf_arr_comma_ObjMap_vdomain\n\nlemma (in is_functor) cf_arr_cf_comma_ObjMap_app[cat_comma_cs_simps]:\n  assumes \"A = [a', b', f']\\<^sub>\\<circ>\" and \"A \\<in>\\<^sub>\\<circ> c' \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\" and \"g : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c'\"\n  shows \"g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> = [a', b', f' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> g]\\<^sub>\\<circ>\"\nproof-\n  from assms have b': \"b' \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n    and f: \"f' : c' \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n    and a'_def: \"a' = 0\"\n    by auto\n  from assms(2) show ?thesis\n    unfolding cf_arr_cf_comma_components'[OF assms(3)] assms(1)\n    by (simp add: nat_omega_simps a'_def)\nqed\n\nlemma (in is_functor) cf_cf_arr_comma_ObjMap_app[cat_comma_cs_simps]:\n  assumes \"A = [a', b', f']\\<^sub>\\<circ>\" and \"A \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> c\\<lparr>Obj\\<rparr>\" and \"g : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c'\"\n  shows \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> = [a', b', g \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f']\\<^sub>\\<circ>\"\nproof-\n  from assms have b'_def: \"b' = 0\"\n    and f: \"f' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\"\n    and a': \"a' \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n    by auto\n  from assms(2) show ?thesis\n    unfolding cf_cf_arr_comma_components'[OF assms(3)] assms(1)\n    by (simp add: nat_omega_simps b'_def)\nqed\n\nlemmas [cat_comma_cs_simps] = is_functor.cf_arr_cf_comma_ObjMap_app\nlemmas [cat_comma_cs_simps] = is_functor.cf_cf_arr_comma_ObjMap_app\n\nlemma (in is_functor) cf_arr_cf_comma_ObjMap_vrange: \n  assumes \"g : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c'\"\n  shows \"\\<R>\\<^sub>\\<circ> (g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr>) \\<subseteq>\\<^sub>\\<circ> c \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\nproof\n  (\n    rule vsv.vsv_vrange_vsubset, \n    unfold cf_arr_cf_comma_ObjMap_vdomain[OF assms]\n  )\n  fix A assume \"A \\<in>\\<^sub>\\<circ> c' \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n  with assms is_functor_axioms obtain a f \n    where A_def: \"A = [0, a, f]\\<^sub>\\<circ>\"\n      and a: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n      and f: \"f : c' \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\" \n    by auto\n  from assms a f show \"g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> \\<in>\\<^sub>\\<circ> c \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n    by \n      (\n        cs_concl cs_shallow\n          cs_simp: cat_comma_cs_simps A_def\n          cs_intro: cat_cs_intros cat_comma_cs_intros\n      )\nqed (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)\n\nlemma (in is_functor) cf_cf_arr_comma_ObjMap_vrange: \n  assumes \"g : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c'\"\n  shows \"\\<R>\\<^sub>\\<circ> (\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>ObjMap\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> c'\\<lparr>Obj\\<rparr>\"\nproof\n  (\n    rule vsv.vsv_vrange_vsubset, \n    unfold cf_cf_arr_comma_ObjMap_vdomain[OF assms]\n  )\n  fix A assume \"A \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> c\\<lparr>Obj\\<rparr>\"\n  with assms is_functor_axioms obtain a f \n    where A_def: \"A = [a, 0, f]\\<^sub>\\<circ>\"\n      and a: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n      and f: \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\" \n    by auto\n  from assms a f show \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> c'\\<lparr>Obj\\<rparr>\"\n    by\n      (\n        cs_concl cs_shallow\n          cs_simp: cat_comma_cs_simps A_def\n          cs_intro: cat_cs_intros cat_comma_cs_intros\n      )\nqed (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)\n\n\nsubsubsection\\<open>Arrow map\\<close>\n\nmk_VLambda cf_arr_cf_comma_components(2)\n  |vsv cf_arr_cf_comma_ArrMap_vsv[cat_comma_cs_intros]|\n\nmk_VLambda cf_cf_arr_comma_components(2)\n  |vsv cf_cf_arr_comma_ArrMap_vsv[cat_comma_cs_intros]|\n\ncontext is_functor\nbegin\n\ncontext \n  fixes g c c'\n  assumes g: \"g : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c'\"\nbegin\n\nmk_VLambda \n  cf_arr_cf_comma_components'(2)[OF g, unfolded VLambda_vid_on[symmetric]]\n  |vdomain cf_arr_cf_comma_ArrMap_vdomain[cat_comma_cs_simps]|\n\nmk_VLambda \n  cf_cf_arr_comma_components'(2)[OF g, unfolded VLambda_vid_on[symmetric]]\n  |vdomain cf_cf_arr_comma_ArrMap_vdomain[cat_comma_cs_simps]|\n\nend\n\nend\n\nlemmas [cat_comma_cs_simps] = is_functor.cf_arr_cf_comma_ArrMap_vdomain\nlemmas [cat_comma_cs_simps] = is_functor.cf_cf_arr_comma_ArrMap_vdomain\n\nlemma (in is_functor) cf_arr_cf_comma_ArrMap_app[cat_comma_cs_simps]:\n  assumes \"A = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [h, k]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n    and \"[[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [h, k]\\<^sub>\\<circ>]\\<^sub>\\<circ> :\n    [a, b, f]\\<^sub>\\<circ> \\<mapsto>\\<^bsub>c' \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<^esub> [a', b', f']\\<^sub>\\<circ>\" \n    and \"g : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c'\"\n  shows \"g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>A\\<rparr> =\n    [[a, b, f \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> g]\\<^sub>\\<circ>, [a', b', f' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> g]\\<^sub>\\<circ>, [h, k]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\nproof-\n  from assms(3) have c': \"c' \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" by auto\n  from \n    cat_obj_cf_comma_is_arrD(1,2)[OF assms(2)[unfolded cat_comma_cs_simps] c'] \n    is_arrD(1)[OF assms(2)] \n  show ?thesis\n    unfolding assms(1) cf_arr_cf_comma_components'[OF assms(3)]\n    by (simp_all add: nat_omega_simps)\nqed\n\nlemmas [cat_comma_cs_simps] = is_functor.cf_arr_cf_comma_ArrMap_app\n\nlemma (in is_functor) cf_cf_arr_comma_ArrMap_app[cat_comma_cs_simps]:\n  assumes \"A = [[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [h, k]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n    and \"[[a, b, f]\\<^sub>\\<circ>, [a', b', f']\\<^sub>\\<circ>, [h, k]\\<^sub>\\<circ>]\\<^sub>\\<circ> :\n      [a, b, f]\\<^sub>\\<circ> \\<mapsto>\\<^bsub>\\<FF> \\<^sub>C\\<^sub>F\\<down> c\\<^esub> [a', b', f']\\<^sub>\\<circ>\" \n    and \"g : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c'\"\n  shows \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>ArrMap\\<rparr>\\<lparr>A\\<rparr> =\n    [[a, b, g \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f]\\<^sub>\\<circ>, [a', b', g \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f']\\<^sub>\\<circ>, [h, k]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\nproof-\n  from assms(3) have c: \"c \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" by auto\n  from \n    cat_cf_obj_comma_is_arrD(1,2)[OF assms(2)[unfolded cat_comma_cs_simps] c] \n    is_arrD(1)[OF assms(2)] \n  show ?thesis\n    unfolding assms(1) cf_cf_arr_comma_components'[OF assms(3)]\n    by (simp_all add: nat_omega_simps)\nqed\n\nlemmas [cat_comma_cs_simps] = is_functor.cf_cf_arr_comma_ArrMap_app\n\n\nsubsubsection\\<open>Comma functors are functors\\<close>\n\nlemma (in is_functor) cf_arr_cf_comma_is_functor:\n  assumes \"g : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c'\"\n  shows \"g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF> : c' \\<down>\\<^sub>C\\<^sub>F \\<FF> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> c \\<down>\\<^sub>C\\<^sub>F \\<FF>\"\nproof(rule is_functorI')\n  show \"vfsequence (g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>)\" unfolding cf_arr_cf_comma_def by simp\n  from assms show \"category \\<alpha> (c' \\<down>\\<^sub>C\\<^sub>F \\<FF>)\"\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_comma_cs_intros)\n  from assms show \"category \\<alpha> (c \\<down>\\<^sub>C\\<^sub>F \\<FF>)\"\n    by (cs_concl cs_intro: cat_cs_intros cat_comma_cs_intros)\n  show \"vcard (g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>) = 4\\<^sub>\\<nat>\"\n    unfolding cf_arr_cf_comma_def by (simp_all add: nat_omega_simps)\n  from assms show \"\\<R>\\<^sub>\\<circ> (g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr>) \\<subseteq>\\<^sub>\\<circ> c \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n    by (intro cf_arr_cf_comma_ObjMap_vrange)\n  show \"g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr> :\n    g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> \\<mapsto>\\<^bsub>c \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<^esub> g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>B\\<rparr>\"\n    if \"F : A \\<mapsto>\\<^bsub>c' \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<^esub> B\" for A B F\n  proof-\n    from assms that obtain b f b' f' k \n      where F_def: \"F = [[0, b, f]\\<^sub>\\<circ>, [0, b', f']\\<^sub>\\<circ>, [0, k]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n        and A_def: \"A = [0, b, f]\\<^sub>\\<circ>\"\n        and B_def: \"B = [0, b', f']\\<^sub>\\<circ>\"\n        and k: \"k : b \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b'\"\n        and f: \"f : c' \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n        and f': \"f' : c' \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n        and f'_def: \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>k\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f = f'\"\n      by auto\n    from assms that k f f' show ?thesis\n      unfolding F_def A_def B_def\n      by \n        (\n          cs_concl \n            cs_simp: cat_cs_simps cat_comma_cs_simps f'_def[symmetric]\n            cs_intro: cat_cs_intros cat_comma_cs_intros\n        )\n  qed\n  show \"g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>G \\<circ>\\<^sub>A\\<^bsub>c' \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<^esub> F\\<rparr> =\n    g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>G\\<rparr> \\<circ>\\<^sub>A\\<^bsub>c \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<^esub> g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr>\"\n    if \"G : B \\<mapsto>\\<^bsub>c' \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<^esub> C\" and \"F : A \\<mapsto>\\<^bsub>c' \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<^esub> B\" for B C G A F\n  proof-\n    from that(2) assms obtain b f b' f' k \n      where F_def: \"F = [[0, b, f]\\<^sub>\\<circ>, [0, b', f']\\<^sub>\\<circ>, [0, k]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n        and A_def: \"A = [0, b, f]\\<^sub>\\<circ>\"\n        and B_def: \"B = [0, b', f']\\<^sub>\\<circ>\"\n        and k: \"k : b \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b'\"\n        and f: \"f : c' \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>b\\<rparr>\"\n        and f': \"f' : c' \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n        and f'_def: \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>k\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f = f'\"\n      by auto\n    with that(1) assms obtain b'' f'' k' \n      where G_def: \"G = [[0, b', f']\\<^sub>\\<circ>, [0, b'', f'']\\<^sub>\\<circ>, [0, k']\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n        and C_def: \"C = [0, b'', f'']\\<^sub>\\<circ>\"\n        and k': \"k' : b' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b''\"\n        and f'': \"f'' : c' \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>b''\\<rparr>\"\n        and f''_def: \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>k'\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f' = f''\"\n      by auto (*slow*)\n    from assms that k f f' f'' k' show ?thesis\n      unfolding F_def G_def A_def B_def C_def \n      by (*slow*)\n        (\n          cs_concl \n            cs_simp:\n              cat_cs_simps cat_comma_cs_simps\n              f''_def[symmetric] f'_def[symmetric]\n            cs_intro: cat_cs_intros cat_comma_cs_intros\n        )\n  qed\n  show \"g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>c' \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>CId\\<rparr>\\<lparr>C\\<rparr>\\<rparr> = c \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>CId\\<rparr>\\<lparr>g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>C\\<rparr>\\<rparr>\"\n    if \"C \\<in>\\<^sub>\\<circ> c' \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\" for C\n  proof-\n    from that assms obtain a f \n      where C_def: \"C = [0, a, f]\\<^sub>\\<circ>\"\n        and a: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n        and f: \"f : c' \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n      by auto\n    from a assms f show\n      \"g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>c' \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>CId\\<rparr>\\<lparr>C\\<rparr>\\<rparr> = c \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>CId\\<rparr>\\<lparr>g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>C\\<rparr>\\<rparr>\"\n      unfolding C_def \n      by\n        (\n          cs_concl \n            cs_simp: cat_cs_simps cat_comma_cs_simps\n            cs_intro: cat_cs_intros cat_comma_cs_intros\n        )\n  qed\nqed\n  (\n    use assms in\n      \\<open>\n        cs_concl cs_shallow\n          cs_simp: cat_comma_cs_simps\n          cs_intro: cat_cs_intros cat_comma_cs_intros\n      \\<close>\n  )+\n\nlemma (in is_functor) cf_cf_arr_comma_is_functor:\n  assumes \"g : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c'\"\n  shows \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g : \\<FF> \\<^sub>C\\<^sub>F\\<down> c \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<FF> \\<^sub>C\\<^sub>F\\<down> c'\"\nproof(rule is_functorI')\n  from assms have c: \"c \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" by auto\n  show \"vfsequence (\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g)\" unfolding cf_cf_arr_comma_def by simp\n  from assms show \"category \\<alpha> (\\<FF> \\<^sub>C\\<^sub>F\\<down> c')\"\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_comma_cs_intros)\n  from assms show \"category \\<alpha> (\\<FF> \\<^sub>C\\<^sub>F\\<down> c)\"\n    by (cs_concl cs_intro: cat_cs_intros cat_comma_cs_intros)\n  show \"vcard (\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g) = 4\\<^sub>\\<nat>\"\n    unfolding cf_cf_arr_comma_def by (simp_all add: nat_omega_simps)\n  from assms show \"\\<R>\\<^sub>\\<circ> (\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>ObjMap\\<rparr>) \\<subseteq>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> c'\\<lparr>Obj\\<rparr>\"\n    by (intro cf_cf_arr_comma_ObjMap_vrange)\n  show \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr> :\n    \\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> \\<mapsto>\\<^bsub>\\<FF> \\<^sub>C\\<^sub>F\\<down> c'\\<^esub> \\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>ObjMap\\<rparr>\\<lparr>B\\<rparr>\"\n    if \"F : A \\<mapsto>\\<^bsub>\\<FF> \\<^sub>C\\<^sub>F\\<down> c\\<^esub> B\" for A B F\n  proof-\n    from assms that obtain a f a' f' h \n      where F_def: \"F = [[a, 0, f]\\<^sub>\\<circ>, [a', 0, f']\\<^sub>\\<circ>, [h, 0]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n        and A_def: \"A = [a, 0, f]\\<^sub>\\<circ>\"\n        and B_def: \"B = [a', 0, f']\\<^sub>\\<circ>\"\n        and h: \"h : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n        and f: \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\"\n        and f': \"f' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\"\n        and f'_def: \"f' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> = f\"\n      by auto\n    from assms that h f f' show ?thesis\n      unfolding F_def A_def B_def\n      by \n        (\n          cs_concl \n            cs_simp: cat_cs_simps cat_comma_cs_simps f'_def\n            cs_intro: cat_cs_intros cat_comma_cs_intros\n        )\n  qed\n  show \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>ArrMap\\<rparr>\\<lparr>G \\<circ>\\<^sub>A\\<^bsub>\\<FF> \\<^sub>C\\<^sub>F\\<down> c\\<^esub> F\\<rparr> =\n    \\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>ArrMap\\<rparr>\\<lparr>G\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<FF> \\<^sub>C\\<^sub>F\\<down> c'\\<^esub> \\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr>\"\n    if \"G : B \\<mapsto>\\<^bsub>\\<FF> \\<^sub>C\\<^sub>F\\<down> c\\<^esub> C\" and \"F : A \\<mapsto>\\<^bsub>\\<FF> \\<^sub>C\\<^sub>F\\<down> c\\<^esub> B\" for B C G A F\n  proof-\n    from that(2) assms obtain a f a' f' h \n      where F_def: \"F = [[a, 0, f]\\<^sub>\\<circ>, [a', 0, f']\\<^sub>\\<circ>, [h, 0]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n        and A_def: \"A = [a, 0, f]\\<^sub>\\<circ>\"\n        and B_def: \"B = [a', 0, f']\\<^sub>\\<circ>\"\n        and h: \"h : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n        and f: \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\"\n        and f': \"f' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\"\n        and [cat_cs_simps]: \"f' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> = f\"\n      by auto\n    with that(1) assms obtain a'' f'' h' \n      where G_def: \"G = [[a', 0, f']\\<^sub>\\<circ>, [a'', 0, f'']\\<^sub>\\<circ>, [h', 0]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n        and C_def: \"C = [a'', 0, f'']\\<^sub>\\<circ>\"\n        and h': \"h' : a' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a''\"\n        and f'': \"f'' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a''\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\"\n        and [cat_cs_simps]: \"f'' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>h'\\<rparr> = f'\"\n      by auto (*slow*)\n    note [cat_cs_simps] = category.cat_assoc_helper[\n        where \\<CC>=\\<BB>, where h=f'' and g=\\<open>\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>h'\\<rparr>\\<close> and q=f'\n        ]\n    from assms that c h f f' f'' h' show ?thesis\n      unfolding F_def G_def A_def B_def C_def\n      by\n        (\n          cs_concl cs_shallow\n             cs_simp: cat_cs_simps cat_comma_cs_simps\n            cs_intro: cat_cs_intros cat_comma_cs_intros\n        )\n  qed\n  show \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>ArrMap\\<rparr>\\<lparr>\\<FF> \\<^sub>C\\<^sub>F\\<down> c\\<lparr>CId\\<rparr>\\<lparr>C\\<rparr>\\<rparr> = \\<FF> \\<^sub>C\\<^sub>F\\<down> c'\\<lparr>CId\\<rparr>\\<lparr>\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g\\<lparr>ObjMap\\<rparr>\\<lparr>C\\<rparr>\\<rparr>\"\n    if \"C \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> c\\<lparr>Obj\\<rparr>\" for C\n  proof-\n    from that assms obtain a f \n      where C_def: \"C = [a, 0, f]\\<^sub>\\<circ>\"\n        and a: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n        and f: \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\"\n      by auto\n    from a c assms f show ?thesis\n      unfolding C_def \n      by\n        (\n          cs_concl cs_shallow\n            cs_simp: cat_cs_simps cat_comma_cs_simps\n            cs_intro: cat_cs_intros cat_comma_cs_intros\n        )\n  qed\nqed\n  (\n    use assms in\n      \\<open>\n        cs_concl cs_shallow\n          cs_simp: cat_comma_cs_simps\n          cs_intro: cat_cs_intros cat_comma_cs_intros\n      \\<close>\n  )+\n\nlemma (in is_functor) cf_arr_cf_comma_is_functor'[cat_comma_cs_intros]:\n  assumes \"g : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c'\" and \"\\<AA>' = c' \\<down>\\<^sub>C\\<^sub>F \\<FF>\" and \"\\<BB>' = c \\<down>\\<^sub>C\\<^sub>F \\<FF>\"\n  shows \"g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF> : \\<AA>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>'\"\n  using assms(1) unfolding assms(2,3) by (rule cf_arr_cf_comma_is_functor(1))\n\nlemmas [cat_comma_cs_intros] = is_functor.cf_arr_cf_comma_is_functor'\n\nlemma (in is_functor) cf_cf_arr_comma_is_functor'[cat_comma_cs_intros]:\n  assumes \"g : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c'\" and \"\\<AA>' = \\<FF> \\<^sub>C\\<^sub>F\\<down> c\" and \"\\<BB>' = \\<FF> \\<^sub>C\\<^sub>F\\<down> c'\"\n  shows \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g : \\<AA>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>'\"\n  using assms(1) unfolding assms(2,3) by (rule cf_cf_arr_comma_is_functor(1))\n\nlemmas [cat_comma_cs_intros] = is_functor.cf_cf_arr_comma_is_functor'\n\nlemma (in is_functor) cf_arr_cf_comma_CId:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"(\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>) \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF> = cf_id (b \\<down>\\<^sub>C\\<^sub>F \\<FF>)\"\nproof(rule cf_eqI)\n  from vempty_is_zet assms show \"cf_id (b \\<down>\\<^sub>C\\<^sub>F \\<FF>) : b \\<down>\\<^sub>C\\<^sub>F \\<FF> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\"\n    by (cs_concl cs_intro: cat_cs_intros cat_comma_cs_intros)\n  from vempty_is_zet assms show \"(\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>) \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF> : b \\<down>\\<^sub>C\\<^sub>F \\<FF> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\"\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_comma_cs_intros)\n  from assms have ObjMap_dom_lhs: \n    \"\\<D>\\<^sub>\\<circ> ((\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>) \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr>) = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps cs_intro: cat_cs_intros)\n  from assms have ObjMap_dom_rhs: \n    \"\\<D>\\<^sub>\\<circ> (cf_id (b \\<down>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ObjMap\\<rparr>) = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  show \"(\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>) \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr> = cf_id (b \\<down>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ObjMap\\<rparr>\"\n  proof(rule vsv_eqI, unfold ObjMap_dom_lhs ObjMap_dom_rhs)\n    fix A assume prems: \"A \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n    with assms obtain a' f' \n      where A_def: \"A = [0, a', f']\\<^sub>\\<circ>\"\n        and a': \"a' \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n        and f': \"f' : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr>\"\n      by auto\n    from prems assms vempty_is_zet a' f' show \n      \"(\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>) \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> = cf_id (b \\<down>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr>\"\n      unfolding A_def\n      by \n        (\n          cs_concl cs_shallow\n            cs_simp: cat_cs_simps cat_comma_cs_simps \n            cs_intro: cat_cs_intros\n        )\n  qed (cs_concl cs_shallow cs_intro: cat_cs_intros cat_comma_cs_intros)+\n  from assms have ArrMap_dom_lhs: \n    \"\\<D>\\<^sub>\\<circ> ((\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>) \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ArrMap\\<rparr>) = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps cs_intro: cat_cs_intros)\n  from assms have ArrMap_dom_rhs: \n    \"\\<D>\\<^sub>\\<circ> (cf_id (b \\<down>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ArrMap\\<rparr>) = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  show \"(\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>) \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ArrMap\\<rparr> = cf_id (b \\<down>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ArrMap\\<rparr>\"\n  proof(rule vsv_eqI, unfold ArrMap_dom_lhs ArrMap_dom_rhs)\n    fix F assume prems: \"F \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>\"\n    then obtain A B where F: \"F : A \\<mapsto>\\<^bsub>b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<^esub> B\" by (auto dest: is_arrI)\n    from assms F obtain b' f' b'' f'' h\n      where F_def: \"F = [[0, b', f']\\<^sub>\\<circ>, [0, b'', f'']\\<^sub>\\<circ>, [0, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n        and A_def: \"A = [0, b', f']\\<^sub>\\<circ>\"\n        and B_def: \"B = [0, b'', f'']\\<^sub>\\<circ>\"\n        and h: \"h : b' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b''\"\n        and f': \"f' : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n        and f'': \"f'' : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>b''\\<rparr>\"\n        and \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f' = f''\"\n      by auto\n    from assms prems F h f' f'' show \n      \"(\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>) \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr> = cf_id (b \\<down>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr>\"\n      unfolding F_def A_def B_def\n      by \n        (\n          cs_concl cs_shallow\n            cs_simp: cat_comma_cs_simps cat_cs_simps cs_intro: cat_cs_intros\n        )\n  qed (cs_concl cs_shallow cs_intro: cat_comma_cs_intros cat_cs_intros)+\nqed simp_all\n\nlemma (in is_functor) cf_cf_arr_comma_CId:\n  assumes \"b \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\"\n  shows \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A (\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>) = cf_id (\\<FF> \\<^sub>C\\<^sub>F\\<down> b)\"\nproof(rule cf_eqI)\n  from vempty_is_zet assms show \"cf_id (\\<FF> \\<^sub>C\\<^sub>F\\<down> b) : \\<FF> \\<^sub>C\\<^sub>F\\<down> b \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\"\n    by (cs_concl cs_intro: cat_cs_intros cat_comma_cs_intros)\n  from vempty_is_zet assms show \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A (\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>) : \\<FF> \\<^sub>C\\<^sub>F\\<down> b \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\"\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_comma_cs_intros)\n  from assms have ObjMap_dom_lhs: \n    \"\\<D>\\<^sub>\\<circ> (\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A (\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>)\\<lparr>ObjMap\\<rparr>) = \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps cs_intro: cat_cs_intros)\n  from assms have ObjMap_dom_rhs:\n    \"\\<D>\\<^sub>\\<circ> (cf_id (\\<FF> \\<^sub>C\\<^sub>F\\<down> b)\\<lparr>ObjMap\\<rparr>) = \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  show \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A (\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>)\\<lparr>ObjMap\\<rparr> = cf_id (\\<FF> \\<^sub>C\\<^sub>F\\<down> b)\\<lparr>ObjMap\\<rparr>\"\n  proof(rule vsv_eqI, unfold ObjMap_dom_lhs ObjMap_dom_rhs)\n    fix A assume prems: \"A \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Obj\\<rparr>\"\n    with assms obtain a' f' \n      where A_def: \"A = [a', 0, f']\\<^sub>\\<circ>\"\n        and a': \"a' \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n        and f': \"f' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n      by auto\n    from prems assms vempty_is_zet a' f' show \n      \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A (\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>)\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> = cf_id (\\<FF> \\<^sub>C\\<^sub>F\\<down> b)\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr>\"\n      unfolding A_def\n      by \n        (\n          cs_concl cs_shallow\n            cs_simp: cat_cs_simps cat_comma_cs_simps cs_intro: cat_cs_intros\n        )\n  qed (cs_concl cs_shallow cs_intro: cat_cs_intros cat_comma_cs_intros)+\n  from assms have ArrMap_dom_lhs: \n    \"\\<D>\\<^sub>\\<circ> (\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A (\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>)\\<lparr>ArrMap\\<rparr>) = \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Arr\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps cs_intro: cat_cs_intros)\n  from assms have ArrMap_dom_rhs: \n    \"\\<D>\\<^sub>\\<circ> (cf_id (\\<FF> \\<down>\\<^sub>C\\<^sub>F b)\\<lparr>ArrMap\\<rparr>) = \\<FF> \\<down>\\<^sub>C\\<^sub>F b\\<lparr>Arr\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  show \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A (\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>)\\<lparr>ArrMap\\<rparr> = cf_id (\\<FF> \\<^sub>C\\<^sub>F\\<down> b)\\<lparr>ArrMap\\<rparr>\"\n  proof(rule vsv_eqI, unfold ArrMap_dom_lhs ArrMap_dom_rhs)\n    fix F assume prems: \"F \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<lparr>Arr\\<rparr>\"\n    then obtain A B where F: \"F : A \\<mapsto>\\<^bsub>\\<FF> \\<^sub>C\\<^sub>F\\<down> b\\<^esub> B\" by (auto dest: is_arrI)\n    from assms F obtain a' f' a'' f'' k\n      where F_def: \"F = [[a', 0, f']\\<^sub>\\<circ>, [a'', 0, f'']\\<^sub>\\<circ>, [k, 0]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n        and A_def: \"A = [a', 0, f']\\<^sub>\\<circ>\"\n        and B_def: \"B = [a'', 0, f'']\\<^sub>\\<circ>\"\n        and k: \"k : a' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a''\"\n        and f': \"f' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n        and f'': \"f'' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a''\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n        and [cat_cs_simps]: \"f'' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>k\\<rparr> = f'\"\n      by auto\n    from assms prems F k f' f'' show \n      \"\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A (\\<BB>\\<lparr>CId\\<rparr>\\<lparr>b\\<rparr>)\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr> = cf_id (\\<FF> \\<^sub>C\\<^sub>F\\<down> b)\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr>\"\n      unfolding F_def A_def B_def\n      by \n        (\n          cs_concl cs_shallow\n            cs_simp: cat_comma_cs_simps cat_cs_simps cs_intro: cat_cs_intros\n        )\n  qed\n    (\n      cs_concl cs_shallow\n        cs_simp: cat_cs_simps cs_intro: cat_comma_cs_intros cat_cs_intros\n    )+\nqed simp_all\n\n\nsubsubsection\\<open>Comma functors and projections\\<close>\n\nlemma (in is_functor) \n  cf_cf_comp_cf_obj_cf_comma_proj_cf_arr_cf_comma[cat_comma_cs_simps]: \n  assumes \"f : a \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n  shows \"a \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF> \\<circ>\\<^sub>C\\<^sub>F f \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF> = b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF>\"\nproof(rule cf_eqI)\n  from assms vempty_is_zet show \"b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF> : b \\<down>\\<^sub>C\\<^sub>F \\<FF> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n    by (cs_concl cs_shallow cs_intro: cat_cs_intros cat_comma_cs_intros)\n  from assms show \"a \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF> \\<circ>\\<^sub>C\\<^sub>F f \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF> : b \\<down>\\<^sub>C\\<^sub>F \\<FF> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n    by (cs_concl cs_intro: cat_cs_intros cat_comma_cs_intros)\n  from assms have ObjMap_dom_lhs:\n    \"\\<D>\\<^sub>\\<circ> ((a \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF> \\<circ>\\<^sub>C\\<^sub>F f \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ObjMap\\<rparr>) = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n    by \n      ( \n        cs_concl \n          cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_comma_cs_intros\n      )\n  from assms have ObjMap_dom_rhs: \"\\<D>\\<^sub>\\<circ> (b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr>) = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps)\n  show \"(a \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF> \\<circ>\\<^sub>C\\<^sub>F f \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ObjMap\\<rparr> = b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr>\"\n  proof(rule vsv_eqI, unfold ObjMap_dom_lhs ObjMap_dom_rhs)\n    from assms show \"vsv (b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr>)\"\n      by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)\n    fix A assume prems: \"A \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n    with assms obtain b' f' \n      where A_def: \"A = [0, b', f']\\<^sub>\\<circ>\"\n        and b': \"b' \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n        and f': \"f' : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n      by auto\n    from prems assms b' f' show \n      \"(a \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF> \\<circ>\\<^sub>C\\<^sub>F f \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> = b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr>\"\n      unfolding A_def\n      by \n        (\n          cs_concl \n            cs_simp: cat_cs_simps cat_comma_cs_simps \n            cs_intro: cat_cs_intros cat_comma_cs_intros\n        )\n  qed\n    (\n      use assms vempty_is_zet in\n        \\<open>cs_concl cs_intro: cat_cs_intros cat_comma_cs_intros\\<close>\n    )\n  from assms have ArrMap_dom_lhs:\n    \"\\<D>\\<^sub>\\<circ> ((a \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF> \\<circ>\\<^sub>C\\<^sub>F f \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ObjMap\\<rparr>) = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n    by\n      (\n        cs_concl \n          cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_comma_cs_intros\n      )\n  from assms vempty_is_zet have ArrMap_dom_rhs:\n    \"\\<D>\\<^sub>\\<circ> (b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ObjMap\\<rparr>) = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Obj\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps)\n  from assms vempty_is_zet have ArrMap_dom_lhs:\n    \"\\<D>\\<^sub>\\<circ> ((a \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF> \\<circ>\\<^sub>C\\<^sub>F f \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ArrMap\\<rparr>) = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>\"\n    by\n      (\n        cs_concl \n          cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_comma_cs_intros\n      )\n  from assms have ArrMap_dom_rhs: \"\\<D>\\<^sub>\\<circ> (b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ArrMap\\<rparr>) = b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps)\n  show \"(a \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF> \\<circ>\\<^sub>C\\<^sub>F f \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ArrMap\\<rparr> = b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ArrMap\\<rparr>\"\n  proof(rule vsv_eqI, unfold ArrMap_dom_lhs ArrMap_dom_rhs)\n    fix F assume \"F \\<in>\\<^sub>\\<circ> b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>Arr\\<rparr>\"\n    then obtain A B where F: \"F : A \\<mapsto>\\<^bsub>b \\<down>\\<^sub>C\\<^sub>F \\<FF>\\<^esub> B\"\n      by (auto dest: is_arrI)\n    with assms obtain b' f' b'' f'' h\n      where F_def: \"F = [[0, b', f']\\<^sub>\\<circ>, [0, b'', f'']\\<^sub>\\<circ>, [0, h]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n        and A_def: \"A = [0, b', f']\\<^sub>\\<circ>\"\n        and B_def: \"B = [0, b'', f'']\\<^sub>\\<circ>\"\n        and h: \"h : b' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> b''\"\n        and f': \"f' : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>b'\\<rparr>\"\n        and f'': \"f'' : b \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>b''\\<rparr>\"\n        and f''_def: \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f' = f''\"\n      by auto\n    from vempty_is_zet h assms f' f'' F show\n      \"(a \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF> \\<circ>\\<^sub>C\\<^sub>F f \\<^sub>A\\<down>\\<^sub>C\\<^sub>F \\<FF>)\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr> = b \\<^sub>O\\<Sqinter>\\<^sub>C\\<^sub>F \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr>\"\n      unfolding F_def A_def B_def \n      by (*slow*)\n        (\n          cs_concl \n            cs_simp: cat_cs_simps cat_comma_cs_simps f''_def[symmetric]\n            cs_intro: cat_cs_intros cat_comma_cs_intros\n        )+\n  qed\n    (\n      use assms vempty_is_zet in\n        \\<open>cs_concl cs_intro: cat_cs_intros cat_comma_cs_intros\\<close>\n    )\nqed simp_all\n\nlemma (in is_functor) \n  cf_cf_comp_cf_cf_obj_comma_proj_cf_cf_arr_comma[cat_comma_cs_simps]: \n  assumes \"f : a \\<mapsto>\\<^bsub>\\<BB>\\<^esub> b\"\n  shows \"\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b \\<circ>\\<^sub>C\\<^sub>F \\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A f = \\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O a\"\nproof(rule cf_eqI)\n  from assms vempty_is_zet show \"\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O a : \\<FF> \\<^sub>C\\<^sub>F\\<down> a \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n    by (cs_concl cs_intro: cat_cs_intros cat_comma_cs_intros)\n  from assms show \"\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b \\<circ>\\<^sub>C\\<^sub>F \\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A f : \\<FF> \\<^sub>C\\<^sub>F\\<down> a \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n    by (cs_concl cs_intro: cat_cs_intros cat_comma_cs_intros)\n  from assms have ObjMap_dom_lhs:\n    \"\\<D>\\<^sub>\\<circ> ((\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b \\<circ>\\<^sub>C\\<^sub>F \\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A f)\\<lparr>ObjMap\\<rparr>) = \\<FF> \\<^sub>C\\<^sub>F\\<down> a\\<lparr>Obj\\<rparr>\"\n    by \n      ( \n        cs_concl cs_shallow \n          cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_comma_cs_intros\n      )\n  from assms have ObjMap_dom_rhs: \"\\<D>\\<^sub>\\<circ> (\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O a\\<lparr>ObjMap\\<rparr>) = \\<FF> \\<^sub>C\\<^sub>F\\<down> a\\<lparr>Obj\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps)\n  show \"(\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b \\<circ>\\<^sub>C\\<^sub>F \\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A f)\\<lparr>ObjMap\\<rparr> = \\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O a\\<lparr>ObjMap\\<rparr>\"\n  proof(rule vsv_eqI, unfold ObjMap_dom_lhs ObjMap_dom_rhs)\n    from assms show \"vsv (\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O a\\<lparr>ObjMap\\<rparr>)\"\n      by (cs_concl cs_shallow cs_intro: cat_comma_cs_intros)\n    fix A assume prems: \"A \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> a\\<lparr>Obj\\<rparr>\"\n    with assms obtain a' f' \n      where A_def: \"A = [a', 0, f']\\<^sub>\\<circ>\"\n        and b': \"a' \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\"\n        and f': \"f' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> a\"\n      by auto\n    from prems assms b' f' show\n      \"(\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b \\<circ>\\<^sub>C\\<^sub>F \\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A f)\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> = \\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O a\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr>\"\n      unfolding A_def\n      by\n        (\n          cs_concl cs_shallow\n            cs_simp: cat_cs_simps cat_comma_cs_simps \n            cs_intro: cat_cs_intros cat_comma_cs_intros\n        )\n  qed\n    (\n      use assms vempty_is_zet in\n        \\<open>cs_concl cs_shallow cs_intro: cat_cs_intros cat_comma_cs_intros\\<close>\n    )\n  from assms vempty_is_zet have ArrMap_dom_lhs:\n    \"\\<D>\\<^sub>\\<circ> ((\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b \\<circ>\\<^sub>C\\<^sub>F \\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A f)\\<lparr>ArrMap\\<rparr>) = \\<FF> \\<^sub>C\\<^sub>F\\<down> a\\<lparr>Arr\\<rparr>\"\n    by\n      (\n        cs_concl cs_shallow\n          cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_comma_cs_intros\n      )\n  from assms have ArrMap_dom_rhs: \"\\<D>\\<^sub>\\<circ> (\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O a\\<lparr>ArrMap\\<rparr>) = \\<FF> \\<^sub>C\\<^sub>F\\<down> a\\<lparr>Arr\\<rparr>\"\n    by (cs_concl cs_shallow cs_simp: cat_comma_cs_simps)\n  show \"(\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b \\<circ>\\<^sub>C\\<^sub>F \\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A f)\\<lparr>ArrMap\\<rparr> = \\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O a\\<lparr>ArrMap\\<rparr>\"\n  proof(rule vsv_eqI, unfold ArrMap_dom_lhs ArrMap_dom_rhs)\n    fix F assume \"F \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> a\\<lparr>Arr\\<rparr>\"\n    then obtain A B where F: \"F : A \\<mapsto>\\<^bsub>\\<FF> \\<^sub>C\\<^sub>F\\<down> a\\<^esub> B\" by (auto dest: is_arrI)\n    with assms obtain a' f' a'' f'' k\n      where F_def: \"F = [[a', 0, f']\\<^sub>\\<circ>, [a'', 0, f'']\\<^sub>\\<circ>, [k, 0]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n        and A_def: \"A = [a', 0, f']\\<^sub>\\<circ>\"\n        and B_def: \"B = [a'', 0, f'']\\<^sub>\\<circ>\"\n        and k: \"k : a' \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a''\"\n        and f': \"f' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> a\"\n        and f'': \"f'' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a''\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> a\"\n        and f'_def: \"f'' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>k\\<rparr> = f'\"\n      by auto\n    from vempty_is_zet k assms f' f'' F show\n      \"(\\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O b \\<circ>\\<^sub>C\\<^sub>F \\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A f)\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr> = \\<FF> \\<^sub>C\\<^sub>F\\<Sqinter>\\<^sub>O a\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr>\"\n      unfolding F_def A_def B_def \n      by\n        (\n          cs_concl cs_shallow\n            cs_simp: cat_cs_simps cat_comma_cs_simps f'_def\n            cs_intro: cat_cs_intros cat_comma_cs_intros\n        )+\n  qed\n    (\n      use assms vempty_is_zet in\n        \\<open>cs_concl cs_shallow cs_intro: cat_cs_intros cat_comma_cs_intros\\<close>\n    )\nqed simp_all\n\n\nsubsubsection\\<open>Opposite comma functors\\<close>\n\nlemma (in is_functor) cf_op_cf_obj_comma_cf_arr_cf_comma:\n  assumes \"g : c \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c'\"\n  shows \n    \"op_cf_obj_comma \\<FF> c' \\<circ>\\<^sub>C\\<^sub>F op_cf (\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g) =\n      g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F (op_cf \\<FF>) \\<circ>\\<^sub>C\\<^sub>F op_cf_obj_comma \\<FF> c\"\nproof(rule cf_eqI)\n  from assms interpret \\<FF>c: category \\<alpha> \\<open>\\<FF> \\<^sub>C\\<^sub>F\\<down> c\\<close>\n    by\n      (\n        cs_concl \n          cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_comma_cs_intros\n      )\n  from assms have c: \"c \\<in>\\<^sub>\\<circ> \\<BB>\\<lparr>Obj\\<rparr>\" by auto\n  from assms show \"op_cf_obj_comma \\<FF> c' \\<circ>\\<^sub>C\\<^sub>F op_cf (\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g) :\n    op_cat (\\<FF> \\<^sub>C\\<^sub>F\\<down> c) \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> c' \\<down>\\<^sub>C\\<^sub>F (op_cf \\<FF>)\"\n    by\n      (\n        cs_concl \n          cs_simp: cat_cs_simps cat_op_simps\n          cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros\n      )\n  then have ObjMap_dom_lhs:\n    \"\\<D>\\<^sub>\\<circ> ((op_cf_obj_comma \\<FF> c' \\<circ>\\<^sub>C\\<^sub>F op_cf (\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g))\\<lparr>ObjMap\\<rparr>) =\n      (op_cat (\\<FF> \\<^sub>C\\<^sub>F\\<down> c))\\<lparr>Obj\\<rparr>\"\n    and ArrMap_dom_lhs:\n    \"\\<D>\\<^sub>\\<circ> ((op_cf_obj_comma \\<FF> c' \\<circ>\\<^sub>C\\<^sub>F op_cf (\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g))\\<lparr>ArrMap\\<rparr>) =\n      (op_cat (\\<FF> \\<^sub>C\\<^sub>F\\<down> c))\\<lparr>Arr\\<rparr>\"\n    by (cs_concl cs_simp: cat_cs_simps)+\n  from assms show \n    \"g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F (op_cf \\<FF>) \\<circ>\\<^sub>C\\<^sub>F op_cf_obj_comma \\<FF> c :\n      op_cat (\\<FF> \\<^sub>C\\<^sub>F\\<down> c) \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> c' \\<down>\\<^sub>C\\<^sub>F (op_cf \\<FF>)\"\n    by\n      (\n        cs_concl \n          cs_simp: cat_cs_simps cat_op_simps\n          cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros\n      )\n  then have ObjMap_dom_rhs:\n    \"\\<D>\\<^sub>\\<circ> ((g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F (op_cf \\<FF>) \\<circ>\\<^sub>C\\<^sub>F op_cf_obj_comma \\<FF> c)\\<lparr>ObjMap\\<rparr>) =\n      (op_cat (\\<FF> \\<^sub>C\\<^sub>F\\<down> c))\\<lparr>Obj\\<rparr>\"\n    and ArrMap_dom_rhs:\n    \"\\<D>\\<^sub>\\<circ> ((g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F (op_cf \\<FF>) \\<circ>\\<^sub>C\\<^sub>F op_cf_obj_comma \\<FF> c)\\<lparr>ArrMap\\<rparr>) =\n      (op_cat (\\<FF> \\<^sub>C\\<^sub>F\\<down> c))\\<lparr>Arr\\<rparr>\"\n    by (cs_concl cs_simp: cat_cs_simps)+\n  show\n    \"(op_cf_obj_comma \\<FF> c' \\<circ>\\<^sub>C\\<^sub>F op_cf (\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g))\\<lparr>ObjMap\\<rparr> =\n      (g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F (op_cf \\<FF>) \\<circ>\\<^sub>C\\<^sub>F op_cf_obj_comma \\<FF> c)\\<lparr>ObjMap\\<rparr>\"\n  proof(rule vsv_eqI, unfold ObjMap_dom_lhs ObjMap_dom_rhs cat_op_simps)\n    fix A assume \"A \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> c\\<lparr>Obj\\<rparr>\"\n    with assms obtain a f\n      where A_def: \"A = [a, 0, f]\\<^sub>\\<circ>\" \n        and a: \"a \\<in>\\<^sub>\\<circ> \\<AA>\\<lparr>Obj\\<rparr>\" \n        and f: \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\"\n      by auto\n    from assms a f show \n      \"(op_cf_obj_comma \\<FF> c' \\<circ>\\<^sub>C\\<^sub>F op_cf (\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g))\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr> =\n        (g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F (op_cf \\<FF>) \\<circ>\\<^sub>C\\<^sub>F op_cf_obj_comma \\<FF> c)\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr>\"\n      unfolding A_def \n      by\n        (\n          cs_concl cs_shallow\n            cs_simp: cat_cs_simps cat_comma_cs_simps cat_op_simps\n            cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros\n        )\n  qed \n    (\n      use assms in \n        \\<open>cs_concl cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros\\<close>\n    )+\n  show \n    \"(op_cf_obj_comma \\<FF> c' \\<circ>\\<^sub>C\\<^sub>F op_cf (\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g))\\<lparr>ArrMap\\<rparr> =\n      (g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F (op_cf \\<FF>) \\<circ>\\<^sub>C\\<^sub>F op_cf_obj_comma \\<FF> c)\\<lparr>ArrMap\\<rparr>\"\n  proof(rule vsv_eqI, unfold ArrMap_dom_lhs ArrMap_dom_rhs cat_op_simps)\n    fix F assume \"F \\<in>\\<^sub>\\<circ> \\<FF> \\<^sub>C\\<^sub>F\\<down> c\\<lparr>Arr\\<rparr>\"\n    then obtain A B where F: \"F : A \\<mapsto>\\<^bsub>\\<FF> \\<^sub>C\\<^sub>F\\<down> c\\<^esub> B\" by auto\n    with assms c obtain a f a' f' h\n      where F_def: \"F = [[a, 0, f]\\<^sub>\\<circ>, [a', 0, f']\\<^sub>\\<circ>, [h, 0]\\<^sub>\\<circ>]\\<^sub>\\<circ>\"\n        and A_def: \"A = [a, 0, f]\\<^sub>\\<circ>\"\n        and B_def: \"B = [a', 0, f']\\<^sub>\\<circ>\"\n        and h: \"h : a \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a'\"\n        and f: \"f : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\"\n        and f': \"f' : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a'\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> c\"\n        and [cat_comma_cs_simps]: \"f' \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>h\\<rparr> = f\"\n      by auto\n    from F assms h f f' c show \n      \"(op_cf_obj_comma \\<FF> c' \\<circ>\\<^sub>C\\<^sub>F op_cf (\\<FF> \\<^sub>C\\<^sub>F\\<down>\\<^sub>A g))\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr> =\n        (g \\<^sub>A\\<down>\\<^sub>C\\<^sub>F (op_cf \\<FF>) \\<circ>\\<^sub>C\\<^sub>F op_cf_obj_comma \\<FF> c)\\<lparr>ArrMap\\<rparr>\\<lparr>F\\<rparr>\"\n      unfolding F_def A_def B_def\n      by\n        (\n          cs_concl cs_shallow\n            cs_simp: cat_cs_simps cat_comma_cs_simps cat_op_simps\n            cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros\n        )\n  qed\n    (\n      use assms in\n        \\<open>cs_concl cs_intro: cat_cs_intros cat_comma_cs_intros cat_op_intros\\<close>\n    )+\nqed simp_all\n\ntext\\<open>\\newpage\\<close>\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/CZH_Elementary_Categories/czh_ecategories/CZH_ECAT_Comma.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5078118642792043, "lm_q2_score": 0.5312093733737563, "lm_q1q2_score": 0.2697544222155151}}
{"text": "(*\n * Copyright 2021, Proofcraft Pty Ltd\n *\n * SPDX-License-Identifier: GPL-2.0-only\n *)\n\n(* Architecture-independent lemmas constraining Kernel_Config definitions *)\n\ntheory Kernel_Config_Lemmas\nimports \"$L4V_ARCH/Kernel_Config\"\nbegin\n\ntext \\<open>\n  seL4's build system allows configuration of some architecture-independent constants, such as the\n  number of domains.\n\n  The long-term goal is to make the proofs resilient in the face of changes of these configuration\n  options. To this end this theory contains properties of these constants, to avoid unfolding\n  their values later in the proofs.\\<close>\n\nlemma numDomains_not_zero:\n  \"numDomains > 0\"\n  unfolding Kernel_Config.numDomains_def\n  by simp\n\nlemma numDomains_machine_word_safe:\n  \"unat (of_nat numDomains :: machine_word) = numDomains\"\n  unfolding Kernel_Config.numDomains_def by simp\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/spec/machine/Kernel_Config_Lemmas.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185351961016, "lm_q2_score": 0.476579651063676, "lm_q1q2_score": 0.2697529159993311}}
{"text": "theory flash88Rev imports flashPub\nbegin\nsection{*Main defintions*}\nlemma NI_FAckVsInv88:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n     have allCases:\"formEval   (neg ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const true )) )  s  \\<or>formEval  ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const true ))  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume b1:\"formEval  (neg ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const true )) )  s\"\nhave \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n    }\n\n    moreover\n                       {assume b1:\"formEval ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const true ))  s\"\n\n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''ShWbMsg_Cmd'') )  ( Const SHWB_FAck ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n    }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_InvVsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_InvAck_1VsInv88:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1_HomeVsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_InvAck_2VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_GetXVsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_Nak1VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_Nak2VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_Nak3VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_PutX1VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv88:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10VsInv88:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10_homeVsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX11VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_GetVsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_Get_Nak1VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_Get_Nak2VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_Get_Nak3VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_Get_Put1VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_Get_Put2VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put3VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_PutVsInv88:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_PutXAcksDoneVsInv88:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_NakVsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Nak_ClearVsInv88:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Nak_HomeVsInv88:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Remote_GetX_NakVsInv88:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_Nak_HomeVsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_PutXVsInv88:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_PutX_HomeVsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Nak1VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Nak2VsInv88:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Put1VsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Put2VsInv88:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutVsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                     have allCases:\"formEval  ( eqn ( IVar ( Para ''InvMarked'' iInv2) )  ( Const true ))  s  \\<or>formEval   (neg ( eqn ( IVar ( Para ''InvMarked'' iInv2) )  ( Const true )) )  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume c1:\"formEval ( eqn ( IVar ( Para ''InvMarked'' iInv2) )  ( Const true ))  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1  c1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n\n    moreover\n                       {assume c1:\"formEval  (neg ( eqn ( IVar ( Para ''InvMarked'' iInv2) )  ( Const true )) )  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1  c1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n   ultimately have \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutXVsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv1))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  )    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_ReplaceVsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_ReplaceHomeVsInv88:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceHomeShrVldVsInv88:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceShrVldVsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_ShWbVsInv88:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_WbVsInv88:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_GetX1VsInv88:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv1))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  )    ( eqn ( IVar ( Para ''CacheState'' iInv2) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_GetX2VsInv88:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv2) )  ( Const CACHE_E ))    ( eqn ( IVar ( Para ''CacheState'' Home) )  ( Const CACHE_S ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX1VsInv88:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX2VsInv88:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX3VsInv88:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX4VsInv88:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_Get_GetVsInv88:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_Get_PutVsInv88:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_PutXVsInv88:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_ReplaceVsInv88:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_GetVsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma PI_Remote_GetXVsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma PI_Remote_PutXVsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_ReplaceVsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma StoreVsInv88:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma StoreHomeVsInv88:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv88  iInv1  iInv2 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash88Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185351961015, "lm_q2_score": 0.476579651063676, "lm_q1q2_score": 0.26975291599933104}}
{"text": "(*\n * Copyright 2016, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the GNU General Public License version 2. Note that NO WARRANTY is provided.\n * See \"LICENSE_GPLv2.txt\" for details.\n *\n * @TAG(NICTA_GPL)\n *)\n\ntheory BufferT\nimports\n  \"BilbyFsConsts.BilbyFs_Shallow_Desugar_Tuples\"\n  \"BilbyFsConsts.BilbyFs_ShallowConsts_Desugar_Tuples\"\n  \"../adt/WordArrayT\"\nbegin\n\n\ndefinition\n  buf_slice :: \"Buffer\\<^sub>T \\<Rightarrow> U32 \\<Rightarrow> U32 \\<Rightarrow> U8 list\"\nwhere\n \"buf_slice buf frm to \\<equiv> slice (unat frm) (unat to) (\\<alpha>wa $ data\\<^sub>f buf)\"\n\ndefinition\n  buf_sub_slice :: \"Buffer\\<^sub>T \\<Rightarrow> U32 \\<Rightarrow> U32 \\<Rightarrow> U8 list \\<Rightarrow> U8 list\"\nwhere\n \"buf_sub_slice buf frm to xs \\<equiv>\n take (length (\\<alpha>wa $ data\\<^sub>f buf)) (take (unat frm) (\\<alpha>wa $ data\\<^sub>f buf) @ \n (take (unat to - unat frm) (xs@replicate (unat to - unat frm) 0)) @\n  drop (max (unat to) (unat frm)) (\\<alpha>wa $ data\\<^sub>f buf))\"\n  \n\nlemma buf_sub_slice_length:\n  \"length (buf_sub_slice buf frm to xs) = length (\\<alpha>wa (data\\<^sub>f buf))\"\n  apply (simp add: buf_sub_slice_def)\n  apply(subst min_def)+\nusing [[linarith_split_limit=20]]\napply clarsimp (* take a while *)\napply safe\napply unat_arith+\ndone\n\ndefinition\n  buf_drop :: \"Buffer\\<^sub>T \\<Rightarrow> U32 \\<Rightarrow> U8 list\"\nwhere\n \"buf_drop buf offs \\<equiv> drop (unat offs) (\\<alpha>wa $ data\\<^sub>f buf)\"\n\ndefinition\n  buf_take :: \"Buffer\\<^sub>T \\<Rightarrow> U32 \\<Rightarrow> U8 list\"\nwhere\n \"buf_take buf offs \\<equiv> take (unat offs) (\\<alpha>wa $ data\\<^sub>f buf)\"\n\ndefinition\n  buf_update_bounded :: \"Buffer\\<^sub>T \\<Rightarrow> U8 list \\<Rightarrow> U8 list\"\nwhere\n \"buf_update_bounded buf buf_updated \\<equiv>\n    take (min (unat $ bound\\<^sub>f buf) (length $ \\<alpha>wa $ data\\<^sub>f buf)) buf_updated @\n    drop (min (unat $ bound\\<^sub>f buf) (length buf_updated)) (\\<alpha>wa $ data\\<^sub>f buf) \"\n\ndefinition\n  buf_memset' :: \"Buffer\\<^sub>T \\<Rightarrow> U32 \\<Rightarrow> U32 \\<Rightarrow> U8 \\<Rightarrow> U8 list\"\nwhere\n \"buf_memset' buf offs len v \\<equiv>\n   buf_update_bounded buf $ buf_take buf offs @ replicate (min (unat len) (unat (bound\\<^sub>f buf) - unat offs)) v @ buf_drop buf (offs+len)\"\n\n\nlemma buf_update_bounded_length:\n \"length (buf_update_bounded buf upd) = length (\\<alpha>wa $ data\\<^sub>f buf)\"\n  by (simp add: buf_bound_def buf_update_bounded_def buf_length_def)\n\nlemmas buf_simps = buf_take_def buf_drop_def buf_slice_def \n    buf_bound_def buf_update_bounded_def buf_length_def\n    buf_memset'_def buf_update_bounded_length\n    slice_def\n\nlemma drop_take_drop:\n  \"n \\<le> m \\<Longrightarrow> drop n (take m xs) @ drop m xs = drop n xs\"\n  by (metis add.commute atd_lem drop_drop drop_take le_add_diff_inverse)\n\nlemma buf_memset_bound_assm_eq:\n  \"unat (bound\\<^sub>f buf) \\<le>  length (\\<alpha>wa (data\\<^sub>f buf)) \\<Longrightarrow>\n  offs \\<le> offs + len \\<Longrightarrow>\n  unat offs \\<le> unat (bound\\<^sub>f buf) \\<Longrightarrow>\n  offs + len \\<le> bound\\<^sub>f buf \\<Longrightarrow>\n  wordarray_set (data\\<^sub>f buf, offs, len, v) = WordArrayT.make (buf_memset' buf offs len v)\"\n unfolding buf_memset_def[unfolded tuple_simps sanitizers]\n   apply (simp add: Let_def wordarray_set_ret buf_simps min_absorb1)\n   apply (rule arg_cong[where f=WordArrayT.make])\n   apply (subgoal_tac \"(unat (bound\\<^sub>f buf) - unat offs) \\<ge> (unat len)\")\n    prefer 2\n    apply unat_arith\n   apply (simp add: min_absorb1 )\n   apply (subgoal_tac \"(unat (bound\\<^sub>f buf)) \\<le>\n            (unat offs + (unat len + (length (\\<alpha>wa (data\\<^sub>f buf)) - unat (offs + len))))\")\n   prefer 2\n   apply (unat_arith)\n  apply (simp add: min_absorb1 take_drop)\n  apply (subgoal_tac \" (unat offs + unat len) =  unat (offs + len)\")\n   apply (simp add: drop_take_drop)\n  apply unat_arith\n done\n\nlemma take_prefix_length:\n \"take n xs = take n ys \\<Longrightarrow>\n   n \\<le> length xs \\<Longrightarrow> n \\<le> length ys\"\nby (metis length_take min.absorb_iff2)\n\nlemma buf_bounded_update_bounded_prefix:\n \"unat (bound\\<^sub>f buf) \\<le> length (\\<alpha>wa (data\\<^sub>f buf)) \\<Longrightarrow>\n take (unat (bound\\<^sub>f buf)) xs = take (unat (bound\\<^sub>f buf)) ys \\<Longrightarrow>\n  buf_update_bounded buf xs = buf_update_bounded buf ys\"\n apply (simp add: buf_simps)\n apply (case_tac \"(unat (bound\\<^sub>f buf)) \\<le> (length xs)\")\n  apply (frule (1) take_prefix_length)\n  apply (simp add: min_absorb1)\n apply simp\ndone\n\nlemma buf_memset_bound:\n \"unat (bound\\<^sub>f buf) \\<le> length (\\<alpha>wa (data\\<^sub>f buf)) \\<Longrightarrow>\n    offs \\<le> offs + len \\<Longrightarrow>\n    offs < bound\\<^sub>f buf \\<Longrightarrow>\n    \\<not> offs + len < bound\\<^sub>f buf \\<Longrightarrow>\n    buf_memset' buf offs (bound\\<^sub>f buf - offs) v = buf_memset' buf offs len v\"\n  apply (simp add: buf_memset'_def)\n  apply (subgoal_tac \"unat (bound\\<^sub>f buf - offs) = unat (bound\\<^sub>f buf) - unat offs\")\n   apply (simp add: min_absorb2)\n   apply (subgoal_tac \"(unat len) \\<ge> (unat (bound\\<^sub>f buf) - unat offs)\")\n    apply simp\n    apply (rule buf_bounded_update_bounded_prefix)\n     apply ((simp add: buf_simps)+)[2]\n   apply unat_arith\n  apply unat_arith\n  done\n\nlemma take_n_m_double_append:\n \"n \\<le> m \\<Longrightarrow> n \\<le> length xs \\<Longrightarrow>\n    take n (take m xs @ ys ) = take n xs\"\n by simp\n\nlemma buf_memset_offs_bound:\n \"unat (bound\\<^sub>f buf) \\<le> length (\\<alpha>wa (data\\<^sub>f buf)) \\<Longrightarrow>\n   offs \\<le> offs + len \\<Longrightarrow>\n   \\<not> offs < bound\\<^sub>f buf \\<Longrightarrow>\n   buf_memset' buf (bound\\<^sub>f buf) len' v =\n   buf_memset' buf offs len v\"\n  apply (simp add: buf_memset'_def)\n  apply (rule buf_bounded_update_bounded_prefix)\n   apply simp\n  apply (simp only: buf_take_def )\n  apply (subst take_n_m_double_append)\n     apply simp\n    apply unat_arith\n   apply unat_arith\n  apply simp\n done\n\n\nlemma buf_memset_eq:\n  \"unat (bound\\<^sub>f buf) \\<le>  length (\\<alpha>wa (data\\<^sub>f buf)) \\<Longrightarrow>\n  offs \\<le> offs + len \\<Longrightarrow>\n  buf_memset (buf, offs, len, v) = buf\\<lparr>data\\<^sub>f:=WordArrayT.make (buf_memset' buf offs len v)\\<rparr>\"\n unfolding buf_memset_def[unfolded tuple_simps sanitizers]\n  apply (simp only: Let_def prod.case_eq_if prod.sel take\\<^sub>c\\<^sub>o\\<^sub>g\\<^sub>e\\<^sub>n\\<^sub>t_def)\n  apply (subst buf_memset_bound_assm_eq)\n      apply simp\n     apply ((case_tac \" offs < bound\\<^sub>f buf\", ((simp, unat_arith)+)[2])+)[3]\n  apply (rule arg_cong[where f=\"\\<lambda>v. data\\<^sub>f_update v buf\"])\n  apply (rule ext)\n  apply (rule arg_cong[where f=WordArrayT.make])\n  apply (case_tac \"offs < bound\\<^sub>f buf\")\n   apply (simp add: buf_memset_bound)\n  apply (simp add: buf_memset_offs_bound)\n done\n\nlemma buf_memset_length_eq:\n  \"unat (bound\\<^sub>f buf) \\<le> length (\\<alpha>wa (data\\<^sub>f buf)) \\<Longrightarrow>\n offs \\<le> offs + len \\<Longrightarrow>\nbuf_length (buf_memset (buf, offs, len, v)) = buf_length buf\"\n by (simp add: buf_length_def wordarray_length_ofnat[OF wordarray_length_ret] \n      buf_memset_eq wordarray_make buf_update_bounded_length buf_memset'_def)\n\nlemma buf_take_buf_slice_adjacent:\n \"st \\<le>  end \\<Longrightarrow> buf_take b st @ buf_slice b st end = buf_take b end\"\nby (simp add: buf_simps word_le_nat_alt) \n  (metis (no_types, lifting) append_take_drop_id min_def take_take)\n\nlemma length_buf_memset:\n  \"unat (bound\\<^sub>f wbuf) \\<le>  length (\\<alpha>wa (data\\<^sub>f wbuf)) \\<Longrightarrow>\n n < n + m \\<Longrightarrow>\nlength (\\<alpha>wa (data\\<^sub>f (buf_memset (wbuf, n, m, v)))) = length (\\<alpha>wa (data\\<^sub>f wbuf))\"\n by (simp add: buf_memset_eq buf_memset'_def wordarray_make buf_update_bounded_length)\n\nlemma buf_slice_n_n:\n  \"buf_slice buf n n = []\"\n  by (simp add: buf_simps)\n\nlemma buf_slice_0_eq_buf_take:\n \"buf_slice buf 0 n = buf_take buf n\"\n by (simp add: buf_simps)\n\n\nlemma buf_slice_out_of_buf_memset:\n \"frm \\<le> to \\<Longrightarrow> to \\<le> st \\<Longrightarrow> st \\<le> st + len \\<Longrightarrow> st \\<le> bound\\<^sub>f b \\<Longrightarrow> unat (bound\\<^sub>f b) = length (\\<alpha>wa (data\\<^sub>f b)) \\<Longrightarrow>\n  buf_slice (buf_memset (b, st, len, v)) frm to = buf_slice b frm to\"\n  apply (subst buf_memset_eq)\n   apply simp+\n  apply (simp add:  buf_simps wordarray_make min_absorb1 min_absorb2)\n  apply (simp only: unat_arith_simps)\n  apply (simp add: min_absorb1 min_absorb2)\n done\n\nlemma buf_update_boundedI:\n \"unat (buf_bound wbuf) \\<le> length (\\<alpha>wa (data\\<^sub>f wbuf)) \\<Longrightarrow>\n  length xs = length (\\<alpha>wa (data\\<^sub>f wbuf)) \\<Longrightarrow>\n  drop (unat (bound\\<^sub>f wbuf)) (\\<alpha>wa (data\\<^sub>f wbuf)) = drop (unat (bound\\<^sub>f wbuf)) xs \\<Longrightarrow>\n  P xs \\<Longrightarrow>\n  P (buf_update_bounded wbuf xs)\"\nby (simp add: buf_bound_def buf_update_bounded_def min_absorb1)\n\nlemma take_n_buf_sub_slice_n:\n \"unat n \\<le> length (\\<alpha>wa (data\\<^sub>f b)) \\<Longrightarrow> take (unat n) (buf_sub_slice b n t xs) = take (unat n) (\\<alpha>wa (data\\<^sub>f b))\"\n by (simp add: buf_sub_slice_def min_absorb1)\n\n lemma take_n_buf_sub_slice_m:\n \"unat m \\<le> length (\\<alpha>wa (data\\<^sub>f b)) \\<Longrightarrow> n \\<le> m \\<Longrightarrow>  take (unat n) (buf_sub_slice b m t xs) = take (unat n) (\\<alpha>wa (data\\<^sub>f b))\"\n by (simp add: buf_sub_slice_def min_absorb1 word_le_nat_alt) \n \n\nlemma slice_buf_sub_slice:\n \"frm \\<le> mid \\<Longrightarrow> mid \\<le> to \\<Longrightarrow> unat to \\<le> length (\\<alpha>wa (data\\<^sub>f b)) \\<Longrightarrow>\n  unat (to - mid) = length xs \\<Longrightarrow>\n slice (unat frm) (unat to) (buf_sub_slice b mid to xs) = buf_slice b frm mid @ take (unat to - unat mid) xs\"\n  apply (simp add: buf_simps buf_sub_slice_def min_absorb1 min_absorb2)\n  apply (subgoal_tac \"unat mid \\<le> length (\\<alpha>wa (data\\<^sub>f b))\")\n   apply (subgoal_tac \"unat frm \\<le> length (\\<alpha>wa (data\\<^sub>f b))\")\n    apply (subgoal_tac \"unat frm \\<le> unat mid\")\n  apply (simp add: buf_simps buf_sub_slice_def min_absorb1 min_absorb2 word_le_nat_alt)\n  apply unat_arith+\n done\n\nend\n", "meta": {"author": "au-ts", "repo": "cogent", "sha": "a1464313bbd1bbfaa5c4e58ab14f669c6d2436a2", "save_path": "github-repos/isabelle/au-ts-cogent", "path": "github-repos/isabelle/au-ts-cogent/cogent-a1464313bbd1bbfaa5c4e58ab14f669c6d2436a2/impl/fs/bilby/proof/adt/BufferT.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6442251064863697, "lm_q2_score": 0.4186969093556867, "lm_q1q2_score": 0.26973506101518113}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory fncall\nimports \"../CTranslation\"\nbegin\n\ndeclare sep_conj_ac [simp add]\n\nprimrec\n  fac :: \"nat \\<Rightarrow> nat\"\nwhere\n  \"fac 0 = 1\"\n| \"fac (Suc n) = (Suc n) * fac n\"\n\nML {*\n\nval ast = IsarInstall.get_Csyntax @{theory} \"fncall.c\"\n\n*}\n\ninstall_C_file \"fncall.c\"\n\ncontext fncall\nbegin\n\n\nthm \"\\<Gamma>_def\"\nthm has_bogus_spec_'proc_def\nthm has_bogus_spec_impl\nthm f_impl\nthm g_impl\nthm h_impl\nthm i_impl\nthm calls_bogus_impl\nthm f_body_def\nthm g_body_def\nthm fact_body_def\n\nthm fact_'proc_def\n\nthm has_bogus_spec_modifies\nthm g_modifies\nthm f_modifies\nthm fact_modifies\n\nterm \"f_body\"\nterm \"\\<Gamma>\"\nterm \"fact_body\"\nterm \"f_'proc\"\n\nend\n\nprint_locale fncall_global_addresses\n\nprint_locale g_modifies\nthm g_modifies_def\n\nprint_locale f_spec\nthm f_spec_def\n\nlemma (in g_modifies)\n  shows \"\\<Gamma> \\<turnstile> \\<lbrace> \\<acute>t_hrs = t \\<rbrace> \\<acute>ret__int :== PROC g() \\<lbrace> \\<acute>t_hrs = t \\<rbrace>\"\napply (hoare_rule HoarePartial.ProcRec1)\napply (vcg spec=modifies)\ndone\n\n\nlemma (in fncall_global_addresses) f_impl_result:\n  \"\\<Gamma> f_'proc = Some f_body\"\n  apply (rule f_impl)\n  done\n\nlemma (in fncall_global_addresses) g_spec:\n  shows\n  \"\\<Gamma> \\<turnstile> \\<lbrace> True \\<rbrace> \\<acute>ret__int :== PROC g() \\<lbrace> \\<acute>ret__int = 257 \\<rbrace>\"\n  apply vcg\n  done\n\nlemma (in fncall_global_addresses) foo:\n  shows\n   \"\\<Gamma> \\<turnstile> \\<lbrace> True \\<rbrace> \\<acute>ret__int :== PROC f(n) \\<lbrace> \\<acute>ret__int = 1 \\<rbrace>\"\napply vcg\napply (simp )\ndone\n\nlemma (in f_spec) foo :\nshows\n  \"\\<Gamma> \\<turnstile> \\<lbrace> True \\<rbrace> \\<acute>ret__int :== CALL f(\\<acute>n) \\<lbrace> \\<acute>ret__int = 1 \\<rbrace>\"\n\napply vcg\ndone\n\nlemma (in fncall_global_addresses) bar:\nshows \"\\<Gamma> \\<turnstile> \\<lbrace> 1\\<le> \\<acute>n & \\<acute>n \\<le> 12 \\<rbrace> \\<acute>ret__int :== CALL fact(\\<acute>n) \\<lbrace> \\<acute>ret__int = of_nat (fac (unat \\<acute>n)) \\<rbrace>\"\napply vcg\napply unat_arith\noops\n\nlemma (in fncall_global_addresses) baz:\nshows \"\\<Gamma> \\<turnstile>\\<^bsub>/UNIV\\<^esub> \\<lbrace> \\<acute>t_hrs = t \\<rbrace> \\<acute>ret__int :== PROC i() \\<lbrace> \\<acute>t_hrs = t \\<rbrace>\"\napply (hoare_rule HoarePartial.ProcRec1)\napply (vcg spec=modifies)\ndone\n\nlocale ih = i_modifies + h_modifies\nlemma (in ih) qux:\nshows \"\\<forall>t. \\<Gamma> \\<turnstile> \\<lbrace>\\<acute>t_hrs = t\\<rbrace> \\<acute>ret__int :== CALL i() \\<lbrace> t = \\<acute>t_hrs \\<rbrace>\"\napply vcg\noops\n\nlocale ff = f_spec + f_modifies\n(* this lemma is bogus, because f does actually modify the globals *)\nlemma (in ff) bogus1:\nshows \"\\<forall>t. \\<Gamma> \\<turnstile> \\<lbrace> \\<acute>t_hrs = t \\<rbrace> \\<acute>ret__int :== CALL f(\\<acute>n) \\<lbrace> t = \\<acute>t_hrs \\<rbrace>\"\napply vcg\napply simp\ndone\n\nlemma (in has_bogus_spec_spec) bogus2:\nshows \"\\<Gamma> \\<turnstile> \\<lbrace> \\<acute>n = 42 \\<rbrace> \\<acute>ret__int :== CALL has_bogus_spec() \\<lbrace> \\<acute>ret__int = 4 \\<rbrace>\"\napply vcg\ndone\n\nlemma (in fncall_global_addresses) toldyou:\nshows \"\\<Gamma> \\<turnstile> \\<lbrace> \\<acute>n = 42 \\<rbrace> \\<acute>ret__int :== CALL has_bogus_spec() \\<lbrace> \\<acute>ret__int = 3 \\<rbrace>\"\napply vcg\ndone\n\nlemma (in has_bogus_spec_spec) bogus3:\nshows \"\\<Gamma> \\<turnstile> \\<lbrace> \\<acute>n = 42 \\<rbrace> \\<acute>ret__int :== CALL calls_bogus() \\<lbrace> \\<acute>ret__int = 4 \\<rbrace>\"\napply vcg\ndone\n\nend\n", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/c-parser/testfiles/fncall.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.2696394000253643}}
{"text": "theory Typeclass_Hierarchy\nimports Setup\nbegin\n\nsection \\<open>Introduction\\<close>\n\ntext \\<open>\n  The {Isabelle/HOL} type-class hierarchy entered the stage\n  in a quite ancient era -- first related \\<^emph>\\<open>NEWS\\<close> entries date\n  back to release {Isabelle99-1}.  Since then, there have been\n  ongoing modifications and additions, leading to ({Isabelle2016})\n  more than 180 type-classes.  This sheer complexity makes access\n  and understanding of that type-class hierarchy difficult and\n  involved, let alone maintenance.\n\n  The purpose of this primer is to shed some light on this,\n  not only on the mere ingredients, but also on the design\n  principles which have evolved and proven useful over time.\n\\<close>\n\nsection \\<open>Foundations\\<close>\n\nsubsection \\<open>Locales and type classes\\<close>\n\ntext \\<open>\n  Some familiarity with the Isabelle module system is assumed:\n  defining locales and type-classes, interpreting locales and\n  instantiating type-classes, adding relationships between\n  locales (@{command sublocale}) and type-classes\n  (@{command subclass}).  Handy introductions are the\n  respective tutorials @{cite \"isabelle-locale\"}\n  @{cite \"isabelle-classes\"}.\n\\<close>\n\nsubsection \\<open>Strengths and restrictions of type classes\\<close>\n\ntext \\<open>\n  The primary motivation for using type classes in {Isabelle/HOL}\n  always have been numerical types, which form an inclusion chain:\n  \n  \\begin{center}\n    \\<^typ>\\<open>nat\\<close> \\<open>\\<sqsubset>\\<close> \\<^typ>\\<open>int\\<close> \\<open>\\<sqsubset>\\<close> \\<^typ>\\<open>rat\\<close>\n      \\<open>\\<sqsubset>\\<close> \\<^typ>\\<open>real\\<close> \\<open>\\<sqsubset>\\<close> \\<^typ>\\<open>complex\\<close>\n  \\end{center}\n\n  \\noindent The inclusion \\<open>\\<sqsubset>\\<close> means that any value of the numerical\n  type to the left hand side mathematically can be transferred\n  to the numerical type on the right hand side.\n\n  How to accomplish this given the quite restrictive type system\n  of {Isabelle/HOL}?  Paulson @{cite \"paulson-numerical\"} explains\n  that each numerical type has some characteristic properties\n  which define an characteristic algebraic structure;  \\<open>\\<sqsubset>\\<close>\n  then corresponds to specialization of the corresponding\n  characteristic algebraic structures.  These algebraic structures\n  are expressed using algebraic type classes and embeddings\n  of numerical types into them:\n\n  \\begin{center}\\begin{tabular}{lccc}\n    \\<^term>\\<open>of_nat\\<close> \\<open>::\\<close>  & \\<^typ>\\<open>nat\\<close>  & \\<open>\\<Rightarrow>\\<close> & @{typ [source] \"'a::semiring_1\"} \\\\\n                                 & \\<open>\\<sqinter>\\<close>   &            & \\<open>\\<up>\\<close> \\\\\n    \\<^term>\\<open>of_int\\<close> \\<open>::\\<close>  & \\<^typ>\\<open>int\\<close>  & \\<open>\\<Rightarrow>\\<close> & @{typ [source] \"'a::ring_1\"} \\\\\n                                 & \\<open>\\<sqinter>\\<close>   &            & \\<open>\\<up>\\<close> \\\\\n    \\<^term>\\<open>of_rat\\<close> \\<open>::\\<close>  & \\<^typ>\\<open>rat\\<close>  & \\<open>\\<Rightarrow>\\<close> & @{typ [source] \"'a::field_char_0\"} \\\\\n                                 & \\<open>\\<sqinter>\\<close>   &            & \\<open>\\<up>\\<close> \\\\\n    \\<^term>\\<open>of_real\\<close> \\<open>::\\<close> & \\<^typ>\\<open>real\\<close> & \\<open>\\<Rightarrow>\\<close> & @{typ [source] \"'a::real_algebra_1\"} \\\\\n                                 & \\<open>\\<sqinter>\\<close> \\\\\n                                 & \\<^typ>\\<open>complex\\<close>\n  \\end{tabular}\\end{center}\n\n  \\noindent \\<open>d \\<leftarrow> c\\<close> means that \\<open>c\\<close> is subclass of \\<open>d\\<close>.\n  Hence each characteristic embedding \\<open>of_num\\<close> can transform\n  any value of type \\<open>num\\<close> to any numerical type further\n  up in the inclusion chain.\n\n  This canonical example exhibits key strengths of type classes:\n\n    \\<^item> Sharing of operations and facts among different\n      types, hence also sharing of notation and names: there\n      is only one plus operation using infix syntax \\<open>+\\<close>,\n      only one zero written \\<open>0\\<close>, and neutrality\n      (@{thm (frugal_sorts) add_0_left [all, no_vars]} and\n      @{thm (frugal_sorts) add_0_right [all, no_vars]})\n      is referred to\n      uniformly by names @{fact add_0_left} and @{fact add_0_right}.\n\n    \\<^item> Proof tool setups are shared implicitly:\n      @{fact add_0} and @{fact add_0_right} are simplification\n      rules by default.\n\n    \\<^item> Hence existing proofs about particular numerical\n      types are often easy to generalize to algebraic structures,\n      given that they do not depend on specific properties of\n      those numerical types.\n\n  Considerable restrictions include:\n\n    \\<^item> Type class operations are restricted to one\n      type parameter; this is insufficient e.g. for expressing\n      a unified power operation adequately (see \\secref{sec:power}).\n\n    \\<^item> Parameters are fixed over the whole type class\n      hierarchy and cannot be refined in specific situations:\n      think of integral domains with a predicate \\<^term>\\<open>is_unit\\<close>;\n      for natural numbers, this degenerates to the much simpler\n      @{term [source] \"HOL.equal (1::nat)\"} but facts\n      refer to \\<^term>\\<open>is_unit\\<close> nonetheless.\n\n    \\<^item> Type classes are not apt for meta-theory.  There\n      is no practically usable way to express that the units\n      of an integral domain form a multiplicative group using\n      type classes.  But see session \\<open>HOL-Algebra\\<close>\n      which provides locales with an explicit carrier.\n\\<close>\n\n\nsubsection \\<open>Navigating the hierarchy\\<close>\n\ntext \\<open>\n  An indispensable tool to inspect the class hierarchy is\n  @{command class_deps} which displays the graph of classes,\n  optionally showing the logical content for each class also.\n  Optional parameters restrict the graph to a particular segment\n  which is useful to get a graspable view.  See\n  the Isar reference manual @{cite \"isabelle-isar-ref\"} for details.\n\\<close>\n\n\nsection \\<open>The hierarchy\\<close>\n\nsubsection \\<open>Syntactic type classes \\label{sec:syntactic-type-class}\\<close>\n\ntext \\<open>\n  At the top of the hierarchy there are a couple of syntactic type\n  classes, ie. classes with operations but with no axioms,\n  most notably:\n\n    \\<^item> @{command class} \\<^class>\\<open>plus\\<close> with @{term [source] \"(a::'a::plus) + b\"}\n\n    \\<^item> @{command class} \\<^class>\\<open>zero\\<close> with @{term [source] \"0::'a::zero\"}\n\n    \\<^item> @{command class} \\<^class>\\<open>times\\<close> with @{term [source] \"(a::'a::times) * b\"}\n\n    \\<^item> @{command class} \\<^class>\\<open>one\\<close> with @{term [source] \"1::'a::one\"}\n\n  \\noindent Before the introduction of the @{command class} statement in\n  Isabelle @{cite \"Haftmann-Wenzel:2006:classes\"} it was impossible\n  to define operations with associated axioms in the same class,\n  hence there were always pairs of syntactic and logical type\n  classes.  This restriction is lifted nowadays, but there are\n  still reasons to maintain syntactic type classes:\n\n    \\<^item> Syntactic type classes allow generic notation to be used\n      regardless of a particular logical interpretation; e.g.\n      although multiplication \\<open>*\\<close> is usually associative,\n      there are examples where it is not (e.g. octonions), and\n      leaving \\<open>*\\<close> without axioms allows to re-use this\n      syntax by means of type class instantiation also for such\n      exotic examples.\n\n    \\<^item> Type classes might share operations but not necessarily\n      axioms on them, e.g. \\<^term>\\<open>gcd\\<close> (see \\secref{sec:gcd}).\n      Hence their common base is a syntactic type class.\n\n  \\noindent However syntactic type classes should only be used with striking\n  cause.  Otherwise there is risk for confusion if the notation\n  suggests properties which do not hold without particular\n  constraints.  This can be illustrated using numerals\n  (see \\secref{sec:numerals}):  @{lemma \"2 + 2 = 4\" by simp} is\n  provable without further ado, and this also meets the typical\n  expectation towards a numeral notation;  in more ancient releases\n  numerals were purely syntactic and \\<^prop>\\<open>2 + 2 = 4\\<close> was\n  not provable without particular type constraints.\n\\<close>\n\n\nsubsection \\<open>Additive and multiplicative semigroups and monoids\\<close>\n\ntext \\<open>\n  In common literature, notation for semigroups and monoids\n  is either multiplicative \\<open>(*, 1)\\<close> or additive\n  \\<open>(+, 0)\\<close> with underlying properties isomorphic.\n  In {Isabelle/HOL}, this is accomplished using the following\n  abstract setup:\n\n    \\<^item> A \\<^locale>\\<open>semigroup\\<close> introduces an abstract binary\n      associative operation.\n\n    \\<^item> A \\<^locale>\\<open>monoid\\<close> is an extension of \\<^locale>\\<open>semigroup\\<close>\n      with a neutral element.\n\n    \\<^item> Both \\<^locale>\\<open>semigroup\\<close> and \\<^locale>\\<open>monoid\\<close> provide\n      dedicated syntax for their operations \\<open>(\\<^bold>*, \\<^bold>1)\\<close>.\n      This syntax is not visible on the global theory level\n      but only for abstract reasoning inside the respective\n      locale.\n\n    \\<^item> Concrete global syntax is added building on existing\n      syntactic type classes \\secref{sec:syntactic-type-class}\n      using the following classes:\n\n        \\<^item> @{command class} \\<^class>\\<open>semigroup_mult\\<close> = \\<^class>\\<open>times\\<close>\n\n        \\<^item> @{command class} \\<^class>\\<open>monoid_mult\\<close> = \\<^class>\\<open>one\\<close> + \\<^class>\\<open>semigroup_mult\\<close>\n\n        \\<^item> @{command class} \\<^class>\\<open>semigroup_add\\<close> = \\<^class>\\<open>plus\\<close>\n\n        \\<^item> @{command class} \\<^class>\\<open>monoid_add\\<close> = \\<^class>\\<open>zero\\<close> + \\<^class>\\<open>semigroup_add\\<close>\n\n      Locales \\<^locale>\\<open>semigroup\\<close> and \\<^locale>\\<open>monoid\\<close> are\n      interpreted (using @{command sublocale}) into their\n      corresponding type classes, with prefixes \\<open>add\\<close>\n      and \\<open>mult\\<close>; hence facts derived in \\<^locale>\\<open>semigroup\\<close>\n      and \\<^locale>\\<open>monoid\\<close> are propagated simultaneously to\n      \\<^emph>\\<open>both\\<close> using a consistent naming policy, ie.\n\n        \\<^item> @{fact semigroup.assoc}: @{thm (frugal_sorts) semigroup.assoc [all, no_vars]}\n\n        \\<^item> @{fact mult.assoc}: @{thm (frugal_sorts) mult.assoc [all, no_vars]}\n\n        \\<^item> @{fact add.assoc}: @{thm (frugal_sorts) add.assoc [all, no_vars]}\n\n        \\<^item> @{fact monoid.right_neutral}: @{thm (frugal_sorts) monoid.right_neutral [all, no_vars]}\n\n        \\<^item> @{fact mult.right_neutral}: @{thm (frugal_sorts) mult.right_neutral [all, no_vars]}\n\n        \\<^item> @{fact add.right_neutral}: @{thm (frugal_sorts) add.right_neutral [all, no_vars]}\n\n    \\<^item> Note that the syntax in \\<^locale>\\<open>semigroup\\<close> and \\<^locale>\\<open>monoid\\<close>\n      is bold; this avoids clashes when writing properties\n      inside one of these locales in presence of that global\n      concrete type class syntax.\n\n  \\noindent That hierarchy extends in a straightforward manner\n  to abelian semigroups and commutative monoids\\footnote{The\n  designation \\<^emph>\\<open>abelian\\<close> is quite standard concerning\n  (semi)groups, but not for monoids}:\n\n    \\<^item> Locales \\<^locale>\\<open>abel_semigroup\\<close> and \\<^locale>\\<open>comm_monoid\\<close>\n      add commutativity as property.\n\n    \\<^item> Concrete syntax emerges through\n\n        \\<^item> @{command class} \\<^class>\\<open>ab_semigroup_add\\<close> = \\<^class>\\<open>semigroup_add\\<close>\n\n        \\<^item> @{command class} \\<^class>\\<open>ab_semigroup_mult\\<close> = \\<^class>\\<open>semigroup_mult\\<close>\n\n        \\<^item> @{command class} \\<^class>\\<open>comm_monoid_add\\<close> = \\<^class>\\<open>zero\\<close> + \\<^class>\\<open>ab_semigroup_add\\<close>\n\n        \\<^item> @{command class} \\<^class>\\<open>comm_monoid_mult\\<close> = \\<^class>\\<open>one\\<close> + \\<^class>\\<open>ab_semigroup_mult\\<close>\n  \n      and corresponding interpretation of the locales above, yielding\n\n        \\<^item> @{fact abel_semigroup.commute}: @{thm (frugal_sorts) abel_semigroup.commute [all, no_vars]}\n\n        \\<^item> @{fact mult.commute}: @{thm (frugal_sorts) mult.commute [all, no_vars]}\n\n        \\<^item> @{fact add.commute}: @{thm (frugal_sorts) add.commute [all, no_vars]}\n\\<close>\n\nparagraph \\<open>Named collection of theorems\\<close>\n\ntext \\<open>\n  Locale interpretation interacts smoothly with named collections of\n  theorems as introduced by command @{command named_theorems}.  In our\n  example, rules concerning associativity and commutativity are no\n  simplification rules by default since they desired orientation may\n  vary depending on the situation.  However, there is a collection\n  @{fact ac_simps} where facts @{fact abel_semigroup.assoc},\n  @{fact abel_semigroup.commute} and @{fact abel_semigroup.left_commute}\n  are declared as members.  Due to interpretation, also\n  @{fact mult.assoc}, @{fact mult.commute} and @{fact mult.left_commute}\n  are also members of @{fact ac_simps}, as any corresponding facts\n  stemming from interpretation of \\<^locale>\\<open>abel_semigroup\\<close>.\n  Hence adding @{fact ac_simps} to the simplification rules for\n  a single method call uses all associativity and commutativity\n  rules known by means of interpretation.\n\\<close>\n\n\nsubsection \\<open>Additive and multiplicative groups\\<close>\n\ntext \\<open>\n  The hierarchy for inverse group operations takes into account\n  that there are weaker algebraic structures with only a partially\n  inverse operation.  E. g. the natural numbers have bounded\n  subtraction \\<^term>\\<open>m - (n::nat)\\<close> which is only an inverse\n  operation if \\<^term>\\<open>m \\<ge> (n::nat)\\<close>;  unary minus \\<open>-\\<close>\n  is pointless on the natural numbers.\n\n  Hence for both additive and multiplicative notation there\n  are syntactic classes for inverse operations, both unary\n  and binary:\n\n    \\<^item> @{command class} \\<^class>\\<open>minus\\<close> with @{term [source] \"(a::'a::minus) - b\"}\n\n    \\<^item> @{command class} \\<^class>\\<open>uminus\\<close> with @{term [source] \"- a::'a::uminus\"}\n\n    \\<^item> @{command class} \\<^class>\\<open>divide\\<close> with @{term [source] \"(a::'a::divide) div b\"}\n\n    \\<^item> @{command class} \\<^class>\\<open>inverse\\<close> = \\<^class>\\<open>divide\\<close> with @{term [source] \"inverse a::'a::inverse\"}\n        \\\\ and @{term [source] \"(a::'a::inverse) / b\"}\n\n  \\noindent Here \\<^class>\\<open>inverse\\<close> specializes the ``partial'' syntax\n  @{term [source] \"a div b\"} to the more specific\n  @{term [source] \"a / b\"}. \n\n  Semantic properties are added by\n\n    \\<^item> @{command class} \\<^class>\\<open>cancel_ab_semigroup_add\\<close> = \\<^class>\\<open>ab_semigroup_add\\<close> + \\<^class>\\<open>minus\\<close>\n\n    \\<^item> @{command class} \\<^class>\\<open>cancel_comm_monoid_add\\<close> = \\<^class>\\<open>cancel_ab_semigroup_add\\<close> + \\<^class>\\<open>comm_monoid_add\\<close>\n\n  \\noindent which specify a minimal binary partially inverse operation as\n\n    \\<^item> @{fact add_diff_cancel_left'}: @{thm (frugal_sorts) add_diff_cancel_left' [all, no_vars]}\n\n    \\<^item> @{fact diff_diff_add}: @{thm (frugal_sorts) diff_diff_add [all, no_vars]}\n\n  \\noindent which in turn allow to derive facts like\n\n    \\<^item> @{fact add_left_imp_eq}: @{thm (frugal_sorts) add_left_imp_eq [all, no_vars]}\n\n  \\noindent The total inverse operation is established as follows:\n\n    \\<^item> Locale \\<^locale>\\<open>group\\<close> extends the abstract hierarchy with\n      the inverse operation.\n\n    \\<^item> The concrete additive inverse operation emerges through\n\n      \\<^item> @{command class} \\<^class>\\<open>group_add\\<close> = \\<^class>\\<open>minus\\<close> + \\<^class>\\<open>uminus\\<close> + \\<^class>\\<open>monoid_add\\<close> (in \\<^theory>\\<open>HOL.Groups\\<close>) \\\\\n\n      \\<^item> @{command class} \\<^class>\\<open>ab_group_add\\<close> = \\<^class>\\<open>minus\\<close> + \\<^class>\\<open>uminus\\<close> + \\<^class>\\<open>comm_monoid_add\\<close> (in \\<^theory>\\<open>HOL.Groups\\<close>)\n\n      and corresponding interpretation of locale \\<^locale>\\<open>group\\<close>, yielding e.g.\n\n      \\<^item> @{fact group.left_inverse}: @{thm (frugal_sorts) group.left_inverse [all, no_vars]}\n\n      \\<^item> @{fact add.left_inverse}: @{thm (frugal_sorts) add.left_inverse [all, no_vars]}\n\n  \\noindent There is no multiplicative counterpart.  Why?  In rings,\n  the multiplicative group excludes the zero element, hence\n  the inverse operation is not total.  See further \\secref{sec:rings}.\n\\<close>\n\nparagraph \\<open>Mitigating against redundancy by default simplification rules\\<close>\n\ntext \\<open>\n  Inverse operations imposes some redundancy on the type class\n  hierarchy: in a group with a total inverse operation, the\n  unary operation is simpler and more primitive than the binary\n  one; but we cannot eliminate the binary one in favour of\n  a mere syntactic abbreviation since the binary one is vital\n  to express a partial inverse operation.\n\n  This is mitigated by providing suitable default simplification\n  rules: expression involving the unary inverse operation are\n  simplified to binary inverse operation whenever appropriate.\n  The rationale is that simplification is a central device in\n  explorative proving, where proof obligation remaining after certain\n  default proof steps including simplification are inspected\n  to get an idea what is missing to finish a proof.  When\n  preferable normal forms are encoded into\n  default simplification rules, proof obligations after simplification\n  are normalized and hence more proof-friendly.\n\\<close>\n\nend\n", "meta": {"author": "m-fleury", "repo": "isabelle-emacs", "sha": "756c662195e138a1941d22d4dd7ff759cbf6b6b9", "save_path": "github-repos/isabelle/m-fleury-isabelle-emacs", "path": "github-repos/isabelle/m-fleury-isabelle-emacs/isabelle-emacs-756c662195e138a1941d22d4dd7ff759cbf6b6b9/src/Doc/Typeclass_Hierarchy/Typeclass_Hierarchy.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.2696394000253643}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\ntheory Datatype_Schematic\n\nimports\n  \"../ml-helpers/MLUtils\"\n  \"../ml-helpers/TermPatternAntiquote\"\nbegin\n\ntext \\<open>\n  Introduces a method for improving unification outcomes for schematics with\n  datatype expressions as parameters.\n\n  There are two variants:\n    1. In cases where a schematic is applied to a constant like @{term True},\n       we wrap the constant to avoid some undesirable unification candidates.\n\n    2. In cases where a schematic is applied to a constructor expression like\n       @{term \"Some x\"} or @{term \"(x, y)\"}, we supply selector expressions\n       like @{term \"the\"} or @{term \"fst\"} to provide more unification\n       candidates.  This is only done if parameter that would be selected (e.g.\n       @{term x} in @{term \"Some x\"}) contains bound variables which the\n       schematic does not have as parameters.\n\n  In the \"constructor expression\" case, we let users supply additional\n  constructor handlers via the `datatype_schematic` attribute. The method uses\n  rules of the following form:\n\n    @{term \"\\<And>x1 x2 x3. getter (constructor x1 x2 x3) = x2\"}\n\n  These are essentially simp rules for simple \"accessor\" primrec functions,\n  which are used to turn schematics like\n\n    @{text \"?P (constructor x1 x2 x3)\"}\n\n  into\n\n    @{text \"?P' x2 (constructor x1 x2 x3)\"}.\n\\<close>\n\nML \\<open>\n  \\<comment> \\<open>\n    Anchor used to link error messages back to the documentation above.\n  \\<close>\n  val usage_pos = @{here};\n\\<close>\n\ndefinition\n  ds_id :: \"'a \\<Rightarrow> 'a\"\nwhere\n  \"ds_id = (\\<lambda>x. x)\"\n\nlemma wrap_ds_id:\n  \"x = ds_id x\"\n  by (simp add: ds_id_def)\n\nML \\<open>\nstructure Datatype_Schematic = struct\n\nfun eq ((idx1, name1, thm1), (idx2, name2, thm2)) =\n  idx1 = idx2 andalso\n  name1 = name2 andalso\n  (Thm.full_prop_of thm1) aconv (Thm.full_prop_of thm2);\n\nstructure Datatype_Schematic_Data = Generic_Data\n(\n  \\<comment> \\<open>\n    Keys are names of datatype constructors (like @{const Cons}), values are\n    `(index, function_name, thm)`.\n\n    - `function_name` is the name of an \"accessor\" function that accesses part\n      of the constructor specified by the key (so the accessor @{const hd} is\n      related to the constructor/key @{const Cons}).\n\n    - `thm` is a theorem showing that the function accesses one of the\n      arguments to the constructor (like @{thm list.sel(1)}).\n\n    - `idx` is the index of the constructor argument that the accessor\n      accesses.  (eg. since `hd` accesses the first argument, `idx = 0`; since\n      `tl` accesses the second argument, `idx = 1`).\n  \\<close>\n  type T = ((int * string * thm) list) Symtab.table;\n  val empty = Symtab.empty;\n  val extend = I;\n  val merge = Symtab.merge_list eq;\n);\n\nfun gen_att m =\n  Thm.declaration_attribute (fn thm => fn context =>\n    Datatype_Schematic_Data.map (m (Context.proof_of context) thm) context);\n\n(* gathers schematic applications from the goal. no effort is made\n   to normalise bound variables here, since we'll always be comparing\n   elements within a compound application which will be at the same\n   level as regards lambdas. *)\nfun gather_schem_apps (f $ x) insts = let\n    val (f, xs) = strip_comb (f $ x)\n    val insts = fold (gather_schem_apps) (f :: xs) insts\n  in if is_Var f then (f, xs) :: insts else insts end\n  | gather_schem_apps (Abs (_, _, t)) insts\n    = gather_schem_apps t insts\n  | gather_schem_apps _ insts = insts\n\nfun sfirst xs f = get_first f xs\n\nfun get_action ctxt prop = let\n    val schem_insts = gather_schem_apps prop [];\n    val actions = Datatype_Schematic_Data.get (Context.Proof ctxt);\n    fun mk_sel selname T i = let\n        val (argTs, resT) = strip_type T\n      in Const (selname, resT --> nth argTs i) end\n  in\n    sfirst schem_insts\n    (fn (var, xs) => sfirst (Library.tag_list 0 xs)\n        (try (fn (idx, x) => let\n            val (c, ys) = strip_comb x\n            val (fname, T) = dest_Const c\n            val acts = Symtab.lookup_list actions fname\n            fun interesting arg = not (member Term.aconv_untyped xs arg)\n                andalso exists (fn i => not (member (=) xs (Bound i)))\n                    (Term.loose_bnos arg)\n          in the (sfirst acts (fn (i, selname, thms) => if interesting (nth ys i)\n            then SOME (var, idx, mk_sel selname T i, thms) else NONE))\n          end)))\n  end\n\nfun get_bound_tac ctxt = SUBGOAL (fn (t, i) => case get_action ctxt t of\n  SOME (Var ((nm, ix), T), idx, sel, thm) => (fn t => let\n    val (argTs, _) = strip_type T\n    val ix2 = Thm.maxidx_of t + 1\n    val xs = map (fn (i, T) => Free (\"x\" ^ string_of_int i, T))\n        (Library.tag_list 1 argTs)\n    val nx = sel $ nth xs idx\n    val v' = Var ((nm, ix2), fastype_of nx --> T)\n    val inst_v = fold lambda (rev xs) (betapplys (v' $ nx, xs))\n    val t' = Drule.infer_instantiate ctxt\n        [((nm, ix), Thm.cterm_of ctxt inst_v)] t\n    val t'' = Conv.fconv_rule (Thm.beta_conversion true) t'\n  in safe_full_simp_tac (clear_simpset ctxt addsimps [thm]) i t'' end)\n  | _ => no_tac)\n\nfun id_applicable (f $ x) = let\n    val (f, xs) = strip_comb (f $ x)\n    val here = is_Var f andalso exists is_Const xs\n  in here orelse exists id_applicable (f :: xs) end\n  | id_applicable (Abs (_, _, t)) = id_applicable t\n  | id_applicable _ = false\n\nfun combination_conv cv1 cv2 ct =\n  let\n    val (ct1, ct2) = Thm.dest_comb ct\n    val r1 = SOME (cv1 ct1) handle Option => NONE\n    val r2 = SOME (cv2 ct2) handle Option => NONE\n    fun mk _ (SOME res) = res\n      | mk ct NONE = Thm.reflexive ct\n  in case (r1, r2) of\n      (NONE, NONE) => raise Option\n    | _ => Thm.combination (mk ct1 r1) (mk ct2 r2)\n  end\n\nval wrap = mk_meta_eq @{thm wrap_ds_id}\n\nfun wrap_const_conv _ ct = if is_Const (Thm.term_of ct)\n        andalso fastype_of (Thm.term_of ct) <> @{typ unit}\n    then Conv.rewr_conv wrap ct\n    else raise Option\n\nfun combs_conv conv ctxt ct = case Thm.term_of ct of\n    _ $ _ => combination_conv (combs_conv conv ctxt) (conv ctxt) ct\n  | _ => conv ctxt ct\n\nfun wrap_conv ctxt ct = case Thm.term_of ct of\n    Abs _ => Conv.sub_conv wrap_conv ctxt ct\n  | f $ x => if is_Var (head_of f) then combs_conv wrap_const_conv ctxt ct\n    else if not (id_applicable (f $ x)) then raise Option\n    else combs_conv wrap_conv ctxt ct\n  | _ => raise Option\n\nfun CONVERSION_opt conv i t = CONVERSION conv i t\n    handle Option => no_tac t\n\nexception Datatype_Schematic_Error of Pretty.T;\n\nfun apply_pos_markup pos text =\n  let\n    val props = Position.def_properties_of pos;\n    val markup = Markup.properties props (Markup.entity \"\" \"\");\n  in Pretty.mark_str (markup, text) end;\n\nfun invalid_accessor ctxt thm : exn =\n  Datatype_Schematic_Error ([\n    Pretty.str \"Bad input theorem '\",\n    Syntax.pretty_term ctxt (Thm.full_prop_of thm),\n    Pretty.str \"'. Click \",\n    apply_pos_markup usage_pos \"*here*\",\n    Pretty.str \" for info on the required rule format.\" ] |> Pretty.paragraph);\n\nlocal\n  fun dest_accessor' thm =\n    case (thm |> Thm.full_prop_of |> HOLogic.dest_Trueprop) of\n      @{term_pat \"?fun_name ?data_pat = ?rhs\"} =>\n        let\n          val fun_name = Term.dest_Const fun_name |> fst;\n          val (data_const, data_args) = Term.strip_comb data_pat;\n          val data_vars = data_args |> map (Term.dest_Var #> fst);\n          val rhs_var = rhs |> Term.dest_Var |> fst;\n          val data_name = Term.dest_Const data_const |> fst;\n          val rhs_idx = ListExtras.find_index (curry op = rhs_var) data_vars |> the;\n        in (fun_name, data_name, rhs_idx) end;\nin\n  fun dest_accessor ctxt thm =\n    case try dest_accessor' thm of\n      SOME x => x\n    | NONE => raise invalid_accessor ctxt thm;\nend\n\nfun add_rule ctxt thm data =\n  let\n    val (fun_name, data_name, idx) = dest_accessor ctxt thm;\n    val entry = (data_name, (idx, fun_name, thm));\n  in Symtab.insert_list eq entry data end;\n\nfun del_rule ctxt thm data =\n  let\n    val (fun_name, data_name, idx) = dest_accessor ctxt thm;\n    val entry = (data_name, (idx, fun_name, thm));\n  in Symtab.remove_list eq entry data end;\n\nval add = gen_att add_rule;\nval del = gen_att del_rule;\n\nfun wrap_tac ctxt = CONVERSION_opt (wrap_conv ctxt)\n\nfun tac1 ctxt = REPEAT_ALL_NEW (get_bound_tac ctxt) THEN' (TRY o wrap_tac ctxt)\n\nfun tac ctxt = tac1 ctxt ORELSE' wrap_tac ctxt\n\nval add_section =\n  Args.add -- Args.colon >> K (Method.modifier add @{here});\n\nval method =\n  Method.sections [add_section] >> (fn _ => fn ctxt => Method.SIMPLE_METHOD' (tac ctxt));\n\nend\n\\<close>\n\nsetup \\<open>\n  Attrib.setup\n    @{binding \"datatype_schematic\"}\n    (Attrib.add_del Datatype_Schematic.add Datatype_Schematic.del)\n    \"Accessor rules to fix datatypes in schematics\"\n\\<close>\n\nmethod_setup datatype_schem = \\<open>\n  Datatype_Schematic.method\n\\<close>\n\ndeclare prod.sel[datatype_schematic]\ndeclare option.sel[datatype_schematic]\ndeclare list.sel(1,3)[datatype_schematic]\n\nlocale datatype_schem_demo begin\n\nlemma handles_nested_constructors:\n  \"\\<exists>f. \\<forall>y. f True (Some [x, (y, z)]) = y\"\n  apply (rule exI, rule allI)\n  apply datatype_schem\n  apply (rule refl)\n  done\n\ndatatype foo =\n    basic nat int\n  | another nat\n\nprimrec get_basic_0 where\n  \"get_basic_0 (basic x0 x1) = x0\"\n\nprimrec get_nat where\n    \"get_nat (basic x _) = x\"\n  | \"get_nat (another z) = z\"\n\nlemma selectively_exposing_datatype_arugments:\n  notes get_basic_0.simps[datatype_schematic]\n  shows \"\\<exists>x. \\<forall>a b. x (basic a b) = a\"\n  apply (rule exI, (rule allI)+)\n  apply datatype_schem \\<comment> \\<open>Only exposes `a` to the schematic.\\<close>\n  by (rule refl)\n\nlemma method_handles_primrecs_with_two_constructors:\n  shows \"\\<exists>x. \\<forall>a b. x (basic a b) = a\"\n  apply (rule exI, (rule allI)+)\n  apply (datatype_schem add: get_nat.simps)\n  by (rule refl)\n\nend\n\nend\n", "meta": {"author": "NICTA", "repo": "l4v", "sha": "3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b", "save_path": "github-repos/isabelle/NICTA-l4v", "path": "github-repos/isabelle/NICTA-l4v/l4v-3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b/lib/Monad_WP/Datatype_Schematic.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.5350984286266115, "lm_q1q2_score": 0.2696394000253643}}
{"text": "(*  Title:       OAWN_Convert.thy\n    License:     BSD 2-Clause. See LICENSE.\n    Author:      Timothy Bourke\n*)\n\nsection \"Transfer standard invariants into open invariants\"\n\ntheory OAWN_Convert\nimports AWN_SOS_Labels AWN_Invariants\n        OAWN_SOS OAWN_Invariants\nbegin\n\ndefinition initiali :: \"'i \\<Rightarrow> (('i \\<Rightarrow> 'g) \\<times> 'l) set \\<Rightarrow> ('g \\<times> 'l) set \\<Rightarrow> bool\"\nwhere \"initiali i OI CI \\<equiv> ({(\\<sigma> i, p)|\\<sigma> p. (\\<sigma>, p) \\<in> OI} = CI)\"\n\nlemma initialiI [intro]:\n  assumes OICI: \"\\<And>\\<sigma> p. (\\<sigma>, p) \\<in> OI \\<Longrightarrow> (\\<sigma> i, p) \\<in> CI\"\n      and CIOI: \"\\<And>\\<xi> p. (\\<xi>, p) \\<in> CI \\<Longrightarrow> \\<exists>\\<sigma>. \\<xi> = \\<sigma> i \\<and> (\\<sigma>, p) \\<in> OI\"\n    shows \"initiali i OI CI\"\n  unfolding initiali_def\n  by (intro set_eqI iffI) (auto elim!: OICI CIOI)\n\nlemma open_from_initialiD [dest]:\n  assumes \"initiali i OI CI\"\n      and \"(\\<sigma>, p) \\<in> OI\"\n    shows \"\\<exists>\\<xi>. \\<sigma> i = \\<xi> \\<and> (\\<xi>, p) \\<in> CI\"\n  using assms unfolding initiali_def by auto\n\nlemma closed_from_initialiD [dest]:\n  assumes \"initiali i OI CI\"\n      and \"(\\<xi>, p) \\<in> CI\"\n    shows \"\\<exists>\\<sigma>. \\<sigma> i = \\<xi> \\<and> (\\<sigma>, p) \\<in> OI\"\n  using assms unfolding initiali_def by auto\n\ndefinition\n  seql :: \"'i \\<Rightarrow> (('s \\<times> 'l) \\<Rightarrow> bool) \\<Rightarrow> (('i \\<Rightarrow> 's) \\<times> 'l) \\<Rightarrow> bool\"\nwhere\n  \"seql i P \\<equiv> (\\<lambda>(\\<sigma>, p). P (\\<sigma> i, p))\"\n\nlemma seqlI [intro]:\n  \"P (fst s i, snd s) \\<Longrightarrow> seql i P s\"\n  by (clarsimp simp: seql_def)\n\nlemma same_seql [elim]:\n  assumes \"\\<forall>j\\<in>{i}. \\<sigma>' j = \\<sigma> j\"\n      and \"seql i P (\\<sigma>', s)\"\n    shows \"seql i P (\\<sigma>, s)\"\n  using assms unfolding seql_def by (clarsimp)\n\nlemma seqlsimp:\n  \"seql i P (\\<sigma>, p) = P (\\<sigma> i, p)\"\n  unfolding seql_def by simp\n\nlemma other_steps_resp_local [intro!, simp]: \"other_steps (other A I) I\"\n  by (clarsimp elim!: otherE)\n\nlemma seql_onl_swap:\n  \"seql i (onl \\<Gamma> P) = onl \\<Gamma> (seql i P)\"\n  unfolding seql_def onl_def by simp\n\nlemma oseqp_sos_resp_local_steps [intro!, simp]:\n  fixes \\<Gamma> :: \"'p \\<Rightarrow> ('s, 'm, 'p, 'l) seqp\"\n  shows \"local_steps (oseqp_sos \\<Gamma> i) {i}\"\n  proof\n    fix \\<sigma> \\<sigma>' \\<zeta> \\<zeta>' :: \"nat \\<Rightarrow> 's\" and s a s'\n    assume tr: \"((\\<sigma>, s), a, \\<sigma>', s') \\<in> oseqp_sos \\<Gamma> i\"\n       and \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j\"\n    thus \"\\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and> ((\\<zeta>, s), a, (\\<zeta>', s')) \\<in> oseqp_sos \\<Gamma> i\"\n    proof induction\n      fix \\<sigma> \\<sigma>' l ms p\n      assume \"\\<sigma>' i = \\<sigma> i\"\n         and \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j\"\n      hence \"((\\<zeta>, {l}broadcast(ms).p), broadcast (ms (\\<sigma> i)), (\\<sigma>', p)) \\<in> oseqp_sos \\<Gamma> i\"\n        by (metis obroadcastT singleton_iff)\n      with \\<open>\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j\\<close> show \"\\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and>\n            ((\\<zeta>, {l}broadcast(ms).p), broadcast (ms (\\<sigma> i)), (\\<zeta>', p)) \\<in> oseqp_sos \\<Gamma> i\"\n        by blast\n    next\n      fix \\<sigma> \\<sigma>' :: \"nat \\<Rightarrow> 's\" and fmsg :: \"'m \\<Rightarrow> 's \\<Rightarrow> 's\" and msg l p\n      assume *:  \"\\<sigma>' i = fmsg msg (\\<sigma> i)\"\n         and **: \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j\"\n      hence \"\\<forall>j\\<in>{i}. (\\<zeta>(i := fmsg msg (\\<zeta> i))) j = \\<sigma>' j\" by clarsimp\n      moreover from * **\n        have \"((\\<zeta>, {l}receive(fmsg).p), receive msg, (\\<zeta>(i := fmsg msg (\\<zeta> i)), p)) \\<in> oseqp_sos \\<Gamma> i\"\n        by (metis fun_upd_same oreceiveT)\n      ultimately show \"\\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and>\n                            ((\\<zeta>, {l}receive(fmsg).p), receive msg, (\\<zeta>', p)) \\<in> oseqp_sos \\<Gamma> i\"\n        by blast\n    next\n      fix \\<sigma>' \\<sigma> l p and fas :: \"'s \\<Rightarrow> 's\"\n      assume *:  \"\\<sigma>' i = fas (\\<sigma> i)\"\n         and **: \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j\"\n      hence \"\\<forall>j\\<in>{i}. (\\<zeta>(i := fas (\\<zeta> i))) j = \\<sigma>' j\" by clarsimp\n      moreover from * ** have \"((\\<zeta>, {l}\\<lbrakk>fas\\<rbrakk> p), \\<tau>, (\\<zeta>(i := fas (\\<zeta> i)), p)) \\<in> oseqp_sos \\<Gamma> i\"\n        by (metis fun_upd_same oassignT)\n      ultimately show \"\\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and> ((\\<zeta>, {l}\\<lbrakk>fas\\<rbrakk> p), \\<tau>, (\\<zeta>', p)) \\<in> oseqp_sos \\<Gamma> i\"\n        by blast\n    next\n      fix g :: \"'s \\<Rightarrow> 's set\" and \\<sigma> \\<sigma>' l p\n      assume *:  \"\\<sigma>' i \\<in> g (\\<sigma> i)\"\n         and **: \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j\"\n      hence \"\\<forall>j\\<in>{i}. (SOME \\<zeta>'. \\<zeta>' i = \\<sigma>' i) j = \\<sigma>' j\" by simp (metis (lifting, full_types) some_eq_ex)\n      moreover with * ** have \"((\\<zeta>, {l}\\<langle>g\\<rangle> p), \\<tau>, (SOME \\<zeta>'. \\<zeta>' i = \\<sigma>' i, p)) \\<in> oseqp_sos \\<Gamma> i\"\n        by simp (metis oguardT step_seq_tau)\n      ultimately show \"\\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and> ((\\<zeta>, {l}\\<langle>g\\<rangle> p), \\<tau>, (\\<zeta>', p)) \\<in> oseqp_sos \\<Gamma> i\"\n        by blast\n    next\n      fix \\<sigma> pn a \\<sigma>' p'\n      assume \"((\\<sigma>, \\<Gamma> pn), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n         and IH: \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j \\<Longrightarrow> \\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and> ((\\<zeta>, \\<Gamma> pn), a, (\\<zeta>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n         and \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j\"\n      then obtain \\<zeta>' where \"\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j\"\n                       and \"((\\<zeta>, \\<Gamma> pn), a, (\\<zeta>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n        by blast\n      thus \"\\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and> ((\\<zeta>, call(pn)), a, (\\<zeta>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n        by blast\n    next\n      fix \\<sigma> p a \\<sigma>' p' q\n      assume \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n         and \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j \\<Longrightarrow> \\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and> ((\\<zeta>, p), a, (\\<zeta>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n         and \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j\"\n      then obtain \\<zeta>' where \"\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j\"\n                       and \"((\\<zeta>, p), a, (\\<zeta>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n        by blast\n      thus \"\\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and> ((\\<zeta>, p \\<oplus> q), a, (\\<zeta>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n        by blast\n    next\n      fix \\<sigma> p a \\<sigma>' q q'\n      assume \"((\\<sigma>, q), a, (\\<sigma>', q')) \\<in> oseqp_sos \\<Gamma> i\"\n         and \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j \\<Longrightarrow> \\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and> ((\\<zeta>, q), a, (\\<zeta>', q')) \\<in> oseqp_sos \\<Gamma> i\"\n         and \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j\"\n      then obtain \\<zeta>' where \"\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j\"\n                       and \"((\\<zeta>, q), a, (\\<zeta>', q')) \\<in> oseqp_sos \\<Gamma> i\"\n        by blast\n      thus \"\\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and> ((\\<zeta>, p \\<oplus> q), a, (\\<zeta>', q')) \\<in> oseqp_sos \\<Gamma> i\"\n        by blast\n    qed (simp_all, (metis ogroupcastT ounicastT onotunicastT osendT odeliverT)+)\n  qed\n\nlemma oseqp_sos_subreachable [intro!, simp]:\n  assumes \"trans OA = oseqp_sos \\<Gamma> i\"\n    shows \"subreachable OA (other ANY {i}) {i}\"\n  by rule (clarsimp simp add: assms(1))+\n\nlemma oseq_step_is_seq_step:\n    fixes \\<sigma> :: \"ip \\<Rightarrow> 's\"\n  assumes \"((\\<sigma>, p), a :: 'm seq_action, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n      and \"\\<sigma> i = \\<xi>\"\n    shows \"\\<exists>\\<xi>'. \\<sigma>' i = \\<xi>' \\<and> ((\\<xi>, p), a, (\\<xi>', p')) \\<in> seqp_sos \\<Gamma>\"\n  using assms proof induction\n    fix \\<sigma> \\<sigma>' l ms p\n    assume \"\\<sigma>' i = \\<sigma> i\"\n       and \"\\<sigma> i = \\<xi>\"\n    hence \"\\<sigma>' i = \\<xi>\" by simp\n    have \"((\\<xi>, {l}broadcast(ms).p), broadcast (ms \\<xi>), (\\<xi>, p)) \\<in> seqp_sos \\<Gamma>\"\n      by auto\n    with \\<open>\\<sigma> i = \\<xi>\\<close> and \\<open>\\<sigma>' i = \\<xi>\\<close> show \"\\<exists>\\<xi>'. \\<sigma>' i = \\<xi>'\n             \\<and> ((\\<xi>, {l}broadcast(ms).p), broadcast (ms (\\<sigma> i)), (\\<xi>', p)) \\<in> seqp_sos \\<Gamma>\"\n       by clarsimp\n  next\n    fix fmsg :: \"'m \\<Rightarrow> 's \\<Rightarrow> 's\" and msg :: 'm and \\<sigma>' \\<sigma> l p\n    assume \"\\<sigma>' i = fmsg msg (\\<sigma> i)\"\n       and \"\\<sigma> i = \\<xi>\"\n    have \"((\\<xi>, {l}receive(fmsg).p), receive msg, (fmsg msg \\<xi>, p)) \\<in> seqp_sos \\<Gamma>\"\n      by auto\n    with \\<open>\\<sigma>' i = fmsg msg (\\<sigma> i)\\<close> and \\<open>\\<sigma> i = \\<xi>\\<close>\n      show \"\\<exists>\\<xi>'. \\<sigma>' i = \\<xi>' \\<and> ((\\<xi>, {l}receive(fmsg).p), receive msg, (\\<xi>', p)) \\<in> seqp_sos \\<Gamma>\"\n         by clarsimp\n  qed (simp_all, (metis assignT choiceT1 choiceT2 groupcastT guardT\n                        callT unicastT notunicastT sendT deliverT step_seq_tau)+)\n\nlemma reachable_oseq_seqp_sos:\n  assumes \"(\\<sigma>, p) \\<in> reachable OA I\"\n      and \"initiali i (init OA) (init A)\"\n      and spo: \"trans OA = oseqp_sos \\<Gamma> i\"\n      and sp: \"trans A = seqp_sos \\<Gamma>\"\n      shows \"\\<exists>\\<xi>. \\<sigma> i = \\<xi> \\<and> (\\<xi>, p) \\<in> reachable A I\"\n  using assms(1) proof (induction rule: reachable_pair_induct)\n    fix \\<sigma> p\n    assume \"(\\<sigma>, p) \\<in> init OA\"\n    with \\<open>initiali i (init OA) (init A)\\<close> obtain \\<xi> where \"\\<sigma> i = \\<xi>\"\n                                                    and \"(\\<xi>, p) \\<in> init A\"\n      by auto\n    from \\<open>(\\<xi>, p) \\<in> init A\\<close> have \"(\\<xi>, p) \\<in> reachable A I\" ..\n    with \\<open>\\<sigma> i = \\<xi>\\<close> show \"\\<exists>\\<xi>. \\<sigma> i = \\<xi> \\<and> (\\<xi>, p) \\<in> reachable A I\"\n      by auto\n  next\n    fix \\<sigma> p \\<sigma>' p' a\n    assume \"(\\<sigma>, p) \\<in> reachable OA I\"\n       and IH: \"\\<exists>\\<xi>. \\<sigma> i = \\<xi> \\<and> (\\<xi>, p) \\<in> reachable A I\"\n       and otr: \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans OA\"\n       and \"I a\"\n    from IH obtain \\<xi> where \"\\<sigma> i = \\<xi>\"\n                       and cr: \"(\\<xi>, p) \\<in> reachable A I\"\n      by clarsimp\n    from otr and spo have \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\" by simp\n    with \\<open>\\<sigma> i = \\<xi>\\<close> obtain \\<xi>' where \"\\<sigma>' i = \\<xi>'\"\n                               and \"((\\<xi>, p), a, (\\<xi>', p')) \\<in> seqp_sos \\<Gamma>\"\n        by (auto dest!: oseq_step_is_seq_step)\n    from this(2) and sp have ctr: \"((\\<xi>, p), a, (\\<xi>', p')) \\<in> trans A\" by simp\n    from \\<open>(\\<xi>, p) \\<in> reachable A I\\<close> and ctr and \\<open>I a\\<close>\n      have \"(\\<xi>', p') \\<in> reachable A I\" ..\n    with \\<open>\\<sigma>' i = \\<xi>'\\<close> show \"\\<exists>\\<xi>. \\<sigma>' i = \\<xi> \\<and> (\\<xi>, p') \\<in> reachable A I\"\n      by blast\n  qed\n\nlemma reachable_oseq_seqp_sos':\n  assumes \"s \\<in> reachable OA I\"\n      and \"initiali i (init OA) (init A)\"\n      and \"trans OA = oseqp_sos \\<Gamma> i\"\n      and \"trans A = seqp_sos \\<Gamma>\"\n    shows \"\\<exists>\\<xi>. (fst s) i = \\<xi> \\<and> (\\<xi>, snd s) \\<in> reachable A I\"\n  using assms\n  by - (cases s, auto dest: reachable_oseq_seqp_sos)\n\ntext \\<open>\n  Any invariant shown in the (simpler) closed semantics can be transferred to an invariant in\n  the open semantics.\n\\<close>\n\ntheorem open_seq_invariant [intro]:\n  assumes \"A \\<TTurnstile> (I \\<rightarrow>) P\"\n      and \"initiali i (init OA) (init A)\"\n      and spo: \"trans OA = oseqp_sos \\<Gamma> i\"\n      and sp: \"trans A = seqp_sos \\<Gamma>\"\n    shows \"OA \\<Turnstile> (act I, other ANY {i} \\<rightarrow>) (seql i P)\"\n  proof -\n    have \"OA \\<TTurnstile> (I \\<rightarrow>) (seql i P)\"\n      proof (rule invariant_arbitraryI)\n        fix s                                      \n        assume \"s \\<in> reachable OA I\"\n        with \\<open>initiali i (init OA) (init A)\\<close> obtain \\<xi> where \"(fst s) i = \\<xi>\"\n                                                        and \"(\\<xi>, snd s) \\<in> reachable A I\"\n          by (auto dest: reachable_oseq_seqp_sos' [OF _ _ spo sp])\n        with \\<open>A \\<TTurnstile> (I \\<rightarrow>) P\\<close> have \"P (\\<xi>, snd s)\" by auto\n        with \\<open>(fst s) i = \\<xi>\\<close> show \"seql i P s\" by auto\n      qed\n    moreover from spo have \"subreachable OA (other ANY {i}) {i}\" ..\n    ultimately show ?thesis\n    proof (rule open_closed_invariant)\n      fix \\<sigma> \\<sigma>' s\n      assume \"\\<forall>j\\<in>{i}. \\<sigma>' j = \\<sigma> j\"\n         and \"seql i P (\\<sigma>', s)\"\n      thus \"seql i P (\\<sigma>, s)\" ..\n    qed\n  qed\n\ndefinition\n  seqll :: \"'i \\<Rightarrow> ((('s \\<times> 'l) \\<times> 'a \\<times> ('s \\<times> 'l)) \\<Rightarrow> bool)\n               \\<Rightarrow> ((('i \\<Rightarrow> 's) \\<times> 'l) \\<times> 'a \\<times> (('i \\<Rightarrow> 's) \\<times> 'l)) \\<Rightarrow> bool\"\nwhere\n  \"seqll i P \\<equiv> (\\<lambda>((\\<sigma>, p), a, (\\<sigma>', p')). P ((\\<sigma> i, p), a, (\\<sigma>' i, p')))\"\n\nlemma same_seqll [elim]:\n  assumes \"\\<forall>j\\<in>{i}. \\<sigma>\\<^sub>1' j = \\<sigma>\\<^sub>1 j\"\n      and \"\\<forall>j\\<in>{i}. \\<sigma>\\<^sub>2' j = \\<sigma>\\<^sub>2 j\"\n      and \"seqll i P ((\\<sigma>\\<^sub>1', s), a, (\\<sigma>\\<^sub>2', s'))\"\n    shows \"seqll i P ((\\<sigma>\\<^sub>1,  s), a, (\\<sigma>\\<^sub>2,  s'))\"\n  using assms unfolding seqll_def by (clarsimp)\n\nlemma seqllI [intro!]:\n  assumes \"P ((\\<sigma> i, p), a, (\\<sigma>' i, p'))\"\n    shows \"seqll i P ((\\<sigma>, p), a, (\\<sigma>', p'))\"\n  using assms unfolding seqll_def by simp\n\nlemma seqllD [dest]:\n  assumes \"seqll i P ((\\<sigma>, p), a, (\\<sigma>', p'))\"\n    shows \"P ((\\<sigma> i, p), a, (\\<sigma>' i, p'))\"\n  using assms unfolding seqll_def by simp\n\nlemma seqllsimp:\n  \"seqll i P ((\\<sigma>, p), a, (\\<sigma>', p')) = P ((\\<sigma> i, p), a, (\\<sigma>' i, p'))\"\n  unfolding seqll_def by simp\n\nlemma seqll_onll_swap:\n  \"seqll i (onll \\<Gamma> P) = onll \\<Gamma> (seqll i P)\"\n  unfolding seqll_def onll_def by simp\n\ntheorem open_seq_step_invariant [intro]:\n  assumes \"A \\<TTurnstile>\\<^sub>A (I \\<rightarrow>) P\"\n      and \"initiali i (init OA) (init A)\"\n      and spo: \"trans OA = oseqp_sos \\<Gamma> i\"\n      and sp: \"trans A = seqp_sos \\<Gamma>\"\n    shows \"OA \\<Turnstile>\\<^sub>A (act I, other ANY {i} \\<rightarrow>) (seqll i P)\"\n  proof -\n    have \"OA \\<TTurnstile>\\<^sub>A (I \\<rightarrow>) (seqll i P)\"\n    proof (rule step_invariant_arbitraryI)\n      fix \\<sigma> p a \\<sigma>' p'\n      assume or: \"(\\<sigma>, p) \\<in> reachable OA I\"\n         and otr: \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans OA\"\n         and \"I a\"\n      from or \\<open>initiali i (init OA) (init A)\\<close> spo sp obtain \\<xi> where \"\\<sigma> i = \\<xi>\"\n                                                             and cr: \"(\\<xi>, p) \\<in> reachable A I\"\n        by - (drule(3) reachable_oseq_seqp_sos', auto)\n      from otr and spo have \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\" by simp\n      with \\<open>\\<sigma> i = \\<xi>\\<close> obtain \\<xi>' where \"\\<sigma>' i = \\<xi>'\"\n                                 and ctr: \"((\\<xi>, p), a, (\\<xi>', p')) \\<in> seqp_sos \\<Gamma>\"\n        by (auto dest!: oseq_step_is_seq_step)\n      with sp have \"((\\<xi>, p), a, (\\<xi>', p')) \\<in> trans A\" by simp\n      with \\<open>A \\<TTurnstile>\\<^sub>A (I \\<rightarrow>) P\\<close> cr have \"P ((\\<xi>, p), a, (\\<xi>', p'))\" using \\<open>I a\\<close> ..\n      with \\<open>\\<sigma> i = \\<xi>\\<close> and \\<open>\\<sigma>' i = \\<xi>'\\<close> have \"P ((\\<sigma> i, p), a, (\\<sigma>' i, p'))\" by simp\n      thus \"seqll i P ((\\<sigma>, p), a, (\\<sigma>', p'))\" ..\n    qed\n    moreover from spo have \"local_steps (trans OA) {i}\" by simp\n    moreover have \"other_steps (other ANY {i}) {i}\" ..\n    ultimately show ?thesis\n    proof (rule open_closed_step_invariant)\n      fix \\<sigma> \\<zeta> a \\<sigma>' \\<zeta>' s s'\n      assume \"\\<forall>j\\<in>{i}. \\<sigma> j = \\<zeta> j\"\n         and \"\\<forall>j\\<in>{i}. \\<sigma>' j = \\<zeta>' j\"\n         and \"seqll i P ((\\<sigma>, s), a, (\\<sigma>', s'))\"\n        thus \"seqll i P ((\\<zeta>, s), a, (\\<zeta>', s'))\" ..\n    qed\n  qed\n\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/AWN/OAWN_Convert.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5350984137988772, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.2696393925535775}}
{"text": "(*  Title:      HOL/Auth/Guard/Proto.thy\n    Author:     Frederic Blanqui, University of Cambridge Computer Laboratory\n    Copyright   2002  University of Cambridge\n*)\n\nsection\\<open>Other Protocol-Independent Results\\<close>\n\ntheory Proto imports Guard_Public begin\n\nsubsection\\<open>protocols\\<close>\n\ntype_synonym rule = \"event set * event\"\n\nabbreviation\n  msg' :: \"rule => msg\" where\n  \"msg' R == msg (snd R)\"\n\ntype_synonym proto = \"rule set\"\n\ndefinition wdef :: \"proto => bool\" where\n\"wdef p \\<equiv> \\<forall>R k. R \\<in> p \\<longrightarrow> Number k \\<in> parts {msg' R}\n\\<longrightarrow> Number k \\<in> parts (msg`(fst R))\"\n\nsubsection\\<open>substitutions\\<close>\n\nrecord subs =\n  agent   :: \"agent => agent\"\n  nonce :: \"nat => nat\"\n  nb    :: \"nat => msg\"\n  key   :: \"key => key\"\n\nprimrec apm :: \"subs => msg => msg\" where\n  \"apm s (Agent A) = Agent (agent s A)\"\n| \"apm s (Nonce n) = Nonce (nonce s n)\"\n| \"apm s (Number n) = nb s n\"\n| \"apm s (Key K) = Key (key s K)\"\n| \"apm s (Hash X) = Hash (apm s X)\"\n| \"apm s (Crypt K X) = (\nif (\\<exists>A. K = pubK A) then Crypt (pubK (agent s (agt K))) (apm s X)\nelse if (\\<exists>A. K = priK A) then Crypt (priK (agent s (agt K))) (apm s X)\nelse Crypt (key s K) (apm s X))\"\n| \"apm s \\<lbrace>X,Y\\<rbrace> = \\<lbrace>apm s X, apm s Y\\<rbrace>\"\n\nlemma apm_parts: \"X \\<in> parts {Y} \\<Longrightarrow> apm s X \\<in> parts {apm s Y}\"\napply (erule parts.induct, simp_all, blast)\napply (erule parts.Fst)\napply (erule parts.Snd)\nby (erule parts.Body)+\n\nlemma Nonce_apm [rule_format]: \"Nonce n \\<in> parts {apm s X} \\<Longrightarrow>\n(\\<forall>k. Number k \\<in> parts {X} \\<longrightarrow> Nonce n \\<notin> parts {nb s k}) \\<longrightarrow>\n(\\<exists>k. Nonce k \\<in> parts {X} \\<and> nonce s k = n)\"\nby (induct X, simp_all, blast)\n\nlemma wdef_Nonce: \"[| Nonce n \\<in> parts {apm s X}; R \\<in> p; msg' R = X; wdef p;\nNonce n \\<notin> parts (apm s `(msg `(fst R))) |] ==>\n(\\<exists>k. Nonce k \\<in> parts {X} \\<and> nonce s k = n)\"\napply (erule Nonce_apm, unfold wdef_def)\napply (drule_tac x=R in spec, drule_tac x=k in spec, clarsimp)\napply (drule_tac x=x in bspec, simp)\napply (drule_tac Y=\"msg x\" and s=s in apm_parts, simp)\nby (blast dest: parts_parts)\n\nprimrec ap :: \"subs \\<Rightarrow> event \\<Rightarrow> event\" where\n  \"ap s (Says A B X) = Says (agent s A) (agent s B) (apm s X)\"\n| \"ap s (Gets A X) = Gets (agent s A) (apm s X)\"\n| \"ap s (Notes A X) = Notes (agent s A) (apm s X)\"\n\nabbreviation\n  ap' :: \"subs \\<Rightarrow> rule \\<Rightarrow> event\" where\n  \"ap' s R \\<equiv> ap s (snd R)\"\n\nabbreviation\n  apm' :: \"subs \\<Rightarrow> rule \\<Rightarrow> msg\" where\n  \"apm' s R \\<equiv> apm s (msg' R)\"\n\nabbreviation\n  priK' :: \"subs \\<Rightarrow> agent \\<Rightarrow> key\" where\n  \"priK' s A \\<equiv> priK (agent s A)\"\n\nabbreviation\n  pubK' :: \"subs \\<Rightarrow> agent \\<Rightarrow> key\" where\n  \"pubK' s A \\<equiv> pubK (agent s A)\"\n\nsubsection\\<open>nonces generated by a rule\\<close>\n\ndefinition newn :: \"rule \\<Rightarrow> nat set\" where\n\"newn R \\<equiv> {n. Nonce n \\<in> parts {msg (snd R)} \\<and> Nonce n \\<notin> parts (msg`(fst R))}\"\n\nlemma newn_parts: \"n \\<in> newn R \\<Longrightarrow> Nonce (nonce s n) \\<in> parts {apm' s R}\"\nby (auto simp: newn_def dest: apm_parts)\n\nsubsection\\<open>traces generated by a protocol\\<close>\n\ndefinition ok :: \"event list \\<Rightarrow> rule \\<Rightarrow> subs \\<Rightarrow> bool\" where\n\"ok evs R s \\<equiv> ((\\<forall>x. x \\<in> fst R \\<longrightarrow> ap s x \\<in> set evs)\n\\<and> (\\<forall>n. n \\<in> newn R \\<longrightarrow> Nonce (nonce s n) \\<notin> used evs))\"\n\ninductive_set\n  tr :: \"proto => event list set\"\n  for p :: proto\nwhere\n\n  Nil [intro]: \"[] \\<in> tr p\"\n\n| Fake [intro]: \"[| evsf \\<in> tr p; X \\<in> synth (analz (spies evsf)) |]\n  ==> Says Spy B X # evsf \\<in> tr p\"\n\n| Proto [intro]: \"[| evs \\<in> tr p; R \\<in> p; ok evs R s |] ==> ap' s R # evs \\<in> tr p\"\n\nsubsection\\<open>general properties\\<close>\n\nlemma one_step_tr [iff]: \"one_step (tr p)\"\napply (unfold one_step_def, clarify)\nby (ind_cases \"ev # evs \\<in> tr p\" for ev evs, auto)\n\ndefinition has_only_Says' :: \"proto => bool\" where\n\"has_only_Says' p \\<equiv> \\<forall>R. R \\<in> p \\<longrightarrow> is_Says (snd R)\"\n\nlemma has_only_Says'D: \"[| R \\<in> p; has_only_Says' p |]\n==> (\\<exists>A B X. snd R = Says A B X)\"\nby (unfold has_only_Says'_def is_Says_def, blast)\n\nlemma has_only_Says_tr [simp]: \"has_only_Says' p ==> has_only_Says (tr p)\"\napply (unfold has_only_Says_def)\napply (rule allI, rule allI, rule impI)\napply (erule tr.induct)\napply (auto simp: has_only_Says'_def ok_def)\nby (drule_tac x=a in spec, auto simp: is_Says_def)\n\nlemma has_only_Says'_in_trD: \"[| has_only_Says' p; list @ ev # evs1 \\<in> tr p |]\n==> (\\<exists>A B X. ev = Says A B X)\"\nby (drule has_only_Says_tr, auto)\n\nlemma ok_not_used: \"[| Nonce n \\<notin> used evs; ok evs R s;\n\\<forall>x. x \\<in> fst R \\<longrightarrow> is_Says x |] ==> Nonce n \\<notin> parts (apm s `(msg `(fst R)))\"\napply (unfold ok_def, clarsimp)\napply (drule_tac x=x in spec, drule_tac x=x in spec)\nby (auto simp: is_Says_def dest: Says_imp_spies not_used_not_spied parts_parts)\n\nlemma ok_is_Says: \"[| evs' @ ev # evs \\<in> tr p; ok evs R s; has_only_Says' p;\nR \\<in> p; x \\<in> fst R |] ==> is_Says x\"\napply (unfold ok_def is_Says_def, clarify)\napply (drule_tac x=x in spec, simp)\napply (subgoal_tac \"one_step (tr p)\")\napply (drule trunc, simp, drule one_step_Cons, simp)\napply (drule has_only_SaysD, simp+)\nby (clarify, case_tac x, auto)\n\nsubsection\\<open>types\\<close>\n\ntype_synonym keyfun = \"rule \\<Rightarrow> subs \\<Rightarrow> nat \\<Rightarrow> event list \\<Rightarrow> key set\"\n\ntype_synonym secfun = \"rule \\<Rightarrow> nat \\<Rightarrow> subs \\<Rightarrow> key set \\<Rightarrow> msg\"\n\nsubsection\\<open>introduction of a fresh guarded nonce\\<close>\n\ndefinition fresh :: \"proto \\<Rightarrow> rule \\<Rightarrow> subs \\<Rightarrow> nat \\<Rightarrow> key set \\<Rightarrow> event list\n\\<Rightarrow> bool\" where\n\"fresh p R s n Ks evs \\<equiv> (\\<exists>evs1 evs2. evs = evs2 @ ap' s R # evs1\n\\<and> Nonce n \\<notin> used evs1 \\<and> R \\<in> p \\<and> ok evs1 R s \\<and> Nonce n \\<in> parts {apm' s R}\n\\<and> apm' s R \\<in> guard n Ks)\"\n\nlemma freshD: \"fresh p R s n Ks evs \\<Longrightarrow> (\\<exists>evs1 evs2.\nevs = evs2 @ ap' s R # evs1 \\<and> Nonce n \\<notin> used evs1 \\<and> R \\<in> p \\<and> ok evs1 R s\n\\<and> Nonce n \\<in> parts {apm' s R} \\<and> apm' s R \\<in> guard n Ks)\"\nby (unfold fresh_def, blast)\n\nlemma freshI [intro]: \"[| Nonce n \\<notin> used evs1; R \\<in> p; Nonce n \\<in> parts {apm' s R};\nok evs1 R s; apm' s R \\<in> guard n Ks |]\n==> fresh p R s n Ks (list @ ap' s R # evs1)\"\nby (unfold fresh_def, blast)\n\nlemma freshI': \"[| Nonce n \\<notin> used evs1; (l,r) \\<in> p;\nNonce n \\<in> parts {apm s (msg r)}; ok evs1 (l,r) s; apm s (msg r) \\<in> guard n Ks |]\n==> fresh p (l,r) s n Ks (evs2 @ ap s r # evs1)\"\nby (drule freshI, simp+)\n\nlemma fresh_used: \"[| fresh p R' s' n Ks evs; has_only_Says' p |]\n==> Nonce n \\<in> used evs\"\napply (unfold fresh_def, clarify)\napply (drule has_only_Says'D)\nby (auto intro: parts_used_app)\n\nlemma fresh_newn: \"[| evs' @ ap' s R # evs \\<in> tr p; wdef p; has_only_Says' p;\nNonce n \\<notin> used evs; R \\<in> p; ok evs R s; Nonce n \\<in> parts {apm' s R} |]\n==> \\<exists>k. k \\<in> newn R \\<and> nonce s k = n\"\napply (drule wdef_Nonce, simp+)\napply (frule ok_not_used, simp+)\napply (clarify, erule ok_is_Says, simp+)\napply (clarify, rule_tac x=k in exI, simp add: newn_def)\napply (clarify, drule_tac Y=\"msg x\" and s=s in apm_parts)\napply (drule ok_not_used, simp+)\nby (clarify, erule ok_is_Says, simp_all)\n\nlemma fresh_rule: \"[| evs' @ ev # evs \\<in> tr p; wdef p; Nonce n \\<notin> used evs;\nNonce n \\<in> parts {msg ev} |] ==> \\<exists>R s. R \\<in> p \\<and> ap' s R = ev\"\napply (drule trunc, simp, ind_cases \"ev # evs \\<in> tr p\", simp)\nby (drule_tac x=X in in_sub, drule parts_sub, simp, simp, blast+)\n\nlemma fresh_ruleD: \"[| fresh p R' s' n Ks evs; keys R' s' n evs \\<subseteq> Ks; wdef p;\nhas_only_Says' p; evs \\<in> tr p; \\<forall>R k s. nonce s k = n \\<longrightarrow> Nonce n \\<in> used evs \\<longrightarrow>\nR \\<in> p \\<longrightarrow> k \\<in> newn R \\<longrightarrow> Nonce n \\<in> parts {apm' s R} \\<longrightarrow> apm' s R \\<in> guard n Ks \\<longrightarrow>\napm' s R \\<in> parts (spies evs) \\<longrightarrow> keys R s n evs \\<subseteq> Ks \\<longrightarrow> P |] ==> P\"\napply (frule fresh_used, simp)\napply (unfold fresh_def, clarify)\napply (drule_tac x=R' in spec)\napply (drule fresh_newn, simp+, clarify)\napply (drule_tac x=k in spec)\napply (drule_tac x=s' in spec)\napply (subgoal_tac \"apm' s' R' \\<in> parts (spies (evs2 @ ap' s' R' # evs1))\")\napply (case_tac R', drule has_only_Says'D, simp, clarsimp)\napply (case_tac R', drule has_only_Says'D, simp, clarsimp)\napply (rule_tac Y=\"apm s' X\" in parts_parts, blast)\nby (rule parts.Inj, rule Says_imp_spies, simp, blast)\n\nsubsection\\<open>safe keys\\<close>\n\ndefinition safe :: \"key set \\<Rightarrow> msg set \\<Rightarrow> bool\" where\n\"safe Ks G \\<equiv> \\<forall>K. K \\<in> Ks \\<longrightarrow> Key K \\<notin> analz G\"\n\nlemma safeD [dest]: \"[| safe Ks G; K \\<in> Ks |] ==> Key K \\<notin> analz G\"\nby (unfold safe_def, blast)\n\nlemma safe_insert: \"safe Ks (insert X G) ==> safe Ks G\"\nby (unfold safe_def, blast)\n\nlemma Guard_safe: \"[| Guard n Ks G; safe Ks G |] ==> Nonce n \\<notin> analz G\"\nby (blast dest: Guard_invKey)\n\nsubsection\\<open>guardedness preservation\\<close>\n\ndefinition preserv :: \"proto \\<Rightarrow> keyfun \\<Rightarrow> nat \\<Rightarrow> key set \\<Rightarrow> bool\" where\n\"preserv p keys n Ks \\<equiv> (\\<forall>evs R' s' R s. evs \\<in> tr p \\<longrightarrow>\nGuard n Ks (spies evs) \\<longrightarrow> safe Ks (spies evs) \\<longrightarrow> fresh p R' s' n Ks evs \\<longrightarrow>\nkeys R' s' n evs \\<subseteq> Ks \\<longrightarrow> R \\<in> p \\<longrightarrow> ok evs R s \\<longrightarrow> apm' s R \\<in> guard n Ks)\"\n\nlemma preservD: \"[| preserv p keys n Ks; evs \\<in> tr p; Guard n Ks (spies evs);\nsafe Ks (spies evs); fresh p R' s' n Ks evs; R \\<in> p; ok evs R s;\nkeys R' s' n evs \\<subseteq> Ks |] ==> apm' s R \\<in> guard n Ks\"\nby (unfold preserv_def, blast)\n\nlemma preservD': \"[| preserv p keys n Ks; evs \\<in> tr p; Guard n Ks (spies evs);\nsafe Ks (spies evs); fresh p R' s' n Ks evs; (l,Says A B X) \\<in> p;\nok evs (l,Says A B X) s; keys R' s' n evs \\<subseteq> Ks |] ==> apm s X \\<in> guard n Ks\"\nby (drule preservD, simp+)\n\nsubsection\\<open>monotonic keyfun\\<close>\n\ndefinition monoton :: \"proto => keyfun => bool\" where\n\"monoton p keys \\<equiv> \\<forall>R' s' n ev evs. ev # evs \\<in> tr p \\<longrightarrow>\nkeys R' s' n evs \\<subseteq> keys R' s' n (ev # evs)\"\n\nlemma monotonD [dest]: \"[| keys R' s' n (ev # evs) \\<subseteq> Ks; monoton p keys;\nev # evs \\<in> tr p |] ==> keys R' s' n evs \\<subseteq> Ks\"\nby (unfold monoton_def, blast)\n\nsubsection\\<open>guardedness theorem\\<close>\n\nlemma Guard_tr [rule_format]: \"[| evs \\<in> tr p; has_only_Says' p;\npreserv p keys n Ks; monoton p keys; Guard n Ks (initState Spy) |] ==>\nsafe Ks (spies evs) \\<longrightarrow> fresh p R' s' n Ks evs \\<longrightarrow> keys R' s' n evs \\<subseteq> Ks \\<longrightarrow>\nGuard n Ks (spies evs)\"\napply (erule tr.induct)\n(* Nil *)\napply simp\n(* Fake *)\napply (clarify, drule freshD, clarsimp)\napply (case_tac evs2)\n(* evs2 = [] *)\napply (frule has_only_Says'D, simp)\napply (clarsimp, blast)\n(* evs2 = aa # list *)\napply (clarsimp, rule conjI)\napply (blast dest: safe_insert)\n(* X:guard n Ks *)\napply (rule in_synth_Guard, simp, rule Guard_analz)\napply (blast dest: safe_insert)\napply (drule safe_insert, simp add: safe_def)\n(* Proto *)\napply (clarify, drule freshD, clarify)\napply (case_tac evs2)\n(* evs2 = [] *)\napply (frule has_only_Says'D, simp)\napply (frule_tac R=R' in has_only_Says'D, simp)\napply (case_tac R', clarsimp, blast)\n(* evs2 = ab # list *)\napply (frule has_only_Says'D, simp)\napply (clarsimp, rule conjI)\napply (drule Proto, simp+, blast dest: safe_insert)\n(* apm s X:guard n Ks *)\napply (frule Proto, simp+)\napply (erule preservD', simp+)\napply (blast dest: safe_insert)\napply (blast dest: safe_insert)\nby (blast, simp, simp, blast)\n\nsubsection\\<open>useful properties for guardedness\\<close>\n\nlemma newn_neq_used: \"[| Nonce n \\<in> used evs; ok evs R s; k \\<in> newn R |]\n==> n \\<noteq> nonce s k\"\nby (auto simp: ok_def)\n\nlemma ok_Guard: \"[| ok evs R s; Guard n Ks (spies evs); x \\<in> fst R; is_Says x |]\n==> apm s (msg x) \\<in> parts (spies evs) \\<and> apm s (msg x) \\<in> guard n Ks\"\napply (unfold ok_def is_Says_def, clarify)\napply (drule_tac x=\"Says A B X\" in spec, simp)\nby (drule Says_imp_spies, auto intro: parts_parts)\n\nlemma ok_parts_not_new: \"[| Y \\<in> parts (spies evs); Nonce (nonce s n) \\<in> parts {Y};\nok evs R s |] ==> n \\<notin> newn R\"\nby (auto simp: ok_def dest: not_used_not_spied parts_parts)\n\nsubsection\\<open>unicity\\<close>\n\ndefinition uniq :: \"proto \\<Rightarrow> secfun \\<Rightarrow> bool\" where\n\"uniq p secret \\<equiv> \\<forall>evs R R' n n' Ks s s'. R \\<in> p \\<longrightarrow> R' \\<in> p \\<longrightarrow>\nn \\<in> newn R \\<longrightarrow> n' \\<in> newn R' \\<longrightarrow> nonce s n = nonce s' n' \\<longrightarrow>\nNonce (nonce s n) \\<in> parts {apm' s R} \\<longrightarrow> Nonce (nonce s n) \\<in> parts {apm' s' R'} \\<longrightarrow>\napm' s R \\<in> guard (nonce s n) Ks \\<longrightarrow> apm' s' R' \\<in> guard (nonce s n) Ks \\<longrightarrow>\nevs \\<in> tr p \\<longrightarrow> Nonce (nonce s n) \\<notin> analz (spies evs) \\<longrightarrow>\nsecret R n s Ks \\<in> parts (spies evs) \\<longrightarrow> secret R' n' s' Ks \\<in> parts (spies evs) \\<longrightarrow>\nsecret R n s Ks = secret R' n' s' Ks\"\n\nlemma uniqD: \"[| uniq p secret; evs \\<in> tr p; R \\<in> p; R' \\<in> p; n \\<in> newn R; n' \\<in> newn R';\nnonce s n = nonce s' n'; Nonce (nonce s n) \\<notin> analz (spies evs);\nNonce (nonce s n) \\<in> parts {apm' s R}; Nonce (nonce s n) \\<in> parts {apm' s' R'};\nsecret R n s Ks \\<in> parts (spies evs); secret R' n' s' Ks \\<in> parts (spies evs);\napm' s R \\<in> guard (nonce s n) Ks; apm' s' R' \\<in> guard (nonce s n) Ks |] ==>\nsecret R n s Ks = secret R' n' s' Ks\"\nby (unfold uniq_def, blast)\n\ndefinition ord :: \"proto \\<Rightarrow> (rule \\<Rightarrow> rule \\<Rightarrow> bool) \\<Rightarrow> bool\" where\n\"ord p inff \\<equiv> \\<forall>R R'. R \\<in> p \\<longrightarrow> R' \\<in> p \\<longrightarrow> \\<not> inff R R' \\<longrightarrow> inff R' R\"\n\nlemma ordD: \"[| ord p inff; \\<not> inff R R'; R \\<in> p; R' \\<in> p |] ==> inff R' R\"\nby (unfold ord_def, blast)\n\ndefinition uniq' :: \"proto \\<Rightarrow> (rule \\<Rightarrow> rule \\<Rightarrow> bool) \\<Rightarrow> secfun \\<Rightarrow> bool\" where\n\"uniq' p inff secret \\<equiv> \\<forall>evs R R' n n' Ks s s'. R \\<in> p \\<longrightarrow> R' \\<in> p \\<longrightarrow>\ninff R R' \\<longrightarrow> n \\<in> newn R \\<longrightarrow> n' \\<in> newn R' \\<longrightarrow> nonce s n = nonce s' n' \\<longrightarrow>\nNonce (nonce s n) \\<in> parts {apm' s R} \\<longrightarrow> Nonce (nonce s n) \\<in> parts {apm' s' R'} \\<longrightarrow>\napm' s R \\<in> guard (nonce s n) Ks \\<longrightarrow> apm' s' R' \\<in> guard (nonce s n) Ks \\<longrightarrow>\nevs \\<in> tr p \\<longrightarrow> Nonce (nonce s n) \\<notin> analz (spies evs) \\<longrightarrow>\nsecret R n s Ks \\<in> parts (spies evs) \\<longrightarrow> secret R' n' s' Ks \\<in> parts (spies evs) \\<longrightarrow>\nsecret R n s Ks = secret R' n' s' Ks\"\n\nlemma uniq'D: \"[| uniq' p inff secret; evs \\<in> tr p; inff R R'; R \\<in> p; R' \\<in> p; n \\<in> newn R;\nn' \\<in> newn R'; nonce s n = nonce s' n'; Nonce (nonce s n) \\<notin> analz (spies evs);\nNonce (nonce s n) \\<in> parts {apm' s R}; Nonce (nonce s n) \\<in> parts {apm' s' R'};\nsecret R n s Ks \\<in> parts (spies evs); secret R' n' s' Ks \\<in> parts (spies evs);\napm' s R \\<in> guard (nonce s n) Ks; apm' s' R' \\<in> guard (nonce s n) Ks |] ==>\nsecret R n s Ks = secret R' n' s' Ks\"\nby (unfold uniq'_def, blast)\n\nlemma uniq'_imp_uniq: \"[| uniq' p inff secret; ord p inff |] ==> uniq p secret\"\napply (unfold uniq_def)\napply (rule allI)+\napply (case_tac \"inff R R'\")\napply (blast dest: uniq'D)\nby (auto dest: ordD uniq'D intro: sym)\n\nsubsection\\<open>Needham-Schroeder-Lowe\\<close>\n\ndefinition a :: agent where \"a == Friend 0\"\ndefinition b :: agent where \"b == Friend 1\"\ndefinition a' :: agent where \"a' == Friend 2\"\ndefinition b' :: agent where \"b' == Friend 3\"\ndefinition Na :: nat where \"Na == 0\"\ndefinition Nb :: nat where \"Nb == 1\"\n\nabbreviation\n  ns1 :: rule where\n  \"ns1 == ({}, Says a b (Crypt (pubK b) \\<lbrace>Nonce Na, Agent a\\<rbrace>))\"\n\nabbreviation\n  ns2 :: rule where\n  \"ns2 == ({Says a' b (Crypt (pubK b) \\<lbrace>Nonce Na, Agent a\\<rbrace>)},\n    Says b a (Crypt (pubK a) \\<lbrace>Nonce Na, Nonce Nb, Agent b\\<rbrace>))\"\n\nabbreviation\n  ns3 :: rule where\n  \"ns3 == ({Says a b (Crypt (pubK b) \\<lbrace>Nonce Na, Agent a\\<rbrace>),\n    Says b' a (Crypt (pubK a) \\<lbrace>Nonce Na, Nonce Nb, Agent b\\<rbrace>)},\n    Says a b (Crypt (pubK b) (Nonce Nb)))\"\n\ninductive_set ns :: proto where\n  [iff]: \"ns1 \\<in> ns\"\n| [iff]: \"ns2 \\<in> ns\"\n| [iff]: \"ns3 \\<in> ns\"\n\nabbreviation (input)\n  ns3a :: event where\n  \"ns3a == Says a b (Crypt (pubK b) \\<lbrace>Nonce Na, Agent a\\<rbrace>)\"\n\nabbreviation (input)\n  ns3b :: event where\n  \"ns3b == Says b' a (Crypt (pubK a) \\<lbrace>Nonce Na, Nonce Nb, Agent b\\<rbrace>)\"\n\ndefinition keys :: \"keyfun\" where\n\"keys R' s' n evs == {priK' s' a, priK' s' b}\"\n\nlemma \"monoton ns keys\"\nby (simp add: keys_def monoton_def)\n\ndefinition secret :: \"secfun\" where\n\"secret R n s Ks ==\n(if R=ns1 then apm s (Crypt (pubK b) \\<lbrace>Nonce Na, Agent a\\<rbrace>)\nelse if R=ns2 then apm s (Crypt (pubK a) \\<lbrace>Nonce Na, Nonce Nb, Agent b\\<rbrace>)\nelse Number 0)\"\n\ndefinition inf :: \"rule => rule => bool\" where\n\"inf R R' == (R=ns1 | (R=ns2 & R'~=ns1) | (R=ns3 & R'=ns3))\"\n\nlemma inf_is_ord [iff]: \"ord ns inf\"\napply (unfold ord_def inf_def)\napply (rule allI)+\napply (rule impI)\napply (simp add: split_paired_all)\nby (rule impI, erule ns.cases, simp_all)+\n\nsubsection\\<open>general properties\\<close>\n\nlemma ns_has_only_Says' [iff]: \"has_only_Says' ns\"\napply (unfold has_only_Says'_def)\napply (rule allI, rule impI)\napply (simp add: split_paired_all)\nby (erule ns.cases, auto)\n\nlemma newn_ns1 [iff]: \"newn ns1 = {Na}\"\nby (simp add: newn_def)\n\nlemma newn_ns2 [iff]: \"newn ns2 = {Nb}\"\nby (auto simp: newn_def Na_def Nb_def)\n\nlemma newn_ns3 [iff]: \"newn ns3 = {}\"\nby (auto simp: newn_def)\n\nlemma ns_wdef [iff]: \"wdef ns\"\nby (auto simp: wdef_def elim: ns.cases)\n\nsubsection\\<open>guardedness for NSL\\<close>\n\nlemma \"uniq ns secret ==> preserv ns keys n Ks\"\napply (unfold preserv_def)\napply (rule allI)+\napply (rule impI, rule impI, rule impI, rule impI, rule impI)\napply (erule fresh_ruleD, simp, simp, simp, simp)\napply (rule allI)+\napply (rule impI, rule impI, rule impI)\napply (simp add: split_paired_all)\napply (erule ns.cases)\n(* fresh with NS1 *)\napply (rule impI, rule impI, rule impI, rule impI, rule impI, rule impI)\napply (erule ns.cases)\n(* NS1 *)\napply clarsimp\napply (frule newn_neq_used, simp, simp)\napply (rule No_Nonce, simp)\n(* NS2 *)\napply clarsimp\napply (frule newn_neq_used, simp, simp)\napply (case_tac \"nonce sa Na = nonce s Na\")\napply (frule Guard_safe, simp)\napply (frule Crypt_guard_invKey, simp)\napply (frule ok_Guard, simp, simp, simp, clarsimp)\napply (frule_tac K=\"pubK' s b\" in Crypt_guard_invKey, simp)\napply (frule_tac R=ns1 and R'=ns1 and Ks=Ks and s=sa and s'=s in uniqD, simp+)\napply (simp add: secret_def, simp add: secret_def, force, force)\napply (simp add: secret_def keys_def, blast)\napply (rule No_Nonce, simp)\n(* NS3 *)\napply clarsimp\napply (case_tac \"nonce sa Na = nonce s Nb\")\napply (frule Guard_safe, simp)\napply (frule Crypt_guard_invKey, simp)\napply (frule_tac x=ns3b in ok_Guard, simp, simp, simp, clarsimp)\napply (frule_tac K=\"pubK' s a\" in Crypt_guard_invKey, simp)\napply (frule_tac R=ns1 and R'=ns2 and Ks=Ks and s=sa and s'=s in uniqD, simp+)\napply (simp add: secret_def, simp add: secret_def, force, force)\napply (simp add: secret_def, rule No_Nonce, simp)\n(* fresh with NS2 *)\napply (rule impI, rule impI, rule impI, rule impI, rule impI, rule impI)\napply (erule ns.cases)\n(* NS1 *)\napply clarsimp\napply (frule newn_neq_used, simp, simp)\napply (rule No_Nonce, simp)\n(* NS2 *)\napply clarsimp\napply (frule newn_neq_used, simp, simp)\napply (case_tac \"nonce sa Nb = nonce s Na\")\napply (frule Guard_safe, simp)\napply (frule Crypt_guard_invKey, simp)\napply (frule ok_Guard, simp, simp, simp, clarsimp)\napply (frule_tac K=\"pubK' s b\" in Crypt_guard_invKey, simp)\napply (frule_tac R=ns2 and R'=ns1 and Ks=Ks and s=sa and s'=s in uniqD, simp+)\napply (simp add: secret_def, simp add: secret_def, force, force)\napply (simp add: secret_def, rule No_Nonce, simp)\n(* NS3 *)\napply clarsimp\napply (case_tac \"nonce sa Nb = nonce s Nb\")\napply (frule Guard_safe, simp)\napply (frule Crypt_guard_invKey, simp)\napply (frule_tac x=ns3b in ok_Guard, simp, simp, simp, clarsimp)\napply (frule_tac K=\"pubK' s a\" in Crypt_guard_invKey, simp)\napply (frule_tac R=ns2 and R'=ns2 and Ks=Ks and s=sa and s'=s in uniqD, simp+)\napply (simp add: secret_def, simp add: secret_def, force, force)\napply (simp add: secret_def keys_def, blast)\napply (rule No_Nonce, simp)\n(* fresh with NS3 *)\nby simp\n\nsubsection\\<open>unicity for NSL\\<close>\n\nlemma \"uniq' ns inf secret\"\napply (unfold uniq'_def)\napply (rule allI)+\napply (simp add: split_paired_all)\napply (rule impI, erule ns.cases)\n(* R = ns1 *)\napply (rule impI, erule ns.cases)\n(* R' = ns1 *)\napply (rule impI, rule impI, rule impI, rule impI)\napply (rule impI, rule impI, rule impI, rule impI)\napply (rule impI, erule tr.induct)\n(* Nil *)\napply (simp add: secret_def)\n(* Fake *)\napply (clarify, simp add: secret_def)\napply (drule notin_analz_insert)\napply (drule Crypt_insert_synth, simp, simp, simp)\napply (drule Crypt_insert_synth, simp, simp, simp, simp)\n(* Proto *)\napply (erule_tac P=\"ok evsa R sa\" in rev_mp)\napply (simp add: split_paired_all)\napply (erule ns.cases)\n(* ns1 *)\napply (clarify, simp add: secret_def)\napply (erule disjE, erule disjE, clarsimp)\napply (drule ok_parts_not_new, simp, simp, simp)\napply (clarify, drule ok_parts_not_new, simp, simp, simp)\n(* ns2 *)\napply (simp add: secret_def)\n(* ns3 *)\napply (simp add: secret_def)\n(* R' = ns2 *)\napply (rule impI, rule impI, rule impI, rule impI)\napply (rule impI, rule impI, rule impI, rule impI)\napply (rule impI, erule tr.induct)\n(* Nil *)\napply (simp add: secret_def)\n(* Fake *)\napply (clarify, simp add: secret_def)\napply (drule notin_analz_insert)\napply (drule Crypt_insert_synth, simp, simp, simp)\napply (drule_tac n=\"nonce s' Nb\" in Crypt_insert_synth, simp, simp, simp, simp)\n(* Proto *)\napply (erule_tac P=\"ok evsa R sa\" in rev_mp)\napply (simp add: split_paired_all)\napply (erule ns.cases)\n(* ns1 *)\napply (clarify, simp add: secret_def)\napply (drule_tac s=sa and n=Na in ok_parts_not_new, simp, simp, simp)\n(* ns2 *)\napply (clarify, simp add: secret_def)\napply (drule_tac s=sa and n=Nb in ok_parts_not_new, simp, simp, simp)\n(* ns3 *)\napply (simp add: secret_def)\n(* R' = ns3 *)\napply simp\n(* R = ns2 *)\napply (rule impI, erule ns.cases)\n(* R' = ns1 *)\napply (simp only: inf_def, blast)\n(* R' = ns2 *)\napply (rule impI, rule impI, rule impI, rule impI)\napply (rule impI, rule impI, rule impI, rule impI)\napply (rule impI, erule tr.induct)\n(* Nil *)\napply (simp add: secret_def)\n(* Fake *)\napply (clarify, simp add: secret_def)\napply (drule notin_analz_insert)\napply (drule_tac n=\"nonce s' Nb\" in Crypt_insert_synth, simp, simp, simp)\napply (drule_tac n=\"nonce s' Nb\" in Crypt_insert_synth, simp, simp, simp, simp)\n(* Proto *)\napply (erule_tac P=\"ok evsa R sa\" in rev_mp)\napply (simp add: split_paired_all)\napply (erule ns.cases)\n(* ns1 *)\napply (simp add: secret_def)\n(* ns2 *)\napply (clarify, simp add: secret_def)\napply (erule disjE, erule disjE, clarsimp, clarsimp)\napply (drule_tac s=sa and n=Nb in ok_parts_not_new, simp, simp, simp)\napply (erule disjE, clarsimp)\napply (drule_tac s=sa and n=Nb in ok_parts_not_new, simp, simp, simp)\nby (simp_all add: secret_def)\n\nend\n", "meta": {"author": "m-fleury", "repo": "isabelle-emacs", "sha": "756c662195e138a1941d22d4dd7ff759cbf6b6b9", "save_path": "github-repos/isabelle/m-fleury-isabelle-emacs", "path": "github-repos/isabelle/m-fleury-isabelle-emacs/isabelle-emacs-756c662195e138a1941d22d4dd7ff759cbf6b6b9/src/HOL/Auth/Guard/Proto.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.5, "lm_q1q2_score": 0.26949161034384206}}
{"text": "theory RB\nimports LTS ArcExt SubExt\nbegin\n\nsection \\<open>Red-Black Graphs\\<close>\n\ntext \\<open>In this section we define red\\hyp{}black graphs and the five operators that perform over \nthem. Then, we state and prove a number of intermediate lemmas about red\\hyp{}black graphs \nbuilt using only these five operators, in other words: invariants about our method of transformation \nof red\\hyp{}black graphs.\n\nThen, we define the notion of red\\hyp{}black paths and state and prove the main properties of our \nmethod, namely its correctness and the fact that it preserves the set of feasible paths of the \nprogram under analysis.\\<close>\n\nsubsection \\<open>Basic Definitions\\<close>\n\nsubsubsection \\<open>The type of Red-Black Graphs\\<close>\n\ntext \\<open>We represent red-black graph with the following record. We detail its fields:\n\\begin{itemize}\n  \\item @{term \"red\"} is the red graph, called \\emph{red part}, which represents the unfolding of \nthe black part. Its vertices are indexed black vertices,\n  \\item @{term \"black\"} is the original LTS, the \\emph{black part},\n  \\item @{term \"subs\"} is the subsumption relation over the vertices of @{term \"red\"},\n  \\item @{term \"init_conf\"} is the initial configuration,\n  \\item @{term \"confs\"} is a function associating configurations to the vertices of @{term \"red\"},\n  \\item @{term \"marked\"} is a function associating truth values to the vertices of @{term \"red\"}. \nWe use it to represent the fact that a particular configuration (associated to a red location) is \nknown to be unsatisfiable,\n  \\item @{term \"strengthenings\"} is a function associating boolean expressions over program \nvariables to vertices of the red graph. Those boolean expressions can be seen as invariants that \nthe configuration associated to the ``strengthened'' red vertex has to model.\n\\end{itemize}\n\nWe are only interested by red-black graphs obtained by the inductive relation \n@{term \"RedBlack\"}. From now on, we call ``red-black graphs\" the @{term pre_RedBlack}'s \nobtained by @{term \"RedBlack\"} and ``pre-red-black graphs\" all other ones.\\<close>\n\nrecord ('vert,'var,'d) pre_RedBlack =\n  red            :: \"('vert \\<times> nat) rgraph\"\n  black          :: \"('vert,'var,'d) lts\"\n  subs           :: \"'vert sub_rel_t\"\n  init_conf      :: \"('var,'d) conf\"\n  confs          :: \"('vert \\<times> nat) \\<Rightarrow> ('var,'d) conf\"\n  marked         :: \"('vert \\<times> nat) \\<Rightarrow> bool\"\n  strengthenings :: \"('vert \\<times> nat) \\<Rightarrow> ('var,'d) bexp\"\n\n\ntext\\<open>We call \\emph{red vertices} the set of vertices of the red graph.\\<close>\n\n\nabbreviation red_vertices :: \n  \"('vert,'var,'d,'x) pre_RedBlack_scheme \\<Rightarrow> ('vert \\<times> nat) set\" \nwhere\n  \"red_vertices lts \\<equiv> Graph.vertices (red lts)\"\n\n\ntext\\<open>@{term \"ui_edge\"} is the operation of ``unindexing'' the ends of a red edge, thus giving the \ncorresponding black edge.\\<close>\n\n\nabbreviation ui_edge :: \n  \"('vert \\<times> nat) edge \\<Rightarrow> 'vert edge\" \nwhere\n  \"ui_edge e \\<equiv> \\<lparr> src = fst (src e), tgt = fst (tgt e) \\<rparr>\"\n\n\ntext \\<open>We extend this idea to sequences of edges.\\<close>\n\n\nabbreviation ui_es ::\n  \"('vert \\<times> nat) edge list \\<Rightarrow> 'vert edge list\"\nwhere\n  \"ui_es es \\<equiv> map ui_edge es\"\n\n\n\nsubsubsection \\<open>Well-formed and finite red-black graphs\\<close>\n\nlocale pre_RedBlack =\n  fixes prb :: \"('vert,'var,'d) pre_RedBlack\" (structure)\n\n\ntext \\<open>A pre-red-black graph is well-formed if :\n\\begin{itemize}\n  \\item its red and black parts are well-formed,\n  \\item the root of its red part is an indexed version of the root of its black part,\n  \\item all red edges are indexed versions of black edges. \n\\end{itemize}\\<close>\n\nlocale wf_pre_RedBlack = pre_RedBlack +\n  assumes red_wf           : \"wf_rgraph (red prb)\"\n  assumes black_wf         : \"wf_lts (black prb)\"\n  assumes consistent_roots : \"fst (root (red prb)) = root (black prb)\"\n  assumes ui_re_are_be     : \"e \\<in> edges (red prb) \\<Longrightarrow> ui_edge e \\<in> edges (black prb)\"\nbegin\n  lemmas wf_pre_RedBlack = red_wf black_wf consistent_roots ui_re_are_be\nend\n\n\ntext\\<open>We say that a pre-red-black graph is finite if :\n\\begin{itemize}\n  \\item the path predicate of its initial configuration contains a finite number of constraints,\n  \\item each of these constraints contains a finite number of variables,\n  \\item its black part is finite (cf. definition of @{term \"finite_lts\"}.).\n\\end{itemize}\\<close>\n\n\nlocale finite_RedBlack = pre_RedBlack +\n  assumes finite_init_pred         : \"finite (pred (init_conf prb))\"\n  assumes finite_init_pred_symvars : \"\\<forall> e \\<in> pred (init_conf prb). finite (Bexp.vars e)\"\n  assumes finite_lts               : \"finite_lts (black prb)\"\nbegin\n  lemmas finite_RedBlack = finite_init_pred finite_init_pred_symvars finite_lts\nend\n\n\n\n\n\n\nsubsection \\<open>Extensions of Red-Black Graphs\\<close>\n\ntext \\<open>We now define the five basic operations that can be performed over red-black graphs. Since \nwe do not want to model the heuristics part of our prototype, a number of conditions must be met \nfor each operator to apply. For example, in our prototype abstractions are performed at nodes that \nactually have successors, and these abstractions must be propagated to these successors in order to \nkeep the symbolic execution graph consistent. Propagation is a complex task, and it is hard to model \nin Isabelle/HOL. This is partially due to the fact that we model the red part as a graph, in which \npropagation might not terminate. Instead, we suppose that abstraction must be performed only at \nleaves of the red part. This is equivalent to implicitly assume the existence of an oracle that \nwould tell that we will need to abstract some red vertex and how to abstract it, as soon as this red \nvertex is added to the red part.\\<close>\n\ntext \\<open>As in the previous theories, we use predicates instead of functions to model these \ntransformations to ease writing and reading definitions, proofs, etc.\\<close>\n\nsubsubsection \\<open>Extension by symbolic execution\\<close>\n\ntext\\<open>The core abstract operation of symbolic execution: take a black edge and\nturn it red, by symbolic execution of its label. In the following abbreviation, @{term re} is the \nred edge obtained from the (hypothetical) black edge @{term e} that we want to symbolically execute \nand @{term c} the configuration obtained by symbolic execution of the label of @{term e}. Note that \nthis extension could have been defined as a \npredicate that takes only two @{term pre_RedBlack}s and evaluates to \\emph{true} if and only if \nthe second has been obtained by adding a red edge as a result of symbolic execution. However, \nmaking the red edge and the configuration explicit allows for lighter definitions, lemmas and proofs \nin the following.\\<close>\n\nabbreviation se_extends :: \n  \"('vert,'var,'d) pre_RedBlack \n   \\<Rightarrow> ('vert \\<times> nat) edge \n   \\<Rightarrow> ('var,'d) conf \n   \\<Rightarrow> ('vert,'var,'d) pre_RedBlack \\<Rightarrow> bool\"\nwhere\n  \"se_extends prb re c prb' \\<equiv> \n     ui_edge re \\<in> edges (black prb) \n   \\<and> ArcExt.extends (red prb) re (red prb') \n   \\<and> src re \\<notin> subsumees (subs prb)\n   \\<and> se  (confs prb (src re)) (labelling (black prb) (ui_edge re)) c\n   \\<and> prb' = \\<lparr> red       = red prb',\n              black     = black prb,\n              subs      = subs prb,\n              init_conf = init_conf prb,\n              confs     = (confs prb) (tgt re := c),\n              marked    = (marked prb)(tgt re := marked prb (src re)),\n              strengthenings = strengthenings prb \\<rparr>\"\n\n\ntext \\<open>Hiding the new red edge (using an existential quantifier) and the new configuration makes \nthe following abbreviation more \nintuitive. However, this would require using \\verb?obtain? or \\verb?let ... = ... in ...? constructs \nin the following lemmas and proofs, making them harder to read and write.\\<close>\n\nabbreviation se_extends2 :: \n  \"('vert,'var,'d) pre_RedBlack \\<Rightarrow> ('vert,'var,'d) pre_RedBlack \\<Rightarrow> bool\"\nwhere\n  \"se_extends2 prb prb' \\<equiv> \n   \\<exists> re \\<in> edges (red prb'). \n     ui_edge re \\<in> edges (black prb)\n   \\<and> ArcExt.extends (red prb) re (red prb') \n   \\<and> src re \\<notin> subsumees (subs prb)\n   \\<and> se (confs prb (src re)) (labelling (black prb) (ui_edge re)) (confs prb' (tgt re))\n   \\<and> black prb' = black prb\n   \\<and> subs prb'  = subs prb\n   \\<and> init_conf prb' = init_conf prb\n   \\<and> confs prb' = (confs prb) (tgt re := confs prb' (tgt re))\n   \\<and> marked prb' = (marked prb)(tgt re := marked prb (src re))\n   \\<and> strengthenings prb' = strengthenings prb\"\n\n\nsubsubsection \\<open>Extension by marking\\<close>\n\ntext\\<open>The abstract operation of mark-as-unsat. It manages the information\n- provided, for example, by an external automated prover -, that the \nconfiguration of the red vertex @{term rv} has been proved unsatisfiable.\\<close>\n\nabbreviation mark_extends ::\n  \"('vert,'var,'d) pre_RedBlack \\<Rightarrow> ('vert \\<times> nat) \\<Rightarrow> ('vert,'var,'d) pre_RedBlack \\<Rightarrow> bool\"\nwhere\n  \"mark_extends prb rv prb' \\<equiv>  \n     rv \\<in> red_vertices prb\n   \\<and> out_edges (red prb) rv = {}\n   \\<and> rv \\<notin> subsumees (subs prb)\n   \\<and> rv \\<notin> subsumers (subs prb)\n   \\<and> \\<not> sat (confs prb rv)\n   \\<and> prb' = \\<lparr> red       = red prb,\n              black     = black prb,\n              subs      = subs prb,\n              init_conf = init_conf prb,\n              confs     = confs prb,\n              marked    = (\\<lambda> rv'. if rv' = rv then True else marked prb rv'),\n              strengthenings = strengthenings prb,\n              \\<dots>        = more prb \\<rparr> \"\n\n\nsubsubsection \\<open>Extension by subsumption\\<close>\n\ntext\\<open>The abstract operation of introducing a subsumption link.\\<close>\n\nabbreviation subsum_extends ::\n  \"('vert,'var,'d) pre_RedBlack \\<Rightarrow> 'vert sub_t \\<Rightarrow> ('vert,'var,'d) pre_RedBlack \\<Rightarrow> bool\"\nwhere\n  \"subsum_extends prb sub prb' \\<equiv>\n     SubExt.extends (red prb) (subs prb) sub (subs prb')\n   \\<and> \\<not> marked prb (subsumer sub)\n   \\<and> \\<not> marked prb (subsumee sub)\n   \\<and> confs prb (subsumee sub) \\<sqsubseteq> confs prb (subsumer sub)\n   \\<and> prb' = \\<lparr> red       = red prb,\n              black     = black prb,\n              subs      = insert sub (subs prb),\n              init_conf = init_conf prb,\n              confs     = confs prb,\n              marked    = marked prb,\n              strengthenings = strengthenings prb,\n              \\<dots>        = more prb \\<rparr>\"\n\n\nsubsubsection \\<open>Extension by abstraction\\<close>\n\ntext\\<open>This operation replaces the configuration of a red vertex @{term rv} by an abstraction of \nthis configuration. The way the abstraction is computed is not specified. However, besides a number \nof side conditions, it must subsume the former configuration of @{term rv} and must entail its \nsafeguard condition, if any.\\<close>\n\nabbreviation abstract_extends ::\n  \"('vert,'var,'d) pre_RedBlack \n    \\<Rightarrow> ('vert \\<times> nat) \n    \\<Rightarrow> ('var,'d) conf \n    \\<Rightarrow> ('vert,'var,'d) pre_RedBlack \n    \\<Rightarrow> bool\"\nwhere\n  \"abstract_extends prb rv c\\<^sub>a prb' \\<equiv> \n     rv \\<in> red_vertices prb\n   \\<and> \\<not> marked prb rv  \n   \\<and> out_edges (red prb) rv = {} \n   \\<and> rv \\<notin> subsumees (subs prb)\n   \\<and> abstract (confs prb rv) c\\<^sub>a\n   \\<and> c\\<^sub>a \\<Turnstile>\\<^sub>c (strengthenings prb rv)\n   \\<and> finite (pred c\\<^sub>a)\n   \\<and> (\\<forall> e \\<in> pred c\\<^sub>a. finite (vars e))\n   \\<and> prb' =  \\<lparr> red       = red prb, \n               black     = black prb, \n               subs      = subs prb, \n               init_conf = init_conf prb,\n               confs     = (confs prb)(rv := c\\<^sub>a),\n               marked    = marked prb,\n               strengthenings = strengthenings prb,\n               \\<dots>        = more prb \\<rparr>\"\n      \n\nsubsubsection \\<open>Extension by strengthening\\<close>\n\ntext \\<open>This operation consists in labeling a red vertex with a safeguard condition. It does not \nactually change the red part, but model the mechanism of preventing too crude abstractions.\\<close>\n\nabbreviation strengthen_extends ::\n  \"('vert,'var,'d) pre_RedBlack \n   \\<Rightarrow> ('vert \\<times> nat) \n   \\<Rightarrow> ('var,'d) bexp \n   \\<Rightarrow> ('vert,'var,'d) pre_RedBlack \n   \\<Rightarrow> bool\"\nwhere\n  \"strengthen_extends prb rv e prb' \\<equiv>  \n     rv \\<in> red_vertices prb\n   \\<and> rv \\<notin> subsumees (subs prb)\n   \\<and> confs prb rv \\<Turnstile>\\<^sub>c e\n   \\<and> prb' =  \\<lparr> red       = red prb, \n               black     = black prb, \n               subs      = subs prb, \n               init_conf = init_conf prb,\n               confs     = confs prb,\n               marked    = marked prb,\n               strengthenings = (strengthenings prb)(rv := (\\<lambda> \\<sigma>. (strengthenings prb rv) \\<sigma> \\<and> e \\<sigma>)),\n               \\<dots>        = more prb \\<rparr>\"\n\n\n\nsubsection \\<open>Building Red-Black Graphs using Extensions\\<close>\n\n\ntext\\<open>Red-black graphs are pre-red-black graphs built with the following inductive relation, i.e.\\ \nusing only the five previous pre-red-black graphs transformation operators, starting from an \nempty red part.\\<close>\n\ninductive RedBlack ::\n  \"('vert,'var,'d) pre_RedBlack \\<Rightarrow> bool\"\nwhere\n  base : \n    \"fst (root (red prb)) = init (black prb)      \\<Longrightarrow>\n     edges (red prb) = {}                         \\<Longrightarrow>\n     subs prb = {}                                \\<Longrightarrow>\n     (confs prb) (root (red prb)) = init_conf prb \\<Longrightarrow>\n     marked prb = (\\<lambda> rv. False)                   \\<Longrightarrow> \n     strengthenings prb = (\\<lambda> rv. (\\<lambda> \\<sigma>. True))     \\<Longrightarrow> RedBlack prb\"\n\n| se_step : \n    \"RedBlack prb                                 \\<Longrightarrow>\n     se_extends prb re p' prb'                    \\<Longrightarrow> RedBlack prb'\"\n\n| mark_step : \n    \"RedBlack prb                                 \\<Longrightarrow>\n     mark_extends prb rv prb'                     \\<Longrightarrow> RedBlack prb'\"\n                                                 \n| subsum_step :                                  \n    \"RedBlack prb                                 \\<Longrightarrow>\n     subsum_extends prb sub prb'                  \\<Longrightarrow> RedBlack prb'\"\n                                                 \n| abstract_step :                                \n    \"RedBlack prb                                 \\<Longrightarrow> \n     abstract_extends prb rv c\\<^sub>a prb'             \\<Longrightarrow> RedBlack prb'\"\n\n| strengthen_step :\n    \"RedBlack prb                                 \\<Longrightarrow> \n     strengthen_extends prb rv e prb'             \\<Longrightarrow> RedBlack prb'\"\n\n\nsubsection \\<open>Properties of Red-Black-Graphs\\<close>\n\nsubsubsection\\<open>Invariants of the Red\\hyp{}Black Graphs\\<close>\n\n\ntext\\<open>The red part of a red-black graph is loop free.\\<close>\n\nlemma\n  assumes \"RedBlack prb\"\n  shows   \"loop_free (red prb)\"\nusing assms by (induct prb) auto\n\n\ntext\\<open>A red edge can not lead to the (red) root.\\<close>\n\n\nlemma \n  assumes \"RedBlack prb\"\n  assumes \"re \\<in> edges (red prb)\"\n  shows   \"tgt re \\<noteq> root (red prb)\"\nusing assms by (induct prb) (auto simp add : vertices_def)\n\n\ntext\\<open>Red edges are specific versions of black edges.\\<close>\n\nlemma ui_re_is_be :\n  assumes \"RedBlack prb\"\n  assumes \"re \\<in> edges (red prb)\"\n  shows   \"ui_edge re \\<in> edges (black prb)\"\nusing assms by (induct rule : RedBlack.induct) auto\n\n\ntext\\<open>The set of out-going edges from a red vertex is a subset of the set of out-going edges from \nthe black location it represents.\\<close>\n\nlemma red_OA_subset_black_OA :\n  assumes \"RedBlack prb\"\n  shows   \"ui_edge ` out_edges (red prb) rv \\<subseteq> out_edges (black prb) (fst rv)\"\nusing assms by (induct prb) (fastforce simp add : vertices_def)+\n\n\ntext \\<open>The red root is an indexed version of the black initial location.\\<close>\n\nlemma consistent_roots :\n  assumes \"RedBlack prb\"\n  shows   \"fst (root (red prb)) = init (black prb)\"\nusing assms by (induct prb) auto\n\n\n\ntext\\<open>The red part of a red-black graph is a tree.\\<close>\n\nlemma \n  assumes \"RedBlack prb\"\n  shows   \"is_tree (red prb)\"\nusing assms \nby (induct prb) (auto simp add : empty_graph_is_tree ArcExt.extends_is_tree)\n\n \ntext \\<open>A red-black graph whose black part is well-formed is also well-formed.\\<close>\n\nlemma\n  assumes \"RedBlack prb\"\n  assumes \"wf_lts (black prb)\"\n  shows   \"wf_pre_RedBlack prb\"\nproof -\n  have \"wf_rgraph (red prb)\"\n       using assms by (induct prb) (force simp add : vertices_def)+\n\n  thus ?thesis \n       using assms consistent_roots ui_re_is_be \n       by (auto simp add : wf_pre_RedBlack_def)\nqed\n\n\ntext \\<open>Red locations of a red-black graph are indexed versions of its black locations.\\<close>\n\nlemma ui_rv_is_bv :\n  assumes \"RedBlack prb\"\n  assumes \"rv \\<in> red_vertices prb\"\n  shows   \"fst rv \\<in> Graph.vertices (black prb)\"\nusing assms consistent_roots ui_re_is_be \nby (auto simp add : vertices_def image_def Bex_def) fastforce+\n\n\n\ntext \\<open>The subsumption of a red-black graph is a sub-relation of its red part.\\<close>\n\nlemma subs_sub_rel_of :\n  assumes \"RedBlack prb\"\n  shows   \"sub_rel_of (red prb) (subs prb)\"\nusing assms unfolding sub_rel_of_def\nproof (induct prb)\n  case base thus ?case by simp\nnext\n  case se_step thus ?case by (elim conjE) (auto simp add : vertices_def)\nnext \n  case mark_step thus ?case by auto\nnext\n  case subsum_step thus ?case by auto\nnext\n  case abstract_step thus ?case by simp\nnext\n  case strengthen_step thus ?case by simp\nqed\n\n\n\ntext\\<open>The subsumption relation of red-black graph is well-formed.\\<close>\n\nlemma subs_wf_sub_rel :\n  assumes \"RedBlack prb\"\n  shows   \"wf_sub_rel (subs prb)\"\nusing assms\nproof (induct prb)\n  case base thus ?case by (simp add : wf_sub_rel_def)\nnext\n  case se_step thus ?case by force\nnext\n  case mark_step thus ?case by (auto simp add : wf_sub_rel_def)\nnext\n  case subsum_step thus ?case by (auto simp add : wf_sub_rel.extends_imp_wf_sub_rel)\nnext\n  case abstract_step thus ?case by simp\nnext\n  case strengthen_step thus ?case by simp\nqed\n\n\ntext \\<open>Using the two previous lemmas, we have that the subsumption relation of a red-black graph \nis a well-formed sub-relation of its red-part.\\<close>\n\nlemma subs_wf_sub_rel_of :\n  assumes \"RedBlack prb\"\n  shows   \"wf_sub_rel_of (red prb) (subs prb)\"\nusing assms subs_sub_rel_of subs_wf_sub_rel by (simp add : wf_sub_rel_of_def) fast\n\n\ntext\\<open>Subsumptions only involve red locations representing the same black location.\\<close>\n\nlemma subs_to_same_BL :\n  assumes \"RedBlack prb\"\n  assumes \"sub \\<in> subs prb\"\n  shows   \"fst (subsumee sub) = fst (subsumer sub)\"\nusing assms subs_wf_sub_rel unfolding wf_sub_rel_def by fast\n\n\ntext\\<open>If a red edge sequence @{term \"res\"} is consistent between red locations @{term \"rv1\"} and \n@{term \"rv2\"} with respect to the subsumption relation of a red-black graph, then its unindexed \nversion is consistent between the black locations represented by @{term \"rv1\"} and @{term \"rv2\"}.\\<close>\n\nlemma rces_imp_bces :\n  assumes \"RedBlack prb\"\n  assumes \"SubRel.ces rv1 res rv2 (subs prb)\"                        \n  shows   \"Graph.ces (fst rv1) (ui_es res) (fst rv2)\"\nusing assms\nproof (induct res arbitrary : rv1)\n  case (Nil rv1) thus ?case \n  using wf_sub_rel.in_trancl_imp[OF subs_wf_sub_rel] subs_to_same_BL\n  by fastforce\nnext\n  case (Cons re res rv1)\n\n  hence 1 : \"rv1 = src re \\<or> (rv1, src re) \\<in> (subs prb)\\<^sup>+\"\n  and   2 : \"ces (tgt re) res rv2 (subs prb)\" by simp_all\n\n  have \"src (ui_edge re) = fst rv1\"\n        using 1  wf_sub_rel.in_trancl_imp[OF subs_wf_sub_rel[OF assms(1)], of rv1 \"src re\"]\n              subs_to_same_BL[OF assms(1), of \"(rv1,src re)\"]\n       by auto\n  \n  moreover \n  have \"Graph.ces (tgt (ui_edge re)) (ui_es res) (fst rv2)\" \n       using assms(1) Cons(1) 2 by simp\n\n  ultimately\n  show ?case by simp\nqed\n\n\ntext\\<open>The unindexed version of a subpath in the red part of a red-black graph is a subpath in its \nblack part. This is an important fact: in the end, it helps proving that set of paths we consider \nin red-black graphs are paths of the original LTS. Thus, the same states are computed along \nthese paths.\\<close>\n\ntheorem red_sp_imp_black_sp :\n  assumes \"RedBlack prb\"\n  assumes \"subpath (red prb) rv1 res rv2 (subs prb)\"\n  shows   \"Graph.subpath (black prb) (fst rv1) (ui_es res) (fst rv2)\"\nusing assms rces_imp_bces ui_rv_is_bv ui_re_is_be\nunfolding subpath_def Graph.subpath_def by (intro conjI) (fast, fast, fastforce)\n\n\ntext\\<open>Any constraint in the path predicate of a configuration associated to a red location of a \nred-black graph contains a finite number of variables.\\<close>\n\nlemma finite_pred_constr_symvars :\n  assumes \"RedBlack prb\"\n  assumes \"finite_RedBlack prb\"\n  assumes \"rv \\<in> red_vertices prb\"\n  shows   \"\\<forall> e \\<in> pred (confs prb rv). finite (Bexp.vars e)\"\nusing assms\nproof (induct prb arbitrary : rv)\n  case base thus ?case by (simp add : vertices_def finite_RedBlack_def)\nnext\n  case (se_step prb re c' prb') \n\n  hence \"rv \\<in> red_vertices prb \\<or> rv = tgt re\" by (auto simp add : vertices_def)\n  \n  thus ?case \n  proof (elim disjE)\n    assume \"rv \\<in> red_vertices prb\"\n\n    moreover\n    have \"finite_RedBlack prb\" \n         using se_step(3,4) by (auto simp add : finite_RedBlack_def)\n\n    ultimately\n    show ?thesis \n         using se_step(2,3) by (elim conjE) (auto simp add : vertices_def)\n  next\n    assume \"rv = tgt re\"\n\n    moreover\n    have \"finite_label (labelling (black prb) (ui_edge re))\"\n         using se_step by (auto simp add : finite_RedBlack_def)\n\n    moreover\n    have \"\\<forall> e \\<in> pred (confs prb (src re)). finite (Bexp.vars e)\"\n           using se_step se_step(2)[of \"src re\"] unfolding finite_RedBlack_def \n    by (elim conjE) auto\n\n    moreover\n    have \"se (confs prb (src re)) (labelling (black prb) (ui_edge re)) c'\"\n          using se_step by auto\n\n    ultimately\n    show ?thesis using se_step se_preserves_finiteness1 by fastforce\n  qed\nnext\n  case mark_step thus ?case by (simp add : finite_RedBlack_def)\nnext\n  case subsum_step thus ?case by (simp add : finite_RedBlack_def)\nnext\n  case abstract_step thus ?case by (auto simp add : finite_RedBlack_def)\nnext\n  case strengthen_step thus ?case by (simp add : finite_RedBlack_def)\nqed\n\n\ntext \\<open>The path predicate of a configuration associated to a red location of a \nred-black graph contains a finite number of constraints.\\<close>\n\nlemma finite_pred :\n  assumes \"RedBlack prb\"\n  assumes \"finite_RedBlack prb\"\n  assumes \"rv \\<in> red_vertices prb\"\n  shows   \"finite (pred (confs prb rv))\"\nusing assms\nproof (induct prb arbitrary : rv)\n  case base thus ?case by (simp add : vertices_def finite_RedBlack_def)\nnext\n  case (se_step prb re c' prb')\n\n  hence \"rv \\<in> red_vertices prb \\<or> rv = tgt re\" \n        by (auto simp add : vertices_def)\n\n  thus ?case \n  proof (elim disjE, goal_cases)\n    case 1 thus ?thesis \n         using se_step(2)[of rv] se_step(3,4) \n         by (auto simp add : finite_RedBlack_def)\n  next\n    case 2\n    moreover\n    hence \"src re \\<in> red_vertices prb\"\n    and   \"finite (pred (confs prb (src re)))\" \n          using se_step(2)[of \"src re\"] se_step(3,4) \n          by (auto simp add : finite_RedBlack_def)\n  \n    ultimately\n    show ?thesis\n         using se_step(3) se_preserves_finiteness2 by auto\n  qed\nnext\n  case mark_step thus ?case by (simp add : finite_RedBlack_def)\nnext\n  case subsum_step thus ?case by (simp add : finite_RedBlack_def)\nnext\n  case abstract_step thus ?case by (simp add : finite_RedBlack_def)\nnext\n  case strengthen_step thus ?case by (simp add : finite_RedBlack_def)\nqed\n\n\ntext\\<open>Hence, for a red location @{term \"rv\"} of a red-black graph and any label @{term \"l\"}, \nthere exists a configuration that can be obtained by symbolic execution of @{term \"l\"} from the \nconfiguration associated to @{term \"rv\"}.\\<close>\n\nlemma (in finite_RedBlack) ex_se_succ :\n  assumes \"RedBlack prb\"\n  assumes \"rv \\<in> red_vertices prb\"\n  shows   \"\\<exists> c'. se (confs prb rv) l c'\"\nusing finite_RedBlack assms \n      finite_imp_ex_se_succ[of \"confs prb rv\"]\n      finite_pred[of prb rv ]\n      finite_pred_constr_symvars[of prb rv]\nunfolding finite_RedBlack_def by fast\n\n\n\ntext\\<open>Generalization of the previous lemma to a list of labels.\\<close>\n\nlemma (in finite_RedBlack) ex_se_star_succ :\n  assumes \"RedBlack prb\"\n  assumes \"rv \\<in> red_vertices prb\"\n  assumes \"finite_labels ls\"\n  shows   \"\\<exists> c'. se_star (confs prb rv) ls c'\"\nusing finite_RedBlack assms \n      finite_imp_ex_se_star_succ[of \"confs prb rv\" ls]\n      finite_pred[OF assms(1), of rv] \n      finite_pred_constr_symvars[OF assms(1), of rv]\nunfolding finite_RedBlack_def by simp\n\n\ntext\\<open>Hence, for any red sub-path, there exists a configuration that can be obtained by symbolic \nexecution of its trace from the configuration associated to its source.\\<close>\n\nlemma (in finite_RedBlack) sp_imp_ex_se_star_succ :\n  assumes \"RedBlack prb\"\n  assumes \"subpath (red prb) rv1 res rv2 (subs prb)\"\n  shows   \"\\<exists> c. se_star \n                  (confs prb rv1) \n                  (trace (ui_es res) (labelling (black prb))) \n                  c\"\nusing finite_RedBlack assms ex_se_star_succ \nby (simp add : subpath_def finite_RedBlack_def)\n\n\ntext\\<open>The configuration associated to a red location @{term \"rl\"} is update-able.\\<close>\n\nlemma (in finite_RedBlack)\n  assumes \"RedBlack prb\"\n  assumes \"rv \\<in> red_vertices prb\"\n  shows   \"updatable (confs prb rv)\"\nusing finite_RedBlack assms \n      finite_conj[OF finite_pred[OF assms(1)] \n                     finite_pred_constr_symvars[OF assms(1)]]\n      finite_pred_imp_se_updatable\nunfolding finite_RedBlack_def by fast\n\n\ntext\\<open>The configuration associated to the first member of a subsumption is subsumed by the \nconfiguration at its second member.\\<close>\n\nlemma sub_subsumed :\n  assumes \"RedBlack prb\"\n  assumes \"sub \\<in> subs prb\"\n  shows   \"confs prb (subsumee sub) \\<sqsubseteq> confs prb (subsumer sub)\"\nusing assms\nproof (induct prb)\n  case base thus ?case by simp \nnext\n  case (se_step prb re c' prb')\n\n  moreover\n  hence \"sub \\<in> subs prb\" by auto\n\n  hence \"subsumee sub \\<in> red_vertices prb\" \n  and   \"subsumer sub \\<in> red_vertices prb\"\n        using se_step(1) subs_sub_rel_of \n        unfolding sub_rel_of_def by fast+\n\n  moreover\n  have \"tgt re \\<notin> red_vertices prb\" using se_step by auto\n\n  ultimately\n  show ?case by auto\nnext\n  case mark_step thus ?case by simp\nnext\n  case (subsum_step prb sub prb') thus ?case by auto\nnext\n  case (abstract_step prb rv c\\<^sub>a prb')\n\n  hence \"rv \\<noteq> subsumee sub\" by auto\n\n  show ?case \n  proof (case_tac \"rv = subsumer sub\")\n    assume \"rv = subsumer sub\"\n\n    moreover\n    hence  \"confs prb (subsumer sub) \\<sqsubseteq> confs prb' (subsumer sub)\" \n           using abstract_step abstract_def by auto\n  \n    ultimately\n    show ?thesis \n         using abstract_step\n               subsums_trans[of \"confs prb  (subsumee sub)\" \n                                \"confs prb  (subsumer sub)\" \n                                \"confs prb' (subsumer sub)\"]\n         by (simp add : subsums_refl)\n  next\n    assume \"rv \\<noteq> subsumer sub\" thus ?thesis using abstract_step \\<open>rv \\<noteq> subsumee sub\\<close> by simp\n  qed\nnext\n  case strengthen_step thus ?case by simp\nqed\n\nsubsubsection\\<open>Simplification lemmas for sub-paths of the red part.\\<close>\n\nlemma rb_Nil_sp :\n  assumes \"RedBlack prb\"\n  shows   \"subpath (red prb) rv1 [] rv2 (subs prb) = \n           (rv1 \\<in> red_vertices prb \\<and> (rv1 = rv2 \\<or> (rv1,rv2) \\<in> (subs prb)))\"\nusing assms subs_wf_sub_rel subs_sub_rel_of wf_sub_rel.Nil_sp by fast\n\n\nlemma rb_sp_one :\n  assumes \"RedBlack prb\"\n  shows \"subpath (red prb) rv1 [re] rv2 (subs prb) = \n         ( sub_rel_of (red prb) (subs prb)\n         \\<and> (rv1 = src re \\<or> (rv1, src re) \\<in> (subs prb)) \n         \\<and> re \\<in> edges (red prb) \\<and> (tgt re = rv2 \\<or> (tgt re, rv2) \\<in> (subs prb)))\"\nusing assms subs_wf_sub_rel_of wf_sub_rel_of.sp_one by fast\n\n\nlemma rb_sp_Cons :\n  assumes \"RedBlack prb\"\n  shows   \"subpath (red prb) rv1 (re # res) rv2 (subs prb) =\n            ( sub_rel_of (red prb) (subs prb)\n            \\<and> (rv1 = src re \\<or> (rv1, src re) \\<in> subs prb) \n            \\<and> re \\<in> edges (red prb)                       \n            \\<and> subpath (red prb) (tgt re) res rv2 (subs prb))\"\nusing assms subs_wf_sub_rel_of wf_sub_rel_of.sp_Cons by fast\n\n\nlemma rb_sp_append_one :\n  assumes \"RedBlack prb\"\n  shows   \"subpath (red prb) rv1 (res @ [re]) rv2 (subs prb) =\n            ( subpath (red prb) rv1 res (src re) (subs prb) \n            \\<and> re \\<in> edges (red prb) \n            \\<and> (tgt re = rv2 \\<or> (tgt re, rv2) \\<in> subs prb))\"\nusing assms subs_wf_sub_rel wf_sub_rel.sp_append_one sp_append_one by fast\n\n\nsubsection \\<open>Relation between red-vertices\\<close>\n\ntext\\<open>The following key-theorem describes the relation between two red locations that are linked by \na red sub-path. In a classical symbolic execution tree, the configuration at the end should be the \nresult of symbolic execution of the trace of the sub-path from the configuration at its source. \nHere, due to the facts that abstractions might have occurred and that we consider sub-paths going \nthrough subsumption links, the configuration at the end subsumes the configuration one would obtain \nby symbolic execution of the trace. Note however that this is only true for configurations computed \nduring the analysis: concrete execution of the sub-paths would yield the same program states \nthan their counterparts in the original LTS.\\<close> \n\nthm RedBlack.induct[of x P]\n\ntheorem (in finite_RedBlack) SE_rel :\n  assumes \"RedBlack prb\"\n  assumes \"subpath (red prb) rv1 res rv2 (subs prb)\"\n  assumes \"se_star (confs prb rv1) (trace (ui_es res) (labelling (black prb))) c\"\n  shows   \"c \\<sqsubseteq> (confs prb rv2)\"\nusing assms finite_RedBlack\nproof (induct arbitrary : rv1 res rv2 c rule : RedBlack.induct) \n  (* If the red part is empty, then @{term \"rv1 = rv2 = root (red prb)\"}, and \n     @{term \"confs prb rv1 = confs prb rv2\"} which prooves the goal, subsumption \n     being reflexive. *) \n  case (base prb rv1 res rv2 c) thus ?case \n       by (force simp add : subpath_def Nil_sp subsums_refl)\n\nnext\n  (* We split the goal into four cases :\n     - rv1 and rv2 are vertices of the old red part,\n     - rv1 is a vertex in the old red part, rv2 is the target of ra,\n     - rv1 is the target of ra, rv2 is a vertex of the old red part,\n     - rv1 are rv2 both equal to the target of ra. *)\n  case (se_step prb re c' prb' rv1 res rv2 c)\n\n       have \"rv1 \\<in> red_vertices prb'\"\n       and  \"rv2 \\<in> red_vertices prb'\"\n            using fst_of_sp_is_vert[OF se_step(4)]\n                  lst_of_sp_is_vert[OF se_step(4)]\n            by simp_all\n           \n       hence \"rv1 \\<in> red_vertices prb \\<and> rv1 \\<noteq> tgt re \\<or> rv1 = tgt re\"\n       and   \"rv2 \\<in> red_vertices prb \\<and> rv2 \\<noteq> tgt re \\<or> rv2 = tgt re\"\n             using se_step by (auto simp add : vertices_def)                             \n\n  thus ?case\n  proof (elim disjE conjE, goal_cases)\n    (* rv1 are rv2 vertices of the old red part *)\n    case 1\n\n    (* hence res is also a subpath from rv1 to rv2 in the old red part *)\n    moreover\n    hence \"subpath (red prb) rv1 res rv2 (subs prb)\"\n          using se_step(1,3,4)\n                sub_rel_of.sp_from_old_verts_imp_sp_in_old \n                [OF subs_sub_rel_of, of prb re \"red prb'\" rv1 rv2 res]\n          by auto\n\n    (* thus, the IH can be used to conclude. *)\n    ultimately\n    show ?thesis using se_step \n         by (fastforce simp add : finite_RedBlack_def)\n\n  next \n    (* rv1 is a vertex of the old red part, rv2 is the target of ra. *)\n    case 2 \n\n    (* hence res is empty or ra occurs only one time in res : at its end. *)\n    hence  \"\\<exists> res'. res = res' @ [re]\n                    \\<and> re \\<notin> set res'\n                    \\<and> subpath (red prb) rv1 res' (src re) (subs prb)\"\n           using se_step \n                 sub_rel_of.sp_to_new_edge_tgt_imp[OF subs_sub_rel_of, of prb re \"red prb'\" rv1 res]\n           by auto \n\n    thus ?thesis\n    proof (elim exE conjE)\n      (* If res = res'@[ra], then there exists a configuration c' such that :\n         - c' is obtained from (confs prb rv1) by symbolic execution of (the trace of) res,\n         - c' is subsumed by (confs prb (src ra)) (by IH),\n         - c is obtained from c' by symbolic execution of (the label of) ra.\n\n         Moreover, we have :\n         - (confs prb rv2) is obtained from (confs prb (src ra) by symbolic execution \n           of (the label of) ra.\n\n         Ultimately, we proof the goal by monotonicity of symbolic execution wrt subsumption. *)  \n      fix res'\n\n      assume \"res = res' @ [re]\"\n      and    \"re \\<notin> set res'\"\n      and    \"subpath (red prb) rv1 res' (src re) (subs prb)\"\n\n      moreover\n      then obtain c'\n      where \"se_star (confs prb rv1) (trace (ui_es res') (labelling (black prb))) c'\"\n      and   \"se c' (labelling (black prb) (ui_edge re)) c\"\n            using se_step 2 se_star_append_one by auto blast\n        \n      ultimately\n      have \"c' \\<sqsubseteq> (confs prb (src re))\" using se_step by fastforce\n\n      thus ?thesis \n           using se_step \\<open>rv1 \\<noteq> tgt re\\<close> 2 \n                 \\<open>se c' (labelling (black prb) (ui_edge re)) c\\<close>\n           by (auto simp add : se_mono_for_sub)\n    qed\n  next\n    (* rv1 is the target of ra. Hence res is empty and rv2 also equals (tgt ra), \n       which contradicts our hypothesis. *) \n    case 3 \n\n    moreover\n    have \"rv1 = rv2\"\n    proof -      \n      have  \"(rv1,rv2) \\<in> (subs prb')\"\n      using se_step 3 \n            sub_rel_of.sp_from_tgt_in_extends_is_Nil\n                [OF subs_sub_rel_of[OF se_step(1)], of re \"red prb'\" res rv2]\n            rb_Nil_sp[OF RedBlack.se_step[OF se_step(1,3)], of rv1 rv2] \n      by auto\n\n      hence \"rv1 \\<in> subsumees (subs prb)\" using se_step(3) by force\n\n      thus ?thesis \n           using se_step \\<open>rv1 = tgt re\\<close> subs_sub_rel_of[OF se_step(1)] \n           by (auto simp add  : sub_rel_of_def)\n    qed\n\n    ultimately\n    show ?thesis by simp\n  next\n    (* Finally, if rv1 and rv2 both equal (tgt ra), then we conclude using the fact that \n       the subsumption is reflexive. *)\n    case 4\n\n    moreover\n    hence \"res = []\"\n          using se_step \n                sub_rel_of.sp_from_tgt_in_extends_is_Nil \n                    [OF subs_sub_rel_of[OF se_step(1)], of re \"red prb'\" res rv2]\n          by auto\n\n    ultimately\n    show ?thesis using se_step by (simp add : subsums_refl)\n  qed\n\nnext\n  (* Marking a red vertex does not affect the configurations associated to red vertices,\n     hence this case is trivial when observing that a subpath after marking is a subpath \n     before marking (which allows to apply the IH). *)\n  case (mark_step prb rv prb') thus ?case by simp\n\nnext\n  case (subsum_step prb sub prb' rv1 res rv2 c)\n\n  (* The fact that prb' is also red-black will be needed several times in the following. *)\n  have RB' : \"RedBlack prb'\" by (rule RedBlack.subsum_step[OF subsum_step(1,3)])\n\n  (* First, we suppose that res starts at the newly subsumed red vertex. *)\n  show ?case \n  proof (case_tac \"rv1 = subsumee sub\")\n\n   (* In this case, res is either empty, or a subpath starting at the subsumer of the new \n       subsumption. *)\n\n    assume \"rv1 = subsumee sub\"\n\n    hence \"res = [] \\<or> subpath (red prb') (subsumer sub) res rv2 (subs prb')\"\n          using subsum_step(3,4) \n                wf_sub_rel_of.sp_in_extends_imp1 [ OF subs_wf_sub_rel_of[OF subsum_step(1)], \n                                                   of \"subsumee sub\" \"subsumer sub\" ]\n          by simp\n\n    thus ?thesis\n    proof (elim disjE)\n      (* If res is empty, then rv1 equals rv2 or (rv1,rv2) is in the new subsumption relation. *)\n      assume \"res = []\"\n\n      hence  \"rv1 = rv2 \\<or> (rv1,rv2) \\<in> (subs prb')\" \n             using subsum_step rb_Nil_sp[OF RB'] by fast\n\n      thus ?thesis \n      proof (elim disjE)\n        (* If rv1 = rv2, \"their\" configurations are also equal. Moreover, res being empty, c is the \n           configuration at rv1. We conclude using reflexivity of subsumption. *)\n        assume \"rv1 = rv2\" \n        thus ?thesis \n             using subsum_step(5) \\<open>res = []\\<close> \n             by (simp add : subsums_refl)\n      next\n        (* If (rv1, rv2) is in the new subsumption relation, then the configuration at rv1 is \n           subsumed by the configuration at rv2. We conclude using the fact c is the configuration \n           at rv1. *) \n        assume \"(rv1, rv2) \\<in> (subs prb')\" \n        thus ?thesis \n             using subsum_step(5) \\<open>res = []\\<close> \n                   sub_subsumed[OF RB', of \"(rv1,rv2)\"] \n             by simp\n      qed\n      \n    next\n      (* If res is also a subpath from the subsumer of the new subsumption, we show the goal \n         by (backward) induction on res *)\n      assume \"subpath (red prb') (subsumer sub) res rv2 (subs prb')\"\n\n      thus ?thesis \n      using subsum_step(5)\n      proof (induct res arbitrary : rv2 c rule : rev_induct, goal_cases)\n        (* If the red subpath is empty, then (rv1,rv2) is the new subsumption, which gives the goal \n           by definition of subsum_extends. *)\n        case (1 rv2 c)\n\n        have \"rv2 = subsumer sub\" \n        proof -\n          have \"(subsumer sub,rv2) \\<notin> subs prb'\"\n          proof (intro notI)\n            assume \"(subsumer sub,rv2) \\<in> subs prb'\"\n\n            hence \"subsumer sub \\<in> subsumees (subs prb')\" by force\n\n            moreover\n            have  \"subsumer sub \\<in> subsumers (subs prb')\" \n                  using subsum_step(3) by force\n\n            ultimately\n            show False \n                 using subs_wf_sub_rel[OF RB'] \n                 unfolding wf_sub_rel_def \n                 by auto\n          qed\n\n          thus ?thesis using 1(1) rb_Nil_sp[OF RB'] by auto\n        qed\n\n        thus ?case \n        using subsum_step(3) 1(2) \\<open>rv1 = subsumee sub\\<close> by simp\n\n      next\n        (* Inductive case : the red subpath has the form res@[ra]. *)\n        case (2 re res rv2 c)\n\n        (* We call :\n           - c' the configuration obtained by symbolic execution of res from the configuration at \n             rv1,\n           - c'' the configuration obtained by symbolic execution of ra from the configuration at \n             the source of ra.\n\n           We show that c' is subsumed by the configuration at the source of ra (using \"internal\" \n           IH), hence c is subsumed by c'', by monotonicity of symbolic execution for subsumption.\n           \n           Moreover, we show that c'' is subsumed by the configuration at the target of ra, \n           using the fact that [ra] is subpath from the source of ra to its target in the old \n           red part with the \"external\" IH. \n\n           Finally, we show that the configuration at the target of ra is subsumed by the \n           configuration at rv2 by observing that the target of ra is either rv2, either subsumed \n           by rv2. \n           \n           We conclude using transitivity of subsumption.  *)\n\n        hence A : \"subpath (red prb') (subsumer sub) res (src re) (subs prb')\"\n        and   B : \"subpath (red prb') (src re) [re] (tgt re) (subs prb')\"\n        using subs_sub_rel_of[OF RB'] by (auto simp add : sp_append_one sp_one)\n\n        obtain c' \n        where C : \"se_star (confs prb' rv1) (trace (ui_es res) (labelling (black prb'))) c'\"\n        and   D : \"se c' (labelling (black prb') (ui_edge re)) c\"\n        using 2 by (simp add : se_star_append_one) blast\n\n        obtain c''\n        where E : \"se (confs prb' (src re)) (labelling (black prb') (ui_edge re)) c''\"\n        using subsum_step(6-8)\n              \\<open>subpath (red prb') (src re) [re] (tgt re) (subs prb')\\<close>\n              RB' finite_RedBlack.ex_se_succ[of prb' \"src re\"]\n        unfolding finite_RedBlack_def\n        by (simp add : se_star_one fst_of_sp_is_vert) blast        \n\n        have \"c \\<sqsubseteq> c''\"\n        proof -\n          have \"c' \\<sqsubseteq> confs prb' (src re)\" using 2(1) A B C D by fast\n          thus ?thesis using D E se_mono_for_sub by fast\n        qed\n\n        moreover\n        have \"c'' \\<sqsubseteq> confs prb' (tgt re)\" \n        proof -\n          have \"subpath (red prb) (src re) [re] (tgt re) (subs prb)\"\n          proof -\n            have \"src re \\<in> red_vertices prb'\"\n            and  \"tgt re \\<in> red_vertices prb'\" \n            and  \"re \\<in> edges (red prb')\"\n            using B by (auto simp add : vertices_def sp_one)\n\n            hence \"src re \\<in> red_vertices prb\"\n            and   \"tgt re \\<in> red_vertices prb\"\n            and   \"re \\<in> edges (red prb)\"\n                  using subsum_step(3) by auto\n\n            thus ?thesis \n                 using subs_sub_rel_of[OF subsum_step(1)] \n                 by (simp add : sp_one)\n          qed\n\n          thus ?thesis \n               using subsum_step(2,3,6-8) E \n               by (simp add : se_star_one)\n        qed\n\n        moreover\n        have \"confs prb' (tgt re) \\<sqsubseteq> confs prb' rv2\"\n        proof -\n          have \"tgt re = rv2 \\<or> (tgt re,rv2) \\<in> subs prb'\" \n               using 2(2) rb_sp_append_one[OF RB'] by auto\n\n          thus ?thesis \n          proof (elim disjE)\n            assume \"tgt re = rv2\" \n            thus ?thesis by (simp add : subsums_refl)\n          next\n            assume \"(tgt re, rv2) \\<in> (subs prb')\" \n            thus ?thesis using sub_subsumed RB' by fastforce\n          qed\n        qed\n              \n        ultimately\n        show ?case using subsums_trans subsums_trans by fast\n      qed\n    qed\n\n  next\n  \n    (* If res does not start at the newly subsumed red vertex, then either res is a subpath in \n       the old red part, either it can be splitted into two parts res1 and res2 such that :\n       - res1 is a subpath in the old red part from rv1 to the newly subsumed vertex, \n       - res2 is a subpath in the new red part from the newly subsumed vertex to rv2. *)\n\n    assume \"rv1 \\<noteq> subsumee sub\"\n\n    hence  \"subpath (red prb) rv1 res rv2 (subs prb) \\<or> \n            (\\<exists> res1 res2. res = res1 @ res2 \n                        \\<and> res1 \\<noteq> [] \n                        \\<and> subpath (red prb) rv1 res1 (subsumee sub) (subs prb) \n                        \\<and> subpath (red prb') (subsumee sub) res2 rv2 (subs prb'))\"\n           using subsum_step(3,4) \n                 wf_sub_rel_of.sp_in_extends_imp2  [OF subs_wf_sub_rel_of[OF subsum_step(1)], \n                                                    of \"subsumee sub\" \"subsumer sub\"]\n           by auto\n    \n    thus ?thesis\n    proof (elim disjE exE conjE)\n      (* In the first case, we conclude by \"external\" IH. *)\n      assume \"subpath (red prb) rv1 res rv2 (subs prb)\" \n      thus ?thesis using subsum_step by simp\n\n    next\n      (* We call :\n         - c1 the configuration obtained from the configuration at rv1 by symbolic execution \n           of res1 and such that c is obtained from c1 by symbolic execution of res2,\n         - c2 the configuration obtained from the configuration at the newly subsumed red vertex \n           by symbolic execution of res2.\n\n         We show that c is subsumed by c2 and that c2 is subsumed by the configuration at rv2.\n         We conclude by transitivity of subsumption. *)\n      fix res1 res2\n       \n      define t_res1 where \"t_res1 = trace (ui_es res1) (labelling (black prb'))\"\n      define t_res2 where \"t_res2 = trace (ui_es res2) (labelling (black prb'))\"\n      \n      assume \"res = res1 @ res2\"\n      and    \"res1 \\<noteq> []\"\n      and    \"subpath (red prb) rv1 res1 (subsumee sub) (subs prb)\"\n      and    \"subpath (red prb') (subsumee sub) res2 rv2 (subs prb')\"\n      \n      then obtain c1 c2\n      where \"se_star (confs prb' rv1) t_res1 c1\"\n      and   \"se_star c1 t_res2 c\"\n      and   \"se_star (confs prb' (subsumee sub)) t_res2 c2\"\n            using subsum_step(1,3,5,6-8) RB'\n                  finite_RedBlack.ex_se_star_succ[of prb rv1 t_res1]\n                  finite_RedBlack.ex_se_star_succ[of prb' \"subsumee sub\" t_res2]\n            unfolding finite_RedBlack_def t_res1_def t_res2_def\n            by (simp  add : fst_of_sp_is_vert  se_star_append) blast\n\n      then have \"c \\<sqsubseteq> c2\"\n      proof -\n        have \"c1 \\<sqsubseteq> confs prb' (subsumee sub)\" \n             using subsum_step(2,3,6-8) \n                   \\<open>subpath (red prb) rv1 res1 (subsumee sub) (subs prb)\\<close>\n                   \\<open>se_star (confs prb' rv1) t_res1 c1\\<close>\n             by (auto simp add : t_res1_def t_res2_def)\n        \n        thus ?thesis\n             using \\<open>se_star c1 t_res2 c\\<close> \n                   \\<open>se_star (confs prb' (subsumee sub)) t_res2 c2\\<close>\n                   se_star_mono_for_sub\n             by fast\n      qed\n\n      moreover\n      (* Here we have to proceed by beckward induction on res2. *)\n      have \"c2 \\<sqsubseteq> confs prb' rv2\"\n           using \\<open>subpath (red prb') (subsumee sub) res2 rv2 (subs prb')\\<close>\n                 \\<open>se_star (confs prb' (subsumee sub)) t_res2 c2\\<close>\n           unfolding t_res2_def\n           proof (induct res2 arbitrary : rv2 c2 rule : rev_induct, goal_cases)\n           (* If the suffix is empty, then either subsumee sub equals rv2, either \n              (subsumee sub,rv2) is in the new subsumption relation. *)\n        case (1 rv2 c2) \n\n           hence \"subsumee sub = rv2 \\<or> (subsumee sub, rv2)\\<in>subs prb'\" \n           using rb_Nil_sp[OF RB'] by simp\n\n        thus ?case \n        proof (elim disjE)\n          (* In the first case, we have : \n               c = confs prb' (subsumee sub) = confs prb' rv2.\n             We conclude by reflexivity of the subsumption. *)\n          assume \"subsumee sub = rv2\" \n          thus ?thesis \n               using 1(2) by (simp add : subsums_refl)\n        next\n          (* In the second case, we have : \n               c = confs prb' (subsumee sub) \\<sqsubseteq> confs prb' rv2, \n             qed.  *)\n          assume \"(subsumee sub, rv2) \\<in> subs prb'\" \n          thus ?thesis \n                using 1(2) \n                sub_subsumed[OF RB', of \"(subsumee sub, rv2)\"] \n                by simp\n        qed\n\n      next \n        (* Inductive case : the suffix has the form res2@[ra]. *)\n        case (2 re res2 rv2 c2)\n\n        (* We call : \n           - c3 the configuration obtained from the configuration at the newly subsumed red \n             vertex. c2 is obtained from c3 by symbolic execution of ra,\n           - c4 the configuration obtained from the configuration at the source of ra by \n             symbolic execution of ra.\n\n           By internal IH, we first show that c3 is subsumed by the configuration at the source of \n           ra. Thus c2 is subsumed by c4, by monotonicity of symbolic execution for the \n           subsumption. \n\n           Then we show that c4 is subsumed by the configuration at the target of ra, using the \n           external IH.\n\n           Finally, we show that the configuration at the target of ra is subsumed by the \n           configuration at rv2, by observing that either tgt ra = rv2, either (tgt ra,rv2) \n           is in the new subsumption relation. \n\n           We conclude by transitivity of the subsumption relation. *)\n\n        have A : \"subpath (red prb') (subsumee sub) res2 (src re) (subs prb')\"\n        and  B : \"subpath (red prb') (src re) [re] rv2 (subs prb')\"\n                 using 2(2) subs_wf_sub_rel[OF RB'] subs_wf_sub_rel_of[OF RB']\n                 by (simp_all only: wf_sub_rel.sp_append_one)\n                    (simp add : wf_sub_rel_of.sp_one wf_sub_rel_of_def)\n\n        obtain c3\n        where C : \"se_star (confs prb' (subsumee sub)) \n                           (trace (ui_es res2) (labelling (black prb'))) \n                           (c3)\"\n        and   D : \"se c3 (labelling (black prb') (ui_edge re)) c2\"\n                  using 2(3) subsum_step(6-8) RB' \n                        finite_RedBlack.ex_se_succ[of prb' \"src re\"]\n                  by (simp add : se_star_append_one) blast\n\n        obtain c4 \n        where E : \"se (confs prb' (src re)) (labelling (black prb') (ui_edge re)) c4\"\n                  using subsum_step(6-8) RB' B \n                        finite_RedBlack.ex_se_succ[of prb' \"src re\"]\n                  unfolding finite_RedBlack_def\n                  by (simp  add : fst_of_sp_is_vert se_star_append) blast\n\n        have \"c2 \\<sqsubseteq> c4\" \n        proof -\n          have \"c3 \\<sqsubseteq> confs prb' (src re)\" using 2(1) A C by fast\n\n          thus ?thesis using D E se_mono_for_sub by fast\n        qed\n        \n        moreover\n        have \"c4 \\<sqsubseteq> confs prb' (tgt re)\"\n        proof -\n          have \"subpath (red prb) (src re) [re] (tgt re) (subs prb)\"\n          proof -\n            have \"src re \\<in> red_vertices prb'\"\n            and  \"tgt re \\<in> red_vertices prb'\" \n            and  \"re \\<in> edges (red prb')\"\n            using B by (auto simp add : vertices_def sp_one)\n\n            hence \"src re \\<in> red_vertices prb\"\n            and   \"tgt re \\<in> red_vertices prb\"\n            and   \"re \\<in> edges (red prb)\"\n            using subsum_step(3) by auto\n\n            thus ?thesis \n                 using subs_sub_rel_of[OF subsum_step(1)] \n                 by (simp add : sp_one)\n          qed\n\n          thus  ?thesis \n                using subsum_step(2,3,6-8) E \n                by (simp add : se_star_one)\n        qed\n\n        moreover\n        have \"confs prb' (tgt re) \\<sqsubseteq> confs prb' rv2\"\n        proof -\n          have \"tgt re = rv2 \\<or> (tgt re, rv2) \\<in> (subs prb')\"\n               using subsum_step 2 rb_sp_append_one[OF RB', of \"subsumee sub\" res2 re]\n               by (auto simp add : vertices_def subpath_def)\n\n          thus ?thesis \n          proof (elim disjE)\n            assume \"tgt re = rv2\" \n            thus ?thesis by (simp add : subsums_refl)\n          next\n            assume \"(tgt re, rv2) \\<in> (subs prb')\" \n            thus ?thesis \n                 using sub_subsumed RB' \n                 by fastforce\n          qed\n        qed\n\n        ultimately\n        show ?case using subsums_trans subsums_trans by fast\n      qed\n\n      ultimately\n      show ?thesis by (rule subsums_trans)\n    qed\n  qed\n\nnext\n  case (abstract_step prb rv c\\<^sub>a prb' rv1 res rv2 c) \n\n  show ?case\n  proof (case_tac \"rv1 = rv\", goal_cases) \n    (* We first suppose that rv1 is the red vertex where the abstraction took place. In this case, \n       we have that res is empty and rv2 = rv1. Hence c is the configuration at rv2 (after \n       abstraction). We conclude using reflexivity of subsumption. *)\n    case 1\n\n    moreover\n    hence \"res = []\" \n          using abstract_step\n                sp_from_de_empty[of rv1 \"subs prb\" \"red prb\" res rv2]\n          by simp\n\n    moreover\n    have  \"rv2 = rv\" \n    proof -\n      have \"rv1 = rv2 \\<or> (rv1, rv2) \\<in> (subs prb)\"\n           using abstract_step \\<open>res = []\\<close> \n                 rb_Nil_sp[OF RedBlack.abstract_step[OF abstract_step(1,3)]]\n           by simp \n\n      moreover\n      have \"(rv1, rv2) \\<notin> (subs prb)\"\n           using abstract_step 1 \n           unfolding Ball_def subsumees_conv\n           by (intro notI) blast\n      \n      ultimately\n      show ?thesis using 1 by simp\n    qed\n\n    ultimately\n    show ?thesis using abstract_step(5) by (simp add : subsums_refl)\n  next\n    (* Suppose that rv1 is not the red vertex where the subsumption took place. *) \n    case 2\n\n    show ?thesis\n    proof (case_tac \"rv2 = rv\")\n      (* We first suppose that rv2 is the newly abstracted red vertex. Then we have that the new \n         configuration at rv2 subsums the old configuration at this red vertex. We conclude \n         by use of IH and transitivity of subsumption. *)\n      assume \"rv2 = rv\"\n\n      hence  \"confs prb rv2 \\<sqsubseteq> confs prb' rv2\" \n             using abstract_step by (simp add : abstract_def)\n\n      moreover\n      have   \"c \\<sqsubseteq> confs prb rv2\" \n             using abstract_step 2 by auto\n\n      ultimately\n      show ?thesis using subsums_trans by fast\n    next\n      assume \"rv2 \\<noteq> rv\" thus ?thesis using abstract_step 2 by simp \n    qed\n  qed\n\nnext\n  (* Strengthening a red vertex does not affect the red part, thus this case is trivial. *)\n  case strengthen_step thus ?case by simp\nqed\n\n\n\n\n\n\n\n\n\nsubsection\\<open>Properties about marking.\\<close>\n\ntext \\<open>A configuration which is indeed satisfiable can not be marked.\\<close>\n\nlemma sat_not_marked :\n  assumes \"RedBlack prb\"\n  assumes \"rv \\<in> red_vertices prb\"\n  assumes \"sat (confs prb rv)\"\n  shows   \"\\<not> marked prb rv\"\nusing assms\nproof (induct prb arbitrary : rv)\n  case base thus ?case by simp\nnext\n  case (se_step prb re c prb')\n\n  hence \"rv \\<in> red_vertices prb \\<or> rv = tgt re\" by (auto simp add : vertices_def)\n\n  thus ?case\n  proof (elim disjE, goal_cases)\n    case 1 \n    moreover\n    hence \"rv \\<noteq> tgt re\" using se_step(3) by (auto simp add : vertices_def)\n    ultimately\n    show ?thesis using se_step by (elim conjE) auto\n  next\n    case 2\n\n    moreover\n    hence \"sat (confs prb (src re))\" using se_step(3,5) se_sat_imp_sat by auto\n    \n    ultimately\n    show ?thesis using se_step(2,3) by (elim conjE) auto\n  qed\nnext\n  case (mark_step prb rv' prb') \n\n  moreover\n  hence \"rv \\<noteq> rv'\" and \"(rv,rv') \\<notin> subs prb\"\n        using sub_subsumed[OF mark_step(1), of \"(rv,rv')\"] unsat_subs_unsat by auto\n  \n  ultimately\n  show ?case by auto\nnext\n  case subsum_step thus ?case by auto\n\nnext\n  case (abstract_step prb rv' c\\<^sub>a prb') thus ?case by (case_tac \"rv' = rv\") simp+\n\nnext\n  case strengthen_step thus ?case by simp\nqed\n\n\ntext\\<open>On the other hand, a red-location which is marked unsat is indeed logically unsatisfiable.\\<close>\n\nlemma\n  assumes \"RedBlack prb\"\n  assumes \"rv \\<in> red_vertices prb\"\n  assumes \"marked prb rv\"\n  shows   \"\\<not> sat (confs prb rv)\"\nusing assms\nproof (induct prb arbitrary : rv)\n  case base thus ?case by simp\nnext\n  case (se_step prb re c prb')\n\n  hence \"rv \\<in> red_vertices prb \\<or> rv = tgt re\" by (auto simp add : vertices_def)\n\n  thus ?case \n  proof (elim disjE, goal_cases)\n    case 1\n\n    moreover\n    hence \"rv \\<noteq> tgt re\" using se_step(3) by auto\n    hence \"marked prb rv\" using se_step by auto\n\n    ultimately\n    have \"\\<not> sat (confs prb rv)\" by (rule se_step(2))\n\n    thus ?thesis using se_step(3) \\<open>rv \\<noteq> tgt re\\<close> by auto\n  next\n    case 2\n\n    moreover\n    hence \"marked prb (src re)\" using se_step(3,5) by auto\n\n    ultimately\n    have \"\\<not> sat (confs prb (src re))\" using se_step(2,3) by auto\n\n    thus ?thesis using se_step(3) \\<open>rv = tgt re\\<close> unsat_imp_se_unsat by (elim conjE) auto\n  qed\nnext\n  case (mark_step prb rv' prb') thus ?case by (case_tac \"rv' = rv\") auto\nnext\n  case subsum_step thus ?case by simp\n\nnext\n  case (abstract_step _ rv' _) thus ?case by (case_tac \"rv' = rv\") simp+\n\nnext\n  case strengthen_step thus ?case by simp\nqed\n\n\n\n\ntext\\<open>Red vertices involved in subsumptions are not marked.\\<close>\n\n\nlemma subsumee_not_marked :\n  assumes \"RedBlack prb\"\n  assumes \"sub \\<in> subs prb\"\n  shows   \"\\<not> marked prb (subsumee sub)\"\nusing assms\nproof (induct prb)\n  case base thus ?case by simp\nnext\n  case (se_step prb re c prb')\n  \n  moreover\n  hence \"subsumee sub \\<noteq> tgt re\"\n  using subs_wf_sub_rel_of[OF se_step(1)]\n  by (elim conjE, auto simp add : wf_sub_rel_of_def sub_rel_of_def)\n\n  ultimately\n  show ?case by auto\nnext\n  case mark_step thus ?case by auto\nnext\n  case subsum_step thus ?case by auto\n\nnext\n  case abstract_step thus ?case by auto\n\nnext\n  case strengthen_step thus ?case by simp\nqed\n\n\nlemma subsumer_not_marked :\n  assumes \"RedBlack prb\"\n  assumes \"sub \\<in> subs prb\"\n  shows   \"\\<not> marked prb (subsumer sub)\"\nusing assms\nproof (induct prb)\n  case base thus ?case by simp\nnext\n  case (se_step prb re c prb')\n\n  moreover\n  hence \"subsumer sub \\<noteq> tgt re\"\n  using subs_wf_sub_rel_of[OF se_step(1)]\n  by (elim conjE, auto simp add : wf_sub_rel_of_def sub_rel_of_def)\n\n  ultimately\n  show ?case by auto\nnext\n  case (mark_step prb rv prb') thus ?case by auto\nnext\n  case (subsum_step prb sub' prb') thus ?case by auto\n\nnext\n  case abstract_step thus ?case by simp\n\nnext\n  case strengthen_step thus ?case by simp\nqed\n\n\n\ntext\\<open>If the target of a red edge is not marked, then its source is also not marked.\\<close>\n\nlemma tgt_not_marked_imp :\n  assumes \"RedBlack prb\"\n  assumes \"re \\<in> edges (red prb)\"\n  assumes \"\\<not> marked prb (tgt re)\"\n  shows   \"\\<not> marked prb (src re)\"\nusing assms\nproof (induct prb arbitrary : re)\n  case base thus ?case by simp\nnext\n  case se_step thus ?case by (force simp add : vertices_def image_def)\nnext\n  case (mark_step prb rv prb' re) thus ?case by (case_tac \"tgt re = rv\") auto\nnext\n  case subsum_step thus ?case by simp\n\nnext\n  case abstract_step thus ?case by simp\n\nnext\n  case strengthen_step thus ?case by simp\nqed\n\ntext\\<open>Given a red subpath leading from red location @{term \"rv1\"} to red location @{term \"rv2\"},\nif @{term \"rv2\"} is not marked, then @{term \"rv1\"} is also not marked (this\nlemma is not used).\\<close>\n\nlemma\n  assumes \"RedBlack prb\"\n  assumes \"subpath (red prb) rv1 res rv2 (subs prb)\"\n  assumes \"\\<not> marked prb rv2\"\n  shows   \"\\<not> marked prb rv1\"\nusing assms\nproof (induct res arbitrary : rv1)\n  case Nil \n  \n  hence \"rv1 = rv2 \\<or> (rv1,rv2) \\<in> subs prb\" by (simp add : rb_Nil_sp)\n  \n  thus ?case \n  proof (elim disjE, goal_cases)\n    case 1 thus ?case using Nil by simp\n  next\n    case 2 show ?case using Nil subsumee_not_marked[OF Nil(1) 2] by simp\n  qed\nnext\n  case (Cons re res)  \n  \n  thus ?case \n  unfolding rb_sp_Cons[OF Cons(2), of rv1 re res rv2]\n  proof (elim conjE disjE, goal_cases)\n    case 1\n\n    moreover\n    hence \"\\<not> marked prb (tgt re)\" by simp\n\n    moreover\n    have \"re \\<in> edges (red prb)\" using Cons(3) rb_sp_Cons[OF Cons(2), of rv1 re res rv2] by fast\n    \n    ultimately\n    show ?thesis using tgt_not_marked_imp[OF Cons(2)] by fast\n  next\n    case 2 thus ?thesis using subsumee_not_marked[OF Cons(2)] by fastforce\n  qed\nqed\n\n\nsubsection\\<open>Fringe of a red-black graph\\<close>\n\ntext \\<open>We have stated and proved a number of properties of red-black graphs. In the end, we are \nmainly interested in proving that the set of paths of such red-black graphs are subsets of the set \nof feasible paths of their black part. Before defining the set of paths of red-black graphs, we \nfirst introduce the intermediate concept of \\emph{fringe} of the red part. Intuitively, the fringe \nis the set of red vertices from which we can approximate more precisely the set of feasible paths of \nthe black part. This includes red vertices that have not been subsumed yet, that are not marked and \nfrom which some black edges have not been yet symbolically executed (i.e.\\ that have no red \ncounterpart from these red vertices).\\<close>\n\nsubsubsection \\<open>Definition\\<close>\n\ntext\\<open>The fringe is the set of red locations from which there exist black edges that have not \nbeen followed yet.\\<close>\n\ndefinition fringe :: \n  \"('vert, 'var, 'd, 'x) pre_RedBlack_scheme \\<Rightarrow> ('vert \\<times> nat) set\"\nwhere\n  \"fringe prb \\<equiv> {rv \\<in> red_vertices prb. \n                   rv \\<notin> subsumees (subs prb) \\<and> \n                   \\<not> marked prb rv           \\<and>\n                   ui_edge ` out_edges (red prb) rv \\<subset> out_edges (black prb) (fst rv)}\"\n\n\nsubsubsection \\<open>Fringe of an empty red-part\\<close>\n\ntext\\<open>At the beginning of the analysis, i.e.\\ when the red part is empty, the fringe consists of the \nred root.\\<close>\n\nlemma fringe_of_empty_red1 :\n  assumes \"edges (red prb) = {}\"\n  assumes \"subs prb = {}\"\n  assumes \"marked prb = (\\<lambda> rv. False)\"\n  assumes \"out_edges (black prb) (fst (root (red prb))) \\<noteq> {}\"\n  shows   \"fringe prb = {root (red prb)}\"\nusing assms by (auto simp add : fringe_def vertices_def)\n\n\nsubsubsection \\<open>Evolution of the fringe after extension\\<close>\n\ntext\\<open>Simplification lemmas for the fringe of the new red-black graph after adding an edge by \nsymbolic execution. If the configuration from which symbolic execution is performed is not marked \nyet, and if there exists black edges going out of the target of the executed edge, the target of \nthe new red edge enters the fringe. Moreover, if there still exist black edges that have no red \ncounterpart yet at the source of the new edge, then its source was and stays in the fringe.\\<close>\n\nlemma seE_fringe1 :\n  assumes \"sub_rel_of (red prb) (subs prb)\"\n  assumes \"se_extends prb re c' prb'\"\n  assumes \"\\<not> marked prb (src re)\"\n  assumes \"ui_edge ` (out_edges (red prb') (src re)) \\<subset> out_edges (black prb) (fst (src re))\"\n  assumes \"out_edges (black prb) (fst (tgt re)) \\<noteq> {}\"\n  shows   \"fringe prb' = fringe prb \\<union> {tgt re}\"\nunfolding set_eq_iff Un_iff singleton_iff\nproof (intro allI iffI, goal_cases)\n  case (1 rv)\n\n  moreover\n  hence \"rv \\<in> red_vertices prb \\<or> rv = tgt re\"\n  using assms(2) by (auto simp add : fringe_def vertices_def) \n\n  ultimately\n  show ?case using assms(2) by (auto simp add : fringe_def)\nnext \n  case (2 rv)\n\n  hence  \"rv \\<in> red_vertices prb'\" using assms(2) by (auto simp add : fringe_def vertices_def)\n\n  moreover\n  have \"rv \\<notin> subsumees (subs prb')\"\n  using 2\n  proof (elim disjE)\n    assume \"rv \\<in> fringe prb\" thus ?thesis using assms(2) by (auto simp add : fringe_def)\n  next\n    assume \"rv = tgt re\" thus ?thesis \n    using assms(1,2) unfolding sub_rel_of_def by force\n  qed\n\n  moreover\n  have \"ui_edge ` (out_edges (red prb') rv) \\<subset> out_edges (black prb') (fst rv)\"\n  using 2\n  proof (elim disjE)\n    assume \"rv \\<in> fringe prb\" \n    \n    thus ?thesis \n    proof (case_tac \"rv = src re\")\n      assume \"rv = src re\" thus ?thesis using assms(2,4) by auto\n    next\n      assume \"rv \\<noteq> src re\" thus ?thesis \n      using assms(2) \\<open>rv \\<in> fringe prb\\<close>\n      by (auto simp add : fringe_def)\n    qed\n  next\n    assume \"rv = tgt re\" thus ?thesis \n    using assms(2,5) extends_tgt_out_edges[of re \"red prb\" \"red prb'\"] by (elim conjE) auto\n  qed\n\n  moreover\n  have \"\\<not> marked prb' rv\" \n  using 2\n  proof (elim disjE, goal_cases)\n    case 1 \n\n    moreover\n    hence \"rv \\<noteq> tgt re\" using assms(2) by (auto simp add : fringe_def)\n\n    ultimately\n    show ?thesis using assms(2) by (auto simp add : fringe_def)\n  next\n    case 2 thus ?thesis using assms(2,3) by auto\n  qed\n\n  ultimately\n  show ?case by (simp add : fringe_def)\nqed\n\ntext \\<open>On the other hand, if all possible black edges have been executed from the source of the new \nedge after the extension, then the source is removed from the fringe.\\<close>\n\nlemma  seE_fringe4 :\n  assumes \"sub_rel_of (red prb) (subs prb)\"\n  assumes \"se_extends prb re c' prb'\"\n  assumes \"\\<not> marked prb (src re)\"\n  assumes \"\\<not> (ui_edge ` (out_edges (red prb') (src re)) \\<subset> out_edges (black prb) (fst (src re)))\"\n  assumes \"out_edges (black prb) (fst (tgt re)) \\<noteq> {}\"\n  shows   \"fringe prb' = fringe prb - {src re} \\<union> {tgt re}\"\nunfolding set_eq_iff Un_iff singleton_iff Diff_iff\nproof (intro allI iffI, goal_cases)\n  case (1 rv)\n\n  hence \"rv \\<in> red_vertices prb \\<or> rv = tgt re\" \n  and   \"rv \\<noteq> src re\" \n  using assms(2,3,4,5) by (auto simp add : fringe_def vertices_def) \n\n  with 1 show ?case using assms(2) by (auto simp add : fringe_def)\n\nnext\n  case (2 rv)\n\n  hence  \"rv \\<in> red_vertices prb'\" using assms(2) by (auto simp add : fringe_def vertices_def)\n\n  moreover\n  have \"rv \\<notin> subsumees (subs prb')\"\n  using 2\n  proof (elim disjE)\n    assume \"rv \\<in> fringe prb \\<and> rv \\<noteq> src re\" \n    thus ?thesis using assms(2) by (auto simp add : fringe_def)\n  next\n    assume \"rv = tgt re\" thus ?thesis \n    using assms(1,2) unfolding sub_rel_of_def by fastforce\n  qed\n\n  moreover\n  have \"ui_edge ` (out_edges (red prb') rv) \\<subset> out_edges (black prb') (fst rv)\"\n  using 2\n  proof (elim disjE)\n    assume \"rv \\<in> fringe prb \\<and> rv \\<noteq> src re\" thus ?thesis \n    using assms(2) by (auto simp add : fringe_def)\n  next\n    assume \"rv = tgt re\" thus ?thesis \n    using assms(2,5) extends_tgt_out_edges[of re \"red prb\" \"red prb'\"] by (elim conjE) auto\n  qed\n\n  moreover\n  have \"\\<not> marked prb' rv\"\n  using 2\n  proof (elim disjE, goal_cases)\n    case 1 \n\n    moreover\n    hence \"rv \\<noteq> tgt re\" using assms by (auto simp add : fringe_def)\n\n    ultimately\n    show ?thesis\n    using assms 1 by (auto simp add : fringe_def)\n  next\n    case 2 thus ?thesis using assms by auto\n  qed\n\n  ultimately\n  show ?case by (simp add : fringe_def)\nqed\n\ntext \\<open>If the source of the new edge is marked, then its target does not enter the fringe (and the \nsource was not part of it in the first place).\\<close>\n\nlemma seE_fringe2 :\n  assumes \"se_extends prb re c prb'\"\n  assumes \"marked prb (src re)\"\n  shows   \"fringe prb' = fringe prb\"\nunfolding set_eq_iff Un_iff singleton_iff\nproof (intro allI iffI, goal_cases)\n  case (1 rv)\n\n  thus ?case \n  unfolding fringe_def mem_Collect_eq\n  using assms\n  proof (intro conjI, goal_cases)\n    case 1 thus ?case by (auto simp add : fringe_def vertices_def)\n  next\n    case 2 thus ?case by auto\n  next\n    case 3 \n\n    moreover\n    hence \"rv \\<noteq> tgt re\" by auto\n\n    ultimately\n    show ?case by auto\n  next\n    case 4 thus ?case by auto\n  qed\nnext\n  case (2 rv)\n\n  thus ?case unfolding fringe_def mem_Collect_eq\n  using assms\n  proof (intro conjI, goal_cases)\n    case 1 thus ?case by (auto simp add : vertices_def)\n  next\n    case 2 thus ?case by auto\n  next\n    case 3 \n    moreover\n    hence \"rv \\<noteq> tgt re\" by auto\n    ultimately\n    show ?case by auto\n  next\n    case 4 thus ?case by auto\n  qed\nqed\n\ntext \\<open>If there exists no black edges going out of the target of the new edge, then this target \ndoes not enter the fringe.\\<close>\n\nlemma seE_fringe3 :\n  assumes \"se_extends prb re c' prb'\"\n  assumes \"ui_edge ` (out_edges (red prb') (src re)) \\<subset> out_edges (black prb) (fst (src re))\"\n  assumes \"out_edges (black prb) (fst (tgt re)) = {}\"\n  shows   \"fringe prb' = fringe prb\"\nunfolding set_eq_iff Un_iff singleton_iff\nproof (intro allI iffI, goal_cases)\n  case (1 rv)\n\n  thus ?case using assms(1,3)\n  unfolding fringe_def mem_Collect_eq\n  proof (intro conjI, goal_cases)\n    case 1 thus ?case by (auto simp add : fringe_def vertices_def) \n  next\n    case 2 thus ?case by (auto simp add : fringe_def)\n  next\n    case 3 thus ?case by (case_tac \"rv = tgt re\") (auto simp add : fringe_def)\n  next\n    case 4 thus ?case by (auto simp add : fringe_def)\n  qed\n\nnext \n  case (2 rv)\n\n  moreover\n  hence \"rv \\<in> red_vertices prb'\"\n  and   \"rv \\<noteq> tgt re\" \n  using assms(1) by (auto simp add : fringe_def vertices_def)\n\n  moreover\n  have \"ui_edge ` (out_edges (red prb') rv) \\<subset> out_edges (black prb) (fst rv)\"\n  proof (case_tac \"rv = src re\")\n    assume \"rv = src re\" thus ?thesis using assms(2) by simp\n  next\n    assume \"rv \\<noteq> src re\" \n    thus ?thesis using assms(1) 2\n    by (auto simp add : fringe_def)\n  qed\n\n  ultimately\n  show ?case using assms(1) by (auto simp add : fringe_def)\nqed\n\n\ntext \\<open>Moreover, if all possible black edges have been executed from the source of the new edge \nafter the extension, then this source is removed from the fringe.\\<close>\n\nlemma seE_fringe5 :\n  assumes \"se_extends prb re c' prb'\"\n  assumes \"\\<not> (ui_edge ` (out_edges (red prb') (src re)) \\<subset> out_edges (black prb) (fst (src re)))\"\n  assumes \"out_edges (black prb) (fst (tgt re)) = {}\"\n  shows   \"fringe prb' = fringe prb - {src re}\"\nunfolding set_eq_iff Un_iff singleton_iff Diff_iff\nproof (intro allI iffI, goal_cases)\n  case (1 rv)\n\n  moreover\n  have \"rv \\<in> red_vertices prb\" and \"rv \\<noteq> src re\"\n  using 1 assms by (auto simp add : fringe_def vertices_def)  (* slow *)\n\n  moreover\n  have \"\\<not> marked prb rv\"\n  proof (intro notI)\n    assume \"marked prb rv\"\n\n    have \"marked prb' rv\"\n    proof -\n      have \"rv \\<noteq> tgt re\" using assms(1) \\<open>rv \\<in> red_vertices prb\\<close> by auto\n      \n      thus ?thesis using assms(1) \\<open>marked prb rv\\<close> by auto\n    qed\n  \n    thus False using 1 by (auto simp add : fringe_def)\n  qed\n\n  ultimately\n  show ?case using assms(1) by (auto simp add : fringe_def)\n\nnext\n  case (2 rv)\n\n  hence  \"rv \\<in> red_vertices prb'\" using assms(1) by (auto simp add : fringe_def vertices_def)\n\n  moreover\n  have \"rv \\<notin> subsumees (subs prb')\" using 2 assms(1) by (auto simp add : fringe_def)\n\n  moreover\n  have \"ui_edge ` (out_edges (red prb') rv) \\<subset> out_edges (black prb') (fst rv)\"\n  using 2 assms(1) by (auto simp add : fringe_def)\n\n  moreover\n  have \"\\<not> marked prb' rv\"\n  proof -\n    have \"rv \\<noteq> tgt re\" using assms(1) 2 by (auto simp add : fringe_def)\n    \n    thus ?thesis using assms(1) 2 by (auto simp add : fringe_def)\n  qed\n\n  ultimately\n  show ?case by (simp add : fringe_def)\nqed\n\n\ntext\\<open>Adding a subsumption to the subsumption relation removes the first member of the \nsubsumption from the fringe.\\<close>\n\nlemma subsumE_fringe :\n  assumes \"subsum_extends prb sub prb'\"\n  shows   \"fringe prb' = fringe prb - {subsumee sub}\"\nusing assms by (auto simp add : fringe_def)\n\n\n\nsubsection\\<open>Red-Black Sub-Paths and Paths\\<close>\n\ntext\\<open>The set of red-black subpaths starting in red location @{term \"rv\"} is the union of :\n\\begin{itemize}\n  \\item the set of black sub-paths that have a red counterpart starting at @{term \"rv\"} and leading \nto a non-marked red location,\n  \\item the set of black sub-paths that have a prefix represented in the red part starting \nat @{term \"rv\"} and leading to an element of the fringe. Moreover, the remainings of these black \nsub-paths must have no non-empty counterpart in the red part. Otherwise, the set of red-black paths \nwould simply be the set of paths of the black part.\n\\end{itemize}\n\\<close>\n\ndefinition RedBlack_subpaths_from ::\n  \"('vert, 'var, 'd, 'x) pre_RedBlack_scheme \\<Rightarrow> ('vert \\<times> nat) \\<Rightarrow> 'vert edge list set\"\nwhere\n  \"RedBlack_subpaths_from prb rv \\<equiv> \n     ui_es ` {res. \\<exists> rv'. subpath (red prb) rv res rv' (subs prb) \\<and> \\<not> marked prb rv'}\n   \\<union> {ui_es res1 @ bes2 \n      | res1 bes2. \\<exists> rv1. rv1 \\<in> fringe prb \n                        \\<and> subpath (red prb) rv res1 rv1 (subs prb)\n                        \\<and> \\<not> (\\<exists> res21 bes22. bes2 = ui_es res21 @ bes22 \n                                              \\<and> res21 \\<noteq> [] \n                                              \\<and> subpath_from (red prb) rv1 res21 (subs prb))\n                        \\<and> Graph.subpath_from (black prb) (fst rv1) bes2}\"\n\n\n\ntext\\<open>Red-black paths are red-black subpaths starting at the root of the red part.\\<close>\n\nabbreviation RedBlack_paths :: \n  \"('vert, 'var, 'd, 'x) pre_RedBlack_scheme \\<Rightarrow> 'vert edge list set\"\nwhere \n  \"RedBlack_paths prb \\<equiv> RedBlack_subpaths_from prb (root (red prb))\"\n\n\ntext\\<open>When the red part is empty, the set of red-black subpaths starting at the red root is the set \nof black paths.\\<close>\n\nlemma (in finite_RedBlack) base_RedBlack_paths :\n  assumes \"fst (root (red prb)) = init (black prb)\"\n  assumes \"edges (red prb) = {}\"\n  assumes \"subs prb = {}\"\n  assumes \"confs prb (root (red prb)) = init_conf prb\"\n  assumes \"marked prb = (\\<lambda> rv. False)\"\n  assumes \"strengthenings prb = (\\<lambda> rv. (\\<lambda> \\<sigma>. True))\"\n  \n  shows   \"RedBlack_paths prb = Graph.paths (black prb)\"\n\nproof -\n  show ?thesis\n  unfolding set_eq_iff\n  proof (intro allI iffI)\n\n     fix    bes   \n     assume \"bes \\<in> RedBlack_subpaths_from prb (root (red prb))\"   \n     thus   \"bes \\<in> Graph.paths (black prb)\" \n     unfolding  RedBlack_subpaths_from_def Un_iff\n     proof (elim disjE exE conjE, goal_cases)\n       case 1\n       \n       hence \"bes = []\" using assms by (auto simp add: subpath_def)\n       \n       thus ?thesis \n       by (auto simp add : Graph.subpath_def vertices_def)\n     next\n       case 2\n   \n       then obtain res1 bes2 rv where \"bes = ui_es res1 @ bes2\"\n                                and   \"rv \\<in> fringe prb\"\n                                and   \"subpath (red prb) (root (red prb)) res1 rv (subs prb)\"\n                                and   \"Graph.subpath_from (black prb) (fst rv) bes2\"\n                   by blast\n    \n       moreover\n       hence \"res1 = []\" using assms by (simp add : subpath_def)\n   \n       ultimately\n       show ?thesis using assms \\<open>rv \\<in> fringe prb\\<close> by (simp add : fringe_def vertices_def)\n     qed\n  next\n    fix bes\n    assume \"bes \\<in> Graph.paths (black prb)\"\n    show \"bes \\<in> RedBlack_subpaths_from prb (root (red prb))\" \n    proof (case_tac \"out_edges (black prb) (init (black prb)) = {}\")\n       assume \"out_edges (black prb) (init (black prb)) = {}\"\n       show ?thesis\n            unfolding RedBlack_subpaths_from_def Un_iff image_def Bex_def mem_Collect_eq\n            apply (intro disjI1)\n            apply (rule_tac ?x=\"[]\" in exI)\n            apply (intro conjI)\n             apply (rule_tac ?x=\"root (red prb)\" in exI)\n             proof (intro conjI)\n               show \"subpath (red prb) (root (red prb)) [] (root (red prb)) (subs prb)\" \n               using assms(3) by (simp add : sub_rel_of_def subpath_def vertices_def)\n             next\n               show \"\\<not> marked prb (root (red prb))\" using assms(5) by simp\n             next\n               show \"bes = ui_es []\" \n               using \\<open>bes \\<in> Graph.paths (black prb)\\<close> \n                     \\<open>out_edges (black prb) (init (black prb)) = {}\\<close>\n               by (cases bes) (auto simp add : Graph.sp_Cons)\n             qed\n            next\n              assume \"out_edges (black prb) (init (black prb)) \\<noteq> {}\"\n              show ?thesis\n                 unfolding RedBlack_subpaths_from_def Un_iff mem_Collect_eq\n                 proof (intro disjI2, rule_tac ?x=\"[]\" in exI, rule_tac ?x=\"bes\" in exI, \n                        intro conjI, goal_cases)\n                    case 1 show ?case by simp\n                 next\n                    case 2 show ?case\n                         unfolding Bex_def\n                         proof (rule_tac ?x=\"root (red prb)\" in exI, intro conjI, goal_cases)          \n                             show \"root (red prb) \\<in> fringe prb\"\n                                 using assms(1-3,5) \\<open>out_edges (black prb) (init (black prb)) \\<noteq> {}\\<close> \n                                 fringe_of_empty_red1 \n                                 by fastforce\n                         next\n                             show \"subpath (red prb)(root (red prb))([])(root (red prb))(subs prb)\"\n                                using subs_sub_rel_of[OF RedBlack.base[OF assms(1-6)]]\n                                by (simp add : subpath_def vertices_def sub_rel_of_def)\n                         next \n                             case 3 show ?case\n                                proof (intro notI, elim exE conjE)\n                                   fix res21 bes22 rv\n                                   assume \"bes = ui_es res21 @ bes22\"\n                                   and    \"res21 \\<noteq> []\" \n                                   and    \"subpath (red prb) (root (red prb)) res21 rv (subs prb)\"\n                                   moreover\n                                   hence \"res21 = []\" using assms by (simp add : subpath_def)\n                                   ultimately  show False by (elim notE)\n                                qed\n                        next\n                             case 4 show ?case \n                                using assms \\<open>bes \\<in> Graph.paths (black prb)\\<close> by simp\n                        qed\n                 qed\n            qed     \n  qed\nqed\n\n\n\n\n\n\n\n\n\n\n\n\ntext \\<open>Red-black sub-paths and paths are sub-paths and paths of the black part.\\<close>\n\nlemma RedBlack_subpaths_are_black_subpaths :\n  assumes \"RedBlack prb\"\n  shows   \"RedBlack_subpaths_from prb rv \\<subseteq> Graph.subpaths_from (black prb) (fst rv)\"\nunfolding subset_iff mem_Collect_eq RedBlack_subpaths_from_def Un_iff image_def Bex_def\nproof (intro allI impI, elim disjE exE conjE, goal_cases)\n  case (1 bes res rv') thus ?case using assms red_sp_imp_black_sp by blast\nnext\n  case (2 bes res1 bes2 rv1 bv2) thus ?case \n  using red_sp_imp_black_sp[OF assms, of rv  res1 rv1]\n  by (rule_tac ?x=\"bv2\" in exI) (auto simp add : Graph.sp_append)\nqed\n\nlemma RedBlack_paths_are_black_paths : \n  assumes \"RedBlack prb\"\n  shows   \"RedBlack_paths prb \\<subseteq> Graph.paths (black prb)\"\nusing assms \n      RedBlack_subpaths_are_black_subpaths[of prb \"root (red prb)\"]\n      consistent_roots[of prb]\nby simp\n\n\n\n\nsubsection \\<open>Preservation of feasible paths\\<close>\n\n\ntext\\<open>The following theorem states that we do not loose feasible paths using\nour five operators,\nand moreover, configurations @{term \"c\"} at the end of feasible red paths in\nsome graph @{term \"prb\"} will have corresponding feasible red paths in\nsuccessors that\nlead to configurations that subsume @{term \"c\"}. As a corollary, our calculus is correct\nwrt. to execution.\\<close>\n\n\n\ntheorem (in finite_RedBlack) feasible_subpaths_preserved :\n  assumes \"RedBlack prb\"\n  assumes \"rv \\<in> red_vertices prb\"\n  shows   \"feasible_subpaths_from (black prb) (confs prb rv) (fst rv) \n           \\<subseteq> RedBlack_subpaths_from prb rv\"\nusing assms finite_RedBlack\nproof (induct prb arbitrary : rv)\n\n  (* Base case : the red part is empty. In this case, rl is the root of the red part. Hence, the \n     set of feasible subpaths starting at (fst rl) is the set of feasible paths of the black part.\n     We conclude using the fact that when the red part is empty, the set of red-black subpaths is \n     the set of paths of the black part, which includes feasible paths. *)\n\n  case (base prb rv) \n\n  moreover\n  hence \"rv = root (red prb)\" by (simp add : vertices_def)\n\n  moreover\n  hence \"feasible_subpaths_from (black prb) (confs prb rv) (fst rv) \n         = feasible_paths (black prb) (confs prb (root (red prb)))\"\n        using base by simp\n\n  moreover\n  have \"out_edges (black prb) (fst (root (red prb))) = {} \\<or>\n        ui_edge `out_edges(red prb)(root (red prb)) \\<subset> out_edges(black prb)(fst (root (red prb)))\"\n        using base by auto\n\n  ultimately\n  show ?case \n        using finite_RedBlack.base_RedBlack_paths[of prb]\n        by (auto simp only : finite_RedBlack_def)\n\nnext\n\n  (* Adding an edge by symbolic execution. *)\n    \n  case (se_step prb re c prb' rv)\n\n  have RB' : \"RedBlack prb'\" by (rule RedBlack.se_step[OF se_step(1,3)])\n\n  show ?case\n  unfolding subset_iff\n  proof (intro allI impI)\n    \n    fix bes \n\n    assume \"bes \\<in> feasible_subpaths_from (black prb') (confs prb' rv) (fst rv)\"\n\n    have \"rv \\<in> red_vertices prb \\<or> rv = tgt re\" \n         using se_step(3,4) by (auto simp add : vertices_def)\n\n    thus \"bes \\<in> RedBlack_subpaths_from prb' rv\" \n    proof (elim disjE)\n      (* We first suppose that bes does not start at the target of the new edge. In this case, we \n         can use the IH to show that bes is a red-black subpath in the old red-black graph. We then \n         proceed by case distinction. *)\n      assume \"rv \\<in> red_vertices prb\"\n\n      moreover\n      hence  \"rv \\<noteq> tgt re\" using se_step by auto\n\n      ultimately\n      have  \"bes \\<in> RedBlack_subpaths_from prb rv\"\n            using se_step \\<open>bes \\<in> feasible_subpaths_from (black prb') (confs prb' rv) (fst rv)\\<close>\n            by fastforce\n\n      thus ?thesis \n        apply (subst (asm) RedBlack_subpaths_from_def)\n        unfolding Un_iff image_def Bex_def mem_Collect_eq\n        proof (elim disjE exE conjE)\n          (* Suppose that bes is entirely represented in the old red part. Then it is also entirely \n             represented in the new red part, qed. *)\n          fix res rv'\n        \n          assume \"bes = ui_es res\"\n          and    \"subpath (red prb) rv res rv' (subs prb)\"\n          and    \"\\<not> marked prb rv'\"\n        \n          moreover\n          hence \"\\<not> marked prb' rv'\" \n          using se_step(3) lst_of_sp_is_vert[of \"red prb\" rv res rv' \"subs prb\"]\n          by (elim conjE) auto\n        \n          ultimately\n          show ?thesis \n          using se_step(3) sp_in_extends_w_subs[of re \"red prb\" \"red prb'\" rv res rv' \"subs prb\"]\n          unfolding RedBlack_subpaths_from_def Un_iff image_def Bex_def mem_Collect_eq\n          by (intro disjI1, rule_tac ?x=\"res\" in exI, intro conjI) \n             (rule_tac ?x=\"rv'\" in exI, auto)\n        \n        next\n          (* Suppose that bes is not entirely represented in the old red part, ie bes is of the form \n             ui_es res1 @ bes2 where res1 is a (maximal) red subpath (leading to a non-marked element \n             rv1 of the old fringe) and bes2 is black subpath (starting at the black vertex \n             represented by rv1. We then proceed by distinguishing the cases where the rv1 is the \n             source of the new edge or is an \"old\" red vertex. *)\n          fix res1 bes2 rv1 bl\n        \n          assume A : \"bes = ui_es res1 @ bes2\"\n          and    B : \"rv1 \\<in> fringe prb\"\n          and    C : \"subpath (red prb) rv res1 rv1 (subs prb)\"\n          (*and    D : \"\\<not> marked prb rv1\"*)\n          and    E : \"\\<not> (\\<exists>res21 bes22. bes2 = ui_es res21 @ bes22 \n                                 \\<and>  res21 \\<noteq> [] \n                                 \\<and> subpath_from (red prb) rv1 res21 (subs prb))\"\n          and    F : \"Graph.subpath (black prb) (fst rv1) bes2 bl\"\n        \n          hence \"rv1 \\<noteq> tgt re\" using se_step by (auto simp add : fringe_def)\n        \n          show ?thesis \n          proof (case_tac \"rv1 = src re\")\n            (* If rv1 is the source of the new edge, we proceed by cases on the black suffix. *)\n            assume \"rv1 = src re\"\n            \n            show ?thesis \n            proof (case_tac \"bes2 = []\")\n              (* If the black suffix is empty, then bes is in fact entirely represented in the old \n                 red part and also in the new red part, qed. *)\n              assume \"bes2 = []\" \n              \n              show ?thesis \n              unfolding RedBlack_subpaths_from_def Un_iff image_def Bex_def mem_Collect_eq\n              apply (intro disjI1)\n              apply (rule_tac ?x=\"res1\" in exI)\n              apply (intro conjI)\n               apply (rule_tac ?x=\"rv1\" in exI)\n                apply (intro conjI)\n                proof -\n                  show \"subpath (red prb') rv res1 rv1 (subs prb')\" \n                  using se_step(3) C by (auto simp add : sp_in_extends_w_subs)\n                next\n                  have \"rv1 \\<noteq> tgt re\" using se_step(3) \\<open>rv1 = src re\\<close> by auto\n                  thus \"\\<not> marked prb' rv1\" using se_step(3) B by (auto simp add : fringe_def)\n                next\n                  show \"bes = ui_es res1\" using A \\<open>bes2 = []\\<close> by simp\n                qed\n        \n            next\n              (* If the black suffix is not empty, we first suppose that its first edge is the new \n                 edge. *)\n              assume \"bes2 \\<noteq> []\"              \n              then obtain be bes2' where \"bes2 = be # bes2'\" unfolding neq_Nil_conv by blast        \n              show ?thesis \n              proof (case_tac \"be = ui_edge re\")\n                (* If the first edge of the black suffix is represented by the new edge, then \n                   res1@[ra] is a red subpath leading to the target of the new edge, which is the \n                   fringe and not marked. Moreover, it is maximal, as there are no out-going edges \n                   from the target of the new edge in the new red part yet. Moreover, the tail of \n                   the black suffix is a suitable \"new\" black suffix, qed. *)\n                assume \"be = ui_edge re\" \n        \n                show ?thesis \n                proof (case_tac \"out_edges (black prb) (fst (tgt re)) = {}\")\n        \n                  assume \"out_edges (black prb) (fst (tgt re)) = {}\"        \n                  show ?thesis\n\n                    unfolding RedBlack_subpaths_from_def Un_iff image_def Bex_def mem_Collect_eq\n                    apply (intro disjI1)\n                    apply (rule_tac ?x=\"res1@[re]\" in exI)\n                    apply (intro conjI)\n                     apply (rule_tac ?x=\"tgt re\" in exI)\n                     proof (intro conjI)\n                       show \"subpath (red prb') rv (res1 @ [re]) (tgt re) (subs prb')\"\n                       using se_step(3) \\<open>rv1 = src re\\<close> C\n                             sp_in_extends_w_subs[of re \"red prb\" \"red prb'\" rv res1 rv1 \"subs prb\"]\n                             rb_sp_append_one[OF RB', of rv res1 re \"tgt re\"]\n                       by auto\n                     next\n                       show \"\\<not> marked prb' (tgt re)\" \n                       using se_step(3) \\<open>rv1 = src re\\<close> B \n                       by (auto simp add : fringe_def)\n                     next\n                       have \"bes2' = []\"\n                       using F \\<open>bes2 = be # bes2'\\<close> \n                             \\<open>be = ui_edge re\\<close> \\<open>out_edges (black prb) (fst (tgt re)) = {}\\<close>\n                       by (cases bes2') (auto simp add:  Graph.sp_Cons)\n                       \n                       thus \"bes = ui_es (res1 @ [re])\"\n                       using \\<open>bes = ui_es res1 @ bes2\\<close> \\<open>bes2 = be # bes2'\\<close> \\<open>be = ui_edge re\\<close> by simp\n                     qed\n        \n                next\n        \n                  assume \"out_edges (black prb) (fst (tgt re)) \\<noteq> {}\"                    \n                  show ?thesis\n\n                  unfolding RedBlack_subpaths_from_def Un_iff mem_Collect_eq\n                  apply (intro disjI2)\n                  apply (rule_tac ?x=\"res1@[re]\" in exI)\n                  apply (rule_tac ?x=\"bes2'\"     in exI)\n                  proof (intro conjI, goal_cases)\n                    show \"bes = ui_es (res1 @ [re]) @ bes2'\"\n                    using \\<open>bes = ui_es res1 @ bes2\\<close> \\<open>bes2 = be # bes2'\\<close> \\<open>be = ui_edge re\\<close> \n                    by simp\n                  next\n                    case 2 show ?case \n                    proof (rule_tac ?x=\"tgt re\" in exI, intro conjI)\n                      have \"\\<not> marked prb (src re)\" \n                           using B \\<open>rv1 = src re\\<close> by (simp add : fringe_def)        \n                      thus \"tgt re \\<in> fringe prb'\" \n                         using se_step(3) \\<open>out_edges (black prb) (fst (tgt re)) \\<noteq> {}\\<close> \n                               seE_fringe1[OF subs_sub_rel_of[OF se_step(1)] se_step(3)] \n                               seE_fringe4[OF subs_sub_rel_of[OF se_step(1)] se_step(3)] \n                         by auto\n                    next\n                      show \"subpath (red prb') rv (res1 @ [re]) (tgt re) (subs prb')\" \n                         using se_step(3) \\<open>rv1 = src re\\<close> C\n                               sp_in_extends_w_subs[of re \"red prb\" \"red prb'\" \n                                                       rv res1 rv1 \"subs prb\"]\n                               rb_sp_append_one[OF RB', of rv res1 re \"tgt re\"]\n                         by auto\n                    next\n                      show \"\\<not> (\\<exists>res21 bes22. bes2' = ui_es res21 @ bes22 \n                                           \\<and> res21 \\<noteq> [] \n                                           \\<and> subpath_from (red prb') (tgt re) res21 (subs prb'))\"\n                      proof (intro notI, elim exE conjE)\n                        fix res21 bes22 rv2\n                        assume \"bes2' = ui_es res21 @ bes22\"\n                        and    \"res21 \\<noteq> []\"\n                        and    \"subpath (red prb') (tgt re) res21 rv2 (subs prb')\"    \n                        thus False \n                             using se_step(3) \n                                   sub_rel_of.sp_from_tgt_in_extends_is_Nil\n                                   [OF subs_sub_rel_of[OF se_step(1)], of re \"red prb'\" res21 rv2]\n                             by auto\n                      qed\n                    next\n                      show \"Graph.subpath_from (black prb') (fst (tgt re)) bes2'\" \n                           using se_step(3) F \\<open>bes2 = be # bes2'\\<close> \\<open>be = ui_edge re\\<close> \n                           by (auto simp add : Graph.sp_Cons) \n                    qed\n                  qed  \n                qed\n        \n              next\n                (* If the first edge of the black suffix is not represented by the new edge, then \n                   this first edge is still not represented in the new red part. Hence, the source \n                   of the new edge is in the fringe of the new red part (and not marked). We \n                   conclude by showing that res1 is a suitable red prefix, and bes2 a suitable \n                   black suffix. *)\n                assume \"be \\<noteq> ui_edge re\" \n        \n                show ?thesis \n                unfolding RedBlack_subpaths_from_def Un_iff mem_Collect_eq\n                unfolding RedBlack_subpaths_from_def Un_iff mem_Collect_eq\n                apply (intro disjI2)\n                apply (rule_tac ?x=\"res1\" in exI)\n                apply (rule_tac ?x=\"bes2\" in exI)\n                apply (intro conjI)\n                 apply (rule \\<open>bes = ui_es res1 @ bes2\\<close>)\n                apply (rule_tac ?x=\"rv1\" in exI)\n                proof (intro conjI)\n       \n                  show \"rv1 \\<in> fringe prb'\"\n                       unfolding fringe_def mem_Collect_eq\n                       proof (intro conjI)\n                         show \"rv1 \\<in> red_vertices prb'\" \n                         using se_step(3) B by (auto simp add : fringe_def vertices_def)\n                       next\n                         show \"rv1 \\<notin> subsumees (subs prb')\" \n                         using se_step(3) B by (auto simp add : fringe_def)\n                       next\n                         show \"\\<not> marked prb' rv1\" \n                         using B se_step(3) \\<open>rv1 \\<noteq> tgt re\\<close> \\<open>rv1 = src re\\<close>\n                         by (auto simp add : fringe_def)\n                       next\n                         have \"be \\<notin> ui_edge ` out_edges (red prb') rv1\"\n                              proof (intro notI)\n                                assume \"be \\<in> ui_edge ` out_edges (red prb') rv1\"\n                            \n                                then obtain re' where \"be = ui_edge re'\"\n                                                and   \"re' \\<in> out_edges (red prb') rv1\"\n                                by blast\n                            \n                                show False \n                                using E\n                                apply (elim notE)\n                                apply (rule_tac ?x=\"[re']\" in exI)\n                                apply (rule_tac ?x=\"bes2'\" in exI)\n                                proof (intro conjI)\n                                  show \"bes2 = ui_es [re'] @ bes2'\"\n                                  using \\<open>bes2 = be # bes2'\\<close> \\<open>be = ui_edge re'\\<close> by simp\n                                next\n                                  show \"[re'] \\<noteq> []\" by simp\n                                next\n                                  have \"re' \\<in> edges (red prb)\" \n                                  using se_step(3) \\<open>rv1 = src re\\<close> \\<open>re' \\<in> out_edges (red prb') rv1\\<close> \n                                        \\<open>be \\<noteq> ui_edge re\\<close> \\<open>be = ui_edge re'\\<close> \n                                  by (auto simp add : vertices_def)\n                            \n                                  thus \"subpath_from (red prb) rv1 [re'] (subs prb)\"\n                                  using \\<open>re' \\<in> out_edges (red prb') rv1\\<close> \n                                        subs_sub_rel_of[OF se_step(1)]\n                                  by (rule_tac ?x=\"tgt re'\" in exI) \n                                     (simp add : rb_sp_one[OF se_step(1)])\n                                qed\n                              qed\n                       \n                         moreover\n                         have \"be \\<in> out_edges (black prb) (fst rv1)\" \n                              using F \\<open>bes2 = be # bes2'\\<close> by (simp add : Graph.sp_Cons)\n                       \n                         ultimately\n                         show \"ui_edge ` out_edges (red prb') rv1 \\<subset> out_edges (black prb') (fst rv1)\"\n                              using se_step(3) red_OA_subset_black_OA[OF RB', of rv1] by auto\n                       qed\n                next\n                  show \"subpath (red prb') rv res1 rv1 (subs prb')\" \n                        using se_step(3) C by (auto simp add : sp_in_extends_w_subs)\n                (*next  show \"\\<not> marked prb' rv1\" using se_step(3) D `rv1 \\<noteq> tgt ra` by auto*)\n                next\n                  show \"\\<not> (\\<exists>res21 bes22. bes2 = ui_es res21 @ bes22 \n                                         \\<and> res21 \\<noteq> [] \n                                         \\<and> subpath_from (red prb') rv1 res21 (subs prb'))\"\n                  apply (intro notI)\n                  apply (elim exE conjE)\n                  proof -\n                    fix res21 bes22 rv3                    \n                    assume \"bes2 = ui_es res21 @ bes22\"\n                    and    \"res21 \\<noteq> []\"\n                    and    \"subpath (red prb') rv1 res21 rv3 (subs prb')\"        \n                    moreover\n                    then obtain re' res21' where \"res21 = re' # res21'\" \n                                           and   \"be = ui_edge re'\"\n                         using \\<open>bes2 = be # bes2'\\<close> unfolding neq_Nil_conv   by (elim exE) simp        \n                    ultimately\n                    have \"re' \\<in> edges (red prb')\" by (simp add : sp_Cons)       \n                    moreover\n                    have \"re' \\<notin> edges (red prb)\" \n                         using E\n                         apply (intro notI)\n                         apply (elim notE)\n                         apply (rule_tac ?x=\"[re']\" in exI)\n                         apply (rule_tac ?x=\"bes2'\" in exI)\n                         proof (intro conjI)\n                           show \"bes2 = ui_es [re'] @ bes2'\" \n                           using \\<open>bes2 = be # bes2'\\<close> \\<open>be = ui_edge re'\\<close> by simp\n                         next\n                           show \"[re'] \\<noteq> []\" by simp\n                         next\n                           assume \"re' \\<in> edges (red prb)\"                           \n                           thus   \"subpath_from (red prb) rv1 [re'] (subs prb)\"\n                                  using  subs_sub_rel_of[OF se_step(1)]\n                                        \\<open>subpath (red prb') rv1 res21 rv3 (subs prb')\\<close> \n                                        \\<open>res21 = re' # res21'\\<close>\n                                  apply (rule_tac ?x=\"tgt re'\" in exI)\n                                  apply (simp add: rb_sp_Cons[OF RB'])\n                                  apply (simp add : rb_sp_one[OF se_step(1)])\n                                  using se_step(3) by auto\n                         qed\n        \n                    ultimately\n                    show False \n                         using se_step(3) \\<open>be \\<noteq> ui_edge re\\<close> \\<open>be = ui_edge re'\\<close>   by auto\n                  qed                           \n                next\n                  show \"Graph.subpath_from (black prb') (fst rv1) bes2\" \n                       using se_step(3) F by auto\n                qed\n              qed\n            qed  \n          next\n            (* If rv1 is not the source of the new edge, then the out-going red edges of rv1 in the \n               new red part are the same as in the old red part. Thus res1 is a suitable red prefix, \n               and bes2 a suitable black suffix. *)\n            assume \"rv1 \\<noteq> src re\"\n              \n            show ?thesis\n            unfolding RedBlack_subpaths_from_def Un_iff mem_Collect_eq\n            apply (intro disjI2)\n            apply (rule_tac ?x=\"res1\" in exI)\n            apply (rule_tac ?x=\"bes2\" in exI)\n             apply (intro conjI, goal_cases)\n             proof -\n               show \"bes = ui_es res1 @ bes2\" by (rule \\<open>bes = ui_es res1 @ bes2\\<close>)\n             next\n               case 2 show ?case \n               apply (rule_tac ?x=\"rv1\" in exI)\n               proof (intro conjI, goal_cases)      \n                 show \"rv1 \\<in> fringe prb'\" \n                      using se_step(3) B \\<open>rv1 \\<noteq> src re\\<close> \\<open>rv1 \\<noteq> tgt re\\<close>\n                            seE_fringe1[OF subs_sub_rel_of[OF se_step(1)] se_step(3)]\n                            seE_fringe2[OF se_step(3)]\n                            seE_fringe3[OF se_step(3)]\n                            seE_fringe4[OF subs_sub_rel_of[OF se_step(1)] se_step(3)] \n                            seE_fringe5[OF se_step(3)]\n                      apply (case_tac \"marked prb (src re)\")\n                       apply simp\n                      apply (case_tac \"ui_edge ` out_edges (red prb') (src re) \\<subset> \n                                       out_edges (black prb) (fst (src re))\") \n                       apply (case_tac \"out_edges (black prb) (fst (tgt re)) = {}\")\n                        apply simp\n                       apply simp   \n                      apply (case_tac \"out_edges (black prb) (fst (tgt re)) = {}\")\n                       apply simp\n                      apply simp\n                      done\n               next\n                 show \"subpath (red prb') rv res1 rv1 (subs prb')\"\n                       using se_step(3) C by (auto simp add :sp_in_extends_w_subs)\n                       (*next\n                         show \"\\<not> marked prb' rv1\" \n                         using se_step(3) B D by (elim conjE) (auto simp add : fringe_def)*)\n               next\n                 show \"\\<not> (\\<exists>res21 bes22. bes2 = ui_es res21 @ bes22 \n                                        \\<and> res21 \\<noteq> [] \n                                        \\<and> subpath_from (red prb') rv1 res21 (subs prb'))\" \n                 proof (intro notI, elim exE conjE)\n                   fix res21 bes22 rv2             \n                   assume \"bes2 = ui_es res21 @ bes22\"\n                   and    \"res21 \\<noteq> []\"\n                   and    \"subpath (red prb') rv1 res21 rv2 (subs prb')\"             \n                   then obtain re' res21' where \"res21 = re' # res21'\" \n                        using \\<open>res21 \\<noteq> []\\<close> unfolding neq_Nil_conv by blast\n             \n                   have \"rv1 = src re' \\<or> (rv1,src re') \\<in> subs prb\"\n                   and  \"re' \\<in> edges (red prb')\"\n                        using se_step(3) rb_sp_Cons[OF RB']\n                             \\<open>subpath (red prb') rv1 res21 rv2 (subs prb')\\<close> \\<open>res21 = re' # res21'\\<close>\n                        by auto\n             \n                   moreover\n                   have \"re' \\<in> edges (red prb)\"\n                        proof -\n                          have \"re' \\<noteq> re\"\n                               using \\<open>rv1 = src re' \\<or> (rv1,src re') \\<in> subs prb\\<close>\n                               proof (elim disjE, goal_cases)\n                                 case 1 thus ?thesis using \\<open>rv1 \\<noteq> src re\\<close> by auto\n                               next\n                                 case 2 thus ?case \n                                             using B unfolding fringe_def subsumees_conv by fast\n                               qed                              \n                               thus ?thesis using se_step(3) \\<open>re' \\<in> edges (red prb')\\<close> by simp\n                        qed\n                   \n                   show False \n                        using E\n                        apply (elim notE)\n                        apply (rule_tac ?x=\"[re']\" in exI)\n                        apply (rule_tac ?x=\"ui_es res21' @ bes22\" in exI)\n                        proof (intro conjI)\n                          show \"bes2 = ui_es [re'] @ ui_es res21' @ bes22\"\n                               using \\<open>bes2 = ui_es res21 @ bes22\\<close> \\<open>res21 = re' # res21'\\<close> by simp\n                        next\n                         show \"[re'] \\<noteq> []\" by simp\n                        next\n                          show \"subpath_from (red prb) rv1 [re'] (subs prb)\"\n                               using se_step(1) \n                                     \\<open>rv1 = src re' \\<or> (rv1,src re') \\<in> subs prb\\<close> \n                                     \\<open>re' \\<in> edges (red prb)\\<close>\n                                     rb_sp_one subs_sub_rel_of \n                               by fast\n                        qed\n                 qed\n               next\n                 case 4 show ?case using se_step(3) F by auto\n               qed\n             qed\n          qed\n        \n        qed\n\n    next \n      (* If rl is the target of the new red edge, then we show that the empty (red) subpath is \n         suitable prefix and bes a suitable suffix, using the fact that the target of the new edge \n         is in the new fringe and can not be marked. *)\n      assume \"rv = tgt re\"\n\n      show ?thesis \n      proof (case_tac \"out_edges (black prb) (fst (tgt re)) = {}\")\n        \n        assume \"out_edges (black prb) (fst (tgt re)) = {}\"\n        show ?thesis\n\n           unfolding RedBlack_subpaths_from_def Un_iff image_def Bex_def mem_Collect_eq\n           apply (intro disjI1)\n           apply (rule_tac ?x=\"[]\" in exI)\n           proof (intro conjI, rule_tac ?x=\"tgt re\" in exI, intro conjI)\n             show \"subpath (red prb') rv [] (tgt re) (subs prb')\"\n                  using se_step(3) \\<open>rv = tgt re\\<close> rb_Nil_sp[OF RB'] by (auto simp add : vertices_def)\n           next\n             have \"sat (confs prb' (tgt re))\" \n                  using \\<open>bes \\<in> feasible_subpaths_from (black prb') (confs prb' rv) (fst rv)\\<close>\n                       \\<open>rv = tgt re\\<close> se_star_sat_imp_sat\n                  by (auto simp add : feasible_def)\n          \n             thus \"\\<not> marked prb' (tgt re)\" \n                  using se_step(3) sat_not_marked[OF RB', of \"tgt re\"]\n                  by (auto simp add : vertices_def)\n           next\n             show \"bes = ui_es []\" \n                  using se_step(3) \\<open>rv = tgt re\\<close> \\<open>out_edges (black prb) (fst (tgt re)) = {}\\<close>\n                        \\<open>bes \\<in> feasible_subpaths_from (black prb') (confs prb' rv) (fst rv)\\<close>\n                  by (cases bes) (auto simp add : Graph.sp_Cons)\n           qed\n\n      next\n        assume \"out_edges (black prb) (fst (tgt re)) \\<noteq> {}\"\n        show ?thesis\n        unfolding RedBlack_subpaths_from_def Un_iff mem_Collect_eq\n        apply (intro disjI2)\n        apply (rule_tac ?x=\"[]\" in exI)\n        apply (rule_tac ?x=\"bes\" in exI)\n        proof (intro conjI, goal_cases) \n          show \"bes = ui_es [] @ bes\" by simp\n        next\n          case 2   \n          show ?case \n          apply (rule_tac ?x=\"rv\" in exI)\n          proof (intro conjI)\n            have \"\\<not> marked prb (src re)\" \n            proof -\n              have \"sat (confs prb' (tgt re))\" \n                   using \\<open>bes \\<in> feasible_subpaths_from (black prb') (confs prb' rv) (fst rv)\\<close>\n                         \\<open>rv = tgt re\\<close> se_star_sat_imp_sat\n                   by (auto simp add : feasible_def)\n\n              hence \"sat (confs prb' (src re))\" \n                    using se_step se_sat_imp_sat by auto\n\n              moreover\n              have \"src re \\<noteq> tgt re\" using se_step by auto\n\n              ultimately\n              have \"sat (confs prb (src re))\" \n                   using se_step(3) by (auto simp add : vertices_def)\n\n              thus ?thesis \n                   using se_step sat_not_marked[OF se_step(1), of \"src re\"]  by fast\n            qed\n  \n            thus \"rv \\<in> fringe prb'\" \n                 using se_step(3) \\<open>rv = tgt re\\<close> \\<open>out_edges (black prb) (fst (tgt re)) \\<noteq> {}\\<close> \n                       seE_fringe1[OF subs_sub_rel_of[OF se_step(1)] se_step(3)] \n                       seE_fringe4[OF subs_sub_rel_of[OF se_step(1)]  se_step(3)] \n                 by auto\n  \n          next\n  \n            show \"subpath (red prb') rv [] rv (subs prb')\" \n                 using se_step(3) \\<open>rv = tgt re\\<close> subs_sub_rel_of[OF RB']\n                 by (auto simp add : subpath_def vertices_def)\n  \n          next\n  \n            show \"\\<not> (\\<exists>res21 bes22. bes = ui_es res21 @ bes22 \n                                 \\<and> res21 \\<noteq> [] \n                                 \\<and> subpath_from (red prb') rv res21 (subs prb'))\"\n  \n            proof (intro notI, elim exE conjE)\n              fix res1 bes22 rv'\n  \n              assume \"bes = ui_es res1 @ bes22\"\n              and    \"res1 \\<noteq> []\"\n              and    \"subpath (red prb') rv res1 rv' (subs prb')\"\n  \n              have \"out_edges (red prb') (tgt re) \\<noteq> {} \\<or> tgt re \\<in> subsumees (subs prb')\"\n              proof -\n                obtain re' res2 where \"res1 = re'#res2\" \n                       using \\<open>res1 \\<noteq> []\\<close> unfolding neq_Nil_conv by blast\n  \n                hence \"rv = src re' \\<or> (rv,src re') \\<in> subs prb\"\n                      using se_step(3) \\<open>subpath (red prb') rv res1 rv' (subs prb')\\<close>\n                            rb_sp_Cons[OF RB', of rv re' res2 rv']\n                      by auto\n                \n                thus ?thesis\n                proof (elim disjE) \n                  assume \"rv = src re'\"\n                  \n                  moreover\n                  hence \"re' \\<in> out_edges (red prb') (tgt re)\" \n                        using \\<open>subpath (red prb') rv res1 rv' (subs prb')\\<close> \n                              \\<open>res1 = re'#res2\\<close> \\<open>rv = tgt re\\<close> \n                        by (auto simp add : sp_Cons)\n                  \n                  ultimately\n                  show ?thesis using se_step(3) by auto\n                next\n                  assume \"(rv,src re') \\<in> subs prb\"\n  \n                  hence \"tgt re \\<in> red_vertices prb\" \n                        using se_step(3) \\<open>rv = tgt re\\<close> subs_sub_rel_of[OF se_step(1)]\n                        unfolding sub_rel_of_def by force\n  \n                  thus ?thesis using se_step(3) by auto\n                qed\n              qed\n  \n              thus False \n              proof (elim disjE)\n                assume \"out_edges (red prb') (tgt re) \\<noteq> {}\" \n                thus ?thesis using se_step(3) \n                     by (auto simp add : vertices_def image_def)\n              next\n                assume \"tgt re \\<in> subsumees (subs prb')\"\n                \n                hence \"tgt re \\<in> red_vertices prb\" \n                       using se_step(3) subs_sub_rel_of[OF se_step(1)]\n                       unfolding subsumees_conv sub_rel_of_def by fastforce\n                \n                thus ?thesis using se_step(3) by (auto simp add : vertices_def)\n              qed\n            qed\n          next\n            show \"Graph.subpath_from (black prb') (fst rv) bes\" \n                 using se_step(3) \n                       \\<open>bes \\<in> feasible_subpaths_from (black prb') (confs prb' rv) (fst rv)\\<close>\n                 by simp\n          qed\n        qed\n      qed\n    qed\n  qed\n\nnext\n  \n  case (mark_step prb rv2 prb' rv1)\n       have \"finite_RedBlack prb\" using mark_step by (auto simp add : finite_RedBlack_def)\n  show ?case \n  unfolding subset_iff\n  proof (intro allI impI) \n    (* Suppose that bes is a (black) feasible subpath starting at the black vertex represented by  \n       red vertex rv1. Hence, by IH, bes is a red-black subpath starting at rv1 in the old red-black \n       graph. We proceed by case distinction. *)\n    fix bes    \n    assume \"bes \\<in> feasible_subpaths_from (black prb') (confs prb' rv1) (fst rv1)\"\n    then obtain c where \"se_star (confs prb rv1) (trace bes (labelling (black prb))) c\"\n                  and   \"sat c\"\n         using mark_step(3) \\<open>bes \\<in> feasible_subpaths_from (black prb') (confs prb' rv1) (fst rv1)\\<close>\n         by (simp add : feasible_def) blast\n\n    have \"bes \\<in> RedBlack_subpaths_from prb rv1\" \n         using mark_step(2)[of rv1] mark_step(3-7) \n               \\<open>bes \\<in> feasible_subpaths_from (black prb') (confs prb' rv1) (fst rv1)\\<close> \n         by auto\n    \n    thus \"bes \\<in> RedBlack_subpaths_from prb' rv1\" \n    apply (subst (asm) RedBlack_subpaths_from_def)\n    unfolding Un_iff image_def Bex_def mem_Collect_eq\n    proof (elim disjE exE conjE)\n      (* Suppose that bes is entirely represented in the old red part and let us call rv3 the red \n         vertex where it ends. We show that it is still fully represented in the new red-part and \n         that rv3 is still not marked in the new red-black graph. We call res the red subpath \n         representing bes in the old red part. *)\n      fix res rv3\n      assume \"bes = ui_es res\" \n      and    \"subpath (red prb) rv1 res rv3 (subs prb)\"\n      and    \"\\<not> marked prb rv3\"\n      show ?thesis \n\n      unfolding RedBlack_subpaths_from_def Un_iff image_def Bex_def mem_Collect_eq\n      proof (intro disjI1,rule_tac ?x=\"res\" in exI,intro conjI)\n\n        show \"\\<exists>rv'. subpath (red prb') rv1 res rv' (subs prb') \\<and> \\<not> marked prb' rv'\" \n        apply (rule_tac ?x=\"rv3\" in exI)\n        proof (intro conjI)       \n          show \"subpath (red prb') rv1 res rv3 (subs prb')\"\n               using mark_step(3) \\<open>subpath (red prb) rv1 res rv3 (subs prb)\\<close>\n               by auto\n        next\n          (* We then show that rv3 is not marked. *)\n          show \"\\<not> marked prb' rv3\" \n          proof -\n            (* res being a red subpath from rv1 to rv3, and c being the configuration obtained \n               from the configuration at rv1 by symbolic execution of the trace of bes (and hence \n               res), we have that c is subsumed by the configuration at rv3. Hence, this \n               configuration is satisfiable, c being satisfiable. Thus, rv3 can not be marked. *)\n            have \"sat (confs prb rv3)\"\n                  proof -\n                    have \"c \\<sqsubseteq> confs prb rv3\"\n                         using mark_step(1) \n                                 \\<open>subpath (red prb) rv1 res rv3 (subs prb)\\<close> \n                                 \\<open>bes = ui_es res\\<close>\n                                 \\<open>se_star (confs prb rv1) (trace bes (labelling (black prb))) c\\<close>\n                                 \\<open>finite_RedBlack prb\\<close>\n                                 finite_RedBlack.SE_rel\n                         by simp\n                \n                    thus ?thesis \n                         using \\<open>se_star (confs prb rv1) (trace bes (labelling (black prb))) c\\<close> \n                               \\<open>sat c\\<close>\n                               sat_sub_by_sat\n                         by fast\n                  qed \n            thus ?thesis \n                 using mark_step(3) \\<open>subpath (red prb) rv1 res rv3 (subs prb)\\<close>\n                       lst_of_sp_is_vert[of \"red prb\" rv1 res rv3 \"subs prb\"]\n                       sat_not_marked[OF RedBlack.mark_step[OF mark_step(1,3)]]\n                 by auto\n          qed\n        qed\n\n      next\n        (* By construction, res represents bes. *)\n        show \"bes = ui_es res\" by (rule \\<open>bes = ui_es res\\<close>)\n      qed\n\n    next\n      (* Suppose that bes has a maximal red prefix res1 leading to non-marked element rv3 of the old \n         fringe, and a black suffix bes2. We show that res1 and bes2 are still suitable red prefix \n         and black prefix, respectively, in the new red part. *)\n      fix res1 bes2 rv3 bl\n\n      assume A : \"bes = ui_es res1 @ bes2\"\n      and    B : \"rv3 \\<in> fringe prb\"\n      and    C : \"subpath (red prb) rv1 res1 rv3 (subs prb)\" (*and    D : \"\\<not> marked prb rv3\"*)\n      and    E : \"\\<not> (\\<exists>res21 bes22. bes2 = ui_es res21 @ bes22 \n                             \\<and> res21 \\<noteq> [] \n                             \\<and> subpath_from (red prb) rv3 res21 (subs prb))\"\n      and    F : \"Graph.subpath (black prb) (fst rv3) bes2 bl\"\n\n      show ?thesis \n      unfolding RedBlack_subpaths_from_def Un_iff mem_Collect_eq\n      apply (intro disjI2)\n      apply (rule_tac ?x=\"res1\" in exI)\n      apply (rule_tac ?x=\"bes2\" in exI)\n      proof (intro conjI, goal_cases)    \n        show \"bes = ui_es res1 @ bes2\" by (rule \\<open>bes = ui_es res1 @ bes2\\<close>)\n      next\n        case 2 show ?case\n        apply (rule_tac ?x=\"rv3\" in exI)\n        proof (intro conjI)\n          (* Marking a red vertex does not change the fringe, so rv3 is in the new fringe. *)\n          have \"sat (confs prb rv3)\" \n          proof -\n            obtain c'\n            where \"se_star (confs prb rv1) (trace (ui_es res1) (labelling (black prb))) c'\"\n            and   \"se_star c' (trace bes2 (labelling (black prb))) c\"\n            and   \"sat c'\"\n                  using A \\<open>se_star (confs prb rv1) (trace bes (labelling (black prb))) c\\<close> \\<open>sat c\\<close>\n                  by (simp add : se_star_append se_star_sat_imp_sat) blast\n              \n            moreover\n            hence \"c' \\<sqsubseteq> confs prb rv3\"\n                  using \\<open>finite_RedBlack prb\\<close> mark_step(1) C finite_RedBlack.SE_rel by fast\n  \n            ultimately\n            show ?thesis by (simp add : sat_sub_by_sat)\n          qed\n\n          thus \"rv3 \\<in> fringe prb'\" using mark_step(3) B by (auto simp add : fringe_def)       \n        next\n          show \"subpath (red prb') rv1 res1 rv3 (subs prb')\"\n               using mark_step(3) \\<open>subpath (red prb) rv1 res1 rv3 (subs prb)\\<close>\n               by auto\n        next\n          (* We show that res1 is a maximal prefix, which is trivial because the new red part \n             contains less subpaths than the old, and res1 was already maximal. *)\n          show \"\\<not> (\\<exists>res21 bes22. bes2 = ui_es res21 @ bes22 \n                               \\<and> res21 \\<noteq> [] \n                               \\<and> subpath_from (red prb') rv3 res21 (subs prb'))\"\n               proof (intro notI, elim exE conjE)\n         \n                 fix res21 bes22 rv4\n         \n                 assume \"bes2 = ui_es res21 @ bes22\"\n                 and    \"res21 \\<noteq> []\"\n                 and    \"subpath (red prb') rv3 res21 rv4 (subs prb')\"\n         \n                 show False \n                      using E\n                      proof (elim notE,rule_tac ?x=\"res21\" in exI,\n                             rule_tac ?x=\"bes22\" in exI,intro conjI)\n                        show \"bes2 = ui_es res21 @ bes22\" by (rule \\<open>bes2 = ui_es res21 @ bes22\\<close>)\n                      next\n                        show \"res21 \\<noteq> []\" by (rule \\<open>res21 \\<noteq> []\\<close>)\n                      next\n                        show \"subpath_from (red prb) rv3 res21 (subs prb)\"\n                             using mark_step(3) \n                                   \\<open>subpath (red prb') rv3 res21 rv4 (subs prb')\\<close>\n                             by (simp del : split_paired_Ex)  blast\n                      qed\n               qed\n\n        next\n          show \"Graph.subpath_from (black prb') (fst rv3) bes2\" using mark_step(3) F by simp blast  \n        qed\n      qed\n    qed \n  qed\n\nnext\n\n  case (subsum_step prb sub prb' rv)\n\n  hence \"finite_RedBlack prb\" by (auto simp add : finite_RedBlack_def)\n  \n  have  RB' : \"RedBlack prb'\" by (rule RedBlack.subsum_step[OF subsum_step(1,3)])\n\n  show ?case \n  unfolding subset_iff\n  proof (intro allI impI)\n    (* Let bes be a feasible subpath starting at a black vertex represented by rl. By IH, bes is \n       a red-black subpath in the old red-black graph. We proceed by case distinction. *)\n    fix bes\n    assume \"bes \\<in> feasible_subpaths_from (black prb') (confs prb' rv) (fst rv)\"\n\n    hence  \"bes \\<in> RedBlack_subpaths_from prb rv\" \n           using subsum_step(2)[of rv] subsum_step(3-7) by auto\n    \n    thus   \"bes \\<in> RedBlack_subpaths_from prb' rv\"\n    apply (subst (asm) RedBlack_subpaths_from_def)\n    unfolding Un_iff image_def Bex_def mem_Collect_eq\n    proof (elim disjE exE conjE)\n      (* Suppose that bes is entirely represented in the old red part, then it is also entirely \n         represented in the new red part, qed. *)\n      fix res rv'\n      assume \"bes = ui_es res\"\n      and    \"subpath (red prb) rv res rv' (subs prb)\"\n      and    \"\\<not> marked prb rv'\"\n      thus   \"bes \\<in> RedBlack_subpaths_from prb' rv\" \n             using subsum_step(3) sp_in_extends[of sub \"red prb\"]\n             by (simp (no_asm) only : RedBlack_subpaths_from_def Un_iff image_def \n                                      Bex_def mem_Collect_eq,\n                 intro disjI1, rule_tac ?x=\"res\" in exI, intro conjI)\n                (rule_tac ?x=\"rv'\" in exI, auto)\n\n    next\n      (* Suppose that bes was of the form ui_es res1 @ bes2, with res1 ending in a red vertex that \n         we call rv'. *)\n      fix res1 bes2 rv' bl\n      assume A : \"bes = ui_es res1 @ bes2\"\n      and    B : \"rv' \\<in> fringe prb\"\n      and    C : \"subpath (red prb) rv res1 rv' (subs prb)\"\n      (*and    D : \"\\<not> marked prb rv'\"*)\n      and    E : \"\\<not> (\\<exists>res21 bes22. bes2 = ui_es res21 @ bes22 \n                                 \\<and> res21 \\<noteq> [] \n                                 \\<and> subpath_from (red prb) rv' res21 (subs prb))\"\n      and    F : \"Graph.subpath (black prb) (fst rv') bes2 bl\"      \n      show   \"bes \\<in> RedBlack_subpaths_from prb' rv\" \n      proof (case_tac \"rv' = subsumee sub\")\n        (* Suppose that rv' is the newly subsumed red vertex. The idea here is to show that \n           either bes2 is a suitable black suffix from the new subsumer, either it is of the form \n           ui_es res21 @ bes22 such that res21 is maximal and ends in a non-marked element of the \n           (new) fringe, making res1@res21 a suitable red prefix and bes22 a suitable black suffix \n           for bes to be a red-black subpath of the new red-black graph (note that bes2 and bes22 \n           might be empty).\n\n           However, assumptions from subsum_step and facts 1 to 6 are not sufficient to \n           to conclude. We proceed by beckward induction on bes2. *)\n\n        assume \"rv' = subsumee sub\" \n\n        show ?thesis\n             using \\<open>bes \\<in> feasible_subpaths_from (black prb') (confs prb' rv) (fst rv)\\<close> A C F\n             proof (induct bes2 arbitrary : bes bl rule : rev_induct, goal_cases)\n               (* Suppose that the black suffix is empty, then bes is entirely representend by res1 in \n                  the new red part and ends in rv' which is not marked, qed. *)\n               case (1 bes bl) thus ?case\n                    using subsum_step(3) B sp_in_extends[of sub \"red prb\"]\n                    by (simp (no_asm) only : \n                          RedBlack_subpaths_from_def Un_iff image_def Bex_def mem_Collect_eq,\n                        intro disjI1, rule_tac ?x=\"res1\" in exI, intro conjI)\n                       (rule_tac ?x=\"rv'\" in exI, auto simp add : fringe_def)\n                    \n        next\n          (* Suppose that the black subpath is not empty. We call bes2 the prefix obtained from this\n             subpath by removing its last edge, which we call be. \n\n             We first show that ui_es res1 @ bes2 is a red-black subpath in the old new-black graph.\n             using our \"internal\" induction hypothesis. We then proceed by case distinction. *)\n          case (2 be bes2 bes bl)\n          then obtain c1 c2 c3 \n               where \"se_star (confs prb' rv) (trace (ui_es res1) (labelling (black prb))) c1\"\n               and   \"se_star c1 (trace bes2 (labelling (black prb))) c2\"\n               and   \"se c2 (labelling (black prb) be) c3\"\n               and   \"sat c3\"\n               using subsum_step(3)\n               by (simp add : feasible_def se_star_append se_star_append_one se_star_one) blast\n             \n          have \"ui_es res1 @ bes2 \\<in> RedBlack_subpaths_from prb' rv\" \n          proof -\n            have \"ui_es res1 @ bes2 \\<in> feasible_subpaths_from (black prb') (confs prb' rv) (fst rv)\" \n                 proof -\n               \n                   have \"Graph.subpath_from (black prb') (fst rv) (ui_es res1 @ bes2)\"\n                   using subsum_step 2(5) red_sp_imp_black_sp[OF subsum_step(1) C]\n                   by (simp add : Graph.sp_append) blast\n               \n                   moreover\n                   have \"feasible (confs prb' rv) \n                                  (trace (ui_es res1 @ bes2) (labelling (black prb')))\"\n                   proof -\n                     have \"se_star (confs prb' rv) \n                                   (trace (ui_es res1@bes2) (labelling (black prb'))) \n                                   c2\"\n                          using subsum_step \n                                \\<open>se_star (confs prb' rv) (trace (ui_es res1) \n                                         (labelling (black prb))) (c1)\\<close>\n                                \\<open>se_star c1 (trace bes2 (labelling (black prb))) c2\\<close>\n                     by (simp add : se_star_append) blast\n               \n                     moreover\n                     have \"sat c2\" \n                          using \\<open>se c2 (labelling (black prb) be) c3\\<close> \\<open>sat c3\\<close>  \n                          by (simp add : se_sat_imp_sat)\n               \n                     ultimately\n                     show ?thesis by (simp add : feasible_def) blast\n                   qed\n               \n                   ultimately\n                   show ?thesis by simp\n                 qed\n  \n            moreover\n            have  \"Graph.subpath_from (black prb) (fst rv') bes2\"\n                  using 2(5) by (auto simp add : Graph.sp_append_one)\n  \n            ultimately\n            show ?thesis using 2(1,4) by(auto simp add : Graph.sp_append_one)\n          qed\n\n          thus ?case \n               apply (subst (asm) RedBlack_subpaths_from_def)\n               unfolding Un_iff image_def Bex_def mem_Collect_eq\n               proof (elim disjE exE conjE, goal_cases)\n                 (* Suppose that ui_es res1 @ bes2 is entirely represented in the new red part by \n                    a red subpath that we call res, and ends in a red vertex that we call rv''. \n                    We conclude depending on the fact that be is represented by an out-going \n                    (red edge) from rv'' or not. *)\n                 case (1 res rv'')  \n                 show ?thesis \n                 proof (case_tac \"be \\<in> ui_edge ` out_edges (red prb') rv''\")\n                   (* If this is the case, then bes = ui_es res1 @ bes2 @ [be] is entirely \n                    represented in the new red part. We call ra the red edge representing be from \n                    rv''. \n               \n                    Moreover, we showed earlier that the configuration c3 that is obtained from the \n                    configuration at rl by symbolic execution of (the trace of) \n                    bes = ui_es res1 @ bes2 @ [be] is satisfiable. As c3 is subsumed by the \n                    configuration at the target of ra, this last configuration is also satisfiable, \n                    and  thus not marked, qed. *)\n                   assume \"be \\<in> ui_edge ` out_edges (red prb') rv''\"\n                   then obtain re where \"be = ui_edge re\"\n                                  and   \"re \\<in> out_edges (red prb') rv''\"\n                        by blast\n                                              \n                   show ?thesis \n                        unfolding RedBlack_subpaths_from_def Un_iff image_def Bex_def mem_Collect_eq\n                        apply (intro disjI1)\n                        apply (rule_tac ?x=\"res@[re]\" in exI)\n                        proof (intro conjI,rule_tac ?x=\"tgt re\" in exI,intro conjI)\n                          show \"subpath (red prb') rv (res@[re]) (tgt re) (subs prb')\" \n                               using 1(2) \\<open>re \\<in> out_edges (red prb') rv''\\<close> \n                               by (simp add : sp_append_one)\n                        next\n                          show \"\\<not> marked prb' (tgt re)\" \n                          proof -\n                            have \"sat (confs prb' (tgt re))\"\n                            proof -\n                              have \"subpath (red prb') rv (res@[re]) (tgt re) (subs prb')\" \n                                   using 1(2) \\<open>re \\<in> out_edges (red prb') rv''\\<close> \n                                   by (simp add : sp_append_one)\n                        \n                              then obtain c \n                              where \"se_star (confs prb' rv) \n                                             (trace (ui_es (res@[re])) (labelling (black prb))) \n                                             c\"\n                                    using subsum_step(3,5,6,7) RB'\n                                          finite_RedBlack.sp_imp_ex_se_star_succ\n                                                 [of prb' rv \"res@[re]\" \"tgt re\"]\n                                    unfolding finite_RedBlack_def \n                                    by simp blast\n                        \n                              hence \"sat c\" \n                                    using 1(1)\n                                          \\<open>se_star (confs prb' rv) (trace (ui_es res1) \n                                                   (labelling (black prb))) (c1)\\<close>\n                                          \\<open>se_star c1 (trace bes2 (labelling (black prb))) c2\\<close>\n                                          \\<open>se c2 (labelling (black prb) be) c3\\<close> \n                                          \\<open>sat c3\\<close> \\<open>be = ui_edge re\\<close>\n                                          se_star_succs_states\n                                                  [of \"confs prb' rv\" \n                                                      \"trace(ui_es(res@[re]))(labelling(black prb))\" \n                                                      c3]\n                                    apply (subst (asm) eq_commute)\n                                    by (auto simp add : se_star_append_one se_star_append \n                                                        se_star_one sat_eq)\n                        \n                              moreover\n                              have \"c \\<sqsubseteq> confs prb' (tgt re)\" \n                                   using subsum_step(3,5,6,7) \n                                         \\<open>subpath (red prb') rv (res@[re]) (tgt re) (subs prb')\\<close> \n                                         \\<open>se_star (confs prb' rv)(trace (ui_es (res@[re])) \n                                                  (labelling (black prb)))(c)\\<close>\n                                         finite_RedBlack.SE_rel[of prb'] RB'\n                                   by (simp add : finite_RedBlack_def)\n                        \n                              ultimately\n                              show ?thesis by (simp add: sat_sub_by_sat)\n                            qed\n                        \n                            thus ?thesis \n                                 using \\<open>re \\<in> out_edges (red prb') rv''\\<close> \n                                       sat_not_marked[OF RB', of \"tgt re\"]\n                                 by (auto simp add : vertices_def)\n                          qed\n                        next\n                          show \"bes = ui_es (res@[re])\" using 1(1) 2(3) \\<open>be = ui_edge re\\<close> by simp\n                        qed\n                        \n                 next\n                   (* Suppose that be is not represented from rv''. We cannot conclude that [be] is \n                      a suitable suffix starting from rv'' for proving the goal, because rv'' might \n                      have been subsumed earlier. If this is the case, we have to show that [be] is \n                      a suitable suffix from the red vertex that subsums rv''. *)\n                   assume \"be \\<notin> ui_edge ` out_edges (red prb') rv''\"\n               \n                   show ?thesis\n                   proof (case_tac \"rv'' \\<in> subsumees (subs prb')\")\n                     (* We suppose that rv'' is subsumed by a red vertex arv''. We conclude depen-\n                        ding on the fact that be is represented in the out-going edges of arv'' or \n                        not. *)\n                     assume \"rv'' \\<in> subsumees (subs prb')\"\n               \n                     then obtain arv'' where \"(rv'',arv'') \\<in> (subs prb')\" by auto\n               \n                     hence \"subpath (red prb') rv res arv'' (subs prb')\" \n                           using \\<open>subpath (red prb') rv res rv'' (subs prb')\\<close>\n                           by (simp add : sp_append_sub)\n               \n                     show ?thesis\n                     proof (case_tac \"be \\<in> ui_edge ` out_edges (red prb') arv''\")\n                       (* If be is represented in the out-going edges of arv'', then bes is entirely \n                          represented in the new red part, from rl to tgt ra. Moreover, the \n                          configuration at the target of ra subsums c, which is satisfiable, thus \n                          tgt ra can not be marked, qed. *)\n                       assume \"be \\<in> ui_edge ` out_edges (red prb') arv''\"\n               \n                       then obtain re where \"re \\<in> out_edges (red prb') arv''\"\n                                      and   \"be = ui_edge re\"\n                            by blast\n               \n                       show ?thesis \n                            unfolding RedBlack_subpaths_from_def Un_iff image_def \n                                      Bex_def mem_Collect_eq\n                            apply (intro disjI1)\n                            apply (rule_tac ?x=\"res@[re]\" in exI)\n                            proof (intro conjI,rule_tac ?x=\"tgt re\" in exI,intro conjI)\n                            \n                              show \"subpath (red prb') rv (res @ [re]) (tgt re) (subs prb')\"\n                                   using \\<open>subpath (red prb') rv res arv'' (subs prb')\\<close> \n                                         \\<open>re \\<in> out_edges (red prb') arv''\\<close>\n                                   by (simp add : sp_append_one)\n                            \n                            next\n                            \n                              have \"sat (confs prb' (tgt re))\"\n                              proof -\n                                have \"subpath (red prb') rv (res@[re]) (tgt re) (subs prb')\" \n                                     using \\<open>subpath (red prb') rv res arv'' (subs prb')\\<close> \n                                             \\<open>re \\<in> out_edges (red prb') arv''\\<close>\n                                     by (simp add : sp_append_one)\n                            \n                                then obtain c \n                                where se : \"se_star (confs prb' rv) (trace (ui_es (res@[re])) \n                                                    (labelling (black prb))) (c)\"\n                                      using subsum_step(3,5,6,7) RB'\n                                            finite_RedBlack.sp_imp_ex_se_star_succ\n                                                [of prb' rv \"res@[re]\" \"tgt re\"]\n                                      unfolding finite_RedBlack_def \n                                      by simp blast\n                            \n                                hence \"sat c\" \n                                      using 1(1)\n                                            \\<open>se_star (confs prb' rv) (trace (ui_es res1) \n                                                     (labelling (black prb))) (c1)\\<close>\n                                            \\<open>se_star c1 (trace bes2 (labelling (black prb))) c2\\<close>\n                                            \\<open>se c2 (labelling (black prb) be) c3\\<close> \\<open>sat c3\\<close> \n                                            \\<open>be = ui_edge re\\<close>\n                                            se_star_succs_states\n                                                    [of \"confs prb' rv\" \n                                                        \"trace (ui_es(res@[re]))\n                                                               (labelling (black prb))\" \n                                                        \"c3\"]\n                                      apply (subst (asm) eq_commute)\n                                      by (auto simp add : se_star_append_one se_star_append \n                                                          se_star_one sat_eq)\n                            \n                                moreover\n                                have \"c \\<sqsubseteq> confs prb' (tgt re)\" \n                                     using subsum_step(3,5,6,7) se RB' \n                                           finite_RedBlack.SE_rel[of prb']\n                                           \\<open>subpath (red prb') rv (res@[re]) (tgt re) (subs prb')\\<close>                          \n                                     by (simp add : finite_RedBlack_def)\n                            \n                                ultimately\n                                show ?thesis by (simp add: sat_sub_by_sat)\n                              qed\n                            \n                              thus \"\\<not> marked prb' (tgt re)\" \n                              using \\<open>re \\<in> out_edges (red prb') arv''\\<close> \n                                    sat_not_marked[OF RB', of \"tgt re\"]\n                              by (auto simp add : vertices_def)\n                            \n                            next\n                            \n                              show \"bes = ui_es (res @ [re])\" \n                              using \\<open>bes = ui_es res1 @ bes2 @ [be]\\<close> \n                                    \\<open>ui_es res1 @ bes2 = ui_es res\\<close>\n                                    \\<open>be = ui_edge re\\<close>\n                              by simp\n                            \n                            qed\n                            \n                     next\n                       (* Suppose that be is not represented in the out-going edges of arv''. We \n                          show that res is a suitable red prefix and [be] a suitable black prefix.*)\n                       assume A : \"be \\<notin> ui_edge ` out_edges (red prb') arv''\"\n               \n                       have \"src be = fst arv''\"\n                       proof -\n                         have \"Graph.subpath (black prb') (fst rv) (ui_es res1 @ bes2) (fst arv'')\"\n                         using \\<open>ui_es res1 @ bes2 = ui_es res\\<close> \n                               \\<open>subpath (red prb') rv res arv'' (subs prb')\\<close> \n                               red_sp_imp_black_sp[OF RB']\n                         by auto\n               \n                         moreover\n                         have \"Graph.subpath (black prb') (fst rv) (ui_es res1 @ bes2) (src be)\"\n                         using \\<open>bes \\<in> feasible_subpaths_from (black prb') (confs prb' rv) (fst rv)\\<close>\n                               \\<open>bes = ui_es res1 @ bes2 @ [be]\\<close>\n                         by (auto simp add : Graph.sp_append Graph.sp_append_one Graph.sp_one)\n               \n                         ultimately\n                         show ?thesis \n                         using sp_same_src_imp_same_tgt by fast\n                       qed\n               \n                       show ?thesis \n                       unfolding RedBlack_subpaths_from_def Un_iff mem_Collect_eq\n                       apply (intro disjI2)\n                       apply (rule_tac ?x=\"res\" in exI)\n                       apply (rule_tac ?x=\"[be]\" in exI)\n                       proof (intro conjI, goal_cases)\n                         \n                         show \"bes = ui_es res @ [be]\" \n                         using \\<open>bes = ui_es res1 @ bes2 @ [be]\\<close> \n                               \\<open>ui_es res1 @ bes2 = ui_es res\\<close>\n                         by simp\n               \n                       next\n               \n                         case 2 show ?case \n                         apply (rule_tac ?x=\"arv''\" in exI)\n                         proof (intro conjI) \n                           \n                           show \"arv'' \\<in> fringe prb'\" \n                           unfolding fringe_def mem_Collect_eq\n                           proof (intro conjI)\n                             show \"arv'' \\<in> red_vertices prb'\" \n                             using \\<open>subpath (red prb') rv res arv'' (subs prb')\\<close>\n                             by (simp add : lst_of_sp_is_vert)\n                           next\n                             show \"arv'' \\<notin> subsumees (subs prb')\" \n                             using \\<open>(rv'',arv'') \\<in> subs prb'\\<close> subs_wf_sub_rel[OF RB']\n                             unfolding wf_sub_rel_def Ball_def\n                             by (force simp del : split_paired_All)\n                           next\n                             show \"\\<not> marked prb' arv''\"\n                             using \\<open>(rv'',arv'') \\<in> (subs prb')\\<close> subsumer_not_marked[OF RB']\n                             by fastforce\n                           next\n                             have \"be \\<in> edges (black prb')\" \n                             using subsum_step(3)\n                                   \\<open>Graph.subpath (black prb) (fst rv') (bes2 @ [be]) bl\\<close>\n                             by (simp add : Graph.sp_append_one)\n               \n                             thus \"ui_edge ` out_edges (red prb') arv'' \\<subset> out_edges (black prb') \n                                                                                    (fst arv'')\"\n                             using \\<open>src be = fst arv''\\<close> A  red_OA_subset_black_OA[OF RB', of arv'']\n                             by auto\n                           qed\n               \n                         next\n               \n                           show \"subpath (red prb') rv res arv'' (subs prb')\"\n                           by (rule \\<open>subpath (red prb') rv res arv'' (subs prb')\\<close>)\n               \n                         next\n               \n                           show \"\\<not> (\\<exists>res21 bes22. [be] = ui_es res21 @ bes22 \n                                                \\<and> res21 \\<noteq> [] \n                                                \\<and> subpath_from (red prb') arv'' res21 (subs prb'))\"\n                           proof (intro notI, elim exE conjE, goal_cases)\n                             case (1 res21 bes22 rv''')\n                               \n                             have \"be \\<in> ui_edge ` out_edges (red prb') arv''\" \n                             proof -\n                               obtain re res21' where \"res21 = re # res21'\"\n                               using 1(2) unfolding neq_Nil_conv by blast\n               \n                               have \"be = ui_edge re\" and  \"re \\<in> out_edges (red prb') arv''\" \n                               proof -\n                                 show \"be = ui_edge re\" using 1(1) \\<open>res21 = re # res21'\\<close> by simp\n                               next\n                                 have \"re \\<in> edges (red prb')\"\n                                      using 1(3) \\<open>res21 = re # res21'\\<close> by (simp add : sp_Cons)\n                                 \n                                 moreover\n                                 have \"src re = arv''\"\n                                 proof -\n                                   have \"(arv'',src re) \\<notin> subs prb'\" \n                                        using \\<open>(rv'',arv'') \\<in> subs prb'\\<close> subs_wf_sub_rel[OF RB']\n                                        unfolding wf_sub_rel_def Ball_def \n                                        by (force simp del : split_paired_All)\n               \n                                   thus ?thesis\n                                        using 1(3) \\<open>res21 = re # res21'\\<close>\n                                        by (simp add : rb_sp_Cons[OF RB'])\n                                 qed\n               \n                                 ultimately\n                                 show \"re \\<in> out_edges (red prb') arv''\" by simp\n                               qed\n                               \n                               thus ?thesis by auto\n                             qed\n               \n                             thus False using A by (elim notE)\n                           qed\n               \n                         next\n               \n                           show \"Graph.subpath_from (black prb') (fst arv'') [be]\" \n                                using subsum_step(3)\n                                      \\<open>Graph.subpath (black prb) (fst rv') (bes2 @ [be]) bl\\<close>\n                                      \\<open>(rv'',arv'') \\<in> subs prb'\\<close>\n                                      \\<open>subpath (red prb') rv res arv'' (subs prb')\\<close>\n                                      \\<open>src be = fst arv''\\<close>\n                                      RB' red_sp_imp_black_sp subs_to_same_BL\n                                by (simp add : Graph.sp_append_one Graph.sp_one)\n                         qed\n                       qed\n                     qed\n               \n                   next\n                     (* Now suppose that rv'' is not subsumed in the new red-black graph. If be is \n                        represented in the out-going edges pf rv'', then ui_es res1 @ bes2 @ [be] \n                        is entirely represented in the new red part. Otherwise, res is a suitable \n                        red prefix and [be] a suitable black prefix. *)\n                     assume \"rv'' \\<notin> subsumees (subs prb')\"\n                     \n                     show ?thesis\n                     proof (case_tac \"be \\<in> ui_edge ` out_edges (red prb') rv''\")\n               \n                       assume \"be \\<in> ui_edge ` out_edges (red prb') rv''\"\n               \n                       then obtain re where \"be = ui_edge re\"\n                                      and   \"re \\<in> out_edges (red prb') rv''\"\n                            by blast\n                       \n                       show ?thesis \n                            unfolding RedBlack_subpaths_from_def Un_iff image_def \n                                      Bex_def mem_Collect_eq\n                            apply (intro disjI1)\n                            apply (rule_tac ?x=\"res @ [re]\" in exI)\n                            apply (intro conjI)\n                            proof (rule_tac ?x=\"tgt re\" in exI,intro conjI)\n                              show \"subpath (red prb') rv (res @ [re]) (tgt re) (subs prb')\"\n                                   using \\<open>subpath (red prb') rv res rv'' (subs prb')\\<close>\n                                         \\<open>re \\<in> out_edges (red prb') rv''\\<close>\n                                   by (simp add : sp_append_one)\n                            next\n                              show \"\\<not> marked prb' (tgt re)\"\n                              proof -\n                                have \"sat (confs prb' (tgt re))\"\n                                proof -\n                                  have \"subpath (red prb') rv (res@[re]) (tgt re) (subs prb')\" \n                                       using \\<open>subpath (red prb') rv res rv'' (subs prb')\\<close> \n                                               \\<open>re \\<in> out_edges (red prb') rv''\\<close>\n                                       by (simp add : sp_append_one)\n                            \n                                  then obtain c \n                                  where se : \"se_star (confs prb' rv)(trace (ui_es (res@[re])) \n                                                      (labelling (black prb)))(c)\"\n                                        using subsum_step(3,5,6,7) RB'\n                                            finite_RedBlack.sp_imp_ex_se_star_succ\n                                                      [of prb' rv \"res@[re]\" \"tgt re\"]\n                                        unfolding finite_RedBlack_def \n                                        by simp blast\n                            \n                                  hence \"sat c\" \n                                        using 1(1)\n                                        \\<open>se_star (confs prb' rv) (trace (ui_es res1) \n                                                 (labelling (black prb))) (c1)\\<close>\n                                        \\<open>se_star c1 (trace bes2 (labelling (black prb))) c2\\<close>\n                                        \\<open>se c2 (labelling (black prb) be) c3\\<close> \\<open>sat c3\\<close> \n                                        \\<open>be = ui_edge re\\<close> \n                                        se_star_succs_states\n                                              [of \"confs prb' rv\" \n                                                  \"trace (ui_es (res@[re])) (labelling (black prb))\" \n                                                  \"c3\"]\n                                        apply (subst (asm) eq_commute)\n                                        by (auto simp add : se_star_append_one se_star_append \n                                                            se_star_one sat_eq)\n                            \n                                  moreover\n                                  have \"c \\<sqsubseteq> confs prb' (tgt re)\" \n                                       using subsum_step(3,5,6,7) se RB' \n                                             finite_RedBlack.SE_rel[of prb']\n                                             \\<open>subpath (red prb') rv (res@[re]) (tgt re) (subs prb')\\<close>  \n                                       by (simp add : finite_RedBlack_def)\n                            \n                                  ultimately\n                                  show ?thesis by (simp add: sat_sub_by_sat)\n                                qed\n                            \n                                thus ?thesis\n                                     using \\<open>re \\<in> out_edges (red prb') rv''\\<close> \n                                           sat_not_marked[OF RB', of \"tgt re\"]\n                                     by (auto simp add : vertices_def)\n                              qed\n                            next\n                              show \"bes = ui_es (res @ [re])\" \n                                   using \\<open>bes = ui_es res1 @ bes2 @ [be]\\<close> \n                                         \\<open>ui_es res1 @ bes2 = ui_es res\\<close>\n                                         \\<open>be = ui_edge re\\<close>\n                                   by simp\n                            qed\n                     \n                     next\n                       assume A : \"be \\<notin> ui_edge ` out_edges (red prb') rv''\"\n               \n                       show ?thesis \n                            unfolding RedBlack_subpaths_from_def Un_iff Bex_def mem_Collect_eq\n                            apply (intro disjI2)\n                            apply (rule_tac ?x=\"res\" in exI)\n                            apply (rule_tac ?x=\"[be]\" in exI)\n                            proof (intro conjI, goal_cases)\n                              show \"bes = ui_es res @ [be]\" \n                                   using \\<open>ui_es res1 @ bes2 = ui_es res\\<close> \n                                         \\<open>bes = ui_es res1 @ bes2 @ [be]\\<close>\n                                   by simp\n                            next\n                            \n                              case 2 \n                            \n                              have \"src be = fst rv''\"\n                              proof -\n                                have \"Graph.subpath (black prb') (fst rv) (ui_es res) (src be)\"\n                                     using \\<open>bes \\<in> feasible_subpaths_from (black prb') \n                                                                         (confs prb' rv) (fst rv)\\<close>\n                                           \\<open>bes = ui_es res1 @ bes2 @ [be]\\<close> \n                                           \\<open>ui_es res1 @ bes2 = ui_es res\\<close>\n                                           red_sp_imp_black_sp\n                                               [OF RB' \\<open>subpath (red prb') rv res rv'' (subs prb')\\<close>]\n                                     by (subst (asm)(2) eq_commute) \n                                        (auto simp add : Graph.sp_append Graph.sp_one)\n                            \n                                thus ?thesis \n                                using red_sp_imp_black_sp\n                                          [OF RB' \\<open>subpath (red prb') rv res rv'' (subs prb')\\<close>]\n                                by (rule sp_same_src_imp_same_tgt)\n                              qed\n                            \n                              show ?case\n                              apply (rule_tac ?x=\"rv''\" in exI)\n                              proof (intro conjI)\n                            \n                                show \"rv'' \\<in> fringe prb'\" \n                                unfolding fringe_def mem_Collect_eq\n                                proof (intro conjI)\n                                  show \"rv'' \\<in> red_vertices prb'\" \n                                       using \\<open>subpath (red prb') rv res rv'' (subs prb')\\<close>\n                                       by (simp add : lst_of_sp_is_vert)\n                                next\n                                  show \"rv'' \\<notin> subsumees (subs prb')\" \n                                  by (rule \\<open>rv'' \\<notin> subsumees (subs prb')\\<close>)\n                                next\n                                  show \"\\<not> marked prb' rv''\" by (rule \\<open>\\<not> marked prb' rv''\\<close>)\n                                next\n                                  have \"be \\<in> edges (black prb')\" \n                                       using subsum_step(3)\n                                            \\<open>Graph.subpath (black prb) (fst rv') (bes2 @ [be]) bl\\<close>\n                                       by (simp add : Graph.sp_append_one)\n                            \n                                  thus \"ui_edge ` out_edges (red prb') rv'' \\<subset> \n                                           out_edges (black prb') (fst rv'')\"\n                                       using \\<open>src be = fst rv''\\<close> A \n                                             red_OA_subset_black_OA[OF RB', of rv'']\n                                       by auto\n                                qed\n                            \n                              next\n                            \n                                show \"subpath (red prb') rv res rv'' (subs prb')\"\n                                     by (rule \\<open>subpath (red prb') rv res rv'' (subs prb')\\<close>)\n                            \n                              next\n                            \n                                show \"\\<not> (\\<exists>res21 bes22. [be] = ui_es res21 @ bes22 \n                                                       \\<and> res21 \\<noteq> [] \n                                                       \\<and> SubRel.subpath_from (red prb') (rv'') \n                                                                             (res21) (subs prb'))\"\n                                proof (intro notI, elim exE conjE, goal_cases)\n                                  case (1 res21 bes22 rv''')\n                                    \n                                  have \"be \\<in> ui_edge ` out_edges (red prb') rv''\" \n                                  proof -\n                                    obtain re res21' where \"res21 = re # res21'\"\n                                           using 1(2) unfolding neq_Nil_conv by blast\n                            \n                                    have \"be = ui_edge re\"\n                                    and  \"re \\<in> out_edges (red prb') rv''\" \n                                    proof -\n                                      show \"be = ui_edge re\" using 1(1) \\<open>res21 = re#res21'\\<close> by simp\n                                    next\n                                      have \"re \\<in> edges (red prb')\"\n                                      using 1(3) \\<open>res21 = re # res21'\\<close> by (simp add : sp_Cons)\n                                      \n                                      moreover\n                                      have \"src re = rv''\"\n                                      proof -\n                                        have \"(rv'',src re) \\<notin> subs prb'\" \n                                             using \\<open>rv'' \\<notin> subsumees (subs prb')\\<close> by force\n                            \n                                        thus ?thesis\n                                              using 1(3) \\<open>res21 = re # res21'\\<close>\n                                              by (simp add : rb_sp_Cons[OF RB'])\n                                      qed\n                            \n                                      ultimately\n                                      show \"re \\<in> out_edges (red prb') rv''\" by simp\n                                    qed\n                                    \n                                    thus ?thesis by auto\n                                  qed\n                            \n                                  thus False using A by (elim notE)\n                                qed\n                            \n                              next\n                            \n                                show \"Graph.subpath_from (black prb') (fst rv'') [be]\"\n                                     using subsum_step(3) \n                                           \\<open>Graph.subpath (black prb) (fst rv') (bes2 @ [be]) bl\\<close> \n                                           \\<open>src be = fst rv''\\<close>\n                                     by (rule_tac ?x=\"tgt be\" in exI) \n                                        (simp add : Graph.sp_append_one Graph.sp_one)\n                            \n                              qed\n                            qed\n                     qed\n                   qed\n                 qed\n               \n               next\n                 (* Now suppose that ui_es res1 @ bes2 is of the form ui_es res1' @ bes2'.\n                    Then there exists a red vertex rv'' such that :\n                    - res1' is a maximal red prefix ending in rv'', which is not marked and \n                      in the new  fringe,\n                    - bes2' starts at the black vertex represented by rv''. \n               \n                    Note that bes2' can be empty. If this is the case, then we conclude depending \n                    on the  fact that be is represented or not in the out-going edges of rv''.\n               \n                    If this is not the case, we show that bes2'@[be] is also a suitable black \n                    suffix. *)\n                 case (2 res1' bes2' rv'' bl')\n               \n                 show ?thesis\n                 proof (case_tac \"bes2' = []\")\n                   (* Suppose that bes2' is empty. Then either be is represented in the \n                      out-going edges of rv'', either it is not. *)\n                   assume \"bes2' = []\"\n               \n                   have \"Graph.subpath (black prb') (fst rv) (ui_es res1' @ [be]) bl\"\n                   proof -\n                     have \"Graph.subpath (black prb') (fst rv) (ui_es res1') (src be)\" \n                     proof -\n                       have \"Graph.subpath (black prb') (fst rv') bes2 (src be)\"\n                            using subsum_step(3) \n                                  \\<open>Graph.subpath (black prb) (fst rv') (bes2@[be]) bl\\<close>\n                            by (simp add : Graph.sp_append_one)\n               \n                       moreover\n                       have \"subpath (red prb') rv res1 rv' (subs prb')\"\n                            using subsum_step(3) \\<open>subpath (red prb) rv res1 rv' (subs prb)\\<close>\n                            by (auto simp add : sp_in_extends)\n               \n                       hence \"Graph.subpath (black prb') (fst rv) (ui_es res1) (fst rv')\"\n                             using RB' by (simp add : red_sp_imp_black_sp)\n               \n                       ultimately\n                       show ?thesis \n                            using \\<open>ui_es res1 @ bes2 = ui_es res1' @ bes2'\\<close> \\<open>bes2' = []\\<close>\n                            by (subst (asm) eq_commute) (auto simp add : Graph.sp_append)\n                     qed\n               \n                     moreover\n                     have \"Graph.subpath (black prb') (src be) [be] bl\" \n                          using subsum_step(3) \\<open>Graph.subpath (black prb) (fst rv') (bes2@[be]) bl\\<close>\n                          by (simp add : Graph.sp_append_one Graph.sp_one)\n               \n                     ultimately\n                     show ?thesis by (auto simp add : Graph.sp_append)\n                   qed\n               \n                   hence \"Graph.subpath (black prb') (fst rv) (ui_es res1') (src be)\"\n                   and  \"be \\<in> edges (black prb')\"\n                   and  \"tgt be = bl\"\n                        by (simp_all add : Graph.sp_append_one)\n               \n                   have \"fst rv'' = src be\"\n                   proof -\n                     have \"Graph.subpath (black prb') (fst rv) (ui_es res1') (fst rv'')\"\n                          using \\<open>subpath (red prb') rv res1' rv'' (subs prb')\\<close> \n                                red_sp_imp_black_sp[OF RB']\n                          by fast\n               \n                     thus ?thesis \n                          using \\<open>Graph.subpath (black prb') (fst rv) (ui_es res1') (src be)\\<close>\n                          by (simp add : sp_same_src_imp_same_tgt)\n                   qed\n               \n                   show ?thesis \n                   proof (case_tac \"be \\<in> ui_edge ` out_edges (red prb') rv''\") \n                     (* If be is represented in the out-going edges of rv'' by a red edge that \n                        we call ra. Then ui_es res1'@[be] is entirely represented in the new \n                        red part. Moreover, the configuration at the target of ra subsums c \n                        which is satisfiable, and is in turn also satisfiable and thus not marked, \n                        qed. *)\n                     assume \"be \\<in> ui_edge ` out_edges (red prb') rv''\"\n               \n                     then obtain re where \"be = ui_edge re\"\n                                    and   \"re \\<in> out_edges (red prb') rv''\"\n                          by blast\n               \n                     show ?thesis \n                          unfolding RedBlack_subpaths_from_def Un_iff \n                                    image_def Bex_def mem_Collect_eq\n                          apply (intro disjI1)\n                          apply (rule_tac ?x=\"res1'@[re]\" in exI)\n                          apply (intro conjI)\n                          apply (rule_tac ?x=\"tgt re\" in exI)\n                          proof (intro conjI)\n                            show \"subpath (red prb') rv (res1' @ [re]) (tgt re) (subs prb')\"\n                                 using \\<open>subpath (red prb') rv res1' rv'' (subs prb')\\<close> \n                                       \\<open>re \\<in> out_edges (red prb') rv''\\<close>\n                                 by (simp add : sp_append_one)\n                          next\n                            show \"\\<not> marked prb' (tgt re)\" \n                            proof -                    \n                              have \"sat (confs prb' (tgt re))\" \n                                   proof -\n                                     have \"subpath (red prb') rv (res1'@[re]) (tgt re) (subs prb')\" \n                                          using \\<open>subpath (red prb') rv res1' rv'' (subs prb')\\<close> \n                                                  \\<open>re \\<in> out_edges (red prb') rv''\\<close>\n                                          by (simp add : sp_append_one)\n                                   \n                                     then obtain c \n                                     where se : \"se_star (confs prb' rv) (trace (ui_es (res1'@[re])) \n                                                         (labelling (black prb))) (c)\"\n                                         using subsum_step(3,5,6,7) RB'\n                                               finite_RedBlack.sp_imp_ex_se_star_succ\n                                                      [of prb' rv \"res1'@[re]\" \"tgt re\"]\n                                         unfolding finite_RedBlack_def \n                                         by simp blast\n                                   \n                                     hence \"sat c\"\n                                           proof -\n                                             have \"bes = ui_es (res1'@[re])\" \n                                                  using \\<open>bes = ui_es res1 @ bes2 @ [be]\\<close> \n                                                        \\<open>be = ui_edge re\\<close> \\<open>bes2' = []\\<close>\n                                                        \\<open>ui_es res1 @ bes2 = ui_es res1' @ bes2'\\<close> \n                                                  by simp\n                                           \n                                             thus ?thesis \n                                                  using subsum_step(3) se_star_succs_states[OF se]\n                                                        \\<open>bes \\<in> feasible_subpaths_from (black prb') \n                                                                                   (confs prb' rv) \n                                                                                   (fst rv)\\<close>           \n                                                  by (auto simp add : feasible_def sat_eq)\n                                           qed\n                                   \n                                     moreover\n                                     have \"c \\<sqsubseteq> confs prb' (tgt re)\" \n                                          using subsum_step(3,5,6,7) se \n                                                finite_RedBlack.SE_rel[of prb'] RB'\n                                                \\<open>subpath (red prb') (rv) (res1'@[re]) \n                                                         (tgt re) (subs prb')\\<close> \n                                          by (simp add : finite_RedBlack_def)\n                                   \n                                     ultimately\n                                     show ?thesis by (simp add: sat_sub_by_sat)\n                                   qed\n                          \n                              thus ?thesis \n                                   using \\<open>re \\<in> out_edges (red prb') rv''\\<close> \n                                         sat_not_marked[OF RB', of \"tgt re\"]\n                                   by (auto simp add : vertices_def)\n                            qed\n                          next\n                            show \"bes = ui_es (res1' @ [re])\"\n                            using \\<open>bes = ui_es res1 @ bes2 @ [be]\\<close> \n                                  \\<open>ui_es res1 @ bes2 = ui_es res1' @ bes2'\\<close>\n                                  \\<open>bes2' = []\\<close> \\<open>be = ui_edge re\\<close>\n                            by simp\n                          qed\n                   \n                   next\n                     (* If be is not represented in the out-going edges of rv'', then we show that \n                        [be] is a suitable black suffix, res1' being known to be a suitable red \n                         prefix. *)\n                     assume A : \"be \\<notin> ui_edge ` out_edges (red prb') rv''\"\n                     show ?thesis \n               \n                          unfolding RedBlack_subpaths_from_def Un_iff mem_Collect_eq\n                          apply (intro disjI2)\n                          apply (rule_tac ?x=\"res1'\" in exI)\n                          apply (rule_tac ?x=\"[be]\"  in exI)\n                          proof (intro conjI, goal_cases)\n                          \n                            show \"bes = ui_es res1' @ [be]\"\n                                 using \\<open>bes = ui_es res1 @ bes2 @ [be]\\<close> \n                                       \\<open>ui_es res1 @ bes2 = ui_es res1' @ bes2'\\<close>\n                                       \\<open>bes2' = []\\<close> \n                                 by simp\n                          \n                          next\n                          \n                            case 2 show ?case \n                            apply (rule_tac ?x=\"rv''\" in exI)\n                            proof (intro conjI)\n                          \n                              show \"rv'' \\<in> fringe prb'\" by (rule \\<open>rv'' \\<in> fringe prb'\\<close>)\n                          \n                            next\n                          \n                              show \"subpath (red prb') rv res1' rv'' (subs prb')\"\n                                   by (rule \\<open>subpath (red prb') rv res1' rv'' (subs prb')\\<close>)\n                          \n                            (*next\n                          \n                              show \"\\<not> marked prb' rv''\" by (rule `\\<not> marked prb' rv''`)*)\n                          \n                            next\n                          \n                              show \"\\<not> (\\<exists>res21 bes22. [be] = ui_es res21 @ bes22 \n                                                   \\<and> res21 \\<noteq> [] \n                                                   \\<and> subpath_from (red prb') (rv'') \n                                                                  (res21) (subs prb'))\"\n                              proof (intro notI, elim exE conjE, goal_cases)\n                                case (1 res21 bes22 rv''')\n                          \n                                then obtain re res21' where \"be = ui_edge re\"\n                                                      and   \"res21 = re # res21'\"\n                                     unfolding neq_Nil_conv by auto\n                                \n                                moreover\n                                hence \"re \\<in> out_edges (red prb') rv''\"\n                                      using 1(3) \\<open>rv'' \\<in> fringe prb'\\<close> RB'\n                                      unfolding subsumees_conv by (force simp add : fringe_def \n                                                                                    rb_sp_Cons)\n                                  \n                                ultimately\n                                show False using A by auto\n                              qed\n                          \n                            next\n                          \n                              show \"Graph.subpath_from (black prb') (fst rv'') [be]\"\n                                   using \\<open>Graph.subpath (black prb') (fst rv)(ui_es res1'@[be]) bl\\<close> \n                                         \\<open>fst rv'' = src be\\<close> \n                                   by (auto simp add : Graph.sp_append_one Graph.sp_one)\n                          \n                            qed\n                          qed\n                   qed\n               \n                 next\n                   (* Suppose that bes2' is not empty. Then appending be at the end of bes2' gives a \n                      suitable black suffix, qed. *)\n                   assume \"bes2' \\<noteq> []\"\n               \n                   then obtain be' bes2'' where \"bes2' = be' # bes2''\"\n                        unfolding neq_Nil_conv by blast\n               \n                   show ?thesis \n                        unfolding RedBlack_subpaths_from_def Un_iff mem_Collect_eq\n                        apply (intro disjI2)\n                        apply (rule_tac ?x=\"res1'\" in exI)\n                        apply (rule_tac ?x=\"bes2'@[be]\" in exI)\n                        proof (intro conjI, goal_cases)\n                        \n                          show \"bes = ui_es res1' @ bes2' @ [be]\"\n                          using \\<open>bes = ui_es res1 @ bes2 @ [be]\\<close> \n                                \\<open>ui_es res1 @ bes2 = ui_es res1' @ bes2'\\<close>\n                          by simp\n                        \n                        next\n                        \n                          case 2 show ?case \n                              apply (rule_tac ?x=\"rv''\" in exI)\n                              proof (intro conjI)\n                              \n                                show \" rv'' \\<in> fringe prb'\" by (rule \\<open> rv'' \\<in> fringe prb'\\<close>)\n                              \n                              next\n                              \n                                show \"subpath (red prb') rv res1' rv'' (subs prb')\"\n                                     by (rule \\<open>subpath (red prb') rv res1' rv'' (subs prb')\\<close>)\n                              \n                              next\n                              \n                                show \"\\<not> (\\<exists>res21 bes22. bes2' @ [be] = ui_es res21 @ bes22 \n                                                     \\<and> res21 \\<noteq> [] \n                                                     \\<and> subpath_from (red prb') (rv'') \n                                                                    (res21) (subs prb'))\"\n                                proof (intro notI, elim exE conjE, goal_cases)\n                                  case (1 res21 bes22 rv''')\n                              \n                                  then obtain re res21' where \"res21 = re # res21'\"\n                                                        and   \"be' = ui_edge re\"\n                                  using \\<open>bes2' = be' # bes2''\\<close> unfolding neq_Nil_conv by auto\n                              \n                                  show False \n                                       using \\<open>\\<not> (\\<exists>res21 bes22. bes2' = ui_es res21 @ bes22 \n                                                             \\<and> res21 \\<noteq> [] \n                                                             \\<and> subpath_from (red prb') (rv'') \n                                                                             (res21) (subs prb'))\\<close>\n                                       apply (elim notE)\n                                       apply (rule_tac ?x=\"[re]\" in exI)\n                                       apply (rule_tac ?x=\"bes2''\" in exI)\n                                       proof (intro conjI)\n                                         show \"bes2' = ui_es [re] @ bes2''\"\n                                              using \\<open>bes2' @ [be] = ui_es res21 @ bes22\\<close> \n                                                    \\<open>bes2' = be' # bes2''\\<close>\n                                                    \\<open>be' = ui_edge re\\<close>\n                                              by simp\n                                       next\n                                         show \"[re] \\<noteq> []\" by simp\n                                       next\n                                         show \"subpath_from (red prb') rv'' [re] (subs prb')\"\n                                              using \\<open>subpath (red prb') rv'' res21 rv'''(subs prb')\\<close> \n                                                    \\<open>res21 = re # res21'\\<close>\n                                              by (fastforce simp add : sp_Cons Nil_sp vertices_def)\n                                       qed\n                                qed\n                              \n                              next\n                              \n                                show \"Graph.subpath_from (black prb') (fst rv'') (bes2' @ [be])\"\n                                proof -\n                                  have \"Graph.subpath (black prb') (fst rv) \n                                                      (ui_es res1' @ bes2') (src be)\"\n                                  proof -\n                                    have \"Graph.subpath (black prb') (fst rv) \n                                                        (ui_es res1 @ bes2) (src be)\"\n                                         using \\<open>bes \\<in> feasible_subpaths_from (black prb') \n                                                                             (confs prb' rv) \n                                                                             (fst rv)\\<close>\n                                               \\<open>bes = ui_es res1 @ bes2 @ [be]\\<close>\n                                         by (auto simp add : Graph.sp_append Graph.sp_one)\n                              \n                                    thus ?thesis using \\<open>ui_es res1 @ bes2 = ui_es res1'@bes2'\\<close> \n                                                 by simp\n                                  qed\n                              \n                                  moreover\n                                  have \"Graph.subpath (black prb')(fst rv)(ui_es res1' @ bes2') bl'\"\n                                       using \\<open>Graph.subpath (black prb') (fst rv'') bes2' bl'\\<close>\n                                             red_sp_imp_black_sp[OF RB' \n                                                                   \\<open>subpath (red prb')(rv)(res1') \n                                                                            (rv'') (subs prb')\\<close>]\n                                       by (auto simp add : Graph.sp_append)\n                                  \n                                  ultimately\n                                       have \"src be = bl'\" by (rule sp_same_src_imp_same_tgt)\n                              \n                                  moreover\n                                  have \"Graph.subpath (black prb') (src be) [be] (tgt be)\" \n                                       using subsum_step(3) \n                                             \\<open>Graph.subpath (black prb) (fst rv') (bes2@[be]) bl\\<close> \n                                       by (auto simp add : Graph.sp_append_one Graph.sp_one)\n                              \n                                  ultimately\n                                  show ?thesis \n                                       using \\<open>Graph.subpath (black prb') (fst rv'') bes2' bl'\\<close>\n                                       by (simp add : Graph.sp_append_one Graph.sp_one)\n                                qed\n                              qed\n                        qed\n                 qed\n               qed\n        qed\n          \n      next\n        (* Suppose that rv' is not the newly subsumed red vertex. Hence, rv' is still not marked \n           and in the fringe and res1 is still maximal, which makes res1 and bes2 suitable red \n           prefix and black suffix in the new red part. *)\n        assume \"rv' \\<noteq> subsumee sub\"\n        \n        show ?thesis\n             unfolding RedBlack_subpaths_from_def Un_iff mem_Collect_eq\n             apply (intro disjI2)\n             apply (rule_tac ?x=\"res1\" in exI)\n             apply (rule_tac ?x=\"bes2\" in exI)\n             proof (intro conjI, goal_cases)\n               show \"bes = ui_es res1 @ bes2\" by (rule \\<open>bes = ui_es res1 @ bes2\\<close>)\n             next\n             \n               case 2 show ?case\n               apply (rule_tac ?x=\"rv'\" in exI)\n               proof (intro conjI)\n                 show \"rv'\\<in> fringe prb'\" \n                 using subsum_step(3) subsumE_fringe[OF subsum_step(3)] B \\<open>rv' \\<noteq> subsumee sub\\<close> \n                 by simp\n               next\n                 show \"subpath (red prb') rv res1 rv' (subs prb')\" \n                 using subsum_step(3) C by (auto simp add : sp_in_extends)\n               (*next\n                 show \"\\<not> marked prb' rv'\" using subsum_step(3) D by auto*)\n               next\n                 show \"\\<not> (\\<exists>res21 bes22. bes2 = ui_es res21 @ bes22 \n                                      \\<and> res21 \\<noteq> [] \n                                      \\<and> subpath_from (red prb') rv' res21 (subs prb'))\"\n                 proof (intro notI, elim exE conjE)\n                   fix res21 bes22 rv''\n             \n                   assume \"bes2 = ui_es res21 @ bes22\"\n                   and    \"res21 \\<noteq> []\"\n                   and    \"subpath (red prb') rv' res21 rv'' (subs prb')\"\n             \n                   then obtain re res21' where \"res21 = re # res21'\" \n                   unfolding neq_Nil_conv by blast\n             \n                   have \"subpath (red prb) rv' [re] (tgt re) (subs prb)\"\n                   proof -\n                     have \"\\<not> uses_sub rv' [re] (tgt re) sub\" using \\<open>rv' \\<noteq> subsumee sub\\<close> by auto\n             \n                     thus ?thesis \n                     using subsum_step(3)\n                         \\<open>subpath (red prb') rv' res21 rv'' (subs prb')\\<close> \\<open>res21 = re # res21'\\<close>\n                         wf_sub_rel_of.sp_in_extends_not_using_sub\n                         [OF subs_wf_sub_rel_of[OF subsum_step(1)],\n                          of \"subsumee sub\" \"subsumer sub\" \"subs prb'\" rv' \"[re]\" \"tgt re\"]\n                         rb_sp_Cons[OF RB', of rv' re res21' rv'']\n                         rb_sp_one[OF subsum_step(1), of rv' re \"tgt re\"]\n                         subs_sub_rel_of[OF subsum_step(1)]\n                     by auto\n                   qed\n             \n                   show False\n                   using E\n                   apply (elim notE)\n                   apply (rule_tac ?x=\"[re]\" in exI)\n                   apply (rule_tac ?x=\"ui_es res21'@bes22\" in exI)\n                   proof (intro conjI)\n                     show \"bes2 = ui_es [re] @ ui_es res21' @ bes22\"\n                     using \\<open>bes2 = ui_es res21 @ bes22\\<close> \\<open>res21 = re # res21'\\<close> by simp\n                   next\n                     show \"[re] \\<noteq> []\" by simp\n                   next\n                     show \"subpath_from (red prb) rv' [re] (subs prb)\"\n                     apply (rule_tac ?x=\"tgt re\" in exI)\n                     using subsum_step(3)\n                         \\<open>rv' \\<noteq> subsumee sub\\<close> \\<open>subpath (red prb') rv' res21 rv'' (subs prb')\\<close>\n                         \\<open>res21 = re # res21'\\<close>\n                         rb_sp_Cons[OF RB', of rv' re res21' rv'']\n                         rb_sp_one[OF subsum_step(1), of rv' re \"tgt re\"]\n                         subs_sub_rel_of[OF subsum_step(1)] subs_sub_rel_of[OF RB']\n                     by fastforce\n                   qed\n                 qed\n               next\n                 show \"Graph.subpath_from (black prb') (fst rv') bes2\" \n                 using subsum_step(3) F by simp blast\n               qed\n             qed\n      qed\n    qed\n  qed\n\nnext \n\n  case (abstract_step prb rv2 c\\<^sub>a prb' rv1)\n    have RB' : \"RedBlack prb'\" by (rule RedBlack.abstract_step[OF abstract_step(1,3)])\n    have \"finite_RedBlack prb\" using abstract_step by (auto simp add : finite_RedBlack_def)\n    show ?case\n    unfolding subset_iff\n    proof (intro allI impI)\n      (* Suppose that bes is a feasible subpath starting at the black vertex represented by the red \n         vertex rv1. We proceed depending on the fact that rv1 is the red vertex where the abstrac-\n         tion  took place or not. We have to make this distinction to be able to use our IH, in the \n         case where rv1 \\<noteq> rv2. *)\n      fix bes\n    \n      assume \"bes \\<in> feasible_subpaths_from (black prb') (confs prb' rv1) (fst rv1)\"\n      \n      show \"bes \\<in> RedBlack_subpaths_from prb' rv1\" \n      proof (case_tac \"rv2 = rv1\")\n        (* If this is the case, then the only possible red prefix is the empty edge sequence. By \n           definition of the abstraction operator, we have that the empty sequence is indeed a \n           suitable red prefix and that bes is suitable black prefix. *)\n        assume \"rv2 = rv1\"\n    \n        show ?thesis \n             proof (case_tac \"out_edges (black prb') (fst rv1) = {}\")\n               assume \"out_edges (black prb') (fst rv1) = {}\"\n               show ?thesis\n                     unfolding RedBlack_subpaths_from_def Un_iff image_def Bex_def mem_Collect_eq\n                     apply (intro disjI1)\n                     apply (rule_tac ?x=\"[]\" in exI)\n                     apply (intro conjI)\n                      apply (rule_tac ?x=\"rv1\" in exI)\n                      proof (intro conjI)\n                        show \"subpath (red prb') rv1 [] rv1 (subs prb')\"\n                        using abstract_step(4) rb_Nil_sp[OF RB'] by fast\n                      next\n                        show \"\\<not> marked prb' rv1\" using abstract_step(3) \\<open>rv2 = rv1\\<close> by simp\n                      next\n                        show \"bes = ui_es []\"\n                        using \\<open>bes \\<in> feasible_subpaths_from (black prb') (confs prb' rv1) (fst rv1)\\<close>\n                              \\<open>out_edges (black prb') (fst rv1) = {}\\<close>\n                        by (cases bes) (auto simp add : Graph.sp_Cons)\n                      qed\n                \n             next\n               assume \"out_edges (black prb') (fst rv1) \\<noteq> {}\"\n               \n               show ?thesis \n               unfolding RedBlack_subpaths_from_def Un_iff mem_Collect_eq\n               apply (intro disjI2)\n               apply (rule_tac ?x=\"[]\"  in exI)\n               apply (rule_tac ?x=\"bes\" in exI)\n               proof (intro conjI, goal_cases)\n             \n                 show \"bes = ui_es [] @ bes\" by simp\n             \n               next\n             \n                 case 2 show ?case \n                 apply (rule_tac ?x=\"rv1\" in exI)\n                 proof (intro conjI)\n             \n                   show \"rv1 \\<in> fringe prb'\" \n                   using abstract_step(1,3) \\<open>rv2 = rv1\\<close> \\<open>out_edges (black prb') (fst rv1) \\<noteq> {}\\<close>\n                   by (auto simp add : fringe_def)\n             \n                 next\n             \n                   show \"subpath (red prb') rv1 [] rv1 (subs prb')\" \n                   using abstract_step(3) \\<open>rv2 = rv1\\<close> \n                         rb_Nil_sp[OF RedBlack.abstract_step[OF abstract_step(1,3)]]\n                   by auto\n             \n                 (*next\n             \n                   show \"\\<not> marked prb' rv1\"  using abstract_step(3) `rv2 = rv1` by simp*)\n             \n                 next\n             \n                   show \"\\<not> (\\<exists>res21 bes22. bes = ui_es res21 @ bes22 \n                                        \\<and> res21 \\<noteq> [] \n                                        \\<and> subpath_from (red prb') rv1 res21 (subs prb'))\"\n                   proof (intro notI, elim exE conjE)\n                     fix res21 rv3\n             \n                     assume \"res21 \\<noteq> []\" \n                     and    \"subpath (red prb') rv1 res21 rv3 (subs prb')\"\n             \n                     moreover\n                     then obtain re res21' where \"res21 = re # res21'\" \n                          unfolding neq_Nil_conv by blast\n             \n                     ultimately\n                     have \"re \\<in> out_edges (red prb') rv1\"\n                     using abstract_step(3) \\<open>rv2 = rv1\\<close>\n                           rb_sp_Cons[OF RedBlack.abstract_step[OF abstract_step(1,3)], \n                                      of rv1 re res21' rv3]\n                     unfolding subsumees_conv by fastforce\n             \n                     thus False using abstract_step(3) \\<open>rv2 = rv1\\<close> by auto\n                   qed\n             \n                 next\n             \n                   show \"Graph.subpath_from (black prb') (fst rv1) bes\"\n                   using \\<open>bes \\<in> feasible_subpaths_from (black prb') (confs prb' rv1) (fst rv1)\\<close>\n                   by simp\n             \n                 qed\n               qed\n             qed\n             \n      next\n        (* Suppose that rv1 is not the red vertex where the abstraction took place. Then, as \n           abstracting a configuration has no effect on the rest of the red tree, we can show by IH \n           that bes is red-black supbeth of the old red-black graph. We conclude by case \n            distinction. *)\n        assume \"rv2 \\<noteq> rv1\"\n    \n        moreover\n        hence \"feasible (confs prb rv1) (trace bes (labelling (black prb)))\"\n              using abstract_step(3) \n                    \\<open>bes \\<in> feasible_subpaths_from (black prb') (confs prb' rv1) (fst rv1)\\<close>\n              by simp \n    \n        ultimately\n        have \"bes \\<in> RedBlack_subpaths_from prb rv1\"\n              using abstract_step(2)[of rv1] abstract_step(3-7)\n                    \\<open>bes \\<in> feasible_subpaths_from (black prb') (confs prb' rv1) (fst rv1)\\<close>\n              by auto\n    \n        thus ?thesis \n             apply (subst (asm) RedBlack_subpaths_from_def)\n             unfolding Un_iff image_def Bex_def mem_Collect_eq\n             proof (elim disjE exE conjE)\n             \n               fix res rv3\n             \n               assume \" bes = ui_es res\"\n               and    \"subpath (red prb) rv1 res rv3 (subs prb)\"\n               and    \"\\<not> marked prb rv3\"\n             \n               thus ?thesis \n               using abstract_step(3)\n               unfolding RedBlack_subpaths_from_def Un_iff image_def Bex_def mem_Collect_eq\n               by (intro disjI1, rule_tac ?x=\"res\" in exI, intro conjI)\n                  (rule_tac ?x=\"rv3\" in exI, simp_all)\n             next\n             \n               fix res1 bes2 rv3 bl\n               assume A : \"bes = ui_es res1 @ bes2\"\n               and    B : \"rv3 \\<in> fringe prb\"\n               and    C : \"subpath (red prb) rv1 res1 rv3 (subs prb)\"\n               and    E : \"\\<not> (\\<exists>res21 bes22. bes2 = ui_es res21 @ bes22 \n                                      \\<and> res21 \\<noteq> [] \n                                      \\<and> subpath_from (red prb) rv3 res21 (subs prb))\"\n               and    F : \"Graph.subpath (black prb) (fst rv3) bes2 bl\"\n             \n               show ?thesis \n                    unfolding RedBlack_subpaths_from_def Un_iff mem_Collect_eq\n                    apply (intro disjI2)\n                    apply (rule_tac ?x=\"res1\" in exI)\n                    apply (rule_tac ?x=\"bes2\" in exI)\n                    proof (intro conjI, goal_cases)\n                      show \"bes = ui_es res1 @ bes2\" by (rule \\<open>bes = ui_es res1 @ bes2\\<close>)\n                    next\n                      case 2 show ?case\n                      using abstract_step(3) B C E F unfolding fringe_def\n                      by (rule_tac ?x=\"rv3\" in exI) auto\n                    qed\n             qed\n      qed\n    qed\n\nnext\n  (* Strengthening a configuration with an invariant will help refuse \"brutal\" abstractions. As \n     all abstractions preserves the set of feasible paths, we conclude. *)\n  case (strengthen_step prb rv2 e prb' rv1)\n  show?case\n       unfolding subset_iff\n       proof (intro allI impI)\n     \n         fix bes \n         assume \"bes \\<in> feasible_subpaths_from (black prb') (confs prb' rv1) (fst rv1)\"\n         hence  \"bes \\<in> RedBlack_subpaths_from prb rv1\"\n                using strengthen_step(2)[of rv1] strengthen_step(3-7) by auto\n     \n         thus \"bes \\<in> RedBlack_subpaths_from prb' rv1\"\n         apply (subst (asm) RedBlack_subpaths_from_def)\n         unfolding Un_iff image_def Bex_def mem_Collect_eq\n         proof (elim disjE exE conjE)\n     \n           fix res rv2\n           assume \"bes = ui_es res\"\n           and    \"subpath (red prb) rv1 res rv2 (subs prb)\"\n           and    \"\\<not> marked prb rv2\"\n           thus ?thesis \n                using strengthen_step(3)\n                unfolding RedBlack_subpaths_from_def Un_iff image_def Bex_def mem_Collect_eq\n                by (intro disjI1) fastforce\n     \n         next\n     \n           fix res1 bes2 rv3 bl\n     \n           assume A : \"bes = ui_es res1 @ bes2\"\n           and    B : \"rv3 \\<in> fringe prb\"\n           and    C : \"subpath (red prb) rv1 res1 rv3 (subs prb)\"\n           (*and    D : \"\\<not> marked prb rv3\"*)\n           and    E : \"\\<not> (\\<exists>res21 bes22. bes2 = ui_es res21 @ bes22 \n                                  \\<and> res21 \\<noteq> [] \n                                  \\<and> subpath_from (red prb) rv3 res21 (subs prb))\"\n           and    F : \"Graph.subpath (black prb) (fst rv3) bes2 bl\"\n     \n           show ?thesis \n                unfolding RedBlack_subpaths_from_def Un_iff mem_Collect_eq\n                apply (intro disjI2)\n                apply (rule_tac ?x=\"res1\" in exI)\n                apply (rule_tac ?x=\"bes2\" in exI)\n                proof (intro conjI, goal_cases)\n                  show \"bes = ui_es res1 @ bes2\" by (rule \\<open>bes = ui_es res1 @ bes2\\<close>)\n                next\n                  case 2 \n                  show ?case\n                       using strengthen_step(3) B C E F unfolding fringe_def \n                       by (rule_tac ?x=\"rv3\" in exI) auto\n                qed\n     \n         qed\n       qed\nqed\n\n\ntext \\<open>Red-black paths being red-black sub-path starting from the red root, and feasible paths \nbeing feasible sub-paths starting at the black initial location, it follows from the previous \ntheorem that the set of feasible paths when considering the configuration of the root is a \nsubset of the set of red-black paths.\\<close>\n\ntheorem (in finite_RedBlack) feasible_path_inclusion :\n  assumes \"RedBlack prb\"\n  shows   \"feasible_paths (black prb) (confs prb (root (red prb))) \\<subseteq> RedBlack_paths prb\"\nusing feasible_subpaths_preserved[OF assms, of \"root (red prb)\"] consistent_roots[OF assms]\nby (simp add : vertices_def)\n\ntext \\<open>The configuration at the red root might have been abstracted. In this case, the initial \nconfiguration is subsumed by the current configuration at the root. Thus the set of feasible paths \nwhen considering the initial configuration is also a subset of the set of red-black paths.\\<close>\n\nlemma init_subsumed :\n  assumes \"RedBlack prb\"\n  shows   \"init_conf prb \\<sqsubseteq> confs prb (root (red prb))\"\nusing assms\nproof (induct prb)\n  case base thus ?case by (simp add: subsums_refl)\nnext\n  case se_step thus ?case by (force simp add : vertices_def)\nnext\n  case mark_step thus ?case by simp\nnext\n  case subsum_step thus ?case by simp\nnext\n  case (abstract_step prb rv c\\<^sub>a prb')\n  thus ?case by (auto simp add : abstract_def subsums_trans)\nnext\n  case strengthen_step thus ?case by simp\nqed\n\n\ntheorem (in finite_RedBlack) feasible_path_inclusion_from_init :\n  assumes \"RedBlack prb\"\n  shows   \"feasible_paths (black prb) (init_conf prb) \\<subseteq> RedBlack_paths prb\"\nunfolding subset_iff mem_Collect_eq\nproof (intro allI impI, elim exE conjE, goal_cases)\n  case (1 es bl)\n\n  hence \"es \\<in> feasible_subpaths_from (black prb) (init_conf prb) (fst (root (red prb)))\"\n        using consistent_roots[OF assms] by simp blast\n\n  hence \"es \\<in> feasible_subpaths_from (black prb) (confs prb (root (red prb))) (fst(root(red prb)))\"\n        unfolding mem_Collect_eq\n        proof (elim exE conjE, goal_cases)\n          case (1 bl')\n       \n          show ?case \n          proof (rule_tac ?x=\"bl'\" in exI, intro conjI)\n            show \"Graph.subpath (black prb) (fst (root (red prb))) es bl'\" by (rule 1(1))\n          next\n            have \"finite_labels (trace es (labelling (black prb)))\"\n                 using finite_RedBlack by auto\n       \n            moreover\n            have \"finite (pred (confs prb (root (red prb))))\"\n                 using finite_RedBlack finite_pred[OF assms]\n                 by (auto simp add : vertices_def finite_RedBlack_def)\n            \n            moreover\n            have \"finite (pred (init_conf prb))\"\n                 using assms by (intro finite_init_pred)\n       \n            moreover\n            have \"\\<forall>e\\<in>pred (confs prb (root (red prb))). finite (Bexp.vars e)\"\n                 using finite_RedBlack finite_pred_constr_symvars[OF assms]\n                 by (fastforce simp add : finite_RedBlack_def vertices_def)\n       \n            moreover\n                 have \"\\<forall>e\\<in>pred (init_conf prb). finite (Bexp.vars e)\"\n                 using assms by (intro finite_init_pred_symvars)\n       \n            moreover\n                 have \"init_conf prb \\<sqsubseteq> confs prb (root (red prb))\"\n                 using assms by (rule init_subsumed)\n       \n            ultimately\n            show \"feasible (confs prb (root (red prb))) (trace es (labelling (black prb)))\" \n                 using 1(2) by (rule subsums_imp_feasible)\n          qed\n        qed\n      \n  thus ?case \n       using feasible_subpaths_preserved[OF assms, of \"root (red prb)\"]\n       by (auto simp add : vertices_def)\nqed\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/InfPathElimination/RB.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526368038304, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.2693599255257554}}
{"text": "(*  Title:       Lightweight Java, the equivalence functions\n    Authors:     Rok Strnisa <rok@strnisa.com>, 2006\n                 Matthew Parkinson <matt@matthewp.com>, 2006\n    Maintainer:  \n*)\n\ntheory Lightweight_Java_Equivalence imports Lightweight_Java_Definition begin\n\n(* BEGIN: HELPER FUNCTIONS *)\n\nlemma map_id[simp]: \"map id list = list\" by (induct list) auto\n\nlemma id_map_two[simp]: \"map (\\<lambda>(x,y). (x,y)) list = list\" by (induct list) auto\n\nlemma id_image_two[simp]: \"(\\<lambda>(x,y). (x,y)) ` set list = set list\" by (induct list) auto\n\nlemma map_fst[simp]: \"map (\\<lambda>(x, y). x) list = map fst list\" by (induct list) auto\n\nlemma map_snd[simp]: \"map (\\<lambda>(x, y). y) list = map snd list\" by (induct list) auto\n\nlemma zip_map_map_two [simp]: \"zip (map fst list) (map snd list) = list\"\nby (induct list) auto\n\nlemma concat_map_singlton [simp]: \"concat (map (\\<lambda>e. [e]) list) = list\"\nby (induct list) simp_all\n\nlemma list_all_map_P [simp]: \"list_all (\\<lambda>b. b) (map (\\<lambda>x. P x) list) = (\\<forall>x \\<in> set list. P x)\"\nby (induct list) simp_all\n\nlemma dom_single[simp]: \"a : dom (empty(k \\<mapsto> v)) = (a = k)\"\nby (simp add: dom_def)\n\nlemma predicted_lu[rule_format, simp]:\n  \"x \\<in> set list \\<longrightarrow> map_of (map (\\<lambda>key. (key, value)) list) x = Some value\"\nby (induct list) auto\n\nlemma key_in_map1[simp]: \"k \\<notin> dom M' \\<Longrightarrow> (M ++ M') k = M k\"\napply (subgoal_tac \"M' k = None\")\napply (simp add: map_add_def, force simp add: domI)\ndone\n\nlemma forall_cons [rule_format]: \"(\\<forall>x \\<in> set (s#S). P x) \\<and> y \\<in> set S \\<longrightarrow> P y\"\nby (induct_tac S) simp_all\n\nlemma mem_cong[rule_format]:\n  \"x \\<in> set list \\<longrightarrow> (f x \\<in> set (map f list))\"\nby (induct list) auto\n\nlemma forall_union: \"\\<lbrakk>\\<forall>a \\<in> dom A. P (A a); \\<forall>b \\<in> dom B. P (B b)\\<rbrakk> \\<Longrightarrow> \\<forall>x \\<in> dom A \\<union> dom B. P ((B ++ A) x)\"\napply(safe)\n apply(force)\napply(drule_tac x = x in bspec, simp add: domI)\napply(case_tac \"A x = None\")\n apply(force simp add: map_add_def)\nby (force)\n\n(* END: HELPER FUNCTIONS *)\n\ndefinition\nclass_name_f :: \"cld \\<Rightarrow> dcl\"\nwhere\n\"class_name_f cld =\n  (case cld of cld_def dcl cl fds mds \\<Rightarrow> dcl)\"\n\n\ndefinition\nsuperclass_name_f :: \"cld \\<Rightarrow> cl\"\nwhere\n\"superclass_name_f cld =\n  (case cld of cld_def dcl cl fds mds \\<Rightarrow> cl)\"\nlemma [simp]: \"(superclass_name cld cl) = (superclass_name_f cld = cl)\"\nby (force simp add: superclass_name_f_def split: cld.splits\n          intro: superclass_nameI elim: superclass_name.cases)\n\ndefinition\nclass_fields_f :: \"cld \\<Rightarrow> fds\"\nwhere\n\"class_fields_f cld =\n  (case cld of cld_def dcl cl fds mds \\<Rightarrow> fds)\"\nlemma [simp]: \"(class_fields cld fds) = (class_fields_f cld = fds)\"\nby (force simp add: class_fields_f_def split: cld.splits\n          intro: class_fieldsI elim: class_fields.cases)\n\ndefinition\nclass_methods_f :: \"cld \\<Rightarrow> meth_defs\"\nwhere\n\"class_methods_f cld =\n  (case cld of cld_def dcl cl fds mds \\<Rightarrow> mds)\"\nlemma [simp]: \"(class_methods cld fds) = (class_methods_f cld = fds)\"\nby (force simp add: class_methods_f_def split: cld.splits\n          intro: class_methodsI elim: class_methods.cases)\n\ndefinition\nmethod_name_f :: \"meth_def \\<Rightarrow> meth\"\nwhere\n\"method_name_f md =\n  (case md of meth_def_def meth_sig meth_body \\<Rightarrow>\n  (case meth_sig of meth_sig_def cl meth vds \\<Rightarrow> meth))\"\nlemma [simp]: \"(method_name md m) = (method_name_f md = m)\"\nby (force simp add: method_name_f_def split: meth_def.splits meth_sig.splits\n          intro: method_nameI elim: method_name.cases)\n\ndefinition\ndistinct_names_f :: \"P \\<Rightarrow> bool\"\nwhere\n\"distinct_names_f P =\n  (distinct (map class_name_f P))\"\nlemma distinct_names_map[rule_format]:\n  \"(\\<forall>x\\<in>set cld_dcl_list. split (\\<lambda>cld. op = (class_name_f cld)) x) \\<and> distinct (map snd cld_dcl_list)\n      \\<longrightarrow> distinct_names_f (map fst cld_dcl_list)\"\napply(induct cld_dcl_list)\n apply(clarsimp simp add: distinct_names_f_def)+ apply(force)\ndone\nlemma [simp]: \"(distinct_names P) = (distinct_names_f P)\"\napply(rule)\n apply(erule distinct_names.cases) apply(clarsimp simp add: distinct_names_map)\napply(simp add: distinct_names_f_def)\napply(rule_tac cld_dcl_list = \"map (\\<lambda>cld. (cld, class_name_f cld)) P\" in dn_defI)\n  apply(simp) apply(induct P) apply(simp) apply(simp)\n apply(clarsimp)\napply(clarsimp) apply(induct P) apply(simp) apply(force)\ndone\n\nprimrec\nfind_cld_f :: \"P \\<Rightarrow> ctx \\<Rightarrow> fqn \\<Rightarrow> ctxcld_opt\"\nwhere\n\"find_cld_f []         ctx fqn = None\" |\n\"find_cld_f (cld#clds) ctx fqn =\n  (case cld of cld_def dcl cl fds mds \\<Rightarrow>\n  (case fqn of fqn_def dcl' \\<Rightarrow>\n  (if dcl = dcl' then Some (ctx, cld) else find_cld_f clds ctx fqn)))\"\nlemma [simp]: \"(find_cld P ctx fqn ctxcld_opt) = (find_cld_f P ctx fqn = ctxcld_opt)\"\napply(rule)\n apply(induct rule: find_cld.induct) apply(simp+)\n apply(clarsimp)\napply(induct P)\n apply(simp add: fc_emptyI)\napply(case_tac fqn) apply(rename_tac cld clds dcl) apply(case_tac cld)\napply(clarsimp) apply(rename_tac dcl' cl' vds' mds') apply(rule)\napply(clarsimp) apply(rule fc_cons_trueI) apply(simp) apply(force)\napply(force intro: fc_cons_falseI[simplified])\ndone\n\nlemma find_to_mem[rule_format]:\n  \"find_cld_f P ctx fqn = Some (ctx', cld) \\<longrightarrow> cld : set P\"\napply(induct P) by (clarsimp split: cld.splits fqn.splits)+\n\nlemma find_cld_name_eq[rule_format]:\n  \"\\<forall>ctxcld. find_cld_f P ctx (fqn_def dcl) = Some ctxcld \\<longrightarrow> (\\<exists>cl fds mds. (ctx, cld_def dcl cl fds mds) = ctxcld)\"\napply(induct P) apply(simp) apply(clarsimp split: cld.splits fqn.splits) done\n\nprimrec\nfind_type_f :: \"P \\<Rightarrow> ctx \\<Rightarrow> cl \\<Rightarrow> ty_opt\"\nwhere\n\"find_type_f P ctx cl_object = Some ty_top\" |\n\"find_type_f P ctx (cl_fqn fqn) =\n  (case fqn of fqn_def dcl \\<Rightarrow>\n  (case find_cld_f P ctx fqn of None \\<Rightarrow> None | Some (ctx', cld) \\<Rightarrow>\n     Some (ty_def ctx' dcl)))\"\nlemma [simp]: \"(find_type P ctx cl ty_opt) = (find_type_f P ctx cl = ty_opt)\"\napply(rule)\n apply(force elim: find_type.cases split: fqn.splits)\napply(case_tac cl) apply(force intro: ft_objI)\napply(rename_tac fqn)\napply(case_tac fqn) apply(clarsimp)\napply(split option.splits) apply(rule)\n apply(force intro: ft_nullI)\nby (force intro: ft_dclI)\n\nlemma mem_remove: \"cld : set P \\<Longrightarrow> length (remove1 cld P) < length P\"\napply(induct P) by(simp, force split: split_if_asm)\n\nlemma finite_program[rule_format, intro]:\n  \"\\<forall>P cld. (\\<exists>ctx ctx' fqn. find_cld_f P ctx fqn = Some (ctx', cld)) \\<longrightarrow>\n      length (remove1 cld P) < length P\"\napply(clarsimp) apply(drule find_to_mem) by (simp add: mem_remove)\n\nlemma path_length_eq[rule_format]:\n  \"path_length P ctx cl nn \\<Longrightarrow> \\<forall>nn'. path_length P ctx cl nn' \\<longrightarrow> nn = nn'\"\napply(erule path_length.induct)\n apply(clarsimp) apply(erule path_length.cases) apply(simp) apply(simp)\napply(rule) apply(rule)\napply(erule_tac ?a4.0 = nn' in path_length.cases) apply(clarify)\napply(clarsimp)\ndone\n\nlemma fpr_termination[iff]:\n  \"\\<forall>P cld ctx ctx' fqn. find_cld_f P ctx fqn = Some (ctx', cld) \\<and> acyclic_clds P\n       \\<longrightarrow> The (path_length P ctx' (superclass_name_f cld)) < The (path_length P ctx (cl_fqn fqn))\"\napply(clarsimp)\napply(erule acyclic_clds.cases) apply(clarsimp) apply(rename_tac P)\napply(erule_tac x = ctx in allE)\napply(erule_tac x = fqn in allE)\napply(clarsimp)\napply(rule theI2) apply(simp) apply(simp add: path_length_eq)\napply(erule path_length.cases) apply(simp) apply(clarsimp)\napply(rule theI2) apply(simp) apply(simp add: path_length_eq)\napply(drule_tac path_length_eq, simp)\napply(erule path_length.cases) apply(simp) apply(clarsimp)\napply(drule_tac path_length_eq, simp) apply(simp)\ndone\n\nfunction\nfind_path_rec_f :: \"P \\<Rightarrow> ctx \\<Rightarrow> cl \\<Rightarrow> ctxclds \\<Rightarrow> ctxclds_opt\"\nwhere\n\"find_path_rec_f P ctx  cl_object   path = Some path\" |\n\"find_path_rec_f P ctx (cl_fqn fqn) path =\n  (if ~(acyclic_clds P) then None else\n  (case find_cld_f P ctx fqn of None \\<Rightarrow> None | Some (ctx', cld) \\<Rightarrow>\n   find_path_rec_f P ctx'\n                    (superclass_name_f cld) (path @ [(ctx',cld)])))\"\nby pat_completeness auto\ntermination\nby (relation \"measure (\\<lambda>(P, ctx, cl, path). (THE nn. path_length P ctx cl nn))\") auto\n\nlemma [simp]: \"(find_path_rec P ctx cl path path_opt) = (find_path_rec_f P ctx cl path = path_opt)\"\napply(rule)\n apply(erule find_path_rec.induct) apply(simp)+\napply(induct rule: find_path_rec_f.induct)\n apply(clarsimp simp add: fpr_objI)\napply(clarsimp) apply(rule)\n apply(simp add: fpr_nullI)\napply(clarsimp split: option.splits)\napply(rule fpr_nullI)\n apply(simp add: fpr_nullI)\napply(rule fpr_fqnI) apply(force)+\ndone\n\ndefinition\nfind_path_f :: \"P \\<Rightarrow> ctx \\<Rightarrow> cl \\<Rightarrow> ctxclds_opt\"\nwhere\n\"find_path_f P ctx cl = find_path_rec_f P ctx cl []\"\nlemma [simp]: \"(find_path P ctx cl path_opt) = (find_path_f P ctx cl = path_opt)\"\napply(rule)\n apply(erule find_path.cases) apply(unfold find_path_f_def) apply(simp)\napply(simp add: fp_defI)\ndone\n\nprimrec\nfind_path_ty_f :: \"P \\<Rightarrow> ty \\<Rightarrow> ctxclds_opt\"\nwhere\n\"find_path_ty_f P  ty_top          = Some []\" |\n\"find_path_ty_f P (ty_def ctx dcl) =\n   find_path_f P ctx (cl_fqn (fqn_def dcl))\"\nlemma [simp]: \"(find_path_ty P ty ctxclds_opt) = (find_path_ty_f P ty = ctxclds_opt)\"\napply(rule)\n apply(force elim: find_path_ty.cases)\napply(case_tac ty)\n apply(clarsimp simp add: fpty_objI)\napply(clarsimp simp add: fpty_dclI)\ndone\n\nprimrec\nfields_in_path_f :: \"ctxclds \\<Rightarrow> fs\"\nwhere\n\"fields_in_path_f []               = []\" |\n\"fields_in_path_f (ctxcld#ctxclds) =\n  (map (\\<lambda>fd. case fd of fd_def cl f \\<Rightarrow> f) (class_fields_f (snd ctxcld)))\n     @ fields_in_path_f ctxclds\"\nlemma cl_f_list_map: \"map (case_fd (\\<lambda>cl f. f)) (map (\\<lambda>(x, y). fd_def x y) cl_f_list) = map (\\<lambda>(cl_XXX, f_XXX). f_XXX) cl_f_list\"\nby (induct cl_f_list, auto)\n\nlemma fip_ind_to_f: \"\\<forall>fs. fields_in_path clds fs \\<longrightarrow> fields_in_path_f clds = fs\"\napply(induct clds)\n apply(clarsimp, erule fields_in_path.cases) apply(simp) apply(clarsimp)\napply(clarsimp)\napply(erule fields_in_path.cases) apply(simp) by(clarsimp simp add: cl_f_list_map)\n\nlemma fd_map_split: \"map (case_fd (\\<lambda>cl f. f)) (map (\\<lambda>(x, y). fd_def x y) list) = map (\\<lambda>(cl, f). f) list\"\napply(induct list) apply(simp) apply(clarsimp) done\n\nlemma fd_map_split': \"map (\\<lambda>(x, y). fd_def x y) (map (case_fd Pair) list) = list\"\napply(induct list) apply(simp split: fd.splits)+ done\n\nlemma fd_map_split'': \"map ((\\<lambda>(x, y). fd_def x y) \\<circ> case_fd Pair) list = list\"\napply(induct list)  apply(simp split: fd.splits)+ done\n\nlemma [simp]: \"\\<forall>fs. (fields_in_path ctxclds fs) = (fields_in_path_f ctxclds = fs)\"\napply(induct ctxclds)\n apply(rule) apply(rule)\n  apply(force elim: fields_in_path.cases)\n apply(simp add: fip_emptyI)\napply(clarsimp)\napply(rule)\n apply(erule fields_in_path.cases)\n  apply(simp)\n apply(simp add: fip_ind_to_f fd_map_split)\napply(clarsimp)\napply(rule_tac cld = b and ctxcld_list = ctxclds\n           and cl_f_list = \"map (case_fd (\\<lambda>cl f. (cl, f))) (class_fields_f b)\" in fip_consI[simplified])\n  apply(simp add: fd_map_split'')\n apply(simp add: fd_map_split')\napply(clarsimp split: fd.splits)\ndone\n\ndefinition\nfields_f :: \"P \\<Rightarrow> ty \\<Rightarrow> fs option\"\nwhere\n\"fields_f P ty =\n  (case find_path_ty_f P ty of None \\<Rightarrow> None | Some ctxclds \\<Rightarrow>\n    Some (fields_in_path_f ctxclds))\"\nlemma [simp]: \"\\<forall>fs_opt. (fields P ty fs_opt) = (fields_f P ty = fs_opt)\"\napply(rule) apply(rule)\n apply(case_tac fs_opt)\n  apply(clarsimp) apply(erule fields.cases)\n   apply(clarsimp) apply(simp add: fields_f_def)\n  apply(clarsimp)\n apply(erule fields.cases)\n  apply(simp)\n apply(clarsimp) apply(simp add: fields_f_def)\n apply(simp add: fields_f_def) apply(case_tac \"find_path_ty_f P ty\") apply(simp) apply(simp add: fields_noneI[simplified])\napply(clarsimp) apply(case_tac \"find_path_ty_f P ty\") apply(simp) apply(simp) apply(clarsimp)\napply(rule fields_someI) apply(simp) apply(simp)\ndone\n\nprimrec\nmethods_in_path_f :: \"clds \\<Rightarrow> meths\"\nwhere\n\"methods_in_path_f []         = []\" |\n\"methods_in_path_f (cld#clds) =\n  map (\\<lambda>md. case md of meth_def_def meth_sig meth_body \\<Rightarrow>\n         case meth_sig of meth_sig_def cl meth vds \\<Rightarrow> meth)\n              (class_methods_f cld) @ methods_in_path_f clds\"\n\nlemma meth_def_map[THEN mp]:\n  \"(\\<forall>x \\<in> set list. (\\<lambda>(md, cl, m, vds, mb). md = meth_def_def (meth_sig_def cl m vds) mb) x)\n     \\<longrightarrow> map (case_meth_def (\\<lambda>ms mb. case ms of meth_sig_def cl m vds \\<Rightarrow> m)) (map (\\<lambda>(md, cl, m, vds, mb). md) list) = map (\\<lambda>(md, cl, m, vds, mb). m) list\"\nby (induct list, auto)\n\nlemma meth_def_map':\n  \"map ((\\<lambda>(md, cl, m, vds, mb). md) \\<circ> (\\<lambda>md. case md of meth_def_def (meth_sig_def cl m vds) mb \\<Rightarrow> (md, cl, m, vds, mb))) list = list\"\napply(induct list) by (auto split: meth_def.splits meth_sig.splits)\n\nlemma [simp]: \"\\<forall>meths. (methods_in_path clds meths) = (methods_in_path_f clds = meths)\"\napply(induct clds)\n apply(clarsimp) apply(rule)\n  apply(erule methods_in_path.cases) apply(simp) apply(clarsimp)\n apply(clarsimp) apply(rule mip_emptyI)\napply(clarsimp) apply(rule)\n apply(erule methods_in_path.cases) apply(simp)\n apply(force)\n\napply(rule_tac\n  meth_def_cl_meth_vds_meth_body_list =\n   \"(case a of cld_def dcl cl fds mds \\<Rightarrow>\n    (map (\\<lambda>md. (case md of meth_def_def ms mb \\<Rightarrow>\n               (case ms of meth_sig_def cl m vds \\<Rightarrow> (md, cl, m, vds, mb)))) mds))\" in\n  mip_consI[simplified])\n   apply(clarsimp) apply(case_tac a) apply(simp add: class_methods_f_def meth_def_map')\n  apply(clarsimp) apply(clarsimp split: meth_def.splits meth_sig.splits)\n apply(simp)\napply(clarsimp) apply(case_tac a) apply(clarsimp simp add: class_methods_f_def split: meth_def.splits meth_sig.splits)\ndone\n\ndefinition\nmethods_f :: \"P \\<Rightarrow> ty \\<Rightarrow> meths option\"\nwhere\n\"methods_f P ty =\n  (case find_path_ty_f P ty of None \\<Rightarrow> None | Some ctxclds \\<Rightarrow>\n    Some (methods_in_path_f (map (\\<lambda>(ctx, cld). cld) ctxclds)))\"\nlemma [simp]: \"(methods P ty meths) = (methods_f P ty = Some meths)\"\napply(rule)\n apply(erule methods.cases) apply(clarsimp simp add: methods_f_def)\napply(simp add: methods_f_def) apply(split option.splits) apply(simp)\napply(clarsimp) apply(rule methods_methodsI) apply(simp) apply(clarsimp)\ndone\n\nprimrec\nftype_in_fds_f :: \"P \\<Rightarrow> ctx \\<Rightarrow> fds \\<Rightarrow> f \\<Rightarrow> ty_opt_bot\"\nwhere\n\"ftype_in_fds_f P ctx []       f = ty_opt_bot_opt None\" |\n\"ftype_in_fds_f P ctx (fd#fds) f =\n  (case fd of fd_def cl f' \\<Rightarrow> (if f = f' then\n  (case find_type_f P ctx cl of None \\<Rightarrow> ty_opt_bot_bot | Some ty \\<Rightarrow>\n     ty_opt_bot_opt (Some ty)) else ftype_in_fds_f P ctx fds f))\"\nlemma [simp]: \"(ftype_in_fds P ctx fds f ty_opt) = (ftype_in_fds_f P ctx fds f = ty_opt)\"\napply(rule)\n apply(induct fds) apply(erule ftype_in_fds.cases) apply(simp) apply(simp) apply(simp) apply(simp)\n apply(erule ftype_in_fds.cases) apply(simp) apply(simp) apply(simp) apply(clarsimp)\napply(induct fds)\n apply(clarsimp) apply(rule ftif_emptyI)\napply(rename_tac fd fds) apply(case_tac fd, rename_tac cl f', clarsimp) apply(rule)\n apply(clarsimp) apply(case_tac \"find_type_f P ctx cl\")\n  apply(simp add: ftif_cons_botI[simplified])\n apply(simp add: ftif_cons_trueI[simplified])\napply(force intro: ftif_cons_falseI[simplified])\ndone\n\nprimrec\nftype_in_path_f :: \"P \\<Rightarrow> ctxclds \\<Rightarrow> f \\<Rightarrow> ty_opt\"\nwhere\n\"ftype_in_path_f P []               f = None\" |\n\"ftype_in_path_f P (ctxcld#ctxclds) f =\n  (case ctxcld of (ctx, cld) \\<Rightarrow>\n  (case ftype_in_fds_f P ctx (class_fields_f cld) f of\n     ty_opt_bot_bot \\<Rightarrow> None | ty_opt_bot_opt ty_opt \\<Rightarrow>\n  (case ty_opt of Some ty \\<Rightarrow> Some ty | None \\<Rightarrow>\n     ftype_in_path_f P ctxclds f)))\"\nlemma [simp]: \"(ftype_in_path P ctxclds f ty_opt) = (ftype_in_path_f P ctxclds f = ty_opt)\"\napply(rule)\n apply(induct rule: ftype_in_path.induct) apply(simp+)\napply(induct ctxclds) apply(simp) apply(rule ftip_emptyI)\napply(hypsubst_thin)\napply(clarsimp) apply(case_tac \"ftype_in_fds_f P a (class_fields_f b) f\")\n apply(rename_tac ty_opt) apply(case_tac ty_opt)\n  apply(simp add: ftip_cons_falseI[simplified])\n apply(simp add: ftip_cons_trueI[simplified])\napply(simp add: ftip_cons_botI[simplified])\ndone\n\ndefinition\nftype_f :: \"P \\<Rightarrow> ty \\<Rightarrow> f \\<Rightarrow> ty_opt\"\nwhere\n\"ftype_f P ty f =\n  (case find_path_ty_f P ty of None \\<Rightarrow> None | Some ctxclds \\<Rightarrow>\n     ftype_in_path_f P ctxclds f)\"\nlemma [simp]: \"(ftype P ty f ty') = (ftype_f P ty f = Some ty')\"\napply(rule)\n apply(induct rule: ftype.induct) apply(clarsimp simp add: ftype_f_def)\napply(clarsimp simp add: ftype_f_def split: option.splits) apply(rule ftypeI) apply(simp+)\ndone\n\nprimrec\nfind_meth_def_in_list_f :: \"meth_defs \\<Rightarrow> meth \\<Rightarrow> meth_def_opt\"\nwhere\n\"find_meth_def_in_list_f []       m = None\" |\n\"find_meth_def_in_list_f (md#mds) m =\n  (case md of meth_def_def ms mb \\<Rightarrow>\n  (case ms of meth_sig_def cl m' vds \\<Rightarrow>\n  (if m = m' then Some md else find_meth_def_in_list_f mds m)))\"\nlemma [simp]: \"(find_meth_def_in_list mds m md_opt) = (find_meth_def_in_list_f mds m = md_opt)\"\napply(rule)\n apply(induct rule: find_meth_def_in_list.induct) apply(simp+)\napply(induct mds) apply(simp) apply(rule fmdil_emptyI)\napply(clarsimp) apply(clarsimp split: meth_def.split meth_sig.split) apply(rule)\n apply(clarsimp) apply(rule fmdil_cons_trueI[simplified]) apply(force)\napply(clarsimp) apply(rule fmdil_cons_falseI[simplified]) apply(force+)\ndone\n\nprimrec\nfind_meth_def_in_path_f :: \"ctxclds \\<Rightarrow> meth \\<Rightarrow> ctxmeth_def_opt\"\nwhere\nfmdip_empty: \"find_meth_def_in_path_f []               m = None\" |\nfmdip_cons:  \"find_meth_def_in_path_f (ctxcld#ctxclds) m =\n  (case ctxcld of (ctx, cld) \\<Rightarrow>\n  (case find_meth_def_in_list_f (class_methods_f cld) m of\n    Some md \\<Rightarrow> Some (ctx, md) |\n    None \\<Rightarrow> find_meth_def_in_path_f ctxclds m))\"\nlemma [simp]: \"(find_meth_def_in_path ctxclds m ctxmeth_def_opt) = (find_meth_def_in_path_f ctxclds m = ctxmeth_def_opt)\"\napply(rule)\n apply(induct rule: find_meth_def_in_path.induct) apply(simp+)\napply(induct ctxclds) apply(simp) apply(rule fmdip_emptyI)\napply(clarsimp) apply(case_tac \"find_meth_def_in_list_f (class_methods_f b) m\") apply(clarsimp)\napply(simp add: fmdip_cons_falseI[simplified])\napply(simp add: fmdip_cons_trueI[simplified])\ndone\n\ndefinition\nfind_meth_def_f :: \"P \\<Rightarrow> ty \\<Rightarrow> meth \\<Rightarrow> ctxmeth_def_opt\"\nwhere\n\"find_meth_def_f P ty m =\n  (case find_path_ty_f P ty of None \\<Rightarrow> None | Some ctxclds \\<Rightarrow>\n    find_meth_def_in_path_f ctxclds m)\"\nlemma [simp]: \"(find_meth_def P ty m ctxmd_opt) = (find_meth_def_f P ty m = ctxmd_opt)\"\napply(rule)\n apply(induct rule: find_meth_def.induct) apply(simp add: find_meth_def_f_def)+\napply(clarsimp simp add: find_meth_def_f_def split: option.splits)\napply(simp add: fmd_nullI)\napply(simp add: fmd_optI)\ndone\n\nprimrec\nlift_opts :: \"'a option list \\<Rightarrow> 'a list option\"\nwhere\n\"lift_opts []         = Some []\" |\n\"lift_opts (opt#opts) =\n  (case opt of None \\<Rightarrow> None | Some v \\<Rightarrow>\n  (case lift_opts opts of None \\<Rightarrow> None | Some vs \\<Rightarrow> Some (v#vs)))\"\n\ndefinition\nmtype_f :: \"P \\<Rightarrow> ty \\<Rightarrow> meth \\<Rightarrow> mty option\"\nwhere\n\"mtype_f P ty m =\n  (case find_meth_def_f P ty m of None \\<Rightarrow> None | Some (ctx, md) \\<Rightarrow>\n  (case md of meth_def_def ms mb \\<Rightarrow>\n  (case ms of meth_sig_def cl m' vds \\<Rightarrow>\n  (case find_type_f P ctx cl of None \\<Rightarrow> None | Some ty' \\<Rightarrow>\n  (case lift_opts (map (\\<lambda>vd. case vd of vd_def clk vark \\<Rightarrow>\n    find_type_f P ctx clk) vds) of None \\<Rightarrow> None | Some tys \\<Rightarrow>\n      Some (mty_def tys ty'))))))\"\n\nlemma lift_opts_ind[rule_format]:\n  \"(\\<forall>x\\<in>set list. (\\<lambda>(cl, var, ty). find_type_f P ctx cl = Some ty) x)\n       \\<longrightarrow> lift_opts (map (case_vd (\\<lambda>clk vark. find_type_f P ctx clk) \\<circ> (\\<lambda>(cl, var, ty). vd_def cl var)) list) = Some (map (\\<lambda>(cl, var, ty). ty) list)\"\nby (induct list, auto)\n\nlemma find_md_m_match'[rule_format]:\n  \"find_meth_def_in_list_f mds m = Some (meth_def_def (meth_sig_def cl m' vds) mb) \\<longrightarrow> m' = m\"\napply(induct mds) apply(simp) apply(clarsimp split: meth_def.splits meth_sig.splits) done\n\nlemma find_md_m_match:\n  \"find_meth_def_in_path_f path m = Some (ctx, meth_def_def (meth_sig_def cl m' vds) mb) \\<longrightarrow> m' = m\"\napply(induct path) apply(simp) apply(clarsimp split: option.splits) by(rule find_md_m_match')\n\nlemma vds_map_length:\n  \"length (map (case_vd (\\<lambda>clk vark. find_type_f P ctx clk)) vds) = length vds\"\nby (induct vds, auto)\n\nlemma lift_opts_length[rule_format]:\n  \"\\<forall>tys. lift_opts ty_opts = Some tys \\<longrightarrow> length ty_opts = length tys\"\napply(induct ty_opts) apply(simp) by(clarsimp split: option.splits)\n\nlemma vds_tys_length_eq[rule_format]:\n  \"lift_opts (map (case_vd (\\<lambda>clk vark. find_type_f P ctx clk)) vds) = Some tys \\<longrightarrow> length vds = length tys\"\napply(rule) apply(drule lift_opts_length) apply(simp add: vds_map_length) done\n\nlemma vds_tys_length_eq'[rule_format]:\n  \"\\<forall>tys. length vds = length tys \\<longrightarrow> vds = map (\\<lambda>(cl, var, ty). vd_def cl var) (map (\\<lambda>(vd, ty). case vd of vd_def cl var \\<Rightarrow> (cl, var, ty)) (zip vds tys))\"\napply(induct vds) apply(simp) apply(clarsimp) apply(case_tac a) apply(clarsimp)\napply(case_tac tys) apply(simp) apply(clarsimp) done\n\nlemma vds_tys_length_eq''[rule_format]:\n  \"\\<forall>vds. length vds = length tys \\<longrightarrow> tys = map ((\\<lambda>(cl, var, ty). ty) \\<circ> (\\<lambda>(vd, ty). case vd of vd_def cl var \\<Rightarrow> (cl, var, ty))) (zip vds tys)\"\napply(induct tys) apply(simp) apply(clarsimp) apply(case_tac vds) apply(clarsimp) apply(clarsimp)\napply(split vd.splits) apply(simp) done\n\nlemma lift_opts_find_type[rule_format]:\n  \"\\<forall>tys. lift_opts (map (case_vd (\\<lambda>clk vark. find_type_f P ctx clk)) vds) = Some tys\n      \\<longrightarrow> (\\<forall>(vd, ty) \\<in> set (zip vds tys). case vd of vd_def cl var \\<Rightarrow> find_type_f P ctx cl = Some ty)\"\napply(induct vds) apply(simp) apply(clarsimp split: vd.splits option.splits) apply(rename_tac cl' var)\napply(drule_tac x = \"(vd_def cl' var, b)\" in bspec, simp) apply(force) done\n\nlemma [simp]: \"(mtype P ty m mty) = (mtype_f P ty m = Some mty)\"\napply(rule)\n apply(induct rule: mtype.induct) apply(clarsimp simp add: mtype_f_def)\n apply(split option.splits) apply(rule) apply(clarsimp)\n apply(rule_tac x = \"map (\\<lambda>(cl, var, ty). ty) cl_var_ty_list\" in exI)\n apply(simp add: lift_opts_ind) apply(clarsimp) apply(simp add: lift_opts_ind)\napply(clarsimp simp add: mtype_f_def split: option.splits meth_def.splits meth_sig.splits)\napply(rename_tac ctx mb cl m' vds ty' tys)\napply(rule_tac ctx = ctx and cl = cl and meth_body = mb and ty' = ty'\n           and cl_var_ty_list = \"map (\\<lambda>(vd, ty). case vd of vd_def cl var \\<Rightarrow> (cl, var, ty)) (zip vds tys)\"\n           and meth_def = \"meth_def_def (meth_sig_def cl m' vds) mb\" in mtypeI[simplified])\n apply(simp) apply(clarsimp) apply(rule) apply(clarsimp simp add: find_meth_def_f_def split: option.splits)\n apply(simp add: find_md_m_match) apply(drule vds_tys_length_eq) apply(frule vds_tys_length_eq') apply(clarsimp)\n apply(simp) apply(clarsimp) apply(split vd.splits) apply(clarsimp) apply(drule lift_opts_find_type) apply(simp)\n apply(clarsimp)\napply(clarsimp) apply(drule vds_tys_length_eq) apply(simp add: vds_tys_length_eq'')\ndone\n\ndefinition\nis_sty_one :: \"P \\<Rightarrow> ty \\<Rightarrow> ty \\<Rightarrow> bool option\"\nwhere\n\"is_sty_one P ty ty' =\n  (case find_path_ty_f P ty of None \\<Rightarrow> None | Some ctxclds \\<Rightarrow>\n  (case ty' of ty_top \\<Rightarrow> Some True | ty_def ctx' dcl' \\<Rightarrow>\n    Some ((ctx', dcl') : set (map (\\<lambda>(ctx, cld). (ctx, class_name_f cld)) ctxclds)) ))\"\n\nlemma class_name_mem_map[rule_format]:\n\"(ctx, cld, class_name_f cld) \\<in> set ctx_cld_dcl_list\n       \\<Longrightarrow> (ctx, class_name_f cld)\n          \\<in> ((\\<lambda>(ctx, cld). (ctx, class_name_f cld)) \\<circ> (\\<lambda>(ctx, cld, dcl). (ctx, cld))) `\n            set ctx_cld_dcl_list\"\nby (induct ctx_cld_dcl_list, auto)\n\nlemma map_map_three:\n  \" ctxclds = map ((\\<lambda>(ctx, cld, dcl). (ctx, cld)) \\<circ> (\\<lambda>(ctx, cld). (ctx, cld, class_name_f cld))) ctxclds\"\nby (induct ctxclds, auto)\n\nlemma mem_el_map[rule_format]:\n  \"(ctx, dcl) \\<in> set ctxclds\n       \\<Longrightarrow> (ctx, class_name_f dcl)\n          \\<in> (\\<lambda>(ctx_XXX, cld_XXX, y). (ctx_XXX, y)) `\n            set (map (\\<lambda>(ctx, cld). (ctx, cld, class_name_f cld)) ctxclds)\"\nby (induct ctxclds, auto)\n\nlemma [simp]: \"(sty_one P ty ty') = (is_sty_one P ty ty' = Some True)\"\napply(rule)\n apply(induct rule: sty_one.induct)\n  apply(simp add: is_sty_one_def)\n apply(clarsimp simp add: is_sty_one_def) apply(rename_tac ctx cld dcl)\n apply(drule_tac x = \"(ctx, cld, dcl)\" in bspec, simp) apply(clarsimp)\n apply(simp add: class_name_mem_map)\napply(clarsimp simp add: is_sty_one_def split: option.splits ty.splits)\n apply(simp add: sty_objI)\napply(rename_tac ctxclds ctx dcl)\napply(rule_tac ctx_cld_dcl_list = \"map (\\<lambda>(ctx, cld). (ctx, cld, class_name_f cld)) ctxclds\" in sty_dclI[simplified])\n  apply(clarsimp) apply(rule map_map_three)\n apply(force)\napply(rule mem_el_map, assumption)\ndone\n\nlemma path_append[rule_format]:\n  \"find_path_rec_f P ctx cl path' = Some path \\<Longrightarrow> \\<exists>path''. path = path' @ path''\"\napply(induct rule: find_path_rec_f.induct)\n apply(clarsimp)\napply(force split: split_if_asm option.splits)\ndone\n\nlemma all_in_path_found'[rule_format]:\n  \"find_path_rec_f P ctx cl path' = Some path \\<longrightarrow>\n      (\\<forall>ctxcld \\<in> set path. ctxcld \\<in> set path' \\<or> (\\<exists>ctx' fqn'. find_cld_f P ctx' fqn' = Some ctxcld))\"\napply(induct rule: find_path_rec_f.induct)\n apply(clarsimp)\napply(rule)\napply(force split: split_if_asm option.splits)\ndone\n\nlemma all_in_path_found:\n  \"\\<lbrakk>find_path_f P ctx cl = Some path; ctxcld \\<in> set path\\<rbrakk> \\<Longrightarrow> \\<exists>ctx' fqn'. find_cld_f P ctx' fqn' = Some ctxcld\"\nby (unfold find_path_f_def, simp only: all_in_path_found'[of _ _ _ \"[]\", simplified])\n\nlemma fpr_target_is_head':\n  \"find_path_rec_f P ctx cl path' = Some path \\<longrightarrow>\n     (\\<forall>fqn ctxcld. cl = cl_fqn fqn \\<and> find_cld_f P ctx fqn = Some ctxcld \\<longrightarrow>\n          (\\<exists>path''. path = path' @ ctxcld # path''))\"\napply(induct_tac P ctx cl path' rule: find_path_rec_f.induct)\n apply(simp)\napply(clarsimp split: split_if_asm option.splits)\napply(case_tac \"superclass_name_f b\") apply(clarsimp)\napply(clarsimp split: split_if_asm option.splits)\napply(force)\ndone\n\nlemma fpr_target_is_head:\n  \"find_path_f P ctx (cl_fqn fqn) = Some path \\<Longrightarrow> \\<exists>ctxcld. find_cld_f P ctx fqn = Some ctxcld \\<and> (\\<exists>path''. path = ctxcld # path'')\"\napply(unfold find_path_f_def) apply(frule fpr_target_is_head'[of _ _ _ \"[]\", THEN mp]) apply(clarsimp split: option.splits) done\n\nlemma fpr_sub_path':\n  \"find_path_rec_f P ctx cl path' = Some path \\<longrightarrow>\n     (\\<forall>fqn ctxcld path'' path_fqn.\n         cl = cl_fqn fqn \\<and> find_cld_f P ctx fqn = Some ctxcld \\<and>\n         find_path_rec_f P (fst ctxcld) (superclass_name_f (snd ctxcld)) path'' = Some path_fqn \\<longrightarrow>\n              (\\<exists>path'''. path_fqn = path'' @ path''' \\<and> path = path' @ ctxcld # path'''))\"\napply(induct_tac P ctx cl path' rule: find_path_rec_f.induct)\n apply(simp)\napply(clarsimp split: split_if_asm option.splits)\napply(case_tac \"superclass_name_f b\") apply(simp add: find_path_f_def)\napply(clarsimp split: split_if_asm option.splits)\napply(frule_tac path = path in path_append) apply(clarsimp) apply(force)\ndone\n\nlemma fpr_sub_path:\n  \"\\<lbrakk>find_path_f P ctx (cl_fqn fqn) = Some path; find_cld_f P ctx fqn = Some ctxcld;\n    find_path_f P (fst ctxcld) (superclass_name_f (snd ctxcld)) = Some path'\\<rbrakk>\n       \\<Longrightarrow> path = ctxcld # path'\"\nby (unfold find_path_f_def, force intro: fpr_sub_path'[rule_format, of _ _ _ \"[]\" _ _ _ \"[]\", simplified])\n\nlemma fpr_sub_path_simp:\n  \"\\<lbrakk>find_path_rec_f P ctx (superclass_name_f cld) path'' = Some path_fqn; find_cld_f P ctx fqn = Some (ctx, cld); acyclic_clds P;\n    find_path_rec_f P ctx (superclass_name_f cld) (path' @ [(ctx, cld)]) = Some path\\<rbrakk>\n       \\<Longrightarrow> \\<exists>path'''. path_fqn = path'' @ path''' \\<and> path = path' @ (ctx, cld) # path'''\"\napply(cut_tac P = P and ctx = ctx and cl = \"cl_fqn fqn\" and path' = path' and path = path in fpr_sub_path')\napply(clarsimp split: option.splits split_if_asm)\ndone\n\nlemma fpr_same_suffix'[rule_format]:\n  \"find_path_rec_f P ctx cl prefix = Some path \\<longrightarrow>\n     (\\<forall>suffix prefix'. path = prefix @ suffix \\<longrightarrow>\n          find_path_rec_f P ctx cl prefix' = Some (prefix' @ suffix))\"\napply(induct_tac P ctx cl prefix rule: find_path_rec_f.induct)\n apply(clarsimp)\napply(clarsimp split: option.splits)\napply(frule path_append) apply(force)\ndone\n\nlemma fpr_same_suffix:\n  \"find_path_rec_f P ctx cl prefix = Some path \\<longrightarrow>\n     (\\<forall>suffix prefix' suffix'. path = prefix @ suffix \\<and>\n          find_path_rec_f P ctx cl prefix' = Some (prefix' @ suffix')\n             \\<longrightarrow> suffix = suffix')\"\napply(induct_tac P ctx cl prefix rule: find_path_rec_f.induct)\n apply(clarsimp)\nby (metis fpr_same_suffix' option.inject same_append_eq)\n\nlemma fpr_mid_path'[rule_format]:\n  \"find_path_rec_f P ctx cl path' = Some path \\<longrightarrow>\n     (\\<forall>ctxcld \\<in> set path.\n         ctxcld \\<in> set path' \\<or>\n         (\\<forall>path_fqn. find_path_rec_f P (fst ctxcld) (cl_fqn (fqn_def (class_name_f (snd ctxcld)))) path'' = Some path_fqn \\<longrightarrow>\n              (\\<forall>path'''. path_fqn = path'' @ path''' \\<longrightarrow> (\\<exists>path_rest. path = path_rest @ path'''))))\"\napply(induct_tac P ctx cl path' rule: find_path_rec_f.induct)\n apply(simp)\napply(clarsimp split: option.splits)\napply(frule find_cld_name_eq) apply(clarsimp)\napply(rename_tac path' ctx' cld' cld'' ctx'' path''' cl fds mds)\napply(subgoal_tac \"find_path_rec_f P ctx' (superclass_name_f cld') (path' @ [(ctx', cld')]) = Some path \\<longrightarrow>\n              (\\<forall>ctxcld\\<in>set path.\n                  ctxcld = (ctx', cld') \\<or>\n                  ctxcld \\<in> set path' \\<or>\n                  (\\<forall>path_fqn. case_option None (case_prod (\\<lambda>ctx' cld. find_path_rec_f P ctx' (superclass_name_f cld) (path'' @ [(ctx', cld)])))\n                               (find_cld_f P (fst ctxcld) (fqn_def (class_name_f (snd ctxcld)))) =\n                              Some path_fqn \\<longrightarrow>\n                              (\\<forall>path'''. path_fqn = path'' @ path''' \\<longrightarrow> (\\<exists>path_rest. path = path_rest @ path'''))))\")\n apply(erule impE) apply simp\n apply(drule_tac x = \"(ctx'', cld'')\" in bspec, simp) apply(clarsimp)\n apply(simp add: superclass_name_f_def)\n apply(case_tac cld') apply(rename_tac dcl' cl' fds' mds') apply(clarsimp simp add: class_name_f_def)\n apply(case_tac fqn) apply(rename_tac dcl'') apply(clarsimp)\n apply(frule find_cld_name_eq) apply(clarsimp)\n apply(frule path_append) apply(frule_tac path = \"path'' @ path'''\" in path_append) apply(clarsimp)\n apply(rule_tac x = path' in exI) apply(clarsimp)\n apply(frule_tac suffix = path''a and prefix' = \"path'' @ [(ctx', cld_def dcl' cl' fds' mds')]\" and\n                suffix' = path''aa in fpr_same_suffix[rule_format]) apply(simp)\n apply(force)\napply(simp)\ndone\n\nlemma fpr_mid_path:\n  \"\\<lbrakk>find_path_f P ctx cl = Some path; (ctx', cld') \\<in> set path;\n    find_path_f P ctx' (cl_fqn (fqn_def (class_name_f cld'))) = Some path'\\<rbrakk>\n       \\<Longrightarrow> \\<exists>path''. path = path'' @ path'\"\napply(cut_tac  P = P and ctx = ctx and cl = cl and path' = \"[]\" and path = path and ctxcld = \"(ctx', cld')\" and path'' = \"[]\" in fpr_mid_path')\napply(unfold find_path_f_def, assumption) apply(assumption) apply(simp)\ndone\n\nlemma fpr_first_in_path'[rule_format]:\n  \"find_path_rec_f P ctx cl path' = Some path \\<longrightarrow>\n      (\\<forall>fqn ctxcld. cl = cl_fqn fqn \\<and> find_cld_f P ctx fqn = Some ctxcld \\<longrightarrow> ctxcld \\<in> set path)\"\napply(case_tac cl)\n apply(simp)\napply(clarsimp) apply(drule path_append) apply(force)\ndone\n\nlemma fpr_first_in_path:\n  \"\\<lbrakk>find_path_f P ctx (cl_fqn fqn) = Some path; find_cld_f P ctx fqn = Some ctxcld\\<rbrakk> \\<Longrightarrow> ctxcld \\<in> set path\"\nby (unfold find_path_f_def, force intro: fpr_first_in_path'[of _ _ _ \"[]\", simplified])\n\nlemma cld_for_path:\n  \"find_path_f P ctx (cl_fqn fqn) = Some path \\<Longrightarrow> \\<exists>ctxcld. find_cld_f P ctx fqn = Some ctxcld\"\napply(unfold find_path_f_def) apply(clarsimp split: split_if_asm option.splits) done\n\nlemma ctx_cld_ctx_dcl[rule_format]:\n  \"(ctx, cld_def dcl cl fds mds) \\<in> set path \\<longrightarrow> (ctx, dcl) \\<in> (\\<lambda>(ctx, cld). (ctx, class_name_f cld)) ` set path\"\nby (induct path, auto simp add: class_name_f_def)\n\nlemma ctx_dcl_ctx_cld[rule_format]:\n  \"(ctx, dcl) \\<in> (\\<lambda>(ctx, cld). (ctx, class_name_f cld)) ` set path \\<longrightarrow> (\\<exists>cl fds mds. (ctx, cld_def dcl cl fds mds) \\<in> set path)\"\napply(induct path) apply(simp)\napply(auto) apply(case_tac b) apply(force simp add: class_name_f_def)\ndone\n\nlemma ctx_dcl_mem_path:\n  \"find_path_f P ctx (cl_fqn (fqn_def dcl)) = Some path \\<Longrightarrow> (ctx, dcl) \\<in> (\\<lambda>(ctx, cld). (ctx, class_name_f cld)) ` set path\"\napply(frule cld_for_path) apply(erule exE)\napply(frule fpr_first_in_path) apply(assumption)\napply(frule find_cld_name_eq) apply(elim exE)\napply(clarsimp simp add: ctx_cld_ctx_dcl)\ndone\n\nlemma sty_reflexiveI:\n  \"is_sty_one P ty ty' = Some True \\<Longrightarrow> is_sty_one P ty ty = Some True\"\napply(simp add: is_sty_one_def split: option.splits) apply(case_tac ty) apply(simp) apply(clarsimp)\napply(drule ctx_dcl_mem_path) apply(force)\ndone\n\nlemma sty_transitiveI:\n  \"\\<lbrakk>is_sty_one P ty ty' = Some True; is_sty_one P ty' ty'' = Some True\\<rbrakk>\n       \\<Longrightarrow> is_sty_one P ty ty'' = Some True\"\napply(clarsimp simp add: is_sty_one_def split: ty.splits option.splits)\napply(rename_tac path ctx dcl path' ctx' dcl')\napply(case_tac ty) apply(simp) apply(clarsimp) apply(rename_tac ctx dcl ctx' cld' ctx'' cld'')\napply(frule fpr_mid_path) apply(simp) apply(simp) apply(force)\ndone\n\ndefinition\nis_sty_many :: \"P \\<Rightarrow> tys \\<Rightarrow> tys \\<Rightarrow> bool option\"\nwhere\n\"is_sty_many P tys tys' =\n  (if length tys \\<noteq> length tys' then None else\n  (case lift_opts (map (\\<lambda>(ty, ty'). is_sty_one P ty ty') (zip tys tys'))\n     of None \\<Rightarrow> None | Some bools \\<Rightarrow> Some (list_all id bools)))\"\n\nlemma lift_opts_exists:\n  \"\\<forall>x\\<in>set ty_ty'_list. (\\<lambda>(ty, ty'). is_sty_one P ty ty' = Some True) x \\<Longrightarrow> \\<exists>bools. lift_opts (map (\\<lambda>(ty, ty'). is_sty_one P ty ty') ty_ty'_list) = Some bools\"\nby (induct ty_ty'_list, auto)\n\nlemma lift_opts_all_true[rule_format]:\n  \"\\<forall>bools. (\\<forall>x\\<in>set ty_ty'_list. (\\<lambda>(ty, ty'). is_sty_one P ty ty' = Some True) x) \\<and>\n            lift_opts (map (\\<lambda>(ty, ty'). is_sty_one P ty ty') ty_ty'_list) = Some bools\n                  \\<longrightarrow> list_all id bools\"\nby (induct ty_ty'_list, auto split: option.splits)\n\nlemma tys_tys'_list: \"\\<And>bools ty ty'. \\<lbrakk>lift_opts (map (\\<lambda>(x, y). is_sty_one P x y) tys_tys'_list) = Some bools; length tys = length tys'; list_all id bools; (ty, ty') \\<in> set tys_tys'_list\\<rbrakk> \\<Longrightarrow> is_sty_one P ty ty' = Some True\"\napply(induct tys_tys'_list)\n apply(simp)\napply(clarsimp split: option.splits)\nby force\n\nlemma [simp]: \"(sty_many P tys tys') = (is_sty_many P tys tys' = Some True)\"\napply(rule)\n apply(erule sty_many.cases) apply(clarsimp simp add: is_sty_many_def split: option.splits) apply(rule)\n  apply(simp add: lift_opts_exists)\n apply(force intro: lift_opts_all_true)\napply(clarsimp simp add: is_sty_many_def split: option.splits split_if_asm)\napply(rule_tac ty_ty'_list = \"zip tys tys'\" in sty_manyI)\n  apply(simp add: map_fst_zip[THEN sym])\n apply(simp add: map_snd_zip[THEN sym])\napply(clarsimp)\napply(simp add: tys_tys'_list)\ndone\n\n(* TODO: here will go all the other definitions for functions equivalent to\n   relations concerning well-formedness *)\n\ndefinition\ntr_x :: \"T \\<Rightarrow> x \\<Rightarrow> x\"\nwhere\n\"tr_x T x = (case T x of None \\<Rightarrow> x | Some x' \\<Rightarrow> x')\"\n\ndefinition\ntr_var :: \"T \\<Rightarrow> var \\<Rightarrow> var\"\nwhere\n\"tr_var T var = (case tr_x T (x_var var) of x_this \\<Rightarrow> var | x_var var' \\<Rightarrow> var')\"\n\nprimrec\ntr_s_f  :: \"T \\<Rightarrow> s \\<Rightarrow> s\" and\ntr_ss_f :: \"T \\<Rightarrow> s list \\<Rightarrow> s list\"\nwhere\n\"tr_s_f T (s_block ss)        = s_block (tr_ss_f T ss)\" |\n\"tr_s_f T (s_ass var x)       = s_ass (tr_var T var) (tr_x T x)\" |\n\"tr_s_f T (s_read var x f)    = s_read (tr_var T var) (tr_x T x) f\" |\n\"tr_s_f T (s_write x f y)     = s_write (tr_x T x) f (tr_x T y)\" |\n\"tr_s_f T (s_if x y s1 s2)    = s_if (tr_x T x) (tr_x T y) (tr_s_f T s1) (tr_s_f T s2)\" |\n\"tr_s_f T (s_call var x m ys) = s_call (tr_var T var) (tr_x T x) m (map (tr_x T) ys)\" |\n\"tr_s_f T (s_new var ctx cl)  = s_new (tr_var T var) ctx cl\" |\n\n\"tr_ss_f T [] = []\" |\n\"tr_ss_f T (s#ss) = tr_s_f T s # tr_ss_f T ss\"\n\nlemma [simp]: \"(\\<forall>x\\<in>set s_s'_list. case x of (s_XXX, s_') \\<Rightarrow> tr_s T s_XXX s_' \\<and> tr_s_f T s_XXX = s_') \\<longrightarrow>\n       tr_ss_f T (map fst s_s'_list) = map snd s_s'_list\"\nby (induct s_s'_list, auto)\n\nlemma [simp]: \"(\\<forall>x\\<in>set y_y'_list. split (\\<lambda>y_XXX. op = (case T y_XXX of None \\<Rightarrow> y_XXX | Some x' \\<Rightarrow> x')) x) \\<longrightarrow> map (tr_x T) (map fst y_y'_list) = map snd y_y'_list\"\napply(induct y_y'_list) apply(simp) apply(clarsimp) apply(simp only: tr_x_def) done\n\nlemma set_zip_tr[simp]: \"(s, s') \\<in> set (zip ss (tr_ss_f T ss)) \\<longrightarrow> s' = tr_s_f T s\" by (induct ss, auto)\n\n\n\nlemma tr_ss_map:\n  \"tr_ss_f T (map fst s_s'_list) = map snd s_s'_list \\<and> (\\<forall>x\\<in>set s_s'_list. case_prod (tr_s T) x) \\<and>\n   (a, b) \\<in> set s_s'_list \\<longrightarrow> tr_s T a (tr_s_f T a)\"\napply(induct s_s'_list) by auto\n\nlemma tr_f_to_rel: \"\\<forall>s'. tr_s_f T s = s' \\<longrightarrow> tr_s T s s'\"\napply(induct s rule: tr_s_f.induct)\napply(simp)\napply(clarsimp) apply(rule tr_s_var_assignI)\napply(clarsimp simp add: tr_x_def tr_var_def split: option.splits)\napply(simp add: tr_x_def)\napply(clarsimp) apply(rule tr_s_field_readI)\napply(clarsimp simp add: tr_x_def tr_var_def split: option.splits)\napply(simp add: tr_x_def)\napply(clarsimp) apply(rule tr_s_field_writeI)\napply(simp add: tr_x_def) apply(simp add: tr_x_def)\napply(clarsimp simp only: tr_s_f.simps) apply(rule tr_s_ifI)\napply(simp only: tr_x_def) apply(simp only: tr_x_def) apply(simp) apply(simp)\napply(clarsimp) apply(rule tr_s_newI)\napply(clarsimp simp add: tr_x_def tr_var_def split: option.splits)\napply(clarsimp)\napply(rename_tac var x m ys)\napply(cut_tac T = T and var = var and var' = \"tr_var T var\" and x = x and\n              x' = \"tr_x T x\" and y_y'_list = \"zip ys (map (tr_x T) ys)\" and\n              meth = m in tr_s_mcallI)\napply(clarsimp simp add: tr_x_def tr_var_def split: option.splits)\napply(simp only: tr_x_def) apply(clarsimp simp add: set_zip tr_x_def) apply(simp)\napply(simp)\napply(cut_tac T = T and s_s'_list = \"[]\" in tr_s_blockI[simplified])\n apply(simp)\napply(clarsimp)\napply(clarsimp) apply(rename_tac s ss)\napply(cut_tac T = T and s_s'_list = \"zip (s # ss) (tr_s_f T s # tr_ss_f T ss)\" in tr_s_blockI[simplified])\n apply(clarsimp) apply(rename_tac x x')\n apply(frule set_zip_tr[THEN mp]) apply(clarsimp)\n apply(erule in_set_zipE)\n apply(erule_tac ?a1.0=\"T\" and ?a2.0=\"s_block ss\" and ?a3.0=\"s_block (tr_ss_f T ss)\" in tr_s.cases)\n apply(clarsimp)\n apply(rule tr_ss_map[THEN mp], force)\n apply(clarsimp)+\ndone\n\nlemma tr_rel_f_eq: \"((tr_s T s s') = (tr_s_f T s = s'))\"\napply(rule)\n apply(erule tr_s.induct)\n apply(force simp add: tr_x_def tr_var_def split: option.splits)+\napply(cut_tac T = T and s = s in tr_f_to_rel) apply(simp)\ndone\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/LightweightJava/Lightweight_Java_Equivalence.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.626124191181315, "lm_q2_score": 0.43014734858584286, "lm_q1q2_score": 0.269325660722098}}
{"text": "(*  Title:      Jinja/J/Equivalence.thy\n    Author:     Tobias Nipkow\n    Copyright   2003 Technische Universitaet Muenchen\n*)\n\nsection \\<open>Equivalence of Big Step and Small Step Semantics\\<close>\n\ntheory Equivalence imports BigStep SmallStep WWellForm begin\n\nsubsection\\<open>Small steps simulate big step\\<close>\n\nsubsubsection \"Cast\"\n\nlemma CastReds:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>Cast C e,s\\<rangle> \\<rightarrow>* \\<langle>Cast C e',s'\\<rangle>\"\n(*<*)\nproof(induct rule: rtrancl_induct2)\n  case refl show ?case by blast\nnext\n  case step show ?case\n   by(rule rtrancl_into_rtrancl[OF step(3) CastRed[OF step(2)]])\nqed\n(*>*)\n\nlemma CastRedsNull:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>null,s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>Cast C e,s\\<rangle> \\<rightarrow>* \\<langle>null,s'\\<rangle>\"\n(*<*)by(rule CastReds[THEN rtrancl_into_rtrancl, OF _ RedCastNull])(*>*)\n\nlemma CastRedsAddr:\n  \"\\<lbrakk> P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>addr a,s'\\<rangle>; hp s' a = Some(D,fs); P \\<turnstile> D \\<preceq>\\<^sup>* C \\<rbrakk> \\<Longrightarrow>\n  P \\<turnstile> \\<langle>Cast C e,s\\<rangle> \\<rightarrow>* \\<langle>addr a,s'\\<rangle>\"\n(*<*)by(rule CastReds[THEN rtrancl_into_rtrancl, OF _ RedCast])(*>*)\n\nlemma CastRedsFail:\n  \"\\<lbrakk> P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>addr a,s'\\<rangle>; hp s' a = Some(D,fs); \\<not> P \\<turnstile> D \\<preceq>\\<^sup>* C \\<rbrakk> \\<Longrightarrow>\n  P \\<turnstile> \\<langle>Cast C e,s\\<rangle> \\<rightarrow>* \\<langle>THROW ClassCast,s'\\<rangle>\"\n(*<*)by(rule CastReds[THEN rtrancl_into_rtrancl, OF _ RedCastFail])(*>*)\n\nlemma CastRedsThrow:\n  \"\\<lbrakk> P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>throw a,s'\\<rangle> \\<rbrakk> \\<Longrightarrow> P \\<turnstile> \\<langle>Cast C e,s\\<rangle> \\<rightarrow>* \\<langle>throw a,s'\\<rangle>\"\n(*<*)by(rule CastReds[THEN rtrancl_into_rtrancl, OF _ red_reds.CastThrow])(*>*)\n\nsubsubsection \"LAss\"\n\nlemma LAssReds:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle> V:=e,s\\<rangle> \\<rightarrow>* \\<langle> V:=e',s'\\<rangle>\"\n(*<*)\nproof(induct rule: rtrancl_induct2)\n  case refl show ?case by blast\nnext\n  case step show ?case\n   by(rule rtrancl_into_rtrancl[OF step(3) LAssRed[OF step(2)]])\nqed\n(*>*)\n\nlemma LAssRedsVal:\n  \"\\<lbrakk> P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>Val v,(h',l')\\<rangle> \\<rbrakk> \\<Longrightarrow> P \\<turnstile> \\<langle> V:=e,s\\<rangle> \\<rightarrow>* \\<langle>unit,(h',l'(V\\<mapsto>v))\\<rangle>\"\n(*<*)by(rule LAssReds[THEN rtrancl_into_rtrancl, OF _ RedLAss])(*>*)\n\n\n\nsubsubsection \"BinOp\"\n\nlemma BinOp1Reds:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle> e \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2, s\\<rangle> \\<rightarrow>* \\<langle>e' \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2, s'\\<rangle>\"\n(*<*)\nproof(induct rule: rtrancl_induct2)\n  case refl show ?case by blast\nnext\n  case step show ?case\n   by(rule rtrancl_into_rtrancl[OF step(3) BinOpRed1[OF step(2)]])\nqed\n(*>*)\n\nlemma BinOp2Reds:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>(Val v) \\<guillemotleft>bop\\<guillemotright> e, s\\<rangle> \\<rightarrow>* \\<langle>(Val v) \\<guillemotleft>bop\\<guillemotright> e', s'\\<rangle>\"\n(*<*)\nproof(induct rule: rtrancl_induct2)\n  case refl show ?case by blast\nnext\n  case step show ?case\n   by(rule rtrancl_into_rtrancl[OF step(3) BinOpRed2[OF step(2)]])\nqed\n(*>*)\n\nlemma BinOpRedsVal:\nassumes e\\<^sub>1_steps: \"P \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>Val v\\<^sub>1,s\\<^sub>1\\<rangle>\"\n  and e\\<^sub>2_steps: \"P \\<turnstile> \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<rightarrow>* \\<langle>Val v\\<^sub>2,s\\<^sub>2\\<rangle>\"\n  and op: \"binop(bop,v\\<^sub>1,v\\<^sub>2) = Some v\"\nshows \"P \\<turnstile> \\<langle>e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2, s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>Val v,s\\<^sub>2\\<rangle>\"\n(*<*)(is \"(?x, ?z) \\<in> (red P)\\<^sup>*\")\nproof -\n  let ?y = \"(Val v\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2, s\\<^sub>1)\"\n  let ?y' = \"(Val v\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> Val v\\<^sub>2, s\\<^sub>2)\"\n  have \"(?x, ?y) \\<in> (red P)\\<^sup>*\" by(rule BinOp1Reds[OF e\\<^sub>1_steps])\n  also have \"(?y, ?y') \\<in> (red P)\\<^sup>*\" by(rule BinOp2Reds[OF e\\<^sub>2_steps])\n  also have \"(?y', ?z) \\<in> (red P)\" by(rule RedBinOp[OF op])\n  ultimately show ?thesis by simp\nqed\n(*>*)\n\nlemma BinOpRedsThrow1:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>throw e',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>e \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2, s\\<rangle> \\<rightarrow>* \\<langle>throw e', s'\\<rangle>\"\n(*<*)by(rule BinOp1Reds[THEN rtrancl_into_rtrancl, OF _ red_reds.BinOpThrow1])(*>*)\n\nlemma BinOpRedsThrow2:\nassumes e\\<^sub>1_steps: \"P \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>Val v\\<^sub>1,s\\<^sub>1\\<rangle>\"\n  and e\\<^sub>2_steps: \"P \\<turnstile> \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<rightarrow>* \\<langle>throw e,s\\<^sub>2\\<rangle>\"\nshows \"P \\<turnstile> \\<langle>e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2, s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>throw e,s\\<^sub>2\\<rangle>\"\n(*<*)(is \"(?x, ?z) \\<in> (red P)\\<^sup>*\")\nproof -\n  let ?y = \"(Val v\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2, s\\<^sub>1)\"\n  let ?y' = \"(Val v\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> throw e, s\\<^sub>2)\"\n  have \"(?x, ?y) \\<in> (red P)\\<^sup>*\" by(rule BinOp1Reds[OF e\\<^sub>1_steps])\n  also have \"(?y, ?y') \\<in> (red P)\\<^sup>*\" by(rule BinOp2Reds[OF e\\<^sub>2_steps])\n  also have \"(?y', ?z) \\<in> (red P)\" by(rule red_reds.BinOpThrow2)\n  ultimately show ?thesis by simp\nqed\n(*>*)\n\nsubsubsection \"FAcc\"\n\nlemma FAccReds:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>e\\<bullet>F{D}, s\\<rangle> \\<rightarrow>* \\<langle>e'\\<bullet>F{D}, s'\\<rangle>\"\n(*<*)\nproof(induct rule: rtrancl_induct2)\n  case refl show ?case by blast\nnext\n  case step show ?case\n   by(rule rtrancl_into_rtrancl[OF step(3) FAccRed[OF step(2)]])\nqed\n(*>*)\n\nlemma FAccRedsVal:\n  \"\\<lbrakk>P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>addr a,s'\\<rangle>; hp s' a = Some(C,fs); fs(F,D) = Some v \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile> \\<langle>e\\<bullet>F{D},s\\<rangle> \\<rightarrow>* \\<langle>Val v,s'\\<rangle>\"\n(*<*)by(rule FAccReds[THEN rtrancl_into_rtrancl, OF _ RedFAcc])(*>*)\n\nlemma FAccRedsNull:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>null,s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>e\\<bullet>F{D},s\\<rangle> \\<rightarrow>* \\<langle>THROW NullPointer,s'\\<rangle>\"\n(*<*)by(rule FAccReds[THEN rtrancl_into_rtrancl, OF _ RedFAccNull])(*>*)\n\nlemma FAccRedsThrow:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>throw a,s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>e\\<bullet>F{D},s\\<rangle> \\<rightarrow>* \\<langle>throw a,s'\\<rangle>\"\n(*<*)by(rule FAccReds[THEN rtrancl_into_rtrancl, OF _ red_reds.FAccThrow])(*>*)\n\nsubsubsection \"FAss\"\n\nlemma FAssReds1:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>e\\<bullet>F{D}:=e\\<^sub>2, s\\<rangle> \\<rightarrow>* \\<langle>e'\\<bullet>F{D}:=e\\<^sub>2, s'\\<rangle>\"\n(*<*)\nproof(induct rule: rtrancl_induct2)\n  case refl show ?case by blast\nnext\n  case step show ?case\n   by(rule rtrancl_into_rtrancl[OF step(3) FAssRed1[OF step(2)]])\nqed\n(*>*)\n\nlemma FAssReds2:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>Val v\\<bullet>F{D}:=e, s\\<rangle> \\<rightarrow>* \\<langle>Val v\\<bullet>F{D}:=e', s'\\<rangle>\"\n(*<*)\nproof(induct rule: rtrancl_induct2)\n  case refl show ?case by blast\nnext\n  case step show ?case\n   by(rule rtrancl_into_rtrancl[OF step(3) FAssRed2[OF step(2)]])\nqed\n(*>*)\n\nlemma FAssRedsVal:\nassumes e\\<^sub>1_steps: \"P \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>addr a,s\\<^sub>1\\<rangle>\"\n  and e\\<^sub>2_steps: \"P \\<turnstile> \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<rightarrow>* \\<langle>Val v,(h\\<^sub>2,l\\<^sub>2)\\<rangle>\"\n  and hC: \"Some(C,fs) = h\\<^sub>2 a\"\nshows \"P \\<turnstile> \\<langle>e\\<^sub>1\\<bullet>F{D}:=e\\<^sub>2, s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>unit, (h\\<^sub>2(a\\<mapsto>(C,fs((F,D)\\<mapsto>v))),l\\<^sub>2)\\<rangle>\"\n(*<*)(is \"(?x, ?z) \\<in> (red P)\\<^sup>*\")\nproof -\n  let ?y = \"(addr a\\<bullet>F{D}:=e\\<^sub>2, s\\<^sub>1)\"\n  let ?y' = \"(addr a\\<bullet>F{D}:=Val v::expr,(h\\<^sub>2,l\\<^sub>2))\"\n  have \"(?x, ?y) \\<in> (red P)\\<^sup>*\" by(rule FAssReds1[OF e\\<^sub>1_steps])\n  also have \"(?y, ?y') \\<in> (red P)\\<^sup>*\" by(rule FAssReds2[OF e\\<^sub>2_steps])\n  also have \"(?y', ?z) \\<in> (red P)\" using RedFAss hC by simp\n  ultimately show ?thesis by simp\nqed\n(*>*)\n\nlemma FAssRedsNull:\nassumes e\\<^sub>1_steps: \"P \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>null,s\\<^sub>1\\<rangle>\"\n  and e\\<^sub>2_steps: \"P \\<turnstile> \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<rightarrow>* \\<langle>Val v,s\\<^sub>2\\<rangle>\"\nshows \"P \\<turnstile> \\<langle>e\\<^sub>1\\<bullet>F{D}:=e\\<^sub>2, s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>THROW NullPointer, s\\<^sub>2\\<rangle>\"\n(*<*)(is \"(?x, ?z) \\<in> (red P)\\<^sup>*\")\nproof -\n  let ?y = \"(null\\<bullet>F{D}:=e\\<^sub>2, s\\<^sub>1)\"\n  let ?y' = \"(null\\<bullet>F{D}:=Val v::expr,s\\<^sub>2)\"\n  have \"(?x, ?y) \\<in> (red P)\\<^sup>*\" by(rule FAssReds1[OF e\\<^sub>1_steps])\n  also have \"(?y, ?y') \\<in> (red P)\\<^sup>*\" by(rule FAssReds2[OF e\\<^sub>2_steps])\n  also have \"(?y', ?z) \\<in> (red P)\" by(rule RedFAssNull)\n  ultimately show ?thesis by simp\nqed\n(*>*)\n\nlemma FAssRedsThrow1:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>throw e',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>e\\<bullet>F{D}:=e\\<^sub>2, s\\<rangle> \\<rightarrow>* \\<langle>throw e', s'\\<rangle>\"\n(*<*)by(rule FAssReds1[THEN rtrancl_into_rtrancl, OF _ red_reds.FAssThrow1])(*>*)\n\nlemma FAssRedsThrow2:\nassumes e\\<^sub>1_steps: \"P \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>Val v,s\\<^sub>1\\<rangle>\"\n  and e\\<^sub>2_steps: \"P \\<turnstile> \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<rightarrow>* \\<langle>throw e,s\\<^sub>2\\<rangle>\"\nshows \"P \\<turnstile> \\<langle>e\\<^sub>1\\<bullet>F{D}:=e\\<^sub>2,s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>throw e,s\\<^sub>2\\<rangle>\"\n(*<*)(is \"(?x, ?z) \\<in> (red P)\\<^sup>*\")\nproof -\n  let ?y = \"(Val v\\<bullet>F{D}:=e\\<^sub>2,s\\<^sub>1)\"\n  let ?y' = \"(Val v\\<bullet>F{D}:=throw e,s\\<^sub>2)\"\n  have \"(?x, ?y) \\<in> (red P)\\<^sup>*\" by(rule FAssReds1[OF e\\<^sub>1_steps])\n  also have \"(?y, ?y') \\<in> (red P)\\<^sup>*\" by(rule FAssReds2[OF e\\<^sub>2_steps])\n  also have \"(?y', ?z) \\<in> (red P)\" by(rule red_reds.FAssThrow2)\n  ultimately show ?thesis by simp\nqed\n(*>*)\n\nsubsubsection\";;\"\n\nlemma  SeqReds:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>e;;e\\<^sub>2, s\\<rangle> \\<rightarrow>* \\<langle>e';;e\\<^sub>2, s'\\<rangle>\"\n(*<*)\nproof(induct rule: rtrancl_induct2)\n  case refl show ?case by blast\nnext\n  case step show ?case\n   by(rule rtrancl_into_rtrancl[OF step(3) SeqRed[OF step(2)]])\nqed\n(*>*)\n\nlemma SeqRedsThrow:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>throw e',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>e;;e\\<^sub>2, s\\<rangle> \\<rightarrow>* \\<langle>throw e', s'\\<rangle>\"\n(*<*)by(rule SeqReds[THEN rtrancl_into_rtrancl, OF _ red_reds.SeqThrow])(*>*)\n\nlemma SeqReds2:\nassumes e\\<^sub>1_steps: \"P \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>Val v\\<^sub>1,s\\<^sub>1\\<rangle>\"\n  and   e\\<^sub>2_steps: \"P \\<turnstile> \\<langle>e\\<^sub>2,s\\<^sub>1\\<rangle> \\<rightarrow>* \\<langle>e\\<^sub>2',s\\<^sub>2\\<rangle>\"\nshows \"P \\<turnstile> \\<langle>e\\<^sub>1;;e\\<^sub>2, s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>e\\<^sub>2',s\\<^sub>2\\<rangle>\"\n(*<*)(is \"(?x, ?z) \\<in> (red P)\\<^sup>*\")\nproof -\n  let ?y = \"(Val v\\<^sub>1;; e\\<^sub>2,s\\<^sub>1)\"\n  have \"(?x, ?y) \\<in> (red P)\\<^sup>*\" by(rule SeqReds[OF e\\<^sub>1_steps])\n  also have \"(?y, ?z) \\<in> (red P)\\<^sup>*\"\n    by(rule RedSeq[THEN converse_rtrancl_into_rtrancl, OF e\\<^sub>2_steps])\n  ultimately show ?thesis by simp\nqed\n(*>*)\n\n\nsubsubsection\"If\"\n\nlemma CondReds:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>if (e) e\\<^sub>1 else e\\<^sub>2,s\\<rangle> \\<rightarrow>* \\<langle>if (e') e\\<^sub>1 else e\\<^sub>2,s'\\<rangle>\"\n(*<*)\nproof(induct rule: rtrancl_induct2)\n  case refl show ?case by blast\nnext\n  case step show ?case\n   by(rule rtrancl_into_rtrancl[OF step(3) CondRed[OF step(2)]])\nqed\n(*>*)\n\nlemma CondRedsThrow:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>throw a,s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>if (e) e\\<^sub>1 else e\\<^sub>2, s\\<rangle> \\<rightarrow>* \\<langle>throw a,s'\\<rangle>\"\n(*<*)by(rule CondReds[THEN rtrancl_into_rtrancl, OF _ red_reds.CondThrow])(*>*)\n\nlemma CondReds2T:\nassumes e_steps: \"P \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>true,s\\<^sub>1\\<rangle>\"\n  and   e\\<^sub>1_steps: \"P \\<turnstile> \\<langle>e\\<^sub>1, s\\<^sub>1\\<rangle> \\<rightarrow>* \\<langle>e',s\\<^sub>2\\<rangle>\"\nshows \"P \\<turnstile> \\<langle>if (e) e\\<^sub>1 else e\\<^sub>2, s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>e',s\\<^sub>2\\<rangle>\"\n(*<*)(is \"(?x, ?z) \\<in> (red P)\\<^sup>*\")\nproof -\n  let ?y = \"(if (true) e\\<^sub>1 else e\\<^sub>2,s\\<^sub>1)\"\n  have \"(?x, ?y) \\<in> (red P)\\<^sup>*\" by(rule CondReds[OF e_steps])\n  also have \"(?y, ?z) \\<in> (red P)\\<^sup>*\"\n    by(rule RedCondT[THEN converse_rtrancl_into_rtrancl, OF e\\<^sub>1_steps])\n  ultimately show ?thesis by simp\nqed\n(*>*)\n\nlemma CondReds2F:\nassumes e_steps: \"P \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>false,s\\<^sub>1\\<rangle>\"\n  and   e\\<^sub>2_steps: \"P \\<turnstile> \\<langle>e\\<^sub>2, s\\<^sub>1\\<rangle> \\<rightarrow>* \\<langle>e',s\\<^sub>2\\<rangle>\"\nshows \"P \\<turnstile> \\<langle>if (e) e\\<^sub>1 else e\\<^sub>2, s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>e',s\\<^sub>2\\<rangle>\"\n(*<*)(is \"(?x, ?z) \\<in> (red P)\\<^sup>*\")\nproof -\n  let ?y = \"(if (false) e\\<^sub>1 else e\\<^sub>2,s\\<^sub>1)\"\n  have \"(?x, ?y) \\<in> (red P)\\<^sup>*\" by(rule CondReds[OF e_steps])\n  also have \"(?y, ?z) \\<in> (red P)\\<^sup>*\"\n    by(rule RedCondF[THEN converse_rtrancl_into_rtrancl, OF e\\<^sub>2_steps])\n  ultimately show ?thesis by simp\nqed\n(*>*)\n\n\nsubsubsection \"While\"\n\nlemma WhileFReds:\nassumes b_steps: \"P \\<turnstile> \\<langle>b,s\\<rangle> \\<rightarrow>* \\<langle>false,s'\\<rangle>\"\nshows \"P \\<turnstile> \\<langle>while (b) c,s\\<rangle> \\<rightarrow>* \\<langle>unit,s'\\<rangle>\"\n(*<*)\nby(rule RedWhile[THEN converse_rtrancl_into_rtrancl,\n                 OF CondReds[THEN rtrancl_into_rtrancl,\n                             OF b_steps RedCondF]])\n(*>*)\n\nlemma WhileRedsThrow:\nassumes b_steps: \"P \\<turnstile> \\<langle>b,s\\<rangle> \\<rightarrow>* \\<langle>throw e,s'\\<rangle>\"\nshows \"P \\<turnstile> \\<langle>while (b) c,s\\<rangle> \\<rightarrow>* \\<langle>throw e,s'\\<rangle>\"\n(*<*)\nby(rule RedWhile[THEN converse_rtrancl_into_rtrancl,\n                 OF CondReds[THEN rtrancl_into_rtrancl,\n                             OF b_steps red_reds.CondThrow]])\n(*>*)\n\nlemma WhileTReds:\nassumes b_steps: \"P \\<turnstile> \\<langle>b,s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>true,s\\<^sub>1\\<rangle>\"\n    and c_steps: \"P \\<turnstile> \\<langle>c,s\\<^sub>1\\<rangle> \\<rightarrow>* \\<langle>Val v\\<^sub>1,s\\<^sub>2\\<rangle>\"\n    and while_steps: \"P \\<turnstile> \\<langle>while (b) c,s\\<^sub>2\\<rangle> \\<rightarrow>* \\<langle>e,s\\<^sub>3\\<rangle>\"\nshows \"P \\<turnstile> \\<langle>while (b) c,s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>e,s\\<^sub>3\\<rangle>\"\n(*<*)(is \"(?a, ?c) \\<in> (red P)\\<^sup>*\")\nproof -\n  let ?b = \"(if (b) (c;; while (b) c) else unit,s\\<^sub>0)\"\n  let ?y = \"(if (true) (c;; while (b) c) else unit,s\\<^sub>1)\"\n  let ?b' = \"(c;; while (b) c,s\\<^sub>1)\"\n  let ?y' = \"(Val v\\<^sub>1;; while (b) c,s\\<^sub>2)\"\n  have \"(?a, ?b) \\<in> (red P)\\<^sup>*\"\n    using RedWhile[THEN converse_rtrancl_into_rtrancl] by simp\n  also have \"(?b, ?y) \\<in> (red P)\\<^sup>*\" by(rule CondReds[OF b_steps])\n  also have \"(?y, ?b') \\<in> (red P)\\<^sup>*\"\n    using RedCondT[THEN converse_rtrancl_into_rtrancl] by simp\n  also have \"(?b', ?y') \\<in> (red P)\\<^sup>*\" by(rule SeqReds[OF c_steps])\n  also have \"(?y', ?c) \\<in> (red P)\\<^sup>*\"\n    by(rule RedSeq[THEN converse_rtrancl_into_rtrancl, OF while_steps])\n  ultimately show ?thesis by simp\nqed\n(*>*)\n\nlemma WhileTRedsThrow:\nassumes b_steps: \"P \\<turnstile> \\<langle>b,s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>true,s\\<^sub>1\\<rangle>\"\n    and c_steps: \"P \\<turnstile> \\<langle>c,s\\<^sub>1\\<rangle> \\<rightarrow>* \\<langle>throw e,s\\<^sub>2\\<rangle>\"\nshows \"P \\<turnstile> \\<langle>while (b) c,s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>throw e,s\\<^sub>2\\<rangle>\"\n(*<*)(is \"(?a, ?c) \\<in> (red P)\\<^sup>*\")\nproof -\n  let ?b = \"(if (b) (c;; while (b) c) else unit,s\\<^sub>0)\"\n  let ?y = \"(if (true) (c;; while (b) c) else unit,s\\<^sub>1)\"\n  let ?b' = \"(c;; while (b) c,s\\<^sub>1)\"\n  let ?y' = \"(throw e;; while (b) c,s\\<^sub>2)\"\n  have \"(?a, ?b) \\<in> (red P)\\<^sup>*\"\n    using RedWhile[THEN converse_rtrancl_into_rtrancl] by simp\n  also have \"(?b, ?y) \\<in> (red P)\\<^sup>*\" by(rule CondReds[OF b_steps])\n  also have \"(?y, ?b') \\<in> (red P)\\<^sup>*\"\n    using RedCondT[THEN converse_rtrancl_into_rtrancl] by simp\n  also have \"(?b', ?y') \\<in> (red P)\\<^sup>*\" by(rule SeqReds[OF c_steps])\n  also have \"(?y', ?c) \\<in> (red P)\" by(rule red_reds.SeqThrow)\n  ultimately show ?thesis by simp\nqed\n(*>*)\n\nsubsubsection\"Throw\"\n\nlemma ThrowReds:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>throw e,s\\<rangle> \\<rightarrow>* \\<langle>throw e',s'\\<rangle>\"\n(*<*)\nproof(induct rule: rtrancl_induct2)\n  case refl show ?case by blast\nnext\n  case step show ?case\n   by(rule rtrancl_into_rtrancl[OF step(3) ThrowRed[OF step(2)]])\nqed\n(*>*)\n\nlemma ThrowRedsNull:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>null,s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>throw e,s\\<rangle> \\<rightarrow>* \\<langle>THROW NullPointer,s'\\<rangle>\"\n(*<*)by(rule ThrowReds[THEN rtrancl_into_rtrancl, OF _ RedThrowNull])(*>*)\n\nlemma ThrowRedsThrow:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>throw a,s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>throw e,s\\<rangle> \\<rightarrow>* \\<langle>throw a,s'\\<rangle>\"\n(*<*)by(rule ThrowReds[THEN rtrancl_into_rtrancl, OF _ red_reds.ThrowThrow])(*>*)\n\nsubsubsection \"InitBlock\"\n\nlemma InitBlockReds_aux:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle> \\<Longrightarrow>\n  \\<forall>h l h' l' v. s = (h,l(V\\<mapsto>v)) \\<longrightarrow> s' = (h',l') \\<longrightarrow>\n  P \\<turnstile> \\<langle>{V:T := Val v; e},(h,l)\\<rangle> \\<rightarrow>* \\<langle>{V:T := Val(the(l' V)); e'},(h',l'(V:=(l V)))\\<rangle>\"\n(*<*)\nproof(induct rule: converse_rtrancl_induct2)\n  case refl then show ?case\n    by(fastforce simp: fun_upd_same simp del:fun_upd_apply)\nnext\n  case (step e0 s0 e1 s1)\n  obtain h1 l1 where s1[simp]: \"s1 = (h1, l1)\" by(cases s1) simp\n  { fix h0 l0 h2 l2 v0\n    assume [simp]: \"s0 = (h0, l0(V \\<mapsto> v0))\" and s'[simp]: \"s' = (h2, l2)\"    \n    then have \"V \\<in> dom l1\" using step(1) by(auto dest!: red_lcl_incr)\n    then obtain v1 where l1V[simp]: \"l1 V = \\<lfloor>v1\\<rfloor>\" by blast\n\n    let ?a = \"({V:T; V:=Val v0;; e0},(h0, l0))\"\n    let ?b = \"({V:T; V:=Val v1;; e1},(h1, l1(V := l0 V)))\"\n    let ?c = \"({V:T; V:=Val (the (l2 V));; e'},(h2, l2(V := l0 V)))\"\n    let ?l = \"l1(V := l0 V)\" and ?v = v1\n\n    have e0_steps: \"P \\<turnstile> \\<langle>e0,(h0, l0(V \\<mapsto> v0))\\<rangle> \\<rightarrow> \\<langle>e1,(h1, l1)\\<rangle>\"\n      using step(1) by simp\n\n    have lv: \"\\<And>l v. l1 = l(V \\<mapsto> v) \\<longrightarrow>\n             P \\<turnstile> \\<langle>{V:T; V:=Val v;; e1},(h1, l)\\<rangle> \\<rightarrow>*\n                  \\<langle>{V:T; V:=Val (the (l2 V));; e'},(h2, l2(V := l V))\\<rangle>\"\n      using step(3) s' s1 by blast\n    moreover have \"l1 = ?l(V \\<mapsto> ?v)\" by(rule ext) (simp add:fun_upd_def)\n    ultimately have \"(?b, ?c) \\<in> (red P)\\<^sup>*\" using lv[of ?l ?v] by simp\n    then have \"(?a, ?c) \\<in> (red P)\\<^sup>*\"\n      by(rule InitBlockRed[THEN converse_rtrancl_into_rtrancl, OF e0_steps l1V])\n  }\n  then show ?case by blast\nqed\n(*>*)\n\nlemma InitBlockReds:\n \"P \\<turnstile> \\<langle>e, (h,l(V\\<mapsto>v))\\<rangle> \\<rightarrow>* \\<langle>e', (h',l')\\<rangle> \\<Longrightarrow>\n  P \\<turnstile> \\<langle>{V:T := Val v; e}, (h,l)\\<rangle> \\<rightarrow>* \\<langle>{V:T := Val(the(l' V)); e'}, (h',l'(V:=(l V)))\\<rangle>\"\n(*<*)by(blast dest:InitBlockReds_aux)(*>*)\n\nlemma InitBlockRedsFinal:\n  \"\\<lbrakk> P \\<turnstile> \\<langle>e,(h,l(V\\<mapsto>v))\\<rangle> \\<rightarrow>* \\<langle>e',(h',l')\\<rangle>; final e' \\<rbrakk> \\<Longrightarrow>\n  P \\<turnstile> \\<langle>{V:T := Val v; e},(h,l)\\<rangle> \\<rightarrow>* \\<langle>e',(h', l'(V := l V))\\<rangle>\"\n(*<*)\nby(fast elim!:InitBlockReds[THEN rtrancl_into_rtrancl] finalE\n        intro:RedInitBlock InitBlockThrow)\n(*>*)\n\n\nsubsubsection \"Block\"\n\nlemma BlockRedsFinal:\nassumes reds: \"P \\<turnstile> \\<langle>e\\<^sub>0,s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>e\\<^sub>2,(h\\<^sub>2,l\\<^sub>2)\\<rangle>\" and fin: \"final e\\<^sub>2\"\nshows \"\\<And>h\\<^sub>0 l\\<^sub>0. s\\<^sub>0 = (h\\<^sub>0,l\\<^sub>0(V:=None)) \\<Longrightarrow> P \\<turnstile> \\<langle>{V:T; e\\<^sub>0},(h\\<^sub>0,l\\<^sub>0)\\<rangle> \\<rightarrow>* \\<langle>e\\<^sub>2,(h\\<^sub>2,l\\<^sub>2(V:=l\\<^sub>0 V))\\<rangle>\"\n(*<*)\nusing reds\nproof (induct rule:converse_rtrancl_induct2)\n  case refl thus ?case\n    by(fastforce intro:finalE[OF fin] RedBlock BlockThrow\n                simp del:fun_upd_apply)\nnext\n  case (step e\\<^sub>0 s\\<^sub>0 e\\<^sub>1 s\\<^sub>1)\n  have red: \"P \\<turnstile> \\<langle>e\\<^sub>0,s\\<^sub>0\\<rangle> \\<rightarrow> \\<langle>e\\<^sub>1,s\\<^sub>1\\<rangle>\"\n   and reds: \"P \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>1\\<rangle> \\<rightarrow>* \\<langle>e\\<^sub>2,(h\\<^sub>2,l\\<^sub>2)\\<rangle>\"\n   and IH: \"\\<And>h l. s\\<^sub>1 = (h,l(V := None))\n                \\<Longrightarrow> P \\<turnstile> \\<langle>{V:T; e\\<^sub>1},(h,l)\\<rangle> \\<rightarrow>* \\<langle>e\\<^sub>2,(h\\<^sub>2, l\\<^sub>2(V := l V))\\<rangle>\"\n   and s\\<^sub>0: \"s\\<^sub>0 = (h\\<^sub>0, l\\<^sub>0(V := None))\" by fact+\n  obtain h\\<^sub>1 l\\<^sub>1 where s\\<^sub>1: \"s\\<^sub>1 = (h\\<^sub>1,l\\<^sub>1)\" by fastforce\n  show ?case\n  proof cases\n    assume \"assigned V e\\<^sub>0\"\n    then obtain v e where e\\<^sub>0: \"e\\<^sub>0 = V := Val v;; e\"\n      by (unfold assigned_def)blast\n    from red e\\<^sub>0 s\\<^sub>0 have e\\<^sub>1: \"e\\<^sub>1 = unit;;e\" and s\\<^sub>1: \"s\\<^sub>1 = (h\\<^sub>0, l\\<^sub>0(V \\<mapsto> v))\"\n      by auto\n    from e\\<^sub>1 fin have \"e\\<^sub>1 \\<noteq> e\\<^sub>2\" by (auto simp:final_def)\n    then obtain e' s' where red1: \"P \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>1\\<rangle> \\<rightarrow> \\<langle>e',s'\\<rangle>\"\n      and reds': \"P \\<turnstile> \\<langle>e',s'\\<rangle> \\<rightarrow>* \\<langle>e\\<^sub>2,(h\\<^sub>2,l\\<^sub>2)\\<rangle>\"\n      using converse_rtranclE2[OF reds] by blast\n    from red1 e\\<^sub>1 have es': \"e' = e\" \"s' = s\\<^sub>1\" by auto\n    show ?case using e\\<^sub>0 s\\<^sub>1 es' reds'\n      by(fastforce intro!: InitBlockRedsFinal[OF _ fin] simp del:fun_upd_apply)\n  next\n    assume unass: \"\\<not> assigned V e\\<^sub>0\"\n    show ?thesis\n    proof (cases \"l\\<^sub>1 V\")\n      assume None: \"l\\<^sub>1 V = None\"\n      hence \"P \\<turnstile> \\<langle>{V:T; e\\<^sub>0},(h\\<^sub>0,l\\<^sub>0)\\<rangle> \\<rightarrow> \\<langle>{V:T; e\\<^sub>1},(h\\<^sub>1, l\\<^sub>1(V := l\\<^sub>0 V))\\<rangle>\"\n        using s\\<^sub>0 s\\<^sub>1 red by(simp add: BlockRedNone[OF _ _ unass])\n      moreover\n      have \"P \\<turnstile> \\<langle>{V:T; e\\<^sub>1},(h\\<^sub>1, l\\<^sub>1(V := l\\<^sub>0 V))\\<rangle> \\<rightarrow>* \\<langle>e\\<^sub>2,(h\\<^sub>2, l\\<^sub>2(V := l\\<^sub>0 V))\\<rangle>\"\n        using IH[of _ \"l\\<^sub>1(V := l\\<^sub>0 V)\"] s\\<^sub>1 None by(simp add:fun_upd_idem)\n      ultimately show ?case by(rule converse_rtrancl_into_rtrancl)\n    next\n      fix v assume Some: \"l\\<^sub>1 V = Some v\"\n      hence \"P \\<turnstile> \\<langle>{V:T;e\\<^sub>0},(h\\<^sub>0,l\\<^sub>0)\\<rangle> \\<rightarrow> \\<langle>{V:T := Val v; e\\<^sub>1},(h\\<^sub>1,l\\<^sub>1(V := l\\<^sub>0 V))\\<rangle>\"\n        using s\\<^sub>0 s\\<^sub>1 red by(simp add: BlockRedSome[OF _ _ unass])\n      moreover\n      have \"P \\<turnstile> \\<langle>{V:T := Val v; e\\<^sub>1},(h\\<^sub>1,l\\<^sub>1(V:= l\\<^sub>0 V))\\<rangle> \\<rightarrow>*\n                \\<langle>e\\<^sub>2,(h\\<^sub>2,l\\<^sub>2(V:=l\\<^sub>0 V))\\<rangle>\"\n        using InitBlockRedsFinal[OF _ fin,of _ _ \"l\\<^sub>1(V:=l\\<^sub>0 V)\" V]\n              Some reds s\\<^sub>1 by(simp add:fun_upd_idem)\n      ultimately show ?case by(rule converse_rtrancl_into_rtrancl)\n    qed\n  qed\nqed\n(*>*)\n\n\nsubsubsection \"try-catch\"\n\nlemma TryReds:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>try e catch(C V) e\\<^sub>2,s\\<rangle> \\<rightarrow>* \\<langle>try e' catch(C V) e\\<^sub>2,s'\\<rangle>\"\n(*<*)\nproof(induct rule: rtrancl_induct2)\n  case refl show ?case by blast\nnext\n  case step show ?case\n   by(rule rtrancl_into_rtrancl[OF step(3) TryRed[OF step(2)]])\nqed\n(*>*)\n\nlemma TryRedsVal:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>Val v,s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>try e catch(C V) e\\<^sub>2,s\\<rangle> \\<rightarrow>* \\<langle>Val v,s'\\<rangle>\"\n(*<*)by(rule TryReds[THEN rtrancl_into_rtrancl, OF _ RedTry])(*>*)\n\nlemma TryCatchRedsFinal:\nassumes e\\<^sub>1_steps: \"P \\<turnstile> \\<langle>e\\<^sub>1,s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>Throw a,(h\\<^sub>1,l\\<^sub>1)\\<rangle>\"\n  and h\\<^sub>1a: \"h\\<^sub>1 a = Some(D,fs)\" and sub: \"P \\<turnstile> D \\<preceq>\\<^sup>* C\"\n  and e\\<^sub>2_steps: \"P \\<turnstile> \\<langle>e\\<^sub>2, (h\\<^sub>1, l\\<^sub>1(V \\<mapsto> Addr a))\\<rangle> \\<rightarrow>* \\<langle>e\\<^sub>2', (h\\<^sub>2,l\\<^sub>2)\\<rangle>\"\n  and final: \"final e\\<^sub>2'\"\nshows \"P \\<turnstile> \\<langle>try e\\<^sub>1 catch(C V) e\\<^sub>2, s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>e\\<^sub>2', (h\\<^sub>2, (l\\<^sub>2::locals)(V := l\\<^sub>1 V))\\<rangle>\"\n(*<*)(is \"(?x, ?z) \\<in> (red P)\\<^sup>*\")\nproof -\n  let ?y = \"(try Throw a catch(C V) e\\<^sub>2,(h\\<^sub>1, l\\<^sub>1))\"\n  let ?b = \"({V:Class C; V:=addr a;; e\\<^sub>2},(h\\<^sub>1, l\\<^sub>1))\"\n  have bz: \"(?b, ?z) \\<in> (red P)\\<^sup>*\"\n    by(rule InitBlockRedsFinal[OF e\\<^sub>2_steps final])\n  have hp: \"hp (h\\<^sub>1, l\\<^sub>1) a = \\<lfloor>(D, fs)\\<rfloor>\" using h\\<^sub>1a by simp\n  have \"(?x, ?y) \\<in> (red P)\\<^sup>*\" by(rule TryReds[OF e\\<^sub>1_steps])\n  also have \"(?y, ?z) \\<in> (red P)\\<^sup>*\"\n    by(rule RedTryCatch[THEN converse_rtrancl_into_rtrancl, OF hp sub bz])\n  ultimately show ?thesis by simp\nqed\n(*>*)\n\nlemma TryRedsFail:\n  \"\\<lbrakk> P \\<turnstile> \\<langle>e\\<^sub>1,s\\<rangle> \\<rightarrow>* \\<langle>Throw a,(h,l)\\<rangle>; h a = Some(D,fs); \\<not> P \\<turnstile> D \\<preceq>\\<^sup>* C \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile> \\<langle>try e\\<^sub>1 catch(C V) e\\<^sub>2,s\\<rangle> \\<rightarrow>* \\<langle>Throw a,(h,l)\\<rangle>\"\n(*<*)by(fastforce intro!: TryReds[THEN rtrancl_into_rtrancl, OF _ RedTryFail])(*>*)\n\nsubsubsection \"List\"\n\nlemma ListReds1:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>e#es,s\\<rangle> [\\<rightarrow>]* \\<langle>e' # es,s'\\<rangle>\"\n(*<*)\nproof(induct rule: rtrancl_induct2)\n  case refl show ?case by blast\nnext\n  case step show ?case\n   by(rule rtrancl_into_rtrancl[OF step(3) ListRed1[OF step(2)]])\nqed\n(*>*)\n\nlemma ListReds2:\n  \"P \\<turnstile> \\<langle>es,s\\<rangle> [\\<rightarrow>]* \\<langle>es',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>Val v # es,s\\<rangle> [\\<rightarrow>]* \\<langle>Val v # es',s'\\<rangle>\"\n(*<*)\nproof(induct rule: rtrancl_induct2)\n  case refl show ?case by blast\nnext\n  case step show ?case\n   by(rule rtrancl_into_rtrancl[OF step(3) ListRed2[OF step(2)]])\nqed\n(*>*)\n\nlemma ListRedsVal:\n  \"\\<lbrakk> P \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>Val v,s\\<^sub>1\\<rangle>; P \\<turnstile> \\<langle>es,s\\<^sub>1\\<rangle> [\\<rightarrow>]* \\<langle>es',s\\<^sub>2\\<rangle> \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile> \\<langle>e#es,s\\<^sub>0\\<rangle> [\\<rightarrow>]* \\<langle>Val v # es',s\\<^sub>2\\<rangle>\"\n(*<*)by(rule rtrancl_trans[OF ListReds1 ListReds2])(*>*)\n\nsubsubsection\"Call\"\n\ntext\\<open>First a few lemmas on what happens to free variables during redction.\\<close>\n\nlemma assumes wf: \"wwf_J_prog P\"\nshows Red_fv: \"P \\<turnstile> \\<langle>e,(h,l)\\<rangle> \\<rightarrow> \\<langle>e',(h',l')\\<rangle> \\<Longrightarrow> fv e' \\<subseteq> fv e\"\n  and  \"P \\<turnstile> \\<langle>es,(h,l)\\<rangle> [\\<rightarrow>] \\<langle>es',(h',l')\\<rangle> \\<Longrightarrow> fvs es' \\<subseteq> fvs es\"\n(*<*)\nproof (induct rule:red_reds_inducts)\n  case (RedCall h l a C fs M Ts T pns body D vs)\n  hence \"fv body \\<subseteq> {this} \\<union> set pns\"\n    using assms by(fastforce dest!:sees_wf_mdecl simp:wf_mdecl_def)\n  with RedCall.hyps show ?case by fastforce\nqed auto\n(*>*)\n\n\nlemma Red_dom_lcl:\n  \"P \\<turnstile> \\<langle>e,(h,l)\\<rangle> \\<rightarrow> \\<langle>e',(h',l')\\<rangle> \\<Longrightarrow> dom l' \\<subseteq> dom l \\<union> fv e\" and\n  \"P \\<turnstile> \\<langle>es,(h,l)\\<rangle> [\\<rightarrow>] \\<langle>es',(h',l')\\<rangle> \\<Longrightarrow> dom l' \\<subseteq> dom l \\<union> fvs es\"\n(*<*)\nproof (induct rule:red_reds_inducts)\n  case RedLAss thus ?case by(force split:if_splits)\nnext\n  case CallParams thus ?case by(force split:if_splits)\nnext\n  case BlockRedNone thus ?case by clarsimp (fastforce split:if_splits)\nnext\n  case BlockRedSome thus ?case by clarsimp (fastforce split:if_splits)\nnext\n  case InitBlockRed thus ?case by clarsimp (fastforce split:if_splits)\nqed auto\n(*>*)\n\nlemma Reds_dom_lcl:\nassumes wf: \"wwf_J_prog P\"\nshows \"P \\<turnstile> \\<langle>e,(h,l)\\<rangle> \\<rightarrow>* \\<langle>e',(h',l')\\<rangle> \\<Longrightarrow> dom l' \\<subseteq> dom l \\<union> fv e\"\n(*<*)\nproof(induct rule: converse_rtrancl_induct_red)\n  case 1 then show ?case by blast\nnext\n  case 2 then show ?case using wf by(blast dest: Red_fv Red_dom_lcl)\nqed\n(*>*)\n\ntext\\<open>Now a few lemmas on the behaviour of blocks during reduction.\\<close>\n\n(* If you want to avoid the premise \"distinct\" further down \\<dots>\nconsts upd_vals :: \"locals \\<Rightarrow> vname list \\<Rightarrow> val list \\<Rightarrow> val list\"\nprimrec\n\"upd_vals l [] vs = []\"\n\"upd_vals l (V#Vs) vs = (if V \\<in> set Vs then hd vs else the(l V)) #\n                        upd_vals l Vs (tl vs)\"\n\n\n\ndeclare fun_upd_apply[simp del] map_upds_twist[simp del]\n(*>*)\n\n\nlemma blocksReds:\n  \"\\<And>l. \\<lbrakk> length Vs = length Ts; length vs = length Ts; distinct Vs;\n         P \\<turnstile> \\<langle>e, (h,l(Vs [\\<mapsto>] vs))\\<rangle> \\<rightarrow>* \\<langle>e', (h',l')\\<rangle> \\<rbrakk>\n        \\<Longrightarrow> P \\<turnstile> \\<langle>blocks(Vs,Ts,vs,e), (h,l)\\<rangle> \\<rightarrow>* \\<langle>blocks(Vs,Ts,map (the \\<circ> l') Vs,e'), (h',override_on l' l (set Vs))\\<rangle>\"\n(*<*)\nproof(induct Vs Ts vs e rule:blocks_induct)\n  case (1 V Vs T Ts v vs e) show ?case\n    using InitBlockReds[OF \"1.hyps\"[of \"l(V\\<mapsto>v)\"]] \"1.prems\"\n    by(auto simp:override_on_upd_lemma)\nqed auto\n(*>*)\n\n\nlemma blocksFinal:\n \"\\<And>l. \\<lbrakk> length Vs = length Ts; length vs = length Ts; final e \\<rbrakk> \\<Longrightarrow>\n       P \\<turnstile> \\<langle>blocks(Vs,Ts,vs,e), (h,l)\\<rangle> \\<rightarrow>* \\<langle>e, (h,l)\\<rangle>\"\n(*<*)\nproof(induct Vs Ts vs e rule:blocks_induct)\n  case 1\n  show ?case using \"1.prems\" InitBlockReds[OF \"1.hyps\"]\n    by(fastforce elim!:finalE elim: rtrancl_into_rtrancl[OF _ RedInitBlock]\n                                   rtrancl_into_rtrancl[OF _ InitBlockThrow])\nqed auto\n(*>*)\n\n\nlemma blocksRedsFinal:\nassumes wf: \"length Vs = length Ts\" \"length vs = length Ts\" \"distinct Vs\"\n    and reds: \"P \\<turnstile> \\<langle>e, (h,l(Vs [\\<mapsto>] vs))\\<rangle> \\<rightarrow>* \\<langle>e', (h',l')\\<rangle>\"\n    and fin: \"final e'\" and l'': \"l'' = override_on l' l (set Vs)\"\nshows \"P \\<turnstile> \\<langle>blocks(Vs,Ts,vs,e), (h,l)\\<rangle> \\<rightarrow>* \\<langle>e', (h',l'')\\<rangle>\"\n(*<*)\nproof -\n  let ?bv = \"blocks(Vs,Ts,map (the o l') Vs,e')\"\n  have \"P \\<turnstile> \\<langle>blocks(Vs,Ts,vs,e), (h,l)\\<rangle> \\<rightarrow>* \\<langle>?bv, (h',l'')\\<rangle>\"\n    using l'' by simp (rule blocksReds[OF wf reds])\n  also have \"P \\<turnstile> \\<langle>?bv, (h',l'')\\<rangle> \\<rightarrow>* \\<langle>e', (h',l'')\\<rangle>\"\n    using wf by(fastforce intro:blocksFinal fin)\n  finally show ?thesis .\nqed\n(*>*)\n\ntext\\<open>An now the actual method call reduction lemmas.\\<close>\n\nlemma CallRedsObj:\n \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>e\\<bullet>M(es),s\\<rangle> \\<rightarrow>* \\<langle>e'\\<bullet>M(es),s'\\<rangle>\"\n(*<*)\nproof(induct rule: rtrancl_induct2)\n  case refl show ?case by blast\nnext\n  case step show ?case\n   by(rule rtrancl_into_rtrancl[OF step(3) CallObj[OF step(2)]])\nqed\n(*>*)\n\n\nlemma CallRedsParams:\n \"P \\<turnstile> \\<langle>es,s\\<rangle> [\\<rightarrow>]* \\<langle>es',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>(Val v)\\<bullet>M(es),s\\<rangle> \\<rightarrow>* \\<langle>(Val v)\\<bullet>M(es'),s'\\<rangle>\"\n(*<*)\nproof(induct rule: rtrancl_induct2)\n  case refl show ?case by blast\nnext\n  case step show ?case\n   by(rule rtrancl_into_rtrancl[OF step(3) CallParams[OF step(2)]])\nqed\n(*>*)\n\n\nlemma CallRedsFinal:\nassumes wwf: \"wwf_J_prog P\"\nand \"P \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>addr a,s\\<^sub>1\\<rangle>\"\n      \"P \\<turnstile> \\<langle>es,s\\<^sub>1\\<rangle> [\\<rightarrow>]* \\<langle>map Val vs,(h\\<^sub>2,l\\<^sub>2)\\<rangle>\"\n      \"h\\<^sub>2 a = Some(C,fs)\" \"P \\<turnstile> C sees M:Ts\\<rightarrow>T = (pns,body) in D\"\n      \"size vs = size pns\"\nand l\\<^sub>2': \"l\\<^sub>2' = [this \\<mapsto> Addr a, pns[\\<mapsto>]vs]\"\nand body: \"P \\<turnstile> \\<langle>body,(h\\<^sub>2,l\\<^sub>2')\\<rangle> \\<rightarrow>* \\<langle>ef,(h\\<^sub>3,l\\<^sub>3)\\<rangle>\"\nand \"final ef\"\nshows \"P \\<turnstile> \\<langle>e\\<bullet>M(es), s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>ef,(h\\<^sub>3,l\\<^sub>2)\\<rangle>\"\n(*<*)\nproof -\n  have wf: \"size Ts = size pns \\<and> distinct pns \\<and> this \\<notin> set pns\"\n    and wt: \"fv body \\<subseteq> {this} \\<union> set pns\"\n    using assms by(fastforce dest!:sees_wf_mdecl simp:wf_mdecl_def)+\n  from body[THEN Red_lcl_add, of l\\<^sub>2]\n  have body': \"P \\<turnstile> \\<langle>body,(h\\<^sub>2,l\\<^sub>2(this\\<mapsto> Addr a, pns[\\<mapsto>]vs))\\<rangle> \\<rightarrow>* \\<langle>ef,(h\\<^sub>3,l\\<^sub>2++l\\<^sub>3)\\<rangle>\"\n    by (simp add:l\\<^sub>2')\n  have \"dom l\\<^sub>3 \\<subseteq> {this} \\<union> set pns\"\n    using Reds_dom_lcl[OF wwf body] wt l\\<^sub>2' set_take_subset by force\n  hence eql\\<^sub>2: \"override_on (l\\<^sub>2++l\\<^sub>3) l\\<^sub>2 ({this} \\<union> set pns) = l\\<^sub>2\"\n    by(fastforce simp add:map_add_def override_on_def fun_eq_iff)\n  have \"P \\<turnstile> \\<langle>e\\<bullet>M(es),s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>(addr a)\\<bullet>M(es),s\\<^sub>1\\<rangle>\" by(rule CallRedsObj)(rule assms(2))\n  also have \"P \\<turnstile> \\<langle>(addr a)\\<bullet>M(es),s\\<^sub>1\\<rangle> \\<rightarrow>*\n                 \\<langle>(addr a)\\<bullet>M(map Val vs),(h\\<^sub>2,l\\<^sub>2)\\<rangle>\"\n    by(rule CallRedsParams)(rule assms(3))\n  also have \"P \\<turnstile> \\<langle>(addr a)\\<bullet>M(map Val vs), (h\\<^sub>2,l\\<^sub>2)\\<rangle> \\<rightarrow>\n                 \\<langle>blocks(this#pns, Class D#Ts, Addr a#vs, body), (h\\<^sub>2,l\\<^sub>2)\\<rangle>\"\n    by(rule RedCall)(auto simp: assms wf, rule assms(5))\n  also (rtrancl_into_rtrancl) have \"P \\<turnstile> \\<langle>blocks(this#pns, Class D#Ts, Addr a#vs, body), (h\\<^sub>2,l\\<^sub>2)\\<rangle>\n                 \\<rightarrow>* \\<langle>ef,(h\\<^sub>3,override_on (l\\<^sub>2++l\\<^sub>3) l\\<^sub>2 ({this} \\<union> set pns))\\<rangle>\"\n    by(rule blocksRedsFinal, insert assms wf body', simp_all)\n  finally show ?thesis using eql\\<^sub>2 by simp\nqed\n(*>*)\n\n\nlemma CallRedsThrowParams:\nassumes e_steps: \"P \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>Val v,s\\<^sub>1\\<rangle>\"\n  and es_steps: \"P \\<turnstile> \\<langle>es,s\\<^sub>1\\<rangle> [\\<rightarrow>]* \\<langle>map Val vs\\<^sub>1 @ throw a # es\\<^sub>2,s\\<^sub>2\\<rangle>\"\nshows \"P \\<turnstile> \\<langle>e\\<bullet>M(es),s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>throw a,s\\<^sub>2\\<rangle>\"\n(*<*)(is \"(?x, ?z) \\<in> (red P)\\<^sup>*\")\nproof -\n  let ?y = \"(Val v\\<bullet>M(es),s\\<^sub>1)\"\n  let ?y' = \"(Val v\\<bullet>M(map Val vs\\<^sub>1 @ throw a # es\\<^sub>2),s\\<^sub>2)\"\n  have \"(?x, ?y) \\<in> (red P)\\<^sup>*\" by(rule CallRedsObj[OF e_steps])\n  also have \"(?y, ?y') \\<in> (red P)\\<^sup>*\" by(rule CallRedsParams[OF es_steps])\n  also have \"(?y', ?z) \\<in> (red P)\\<^sup>*\" using CallThrowParams by fast\n  ultimately show ?thesis by simp\nqed\n(*>*)\n\n\nlemma CallRedsThrowObj:\n  \"P \\<turnstile> \\<langle>e,s0\\<rangle> \\<rightarrow>* \\<langle>throw a,s\\<^sub>1\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>e\\<bullet>M(es),s0\\<rangle> \\<rightarrow>* \\<langle>throw a,s\\<^sub>1\\<rangle>\"\n(*<*)by(rule CallRedsObj[THEN rtrancl_into_rtrancl, OF _ CallThrowObj])(*>*)\n\n\nlemma CallRedsNull:\nassumes e_steps: \"P \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>null,s\\<^sub>1\\<rangle>\"\n  and es_steps: \"P \\<turnstile> \\<langle>es,s\\<^sub>1\\<rangle> [\\<rightarrow>]* \\<langle>map Val vs,s\\<^sub>2\\<rangle>\"\nshows \"P \\<turnstile> \\<langle>e\\<bullet>M(es),s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>THROW NullPointer,s\\<^sub>2\\<rangle>\"\n(*<*)(is \"(?x, ?z) \\<in> (red P)\\<^sup>*\")\nproof -\n  let ?y = \"(null\\<bullet>M(es),s\\<^sub>1)\"\n  let ?y' = \"(null\\<bullet>M(map Val vs),s\\<^sub>2)\"\n  have \"(?x, ?y) \\<in> (red P)\\<^sup>*\" by(rule CallRedsObj[OF e_steps])\n  also have \"(?y, ?y') \\<in> (red P)\\<^sup>*\" by(rule CallRedsParams[OF es_steps])\n  also have \"(?y', ?z) \\<in> (red P)\" by(rule RedCallNull)\n  ultimately show ?thesis by simp\nqed\n(*>*)\n\nsubsubsection \"The main Theorem\"\n\nlemma assumes wwf: \"wwf_J_prog P\"\nshows big_by_small: \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle>\"\nand bigs_by_smalls: \"P \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>es',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>es,s\\<rangle> [\\<rightarrow>]* \\<langle>es',s'\\<rangle>\"\n(*<*)\nproof (induct rule: eval_evals.inducts)\n  case New thus ?case by (auto simp:RedNew)\nnext\n  case NewFail thus ?case by (auto simp:RedNewFail)\nnext\n  case Cast thus ?case by(fastforce intro:CastRedsAddr)\nnext\n  case CastNull thus ?case by(simp add:CastRedsNull)\nnext\n  case CastFail thus ?case by(fastforce intro!:CastRedsFail)\nnext\n  case CastThrow thus ?case by(auto dest!:eval_final simp:CastRedsThrow)\nnext\n  case Val thus ?case by simp\nnext\n  case BinOp thus ?case by(auto simp:BinOpRedsVal)\nnext\n  case BinOpThrow1 thus ?case by(auto dest!:eval_final simp: BinOpRedsThrow1)\nnext\n  case BinOpThrow2 thus ?case by(auto dest!:eval_final simp: BinOpRedsThrow2)\nnext\n  case Var thus ?case by (auto simp:RedVar)\nnext\n  case LAss thus ?case by(auto simp: LAssRedsVal)\nnext\n  case LAssThrow thus ?case by(auto dest!:eval_final simp: LAssRedsThrow)\nnext\n  case FAcc thus ?case by(auto intro:FAccRedsVal)\nnext\n  case FAccNull thus ?case by(simp add:FAccRedsNull)\nnext\n  case FAccThrow thus ?case by(auto dest!:eval_final simp:FAccRedsThrow)\nnext\n  case FAss thus ?case by(auto simp:FAssRedsVal)\nnext\n  case FAssNull thus ?case by(auto simp:FAssRedsNull)\nnext\n  case FAssThrow1 thus ?case by(auto dest!:eval_final simp:FAssRedsThrow1)\nnext\n  case FAssThrow2 thus ?case by(auto dest!:eval_final simp:FAssRedsThrow2)\nnext\n  case CallObjThrow thus ?case by(auto dest!:eval_final simp:CallRedsThrowObj)\nnext\n  case CallNull thus ?case by(simp add:CallRedsNull)\nnext\n  case CallParamsThrow thus ?case\n    by(auto dest!:evals_final simp:CallRedsThrowParams)\nnext\n  case (Call e s\\<^sub>0 a s\\<^sub>1 ps vs h\\<^sub>2 l\\<^sub>2 C fs M Ts T pns body D l\\<^sub>2' e' h\\<^sub>3 l\\<^sub>3)\n  have IHe: \"P \\<turnstile> \\<langle>e,s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>addr a,s\\<^sub>1\\<rangle>\"\n    and IHes: \"P \\<turnstile> \\<langle>ps,s\\<^sub>1\\<rangle> [\\<rightarrow>]* \\<langle>map Val vs,(h\\<^sub>2,l\\<^sub>2)\\<rangle>\"\n    and h\\<^sub>2a: \"h\\<^sub>2 a = Some(C,fs)\"\n    and \"method\": \"P \\<turnstile> C sees M:Ts\\<rightarrow>T = (pns,body) in D\"\n    and same_length: \"length vs = length pns\"\n    and l\\<^sub>2': \"l\\<^sub>2' = [this \\<mapsto> Addr a, pns[\\<mapsto>]vs]\"\n    and eval_body: \"P \\<turnstile> \\<langle>body,(h\\<^sub>2, l\\<^sub>2')\\<rangle> \\<Rightarrow> \\<langle>e',(h\\<^sub>3, l\\<^sub>3)\\<rangle>\"\n    and IHbody: \"P \\<turnstile> \\<langle>body,(h\\<^sub>2,l\\<^sub>2')\\<rangle> \\<rightarrow>* \\<langle>e',(h\\<^sub>3,l\\<^sub>3)\\<rangle>\" by fact+\n  show \"P \\<turnstile> \\<langle>e\\<bullet>M(ps),s\\<^sub>0\\<rangle> \\<rightarrow>* \\<langle>e',(h\\<^sub>3, l\\<^sub>2)\\<rangle>\"\n    using \"method\" same_length l\\<^sub>2' h\\<^sub>2a IHbody eval_final[OF eval_body]\n    by(fastforce intro:CallRedsFinal[OF wwf IHe IHes])\nnext\n  case Block thus ?case by(auto simp: BlockRedsFinal dest:eval_final)\nnext\n  case Seq thus ?case by(auto simp:SeqReds2)\nnext\n  case SeqThrow thus ?case by(auto dest!:eval_final simp: SeqRedsThrow)\nnext\n  case CondT thus ?case by(auto simp:CondReds2T)\nnext\n  case CondF thus ?case by(auto simp:CondReds2F)\nnext\n  case CondThrow thus ?case by(auto dest!:eval_final simp:CondRedsThrow)\nnext\n  case WhileF thus ?case by(auto simp:WhileFReds)\nnext\n  case WhileT thus ?case by(auto simp: WhileTReds)\nnext\n  case WhileCondThrow thus ?case by(auto dest!:eval_final simp: WhileRedsThrow)\nnext\n  case WhileBodyThrow thus ?case by(auto dest!:eval_final simp: WhileTRedsThrow)\nnext\n  case Throw thus ?case by(auto simp:ThrowReds)\nnext\n  case ThrowNull thus ?case by(auto simp:ThrowRedsNull)\nnext\n  case ThrowThrow thus ?case by(auto dest!:eval_final simp:ThrowRedsThrow)\nnext\n  case Try thus ?case by(simp add:TryRedsVal)\nnext\n  case TryCatch thus ?case by(fast intro!: TryCatchRedsFinal dest!:eval_final)\nnext\n  case TryThrow thus ?case by(fastforce intro!:TryRedsFail)\nnext\n  case Nil thus ?case by simp\nnext\n  case Cons thus ?case\n    by(fastforce intro!:Cons_eq_appendI[OF refl refl] ListRedsVal)\nnext\n  case ConsThrow thus ?case by(fastforce elim: ListReds1)\nqed\n(*>*)\n\n\nsubsection\\<open>Big steps simulates small step\\<close>\n\ntext\\<open>This direction was carried out by Norbert Schirmer and Daniel\nWasserrab.\\<close>\n\ntext \\<open>The big step equivalent of \\<open>RedWhile\\<close>:\\<close> \n\nlemma unfold_while: \n  \"P \\<turnstile> \\<langle>while(b) c,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>  =  P \\<turnstile> \\<langle>if(b) (c;;while(b) c) else (unit),s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n(*<*)\nproof\n  assume \"P \\<turnstile> \\<langle>while (b) c,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n  thus \"P \\<turnstile> \\<langle>if (b) (c;; while (b) c) else unit,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n    by cases (fastforce intro: eval_evals.intros)+\nnext\n  assume \"P \\<turnstile> \\<langle>if (b) (c;; while (b) c) else unit,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n  thus \"P \\<turnstile> \\<langle>while (b) c,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n  proof (cases)\n    fix a\n    assume e': \"e' = throw a\"\n    assume \"P \\<turnstile> \\<langle>b,s\\<rangle> \\<Rightarrow> \\<langle>throw a,s'\\<rangle>\"  \n    hence \"P \\<turnstile> \\<langle>while(b) c,s\\<rangle> \\<Rightarrow> \\<langle>throw a,s'\\<rangle>\" by (rule WhileCondThrow)\n    with e' show ?thesis by simp\n  next\n    fix s\\<^sub>1\n    assume eval_false: \"P \\<turnstile> \\<langle>b,s\\<rangle> \\<Rightarrow> \\<langle>false,s\\<^sub>1\\<rangle>\"\n    and eval_unit: \"P \\<turnstile> \\<langle>unit,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n    with eval_unit have \"s' = s\\<^sub>1\" \"e' = unit\" by (auto elim: eval_cases)\n    moreover from eval_false have \"P \\<turnstile> \\<langle>while (b) c,s\\<rangle> \\<Rightarrow> \\<langle>unit,s\\<^sub>1\\<rangle>\"\n      by - (rule WhileF, simp)\n    ultimately show ?thesis by simp\n  next\n    fix s\\<^sub>1\n    assume eval_true: \"P \\<turnstile> \\<langle>b,s\\<rangle> \\<Rightarrow> \\<langle>true,s\\<^sub>1\\<rangle>\"\n    and eval_rest: \"P \\<turnstile> \\<langle>c;; while (b) c,s\\<^sub>1\\<rangle>\\<Rightarrow>\\<langle>e',s'\\<rangle>\"\n    from eval_rest show ?thesis\n    proof (cases)\n      fix s\\<^sub>2 v\\<^sub>1\n      assume \"P \\<turnstile> \\<langle>c,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>Val v\\<^sub>1,s\\<^sub>2\\<rangle>\" \"P \\<turnstile> \\<langle>while (b) c,s\\<^sub>2\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n      with eval_true show \"P \\<turnstile> \\<langle>while(b) c,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\" by (rule WhileT)\n    next\n      fix a\n      assume \"P \\<turnstile> \\<langle>c,s\\<^sub>1\\<rangle> \\<Rightarrow> \\<langle>throw a,s'\\<rangle>\" \"e' = throw a\"\n      with eval_true show \"P \\<turnstile> \\<langle>while(b) c,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"        \n        by (iprover intro: WhileBodyThrow)\n    qed\n  qed\nqed\n(*>*)\n\n\nlemma blocksEval:\n  \"\\<And>Ts vs l l'. \\<lbrakk>size ps = size Ts; size ps = size vs; P \\<turnstile> \\<langle>blocks(ps,Ts,vs,e),(h,l)\\<rangle> \\<Rightarrow> \\<langle>e',(h',l')\\<rangle> \\<rbrakk>\n    \\<Longrightarrow> \\<exists> l''. P \\<turnstile> \\<langle>e,(h,l(ps[\\<mapsto>]vs))\\<rangle> \\<Rightarrow> \\<langle>e',(h',l'')\\<rangle>\"\n(*<*)\nproof (induct ps)\n  case Nil then show ?case by fastforce\nnext\n  case (Cons p ps')\n  have length_eqs: \"length (p # ps') = length Ts\" \n                   \"length (p # ps') = length vs\" by fact+\n  then obtain T Ts' where Ts: \"Ts = T#Ts'\" by (cases \"Ts\") simp\n  obtain v vs' where vs: \"vs = v#vs'\" using length_eqs by (cases \"vs\") simp\n  have \"P \\<turnstile> \\<langle>blocks (p # ps', Ts, vs, e),(h,l)\\<rangle> \\<Rightarrow> \\<langle>e',(h', l')\\<rangle>\" by fact\n  with Ts vs \n  have \"P \\<turnstile> \\<langle>{p:T := Val v; blocks (ps', Ts', vs', e)},(h,l)\\<rangle> \\<Rightarrow> \\<langle>e',(h', l')\\<rangle>\"\n    by simp\n  then obtain l''' where\n    eval_ps': \"P \\<turnstile> \\<langle>blocks (ps', Ts', vs', e),(h, l(p\\<mapsto>v))\\<rangle> \\<Rightarrow> \\<langle>e',(h', l''')\\<rangle>\"\n    and l''': \"l'=l'''(p:=l p)\"\n    by (auto elim!: eval_cases)\n  then obtain l'' where \n    hyp: \"P \\<turnstile> \\<langle>e,(h, l(p\\<mapsto>v, ps'[\\<mapsto>]vs'))\\<rangle> \\<Rightarrow> \\<langle>e',(h', l'')\\<rangle>\"\n    using length_eqs Ts vs Cons.hyps [OF _ _ eval_ps'] by auto\n  from hyp\n  show \"\\<exists>l''. P \\<turnstile> \\<langle>e,(h, l(p # ps'[\\<mapsto>]vs))\\<rangle> \\<Rightarrow> \\<langle>e',(h', l'')\\<rangle>\"\n    using Ts vs by auto\nqed\n(*>*)\n(* FIXME exercise: show precise relationship between l' and l'':\nlemma blocksEval:\n  \"\\<And> Ts vs l l'. \\<lbrakk>length ps = length Ts; length ps = length vs; \n        P\\<turnstile> \\<langle>blocks(ps,Ts,vs,e),(h,l)\\<rangle> \\<Rightarrow> \\<langle>e',(h',l')\\<rangle> \\<rbrakk>\n    \\<Longrightarrow> \\<exists> l''. P \\<turnstile> \\<langle>e,(h,l(ps[\\<mapsto>]vs))\\<rangle> \\<Rightarrow> \\<langle>e',(h',l'')\\<rangle> \\<and> l'=l''(l|set ps)\"\nproof (induct ps)\n  case Nil then show ?case by simp\nnext\n  case (Cons p ps')\n  have length_eqs: \"length (p # ps') = length Ts\" \n                   \"length (p # ps') = length vs\" .\n  then obtain T Ts' where Ts: \"Ts=T#Ts'\" by (cases \"Ts\") simp\n  obtain v vs' where vs: \"vs=v#vs'\" using length_eqs by (cases \"vs\") simp\n  have \"P \\<turnstile> \\<langle>blocks (p # ps', Ts, vs, e),(h,l)\\<rangle> \\<Rightarrow> \\<langle>e',(h', l')\\<rangle>\".\n  with Ts vs \n  have \"P \\<turnstile> \\<langle>{p:T := Val v; blocks (ps', Ts', vs', e)},(h,l)\\<rangle> \\<Rightarrow> \\<langle>e',(h', l')\\<rangle>\"\n    by simp\n  then obtain l''' where\n    eval_ps': \"P \\<turnstile> \\<langle>blocks (ps', Ts', vs', e),(h, l(p\\<mapsto>v))\\<rangle> \\<Rightarrow> \\<langle>e',(h', l''')\\<rangle>\"\n    and l''': \"l'=l'''(p:=l p)\"\n    by (cases) (auto elim: eval_cases)\n \n  then obtain l'' where \n    hyp: \"P \\<turnstile> \\<langle>e,(h, l(p\\<mapsto>v)(ps'[\\<mapsto>]vs'))\\<rangle> \\<Rightarrow> \\<langle>e',(h', l'')\\<rangle>\" and\n    l'': \"l''' = l''(l(p\\<mapsto>v)|set ps')\"\n    using length_eqs Ts vs Cons.hyps [OF _ _ eval_ps'] by auto\n  have \"l' = l''(l|set (p # ps'))\"\n  proof -\n    have \"(l''(l(p\\<mapsto>v)|set ps'))(p := l p) = l''(l|insert p (set ps'))\"\n      by (induct ps') (auto intro: ext simp add: fun_upd_def override_on_def)\n    with l''' l'' show ?thesis  by simp\n  qed\n  with hyp\n  show \"\\<exists>l''. P \\<turnstile> \\<langle>e,(h, l(p # ps'[\\<mapsto>]vs))\\<rangle> \\<Rightarrow> \\<langle>e',(h', l'')\\<rangle> \\<and>\n        l' = l''(l|set (p # ps'))\"\n    using Ts vs by auto\nqed\n*)\n\nlemma\nassumes wf: \"wwf_J_prog P\"\nshows eval_restrict_lcl:\n  \"P \\<turnstile> \\<langle>e,(h,l)\\<rangle> \\<Rightarrow> \\<langle>e',(h',l')\\<rangle> \\<Longrightarrow> (\\<And>W. fv e \\<subseteq> W \\<Longrightarrow> P \\<turnstile> \\<langle>e,(h,l|`W)\\<rangle> \\<Rightarrow> \\<langle>e',(h',l'|`W)\\<rangle>)\"\nand \"P \\<turnstile> \\<langle>es,(h,l)\\<rangle> [\\<Rightarrow>] \\<langle>es',(h',l')\\<rangle> \\<Longrightarrow> (\\<And>W. fvs es \\<subseteq> W \\<Longrightarrow> P \\<turnstile> \\<langle>es,(h,l|`W)\\<rangle> [\\<Rightarrow>] \\<langle>es',(h',l'|`W)\\<rangle>)\"\n(*<*)\nproof(induct rule:eval_evals_inducts)\n  case (Block e\\<^sub>0 h\\<^sub>0 l\\<^sub>0 V e\\<^sub>1 h\\<^sub>1 l\\<^sub>1 T)\n  have IH: \"\\<And>W. fv e\\<^sub>0 \\<subseteq> W \\<Longrightarrow> P \\<turnstile> \\<langle>e\\<^sub>0,(h\\<^sub>0,l\\<^sub>0(V:=None)|`W)\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>1,(h\\<^sub>1,l\\<^sub>1|`W)\\<rangle>\" by fact\n  have \"fv({V:T; e\\<^sub>0}) \\<subseteq> W\" by fact+\n  hence \"fv e\\<^sub>0 - {V} \\<subseteq> W\" by simp_all\n  hence \"fv e\\<^sub>0 \\<subseteq> insert V W\" by fast\n  from IH[OF this]\n  have \"P \\<turnstile> \\<langle>e\\<^sub>0,(h\\<^sub>0, (l\\<^sub>0|`W)(V := None))\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>1,(h\\<^sub>1, l\\<^sub>1|`insert V W)\\<rangle>\"\n    by fastforce\n  from eval_evals.Block[OF this] show ?case by fastforce\nnext\n  case Seq thus ?case by simp (blast intro:eval_evals.Seq)\nnext\n  case New thus ?case by(simp add:eval_evals.intros)\nnext\n  case NewFail thus ?case by(simp add:eval_evals.intros)\nnext\n  case Cast thus ?case by simp (blast intro:eval_evals.Cast)\nnext\n  case CastNull thus ?case by simp (blast intro:eval_evals.CastNull)\nnext\n  case CastFail thus ?case by simp (blast intro:eval_evals.CastFail)\nnext\n  case CastThrow thus ?case by(simp add:eval_evals.intros)\nnext\n  case Val thus ?case by(simp add:eval_evals.intros)\nnext\n  case BinOp thus ?case by simp (blast intro:eval_evals.BinOp)\nnext\n  case BinOpThrow1 thus ?case by simp (blast intro:eval_evals.BinOpThrow1)\nnext\n  case BinOpThrow2 thus ?case by simp (blast intro:eval_evals.BinOpThrow2)\nnext\n  case Var thus ?case by(simp add:eval_evals.intros)\nnext\n  case (LAss e h\\<^sub>0 l\\<^sub>0 v h l l' V)\n  have IH: \"\\<And>W. fv e \\<subseteq> W \\<Longrightarrow> P \\<turnstile> \\<langle>e,(h\\<^sub>0,l\\<^sub>0|`W)\\<rangle> \\<Rightarrow> \\<langle>Val v,(h,l|`W)\\<rangle>\"\n   and [simp]: \"l' = l(V \\<mapsto> v)\" by fact+\n  have \"fv (V:=e) \\<subseteq> W\" by fact\n  hence fv: \"fv e \\<subseteq> W\" and VinW: \"V \\<in> W\" by auto\n  from eval_evals.LAss[OF IH[OF fv] refl, of V] VinW\n  show ?case by simp\nnext\n  case LAssThrow thus ?case by(fastforce intro: eval_evals.LAssThrow)\nnext\n  case FAcc thus ?case by simp (blast intro: eval_evals.FAcc)\nnext\n  case FAccNull thus ?case by(fastforce intro: eval_evals.FAccNull)\nnext\n  case FAccThrow thus ?case by(fastforce intro: eval_evals.FAccThrow)\nnext\n  case FAss thus ?case by simp (blast intro: eval_evals.FAss)\nnext\n  case FAssNull thus ?case by simp (blast intro: eval_evals.FAssNull)\nnext\n  case FAssThrow1 thus ?case by simp (blast intro: eval_evals.FAssThrow1)\nnext\n  case FAssThrow2 thus ?case by simp (blast intro: eval_evals.FAssThrow2)\nnext\n  case CallObjThrow thus ?case by simp (blast intro: eval_evals.intros)\nnext\n  case CallNull thus ?case by simp (blast intro: eval_evals.CallNull)\nnext\n  case CallParamsThrow thus ?case\n    by simp (blast intro: eval_evals.CallParamsThrow)\nnext\n  case (Call e h\\<^sub>0 l\\<^sub>0 a h\\<^sub>1 l\\<^sub>1 ps vs h\\<^sub>2 l\\<^sub>2 C fs M Ts T pns body\n      D l\\<^sub>2' e' h\\<^sub>3 l\\<^sub>3)\n  have IHe: \"\\<And>W. fv e \\<subseteq> W \\<Longrightarrow> P \\<turnstile> \\<langle>e,(h\\<^sub>0,l\\<^sub>0|`W)\\<rangle> \\<Rightarrow> \\<langle>addr a,(h\\<^sub>1,l\\<^sub>1|`W)\\<rangle>\"\n   and IHps: \"\\<And>W. fvs ps \\<subseteq> W \\<Longrightarrow> P \\<turnstile> \\<langle>ps,(h\\<^sub>1,l\\<^sub>1|`W)\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs,(h\\<^sub>2,l\\<^sub>2|`W)\\<rangle>\"\n   and IHbd: \"\\<And>W. fv body \\<subseteq> W \\<Longrightarrow> P \\<turnstile> \\<langle>body,(h\\<^sub>2,l\\<^sub>2'|`W)\\<rangle> \\<Rightarrow> \\<langle>e',(h\\<^sub>3,l\\<^sub>3|`W)\\<rangle>\"\n   and h\\<^sub>2a: \"h\\<^sub>2 a = Some (C, fs)\"\n   and \"method\": \"P \\<turnstile> C sees M: Ts\\<rightarrow>T = (pns, body) in D\"\n   and same_len: \"size vs = size pns\"\n   and l\\<^sub>2': \"l\\<^sub>2' = [this \\<mapsto> Addr a, pns [\\<mapsto>] vs]\" by fact+\n  have \"fv (e\\<bullet>M(ps)) \\<subseteq> W\" by fact\n  hence fve: \"fv e  \\<subseteq> W\" and fvps: \"fvs(ps) \\<subseteq> W\" by auto\n  have wfmethod: \"size Ts = size pns \\<and> this \\<notin> set pns\" and\n       fvbd: \"fv body \\<subseteq> {this} \\<union> set pns\"\n    using \"method\" wf by(fastforce dest!:sees_wf_mdecl simp:wf_mdecl_def)+\n  show ?case\n    using IHbd[OF fvbd] l\\<^sub>2' same_len wfmethod h\\<^sub>2a\n      eval_evals.Call[OF IHe[OF fve] IHps[OF fvps] _ \"method\" same_len l\\<^sub>2']\n    by (simp add:subset_insertI)\nnext\n  case SeqThrow thus ?case by simp (blast intro: eval_evals.SeqThrow)\nnext\n  case CondT thus ?case by simp (blast intro: eval_evals.CondT)\nnext\n  case CondF thus ?case by simp (blast intro: eval_evals.CondF)\nnext\n  case CondThrow thus ?case by simp (blast intro: eval_evals.CondThrow)\nnext\n  case WhileF thus ?case by simp (blast intro: eval_evals.WhileF)\nnext\n  case WhileT thus ?case by simp (blast intro: eval_evals.WhileT)\nnext\n  case WhileCondThrow thus ?case by simp (blast intro: eval_evals.WhileCondThrow)\nnext\n  case WhileBodyThrow thus ?case by simp (blast intro: eval_evals.WhileBodyThrow)\nnext\n  case Throw thus ?case by simp (blast intro: eval_evals.Throw)\nnext\n  case ThrowNull thus ?case by simp (blast intro: eval_evals.ThrowNull)\nnext\n  case ThrowThrow thus ?case by simp (blast intro: eval_evals.ThrowThrow)\nnext\n  case Try thus ?case by simp (blast intro: eval_evals.Try)\nnext\n  case (TryCatch e\\<^sub>1 h\\<^sub>0 l\\<^sub>0 a h\\<^sub>1 l\\<^sub>1 D fs C e\\<^sub>2 V e\\<^sub>2' h\\<^sub>2 l\\<^sub>2)\n  have IH\\<^sub>1: \"\\<And>W. fv e\\<^sub>1 \\<subseteq> W \\<Longrightarrow> P \\<turnstile> \\<langle>e\\<^sub>1,(h\\<^sub>0,l\\<^sub>0|`W)\\<rangle> \\<Rightarrow> \\<langle>Throw a,(h\\<^sub>1,l\\<^sub>1|`W)\\<rangle>\"\n   and IH\\<^sub>2: \"\\<And>W. fv e\\<^sub>2 \\<subseteq> W \\<Longrightarrow> P \\<turnstile> \\<langle>e\\<^sub>2,(h\\<^sub>1,l\\<^sub>1(V\\<mapsto>Addr a)|`W)\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2',(h\\<^sub>2,l\\<^sub>2|`W)\\<rangle>\"\n   and lookup: \"h\\<^sub>1 a = Some(D, fs)\" and subtype: \"P \\<turnstile> D \\<preceq>\\<^sup>* C\" by fact+\n  have \"fv (try e\\<^sub>1 catch(C V) e\\<^sub>2) \\<subseteq> W\" by fact\n  hence fv\\<^sub>1: \"fv e\\<^sub>1 \\<subseteq> W\" and fv\\<^sub>2: \"fv e\\<^sub>2 \\<subseteq> insert V W\" by auto\n  have IH\\<^sub>2': \"P \\<turnstile> \\<langle>e\\<^sub>2,(h\\<^sub>1,(l\\<^sub>1|`W)(V \\<mapsto> Addr a))\\<rangle> \\<Rightarrow> \\<langle>e\\<^sub>2',(h\\<^sub>2,l\\<^sub>2|`insert V W)\\<rangle>\"\n    using IH\\<^sub>2[OF fv\\<^sub>2] fun_upd_restrict[of l\\<^sub>1 W] (*FIXME just l|W instead of l|(W-V) in simp rule??*) by simp\n  with eval_evals.TryCatch[OF IH\\<^sub>1[OF fv\\<^sub>1] _ subtype IH\\<^sub>2'] lookup\n  show ?case by fastforce\nnext\n  case TryThrow thus ?case by simp (blast intro: eval_evals.TryThrow)\nnext\n  case Nil thus ?case by (simp add: eval_evals.Nil)\nnext\n  case Cons thus ?case by simp (blast intro: eval_evals.Cons)\nnext\n  case ConsThrow thus ?case by simp (blast intro: eval_evals.ConsThrow)\nqed\n(*>*)\n\n\nlemma eval_notfree_unchanged:\n  \"P \\<turnstile> \\<langle>e,(h,l)\\<rangle> \\<Rightarrow> \\<langle>e',(h',l')\\<rangle> \\<Longrightarrow> (\\<And>V. V \\<notin> fv e \\<Longrightarrow> l' V = l V)\"\nand \"P \\<turnstile> \\<langle>es,(h,l)\\<rangle> [\\<Rightarrow>] \\<langle>es',(h',l')\\<rangle> \\<Longrightarrow> (\\<And>V. V \\<notin> fvs es \\<Longrightarrow> l' V = l V)\"\n(*<*)\nproof(induct rule:eval_evals_inducts)\n  case LAss thus ?case by(simp add:fun_upd_apply)\nnext\n  case Block thus ?case\n    by (simp only:fun_upd_apply split:if_splits) fastforce\nnext\n  case TryCatch thus ?case\n    by (simp only:fun_upd_apply split:if_splits) fastforce\nqed simp_all\n(*>*)\n\n\nlemma eval_closed_lcl_unchanged:\n  \"\\<lbrakk> P \\<turnstile> \\<langle>e,(h,l)\\<rangle> \\<Rightarrow> \\<langle>e',(h',l')\\<rangle>; fv e = {} \\<rbrakk> \\<Longrightarrow> l' = l\"\n(*<*)by(fastforce dest:eval_notfree_unchanged simp add:fun_eq_iff [where 'b=\"val option\"])(*>*)\n\n\nlemma list_eval_Throw: \nassumes eval_e: \"P \\<turnstile> \\<langle>throw x,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\nshows \"P \\<turnstile> \\<langle>map Val vs @ throw x # es',s\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs @ e' # es',s'\\<rangle>\"\n(*<*)\nproof -\n  from eval_e \n  obtain a where e': \"e' = Throw a\"\n    by (cases) (auto dest!: eval_final)\n  {\n    fix es\n    have \"\\<And>vs. es = map Val vs @ throw x # es' \n           \\<Longrightarrow> P \\<turnstile> \\<langle>es,s\\<rangle>[\\<Rightarrow>]\\<langle>map Val vs @ e' # es',s'\\<rangle>\"\n    proof (induct es type: list)\n      case Nil thus ?case by simp\n    next\n      case (Cons e es vs)\n      have e_es: \"e # es = map Val vs @ throw x # es'\" by fact\n      show \"P \\<turnstile> \\<langle>e # es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs @ e' # es',s'\\<rangle>\"\n      proof (cases vs)\n        case Nil\n        with e_es obtain \"e=throw x\" \"es=es'\" by simp\n        moreover from eval_e e'\n        have \"P \\<turnstile> \\<langle>throw x # es,s\\<rangle> [\\<Rightarrow>] \\<langle>Throw a # es,s'\\<rangle>\"\n          by (iprover intro: ConsThrow)\n        ultimately show ?thesis using Nil e' by simp\n      next\n        case (Cons v vs')\n        have vs: \"vs = v # vs'\" by fact\n        with e_es obtain \n          e: \"e=Val v\" and es:\"es= map Val vs' @ throw x # es'\"\n          by simp\n        from e \n        have \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<Rightarrow> \\<langle>Val v,s\\<rangle>\"\n          by (iprover intro: eval_evals.Val)\n        moreover from es \n        have \"P \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs' @ e' # es',s'\\<rangle>\"\n          by (rule Cons.hyps)\n        ultimately show \n          \"P \\<turnstile> \\<langle>e#es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs @ e' # es',s'\\<rangle>\"\n          using vs by (auto intro: eval_evals.Cons)\n      qed\n    qed\n  }\n  thus ?thesis\n    by simp\nqed\n(*>*)\n(* Hiermit kann man die ganze pair-Splitterei in den automatischen Taktiken\nabschalten. Wieder anschalten siehe nach dem Beweis. *)\n(*<*)\ndeclare split_paired_All [simp del] split_paired_Ex [simp del]\n(*>*)\n(* FIXME\n exercise 1: define a big step semantics where the body of a procedure can\n access not juts this and pns but all of the enclosing l. What exactly is fed\n in? What exactly is returned at the end? Notion: \"dynamic binding\"\n\n  excercise 2: the semantics of exercise 1 is closer to the small step\n  semantics. Reformulate equivalence proof by modifying call lemmas.\n*)\ntext \\<open>The key lemma:\\<close>\n\nlemma\nassumes wf: \"wwf_J_prog P\"\nshows extend_1_eval:\n  \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow> \\<langle>e'',s''\\<rangle> \\<Longrightarrow>  (\\<And>s' e'. P \\<turnstile> \\<langle>e'',s''\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>e,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>)\"\nand extend_1_evals:\n  \"P \\<turnstile> \\<langle>es,t\\<rangle> [\\<rightarrow>] \\<langle>es'',t''\\<rangle> \\<Longrightarrow> (\\<And>t' es'. P \\<turnstile> \\<langle>es'',t''\\<rangle> [\\<Rightarrow>] \\<langle>es',t'\\<rangle> \\<Longrightarrow> P \\<turnstile> \\<langle>es,t\\<rangle> [\\<Rightarrow>] \\<langle>es',t'\\<rangle>)\"\n(*<*)\nproof (induct rule: red_reds.inducts)\n  case (RedCall s a C fs M Ts T pns body D vs s' e')\n  have \"P \\<turnstile> \\<langle>addr a,s\\<rangle> \\<Rightarrow> \\<langle>addr a,s\\<rangle>\" by (rule eval_evals.intros)\n  moreover\n  have finals: \"finals(map Val vs)\" by simp\n  obtain h\\<^sub>2 l\\<^sub>2 where s: \"s = (h\\<^sub>2,l\\<^sub>2)\" by (cases s)\n  with finals have \"P \\<turnstile> \\<langle>map Val vs,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs,(h\\<^sub>2,l\\<^sub>2)\\<rangle>\"\n    by (iprover intro: eval_finalsId)\n  moreover from s have \"h\\<^sub>2 a = Some (C, fs)\" using RedCall by simp\n  moreover have \"method\": \"P \\<turnstile> C sees M: Ts\\<rightarrow>T = (pns, body) in D\" by fact\n  moreover have same_len\\<^sub>1: \"length Ts = length pns\"\n   and this_distinct: \"this \\<notin> set pns\" and fv: \"fv body \\<subseteq> {this} \\<union> set pns\"\n    using \"method\" wf by (fastforce dest!:sees_wf_mdecl simp:wf_mdecl_def)+\n  have same_len: \"length vs = length pns\" by fact\n  moreover\n  obtain l\\<^sub>2' where l\\<^sub>2': \"l\\<^sub>2' = [this\\<mapsto>Addr a,pns[\\<mapsto>]vs]\" by simp\n  moreover\n  obtain h\\<^sub>3 l\\<^sub>3 where s': \"s' = (h\\<^sub>3,l\\<^sub>3)\" by (cases s')\n  have eval_blocks:\n    \"P \\<turnstile> \\<langle>blocks (this # pns, Class D # Ts, Addr a # vs, body),s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\" by fact\n  hence id: \"l\\<^sub>3 = l\\<^sub>2\" using fv s s' same_len\\<^sub>1 same_len\n    by(fastforce elim: eval_closed_lcl_unchanged)\n  from eval_blocks obtain l\\<^sub>3' where \"P \\<turnstile> \\<langle>body,(h\\<^sub>2,l\\<^sub>2')\\<rangle> \\<Rightarrow> \\<langle>e',(h\\<^sub>3,l\\<^sub>3')\\<rangle>\"\n  proof -\n    from same_len\\<^sub>1 have \"length(this#pns) = length(Class D#Ts)\" by simp\n    moreover from same_len\\<^sub>1 same_len\n    have \"length (this#pns) = length (Addr a#vs)\" by simp\n    moreover from eval_blocks\n    have \"P \\<turnstile> \\<langle>blocks (this#pns,Class D#Ts,Addr a#vs,body),(h\\<^sub>2,l\\<^sub>2)\\<rangle>\n              \\<Rightarrow>\\<langle>e',(h\\<^sub>3,l\\<^sub>3)\\<rangle>\" using s s' by simp\n    ultimately obtain l''\n      where \"P \\<turnstile> \\<langle>body,(h\\<^sub>2,l\\<^sub>2(this # pns[\\<mapsto>]Addr a # vs))\\<rangle>\\<Rightarrow>\\<langle>e',(h\\<^sub>3, l'')\\<rangle>\"\n      by (blast dest:blocksEval)\n    from eval_restrict_lcl[OF wf this fv] this_distinct same_len\\<^sub>1 same_len\n    have \"P \\<turnstile> \\<langle>body,(h\\<^sub>2,[this # pns[\\<mapsto>]Addr a # vs])\\<rangle> \\<Rightarrow>\n               \\<langle>e',(h\\<^sub>3, l''|`(set(this#pns)))\\<rangle>\"\n      by(simp add:subset_insert_iff insert_Diff_if)\n    thus ?thesis by(fastforce intro!:that simp add: l\\<^sub>2')\n  qed\n  ultimately\n  have \"P \\<turnstile> \\<langle>(addr a)\\<bullet>M(map Val vs),s\\<rangle> \\<Rightarrow> \\<langle>e',(h\\<^sub>3,l\\<^sub>2)\\<rangle>\" by (rule Call)\n  with s' id show ?case by simp\nnext\n case RedNew\n  thus ?case\n     by (iprover elim: eval_cases intro: eval_evals.intros)\nnext\n  case RedNewFail\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case (CastRed e s e'' s'' C s' e')\n  thus ?case\n    by(cases s, cases s') (erule eval_cases, auto intro: eval_evals.intros)\nnext\n  case RedCastNull\n  thus ?case\n    by (iprover elim: eval_cases intro: eval_evals.intros)\nnext\n  case (RedCast s a D fs C s'' e'')\n  thus ?case\n    by (cases s) (auto elim: eval_cases intro: eval_evals.intros)\nnext\n  case (RedCastFail s a D fs C s'' e'')\n  thus ?case\n    by (cases s) (auto elim!: eval_cases intro: eval_evals.intros)\nnext\n  case (BinOpRed1 e s e' s' bop e\\<^sub>2 s'' e')\n  thus ?case\n    by (cases s'')(erule eval_cases,auto intro: eval_evals.intros)\nnext\n  case BinOpRed2\n  thus ?case\n    by (fastforce elim!: eval_cases intro: eval_evals.intros eval_finalId)\nnext\n  case RedBinOp\n  thus ?case\n    by (iprover elim: eval_cases intro: eval_evals.intros)\nnext\n  case (RedVar s V v s' e')\n  thus ?case\n    by (cases s)(fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case (LAssRed e s e' s' V s'')\n  thus ?case\n    by (cases s'')(erule eval_cases,auto intro: eval_evals.intros)\nnext\n  case RedLAss\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case (FAccRed e s e' s' F D s'')\n  thus ?case\n    by (cases s'')(erule eval_cases,auto intro: eval_evals.intros)\nnext\n  case (RedFAcc s a C fs F D v s' e')\n  thus ?case\n    by (cases s)(fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case RedFAccNull\n  thus ?case\n    by (fastforce elim!: eval_cases intro: eval_evals.intros)\nnext\n  case (FAssRed1 e s e' s'' F D e\\<^sub>2 s' e')\n  thus ?case\n    by (cases s')(erule eval_cases, auto intro: eval_evals.intros)\nnext\n  case (FAssRed2 e s e' s'' v F D s' e')\n  thus ?case\n    by (cases s)\n       (fastforce elim!: eval_cases intro: eval_evals.intros eval_finalId)\nnext\n  case RedFAss\n  thus ?case\n    by (fastforce elim!: eval_cases intro: eval_evals.intros)\nnext\n  case RedFAssNull\n  thus ?case\n    by (fastforce elim!: eval_cases intro: eval_evals.intros)\nnext\n  case CallObj\n  thus ?case\n    by (fastforce elim!: eval_cases intro: eval_evals.intros)\nnext\n  case CallParams\n  thus ?case\n    by (fastforce elim!: eval_cases intro: eval_evals.intros eval_finalId)\nnext\n  case RedCallNull\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros eval_finalsId)\nnext\n  case InitBlockRed\n  thus ?case\n    by (fastforce elim!: eval_cases intro: eval_evals.intros eval_finalId\n                 simp add: map_upd_triv fun_upd_same)\nnext\n  case (RedInitBlock V T v u s s' e')\n  have \"P \\<turnstile> \\<langle>Val u,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\" by fact\n  then obtain s': \"s'=s\" and e': \"e'=Val u\" by cases simp\n  obtain h l where s: \"s=(h,l)\" by (cases s)\n  have \"P \\<turnstile> \\<langle>{V:T :=Val v; Val u},(h,l)\\<rangle> \\<Rightarrow> \\<langle>Val u,(h, (l(V\\<mapsto>v))(V:=l V))\\<rangle>\"\n    by (fastforce intro!: eval_evals.intros)\n  thus \"P \\<turnstile> \\<langle>{V:T := Val v; Val u},s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n    using s s' e' by simp\nnext\n  case BlockRedNone\n  thus ?case\n    by (fastforce elim!: eval_cases intro: eval_evals.intros \n                 simp add: fun_upd_same fun_upd_idem)\nnext\n  case BlockRedSome\n  thus ?case\n    by (fastforce elim!: eval_cases intro: eval_evals.intros \n                 simp add:  fun_upd_same fun_upd_idem)\nnext\n case (RedBlock V T v s s' e') \n have \"P \\<turnstile> \\<langle>Val v,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\" by fact\n then obtain s': \"s'=s\" and e': \"e'=Val v\" \n    by cases simp\n  obtain h l where s: \"s=(h,l)\" by (cases s)\n have \"P \\<turnstile> \\<langle>Val v,(h,l(V:=None))\\<rangle> \\<Rightarrow> \\<langle>Val v,(h,l(V:=None))\\<rangle>\" \n   by (rule eval_evals.intros)\n hence \"P \\<turnstile> \\<langle>{V:T;Val v},(h,l)\\<rangle> \\<Rightarrow> \\<langle>Val v,(h,(l(V:=None))(V:=l V))\\<rangle>\"\n   by (rule eval_evals.Block)\n thus \"P \\<turnstile> \\<langle>{V:T; Val v},s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n    using s s' e'\n    by simp\nnext\n  case SeqRed\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case RedSeq\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case CondRed\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case RedCondT\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case RedCondF\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case RedWhile\n  thus ?case\n    by (auto simp add: unfold_while intro:eval_evals.intros elim:eval_cases)\nnext\n  case ThrowRed\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case RedThrowNull\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case (TryRed e s e' s' C V e\\<^sub>2 s'' e')\n  thus ?case\n    by (cases s, cases s'', auto elim!: eval_cases intro: eval_evals.intros)\nnext\n  case RedTry\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case RedTryCatch\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case (RedTryFail s a D fs C V e\\<^sub>2 s' e')\n  thus ?case\n    by (cases s)(auto elim!: eval_cases intro: eval_evals.intros)\nnext\n  case ListRed1\n  thus ?case\n    by (fastforce elim: evals_cases intro: eval_evals.intros)\nnext\n  case ListRed2\n  thus ?case\n    by (fastforce elim!: evals_cases eval_cases \n                 intro: eval_evals.intros eval_finalId)\nnext\n  case CastThrow\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case BinOpThrow1\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case BinOpThrow2\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case LAssThrow\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case FAccThrow\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case FAssThrow1\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case FAssThrow2\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case CallThrowObj\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case (CallThrowParams es vs e es' v M s s' e')\n  have \"P \\<turnstile> \\<langle>Val v,s\\<rangle> \\<Rightarrow> \\<langle>Val v,s\\<rangle>\" by (rule eval_evals.intros)\n  moreover\n  have es: \"es = map Val vs @ throw e # es'\" by fact\n  have eval_e: \"P \\<turnstile> \\<langle>throw e,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\" by fact\n  then obtain xa where e': \"e' = Throw xa\" by (cases) (auto dest!: eval_final)\n  with list_eval_Throw [OF eval_e] es\n  have \"P \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>map Val vs @ Throw xa # es',s'\\<rangle>\" by simp\n  ultimately have \"P \\<turnstile> \\<langle>Val v\\<bullet>M(es),s\\<rangle> \\<Rightarrow> \\<langle>Throw xa,s'\\<rangle>\"\n    by (rule eval_evals.CallParamsThrow)\n  thus ?case using e' by simp\nnext\n  case (InitBlockThrow V T v a s s' e')\n  have \"P \\<turnstile> \\<langle>Throw a,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\" by fact\n  then obtain s': \"s' = s\" and e': \"e' = Throw a\"\n    by cases (auto elim!:eval_cases)\n  obtain h l where s: \"s = (h,l)\" by (cases s)\n  have \"P \\<turnstile> \\<langle>{V:T :=Val v; Throw a},(h,l)\\<rangle> \\<Rightarrow> \\<langle>Throw a, (h, (l(V\\<mapsto>v))(V:=l V))\\<rangle>\"\n    by(fastforce intro:eval_evals.intros)\n  thus \"P \\<turnstile> \\<langle>{V:T := Val v; Throw a},s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\" using s s' e' by simp\nnext\n  case (BlockThrow V T a s s' e')\n  have \"P \\<turnstile> \\<langle>Throw a, s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\" by fact\n  then obtain s': \"s' = s\" and e': \"e' = Throw a\"\n    by cases (auto elim!:eval_cases)\n  obtain h l where s: \"s=(h,l)\" by (cases s)\n  have \"P \\<turnstile> \\<langle>Throw a, (h,l(V:=None))\\<rangle> \\<Rightarrow> \\<langle>Throw a, (h,l(V:=None))\\<rangle>\"\n    by (simp add:eval_evals.intros eval_finalId)\n  hence \"P\\<turnstile>\\<langle>{V:T;Throw a},(h,l)\\<rangle>\\<Rightarrow>\\<langle>Throw a, (h,(l(V:=None))(V:=l V))\\<rangle>\"\n    by (rule eval_evals.Block)\n  thus \"P \\<turnstile> \\<langle>{V:T; Throw a},s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\" using s s' e' by simp\nnext\n  case SeqThrow\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case CondThrow\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nnext\n  case ThrowThrow\n  thus ?case\n    by (fastforce elim: eval_cases intro: eval_evals.intros)\nqed\n(*>*)\n(*<*)\n(* ... und wieder anschalten: *)\ndeclare split_paired_All [simp] split_paired_Ex [simp]\n(*>*)\n\ntext \\<open>Its extension to \\<open>\\<rightarrow>*\\<close>:\\<close> \n\nlemma extend_eval:\nassumes wf: \"wwf_J_prog P\"\nand reds: \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e'',s''\\<rangle>\" and eval_rest:  \"P \\<turnstile> \\<langle>e'',s''\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\nshows \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n(*<*)\nusing reds eval_rest\nproof (induct rule: converse_rtrancl_induct2)\n  case refl then show ?case by simp\nnext\n  case step\n  show ?case using step extend_1_eval[OF wf step.hyps(1)] by simp\nqed\n(*>*)\n\n\nlemma extend_evals:\nassumes wf: \"wwf_J_prog P\"\nand reds: \"P \\<turnstile> \\<langle>es,s\\<rangle> [\\<rightarrow>]* \\<langle>es'',s''\\<rangle>\" and eval_rest:  \"P \\<turnstile> \\<langle>es'',s''\\<rangle> [\\<Rightarrow>] \\<langle>es',s'\\<rangle>\"\nshows \"P \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>es',s'\\<rangle>\"\n(*<*)\nusing reds eval_rest\nproof (induct rule: converse_rtrancl_induct2)\n  case refl then show ?case by simp\nnext\n  case step\n  show ?case using step extend_1_evals[OF wf step.hyps(1)] by simp\nqed\n(*>*)\n\ntext \\<open>Finally, small step semantics can be simulated by big step semantics:\n\\<close>\n\ntheorem\nassumes wf: \"wwf_J_prog P\"\nshows small_by_big: \"\\<lbrakk>P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle>; final e'\\<rbrakk> \\<Longrightarrow> P \\<turnstile> \\<langle>e,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\nand \"\\<lbrakk>P \\<turnstile> \\<langle>es,s\\<rangle> [\\<rightarrow>]* \\<langle>es',s'\\<rangle>; finals es'\\<rbrakk> \\<Longrightarrow> P \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>es',s'\\<rangle>\"\n(*<*)\nproof -\n  note wf \n  moreover assume \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle>\"\n  moreover assume \"final e'\"\n  then have \"P \\<turnstile> \\<langle>e',s'\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>\"\n    by (rule eval_finalId)\n  ultimately show \"P \\<turnstile> \\<langle>e,s\\<rangle>\\<Rightarrow>\\<langle>e',s'\\<rangle>\"\n    by (rule extend_eval)\nnext\n  note wf \n  moreover assume \"P \\<turnstile> \\<langle>es,s\\<rangle> [\\<rightarrow>]* \\<langle>es',s'\\<rangle>\"\n  moreover assume \"finals es'\"\n  then have \"P \\<turnstile> \\<langle>es',s'\\<rangle> [\\<Rightarrow>] \\<langle>es',s'\\<rangle>\"\n    by (rule eval_finalsId)\n  ultimately show \"P \\<turnstile> \\<langle>es,s\\<rangle> [\\<Rightarrow>] \\<langle>es',s'\\<rangle>\"\n    by (rule extend_evals)\nqed\n(*>*)\n\nsubsection \"Equivalence\"\n\ntext\\<open>And now, the crowning achievement:\\<close>\n\ncorollary big_iff_small:\n  \"wwf_J_prog P \\<Longrightarrow>\n  P \\<turnstile> \\<langle>e,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>  =  (P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle> \\<and> final e')\"\n(*<*)by(blast dest: big_by_small eval_final small_by_big)(*>*)\n\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Jinja/J/Equivalence.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.2693111250282043}}
{"text": "(*\n * Copyright 2014, General Dynamics C4 Systems\n *\n * SPDX-License-Identifier: GPL-2.0-only\n *)\n\ntheory Recycle_C\nimports Delete_C Retype_C\nbegin\n\ncontext kernel_m\nbegin\n\ndefinition\n  \"replicateHider \\<equiv> replicate\"\n\nlemma collapse_foldl_replicate:\n  \"replicate (length xs) v = xs \\<Longrightarrow>\n   foldl (@) [] (map (\\<lambda>_. xs) ys)\n        = replicateHider (length xs * length ys) v\"\n  apply (induct ys rule: rev_induct)\n   apply (simp add: replicateHider_def)\n  apply (simp add: replicateHider_def)\n  apply (subst add.commute, simp add: replicate_add)\n  done\n\nlemma coerce_memset_to_heap_update_user_data:\n  \"heap_update_list x (replicateHider 4096 0)\n      = heap_update (Ptr x :: user_data_C ptr)\n             (user_data_C (FCP (\\<lambda>_. 0)))\"\n  apply (intro ext, simp add: heap_update_def)\n  apply (rule_tac f=\"\\<lambda>xs. heap_update_list x xs a b\" for a b in arg_cong)\n  apply (simp add: to_bytes_def size_of_def typ_info_simps user_data_C_tag_def)\n  apply (simp add: ti_typ_pad_combine_empty_ti ti_typ_pad_combine_td align_of_def padup_def\n                   final_pad_def size_td_lt_ti_typ_pad_combine Let_def size_of_def)\n  apply (simp add: typ_info_simps\n                   user_context_C_tag_def thread_state_C_tag_def seL4_Fault_C_tag_def\n                   lookup_fault_C_tag_def update_ti_t_ptr_0s\n                   ti_typ_pad_combine_empty_ti ti_typ_pad_combine_td\n                   align_of_def padup_def\n                   final_pad_def size_td_lt_ti_typ_pad_combine Let_def size_of_def\n                   align_td_array' size_td_array)\n  apply (simp add: typ_info_array')\n  apply (subst access_ti_list_array)\n     apply simp\n    apply simp\n   apply (simp add: typ_info_word typ_info_ptr word_rsplit_0)\n   apply fastforce\n  apply (simp add: collapse_foldl_replicate word_bits_def)\n  done\n\nlemma clift_foldl_hrs_mem_update:\n  \"\\<lbrakk> \\<forall>x \\<in> set xs. hrs_htd s \\<Turnstile>\\<^sub>t f x;\n     \\<And>x s. hrs_htd s \\<Turnstile>\\<^sub>t f x \\<Longrightarrow> clift (hrs_mem_update (heap_update (f x) v) s)\n                                  = g (clift s :: ('a :: c_type) ptr \\<rightharpoonup> 'a) x \\<rbrakk>\n   \\<Longrightarrow>\n   clift (hrs_mem_update (\\<lambda>s. foldl (\\<lambda>s x. heap_update (f x) v s) s xs) s)\n       = foldl g (clift s :: 'a ptr \\<rightharpoonup> 'a) xs\"\n  using [[hypsubst_thin]]\n  apply (cases s, clarsimp)\n  apply (induct xs arbitrary: a b)\n   apply (simp add: hrs_mem_update_def)\n  apply (clarsimp simp add: hrs_mem_update_def split_def hrs_htd_def)\n  done\n\nlemma map_to_user_data_aligned:\n  \"\\<lbrakk> map_to_user_data (ksPSpace s) x = Some y; pspace_aligned' s \\<rbrakk>\n        \\<Longrightarrow> is_aligned x pageBits\"\n  apply (clarsimp simp: map_comp_eq projectKOs split: option.split_asm)\n  apply (drule(1) pspace_alignedD')\n  apply (simp add: objBits_simps)\n  done\n\nlemma help_force_intvl_range_conv:\n  \"\\<lbrakk> is_aligned (p::word32) n; v = 2 ^ n; n < word_bits \\<rbrakk>\n    \\<Longrightarrow> {p ..+ v} = {p .. p + 2 ^ n - 1}\"\n  by (simp add: intvl_range_conv word_bits_def)\n\nlemma cmap_relation_If_upd:\n  \"\\<lbrakk> cmap_relation f g ptrfun rel; rel v v'; ptrfun ` S = S'; inj ptrfun \\<rbrakk>\n   \\<Longrightarrow> cmap_relation (\\<lambda>x. if x \\<in> S then Some v else f x)\n                     (\\<lambda>y. if y \\<in> S' then Some v' else g y)\n        ptrfun rel\"\n  apply (simp add: cmap_relation_def dom_If_Some)\n  apply (rule context_conjI)\n   apply blast\n  apply clarsimp\n  apply (case_tac \"x \\<in> S\")\n   apply simp\n  apply clarsimp\n  apply (subst if_not_P)\n   apply (clarsimp simp: inj_eq)\n  apply (drule bspec, erule domI)\n  apply simp\n  done\n\nlemma length_replicateHider [simp]:\n  \"length (replicateHider n x) = n\"\n  by (simp add: replicateHider_def)\n\nlemma coerce_heap_update_to_heap_updates':\n  \"n = chunk * m \\<Longrightarrow>\n  heap_update_list x (replicateHider n 0)\n  = (\\<lambda>s. foldl (\\<lambda>s x. heap_update_list x (replicateHider chunk 0) s) s\n    (map (\\<lambda>n. x + (of_nat n * of_nat chunk)) [0 ..< m]))\"\n  using [[hypsubst_thin]]\n  apply clarsimp\n  apply (induct m arbitrary: x)\n   apply (rule ext, simp)\n   apply (simp add: replicateHider_def)\n  apply (rule ext)\n  apply (simp only: map_upt_unfold map_Suc_upt[symmetric])\n  apply (simp add: replicate_add[folded replicateHider_def]\n                   heap_update_list_concat_unfold\n                   o_def field_simps\n                   length_replicate[folded replicateHider_def])\n  done\n\nlemma h_t_valid_dom_s:\n  \"\\<lbrakk> h_t_valid htd c_guard p; x = ptr_val (p :: ('a :: mem_type) ptr);\n              n = size_of TYPE ('a) \\<rbrakk>\n    \\<Longrightarrow> {x ..+ n} \\<times> {SIndexVal, SIndexTyp 0} \\<subseteq> dom_s htd\"\n  apply (clarsimp simp: h_t_valid_def valid_footprint_def Let_def\n                        intvl_def)\n  apply (drule_tac x=k in spec, simp add: size_of_def)\n  apply (clarsimp simp: dom_s_def)\n  apply (drule_tac x=0 in map_leD, simp_all)\n  done\n\nlemma user_data_at_rf_sr_dom_s:\n  \"\\<lbrakk> typ_at' UserDataT x s; (s, s') \\<in> rf_sr \\<rbrakk>\n    \\<Longrightarrow> {x ..+ 2 ^ pageBits} \\<times> {SIndexVal, SIndexTyp 0}\n    \\<subseteq> dom_s (hrs_htd (t_hrs_' (globals s')))\"\n  apply (drule rf_sr_heap_user_data_relation)\n  apply (drule user_data_at_ko)\n  apply (erule_tac x=x in cmap_relationE1)\n   apply (simp only: heap_to_user_data_def Let_def ko_at_projectKO_opt)\n   apply simp\n  apply (drule h_t_valid_clift)\n  apply (simp add: h_t_valid_dom_s pageBits_def)\n  done\n\nlemma intvl_2_power_times_decomp:\n  \"\\<forall>y < 2 ^ (n - m). {x + y * 2 ^ m ..+ 2 ^ m} \\<times> S \\<subseteq> T\n    \\<Longrightarrow> m \\<le> n \\<Longrightarrow> n < word_bits\n    \\<Longrightarrow> {(x :: word32) ..+ 2 ^ n} \\<times> S \\<subseteq> T\"\n  apply (clarsimp simp: intvl_def)\n  apply (drule_tac x=\"of_nat k >> m\" in spec)\n  apply (drule mp)\n   apply (rule shiftr_less_t2n)\n   apply (rule word_of_nat_less)\n   apply (simp add: word_of_nat_less)\n  apply (erule subsetD)\n  apply (clarsimp simp: shiftl_t2n[simplified mult.commute mult.left_commute, symmetric]\n                        shiftr_shiftl1)\n  apply (rule_tac x=\"unat (of_nat k && mask m :: word32)\" in exI)\n  apply (simp add: field_simps word_plus_and_or_coroll2)\n  apply (simp add: word_bits_def unat_less_power and_mask_less')\n  done\n\nlemma flex_user_data_at_rf_sr_dom_s:\n  \"\\<lbrakk> (\\<forall>p<2 ^ (pageBitsForSize sz - pageBits).\n         typ_at' UserDataT (x + p * 2 ^ pageBits) s); (s, s') \\<in> rf_sr \\<rbrakk>\n    \\<Longrightarrow> {x ..+ 2 ^ pageBitsForSize sz} \\<times> {SIndexVal, SIndexTyp 0}\n    \\<subseteq> dom_s (hrs_htd (t_hrs_' (globals s')))\"\n  apply (rule_tac m=pageBits in intvl_2_power_times_decomp,\n         simp_all add: pbfs_atleast_pageBits pbfs_less_wb')\n  apply (erule allEI, clarsimp)\n  apply (drule(1) user_data_at_rf_sr_dom_s)\n  apply (erule subsetD)\n  apply simp\n  done\n\nlemma hrs_mem_update_fold_eq:\n  \"hrs_mem_update (fold f xs)\n    = fold (hrs_mem_update o f) xs\"\n  apply (rule sym, induct xs)\n   apply (simp add: hrs_mem_update_def)\n  apply (simp add: hrs_mem_update_def fun_eq_iff)\n  done\n\nlemma power_user_page_foldl_zero_ranges:\n  \" \\<forall>p<2 ^ (pageBitsForSize sz - pageBits).\n      hrs_htd hrs \\<Turnstile>\\<^sub>t (Ptr (ptr + of_nat p * 0x1000) :: user_data_C ptr)\n    \\<Longrightarrow> zero_ranges_are_zero rngs hrs\n    \\<Longrightarrow> zero_ranges_are_zero rngs\n        (hrs_mem_update (\\<lambda>s. foldl (\\<lambda>s x. heap_update (Ptr x) (user_data_C (arr x)) s) s\n            (map (\\<lambda>n. ptr + of_nat n * 0x1000) [0..<2 ^ (pageBitsForSize sz - pageBits)]))\n            hrs)\"\n  apply (simp add: foldl_conv_fold hrs_mem_update_fold_eq)\n  apply (rule conjunct1)\n  apply (rule fold_invariant[where P=\"\\<lambda>hrs'. zero_ranges_are_zero rngs hrs'\n          \\<and> hrs_htd hrs' = hrs_htd hrs\"\n      and xs=xs and Q=\"\\<lambda>x. x \\<in> set xs\" for xs], simp_all)\n  apply (subst zero_ranges_are_zero_update, simp_all)\n  apply clarsimp\n  done\n\ndeclare replicate_numeral [simp]\n\nlemma coerce_memset_to_heap_update_pte:\n  \"heap_update_list x (replicateHider 4 0)\n      = heap_update (Ptr x :: pte_C ptr)\n             (pte_C.pte_C (FCP (\\<lambda>x. 0)))\"\n  apply (intro ext, simp add: heap_update_def)\n  apply (rule_tac f=\"\\<lambda>xs. heap_update_list x xs a b\" for a b in arg_cong)\n  apply (simp add: to_bytes_def size_of_def typ_info_simps pte_C_tag_def)\n  apply (simp add: ti_typ_pad_combine_empty_ti ti_typ_pad_combine_td align_of_def padup_def\n                   final_pad_def size_td_lt_ti_typ_pad_combine Let_def size_of_def)\n  apply (simp add: typ_info_simps align_td_array' size_td_array)\n  apply (simp add: typ_info_array' typ_info_word word_rsplit_0)\n  apply (simp add: replicateHider_def word_bits_def)\n  done\n\nlemma objBits_eq_by_type:\n  fixes x :: \"'a :: pspace_storable\" and y :: 'a\n  shows \"objBits x = objBits y\"\n  apply (simp add: objBits_def)\n  apply (rule objBits_type)\n  apply (simp add: koTypeOf_injectKO)\n  done\n\nlemma mapM_x_store_memset_ccorres_assist:\n  fixes val :: \"'a :: pspace_storable\"\n  assumes nofail: \"\\<not> snd (mapM_x (\\<lambda>slot. setObject slot val) slots \\<sigma>)\"\n  assumes slots1: \"\\<forall>n < length slots. slots ! n = hd slots + (of_nat n << objBits val)\"\n  assumes slots2: \"n = length slots * (2 ^ objBits val)\"\n  assumes ptr: \"ptr = hd slots\"\n  assumes ko: \"\\<And>ko :: 'a. updateObject ko = updateObject_default ko\"\n              \"\\<And>ko :: 'a. (1 :: word32) < 2 ^ objBits ko\"\n  assumes restr: \"set slots \\<subseteq> S\"\n  assumes worker: \"\\<And>ptr s s' (ko :: 'a). \\<lbrakk> (s, s') \\<in> rf_sr; ko_at' ko ptr s; ptr \\<in> S \\<rbrakk>\n                                \\<Longrightarrow> (s \\<lparr> ksPSpace := ksPSpace s (ptr \\<mapsto> injectKO val)\\<rparr>,\n                                     globals_update (t_hrs_'_update (hrs_mem_update\n                                                    (heap_update_list ptr\n                                                    (replicateHider (2 ^ objBits val) (ucast c))))) s') \\<in> rf_sr\"\n  assumes rf_sr: \"(\\<sigma>, s) \\<in> rf_sr\"\n  shows\n  \"\\<exists>(rv, \\<sigma>') \\<in> fst (mapM_x (\\<lambda>slot. setObject slot val) slots \\<sigma>).\n      (\\<sigma>', globals_update (t_hrs_'_update (hrs_mem_update\n                          (heap_update_list ptr (replicateHider n c)))) s) \\<in> rf_sr\"\n  unfolding slots2 ptr using rf_sr slots1 nofail restr\nproof (induct slots arbitrary: s \\<sigma>)\n  case Nil\n  show ?case\n    using Nil.prems\n    apply (simp add: mapM_x_def sequence_x_def return_def replicateHider_def)\n    apply (simp add: rf_sr_def hrs_mem_update_def cstate_relation_def Let_def\n                     carch_state_relation_def cmachine_state_relation_def\n                     h_t_valid_clift_Some_iff)\n    done\nnext\n  case (Cons x xs tPre sPre)\n\n  note nofail_bind = Cons.prems(3)[unfolded mapM_x_Cons K_bind_def]\n\n  have obj_at: \"obj_at' (\\<lambda>x :: 'a. True) x sPre\"\n    using not_snd_bindI1[OF nofail_bind]\n    apply (subst(asm) setObject_obj_at_pre, simp_all add: ko snd_bind)\n    apply (clarsimp simp: stateAssert_def exec_get return_def)\n    apply (simp add: koTypeOf_injectKO typ_at_to_obj_at')\n    done\n\n  note in_setObject = setObject_eq[OF _ _ objBits_eq_by_type obj_at,\n                                   where ko=val, simplified ko, simplified]\n\n  note nofail_mapM = not_snd_bindI2[OF nofail_bind, OF in_setObject]\n\n  have hd_xs: \"xs \\<noteq> [] \\<Longrightarrow> hd xs = x + (2 ^ objBits val)\"\n    using Cons.prems(2)[rule_format, where n=1]\n    by (simp add: hd_conv_nth)\n\n  show ?case\n    using obj_at_ko_at'[OF obj_at] Cons.prems(4)\n    apply (clarsimp simp add: mapM_x_Cons bind_def split_def)\n    apply (rule rev_bexI, rule in_setObject)\n    apply (cut_tac Cons.hyps[OF _ _ nofail_mapM])\n       defer\n       apply (rule worker, rule Cons.prems, assumption+)\n      apply clarsimp\n      apply (case_tac \"xs = []\", simp_all)[1]\n      apply (insert Cons.prems, simp)[1]\n      apply (frule_tac x=\"Suc n\" in spec)\n      apply (simp add: hd_xs shiftl_t2n field_simps)\n     apply assumption\n    apply clarsimp\n    apply (rule rev_bexI, assumption)\n    apply (simp add: o_def)\n    apply (case_tac \"xs = []\")\n     apply (simp add: hrs_mem_update_def split_def replicateHider_def)\n    apply (subst(asm) heap_update_list_concat_fold_hrs_mem)\n     apply (simp add: hd_xs replicateHider_def)\n    apply (simp add: replicateHider_def replicate_add)\n    done\nqed\n\nlemma invalidateTLBByASID_ccorres:\n  \"ccorres dc xfdc (valid_pde_mappings' and (\\<lambda>_. asid \\<le> mask asid_bits))\n                   (UNIV \\<inter> {s. asid_' s = asid}) []\n       (invalidateTLBByASID asid) (Call invalidateTLBByASID_'proc)\"\n  apply (cinit lift: asid_')\n   apply (ctac(no_vcg) add: loadHWASID_ccorres)\n    apply csymbr\n    apply (simp add: case_option_If2 del: Collect_const)\n    apply (rule ccorres_if_cond_throws2[where Q=\\<top> and Q'=\\<top>])\n       apply (clarsimp simp: pde_stored_asid_def to_bool_def split: if_split)\n      apply (rule ccorres_return_void_C[unfolded dc_def])\n     apply (simp add: dc_def[symmetric])\n     apply csymbr\n     apply (ctac add: invalidateTranslationASID_ccorres)\n    apply vcg\n   apply (wp hoare_drop_imps)\n  apply (clarsimp simp: pde_stored_asid_def to_bool_def)\n  done\n\nend\n\nlemma option_to_0_user_mem':\n  \"option_to_0 \\<circ> user_mem' as =(\\<lambda>x. if x \\<in> {y. \\<not> pointerInUserData y as} then 0\n  else underlying_memory (ksMachineState as) x) \"\n  apply (rule ext)\n  apply (simp add:user_mem'_def option_to_0_def split:if_splits)\n  done\n\nlemma heap_to_user_data_in_user_mem'[simp]:\n  \"\\<lbrakk>pspace_aligned' as;pspace_distinct' as\\<rbrakk> \\<Longrightarrow> heap_to_user_data (ksPSpace as) (option_to_0 \\<circ> user_mem' as) =\n  heap_to_user_data (ksPSpace as)(underlying_memory (ksMachineState as))\"\n  apply (rule ext)+\n  apply (clarsimp simp: heap_to_user_data_def option_map_def\n                 split: option.splits)\n  apply (subst option_to_0_user_mem')\n  apply (subst map_option_byte_to_word_heap)\n   apply (clarsimp simp: projectKO_opt_user_data map_comp_def\n                  split: option.split_asm kernel_object.split_asm)\n   apply (frule(1) pspace_alignedD')\n   apply (frule(1) pspace_distinctD')\n   apply (subgoal_tac \"x + ucast off * 4 + xa  && ~~ mask pageBits = x\" )\n    apply (clarsimp simp: pointerInUserData_def typ_at'_def ko_wp_at'_def)\n   apply (simp add: ARM.pageBits_def)\n   apply (subst mask_lower_twice2[where n = 2 and m = 12,simplified,symmetric])\n   apply (subst is_aligned_add_helper[THEN conjunct2,where n1 = 2])\n     apply (erule aligned_add_aligned)\n      apply (simp add: is_aligned_mult_triv2[where n = 2,simplified])\n     apply  (clarsimp simp: objBits_simps ARM.pageBits_def)\n    apply simp\n   apply (rule is_aligned_add_helper[THEN conjunct2])\n    apply (simp add: ARM.pageBits_def objBits_simps)\n   apply (rule word_less_power_trans2[where k = 2,simplified])\n     apply (rule less_le_trans[OF ucast_less])\n      apply simp+\n  done\n\ncontext begin interpretation Arch . (*FIXME: arch_split*)\n\ncrunch pde_mappings'[wp]: invalidateTLBByASID \"valid_pde_mappings'\"\ncrunch ksArchState[wp]: invalidateTLBByASID \"\\<lambda>s. P (ksArchState s)\"\n\ncrunch gsMaxObjectSize[wp]: invalidateTLBByASID \"\\<lambda>s. P (gsMaxObjectSize s)\"\ncrunch gsMaxObjectSize[wp]: deleteASIDPool \"\\<lambda>s. P (gsMaxObjectSize s)\"\n  (wp: crunch_wps getObject_inv loadObject_default_inv\n   simp: crunch_simps)\nend\n\ncontext kernel_m begin\n\nlemma page_table_at_rf_sr_dom_s:\n  \"\\<lbrakk> page_table_at' x s; (s, s') \\<in> rf_sr \\<rbrakk>\n    \\<Longrightarrow> {x ..+ 2 ^ ptBits} \\<times> {SIndexVal, SIndexTyp 0}\n    \\<subseteq> dom_s (hrs_htd (t_hrs_' (globals s')))\"\n  apply (rule_tac m=2 in intvl_2_power_times_decomp,\n         simp_all add: shiftl_t2n field_simps ptBits_def pageBits_def\n                       word_bits_def pteBits_def)\n  apply (clarsimp simp: page_table_at'_def intvl_def)\n  apply (drule spec, drule(1) mp)\n  apply (simp add: typ_at_to_obj_at_arches)\n  apply (drule obj_at_ko_at', clarsimp)\n  apply (erule cmap_relationE1[OF rf_sr_cpte_relation])\n   apply (erule ko_at_projectKO_opt)\n  apply (drule h_t_valid_clift)\n  apply (drule h_t_valid_dom_s[OF _ refl refl])\n  apply (erule subsetD)\n  apply (auto simp add: intvl_def shiftl_t2n)[1]\n  done\n\nlemma clearMemory_PT_setObject_PTE_ccorres:\n  \"ccorres dc xfdc (page_table_at' ptr\n                and (\\<lambda>s. 2 ^ ptBits \\<le> gsMaxObjectSize s)\n                and (\\<lambda>_. is_aligned ptr ptBits \\<and> ptr \\<noteq> 0 \\<and> pstart = addrFromPPtr ptr))\n            (UNIV \\<inter> {s. ptr___ptr_to_unsigned_long_' s = Ptr ptr} \\<inter> {s. bits_' s = of_nat ptBits}) []\n       (do x \\<leftarrow> mapM_x (\\<lambda>a. setObject a ARM_H.InvalidPTE)\n                       [ptr , ptr + 2 ^ pteBits .e. ptr + 2 ^ ptBits - 1];\n           doMachineOp (cleanCacheRange_PoU ptr (ptr + 2 ^ ptBits - 1) pstart)\n        od)\n       (Call clearMemory_PT_'proc)\"\n  apply (rule ccorres_gen_asm)+\n  apply (cinit' lift: ptr___ptr_to_unsigned_long_' bits_')\n   apply (rule ccorres_Guard_Seq)\n   apply (rule ccorres_split_nothrow_novcg_dc)\n      apply (rule_tac P=\"page_table_at' ptr and (\\<lambda>s. 2 ^ ptBits \\<le> gsMaxObjectSize s)\"\n               in ccorres_from_vcg_nofail[where P'=UNIV])\n      apply (rule allI, rule conseqPre, vcg)\n      apply clarsimp\n      apply (subst ghost_assertion_size_logic[unfolded o_def])\n        apply (simp add: ptBits_def pageBits_def pteBits_def)\n       apply simp\n      apply (clarsimp simp: replicateHider_def[symmetric])\n      apply (frule is_aligned_no_overflow')\n      apply (intro conjI)\n          apply (clarsimp simp add: ptBits_def pageBits_def pteBits_def\n                          cong: StateSpace.state.fold_congs globals.fold_congs)\n         apply (erule is_aligned_weaken, simp add: ptBits_def pageBits_def)\n        apply (clarsimp simp: is_aligned_def ptBits_def pageBits_def pteBits_def)\n       apply (simp add: unat_of_nat32 order_less_le_trans[OF pt_bits_stuff(2)]\n                        word_bits_def page_table_at_rf_sr_dom_s)\n      apply (clarsimp simp add: ptBits_def pageBits_def pteBits_def\n                      cong: StateSpace.state.fold_congs globals.fold_congs)\n      apply (simp only: field_simps)\n      apply (simp add: upto_enum_step_def objBits_simps ptBits_def pageBits_def\n                       linorder_not_less[symmetric] archObjSize_def\n                       upto_enum_word split_def pteBits_def)\n      apply (erule mapM_x_store_memset_ccorres_assist\n                      [unfolded split_def, OF _ _ _ _ _ _ subset_refl],\n             simp_all add: shiftl_t2n hd_map objBits_simps archObjSize_def pteBits_def)[1]\n      apply (rule cmap_relationE1, erule rf_sr_cpte_relation, erule ko_at_projectKO_opt)\n      apply (subst coerce_memset_to_heap_update_pte)\n      apply (clarsimp simp: rf_sr_def Let_def cstate_relation_def typ_heap_simps)\n      apply (rule conjI)\n       apply (simp add: cpspace_relation_def typ_heap_simps update_pte_map_tos\n                        update_pte_map_to_ptes carray_map_relation_upd_triv)\n       apply (rule cmap_relation_updI, simp_all)[1]\n       apply (simp add: cpte_relation_def Let_def pte_lift_def\n                        pte_get_tag_def pte_tag_defs)\n       apply (simp add: carch_state_relation_def cmachine_state_relation_def\n                        typ_heap_simps update_pte_map_tos)\n      apply csymbr\n     apply (rule ccorres_Guard)\n     apply (ctac add: cleanCacheRange_PoU_ccorres)\n    apply (wp mapM_x_wp' setObject_ksPSpace_only updateObject_default_inv | simp)+\n   apply (clarsimp simp: guard_is_UNIV_def ptBits_def pageBits_def pteBits_def)\n  apply (clarsimp simp: ptBits_def pageBits_def pteBits_def)\n  apply (frule is_aligned_addrFromPPtr_n, simp)\n  apply (clarsimp simp: is_aligned_no_overflow'[where n=10, simplified] pageBits_def\n                        field_simps is_aligned_mask[symmetric] mask_AND_less_0)\n  done\n\nlemma modify_gets_helper:\n  \"do y \\<leftarrow> modify (ksPSpace_update (\\<lambda>_. ps)); ps' \\<leftarrow> gets ksPSpace; f ps' od\n      = do y \\<leftarrow> modify (ksPSpace_update (\\<lambda>_. ps)); f ps od\"\n  by (simp add: bind_def simpler_modify_def simpler_gets_def)\n\nlemma snd_lookupAround2_update:\n  \"ps y \\<noteq> None \\<Longrightarrow>\n    snd (lookupAround2 x (ps (y \\<mapsto> v'))) = snd (lookupAround2 x ps)\"\n  apply (clarsimp simp: lookupAround2_def lookupAround_def Let_def\n                        dom_fun_upd2\n              simp del: dom_fun_upd cong: if_cong option.case_cong)\n  apply (clarsimp split: option.split if_split  cong: if_cong)\n  apply auto\n  done\n\nlemma double_setEndpoint:\n  \"do y \\<leftarrow> setEndpoint epptr v1; setEndpoint epptr v2 od\n       = setEndpoint epptr v2\"\n  apply (simp add: setEndpoint_def setObject_def bind_assoc split_def\n                   modify_gets_helper)\n  apply (simp add: updateObject_default_def bind_assoc objBits_simps)\n  apply (rule ext)\n  apply (rule bind_apply_cong, rule refl)+\n  apply (clarsimp simp add: in_monad projectKOs magnitudeCheck_assert\n                            snd_lookupAround2_update)\n  apply (simp add: lookupAround2_known1 assert_opt_def projectKO_def projectKO_opt_ep\n                    alignCheck_assert)\n  apply (simp add: bind_def simpler_modify_def)\n  done\n\nlemma ccorres_inst_voodoo:\n  \"\\<forall>x. ccorres r xf (P x) (P' x) hs (h x) (c x)\n     \\<Longrightarrow> \\<forall>x. ccorres r xf (P x) (P' x) hs (h x) (c x)\"\n  by simp\n\nlemma cpspace_relation_ep_update_ep2:\n  \"\\<lbrakk> ko_at' (ep :: endpoint) epptr s;\n      cmap_relation (map_to_eps (ksPSpace s))\n           (cslift t) ep_Ptr (cendpoint_relation (cslift t));\n      cendpoint_relation (cslift t') ep' endpoint;\n      (cslift t' :: tcb_C ptr \\<rightharpoonup> tcb_C) = cslift t \\<rbrakk>\n     \\<Longrightarrow> cmap_relation (map_to_eps (ksPSpace s(epptr \\<mapsto> KOEndpoint ep')))\n          (cslift t(ep_Ptr epptr \\<mapsto> endpoint))\n          ep_Ptr (cendpoint_relation (cslift t'))\"\n  apply (rule cmap_relationE1, assumption, erule ko_at_projectKO_opt)\n  apply (rule_tac P=\"\\<lambda>a. cmap_relation a b c d\" for b c d in rsubst,\n                   erule cmap_relation_upd_relI, assumption+)\n    apply simp+\n  apply (rule ext, simp add: map_comp_def projectKO_opt_ep split: if_split)\n  done\n\nend\n\ncontext kernel_m begin\n\nlemma ccorres_subst_basic_helper:\n  \"\\<lbrakk> \\<And>s s'. \\<lbrakk> P s; s' \\<in> P'; (s, s') \\<in> rf_sr \\<rbrakk> \\<Longrightarrow> f s' = f' s';\n     \\<And>s s'. \\<lbrakk> P s; s' \\<in> P'; (s, s') \\<in> rf_sr \\<rbrakk> \\<Longrightarrow> (s, f' s') \\<in> rf_sr;\n     \\<And>s'. xf' (f' s') = v; \\<And>rv' t t'. ceqv \\<Gamma> xf' rv' t t' c (c' rv');\n        ccorres rrel xf Q Q' hs a (c' v) \\<rbrakk>\n       \\<Longrightarrow> ccorres rrel xf (P and Q) {s. s \\<in> P' \\<and> f' s \\<in> Q'} hs a (Basic f ;; c)\"\n  apply (rule ccorres_guard_imp2)\n   apply (rule ccorres_add_return)\n   apply (rule ccorres_split_nothrow[where xf'=xf' and r'=\"\\<lambda>rv rv'. rv' = v\"])\n       apply (rule ccorres_from_vcg[where P=P and P'=P'])\n       apply (rule allI, rule conseqPre, vcg)\n       apply (clarsimp simp: return_def)\n      apply assumption\n     apply simp\n    apply wp\n   apply vcg\n  apply clarsimp\n  done\n\nlemma ctcb_relation_blocking_ipc_badge:\n  \"\\<lbrakk> ctcb_relation tcb ctcb; isBlockedOnSend (tcbState tcb) \\<rbrakk> \\<Longrightarrow>\n      tsType_CL (thread_state_lift (tcbState_C ctcb)) = scast ThreadState_BlockedOnSend\"\n  \"\\<lbrakk> ctcb_relation tcb ctcb;\n        tsType_CL (thread_state_lift (tcbState_C ctcb)) = scast ThreadState_BlockedOnSend \\<rbrakk>\n      \\<Longrightarrow> blockingIPCBadge (tcbState tcb)\n             = blockingIPCBadge_CL (thread_state_lift (tcbState_C ctcb))\"\n   apply (clarsimp simp add: ctcb_relation_def)\n   apply (simp add: isBlockedOnSend_def split: Structures_H.thread_state.split_asm)\n   apply (clarsimp simp: cthread_state_relation_def)\n  apply (clarsimp simp add: ctcb_relation_def cthread_state_relation_def)\n  apply (cases \"tcbState tcb\", simp_all add: \"StrictC'_thread_state_defs\")\n  done\n\nlemma cendpoint_relation_q_cong:\n  \"\\<lbrakk> \\<And>t rf. (t, rf) \\<in> ep_q_refs_of' ep \\<Longrightarrow> hp (tcb_ptr_to_ctcb_ptr t) = hp' (tcb_ptr_to_ctcb_ptr t) \\<rbrakk>\n      \\<Longrightarrow> cendpoint_relation hp ep ep' = cendpoint_relation hp' ep ep'\"\n  apply (cases ep, simp_all add: cendpoint_relation_def Let_def)\n   apply (rule conj_cong [OF refl])\n   apply (rule tcb_queue_relation'_cong[OF refl refl refl])\n   apply clarsimp\n  apply (rule conj_cong [OF refl])\n  apply (rule tcb_queue_relation'_cong[OF refl refl refl])\n  apply clarsimp\n  done\n\nlemma cnotification_relation_q_cong:\n  \"\\<lbrakk>\\<And>t rf. (t, rf) \\<in> ntfn_q_refs_of' (ntfnObj ntfn) \\<Longrightarrow>  hp (tcb_ptr_to_ctcb_ptr t) = hp' (tcb_ptr_to_ctcb_ptr t)\\<rbrakk>\n      \\<Longrightarrow>  cnotification_relation hp ntfn ntfn' = cnotification_relation hp' ntfn ntfn'\"\n  apply (cases \"ntfnObj ntfn\", simp_all add: cnotification_relation_def Let_def)\n  apply (auto intro: iffD1[OF tcb_queue_relation'_cong[OF refl refl refl]])\n  done\n\nlemma tcbSchedEnqueue_ep_at:\n  \"\\<lbrace>obj_at' (P :: endpoint \\<Rightarrow> bool) ep\\<rbrace>\n      tcbSchedEnqueue t\n   \\<lbrace>\\<lambda>rv. obj_at' P ep\\<rbrace>\"\n  including no_pre\n  apply (simp add: tcbSchedEnqueue_def unless_def null_def)\n  apply (wp threadGet_wp, clarsimp, wp+)\n  apply (clarsimp split: if_split, wp)\n  done\n\nlemma ccorres_duplicate_guard:\n  \"ccorres r xf (P and P) Q hs f f' \\<Longrightarrow> ccorres r xf P Q hs f f'\"\n  by (erule ccorres_guard_imp, auto)\n\n\nlemma ep_q_refs'_no_NTFNBound[simp]:\n  \"(x, NTFNBound) \\<notin> ep_q_refs_of' ep\"\n  by (auto simp: ep_q_refs_of'_def split: endpoint.splits)\n\n\nlemma ntfn_q_refs'_no_NTFNBound[simp]:\n  \"(x, NTFNBound) \\<notin> ntfn_q_refs_of' ntfn\"\n  by (auto simp: ntfn_q_refs_of'_def split: ntfn.splits)\n\nlemma cancelBadgedSends_ccorres:\n  \"ccorres dc xfdc (invs' and ep_at' ptr)\n              (UNIV \\<inter> {s. epptr_' s = Ptr ptr} \\<inter> {s. badge_' s = bdg}) []\n       (cancelBadgedSends ptr bdg) (Call cancelBadgedSends_'proc)\"\n  apply (cinit lift: epptr_' badge_' simp: whileAnno_def)\n   apply (simp add: list_case_return\n              cong: list.case_cong Structures_H.endpoint.case_cong call_ignore_cong\n               del: Collect_const)\n   apply (rule ccorres_pre_getEndpoint)\n   apply (rule_tac R=\"ko_at' rv ptr\" and xf'=\"ret__unsigned_'\"\n               and val=\"case rv of RecvEP q \\<Rightarrow> scast EPState_Recv | IdleEP \\<Rightarrow> scast EPState_Idle\n                                | SendEP q \\<Rightarrow> scast EPState_Send\"\n               in ccorres_symb_exec_r_known_rv_UNIV[where R'=UNIV])\n      apply vcg\n      apply clarsimp\n      apply (erule cmap_relationE1 [OF cmap_relation_ep], erule ko_at_projectKO_opt)\n      apply (clarsimp simp: typ_heap_simps cendpoint_relation_def Let_def\n                     split: Structures_H.endpoint.split_asm)\n     apply ceqv\n    apply wpc\n      apply (simp add: dc_def[symmetric] ccorres_cond_iffs)\n      apply (rule ccorres_return_Skip)\n     apply (simp add: dc_def[symmetric] ccorres_cond_iffs)\n     apply (rule ccorres_return_Skip)\n    apply (rename_tac list)\n    apply (simp add: Collect_True Collect_False endpoint_state_defs\n                     ccorres_cond_iffs dc_def[symmetric]\n                del: Collect_const cong: call_ignore_cong)\n    apply (rule ccorres_rhs_assoc)+\n    apply (csymbr, csymbr)\n    apply (drule_tac s = rv in sym, simp only:)\n    apply (rule_tac P=\"ko_at' rv ptr and invs'\" in ccorres_cross_over_guard)\n    apply (rule ccorres_symb_exec_r)\n      apply (rule ccorres_rhs_assoc2, rule ccorres_rhs_assoc2)\n      apply (rule ccorres_split_nothrow[where r'=dc and xf'=xfdc, OF _ ceqv_refl])\n         apply (rule_tac P=\"ko_at' rv ptr\"\n                    in ccorres_from_vcg[where P'=UNIV])\n         apply (rule allI, rule conseqPre, vcg)\n         apply clarsimp\n         apply (rule cmap_relationE1[OF cmap_relation_ep], assumption)\n          apply (erule ko_at_projectKO_opt)\n         apply (clarsimp simp: typ_heap_simps setEndpoint_def)\n         apply (rule rev_bexI)\n          apply (rule setObject_eq; simp add: objBits_simps')[1]\n         apply (clarsimp simp: rf_sr_def cstate_relation_def\n                               Let_def carch_state_relation_def\n                               cmachine_state_relation_def\n                               )\n         apply (clarsimp simp: cpspace_relation_def\n                               update_ep_map_tos\n                               typ_heap_simps')\n         apply (erule(1) cpspace_relation_ep_update_ep2)\n          apply (simp add: cendpoint_relation_def endpoint_state_defs)\n         subgoal by simp\n        apply (rule ccorres_symb_exec_r)\n          apply (rule_tac xs=list in filterM_voodoo)\n          apply (rule_tac P=\"\\<lambda>xs s. (\\<forall>x \\<in> set xs \\<union> set list.\n                   st_tcb_at' (\\<lambda>st. isBlockedOnSend st \\<and> blockingObject st = ptr) x s)\n                              \\<and> distinct (xs @ list) \\<and> ko_at' IdleEP ptr s\n                              \\<and> (\\<forall>p. \\<forall>x \\<in> set (xs @ list). \\<forall>rf. (x, rf) \\<notin> {r \\<in> state_refs_of' s p. snd r \\<noteq> NTFNBound})\n                              \\<and> valid_queues s \\<and> pspace_aligned' s \\<and> pspace_distinct' s\n                              \\<and> sch_act_wf (ksSchedulerAction s) s \\<and> valid_objs' s\"\n                     and P'=\"\\<lambda>xs. {s. ep_queue_relation' (cslift s) (xs @ list)\n                                         (head_C (queue_' s)) (end_C (queue_' s))}\n                                \\<inter> {s. thread_' s = (case list of [] \\<Rightarrow> tcb_Ptr 0\n                                                       | x # xs \\<Rightarrow> tcb_ptr_to_ctcb_ptr x)}\"\n                      in ccorres_inst_voodoo)\n          apply (induct_tac list)\n           apply (rule allI)\n           apply (rule iffD1 [OF ccorres_expand_while_iff_Seq])\n           apply (rule ccorres_tmp_lift2 [OF _ _ Int_lower1])\n            apply ceqv\n           apply (simp add: ccorres_cond_iffs)\n           apply (rule ccorres_rhs_assoc2)\n           apply (rule ccorres_duplicate_guard, rule ccorres_split_nothrow_novcg_dc)\n              apply (rule ccorres_from_vcg, rule allI, rule conseqPre, vcg)\n              apply clarsimp\n              apply (drule obj_at_ko_at', clarsimp)\n              apply (rule cmap_relationE1[OF cmap_relation_ep], assumption)\n               apply (erule ko_at_projectKO_opt)\n              apply (clarsimp simp: typ_heap_simps tcb_queue_relation'_def)\n              apply (case_tac x)\n               apply (clarsimp simp: setEndpoint_def)\n               apply (rule rev_bexI, rule setObject_eq,\n                      (simp add: objBits_simps')+)\n               apply (clarsimp simp: rf_sr_def cstate_relation_def Let_def\n                 carch_state_relation_def\n                 cmachine_state_relation_def\n                 cpspace_relation_def typ_heap_simps'\n                 update_ep_map_tos)\n               apply (erule(1) cpspace_relation_ep_update_ep2)\n                subgoal by (simp add: cendpoint_relation_def Let_def)\n               subgoal by simp\n              apply (clarsimp simp: tcb_at_not_NULL[OF pred_tcb_at']\n                                    setEndpoint_def)\n              apply (rule rev_bexI, rule setObject_eq,\n                      (simp add: objBits_simps')+)\n              apply (clarsimp simp: rf_sr_def cstate_relation_def Let_def\n                                     carch_state_relation_def\n                                     cmachine_state_relation_def\n                                     cpspace_relation_def typ_heap_simps'\n                                     update_ep_map_tos)\n              apply (erule(1) cpspace_relation_ep_update_ep2)\n               apply (simp add: cendpoint_relation_def Let_def)\n               apply (subgoal_tac \"tcb_at' (last (a # list)) \\<sigma> \\<and> tcb_at' a \\<sigma>\")\n                apply (clarsimp simp: is_aligned_neg_mask_weaken[\n                                        OF is_aligned_tcb_ptr_to_ctcb_ptr[where P=\\<top>]])\n                subgoal by (simp add: tcb_queue_relation'_def EPState_Send_def mask_def)\n               subgoal by (auto split: if_split)\n              subgoal by simp\n             apply (ctac add: rescheduleRequired_ccorres[unfolded dc_def])\n            apply (rule hoare_pre, wp weak_sch_act_wf_lift_linear set_ep_valid_objs')\n            apply (clarsimp simp: weak_sch_act_wf_def sch_act_wf_def)\n            apply (fastforce simp: valid_ep'_def pred_tcb_at' split: list.splits)\n           apply (simp add: guard_is_UNIV_def)\n          apply (rule allI)\n          apply (rename_tac a lista x)\n          apply (rule iffD1 [OF ccorres_expand_while_iff_Seq])\n          apply (rule ccorres_init_tmp_lift2, ceqv)\n          apply (rule ccorres_guard_imp2)\n           apply (simp add: bind_assoc dc_def[symmetric]\n                       del: Collect_const)\n           apply (rule ccorres_cond_true)\n           apply (rule ccorres_rhs_assoc)+\n           apply (rule ccorres_pre_threadGet[where f=tcbState, folded getThreadState_def])\n           apply (rule ccorres_move_c_guard_tcb)\n           apply csymbr\n           apply (rule ccorres_abstract_cleanup)\n           apply csymbr\n           apply (rule ccorres_move_c_guard_tcb)\n           apply (rule_tac P=\\<top>\n                      and P'=\"{s. ep_queue_relation' (cslift s) (x @ a # lista)\n                                        (head_C (queue_' s)) (end_C (queue_' s))}\"\n                      and f'=\"\\<lambda>s. s \\<lparr> next___ptr_to_struct_tcb_C_' := (case lista of [] \\<Rightarrow> tcb_Ptr 0\n                                              | v # vs \\<Rightarrow> tcb_ptr_to_ctcb_ptr v) \\<rparr>\"\n                      and xf'=\"next___ptr_to_struct_tcb_C_'\"\n                           in ccorres_subst_basic_helper)\n               apply (thin_tac \"\\<forall>x. P x\" for P)\n               apply (rule myvars.fold_congs, (rule refl)+)\n               apply (clarsimp simp: tcb_queue_relation'_def use_tcb_queue_relation2\n                                     tcb_queue_relation2_concat)\n               apply (clarsimp simp: typ_heap_simps split: list.split)\n              subgoal by (simp add: rf_sr_def)\n             apply simp\n            apply ceqv\n           apply (rule_tac P=\"ret__unsigned=blockingIPCBadge rva\" in ccorres_gen_asm2)\n           apply (rule ccorres_if_bind, rule ccorres_if_lhs)\n            apply (simp add: bind_assoc dc_def[symmetric])\n            apply (rule ccorres_rhs_assoc)+\n            apply (ctac add: setThreadState_ccorres)\n              apply (ctac add: tcbSchedEnqueue_ccorres)\n                apply (rule_tac P=\"\\<lambda>s. \\<forall>t \\<in> set (x @ a # lista). tcb_at' t s\"\n                             in ccorres_cross_over_guard)\n                apply (rule ccorres_add_return, rule ccorres_split_nothrow[OF _ ceqv_refl])\n                   apply (rule_tac rrel=dc and xf=xfdc\n                               and P=\"\\<lambda>s. (\\<forall>t \\<in> set (x @ a # lista). tcb_at' t s)\n                                          \\<and> (\\<forall>p. \\<forall>t \\<in> set (x @ a # lista). \\<forall>rf. (t, rf) \\<notin> {r \\<in> state_refs_of' s p. snd r \\<noteq> NTFNBound})\n                                          \\<and> valid_queues s \\<and> distinct (x @ a # lista)\n                                          \\<and> pspace_aligned' s \\<and> pspace_distinct' s\"\n                              and P'=\"{s. ep_queue_relation' (cslift s) (x @ a # lista)\n                                           (head_C (queue_' s)) (end_C (queue_' s))}\"\n                               in ccorres_from_vcg)\n                   apply (thin_tac \"\\<forall>x. P x\" for P)\n                   apply (rule allI, rule conseqPre, vcg)\n                   apply (clarsimp simp: ball_Un)\n                   apply (rule exI, rule conjI)\n                    apply (rule exI, erule conjI)\n                    apply (intro conjI[rotated])\n                    apply (assumption)\n                    apply (fold_subgoals (prefix))[3]\n                    subgoal premises prems using prems by (fastforce intro: pred_tcb_at')+\n                   apply (clarsimp simp: return_def rf_sr_def cstate_relation_def Let_def)\n                   apply (rule conjI)\n                    apply (clarsimp simp: cpspace_relation_def)\n                    apply (rule conjI, erule ctcb_relation_null_queue_ptrs)\n                     apply (rule null_ep_queue)\n                     subgoal by (simp add: o_def)\n                    apply (rule conjI)\n                     apply (erule iffD1 [OF cmap_relation_cong, OF refl refl, rotated -1])\n                     apply clarsimp\n                     apply (rule cendpoint_relation_q_cong)\n                     apply (rule sym, erule restrict_map_eqI)\n                     apply (clarsimp simp: image_iff)\n                     apply (drule(2) map_to_ko_atI)\n                     apply (drule ko_at_state_refs_ofD')\n                     apply clarsimp\n                     apply (drule_tac x=p in spec)\n                     subgoal by fastforce\n                    apply (erule iffD1 [OF cmap_relation_cong, OF refl refl, rotated -1])\n                    apply clarsimp\n                    apply (drule(2) map_to_ko_atI, drule ko_at_state_refs_ofD')\n\n                    apply (rule cnotification_relation_q_cong)\n                    apply (rule sym, erule restrict_map_eqI)\n                    apply (clarsimp simp: image_iff)\n                    apply (drule_tac x=p in spec)\n                    subgoal by fastforce\n                   apply (rule conjI)\n                    apply (erule cready_queues_relation_not_queue_ptrs,\n                           auto dest: null_ep_schedD[unfolded o_def] simp: o_def)[1]\n                   apply (simp add: carch_state_relation_def\n                                    cmachine_state_relation_def\n                                    h_t_valid_clift_Some_iff)\n                  apply (rule ccorres_symb_exec_r2)\n                    apply (erule spec)\n                   apply vcg\n                  apply (vcg spec=modifies)\n                 apply wp\n                apply simp\n                apply vcg\n               apply (wp hoare_vcg_const_Ball_lift tcbSchedEnqueue_ep_at\n                         sch_act_wf_lift)\n              apply simp\n              apply (vcg exspec=tcbSchedEnqueue_cslift_spec)\n             apply (wp hoare_vcg_const_Ball_lift sts_st_tcb_at'_cases\n                       sts_sch_act sts_valid_queues setThreadState_oa_queued)\n            apply (vcg exspec=setThreadState_cslift_spec)\n           apply (simp add: ccorres_cond_iffs dc_def[symmetric])\n           apply (rule ccorres_symb_exec_r2)\n             apply (drule_tac x=\"x @ [a]\" in spec, simp add: dc_def[symmetric])\n            apply vcg\n           apply (vcg spec=modifies)\n          apply (thin_tac \"\\<forall>x. P x\" for P)\n          apply (clarsimp simp: pred_tcb_at' ball_Un)\n          apply (rule conjI)\n           apply (clarsimp split: if_split)\n           subgoal by (fastforce simp: valid_tcb_state'_def valid_objs'_maxDomain\n                                  valid_objs'_maxPriority dest: pred_tcb_at')\n          apply (clarsimp simp: tcb_at_not_NULL [OF pred_tcb_at'])\n          apply (clarsimp simp: typ_heap_simps st_tcb_at'_def)\n          apply (drule(1) obj_at_cslift_tcb)\n          apply (clarsimp simp: ctcb_relation_blocking_ipc_badge)\n          apply (rule conjI, simp add: \"StrictC'_thread_state_defs\" mask_def)\n          apply (rule conjI)\n           apply clarsimp\n           apply (frule rf_sr_cscheduler_relation)\n           apply (clarsimp simp: cscheduler_action_relation_def st_tcb_at'_def\n                          split: scheduler_action.split_asm)\n           apply (rename_tac word)\n           apply (frule_tac x=word in tcbSchedEnqueue_cslift_precond_discharge)\n              apply simp\n             subgoal by clarsimp\n            subgoal by clarsimp\n           subgoal by clarsimp\n          apply clarsimp\n          apply (rule conjI)\n           apply (frule(3) tcbSchedEnqueue_cslift_precond_discharge)\n           subgoal by clarsimp\n          apply clarsimp\n          apply (rule context_conjI)\n           apply (clarsimp simp: tcb_queue_relation'_def)\n           apply (erule iffD2[OF ep_queue_relation_shift[rule_format], rotated -1])\n           subgoal by simp\n          apply (rule_tac x=\"x @ a # lista\" in exI)\n          apply (clarsimp simp: ball_Un)\n          apply (rule conjI, fastforce)\n          subgoal by (clarsimp simp: remove1_append)\n         apply vcg\n        apply (rule conseqPre, vcg)\n        apply clarsimp\n       apply (wp hoare_vcg_const_Ball_lift)\n       apply (wp obj_at_setObject3[where 'a=endpoint, folded setEndpoint_def])\n         apply (simp add: objBits_simps')+\n       apply (wp set_ep_valid_objs')\n      apply vcg\n     apply vcg\n    apply (rule conseqPre, vcg)\n    apply clarsimp\n   apply (clarsimp simp: guard_is_UNIV_def)\n   apply (erule cmap_relationE1[OF cmap_relation_ep], erule ko_at_projectKO_opt)\n   apply (clarsimp simp: typ_heap_simps)\n   apply (clarsimp simp: cendpoint_relation_def Let_def)\n   subgoal by (clarsimp simp: tcb_queue_relation'_def neq_Nil_conv\n                  split: if_split_asm)\n  apply clarsimp\n  apply (frule ko_at_valid_objs', clarsimp)\n   apply (simp add: projectKOs)\n  apply (clarsimp simp: valid_obj'_def valid_ep'_def)\n  apply (frule sym_refs_ko_atD', clarsimp)\n  apply (clarsimp simp: st_tcb_at_refs_of_rev')\n  apply (rule conjI)\n   subgoal by (auto simp: isBlockedOnSend_def elim!: pred_tcb'_weakenE)\n  apply (rule conjI)\n   apply (clarsimp split: if_split)\n   apply (drule sym_refsD, clarsimp)\n   apply (drule(1) bspec)+\n   by (auto simp: obj_at'_def projectKOs state_refs_of'_def pred_tcb_at'_def tcb_bound_refs'_def\n              dest!: symreftype_inverse')\n\ndeclare Kernel_C.tcb_C_size [simp del]\n\nlemma cte_lift_ccte_relation:\n  \"cte_lift cte' = Some ctel'\n    \\<Longrightarrow> c_valid_cte cte'\n    \\<Longrightarrow> ccte_relation (cte_to_H ctel') cte'\"\n  by (simp add: ccte_relation_def)\n\nlemma updateFreeIndex_ccorres:\n  \"\\<forall>s. \\<Gamma> \\<turnstile> ({s} \\<inter> {s. \\<exists>cte cte'. cslift s (cte_Ptr srcSlot) = Some cte'\n               \\<and> cteCap cte = cap' \\<and> ccte_relation cte cte'})\n          c\n        {t. \\<exists>cap. cap_untyped_cap_lift cap = (cap_untyped_cap_lift\n                    (cte_C.cap_C (the (cslift s (cte_Ptr srcSlot)))))\n                        \\<lparr> cap_untyped_cap_CL.capFreeIndex_CL := ((of_nat idx') >> 4) \\<rparr>\n                \\<and> cap_get_tag cap = scast cap_untyped_cap\n                \\<and> t_hrs_' (globals t) = hrs_mem_update (heap_update (cte_Ptr srcSlot)\n                    (cte_C.cap_C_update (\\<lambda>_. cap) (the (cslift s (cte_Ptr srcSlot)))))\n                    (t_hrs_' (globals s))\n                \\<and> t may_only_modify_globals s in [t_hrs]\n        }\n    \\<Longrightarrow> ccorres dc xfdc\n           (valid_objs' and cte_wp_at' (\\<lambda>cte. isUntypedCap (cteCap cte)\n               \\<and> cap' = (cteCap cte)) srcSlot\n           and untyped_ranges_zero'\n           and (\\<lambda>_. is_aligned (of_nat idx' :: word32) 4 \\<and> idx' \\<le> 2 ^ (capBlockSize cap')))\n           {s. \\<not> capIsDevice cap'\n               \\<longrightarrow> region_actually_is_zero_bytes (capPtr cap' + of_nat idx') (capFreeIndex cap' - idx') s} hs\n           (updateFreeIndex srcSlot idx') c\"\n  (is \"_ \\<Longrightarrow> ccorres dc xfdc (valid_objs' and ?cte_wp_at' and _ and _) ?P' hs ?a c\")\n  apply (rule ccorres_gen_asm)\n  apply (simp add: updateFreeIndex_def getSlotCap_def updateCap_def)\n  apply (rule ccorres_guard_imp2)\n   apply (rule ccorres_split_noop_lhs, rule_tac cap'=cap' in updateTrackedFreeIndex_noop_ccorres)\n    apply (rule ccorres_pre_getCTE)+\n    apply (rename_tac cte cte2)\n    apply (rule_tac P = \"\\<lambda>s. ?cte_wp_at' s \\<and> cte2 = cte \\<and> cte_wp_at' ((=) cte) srcSlot s\"\n              and P'=\"{s. \\<exists>cte cte'. cslift s (cte_Ptr srcSlot) = Some cte'\n               \\<and> cteCap cte = cap' \\<and> ccte_relation cte cte'} \\<inter> ?P'\" in ccorres_from_vcg)\n    apply (rule allI, rule HoarePartial.conseq_exploit_pre, clarify)\n    apply (drule_tac x=s in spec, rule conseqPre, erule conseqPost)\n      defer\n      apply clarsimp\n     apply clarsimp\n    apply (simp add: cte_wp_at_ctes_of)\n    apply wp\n   apply (clarsimp simp: isCap_simps cte_wp_at_ctes_of)\n   apply (frule(1) rf_sr_ctes_of_clift)\n   apply clarsimp\n   apply (frule(1) cte_lift_ccte_relation)\n   apply (rule exI, intro conjI[rotated], assumption, simp_all)[1]\n  apply (clarsimp simp: cte_wp_at_ctes_of)\n  apply (erule(1) rf_sr_ctes_of_cliftE)\n  apply (frule(1) rf_sr_ctes_of_clift)\n  apply clarsimp\n  apply (subgoal_tac \"ccap_relation (capFreeIndex_update (\\<lambda>_. idx')\n        (cteCap (the (ctes_of \\<sigma> srcSlot)))) cap\")\n   apply (rule fst_setCTE [OF ctes_of_cte_at], assumption)\n   apply (erule bexI [rotated])\n   apply (clarsimp simp add: rf_sr_def cstate_relation_def Let_def\n      cvariable_array_map_const_add_map_option[where f=\"tcb_no_ctes_proj\"]\n      isCap_simps)\n   apply (simp add:cpspace_relation_def)\n   apply (clarsimp simp:typ_heap_simps' modify_map_def mex_def meq_def)\n   apply (rule conjI)\n    apply (rule cpspace_cte_relation_upd_capI, assumption+)\n   apply (rule conjI)\n    apply (rule setCTE_tcb_case, assumption+)\n   apply (case_tac s', clarsimp)\n   subgoal by (simp add: carch_state_relation_def cmachine_state_relation_def\n                   typ_heap_simps')\n\n  apply (clarsimp simp: isCap_simps)\n  apply (drule(1) cte_lift_ccte_relation,\n    drule ccte_relation_ccap_relation)\n  apply (simp add: cte_to_H_def)\n  apply (frule cap_get_tag_isCap_unfolded_H_cap)\n  apply (clarsimp simp: ccap_relation_def cap_lift_untyped_cap\n                        cap_to_H_simps cap_untyped_cap_lift_def\n                        is_aligned_shiftr_shiftl\n                 dest!: ccte_relation_ccap_relation)\n  apply (rule unat_of_nat_eq unat_of_nat_eq[symmetric],\n    erule order_le_less_trans,\n    rule power_strict_increasing, simp_all)\n  apply (rule unat_less_helper, rule order_le_less_trans[OF word_and_le1], simp add: mask_def)\n  done\n\nend\n\nlemma ccap_relation_isDeviceCap2:\n \"\\<lbrakk>ccap_relation cp cap; isUntypedCap cp\n  \\<rbrakk> \\<Longrightarrow> (capIsDevice_CL (cap_untyped_cap_lift cap) = 0) = (\\<not> (capIsDevice cp))\"\n  apply (frule cap_get_tag_UntypedCap)\n  apply (simp add:cap_get_tag_isCap to_bool_def)\n  done\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/proof/crefine/ARM/Recycle_C.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6150878414043814, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.26929991098626754}}
{"text": "section \\<open>Preprocessor and Code-Generator User Interface\\<close>\ntheory LLVM_Codegen_Preproc\nimports \n  \"../kernel/LLVM_Codegen\"\n  \"Monadify\"\n  \"../../lib/Definition_Utils\" \nkeywords \"export_llvm\" \"llvm_deps\" :: thy_decl\nbegin\n\n  subsection \\<open>Fixed-Point Unfolding Setup\\<close>\n\n  lemma llc_while_mono[partial_function_mono]:      \n    assumes \"\\<And>x. M_mono (\\<lambda>f. b f x)\"\n    assumes \"\\<And>x. M_mono (\\<lambda>f. c f x)\"\n    shows \"M_mono (\\<lambda>D. llc_while (b D) (c D) \\<sigma>)\"\n    using assms unfolding llc_while_def by pf_mono_prover\n      \n  declaration \\<open>fn _ => Definition_Utils.declare_extraction_group @{binding LLVM} #> snd\\<close>\n  declaration \\<open>fn _ => Definition_Utils.declare_extraction_group @{binding LLVM_while} #> snd\\<close>\n    \n  declaration {* fn _ =>\n    Definition_Utils.add_extraction (@{extraction_group LLVM_while},\\<^here>) {\n      pattern = Logic.varify_global @{term \"llc_while b body\"},\n      gen_thm = @{thm gen_code_thm_llc_while},\n      gen_tac = K (K no_tac)\n    }\n  *}\n\n  declaration {*fn _ =>\n    Definition_Utils.add_extraction (@{extraction_group LLVM},\\<^here>) {\n      pattern = Logic.varify_global @{term \"REC (B::('a \\<Rightarrow> 'b llM) \\<Rightarrow> 'a \\<Rightarrow> 'b llM)\"},\n      gen_thm = @{thm REC_unfold},\n      gen_tac = Partial_Function.mono_tac\n    }\n  *}\n\nsubsection \\<open>Preprocessor\\<close>  \n  text \\<open>\n    The actual code generator expects a set of monomorphic, well-shaped equations.\n    The preprocessor processes user specified equations, monomorphizes them and \n    brings them into the right shape.\n  \\<close>\n  \n  named_theorems llvm_code \\<open>Isabelle-LLVM code theorems\\<close>\n  named_theorems llvm_inline\n\n  lemma llvm_inline_bind_laws[llvm_inline]:\n    \"bind m return = m\"\n    \"bind (bind m (\\<lambda>x. f x)) g = bind m (\\<lambda>x. bind (f x) g)\"\n    by auto\n  \n  lemma unit_meta_eq: \"x \\<equiv> ()\" by simp\n  \n  lemma pull_lambda_case: \"(case x of (a,b) \\<Rightarrow> \\<lambda>y. t a b y) = (\\<lambda>y. case x of (a,b) \\<Rightarrow> t a b y)\"\n    apply (rule ext) apply (cases x) by auto\n\n  ML \\<open> structure LLC_Preprocessor = \n    struct\n      open LLC_Lib\n          \n      structure Monadify = Gen_Monadify (\n      \n        fun mk_return x = @{mk_term \"return ?x ::_ llM\"}\n        fun mk_bind m f = @{mk_term \"bind ?m ?f ::_ llM\"}\n      \n        fun dest_return @{mpat \"return ?x ::_ llM\"} = SOME x | dest_return _ = NONE\n        fun dest_bind @{mpat \"bind ?m ?f ::_ llM\"} = SOME (m,f) | dest_bind _ = NONE\n        \n        fun dest_monadT (Type (@{type_name M},[T,@{typ unit},@{typ llvm_memory},@{typ err}])) = SOME T | dest_monadT _ = NONE\n\n        val strip_op = K strip_comb\n        \n        val bind_return_thm = @{lemma \"bind m return = m\" by simp}\n        val return_bind_thm = @{lemma \"bind (return x) f = f x\" by simp}\n        val bind_bind_thm = @{lemma \"bind (bind m (\\<lambda>x. f x)) g = bind m (\\<lambda>x. bind (f x) g)\" by simp}\n        \n      )\n      \n      (********* Normalization of code theorems *)\n      \n  \n      fun cthm_inline ctxt thm = let\n        val inline_thms = Named_Theorems.get ctxt @{named_theorems llvm_inline}\n        val ctxt = put_simpset HOL_ss ctxt addsimps inline_thms\n      in\n        Conv.fconv_rule (rhs_conv (Simplifier.rewrite ctxt)) thm\n      end\n    \n      val cthm_monadify = Conv.fconv_rule o (rhs_conv o Monadify.monadify_conv)\n            \n      val inline_iteration_limit =\n        Config.int (Config.declare (\"inline_iteration_limit\", \\<^here>) (fn _ => Config.Int ~1));\n      \n      \n      fun monadify_inline_cthm ctxt thm = let\n        fun rpt 0 thm' = raise THM (\"inline_iteration_limit exceeded\",~1,[thm,thm'])\n          | rpt n thm = let\n          val thm' = thm |> cthm_monadify ctxt |> cthm_inline ctxt\n        in\n          if Thm.eq_thm_prop (thm,thm') then thm \n          else rpt (n-1) thm'\n        end\n        \n        val it_limit = Config.get ctxt inline_iteration_limit\n      in\n        thm \n        |> cthm_inline ctxt\n        |> rpt it_limit\n      end  \n      \n      (*\n        Bring code theorem into parseable format. To be applied after inlining, \n          immediately before parsing.\n        \n        Applies eta-expansion, return-expansion, and converts \\<equiv> to =.\n        Finally, it will replace unit-binds by () constants and anonymous bind.\n        \n        May fail on non-well-formed theorems.\n      *)\n      fun cthm_format ctxt thm = let\n        fun normalize_bind1 t = let\n          val (f,args) = strip_comb t\n          val _ = check_valid_head f\n  \n          val args_is_M = fastype_of f |> binder_types |> map (is_llM o body_type)\n                  \n          val _ = length args_is_M = length args orelse raise TYPE (\"cthm_format: All arguments must be explicit\", [fastype_of f], [t])\n          \n          val args = map2 (fn isM => isM?(normalize o expand_eta_all)) args_is_M args\n          \n        in\n          list_comb (f, args)\n        end  \n          \n        and normalize @{mpat \"bind ?m ?f\"} = let\n            val m = normalize_bind1 m\n            val f = (*ensure_abs f*) expand_eta_all f |> normalize\n          in @{mk_term \"bind ?m ?f\"} end\n        | normalize (Abs (x,T,t)) = Abs (x,T,normalize t)\n        | normalize (t as @{mpat \"return _\"}) = t\n        | normalize t = let val t = normalize_bind1 t in @{mk_term \"bind ?t (\\<lambda>x. return x)\"} end\n      \n        fun normalize_eq @{mpat \"Trueprop (?a = ?b)\"} = let val b = normalize b in @{mk_term \"Trueprop (?a = ?b)\"} end\n          | normalize_eq @{mpat \"?a \\<equiv> ?b\"} = let val b = normalize b in @{mk_term \"?a \\<equiv> ?b\"} end\n          | normalize_eq t = raise TERM (\"format_code_thm: normalize_eq\", [t])\n      \n        fun norm_tac ctxt = ALLGOALS (simp_tac (put_simpset HOL_ss ctxt addsimps @{thms bind_laws}))\n    \n        fun cthm_norm_lambda ctxt thm = let\n          val thm = Local_Defs.unfold ctxt @{thms pull_lambda_case} thm\n        \n          fun r thm = case Thm.concl_of thm of\n            @{mpat \"Trueprop (_ = (\\<lambda>_. _))\"} => r (thm RS @{thm fun_cong})\n          | @{mpat \"_ \\<equiv> (\\<lambda>_. _)\"} => r (thm RS @{thm meta_fun_cong})\n          | _ => thm\n          \n        in\n          r thm\n        end\n        \n      in\n        thm \n        |> (simplify (put_simpset HOL_ss ctxt addsimps @{thms Monad.bind_laws atomize_eq}))\n        |> (Conv.fconv_rule (Refine_Util.f_tac_conv ctxt normalize_eq (norm_tac ctxt)))\n        |> cthm_norm_lambda ctxt\n        |> (Conv.fconv_rule (Conv.top_sweep_conv (K (Conv.rewr_conv @{thm unit_meta_eq})) ctxt))\n      end\n      \n      (********* Gathering of code equations *)\n      (* TODO: Use net *)\n\n      \n      fun dep_prep_code_thm thm = let\n        val c = head_of_eqn_thm thm\n        val _ = check_valid_head c\n      in\n        (c,thm)\n      end\n      \n      fun dep_try_instantiate_code_thm c (l,thm) = let\n        val thy = Thm.theory_of_thm thm\n      in\n        case SOME (Pattern.match thy (l,c) (Vartab.empty,Vartab.empty)) handle Pattern.MATCH => NONE of\n          NONE => NONE\n        | SOME m => SOME (instantiate_uc m thm)\n      end\n      \n      fun dep_find_code_thm pthms c = \n        case get_first (dep_try_instantiate_code_thm c) pthms of\n          SOME eqn => eqn\n        | NONE => raise TERM (\"No code equation\",[c])\n      \n      val cmd_name_prefix = Long_Name.qualify (Long_Name.qualifier @{const_name ll_add}) \"ll_\"\n      val comb_name_prefix = Long_Name.qualify (Long_Name.qualifier @{const_name llc_while}) \"llc_\"\n          \n      fun dep_is_ll_comb_name name =\n               name = @{const_name bind}\n        orelse name = @{const_name return}\n        orelse String.isPrefix cmd_name_prefix name\n        orelse String.isPrefix comb_name_prefix name\n        \n        \n      fun dep_is_call_const t = case try dest_head t of\n        NONE => false\n      | SOME (name,T) => \n                  not (dep_is_ll_comb_name name) (* Not an internal name *)\n          andalso is_llM (body_type T)           (* Yields a monadic result *)\n          andalso not (exists (exists_subtype is_llM) (binder_types T)) (* No monadic parameters *)\n        \n      fun calls_of_cthm thm = Term.fold_aterms \n        (fn t => dep_is_call_const t?cons t) \n        (rhs_of_eqn (Thm.prop_of thm))\n        []\n      \n      fun default_extractions ctxt = \n          Definition_Utils.get_extraction_group ctxt @{extraction_group LLVM}\n        |> (not (Config.get ctxt llc_compile_while) ? \n              append (Definition_Utils.get_extraction_group ctxt @{extraction_group LLVM_while}))  \n      \n      fun gather_code_thms roots lthy = let\n        val thy = Proof_Context.theory_of lthy\n        val pthms = Named_Theorems.get lthy @{named_theorems llvm_code}\n          |> map dep_prep_code_thm\n          |> Refine_Util.subsume_sort fst thy\n      \n        fun process_root c (ctab, lthy) = let\n          val _ = check_valid_head c\n          val basename = name_of_head c |> Long_Name.base_name\n        in\n          case Termtab.lookup ctab c of\n            SOME _ => (ctab, lthy)\n          | NONE => let\n              val _ = assert_monomorphic_const c\n              (* Get code theorem and inline it *)\n              val teqn = dep_find_code_thm pthms c |> monadify_inline_cthm lthy\n\n              (* Extract recursion equations *)\n              val exs = default_extractions lthy\n              \n              val ((teqn,add_eqns,_),lthy) = Definition_Utils.extract_recursion_eqs exs basename teqn lthy\n              val teqns = teqn::add_eqns\n              \n              (* Inline and format again *)\n              val teqns = map (monadify_inline_cthm lthy #> cthm_format lthy) teqns\n\n              (* Update table *)\n              val ctab = fold Termtab.update_new (map dep_prep_code_thm teqns) ctab\n                            \n              (* Find calls *)\n              val calls = map calls_of_cthm teqns |> flat\n              \n              (* Recurse *)\n              val (ctab,lthy) = fold process_root calls (ctab,lthy)\n            in\n              (ctab, lthy)\n            end\n        end \n\n        val (ctab,lthy) = fold process_root roots (Termtab.empty,lthy)\n        val thms = Termtab.dest ctab |> map snd\n        \n      in\n        (thms,lthy)\n      end\n        \n    end\n  \\<close>\n  \nsubsection \\<open>Code Generator Driver\\<close>  \n  text \\<open>\n    The driver combines preeprocessing and code generation, \n    and defines the user interface of the code generator, namely the commands\n    @{command export_llvm} and @{command llvm_deps}.\n  \\<close>\n  \n  ML \\<open> structure LLC_Driver \n    = struct\n    \n      val cfg_llvm_debug = Attrib.setup_config_bool @{binding llvm_debug} (K false)\n    \n      fun pretty_cthms ctxt cthms = let \n        val ctxt = Config.put Syntax_Trans.eta_contract_raw (Config.Bool false) ctxt      \n      in Pretty.big_list \"Code Theorems\" (map (Thm.pretty_thm ctxt) cthms) end\n\n      fun pretty_ftab_entry ctxt (t,n) = Pretty.block [\n        Syntax.pretty_term ctxt t, Pretty.brk 1, Pretty.str \":: \", Syntax.pretty_typ ctxt (fastype_of t), \n        Pretty.brk 1,Pretty.str \"\\<rightarrow>\",Pretty.brk 1, Pretty.str n\n      ]\n          \n      fun pretty_ftab ctxt ftab = Pretty.big_list \"Symbol table:\" \n        (map (pretty_ftab_entry ctxt) (Termtab.dest ftab))\n                \n      fun consts_to_llvm cns lthy = let\n        val dbg = Config.get lthy cfg_llvm_debug\n        \n        fun trace s = if dbg then Pretty.string_of (s ()) |> tracing else ()\n                                                                                                      \n        val _ = trace (fn () => Pretty.str \"Gathering code theorems\")\n        val (cthms,lthy) = LLC_Preprocessor.gather_code_thms (map fst cns) lthy\n        val _ = trace (fn () => pretty_cthms lthy cthms)\n        \n        val _ = trace (fn () => Pretty.str \"Computing symbol table\")\n        val fixes = map_filter (fn (_,NONE) => NONE | (cn,SOME name) => SOME (cn,name)) cns\n        val ftab = LLC_Compiler.compute_fun_names fixes cthms\n        val _ = trace (fn () => pretty_ftab lthy ftab)\n        \n                  \n        val _ = trace (fn () => Pretty.str \"Translating code theorems to IL\")\n        val tysxeqns = LLC_Compiler.parse_cthms ftab cthms lthy\n        val _ = trace (fn () => LLC_Intermediate.pretty_llc tysxeqns)\n        \n        val _ = trace (fn () => Pretty.str \"Writing LLVM\")\n        val res = LLC_Backend.compile_to_llvm lthy tysxeqns\n      in\n        ((cthms,res), lthy)\n      end\n      \n      local\n        val using_master_directory =\n          File.full_path o Resources.master_directory o Proof_Context.theory_of;\n          \n        fun prepare_path ctxt (s,pos) = let\n          val _ = Position.report pos Markup.language_path;\n          val path = Path.explode s;\n          val _ = Position.report pos (Markup.path (Path.smart_implode path));\n          val path = using_master_directory ctxt path\n        in path end\n      \n        fun write_out NONE s = writeln s\n          | write_out (SOME path) s = File.write path s\n      in\n        fun export_llvm cns path lthy = let\n          val lthy = Config.put Syntax_Trans.eta_contract_raw (Config.Bool false) lthy\n          val ((cthms,llvm_code),lthy) = consts_to_llvm cns lthy\n          val _ = write_out path llvm_code      \n        in\n          (cthms,lthy)\n        end\n        \n        val export_llvm_cmd = (Args.mode \"debug\" -- Args.mode \"no_while\" -- Parse_Spec.opt_thm_name \":\" -- (Scan.repeat1 (Parse.term -- Scan.option (@{keyword \"is\"} |-- Parse.name )) -- Scan.option ((@{keyword \"file\"} |-- Parse.position Parse.path))) \n            >> (fn (((dbg,nowhile),bnd),(cns,path)) => fn lthy => let \n            \n              local\n                val lthy = (dbg?Config.put cfg_llvm_debug true) lthy\n                val lthy = (nowhile?Config.put LLC_Lib.llc_compile_while false) lthy\n              in\n                val cns = map (apfst (Syntax.read_term lthy)) cns\n                val path = Option.map (prepare_path lthy) path \n                \n                val (cthms,lthy) = export_llvm cns path lthy\n              end\n              \n              val (_,lthy) = Local_Theory.note (bnd,cthms) lthy \n              \n            in lthy end))\n        \n        val llvm_deps_cmd = Parse_Spec.opt_thm_name \":\" -- Scan.repeat1 Parse.term\n          >> (fn (bnd,cns) => fn lthy => let\n              val cns = map (Syntax.read_term lthy) cns\n              val (cthms,lthy) = LLC_Preprocessor.gather_code_thms cns lthy\n              val (_,lthy) = Local_Theory.note (bnd,cthms) lthy \n              \n              val _ = pretty_cthms lthy cthms |> Pretty.string_of |> writeln\n          \n             in lthy end \n          )\n        \n            \n      end\n\n      val _ = Outer_Syntax.local_theory @{command_keyword export_llvm} \"generate LLVM code for constants\" export_llvm_cmd\n      val _ = Outer_Syntax.local_theory @{command_keyword llvm_deps} \"Print LLVM code theorems for constants\" llvm_deps_cmd\n    end\n  \\<close>                                                      \n  \n  subsection \\<open>Setup for Product Type\\<close>\n  text \\<open>We prepare a setup to compile product types to anonymous 2-element structures\\<close>\n  \n  lemma ll_prod_is_pair[ll_is_pair_type_thms]: \n    \"ll_is_pair_type True TYPE('a::llvm_rep \\<times>'b::llvm_rep) TYPE('a) TYPE('b)\"\n    by (simp add: ll_is_pair_type_def)\n  \n  definition [llvm_inline]: \"prod_insert_fst \\<equiv> ll_insert_fst :: ('a::llvm_rep \\<times> 'b::llvm_rep) \\<Rightarrow> 'a \\<Rightarrow> ('a\\<times>'b) llM\"\n  definition [llvm_inline]: \"prod_insert_snd \\<equiv> ll_insert_snd :: ('a::llvm_rep \\<times> 'b::llvm_rep) \\<Rightarrow> 'b \\<Rightarrow> ('a\\<times>'b) llM\"\n  definition [llvm_inline]: \"prod_extract_fst \\<equiv> ll_extract_fst :: ('a::llvm_rep \\<times> 'b::llvm_rep) \\<Rightarrow> 'a llM\"\n  definition [llvm_inline]: \"prod_extract_snd \\<equiv> ll_extract_snd :: ('a::llvm_rep \\<times> 'b::llvm_rep) \\<Rightarrow> 'b llM\"\n  definition [llvm_inline]: \"prod_gep_fst \\<equiv> ll_gep_fst :: ('a::llvm_rep \\<times> 'b::llvm_rep) ptr \\<Rightarrow> 'a ptr llM\"\n  definition [llvm_inline]: \"prod_gep_snd \\<equiv> ll_gep_snd :: ('a::llvm_rep \\<times> 'b::llvm_rep) ptr \\<Rightarrow> 'b ptr llM\"\n\n  \n  lemma prod_ops_simp:\n    \"prod_insert_fst = (\\<lambda>(_,b) a. return (a,b))\"\n    \"prod_insert_snd = (\\<lambda>(a,_) b. return (a,b))\"\n    \"prod_extract_fst = (\\<lambda>(a,b). return a)\"\n    \"prod_extract_snd = (\\<lambda>(a,b). return b)\"\n    unfolding \n      prod_insert_fst_def ll_insert_fst_def \n      prod_insert_snd_def ll_insert_snd_def\n      prod_extract_fst_def ll_extract_fst_def \n      prod_extract_snd_def ll_extract_snd_def       \n    apply (all \\<open>intro ext\\<close>  )\n    apply (auto \n      simp: checked_split_pair_def to_val_prod_def from_val_prod_def checked_from_val_def\n      split: prod.splits\n      )\n    done\n  \n    \n  subsection \\<open>Ad-Hoc Regression Tests\\<close>\n  \nexperiment begin  \n  \n  definition exp :: \"64 word \\<Rightarrow> 64 word llM\" where [llvm_code]: \"exp i \\<equiv> doM {\n    s \\<leftarrow> prod_insert_fst init 1;\n    s \\<leftarrow> prod_insert_snd s i;\n    s \\<leftarrow> llc_while\n      (\\<lambda>s. doM {\n        i \\<leftarrow> prod_extract_snd s;\n        ll_icmp_ne i 0\n      })\n      (\\<lambda>s. doM {\n        c \\<leftarrow> prod_extract_fst s;\n        i \\<leftarrow> prod_extract_snd s;\n        \n        c \\<leftarrow> ll_mul c 2;\n        i \\<leftarrow> ll_sub i 1;\n        \n        s \\<leftarrow> prod_insert_fst init c;\n        s \\<leftarrow> prod_insert_snd s i;\n        \n        return s\n      })\n      s;\n  \n    prod_extract_fst s\n  }\"\n  \n  \n  definition streq :: \"8 word ptr \\<Rightarrow> 8 word ptr \\<Rightarrow> 1 word llM\" where [llvm_code]: \"streq s\\<^sub>1 s\\<^sub>2 = doM {\n      x \\<leftarrow> ll_load s\\<^sub>1;\n      ll_load s\\<^sub>2 \\<bind> ll_icmp_eq x\n    }\"\n  \n  export_llvm streq  \n  \n  definition [llvm_code]: \"test2 (n::32 word) \\<equiv> doM {\n    n \\<leftarrow> ll_add n 42;\n    p \\<leftarrow> ll_malloc TYPE(16 word) n;\n    p \\<leftarrow> ll_ofs_ptr p (5::32 word);\n    ll_store 42 p;\n    r \\<leftarrow> ll_load p; \n    return r  \n  }\"\n  \n  definition [llvm_code]: \"add_add (a::_ word) \\<equiv> doM {\n    x \\<leftarrow> ll_add a a;\n    x \\<leftarrow> ll_add x x;\n    return x\n  }\"\n\n  definition [llvm_code]: \"add_add_driver (a::32 word) (b::64 word) \\<equiv> doM {\n    a \\<leftarrow> add_add a;\n    b \\<leftarrow> add_add b;\n    a \\<leftarrow> ll_zext a TYPE(64 word);\n    b \\<leftarrow> ll_add a b;\n    return b\n  }\"\n  \n  export_llvm (debug) add_add_driver\n  \n  definition [llvm_code]: \"main (argc::32 word) (argv::8 word ptr ptr) \\<equiv> doM {\n    r \\<leftarrow> test2 argc;\n    r \\<leftarrow> ll_zext r TYPE(32 word);\n    return r\n  }\" \n\n  definition [llvm_code]: \"main_exp (argc::32 word) (argv::8 word ptr ptr) \\<equiv> doM {\n    argc \\<leftarrow> ll_zext argc TYPE(64 word);\n    r \\<leftarrow> exp argc;\n    r \\<leftarrow> ll_trunc r TYPE(32 word);\n    return r\n  }\" \n\n  \ndefinition [llvm_code]: \"testx (a::64 word) \\<equiv> llc_while (\\<lambda>a. ll_icmp_ult 0 a) (\\<lambda>a. ll_sub a 1) a\"\n    \ndeclare [[eta_contract = false]]\nexport_llvm (debug) testx\nexport_llvm (debug) exp_thms1: exp  \nexport_llvm (debug) (no_while) exp_thms2: exp  \nexport_llvm (debug) (no_while) exp_thms3: exp  \n\nthm exp_thms1\nthm exp_thms2\nthm exp_thms3\n\n\nexport_llvm (debug) foobar: main_exp is main\nexport_llvm (debug) main is main\n\n\n\ndefinition [llvm_code]: \n  \"test_if_names (n::32 word) \\<equiv> doM {\n    tmp \\<leftarrow> ll_icmp_eq n 0;\n    a \\<leftarrow> llc_if tmp (return null) (doM {\n                                     x \\<leftarrow> ll_malloc TYPE(8 word) n;\n                                     return x\n                                   });\n    p \\<leftarrow> ll_ofs_ptr a (1::32 word);\n    ll_store 0x2A p;\n    ll_free a;\n    return ()\n  }\"\n \nexport_llvm test_if_names\n\ndefinition fib :: \"64 word \\<Rightarrow> 64 word llM\" \n  where [llvm_code]: \"fib n \\<equiv> REC (\\<lambda>fib n. doM { \n    t\\<leftarrow>ll_icmp_ule n 1; \n    llc_if t \n      (return n) \n      (doM { \n        n\\<^sub>1 \\<leftarrow> ll_sub n 1; \n        a\\<leftarrow>fib n\\<^sub>1; \n        n\\<^sub>2 \\<leftarrow> ll_sub n 2; \n        b\\<leftarrow>fib n\\<^sub>2; \n        c\\<leftarrow>ll_add a b; \n        return c })} ) n\"\n\nexport_llvm fib is fib\n\n\nend\n\nend\n", "meta": {"author": "lammich", "repo": "isabelle_llvm", "sha": "6be37a9c3cae74a1134dbef2979e312abb5f7f42", "save_path": "github-repos/isabelle/lammich-isabelle_llvm", "path": "github-repos/isabelle/lammich-isabelle_llvm/isabelle_llvm-6be37a9c3cae74a1134dbef2979e312abb5f7f42/thys-2018/basic/preproc/LLVM_Codegen_Preproc.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.26920284381460396}}
{"text": "(*******************************************************************************\n\n  Project: Development of Security Protocols by Refinement\n\n  Module:  Key_establish/m1_nssk.thy (Isabelle/HOL 2016-1)\n  ID:      $Id: m1_nssk.thy 133856 2017-03-20 18:05:54Z csprenge $\n  Author:  Christoph Sprenger, ETH Zurich <sprenger@inf.ethz.ch>\n  \n  Key distribution protocols\n  First refinement: abstract server-based key transport protocol with \n  initiator and responder roles.\n\n  Copyright (c) 2009-2016 Christoph Sprenger\n  Licence: LGPL\n\n*******************************************************************************)\n\nsection \\<open>Abstract Needham-Schroeder Shared Key (L1)\\<close>\n\ntheory m1_nssk imports m1_keydist_iirn \nbegin\n\ntext \\<open>We add augment the basic abstract key distribution model such that \nthe server reads and stores the initiator's nonce. We show three refinements, \nnamley that this model refines\n\\begin{enumerate}\n\\item the basic key distribution model \\<open>m1a\\<close>, and\n\\item the injective agreement model \\<open>a0i\\<close>, instantiated such that \nthe initiator agrees with the server on the session key and its nonce.\n\\item the non-injective agreement model \\<open>a0n\\<close>, instantiated such that \nthe responder agrees with the server on the session key.\n\\end{enumerate}\n\\<close>\n\nconsts\n  nb :: \"nat\"       \\<comment> \\<open>responder nonce constant\\<close>\n  END :: \"atom\"     \\<comment> \\<open>run end marker for responder\\<close>\n\n\n(******************************************************************************)\nsubsection \\<open>State\\<close>\n(******************************************************************************)\n\ntext \\<open>We extend the basic key distribution by adding nonces. The frames, \nthe state, and the observations remain the same as in the previous model, but \nwe will use the @{typ \"nat list\"}'s to store nonces.\\<close>\n\nrecord m1_state = m1r_state + \n  leak :: \"(key \\<times> fresh_t \\<times> fresh_t) set\"   \\<comment> \\<open>keys leaked plus session context\\<close>\n\ntype_synonym m1_obs = \"m1_state\"\n\ntype_synonym 'x m1_pred = \"'x m1_state_scheme set\"\ntype_synonym 'x m1_trans = \"('x m1_state_scheme \\<times> 'x m1_state_scheme) set\"\n\n\n(******************************************************************************)\nsubsection \\<open>Events\\<close>\n(******************************************************************************)\n\ndefinition     \\<comment> \\<open>by @{term \"A\"}, refines @{term \"m1a_step1\"}\\<close>\n  m1_step1 :: \"[rid_t, agent, agent, nonce] \\<Rightarrow> 'x m1r_trans\"\nwhere\n  \"m1_step1 Ra A B Na \\<equiv> m1a_step1 Ra A B Na\"\n\ndefinition    \\<comment> \\<open>by @{term \"B\"}, refines @{text \"m1a_step2\"}\\<close>\n  m1_step2 :: \"[rid_t, agent, agent] \\<Rightarrow> 'x m1r_trans\"\nwhere\n  \"m1_step2 Rb A B \\<equiv> m1a_step2 Rb A B\"\n\ndefinition    \\<comment> \\<open>by @{term \"Server\"}, refines @{term m1a_step3}\\<close>\n  m1_step3 :: \"[rid_t, agent, agent, nonce, key] \\<Rightarrow> 'x m1r_trans\"\nwhere\n  \"m1_step3 Rs A B Na Kab \\<equiv> m1a_step3 Rs A B Kab Na []\"\n\ndefinition     \\<comment> \\<open>by @{text \"A\"}, refines @{term m1a_step4}\\<close>\n  m1_step4 :: \"[rid_t, agent, agent, nonce, key] \\<Rightarrow> 'x m1_trans\"\nwhere\n  \"m1_step4 Ra A B Na Kab \\<equiv> {(s, s').\n     \\<comment> \\<open>guards:\\<close>\n     runs s Ra = Some (Init, [A, B], []) \\<and>\n     Na = Ra$na \\<and>                                              \\<comment> \\<open>fix parameter\\<close>\n     (Kab \\<notin> Domain (leak s) \\<longrightarrow> (Kab, A) \\<in> azC (runs s)) \\<and>     \\<comment> \\<open>authorization guard\\<close>\n\n     \\<comment> \\<open>new guard for agreement with server on \\<open>(Kab, B, Na)\\<close>,\\<close>\n     \\<comment> \\<open>injectiveness by including \\<open>Na\\<close>\\<close>\n     (A \\<notin> bad \\<longrightarrow> (\\<exists>Rs. Kab = sesK (Rs$sk) \\<and>\n        runs s Rs = Some (Serv, [A, B], [aNon Na]))) \\<and>\n\n     \\<comment> \\<open>actions:\\<close>\n     s' = s\\<lparr> runs := (runs s)(Ra \\<mapsto> (Init, [A, B], [aKey Kab])) \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by @{term \"B\"}, refines @{term m1a_step5}\\<close>\n  m1_step5 :: \"[rid_t, agent, agent, nonce, key] \\<Rightarrow> 'x m1_trans\"\nwhere\n  \"m1_step5 Rb A B Nb Kab \\<equiv> {(s, s'). \n     \\<comment> \\<open>new guards:\\<close>\n     Nb = Rb$nb \\<and>                                              \\<comment> \\<open>generate Nb\\<close>\n\n     \\<comment> \\<open>prev guards:\\<close>\n     runs s Rb = Some (Resp, [A, B], []) \\<and> \n     (Kab \\<notin> Domain (leak s) \\<longrightarrow> (Kab, B) \\<in> azC (runs s)) \\<and>    \\<comment> \\<open>authorization guard\\<close>\n\n     \\<comment> \\<open>guard for showing agreement with server on \\<open>(Kab, A)\\<close>,\\<close>\n     \\<comment> \\<open>this agreement is non-injective\\<close>\n     (B \\<notin> bad \\<longrightarrow> (\\<exists>Rs Na. Kab = sesK (Rs$sk) \\<and>\n        runs s Rs = Some (Serv, [A, B], [aNon Na]))) \\<and>\n\n     \\<comment> \\<open>actions:\\<close>\n     s' = s\\<lparr> runs := (runs s)(Rb \\<mapsto> (Resp, [A, B], [aKey Kab])) \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by @{term \"A\"}, refines @{term skip}\\<close>\n  m1_step6 :: \"[rid_t, agent, agent, nonce, nonce, key] \\<Rightarrow> 'x m1_trans\"\nwhere\n  \"m1_step6 Ra A B Na Nb Kab \\<equiv> {(s, s'). \n    runs s Ra = Some (Init, [A, B], [aKey Kab]) \\<and>      \\<comment> \\<open>key recv'd before\\<close>\n    Na = Ra$na \\<and>\n\n    \\<comment> \\<open>guard for showing agreement with \\<open>B\\<close> on \\<open>Kab\\<close> and \\<open>Nb\\<close>\\<close>\n    (A \\<notin> bad \\<longrightarrow> B \\<notin> bad \\<longrightarrow> \n    (\\<forall>Nb'. (Kab, Na, Nb') \\<notin> leak s) \\<longrightarrow>    \\<comment> \\<open>NEW: weaker condition\\<close>\n       (\\<exists>Rb nl. Nb = Rb$nb \\<and> runs s Rb = Some (Resp, [A, B], aKey Kab # nl))) \\<and> \n\n    \\<comment> \\<open>actions:\\<close>\n    s' = s\\<lparr>\n      runs := (runs s)(Ra \\<mapsto> (Init, [A, B], [aKey Kab, aNon Nb])) \n    \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by @{term \"B\"}, refines @{term skip}\\<close>\n  m1_step7 :: \"[rid_t, agent, agent, nonce, key] \\<Rightarrow> 'x m1_trans\"\nwhere\n  \"m1_step7 Rb A B Nb Kab \\<equiv> {(s, s').\n    runs s Rb = Some (Resp, [A, B], [aKey Kab]) \\<and>      \\<comment> \\<open>key recv'd before\\<close>\n    Nb = Rb$nb \\<and>\n\n    \\<comment> \\<open>guard for showing agreement with \\<open>A\\<close> on \\<open>Kab\\<close> and \\<open>Nb\\<close>\\<close>\n    (A \\<notin> bad \\<longrightarrow> B \\<notin> bad \\<longrightarrow> Kab \\<notin> Domain (leak s) \\<longrightarrow> \n      \\<comment> \\<open>\\<open>(\\<forall>Na'. (Kab, Na', Nb) \\<notin> leak s) \\<longrightarrow>\\<close> too strong, does not work\\<close>\n      (\\<exists>Ra. runs s Ra = Some (Init, [A, B], [aKey Kab, aNon Nb]))) \\<and> \n     \n    \\<comment> \\<open>actions: (redundant) update local state marks successful termination\\<close>\n    s' = s\\<lparr>\n      runs := (runs s)(Rb \\<mapsto> (Resp, [A, B], [aKey Kab, END]))\n    \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by attacker, refines @{term s0g_leak}\\<close>\n  m1_leak :: \"[rid_t, rid_t, rid_t, agent, agent] \\<Rightarrow> 'x m1_trans\"\nwhere\n  \"m1_leak Rs Ra Rb A B \\<equiv> {(s, s1).           \n    \\<comment> \\<open>guards:\\<close>\n    runs s Rs = Some (Serv, [A, B], [aNon (Ra$na)]) \\<and>\n    runs s Ra = Some (Init, [A, B], [aKey (sesK (Rs$sk)), aNon (Rb$nb)]) \\<and>  \n    runs s Rb = Some (Resp, [A, B], [aKey (sesK (Rs$sk)), END]) \\<and>  \n\n    \\<comment> \\<open>actions:\\<close>\n    s1 = s\\<lparr> leak := insert (sesK (Rs$sk), Ra$na, Rb$nb) (leak s) \\<rparr>\n  }\"\n\n\n(******************************************************************************)\nsubsection \\<open>Specification\\<close>\n(******************************************************************************)\n\nabbreviation\n  m1_init :: \"m1_state set\"\nwhere\n  \"m1_init \\<equiv> { \\<lparr>\n     runs = Map.empty,\n     leak = corrKey \\<times> {undefined} \\<times> {undefined}      \\<comment> \\<open>initial leakage\\<close>\n  \\<rparr> }\" \n\ndefinition \n  m1_trans :: \"'x m1_trans\" where\n  \"m1_trans \\<equiv> (\\<Union>A B Ra Rb Rs Na Nb Kab.\n     m1_step1 Ra A B Na \\<union>\n     m1_step2 Rb A B \\<union>\n     m1_step3 Rs A B Na Kab \\<union>\n     m1_step4 Ra A B Na Kab \\<union>\n     m1_step5 Rb A B Nb Kab \\<union>\n     m1_step6 Ra A B Na Nb Kab \\<union>\n     m1_step7 Rb A B Nb Kab \\<union>\n     m1_leak Rs Ra Rb A B \\<union>\n     Id\n  )\"\n\ndefinition \n  m1 :: \"(m1_state, m1_obs) spec\" where\n  \"m1 \\<equiv> \\<lparr>\n    init = m1_init,\n    trans = m1_trans,\n    obs = id\n  \\<rparr>\" \n\nlemmas m1_loc_defs = \n  m1_def m1_trans_def\n  m1_step1_def m1_step2_def m1_step3_def m1_step4_def m1_step5_def \n  m1_step6_def m1_step7_def m1_leak_def\n\nlemmas m1_defs = m1_loc_defs m1a_defs \n\nlemma m1_obs_id [simp]: \"obs m1 = id\"\nby (simp add: m1_def)\n\n\n(******************************************************************************)\nsubsection \\<open>Invariants\\<close>\n(******************************************************************************)\n\nsubsubsection \\<open>inv0: Finite domain\\<close>\n(*inv**************************************************************************)\n\ntext \\<open>There are only finitely many runs. This is needed to establish the \nresponder/initiator agreements. This is already defined in the previous model,\nwe just need to show that it still holds in the current model.\\<close>\n\nabbreviation\n  m1_inv0_fin :: \"'x m1_pred\" where\n  \"m1_inv0_fin \\<equiv> m1a_inv0_fin\"\n\nlemmas m1_inv0_finI = m1a_inv0_finI\nlemmas m1_inv0_finE = m1a_inv0_finE\nlemmas m1_inv0_finD = m1a_inv0_finD\n\n\ntext \\<open>Invariance proofs.\\<close>\n\nlemma PO_m1_inv0_fin_init [iff]:\n  \"init m1 \\<subseteq> m1_inv0_fin\"\nby (auto simp add: m1_defs intro!: m1_inv0_finI)\n\nlemma PO_m1_inv0_fin_trans [iff]:\n  \"{m1_inv0_fin} trans m1 {> m1_inv0_fin}\"\nby (auto simp add: PO_hoare_defs m1_defs intro!: m1_inv0_finI)\n\nlemma PO_m1_inv0_fin [iff]: \"reach m1 \\<subseteq> m1_inv0_fin\"\nby (rule inv_rule_incr, auto del: subsetI)\n\ndeclare PO_m1_inv0_fin [THEN subsetD, intro]\n\n\n(******************************************************************************)\nsubsection \\<open>Refinement of \\<open>m1a\\<close>\\<close>\n(******************************************************************************)\n\nsubsubsection \\<open>Simulation relation\\<close>\n(******************************************************************************)\n\ntext \\<open>med1a1: The mediator function maps a concrete observation (i.e., run) \nto an abstract one.\\<close>\n\n\ntext \\<open>Instantiate parameters regarding list of freshness identifiers stored\nat server.\\<close>\n\noverloading is_len' \\<equiv> \"is_len\" rs_len' \\<equiv> \"rs_len\" begin\ndefinition is_len_def [simp]: \"is_len' \\<equiv> 0::nat\"\ndefinition rs_len_def [simp]: \"rs_len' \\<equiv> 0::nat\"\nend\n\nfun \n  rm1a1 :: \"role_t \\<Rightarrow> atom list \\<Rightarrow> atom list\"\nwhere\n  \"rm1a1 Init = take (Suc is_len)\"       \\<comment> \\<open>take \\<open>Kab\\<close>\\<close>\n| \"rm1a1 Resp = take (Suc rs_len)\"       \\<comment> \\<open>take \\<open>Kab\\<close>\\<close>\n| \"rm1a1 Serv = id\"                      \\<comment> \\<open>take all\\<close>\n\nabbreviation \n  runs1a1 :: \"runs_t \\<Rightarrow> runs_t\" where\n  \"runs1a1 \\<equiv> map_runs rm1a1\" \n\nlemmas runs1a1_def = map_runs_def\n\nlemma knC_runs1a1 [simp]:\n  \"knC (runs1a1 runz) = knC runz\"\napply (auto simp add: map_runs_def elim!: knC.cases)\napply (rename_tac b, case_tac b, auto)\napply (rename_tac b, case_tac b, auto)\napply (rule knC_init, auto simp add: runs1a1_def)\napply (rule knC_resp, auto simp add: runs1a1_def)\napply (rule_tac knC_serv, auto simp add: runs1a1_def)\ndone\n\n\ntext \\<open>R1a1: The simulation relation is defined in terms of the mediator\nfunction.\\<close>\n\ndefinition\n  med1a1 :: \"m1_obs \\<Rightarrow> m1a_obs\" where\n  \"med1a1 s \\<equiv> \\<lparr> runs = runs1a1 (runs s), m1x_state.leak = Domain (leak s) \\<rparr>\"\n   \ndefinition\n  R1a1 :: \"(m1a_state \\<times> m1_state) set\" where\n  \"R1a1 \\<equiv> {(s, t). s = med1a1 t}\"\n\nlemmas R1a1_defs = R1a1_def med1a1_def \n\n\nsubsubsection \\<open>Refinement proof\\<close>\n(******************************************************************************)\n\nlemma PO_m1_step1_refines_m1a_step1:\n  \"{R1a1} \n     (m1a_step1 Ra A B Na), (m1_step1 Ra A B Na) \n   {> R1a1}\"\nby (auto simp add: PO_rhoare_defs R1a1_defs m1_defs)\n\nlemma PO_m1_step2_refines_m1a_step2:\n  \"{R1a1} \n     (m1a_step2 Rb A B), (m1_step2 Rb A B) \n   {> R1a1}\"\nby (auto simp add: PO_rhoare_defs R1a1_defs m1_defs)\n\nlemma PO_m1_step3_refines_m1a_step3:\n  \"{R1a1} \n     (m1a_step3 Rs A B Kab Na []), (m1_step3 Rs A B Na Kab)\n   {> R1a1}\"\nby (auto simp add: PO_rhoare_defs R1a1_defs m1_defs)\n\nlemma PO_m1_step4_refines_m1a_step4:\n  \"{R1a1} \n     (m1a_step4 Ra A B Na Kab []), (m1_step4 Ra A B Na Kab) \n   {> R1a1}\"\nby (auto simp add: PO_rhoare_defs R1a1_defs m1_defs runs1a1_def)\n\nlemma PO_m1_step5_refines_m1a_step5:\n  \"{R1a1} \n     (m1a_step5 Rb A B Kab []), (m1_step5 Rb A B Nb Kab) \n   {> R1a1}\"\nby (auto simp add: PO_rhoare_defs R1a1_defs m1_defs runs1a1_def)\n\nlemma PO_m1_step6_refines_m1a_skip:\n  \"{R1a1} \n     Id, (m1_step6 Ra A B Na Nb Kab) \n   {> R1a1}\"\nby (auto simp add: PO_rhoare_defs R1a1_defs m1_defs runs1a1_def)\n\nlemma PO_m1_step7_refines_m1a_skip:\n  \"{R1a1} \n     Id, (m1_step7 Rb A B Nb Kab) \n   {> R1a1}\"\nby (auto simp add: PO_rhoare_defs R1a1_defs m1_defs runs1a1_def)\n\n\n\n\ntext \\<open>All together now...\\<close>\n\nlemmas PO_m1_trans_refines_m1a_trans = \n  PO_m1_step1_refines_m1a_step1 PO_m1_step2_refines_m1a_step2\n  PO_m1_step3_refines_m1a_step3 PO_m1_step4_refines_m1a_step4\n  PO_m1_step5_refines_m1a_step5 PO_m1_step6_refines_m1a_skip \n  PO_m1_step7_refines_m1a_skip PO_m1_leak_refines_m1a_leak\n\nlemma PO_m1_refines_init_m1a [iff]:\n  \"init m1 \\<subseteq>  R1a1``(init m1a)\"\nby (auto simp add: R1a1_defs m1a_defs m1_loc_defs)\n\nlemma PO_m1_refines_trans_m1a [iff]:\n  \"{R1a1} \n     (trans m1a), (trans m1) \n   {> R1a1}\"\napply (auto simp add: m1_def m1_trans_def m1a_def m1a_trans_def\n         intro!: PO_m1_trans_refines_m1a_trans)\napply (force intro!: PO_m1_trans_refines_m1a_trans)+\ndone\n\n\ntext \\<open>Observation consistency.\\<close>\n\nlemma obs_consistent_med1a1 [iff]: \n  \"obs_consistent R1a1 med1a1 m1a m1\"\nby (auto simp add: obs_consistent_def R1a1_def med1a1_def m1a_def m1_def)\n\n\ntext \\<open>Refinement result.\\<close>\n\nlemma PO_m1_refines_m1a [iff]: \n  \"refines R1a1 med1a1 m1a m1\"\nby (rule Refinement_basic) (auto del: subsetI)\n\nlemma  m1_implements_m1a [iff]: \"implements med1a1 m1a m1\"\nby (rule refinement_soundness) (fast)\n\n\n\nsubsubsection \\<open>inv (inherited): Key secrecy\\<close>\n(*invh**************************************************************************)\n\ntext \\<open>Secrecy, as external and internal invariant\\<close>\n\ndefinition \n  m1_secrecy :: \"'x m1_pred\" where\n  \"m1_secrecy \\<equiv> {s. knC (runs s) \\<subseteq> azC (runs s) \\<union> Domain (leak s) \\<times> UNIV}\"\n\nlemmas m1_secrecyI = m1_secrecy_def [THEN setc_def_to_intro, rule_format]\nlemmas m1_secrecyE [elim] = m1_secrecy_def [THEN setc_def_to_elim, rule_format]\n\n\nlemma PO_m1_obs_secrecy [iff]: \"oreach m1 \\<subseteq> m1_secrecy\"\napply (rule_tac Q=m1x_secrecy in external_invariant_translation)\napply (auto del: subsetI)\napply (fastforce simp add: med1a1_def intro!: m1_secrecyI)\ndone\n\nlemma PO_m1_secrecy [iff]: \"reach m1 \\<subseteq> m1_secrecy\"\nby (rule external_to_internal_invariant) (auto del: subsetI)\n\n(*\nsubsubsection {* inv (inherited): Disjointness of session and static keys *}\n(******************************************************************************)\n\nlemma PO_m1_inv0b_key [iff]: \"reach m1 \\<subseteq> m1a_inv0b_key\"\napply (rule_tac Pa=m1a_inv0b_key and Qa=m1a_inv0b_key and Q=m1a_inv0b_key\n       in internal_invariant_translation)\napply (auto del: subsetI)\napply (force simp add: med1a1_def runs1a1_def vimage_def m1a_inv0b_key_def)\ndone\n*)\n\nsubsubsection \\<open>inv (inherited): Initiator auth server.\\<close>\n(*invh*************************************************************************)\n\ntext \\<open>Simplified version of invariant \\<open>m1a_inv2i_serv\\<close>.\\<close>\n\ndefinition \n  m1_inv2i_serv :: \"'x m1r_pred\" \nwhere\n  \"m1_inv2i_serv \\<equiv> {s. \\<forall>A B Ra Na Kab nla.\n     A \\<notin> bad \\<longrightarrow> \n     runs s Ra = Some (Init, [A, B], aKey Kab # nla) \\<longrightarrow>\n     Na = Ra$na \\<longrightarrow>\n       (\\<exists>Rs. Kab = sesK (Rs$sk) \\<and> runs s Rs = Some (Serv, [A, B], [aNon Na]))\n  }\"\n\nlemmas m1_inv2i_servI = m1_inv2i_serv_def [THEN setc_def_to_intro, rule_format]\nlemmas m1_inv2i_servE [elim] = m1_inv2i_serv_def [THEN setc_def_to_elim, rule_format]\nlemmas m1_inv2i_servD = m1_inv2i_serv_def [THEN setc_def_to_dest, rule_format, rotated 2]\n\n\ntext \\<open>Proof of invariance.\\<close>\n\nlemma PO_m1_inv2i_serv [iff]: \"reach m1 \\<subseteq> m1_inv2i_serv\"\napply (rule_tac Pa=m1a_inv2i_serv and Qa=m1a_inv2i_serv and Q=m1_inv2i_serv\n       in internal_invariant_translation)\napply (auto del: subsetI)\napply (auto simp add: m1a_inv2i_serv_def med1a1_def vimage_def \n            intro!: m1_inv2i_servI)\napply (rename_tac s A B Ra Kab nla)\napply (drule_tac x=A in spec, clarsimp)\napply (drule_tac x=B in spec) \napply (drule_tac x=Ra in spec) \napply (drule_tac x=Kab in spec) \napply (clarsimp simp add: runs1a1_def)\ndone\n\ndeclare PO_m1_inv2i_serv [THEN subsetD, intro]\n\n\nsubsubsection \\<open>inv (inherited): Responder auth server.\\<close>\n(*invh*************************************************************************)\n\ntext \\<open>Simplified version of invarant \\<open>m1a_inv2r_serv\\<close>.\\<close>\n\ndefinition \n  m1_inv2r_serv :: \"'x m1r_pred\"\nwhere\n  \"m1_inv2r_serv \\<equiv> {s. \\<forall>A B Rb Kab nlb.\n     B \\<notin> bad \\<longrightarrow> \n     runs s Rb = Some (Resp, [A, B], aKey Kab # nlb) \\<longrightarrow>\n       (\\<exists>Rs Na. Kab = sesK (Rs$sk) \\<and> runs s Rs = Some (Serv, [A, B], [aNon Na]))\n  }\"\n\nlemmas m1_inv2r_servI = m1_inv2r_serv_def [THEN setc_def_to_intro, rule_format]\nlemmas m1_inv2r_servE [elim] = m1_inv2r_serv_def [THEN setc_def_to_elim, rule_format]\nlemmas m1_inv2r_servD = m1_inv2r_serv_def [THEN setc_def_to_dest, rule_format, rotated -1]\n\n\ntext \\<open>Proof of invariance.\\<close>\n\nlemma PO_m1_inv2r_serv [iff]: \"reach m1 \\<subseteq> m1_inv2r_serv\"\napply (rule_tac Pa=m1a_inv2r_serv and Qa=m1a_inv2r_serv and Q=m1_inv2r_serv\n       in internal_invariant_translation)\napply (auto del: subsetI)\napply (auto simp add: simp add: m1a_inv2r_serv_def med1a1_def vimage_def \n            intro!: m1_inv2r_servI)\napply (rename_tac s A B Rb Kab nlb)\napply (drule_tac x=A in spec)\napply (drule_tac x=B in spec, clarsimp) \napply (drule_tac x=Rb in spec)\napply (drule_tac x=Kab in spec) \napply (clarsimp simp add: runs1a1_def)\ndone\n\ndeclare PO_m1_inv2r_serv [THEN subsetD, intro]\n\n\nsubsubsection \\<open>inv (inherited): Initiator key freshness\\<close>\n(*invh*************************************************************************)\n\ndefinition \n  m1_inv3_ifresh :: \"'x m1_pred\"\nwhere\n  \"m1_inv3_ifresh \\<equiv> {s. \\<forall>A A' B B' Ra Ra' Kab nl nl'.\n     runs s Ra  = Some (Init, [A,  B],  aKey Kab # nl) \\<longrightarrow>\n     runs s Ra' = Some (Init, [A', B'], aKey Kab # nl') \\<longrightarrow>\n     A \\<notin> bad \\<longrightarrow> B \\<notin> bad \\<longrightarrow> Kab \\<notin> Domain (leak s) \\<longrightarrow>\n       Ra = Ra'\n  }\"\n\nlemmas m1_inv3_ifreshI = m1_inv3_ifresh_def [THEN setc_def_to_intro, rule_format]\nlemmas m1_inv3_ifreshE [elim] = m1_inv3_ifresh_def [THEN setc_def_to_elim, rule_format]\nlemmas m1_inv3_ifreshD = m1_inv3_ifresh_def [THEN setc_def_to_dest, rule_format, rotated 1]\n\nlemma PO_m1_inv3_ifresh [iff]: \"reach m1 \\<subseteq> m1_inv3_ifresh\"\napply (rule_tac Pa=m1a_inv1_ifresh and Qa=m1a_inv1_ifresh and Q=m1_inv3_ifresh \n       in internal_invariant_translation)\napply (auto del: subsetI)\napply (auto simp add: med1a1_def runs1a1_def vimage_def m1_inv3_ifresh_def)\ndone\n\n\n(******************************************************************************)\nsubsection \\<open>Refinement of \\<open>a0i\\<close> for initiator/responder\\<close>\n(******************************************************************************)\n\nsubsubsection \\<open>Simulation relation\\<close>\n(******************************************************************************)\n\ntext \\<open>We define two auxiliary functions to reconstruct the signals of the\ninitial model from completed initiator and responder runs. For the initiator, \nwe get an injective agreement with the responder on Kab and Nb.\\<close>\n\ntype_synonym\n  irsig = \"key \\<times> nonce\"\n\nabbreviation\n  ir_commit :: \"[runs_t, agent, agent, key, nonce] \\<Rightarrow> rid_t set\" \nwhere\n  \"ir_commit runz A B Kab Nb \\<equiv> {Ra. \n     runz Ra = Some (Init, [A, B], [aKey Kab, aNon Nb])\n  }\"\n\nfun\n  ir_runs2sigs :: \"runs_t \\<Rightarrow> irsig signal \\<Rightarrow> nat\"\nwhere\n  \"ir_runs2sigs runz (Commit [A, B] (Kab, Nb)) =\n     card (ir_commit runz A B Kab Nb)\"\n\n| \"ir_runs2sigs runz (Running [A, B] (Kab, Nb)) =\n     (if \\<exists>Rb nl. Nb = Rb$nb \\<and> runz Rb = Some (Resp, [A, B], aKey Kab # nl) \n      then 1 else 0)\"\n\n| \"ir_runs2sigs runz _ = 0\"\n\n\ntext \\<open>Simulation relation and mediator function. We map completed initiator \nand responder runs to commit and running signals, respectively.\\<close>\n\ndefinition \n  med_a0im1_ir :: \"m1_obs \\<Rightarrow> irsig a0i_obs\" where\n  \"med_a0im1_ir o1 \\<equiv> \\<lparr> signals = ir_runs2sigs (runs o1), corrupted = Domain (leak o1) \\<times> UNIV \\<rparr>\"\n\ndefinition\n  R_a0im1_ir :: \"(irsig a0i_state \\<times> m1_state) set\" where\n  \"R_a0im1_ir \\<equiv> {(s, t). signals s = ir_runs2sigs (runs t) \\<and> corrupted s = Domain (leak t) \\<times> UNIV}\"\n\nlemmas R_a0im1_ir_defs = R_a0im1_ir_def med_a0im1_ir_def \n\n\nsubsubsection \\<open>Lemmas about the abstraction function\\<close>\n(******************************************************************************)\n\nlemma ir_runs2sigs_empty [simp]: \n   \"runz = Map.empty \\<Longrightarrow> ir_runs2sigs runz = (\\<lambda>s. 0)\"\nby (rule ext, erule rev_mp) \n   (rule ir_runs2sigs.induct, auto)\n\nlemma finite_ir_commit [simp, intro!]: \n   \"finite (dom runz) \\<Longrightarrow> finite (ir_commit runz A B Kab Nb)\"\nby (auto intro: finite_subset dest: dom_lemmas)\n\n\ntext \\<open>Update lemmas\\<close>\n\nlemma ir_runs2sigs_upd_init_none [simp]:\n  \"\\<lbrakk> Ra \\<notin> dom runz \\<rbrakk>\n  \\<Longrightarrow> ir_runs2sigs (runz(Ra \\<mapsto> (Init, [A, B], []))) = ir_runs2sigs runz\"\nby (rule ext, erule rev_mp)\n   (rule ir_runs2sigs.induct, auto dest: dom_lemmas)\n\nlemma ir_runs2sigs_upd_resp_none [simp]:\n  \"\\<lbrakk> Rb \\<notin> dom runz \\<rbrakk>\n  \\<Longrightarrow> ir_runs2sigs (runz(Rb \\<mapsto> (Resp, [A, B], []))) = ir_runs2sigs runz\"\nby (rule ext, erule rev_mp)\n   (rule ir_runs2sigs.induct, auto dest: dom_lemmas)\n\nlemma ir_runs2sigs_upd_serv_none [simp]:\n  \"\\<lbrakk> Rs \\<notin> dom runz \\<rbrakk>\n  \\<Longrightarrow> ir_runs2sigs (runz(Rs \\<mapsto> (Serv, [A, B], nl))) = ir_runs2sigs runz\"\nby (rule ext, erule rev_mp)\n   (rule ir_runs2sigs.induct, auto dest: dom_lemmas)\n\nlemma ir_runs2sigs_upd_init_some [simp]:\n  \"\\<lbrakk> runz Ra = Some (Init, [A, B], []) \\<rbrakk>\n  \\<Longrightarrow> ir_runs2sigs (runz(Ra \\<mapsto> (Init, [A, B], [aKey Kab]))) = ir_runs2sigs runz\"\nby (rule ext, erule rev_mp)\n   (rule ir_runs2sigs.induct, auto)\n\nlemma ir_runs2sigs_upd_resp [simp]:\n  \"\\<lbrakk> runz Rb = Some (Resp, [A, B], []) \\<rbrakk>\n  \\<Longrightarrow> ir_runs2sigs (runz(Rb \\<mapsto> (Resp, [A, B], [aKey Kab]))) =\n     (ir_runs2sigs runz)(Running [A, B] (Kab, Rb$nb) := 1)\"\napply (rule ext, erule rev_mp) \napply (rule ir_runs2sigs.induct, fastforce+) \ndone\n\nlemma ir_runs2sigs_upd_init [simp]:\n  \"\\<lbrakk> runz Ra = Some (Init, [A, B], [aKey Kab]); finite (dom runz) \\<rbrakk>\n  \\<Longrightarrow> ir_runs2sigs (runz(Ra \\<mapsto> (Init, [A, B], [aKey Kab, aNon Nb]))) = \n     (ir_runs2sigs runz)\n       (Commit [A, B] (Kab, Nb) := Suc (card (ir_commit runz A B Kab Nb)))\"\napply (rule ext, erule rev_mp, erule rev_mp) \napply (rule_tac ?a0.0=runz in ir_runs2sigs.induct, auto)\n\\<comment> \\<open>1 subgoal, solved using @{thm \"card_insert_disjoint\"}\\<close>\napply (rename_tac runz)\napply (rule_tac \n         s=\"card (insert Ra (ir_commit runz A B Kab Nb))\" \n       in trans, fast, auto)\ndone\n\nlemma ir_runs2sigs_upd_resp_some [simp]:\n  \"\\<lbrakk> runz Rb = Some (Resp, [A, B], [aKey K]) \\<rbrakk>\n  \\<Longrightarrow> ir_runs2sigs (runz(Rb \\<mapsto> (Resp, [A, B], [aKey K, END]))) = ir_runs2sigs runz\"\nby (rule ext, erule rev_mp) \n   (rule ir_runs2sigs.induct, fastforce+)\n\n\ntext \\<open>Needed for injectiveness of agreement.\\<close>\n\nlemma m1_inv2i_serv_lemma:\n  \"\\<lbrakk> runs t Ra  = Some (Init, [A, B], [aKey Kab, aNon Nb]);\n     runs t Ra' = Some (Init, [A, B], [aKey Kab]); \n     A \\<notin> bad; t \\<in> m1_inv2i_serv \\<rbrakk>\n  \\<Longrightarrow> P\"\napply (frule m1_inv2i_servD, auto)\napply (rotate_tac 1)\napply (frule m1_inv2i_servD, auto) \ndone\n\n\nsubsubsection \\<open>Refinement proof\\<close>\n(******************************************************************************)\n\nlemma PO_m1_step1_refines_ir_a0i_skip:\n  \"{R_a0im1_ir} \n     Id, (m1_step1 Ra A B Na) \n   {> R_a0im1_ir}\"\nby (simp add: PO_rhoare_defs R_a0im1_ir_defs m1_defs, safe, auto)\n\nlemma PO_m1_step2_refines_ir_a0i_skip:\n  \"{R_a0im1_ir} \n     Id, (m1_step2 Rb A B) \n   {> R_a0im1_ir}\"\nby (simp add: PO_rhoare_defs R_a0im1_ir_defs m1_defs, safe, auto)\n\nlemma PO_m1_step3_refines_ir_a0i_skip:\n  \"{R_a0im1_ir} \n     Id, (m1_step3 Rs A B Na Kab) \n   {> R_a0im1_ir}\"\nby (simp add: PO_rhoare_defs R_a0im1_ir_defs m1_defs, safe, auto)\n\nlemma PO_m1_step4_refines_ir_a0i_skip:\n  \"{R_a0im1_ir} \n     Id, (m1_step4 Ra A B Na Kab) \n   {> R_a0im1_ir}\"\nby (simp add: PO_rhoare_defs R_a0im1_ir_defs a0i_defs m1_defs, safe, auto)\n\nlemma PO_m1_step5_refines_ir_a0i_running:\n  \"{R_a0im1_ir} \n     (a0i_running [A, B] (Kab, Nb)), (m1_step5 Rb A B Nb Kab) \n   {> R_a0im1_ir}\"\nby (simp add: PO_rhoare_defs R_a0im1_ir_defs a0i_defs m1_defs, safe, auto)\n\nlemma PO_m1_step6_refines_ir_a0i_commit:\n  \"{R_a0im1_ir \\<inter> UNIV \\<times> (m1_inv2i_serv \\<inter> m1_inv0_fin)} \n     (a0i_commit [A, B] (Kab, Nb)), (m1_step6 Ra A B Na Nb Kab) \n   {> R_a0im1_ir}\"\nby (simp add: PO_rhoare_defs R_a0im1_ir_defs a0i_defs m1_defs, safe, auto)\n   (auto dest: m1_inv2i_serv_lemma)\n\nlemma PO_m1_step7_refines_ir_a0i_skip:\n  \"{R_a0im1_ir} \n     Id, (m1_step7 Rb A B Nb Kab) \n   {> R_a0im1_ir}\"\nby (simp add: PO_rhoare_defs R_a0im1_ir_defs a0i_defs m1_defs, safe, auto)\n\nlemma PO_m1_leak_refines_ir_a0i_corrupt:\n  \"{R_a0im1_ir} \n     (a0i_corrupt ({sesK (Rs$sk)} \\<times> UNIV)), (m1_leak Rs Ra Rb A B) \n   {> R_a0im1_ir}\"\nby (simp add: PO_rhoare_defs R_a0im1_ir_defs a0i_defs m1_defs, safe, auto)\n\n\ntext \\<open>All together now...\\<close>\n\nlemmas PO_m1_trans_refines_ir_a0i_trans = \n  PO_m1_step1_refines_ir_a0i_skip PO_m1_step2_refines_ir_a0i_skip\n  PO_m1_step3_refines_ir_a0i_skip PO_m1_step4_refines_ir_a0i_skip\n  PO_m1_step5_refines_ir_a0i_running PO_m1_step6_refines_ir_a0i_commit\n  PO_m1_step7_refines_ir_a0i_skip PO_m1_leak_refines_ir_a0i_corrupt \n\nlemma PO_m1_refines_ir_init_a0i [iff]:\n  \"init m1 \\<subseteq>  R_a0im1_ir``(init a0i)\"\nby (auto simp add: R_a0im1_ir_defs a0i_defs m1_defs\n         intro!: exI [where x=\"\\<lparr>signals = \\<lambda>s. 0, corrupted = corrKey \\<times> UNIV \\<rparr>\"])\n\nlemma PO_m1_refines_ir_trans_a0i [iff]:\n  \"{R_a0im1_ir \\<inter> reach a0i \\<times> reach m1} \n     (trans a0i), (trans m1) \n   {> R_a0im1_ir}\"\napply (rule_tac pre'=\"R_a0im1_ir \\<inter> UNIV \\<times> (m1_inv2i_serv \\<inter> m1_inv0_fin)\" \n       in relhoare_conseq_left, auto)\napply (auto simp add: m1_def m1_trans_def a0i_def a0i_trans_def\n            intro!: PO_m1_trans_refines_ir_a0i_trans)\ndone\n\n\ntext \\<open>Observation consistency.\\<close>\n\nlemma obs_consistent_med_a0im1_ir [iff]: \n  \"obs_consistent R_a0im1_ir med_a0im1_ir a0i m1\"\nby (auto simp add: obs_consistent_def R_a0im1_ir_def med_a0im1_ir_def \n         a0i_def m1_def)\n\ntext \\<open>Refinement result.\\<close>\n\nlemma PO_m1_refines_ir_a0i [iff]: \n  \"refines \n     (R_a0im1_ir \\<inter> reach a0i \\<times> reach m1)\n     med_a0im1_ir a0i m1\"\nby (rule Refinement_using_invariants) (auto)\n\nlemma  m1_implements_ir_a0i: \"implements med_a0im1_ir a0i m1\"\nby (rule refinement_soundness) (fast)\n\n\n(******************************************************************************)\nsubsection \\<open>Refinement of \\<open>a0i\\<close> for responder/initiator\\<close>\n(******************************************************************************)\n\nsubsubsection \\<open>Simulation relation\\<close>\n(******************************************************************************)\n\ntext \\<open>We define two auxiliary functions to reconstruct the signals of the\ninitial model from initiator and responder runs. For the responder, we get an \ninjective agreement with the initiator on Kab and Nb.\\<close>\n\ntype_synonym\n  risig = \"key \\<times> nonce\"\n\nabbreviation\n  ri_running :: \"[runs_t, agent, agent, key, nonce] \\<Rightarrow> rid_t set\"\nwhere\n  \"ri_running runz A B Kab Nb \\<equiv> {Ra. \n     runz Ra = Some (Init, [A, B], [aKey Kab, aNon Nb])\n  }\"\n\nfun\n  ri_runs2sigs :: \"runs_t \\<Rightarrow> risig signal \\<Rightarrow> nat\"\nwhere\n  \"ri_runs2sigs runz (Commit [B, A] (Kab, Nb)) = \n     (if \\<exists>Rb. Nb = Rb$nb \\<and> runz Rb = Some (Resp, [A, B], [aKey Kab, END]) \n      then 1 else 0)\"\n\n| \"ri_runs2sigs runz (Running [B, A] (Kab, Nb)) = \n     card (ri_running runz A B Kab Nb)\"\n\n| \"ri_runs2sigs runz _ = 0\"\n\n\ntext \\<open>Simulation relation and mediator function. We map completed initiator \nand responder runs to commit and running signals, respectively.\\<close>\n\ndefinition \n  med_a0im1_ri :: \"m1_obs \\<Rightarrow> risig a0i_obs\" where\n  \"med_a0im1_ri o1 \\<equiv> \\<lparr> signals = ri_runs2sigs (runs o1), corrupted = Domain (leak o1) \\<times> UNIV \\<rparr>\"\n\ndefinition\n  R_a0im1_ri :: \"(risig a0i_state \\<times> m1_state) set\" where\n  \"R_a0im1_ri \\<equiv> {(s, t). signals s = ri_runs2sigs (runs t) \\<and> corrupted s = Domain (leak t) \\<times> UNIV}\"\n\nlemmas R_a0im1_ri_defs = R_a0im1_ri_def med_a0im1_ri_def \n\n\nsubsubsection \\<open>Lemmas about the auxiliary functions\\<close>\n(******************************************************************************)\n\nlemma ri_runs2sigs_empty [simp]: \n  \"runz = Map.empty \\<Longrightarrow> ri_runs2sigs runz = (\\<lambda>s. 0)\"\nby (rule ext, erule rev_mp) \n   (rule ri_runs2sigs.induct, auto)\n\nlemma finite_inv_ri_running [simp, intro!]: \n   \"finite (dom runz) \\<Longrightarrow> finite (ri_running runz A B Kab Nb)\"\nby (auto intro: finite_subset dest: dom_lemmas)\n\n\ntext \\<open>Update lemmas\\<close>\n\nlemma ri_runs2sigs_upd_init_none [simp]:\n  \"\\<lbrakk> Na \\<notin> dom runz \\<rbrakk>\n  \\<Longrightarrow> ri_runs2sigs (runz(Na \\<mapsto> (Init, [A, B], []))) = ri_runs2sigs runz\"\nby (rule ext, erule rev_mp)\n   (rule ri_runs2sigs.induct, auto dest: dom_lemmas)\n\nlemma ri_runs2sigs_upd_resp_none [simp]:\n  \"\\<lbrakk> Rb \\<notin> dom runz \\<rbrakk>\n  \\<Longrightarrow> ri_runs2sigs (runz(Rb \\<mapsto> (Resp, [A, B], []))) = ri_runs2sigs runz\"\nby (rule ext, erule rev_mp)\n   (rule ri_runs2sigs.induct, auto dest: dom_lemmas)\n\nlemma ri_runs2sigs_upd_serv_none [simp]:\n  \"\\<lbrakk> Rs \\<notin> dom runz \\<rbrakk>\n  \\<Longrightarrow> ri_runs2sigs (runz(Rs \\<mapsto> (Serv, [A, B], nl))) = ri_runs2sigs runz\"\nby (rule ext, erule rev_mp)\n   (rule ri_runs2sigs.induct, auto dest: dom_lemmas)\n\nlemma ri_runs2sigs_upd_init [simp]:\n  \"\\<lbrakk> runz Ra = Some (Init, [A, B], [aKey Kab]); finite (dom runz) \\<rbrakk>\n  \\<Longrightarrow> ri_runs2sigs (runz(Ra \\<mapsto> (Init, [A, B], [aKey Kab, aNon Nb]))) =\n     (ri_runs2sigs runz)\n       (Running [B, A] (Kab, Nb) := Suc (card (ri_running runz A B Kab Nb)))\"\napply (rule ext, erule rev_mp, erule rev_mp)\napply (rule_tac ?a0.0=runz in ri_runs2sigs.induct, auto)\n\\<comment> \\<open>1 subgoal, solved using @{thm \"card_insert_disjoint\"}\\<close>\napply (rename_tac runz)\napply (rule_tac \n         s=\"card (insert Ra (ri_running runz A B Kab Nb))\" \n       in trans, fast, auto)\ndone\n\nlemma ri_runs2sigs_upd_init_some [simp]:\n  \"\\<lbrakk> runz Ra = Some (Init, [A, B], []) \\<rbrakk>\n  \\<Longrightarrow> ri_runs2sigs (runz(Ra \\<mapsto> (Init, [A, B], [aKey Kab]))) = ri_runs2sigs runz\"\nby (rule ext, erule rev_mp)\n   (rule ri_runs2sigs.induct, auto)\n\nlemma ri_runs2sigs_upd_resp_some [simp]:\n  \"\\<lbrakk> runz Rb = Some (Resp, [A, B], [])\\<rbrakk>\n  \\<Longrightarrow> ri_runs2sigs (runz(Rb \\<mapsto> (Resp, [A, B], [aKey K]))) = ri_runs2sigs runz\"\nby (rule ext, erule rev_mp)\n   (rule ri_runs2sigs.induct, auto)\n\nlemma ri_runs2sigs_upd_resp_some2 [simp]:\n  \"\\<lbrakk> runz Rb = Some (Resp, [A, B], [aKey Kab]) \\<rbrakk>\n  \\<Longrightarrow> ri_runs2sigs (runz(Rb \\<mapsto> (Resp, [A, B], [aKey Kab, END]))) = \n     (ri_runs2sigs runz)(Commit [B, A] (Kab, Rb$nb) := 1)\"\napply (rule ext, erule rev_mp)\napply (rule ri_runs2sigs.induct, fastforce+)\ndone\n\n\nsubsubsection \\<open>Refinement proof\\<close>\n(******************************************************************************)\n\nlemma PO_m1_step1_refines_ri_a0i_skip:\n  \"{R_a0im1_ri} \n     Id, (m1_step1 Ra A B Na) \n   {> R_a0im1_ri}\"\nby (simp add: PO_rhoare_defs R_a0im1_ri_defs m1_defs, safe, auto)\n\nlemma PO_m1_step2_refines_ri_a0i_skip:\n  \"{R_a0im1_ri} \n     Id, (m1_step2 Rb A B) \n   {> R_a0im1_ri}\"\nby (simp add: PO_rhoare_defs R_a0im1_ri_defs m1_defs, safe, auto)\n\nlemma PO_m1_step3_refines_ri_a0i_skip:\n  \"{R_a0im1_ri} \n     Id, (m1_step3 Rs A B Na Kab) \n   {> R_a0im1_ri}\"\nby (simp add: PO_rhoare_defs R_a0im1_ri_defs a0i_defs m1_defs, safe, auto)\n\nlemma PO_m1_step4_refines_ri_a0i_skip:\n  \"{R_a0im1_ri} \n     Id, (m1_step4 Ra A B Nb Kab) \n   {> R_a0im1_ri}\"\nby (simp add: PO_rhoare_defs R_a0im1_ri_defs a0i_defs m1_defs, safe, auto)\n\nlemma PO_m1_step5_refines_ri_a0i_skip:\n  \"{R_a0im1_ri} \n     Id, (m1_step5 Rb A B Nb Kab) \n   {> R_a0im1_ri}\"\nby (simp add: PO_rhoare_defs R_a0im1_ri_defs a0i_defs m1_defs, safe, auto)\n\n\n\nlemma PO_m1_step7_refines_ri_a0i_commit:\n  \"{R_a0im1_ri \\<inter> UNIV \\<times> m1_inv0_fin} \n     (a0i_commit [B, A] (Kab, Nb)), (m1_step7 Rb A B Nb Kab) \n   {> R_a0im1_ri}\"\nby (simp add: PO_rhoare_defs R_a0im1_ri_defs a0i_defs m1_defs, safe, auto)\n\nlemma PO_m1_leak_refines_ri_a0i_corrupt:\n  \"{R_a0im1_ri} \n     (a0i_corrupt ({sesK (Rs$sk)} \\<times> UNIV)), (m1_leak Rs Ra Rb A B) \n   {> R_a0im1_ri}\"\nby (simp add: PO_rhoare_defs R_a0im1_ri_defs a0i_defs m1_defs, safe, auto)\n\n\ntext \\<open>All together now...\\<close>\n\nlemmas PO_m1_trans_refines_ri_a0i_trans = \n  PO_m1_step1_refines_ri_a0i_skip PO_m1_step2_refines_ri_a0i_skip\n  PO_m1_step3_refines_ri_a0i_skip PO_m1_step4_refines_ri_a0i_skip\n  PO_m1_step5_refines_ri_a0i_skip PO_m1_step6_refines_ri_a0i_running\n  PO_m1_step7_refines_ri_a0i_commit PO_m1_leak_refines_ri_a0i_corrupt\n\nlemma PO_m1_refines_ri_init_a0i [iff]:\n  \"init m1 \\<subseteq>  R_a0im1_ri``(init a0i)\"\nby (auto simp add: R_a0im1_ri_defs a0i_defs m1_defs\n         intro!: exI [where x=\"\\<lparr>signals = \\<lambda>s. 0, corrupted = corrKey \\<times> UNIV \\<rparr>\"])\n\nlemma PO_m1_refines_ri_trans_a0i [iff]:\n  \"{R_a0im1_ri \\<inter> a0i_inv1_iagree \\<times> m1_inv0_fin} \n     (trans a0i), (trans m1) \n   {> R_a0im1_ri}\"\nby (auto simp add: m1_def m1_trans_def a0i_def a0i_trans_def)\n   (blast intro!: PO_m1_trans_refines_ri_a0i_trans)+\n\n\ntext \\<open>Observation consistency.\\<close>\n\nlemma obs_consistent_med_a0im1_ri [iff]: \n  \"obs_consistent R_a0im1_ri med_a0im1_ri a0i m1\"\nby (auto simp add: obs_consistent_def R_a0im1_ri_def med_a0im1_ri_def a0i_def m1_def)\n\n\ntext \\<open>Refinement result.\\<close>\n\nlemma PO_m1_refines_ri_a0i [iff]: \n  \"refines (R_a0im1_ri \\<inter> a0i_inv1_iagree \\<times> m1_inv0_fin) med_a0im1_ri a0i m1\"\nby (rule Refinement_using_invariants) (auto)\n\nlemma  m1_implements_ri_a0i: \"implements med_a0im1_ri a0i m1\"\nby (rule refinement_soundness) (fast)\n\n\nsubsubsection \\<open>inv3 (inherited): Responder and initiator\\<close>\n(*invh*************************************************************************)\n\ntext \\<open>This is a translation of the agreement property to Level 1. It\nfollows from the refinement and is needed to prove inv4.\\<close>\n\ndefinition \n  m1_inv3r_init :: \"'x m1_pred\"\nwhere\n  \"m1_inv3r_init \\<equiv> {s. \\<forall>A B Rb Kab.\n     B \\<notin> bad \\<longrightarrow> A \\<notin> bad \\<longrightarrow> Kab \\<notin> Domain (leak s) \\<longrightarrow>\n     runs s Rb = Some (Resp, [A, B], [aKey Kab, END]) \\<longrightarrow>\n       (\\<exists>Ra nla. runs s Ra = Some (Init, [A, B], aKey Kab # aNon (Rb$nb) # nla))\n  }\"\n\nlemmas m1_inv3r_initI = \n  m1_inv3r_init_def [THEN setc_def_to_intro, rule_format]\nlemmas m1_inv3r_initE [elim] = \n  m1_inv3r_init_def [THEN setc_def_to_elim, rule_format]\nlemmas m1_inv3r_initD = \n  m1_inv3r_init_def [THEN setc_def_to_dest, rule_format, rotated -1]\n\n\ntext \\<open>Invariance proof.\\<close>\n\nlemma PO_m1_inv3r_init [iff]: \"reach m1 \\<subseteq> m1_inv3r_init\"\napply (rule INV_from_Refinement_basic [OF PO_m1_refines_ri_a0i])\napply (auto simp add: R_a0im1_ri_def a0i_inv1_iagree_def\n            intro!:  m1_inv3r_initI)\napply (rename_tac s A B Rb Kab a)\napply (drule_tac x=\"[B, A]\" in spec, clarsimp)\napply (drule_tac x=\"Kab\" in spec)\n(* apply (drule_tac x=\"Rb$nb\" in spec, auto) *)\napply (subgoal_tac \"card (ri_running (runs s) A B Kab (Rb$nb)) > 0\", auto) \ndone\n\n\nsubsubsection \\<open>inv4: Key freshness for responder\\<close>\n(*inv**************************************************************************)\n\ndefinition \n  m1_inv4_rfresh :: \"'x m1_pred\"\nwhere\n  \"m1_inv4_rfresh \\<equiv> {s. \\<forall>Rb Rb' A A' B B' Kab.\n     runs s Rb  = Some (Resp, [A,  B ], [aKey Kab, END]) \\<longrightarrow> \n     runs s Rb' = Some (Resp, [A', B'], [aKey Kab, END]) \\<longrightarrow> \n     B \\<notin> bad \\<longrightarrow> A \\<notin> bad \\<longrightarrow> Kab \\<notin> Domain (leak s) \\<longrightarrow>\n       Rb = Rb'\n  }\"\n\nlemmas m1_inv4_rfreshI = m1_inv4_rfresh_def [THEN setc_def_to_intro, rule_format]\nlemmas m1_inv4_rfreshE [elim] = m1_inv4_rfresh_def [THEN setc_def_to_elim, rule_format]\nlemmas m1_inv4_rfreshD = m1_inv4_rfresh_def [THEN setc_def_to_dest, rule_format, rotated 1]\n\n\ntext \\<open>Proof of key freshness for responder\\<close>\n\nlemma PO_m1_inv4_rfresh_init [iff]:\n  \"init m1 \\<subseteq> m1_inv4_rfresh\"\nby (auto simp add: m1_defs intro!: m1_inv4_rfreshI)\n\nlemma PO_m1_inv4_rfresh_trans [iff]:\n  \"{m1_inv4_rfresh \\<inter> m1_inv3r_init \\<inter> m1_inv2r_serv \\<inter> m1_inv3_ifresh \\<inter> m1_secrecy} \n      trans m1 \n   {> m1_inv4_rfresh}\"\napply (simp add: PO_hoare_defs m1_defs, safe intro!: m1_inv4_rfreshI, simp_all)\napply (auto dest: m1_inv4_rfreshD) \n\n\\<comment> \\<open>4 subgoals, from responder's final step 7\\<close>  \n  apply (rename_tac Rb A A' B B' Kab xa xe)\n  apply (frule_tac B=B in m1_inv2r_servD, fast, fast, clarsimp)\n  apply (case_tac \"B' \\<notin> bad\", auto dest: m1_inv2r_servD)\n  apply (subgoal_tac \"(sesK (Rs$sk), B') \\<in> azC (runs xa)\")\n  prefer 2 apply (erule m1_secrecyE, auto)\n  apply (erule azC.cases, auto)\n\n  apply (rename_tac Rb A A' B B' Kab xa xe)\n  apply (frule_tac B=B in m1_inv2r_servD, fast, fast, clarify)\n  apply (subgoal_tac \"(sesK (Rs$sk), B') \\<in> azC (runs xa)\")\n  prefer 2 apply (erule m1_secrecyE, auto)\n  apply (erule azC.cases, auto)\n\n  apply (rename_tac Rb' A A' B B' Kab xa xe Ra)\n  apply (case_tac \"A' \\<notin> bad \\<and> B' \\<notin> bad\", auto)\n    apply (frule m1_inv3r_initD, auto)\n    apply (rename_tac Raa nla)\n    apply (frule_tac Ra=Ra in m1_inv3_ifreshD, auto)\n    apply (subgoal_tac \"Ra = Raa\", auto)\n\n    \\<comment> \\<open>@{text \"A' \\<in> bad\"}\\<close>\n    apply (frule_tac B=B in m1_inv2r_servD, fast, fast, clarify) \n    apply (rename_tac Rs Na) \n    apply (case_tac \"B' \\<notin> bad\", auto dest: m1_inv2r_servD) \n    apply (subgoal_tac \"(sesK (Rs$sk), B') \\<in> azC (runs xa)\")\n    prefer 2 apply (erule m1_secrecyE, auto)\n    apply (erule azC.cases, auto)\n\n    \\<comment> \\<open>@{text \"B' \\<in> bad\"}\\<close>\n    apply (frule_tac B=B in m1_inv2r_servD, fast, fast, clarify)\n    apply (rename_tac Rs Na) \n    apply (subgoal_tac \"(sesK (Rs$sk), B') \\<in> azC (runs xa)\")\n    prefer 2 apply (erule m1_secrecyE, auto)\n    apply (erule azC.cases, auto)\n\n  apply (frule m1_inv3r_initD, auto)\n  apply (rename_tac Raa nla)\n  apply (subgoal_tac \"Raa = Ra\", auto)\ndone\n\nlemma PO_m1_inv4_rfresh [iff]: \"reach m1 \\<subseteq> m1_inv4_rfresh\"\napply (rule_tac \n         J=\"m1_inv3r_init \\<inter> m1_inv2r_serv \\<inter> m1_inv3_ifresh \\<inter> m1_secrecy\" \n       in inv_rule_incr) \napply (auto simp add: Int_assoc del: subsetI)\ndone\n\nlemma PO_m1_obs_inv4_rfresh [iff]: \"oreach m1 \\<subseteq> m1_inv4_rfresh\"\nby (rule external_from_internal_invariant)\n   (auto del: subsetI)\n\n\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Security_Protocol_Refinement/Key_establish/m1_nssk.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.546738151984614, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.2690980317527401}}
{"text": "theory IICF_Array\nimports \"../Intf/IICF_List\" \nbegin\n\n\n\n\nsection \\<open>Plain Arrays Implementing List Interface\\<close>\n\nsubsection \\<open>Abstract Replicate-Init Operation\\<close>\n  definition [simp]: \"replicate_init_raw n \\<equiv> replicate n init\"\n\n  locale replicate_init = \n    fixes repl :: \"'a \\<Rightarrow> nat \\<Rightarrow> 'a list\"  \n    assumes repl_def[simp]: \"repl i n = replicate n i\"\n  begin\n  \n    context fixes i::'a begin\n      sepref_register \"repl i\" \n    end\n    \n    lemma replicate_init_param:\n      fixes A :: \"'a \\<Rightarrow> 'c::llvm_rep \\<Rightarrow> assn\"\n      assumes INIT: \"GEN_ALGO i (is_init A)\"\n      shows \"(RETURN o replicate_init_raw, RETURN o PR_CONST (repl i)) \\<in> nat_rel \\<rightarrow>\\<^sub>f \\<langle>\\<langle>the_pure A\\<rangle>list_rel\\<rangle>nres_rel\"\n    proof -\n      from INIT have [param]: \"(init,i) \\<in> the_pure A\" unfolding is_init_def GEN_ALGO_def by simp\n      show ?thesis\n        unfolding repl_def replicate_init_raw_def PR_CONST_def \n        apply (rule frefI)\n        apply (parametricity)\n        done\n        \n    qed\n    \n    lemma fold_replicate_init: \"replicate n i = repl i n\" by simp\n  end\n  \n    \n  sepref_decl_op list_free: \"\\<lambda>_::_ list. ()\" :: \"\\<langle>A\\<rangle>list_rel \\<rightarrow> unit_rel\" .\n\n  \n\nsubsection \\<open>Definition of Assertion\\<close>\n\n  text \\<open>Lists of fixed length are directly implemented with arrays. \\<close>\n  \n  hide_const (open) LLVM_DS_Array.array_assn\n  \n  abbreviation \"raw_array_assn \\<equiv> \\<upharpoonleft>LLVM_DS_NArray.narray_assn\"\n\n  definition array_assn where \"array_assn A \\<equiv> hr_comp raw_array_assn (\\<langle>the_pure A\\<rangle>list_rel)\"\n  lemmas [safe_constraint_rules] = CN_FALSEI[of is_pure \"array_assn A\" for A]\n\nsubsection \\<open>Interface Implementation\\<close>  \n    \ndefinition [simp]: \"array_replicate_init i n \\<equiv> replicate n i\"\ninterpretation array: replicate_init array_replicate_init by unfold_locales simp\n\ncontext \n  notes [fcomp_norm_unfold] = array_assn_def[symmetric]\n  (*notes [simp] = pure_def hn_ctxt_def is_array_def invalid_assn_def*)\nbegin  \n\n  lemma array_get_hnr_aux: \"(uncurry array_nth,uncurry (RETURN oo op_list_get)) \n    \\<in> [\\<lambda>(l,i). i<length l]\\<^sub>a raw_array_assn\\<^sup>k *\\<^sub>a snat_assn\\<^sup>k \\<rightarrow> id_assn\"  \n    unfolding snat_rel_def snat.assn_is_rel[symmetric]\n    apply sepref_to_hoare\n    apply vcg'\n    done\n    \n  sepref_decl_impl array_get: array_get_hnr_aux .  \n\n  lemma array_set_hnr_aux: \"(uncurry2 array_upd,uncurry2 (RETURN ooo op_list_set)) \n    \\<in> [\\<lambda>((l,i),_). i<length l]\\<^sub>a raw_array_assn\\<^sup>d *\\<^sub>a snat_assn\\<^sup>k *\\<^sub>a id_assn\\<^sup>k \\<rightarrow> raw_array_assn\"  \n    unfolding snat_rel_def snat.assn_is_rel[symmetric] \n    apply sepref_to_hoare\n    apply (clarsimp simp: invalid_assn_def)\n    apply (rule htriple_pure_preI, ((determ \\<open>drule pure_part_split_conj|erule conjE\\<close>)+)?)\n    apply vcg\n    done\n    \n  sepref_decl_impl array_set: array_set_hnr_aux .\n  \n  lemma hn_array_repl_init_raw:\n    shows \"(narray_new TYPE('c::llvm_rep),RETURN o replicate_init_raw) \\<in> snat_assn\\<^sup>k \\<rightarrow>\\<^sub>a raw_array_assn\"\n    unfolding snat_rel_def snat.assn_is_rel[symmetric]\n    apply sepref_to_hoare\n    apply vcg'\n    done\n\n  sepref_decl_impl (no_mop) hn_array_repl_init_raw uses array.replicate_init_param . \n  \n  \n  term op_list_replicate\n  \n  sepref_decl_op array_custom_replicate: op_list_replicate :: \"nat_rel \\<rightarrow> A \\<rightarrow> \\<langle>A\\<rangle>list_rel\" .\n  \n  lemma hn_array_replicate_new_raw:\n    \"(uncurry narray_new_init, uncurry (RETURN oo op_array_custom_replicate)) \\<in> snat_assn\\<^sup>k *\\<^sub>a id_assn\\<^sup>k \\<rightarrow>\\<^sub>a raw_array_assn\"\n    unfolding snat_rel_def snat.assn_is_rel[symmetric]\n    apply sepref_to_hoare\n    by vcg\n    \n  sepref_decl_impl hn_array_replicate_new_raw .\n  \n  lemma array_fold_custom_replicate: \n    \"replicate = op_array_custom_replicate\"\n    \"op_list_replicate = op_array_custom_replicate\"\n    \"mop_list_replicate = mop_array_custom_replicate\"\n    by (auto del: ext intro!: ext)\n  \n  lemma hn_array_free_raw: \"(narray_free,RETURN o op_list_free) \\<in> raw_array_assn\\<^sup>d \\<rightarrow>\\<^sub>a unit_assn\"\n    by sepref_to_hoare vcg\n  \n  sepref_decl_impl array_free: hn_array_free_raw .\n  lemmas array_mk_free[sepref_frame_free_rules] = hn_MK_FREEI[OF array_free_hnr]\n  \nend  \n  \n  \n  \nsection \\<open>Arrays with Length\\<close>\n\ndefinition \"larray1_rel = br snd (\\<lambda>(n,xs). n = length xs)\"\nabbreviation \"larray_impl_assn' TYPE('b::len2) \\<equiv> snat_assn' TYPE('b) \\<times>\\<^sub>a array_assn id_assn\"\ndefinition \"raw_larray_assn \\<equiv> hr_comp (larray_impl_assn' TYPE(_)) larray1_rel\"\n\ndefinition \"larray_assn A \\<equiv>  hr_comp raw_larray_assn (\\<langle>the_pure A\\<rangle>list_rel)\"\n\nabbreviation larray_assn' \n  :: \"'b itself \\<Rightarrow> ('a \\<Rightarrow> 'c \\<Rightarrow> llvm_amemory \\<Rightarrow> bool) \\<Rightarrow> 'a list \\<Rightarrow> 'b::len2 word \\<times> 'c::llvm_rep ptr \\<Rightarrow> llvm_amemory \\<Rightarrow> bool\" \n  where\n  \"larray_assn' _ == larray_assn\"\n\n\nlemma larray1_rel_prenorm: \"((n, xs), ys) \\<in> larray1_rel \\<longleftrightarrow> n = length ys \\<and> xs=ys\"  \n  by (auto simp: larray1_rel_def in_br_conv)\n\n\ndefinition [simp]: \"larray_replicate_init i n \\<equiv> replicate n i\"\ninterpretation larray: replicate_init larray_replicate_init by unfold_locales simp\n  \n\ncontext \n  notes [fcomp_norm_unfold] = raw_larray_assn_def[symmetric] larray_assn_def[symmetric]\n  notes [fcomp_prenorm_simps] = larray1_rel_prenorm\nbegin\n\nsepref_decl_op larray_custom_replicate: op_list_replicate :: \"nat_rel \\<rightarrow> A \\<rightarrow> \\<langle>A\\<rangle>list_rel\" .\n\ndefinition \"la_replicate1 n i \\<equiv> (n, replicate n i)\"\nlemma la_replicate1_refine: \"(la_replicate1,op_larray_custom_replicate) \\<in> nat_rel \\<rightarrow> Id \\<rightarrow> larray1_rel\"\n  by (auto simp: larray1_rel_def in_br_conv la_replicate1_def)\n  \nsepref_definition la_replicate_impl [llvm_inline] is \"uncurry (RETURN oo la_replicate1)\" \n  :: \"(snat_assn' TYPE('b::len2))\\<^sup>k *\\<^sub>a id_assn\\<^sup>k \\<rightarrow>\\<^sub>a larray_impl_assn' TYPE('b::len2)\"\n  unfolding la_replicate1_def \n  apply (rewrite array_fold_custom_replicate)\n  apply sepref_dbg_keep\n  done\n  \nsepref_decl_impl la_replicate_impl.refine[FCOMP la_replicate1_refine] . \n\nlemma larray_fold_custom_replicate: \n  \"replicate = op_larray_custom_replicate\"\n  \"op_list_replicate = op_larray_custom_replicate\"\n  \"mop_list_replicate = mop_larray_custom_replicate\"\n  by (auto del: ext intro!: ext)\n\n\n\ndefinition \"la_replicate_init1 n \\<equiv> (n, array_replicate_init init n)\"\nlemma la_replicate_init1_refine: \"(la_replicate_init1, replicate_init_raw) \\<in> nat_rel \\<rightarrow> larray1_rel\"\n  by (auto simp: larray1_rel_def in_br_conv la_replicate_init1_def)\n  \n    \nsepref_definition la_replicate_init_impl [llvm_inline] is \"(RETURN o la_replicate_init1)\" \n  :: \"(snat_assn' TYPE('b::len2))\\<^sup>k \\<rightarrow>\\<^sub>a larray_impl_assn' TYPE('b::len2)\"\n  unfolding la_replicate_init1_def \n  apply sepref_dbg_keep\n  done\n\nsepref_decl_impl (no_mop) la_replicate_init_impl.refine[FCOMP la_replicate_init1_refine] uses larray.replicate_init_param .\n  \n\ndefinition \"la_length1 nxs \\<equiv> case nxs of (n,_) \\<Rightarrow> id n\"\nlemma la_length1_refine: \"(la_length1,op_list_length) \\<in> larray1_rel \\<rightarrow> nat_rel\"\n  by (auto simp: larray1_rel_def in_br_conv la_length1_def)\n\nsepref_definition la_length_impl [llvm_inline] is \"RETURN o la_length1\" :: \"(larray_impl_assn' TYPE('b::len2))\\<^sup>k \\<rightarrow>\\<^sub>a snat_assn' TYPE('b)\"\n  unfolding la_length1_def \n  apply sepref_dbg_keep\n  done\n  \nsepref_decl_impl la_length_impl.refine[FCOMP la_length1_refine] . \n\n\n  \ndefinition \"la_is_empty1 nxs \\<equiv> case nxs of (n,_) \\<Rightarrow> n=0\"\nlemma la_is_empty1_refine: \"(la_is_empty1,op_list_is_empty) \\<in> larray1_rel \\<rightarrow> bool_rel\"\n  by (auto simp: larray1_rel_def in_br_conv la_is_empty1_def)\n    \nsepref_definition la_is_empty_impl [llvm_inline] is \"RETURN o la_is_empty1\" :: \"(larray_impl_assn' TYPE('b::len2))\\<^sup>k \\<rightarrow>\\<^sub>a bool1_assn\"\n  unfolding la_is_empty1_def \n  apply (annot_snat_const \"TYPE('b)\")\n  apply sepref_dbg_keep\n  done\n\nsepref_decl_impl la_is_empty_impl.refine[FCOMP la_is_empty1_refine] . \n  \n\n  \ndefinition \"la_get1 nxs i \\<equiv> case nxs of (n,xs) \\<Rightarrow> xs!i\"\nlemma la_get1_refine: \"(la_get1,op_list_get) \\<in> larray1_rel \\<rightarrow> nat_rel \\<rightarrow> Id\"\n  by (auto simp: larray1_rel_def in_br_conv la_get1_def)\n  \nsepref_definition la_get_impl [llvm_inline] is \"uncurry (RETURN oo la_get1)\" :: \"[\\<lambda>(la,i). i<length (snd la)]\\<^sub>a (larray_impl_assn' TYPE('b::len2))\\<^sup>k *\\<^sub>a (snat_assn' TYPE('b))\\<^sup>k \\<rightarrow> id_assn\"\n  unfolding la_get1_def la_length1_def\n  apply sepref_dbg_keep\n  done\n  \nsepref_decl_impl la_get_impl.refine[FCOMP la_get1_refine] .\n  \n\ndefinition \"la_set1 nxs i x \\<equiv> case nxs of (n,xs) \\<Rightarrow> (n,xs[i:=x])\"\nlemma la_set1_refine: \"(la_set1,op_list_set) \\<in> larray1_rel \\<rightarrow> nat_rel \\<rightarrow> Id \\<rightarrow> larray1_rel\"\n  by (auto simp: larray1_rel_def in_br_conv la_set1_def)\n  \nsepref_definition la_set_impl [llvm_inline] is \"uncurry2 (RETURN ooo la_set1)\" \n  :: \"[\\<lambda>((la,i),_). i<length (snd la)]\\<^sub>a (larray_impl_assn' TYPE('b::len2))\\<^sup>d *\\<^sub>a (snat_assn' TYPE('b))\\<^sup>k *\\<^sub>a id_assn\\<^sup>k \\<rightarrow> larray_impl_assn' TYPE('b::len2)\"\n  unfolding la_set1_def\n  apply sepref_dbg_keep\n  done\n  \nsepref_decl_impl la_set_impl.refine[FCOMP la_set1_refine] .\n\ndefinition \"la_free1 nxs \\<equiv> case nxs of (_,xs) \\<Rightarrow> op_list_free xs\"\nlemma la_free1_refine: \"(la_free1,op_list_free) \\<in> larray1_rel \\<rightarrow> unit_rel\" by auto\n\nsepref_definition la_free_impl [llvm_inline] is \"RETURN o la_free1\" :: \"(larray_impl_assn' TYPE(_))\\<^sup>d \\<rightarrow>\\<^sub>a unit_assn\"\n  unfolding la_free1_def\n  by sepref\n\nsepref_decl_impl larray_free: la_free_impl.refine[FCOMP la_free1_refine] .\nlemmas larray_mk_free[sepref_frame_free_rules] = hn_MK_FREEI[OF larray_free_hnr]\n  \nend\n  \n\n\nsubsection \\<open>Ad-Hoc Regression Tests\\<close>\n  \nsepref_definition example1 [llvm_code] is \"\\<lambda>n. RETURN (replicate (n+1) (snat_init TYPE(32)))\" \n  :: \"[\\<lambda>n. n\\<in>{1..<150}]\\<^sub>a (snat_assn' TYPE(32))\\<^sup>k \\<rightarrow> array_assn (snat_assn' TYPE(32))\"\n  supply [simp] = max_snat_def\n  apply (annot_snat_const \"TYPE(32)\")\n  apply (rewrite array.fold_replicate_init)\n  apply sepref_dbg_keep\n  done\n  \nsepref_definition example2 [llvm_code] is \\<open>\\<lambda>n. do {\n  ASSERT (n>10);\n  let a = replicate n (snat_const TYPE(64) 42);\n  let a = a[snat_const TYPE(32) 3:=0];\n  ASSERT (a!1=42 \\<and> a!2=42);\n  RETURN (a!snat_const TYPE(32) 1 + a!snat_const TYPE(32) 2)\n}\\<close> :: \"(snat_assn' TYPE(32))\\<^sup>k \\<rightarrow>\\<^sub>a snat_assn' TYPE(64)\"\n  supply [simp] = max_snat_def\n  apply (annot_snat_const \"TYPE(64)\")\n  apply (rewrite array_fold_custom_replicate)\n  apply sepref_dbg_keep\n  done\n  \n  \nsepref_definition example1n [llvm_code] is \"\\<lambda>n. RETURN (replicate (n+1) (snat_init TYPE(8)))\" \n  :: \"[\\<lambda>n. n\\<in>{1..<150}]\\<^sub>a (snat_assn' TYPE(32))\\<^sup>k \\<rightarrow> larray_assn' TYPE(32) (snat_assn' TYPE(8))\"\n  supply [simp] = max_snat_def\n  apply (rewrite larray.fold_replicate_init)\n  apply (annot_snat_const \"TYPE(32)\")\n  apply sepref_dbg_keep\n  done\n  \n  \nsepref_definition example2n [llvm_code] is \\<open>\\<lambda>n. do {\n  ASSERT (n>10);\n  let a = replicate n (snat_const TYPE(64) 42);\n  let a = a[snat_const TYPE(32) 3:=0];\n  ASSERT (a!1=42 \\<and> a!2=42);\n  RETURN (a!snat_const TYPE(32) 1 + a!snat_const TYPE(32) 2)\n}\\<close> :: \"(snat_assn' TYPE(32))\\<^sup>k \\<rightarrow>\\<^sub>a snat_assn' TYPE(64)\"\n  supply [simp] = max_snat_def\n  apply (annot_snat_const \"TYPE(64)\")\n  apply (rewrite larray_fold_custom_replicate)\n  apply sepref_dbg_keep\n  done\n\n  \nexport_llvm example1 example2 example1n example2n\n    \n  \nend\n", "meta": {"author": "lammich", "repo": "isabelle_llvm", "sha": "6be37a9c3cae74a1134dbef2979e312abb5f7f42", "save_path": "github-repos/isabelle/lammich-isabelle_llvm", "path": "github-repos/isabelle/lammich-isabelle_llvm/isabelle_llvm-6be37a9c3cae74a1134dbef2979e312abb5f7f42/thys-2018/sepref/IICF/Impl/IICF_Array.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.26909803175274005}}
{"text": "section\\<open>Simple Firewall Syntax\\<close>\ntheory SimpleFw_Syntax\nimports IP_Addresses.Hs_Compat\n        Firewall_Common_Decision_State\n        \"Primitives/Iface\"\n        \"Primitives/L4_Protocol\"\n        Simple_Packet\nbegin\n\n  text\\<open>For for IP addresses of arbitrary length\\<close>\n\n  datatype simple_action = Accept | Drop\n  \n  text\\<open>Simple match expressions do not allow negated expressions.\n        However, Most match expressions can still be transformed into simple match expressions.\n        \n        A negated IP address range can be represented as a set of non-negated IP ranges.\n        For example \\<open>!8 = {0..7} \\<union> {8 .. ipv4max}\\<close>.\n        Using CIDR notation (i.e. the \\<open>a.b.c.d/n\\<close> notation), we can represent negated IP\n        ranges as a set of non-negated IP ranges with only fair blowup.\n        Another handy result is that the conjunction of two IP ranges in CIDR notation is \n        either the smaller of the two ranges or the empty set.\n        An empty IP range cannot be represented.\n        If one wants to represent the empty range, then the complete rule needs to be removed.\n\n        The same holds for layer 4 ports.\n        In addition, there exists an empty port range, e.g. \\<open>(1,0)\\<close>.\n        The conjunction of two port ranges is again just one port range.\n        \n        But negation of interfaces is not supported. Since interfaces support a wildcard character,\n        transforming a negated interface would either result in an infeasible blowup or requires\n        knowledge about the existing interfaces (e.g. there only is eth0, eth1, wlan3, and vbox42)\n        An empirical test shows that negated interfaces do not occur in our data sets.\n        Negated interfaces can also be considered bad style: What is !eth0? Everything that is\n        not eth0, experience shows that interfaces may come up randomly, in particular in combination \n        with virtual machines, so !eth0 might not be the desired match.\n        At the moment, if an negated interface occurs which prevents translation to a simple match,\n        we recommend to abstract the negated interface to unknown and remove it (upper or lower closure\n        rule set) before translating to a simple match.\n        The same discussion holds for negated protocols.\n\n        Noteworthy, simple match expressions are both expressive and support conjunction:\n        \\<open>simple-match1 \\<and> simple-match2 = simple-match3\\<close>\n\\<close>\n        (*It took very long to design the simple match such that it can represent everything we need\n        and that you can calculate with it. Disjunction is easy: just have two consecutive rules with the same action.\n        Conjunction was a tough fight! It is needed to translate:\n        common_primitive_match_to_simple_match (MatchAny e1 e2) =\n          simple_match_and (common_primitive_match_to_simple_match e1) (common_primitive_match_to_simple_match e2)\n        This is key to translate common_primitive_match to simple_match\n\n        It may seem a simple enhancement to support iiface :: \"iface negation_type\", but then you\n        can no longer form the conjunction of two simple_matches.\n        *)\n\n  record (overloaded) 'i simple_match =\n    iiface :: \"iface\" \\<comment> \\<open>in-interface\\<close>\n      (*we cannot (and don't want to) express negated interfaces*)\n      (*We could also drop interface wildcard support and try negated interfaces again \\<dots>*)\n    oiface :: \"iface\" \\<comment> \\<open>out-interface\\<close>\n    src :: \"('i::len word \\<times> nat) \" \\<comment> \\<open>source IP address\\<close>\n    dst :: \"('i::len word \\<times> nat) \" \\<comment> \\<open>destination\\<close>\n    proto :: \"protocol\"\n    sports :: \"(16 word \\<times> 16 word)\" \\<comment> \\<open>source-port first:last\\<close>\n    dports :: \"(16 word \\<times> 16 word)\" \\<comment> \\<open>destination-port first:last\\<close>\n\n  \n  context\n    notes [[typedef_overloaded]]\n  begin\n    datatype 'i simple_rule = SimpleRule (match_sel: \"'i simple_match\") (action_sel: simple_action)\n  end\n\n\n\ntext\\<open>Simple rule destructor. Removes the @{typ \"'a simple_rule\"} type, returns a tuple with the match and action.\\<close>\n  definition simple_rule_dtor :: \"'a simple_rule \\<Rightarrow> 'a simple_match \\<times> simple_action\" where\n    \"simple_rule_dtor r \\<equiv> (case r of SimpleRule m a \\<Rightarrow> (m,a))\"\n  \n  lemma simple_rule_dtor_ids:\n    \"uncurry SimpleRule \\<circ> simple_rule_dtor = id\"\n    \"simple_rule_dtor \\<circ> uncurry SimpleRule = id\" \n    unfolding simple_rule_dtor_def comp_def fun_eq_iff\n    by(simp_all split: simple_rule.splits)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Simple_Firewall/SimpleFw_Syntax.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.26909803175274005}}
{"text": "(*\n * Copyright 2018-2019, NTU\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n *  Author: Albert Rizaldi, NTU Singapore\n *)\n\ntheory Femto_VHDL\n  imports Main\n          \"HOL-Library.Poly_Mapping\"\n          \"HOL-Library.Finite_Map\"\n          \"Polynomials.Poly_Mapping_Finite_Map\"\n          \"Femto_VHDL_raw\"\nbegin\n\nsection \"Syntax and Semantics\"\n\nlemma zero_map:\n  \"(0 :: 'a \\<rightharpoonup> 'b) x = None\"\n  by (auto simp add:zero_option_def zero_fun_def)\n\nsubsection \"Operational Semantics\"\n\n(* ADD an introduction text *)\ntype_synonym 'signal transaction = \"(nat, 'signal valuation) poly_mapping\"\n\nabbreviation empty_trans :: \"'signal transaction\" where\n  \"empty_trans \\<equiv> 0\"\n\ntype_synonym 'signal transaction_sig = \"'signal \\<Rightarrow> nat \\<Rightarrow>\\<^sub>0 val option\"\n\nlift_definition to_transaction_sig :: \"'signal transaction \\<Rightarrow> 'signal transaction_sig\"\n  is to_trans_raw_sig\n  by (metis (mono_tags, lifting) finite_subset mem_Collect_eq subsetI to_trans_raw_sig_def\n  zero_fun_def)\n\nlift_definition to_transaction_sig_bit :: \"val \\<Rightarrow> 'signal transaction \\<Rightarrow> nat \\<Rightarrow> 'signal \\<Rightarrow> 'signal transaction\"\n  is to_trans_raw_bit\n  unfolding to_trans_raw_bit_def sym[OF eventually_cofinite] zero_fun_def zero_option_def \n  using zero_map\nproof -\n  fix val\n  fix \"fun\" :: \"nat \\<Rightarrow> 'signal \\<Rightarrow> val option\" and nat :: nat and signal :: 'signal\n  assume a1: \"\\<forall>\\<^sub>\\<infinity>x. fun x = Map.empty\"\n  obtain nn :: \"(nat \\<Rightarrow> bool) \\<Rightarrow> (nat \\<Rightarrow> bool) \\<Rightarrow> nat\" where\n    f2: \"\\<And>p f pa fa. (\\<not> eventually p f \\<or> eventually pa f \\<or> p (nn p pa)) \\<and> (\\<not> eventually p fa \\<or> \\<not> pa (nn p pa) \\<or> eventually pa fa)\"\n    by (metis (no_types) eventually_mono)\n  then have f3: \"\\<And>p. Alm_all p \\<or> (\\<forall>s. fun (nn (\\<lambda>n. \\<forall>s. fun n s = None) p) s = None)\"\n    using a1  by (metis (mono_tags, lifting))\n  have f4: \"\\<And>n. (\\<exists>s. fun n s \\<noteq> None) \\<or> (\\<forall>s. (s \\<noteq> signal \\<longrightarrow> fun n s = None) \\<and> (s = signal \\<longrightarrow> (case fun n s of None \\<Rightarrow> None | Some (Bv xa) \\<Rightarrow> Map.empty xa | Some (Lv s bs) \\<Rightarrow> (Some \\<circ> Bv) (bs ! nat)) = None))\"\n    by force\n  { assume \"(\\<forall>\\<^sub>\\<infinity>n. \\<forall>s. fun n s = None) \\<and> \\<not> (\\<forall>\\<^sub>\\<infinity>n. \\<forall>s. (s \\<noteq> signal \\<longrightarrow> fun n s = None) \\<and> (s = signal \\<longrightarrow> (case fun n s of None \\<Rightarrow> None | Some (Bv xa) \\<Rightarrow> Map.empty xa | Some (Lv s bs) \\<Rightarrow> (Some \\<circ> Bv) (bs ! nat)) = None))\"\n    then have \"\\<exists>p. (\\<forall>s. (s = signal \\<or> fun (nn p (\\<lambda>n. \\<forall>s. (s \\<noteq> signal \\<longrightarrow> fun n s = None) \\<and> (s = signal \\<longrightarrow> (case fun n s of None \\<Rightarrow> None | Some (Bv xa) \\<Rightarrow> Map.empty xa | Some (Lv s bs) \\<Rightarrow> (Some \\<circ> Bv) (bs ! nat)) = None))) s = None) \\<and> (s \\<noteq> signal \\<or> (case fun (nn p (\\<lambda>n. \\<forall>s. (s \\<noteq> signal \\<longrightarrow> fun n s = None) \\<and> (s = signal \\<longrightarrow> (case fun n s of None \\<Rightarrow> None | Some (Bv xa) \\<Rightarrow> Map.empty xa | Some (Lv s bs) \\<Rightarrow> (Some \\<circ> Bv) (bs ! nat)) = None))) s of None \\<Rightarrow> None | Some (Bv xa) \\<Rightarrow> Map.empty xa | Some (Lv s bs) \\<Rightarrow> (Some \\<circ> Bv) (bs ! nat)) = None)) \\<and> Alm_all p\"\n      using f4 f3 by meson\n    then have \"\\<forall>\\<^sub>\\<infinity>n. (\\<lambda>s. if s \\<noteq> signal then fun n s else case fun n s of None \\<Rightarrow> None | Some (Bv xa) \\<Rightarrow> Map.empty xa | Some (Lv s bs) \\<Rightarrow> (Some \\<circ> Bv) (bs ! nat)) = Map.empty\"\n      using f2\n      by (smt \\<open>(\\<forall>\\<^sub>\\<infinity>n. \\<forall>s. fun n s = None) \\<and> \\<not> (\\<forall>\\<^sub>\\<infinity>n. \\<forall>s. (s \\<noteq> signal \\<longrightarrow> fun n s = None) \\<and> (s = signal \\<longrightarrow> (case fun n s of None \\<Rightarrow> None | Some (Bv x) \\<Rightarrow> Map.empty x | Some (Lv s bs) \\<Rightarrow> (Some \\<circ> Bv) (bs ! nat)) = None))\\<close>) }\n  then show \"\\<forall>\\<^sub>\\<infinity>x. (\\<lambda>sig. if sig \\<noteq> signal then fun x sig\n                     else case fun x sig of None \\<Rightarrow> None\n                          | Some v \\<Rightarrow>\n                              if 0 < x \\<and> to_bit nat (signal_of val fun sig (x - 1)) = to_bit nat v then None\n                              else if x = 0 \\<and> to_bit nat val = to_bit nat v then None else Some (to_bit nat v)) =\n              Map.empty\"\n  proof -\n    have f1: \"\\<And>p. Alm_all p \\<or> (\\<forall>s. fun (nn (\\<lambda>n. \\<forall>s. fun n s = None) p) s = None)\"\n      by (simp add: f3)\n    { assume \"\\<not> (\\<forall>\\<^sub>\\<infinity>n. \\<forall>s. (s \\<noteq> signal \\<longrightarrow> fun n s = None) \\<and> (s = signal \\<longrightarrow> (case fun n s of None \\<Rightarrow> None | Some v \\<Rightarrow> if 0 < n \\<and> to_bit nat (signal_of val fun s (n - 1)) = to_bit nat v then None else if n = 0 \\<and> to_bit nat val = to_bit nat v then None else Some (to_bit nat v)) = None))\"\n      then have \"(\\<forall>\\<^sub>\\<infinity>n. \\<forall>s. fun n s = None) \\<and> \\<not> (\\<forall>\\<^sub>\\<infinity>n. \\<forall>s. (s \\<noteq> signal \\<longrightarrow> fun n s = None) \\<and> (s = signal \\<longrightarrow> (case fun n s of None \\<Rightarrow> None | Some v \\<Rightarrow> if 0 < n \\<and> to_bit nat (signal_of val fun s (n - 1)) = to_bit nat v then None else if n = 0 \\<and> to_bit nat val = to_bit nat v then None else Some (to_bit nat v)) = None))\"\n        by (metis a1)\n      then have \"\\<exists>p. Alm_all p \\<and> (\\<forall>s. (s = signal \\<or> fun (nn p (\\<lambda>n. \\<forall>s. (s \\<noteq> signal \\<longrightarrow> fun n s = None) \\<and> (s = signal \\<longrightarrow> (case fun n s of None \\<Rightarrow> None | Some v \\<Rightarrow> if 0 < n \\<and> to_bit nat (signal_of val fun s (n - 1)) = to_bit nat v then None else if n = 0 \\<and> to_bit nat val = to_bit nat v then None else Some (to_bit nat v)) = None))) s = None) \\<and> (s \\<noteq> signal \\<or> (case fun (nn p (\\<lambda>n. \\<forall>s. (s \\<noteq> signal \\<longrightarrow> fun n s = None) \\<and> (s = signal \\<longrightarrow> (case fun n s of None \\<Rightarrow> None | Some v \\<Rightarrow> if 0 < n \\<and> to_bit nat (signal_of val fun s (n - 1)) = to_bit nat v then None else if n = 0 \\<and> to_bit nat val = to_bit nat v then None else Some (to_bit nat v)) = None))) s of None \\<Rightarrow> None | Some v \\<Rightarrow> if 0 < nn p (\\<lambda>n. \\<forall>s. (s \\<noteq> signal \\<longrightarrow> fun n s = None) \\<and> (s = signal \\<longrightarrow> (case fun n s of None \\<Rightarrow> None | Some v \\<Rightarrow> if 0 < n \\<and> to_bit nat (signal_of val fun s (n - 1)) = to_bit nat v then None else if n = 0 \\<and> to_bit nat val = to_bit nat v then None else Some (to_bit nat v)) = None)) \\<and> to_bit nat (signal_of val fun s (nn p (\\<lambda>n. \\<forall>s. (s \\<noteq> signal \\<longrightarrow> fun n s = None) \\<and> (s = signal \\<longrightarrow> (case fun n s of None \\<Rightarrow> None | Some v \\<Rightarrow> if 0 < n \\<and> to_bit nat (signal_of val fun s (n - 1)) = to_bit nat v then None else if n = 0 \\<and> to_bit nat val = to_bit nat v then None else Some (to_bit nat v)) = None)) - 1)) = to_bit nat v then None else if nn p (\\<lambda>n. \\<forall>s. (s \\<noteq> signal \\<longrightarrow> fun n s = None) \\<and> (s = signal \\<longrightarrow> (case fun n s of None \\<Rightarrow> None | Some v \\<Rightarrow> if 0 < n \\<and> to_bit nat (signal_of val fun s (n - 1)) = to_bit nat v then None else if n = 0 \\<and> to_bit nat val = to_bit nat v then None else Some (to_bit nat v)) = None)) = 0 \\<and> to_bit nat val = to_bit nat v then None else Some (to_bit nat v)) = None))\"\n        using f1 by fastforce\n      then have ?thesis\n        by (smt MOST_mono \\<open>(\\<forall>\\<^sub>\\<infinity>n. \\<forall>s. fun n s = None) \\<and> \\<not> (\\<forall>\\<^sub>\\<infinity>n. \\<forall>s. (s \\<noteq> signal \\<longrightarrow> fun n s = None) \\<and> (s = signal \\<longrightarrow> (case fun n s of None \\<Rightarrow> None | Some v \\<Rightarrow> if 0 < n \\<and> to_bit nat (signal_of val fun s (n - 1)) = to_bit nat v then None else if n = 0 \\<and> to_bit nat val = to_bit nat v then None else Some (to_bit nat v)) = None))\\<close> option.simps(4)) }\n    then show ?thesis\n      by meson\n  qed\nqed\n\nlemma finite_keys_to_transaction_sig:\n  \"finite (Poly_Mapping.keys (to_transaction_sig \\<tau> s))\"\n  by auto\n\nsubsection \\<open>From transaction to function of time (signal)\\<close>\n\nlemma list_split3:\n  assumes \"sorted xs\" and \"distinct xs\" and \"xs \\<noteq> []\"\n  assumes \"hd xs \\<le> x\" and \"x < last xs\"\n  shows \"\\<exists>ys y zs. xs = ys @ y # zs \\<and> (\\<forall>k \\<in> set ys. k \\<le> x) \\<and> x < y\"\nproof -\n  obtain ys where \"takeWhile (\\<lambda>n. n \\<le> x) xs = ys\"\n    by auto\n  moreover obtain y zs where \"dropWhile (\\<lambda>n. n \\<le> x) xs = y # zs\"\n    by (metis append_Nil2 assms(3) assms(5) last_in_set le_less not_less_iff_gr_or_eq set_takeWhileD\n        sorted.cases takeWhile_dropWhile_id)\n  ultimately have \"xs = ys @ y # zs \\<and> x < y\"\n    using dropWhile_eq_Cons_conv by fastforce\n  moreover have \"(\\<forall>k\\<in>set ys. k \\<le> x)\"\n    using `takeWhile (\\<lambda>n. n \\<le> x) xs = ys`  by (meson set_takeWhileD)\n  ultimately show ?thesis\n    by auto\nqed\n\nlemma takeWhile_last:\n  fixes maxtime :: nat\n  assumes \"sorted ys\" and \"ys \\<noteq> []\" and \"last ys \\<le> maxtime\"\n  shows \"takeWhile (\\<lambda>k. k \\<le> maxtime) ys = ys\"\n  unfolding takeWhile_eq_all_conv\nproof\n  fix k\n  assume \"k \\<in> set ys\"\n  hence \"k \\<le> last ys\"\n    using `sorted ys` `ys \\<noteq> []`\n    by (metis insertE last_appendR last_in_set less_or_eq_imp_le list.distinct(1) list.set(2)\n        sorted.simps(2) sorted_append split_list)\n  thus \"k \\<le> maxtime\"\n    using assms by auto\nqed\n\nlemma takeWhile_last_strict:\n  fixes maxtime :: nat\n  assumes \"sorted ys\" and \"ys \\<noteq> []\" and \"last ys < maxtime\"\n  shows \"takeWhile (\\<lambda>k. k < maxtime) ys = ys\"\n  using assms\n  by (metis nat_less_le not_less takeWhile_eq_all_conv takeWhile_last)\n\nfun inf_key :: \"nat list \\<Rightarrow> nat \\<Rightarrow> nat option\" where\n  \"inf_key ks n = (case takeWhile (\\<lambda>k. k \\<le> n) ks of [] \\<Rightarrow> None | ks' \\<Rightarrow> Some (last ks'))\"\n\nlemma inf_key_alt_def:\n  assumes \"sorted (a # ks)\"\n  shows \"inf_key (a # ks) n = (if a \\<le> n \\<and> inf_key ks n = None then Some a else inf_key ks n)\"\nproof -\n  have \"a \\<le> n \\<or> n < a\" by auto\n  moreover\n  { assume \"a \\<le> n\"\n    hence \"takeWhile (\\<lambda>k. k \\<le> n) (a # ks) = a # takeWhile (\\<lambda>k. k \\<le> n) ks\"\n      by auto\n    hence \"inf_key (a # ks) n =\n                         (case a # takeWhile (\\<lambda>k. k \\<le> n) ks of [] \\<Rightarrow> None | ks' \\<Rightarrow> Some (last ks'))\"\n      by auto\n    also have \"... =\n        (if takeWhile (\\<lambda>k. k \\<le> n) ks = [] then Some a else Some (last (takeWhile (\\<lambda>k. k \\<le> n) ks)))\"\n      by auto\n    also have \"... = (if inf_key ks n = None then Some a else inf_key ks n)\"\n      by (auto split:list.splits)\n    finally have \"inf_key (a # ks) n = (if inf_key ks n = None then Some a else inf_key ks n)\"\n      by auto\n    hence ?thesis using `a \\<le> n` by auto }\n  moreover\n  { assume \"n < a\"\n    hence \"takeWhile (\\<lambda>k. k \\<le> n) (a # ks) = []\"\n      by auto\n    hence \"inf_key (a # ks) n = None\"\n      by auto\n    moreover have \"inf_key ks n = None\"\n      using `sorted (a # ks)`\n      by (metis \\<open>n < a\\<close> inf_key.simps list.simps(4) neq_Nil_conv not_le order.strict_trans2 sorted2\n          takeWhile.simps(1) takeWhile.simps(2))\n    ultimately have ?thesis using `n < a` by auto }\n  ultimately show ?thesis by auto\nqed\n\nlift_definition inf_time :: \"'a transaction_sig \\<Rightarrow> 'a \\<Rightarrow> nat \\<Rightarrow> nat option\" is\n  Femto_VHDL_raw.inf_time .\n\nlemma dropWhileD2:\n  assumes \"sorted xs\" and \"distinct xs\"\n  shows \"x \\<in> set (dropWhile (\\<lambda>k. k \\<le> n) xs) \\<Longrightarrow> n < x\"\n  using assms\nproof (induction xs)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons a xs)\n  have \"a \\<le> n \\<or> n < a\"\n    by auto\n  moreover\n  { assume \"a \\<le> n\"\n    hence \"dropWhile (\\<lambda>k. k \\<le> n) (a # xs) = dropWhile (\\<lambda>k. k \\<le> n) xs\"\n      by auto\n    with Cons have ?case\n      by auto }\n  moreover\n  { assume \"n < a\"\n    hence \"dropWhile (\\<lambda>k. k \\<le> n) (a # xs) = a # xs\"\n      by auto\n    hence \"x \\<in> set (a # xs)\"\n      using Cons by auto\n    with Cons have ?case\n      using \\<open>n < a\\<close> order.strict_trans2 by auto }\n  ultimately show ?case by auto\nqed\n\nlemma inf_time_inf_key [code]:\n  \"inf_time \\<tau> sig n = inf_key (sorted_list_of_set (Poly_Mapping.keys (\\<tau> sig))) n\"\nproof transfer\n  fix \\<tau> :: \"'a \\<Rightarrow> nat \\<Rightarrow> val option\"\n  fix sig\n  fix n\n  assume \"pred_fun top (\\<lambda>f. finite {x. f x \\<noteq> 0}) \\<tau>\"\n  hence \"finite {k. \\<tau> sig k \\<noteq> 0}\"\n    unfolding pred_fun_def by auto\n  define ks where \"ks = sorted_list_of_set {k. \\<tau> sig k \\<noteq> 0}\"\n  have \"(\\<exists>k\\<in> keys(\\<tau> sig). k \\<le> n) \\<or> \\<not> (\\<exists>k\\<in> keys(\\<tau> sig). k \\<le> n)\"\n    by auto\n  moreover\n  { assume not: \"\\<not> (\\<exists>k\\<in> keys(\\<tau> sig). k \\<le> n)\"\n    have \"takeWhile (\\<lambda>k. k \\<le> n) ks = []\"\n      using ks_def unfolding keys_def\n      by (induction ks, simp)\n         (metis Femto_VHDL_raw.keys_def \\<open>finite {k. \\<tau> sig k \\<noteq> 0}\\<close> insertI1 list.simps(15) not\n         set_sorted_list_of_set takeWhile.simps(2))\n    hence \"inf_key ks n = None\"\n      by (simp add: ks_def)\n    also have \"... = Femto_VHDL_raw.inf_time \\<tau> sig n\"\n      by (auto simp add: not Femto_VHDL_raw.inf_time_def)\n    finally have \"Femto_VHDL_raw.inf_time \\<tau> sig n = inf_key ks n\"\n      by auto }\n  moreover\n  { assume exi: \"\\<exists>k\\<in> keys(\\<tau> sig). k \\<le> n\"\n    hence *: \"Femto_VHDL_raw.inf_time \\<tau> sig n = Some (GREATEST k. k \\<in> keys (\\<tau> sig) \\<and> k \\<le> n)\"\n      by (auto simp add: Femto_VHDL_raw.inf_time_def)\n    have \"ks \\<noteq> []\"\n      using exi by (auto simp add: \\<open>finite {k. \\<tau> sig k \\<noteq> 0}\\<close> ks_def keys_def)\n    hence \"takeWhile (\\<lambda>k. k \\<le> n) ks \\<noteq> []\"\n      using ks_def exi unfolding keys_def\n    proof (induction ks)\n      case (Cons a ks)\n      have \"a \\<le> n \\<or> n < a\"\n        by auto\n      moreover\n      { assume \"a \\<le> n\"\n        hence \"takeWhile (\\<lambda>k. k \\<le> n) (a # ks) = a # takeWhile (\\<lambda>k. k \\<le> n) ks\"\n          by auto\n        hence ?case\n          by auto }\n      moreover\n      { assume \"n < a\"\n        with Cons.prems have \"\\<tau> sig a \\<noteq> 0\"\n          by (metis \\<open>finite {k. \\<tau> sig k \\<noteq> 0}\\<close> domIff dom_def insertI1 list.simps(15)\n          set_sorted_list_of_set zero_option_def)\n        have \"sorted (a # ks)\" and \"distinct (a # ks)\"\n          using Cons.prems(2) by auto\n        hence \"\\<forall>k' \\<in> set ks. a < k'\"\n          using nat_less_le by auto\n        with `n < a` have \"\\<forall>k' \\<in> set (a # ks). n < k'\"\n          by auto\n        with Cons have \"False\"\n          using \\<open>finite {k. \\<tau> sig k \\<noteq> 0}\\<close> by auto\n        hence ?case by auto }\n      ultimately show ?case by auto\n    qed (auto)\n    define ks' where \"ks' = takeWhile (\\<lambda>k. k \\<le> n) ks\"\n    hence \"ks' \\<noteq> []\"\n      using `takeWhile (\\<lambda>k. k \\<le> n) ks \\<noteq> []` by auto\n    have \"(GREATEST k. k \\<in> keys (\\<tau> sig) \\<and> k \\<le> n) = last ks'\"\n    proof (rule Greatest_equality)\n      have \"last ks' \\<in> Femto_VHDL_raw.keys (\\<tau> sig)\"\n        using `ks' \\<noteq> []` unfolding keys_def ks'_def ks_def\n        by (metis \\<open>finite {k. \\<tau> sig k \\<noteq> 0}\\<close> last_in_set set_sorted_list_of_set set_takeWhileD)\n      moreover have \"last ks' \\<le> n\"\n        using `ks' \\<noteq> []` unfolding ks'_def  by (meson last_in_set set_takeWhileD)\n      ultimately show \"last ks' \\<in> Femto_VHDL_raw.keys (\\<tau> sig) \\<and> last ks' \\<le> n\"\n        by auto\n    next\n      { fix y\n        assume \"\\<not> y \\<le> last ks'\" hence \"last ks' < y\" by auto\n        have \"y \\<in> set ks \\<or> y \\<notin> set ks\"\n          by auto\n        moreover\n        { assume \"y \\<notin> set ks\"\n          hence \"y \\<notin> Femto_VHDL_raw.keys (\\<tau> sig)\"\n            unfolding keys_def ks_def by (simp add: \\<open>finite {k. \\<tau> sig k \\<noteq> 0}\\<close>)\n          hence \"\\<not> (y \\<in> Femto_VHDL_raw.keys (\\<tau> sig) \\<and> y \\<le> n)\"\n            by auto }\n        moreover\n        { assume \"y \\<in> set ks\"\n          hence \"y \\<in> set (takeWhile (\\<lambda>k. k \\<le> n) ks) \\<or> y \\<in> set (dropWhile (\\<lambda>k. k \\<le> n) ks)\"\n            by (metis Un_iff set_append takeWhile_dropWhile_id)\n          moreover\n          { assume \"y \\<in> set (dropWhile (\\<lambda>k. k \\<le> n) ks)\"\n            hence \"n < y\"\n              using dropWhileD2 distinct_sorted_list_of_set ks_def sorted_sorted_list_of_set\n              by blast\n            hence \"\\<not> (y \\<in> Femto_VHDL_raw.keys (\\<tau> sig) \\<and> y \\<le> n)\"\n              by auto }\n          moreover\n          { assume \"y \\<in> set (takeWhile (\\<lambda>k. k \\<le> n) ks)\"\n            hence \"y \\<le> last ks'\"\n              using `ks' \\<noteq> []`\n              by (metis ks'_def ks_def linorder_not_le order_refl sorted_list_of_set(2)\n              sorted_takeWhile takeWhile_eq_all_conv takeWhile_last_strict)\n            with `last ks' < y` have False by auto\n            hence \"\\<not> (y \\<in> Femto_VHDL_raw.keys (\\<tau> sig) \\<and> y \\<le> n)\"\n              by auto }\n          ultimately have \"\\<not> (y \\<in> Femto_VHDL_raw.keys (\\<tau> sig) \\<and> y \\<le> n)\"\n            by auto }\n        ultimately have \"\\<not> (y \\<in> Femto_VHDL_raw.keys (\\<tau> sig) \\<and> y \\<le> n)\"\n          by auto }\n      thus \"\\<And>y. y \\<in> Femto_VHDL_raw.keys (\\<tau> sig) \\<and> y \\<le> n \\<Longrightarrow> y \\<le> last ks'\"\n        by auto\n    qed\n    moreover have \"inf_key ks n = Some (last ks')\"\n    proof -\n      obtain x xs where \"ks' = x # xs\"\n        using `ks' \\<noteq> []`  by (meson neq_Nil_conv)\n      hence \"inf_key ks n = Some (last (x # xs))\"\n        using `ks' \\<noteq>[]` unfolding ks'_def by auto\n      thus ?thesis\n        using `ks' = x # xs` by auto\n    qed\n    ultimately have \"Femto_VHDL_raw.inf_time \\<tau> sig n = inf_key ks n\"\n      using * by auto }\n  ultimately show \"Femto_VHDL_raw.inf_time \\<tau> sig n = inf_key ks n\"\n    by auto\nqed\n\nlift_definition to_signal :: \"val \\<Rightarrow> 'signal transaction_sig \\<Rightarrow> 'signal \\<Rightarrow> nat \\<Rightarrow> val\" is\n  Femto_VHDL_raw.to_signal .\n\n\n\nabbreviation \"signal_of2 def \\<equiv> to_signal def o to_transaction_sig\"\n\nlift_definition beval ::\n  \"nat \\<Rightarrow> 'signal state \\<Rightarrow> 'signal event \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal state \\<Rightarrow> 'signal bexp \\<Rightarrow> val \\<Rightarrow> bool\"\n  is beval_raw .\n\ninductive beval_ind :: \"nat \\<Rightarrow> 'signal state \\<Rightarrow> 'signal event \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal state \\<Rightarrow> 'signal bexp \\<Rightarrow> val \\<Rightarrow> bool\"\n  where\n  \"beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bsig sig) (\\<sigma> sig)\"\n| \"beval_ind now \\<sigma> \\<gamma> \\<theta> def (Btrue) (Bv True)\"\n| \"beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bfalse) (Bv False)\"\n| \"beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bsig_delayed sig t) (signal_of2 (def sig) \\<theta> sig (now - t))\"\n| \"beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bsig_event sig) (Bv (sig \\<in> \\<gamma>))\"\n| \"beval_ind now \\<sigma> \\<gamma> \\<theta> def e (Bv bool) \\<Longrightarrow> beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bnot e) (Bv (\\<not> bool))\"\n| \"beval_ind now \\<sigma> \\<gamma> \\<theta> def e (Lv ki bs) \\<Longrightarrow> beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bnot e) (Lv ki (map Not bs))\"\n| \"\\<lbrakk>beval_ind now \\<sigma> \\<gamma> \\<theta> def e1 (Bv val1); beval_ind now \\<sigma> \\<gamma> \\<theta> def e2 (Bv val2)\\<rbrakk> \\<Longrightarrow>\n                                           beval_ind now \\<sigma> \\<gamma> \\<theta> def (Band e1 e2) (Bv ( val1 \\<and> val2))\"\n| \"\\<lbrakk>beval_ind now \\<sigma> \\<gamma> \\<theta> def e1 (Lv ki bs1); beval_ind now \\<sigma> \\<gamma> \\<theta> def e2 (Lv ki bs2); length bs1 = length bs2\\<rbrakk>\n                                  \\<Longrightarrow>  beval_ind now \\<sigma> \\<gamma> \\<theta> def (Band e1 e2) (Lv ki (map2 (\\<and>) bs1 bs2))\"\n| \"\\<lbrakk>beval_ind now \\<sigma> \\<gamma> \\<theta> def e1 (Bv val1); beval_ind now \\<sigma> \\<gamma> \\<theta> def e2 (Bv val2)\\<rbrakk> \\<Longrightarrow>\n                                            beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bor e1 e2) (Bv ( val1 \\<or> val2))\"\n| \"\\<lbrakk>beval_ind now \\<sigma> \\<gamma> \\<theta> def e1 (Lv ki bs1); beval_ind now \\<sigma> \\<gamma> \\<theta> def e2 (Lv ki bs2); length bs1 = length bs2\\<rbrakk>\n                                   \\<Longrightarrow>  beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bor e1 e2) (Lv ki (map2 (\\<or>) bs1 bs2))\"\n| \"\\<lbrakk>beval_ind now \\<sigma> \\<gamma> \\<theta> def e1 (Bv val1); beval_ind now \\<sigma> \\<gamma> \\<theta> def e2 (Bv val2)\\<rbrakk> \\<Longrightarrow>\n                                        beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bnand e1 e2) (Bv (\\<not>(val1 \\<and> val2)))\"\n| \"\\<lbrakk>beval_ind now \\<sigma> \\<gamma> \\<theta> def e1  (Lv ki bs1); beval_ind now \\<sigma> \\<gamma> \\<theta> def e2  (Lv ki bs2); length bs1 = length bs2\\<rbrakk>\n                    \\<Longrightarrow> beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bnand e1 e2)  (Lv ki (map2 (\\<lambda>x y. \\<not> (x \\<and> y)) bs1 bs2))\"\n| \"\\<lbrakk>beval_ind now \\<sigma> \\<gamma> \\<theta> def e1  (Bv val1); beval_ind now \\<sigma> \\<gamma> \\<theta> def e2  (Bv val2)\\<rbrakk> \\<Longrightarrow>\n                                         beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bnor e1 e2)  (Bv (\\<not>(val1 \\<or> val2)))\"\n| \"\\<lbrakk>beval_ind now \\<sigma> \\<gamma> \\<theta> def e1  (Lv ki bs1); beval_ind now \\<sigma> \\<gamma> \\<theta> def  e2  (Lv ki bs2); length bs1 = length bs2\\<rbrakk>\n                     \\<Longrightarrow> beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bnor e1 e2)  (Lv ki (map2 (\\<lambda>x y. \\<not> (x \\<or> y)) bs1 bs2))\"\n| \"\\<lbrakk>beval_ind now \\<sigma> \\<gamma> \\<theta> def e1  (Bv val1); beval_ind now \\<sigma> \\<gamma> \\<theta> def e2  (Bv val2)\\<rbrakk> \\<Longrightarrow>\n                                          beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bxor e1 e2)  (Bv (xor val1 val2))\"\n| \"\\<lbrakk>beval_ind now \\<sigma> \\<gamma> \\<theta> def e1  (Lv ki bs1); beval_ind now \\<sigma> \\<gamma> \\<theta> def e2  (Lv ki bs2); length bs1 = length bs2\\<rbrakk>\n                                   \\<Longrightarrow> beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bxor e1 e2)  (Lv ki (map2 xor bs1 bs2))\"\n| \"\\<lbrakk>beval_ind now \\<sigma> \\<gamma> \\<theta> def e1  (Bv val1); beval_ind now \\<sigma> \\<gamma> \\<theta> def e2  (Bv val2)\\<rbrakk> \\<Longrightarrow>\n                                       beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bxnor e1 e2)  (Bv (\\<not> xor val1 val2))\"\n| \"\\<lbrakk>beval_ind now \\<sigma> \\<gamma> \\<theta> def e1  (Lv ki bs1); beval_ind now \\<sigma> \\<gamma> \\<theta> def e2  (Lv ki bs2); length bs1 = length bs2\\<rbrakk>\n                    \\<Longrightarrow> beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bxnor e1 e2)  (Lv ki (map2 (\\<lambda>x y. \\<not> xor x y) bs1 bs2))\"\n| \"beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bsig sig) (Lv ki bs) \\<Longrightarrow>  length bs = len \\<Longrightarrow>\n                                    beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bslice sig l r) (Lv ki (nths bs {len - l - 1 .. len - r - 1}))\"\n| \"beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bsig sig) (Lv ki bs) \\<Longrightarrow> beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bindex sig idx) (Bv (bs ! idx))\"\n\n| \"beval_ind now \\<sigma> \\<gamma> \\<theta> def e1 (Lv Uns bs1) \\<Longrightarrow> beval_ind now \\<sigma> \\<gamma> \\<theta> def e2 (Lv Uns bs2) \\<Longrightarrow>\n   len = max (length bs1) (length bs2) \\<Longrightarrow> bs = bin_to_bl len (bl_to_bin bs1 + bl_to_bin bs2) \\<Longrightarrow>\n   beval_ind now \\<sigma> \\<gamma> \\<theta> def (Badd e1 e2) (Lv Uns bs)\"\n\n| \"beval_ind now \\<sigma> \\<gamma> \\<theta> def e1 (Lv Sig bs1) \\<Longrightarrow> beval_ind now \\<sigma> \\<gamma> \\<theta> def e2 (Lv Sig bs2) \\<Longrightarrow>\n   len = max (length bs1) (length bs2) \\<Longrightarrow> bs = bin_to_bl len (sbl_to_bin bs1 + sbl_to_bin bs2) \\<Longrightarrow>\n   beval_ind now \\<sigma> \\<gamma> \\<theta> def (Badd e1 e2) (Lv Sig bs)\"\n\n| \"beval_ind now \\<sigma> \\<gamma> \\<theta> def e1 (Lv Uns bs1) \\<Longrightarrow> beval_ind now \\<sigma> \\<gamma> \\<theta> def e2 (Lv Uns bs2) \\<Longrightarrow>\n   len = (length bs1) + (length bs2) \\<Longrightarrow> bs = bin_to_bl len (bl_to_bin bs1 * bl_to_bin bs2) \\<Longrightarrow>\n   beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bmult e1 e2) (Lv Uns bs)\"\n\n| \"beval_ind now \\<sigma> \\<gamma> \\<theta> def e1 (Lv Sig bs1) \\<Longrightarrow> beval_ind now \\<sigma> \\<gamma> \\<theta> def e2 (Lv Sig bs2) \\<Longrightarrow>\n   len = (length bs1) + (length bs2) \\<Longrightarrow> bs = bin_to_bl len (sbl_to_bin bs1 * sbl_to_bin bs2) \\<Longrightarrow>\n   beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bmult e1 e2) (Lv Sig bs)\"\n\n| \"beval_ind now \\<sigma> \\<gamma> \\<theta> def e1 (Lv Uns bs1) \\<Longrightarrow> beval_ind now \\<sigma> \\<gamma> \\<theta> def e2 (Lv Uns bs2) \\<Longrightarrow>\n   len = max (length bs1) (length bs2) \\<Longrightarrow> bs = bin_to_bl len (bl_to_bin bs1 - bl_to_bin bs2) \\<Longrightarrow>\n   beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bsub e1 e2) (Lv Uns bs)\"\n\n| \"beval_ind now \\<sigma> \\<gamma> \\<theta> def e1 (Lv Sig bs1) \\<Longrightarrow> beval_ind now \\<sigma> \\<gamma> \\<theta> def e2 (Lv Sig bs2) \\<Longrightarrow>\n   len = max (length bs1) (length bs2) \\<Longrightarrow> bs = bin_to_bl len (sbl_to_bin bs1 - sbl_to_bin bs2) \\<Longrightarrow>\n   beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bsub e1 e2) (Lv Sig bs)\"\n\n| \"\\<lbrakk>beval_ind now \\<sigma> \\<gamma> \\<theta> def e (Lv Uns bs);  bs' = drop n (bs @ replicate n False)\\<rbrakk>\n                                              \\<Longrightarrow>  beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bshiftl e n) (Lv Uns bs')\"\n\n| \"\\<lbrakk>beval_ind now \\<sigma> \\<gamma> \\<theta> def e (Lv Sig bs);  bs' = drop n (bs @ replicate n False)\\<rbrakk>\n                                              \\<Longrightarrow>  beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bshiftl e n) (Lv Sig bs')\"\n\n| \"\\<lbrakk>beval_ind now \\<sigma> \\<gamma> \\<theta> def e (Lv Uns bs);  bs' = take (length bs) (replicate n False @ bs)\\<rbrakk>\n                                              \\<Longrightarrow>  beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bshiftr e n) (Lv Uns bs')\"\n\n| \"\\<lbrakk>beval_ind now \\<sigma> \\<gamma> \\<theta> def e (Lv Sig bs);  bs' = take (length bs) (replicate n (hd bs) @ bs)\\<rbrakk>\n                                              \\<Longrightarrow>  beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bshiftr e n) (Lv Sig bs')\"\n\n| \"\\<lbrakk>beval_ind now \\<sigma> \\<gamma> \\<theta> def g (Bv True);  beval_ind now \\<sigma> \\<gamma> \\<theta> def th res\\<rbrakk>\n                                              \\<Longrightarrow>  beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bwhen th g el) res\"\n\n| \"\\<lbrakk>beval_ind now \\<sigma> \\<gamma> \\<theta> def g (Bv False);  beval_ind now \\<sigma> \\<gamma> \\<theta> def el res\\<rbrakk>\n                                              \\<Longrightarrow>  beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bwhen th g el) res\"\n\n| \"beval_ind now \\<sigma> \\<gamma> \\<theta> def (Bliteral sign val) (Lv sign val)\"\n\nlemma beval_eq_beval_ind:\n  \"beval t \\<sigma> \\<gamma> \\<theta> def exp res = beval_ind t \\<sigma> \\<gamma> \\<theta> def exp res\"\nproof\n  assume \"beval t \\<sigma> \\<gamma> \\<theta> def exp res\"\n  hence \"beval_ind t \\<sigma> \\<gamma> (Abs_poly_mapping (lookup \\<theta>)) def exp res\"\n  proof transfer\n    fix t \\<sigma> \\<gamma>\n    fix \\<theta> :: \"nat \\<Rightarrow> 'a \\<Rightarrow> val option\"\n    fix def exp res\n    assume \"finite {x. \\<theta> x \\<noteq> 0}\"\n    assume \"t , \\<sigma> , \\<gamma> , \\<theta>, def  \\<turnstile> exp \\<longrightarrow>\\<^sub>b res\"\n    thus \"beval_ind t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def exp res\"\n      using `finite {x. \\<theta> x \\<noteq> 0}`\n    proof (induction rule: beval_raw.induct)\n      case (4 now \\<sigma> \\<gamma> \\<theta> def sig t)\n      have \"signal_of2 (def sig) (Abs_poly_mapping \\<theta>) sig (now - t) = signal_of (def sig) \\<theta> sig (now - t)\"\n        unfolding Femto_VHDL.to_signal.rep_eq comp_def to_transaction_sig.rep_eq\n        lookup_Abs_poly_mapping[OF 4] by auto\n      then show ?case by (metis beval_ind.intros(4))\n    qed (metis beval_ind.intros)+\n  qed\n  thus \"beval_ind t \\<sigma> \\<gamma> \\<theta> def exp res\"\n    unfolding lookup_inverse by auto\nnext\n  assume \"beval_ind t \\<sigma> \\<gamma> \\<theta> def exp res\"\n  thus \"beval t \\<sigma> \\<gamma> \\<theta> def exp res\"\n    unfolding beval.rep_eq\n  proof (induction rule: beval_ind.inducts)\n    case (4 now \\<sigma> \\<gamma> \\<theta> def sig t)\n    have \"signal_of2 (def sig) \\<theta> sig (now - t) = signal_of (def sig) (lookup \\<theta>) sig (now - t)\"\n      by transfer' auto\n    then show ?case\n      using beval_raw.intros(4) by force\n  qed (metis beval_raw.intros)+\nqed\n\nlemma beval_ind_deterministic:\n  assumes \"beval_ind t \\<sigma> \\<gamma> \\<theta> def exp res1\"\n  assumes \"beval_ind t \\<sigma> \\<gamma> \\<theta> def exp res2\"\n  shows \"res2 = res1\"\n  using assms unfolding sym[OF beval_eq_beval_ind]\n  by transfer' (simp add: beval_raw_deterministic)\n\nlift_definition transtyping :: \"'s tyenv \\<Rightarrow> 's transaction \\<Rightarrow> bool\" is ttyping .\n\nlemma beval_ind_progress_unique:\n  assumes \"bexp_wt \\<Gamma> exp type\" and \"styping \\<Gamma> \\<sigma>\" and \"transtyping \\<Gamma> \\<theta>\" and \"styping \\<Gamma> def\"\n  shows \"\\<exists>!v. beval_ind t \\<sigma> \\<gamma> \\<theta> def exp v\"\n  unfolding sym[OF beval_eq_beval_ind] using assms\n  by transfer' (auto simp add: beval_raw_progress beval_raw_deterministic)\n\nlift_definition post :: \"'signal \\<Rightarrow> val \\<Rightarrow> 'signal transaction \\<Rightarrow> nat \\<Rightarrow> 'signal transaction\" is\n  post_raw unfolding post_raw_def sym[OF eventually_cofinite]\n  by (smt MOST_mono MOST_neq(2) MOST_rev_mp fun_upd_idem_iff zero_fun_def zero_option_def)\n\nlift_definition preempt :: \"'signal \\<Rightarrow> 'signal transaction \\<Rightarrow> nat \\<Rightarrow> 'signal transaction\" is\n  preempt_raw unfolding preempt_raw_def sym[OF eventually_cofinite]\n  by (smt MOST_mono fun_upd_idem_iff zero_map)\n\nlift_definition post_necessary:: \"nat \\<Rightarrow> 'signal transaction \\<Rightarrow> nat \\<Rightarrow> 'signal \\<Rightarrow> val \\<Rightarrow> val \\<Rightarrow> bool\"\n  is post_necessary_raw .\n\nlift_definition trans_post ::\n  \"'signal \\<Rightarrow> val \\<Rightarrow> val \\<Rightarrow> 'signal transaction \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> 'signal transaction\"\n  is trans_post_raw\n  unfolding  sym[OF eventually_cofinite] using trans_post_raw_almost_all_zero\n  by metis\n\nlemma [code]:\n  \"trans_post s val def \\<tau> t dly =\n  (if post_necessary (dly - 1) \\<tau> t s val def then post s val \\<tau> (t + dly) else preempt s \\<tau> (t + dly))\"\n  by (transfer', auto simp add: trans_post_raw_def)\n\nlift_definition purge :: \"'signal transaction \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> 'signal \\<Rightarrow> val \\<Rightarrow> val \\<Rightarrow> 'signal transaction\" is\n  purge_raw unfolding purge_raw_def sym[OF eventually_cofinite]\n  by (metis purge_raw_almost_all_zero purge_raw_def)\n\nlift_definition purge' :: \"'signal transaction \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> 'signal \\<Rightarrow> val \\<Rightarrow> val \\<Rightarrow> 'signal transaction\" is\n  purge_raw' unfolding purge_raw'_def sym[OF eventually_cofinite]\n  by (metis (no_types) purge_raw'_def purge_raw_almost_all_zero')\n\n(* TODO: remove the following proof since it  is duplicated from Femto_VHDL_raw.thy *)\n\nlift_definition combine_trans_bit_lifted :: \"'signal transaction \\<Rightarrow> (val \\<times> 'signal transaction) list \\<Rightarrow> signedness \\<Rightarrow> 'signal \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> 'signal transaction\" is\n  combine_trans_bit unfolding combine_trans_bit_def Let_def \nproof -\n  fix f :: \"nat \\<Rightarrow> 'signal \\<Rightarrow> val option\"\n  fix list :: \"(val \\<times> (nat \\<Rightarrow> 'signal \\<Rightarrow> val option)) list\" \n  fix signedness signal now dly\n  assume *: \"list_all (pred_prod top (\\<lambda>f. finite {x. f x \\<noteq> 0})) list\"\n  assume \"finite {x. f x \\<noteq> 0}\"\n  hence \"\\<forall>\\<^sub>\\<infinity>x. f x = 0\"\n    unfolding sym[OF eventually_cofinite] by auto\n  assume \"list_all (pred_prod top (\\<lambda>f. finite {x. f x \\<noteq> 0})) list\"  \n  have \"(\\<lambda>x sig. if x \\<le> now \\<or> now + dly < x \\<or> sig \\<noteq> signal then f x sig\n                 else if x \\<in> fold (\\<union>) (map (Femto_VHDL_raw.keys \\<circ> (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> signal) \\<circ> snd) list) {}\n                 then Some (Lv signedness (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig x)) list)) else None) = \n        (override_on (\\<lambda>x. if x \\<le> now \\<or> now + dly < x then f x else (f x)(signal := None)) \n                     (\\<lambda>x. \\<lambda>sig. if x \\<le> now \\<or> now + dly < x \\<or> sig \\<noteq> signal then f x sig else \n                               Some (Lv signedness (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig x)) list))) \n                     (fold (\\<union>) (map (Femto_VHDL_raw.keys \\<circ> (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> signal) \\<circ> snd) list) {}))\"\n      (is \"?fun = ?fun'\") by (auto intro!: ext)\n  have \"finite {x. ?fun' x \\<noteq> 0}\"\n    unfolding sym[OF eventually_cofinite] \n  proof (intro upd_eventually_cofinite_override_on_finite)\n    have \"\\<And>init. finite init \\<Longrightarrow> finite (fold (\\<union>) (map (\\<lambda>x. {k. to_trans_raw_sig (snd x) signal k \\<noteq> 0}) list) init)\"\n      using *\n    proof (induction list)\n      case Nil\n      then show ?case by auto\n    next\n      case (Cons a ps)\n      have \"pred_prod (\\<lambda>a. True) (\\<lambda>f. finite {x. f x \\<noteq> 0}) a\"\n        using Cons(3) by auto\n      hence \"finite {x. snd a x \\<noteq> 0}\"\n        using pred_prod_inject surjective_pairing[of \"a\"] by metis\n      have **: \" (fold (\\<union>) (map (\\<lambda>x. {k. to_trans_raw_sig (snd x) signal k \\<noteq> 0}) (a # ps)) init) = \n             fold (\\<union>) (map (\\<lambda>x. {k. to_trans_raw_sig (snd x) signal k \\<noteq> 0}) ps) ({k. to_trans_raw_sig (snd a) signal k \\<noteq> 0} \\<union> init)\"\n        unfolding list.map(2) fold_Cons comp_def Un_empty_right by auto\n      have \"finite  ({k. to_trans_raw_sig (snd a) signal k \\<noteq> 0} \\<union> init)\"\n        using `finite init` `finite {x. snd a x \\<noteq> 0}` unfolding finite_Un \n        to_trans_raw_sig_def\n        by (metis (mono_tags, lifting) finite_nat_iff_bounded mem_Collect_eq subset_eq zero_map zero_option_def)\n      thus ?case\n        using Cons by auto\n    qed\n    hence fin: \"finite (fold (\\<union>) (map (\\<lambda>x. {k. to_trans_raw_sig (snd x) signal k \\<noteq> 0}) list) {})\"\n      by auto\n    thus \" finite (fold (\\<union>) (map (Femto_VHDL_raw.keys \\<circ> (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> signal) \\<circ> snd) list) {})\"\n      unfolding keys_def comp_def by auto\n  next\n    show \" \\<forall>\\<^sub>\\<infinity>x. (if x \\<le> now \\<or> now + dly < x then f x else (f x)(signal := None)) = 0\"\n      using `\\<forall>\\<^sub>\\<infinity>x. f x = 0` by (smt MOST_mono fun_upd_idem zero_map)\n  qed\n  thus \"finite                                                                \n        {x. (\\<lambda>sig. if x \\<le> now \\<or> now + dly < x \\<or> sig \\<noteq> signal then f x sig\n                   else if x \\<in> fold (\\<union>) (map (Femto_VHDL_raw.keys \\<circ> (\\<lambda>\\<tau>. to_trans_raw_sig \\<tau> signal) \\<circ> snd) list) {}\n                        then Some (Lv signedness (map (\\<lambda>p. bval_of (signal_of (get_time p) (snd p) sig x)) list)) else None) \\<noteq>\n            0}\"\n    using `?fun = ?fun'` by metis\nqed\n\nlift_definition inr_post ::\n  \"'signal \\<Rightarrow> val \\<Rightarrow> val \\<Rightarrow> 'signal transaction \\<Rightarrow> nat \\<Rightarrow> delay \\<Rightarrow> 'signal transaction\"\n  is inr_post_raw'\n  unfolding sym[OF eventually_cofinite] using inr_post_raw_almost_all_zero'\n  by metis\n\nlemma [code]:\n  \"inr_post sig val def \\<tau> now dly =\n      trans_post sig val def (purge' \\<tau> now dly sig def val) now dly\"\n  by (transfer', auto simp add: Femto_VHDL_raw.inr_post_raw'_def)\n\nlift_definition seq_exec :: \"nat \\<Rightarrow> 'signal state \\<Rightarrow> 'signal event \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal state \\<Rightarrow>\n                                    'signal seq_stmt \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal transaction \\<Rightarrow> bool\" is\n  b_seq_exec .\n\ndeclare seq_exec.rep_eq[code_abbrev]\n\ninductive seq_exec_ind :: \"nat \\<Rightarrow> 'signal state \\<Rightarrow> 'signal event \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal state \\<Rightarrow>\n                                    'signal seq_stmt \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal transaction \\<Rightarrow> bool\" where\n  \"seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def Bnull \\<tau> \\<tau>\"\n\n| \"seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def ss1 \\<tau> \\<tau>'' \\<Longrightarrow> seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def ss2 \\<tau>'' \\<tau>' \\<Longrightarrow>\n                                                        seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def (Bcomp ss1 ss2) \\<tau> \\<tau>'\"\n\n| \"beval_ind t \\<sigma> \\<gamma> \\<theta> def guard (Bv True)  \\<Longrightarrow> seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def ss1 \\<tau> \\<tau>' \\<Longrightarrow>\n                                               seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def (Bguarded guard ss1 ss2) \\<tau> \\<tau>'\"\n\n\n| \"beval_ind t \\<sigma> \\<gamma> \\<theta> def guard (Bv False) \\<Longrightarrow> seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def ss2 \\<tau> \\<tau>' \\<Longrightarrow>\n                                               seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def (Bguarded guard ss1 ss2) \\<tau> \\<tau>'\"\n\n| \"beval_ind t \\<sigma> \\<gamma> \\<theta> def e x \\<Longrightarrow> trans_post sig x (\\<sigma> sig) \\<tau> t dly = \\<tau>' \\<Longrightarrow>\n                                              seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def (Bassign_trans sig e dly) \\<tau> \\<tau>'\"\n\n| \"beval_ind t \\<sigma> \\<gamma> \\<theta> def e x \\<Longrightarrow> inr_post sig x (\\<sigma> sig) \\<tau> t dly = \\<tau>' \\<Longrightarrow>\n                                              seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def (Bassign_inert sig e dly) \\<tau> \\<tau>'\"\n\n| \"beval_ind t \\<sigma> \\<gamma> \\<theta> def exp x \\<Longrightarrow> beval_ind t \\<sigma> \\<gamma> \\<theta> def exp' x \\<Longrightarrow> seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def ss \\<tau> \\<tau>'\n   \\<Longrightarrow> seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def (Bcase exp ((Explicit exp', ss) # choices)) \\<tau> \\<tau>'\"\n\n| \"beval_ind t \\<sigma> \\<gamma> \\<theta> def exp x \\<Longrightarrow> beval_ind t \\<sigma> \\<gamma> \\<theta> def exp' x' \\<Longrightarrow> x \\<noteq> x' \\<Longrightarrow>\n   seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def (Bcase exp choices) \\<tau> \\<tau>'  \\<Longrightarrow>\n   seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def (Bcase exp ((Explicit exp', ss) # choices)) \\<tau> \\<tau>'\"\n\n| \"seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def ss \\<tau> \\<tau>' \\<Longrightarrow>\n   seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def (Bcase exp ((Others, ss) # choices)) \\<tau> \\<tau>'\"\n\n| \"seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def (Bcase exp []) \\<tau> \\<tau>\"\n\nlemma seq_exec_eq_seq_exec_ind:\n  \"seq_exec t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>' = seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>'\"\nproof\n  assume \"seq_exec t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>'\"\n  hence \"seq_exec_ind t \\<sigma> \\<gamma> (Abs_poly_mapping (lookup \\<theta>)) def cs (Abs_poly_mapping (lookup \\<tau>)) (Abs_poly_mapping (lookup \\<tau>'))\"\n  proof transfer\n    fix t \\<sigma> \\<gamma>\n    fix \\<theta> :: \"nat \\<Rightarrow> 'a \\<Rightarrow> val option\"\n    fix def cs\n    fix \\<tau> \\<tau>' :: \"nat \\<Rightarrow> 'a \\<Rightarrow> val option\"\n    assume \"finite {x. \\<theta> x \\<noteq> 0}\"\n    assume \"finite {x. \\<tau> x \\<noteq> 0}\"\n    assume \"finite {x. \\<tau>' x \\<noteq> 0}\"\n    assume \"t , \\<sigma> , \\<gamma> , \\<theta> , def \\<turnstile> <cs , \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\"\n    thus \"seq_exec_ind t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def cs (Abs_poly_mapping \\<tau>) (Abs_poly_mapping \\<tau>')\"\n      using `finite {x. \\<theta> x \\<noteq> 0}` `finite {x. \\<tau> x \\<noteq> 0}` `finite {x. \\<tau>' x \\<noteq> 0}`\n    proof (induction rule:b_seq_exec.induct)\n      case (1 t \\<sigma> \\<gamma> \\<theta> def \\<tau>)\n      then show ?case by (auto intro!: seq_exec_ind.intros)\n    next\n      case (2 t \\<sigma> \\<gamma> \\<theta> def ss1 \\<tau> \\<tau>'' ss2 \\<tau>')\n      hence \"finite {x. \\<tau>'' x \\<noteq> 0}\"\n        using b_seq_exec_almost_all_zero[OF 2(1)]  by (simp add: eventually_cofinite)\n      hence \"seq_exec_ind t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def ss1 (Abs_poly_mapping \\<tau>) (Abs_poly_mapping \\<tau>'')\"\n        using 2(3)[OF 2(5-6)] by auto\n      moreover have \" seq_exec_ind t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def ss2 (Abs_poly_mapping \\<tau>'') (Abs_poly_mapping \\<tau>')\"\n        using 2(4)[OF 2(5) `finite {x. \\<tau>'' x \\<noteq> 0}` 2(7)] by auto\n      ultimately show ?case\n        by (auto intro!: seq_exec_ind.intros)\n    next\n      case (3 t \\<sigma> \\<gamma> \\<theta> def guard ss1 \\<tau> \\<tau>' ss2)\n      hence \"finite {x. \\<tau>' x \\<noteq> 0}\"\n        using b_seq_exec_almost_all_zero  by blast\n      moreover have \"beval t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def guard (Bv True)\"\n        using 3(1) unfolding beval.rep_eq lookup_Abs_poly_mapping[OF `finite {x. \\<theta> x \\<noteq> 0}`]\n        by auto\n      ultimately show ?case\n        by (simp add: beval_eq_beval_ind \"3.IH\" \"3.prems\"(1) \"3.prems\"(2) seq_exec_ind.intros(3))\n    next\n      case (4 t \\<sigma> \\<gamma> \\<theta> def guard ss2 \\<tau> \\<tau>' ss1)\n      hence \"finite {x. \\<tau>' x \\<noteq> 0}\"\n        using b_seq_exec_almost_all_zero  by blast\n      moreover have \"beval t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def guard (Bv False)\"\n        using 4(1) unfolding beval.rep_eq lookup_Abs_poly_mapping[OF `finite {x. \\<theta> x \\<noteq> 0}`]\n        by auto\n      ultimately show ?case\n        by (simp add: beval_eq_beval_ind \"4.IH\" \"4.prems\"(1) \"4.prems\"(2) seq_exec_ind.intros(4))\n    next\n      case (5 t \\<sigma> \\<gamma> \\<theta> def e x sig \\<tau> dly \\<tau>')\n      have \"beval t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def e x\"\n        using 5(1) unfolding beval.rep_eq lookup_Abs_poly_mapping[OF `finite {x. \\<theta> x \\<noteq> 0}`]\n        by auto\n      have \"lookup (trans_post sig x (\\<sigma> sig) (Abs_poly_mapping \\<tau>) t dly) = lookup (Abs_poly_mapping \\<tau>')\"\n        using 5(2) unfolding trans_post.rep_eq lookup_Abs_poly_mapping[OF `finite {x. \\<tau> x \\<noteq> 0}`]\n        lookup_Abs_poly_mapping[OF `finite {x. \\<tau>' x \\<noteq> 0}`] by auto\n      hence \"trans_post sig x (\\<sigma> sig) (Abs_poly_mapping \\<tau>) t dly = Abs_poly_mapping \\<tau>'\"\n        unfolding lookup_inject by auto\n      then show ?case\n        using `beval t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def e x`\n        by (simp add: beval_eq_beval_ind seq_exec_ind.intros(5))\n    next\n      case (6 t \\<sigma> \\<gamma> \\<theta> def e x sig \\<tau> dly \\<tau>')\n      have \"beval t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def e x\"\n        using 6(1) unfolding beval.rep_eq lookup_Abs_poly_mapping[OF `finite {x. \\<theta> x \\<noteq> 0}`]\n        by auto\n      have \"lookup (inr_post sig x (\\<sigma> sig) (Abs_poly_mapping \\<tau>) t dly) = lookup (Abs_poly_mapping \\<tau>')\"\n        using 6(2) unfolding inr_post.rep_eq  lookup_Abs_poly_mapping[OF `finite {x. \\<tau> x \\<noteq> 0}`]\n        lookup_Abs_poly_mapping[OF `finite {x. \\<tau>' x \\<noteq> 0}`] by auto\n      hence \"inr_post sig x (\\<sigma> sig) (Abs_poly_mapping \\<tau>) t dly = Abs_poly_mapping \\<tau>'\"\n        unfolding lookup_inject by auto\n      then show ?case\n        using `beval t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def e x`\n        by (auto simp add: seq_exec_ind.intros(6) beval_eq_beval_ind)\n    next\n      case (7 t \\<sigma> \\<gamma> \\<theta> def exp x exp' ss \\<tau> \\<tau>' choices)\n      have \"beval_ind t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def exp x\"\n        by (metis (mono_tags, lifting) \"7.hyps\"(1) \"7.prems\"(1) beval.abs_eq beval_eq_beval_ind\n        eq_onp_same_args)\n      moreover have \"beval_ind t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def exp' x\"\n        by (metis \"7.hyps\"(2) \"7.prems\"(1) beval.rep_eq beval_eq_beval_ind lookup_Abs_poly_mapping)\n      moreover have \" seq_exec_ind t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def ss (Abs_poly_mapping \\<tau>) (Abs_poly_mapping \\<tau>')\"\n        using 7 by auto\n      ultimately show ?case\n        by (intro seq_exec_ind.intros) auto\n    next\n      case (8 t \\<sigma> \\<gamma> \\<theta> def exp x exp' x' choices \\<tau> \\<tau>' ss)\n      have \"beval_ind t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def exp x\"\n        by (metis (mono_tags, lifting) \"8.hyps\"(1) \"8.prems\"(1) beval.abs_eq beval_eq_beval_ind\n        eq_onp_same_args)\n      moreover have \"beval_ind t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def exp' x'\"\n        by (metis (mono_tags) \"8.hyps\"(2) \"8.prems\"(1) beval.rep_eq beval_eq_beval_ind\n        lookup_Abs_poly_mapping)\n      moreover have \"seq_exec_ind t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def (Bcase exp choices) (Abs_poly_mapping \\<tau>) (Abs_poly_mapping \\<tau>')\"\n        using 8 by auto\n      ultimately show ?case\n        using 8(3) by (intro seq_exec_ind.intros(8)) auto\n    qed (auto simp add: seq_exec_ind.intros)\n  qed\n  thus \"seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>'\"\n    unfolding lookup_inverse by auto\nnext\n  assume \"seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>'\"\n  thus \"seq_exec t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>'\"\n    unfolding seq_exec.rep_eq\n  proof (induction rule:seq_exec_ind.inducts)\n    case (3 t \\<sigma> \\<gamma> \\<theta> def guard ss1 \\<tau> \\<tau>' ss2)\n    have \"beval_raw t \\<sigma> \\<gamma> (lookup \\<theta>) def guard (Bv True)\"\n      using 3(1) unfolding sym[OF beval_eq_beval_ind]\n      by transfer' auto\n    then show ?case\n      using 3(3)  by (simp add: b_seq_exec.intros(3))\n  next\n    case (4 t \\<sigma> \\<gamma> \\<theta> def guard ss2 \\<tau> \\<tau>' ss1)\n    have \"beval_raw t \\<sigma> \\<gamma> (lookup \\<theta>) def guard (Bv False)\"\n      using 4(1) unfolding sym[OF beval_eq_beval_ind] by transfer' auto\n    then show ?case\n      using 4(3)  by (simp add: b_seq_exec.intros(4))\n  next\n    case (5 t \\<sigma> \\<gamma> \\<theta> def e x sig \\<tau> dly \\<tau>')\n    have \"beval_raw t \\<sigma> \\<gamma> (lookup \\<theta>) def e x\"\n      using 5(1) unfolding sym[OF beval_eq_beval_ind] by transfer' auto\n    have \"trans_post_raw sig x (\\<sigma> sig) (lookup \\<tau>) t dly = lookup \\<tau>'\"\n      using 5(2) by transfer' auto\n    then show ?case\n      by (metis \\<open>t , \\<sigma> , \\<gamma> , lookup \\<theta>, def \\<turnstile> e \\<longrightarrow>\\<^sub>b x\\<close> b_seq_exec.intros(5))\n  next\n    case (6 t \\<sigma> \\<gamma> \\<theta> def e x sig \\<tau> dly \\<tau>')\n    have \"beval_raw t \\<sigma> \\<gamma> (lookup \\<theta>) def e x\"\n      using 6(1) unfolding sym[OF beval_eq_beval_ind] by transfer' auto\n    have \"inr_post_raw' sig x (\\<sigma> sig) (lookup \\<tau>) t dly = lookup \\<tau>'\"\n      using 6(2) by transfer' auto\n    then show ?case\n      by (metis \\<open>t , \\<sigma> , \\<gamma> , lookup \\<theta>, def \\<turnstile> e \\<longrightarrow>\\<^sub>b x\\<close> b_seq_exec.intros(6))\n  next\n    case (7 t \\<sigma> \\<gamma> \\<theta> def exp x exp' ss \\<tau> \\<tau>' choices)\n    have \"t, \\<sigma> , \\<gamma> , lookup \\<theta> , def \\<turnstile> exp \\<longrightarrow>\\<^sub>b x\"\n      by (metis \"7.hyps\"(1) beval.rep_eq beval_eq_beval_ind)\n    moreover have \"t, \\<sigma> , \\<gamma> , lookup \\<theta> , def \\<turnstile> exp' \\<longrightarrow>\\<^sub>b x\"\n      by (metis \"7.hyps\"(2) beval.rep_eq beval_eq_beval_ind)\n    moreover have \"b_seq_exec t \\<sigma> \\<gamma> (lookup \\<theta>) def ss (lookup \\<tau>) (lookup \\<tau>')\"\n      using 7(3)  by (simp add: \"7.IH\")\n    ultimately show ?case\n      by (intro b_seq_exec.intros) auto\n  next\n    case (8 t \\<sigma> \\<gamma> \\<theta> def exp x exp' x' choices \\<tau> \\<tau>' ss)\n    have \"t, \\<sigma> , \\<gamma> , lookup \\<theta> , def \\<turnstile> exp \\<longrightarrow>\\<^sub>b x\"\n      by (metis \"8.hyps\"(1) beval.rep_eq beval_eq_beval_ind)\n    moreover have \"t, \\<sigma> , \\<gamma> , lookup \\<theta> , def \\<turnstile> exp' \\<longrightarrow>\\<^sub>b x'\"\n      by (metis \"8.hyps\"(2) beval.rep_eq beval_eq_beval_ind)\n    moreover have \"b_seq_exec t \\<sigma> \\<gamma> (lookup \\<theta>) def (Bcase exp choices) (lookup \\<tau>) (lookup \\<tau>')\"\n      using 8 by auto\n    ultimately show ?case\n      using 8(3) by (intro b_seq_exec.intros(8)) auto\n  qed (auto intro!: b_seq_exec.intros)\nqed\n\nlemma seq_exec_ind_deterministic:\n  assumes \"seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>1\"\n  assumes \"seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>2\"\n  shows \"\\<tau>2 = \\<tau>1\"\n  using assms unfolding sym[OF seq_exec_eq_seq_exec_ind]\n  by transfer' (auto simp add: b_seq_exec_deterministic)\n\nlemma seq_exec_ind_progress:\n  assumes \"seq_wt \\<Gamma> ss\" and \"styping \\<Gamma> \\<sigma>\" and \"transtyping \\<Gamma> \\<theta>\" and \"styping \\<Gamma> def\" and \"transtyping \\<Gamma> \\<tau>\"\n  shows \"\\<exists>\\<tau>'. seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def ss \\<tau> \\<tau>'\"\n  unfolding sym[OF seq_exec_eq_seq_exec_ind] using assms\nproof transfer\n  fix \\<Gamma> :: \"'a tyenv\"\n  fix ss \\<sigma>\n  fix \\<theta> \\<tau> :: \"nat \\<Rightarrow> 'a \\<rightharpoonup> val\"\n  fix def t \\<gamma>\n  assume \"seq_wt \\<Gamma> ss\"\n  assume \"styping \\<Gamma> \\<sigma>\"\n  assume \"finite {x. \\<theta> x \\<noteq> 0}\"\n  assume \"ttyping \\<Gamma> \\<theta>\"\n  assume \"styping \\<Gamma> def\"\n  assume \"finite {x. \\<tau> x \\<noteq> 0}\"\n  assume \"ttyping \\<Gamma> \\<tau>\"\n  hence \"\\<exists>\\<tau>'. t, \\<sigma>, \\<gamma>, \\<theta>, def \\<turnstile> < ss, \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\"\n    using seq_stmts_progress[OF `seq_wt \\<Gamma> ss` `styping \\<Gamma> \\<sigma>` `ttyping \\<Gamma> \\<theta>` `styping \\<Gamma> def` `ttyping \\<Gamma> \\<tau>`]\n    by auto\n  then obtain \\<tau>' where \"t, \\<sigma>, \\<gamma>, \\<theta>, def \\<turnstile> < ss, \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\"\n    by auto\n  hence \"finite {x. \\<tau>' x \\<noteq> 0}\"\n    using b_seq_exec_almost_all_zero\n    by (metis (mono_tags) \\<open>finite {x. \\<tau> x \\<noteq> 0}\\<close> \\<open>finite {x. \\<theta> x \\<noteq> 0}\\<close> eventually_cofinite map_diff_fin_variability)\n  thus \"Bex {f. finite {x. f x \\<noteq> 0}} (b_seq_exec t \\<sigma> \\<gamma> \\<theta> def ss \\<tau>)\"\n    using \\<open>t , \\<sigma> , \\<gamma> , \\<theta> , def \\<turnstile> < ss , \\<tau>> \\<longrightarrow>\\<^sub>s \\<tau>'\\<close> by blast\nqed\n\nlemma seq_exec_ind_unique_progress:\n  assumes \"seq_wt \\<Gamma> ss\" and \"styping \\<Gamma> \\<sigma>\" and \"transtyping \\<Gamma> \\<theta>\" and \"styping \\<Gamma> def\" and \"transtyping \\<Gamma> \\<tau>\"\n  shows \"\\<exists>!\\<tau>'. seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def ss \\<tau> \\<tau>'\"\n  using assms\n  by (auto simp add: seq_exec_ind_progress  seq_exec_ind_deterministic)\n\nlift_definition map_diff_trans :: \"'signal transaction \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal transaction\"\n  is map_diff_trans_raw unfolding sym[OF eventually_cofinite]\n  by (simp add: map_diff_fin_variability)\n\nlift_definition map_add_trans :: \"'signal transaction \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal transaction\"\n  is \"\\<lambda>\\<tau>1 \\<tau>2 n. map_add (\\<tau>1 n) (\\<tau>2 n)\" unfolding sym[OF eventually_cofinite]\n  by (simp add: map_add_fin_variability)\n\nlemma dom_map_diff_trans_post:\n  \"dom (lookup (map_diff_trans (trans_post sig x def \\<tau> t dly) \\<tau>) n)  \\<subseteq> {sig}\"\n  by (transfer', simp add: dom_map_diff_trans_post)\n\nlemma dom_map_diff_purge:\n  \"\\<And>n. dom (lookup (map_diff_trans (purge \\<tau> t dly sig def val) \\<tau>) n) \\<subseteq> {sig}\"\n  by (transfer', simp add: dom_map_diff_purge)\n\nlift_definition clean_zip ::\n  \"'signal transaction \\<Rightarrow> 'signal transaction \\<times> 'signal set \\<Rightarrow>  'signal transaction \\<times> 'signal set \\<Rightarrow>\n                                                                                'signal transaction\"\n  is clean_zip_raw unfolding sym[OF eventually_cofinite]\nproof (auto split:prod.splits)\n  fix f x1 x1a:: \"nat \\<Rightarrow> 'signal \\<Rightarrow> val option\"\n  fix x2 x2a\n  assume assm1: \"\\<forall>\\<^sub>\\<infinity>x. f x = 0\"\n  assume assm2: \"\\<forall>\\<^sub>\\<infinity>x. x1 x = 0\"\n  assume assm3: \"\\<forall>\\<^sub>\\<infinity>x. x1a x = 0\"\n  thus \"\\<forall>\\<^sub>\\<infinity>x. clean_zip_raw f (x1, x2) (x1a, x2a) x = 0\"\n    using clean_zip_raw_almost_all_zero[OF assm1 assm2 assm3] by auto\nqed\n\nlift_definition conc_exec :: \"nat \\<Rightarrow> 'signal state \\<Rightarrow> 'signal event \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal state \\<Rightarrow>\n                             'signal conc_stmt \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal transaction \\<Rightarrow> bool\" is\n  b_conc_exec .\n\ndeclare conc_exec.rep_eq[code_abbrev]\n\ninductive conc_exec_ind :: \"nat \\<Rightarrow> 'signal state \\<Rightarrow> 'signal event \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal state \\<Rightarrow>\n                             'signal conc_stmt \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal transaction \\<Rightarrow> bool\"\n  where\n  \"disjnt sl \\<gamma> \\<Longrightarrow> conc_exec_ind t \\<sigma> \\<gamma> \\<theta> def (process sl : ss) \\<tau> \\<tau>\"\n\n| \"seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def ss \\<tau> \\<tau>' \\<Longrightarrow> \\<not> disjnt sl \\<gamma> \\<Longrightarrow>\n                                                     conc_exec_ind t \\<sigma> \\<gamma> \\<theta> def (process sl : ss) \\<tau> \\<tau>'\"\n\n| \"conc_exec_ind t \\<sigma> \\<gamma> \\<theta> def cs1 \\<tau> \\<tau>1 \\<Longrightarrow> conc_exec_ind t \\<sigma> \\<gamma> \\<theta> def cs2 \\<tau> \\<tau>2 \\<Longrightarrow>\n    clean_zip \\<tau> (\\<tau>1, set (signals_from cs1)) (\\<tau>2, set (signals_from cs2)) = \\<tau>'\n                                                      \\<Longrightarrow> conc_exec_ind t \\<sigma> \\<gamma> \\<theta> def (cs1 || cs2) \\<tau> \\<tau>'\"\n\nlemma conc_exec_eq_conc_exec_ind:\n  \"conc_exec t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>' = conc_exec_ind t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>'\"\nproof\n  assume \"conc_exec t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>'\"\n  hence \"conc_exec_ind t \\<sigma> \\<gamma> (Abs_poly_mapping (lookup \\<theta>)) def cs (Abs_poly_mapping (lookup \\<tau>)) (Abs_poly_mapping (lookup \\<tau>'))\"\n  proof transfer\n    fix t \\<sigma> \\<gamma>\n    fix \\<theta> \\<tau> \\<tau>':: \"nat \\<Rightarrow> 'a \\<Rightarrow> val option\"\n    fix def cs\n    assume 1: \"finite {x. \\<theta> x \\<noteq> 0}\"\n    assume 2: \"finite {x. \\<tau> x \\<noteq> 0}\"\n    assume 3: \"finite {x. \\<tau>' x \\<noteq> 0}\"\n    assume \"t, \\<sigma>, \\<gamma>, \\<theta>, def \\<turnstile> <cs, \\<tau>> \\<longrightarrow>\\<^sub>c \\<tau>'\"\n    thus \"conc_exec_ind t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def cs (Abs_poly_mapping \\<tau>) (Abs_poly_mapping \\<tau>')\"\n      using 1 2 3\n    proof (induction rule: b_conc_exec.inducts)\n      case (1 sl \\<gamma> t \\<sigma> \\<theta> def ss \\<tau>)\n      then show ?case by (auto intro!: conc_exec_ind.intros)\n    next\n      case (2 t \\<sigma> \\<gamma> \\<theta> def ss \\<tau> \\<tau>' sl)\n      have \"seq_exec t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def ss (Abs_poly_mapping \\<tau>) (Abs_poly_mapping \\<tau>')\"\n        using 2(1) unfolding seq_exec.rep_eq lookup_Abs_poly_mapping[OF `finite {x. \\<theta> x \\<noteq> 0}`]\n        lookup_Abs_poly_mapping[OF `finite {x. \\<tau> x \\<noteq> 0}`] lookup_Abs_poly_mapping[OF `finite {x. \\<tau>' x \\<noteq> 0}`]\n        by auto\n      then show ?case\n        using 2(2) unfolding seq_exec_eq_seq_exec_ind\n        by (auto intro!: conc_exec_ind.intros)\n    next\n      case (3 t \\<sigma> \\<gamma> \\<theta> def cs1 \\<tau> \\<tau>1 cs2 \\<tau>2 \\<tau>')\n      hence \"finite {x. \\<tau>1 x \\<noteq> 0}\" and \"finite {x. \\<tau>2 x \\<noteq> 0}\"\n        using b_conc_exec_almost_all_zero by blast+\n      hence \" conc_exec_ind t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def cs1 (Abs_poly_mapping \\<tau>) (Abs_poly_mapping \\<tau>1)\"\n        and \" conc_exec_ind t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def cs2 (Abs_poly_mapping \\<tau>) (Abs_poly_mapping \\<tau>2)\"\n        using 3 by blast+\n      have \"lookup (clean_zip (Abs_poly_mapping \\<tau>) (Abs_poly_mapping \\<tau>1, set (signals_from cs1)) (Abs_poly_mapping \\<tau>2, set (signals_from cs2))) =\n            lookup (Abs_poly_mapping \\<tau>')\"\n        using 3(3) unfolding clean_zip.rep_eq lookup_Abs_poly_mapping[OF `finite {x. \\<tau> x \\<noteq> 0}`]\n        lookup_Abs_poly_mapping[OF `finite {x. \\<tau>' x \\<noteq> 0}`]\n        by (simp add: \\<open>finite {x. \\<tau>1 x \\<noteq> 0}\\<close> \\<open>finite {x. \\<tau>2 x \\<noteq> 0}\\<close>)\n      hence \"clean_zip (Abs_poly_mapping \\<tau>) (Abs_poly_mapping \\<tau>1, set (signals_from cs1)) (Abs_poly_mapping \\<tau>2, set (signals_from cs2)) =\n             Abs_poly_mapping \\<tau>'\"\n        unfolding lookup_inject by auto\n      then show ?case\n        using \\<open>conc_exec_ind t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def cs1 (Abs_poly_mapping \\<tau>)\n        (Abs_poly_mapping \\<tau>1)\\<close> \\<open>conc_exec_ind t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def cs2 (Abs_poly_mapping\n        \\<tau>) (Abs_poly_mapping \\<tau>2)\\<close> conc_exec_ind.intros(3) by blast\n    qed\n  qed\n  thus \"conc_exec_ind t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>'\"\n    unfolding lookup_inverse by auto\nnext\n  assume \"conc_exec_ind t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>'\"\n  thus \"conc_exec t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>'\"\n    unfolding conc_exec.rep_eq\n  proof (induction rule: conc_exec_ind.inducts)\n    case (1 sl \\<gamma> t \\<sigma> \\<theta> def ss \\<tau>)\n    then show ?case by transfer' (auto intro!: b_conc_exec.intros)\n  next\n    case (2 t \\<sigma> \\<gamma> \\<theta> def ss \\<tau> \\<tau>' sl)\n    then show ?case\n      unfolding sym[OF seq_exec_eq_seq_exec_ind] by transfer' (auto intro!: b_conc_exec.intros)\n  next\n    case (3 t \\<sigma> \\<gamma> \\<theta> def cs1 \\<tau> \\<tau>1 cs2 \\<tau>2 \\<tau>')\n    hence \"b_conc_exec t \\<sigma> \\<gamma> (lookup \\<theta>) def cs1 (lookup \\<tau>) (lookup \\<tau>1)\" and\n          \"b_conc_exec t \\<sigma> \\<gamma> (lookup \\<theta>) def cs2 (lookup \\<tau>) (lookup \\<tau>2)\"\n      using 3(1-2) by (transfer', auto)+\n    then show ?case\n      by (metis \"3.hyps\"(3) b_conc_exec.intros(3) clean_zip.rep_eq id_apply map_prod_simp)\n  qed\nqed\n\nlemma conc_exec_ind_deterministic:\n  assumes \"conc_exec_ind t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>1\"\n  assumes \"conc_exec_ind t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>2\"\n  shows \"\\<tau>2 = \\<tau>1\"\n  using assms unfolding sym[OF conc_exec_eq_conc_exec_ind]\n  by transfer' (simp add: b_conc_exec_deterministic)\n\nlemma conc_exec_ind_progress:\n  assumes \"conc_wt \\<Gamma> cs\" and \"styping \\<Gamma> \\<sigma>\" and \"transtyping \\<Gamma> \\<theta>\" and \"styping \\<Gamma> def\" and \"transtyping \\<Gamma> \\<tau>\"\n  shows \"\\<exists>\\<tau>'. conc_exec_ind t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>'\"\n  unfolding sym[OF conc_exec_eq_conc_exec_ind] using assms\nproof transfer\n  fix \\<Gamma> :: \"'a tyenv\"\n  fix cs \\<sigma>\n  fix \\<theta> \\<tau> :: \"nat \\<Rightarrow> 'a \\<rightharpoonup> val\"\n  fix def t \\<gamma>\n  assume 1: \"conc_wt \\<Gamma> cs\"\n  assume 2: \"styping \\<Gamma> \\<sigma>\"\n  assume 3: \"finite {x. \\<theta> x \\<noteq> 0}\"\n  assume 4: \"ttyping \\<Gamma> \\<theta>\"\n  assume 5: \"styping \\<Gamma> def\"\n  assume 6: \"finite {x. \\<tau> x \\<noteq> 0}\"\n  assume 7: \"ttyping \\<Gamma> \\<tau>\"\n  then obtain \\<tau>' where \"t, \\<sigma>, \\<gamma>, \\<theta>, def \\<turnstile> <cs, \\<tau>> \\<longrightarrow>\\<^sub>c \\<tau>'\"\n    using conc_stmts_progress[OF 1 2 4 5 7] by blast\n  moreover hence \"finite {x. \\<tau>' x \\<noteq> 0}\"\n    using b_conc_exec_almost_all_zero 3 6 by blast\n  ultimately show \" Bex {f. finite {x. f x \\<noteq> 0}} (b_conc_exec t \\<sigma> \\<gamma> \\<theta> def cs \\<tau>)\"\n    by auto\nqed\n\nlemma conc_exec_ind_unique_progress:\n  assumes \"conc_wt \\<Gamma> cs\" and \"styping \\<Gamma> \\<sigma>\" and \"transtyping \\<Gamma> \\<theta>\" and \"styping \\<Gamma> def\" and \"transtyping \\<Gamma> \\<tau>\"\n  shows \"\\<exists>!\\<tau>'. conc_exec_ind t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>'\"\n  using assms conc_exec_ind_deterministic conc_exec_ind_progress\n  by auto\n\nlift_definition init' :: \"nat \\<Rightarrow> 'signal state \\<Rightarrow> 'signal event \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal state \\<Rightarrow>\n                                 'signal conc_stmt \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal transaction \\<Rightarrow> bool\"\n  is Femto_VHDL_raw.init' .\n\ninductive init'_ind :: \"nat \\<Rightarrow> 'signal state \\<Rightarrow> 'signal event \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal state \\<Rightarrow>\n                                 'signal conc_stmt \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal transaction \\<Rightarrow> bool\" where\n  \"seq_exec_ind t \\<sigma> \\<gamma> \\<theta> def ss \\<tau> \\<tau>' \\<Longrightarrow> init'_ind t \\<sigma> \\<gamma> \\<theta> def (process sl : ss) \\<tau> \\<tau>'\"\n| \"init'_ind t \\<sigma> \\<gamma> \\<theta> def cs1 \\<tau> \\<tau>1 \\<Longrightarrow> init'_ind t \\<sigma> \\<gamma> \\<theta> def cs2 \\<tau> \\<tau>2 \\<Longrightarrow>\n    clean_zip \\<tau> (\\<tau>1, set (signals_from cs1)) (\\<tau>2, set (signals_from cs2)) = \\<tau>'\n                                                      \\<Longrightarrow> init'_ind t \\<sigma> \\<gamma> \\<theta> def (cs1 || cs2) \\<tau> \\<tau>'\"\n\nlemma init'_eq_init'_ind:\n  \"init' t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>' = init'_ind t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>'\"\nproof\n  assume \"init' t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>'\"\n  hence \"init'_ind t \\<sigma> \\<gamma> (Abs_poly_mapping (lookup \\<theta>)) def cs (Abs_poly_mapping (lookup \\<tau>)) (Abs_poly_mapping (lookup \\<tau>'))\"\n  proof transfer\n    fix t \\<sigma> \\<gamma>\n    fix \\<theta> \\<tau> \\<tau>' :: \"nat \\<Rightarrow> 'a \\<rightharpoonup> val\"\n    fix def cs\n    assume 1: \"finite {x. \\<theta> x \\<noteq> 0}\"\n    assume 2: \"finite {x. \\<tau> x \\<noteq> 0}\"\n    assume 3: \"finite {x. \\<tau>' x \\<noteq> 0}\"\n    assume \"Femto_VHDL_raw.init' t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>' \"\n    thus \"init'_ind t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def cs (Abs_poly_mapping \\<tau>) (Abs_poly_mapping \\<tau>')\"\n      using 1 2 3\n    proof (induction rule:Femto_VHDL_raw.init'.inducts)\n      case (1 t \\<sigma> \\<gamma> \\<theta> def ss \\<tau> \\<tau>' sl)\n      have \" seq_exec t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def ss (Abs_poly_mapping \\<tau>) (Abs_poly_mapping \\<tau>')\"\n        using 1  by (simp add: seq_exec.rep_eq)\n      then show ?case\n        unfolding seq_exec_eq_seq_exec_ind\n        by (simp add: init'_ind.intros(1))\n    next\n      case (2 t \\<sigma> \\<gamma> \\<theta> def cs1 \\<tau> \\<tau>1 cs2 \\<tau>2 \\<tau>')\n      hence \"finite {x. \\<tau>1 x \\<noteq> 0}\" and \"finite {x. \\<tau>2 x \\<noteq> 0}\"\n        using init'_raw_almost_all_zero by blast+\n      hence \"init'_ind t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def cs1 (Abs_poly_mapping \\<tau>) (Abs_poly_mapping \\<tau>1)\"\n        and \"init'_ind t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def cs2 (Abs_poly_mapping \\<tau>) (Abs_poly_mapping \\<tau>2)\"\n        using 2 by auto\n      have \"lookup (clean_zip (Abs_poly_mapping \\<tau>) (Abs_poly_mapping \\<tau>1, set (signals_from cs1)) (Abs_poly_mapping \\<tau>2, set (signals_from cs2))) =\n             lookup (Abs_poly_mapping \\<tau>')\"\n        using 2(3) unfolding clean_zip.rep_eq lookup_Abs_poly_mapping[OF `finite {x. \\<tau> x \\<noteq> 0}`]\n        lookup_Abs_poly_mapping[OF `finite {x. \\<tau>' x \\<noteq> 0}`]\n        by (simp add: \\<open>finite {x. \\<tau>1 x \\<noteq> 0}\\<close> \\<open>finite {x. \\<tau>2 x \\<noteq> 0}\\<close>)\n      hence \"clean_zip (Abs_poly_mapping \\<tau>) (Abs_poly_mapping \\<tau>1, set (signals_from cs1)) (Abs_poly_mapping \\<tau>2, set (signals_from cs2)) = Abs_poly_mapping \\<tau>'\"\n        unfolding lookup_inject by auto\n      then show ?case\n        using \\<open>init'_ind t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def cs1 (Abs_poly_mapping \\<tau>) (Abs_poly_mapping\n        \\<tau>1)\\<close> \\<open>init'_ind t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def cs2 (Abs_poly_mapping \\<tau>) (Abs_poly_mapping\n        \\<tau>2)\\<close> init'_ind.intros(2) by blast\n    qed\n  qed\n  thus \"init'_ind t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>'\"\n    unfolding lookup_inverse by auto\nnext\n  assume \"init'_ind t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>'\"\n  thus \"init' t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>'\"\n    unfolding init'.rep_eq\n  proof (induction rule: init'_ind.inducts)\n    case (1 t \\<sigma> \\<gamma> \\<theta> def ss \\<tau> \\<tau>' sl)\n    then show ?case\n      unfolding sym[OF seq_exec_eq_seq_exec_ind]\n      by (transfer', auto intro!: Femto_VHDL_raw.init'.intros)\n  next\n    case (2 t \\<sigma> \\<gamma> \\<theta> def cs1 \\<tau> \\<tau>1 cs2 \\<tau>2 \\<tau>')\n    have \"clean_zip_raw (lookup \\<tau>) (lookup \\<tau>1, set (signals_from cs1)) (lookup \\<tau>2, set (signals_from cs2)) = lookup \\<tau>'\"\n      using 2(3) by transfer' auto\n    then show ?case\n      using \"2.IH\"(1) \"2.IH\"(2) init'.intros(2) by blast\n  qed\nqed\n\ndefinition rem_curr_trans :: \"nat \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal transaction\" where\n  \"rem_curr_trans t \\<tau> = Poly_Mapping.update t 0 \\<tau>\"\n\nsubsection \\<open>Semantics of simulation\\<close>\n\nlift_definition next_time :: \"nat \\<Rightarrow> 'signal transaction \\<Rightarrow> nat\"\n  is Femto_VHDL_raw.next_time .\n\ndeclare next_time.rep_eq[code_abbrev]\n\nlift_definition quiet :: \"'signal transaction \\<Rightarrow> 'signal event \\<Rightarrow> bool\"\n  is Femto_VHDL_raw.quiet .\n\ndeclare quiet.rep_eq[code_abbrev]\n\nlemma [code]:\n  \"quiet \\<tau> \\<gamma> = (if \\<tau> = 0 \\<and> \\<gamma> = {} then True else False)\"\n  by (transfer', auto simp add: Femto_VHDL_raw.quiet_def zero_fun_def zero_option_def)\n\nlift_definition next_state :: \"nat \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal state \\<Rightarrow> 'signal state\"\n  is Femto_VHDL_raw.next_state .\n\ndeclare next_state.rep_eq[code_abbrev]\n\nlemma [code]:\n  \"next_state t \\<tau>' \\<sigma> = (let m = lookup \\<tau>' (next_time t \\<tau>') in override_on \\<sigma> (the o m) (dom m))\"\n  by (transfer', auto simp add: Femto_VHDL_raw.next_state_def)\n\nlift_definition next_event :: \"nat \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal state \\<Rightarrow> 'signal event\"\n  is Femto_VHDL_raw.next_event .\n\ndeclare next_event.rep_eq[code_abbrev]\n\nlemma [code]:\n  \"next_event t \\<tau>' \\<sigma> = (let m = lookup \\<tau>' (next_time t \\<tau>') in\n                                       {sig. if sig \\<in> dom m then (the o m) sig \\<noteq> \\<sigma> sig else False})\"\n  by (transfer', auto simp add: Femto_VHDL_raw.next_event_def Let_def)\n\nlift_definition add_to_beh ::\n  \"'signal state \\<Rightarrow> 'signal transaction \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> 'signal transaction\"\n  is Femto_VHDL_raw.add_to_beh unfolding add_to_beh_def sym[OF eventually_cofinite]\n  by (metis (mono_tags) upd_eventually_cofinite)\n\nlemma [code]:\n  \"add_to_beh \\<sigma> \\<theta> st fi = (if st < fi then Poly_Mapping.update st (Some o \\<sigma>) \\<theta> else \\<theta>)\"\n  by (transfer', auto simp add: Femto_VHDL_raw.add_to_beh_def)\n\nlift_definition simulate_fin ::  \"nat \\<Rightarrow> nat \\<Rightarrow> 'a  state \\<Rightarrow> 'a event \\<Rightarrow> 'a transaction \\<Rightarrow> 'a state \\<Rightarrow>\n                                            'a conc_stmt \\<Rightarrow> 'a transaction \\<Rightarrow> nat \\<times> 'a state \\<times> 'a transaction \\<times> 'a transaction \\<Rightarrow> bool\"\n  is b_simulate_fin .\n\ninductive simulate_fin_ind :: \"nat \\<Rightarrow> nat \\<Rightarrow> 'signal  state \\<Rightarrow> 'signal event \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal state \\<Rightarrow>\n                            'signal conc_stmt \\<Rightarrow> 'signal transaction \\<Rightarrow> nat \\<times> 'signal state \\<times> 'signal transaction \\<times> 'signal transaction \\<Rightarrow> bool\"\n  where\n\n  \\<comment> \\<open>Business as usual: not quiesced yet and there is still time\\<close>\n  \"    (t < maxtime)\n   \\<Longrightarrow> (\\<not> quiet \\<tau> \\<gamma>)\n   \\<Longrightarrow> (conc_exec_ind t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>')\n   \\<Longrightarrow> next_time t \\<tau>' \\<le> maxtime\n   \\<Longrightarrow> simulate_fin_ind\n          maxtime\n             (next_time t \\<tau>')\n                (next_state t \\<tau>' \\<sigma>)\n                    (next_event t \\<tau>' \\<sigma>)\n                        (add_to_beh \\<sigma> \\<theta> t (next_time t \\<tau>')) def cs (rem_curr_trans (next_time t \\<tau>') \\<tau>') res\n   \\<Longrightarrow> simulate_fin_ind maxtime t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> res\"\n\n  \\<comment> \\<open>Business as usual: not quiesced yet and there is still time --- case 2\\<close>\n| \"    (t < maxtime)\n   \\<Longrightarrow> (\\<not> quiet \\<tau> \\<gamma>)\n   \\<Longrightarrow> (conc_exec_ind t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> \\<tau>')\n   \\<Longrightarrow> (maxtime < next_time t \\<tau>')\n   \\<Longrightarrow> simulate_fin_ind maxtime t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> (maxtime, \\<sigma>, Poly_Mapping.update t (Some o \\<sigma>) \\<theta>, \\<tau>')\"\n\n  \\<comment> \\<open>The simulation has quiesced and there is still time\\<close>\n| \"    (t < maxtime)\n   \\<Longrightarrow> (quiet \\<tau> \\<gamma>)\n   \\<Longrightarrow> simulate_fin_ind maxtime t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> (maxtime, \\<sigma>, Poly_Mapping.update t (Some o \\<sigma>) \\<theta>, 0)\"\n\n  \\<comment> \\<open>Time is up\\<close>\n| \"  t = maxtime\n   \\<Longrightarrow> simulate_fin_ind maxtime t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> (maxtime, \\<sigma>, \\<theta>, \\<tau>)\"\n\nthm b_simulate_fin_deterministic\n\nlemma simulate_fin_deterministic:\n  assumes \"simulate_fin maxtime t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> res1\"\n  assumes \"simulate_fin maxtime t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> res2\"\n  shows \"res2 = res1\"\n  using assms\n  by (transfer', auto simp add: b_simulate_fin_deterministic)\n\ninductive_cases bau2: \"simulate_fin_ind maxtime t \\<sigma> \\<gamma> def \\<theta> cs \\<tau> res\"\n\nlemma simulate_fin_eq_simulate_fin_ind:\n  \"simulate_fin maxtime t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> res = simulate_fin_ind maxtime t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> res\"\nproof\n  assume \"simulate_fin maxtime t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> res\"\n  hence \"simulate_fin_ind maxtime t \\<sigma> \\<gamma> (Abs_poly_mapping (lookup \\<theta>)) def cs (Abs_poly_mapping (lookup \\<tau>))\n         (get_time res, get_state res, (Abs_poly_mapping (lookup (get_beh res))), (Abs_poly_mapping (lookup (get_trans res))))\"\n  proof  transfer\n    fix maxtime t :: nat\n    fix \\<sigma> :: \"'a state \"\n    fix \\<gamma> def cs\n    fix \\<tau> \\<theta> :: \"'a trans_raw\"\n    fix res :: \"nat \\<times> 'a state \\<times> 'a trans_raw \\<times> 'a trans_raw\"\n    assume fin_trans: \"finite {x. \\<tau> x \\<noteq> 0}\"\n    assume fin_hist:  \"finite {x. \\<theta> x \\<noteq> 0}\"\n    assume fin_res: \"pred_prod top (pred_prod (pred_fun top top) (pred_prod (\\<lambda>f. finite {x. f x \\<noteq> 0}) (\\<lambda>f. finite {x. f x \\<noteq> 0}))) res\"\n    hence fin_res1: \"finite {x. get_beh res x \\<noteq> 0}\" and fin_res2: \"finite {x. get_trans res x \\<noteq> 0}\"\n      by (metis (no_types, lifting) Collect_cong comp_eq_dest_lhs pred_prod_beta)+\n    assume \"maxtime, t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> <cs , \\<tau>> \\<leadsto> res\"\n    thus \"simulate_fin_ind maxtime t \\<sigma> \\<gamma> (Abs_poly_mapping \\<theta>) def cs (Abs_poly_mapping \\<tau>) (get_time res, get_state res, Abs_poly_mapping (get_beh res), Abs_poly_mapping (get_trans res))\"\n      using fin_res1 fin_res2 fin_hist fin_trans\n    proof (induction rule:b_simulate_fin.induct)\n      case (1 t maxtime \\<tau> \\<gamma> \\<sigma> \\<theta> def cs \\<tau>' res)\n      have \"\\<not> quiet (Abs_poly_mapping \\<tau>) \\<gamma>\"\n        using 1(2) unfolding quiet.rep_eq lookup_Abs_poly_mapping[OF `finite {x. \\<tau> x \\<noteq> 0}`] by auto\n\n      \\<comment> \\<open>several abbreviations for simplifying the proof notation\\<close>\n      let ?\\<theta> = \"Abs_poly_mapping \\<theta>\"\n      let ?\\<tau> = \"Abs_poly_mapping \\<tau>\"\n      let ?res = \"(t, \\<sigma>, Abs_poly_mapping (get_beh res), Abs_poly_mapping (get_trans res))\"\n      obtain q\\<tau>' where qt_def: \"conc_exec t \\<sigma> \\<gamma> ?\\<theta> def cs ?\\<tau> q\\<tau>'\"\n        by (metis (no_types, lifting) \"1.hyps\"(3) \"1.prems\"(3) \"1.prems\"(4) Collect_cong b_conc_exec_almost_all_zero conc_exec.abs_eq eq_onp_same_args)\n      note fin_res1 = `finite {x. get_beh res x \\<noteq> 0}`\n      note fin_res2 = `finite {x. get_trans res x \\<noteq> 0}`\n      note fin_trans = `finite {x. \\<tau> x \\<noteq> 0}`\n      note fin_hist = `finite {x. \\<theta> x \\<noteq> 0}`\n\n      \\<comment> \\<open>obtaining inductive hypothesis\\<close>\n      have \"finite {x. Femto_VHDL_raw.add_to_beh \\<sigma> \\<theta> t (Femto_VHDL_raw.next_time t \\<tau>') x \\<noteq> 0}\"\n        using add_to_beh_almost_all_zero[OF fin_hist] by auto\n      moreover have \"finite {x. \\<tau>' x \\<noteq> 0}\"\n        using b_conc_exec_almost_all_zero[OF `t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> <cs , \\<tau>> \\<longrightarrow>\\<^sub>c \\<tau>'` fin_trans fin_hist]\n        by auto\n      moreover hence \"finite {x. (\\<tau>'(Femto_VHDL_raw.next_time t \\<tau>' := 0)) x \\<noteq> 0}\"\n        using rem_next_time_almost_all_zero by metis\n      ultimately have IH: \"simulate_fin_ind maxtime (Femto_VHDL_raw.next_time t \\<tau>')\n                                                    (Femto_VHDL_raw.next_state t \\<tau>' \\<sigma>)\n                                                    (Femto_VHDL_raw.next_event t \\<tau>' \\<sigma>)\n                           (Abs_poly_mapping (Femto_VHDL_raw.add_to_beh \\<sigma> \\<theta> t (Femto_VHDL_raw.next_time t \\<tau>')))\n                                                     def cs\n                           (Abs_poly_mapping (\\<tau>'(Femto_VHDL_raw.next_time t \\<tau>' := 0)))\n              (get_time res, get_state res, Abs_poly_mapping (get_beh res), Abs_poly_mapping (get_trans res))\"\n        using 1(6)[OF fin_res1 fin_res2] by metis \n\n      \\<comment> \\<open>continuing the proof\\<close>\n      have nt: \"Femto_VHDL_raw.next_time t \\<tau>' = next_time t q\\<tau>'\" and\n           ns: \"Femto_VHDL_raw.next_state t \\<tau>' \\<sigma> = next_state t q\\<tau>' \\<sigma>\" and\n           ne: \"Femto_VHDL_raw.next_event t \\<tau>' \\<sigma> = next_event t q\\<tau>' \\<sigma>\" and\n           nb: \"Femto_VHDL_raw.add_to_beh \\<sigma> \\<theta> t (Femto_VHDL_raw.next_time t \\<tau>') =\n                lookup (add_to_beh \\<sigma> ?\\<theta> t (next_time t q\\<tau>'))\"\n        unfolding next_time.rep_eq next_state.rep_eq next_event.rep_eq  add_to_beh.rep_eq\n          conc_exec.rep_eq  lookup_Abs_poly_mapping[OF fin_hist]  lookup_Abs_poly_mapping[OF fin_trans]\n        using `t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> <cs , \\<tau>> \\<longrightarrow>\\<^sub>c \\<tau>'` qt_def\n        by (metis \\<open>lookup (Abs_poly_mapping \\<tau>) = \\<tau>\\<close> \\<open>lookup (Abs_poly_mapping \\<theta>) = \\<theta>\\<close> b_conc_exec_deterministic conc_exec.rep_eq)+\n      have ntr: \"\\<tau>'(Femto_VHDL_raw.next_time t \\<tau>' := 0) = lookup (rem_curr_trans (next_time t q\\<tau>') q\\<tau>')\"\n        unfolding rem_curr_trans_def Poly_Mapping.update.rep_eq conc_exec.rep_eq next_time.rep_eq\n        lookup_Abs_poly_mapping[OF fin_hist]  lookup_Abs_poly_mapping[OF fin_trans]\n        using `t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> <cs , \\<tau>> \\<longrightarrow>\\<^sub>c \\<tau>'` qt_def\n        by (metis \\<open>lookup (Abs_poly_mapping \\<tau>) = \\<tau>\\<close> \\<open>lookup (Abs_poly_mapping \\<theta>) = \\<theta>\\<close> b_conc_exec_deterministic conc_exec.rep_eq)+\n      have sim: \"simulate_fin_ind maxtime (next_time t q\\<tau>') (next_state t q\\<tau>' \\<sigma>) (next_event t q\\<tau>' \\<sigma>)\n                (add_to_beh \\<sigma> ?\\<theta> t (next_time t q\\<tau>'))  def cs  (rem_curr_trans (next_time t q\\<tau>') q\\<tau>')\n              (get_time res, get_state res, Abs_poly_mapping (get_beh res), Abs_poly_mapping (get_trans res))\"\n        using IH by (metis lookup_inverse nt ns ne nb nt ntr)\n      show ?case\n        using simulate_fin_ind.intros(1)[OF `t < maxtime` `\\<not> quiet ?\\<tau> \\<gamma>` _ _ sim] qt_def \n        \\<open>Femto_VHDL_raw.next_time t \\<tau>' \\<le> maxtime\\<close>\n        unfolding conc_exec_eq_conc_exec_ind  using nt by linarith\n    next\n      case (2 t maxtime \\<tau> \\<gamma> \\<sigma> \\<theta> def cs \\<tau>')\n      hence \"\\<not> quiet (Abs_poly_mapping \\<tau>) \\<gamma>\"\n        using 2(2) unfolding quiet.rep_eq lookup_Abs_poly_mapping[OF `finite {x. \\<tau> x \\<noteq> 0}`] by auto\n\n      \\<comment> \\<open>several abbreviations for simplifying the proof notation\\<close>\n      let ?\\<theta> = \"Abs_poly_mapping \\<theta>\"\n      let ?\\<tau> = \"Abs_poly_mapping \\<tau>\"\n      let ?res = \"(t, \\<sigma>, Abs_poly_mapping (get_beh res), Abs_poly_mapping (get_trans res))\"\n      obtain q\\<tau>' where qt_def: \"conc_exec t \\<sigma> \\<gamma> ?\\<theta> def cs ?\\<tau> q\\<tau>'\"\n        by (metis (no_types, lifting) 2 Collect_cong b_conc_exec_almost_all_zero conc_exec.abs_eq eq_onp_same_args)\n      note fin_res1 = `finite {x. get_beh res x \\<noteq> 0}`\n      note fin_res2 = `finite {x. get_trans res x \\<noteq> 0}`\n      note fin_trans = `finite {x. \\<tau> x \\<noteq> 0}`\n      note fin_hist = `finite {x. \\<theta> x \\<noteq> 0}`\n      have qt_def': \"conc_exec_ind t \\<sigma> \\<gamma> ?\\<theta> def cs ?\\<tau> q\\<tau>'\"\n        using qt_def unfolding conc_exec_eq_conc_exec_ind by auto\n      have nt: \"Femto_VHDL_raw.next_time t \\<tau>' = next_time t q\\<tau>'\" and\n           ns: \"Femto_VHDL_raw.next_state t \\<tau>' \\<sigma> = next_state t q\\<tau>' \\<sigma>\" and\n           ne: \"Femto_VHDL_raw.next_event t \\<tau>' \\<sigma> = next_event t q\\<tau>' \\<sigma>\" and\n           nb: \"Femto_VHDL_raw.add_to_beh \\<sigma> \\<theta> t (Femto_VHDL_raw.next_time t \\<tau>') =\n                lookup (add_to_beh \\<sigma> ?\\<theta> t (next_time t q\\<tau>'))\"\n        unfolding next_time.rep_eq next_state.rep_eq next_event.rep_eq  add_to_beh.rep_eq\n          conc_exec.rep_eq  lookup_Abs_poly_mapping[OF fin_hist]  lookup_Abs_poly_mapping[OF fin_trans]\n        using `t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> <cs , \\<tau>> \\<longrightarrow>\\<^sub>c \\<tau>'` qt_def\n        by (metis \\<open>lookup (Abs_poly_mapping \\<tau>) = \\<tau>\\<close> \\<open>lookup (Abs_poly_mapping \\<theta>) = \\<theta>\\<close> b_conc_exec_deterministic conc_exec.rep_eq)+\n      hence \"maxtime < Femto_VHDL.next_time t q\\<tau>'\"\n        using 2(4) by auto\n      have \"lookup (Poly_Mapping.update t (Some \\<circ> \\<sigma>) (Abs_poly_mapping \\<theta>)) = (\\<theta>(t := Some \\<circ> \\<sigma>))\"\n        unfolding Poly_Mapping.update.rep_eq lookup_Abs_poly_mapping[OF 2(5)]\n        by (simp add: \"2.prems\"(3))\n      hence \"Abs_poly_mapping (\\<theta>(t := Some \\<circ> \\<sigma>)) = Poly_Mapping.update t (Some \\<circ> \\<sigma>) (Abs_poly_mapping \\<theta>)\"\n        by (metis lookup_inverse)\n      have \"lookup (Abs_poly_mapping \\<theta>) = \\<theta>\"\n        using fin_hist by auto\n      moreover have \"lookup (Abs_poly_mapping \\<tau>) = \\<tau>\" \n        by (simp add: \"2.prems\"(4))\n      ultimately have \"lookup q\\<tau>' = \\<tau>'\"\n        using qt_def \\<open>t , \\<sigma> , \\<gamma> , \\<theta>, def \\<turnstile> <cs , \\<tau>> \\<longrightarrow>\\<^sub>c \\<tau>'\\<close> unfolding conc_exec.rep_eq\n        using b_conc_exec_deterministic by fastforce\n      hence \"Abs_poly_mapping \\<tau>' = q\\<tau>'\"\n        using lookup_inverse by blast\n      show ?case \n        using simulate_fin_ind.intros(2)[OF `t < maxtime` \\<open>\\<not> quiet (Abs_poly_mapping \\<tau>) \\<gamma>\\<close> qt_def' \\<open>maxtime < Femto_VHDL.next_time t q\\<tau>'\\<close>]\n        by (metis \\<open>Abs_poly_mapping (\\<theta>(t := Some \\<circ> \\<sigma>)) = Poly_Mapping.update t (Some \\<circ> \\<sigma>)\n        (Abs_poly_mapping \\<theta>)\\<close> \\<open>Abs_poly_mapping \\<tau>' = q\\<tau>'\\<close> comp_apply fst_conv snd_conv)\n    next\n      case (3 t maxtime \\<tau> \\<gamma> \\<sigma> \\<theta> def cs)\n      have *: \"quiet (Abs_poly_mapping \\<tau>) \\<gamma>\"\n        using 3 unfolding quiet.rep_eq lookup_Abs_poly_mapping[OF `finite {x. \\<tau> x \\<noteq> 0}`] by auto\n      have \"lookup (Poly_Mapping.update t (Some \\<circ> \\<sigma>) (Abs_poly_mapping \\<theta>)) = (\\<theta>(t := Some \\<circ> \\<sigma>))\"\n        unfolding Poly_Mapping.update.rep_eq lookup_Abs_poly_mapping[OF 3(4)]\n        by (simp add: \"3.prems\"(3))\n      hence \"Abs_poly_mapping (\\<theta>(t := Some \\<circ> \\<sigma>)) = Poly_Mapping.update t (Some \\<circ> \\<sigma>) (Abs_poly_mapping \\<theta>)\"\n        by (metis lookup_inverse)\n      thus ?case\n        using simulate_fin_ind.intros(3)[OF 3(1) *]\n      proof -\n        have \"lookup (Abs_poly_mapping (0::nat \\<Rightarrow> 'a \\<Rightarrow> val option)) = 0\"\n          using \"3.prems\"(2) by force\n        then show ?thesis\n          by (metis (no_types) \\<open>Abs_poly_mapping (\\<theta>(t := Some \\<circ> \\<sigma>)) = Poly_Mapping.update t (Some \\<circ>\n          \\<sigma>) (Abs_poly_mapping \\<theta>)\\<close> \\<open>\\<And>def cs \\<theta> \\<sigma>. simulate_fin_ind maxtime t \\<sigma> \\<gamma> \\<theta> def cs\n          (Abs_poly_mapping \\<tau>) (maxtime, \\<sigma>, Poly_Mapping.update t (Some \\<circ> \\<sigma>) \\<theta>, empty_trans)\\<close>\n          comp_apply fst_conv lookup_zero poly_mapping_eqI snd_conv zero_fun_def)\n      qed\n    next\n      case (4 t maxtime \\<sigma> \\<gamma> \\<theta> def cs \\<tau>)\n      then show ?case\n        using simulate_fin_ind.intros(4)[OF 4(1)] by auto\n    qed\n  qed\n  thus \"simulate_fin_ind maxtime t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> res\"\n    unfolding lookup_inverse by auto\nnext\n  assume \"simulate_fin_ind maxtime t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> res\"\n  thus \"simulate_fin maxtime t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> res\"\n    unfolding simulate_fin.rep_eq\n  proof (induction rule: simulate_fin_ind.induct)\n    case (1 t maxtime \\<tau> \\<gamma> \\<sigma> \\<theta> def cs \\<tau>' res)\n    then show ?case     \n      unfolding sym[OF conc_exec_eq_conc_exec_ind]\n      by (metis Femto_VHDL.rem_curr_trans_def add_to_beh.rep_eq b_simulate_fin.intros(1)\n      conc_exec.rep_eq next_event.rep_eq next_state.rep_eq next_time.rep_eq quiet.rep_eq\n      update.rep_eq)\n  next\n    case (2 t maxtime \\<tau> \\<gamma> \\<sigma> \\<theta> def cs \\<tau>')\n    then show ?case     \n      unfolding sym[OF conc_exec_eq_conc_exec_ind]\n      by (simp add: b_simulate_fin.intros(2) conc_exec.rep_eq next_time.rep_eq quiet.rep_eq update.rep_eq)\n  next\n    case (3 t maxtime \\<tau> \\<gamma> \\<sigma> \\<theta> def cs)\n    then show ?case \n      unfolding sym[OF conc_exec_eq_conc_exec_ind]\n      by (smt Femto_VHDL_raw.quiet_def apsnd_conv apsnd_def b_simulate_fin.intros(3) lookup_zero\n      map_prod_def old.prod.case poly_mapping_eqI quiet.rep_eq update.rep_eq zero_fun_def)\n  qed (simp add: b_simulate_fin.intros(4))\nqed\n\nlemma simulate_fin_ind_deterministic:\n  assumes \"simulate_fin_ind maxtime t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> res1\"\n  assumes \"simulate_fin_ind maxtime t \\<sigma> \\<gamma> \\<theta> def cs \\<tau> res2\"\n  shows \"res2 = res1\"\n  using assms unfolding sym[OF simulate_fin_eq_simulate_fin_ind]\n  by (auto simp add: simulate_fin_deterministic)\n\nlift_definition simulate :: \"nat \\<Rightarrow> 'a state \\<Rightarrow> 'a conc_stmt \\<Rightarrow> 'a transaction \\<Rightarrow> nat \\<times> 'a state \\<times> 'a transaction \\<times> 'a transaction \\<Rightarrow> bool\"\n  is b_simulate .\n\ninductive simulate_ind :: \"nat \\<Rightarrow> 'a state \\<Rightarrow> 'a conc_stmt \\<Rightarrow> 'a transaction \\<Rightarrow>  nat \\<times> 'a state \\<times> 'a transaction \\<times> 'a transaction \\<Rightarrow> bool\" where\n  \"     init'_ind 0 def {} 0 def cs \\<tau> \\<tau>'\n   \\<Longrightarrow>  next_time  0 \\<tau>' = t'\n   \\<Longrightarrow>  next_state 0 \\<tau>' def = \\<sigma>'\n   \\<Longrightarrow>  next_event 0 \\<tau>' def = \\<gamma>'\n   \\<Longrightarrow>  add_to_beh def 0 0 t' = beh'\n   \\<Longrightarrow>  simulate_fin_ind maxtime t' \\<sigma>' \\<gamma>' beh' def cs (rem_curr_trans t' \\<tau>') res\n   \\<Longrightarrow>  simulate_ind  maxtime def cs \\<tau> res\"\n\nlemma simulate_eq_simulate_ind:\n  \"simulate maxtime def cs \\<tau> res = simulate_ind maxtime def cs \\<tau> res\"\nproof\n  assume \"simulate maxtime def cs \\<tau> res\"\n  hence \"simulate_ind maxtime def cs (Abs_poly_mapping (lookup \\<tau>))\n         (get_time res, get_state res, (Abs_poly_mapping (lookup (get_beh res))), (Abs_poly_mapping (lookup (get_trans res))))\"\n  proof transfer\n    fix maxtime :: nat\n    fix def\n    fix \\<tau> :: \"'a trans_raw\"\n    fix res :: \"nat \\<times> 'a state \\<times> 'a trans_raw \\<times> 'a trans_raw\"\n    fix cs :: \"'a conc_stmt\"\n    assume fin_trans: \"finite {x. \\<tau> x \\<noteq> 0}\"\n    assume fin_hist: \"pred_prod top (pred_prod (pred_fun top top) (pred_prod (\\<lambda>f. finite {x. f x \\<noteq> 0}) (\\<lambda>f. finite {x. f x \\<noteq> 0}))) res\"\n    hence fin_hist1: \"finite {x. get_beh res x \\<noteq> 0}\" and fin_hist2: \"finite {x. get_trans res x \\<noteq> 0}\"\n      by (simp add: pred_prod_beta)+\n    assume \"b_simulate maxtime def cs \\<tau> res\"\n    thus \"simulate_ind maxtime def cs (Abs_poly_mapping \\<tau>)\n          (get_time res, get_state res, (Abs_poly_mapping (get_beh res)), Abs_poly_mapping (get_trans res))\"\n      using fin_trans fin_hist1 fin_hist2\n    proof (induction rule: b_simulate.induct)\n      case (1 def cs \\<tau> \\<tau>' t' \\<sigma>' \\<gamma>' beh' maxtime res)\n      note fin_trans = `finite {x. \\<tau> x \\<noteq> 0}`\n      note fin_hist1 = `finite {x. get_beh res x \\<noteq> 0}`\n      note fin_hist2 = `finite {x. get_trans res x \\<noteq> 0}`\n      have fin_next_trans: \"finite {x. \\<tau>' x \\<noteq> 0}\"\n        using init'_raw_almost_all_zero[OF 1(1) _ fin_trans]\n        by (simp add: zero_fun_def)\n      \\<comment> \\<open>obtaining the first premise in the proof rule of @{term \"simulate_ind\"}\\<close>\n      have look_abs_trans: \"lookup (Abs_poly_mapping \\<tau>) = \\<tau>\"\n        using lookup_Abs_poly_mapping[OF fin_trans] by auto\n      have \"lookup (Abs_poly_mapping \\<tau>') = \\<tau>'\"\n        using lookup_Abs_poly_mapping[OF `finite {x. \\<tau>' x \\<noteq> 0}`] by auto\n      have \"lookup empty_trans = 0\"\n        by (transfer', auto simp add: zero_fun_def)\n      have prem1: \"init' 0 def {} 0 def cs  (Abs_poly_mapping \\<tau>) (Abs_poly_mapping \\<tau>')\"\n        unfolding init'.rep_eq `lookup empty_trans = 0` using 1(1)\n        by (simp add: \\<open>lookup (Abs_poly_mapping \\<tau>') = \\<tau>'\\<close> look_abs_trans)\n\n      \\<comment> \\<open>obtaining the 2nd and 3rd premise in the proof rule of @{term \"simulate_ind\"}\\<close>\n      have prem2: \"next_time 0 (Abs_poly_mapping \\<tau>') = t'\" and\n           prem3: \"next_state 0 (Abs_poly_mapping \\<tau>') def = \\<sigma>'\"\n        using 1(2) 1(3) unfolding next_time.rep_eq next_state.rep_eq\n        lookup_Abs_poly_mapping[OF fin_next_trans] by auto\n\n      \\<comment> \\<open>obtaining the 4th premise in the proof rule of @{term \"simulate_ind\"}\\<close>\n      have prem4: \"next_event 0 (Abs_poly_mapping \\<tau>') def = \\<gamma>'\"\n        using 1(4) unfolding next_event.rep_eq\n        lookup_Abs_poly_mapping[OF fin_next_trans] by auto\n\n      \\<comment> \\<open>obtaining the 5th premise in the proof rule of @{term \"simulate_ind\"}\\<close>\n      have \"lookup (add_to_beh def 0 0 t') = beh'\" (is \"?lhs0 = ?rhs0\")\n        using 1(5) by (transfer', auto simp add: zero_fun_def)\n      hence \"Abs_poly_mapping ?lhs0 = Abs_poly_mapping ?rhs0\"\n        by auto\n      hence prem5: \"add_to_beh def 0 0 t' = Abs_poly_mapping beh'\"\n        unfolding lookup_inverse by auto\n\n      \\<comment> \\<open>obtaining the 6th premise in the proof rule of @{term \"simulate_ind\"}\\<close>\n      let ?beh' = \"Abs_poly_mapping beh'\"\n      let ?res  = \"(get_time res, get_state res, (Abs_poly_mapping (get_beh res)), Abs_poly_mapping (get_trans res))\"\n      let ?\\<tau>'   = \"Abs_poly_mapping \\<tau>'\"\n      have lookup_res: \"(get_time res, get_state res, lookup (Abs_poly_mapping (get_beh res)), lookup (Abs_poly_mapping (get_trans res))) = res\"\n        using lookup_Abs_poly_mapping[OF fin_hist1] lookup_Abs_poly_mapping[OF fin_hist2]\n        by auto\n      have \"finite {x. beh' x \\<noteq> 0}\"\n        using 1(5) unfolding Femto_VHDL_raw.add_to_beh_def by (auto simp add: zero_fun_def)\n      hence lookup_beh: \"lookup ?beh' = beh'\"\n        by (auto intro!: lookup_Abs_poly_mapping)\n      have lookup_rem: \"lookup (rem_curr_trans t' ?\\<tau>') = \\<tau>'(t':=0)\"\n        unfolding rem_curr_trans_def update.rep_eq lookup_Abs_poly_mapping[OF fin_next_trans]\n        by auto\n      have \"simulate_fin maxtime t' \\<sigma>' \\<gamma>' ?beh' def cs (rem_curr_trans t' ?\\<tau>') ?res\"\n        using 1(6) unfolding simulate_fin.rep_eq lookup_beh lookup_rem\n        using lookup_res by auto\n      hence prem6: \"simulate_fin_ind maxtime t' \\<sigma>' \\<gamma>' ?beh' def cs (rem_curr_trans t' ?\\<tau>') ?res\"\n        using simulate_fin_eq_simulate_fin_ind by metis\n      show \"simulate_ind maxtime def cs (Abs_poly_mapping \\<tau>)\n        (get_time res, get_state res, Abs_poly_mapping (get_beh res), Abs_poly_mapping (get_trans res))\"\n        using prem1 prem2 prem3 prem4 prem5 prem6\n        unfolding init'_eq_init'_ind by (auto intro!:simulate_ind.intros)\n    qed\n  qed\n  thus \"simulate_ind maxtime def cs \\<tau> res\"\n    unfolding lookup_inverse by auto\nnext\n  assume \"simulate_ind maxtime def cs \\<tau> res\"\n  thus \"simulate maxtime def cs \\<tau> res\"\n    unfolding simulate.rep_eq\n  proof (induction rule:simulate_ind.induct)\n    case (1 def cs \\<tau> \\<tau>' t' \\<sigma>' \\<gamma>' beh' maxtime res)\n    have prem1: \"Femto_VHDL_raw.init' 0 def {} 0 def cs (lookup \\<tau>) (lookup \\<tau>')\"\n      using 1(1) unfolding sym[OF init'_eq_init'_ind] by (transfer', auto simp add: zero_fun_def)\n    have prem2: \"Femto_VHDL_raw.next_time  0 (lookup \\<tau>') = t'\"\n      using 1(2) by transfer'\n    have prem3: \"Femto_VHDL_raw.next_state 0 (lookup \\<tau>') def = \\<sigma>'\"\n      using 1(3) by transfer'\n    have prem4: \"Femto_VHDL_raw.next_event 0 (lookup \\<tau>') def = \\<gamma>'\"\n      using 1(4) by transfer'\n    have prem5: \"Femto_VHDL_raw.add_to_beh def 0 0 t'  = (lookup beh')\"\n      using 1(5) by (transfer', auto simp add: zero_fun_def)\n    have prem6: \"maxtime, t', \\<sigma>', \\<gamma>', (lookup beh'), def \\<turnstile> <cs, (lookup \\<tau>')(t' := 0)> \\<leadsto> (get_time res, get_state res, lookup (get_beh res), lookup (get_trans res))\"\n      using 1(6) unfolding sym[OF simulate_fin_eq_simulate_fin_ind] rem_curr_trans_def\n      by (transfer', auto)\n    have helper: \"map_prod id (map_prod id (map_prod lookup lookup)) res = (get_time res, get_state res, lookup (get_beh res), lookup (get_trans res))\"\n      by (metis (no_types, hide_lams) apsnd_conv apsnd_def comp_apply fst_map_prod prod.exhaust_sel snd_map_prod)\n    show ?case\n      using prem1 prem2 prem3 prem4 prem5 prem6 unfolding helper\n      by(auto intro!: b_simulate.intros)\n  qed\nqed\n\ntype_synonym 'signal configuration = \"nat \\<times> 'signal  state \\<times> 'signal event \\<times> 'signal transaction\"\n\nlift_definition update_config :: \"'signal configuration \\<Rightarrow> 'signal transaction \\<Rightarrow> 'signal configuration\"\n  is update_config_raw unfolding sym[OF eventually_cofinite]\nproof -\n  fix config :: \"nat \\<times> 'signal  state \\<times> 'signal event \\<times> 'signal trans_raw\"\n  fix \\<tau>' :: \"'signal trans_raw\"\n  assume *: \"pred_prod top (pred_prod top (pred_prod top (\\<lambda>f. \\<forall>\\<^sub>\\<infinity>x. f x = 0))) config\"\n  obtain t \\<sigma> \\<gamma> \\<theta> where \"config = (t, \\<sigma>, \\<gamma>, \\<theta>)\"\n    using prod_cases4 by blast\n  hence \"\\<forall>\\<^sub>\\<infinity>x. \\<theta> x = 0\"\n    using * by auto\n  assume \"\\<forall>\\<^sub>\\<infinity>x. \\<tau>' x = 0\"\n  obtain t' \\<sigma>' \\<gamma>' \\<theta>' where \"update_config_raw config \\<tau>' = (t', \\<sigma>', \\<gamma>', \\<theta>')\" and\n    \"t' = Femto_VHDL_raw.next_time t \\<tau>'\" and \"\\<sigma>' = Femto_VHDL_raw.next_state t \\<tau>' \\<sigma>\" and\n    \"\\<gamma>' = Femto_VHDL_raw.next_event t \\<tau>' \\<sigma>\" and \"\\<theta>' = Femto_VHDL_raw.add_to_beh \\<sigma> \\<theta> t t'\"\n    using `config = (t, \\<sigma>, \\<gamma>, \\<theta>)`  by (metis update_config_raw.simps)\n  have \"\\<forall>\\<^sub>\\<infinity>x. Femto_VHDL_raw.add_to_beh \\<sigma> \\<theta> t t' x = 0\"\n    unfolding Femto_VHDL_raw.add_to_beh_def  using `\\<forall>\\<^sub>\\<infinity>x. \\<theta> x = 0`\n    by (metis (mono_tags) upd_eventually_cofinite)\n  thus \"pred_prod top (pred_prod top (pred_prod top (\\<lambda>f. \\<forall>\\<^sub>\\<infinity>x. f x = 0))) (update_config_raw config \\<tau>')\"\n    by (simp add: \\<open>\\<theta>' = Femto_VHDL_raw.add_to_beh \\<sigma> \\<theta> t t'\\<close> \\<open>update_config_raw config \\<tau>' = (t', \\<sigma>', \\<gamma>', \\<theta>')\\<close>)\nqed\n\nlift_definition simulate_fin_ss :: \"nat \\<Rightarrow> 'signal state \\<Rightarrow> 'signal conc_stmt \\<Rightarrow>\n  'signal transaction \\<times> 'signal configuration  \\<Rightarrow>  'signal transaction \\<times> 'signal configuration \\<Rightarrow> bool\"\n  is b_simulate_fin_ss .\n\nend", "meta": {"author": "rizaldialbert", "repo": "vhdl-semantics", "sha": "352f89c9ccdfe830c054757dfd86caeadbd67159", "save_path": "github-repos/isabelle/rizaldialbert-vhdl-semantics", "path": "github-repos/isabelle/rizaldialbert-vhdl-semantics/vhdl-semantics-352f89c9ccdfe830c054757dfd86caeadbd67159/Femto_VHDL.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318337259583, "lm_q2_score": 0.44552953503957277, "lm_q1q2_score": 0.26906946907552276}}
{"text": "(*  Title:      HOL/HOLCF/IOA/SimCorrectness.thy\n    Author:     Olaf Müller\n*)\n\nsection \\<open>Correctness of Simulations in HOLCF/IOA\\<close>\n\ntheory SimCorrectness\nimports Simulations\nbegin\n\n(*Note: s2 instead of s1 in last argument type!*)\ndefinition corresp_ex_simC ::\n    \"('a, 's2) ioa \\<Rightarrow> ('s1 \\<times> 's2) set \\<Rightarrow> ('a, 's1) pairs \\<rightarrow> ('s2 \\<Rightarrow> ('a, 's2) pairs)\"\n  where \"corresp_ex_simC A R =\n    (fix \\<cdot> (LAM h ex. (\\<lambda>s. case ex of\n      nil \\<Rightarrow> nil\n    | x ## xs \\<Rightarrow>\n        (flift1\n          (\\<lambda>pr.\n            let\n              a = fst pr;\n              t = snd pr;\n              T' = SOME t'. \\<exists>ex1. (t, t') \\<in> R \\<and> move A ex1 s a t'\n            in (SOME cex. move A cex s a T') @@ ((h \\<cdot> xs) T')) \\<cdot> x))))\"\n\ndefinition corresp_ex_sim ::\n    \"('a, 's2) ioa \\<Rightarrow> ('s1 \\<times> 's2) set \\<Rightarrow> ('a, 's1) execution \\<Rightarrow> ('a, 's2) execution\"\n  where \"corresp_ex_sim A R ex \\<equiv>\n    let S' = SOME s'. (fst ex, s') \\<in> R \\<and> s' \\<in> starts_of A\n    in (S', (corresp_ex_simC A R \\<cdot> (snd ex)) S')\"\n\n\nsubsection \\<open>\\<open>corresp_ex_sim\\<close>\\<close>\n\nlemma corresp_ex_simC_unfold:\n  \"corresp_ex_simC A R =\n    (LAM ex. (\\<lambda>s. case ex of\n      nil \\<Rightarrow> nil\n    | x ## xs \\<Rightarrow>\n        (flift1\n          (\\<lambda>pr.\n            let\n              a = fst pr;\n              t = snd pr;\n              T' = SOME t'. \\<exists>ex1. (t, t') \\<in> R \\<and> move A ex1 s a t'\n            in (SOME cex. move A cex s a T') @@ ((corresp_ex_simC A R \\<cdot> xs) T')) \\<cdot> x)))\"\n  apply (rule trans)\n  apply (rule fix_eq2)\n  apply (simp only: corresp_ex_simC_def)\n  apply (rule beta_cfun)\n  apply (simp add: flift1_def)\n  done\n\nlemma corresp_ex_simC_UU [simp]: \"(corresp_ex_simC A R \\<cdot> UU) s = UU\"\n  apply (subst corresp_ex_simC_unfold)\n  apply simp\n  done\n\nlemma corresp_ex_simC_nil [simp]: \"(corresp_ex_simC A R \\<cdot> nil) s = nil\"\n  apply (subst corresp_ex_simC_unfold)\n  apply simp\n  done\n\nlemma corresp_ex_simC_cons [simp]:\n  \"(corresp_ex_simC A R \\<cdot> ((a, t) \\<leadsto> xs)) s =\n    (let T' = SOME t'. \\<exists>ex1. (t, t') \\<in> R \\<and> move A ex1 s a t'\n     in (SOME cex. move A cex s a T') @@ ((corresp_ex_simC A R \\<cdot> xs) T'))\"\n  apply (rule trans)\n  apply (subst corresp_ex_simC_unfold)\n  apply (simp add: Consq_def flift1_def)\n  apply simp\n  done\n\n\nsubsection \\<open>Properties of move\\<close>\n\nlemma move_is_move_sim:\n   \"is_simulation R C A \\<Longrightarrow> reachable C s \\<Longrightarrow> s \\<midarrow>a\\<midarrow>C\\<rightarrow> t \\<Longrightarrow> (s, s') \\<in> R \\<Longrightarrow>\n     let T' = SOME t'. \\<exists>ex1. (t, t') \\<in> R \\<and> move A ex1 s' a t'\n     in (t, T') \\<in> R \\<and> move A (SOME ex2. move A ex2 s' a T') s' a T'\"\n  supply Let_def [simp del]\n  apply (unfold is_simulation_def)\n  (* Does not perform conditional rewriting on assumptions automatically as\n     usual. Instantiate all variables per hand. Ask Tobias?? *)\n  apply (subgoal_tac \"\\<exists>t' ex. (t, t') \\<in> R \\<and> move A ex s' a t'\")\n  prefer 2\n  apply simp\n  apply (erule conjE)\n  apply (erule_tac x = \"s\" in allE)\n  apply (erule_tac x = \"s'\" in allE)\n  apply (erule_tac x = \"t\" in allE)\n  apply (erule_tac x = \"a\" in allE)\n  apply simp\n  (* Go on as usual *)\n  apply (erule exE)\n  apply (drule_tac x = \"t'\" and P = \"\\<lambda>t'. \\<exists>ex. (t, t') \\<in> R \\<and> move A ex s' a t'\" in someI)\n  apply (erule exE)\n  apply (erule conjE)\n  apply (simp add: Let_def)\n  apply (rule_tac x = \"ex\" in someI)\n  apply assumption\n  done\n\nlemma move_subprop1_sim:\n  \"is_simulation R C A \\<Longrightarrow> reachable C s \\<Longrightarrow> s \\<midarrow>a\\<midarrow>C\\<rightarrow> t \\<Longrightarrow> (s, s') \\<in> R \\<Longrightarrow>\n    let T' = SOME t'. \\<exists>ex1. (t, t') \\<in> R \\<and> move A ex1 s' a t'\n    in is_exec_frag A (s', SOME x. move A x s' a T')\"\n  apply (cut_tac move_is_move_sim)\n  defer\n  apply assumption+\n  apply (simp add: move_def)\n  done\n\nlemma move_subprop2_sim:\n  \"is_simulation R C A \\<Longrightarrow> reachable C s \\<Longrightarrow> s \\<midarrow>a\\<midarrow>C\\<rightarrow> t \\<Longrightarrow> (s, s') \\<in> R \\<Longrightarrow>\n    let T' = SOME t'. \\<exists>ex1. (t, t') \\<in> R \\<and> move A ex1 s' a t'\n    in Finite (SOME x. move A x s' a T')\"\n  apply (cut_tac move_is_move_sim)\n  defer\n  apply assumption+\n  apply (simp add: move_def)\n  done\n\nlemma move_subprop3_sim:\n  \"is_simulation R C A \\<Longrightarrow> reachable C s \\<Longrightarrow> s \\<midarrow>a\\<midarrow>C\\<rightarrow> t \\<Longrightarrow> (s, s') \\<in> R \\<Longrightarrow>\n    let T' = SOME t'. \\<exists>ex1. (t, t') \\<in> R \\<and> move A ex1 s' a t'\n    in laststate (s', SOME x. move A x s' a T') = T'\"\n  apply (cut_tac move_is_move_sim)\n  defer\n  apply assumption+\n  apply (simp add: move_def)\n  done\n\nlemma move_subprop4_sim:\n  \"is_simulation R C A \\<Longrightarrow> reachable C s \\<Longrightarrow> s \\<midarrow>a\\<midarrow>C\\<rightarrow> t \\<Longrightarrow> (s, s') \\<in> R \\<Longrightarrow>\n    let T' = SOME t'. \\<exists>ex1. (t, t') \\<in> R \\<and> move A ex1 s' a t'\n    in mk_trace A \\<cdot> (SOME x. move A x s' a T') = (if a \\<in> ext A then a \\<leadsto> nil else nil)\"\n  apply (cut_tac move_is_move_sim)\n  defer\n  apply assumption+\n  apply (simp add: move_def)\n  done\n\nlemma move_subprop5_sim:\n  \"is_simulation R C A \\<Longrightarrow> reachable C s \\<Longrightarrow> s \\<midarrow>a\\<midarrow>C\\<rightarrow> t \\<Longrightarrow> (s, s') \\<in> R \\<Longrightarrow>\n    let T' = SOME t'. \\<exists>ex1. (t, t') \\<in> R \\<and> move A ex1 s' a t'\n    in (t, T') \\<in> R\"\n  apply (cut_tac move_is_move_sim)\n  defer\n  apply assumption+\n  apply (simp add: move_def)\n  done\n\n\nsubsection \\<open>TRACE INCLUSION Part 1: Traces coincide\\<close>\n\nsubsubsection \"Lemmata for <==\"\n\ntext \\<open>Lemma 1: Traces coincide\\<close>\n\nlemma traces_coincide_sim [rule_format (no_asm)]:\n  \"is_simulation R C A \\<Longrightarrow> ext C = ext A \\<Longrightarrow>\n    \\<forall>s s'. reachable C s \\<and> is_exec_frag C (s, ex) \\<and> (s, s') \\<in> R \\<longrightarrow>\n      mk_trace C \\<cdot> ex = mk_trace A \\<cdot> ((corresp_ex_simC A R \\<cdot> ex) s')\"\n  supply if_split [split del]\n  apply (pair_induct ex simp: is_exec_frag_def)\n  text \\<open>cons case\\<close>\n  apply auto\n  apply (rename_tac ex a t s s')\n  apply (simp add: mk_traceConc)\n  apply (frule reachable.reachable_n)\n  apply assumption\n  apply (erule_tac x = \"t\" in allE)\n  apply (erule_tac x = \"SOME t'. \\<exists>ex1. (t, t') \\<in> R \\<and> move A ex1 s' a t'\" in allE)\n  apply (simp add: move_subprop5_sim [unfolded Let_def]\n    move_subprop4_sim [unfolded Let_def] split: if_split)\n  done\n\ntext \\<open>Lemma 2: \\<open>corresp_ex_sim\\<close> is execution\\<close>\n\nlemma correspsim_is_execution [rule_format]:\n  \"is_simulation R C A \\<Longrightarrow>\n    \\<forall>s s'. reachable C s \\<and> is_exec_frag C (s, ex) \\<and> (s, s') \\<in> R\n      \\<longrightarrow> is_exec_frag A (s', (corresp_ex_simC A R \\<cdot> ex) s')\"\n  apply (pair_induct ex simp: is_exec_frag_def)\n  text \\<open>main case\\<close>\n  apply auto\n  apply (rename_tac ex a t s s')\n  apply (rule_tac t = \"SOME t'. \\<exists>ex1. (t, t') \\<in> R \\<and> move A ex1 s' a t'\" in lemma_2_1)\n\n  text \\<open>Finite\\<close>\n  apply (erule move_subprop2_sim [unfolded Let_def])\n  apply assumption+\n  apply (rule conjI)\n\n  text \\<open>\\<open>is_exec_frag\\<close>\\<close>\n  apply (erule move_subprop1_sim [unfolded Let_def])\n  apply assumption+\n  apply (rule conjI)\n\n  text \\<open>Induction hypothesis\\<close>\n  text \\<open>\\<open>reachable_n\\<close> looping, therefore apply it manually\\<close>\n  apply (erule_tac x = \"t\" in allE)\n  apply (erule_tac x = \"SOME t'. \\<exists>ex1. (t, t') \\<in> R \\<and> move A ex1 s' a t'\" in allE)\n  apply simp\n  apply (frule reachable.reachable_n)\n  apply assumption\n  apply (simp add: move_subprop5_sim [unfolded Let_def])\n  text \\<open>laststate\\<close>\n  apply (erule move_subprop3_sim [unfolded Let_def, symmetric])\n  apply assumption+\n  done\n\n\nsubsection \\<open>Main Theorem: TRACE - INCLUSION\\<close>\n\ntext \\<open>\n  Generate condition \\<open>(s, S') \\<in> R \\<and> S' \\<in> starts_of A\\<close>, the first being\n  interesting for the induction cases concerning the two lemmas\n  \\<open>correpsim_is_execution\\<close> and \\<open>traces_coincide_sim\\<close>, the second for the start\n  state case.\n  \\<open>S' := SOME s'. (s, s') \\<in> R \\<and> s' \\<in> starts_of A\\<close>, where \\<open>s \\<in> starts_of C\\<close>\n\\<close>\n\nlemma simulation_starts:\n  \"is_simulation R C A \\<Longrightarrow> s\\<in>starts_of C \\<Longrightarrow>\n    let S' = SOME s'. (s, s') \\<in> R \\<and> s' \\<in> starts_of A\n    in (s, S') \\<in> R \\<and> S' \\<in> starts_of A\"\n  apply (simp add: is_simulation_def corresp_ex_sim_def Int_non_empty Image_def)\n  apply (erule conjE)+\n  apply (erule ballE)\n  prefer 2 apply blast\n  apply (erule exE)\n  apply (rule someI2)\n  apply assumption\n  apply blast\n  done\n\nlemmas sim_starts1 = simulation_starts [unfolded Let_def, THEN conjunct1]\nlemmas sim_starts2 = simulation_starts [unfolded Let_def, THEN conjunct2]\n\n\nlemma trace_inclusion_for_simulations:\n  \"ext C = ext A \\<Longrightarrow> is_simulation R C A \\<Longrightarrow> traces C \\<subseteq> traces A\"\n  apply (unfold traces_def)\n  apply (simp add: has_trace_def2)\n  apply auto\n\n  text \\<open>give execution of abstract automata\\<close>\n  apply (rule_tac x = \"corresp_ex_sim A R ex\" in bexI)\n\n  text \\<open>Traces coincide, Lemma 1\\<close>\n  apply (pair ex)\n  apply (rename_tac s ex)\n  apply (simp add: corresp_ex_sim_def)\n  apply (rule_tac s = \"s\" in traces_coincide_sim)\n  apply assumption+\n  apply (simp add: executions_def reachable.reachable_0 sim_starts1)\n\n  text \\<open>\\<open>corresp_ex_sim\\<close> is execution, Lemma 2\\<close>\n  apply (pair ex)\n  apply (simp add: executions_def)\n  apply (rename_tac s ex)\n\n  text \\<open>start state\\<close>\n  apply (rule conjI)\n  apply (simp add: sim_starts2 corresp_ex_sim_def)\n\n  text \\<open>\\<open>is_execution-fragment\\<close>\\<close>\n  apply (simp add: corresp_ex_sim_def)\n  apply (rule_tac s = s in correspsim_is_execution)\n  apply assumption\n  apply (simp add: reachable.reachable_0 sim_starts1)\n  done\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/HOLCF/IOA/SimCorrectness.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736783928749127, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.2689350532777668}}
{"text": "theory TelephoneExchange\n  imports \"Z_Machines.Z_Machine\"\nbegin unbundle Z_Syntax\n\ntype_synonym digit = integer\ntype_synonym subs = \"digit list\"\n\ndefinition Digit :: \"\\<bbbP> digit\" where \"Digit = integer_of_int ` {0..9}\"\n\nconsts \n  Subs :: \"\\<bbbP> (digit list)\" \n\ndefinition \"Valid = {n \\<in> blists 6 Digit. \\<exists> s \\<in> Subs. n \\<le> s}\"\n\ndefinition \n  \"TelephoneExchange_axioms = (Subs \\<in> \\<bbbP> (seq Digit))\"\n\nenumtype Status = seize | dialling | unobtainable | connecting | ringing | speech | engaged | suspended\n\ndefinition \"Connected = {ringing , speech, suspended}\"\n\ndefinition \"Established = Connected \\<union> {connecting , engaged}\"\n\ntype_synonym subrec = \"Status \\<times> digit list\"\n\ndefinition SubRec :: \"Status \\<leftrightarrow> digit list\" where\n\"SubRec = {(s, n). (s = seize \\<longleftrightarrow> n = []) \n                 \\<and> (s = dialling \\<longleftrightarrow> n \\<in> Valid - Subs - {[]})\n                 \\<and> (s = unobtainable \\<longleftrightarrow> n \\<notin> Valid)\n                 \\<and> (s \\<in> Established \\<longleftrightarrow> n \\<in> Subs)}\"\n\ndefinition st :: \"subrec \\<Zpfun> Status\" where [simp]: \"st = (\\<lambda> x \\<bullet> first x)\"\ndefinition num :: \"subrec \\<Zpfun> subs\" where [simp]: \"num = (\\<lambda> x \\<bullet> second x)\"\n\nno_syntax\n  \"_kleisli_comp\" :: \"logic \\<Rightarrow> logic \\<Rightarrow> logic\" (infixl \"\\<Zcomp>\" 54)\n\nschema Exchange =\n  Free :: \"\\<bbbP> subs\"\n  Unavailable :: \"\\<bbbP> subs\"\n  Callers :: \"\\<bbbP> subs\"\n  cal :: \"subs \\<leftrightarrow> subrec\"\n  connected :: \"subs \\<leftrightarrow> subs\"\nwhere\n  \"[Free, Unavailable, dom cal \\<union> dom connected] partitions Subs\"\n  \"Callers = dom ((cal \\<Zcomp> st) \\<Zrres> Connected)\"\n  \"connected = Callers \\<Zdres> (cal \\<Zcomp> num)\"\n  \"functional cal\"\n\nrecord_default Exchange\n\ndefinition \"InitExchange = [Free\\<Zprime> = Subs, Unavailable\\<Zprime> = {}, Callers\\<Zprime> = {}, cal\\<Zprime> = {}, connected\\<Zprime> = {}]\"\n\nzoperation LiftFree =\n  params s \\<in> Subs\n  pre \"s \\<in> Free\"\n  update \"[Free\\<Zprime> = Free - {s}\n          ,cal\\<Zprime> = cal \\<union> {s \\<mapsto> (seize, [])}]\"\n\ndeclare list_partitions_def [simp]\n\nlemma \"s \\<in> Subs \\<Longrightarrow> \\<^bold>{Exchange\\<^bold>}LiftFree s\\<^bold>{Exchange\\<^bold>}\"\n  unfolding LiftFree_def Exchange_inv_def Connected_def\n  apply (hoare_wlp_auto)\n  apply (simp add: Domain_iff disjoint_iff rel_ranres_def)\n   apply (simp_all add: Domain_iff disjoint_iff rel_ranres_def)\n  apply (rule compatible_relI)\n  apply (simp add: pfun_graph_domres[THEN sym])\n  apply (subgoal_tac \"s \\<notin> dom cal\")\n  apply (auto)\n  done\n\nzoperation LiftSuspended =\n  params s \\<in> Subs\n  pre \"(s, suspended) \\<in> connected\\<^sup>\\<sim> \\<Zcomp> cal \\<Zcomp> st\" \n  update \"[cal\\<Zprime> = cal \\<oplus> {(connected\\<^sup>\\<sim>) s \\<mapsto> (speech, s)}]\"\n\nzoperation Answer =\n  params s \\<in> Subs\n  pre \"(s, ringing) \\<in> connected\\<^sup>\\<sim> \\<Zcomp> cal \\<Zcomp> st\"\n  update \"[ Free\\<Zprime> = Free - {s}\n          , cal\\<Zprime> = cal \\<oplus> {(connected\\<^sup>\\<sim>) s \\<mapsto> (speech, s)}]\"\n\ndefinition \"nextstate n = \n  (if n \\<in> Subs then connecting\n   else if n \\<in> Valid - Subs then dialling\n   else unobtainable)\"\n\nzoperation Dial =\n  params s \\<in> Subs d \\<in> Digit\n  pre \"(s, seize) \\<in> cal \\<Zcomp> st \\<or> (s, dialling) \\<in> cal \\<Zcomp> st\"\n  update \"[cal\\<Zprime> = (let newnum = (cal \\<Zcomp> num) s @ [d] in cal \\<oplus> {s \\<mapsto> (nextstate newnum, newnum)})]\"\n\nzoperation ClearAttempt =\n  params s \\<in> Subs\n  pre \"s \\<in> dom cal \\<and> (cal \\<Zcomp> st) s \\<in> {seize, dialling , connecting , engaged, unobtainable}\"\n  update \"[Free\\<Zprime> = Free \\<union> {s}, cal\\<Zprime> = {s} \\<Zndres> cal]\"\n\nzoperation ClearLine =\n  params s \\<in> Subs\n  pre \"s \\<in> dom cal \\<and> (cal \\<Zcomp> st) s \\<in> {ringing , suspended}\"\n  update \"[ Free\\<Zprime> = Free \\<union> {s, connected s}, cal\\<Zprime> = {s} \\<Zndres> cal\n          , Callers\\<Zprime> = Callers - {s, connected s}\n          , connected\\<Zprime> = {s} \\<Zndres> connected]\"\n\nzoperation ClearConnect =\n  params s \\<in> Subs\n  pre \"s \\<in> dom cal \\<and> (cal \\<Zcomp> st) s = speech\"\n  update \"[ Free\\<Zprime> = Free \\<union> {s}\n          , cal\\<Zprime> = ({s} \\<Zndres> cal) \\<oplus> {connected s \\<mapsto> (seize, [])}\n          , Callers\\<Zprime> = Callers - {s}\n          , connected\\<Zprime> = {s} \\<Zndres> connected]\"\n\nzoperation ClearSuspend =\n  params s \\<in> Subs\n  pre \"s \\<in> ran connected\"\n  update \"[cal\\<Zprime> = cal \\<oplus> {(connected\\<^sup>\\<sim>) s \\<mapsto> (suspended, s)}]\"\n\nzoperation ClearUnavail =\n  params s \\<in> Subs\n  pre \"s \\<in> Unavailable\"\n  update \"[Free\\<Zprime> = Free \\<union> {s}, Unavailable\\<Zprime> = Unavailable - {s}]\"\n\nzoperation MakeUnavail =\n  params s \\<in> Subs\n  pre \"s \\<in> dom cal \\<and> (cal \\<Zcomp> st) s \\<in> {seize, dialling}\"\n  update \"[Unavailable\\<Zprime> = Unavailable \\<union> {s}, cal\\<Zprime> = {s} \\<Zndres> cal]\"\n\nzoperation Connect2Ringing =\n  params s \\<in> Subs\n  pre \"s \\<in> dom cal \\<and> (cal \\<Zcomp> st) s = connecting \\<and> s \\<notin> dom connected \\<and> (cal \\<Zcomp> num) s \\<in> Free \\<and> (cal \\<Zcomp> num) s \\<notin> ran connected\"\n  update \"[ Free\\<Zprime> = Free - {s}\n          , cal\\<Zprime> = cal \\<oplus> {s \\<mapsto> (ringing, (cal \\<Zcomp> num) s)}\n          , Callers\\<Zprime> = Callers \\<union> {s}\n          , connected\\<Zprime> = connected \\<oplus> {s \\<mapsto> (cal \\<Zcomp> num) s}]\"\n\nzoperation Connect2Engaged =\n  params s \\<in> Subs\n  pre \"s \\<in> dom cal \\<and> (cal \\<Zcomp> st) s = connecting \\<and> s \\<notin> dom connected \\<and> (cal \\<Zcomp> num) s \\<notin> Free\"\n  update \"[ cal\\<Zprime> = cal \\<oplus> {s \\<mapsto> (engaged, (cal \\<Zcomp> num) s)} ]\"\n  \n\nzmachine TelephoneExchange =\n  over Exchange\n  init \"InitExchange\"\n  operations \n    LiftFree LiftSuspended Answer Dial \n    ClearAttempt ClearLine ClearConnect ClearSuspend ClearUnavail\n    MakeUnavail\n    Connect2Ringing Connect2Engaged\n    \ndef_consts Subs = \"{[1,2,3], [3,4,5], [6,7,8]}\"\n\nanimate TelephoneExchange\n\n\n\nend", "meta": {"author": "isabelle-utp", "repo": "Z_Machines", "sha": "72ed0f7b198d8e9f34efd10f1bff5351bbcab1a7", "save_path": "github-repos/isabelle/isabelle-utp-Z_Machines", "path": "github-repos/isabelle/isabelle-utp-Z_Machines/Z_Machines-72ed0f7b198d8e9f34efd10f1bff5351bbcab1a7/examples/TelephoneExchange.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7122321842389469, "lm_q2_score": 0.3775406687981454, "lm_q1q2_score": 0.2688966151771359}}
{"text": "theory IICF_List_List\nimports \n  \"../../Sepref\"\nbegin\n\n\n  context begin\n    private abbreviation (input) \"LR A \\<equiv> \\<langle>\\<langle>A\\<rangle>list_rel\\<rangle>list_rel\"\n\n    sepref_decl_op list_list_lempty: \"\\<lambda>n. replicate n []\" :: \"nat_rel \\<rightarrow> LR A\" .\n    sepref_decl_op list_list_push_back: \"\\<lambda>xss i x. xss[i:=xss!i@[x]]\" \n      :: \"[\\<lambda>((xss,i),_). i<length xss]\\<^sub>f (LR A \\<times>\\<^sub>r nat_rel) \\<times>\\<^sub>r A \\<rightarrow> LR A\" .\n\n    sepref_decl_op list_list_pop_back: \"\\<lambda>xss i. (last (xss!i), xss[i:=butlast (xss!i)])\" \n      :: \"[\\<lambda>(xss,i). i<length xss \\<and> xss!i\\<noteq>[]]\\<^sub>f (LR A \\<times>\\<^sub>r nat_rel)\\<rightarrow> A \\<times>\\<^sub>r LR A\" \n      unfolding conv_to_is_Nil short_circuit_conv\n      by parametricity\n      \n    sepref_decl_op list_list_idx: \"\\<lambda>xss i j. xss!i!j\" :: \"[\\<lambda>((xss,i),j). i<length xss \\<and> j<length (xss!i)]\\<^sub>f ((LR A \\<times>\\<^sub>r nat_rel) \\<times>\\<^sub>r nat_rel) \\<rightarrow> A\" \n      unfolding short_circuit_conv\n      by parametricity\n    \n    sepref_decl_op list_list_llen: \"\\<lambda>xss i. length (xss!i)\" :: \"[\\<lambda>(xss,i). i<length xss]\\<^sub>f LR A \\<times>\\<^sub>r nat_rel \\<rightarrow> nat_rel\" .\n    sepref_decl_op list_list_len: \"length :: _ list list \\<Rightarrow> _\" :: \"LR A \\<rightarrow> nat_rel\" .\n    \n    sepref_decl_op list_list_take: \"\\<lambda>xss i l. (xss[i:=take l (xss!i)])\" \n      :: \"[\\<lambda>((xss,i),l). i<length xss \\<and> l\\<le>length (xss!i)]\\<^sub>f ((LR A \\<times>\\<^sub>r nat_rel) \\<times>\\<^sub>r nat_rel)\\<rightarrow> LR A\" \n      unfolding conv_to_is_Nil short_circuit_conv\n      by parametricity\n    \n  end\n\n  locale list_list_custom_empty = \n    fixes rel empty PRE and op_custom_empty :: \"nat \\<Rightarrow> 'a list list\"\n    assumes customize_hnr_aux: \"(empty,(RETURN o (op_list_list_lempty::nat \\<Rightarrow> 'a list list))) \\<in> [PRE]\\<^sub>a snat_assn\\<^sup>k \\<rightarrow> rel\"\n    assumes op_custom_empty_def: \"op_custom_empty = op_list_list_lempty\"\n  begin\n    sepref_register op_custom_empty :: \"nat \\<Rightarrow> 'c list list\"\n  \n    lemma fold_custom_empty:\n      \"replicate n [] = op_custom_empty n\"\n      \"op_list_list_lempty = op_custom_empty\"\n      \"mop_list_list_lempty n = RETURN (op_custom_empty n)\"\n      unfolding op_custom_empty_def by simp_all\n  \n    lemmas custom_hnr[sepref_fr_rules] = customize_hnr_aux[folded op_custom_empty_def]\n  end\n\nend\n", "meta": {"author": "lammich", "repo": "isabelle_llvm", "sha": "6be37a9c3cae74a1134dbef2979e312abb5f7f42", "save_path": "github-repos/isabelle/lammich-isabelle_llvm", "path": "github-repos/isabelle/lammich-isabelle_llvm/isabelle_llvm-6be37a9c3cae74a1134dbef2979e312abb5f7f42/thys-2018/sepref/IICF/Intf/IICF_List_List.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5506073802837477, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.2688524411198931}}
{"text": "chapter \\<open>Basic Control Flow\\<close>\n\ntheory PhiSem_CF_Basic\n  imports PhiSem_Generic_Boolean\nbegin\n\nsection \\<open>Instructions\\<close>\n\nsubsection \\<open>Non-Branching Selection\\<close>\n\ndefinition op_sel :: \"TY \\<Rightarrow> (VAL \\<times> VAL \\<times> VAL, VAL) proc'\"\n  where \"op_sel TY =\n    \\<phi>M_caseV (\\<lambda>vc. \\<phi>M_caseV (\\<lambda>va vb.\n    \\<phi>M_getV bool V_bool.dest vc (\\<lambda>c.\n    \\<phi>M_getV TY id va (\\<lambda>a.\n    \\<phi>M_getV TY id vb (\\<lambda>b.\n    Return (\\<phi>arg (if c then b else a)))))))\"\n\nsubsection \\<open>Branch\\<close>\n\ndefinition op_if :: \"'ret proc\n                  \\<Rightarrow> 'ret proc\n                  \\<Rightarrow> (VAL,'ret::VALs) proc'\"\n  where \"op_if brT brF v =\n    \\<phi>M_getV bool V_bool.dest v (\\<lambda>c. (if c then brT else brF))\"\n\nsubsection \\<open>While Loop\\<close>\n\ninductive SemDoWhile :: \"VAL proc \\<Rightarrow> resource \\<Rightarrow> unit comp \\<Rightarrow> bool\" where\n  \"Success (\\<phi>arg (V_bool.mk False)) res \\<in> f s \\<Longrightarrow> SemDoWhile f s (Success (\\<phi>arg ()) res)\"\n| \"Success (\\<phi>arg (V_bool.mk True)) res \\<in> f s \\<Longrightarrow> SemDoWhile f res s'' \\<Longrightarrow> SemDoWhile f s s''\"\n| \"Abnormality v e \\<in> f s \\<Longrightarrow> SemDoWhile f s (Abnormality v e)\"\n| \"NonTerm \\<in> f s \\<Longrightarrow> SemDoWhile f s NonTerm\"\n| \"AssumptionBroken \\<in> f s \\<Longrightarrow> SemDoWhile f s AssumptionBroken\"\n| \"Invalid \\<in> f s \\<Longrightarrow> SemDoWhile f s Invalid\"\n\nlemma \"\\<nexists> y. SemDoWhile ((\\<lambda>res. Return (\\<phi>arg (V_bool.mk True)) res) :: VAL proc) res y\"\n  apply rule apply (elim exE) subgoal for y\n    apply (induct \"((\\<lambda>res. Return (\\<phi>arg (V_bool.mk True)) (res::resource)) :: VAL proc)\" res y\n           rule: SemDoWhile.induct)\n       apply (simp_all add: Return_def det_lift_def) . .\n\ndefinition op_do_while :: \" VAL proc \\<Rightarrow> unit proc\"\n  where \"op_do_while f s = Collect (SemDoWhile f s)\"\n\n(* lemma SemDoWhile_deterministic:\n  assumes \"SemDoWhile c s s1\"\n      and \"SemDoWhile c s s2\"\n    shows \"s1 = s2\"\nproof -\n  have \"SemDoWhile c s s1 \\<Longrightarrow> (\\<forall>s2. SemDoWhile c s s2 \\<longrightarrow> s1 = s2)\"\n    apply (induct rule: SemDoWhile.induct)\n    by (subst SemDoWhile.simps, simp)+\n  thus ?thesis\n    using assms by simp\nqed\n\nlemma SemDoWhile_deterministic2:\n    \"SemDoWhile body s x \\<Longrightarrow> The ( SemDoWhile body s) = x\"\n  using SemDoWhile_deterministic by blast *)\n\n\nsubsection \\<open>Recursion\\<close>\n\ninductive SemRec :: \"(('a,'a) proc' \\<Rightarrow> ('a,'a) proc')\n            \\<Rightarrow> 'a \\<phi>arg \\<Rightarrow> resource \\<Rightarrow> 'a comp set \\<Rightarrow> bool\"\nwhere\n  SemRec_I0: \"(\\<And>g. F g x res = y) \\<Longrightarrow> SemRec F x res y\"\n| SemRec_IS: \"SemRec (F o F) x res y \\<Longrightarrow> SemRec F x res y\"\n\ndefinition op_fix_point :: \"(('a,'a) proc' \\<Rightarrow> ('a,'a) proc')\n                         \\<Rightarrow> ('a,'a) proc'\"\n  where \"op_fix_point F x s = (if (\\<exists>t. SemRec F x s t) then The (SemRec F x s) else {})\"\n\n\n\nsubsubsection \\<open>Simple Properties\\<close>\n\nlemma SemRec_IR: \"SemRec F x r y \\<Longrightarrow> SemRec (F o F) x r y\"\n  by (induct rule: SemRec.induct, rule SemRec_I0, simp)\n\nlemma SemRec_deterministic:\n  assumes \"SemRec c s r s1\" and \"SemRec c s r s2\" shows \"s1 = s2\"\nproof -\n  have \"SemRec c s r s1 \\<Longrightarrow> (\\<forall>s2. SemRec c s r s2 \\<longrightarrow> s1 = s2)\"\n    apply (induct rule: SemRec.induct)\n     apply clarify\n    subgoal for F a b y s2 apply (rotate_tac 1)\n      apply (induct rule: SemRec.induct) by auto\n    apply clarify apply (blast intro: SemRec_IR) done\n  thus ?thesis using assms by simp\nqed\n\nlemma SemRec_deterministic2: \" SemRec body s r x \\<Longrightarrow> The (SemRec body s r) = x\"\n  using SemRec_deterministic by (metis theI_unique)\n\n\n\nsection \\<open>Abstraction of Procedures\\<close>\n\nsubsubsection \\<open>Syntax for Annotations\\<close>\n\nconsts Invariant :: \\<open>bool \\<Rightarrow> bool\\<close> (\"Inv: _\" [100] 36)\nconsts Guard :: \\<open>bool \\<Rightarrow> bool\\<close> (\"Guard: _\" [100] 36)\nconsts End   :: \\<open>bool \\<Rightarrow> bool\\<close> (\"End: _\" [100] 36)\n\nsubsection \\<open>Branch-like\\<close>\n\nlemma op_sel_\\<phi>app:\n  \\<open> \\<phi>SemType (a \\<Ztypecolon> A) TY\n\\<Longrightarrow> \\<phi>SemType (b \\<Ztypecolon> B) TY\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_sel TY (\\<phi>V_pair rawc (\\<phi>V_pair rawb rawa)) \\<lbrace>\n        a \\<Ztypecolon> \\<v>\\<a>\\<l>[rawa] A\\<heavy_comma> b \\<Ztypecolon> \\<v>\\<a>\\<l>[rawb] B\\<heavy_comma> c \\<Ztypecolon> \\<v>\\<a>\\<l>[rawc] \\<bool>\n    \\<longmapsto> (if c then a else b) \\<Ztypecolon> \\<v>\\<a>\\<l> (if c then A else B)\n    \\<rbrace>\\<close>\n  unfolding op_sel_def\n  by (cases rawc; cases rawb; cases rawa; cases c; simp add: \\<phi>SemType_def subset_iff,\n      rule, rule, rule, simp add: \\<phi>expns WT_bool, blast, rule, simp add: \\<phi>expns WT_bool, rule,\n      simp add: \\<phi>expns WT_bool, rule, simp add: \\<phi>expns WT_bool)\n\nlemma branch_\\<phi>app:\n  \\<open> (\\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e>   C \\<longrightarrow> \\<p>\\<r>\\<o>\\<c> br\\<^sub>T \\<lbrace> X \\<longmapsto> Y\\<^sub>T \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\\<^sub>T )\n\\<Longrightarrow> (\\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> \\<not> C \\<longrightarrow> \\<p>\\<r>\\<o>\\<c> br\\<^sub>F \\<lbrace> X \\<longmapsto> Y\\<^sub>F \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\\<^sub>F )\n\\<Longrightarrow> (\\<And>v. If C (Y\\<^sub>T v) (Y\\<^sub>F v) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> Y v @action invoke_branch_convergence)\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_if br\\<^sub>T br\\<^sub>F rawc \\<lbrace> X\\<heavy_comma> C \\<Ztypecolon> \\<v>\\<a>\\<l>[rawc] \\<bool> \\<longmapsto> Y \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> (\\<lambda>e. (E\\<^sub>T e \\<s>\\<u>\\<b>\\<j> C) + (E\\<^sub>F e \\<s>\\<u>\\<b>\\<j> \\<not> C)) \\<close>\n  unfolding op_if_def Premise_def Action_Tag_def\n  apply (cases rawc; cases C; simp; rule; simp add: \\<phi>expns WT_bool)\n  using \\<phi>CONSEQ view_shift_by_implication view_shift_refl by blast+\n\nproc \"if\":\n  assumes C: \\<open>\\<p>\\<r>\\<o>\\<c> cond \\<lbrace> X \\<longmapsto> X1\\<heavy_comma> \\<v>\\<a>\\<l> C \\<Ztypecolon> \\<bool> \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E \\<close>\n      and brT: \\<open>\\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e>   C \\<longrightarrow> \\<p>\\<r>\\<o>\\<c> brT \\<lbrace> X1 \\<longmapsto> Y\\<^sub>T \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\\<^sub>T \\<close>\n      and brF: \\<open>\\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> \\<not> C \\<longrightarrow> \\<p>\\<r>\\<o>\\<c> brF \\<lbrace> X1 \\<longmapsto> Y\\<^sub>F \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\\<^sub>F \\<close>\n      and BC: \\<open>(\\<And>v. If C (Y\\<^sub>T v) (Y\\<^sub>F v) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> Y v @action invoke_branch_convergence)\\<close>\n  input  \\<open>X\\<close>\n  output \\<open>Y\\<close>\n  throws \\<open>E + E\\<^sub>T + E\\<^sub>F\\<close>\n  \\<medium_left_bracket> C branch brT brF BC \\<medium_right_bracket>. .\n\n\nsubsection \\<open>Loops\\<close>\n\nlemma \"__DoWhile__rule_\\<phi>app\":\n  \" \\<p>\\<r>\\<o>\\<c> body \\<lbrace> X x \\<s>\\<u>\\<b>\\<j> x. P x \\<longmapsto> (\\<exists>*x'. X x' \\<heavy_comma> \\<v>\\<a>\\<l> P x' \\<Ztypecolon> \\<bool>) \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_do_while body \\<lbrace> X x \\<s>\\<u>\\<b>\\<j> x. P x \\<longmapsto> X x' \\<s>\\<u>\\<b>\\<j> x'. \\<not> P x' \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E \"\n  unfolding op_do_while_def \\<phi>Procedure_def\n  apply (simp add: subset_iff LooseStateSpec_expn')\n  apply (rule allI impI conjI)+\n  subgoal for comp R s\n  apply (rotate_tac 2)\n    apply (induct body comp s rule: SemDoWhile.induct; clarsimp simp add: \\<phi>expns times_list_def)\n    apply fastforce\n    subgoal premises prems for res f s s'' c u v proof -\n      have t1: \\<open>\\<exists>c. (\\<exists>fic. (\\<exists>u v. fic = u * v \\<and> u \\<in> R \\<and> v \\<in> X c \\<and> u ## v) \\<and> s \\<in> INTERP_RES fic) \\<and> P c\\<close>\n        using prems(5) prems(6) prems(7) prems(8) prems(9) by blast\n      show ?thesis\n        apply (insert \\<open>\\<forall>_ _. (\\<exists>_. _) \\<longrightarrow> _\\<close>[THEN spec[where x=s], THEN spec[where x=R], THEN mp, OF t1])\n        using prems(1) prems(3) by fastforce\n    qed\n    apply fastforce\n    by blast .\n\nproc (nodef) do_while:\nassumes \\<open>\\<p>\\<a>\\<r>\\<a>\\<m> ( X' x \\<s>\\<u>\\<b>\\<j> x. Inv: invariant x \\<and> Guard: cond x)\\<close>\n    and V: \\<open>X \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> ( X' x \\<s>\\<u>\\<b>\\<j> x. invariant x \\<and> cond x) \\<a>\\<n>\\<d> Any @action ToSA\\<close>\nassumes B: \\<open>\\<forall>x. \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> cond x \\<longrightarrow> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> invariant x\n    \\<longrightarrow> \\<p>\\<r>\\<o>\\<c> body \\<lbrace> X' x \\<longmapsto> (X' x'\\<heavy_comma> \\<v>\\<a>\\<l> cond x' \\<Ztypecolon> \\<bool> \\<s>\\<u>\\<b>\\<j> x'. invariant x') \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E \\<close>\ninput  \\<open>X\\<close>\noutput \\<open>X' x' \\<s>\\<u>\\<b>\\<j> x'. invariant x' \\<and> \\<not> cond x'\\<close>\nthrows E\n  \\<medium_left_bracket>\n    V[unfolded Action_Tag_def]\n    \"__DoWhile__rule_\\<phi>app\"[where P=cond and X=\\<open>\\<lambda>x'. X' x' \\<s>\\<u>\\<b>\\<j> invariant x'\\<close>, simplified]\n  \\<medium_left_bracket> B \\<medium_right_bracket>.\n  \\<medium_right_bracket> by simp .\n\nproc while:\n  assumes \\<open>\\<p>\\<a>\\<r>\\<a>\\<m> ( X x \\<s>\\<u>\\<b>\\<j> x. Inv: invariant x \\<and> Guard: cond x)\\<close>\n  assumes V[unfolded Action_Tag_def]:\n           \"X' \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> ((X x \\<r>\\<e>\\<m>\\<a>\\<i>\\<n>\\<s> R) \\<s>\\<u>\\<b>\\<j> x. invariant x) \\<a>\\<n>\\<d> Any @action ToSA\"\n    and C: \"\\<forall>x. \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> invariant x \\<longrightarrow> \\<p>\\<r>\\<o>\\<c> Cond \\<lbrace> R\\<heavy_comma> X x \\<longmapsto> R\\<heavy_comma> X x'\\<heavy_comma> \\<v>\\<a>\\<l> cond x' \\<Ztypecolon> \\<bool> \\<s>\\<u>\\<b>\\<j> x'. invariant x' \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E1\"\n    and B: \"\\<forall>x. \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> invariant x \\<longrightarrow> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> cond x \\<longrightarrow> \\<p>\\<r>\\<o>\\<c> Body \\<lbrace> R\\<heavy_comma> X x \\<longmapsto> R\\<heavy_comma> X x' \\<s>\\<u>\\<b>\\<j> x'. invariant x' \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E2\"\n  input  \\<open>X'\\<close>\n  output \\<open>R\\<heavy_comma> X x \\<s>\\<u>\\<b>\\<j> x. invariant x \\<and> \\<not> cond x\\<close>\n  throws \\<open>E1 + E2\\<close>\n  \\<medium_left_bracket> V C\n    branch \\<medium_left_bracket>\n      do_while \\<open>R\\<heavy_comma> X vars \\<s>\\<u>\\<b>\\<j> vars. Inv: invariant vars \\<and> Guard: cond vars\\<close>\n      \\<medium_left_bracket> B C \\<medium_right_bracket>.\n      \\<medium_right_bracket>.\n    \\<medium_left_bracket> \\<medium_right_bracket> for \\<open>R\\<heavy_comma> X vars \\<s>\\<u>\\<b>\\<j> vars. invariant vars \\<and> \\<not> cond vars\\<close> ..\n  \\<medium_right_bracket> .. .\n\n(*\nWe fail to infer the abstraction of the loop guard automatically but\nrequire users to give by an annotation.\nThe main difficulty is about the nondeterminancy in higher-order unification.\nIn \\<^term>\\<open>cond x' \\<Ztypecolon> \\<bool>\\<close> in the above rule, both \\<open>cond\\<close> and \\<open>x'\\<close> are schematic variables,\nwhich means we cannot determine either of them via unification.\nEven though the abstract state \\<open>x'\\<close> may be determined possibly in the unification of \\<open>X x'\\<close>,\nto infer \\<open>cond x'\\<close> it is still a problem especially when \\<open>x'\\<close> is not a variable but a compounded\nterm and its expression may be shattered in and mixed up with the expression of \\<open>cond\\<close> after\nsimplifications like beta reduction,\ncausing it is very difficult to recover the actual abstract guard\n\\<open>cond\\<close> from the reduced composition \\<open>cond x'\\<close>.\n*)\n\n\nsubsection \\<open>Recursion\\<close>\n\nlemma \"__op_recursion_simp__\":\n  \"(\\<And>g x' v'. (\\<And>x'' v''. \\<p>\\<r>\\<o>\\<c> g v''  \\<lbrace> X x'' v'' \\<longmapsto> \\<lambda>ret. Y x'' ret \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E x'')\n                      \\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> F g v' \\<lbrace> X x' v'   \\<longmapsto> \\<lambda>ret. Y x'  ret \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E x' )\n\\<Longrightarrow> \\<forall>x v. \\<p>\\<r>\\<o>\\<c> op_fix_point F v \\<lbrace> X x v \\<longmapsto> \\<lambda>ret. Y x ret \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E x\"\n  unfolding op_fix_point_def \\<phi>Procedure_def atomize_all\n  apply (clarsimp simp add: SemRec_deterministic2 del: subsetI)\n\n  subgoal for x v comp a R\n    apply (rotate_tac 1) apply (induct rule: SemRec.induct)\n\n    subgoal premises prems for F v res y\n      using prems(3)[of \\<open>\\<lambda>_ _. {AssumptionBroken}\\<close> x v, simplified, THEN spec[where x=res],\n                     THEN spec[where x=R], THEN mp, OF prems(2), unfolded prems(1)] .\n    by simp .\n\ntext \\<open>Instead, we use a variant of the above rule which in addition annotates the names\n  of the values.\\<close>\n\nlemma \"__op_recursion__\":\n  \"(\\<And>g x' (v':: 'a::VALs \\<phi>arg <named> 'names).\n          P x'\n      \\<Longrightarrow> PROP Labelled label (HIDDEN_PREM\n          (\\<And>x'' (v''::'a \\<phi>arg <named> 'names).\n              P x'' \\<Longrightarrow>\n              \\<p>\\<r>\\<o>\\<c> g (case_named id v'') \\<lbrace> case_named (X x'') v'' \\<longmapsto> \\<lambda>ret. Y x'' ret \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E x''))\n      \\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> F g (case_named id v') \\<lbrace> case_named (X x') v'   \\<longmapsto> \\<lambda>ret. Y x'  ret \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E x' )\n\\<Longrightarrow> PROP Pure.prop (\n      P x \\<Longrightarrow>\n      \\<p>\\<r>\\<o>\\<c> op_fix_point F v \\<lbrace> X x v \\<longmapsto> \\<lambda>ret. Y x ret \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E x\n)\"\n  unfolding op_fix_point_def \\<phi>Procedure_def atomize_all \\<phi>arg_forall \\<phi>arg_All HIDDEN_PREM_def\n            Pure.prop_def\n  apply (clarsimp simp add: SemRec_deterministic2 del: subsetI)\n\n  subgoal for comp a R\n    apply (rotate_tac 2) apply (induct rule: SemRec.induct)\n\n    subgoal premises prems for F v res y\n      using prems(3)[OF prems(4),\n                     of \\<open>\\<lambda>_ _. {AssumptionBroken}\\<close> v, simplified, THEN spec[where x=res],\n                     THEN spec[where x=R], THEN mp, OF prems(2), unfolded prems(1)] .\n    by simp .\n\n\nML_file \\<open>library/basic_recursion.ML\\<close>\n\nattribute_setup recursive = \\<open>Scan.repeat (Scan.lift Parse.term) >> (fn vars =>\n    Phi_Modifier.wrap_to_attribute (fn (ctxt,sequent) =>\n      case Phi_Toplevel.name_of_the_building_procedure ctxt\n        of NONE => error \"Name binding of the recursive procedure is mandatory.\"\n         | SOME b => (\n            if Binding.is_empty b\n            then error \"Name binding of the recursive procedure is mandatory.\"\n            else if null vars then tracing \"You may want to use syntax \\<open>recursive vars\\<close> to indicate \\\n                 \\which variables are varied between the recursive callings.\" else ();\n            PhiSem_Control_Flow.basic_recursive_mod Syntax.read_terms b vars (ctxt,sequent)\n           )\n  ))\\<close>\n\nend", "meta": {"author": "xqyww123", "repo": "phi-system", "sha": "c8dca186bcc8ac2c9b38d813fc0f0dfec486ebab", "save_path": "github-repos/isabelle/xqyww123-phi-system", "path": "github-repos/isabelle/xqyww123-phi-system/phi-system-c8dca186bcc8ac2c9b38d813fc0f0dfec486ebab/Phi_Semantics/PhiSem_CF_Basic.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.550607350786733, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.2688524267169906}}
{"text": "section \\<open>Preparing Partial Order Reduction\\<close>\ntheory SM_Visible\nimports \"../RefPoint/SM_LTL\" Rename_Cfg\nbegin\n\n  section \\<open>Visible Part of State\\<close>\n\n  locale visible_prog = well_typed_prog +\n    fixes is_vis_var :: \"ident \\<Rightarrow> bool\"\n  begin\n    abbreviation \"vis_vars \\<equiv> Collect is_vis_var\"\n\n    definition interp_gs :: \"global_state \\<Rightarrow> exp set\" where\n      \"interp_gs gs \\<equiv> sm_props (global_state.variables gs |` vis_vars)\"\n  \n    definition interp_gc :: \"global_config \\<Rightarrow> exp set\" where\n      \"interp_gc gc \\<equiv> interp_gs (global_config.state gc)\"\n    \n    sublocale lv: Gen_Scheduler'_linit\n      cfgc la_en' la_ex' \n      \"{init_gc}\" interp_gc .\n\n    lemma lv_accept_conv: \"lv.sa.accept w \n      \\<longleftrightarrow> (\\<exists>w'. w=interp_gs o w' \\<and> ref_accept prog w')\"\n      unfolding lih'_accept_eq[symmetric]\n      unfolding lih'.sa.accept_def lv.sa.accept_def\n      unfolding lih'.sa.is_run_def\n      unfolding lv.sa.is_run_def\n      apply simp\n      unfolding interp_gc_def[abs_def]\n      by fastforce\n\n  end\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/CAVA_LTL_Modelchecker/SM/Refine/SM_Visible.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926665999540698, "lm_q2_score": 0.4532618480153861, "lm_q1q2_score": 0.2686331583521772}}
{"text": "\n\ntheory X86_Parse_Hoare_Triples\n  imports X86_InstructionSemantics\n  keywords \"htriple\" :: thy_decl\n\n  and \"Separations\" \"Assertions\" \"Pre\" \"Post\" \"Instruction\" \"FunctionConstraints\" :: quasi_command\n\nbegin\n\ncontext semantics\nbegin \n\nlemma ucast_take_bits_8[simp]:\n  fixes a :: \"'b::len word\" \n  assumes \"LENGTH('b) > 8\"\n  shows \"((ucast (\\<langle>0,8\\<rangle>a)::'a ::len word) = ucast (ucast a :: 8 word))\"\n  using assms\n  by (auto simp add: word_eq_iff word_size nth_ucast nth_takebits)\n\nlemma ucast_take_bits_16[simp]:\n  fixes a :: \"'b::len word\" \n  assumes \"LENGTH('b) > 16\"\n  shows \"((ucast (\\<langle>0,16\\<rangle>a)::'a::len word) = ucast (ucast a :: 16 word))\"\n  using assms\n  by (auto simp add: word_eq_iff word_size nth_ucast nth_takebits)\n\nlemma ucast_take_bits_32[simp]:\n  fixes a :: \"'b::len word\" \n  assumes \"LENGTH('b) > 32\"\n  shows \"((ucast (\\<langle>0,32\\<rangle>a)::'a::len word) = ucast (ucast a :: 32 word))\"\n  using assms\n  by (auto simp add: word_eq_iff word_size nth_ucast nth_takebits)\n\nlemma ucast_ucast_ucast[simp]:\n  assumes \"LENGTH('c) < LENGTH('b)\"\n  shows  \"(ucast (ucast (ucast (w::'a::len word)::'b::len word)::'c::len word)::'d::len word) = ucast (ucast w::'c::len word)\"\n  using assms\n  by (auto simp add: word_eq_iff nth_ucast)\n\nlemma scast_ucast_ucast[simp]:\n  assumes \"LENGTH('c) < LENGTH('b)\"\n  shows  \"(scast (ucast (ucast (w::'a::len word)::'b::len word)::'c::len word)::'d::len word) = scast (ucast w::'c::len word)\"\n  using assms\n  by (auto simp add: word_eq_iff nth_ucast nth_scast)\n\nlemma test_bit_mem_read:\n  shows \"mem_read \\<sigma> a si !! n \\<Longrightarrow> n < si*8\"\n  by (auto simp add: mem_read_def test_bit_rcat word_size rev_nth length_read_bytes)\n\nlemma ucast_ucast_mem_read_8[simp]:\nassumes \"LENGTH('a) > 8\"\n  shows \"(ucast (ucast (mem_read \\<sigma> a 1)::'a::len word) :: 8 word) = ucast (mem_read \\<sigma> a 1)\"\n  apply (subst word_eq_iff)+\n  using test_bit_mem_read[of \\<sigma> a 4] assms\n  by (auto simp add: word_size nth_ucast)\n\nlemma ucast_ucast_mem_read_16[simp]:\nassumes \"LENGTH('a) > 16\"\n  shows \"(ucast (ucast (mem_read \\<sigma> a 2)::'a::len word) :: 16 word) = ucast (mem_read \\<sigma> a 2)\"\n  apply (subst word_eq_iff)+\n  using test_bit_mem_read[of \\<sigma> a 4] assms\n  by (auto simp add: word_size nth_ucast)\n\nlemma ucast_ucast_mem_read_32[simp]:\n  assumes \"LENGTH('a) > 32\"\n  shows \"(ucast (ucast (mem_read \\<sigma> a 4)::'a::len word) :: 32 word) = ucast (mem_read \\<sigma> a 4)\"\n  apply (subst word_eq_iff)+\n  using test_bit_mem_read[of \\<sigma> a 4] assms\n  by (auto simp add: word_size nth_ucast)\n\nlemma ucast_ucast_mem_read_1byte[simp]:\nassumes \"LENGTH('a) > 8\" and \"LENGTH('b) > 8\"\n  shows \"(ucast (ucast (mem_read \\<sigma> a 1)::'a::len word) :: 'b::len word) = ucast (mem_read \\<sigma> a 1)\"\n  apply (subst word_eq_iff)+\n  using test_bit_mem_read[of \\<sigma> a 1] assms\n  apply (auto simp add: word_size nth_ucast)\n  by (meson le_eq_less_or_eq le_less_trans)\n\nlemma ucast_ucast_mem_read_2bytes[simp]:\nassumes \"LENGTH('a) > 16\" and \"LENGTH('b) > 16\"\n  shows \"(ucast (ucast (mem_read \\<sigma> a 2)::'a::len word) :: 'b::len word) = ucast (mem_read \\<sigma> a 2)\"\n  apply (subst word_eq_iff)+\n  using test_bit_mem_read[of \\<sigma> a 2] assms\n  apply (auto simp add: word_size nth_ucast)\n  by (meson le_eq_less_or_eq le_less_trans)\n\nlemma ucast_ucast_mem_read_4bytes[simp]:\nassumes \"LENGTH('a) > 32\" and \"LENGTH('b) > 32\"\n  shows \"(ucast (ucast (mem_read \\<sigma> a 4)::'a::len word) :: 'b::len word) = ucast (mem_read \\<sigma> a 4)\"\n  apply (subst word_eq_iff)+\n  using test_bit_mem_read[of \\<sigma> a 4] assms\n  apply (auto simp add: word_size nth_ucast)\n  by (meson le_eq_less_or_eq le_less_trans)\n\nlemma ucast_mem_read_cmp_8[simp]:\nfixes \\<sigma> :: state and b :: \"'a::len word\"\nassumes \"LENGTH('a) > 8\"\n  shows \"(ucast (mem_read \\<sigma> a 1)) = b \\<longleftrightarrow> ucast (ucast (mem_read \\<sigma> a 1)::8 word) = b\"\n  using test_bit_mem_read[of \\<sigma> a 1] test_bit_size[of b]\n  by (auto simp add: word_eq_iff word_size nth_ucast nth_takebits)\n\nlemma ucast_mem_read_cmp_16[simp]:\nfixes \\<sigma> :: state and b :: \"'a::len word\"\nassumes \"LENGTH('a) > 16\"\n  shows \"(ucast (mem_read \\<sigma> a 2)) = b \\<longleftrightarrow> ucast (ucast (mem_read \\<sigma> a 2)::16 word) = b\"\n  using test_bit_mem_read[of \\<sigma> a 2] test_bit_size[of b]\n  by (auto simp add: word_eq_iff word_size nth_ucast nth_takebits)\n\nlemma ucast_mem_read_cmp_32[simp]:\nfixes \\<sigma> :: state and b :: \"'a::len word\"\nassumes \"LENGTH('a) > 32\"\n  shows \"(ucast (mem_read \\<sigma> a 4)) = b \\<longleftrightarrow> ucast (ucast (mem_read \\<sigma> a 4)::32 word) = b\"\n  using test_bit_mem_read[of \\<sigma> a 4] test_bit_size[of b]\n  by (auto simp add: word_eq_iff word_size nth_ucast nth_takebits)\n\n\n\n\n\n\nlemma ucast_overwrite[simp]:\n  shows \"ucast (overwrite 0 n a b) = overwrite 0 n (ucast a) (ucast b)\"\n  using test_bit_size[of a] test_bit_size[of b]\n  by (auto simp add: word_eq_iff nth_ucast overwrite_def nth_shiftl nth_takebits word_size)\n\nlemma takebits_overwrite[simp]:\n  shows \"(\\<langle>0,h\\<rangle> (overwrite 0 n a b)) = overwrite 0 n (\\<langle>0,h\\<rangle> a) (\\<langle>0,h\\<rangle> b)\"\n  using test_bit_size[of a] test_bit_size[of b]\n  by (auto simp add: word_eq_iff nth_ucast overwrite_def nth_shiftl nth_takebits word_size)\n\nlemma overwrite_overwrite_l[simp]:\n  shows \"overwrite 0 h (overwrite 0 h a b) c = overwrite 0 h a c\"\n  by (auto simp add: word_eq_iff nth_ucast overwrite_def nth_shiftl nth_takebits word_size)\n\nlemma overwrite_overwrite_r[simp]:\n  shows \"overwrite 0 h a (overwrite 0 h b c) = overwrite 0 h a c\"\n  by (auto simp add: word_eq_iff nth_ucast overwrite_def nth_shiftl nth_takebits word_size)\n\nlemma overwrite_all_8[simp]:\n  fixes a :: \"8 word\"\n  shows \"overwrite 0 8 a b = b\"\n  by (auto simp add: word_eq_iff overwrite_def nth_shiftl nth_takebits)\n\nlemma overwrite_all_16[simp]:\n  fixes a :: \"16 word\"\n  shows \"overwrite 0 16 a b = b\"\n  by (auto simp add: word_eq_iff overwrite_def nth_shiftl nth_takebits)\n\n\n\nlemma ucast_AND[simp]:\n  shows \"ucast (a AND b) = ucast a AND ucast b\"\n  by (auto simp add: word_eq_iff nth_ucast)\n\nlemma ucast_OR[simp]:\n  shows \"ucast (a OR b) = ucast a OR ucast b\"\n  by (auto simp add: word_eq_iff nth_ucast)\n\nlemma ucast_XOR[simp]:\n  shows \"ucast (a XOR b) = ucast a XOR ucast b\"\n  by (auto simp add: word_eq_iff nth_ucast)\n\nlemma take_bits_AND[simp]:\n  shows \"(\\<langle>l,h\\<rangle> (a AND b)) = (\\<langle>l,h\\<rangle> a) AND (\\<langle>l,h\\<rangle> b)\"\n  by (auto simp add: word_eq_iff nth_ucast nth_takebits)\n\nlemma take_bits_OR[simp]:\n  shows \"(\\<langle>l,h\\<rangle> (a OR b)) = (\\<langle>l,h\\<rangle> a) OR (\\<langle>l,h\\<rangle> b)\"\n  by (auto simp add: word_eq_iff nth_ucast nth_takebits)\n\nlemma take_bits_XOR[simp]:\n  shows \"(\\<langle>l,h\\<rangle> (a XOR b)) = (\\<langle>l,h\\<rangle> a) XOR (\\<langle>l,h\\<rangle> b)\"\n  by (auto simp add: word_eq_iff nth_ucast nth_takebits)\n\n\n\nlemma dummy:\n  assumes \"LENGTH('a) < 0\" and \"LENGTH('b) < 0\"\n  shows \"(ucast (a::'a::len word) ::'b::len word) = x\"\n  using assms\n  by auto\n\nlemma dummy':\n  assumes \"LENGTH('a) < 0\" and \"LENGTH('b) < 0\"\n  shows \"(scast (a::'a::len word) ::'b::len word) = x\"\n  using assms\n  by auto\n\n\n\n\n\n\n\n\nML_file \\<open>X86_Parse_Hoare_Triple.ML\\<close>\n\n\nML \\<open>\n(*\n  If thm is of the form (thm0 \\<and> thm1), return the conjuncts.\n*)\nfun split_conj thm =\n  case (Thm.prop_of thm) of\n    (Const (\"HOL.Trueprop\", _) $ (Const (\"HOL.conj\", _) $ _ $ _)) => SOME (thm RS @{thm conjunct1} ,thm RS @{thm conjunct2})\n  | _ => NONE;\n\n(*\n  conjs = thm0 \\<and> thm1 \\<and> ...\n  Searches a conjunct equal to thm.\n  If found, insert the found conjunct as assumption.\n*)\n\nfun insert_assumption_from_conjunct ctxt conjs thm =\n  case split_conj conjs of\n    NONE => \n      if Envir.aeconv (Thm.prop_of conjs,Thm.major_prem_of thm) then\n        SOME (Method.insert_tac ctxt [conjs])\n      else if Envir.aeconv (Thm.prop_of conjs,Thm.major_prem_of thm) then\n        SOME (Method.insert_tac ctxt [conjs])\n      else\n        NONE  \n  | SOME (conj0,conj1) =>\n      case insert_assumption_from_conjunct ctxt conj0 thm of\n        NONE => insert_assumption_from_conjunct ctxt conj1 thm\n      | SOME thm' => SOME thm'\n\n\nfun from_conjunctive_assm_tactic assm ctxt i thm =\n   if Thm.no_prems thm then\n     Seq.single thm\n   else case insert_assumption_from_conjunct ctxt assm thm of\n        NONE => Seq.empty\n      | SOME tac => Seq.maps (Seq.single o Thm.eq_assumption i) (tac i thm)\n\n\ninfix 1 DETERM_THEN AND_IF_NOT_SOLVED;\n\nfun tac1 DETERM_THEN tac2 = fn thm =>\n  let val result = tac1 thm \n  in\n    case Seq.pull result of\n      NONE => Seq.empty\n    | SOME (thm',_) => tac2 thm'\n  end\n\nfun tac1 AND_IF_NOT_SOLVED tac2 = fn thm =>\n  let val result = tac1 thm \n  in\n    case Seq.pull result of\n      NONE => tac2 thm\n    | SOME (thm',_) => if Thm.nprems_of thm' < Thm.nprems_of thm then Seq.single thm' else tac2 thm'\n  end\n\nfun add_simps simp_theorems = fold Simplifier.add_simp simp_theorems\n\n(*\n  apply (subst mem_read_mem_write_separate)\n  apply (from_conjunctive_assm conjI[OF seps asserts,simplified])\n  apply (insert conjI[OF seps asserts,simplified])[1]\n  apply (erule conjE)+\n  apply (simp (no_asm_simp) add: state_simps BitByte_simps separate_simps)\n  apply (simp only: algeba_simps_small)?\n  apply (simp add: state_simps BitByte_simps separate_simps)\n  apply (simp only: algeba_simps_small)?\n*)\nfun resolve_mem_read_tactic seps ctxt i =\n  let val tac1 = CHANGED (EqSubst.eqsubst_tac ctxt [0] [@{thm mem_read_mem_write_separate}] i)\n      val tac2 = HEADGOAL (from_conjunctive_assm_tactic seps ctxt)\n      val tac3 = HEADGOAL (Method.insert_tac ctxt [seps])\n      val tac4 = REPEAT_DETERM (HEADGOAL (eresolve_tac ctxt [@{thm conjE}]))\n      val simp_theorems = @{thms state_simps BitByte_simps separate_simps}\n      val ctxt' = add_simps simp_theorems ctxt\n      val tac5 = HEADGOAL (asm_simp_tac ctxt')\n      val ctxt_only_commutes = add_simps @{thms algebra_simps} (Raw_Simplifier.clear_simpset ctxt)\n      val tac6 = HEADGOAL (full_simp_tac ctxt_only_commutes)\n      val tac7 = HEADGOAL (asm_full_simp_tac ctxt')\n      val tac8 = tac6\n  in\n    CHANGED (\n      tac1 DETERM_THEN \n        (  (DETERM tac2)\n        ORELSE \n           (tac3 DETERM_THEN tac4 DETERM_THEN (tac5 AND_IF_NOT_SOLVED tac6 AND_IF_NOT_SOLVED tac7 AND_IF_NOT_SOLVED tac8))\n        )\n    )\n  end\n\\<close>                                 \nmethod_setup from_conjunctive_assm = \\<open>\n   Attrib.thm >> (fn (assm) => fn ctxt =>\n     SIMPLE_METHOD' (fn i => fn thm =>\n        if Thm.no_prems thm then\n          Seq.single thm\n        else case insert_assumption_from_conjunct ctxt assm thm of\n             NONE => Seq.empty\n           | SOME tac => Seq.maps (Seq.single o Thm.eq_assumption i) (tac i thm)\n        ))\n\\<close>\n\nmethod_setup resolve_mem_read = \\<open>\n   Attrib.thm >> (fn (assm) => fn ctxt => \n      SIMPLE_METHOD' (fn i => fn thm =>\n        if Thm.no_prems thm then\n          Seq.single thm\n        else\n          resolve_mem_read_tactic assm ctxt i thm\n     ))\n\\<close>\n\nmethod_setup eq_assumption = \\<open>Scan.succeed (fn ctxt => SIMPLE_METHOD' (PRIMITIVE o Thm.eq_assumption))\\<close>\n\nML \\<open>\nfun REPEAT_WHILE_CHANGING tac = fn thm =>\n  let val result = (CHANGED tac) thm \n  in\n    case Seq.pull result of\n      NONE => Seq.single thm\n    | SOME (thm',_) => REPEAT_WHILE_CHANGING tac thm'\n  end\n\nfun REPEAT_WHILE_SOLVING tac = fn thm =>\n  let val result = (CHANGED tac) thm \n  in\n    case Seq.pull result of\n      NONE => Seq.single thm\n    | SOME (thm',_) => if Thm.nprems_of thm' < Thm.nprems_of thm then REPEAT_WHILE_SOLVING tac thm' else Seq.single thm\n  end\n\nfun FAIL_IF_GENERATES_NEW_GOALS tac = fn thm =>\n  let val result = (CHANGED tac) thm \n  in\n    case Seq.pull result of\n      NONE => Seq.empty\n    | SOME (thm',_) => if Thm.nprems_of thm' > Thm.nprems_of thm then Seq.empty else Seq.single thm'\n  end\n\\<close>\n\nmethod_setup repeat_while_changing = \\<open>\n  Method.text_closure >> (fn m => fn ctxt => fn _ =>\n      CONTEXT_TACTIC (REPEAT_WHILE_CHANGING (NO_CONTEXT_TACTIC ctxt (Method.evaluate m ctxt []))))\n\\<close>\n\nmethod_setup fail_if_generates_new_goals = \\<open>\n  Method.text_closure >> (fn m => fn ctxt => fn _ =>\n    CONTEXT_TACTIC (FAIL_IF_GENERATES_NEW_GOALS (NO_CONTEXT_TACTIC ctxt (Method.evaluate m ctxt []))))\n\\<close>\n\nmethod_setup repeat_while_solving = \\<open>\n  Method.text_closure >> (fn m => fn ctxt => fn _ =>\n    CONTEXT_TACTIC (REPEAT_WHILE_SOLVING (NO_CONTEXT_TACTIC ctxt (Method.evaluate m ctxt []))))\n\\<close>\n\n\nmethod se_step uses assms seps = (\n  (insert assms)[1],\n  (erule conjE)+,\n  (  (simp (no_asm_use) add: state_simps BitByte_simps separate_simps)? ;\n     (repeat_while_changing\n         \\<open>(simp only: algebra_simps)?,\n          (simp (no_asm_simp) add: state_simps BitByte_simps separate_simps)?,\n          (fail_if_generates_new_goals \\<open>resolve_mem_read seps\\<close>)?\\<close>\n     )\n  )\n )\n\nmethod htriple_solver uses seps assms = (\n    (simp add: semantics_simps state_simps BitByte_simps separate_simps del: Let_def),\n    (auto simp add: semantics_simps state_simps BitByte_simps separate_simps)?,\n    (repeat_while_solving \\<open>se_step assms: assms seps: seps\\<close>)\n )\n\n(*\n  apply (simp add: semantics_simps state_simps BitByte_simps separate_simps del: Let_def)\n  apply (auto simp add: semantics_simps state_simps BitByte_simps separate_simps)?\n  apply (repeat_while_changing \\<open>se_step assms: assms seps: conjI[OF seps asserts,simplified]\\<close>)\n  apply (se_step assms: assms seps: conjI[OF seps asserts,simplified])\n\n  apply (insert assms)[1]\n  apply (erule conjE)+\n  apply (simp (no_asm_use) add: state_simps BitByte_simps separate_simps)\n  (* repeat *)\n  apply (simp only: algebra_simps)\n  apply (simp (no_asm_simp) add: state_simps BitByte_simps separate_simps)\n  apply (simp only: algebra_simps)\n  apply (fail_if_generates_new_goals \\<open>resolve_mem_read conjI[OF seps asserts,simplified]\\<close>)\n\n*)\n\nend\n\n\n\nabbreviation ucast\\<^sub>3\\<^sub>2\\<^sub>_\\<^sub>6\\<^sub>4 :: \"32 word \\<Rightarrow> 64 word\"\n  where \"ucast\\<^sub>3\\<^sub>2\\<^sub>_\\<^sub>6\\<^sub>4 \\<equiv> ucast\"\nabbreviation ucast\\<^sub>6\\<^sub>4\\<^sub>_\\<^sub>3\\<^sub>2 :: \"64 word \\<Rightarrow> 32 word\"\n  where \"ucast\\<^sub>6\\<^sub>4\\<^sub>_\\<^sub>3\\<^sub>2 \\<equiv> ucast\"\nabbreviation ucast\\<^sub>1\\<^sub>6\\<^sub>_\\<^sub>6\\<^sub>4 :: \"16 word \\<Rightarrow> 64 word\"\n  where \"ucast\\<^sub>1\\<^sub>6\\<^sub>_\\<^sub>6\\<^sub>4 \\<equiv> ucast\"\nabbreviation ucast\\<^sub>6\\<^sub>4\\<^sub>_\\<^sub>1\\<^sub>6 :: \"64 word \\<Rightarrow> 16 word\"\n  where \"ucast\\<^sub>6\\<^sub>4\\<^sub>_\\<^sub>1\\<^sub>6 \\<equiv> ucast\"\nabbreviation ucast\\<^sub>8\\<^sub>_\\<^sub>6\\<^sub>4 :: \"8 word \\<Rightarrow> 64 word\"\n  where \"ucast\\<^sub>8\\<^sub>_\\<^sub>6\\<^sub>4 \\<equiv> ucast\"\nabbreviation ucast\\<^sub>6\\<^sub>4\\<^sub>_\\<^sub>8 :: \"64 word \\<Rightarrow> 8 word\"\n  where \"ucast\\<^sub>6\\<^sub>4\\<^sub>_\\<^sub>8 \\<equiv> ucast\"\nabbreviation ucast\\<^sub>3\\<^sub>2\\<^sub>_\\<^sub>1\\<^sub>6 :: \"32 word \\<Rightarrow> 16 word\"\n  where \"ucast\\<^sub>3\\<^sub>2\\<^sub>_\\<^sub>1\\<^sub>6 \\<equiv> ucast\"\nabbreviation ucast\\<^sub>8\\<^sub>_\\<^sub>3\\<^sub>2 :: \"8 word \\<Rightarrow> 32 word\"\n  where \"ucast\\<^sub>8\\<^sub>_\\<^sub>3\\<^sub>2 \\<equiv> ucast\"\nabbreviation ucast\\<^sub>3\\<^sub>2\\<^sub>_\\<^sub>8 :: \"32 word \\<Rightarrow> 8 word\"\n  where \"ucast\\<^sub>3\\<^sub>2\\<^sub>_\\<^sub>8 \\<equiv> ucast\"\nabbreviation ucast\\<^sub>1\\<^sub>6\\<^sub>_\\<^sub>8 :: \"16 word \\<Rightarrow> 8 word\"\n  where \"ucast\\<^sub>1\\<^sub>6\\<^sub>_\\<^sub>8 \\<equiv> ucast\"\nabbreviation ucast\\<^sub>8\\<^sub>_\\<^sub>1\\<^sub>6 :: \"8 word \\<Rightarrow> 16 word\"\n  where \"ucast\\<^sub>8\\<^sub>_\\<^sub>1\\<^sub>6 \\<equiv> ucast\"\n\n\nend", "meta": {"author": "jabocken", "repo": "SSM-Construction", "sha": "6d4dc2782bb0dc4f18b638e62f7fa54f484359e5", "save_path": "github-repos/isabelle/jabocken-SSM-Construction", "path": "github-repos/isabelle/jabocken-SSM-Construction/SSM-Construction-6d4dc2782bb0dc4f18b638e62f7fa54f484359e5/isabelle/isabelle/X86_Semantics/X86_Parse_Hoare_Triples.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926665855647395, "lm_q2_score": 0.4532618480153861, "lm_q1q2_score": 0.26863315183004277}}
{"text": "chapter \\<open>A Control Flow Graph for Jinja Byte Code\\<close>\n\nsection \\<open>Formalizing the CFG\\<close>\n\ntheory JVMCFG imports \"../StaticInter/BasicDefs\" Jinja.BVExample begin\n\ndeclare lesub_list_impl_same_size [simp del]\ndeclare nlistsE_length [simp del]\n\nsubsection \\<open>Type definitions\\<close>\n\nsubsubsection \\<open>Wellformed Programs\\<close>\n\ndefinition \"wf_jvmprog = {(P, Phi). wf_jvm_prog\\<^bsub>Phi\\<^esub> P}\"\n\ntypedef wf_jvmprog = \"wf_jvmprog\"\nproof\n  show \"(E, Phi) \\<in> wf_jvmprog\"\n    unfolding wf_jvmprog_def by (auto intro: wf_prog)\nqed\n\nhide_const Phi E\n\nabbreviation PROG :: \"wf_jvmprog \\<Rightarrow> jvm_prog\"\n  where \"PROG P \\<equiv> fst(Rep_wf_jvmprog(P))\"\n\nabbreviation TYPING :: \"wf_jvmprog \\<Rightarrow> ty\\<^sub>P\"\n  where \"TYPING P \\<equiv> snd(Rep_wf_jvmprog(P))\"\n\nlemma wf_jvmprog_is_wf_typ: \"wf_jvm_prog\\<^bsub>TYPING P\\<^esub> (PROG P)\"\nusing Rep_wf_jvmprog [of P]\n  by (auto simp: wf_jvmprog_def split_beta)\n\nlemma wf_jvmprog_is_wf: \"wf_jvm_prog (PROG P)\"\n  using wf_jvmprog_is_wf_typ unfolding wf_jvm_prog_def\n  by blast\n\nsubsubsection \\<open>Interprocedural CFG\\<close>\n\ntype_synonym jvm_method = \"wf_jvmprog \\<times> cname \\<times> mname\"\ndatatype var = Heap | Local \"nat\" | Stack \"nat\" | Exception\ndatatype val = Hp \"heap\" | Value \"Value.val\"\n\ntype_synonym state = \"var \\<rightharpoonup> val\"\n\ndefinition valid_state :: \"state \\<Rightarrow> bool\"\n  where \"valid_state s \\<equiv> (\\<forall>val. s Heap \\<noteq> Some (Value val))\n  \\<and> (s Exception = None \\<or> (\\<exists>addr. s Exception = Some (Value (Addr addr))))\n  \\<and> (\\<forall>var. var \\<noteq> Heap \\<and> var \\<noteq> Exception \\<longrightarrow> (\\<forall>h. s var \\<noteq> Some (Hp h)))\"\n\nfun the_Heap :: \"val \\<Rightarrow> heap\"\n  where \"the_Heap (Hp h) = h\"\n\nfun the_Value :: \"val \\<Rightarrow> Value.val\"\n  where \"the_Value (Value v) = v\"\n\nabbreviation heap_of :: \"state \\<Rightarrow> heap\"\n  where \"heap_of s \\<equiv> the_Heap (the (s Heap))\"\n\nabbreviation exc_flag :: \"state \\<Rightarrow> addr option\"\n  where \"exc_flag s \\<equiv> case (s Exception) of None \\<Rightarrow> None\n  | Some v \\<Rightarrow> Some (THE a. v = Value (Addr a))\"\n\nabbreviation stkAt :: \"state \\<Rightarrow> nat \\<Rightarrow> Value.val\"\n  where \"stkAt s n \\<equiv> the_Value (the (s (Stack n)))\"\n\nabbreviation locAt :: \"state \\<Rightarrow> nat \\<Rightarrow> Value.val\"\n  where \"locAt s n \\<equiv> the_Value (the (s (Local n)))\"\n\ndatatype nodeType = Enter | Normal | Return | Exceptional \"pc option\" \"nodeType\"\ntype_synonym cfg_node = \"cname \\<times> mname \\<times> pc option \\<times> nodeType\"\n\ntype_synonym\n  cfg_edge = \"cfg_node \\<times> (var, val, cname \\<times> mname \\<times> pc, cname \\<times> mname) edge_kind \\<times> cfg_node\"\n\ndefinition ClassMain :: \"wf_jvmprog \\<Rightarrow> cname\"\n  where \"ClassMain P \\<equiv> SOME Name. \\<not> is_class (PROG P) Name\"\n\ndefinition MethodMain :: \"wf_jvmprog \\<Rightarrow> mname\"\n  where \"MethodMain P \\<equiv> SOME Name.\n  \\<forall>C D fs ms. class (PROG P) C = \\<lfloor>(D, fs, ms)\\<rfloor> \\<longrightarrow> (\\<forall>m \\<in> set ms. Name \\<noteq> fst m)\"\n\ndefinition stkLength :: \"jvm_method \\<Rightarrow> pc \\<Rightarrow> nat\"\n  where\n  \"stkLength m pc \\<equiv> let (P, C, M) = m in (\n  if (C = ClassMain P) then 1 else (\n    length (fst(the(((TYPING P) C M) ! pc)))\n  ))\"\n\ndefinition locLength :: \"jvm_method \\<Rightarrow> pc \\<Rightarrow> nat\"\n  where\n  \"locLength m pc \\<equiv> let (P, C, M) = m in (\n  if (C = ClassMain P) then 1 else (\n    length (snd(the(((TYPING P) C M) ! pc)))\n  ))\"\n\nlemma ex_new_class_name: \"\\<exists>C. \\<not> is_class P C\"\nproof -\n  have \"\\<not> finite (UNIV :: cname set)\"\n    by (rule infinite_UNIV_listI)\n  hence \"\\<exists>C. C \\<notin> set (map fst P)\"\n    by -(rule ex_new_if_finite, auto)\n  then obtain C where \"C \\<notin> set (map fst P)\"\n    by blast\n  have \"\\<not> is_class P C\"\n  proof\n    assume \"is_class P C\"\n    then obtain D fs ms where \"class P C = \\<lfloor>(D, fs, ms)\\<rfloor>\"\n      by auto\n    with \\<open>C \\<notin> set (map fst P)\\<close> show False\n      by (auto dest: map_of_SomeD intro!: image_eqI simp: class_def)\n  qed\n  thus ?thesis\n    by blast\nqed\n\nlemma ClassMain_unique_in_P:\n  assumes \"is_class (PROG P) C\"\n  shows \"ClassMain P \\<noteq> C\"\nproof -\n  from ex_new_class_name [of \"PROG P\"] obtain D where \"\\<not> is_class (PROG P) D\"\n    by blast\n  with \\<open>is_class (PROG P) C\\<close> show ?thesis\n    unfolding ClassMain_def\n    by -(rule someI2, fastforce+)\nqed\n\nlemma map_of_fstD: \"\\<lbrakk> map_of xs a = \\<lfloor>b\\<rfloor>; \\<forall>x \\<in> set xs. fst x \\<noteq> a \\<rbrakk> \\<Longrightarrow> False\"\n  by (induct xs, auto)\n\nlemma map_of_fstE: \"\\<lbrakk> map_of xs a = \\<lfloor>b\\<rfloor>; \\<exists>x \\<in> set xs. fst x = a \\<Longrightarrow> thesis \\<rbrakk> \\<Longrightarrow> thesis\"\n  by (induct xs) (auto split: if_split_asm)\n\nlemma ex_unique_method_name:\n  \"\\<exists>Name. \\<forall>C D fs ms. class (PROG P) C = \\<lfloor>(D, fs, ms)\\<rfloor> \\<longrightarrow> (\\<forall>m\\<in>set ms. Name \\<noteq> fst m)\"\nproof -\n  from wf_jvmprog_is_wf [of P]\n  have \"distinct_fst (PROG P)\"\n    by (simp add: wf_jvm_prog_def wf_jvm_prog_phi_def wf_prog_def)\n  hence \"{C. \\<exists>D fs ms. class (PROG P) C = \\<lfloor>(D, fs, ms)\\<rfloor>} = fst ` set (PROG P)\"\n    by (fastforce elim: map_of_fstE simp: class_def intro: map_of_SomeI)\n  hence \"finite {C. \\<exists>D fs ms. class (PROG P) C = \\<lfloor>(D, fs, ms)\\<rfloor>}\"\n    by auto\n  moreover have \"{ms. \\<exists>C D fs. class (PROG P) C = \\<lfloor>(D, fs, ms)\\<rfloor>}\n    = snd ` snd ` the ` (\\<lambda>C. class (PROG P) C) ` {C. \\<exists>D fs ms. class (PROG P) C = \\<lfloor>(D, fs, ms)\\<rfloor>}\"\n    by (fastforce intro: rev_image_eqI map_of_SomeI simp: class_def)\n  ultimately have \"finite {ms. \\<exists>C D fs. class (PROG P) C = \\<lfloor>(D, fs, ms)\\<rfloor>}\"\n    by auto\n  moreover have \"\\<not> finite (UNIV :: mname set)\"\n    by (rule infinite_UNIV_listI)\n  ultimately\n  have \"\\<exists>Name. Name \\<notin> fst ` (\\<Union>ms \\<in> {ms. \\<exists>C D fs. class (PROG P) C = \\<lfloor>(D, fs, ms)\\<rfloor>}. set ms)\"\n    by -(rule ex_new_if_finite, auto)\n  thus ?thesis\n    by fastforce\nqed\n\nlemma MethodMain_unique_in_P:\n  assumes \"PROG P \\<turnstile> D sees M:Ts\\<rightarrow>T = mb in C\"\n  shows \"MethodMain P \\<noteq> M\"\nproof -\n  from ex_unique_method_name [of P] obtain M'\n    where \"\\<And>C D fs ms. class (PROG P) C = \\<lfloor>(D, fs, ms)\\<rfloor> \\<Longrightarrow> (\\<forall>m \\<in> set ms. M' \\<noteq> fst m)\"\n    by blast\n  with \\<open>PROG P \\<turnstile> D sees M:Ts\\<rightarrow>T = mb in C\\<close>\n  show ?thesis\n    unfolding MethodMain_def\n    by -(rule someI2_ex, fastforce, fastforce dest!: visible_method_exists elim: map_of_fstE)\nqed\n\nlemma ClassMain_is_no_class [dest!]: \"is_class (PROG P) (ClassMain P) \\<Longrightarrow> False\"\nproof (erule rev_notE)\n  from ex_new_class_name [of \"PROG P\"] obtain C where \"\\<not> is_class (PROG P) C\"\n    by blast\n  thus \"\\<not> is_class (PROG P) (ClassMain P)\" unfolding ClassMain_def\n    by (rule someI)\nqed\n\nlemma MethodMain_not_seen [dest!]: \"PROG P \\<turnstile> C sees (MethodMain P):Ts\\<rightarrow>T = mb in D \\<Longrightarrow> False\"\n  by (fastforce dest: MethodMain_unique_in_P)\n\nlemma no_Call_from_ClassMain [dest!]: \"PROG P \\<turnstile> ClassMain P sees M:Ts\\<rightarrow>T = mb in C \\<Longrightarrow> False\"\n  by (fastforce dest: sees_method_is_class)\n\nlemma no_Call_in_ClassMain [dest!]: \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = mb in ClassMain P \\<Longrightarrow> False\"\n  by (fastforce dest: sees_method_idemp)\n\ninductive JVMCFG :: \"jvm_method \\<Rightarrow> cfg_node \\<Rightarrow> (var, val, cname \\<times> mname \\<times> pc, cname \\<times> mname) edge_kind \\<Rightarrow> cfg_node \\<Rightarrow> bool\" (\" _ \\<turnstile> _ -_\\<rightarrow> _\")\n  and reachable :: \"jvm_method \\<Rightarrow> cfg_node \\<Rightarrow> bool\" (\" _ \\<turnstile> \\<Rightarrow>_\")\n  where\n    Entry_reachable: \"(P, C0, Main) \\<turnstile> \\<Rightarrow>(ClassMain P, MethodMain P, None, Enter)\"\n  | reachable_step: \"\\<lbrakk> P \\<turnstile> \\<Rightarrow>n; P \\<turnstile> n -(e)\\<rightarrow> n' \\<rbrakk> \\<Longrightarrow> P \\<turnstile> \\<Rightarrow>n'\"\n  | Main_to_Call: \"(P, C0, Main) \\<turnstile> \\<Rightarrow>(ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Enter)\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Enter) -\\<Up>id\\<rightarrow> (ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Normal)\"\n  | Main_Call_LFalse: \"(P, C0, Main) \\<turnstile> \\<Rightarrow>(ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Normal)\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Normal) -(\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow> (ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Return)\"\n  | Main_Call: \"\\<lbrakk> (P, C0, Main) \\<turnstile> \\<Rightarrow>(ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Normal);\n     PROG P \\<turnstile> C0 sees Main:[]\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in D;\n     initParams = [(\\<lambda>s. s Heap),(\\<lambda>s. \\<lfloor>Value Null\\<rfloor>)];\n     ek = (\\<lambda>(s, ret). True):(ClassMain P, MethodMain P, 0)\\<hookrightarrow>\\<^bsub>(D, Main)\\<^esub>initParams \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Normal) -(ek)\\<rightarrow> (D, Main, None, Enter)\"\n  | Main_Return_to_Exit: \"(P, C0, Main) \\<turnstile> \\<Rightarrow>(ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Return)\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Return) -(\\<Up>id)\\<rightarrow> (ClassMain P, MethodMain P, None, Return)\"\n  | Method_LFalse: \"(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, None, Enter)\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, None, Enter) -(\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow> (C, M, None, Return)\"\n  | Method_LTrue: \"(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, None, Enter)\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, None, Enter) -(\\<lambda>s. True)\\<^sub>\\<surd>\\<rightarrow> (C, M, \\<lfloor>0\\<rfloor>, Enter)\"\n  | CFG_Load: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter); instrs_of (PROG P) C M ! pc = Load n;\n    ek = \\<Up>(\\<lambda>s. s(Stack (stkLength (P, C, M) pc) := s (Local n))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_Store: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter); instrs_of (PROG P) C M ! pc = Store n;\n    ek = \\<Up>(\\<lambda>s. s(Local n := s (Stack (stkLength (P, C, M) pc - 1)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_Push: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter); instrs_of (PROG P) C M ! pc = Push v;\n    ek = \\<Up>(\\<lambda>s. s(Stack (stkLength (P, C, M) pc) \\<mapsto> Value v)) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_Pop: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter); instrs_of (PROG P) C M ! pc = Pop;\n    ek = \\<Up>id \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_IAdd: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter); instrs_of (PROG P) C M ! pc = IAdd;\n    ek = \\<Up>(\\<lambda>s. let i1 = the_Intg (stkAt s (stkLength (P, C, M) pc - 1));\n                   i2 = the_Intg (stkAt s (stkLength (P, C, M) pc - 2))\n                in s(Stack (stkLength (P, C, M) pc - 2) \\<mapsto> Value (Intg (i1 + i2)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_Goto: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter); instrs_of (PROG P) C M ! pc = Goto i \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -((\\<lambda>s. True)\\<^sub>\\<surd>)\\<rightarrow> (C, M, \\<lfloor>nat (int pc + i)\\<rfloor>, Enter)\"\n  | CFG_CmpEq: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter); instrs_of (PROG P) C M ! pc = CmpEq;\n    ek = \\<Up>(\\<lambda>s. let e1 = stkAt s (stkLength (P, C, M) pc - 1);\n                   e2 = stkAt s (stkLength (P, C, M) pc - 2)\n                in s(Stack (stkLength (P, C, M) pc - 2) \\<mapsto> Value (Bool (e1 = e2)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_IfFalse_False: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = IfFalse i;\n    i \\<noteq> 1;\n    ek = (\\<lambda>s. stkAt s (stkLength(P, C, M) pc - 1) = Bool False)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>nat (int pc + i)\\<rfloor>, Enter)\"\n  | CFG_IfFalse_True: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = IfFalse i;\n    ek = (\\<lambda>s. stkAt s (stkLength(P, C, M) pc - 1) \\<noteq> Bool False \\<or> i = 1)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_New_Check_Normal: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = New Cl;\n    ek = (\\<lambda>s. new_Addr (heap_of s) \\<noteq> None)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Normal)\"\n  | CFG_New_Check_Exceptional: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = New Cl;\n    pc' = (case (match_ex_table (PROG P) OutOfMemory pc (ex_table_of (PROG P) C M)) of\n             None \\<Rightarrow> None\n           | Some (pc'', d) \\<Rightarrow> \\<lfloor>pc''\\<rfloor>);\n    ek = (\\<lambda>s. new_Addr (heap_of s) = None)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional pc' Enter)\"\n  | CFG_New_Update: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Normal);\n    instrs_of (PROG P) C M ! pc = New Cl;\n    ek = \\<Up>(\\<lambda>s. let a = the (new_Addr (heap_of s))\n                in s(Heap \\<mapsto> Hp ((heap_of s)(a \\<mapsto> blank (PROG P) Cl)),\n                    Stack (stkLength(P, C, M) pc) \\<mapsto> Value (Addr a))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Normal) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_New_Exceptional_prop: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter);\n    instrs_of (PROG P) C M ! pc = New Cl;\n    ek = \\<Up>(\\<lambda>s. s(Exception \\<mapsto> Value (Addr (addr_of_sys_xcpt OutOfMemory)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter) -(ek)\\<rightarrow> (C, M, None, Return)\"\n  | CFG_New_Exceptional_handle: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter);\n    instrs_of (PROG P) C M ! pc = New Cl;\n    ek = \\<Up>(\\<lambda>s. (s(Exception := None))\n                (Stack (stkLength (P, C, M) pc' - 1) \\<mapsto> Value (Addr (addr_of_sys_xcpt OutOfMemory)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc'\\<rfloor>, Enter)\"\n  | CFG_Getfield_Check_Normal: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = Getfield F Cl;\n    ek = (\\<lambda>s. stkAt s (stkLength (P, C, M) pc - 1) \\<noteq> Null)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Normal)\"\n  | CFG_Getfield_Check_Exceptional: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = Getfield F Cl;\n    pc' = (case (match_ex_table (PROG P) NullPointer pc (ex_table_of (PROG P) C M)) of\n             None \\<Rightarrow> None\n           | Some (pc'', d) \\<Rightarrow> \\<lfloor>pc''\\<rfloor>);\n    ek = (\\<lambda>s. stkAt s (stkLength (P, C, M) pc - 1) = Null)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional pc' Enter)\"\n  | CFG_Getfield_Update: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Normal);\n    instrs_of (PROG P) C M ! pc = Getfield F Cl;\n    ek = \\<Up>(\\<lambda>s. let (D, fs) = the (heap_of s (the_Addr (stkAt s (stkLength (P, C, M) pc - 1))))\n                 in s(Stack (stkLength(P, C, M) pc - 1) \\<mapsto> Value (the (fs (F, Cl))))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Normal) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_Getfield_Exceptional_prop: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter);\n    instrs_of (PROG P) C M ! pc = Getfield F Cl;\n    ek = \\<Up>(\\<lambda>s. s(Exception \\<mapsto> Value (Addr (addr_of_sys_xcpt NullPointer)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter) -(ek)\\<rightarrow> (C, M, None, Return)\"\n  | CFG_Getfield_Exceptional_handle: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter);\n    instrs_of (PROG P) C M ! pc = Getfield F Cl;\n    ek = \\<Up>(\\<lambda>s. (s(Exception := None))\n                (Stack (stkLength (P, C, M) pc' - 1) \\<mapsto> Value (Addr (addr_of_sys_xcpt NullPointer)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc'\\<rfloor>, Enter)\"\n  | CFG_Putfield_Check_Normal: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = Putfield F Cl;\n    ek = (\\<lambda>s. stkAt s (stkLength (P, C, M) pc - 2) \\<noteq> Null)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Normal)\"\n  | CFG_Putfield_Check_Exceptional: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = Putfield F Cl;\n    pc' = (case (match_ex_table (PROG P) NullPointer pc (ex_table_of (PROG P) C M)) of\n             None \\<Rightarrow> None\n           | Some (pc'', d) \\<Rightarrow> \\<lfloor>pc''\\<rfloor>);\n    ek = (\\<lambda>s. stkAt s (stkLength (P, C, M) pc - 2) = Null)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional pc' Enter)\"\n  | CFG_Putfield_Update: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Normal);\n    instrs_of (PROG P) C M ! pc = Putfield F Cl;\n    ek = \\<Up>(\\<lambda>s. let v = stkAt s (stkLength (P, C, M) pc - 1);\n                   r = stkAt s (stkLength (P, C, M) pc - 2);\n                   a = the_Addr r;\n                   (D, fs) = the (heap_of s a);\n                   h' = (heap_of s)(a \\<mapsto> (D, fs((F, Cl) \\<mapsto> v)))\n                 in s(Heap \\<mapsto> Hp h')) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Normal) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_Putfield_Exceptional_prop: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter);\n    instrs_of (PROG P) C M ! pc = Putfield F Cl;\n    ek = \\<Up>(\\<lambda>s. s(Exception \\<mapsto> Value (Addr (addr_of_sys_xcpt NullPointer)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter) -(ek)\\<rightarrow> (C, M, None, Return)\"\n  | CFG_Putfield_Exceptional_handle: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter);\n    instrs_of (PROG P) C M ! pc = Putfield F Cl;\n    ek = \\<Up>(\\<lambda>s. (s(Exception := None))\n                (Stack (stkLength (P, C, M) pc' - 1) \\<mapsto> Value (Addr (addr_of_sys_xcpt NullPointer)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc'\\<rfloor>, Enter)\"\n  | CFG_Checkcast_Check_Normal: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = Checkcast Cl;\n    ek = (\\<lambda>s. cast_ok (PROG P) Cl (heap_of s) (stkAt s (stkLength (P, C, M) pc - 1)))\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_Checkcast_Check_Exceptional: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = Checkcast Cl;\n    pc' = (case (match_ex_table (PROG P) ClassCast pc (ex_table_of (PROG P) C M)) of\n             None \\<Rightarrow> None\n           | Some (pc'', d) \\<Rightarrow> \\<lfloor>pc''\\<rfloor>);\n    ek = (\\<lambda>s. \\<not> cast_ok (PROG P) Cl (heap_of s) (stkAt s (stkLength (P, C, M) pc - 1)))\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional pc' Enter)\"\n  | CFG_Checkcast_Exceptional_prop: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter);\n    instrs_of (PROG P) C M ! pc = Checkcast Cl;\n    ek = \\<Up>(\\<lambda>s. s(Exception \\<mapsto> Value (Addr (addr_of_sys_xcpt ClassCast)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter) -(ek)\\<rightarrow> (C, M, None, Return)\"\n  | CFG_Checkcast_Exceptional_handle: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter);\n    instrs_of (PROG P) C M ! pc = Checkcast Cl;\n    ek = \\<Up>(\\<lambda>s. (s(Exception := None))\n                (Stack (stkLength (P, C, M) pc' - 1) \\<mapsto> Value (Addr (addr_of_sys_xcpt ClassCast)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc'\\<rfloor>, Enter)\"\n  | CFG_Throw_Check: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = Throw;\n    pc' = None \\<or> match_ex_table (PROG P) Exc pc (ex_table_of (PROG P) C M) = \\<lfloor>(the pc', d)\\<rfloor>;\n    ek = (\\<lambda>s. let v = stkAt s (stkLength (P, C, M) pc - 1);\n                  Cl = if (v = Null) then NullPointer else (cname_of (heap_of s) (the_Addr v))\n               in case pc' of\n                  None \\<Rightarrow> match_ex_table (PROG P) Cl pc (ex_table_of (PROG P) C M) = None\n                | Some pc'' \\<Rightarrow> \\<exists>d. match_ex_table (PROG P) Cl pc (ex_table_of (PROG P) C M)\n                                  = \\<lfloor>(pc'', d)\\<rfloor>\n    )\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional pc' Enter)\"\n\n  | CFG_Throw_prop: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter);\n    instrs_of (PROG P) C M ! pc = Throw;\n    ek = \\<Up>(\\<lambda>s. s(Exception \\<mapsto> Value (stkAt s (stkLength (P, C, M) pc - 1)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter) -(ek)\\<rightarrow> (C, M, None, Return)\"\n  | CFG_Throw_handle: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter);\n    pc' \\<noteq> length (instrs_of (PROG P) C M);\n    instrs_of (PROG P) C M ! pc = Throw;\n    ek = \\<Up>(\\<lambda>s. (s(Exception := None))\n                (Stack (stkLength (P, C, M) pc' - 1) \\<mapsto> Value (stkAt s (stkLength (P, C, M) pc - 1)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc'\\<rfloor>, Enter)\"\n  | CFG_Invoke_Check_NP_Normal: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = Invoke M' n;\n    ek = (\\<lambda>s. stkAt s (stkLength (P, C, M) pc - Suc n) \\<noteq> Null)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Normal)\"\n  | CFG_Invoke_Check_NP_Exceptional: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = Invoke M' n;\n    pc' = (case (match_ex_table (PROG P) NullPointer pc (ex_table_of (PROG P) C M)) of\n             None \\<Rightarrow> None\n           | Some (pc'', d) \\<Rightarrow> \\<lfloor>pc''\\<rfloor>);\n    ek = (\\<lambda>s. stkAt s (stkLength (P, C, M) pc - Suc n) = Null)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional pc' Enter)\"\n  | CFG_Invoke_NP_prop: \"\\<lbrakk> C \\<noteq> ClassMain P;\n    (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter);\n    instrs_of (PROG P) C M ! pc = Invoke M' n;\n    ek = \\<Up>(\\<lambda>s. s(Exception \\<mapsto> Value (Addr (addr_of_sys_xcpt NullPointer)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional None Enter) -(ek)\\<rightarrow> (C, M, None, Return)\"\n  | CFG_Invoke_NP_handle: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter);\n    instrs_of (PROG P) C M ! pc = Invoke M' n;\n    ek = \\<Up>(\\<lambda>s. (s(Exception := None))\n                (Stack (stkLength (P, C, M) pc' - 1) \\<mapsto> Value (Addr (addr_of_sys_xcpt NullPointer)))) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc'\\<rfloor>, Enter)\"\n  | CFG_Invoke_Call: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Normal);\n    instrs_of (PROG P) C M ! pc = Invoke M' n;\n    TYPING P C M ! pc = \\<lfloor>(ST, LT)\\<rfloor>;\n    ST ! n = Class D';\n    PROG P \\<turnstile> D' sees M':Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in D;\n    Q = (\\<lambda>(s, ret). let r = stkAt s (stkLength (P, C, M) pc - Suc n);\n                        C' = fst (the (heap_of s (the_Addr r)))\n                     in D = fst (method (PROG P) C' M'));\n    paramDefs = (\\<lambda>s. s Heap)\n                # (\\<lambda>s. s (Stack (stkLength (P, C, M) pc - Suc n)))\n                # (rev (map (\\<lambda>i. (\\<lambda>s. s (Stack (stkLength (P, C, M) pc - Suc i)))) [0..<n]));\n    ek = Q:(C, M, pc)\\<hookrightarrow>\\<^bsub>(D,M')\\<^esub>paramDefs\n  \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Normal) -(ek)\\<rightarrow> (D, M', None, Enter)\"\n  | CFG_Invoke_False: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Normal);\n    instrs_of (PROG P) C M ! pc = Invoke M' n;\n    ek = (\\<lambda>s. False)\\<^sub>\\<surd>\n  \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Normal) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Return)\"\n  | CFG_Invoke_Return_Check_Normal: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Return);\n    instrs_of (PROG P) C M ! pc = Invoke M' n;\n    (TYPING P) C M ! pc = \\<lfloor>(ST, LT)\\<rfloor>;\n    ST ! n \\<noteq> NT;\n    ek = (\\<lambda>s. s Exception = None)\\<^sub>\\<surd>\n  \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Return) -(ek)\\<rightarrow> (C, M, \\<lfloor>Suc pc\\<rfloor>, Enter)\"\n  | CFG_Invoke_Return_Check_Exceptional: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Return);\n    instrs_of (PROG P) C M ! pc = Invoke M' n;\n    match_ex_table (PROG P) Exc pc (ex_table_of (PROG P) C M) = \\<lfloor>(pc', diff)\\<rfloor>;\n    pc' \\<noteq> length (instrs_of (PROG P) C M);\n    ek = (\\<lambda>s. \\<exists>v d. s Exception = \\<lfloor>v\\<rfloor> \\<and>\n                  match_ex_table (PROG P) (cname_of (heap_of s) (the_Addr (the_Value v))) pc (ex_table_of (PROG P) C M) = \\<lfloor>(pc', d)\\<rfloor>)\\<^sub>\\<surd>\n  \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Return) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Return)\"\n  | CFG_Invoke_Return_Exceptional_handle: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Return);\n    instrs_of (PROG P) C M ! pc = Invoke M' n;\n    ek = \\<Up>(\\<lambda>s. s(Exception := None,\n                 Stack (stkLength (P, C, M) pc' - 1) := s Exception)) \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Return) -(ek)\\<rightarrow> (C, M, \\<lfloor>pc'\\<rfloor>, Enter)\"\n  | CFG_Invoke_Return_Exceptional_prop: \"\\<lbrakk> C \\<noteq> ClassMain P;\n    (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Return);\n    instrs_of (PROG P) C M ! pc = Invoke M' n;\n    ek = (\\<lambda>s. \\<exists>v. s Exception = \\<lfloor>v\\<rfloor> \\<and>\n              match_ex_table (PROG P) (cname_of (heap_of s) (the_Addr (the_Value v))) pc (ex_table_of (PROG P) C M) = None)\\<^sub>\\<surd> \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Return) -(ek)\\<rightarrow> (C, M, None, Return)\"\n  | CFG_Return: \"\\<lbrakk> C \\<noteq> ClassMain P; (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter);\n    instrs_of (PROG P) C M ! pc = instr.Return;\n    ek = \\<Up>(\\<lambda>s. s(Stack 0 := s (Stack (stkLength (P, C, M) pc - 1))))\n  \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, \\<lfloor>pc\\<rfloor>, Enter) -(ek)\\<rightarrow> (C, M, None, Return)\"\n  | CFG_Return_from_Method: \"\\<lbrakk> (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, None, Return);\n    (P, C0, Main) \\<turnstile> (C', M', \\<lfloor>pc'\\<rfloor>, Normal) -(Q':(C', M', pc')\\<hookrightarrow>\\<^bsub>(C,M)\\<^esub>ps)\\<rightarrow> (C, M, None, Enter);\n    Q = (\\<lambda>(s, ret). ret = (C', M', pc'));\n    stateUpdate = (\\<lambda>s s'. s'(Heap := s Heap,\n                            Exception := s Exception,\n                            Stack (stkLength (P, C', M') (Suc pc') - 1) := s (Stack 0))\n                  );\n    ek = Q\\<hookleftarrow>\\<^bsub>(C, M)\\<^esub>stateUpdate\n  \\<rbrakk>\n  \\<Longrightarrow> (P, C0, Main) \\<turnstile> (C, M, None, Return) -(ek)\\<rightarrow> (C', M', \\<lfloor>pc'\\<rfloor>, Return)\"\n\n\n(* This takes veeeery long *)\nlemma JVMCFG_edge_det: \"\\<lbrakk> P \\<turnstile> n -(et)\\<rightarrow> n'; P \\<turnstile> n -(et')\\<rightarrow> n' \\<rbrakk> \\<Longrightarrow> et = et'\"\n  by (erule JVMCFG.cases) (erule JVMCFG.cases, (fastforce dest: sees_method_fun)+)+\n\nlemma sourcenode_reachable: \"P \\<turnstile> n -(ek)\\<rightarrow> n' \\<Longrightarrow> P \\<turnstile> \\<Rightarrow>n\"\n  by (erule JVMCFG.cases, auto)\n\nlemma targetnode_reachable:\n  assumes edge: \"P \\<turnstile> n -(ek)\\<rightarrow> n'\"\n  shows \"P \\<turnstile> \\<Rightarrow>n'\"\nproof -\n  from edge have \"P \\<turnstile> \\<Rightarrow>n\"\n    by -(drule sourcenode_reachable)\n  with edge show ?thesis\n    by -(rule JVMCFG_reachable.intros)\nqed\n\nlemmas JVMCFG_reachable_inducts = JVMCFG_reachable.inducts[split_format (complete)]\n\nlemma ClassMain_imp_MethodMain:\n  \"(P, C0, Main) \\<turnstile> (C', M', pc', nt') -ek\\<rightarrow> (ClassMain P, M, pc, nt) \\<Longrightarrow> M = MethodMain P\"\n  \"(P, C0, Main) \\<turnstile> \\<Rightarrow>(ClassMain P, M, pc, nt) \\<Longrightarrow> M = MethodMain P\"\nproof (induct P==\"P\" C0\\<equiv>\"C0\" Main\\<equiv>Main C' M' pc' nt' ek C''==\"ClassMain P\" M pc nt and\n              P==\"P\" C0\\<equiv>\"C0\" Main\\<equiv>Main C'==\"ClassMain P\" M pc nt\n       rule: JVMCFG_reachable_inducts)\n  case CFG_Return_from_Method\n  thus ?case\n    by (fastforce elim: JVMCFG.cases)\nqed auto\n\nlemma ClassMain_no_Call_target [dest!]:\n  \"(P, C0, Main) \\<turnstile> (C, M, pc, nt) -Q:(C', M', pc')\\<hookrightarrow>\\<^bsub>(D,M'')\\<^esub>paramDefs\\<rightarrow> (ClassMain P, M''', pc'', nt')\n  \\<Longrightarrow> False\"\n  and\n  \"(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, pc, nt) \\<Longrightarrow> True\"\n  by (induct  P C0 Main C M pc nt ek==\"Q:(C', M', pc')\\<hookrightarrow>\\<^bsub>(D,M'')\\<^esub>paramDefs\"\n                         C''==\"ClassMain P\" M''' pc'' nt' and\n               P C0 Main C M pc nt\n    rule: JVMCFG_reachable_inducts) auto\n\nlemma method_of_src_and_trg_exists:\n  \"\\<lbrakk> (P, C0, Main) \\<turnstile> (C', M', pc', nt') -ek\\<rightarrow> (C, M, pc, nt); C \\<noteq> ClassMain P; C' \\<noteq> ClassMain P \\<rbrakk>\n  \\<Longrightarrow> (\\<exists>Ts T mb. (PROG P) \\<turnstile> C sees M:Ts\\<rightarrow>T = mb in C) \\<and>\n     (\\<exists>Ts T mb. (PROG P) \\<turnstile> C' sees M':Ts\\<rightarrow>T = mb in C')\"\n  and method_of_reachable_node_exists:\n  \"\\<lbrakk> (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, pc, nt); C \\<noteq> ClassMain P \\<rbrakk>\n  \\<Longrightarrow> \\<exists>Ts T mb. (PROG P) \\<turnstile> C sees M:Ts\\<rightarrow>T = mb in C\"\nproof (induct rule: JVMCFG_reachable_inducts)\n  case CFG_Invoke_Call\n  thus ?case\n    by (blast dest: sees_method_idemp)\nnext\n  case (reachable_step P C0 Main C M pc nt ek C' M' pc' nt')\n  show ?case\n  proof (cases \"C = ClassMain P\")\n    case True\n    with \\<open>(P, C0, Main) \\<turnstile> (C, M, pc, nt) -ek\\<rightarrow> (C', M', pc', nt')\\<close> \\<open>C' \\<noteq> ClassMain P\\<close>\n    show ?thesis\n    proof cases\n      case Main_Call\n      thus ?thesis\n        by (blast dest: sees_method_idemp)\n    qed auto\n  next\n    case False\n    with reachable_step show ?thesis\n      by simp\n  qed\nqed simp_all\n\nlemma \"\\<lbrakk> (P, C0, Main) \\<turnstile> (C', M', pc', nt') -ek\\<rightarrow> (C, M, pc, nt); C \\<noteq> ClassMain P; C' \\<noteq> ClassMain P \\<rbrakk>\n  \\<Longrightarrow> (case pc of None \\<Rightarrow> True |\n    \\<lfloor>pc''\\<rfloor> \\<Rightarrow> (TYPING P) C M ! pc'' \\<noteq> None \\<and> pc'' < length (instrs_of (PROG P) C M)) \\<and>\n  (case pc' of None \\<Rightarrow> True |\n    \\<lfloor>pc''\\<rfloor> \\<Rightarrow> (TYPING P) C' M' ! pc'' \\<noteq> None \\<and> pc'' < length (instrs_of (PROG P) C' M'))\"\n  and instr_of_reachable_node_typable: \"\\<lbrakk> (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, pc, nt); C \\<noteq> ClassMain P \\<rbrakk>\n  \\<Longrightarrow> case pc of None \\<Rightarrow> True |\n  \\<lfloor>pc''\\<rfloor> \\<Rightarrow> (TYPING P) C M ! pc'' \\<noteq> None \\<and> pc'' < length (instrs_of (PROG P) C M)\"\nproof (induct rule: JVMCFG_reachable_inducts)\n  case (CFG_Load C P C0 Main M pc n ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_Load show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_Store C P C0 Main M pc n ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_Store show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_Push C P C0 Main M pc v ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_Push show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_Pop C P C0 Main M pc ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_Pop show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_IAdd C P C0 Main M pc ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_IAdd show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_Goto C P C0 Main M pc i)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_Goto show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_CmpEq C P C0 Main M pc ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_CmpEq show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_IfFalse_False C P C0 Main M pc i ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_IfFalse_False show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_IfFalse_True C P C0 Main M pc i ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_IfFalse_True show ?case\n    using [[simproc del: list_to_set_comprehension]] by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_New_Update C P C0 Main M pc Cl ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Normal)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_New_Update show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_New_Exceptional_handle C P C0 Main M pc pc' Cl ek)\n  hence \"TYPING P C M ! pc \\<noteq> None\" and \"pc < length (instrs_of (PROG P) C M)\"\n    by simp_all\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 where\n    \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, instrs_of (PROG P) C M, ex_table_of (PROG P) C M) in C\"\n    by (fastforce dest: method_of_reachable_node_exists)\n  with \\<open>pc < length (instrs_of (PROG P) C M)\\<close> \\<open>instrs_of (PROG P) C M ! pc = New Cl\\<close>\n  have \"PROG P,T,mxs,length (instrs_of (PROG P) C M),ex_table_of (PROG P) C M\n    \\<turnstile> New Cl,pc :: TYPING P C M\"\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n    \\<open>instrs_of (PROG P) C M ! pc = New Cl\\<close> obtain d'\n    where \"match_ex_table (PROG P) OutOfMemory pc (ex_table_of (PROG P) C M) = \\<lfloor>(pc', d')\\<rfloor>\"\n    by cases (fastforce elim: JVMCFG.cases)\n  hence \"\\<exists>(f, t, D, h, d)\\<in>set (ex_table_of (PROG P) C M).\n    matches_ex_entry (PROG P) OutOfMemory pc (f, t, D, h, d) \\<and> h = pc' \\<and> d = d'\"\n    by -(drule match_ex_table_SomeD)\n  ultimately show ?case using \\<open>instrs_of (PROG P) C M ! pc = New Cl\\<close>\n    by (fastforce simp: relevant_entries_def is_relevant_entry_def matches_ex_entry_def)\nnext\n  case (CFG_Getfield_Update C P C0 Main M pc F Cl ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Normal)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_Getfield_Update show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_Getfield_Exceptional_handle C P C0 Main M pc pc' F Cl ek)\n  hence \"TYPING P C M ! pc \\<noteq> None\" and \"pc < length (instrs_of (PROG P) C M)\"\n    by simp_all\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 where\n    \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, instrs_of (PROG P) C M, ex_table_of (PROG P) C M) in C\"\n    by (fastforce dest: method_of_reachable_node_exists)\n  with \\<open>pc < length (instrs_of (PROG P) C M)\\<close> \\<open>instrs_of (PROG P) C M ! pc = Getfield F Cl\\<close>\n  have \"PROG P,T,mxs,length (instrs_of (PROG P) C M),ex_table_of (PROG P) C M\n    \\<turnstile> Getfield F Cl,pc :: TYPING P C M\"\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n    \\<open>instrs_of (PROG P) C M ! pc = Getfield F Cl\\<close> obtain d'\n    where \"match_ex_table (PROG P) NullPointer pc (ex_table_of (PROG P) C M) = \\<lfloor>(pc', d')\\<rfloor>\"\n    by cases (fastforce elim: JVMCFG.cases)\n  hence \"\\<exists>(f, t, D, h, d)\\<in>set (ex_table_of (PROG P) C M).\n    matches_ex_entry (PROG P) NullPointer pc (f, t, D, h, d) \\<and> h = pc' \\<and> d = d'\"\n    by -(drule match_ex_table_SomeD)\n  ultimately show ?case using \\<open>instrs_of (PROG P) C M ! pc = Getfield F Cl\\<close>\n    by (fastforce simp: relevant_entries_def is_relevant_entry_def matches_ex_entry_def)\nnext\n  case (CFG_Putfield_Update C P C0 Main M pc F Cl ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Normal)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_Putfield_Update show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_Putfield_Exceptional_handle C P C0 Main M pc pc' F Cl ek)\n  hence \"TYPING P C M ! pc \\<noteq> None\" and \"pc < length (instrs_of (PROG P) C M)\"\n    by simp_all\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 where\n    \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, instrs_of (PROG P) C M, ex_table_of (PROG P) C M) in C\"\n    by (fastforce dest: method_of_reachable_node_exists)\n  with \\<open>pc < length (instrs_of (PROG P) C M)\\<close> \\<open>instrs_of (PROG P) C M ! pc = Putfield F Cl\\<close>\n  have \"PROG P,T,mxs,length (instrs_of (PROG P) C M),ex_table_of (PROG P) C M\n    \\<turnstile> Putfield F Cl,pc :: TYPING P C M\"\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n    \\<open>instrs_of (PROG P) C M ! pc = Putfield F Cl\\<close> obtain d'\n    where \"match_ex_table (PROG P) NullPointer pc (ex_table_of (PROG P) C M) = \\<lfloor>(pc', d')\\<rfloor>\"\n    by cases (fastforce elim: JVMCFG.cases)\n  hence \"\\<exists>(f, t, D, h, d)\\<in>set (ex_table_of (PROG P) C M).\n    matches_ex_entry (PROG P) NullPointer pc (f, t, D, h, d) \\<and> h = pc' \\<and> d = d'\"\n    by -(drule match_ex_table_SomeD)\n  ultimately show ?case using \\<open>instrs_of (PROG P) C M ! pc = Putfield F Cl\\<close>\n    by (fastforce simp: relevant_entries_def is_relevant_entry_def matches_ex_entry_def)\nnext\n  case (CFG_Checkcast_Check_Normal C P C0 Main M pc Cl ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_Checkcast_Check_Normal show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext\n  case (CFG_Checkcast_Exceptional_handle C P C0 Main M pc pc' Cl ek)\n  hence \"TYPING P C M ! pc \\<noteq> None\" and \"pc < length (instrs_of (PROG P) C M)\"\n    by simp_all\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 where\n    \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, instrs_of (PROG P) C M, ex_table_of (PROG P) C M) in C\"\n    by (fastforce dest: method_of_reachable_node_exists)\n  with \\<open>pc < length (instrs_of (PROG P) C M)\\<close> \\<open>instrs_of (PROG P) C M ! pc = Checkcast Cl\\<close>\n  have \"PROG P,T,mxs,length (instrs_of (PROG P) C M),ex_table_of (PROG P) C M\n    \\<turnstile> Checkcast Cl,pc :: TYPING P C M\"\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n    \\<open>instrs_of (PROG P) C M ! pc = Checkcast Cl\\<close> obtain d'\n    where \"match_ex_table (PROG P) ClassCast pc (ex_table_of (PROG P) C M) = \\<lfloor>(pc', d')\\<rfloor>\"\n    by cases (fastforce elim: JVMCFG.cases)\n  hence \"\\<exists>(f, t, D, h, d)\\<in>set (ex_table_of (PROG P) C M).\n    matches_ex_entry (PROG P) ClassCast pc (f, t, D, h, d) \\<and> h = pc' \\<and> d = d'\"\n    by -(drule match_ex_table_SomeD)\n  ultimately show ?case using \\<open>instrs_of (PROG P) C M ! pc = Checkcast Cl\\<close>\n    by (fastforce simp: relevant_entries_def is_relevant_entry_def matches_ex_entry_def)\nnext\n  case (CFG_Throw_handle C P C0 Main M pc pc' ek)\n  hence \"TYPING P C M ! pc \\<noteq> None\" and \"pc < length (instrs_of (PROG P) C M)\"\n    by simp_all\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 where\n    \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, instrs_of (PROG P) C M, ex_table_of (PROG P) C M) in C\"\n    by (fastforce dest: method_of_reachable_node_exists)\n  with \\<open>pc < length (instrs_of (PROG P) C M)\\<close> \\<open>instrs_of (PROG P) C M ! pc = Throw\\<close>\n  have \"PROG P,T,mxs,length (instrs_of (PROG P) C M),ex_table_of (PROG P) C M\n    \\<turnstile> Throw,pc :: TYPING P C M\"\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n    \\<open>instrs_of (PROG P) C M ! pc = Throw\\<close> obtain d' Exc\n    where \"match_ex_table (PROG P) Exc pc (ex_table_of (PROG P) C M) = \\<lfloor>(pc', d')\\<rfloor>\"\n    by cases (fastforce elim: JVMCFG.cases)\n  hence \"\\<exists>(f, t, D, h, d)\\<in>set (ex_table_of (PROG P) C M).\n    matches_ex_entry (PROG P) Exc pc (f, t, D, h, d) \\<and> h = pc' \\<and> d = d'\"\n    by -(drule match_ex_table_SomeD)\n  ultimately show ?case using \\<open>instrs_of (PROG P) C M ! pc = Throw\\<close>\n    by (fastforce simp: relevant_entries_def is_relevant_entry_def matches_ex_entry_def)\nnext\n  case (CFG_Invoke_NP_handle C P C0 Main M pc pc' M' n ek)\n  hence \"TYPING P C M ! pc \\<noteq> None\" and \"pc < length (instrs_of (PROG P) C M)\"\n    by simp_all\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 where\n    \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, instrs_of (PROG P) C M, ex_table_of (PROG P) C M) in C\"\n    by (fastforce dest: method_of_reachable_node_exists)\n  with \\<open>pc < length (instrs_of (PROG P) C M)\\<close> \\<open>instrs_of (PROG P) C M ! pc = Invoke M' n\\<close>\n  have \"PROG P,T,mxs,length (instrs_of (PROG P) C M),ex_table_of (PROG P) C M\n    \\<turnstile> Invoke M' n,pc :: TYPING P C M\"\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n    \\<open>instrs_of (PROG P) C M ! pc = Invoke M' n\\<close> obtain d'\n    where \"match_ex_table (PROG P) NullPointer pc (ex_table_of (PROG P) C M) = \\<lfloor>(pc', d')\\<rfloor>\"\n    by cases (fastforce elim: JVMCFG.cases)\n  hence \"\\<exists>(f, t, D, h, d)\\<in>set (ex_table_of (PROG P) C M).\n    matches_ex_entry (PROG P) NullPointer pc (f, t, D, h, d) \\<and> h = pc' \\<and> d = d'\"\n    by -(drule match_ex_table_SomeD)\n  ultimately show ?case using \\<open>instrs_of (PROG P) C M ! pc = Invoke M' n\\<close>\n    by (fastforce simp: relevant_entries_def is_relevant_entry_def matches_ex_entry_def)\nnext\n  case (CFG_Invoke_Return_Exceptional_handle C P C0 Main M pc pc' M' n ek)\n  hence \"TYPING P C M ! pc \\<noteq> None\" and \"pc < length (instrs_of (PROG P) C M)\"\n    by simp_all\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Return)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 where\n    \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, instrs_of (PROG P) C M, ex_table_of (PROG P) C M) in C\"\n    by (fastforce dest: method_of_reachable_node_exists)\n  with \\<open>pc < length (instrs_of (PROG P) C M)\\<close> \\<open>instrs_of (PROG P) C M ! pc = Invoke M' n\\<close>\n  have \"PROG P,T,mxs,length (instrs_of (PROG P) C M),ex_table_of (PROG P) C M\n    \\<turnstile> Invoke M' n,pc :: TYPING P C M\"\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\n  moreover from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Return)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n    \\<open>instrs_of (PROG P) C M ! pc = Invoke M' n\\<close> obtain d' Exc\n    where \"match_ex_table (PROG P) Exc pc (ex_table_of (PROG P) C M) = \\<lfloor>(pc', d')\\<rfloor>\"\n    by cases (fastforce elim: JVMCFG.cases)\n  hence \"\\<exists>(f, t, D, h, d)\\<in>set (ex_table_of (PROG P) C M).\n    matches_ex_entry (PROG P) Exc pc (f, t, D, h, d) \\<and> h = pc' \\<and> d = d'\"\n    by -(drule match_ex_table_SomeD)\n  ultimately show ?case using \\<open>instrs_of (PROG P) C M ! pc = Invoke M' n\\<close>\n    by (fastforce simp: relevant_entries_def is_relevant_entry_def matches_ex_entry_def)\nnext\n  case (CFG_Invoke_Return_Check_Normal C P C0 Main M pc M' n ST LT ek)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Return)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with CFG_Invoke_Return_Check_Normal show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr [OF wf_jvmprog_is_wf_typ])\nnext \n  case (Method_LTrue P C0 Main C M)\n  from \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, None, Enter)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"instrs_of (PROG P) C M = is\"\n    by -(drule method_of_reachable_node_exists, auto)\n  with Method_LTrue show ?case\n    by (fastforce dest!: wt_jvm_prog_impl_wt_start [OF wf_jvmprog_is_wf_typ] simp: wt_start_def)\nnext\n  case (reachable_step P C0 Main C M opc nt ek C' M' opc' nt')\n  thus ?case\n    by (cases \"C = ClassMain P\") (fastforce elim: JVMCFG.cases, simp)\nqed simp_all\n\nlemma reachable_node_impl_wt_instr:\n  assumes \"(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, nt)\"\n  and \"C \\<noteq> ClassMain P\"\n  shows \"\\<exists>T mxs mpc xt. PROG P,T,mxs,mpc,xt \\<turnstile> (instrs_of (PROG P) C M ! pc),pc :: TYPING P C M\"\nproof -\n  from \\<open>C \\<noteq> ClassMain P\\<close> \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, nt)\\<close>\n    method_of_reachable_node_exists [of P C0 Main C M \"\\<lfloor>pc\\<rfloor>\" nt]\n    instr_of_reachable_node_typable [of P C0 Main C M \"\\<lfloor>pc\\<rfloor>\" nt]\n  obtain Ts T mxs mxl\\<^sub>0 \"is\" xt\n    where \"PROG P \\<turnstile> C sees M:Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in C\"\n    and \"TYPING P C M ! pc \\<noteq> None\"\n    and \"pc < length (instrs_of (PROG P) C M)\"\n    by fastforce+\n  with wf_jvmprog_is_wf_typ [of P]\n  have \"PROG P,T,mxs,length is,xt \\<turnstile> instrs_of (PROG P) C M ! pc,pc :: TYPING P C M\"\n    by (fastforce dest!: wt_jvm_prog_impl_wt_instr)\n  thus ?thesis\n    by blast\nqed\n\nlemma\n  \"\\<lbrakk> (P, C0, Main) \\<turnstile> (C, M, pc, nt) -ek\\<rightarrow> (C', M', pc', nt'); C \\<noteq> ClassMain P \\<or> C' \\<noteq> ClassMain P \\<rbrakk>\n  \\<Longrightarrow> \\<exists>T mb D. PROG P \\<turnstile> C0 sees Main:[]\\<rightarrow>T = mb in D\"\n  and reachable_node_impl_Main_ex:\n  \"\\<lbrakk> (P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, pc, nt); C \\<noteq> ClassMain P\\<rbrakk>\n  \\<Longrightarrow> \\<exists>T mb D. PROG P \\<turnstile> C0 sees Main:[]\\<rightarrow>T = mb in D\"\n  by (induct rule: JVMCFG_reachable_inducts) fastforce+\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/HRB-Slicing/JinjaVM_Inter/JVMCFG.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6187804337438501, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.26853923902814775}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2005         |\n            |              Februaru 2006                |\n            |                 March 2007  (modified)    |\n            |                 August 2007  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory FNF_F_sf_rest\nimports FNF_F_sf_def\nbegin\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite UnionT and InterT.                 *)\n(*                  disj_not1: (~ P | Q) = (P --> Q)                   *)\n\ndeclare disj_not1 [simp del]\n\n(*  The following simplification rules are deleted in this theory file *)\n(*       P (if Q then x else y) = ((Q --> P x) & (~ Q --> P y))        *)\n\ndeclare split_if  [split del]\n\n(*****************************************************************\n\n         1. full sequentialization for Depth-restriction (P |. n)\n         2.\n         3.\n\n *****************************************************************)\n\n(*============================================================*\n |                                                            |\n |                       Depth_rest                           |\n |                                                            |\n *============================================================*)\n\n(*============================================================*\n |                         Pfun P1 P2                         |\n *============================================================*)\n\n(*** relation ***)\n\ninductive_set\n  fsfF_Depth_rest_rel ::\n  \"(('p,'a) proc * nat * ('p,'a) proc) set\"\n\nwhere\nfsfF_Depth_rest_rel_zero:\n  \"(P1, 0, SDIV) : fsfF_Depth_rest_rel\"\n|\nfsfF_Depth_rest_rel_etc:\n  \"P1 ~: fsfF_proc\n   ==> (P1, Suc n, P1 |. (Suc n)) : fsfF_Depth_rest_rel\"\n|\nfsfF_Depth_rest_rel_int:\n  \"[| ALL c. if (c: sumset C1)\n             then (Rf1 c, Suc m, SRf c) : fsfF_Depth_rest_rel\n             else SRf c = DIV ;\n      sumset C1 ~= {} ; ALL c: sumset C1. Rf1 c : fsfF_proc |]\n   ==>\n   ((!! :C1 .. Rf1), Suc m, !! c:C1 .. SRf c)\n   : fsfF_Depth_rest_rel\"\n|\nfsfF_Depth_rest_rel_step:\n  \"[| ALL a. if a:A1\n             then (Pf1 a, n, SPf a) : fsfF_Depth_rest_rel\n             else SPf a = DIV ;\n      ALL a:A1. Pf1 a : fsfF_proc ;\n      Q1 = SKIP | Q1 = DIV | Q1 = STOP |]\n   ==> \n   ((? :A1 -> Pf1) [+] Q1, Suc n, (? :A1 -> SPf) [+] Q1) : fsfF_Depth_rest_rel\"\n\n(*** function ***)\n\ndefinition\n  fsfF_Depth_rest ::\n  \"('p,'a) proc => nat => ('p,'a) proc\"   (\"(1_ /|.seq _)\" [84,900] 84)\n  where\n  fsfF_Depth_rest_def:\n    \"P1 |.seq n == THE SP. (P1, n, SP) : fsfF_Depth_rest_rel\"\n\n(****************************************************************\n |                      uniquness                               |\n ****************************************************************)\n\nlemma fsfF_Depth_rest_rel_unique_in_lm:\n   \"(P1, n, SP1) : fsfF_Depth_rest_rel\n    ==> (ALL SP2. ((P1, n, SP2) : fsfF_Depth_rest_rel\n                   --> SP1 = SP2))\"\napply (rule fsfF_Depth_rest_rel.induct[of P1 n SP1])\napply (simp)\n\n(* zero *)\napply (intro allI impI)\napply (rotate_tac -1)\napply (erule fsfF_Depth_rest_rel.cases)\napply (simp_all)\n\n(* etc *)\napply (intro allI impI)\napply (rotate_tac -1)\napply (erule fsfF_Depth_rest_rel.cases)\napply (simp_all)\napply (simp add: fsfF_proc_int)\napply (simp add: fsfF_proc_ext)\n\n(* step_int *)\napply (intro allI impI)\napply (rotate_tac -1)\napply (erule fsfF_Depth_rest_rel.cases, simp_all)\n\n apply (rotate_tac -4)\n apply (drule sym)\n apply (simp add: fsfF_proc_int)\n\n apply (simp add: fun_eq_iff)\n apply (intro allI)\n apply (drule_tac x=\"x\" in spec)+\n apply (case_tac \"x : sumset C1a\")\n apply (simp)\n apply (simp)\n\n(* step *)\napply (intro allI impI)\napply (rotate_tac -1)\napply (erule fsfF_Depth_rest_rel.cases, simp_all)\n\n apply (rotate_tac -4)\n apply (drule sym)\n apply (simp add: fsfF_proc_ext)\n\n  apply (simp add: fun_eq_iff)\n  apply (rule allI)\n  apply (drule_tac x=\"x\" in spec)+\n  apply (case_tac \"x : A1a\")\n  apply (simp_all)\ndone\n\n(*-----------------------*\n |        unique         |\n *-----------------------*)\n\nlemma fsfF_Depth_rest_rel_unique:\n   \"[| (P1, n, SP1) : fsfF_Depth_rest_rel;\n       (P1, n, SP2) : fsfF_Depth_rest_rel |]\n    ==> SP1 = SP2\"\nby (simp add: fsfF_Depth_rest_rel_unique_in_lm)\n\nlemma fsfF_Depth_rest_rel_EX1:\n   \"(EX SP. (P1, n, SP) : fsfF_Depth_rest_rel)\n = (EX! SP. (P1, n, SP) : fsfF_Depth_rest_rel)\"\napply (rule iffI)\n\n apply (erule exE)\n apply (rule_tac a=\"SP\" in ex1I)\n apply (simp)\n apply (simp add: fsfF_Depth_rest_rel_unique)\n\n apply (elim ex1_implies_exE)\n apply (simp)\ndone\n\n(*------------------------------------------------------------*\n |                   fsfF_Depth_rest_rel (iff)                |\n *------------------------------------------------------------*)\n\n(* zero *)\n\nlemma fsfF_Depth_rest_rel_zero_iff:\n  \"(P1, 0, SP) : fsfF_Depth_rest_rel\n   = (SP = SDIV)\"\napply (rule)\napply (erule fsfF_Depth_rest_rel.cases, simp_all)\napply (simp add: fsfF_Depth_rest_rel_zero)\ndone\n\n(* etc *)\n\nlemma fsfF_Depth_rest_rel_etc_iff:\n  \"P1 ~: fsfF_proc\n   ==> (P1, Suc n, SP) : fsfF_Depth_rest_rel\n       = (SP = P1 |. Suc n)\"\napply (rule)\napply (erule fsfF_Depth_rest_rel.cases, simp_all)\n apply (simp add: fsfF_proc_int)\n apply (simp add: fsfF_proc_ext)\napply (simp add: fsfF_Depth_rest_rel_etc)\ndone\n\n(* int nat *)\n\nlemma fsfF_Depth_rest_rel_int_iff:\n  \"[| ALL c. if (c: sumset C1)\n             then (Rf1 c, Suc m, SRf c) : fsfF_Depth_rest_rel\n             else SRf c = DIV ;\n      sumset C1 ~= {} ; ALL c: sumset C1. Rf1 c : fsfF_proc |]\n   ==>\n   ((!! :C1 .. Rf1), Suc m, SP) : fsfF_Depth_rest_rel\n   = (SP = !! :C1 .. SRf)\"\napply (rule)\napply (erule fsfF_Depth_rest_rel.cases, simp_all)\n\n apply (rotate_tac -4)\n apply (drule sym)\n apply (simp add: fsfF_proc_int)\n\n apply (simp add: fun_eq_iff)\n apply (rule allI)\n apply (drule_tac x=\"x\" in spec)+\n apply (case_tac \"x : sumset C1a\")\n apply (simp add: fsfF_Depth_rest_rel_unique)\n\n apply (simp)\napply (simp add: fsfF_Depth_rest_rel_int)\ndone\n\n(* step *)\n\nlemma fsfF_Depth_rest_rel_step_iff:\n  \"[| ALL a. if a:A1\n             then (Pf1 a, n, SPf a) : fsfF_Depth_rest_rel\n             else SPf a = DIV ;\n      ALL a:A1. Pf1 a : fsfF_proc ;\n      Q1 = SKIP | Q1 = DIV | Q1 = STOP |]\n   ==> \n   ((? :A1 -> Pf1) [+] Q1, Suc n, SP) : fsfF_Depth_rest_rel\n   = (SP = (? :A1 -> SPf) [+] Q1)\"\napply (rule)\napply (erule fsfF_Depth_rest_rel.cases, simp_all)\n\n apply (rotate_tac -4)\n apply (drule sym)\n apply (simp add: fsfF_proc_ext)\n\n apply (simp add: fun_eq_iff)\n apply (intro allI conjI)\n apply (elim conjE)\n apply (drule_tac x=\"x\" in spec)+\n apply (case_tac \"x : A1a\")\n apply (simp add: fsfF_Depth_rest_rel_unique)\n apply (simp)\napply (simp add: fsfF_Depth_rest_rel_step)\ndone\n\n(****************************************************************\n |                      existency                               |\n ****************************************************************)\n\n(*** exists ***)\n\nlemma fsfF_Depth_rest_rel_exists_zero:\n   \"(EX SP. (P1, 0, SP) : fsfF_Depth_rest_rel)\"\napply (rule_tac x=\"SDIV\" in exI)\napply (simp add: fsfF_Depth_rest_rel.intros)\ndone\n\nlemma fsfF_Depth_rest_rel_exists_notin:\n   \"P1 ~: fsfF_proc\n    ==> (EX SP. (P1, n, SP) : fsfF_Depth_rest_rel)\"\napply (insert nat_zero_or_Suc)\napply (drule_tac x=\"n\" in spec)\napply (elim disjE exE)\napply (simp add: fsfF_Depth_rest_rel_exists_zero)\napply (rule_tac x=\"P1 |. n\" in exI)\napply (simp add: fsfF_Depth_rest_rel.intros)\ndone\n\n(*** in fsfF_proc ***)\n\n(********* P1 and P2 *********)\n\nlemma fsfF_Depth_rest_rel_exists_in:\n   \"P1 : fsfF_proc\n    ==> ALL n. (EX SP. (P1, n, SP) :  fsfF_Depth_rest_rel)\"\napply (rule fsfF_proc.induct[of P1])\napply (simp)\n\n(* int nat *)\napply (rule allI)\napply (insert nat_zero_or_Suc)\napply (drule_tac x=\"n\" in spec)\napply (elim disjE exE)\napply (simp add: fsfF_Depth_rest_rel_exists_zero)\n\napply (erule dist_BALL_conjE)\napply (simp add: exchange_ALL_BALL)\napply (simp add: choice_BALL_EX)\napply (drule_tac x=\"n\" in spec)\napply (elim exE)\napply (rule_tac x=\"!! c:C .. (if (c : sumset C) then f c else DIV)\" in exI)\napply (rule fsfF_Depth_rest_rel.intros)\napply (simp split: split_if)\napply (simp_all)\n\n(* ext *)\napply (rule allI)\napply (drule_tac x=\"n\" in spec)\napply (rotate_tac -1)\napply (erule disjE)\napply (simp add: fsfF_Depth_rest_rel_exists_zero)\n\napply (elim exE)\napply (erule dist_BALL_conjE)\n\napply (simp add: exchange_ALL_BALL)\napply (simp add: choice_BALL_EX)\napply (drule_tac x=\"m\" in spec)\napply (elim exE)\napply (rule_tac x=\"? a:A -> (if (a : A) then (f a) else DIV) [+] Q\" in exI)\napply (rule fsfF_Depth_rest_rel.intros)\napply (simp split: split_if)\napply (simp_all)\ndone\n\n(*-----------------------*\n |        exists         |\n *-----------------------*)\n\nlemma fsfF_Depth_rest_rel_exists:\n   \"EX SP. (P1, n, SP) :  fsfF_Depth_rest_rel\"\napply (case_tac \"P1 ~: fsfF_proc\")\napply (simp add: fsfF_Depth_rest_rel_exists_notin)\napply (simp add: fsfF_Depth_rest_rel_exists_in)\ndone\n\n(*-----------------------*\n |    uniquely exists    |\n *-----------------------*)\n\nlemma fsfF_Depth_rest_rel_unique_exists:\n   \"EX! SP. (P1, n, SP) :  fsfF_Depth_rest_rel\"\napply (simp add: fsfF_Depth_rest_rel_EX1[THEN sym])\napply (simp add: fsfF_Depth_rest_rel_exists)\ndone\n\n(*------------------------------------------------------------*\n |                        in fsfF_proc                        |\n *------------------------------------------------------------*)\n\nlemma fsfF_Depth_rest_rel_zero_in:\n  \"(P1, 0, SP) : fsfF_Depth_rest_rel ==> SP : fsfF_proc\"\napply (simp add: fsfF_Depth_rest_rel_zero_iff)\ndone\n\nlemma fsfF_Depth_rest_rel_in_lm:\n  \"P1 : fsfF_proc ==> \n   ALL n SP. (P1, n, SP) : fsfF_Depth_rest_rel --> SP : fsfF_proc\"\napply (rule fsfF_proc.induct[of P1])\napply (simp)\n\n(* int nat *)\napply (intro allI)\napply (insert nat_zero_or_Suc)\napply (drule_tac x=\"n\" in spec)\napply (elim disjE exE)\napply (simp add: fsfF_Depth_rest_rel_zero_in)\n\napply (intro impI)\napply (simp)\napply (rotate_tac -1)\napply (erule fsfF_Depth_rest_rel.cases, simp_all)\n\n apply (rotate_tac -4)\n apply (drule sym)\n apply (simp add: fsfF_proc.intros)\n\napply (rule fsfF_proc.intros)\napply (simp_all)\napply (rule ballI)\napply (drule_tac x=\"c\" in spec)\napply (drule_tac x=\"c\" in bspec, simp)\napply (force)\n\n(* ext *)\napply (intro allI)\napply (drule_tac x=\"n\" in spec)\napply (rotate_tac -1)\napply (erule disjE)\napply (simp add: fsfF_Depth_rest_rel_zero_in)\n\napply (intro impI)\napply (erule fsfF_Depth_rest_rel.cases, simp_all)\n\n apply (rotate_tac -4)\n apply (drule sym)\n apply (simp add: fsfF_proc.intros)\n\napply (rule fsfF_proc.intros)\napply (simp_all)\napply (rule ballI)\napply (drule_tac x=\"a\" in spec)\napply (drule_tac x=\"a\" in bspec, simp)\napply (force)\ndone\n\n(*------------------------------------*\n |                 in                 |\n *------------------------------------*)\n\nlemma fsfF_Depth_rest_rel_in:\n  \"[| P1 : fsfF_proc ; (P1, n, SP) : fsfF_Depth_rest_rel |]\n   ==> SP : fsfF_proc\"\napply (insert fsfF_Depth_rest_rel_in_lm[of P1])\napply (blast)\ndone\n\n(*------------------------------------------------------------*\n |             syntactical transformation to fsfF             |\n *------------------------------------------------------------*)\n\n(*** relation ***)\n\nlemma cspF_fsfF_Depth_rest_rel_eqF_zero:\n   \"(P1, 0, SP) : fsfF_Depth_rest_rel\n     ==> P1 |. 0 =F SP\"\napply (simp add: fsfF_Depth_rest_rel_zero_iff)\napply (rule cspF_rw_left)\napply (rule cspF_Depth_rest_Zero)\napply (rule cspF_SDIV_eqF)\ndone\n\nlemma cspF_fsfF_Depth_rest_rel_eqF_notin:\n   \"[| P1 ~: fsfF_proc ; (P1, n, SP) : fsfF_Depth_rest_rel |]\n    ==> P1 |. n =F SP\"\napply (insert nat_zero_or_Suc)\napply (drule_tac x=\"n\" in spec)\napply (elim disjE exE)\napply (simp add: cspF_fsfF_Depth_rest_rel_eqF_zero)\napply (simp add: fsfF_Depth_rest_rel_etc_iff)\ndone\n\nlemma cspF_fsfF_Depth_rest_rel_eqF_in:\n    \"P1 : fsfF_proc ==>\n     ALL n SP. (P1, n, SP) : fsfF_Depth_rest_rel\n                --> P1 |. n =F SP\"\napply (rule fsfF_proc.induct[of P1])\napply (simp)\n\n(* int *)\napply (intro allI)\napply (insert nat_zero_or_Suc)\napply (drule_tac x=\"n\" in spec)\napply (elim disjE exE)\napply (simp add: cspF_fsfF_Depth_rest_rel_eqF_zero)\n\napply (intro impI)\napply (simp)\napply (rotate_tac -1)\napply (erule fsfF_Depth_rest_rel.cases, simp_all)\napply (elim conjE)\n\napply (rule cspF_rw_left)\napply (rule cspF_Dist)\napply (rule cspF_decompo)\napply (simp)\napply (drule_tac x=\"c\" in bspec, simp)\napply (drule_tac x=\"c\" in spec)\napply (simp)\n\n(* ext *)\napply (intro allI)\napply (drule_tac x=\"n\" in spec)\napply (rotate_tac -1)\napply (erule disjE)\napply (simp add: cspF_fsfF_Depth_rest_rel_eqF_zero)\n\napply (intro impI)\napply (erule fsfF_Depth_rest_rel.cases, simp_all)\n\napply (rule cspF_rw_left)\napply (rule cspF_Ext_dist)\napply (rule cspF_decompo)\n\n apply (rule cspF_rw_left)\n apply (rule cspF_step)\n apply (rule cspF_decompo)\n apply (simp)\n apply (simp)\n apply (case_tac \"Q = STOP\")\n apply (simp add: cspF_STOP_Depth_rest)\n apply (simp add: cspF_SKIP_or_DIV_Depth_rest)\ndone\n\n(*------------------------------------*\n |                 eqF                |\n *------------------------------------*)\n\nlemma cspF_fsfF_Depth_rest_rel_eqF:\n   \"(P1, n, SP) : fsfF_Depth_rest_rel ==> P1 |. n =F SP\"\napply (case_tac \"P1 ~: fsfF_proc\")\napply (simp add: cspF_fsfF_Depth_rest_rel_eqF_notin)\napply (simp add: cspF_fsfF_Depth_rest_rel_eqF_in)\ndone\n\n(*************************************************************\n                  relation --> function\n *************************************************************)\n\nlemma fsfF_Depth_rest_in_rel:\n    \"(P1, n, P1 |.seq n) : fsfF_Depth_rest_rel\"\napply (simp add: fsfF_Depth_rest_def)\napply (rule theI'\n  [of \"(%R. (P1, n, R) : fsfF_Depth_rest_rel)\"])\napply (simp add: fsfF_Depth_rest_rel_unique_exists)\ndone\n\nlemma fsfF_Depth_rest_from_rel:\n    \"((P1, n, SP) : fsfF_Depth_rest_rel)\n   = (P1 |.seq n = SP)\"\napply (rule iffI)\napply (simp add: fsfF_Depth_rest_def)\napply (simp add: fsfF_Depth_rest_rel_unique_exists the1_equality)\n\napply (drule sym)\napply (simp add: fsfF_Depth_rest_in_rel)\ndone\n\nlemma fsfF_Depth_rest_to_rel:\n    \"(P1 |.seq n = SP)\n   = ((P1, n, SP) : fsfF_Depth_rest_rel)\"\nby (simp add: fsfF_Depth_rest_from_rel)\n\n(*************************************************************\n                          function\n *************************************************************)\n\nlemma fsfF_Depth_rest_zero:\n  \"P1 |.seq 0 = SDIV\"\napply (simp add: fsfF_Depth_rest_to_rel)\napply (simp add: fsfF_Depth_rest_rel_zero_iff)\ndone\n\nlemma fsfF_Depth_rest_etc:\n  \"P1 ~: fsfF_proc\n   ==> P1 |.seq (Suc n) = P1 |. (Suc n)\"\napply (simp add: fsfF_Depth_rest_to_rel)\napply (simp add: fsfF_Depth_rest_rel_etc_iff)\ndone\n\nlemma fsfF_Depth_rest_int:\n  \"[| sumset C1 ~= {} ; ALL c: sumset C1. Rf1 c : fsfF_proc |]\n   ==>\n   (!! :C1 .. Rf1) |.seq (Suc m) = \n    !! c:C1 .. (if c: sumset C1 then (Rf1 c |.seq (Suc m)) else DIV)\"\napply (simp add: fsfF_Depth_rest_to_rel)\napply (rule fsfF_Depth_rest_rel_int)\napply (simp_all)\napply (simp split: split_if)\napply (simp add: fsfF_Depth_rest_in_rel)\ndone\n\nlemma fsfF_Depth_rest_step:\n  \"[| ALL a:A1. Pf1 a : fsfF_proc ; Q1 = SKIP | Q1 = DIV | Q1 = STOP |]\n   ==>\n    ((? :A1 -> Pf1) [+] Q1) |.seq (Suc n) = \n    ((? a:A1 -> (if (a:A1) then (Pf1 a |.seq n) else DIV)) [+] Q1)\"\napply (simp add: fsfF_Depth_rest_to_rel)\napply (rule fsfF_Depth_rest_rel_step)\napply (simp_all)\napply (simp split: split_if)\napply (simp add: fsfF_Depth_rest_in_rel)\ndone\n\nlemmas fsfF_Depth_rest =\n       fsfF_Depth_rest_etc\n       fsfF_Depth_rest_int\n       fsfF_Depth_rest_step\n\n(*------------------------------------------------------------*\n |                        in fsfF_proc                        |\n *------------------------------------------------------------*)\n\nlemma fsfF_Depth_rest_in:\n  \"P1 : fsfF_proc\n   ==> P1 |.seq n : fsfF_proc\"\napply (rule fsfF_Depth_rest_rel_in[of P1 n])\napply (simp_all add: fsfF_Depth_rest_in_rel)\ndone\n\n(*------------------------------------------------------------*\n |             syntactical transformation to fsfF             |\n *------------------------------------------------------------*)\n\nlemma cspF_fsfF_Depth_rest_eqF:\n   \"P1 |. n =F P1 |.seq n\"\napply (rule cspF_fsfF_Depth_rest_rel_eqF)\napply (simp add: fsfF_Depth_rest_in_rel)\ndone\n\n(****************** to add them again ******************)\n\ndeclare split_if    [split]\ndeclare disj_not1   [simp]\n\nend\n", "meta": {"author": "pefribeiro", "repo": "CSP-Prover", "sha": "8967cc482e5695fca4abb52d9dc2cf36b7b7a44e", "save_path": "github-repos/isabelle/pefribeiro-CSP-Prover", "path": "github-repos/isabelle/pefribeiro-CSP-Prover/CSP-Prover-8967cc482e5695fca4abb52d9dc2cf36b7b7a44e/FNF_F/FNF_F_sf_rest.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6297746213017459, "lm_q2_score": 0.42632159254749036, "lm_q1q2_score": 0.2684865194993529}}
{"text": "theory javacap_auxiliary\nimports\n  Main\n  javacap_syntax\nbegin   \n\n(* Basic accessors for classes and interfaces *)\ndefinition \"class\" :: \"prog \\<Rightarrow> (cname \\<rightharpoonup> class)\" where\n  \"class p \\<equiv> map_of (pclasses p)\"\n\ndefinition is_class :: \"prog \\<Rightarrow> cname \\<Rightarrow> bool\" where\n  \"is_class p c \\<equiv> (class p c) \\<noteq> None\"\n\ndefinition interface :: \"prog \\<Rightarrow> (iname \\<rightharpoonup> interface)\" where\n  \"interface p \\<equiv> map_of (pinterfaces p)\"\n\ndefinition is_interface :: \"prog \\<Rightarrow> iname \\<Rightarrow> bool\" where\n  \"is_interface p i \\<equiv> (interface p i) \\<noteq> None\"\n\n(* Is this a capability interface? *)\ndefinition is_cap :: \"prog \\<Rightarrow> iname \\<Rightarrow> bool\" where\n  \"is_cap p c \\<equiv> (\\<exists>iface. interface p c = Some iface \\<and> icap iface)\"\n\n(* Determines if the specified type exists (is defined) in the given program *)\nprimrec is_type :: \"prog \\<Rightarrow> \\<tau> \\<Rightarrow> bool\" where\n  \"is_type p (ValT t) = True\" |\n  \"is_type p (ClassT c) = is_class p c\" |\n  \"is_type p (IfaceT c) = is_interface p c\"\n\nprimrec is_cap_type :: \"prog \\<Rightarrow> \\<tau> \\<Rightarrow> bool\" where\n  \"is_cap_type p (ValT t) = False\" |\n  \"is_cap_type p (ClassT c) = False\" |\n  \"is_cap_type p (IfaceT i) = is_cap p i\"\n\ndefinition grant :: \"prog \\<Rightarrow> (cname \\<rightharpoonup> label)\" where\n  \"grant p \\<equiv> map_of (pgrants p)\"\n\n(* utility *)\nprimrec map_adds :: \"('a \\<rightharpoonup> 'b) list \\<Rightarrow> ('a \\<rightharpoonup> 'b)\"  where\n  \"map_adds Nil = empty\" |\n  \"map_adds (x # xs) = x ++ (map_adds xs)\"\n\n(* Auxilliary definitions *)\ndefinition direct_subclass :: \"prog \\<Rightarrow> cname rel\"\n  where \"direct_subclass p \\<equiv> {(c,s). c \\<noteq> Object \\<and> (\\<exists>cl. class p c = Some cl \\<and> cextends cl = s) }\"\n\ndefinition direct_subinterface :: \"prog \\<Rightarrow> iname rel\"\n  where \"direct_subinterface p \\<equiv> {(c,s). (\\<exists>i. interface p c = Some i \\<and> s \\<in> set (iextends i))}\"\n\n(* Reflective transitive closure. *)\nabbreviation \"subclass\" :: \"prog \\<Rightarrow> cname rel\"\n  where \"subclass p \\<equiv> (direct_subclass p)\\<^sup>*\"\n\nabbreviation subinterface :: \"prog \\<Rightarrow> iname rel\"\n  where \"subinterface p \\<equiv> (direct_subinterface p)\\<^sup>*\"\n\n\n\n(* Note: subtype overrides supertype. *)\n(* 'a = cname, 'b = (class \\<Rightarrow> ('a \\<times> 'b) list) \\<Rightarrow> ('a \\<rightharpoonup> 'b) *)\ndefinition class_recursion ::\"prog \\<Rightarrow> cname \\<Rightarrow> (cdecl \\<Rightarrow> ('a \\<rightharpoonup> 'b)) \\<Rightarrow> ('a \\<rightharpoonup> 'b)\"\n  where\n  \"class_recursion p \\<equiv> wfrec ((direct_subclass p)\\<inverse>) (\\<lambda>rec cname f.\n     case class p cname of None \\<Rightarrow> undefined\n        | Some cl \\<Rightarrow> (if cname = Object then empty else rec (cextends cl) f) ++ (f (cname,cl)))\"\n  (* With the map ++ operator, the RHS overrides the LHS. Therefore, the subtype overrides the\n     supertype. *)\n\ndefinition interface_recursion ::  \"prog \\<Rightarrow> iname \\<Rightarrow> (interface \\<Rightarrow> ('a \\<times> 'b) list) \\<Rightarrow> ('a \\<rightharpoonup> 'b)\"\n  where \"interface_recursion p \\<equiv> wfrec ((direct_subinterface p)\\<inverse>) (\\<lambda>rec (iname::iname) f. \n    case interface p iname of None \\<Rightarrow> undefined \n        | Some cb \\<Rightarrow> map_adds (map (\\<lambda>super. rec super f) (iextends cb)) ++ map_of (f cb))\"\n\ndefinition cdeclmethods :: \"cdecl \\<Rightarrow> (mname \\<rightharpoonup> (cname \\<times> method))\"\n  where \"cdeclmethods \\<equiv> (\\<lambda>(cn,cl). map_comp (\\<lambda>m. Some (cn,m)) (map_of (cmethods cl)))\"\n(* equivalent to:  where \"cdeclmethods \\<equiv> (\\<lambda>(cn,cl). map_of (map (\\<lambda>(mn,meth). (mn,(cn,meth))) (cmethods cl)))\"*)\n\n(* For a given class and program name, returns a mapping\n   from method names to a (declaring class name, method declaration) pair.*)\ndefinition cmethod :: \"prog \\<Rightarrow> cname \\<Rightarrow> (mname \\<rightharpoonup> (cname \\<times> method))\"\n  where \"cmethod p c \\<equiv> class_recursion p c cdeclmethods\"     \n\ndefinition cmethoddecl :: \"prog \\<Rightarrow> cname \\<Rightarrow> (mname \\<rightharpoonup> mdecl)\"\n  where \"cmethoddecl p c \\<equiv> map_comp (\\<lambda>(cn,m). Some (mdecl m)) (cmethod p c)\"\n\ndefinition imethoddecl :: \"prog \\<Rightarrow> iname \\<Rightarrow> (mname \\<rightharpoonup> mdecl)\"\n  where \"imethoddecl p c \\<equiv> interface_recursion p c imethods\"\n\ndefinition methoddecl :: \"prog \\<Rightarrow> \\<tau> \\<Rightarrow> (mname \\<rightharpoonup> mdecl)\"\n  where \"methoddecl p t \\<equiv> (case t of ValT t' \\<Rightarrow> undefined | ClassT c \\<Rightarrow> cmethoddecl p c | IfaceT cb \\<Rightarrow> imethoddecl p cb)\"\n\ndefinition field :: \"prog \\<Rightarrow> cname \\<Rightarrow> (fname \\<rightharpoonup> fdecl)\"\n  where \"field p c \\<equiv> class_recursion p c (\\<lambda>(cn,cl). (map_of (cfields cl)))\"\n\n\n(* Gets the minimal label that acts as an identity when intersected with the method parameters\n   and return values of this object. *)\ndefinition sum_method_labels :: \"mdecl \\<Rightarrow> label\"\n  where \"sum_method_labels md \\<equiv> (tlabel (mret md)) \\<union> (\\<Union>p\\<in>(set (msig(mpar md))). (tlabel p))\"\n\n(* The set of all superinterfaces (including itself) of an interface *)\ndefinition superinterface_set :: \"prog \\<Rightarrow> iname \\<Rightarrow> iname set\" \n  where \"superinterface_set p ifname \\<equiv> {ifname'. (ifname, ifname') \\<in> (subinterface p)}\"\n\n(* The set of capabilities that can be accessed via a capability interface. It is the minimal label that acts \n   as an the identity when intersected with the label of any method return value or parameter\n   of that interface.  *)\ndefinition cap_label :: \"prog \\<Rightarrow> iname \\<Rightarrow> label\"\n  where \"cap_label p ifname \\<equiv> (superinterface_set p ifname) \\<union> \n         (let meths = imethoddecl p ifname in (\\<Union>m\\<in>dom(meths). sum_method_labels (the (meths m))))\"\n                                                                                        \n(* if x is in the domain of a mapping, and the mapping is in the list,\n   then x must be in the domain of the final mapping. *)\nlemma map_adds_domain:\n  shows \"x \\<in> dom m \\<Longrightarrow> m \\<in> (set ms) \\<Longrightarrow> x \\<in> dom (map_adds ms)\"\nproof (induction ms)\n  case Nil\n  then show ?case by auto (* by contradiction; the premises are not possible *)\nnext\n  case a1: (Cons a ms)\n  then show ?case\n  proof (cases \"m \\<in> set ms\")\n    case b1: True\n    then have \"x \\<in> dom (map_adds ms)\" using a1 by blast (* by induction *)\n    then have \"x \\<in> dom (map_adds (a # ms))\" by auto\n    then show ?thesis by simp\n  next\n    case b1: False\n    then have \"m = a\" using a1 by simp\n    then have \"x \\<in> dom (map_adds (a # ms))\" using a1 by auto\n    then show ?thesis by simp\n  qed\nqed\n\nlemma class_unfold:\n  assumes wf_subclass: \"wf ((direct_subclass P)\\<inverse>)\"\n  assumes class_exist: \"class P c = Some cl\"\n(* prog \\<Rightarrow> cname \\<Rightarrow> (class \\<Rightarrow> ('a \\<times> 'b) list) \\<Rightarrow> ('a \\<rightharpoonup> 'b) *)\n(*  (f::(class \\<Rightarrow> ('a \\<times> 'b) list)) *)\n  shows \"((class_recursion P c f)::('a \\<rightharpoonup> 'b)) = \n          (if c = Object then empty else class_recursion P (cextends cl) f) ++ (f (c,cl))\"\nproof -\n  define R where \"R = ((direct_subclass P)\\<inverse>)\"\n  define F where \"F = (\\<lambda>rec cname (f::(cdecl \\<Rightarrow> ('a \\<rightharpoonup> 'b))).\n     case class P cname of None \\<Rightarrow> undefined\n        | Some cl \\<Rightarrow> (if cname = Object then empty else rec (cextends cl) f) ++ (f (cname,cl)))\"\n  have a1: \"class_recursion P = wfrec R F\" unfolding R_def F_def class_recursion_def by simp\n  have \"wf R\" unfolding R_def using wf_subclass by simp\n  then have \"class_recursion P c = F (cut (wfrec R F) R c) c\"\n    unfolding class_recursion_def using R_def F_def wfrec by simp\n  then have \"class_recursion P c f = (\n      case class P c of None \\<Rightarrow> undefined\n        | Some cl \\<Rightarrow> (if c = Object then empty else \n              (if ((cextends cl), c) \\<in> (direct_subclass P)\\<inverse> then class_recursion P (cextends cl) else undefined) f) ++ (f (c,cl))\n       )\" using a1 R_def unfolding F_def cut_def by metis \n  also have \"... = (if c = Object then empty else class_recursion P (cextends cl) f) ++ (f (c,cl))\"\n    using class_exist unfolding direct_subclass_def by simp\n  finally show ?thesis .\nqed\n\nlemma interface_unfold:\n  assumes wf_subinterface: \"wf ((direct_subinterface P)\\<inverse>)\"\n  assumes interface_exist: \"interface P c = Some cb\"\n  shows \"((interface_recursion P c f)::('a \\<rightharpoonup> 'b)) = \n        map_adds (map (\\<lambda>super. interface_recursion P super f) (iextends cb)) ++ map_of (f cb)\"\nproof -\n  define R where \"R = ((direct_subinterface P)\\<inverse>)\"\n  define F where \"F = (\\<lambda>rec (iname::iname) (f::(interface \\<Rightarrow> ('a \\<times> 'b) list)). \n    case interface P iname of None \\<Rightarrow> undefined \n        | Some cb \\<Rightarrow>  map_adds (map (\\<lambda>super. rec super f) (iextends cb)) ++ map_of (f cb))\"\n  have a1: \"interface_recursion P = wfrec R F\" unfolding R_def F_def interface_recursion_def by simp\n  have a2: \"\\<forall>cb'\\<in>set (iextends cb). (if (cb', c) \\<in> (direct_subinterface P)\\<inverse> then (interface_recursion P) cb' else undefined) f = ((interface_recursion P) cb') f\"\n    unfolding direct_subinterface_def using interface_exist by simp\n\n  have \"wf R\" unfolding R_def using wf_subinterface by simp\n  then have \"interface_recursion P c = F (cut (wfrec R F) R c) c\"\n    unfolding interface_recursion_def using R_def F_def wfrec by simp\n  then have \"interface_recursion P c f = (\n      case interface P c of None \\<Rightarrow> undefined \n        | Some cb \\<Rightarrow> map_adds (map (\\<lambda>super. (if (super, c) \\<in> (direct_subinterface P)\\<inverse> then (interface_recursion P) super else undefined) f) (iextends cb)) ++ map_of (f cb)\n       )\" using a1 F_def unfolding cut_def R_def by metis\n  also have \"... = map_adds (map (\\<lambda>super. (interface_recursion P) super f) (iextends cb)) ++ map_of (f cb)\"\n    using interface_exist a2 map_eq_conv option.simps(5) by (metis (no_types, lifting)) \n  finally show ?thesis .\nqed\n\nlemma cmethod_unfold:\n  assumes wf_subclass: \"wf ((direct_subclass P)\\<inverse>)\"\n  assumes class_exist: \"class P c = Some cl\"\n  shows \"cmethod P c = (if c = Object then empty else cmethod P (cextends cl)) ++ (cdeclmethods (c,cl))\"\n  using assms class_unfold unfolding cmethod_def by metis\n\nlemma cmethod_cmethods:\n  assumes wf_subclass: \"wf ((direct_subclass P)\\<inverse>)\"\n  assumes class_exist: \"class P c = Some cl\"\n  assumes method_exist: \"(map_of (cmethods cl)) mname = Some m\"\n  shows \"cmethod P c mname = Some (c,m)\"\nproof -\n  have \"cdeclmethods (c,cl) mname = Some (c,m)\"\n    unfolding cdeclmethods_def using method_exist by auto\n  then show ?thesis using cmethod_unfold wf_subclass class_exist by auto\nqed\n\nlemma cmethoddecl_cmethods:\n  assumes wf_subclass: \"wf ((direct_subclass P)\\<inverse>)\"\n  assumes class_exist: \"class P c = Some cl\"\n  assumes method_exist: \"(map_of (cmethods cl)) mname = Some m\"\n  shows \"cmethoddecl P c mname = Some (mdecl m)\"\n  using cmethod_cmethods assms unfolding cmethoddecl_def by auto\n\nlemma field_unfold:\n  assumes wf_subclass: \"wf ((direct_subclass P)\\<inverse>)\"\n  assumes class_exist: \"class P c = Some cl\"\n  shows \"field P c = (if c = Object then empty else field P (cextends cl)) ++ (map_of (cfields cl))\"\nproof -\n  have \"field P c = (if c = Object then empty else field P (cextends cl)) ++ ((\\<lambda>(cn,cl). (map_of (cfields cl))) (c,cl))\"\n    using assms class_unfold unfolding field_def by metis\n  then show ?thesis by auto\nqed\n\nlemma imethoddecl_unfold:\n  assumes wf_subinterface: \"wf ((direct_subinterface P)\\<inverse>)\"\n  assumes interface_exist: \"interface P c = Some cb\"\n  shows \"imethoddecl P c = map_adds (map (\\<lambda>super. imethoddecl P super) (iextends cb)) ++ map_of (imethods cb)\"\n  using assms interface_unfold unfolding imethoddecl_def by metis\n\nend", "meta": {"author": "patrickmeiring", "repo": "JavaCap", "sha": "43ded44673c45d596b6a399ef24292416591520b", "save_path": "github-repos/isabelle/patrickmeiring-JavaCap", "path": "github-repos/isabelle/patrickmeiring-JavaCap/JavaCap-43ded44673c45d596b6a399ef24292416591520b/javacap_auxiliary.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297746074044134, "lm_q2_score": 0.4263215925474903, "lm_q1q2_score": 0.26848651357462}}
{"text": "(*  Title:      HOL/HOLCF/IOA/meta_theory/SimCorrectness.thy\n    Author:     Olaf Müller\n*)\n\nsection {* Correctness of Simulations in HOLCF/IOA *}\n\ntheory SimCorrectness\nimports Simulations\nbegin\n\ndefinition\n  (* Note: s2 instead of s1 in last argument type !! *)\n  corresp_ex_simC :: \"('a,'s2)ioa => (('s1 * 's2)set) => ('a,'s1)pairs\n                   -> ('s2 => ('a,'s2)pairs)\" where\n  \"corresp_ex_simC A R = (fix$(LAM h ex. (%s. case ex of\n      nil =>  nil\n    | x##xs => (flift1 (%pr. let a = (fst pr); t = (snd pr);\n                                 T' = @t'. ? ex1. (t,t'):R & move A ex1 s a t'\n                             in\n                                (@cex. move A cex s a T')\n                                 @@ ((h$xs) T'))\n                        $x) )))\"\n\ndefinition\n  corresp_ex_sim :: \"('a,'s2)ioa => (('s1 *'s2)set) =>\n                      ('a,'s1)execution => ('a,'s2)execution\" where\n  \"corresp_ex_sim A R ex == let S'= (@s'.(fst ex,s'):R & s': starts_of A)\n                            in\n                               (S',(corresp_ex_simC A R$(snd ex)) S')\"\n\n\nsubsection \"corresp_ex_sim\"\n\nlemma corresp_ex_simC_unfold: \"corresp_ex_simC A R  = (LAM ex. (%s. case ex of\n       nil =>  nil\n     | x##xs => (flift1 (%pr. let a = (fst pr); t = (snd pr);\n                                  T' = @t'. ? ex1. (t,t'):R & move A ex1 s a t'\n                              in\n                                 (@cex. move A cex s a T')\n                               @@ ((corresp_ex_simC A R $xs) T'))\n                         $x) ))\"\napply (rule trans)\napply (rule fix_eq2)\napply (simp only: corresp_ex_simC_def)\napply (rule beta_cfun)\napply (simp add: flift1_def)\ndone\n\nlemma corresp_ex_simC_UU: \"(corresp_ex_simC A R$UU) s=UU\"\napply (subst corresp_ex_simC_unfold)\napply simp\ndone\n\nlemma corresp_ex_simC_nil: \"(corresp_ex_simC A R$nil) s = nil\"\napply (subst corresp_ex_simC_unfold)\napply simp\ndone\n\nlemma corresp_ex_simC_cons: \"(corresp_ex_simC A R$((a,t)>>xs)) s =\n           (let T' = @t'. ? ex1. (t,t'):R & move A ex1 s a t'\n            in\n             (@cex. move A cex s a T')\n              @@ ((corresp_ex_simC A R$xs) T'))\"\napply (rule trans)\napply (subst corresp_ex_simC_unfold)\napply (simp add: Consq_def flift1_def)\napply simp\ndone\n\n\ndeclare corresp_ex_simC_UU [simp] corresp_ex_simC_nil [simp] corresp_ex_simC_cons [simp]\n\n\nsubsection \"properties of move\"\n\ndeclare Let_def [simp del]\n\nlemma move_is_move_sim:\n   \"[|is_simulation R C A; reachable C s; s -a--C-> t; (s,s'):R|] ==>\n      let T' = @t'. ? ex1. (t,t'):R & move A ex1 s' a t' in\n      (t,T'): R & move A (@ex2. move A ex2 s' a T') s' a T'\"\napply (unfold is_simulation_def)\n\n(* Does not perform conditional rewriting on assumptions automatically as\n   usual. Instantiate all variables per hand. Ask Tobias?? *)\napply (subgoal_tac \"? t' ex. (t,t') :R & move A ex s' a t'\")\nprefer 2\napply simp\napply (erule conjE)\napply (erule_tac x = \"s\" in allE)\napply (erule_tac x = \"s'\" in allE)\napply (erule_tac x = \"t\" in allE)\napply (erule_tac x = \"a\" in allE)\napply simp\n(* Go on as usual *)\napply (erule exE)\napply (drule_tac x = \"t'\" and P = \"%t'. ? ex. (t,t') :R & move A ex s' a t'\" in someI)\napply (erule exE)\napply (erule conjE)\napply (simp add: Let_def)\napply (rule_tac x = \"ex\" in someI)\napply assumption\ndone\n\ndeclare Let_def [simp]\n\nlemma move_subprop1_sim:\n   \"[|is_simulation R C A; reachable C s; s-a--C-> t; (s,s'):R|] ==>\n    let T' = @t'. ? ex1. (t,t'):R & move A ex1 s' a t' in\n     is_exec_frag A (s',@x. move A x s' a T')\"\napply (cut_tac move_is_move_sim)\ndefer\napply assumption+\napply (simp add: move_def)\ndone\n\nlemma move_subprop2_sim:\n   \"[|is_simulation R C A; reachable C s; s-a--C-> t; (s,s'):R|] ==>\n    let T' = @t'. ? ex1. (t,t'):R & move A ex1 s' a t' in\n    Finite (@x. move A x s' a T')\"\napply (cut_tac move_is_move_sim)\ndefer\napply assumption+\napply (simp add: move_def)\ndone\n\nlemma move_subprop3_sim:\n   \"[|is_simulation R C A; reachable C s; s-a--C-> t; (s,s'):R|] ==>\n    let T' = @t'. ? ex1. (t,t'):R & move A ex1 s' a t' in\n     laststate (s',@x. move A x s' a T') = T'\"\napply (cut_tac move_is_move_sim)\ndefer\napply assumption+\napply (simp add: move_def)\ndone\n\nlemma move_subprop4_sim:\n   \"[|is_simulation R C A; reachable C s; s-a--C-> t; (s,s'):R|] ==>\n    let T' = @t'. ? ex1. (t,t'):R & move A ex1 s' a t' in\n      mk_trace A$((@x. move A x s' a T')) =\n        (if a:ext A then a>>nil else nil)\"\napply (cut_tac move_is_move_sim)\ndefer\napply assumption+\napply (simp add: move_def)\ndone\n\nlemma move_subprop5_sim:\n   \"[|is_simulation R C A; reachable C s; s-a--C-> t; (s,s'):R|] ==>\n    let T' = @t'. ? ex1. (t,t'):R & move A ex1 s' a t' in\n      (t,T'):R\"\napply (cut_tac move_is_move_sim)\ndefer\napply assumption+\napply (simp add: move_def)\ndone\n\n\nsubsection {* TRACE INCLUSION Part 1: Traces coincide *}\n\nsubsubsection \"Lemmata for <==\"\n\n(* ------------------------------------------------------\n                 Lemma 1 :Traces coincide\n   ------------------------------------------------------- *)\n\ndeclare split_if [split del]\nlemma traces_coincide_sim [rule_format (no_asm)]:\n  \"[|is_simulation R C A; ext C = ext A|] ==>\n         !s s'. reachable C s & is_exec_frag C (s,ex) & (s,s'): R -->\n             mk_trace C$ex = mk_trace A$((corresp_ex_simC A R$ex) s')\"\n\napply (tactic {* pair_induct_tac @{context} \"ex\" [@{thm is_exec_frag_def}] 1 *})\n(* cons case *)\napply auto\napply (rename_tac ex a t s s')\napply (simp add: mk_traceConc)\napply (frule reachable.reachable_n)\napply assumption\napply (erule_tac x = \"t\" in allE)\napply (erule_tac x = \"@t'. ? ex1. (t,t') :R & move A ex1 s' a t'\" in allE)\napply (simp add: move_subprop5_sim [unfolded Let_def]\n  move_subprop4_sim [unfolded Let_def] split add: split_if)\ndone\ndeclare split_if [split]\n\n\n(* ----------------------------------------------------------- *)\n(*               Lemma 2 : corresp_ex_sim is execution         *)\n(* ----------------------------------------------------------- *)\n\n\nlemma correspsim_is_execution [rule_format (no_asm)]:\n \"[| is_simulation R C A |] ==>\n  !s s'. reachable C s & is_exec_frag C (s,ex) & (s,s'):R\n  --> is_exec_frag A (s',(corresp_ex_simC A R$ex) s')\"\n\napply (tactic {* pair_induct_tac @{context} \"ex\" [@{thm is_exec_frag_def}] 1 *})\n(* main case *)\napply auto\napply (rename_tac ex a t s s')\napply (rule_tac t = \"@t'. ? ex1. (t,t') :R & move A ex1 s' a t'\" in lemma_2_1)\n\n(* Finite *)\napply (erule move_subprop2_sim [unfolded Let_def])\napply assumption+\napply (rule conjI)\n\n(* is_exec_frag *)\napply (erule move_subprop1_sim [unfolded Let_def])\napply assumption+\napply (rule conjI)\n\n(* Induction hypothesis  *)\n(* reachable_n looping, therefore apply it manually *)\napply (erule_tac x = \"t\" in allE)\napply (erule_tac x = \"@t'. ? ex1. (t,t') :R & move A ex1 s' a t'\" in allE)\napply simp\napply (frule reachable.reachable_n)\napply assumption\napply (simp add: move_subprop5_sim [unfolded Let_def])\n(* laststate *)\napply (erule move_subprop3_sim [unfolded Let_def, symmetric])\napply assumption+\ndone\n\n\nsubsection \"Main Theorem: TRACE - INCLUSION\"\n\n(* -------------------------------------------------------------------------------- *)\n\n  (* generate condition (s,S'):R & S':starts_of A, the first being intereting\n     for the induction cases concerning the two lemmas correpsim_is_execution and\n     traces_coincide_sim, the second for the start state case.\n     S':= @s'. (s,s'):R & s':starts_of A, where s:starts_of C  *)\n\nlemma simulation_starts:\n\"[| is_simulation R C A; s:starts_of C |]\n  ==> let S' = @s'. (s,s'):R & s':starts_of A in\n      (s,S'):R & S':starts_of A\"\n  apply (simp add: is_simulation_def corresp_ex_sim_def Int_non_empty Image_def)\n  apply (erule conjE)+\n  apply (erule ballE)\n  prefer 2 apply (blast)\n  apply (erule exE)\n  apply (rule someI2)\n  apply assumption\n  apply blast\n  done\n\nlemmas sim_starts1 = simulation_starts [unfolded Let_def, THEN conjunct1]\nlemmas sim_starts2 = simulation_starts [unfolded Let_def, THEN conjunct2]\n\n\nlemma trace_inclusion_for_simulations:\n  \"[| ext C = ext A; is_simulation R C A |]\n           ==> traces C <= traces A\"\n\n  apply (unfold traces_def)\n\n  apply (simp (no_asm) add: has_trace_def2)\n  apply auto\n\n  (* give execution of abstract automata *)\n  apply (rule_tac x = \"corresp_ex_sim A R ex\" in bexI)\n\n  (* Traces coincide, Lemma 1 *)\n  apply (tactic {* pair_tac @{context} \"ex\" 1 *})\n  apply (rename_tac s ex)\n  apply (simp (no_asm) add: corresp_ex_sim_def)\n  apply (rule_tac s = \"s\" in traces_coincide_sim)\n  apply assumption+\n  apply (simp add: executions_def reachable.reachable_0 sim_starts1)\n\n  (* corresp_ex_sim is execution, Lemma 2 *)\n  apply (tactic {* pair_tac @{context} \"ex\" 1 *})\n  apply (simp add: executions_def)\n  apply (rename_tac s ex)\n\n  (* start state *)\n  apply (rule conjI)\n  apply (simp add: sim_starts2 corresp_ex_sim_def)\n\n  (* is-execution-fragment *)\n  apply (simp add: corresp_ex_sim_def)\n  apply (rule_tac s = s in correspsim_is_execution)\n  apply assumption\n  apply (simp add: reachable.reachable_0 sim_starts1)\n  done\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/HOLCF/IOA/meta_theory/SimCorrectness.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953797290153, "lm_q2_score": 0.4649015713733885, "lm_q1q2_score": 0.2684785094968909}}
{"text": "theory Design_generated_generated imports \"../Toy_Library\"   \"../Toy_Library_Static\" begin\n\n(* 1 ************************************ 0 + 1 *)\nsection \\<open>Class Model: Introduction\\<close>\n\n(* 2 ************************************ 1 + 1 *)\ntext \\<open>\n  For certain concepts like classes and class-types, only a generic\n  definition for its resulting semantics can be given. Generic means,\n  there is a function outside HOL that ``compiles'' a concrete,\n  closed-world class diagram into a ``theory'' of this data model,\n  consisting of a bunch of definitions for classes, accessors, method,\n  casts, and tests for actual types, as well as proofs for the\n  fundamental properties of these operations in this concrete data\n  model. \\<close>\n\n(* 3 ************************************ 2 + 1 *)\nsection \\<open>Class Model: The Construction of the Object Universe\\<close>\n\n(* 4 ************************************ 3 + 1 *)\ntext \\<open>\n   Our data universe  consists in the concrete class diagram just of node's,\nand implicitly of the class object. Each class implies the existence of a class\ntype defined for the corresponding object representations as follows: \\<close>\n\n(* 5 ************************************ 4 + 10 *)\ndatatype ty\\<E>\\<X>\\<T>\\<^sub>A\\<^sub>t\\<^sub>o\\<^sub>m = mk\\<E>\\<X>\\<T>\\<^sub>A\\<^sub>t\\<^sub>o\\<^sub>m \"oid\" \"oid list option\" \"int option\" \"bool option\" \"nat option\" \"unit option\"\ndatatype ty\\<^sub>A\\<^sub>t\\<^sub>o\\<^sub>m = mk\\<^sub>A\\<^sub>t\\<^sub>o\\<^sub>m \"ty\\<E>\\<X>\\<T>\\<^sub>A\\<^sub>t\\<^sub>o\\<^sub>m\" \"int option\"\ndatatype ty\\<E>\\<X>\\<T>\\<^sub>M\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>c\\<^sub>u\\<^sub>l\\<^sub>e = mk\\<E>\\<X>\\<T>\\<^sub>M\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>c\\<^sub>u\\<^sub>l\\<^sub>e_\\<^sub>A\\<^sub>t\\<^sub>o\\<^sub>m \"ty\\<^sub>A\\<^sub>t\\<^sub>o\\<^sub>m\"\n                        | mk\\<E>\\<X>\\<T>\\<^sub>M\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>c\\<^sub>u\\<^sub>l\\<^sub>e \"oid\" \"oid list option\" \"int option\" \"bool option\" \"nat option\" \"unit option\"\ndatatype ty\\<^sub>M\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>c\\<^sub>u\\<^sub>l\\<^sub>e = mk\\<^sub>M\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>c\\<^sub>u\\<^sub>l\\<^sub>e \"ty\\<E>\\<X>\\<T>\\<^sub>M\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>c\\<^sub>u\\<^sub>l\\<^sub>e\"\ndatatype ty\\<E>\\<X>\\<T>\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n = mk\\<E>\\<X>\\<T>\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n_\\<^sub>M\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>c\\<^sub>u\\<^sub>l\\<^sub>e \"ty\\<^sub>M\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>c\\<^sub>u\\<^sub>l\\<^sub>e\"\n                        | mk\\<E>\\<X>\\<T>\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n_\\<^sub>A\\<^sub>t\\<^sub>o\\<^sub>m \"ty\\<^sub>A\\<^sub>t\\<^sub>o\\<^sub>m\"\n                        | mk\\<E>\\<X>\\<T>\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n \"oid\" \"nat option\" \"unit option\"\ndatatype ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n = mk\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n \"ty\\<E>\\<X>\\<T>\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" \"oid list option\" \"int option\" \"bool option\"\ndatatype ty\\<E>\\<X>\\<T>\\<^sub>G\\<^sub>a\\<^sub>l\\<^sub>a\\<^sub>x\\<^sub>y = mk\\<E>\\<X>\\<T>\\<^sub>G\\<^sub>a\\<^sub>l\\<^sub>a\\<^sub>x\\<^sub>y_\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\n                        | mk\\<E>\\<X>\\<T>\\<^sub>G\\<^sub>a\\<^sub>l\\<^sub>a\\<^sub>x\\<^sub>y_\\<^sub>M\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>c\\<^sub>u\\<^sub>l\\<^sub>e \"ty\\<^sub>M\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>c\\<^sub>u\\<^sub>l\\<^sub>e\"\n                        | mk\\<E>\\<X>\\<T>\\<^sub>G\\<^sub>a\\<^sub>l\\<^sub>a\\<^sub>x\\<^sub>y_\\<^sub>A\\<^sub>t\\<^sub>o\\<^sub>m \"ty\\<^sub>A\\<^sub>t\\<^sub>o\\<^sub>m\"\n                        | mk\\<E>\\<X>\\<T>\\<^sub>G\\<^sub>a\\<^sub>l\\<^sub>a\\<^sub>x\\<^sub>y \"oid\"\ndatatype ty\\<^sub>G\\<^sub>a\\<^sub>l\\<^sub>a\\<^sub>x\\<^sub>y = mk\\<^sub>G\\<^sub>a\\<^sub>l\\<^sub>a\\<^sub>x\\<^sub>y \"ty\\<E>\\<X>\\<T>\\<^sub>G\\<^sub>a\\<^sub>l\\<^sub>a\\<^sub>x\\<^sub>y\" \"nat option\" \"unit option\"\ndatatype ty\\<E>\\<X>\\<T>\\<^sub>T\\<^sub>o\\<^sub>y\\<^sub>A\\<^sub>n\\<^sub>y = mk\\<E>\\<X>\\<T>\\<^sub>T\\<^sub>o\\<^sub>y\\<^sub>A\\<^sub>n\\<^sub>y_\\<^sub>G\\<^sub>a\\<^sub>l\\<^sub>a\\<^sub>x\\<^sub>y \"ty\\<^sub>G\\<^sub>a\\<^sub>l\\<^sub>a\\<^sub>x\\<^sub>y\"\n                        | mk\\<E>\\<X>\\<T>\\<^sub>T\\<^sub>o\\<^sub>y\\<^sub>A\\<^sub>n\\<^sub>y_\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\n                        | mk\\<E>\\<X>\\<T>\\<^sub>T\\<^sub>o\\<^sub>y\\<^sub>A\\<^sub>n\\<^sub>y_\\<^sub>M\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>c\\<^sub>u\\<^sub>l\\<^sub>e \"ty\\<^sub>M\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>c\\<^sub>u\\<^sub>l\\<^sub>e\"\n                        | mk\\<E>\\<X>\\<T>\\<^sub>T\\<^sub>o\\<^sub>y\\<^sub>A\\<^sub>n\\<^sub>y_\\<^sub>A\\<^sub>t\\<^sub>o\\<^sub>m \"ty\\<^sub>A\\<^sub>t\\<^sub>o\\<^sub>m\"\n                        | mk\\<E>\\<X>\\<T>\\<^sub>T\\<^sub>o\\<^sub>y\\<^sub>A\\<^sub>n\\<^sub>y \"oid\"\ndatatype ty\\<^sub>T\\<^sub>o\\<^sub>y\\<^sub>A\\<^sub>n\\<^sub>y = mk\\<^sub>T\\<^sub>o\\<^sub>y\\<^sub>A\\<^sub>n\\<^sub>y \"ty\\<E>\\<X>\\<T>\\<^sub>T\\<^sub>o\\<^sub>y\\<^sub>A\\<^sub>n\\<^sub>y\"\n\n(* 6 ************************************ 14 + 1 *)\ntext \\<open>\n   Now, we construct a concrete ``universe of ToyAny types'' by injection into a\nsum type containing the class types. This type of ToyAny will be used as instance\nfor all respective type-variables. \\<close>\n\n(* 7 ************************************ 15 + 1 *)\ndatatype \\<AA> = in\\<^sub>A\\<^sub>t\\<^sub>o\\<^sub>m \"ty\\<^sub>A\\<^sub>t\\<^sub>o\\<^sub>m\"\n                        | in\\<^sub>M\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>c\\<^sub>u\\<^sub>l\\<^sub>e \"ty\\<^sub>M\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>c\\<^sub>u\\<^sub>l\\<^sub>e\"\n                        | in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\n                        | in\\<^sub>G\\<^sub>a\\<^sub>l\\<^sub>a\\<^sub>x\\<^sub>y \"ty\\<^sub>G\\<^sub>a\\<^sub>l\\<^sub>a\\<^sub>x\\<^sub>y\"\n                        | in\\<^sub>T\\<^sub>o\\<^sub>y\\<^sub>A\\<^sub>n\\<^sub>y \"ty\\<^sub>T\\<^sub>o\\<^sub>y\\<^sub>A\\<^sub>n\\<^sub>y\"\n\n(* 8 ************************************ 16 + 1 *)\ntext \\<open>\n   Having fixed the object universe, we can introduce type synonyms that exactly correspond\nto Toy types. Again, we exploit that our representation of Toy is a ``shallow embedding'' with a\none-to-one correspondance of Toy-types to types of the meta-language HOL. \\<close>\n\n(* 9 ************************************ 17 + 5 *)\ntype_synonym Atom = \"\\<langle>\\<langle>ty\\<^sub>A\\<^sub>t\\<^sub>o\\<^sub>m\\<rangle>\\<^sub>\\<bottom>\\<rangle>\\<^sub>\\<bottom>\"\ntype_synonym Molecule = \"\\<langle>\\<langle>ty\\<^sub>M\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>c\\<^sub>u\\<^sub>l\\<^sub>e\\<rangle>\\<^sub>\\<bottom>\\<rangle>\\<^sub>\\<bottom>\"\ntype_synonym Person = \"\\<langle>\\<langle>ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\\<rangle>\\<^sub>\\<bottom>\\<rangle>\\<^sub>\\<bottom>\"\ntype_synonym Galaxy = \"\\<langle>\\<langle>ty\\<^sub>G\\<^sub>a\\<^sub>l\\<^sub>a\\<^sub>x\\<^sub>y\\<rangle>\\<^sub>\\<bottom>\\<rangle>\\<^sub>\\<bottom>\"\ntype_synonym ToyAny = \"\\<langle>\\<langle>ty\\<^sub>T\\<^sub>o\\<^sub>y\\<^sub>A\\<^sub>n\\<^sub>y\\<rangle>\\<^sub>\\<bottom>\\<rangle>\\<^sub>\\<bottom>\"\n\n(* 10 ************************************ 22 + 1 *)\nsection \\<open>Class Model: The Accessors\\<close>\n\n(* 11 ************************************ 23 + 3 *)\ndefinition \"oid\\<^sub>A\\<^sub>t\\<^sub>o\\<^sub>m_0___boss = 0\"\ndefinition \"oid\\<^sub>M\\<^sub>o\\<^sub>l\\<^sub>e\\<^sub>c\\<^sub>u\\<^sub>l\\<^sub>e_0___boss = 0\"\ndefinition \"oid\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n_0___boss = 0\"\n\n(* 12 ************************************ 26 + 2 *)\ndefinition \"switch\\<^sub>2_01 = (\\<lambda> [x0 , x1] \\<Rightarrow> (x0 , x1))\"\ndefinition \"switch\\<^sub>2_10 = (\\<lambda> [x0 , x1] \\<Rightarrow> (x1 , x0))\"\n\n(* 13 ************************************ 28 + 1 *)\nsection \\<open>Instance\\<close>\n\n(* 14 ************************************ 29 + 3 *)\ndefinition \"oid1 = 1\"\ndefinition \"oid2 = 2\"\ndefinition \"inst_assoc1 = (\\<lambda>oid_class to_from oid. ((case (deref_assocs_list ((to_from::oid list list \\<Rightarrow> oid list \\<times> oid list)) ((oid::oid)) ((the ((((map_of_list ([(oid\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n_0___boss , (List.map ((\\<lambda>(x , y). [x , y]) o switch\\<^sub>2_01) ([[[oid1] , [oid2]]])))]))) ((oid_class::oid))))))) of Nil \\<Rightarrow> None\n    | l \\<Rightarrow> (Some (l)))::oid list option))\"\n\n(* 15 ************************************ 32 + 0 *)\n\n(* 16 ************************************ 32 + 1 *)\nsection \\<open>Instance\\<close>\n\n(* 17 ************************************ 33 + 2 *)\ndefinition \"oid3 = 3\"\ndefinition \"inst_assoc3 = (\\<lambda>oid_class to_from oid. ((case (deref_assocs_list ((to_from::oid list list \\<Rightarrow> oid list \\<times> oid list)) ((oid::oid)) ((the ((((map_of_list ([]))) ((oid_class::oid))))))) of Nil \\<Rightarrow> None\n    | l \\<Rightarrow> (Some (l)))::oid list option))\"\n\n(* 18 ************************************ 35 + 0 *)\n\n(* 19 ************************************ 35 + 1 *)\nsection \\<open>Instance\\<close>\n\n(* 20 ************************************ 36 + 5 *)\ndefinition \"oid4 = 4\"\ndefinition \"oid5 = 5\"\ndefinition \"oid6 = 6\"\ndefinition \"oid7 = 7\"\ndefinition \"inst_assoc4 = (\\<lambda>oid_class to_from oid. ((case (deref_assocs_list ((to_from::oid list list \\<Rightarrow> oid list \\<times> oid list)) ((oid::oid)) ((the ((((map_of_list ([(oid\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n_0___boss , (List.map ((\\<lambda>(x , y). [x , y]) o switch\\<^sub>2_01) ([[[oid7] , [oid6]] , [[oid6] , [oid1]] , [[oid4] , [oid5]]])))]))) ((oid_class::oid))))))) of Nil \\<Rightarrow> None\n    | l \\<Rightarrow> (Some (l)))::oid list option))\"\n\n(* 21 ************************************ 41 + 0 *)\n\n(* 22 ************************************ 41 + 1 *)\nsection \\<open>State (Floor 2)\\<close>\n\n(* 23 ************************************ 42 + 1 *)\nlocale state_\\<sigma>\\<^sub>1 =\nfixes \"oid1\" :: \"nat\"\nfixes \"oid2\" :: \"nat\"\nfixes \"oid4\" :: \"nat\"\nfixes \"oid5\" :: \"nat\"\nfixes \"oid6\" :: \"nat\"\nfixes \"oid7\" :: \"nat\"\nassumes distinct_oid: \"(distinct ([oid1 , oid2 , oid4 , oid5 , oid6 , oid7]))\"\nfixes \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" :: \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\nfixes \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1\" :: \"\\<cdot>Person\"\nassumes X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1_def: \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1 = (\\<lambda>_. \\<lfloor>\\<lfloor>X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\\<rfloor>\\<rfloor>)\"\nfixes \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" :: \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\nfixes \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2\" :: \"\\<cdot>Person\"\nassumes X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2_def: \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2 = (\\<lambda>_. \\<lfloor>\\<lfloor>X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\\<rfloor>\\<rfloor>)\"\nfixes \"\\<sigma>\\<^sub>1_object0\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" :: \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\nfixes \"\\<sigma>\\<^sub>1_object0\" :: \"\\<cdot>Person\"\nassumes \\<sigma>\\<^sub>1_object0_def: \"\\<sigma>\\<^sub>1_object0 = (\\<lambda>_. \\<lfloor>\\<lfloor>\\<sigma>\\<^sub>1_object0\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\\<rfloor>\\<rfloor>)\"\nfixes \"\\<sigma>\\<^sub>1_object1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" :: \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\nfixes \"\\<sigma>\\<^sub>1_object1\" :: \"\\<cdot>Person\"\nassumes \\<sigma>\\<^sub>1_object1_def: \"\\<sigma>\\<^sub>1_object1 = (\\<lambda>_. \\<lfloor>\\<lfloor>\\<sigma>\\<^sub>1_object1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\\<rfloor>\\<rfloor>)\"\nfixes \"\\<sigma>\\<^sub>1_object2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" :: \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\nfixes \"\\<sigma>\\<^sub>1_object2\" :: \"\\<cdot>Person\"\nassumes \\<sigma>\\<^sub>1_object2_def: \"\\<sigma>\\<^sub>1_object2 = (\\<lambda>_. \\<lfloor>\\<lfloor>\\<sigma>\\<^sub>1_object2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\\<rfloor>\\<rfloor>)\"\nfixes \"\\<sigma>\\<^sub>1_object4\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" :: \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\nfixes \"\\<sigma>\\<^sub>1_object4\" :: \"\\<cdot>Person\"\nassumes \\<sigma>\\<^sub>1_object4_def: \"\\<sigma>\\<^sub>1_object4 = (\\<lambda>_. \\<lfloor>\\<lfloor>\\<sigma>\\<^sub>1_object4\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\\<rfloor>\\<rfloor>)\"\nbegin\ndefinition \"\\<sigma>\\<^sub>1 = (state.make ((Map.empty (oid4 \\<mapsto> (in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n (\\<sigma>\\<^sub>1_object0\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n))) (oid5 \\<mapsto> (in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n (\\<sigma>\\<^sub>1_object1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n))) (oid6 \\<mapsto> (in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n (\\<sigma>\\<^sub>1_object2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n))) (oid1 \\<mapsto> (in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n))) (oid7 \\<mapsto> (in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n (\\<sigma>\\<^sub>1_object4\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n))) (oid2 \\<mapsto> (in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n))))) ((map_of_list ([(oid\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n_0___boss , (List.map ((\\<lambda>(x , y). [x , y]) o switch\\<^sub>2_01) ([[[oid4] , [oid5]] , [[oid6] , [oid1]] , [[oid1] , [oid2]] , [[oid7] , [oid6]]])))]))))\"\n\nlemma perm_\\<sigma>\\<^sub>1 : \"\\<sigma>\\<^sub>1 = (state.make ((Map.empty (oid2 \\<mapsto> (in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n))) (oid7 \\<mapsto> (in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n (\\<sigma>\\<^sub>1_object4\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n))) (oid1 \\<mapsto> (in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n))) (oid6 \\<mapsto> (in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n (\\<sigma>\\<^sub>1_object2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n))) (oid5 \\<mapsto> (in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n (\\<sigma>\\<^sub>1_object1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n))) (oid4 \\<mapsto> (in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n (\\<sigma>\\<^sub>1_object0\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n))))) ((assocs (\\<sigma>\\<^sub>1))))\"\n  apply(simp add: \\<sigma>\\<^sub>1_def)\n  apply(subst (1) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\n  apply(subst (2) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\n  apply(subst (1) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\n  apply(subst (3) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\n  apply(subst (2) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\n  apply(subst (1) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\n  apply(subst (4) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\n  apply(subst (3) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\n  apply(subst (2) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\n  apply(subst (1) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\n  apply(subst (5) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\n  apply(subst (4) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\n  apply(subst (3) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\n  apply(subst (2) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\n  apply(subst (1) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\nby(simp)\nend\n\n(* 24 ************************************ 43 + 1 *)\nsection \\<open>Instance\\<close>\n\n(* 25 ************************************ 44 + 2 *)\ndefinition \"oid8 = 8\"\ndefinition \"inst_assoc8 = (\\<lambda>oid_class to_from oid. ((case (deref_assocs_list ((to_from::oid list list \\<Rightarrow> oid list \\<times> oid list)) ((oid::oid)) ((the ((((map_of_list ([]))) ((oid_class::oid))))))) of Nil \\<Rightarrow> None\n    | l \\<Rightarrow> (Some (l)))::oid list option))\"\n\n(* 26 ************************************ 46 + 0 *)\n\n(* 27 ************************************ 46 + 1 *)\nsection \\<open>State (Floor 2)\\<close>\n\n(* 28 ************************************ 47 + 1 *)\nlocale state_\\<sigma>\\<^sub>1' =\nfixes \"oid1\" :: \"nat\"\nfixes \"oid2\" :: \"nat\"\nfixes \"oid3\" :: \"nat\"\nfixes \"oid8\" :: \"nat\"\nassumes distinct_oid: \"(distinct ([oid1 , oid2 , oid3 , oid8]))\"\nfixes \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" :: \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\nfixes \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1\" :: \"\\<cdot>Person\"\nassumes X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1_def: \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1 = (\\<lambda>_. \\<lfloor>\\<lfloor>X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\\<rfloor>\\<rfloor>)\"\nfixes \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" :: \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\nfixes \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2\" :: \"\\<cdot>Person\"\nassumes X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2_def: \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2 = (\\<lambda>_. \\<lfloor>\\<lfloor>X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\\<rfloor>\\<rfloor>)\"\nfixes \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n3\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" :: \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\nfixes \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n3\" :: \"\\<cdot>Person\"\nassumes X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n3_def: \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n3 = (\\<lambda>_. \\<lfloor>\\<lfloor>X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n3\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\\<rfloor>\\<rfloor>)\"\nfixes \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n4\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" :: \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\nfixes \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n4\" :: \"\\<cdot>Person\"\nassumes X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n4_def: \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n4 = (\\<lambda>_. \\<lfloor>\\<lfloor>X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n4\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\\<rfloor>\\<rfloor>)\"\nbegin\ndefinition \"\\<sigma>\\<^sub>1' = (state.make ((Map.empty (oid1 \\<mapsto> (in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n))) (oid2 \\<mapsto> (in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n))) (oid3 \\<mapsto> (in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n3\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n))) (oid8 \\<mapsto> (in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n4\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n))))) ((map_of_list ([(oid\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n_0___boss , (List.map ((\\<lambda>(x , y). [x , y]) o switch\\<^sub>2_01) ([[[oid1] , [oid2]]])))]))))\"\n\nlemma perm_\\<sigma>\\<^sub>1' : \"\\<sigma>\\<^sub>1' = (state.make ((Map.empty (oid8 \\<mapsto> (in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n4\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n))) (oid3 \\<mapsto> (in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n3\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n))) (oid2 \\<mapsto> (in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n))) (oid1 \\<mapsto> (in\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n))))) ((assocs (\\<sigma>\\<^sub>1'))))\"\n  apply(simp add: \\<sigma>\\<^sub>1'_def)\n  apply(subst (1) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\n  apply(subst (2) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\n  apply(subst (1) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\n  apply(subst (3) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\n  apply(subst (2) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\n  apply(subst (1) fun_upd_twist, metis distinct_oid distinct_length_2_or_more)\nby(simp)\nend\n\n(* 29 ************************************ 48 + 1 *)\nsection \\<open>Transition (Floor 2)\\<close>\n\n(* 30 ************************************ 49 + 1 *)\nlocale transition_\\<sigma>\\<^sub>1_\\<sigma>\\<^sub>1' =\nfixes \"oid1\" :: \"nat\"\nfixes \"oid2\" :: \"nat\"\nfixes \"oid3\" :: \"nat\"\nfixes \"oid4\" :: \"nat\"\nfixes \"oid5\" :: \"nat\"\nfixes \"oid6\" :: \"nat\"\nfixes \"oid7\" :: \"nat\"\nfixes \"oid8\" :: \"nat\"\nassumes distinct_oid: \"(distinct ([oid1 , oid2 , oid3 , oid4 , oid5 , oid6 , oid7 , oid8]))\"\nfixes \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" :: \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\nfixes \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1\" :: \"\\<cdot>Person\"\nassumes X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1_def: \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1 = (\\<lambda>_. \\<lfloor>\\<lfloor>X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\\<rfloor>\\<rfloor>)\"\nfixes \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" :: \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\nfixes \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2\" :: \"\\<cdot>Person\"\nassumes X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2_def: \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2 = (\\<lambda>_. \\<lfloor>\\<lfloor>X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\\<rfloor>\\<rfloor>)\"\nfixes \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n3\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" :: \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\nfixes \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n3\" :: \"\\<cdot>Person\"\nassumes X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n3_def: \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n3 = (\\<lambda>_. \\<lfloor>\\<lfloor>X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n3\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\\<rfloor>\\<rfloor>)\"\nfixes \"\\<sigma>\\<^sub>1_object0\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" :: \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\nfixes \"\\<sigma>\\<^sub>1_object0\" :: \"\\<cdot>Person\"\nassumes \\<sigma>\\<^sub>1_object0_def: \"\\<sigma>\\<^sub>1_object0 = (\\<lambda>_. \\<lfloor>\\<lfloor>\\<sigma>\\<^sub>1_object0\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\\<rfloor>\\<rfloor>)\"\nfixes \"\\<sigma>\\<^sub>1_object1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" :: \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\nfixes \"\\<sigma>\\<^sub>1_object1\" :: \"\\<cdot>Person\"\nassumes \\<sigma>\\<^sub>1_object1_def: \"\\<sigma>\\<^sub>1_object1 = (\\<lambda>_. \\<lfloor>\\<lfloor>\\<sigma>\\<^sub>1_object1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\\<rfloor>\\<rfloor>)\"\nfixes \"\\<sigma>\\<^sub>1_object2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" :: \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\nfixes \"\\<sigma>\\<^sub>1_object2\" :: \"\\<cdot>Person\"\nassumes \\<sigma>\\<^sub>1_object2_def: \"\\<sigma>\\<^sub>1_object2 = (\\<lambda>_. \\<lfloor>\\<lfloor>\\<sigma>\\<^sub>1_object2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\\<rfloor>\\<rfloor>)\"\nfixes \"\\<sigma>\\<^sub>1_object4\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" :: \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\nfixes \"\\<sigma>\\<^sub>1_object4\" :: \"\\<cdot>Person\"\nassumes \\<sigma>\\<^sub>1_object4_def: \"\\<sigma>\\<^sub>1_object4 = (\\<lambda>_. \\<lfloor>\\<lfloor>\\<sigma>\\<^sub>1_object4\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\\<rfloor>\\<rfloor>)\"\nfixes \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n4\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" :: \"ty\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\"\nfixes \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n4\" :: \"\\<cdot>Person\"\nassumes X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n4_def: \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n4 = (\\<lambda>_. \\<lfloor>\\<lfloor>X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n4\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\\<rfloor>\\<rfloor>)\"\n\nassumes \\<sigma>\\<^sub>1: \"(state_\\<sigma>\\<^sub>1 (oid1) (oid2) (oid4) (oid5) (oid6) (oid7) (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n) (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1) (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n) (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2) (\\<sigma>\\<^sub>1_object0\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n) (\\<sigma>\\<^sub>1_object0) (\\<sigma>\\<^sub>1_object1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n) (\\<sigma>\\<^sub>1_object1) (\\<sigma>\\<^sub>1_object2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n) (\\<sigma>\\<^sub>1_object2) (\\<sigma>\\<^sub>1_object4\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n) (\\<sigma>\\<^sub>1_object4))\"\n\nassumes \\<sigma>\\<^sub>1': \"(state_\\<sigma>\\<^sub>1' (oid1) (oid2) (oid3) (oid8) (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n) (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1) (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n) (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2) (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n3\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n) (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n3) (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n4\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n) (X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n4))\"\nbegin\ninterpretation state_\\<sigma>\\<^sub>1: state_\\<sigma>\\<^sub>1 \"oid1\" \"oid2\" \"oid4\" \"oid5\" \"oid6\" \"oid7\" \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1\" \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2\" \"\\<sigma>\\<^sub>1_object0\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" \"\\<sigma>\\<^sub>1_object0\" \"\\<sigma>\\<^sub>1_object1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" \"\\<sigma>\\<^sub>1_object1\" \"\\<sigma>\\<^sub>1_object2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" \"\\<sigma>\\<^sub>1_object2\" \"\\<sigma>\\<^sub>1_object4\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" \"\\<sigma>\\<^sub>1_object4\"\nby(rule \\<sigma>\\<^sub>1)\n\ninterpretation state_\\<sigma>\\<^sub>1': state_\\<sigma>\\<^sub>1' \"oid1\" \"oid2\" \"oid3\" \"oid8\" \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n1\" \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n2\" \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n3\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n3\" \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n4\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n\" \"X\\<^sub>P\\<^sub>e\\<^sub>r\\<^sub>s\\<^sub>o\\<^sub>n4\"\nby(rule \\<sigma>\\<^sub>1')\nend\n\nend\n", "meta": {"author": "object-logics", "repo": "citadelle-devel", "sha": "fd4d57977d1a8a7330ae7d8651d003789980c802", "save_path": "github-repos/isabelle/object-logics-citadelle-devel", "path": "github-repos/isabelle/object-logics-citadelle-devel/citadelle-devel-fd4d57977d1a8a7330ae7d8651d003789980c802/src/compiler_generic/toy_example/document_generated/Design_generated_generated.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631698328916, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.2683884186517871}}
{"text": "(*  Title:      HOL/HOLCF/IOA/NTP/Impl.thy\n    Author:     Tobias Nipkow & Konrad Slind\n*)\n\nsection \\<open>The implementation\\<close>\n\ntheory Impl\nimports Sender Receiver Abschannel\nbegin\n\ntype_synonym 'm impl_state\n  = \"'m sender_state * 'm receiver_state * 'm packet multiset * bool multiset\"\n  (*  sender_state   *  receiver_state   *    srch_state      * rsch_state *)\n\n\ndefinition\n  impl_ioa :: \"('m action, 'm impl_state)ioa\" where\n  impl_def: \"impl_ioa == (sender_ioa \\<parallel> receiver_ioa \\<parallel> srch_ioa \\<parallel> rsch_ioa)\"\n\ndefinition sen :: \"'m impl_state => 'm sender_state\" where \"sen = fst\"\ndefinition rec :: \"'m impl_state => 'm receiver_state\" where \"rec = fst \\<circ> snd\"\ndefinition srch :: \"'m impl_state => 'm packet multiset\" where \"srch = fst \\<circ> snd \\<circ> snd\"\ndefinition rsch :: \"'m impl_state => bool multiset\" where \"rsch = snd \\<circ> snd \\<circ> snd\"\n\ndefinition\n  hdr_sum :: \"'m packet multiset => bool => nat\" where\n  \"hdr_sum M b == countm M (%pkt. hdr(pkt) = b)\"\n\n(* Lemma 5.1 *)\ndefinition\n  \"inv1(s) ==\n     (!b. count (rsent(rec s)) b = count (srcvd(sen s)) b + count (rsch s) b)\n   & (!b. count (ssent(sen s)) b\n          = hdr_sum (rrcvd(rec s)) b + hdr_sum (srch s) b)\"\n\n(* Lemma 5.2 *)\ndefinition\n  \"inv2(s) ==\n  (rbit(rec(s)) = sbit(sen(s)) &\n   ssending(sen(s)) &\n   count (rsent(rec s)) (~sbit(sen s)) <= count (ssent(sen s)) (~sbit(sen s)) &\n   count (ssent(sen s)) (~sbit(sen s)) <= count (rsent(rec s)) (sbit(sen s)))\n   |\n  (rbit(rec(s)) = (~sbit(sen(s))) &\n   rsending(rec(s)) &\n   count (ssent(sen s)) (~sbit(sen s)) <= count (rsent(rec s)) (sbit(sen s)) &\n   count (rsent(rec s)) (sbit(sen s)) <= count (ssent(sen s)) (sbit(sen s)))\"\n\n(* Lemma 5.3 *)\ndefinition\n  \"inv3(s) ==\n   rbit(rec(s)) = sbit(sen(s))\n   --> (!m. sq(sen(s))=[] | m ~= hd(sq(sen(s)))\n        -->  count (rrcvd(rec s)) (sbit(sen(s)),m)\n             + count (srch s) (sbit(sen(s)),m)\n            <= count (rsent(rec s)) (~sbit(sen s)))\"\n\n(* Lemma 5.4 *)\ndefinition \"inv4(s) == rbit(rec(s)) = (~sbit(sen(s))) --> sq(sen(s)) ~= []\"\n\n\nsubsection \\<open>Invariants\\<close>\n\ndeclare le_SucI [simp]\n\nlemmas impl_ioas =\n  impl_def sender_ioa_def receiver_ioa_def srch_ioa_thm [THEN eq_reflection]\n  rsch_ioa_thm [THEN eq_reflection]\n\nlemmas \"transitions\" =\n  sender_trans_def receiver_trans_def srch_trans_def rsch_trans_def\n\n\nlemmas [simp] =\n  ioa_triple_proj starts_of_par trans_of_par4 in_sender_asig\n  in_receiver_asig in_srch_asig in_rsch_asig\n\ndeclare let_weak_cong [cong]\n\n\n\nlemma [simp]:\n  \"a:actions(sender_asig)\n  | a:actions(receiver_asig)\n  | a:actions(srch_asig)\n  | a:actions(rsch_asig)\"\n  by (induct a) simp_all\n\ndeclare split_paired_All [simp del]\n\n\n(* Three Simp_sets in different sizes\n----------------------------------------------\n\n1) simpset() does not unfold the transition relations\n2) ss unfolds transition relations\n3) renname_ss unfolds transitions and the abstract channel *)\n\nML \\<open>\nval ss = simpset_of (@{context} addsimps @{thms \"transitions\"});\nval rename_ss = simpset_of (put_simpset ss @{context} addsimps @{thms unfold_renaming});\n\nfun tac ctxt =\n  asm_simp_tac (put_simpset ss ctxt\n    |> Simplifier.add_cong @{thm conj_cong} |> Splitter.add_split @{thm if_split})\nfun tac_ren ctxt =\n  asm_simp_tac (put_simpset rename_ss ctxt\n    |> Simplifier.add_cong @{thm conj_cong} |> Splitter.add_split @{thm if_split})\n\\<close>\n\n\nsubsubsection \\<open>Invariant 1\\<close>\n\nlemma raw_inv1: \"invariant impl_ioa inv1\"\n\napply (unfold impl_ioas)\napply (rule invariantI)\napply (simp add: inv1_def hdr_sum_def srcvd_def ssent_def rsent_def rrcvd_def)\n\napply (simp (no_asm) del: trans_of_par4 add: imp_conjR inv1_def)\n\ntxt \\<open>Split proof in two\\<close>\napply (rule conjI)\n\n(* First half *)\napply (simp add: Impl.inv1_def split del: if_split)\napply (induct_tac a)\n\napply (tactic \"EVERY1[tac @{context}, tac @{context}, tac @{context}, tac @{context}]\")\napply (tactic \"tac @{context} 1\")\napply (tactic \"tac_ren @{context} 1\")\n\ntxt \\<open>5 + 1\\<close>\n\napply (tactic \"tac @{context} 1\")\napply (tactic \"tac_ren @{context} 1\")\n\ntxt \\<open>4 + 1\\<close>\napply (tactic \\<open>EVERY1[tac @{context}, tac @{context}, tac @{context}, tac @{context}]\\<close>)\n\n\ntxt \\<open>Now the other half\\<close>\napply (simp add: Impl.inv1_def split del: if_split)\napply (induct_tac a)\napply (tactic \"EVERY1 [tac @{context}, tac @{context}]\")\n\ntxt \\<open>detour 1\\<close>\napply (tactic \"tac @{context} 1\")\napply (tactic \"tac_ren @{context} 1\")\napply (rule impI)\napply (erule conjE)+\napply (simp (no_asm_simp) add: hdr_sum_def Multiset.count_def Multiset.countm_nonempty_def\n  split: if_split)\ntxt \\<open>detour 2\\<close>\napply (tactic \"tac @{context} 1\")\napply (tactic \"tac_ren @{context} 1\")\napply (rule impI)\napply (erule conjE)+\napply (simp add: Impl.hdr_sum_def Multiset.count_def Multiset.countm_nonempty_def\n  Multiset.delm_nonempty_def split: if_split)\napply (rule allI)\napply (rule conjI)\napply (rule impI)\napply hypsubst\napply (rule pred_suc [THEN iffD1])\napply (drule less_le_trans)\napply (cut_tac eq_packet_imp_eq_hdr [unfolded Packet.hdr_def, THEN countm_props])\napply assumption\napply assumption\n\napply (rule countm_done_delm [THEN mp, symmetric])\napply (rule refl)\napply (simp (no_asm_simp) add: Multiset.count_def)\n\napply (rule impI)\napply (simp add: neg_flip)\napply hypsubst\napply (rule countm_spurious_delm)\napply (simp (no_asm))\n\napply (tactic \"EVERY1 [tac @{context}, tac @{context}, tac @{context},\n  tac @{context}, tac @{context}, tac @{context}]\")\n\ndone\n\n\n\nsubsubsection \\<open>INVARIANT 2\\<close>\n\nlemma raw_inv2: \"invariant impl_ioa inv2\"\n\n  apply (rule invariantI1)\n  txt \\<open>Base case\\<close>\n  apply (simp add: inv2_def receiver_projections sender_projections impl_ioas)\n\n  apply (simp (no_asm_simp) add: impl_ioas split del: if_split)\n  apply (induct_tac \"a\")\n\n  txt \\<open>10 cases. First 4 are simple, since state doesn't change\\<close>\n\n  ML_prf \\<open>val tac2 = asm_full_simp_tac (put_simpset ss @{context} addsimps [@{thm inv2_def}])\\<close>\n\n  txt \\<open>10 - 7\\<close>\n  apply (tactic \"EVERY1 [tac2,tac2,tac2,tac2]\")\n  txt \\<open>6\\<close>\n  apply (tactic \\<open>forward_tac @{context} [rewrite_rule @{context} [@{thm Impl.inv1_def}]\n                               (@{thm raw_inv1} RS @{thm invariantE}) RS conjunct1] 1\\<close>)\n\n  txt \\<open>6 - 5\\<close>\n  apply (tactic \"EVERY1 [tac2,tac2]\")\n\n  txt \\<open>4\\<close>\n  apply (tactic \\<open>forward_tac @{context} [rewrite_rule @{context} [@{thm Impl.inv1_def}]\n                                (@{thm raw_inv1} RS @{thm invariantE}) RS conjunct1] 1\\<close>)\n  apply (tactic \"tac2 1\")\n\n  txt \\<open>3\\<close>\n  apply (tactic \\<open>forward_tac @{context} [rewrite_rule @{context} [@{thm Impl.inv1_def}]\n    (@{thm raw_inv1} RS @{thm invariantE})] 1\\<close>)\n\n  apply (tactic \"tac2 1\")\n  apply (tactic \\<open>fold_goals_tac @{context} [rewrite_rule @{context} [@{thm Packet.hdr_def}]\n    (@{thm Impl.hdr_sum_def})]\\<close>)\n  apply arith\n\n  txt \\<open>2\\<close>\n  apply (tactic \"tac2 1\")\n  apply (tactic \\<open>forward_tac @{context} [rewrite_rule @{context} [@{thm Impl.inv1_def}]\n                               (@{thm raw_inv1} RS @{thm invariantE}) RS conjunct1] 1\\<close>)\n  apply (intro strip)\n  apply (erule conjE)+\n  apply simp\n\n  txt \\<open>1\\<close>\n  apply (tactic \"tac2 1\")\n  apply (tactic \\<open>forward_tac @{context} [rewrite_rule @{context} [@{thm Impl.inv1_def}]\n                               (@{thm raw_inv1} RS @{thm invariantE}) RS conjunct2] 1\\<close>)\n  apply (intro strip)\n  apply (erule conjE)+\n  apply (tactic \\<open>fold_goals_tac @{context}\n    [rewrite_rule @{context} [@{thm Packet.hdr_def}] (@{thm Impl.hdr_sum_def})]\\<close>)\n  apply simp\n\n  done\n\n\nsubsubsection \\<open>INVARIANT 3\\<close>\n\nlemma raw_inv3: \"invariant impl_ioa inv3\"\n\n  apply (rule invariantI)\n  txt \\<open>Base case\\<close>\n  apply (simp add: Impl.inv3_def receiver_projections sender_projections impl_ioas)\n\n  apply (simp (no_asm_simp) add: impl_ioas split del: if_split)\n  apply (induct_tac \"a\")\n\n  ML_prf \\<open>val tac3 = asm_full_simp_tac (put_simpset ss @{context} addsimps [@{thm inv3_def}])\\<close>\n\n  txt \\<open>10 - 8\\<close>\n\n  apply (tactic \"EVERY1[tac3,tac3,tac3]\")\n\n  apply (tactic \"tac_ren @{context} 1\")\n  apply (intro strip, (erule conjE)+)\n  apply hypsubst\n  apply (erule exE)\n  apply simp\n\n  txt \\<open>7\\<close>\n  apply (tactic \"tac3 1\")\n  apply (tactic \"tac_ren @{context} 1\")\n  apply force\n\n  txt \\<open>6 - 3\\<close>\n\n  apply (tactic \"EVERY1[tac3,tac3,tac3,tac3]\")\n\n  txt \\<open>2\\<close>\n  apply (tactic \"asm_full_simp_tac (put_simpset ss @{context}) 1\")\n  apply (simp (no_asm) add: inv3_def)\n  apply (intro strip, (erule conjE)+)\n  apply (rule imp_disjL [THEN iffD1])\n  apply (rule impI)\n  apply (tactic \\<open>forward_tac @{context} [rewrite_rule @{context} [@{thm Impl.inv2_def}]\n    (@{thm raw_inv2} RS @{thm invariantE})] 1\\<close>)\n  apply simp\n  apply (erule conjE)+\n  apply (rule_tac j = \"count (ssent (sen s)) (~sbit (sen s))\" and\n    k = \"count (rsent (rec s)) (sbit (sen s))\" in le_trans)\n  apply (tactic \\<open>forward_tac @{context} [rewrite_rule @{context} [@{thm inv1_def}]\n                                (@{thm raw_inv1} RS @{thm invariantE}) RS conjunct2] 1\\<close>)\n  apply (simp add: hdr_sum_def Multiset.count_def)\n  apply (rule add_le_mono)\n  apply (rule countm_props)\n  apply (simp (no_asm))\n  apply (rule countm_props)\n  apply (simp (no_asm))\n  apply assumption\n\n  txt \\<open>1\\<close>\n  apply (tactic \"tac3 1\")\n  apply (intro strip, (erule conjE)+)\n  apply (rule imp_disjL [THEN iffD1])\n  apply (rule impI)\n  apply (tactic \\<open>forward_tac @{context} [rewrite_rule @{context} [@{thm Impl.inv2_def}]\n    (@{thm raw_inv2} RS @{thm invariantE})] 1\\<close>)\n  apply simp\n  done\n\n\nsubsubsection \\<open>INVARIANT 4\\<close>\n\nlemma raw_inv4: \"invariant impl_ioa inv4\"\n\n  apply (rule invariantI)\n  txt \\<open>Base case\\<close>\n  apply (simp add: Impl.inv4_def receiver_projections sender_projections impl_ioas)\n\n  apply (simp (no_asm_simp) add: impl_ioas split del: if_split)\n  apply (induct_tac \"a\")\n\n  ML_prf \\<open>val tac4 =  asm_full_simp_tac (put_simpset ss @{context} addsimps [@{thm inv4_def}])\\<close>\n\n  txt \\<open>10 - 2\\<close>\n\n  apply (tactic \"EVERY1[tac4,tac4,tac4,tac4,tac4,tac4,tac4,tac4,tac4]\")\n\n  txt \\<open>2 b\\<close>\n\n  apply (intro strip, (erule conjE)+)\n  apply (tactic \\<open>forward_tac @{context} [rewrite_rule @{context} [@{thm Impl.inv2_def}]\n                               (@{thm raw_inv2} RS @{thm invariantE})] 1\\<close>)\n  apply simp\n\n  txt \\<open>1\\<close>\n  apply (tactic \"tac4 1\")\n  apply (intro strip, (erule conjE)+)\n  apply (rule ccontr)\n  apply (tactic \\<open>forward_tac @{context} [rewrite_rule @{context} [@{thm Impl.inv2_def}]\n                               (@{thm raw_inv2} RS @{thm invariantE})] 1\\<close>)\n  apply (tactic \\<open>forward_tac @{context} [rewrite_rule @{context} [@{thm Impl.inv3_def}]\n                               (@{thm raw_inv3} RS @{thm invariantE})] 1\\<close>)\n  apply simp\n  apply (rename_tac m, erule_tac x = \"m\" in allE)\n  apply simp\n  done\n\n\ntext \\<open>rebind them\\<close>\n\nlemmas inv1 = raw_inv1 [THEN invariantE, unfolded inv1_def]\n  and inv2 = raw_inv2 [THEN invariantE, unfolded inv2_def]\n  and inv3 = raw_inv3 [THEN invariantE, unfolded inv3_def]\n  and inv4 = raw_inv4 [THEN invariantE, unfolded inv4_def]\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/HOL/HOLCF/IOA/NTP/Impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5583269943353745, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.26826421615672197}}
{"text": "(* Title: While_SPMF.thy\n   Author: Andreas Lochbihler, ETH Zurich *)\n\ntheory While_SPMF imports\n  MFMC_Countable.Rel_PMF_Characterisation\n  \"HOL-Types_To_Sets.Types_To_Sets\"\n  \"HOL-Library.Complete_Partial_Order2\"\nbegin\n\ntext \\<open>\n  This theory defines a probabilistic while combinator for discrete (sub-)probabilities and\n  formalises rules for probabilistic termination similar to those by Hurd \\cite{Hurd2002TPHOLs}\n  and McIver and Morgan \\cite{McIverMorgan2005}.\n\\<close>\n\nsection \\<open>Miscellaneous library additions\\<close>\n\nfun map_option_set :: \"('a \\<Rightarrow> 'b option set) \\<Rightarrow> 'a option \\<Rightarrow> 'b option set\"\nwhere\n  \"map_option_set f None = {None}\"\n| \"map_option_set f (Some x) = f x\"\n\nlemma None_in_map_option_set:\n  \"None \\<in> map_option_set f x \\<longleftrightarrow> None \\<in> Set.bind (set_option x) f \\<or> x = None\"\nby(cases x) simp_all\n\nlemma None_in_map_option_set_None [intro!]: \"None \\<in> map_option_set f None\"\nby simp\n\nlemma None_in_map_option_set_Some [intro!]: \"None \\<in> f x \\<Longrightarrow> None \\<in> map_option_set f (Some x)\"\nby simp\n\nlemma Some_in_map_option_set [intro!]: \"Some y \\<in> f x \\<Longrightarrow> Some y \\<in> map_option_set f (Some x)\"\nby simp\n\nlemma map_option_set_singleton [simp]: \"map_option_set (\\<lambda>x. {f x}) y = {Option.bind y f}\"\nby(cases y) simp_all\n\nlemma Some_eq_bind_conv: \"Some y = Option.bind x f \\<longleftrightarrow> (\\<exists>z. x = Some z \\<and> f z = Some y)\"\nby(cases x) auto\n\nlemma map_option_set_bind: \"map_option_set f (Option.bind x g) = map_option_set (map_option_set f \\<circ> g) x\"\nby(cases x) simp_all\n\nlemma Some_in_map_option_set_conv: \"Some y \\<in> map_option_set f x \\<longleftrightarrow> (\\<exists>z. x = Some z \\<and> Some y \\<in> f z)\"\nby(cases x) auto\n\n\ninterpretation rel_spmf_characterisation by unfold_locales(rule rel_pmf_measureI)\nhide_fact (open) rel_pmf_measureI\n\nlemma Sup_conv_fun_lub: \"Sup = fun_lub Sup\"\n  by(auto simp add: Sup_fun_def fun_eq_iff fun_lub_def intro: arg_cong[where f=Sup])\n\nlemma le_conv_fun_ord: \"(\\<le>) = fun_ord (\\<le>)\"\n  by(auto simp add: fun_eq_iff fun_ord_def le_fun_def)\n\nlemmas parallel_fixp_induct_2_1 = parallel_fixp_induct_uc[\n  of _ _ _ _ \"case_prod\" _ \"curry\" \"\\<lambda>x. x\" _ \"\\<lambda>x. x\",\n  where P=\"\\<lambda>f g. P (curry f) g\",\n  unfolded case_prod_curry curry_case_prod curry_K,\n  OF _ _ _ _ _ _ refl refl]\n  for P\n\nlemma monotone_Pair:\n  \"\\<lbrakk> monotone ord orda f; monotone ord ordb g \\<rbrakk>\n  \\<Longrightarrow> monotone ord (rel_prod orda ordb) (\\<lambda>x. (f x, g x))\"\nby(simp add: monotone_def)\n\nlemma cont_Pair:\n  \"\\<lbrakk> cont lub ord luba orda f; cont lub ord lubb ordb g \\<rbrakk>\n  \\<Longrightarrow> cont lub ord (prod_lub luba lubb) (rel_prod orda ordb) (\\<lambda>x. (f x, g x))\"\nby(rule contI)(auto simp add: prod_lub_def image_image dest!: contD)\n\nlemma mcont_Pair:\n  \"\\<lbrakk> mcont lub ord luba orda f; mcont lub ord lubb ordb g \\<rbrakk>\n  \\<Longrightarrow> mcont lub ord (prod_lub luba lubb) (rel_prod orda ordb) (\\<lambda>x. (f x, g x))\"\nby(rule mcontI)(simp_all add: monotone_Pair mcont_mono cont_Pair)\n\nlemma mono2mono_emeasure_spmf [THEN lfp.mono2mono]:\n  shows monotone_emeasure_spmf:\n  \"monotone (ord_spmf (=)) (\\<le>) (\\<lambda>p. emeasure (measure_spmf p))\"\n  by(rule monotoneI le_funI ord_spmf_eqD_emeasure)+\n\nlemma cont_emeasure_spmf: \"cont lub_spmf (ord_spmf (=)) Sup (\\<le>) (\\<lambda>p. emeasure (measure_spmf p))\"\n  by (rule contI) (simp add: emeasure_lub_spmf fun_eq_iff image_comp)\n\nlemma mcont2mcont_emeasure_spmf [THEN lfp.mcont2mcont, cont_intro]:\n  shows mcont_emeasure_spmf: \"mcont lub_spmf (ord_spmf (=)) Sup (\\<le>) (\\<lambda>p. emeasure (measure_spmf p))\"\n  by(simp add: mcont_def monotone_emeasure_spmf cont_emeasure_spmf)\n\nlemma mcont2mcont_emeasure_spmf' [THEN lfp.mcont2mcont, cont_intro]:\n  shows mcont_emeasure_spmf': \"mcont lub_spmf (ord_spmf (=)) Sup (\\<le>) (\\<lambda>p. emeasure (measure_spmf p) A)\"\n  using mcont_emeasure_spmf[unfolded Sup_conv_fun_lub le_conv_fun_ord]\n  by(subst (asm) mcont_fun_lub_apply) blast\n\nlemma mcont_bind_pmf [cont_intro]:\n  assumes g: \"\\<And>y. mcont luba orda lub_spmf (ord_spmf (=)) (g y)\"\n  shows \"mcont luba orda lub_spmf (ord_spmf (=)) (\\<lambda>x. bind_pmf p (\\<lambda>y. g y x))\"\nusing mcont_bind_spmf[where f=\"\\<lambda>_. spmf_of_pmf p\" and g=g, OF _ assms] by(simp)\n\nlemma ennreal_less_top_iff: \"x < \\<top> \\<longleftrightarrow> x \\<noteq> (\\<top> :: ennreal)\"\n  by(cases x) simp_all\n\nlemma type_definition_Domainp: \n  fixes Rep Abs A T\n  assumes type: \"type_definition Rep Abs A\"\n  assumes T_def: \"T \\<equiv> (\\<lambda>(x::'a) (y::'b). x = Rep y)\"\n  shows \"Domainp T = (\\<lambda>x. x \\<in> A)\"\nproof -\n  interpret type_definition Rep Abs A by(rule type)\n  show ?thesis unfolding Domainp_iff[abs_def] T_def fun_eq_iff by(metis Abs_inverse Rep)\nqed\n\ncontext includes lifting_syntax begin\n\nlemma weight_spmf_parametric [transfer_rule]:\n  \"(rel_spmf A ===> (=)) weight_spmf weight_spmf\"\nby(simp add: rel_fun_def rel_spmf_weightD)\n\nlemma lossless_spmf_parametric [transfer_rule]:\n  \"(rel_spmf A ===> (=)) lossless_spmf lossless_spmf\"\nby(simp add: rel_fun_def lossless_spmf_def rel_spmf_weightD)\n\nlemma UNIV_parametric_pred: \"rel_pred R UNIV UNIV\"\n  by(auto intro!: rel_predI)\nend\n\nlemma bind_spmf_spmf_of_set:\n  \"\\<And>A. \\<lbrakk> finite A; A \\<noteq> {} \\<rbrakk> \\<Longrightarrow> bind_spmf (spmf_of_set A) = bind_pmf (pmf_of_set A)\"\nby(simp add: spmf_of_set_def fun_eq_iff del: spmf_of_pmf_pmf_of_set)\n\nlemma set_pmf_bind_spmf: \"set_pmf (bind_spmf M f) = set_pmf M \\<bind> map_option_set (set_pmf \\<circ> f)\"\nby(auto 4 3 simp add: bind_spmf_def split: option.splits intro: rev_bexI)\n\nlemma set_pmf_spmf_of_set:\n  \"set_pmf (spmf_of_set A) = (if finite A \\<and> A \\<noteq> {} then Some ` A else {None})\"\nby(simp add: spmf_of_set_def spmf_of_pmf_def del: spmf_of_pmf_pmf_of_set)\n\ndefinition measure_measure_spmf :: \"'a spmf \\<Rightarrow> 'a set \\<Rightarrow> real\"\nwhere [simp]: \"measure_measure_spmf p = measure (measure_spmf p)\"\n\nlemma measure_measure_spmf_parametric [transfer_rule]:\n  includes lifting_syntax shows\n  \"(rel_spmf A ===> rel_pred A ===> (=)) measure_measure_spmf measure_measure_spmf\"\nunfolding measure_measure_spmf_def[abs_def] by(rule measure_spmf_parametric)\n\nlemma of_nat_le_one_cancel_iff [simp]:\n  fixes n :: nat shows \"real n \\<le> 1 \\<longleftrightarrow> n \\<le> 1\"\nby linarith\n\nlemma of_int_ceiling_less_add_one [simp]: \"of_int \\<lceil>r\\<rceil> < r + 1\"\n  by linarith\n\nlemma lessThan_subset_Collect: \"{..<x} \\<subseteq> Collect P \\<longleftrightarrow> (\\<forall>y<x. P y)\"\n  by(auto simp add: lessThan_def)\n\nlemma spmf_ub_tight:\n  assumes ub: \"\\<And>x. spmf p x \\<le> f x\"\n  and sum: \"(\\<integral>\\<^sup>+ x. f x \\<partial>count_space UNIV) = weight_spmf p\"\n  shows \"spmf p x = f x\"\nproof -\n  have [rule_format]: \"\\<forall>x. f x \\<le> spmf p x\"\n  proof(rule ccontr)\n    assume \"\\<not> ?thesis\"\n    then obtain x where x: \"spmf p x < f x\" by(auto simp add: not_le)\n    have *: \"(\\<integral>\\<^sup>+ y. ennreal (f y) * indicator (- {x}) y \\<partial>count_space UNIV) \\<noteq> \\<top>\"\n      by(rule neq_top_trans[where y=\"weight_spmf p\"], simp)(auto simp add: sum[symmetric] intro!: nn_integral_mono split: split_indicator)\n      \n    have \"weight_spmf p = \\<integral>\\<^sup>+ y. spmf p y \\<partial>count_space UNIV\"\n      by(simp add: nn_integral_spmf space_measure_spmf measure_spmf.emeasure_eq_measure)\n    also have \"\\<dots> = (\\<integral>\\<^sup>+ y. ennreal (spmf p y) * indicator (- {x}) y \\<partial>count_space UNIV) +\n      (\\<integral>\\<^sup>+ y. spmf p y * indicator {x} y \\<partial>count_space UNIV)\"\n      by(subst nn_integral_add[symmetric])(auto intro!: nn_integral_cong split: split_indicator)\n    also have \"\\<dots> \\<le> (\\<integral>\\<^sup>+ y. ennreal (f y) * indicator (- {x}) y \\<partial>count_space UNIV) + spmf p x\"\n      using ub by(intro add_mono nn_integral_mono)(auto split: split_indicator intro: ennreal_leI)\n    also have \"\\<dots> < (\\<integral>\\<^sup>+ y. ennreal (f y) * indicator (- {x}) y \\<partial>count_space UNIV) + (\\<integral>\\<^sup>+ y. f y * indicator {x} y \\<partial>count_space UNIV)\"\n      using * x by(simp add: ennreal_less_iff)\n    also have \"\\<dots> = (\\<integral>\\<^sup>+ y. ennreal (f y) \\<partial>count_space UNIV)\"\n      by(subst nn_integral_add[symmetric])(auto intro: nn_integral_cong split: split_indicator)\n    also have \"\\<dots> = weight_spmf p\" using sum by simp\n    finally show False by simp\n  qed\n  from this[of x] ub[of x] show ?thesis by simp\nqed\n\nsection \\<open>Probabilistic while loop\\<close>\n\nlocale loop_spmf = \n  fixes guard :: \"'a \\<Rightarrow> bool\"\n  and body :: \"'a \\<Rightarrow> 'a spmf\"\nbegin\n\ncontext notes [[function_internals]] begin\n\npartial_function (spmf) while :: \"'a \\<Rightarrow> 'a spmf\"\nwhere \"while s = (if guard s then bind_spmf (body s) while else return_spmf s)\"\n\nend\n\nlemma while_fixp_induct [case_names adm bottom step]:\n  assumes \"spmf.admissible P\"\n  and \"P (\\<lambda>while. return_pmf None)\"\n  and \"\\<And>while'. P while' \\<Longrightarrow> P (\\<lambda>s. if guard s then body s \\<bind> while' else return_spmf s)\"\n  shows \"P while\"\n  using assms by(rule while.fixp_induct)\n\nlemma while_simps:\n  \"guard s \\<Longrightarrow> while s = bind_spmf (body s) while\"\n  \"\\<not> guard s \\<Longrightarrow> while s = return_spmf s\"\nby(rewrite while.simps; simp; fail)+\n\nend\n\nlemma while_spmf_parametric [transfer_rule]:\n  includes lifting_syntax shows\n  \"((S ===> (=)) ===> (S ===> rel_spmf S) ===> S ===> rel_spmf S) loop_spmf.while loop_spmf.while\"\nunfolding loop_spmf.while_def[abs_def]\napply(rule rel_funI)\napply(rule rel_funI)\napply(rule fixp_spmf_parametric[OF loop_spmf.while.mono loop_spmf.while.mono])\nsubgoal premises [transfer_rule] by transfer_prover\ndone\n\nlemma loop_spmf_while_cong:\n  \"\\<lbrakk> guard = guard'; \\<And>s. guard' s \\<Longrightarrow> body s = body' s \\<rbrakk>\n  \\<Longrightarrow> loop_spmf.while guard body = loop_spmf.while guard' body'\"\nunfolding loop_spmf.while_def[abs_def] by(simp cong: if_cong)\n\nsection \\<open>Rules for probabilistic termination\\<close>\n\ncontext loop_spmf begin\n\nsubsection \\<open>0/1 termination laws\\<close>\n\nlemma termination_0_1_immediate:\n  assumes p: \"\\<And>s. guard s \\<Longrightarrow> spmf (map_spmf guard (body s)) False \\<ge> p\"\n  and p_pos: \"0 < p\"\n  and lossless: \"\\<And>s. guard s \\<Longrightarrow> lossless_spmf (body s)\"\n  shows \"lossless_spmf (while s)\"\nproof -\n  have \"\\<forall>s. lossless_spmf (while s)\"\n  proof(rule ccontr)\n    assume \"\\<not> ?thesis\"\n    then obtain s where s: \"\\<not> lossless_spmf (while s)\" by blast\n    hence True: \"guard s\" by(simp add: while.simps split: if_split_asm)\n\n    from p[OF this] have p_le_1: \"p \\<le> 1\" using pmf_le_1 by(rule order_trans)\n    have new_bound: \"p * (1 - k) + k \\<le> weight_spmf (while s)\" \n      if k: \"0 \\<le> k\" \"k \\<le> 1\" and k_le: \"\\<And>s. k \\<le> weight_spmf (while s)\" for k s\n    proof(cases \"guard s\")\n      case False\n      have \"p * (1 - k) + k \\<le> 1 * (1 - k) + k\" using p_le_1 k by(intro mult_right_mono add_mono; simp)\n      also have \"\\<dots> \\<le> 1\" by simp\n      finally show ?thesis using False by(simp add: while.simps)\n    next\n      case True\n      let ?M = \"\\<lambda>s. measure_spmf (body s)\"\n      have bounded: \"\\<bar>\\<integral> s''. weight_spmf (while s'') \\<partial>?M s'\\<bar> \\<le> 1\" for s'\n        using integral_nonneg_AE[of \"\\<lambda>s''. weight_spmf (while s'')\" \"?M s'\"]\n        by(auto simp add: weight_spmf_nonneg weight_spmf_le_1 intro!: measure_spmf.nn_integral_le_const integral_real_bounded)\n      have \"p \\<le> measure (?M s) {s'. \\<not> guard s'}\" using p[OF True]\n        by(simp add: spmf_conv_measure_spmf measure_map_spmf vimage_def)\n      hence \"p * (1 - k) + k \\<le> measure (?M s) {s'. \\<not> guard s'} * (1 - k) + k\"\n        using k by(intro add_mono mult_right_mono)(simp_all)\n      also have \"\\<dots> = \\<integral> s'. indicator {s'. \\<not> guard s'} s' * (1 - k) +  k \\<partial>?M s\"\n        using True by(simp add: ennreal_less_top_iff lossless lossless_weight_spmfD)\n      also have \"\\<dots> = \\<integral> s'. indicator {s'. \\<not> guard s'} s' + indicator {s'. guard s'} s' * k \\<partial>?M s\"\n        by(rule Bochner_Integration.integral_cong)(simp_all split: split_indicator)\n      also have \"\\<dots> = \\<integral> s'. indicator {s'. \\<not> guard s'} s' + indicator {s'. guard s'} s' * \\<integral> s''. k \\<partial>?M s' \\<partial>?M s\"\n        by(rule Bochner_Integration.integral_cong)(auto simp add: lossless lossless_weight_spmfD split: split_indicator)\n      also have \"\\<dots> \\<le> \\<integral> s'. indicator {s'. \\<not> guard s'} s' + indicator {s'. guard s'} s' * \\<integral> s''. weight_spmf (while s'') \\<partial>?M s' \\<partial>?M s\"\n        using k bounded\n        by(intro integral_mono integrable_add measure_spmf.integrable_const_bound[where B=1] add_mono mult_left_mono)\n          (simp_all add: weight_spmf_nonneg weight_spmf_le_1 mult_le_one k_le split: split_indicator)\n      also have \"\\<dots> = \\<integral>s'. (if \\<not> guard s' then 1 else \\<integral> s''. weight_spmf (while s'') \\<partial>?M s') \\<partial>?M s\"\n        by(rule Bochner_Integration.integral_cong)(simp_all split: split_indicator)\n      also have \"\\<dots> = \\<integral> s'. weight_spmf (while s') \\<partial>measure_spmf (body s)\"\n        by(rule Bochner_Integration.integral_cong; simp add: while.simps weight_bind_spmf o_def)\n      also have \"\\<dots> = weight_spmf (while s)\" using True\n        by(simp add: while.simps weight_bind_spmf o_def)\n      finally show ?thesis .\n    qed\n\n    define k where \"k \\<equiv> INF s. weight_spmf (while s)\"\n    define k' where \"k' \\<equiv> p * (1 - k) + k\"\n    from s have \"weight_spmf (while s) < 1\"\n      using weight_spmf_le_1[of \"while s\"] by(simp add: lossless_spmf_def)\n    then have \"k < 1\"\n      unfolding k_def by(rewrite cINF_less_iff)(auto intro!: bdd_belowI2 weight_spmf_nonneg)\n\n    have \"0 \\<le> k\" unfolding k_def by(auto intro: cINF_greatest simp add: weight_spmf_nonneg)\n    moreover from \\<open>k < 1\\<close> have \"k \\<le> 1\" by simp\n    moreover have \"k \\<le> weight_spmf (while s)\" for s unfolding k_def\n      by(rule cINF_lower)(auto intro!: bdd_belowI2 weight_spmf_nonneg)\n    ultimately have \"\\<And>s. k' \\<le> weight_spmf (while s)\"\n      unfolding k'_def by(rule new_bound)\n    hence \"k' \\<le> k\" unfolding k_def by(auto intro: cINF_greatest)\n    also have \"k < k'\" using p_pos \\<open>k < 1\\<close> by(auto simp add: k'_def)\n    finally show False by simp\n  qed\n  thus ?thesis by blast\nqed\n\nprimrec iter :: \"nat \\<Rightarrow> 'a \\<Rightarrow> 'a spmf\"\nwhere\n  \"iter 0 s = return_spmf s\"\n| \"iter (Suc n) s = (if guard s then bind_spmf (body s) (iter n) else return_spmf s)\"\n\nlemma iter_unguarded [simp]: \"\\<not> guard s \\<Longrightarrow> iter n s = return_spmf s\"\n  by(induction n) simp_all\n  \nlemma iter_bind_iter: \"bind_spmf (iter m s) (iter n) = iter (m + n) s\"\n  by(induction m arbitrary: s) simp_all\n\nlemma iter_Suc2: \"iter (Suc n) s = bind_spmf (iter n s) (\\<lambda>s. if guard s then body s else return_spmf s)\"\n  using iter_bind_iter[of n s 1, symmetric]\n  by(simp del: iter.simps)(rule bind_spmf_cong; simp cong: bind_spmf_cong)\n\nlemma lossless_iter: \"(\\<And>s. guard s \\<Longrightarrow> lossless_spmf (body s)) \\<Longrightarrow> lossless_spmf (iter n s)\"\n  by(induction n arbitrary: s) simp_all\n\nlemma iter_mono_emeasure1:\n  \"emeasure (measure_spmf (iter n s)) {s. \\<not> guard s} \\<le> emeasure (measure_spmf (iter (Suc n) s)) {s. \\<not> guard s}\"\n  (is \"?lhs \\<le> ?rhs\")\nproof(cases \"guard s\")\n  case True\n  have \"?lhs = emeasure (measure_spmf (bind_spmf (iter n s) return_spmf)) {s. \\<not> guard s}\" by simp\n  also have \"\\<dots> = \\<integral>\\<^sup>+ s'. emeasure (measure_spmf (return_spmf s')) {s. \\<not> guard s} \\<partial>measure_spmf (iter n s)\"\n    by(simp del: bind_return_spmf add: measure_spmf_bind o_def emeasure_bind[where N=\"measure_spmf _\"] space_measure_spmf Pi_def space_subprob_algebra)\n  also have \"\\<dots> \\<le> \\<integral>\\<^sup>+ s'. emeasure (measure_spmf (if guard s' then body s' else return_spmf s')) {s. \\<not> guard s} \\<partial>measure_spmf (iter n s)\"\n    by(rule nn_integral_mono)(simp add: measure_spmf_return_spmf)\n  also have \"\\<dots> = ?rhs\"\n    by(simp add: iter_Suc2 measure_spmf_bind o_def emeasure_bind[where N=\"measure_spmf _\"] space_measure_spmf Pi_def space_subprob_algebra del: iter.simps)\n  finally show ?thesis .\nqed simp\n\nlemma weight_while_conv_iter:\n  \"weight_spmf (while s) = (SUP n. measure (measure_spmf (iter n s)) {s. \\<not> guard s})\"\n  (is \"?lhs = ?rhs\")\nproof(rule antisym)\n  have \"emeasure (measure_spmf (while s)) UNIV \\<le> (SUP n. emeasure (measure_spmf (iter n s)) {s. \\<not> guard s})\"\n    (is \"_ \\<le> (SUP n. ?f n s)\")\n  proof(induction arbitrary: s rule: while_fixp_induct)\n    case adm show ?case by simp\n    case bottom show ?case by simp\n    case (step while')\n    show ?case (is \"?lhs' \\<le> ?rhs'\")\n    proof(cases \"guard s\")\n      case True\n      have inc: \"incseq ?f\" by(rule incseq_SucI le_funI iter_mono_emeasure1)+\n\n      from True have \"?lhs' = \\<integral>\\<^sup>+ s'. emeasure (measure_spmf (while' s')) UNIV \\<partial>measure_spmf (body s)\"\n        by(simp add: measure_spmf_bind o_def emeasure_bind[where N=\"measure_spmf _\"] space_measure_spmf Pi_def space_subprob_algebra)\n      also have \"\\<dots> \\<le> \\<integral>\\<^sup>+ s'. (SUP n. ?f n s') \\<partial>measure_spmf (body s)\"\n        by(rule nn_integral_mono)(rule step.IH)\n      also have \"\\<dots> = (SUP n. \\<integral>\\<^sup>+ s'. ?f n s' \\<partial>measure_spmf (body s))\" using inc\n        by(subst nn_integral_monotone_convergence_SUP) simp_all\n      also have \"\\<dots> = (SUP n. ?f (Suc n) s)\" using True\n        by(simp add: measure_spmf_bind o_def emeasure_bind[where N=\"measure_spmf _\"] space_measure_spmf Pi_def space_subprob_algebra)\n      also have \"\\<dots> \\<le> (SUP n. ?f n s)\"\n        by(rule SUP_mono)(auto intro: exI[where x=\"Suc _\"])\n      finally show ?thesis .\n    next\n      case False\n      then have \"?lhs' = emeasure (measure_spmf (iter 0 s)) {s. \\<not> guard s}\" \n        by(simp add: measure_spmf_return_spmf)\n      also have \\<open>\\<dots> \\<le> ?rhs'\\<close> by(rule SUP_upper) simp\n      finally show ?thesis .\n    qed\n  qed\n  also have \"\\<dots> = ennreal (SUP n. measure (measure_spmf (iter n s)) {s. \\<not> guard s})\"\n    by(subst ennreal_SUP)(fold measure_spmf.emeasure_eq_measure, auto simp add: not_less measure_spmf.subprob_emeasure_le_1 intro!: exI[where x=\"1\"])\n  also have \"0 \\<le> (SUP n. measure (measure_spmf (iter n s)) {s. \\<not> guard s})\"\n    by(rule cSUP_upper2)(auto intro!: bdd_aboveI[where M=1] simp add: measure_spmf.subprob_measure_le_1)\n  ultimately show \"?lhs \\<le> ?rhs\" by(simp add: measure_spmf.emeasure_eq_measure space_measure_spmf)\n  \n  show \"?rhs \\<le> ?lhs\"\n  proof(rule cSUP_least)\n    show \"measure (measure_spmf (iter n s)) {s. \\<not> guard s} \\<le> weight_spmf (while s)\" (is \"?f n s \\<le> _\") for n\n    proof(induction n arbitrary: s)\n      case 0 show ?case\n        by(simp add: measure_spmf_return_spmf measure_return while_simps split: split_indicator)\n    next\n      case (Suc n)\n      show ?case\n      proof(cases \"guard s\")\n        case True\n        have \"?f (Suc n) s = \\<integral>\\<^sup>+ s'. ?f n s' \\<partial>measure_spmf (body s)\"\n          using True unfolding measure_spmf.emeasure_eq_measure[symmetric]\n          by(simp add: measure_spmf_bind o_def emeasure_bind[where N=\"measure_spmf _\"] space_measure_spmf Pi_def space_subprob_algebra)\n        also have \"\\<dots> \\<le> \\<integral>\\<^sup>+ s'. weight_spmf (while s') \\<partial>measure_spmf (body s)\"\n          by(rule nn_integral_mono ennreal_leI Suc.IH)+\n        also have \"\\<dots> = weight_spmf (while s)\"\n          using True unfolding measure_spmf.emeasure_eq_measure[symmetric] space_measure_spmf\n          by(simp add: while_simps measure_spmf_bind o_def emeasure_bind[where N=\"measure_spmf _\"] space_measure_spmf Pi_def space_subprob_algebra)\n        finally show ?thesis by(simp)\n      next\n        case False then show ?thesis\n          by(simp add: measure_spmf_return_spmf measure_return while_simps split: split_indicator)\n      qed\n    qed\n  qed simp\nqed\n\nlemma termination_0_1:\n  assumes p: \"\\<And>s. guard s \\<Longrightarrow> p \\<le> weight_spmf (while s)\"\n    and p_pos: \"0 < p\"\n    and lossless: \"\\<And>s. guard s \\<Longrightarrow> lossless_spmf (body s)\"\n  shows \"lossless_spmf (while s)\"\n  unfolding lossless_spmf_def\nproof(rule antisym)\n  let ?X = \"{s. \\<not> guard s}\"\n  show \"weight_spmf (while s) \\<le> 1\" by(rule weight_spmf_le_1)\n  \n  define p' where \"p' \\<equiv> p / 2\"\n  have p'_pos: \"p' > 0\" and \"p' < p\" using p_pos by(simp_all add: p'_def)\n  \n  have \"\\<exists>n. p' < measure (measure_spmf (iter n s)) ?X\" if \"guard s\" for s using p[OF that] \\<open>p' < p\\<close>\n    unfolding weight_while_conv_iter\n    by(subst (asm) le_cSUP_iff)(auto intro!: measure_spmf.subprob_measure_le_1)\n  then obtain N where p': \"p' \\<le> measure (measure_spmf (iter (N s) s)) ?X\" if \"guard s\" for s\n    using p by atomize_elim(rule choice, force dest: order.strict_implies_order)\n\n  interpret fuse: loop_spmf guard \"\\<lambda>s. iter (N s) s\" .\n  \n  have \"1 = weight_spmf (fuse.while s)\"\n    by(rule lossless_weight_spmfD[symmetric])\n      (rule fuse.termination_0_1_immediate; auto simp add: spmf_map vimage_def intro: p' p'_pos lossless_iter lossless)\n  also have \"\\<dots> \\<le> (\\<Squnion>n. measure (measure_spmf (iter n s)) ?X)\"\n    unfolding fuse.weight_while_conv_iter\n  proof(rule cSUP_least)\n    fix n\n    have \"emeasure (measure_spmf (fuse.iter n s)) ?X \\<le> (SUP n. emeasure (measure_spmf (iter n s)) ?X)\"\n    proof(induction n arbitrary: s)\n      case 0 show ?case by(auto intro!: SUP_upper2[where i=0])\n    next\n      case (Suc n)\n      have inc: \"incseq (\\<lambda>n s'. emeasure (measure_spmf (iter n s')) ?X)\"\n        by(rule incseq_SucI le_funI iter_mono_emeasure1)+\n\n      have \"emeasure (measure_spmf (fuse.iter (Suc n) s)) ?X = emeasure (measure_spmf (iter (N s) s \\<bind> fuse.iter n)) ?X\"\n        by simp\n      also have \"\\<dots> = \\<integral>\\<^sup>+ s'. emeasure (measure_spmf (fuse.iter n s')) ?X \\<partial>measure_spmf (iter (N s) s)\"\n        by(simp add: measure_spmf_bind o_def emeasure_bind[where N=\"measure_spmf _\"] space_measure_spmf Pi_def space_subprob_algebra)\n      also have \"\\<dots> \\<le> \\<integral>\\<^sup>+ s'. (SUP n. emeasure (measure_spmf (iter n s')) ?X) \\<partial>measure_spmf (iter (N s) s)\"\n        by(rule nn_integral_mono Suc.IH)+\n      also have \"\\<dots> = (SUP n. \\<integral>\\<^sup>+ s'. emeasure (measure_spmf (iter n s')) ?X \\<partial>measure_spmf (iter (N s) s))\"\n        by(rule nn_integral_monotone_convergence_SUP[OF inc]) simp\n      also have \"\\<dots> = (SUP n. emeasure (measure_spmf (bind_spmf (iter (N s) s) (iter n))) ?X)\"\n        by(simp add: measure_spmf_bind o_def emeasure_bind[where N=\"measure_spmf _\"] space_measure_spmf Pi_def space_subprob_algebra)\n      also have \"\\<dots> = (SUP n. emeasure (measure_spmf (iter (N s + n) s)) ?X)\" by(simp add: iter_bind_iter)\n      also have \"\\<dots> \\<le> (SUP n. emeasure (measure_spmf (iter n s)) ?X)\" by(rule SUP_mono) auto\n      finally show ?case .\n    qed\n    also have \"\\<dots> = ennreal (SUP n. measure (measure_spmf (iter n s)) ?X)\"\n      by(subst ennreal_SUP)(fold measure_spmf.emeasure_eq_measure, auto simp add: not_less measure_spmf.subprob_emeasure_le_1 intro!: exI[where x=\"1\"])\n    also have \"0 \\<le> (SUP n. measure (measure_spmf (iter n s)) ?X)\"\n      by(rule cSUP_upper2)(auto intro!: bdd_aboveI[where M=1] simp add: measure_spmf.subprob_measure_le_1)\n    ultimately show \"measure (measure_spmf (fuse.iter n s)) ?X \\<le> \\<dots>\"\n      by(simp add: measure_spmf.emeasure_eq_measure)\n  qed simp\n  finally show  \"1 \\<le> weight_spmf (while s)\" unfolding weight_while_conv_iter .\nqed\n\nend\n\nlemma termination_0_1_immediate_invar:\n  fixes I :: \"'s \\<Rightarrow> bool\"\n  assumes p: \"\\<And>s. \\<lbrakk> guard s; I s \\<rbrakk> \\<Longrightarrow> spmf (map_spmf guard (body s)) False \\<ge> p\"\n  and p_pos: \"0 < p\"\n  and lossless: \"\\<And>s. \\<lbrakk> guard s; I s \\<rbrakk> \\<Longrightarrow> lossless_spmf (body s)\"\n  and invar: \"\\<And>s s'. \\<lbrakk> s' \\<in> set_spmf (body s); I s; guard s \\<rbrakk> \\<Longrightarrow> I s'\"\n  and I: \"I s\"\n  shows \"lossless_spmf (loop_spmf.while guard body s)\"\n  including lifting_syntax\nproof -\n  { assume \"\\<exists>(Rep :: 's' \\<Rightarrow> 's) Abs. type_definition Rep Abs {s. I s}\"\n    then obtain Rep :: \"'s' \\<Rightarrow> 's\" and Abs where td: \"type_definition Rep Abs {s. I s}\" by blast\n    then interpret td: type_definition Rep Abs \"{s. I s}\" .\n    define cr where \"cr \\<equiv> \\<lambda>x y. x = Rep y\"\n    have [transfer_rule]: \"bi_unique cr\" \"right_total cr\" using td cr_def by(rule typedef_bi_unique typedef_right_total)+\n    have [transfer_domain_rule]: \"Domainp cr = I\" using type_definition_Domainp[OF td cr_def] by simp\n\n    define guard' where \"guard' \\<equiv> (Rep ---> id) guard\"\n    have [transfer_rule]: \"(cr ===> (=)) guard guard'\" by(simp add: rel_fun_def cr_def guard'_def)\n    define body1 where \"body1 \\<equiv> \\<lambda>s. if guard s then body s else return_pmf None\"\n    define body1' where \"body1' \\<equiv> (Rep ---> map_spmf Abs) body1\"\n    have [transfer_rule]: \"(cr ===> rel_spmf cr) body1 body1'\"\n      by(auto simp add: rel_fun_def body1'_def body1_def cr_def spmf_rel_map td.Rep[simplified] invar td.Abs_inverse intro!: rel_spmf_reflI)\n    define s' where \"s' \\<equiv> Abs s\"\n    have [transfer_rule]: \"cr s s'\" by(simp add: s'_def cr_def I td.Abs_inverse)\n\n    have \"\\<And>s. guard' s \\<Longrightarrow> p \\<le> spmf (map_spmf guard' (body1' s)) False\"\n      by(transfer fixing: p)(simp add: body1_def p)\n    moreover note p_pos\n    moreover have \"\\<And>s. guard' s \\<Longrightarrow> lossless_spmf (body1' s)\" by transfer(simp add: lossless body1_def)\n    ultimately have \"lossless_spmf (loop_spmf.while guard' body1' s')\" by(rule loop_spmf.termination_0_1_immediate)\n    hence \"lossless_spmf (loop_spmf.while guard body1 s)\" by transfer }\n  from this[cancel_type_definition] I show ?thesis by(auto cong: loop_spmf_while_cong)\nqed\n\nlemma termination_0_1_invar:\n  fixes I :: \"'s \\<Rightarrow> bool\"\n  assumes p: \"\\<And>s. \\<lbrakk> guard s; I s \\<rbrakk> \\<Longrightarrow> p \\<le> weight_spmf (loop_spmf.while guard body s)\"\n    and p_pos: \"0 < p\"\n    and lossless: \"\\<And>s. \\<lbrakk> guard s; I s \\<rbrakk> \\<Longrightarrow> lossless_spmf (body s)\"\n    and invar: \"\\<And>s s'. \\<lbrakk> s' \\<in> set_spmf (body s); I s; guard s \\<rbrakk> \\<Longrightarrow> I s'\"\n    and I: \"I s\"\n  shows \"lossless_spmf (loop_spmf.while guard body s)\"\n  including lifting_syntax\nproof-\n  { assume \"\\<exists>(Rep :: 's' \\<Rightarrow> 's) Abs. type_definition Rep Abs {s. I s}\"\n    then obtain Rep :: \"'s' \\<Rightarrow> 's\" and Abs where td: \"type_definition Rep Abs {s. I s}\" by blast\n    then interpret td: type_definition Rep Abs \"{s. I s}\" .\n    define cr where \"cr \\<equiv> \\<lambda>x y. x = Rep y\"\n    have [transfer_rule]: \"bi_unique cr\" \"right_total cr\" using td cr_def by(rule typedef_bi_unique typedef_right_total)+\n    have [transfer_domain_rule]: \"Domainp cr = I\" using type_definition_Domainp[OF td cr_def] by simp\n\n    define guard' where \"guard' \\<equiv> (Rep ---> id) guard\"\n    have [transfer_rule]: \"(cr ===> (=)) guard guard'\" by(simp add: rel_fun_def cr_def guard'_def)\n    define body1 where \"body1 \\<equiv> \\<lambda>s. if guard s then body s else return_pmf None\"\n    define body1' where \"body1' \\<equiv> (Rep ---> map_spmf Abs) body1\"\n    have [transfer_rule]: \"(cr ===> rel_spmf cr) body1 body1'\"\n      by(auto simp add: rel_fun_def body1'_def body1_def cr_def spmf_rel_map td.Rep[simplified] invar td.Abs_inverse intro!: rel_spmf_reflI)\n    define s' where \"s' \\<equiv> Abs s\"\n    have [transfer_rule]: \"cr s s'\" by(simp add: s'_def cr_def I td.Abs_inverse)\n    \n    interpret loop_spmf guard' body1' .\n\n    note UNIV_parametric_pred[transfer_rule]\n    have \"\\<And>s. guard' s \\<Longrightarrow> p \\<le> weight_spmf (while s)\"\n      unfolding measure_measure_spmf_def[symmetric] space_measure_spmf\n      by(transfer fixing: p)(simp add: body1_def p[simplified space_measure_spmf] cong: loop_spmf_while_cong)\n    moreover note p_pos\n    moreover have \"\\<And>s. guard' s \\<Longrightarrow> lossless_spmf (body1' s)\" by transfer(simp add: lossless body1_def)\n    ultimately have \"lossless_spmf (while s')\" by(rule termination_0_1)\n    hence \"lossless_spmf (loop_spmf.while guard body1 s)\" by transfer }\n  from this[cancel_type_definition] I show ?thesis by(auto cong: loop_spmf_while_cong)\nqed\n\nsubsection \\<open>Variant rule\\<close>\n\ncontext loop_spmf begin\n\nlemma termination_variant:\n  fixes bound :: nat\n  assumes bound: \"\\<And>s. guard s \\<Longrightarrow> f s \\<le> bound\"\n  and step: \"\\<And>s. guard s \\<Longrightarrow> p \\<le> spmf (map_spmf (\\<lambda>s'. f s' < f s) (body s)) True\"\n  and p_pos: \"0 < p\"\n  and lossless: \"\\<And>s. guard s \\<Longrightarrow> lossless_spmf (body s)\"\n  shows \"lossless_spmf (while s)\"\nproof -\n  define p' and n where \"p' \\<equiv> min p 1\" and \"n \\<equiv> bound + 1\"\n  have p'_pos: \"0 < p'\" and p'_le_1: \"p' \\<le> 1\" \n    and step': \"guard s \\<Longrightarrow> p' \\<le> measure (measure_spmf (body s)) {s'. f s' < f s}\" for s\n    using p_pos step[of s] by(simp_all add: p'_def spmf_map vimage_def)\n  have \"p' ^ n \\<le> weight_spmf (while s)\" if \"f s < n\" for s using that\n  proof(induction n arbitrary: s)\n    case 0 thus ?case by simp\n  next\n    case (Suc n)\n    show ?case\n    proof(cases \"guard s\")\n      case False\n      hence \"weight_spmf (while s) = 1\" by(simp add: while.simps)\n      thus ?thesis using p'_le_1 p_pos \n        by simp(meson less_eq_real_def mult_le_one p'_pos power_le_one zero_le_power)\n    next\n      case True\n      let ?M = \"measure_spmf (body s)\"\n      have \"p' ^ Suc n \\<le> (\\<integral> s'. indicator {s'. f s' < f s} s' \\<partial>?M) * p' ^ n\"\n        using step'[OF True] p'_pos by(simp add: mult_right_mono)\n      also have \"\\<dots> = (\\<integral> s'. indicator {s'. f s' < f s} s' * p' ^ n \\<partial>?M)\" by simp\n      also have \"\\<dots> \\<le> (\\<integral> s'. indicator {s'. f s' < f s} s' * weight_spmf (while s') \\<partial>?M)\"\n        using Suc.prems p'_le_1 p'_pos\n        by(intro integral_mono)(auto simp add: Suc.IH power_le_one weight_spmf_le_1 split: split_indicator intro!: measure_spmf.integrable_const_bound[where B=1])\n      also have \"\\<dots> \\<le> \\<dots> + (\\<integral> s'. indicator {s'. f s' \\<ge> f s} s' * weight_spmf (while s') \\<partial>?M)\"\n        by(simp add: integral_nonneg_AE weight_spmf_nonneg)\n      also have \"\\<dots> = \\<integral> s'. weight_spmf (while s') \\<partial>?M\"\n        by(subst Bochner_Integration.integral_add[symmetric])\n          (auto intro!: Bochner_Integration.integral_cong measure_spmf.integrable_const_bound[where B=1] weight_spmf_le_1 split: split_indicator)\n      also have \"\\<dots> = weight_spmf (while s)\"\n        using True by(subst (1 2) while.simps)(simp add: weight_bind_spmf o_def)\n      finally show ?thesis .\n    qed\n  qed\n  moreover have \"0 < p' ^ n\" using p'_pos by simp\n  ultimately show ?thesis using lossless\n  proof(rule termination_0_1_invar)\n    show \"f s < n\" if \"guard s\" \"guard s \\<longrightarrow> f s < n\" for s using that by simp\n    show \"guard s \\<longrightarrow> f s < n\" using bound[of s] by(auto simp add: n_def)\n    show \"guard s' \\<longrightarrow> f s' < n\" for s' using bound[of s'] by(clarsimp simp add: n_def)\n  qed\nqed\n\nend\n\nlemma termination_variant_invar:\n  fixes bound :: nat and I :: \"'s \\<Rightarrow> bool\"\n  assumes bound: \"\\<And>s. \\<lbrakk> guard s; I s \\<rbrakk> \\<Longrightarrow> f s \\<le> bound\"\n  and step: \"\\<And>s. \\<lbrakk> guard s; I s \\<rbrakk> \\<Longrightarrow> p \\<le> spmf (map_spmf (\\<lambda>s'. f s' < f s) (body s)) True\"\n  and p_pos: \"0 < p\"\n  and lossless: \"\\<And>s. \\<lbrakk> guard s; I s \\<rbrakk> \\<Longrightarrow> lossless_spmf (body s)\"\n  and invar: \"\\<And>s s'. \\<lbrakk> s' \\<in> set_spmf (body s); I s; guard s \\<rbrakk> \\<Longrightarrow> I s'\"\n  and I: \"I s\"\n  shows \"lossless_spmf (loop_spmf.while guard body s)\"\n  including lifting_syntax\nproof -\n  { assume \"\\<exists>(Rep :: 's' \\<Rightarrow> 's) Abs. type_definition Rep Abs {s. I s}\"\n    then obtain Rep :: \"'s' \\<Rightarrow> 's\" and Abs where td: \"type_definition Rep Abs {s. I s}\" by blast\n    then interpret td: type_definition Rep Abs \"{s. I s}\" .\n    define cr where \"cr \\<equiv> \\<lambda>x y. x = Rep y\"\n    have [transfer_rule]: \"bi_unique cr\" \"right_total cr\" using td cr_def by(rule typedef_bi_unique typedef_right_total)+\n    have [transfer_domain_rule]: \"Domainp cr = I\" using type_definition_Domainp[OF td cr_def] by simp\n\n    define guard' where \"guard' \\<equiv> (Rep ---> id) guard\"\n    have [transfer_rule]: \"(cr ===> (=)) guard guard'\" by(simp add: rel_fun_def cr_def guard'_def)\n    define body1 where \"body1 \\<equiv> \\<lambda>s. if guard s then body s else return_pmf None\"\n    define body1' where \"body1' \\<equiv> (Rep ---> map_spmf Abs) body1\"\n    have [transfer_rule]: \"(cr ===> rel_spmf cr) body1 body1'\"\n      by(auto simp add: rel_fun_def body1'_def body1_def cr_def spmf_rel_map td.Rep[simplified] invar td.Abs_inverse intro!: rel_spmf_reflI)\n    define s' where \"s' \\<equiv> Abs s\"\n    have [transfer_rule]: \"cr s s'\" by(simp add: s'_def cr_def I td.Abs_inverse)\n    define f' where \"f' \\<equiv> (Rep ---> id) f\"\n    have [transfer_rule]: \"(cr ===> (=)) f f'\" by(simp add: rel_fun_def cr_def f'_def)\n\n    have \"\\<And>s. guard' s \\<Longrightarrow> f' s \\<le> bound\" by(transfer fixing: bound)(rule bound)\n    moreover have \"\\<And>s. guard' s \\<Longrightarrow> p \\<le> spmf (map_spmf (\\<lambda>s'. f' s' < f' s) (body1' s)) True\"\n      by(transfer fixing: p)(simp add: step body1_def)\n    note this p_pos\n    moreover have \"\\<And>s. guard' s \\<Longrightarrow> lossless_spmf (body1' s)\"\n      by transfer(simp add: body1_def lossless)\n    ultimately have \"lossless_spmf (loop_spmf.while guard' body1' s')\" by(rule loop_spmf.termination_variant)\n    hence \"lossless_spmf (loop_spmf.while guard body1 s)\" by transfer }\n  from this[cancel_type_definition] I show ?thesis by(auto cong: loop_spmf_while_cong)\nqed\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Probabilistic_While/While_SPMF.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5813030906443134, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.2679904786531366}}
{"text": "(*\n(C) Copyright Andreas Viktor Hess, DTU, 2020\n(C) Copyright Sebastian A. Mödersheim, DTU, 2020\n(C) Copyright Achim D. Brucker, University of Exeter, 2020\n(C) Copyright Anders Schlichtkrull, DTU, 2020\n\nAll Rights Reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\n- Redistributions of source code must retain the above copyright\n  notice, this list of conditions and the following disclaimer.\n\n- Redistributions in binary form must reproduce the above copyright\n  notice, this list of conditions and the following disclaimer in the\n  documentation and/or other materials provided with the distribution.\n\n- Neither the name of the copyright holder nor the names of its\n  contributors may be used to endorse or promote products\n  derived from this software without specific prior written\n  permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\nLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\nA PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\nOWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\nLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\nTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n*)\n\n(*  Title:      Term_Variants.thy\n    Author:     Andreas Viktor Hess, DTU\n    Author:     Sebastian A. Mödersheim, DTU\n    Author:     Achim D. Brucker, University of Exeter\n    Author:     Anders Schlichtkrull, DTU\n*)\n\nsection\\<open>Term Variants\\<close>\ntheory Term_Variants\n  imports Stateful_Protocol_Composition_and_Typing.Intruder_Deduction\nbegin\n\nfun term_variants where\n  \"term_variants P (Var x) = [Var x]\"\n| \"term_variants P (Fun f T) = (\n  let S = product_lists (map (term_variants P) T)\n  in map (Fun f) S@concat (map (\\<lambda>g. map (Fun g) S) (P f)))\"\n\ninductive term_variants_pred where\n  term_variants_Var:\n  \"term_variants_pred P (Var x) (Var x)\"\n| term_variants_P:\n  \"\\<lbrakk>length T = length S; \\<And>i. i < length T \\<Longrightarrow> term_variants_pred P (T ! i) (S ! i); g \\<in> set (P f)\\<rbrakk>\n   \\<Longrightarrow> term_variants_pred P (Fun f T) (Fun g S)\"\n| term_variants_Fun:\n  \"\\<lbrakk>length T = length S; \\<And>i. i < length T \\<Longrightarrow> term_variants_pred P (T ! i) (S ! i)\\<rbrakk>\n   \\<Longrightarrow> term_variants_pred P (Fun f T) (Fun f S)\"\n\nlemma term_variants_pred_inv:\n  assumes \"term_variants_pred P (Fun f T) (Fun h S)\"\n  shows \"length T = length S\"\n    and \"\\<And>i. i < length T \\<Longrightarrow> term_variants_pred P (T ! i) (S ! i)\"\n    and \"f \\<noteq> h \\<Longrightarrow> h \\<in> set (P f)\"\nusing assms by (auto elim: term_variants_pred.cases)\n\nlemma term_variants_pred_inv':\n  assumes \"term_variants_pred P (Fun f T) t\"\n  shows \"is_Fun t\"\n    and \"length T = length (args t)\"\n    and \"\\<And>i. i < length T \\<Longrightarrow> term_variants_pred P (T ! i) (args t ! i)\"\n    and \"f \\<noteq> the_Fun t \\<Longrightarrow> the_Fun t \\<in> set (P f)\"\n    and \"P \\<equiv> (\\<lambda>_. [])(g := [h]) \\<Longrightarrow> f \\<noteq> the_Fun t \\<Longrightarrow> f = g \\<and> the_Fun t = h\"\nusing assms by (auto elim: term_variants_pred.cases)\n\nlemma term_variants_pred_inv'':\n  assumes \"term_variants_pred P t (Fun f T)\"\n  shows \"is_Fun t\"\n    and \"length T = length (args t)\"\n    and \"\\<And>i. i < length T \\<Longrightarrow> term_variants_pred P (args t ! i) (T ! i)\"\n    and \"f \\<noteq> the_Fun t \\<Longrightarrow> f \\<in> set (P (the_Fun t))\"\n    and \"P \\<equiv> (\\<lambda>_. [])(g := [h]) \\<Longrightarrow> f \\<noteq> the_Fun t \\<Longrightarrow> f = h \\<and> the_Fun t = g\"\nusing assms by (auto elim: term_variants_pred.cases)\n\nlemma term_variants_pred_inv_Var:\n  \"term_variants_pred P (Var x) t \\<longleftrightarrow> t = Var x\"\n  \"term_variants_pred P t (Var x) \\<longleftrightarrow> t = Var x\"\nby (auto intro: term_variants_Var elim: term_variants_pred.cases)\n\nlemma term_variants_pred_inv_const:\n  \"term_variants_pred P (Fun c []) t \\<longleftrightarrow> ((\\<exists>g \\<in> set (P c). t = Fun g []) \\<or> (t = Fun c []))\"\nby (auto intro: term_variants_P term_variants_Fun elim: term_variants_pred.cases)\n\nlemma term_variants_pred_refl: \"term_variants_pred P t t\"\nby (induct t) (auto intro: term_variants_pred.intros)\n\nlemma term_variants_pred_refl_inv:\n  assumes st: \"term_variants_pred P s t\"\n    and P: \"\\<forall>f. \\<forall>g \\<in> set (P f). f = g\"\n  shows \"s = t\"\n  using st P\nproof (induction s t rule: term_variants_pred.induct)\ncase (term_variants_Var P x) thus ?case by blast\nnext\n  case (term_variants_P T S P g f)\n  hence \"T ! i = S ! i\" when i: \"i < length T\" for i using i by blast\n  hence \"T = S\" using term_variants_P.hyps(1) by (simp add: nth_equalityI)\n  thus ?case using term_variants_P.prems term_variants_P.hyps(3) by fast\nnext\n  case (term_variants_Fun T S P f)\n  hence \"T ! i = S ! i\" when i: \"i < length T\" for i using i by blast\n  hence \"T = S\" using term_variants_Fun.hyps(1) by (simp add: nth_equalityI)\n  thus ?case by fast\nqed\n\nlemma term_variants_pred_const:\n  assumes \"b \\<in> set (P a)\"\n  shows \"term_variants_pred P (Fun a []) (Fun b [])\"\nusing term_variants_P[of \"[]\" \"[]\"] assms by simp\n\nlemma term_variants_pred_const_cases:\n  \"P a \\<noteq> [] \\<Longrightarrow> term_variants_pred P (Fun a []) t \\<longleftrightarrow>\n                 (t = Fun a [] \\<or> (\\<exists>b \\<in> set (P a). t = Fun b []))\"\n  \"P a = [] \\<Longrightarrow> term_variants_pred P (Fun a []) t \\<longleftrightarrow> t = Fun a []\"\nusing term_variants_pred_inv_const[of P] by auto\n\nlemma term_variants_pred_param:\n  assumes \"term_variants_pred P t s\"\n    and fg: \"f = g \\<or> g \\<in> set (P f)\"\n  shows \"term_variants_pred P (Fun f (S@t#T)) (Fun g (S@s#T))\"\nproof -\n  have 1: \"length (S@t#T) = length (S@s#T)\" by simp\n  \n  have \"term_variants_pred P (T ! i) (T ! i)\" \"term_variants_pred P (S ! i) (S ! i)\" for i\n    by (metis term_variants_pred_refl)+\n  hence 2: \"term_variants_pred P ((S@t#T) ! i) ((S@s#T) ! i)\" for i\n    by (simp add: assms nth_Cons' nth_append)\n\n  show ?thesis by (metis term_variants_Fun[OF 1 2] term_variants_P[OF 1 2] fg)\nqed\n\nlemma term_variants_pred_Cons:\n  assumes t: \"term_variants_pred P t s\"\n    and T: \"term_variants_pred P (Fun f T) (Fun f S)\"\n    and fg: \"f = g \\<or> g \\<in> set (P f)\"\n  shows \"term_variants_pred P (Fun f (t#T)) (Fun g (s#S))\"\nproof -\n  have 1: \"length (t#T) = length (s#S)\"\n       and \"\\<And>i. i < length T \\<Longrightarrow> term_variants_pred P (T ! i) (S ! i)\"\n    using term_variants_pred_inv[OF T] by simp_all\n  hence 2: \"\\<And>i. i < length (t#T) \\<Longrightarrow> term_variants_pred P ((t#T) ! i) ((s#S) ! i)\"\n    by (metis t One_nat_def diff_less length_Cons less_Suc_eq less_imp_diff_less nth_Cons'\n              zero_less_Suc) \n\n  show ?thesis using 1 2 fg by (auto intro: term_variants_pred.intros)\nqed\n\nlemma term_variants_pred_dense:\n  fixes P Q::\"'a set\" and fs gs::\"'a list\"\n  defines \"P_fs x \\<equiv> if x \\<in> P then fs else []\"\n    and \"P_gs x \\<equiv> if x \\<in> P then gs else []\"\n    and \"Q_fs x \\<equiv> if x \\<in> Q then fs else []\"\n  assumes ut: \"term_variants_pred P_fs u t\"\n    and g: \"g \\<in> Q\" \"g \\<in> set gs\"\n  shows \"\\<exists>s. term_variants_pred P_gs u s \\<and> term_variants_pred Q_fs s t\"\nproof -\n  define F where \"F \\<equiv> \\<lambda>(P::'a set) (fs::'a list) x. if x \\<in> P then fs else []\"\n\n  show ?thesis using ut g P_fs_def unfolding P_gs_def Q_fs_def\n  proof (induction P_fs u t arbitrary: g gs rule: term_variants_pred.induct)\n    case (term_variants_Var P h x) thus ?case\n      by (auto intro: term_variants_pred.term_variants_Var)\n  next\n    case (term_variants_P T S P' h' h g gs)\n    note hyps = term_variants_P.hyps(1,2,4,5,6,7)\n    note IH = term_variants_P.hyps(3)\n\n    have \"\\<exists>s. term_variants_pred (F P gs) (T ! i) s \\<and> term_variants_pred (F Q fs) s (S ! i)\"\n      when i: \"i < length T\" for i\n      using IH[OF i hyps(4,5,6)] unfolding F_def by presburger\n    then obtain U where U:\n        \"length T = length U\" \"\\<And>i. i < length T \\<Longrightarrow> term_variants_pred (F P gs) (T ! i) (U ! i)\"\n        \"length U = length S\" \"\\<And>i. i < length U \\<Longrightarrow> term_variants_pred (F Q fs) (U ! i) (S ! i)\"\n      using hyps(1) Skolem_list_nth[of _ \"\\<lambda>i s. term_variants_pred (F P gs) (T ! i) s \\<and>\n                                                term_variants_pred (F Q fs) s (S ! i)\"]\n      by moura\n\n    show ?case\n      using term_variants_pred.term_variants_P[OF U(1,2), of g h]\n            term_variants_pred.term_variants_P[OF U(3,4), of h' g]\n            hyps(3)[unfolded hyps(6)] hyps(4,5)\n      unfolding F_def by force\n  next\n    case (term_variants_Fun T S P' h' g gs)\n    note hyps = term_variants_Fun.hyps(1,2,4,5,6)\n    note IH = term_variants_Fun.hyps(3)\n\n    have \"\\<exists>s. term_variants_pred (F P gs) (T ! i) s \\<and> term_variants_pred (F Q fs) s (S ! i)\"\n      when i: \"i < length T\" for i\n      using IH[OF i hyps(3,4,5)] unfolding F_def by presburger\n    then obtain U where U:\n        \"length T = length U\" \"\\<And>i. i < length T \\<Longrightarrow> term_variants_pred (F P gs) (T ! i) (U ! i)\"\n        \"length U = length S\" \"\\<And>i. i < length U \\<Longrightarrow> term_variants_pred (F Q fs) (U ! i) (S ! i)\"\n      using hyps(1) Skolem_list_nth[of _ \"\\<lambda>i s. term_variants_pred (F P gs) (T ! i) s \\<and>\n                                                term_variants_pred (F Q fs) s (S ! i)\"]\n      by moura\n    \n    thus ?case\n      using term_variants_pred.term_variants_Fun[OF U(1,2)]\n            term_variants_pred.term_variants_Fun[OF U(3,4)]\n      unfolding F_def by meson\n  qed\nqed\n\nlemma term_variants_pred_dense':\n  assumes ut: \"term_variants_pred ((\\<lambda>_. [])(a := [b])) u t\"\n  shows \"\\<exists>s. term_variants_pred ((\\<lambda>_. [])(a := [c])) u s \\<and>\n             term_variants_pred ((\\<lambda>_. [])(c := [b])) s t\"\nusing ut term_variants_pred_dense[of \"{a}\" \"[b]\" u t c \"{c}\" \"[c]\"]\nunfolding fun_upd_def by simp\n\nlemma term_variants_pred_eq_case:\n  fixes t s::\"('a,'b) term\"\n  assumes \"term_variants_pred P t s\" \"\\<forall>f \\<in> funs_term t. P f = []\"\n  shows \"t = s\"\nusing assms\nproof (induction P t s rule: term_variants_pred.induct)\n  case (term_variants_Fun T S P f) thus ?case\n    using subtermeq_imp_funs_term_subset[OF Fun_param_in_subterms[OF nth_mem], of _ T f]\n          nth_equalityI[of T S]\n    by blast\nqed (simp_all add: term_variants_pred_refl)\n\nlemma term_variants_pred_subst:\n  assumes \"term_variants_pred P t s\"\n  shows \"term_variants_pred P (t \\<cdot> \\<delta>) (s \\<cdot> \\<delta>)\"\nusing assms\nproof (induction P t s rule: term_variants_pred.induct)\n  case (term_variants_P T S P f g)\n  have 1: \"length (map (\\<lambda>t. t \\<cdot> \\<delta>) T) = length (map (\\<lambda>t. t \\<cdot> \\<delta>) S)\"\n    using term_variants_P.hyps\n    by simp\n\n  have 2: \"term_variants_pred P ((map (\\<lambda>t. t \\<cdot> \\<delta>) T) ! i) ((map (\\<lambda>t. t \\<cdot> \\<delta>) S) ! i)\"\n    when \"i < length (map (\\<lambda>t. t \\<cdot> \\<delta>) T)\" for i\n    using term_variants_P that\n    by fastforce\n\n  show ?case\n    using term_variants_pred.term_variants_P[OF 1 2 term_variants_P.hyps(3)]\n    by fastforce\nnext\n  case (term_variants_Fun T S P f)\n  have 1: \"length (map (\\<lambda>t. t \\<cdot> \\<delta>) T) = length (map (\\<lambda>t. t \\<cdot> \\<delta>) S)\"\n    using term_variants_Fun.hyps\n    by simp\n\n  have 2: \"term_variants_pred P ((map (\\<lambda>t. t \\<cdot> \\<delta>) T) ! i) ((map (\\<lambda>t. t \\<cdot> \\<delta>) S) ! i)\"\n    when \"i < length (map (\\<lambda>t. t \\<cdot> \\<delta>) T)\" for i\n    using term_variants_Fun that\n    by fastforce\n\n  show ?case\n    using term_variants_pred.term_variants_Fun[OF 1 2]\n    by fastforce\nqed (simp add: term_variants_pred_refl)\n\nlemma term_variants_pred_subst':\n  fixes t s::\"('a,'b) term\" and \\<delta>::\"('a,'b) subst\"\n  assumes \"term_variants_pred P (t \\<cdot> \\<delta>) s\"\n    and \"\\<forall>x \\<in> fv t \\<union> fv s. (\\<exists>y. \\<delta> x = Var y) \\<or> (\\<exists>f. \\<delta> x = Fun f [] \\<and> P f = [])\"\n  shows \"\\<exists>u. term_variants_pred P t u \\<and> s = u \\<cdot> \\<delta>\"\nusing assms\nproof (induction P \"t \\<cdot> \\<delta>\" s arbitrary: t rule: term_variants_pred.induct)\n  case (term_variants_Var P x g) thus ?case using term_variants_pred_refl by fast\nnext\n  case (term_variants_P T S P g f) show ?case\n  proof (cases t)\n    case (Var x) thus ?thesis\n      using term_variants_P.hyps(4,5) term_variants_P.prems\n      by fastforce\n  next\n    case (Fun h U)\n    hence 1: \"h = f\" \"T = map (\\<lambda>s. s \\<cdot> \\<delta>) U\" \"length U = length T\"\n      using term_variants_P.hyps(5) by simp_all\n    hence 2: \"T ! i = U ! i \\<cdot> \\<delta>\" when \"i < length T\" for i\n      using that by simp\n\n    have \"\\<forall>x \\<in> fv (U ! i) \\<union> fv (S ! i). (\\<exists>y. \\<delta> x = Var y) \\<or> (\\<exists>f. \\<delta> x = Fun f [] \\<and> P f = [])\"\n      when \"i < length U\" for i\n      using that Fun term_variants_P.prems term_variants_P.hyps(1) 1(3)\n      by force\n    hence IH: \"\\<forall>i < length U. \\<exists>u. term_variants_pred P (U ! i) u \\<and> S ! i = u \\<cdot> \\<delta>\"\n      by (metis 1(3) term_variants_P.hyps(3)[OF _ 2])\n\n    have \"\\<exists>V. length U = length V \\<and> S = map (\\<lambda>v. v \\<cdot> \\<delta>) V \\<and>\n               (\\<forall>i < length U. term_variants_pred P (U ! i) (V ! i))\"\n      using term_variants_P.hyps(1) 1(3) subst_term_list_obtain[OF IH] by metis\n    then obtain V where V: \"length U = length V\" \"S = map (\\<lambda>v. v \\<cdot> \\<delta>) V\"\n                           \"\\<And>i. i < length U \\<Longrightarrow> term_variants_pred P (U ! i) (V ! i)\"\n      by moura\n\n    have \"term_variants_pred P (Fun f U) (Fun g V)\"\n      by (metis term_variants_pred.term_variants_P[OF V(1,3) term_variants_P.hyps(4)])\n    moreover have \"Fun g S = Fun g V \\<cdot> \\<delta>\" using V(2) by simp\n    ultimately show ?thesis using term_variants_P.hyps(1,4) Fun 1 by blast\n  qed\nnext\n  case (term_variants_Fun T S P f t) show ?case\n  proof (cases t)\n    case (Var x)\n    hence \"T = []\" \"P f = []\" using term_variants_Fun.hyps(4) term_variants_Fun.prems by fastforce+\n    thus ?thesis using term_variants_pred_refl Var term_variants_Fun.hyps(1,4) by fastforce\n  next\n    case (Fun h U)\n    hence 1: \"h = f\" \"T = map (\\<lambda>s. s \\<cdot> \\<delta>) U\" \"length U = length T\"\n      using term_variants_Fun.hyps(4) by simp_all\n    hence 2: \"T ! i = U ! i \\<cdot> \\<delta>\" when \"i < length T\" for i\n      using that by simp\n\n    have \"\\<forall>x \\<in> fv (U ! i) \\<union> fv (S ! i). (\\<exists>y. \\<delta> x = Var y) \\<or> (\\<exists>f. \\<delta> x = Fun f [] \\<and> P f = [])\"\n      when \"i < length U\" for i\n      using that Fun term_variants_Fun.prems term_variants_Fun.hyps(1) 1(3)\n      by force\n    hence IH: \"\\<forall>i < length U. \\<exists>u. term_variants_pred P (U ! i) u \\<and> S ! i = u \\<cdot> \\<delta>\"\n      by (metis 1(3) term_variants_Fun.hyps(3)[OF _ 2 ])\n\n    have \"\\<exists>V. length U = length V \\<and> S = map (\\<lambda>v. v \\<cdot> \\<delta>) V \\<and>\n               (\\<forall>i < length U. term_variants_pred P (U ! i) (V ! i))\"\n      using term_variants_Fun.hyps(1) 1(3) subst_term_list_obtain[OF IH] by metis\n    then obtain V where V: \"length U = length V\" \"S = map (\\<lambda>v. v \\<cdot> \\<delta>) V\"\n                           \"\\<And>i. i < length U \\<Longrightarrow> term_variants_pred P (U ! i) (V ! i)\"\n      by moura\n\n    have \"term_variants_pred P (Fun f U) (Fun f V)\"\n      by (metis term_variants_pred.term_variants_Fun[OF V(1,3)])\n    moreover have \"Fun f S = Fun f V \\<cdot> \\<delta>\" using V(2) by simp\n    ultimately show ?thesis using term_variants_Fun.hyps(1) Fun 1 by blast\n  qed\nqed\n\nlemma term_variants_pred_iff_in_term_variants:\n  fixes t::\"('a,'b) term\"\n  shows \"term_variants_pred P t s \\<longleftrightarrow> s \\<in> set (term_variants P t)\"\n    (is \"?A t s \\<longleftrightarrow> ?B t s\")\nproof\n  define U where \"U \\<equiv> \\<lambda>P (T::('a,'b) term list). product_lists (map (term_variants P) T)\"\n\n  have a:\n      \"g \\<in> set (P f) \\<Longrightarrow> set (map (Fun g) (U P T)) \\<subseteq> set (term_variants P (Fun f T))\"\n      \"set (map (Fun f) (U P T)) \\<subseteq> set (term_variants P (Fun f T))\"\n    for f P g and T::\"('a,'b) term list\"\n    using term_variants.simps(2)[of P f T]\n    unfolding U_def Let_def by auto\n\n  have b: \"\\<exists>S \\<in> set (U P T). s = Fun f S \\<or> (\\<exists>g \\<in> set (P f). s = Fun g S)\"\n    when \"s \\<in> set (term_variants P (Fun f T))\" for P T f s\n    using that by (cases \"P f\") (auto simp add: U_def Let_def)\n\n  have c: \"length T = length S\" when \"S \\<in> set (U P T)\" for S P T\n    using that unfolding U_def\n    by (simp add: in_set_product_lists_length)\n\n  show \"?A t s \\<Longrightarrow> ?B t s\"\n  proof (induction P t s rule: term_variants_pred.induct)\n    case (term_variants_P T S P g f)\n    note hyps = term_variants_P.hyps\n    note IH = term_variants_P.IH\n\n    have \"S \\<in> set (U P T)\"\n      using IH hyps(1) product_lists_in_set_nth'[of _ S]\n      unfolding U_def by simp\n    thus ?case using a(1)[of _ P, OF hyps(3)] by auto\n  next\n    case (term_variants_Fun T S P f)\n    note hyps = term_variants_Fun.hyps\n    note IH = term_variants_Fun.IH\n\n    have \"S \\<in> set (U P T)\"\n      using IH hyps(1) product_lists_in_set_nth'[of _ S]\n      unfolding U_def by simp\n    thus ?case using a(2)[of f P T] by (cases \"P f\") auto\n  qed (simp add: term_variants_Var)\n\n  show \"?B t s \\<Longrightarrow> ?A t s\"\n  proof (induction P t arbitrary: s rule: term_variants.induct)\n    case (2 P f T)\n    obtain S where S:\n        \"s = Fun f S \\<or> (\\<exists>g \\<in> set (P f). s = Fun g S)\"\n        \"S \\<in> set (U P T)\" \"length T = length S\"\n      using c b[OF \"2.prems\"] by moura\n\n    have \"\\<forall>i < length T. term_variants_pred P (T ! i) (S ! i)\"\n      using \"2.IH\" S product_lists_in_set_nth by (fastforce simp add: U_def)\n    thus ?case using S by (auto intro: term_variants_pred.intros)\n  qed (simp add: term_variants_Var)\nqed\n\nlemma term_variants_pred_finite:\n  \"finite {s. term_variants_pred P t s}\"\nusing term_variants_pred_iff_in_term_variants[of P t]\nby simp\n\nlemma term_variants_pred_fv_eq:\n  assumes \"term_variants_pred P s t\"\n  shows \"fv s = fv t\"\nusing assms\nby (induct rule: term_variants_pred.induct)\n   (metis, metis fv_eq_FunI, metis fv_eq_FunI)\n\nlemma (in intruder_model) term_variants_pred_wf_trms:\n  assumes \"term_variants_pred P s t\"\n    and \"\\<And>f g. g \\<in> set (P f) \\<Longrightarrow> arity f = arity g\"\n    and \"wf\\<^sub>t\\<^sub>r\\<^sub>m s\"\n  shows \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\nusing assms\napply (induction rule: term_variants_pred.induct, simp)\nby (metis (no_types) wf_trmI wf_trm_arity in_set_conv_nth wf_trm_param_idx)+\n\nlemma term_variants_pred_funs_term:\n  assumes \"term_variants_pred P s t\"\n    and \"f \\<in> funs_term t\"\n  shows \"f \\<in> funs_term s \\<or> (\\<exists>g \\<in> funs_term s. f \\<in> set (P g))\"\n  using assms\nproof (induction rule: term_variants_pred.induct)\n  case (term_variants_P T S P g h) thus ?case\n  proof (cases \"f = g\")\n    case False\n    then obtain s where \"s \\<in> set S\" \"f \\<in> funs_term s\"\n      using funs_term_subterms_eq(1)[of \"Fun g S\"] term_variants_P.prems by auto\n    thus ?thesis\n      using term_variants_P.IH term_variants_P.hyps(1) in_set_conv_nth[of s S] by force\n  qed simp\nnext\n  case (term_variants_Fun T S P h) thus ?case\n  proof (cases \"f = h\")\n    case False\n    then obtain s where \"s \\<in> set S\" \"f \\<in> funs_term s\"\n      using funs_term_subterms_eq(1)[of \"Fun h S\"] term_variants_Fun.prems by auto\n    thus ?thesis\n      using term_variants_Fun.IH term_variants_Fun.hyps(1) in_set_conv_nth[of s S] by force\n  qed simp\nqed fast\n\nend\n", "meta": {"author": "logicalhacking", "repo": "Automated_Stateful_Protocol_Verification", "sha": "e24b8241b56d24240e1227caff737d4af82e12ec", "save_path": "github-repos/isabelle/logicalhacking-Automated_Stateful_Protocol_Verification", "path": "github-repos/isabelle/logicalhacking-Automated_Stateful_Protocol_Verification/Automated_Stateful_Protocol_Verification-e24b8241b56d24240e1227caff737d4af82e12ec/Automated_Stateful_Protocol_Verification/Term_Variants.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5813030906443133, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.2679904786531365}}
{"text": "chapter {* camr project *}\n\ntheory Execute imports Main Unification Term Deduction begin\n\n\n(* helper function that applies ANALYSIS RULES one step *)\nfun through_m :: \"msg list \\<Rightarrow> msg list \\<Rightarrow> msg list \\<Rightarrow> msg \\<Rightarrow> (subst_msg \\<times> system) list\" where\n\"through_m head [] a t = []\" |\n\"through_m head (u#tail) a t = (\n  case u of\n    Concat u1 u2 \\<Rightarrow>\n      [(Variable, [(((u1#u2#head@tail) | (u#a) } t))])]\n    | Sym_encrypt m k \\<Rightarrow>\n      [(Variable, [(((m#head@tail) | (u#a) } t)), (((head@tail) | (u#a) } k))])]\n    | Pub_encrypt m (Variable agent) \\<Rightarrow> \n        let s = Variable(agent:=(Const ''intruder'')) in\n        [(s, [sapplyc s ((head@u#tail)|a}t)])]\n    | Pub_encrypt m (Const x) \\<Rightarrow> (  \n      if x = ''intruder'' then  \n        [(Variable, [(((m#head@tail) | (u#a) } t))])]\n      else\n        []\n      )\n    | _ \\<Rightarrow> []\n) @ through_m (head@[u]) tail a t\"\n\nlemma through_m_ribosom: \"set (through_m head tail a t) \\<subseteq> set (through_m [] (head@tail) a t)\"\nproof(induction \"rev head\" arbitrary:head tail)\ncase Nil\n  then show ?case by simp\nnext\n  case (Cons u rhead head)\n  then have \"head = rev (u#rhead)\" by simp\n  then have headdef:\"head = (rev rhead) @ [u]\" by simp\n  have \"rhead = rev (rev rhead)\" by simp\n  then have \"set (through_m (rev rhead) (u # tail) a t)\n\\<subseteq> set (through_m [] (rev rhead @ u # tail) a t)\" by(rule Cons(1))\n  moreover have \"rev rhead @ u # tail = head @ tail\" by(simp add: headdef)\n  ultimately have \"set (through_m (rev rhead) (u # tail) a t) \\<subseteq> set (through_m [] (head @ tail) a t)\" by simp\n  moreover have \"set (through_m ((rev rhead) @ [u]) tail a t) \\<subseteq> set (through_m (rev rhead) (u # tail) a t)\" by auto\n  then have \"set (through_m head tail a t) \\<subseteq> set (through_m (rev rhead) (u # tail) a t)\" by(simp add:headdef)\n  ultimately show ?case by blast\nqed\n\nlemma through_m_sound: \n  assumes \"(s', cs') \\<in> set (through_m head tail a t)\"\n  shows \"((head@tail) | a } t) \\<leadsto>1[s'] cs'\"\n  using assms\nproof(induction head tail a t rule: through_m.induct)\n  case (1 head a t)\n  then show ?case by auto\nnext\n  case (2 head u tail a t)\n  let ?snd = \"through_m (head @ [u]) tail a t\"\n  let ?fst = \"through_m head (u # tail) a t\"\n  let ?prefix = \"case u of\n    Concat u1 u2 \\<Rightarrow>\n      [(Variable, [(((u1#u2#head@tail) | (u#a) } t))])]\n    | Sym_encrypt m k \\<Rightarrow>\n      [(Variable, [(((m#head@tail) | (u#a) } t)), (((head@tail) | (u#a) } k))])]\n    | Pub_encrypt m (Variable agent) \\<Rightarrow> \n        let s = Variable(agent:=(Const ''intruder'')) in\n        [(s, [sapplyc s ((head@u#tail)|a}t)])]\n    | Pub_encrypt m (Const x) \\<Rightarrow> (  \n      if x = ''intruder'' then  \n        [(Variable, [(((m#head@tail) | (u#a) } t))])]\n      else\n        []\n      )\n    | _ \\<Rightarrow> []\"\n  have decomp:\"set ?fst = set ?prefix \\<union> set ?snd\" by auto\n  then show ?case \n  proof (cases \"(s', cs') \\<in> set ?snd\")\n    case True\n    then show ?thesis using 2 by auto\n  next\n    case False\n    then have \"(s', cs') \\<in> set ?prefix\" using assms decomp 2 by blast\n    then show ?thesis by(cases u)(auto intro!: rer1.intros split: msg.split_asm simp add: Let_def simp del: fun_upd_apply)\n  qed\nqed\n\n\n(* helper function that applies UNIFY RULE one step*)\nfun through_all :: \"msg list \\<Rightarrow> msg \\<Rightarrow> (subst_msg \\<times> system) list\" where\n  \"through_all _ (Variable _) = []\" |\n  \"through_all l t  = \n    concat (map (%u. (case unify_msg [(t, u)] of\n      None \\<Rightarrow> []\n    | Some s \\<Rightarrow> [(s, [])]\n    )) l)\"\n\nlemma through_all_sound:\n  assumes \"(s, cs) \\<in> set (through_all (m@a) t)\"\n          \"c = m|a}t\"\n        shows \"c \\<leadsto>1[s] cs\"\n  using assms\nproof(cases t)\nqed(auto intro:rer1.intros)\n\n\n(* helper function that applies COMPOSITION RULES one step *)\nfun through_t :: \"constraint \\<Rightarrow> (subst_msg \\<times> system) option\" where\n  \"through_t (m|a}Concat x y) = Some (Variable, [(m|a}x), (m|a}y)])\"\n| \"through_t (m|a}Sym_encrypt x y) =  Some (Variable, [(m|a}x), (m|a}y)])\"\n| \"through_t (m|a}Pub_encrypt x y) = Some (Variable, [(m|a}x), (m|a}y)])\"\n| \"through_t (m|a}Sign x y) = (if y = Const ''intruder'' then  Some (Variable, [(m|a}x)]) else None)\"\n| \"through_t (m|a}Hash x) = Some (Variable, [(m|a}x)])\"\n| \"through_t _ = None\"\n\nlemma through_t_sound:\"Some (s, cs) = (through_t c) \\<Longrightarrow> c \\<leadsto>1[s] cs\"\nproof(cases c)\n  case (Constraint a m t)\n  show \"Some (s, cs) = (through_t c) \\<Longrightarrow> c \\<leadsto>1[s] cs\" \n    apply(cases t)\n          apply(auto simp add:Constraint intro!:rer1.intros split:if_split_asm)\n    done\nqed\n\n\n(* apply all constraint reduction rules to the input constraint *)\nfun rer1_succ:: \"constraint \\<Rightarrow> (subst_msg \\<times> system) list\" where\n  \"rer1_succ (m|a}t) = \n(through_all (m@a) t) @ (\n(through_m [] m a t) @ ( \n(case through_t (m|a}t) of None \\<Rightarrow> [] | Some x \\<Rightarrow> [x])))\"\n\nlemma rer1_succ_sound: \"(s, cs) \\<in> set (rer1_succ c) \\<Longrightarrow> c \\<leadsto>1[s] cs\"\nproof (cases c)\n  case (Constraint m a t)\n  assume in_set: \"(s, cs) \\<in> set (rer1_succ c)\" \n  have in_union: \"(set (rer1_succ (m|a}t))) = (set (through_all (m@a) t)) \\<union> (set (through_m [] m a t)) \\<union> (set (case through_t (m|a}t) of None \\<Rightarrow> [] | Some x \\<Rightarrow> [x]))\" \n    (is \"_ = ?Setall \\<union> ?Setm \\<union> ?Sett\") by auto\n  then show ?thesis \n  proof (cases \"(s, cs) \\<in> ?Setall\")\n    case True\n    then show ?thesis using Constraint by (rule through_all_sound)\n  next\n    case ex: False\n    then show ?thesis\n    proof(cases \"(s, cs) \\<in> ?Setm\")\n      case True\n      thm through_m_sound through_m_sound[of s cs \"[]\" m a t]\n      then have \"([] @ m)|a} t \\<leadsto>1[s] cs\" by (rule through_m_sound)\n      then show ?thesis using Constraint by simp\n    next\n      case False\n      then have \"(s, cs) \\<in> ?Sett\" using ex in_union in_set Constraint by simp\n      then show ?thesis using Constraint by (auto simp add: through_t_sound)\n    qed\n  qed\nqed\n\nlemma rer1_succ_complete: \"c \\<leadsto>1[s] cs \\<Longrightarrow> (s, cs) \\<in> set (rer1_succ c)\"\nproof(induction c s cs rule:rer1.induct)\n  case (rer1_unify t u a m s)\n  then have \"(s, []) \\<in> set (through_all (m@a) t)\"\n    apply(cases t; cases \"u\\<in>set a\")\n                 apply(auto simp add:sym[of \"Some s\" _] intro:bexI[of _ \"u\" \"set a\"])\n         apply(auto simp add:sym[of \"Some s\" _] intro:bexI[of _ \"u\" \"set m\"])\n    done    \n  then show ?case by simp\nnext\n  case (rer1_proj x u v head tail a t)\n  then have \"(Variable, [(u # v # head @ tail)|(x # a)} t ]) \\<in> set (through_m head (x # tail) a t)\" (is \"?x \\<in> ?s\")\n    by(auto)\n  moreover have \"?s \\<subseteq> set (through_m [] (head@x#tail) a t)\" by(rule through_m_ribosom)\n  ultimately have \"?x \\<in> set (through_m [] (head @ x # tail) a t)\"\n    by blast\n  then show ?case by simp\nnext\n  case (rer1_sdec x u k head tail a t)\n  then have \"(Variable,\n     [(u # head @ tail)|(x # a)} t , (head @ tail)|(x # a)} k ]) \\<in> set (through_m head (x # tail) a t)\" (is \"?x \\<in> ?s\")\n    by(auto)\n  moreover have \"?s \\<subseteq> set (through_m [] (head@x#tail) a t)\" by(rule through_m_ribosom)\n  ultimately have \"?x \\<in> set (through_m [] (head @ x # tail) a t)\"\n    by blast\n  then show ?case by simp\nnext\n  case (rer1_adec x u head tail a t)\n   then have \"(Variable, [(u # head @ tail)|(x # a)} t ]) \\<in> set (through_m head (x # tail) a t)\" (is \"?x \\<in> ?s\")\n    by(auto)\n  moreover have \"?s \\<subseteq> set (through_m [] (head@x#tail) a t)\" by(rule through_m_ribosom)\n  ultimately have \"?x \\<in> set (through_m [] (head @ x # tail) a t)\"\n    by blast\n  then show ?case by simp\nnext\n  case (rer1_ksub u agent m s a t)\n  let ?x=\"Pub_encrypt u (Variable agent)\"\n  from rer1_ksub(1) and split_list[of \"?x\" \"m\"]  obtain head tail where mdef:\"m = head @ ?x#tail\" by blast\n then have \" (s, [sapplyc s (m|a} t )]) \\<in> set (through_m head (?x # tail) a t)\" (is \"?elt \\<in> ?s\")\n   by(auto simp add:rer1_ksub Let_def sapplyc_def)\n  moreover have \"?s \\<subseteq> set (through_m [] (head@?x#tail) a t)\" by(rule through_m_ribosom)\n  ultimately have \"?elt \\<in> set (through_m [] (head @ ?x # tail) a t)\"\n    by blast\n  then show ?case by (simp add:mdef)\nqed auto\n\n\n(* apply the substitutions collected by applying the constraint reduction rules*)\nfun rer_succ_aux:: \"system \\<Rightarrow> system \\<Rightarrow> (subst_msg \\<times> system) list\" where\n  \"rer_succ_aux head [] = []\" |\n  \"rer_succ_aux head (c#tail) = \nrer_succ_aux (head@[c]) tail @ (map\n  (%(s, cs). \n     (s,\n      cs@(sapplys s (head@tail))\n     )\n  )\n  (rer1_succ c)\n)\"\n\nlemma rer_succ_aux_sound: \"(s, cs') \\<in> set (rer_succ_aux head tail) \\<Longrightarrow> (head@tail) \\<leadsto>[s] cs'\"\nproof(induction head tail arbitrary:s cs' rule:rer_succ_aux.induct)\n  case (1 head)\n  then show ?case by simp\nnext\n  case (2 head c tail)\n  then show ?case\n  proof(cases \"(s, cs') \\<in> set (rer_succ_aux (head@[c]) tail)\")\n    case True\n    then have \"((head @ [c]) @ tail)\\<leadsto>[s] cs'\" by(rule 2)\n    then show ?thesis by(simp)\nnext\n  case False\n  from this and \"2\"(2) have \"(s, cs') \\<in> set (map\n  (%(s, cs). \n     (s,\n      cs@(sapplys s (head@tail))\n     )\n  )\n  (rer1_succ c)\n)\" by simp\n  then obtain cs where csdef:\"cs' = cs@(sapplys s (head@tail))\" and in_rer1_succ:\"(s, cs) \\<in> set (rer1_succ c)\" by auto\n  moreover from in_rer1_succ have \"c \\<leadsto>1[s] cs\" by(rule rer1_succ_sound)\n  ultimately show ?thesis by(auto intro!:rer.intros)\nqed\nqed\n\n(* ok, this is exactly the same proof that for through_m_ribosom; I could have done a proper\ngeneral theorem *)\nlemma rer_succ_aux_ribosom: \"set (rer_succ_aux head tail) \\<subseteq> set (rer_succ_aux [] (head@tail))\"\nproof(induction \"rev head\" arbitrary:head tail)\ncase Nil\n  then show ?case by simp\nnext\n  case (Cons u rhead head)\n  then have \"head = rev (u#rhead)\" by simp\n  then have headdef:\"head = (rev rhead) @ [u]\" by simp\n  have \"rhead = rev (rev rhead)\" by simp\n  then have \"set (rer_succ_aux (rev rhead) (u # tail))\n\\<subseteq> set (rer_succ_aux [] (rev rhead @ u # tail))\" by(rule Cons(1))\n  moreover have \"rev rhead @ u # tail = head @ tail\" by(simp add: headdef)\n  ultimately have \"set (rer_succ_aux (rev rhead) (u # tail)) \\<subseteq> set (rer_succ_aux [] (head @ tail))\" by simp\n  moreover have \"set (rer_succ_aux ((rev rhead) @ [u]) tail) \\<subseteq> set (rer_succ_aux (rev rhead) (u # tail))\" by auto\n  then have \"set (rer_succ_aux head tail) \\<subseteq> set (rer_succ_aux (rev rhead) (u # tail))\" by(simp add:headdef)\n  ultimately show ?case by blast\nqed\n\nfun rer_succ:: \"system \\<Rightarrow> (subst_msg \\<times> system) list\" where\n\"rer_succ cs = rer_succ_aux [] cs\"\n\nlemma rer_succ_complete: \"cs \\<leadsto>[s] cs' \\<Longrightarrow> (s, cs') \\<in> set (rer_succ cs)\"\nproof(induction cs s cs' rule:rer.induct)\n  case (1 c s cs head tail)\n  then have \"(s, cs)\\<in> set (rer1_succ c)\" by(rule rer1_succ_complete)\n  then have \"(s, cs @ sapplys s (head @ tail))\\<in> set (rer_succ_aux head (c#tail))\" (is \"?elt \\<in> ?set\") by auto\n  moreover have \"?set \\<subseteq> set (rer_succ_aux [] (head@c#tail))\" by(rule rer_succ_aux_ribosom)\n  then have \"?set \\<subseteq> set (rer_succ (head@c#tail))\" by simp\n  ultimately show ?case by blast\nqed\n\nlemma rer_succ_sound: \"(s, cs') \\<in> set (rer_succ cs) \\<Longrightarrow> cs \\<leadsto>[s] cs'\"\nproof -\n  assume \"(s, cs') \\<in> set (rer_succ cs)\"\n  then have \"(s, cs') \\<in> set (rer_succ_aux [] cs)\" by simp\n  then have \"([]@cs) \\<leadsto>[s] cs'\" by(rule rer_succ_aux_sound)\n  then show \"cs \\<leadsto>[s] cs'\" by simp\nqed\n\n\n(* get the set of all constraints reachable from the current set *)\nfun next_step:: \"(subst_msg \\<times> system) list \\<Rightarrow> (subst_msg \\<times> system) list\" where\n\"next_step l = (concat (map \n(%(s, cs).\n  map (%(s', cs'). (scomp_msg s' s, cs')) (rer_succ cs)\n) l\n))\"\n\n\nlemma set_next_step: \"set (next_step l) = (\\<Union> (s, cs) \\<in> set l. {(scomp_msg s' s, cs') |cs' s'. cs\\<leadsto>[s'] cs'})\" (is \"_ = ?UN\")\nproof(rule equalityI; rule subsetI)\n  fix x\n  assume xin:\"x\\<in> set(next_step l)\"\n  then obtain s cs s' cs' where xdef:\"x= (scomp_msg s' s, cs')\" and rel:\"(s', cs')\\<in>set (rer_succ cs)\" and csdef:\"(s, cs)\\<in>set l\"  by auto\n  moreover from rel have \"cs \\<leadsto>[s'] cs'\" by(rule rer_succ_sound)\n  ultimately show \"x\\<in> ?UN\" by auto\nnext\n  fix x\n  assume xin:\"x\\<in>?UN\"\n  then obtain s cs s' cs' where\n    xdef:\"x= (scomp_msg s' s, cs')\" and rel:\"cs\\<leadsto>[s'] cs'\" and csdef:\"(s, cs)\\<in>set l\" \n    by auto\n  moreover from rel have \"(s', cs')\\<in>set (rer_succ cs)\" by(rule rer_succ_complete)\n  ultimately have \"x\\<in> set (map (%(s', cs'). (scomp_msg s' s, cs')) (rer_succ cs))\" (is \"x\\<in> set ?L\") by auto\n  moreover from csdef have \"?L \\<in> set (map \n(%(s, cs).\n  map (%(s', cs'). (scomp_msg s' s, cs')) (rer_succ cs)\n) l)\" by auto\n  ultimately show \"x\\<in> set (next_step l)\" by(auto simp only:set_concat next_step.simps)\nqed\n\nlemma wf_empty: \"wf {}\" by(auto simp add: wf_eq_minimal)\n\ndefinition steps_set:: \"(((subst_msg \\<times> system) list) \\<times> ((subst_msg \\<times> system) list)) set\"\n  where \"steps_set = {((next_step l), l)|l. l\\<noteq>[]}\"\n\nlemma wf_steps_set:\"wf steps_set\"\nproof -\n  let ?orig = \"{(y, x). reducesto x y}\"\n  let ?pairs = \"?orig <*lex*> ({}::subst_msg rel)\"\n  let ?revpairs = \"inv_image ?pairs (%(x, y). (y, x))\"\n  let ?sets = \"max_ext ?revpairs\"\n  have \"steps_set \\<subseteq> inv_image ?sets set\" (is \"_ \\<subseteq> ?lists\")\n  proof(rule subsetI)\n    fix x\n    assume assms:\"x \\<in> steps_set\"\n    then obtain l where xdef:\"x = (next_step l, l)\" and lnonempty:\"l\\<noteq>[]\" by(auto simp del:next_step.simps simp add:steps_set_def)\n    have \"(set (next_step l), set l) \\<in> ?sets\"\n    proof(rule max_extI)\n      fix y\n      assume \"y \\<in> set (next_step l)\"\n      then obtain s cs s' cs'\n        where ydef:\"y = (scomp_msg s' s, cs')\"\n          and cs'def:\"(s', cs')\\<in> set (rer_succ cs)\"\n          and csdef: \"(s, cs) \\<in> set l\"\n        by auto\n      show \"\\<exists>z\\<in>set l. (y, z) \\<in> ?revpairs\"\n      proof(rule bexI[of _ \"(s, cs)\"])\n        from cs'def have \"cs \\<leadsto>[s'] cs'\" by(rule rer_succ_sound)\n        then have \"reducesto cs cs'\" by(auto intro:reducesto.intros)\n        then have \"(cs', cs) \\<in> ?orig\" by simp\n        then have \"((cs', s'), (cs, s)) \\<in> ?pairs\" by(auto)\n        then show \"(y, (s, cs)) \\<in> ?revpairs\" by(auto simp add:inv_image_def ydef)\n      qed(simp add:csdef)\n    qed(auto simp add:lnonempty)\n    from this assms xdef show \"x\\<in> ?lists\" by(auto simp del:next_step.simps simp add:steps_set_def)\n  qed\n  moreover from termination_red and wf_empty have \"wf ?pairs\" by(rule wf_lex_prod)\n  then have \"wf ?revpairs\" by auto\n  then have \"wf ?sets\" by(auto intro:max_ext_wf)\n  then have \"wf ?lists\" by auto\n  ultimately show ?thesis by(auto intro:wf_subset)\nqed\n\n(* search for a simple constraint system which can be reached from the original constraint system *)\nfunction search_aux :: \"(subst_msg \\<times> system) list \\<Rightarrow> (subst_msg \\<times> system) option\" where\n\"search_aux l = (if l=[] then None else (case find (%(s, cs). simples cs) l of Some x \\<Rightarrow> Some x | None \\<Rightarrow> search_aux (next_step l)))\"\n  by pat_completeness auto\ntermination\n  apply(relation \"steps_set\")\n  using wf_steps_set apply(auto simp add:steps_set_def simp del:next_step.simps)\n  done\n\n\nlemma search_aux_none: \"search_aux l = None \\<Longrightarrow> (s, cs)\\<in> set l \\<Longrightarrow> cs \\<leadsto>*[s'] cs' \\<Longrightarrow> simples cs' \\<Longrightarrow> False\"\nproof(induction l arbitrary:s cs s' rule:search_aux.induct)\n  case (1 l)\n  then show ?case\n  proof(cases \"l=[]\")\n    case True\n    from this and \"1\" show ?thesis by(simp)\n  next\n    case False\n    from `l\\<noteq>[]` and `search_aux l = None` have a:\"find (\\<lambda>a. case a of (s, a) \\<Rightarrow> simples a) l = None\"\n      by(cases)(auto simp del:next_step.simps split:if_split_asm option.split)\n    from `l\\<noteq>[]` and `search_aux l = None` and this have b:\"search_aux (next_step l) = None\"\n      by(auto simp del:next_step.simps split:if_split_asm option.split)\n    from a b \"1\" False have \"\\<And>s s' cs. (s, cs) \\<in> set (next_step l) \\<Longrightarrow>  cs\\<leadsto>*[s'] cs' \\<Longrightarrow> False\" \n      by blast\n    from `cs\\<leadsto>*[s'] cs'` and `simples cs'` and `(s, cs) \\<in> set l` and `search_aux l = None` and this show ?thesis\n    proof(induction cs s' cs' arbitrary:s l rule:rer_star.induct)\n      case (rer_star_id cs)\n      from `(s, cs) \\<in> set l` have \"l \\<noteq> []\" by auto\n      from `simples cs` and `l\\<noteq>[]` and `(s, cs)\\<in> set l`\n      have \"find (\\<lambda>(s, y). simples y) l \\<noteq> None\"\n        by(auto simp add:find_None_iff)\n      from this and `search_aux l = None` show False\n        by(auto simp del:next_step.simps split:if_split_asm option.split_asm)\n    next\n      case (rer_star_step cs t' cs'' t cs')\n      from `cs\\<leadsto>[t'] cs''` and `(s, cs)\\<in>set l` have c:\"(scomp_msg t' s, cs'')\\<in> set (next_step l)\" (is \"(?s, _)\\<in>_\")\n        by (auto simp add:set_next_step simp del:next_step.simps)\n      have d:\"search_aux (next_step l) = None\"\n      proof(rule ccontr)\n        assume \"search_aux (next_step l) \\<noteq> None\"\n        then obtain x where \"search_aux (next_step l) =Some x\" by auto\n        moreover from `(s, cs) \\<in> set l` have \"l\\<noteq>[]\" by auto\n        ultimately have \"search_aux (l) \\<noteq> None\"\n          by(auto simp del:next_step.simps split:if_split_asm option.split)\n        from this and `search_aux l = None` show False by blast\n      qed\n      have \"\\<And>S CS S'. (S, CS) \\<in> set (next_step (next_step l)) \\<Longrightarrow> CS\\<leadsto>*[S'] cs'  \\<Longrightarrow> False\"\n      proof -\n        fix S CS S'\n        assume \"(S, CS) \\<in> set (next_step (next_step l))\" \"CS\\<leadsto>*[S'] cs'\"\n        from `(?s, cs'')\\<in>set (next_step l)` and this and set_next_step[of \"next_step l\"]\n        obtain k T U where \"k \\<leadsto>[T] CS\" and \"(U, k)\\<in> set (next_step l)\"\n          by(auto simp del:next_step.simps)\n        from this and `CS\\<leadsto>*[S'] cs'` have \"k \\<leadsto>*[scomp_msg S' T] cs'\" by(auto intro:rer_star.intros)\n        from `(U, k)\\<in>set (next_step l)` and this show False by(rule rer_star_step)\n      qed\n      from `simples cs'` and c and d and this and rer_star_step show False by blast\n    qed\n  qed\nqed\n\nlemma find_invent: \"find P l = Some x \\<Longrightarrow> x\\<in> set l\"\nproof(induction l)\n  case Nil\n  then show ?case by simp\nnext\n  case (Cons a l)\n  then show ?case\n  proof(cases \"P a\")\n    case True\n    from True and Cons show ?thesis by auto\n  next\n    case False\n    from False and Cons show ?thesis by auto\n  qed\nqed\n\nlemma search_finds_descendent:\"search_aux l = Some (s', cs') \\<Longrightarrow> (\\<exists>S. (\\<exists> (s, cs)\\<in> set l. cs \\<leadsto>*[S] cs'))\"\nproof(induction l rule:search_aux.induct)\n  case (1 l)\n  then have \"l\\<noteq>[]\" by auto\n  show ?case\n  proof(cases \"find (\\<lambda>(s, y). simples y) l\")\n    case None\n    from \"1\" and None and `l \\<noteq> []` \n    obtain S cs s where \"(s, cs)\\<in>set (next_step l)\" \"cs\\<leadsto>*[S] cs'\"\n      by(auto simp del:next_step.simps split:if_split_asm)\n    then obtain s0 cs0 W where \"(s0, cs0)\\<in> set l\" \"cs0 \\<leadsto>[W] cs\"\n      by(auto simp add:set_next_step simp del:next_step.simps)\n    from `cs0 \\<leadsto>[W] cs` and  `cs\\<leadsto>*[S] cs'` have \"cs0 \\<leadsto>*[scomp_msg S W] cs'\" by(rule rer_star_step)\n    from this and `(s0, cs0)\\<in> set l` show ?thesis by(auto simp del:next_step.simps)\n  next\n    case (Some a)\n    from this and \"1\" and `l\\<noteq>[]` have \"a = (s', cs')\" by simp\n    from this and Some have \"(s', cs')\\<in> set l\" by(auto simp add:find_invent)\n    moreover have \"cs' \\<leadsto>*[Variable] cs'\" by(rule rer_star_id)\n    ultimately show ?thesis by auto\n  qed\nqed\n\nlemma search_aux_complete: \"(\\<exists> s cs'. cs \\<leadsto>*[s] cs' \\<and> simples cs') \\<Longrightarrow> (\\<exists> s' cs''. search_aux [(Variable, cs)] = Some (s', cs''))\"\nproof (rule ccontr)\n  assume \"\\<exists>s cs'. cs\\<leadsto>*[s] cs' \\<and> simples cs'\"\n  then show \"\\<nexists>s' cs''. search_aux [(Variable, cs)] = Some (s', cs'') \\<Longrightarrow> False\"\n  proof -\n    assume asm: \"\\<nexists>s' cs''. search_aux [(Variable, cs)] = Some (s', cs'')\"\n    have \"\\<exists>x. search_aux [(Variable, cs)] = x\" by simp\n    then have \"search_aux [(Variable, cs)] = None \\<or> (\\<exists> x xs. search_aux [(Variable, cs)] = Some (x, xs))\" by (simp add: split_option_ex)\n    then have \"search_aux [(Variable, cs)] = None\" using asm by blast\n    then have \"(s1, cs) \\<in> set [(Variable, cs)] \\<Longrightarrow> cs \\<leadsto>*[s] cs' \\<Longrightarrow> simples cs' \\<Longrightarrow> False\" using search_aux_none by blast\n    then show ?thesis by (meson \\<open>\\<exists>s cs'. cs\\<leadsto>*[s] cs' \\<and> simples cs'\\<close> \\<open>search_aux [(Variable, cs)] = None\\<close> list.set_intros(1) search_aux_none)\n  qed\nqed\n\n(*\nMISSING PROOFS:\nsearch_aux_sound\nsearch_sound\n*)\n\nfun search:: \"system \\<Rightarrow> (subst_msg \\<times> system) option\" where\n\"search cs = search_aux [(Variable, cs)]\"\n\nlemma search_complete: \"(\\<exists> s cs'. cs \\<leadsto>*[s] cs' \\<and> simples cs') \\<Longrightarrow> (\\<exists> s' cs''. search cs = Some (s', cs''))\"\n  by (auto simp del: search_aux.simps simp add: search_aux_complete)\n\n(* test examples *)\n\ndefinition KTP:: \"msg \\<Rightarrow> msg \\<Rightarrow> msg \\<Rightarrow> msg \\<Rightarrow> system\"\n  where\n\"KTP A0 B0 A1 B1 =\n(let\n  IK0 = [Const ''A'', Const ''B'', Const ''intruder''];\n  IK1 = (Pub_encrypt (Sign (Const ''k0'') A0) B0) # IK0;\n  IK2 = (Sym_encrypt (Const ''m1'') (Variable ''K1''))#IK1\nin [\n  (IK0|[]}A0), \n  (IK0|[]}A1),\n  (IK1|[]} (Pub_encrypt (Sign (Variable ''K1'') A1) B1)),\n  (IK2|[]} (Sym_encrypt (Variable ''Z0'') (Variable ''K1''))),\n  (IK2|[]} (Concat (Variable ''K1'') (Variable ''Z0'')))\n  ]\n)\"\n\n\ndefinition \"A0 = Variable ''A0''\"\ndefinition \"A1 = Const ''A''\"\ndefinition \"B0 = Variable ''B0''\"\ndefinition \"B1 = Const ''B''\"\n\nvalue \"find (%(s, cs). simples cs) (rer_succ (KTP A0 B0 A1 B1))\"\nvalue \"rer_succ (KTP A0 B0 A1 B1)\"\nvalue \"(next_step ([(Variable, (KTP A0 B0 A1 B1))]))\"\n\n(* value \"map_option (%(s, cs). (cs, map (%v. (v, s v)) [''A0'', ''B0'', ''K1'', ''Z0''])) (search (KTP A0 B0 A1 B1))\" *)\n\nend ", "meta": {"author": "symphorien", "repo": "camr-project", "sha": "303a4f66f91c5ad36f5907b684f8969799a3e2e5", "save_path": "github-repos/isabelle/symphorien-camr-project", "path": "github-repos/isabelle/symphorien-camr-project/camr-project-303a4f66f91c5ad36f5907b684f8969799a3e2e5/Execute.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621765155565326, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.2679218876201255}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      HoarePartial.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer\nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection \\<open>Derived Hoare Rules for Partial Correctness\\<close>\n\ntheory HoarePartial imports HoarePartialProps begin\n\nlemma conseq_no_aux:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' c Q',A';\n    \\<forall>s. s \\<in> P \\<longrightarrow> (s\\<in>P' \\<and> (Q' \\<subseteq> Q) \\<and> (A' \\<subseteq> A))\\<rbrakk>\n  \\<Longrightarrow>\n  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule conseq [where P'=\"\\<lambda>Z. P'\" and Q'=\"\\<lambda>Z. Q'\" and A'=\"\\<lambda>Z. A'\"]) auto\n\n\nlemma conseq_exploit_pre:\n             \"\\<lbrakk>\\<forall>s \\<in> P. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s} \\<inter> P) c Q,A\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule Conseq)\n  apply clarify\n  apply (rule_tac x=\"{s} \\<inter> P\" in exI)\n  apply (rule_tac x=\"Q\" in exI)\n  apply (rule_tac x=\"A\" in exI)\n  by simp\n\n\nlemma conseq:\"\\<lbrakk>\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z);\n              \\<forall>s. s \\<in> P \\<longrightarrow> (\\<exists> Z. s\\<in>P' Z \\<and> (Q' Z \\<subseteq> Q) \\<and> (A' Z \\<subseteq> A))\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule Conseq') blast\n\nlemma Lem: \"\\<lbrakk>\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z);\n             P \\<subseteq> {s. \\<exists> Z. s\\<in>P' Z \\<and> (Q' Z \\<subseteq> Q) \\<and> (A' Z \\<subseteq> A)}\\<rbrakk>\n             \\<Longrightarrow>\n             \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (lem x c) Q,A\"\n  apply (unfold lem_def)\n  apply (erule conseq)\n  apply blast\n  done\n\nlemma LemAnno:\nassumes conseq:  \"P \\<subseteq> {s. \\<exists>Z. s\\<in>P' Z \\<and>\n                     (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> t \\<in> Q) \\<and> (\\<forall>t. t \\<in> A' Z \\<longrightarrow> t \\<in> A)}\"\nassumes lem: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (lem x c) Q,A\"\n  apply (rule Lem [OF lem])\n  using conseq\n  by blast\n\nlemma LemAnnoNoAbrupt:\nassumes conseq:  \"P \\<subseteq>  {s. \\<exists>Z. s\\<in>P' Z \\<and> (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> t \\<in> Q)}\"\nassumes lem: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),{}\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (lem x c) Q,{}\"\n  apply (rule Lem [OF lem])\n  using conseq\n  by blast\n\nlemma TrivPost: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z)\n                 \\<Longrightarrow>\n                 \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c UNIV,UNIV\"\napply (rule allI)\napply (erule conseq)\napply auto\ndone\n\nlemma TrivPostNoAbr: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),{}\n                 \\<Longrightarrow>\n                 \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c UNIV,{}\"\napply (rule allI)\napply (erule conseq)\napply auto\ndone\n\nlemma conseq_under_new_pre:\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P' c Q',A';\n        \\<forall>s \\<in> P. s \\<in> P' \\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A\\<rbrakk>\n\\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P c Q,A\"\napply (rule conseq)\napply (rule allI)\napply assumption\napply auto\ndone\n\n\n\nlemma DynComConseq:\n  assumes \"P \\<subseteq> {s. \\<exists>P' Q' A'.  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P' (c s) Q',A' \\<and> P \\<subseteq> P' \\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P DynCom c Q,A\"\n  using assms\n  apply -\n  apply (rule DynCom)\n  apply clarsimp\n  apply (rule Conseq)\n  apply clarsimp\n  apply blast\n  done\n\nlemma SpecAnno:\n assumes consequence: \"P \\<subseteq> {s. (\\<exists> Z. s\\<in>P' Z \\<and> (Q' Z \\<subseteq> Q) \\<and> (A' Z \\<subseteq> A))}\"\n assumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) (c Z) (Q' Z),(A' Z)\"\n assumes bdy_constant:  \"\\<forall>Z. c Z = c undefined\"\n shows   \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (specAnno P' c Q' A') Q,A\"\nproof -\n  from spec bdy_constant\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ((P' Z)) (c undefined) (Q' Z),(A' Z)\"\n    apply -\n    apply (rule allI)\n    apply (erule_tac x=Z in allE)\n    apply (erule_tac x=Z in allE)\n    apply simp\n    done\n  with consequence show ?thesis\n    apply (simp add: specAnno_def)\n    apply (erule conseq)\n    apply blast\n    done\nqed\n\nlemma SpecAnno':\n \"\\<lbrakk>P \\<subseteq> {s.  \\<exists> Z. s\\<in>P' Z \\<and>\n            (\\<forall>t. t \\<in> Q' Z \\<longrightarrow>  t \\<in> Q) \\<and> (\\<forall>t. t \\<in> A' Z \\<longrightarrow> t \\<in>  A)};\n   \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) (c Z) (Q' Z),(A' Z);\n   \\<forall>Z. c Z = c undefined\n  \\<rbrakk> \\<Longrightarrow>\n    \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (specAnno P' c Q' A') Q,A\"\napply (simp only: subset_iff [THEN sym])\napply (erule (1) SpecAnno)\napply assumption\ndone\n\n\nlemma SpecAnnoNoAbrupt:\n \"\\<lbrakk>P \\<subseteq> {s.  \\<exists> Z. s\\<in>P' Z \\<and>\n            (\\<forall>t. t \\<in> Q' Z \\<longrightarrow>  t \\<in> Q)};\n   \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) (c Z) (Q' Z),{};\n   \\<forall>Z. c Z = c undefined\n  \\<rbrakk> \\<Longrightarrow>\n    \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (specAnno P' c Q' (\\<lambda>s. {})) Q,A\"\napply (rule SpecAnno')\napply auto\ndone\n\nlemma Skip: \"P \\<subseteq> Q \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Skip Q,A\"\n  by (rule hoarep.Skip [THEN conseqPre],simp)\n\nlemma Basic: \"P \\<subseteq> {s. (f s) \\<in> Q} \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Basic f) Q,A\"\n  by (rule hoarep.Basic [THEN conseqPre])\n\nlemma BasicCond:\n  \"\\<lbrakk>P \\<subseteq> {s. (b s \\<longrightarrow> f s\\<in>Q) \\<and> (\\<not> b s \\<longrightarrow> g s\\<in>Q)}\\<rbrakk> \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Basic (\\<lambda>s. if b s then f s else g s) Q,A\"\n  apply (rule Basic)\n  apply auto\n  done\n\nlemma Spec: \"P \\<subseteq> {s. (\\<forall>t. (s,t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s,t) \\<in> r)}\n            \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Spec r) Q,A\"\nby (rule hoarep.Spec [THEN conseqPre])\n\nlemma SpecIf:\n  \"\\<lbrakk>P \\<subseteq> {s. (b s \\<longrightarrow> f s \\<in> Q) \\<and> (\\<not> b s \\<longrightarrow> g s \\<in> Q \\<and> h s \\<in> Q)}\\<rbrakk> \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Spec (if_rel b f g h) Q,A\"\n  apply (rule Spec)\n  apply (auto simp add: if_rel_def)\n  done\n\n\nlemma Seq [trans, intro?]:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>1 R,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Seq c\\<^sub>1 c\\<^sub>2) Q,A\"\n  by (rule hoarep.Seq)\n\nlemma SeqSwap:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c2 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c1 R,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Seq c1 c2) Q,A\"\n  by (rule Seq)\n\nlemma BSeq:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>1 R,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (bseq c\\<^sub>1 c\\<^sub>2) Q,A\"\n  by (unfold bseq_def) (rule Seq)\n\n\nlemma Cond:\n  assumes wp: \"P \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\"\n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P\\<^sub>1 c\\<^sub>1 Q,A\"\n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P\\<^sub>2 c\\<^sub>2 Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) Q,A\"\nproof (rule hoarep.Cond [THEN conseqPre])\n  from deriv_c1\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. (s \\<in> b \\<longrightarrow> s \\<in> P\\<^sub>1) \\<and> (s \\<notin> b \\<longrightarrow> s \\<in> P\\<^sub>2)} \\<inter> b) c\\<^sub>1 Q,A\"\n    by (rule conseqPre) blast\nnext\n  from deriv_c2\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. (s \\<in> b \\<longrightarrow> s \\<in> P\\<^sub>1) \\<and> (s \\<notin> b \\<longrightarrow> s \\<in> P\\<^sub>2)} \\<inter> - b) c\\<^sub>2 Q,A\"\n    by (rule conseqPre) blast\nnext\n  show \"P \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\" by (rule wp)\nqed\n\n\nlemma CondSwap:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P1 c1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P2 c2 Q,A; P \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P2)}\\<rbrakk>\n   \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c1 c2) Q,A\"\n  by (rule Cond)\n\nlemma Cond':\n  \"\\<lbrakk>P \\<subseteq> {s. (b \\<subseteq> P1) \\<and> (- b \\<subseteq> P2)};\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P1 c1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P2 c2 Q,A\\<rbrakk>\n   \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c1 c2) Q,A\"\n  by (rule CondSwap) blast+\n\nlemma CondInv:\n  assumes wp: \"P \\<subseteq> Q\"\n  assumes inv: \"Q \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\"\n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P\\<^sub>1 c\\<^sub>1 Q,A\"\n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P\\<^sub>2 c\\<^sub>2 Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) Q,A\"\nproof -\n  from wp inv\n  have \"P \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\"\n    by blast\n  from Cond [OF this deriv_c1 deriv_c2]\n  show ?thesis .\nqed\n\nlemma CondInv':\n  assumes wp: \"P \\<subseteq> I\"\n  assumes inv: \"I \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\"\n  assumes wp': \"I \\<subseteq> Q\"\n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P\\<^sub>1 c\\<^sub>1 I,A\"\n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P\\<^sub>2 c\\<^sub>2 I,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) Q,A\"\nproof -\n  from CondInv [OF wp inv deriv_c1 deriv_c2]\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) I,A\".\n  from conseqPost [OF this wp' subset_refl]\n  show ?thesis .\nqed\n\n\nlemma switchNil:\n  \"P \\<subseteq> Q \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P (switch v []) Q,A\"\n  by (simp add: Skip)\n\nlemma switchCons:\n  \"\\<lbrakk>P \\<subseteq> {s. (v s \\<in> V \\<longrightarrow> s \\<in> P\\<^sub>1) \\<and> (v s \\<notin> V \\<longrightarrow> s \\<in> P\\<^sub>2)};\n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P\\<^sub>1 c Q,A;\n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P\\<^sub>2 (switch v vs) Q,A\\<rbrakk>\n\\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P (switch v ((V,c)#vs)) Q,A\"\n  by (simp add: Cond)\n\nlemma Guard:\n \"\\<lbrakk>P \\<subseteq> g \\<inter> R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\napply (rule Guard [THEN conseqPre, of _ _ _ _ R])\napply (erule conseqPre)\napply auto\ndone\n\nlemma GuardSwap:\n \"\\<lbrakk> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> g \\<inter> R\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\n  by (rule Guard)\n\nlemma Guarantee:\n \"\\<lbrakk>P \\<subseteq> {s. s \\<in> g \\<longrightarrow> s \\<in> R}; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; f \\<in> F\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\napply (rule Guarantee [THEN conseqPre, of _ _ _ _ _ \"{s. s \\<in> g \\<longrightarrow> s \\<in> R}\"])\napply   assumption\napply  (erule conseqPre)\napply auto\ndone\n\nlemma GuaranteeSwap:\n \"\\<lbrakk> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> {s. s \\<in> g \\<longrightarrow> s \\<in> R}; f \\<in> F\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\n  by (rule Guarantee)\n\nlemma GuardStrip:\n \"\\<lbrakk>P \\<subseteq> R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; f \\<in> F\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\napply (rule Guarantee [THEN conseqPre])\napply auto\ndone\n\nlemma GuardStripSwap:\n \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> R; f \\<in> F\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\n  by (rule GuardStrip)\n\nlemma GuaranteeStrip:\n \"\\<lbrakk>P \\<subseteq> R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; f \\<in> F\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guaranteeStrip f g c) Q,A\"\n  by (unfold guaranteeStrip_def) (rule GuardStrip)\n\nlemma GuaranteeStripSwap:\n \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> R; f \\<in> F\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guaranteeStrip f g c) Q,A\"\n  by (unfold guaranteeStrip_def) (rule GuardStrip)\n\nlemma GuaranteeAsGuard:\n \"\\<lbrakk>P \\<subseteq> g \\<inter> R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guaranteeStrip f g c) Q,A\"\n  by (unfold guaranteeStrip_def) (rule Guard)\n\n\nlemma GuaranteeAsGuardSwap:\n \"\\<lbrakk> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> g \\<inter> R\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guaranteeStrip f g c) Q,A\"\n  by (rule GuaranteeAsGuard)\n\nlemma GuardsNil:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guards [] c) Q,A\"\n  by simp\n\n\n\nlemma GuardsConsGuaranteeStrip:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P guaranteeStrip f g (guards gs c) Q,A \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guards (guaranteeStripPair f g#gs) c) Q,A\"\n  by (simp add: guaranteeStripPair_def guaranteeStrip_def)\n\nlemma While:\n  assumes P_I: \"P \\<subseteq> I\"\n  assumes deriv_body: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (I \\<inter> b) c I,A\"\n  assumes I_Q: \"I \\<inter> -b \\<subseteq> Q\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnno b I V c) Q,A\"\nproof -\n  from deriv_body P_I I_Q\n  show ?thesis\n    apply (simp add: whileAnno_def)\n    apply (erule conseqPrePost [OF HoarePartialDef.While])\n    apply simp_all\n    done\nqed\n\ntext \\<open>@{term \"J\"} will be instantiated by tactic with @{term \"gs' \\<inter> I\"} for\n  those guards that are not stripped.\\<close>\nlemma  WhileAnnoG:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guards gs\n                    (whileAnno  b J V (Seq c (guards gs Skip)))) Q,A\n        \\<Longrightarrow>\n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnnoG gs b I V c) Q,A\"\n  by (simp add: whileAnnoG_def whileAnno_def while_def)\n\n\ntext \\<open>This form stems from @{term \"strip_guards F (whileAnnoG gs b I V c)\"}\\<close>\n\n\n\n\n\nlemma WhileAnnoFix':\nassumes consequence: \"P \\<subseteq> {s. (\\<exists> Z. s\\<in>I Z \\<and>\n                               (\\<forall>t. t \\<in> I Z \\<inter> -b \\<longrightarrow> t \\<in> Q)) }\"\nassumes bdy: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (I Z \\<inter> b) (c Z) (I Z),A\"\nassumes bdy_constant:  \"\\<forall>Z. c Z = c undefined\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnnoFix b I V c) Q,A\"\n  apply (rule WhileAnnoFix [OF _ bdy bdy_constant])\n  using consequence by blast\n\nlemma WhileAnnoGFix:\nassumes whileAnnoFix:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guards gs\n                (whileAnnoFix  b J V (\\<lambda>Z. (Seq (c Z) (guards gs Skip))))) Q,A\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnnoGFix gs b I V c) Q,A\"\n  using whileAnnoFix\n  by (simp add: whileAnnoGFix_def whileAnnoFix_def while_def)\n\nlemma Bind:\n  assumes adapt: \"P \\<subseteq> {s. s \\<in> P' s}\"\n  assumes c: \"\\<forall>s. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' s) (c (e s)) Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (bind e c) Q,A\"\napply (rule conseq [where P'=\"\\<lambda>Z. {s. s=Z \\<and> s \\<in> P' Z}\" and Q'=\"\\<lambda>Z. Q\" and\nA'=\"\\<lambda>Z. A\"])\napply  (rule allI)\napply  (unfold bind_def)\napply  (rule DynCom)\napply  (rule ballI)\napply  simp\napply  (rule conseqPre)\napply   (rule c [rule_format])\napply  blast\nusing adapt\napply blast\ndone\n\nlemma Block:\nassumes adapt: \"P \\<subseteq> {s. init s \\<in> P' s}\"\nassumes bdy: \"\\<forall>s. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' s) bdy {t. return s t \\<in> R s t},{t. return s t \\<in> A}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (block init bdy return c) Q,A\"\napply (rule conseq [where P'=\"\\<lambda>Z. {s. s=Z \\<and> init s \\<in> P' Z}\" and Q'=\"\\<lambda>Z. Q\" and\nA'=\"\\<lambda>Z. A\"])\nprefer 2\nusing adapt\napply  blast\napply (rule allI)\napply (unfold block_def)\napply (rule DynCom)\napply (rule ballI)\napply clarsimp\napply (rule_tac R=\"{t. return Z t \\<in> R Z t}\" in SeqSwap )\napply  (rule_tac  P'=\"\\<lambda>Z'. {t. t=Z' \\<and> return Z t \\<in> R Z t}\" and\n          Q'=\"\\<lambda>Z'. Q\" and A'=\"\\<lambda>Z'. A\" in conseq)\nprefer 2 apply simp\napply  (rule allI)\napply  (rule DynCom)\napply  (clarsimp)\napply  (rule SeqSwap)\napply   (rule c [rule_format])\napply  (rule Basic)\napply  clarsimp\napply (rule_tac R=\"{t. return Z t \\<in> A}\" in Catch)\napply  (rule_tac R=\"{i. i \\<in> P' Z}\" in Seq)\napply   (rule Basic)\napply   clarsimp\napply  simp\napply  (rule bdy [rule_format])\napply (rule SeqSwap)\napply  (rule Throw)\napply (rule Basic)\napply simp\ndone\n\n\nlemma BlockSwap:\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes bdy: \"\\<forall>s. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' s) bdy {t. return s t \\<in> R s t},{t. return s t \\<in> A}\"\nassumes adapt: \"P \\<subseteq> {s. init s \\<in> P' s}\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (block init bdy return c) Q,A\"\nusing adapt bdy c\n  by (rule Block)\n\n\nlemma BlockSpec:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' Z \\<and>\n                             (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t) \\<and>\n                             (\\<forall>t. t \\<in> A' Z \\<longrightarrow> return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes bdy: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) bdy (Q' Z),(A' Z)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (block init bdy return c) Q,A\"\napply (rule conseq [where P'=\"\\<lambda>Z. {s. init s \\<in> P' Z \\<and>\n                             (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t) \\<and>\n                             (\\<forall>t. t \\<in> A' Z \\<longrightarrow> return s t \\<in> A)}\" and Q'=\"\\<lambda>Z. Q\" and\nA'=\"\\<lambda>Z. A\"])\nprefer 2\nusing adapt\napply  blast\napply (rule allI)\napply (unfold block_def)\napply (rule DynCom)\napply (rule ballI)\napply clarsimp\napply (rule_tac R=\"{t. return s t \\<in> R s t}\" in SeqSwap )\napply  (rule_tac  P'=\"\\<lambda>Z'. {t. t=Z' \\<and> return s t \\<in> R s t}\" and\n          Q'=\"\\<lambda>Z'. Q\" and A'=\"\\<lambda>Z'. A\" in conseq)\nprefer 2 apply simp\napply  (rule allI)\napply  (rule DynCom)\napply  (clarsimp)\napply  (rule SeqSwap)\napply   (rule c [rule_format])\napply  (rule Basic)\napply  clarsimp\napply (rule_tac R=\"{t. return s t \\<in> A}\" in Catch)\napply  (rule_tac R=\"{i. i \\<in> P' Z}\" in Seq)\napply   (rule Basic)\napply   clarsimp\napply  simp\napply  (rule conseq [OF bdy])\napply  clarsimp\napply  blast\napply (rule SeqSwap)\napply  (rule Throw)\napply (rule Basic)\napply simp\ndone\n\nlemma Throw: \"P \\<subseteq> A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Throw Q,A\"\n  by (rule hoarep.Throw [THEN conseqPre])\n\nlemmas Catch = hoarep.Catch\nlemma CatchSwap: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,R\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Catch c\\<^sub>1 c\\<^sub>2 Q,A\"\n  by (rule hoarep.Catch)\n\nlemma raise: \"P \\<subseteq> {s. f s \\<in> A} \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P raise f Q,A\"\n  apply (simp add: raise_def)\n  apply (rule Seq)\n  apply  (rule Basic)\n  apply  (assumption)\n  apply (rule Throw)\n  apply (rule subset_refl)\n  done\n\nlemma condCatch: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,((b \\<inter> R) \\<union> (-b \\<inter> A));\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk>\n                  \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P condCatch c\\<^sub>1 b c\\<^sub>2 Q,A\"\n  apply (simp add: condCatch_def)\n  apply (rule Catch)\n  apply  assumption\n  apply (rule CondSwap)\n  apply   (assumption)\n  apply  (rule hoarep.Throw)\n  apply blast\n  done\n\nlemma condCatchSwap: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A;\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,((b \\<inter> R) \\<union> (-b \\<inter> A))\\<rbrakk>\n                  \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P condCatch c\\<^sub>1 b c\\<^sub>2 Q,A\"\n  by (rule condCatch)\n\n\nlemma ProcSpec:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' Z \\<and>\n                             (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t) \\<and>\n                             (\\<forall>t. t \\<in> A' Z \\<longrightarrow> return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) Call p (Q' Z),(A' Z)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nusing adapt c p\napply (unfold call_def)\nby (rule BlockSpec)\n\nlemma ProcSpec':\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' Z \\<and>\n                             (\\<forall>t \\<in> Q' Z. return s t \\<in> R s t) \\<and>\n                             (\\<forall>t \\<in> A' Z. return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) Call p (Q' Z),(A' Z)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule ProcSpec [OF _ c p])\napply (insert adapt)\napply clarsimp\napply (drule (1) subsetD)\napply (clarsimp)\napply (rule_tac x=Z in exI)\napply blast\ndone\n\nlemma ProcSpecNoAbrupt:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' Z \\<and>\n                             (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) Call p (Q' Z),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule ProcSpec [OF _ c p])\nusing adapt\napply simp\ndone\n\nlemma FCall:\n\"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return (\\<lambda>s t. c (result t))) Q,A\n\\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (fcall init p return result c) Q,A\"\n  by (simp add: fcall_def)\n\n\nlemma ProcRec:\n  assumes deriv_bodies:\n   \"\\<forall>p\\<in>Procs.\n    \\<forall>Z. \\<Gamma>,\\<Theta>\\<union>(\\<Union>p\\<in>Procs. \\<Union>Z. {(P p Z,p,Q p Z,A p Z)})\n        \\<turnstile>\\<^bsub>/F\\<^esub> (P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n  assumes Procs_defined: \"Procs \\<subseteq> dom \\<Gamma>\"\n  shows \"\\<forall>p\\<in>Procs. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>(P p Z) Call p (Q p Z),(A p Z)\"\n  by (intro strip)\n     (rule CallRec'\n     [OF _   Procs_defined deriv_bodies],\n     simp_all)\n\nlemma ProcRec':\n  assumes ctxt: \"\\<Theta>' = \\<Theta>\\<union>(\\<Union>p\\<in>Procs. \\<Union>Z. {(P p Z,p,Q p Z,A p Z)})\"\n  assumes deriv_bodies:\n   \"\\<forall>p\\<in>Procs. \\<forall>Z. \\<Gamma>,\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> (P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n  assumes Procs_defined: \"Procs \\<subseteq> dom \\<Gamma>\"\n  shows \"\\<forall>p\\<in>Procs. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>(P p Z) Call p (Q p Z),(A p Z)\"\n  using ctxt deriv_bodies\n  apply simp\n  apply (erule ProcRec [OF _ Procs_defined])\n  done\n\n\nlemma ProcRecList:\n  assumes deriv_bodies:\n   \"\\<forall>p\\<in>set Procs.\n    \\<forall>Z. \\<Gamma>,\\<Theta>\\<union>(\\<Union>p\\<in>set Procs. \\<Union>Z. {(P p Z,p,Q p Z,A p Z)})\n        \\<turnstile>\\<^bsub>/F\\<^esub> (P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n  assumes dist: \"distinct Procs\"\n  assumes Procs_defined: \"set Procs \\<subseteq> dom \\<Gamma>\"\n  shows \"\\<forall>p\\<in>set Procs. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>(P p Z) Call p (Q p Z),(A p Z)\"\n  using deriv_bodies Procs_defined\n  by (rule ProcRec)\n\nlemma  ProcRecSpecs:\n  \"\\<lbrakk>\\<forall>(P,p,Q,A) \\<in> Specs. \\<Gamma>,\\<Theta>\\<union>Specs\\<turnstile>\\<^bsub>/F\\<^esub> P (the (\\<Gamma> p)) Q,A;\n    \\<forall>(P,p,Q,A) \\<in> Specs. p \\<in> dom \\<Gamma>\\<rbrakk>\n  \\<Longrightarrow> \\<forall>(P,p,Q,A) \\<in> Specs. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\napply (auto intro: CallRec)\ndone\n\n\nlemma ProcRec1:\n  assumes deriv_body:\n   \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<union>(\\<Union>Z. {(P Z,p,Q Z,A Z)})\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) (the (\\<Gamma> p)) (Q Z),(A Z)\"\n  assumes p_defined: \"p \\<in> dom \\<Gamma>\"\n  shows \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) Call p (Q Z),(A Z)\"\nproof -\n  from deriv_body p_defined\n  have \"\\<forall>p\\<in>{p}. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) Call p (Q Z),(A Z)\"\n    by - (rule ProcRec [where A=\"\\<lambda>p. A\" and P=\"\\<lambda>p. P\" and Q=\"\\<lambda>p. Q\"],\n          simp_all)\n  thus ?thesis\n    by simp\nqed\n\nlemma ProcNoRec1:\n  assumes deriv_body:\n   \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) (the (\\<Gamma> p)) (Q Z),(A Z)\"\n  assumes p_def: \"p \\<in> dom \\<Gamma>\"\n  shows \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) Call p (Q Z),(A Z)\"\nproof -\nfrom deriv_body\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<union>(\\<Union>Z. {(P Z,p,Q Z,A Z)})\n             \\<turnstile>\\<^bsub>/F\\<^esub> (P Z) (the (\\<Gamma> p)) (Q Z),(A Z)\"\n    by (blast intro: hoare_augment_context)\n  from this p_def\n  show ?thesis\n    by (rule ProcRec1)\nqed\n\nlemma ProcBody:\n assumes WP: \"P \\<subseteq> P'\"\n assumes deriv_body: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' body Q,A\"\n assumes body: \"\\<Gamma> p = Some body\"\n shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Call p Q,A\"\napply (rule conseqPre [OF _ WP])\napply (rule ProcNoRec1 [rule_format, where P=\"\\<lambda>Z. P'\" and Q=\"\\<lambda>Z. Q\" and A=\"\\<lambda>Z. A\"])\napply  (insert body)\napply  simp\napply  (rule hoare_augment_context [OF deriv_body])\napply  blast\napply fastforce\ndone\n\nlemma CallBody:\nassumes adapt: \"P \\<subseteq> {s. init s \\<in> P' s}\"\nassumes bdy: \"\\<forall>s. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' s) body {t. return s t \\<in> R s t},{t. return s t \\<in> A}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes body: \"\\<Gamma> p = Some body\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (unfold call_def)\napply (rule Block [OF adapt _ c])\napply (rule allI)\napply (rule ProcBody [where \\<Gamma>=\\<Gamma>, OF _ bdy [rule_format] body])\napply simp\ndone\n\nlemmas ProcModifyReturn = HoarePartialProps.ProcModifyReturn\nlemmas ProcModifyReturnSameFaults = HoarePartialProps.ProcModifyReturnSameFaults\n\nlemma ProcModifyReturnNoAbr:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes result_conform:\n      \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:\n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} Call p (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nby (rule ProcModifyReturn [OF spec result_conform _ modifies_spec]) simp\n\nlemma ProcModifyReturnNoAbrSameFaults:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes result_conform:\n      \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:\n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call p (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nby (rule ProcModifyReturnSameFaults [OF spec result_conform _ modifies_spec]) simp\n\n\nlemma DynProc:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' s Z \\<and>\n                          (\\<forall>t. t \\<in> Q' s Z \\<longrightarrow>  return s t \\<in> R s t) \\<and>\n                          (\\<forall>t. t \\<in> A' s Z \\<longrightarrow> return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>s\\<in> P. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' s Z) Call (p s) (Q' s Z),(A' s Z)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P dynCall init p return c Q,A\"\napply (rule conseq [where P'=\"\\<lambda>Z. {s. s=Z \\<and> s \\<in> P}\"\n  and Q'=\"\\<lambda>Z. Q\" and A'=\"\\<lambda>Z. A\"])\nprefer 2\nusing adapt\napply  blast\napply (rule allI)\napply (unfold dynCall_def call_def block_def)\napply (rule DynCom)\napply clarsimp\napply (rule DynCom)\napply clarsimp\napply (frule in_mono [rule_format, OF adapt])\napply clarsimp\napply (rename_tac Z')\napply (rule_tac R=\"Q' Z Z'\" in Seq)\napply  (rule CatchSwap)\napply   (rule SeqSwap)\napply    (rule Throw)\napply    (rule subset_refl)\napply   (rule Basic)\napply   (rule subset_refl)\napply  (rule_tac R=\"{i. i \\<in> P' Z Z'}\" in Seq)\napply   (rule Basic)\napply   clarsimp\napply  simp\napply  (rule_tac Q'=\"Q' Z Z'\" and A'=\"A' Z Z'\" in conseqPost)\nusing p\napply    clarsimp\napply   simp\napply  clarsimp\napply  (rule_tac  P'=\"\\<lambda>Z''. {t. t=Z'' \\<and> return Z t \\<in> R Z t}\" and\n          Q'=\"\\<lambda>Z''. Q\" and A'=\"\\<lambda>Z''. A\" in conseq)\nprefer 2 apply simp\napply (rule allI)\napply (rule DynCom)\napply clarsimp\napply (rule SeqSwap)\napply  (rule c [rule_format])\napply (rule Basic)\napply clarsimp\ndone\n\nlemma DynProc':\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' s Z \\<and>\n                          (\\<forall>t \\<in> Q' s Z. return s t \\<in> R s t) \\<and>\n                          (\\<forall>t \\<in> A' s Z. return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>s\\<in> P. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' s Z) Call (p s) (Q' s Z),(A' s Z)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P dynCall init p return c Q,A\"\nproof -\n  from adapt have \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' s Z \\<and>\n                          (\\<forall>t. t \\<in> Q' s Z \\<longrightarrow>  return s t \\<in> R s t) \\<and>\n                          (\\<forall>t. t \\<in> A' s Z \\<longrightarrow> return s t \\<in> A)}\"\n    by blast\n  from this c p show ?thesis\n    by (rule DynProc)\nqed\n\n\nlemma DynProcStaticSpec:\nassumes adapt: \"P \\<subseteq> {s. s \\<in> S \\<and> (\\<exists>Z. init s \\<in> P' Z  \\<and>\n                            (\\<forall>\\<tau>. \\<tau> \\<in> Q' Z \\<longrightarrow> return s \\<tau> \\<in> R s \\<tau>) \\<and>\n                            (\\<forall>\\<tau>. \\<tau> \\<in> A' Z \\<longrightarrow> return s \\<tau> \\<in> A))}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes spec: \"\\<forall>s\\<in>S. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) Call (p s) (Q' Z),(A' Z)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from adapt have P_S: \"P \\<subseteq> S\"\n    by blast\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> S) (dynCall init p return c) Q,A\"\n    apply (rule DynProc [where P'=\"\\<lambda>s Z. P' Z\" and Q'=\"\\<lambda>s Z. Q' Z\"\n                         and A'=\"\\<lambda>s Z. A' Z\", OF _ c])\n    apply  clarsimp\n    apply  (frule in_mono [rule_format, OF adapt])\n    apply  clarsimp\n    using spec\n    apply clarsimp\n    done\n  thus ?thesis\n    by (rule conseqPre) (insert P_S,blast)\nqed\n\n\nlemma DynProcProcPar:\nassumes adapt: \"P \\<subseteq> {s. p s = q \\<and> (\\<exists>Z. init s \\<in> P' Z  \\<and>\n                            (\\<forall>\\<tau>. \\<tau> \\<in> Q' Z \\<longrightarrow> return s \\<tau> \\<in> R s \\<tau>) \\<and>\n                            (\\<forall>\\<tau>. \\<tau> \\<in> A' Z \\<longrightarrow> return s \\<tau> \\<in> A))}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) Call q (Q' Z),(A' Z)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\n  apply (rule DynProcStaticSpec [where S=\"{s. p s = q}\",simplified, OF adapt c])\n  using spec\n  apply simp\n  done\n\n\nlemma DynProcProcParNoAbrupt:\nassumes adapt: \"P \\<subseteq> {s. p s = q \\<and> (\\<exists>Z. init s \\<in> P' Z  \\<and>\n                            (\\<forall>\\<tau>. \\<tau> \\<in> Q' Z \\<longrightarrow> return s \\<tau> \\<in> R s \\<tau>))}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) Call q (Q' Z),{}\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  have \"P \\<subseteq> {s. p s = q \\<and> (\\<exists> Z. init s \\<in> P' Z \\<and>\n                      (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t) \\<and>\n                      (\\<forall>t. t \\<in> {} \\<longrightarrow> return s t \\<in> A))}\"\n    (is \"P \\<subseteq> ?P'\")\n  proof\n    fix s\n    assume P: \"s\\<in>P\"\n    with adapt obtain Z where\n      Pre: \"p s = q \\<and> init s \\<in> P' Z\" and\n      adapt_Norm: \"\\<forall>\\<tau>. \\<tau> \\<in> Q' Z \\<longrightarrow> return s \\<tau> \\<in> R s \\<tau>\"\n      by blast\n    from  adapt_Norm\n    have \"\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t\"\n      by auto\n    then\n    show \"s\\<in>?P'\"\n      using Pre by blast\n  qed\n  note P = this\n  show ?thesis\n    apply -\n    apply (rule DynProcStaticSpec [where S=\"{s. p s = q}\",simplified, OF P c])\n    apply (insert spec)\n    apply auto\n    done\nqed\n\n\nlemma DynProcModifyReturnNoAbr:\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s))\n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause:\n            \"\\<forall>s \\<in> P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} Call (p s)  (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from ret_nrm_modif\n  have \"\\<forall>s t. t  \\<in> (Modif (init s))\n        \\<longrightarrow> return' s t = return s t\"\n    by iprover\n  then\n  have ret_nrm_modif': \"\\<forall>s t. t \\<in> (Modif (init s))\n                      \\<longrightarrow> return' s t = return s t\"\n    by simp\n  have ret_abr_modif': \"\\<forall>s t. t \\<in> {}\n                        \\<longrightarrow> return' s t = return s t\"\n    by simp\n  from to_prove ret_nrm_modif' ret_abr_modif' modif_clause show ?thesis\n    by (rule dynProcModifyReturn)\nqed\n\n\nlemma ProcDynModifyReturnNoAbrSameFaults:\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s))\n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause:\n            \"\\<forall>s \\<in> P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} (Call (p s)) (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from ret_nrm_modif\n  have \"\\<forall>s t. t  \\<in> (Modif (init s))\n        \\<longrightarrow> return' s t = return s t\"\n    by iprover\n  then\n  have ret_nrm_modif': \"\\<forall>s t. t \\<in> (Modif (init s))\n                      \\<longrightarrow> return' s t = return s t\"\n    by simp\n  have ret_abr_modif': \"\\<forall>s t. t \\<in> {}\n                        \\<longrightarrow> return' s t = return s t\"\n    by simp\n  from to_prove ret_nrm_modif' ret_abr_modif' modif_clause show ?thesis\n    by (rule dynProcModifyReturnSameFaults)\nqed\n\n\nlemma ProcProcParModifyReturn:\n  assumes q: \"P \\<subseteq> {s. p s = q} \\<inter> P'\"\n   \\<comment> \\<open>@{thm[source] DynProcProcPar} introduces the same constraint as first conjunction in\n         @{term P'}, so the vcg can simplify it.\\<close>\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s))\n                            \\<longrightarrow> return' s t = return s t\"\n  assumes ret_abr_modif: \"\\<forall>s t. t \\<in> (ModifAbr (init s))\n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause:\n          \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call q) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from to_prove have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return' c) Q,A\"\n    by (rule conseqPre) blast\n  from this ret_nrm_modif\n       ret_abr_modif\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return c) Q,A\"\n    by (rule dynProcModifyReturn) (insert modif_clause,auto)\n  from this q show ?thesis\n    by (rule conseqPre)\nqed\n\n\nlemma ProcProcParModifyReturnSameFaults:\n  assumes q: \"P \\<subseteq> {s. p s = q} \\<inter> P'\"\n   \\<comment> \\<open>@{thm[source] DynProcProcPar} introduces the same constraint as first conjunction in\n         @{term P'}, so the vcg can simplify it.\\<close>\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s))\n                            \\<longrightarrow> return' s t = return s t\"\n  assumes ret_abr_modif: \"\\<forall>s t. t \\<in> (ModifAbr (init s))\n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause:\n          \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call q (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from to_prove\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return' c) Q,A\"\n    by (rule conseqPre) blast\n  from this ret_nrm_modif\n       ret_abr_modif\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return c) Q,A\"\n    by (rule dynProcModifyReturnSameFaults) (insert modif_clause,auto)\n  from this q show ?thesis\n    by (rule conseqPre)\nqed\n\n\nlemma ProcProcParModifyReturnNoAbr:\n  assumes q: \"P \\<subseteq> {s. p s = q} \\<inter> P'\"\n   \\<comment> \\<open>@{thm[source] DynProcProcParNoAbrupt} introduces the same constraint as\n      first conjunction in @{term P'}, so the vcg can simplify it.\\<close>\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s))\n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause:\n            \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call q) (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from to_prove have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return' c) Q,A\"\n    by (rule conseqPre) blast\n  from this ret_nrm_modif\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return c) Q,A\"\n    by (rule DynProcModifyReturnNoAbr) (insert modif_clause,auto)\n  from this q show ?thesis\n    by (rule conseqPre)\nqed\n\nlemma ProcProcParModifyReturnNoAbrSameFaults:\n  assumes q: \"P \\<subseteq> {s. p s = q} \\<inter> P'\"\n   \\<comment> \\<open>@{thm[source] DynProcProcParNoAbrupt} introduces the same constraint as\n      first conjunction in @{term P'}, so the vcg can simplify it.\\<close>\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s))\n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause:\n            \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} (Call q) (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from to_prove have\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return' c) Q,A\"\n    by (rule conseqPre) blast\n  from this ret_nrm_modif\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return c) Q,A\"\n    by (rule ProcDynModifyReturnNoAbrSameFaults) (insert modif_clause,auto)\n  from this q show ?thesis\n    by (rule conseqPre)\nqed\n\nlemma MergeGuards_iff: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P merge_guards c Q,A = \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (auto intro: MergeGuardsI MergeGuardsD)\n\nlemma CombineStrip':\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c' Q,A\"\n  assumes deriv_strip_triv: \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/{}\\<^esub> P c'' UNIV,UNIV\"\n  assumes c'': \"c''= mark_guards False (strip_guards (-F) c')\"\n  assumes c: \"merge_guards c = merge_guards (mark_guards False c')\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof -\n  from deriv_strip_triv have deriv_strip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c'' UNIV,UNIV\"\n    by (auto intro: hoare_augment_context)\n  from deriv_strip [simplified c'']\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P (strip_guards (- F) c') UNIV,UNIV\"\n    by (rule MarkGuardsD)\n  with deriv\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c' Q,A\"\n    by (rule CombineStrip)\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P mark_guards False c' Q,A\"\n    by (rule MarkGuardsI)\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P merge_guards (mark_guards False c') Q,A\"\n    by (rule MergeGuardsI)\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P merge_guards c Q,A\"\n    by (simp add: c)\n  thus ?thesis\n    by (rule MergeGuardsD)\nqed\n\nlemma CombineStrip'':\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{True}\\<^esub> P c' Q,A\"\n  assumes deriv_strip_triv: \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/{}\\<^esub> P c'' UNIV,UNIV\"\n  assumes c'': \"c''= mark_guards False (strip_guards ({False}) c')\"\n  assumes c: \"merge_guards c = merge_guards (mark_guards False c')\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c Q,A\"\n  apply (rule CombineStrip' [OF deriv deriv_strip_triv _ c])\n  apply (insert c'')\n  apply (subgoal_tac \"- {True} = {False}\")\n  apply auto\n  done\n\nlemma AsmUN:\n  \"(\\<Union>Z. {(P Z, p, Q Z,A Z)}) \\<subseteq> \\<Theta>\n  \\<Longrightarrow>\n  \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) (Call p) (Q Z),(A Z)\"\n  by (blast intro: hoarep.Asm)\n\nlemma augment_context':\n  \"\\<lbrakk>\\<Theta> \\<subseteq> \\<Theta>'; \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P Z)  p (Q Z),(A Z)\\<rbrakk>\n   \\<Longrightarrow> \\<forall>Z. \\<Gamma>,\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z)\"\n  by (iprover intro: hoare_augment_context)\n\n\nlemma hoarep_strip:\n \"\\<lbrakk>\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z); F' \\<subseteq> -F\\<rbrakk> \\<Longrightarrow>\n    \\<forall>Z. strip F' \\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z)\"\n  by (iprover intro: hoare_strip_\\<Gamma>)\n\nlemma augment_emptyFaults:\n \"\\<lbrakk>\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^bsub>/{}\\<^esub> (P Z) p (Q Z),(A Z)\\<rbrakk> \\<Longrightarrow>\n    \\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z)\"\n  by (blast intro: augment_Faults)\n\nlemma augment_FaultsUNIV:\n \"\\<lbrakk>\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z)\\<rbrakk> \\<Longrightarrow>\n    \\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^bsub>/UNIV\\<^esub> (P Z) p (Q Z),(A Z)\"\n  by (blast intro: augment_Faults)\n\nlemma PostConjI [trans]:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c R,B\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\n  by (rule PostConjI)\n\nlemma PostConjI' :\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c R,B\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\n  by (rule PostConjI) iprover+\n\nlemma PostConjE [consumes 1]:\n  assumes conj: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\n  assumes E: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c R,B\\<rbrakk> \\<Longrightarrow> S\"\n  shows \"S\"\nproof -\n  from conj have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\" by (rule conseqPost) blast+\n  moreover\n  from conj have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c R,B\" by (rule conseqPost) blast+\n  ultimately show \"S\"\n    by (rule E)\nqed\n\n\nsubsection \\<open>Rules for Single-Step Proof \\label{sec:hoare-isar}\\<close>\n\ntext \\<open>\n We are now ready to introduce a set of Hoare rules to be used in\n single-step structured proofs in Isabelle/Isar.\n\n \\medskip Assertions of Hoare Logic may be manipulated in\n calculational proofs, with the inclusion expressed in terms of sets\n or predicates.  Reversed order is supported as well.\n\\<close>\n\nlemma annotateI [trans]:\n\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P anno Q,A; c = anno\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P c Q,A\"\n  by simp\n\nlemma annotate_normI:\n  assumes deriv_anno: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P anno Q,A\"\n  assumes norm_eq: \"normalize c = normalize anno\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P c Q,A\"\nproof -\n  from NormalizeI [OF deriv_anno] norm_eq\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P normalize c Q,A\"\n    by simp\n  from NormalizeD [OF this]\n  show ?thesis .\nqed\n\nlemma annotateWhile:\n\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnnoG gs b I V c) Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (while gs b c) Q,A\"\n  by (simp add: whileAnnoG_def)\n\n\nlemma reannotateWhile:\n\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnnoG gs b I V c) Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnnoG gs b J V c) Q,A\"\n  by (simp add: whileAnnoG_def)\n\nlemma reannotateWhileNoGuard:\n\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnno b I V c) Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnno b J V c) Q,A\"\n  by (simp add: whileAnno_def)\n\nlemma [trans] : \"P' \\<subseteq> P \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' c Q,A\"\n  by (rule conseqPre)\n\nlemma [trans]: \"Q \\<subseteq> Q' \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q',A\"\n  by (rule conseqPost) blast+\n\nlemma [trans]:\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s} c Q,A \\<Longrightarrow> (\\<And>s. P' s \\<longrightarrow> P s) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P' s} c Q,A\"\n  by (rule conseqPre) auto\n\nlemma [trans]:\n    \"(\\<And>s. P' s \\<longrightarrow> P s) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s} c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P' s} c Q,A\"\n  by (rule conseqPre) auto\n\nlemma [trans]:\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P c {s. Q s},A \\<Longrightarrow> (\\<And>s. Q s \\<longrightarrow> Q' s) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P c {s. Q' s},A\"\n  by (rule conseqPost) auto\n\nlemma [trans]:\n    \"(\\<And>s. Q s \\<longrightarrow> Q' s) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P c {s. Q s},A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P c {s. Q' s},A\"\n  by (rule conseqPost) auto\n\nlemma [intro?]: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Skip P,A\"\n  by (rule Skip) auto\n\nlemma CondInt [trans,intro?]:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> b) c1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> - b) c2 Q,A\\<rbrakk>\n   \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c1 c2) Q,A\"\n  by (rule Cond) auto\n\nlemma CondConj [trans, intro?]:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s \\<and> b s} c1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s \\<and> \\<not> b s} c2 Q,A\\<rbrakk>\n   \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s} (Cond {s. b s} c1 c2) Q,A\"\n  by (rule Cond) auto\n\nlemma WhileInvInt [intro?]:\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> b) c P,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnno b P V c) (P \\<inter> -b),A\"\n  by (rule While) auto\n\nlemma WhileInt [intro?]:\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> b) c P,A\n    \\<Longrightarrow>\n    \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnno b {s. undefined} V c) (P \\<inter> -b),A\"\n  by (unfold whileAnno_def)\n     (rule HoarePartialDef.While [THEN conseqPrePost],auto)\n\nlemma WhileInvConj [intro?]:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s \\<and> b s} c {s. P s},A\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s} (whileAnno {s. b s} {s. P s} V c) {s. P s \\<and> \\<not> b s},A\"\n  by (simp add: While Collect_conj_eq Collect_neg_eq)\n\nlemma WhileConj [intro?]:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s \\<and> b s} c {s. P s},A\n    \\<Longrightarrow>\n\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s} (whileAnno {s. b s} {s. undefined} V c) {s. P s \\<and> \\<not> b s},A\"\n  by (unfold whileAnno_def)\n     (simp add: HoarePartialDef.While [THEN conseqPrePost]\n      Collect_conj_eq Collect_neg_eq)\n\n(* FIXME: Add rules for guarded while *)\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/c-parser/Simpl/HoarePartial.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621765008857981, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.267921880628352}}
{"text": "(* Title: Examples/Vector_Spaces/VS_Prerequisites.thy\n   Author: Mihails Milehins\n   Copyright 2021 (C) Mihails Milehins\n*)\nchapter\\<open>TTS Vector Spaces\\<close>\ntheory VS_Prerequisites\n  imports Types_To_Sets_Extension.ETTS_Auxiliary\nbegin\n\n\n\n\nsection\\<open>Introduction\\<close>\n\n\n\nsubsection\\<open>Background\\<close>\n\n\ntext\\<open>\nThe content of this chapter is an adoption of the applied relativization\nstudy presented in \\<^cite>\\<open>\"immler_smooth_2019\"\\<close> to the ETTS. \nThe content of this chapter incorporates \nmany elements of the content of the aforementioned relativization study without \nan explicit reference. Nonetheless, no attempt was made to ensure that\nthe theorems obtained as a result of this work are identical to the theorems \nobtained in \\<^cite>\\<open>\"immler_smooth_2019\"\\<close>. \n\\<close>\n\n\n\nsubsection\\<open>Prerequisites\\<close>\n\nctr parametricity\n  in bij_betw_ow: bij_betw_def\n\nlemma bij_betw_parametric'[transfer_rule]:\n  includes lifting_syntax\n  assumes \"bi_unique A\"\n  shows \"((A ===> A) ===> rel_set A ===> rel_set A ===> (=)) \n    bij_betw bij_betw\"\n  by (rule bij_betw_ow.transfer[OF assms assms])\n\nlemma vimage_transfer[transfer_rule]: \n  includes lifting_syntax\n  assumes [transfer_rule]: \"bi_unique B\" \"right_total A\" \n  shows \n    \"((A ===> B) ===> (rel_set B) ===> rel_set A) \n      (\\<lambda>f s. (vimage f s) \\<inter> (Collect (Domainp A))) (-`)\"\n  by transfer_prover\n\nlemma Eps_unique_transfer_lemma:\n  includes lifting_syntax\n  assumes [transfer_rule]: \n    \"right_total A\" \"(A ===> (=)) f g\" \"(A ===> (=)) f' g'\"\n    and holds: \"\\<exists>x. Domainp A x \\<and> f x\"\n    and unique_g: \"\\<And>x y. \\<lbrakk> g x; g y \\<rbrakk> \\<Longrightarrow> g' x = g' y\"\n  shows \"f' (Eps (\\<lambda>x. Domainp A x \\<and> f x)) = g' (Eps g)\"\nproof -\n  define Epsg where \"Epsg = Eps g\"\n  have \"\\<exists>x. g x\" by transfer (simp add: holds)\n  then have \"g Epsg\" unfolding Epsg_def by (rule someI_ex)\n  obtain x where x[transfer_rule]: \"A x Epsg\" \n    by (meson \\<open>right_total A\\<close> right_totalE)\n  then have \"Domainp A x\" by auto\n  from \\<open>g Epsg\\<close>[untransferred] have \"f x\" .\n  from unique_g have unique:\n    \"\\<And>x y. \\<lbrakk> Domainp A x; Domainp A y; f x; f y \\<rbrakk> \\<Longrightarrow> f' x = f' y\"\n    by transfer\n  have \"f' (Eps (\\<lambda>x. Domainp A x \\<and> f x)) = f' x\"\n    by (rule unique[OF _ \\<open>Domainp A x\\<close> _ \\<open>f x\\<close>]) \n      (metis (mono_tags, lifting) local.holds someI_ex)+\n  show \"f' (SOME x. Domainp A x \\<and> f x) = g' (Eps g)\"\n    using x \\<open>f' (Eps _) = f' x\\<close> Epsg_def rel_funE assms(3) by fastforce\nqed\n\ntext\\<open>\\newpage\\<close>\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Types_To_Sets_Extension/Examples/Vector_Spaces/VS_Prerequisites.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5156199157230157, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.2678755402412479}}
{"text": "section Parser\ntheory IpRoute_Parser\nimports Routing_Table \n  IP_Addresses.IP_Address_Parser\nkeywords \"parse_ip_route\" \"parse_ip_6_route\" :: thy_decl\nbegin\ntext\\<open>This helps to read the output of the \\texttt{ip route} command into a @{typ \"32 routing_rule list\"}.\\<close>\n\ndefinition empty_rr_hlp :: \"('a::len) prefix_match \\<Rightarrow> 'a routing_rule\" where\n  \"empty_rr_hlp pm = routing_rule.make pm default_metric (routing_action.make '''' None)\"\n\nlemma empty_rr_hlp_alt:\n  \"empty_rr_hlp pm = \\<lparr> routing_match = pm, metric = 0, routing_action = \\<lparr>output_iface = [], next_hop = None\\<rparr>\\<rparr>\"\n  unfolding empty_rr_hlp_def routing_rule.defs default_metric_def routing_action.defs ..\n\ndefinition routing_action_next_hop_update :: \"'a word \\<Rightarrow> 'a routing_rule \\<Rightarrow> ('a::len) routing_rule\"\n  where\n  \"routing_action_next_hop_update h pk = pk\\<lparr> routing_action := (routing_action pk)\\<lparr> next_hop := Some h\\<rparr> \\<rparr>\"\nlemma \"routing_action_next_hop_update h pk = routing_action_update (next_hop_update (\\<lambda>_. (Some h))) (pk::32 routing_rule)\"\n  by(simp add: routing_action_next_hop_update_def)\n\ndefinition routing_action_oiface_update :: \"string \\<Rightarrow> 'a routing_rule \\<Rightarrow> ('a::len) routing_rule\"\n  where\n  \"routing_action_oiface_update h pk = routing_action_update (output_iface_update (\\<lambda>_. h)) (pk::'a routing_rule)\"\nlemma \"routing_action_oiface_update h pk = pk\\<lparr> routing_action := (routing_action pk)\\<lparr> output_iface :=  h\\<rparr> \\<rparr>\"\n  by(simp add: routing_action_oiface_update_def)\n\n(* Could be moved to Bitmagic *)\ndefinition \"default_prefix = PrefixMatch 0 0\"\nlemma default_prefix_matchall: \"prefix_match_semantics default_prefix ip\"\n  unfolding default_prefix_def by (simp add: valid_prefix_00 zero_prefix_match_all)\n\ndefinition \"sanity_ip_route (r::('a::len) prefix_routing) \\<equiv> correct_routing r \\<and> unambiguous_routing r \\<and> list_all ((\\<noteq>) '''' \\<circ> routing_oiface) r\"\ntext\\<open>The parser ensures that @{const sanity_ip_route} holds for any ruleset that is imported.\\<close>\n\n(* Hide all the ugly ml in a file with the right extension *)\n(*Depends on the function parser_ipv4 from IP_Address_Parser*)\nML_file \\<open>IpRoute_Parser.ml\\<close>\n                  \nML\\<open>\n  Outer_Syntax.local_theory @{command_keyword parse_ip_route}\n  \"Load a file generated by ip route and make the routing table definition available as isabelle term\"\n  (Parse.binding --| @{keyword \"=\"} -- Parse.string >> register_ip_route 32)\n\\<close>\n\nML\\<open>\n  Outer_Syntax.local_theory @{command_keyword parse_ip_6_route}\n  \"Load a file generated by ip -6 route and make the routing table definition available as isabelle term\"\n  (Parse.binding --| @{keyword \"=\"} -- Parse.string >> register_ip_route 128)\n\\<close>\n\nparse_ip_route \"rtbl_parser_test1\" = \"ip-route-ex\"\nlemma  \"sanity_ip_route rtbl_parser_test1\" by eval (* checked by parse_ip_route alread *)\n\nlemma \"rtbl_parser_test1 =\n  [\\<lparr>routing_match = PrefixMatch 0xFFFFFF00 32, metric = 0, routing_action = \\<lparr>output_iface = ''tun0'', next_hop = None\\<rparr>\\<rparr>,\n  \\<lparr>routing_match = PrefixMatch 0xA0D2AA0 28, metric = 303, routing_action = \\<lparr>output_iface = ''ewlan'', next_hop = None\\<rparr>\\<rparr>,\n  \\<lparr>routing_match = PrefixMatch 0xA0D2500 24, metric = 0, routing_action = \\<lparr>output_iface = ''tun0'', next_hop = Some 0xFFFFFF00\\<rparr>\\<rparr>,\n  \\<lparr>routing_match = PrefixMatch 0xA0D2C00 24, metric = 0, routing_action = \\<lparr>output_iface = ''tun0'', next_hop = Some 0xFFFFFF00\\<rparr>\\<rparr>,\n  \\<lparr>routing_match = PrefixMatch 0 0, metric = 303, routing_action = \\<lparr>output_iface = ''ewlan'', next_hop = Some 0xA0D2AA1\\<rparr>\\<rparr>]\"\nby eval\n\nparse_ip_6_route \"rtbl_parser_test2\" = \"ip-6-route-ex\"\nvalue[code] rtbl_parser_test2\nlemma  \"sanity_ip_route rtbl_parser_test2\" by eval\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Routing/IpRoute_Parser.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.523420348936324, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.2678428837907652}}
{"text": "(*  Title:      HOL/Auth/n_mutualExOnI_lemma_inv__2_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mutualExOnI Protocol Case Study*} \n\ntheory n_mutualExOnI_lemma_inv__2_on_rules imports n_mutualExOnI_lemma_on_inv__2\nbegin\nsection{*All lemmas on causal relation between inv__2*}\nlemma lemma_inv__2_on_rules:\n  assumes b1: \"r \\<in> rules N\" and b2: \"(\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__2  p__Inv0 p__Inv1)\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have c1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n  apply (cut_tac b1, auto) done\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_TryVsinv__2) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_CritVsinv__2) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_ExitVsinv__2) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_IdleVsinv__2) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "lyj238Gmail", "repo": "newParaVerifier", "sha": "5c2d49bf8e6c46c60efa53c98b0ba5c577d59618", "save_path": "github-repos/isabelle/lyj238Gmail-newParaVerifier", "path": "github-repos/isabelle/lyj238Gmail-newParaVerifier/newParaVerifier-5c2d49bf8e6c46c60efa53c98b0ba5c577d59618/examples/n_mutualExOnI/n_mutualExOnI_lemma_inv__2_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7025300698514777, "lm_q2_score": 0.38121956625614994, "lm_q1q2_score": 0.26781820851068305}}
{"text": "section \\<open>Introduction\\<close>\n(*<*) \ntheory Lam_ml\nimports \"HOL-Nominal.Nominal\" \"HOL-Library.LaTeXsugar\"\nbegin (*>*)\ntext_raw \\<open>\\label{chap:formal}\\<close>\n\ntext \\<open>This article contains a formalization of the strong normalization\ntheorem for the $\\lambda_{ml}$-calculus. The formalization is based on a proof\nby Lindley and Stark \\cite{TT-lifting}. An informal description of the\nformalization can be found in \\cite{Doczkal:09}.\n\nThis formalization extends the example proof of strong normalization for the\nsimply-typed $\\lambda$-calculus, which is included in the Isabelle distribution\n\\cite{SN.thy}. The parts of the original proof which have been left unchanged\nare not displayed in this document.\n\nThe next section deals with the formalization of syntax, typing, and\nsubstitution. Section~\\ref{sec:reduction} contains the formalization of the\nreduction relation. Section~\\ref{sec:stacks} defines stacks which are used to\ndefine the reducibility relation in Section~\\ref{sec:reducibility-formal}. The\nfollowing sections contain proofs about the reducibility relation, ending with\nthe normalization theorem in Section~\\ref{sec:FTLR}.\\<close>\n\nsection \\<open>The Calculus\\<close>\ntext_raw \\<open>\\label{sec:calc}\\<close>\n\natom_decl name\n\nnominal_datatype trm = \n    Var \"name\" \n  | App \"trm\" \"trm\"\n  | Lam \"\\<guillemotleft>name\\<guillemotright>trm\"      (\"\\<Lambda> _ . _\" [0,120] 120)\n  | To \"trm\" \"\\<guillemotleft>name\\<guillemotright>trm\" (\"_ to _ in _\" [141,0,140] 140) \n  | Ret \"trm\" (\"[_]\")\n\n\ndeclare trm.inject[simp]\nlemmas name_swap_bij = pt_swap_bij''[OF pt_name_inst at_name_inst]\nlemmas ex_fresh = exists_fresh'[OF fin_supp]\n\nlemma alpha'' :\n  fixes x y :: name and t::trm\n  assumes a: \"x \\<sharp> t\"\n  shows \"[y].t = [x].([(y,x)] \\<bullet> t)\"\nproof -\n  from a have aux: \"y \\<sharp> [(y, x)] \\<bullet> t\"\n    by (subst fresh_bij[THEN sym, of _ _ \"[(x,y)]\"]) \n        (auto simp add: perm_swap calc_atm)\n  thus ?thesis  \n    by(auto simp add: alpha perm_swap name_swap_bij fresh_bij)\nqed\n\ntext \\<open>Even though our types do not involve binders, we still need to formalize\nthem as nominal datatypes to obtain a permutation action. This is required to\nestablish equivariance of the typing relation.\\<close>\n\nnominal_datatype ty =\n    TBase\n  | TFun \"ty\" \"ty\" (infix \"\\<rightarrow>\" 200)\n  | T \"ty\" \n\ntext\\<open>Since we cannot use typed variables, we have to formalize typing\ncontexts. Typing contexts are formalized as lists. A context is \\textit{valid}\nif no name occurs twice.\\<close>\n\ninductive \n  valid :: \"(name\\<times>ty) list \\<Rightarrow> bool\"\nwhere\n  v1[intro]: \"valid []\"\n| v2[intro]: \"\\<lbrakk>valid \\<Gamma>;x\\<sharp>\\<Gamma>\\<rbrakk>\\<Longrightarrow> valid ((x,\\<sigma>)#\\<Gamma>)\"\nequivariance valid \n\nlemma fresh_ty: \n  fixes x :: name and \\<tau>::ty\n  shows \"x \\<sharp> \\<tau>\"\nby (induct \\<tau> rule: ty.induct) (auto)\n\nlemma fresh_context: \n  fixes  \\<Gamma> :: \"(name\\<times>ty)list\"\n  assumes a: \"x \\<sharp> \\<Gamma>\"\n  shows \"\\<not>(\\<exists> \\<tau> . (x,\\<tau>)\\<in>set \\<Gamma>)\"\nusing a\nby (induct \\<Gamma>) (auto simp add: fresh_prod fresh_list_cons fresh_atm)\n\ninductive \n  typing :: \"(name\\<times>ty) list\\<Rightarrow>trm\\<Rightarrow>ty\\<Rightarrow>bool\" (\"_ \\<turnstile> _ : _\" [60,60,60] 60)\nwhere\n  t1[intro]: \"\\<lbrakk>valid \\<Gamma>; (x,\\<tau>)\\<in>set \\<Gamma>\\<rbrakk> \\<Longrightarrow> \\<Gamma> \\<turnstile> Var x : \\<tau>\"\n| t2[intro]: \"\\<lbrakk>\\<Gamma> \\<turnstile> s : \\<tau>\\<rightarrow>\\<sigma>; \\<Gamma> \\<turnstile> t : \\<tau>\\<rbrakk> \\<Longrightarrow> \\<Gamma> \\<turnstile> App s t : \\<sigma>\"\n| t3[intro]: \"\\<lbrakk>x \\<sharp> \\<Gamma>; ((x,\\<tau>)#\\<Gamma>) \\<turnstile> t : \\<sigma>\\<rbrakk> \\<Longrightarrow> \\<Gamma> \\<turnstile> \\<Lambda> x . t : \\<tau>\\<rightarrow>\\<sigma>\" \n| t4[intro]: \"\\<lbrakk> \\<Gamma> \\<turnstile> s : \\<sigma> \\<rbrakk> \\<Longrightarrow> \\<Gamma> \\<turnstile> [s] : T \\<sigma>\" \n| t5[intro]: \"\\<lbrakk>x \\<sharp> (\\<Gamma>,s); \\<Gamma> \\<turnstile> s : T \\<sigma> ; ((x,\\<sigma>)#\\<Gamma>) \\<turnstile> t : T \\<tau> \\<rbrakk> \n                \\<Longrightarrow> \\<Gamma> \\<turnstile> s to x in t : T \\<tau>\" \nequivariance typing\nnominal_inductive typing \n  by(simp_all add: abs_fresh fresh_ty)\n\ntext \\<open>Except for the explicit requirement that contexts be valid in the\nvariable case and the freshness requirements in \\isa{t3} and \\isa{t5}, this\ntyping\nrelation is a direct translation of the original typing relation in\n\\cite{TT-lifting} to Curry-style typing.\\<close>\n\nfun\n  lookup :: \"(name\\<times>trm) list \\<Rightarrow> name \\<Rightarrow> trm\"   \nwhere\n  \"lookup [] x        = Var x\"\n| \"lookup ((y,e)#\\<theta>) x = (if x=y then e else lookup \\<theta> x)\"\n\nlemma lookup_eqvt[eqvt]:\n  fixes pi::\"name prm\"\n  and   \\<theta>::\"(name\\<times>trm) list\"\n  and   x::\"name\"\n  shows \"pi \\<bullet> (lookup \\<theta> x) = lookup (pi \\<bullet> \\<theta>) (pi \\<bullet> x)\"\nby (induct \\<theta>) (auto simp add: eqvts)\n\nnominal_primrec\n  psubst :: \"(name\\<times>trm) list \\<Rightarrow> trm \\<Rightarrow> trm\"  (\"_<_>\" [95,95] 205)\nwhere \n    \"\\<theta><Var x> = lookup \\<theta> x\"\n  | \"\\<theta><App s t> = App (\\<theta><s>) (\\<theta><t>)\"\n  | \"x \\<sharp> \\<theta> \\<Longrightarrow> \\<theta><\\<Lambda> x .s> = \\<Lambda> x . (\\<theta><s>)\"\n  | \"\\<theta><[t]> = [\\<theta><t>]\"\n  | \"\\<lbrakk> x \\<sharp> \\<theta> ; x \\<sharp> t \\<rbrakk> \\<Longrightarrow> \\<theta><t to x in s> = (\\<theta><t>) to x in (\\<theta><s>)\"\nby(finite_guess+ , (simp add: abs_fresh)+ , fresh_guess+)\n\nlemma psubst_eqvt[eqvt]:\n  fixes pi::\"name prm\"\n  shows \"pi \\<bullet> (\\<theta><t>) = (pi \\<bullet> \\<theta>)<(pi \\<bullet> t)>\"\nby(nominal_induct t avoiding: \\<theta> rule:trm.strong_induct)\n  (auto simp add: eqvts fresh_bij)\n\nabbreviation \n  subst :: \"trm \\<Rightarrow> name \\<Rightarrow> trm \\<Rightarrow> trm\" (\"_[_::=_]\" [200,100,100] 200)\nwhere \n  \"t[x::=t']  \\<equiv> ([(x,t')])<t>\"\n\nlemma subst[simp]:\nshows \"(Var x)[y::=v] = (if x = y then v else Var x)\"\n  and \"(App s t)[y::=v] = App (s[y::=v]) (t[y::=v])\"\n  and \"x \\<sharp> (y,v) \\<Longrightarrow> (\\<Lambda> x . t)[y::=v] = \\<Lambda> x .t[y::=v]\"\n  and \"x \\<sharp> (s,y,v) \\<Longrightarrow> (s to x in t)[y::=v] = s[y::=v] to x in t[y::=v]\"\n  and \"([s])[y::=v] = [s[y::=v]]\"\nby(simp_all add: fresh_list_cons fresh_list_nil)\n\nlemma subst_rename: \n  assumes a: \"y \\<sharp> t\"\n  shows \"([(y,x)]\\<bullet>t)[y::=v] = t[x::=v]\"\nusing a\nby(nominal_induct t avoiding: x y v rule: trm.strong_induct)\n    (auto simp add: calc_atm fresh_atm abs_fresh fresh_prod fresh_aux)\nlemmas subst_rename' = subst_rename[THEN sym]\n\nlemma forget: \"x \\<sharp> t \\<Longrightarrow> t[x::=v] = t\"\nby(nominal_induct t avoiding: x v rule: trm.strong_induct)\n    (auto simp add: abs_fresh fresh_atm)\n\nlemma fresh_fact: \n  fixes x::\"name\"\n  assumes x: \"x \\<sharp> v\"   \"x \\<sharp> t\"\n  shows \"x \\<sharp> t[y::=v]\"\nusing x\nby(nominal_induct t avoiding: x y v rule: trm.strong_induct)\n    (auto simp add: abs_fresh fresh_atm)\n\nlemma fresh_fact': \n  fixes x::\"name\"\n  assumes x: \"x \\<sharp> v\"\n  shows \"x \\<sharp> t[x::=v]\"\nusing x\nby(nominal_induct t avoiding: x v rule: trm.strong_induct)\n    (auto simp add: abs_fresh fresh_atm)\n\nlemma subst_lemma:  \n  assumes a: \"x\\<noteq>y\"\n  and     b: \"x \\<sharp> u\"\n  shows \"s[x::=v][y::=u] = s[y::=u][x::=v[y::=u]]\"\nusing a b\nby(nominal_induct s avoiding: x y u v rule: trm.strong_induct)\n    (auto simp add: fresh_fact forget)\n\nlemma id_subs: \n  shows \"t[x::=Var x] = t\"\nby(nominal_induct t avoiding: x rule:trm.strong_induct) auto\n\ntext \\<open>In addition to the facts on simple substitution we also need some facts\non parallel substitution. In particular we want to be able to extend a parallel\nsubstitution with a simple one.\\<close>\n\nlemma lookup_fresh:\n  fixes z::\"name\"\n  assumes \"z\\<sharp>\\<theta>\"   \"z\\<sharp>x\"\n  shows \"z\\<sharp> lookup \\<theta> x\"\nusing assms \nby(induct rule: lookup.induct) \n  (auto simp add: fresh_list_cons)\n\nlemma lookup_fresh':\n  assumes a: \"z\\<sharp>\\<theta>\"\n  shows \"lookup \\<theta> z = Var z\"\nusing a\nby (induct rule: lookup.induct)\n   (auto simp add: fresh_list_cons fresh_prod fresh_atm)\n\nlemma psubst_fresh_fact:\n  fixes x :: name\n  assumes a: \"x \\<sharp> t\" and b: \"x \\<sharp> \\<theta>\" \n  shows \"x \\<sharp> \\<theta><t>\"\nusing a b\nby(nominal_induct t avoiding: \\<theta> x rule:trm.strong_induct) \n    (auto simp add: lookup_fresh abs_fresh)\n\nlemma psubst_subst:\n  assumes a: \"x \\<sharp> \\<theta>\"\n  shows \"\\<theta><t>[x::=s] = ((x,s)#\\<theta>)<t>\"\n  using a\nby(nominal_induct t avoiding: \\<theta> x s rule: trm.strong_induct)\n    (auto simp add: fresh_list_cons fresh_atm forget \n      lookup_fresh lookup_fresh' fresh_prod psubst_fresh_fact)\n\nsection \\<open>The Reduction Relation\\<close>\ntext_raw \\<open>\\label{sec:reduction}\\<close>\n\ntext \\<open>With substitution in place, we can now define the reduction relation on\n$\\lambda_{ml}$-terms. To derive strong induction and case rules, all the rules\nmust be vc-compatible (cf. \\cite{nominal-techniques}). This requires some\nadditional freshness conditions. Note that in this particular case the\nadditional freshness conditions only serve the technical purpose of\nautomatically deriving strong reasoning principles. To show that the version\nwith freshness conditions defines the same relation as the one without the\nfreshness conditions, we also state this version and prove equality of the two\nrelations. \n\nThis requires quite some effort and is something that is certainly undesirable\nin nominal reasoning. Unfortunately, handling the reduction rule \\isa{r10} which\nrearranges the binding structure, appeared to be impossible without going\nthrough this.\\<close>\n\n\ninductive std_reduction :: \"trm \\<Rightarrow> trm \\<Rightarrow> bool\" (\"_ \\<leadsto> _\" [80,80] 80)\nwhere\n  std_r1[intro!]:\"s \\<leadsto> s' \\<Longrightarrow> App s t \\<leadsto> App s' t\"\n| std_r2[intro!]:\"t \\<leadsto> t' \\<Longrightarrow> App s t \\<leadsto> App s t'\"\n| std_r3[intro!]:\"App (\\<Lambda> x . t) s \\<leadsto> t[x::=s]\"\n\n| std_r4[intro!]:\"t \\<leadsto> t' \\<Longrightarrow> \\<Lambda> x . t \\<leadsto> \\<Lambda> x . t'\"\n| std_r5[intro!]:\"x \\<sharp> t \\<Longrightarrow> \\<Lambda> x . App t (Var x) \\<leadsto> t\"\n\n| std_r6[intro!]:\"\\<lbrakk> s \\<leadsto> s' \\<rbrakk> \\<Longrightarrow> s to x in t \\<leadsto> s' to x in t\"\n| std_r7[intro!]:\"\\<lbrakk> t \\<leadsto> t' \\<rbrakk> \\<Longrightarrow> s to x in t \\<leadsto> s  to x in t'\"\n| std_r8[intro!]:\"[s] to x in t \\<leadsto> t[x::=s]\"\n| std_r9[intro!]:\"x \\<sharp> s \\<Longrightarrow> s to x in [Var x] \\<leadsto> s\"\n| std_r10[intro!]: \"\\<lbrakk> x \\<sharp> y; x \\<sharp> u\\<rbrakk> \n                     \\<Longrightarrow> (s to x in t) to y in u \\<leadsto> s to x in (t to y in u)\"\n| std_r11[intro!]: \"s \\<leadsto> s' \\<Longrightarrow> [s] \\<leadsto> [s']\"\n\ninductive \n  reduction :: \"trm \\<Rightarrow> trm \\<Rightarrow> bool\" (\"_ \\<mapsto> _\" [80,80] 80)\nwhere\n  r1[intro!]:\"s \\<mapsto> s' \\<Longrightarrow> App s t \\<mapsto> App s' t\"\n| r2[intro!]:\"t \\<mapsto> t' \\<Longrightarrow> App s t \\<mapsto> App s t'\"\n| r3[intro!]:\"x \\<sharp> s \\<Longrightarrow> App (\\<Lambda> x . t) s \\<mapsto> t[x::=s]\"\n\n| r4[intro!]:\"t \\<mapsto> t' \\<Longrightarrow> \\<Lambda> x . t \\<mapsto> \\<Lambda> x . t'\"\n| r5[intro!]:\"x \\<sharp> t \\<Longrightarrow> \\<Lambda> x . App t (Var x) \\<mapsto> t\"\n\n| r6[intro!]:\"\\<lbrakk> x \\<sharp> (s,s') ; s \\<mapsto> s' \\<rbrakk> \\<Longrightarrow> s to x in t \\<mapsto> s' to x in t\"\n| r7[intro!]:\"\\<lbrakk> x \\<sharp> s ; t \\<mapsto> t' \\<rbrakk> \\<Longrightarrow> s to x in t \\<mapsto> s  to x in t'\"\n| r8[intro!]:\"x \\<sharp> s \\<Longrightarrow> [s] to x in t \\<mapsto> t[x::=s]\"\n| r9[intro!]:\"x \\<sharp> s \\<Longrightarrow> s to x in [Var x] \\<mapsto> s\"\n| r10[intro!]: \"\\<lbrakk> x \\<sharp> (y,s,u) ; y \\<sharp> (s,t) \\<rbrakk> \n                  \\<Longrightarrow> (s to x in t) to y in u \\<mapsto> s to x in (t to y in u)\"\n| r11[intro!]: \"s \\<mapsto> s' \\<Longrightarrow> [s] \\<mapsto> [s']\" \nequivariance reduction\nnominal_inductive reduction\n  by(auto simp add: abs_fresh fresh_fact' fresh_prod fresh_atm)\n\n\ntext \\<open>In order to show adequacy, the extra freshness conditions in the rules\n\\isa{r3}, \\isa{r6}, \\isa{r7}, \\isa{r8}, \\isa{r9}, and \\isa{r10} need to be\ndischarged.\\<close>\n\ntext_raw \\<open>\\label{pg:alpha-begin}\\<close>\n\nlemma r3'[intro!]: \"App (\\<Lambda> x . t) s \\<mapsto> t[x::=s]\"\nproof -\n  obtain x'::name where s: \"x' \\<sharp> s\" and t: \"x' \\<sharp> t\"\n    using ex_fresh[of \"(s,t)\"] by (auto simp add: fresh_prod)\n  from t have \"App (\\<Lambda> x . t) s = App (\\<Lambda> x' . ([(x,x')] \\<bullet> t)) s\" \n    by (simp add: alpha'')\n  also from s have \"\\<dots> \\<mapsto> ([(x, x')] \\<bullet> t)[x'::=s]\" ..\n  also have \"\\<dots> = t[x::=s]\" using t \n    by (auto simp add: subst_rename') (metis perm_swap)\n  finally show ?thesis .\nqed \ndeclare r3[rule del]\n\n\nlemma r6'[intro]:\n  fixes s :: trm \n  assumes r: \"s \\<mapsto> s'\"\n  shows \"s to x in t \\<mapsto> s' to x in t\"\nusing assms\nproof -\n  obtain x'::name where s: \"x' \\<sharp> (s, s')\" and t: \"x' \\<sharp> t\"\n    using ex_fresh[of \"(s,s',t)\"] by (auto simp add: fresh_prod)\n  from t have \"s to x in t = s to x' in ([(x,x')] \\<bullet> t)\"\n    by (simp add: alpha'')\n  also from s r have \"\\<dots> \\<mapsto> s' to x' in ([(x, x')] \\<bullet> t)\" ..\n  also from t have \"\\<dots> = s' to x in t\"\n    by (simp add: alpha'')\n  finally show ?thesis .\nqed\ndeclare r6[rule del]\n\nlemma r7'[intro]: \n  fixes t :: trm\n  assumes \"t \\<mapsto> t'\"\n  shows \"s to x in t \\<mapsto> s to x in t'\"\nusing assms\nproof -\n  obtain x'::name where f: \"x' \\<sharp> t\"   \"x' \\<sharp> t'\"   \"x' \\<sharp> s\"   \"x' \\<sharp> x\" \n    using ex_fresh[of \"(t,t',s,x)\"] by(auto simp add:fresh_prod)\n  hence a: \"s to x in t = s to x' in ([(x,x')] \\<bullet> t)\" \n    by (auto simp add: alpha'')\n  from assms have \"([(x,x')] \\<bullet> t) \\<mapsto> [(x,x')] \\<bullet> t'\" \n    by (simp add: eqvts)\n  hence r: \"s to x' in ([(x,x')] \\<bullet> t) \\<mapsto> s to x' in ([(x,x')] \\<bullet> t')\" \n    using f by auto \n  from f have \"s to x in t' = s to x' in ([(x,x')] \\<bullet> t')\" \n    by (auto simp add: alpha'')\n  with a r show ?thesis by (simp del: trm.inject)\nqed\ndeclare r7[rule del]\n\nlemma r8'[intro!]: \"[s] to x in t \\<mapsto> t[x::=s]\"\nproof - \n  obtain x'::name where s: \"x' \\<sharp> s\" and t: \"x' \\<sharp> t\"\n    using ex_fresh[of \"(s,t)\"] by (auto simp add: fresh_prod)\n  from t have \"[s] to x in t = [s] to x' in ([(x,x')] \\<bullet> t)\" \n    by (simp add: alpha'')\n  also from s have \"\\<dots> \\<mapsto> ([(x, x')] \\<bullet> t)[x'::=s]\" ..\n  also have \"\\<dots> = t[x::=s]\" using t \n    by (auto simp add: subst_rename') (metis perm_swap)\n  finally show ?thesis .\nqed\ndeclare r8[rule del]\n\n\n\ntext \\<open>While discharging these freshness conditions is easy for rules involving\nonly one binder it unfortunately becomes quite tedious for the assoc rule\n\\isa{r10}. This is due to the complex binding structure of this rule which\nincludes \\textit{four} binding occurrences of two different names. Furthermore,\nthe binding structure changes from the left to the right: On the left hand\nside, $x$ is only bound in $t$, whereas on the right hand side the scope of $x$\nextends over the whole term @{term \"(t to y in u)\"}.\\<close>\n\nlemma r10'[intro!]: \n  assumes xf: \"x \\<sharp> y\"   \"x \\<sharp> u\"\n  shows \"(s to x in t) to y in u \\<mapsto> s to x in (t to y in u)\"\nproof -\n  obtain y'::name \\<comment> \\<open>suitably fresh\\<close>\n    where y: \"y' \\<sharp> s\"   \"y' \\<sharp> x\"   \"y' \\<sharp> t\"   \"y' \\<sharp> u\" \n    using ex_fresh[of \"(s,x,t,u,[(x, x')] \\<bullet> t)\"] \n    by (auto simp add: fresh_prod)\n  obtain x'::name \n    where x: \"x' \\<sharp> s\"   \"x' \\<sharp> y'\"   \"x' \\<sharp> y\"  \"x' \\<sharp> t\"   \"x' \\<sharp> u\"   \n             \"x' \\<sharp> ([(y,y')] \\<bullet> u)\"\n    using ex_fresh[of \"(s,y',y,t,u,([(y,y')] \\<bullet> u))\"] \n    by (auto simp add: fresh_prod)\n  from x y have yaux: \"y' \\<sharp> [(x, x')] \\<bullet> t\"\n    by(simp add: fresh_left perm_fresh_fresh fresh_atm)\n   have \"(s to x in t) to y in u = (s to x in t) to y' in ([(y,y')] \\<bullet> u)\"\n    using \\<open>y' \\<sharp> u\\<close> by (simp add: alpha'')\n  also have \"\\<dots> = (s to x' in ([(x,x')] \\<bullet> t)) to y' in ([(y,y')] \\<bullet> u)\"\n    using \\<open>x' \\<sharp> t\\<close> by (simp add: alpha'')\n  also have \"\\<dots> \\<mapsto> s to x' in (([(x,x')] \\<bullet> t) to y' in ([(y,y')] \\<bullet> u))\"\n    using x y yaux by (auto simp add: fresh_prod) \n  also have \" \\<dots> = s to x' in (([(x,x')] \\<bullet> t) to y in u)\"\n    using \\<open>y' \\<sharp> u\\<close> by (simp add: abs_fun_eq1 alpha'')\n  also have \"\\<dots> = s to x in (t to y in u)\"\n  proof (subst trm.inject)\n    from xf x have swap: \"[(x,x')] \\<bullet> y = y\"   \"[(x,x')] \\<bullet> u = u \" \n      by(auto simp add: fresh_atm perm_fresh_fresh )\n    with x show \"s = s \\<and> [x'].([(x, x')] \\<bullet> t) to y in u = [x].t to y in u\"\n      by (auto simp add: alpha''[of x' _ x] abs_fresh abs_fun_eq1 swap)\n  qed\n  finally show ?thesis .\nqed\ndeclare r10[rule del]\n\ntext_raw \\<open>\\label{pg:alpha-end}\\<close>\n\ntext \\<open>Since now all the introduction rules of the vc-compatible reduction\nrelation exactly match their standard counterparts, both directions of the\nadequacy proof are trivial inductions.\\<close>\n\ntheorem adequacy: \"s \\<mapsto> t = s \\<leadsto> t\"\nby (auto elim:reduction.induct std_reduction.induct)\n\ntext \\<open>Next we show that the reduction relation preserves freshness and is in\nturn preserved under substitution.\\<close>\n\nlemma reduction_fresh: \n  fixes x::\"name\"\n  assumes r: \"t \\<mapsto> t'\"\n  shows \"x \\<sharp> t \\<Longrightarrow> x \\<sharp> t'\"\nusing r\nby(nominal_induct t t' avoiding: x rule: reduction.strong_induct)\n    (auto simp add: abs_fresh fresh_fact fresh_atm)\n\nlemma reduction_subst:\n  assumes a: \" t \\<mapsto> t' \"\n  shows \"t[x::=v] \\<mapsto> t'[x::=v]\"\nusing a\nby(nominal_induct t t' avoiding: x v rule: reduction.strong_induct)\n  (auto simp add: fresh_atm fresh_fact subst_lemma fresh_prod abs_fresh)\n\n\n(*section {* Strong Normalization *}\ntext_raw {* \\label{sec:SN-formal} *} *)\n\ntext \\<open>Following \\cite{SN.thy}, we use an inductive variant of strong\nnormalization, as it allows for inductive proofs on terms being strongly\nnormalizing, without establishing that\nthe reduction relation is finitely branching.\\<close>   \n\n\ninductive \n  SN :: \"trm \\<Rightarrow> bool\"\nwhere\n  SN_intro: \"(\\<And> t' . t \\<mapsto> t' \\<Longrightarrow> SN t') \\<Longrightarrow> SN t\" \n\n(*\ntext {* It remains to be shown that this definition actually excludes infinite\nsequences of reductions. We define a term $t$ to be diverging, written @{term\n\"DIV t\"}, if there is some infinite sequence $S$ of reductions beginning at\n$t$. *}\n\ndefinition DIV :: \"trm \\<Rightarrow> bool\"\nwhere\n  \"DIV t \\<equiv> \\<exists> (S::nat \\<Rightarrow> trm) .  t = S 0 \\<and> (\\<forall> n . S n \\<mapsto> S (n + 1))\"\n\ntheorem \"SN t \\<Longrightarrow> \\<not> DIV t\"\nproof (induct rule:SN.induct)\n  case (SN_intro t)\n  have ih: \"\\<And>t'. t \\<mapsto> t' \\<Longrightarrow> \\<not> DIV t'\" by fact\n  moreover have \"DIV t \\<Longrightarrow> \\<exists> t' . t \\<mapsto> t' \\<and> DIV t'\"\n  proof -\n    assume \"DIV t\" from this obtain S::\"nat\\<Rightarrow>trm\" \n      where S: \"t = S 0 \\<and> (\\<forall> n . S n \\<mapsto> S (n + 1))\"\n      unfolding DIV_def .. \n    let ?t = \"S 1\" let ?S = \"\\<lambda> n . S (n + 1)\"\n    from S have \" t \\<mapsto> ?t\" by auto\n    moreover { \n      from S have \"?t = ?S 0 \\<and> (\\<forall> n . ?S n \\<mapsto> ?S (n + 1))\" by auto\n      hence \"DIV ?t\" unfolding DIV_def by auto}\n    ultimately show ?thesis by blast\n  qed\n  ultimately show \"\\<not> DIV t\" using ih by blast\nqed\n\n\ntheorem \"\\<not> SN t \\<Longrightarrow> DIV t\"\nproof -\n  fix t assume t: \"\\<not> SN t\"\n  let ?NSN = \"{ t . \\<not> SN t }\"\n  have \"\\<forall> t \\<in> ?NSN .  \\<exists> t' . t \\<mapsto> t' \\<and> \\<not> SN t'\"\n    by (auto intro: SN_intro)\n  hence \" \\<exists> f . \\<forall> t \\<in> ?NSN . t \\<mapsto> f t \\<and> \\<not> SN (f t)\"\n    by (rule bchoice)\n  from this obtain f where f: \"\\<forall> t \\<in> ?NSN . t \\<mapsto> f t \\<and> \\<not> SN (f t)\" ..\n  let ?S = \"\\<lambda> n . (f^^n) t\"\n  { fix n from t f have  \"?S n \\<mapsto> ?S (n + 1) \\<and> \\<not> SN (?S (n + 1))\"\n      by (induct n) auto }\n  hence \"t = ?S 0 \\<and> (\\<forall> n . ?S n \\<mapsto> ?S (n + 1))\" by auto\n  thus \"DIV t\" unfolding DIV_def  by(rule exI[where x=\"?S\"])\nqed\n\ntext{* For the normalization theorem, we merely need that strong normalization\nis preserved under reduction and some lemmas on normal terms. *}\n*)\n\nlemma SN_preserved[intro]: \n  assumes a: \"SN t\"   \"t \\<mapsto> t'\"\n  shows \"SN t'\"\nusing a by (cases) (auto)\n\ndefinition \"NORMAL\" :: \"trm \\<Rightarrow> bool\"\nwhere\n  \"NORMAL t \\<equiv> \\<not>(\\<exists>t'. t \\<mapsto> t')\"\n\nlemma normal_var: \"NORMAL (Var x)\"\nunfolding NORMAL_def by (auto elim: reduction.cases)\n\nlemma normal_implies_sn : \"NORMAL s \\<Longrightarrow> SN s\"\nunfolding NORMAL_def by(auto intro: SN_intro)\n\nsection \\<open>Stacks\\<close>\ntext_raw \\<open>\\label{sec:stacks}\\<close>\n\ntext\\<open>As explained in \\cite{TT-lifting}, the monadic type structure of\nthe $\\lambda_{ml}$-calculus does not lend itself to an easy definition of a\nlogical relation along the type structure of the calculus. Therefore, we need to\nintroduce stacks as an auxiliary notion to handle the monadic type constructor\n$T$. Stacks can be thought of as lists of term abstractions @{term \"[x].t\"}. The\nnotation for stacks is chosen with this resemblance in mind.\\<close>\n\nnominal_datatype stack = Id | St \"\\<guillemotleft>name\\<guillemotright>trm\" \"stack\" (\"[_]_\\<ggreater>_\")\n\nlemma stack_exhaust :\n  fixes c :: \"'a::fs_name\"\n  shows \"k = Id \\<or> (\\<exists> y n l  . y \\<sharp> l \\<and> y \\<sharp> c \\<and> k = [y]n\\<ggreater>l)\"\nby(nominal_induct k avoiding: c rule: stack.strong_induct) (auto)\n\nnominal_primrec \n  length :: \"stack \\<Rightarrow> nat\" ( \"|_|\")\nwhere\n  \"|Id| = 0\" \n| \"y \\<sharp> L \\<Longrightarrow> length ([y]n\\<ggreater>L) = 1 + |L|\"\nby(finite_guess+,auto simp add: fresh_nat,fresh_guess)\n\n\ntext\\<open>Together with the stack datatype, we introduce the notion of dismantling\na term onto a stack. Unfortunately, the dismantling operation has no easy\nprimitive recursive formulation. The Nominal package, however, only provides a\nrecursion combinator for primitive recursion. This means that for dismantling\none has to prove pattern completeness, right uniqueness, and termination\nexplicitly.\\<close>\n\nfunction\n  dismantle :: \"trm \\<Rightarrow> stack \\<Rightarrow> trm\" (\"_ \\<star> _\" [160,160] 160)\nwhere\n  \"t \\<star> Id = t\" |\n  \"x \\<sharp> (K,t) \\<Longrightarrow> t \\<star> ([x]s\\<ggreater>K) = (t to x in s) \\<star> K\"\nproof -    \\<comment> \\<open>pattern completeness\\<close>\n  fix P :: bool and arg::\"trm \\<times> stack\"\n  assume id: \"\\<And>t. arg = (t, stack.Id) \\<Longrightarrow> P\"\n    and st: \"\\<And>x K t s. \\<lbrakk>x \\<sharp> (K, t); arg = (t, [x]s\\<ggreater>K)\\<rbrakk> \\<Longrightarrow> P\"\n  { assume \"snd arg = Id\"\n    hence P by (metis id[where t=\"fst arg\"] surjective_pairing) }\n  moreover \n  { fix y n L assume \"snd arg = [y]n\\<ggreater>L\"   \"y \\<sharp> (L, fst arg)\"\n    hence P by (metis st[where t=\"fst arg\"] surjective_pairing) }\n  ultimately show P using stack_exhaust[of   \"snd arg\"   \"fst arg\"] by auto\nnext\n    \\<comment> \\<open>right uniqueness\\<close>\n    \\<comment> \\<open>only the case of the second equation matching both args needs to be\nshown.\\<close>\n  fix t t' :: trm and x x' :: name and s s' :: trm and K K' :: stack\n  let ?g = dismantle_sumC \\<comment> \\<open>graph of dismantle\\<close>\n  assume \"x \\<sharp> (K, t)\"   \"x' \\<sharp> (K', t')\" \n    and  \"(t, [x]s\\<ggreater>K) = (t', [x']s'\\<ggreater>K')\"\n  thus \"?g (t to x in s, K) = ?g (t' to x' in s', K')\" \n    by (auto intro!: arg_cong[where f=\"?g\"] simp add: stack.inject)\nqed (simp_all add: stack.inject) \\<comment> \\<open>all other cases are trivial\\<close>\n\ntermination dismantle\nby(relation \"measure (\\<lambda>(t,K). |K| )\")(auto)\n\ntext\\<open>Like all our constructions, dismantling is equivariant. Also, freshness\ncan be pushed over dismantling, and the freshness requirement in the second\ndefining equation is not needed\\<close>\n\nlemma dismantle_eqvt[eqvt]:\n  fixes pi :: \"(name \\<times> name) list\"\n  shows \"pi \\<bullet> (t \\<star> K) =  (pi \\<bullet> t) \\<star> (pi \\<bullet> K)\"\nby(nominal_induct K avoiding: pi t rule:stack.strong_induct)\n  (auto simp add: eqvts fresh_bij)\n\nlemma dismantle_fresh[iff]:\n  fixes  x :: name\n  shows \"(x \\<sharp> (t \\<star> k)) = (x \\<sharp> t \\<and> x \\<sharp> k)\"\nby(nominal_induct k avoiding: t x rule: stack.strong_induct) \n  (simp_all)\n\nlemma dismantle_simp[simp]: \"s \\<star> [y]n\\<ggreater>L = (s to y in n) \\<star> L\"\nproof - \n  obtain x::name where f: \"x \\<sharp> s\"   \"x \\<sharp> L\"   \"x \\<sharp> n\"  \n    using ex_fresh[of \"(s,L,n)\"] by(auto simp add:fresh_prod)\n  hence t: \"s to y in n = s to x in ([(y,x)] \\<bullet> n)\" \n    by(auto simp add: alpha'')\n  from f have \"[y]n\\<ggreater>L = [x]([(y,x)] \\<bullet> n)\\<ggreater>L\" \n    by (auto simp add: stack.inject alpha'')\n  hence \"s \\<star> [y]n\\<ggreater>L = s \\<star> [x]([(y,x)] \\<bullet> n)\\<ggreater>L\" by simp\n  also have \" \\<dots> = (s to y in n) \\<star> L\" using f t by(simp del:trm.inject)\n  finally show ?thesis .\nqed\n\n\ntext \\<open>We also need a notion of reduction on stacks. This reduction relation\nallows us to define strong normalization not only for terms but also for stacks\nand is needed to prove the properties of the logical relation later on.\\<close>\n\ndefinition stack_reduction :: \"stack \\<Rightarrow> stack \\<Rightarrow> bool\" (\" _ \\<mapsto> _ \")\nwhere\n  \"k \\<mapsto> k' \\<equiv> \\<forall> (t::trm) . (t \\<star> k)  \\<mapsto> (t \\<star> k')\" \n\n\nlemma stack_reduction_fresh:\n  fixes k :: stack  and x :: name\n  assumes r : \"k \\<mapsto> k'\" and f :\"x \\<sharp> k\"\n  shows \"x \\<sharp> k'\"\nproof -\n  from ex_fresh[of x] obtain z::name where f': \"z \\<sharp> x\" ..\n  from r have \"Var z \\<star> k \\<mapsto> Var z \\<star> k'\" unfolding stack_reduction_def ..\n  moreover from f f' have \"x \\<sharp> Var z \\<star> k\" by(auto simp add: fresh_atm)\n  ultimately have \"x \\<sharp> Var z \\<star> k'\" by(rule reduction_fresh)\n  thus \"x \\<sharp> k'\" by simp\nqed\n\nlemma dismantle_red[intro]:\n  fixes m :: trm\n  assumes r: \" m \\<mapsto> m'\"\n  shows \"m \\<star> k \\<mapsto> m' \\<star> k\"\nusing r\nby (nominal_induct k avoiding: m m' rule:stack.strong_induct) auto\n\n\ntext \\<open>Next we define a substitution operation for stacks. The main purpose of\nthis is to distribute substitution over dismantling.\\<close>\n\nnominal_primrec\n  ssubst :: \"name \\<Rightarrow> trm \\<Rightarrow> stack \\<Rightarrow> stack\" \nwhere\n    \"ssubst x v Id = Id\"\n  | \" y \\<sharp> (k,x,v)  \\<Longrightarrow> ssubst x v ([y]n\\<ggreater>k) = [y](n[x::=v])\\<ggreater>(ssubst x v k)\"\nby(finite_guess+ , (simp add: abs_fresh)+ , fresh_guess+)\n\nlemma ssubst_fresh:\n  fixes y :: name\n  assumes \" y \\<sharp> (x,v,k) \"\n  shows  \"y \\<sharp> ssubst x v k\"\nusing assms\nby(nominal_induct k avoiding: y x v rule: stack.strong_induct)\n  (auto simp add: fresh_prod fresh_atm abs_fresh fresh_fact)\n\nlemma ssubst_forget: \n  fixes x :: name\n  assumes \"x \\<sharp> k\"\n  shows \"ssubst x v k = k\"\nusing assms\nby(nominal_induct k avoiding: x v rule: stack.strong_induct)\n  (auto simp add: abs_fresh fresh_atm forget)\n\nlemma subst_dismantle[simp]: \"(t \\<star> k)[x ::= v] = (t[x::=v]) \\<star> ssubst x v k\"\nby(nominal_induct k avoiding: t x v  rule: stack.strong_induct)\n  (auto simp add: ssubst_fresh fresh_prod fresh_fact)\n\nsection \\<open>Reducibility for Terms and Stacks\\<close>\ntext_raw \\<open>\\label{sec:reducibility-formal}\\<close>\n\ntext \\<open>Following \\cite{SN.thy}, we formalize the logical relation as a function\n@{term \"RED\"} of type @{typ \"ty \\<Rightarrow> trm set\"} for the term part and accordingly\n@{term SRED} of type @{typ \"ty \\<Rightarrow> stack set\"} for the stack part of the logical\nrelation.\\<close>\n\nlemma ty_exhaust: \"ty = TBase \\<or> (\\<exists> \\<sigma> \\<tau> . ty = \\<sigma> \\<rightarrow> \\<tau>) \\<or> (\\<exists> \\<sigma> . ty = T \\<sigma>)\"\nby(induct ty rule:ty.induct) (auto)\n\nfunction RED :: \"ty \\<Rightarrow> trm set\"\nand     SRED :: \"ty \\<Rightarrow> stack set\"\nwhere\n  \"RED (TBase) = {t. SN(t)}\"\n| \"RED (\\<tau>\\<rightarrow>\\<sigma>) = {t. \\<forall> u \\<in> RED \\<tau> . (App t u) \\<in> RED \\<sigma> }\"\n| \"RED (T \\<sigma>) = {t. \\<forall> k \\<in> SRED \\<sigma> . SN(t \\<star> k) }\" \n| \"SRED \\<tau> = {k. \\<forall> t \\<in> RED \\<tau> . SN ([t] \\<star> k) }\"\nby(auto simp add: ty.inject, case_tac x rule: sum.exhaust,insert ty_exhaust)\n  (blast)+\n\ntext \\<open>This is the second non-primitive function in the formalization. Since\ntypes do not involve binders, pattern completeness and right uniqueness are\nmostly trivial. The termination argument is not as simple as for the dismantling\nfunction, because the definiton of @{term \"SRED \\<tau>\"} involves a recursive call to\n@{term \"RED \\<tau>\"} without reducing the size of @{term \"\\<tau>\"}.\\<close>\n\nnominal_primrec\n  tsize :: \"ty \\<Rightarrow> nat\"\nwhere\n    \"tsize TBase = 1\"\n  | \"tsize (\\<sigma>\\<rightarrow>\\<tau>) = 1 + tsize \\<sigma> + tsize \\<tau>\"\n  | \"tsize (T \\<tau>) = 1 + tsize \\<tau>\"\nby (rule TrueI)+\n\ntext \\<open>In the termination argument below, @{term \"Inl \\<tau>\"} corresponds to the\ncall @{term \"RED \\<tau>\"}, whereas @{term \"Inr \\<tau>\"}  corresponds to @{term \"SRED \\<tau>\"}\n\\<close>\n\ntermination RED\nby(relation \"measure \n    (\\<lambda> x . case x of Inl \\<tau> \\<Rightarrow> 2 * tsize \\<tau> \n                      | Inr \\<tau> \\<Rightarrow> 2 * tsize \\<tau> + 1)\") (auto)\n\nsection \\<open>Properties of the Reducibility Relation\\<close>\n\ntext \\<open>After defining the logical relations we need to prove that the relation\nimplies strong normalization, is preserved under reduction, and satisfies the\nhead expansion property.\\<close>\n\ndefinition NEUT :: \"trm \\<Rightarrow> bool\"\nwhere\n  \"NEUT t \\<equiv> (\\<exists>a. t = Var a) \\<or> (\\<exists>t1 t2. t = App t1 t2)\" \n\ndefinition \"CR1\" :: \"ty \\<Rightarrow> bool\"\nwhere\n  \"CR1 \\<tau> \\<equiv> \\<forall>t. (t\\<in>RED \\<tau> \\<longrightarrow> SN t)\"\n\ndefinition \"CR2\" :: \"ty \\<Rightarrow> bool\"\nwhere\n  \"CR2 \\<tau> \\<equiv> \\<forall>t t'. (t\\<in>RED \\<tau> \\<and> t \\<mapsto> t') \\<longrightarrow> t'\\<in>RED \\<tau>\"\n\ndefinition \"CR3_RED\" :: \"trm \\<Rightarrow> ty \\<Rightarrow> bool\"\nwhere\n  \"CR3_RED t \\<tau> \\<equiv> \\<forall>t'. t \\<mapsto> t' \\<longrightarrow>  t'\\<in>RED \\<tau>\" \n\ndefinition \"CR3\" :: \"ty \\<Rightarrow> bool\"\nwhere\n  \"CR3 \\<tau> \\<equiv> \\<forall>t. (NEUT t \\<and> CR3_RED t \\<tau>) \\<longrightarrow> t\\<in>RED \\<tau>\"\n   \ndefinition \"CR4\" :: \"ty \\<Rightarrow> bool\"\nwhere\n  \"CR4 \\<tau> \\<equiv> \\<forall>t. (NEUT t \\<and> NORMAL t) \\<longrightarrow>t\\<in>RED \\<tau>\"\n\nlemma CR3_implies_CR4[intro]: \"CR3 \\<tau> \\<Longrightarrow> CR4 \\<tau>\"\nby (auto simp add: CR3_def CR3_RED_def CR4_def NORMAL_def)\n\nlemma%invisible sub_induction: \n  assumes a: \"SN(u)\"\n  and     b: \"u\\<in>RED \\<tau>\"\n  and     c1: \"NEUT t\"\n  and     c2: \"CR2 \\<tau>\"\n  and     c3: \"CR3 \\<sigma>\"\n  and     c4: \"CR3_RED t (\\<tau>\\<rightarrow>\\<sigma>)\"\n  shows \"(App t u)\\<in>RED \\<sigma>\"\nusing a b\nproof(induct)\n  fix u\n  assume as: \"u\\<in>RED \\<tau>\"\n  assume ih: \" \\<And>u'. \\<lbrakk>u \\<mapsto> u'; u' \\<in> RED \\<tau>\\<rbrakk> \\<Longrightarrow> App t u' \\<in> RED \\<sigma>\"\n  have \"NEUT (App t u)\" using c1 by (auto simp add: NEUT_def)\n  moreover\n  have \"CR3_RED (App t u) \\<sigma>\" unfolding CR3_RED_def\n  proof (intro strip)\n    fix r\n    assume red: \"App t u \\<mapsto> r\"\n    moreover\n    { assume \"\\<exists>t'. t \\<mapsto> t' \\<and> r = App t' u\"\n      then obtain t' where a1: \"t \\<mapsto> t'\" and a2: \"r = App t' u\" by blast\n      have \"t'\\<in>RED (\\<tau>\\<rightarrow>\\<sigma>)\" using c4 a1 by (simp add: CR3_RED_def)\n      then have \"App t' u\\<in>RED \\<sigma>\" using as by simp\n      then have \"r\\<in>RED \\<sigma>\" using a2 by simp\n    }\n    moreover\n    { assume \"\\<exists>u'. u \\<mapsto> u' \\<and> r = App t u'\"\n      then obtain u' where b1: \"u \\<mapsto> u'\" and b2: \"r = App t u'\" by blast\n      have \"u'\\<in>RED \\<tau>\" using as b1 c2 by (auto simp add: CR2_def)\n      with ih have \"App t u' \\<in> RED \\<sigma>\" using b1 by simp\n      then have \"r\\<in>RED \\<sigma>\" using b2 by simp\n    }\n    moreover\n    { assume \"\\<exists>x t'. t = \\<Lambda> x .t'\"\n      then obtain x t' where \"t = \\<Lambda> x .t'\" by blast\n      then have \"NEUT (\\<Lambda> x .t')\" using c1 by simp\n      then have \"False\" by (simp add: NEUT_def)\n      then have \"r\\<in>RED \\<sigma>\" by simp\n    }\n    ultimately show \"r \\<in> RED \\<sigma>\" by (cases) (auto)\n  qed\n  ultimately show \"App t u \\<in> RED \\<sigma>\" using c3 by (simp add: CR3_def)\nqed\n\n\ninductive \n  FST :: \"trm\\<Rightarrow>trm\\<Rightarrow>bool\" (\" _ \\<guillemotright> _\" [80,80] 80)\nwhere\n  fst[intro!]:  \"(App t s) \\<guillemotright> t\"\n\nlemma SN_of_FST_of_App: \n  assumes a: \"SN (App t s)\"\n  shows \"SN t\"\nproof - \n  from a have \"\\<forall>z. (App t s \\<guillemotright> z) \\<longrightarrow> SN z\"\n    by (induct rule: SN.induct)\n       (blast elim: FST.cases intro: SN_intro)\n  then show \"SN t\" by blast\nqed\n\ntext \\<open>The lemma above is a simplified version of the one used in\n\\cite{SN.thy}. Since we have generalized our notion of reduction from terms to\nstacks, we can also generalize the notion of strong normalization. The new\ninduction principle will be used to prove the @{term \"T\"} case of the\nproperties of the reducibility relation.\\<close>\n\ninductive \n  SSN :: \"stack \\<Rightarrow> bool\"\nwhere\n  SSN_intro: \"(\\<And> k' . k \\<mapsto> k' \\<Longrightarrow> SSN k') \\<Longrightarrow> SSN k\"\n\ntext \\<open>Furthermore, the approach for deriving strong normalization of\nsubterms from above can be generalized to terms of the form @{term \"t \\<star> k\"}. In\ncontrast to the case of applications, @{term \"t \\<star> k\"} does \\textit{not} uniquely\ndetermine @{term t} and @{term k}. Thus, the extraction is a proper relation in\nthis case.\\<close>\n\ninductive\n  SND_DIS :: \"trm \\<Rightarrow> stack \\<Rightarrow> bool\" (\"_ \\<rhd> _\")\nwhere\n  snd_dis[intro!]: \"t \\<star> k \\<rhd> k\"\n\nlemma SN_SSN:\n  assumes a: \"SN (t \\<star> k)\"\n  shows \" SSN k\"\nproof - \n  from a have \"\\<forall>z. (t \\<star> k \\<rhd> z) \\<longrightarrow> SSN z\"  by (induct rule: SN.induct)\n       (metis SND_DIS.cases SSN_intro snd_dis stack_reduction_def)\n  thus \"SSN k\" by blast\nqed\n\ntext \\<open>To prove CR1-3, the authors of\n\\cite{TT-lifting} use a case distinction on the reducts of @{term \"t \\<star> k\"},\nwhere $t$ is a neutral term and therefore no interaction occurs between $t$ and\n$k$.\n\n%auto generated stuff\n\\begin{isamarkuptext}%\n\\renewcommand\\isacharquery{}\n$$\\inferrule{\n    \\isa{{\\isacharquery}t\\ {\\isasymstar}\\ {\\isacharquery}k\\ {\\isasymmapsto}\\\n{\\isacharquery}r}\\\\\n    \\isa{{\\isasymAnd}t{\\isacharprime}{\\isachardot}\\\n{\\isasymlbrakk}{\\isacharquery}t\\ {\\isasymmapsto}\\\nt{\\isacharprime}{\\isacharsemicolon}\\ {\\isacharquery}r\\ {\\isacharequal}\\\nt{\\isacharprime}\\ {\\isasymstar}\\ {\\isacharquery}k{\\isasymrbrakk}\\\n{\\isasymLongrightarrow}\\ {\\isacharquery}P}\\\\\n    \\isa{NEUT\\ {\\isacharquery}t}\\\\\n    \\isa{{\\isasymAnd}k{\\isacharprime}{\\isachardot}\\ {\\isasymlbrakk}\\\n{\\isacharquery}k\\ {\\isasymmapsto}\\ k{\\isacharprime}\\ {\\isacharsemicolon}\\\n{\\isacharquery}r\\ {\\isacharequal}\\ {\\isacharquery}t\\ {\\isasymstar}\\\nk{\\isacharprime}{\\isasymrbrakk}\\ {\\isasymLongrightarrow}\\ {\\isacharquery}P}\\\\\n    }{\n    \\isa{{\\isacharquery}P}}$$%\n\\end{isamarkuptext}%\\<close>\n\ntext \\<open>We strive for a proof of this rule by structural induction on $k$. The\ngeneral idea of the case where @{term \"k = [y]n\\<ggreater>l\"} is to move the first stack\nframe into the term $t$ and then apply the induction hypothesis as a case\nrule. Unfortunately, this term is no longer neutral, so, for the induction to go\nthrough, we need to generalize the claim to also include the possible\ninteractions of non-neutral terms and stacks.\\<close>\n\n\nlemma dismantle_cases:\n  fixes t :: trm\n  assumes r: \"t \\<star> k \\<mapsto> r\"\n  and T: \"\\<And> t' . \\<lbrakk> t \\<mapsto> t' ; r = t' \\<star> k \\<rbrakk> \\<Longrightarrow> P\"\n  and K: \"\\<And> k' . \\<lbrakk> k \\<mapsto> k' ; r = t \\<star> k' \\<rbrakk> \\<Longrightarrow> P\" \n  and B: \"\\<And> s y n l .\\<lbrakk> t = [s] ; k = [y]n\\<ggreater>l ; r = (n[y::=s]) \\<star> l \\<rbrakk> \\<Longrightarrow> P\"\n  and A: \"\\<And> u x v y n l.\\<lbrakk> x \\<sharp> y; x \\<sharp> n ; t = u to x in v ; \n             k = [y]n\\<ggreater>l ; r = (u to x in (v to y in n)) \\<star> l \\<rbrakk> \\<Longrightarrow> P \"\n  shows \"P\"\nusing assms\nproof (nominal_induct k avoiding: t r rule:stack.strong_induct)\n  case (St y n L) note  yfresh = \\<open>y \\<sharp> t\\<close> \\<open>y \\<sharp> r\\<close> \\<open>y \\<sharp> L\\<close> \n  note IH = St(4) \n    and T = St(6) and K = St(7) and B = St(8) and A = St(9) \n  thus \"P\" proof (cases rule:IH[where b=\"t to y in n\" and ba=\"r\"])\n    case (2 r') have red: \"t to y in n \\<mapsto> r'\" and r: \" r = r' \\<star> L\" by fact+\ntxt \\<open>If @{term \"m to y in n\"} makes a step we reason by case distinction      \non the successors of @{term \"m to y in n\"}. We want to use the strong inversion\nprinciple for the reduction relation. For this we need that $y$ is fresh for\n@{term \"t to y in n\"} and $r'$.\\<close>\n    from yfresh r have y: \"y \\<sharp>  t to y in n\"   \"y \\<sharp> r'\" \n      by (auto simp add: abs_fresh)\n    obtain z where z: \"z \\<noteq> y\"   \"z \\<sharp> r'\"   \"z \\<sharp> t to y in n\" \n      using ex_fresh[of \"(y,r',t to y in n)\"] \n      by(auto simp add:fresh_prod fresh_atm)\n    from red  r show \"P\" \n    proof (cases rule:reduction.strong_cases\n        [ where x=\"y\"and xa=\"y\" and xb=\"y\" and xc=\"y\" and xd=\"y\" \n          and xe=\"y\" and xf=\"y\" and xg=\"z\" and y=\"y\"])\n      case (r6 s t' u) \\<comment> \\<open>if $t$ makes a step we use assumption T\\<close>\n      with y have m: \"t \\<mapsto> t'\"   \"r' = t' to y in n\" by auto\n      thus \"P\" using T[of t'] r by auto\n    next\n      case (r7 _ _ n') with y have n: \"n \\<mapsto> n'\" and r': \"r' = t to y in n'\"\n        by (auto simp add: alpha)\n      txt \\<open>Since @{term \"k = [y]n\\<ggreater>L\"}, the reduction @{thm n} occurs within\n        the stack $k$. Hence, we need to establish this stack reduction.\\<close>\n      have \"[y]n\\<ggreater>L \\<mapsto> [y]n'\\<ggreater>L\" unfolding stack_reduction_def\n      proof \n        fix u have \"u to y in n \\<mapsto> u to y in n'\" using n .. \n        hence \"(u to y in n) \\<star> L \\<mapsto> (u to y in n') \\<star> L\" ..\n        thus \" u \\<star> [y]n\\<ggreater>L \\<mapsto> u \\<star> [y]n'\\<ggreater>L\" \n          by simp\n      qed\n      moreover have \"r = t \\<star> [y]n'\\<ggreater>L\" using r r' by simp\n      ultimately show \"P\" by (rule K)\n    next \n      case (r8 s _) \\<comment> \\<open>the case of a $\\beta$-reduction is exactly B\\<close>\n      with y have \"t = [s]\"   \"r' = n[y::=s]\" by(auto simp add: alpha) \n      thus \"P\" using B[of \"s\" \"y\" \"n\" \"L\"] r by auto \n    next \n      case (r9 _) \\<comment> \\<open>The case of an $\\eta$-reduction is a stack\nreduction as well.\\<close>\n      with y have n: \"n = [Var y]\" and r': \"r' = t\" \n        by(auto simp add: alpha)\n      { fix u have \"u to y in n \\<mapsto> u\" unfolding n ..\n        hence \"(u to y in n) \\<star> L \\<mapsto> u \\<star> L \" ..\n        hence \"u \\<star> [y]n\\<ggreater>L \\<mapsto> u \\<star> L\" by simp\n      } hence \"[y]n\\<ggreater>L \\<mapsto> L\" unfolding stack_reduction_def ..\n      moreover have \"r = t \\<star> L\" using r r' by simp\n      ultimately show \"P\" by (rule K)\n    next\n      case (r10 u _ v) \\<comment> \\<open>The assoc case holds by A.\\<close>\n      with y z have \n        \"t = (u to z in v)\" \n        \"r' = u to z in (v to y in n)\" \n        \"z \\<sharp> (y,n)\" by (auto simp add: fresh_prod alpha)\n      thus \"P\" using A[of z y n] r by auto\n    qed (insert y, auto)  \\<comment> \\<open>No other reductions are possible.\\<close>\n  next \n    txt \\<open>Next we have to solve the case where a reduction occurs deep within\n$L$. We get a reduction of the stack $k$ by moving the first stack frame\n``[y]n'' back to the right hand side of the dismantling operator.\\<close>\n    case (3 L')\n    hence L: \"L \\<mapsto> L'\" and  r: \"r = (t to y in n) \\<star> L'\" by auto\n    { fix s from L have  \"(s to y in n) \\<star> L \\<mapsto> (s to y in n) \\<star> L'\" \n        unfolding stack_reduction_def ..\n      hence \"s \\<star> [y]n\\<ggreater>L \\<mapsto> s \\<star> [y]n\\<ggreater>L'\" by simp\n    } hence \"[y]n\\<ggreater>L \\<mapsto> [y]n\\<ggreater>L'\" unfolding stack_reduction_def by auto\n    moreover from r have \"r = t \\<star> [y]n\\<ggreater>L'\" by simp\n    ultimately show \"P\" by (rule K) \n  next\n    case (5 x z n' s v K) \\<comment> \\<open>The ``assoc'' case is again a stack reduction\\<close>\n    have xf: \"x \\<sharp> z\"   \"x \\<sharp> n'\" \n      \\<comment> \\<open>We get the following equalities\\<close>\n    and red: \"t to y in n = s to x in v\"\n             \"L = [z]n'\\<ggreater>K\"\n             \"r = (s to x in v to z in n') \\<star> K\" by fact+\n    { fix u from red have \"u \\<star> [y]n\\<ggreater>L = ((u to x in v) to z in n') \\<star> K \"\n        by(auto intro: arg_cong[where f=\"\\<lambda> x . x \\<star> K\"])\n      moreover \n      { from xf have \"(u to x in v) to z in n' \\<mapsto> u to x in (v to z in n')\" ..\n        hence \"((u to x in v) to z in n') \\<star> K \\<mapsto> (u to x in (v to z in n')) \\<star> K\"\n          by rule \n      } ultimately  have \"u \\<star> [y]n\\<ggreater>L \\<mapsto> (u to x in (v to z in n')) \\<star> K\" \n        by (simp (no_asm_simp) del:dismantle_simp)\n      hence \"u \\<star> [y]n\\<ggreater>L \\<mapsto> u \\<star> [x](v to z in n')\\<ggreater>K\" by simp\n    } hence \"[y]n\\<ggreater>L \\<mapsto>  [x](v to z in n')\\<ggreater> K\" \n      unfolding stack_reduction_def by simp\n    moreover have \"r = t \\<star> ([x](v to z in n')\\<ggreater>K)\" using red \n      by (auto)\n    ultimately show \"P\" by (rule K)\n  qed (insert St, auto )\nqed auto\n\ntext \\<open>Now that we have established the general claim, we can restrict $t$ to\nneutral terms only and drop the cases dealing with possible interactions.\\<close>\n\nlemma dismantle_cases'[consumes 2, case_names T K]:\n  fixes m :: trm\n  assumes r: \"t \\<star> k \\<mapsto> r\"\n  and \"NEUT t\"\n  and \"\\<And> t' . \\<lbrakk> t \\<mapsto> t' ; r = t' \\<star> k \\<rbrakk> \\<Longrightarrow> P\"\n  and \"\\<And> k' . \\<lbrakk> k \\<mapsto> k' ; r = t \\<star> k' \\<rbrakk> \\<Longrightarrow> P\" \n  shows \"P\"  \nusing assms unfolding NEUT_def\nby (cases rule: dismantle_cases[of t k r]) (auto) \n\nlemma red_Ret:\n  fixes t :: trm\n  assumes \"[s] \\<mapsto> t\"\n  shows \" \\<exists> s' . t = [s'] \\<and> s  \\<mapsto> s'\"\nusing assms by cases (auto)\n\nlemma SN_Ret: \"SN u \\<Longrightarrow> SN [u]\"\nby(induct rule:SN.induct) (metis SN.intros red_Ret)\n\ntext \\<open>All the properties of reducibility are shown simultaneously by induction\non the type. Lindley and Stark \\cite{TT-lifting} only spell out the cases\ndealing with the monadic type constructor $T$. We do the same by reusing the\nproofs from \\cite{SN.thy} for the other cases. To shorten the presentation,\nthese proofs are omitted\\<close>\n    \nlemma RED_props: \n  shows \"CR1 \\<tau>\" and \"CR2 \\<tau>\" and \"CR3 \\<tau>\"\nproof (nominal_induct \\<tau> rule: ty.strong_induct)\n  case TBase {%invisible case 1 show \"CR1 TBase\" \n      by (simp add: CR1_def)\n  next\n    case 2 show \"CR2 TBase\" \n      by (auto intro: SN_preserved simp add: CR2_def)\n  next\n    case 3 show \"CR3 TBase\" \n      by (auto intro: SN_intro simp add: CR3_def CR3_RED_def)\n  }\nnext\n  case (TFun \\<tau>1 \\<tau>2) {%invisible case 1\n    have ih_CR3_\\<tau>1: \"CR3 \\<tau>1\" by fact\n    have ih_CR1_\\<tau>2: \"CR1 \\<tau>2\" by fact\n    have \"\\<And>t. t \\<in> RED (\\<tau>1 \\<rightarrow> \\<tau>2) \\<Longrightarrow> SN t\" \n    proof - \n      fix t\n      assume \"t \\<in> RED (\\<tau>1 \\<rightarrow> \\<tau>2)\"\n      then have a: \"\\<forall>u. u \\<in> RED \\<tau>1 \\<longrightarrow> App t u \\<in> RED \\<tau>2\" by simp\n      from ih_CR3_\\<tau>1 have \"CR4 \\<tau>1\" by (simp add: CR3_implies_CR4) \n      moreover\n      fix a have \"NEUT (Var a)\" by (force simp add: NEUT_def)\n      moreover\n      have \"NORMAL (Var a)\" by (rule normal_var)\n      ultimately have \"(Var a)\\<in> RED \\<tau>1\" by (simp add: CR4_def)\n      with a have \"App t (Var a) \\<in> RED \\<tau>2\" by simp\n      hence \"SN (App t (Var a))\" using ih_CR1_\\<tau>2 by (simp add: CR1_def)\n      thus \"SN t\" by (auto dest: SN_of_FST_of_App)\n    qed\n    then show \"CR1 (\\<tau>1 \\<rightarrow> \\<tau>2)\" unfolding CR1_def by simp\n  next\n    case 2\n    have ih_CR2_\\<tau>2: \"CR2 \\<tau>2\" by fact\n    then show \"CR2 (\\<tau>1 \\<rightarrow> \\<tau>2)\" unfolding CR2_def by auto \n  next\n    case 3\n    have ih_CR1_\\<tau>1: \"CR1 \\<tau>1\" by fact\n    have ih_CR2_\\<tau>1: \"CR2 \\<tau>1\" by fact\n    have ih_CR3_\\<tau>2: \"CR3 \\<tau>2\" by fact\n    show \"CR3 (\\<tau>1 \\<rightarrow> \\<tau>2)\" unfolding CR3_def\n    proof (simp, intro strip)\n      fix t u\n      assume a1: \"u \\<in> RED \\<tau>1\"\n      assume a2: \"NEUT t \\<and> CR3_RED t (\\<tau>1 \\<rightarrow> \\<tau>2)\"\n      have \"SN(u)\" using a1 ih_CR1_\\<tau>1 by (simp add: CR1_def)\n      then show \"(App t u)\\<in>RED \\<tau>2\" \n        using ih_CR2_\\<tau>1 ih_CR3_\\<tau>2 a1 a2 by (blast intro: sub_induction)\n    qed\n  }\nnext\n  case (T \\<sigma>)\n  { case 1 \\<comment> \\<open>follows from the fact that @{term \"Id \\<in> SRED \\<sigma>\"}\\<close>\n    have ih_CR1_\\<sigma>: \"CR1 \\<sigma>\" by fact\n    { fix t assume t_red: \"t \\<in> RED (T \\<sigma>)\"\n      { fix s assume \"s \\<in> RED \\<sigma>\" \n        hence \"SN s\" using ih_CR1_\\<sigma> by (auto simp add: CR1_def)\n        hence \"SN ([s])\" by (rule SN_Ret)\n        hence \"SN ([s] \\<star> Id)\" by simp\n      } hence \"Id \\<in> SRED \\<sigma>\" by simp\n      with t_red have \"SN (t)\" by (auto simp del: SRED.simps)\n    } thus \"CR1 (T \\<sigma>)\" unfolding CR1_def by blast\n  next\n    case 2 \\<comment> \\<open>follows since \\isa{SN} is preserved under redcution\\<close>\n    { fix t t'::trm  assume t_red: \"t \\<in> RED (T \\<sigma>)\" and t_t': \"t \\<mapsto> t'\" \n      { fix k assume k: \"k \\<in> SRED \\<sigma>\"\n        with t_red have \"SN(t \\<star> k)\" by simp\n        moreover from t_t' have \"t \\<star> k \\<mapsto> t' \\<star> k\" ..\n        ultimately have \"SN(t' \\<star> k)\" by (rule SN_preserved) \n      } hence \"t' \\<in> RED (T \\<sigma>)\"  by (simp del: SRED.simps)\n    } thus \"CR2 (T \\<sigma>)\"unfolding CR2_def by blast\n  next\n    case 3 from \\<open>CR3 \\<sigma>\\<close> have ih_CR4_\\<sigma> : \"CR4 \\<sigma>\" ..\n    { fix t assume t'_red: \"\\<And> t' . t \\<mapsto> t' \\<Longrightarrow> t' \\<in> RED (T \\<sigma>)\" \n      and neut_t: \"NEUT t\"\n      { fix k assume k_red: \"k \\<in> SRED \\<sigma>\" \n        fix x have \"NEUT (Var x)\" unfolding NEUT_def by simp \n        hence \"Var x \\<in> RED \\<sigma>\" using normal_var ih_CR4_\\<sigma> \n          by (simp add: CR4_def)\n        hence \"SN ([Var x] \\<star> k)\" using k_red by simp\n        hence \"SSN k\" by (rule SN_SSN)\n        then have \"SN (t \\<star> k)\" using k_red\n        proof (induct k rule:SSN.induct)\n          case (SSN_intro k)\n          have ih : \"\\<And>k'. \\<lbrakk> k \\<mapsto> k' ; k' \\<in> SRED \\<sigma> \\<rbrakk>  \\<Longrightarrow> SN (t \\<star> k')\"\n            and k_red: \"k \\<in> SRED \\<sigma>\" by fact+\n          { fix r assume r: \"t \\<star> k \\<mapsto> r\"\n            hence \"SN r\" using neut_t\n            proof (cases rule:dismantle_cases')\n              case (T t') hence t_t': \"t \\<mapsto> t'\" and r_def: \"r = t' \\<star> k\" . \n              from t_t' have \"t' \\<in> RED (T \\<sigma>)\" by (rule t'_red)\n              thus \"SN r\" using k_red r_def by simp\n            next\n              case (K k') hence k_k': \"k \\<mapsto> k'\" and r_def: \"r = t \\<star> k'\" .\n              { fix s assume \"s \\<in> RED \\<sigma>\" \n                hence \"SN ([s] \\<star> k)\" using k_red\n                  by simp\n                moreover have \"[s] \\<star> k \\<mapsto> [s] \\<star> k'\"\n                  using k_k' unfolding stack_reduction_def ..   \n                ultimately have \"SN ([s] \\<star> k')\" ..\n              } hence \"k' \\<in> SRED \\<sigma>\" by simp\n              with k_k' show \"SN r\" unfolding r_def by (rule ih)\n            qed } thus \"SN (t \\<star> k)\" .. \n        qed } hence \"t \\<in> RED (T \\<sigma>)\" by simp\n    } thus \"CR3 (T \\<sigma>)\" unfolding CR3_def CR3_RED_def by blast\n  }\nqed\n\ntext \\<open>The last case above shows that, once all the reasoning principles have\nbeen established, some proofs have a formalization which is amazingly close to\nthe informal version. For a direct comparison, the informal proof is presented\nin Figure~\\ref{fig:cr3}.\\<close>\n\ntext_raw \\<open>\\input{figureCR3}\\<close>\n\ntext \\<open>Now that we have established the properties of the reducibility\nrelation, we need to show that reducibility is preserved by the various term\nconstructors. The only nontrivial cases are abstraction and sequencing.\\<close>\n\nsection \\<open>Abstraction Preserves Reducibility\\<close>    \n\ntext \\<open>Once again we could reuse the proofs from \\cite{SN.thy}. The proof uses\nthe \\isa{double-SN} rule and the lemma \\isa{red-Lam} below. Unfortunately, this\ntime the proofs are not fully identical to the proofs in \\cite{SN.thy} because\nwe consider $\\beta\\eta$-reduction rather than $\\beta$-reduction only. However,\nthe differences are only minor.\\<close>\n    \nlemma%invisible double_SN_aux:\n  assumes a: \"SN a\"\n  and b: \"SN b\"\n  and hyp: \"\\<And>x z.\n    \\<lbrakk>\\<And>y. x \\<mapsto> y \\<Longrightarrow> SN y; \\<And>y. x \\<mapsto> y \\<Longrightarrow> P y z;\n     \\<And>u. z \\<mapsto> u \\<Longrightarrow> SN u; \\<And>u. z \\<mapsto> u \\<Longrightarrow> P x u\\<rbrakk> \\<Longrightarrow> P x z\"\n  shows \"P a b\"\nproof -\n  from a\n  have r: \"\\<And>b. SN b \\<Longrightarrow> P a b\"\n  proof (induct a rule: SN.induct)\n    case (SN_intro x)\n    note SNI' = SN_intro\n    have \"SN b\" by fact\n    thus ?case\n    proof (induct b rule: SN.induct)\n      case (SN_intro y)\n      show ?case\n        apply (rule hyp)\n        apply (erule SNI')\n        apply (erule SNI')\n        apply (rule SN.SN_intro)\n        apply (erule SN_intro)+\n        done\n    qed\n  qed\n  from b show ?thesis by (rule r)\nqed\n\nlemma double_SN[consumes 2]:\n  assumes a: \"SN a\"\n  and     b: \"SN b\" \n  and     c: \"\\<And>(x::trm) (z::trm). \n             \\<lbrakk>\\<And>y. x \\<mapsto> y \\<Longrightarrow> P y z; \\<And>u. z \\<mapsto> u \\<Longrightarrow> P x u\\<rbrakk> \\<Longrightarrow> P x z\"\n  shows \"P a b\"\nusing a b c\nby%invisible (blast intro: double_SN_aux)\n\nlemma red_Lam:\n  assumes a: \"\\<Lambda> x . t \\<mapsto> r\" \n  shows \" (\\<exists>t'. r = \\<Lambda> x . t' \\<and> t \\<mapsto> t') \\<or> (t = App r (Var x) \\<and> x \\<sharp> r ) \"\nproof -\n  obtain z::name where z: \"z \\<sharp> x\"   \"z \\<sharp> t\"   \"z \\<sharp> r\" \n    using ex_fresh[of \"(x,t,r)\"] by (auto simp add: fresh_prod)\n  have \"x \\<sharp> \\<Lambda> x . t\" by (simp add: abs_fresh)\n  with a have \"x \\<sharp> r\" by (simp add: reduction_fresh)\n  with a show ?thesis using z\n    by(cases rule: reduction.strong_cases\n       [where x =\"x\" and xa=\"x\" and xb=\"x\" and xc=\"x\" and \n              xd=\"x\" and xe=\"x\" and xf=\"x\" and xg=\"x\" and y=\"z\"])\n        (auto simp add: abs_fresh alpha fresh_atm)\nqed\n\nlemma abs_RED: \n  assumes asm: \"\\<forall>s\\<in>RED \\<tau>. t[x::=s]\\<in>RED \\<sigma>\"\n  shows \"\\<Lambda> x . t \\<in>RED (\\<tau>\\<rightarrow>\\<sigma>)\"\nproof %invisible -\n  have b1: \"SN t\" \n  proof -\n    have \"Var x\\<in>RED \\<tau>\"\n    proof -\n      have \"CR4 \\<tau>\" by (simp add: RED_props CR3_implies_CR4)\n      moreover\n      have \"NEUT (Var x)\" by (auto simp add: NEUT_def)\n      moreover\n      have \"NORMAL (Var x)\" by (rule normal_var) \n      ultimately show \"Var x\\<in>RED \\<tau>\" by (simp add: CR4_def)\n    qed\n    then have \"t[x::=Var x]\\<in>RED \\<sigma>\" using asm by simp\n    then have \"t\\<in>RED \\<sigma>\" by (simp add: id_subs)\n    moreover \n    have \"CR1 \\<sigma>\" by (simp add: RED_props)\n    ultimately show \"SN t\" by (simp add: CR1_def)\n  qed\n  show \"\\<Lambda> x .t\\<in>RED (\\<tau>\\<rightarrow>\\<sigma>)\"\n  proof (simp, intro strip)\n    fix u\n    assume b2: \"u\\<in>RED \\<tau>\"\n    then have b3: \"SN u\" using RED_props by (auto simp add: CR1_def)\n    show \"App (\\<Lambda> x .t) u \\<in> RED \\<sigma>\" using b1 b3 b2 asm\n    proof(induct t u rule: double_SN)\n      fix t u\n      assume ih1: \"\\<And>t'.  \\<lbrakk>t \\<mapsto> t'; u\\<in>RED \\<tau>; \\<forall>s\\<in>RED \\<tau>. t'[x::=s]\\<in>RED \\<sigma>\\<rbrakk> \\<Longrightarrow> App (\\<Lambda> x\n.t') u \\<in>\nRED \\<sigma>\" \n      assume ih2: \"\\<And>u'.  \\<lbrakk>u \\<mapsto> u'; u'\\<in>RED \\<tau>; \\<forall>s\\<in>RED \\<tau>. t[x::=s]\\<in>RED \\<sigma>\\<rbrakk> \\<Longrightarrow> App (\\<Lambda> x\n.t) u' \\<in>\nRED \\<sigma>\"\n      assume as1: \"u \\<in> RED \\<tau>\"\n      assume as2: \"\\<forall>s\\<in>RED \\<tau>. t[x::=s]\\<in>RED \\<sigma>\"\n      have \"CR3_RED (App (\\<Lambda> x. t) u) \\<sigma>\" unfolding CR3_RED_def\n      proof(intro strip)\n        fix r\n        assume red: \"App (\\<Lambda> x .t) u \\<mapsto> r\"\n        moreover\n        { assume \"\\<exists>t'. t \\<mapsto> t' \\<and> r = App (\\<Lambda> x . t') u\"\n          then obtain t' where a1: \"t \\<mapsto> t'\" and a2: \"r = App (\\<Lambda> x .t') u\" by\nblast\n          have \"App (\\<Lambda> x .t') u\\<in>RED \\<sigma>\" using ih1 a1 as1 as2\n            apply(auto)\n            apply(drule_tac x=\"t'\" in meta_spec)\n            apply(simp)\n            apply(drule meta_mp)\n            prefer 2\n            apply(auto)[1]\n            apply(rule ballI)\n            apply(drule_tac x=\"s\" in bspec)\n            apply(simp)\n            apply(subgoal_tac \"CR2 \\<sigma>\")(*A*)\n            apply(unfold CR2_def)[1]\n            apply(drule_tac x=\"t[x::=s]\" in spec)\n            apply(drule_tac x=\"t'[x::=s]\" in spec)\n            apply(simp add: reduction_subst)\n            (*A*)\n            apply(simp add: RED_props)\n            done\n          then have \"r\\<in>RED \\<sigma>\" using a2 by simp\n        } note rt = this\n        moreover\n        { assume \"\\<exists>u'. u \\<mapsto> u' \\<and> r = App (\\<Lambda> x . t) u'\"\n          then obtain u' where b1: \"u \\<mapsto> u'\" and b2: \"r = App (\\<Lambda> x .t) u'\" by\nblast\n          have \"App (\\<Lambda> x .t) u'\\<in>RED \\<sigma>\" using ih2 b1 as1 as2\n            apply(auto)\n            apply(drule_tac x=\"u'\" in meta_spec)\n            apply(simp)\n            apply(drule meta_mp)\n            apply(subgoal_tac \"CR2 \\<tau>\")\n            apply(unfold CR2_def)[1]\n            apply(drule_tac x=\"u\" in spec)\n            apply(drule_tac x=\"u'\" in spec)\n            apply(simp)\n            apply(simp add: RED_props)\n            apply(simp)\n            done\n          then have \"r\\<in>RED \\<sigma>\" using b2 by simp\n        } note ru= this\n        moreover\n        { assume \"r = t[x::=u]\"\n          then have \"r\\<in>RED \\<sigma>\" using as1 as2 by auto\n        } note r = this\n        \n        ultimately show \"r \\<in> RED \\<sigma>\" \n          (* one wants to use the strong elimination principle; for this one \n             has to know that x\\<sharp>u *)\n        apply(cases) \n        apply(auto)\n        apply(drule red_Lam)\n        apply(drule disjE)prefer 3 apply simp\n        apply(auto)[1]\n        prefer 2\n        apply(auto simp add: alpha subst_rename')[1]\n        apply(subgoal_tac \"App s' u = t[x::=u]\")\n        apply(auto)\n        apply(auto simp add: forget)\n        done\n    qed\n    moreover \n    have \"NEUT (App (\\<Lambda> x . t) u)\" unfolding NEUT_def by (auto)\n    ultimately show \"App (\\<Lambda> x . t) u \\<in> RED \\<sigma>\"  using RED_props by (simp add:\nCR3_def)\n  qed\nqed\nqed\n\n\nsection \\<open>Sequencing Preserves Reducibility\\<close>\n\ntext \\<open>This section corresponds to the main part of the paper being formalized\nand as such deserves special attention. In the lambda case one has to formalize\ndoing induction on $\\max(s) + max(t)$ for two strongly normalizing terms $s$ and\n$t$ (cf. \\cite[Section 6.3]{proofs+types}). Above, this was done through a\n\\isa{double-SN}\nrule. The central Lemma 7 of Lindley and Stark's paper uses an even more\ncomplicated induction scheme. They assume terms $p$ and $n$ as well as a stack\n$K$ such that @{term \"SN(p)\"} and @{term \"SN(n[x::=p] \\<star> K)\"}. The induction is\nthen done on $|K| + max(n \\star K) + max(p)$. See Figure~\\ref{fig:lemma7} in\nfor details.\\<close>\n\ntext_raw \\<open>\\input{figureLemma7}\\<close>\n\n\ntext \\<open>Since we have settled for a different characterization of strong\nnormalization, we have to derive an induction principle similar in spirit to the\n\\isa{double-SN} rule. \n\nFurthermore, it turns out that it is not necessary to formalize the fact that\nstack reductions do not increase the length of the stack.\\footnote{This\npossibility was only discovered \\textit{after} having formalized $ K \\mapsto K'\n\\Rightarrow |K| \\geq |K'|$. The proof of this seemingly simple fact\nwas about 90 lines of Isar code.} Doing induction on the sum above, this is\nnecessary to handle the case of a reduction occurring in $K$. We differ\nfrom \\cite{TT-lifting} and establish an induction principle which to some extent\nresembles the lexicographic order on $$(\\SN,\\mapsto) \\times (\\SN,\\mapsto) \\times\n(\\N,>)\\,.$$\\<close>\n\nlemma triple_induct[consumes 2]: \n  assumes a: \"SN (p)\"\n  and b: \"SN (q)\"\n  and hyp: \"\\<And> (p::trm) (q::trm) (k::stack) . \n  \\<lbrakk> \\<And> p' . p \\<mapsto> p' \\<Longrightarrow> P p' q k ; \n    \\<And> q' k . q \\<mapsto> q' \\<Longrightarrow> P p q' k; \n    \\<And> k' .  |k'| < |k| \\<Longrightarrow> P p q k' \\<rbrakk> \\<Longrightarrow> P p q k \"\n  shows \"P p q k\"\nproof -\n  from a have \"\\<And>q K . SN q \\<Longrightarrow> P p q K\"\n  proof (induct p)\n    case (SN_intro p) \n    have sn1: \"\\<And> p' q K . \\<lbrakk>p \\<mapsto> p'; SN q\\<rbrakk> \\<Longrightarrow> P p' q K\" by fact\n    have sn_q: \"SN q\"   \"SN q\" by fact+\n    thus \"P p q K\"\n    proof (induct q arbitrary: K) \n      case (SN_intro q K)\n      have sn2: \"\\<And> q' K . \\<lbrakk>q \\<mapsto> q'; SN q'\\<rbrakk> \\<Longrightarrow> P p q' K\" by fact\n      show \"P p q K\"\n      proof (induct K rule: measure_induct_rule[where f=\"length\"])\n        case (less k)\n        have le: \"\\<And> k' . |k'| < |k| \\<Longrightarrow> P p q k'\" by fact\n        { fix p' assume \"p \\<mapsto> p'\"\n          moreover have \"SN q\" by fact\n          ultimately have \"P p' q k\" using sn1 by auto }\n        moreover\n        { fix q' K  assume r: \"q \\<mapsto> q'\" \n          have \"SN q\" by fact\n          hence \"SN q'\" using r by (rule SN_preserved)\n          with r have \"P p q' K\" using sn2 by auto }\n        ultimately show ?case using le\n          by (auto intro:hyp)\n      qed\n    qed\n  qed \n  with b show ?thesis by blast\nqed\n\n\ntext \\<open>Here we strengthen the case rule for terms of the form @{term \"t \\<star> k \\<mapsto>\nr\"}. The freshness requirements on $x$,$y$, and $z$\ncorrespond to those for the rule \\isa{reduction.strong-cases}, the strong\ninversion principle for the reduction relation.\\<close>\n\n\nlemma dismantle_strong_cases:\n  fixes t :: trm\n  assumes r: \"t \\<star> k \\<mapsto> r\"\n  and f: \"y \\<sharp> (t,k,r)\"   \"x \\<sharp> (z,t,k,r)\"   \"z \\<sharp> (t,k,r)\"\n  and T: \"\\<And> t' . \\<lbrakk> t \\<mapsto> t' ; r = t' \\<star> k \\<rbrakk> \\<Longrightarrow> P\"\n  and K: \"\\<And> k' . \\<lbrakk> k \\<mapsto> k' ; r = t \\<star> k' \\<rbrakk> \\<Longrightarrow> P\" \n  and B: \"\\<And> s n l . \\<lbrakk> t = [s] ; \n                       k = [y]n\\<ggreater>l ; r = (n[y::=s]) \\<star> l \\<rbrakk> \\<Longrightarrow> P \"\n  and A: \"\\<And> u v n l . \n           \\<lbrakk> x \\<sharp> (z,n); t = u to x in v ; k = [z]n\\<ggreater>l ; \n             r = (u to x in (v to z in n)) \\<star> l \\<rbrakk> \\<Longrightarrow> P \"\n  shows \"P\"\nproof (cases rule:dismantle_cases[of t k r P])\n  case (4 s y' n L) have ch:\n    \"t = [s]\"\n    \"k = [y']n\\<ggreater>L\"\n    \"r = n[y'::=s] \\<star> L\" by fact+\n  txt \\<open>The equations we get look almost like those we need to instantiate the\nhypothesis \\isa{B}. The only difference is that \\isa{B} only applies to $y$, and\nsince we want $y$ to become an instantiation variable of the strengthened rule,\nwe only know that $y$ satisfies \\isa{f} and nothing else. But the condition\n\\isa{f} is just strong enough to rename $y'$ to $y$ and apply \\isa{B}.\\<close>\n  with f have \"y = y' \\<or> y \\<sharp> n\" \n    by (auto simp add: fresh_prod abs_fresh)\n  hence \"n[y'::=s] = ([(y,y')] \\<bullet> n)[y::=s]\" \n    and \"[y']n\\<ggreater>L = [y]([(y,y')] \\<bullet> n)\\<ggreater>L\"\n    by(auto simp add: name_swap_bij subst_rename' stack.inject alpha' )\n  with ch have \"t = [s]\" \n    \"k = [y]([(y,y')] \\<bullet> n)\\<ggreater>L\" \n    \"r = ([(y,y')] \\<bullet> n)[y::=s] \\<star> L\"\n    by (auto)\n  thus \"P\" by (rule B) \nnext \n  case (5 u x' v z' n L) have ch:\n    \"x' \\<sharp> z'\"   \"x' \\<sharp> n\"\n    \"t = u to x' in v\"\n    \"k = [z']n\\<ggreater>L\"\n    \"r = (u to x' in v to z' in n) \\<star> L\" by fact+ \n  txt \\<open>We want to do the same trick as above but at this point we have to take\ncare of the possibility that $x$ might coincide with $x'$ or $z'$. Similarly,\n$z$\nmight coincide with $z'$.\\<close>\n  with f have x: \"x = x' \\<or> x \\<sharp> v to z' in n\" \n    and z: \"z = z' \\<or> z \\<sharp> n\"\n    by (auto simp add: fresh_prod abs_fresh)\n  from f ch have x': \"x' \\<sharp> n\"   \" x' \\<sharp> z'\" \n    and xz': \"x = z' \\<or> x \\<sharp> n\" \n    by (auto simp add:name_swap_bij alpha fresh_prod fresh_atm abs_fresh)\n  from f ch have \"x \\<sharp> z\" \"x \\<sharp> [z'].n\" by (auto simp add:  fresh_prod)\n  with xz' z have  \" x \\<sharp> (z , ([(z, z')] \\<bullet> n))\" \n    by (auto simp add: fresh_atm fresh_bij name_swap_bij \n          fresh_prod abs_fresh calc_atm fresh_aux fresh_left)\n  moreover from x ch have \"t = u to x in ([(x,x')] \\<bullet> v)\" \n    by (auto simp add:name_swap_bij alpha')\n  moreover from z ch have \"k = [z]([(z,z')] \\<bullet> n)\\<ggreater>L\"\n    by (auto simp add:name_swap_bij stack.inject alpha')\n  txt \\<open>The first two $\\alpha$-renamings are simple, but here we have to handle\nthe nested binding structure of the assoc rule. Since $x$ scopes over the whole\nterm @{term \"(v to z' in n)\" }, we have to push the swapping over $z'$\\<close>\n  moreover { from x have \n    \"u to x' in (v to z' in n) = u to x in ([(x,x')] \\<bullet> (v to z' in n))\"\n      by (auto simp add:name_swap_bij alpha' simp del: trm.perm)\n    also from xz' x' have \"\\<dots> = u to x in (([(x,x')] \\<bullet> v) to z' in n)\"\n      by (auto simp add: abs_fun_eq1 swap_simps alpha'') \n           (metis alpha'' fresh_atm perm_fresh_fresh swap_simps(1) x')\n    also from z have \" \\<dots> = u to x in (([(x,x')] \\<bullet> v) to z in ([(z,z')] \\<bullet> n))\"\n      by (auto simp add: abs_fun_eq1 alpha' name_swap_bij )\n    finally \n      have \"r =  (u to x in (([(x, x')] \\<bullet> v) to z in ([(z, z')] \\<bullet> n))) \\<star> L\" \n        using ch by (simp del: trm.inject) }\n  ultimately show \"P\" \n    by (rule A[where n=\"[(z, z')] \\<bullet> n\" and v=\"([(x, x')] \\<bullet> v)\"]) \nqed (insert r T K, auto)\n\n\ntext \\<open>The lemma in Figure~\\ref{fig:lemma7} assumes @{term \"SN(n[x::=p] \\<star> K)\"}\nbut the actual induction in done on @{term \"SN(n \\<star> K)\"}. The stronger\nassumption @{term \"SN (n[x::=p] \\<star> K)\"} is needed to handle the $\\beta$ and\n$\\eta$ cases.\\<close>\n\nlemma sn_forget:\n  assumes a: \"SN(t[x::=v])\"\n  shows \"SN t\"\nproof -\n  define q where \"q = t[x::=v]\"\n  from a have \"SN q\" unfolding q_def .\n  thus \"SN t\" using q_def\n  proof (induct q arbitrary: t)\n    case (SN_intro t)\n    hence ih: \"\\<And> t'. \\<lbrakk>t[x::=v] \\<mapsto> t'[x::=v]\\<rbrakk> \\<Longrightarrow> SN t'\" by auto\n    { fix t' assume \"t \\<mapsto> t'\"\n      hence \"t[x::=v] \\<mapsto> t'[x::=v]\" by (rule reduction_subst)\n      hence \"SN t'\" by (rule ih) }\n    thus \"SN t\" ..\n  qed\nqed\n\n          \nlemma sn_forget': \n  assumes sn: \"SN (t[x::=p] \\<star> k)\" \n  and x: \"x \\<sharp> k\"\n  shows \"SN (t \\<star> k)\"\nproof -\n  from x have \"t[x::=p] \\<star> k = (t \\<star> k)[x::=p]\" by (simp add: ssubst_forget)\n  with sn have \"SN( (t \\<star> k)[x::=p] )\" by simp\n  thus ?thesis by (rule sn_forget)\nqed\n\nabbreviation\nredrtrans :: \"trm \\<Rightarrow> trm \\<Rightarrow> bool\" (\" _ \\<mapsto>\\<^sup>* _ \" )\nwhere \"redrtrans \\<equiv> reduction^**\" \n\ntext \\<open>To be able to handle the case where $p$ makes a step, we need to\nestablish @{term \"p \\<mapsto> p' \\<Longrightarrow> (m[x::=p]) \\<mapsto>\\<^sup>* (m[x::=p'])\"} as well as the\nfact that strong normalization is preserved for an arbitrary number of reduction\nsteps. The first claim involves a number of simple transitivity lemmas. Here we\ncan benefit from having removed the freshness conditions from the reduction\nrelation as this allows all the cases to be proven automatically. Similarly, in\nthe \\isa{red-subst} lemma, only those cases where substitution is pushed to two\nsubterms needs to be proven explicitly.\\<close>\n\nlemma red_trans:\n  shows r1_trans: \" s \\<mapsto>\\<^sup>* s' \\<Longrightarrow> App s t \\<mapsto>\\<^sup>* App s' t\"\n  and r2_trans: \" t \\<mapsto>\\<^sup>* t' \\<Longrightarrow> App s t \\<mapsto>\\<^sup>* App s t'\"\n  and r4_trans: \"t \\<mapsto>\\<^sup>* t' \\<Longrightarrow> \\<Lambda> x . t \\<mapsto>\\<^sup>* \\<Lambda> x . t' \"\n  and r6_trans: \" s \\<mapsto>\\<^sup>* s'  \\<Longrightarrow> s to x in t \\<mapsto>\\<^sup>* s' to x in t\"\n  and r7_trans: \"\\<lbrakk> t \\<mapsto>\\<^sup>* t'  \\<rbrakk> \\<Longrightarrow> s to x in t \\<mapsto>\\<^sup>* s  to x in t'\"\n  and r11_trans: \"s \\<mapsto>\\<^sup>* s' \\<Longrightarrow> [s] \\<mapsto>\\<^sup>* ([s'])\"\nby - (induct rule: rtranclp_induct , (auto intro:\ntransitive_closurep_trans')[2])+\n\nlemma red_subst: \"p \\<mapsto> p' \\<Longrightarrow> (m[x::=p]) \\<mapsto>\\<^sup>* (m[x::=p'])\"\nproof(nominal_induct m avoiding: x p p' rule:trm.strong_induct)\n  case (App s t) \n  hence \"App (s[x::=p]) (t[x::=p]) \\<mapsto>\\<^sup>* App (s[x::=p']) (t[x::=p])\" \n    by (auto intro: r1_trans)\n  also from App have \"\\<dots> \\<mapsto>\\<^sup>* App (s[x::=p']) ( t[x::=p'])\"\n    by (auto intro: r2_trans)\n  finally show ?case by auto\nnext\n  case (To s y n) hence \n    \"(s[x::=p]) to y in (n[x::=p]) \\<mapsto>\\<^sup>* (s[x::=p']) to y in (n[x::=p])\" \n    by (auto intro: r6_trans)\n  also from To have \" \\<dots> \\<mapsto>\\<^sup>* (s[x::=p']) to y in (n[x::=p']) \"\n    by (auto intro: r7_trans)\n  finally show ?case using To by auto\nqed (auto intro:red_trans)\n\nlemma SN_trans : \"\\<lbrakk>  p \\<mapsto>\\<^sup>* p' ; SN p \\<rbrakk> \\<Longrightarrow> SN p' \"\nby (induct rule: rtranclp_induct) (auto intro: SN_preserved)\n\nsubsection \\<open>Central lemma\\<close>\ntext_raw \\<open>\\label{sec:central}\\<close>\n\ntext \\<open>Now we have everything in place we need to tackle the central ``Lemma\n7'' of \\cite{TT-lifting} (cf. Figure~\\ref{fig:lemma7}). The proof is quite long,\nbut for the most part, the reasoning is that of \\cite{TT-lifting}.\\<close>\n\nlemma to_RED_aux: \n  assumes p: \"SN p\"\n  and x: \"x \\<sharp> p\"   \"x \\<sharp> k\"\n  and npk: \" SN (n[x::=p] \\<star> k)\"\n  shows \"SN (([p] to x in n) \\<star> k)\"\nproof -\n  { fix q assume \"SN q\" with p \n    have  \"\\<And> m . \\<lbrakk> q = m \\<star> k ; SN(m[x::=p] \\<star> k) \\<rbrakk> \n               \\<Longrightarrow> SN (([p] to x in m) \\<star> k)\"\n      using x\n    proof (induct p q rule:triple_induct[where k=\"k\"]) \n      case (1 p q k) \\<comment> \\<open>We obtain an induction hypothesis for $p$, $q$, and\n$k$.\\<close>\n      have ih_p: \n        \"\\<And> p' m . \\<lbrakk>p \\<mapsto> p'; q = m \\<star> k; SN (m[x::=p'] \\<star> k); x \\<sharp> p'; x \\<sharp> k\\<rbrakk>\n            \\<Longrightarrow> SN (([p'] to x in m) \\<star> k)\" by fact\n      have ih_q: \n        \"\\<And> q' m k . \\<lbrakk>q \\<mapsto> q'; q' = m \\<star> k; SN (m[x::=p] \\<star> k); x \\<sharp> p; x \\<sharp> k\\<rbrakk>\n            \\<Longrightarrow> SN (([p] to x in m) \\<star> k)\" by fact\n      have ih_k: \n        \"\\<And> k' m . \\<lbrakk> |k'| < |k|; q = m \\<star> k'; SN (m[x::=p] \\<star> k'); x \\<sharp> p; x \\<sharp> k'\\<rbrakk>\n            \\<Longrightarrow> SN (([p] to x in m) \\<star> k')\" by fact\n      have q: \"q = m \\<star> k\" and sn: \"SN (m[x::=p] \\<star> k)\" by fact+\n      have xp: \"x \\<sharp> p\" and xk: \"x \\<sharp> k\" by fact+\n\ntxt \\<open>Once again we want to reason via case distinction on the successors of a\nterm including a dismantling operator. Since this time we also need to handle\nthe cases where interactions occur, we want to use the strengthened case\nrule. We already require $x$ to be suitably fresh. To instantiate the rule, we\nneed another fresh name.\\<close>\n\n      { fix r assume red: \"([p] to x in m) \\<star> k \\<mapsto> r\"\n        from xp xk have x1 : \"x \\<sharp> ([p] to x in m) \\<star> k \"  \n          by (simp add: abs_fresh)\n        with red have x2: \"x \\<sharp> r\" by (rule reduction_fresh)\n        obtain z::name where z: \"z \\<sharp> (x,p,m,k,r)\" \n          using ex_fresh[of \"(x,p,m,k,r)\"] by (auto simp add: fresh_prod)\n        have \"SN r\"\n        proof (cases rule:dismantle_strong_cases\n            [of   \"[p] to x in m\"   k r x x z ])\n          case (5 r') have r: \"r = r' \\<star> k\" and r': \"[p] to x in m \\<mapsto> r'\" by fact+\n          txt \\<open>To handle the case of a reduction occurring somewhere in @{term\n\"[p] to x in m\" }, we need to contract the freshness conditions to this subterm.\nThis allows the use of the strong inversion rule for the reduction relation.\\<close>\n          from x1 x2 r \n          have xl:\"(x \\<sharp> [p] to x in m)\" and xr:\"x \\<sharp> r'\" by auto\n          from z have zl: \"z \\<sharp> ([p] to x in m)\"   \"x \\<noteq> z\" \n            by (auto simp add: abs_fresh fresh_prod fresh_atm)\n          with r' have zr: \"z \\<sharp> r'\"  by (blast intro:reduction_fresh)\n          \\<comment> \\<open>handle all reductions of @{term \"[p] to x in m\"}\\<close>\n          from r' show \"SN r\" proof (cases rule:reduction.strong_cases\n              [where x=\"x\" and xa=\"x\" and xb=\"x\" and xc=\"x\" and xd=\"x\" \n                and xe=\"x\" and xf=\"x\"and xg=\"x\" and y=\"z\"])\ntxt \\<open>The case where @{term \"p \\<mapsto> p'\"} is interesting, because it requires\nreasioning about the reflexive transitive closure of the reduction relation.\\<close>\n            case (r6 s s' t)  hence ch: \"[p] \\<mapsto> s'\"   \"r' = s' to x in m\" \n              using xl xr by (auto)\n            from this obtain p' where s: \"s' = [p']\" and  p : \"p \\<mapsto> p'\" \n              by (blast dest:red_Ret)\n            from p have \"((m\\<star>k)[x::=p]) \\<mapsto>\\<^sup>* ((m\\<star>k)[x::=p'])\" \n              by (rule red_subst)\n            with xk have \"((m[x::=p]) \\<star> k) \\<mapsto>\\<^sup>* ((m[x::=p']) \\<star> k)\" \n              by (simp add: ssubst_forget)\n            hence sn: \"SN ((m[x::=p']) \\<star> k)\" using sn by (rule SN_trans)\n            from p xp have xp' : \"x \\<sharp> p'\" by (rule reduction_fresh)\n            from ch s have rr: \"r' = [p'] to x in m\" by simp\n            from p q  sn xp' xk\n            show \"SN r\" unfolding r rr by (rule ih_p)\n          next\n\n            case(r7 s t m') hence \"r' = [p] to x in m'\" and \"m \\<mapsto> m'\" \n              using xl xr by (auto simp add: alpha)\n            hence rr: \"r' = [p] to x in m'\" by simp\n            from q \\<open>m \\<mapsto> m'\\<close> have  \"q \\<mapsto> m' \\<star> k\" by(simp add: dismantle_red)\n            moreover have \"m' \\<star> k = m' \\<star> k\" .. \\<comment> \\<open>a triviality\\<close>\n            moreover { from \\<open>m \\<mapsto> m'\\<close> have \"(m[x::=p]) \\<star> k \\<mapsto> (m'[x::=p]) \\<star> k\"\n                by (simp add: dismantle_red reduction_subst)\n              with sn have \"SN(m'[x::=p] \\<star> k)\" .. }\n            ultimately show \"SN r\" using xp xk unfolding r rr by (rule ih_q)\n          next  \n              \n            case (r8 s t) \\<comment> \\<open>the $\\beta$-case is handled by assumption\\<close>\n            hence \"r' = m[x::=p]\" using xl xr by(auto simp add: alpha)\n            thus \"SN r\" unfolding r using sn by simp\n          next \n\n            case (r9 s) \\<comment> \\<open>the $\\eta$-case is handled by assumption as well\\<close> \n            hence \"m = [Var x]\" and \"r' = [p]\" using xl xr \n              by(auto simp add: alpha)\n            hence \"r' = m[x::=p]\" by simp\n            thus \"SN r\" unfolding r using sn by simp\n          qed (simp_all only: xr xl zl zr abs_fresh , auto)\n          \\<comment> \\<open>There are no other possible reductions of @{term \"[p] to x in\nm\"}.\\<close>\n        next\n\n          case (6 k') \n          have k: \"k \\<mapsto> k'\" and r: \"r = ([p] to x in m) \\<star> k'\" by fact+\n          from q k have \"q \\<mapsto> m \\<star> k'\" unfolding stack_reduction_def by blast\n          moreover have \"m \\<star> k' = m \\<star> k'\" ..\n          moreover { have \"SN (m[x::=p] \\<star> k)\" by fact\n            moreover have \"(m[x::=p]) \\<star> k \\<mapsto> (m[x::=p]) \\<star> k'\" \n              using k unfolding stack_reduction_def .. \n            ultimately have \"SN (m[x::=p] \\<star> k')\" .. }\n          moreover note xp \n          moreover from k xk  have \"x \\<sharp> k'\"\n            by (rule stack_reduction_fresh)\n          ultimately show \"SN r\" unfolding r by (rule ih_q)\n        next\ntxt \\<open>The case of an assoc interaction between @{term \"[p] to x in m\" } and\n@{term \"k\"} is easily handled by the induction hypothesis, since @{term\n\"(m[x::=p]) \\<star> k\"} remains fixed under assoc.\\<close>\n          case (8 s t u L)\n          hence k: \"k = [z]u\\<ggreater>L\"\n            and r: \"r = ([p] to x in (m to z in u)) \\<star> L\" \n            and u: \"x \\<sharp> u\" \n            by(auto simp add: alpha fresh_prod)\n          let ?k = L and ?m = \"m to z in u\"\n          from k z have \"|?k| < |k|\" by (simp add: fresh_prod)\n          moreover have \"q =  ?m \\<star> ?k\" using k q by simp\n          moreover { from k u z xp have \"(?m[x::=p] \\<star> ?k) = (m[x::=p]) \\<star> k\" \n            by(simp add: fresh_prod forget)\n          hence \"SN (?m[x::=p] \\<star> ?k)\" using sn by simp }\n          moreover from xp xk k have \"x \\<sharp> p\" and \"x \\<sharp> ?k\" by auto\n          ultimately show \"SN r\" unfolding r by (rule ih_k)\n        qed (insert red z x1 x2 xp xk ,\n            auto simp add: fresh_prod fresh_atm abs_fresh)\n      } thus \"SN (([p] to x in m) \\<star> k)\" ..\n    qed } \n  moreover have \"SN ((n[x::=p]) \\<star> k)\" by fact\n  moreover hence \"SN (n \\<star> k)\" using \\<open>x \\<sharp> k\\<close> by (rule sn_forget') \n  ultimately show ?thesis by blast\nqed\n\ntext \\<open>Having established the claim above, we use it show that\n\\textsf{to}-bindings preserve reducibility.\\<close>\n\nlemma to_RED:\n  assumes s: \"s \\<in> RED (T \\<sigma>)\"\n  and t : \" \\<forall> p \\<in> RED \\<sigma> . t[x::=p] \\<in> RED (T \\<tau>)\"\n  shows \"s to x in t \\<in> RED (T \\<tau>)\"\nproof -\n  { fix K assume k: \"K \\<in> SRED \\<tau>\" \n    { fix p assume p: \"p \\<in> RED \\<sigma>\"\n      hence snp: \"SN p\" using RED_props by(simp add: CR1_def)\n      obtain x'::name where x: \"x' \\<sharp> (t, p, K)\" \n        using ex_fresh[of \"(t,p,K)\"] by (auto)\n      from p t k have \"SN((t[x::=p]) \\<star> K)\" by auto\n      with x have \"SN ((([(x',x)] \\<bullet> t )[x'::=p]) \\<star> K)\" \n        by (simp add: fresh_prod subst_rename)\n      with snp x  have snx': \"SN (([p] to x' in ([(x',x)] \\<bullet> t )) \\<star> K)\" \n        by (auto intro: to_RED_aux)\n      from x have \"[p] to x' in ([(x',x)] \\<bullet> t ) = [p] to x in t\" \n        by simp (metis alpha' fresh_prod name_swap_bij x)\n      moreover have \"([p] to x in t) \\<star> K  = [p] \\<star> [x]t\\<ggreater>K\" by simp\n      ultimately have snx: \"SN([p] \\<star> [x]t\\<ggreater>K)\" using snx' \n        by (simp del: trm.inject)\n    } hence \"[x]t\\<ggreater>K \\<in> SRED \\<sigma>\" by simp\n    with s have \"SN((s to x in t) \\<star> K)\" by(auto simp del: SRED.simps) \n  } thus \"s to x in t \\<in> RED (T \\<tau>)\" by simp\nqed\n\n\nsection \\<open>Fundamental Theorem\\<close>\ntext_raw \\<open>\\label{sec:FTLR}\\<close>\n\ntext \\<open>The remainder of this section follows \\cite{SN.thy} very closely.  We\nfirst establish that all well typed terms are reducible if we substitute\nreducible terms for the free variables.\\<close>\n\nabbreviation \n mapsto :: \"(name\\<times>trm) list \\<Rightarrow> name \\<Rightarrow> trm \\<Rightarrow> bool\" (\"_ maps _ to _\" [55,55,55] 55)\nwhere\n \"\\<theta> maps x to e \\<equiv> (lookup \\<theta> x) = e\"\n\nabbreviation \n  closes :: \"(name\\<times>trm) list \\<Rightarrow> (name\\<times>ty) list \\<Rightarrow> bool\" (\"_ closes _\" [55,55] 55) \nwhere\n  \"\\<theta> closes \\<Gamma> \\<equiv> \\<forall>x \\<tau>. ((x,\\<tau>) \\<in> set \\<Gamma> \\<longrightarrow> (\\<exists>t. \\<theta> maps x to t \\<and> t \\<in> RED \\<tau>))\"\n\ntheorem fundamental_theorem: \n  assumes a: \"\\<Gamma> \\<turnstile> t : \\<tau>\"   and   b: \"\\<theta> closes \\<Gamma>\"\n  shows \"\\<theta><t> \\<in> RED \\<tau>\"\nusing a b\nproof(nominal_induct  avoiding: \\<theta> rule: typing.strong_induct)\n  case (t3 a \\<Gamma> \\<sigma> t \\<tau> \\<theta>) \\<comment> \\<open>lambda case\\<close> \n  {%invisible \n  have ih: \"\\<And>\\<theta>. \\<theta> closes ((a,\\<sigma>)#\\<Gamma>) \\<Longrightarrow> \\<theta><t> \\<in> RED \\<tau>\" by fact\n  have \\<theta>_cond: \"\\<theta> closes \\<Gamma>\" by fact\n  have fresh: \"a\\<sharp>\\<Gamma>\"   \"a\\<sharp>\\<theta>\" by fact+\n  from ih have \"\\<forall>s\\<in>RED \\<sigma>. ((a,s)#\\<theta>)<t> \\<in> RED \\<tau>\" \n    using fresh \\<theta>_cond fresh_context by simp\n  then have \"\\<forall>s\\<in>RED \\<sigma>. \\<theta><t>[a::=s] \\<in> RED \\<tau>\" \n    using fresh by (simp add: psubst_subst)\n  then have \"\\<Lambda> a . (\\<theta><t>) \\<in> RED (\\<sigma> \\<rightarrow> \\<tau>)\" by (simp only: abs_RED)\n  then show \"\\<theta><(\\<Lambda> a . t)> \\<in> RED (\\<sigma> \\<rightarrow> \\<tau>)\" using fresh by simp }\nnext\n  case (t5 x \\<Gamma> s \\<sigma> t \\<tau> \\<theta>) \\<comment> \\<open>to case\\<close>\n  have ihs : \"\\<And> \\<theta> . \\<theta> closes \\<Gamma> \\<Longrightarrow> \\<theta><s> \\<in> RED (T \\<sigma>)\" by fact\n  have iht : \"\\<And> \\<theta> . \\<theta> closes ((x, \\<sigma>) # \\<Gamma>) \\<Longrightarrow> \\<theta><t> \\<in> RED (T \\<tau>)\" by fact\n  have \\<theta>_cond: \"\\<theta> closes \\<Gamma>\" by fact\n  have fresh: \"x \\<sharp> \\<theta>\"  \"x \\<sharp> \\<Gamma>\"   \"x \\<sharp> s\" by fact+\n  from ihs have \"\\<theta><s> \\<in> RED (T \\<sigma>)\" using \\<theta>_cond by simp\n  moreover \n  { from iht have \"\\<forall>s\\<in>RED \\<sigma>. ((x,s)#\\<theta>)<t> \\<in> RED (T \\<tau>)\" \n      using fresh \\<theta>_cond fresh_context by simp\n    hence \"\\<forall>s\\<in>RED \\<sigma>. \\<theta><t>[x::=s] \\<in> RED (T \\<tau>)\" \n      using fresh by (simp add: psubst_subst) }\n  ultimately have \"(\\<theta><s>) to x in (\\<theta><t>) \\<in> RED (T \\<tau>)\" by (simp only: to_RED)\n  thus \"\\<theta><s to x in t> \\<in> RED (T \\<tau>)\" using fresh by simp\nqed auto \\<comment> \\<open>all other cases are trivial\\<close>\n\ntext \\<open>The final result then follows using the identity substitution, which is\n$\\Gamma$-closing since all variables are reducible at any type.\\<close>\n\nfun\n  \"id\" :: \"(name\\<times>ty) list \\<Rightarrow> (name\\<times>trm) list\"\nwhere\n  \"id []    = []\"\n| \"id ((x,\\<tau>)#\\<Gamma>) = (x,Var x)#(id \\<Gamma>)\"\n\nlemma id_maps: \n  shows \"(id \\<Gamma>) maps a to (Var a)\"\nby (induct \\<Gamma>) (auto)\n\nlemma id_fresh:\n  fixes x::\"name\"\n  assumes x: \"x \\<sharp> \\<Gamma>\"\n  shows \"x \\<sharp> (id \\<Gamma>)\"\nusing x\nby (induct \\<Gamma>) (auto simp add: fresh_list_nil fresh_list_cons)\n\nlemma id_apply: \n  shows \"(id \\<Gamma>)<t> = t\"\nby (nominal_induct t avoiding: \\<Gamma> rule: trm.strong_induct)\n   (auto simp add: id_maps id_fresh)\n\nlemma id_closes:\n  shows \"(id \\<Gamma>) closes \\<Gamma>\"\nproof - \n  { fix x \\<tau> assume \"(x,\\<tau>) \\<in> set \\<Gamma>\"\n    have \"CR4 \\<tau>\" by(simp add: RED_props CR3_implies_CR4)\n    hence \"Var x \\<in> RED \\<tau>\" \n      by(auto simp add: NEUT_def normal_var CR4_def)\n    hence \"(id \\<Gamma>) maps x to Var x \\<and> Var x \\<in> RED \\<tau>\"\n      by (simp add: id_maps) \n  } thus ?thesis by blast\nqed\n\nsubsection \\<open>Strong normalization theorem\\<close>\n\nlemma typing_implies_RED:  \n  assumes a: \"\\<Gamma> \\<turnstile> t : \\<tau>\"\n  shows \"t \\<in> RED \\<tau>\"\nproof -\n  have \"(id \\<Gamma>)<t>\\<in>RED \\<tau>\" \n  proof -\n    have \"(id \\<Gamma>) closes \\<Gamma>\" by (rule id_closes)\n    with a show ?thesis by (rule fundamental_theorem)\n  qed\n  thus\"t \\<in> RED \\<tau>\" by (simp add: id_apply)\nqed\n\ntheorem strong_normalization: \n  assumes a: \"\\<Gamma> \\<turnstile> t : \\<tau>\"\n  shows \"SN(t)\"\nproof -\n  from a have \"t \\<in> RED \\<tau>\" by (rule typing_implies_RED)\n  moreover have \"CR1 \\<tau>\" by (rule RED_props)\n  ultimately show \"SN(t)\" by (simp add: CR1_def)\nqed\n\ntext \\<open>This finishes our formalization effort. This article is generated\nfrom the Isabelle theory file, which consists of roughly 1500 lines of proof\ncode. The reader is invited to replay some of the more technical proofs using\nthe theory file provided.\\<close>\n\n(*<*)end(*>*)\n\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Lam-ml-Normalization/Lam_ml.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5078118642792044, "lm_q2_score": 0.5273165233795672, "lm_q1q2_score": 0.2677775868026067}}
{"text": "theory Calls\n  imports \"artifact_setup.Artifact_Setup\"\n          \"Det_Step\"\nbegin\n\ncontext execution_context\nbegin\ntext \"To call a concrete function on a concrete state.\"\ndefinition call\\<^sub>c :: \"(state \\<Rightarrow> state) \\<Rightarrow> state \\<Rightarrow> state \\<Rightarrow> bool\"\n  where \"call\\<^sub>c f s s' \\<equiv> s' = (let s'' = f s in s''\\<lparr>regs := (regs s'')(rip := get_rip s + 5)\\<rparr>)\"\n\ntext \"To call an abstract function on an abstract state\"\ndefinition abstract\\<^sub>0 :: \"(state \\<Rightarrow> '\\<sigma>\\<^sub>C \\<times> '\\<sigma>\\<^sub>C\\<^sub>C) \\<Rightarrow> _ \\<Rightarrow> unit \\<times> '\\<sigma>\\<^sub>C \\<Rightarrow> unit \\<times> '\\<sigma>\\<^sub>C \\<Rightarrow> bool\"\n  where \"abstract\\<^sub>0 S f \\<sigma> \\<sigma>' \\<equiv> \\<exists> s s' . call\\<^sub>c f s s' \\<and> ((), \\<L> S s') = \\<sigma>' \\<and> ((), \\<L> S s) = \\<sigma>\"\n\nlemma abstract_call\\<^sub>0:\n  shows \"call\\<^sub>c f s s' \\<Longrightarrow> abstract\\<^sub>0 S f ((), \\<L> S s) ((), \\<L> S s')\"\n  by (auto simp add: call\\<^sub>c_def Let_def abstract\\<^sub>0_def)\n\ndefinition abstract\\<^sub>1\\<^sub>_\\<^sub>3\\<^sub>2 :: \"(state \\<Rightarrow> '\\<sigma>\\<^sub>C \\<times> '\\<sigma>\\<^sub>C\\<^sub>C) \\<Rightarrow> _ \\<Rightarrow> 32 word \\<Rightarrow> unit \\<times> '\\<sigma>\\<^sub>C \\<Rightarrow> unit \\<times> '\\<sigma>\\<^sub>C \\<Rightarrow> bool\"\n  where \"abstract\\<^sub>1\\<^sub>_\\<^sub>3\\<^sub>2 S f p\\<^sub>0 \\<sigma> \\<sigma>' \\<equiv> \\<exists> s s' . EDI s = p\\<^sub>0 \\<and> call\\<^sub>c f s s' \\<and> ((), \\<L> S s') = \\<sigma>' \\<and> ((), \\<L> S s) = \\<sigma>\"\n\nlemma abstract_call\\<^sub>1\\<^sub>_\\<^sub>3\\<^sub>2:\n  shows \"EDI s = p\\<^sub>0 \\<Longrightarrow> call\\<^sub>c f s s' \\<Longrightarrow> abstract\\<^sub>1\\<^sub>_\\<^sub>3\\<^sub>2 S f p\\<^sub>0 ((), \\<L> S s) ((), \\<L> S s')\"\n  by (auto simp add: call\\<^sub>c_def Let_def abstract\\<^sub>1\\<^sub>_\\<^sub>3\\<^sub>2_def)\n\ndefinition abstract\\<^sub>1\\<^sub>_\\<^sub>6\\<^sub>4 :: \"(state \\<Rightarrow> '\\<sigma>\\<^sub>C \\<times> '\\<sigma>\\<^sub>C\\<^sub>C) \\<Rightarrow> _ \\<Rightarrow> 64 word \\<Rightarrow> unit \\<times> '\\<sigma>\\<^sub>C \\<Rightarrow> unit \\<times> '\\<sigma>\\<^sub>C \\<Rightarrow> bool\"\n  where \"abstract\\<^sub>1\\<^sub>_\\<^sub>6\\<^sub>4 S f p\\<^sub>0 \\<sigma> \\<sigma>' \\<equiv> \\<exists> s s' . RDI s = p\\<^sub>0 \\<and> call\\<^sub>c f s s' \\<and> ((), \\<L> S s') = \\<sigma>' \\<and> ((), \\<L> S s) = \\<sigma>\"\n\nlemma abstract_call\\<^sub>1\\<^sub>_\\<^sub>6\\<^sub>4:\n  shows \"RDI s = p\\<^sub>0 \\<Longrightarrow> call\\<^sub>c f s s' \\<Longrightarrow> abstract\\<^sub>1\\<^sub>_\\<^sub>6\\<^sub>4 S f p\\<^sub>0 ((), \\<L> S s) ((), \\<L> S s')\"\n  by (auto simp add: call\\<^sub>c_def Let_def abstract\\<^sub>1\\<^sub>_\\<^sub>6\\<^sub>4_def)\n\ndefinition abstract\\<^sub>2\\<^sub>_\\<^sub>6\\<^sub>4\\<^sub>_\\<^sub>3\\<^sub>2 :: \"(state \\<Rightarrow> '\\<sigma>\\<^sub>C \\<times> '\\<sigma>\\<^sub>C\\<^sub>C) \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> unit \\<times> '\\<sigma>\\<^sub>C \\<Rightarrow> unit \\<times> '\\<sigma>\\<^sub>C \\<Rightarrow> bool\"\n  where \"abstract\\<^sub>2\\<^sub>_\\<^sub>6\\<^sub>4\\<^sub>_\\<^sub>3\\<^sub>2 S f p\\<^sub>0 p\\<^sub>1 \\<sigma> \\<sigma>' \\<equiv> \\<exists> s s' . RDI s = p\\<^sub>0 \\<and> ESI s = p\\<^sub>1 \\<and> call\\<^sub>c f s s' \\<and> ((), \\<L> S s') = \\<sigma>' \\<and> ((), \\<L> S s) = \\<sigma>\"\n\nlemma abstract_call\\<^sub>2\\<^sub>_\\<^sub>6\\<^sub>4\\<^sub>_\\<^sub>3\\<^sub>2:\n  shows \"RDI s = p\\<^sub>0 \\<Longrightarrow> ESI s = p\\<^sub>1 \\<Longrightarrow> call\\<^sub>c f s s' \\<Longrightarrow> abstract\\<^sub>2\\<^sub>_\\<^sub>6\\<^sub>4\\<^sub>_\\<^sub>3\\<^sub>2 S f p\\<^sub>0 p\\<^sub>1 ((), \\<L> S s) ((), \\<L> S s')\"\n  by (auto simp add: call\\<^sub>c_def Let_def abstract\\<^sub>2\\<^sub>_\\<^sub>6\\<^sub>4\\<^sub>_\\<^sub>3\\<^sub>2_def)\n\ndefinition abstract\\<^sub>2\\<^sub>_\\<^sub>3\\<^sub>2_\\<^sub>3\\<^sub>2 :: \"(state \\<Rightarrow> '\\<sigma>\\<^sub>C \\<times> '\\<sigma>\\<^sub>C\\<^sub>C) \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> unit \\<times> '\\<sigma>\\<^sub>C \\<Rightarrow> unit \\<times> '\\<sigma>\\<^sub>C \\<Rightarrow> bool\"\n  where \"abstract\\<^sub>2\\<^sub>_\\<^sub>3\\<^sub>2_\\<^sub>3\\<^sub>2 S f p\\<^sub>0 p\\<^sub>1 \\<sigma> \\<sigma>' \\<equiv> \\<exists> s s' . EDI s = p\\<^sub>0 \\<and> ESI s = p\\<^sub>1 \\<and> call\\<^sub>c f s s' \\<and> ((), \\<L> S s') = \\<sigma>' \\<and> ((), \\<L> S s) = \\<sigma>\"\n\nlemma abstract_call\\<^sub>2\\<^sub>_\\<^sub>3\\<^sub>2\\<^sub>_\\<^sub>3\\<^sub>2:\n  shows \"EDI s = p\\<^sub>0 \\<Longrightarrow> ESI s = p\\<^sub>1 \\<Longrightarrow> call\\<^sub>c f s s' \\<Longrightarrow> abstract\\<^sub>2\\<^sub>_\\<^sub>3\\<^sub>2_\\<^sub>3\\<^sub>2 S f p\\<^sub>0 p\\<^sub>1 ((), \\<L> S s) ((), \\<L> S s')\"\n  by (auto simp add: call\\<^sub>c_def Let_def abstract\\<^sub>2\\<^sub>_\\<^sub>3\\<^sub>2_\\<^sub>3\\<^sub>2_def)\n\nend\nend", "meta": {"author": "ssrg-vt", "repo": "Luce-src", "sha": "f7f1ef0fd07bba48bcb3d5e32404db6013a5f1bc", "save_path": "github-repos/isabelle/ssrg-vt-Luce-src", "path": "github-repos/isabelle/ssrg-vt-Luce-src/Luce-src-f7f1ef0fd07bba48bcb3d5e32404db6013a5f1bc/tacas2020_artifact/isabelle/Calls.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6224593452091672, "lm_q2_score": 0.4301473485858429, "lm_q1q2_score": 0.26774923694420316}}
{"text": "theory ReduceProper\n  imports SafeSubRename ResMapValid\nbegin\n\nfun own_pairs where\n  \"own_pairs (ConstExp c) = {}\"\n| \"own_pairs (OpExp xop) = {}\"\n| \"own_pairs (VarExp v) = (case v of\n    VarType x \\<Rightarrow> {}\n    | LocType x y \\<Rightarrow> {(y, x)}\n  )\"  \n| \"own_pairs (PairExp e1 e2) = (own_pairs e1 \\<union> own_pairs e2)\"\n| \"own_pairs (IfExp e1 e2 e3) = (own_pairs e1 \\<union> own_pairs e2 \\<union> own_pairs e3)\"\n| \"own_pairs (LamExp x e) = own_pairs e\"  \n| \"own_pairs (AppExp e1 e2) = (own_pairs e1 \\<union> own_pairs e2)\"  \n  \n    (* ##### given a perm set, we derive its \"resource completion\" by taking all of the resources that are reachable from it.\n        in other words, for each permission z in s, we lookup its resource map, and take all of the resources in it, as well\n        as recursing on each resource. #####\n     *)  \n  \nfun path_lookup :: \"nres_map \\<Rightarrow> string \\<Rightarrow> string list \\<Rightarrow> string \\<Rightarrow> bool\" where\n  \"path_lookup rs_map z Nil x = (z = x)\"\n| \"path_lookup rs_map z (y # t) x = (case rs_map z of\n    None \\<Rightarrow> False\n    | Some r_s \\<Rightarrow> r_s (Loc y) \\<noteq> NoPerm \\<and> path_lookup rs_map y t x\n  )\"    \n\nlemma path_lookup_parent: \"\\<lbrakk> l \\<noteq> Nil; path_lookup rs_map z l x; valid_nres_map s rs_map \\<rbrakk> \\<Longrightarrow>\n  (\\<exists> l' y r_s. path_lookup rs_map z l' y \\<and> rs_map y = Some r_s \\<and> r_s (Loc x) \\<noteq> NoPerm )\"\n  apply (induct l arbitrary: z)\n   apply (auto)\n  apply (case_tac \"rs_map z\")\n   apply (auto)\n    (* case where we have reached x *)\n  apply (case_tac \"a = x\")\n   apply (rule_tac x=\"Nil\" in exI)\n   apply (auto)\n    (* otherwise, induct *)\n  apply (case_tac \"l = []\")\n   apply (auto)\n  apply (case_tac \"\\<exists>l' y. path_lookup rs_map a l' y \\<and> (\\<exists>r_s. rs_map y = Some r_s \\<and> r_s (Loc x) \\<noteq> NoPerm)\")\n   apply (erule_tac exE)\n   apply (auto)\n  apply (rule_tac x=\"a # l'\" in exI)\n  apply (auto)\n  done\n    \nlemma path_lookup_append: \"\\<lbrakk> path_lookup rs_map x l y; path_lookup rs_map y m z \\<rbrakk> \\<Longrightarrow> path_lookup rs_map x (l @ m) z\"    \n  apply (induct l arbitrary: x)\n   apply (auto)\n  apply (case_tac \"rs_map x\")\n   apply (auto)\n  done    \n    \n    (* ##### proper expressions ##### *)\n  \ndefinition proper_exp :: \"nres_map \\<Rightarrow> p_exp \\<Rightarrow> bool\" where\n  \"proper_exp rs_map e = (\\<forall> x y. (x, y) \\<in> own_pairs e \\<longrightarrow> (\\<exists> l. path_lookup rs_map x l y))\"\n\nlemma proper_pair: \"\\<lbrakk> proper_exp rs_map (PairExp e1 e2) \\<rbrakk> \\<Longrightarrow> proper_exp rs_map e1 \\<and> proper_exp rs_map e2\"  \n  apply (simp add: proper_exp_def)\n  done\n\nlemma proper_if: \"\\<lbrakk> proper_exp rs_map (IfExp e1 e2 e3) \\<rbrakk> \\<Longrightarrow> proper_exp rs_map e1 \\<and> proper_exp rs_map e2 \\<and> proper_exp rs_map e3\"  \n  apply (simp add: proper_exp_def)\n  done    \n\nlemma proper_app: \"\\<lbrakk> proper_exp rs_map (AppExp e1 e2) \\<rbrakk> \\<Longrightarrow> proper_exp rs_map e1 \\<and> proper_exp rs_map e2\"  \n  apply (simp add: proper_exp_def)\n  done\n    \nlemma proper_subst_exp: \"\\<lbrakk> proper_exp rs_map e; proper_exp rs_map e' \\<rbrakk> \\<Longrightarrow> proper_exp rs_map (subst_exp e x e')\"\n  apply (induct e)\n        apply (auto)\n      apply (case_tac xa)\n       apply (auto)\n     apply (cut_tac rs_map=\"rs_map\" and ?e1.0=\"e1\" and ?e2.0=\"e2\" in proper_pair)\n      apply (auto)\n     apply (simp add: proper_exp_def)\n    apply (cut_tac rs_map=\"rs_map\" and ?e1.0=\"e1\" and ?e2.0=\"e2\" and ?e3.0=\"e3\" in proper_if)\n     apply (auto)\n    apply (simp add: proper_exp_def)\n   apply (simp add: proper_exp_def)\n  apply (cut_tac rs_map=\"rs_map\" and ?e1.0=\"e1\" and ?e2.0=\"e2\" in proper_app)\n   apply (auto)\n  apply (simp add: proper_exp_def)\n  done\n \nlemma proper_alpha_rename: \"\\<lbrakk> proper_exp rs_map e \\<rbrakk> \\<Longrightarrow> proper_exp rs_map (deep_alpha_rename e a b)\"    \n  apply (induct e)\n        apply (auto)\n       apply (simp add: proper_exp_def)\n       apply (auto)\n       apply (case_tac x)\n        apply (auto)\n       apply (case_tac \"a = x1\")\n        apply (auto)\n      apply (cut_tac rs_map=\"rs_map\" and ?e1.0=\"e1\" and ?e2.0=\"e2\" in proper_pair)\n       apply (auto)\n      apply (simp add: proper_exp_def)\n     apply (cut_tac rs_map=\"rs_map\" and ?e1.0=\"e1\" and ?e2.0=\"e2\" and ?e3.0=\"e3\" in proper_if)\n      apply (auto)\n     apply (simp add: proper_exp_def)\n    apply (simp add: proper_exp_def)\n   apply (simp add: proper_exp_def)\n  apply (cut_tac rs_map=\"rs_map\" and ?e1.0=\"e1\" and ?e2.0=\"e2\" in proper_app)\n   apply (auto)\n  apply (simp add: proper_exp_def)\n  done\n    \nlemma proper_lam_var_remove_ex: \"\\<lbrakk> proper_exp rs_map e; well_typed env r_s1 e tau r_s2 rx \\<rbrakk> \\<Longrightarrow> proper_exp rs_map (lam_var_remove e a b)\"      \n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n        apply (auto)\n      apply (cut_tac rs_map=\"rs_map\" and ?e1.0=\"e1\" and ?e2.0=\"e2\" in proper_pair)\n       apply (auto)\n      apply (simp add: proper_exp_def)\n     apply (cut_tac rs_map=\"rs_map\" and ?e1.0=\"e1\" and ?e2.0=\"e2\" and ?e3.0=\"e3\" in proper_if)\n      apply (auto)\n     apply (simp add: proper_exp_def)\n    apply (cut_tac rs_map=\"rs_map\" and e=\"e\" and a=\"a\" and b=\"b\" in proper_alpha_rename)\n     apply (simp add: proper_exp_def)\n    apply (simp add: proper_exp_def)\n   apply (simp add: proper_exp_def)\n  apply (cut_tac rs_map=\"rs_map\" and ?e1.0=\"e1\" and ?e2.0=\"e2\" in proper_app)\n   apply (auto)\n  apply (simp add: proper_exp_def)\n  done\n    \nlemma proper_lam_var_remove: \"\\<lbrakk> proper_exp rs_map e \\<rbrakk> \\<Longrightarrow> proper_exp rs_map (lam_var_remove e a b)\"   \n  apply (induct e)\n        apply (auto)\n      apply (cut_tac rs_map=\"rs_map\" and ?e1.0=\"e1\" and ?e2.0=\"e2\" in proper_pair)\n       apply (auto)\n      apply (simp add: proper_exp_def)\n     apply (cut_tac rs_map=\"rs_map\" and ?e1.0=\"e1\" and ?e2.0=\"e2\" and ?e3.0=\"e3\" in proper_if)\n      apply (auto)\n     apply (simp add: proper_exp_def)\n    apply (cut_tac rs_map=\"rs_map\" and e=\"e\" and a=\"a\" and b=\"b\" in proper_alpha_rename)\n     apply (simp add: proper_exp_def)\n    apply (simp add: proper_exp_def)\n   apply (simp add: proper_exp_def)\n  apply (cut_tac rs_map=\"rs_map\" and ?e1.0=\"e1\" and ?e2.0=\"e2\" in proper_app)\n   apply (auto)\n  apply (simp add: proper_exp_def)\n  done\n      \nlemma lam_var_remove_eq: \"\\<lbrakk> a \\<notin> lam_vars e \\<rbrakk> \\<Longrightarrow> lam_var_remove e a b = e\"    \n  apply (induct e)\n        apply (auto)\n  done\n  \nlemma proper_lvlr_ex: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; proper_exp rs_map e; unique_post_vars vl;\n  post_vars vl \\<inter> (free_vars e \\<union> lam_vars e) = {} \\<rbrakk> \\<Longrightarrow> proper_exp rs_map (lam_var_list_remove e vl)\"   \n  apply (induct vl arbitrary: e)\n   apply (auto)\n  (*apply (case_tac \"a \\<notin> lam_vars e\")\n   apply (simp add: lam_var_remove_eq)*)\n  apply (cut_tac rs_map=\"rs_map\" and e=\"e\" and a=\"a\" and b=\"b\" in proper_lam_var_remove_ex)\n    apply (auto)\n    (* we have to prove that the post vars are still disjoint from the lam_vars / ref_vars, which is true since\n        the only new lam_var is b, which must be disjoint from the rest of the post_var list *)\n  apply (case_tac \"post_vars vl \\<inter> (free_vars (lam_var_remove e a b) \\<union> lam_vars (lam_var_remove e a b)) \\<noteq> {}\")\n   apply (auto)\n    apply (cut_tac x=\"x\" and e=\"e\" and a=\"a\" and b=\"b\" in lam_var_remove_free_var_none)\n     apply (auto)\n   apply (case_tac \"x = b\")\n    apply (auto)\n   apply (cut_tac x=\"x\" and e=\"e\" and a=\"a\" and b=\"b\" in lam_var_remove_lam_var_none)\n     apply (auto)\n    (* the last part of the induction is to prove that e is still well-typed *)\n  apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s1\" and e=\"e\" and x=\"a\" and y=\"b\" in lam_var_remove_type_preserve)\n      apply (auto)\n  done\n  \nlemma proper_safe_subst_exp: \"\\<lbrakk> proper_exp rs_map e; well_typed env r_s1 e tau r_s2 rx;\n  proper_exp rs_map e'; safe_subst_exp e x e' e_f \\<rbrakk> \\<Longrightarrow> proper_exp rs_map e_f\"    \n  apply (simp add: safe_subst_exp_def)\n  apply (auto)\n  apply (rule_tac proper_subst_exp)\n   apply (rule_tac proper_lvlr_ex)\n      apply (auto)\n  done\n\nend", "meta": {"author": "anon-ef", "repo": "perm_lang_ef2", "sha": "0fcb6e4c175193cc7b94f297a8aaa605f502d711", "save_path": "github-repos/isabelle/anon-ef-perm_lang_ef2", "path": "github-repos/isabelle/anon-ef-perm_lang_ef2/perm_lang_ef2-0fcb6e4c175193cc7b94f297a8aaa605f502d711/perm_ref/ReduceProper.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6224593312018546, "lm_q2_score": 0.43014734858584286, "lm_q1q2_score": 0.2677492309189948}}
{"text": "theory ContextDeterminism\nimports ContextEvaluate\nbegin\n\n(*\n\nlemma [elim]: \"head_var e = Some x \\<Longrightarrow> is_value e \\<Longrightarrow> False\"\n  by (induction e arbitrary: x) (auto split: option.splits nat.splits)\n\nlemma [elim]: \"e \\<leadsto> e' \\<Longrightarrow> is_value e \\<Longrightarrow> False\"\n  by (induction e e' rule: evaluate.induct) auto\n\nlemma [elim]: \"e \\<leadsto> e' \\<Longrightarrow> head_var e = Some x \\<Longrightarrow> False\"\n  by (induction e e' arbitrary: x rule: evaluate.induct) (auto split: option.splits nat.splits)\n\ntheorem determinism [elim]: \"e \\<leadsto> e' \\<Longrightarrow> e \\<leadsto> e'' \\<Longrightarrow> e' = e''\"\n  proof (induction e e' arbitrary: e'' rule: evaluate.induct)\n  case (ev_app1 e\\<^sub>1 e\\<^sub>1' e\\<^sub>2)\n    with ev_app1(3) show ?case\n      proof (induction \"App e\\<^sub>1 e\\<^sub>2\" e'' rule: evaluate.induct)\n      case ev_app2\n        hence False by auto\n        thus ?case by simp\n      next case ev_app_let\n        hence False by auto\n        thus ?case by simp\n      qed simp_all\n  next case (ev_app2 t e\\<^sub>1 e\\<^sub>2)\n    thus ?case by (induction \"App (Abs t e\\<^sub>1) e\\<^sub>2\" e'' rule: evaluate.induct) auto\n  next case (ev_app_let e\\<^sub>1\\<^sub>2 e\\<^sub>1\\<^sub>1 e\\<^sub>2)\n    with ev_app_let(2) show ?case\n      proof (induction \"App (Let e\\<^sub>1\\<^sub>1 e\\<^sub>1\\<^sub>2) e\\<^sub>2\" e'' rule: evaluate.induct)\n      case ev_app1\n        hence False by auto\n        thus ?case by simp\n      qed simp_all\n  next case (ev_let1 e\\<^sub>2 e\\<^sub>2' e\\<^sub>1)\n    with ev_let1(3) show ?case\n      proof (induction \"Let e\\<^sub>1 e\\<^sub>2\" e'' rule: evaluate.induct) \n      case ev_let2\n        hence False by fast\n        thus ?case by simp\n      next case ev_let3\n        hence False by auto\n        thus ?case by simp\n      qed simp_all\n  next case (ev_let2 e\\<^sub>1 e\\<^sub>1' e\\<^sub>2)\n    with ev_let2(4) show ?case\n      proof (induction \"Let e\\<^sub>1 e\\<^sub>2\" e'' rule: evaluate.induct) \n      case ev_let1\n        hence False by fast\n        thus ?case by simp\n      next case ev_let3\n        hence False by auto\n        thus ?case by simp\n      qed simp_all\n  next case (ev_let3 e\\<^sub>1 e\\<^sub>2)\n    with ev_let3(3) show ?case\n      proof (induction \"Let e\\<^sub>1 e\\<^sub>2\" e'' rule: evaluate.induct) \n      case ev_let1\n        hence False by auto\n        thus ?case by simp\n      next case ev_let2\n        hence False by auto\n        thus ?case by simp\n      qed simp_all\n  next case (ev_proj1 e e' l)\n    with ev_proj1(3) show ?case\n      proof (induction \"Proj e l\" e'' rule: evaluate.induct)\n      case ev_proj2\n        hence False by auto\n        thus ?case by simp\n      next case ev_proj_let\n        hence False by auto\n        thus ?case by simp\n      qed simp_all\n  next case (ev_proj2 fs l e)\n    with ev_proj2(2) show ?case\n      proof (induction \"Proj (Rec fs) l\" e'' rule: evaluate.induct)\n      case ev_proj1\n        hence False by auto\n        thus ?case by simp\n      qed simp_all\n  next case (ev_proj_let e\\<^sub>2 e\\<^sub>1 l)\n    with ev_proj_let(2) show ?case\n      proof (induction \"Proj (expr.Let e\\<^sub>1 e\\<^sub>2) l\" e'' rule: evaluate.induct)\n      case ev_proj1\n        hence False by auto\n        thus ?case by simp\n      qed simp_all\n  next case (ev_case1 e e' t cs)\n    with ev_case1(3) show ?case\n      proof (induction \"Case e t cs\" e'' rule: evaluate.induct)\n      case ev_case2\n        hence False by auto\n        thus ?case by simp\n      next case ev_case_let\n        hence False by auto\n        thus ?case by simp\n      qed simp_all\n  next case (ev_case2 cs l e' ts e t)\n    with ev_case2(2) show ?case\n      proof (induction \"Case (Inj l ts e) t cs\" e'' rule: evaluate.induct)\n      case ev_case1\n        hence False by auto\n        thus ?case by simp\n      qed simp_all\n  next case (ev_case_let e\\<^sub>2 e\\<^sub>1 t cs)\n    with ev_case_let(2) show ?case\n      proof (induction \"Case (Let e\\<^sub>1 e\\<^sub>2) t cs\" e'' rule: evaluate.induct)\n      case ev_case1\n        hence False by auto\n        thus ?case by simp\n      qed simp_all\n  next case (ev_unfold1 e e' t)\n    with ev_unfold1(3) show ?case\n      proof (induction \"Unfold t e\" e'' rule: evaluate.induct)\n      case ev_unfold2\n        hence False by auto\n        thus ?case by simp\n      next case ev_unfold_let\n        hence False by auto\n        thus ?case by simp\n      qed simp_all\n  next case (ev_unfold2 t e)\n    thus ?case\n      proof (induction \"Unfold t (Fold t e)\" e'' rule: evaluate.induct)\n      case ev_unfold1\n        hence False by auto\n        thus ?case by simp\n      qed simp_all\n  next case (ev_unfold_let e\\<^sub>2 e\\<^sub>1 t)\n    with ev_unfold_let(2) show ?case\n      proof (induction \"Unfold e\\<^sub>1 (Let t e\\<^sub>2)\" e'' rule: evaluate.induct)\n      case ev_unfold1\n        hence False by auto\n        thus ?case by simp\n      qed simp_all\n  next case (ev_tyapp1 e e' t)\n    with ev_tyapp1(3) show ?case\n      proof (induction \"TyApp e t\" e'' rule: evaluate.induct)\n      case ev_tyapp2\n        hence False by auto\n        thus ?case by simp\n      next case ev_tyapp_let\n        hence False by auto\n        thus ?case by simp\n      qed simp_all\n  next case (ev_tyapp2 k e t)\n    thus ?case\n      proof (induction \"TyApp (TyAbs k e) t\" e'' rule: evaluate.induct)\n      case ev_tyapp1\n        hence False by auto\n        thus ?case by simp\n      qed simp_all\n  next case (ev_tyapp_let e\\<^sub>2 e\\<^sub>1 t)\n    with ev_tyapp_let(2) show ?case \n      by (induction \"TyApp (Let e\\<^sub>1 e\\<^sub>2) t\" e'' rule: evaluate.induct) auto\n  next case (ev_tylet t e)\n    thus ?case by (induction \"TyLet t e\" e'' rule: evaluate.induct) simp_all\n  qed\n\n*)\n\nend", "meta": {"author": "xtreme-james-cooper", "repo": "LazyCompiler", "sha": "3b95c3550e0cce4966aaf45c7eb38f2cbc2bfbfa", "save_path": "github-repos/isabelle/xtreme-james-cooper-LazyCompiler", "path": "github-repos/isabelle/xtreme-james-cooper-LazyCompiler/LazyCompiler-3b95c3550e0cce4966aaf45c7eb38f2cbc2bfbfa/01Expression/03EvaluationContext/ContextDeterminism.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6224593312018545, "lm_q2_score": 0.43014734858584286, "lm_q1q2_score": 0.2677492309189947}}
{"text": "theory PhiSem_Machine_Integer\n  imports PhiSem_Common_Int PhiSem_Generic_Boolean\n          \"Word_Lib.More_Word\" (*We use the word lib from seL4*)\n          \"Word_Lib.Signed_Division_Word\"\n          \"Word_Lib.Word_Lemmas\"\nbegin\n\nchapter \\<open>Semantics for Machine Integers\\<close>\n\nsection \\<open>Models\\<close>\n\nsubsubsection \\<open>Type\\<close>\n\nvirtual_datatype \\<phi>machine_int_ty =\n  T_int     :: nat \\<comment> \\<open>in unit of bits\\<close>\n\ndebt_axiomatization T_int :: \\<open>nat type_entry\\<close>\n  where \\<phi>machine_int_ty_ax: \\<open>\\<phi>machine_int_ty TY_CONS_OF T_int\\<close>\n\ninterpretation \\<phi>machine_int_ty TY_CONS_OF \\<open>TYPE(TY_N)\\<close> \\<open>TYPE(TY)\\<close> T_int using \\<phi>machine_int_ty_ax .\n\nhide_fact \\<phi>machine_int_ty_ax \\<phi>machine_int_ty_axioms \\<phi>machine_int_ty_names_def \\<phi>machine_int_ty_def\n  \\<phi>machine_int_ty_prjs_axioms \\<phi>machine_int_ty_prjs_def \\<phi>machine_int_ty.axioms \\<phi>machine_int_ty.intro\n  \\<phi>machine_int_ty__names.\\<phi>machine_int_ty_names_axioms \\<phi>machine_int_ty_prjs.axioms\n\nsyntax \"_int_semty_\" :: \\<open>type \\<Rightarrow> TY\\<close> (\"int'(_')\")\n\ntranslations \"int('b)\" <= \"CONST T_int.mk LENGTH('b)\"\n\nML \\<open>local open Ast in\n  fun need_add_sort (Appl [Constant \\<^syntax_const>\\<open>_ofsort\\<close>, Variable _, _]) = true\n    | need_add_sort (Variable _) = true\n    | need_add_sort _ = false\n  fun add_sort X =\n    if need_add_sort X\n    then Appl [Constant \\<^syntax_const>\\<open>_ofsort\\<close>, X, Constant \\<^class_syntax>\\<open>len\\<close>]\n    else X\nend\\<close>\n\nparse_ast_translation \\<open>\n  let open Ast\n   in [(\\<^syntax_const>\\<open>_int_semty_\\<close>, (fn _ => fn [V] =>\n          Appl [Constant \\<^const_syntax>\\<open>T_int.mk\\<close>, Appl [Constant \\<^syntax_const>\\<open>_type_length\\<close>, add_sort V]]))] end\\<close>\n\n\nsubsubsection \\<open>Value\\<close>\n\nvirtual_datatype \\<phi>machine_int_val =\n  V_int     :: \\<open>nat \\<times> nat\\<close> \\<comment> \\<open>bits \\<times> value\\<close>\n\ndebt_axiomatization V_int :: \\<open>(nat \\<times> nat) value_entry\\<close>\n  where \\<phi>machine_int_val_ax: \\<open>\\<phi>machine_int_val VAL_CONS_OF V_int\\<close>\n\ninterpretation \\<phi>machine_int_val VAL_CONS_OF \\<open>TYPE(VAL_N)\\<close> \\<open>TYPE(VAL)\\<close> V_int using \\<phi>machine_int_val_ax .\n\nhide_fact \\<phi>machine_int_val_ax \\<phi>machine_int_val_axioms\n\nsubsubsection \\<open>Semantics\\<close>\n\ndebt_axiomatization\n    WT_int[simp]: \\<open>Well_Type (T_int.mk b)     = { V_int.mk (b,x)    |x. x < 2 ^ b } \\<close>\nand can_eqcmp_int[simp]: \"Can_EqCompare res (V_int.mk (b1,x1)) (V_int.mk (b2,x2)) \\<longleftrightarrow> b1 = b2\"\nand eqcmp_int[simp]: \"EqCompare (V_int.mk i1) (V_int.mk i2) \\<longleftrightarrow> i1 = i2\"\nand  zero_int[simp]: \\<open>Zero (T_int.mk b)    = Some (V_int.mk (b,0))\\<close>\n\n(*lemma Valid_Types[simp]:\n  \\<open>Valid_Type (T_int.mk n)\\<close>\n  unfolding Inhabited_def\n  apply simp\n  using less_exp by blast *)\n\n\nsection \\<open>\\<phi>-Types\\<close>\n\ntext \\<open>Thresholds between \\<phi>-Types\n\\<^item> 9 \\<open>Word \\<longrightarrow> \\<nat>\\<^sup>r\\<close>\n\\<^item> 9 \\<open>Word \\<longrightarrow> \\<nat>\\<close>\n\\<^item> 9 \\<open>Word \\<longrightarrow> \\<int>\\<close>\n\\<^item> 7 \\<open>\\<nat>\\<^sup>r \\<longrightarrow> Word\\<close>\n\\<^item> 7 \\<open>\\<nat> \\<longrightarrow> Word\\<close>\n\\<^item> 7 \\<open>\\<int> \\<longrightarrow> Word\\<close>\n\\<^item> 6 \\<open>\\<int> \\<longrightarrow> \\<nat>\\<close>\n\\<^item> 5 \\<open>\\<nat> \\<longrightarrow> \\<int>\\<close>\n\\<^item> 4 \\<open>\\<nat>\\<^sup>r \\<longrightarrow> \\<nat>\\<close>\n\\<^item> 2 \\<open>\\<nat> \\<longrightarrow> \\<nat>\\<^sup>r\\<close>\n\nThere is no direct transformation between \\<open>\\<nat>\\<^sup>r\\<close> and \\<open>\\<int>\\<close> because of complexity in the expression.\n\n\\<close>\n\nsubsection \\<open>Words\\<close>\n\ndefinition Word :: \\<open>'b itself \\<Rightarrow> (VAL, 'b::len word) \\<phi>\\<close>\n  where \\<open>Word _ x = { V_int.mk (LENGTH('b), unat x) }\\<close>\n\nsyntax Word_syntax :: \"type \\<Rightarrow> (VAL, 'b::len word) \\<phi>\" (\"Word'(_')\")\n\ntranslations \"Word('x)\" <= \"CONST Word TYPE('x)\"\n\nparse_ast_translation \\<open>\n  let open Ast\n   in [(\\<^syntax_const>\\<open>Word_syntax\\<close>, (fn _ => fn [V] =>\n          Appl [Constant \\<^const_syntax>\\<open>Word\\<close>, Appl [Constant \\<^syntax_const>\\<open>_TYPE\\<close>, add_sort V]]))] end\\<close>\n\n\n\nlemma Word_expn[\\<phi>expns]:\n  \\<open>p \\<in> (x \\<Ztypecolon> Word('b)) \\<longleftrightarrow> p = V_int.mk (LENGTH('b), unat x)\\<close>\n  unfolding \\<phi>Type_def Word_def by simp\n\nlemma [elim!,\\<phi>inhabitance_rule]:\n  \\<open>Inhabited (x \\<Ztypecolon> Word('b)) \\<Longrightarrow> C \\<Longrightarrow> C\\<close> .\n\nlemma [\\<phi>reason 1000]:\n  \\<open>\\<phi>SemType (x \\<Ztypecolon> Word('b)) int('b)\\<close>\n  unfolding \\<phi>SemType_def subset_iff by (simp add: Word_expn)\n\nlemma [\\<phi>reason 1000]:\n  \"\\<phi>Equal Word('b) (\\<lambda>x y. True) (=)\"\n  unfolding \\<phi>Equal_def by (simp add: word_unat_eq_iff Word_expn)\n\nlemma [\\<phi>reason 1000]:\n  \"\\<phi>Zero int('b) Word('b) (0::'b::len word)\"\n  unfolding \\<phi>Zero_def by (simp add: Word_expn image_iff)\n\n\n\nsubsection \\<open>Natural Numbers\\<close>\n\nsubsubsection \\<open>Rounded Natural Number\\<close>\n\ndefinition \\<phi>RoundedNat :: \"'b::len itself \\<Rightarrow> (VAL, nat) \\<phi>\"\n  where [\\<phi>defs]: \"\\<phi>RoundedNat _ x = ((of_nat x :: 'b word) \\<Ztypecolon> Word('b))\"\n\nsyntax \\<phi>RoundedNat_syntax :: \"type \\<Rightarrow> (VAL, nat) \\<phi>\" (\"\\<nat>\\<^sup>r'(_')\")\n\ntranslations \"\\<nat>\\<^sup>r('x)\" <= \"CONST \\<phi>RoundedNat TYPE('x)\"\n\nparse_ast_translation \\<open>\n  let open Ast\n   in [(\\<^syntax_const>\\<open>\\<phi>RoundedNat_syntax\\<close>, (fn _ => fn [V] =>\n          Appl [Constant \\<^const_syntax>\\<open>\\<phi>RoundedNat\\<close>,\n                Appl [Constant \\<^syntax_const>\\<open>_TYPE\\<close>, add_sort V]]))] end\\<close>\n\nlemma [\n  \\<phi>reason 1000 for \\<open>?x \\<Ztypecolon> \\<nat>\\<^sup>r(?'b1) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> ?y \\<Ztypecolon> _ \\<a>\\<n>\\<d> _\\<close>\n]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> x mod 2^LENGTH('b) = y mod 2^LENGTH('b)\n\\<Longrightarrow> x \\<Ztypecolon> \\<nat>\\<^sup>r('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> y \\<Ztypecolon> \\<nat>\\<^sup>r('b)\\<close>\n  \\<medium_left_bracket> destruct\\<phi> _\n    construct\\<phi> \\<open>y \\<Ztypecolon> \\<nat>\\<^sup>r('b)\\<close> \n    affirm by (simp add: the_\\<phi> unat_of_nat word_unat_eq_iff) \\<medium_right_bracket>. .\n\nlemma [\\<phi>reason 800 for \\<open>_ \\<Ztypecolon> \\<nat>\\<^sup>r(_) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> _ \\<Ztypecolon> Word(_) \\<a>\\<n>\\<d> _\\<close>]:\n  \\<open> Threshold_Cost 7\n\\<Longrightarrow> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> y = of_nat x\n\\<Longrightarrow> x \\<Ztypecolon> \\<nat>\\<^sup>r('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> y \\<Ztypecolon> Word('b)\\<close>\n  for y :: \\<open>'b::len word\\<close>\n  \\<medium_left_bracket> destruct\\<phi> _ \\<medium_right_bracket>. .\n\nlemma [\n  \\<phi>reason 800 for \\<open>_ \\<Ztypecolon> \\<phi>RoundedNat _ \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> _ \\<a>\\<n>\\<d> _ @action to (Word _)\\<close>,\n  \\<phi>inhabitance_rule\n]:\n  \\<open>x \\<Ztypecolon> \\<nat>\\<^sup>r('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> (of_nat x :: 'b::len word) \\<Ztypecolon> Word('b) @action to Word('b)\\<close>\n  \\<medium_left_bracket> \\<medium_right_bracket>. .\n\nlemma [\\<phi>reason 1200 for \\<open>_ \\<Ztypecolon> Word(_) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> _ \\<Ztypecolon> \\<nat>\\<^sup>r(_) \\<a>\\<n>\\<d> _\\<close>]:\n  \\<open> Threshold_Cost 9\n\\<Longrightarrow> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> y mod 2^LENGTH('b) = unat x\n\\<Longrightarrow> x \\<Ztypecolon> Word('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> y \\<Ztypecolon> \\<nat>\\<^sup>r('b)\\<close>\n  for x :: \\<open>'b::len word\\<close>\n  \\<medium_left_bracket> construct\\<phi> \\<open>unat x \\<Ztypecolon> \\<nat>\\<^sup>r('b)\\<close> \\<medium_right_bracket>. .\n\nlemma [\\<phi>reason 1200 for \\<open>_ \\<Ztypecolon> Word _ \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> _ \\<a>\\<n>\\<d> _ @action to (\\<phi>RoundedNat _)\\<close>]:\n  \\<open> x \\<Ztypecolon> Word('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> unat x \\<Ztypecolon> \\<nat>\\<^sup>r('b) @action to \\<nat>\\<^sup>r('b)\\<close>\n  for x :: \\<open>'b::len word\\<close> \\<medium_left_bracket> \\<medium_right_bracket>. .\n\nlemma [\\<phi>reason 1000]:\n  \\<open>\\<phi>SemType (x \\<Ztypecolon> \\<nat>\\<^sup>r('b)) int('b)\\<close>\n  \\<medium_left_bracket> to \\<open>Word _\\<close> \\<medium_right_bracket>. .\n\nlemma [\\<phi>reason 1000]:\n  \\<open>\\<phi>Zero int('b) \\<nat>\\<^sup>r('b) 0\\<close>\n  \\<medium_left_bracket> \\<open>0 \\<Ztypecolon> Word('b)\\<close> \\<medium_right_bracket>. .\n\nlemma [\\<phi>reason 1000]:\n  \"\\<phi>Equal (\\<nat>\\<^sup>r('b::len)) (\\<lambda>x y. True) (\\<lambda>x y. x mod 2^LENGTH('b) = y mod 2^LENGTH('b))\"\n  \\<medium_left_bracket> to \\<open>Word('b)\\<close> \\<medium_right_bracket>\n    by (simp add: unat_of_nat word_unat_eq_iff) .\n\n\nsubsubsection \\<open>Natural Number\\<close>\n\ndefinition \\<phi>Nat :: \"'b::len itself \\<Rightarrow> (VAL, nat) \\<phi>\"\n  where [\\<phi>defs]: \"\\<phi>Nat _ x = (x \\<Ztypecolon> \\<nat>\\<^sup>r('b) \\<s>\\<u>\\<b>\\<j> x \\<in> {0..< 2 ^ LENGTH('b)})\"\n\nsyntax \\<phi>Nat_syntax :: \"type \\<Rightarrow> (VAL, nat) \\<phi>\" (\"\\<nat>'(_')\")\n\ntranslations \"\\<nat>('x)\" <= \"CONST \\<phi>Nat TYPE('x)\"\n\nparse_ast_translation \\<open>\n  let open Ast\n   in [(\\<^syntax_const>\\<open>\\<phi>Nat_syntax\\<close>, (fn _ => fn [V] =>\n          Appl [Constant \\<^const_syntax>\\<open>\\<phi>Nat\\<close>, Appl [Constant \\<^syntax_const>\\<open>_TYPE\\<close>, add_sort V]]))] end\\<close>\n\nlemma [\\<phi>reason 800 for \\<open>_ \\<Ztypecolon> \\<nat>(_) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> _ \\<Ztypecolon> \\<nat>\\<^sup>r(_) \\<a>\\<n>\\<d> _\\<close>]:\n  \\<open> Threshold_Cost 2\n\\<Longrightarrow> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> y = x\n\\<Longrightarrow> x \\<Ztypecolon> \\<nat>('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> y \\<Ztypecolon> \\<nat>\\<^sup>r('b) \\<a>\\<n>\\<d> x < 2 ^ LENGTH('b)\\<close>\n  \\<medium_left_bracket> destruct\\<phi> _ \\<medium_right_bracket>. .\n\nlemma [\n  \\<phi>reason 800 for \\<open>_ \\<Ztypecolon> \\<nat>(_) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> _ \\<a>\\<n>\\<d> _ @action to (\\<phi>RoundedNat _)\\<close>,\n  \\<phi>inhabitance_rule\n]:\n  \\<open>x \\<Ztypecolon> \\<nat>('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> x \\<Ztypecolon> \\<nat>\\<^sup>r('b) \\<a>\\<n>\\<d> x < 2 ^ LENGTH('b) @action to \\<nat>\\<^sup>r('b)\\<close>\n  \\<medium_left_bracket> \\<medium_right_bracket>. .\n\n\nlemma [\\<phi>reason 800 for \\<open>_ \\<Ztypecolon> \\<nat>\\<^sup>r(_) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> _ \\<a>\\<n>\\<d> _ @action to (\\<phi>Nat _)\\<close>]:\n  \\<open> x \\<Ztypecolon> \\<nat>\\<^sup>r('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> x mod 2 ^ LENGTH('b) \\<Ztypecolon> \\<nat>('b) @action to \\<nat>('b)\\<close>\n  \\<medium_left_bracket> construct\\<phi> \\<open>x mod 2 ^ LENGTH('b) \\<Ztypecolon> \\<nat>('b)\\<close> \\<medium_right_bracket>. .\n\nlemma [\\<phi>reason 800 for \\<open>_ \\<Ztypecolon> \\<nat>\\<^sup>r(_) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> _ \\<Ztypecolon> \\<nat>(_) \\<a>\\<n>\\<d> _ \\<close>]:\n  \\<open> Threshold_Cost 4\n\\<Longrightarrow> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> x mod 2 ^ LENGTH('b) = y\n\\<Longrightarrow> x \\<Ztypecolon> \\<nat>\\<^sup>r('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> y \\<Ztypecolon> \\<nat>('b) \\<close>\n  \\<medium_left_bracket> to \\<open>\\<nat>(_)\\<close> \\<medium_right_bracket>. .\n\n\nlemma [\\<phi>reason 800 for \\<open>_ \\<Ztypecolon> \\<nat>(_) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> _ \\<Ztypecolon> Word(_) \\<a>\\<n>\\<d> _\\<close>]:\n  \\<open> Threshold_Cost 7\n\\<Longrightarrow> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> y = of_nat x\n\\<Longrightarrow> x \\<Ztypecolon> \\<nat>('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> y \\<Ztypecolon> Word('b) \\<a>\\<n>\\<d> x < 2 ^ LENGTH('b)\\<close>\n  for y :: \\<open>'b::len word\\<close>\n  \\<medium_left_bracket> to \\<open>\\<nat>\\<^sup>r(_)\\<close> \\<medium_right_bracket>. .\n\nlemma [\n  \\<phi>reason 800 for \\<open>_ \\<Ztypecolon> \\<nat>(_) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> _ \\<a>\\<n>\\<d> _ @action to (Word _)\\<close>,\n  \\<phi>inhabitance_rule\n]:\n  \\<open>x \\<Ztypecolon> \\<nat>('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> (of_nat x :: 'b::len word) \\<Ztypecolon> Word('b) \\<a>\\<n>\\<d> x < 2 ^ LENGTH('b)\n   @action to Word('b)\\<close>\n  \\<medium_left_bracket> \\<medium_right_bracket>. .\n\n\nlemma [\\<phi>reason 1200 for \\<open>_ \\<Ztypecolon> Word(_) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> _ \\<Ztypecolon> \\<nat>(_) \\<a>\\<n>\\<d> _\\<close>]:\n  \\<open> Threshold_Cost 9\n\\<Longrightarrow> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> y = unat x\n\\<Longrightarrow> x \\<Ztypecolon> Word('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> y \\<Ztypecolon> \\<nat>('b)\\<close>\n  for x :: \\<open>'b::len word\\<close>\n  \\<medium_left_bracket> to \\<open>\\<nat>\\<^sup>r('b)\\<close> \\<medium_right_bracket>. .\n\nlemma [\\<phi>reason 1200 for \\<open>_ \\<Ztypecolon> Word _ \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> _ \\<a>\\<n>\\<d> _ @action to (\\<phi>Nat _)\\<close>]:\n  \\<open> x \\<Ztypecolon> Word('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> unat x \\<Ztypecolon> \\<nat>('b) @action to \\<nat>('b)\\<close>\n  for x :: \\<open>'b::len word\\<close> \\<medium_left_bracket> \\<medium_right_bracket>. .\n\n\n\nlemma [\\<phi>reason 1000]:\n  \\<open>\\<phi>SemType (x \\<Ztypecolon> \\<nat>('b)) int('b)\\<close>\n  \\<medium_left_bracket> to \\<open>Word _\\<close> \\<medium_right_bracket>. .\n\nlemma [\\<phi>reason 1000]:\n  \\<open>\\<phi>Zero int('b) \\<nat>('b) 0\\<close>\n  \\<medium_left_bracket> \\<open>0 \\<Ztypecolon> Word('b)\\<close> \\<medium_right_bracket>. .\n\nlemma [\\<phi>reason 1000]:\n  \"\\<phi>Equal (\\<nat>('b::len)) (\\<lambda>x y. True) (=)\"\n  \\<medium_left_bracket> to \\<open>Word('b)\\<close> \\<medium_right_bracket> using \\<phi>lemmata of_nat_inverse by blast .\n\n\nsubsection \\<open>Integer\\<close>\n\ndefinition \\<phi>Int :: \"'b::len itself \\<Rightarrow> (VAL, int) \\<phi>\"\n  where [\\<phi>defs]: \"\\<phi>Int _ x = ((of_int x :: 'b word) \\<Ztypecolon> Word('b)\n                              \\<s>\\<u>\\<b>\\<j> x \\<in> { -(2^(LENGTH('b)-1)) ..< 2^(LENGTH('b)-1)})\"\n\nsyntax \\<phi>Int_syntax :: \"type \\<Rightarrow> (VAL, nat) \\<phi>\" (\"\\<int>'(_')\")\n\ntranslations \"\\<int>('x)\" == \"CONST \\<phi>Int TYPE('x)\"\n\nparse_ast_translation \\<open>\n  let open Ast\n   in [(\\<^syntax_const>\\<open>\\<phi>Int_syntax\\<close>, (fn _ => fn [V] =>\n          Appl [Constant \\<^const_syntax>\\<open>\\<phi>Int\\<close>, Appl [Constant \\<^syntax_const>\\<open>_TYPE\\<close>, add_sort V]]))] end\\<close>\n\nlemma [\\<phi>reason 800 for \\<open>_ \\<Ztypecolon> \\<int>(_) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> _ \\<Ztypecolon> Word(_) \\<a>\\<n>\\<d> _\\<close>]:\n  \" Threshold_Cost 7\n\\<Longrightarrow> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> y = of_int x\n\\<Longrightarrow> x \\<Ztypecolon> \\<int>('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> y \\<Ztypecolon> Word('b) \\<a>\\<n>\\<d> x \\<in> { -(2^(LENGTH('b)-1)) ..< 2^(LENGTH('b)-1)}\"\n  \\<medium_left_bracket> destruct\\<phi> _ \\<medium_right_bracket>. .\n\nlemma [\n  \\<phi>reason 800 for \\<open>_ \\<Ztypecolon> \\<int>(_) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> _ \\<a>\\<n>\\<d> _ @action to Word(_)\\<close>,\n  \\<phi>inhabitance_rule\n]:\n  \\<open>x \\<Ztypecolon> \\<int>('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> (of_int x :: 'b::len word) \\<Ztypecolon> Word('b) \\<a>\\<n>\\<d> x \\<in> { -(2^(LENGTH('b)-1)) ..< 2^(LENGTH('b)-1)}\n   @action to Word('b)\\<close>\n  \\<medium_left_bracket> \\<medium_right_bracket>. .\n\nlemma [\\<phi>reason 800 for \\<open>?x \\<Ztypecolon> Word(_) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> _ \\<Ztypecolon> \\<int>(_) \\<a>\\<n>\\<d> _\\<close>]:\n  \" Threshold_Cost 9\n\\<Longrightarrow> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> y = sint x\n\\<Longrightarrow> x \\<Ztypecolon> Word('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> y \\<Ztypecolon> \\<int>('b)\"\n  for x :: \\<open>'b::len word\\<close>\n  \\<medium_left_bracket> construct\\<phi> \\<open>y \\<Ztypecolon> \\<int>('b)\\<close>\n    affirm apply (simp add: \\<open>y = sint x\\<close>) using sint_greater_eq sint_less by blast\n  \\<medium_right_bracket>. .\n\nlemma [\\<phi>reason 800 for \\<open>_ \\<Ztypecolon> Word(_) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> _ \\<a>\\<n>\\<d> _ @action to (Word _)\\<close>]:\n  \\<open> x \\<Ztypecolon> Word('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> sint x \\<Ztypecolon> \\<int>('b) @action to Word('b) \\<close>\n  \\<medium_left_bracket> \\<medium_right_bracket>. .\n\nlemma [\\<phi>reason 800 for \\<open>_ \\<Ztypecolon> \\<int>(_) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> _ \\<a>\\<n>\\<d> _ @action to (\\<phi>Nat _)\\<close>]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> 0 \\<le> x \\<and> x < 2 ^ (LENGTH('b)-1)\n\\<Longrightarrow> x \\<Ztypecolon> \\<int>('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> nat x \\<Ztypecolon> \\<nat>('b) @action to \\<nat>('b)\\<close>\n  \\<medium_left_bracket> to \\<open>Word('b)\\<close> \\<medium_right_bracket>\n  by (smt (verit, del_insts) diff_le_self power_increasing_iff the_\\<phi>(1) unat_eq_nat_uint word_of_int_inverse) .\n\nlemma [\\<phi>reason 800 for \\<open>_ \\<Ztypecolon> \\<int>(_) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> _ \\<Ztypecolon> \\<nat>(_) \\<a>\\<n>\\<d> _\\<close>]:\n  \\<open> Threshold_Cost 6\n\\<Longrightarrow> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> 0 \\<le> x \\<and> x < 2 ^ (LENGTH('b)-1) \\<and> y = nat x\n\\<Longrightarrow> x \\<Ztypecolon> \\<int>('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> y \\<Ztypecolon> \\<nat>('b)\\<close>\n  \\<medium_left_bracket> to \\<open>\\<nat>('b)\\<close> \\<medium_right_bracket>. .\n\nlemma [\\<phi>reason 800 for \\<open>_ \\<Ztypecolon> \\<nat>(_) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> _ \\<a>\\<n>\\<d> _ @action to \\<int>(_)\\<close>]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> x < 2 ^ (LENGTH('b)-1)\n\\<Longrightarrow> x \\<Ztypecolon> \\<nat>('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> of_nat x \\<Ztypecolon> \\<int>('b) @action to \\<int>(_) \\<close>\n  \\<medium_left_bracket> to \\<open>Word('b)\\<close> \\<medium_right_bracket>\n  by (metis One_nat_def id_apply the_\\<phi>(1) negative_zle of_int_eq_id of_nat_less_numeral_power_cancel_iff real_of_nat_eq_numeral_power_cancel_iff signed_of_nat signed_take_bit_int_eq_self_iff) .\n\nlemma [\\<phi>reason 800 for \\<open>_ \\<Ztypecolon> \\<nat>(_) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> _ \\<Ztypecolon> \\<int>(_) \\<a>\\<n>\\<d> _ \\<close>]:\n  \\<open> Threshold_Cost 5\n\\<Longrightarrow> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> x < 2 ^ (LENGTH('b)-1) \\<and> y = of_nat x\n\\<Longrightarrow> x \\<Ztypecolon> \\<nat>('b) \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> y \\<Ztypecolon> \\<int>('b) \\<close>\n  \\<medium_left_bracket> to \\<open>\\<int>(_)\\<close> \\<medium_right_bracket>. .\n\nlemma [\\<phi>reason 1000]:\n  \\<open>\\<phi>SemType (x \\<Ztypecolon> \\<int>('b)) int('b)\\<close> \\<medium_left_bracket> to \\<open>Word(_)\\<close> \\<medium_right_bracket>. .\n\nlemma [\\<phi>reason 1000]:\n  \"\\<phi>Zero int('b) \\<int>('b) 0\" \\<medium_left_bracket> \\<open>0 \\<Ztypecolon> Word('b)\\<close> \\<medium_right_bracket>. .\n\n\nlemma [\\<phi>reason 1000]:\n  \"\\<phi>Equal \\<int>('b) (\\<lambda>x y. True) (=)\"\n  \\<medium_left_bracket> to \\<open>Word(_)\\<close> \\<medium_right_bracket>\n  by (metis One_nat_def atLeastLessThan_iff the_\\<phi>lemmata signed_take_bit_int_eq_self_iff sint_sbintrunc') .\n\n\n\nsection \\<open>Instructions\\<close>\n\ndefinition op_const_int :: \"nat \\<Rightarrow> nat \\<Rightarrow> VAL proc\"\n  where \"op_const_int bits const = Return (\\<phi>arg (V_int.mk (bits,const)))\"\n\n(* definition op_const_size_t :: \"nat \\<Rightarrow> (VAL,VAL,'RES_N,'RES) proc\"\n  where \"op_const_size_t c = \\<phi>M_assume (c < 2 ^ addrspace_bits)\n                          \\<ggreater> Return (\\<phi>arg (V_int.mk (addrspace_bits,c)))\"\n  \\<comment> \\<open> `op_const_size_t` checks the overflow during the compilation towards certain decided platform.  \\<close>\n*)\n\ndefinition op_add :: \"nat \\<Rightarrow> (VAL \\<times> VAL, VAL) proc'\"\n  where \"op_add bits =\n      \\<phi>M_caseV (\\<lambda>vb va.\n      \\<phi>M_getV (T_int.mk bits) (snd o V_int.dest) vb (\\<lambda>val_b.\n      \\<phi>M_getV (T_int.mk bits) (snd o V_int.dest) va (\\<lambda>val_a.\n      Return (\\<phi>arg (V_int.mk (bits, ((val_a + val_b) mod 2^bits))))\n  )))\"\n\ndefinition op_sub :: \"nat \\<Rightarrow> (VAL \\<times> VAL, VAL) proc'\"\n  where \"op_sub bits =\n      \\<phi>M_caseV (\\<lambda>va vb.\n      \\<phi>M_getV (T_int.mk bits) (snd o V_int.dest) va (\\<lambda>val_a.\n      \\<phi>M_getV (T_int.mk bits) (snd o V_int.dest) vb (\\<lambda>val_b.\n      Return (\\<phi>arg (V_int.mk (bits, ((2^bits + val_b - val_a) mod 2^bits))))\n  )))\"\n\ndefinition op_umul :: \"nat \\<Rightarrow> (VAL \\<times> VAL, VAL) proc'\"\n  where \"op_umul bits =\n      \\<phi>M_caseV (\\<lambda>va vb.\n      \\<phi>M_getV (T_int.mk bits) (snd o V_int.dest) va (\\<lambda>val_a.\n      \\<phi>M_getV (T_int.mk bits) (snd o V_int.dest) vb (\\<lambda>val_b.\n      Return (\\<phi>arg (V_int.mk (bits, ((val_b * val_a) mod 2^bits))))\n  )))\"\n\ndefinition op_udiv :: \"nat \\<Rightarrow> (VAL \\<times> VAL, VAL) proc'\"\n  where \"op_udiv bits =\n      \\<phi>M_caseV (\\<lambda>va vb.\n      \\<phi>M_getV (T_int.mk bits) (snd o V_int.dest) va (\\<lambda>val_a.\n      \\<phi>M_getV (T_int.mk bits) (snd o V_int.dest) vb (\\<lambda>val_b.\n      \\<phi>M_assert (val_a \\<noteq> 0) \\<ggreater>\n      Return (\\<phi>arg (V_int.mk (bits, (val_b div val_a))))\n  )))\"\n\ndefinition op_sdiv :: \"'b::len itself \\<Rightarrow> (VAL \\<times> VAL, VAL) proc'\"\n  where \"op_sdiv _ =\n      \\<phi>M_caseV (\\<lambda>va vb.\n      \\<phi>M_getV (T_int.mk LENGTH('b)) (of_nat o snd o V_int.dest) va (\\<lambda>val_a::'b word.\n      \\<phi>M_getV (T_int.mk LENGTH('b)) (of_nat o snd o V_int.dest) vb (\\<lambda>val_b::'b word.\n      \\<phi>M_assert (val_a \\<noteq> 0) \\<ggreater>\n      Return (\\<phi>arg (V_int.mk (LENGTH('b), unat (val_b sdiv val_a))))\n  )))\"\n\ndefinition op_umod :: \"'b::len itself \\<Rightarrow> (VAL \\<times> VAL, VAL) proc'\"\n  where \"op_umod _ =\n      \\<phi>M_caseV (\\<lambda>va vb.\n      \\<phi>M_getV (T_int.mk LENGTH('b)) (of_nat o snd o V_int.dest) va (\\<lambda>val_a::'b word.\n      \\<phi>M_getV (T_int.mk LENGTH('b)) (of_nat o snd o V_int.dest) vb (\\<lambda>val_b::'b word.\n      \\<phi>M_assert (val_a \\<noteq> 0) \\<ggreater>\n      Return (\\<phi>arg (V_int.mk (LENGTH('b), unat (val_b mod val_a))))\n  )))\"\n\ndefinition op_smod :: \"'b::len itself \\<Rightarrow> (VAL \\<times> VAL, VAL) proc'\"\n  where \"op_smod _ =\n      \\<phi>M_caseV (\\<lambda>va vb.\n      \\<phi>M_getV (T_int.mk LENGTH('b)) (of_nat o snd o V_int.dest) va (\\<lambda>val_a::'b word.\n      \\<phi>M_getV (T_int.mk LENGTH('b)) (of_nat o snd o V_int.dest) vb (\\<lambda>val_b::'b word.\n      \\<phi>M_assert (val_a \\<noteq> 0) \\<ggreater>\n      Return (\\<phi>arg (V_int.mk (LENGTH('b), unat (val_b smod val_a))))\n  )))\"\n\ndefinition op_lshr :: \"nat \\<Rightarrow> nat \\<Rightarrow> (VAL \\<times> VAL, VAL) proc'\"\n  where \"op_lshr b_b b_a =\n      \\<phi>M_caseV (\\<lambda>va vb.\n      \\<phi>M_getV (T_int.mk b_a) (snd o V_int.dest) va (\\<lambda>val_a.\n      \\<phi>M_getV (T_int.mk b_b) (snd o V_int.dest) vb (\\<lambda>val_b.\n      Return (\\<phi>arg (V_int.mk (b_b, (val_b div 2 ^ val_a))))\n  )))\"\n\ndefinition op_lshl :: \"nat \\<Rightarrow> nat \\<Rightarrow> (VAL \\<times> VAL, VAL) proc'\"\n  where \"op_lshl b_b b_a =\n      \\<phi>M_caseV (\\<lambda>va vb.\n      \\<phi>M_getV (T_int.mk b_a) (snd o V_int.dest) va (\\<lambda>val_a.\n      \\<phi>M_getV (T_int.mk b_b) (snd o V_int.dest) vb (\\<lambda>val_b.\n      Return (\\<phi>arg (V_int.mk (b_b, (val_b * 2 ^ val_a mod 2^b_b))))\n  )))\"\n\ndefinition op_ult :: \"nat \\<Rightarrow> (VAL \\<times> VAL, VAL) proc'\"\n  where \"op_ult bits =\n      \\<phi>M_caseV (\\<lambda>va vb.\n      \\<phi>M_getV (T_int.mk bits) (snd o V_int.dest) va (\\<lambda>val_a.\n      \\<phi>M_getV (T_int.mk bits) (snd o V_int.dest) vb (\\<lambda>val_b.\n      Return (\\<phi>arg (V_bool.mk (val_b < val_a)))\n  )))\"\n\ndefinition op_ule :: \"nat \\<Rightarrow> (VAL \\<times> VAL, VAL) proc'\"\n  where \"op_ule bits =\n      \\<phi>M_caseV (\\<lambda>va vb.\n      \\<phi>M_getV (T_int.mk bits) (snd o V_int.dest) va (\\<lambda>val_a.\n      \\<phi>M_getV (T_int.mk bits) (snd o V_int.dest) vb (\\<lambda>val_b.\n      Return (\\<phi>arg (V_bool.mk (val_b \\<le> val_a)))\n  )))\"\n\ndefinition op_slt :: \"'b::len itself \\<Rightarrow> (VAL \\<times> VAL, VAL) proc'\"\n  where \"op_slt _ =\n      \\<phi>M_caseV (\\<lambda>va vb.\n      \\<phi>M_getV (T_int.mk LENGTH('b)) (of_nat o snd o V_int.dest) va (\\<lambda>val_a::'b word.\n      \\<phi>M_getV (T_int.mk LENGTH('b)) (of_nat o snd o V_int.dest) vb (\\<lambda>val_b.\n      Return (\\<phi>arg (V_bool.mk (val_b <s val_a)))\n  )))\"\n\ndefinition op_sle :: \"'b::len itself \\<Rightarrow> (VAL \\<times> VAL, VAL) proc'\"\n  where \"op_sle _ =\n      \\<phi>M_caseV (\\<lambda>va vb.\n      \\<phi>M_getV (T_int.mk LENGTH('b)) (of_nat o snd o V_int.dest) va (\\<lambda>val_a::'b word.\n      \\<phi>M_getV (T_int.mk LENGTH('b)) (of_nat o snd o V_int.dest) vb (\\<lambda>val_b.\n      Return (\\<phi>arg (V_bool.mk (val_b \\<le>s val_a)))\n  )))\"\n\n\ndefinition op_cast_uint :: \\<open>'b1::len itself \\<Rightarrow> 'b2::len itself \\<Rightarrow> (VAL, VAL) proc'\\<close>\n  where \\<open>op_cast_uint _ _ va =\n    \\<phi>M_getV (T_int.mk LENGTH('b1)) (of_nat o snd o V_int.dest) va (\\<lambda>val::'b1 word.\n    Return (\\<phi>arg (V_int.mk (LENGTH('b2), unat (Word.cast val :: 'b2 word)))))\\<close>\n\ndefinition op_cast_int :: \\<open>'b1::len itself \\<Rightarrow> 'b2::len itself \\<Rightarrow> (VAL, VAL) proc'\\<close>\n  where \\<open>op_cast_int _ _ va =\n    \\<phi>M_getV (T_int.mk LENGTH('b1)) (of_nat o snd o V_int.dest) va (\\<lambda>val::'b1 word.\n    Return (\\<phi>arg (V_int.mk (LENGTH('b2), unat (Word.scast val :: 'b2 word)))))\\<close>\n\n\nsection \\<open>Abstraction of Instructions\\<close>\n\nsubsection \\<open>Arithmetic Operations\\<close>\n\nsubsubsection \\<open>Constant Integer\\<close>\n\nlemma op_const_word_\\<phi>app[\\<phi>synthesis 300]:\n  \\<open> Simplify literal n (unat n')\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_const_int LENGTH('b) n \\<lbrace> Void \\<longmapsto> \\<v>\\<a>\\<l> n' \\<Ztypecolon> Word('b) \\<rbrace> \\<close>\n  unfolding op_const_int_def Premise_def Simplify_def\n  by (rule, simp add: \\<phi>expns)\n\nlemma op_const_nat_\\<phi>app[\\<phi>synthesis 200]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> n < 2 ^ LENGTH('b)\n\\<Longrightarrow> Simplify literal n' n\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_const_int LENGTH('b::len) n' \\<lbrace> Void \\<longmapsto> \\<v>\\<a>\\<l> n \\<Ztypecolon> \\<nat>('b) \\<rbrace> \\<close>\n  \\<medium_left_bracket> have [simp]: \\<open>unat (word_of_nat n :: 'b word) = n\\<close> using \\<phi> of_nat_inverse by blast\n  ;; op_const_word_\\<phi>app[where 'b='b and n'=\\<open>of_nat n\\<close> and n=n']\n    affirm by (simp add: \\<open>n' = n\\<close>)\n  \\<medium_right_bracket> by simp .\n\nlemma op_const_natR_\\<phi>app[\\<phi>synthesis 120]:\n  \\<open> Simplify literal n' (n mod 2 ^ LENGTH('b))\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_const_int LENGTH('b::len) n' \\<lbrace> Void \\<longmapsto> \\<v>\\<a>\\<l> n \\<Ztypecolon> \\<nat>\\<^sup>r('b) \\<rbrace> \\<close>\n  \\<medium_left_bracket> op_const_word[where 'b='b and n=n' and n' = \\<open>of_nat n\\<close>, simplified]\n    affirm by (simp add: the_\\<phi>(1) unat_of_nat)\n  \\<medium_right_bracket> by (simp add: unat_of_nat) .\n\nlemma [\\<phi>reason 50\n    for \\<open>Synthesis_Parse (numeral ?n::nat) (?X :: ?'ret \\<Rightarrow> assn)\\<close>\n       \\<open>Synthesis_Parse (1::nat) (?X :: ?'ret \\<Rightarrow> assn)\\<close>\n       \\<open>Synthesis_Parse (0::nat) (?X :: ?'ret \\<Rightarrow> assn)\\<close>\n]:\n  \\<open> Synthesis_Parse (n \\<Ztypecolon> \\<nat>(32)) X\n\\<Longrightarrow> Synthesis_Parse n X\\<close>\n  for X :: \\<open>'ret \\<Rightarrow> assn\\<close>\n  unfolding Synthesis_Parse_def ..\n\n\n(* lemma op_const_size_t:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_const_size_t n \\<lbrace> Void \\<longmapsto> \\<v>\\<a>\\<l> n \\<Ztypecolon> Size \\<rbrace>\\<close>\n  unfolding op_const_size_t_def Premise_def\n  by (\\<phi>reason, simp add: \\<phi>expns Big_def) *)\n\n\n(* lemma [\\<phi>reason 1200\n    for \\<open>\\<p>\\<r>\\<o>\\<c> ?f \\<lbrace> ?X' \\<longmapsto> ?X\\<heavy_comma> SYNTHESIS \\<v>\\<a>\\<l> (numeral ?n) \\<Ztypecolon> Size \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> ?E  @action synthesis ?G\\<close>\n       \\<open>\\<p>\\<r>\\<o>\\<c> ?f \\<lbrace> ?X' \\<longmapsto> ?X\\<heavy_comma> SYNTHESIS \\<v>\\<a>\\<l> 0 \\<Ztypecolon> Size \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> ?E  @action synthesis ?G\\<close>\n       \\<open>\\<p>\\<r>\\<o>\\<c> ?f \\<lbrace> ?X' \\<longmapsto> ?X\\<heavy_comma> SYNTHESIS \\<v>\\<a>\\<l> 1 \\<Ztypecolon> Size \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> ?E  @action synthesis ?G\\<close>\n]:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_const_size_t n \\<lbrace> R \\<longmapsto> R\\<heavy_comma> SYNTHESIS \\<v>\\<a>\\<l> n \\<Ztypecolon> Size \\<rbrace> @action synthesis G\\<close>\n  unfolding Synthesis_def Action_Tag_def\n  using op_const_size_t[THEN \\<phi>frame, simplified] . *)\n\n\nsubsubsection \\<open>Addition\\<close>\n\nlemma op_add_word_\\<phi>app[\\<phi>synthesis for _ (100)\n                                   and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x + y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<o>\\<c> op_add LENGTH('b) (\\<phi>V_pair vy vx) \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] Word('b) \\<longmapsto> \\<v>\\<a>\\<l> x + y \\<Ztypecolon> Word('b) \\<rbrace>\\<close>\n  unfolding op_add_def Premise_def\n  by (cases vx; cases vy; simp, rule, rule, simp add: \\<phi>expns, rule,\n      simp add: \\<phi>expns, rule, simp add: \\<phi>expns unat_word_ariths)\n\nlemma op_add_nat_\\<phi>app[\\<phi>overload add,\n                      \\<phi>synthesis for _ (100)\n                                 and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x + y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> x + y < 2 ^ LENGTH('b)\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_add LENGTH('b::len) (\\<phi>V_pair vy vx) \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] \\<nat>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] \\<nat>('b) \\<longmapsto> \\<v>\\<a>\\<l> x + y \\<Ztypecolon> \\<nat>('b) \\<rbrace> \\<close>\n  \\<medium_left_bracket> op_add_word[where 'b='b] \\<medium_right_bracket> using \\<phi> by (metis of_nat_add of_nat_inverse) .\n\nlemma op_add_natR_\\<phi>app[\\<phi>overload add,\n                       \\<phi>synthesis for _ (100)\n                                  and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>\\<^sup>r('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>\\<^sup>r('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x + y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<o>\\<c> op_add LENGTH('b::len) (\\<phi>V_pair vy vx) \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] \\<nat>\\<^sup>r('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] \\<nat>\\<^sup>r('b) \\<longmapsto> \\<v>\\<a>\\<l> x + y \\<Ztypecolon> \\<nat>\\<^sup>r('b) \\<rbrace> \\<close>\n  \\<medium_left_bracket> op_add_word[where 'b='b] \\<medium_right_bracket>\n    by (metis of_nat_add unat_of_nat) .\n\nlemma op_add_int_\\<phi>app[\\<phi>overload add,\n                      \\<phi>synthesis for _ (100)\n                                 and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<int>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<int>('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x + y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> x + y \\<in> {- (2 ^ (LENGTH('b)-1)) ..< 2 ^ (LENGTH('b)-1) }\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_add LENGTH('b::len) (\\<phi>V_pair vy vx) \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] \\<int>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] \\<int>('b) \\<longmapsto> \\<v>\\<a>\\<l> x + y \\<Ztypecolon> \\<int>('b) \\<rbrace> \\<close>\n  \\<medium_left_bracket> op_add_word[where 'b='b] \\<medium_right_bracket>\n    by (metis atLeastLessThan_iff the_\\<phi>(1) of_int_add signed_take_bit_int_eq_self_iff sint_sbintrunc') .\n\ndeclare op_add_word_\\<phi>app[\\<phi>overload add]\n\n\nsubsubsection \\<open>Subtraction\\<close>\n\nlemma op_sub_word_\\<phi>app[\\<phi>synthesis for _ (100)\n                                   and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x - y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_sub LENGTH('b::len) (\\<phi>V_pair vy vx) \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] Word('b) \\<longmapsto> \\<v>\\<a>\\<l> x - y \\<Ztypecolon> Word('b) \\<rbrace>\\<close>\n  unfolding op_sub_def Premise_def\n  apply (cases vx; cases vy; simp, rule, rule, simp add: \\<phi>expns,\n      rule, simp add: \\<phi>expns, rule, simp add: \\<phi>expns)\n  by (metis (no_types, opaque_lifting) Nat.add_diff_assoc2 add.commute add_0 mod_add_self2 unat_of_nat unat_sub_if' unsigned_0 word_arith_nat_add)\n\nlemma op_sub_nat_\\<phi>app[\\<phi>overload sub,\n                      \\<phi>synthesis for _ (100)\n                                 and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x - y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> y \\<le> x\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_sub LENGTH('b::len) (\\<phi>V_pair vy vx) \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] \\<nat>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] \\<nat>('b) \\<longmapsto> \\<v>\\<a>\\<l> x - y \\<Ztypecolon> \\<nat>('b) \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_sub_word[where 'b='b] \\<medium_right_bracket>\n    by (metis diff_le_self le_unat_uoi the_\\<phi>(1) the_\\<phi>lemmata(2) of_nat_diff of_nat_inverse) .\n\nlemma op_sub_natR_\\<phi>app[\\<phi>overload sub,\n                       \\<phi>synthesis for _ (100)\n                                  and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>\\<^sup>r('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>\\<^sup>r('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x - y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> y \\<le> x\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_sub LENGTH('b::len) (\\<phi>V_pair vy vx) \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] \\<nat>\\<^sup>r('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] \\<nat>\\<^sup>r('b) \\<longmapsto> \\<v>\\<a>\\<l> x - y \\<Ztypecolon> \\<nat>\\<^sup>r('b) \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_sub_word[where 'b='b] \\<medium_right_bracket>\n    by (metis of_nat_diff the_\\<phi>(1) unat_of_nat) .\n\nlemma op_sub_int_\\<phi>app[\\<phi>overload sub,\n                      \\<phi>synthesis for _ (100)\n                                 and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<int>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<int>('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x - y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> x - y \\<in> {- (2 ^ (LENGTH('b)-1)) ..< 2 ^ (LENGTH('b)-1) }\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_sub LENGTH('b::len) (\\<phi>V_pair vy vx) \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] \\<int>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] \\<int>('b) \\<longmapsto> \\<v>\\<a>\\<l> x - y \\<Ztypecolon> \\<int>('b) \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_sub_word[where 'b='b] \\<medium_right_bracket>\n    by (metis atLeastLessThan_iff the_\\<phi>(1) signed_take_bit_int_eq_self_iff sint_sbintrunc' wi_hom_sub) .\n\ndeclare op_sub_word_\\<phi>app[\\<phi>overload sub]\n\n\nsubsubsection \\<open>Multiplication\\<close>\n\n\nlemma op_mul_word_\\<phi>app[\\<phi>synthesis for _ (100)\n                                   and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x * y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<o>\\<c> op_umul LENGTH('b::len) (\\<phi>V_pair vy vx)\n         \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] Word('b) \\<longmapsto> \\<v>\\<a>\\<l> x * y \\<Ztypecolon> Word('b) \\<rbrace>\\<close>\n  unfolding op_umul_def Premise_def\n  by (cases vx; cases vy; simp, rule, rule, simp add: \\<phi>expns,\n      rule, simp add: \\<phi>expns, rule, simp add: \\<phi>expns unat_word_ariths(2))\n\nlemma op_mul_nat_\\<phi>app[\\<phi>overload mul,\n                      \\<phi>synthesis for _ (100)\n                                 and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x * y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> x * y < 2^LENGTH('b)\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_umul LENGTH('b::len) (\\<phi>V_pair vy vx)\n         \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] \\<nat>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] \\<nat>('b) \\<longmapsto> \\<v>\\<a>\\<l> x * y \\<Ztypecolon> \\<nat>('b) \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_mul_word[where 'b='b] \\<medium_right_bracket>\n    using the_\\<phi>(1) of_nat_inverse by fastforce .\n\nlemma op_mul_natR_\\<phi>app[\\<phi>overload mul,\n                       \\<phi>synthesis for _ (100)\n                                  and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>\\<^sup>r('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>\\<^sup>r('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x * y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<o>\\<c> op_umul LENGTH('b::len) (\\<phi>V_pair vy vx)\n         \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] \\<nat>\\<^sup>r('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] \\<nat>\\<^sup>r('b) \\<longmapsto> \\<v>\\<a>\\<l> x * y \\<Ztypecolon> \\<nat>\\<^sup>r('b) \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_mul_word[where 'b='b] \\<medium_right_bracket>\n    by (metis of_nat_mult unat_of_nat) .\n\nlemma op_mul_int_\\<phi>app[\\<phi>overload mul,\n                      \\<phi>synthesis for _ (100)\n                                 and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<int>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<int>('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x * y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> x * y \\<in> {- (2 ^ (LENGTH('b)-1)) ..< 2 ^ (LENGTH('b)-1) }\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_umul LENGTH('b::len) (\\<phi>V_pair vy vx)\n         \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] \\<int>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] \\<int>('b) \\<longmapsto> \\<v>\\<a>\\<l> x * y \\<Ztypecolon> \\<int>('b) \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_mul_word[where 'b='b] \\<medium_right_bracket>\n    by (metis atLeastLessThan_iff the_\\<phi>(1) nle_le of_int_mult signed_take_bit_int_greater_eq_self_iff signed_take_bit_int_less_eq_self_iff sint_sbintrunc') .\n\ndeclare op_mul_word_\\<phi>app[\\<phi>overload mul]\n\n\nsubsubsection \\<open>Division\\<close>\n\nlemma op_udiv_word_\\<phi>app[\\<phi>synthesis for _ (100)\n                                   and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x div y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> y \\<noteq> 0\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_udiv LENGTH('b) (\\<phi>V_pair vy vx) \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] Word('b) \\<longmapsto> \\<v>\\<a>\\<l> x div y \\<Ztypecolon> Word('b) \\<rbrace>\\<close>\n  unfolding op_udiv_def Premise_def\n  by (cases vx; cases vy; simp, rule, rule, simp add: \\<phi>expns, rule, simp add: \\<phi>expns, rule,\n      rule \\<phi>M_assert, simp add: \\<phi>expns unat_gt_0, rule, simp add: \\<phi>expns unat_div)\n\nlemma op_div_nat_\\<phi>app[\\<phi>overload div,\n                      \\<phi>synthesis for _ (100)\n                                 and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x div y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> y \\<noteq> 0\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_udiv LENGTH('b) (\\<phi>V_pair vy vx) \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] \\<nat>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] \\<nat>('b) \\<longmapsto> \\<v>\\<a>\\<l> x div y \\<Ztypecolon> \\<nat>('b) \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_udiv_word_\\<phi>app[where 'b='b]\n    affirm using More_Word.of_nat_0 the_\\<phi>(2) the_\\<phi>(3) by blast\n  \\<medium_right_bracket> by (simp add: the_\\<phi>lemmata(1) the_\\<phi>lemmata(2) of_nat_inverse unat_div) .\n\ndeclare op_udiv_word_\\<phi>app[\\<phi>overload div]\n\n\nlemma op_sdiv_word_\\<phi>app[\\<phi>synthesis for _ (100)\n                                   and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x sdiv y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> y \\<noteq> 0\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_sdiv TYPE('b) (\\<phi>V_pair vy vx) \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] Word('b) \\<longmapsto> \\<v>\\<a>\\<l> x sdiv y \\<Ztypecolon> Word('b) \\<rbrace>\\<close>\n  unfolding op_sdiv_def Premise_def\n  by (cases vx; cases vy; simp, rule, rule, simp add: \\<phi>expns, rule, simp add: \\<phi>expns, rule,\n        rule \\<phi>M_assert, simp add: \\<phi>expns unat_gt_0, rule, simp add: \\<phi>expns)\n\nlemma op_div_int_\\<phi>app[\\<phi>synthesis for _ (100)\n                                 and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<int>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<int>('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x sdiv y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> x \\<noteq> - (2 ^ (LENGTH('b) - 1)) \\<and> y \\<noteq> 0\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_sdiv TYPE('b) (\\<phi>V_pair vy vx) \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] \\<int>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] \\<int>('b) \\<longmapsto> \\<v>\\<a>\\<l> x sdiv y \\<Ztypecolon> \\<int>('b) \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_sdiv_word\n    affirm by (metis atLeastLessThan_iff signed_0 sint_of_int_eq the_\\<phi>(2) the_\\<phi>(3)) \\<medium_right_bracket>\n    unfolding sdiv_word_def\n  proof simp\n    have [simp]: \\<open>sint (word_of_int x::'b word) = x\\<close>\n      by (meson atLeastLessThan_iff sint_of_int_eq the_\\<phi>lemmata(2))\n    have [simp]: \\<open>sint (word_of_int y::'b word) = y\\<close>\n      by (meson atLeastLessThan_iff sint_of_int_eq the_\\<phi>lemmata(1))\n\n    have t1: \\<open>x < 2 ^ (LENGTH('b)-1)\\<close>\n      using atLeastLessThan_iff the_\\<phi>lemmata(2) by blast\n    have t2: \\<open>- (2 ^ (LENGTH('b)-1)) < x\\<close>\n      by (meson Orderings.order_eq_iff atLeastLessThan_iff leI the_\\<phi>(3) the_\\<phi>lemmata(2))\n    have t3: \\<open>\\<bar>x\\<bar> < 2 ^ (LENGTH('b)-1)\\<close>\n      using t1 t2 by linarith\n    have t4: \\<open>\\<bar>x sdiv y\\<bar> < 2 ^ (LENGTH('b)-1)\\<close>\n      unfolding signed_divide_int_def\n      apply (cases \\<open>x = 0\\<close>) apply simp\n      apply (cases \\<open>y = 0\\<close>) apply simp\n      apply (simp add: abs_mult)\n      by (smt (verit, best) One_nat_def int_div_less_self int_div_same_is_1 pos_imp_zdiv_neg_iff t3)\n    show \\<open>x sdiv y = sint (word_of_int (sint (word_of_int x::'b word) sdiv sint (word_of_int y::'b word))::'b word)\\<close>\n      apply simp\n      by (smt (verit, del_insts) t4 sint_of_int_eq)\n  qed .\n\nlemma op_div_int_fail[\\<phi>synthesis for _ (100)\n                                 and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<int>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<int>('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x div y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> FAIL TEXT(\\<open>About integers, there is no rule available for unsigned division\\<close> (div)\n              \\<open>Please use the signed\\<close> (sdiv)\n              \\<open>Note the C semantics is\\<close> (sdiv) \\<open>instead of\\<close> (div)\n              \\<open>and they are different in negative numbers\\<close>)\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> fail \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] \\<int>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] \\<int>('b) \\<longmapsto> \\<v>\\<a>\\<l> x div y \\<Ztypecolon> \\<int>('b) \\<rbrace>\\<close>\n  by blast\n\nsubsubsection \\<open>Modulo\\<close>\n\nlemma op_umod_word_\\<phi>app\n  [\\<phi>synthesis for _ (100)\n              and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x mod y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> y \\<noteq> 0\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_umod TYPE('b) (\\<phi>V_pair vy vx) \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] Word('b) \\<longmapsto> \\<v>\\<a>\\<l> x mod y \\<Ztypecolon> Word('b) \\<rbrace>\\<close>\n  unfolding op_umod_def Premise_def\n  by (cases vx; cases vy; simp, rule, rule, simp add: \\<phi>expns, rule, simp add: \\<phi>expns, rule,\n      rule \\<phi>M_assert, simp add: \\<phi>expns unat_gt_0, rule, simp add: \\<phi>expns unat_div)\n\nlemma op_mod_nat_\\<phi>app\n  [\\<phi>synthesis for _ (100)\n              and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x mod y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> y \\<noteq> 0\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_umod TYPE('b) (\\<phi>V_pair vy vx)\n      \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] \\<nat>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] \\<nat>('b) \\<longmapsto> \\<v>\\<a>\\<l> x mod y \\<Ztypecolon> \\<nat>('b) \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_umod_word\n    affirm using More_Word.of_nat_0 the_\\<phi>(2) the_\\<phi>(3) by blast \\<medium_right_bracket>\n  by (simp add: of_nat_inverse the_\\<phi>lemmata(1) the_\\<phi>lemmata(2) unat_mod_distrib) .\n\nlemma op_smod_word_\\<phi>app\n  [\\<phi>synthesis for _ (100)\n              and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<close> \\<Rightarrow> \\<open>\\<lambda> v. x smod y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> y \\<noteq> 0\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_smod TYPE('b) (\\<phi>V_pair vy vx) \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] Word('b) \\<longmapsto> \\<v>\\<a>\\<l> x smod y \\<Ztypecolon> Word('b) \\<rbrace>\\<close>\n  unfolding op_smod_def Premise_def\n  by (cases vx; cases vy; simp, rule, rule, simp add: \\<phi>expns, rule, simp add: \\<phi>expns, rule,\n      rule \\<phi>M_assert, simp add: \\<phi>expns unat_gt_0, rule, simp add: \\<phi>expns unat_div)\n\nlemma op_mod_int_\\<phi>app\n  [\\<phi>synthesis for _ (100)\n              and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<int>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<int>('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x smod y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> y \\<noteq> 0\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_smod TYPE('b) (\\<phi>V_pair vy vx)\n      \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] \\<int>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] \\<int>('b) \\<longmapsto> \\<v>\\<a>\\<l> x smod y \\<Ztypecolon> \\<int>('b) \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_smod_word\n    affirm by (metis atLeastLessThan_iff signed_0 sint_of_int_eq the_\\<phi>(2) the_\\<phi>(3)) \\<medium_right_bracket>\n  by (metis One_nat_def atLeastLessThan_iff signed_take_bit_int_eq_self_iff sint_sbintrunc' smod_word_def smod_word_max smod_word_min the_\\<phi>lemmata(1) the_\\<phi>lemmata(2)) .\n\nlemma op_mod_int_fail[\\<phi>synthesis 100]:\n  \\<open> FAIL TEXT(\\<open>About integers, there is no rule available for unsigned modulo\\<close> (mod)\n              \\<open>Please use the signed\\<close> (smod)\n              \\<open>Note the C semantics is\\<close> (smod) \\<open>instead of\\<close> (mod)\n              \\<open>and they are different in negative numbers\\<close>)\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> fail \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] \\<int>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] \\<int>('b) \\<longmapsto> \\<v>\\<a>\\<l> x mod y \\<Ztypecolon> \\<int>('b) \\<rbrace>\\<close>\n  by blast\n\n\nsubsubsection \\<open>Shift\\<close>\n\nparagraph \\<open>Right Shift\\<close>\n\nlemma op_lshr_word_pre_\\<phi>app:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_lshr LENGTH('ba) LENGTH('bb) (\\<phi>V_pair v2 v1)\n        \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[v1] Word('ba) \\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[v2] Word('bb) \\<longmapsto> \\<v>\\<a>\\<l> drop_bit (unat y) x \\<Ztypecolon> Word('ba) \\<rbrace>\\<close>\n  unfolding op_lshr_def\n  apply (cases v1; cases v2; simp; rule, rule, simp add: \\<phi>expns, rule, simp add: \\<phi>expns,\n      rule, simp add: \\<phi>expns)\n  by (metis drop_bit_eq_div unat_drop_bit_eq)\n\nlemma op_lshr_word_\\<phi>app\n  [\\<phi>synthesis for _ (100)\n              and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> Word('ba) \\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('bb)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. drop_bit y x \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_lshr LENGTH('ba) LENGTH('bb) (\\<phi>V_pair v2 v1)\n        \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[v1] Word('ba) \\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[v2] \\<nat>('bb) \\<longmapsto> \\<v>\\<a>\\<l> drop_bit y x \\<Ztypecolon> Word('ba) \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_lshr_word_pre_\\<phi>app[where 'ba='ba and 'bb='bb] \\<medium_right_bracket>\n    by (simp add: the_\\<phi>(1) unat_of_nat) .\n\nlemma op_lshr_nat_\\<phi>app\n  [\\<phi>synthesis for _ (100)\n              and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('ba) \\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('bb)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. drop_bit y x \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_lshr LENGTH('ba) LENGTH('bb) (\\<phi>V_pair v2 v1)\n        \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[v1] \\<nat>('ba) \\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[v2] \\<nat>('bb) \\<longmapsto> \\<v>\\<a>\\<l> drop_bit y x \\<Ztypecolon> \\<nat>('ba) \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_lshr_word_\\<phi>app[where 'ba='ba and 'bb='bb] \\<medium_right_bracket>\n    by (simp add: the_\\<phi>(1) of_nat_inverse unat_drop_bit_eq) .\n\n\nlemma drop_bit_nat_le:\n  \\<open>drop_bit n x \\<le> x\\<close> for x :: nat\n  using div_le_dividend drop_bit_nat_def by presburger\n\nlemma op_lshr_int_\\<phi>app\n  [\\<phi>synthesis for _ (100)\n              and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<int>('ba) \\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('bb)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. drop_bit y x \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> 0 \\<le> x\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_lshr LENGTH('ba) LENGTH('bb) (\\<phi>V_pair v2 v1)\n        \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[v1] \\<int>('ba) \\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[v2] \\<nat>('bb) \\<longmapsto> \\<v>\\<a>\\<l> drop_bit y x \\<Ztypecolon> \\<int>('ba) \\<rbrace>\\<close>\n  \\<medium_left_bracket>\n  ;; $v1\n  have t1: \\<open>x < 2 ^ (LENGTH('ba) - 1)\\<close>\n    using atLeastLessThan_iff the_\\<phi>(1) by blast\n  have t2: \\<open>nat x < 2 ^ (LENGTH('ba) - 1)\\<close>\n    using t1 by fastforce\n\n  ;; $v1 $v2 op_lshr_nat_\\<phi>app[where 'ba='ba and 'bb='bb]\n  \\<medium_right_bracket>\n  apply rule+ using t2 drop_bit_nat_le order.strict_trans1 apply blast\n  apply (simp add: of_nat_drop_bit the_\\<phi>(2)) .. .\n\nparagraph \\<open>Left Shift\\<close>\n\nlemma op_lshl_word_pre_\\<phi>app:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_lshl LENGTH('ba) LENGTH('bb) (\\<phi>V_pair v2 v1)\n        \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[v1] Word('ba) \\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[v2] Word('bb) \\<longmapsto> \\<v>\\<a>\\<l> push_bit (unat y) x \\<Ztypecolon> Word('ba) \\<rbrace>\\<close>\n  unfolding op_lshl_def\n  apply (cases v1; cases v2; simp; rule, rule, simp add: \\<phi>expns, rule, simp add: \\<phi>expns,\n      rule, simp add: \\<phi>expns)\n  by (simp add: push_bit_nat_def take_bit_nat_def unsigned_push_bit_eq)\n\nlemma op_lshl_word_\\<phi>app\n  [\\<phi>synthesis for _ (100)\n              and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> Word('ba) \\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('bb)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. push_bit y x \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_lshl LENGTH('ba) LENGTH('bb) (\\<phi>V_pair v2 v1)\n        \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[v1] Word('ba) \\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[v2] \\<nat>('bb) \\<longmapsto> \\<v>\\<a>\\<l> push_bit y x \\<Ztypecolon> Word('ba) \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_lshl_word_pre_\\<phi>app[where 'ba='ba and 'bb='bb] \\<medium_right_bracket>\n    by (simp add: of_nat_inverse the_\\<phi>(1)) .\n\nlemma op_lshl_nat_\\<phi>app\n  [\\<phi>synthesis for _ (100)\n              and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('ba) \\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('bb)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. push_bit y x \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> x * 2 ^ y < LENGTH('ba)\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_lshl LENGTH('ba) LENGTH('bb) (\\<phi>V_pair v2 v1)\n        \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[v1] \\<nat>('ba) \\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[v2] \\<nat>('bb) \\<longmapsto> \\<v>\\<a>\\<l> push_bit y x \\<Ztypecolon> \\<nat>('ba) \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_lshl_word_\\<phi>app[where 'ba='ba and 'bb='bb] \\<medium_right_bracket>\n  unfolding push_bit_nat_def\n  by (metis dual_order.strict_trans less_exp of_nat_inverse of_nat_push_bit push_bit_eq_mult the_\\<phi>(1)) .\n\nlemma op_lshl_natR_\\<phi>app\n  [\\<phi>synthesis for _ (100)\n              and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>\\<^sup>r('ba) \\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('bb)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. push_bit y x \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> x * 2 ^ y < LENGTH('ba)\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_lshl LENGTH('ba) LENGTH('bb) (\\<phi>V_pair v2 v1)\n        \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[v1] \\<nat>\\<^sup>r('ba) \\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[v2] \\<nat>('bb) \\<longmapsto> \\<v>\\<a>\\<l> push_bit y x \\<Ztypecolon> \\<nat>\\<^sup>r('ba) \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_lshl_word_\\<phi>app[where 'ba='ba and 'bb='bb] \\<medium_right_bracket>\n  unfolding push_bit_nat_def\n  by (metis push_bit_nat_def push_bit_of_nat unat_of_nat) .\n\n\nsubsubsection \\<open>Comparison\\<close>\n\nparagraph \\<open>Unsigned Less Than\\<close>\n\nlemma op_lt_word_\\<phi>app\n  [\\<phi>overload less, \\<phi>synthesis for _ (100)\n                           and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x < y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_ult LENGTH('b) (\\<phi>V_pair vy vx)\n       \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] Word('b) \\<longmapsto> \\<v>\\<a>\\<l> x < y \\<Ztypecolon> \\<bool> \\<rbrace>\\<close>\n  unfolding op_ult_def\n  by (cases vx; cases vy; simp, rule, rule, simp add: \\<phi>expns, rule,\n      simp add: \\<phi>expns, rule, simp add: \\<phi>expns word_less_nat_alt)\n\nlemma op_lt_nat_\\<phi>app\n  [\\<phi>overload less, \\<phi>synthesis for _ (100)\n                           and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x < y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_ult LENGTH('b) (\\<phi>V_pair vy vx)\n       \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] \\<nat>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] \\<nat>('b) \\<longmapsto> \\<v>\\<a>\\<l> x < y \\<Ztypecolon> \\<bool> \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_lt_word[where 'b='b] \\<medium_right_bracket>\n    by (simp add: of_nat_inverse the_\\<phi>lemmata(1) the_\\<phi>lemmata(2) word_less_nat_alt) .\n\nparagraph \\<open>Signed Less Than\\<close>\n\nlemma op_slt_word_\\<phi>app\n  [\\<phi>overload less, \\<phi>synthesis for _ (100)\n                           and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x <s y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_slt TYPE('b) (\\<phi>V_pair vy vx)\n       \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] Word('b) \\<longmapsto> \\<v>\\<a>\\<l> x <s y \\<Ztypecolon> \\<bool> \\<rbrace>\\<close>\n  unfolding op_slt_def\n  by (cases vx; cases vy; simp, rule, rule, simp add: \\<phi>expns, rule,\n      simp add: \\<phi>expns, rule, simp add: \\<phi>expns)\n\nlemma op_slt_int_\\<phi>app\n  [\\<phi>overload less, \\<phi>synthesis for _ (100)\n                           and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<int>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<int>('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x < y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_slt TYPE('b) (\\<phi>V_pair vy vx)\n       \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[vx] \\<int>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[vy] \\<int>('b) \\<longmapsto> \\<v>\\<a>\\<l> x < y \\<Ztypecolon> \\<bool> \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_slt_word[where 'b='b] \\<medium_right_bracket>\n    by (metis antisym_conv1 atLeastLessThan_iff linorder_not_le signed_take_bit_int_greater_eq_self_iff signed_take_bit_int_less_eq_self_iff sint_sbintrunc' the_\\<phi>lemmata(1) the_\\<phi>lemmata(2) word_sless_alt) .\n\n\nparagraph \\<open>Unsigned Less Equal\\<close>\n\nlemma op_le_word_\\<phi>app\n  [\\<phi>overload less_equal, \\<phi>synthesis for _ (100)\n                            and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x \\<le> y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_ule LENGTH('b) (\\<phi>V_pair rawy rawx)\n        \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[rawx] Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[rawy] Word('b) \\<longmapsto> \\<v>\\<a>\\<l> x \\<le> y \\<Ztypecolon> \\<bool> \\<rbrace>\\<close>\n  unfolding op_ule_def\n  by (cases rawx; cases rawy; simp, rule, rule, simp add: \\<phi>expns,\n      rule, simp add: \\<phi>expns, rule, simp add: \\<phi>expns word_le_nat_alt)\n\nlemma op_le_nat_\\<phi>app\n  [\\<phi>overload less_equal, \\<phi>synthesis for _ (100)\n                            and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x \\<le> y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_ule LENGTH('b) (\\<phi>V_pair rawy rawx)\n        \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[rawx] \\<nat>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[rawy] \\<nat>('b) \\<longmapsto> \\<v>\\<a>\\<l> x \\<le> y \\<Ztypecolon> \\<bool> \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_le_word \\<medium_right_bracket>\n    by (simp add: the_\\<phi>lemmata(1) the_\\<phi>lemmata(2) unat_of_nat word_le_nat_alt) .\n\nparagraph \\<open>Signed Less Equal\\<close>\n\nlemma op_sle_word_\\<phi>app\n  [\\<phi>overload less_equal, \\<phi>synthesis for _ (100)\n                            and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> Word('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x \\<le>s y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_sle TYPE('b) (\\<phi>V_pair rawy rawx)\n        \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[rawx] Word('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[rawy] Word('b) \\<longmapsto> \\<v>\\<a>\\<l> x \\<le>s y \\<Ztypecolon> \\<bool> \\<rbrace>\\<close>\n  unfolding op_sle_def\n  by (cases rawx; cases rawy; simp, rule, rule, simp add: \\<phi>expns,\n      rule, simp add: \\<phi>expns, rule, simp add: \\<phi>expns word_le_nat_alt)\n\nlemma op_le_int_\\<phi>app\n  [\\<phi>overload less_equal, \\<phi>synthesis for _ (100)\n                            and \\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<int>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l> \\<int>('b)\\<close> \\<Rightarrow> \\<open>\\<lambda>v. x \\<le> y \\<Ztypecolon> _\\<close> (1200)]:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_sle TYPE('b) (\\<phi>V_pair rawy rawx)\n        \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[rawx] \\<int>('b)\\<heavy_comma> y \\<Ztypecolon> \\<v>\\<a>\\<l>[rawy] \\<int>('b) \\<longmapsto> \\<v>\\<a>\\<l> x \\<le> y \\<Ztypecolon> \\<bool> \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_sle_word \\<medium_right_bracket>\n    by (metis atLeastLessThan_iff signed_take_bit_int_eq_self_iff sint_sbintrunc' the_\\<phi>lemmata(1) the_\\<phi>lemmata(2) word_sle_eq) .\n\nsubsubsection \\<open>Cast\\<close>\n\nlemma op_cast_uint_word_\\<phi>app:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_cast_uint TYPE('ba) TYPE('bb) v\n     \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[v] Word('ba) \\<longmapsto> Word.cast x \\<Ztypecolon> \\<v>\\<a>\\<l> Word('bb) \\<rbrace>\\<close>\n  unfolding op_cast_uint_def\n  by (cases v, simp, rule, simp add: \\<phi>expns, rule, simp add: \\<phi>expns)\n\nlemma op_cast_nat_\\<phi>app:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_cast_uint TYPE('ba) TYPE('bb) v\n     \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[v] \\<nat>('ba) \\<longmapsto> take_bit LENGTH('bb) x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('bb) \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_cast_uint_word[where 'bb='bb] \\<medium_right_bracket>\n    by (simp add: of_nat_inverse the_\\<phi>lemmata unsigned_ucast_eq) .\n\nlemma op_cast_int_word_\\<phi>app:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_cast_int TYPE('ba) TYPE('bb) v\n     \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[v] Word('ba) \\<longmapsto> Word.scast x \\<Ztypecolon> \\<v>\\<a>\\<l> Word('bb) \\<rbrace>\\<close>\n  unfolding op_cast_int_def\n  by (cases v, simp, rule, simp add: \\<phi>expns, rule, simp add: \\<phi>expns)\n\nlemma op_cast_int_\\<phi>app:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_cast_int TYPE('ba) TYPE('bb) v\n     \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[v] \\<int>('ba) \\<longmapsto> signed_take_bit (LENGTH('bb)-1) x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<int>('bb) \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_cast_int_word[where 'bb='bb] \\<medium_right_bracket>\n    by (metis One_nat_def atLeastLessThan_iff signed_scast_eq signed_take_bit_int_eq_self sint_sbintrunc' the_\\<phi>lemmata) .\n\nlemma op_upcast_nat_\\<phi>app:\n  \\<open> \\<s>\\<i>\\<m>\\<p>\\<r>\\<e>\\<m> LENGTH('ba) \\<le> LENGTH('bb)\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_cast_uint TYPE('ba) TYPE('bb) v\n     \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[v] \\<nat>('ba) \\<longmapsto> x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<nat>('bb) \\<rbrace>\\<close>\n  \\<medium_left_bracket> have [useful]: \\<open>x < 2 ^ LENGTH('ba)\\<close> using \\<phi> by blast\n  ;; $v op_cast_nat[where 'bb='bb] \\<medium_right_bracket>\n    by (metis le_antisym take_bit_nat_eq_self take_bit_nat_less_eq_self take_bit_tightened_less_eq_nat the_\\<phi>(2) the_\\<phi>(3)) .\n\nlemma op_upcast_int_\\<phi>app:\n  \\<open> \\<s>\\<i>\\<m>\\<p>\\<r>\\<e>\\<m> LENGTH('ba) \\<le> LENGTH('bb)\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_cast_int TYPE('ba) TYPE('bb) v\n     \\<lbrace> x \\<Ztypecolon> \\<v>\\<a>\\<l>[v] \\<int>('ba) \\<longmapsto> x \\<Ztypecolon> \\<v>\\<a>\\<l> \\<int>('bb) \\<rbrace>\\<close>\n  \\<medium_left_bracket> op_cast_int_word[where 'bb='bb] \\<medium_right_bracket>\n  proof simp\n    have t1: \\<open>is_up (Word.scast :: 'ba word \\<Rightarrow> 'bb word)\\<close>\n      using is_up that(1) by blast\n    show \\<open>x = sint (Word.scast (word_of_int x :: 'ba word) :: 'bb word)\\<close>\n      by (metis atLeastLessThan_iff sint_of_int_eq sint_up_scast t1 the_\\<phi>lemmata)\n  qed .\n\n\nend", "meta": {"author": "xqyww123", "repo": "phi-system", "sha": "c8dca186bcc8ac2c9b38d813fc0f0dfec486ebab", "save_path": "github-repos/isabelle/xqyww123-phi-system", "path": "github-repos/isabelle/xqyww123-phi-system/phi-system-c8dca186bcc8ac2c9b38d813fc0f0dfec486ebab/Phi_Semantics/PhiSem_Machine_Integer.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6113819874558604, "lm_q2_score": 0.43782349911420193, "lm_q1q2_score": 0.2676774010433199}}
{"text": "(*  Title:       Safe OCL\n    Author:      Denis Nikiforov, March 2019\n    Maintainer:  Denis Nikiforov <denis.nikif at gmail.com>\n    License:     LGPL\n*)\nsection \\<open>Object Model\\<close>\ntheory Object_Model\n  imports \"HOL-Library.Extended_Nat\" Finite_Map_Ext\nbegin\n\ntext \\<open>\n  The section defines a generic object model.\\<close>\n\n(*** Type Synonyms **********************************************************)\n\nsubsection \\<open>Type Synonyms\\<close>\n\ntype_synonym attr = String.literal\ntype_synonym assoc = String.literal\ntype_synonym role = String.literal\ntype_synonym oper = String.literal\ntype_synonym param = String.literal\ntype_synonym elit = String.literal\n\ndatatype param_dir = In | Out | InOut\n\ntype_synonym 'c assoc_end = \"'c \\<times> nat \\<times> enat \\<times> bool \\<times> bool\"\ntype_synonym 't param_spec = \"param \\<times> 't \\<times> param_dir\"\ntype_synonym ('t, 'e) oper_spec =\n  \"oper \\<times> 't \\<times> 't param_spec list \\<times> 't \\<times> bool \\<times> 'e option\"\n\ndefinition \"assoc_end_class :: 'c assoc_end \\<Rightarrow> 'c \\<equiv> fst\"\ndefinition \"assoc_end_min :: 'c assoc_end \\<Rightarrow> nat \\<equiv> fst \\<circ> snd\"\ndefinition \"assoc_end_max :: 'c assoc_end \\<Rightarrow> enat \\<equiv> fst \\<circ> snd \\<circ> snd\"\ndefinition \"assoc_end_ordered :: 'c assoc_end \\<Rightarrow> bool \\<equiv> fst \\<circ> snd \\<circ> snd \\<circ> snd\"\ndefinition \"assoc_end_unique :: 'c assoc_end \\<Rightarrow> bool \\<equiv> snd \\<circ> snd \\<circ> snd \\<circ> snd\"\n\ndefinition \"oper_name :: ('t, 'e) oper_spec \\<Rightarrow> oper \\<equiv> fst\"\ndefinition \"oper_context :: ('t, 'e) oper_spec \\<Rightarrow> 't \\<equiv> fst \\<circ> snd\"\ndefinition \"oper_params :: ('t, 'e) oper_spec \\<Rightarrow> 't param_spec list \\<equiv> fst \\<circ> snd \\<circ> snd\"\ndefinition \"oper_result :: ('t, 'e) oper_spec \\<Rightarrow> 't \\<equiv> fst \\<circ> snd \\<circ> snd \\<circ> snd\"\ndefinition \"oper_static :: ('t, 'e) oper_spec \\<Rightarrow> bool \\<equiv> fst \\<circ> snd \\<circ> snd \\<circ> snd \\<circ> snd\"\ndefinition \"oper_body :: ('t, 'e) oper_spec \\<Rightarrow> 'e option \\<equiv> snd \\<circ> snd \\<circ> snd \\<circ> snd \\<circ> snd\"\n\ndefinition \"param_name ::'t param_spec \\<Rightarrow> param \\<equiv> fst\"\ndefinition \"param_type ::'t param_spec \\<Rightarrow> 't \\<equiv> fst \\<circ> snd\"\ndefinition \"param_dir ::'t param_spec \\<Rightarrow> param_dir \\<equiv> snd \\<circ> snd\"\n\ndefinition \"oper_in_params op \\<equiv>\n  filter (\\<lambda>p. param_dir p = In \\<or> param_dir p = InOut) (oper_params op)\"\n\ndefinition \"oper_out_params op \\<equiv>\n  filter (\\<lambda>p. param_dir p = Out \\<or> param_dir p = InOut) (oper_params op)\"\n\nsubsection \\<open>Attributes\\<close>\n\ninductive owned_attribute' where\n  \"\\<C> |\\<in>| fmdom attributes \\<Longrightarrow>\n   fmlookup attributes \\<C> = Some attrs\\<^sub>\\<C> \\<Longrightarrow>\n   fmlookup attrs\\<^sub>\\<C> attr = Some \\<tau> \\<Longrightarrow>\n   owned_attribute' attributes \\<C> attr \\<tau>\"\n\ninductive attribute_not_closest where\n  \"owned_attribute' attributes \\<D>' attr \\<tau>' \\<Longrightarrow>\n   \\<C> \\<le> \\<D>' \\<Longrightarrow>\n   \\<D>' < \\<D> \\<Longrightarrow>\n   attribute_not_closest attributes \\<C> attr \\<D> \\<tau>\"\n\ninductive closest_attribute where\n  \"owned_attribute' attributes \\<D> attr \\<tau> \\<Longrightarrow>\n   \\<C> \\<le> \\<D> \\<Longrightarrow>\n   \\<not> attribute_not_closest attributes \\<C> attr \\<D> \\<tau> \\<Longrightarrow>\n   closest_attribute attributes \\<C> attr \\<D> \\<tau>\"\n\ninductive closest_attribute_not_unique where\n  \"closest_attribute attributes \\<C> attr \\<D>' \\<tau>' \\<Longrightarrow>\n   \\<D> \\<noteq> \\<D>' \\<or> \\<tau> \\<noteq> \\<tau>' \\<Longrightarrow>\n   closest_attribute_not_unique attributes \\<C> attr \\<D> \\<tau>\"\n\ninductive unique_closest_attribute where\n  \"closest_attribute attributes \\<C> attr \\<D> \\<tau> \\<Longrightarrow>\n   \\<not> closest_attribute_not_unique attributes \\<C> attr \\<D> \\<tau> \\<Longrightarrow>\n   unique_closest_attribute attributes \\<C> attr \\<D> \\<tau>\"\n\nsubsection \\<open>Association Ends\\<close>\n\ninductive role_refer_class where\n  \"role |\\<in>| fmdom ends \\<Longrightarrow>\n   fmlookup ends role = Some end \\<Longrightarrow>\n   assoc_end_class end = \\<C> \\<Longrightarrow>\n   role_refer_class ends \\<C> role\"\n\ninductive association_ends' where\n  \"\\<C> |\\<in>| classes \\<Longrightarrow>\n   assoc |\\<in>| fmdom associations \\<Longrightarrow>\n   fmlookup associations assoc = Some ends \\<Longrightarrow>\n   role_refer_class ends \\<C> from \\<Longrightarrow>\n   role |\\<in>| fmdom ends \\<Longrightarrow>\n   fmlookup ends role = Some end \\<Longrightarrow>\n   role \\<noteq> from \\<Longrightarrow>\n   association_ends' classes associations \\<C> from role end\"\n\ninductive association_ends_not_unique' where\n  \"association_ends' classes associations \\<C> from role end\\<^sub>1 \\<Longrightarrow>\n   association_ends' classes associations \\<C> from role end\\<^sub>2 \\<Longrightarrow>\n   end\\<^sub>1 \\<noteq> end\\<^sub>2 \\<Longrightarrow>\n   association_ends_not_unique' classes associations\"\n\ninductive owned_association_end' where\n  \"association_ends' classes associations \\<C> from role end \\<Longrightarrow>\n   owned_association_end' classes associations \\<C> None role end\"\n| \"association_ends' classes associations \\<C> from role end \\<Longrightarrow>\n   owned_association_end' classes associations \\<C> (Some from) role end\"\n\ninductive association_end_not_closest where\n  \"owned_association_end' classes associations \\<D>' from role end' \\<Longrightarrow>\n   \\<C> \\<le> \\<D>' \\<Longrightarrow>\n   \\<D>' < \\<D> \\<Longrightarrow>\n   association_end_not_closest classes associations \\<C> from role \\<D> end\"\n\ninductive closest_association_end where\n  \"owned_association_end' classes associations \\<D> from role end \\<Longrightarrow>\n   \\<C> \\<le> \\<D> \\<Longrightarrow>\n   \\<not> association_end_not_closest classes associations \\<C> from role \\<D> end \\<Longrightarrow>\n   closest_association_end classes associations \\<C> from role \\<D> end\"\n\ninductive closest_association_end_not_unique where\n  \"closest_association_end classes associations \\<C> from role \\<D>' end' \\<Longrightarrow>\n   \\<D> \\<noteq> \\<D>' \\<or> end \\<noteq> end' \\<Longrightarrow>\n   closest_association_end_not_unique classes associations \\<C> from role \\<D> end\"\n\ninductive unique_closest_association_end where\n  \"closest_association_end classes associations \\<C> from role \\<D> end \\<Longrightarrow>\n   \\<not> closest_association_end_not_unique classes associations \\<C> from role \\<D> end \\<Longrightarrow>\n   unique_closest_association_end classes associations \\<C> from role \\<D> end\"\n\nsubsection \\<open>Association Classes\\<close>\n\ninductive referred_by_association_class'' where\n  \"fmlookup association_classes \\<A> = Some assoc \\<Longrightarrow>\n   fmlookup associations assoc = Some ends \\<Longrightarrow>\n   role_refer_class ends \\<C> from \\<Longrightarrow>\n   referred_by_association_class'' association_classes associations \\<C> from \\<A>\"\n\ninductive referred_by_association_class' where\n  \"referred_by_association_class'' association_classes associations \\<C> from \\<A> \\<Longrightarrow>\n   referred_by_association_class' association_classes associations \\<C> None \\<A>\"\n| \"referred_by_association_class'' association_classes associations \\<C> from \\<A> \\<Longrightarrow>\n   referred_by_association_class' association_classes associations \\<C> (Some from) \\<A>\"\n\ninductive association_class_not_closest where\n  \"referred_by_association_class' association_classes associations \\<D>' from \\<A> \\<Longrightarrow>\n   \\<C> \\<le> \\<D>' \\<Longrightarrow>\n   \\<D>' < \\<D> \\<Longrightarrow>\n   association_class_not_closest association_classes associations \\<C> from \\<A> \\<D>\"\n\ninductive closest_association_class where\n  \"referred_by_association_class' association_classes associations \\<D> from \\<A> \\<Longrightarrow>\n   \\<C> \\<le> \\<D> \\<Longrightarrow>\n   \\<not> association_class_not_closest association_classes associations \\<C> from \\<A> \\<D> \\<Longrightarrow>\n   closest_association_class association_classes associations \\<C> from \\<A> \\<D>\"\n\ninductive closest_association_class_not_unique where\n  \"closest_association_class association_classes associations \\<C> from \\<A> \\<D>' \\<Longrightarrow>\n   \\<D> \\<noteq> \\<D>' \\<Longrightarrow>\n   closest_association_class_not_unique\n        association_classes associations \\<C> from \\<A> \\<D>\"\n\ninductive unique_closest_association_class where\n  \"closest_association_class association_classes associations \\<C> from \\<A> \\<D> \\<Longrightarrow>\n   \\<not> closest_association_class_not_unique\n        association_classes associations \\<C> from \\<A> \\<D> \\<Longrightarrow>\n   unique_closest_association_class association_classes associations \\<C> from \\<A> \\<D>\"\n\nsubsection \\<open>Association Class Ends\\<close>\n\ninductive association_class_end' where\n  \"fmlookup association_classes \\<A> = Some assoc \\<Longrightarrow>\n   fmlookup associations assoc = Some ends \\<Longrightarrow>\n   fmlookup ends role = Some end \\<Longrightarrow>\n   association_class_end' association_classes associations \\<A> role end\"\n\ninductive association_class_end_not_unique where\n  \"association_class_end' association_classes associations \\<A> role end' \\<Longrightarrow>\n   end \\<noteq> end' \\<Longrightarrow>\n   association_class_end_not_unique association_classes associations \\<A> role end\"\n\ninductive unique_association_class_end where\n  \"association_class_end' association_classes associations \\<A> role end \\<Longrightarrow>\n   \\<not> association_class_end_not_unique\n        association_classes associations \\<A> role end \\<Longrightarrow>\n   unique_association_class_end association_classes associations \\<A> role end\"\n\nsubsection \\<open>Operations\\<close>\n\ninductive any_operation' where\n  \"op |\\<in>| fset_of_list operations \\<Longrightarrow>\n   oper_name op = name \\<Longrightarrow>\n   \\<tau> \\<le> oper_context op \\<Longrightarrow>\n   list_all2 (\\<lambda>\\<sigma> param. \\<sigma> \\<le> param_type param) \\<pi> (oper_in_params op) \\<Longrightarrow>\n   any_operation' operations \\<tau> name \\<pi> op\"\n\ninductive operation' where\n  \"any_operation' operations \\<tau> name \\<pi> op \\<Longrightarrow>\n   \\<not> oper_static op \\<Longrightarrow>\n   operation' operations \\<tau> name \\<pi> op\"\n\ninductive operation_not_unique where\n  \"operation' operations \\<tau> name \\<pi> oper' \\<Longrightarrow>\n   oper \\<noteq> oper' \\<Longrightarrow>\n   operation_not_unique operations \\<tau> name \\<pi> oper\"\n\ninductive unique_operation where\n  \"operation' operations \\<tau> name \\<pi> oper \\<Longrightarrow>\n   \\<not> operation_not_unique operations \\<tau> name \\<pi> oper \\<Longrightarrow>\n   unique_operation operations \\<tau> name \\<pi> oper\"\n\ninductive operation_defined' where\n  \"unique_operation operations \\<tau> name \\<pi> oper \\<Longrightarrow>\n   operation_defined' operations \\<tau> name \\<pi>\"\n\ninductive static_operation' where\n  \"any_operation' operations \\<tau> name \\<pi> op \\<Longrightarrow>\n   oper_static op \\<Longrightarrow>\n   static_operation' operations \\<tau> name \\<pi> op\"\n\ninductive static_operation_not_unique where\n  \"static_operation' operations \\<tau> name \\<pi> oper' \\<Longrightarrow>\n   oper \\<noteq> oper' \\<Longrightarrow>\n   static_operation_not_unique operations \\<tau> name \\<pi> oper\"\n\ninductive unique_static_operation where\n  \"static_operation' operations \\<tau> name \\<pi> oper \\<Longrightarrow>\n   \\<not> static_operation_not_unique operations \\<tau> name \\<pi> oper \\<Longrightarrow>\n   unique_static_operation operations \\<tau> name \\<pi> oper\"\n\ninductive static_operation_defined' where\n  \"unique_static_operation operations \\<tau> name \\<pi> oper \\<Longrightarrow>\n   static_operation_defined' operations \\<tau> name \\<pi>\"\n\nsubsection \\<open>Literals\\<close>\n\ninductive has_literal' where\n  \"fmlookup literals e = Some lits \\<Longrightarrow>\n   lit |\\<in>| lits \\<Longrightarrow>\n   has_literal' literals e lit\"\n\n(*** Definition *************************************************************)\n\nsubsection \\<open>Definition\\<close>\n\nlocale object_model =\n  fixes classes :: \"'a :: semilattice_sup fset\"\n    and attributes :: \"'a \\<rightharpoonup>\\<^sub>f attr \\<rightharpoonup>\\<^sub>f 't :: order\"\n    and associations :: \"assoc \\<rightharpoonup>\\<^sub>f role \\<rightharpoonup>\\<^sub>f 'a assoc_end\"\n    and association_classes :: \"'a \\<rightharpoonup>\\<^sub>f assoc\"\n    and operations :: \"('t, 'e) oper_spec list\"\n    and literals :: \"'n \\<rightharpoonup>\\<^sub>f elit fset\"\n  assumes assoc_end_min_less_eq_max:\n    \"assoc |\\<in>| fmdom associations \\<Longrightarrow>\n     fmlookup associations assoc = Some ends \\<Longrightarrow>\n     role |\\<in>| fmdom ends  \\<Longrightarrow>\n     fmlookup ends role = Some end \\<Longrightarrow>\n     assoc_end_min end \\<le> assoc_end_max end\"\n  assumes association_ends_unique:\n    \"association_ends' classes associations \\<C> from role end\\<^sub>1 \\<Longrightarrow>\n     association_ends' classes associations \\<C> from role end\\<^sub>2 \\<Longrightarrow> end\\<^sub>1 = end\\<^sub>2\"\nbegin\n\nabbreviation \"owned_attribute \\<equiv>\n  owned_attribute' attributes\"\n\nabbreviation \"attribute \\<equiv>\n  unique_closest_attribute attributes\"\n\nabbreviation \"association_ends \\<equiv>\n  association_ends' classes associations\"\n\nabbreviation \"owned_association_end \\<equiv>\n  owned_association_end' classes associations\"\n\nabbreviation \"association_end \\<equiv>\n  unique_closest_association_end classes associations\"\n\nabbreviation \"referred_by_association_class \\<equiv>\n  unique_closest_association_class association_classes associations\"\n\nabbreviation \"association_class_end \\<equiv>\n  unique_association_class_end association_classes associations\"\n\nabbreviation \"operation \\<equiv>\n  unique_operation operations\"\n\nabbreviation \"operation_defined \\<equiv>\n  operation_defined' operations\"\n\nabbreviation \"static_operation \\<equiv>\n  unique_static_operation operations\"\n\nabbreviation \"static_operation_defined \\<equiv>\n  static_operation_defined' operations\"\n\nabbreviation \"has_literal \\<equiv>\n  has_literal' literals\"\n\nend\n\ndeclare operation_defined'.simps [simp]\ndeclare static_operation_defined'.simps [simp]\n\ndeclare has_literal'.simps [simp]\n\n(*** Properties *************************************************************)\n\nsubsection \\<open>Properties\\<close>\n\nlemma (in object_model) attribute_det:\n  \"attribute \\<C> attr \\<D>\\<^sub>1 \\<tau>\\<^sub>1 \\<Longrightarrow>\n   attribute \\<C> attr \\<D>\\<^sub>2 \\<tau>\\<^sub>2 \\<Longrightarrow> \\<D>\\<^sub>1 = \\<D>\\<^sub>2 \\<and> \\<tau>\\<^sub>1 = \\<tau>\\<^sub>2\"\n  by (meson closest_attribute_not_unique.intros unique_closest_attribute.cases)\n\nlemma (in object_model) attribute_self_or_inherited:\n  \"attribute \\<C> attr \\<D> \\<tau> \\<Longrightarrow> \\<C> \\<le> \\<D>\"\n  by (meson closest_attribute.cases unique_closest_attribute.cases)\n\nlemma (in object_model) attribute_closest:\n  \"attribute \\<C> attr \\<D> \\<tau> \\<Longrightarrow>\n   owned_attribute \\<D>' attr \\<tau> \\<Longrightarrow>\n   \\<C> \\<le> \\<D>' \\<Longrightarrow> \\<not> \\<D>' < \\<D>\"\n  by (meson attribute_not_closest.intros closest_attribute.cases\n      unique_closest_attribute.cases)\n\n\nlemma (in object_model) association_end_det:\n  \"association_end \\<C> from role \\<D>\\<^sub>1 end\\<^sub>1 \\<Longrightarrow>\n   association_end \\<C> from role \\<D>\\<^sub>2 end\\<^sub>2 \\<Longrightarrow> \\<D>\\<^sub>1 = \\<D>\\<^sub>2 \\<and> end\\<^sub>1 = end\\<^sub>2\"\n  by (meson closest_association_end_not_unique.intros\n      unique_closest_association_end.cases)\n\nlemma (in object_model) association_end_self_or_inherited:\n  \"association_end \\<C> from role \\<D> end \\<Longrightarrow> \\<C> \\<le> \\<D>\"\n  by (meson closest_association_end.cases unique_closest_association_end.cases)\n\nlemma (in object_model) association_end_closest:\n  \"association_end \\<C> from role \\<D> end \\<Longrightarrow>\n   owned_association_end \\<D>' from role end \\<Longrightarrow>\n   \\<C> \\<le> \\<D>' \\<Longrightarrow> \\<not> \\<D>' < \\<D>\"\n  by (meson association_end_not_closest.intros closest_association_end.cases\n      unique_closest_association_end.cases)\n\n\nlemma (in object_model) association_class_end_det:\n  \"association_class_end \\<A> role end\\<^sub>1 \\<Longrightarrow>\n   association_class_end \\<A> role end\\<^sub>2 \\<Longrightarrow> end\\<^sub>1 = end\\<^sub>2\"\n  by (meson association_class_end_not_unique.intros unique_association_class_end.cases)\n\n\nlemma (in object_model) operation_det:\n  \"operation \\<tau> name \\<pi> oper\\<^sub>1 \\<Longrightarrow>\n   operation \\<tau> name \\<pi> oper\\<^sub>2 \\<Longrightarrow> oper\\<^sub>1 = oper\\<^sub>2\"\n  by (meson operation_not_unique.intros unique_operation.cases)\n\nlemma (in object_model) static_operation_det:\n  \"static_operation \\<tau> name \\<pi> oper\\<^sub>1 \\<Longrightarrow>\n   static_operation \\<tau> name \\<pi> oper\\<^sub>2 \\<Longrightarrow> oper\\<^sub>1 = oper\\<^sub>2\"\n  by (meson static_operation_not_unique.intros unique_static_operation.cases)\n\n(*** Code Setup *************************************************************)\n\nsubsection \\<open>Code Setup\\<close>\n\nlemma fmember_code_predI [code_pred_intro]:\n  \"x |\\<in>| xs\" if \"Predicate_Compile.contains (fset xs) x\"\n  using that by (simp add: Predicate_Compile.contains_def fmember.rep_eq)\n\ncode_pred fmember\n  by (simp add: Predicate_Compile.contains_def fmember.rep_eq)\n\ncode_pred unique_closest_attribute .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool) association_ends' .\n\ncode_pred association_ends_not_unique' .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool) owned_association_end' .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool) closest_association_end .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool ) closest_association_end_not_unique .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> o \\<Rightarrow> bool) unique_closest_association_end .\n\ncode_pred unique_closest_association_class .\n\ncode_pred association_class_end' .\n\ncode_pred association_class_end_not_unique .\n\ncode_pred unique_association_class_end .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool) any_operation' .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool) operation' .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool) operation_not_unique .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool) unique_operation .\n\ncode_pred operation_defined' .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool) static_operation' .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool) static_operation_not_unique .\n\ncode_pred (modes:\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool,\n    i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool) unique_static_operation .\n\ncode_pred static_operation_defined' .\n\ncode_pred has_literal' .\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Evaluation/Safe_OCL/Object_Model.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6113819874558603, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.26767740104331983}}
{"text": "(*  Title:      HOL/Auth/n_mesi_lemma_invs_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mesi Protocol Case Study*} \n\ntheory n_mesi_lemma_invs_on_rules imports n_mesi_lemma_inv__1_on_rules n_mesi_lemma_inv__2_on_rules n_mesi_lemma_inv__3_on_rules\nbegin\nlemma invs_on_rules:\n  assumes a1: \"f \\<in> invariants N\" and a2: \"r \\<in> rules N\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have b1: \"(\\<exists> p__Inv0 p__Inv2. p__Inv0\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv0~=p__Inv2\\<and>f=inv__1  p__Inv0 p__Inv2)\\<or>\n    (\\<exists> p__Inv0 p__Inv2. p__Inv0\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv0~=p__Inv2\\<and>f=inv__2  p__Inv0 p__Inv2)\\<or>\n    (\\<exists> p__Inv0 p__Inv2. p__Inv0\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv0~=p__Inv2\\<and>f=inv__3  p__Inv0 p__Inv2)\"\n  apply (cut_tac a1, auto) done\n    moreover {\n      assume c1: \"(\\<exists> p__Inv0 p__Inv2. p__Inv0\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv0~=p__Inv2\\<and>f=inv__1  p__Inv0 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__1_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv0 p__Inv2. p__Inv0\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv0~=p__Inv2\\<and>f=inv__2  p__Inv0 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__2_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv0 p__Inv2. p__Inv0\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv0~=p__Inv2\\<and>f=inv__3  p__Inv0 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__3_on_rules) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "paraVerifier", "repo": "paraVerifier", "sha": "5de62b433a160bf8d714e0a5085a38b9dd8899f0", "save_path": "github-repos/isabelle/paraVerifier-paraVerifier", "path": "github-repos/isabelle/paraVerifier-paraVerifier/paraVerifier-5de62b433a160bf8d714e0a5085a38b9dd8899f0/proof_scripts/mesi/n_mesi_lemma_invs_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6113819732941511, "lm_q2_score": 0.43782349911420193, "lm_q1q2_score": 0.2676773948429908}}
{"text": "(*  Title:      ZF/UNITY/Mutex.thy\n    Author:     Sidi O Ehmety, Computer Laboratory\n    Copyright   2001  University of Cambridge\n\nBased on \"A Family of 2-Process Mutual Exclusion Algorithms\" by J Misra.\n\nVariables' types are introduced globally so that type verification\nreduces to the usual ZF typechecking \\<in> an ill-tyed expression will\nreduce to the empty set.\n*)\n\nsection\\<open>Mutual Exclusion\\<close>\n\ntheory Mutex\nimports SubstAx\nbegin\n\ntext\\<open>Based on \"A Family of 2-Process Mutual Exclusion Algorithms\" by J Misra\n\nVariables' types are introduced globally so that type verification reduces to\nthe usual ZF typechecking: an ill-tyed expressions reduce to the empty set.\n\\<close>\n\nabbreviation \"p \\<equiv> Var([0])\"\nabbreviation \"m \\<equiv> Var([1])\"\nabbreviation \"n \\<equiv> Var([0,0])\"\nabbreviation \"u \\<equiv> Var([0,1])\"\nabbreviation \"v \\<equiv> Var([1,0])\"\n\naxiomatization where \\<comment> \\<open>Type declarations\\<close>\n  p_type:  \"type_of(p)=bool \\<and> default_val(p)=0\" and\n  m_type:  \"type_of(m)=int  \\<and> default_val(m)=#0\" and\n  n_type:  \"type_of(n)=int  \\<and> default_val(n)=#0\" and\n  u_type:  \"type_of(u)=bool \\<and> default_val(u)=0\" and\n  v_type:  \"type_of(v)=bool \\<and> default_val(v)=0\"\n\ndefinition\n  (** The program for process U **)\n  \"U0 \\<equiv> {\\<langle>s,t\\<rangle>:state*state. t = s(u:=1, m:=#1) \\<and> s`m = #0}\"\n\ndefinition\n  \"U1 \\<equiv> {\\<langle>s,t\\<rangle>:state*state. t = s(p:= s`v, m:=#2) \\<and>  s`m = #1}\"\n\ndefinition\n  \"U2 \\<equiv> {\\<langle>s,t\\<rangle>:state*state. t = s(m:=#3) \\<and> s`p=0 \\<and> s`m = #2}\"\n\ndefinition\n  \"U3 \\<equiv> {\\<langle>s,t\\<rangle>:state*state. t=s(u:=0, m:=#4) \\<and> s`m = #3}\"\n\ndefinition\n  \"U4 \\<equiv> {\\<langle>s,t\\<rangle>:state*state. t = s(p:=1, m:=#0) \\<and> s`m = #4}\"\n\n\n   (** The program for process V **)\n\ndefinition\n  \"V0 \\<equiv> {\\<langle>s,t\\<rangle>:state*state. t = s (v:=1, n:=#1) \\<and> s`n = #0}\"\n\ndefinition\n  \"V1 \\<equiv> {\\<langle>s,t\\<rangle>:state*state. t = s(p:=not(s`u), n:=#2) \\<and> s`n = #1}\"\n\ndefinition\n  \"V2 \\<equiv> {\\<langle>s,t\\<rangle>:state*state. t  = s(n:=#3) \\<and> s`p=1 \\<and> s`n = #2}\"\n\ndefinition\n  \"V3 \\<equiv> {\\<langle>s,t\\<rangle>:state*state. t = s (v:=0, n:=#4) \\<and> s`n = #3}\"\n\ndefinition\n  \"V4 \\<equiv> {\\<langle>s,t\\<rangle>:state*state. t  = s (p:=0, n:=#0) \\<and> s`n = #4}\"\n\ndefinition\n  \"Mutex \\<equiv> mk_program({s:state. s`u=0 \\<and> s`v=0 \\<and> s`m = #0 \\<and> s`n = #0},\n              {U0, U1, U2, U3, U4, V0, V1, V2, V3, V4}, Pow(state*state))\"\n\n  (** The correct invariants **)\n\ndefinition\n  \"IU \\<equiv> {s:state. (s`u = 1\\<longleftrightarrow>(#1 $\\<le> s`m \\<and> s`m $\\<le> #3))\n                     \\<and> (s`m = #3 \\<longrightarrow> s`p=0)}\"\n\ndefinition\n  \"IV \\<equiv> {s:state. (s`v = 1 \\<longleftrightarrow> (#1 $\\<le> s`n \\<and> s`n $\\<le> #3))\n                      \\<and> (s`n = #3 \\<longrightarrow> s`p=1)}\"\n\n  (** The faulty invariant (for U alone) **)\n\ndefinition\n  \"bad_IU \\<equiv> {s:state. (s`u = 1 \\<longleftrightarrow> (#1 $\\<le> s`m \\<and> s`m  $\\<le> #3))\\<and>\n                   (#3 $\\<le> s`m \\<and> s`m $\\<le> #4 \\<longrightarrow> s`p=0)}\"\n\n\n(** Variables' types **)\n\ndeclare p_type [simp] u_type [simp] v_type [simp] m_type [simp] n_type [simp]\n\nlemma u_value_type: \"s \\<in> state \\<Longrightarrow>s`u \\<in> bool\"\n  unfolding state_def\napply (drule_tac a = u in apply_type, auto)\ndone\n\nlemma v_value_type: \"s \\<in> state \\<Longrightarrow> s`v \\<in> bool\"\n  unfolding state_def\napply (drule_tac a = v in apply_type, auto)\ndone\n\nlemma p_value_type: \"s \\<in> state \\<Longrightarrow> s`p \\<in> bool\"\n  unfolding state_def\napply (drule_tac a = p in apply_type, auto)\ndone\n\nlemma m_value_type: \"s \\<in> state \\<Longrightarrow> s`m \\<in> int\"\n  unfolding state_def\napply (drule_tac a = m in apply_type, auto)\ndone\n\nlemma n_value_type: \"s \\<in> state \\<Longrightarrow>s`n \\<in> int\"\n  unfolding state_def\napply (drule_tac a = n in apply_type, auto)\ndone\n\ndeclare p_value_type [simp] u_value_type [simp] v_value_type [simp]\n        m_value_type [simp] n_value_type [simp]\n\ndeclare p_value_type [TC] u_value_type [TC] v_value_type [TC]\n        m_value_type [TC] n_value_type [TC]\n\n\n\ntext\\<open>Mutex is a program\\<close>\n\nlemma Mutex_in_program [simp,TC]: \"Mutex \\<in> program\"\nby (simp add: Mutex_def)\n\n\ndeclare Mutex_def [THEN def_prg_Init, simp]\ndeclare Mutex_def [program]\n\ndeclare  U0_def [THEN def_act_simp, simp]\ndeclare  U1_def [THEN def_act_simp, simp]\ndeclare  U2_def [THEN def_act_simp, simp]\ndeclare  U3_def [THEN def_act_simp, simp]\ndeclare  U4_def [THEN def_act_simp, simp]\n\ndeclare  V0_def [THEN def_act_simp, simp]\ndeclare  V1_def [THEN def_act_simp, simp]\ndeclare  V2_def [THEN def_act_simp, simp]\ndeclare  V3_def [THEN def_act_simp, simp]\ndeclare  V4_def [THEN def_act_simp, simp]\n\ndeclare  U0_def [THEN def_set_simp, simp]\ndeclare  U1_def [THEN def_set_simp, simp]\ndeclare  U2_def [THEN def_set_simp, simp]\ndeclare  U3_def [THEN def_set_simp, simp]\ndeclare  U4_def [THEN def_set_simp, simp]\n\ndeclare  V0_def [THEN def_set_simp, simp]\ndeclare  V1_def [THEN def_set_simp, simp]\ndeclare  V2_def [THEN def_set_simp, simp]\ndeclare  V3_def [THEN def_set_simp, simp]\ndeclare  V4_def [THEN def_set_simp, simp]\n\ndeclare  IU_def [THEN def_set_simp, simp]\ndeclare  IV_def [THEN def_set_simp, simp]\ndeclare  bad_IU_def [THEN def_set_simp, simp]\n\nlemma IU: \"Mutex \\<in> Always(IU)\"\napply (rule AlwaysI, force)\napply (unfold Mutex_def, safety, auto)\ndone\n\nlemma IV: \"Mutex \\<in> Always(IV)\"\napply (rule AlwaysI, force)\napply (unfold Mutex_def, safety)\ndone\n\n(*The safety property: mutual exclusion*)\nlemma mutual_exclusion: \"Mutex \\<in> Always({s \\<in> state. \\<not>(s`m = #3 \\<and> s`n = #3)})\"\napply (rule Always_weaken)\napply (rule Always_Int_I [OF IU IV], auto)\ndone\n\n(*The bad invariant FAILS in V1*)\n\nlemma less_lemma: \"\\<lbrakk>x$<#1; #3 $\\<le> x\\<rbrakk> \\<Longrightarrow> P\"\napply (drule_tac j = \"#1\" and k = \"#3\" in zless_zle_trans)\napply (drule_tac [2] j = x in zle_zless_trans, auto)\ndone\n\nlemma \"Mutex \\<in> Always(bad_IU)\"\napply (rule AlwaysI, force)\napply (unfold Mutex_def, safety, auto)\napply (subgoal_tac \"#1 $\\<le> #3\")\napply (drule_tac x = \"#1\" and y = \"#3\" in zle_trans, auto)\napply (simp (no_asm) add: not_zless_iff_zle [THEN iff_sym])\napply auto\n(*Resulting state: n=1, p=false, m=4, u=false.\n  Execution of V1 (the command of process v guarded by n=1) sets p:=true,\n  violating the invariant!*)\noops\n\n\n\n(*** Progress for U ***)\n\nlemma U_F0: \"Mutex \\<in> {s \\<in> state. s`m=#2} Unless {s \\<in> state. s`m=#3}\"\nby (unfold op_Unless_def Mutex_def, safety)\n\nlemma U_F1:\n     \"Mutex \\<in> {s \\<in> state. s`m=#1} \\<longmapsto>w {s \\<in> state. s`p = s`v \\<and> s`m = #2}\"\nby (unfold Mutex_def, ensures U1)\n\nlemma U_F2: \"Mutex \\<in> {s \\<in> state. s`p =0 \\<and> s`m = #2} \\<longmapsto>w {s \\<in> state. s`m = #3}\"\napply (cut_tac IU)\napply (unfold Mutex_def, ensures U2)\ndone\n\nlemma U_F3: \"Mutex \\<in> {s \\<in> state. s`m = #3} \\<longmapsto>w {s \\<in> state. s`p=1}\"\napply (rule_tac B = \"{s \\<in> state. s`m = #4}\" in LeadsTo_Trans)\n   unfolding Mutex_def\n apply (ensures U3)\napply (ensures U4)\ndone\n\n\nlemma U_lemma2: \"Mutex \\<in> {s \\<in> state. s`m = #2} \\<longmapsto>w {s \\<in> state. s`p=1}\"\napply (rule LeadsTo_Diff [OF LeadsTo_weaken_L\n                             Int_lower2 [THEN subset_imp_LeadsTo]])\napply (rule LeadsTo_Trans [OF U_F2 U_F3], auto)\napply (auto dest!: p_value_type simp add: bool_def)\ndone\n\nlemma U_lemma1: \"Mutex \\<in> {s \\<in> state. s`m = #1} \\<longmapsto>w {s \\<in> state. s`p =1}\"\nby (rule LeadsTo_Trans [OF U_F1 [THEN LeadsTo_weaken_R] U_lemma2], blast)\n\nlemma eq_123: \"i \\<in> int \\<Longrightarrow> (#1 $\\<le> i \\<and> i $\\<le> #3) \\<longleftrightarrow> (i=#1 | i=#2 | i=#3)\"\napply auto\napply (auto simp add: neq_iff_zless)\napply (drule_tac [4] j = \"#3\" and i = i in zle_zless_trans)\napply (drule_tac [2] j = i and i = \"#1\" in zle_zless_trans)\napply (drule_tac j = i and i = \"#1\" in zle_zless_trans, auto)\napply (rule zle_anti_sym)\napply (simp_all (no_asm_simp) add: zless_add1_iff_zle [THEN iff_sym])\ndone\n\n\nlemma U_lemma123: \"Mutex \\<in> {s \\<in> state. #1 $\\<le> s`m \\<and> s`m $\\<le> #3} \\<longmapsto>w {s \\<in> state. s`p=1}\"\nby (simp add: eq_123 Collect_disj_eq LeadsTo_Un_distrib U_lemma1 U_lemma2 U_F3)\n\n\n(*Misra's F4*)\nlemma u_Leadsto_p: \"Mutex \\<in> {s \\<in> state. s`u = 1} \\<longmapsto>w {s \\<in> state. s`p=1}\"\nby (rule Always_LeadsTo_weaken [OF IU U_lemma123], auto)\n\n\n(*** Progress for V ***)\n\nlemma V_F0: \"Mutex \\<in> {s \\<in> state. s`n=#2} Unless {s \\<in> state. s`n=#3}\"\nby (unfold op_Unless_def Mutex_def, safety)\n\nlemma V_F1: \"Mutex \\<in> {s \\<in> state. s`n=#1} \\<longmapsto>w {s \\<in> state. s`p = not(s`u) \\<and> s`n = #2}\"\nby (unfold Mutex_def, ensures \"V1\")\n\nlemma V_F2: \"Mutex \\<in> {s \\<in> state. s`p=1 \\<and> s`n = #2} \\<longmapsto>w {s \\<in> state. s`n = #3}\"\napply (cut_tac IV)\napply (unfold Mutex_def, ensures \"V2\")\ndone\n\nlemma V_F3: \"Mutex \\<in> {s \\<in> state. s`n = #3} \\<longmapsto>w {s \\<in> state. s`p=0}\"\napply (rule_tac B = \"{s \\<in> state. s`n = #4}\" in LeadsTo_Trans)\n   unfolding Mutex_def\n apply (ensures V3)\napply (ensures V4)\ndone\n\nlemma V_lemma2: \"Mutex \\<in> {s \\<in> state. s`n = #2} \\<longmapsto>w {s \\<in> state. s`p=0}\"\napply (rule LeadsTo_Diff [OF LeadsTo_weaken_L\n                             Int_lower2 [THEN subset_imp_LeadsTo]])\napply (rule LeadsTo_Trans [OF V_F2 V_F3], auto)\napply (auto dest!: p_value_type simp add: bool_def)\ndone\n\nlemma V_lemma1: \"Mutex \\<in> {s \\<in> state. s`n = #1} \\<longmapsto>w {s \\<in> state. s`p = 0}\"\nby (rule LeadsTo_Trans [OF V_F1 [THEN LeadsTo_weaken_R] V_lemma2], blast)\n\nlemma V_lemma123: \"Mutex \\<in> {s \\<in> state. #1 $\\<le> s`n \\<and> s`n $\\<le> #3} \\<longmapsto>w {s \\<in> state. s`p = 0}\"\nby (simp add: eq_123 Collect_disj_eq LeadsTo_Un_distrib V_lemma1 V_lemma2 V_F3)\n\n(*Misra's F4*)\nlemma v_Leadsto_not_p: \"Mutex \\<in> {s \\<in> state. s`v = 1} \\<longmapsto>w {s \\<in> state. s`p = 0}\"\nby (rule Always_LeadsTo_weaken [OF IV V_lemma123], auto)\n\n\n(** Absence of starvation **)\n\n(*Misra's F6*)\nlemma m1_Leadsto_3: \"Mutex \\<in> {s \\<in> state. s`m = #1} \\<longmapsto>w {s \\<in> state. s`m = #3}\"\napply (rule LeadsTo_cancel2 [THEN LeadsTo_Un_duplicate])\napply (rule_tac [2] U_F2)\napply (simp add: Collect_conj_eq)\napply (subst Un_commute)\napply (rule LeadsTo_cancel2 [THEN LeadsTo_Un_duplicate])\n apply (rule_tac [2] PSP_Unless [OF v_Leadsto_not_p U_F0])\napply (rule U_F1 [THEN LeadsTo_weaken_R], auto)\napply (auto dest!: v_value_type simp add: bool_def)\ndone\n\n\n(*The same for V*)\nlemma n1_Leadsto_3: \"Mutex \\<in> {s \\<in> state. s`n = #1} \\<longmapsto>w {s \\<in> state. s`n = #3}\"\napply (rule LeadsTo_cancel2 [THEN LeadsTo_Un_duplicate])\napply (rule_tac [2] V_F2)\napply (simp add: Collect_conj_eq)\napply (subst Un_commute)\napply (rule LeadsTo_cancel2 [THEN LeadsTo_Un_duplicate])\n apply (rule_tac [2] PSP_Unless [OF u_Leadsto_p V_F0])\napply (rule V_F1 [THEN LeadsTo_weaken_R], auto)\napply (auto dest!: u_value_type simp add: bool_def)\ndone\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/ZF/UNITY/Mutex.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5350984434543457, "lm_q2_score": 0.5, "lm_q1q2_score": 0.2675492217271728}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      ProcParEx.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2007-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection \"Examples for Procedures as Parameters using Statespaces\"\ntheory ProcParExSP imports \"../Vcg\" begin\n\n\n\n\n\n\n\nlemma conseq_exploit_pre':\n             \"\\<lbrakk>\\<forall>s \\<in> S. \\<Gamma>,\\<Theta> \\<turnstile> ({s} \\<inter> P) c Q,A\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile> (P \\<inter> S)c Q,A\"\n  apply (rule HoarePartialDef.Conseq)\n  apply clarify\n  by (metis IntI insertI1 subset_refl)\n\nlemma conseq_exploit_pre'':\n             \"\\<lbrakk>\\<forall>Z. \\<forall>s \\<in> S Z.  \\<Gamma>,\\<Theta> \\<turnstile> ({s} \\<inter> P Z) c (Q Z),(A Z)\\<rbrakk>\n              \\<Longrightarrow>\n              \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile> (P Z \\<inter> S Z)c (Q Z),(A Z)\"\n  apply (rule allI)\n  apply (rule conseq_exploit_pre')\n  apply blast\n  done\n\nlemma conseq_exploit_pre''':\n             \"\\<lbrakk>\\<forall>s \\<in> S. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile> ({s} \\<inter> P Z) c (Q Z),(A Z)\\<rbrakk>\n              \\<Longrightarrow>\n              \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile> (P Z \\<inter> S)c (Q Z),(A Z)\"\n  apply (rule allI)\n  apply (rule conseq_exploit_pre')\n  apply blast\n  done\n\n\nprocedures compare(i::nat,j::nat|r::bool) \"NoBody\"\n  \n\nprint_locale! compare_signature\n\n\ncontext compare_impl\nbegin\ndeclare [[hoare_use_call_tr' = false]]\nterm \"\\<acute>r :== CALL compare(\\<acute>i,\\<acute>j)\"\ndeclare [[hoare_use_call_tr' = true]]\nend\n\n\n(* FIXME: typing issue with modifies locale*)\nprocedures\n  LEQ (i::nat,j::nat | r::bool) \"\\<acute>r :== \\<acute>i \\<le> \\<acute>j\"\n  LEQ_spec: \"\\<forall>\\<sigma>. \\<Gamma>\\<turnstile> {\\<sigma>}  PROC LEQ(\\<acute>i,\\<acute>j,\\<acute>r) \\<lbrace>\\<acute>r = (\\<^bsup>\\<sigma>\\<^esup>i \\<le> \\<^bsup>\\<sigma>\\<^esup>j)\\<rbrace>\"\n\n  LEQ_modifies: \"\\<forall>\\<sigma>. \\<Gamma>\\<turnstile> {\\<sigma>} PROC LEQ(\\<acute>i,\\<acute>j,\\<acute>r) {t. t may_only_modify_globals \\<sigma> in []}\"\n\n\n\ndefinition mx:: \"('a \\<Rightarrow> 'a \\<Rightarrow> bool) \\<Rightarrow> 'a \\<Rightarrow> 'a \\<Rightarrow> 'a\"\n  where \"mx leq a b = (if leq a b then a else b)\"\n\nprocedures (imports compare_signature)\n  Max (compare::string, n::nat, m::nat | k::nat)  \n  where b::bool\n  in\n  \"\\<acute>b :== DYNCALL \\<acute>compare(\\<acute>n,\\<acute>m);;\n   IF \\<acute>b THEN \\<acute>k :== \\<acute>n ELSE \\<acute>k :== \\<acute>m FI\"\n\n  Max_spec: \"\\<And>leq. \\<forall>\\<sigma>. \\<Gamma>\\<turnstile> \n  ({\\<sigma>} \\<inter> {s. (\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<^bsup>s\\<^esup>compare(\\<acute>i,\\<acute>j) \\<lbrace>\\<acute>r = (leq \\<^bsup>\\<tau>\\<^esup>i \\<^bsup>\\<tau>\\<^esup>j)\\<rbrace>) \\<and> \n              (\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<^bsup>s\\<^esup>compare(\\<acute>i,\\<acute>j) {t. t may_only_modify_globals \\<tau> in []})})\n    PROC Max(\\<acute>compare,\\<acute>n,\\<acute>m,\\<acute>k)\n  \\<lbrace>\\<acute>k = mx leq \\<^bsup>\\<sigma>\\<^esup>n \\<^bsup>\\<sigma>\\<^esup>m\\<rbrace>\"\n\ncontext Max_spec\nbegin\nthm Max_spec\nend\ncontext Max_impl\nbegin\nterm \"\\<acute>b :== DYNCALL \\<acute>compare(\\<acute>n,\\<acute>m)\"\ndeclare [[hoare_use_call_tr' = false]]\nterm \"\\<acute>b :== DYNCALL \\<acute>compare(\\<acute>n,\\<acute>m)\"\ndeclare [[hoare_use_call_tr' = true]]\nend\n\n\n\nlemma (in Max_impl ) Max_spec1: \nshows\n\"\\<forall>\\<sigma> leq. \\<Gamma>\\<turnstile> \n  ({\\<sigma>} \\<inter> \\<lbrace> (\\<forall>\\<tau>. \\<Gamma>\\<turnstile>{\\<tau>} \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) \\<lbrace>\\<acute>r = (leq \\<^bsup>\\<tau>\\<^esup>i \\<^bsup>\\<tau>\\<^esup>j)\\<rbrace>) \\<and> \n      (\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) {t. t may_only_modify_globals \\<tau> in []})\\<rbrace>)\n    \\<acute>k :== PROC Max(\\<acute>compare,\\<acute>n,\\<acute>m)\n  \\<lbrace>\\<acute>k = mx leq \\<^bsup>\\<sigma>\\<^esup>n \\<^bsup>\\<sigma>\\<^esup>m\\<rbrace>\"\napply (hoare_rule HoarePartial.ProcNoRec1)\napply (intro allI)\napply (rule conseq_exploit_pre')\napply (rule)\napply clarify\nproof -\n  fix \\<sigma>:: \"('a, 'b, 'c, 'd) stateSP_scheme\" and s::\"('a, 'b, 'c, 'd) stateSP_scheme\" and leq\n   assume compare_spec: \n       \"\\<forall>\\<tau>. \\<Gamma>\\<turnstile>{\\<tau>} \\<acute>r :== PROC \\<^bsup>s\\<^esup>compare(\\<acute>i,\\<acute>j) \\<lbrace>\\<acute>r = leq \\<^bsup>\\<tau>\\<^esup>i \\<^bsup>\\<tau>\\<^esup>j\\<rbrace>\"\n \n  assume compare_modifies:\n        \"\\<forall>\\<tau>. \\<Gamma>\\<turnstile>{\\<tau>} \\<acute>r :== PROC \\<^bsup>s\\<^esup>compare(\\<acute>i,\\<acute>j) \n                {t. t may_only_modify_globals \\<tau> in []}\"\n\n   show \"\\<Gamma>\\<turnstile>({s} \\<inter> {\\<sigma>})\n            \\<acute>b :== DYNCALL \\<acute>compare (\\<acute>n,\\<acute>m);;\n            IF \\<acute>b THEN \\<acute>k :== \\<acute>n ELSE \\<acute>k :== \\<acute>m FI\n            \\<lbrace>\\<acute>k = mx leq \\<^bsup>\\<sigma>\\<^esup>n \\<^bsup>\\<sigma>\\<^esup>m\\<rbrace>\"\n     apply vcg\n     apply (clarsimp simp add: mx_def)\n     done\n qed\n\n\nlemma (in Max_impl) Max_spec2: \nshows\n\"\\<forall>\\<sigma> leq. \\<Gamma>\\<turnstile> \n  ({\\<sigma>} \\<inter> \\<lbrace>(\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) \\<lbrace>\\<acute>r = (leq \\<^bsup>\\<tau>\\<^esup>i \\<^bsup>\\<tau>\\<^esup>j)\\<rbrace>) \\<and> \n      (\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) {t. t may_only_modify_globals \\<tau> in []})\\<rbrace>)\n    \\<acute>k :== PROC Max(\\<acute>compare,\\<acute>n,\\<acute>m)\n  \\<lbrace>\\<acute>k = mx leq \\<^bsup>\\<sigma>\\<^esup>n \\<^bsup>\\<sigma>\\<^esup>m\\<rbrace>\"\napply (hoare_rule HoarePartial.ProcNoRec1)\napply (intro allI)\napply (rule conseq_exploit_pre')\napply (rule)\napply clarify\napply vcg\napply (clarsimp simp add: mx_def)\ndone\n\nlemma (in Max_impl) Max_spec3: \nshows\n\"\\<forall>n m leq. \\<Gamma>\\<turnstile> \n  (\\<lbrace>\\<acute>n=n \\<and> \\<acute>m=m\\<rbrace>  \\<inter> \n   \\<lbrace>(\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) \\<lbrace>\\<acute>r = (leq \\<^bsup>\\<tau>\\<^esup>i \\<^bsup>\\<tau>\\<^esup>j)\\<rbrace>) \\<and> \n     (\\<forall>\\<tau>. \\<Gamma>\\<turnstile> {\\<tau>} \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) {t. t may_only_modify_globals \\<tau> in []})\\<rbrace>)\n    \\<acute>k :== PROC Max(\\<acute>compare,\\<acute>n,\\<acute>m)\n  \\<lbrace>\\<acute>k = mx leq n m\\<rbrace>\"\napply (hoare_rule HoarePartial.ProcNoRec1)\napply (intro allI)\napply (rule conseq_exploit_pre')\napply (rule)\napply clarify\napply vcg\napply (clarsimp simp add: mx_def)\ndone\n\n\n\nprint_locale Max_spec\n\n(* We have to rename the parameters of the compare procedure to match the LEQ procedure *)\nlocale Max_test = Max_spec where\n        i_'compare_' = i_'LEQ_' and\n        j_'compare_' = j_'LEQ_' and\n        r_'compare_' = r_'LEQ_'\n       + LEQ_spec + LEQ_modifies\n\nlemma (in Max_test) \n  shows\n  \"\\<Gamma>\\<turnstile> {\\<sigma>} \\<acute>k :== CALL Max(LEQ_'proc,\\<acute>n,\\<acute>m) \\<lbrace>\\<acute>k = mx (op \\<le>) \\<^bsup>\\<sigma>\\<^esup>n \\<^bsup>\\<sigma>\\<^esup>m\\<rbrace>\"\nproof -\n  note Max_spec = Max_spec [where leq=\"(op \\<le>)\"]\n  show ?thesis\n    apply vcg\n    apply (clarsimp)\n    apply (rule conjI)\n    apply (rule LEQ_spec)\n    apply (rule LEQ_modifies)\n    done\nqed\n\n\n\n\n\n\nlemma (in Max_impl) Max_spec5:\nshows\n\"\\<forall>n m leq. \\<Gamma>\\<turnstile> \n  (\\<lbrace>\\<acute>n=n \\<and> \\<acute>m=m\\<rbrace> \\<inter> \\<lbrace>\\<forall>n' m'. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>i=n' \\<and> \\<acute>j=m'\\<rbrace> \\<acute>r :== PROC \\<acute>compare(\\<acute>i,\\<acute>j) \\<lbrace>\\<acute>r = (leq n' m')\\<rbrace>\\<rbrace>)\n    \\<acute>k :== PROC Max(\\<acute>compare,\\<acute>n,\\<acute>m)\n  \\<lbrace>\\<acute>k = mx leq n m\\<rbrace>\"\napply (hoare_rule HoarePartial.ProcNoRec1)\napply (intro allI)\napply (rule conseq_exploit_pre')\napply (rule)\napply clarify\napply vcg\napply clarsimp\napply (clarsimp simp add: mx_def)\ndone\n\nlemma (in LEQ_impl)\n LEQ_spec: \"\\<forall>n m. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>i=n \\<and> \\<acute>j=m\\<rbrace>  PROC LEQ(\\<acute>i,\\<acute>j,\\<acute>r) \\<lbrace>\\<acute>r = (n \\<le> m)\\<rbrace>\"\n  apply vcg\n  apply simp\n  done\n\n\nprint_locale Max_impl\nlocale Max_test' = Max_impl where\n        i_'compare_' = i_'LEQ_' and\n        j_'compare_' = j_'LEQ_' and\n        r_'compare_' = r_'LEQ_'\n        + LEQ_impl\nlemma (in Max_test') \n  shows\n  \"\\<forall>n m. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>n=n \\<and> \\<acute>m=m\\<rbrace> \\<acute>k :== CALL Max(LEQ_'proc,\\<acute>n,\\<acute>m) \\<lbrace>\\<acute>k = mx (op \\<le>) n m\\<rbrace>\"\nproof -\n  note Max_spec = Max_spec5\n  show ?thesis\n    apply vcg\n    apply (rule_tac x=\"op \\<le>\" in exI)\n    apply clarsimp\n    apply (rule LEQ_spec [rule_format])\n    done\nqed\n\nend\n", "meta": {"author": "LVPGroup", "repo": "TimSort", "sha": "16437b6b6e2df9f6d32b2a32be7d0d650d83f980", "save_path": "github-repos/isabelle/LVPGroup-TimSort", "path": "github-repos/isabelle/LVPGroup-TimSort/TimSort-16437b6b6e2df9f6d32b2a32be7d0d650d83f980/Simpl/ex/ProcParExSP.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.5, "lm_q1q2_score": 0.26754921431330575}}
{"text": "theory outEvenData\n\nimports bundle.SB\n  begin\n\ntypedef outEven = \"{cout}\"\n  by auto\n\ninstantiation outEven::\"{somechan,finite}\"\nbegin\ndefinition \"Rep = Rep_outEven\"\ninstance\n  apply(standard)\n  apply(auto simp add: Rep_outEven_def cEmpty_def)\n  apply(auto simp add: ctype_empty_iff)\n  using ctype_empty_iff\n  apply (metis Rep_outEven cMsg.simps ex_in_conv insertE insert_iff)\n  apply (meson Rep_outEven_inject injI) using cMsg.elims Rep_outEven apply simp\n  using type_definition.Abs_image type_definition_outEven typedef_finite_UNIV by fastforce\nend\n\ndefinition \"Evenout \\<equiv> Abs_outEven cout\"\n\nfree_constructors outEven for \"Evenout\"\n  by (metis(full_types) Abs_outEven_cases singletonD)\n\nlemma Andin1_rep [simp]: \"Rep (Evenout) = cout\"\n  by (simp add: Abs_outEven_inverse Evenout_def Rep_outEven_def)\n\nfun outEvenChan::\"('bool::type \\<Rightarrow> 'a::type) \\<Rightarrow> 'bool \\<Rightarrow> outEven \\<Rightarrow> 'a\" where\n\"outEvenChan Cc1 bool Evenout = Cc1 bool\"\n\nabbreviation \"buildEvenoutSBE \\<equiv> outEvenChan (Untimed o \\<B>)\" \n\nlemma buildevenout_ctype: \"buildEvenoutSBE a c \\<in> ctype (Rep c)\"\n  sorry\n\nlemma buildevenout_inj: \"inj buildEvenoutSBE\"\n  sorry\n\nlemma buildevenout_range: \"range (\\<lambda>a. buildEvenoutSBE a c) = ctype (Rep c)\"\n  sorry\n\nlemma buildevenout_surj: assumes \"sbElem_well (Some sbe)\"\n  shows \"sbe \\<in> range buildEvenoutSBE\"\nproof -\n  have ctypewell:\"\\<And> c. sbe c\\<in> ctype (Rep c)\"\n    using assms by auto\n  hence \"\\<And>c. sbe c \\<in> range (\\<lambda>a. buildEvenoutSBE a c)\"\n    by (simp add: buildevenout_range)\n  hence \"\\<exists>prod. sbe = buildEvenoutSBE prod\"\n    apply(subst fun_eq_iff,auto)\n    sorry\n  thus ?thesis\n    by auto\nqed\n\nabbreviation \"buildEvenoutSB \\<equiv> outEvenChan (Rep_cfun (smap (Untimed o \\<B>)))\" \n\nend", "meta": {"author": "yyisgladiator", "repo": "demo", "sha": "2a57300dfa7268721c78c233ee6b0a5454acce1f", "save_path": "github-repos/isabelle/yyisgladiator-demo", "path": "github-repos/isabelle/yyisgladiator-demo/demo-2a57300dfa7268721c78c233ee6b0a5454acce1f/src/demo/evenA/outEvenData.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185498374789, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.26754761596883525}}
{"text": "section \\<open>Accessed Variables\\<close>\ntheory SM_Variables\nimports \"../Refine/SM_Pid\"\nbegin\n\n  subsection \"Expressions\"\n\n  primrec udvars_of_exp :: \"exp \\<Rightarrow> ident set\" where\n      \"udvars_of_exp (e_var x) = {x}\"\n    | \"udvars_of_exp (e_localvar x) = {}\"\n    | \"udvars_of_exp (e_globalvar x) = {}\"\n    | \"udvars_of_exp (e_const c) = {}\"\n    | \"udvars_of_exp (e_bin bop e1 e2) = (udvars_of_exp e1) \\<union> (udvars_of_exp e2)\"\n    | \"udvars_of_exp (e_un uop e) = (udvars_of_exp e)\"\n\n  primrec lvars_of_exp :: \"exp \\<Rightarrow> ident set\" where\n      \"lvars_of_exp (e_var x) = {}\"\n    | \"lvars_of_exp (e_localvar x) = {x}\"\n    | \"lvars_of_exp (e_globalvar x) = {}\"\n    | \"lvars_of_exp (e_const c) = {}\"\n    | \"lvars_of_exp (e_bin bop e1 e2) = (lvars_of_exp e1) \\<union> (lvars_of_exp e2)\"\n    | \"lvars_of_exp (e_un uop e) = (lvars_of_exp e)\"\n      \n  primrec gvars_of_exp :: \"exp \\<Rightarrow> ident set\" where\n      \"gvars_of_exp (e_var x) = {}\"\n    | \"gvars_of_exp (e_localvar x) = {}\"\n    | \"gvars_of_exp (e_globalvar x) = {x}\"\n    | \"gvars_of_exp (e_const c) = {}\"\n    | \"gvars_of_exp (e_bin bop e1 e2) = (gvars_of_exp e1) \\<union> (gvars_of_exp e2)\"\n    | \"gvars_of_exp (e_un uop e) = (gvars_of_exp e)\"\n\n  subsection \"Commands\"\n  primrec join_cmd_exp :: \"'a \\<Rightarrow> ('a \\<Rightarrow> 'a \\<Rightarrow> 'a) \\<Rightarrow> (exp \\<Rightarrow> 'a) \\<Rightarrow> cmd \\<Rightarrow> 'a\" where  \n    \"join_cmd_exp z join f (Assign c x e) = join (f c) (f e)\"\n  | \"join_cmd_exp z join f (Assign_local c x e) = join (f c) (f e)\"\n  | \"join_cmd_exp z join f (Assign_global c x e) = join (f c) (f e)\"\n  | \"join_cmd_exp z join f (Test e) = f e\"\n  | \"join_cmd_exp z join f (Skip) = z\"\n  | \"join_cmd_exp z join f (Seq c1 c2) \n      = join (join_cmd_exp z join f c1) (join_cmd_exp z join f c2)\"\n  | \"join_cmd_exp z join f (Or c1 c2) \n      = join (join_cmd_exp z join f c1) (join_cmd_exp z join f c2)\"\n  | \"join_cmd_exp z join f (Break) = z\"\n  | \"join_cmd_exp z join f (Continue) = z\"\n  | \"join_cmd_exp z join f (Iterate c1 c2) \n      = join (join_cmd_exp z join f c1) (join_cmd_exp z join f c2)\"\n  | \"join_cmd_exp z join f (Invalid) = z\"\n\n  abbreviation \"union_cmd_exp \\<equiv> join_cmd_exp {} (\\<union>)\"\n  abbreviation \"all_cmd_exp \\<equiv> join_cmd_exp True (\\<and>)\"\n  abbreviation \"ex_cmd_exp \\<equiv> join_cmd_exp False (\\<or>)\"\n\n  abbreviation \"ud_rvars_of_cmd == union_cmd_exp udvars_of_exp\"\n  abbreviation \"g_rvars_of_cmd == union_cmd_exp gvars_of_exp\"\n  abbreviation \"l_rvars_of_cmd == union_cmd_exp lvars_of_exp\"\n\n  primrec ud_wvars_of_cmd :: \"cmd \\<Rightarrow> ident set\" where  \n    \"ud_wvars_of_cmd (Assign c x e) = {x}\"\n  | \"ud_wvars_of_cmd (Assign_local c x e) = {}\"\n  | \"ud_wvars_of_cmd (Assign_global c x e) = {}\"\n  | \"ud_wvars_of_cmd (Test e) = {}\"\n  | \"ud_wvars_of_cmd (Skip) = {}\"\n  | \"ud_wvars_of_cmd (Seq c1 c2) = (ud_wvars_of_cmd c1 \\<union> ud_wvars_of_cmd c2)\"\n  | \"ud_wvars_of_cmd (Or c1 c2) = (ud_wvars_of_cmd c1 \\<union> ud_wvars_of_cmd c2)\"\n  | \"ud_wvars_of_cmd (Break) = {}\"\n  | \"ud_wvars_of_cmd (Continue) = {}\"\n  | \"ud_wvars_of_cmd (Iterate c1 c2) = (ud_wvars_of_cmd c1 \\<union> ud_wvars_of_cmd c2)\"\n  | \"ud_wvars_of_cmd (Invalid) = {}\"\n\n  primrec l_wvars_of_cmd :: \"cmd \\<Rightarrow> ident set\" where  \n    \"l_wvars_of_cmd (Assign c x e) = {}\"\n  | \"l_wvars_of_cmd (Assign_local c x e) = {x}\"\n  | \"l_wvars_of_cmd (Assign_global c x e) = {}\"\n  | \"l_wvars_of_cmd (Test e) = {}\"\n  | \"l_wvars_of_cmd (Skip) = {}\"\n  | \"l_wvars_of_cmd (Seq c1 c2) = (l_wvars_of_cmd c1 \\<union> l_wvars_of_cmd c2)\"\n  | \"l_wvars_of_cmd (Or c1 c2) = (l_wvars_of_cmd c1 \\<union> l_wvars_of_cmd c2)\"\n  | \"l_wvars_of_cmd (Break) = {}\"\n  | \"l_wvars_of_cmd (Continue) = {}\"\n  | \"l_wvars_of_cmd (Iterate c1 c2) = (l_wvars_of_cmd c1 \\<union> l_wvars_of_cmd c2)\"\n  | \"l_wvars_of_cmd (Invalid) = {}\"\n\n  primrec g_wvars_of_cmd :: \"cmd \\<Rightarrow> ident set\" where  \n    \"g_wvars_of_cmd (Assign c x e) = {}\"\n  | \"g_wvars_of_cmd (Assign_local c x e) = {}\"\n  | \"g_wvars_of_cmd (Assign_global c x e) = {x}\"\n  | \"g_wvars_of_cmd (Test e) = {}\"\n  | \"g_wvars_of_cmd (Skip) = {}\"\n  | \"g_wvars_of_cmd (Seq c1 c2) = (g_wvars_of_cmd c1 \\<union> g_wvars_of_cmd c2)\"\n  | \"g_wvars_of_cmd (Or c1 c2) = (g_wvars_of_cmd c1 \\<union> g_wvars_of_cmd c2)\"\n  | \"g_wvars_of_cmd (Break) = {}\"\n  | \"g_wvars_of_cmd (Continue) = {}\"\n  | \"g_wvars_of_cmd (Iterate c1 c2) = (g_wvars_of_cmd c1 \\<union> g_wvars_of_cmd c2)\"\n  | \"g_wvars_of_cmd (Invalid) = {}\"\n\n\n  definition \"udvars_of_cmd c \\<equiv> ud_rvars_of_cmd c \\<union> ud_wvars_of_cmd c\"\n  definition \"lvars_of_cmd c \\<equiv> l_rvars_of_cmd c \\<union> l_wvars_of_cmd c\"\n  definition \"gvars_of_cmd c \\<equiv> g_rvars_of_cmd c \\<union> g_wvars_of_cmd c\"\n\n  fun read_globals :: \"action \\<Rightarrow> ident set\" where\n    \"read_globals (AAssign c _ e) = gvars_of_exp c \\<union> udvars_of_exp c \\<union>\n      gvars_of_exp e \\<union> udvars_of_exp e\"\n  | \"read_globals (AAssign_local c _ e) = gvars_of_exp c \\<union> udvars_of_exp c \\<union>\n      gvars_of_exp e \\<union> udvars_of_exp e\"\n  | \"read_globals (AAssign_global c _ e) = gvars_of_exp c \\<union> udvars_of_exp c \\<union>\n      gvars_of_exp e \\<union> udvars_of_exp e\"\n  | \"read_globals (ATest e) = gvars_of_exp e \\<union> udvars_of_exp e\"\n  | \"read_globals (ASkip) = {}\"\n\n  fun write_globals :: \"action \\<Rightarrow> ident set\" where\n    \"write_globals (AAssign _ x _) = {x}\"\n  | \"write_globals (AAssign_local _ _ _) = {}\"\n  | \"write_globals (AAssign_global _ x _) = {x}\"\n  | \"write_globals (ATest e) = {}\"\n  | \"write_globals (ASkip) = {}\"\n\n  abbreviation \"rw_globals a \\<equiv> read_globals a \\<union> write_globals a\"\n\n  definition eq_on :: \"ident set \\<Rightarrow> valuation \\<Rightarrow> valuation \\<Rightarrow> bool\"\n    where \"eq_on X s1 s2 \\<equiv> \\<forall>x\\<in>X. s1 x = s2 x\"\n\n  lemma eq_onD: \"\\<lbrakk>eq_on X s1 s2; x\\<in>X\\<rbrakk> \\<Longrightarrow> s1 x = s2 x\"\n    unfolding eq_on_def by auto  \n    \n  lemma \n    eq_on_refl[simp]: \"eq_on X s s\" and\n    eq_on_sym: \"eq_on X s1 s2 \\<Longrightarrow> eq_on X s2 s1\" and\n    eq_on_sym_eq: \"eq_on X s1 s2 \\<longleftrightarrow> eq_on X s2 s1\" and\n    eq_on_trans[trans]: \"\\<lbrakk>eq_on Xa s1 s2; eq_on Xb s2 s3\\<rbrakk> \n      \\<Longrightarrow> eq_on (Xa\\<inter>Xb) s1 s3\" and\n    eq_on_UNIV_eq[simp]: \"eq_on UNIV s1 s2 \\<longleftrightarrow> s1=s2\"  \n    unfolding eq_on_def by auto\n\n  lemma eq_on_join: \"\\<lbrakk>eq_on X s s'; eq_on Y s s'\\<rbrakk> \\<Longrightarrow> eq_on (X\\<union>Y) s s'\"\n    unfolding eq_on_def by auto\n\n  abbreviation ls_eq_on :: \"ident set \\<Rightarrow> local_state \\<Rightarrow> local_state \\<Rightarrow> bool\"\n    where \"ls_eq_on X ls1 ls2 \\<equiv> \n      eq_on X (local_state.variables ls1) (local_state.variables ls2)\"  \n\n  abbreviation gs_eq_on :: \"ident set \\<Rightarrow> global_state \\<Rightarrow> global_state \\<Rightarrow> bool\"\n    where \"gs_eq_on X ls1 ls2 \\<equiv> \n      eq_on X (global_state.variables ls1) (global_state.variables ls2)\"  \n\n  lemma eval_dep_vars:\n    assumes \"gs_eq_on X gs gs'\"    \n    assumes \"udvars_of_exp e \\<subseteq> X\" \"gvars_of_exp e \\<subseteq> X\"\n    shows \"eval_exp e (ls,gs) = eval_exp e (ls,gs')\"\n    using assms\n    apply (induction e)\n    apply (auto split: option.splits simp: eq_on_def)\n    done    \n\n  lemma en_dep_read:\n    assumes \"gs_eq_on X gs gs'\"\n    assumes \"read_globals a \\<subseteq> X\"\n    shows \"la_en' (ls,gs) a = la_en' (ls,gs') a\"\n    using assms\n    apply (cases a)\n    apply (auto \n      simp: la_en'_def eval_dep_vars \n      split: Option.bind_splits)\n    done\n\n  lemma ex_mod_limit: \n    assumes \"la_ex' (ls,gs) a = (ls',gs')\"\n    shows \"gs_eq_on (-write_globals a) gs gs'\"\n    using assms\n    apply (cases a)\n    apply (auto \n      simp: la_ex'_def eval_dep_vars eq_on_def \n      split: option.splits Option.bind_splits if_split_asm)\n    done    \n\n  lemma ex_dep_pres:\n    assumes \"gs_eq_on X gs1 gs2\"\n    assumes \"read_globals a \\<subseteq> X\"\n    assumes \"la_ex' (ls,gs1) a = (ls1',gs1')\"\n    assumes \"la_ex' (ls,gs2) a = (ls2',gs2')\"\n    shows \"ls1'=ls2' \\<and> gs_eq_on X gs1' gs2'\"\n    using assms\n    apply (cases a)\n    apply (auto \n      simp: la_ex'_def eval_dep_vars eq_on_def\n      split: Option.bind_splits option.splits bool.splits if_split_asm)\n    done\n\n\n  lemma ex_swap_global:\n    assumes DJ:\n      \"write_globals a1 \\<inter> read_globals a2 = {}\"\n      \"write_globals a2 \\<inter> read_globals a1 = {}\"\n      \"write_globals a1 \\<inter> write_globals a2 = {}\"\n    assumes EXA: \n      \"la_ex' (ls1,gs) a1 = (ls1a, gsa)\"\n      \"la_ex' (ls2, gsa) a2 = (ls2a, gsa')\"\n    assumes EXB:\n      \"la_ex' (ls2,gs) a2 = (ls2b, gsb)\"\n      \"la_ex' (ls1, gsb) a1 = (ls1b, gsb')\"\n    shows \"ls1a=ls1b\" \"ls2a=ls2b\" \"gsa'=gsb'\"\n  proof -\n    from ex_dep_pres[OF ex_mod_limit[OF EXB(1)] _ EXA(1) EXB(2)] DJ\n    have \"ls1a = ls1b\" and E1: \"gs_eq_on (- write_globals a2) gsa gsb'\"\n      by auto\n    thus [simp]: \"ls1a=ls1b\" by simp\n      \n    from \n      ex_dep_pres[OF \n        ex_mod_limit[OF EXA(1), THEN eq_on_sym] _ EXA(2) EXB(1)\n      ] DJ\n    have \"ls2a = ls2b\" and E2: \"gs_eq_on (- write_globals a1) gsa' gsb\"\n      by auto\n    thus [simp]: \"ls2a=ls2b\" by simp\n\n    from DJ have [simp]: \"- write_globals a1 \\<union> - write_globals a2 = UNIV\" \n      by auto\n\n    from eq_on_trans[OF E2 ex_mod_limit[OF EXB(2)]]\n    have \"gs_eq_on (- write_globals a1) gsa' gsb'\" by simp\n    also from eq_on_trans[OF ex_mod_limit[OF EXA(2), THEN eq_on_sym] E1]\n    have \"gs_eq_on (- write_globals a2) gsa' gsb'\" by simp\n    finally (eq_on_join) have \"gs_eq_on UNIV gsa' gsb'\" by simp\n    thus \"gsa' = gsb'\" \n      apply (cases gsa', cases gsb')\n      apply simp\n      done\n  qed\n\n  lemma ex_pres_en:\n    assumes EX: \"la_ex' (ls1,gs) a1 = (ls1',gs')\"\n    assumes DJ: \"write_globals a1 \\<inter> read_globals a2 = {}\"\n    shows \"la_en' (ls2,gs') a2 = la_en' (ls2,gs) a2\"\n    using en_dep_read[OF ex_mod_limit[OF EX], of a2] DJ by auto\n\n\n\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/CAVA_LTL_Modelchecker/SM/Analysis/SM_Variables.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185351961015, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.26754760904809805}}
{"text": "theory Post_ISSUER\n  imports\n    \"Bounded_Deducibility_Security.Compositional_Reasoning\"\n    \"Post_Observation_Setup_ISSUER\"\n    \"Post_Value_Setup_ISSUER\"\nbegin\n\nsubsubsection \\<open>Issuer declassification bound\\<close>\n\ntext \\<open>We verify that a group of users of some node \\<open>i\\<close>,\nallowed to take normal actions to the system and observe their outputs\n\\emph{and additionally allowed to observe communication},\ncan learn nothing about the updates to a post located at node \\<open>i\\<close>\nand the sends of that post to other nodes beyond\n\n(1) the presence of the sends (i.e., the number of the sending actions)\n\n(2) the public knowledge that what is being sent is always the last version (modeled as\nthe correlation predicate)\n\nunless:\n\\begin{itemize}\n\\item either a user in the group is the post's owner or the administrator\n\\item or a user in the group becomes a friend of the owner\n\\item or the group has at least one registered user and the post is being marked as \"public\"\n\\end{itemize}\n\nSee \\<^cite>\\<open>\"cosmedis-SandP2017\"\\<close> for more details.\n\\<close>\n\ncontext Post_ISSUER\nbegin\n\nfun T :: \"(state,act,out) trans \\<Rightarrow> bool\" where\n\"T (Trans s a ou s') \\<longleftrightarrow>\n (\\<exists> uid \\<in> UIDs.\n   uid \\<in>\\<in> userIDs s' \\<and> PID \\<in>\\<in> postIDs s' \\<and>\n   (uid = admin s' \\<or>\n    uid = owner s' PID \\<or>\n    uid \\<in>\\<in> friendIDs s' (owner s' PID) \\<or>\n    vis s' PID = PublicV))\"\n\n(* Correlation is defined to mean: always send what was last uploaded, or emptyPost\nif nothing had been uploaded. This needs the auxiliary notion of \"correlated from\" *)\nfun corrFrom :: \"post \\<Rightarrow> value list \\<Rightarrow> bool\" where\n \"corrFrom pst [] = True\"\n|\"corrFrom pst (PVal pstt # vl) = corrFrom pstt vl\"\n|\"corrFrom pst (PValS aid pstt # vl) = (pst = pstt \\<and> corrFrom pst vl)\"\n\nabbreviation corr :: \"value list \\<Rightarrow> bool\" where \"corr \\<equiv> corrFrom emptyPost\"\n\n(* Beyond correlation (which is public knowledge), one can only learn\nthe absence of any secret produced (if that is the case), the number of\ntimes the notice has been sent, and to which nodes they have been sent:\n(since network traffic is assumed to be observable) *)\ndefinition B :: \"value list \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"B vl vl1 \\<equiv>\n corr vl1 \\<and>\n (vl = [] \\<longrightarrow> vl1 = []) \\<and>\n map PValS_tgtAPI (filter isPValS vl) = map PValS_tgtAPI (filter isPValS vl1)\"\n\n\nsublocale BD_Security_IO where\nistate = istate and step = step and\n\\<phi> = \\<phi> and f = f and \\<gamma> = \\<gamma> and g = g and T = T and B = B\ndone\n\nsubsubsection \\<open>Unwinding proof\\<close>\n\nlemma reach_PublicV_imples_FriendV[simp]:\nassumes \"reach s\"\nand \"vis s pID \\<noteq> PublicV\"\nshows \"vis s pID = FriendV\"\nusing assms reach_vis by auto\n\nlemma reachNT_state:\nassumes \"reachNT s\"\nshows \"\\<not> (\\<exists> uid \\<in> UIDs.\n   uid \\<in>\\<in> userIDs s \\<and> PID \\<in>\\<in> postIDs s \\<and>\n   (uid = admin s \\<or> uid = owner s PID \\<or> uid \\<in>\\<in> friendIDs s (owner s PID) \\<or>\n    vis s PID = PublicV))\"\nusing assms proof induct\n  case (Step trn) thus ?case\n  by (cases trn) auto\nqed (simp add: istate_def)\n\n(* major *) lemma T_\\<phi>_\\<gamma>:\nassumes 1: \"reachNT s\" and 2: \"step s a = (ou,s')\"\nand 3: \"\\<phi> (Trans s a ou s')\" and\n(* note that now we have some overlap between \\<phi> and \\<gamma>, even for reachNT: *)\n4: \"\\<forall> ca. a \\<noteq> COMact ca\"\nshows \"\\<not> \\<gamma> (Trans s a ou s')\"\nusing reachNT_state[OF 1] 2 3 4 using \\<phi>_def2(* [OF 2] *)\nby (auto simp add: u_defs com_defs)\n\n(* major *) lemma eqButPID_step_\\<gamma>_out:\nassumes ss1: \"eqButPID s s1\"\nand step: \"step s a = (ou,s')\" and step1: \"step s1 a = (ou1,s1')\"\nand sT: \"reachNT s\" and T: \"\\<not> T (Trans s a ou s')\"\nand s1: \"reach s1\"\nand \\<gamma>: \"\\<gamma> (Trans s a ou s')\"\nshows \"(\\<exists> uid p aid pid. a = COMact (comSendPost uid p aid pid) \\<and> outPurge ou = outPurge ou1) \\<or> ou = ou1\"\nproof-\n  have s'T: \"reachNT s'\" using step sT T using reachNT_PairI by blast\n  note op = reachNT_state[OF s'T]\n  note [simp] = all_defs\n  note s = reachNT_reach[OF sT]\n  note willUse =\n    step step1 \\<gamma>\n    op\n    reach_vis[OF s]\n    eqButPID_stateSelectors[OF ss1] (* eqButPID_postSelectors[OF ss1] *)\n    eqButPID_actions[OF ss1]\n    eqButPID_update[OF ss1] (* eqButPID_setTextPost[OF ss1] *) eqButPID_not_PID[OF ss1]\n    (* added to cope with extra leak towards the admin, when moving from API to CAPI: *)\n    (* eqButPID_eqButT[OF ss1] *) eqButPID_eqButF[OF ss1]\n    eqButPID_setShared[OF ss1] eqButPID_updateShared[OF ss1]\n    eeqButPID_F_not_PID eqButPID_not_PID_sharedWith\n    eqButPID_insert2[OF ss1]\n  show ?thesis\n  proof (cases a)\n    case (Sact x1)\n    with willUse show ?thesis by (cases x1) auto\n  next\n    case (Cact x2)\n    with willUse show ?thesis by (cases x2) auto\n  next\n    case (Dact x3)\n    with willUse show ?thesis by (cases x3) auto\n  next\n    case (Uact x4)\n    with willUse show ?thesis by (cases x4) auto\n  next\n    case (Ract x5)\n    with willUse show ?thesis\n    proof (cases x5)\n      case (rPost uid p pid)\n      with Ract willUse show ?thesis by (cases \"pid = PID\") auto\n    qed auto\n  next\n    case (Lact x6)\n    with willUse show ?thesis\n    proof (cases x6)\n      case (lClientsPost uid p pid)\n      with Lact willUse show ?thesis by (cases \"pid = PID\") auto\n    qed auto\n  next\n    case (COMact x7)\n    with willUse show ?thesis by (cases x7) auto\n  qed\nqed\n\n(* major *) lemma eqButPID_step_eq:\nassumes ss1: \"eqButPID s s1\"\nand a: \"a = Uact (uPost uid p PID pst)\" \"ou = outOK\"\nand step: \"step s a = (ou, s')\" and step1: \"step s1 a = (ou', s1')\"\nshows \"s' = s1'\"\nusing ss1 step step1\nusing eqButPID_stateSelectors[OF ss1]\neqButPID_update[OF ss1] (* eqButPID_setTextPost[OF ss1] *) eqButPID_setShared[OF ss1]\nunfolding a by (auto simp: u_defs)\n\ndefinition \\<Delta>0 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>0 s vl s1 vl1 \\<equiv>\n \\<not> PID \\<in>\\<in> postIDs s \\<and> post s PID = emptyPost \\<and>\n s = s1 \\<and>\n corrFrom (post s1 PID) vl1 \\<and>\n (vl = [] \\<longrightarrow> vl1 = []) \\<and>\n map PValS_tgtAPI (filter isPValS vl) = map PValS_tgtAPI (filter isPValS vl1)\"\n\ndefinition \\<Delta>1 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>1 s vl s1 vl1 \\<equiv>\n PID \\<in>\\<in> postIDs s \\<and>\n eqButPID s s1 \\<and>\n corrFrom (post s1 PID) vl1 \\<and>\n (vl = [] \\<longrightarrow> vl1 = []) \\<and>\n map PValS_tgtAPI (filter isPValS vl) = map PValS_tgtAPI (filter isPValS vl1)\"\n\ndefinition \\<Delta>2 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>2 s vl s1 vl1 \\<equiv>\n PID \\<in>\\<in> postIDs s \\<and>\n eqButPID s s1 \\<and>\n vl = [] \\<and> list_all isPVal vl1\"\n\nlemma istate_\\<Delta>0:\nassumes B: \"B vl vl1\"\nshows \"\\<Delta>0 istate vl istate vl1\"\nusing assms unfolding \\<Delta>0_def B_def istate_def by auto\n\nlemma unwind_cont_\\<Delta>0: \"unwind_cont \\<Delta>0 {\\<Delta>0,\\<Delta>1}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>0 s vl s1 vl1 \\<or> \\<Delta>1 s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \"\\<Delta>0 s vl s1 vl1\"\n  hence rs: \"reach s\" and ss1: \"s1 = s\" and pPID: \"post s PID = emptyPost\"\n  and ch: \"corrFrom (post s1 PID) vl1\"\n  and l: \"map PValS_tgtAPI (filter isPValS vl) = map PValS_tgtAPI (filter isPValS vl1)\"\n  and PID: \"\\<not> PID \\<in>\\<in> postIDs s\" and vlvl1: \"vl = [] \\<Longrightarrow> vl1 = []\"\n  using reachNT_reach unfolding \\<Delta>0_def by auto\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof-\n    have ?react proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\"  let ?trn1 = \"Trans s1 a ou s'\"\n      assume step: \"step s a = (ou, s')\" and T: \"\\<not> T ?trn\" and c: \"consume ?trn vl vl'\"\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n      proof-\n        have \\<phi>: \"\\<not> \\<phi> ?trn\" using PID step unfolding \\<phi>_def2(* [OF step] *) by (auto simp: u_defs com_defs)\n        hence vl': \"vl' = vl\" using c \\<phi> unfolding consume_def by simp\n        have pPID': \"post s' PID = emptyPost\"\n          using pPID PID step\n          apply(cases a)\n          subgoal for x1 apply(cases x1, auto simp: all_defs) .\n          subgoal for x2 apply(cases x2, auto simp: all_defs) .\n          subgoal for x3 apply(cases x3, auto simp: all_defs) .\n          subgoal for x4 apply(cases x4, auto simp: all_defs) .\n          subgoal by auto\n          subgoal by auto\n          subgoal for x7 apply(cases x7, auto simp: all_defs) .\n          done\n        have ?match proof(cases \"\\<exists> uid p. a = Cact (cPost uid p PID) \\<and> ou = outOK\")\n          case True\n          then obtain uid p where a: \"a = Cact (cPost uid p PID)\" and ou: \"ou = outOK\" by auto\n          have PID': \"PID \\<in>\\<in> postIDs s'\"\n          using step PID unfolding a ou by (auto simp: c_defs)\n          note uid = reachNT_state[OF rsT]\n          show ?thesis proof\n            show \"validTrans ?trn1\" unfolding ss1 using step by simp\n          next\n            show \"consume ?trn1 vl1 vl1\" using \\<phi> unfolding consume_def ss1 by auto\n          next\n            show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n          next\n            assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\" unfolding ss1 by simp\n          next\n            have \"\\<Delta>1 s' vl' s' vl1\" using l PID' c ch vlvl1 pPID' pPID\n             unfolding ss1 \\<Delta>1_def vl' by auto\n            thus \"?\\<Delta> s' vl' s' vl1\" by simp\n          qed\n        next\n          case False note a = False\n          have PID': \"\\<not> PID \\<in>\\<in> postIDs s'\"\n            using step PID a\n            apply(cases a)\n            subgoal for x1 apply(cases x1) apply(fastforce simp: s_defs)+ .\n            subgoal for x2 apply(cases x2) apply(fastforce simp: c_defs)+ .\n            subgoal for x3 apply(cases x3) apply(fastforce simp: d_defs)+ .\n            subgoal for x4 apply(cases x4) apply(fastforce simp: u_defs)+ .\n            subgoal by auto\n            subgoal by auto\n            subgoal for x7 apply(cases x7) apply(fastforce simp: com_defs)+ .\n            done\n          show ?thesis proof\n            show \"validTrans ?trn1\" unfolding ss1 using step by simp\n          next\n            show \"consume ?trn1 vl1 vl1\" using \\<phi> unfolding consume_def ss1 by auto\n          next\n            show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n          next\n            assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\" unfolding ss1 by simp\n          next\n            have \"\\<Delta>0 s' vl' s' vl1\" using a PID' pPID pPID' ch vlvl1 l unfolding \\<Delta>0_def vl' ss1 by simp\n            thus \"?\\<Delta> s' vl' s' vl1\" by simp\n          qed\n        qed\n        thus ?thesis by simp\n      qed\n    qed\n  thus ?thesis using vlvl1 by simp\n  qed\nqed\n\nlemma unwind_cont_\\<Delta>1: \"unwind_cont \\<Delta>1 {\\<Delta>1,\\<Delta>2}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>1 s vl s1 vl1 \\<or> \\<Delta>2 s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \"\\<Delta>1 s vl s1 vl1\"\n  hence vlvl1: \"vl = [] \\<longrightarrow> vl1 = []\" and ch1: \"corrFrom (post s1 PID) vl1\"\n  and rs: \"reach s\" and ss1: \"eqButPID s s1\" and PID: \"PID \\<in>\\<in> postIDs s\"\n  and l: \"map PValS_tgtAPI (filter isPValS vl) = map PValS_tgtAPI (filter isPValS vl1)\"\n  using reachNT_reach unfolding \\<Delta>1_def by auto\n  have PID1: \"PID \\<in>\\<in> postIDs s1\" using eqButPID_stateSelectors[OF ss1] PID by auto\n  have own: \"owner s PID \\<in> set (userIDs s)\" using reach_owner_userIDs[OF rs PID] .\n  hence own1: \"owner s1 PID \\<in> set (userIDs s1)\" using eqButPID_stateSelectors[OF ss1] by auto\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof(cases vl1)\n    case (Cons v1 vll1) note vl1 = Cons\n    obtain v vll where vl: \"vl = v # vll\" using vl1 vlvl1 by (cases vl) auto\n    show ?thesis\n    proof(cases v1)\n      case (PVal pst1) note v1 = PVal\n      let ?uid1 = \"owner s1 PID\" let ?p1 = \"pass s1 ?uid1\"\n      have uid1: \"?uid1 \\<in>\\<in> userIDs s1\" using reach_owner_userIDs[OF rs1 PID1] .\n      define a1 where \"a1 \\<equiv> Uact (uPost ?uid1 ?p1 PID pst1)\"\n      obtain s1' ou1 where step1: \"step s1 a1 = (ou1,s1')\" by force\n      hence ou1: \"ou1 = outOK\" using PID1 uid1 unfolding a1_def by (auto simp: u_defs)\n      let ?trn1 = \"Trans s1 a1 ou1 s1'\"\n      have \\<phi>1: \"\\<phi> ?trn1\" unfolding a1_def PID1 ou1 by simp\n      have 2[simp]: \"post s1' PID = pst1\"\n      using step1 unfolding a1_def ou1 by (auto simp: u_defs)\n      have \"?uid1 = owner s PID\" using eqButPID_stateSelectors[OF ss1] by simp\n      hence uid1: \"?uid1 \\<notin> UIDs\" using reachNT_state own rsT PID by auto\n      have \"eqButPID s1 s1'\" using step1 a1_def Uact_uPaperC_step_eqButPID by auto\n      hence ss1': \"eqButPID s s1'\" using ss1 using eqButPID_trans by blast\n      have \"?iact\" proof\n        show \"step s1 a1 = (ou1, s1')\" \"\\<phi> ?trn1\" by fact+\n        show \"consume (Trans s1 a1 ou1 s1') vl1 vll1\"\n        using \\<phi>1 unfolding consume_def vl1 a1_def v1 by simp\n        show \"\\<not> \\<gamma> ?trn1\" using uid1 unfolding a1_def by auto\n        show \"?\\<Delta> s vl s1' vll1\"\n        proof(cases vll1)\n          case Nil\n          have \"\\<Delta>1 s vl s1' vll1\" using PID ss1' l unfolding \\<Delta>1_def B_def vl1 v1 Nil by auto\n          thus ?thesis by simp\n        next\n          case (Cons w1 vlll1) note vll1 = Cons\n          have \"\\<Delta>1 s vl s1' vll1\" using PID ss1' l ch1\n          unfolding \\<Delta>1_def B_def vl1 v1 vl by auto\n          thus ?thesis by simp\n        qed\n      qed\n      thus ?thesis by simp\n    next\n      case (PValS aid1 pst1) note v1 = PValS\n      have pst1: \"pst1 = post s1 PID\" using ch1 unfolding vl1 v1 by simp\n      show ?thesis\n      proof(cases v)\n        case (PVal \"pst\") note v = PVal\n        hence vll: \"vll \\<noteq> []\" using vlvl1 l unfolding vl vl1 v v1 by auto\n        have ?react proof\n          fix a :: act and ou :: out and s' :: state and vl'\n          let ?trn = \"Trans s a ou s'\"\n          assume step: \"step s a = (ou, s')\" and T: \"\\<not> T ?trn\" and c: \"consume ?trn vl vl'\"\n          have vl': \"vl' = vl \\<or> vl' = vll\" using c unfolding vl consume_def by (cases \"\\<phi> ?trn\") auto\n          hence vl'NE: \"vl' \\<noteq> []\" using vll vl by auto\n          have fvl': \"filter isPValS vl' = filter isPValS vll\" using vl' unfolding vl v by auto\n          obtain ou1 s1' where step1: \"step s1 a = (ou1, s1')\" by fastforce\n          let ?trn1 = \"Trans s1 a ou1 s1'\"\n          have s's1': \"eqButPID s' s1'\" using eqButPID_step ss1 step step1 by blast\n          have \\<gamma>\\<gamma>1: \"\\<gamma> ?trn \\<longleftrightarrow> \\<gamma> ?trn1\" by simp\n          have PID': \"PID \\<in>\\<in> postIDs s'\" using step rs PID using reach_postIDs_persist by blast\n          have 2[simp]: \"\\<not> \\<phi> ?trn1 \\<Longrightarrow> post s1' PID = post s1 PID\"\n            using step1 PID1 unfolding \\<phi>_def2(* [OF step1] *)\n            apply(cases a, auto)\n            subgoal for x1 apply(cases x1, auto simp: all_defs) .\n            subgoal for x2 apply(cases x2, auto simp: all_defs) .\n            subgoal for x3 apply(cases x3, auto simp: all_defs) .\n            subgoal for x4 apply(cases x4, auto simp: all_defs) .\n            subgoal for x4 apply(cases x4, auto simp: all_defs) .\n            subgoal for x7 apply(cases x7, auto simp: all_defs) .\n            subgoal for x7 apply(cases x7, auto simp: all_defs) .\n            done\n          show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n          proof(cases \"\\<gamma> ?trn\")\n            case True note \\<gamma> = True\n            have ou: \"(\\<exists> uid p aid pid. a = COMact (comSendPost uid p aid pid) \\<and> outPurge ou = outPurge ou1) \\<or>\n                                        ou = ou1\"\n            using eqButPID_step_\\<gamma>_out[OF ss1 step step1 rsT T rs1 \\<gamma>] .\n            {assume \\<phi>: \"\\<phi> ?trn\"\n             hence \"f ?trn = v\" using c unfolding consume_def vl by simp\n             hence \"\\<forall>ca. a \\<noteq> COMact ca\" using \\<phi> unfolding \\<phi>_def3[OF step] v by auto\n             hence False using T_\\<phi>_\\<gamma>[OF rsT step \\<phi>] \\<gamma> by auto\n            }\n            hence \\<phi>: \"\\<not> \\<phi> ?trn\" by auto\n            have vl': \"vl' = vl\" using \\<phi> c unfolding consume_def by simp\n            have \\<phi>1: \"\\<not> \\<phi> ?trn1\" using step step1 ss1 \\<phi> eqButPID_step_\\<phi> by blast\n            have ?match proof\n              show \"validTrans ?trn1\" using step1 by auto\n              show \"consume ?trn1 vl1 vl1\" using \\<phi>1 unfolding consume_def by simp\n              show \"\\<gamma> ?trn \\<longleftrightarrow> \\<gamma> ?trn1\" by fact\n            next\n              show \"g ?trn = g ?trn1\" using ou by (cases a) auto\n              have \"\\<Delta>1 s' vl' s1' vl1\"\n              using PID' s's1' vlvl1 l ch1 \\<phi>1 unfolding \\<Delta>1_def vl' by auto\n              thus \"?\\<Delta> s' vl' s1' vl1\" by simp\n            qed\n            thus ?thesis by simp\n          next\n            case False note \\<gamma> = False\n            show ?thesis\n            proof(cases \"\\<phi> ?trn\")\n              case True note \\<phi> = True\n              hence \"f ?trn = v\" using c unfolding consume_def vl by simp\n              hence \"\\<forall>ca. a \\<noteq> COMact ca\" using \\<phi> unfolding \\<phi>_def3[OF step] v by auto\n              then obtain uid p \"pstt\" where a: \"a = Uact (uPost uid p PID pstt)\"\n              using \\<phi> unfolding \\<phi>_def2(* [OF step] *) by auto\n              hence ss': \"eqButPID s s'\" using step Uact_uPaperC_step_eqButPID by auto\n              hence s's1: \"eqButPID s' s1\" using ss1 eqButPID_sym eqButPID_trans by blast\n              have ?ignore proof\n                show \"\\<not> \\<gamma> ?trn\" by fact\n                have \"\\<Delta>1 s' vl' s1 vl1\"\n                using PID' s's1' ch1 l vl'NE s's1 unfolding \\<Delta>1_def fvl' vl v by auto\n                thus \"?\\<Delta> s' vl' s1 vl1\" by simp\n              qed\n              thus ?thesis by simp\n            next\n              case False note \\<phi> = False\n              have vl': \"vl' = vl\" using \\<phi> c unfolding consume_def by simp\n              have \\<phi>1: \"\\<not> \\<phi> ?trn1\" using step step1 ss1 \\<phi> eqButPID_step_\\<phi> by blast\n              have ?match proof\n                show \"validTrans ?trn1\" using step1 by auto\n                show \"consume ?trn1 vl1 vl1\" using \\<phi>1 unfolding consume_def by simp\n                show \"\\<gamma> ?trn \\<longleftrightarrow> \\<gamma> ?trn1\" by fact\n              next\n                assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\" using \\<gamma> by simp\n              next\n                have \"\\<Delta>1 s' vl' s1' vl1\"\n                using PID' s's1' vlvl1 l ch1 \\<phi>1 unfolding \\<Delta>1_def vl' by auto\n                thus \"?\\<Delta> s' vl' s1' vl1\" by simp\n              qed\n              thus ?thesis by simp\n            qed\n          qed\n        qed\n        thus ?thesis using vlvl1 by simp\n      next\n        case (PValS aid \"pst\") note v = PValS\n        have ?react proof\n          fix a :: act and ou :: out and s' :: state and vl'\n          let ?trn = \"Trans s a ou s'\"\n          assume step: \"step s a = (ou, s')\" and T: \"\\<not> T ?trn\" and c: \"consume ?trn vl vl'\"\n          have vl': \"vl' = vl \\<or> vl' = vll\" using c unfolding vl consume_def by (cases \"\\<phi> ?trn\") auto\n          obtain ou1 s1' where step1: \"step s1 a = (ou1, s1')\" by fastforce\n          let ?trn1 = \"Trans s1 a ou1 s1'\"\n          have s's1': \"eqButPID s' s1'\" using eqButPID_step ss1 step step1 by blast\n          have \\<gamma>\\<gamma>1: \"\\<gamma> ?trn \\<longleftrightarrow> \\<gamma> ?trn1\" by simp\n          have PID': \"PID \\<in>\\<in> postIDs s'\" using step rs PID using reach_postIDs_persist by blast\n          show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n          proof-\n            have ?match proof(cases \"\\<phi> ?trn\")\n              case True note \\<phi> = True\n              have \\<phi>1: \"\\<phi> ?trn1\" using step step1 ss1 \\<phi> eqButPID_step_\\<phi> by blast\n              let ?ad = \"admin s\"  let ?p = \"pass s ?ad\" let ?pst = \"post s PID\"\n              let ?uid = \"owner s PID\" let ?vs = \"vis s PID\"\n              obtain vl': \"vl' = vll\"\n              and ou: \"ou = O_sendPost (aid, clientPass s aid, PID, pst, ?uid, ?vs)\"\n              and a: \"a = COMact (comSendPost ?ad ?p aid PID)\" and \"pst\": \"pst = ?pst\"\n              using \\<phi> c unfolding \\<phi>_def3[OF step] consume_def vl v by auto\n              let ?pst1 = \"post s1 PID\"\n              have \"clientPass s aid = clientPass s1 aid\" and \"?uid = owner s1 PID\"\n              and \"?vs = vis s1 PID\"\n              using eqButPID_stateSelectors[OF ss1] by auto\n              hence ou1: \"ou1 = O_sendPost (aid, clientPass s aid, PID, ?pst1, ?uid, ?vs)\"\n              using step1 \\<phi>1 unfolding \\<phi>_def3[OF step1] vl1 v1 a\n              by (auto simp: com_defs)\n              have 2[simp]: \"post s1' PID = pst1\"\n              using step1 unfolding a ou1 pst1 by (auto simp: com_defs)\n              have ch_vll1: \"corrFrom pst1 vll1\" using ch1 unfolding pst1[symmetric] vl1 v1 by auto\n              show ?thesis proof\n                show \"validTrans ?trn1\" using step1 by auto\n                show \"consume (Trans s1 a ou1 s1') vl1 vll1\"\n                using l \\<phi>1 pst1 unfolding consume_def vl vl1 v v1 a ou1 by simp\n                show \"\\<gamma> ?trn \\<longleftrightarrow> \\<gamma> ?trn1\" by fact\n              next\n                show \"g ?trn = g ?trn1\" unfolding a ou ou1 by (simp add: ss1)\n                show \"?\\<Delta> s' vl' s1' vll1\"\n                proof(cases \"vll = []\")\n                  case False\n                  hence \"\\<Delta>1 s' vl' s1' vll1\" using PID' s's1' vlvl1 l ch1 ch_vll1\n                  unfolding \\<Delta>1_def vl' vl vl1 v v1 by auto\n                  thus ?thesis by simp\n                next\n                  case True\n                  hence \"list_all isPVal vll1\" using l unfolding vl vl1 v v1 by (simp add: filter_isPValS_Nil)\n                  hence \"\\<Delta>2 s' vl' s1' vll1\" using True PID' s's1' vlvl1 l ch1 ch_vll1\n                  unfolding \\<Delta>2_def vl' vl vl1 v v1 by simp\n                  thus ?thesis by simp\n                qed\n              qed\n            next\n              case False note \\<phi> = False\n              have vl': \"vl' = vl\" using \\<phi> c unfolding consume_def by simp\n              have \\<phi>1: \"\\<not> \\<phi> ?trn1\" using step step1 ss1 \\<phi> eqButPID_step_\\<phi> by blast\n              have ?match proof\n                show \"validTrans ?trn1\" using step1 by auto\n                show \"consume ?trn1 vl1 vl1\" using \\<phi>1 unfolding consume_def by simp\n                show \"\\<gamma> ?trn \\<longleftrightarrow> \\<gamma> ?trn1\" by fact\n              next\n                assume \"\\<gamma> ?trn\" note \\<gamma> = this\n                have ou: \"(\\<exists> uid p aid pid. a = COMact (comSendPost uid p aid pid) \\<and> outPurge ou = outPurge ou1) \\<or>\n                                        ou = ou1\"\n                using eqButPID_step_\\<gamma>_out[OF ss1 step step1 rsT T rs1 \\<gamma>] .\n                thus \"g ?trn = g ?trn1\" by (cases a) auto\n              next\n                have 2[simp]: \"post s1' PID  = post s1 PID\"\n                  using step1 PID1 \\<phi>1 unfolding \\<phi>_def2(* [OF step1] *)\n                  apply(cases a)\n                  subgoal for x1 apply(cases x1, auto simp: all_defs) .\n                  subgoal for x2 apply(cases x2, auto simp: all_defs) .\n                  subgoal for x3 apply(cases x3, auto simp: all_defs) .\n                  subgoal for x4 apply(cases x4, auto simp: all_defs) .\n                  subgoal by auto\n                  subgoal by auto\n                  subgoal for x7 apply(cases x7, auto simp: all_defs) .\n                  done\n                have \"\\<Delta>1 s' vl' s1' vl1\" using PID' s's1' vlvl1 l ch1\n                unfolding \\<Delta>1_def vl' vl vl1 v v1 by auto\n                thus \"?\\<Delta> s' vl' s1' vl1\" by simp\n              qed\n              thus ?thesis by simp\n            qed\n            thus ?thesis by simp\n          qed\n        qed\n        thus ?thesis using vlvl1 by simp\n      qed\n    qed\n  next\n    case Nil note vl1 = Nil\n    have ?react proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\"\n      assume step: \"step s a = (ou, s')\" and T: \"\\<not> T ?trn\" and c: \"consume ?trn vl vl'\"\n      obtain ou1 s1' where step1: \"step s1 a = (ou1, s1')\" by fastforce\n      let ?trn1 = \"Trans s1 a ou1 s1'\"\n      have s's1': \"eqButPID s' s1'\" using eqButPID_step ss1 step step1 by blast\n      have \\<gamma>\\<gamma>1: \"\\<gamma> ?trn \\<longleftrightarrow> \\<gamma> ?trn1\" by simp\n      have PID': \"PID \\<in>\\<in> postIDs s'\" using step rs PID using reach_postIDs_persist by blast\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n      proof(cases \"\\<phi> ?trn\")\n        case True note \\<phi> = True\n        then obtain v vll where vl: \"vl = v # vll\"\n        and f: \"f ?trn = v\" using c unfolding consume_def by (cases vl) auto\n        obtain \"pst\" where v: \"v = PVal pst\" using l unfolding vl1 vl by (cases v) auto\n        have fvll: \"filter isPValS vll = []\"using l unfolding vl1 vl by auto\n        have vl': \"vl' = vll\" using c \\<phi> unfolding vl consume_def by auto\n        hence 0: \"\\<forall>ca. a \\<noteq> COMact ca\" using \\<phi> v f unfolding \\<phi>_def3[OF step] by auto\n        then obtain uid p \"pstt\" where a: \"a = Uact (uPost uid p PID pstt)\"\n        using \\<phi> unfolding \\<phi>_def2(* [OF step] *) by auto\n        hence ss': \"eqButPID s s'\" using step Uact_uPaperC_step_eqButPID by auto\n        hence s's1: \"eqButPID s' s1\" using ss1 eqButPID_sym eqButPID_trans by blast\n        have ?ignore proof\n          show \"\\<not> \\<gamma> ?trn\" using T_\\<phi>_\\<gamma>[OF rsT step \\<phi> 0] .\n          have \"\\<Delta>1 s' vl' s1 vl1\"\n          using PID' s's1' ch1 l s's1 vl1 fvll  unfolding \\<Delta>1_def vl v vl' by auto\n          thus \"?\\<Delta> s' vl' s1 vl1\" by simp\n        qed\n        thus ?thesis by simp\n      next\n        case False note \\<phi> = False\n        have vl': \"vl' = vl\" using \\<phi> c unfolding consume_def by simp\n        have \\<phi>1: \"\\<not> \\<phi> ?trn1\" using step step1 ss1 \\<phi> eqButPID_step_\\<phi> by blast\n        have ?match proof\n          show \"validTrans ?trn1\" using step1 by auto\n          show \"consume ?trn1 vl1 vl1\" using \\<phi>1 unfolding consume_def by simp\n          show \"\\<gamma> ?trn \\<longleftrightarrow> \\<gamma> ?trn1\" by fact\n        next\n          assume \"\\<gamma> ?trn\" note \\<gamma> = this\n          have ou: \"(\\<exists> uid p aid pid. a = COMact (comSendPost uid p aid pid) \\<and> outPurge ou = outPurge ou1) \\<or>\n                                        ou = ou1\"\n          using eqButPID_step_\\<gamma>_out[OF ss1 step step1 rsT T rs1 \\<gamma>] .\n          thus \"g ?trn = g ?trn1\" by (cases a) auto\n        next\n          have 2[simp]: \"post s1' PID  = post s1 PID\"\n            using step1 PID1 \\<phi>1 unfolding \\<phi>_def2(* [OF step1] *)\n            apply(cases a)\n            subgoal for x1 apply(cases x1, auto simp: all_defs) .\n            subgoal for x2 apply(cases x2, auto simp: all_defs) .\n            subgoal for x3 apply(cases x3, auto simp: all_defs) .\n            subgoal for x4 apply(cases x4, auto simp: all_defs) .\n            subgoal by auto\n            subgoal by auto\n            subgoal for x7 apply(cases x7, auto simp: all_defs) .\n            done\n          have \"\\<Delta>1 s' vl' s1' vl1\" using PID' s's1' vlvl1 l ch1\n          unfolding \\<Delta>1_def vl' vl1 by auto\n          thus \"?\\<Delta> s' vl' s1' vl1\" by simp\n        qed\n        thus ?thesis by simp\n      qed\n    qed\n    thus ?thesis using vl1 by simp\n  qed\nqed\n\nlemma unwind_cont_\\<Delta>2: \"unwind_cont \\<Delta>2 {\\<Delta>2}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>2 s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \"\\<Delta>2 s vl s1 vl1\"\n  hence PID: \"PID \\<in>\\<in> postIDs s\" and ss1: \"eqButPID s s1\" and vl: \"vl = []\" and lvl1: \"list_all isPVal vl1\"\n  and rs: \"reach s\" using reachNT_reach unfolding \\<Delta>2_def by auto\n  have PID1: \"PID \\<in>\\<in> postIDs s1\" using eqButPID_stateSelectors[OF ss1] PID by auto\n  have own: \"owner s PID \\<in> set (userIDs s)\" using reach_owner_userIDs[OF rs PID] .\n  hence own1: \"owner s1 PID \\<in> set (userIDs s1)\" using eqButPID_stateSelectors[OF ss1] by auto\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof(cases vl1)\n    case (Cons v1 vll1) note vl1 = Cons\n    obtain pst1 where v1: \"v1 = PVal pst1\" and lvll1: \"list_all isPVal vll1\"\n      using lvl1 unfolding vl1 by (cases v1) auto\n    define uid where \"uid \\<equiv> owner s PID\"  define p where \"p \\<equiv> pass s uid\"\n    define a1 where \"a1 \\<equiv> Uact (uPost uid p PID pst1)\"\n    have uid1: \"uid = owner s1 PID\" and p1: \"p = pass s1 uid\" unfolding uid_def p_def\n    using eqButPID_stateSelectors[OF ss1] by auto\n    obtain ou1 s1' where step1: \"step s1 a1 = (ou1, s1')\" by(cases \"step s1 a1\") auto\n    have ou1: \"ou1 = outOK\" using step1 PID1 own1 unfolding a1_def uid1 p1 by (auto simp: u_defs)\n    have uid: \"uid \\<notin> UIDs\" unfolding uid_def using rsT reachNT_state own PID by blast\n    let ?trn1 = \"Trans s1 a1 ou1 s1'\"\n    have ?iact proof\n      show \"step s1 a1 = (ou1, s1')\" using step1 .\n    next\n      show \\<phi>1: \"\\<phi> ?trn1\" unfolding \\<phi>_def2(* [OF step1] *) a1_def ou1 by simp\n      show \"consume ?trn1 vl1 vll1\"\n      using \\<phi>1 unfolding vl1 consume_def a1_def v1 by simp\n      show \"\\<not> \\<gamma> ?trn1\" using uid unfolding a1_def by simp\n    next\n      have \"eqButPID s1 s1'\" using Uact_uPaperC_step_eqButPID[OF _ step1] a1_def by auto\n      hence ss1': \"eqButPID s s1'\" using eqButPID_trans ss1 by blast\n      show \"\\<Delta>2 s vl s1' vll1\"\n      using PID ss1' lvll1 unfolding \\<Delta>2_def vl by auto\n    qed\n    thus ?thesis by simp\n  next\n    case Nil note vl1 = Nil\n    have ?react proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\"\n      assume step: \"step s a = (ou, s')\" and T: \"\\<not> T ?trn\" and c: \"consume ?trn vl vl'\"\n      obtain ou1 s1' where step1: \"step s1 a = (ou1, s1')\" by fastforce\n      let ?trn1 = \"Trans s1 a ou1 s1'\"\n      have s's1': \"eqButPID s' s1'\" using eqButPID_step ss1 step step1 by blast\n      have \\<gamma>\\<gamma>1: \"\\<gamma> ?trn \\<longleftrightarrow> \\<gamma> ?trn1\" by simp\n      have PID': \"PID \\<in>\\<in> postIDs s'\" using step rs PID using reach_postIDs_persist by blast\n      have \\<phi>: \"\\<not> \\<phi> ?trn\" and vl': \"vl' = vl\" using c unfolding vl consume_def by auto\n      hence \\<phi>1: \"\\<not> \\<phi> ?trn1\" using eqButPID_step_\\<phi> step ss1 step1 by auto\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n      proof-\n        have ?match proof\n          show \"validTrans ?trn1\" using step1 by auto\n          show \"consume ?trn1 vl1 vl1\" using \\<phi>1 unfolding consume_def by simp\n          show \"\\<gamma> ?trn \\<longleftrightarrow> \\<gamma> ?trn1\" by fact\n        next\n          assume \"\\<gamma> ?trn\" note \\<gamma> = this\n          have ou: \"(\\<exists> uid p aid pid. a = COMact (comSendPost uid p aid pid) \\<and> outPurge ou = outPurge ou1) \\<or>\n                                        ou = ou1\"\n          using eqButPID_step_\\<gamma>_out[OF ss1 step step1 rsT T rs1 \\<gamma>] .\n          thus \"g ?trn = g ?trn1\" by (cases a) auto\n        next\n          have 2[simp]: \"textPost (post s1' PID)  = textPost (post s1 PID)\"\n            using step1 PID1 \\<phi>1 unfolding \\<phi>_def2(* [OF step1] *)\n            apply(cases a)\n            subgoal for x1 apply(cases x1, auto simp: all_defs) .\n            subgoal for x2 apply(cases x2, auto simp: all_defs) .\n            subgoal for x3 apply(cases x3, auto simp: all_defs) .\n            subgoal for x4 apply(cases x4, auto simp: all_defs) .\n            subgoal by auto\n            subgoal by auto\n            subgoal for x7 apply(cases x7, auto simp: all_defs) .\n            done\n          show \"\\<Delta>2 s' vl' s1' vl1\" using PID' s's1' vl\n          unfolding \\<Delta>2_def vl1 vl' by auto\n        qed\n        thus ?thesis by simp\n      qed\n    qed\n  thus ?thesis using vl1 by simp\n  qed\nqed\n\ndefinition Gr where\n\"Gr =\n {\n (\\<Delta>0, {\\<Delta>0,\\<Delta>1}),\n (\\<Delta>1, {\\<Delta>1,\\<Delta>2}),\n (\\<Delta>2, {\\<Delta>2})\n }\"\n\n\ntheorem Post_secure: secure\napply (rule unwind_decomp_secure_graph[of Gr \\<Delta>0])\nunfolding Gr_def\napply (simp, smt insert_subset order_refl)\nusing istate_\\<Delta>0 unwind_cont_\\<Delta>0 unwind_cont_\\<Delta>1 unwind_cont_\\<Delta>2\nunfolding Gr_def by auto\n\n\n\nend (* context Post_ISSUER *)\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/CoSMeDis/Post_Confidentiality/Post_ISSUER.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185205547239, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.26754760212736084}}
{"text": "\nsection \"Auxiliary algebraic laws for abrupt designs\"\ntheory algebraic_laws_abrupt_aux\nimports \"../../../theories/Abrupt/utp_abrupt_designs\"\n \nbegin\n\nnamed_theorems uabr_simpl and uabr_cond and uabr_comp and uabr_lens\nsubsection {*THM setup*}\ndeclare design_condr[urel_cond] \n\nsubsection {*abrupt alphabet behavior*}\n\nlemma assigns_abr_alpha:\n  \"(abrupt :== (\\<not> &abrupt)) = (\\<lceil>II\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<and>  $abrupt\\<acute> =\\<^sub>u (\\<not>$abrupt) \\<and> $ok =\\<^sub>u $ok\\<acute>)\"\n  \"(ok :== (\\<not> &ok)) = (\\<lceil>II\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<and>  $abrupt\\<acute> =\\<^sub>u $abrupt \\<and> $ok =\\<^sub>u (\\<not>$ok\\<acute>))\"\n  by rel_auto+\n\nlemma vwb_of_abrupt[simp]: \n  \"vwb_lens ok\" \"vwb_lens abrupt\"\n  by simp_all\n\nlemma unrest_pre_out\\<alpha>_abr[unrest]: \"out\\<alpha> \\<sharp> \\<lceil>b\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\\<^sub><\"\n  by (transfer, auto simp add: out\\<alpha>_def lens_prod_def)\n \nlemma unrest_post_in\\<alpha>_abr[unrest]: \"in\\<alpha> \\<sharp> \\<lceil>b\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\\<^sub>>\"\n  by (transfer, auto simp add: in\\<alpha>_def lens_prod_def)\n\nlemma unrest_ok_abrupt_rel_uexpr_lift_cpa[unrest]:\n  \"$ok \\<sharp> \\<lceil>P\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\" \"$ok\\<acute> \\<sharp> \\<lceil>P\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\"\n  \"$abrupt \\<sharp> \\<lceil>P\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\" \"$abrupt\\<acute> \\<sharp> \\<lceil>P\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\"\n  by (pred_auto)+\n\nlemma unrest_ok_abrupt_rel_usubst_lift_cpa[unrest]:\n  \"$ok\\<acute> \\<sharp> \\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>A\\<^sub>B\\<^sub>R\" \"$ok \\<sharp> \\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>A\\<^sub>B\\<^sub>R\"\n  \"$abrupt\\<acute> \\<sharp> \\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>A\\<^sub>B\\<^sub>R\" \"$abrupt \\<sharp> \\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>A\\<^sub>B\\<^sub>R\"               \n  by rel_auto+\n\nlemma unrest_in_out_rel_ok_abrupt_res_abr [unrest]:\n  \"$ok \\<sharp> (P \\<restriction>\\<^sub>\\<alpha> ok)\" \"$ok\\<acute> \\<sharp> (P \\<restriction>\\<^sub>\\<alpha> ok)\"  \n  \"$abrupt \\<sharp> (P \\<restriction>\\<^sub>\\<alpha> abrupt)\" \"$abrupt\\<acute> \\<sharp> (P \\<restriction>\\<^sub>\\<alpha> abrupt)\"\n  by (simp_all add: rel_var_res_def unrest)\n\nlemma uabr_alphabet_unrest[unrest]:(*FIXEME:These laws should be generated automatically by alphabet backend since all the fields of alphabet are independant*)\n  \"$ok\\<acute> \\<sharp> $abrupt\\<acute>\" \"$ok \\<sharp> $abrupt\"\n  \"$ok\\<acute> \\<sharp> $abrupt\"  \"$ok \\<sharp> $abrupt\\<acute>\"\n  \"$abrupt\\<acute> \\<sharp> $ok\\<acute>\" \"$abrupt \\<sharp> $ok \"\n  \"$abrupt \\<sharp> $ok\\<acute>\"  \"$abrupt\\<acute> \\<sharp> $ok\"\n  by pred_simp+\n\nlemma cpa_ord [usubst]:\n  \"$ok \\<prec>\\<^sub>v $ok\\<acute>\" \"$abrupt \\<prec>\\<^sub>v $abrupt\\<acute>\" \"$ok \\<prec>\\<^sub>v $abrupt\\<acute>\" \n  \"$ok \\<prec>\\<^sub>v $abrupt\" \"$ok\\<acute> \\<prec>\\<^sub>v $abrupt\\<acute>\" \"$ok\\<acute> \\<prec>\\<^sub>v $abrupt\" \n  by (simp_all add: var_name_ord_def)\n\nlemma rel_usubst_lift_cpa_in_out_abrupt_ok[usubst]:\n  \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>A\\<^sub>B\\<^sub>R \\<dagger> $abrupt = $abrupt\" \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>A\\<^sub>B\\<^sub>R \\<dagger> (\\<not>$abrupt) = (\\<not>$abrupt)\"\n  \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>A\\<^sub>B\\<^sub>R \\<dagger> ($ok) = ($ok)\" \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>A\\<^sub>B\\<^sub>R \\<dagger> (\\<not>$ok) = (\\<not>$ok)\" \n  \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>A\\<^sub>B\\<^sub>R \\<dagger> ($abrupt\\<acute>) = (($abrupt\\<acute>))\" \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>A\\<^sub>B\\<^sub>R \\<dagger> (\\<not>$abrupt\\<acute>) = (\\<not>$abrupt\\<acute>)\"\n  \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>A\\<^sub>B\\<^sub>R \\<dagger> ($ok\\<acute>) = ($ok\\<acute>)\"  \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>A\\<^sub>B\\<^sub>R \\<dagger> (\\<not>$ok\\<acute>) = (\\<not>$ok\\<acute>)\" \n  by (simp_all add: usubst unrest)\n\nlemma abrupt_ok_simpl[uabr_comp]:\n  \"($abrupt ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R P) = $abrupt\" \"(\\<not>$ok ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R P) = (\\<not>$ok)\" \n  \"($abrupt ;; (P \\<turnstile> Q)) = $abrupt\" \"(\\<not>$ok ;; (P \\<turnstile> Q)) = (\\<not>$ok)\"\n  \"(\\<not>$abrupt ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R P) = (\\<not>$abrupt)\" \"(\\<not>$ok ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R P) = (\\<not>$ok)\" \n  \"(\\<not>$abrupt ;; (P \\<turnstile> Q)) = (\\<not>$abrupt)\" \"(\\<not>$ok ;; (P \\<turnstile> Q)) = (\\<not>$ok)\"\n  \"($abrupt\\<acute> ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R P) = $abrupt\\<acute>\" \n  \"(\\<not>$abrupt\\<acute> ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R P) = (\\<not>$abrupt\\<acute>)\" \n  by rel_auto+\n\nlemma simpl_abr_in_ok:\n  \"Simpl\\<^sub>A\\<^sub>B\\<^sub>R ($ok) = ((\\<not>$abrupt \\<and> ($ok \\<Rightarrow>$ok\\<acute>)) \\<or> (II))\" \n  by rel_auto\n\nlemma  simpl_abr_our_ok:\n  \"Simpl\\<^sub>A\\<^sub>B\\<^sub>R ($ok\\<acute>) = \n   ((\\<not>$abrupt \\<and> ($ok \\<Rightarrow>$ok\\<acute>)) \\<or> (II))\" \n  by rel_auto\n\nlemma simpl_abr_in_abrupt:\n  \"Simpl\\<^sub>A\\<^sub>B\\<^sub>R ($abrupt) = \n   ((\\<not>$abrupt \\<and> ($ok \\<Rightarrow>($ok\\<acute> \\<and> $abrupt))) \\<or> ($abrupt \\<and> II))\" \n  by rel_auto\n\nlemma simpl_abr_alr_def:\n  \"Simpl\\<^sub>A\\<^sub>B\\<^sub>R (P) = \n   ((\\<not>$abrupt \\<and> ($ok \\<Rightarrow>($ok\\<acute> \\<and> P))) \\<or> ($abrupt \\<and> II))\" \n  by rel_auto\n\nsubsection {*Healthiness condition behavior*}\n\nlemma rel_usubst_cpa_c3_abr[usubst]: \n  assumes \"$ok \\<sharp> \\<sigma>\" \"$ok\\<acute> \\<sharp> \\<sigma> \"\n  shows \"\\<sigma> \\<dagger> C3_abr(P) = (\\<sigma> \\<dagger> P \\<triangleleft> \\<sigma> \\<dagger> (\\<not>$abrupt) \\<triangleright> (\\<sigma> \\<dagger> II))\"\n  using assms unfolding C3_abr_def  \n  by (simp add: usubst) \n\nlemma Simpl_abr_idem[simp]: \"Simpl\\<^sub>A\\<^sub>B\\<^sub>R(Simpl\\<^sub>A\\<^sub>B\\<^sub>R(P)) = Simpl\\<^sub>A\\<^sub>B\\<^sub>R(P)\"\n  by (rel_auto)\n\nlemma simpl_abr_Idempotent: \"Idempotent Simpl\\<^sub>A\\<^sub>B\\<^sub>R\"\n  by (simp add: Idempotent_def)\n\nlemma Simpl_abr_mono: \"P \\<sqsubseteq> Q \\<Longrightarrow> Simpl\\<^sub>A\\<^sub>B\\<^sub>R(P) \\<sqsubseteq> Simpl\\<^sub>A\\<^sub>B\\<^sub>R(Q)\"\n  by (rel_auto)\n\nlemma simpl_abr_Monotonic: \"Monotonic Simpl\\<^sub>A\\<^sub>B\\<^sub>R\"\n  by (simp add: Monotonic_def Simpl_abr_mono)\n\nlemma simpl_abr_def: \n  \"Simpl\\<^sub>A\\<^sub>B\\<^sub>R(P) = ((\\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<turnstile> P) \\<triangleleft> \\<not>$abrupt \\<triangleright>  II)\"\n  unfolding C3_abr_def ..\n\n\nlemma simpl_abr_condr[uabr_simpl]: \n  \"Simpl\\<^sub>A\\<^sub>B\\<^sub>R(P \\<triangleleft> b \\<triangleright> Q) = (Simpl\\<^sub>A\\<^sub>B\\<^sub>R(P) \\<triangleleft> b \\<triangleright> Simpl\\<^sub>A\\<^sub>B\\<^sub>R(Q))\"\n  unfolding simpl_abr_def \n  by (simp add: urel_cond)\n\nlemma simpl_abr_skip_abr[uabr_simpl]: \n  \"Simpl\\<^sub>A\\<^sub>B\\<^sub>R(SKIP\\<^sub>A\\<^sub>B\\<^sub>R) = (SKIP\\<^sub>A\\<^sub>B\\<^sub>R)\"\n  by (simp add: urel_cond urel_defs) \n                    \nlemma simpl_abr_throw_abr: \n  \"Simpl\\<^sub>A\\<^sub>B\\<^sub>R(THROW\\<^sub>A\\<^sub>B\\<^sub>R) = ((\\<not>$abrupt) \\<and> ($ok \\<Rightarrow>($ok\\<acute> \\<and> $abrupt\\<acute> \\<and> \\<lceil>II\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R)) \\<or> ($abrupt \\<and> II))\"\n  by rel_auto\n\nlemma simpl_abr_assign_abr[uabr_simpl]: \n  \"Simpl\\<^sub>A\\<^sub>B\\<^sub>R(\\<langle>\\<sigma>\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R) = (\\<langle>\\<sigma>\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R)\"\n  by (simp add: urel_cond urel_defs)\n\nlemma simpl_abr_throw_abr_comp_abrupt[uabr_simpl]:\n  \"Simpl\\<^sub>A\\<^sub>B\\<^sub>R (THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; ((abrupt:== (\\<not> &abrupt) ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R Q) \\<triangleleft> $abrupt \\<triangleright> II)) = Simpl\\<^sub>A\\<^sub>B\\<^sub>R Q\" \n   apply pred_simp\n   apply rel_simp \n   apply auto \ndone\n\nlemma simpl_abr_throw_abr_comp_abrupt_cond_throw_abr[uabr_simpl]:\n  \"Simpl\\<^sub>A\\<^sub>B\\<^sub>R (THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; ((abrupt:== (\\<not> &abrupt) ;; THROW\\<^sub>A\\<^sub>B\\<^sub>R) \\<triangleleft> $abrupt \\<triangleright> II)) = Simpl\\<^sub>A\\<^sub>B\\<^sub>R THROW\\<^sub>A\\<^sub>B\\<^sub>R\" \n   apply pred_simp\n   apply rel_simp \n   apply auto \ndone\n\nlemma simpl_abr_throw_abr_comp_abrupt_cond_skip_abr[uabr_simpl]:\n  \"Simpl\\<^sub>A\\<^sub>B\\<^sub>R (THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; ((abrupt:== (\\<not> &abrupt) ;; SKIP\\<^sub>A\\<^sub>B\\<^sub>R) \\<triangleleft> $abrupt \\<triangleright> II)) = SKIP\\<^sub>A\\<^sub>B\\<^sub>R\" \n   apply pred_simp\n   apply rel_simp \n   apply auto \ndone\n \nlemma simpl_abr_throw_abr_comp_abrupt_cond_assigns_abr[uabr_simpl]:\n  \"Simpl\\<^sub>A\\<^sub>B\\<^sub>R (THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; ((abrupt:== (\\<not> &abrupt) ;; \\<langle>\\<sigma>\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R) \\<triangleleft> $abrupt \\<triangleright> II)) = \\<langle>\\<sigma>\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R\" \n   apply pred_simp\n   apply rel_simp \n   apply auto \ndone\n\nlemma C3_abr_throw_abr_comp_abrupt[uabr_simpl]: \n  \"C3_abr (THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; ((abrupt:== (\\<not> &abrupt) ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R Q) \\<triangleleft> $abrupt \\<triangleright> II)) = \n    Simpl\\<^sub>A\\<^sub>B\\<^sub>R Q\"\n  apply pred_simp\n  apply rel_simp \n  apply safe\n  apply auto\ndone\n\nlemma C3_abr_throw_abr_comp_abrupt_cond_skip_abr[uabr_simpl]: \n  \"C3_abr (THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; ((abrupt:== (\\<not> &abrupt) ;; SKIP\\<^sub>A\\<^sub>B\\<^sub>R) \\<triangleleft> $abrupt \\<triangleright> II)) = \n    SKIP\\<^sub>A\\<^sub>B\\<^sub>R\"\n  apply pred_simp\n  apply rel_simp \n  apply safe\n  apply auto\ndone\n\nlemma C3_abr_throw_abr_comp_abrupt_cond_throw_abr[uabr_simpl]: \n  \"C3_abr (THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; ((abrupt:== (\\<not> &abrupt) ;; THROW\\<^sub>A\\<^sub>B\\<^sub>R) \\<triangleleft> $abrupt \\<triangleright> II)) = \n    C3_abr THROW\\<^sub>A\\<^sub>B\\<^sub>R\"\n  apply pred_simp\n  apply rel_simp \n  apply safe\n  apply auto\ndone\n\nlemma C3_abr_throw_abr_comp_abrupt_cond_assigns_abr[uabr_simpl]: \n  \"C3_abr (THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; ((abrupt:== (\\<not> &abrupt) ;; \\<langle>\\<sigma>\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R) \\<triangleleft> $abrupt \\<triangleright> II)) = \n    \\<langle>\\<sigma>\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R\"\n  apply pred_simp\n  apply rel_simp \n  apply safe\n  apply auto \ndone\n\n(*lemma [uabr_comp]:\n  \"(THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; ((abrupt:== (\\<not> &abrupt) ;; THROW\\<^sub>A\\<^sub>B\\<^sub>R) \\<triangleleft> $abrupt \\<triangleright> II)) = \n   (\\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<turnstile> ($abrupt\\<acute> \\<and> \\<lceil>II\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R)) \"\n  apply pred_simp\n  apply rel_simp \n  apply safe\n  apply auto\ndone\n\nlemma throw_abr_comp_abrupt_cond_skip_abr[uabr_comp]:\n  \"(THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; ((abrupt:== (\\<not> &abrupt) ;; SKIP\\<^sub>A\\<^sub>B\\<^sub>R) \\<triangleleft> $abrupt \\<triangleright> II)) = \n   (\\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<turnstile> (\\<not>$abrupt\\<acute> \\<and> \\<lceil>II\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R)) \"\n  apply pred_simp\n  apply rel_simp\n  apply safe\n  apply auto \ndone\n\n\nlemma [uabr_comp]:\n  \"(THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; ((abrupt:== (\\<not> &abrupt) ;; \\<langle>\\<sigma>\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R) \\<triangleleft> $abrupt \\<triangleright> II)) = \n   (\\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<turnstile> (\\<not>$abrupt\\<acute> \\<and> \\<lceil>\\<langle>\\<sigma>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R)) \"\n  apply pred_simp\n  apply rel_simp \n  apply safe\n  apply auto \ndone*)\n\nlemma [uabr_comp]:\n  \"(THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; ((abrupt:== (\\<not> &abrupt) ;; \\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R) \\<triangleleft> $abrupt \\<triangleright> II)) = (true) \"\n  apply pred_simp\n  apply rel_simp \n  apply auto \ndone\n\n\nlemma simpl_abr_form: \n  \"Simpl\\<^sub>A\\<^sub>B\\<^sub>R(P) = (((\\<not>$abrupt) \\<and> (\\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<turnstile> (P)))  \\<or> ($abrupt \\<and> II))\"\n  by rel_auto \n\nlemma abrupt_simpl_abr[uabr_simpl]:\n  \"($abrupt \\<and> Simpl\\<^sub>A\\<^sub>B\\<^sub>R(P)) = ($abrupt \\<and>II)\"\n   by rel_auto\n\nlemma nabrupt_simpl_abr[uabr_simpl]:\n  \"(\\<not>$abrupt \\<and> Simpl\\<^sub>A\\<^sub>B\\<^sub>R(P)) = (\\<not>$abrupt \\<and> (\\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<turnstile> (P)))\"\n  by (rel_auto)\n\ndefinition design_abr_sup :: \"('\\<alpha>,'\\<beta>) rel_cpa set \\<Rightarrow> ('\\<alpha>,'\\<beta>) rel_cpa\" (\"\\<Sqinter>\\<^sub>A\\<^sub>B\\<^sub>R_\" [900] 900) where\n\"\\<Sqinter>\\<^sub>A\\<^sub>B\\<^sub>R A = (if (A = {}) then \\<top>\\<^sub>A\\<^sub>B\\<^sub>R else \\<Sqinter> A)\"\n\nlemma simpl_abr_Continuous: \"Continuous Simpl\\<^sub>A\\<^sub>B\\<^sub>R\"\n  unfolding Continuous_def SUP_def apply rel_simp\n  unfolding  SUP_def \n  apply transfer apply auto \ndone\n\nlemma simpl_abr_R3_conj: \n  \"Simpl\\<^sub>A\\<^sub>B\\<^sub>R(P \\<and> Q) = (Simpl\\<^sub>A\\<^sub>B\\<^sub>R(P) \\<and> Simpl\\<^sub>A\\<^sub>B\\<^sub>R(Q))\"\n  by (rel_auto)\n\nlemma simpl_abr_disj: \n  \"Simpl\\<^sub>A\\<^sub>B\\<^sub>R(P \\<or> Q) = (Simpl\\<^sub>A\\<^sub>B\\<^sub>R(P) \\<or> Simpl\\<^sub>A\\<^sub>B\\<^sub>R(Q))\"\n  by (rel_auto)\n\nlemma Simpl_abr_USUP:\n  assumes \"A \\<noteq> {}\"\n  shows \"Simpl\\<^sub>A\\<^sub>B\\<^sub>R(\\<Sqinter> i \\<in> A \\<bullet> P(i)) = (\\<Sqinter> i \\<in> A \\<bullet> Simpl\\<^sub>A\\<^sub>B\\<^sub>R(P(i)))\"\n  using assms by (rel_auto)\n\nlemma design_abr_sup_non_empty [simp]:  \n  \"A \\<noteq> {} \\<Longrightarrow> \\<Sqinter>\\<^sub>A\\<^sub>B\\<^sub>R A = \\<Sqinter> A\"\n  by (simp add: design_abr_sup_def)\n\nsubsection {*Signature behavior*}\n\nlemma design_top_abr:\n  \"(P \\<turnstile> Q) \\<sqsubseteq> \\<top>\\<^sub>A\\<^sub>B\\<^sub>R\"\n  by (rel_auto)\n\nlemma design_abr_sup_empty [simp]: \n  \"\\<Sqinter>\\<^sub>A\\<^sub>B\\<^sub>R {} = \\<top>\\<^sub>A\\<^sub>B\\<^sub>R\"\n  by (simp add: design_abr_sup_def)\n\n\nabbreviation design_inf :: \"('\\<alpha>, '\\<beta>) rel_des set \\<Rightarrow> ('\\<alpha>, '\\<beta>) rel_des\" (\"\\<Squnion>\\<^sub>A\\<^sub>B\\<^sub>R_\" [900] 900) where\n\"\\<Squnion>\\<^sub>A\\<^sub>B\\<^sub>R A \\<equiv> \\<Squnion> A\"\n\nlemma design_bottom_abr:\n  \"\\<bottom>\\<^sub>A\\<^sub>B\\<^sub>R \\<sqsubseteq> (P \\<turnstile> Q)\"\n  by simp\n\nlemma Simpl_abr_bottom_abr:\n  \"\\<bottom>\\<^sub>A\\<^sub>B\\<^sub>R \\<sqsubseteq> Simpl\\<^sub>A\\<^sub>B\\<^sub>R (P)\"\n  by simp\n\nlemma Simpl_abr_UINF:\n  assumes \"A \\<noteq> {}\"\n  shows \"Simpl\\<^sub>A\\<^sub>B\\<^sub>R(\\<Squnion> i \\<in> A \\<bullet> P(i)) = (\\<Squnion> i \\<in> A \\<bullet> Simpl\\<^sub>A\\<^sub>B\\<^sub>R(P(i)))\"\n  using assms by (rel_auto)\n\nlemma skip_cpa_def:\n  \"II = (\\<lceil>II\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<and> $abrupt =\\<^sub>u $abrupt\\<acute> \\<and> $ok =\\<^sub>u $ok\\<acute>)\" \n  by rel_auto\n\nlemma skip_lift_cpa_def:\n  \"\\<lceil>II\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R = ($\\<Sigma>\\<^sub>A\\<^sub>B\\<^sub>R\\<acute> =\\<^sub>u $\\<Sigma>\\<^sub>A\\<^sub>B\\<^sub>R)\"\n  by rel_auto\n\nlemma seqr_abrupt_true [usubst]: \"(P ;; Q) \\<^sub>a\\<^sub>t = (P \\<^sub>a\\<^sub>t ;; Q)\"\n  by (rel_auto)\n\nlemma seqr_abrupt_false [usubst]: \"(P ;; Q) \\<^sub>a\\<^sub>f = (P \\<^sub>a\\<^sub>f ;; Q)\"\n  by (rel_auto)\n\nlemma rel_usubst_lift_cpa_uexpr_lift_cpa[usubst]:\n  \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>A\\<^sub>B\\<^sub>R \\<dagger> \\<lceil>P\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R = \\<lceil>\\<sigma> \\<dagger> P\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\" \n  by rel_auto\n\nlemma usubst_lift_cpa_assigns_lift_cpa [usubst]:\n  \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>s\\<^sub>A\\<^sub>B\\<^sub>R \\<dagger> \\<lceil>\\<langle>\\<rho>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R = \\<lceil>\\<langle>\\<rho> \\<circ> \\<sigma>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\" \n  by (simp add: usubst)\n\nlemma usubst_lift_cpa_pre_uexpr_lift_cpa[usubst]:\n  \"\\<lceil>\\<sigma>\\<rceil>\\<^sub>s\\<^sub>A\\<^sub>B\\<^sub>R \\<dagger> \\<lceil>b\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\\<^sub>< = \\<lceil>\\<sigma> \\<dagger> b\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\\<^sub><\" \n  by (simp add: usubst)\n\nlemma rel_usubst_lift_cpa_design[usubst]: \n  \"(\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>A\\<^sub>B\\<^sub>R \\<dagger> (Q \\<turnstile> P)) = (\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>A\\<^sub>B\\<^sub>R \\<dagger> Q) \\<turnstile> (\\<lceil>\\<sigma>\\<rceil>\\<^sub>S\\<^sub>A\\<^sub>B\\<^sub>R \\<dagger> P)\"\n  by (simp add: usubst unrest)\n\nlemma usubst_cpa_true[usubst]: \"\\<sigma> \\<dagger> \\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R = \\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\" \n  by rel_auto\n\nlemma usubst_cpa_false[usubst]: \"\\<sigma> \\<dagger> \\<lceil>false\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R = \\<lceil>false\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\" \n  by rel_auto\n\nlemma rel_usubst_cpa_skip_cpa[usubst]: \n  \"(\\<sigma> \\<dagger> II) = ((\\<sigma> \\<dagger> \\<lceil>II\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R) \\<and> \\<sigma> \\<dagger> $abrupt =\\<^sub>u \\<sigma> \\<dagger> $abrupt\\<acute> \\<and> \\<sigma> \\<dagger> $ok =\\<^sub>u \\<sigma> \\<dagger> $ok\\<acute>)\" \n  by (simp add: usubst unrest skip_cpa_def)\n\nlemma usubst_lift_cpa_skip_lift_cpa[usubst]: \n  \"(\\<lceil>\\<sigma>\\<rceil>\\<^sub>s\\<^sub>A\\<^sub>B\\<^sub>R \\<dagger> \\<lceil>II\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R) = \\<lceil>\\<langle>\\<sigma>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\" \n  unfolding skip_r_def\n  by (simp add: usubst_lift_cpa_assigns_lift_cpa)\n\nlemma usubst_cpa_skip_cpa [usubst]:\n  assumes \"$ok \\<sharp> \\<sigma>\" \"$ok\\<acute> \\<sharp> \\<sigma> \"\n  shows \n  \"(\\<sigma> \\<dagger> SKIP\\<^sub>A\\<^sub>B\\<^sub>R) = (\\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<turnstile> (\\<sigma> \\<dagger> ((\\<not>$abrupt\\<acute>) \\<and> \\<lceil>II\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R)) \\<triangleleft> \\<sigma> \\<dagger> (\\<not>$abrupt) \\<triangleright> (\\<sigma> \\<dagger> (II)))\"\n  using assms unfolding skip_abr_def \n  using [[simp_trace]]\n  by (simp add: usubst) \n\nlemma usubst_cpa_throw_cpa [usubst]:\n  assumes \"$ok \\<sharp> \\<sigma>\" \"$ok\\<acute> \\<sharp> \\<sigma> \"\n  shows \n  \"(\\<sigma> \\<dagger> THROW\\<^sub>A\\<^sub>B\\<^sub>R) = (\\<sigma> \\<dagger> (\\<not>$abrupt) \\<turnstile> (\\<sigma> \\<dagger> ($abrupt\\<acute> \\<and> \\<lceil>II\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R)))\"\n  using assms unfolding throw_abr_def \n  by (simp add: usubst) \n\nlemma usubst_cpa_assigns_cpa [usubst]:\n  assumes \"$ok \\<sharp> \\<sigma>\" \"$ok\\<acute> \\<sharp> \\<sigma> \"\n  shows \n  \"\\<sigma> \\<dagger> \\<langle>\\<rho>\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R = (\\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<turnstile> (\\<sigma> \\<dagger> ((\\<not>$abrupt\\<acute>) \\<and> \\<lceil>\\<langle>\\<rho>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R)) \\<triangleleft> \\<sigma> \\<dagger> (\\<not>$abrupt) \\<triangleright>  (\\<sigma> \\<dagger> (II)))\"  \n  using assms unfolding assigns_abr_def\n  by (simp add: usubst)\n\nlemma simpl_comp_left_distr:\n  \"(C3_abr (P) ;; R) = ((P;;R) \\<triangleleft> \\<not>$abrupt \\<triangleright> (II ;; R))\"\n  apply pred_simp\n  apply rel_simp\n  apply fastforce\ndone\n\nlemma c3_abr_comp_semir:\n  \"(C3_abr(P) ;; C3_abr(R)) = C3_abr (P ;; C3_abr(R))\"\n  by rel_auto\n\nlemma c3_abr_comp_simpl[uabr_comp]:\n  \"(C3_abr(P) ;; C3_abr(R)) = ((P ;; C3_abr(R)) \\<triangleleft> \\<not>$abrupt \\<triangleright> (II))\"\n  by rel_auto\n\nlemma simpl_abr_comp_semir:\n  \"(Simpl\\<^sub>A\\<^sub>B\\<^sub>R(P) ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R(R)) = Simpl\\<^sub>A\\<^sub>B\\<^sub>R ((\\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<turnstile> P) ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R(R))\"\n  by rel_auto\n\ntheorem design_top_abr_left_zero[uabr_comp]: \n  \"(\\<top>\\<^sub>A\\<^sub>B\\<^sub>R ;; (P \\<turnstile> Q)) = \\<top>\\<^sub>A\\<^sub>B\\<^sub>R\"\n  by (rel_auto)\n\ntheorem Simpl_abr_top_abr_left_zero[uabr_comp]: \n  \"(\\<top>\\<^sub>A\\<^sub>B\\<^sub>R ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R (P)) = \\<top>\\<^sub>A\\<^sub>B\\<^sub>R\"\n  by (rel_auto)\n\nlemma assigns_lift_cpa_comp_rel_cpa[uabr_comp]:\n  assumes \"$ok \\<sharp> P\" \"$abrupt \\<sharp> P\"\n  shows  \"(\\<lceil>\\<langle>\\<sigma>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R ;; P) = (\\<lceil>\\<sigma>\\<rceil>\\<^sub>s\\<^sub>A\\<^sub>B\\<^sub>R \\<dagger> P)\"\n  apply (insert assms)\n  apply pred_simp \n  apply rel_blast \ndone\n\nlemma lift_des_skip_dr_unit_abr [uabr_comp]:\n  \"(\\<lceil>P\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R ;; \\<lceil>II\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R) = \\<lceil>P\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\"\n  \"(\\<lceil>II\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R ;; \\<lceil>P\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R) = \\<lceil>P\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\"\n  by (rel_auto)+\n\nlemma skip_cpa_left_comp_simpl[uabr_comp]:\n  \"(SKIP\\<^sub>A\\<^sub>B\\<^sub>R ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R(R)) = (Simpl\\<^sub>A\\<^sub>B\\<^sub>R(R))\"\n  by rel_auto\n\nlemma skip_cpa_right_comp_simpl[uabr_comp]:\n  \"(Simpl\\<^sub>A\\<^sub>B\\<^sub>R(R) ;; SKIP\\<^sub>A\\<^sub>B\\<^sub>R) = (Simpl\\<^sub>A\\<^sub>B\\<^sub>R(R))\"\n  by rel_auto\n\nlemma throw_cpa_left_comp_simpl[uabr_comp]:\n  \"(THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R(R)) = (THROW\\<^sub>A\\<^sub>B\\<^sub>R)\"\n  by rel_auto\n\nlemma assign_abr_alt_def: \n  \"\\<langle>\\<sigma>\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R = Simpl\\<^sub>A\\<^sub>B\\<^sub>R (\\<not>$abrupt\\<acute> \\<and> \\<lceil>\\<lceil>\\<sigma>\\<rceil>\\<^sub>s \\<dagger> II\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R)\"\n  by rel_auto\n\nlemma assign_abr_left_comp_c3[uabr_comp]:\n  \"\\<langle>a\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R ;; C3_abr (P \\<turnstile> Q) = C3_abr (\\<lceil>a\\<rceil>\\<^sub>s\\<^sub>A\\<^sub>B\\<^sub>R \\<dagger> (P \\<turnstile>  Q))\"\n  by rel_auto\n\n\nlemma assigns_abr_comp[uabr_comp]: \n  \"(\\<langle>f\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R ;; \\<langle>g\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R) = \\<langle>g \\<circ> f\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R\"\n  by rel_auto\n\nlemma usubst_cpa_des_cond_abr [usubst]:\n  \"\\<lbrakk>$ok \\<sharp> \\<sigma>; $ok\\<acute> \\<sharp> \\<sigma> \\<rbrakk> \\<Longrightarrow> \n    \\<sigma> \\<dagger> (R \\<turnstile> bif b then P else Q eif) = \n    (\\<sigma> \\<dagger> R \\<turnstile>  (\\<sigma> \\<dagger> P \\<triangleleft> \\<sigma> \\<dagger> \\<lceil>b\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\\<^sub>< \\<triangleright> \\<sigma> \\<dagger> Q))\"\n  by (simp add: usubst)\n\nlemma comp_cond_abr_left_distr[uabr_comp]:\n  \"((bif b then Simpl\\<^sub>A\\<^sub>B\\<^sub>R P else Simpl\\<^sub>A\\<^sub>B\\<^sub>R Q eif) ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R R) = \n    (bif b then (Simpl\\<^sub>A\\<^sub>B\\<^sub>R P ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R R) else (Simpl\\<^sub>A\\<^sub>B\\<^sub>R Q ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R R) eif)\"\n  apply (simp add: usubst uabr_comp)\n  apply pred_simp \n  apply rel_simp\n  apply auto\ndone\n\n\nlemma if_mono:\n  \"\\<lbrakk> P\\<^sub>1 \\<sqsubseteq> P\\<^sub>2; Q\\<^sub>1 \\<sqsubseteq> Q\\<^sub>2 \\<rbrakk> \\<Longrightarrow> (bif b then P\\<^sub>1 else Q\\<^sub>1 eif) \\<sqsubseteq> (bif b then P\\<^sub>2 else Q\\<^sub>2 eif)\"\n  by rel_auto\n\n\n\nsubsection {*While abrupt usubst*}\n\nsubsection {*block abrupt usubst*}\n\nsubsection {*Catch abrupt usubst*}\n\nend", "meta": {"author": "git-vt", "repo": "orca", "sha": "92bda0f9cfe5cc680b9c405fc38f07a960087a36", "save_path": "github-repos/isabelle/git-vt-orca", "path": "github-repos/isabelle/git-vt-orca/orca-92bda0f9cfe5cc680b9c405fc38f07a960087a36/Archive/Programming-Languages-Semantics/WP11-C-semantics/src/IMP-Lenses/hoare/AlgebraicLaws/Abrupt/algebraic_laws_abrupt_aux.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185205547239, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.2675476021273608}}
{"text": "(*******************************************************************************\n \n  Project: IsaNet\n\n  Author:  Tobias Klenze, ETH Zurich <tobias.klenze@inf.ethz.ch>\n           Christoph Sprenger, ETH Zurich <sprenger@inf.ethz.ch>\n  Version: JCSPaper.1.0\n  Isabelle Version: Isabelle2021-1\n\n  Copyright (c) 2022 Tobias Klenze, Christoph Sprenger\n  Licence: Mozilla Public License 2.0 (MPL) / BSD-3-Clause (dual license)\n\n*******************************************************************************)\n\nsection\\<open>Network Assumptions used for authorized segments.\\<close>\ntheory Network_Assumptions\n  imports\n    \"Network_Model\"\nbegin\n\nlocale network_assums_generic = network_model _ auth_seg0 for\n   auth_seg0 :: \"('ainfo \\<times> 'aahi ahi_scheme list) set\" +\n assumes\n\\<comment> \\<open>All authorized segments have valid interfaces\\<close>\n    ASM_if_valid: \"(info, l) \\<in> auth_seg0 \\<Longrightarrow> ifs_valid_None l\" and\n\\<comment> \\<open>All authorized segments are rooted, i.e., they start with None\\<close>\n    ASM_empty [simp, intro!]: \"(info, []) \\<in> auth_seg0\" and\n    ASM_rooted: \"(info, l) \\<in> auth_seg0 \\<Longrightarrow> rooted l\" and\n    ASM_terminated: \"(info, l) \\<in> auth_seg0 \\<Longrightarrow> terminated l\"\n\nlocale network_assums_undirect = network_assums_generic _ _ +\n  assumes\n    ASM_adversary: \"\\<lbrakk>\\<And>hf. hf \\<in> set hfs \\<Longrightarrow> ASID hf \\<in> bad\\<rbrakk> \\<Longrightarrow> (info, hfs) \\<in> auth_seg0\"\n\nlocale network_assums_direct = network_assums_generic _ _ +\n  assumes\n    ASM_singleton: \"\\<lbrakk>ASID hf \\<in> bad\\<rbrakk> \\<Longrightarrow> (info, [hf]) \\<in> auth_seg0\" and\n    ASM_extension: \"\\<lbrakk>(info, hf2#ys) \\<in> auth_seg0; ASID hf2 \\<in> bad; ASID hf1 \\<in> bad\\<rbrakk>\n                    \\<Longrightarrow> (info, hf1#hf2#ys) \\<in> auth_seg0\" and\n    ASM_modify: \"\\<lbrakk>(info, hf#ys) \\<in> auth_seg0; ASID hf = a; ASID hf' = a; UpIF hf' = UpIF hf; a \\<in> bad\\<rbrakk> \n                  \\<Longrightarrow> (info, hf'#ys) \\<in> auth_seg0\" and\n    ASM_cutoff: \"\\<lbrakk>(info, zs@hf#ys) \\<in> auth_seg0; ASID hf = a; a \\<in> bad\\<rbrakk> \\<Longrightarrow> (info, hf#ys) \\<in> auth_seg0\"\nbegin\n\nlemma auth_seg0_non_empty [simp, intro!]: \"auth_seg0 \\<noteq> {}\"\n  by auto\n\nlemma auth_seg0_non_empty_frag [simp, intro!]: \"\\<exists> info . pfragment info [] auth_seg0\"\n  apply(auto simp add: pfragment_def)\n  by (metis append_Nil2 ASM_empty)\n\ntext \\<open>This lemma applies the extendability assumptions on @{text \"auth_seg0\"} to pfragments of \n@{text \"auth_seg0\"}.\\<close>\nlemma extend_pfragment0:\n  assumes \"pfragment ainfo (hf2#xs) auth_seg0\"\n  assumes \"ASID hf1 \\<in> bad\"\n  assumes \"ASID hf2 \\<in> bad\"\n  shows \"pfragment ainfo (hf1#hf2#xs) auth_seg0\"\n  using assms\n  by(auto intro!: pfragmentI[of _ \"[]\" _ _] elim!: pfragmentE intro: ASM_cutoff intro!: ASM_extension)\n\ntext\\<open>This lemma shows that the above assumptions imply that of the undirected setting\\<close>\nlemma \"\\<lbrakk>\\<And>hf. hf \\<in> set hfs \\<Longrightarrow> ASID hf \\<in> bad\\<rbrakk> \\<Longrightarrow> (info, hfs) \\<in> auth_seg0\"\n  apply(induction hfs)\n  using ASM_empty apply blast\n  subgoal for a hfs\n    apply(cases hfs)\n    by(auto intro!: ASM_singleton ASM_extension)\n  done\n\nend\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/IsaNet/Network_Assumptions.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.600188359260205, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.26740164063736316}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      HoarePartial.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer\nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection \\<open>Properties of Total Correctness Hoare Logic\\<close>\n\ntheory HoareTotalProps imports SmallStep HoareTotalDef HoarePartialProps begin\n\nsubsection \\<open>Soundness\\<close>\n\nlemma hoaret_sound:\n assumes hoare: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nusing hoare\nproof (induct)\n  case (Skip \\<Theta> F P A)\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Skip P,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Skip,Normal s\\<rangle> \\<Rightarrow> t\" \"s \\<in> P\"\n    thus \"t \\<in> Normal ` P \\<union> Abrupt ` A\"\n      by cases auto\n  next\n    fix s show \"\\<Gamma>\\<turnstile>Skip \\<down> Normal s\"\n      by (rule terminates.intros)\n  qed\nnext\n  case (Basic \\<Theta> F f P A)\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. f s \\<in> P} (Basic f) P,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Basic f,Normal s\\<rangle> \\<Rightarrow> t\" \"s \\<in> {s. f s \\<in> P}\"\n    thus \"t \\<in> Normal ` P \\<union> Abrupt ` A\"\n      by cases auto\n  next\n    fix s show \"\\<Gamma>\\<turnstile>Basic f \\<down> Normal s\"\n      by (rule terminates.intros)\n  qed\nnext\n  case (Spec \\<Theta> F r Q A)\n  show \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. (\\<forall>t. (s, t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s, t) \\<in> r)} Spec r Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Spec r ,Normal s\\<rangle> \\<Rightarrow> t\"\n           \"s \\<in> {s. (\\<forall>t. (s, t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s, t) \\<in> r)}\"\n    thus \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by cases auto\n  next\n    fix s show \"\\<Gamma>\\<turnstile>Spec r \\<down> Normal s\"\n      by (rule terminates.intros)\n  qed\nnext\n  case (Seq \\<Theta> F P c1 R A c2 Q)\n  have valid_c1: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c1 R,A\" by fact\n  have valid_c2: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c2 Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Seq c1 c2 Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal s\\<rangle> \\<Rightarrow> t\"\n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    from exec P obtain r where\n      exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> r\" and exec_c2:  \"\\<Gamma>\\<turnstile>\\<langle>c2,r\\<rangle> \\<Rightarrow> t\"\n      by cases auto\n    with t_notin_F have \"r \\<notin> Fault ` F\"\n      by (auto dest: Fault_end)\n    from valid_c1 ctxt exec_c1 P this\n    have r: \"r \\<in> Normal ` R \\<union> Abrupt ` A\"\n      by (rule cvalidt_postD)\n    show \"t\\<in>Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases r)\n      case (Normal r')\n      with exec_c2 r\n      show \"t\\<in>Normal ` Q \\<union> Abrupt ` A\"\n        apply -\n        apply (rule cvalidt_postD [OF valid_c2 ctxt _ _ t_notin_F])\n        apply auto\n        done\n    next\n      case (Abrupt r')\n      with exec_c2 have \"t=Abrupt r'\"\n        by (auto elim: exec_elim_cases)\n      with Abrupt r show ?thesis\n        by auto\n    next\n      case Fault with r show ?thesis by blast\n    next\n      case Stuck with r show ?thesis by blast\n    qed\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s\\<in>P\"\n    show \"\\<Gamma>\\<turnstile>Seq c1 c2 \\<down> Normal s\"\n    proof -\n      from valid_c1 ctxt P\n      have \"\\<Gamma>\\<turnstile>c1\\<down> Normal s\"\n        by (rule cvalidt_termD)\n      moreover\n      {\n        fix r assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> r\"\n        have \"\\<Gamma>\\<turnstile>c2 \\<down> r\"\n        proof (cases r)\n          case (Normal r')\n          with cvalidt_postD [OF valid_c1 ctxt exec_c1 P]\n          have r: \"r\\<in>Normal ` R\"\n            by auto\n          with cvalidt_termD [OF valid_c2 ctxt] exec_c1\n          show \"\\<Gamma>\\<turnstile>c2 \\<down> r\"\n            by auto\n        qed auto\n      }\n      ultimately show ?thesis\n        by (iprover intro: terminates.intros)\n    qed\n  qed\nnext\n  case (Cond \\<Theta> F P b c1 Q A c2)\n  have valid_c1: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> b) c1 Q,A\" by fact\n  have valid_c2: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> - b) c2 Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Cond b c1 c2 Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow> t\"\n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases \"s\\<in>b\")\n      case True\n      with exec have \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> t\"\n        by cases auto\n      with P True\n      show ?thesis\n        by - (rule cvalidt_postD [OF valid_c1 ctxt _ _ t_notin_F],auto)\n    next\n      case False\n      with exec P have \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal s\\<rangle> \\<Rightarrow> t\"\n        by cases auto\n      with P False\n      show ?thesis\n        by - (rule cvalidt_postD [OF valid_c2 ctxt _ _ t_notin_F],auto)\n    qed\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s \\<in> P\"\n    thus \"\\<Gamma>\\<turnstile>Cond b c1 c2 \\<down> Normal s\"\n      using cvalidt_termD [OF valid_c1 ctxt] cvalidt_termD [OF valid_c2 ctxt]\n      by (cases \"s \\<in> b\") (auto intro: terminates.intros)\n  qed\nnext\n  case (While r \\<Theta> F P b c A)\n  assume wf: \"wf r\"\n  have valid_c: \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P \\<inter> b) c ({t. (t, \\<sigma>) \\<in> r} \\<inter> P),A\"\n    using While.hyps by iprover\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (While b c) (P \\<inter> - b),A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume wprems: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow> t\" \"s \\<in> P\" \"t \\<notin> Fault ` F\"\n    from wf\n    have \"\\<And>t. \\<lbrakk>\\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow> t; s \\<in> P; t \\<notin> Fault ` F\\<rbrakk>\n                 \\<Longrightarrow> t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\"\n    proof (induct)\n      fix s t\n      assume hyp:\n        \"\\<And>s' t. \\<lbrakk>(s',s)\\<in>r; \\<Gamma>\\<turnstile>\\<langle>While b c,Normal s'\\<rangle> \\<Rightarrow> t; s' \\<in> P; t \\<notin> Fault ` F\\<rbrakk>\n                 \\<Longrightarrow> t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\"\n      assume exec: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow> t\"\n      assume P: \"s \\<in> P\"\n      assume t_notin_F: \"t \\<notin> Fault ` F\"\n      from exec\n      show \"t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\"\n      proof (cases)\n        fix s'\n        assume b: \"s\\<in>b\"\n        assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> s'\"\n        assume exec_w: \"\\<Gamma>\\<turnstile>\\<langle>While b c,s'\\<rangle> \\<Rightarrow> t\"\n        from exec_w t_notin_F have \"s' \\<notin> Fault ` F\"\n          by (auto dest: Fault_end)\n        from exec_c P b valid_c ctxt this\n        have s': \"s' \\<in> Normal ` ({s'. (s', s) \\<in> r} \\<inter> P) \\<union> Abrupt ` A\"\n          by (auto simp add: cvalidt_def validt_def valid_def)\n        show ?thesis\n        proof (cases s')\n          case Normal\n          with exec_w s' t_notin_F\n          show ?thesis\n            by - (rule hyp,auto)\n        next\n          case Abrupt\n          with exec_w have \"t=s'\"\n            by (auto dest: Abrupt_end)\n          with Abrupt s' show ?thesis\n            by blast\n        next\n          case Fault\n          with exec_w have \"t=s'\"\n            by (auto dest: Fault_end)\n          with Fault s' show ?thesis\n            by blast\n        next\n          case Stuck\n          with exec_w have \"t=s'\"\n            by (auto dest: Stuck_end)\n          with Stuck s' show ?thesis\n            by blast\n        qed\n      next\n        assume \"s\\<notin>b\" \"t=Normal s\" with P show ?thesis by simp\n      qed\n    qed\n    with wprems show \"t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\" by blast\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume \"s \\<in> P\"\n    with wf\n    show \"\\<Gamma>\\<turnstile>While b c \\<down> Normal s\"\n    proof (induct)\n      fix s\n      assume hyp: \"\\<And>s'. \\<lbrakk>(s',s)\\<in>r; s' \\<in> P\\<rbrakk>\n                         \\<Longrightarrow> \\<Gamma>\\<turnstile>While b c \\<down> Normal s'\"\n      assume P: \"s \\<in> P\"\n      show \"\\<Gamma>\\<turnstile>While b c \\<down> Normal s\"\n      proof (cases \"s \\<in> b\")\n        case False with P show ?thesis\n          by (blast intro: terminates.intros)\n      next\n        case True\n        with valid_c P ctxt\n        have \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n          by (simp add: cvalidt_def validt_def)\n        moreover\n        {\n          fix s'\n          assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> s'\"\n          have \"\\<Gamma>\\<turnstile>While b c \\<down> s'\"\n          proof (cases s')\n            case (Normal s'')\n            with exec_c P True valid_c ctxt\n            have s': \"s' \\<in> Normal ` ({s'. (s', s) \\<in> r} \\<inter> P)\"\n              by (fastforce simp add: cvalidt_def validt_def valid_def)\n            then show ?thesis\n              by (blast intro: hyp)\n          qed auto\n        }\n        ultimately\n        show ?thesis\n          by (blast intro: terminates.intros)\n      qed\n    qed\n  qed\nnext\n  case (Guard \\<Theta> F g P c Q A  f)\n  have valid_c: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) Guard f g c Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow> t\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    assume P:\"s \\<in> (g \\<inter> P)\"\n    from exec P have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by cases auto\n    from valid_c ctxt this P t_notin_F\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by (rule cvalidt_postD)\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P:\"s \\<in> (g \\<inter> P)\"\n    thus \"\\<Gamma>\\<turnstile>Guard f g c  \\<down> Normal s\"\n      by (auto intro: terminates.intros cvalidt_termD [OF valid_c ctxt])\n  qed\nnext\n  case (Guarantee f F \\<Theta> g P c Q A)\n  have valid_c: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\" by fact\n  have f_F: \"f \\<in> F\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Guard f g c Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow> t\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    assume P:\"s \\<in> P\"\n    from exec f_F t_notin_F have g: \"s \\<in> g\"\n      by cases auto\n    with P have P': \"s \\<in> g \\<inter> P\"\n      by blast\n    from exec g have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by cases auto\n    from valid_c ctxt this P' t_notin_F\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by (rule cvalidt_postD)\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P:\"s \\<in> P\"\n    thus \"\\<Gamma>\\<turnstile>Guard f g c  \\<down> Normal s\"\n      by (auto intro: terminates.intros cvalidt_termD [OF valid_c ctxt])\n  qed\nnext\n  case (CallRec P p Q A Specs r Specs_wf \\<Theta>  F)\n  have p: \"(P,p,Q,A) \\<in> Specs\"  by fact\n  have wf: \"wf r\" by fact\n  have Specs_wf:\n    \"Specs_wf = (\\<lambda>p \\<tau>. (\\<lambda>(P,q,Q,A). (P \\<inter> {s. ((s, q),\\<tau>,p) \\<in> r},q,Q,A)) ` Specs)\" by fact\n  from CallRec.hyps\n  have valid_body:\n    \"\\<forall>(P, p, Q, A)\\<in>Specs. p \\<in> dom \\<Gamma> \\<and>\n        (\\<forall>\\<tau>. \\<Gamma>,\\<Theta> \\<union> Specs_wf p \\<tau>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) the (\\<Gamma> p) Q,A)\" by auto\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  proof -\n    {\n      fix \\<tau>p\n      assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n      from wf\n      have \"\\<And>\\<tau> p P Q A.  \\<lbrakk>\\<tau>p = (\\<tau>,p); (P,p,Q,A) \\<in> Specs\\<rbrakk> \\<Longrightarrow>\n                  \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> (p))) Q,A\"\n      proof (induct \\<tau>p rule: wf_induct [rule_format, consumes 1, case_names WF])\n        case (WF \\<tau>p \\<tau> p P Q A)\n        have \\<tau>p: \"\\<tau>p = (\\<tau>, p)\" by fact\n        have p: \"(P, p, Q, A) \\<in> Specs\" by fact\n        {\n          fix q P' Q' A'\n          assume q: \"(P',q,Q',A') \\<in> Specs\"\n          have \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' \\<inter> {s. ((s,q), \\<tau>,p) \\<in> r}) (Call q) Q',A'\"\n          proof (rule validtI)\n            fix s t\n            assume exec_q:\n              \"\\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow> t\"\n            assume Pre: \"s \\<in> P' \\<inter> {s. ((s,q), \\<tau>,p) \\<in> r}\"\n            assume t_notin_F: \"t \\<notin> Fault ` F\"\n            from Pre q \\<tau>p\n            have valid_bdy:\n              \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s} \\<inter> P') the (\\<Gamma> q) Q',A'\"\n              by - (rule WF.hyps, auto)\n            from Pre q\n            have Pre': \"s \\<in> {s} \\<inter> P'\"\n              by auto\n            from exec_q show \"t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n            proof (cases)\n              fix bdy\n              assume bdy: \"\\<Gamma> q = Some bdy\"\n              assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal s\\<rangle> \\<Rightarrow> t\"\n              from valid_bdy [simplified bdy option.sel]  t_notin_F exec_bdy Pre'\n              have \"t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n                by (auto simp add: validt_def valid_def)\n              with Pre q\n              show ?thesis\n                by auto\n            next\n              assume \"\\<Gamma> q = None\"\n              with q valid_body have False by auto\n              thus ?thesis ..\n            qed\n          next\n            fix s\n            assume Pre: \"s \\<in> P' \\<inter> {s. ((s,q), \\<tau>,p) \\<in> r}\"\n            from Pre q \\<tau>p\n            have valid_bdy:\n              \"\\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s} \\<inter> P') (the (\\<Gamma> q)) Q',A'\"\n              by - (rule WF.hyps, auto)\n            from Pre q\n            have Pre': \"s \\<in> {s} \\<inter> P'\"\n              by auto\n            from valid_bdy ctxt Pre'\n            have \"\\<Gamma>\\<turnstile>the (\\<Gamma> q) \\<down> Normal s\"\n              by (auto simp add: validt_def)\n            with valid_body q\n            show \"\\<Gamma>\\<turnstile>Call q\\<down> Normal s\"\n              by (fastforce intro: terminates.Call)\n          qed\n        }\n        hence \"\\<forall>(P, p, Q, A)\\<in>Specs_wf p \\<tau>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Call p Q,A\"\n          by (auto simp add: cvalidt_def Specs_wf)\n        with ctxt have \"\\<forall>(P, p, Q, A)\\<in>\\<Theta> \\<union> Specs_wf p \\<tau>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Call p Q,A\"\n          by auto\n        with p valid_body\n        show \"\\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> p)) Q,A\"\n          by (simp add: cvalidt_def) blast\n      qed\n    }\n    note lem = this\n    have valid_body':\n      \"\\<And>\\<tau>. \\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A \\<Longrightarrow>\n      \\<forall>(P,p,Q,A)\\<in>Specs. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> p)) Q,A\"\n      by (auto intro: lem)\n    show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    proof (rule cvalidtI)\n      fix s t\n      assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n      assume exec_call: \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow> t\"\n      assume P: \"s \\<in> P\"\n      assume t_notin_F: \"t \\<notin> Fault ` F\"\n      from exec_call show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      proof (cases)\n        fix bdy\n        assume bdy: \"\\<Gamma> p = Some bdy\"\n        assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal s\\<rangle> \\<Rightarrow> t\"\n        from exec_body bdy p P t_notin_F\n          valid_body' [of \"s\", OF ctxt]\n          ctxt\n        have \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n          apply (simp only: cvalidt_def validt_def valid_def)\n          apply (drule (1) bspec)\n          apply auto\n          done\n        with p P\n        show ?thesis\n          by simp\n      next\n        assume \"\\<Gamma> p = None\"\n        with p valid_body have False by auto\n        thus ?thesis by simp\n      qed\n    next\n      fix s\n      assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n      assume P: \"s \\<in> P\"\n      show \"\\<Gamma>\\<turnstile>Call p \\<down> Normal s\"\n      proof -\n        from ctxt P p valid_body' [of \"s\",OF ctxt]\n        have \"\\<Gamma>\\<turnstile>(the (\\<Gamma> p)) \\<down> Normal s\"\n          by (auto simp add: cvalidt_def validt_def)\n        with valid_body p show ?thesis\n          by (fastforce intro: terminates.Call)\n      qed\n    qed\n  qed\nnext\n  case (DynCom P \\<Theta> F c Q A)\n  hence valid_c: \"\\<forall>s\\<in>P. \\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (c s) Q,A\" by simp\n  show \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P DynCom c Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal s\\<rangle> \\<Rightarrow> t\"\n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    from exec show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases)\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c s,Normal s\\<rangle> \\<Rightarrow> t\"\n      from cvalidt_postD [OF valid_c [rule_format, OF P] ctxt this P t_notin_F]\n      show ?thesis .\n    qed\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s \\<in> P\"\n    show \"\\<Gamma>\\<turnstile>DynCom c \\<down> Normal s\"\n    proof -\n      from cvalidt_termD [OF valid_c [rule_format, OF P] ctxt P]\n      have \"\\<Gamma>\\<turnstile>c s \\<down> Normal s\" .\n      thus ?thesis\n        by (rule terminates.intros)\n    qed\n  qed\nnext\n  case (Throw \\<Theta> F A Q)\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> A Throw Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Throw,Normal s\\<rangle> \\<Rightarrow> t\" \"s \\<in> A\"\n    then show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by cases simp\n  next\n    fix s\n    show \"\\<Gamma>\\<turnstile>Throw \\<down> Normal s\"\n      by (rule terminates.intros)\n  qed\nnext\n  case (Catch \\<Theta> F P c\\<^sub>1 Q R c\\<^sub>2 A)\n  have valid_c1: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,R\" by fact\n  have valid_c2: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Catch c\\<^sub>1 c\\<^sub>2 Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow> t\"\n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    from exec show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases)\n      fix s'\n      assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Abrupt s'\"\n      assume exec_c2: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s'\\<rangle> \\<Rightarrow> t\"\n      from cvalidt_postD [OF valid_c1 ctxt exec_c1 P]\n      have \"Abrupt s' \\<in> Abrupt ` R\"\n        by auto\n      with cvalidt_postD [OF valid_c2 ctxt] exec_c2 t_notin_F\n      show ?thesis\n        by fastforce\n    next\n      assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t\"\n      assume notAbr: \"\\<not> isAbr t\"\n      from cvalidt_postD [OF valid_c1 ctxt exec_c1 P] t_notin_F\n      have \"t \\<in> Normal ` Q \\<union> Abrupt ` R\" .\n      with notAbr\n      show ?thesis\n        by auto\n    qed\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s \\<in> P\"\n    show \"\\<Gamma>\\<turnstile>Catch c\\<^sub>1 c\\<^sub>2 \\<down> Normal s\"\n    proof -\n      from valid_c1 ctxt P\n      have \"\\<Gamma>\\<turnstile>c\\<^sub>1\\<down> Normal s\"\n        by (rule cvalidt_termD)\n      moreover\n      {\n        fix r assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Abrupt r\"\n        from cvalidt_postD [OF valid_c1 ctxt exec_c1 P]\n        have r: \"Abrupt r\\<in>Normal ` Q \\<union> Abrupt ` R\"\n          by auto\n        hence \"Abrupt r\\<in>Abrupt ` R\" by fast\n        with cvalidt_termD [OF valid_c2 ctxt] exec_c1\n        have \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal r\"\n          by fast\n      }\n      ultimately show ?thesis\n        by (iprover intro: terminates.intros)\n    qed\n  qed\nnext\n  case (Conseq P \\<Theta> F c Q A)\n  hence adapt:\n    \"\\<forall>s \\<in> P. (\\<exists>P' Q' A'. (\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A') \\<and> s \\<in> P'\\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A)\" by blast\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof -\n      from adapt [rule_format, OF P]\n      obtain P' and Q' and A' where\n        valid_P'_Q': \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A'\"\n        and weaken: \"s \\<in> P'\" \"Q' \\<subseteq>  Q\" \"A'\\<subseteq> A\"\n        by blast\n      from exec valid_P'_Q' ctxt t_notin_F\n      have P'_Q': \"Normal s \\<in> Normal ` P' \\<longrightarrow>\n        t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n        by (unfold cvalidt_def validt_def valid_def) blast\n      hence \"s \\<in> P' \\<longrightarrow> t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n        by blast\n      with weaken\n      show ?thesis\n        by blast\n    qed\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s \\<in> P\"\n    show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    proof -\n      from P adapt\n      obtain P' and Q' and  A' where\n        \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A'\"\n        \"s \\<in> P'\"\n        by blast\n      with ctxt\n      show ?thesis\n        by (simp add: cvalidt_def validt_def)\n    qed\n  qed\nnext\n  case (Asm P p Q A \\<Theta> F)\n  assume \"(P, p, Q, A) \\<in> \\<Theta>\"\n  then show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (auto simp add: cvalidt_def )\nnext\n  case ExFalso thus ?case by iprover\nqed\n\nlemma hoaret_sound':\n\"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (drule hoaret_sound)\n  apply (simp add: cvalidt_def)\n  done\n\ntheorem total_to_partial:\n assumes total: \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" shows \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from total have \"\\<Gamma>,{}\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (rule hoaret_sound)\n  hence \"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (simp add: cvalidt_def validt_def cvalid_def)\n  thus ?thesis\n    by (rule hoare_complete)\nqed\n\nsubsection \\<open>Completeness\\<close>\n\nlemma MGT_valid:\n\"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \\<Gamma>\\<turnstile>c\\<down>Normal s} c\n    {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t}, {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\nproof (rule validtI)\n  fix s t\n  assume \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n         \"s \\<in> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \\<Gamma>\\<turnstile>c\\<down>Normal s}\"\n         \"t \\<notin> Fault ` F\"\n  thus \"t \\<in> Normal ` {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t} \\<union>\n            Abrupt ` {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    apply (cases t)\n    apply (auto simp add: final_notin_def)\n    done\nnext\n  fix s\n  assume \"s \\<in> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \\<Gamma>\\<turnstile>c\\<down>Normal s}\"\n  thus \"\\<Gamma>\\<turnstile>c\\<down>Normal s\"\n    by blast\nqed\n\ntext \\<open>The consequence rule where the existential @{term Z} is instantiated\nto @{term s}. Usefull in proof of \\<open>MGT_lemma\\<close>.\\<close>\nlemma ConseqMGT:\n  assumes modif: \"\\<forall>Z::'a. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z::'a assn) c (Q' Z),(A' Z)\"\n  assumes impl: \"\\<And>s. s \\<in> P \\<Longrightarrow> s \\<in> P' s \\<and> (\\<forall>t. t \\<in> Q' s \\<longrightarrow> t \\<in> Q) \\<and>\n                                            (\\<forall>t. t \\<in> A' s \\<longrightarrow> t \\<in> A)\"\n  shows \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nusing impl\nby - (rule conseq [OF modif],blast)\n\nlemma MGT_implies_complete:\n  assumes MGT: \"\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                                 \\<Gamma>\\<turnstile>c\\<down>Normal s}\n                              c\n                            {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                            {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  assumes valid: \"\\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,{} \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  using MGT\n  apply (rule ConseqMGT)\n  apply (insert valid)\n  apply (auto simp add: validt_def valid_def intro!: final_notinI)\n  done\n\nlemma conseq_extract_state_indep_prop:\n  assumes state_indep_prop:\"\\<forall>s \\<in> P. R\"\n  assumes to_show: \"R \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule Conseq)\n  apply (clarify)\n  apply (rule_tac x=\"P\" in exI)\n  apply (rule_tac x=\"Q\" in exI)\n  apply (rule_tac x=\"A\" in exI)\n  using state_indep_prop to_show\n  by blast\n\nlemma MGT_lemma:\n  assumes MGT_Calls:\n    \"\\<forall>p \\<in> dom \\<Gamma>. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>\n       {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n           \\<Gamma>\\<turnstile>(Call p)\\<down>Normal s}\n             (Call p)\n       {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n       {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  shows \"\\<And>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                          \\<Gamma>\\<turnstile>c\\<down>Normal s}\n               c\n             {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\nproof (induct c)\n  case Skip\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Skip,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                   \\<Gamma>\\<turnstile>Skip \\<down> Normal s}\n               Skip\n            {t. \\<Gamma>\\<turnstile>\\<langle>Skip,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>Skip,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoaret.Skip [THEN conseqPre])\n       (auto elim: exec_elim_cases simp add: final_notin_def\n             intro: exec.intros terminates.intros)\nnext\n  case (Basic f)\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Basic f,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                 \\<Gamma>\\<turnstile>Basic f \\<down> Normal s}\n                Basic f\n              {t. \\<Gamma>\\<turnstile>\\<langle>Basic f,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Basic f,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoaret.Basic [THEN conseqPre])\n       (auto elim: exec_elim_cases simp add: final_notin_def\n             intro: exec.intros terminates.intros)\nnext\n  case (Spec r)\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Spec r,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                    \\<Gamma>\\<turnstile>Spec r \\<down> Normal s}\n                Spec r\n              {t. \\<Gamma>\\<turnstile>\\<langle>Spec r,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Spec r,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    apply (rule hoaret.Spec [THEN conseqPre])\n    apply (clarsimp simp add: final_notin_def)\n    apply (case_tac \"\\<exists>t. (Z,t) \\<in> r\")\n    apply (auto elim: exec_elim_cases simp add: final_notin_def intro: exec.intros)\n    done\nnext\n  case (Seq c1 c2)\n  have hyp_c1: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                                \\<Gamma>\\<turnstile>c1\\<down>Normal s}\n                            c1\n                           {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                           {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Seq.hyps by iprover\n  have hyp_c2: \"\\<forall> Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                                 \\<Gamma>\\<turnstile>c2\\<down>Normal s}\n                              c2\n                            {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                            {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Seq.hyps by iprover\n  from hyp_c1\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                \\<Gamma>\\<turnstile>Seq c1 c2\\<down>Normal s} c1\n    {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t \\<and> \\<Gamma>\\<turnstile>\\<langle>c2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n        \\<Gamma>\\<turnstile>c2\\<down>Normal t},\n    {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT)\n       (auto dest: Seq_NoFaultStuckD1 [simplified] Seq_NoFaultStuckD2 [simplified]\n             elim: terminates_Normal_elim_cases\n             intro: exec.intros)\n  thus \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                 \\<Gamma>\\<turnstile>Seq c1 c2\\<down>Normal s}\n                Seq c1 c2\n              {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  proof (rule hoaret.Seq )\n    show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t \\<and>\n                    \\<Gamma>\\<turnstile>\\<langle>c2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \\<Gamma>\\<turnstile>c2 \\<down> Normal t}\n                 c2\n                {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    proof (rule ConseqMGT [OF hyp_c2],safe)\n      fix r t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal r\" \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal r\\<rangle> \\<Rightarrow> Normal t\"\n      then show \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n        by (rule exec.intros)\n    next\n      fix r t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal r\" \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal r\\<rangle> \\<Rightarrow> Abrupt t\"\n      then show \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n        by (rule exec.intros)\n    qed\n  qed\nnext\n  case (Cond b c1 c2)\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                         \\<Gamma>\\<turnstile>c1\\<down>Normal s}\n                     c1\n                   {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                   {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Cond.hyps by iprover\n  hence \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                     \\<Gamma>\\<turnstile>(Cond b c1 c2)\\<down>Normal s}\\<inter>b)\n                c1\n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT)\n       (fastforce simp add: final_notin_def intro: exec.CondTrue\n                 elim: terminates_Normal_elim_cases)\n  moreover\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                               \\<Gamma>\\<turnstile>c2\\<down>Normal s}\n                      c2\n                    {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                    {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Cond.hyps by iprover\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                    \\<Gamma>\\<turnstile>(Cond b c1 c2)\\<down>Normal s}\\<inter>-b)\n                c2\n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT)\n       (fastforce simp add: final_notin_def intro: exec.CondFalse\n                 elim: terminates_Normal_elim_cases)\n  ultimately\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n               \\<Gamma>\\<turnstile>(Cond b c1 c2)\\<down>Normal s}\n               (Cond b c1 c2)\n              {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoaret.Cond)\nnext\n  case (While b c)\n  let ?unroll = \"({(s,t). s\\<in>b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t})\\<^sup>*\"\n  let ?P' = \"\\<lambda>Z. {t. (Z,t)\\<in>?unroll \\<and>\n                    (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                         \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                             (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow>\n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)) \\<and>\n                    \\<Gamma>\\<turnstile>(While b c)\\<down>Normal t}\"\n  let ?A = \"\\<lambda>Z. {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  let ?r = \"{(t,s). \\<Gamma>\\<turnstile>(While b c)\\<down>Normal s \\<and> s\\<in>b \\<and>\n                    \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t}\"\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                  \\<Gamma>\\<turnstile>(While b c)\\<down>Normal s}\n              (While b c)\n              {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  proof (rule ConseqMGT [where ?P'=\"\\<lambda> Z. ?P' Z\"\n                         and ?Q'=\"\\<lambda> Z. ?P' Z \\<inter> - b\"])\n    have wf_r: \"wf ?r\" by (rule wf_terminates_while)\n    show \"\\<forall> Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (?P' Z) (While b c) (?P' Z \\<inter> - b),(?A Z)\"\n    proof (rule allI, rule hoaret.While [OF wf_r])\n      fix Z\n      from While\n      have hyp_c: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                                  \\<Gamma>\\<turnstile>c\\<down>Normal s}\n                                c\n                              {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                              {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" by iprover\n      show \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> ?P' Z  \\<inter> b) c\n                       ({t. (t, \\<sigma>) \\<in> ?r} \\<inter> ?P' Z),(?A Z)\"\n      proof (rule allI, rule ConseqMGT [OF hyp_c])\n        fix \\<sigma> s\n        assume  \"s\\<in> {\\<sigma>} \\<inter>\n                   {t. (Z, t) \\<in> ?unroll \\<and>\n                      (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                           \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                               (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow>\n                                    \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)) \\<and>\n                      \\<Gamma>\\<turnstile>(While b c)\\<down>Normal t}\n                   \\<inter> b\"\n        then obtain\n          s_eq_\\<sigma>: \"s=\\<sigma>\" and\n          Z_s_unroll: \"(Z,s) \\<in> ?unroll\" and\n          noabort:\"\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                        \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                            (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow>\n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)\" and\n          while_term:  \"\\<Gamma>\\<turnstile>(While b c)\\<down>Normal s\" and\n          s_in_b: \"s\\<in>b\"\n          by blast\n        show \"s \\<in> {t. t = s \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                       \\<Gamma>\\<turnstile>c\\<down>Normal t} \\<and>\n        (\\<forall>t. t \\<in> {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t} \\<longrightarrow>\n             t \\<in> {t. (t,\\<sigma>) \\<in> ?r} \\<inter>\n                 {t. (Z, t) \\<in> ?unroll \\<and>\n                     (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow>  e\\<in>b\n                           \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                              (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow>\n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)) \\<and>\n                      \\<Gamma>\\<turnstile>(While b c)\\<down>Normal t})  \\<and>\n         (\\<forall>t. t \\<in> {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Abrupt t} \\<longrightarrow>\n             t \\<in> {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})\"\n          (is \"?C1 \\<and> ?C2 \\<and> ?C3\")\n        proof (intro conjI)\n          from Z_s_unroll noabort s_in_b while_term show ?C1\n            by (blast elim: terminates_Normal_elim_cases)\n        next\n          {\n            fix t\n            assume s_t: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t\"\n            with s_eq_\\<sigma> while_term s_in_b have \"(t,\\<sigma>) \\<in> ?r\"\n              by blast\n            moreover\n            from Z_s_unroll s_t s_in_b\n            have \"(Z, t) \\<in> ?unroll\"\n              by (blast intro: rtrancl_into_rtrancl)\n            moreover from while_term s_t s_in_b\n            have \"\\<Gamma>\\<turnstile>(While b c)\\<down>Normal t\"\n              by (blast elim: terminates_Normal_elim_cases)\n            moreover note noabort\n            ultimately\n            have \"(t,\\<sigma>) \\<in> ?r \\<and> (Z, t) \\<in> ?unroll \\<and>\n                  (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                        \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                            (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow>\n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)) \\<and>\n                  \\<Gamma>\\<turnstile>(While b c)\\<down>Normal t\"\n              by iprover\n          }\n          then show ?C2 by blast\n        next\n          {\n            fix t\n            assume s_t:  \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Abrupt t\"\n            from Z_s_unroll noabort s_t s_in_b\n            have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n              by blast\n          } thus ?C3 by simp\n        qed\n      qed\n    qed\n  next\n    fix s\n    assume P: \"s \\<in> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                       \\<Gamma>\\<turnstile>While b c \\<down> Normal s}\"\n    hence WhileNoFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n      by auto\n    show \"s \\<in> ?P' s \\<and>\n     (\\<forall>t. t\\<in>(?P' s \\<inter> - b)\\<longrightarrow>\n          t\\<in>{t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t})\\<and>\n     (\\<forall>t. t\\<in>?A s \\<longrightarrow> t\\<in>?A Z)\"\n    proof (intro conjI)\n      {\n        fix e\n        assume \"(Z,e) \\<in> ?unroll\" \"e \\<in> b\"\n        from this WhileNoFault\n        have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n               (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow>\n                    \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)\" (is \"?Prop Z e\")\n        proof (induct rule: converse_rtrancl_induct [consumes 1])\n          assume e_in_b: \"e \\<in> b\"\n          assume WhileNoFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n          with e_in_b WhileNoFault\n          have cNoFault: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n            by (auto simp add: final_notin_def intro: exec.intros)\n          moreover\n          {\n            fix u assume \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow> Abrupt u\"\n            with e_in_b have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal e\\<rangle> \\<Rightarrow> Abrupt u\"\n              by (blast intro: exec.intros)\n          }\n          ultimately\n          show \"?Prop e e\"\n            by iprover\n        next\n          fix Z r\n          assume e_in_b: \"e\\<in>b\"\n          assume WhileNoFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n          assume hyp: \"\\<lbrakk>e\\<in>b;\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\\<rbrakk>\n                       \\<Longrightarrow> ?Prop r e\"\n          assume Z_r:\n            \"(Z, r) \\<in> {(Z, r). Z \\<in> b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal r}\"\n          with WhileNoFault\n          have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n            by (auto simp add: final_notin_def intro: exec.intros)\n          from hyp [OF e_in_b this] obtain\n            cNoFault: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\" and\n            Abrupt_r: \"\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow> Abrupt u \\<longrightarrow>\n                            \\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow> Abrupt u\"\n            by simp\n\n           {\n            fix u assume \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow> Abrupt u\"\n            with Abrupt_r have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow> Abrupt u\" by simp\n            moreover from  Z_r obtain\n              \"Z \\<in> b\"  \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal r\"\n              by simp\n            ultimately have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u\"\n              by (blast intro: exec.intros)\n          }\n          with cNoFault show \"?Prop Z e\"\n            by iprover\n        qed\n      }\n      with P show \"s \\<in> ?P' s\"\n        by blast\n    next\n      {\n        fix t\n        assume \"termination\": \"t \\<notin> b\"\n        assume \"(Z, t) \\<in> ?unroll\"\n        hence \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n        proof (induct rule: converse_rtrancl_induct [consumes 1])\n          from \"termination\"\n          show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal t\\<rangle> \\<Rightarrow> Normal t\"\n            by (blast intro: exec.WhileFalse)\n        next\n          fix Z r\n          assume first_body:\n                 \"(Z, r) \\<in> {(s, t). s \\<in> b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t}\"\n          assume \"(r, t) \\<in> ?unroll\"\n          assume rest_loop: \"\\<Gamma>\\<turnstile>\\<langle>While b c, Normal r\\<rangle> \\<Rightarrow> Normal t\"\n          show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n          proof -\n            from first_body obtain\n              \"Z \\<in> b\" \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal r\"\n              by fast\n            moreover\n            from rest_loop have\n              \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow> Normal t\"\n              by fast\n            ultimately show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n              by (rule exec.WhileTrue)\n          qed\n        qed\n      }\n      with P\n      show \"(\\<forall>t. t\\<in>(?P' s \\<inter> - b)\n            \\<longrightarrow>t\\<in>{t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t})\"\n        by blast\n    next\n      from P show \"\\<forall>t. t\\<in>?A s \\<longrightarrow> t\\<in>?A Z\"\n        by simp\n    qed\n  qed\nnext\n  case (Call p)\n  from noStuck_Call\n  have \"\\<forall>s \\<in> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                         \\<Gamma>\\<turnstile>Call p\\<down> Normal s}.\n          p \\<in> dom \\<Gamma>\"\n    by (fastforce simp add: final_notin_def)\n  then show ?case\n  proof (rule conseq_extract_state_indep_prop)\n    assume p_defined: \"p \\<in> dom \\<Gamma>\"\n    with MGT_Calls show\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s=Z \\<and>\n                 \\<Gamma>\\<turnstile>\\<langle>Call p ,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\\<and>\n                 \\<Gamma>\\<turnstile>Call  p\\<down>Normal s}\n                (Call p)\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      by (auto)\n  qed\nnext\n  case (DynCom c)\n  have hyp:\n    \"\\<And>s'. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c s',Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                       \\<Gamma>\\<turnstile>c s'\\<down>Normal s} c s'\n      {t. \\<Gamma>\\<turnstile>\\<langle>c s',Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c s',Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using DynCom by simp\n  have hyp':\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n            \\<Gamma>\\<turnstile>DynCom c\\<down>Normal s}\n         (c Z)\n        {t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT [OF hyp])\n       (fastforce simp add: final_notin_def intro: exec.intros\n          elim: terminates_Normal_elim_cases)\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                 \\<Gamma>\\<turnstile>DynCom c\\<down>Normal s}\n                DynCom c\n             {t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    apply (rule hoaret.DynCom)\n    apply (clarsimp)\n    apply (rule hyp' [simplified])\n    done\nnext\n  case (Guard f g c)\n  have hyp_c: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                              \\<Gamma>\\<turnstile>c\\<down>Normal s}\n                     c\n                   {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                   {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Guard by iprover\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                    \\<Gamma>\\<turnstile>Guard f g c\\<down> Normal s}\n                Guard f g c\n              {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  proof (cases \"f \\<in> F\")\n    case True\n    from hyp_c\n    have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>(g \\<inter> {s. s=Z \\<and>\n                     \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck}\\<union> Fault ` (-F))\\<and>\n                     \\<Gamma>\\<turnstile>Guard f g c\\<down> Normal s})\n                   c\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      apply (rule ConseqMGT)\n      apply (insert True)\n      apply  (auto simp add: final_notin_def intro: exec.intros\n                   elim: terminates_Normal_elim_cases)\n      done\n    from True this\n    show ?thesis\n      by (rule conseqPre [OF Guarantee]) auto\n  next\n    case False\n    from hyp_c\n    have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>(g \\<inter> {s. s \\<in> g \\<and> s=Z \\<and>\n                     \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck}\\<union> Fault ` (-F))\\<and>\n                     \\<Gamma>\\<turnstile>Guard f g c\\<down> Normal s} )\n                   c\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      apply (rule ConseqMGT)\n      apply clarify\n      apply (frule Guard_noFaultStuckD [OF _ False])\n      apply  (auto simp add: final_notin_def intro: exec.intros\n                   elim: terminates_Normal_elim_cases)\n      done\n    then show ?thesis\n      apply (rule conseqPre [OF hoaret.Guard])\n      apply clarify\n      apply (frule Guard_noFaultStuckD [OF _ False])\n      apply auto\n      done\n  qed\nnext\n  case Throw\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Throw,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                    \\<Gamma>\\<turnstile>Throw \\<down> Normal s}\n              Throw\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule conseqPre [OF hoaret.Throw])\n       (blast intro: exec.intros terminates.intros)\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                        \\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s}\n                    c\\<^sub>1\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                   \\<Gamma>\\<turnstile>Catch c\\<^sub>1 c\\<^sub>2 \\<down> Normal s}\n                c\\<^sub>1\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t \\<and> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal t \\<and>\n                   \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\"\n    by (rule ConseqMGT)\n       (fastforce intro: exec.intros terminates.intros\n                 elim: terminates_Normal_elim_cases\n                 simp add: final_notin_def)\n  moreover\n  have\n    \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                     \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s} c\\<^sub>2\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow>Abrupt s \\<and> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s \\<and>\n                   \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\n               c\\<^sub>2\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      by (rule ConseqMGT)\n         (fastforce intro: exec.intros terminates.intros\n                   simp add: noFault_def')\n  ultimately\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                   \\<Gamma>\\<turnstile>Catch c\\<^sub>1 c\\<^sub>2 \\<down> Normal s}\n                Catch c\\<^sub>1 c\\<^sub>2\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoaret.Catch )\nqed\n\n\n\n\n           {\n            fix u assume \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow> Abrupt u\"\n            with Abrupt_r have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow> Abrupt u\" by simp\n            moreover from  Z_r obtain\n              \"Z \\<in> b\"  \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal r\"\n              by simp\n            ultimately have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u\"\n              by (blast intro: exec.intros)\n          }\n          with cNoFault show \"?Prop Z e\"\n            by iprover\n        qed\n      }\n      with P show \"s \\<in> ?P' s\"\n        by blast\n    next\n      {\n        fix t\n        assume \"termination\": \"t \\<notin> b\"\n        assume \"(Z, t) \\<in> ?unroll\"\n        hence \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n        proof (induct rule: converse_rtrancl_induct [consumes 1])\n          from \"termination\"\n          show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal t\\<rangle> \\<Rightarrow> Normal t\"\n            by (blast intro: exec.WhileFalse)\n        next\n          fix Z r\n          assume first_body:\n                 \"(Z, r) \\<in> {(s, t). s \\<in> b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t}\"\n          assume \"(r, t) \\<in> ?unroll\"\n          assume rest_loop: \"\\<Gamma>\\<turnstile>\\<langle>While b c, Normal r\\<rangle> \\<Rightarrow> Normal t\"\n          show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n          proof -\n            from first_body obtain\n              \"Z \\<in> b\" \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal r\"\n              by fast\n            moreover\n            from rest_loop have\n              \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow> Normal t\"\n              by fast\n            ultimately show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n              by (rule exec.WhileTrue)\n          qed\n        qed\n      }\n      with P\n      show \"\\<forall>t. t\\<in>(?P' s \\<inter> - b)\n            \\<longrightarrow>t\\<in>{t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t}\"\n        by blast\n    next\n      from P show \"\\<forall>t. t\\<in>?A s \\<longrightarrow> t\\<in>?A Z\"\n        by simp\n    qed\n  qed\nnext\n  case (Call q)\n  let ?P = \"{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call q ,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n               \\<Gamma>\\<turnstile>Call p\\<down>Normal \\<sigma> \\<and>\n              (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and> Call q \\<in> redexes c')}\"\n  from noStuck_Call\n  have \"\\<forall>s \\<in> ?P. q \\<in> dom \\<Gamma>\"\n    by (fastforce simp add: final_notin_def)\n  then show ?case\n  proof (rule conseq_extract_state_indep_prop)\n    assume q_defined: \"q \\<in> dom \\<Gamma>\"\n    from Call_hyp have\n      \"\\<forall>q\\<in>dom \\<Gamma>. \\<forall>Z.\n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                        \\<Gamma>\\<turnstile>Call q\\<down>Normal s \\<and> ((s,q),(\\<sigma>,p)) \\<in> termi_call_steps \\<Gamma>}\n                 (Call q)\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      by (simp add: exec_Call_body' noFaultStuck_Call_body' [simplified]\n         terminates_Normal_Call_body)\n    from Call_hyp q_defined have Call_hyp':\n    \"\\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                     \\<Gamma>\\<turnstile>Call q\\<down>Normal s \\<and> ((s,q),(\\<sigma>,p)) \\<in> termi_call_steps \\<Gamma>}\n                  (Call q)\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      by auto\n    show\n     \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ?P\n           (Call q)\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call q ,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call q ,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    proof (rule ConseqMGT [OF Call_hyp'],safe)\n      fix c'\n      assume termi: \"\\<Gamma>\\<turnstile>Call p \\<down> Normal \\<sigma>\"\n      assume steps_c': \"\\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z)\"\n      assume red_c': \"Call q \\<in> redexes c'\"\n      show \"\\<Gamma>\\<turnstile>Call q \\<down> Normal Z\"\n      proof -\n        from steps_preserves_termination' [OF steps_c' termi]\n        have \"\\<Gamma>\\<turnstile>c' \\<down> Normal Z\" .\n        from redexes_preserves_termination [OF this red_c']\n        show ?thesis .\n      qed\n    next\n      fix c'\n      assume termi: \"\\<Gamma>\\<turnstile>Call p \\<down> Normal \\<sigma>\"\n      assume steps_c': \"\\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z)\"\n      assume red_c': \"Call q \\<in> redexes c'\"\n      from redex_redexes [OF this]\n      have \"redex c' = Call q\"\n        by auto\n      with termi steps_c'\n      show \"((Z, q), \\<sigma>, p) \\<in> termi_call_steps \\<Gamma>\"\n        by (auto simp add: termi_call_steps_def)\n    qed\n  qed\nnext\n  case (DynCom c)\n  have hyp:\n    \"\\<And>s'. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>\n      {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c s',Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n            \\<Gamma>\\<turnstile>Call p \\<down> Normal \\<sigma> \\<and>\n          (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and> c s' \\<in> redexes c')}\n        (c s')\n       {t. \\<Gamma>\\<turnstile>\\<langle>c s',Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c s',Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using DynCom by simp\n  have hyp':\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                 \\<Gamma>\\<turnstile>Call p \\<down> Normal \\<sigma> \\<and>\n               (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and> DynCom c \\<in> redexes c')}\n        (c Z)\n       {t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  proof (rule ConseqMGT [OF hyp],safe)\n    assume \"\\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n    then show \"\\<Gamma>\\<turnstile>\\<langle>c Z,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n      by (fastforce simp add: final_notin_def intro: exec.intros)\n  next\n    fix c'\n    assume steps: \"\\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z)\"\n    assume c': \"DynCom c \\<in> redexes c'\"\n    have \"\\<Gamma>\\<turnstile> (DynCom c, Normal Z) \\<rightarrow> (c Z,Normal Z)\"\n      by (rule step.DynCom)\n    from step_redexes [OF this c'] obtain c'' where\n      step: \"\\<Gamma>\\<turnstile> (c', Normal Z) \\<rightarrow> (c'', Normal Z)\"  and c'': \"c Z \\<in> redexes c''\"\n      by blast\n    note steps also note step\n    finally show \"\\<exists>c'. \\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z) \\<and> c Z \\<in> redexes c'\"\n      using c'' by blast\n  next\n    fix t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>c Z,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n    thus \"\\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n      by (auto intro: exec.intros)\n  next\n    fix t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>c Z,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n    thus \"\\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n      by (auto intro: exec.intros)\n  qed\n  show ?case\n    apply (rule hoaret.DynCom)\n    apply safe\n    apply (rule hyp')\n    done\nnext\n  case (Guard f g c)\n  have hyp_c: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>\n         {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n              \\<Gamma>\\<turnstile>Call p\\<down>Normal \\<sigma> \\<and>\n            (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and> c \\<in> redexes c')}\n          c\n         {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n         {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Guard.hyps by iprover\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                  \\<Gamma>\\<turnstile>Call p\\<down>Normal \\<sigma> \\<and>\n            (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and> Guard f g c \\<in> redexes c')}\n              Guard f g c\n              {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  proof (cases \"f \\<in> F\")\n    case True\n    have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> {s. s=Z \\<and>\n                     \\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                 \\<Gamma>\\<turnstile>Call p\\<down>Normal \\<sigma> \\<and>\n            (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and>\n                  Guard f g c \\<in> redexes c')})\n              c\n              {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    proof (rule ConseqMGT [OF hyp_c], safe)\n      assume \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\" \"Z\\<in>g\"\n      thus \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n        by (auto simp add: final_notin_def intro: exec.intros)\n    next\n      fix c'\n      assume steps: \"\\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z)\"\n      assume c': \"Guard f g c \\<in> redexes c'\"\n      assume \"Z \\<in> g\"\n      from this have \"\\<Gamma>\\<turnstile>(Guard f g c,Normal Z) \\<rightarrow> (c,Normal Z)\"\n        by (rule step.Guard)\n      from step_redexes [OF this c'] obtain c'' where\n        step: \"\\<Gamma>\\<turnstile> (c', Normal Z) \\<rightarrow> (c'', Normal Z)\"  and c'': \"c \\<in> redexes c''\"\n        by blast\n      note steps also note step\n      finally show \"\\<exists>c'. \\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z) \\<and> c \\<in> redexes c'\"\n        using c'' by blast\n    next\n      fix t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n             \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t\" \"Z \\<in> g\"\n      thus \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n        by (auto simp add: final_notin_def intro: exec.intros )\n    next\n      fix t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n              \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\" \"Z \\<in> g\"\n      thus \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n        by (auto simp add: final_notin_def intro: exec.intros )\n    qed\n    from True this show ?thesis\n      by (rule conseqPre [OF Guarantee]) auto\n  next\n    case False\n    have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> {s. s=Z \\<and>\n                     \\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                 \\<Gamma>\\<turnstile>Call p\\<down>Normal \\<sigma> \\<and>\n            (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and>\n                  Guard f g c \\<in> redexes c')})\n              c\n              {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    proof (rule ConseqMGT [OF hyp_c], safe)\n      assume \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n      thus \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n        using False\n        by (cases \"Z\\<in> g\") (auto simp add: final_notin_def intro: exec.intros)\n    next\n      fix c'\n      assume steps: \"\\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z)\"\n      assume c': \"Guard f g c \\<in> redexes c'\"\n\n      assume \"Z \\<in> g\"\n      from this have \"\\<Gamma>\\<turnstile>(Guard f g c,Normal Z) \\<rightarrow> (c,Normal Z)\"\n        by (rule step.Guard)\n      from step_redexes [OF this c'] obtain c'' where\n        step: \"\\<Gamma>\\<turnstile> (c', Normal Z) \\<rightarrow> (c'', Normal Z)\"  and c'': \"c \\<in> redexes c''\"\n        by blast\n      note steps also note step\n      finally show \"\\<exists>c'. \\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z) \\<and> c \\<in> redexes c'\"\n        using c'' by blast\n    next\n      fix t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n        \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n      thus \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n        using False\n        by (cases \"Z\\<in> g\") (auto simp add: final_notin_def intro: exec.intros )\n    next\n      fix t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n             \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n      thus \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n        using False\n        by (cases \"Z\\<in> g\") (auto simp add: final_notin_def intro: exec.intros )\n    qed\n    then show ?thesis\n      apply (rule conseqPre [OF hoaret.Guard])\n      apply clarify\n      apply (frule Guard_noFaultStuckD [OF _ False])\n      apply auto\n      done\n  qed\nnext\n  case Throw\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Throw,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                  \\<Gamma>\\<turnstile>Call p\\<down>Normal \\<sigma> \\<and>\n                (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and> Throw \\<in> redexes c')}\n              Throw\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule conseqPre [OF hoaret.Throw])\n       (blast intro: exec.intros terminates.intros)\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have hyp_c1:\n   \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s= Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                    \\<Gamma>\\<turnstile>Call p \\<down> Normal \\<sigma> \\<and>\n                (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and>\n                      c\\<^sub>1 \\<in> redexes c')}\n               c\\<^sub>1\n              {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  have hyp_c2:\n   \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s= Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                     \\<Gamma>\\<turnstile>Call p\\<down> Normal \\<sigma> \\<and>\n                (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and> c\\<^sub>2 \\<in> redexes c')}\n               c\\<^sub>2\n              {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  have\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n               \\<Gamma>\\<turnstile>Call p\\<down> Normal \\<sigma> \\<and>\n            (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>)\\<rightarrow>\\<^sup>+(c',Normal s) \\<and>\n                   Catch c\\<^sub>1 c\\<^sub>2 \\<in> redexes c')}\n            c\\<^sub>1\n           {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n           {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t \\<and>\n               \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault`(-F)) \\<and> \\<Gamma>\\<turnstile>Call p \\<down> Normal \\<sigma> \\<and>\n               (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal t) \\<and> c\\<^sub>2 \\<in> redexes c')}\"\n  proof (rule ConseqMGT [OF hyp_c1],clarify,safe)\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n    thus \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n      by (fastforce simp add: final_notin_def intro: exec.intros)\n  next\n    fix c'\n    assume steps: \"\\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z)\"\n    assume c': \"Catch c\\<^sub>1 c\\<^sub>2 \\<in> redexes c'\"\n    from steps redexes_subset [OF this]\n    show \"\\<exists>c'. \\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z) \\<and> c\\<^sub>1 \\<in> redexes c'\"\n      by (auto iff:  root_in_redexes)\n  next\n    fix t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n    thus \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n      by (auto intro: exec.intros)\n  next\n    fix t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n      \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n    thus \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n      by (auto simp add: final_notin_def intro: exec.intros)\n  next\n    fix c' t\n    assume steps_c': \"\\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z)\"\n    assume red: \"Catch c\\<^sub>1 c\\<^sub>2 \\<in> redexes c'\"\n    assume exec_c\\<^sub>1: \"\\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n    show \"\\<exists>c'. \\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal t) \\<and> c\\<^sub>2 \\<in> redexes c'\"\n    proof -\n      note steps_c'\n      also\n      from exec_impl_steps_Normal_Abrupt [OF exec_c\\<^sub>1]\n      have \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal Z) \\<rightarrow>\\<^sup>* (Throw, Normal t)\".\n      from steps_redexes_Catch [OF this red]\n      obtain c'' where\n        steps_c'': \"\\<Gamma>\\<turnstile> (c', Normal Z) \\<rightarrow>\\<^sup>* (c'', Normal t)\" and\n        Catch: \"Catch Throw c\\<^sub>2 \\<in> redexes c''\"\n        by blast\n      note steps_c''\n      also\n      have step_Catch: \"\\<Gamma>\\<turnstile> (Catch Throw c\\<^sub>2,Normal t) \\<rightarrow> (c\\<^sub>2,Normal t)\"\n        by (rule step.CatchThrow)\n      from step_redexes [OF step_Catch Catch]\n      obtain c''' where\n        step_c''': \"\\<Gamma>\\<turnstile> (c'', Normal t) \\<rightarrow> (c''', Normal t)\" and\n        c2: \"c\\<^sub>2 \\<in> redexes c'''\"\n        by blast\n      note step_c'''\n      finally show ?thesis\n        using c2\n        by blast\n    qed\n  qed\n  moreover\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t \\<and>\n                  \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                  \\<Gamma>\\<turnstile>Call p \\<down> Normal \\<sigma> \\<and>\n                  (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal t) \\<and> c\\<^sub>2 \\<in> redexes c')}\n               c\\<^sub>2\n              {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT [OF hyp_c2]) (fastforce intro: exec.intros)\n  ultimately show ?case\n    by (rule hoaret.Catch)\nqed\n\n\ntext \\<open>To prove a procedure implementation correct it suffices to assume\n       only the procedure specifications of procedures that actually\n       occur during evaluation of the body.\n\\<close>\n\nlemma Call_lemma:\n assumes A:\n \"\\<forall>q \\<in> dom \\<Gamma>. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>\n                 {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                    \\<Gamma>\\<turnstile>Call q\\<down>Normal s \\<and> ((s,q),(\\<sigma>,p)) \\<in> termi_call_steps \\<Gamma>}\n                 (Call q)\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n assumes pdef: \"p \\<in> dom \\<Gamma>\"\n shows \"\\<And>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>\n              ({\\<sigma>} \\<inter> {s. s=Z \\<and>\\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                                 \\<Gamma>\\<turnstile>the (\\<Gamma> p)\\<down>Normal s})\n                 the (\\<Gamma> p)\n              {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (rule conseqPre)\napply (rule Call_lemma' [OF A])\nusing pdef\napply (fastforce intro: terminates.intros tranclp.r_into_trancl [of \"(step \\<Gamma>)\", OF step.Call] root_in_redexes)\ndone\n\nlemma Call_lemma_switch_Call_body:\n assumes\n call: \"\\<forall>q \\<in> dom \\<Gamma>. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>\n                 {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                    \\<Gamma>\\<turnstile>Call q\\<down>Normal s \\<and> ((s,q),(\\<sigma>,p)) \\<in> termi_call_steps \\<Gamma>}\n                 (Call q)\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n assumes p_defined: \"p \\<in> dom \\<Gamma>\"\n shows \"\\<And>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>\n              ({\\<sigma>} \\<inter> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                                 \\<Gamma>\\<turnstile>Call p\\<down>Normal s})\n                 the (\\<Gamma> p)\n              {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (simp only: exec_Call_body' [OF p_defined] noFaultStuck_Call_body' [OF p_defined] terminates_Normal_Call_body [OF p_defined])\napply (rule conseqPre)\napply (rule Call_lemma')\napply (rule call)\nusing p_defined\napply (fastforce intro: terminates.intros tranclp.r_into_trancl [of \"(step \\<Gamma>)\", OF step.Call]\nroot_in_redexes)\ndone\n\nlemma MGT_Call:\n\"\\<forall>p \\<in> dom \\<Gamma>. \\<forall>Z.\n  \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n             \\<Gamma>\\<turnstile>(Call p)\\<down>Normal s}\n           (Call p)\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (intro ballI allI)\napply (rule CallRec' [where Procs=\"dom \\<Gamma>\" and\n    P=\"\\<lambda>p Z. {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                    \\<Gamma>\\<turnstile>Call p\\<down>Normal s}\" and\n    Q=\"\\<lambda>p Z. {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t}\" and\n    A=\"\\<lambda>p Z. {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" and\n    r=\"termi_call_steps \\<Gamma>\"\n    ])\napply    simp\napply   simp\napply  (rule wf_termi_call_steps)\napply (intro ballI allI)\napply simp\napply (rule Call_lemma_switch_Call_body [rule_format, simplified])\napply  (rule hoaret.Asm)\napply  fastforce\napply assumption\ndone\n\n\nlemma CollInt_iff: \"{s. P s} \\<inter> {s. Q s} = {s. P s \\<and> Q s}\"\n  by auto\n\nlemma image_Un_conv: \"f ` (\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. {x p Z}) =  (\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. {f (x p Z)})\"\n  by (auto iff: not_None_eq)\n\n\ntext \\<open>Another proof of \\<open>MGT_Call\\<close>, maybe a little more readable\\<close>\nlemma\n\"\\<forall>p \\<in> dom \\<Gamma>. \\<forall>Z.\n  \\<Gamma>,{} \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n             \\<Gamma>\\<turnstile>(Call p)\\<down>Normal s}\n           (Call p)\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\nproof -\n  {\n    fix p Z \\<sigma>\n    assume defined: \"p \\<in> dom \\<Gamma>\"\n    define Specs where \"Specs = (\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z.\n            {({s. s=Z \\<and>\n              \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n              \\<Gamma>\\<turnstile>Call p\\<down>Normal s},\n             p,\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})})\"\n    define Specs_wf where \"Specs_wf p \\<sigma> = (\\<lambda>(P,q,Q,A).\n                       (P \\<inter> {s. ((s,q),\\<sigma>,p) \\<in> termi_call_steps \\<Gamma>}, q, Q, A)) ` Specs\" for p \\<sigma>\n    have \"\\<Gamma>,Specs_wf p \\<sigma>\n            \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>({\\<sigma>} \\<inter>\n                 {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                  \\<Gamma>\\<turnstile>the (\\<Gamma> p)\\<down>Normal s})\n                (the (\\<Gamma> p))\n               {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      apply (rule Call_lemma [rule_format, OF _ defined])\n      apply (rule hoaret.Asm)\n      apply (clarsimp simp add: Specs_wf_def Specs_def image_Un_conv)\n      apply (rule_tac x=q in bexI)\n      apply (rule_tac x=Z in exI)\n      apply (clarsimp simp add: CollInt_iff)\n      apply auto\n      done\n    hence \"\\<Gamma>,Specs_wf p \\<sigma>\n            \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>({\\<sigma>} \\<inter>\n                 {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                  \\<Gamma>\\<turnstile>Call p\\<down>Normal s})\n                (the (\\<Gamma> p))\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      by (simp only: exec_Call_body' [OF defined]\n                   noFaultStuck_Call_body' [OF defined]\n                  terminates_Normal_Call_body [OF defined])\n  } note bdy=this\n  show ?thesis\n    apply (intro ballI allI)\n    apply (rule hoaret.CallRec [where Specs=\"(\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z.\n            {({s. s=Z \\<and>\n              \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n              \\<Gamma>\\<turnstile>Call p\\<down>Normal s},\n             p,\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})})\",\n             OF _ wf_termi_call_steps [of \\<Gamma>] refl])\n    apply fastforce\n    apply clarify\n    apply (rule conjI)\n    apply  fastforce\n    apply (rule allI)\n    apply (simp (no_asm_use) only : Un_empty_left)\n    apply (rule bdy)\n    apply auto\n    done\nqed\n\n\ntheorem hoaret_complete: \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (iprover intro: MGT_implies_complete MGT_lemma [OF MGT_Call])\n\nlemma hoaret_complete':\n  assumes cvalid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (cases \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\")\n  case True\n  hence \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (rule hoaret_complete)\n  thus \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (rule hoaret_augment_context) simp\nnext\n  case False\n  with cvalid\n  show ?thesis\n    by (rule ExFalso)\nqed\n\nsubsection \\<open>And Now: Some Useful Rules\\<close>\n\nsubsubsection \\<open>Modify Return\\<close>\n\nlemma ProcModifyReturn_sound:\n  assumes valid_call: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P call init p return' c Q,A\"\n  assumes valid_modif:\n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call p) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  assumes res_modif:\n  \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\n  assumes ret_modifAbr:\n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\n  shows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (auto simp add: validt_def)\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>call init p return c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from exec\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: exec_call_Normal_elim)\n    fix bdy t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> \\<Rightarrow> t\"\n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>(Call p ),Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with res_modif have \"Normal (return' s t') = Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_call)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n    assume t: \"t = Abrupt (return s t')\"\n    also from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>(Call p),Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callAbrupt)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy f\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Fault f\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callFault)\n    from cvalidt_postD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Stuck\"\n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callStuck)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    assume \"\\<Gamma> p = None\" \"t=Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callUndefined)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (auto simp add: validt_def)\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults)\n  assume P: \"s \\<in> P\"\n  from valid_call ctxt P\n  have call: \"\\<Gamma>\\<turnstile>call init p return' c\\<down> Normal s\"\n    by (rule cvalidt_termD)\n  show \"\\<Gamma>\\<turnstile>call init p return c \\<down> Normal s\"\n  proof (cases \"p \\<in> dom \\<Gamma>\")\n    case True\n    with call obtain bdy where\n      bdy: \"\\<Gamma> p = Some bdy\" and termi_bdy: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\" and\n      termi_c: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow>\n                    \\<Gamma>\\<turnstile>c s t \\<down> Normal (return' s t)\"\n      by cases auto\n    {\n      fix t\n      assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n      hence \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n      proof -\n        from exec_bdy bdy\n        have \"\\<Gamma>\\<turnstile>\\<langle>(Call p ),Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n          by (auto simp add: intro: exec.intros)\n        from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n          res_modif\n        have \"return' s t = return s t\"\n          by auto\n        with termi_c exec_bdy show ?thesis by auto\n      qed\n    }\n    with bdy termi_bdy\n    show ?thesis\n      by (iprover intro: terminates_call)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates_callUndefined)\n  qed\nqed\n\nlemma ProcModifyReturn:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes res_modif:\n  \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes ret_modifAbr:\n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:\n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call p) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule hoaret_complete')\napply (rule ProcModifyReturn_sound [where Modif=Modif and ModifAbr=ModifAbr,\n        OF _ _ res_modif ret_modifAbr])\napply (rule hoaret_sound [OF spec])\nusing modifies_spec\napply (blast intro: hoare_sound)\ndone\n\nlemma ProcModifyReturnSameFaults_sound:\n  assumes valid_call: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P call init p return' c Q,A\"\n  assumes valid_modif:\n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call p (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  assumes res_modif:\n  \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\n  assumes ret_modifAbr:\n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\n  shows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (auto simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>call init p return c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from exec\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: exec_call_Normal_elim)\n    fix bdy t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> \\<Rightarrow> t\"\n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>(Call p) ,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with res_modif have \"Normal (return' s t') = Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_call)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n    assume t: \"t = Abrupt (return s t')\"\n    also\n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call p ,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callAbrupt)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy f\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Fault f\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callFault)\n    from cvalidt_postD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Stuck\"\n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callStuck)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    assume \"\\<Gamma> p = None\" \"t=Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callUndefined)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (auto simp add: validt_def)\n  assume P: \"s \\<in> P\"\n  from valid_call ctxt P\n  have call: \"\\<Gamma>\\<turnstile>call init p return' c\\<down> Normal s\"\n    by (rule cvalidt_termD)\n  show \"\\<Gamma>\\<turnstile>call init p return c \\<down> Normal s\"\n  proof (cases \"p \\<in> dom \\<Gamma>\")\n    case True\n    with call obtain bdy where\n      bdy: \"\\<Gamma> p = Some bdy\" and termi_bdy: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\" and\n      termi_c: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow>\n                    \\<Gamma>\\<turnstile>c s t \\<down> Normal (return' s t)\"\n      by cases auto\n    {\n      fix t\n      assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n      hence \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n      proof -\n        from exec_bdy bdy\n        have \"\\<Gamma>\\<turnstile>\\<langle>(Call p ),Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n          by (auto simp add: intro: exec.intros)\n        from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n          res_modif\n        have \"return' s t = return s t\"\n          by auto\n        with termi_c exec_bdy show ?thesis by auto\n      qed\n    }\n    with bdy termi_bdy\n    show ?thesis\n      by (iprover intro: terminates_call)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates_callUndefined)\n  qed\nqed\n\nlemma ProcModifyReturnSameFaults:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes res_modif:\n  \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes ret_modifAbr:\n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:\n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} (Call p) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule hoaret_complete')\napply (rule ProcModifyReturnSameFaults_sound [where Modif=Modif and ModifAbr=ModifAbr,\n          OF _ _ res_modif ret_modifAbr])\napply (rule hoaret_sound [OF spec])\nusing modifies_spec\napply (blast intro: hoare_sound)\ndone\n\n\nsubsubsection \\<open>DynCall\\<close>\n\n\nlemma dynProcModifyReturn_sound:\nassumes valid_call: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes valid_modif:\n    \"\\<forall>s\\<in>P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call (p s)) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\nshows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (auto simp add: validt_def)\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  assume P: \"s \\<in> P\"\n  with valid_modif\n  have valid_modif':\n    \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call (p s)) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n    by blast\n  from exec\n  have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return c,Normal s\\<rangle> \\<Rightarrow> t\"\n    by (cases rule: exec_dynCall_Normal_elim)\n  then show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: exec_call_Normal_elim)\n    fix bdy t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> \\<Rightarrow> t\"\n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s),Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: exec.Call)\n    from cvalidD [OF valid_modif' [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with ret_modif have \"Normal (return' s t') =\n      Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_call)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n    assume t: \"t = Abrupt (return s t')\"\n    also from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s) ,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif' [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callAbrupt)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy f\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Fault f\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callFault)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by blast\n  next\n    fix bdy\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Stuck\"\n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callStuck)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (rule exec_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    fix bdy\n    assume \"\\<Gamma> (p s) = None\" \"t=Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callUndefined)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (rule exec_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (auto simp add: validt_def)\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults)\n  assume P: \"s \\<in> P\"\n  from valid_call ctxt P\n  have \"\\<Gamma>\\<turnstile>dynCall init p return' c\\<down> Normal s\"\n    by (rule cvalidt_termD)\n  hence call: \"\\<Gamma>\\<turnstile>call init (p s) return' c\\<down> Normal s\"\n    by cases\n  have \"\\<Gamma>\\<turnstile>call init (p s) return c \\<down> Normal s\"\n  proof (cases \"p s \\<in> dom \\<Gamma>\")\n    case True\n    with call obtain bdy where\n      bdy: \"\\<Gamma> (p s) = Some bdy\" and termi_bdy: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\" and\n      termi_c: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow>\n                    \\<Gamma>\\<turnstile>c s t \\<down> Normal (return' s t)\"\n      by cases auto\n    {\n      fix t\n      assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n      hence \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n      proof -\n        from exec_bdy bdy\n        have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s),Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n          by (auto simp add: intro: exec.intros)\n        from cvalidD [OF valid_modif [rule_format, of s \"init s\"] ctxt' this] P\n          ret_modif\n        have \"return' s t = return s t\"\n          by auto\n        with termi_c exec_bdy show ?thesis by auto\n      qed\n    }\n    with bdy termi_bdy\n    show ?thesis\n      by (iprover intro: terminates_call)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates_callUndefined)\n  qed\n  thus \"\\<Gamma>\\<turnstile>dynCall init p return c \\<down> Normal s\"\n    by (iprover intro: terminates_dynCall)\nqed\n\nlemma dynProcModifyReturn:\nassumes dyn_call: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s)\n           \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s)\n                             \\<longrightarrow> return' s t = return s t\"\nassumes modif:\n    \"\\<forall>s \\<in> P. \\<forall>\\<sigma>.\n       \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\nshows \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\napply (rule hoaret_complete')\napply (rule dynProcModifyReturn_sound\n        [where Modif=Modif and ModifAbr=ModifAbr,\n            OF hoaret_sound [OF dyn_call] _ ret_modif ret_modifAbr])\napply (intro ballI allI)\napply (rule hoare_sound [OF modif [rule_format]])\napply assumption\ndone\n\nlemma dynProcModifyReturnSameFaults_sound:\nassumes valid_call: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes valid_modif:\n    \"\\<forall>s\\<in>P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\nshows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (auto simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  assume P: \"s \\<in> P\"\n  with valid_modif\n  have valid_modif':\n    \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} (Call (p s)) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n    by blast\n  from exec\n  have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return c,Normal s\\<rangle> \\<Rightarrow> t\"\n    by (cases rule: exec_dynCall_Normal_elim)\n  then show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: exec_call_Normal_elim)\n    fix bdy t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> \\<Rightarrow> t\"\n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s),Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif' [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with ret_modif have \"Normal (return' s t') =\n      Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_call)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n    assume t: \"t = Abrupt (return s t')\"\n    also from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s)  ,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif' [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callAbrupt)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy f\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Fault f\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callFault)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Stuck\"\n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callStuck)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (rule exec_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    fix bdy\n    assume \"\\<Gamma> (p s) = None\" \"t=Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callUndefined)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (rule exec_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (auto simp add: validt_def)\n  assume P: \"s \\<in> P\"\n  from valid_call ctxt P\n  have \"\\<Gamma>\\<turnstile>dynCall init p return' c\\<down> Normal s\"\n    by (rule cvalidt_termD)\n  hence call: \"\\<Gamma>\\<turnstile>call init (p s) return' c\\<down> Normal s\"\n    by cases\n  have \"\\<Gamma>\\<turnstile>call init (p s) return c \\<down> Normal s\"\n  proof (cases \"p s \\<in> dom \\<Gamma>\")\n    case True\n    with call obtain bdy where\n      bdy: \"\\<Gamma> (p s) = Some bdy\" and termi_bdy: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\" and\n      termi_c: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow>\n                    \\<Gamma>\\<turnstile>c s t \\<down> Normal (return' s t)\"\n      by cases auto\n    {\n      fix t\n      assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n      hence \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n      proof -\n        from exec_bdy bdy\n        have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s),Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n          by (auto simp add: intro: exec.intros)\n        from cvalidD [OF valid_modif [rule_format, of s \"init s\"] ctxt' this] P\n          ret_modif\n        have \"return' s t = return s t\"\n          by auto\n        with termi_c exec_bdy show ?thesis by auto\n      qed\n    }\n    with bdy termi_bdy\n    show ?thesis\n      by (iprover intro: terminates_call)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates_callUndefined)\n  qed\n  thus \"\\<Gamma>\\<turnstile>dynCall init p return c \\<down> Normal s\"\n    by (iprover intro: terminates_dynCall)\nqed\n\nlemma dynProcModifyReturnSameFaults:\nassumes dyn_call: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\nassumes modif:\n    \"\\<forall>s \\<in> P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\nshows \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\napply (rule hoaret_complete')\napply (rule dynProcModifyReturnSameFaults_sound\n        [where Modif=Modif and ModifAbr=ModifAbr,\n          OF hoaret_sound [OF dyn_call] _ ret_modif ret_modifAbr])\napply (intro ballI allI)\napply (rule hoare_sound [OF modif [rule_format]])\napply assumption\ndone\n\nsubsubsection \\<open>Conjunction of Postcondition\\<close>\n\nlemma PostConjI_sound:\n  assumes valid_Q: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes valid_R: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c R,B\"\n  shows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from valid_Q ctxt exec P t_notin_F have \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    by (rule cvalidt_postD)\n  moreover\n  from valid_R ctxt exec P t_notin_F have \"t \\<in> Normal ` R \\<union> Abrupt ` B\"\n    by (rule cvalidt_postD)\n  ultimately show \"t \\<in> Normal ` (Q \\<inter> R) \\<union> Abrupt ` (A \\<inter> B)\"\n    by blast\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  from valid_Q ctxt P\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule cvalidt_termD)\nqed\n\nlemma PostConjI:\n  assumes deriv_Q: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes deriv_R: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c R,B\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\napply (rule hoaret_complete')\napply (rule PostConjI_sound)\napply (rule hoaret_sound [OF deriv_Q])\napply (rule hoaret_sound [OF deriv_R])\ndone\n\n\nlemma Merge_PostConj_sound:\n  assumes validF: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes validG: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/G\\<^esub> P' c R,X\"\n  assumes F_G: \"F \\<subseteq> G\"\n  assumes P_P': \"P \\<subseteq> P'\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> X)\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  with F_G have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/G\\<^esub> P (Call p) Q,A\"\n    by (auto intro: validt_augment_Faults)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  with P_P' have P': \"s \\<in> P'\"\n    by auto\n  assume t_noFault: \"t \\<notin> Fault ` F\"\n  show \"t \\<in> Normal ` (Q \\<inter> R) \\<union> Abrupt ` (A \\<inter> X)\"\n  proof -\n    from cvalidt_postD [OF validF [rule_format] ctxt exec P t_noFault]\n    have t: \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\n    then have \"t \\<notin> Fault ` G\"\n      by auto\n    from cvalidt_postD [OF validG [rule_format] ctxt' exec P' this]\n    have \"t \\<in> Normal ` R \\<union> Abrupt ` X\" .\n    with t show ?thesis by auto\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  from validF ctxt P\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule cvalidt_termD)\nqed\n\n\n\nlemma Merge_PostConj:\n  assumes validF: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes validG: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/G\\<^esub> P' c R,X\"\n  assumes F_G: \"F \\<subseteq> G\"\n  assumes P_P': \"P \\<subseteq> P'\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> X)\"\napply (rule hoaret_complete')\napply (rule Merge_PostConj_sound [OF _ _ F_G P_P'])\nusing validF apply (blast intro:hoaret_sound)\nusing validG apply (blast intro:hoaret_sound)\ndone\n\n\nsubsubsection \\<open>Guards and Guarantees\\<close>\n\nlemma SplitGuards_sound:\n  assumes valid_c1: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,A\"\n  assumes valid_c2: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>2 UNIV,UNIV\"\n  assumes c: \"(c\\<^sub>1 \\<inter>\\<^sub>g c\\<^sub>2) = Some c\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (auto simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases t)\n    case Normal\n    with inter_guards_exec_noFault [OF c exec]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t\" by simp\n    from valid_c1 ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    case Abrupt\n    with inter_guards_exec_noFault [OF c exec]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t\" by simp\n    from valid_c1 ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    case (Fault f)\n    assume t: \"t=Fault f\"\n    with exec inter_guards_exec_Fault [OF c]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Fault f \\<or> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow> Fault f\"\n      by auto\n    then show ?thesis\n    proof (cases rule: disjE [consumes 1])\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Fault f\"\n      from cvalidt_postD [OF valid_c1 ctxt this P] t t_notin_F\n      show ?thesis\n        by blast\n    next\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow> Fault f\"\n      from cvalidD [OF valid_c2 ctxt' this P] t t_notin_F\n      show ?thesis\n        by blast\n    qed\n  next\n    case Stuck\n    with inter_guards_exec_noFault [OF c exec]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t\" by simp\n    from valid_c1 ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n  proof -\n    from valid_c1 ctxt P\n    have \"\\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s\"\n      by (rule cvalidt_termD)\n    with c show ?thesis\n      by (rule inter_guards_terminates)\n  qed\nqed\n\nlemma SplitGuards:\n  assumes c: \"(c\\<^sub>1 \\<inter>\\<^sub>g c\\<^sub>2) = Some c\"\n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,A\"\n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>2 UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule SplitGuards_sound [OF _ _ c])\napply (rule hoaret_sound [OF deriv_c1])\napply (rule hoare_sound [OF deriv_c2])\ndone\n\nlemma CombineStrip_sound:\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes valid_strip: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/{}\\<^esub> P (strip_guards (-F) c) UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n    by (auto simp add: validt_def)\n  from ctxt have ctxt'': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases t)\n    case (Normal t')\n    from cvalidt_postD [OF valid ctxt'' exec P] Normal\n    show ?thesis\n      by auto\n  next\n    case (Abrupt t')\n    from cvalidt_postD [OF valid ctxt'' exec P] Abrupt\n    show ?thesis\n      by auto\n  next\n    case (Fault f)\n    show ?thesis\n    proof (cases \"f \\<in> F\")\n      case True\n      hence \"f \\<notin> -F\" by simp\n      with exec Fault\n      have \"\\<Gamma>\\<turnstile>\\<langle>strip_guards (-F) c,Normal s\\<rangle> \\<Rightarrow> Fault f\"\n        by (auto intro: exec_to_exec_strip_guards_Fault)\n      from cvalidD [OF valid_strip ctxt' this P] Fault\n      have False\n        by auto\n      thus ?thesis ..\n    next\n      case False\n      with cvalidt_postD [OF valid ctxt'' exec P] Fault\n      show ?thesis\n        by auto\n    qed\n  next\n    case Stuck\n    from cvalidt_postD [OF valid ctxt'' exec P] Stuck\n    show ?thesis\n      by auto\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  assume P: \"s \\<in> P\"\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n  proof -\n    from valid ctxt' P\n    show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n      by (rule cvalidt_termD)\n  qed\nqed\n\nlemma CombineStrip:\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes deriv_strip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P (strip_guards (-F) c) UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule CombineStrip_sound)\napply  (iprover intro: hoaret_sound [OF deriv])\napply (iprover intro: hoare_sound [OF deriv_strip])\ndone\n\nlemma GuardsFlip_sound:\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes validFlip: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/-F\\<^esub> P c UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  from ctxt have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  from ctxt have ctxtFlip: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^bsub>/-F\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases t)\n    case (Normal t')\n    from cvalidt_postD [OF valid ctxt' exec P] Normal\n    show ?thesis\n      by auto\n  next\n    case (Abrupt t')\n    from cvalidt_postD [OF valid ctxt' exec P] Abrupt\n    show ?thesis\n      by auto\n  next\n    case (Fault f)\n    show ?thesis\n    proof (cases \"f \\<in> F\")\n      case True\n      hence \"f \\<notin> -F\" by simp\n      with cvalidD [OF validFlip ctxtFlip exec P] Fault\n      have False\n        by auto\n      thus ?thesis ..\n    next\n      case False\n      with cvalidt_postD [OF valid ctxt' exec P] Fault\n      show ?thesis\n        by auto\n    qed\n  next\n    case Stuck\n    from cvalidt_postD [OF valid ctxt' exec P] Stuck\n    show ?thesis\n      by auto\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  assume P: \"s \\<in> P\"\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n  proof -\n    from valid ctxt' P\n    show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n      by (rule cvalidt_termD)\n  qed\nqed\n\n\nlemma GuardsFlip:\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes derivFlip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/-F\\<^esub> P c UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule GuardsFlip_sound)\napply  (iprover intro: hoaret_sound [OF deriv])\napply (iprover intro: hoare_sound [OF derivFlip])\ndone\n\nlemma MarkGuardsI_sound:\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c,Normal s\\<rangle> \\<Rightarrow> t\"\n  from exec_mark_guards_to_exec [OF exec] obtain t' where\n    exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t'\" and\n    t'_noFault: \"\\<not> isFault t' \\<longrightarrow> t' = t\"\n    by blast\n  assume P: \"s \\<in> P\"\n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof -\n    from cvalidt_postD [OF valid [rule_format] ctxt exec_c P]\n    have \"t' \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by blast\n    with t'_noFault\n    show ?thesis\n      by auto\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>mark_guards f c \\<down> Normal s\"\n    by (rule terminates_to_terminates_mark_guards)\nqed\n\nlemma MarkGuardsI:\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\"\napply (rule hoaret_complete')\napply (rule MarkGuardsI_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\n\nlemma MarkGuardsD_sound:\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases \"isFault t\")\n    case True\n    with exec_to_exec_mark_guards_Fault exec\n    obtain f' where \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c,Normal s\\<rangle> \\<Rightarrow> Fault f'\"\n      by (fastforce elim: isFaultE)\n    from cvalidt_postD [OF valid [rule_format] ctxt this P]\n    have False\n      by auto\n    thus ?thesis ..\n  next\n    case False\n    from exec_to_exec_mark_guards [OF exec False]\n    obtain f' where \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by auto\n    from cvalidt_postD [OF valid [rule_format] ctxt this P]\n    show ?thesis\n      by auto\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>mark_guards f c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule terminates_mark_guards_to_terminates)\nqed\n\nlemma MarkGuardsD:\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule MarkGuardsD_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nlemma MergeGuardsI_sound:\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P merge_guards c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume exec_merge: \"\\<Gamma>\\<turnstile>\\<langle>merge_guards c,Normal s\\<rangle> \\<Rightarrow> t\"\n  from exec_merge_guards_to_exec [OF exec_merge]\n  have exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" .\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec P t_notin_F]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>merge_guards c \\<down> Normal s\"\n    by (rule terminates_to_terminates_merge_guards)\nqed\n\nlemma MergeGuardsI:\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P merge_guards c Q,A\"\napply (rule hoaret_complete')\napply (rule MergeGuardsI_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nlemma MergeGuardsD_sound:\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P merge_guards c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n  from exec_to_exec_merge_guards [OF exec]\n  have exec_merge: \"\\<Gamma>\\<turnstile>\\<langle>merge_guards c,Normal s\\<rangle> \\<Rightarrow> t\".\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec_merge P t_notin_F]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>merge_guards c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule terminates_merge_guards_to_terminates)\nqed\n\n\n\n\nlemma SubsetGuards_sound:\n  assumes c_c': \"c \\<subseteq>\\<^sub>g c'\"\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c' Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n  from exec_to_exec_subseteq_guards [OF c_c' exec] obtain t' where\n    exec_c': \"\\<Gamma>\\<turnstile>\\<langle>c',Normal s\\<rangle> \\<Rightarrow> t'\" and\n    t'_noFault: \"\\<not> isFault t' \\<longrightarrow> t' = t\"\n    by blast\n  assume P: \"s \\<in> P\"\n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec_c' P] t'_noFault t_noFault\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    by auto\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  from cvalidt_termD [OF valid ctxt P]\n  have termi_c': \"\\<Gamma>\\<turnstile>c' \\<down> Normal s\".\n  from cvalidt_postD [OF valid ctxt _ P]\n  have noFault_c': \"\\<Gamma>\\<turnstile>\\<langle>c',Normal s\\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\"\n    by (auto simp add: final_notin_def)\n  from termi_c' c_c' noFault_c'\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule terminates_fewer_guards)\nqed\n\nlemma SubsetGuards:\n  assumes c_c': \"c \\<subseteq>\\<^sub>g c'\"\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c' Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule SubsetGuards_sound [OF c_c'])\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nlemma NormalizeD_sound:\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n  hence exec_norm: \"\\<Gamma>\\<turnstile>\\<langle>normalize c,Normal s\\<rangle> \\<Rightarrow> t\"\n    by (rule exec_to_exec_normalize)\n  assume P: \"s \\<in> P\"\n  assume noFault: \"t \\<notin> Fault ` F\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec_norm P noFault]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>normalize c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule terminates_normalize_to_terminates)\nqed\n\nlemma NormalizeD:\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule NormalizeD_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nlemma NormalizeI_sound:\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume \"\\<Gamma>\\<turnstile>\\<langle>normalize c,Normal s\\<rangle> \\<Rightarrow> t\"\n  hence exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n    by (rule exec_normalize_to_exec)\n  assume P: \"s \\<in> P\"\n  assume noFault: \"t \\<notin> Fault ` F\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec P noFault]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile> c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>normalize c \\<down> Normal s\"\n    by (rule terminates_to_terminates_normalize)\nqed\n\nlemma NormalizeI:\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\napply (rule hoaret_complete')\napply (rule NormalizeI_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nsubsubsection \\<open>Restricting the Procedure Environment\\<close>\n\nlemma validt_restrict_to_validt:\nassumes validt_c: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nshows \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from validt_c\n  have valid_c: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\" by (simp add: validt_def)\n  hence \"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\" by (rule valid_restrict_to_valid)\n  moreover\n  {\n    fix s\n    assume P: \"s \\<in> P\"\n    have \"\\<Gamma>\\<turnstile>c\\<down>Normal s\"\n    proof -\n      from P validt_c have \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>c\\<down>Normal s\"\n        by (auto simp add: validt_def)\n      moreover\n      from P valid_c\n      have \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>{Stuck}\"\n        by (auto simp add: valid_def  final_notin_def)\n      ultimately show ?thesis\n        by (rule terminates_restrict_to_terminates)\n    qed\n   }\n   ultimately show ?thesis\n     by (auto simp add: validt_def)\nqed\n\n\nlemma augment_procs:\nassumes deriv_c: \"\\<Gamma>|\\<^bsub>M\\<^esub>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nshows \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule hoaret_complete)\n  apply (rule validt_restrict_to_validt)\n  apply (insert hoaret_sound [OF deriv_c])\n  by (simp add: cvalidt_def)\n\nsubsubsection \\<open>Miscellaneous\\<close>\n\nlemma augment_Faults:\nassumes deriv_c: \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nassumes F: \"F \\<subseteq> F'\"\nshows \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F'\\<^esub> P c Q,A\"\n  apply (rule hoaret_complete)\n  apply (rule validt_augment_Faults [OF _ F])\n  apply (insert hoaret_sound [OF deriv_c])\n  by (simp add: cvalidt_def)\n\nlemma TerminationPartial_sound:\n  assumes \"termination\": \"\\<forall>s \\<in> P. \\<Gamma>\\<turnstile>c\\<down>Normal s\"\n  assumes partial_corr: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nusing \"termination\" partial_corr\nby (auto simp add: cvalidt_def validt_def cvalid_def)\n\nlemma TerminationPartial:\n  assumes partial_deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes \"termination\": \"\\<forall>s \\<in> P. \\<Gamma>\\<turnstile>c\\<down>Normal s\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule hoaret_complete')\n  apply (rule TerminationPartial_sound [OF \"termination\"])\n  apply (rule hoare_sound [OF partial_deriv])\n  done\n\nlemma TerminationPartialStrip:\n  assumes partial_deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes \"termination\": \"\\<forall>s \\<in> P. strip F' \\<Gamma>\\<turnstile>strip_guards F' c\\<down>Normal s\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from \"termination\" have \"\\<forall>s \\<in> P. \\<Gamma>\\<turnstile>c\\<down>Normal s\"\n    by (auto intro: terminates_strip_guards_to_terminates\n      terminates_strip_to_terminates)\n  with partial_deriv\n  show ?thesis\n    by (rule TerminationPartial)\nqed\n\nlemma SplitTotalPartial:\n  assumes termi: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q',A'\"\n  assumes part: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from hoaret_sound [OF termi] hoare_sound [OF part]\n  have \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (fastforce simp add: cvalidt_def validt_def cvalid_def valid_def)\n  thus ?thesis\n    by (rule hoaret_complete')\nqed\n\nlemma SplitTotalPartial':\n  assumes termi: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/UNIV\\<^esub> P c Q',A'\"\n  assumes part: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from hoaret_sound [OF termi] hoare_sound [OF part]\n  have \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (fastforce simp add: cvalidt_def validt_def cvalid_def valid_def)\n  thus ?thesis\n    by (rule hoaret_complete')\nqed\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/c-parser/Simpl/HoareTotalProps.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.26738624997152294}}
{"text": "section \\<open>Instantiate framework with control dependences\\<close>\n\ntheory CDepInstantiations imports \n  Slice \n  PDG \n  WeakOrderDependence \nbegin\n\nsubsection\\<open>Standard control dependence\\<close>\n\ncontext StandardControlDependencePDG begin\n\nlemma Exit_in_obs_slice_node:\"(_Exit_) \\<in> obs n' (PDG_BS S) \\<Longrightarrow> (_Exit_) \\<in> S\"\n  by(auto elim:obsE PDG_path_CFG_path simp:PDG_BS_def split:if_split_asm)\n\n\nabbreviation PDG_path' :: \"'node \\<Rightarrow> 'node \\<Rightarrow> bool\" (\"_ \\<longrightarrow>\\<^sub>d* _\" [51,0] 80)\n  where \"n \\<longrightarrow>\\<^sub>d* n' \\<equiv> PDG.PDG_path sourcenode targetnode valid_edge Def Use\n  standard_control_dependence n n'\"\n\nlemma cd_closed:\n  \"\\<lbrakk>n' \\<in> PDG_BS S; n controls\\<^sub>s n'\\<rbrakk> \\<Longrightarrow> n \\<in> PDG_BS S\"\n  by(simp add:PDG_BS_def)(blast dest:PDG_cdep_edge PDG_path_Append PDG_path_cdep)\n\n\nlemma obs_postdominate:\n  assumes \"n \\<in> obs n' (PDG_BS S)\" and \"n \\<noteq> (_Exit_)\" shows \"n postdominates n'\"\nproof(rule ccontr)\n  assume \"\\<not> n postdominates n'\"\n  from \\<open>n \\<in> obs n' (PDG_BS S)\\<close> have \"valid_node n\" by(fastforce dest:in_obs_valid)\n  with \\<open>n \\<in> obs n' (PDG_BS S)\\<close> \\<open>n \\<noteq> (_Exit_)\\<close> have \"n postdominates n\"\n    by(fastforce intro:postdominate_refl)\n  from \\<open>n \\<in> obs n' (PDG_BS S)\\<close> obtain as where \"n' -as\\<rightarrow>* n\"\n    and \"\\<forall>n' \\<in> set(sourcenodes as). n' \\<notin> (PDG_BS S)\"\n    and \"n \\<in> (PDG_BS S)\" by(erule obsE)\n  from \\<open>n postdominates n\\<close> \\<open>\\<not> n postdominates n'\\<close> \\<open>n' -as\\<rightarrow>* n\\<close>\n  obtain as' a as'' where [simp]:\"as = as'@a#as''\" and \"valid_edge a\"\n    and \"\\<not> n postdominates (sourcenode a)\" and \"n postdominates (targetnode a)\"\n    by -(erule postdominate_path_branch)\n  from \\<open>\\<not> n postdominates (sourcenode a)\\<close> \\<open>valid_edge a\\<close> \\<open>valid_node n\\<close>\n  obtain asx  where \"sourcenode a -asx\\<rightarrow>* (_Exit_)\"\n    and \"n \\<notin> set(sourcenodes asx)\" by(auto simp:postdominate_def)\n  from \\<open>sourcenode a -asx\\<rightarrow>* (_Exit_)\\<close> \\<open>valid_edge a\\<close>\n  obtain ax asx' where [simp]:\"asx = ax#asx'\"\n    apply - apply(erule path.cases)\n    apply(drule_tac s=\"(_Exit_)\" in sym)\n    apply simp\n    apply(drule Exit_source)\n    by simp_all\n  with \\<open>sourcenode a -asx\\<rightarrow>* (_Exit_)\\<close> have \"sourcenode a -[]@ax#asx'\\<rightarrow>* (_Exit_)\" \n    by simp\n  hence \"valid_edge ax\" and [simp]:\"sourcenode a = sourcenode ax\"\n    and \"targetnode ax -asx'\\<rightarrow>* (_Exit_)\"\n    by(fastforce dest:path_split)+\n  with \\<open>n \\<notin> set(sourcenodes asx)\\<close> have \"\\<not> n postdominates targetnode ax\"\n    by(fastforce simp:postdominate_def sourcenodes_def)\n  from \\<open>n \\<in> obs n' (PDG_BS S)\\<close> \\<open>\\<forall>n' \\<in> set(sourcenodes as). n' \\<notin> (PDG_BS S)\\<close>\n  have \"n \\<notin> set (sourcenodes (a#as''))\"\n    by(fastforce elim:obs.cases simp:sourcenodes_def)\n  from \\<open>n' -as\\<rightarrow>* n\\<close> have \"sourcenode a -a#as''\\<rightarrow>* n\"\n    by(fastforce dest:path_split_second)\n  with \\<open>n postdominates (targetnode a)\\<close> \\<open>\\<not> n postdominates targetnode ax\\<close>\n    \\<open>valid_edge ax\\<close> \\<open>n \\<notin> set (sourcenodes (a#as''))\\<close>\n  have \"sourcenode a controls\\<^sub>s n\" by(fastforce simp:standard_control_dependence_def)\n  with \\<open>n \\<in> obs n' (PDG_BS S)\\<close> have \"sourcenode a \\<in> (PDG_BS S)\"\n    by(fastforce intro:cd_closed PDG_cdep_edge elim:obs.cases)\n  with \\<open>\\<forall>n' \\<in> set(sourcenodes as). n' \\<notin> (PDG_BS S)\\<close> \n  show False by(simp add:sourcenodes_def)\nqed\n\n\nlemma obs_singleton:\"(\\<exists>m. obs n (PDG_BS S) = {m}) \\<or> obs n (PDG_BS S) = {}\"\nproof(rule ccontr)\n  assume \"\\<not> ((\\<exists>m. obs n (PDG_BS S) = {m}) \\<or> obs n (PDG_BS S) = {})\"\n  hence \"\\<exists>nx nx'. nx \\<in> obs n (PDG_BS S) \\<and> nx' \\<in> obs n (PDG_BS S) \\<and>\n    nx \\<noteq> nx'\" by auto\n  then obtain nx nx' where \"nx \\<in> obs n (PDG_BS S)\" and \"nx' \\<in> obs n (PDG_BS S)\"\n    and \"nx \\<noteq> nx'\" by auto\n  from \\<open>nx \\<in> obs n (PDG_BS S)\\<close> obtain as where \"n -as\\<rightarrow>* nx\" \n    and \"\\<forall>n' \\<in> set(sourcenodes as). n' \\<notin> (PDG_BS S)\" and \"nx \\<in> (PDG_BS S)\" \n    by(erule obsE)\n  from \\<open>n -as\\<rightarrow>* nx\\<close> have \"valid_node nx\" by(fastforce dest:path_valid_node)\n  with \\<open>nx \\<in> (PDG_BS S)\\<close> have \"obs nx (PDG_BS S) = {nx}\" by -(rule n_in_obs)\n  with \\<open>n -as\\<rightarrow>* nx\\<close> \\<open>nx \\<in> obs n (PDG_BS S)\\<close> \\<open>nx' \\<in> obs n (PDG_BS S)\\<close> \\<open>nx \\<noteq> nx'\\<close>\n  have \"as \\<noteq> []\" by(fastforce elim:path.cases)\n  with \\<open>n -as\\<rightarrow>* nx\\<close> \\<open>nx \\<in> obs n (PDG_BS S)\\<close> \\<open>nx' \\<in> obs n (PDG_BS S)\\<close> \n    \\<open>nx \\<noteq> nx'\\<close> \\<open>obs nx (PDG_BS S) = {nx}\\<close> \\<open>\\<forall>n' \\<in> set(sourcenodes as). n' \\<notin> (PDG_BS S)\\<close>\n  have \"\\<exists>a as' as''. n -as'\\<rightarrow>* sourcenode a \\<and> targetnode a -as''\\<rightarrow>* nx \\<and>\n                     valid_edge a \\<and> as = as'@a#as'' \\<and> \n                     obs (targetnode a) (PDG_BS S) = {nx} \\<and> \n                    (\\<not> (\\<exists>m. obs (sourcenode a) (PDG_BS S) = {m} \\<or> \n                       obs (sourcenode a) (PDG_BS S) = {}))\"\n  proof(induct arbitrary:nx' rule:path.induct)\n    case (Cons_path n'' as n' a n)\n    note [simp] = \\<open>sourcenode a = n\\<close>[THEN sym] \\<open>targetnode a = n''\\<close>[THEN sym]\n    note more_than_one = \\<open>n' \\<in> obs n (PDG_BS S)\\<close> \\<open>nx' \\<in> obs n (PDG_BS S)\\<close> \\<open>n' \\<noteq> nx'\\<close>\n    note IH = \\<open>\\<And>nx'. \\<lbrakk>n' \\<in> obs n'' (PDG_BS S); nx' \\<in> obs n'' (PDG_BS S); n' \\<noteq> nx'; \n      obs n' (PDG_BS S) = {n'}; \\<forall>n'\\<in>set (sourcenodes as). n' \\<notin> (PDG_BS S); as \\<noteq> []\\<rbrakk>\n      \\<Longrightarrow> \\<exists>a as' as''. n'' -as'\\<rightarrow>* sourcenode a \\<and> targetnode a -as''\\<rightarrow>* n' \\<and>\n      valid_edge a \\<and> as = as'@a#as'' \\<and> obs (targetnode a) (PDG_BS S) = {n'} \\<and>\n      (\\<not> (\\<exists>m. obs (sourcenode a) (PDG_BS S) = {m} \\<or> \n      obs (sourcenode a) (PDG_BS S) = {}))\\<close>\n    from \\<open>\\<forall>n'\\<in>set (sourcenodes (a#as)). n' \\<notin> (PDG_BS S)\\<close>\n    have \"\\<forall>n'\\<in>set (sourcenodes as). n' \\<notin> (PDG_BS S)\" and \"sourcenode a \\<notin> (PDG_BS S)\"\n      by(simp_all add:sourcenodes_def)\n    show ?case\n    proof(cases \"as = []\")\n      case True\n      with \\<open>n'' -as\\<rightarrow>* n'\\<close> have [simp]:\"n' = n''\" by(fastforce elim:path.cases)\n      from more_than_one\n      have \"\\<not> (\\<exists>m. obs (sourcenode a) (PDG_BS S) = {m} \\<or> \n               obs (sourcenode a) (PDG_BS S) = {})\"\n        by auto\n      with \\<open>obs n' (PDG_BS S) = {n'}\\<close> True \\<open>valid_edge a\\<close> show ?thesis\n        apply(rule_tac x=\"a\" in exI)\n        apply(rule_tac x=\"[]\" in exI)\n        apply(rule_tac x=\"[]\" in exI)\n        by(auto intro!:empty_path)\n    next\n      case False\n      hence \"as \\<noteq> []\" .\n      from \\<open>n'' -as\\<rightarrow>* n'\\<close> \\<open>\\<forall>n'\\<in>set (sourcenodes as). n' \\<notin> (PDG_BS S)\\<close> \n      have \"obs n' (PDG_BS S) \\<subseteq> obs n'' (PDG_BS S)\" by(rule path_obs_subset)\n      show ?thesis\n      proof(cases \"obs n' (PDG_BS S) = obs n'' (PDG_BS S)\")\n        case True\n        with \\<open>n'' -as\\<rightarrow>* n'\\<close> \\<open>valid_edge a\\<close> \\<open>obs n' (PDG_BS S) = {n'}\\<close> more_than_one\n        show ?thesis\n          apply(rule_tac x=\"a\" in exI)\n          apply(rule_tac x=\"[]\" in exI)\n          apply(rule_tac x=\"as\" in exI)\n          by(fastforce intro:empty_path)\n      next\n        case False\n        with \\<open>obs n' (PDG_BS S) \\<subseteq> obs n'' (PDG_BS S)\\<close>\n        have \"obs n' (PDG_BS S) \\<subset> obs n'' (PDG_BS S)\" by simp\n        with \\<open>obs n' (PDG_BS S) = {n'}\\<close> obtain ni where \"n' \\<in> obs n'' (PDG_BS S)\"\n          and \"ni \\<in> obs n'' (PDG_BS S)\" and \"n' \\<noteq> ni\" by auto\n        from IH[OF this \\<open>obs n' (PDG_BS S) = {n'}\\<close> \n          \\<open>\\<forall>n'\\<in>set (sourcenodes as). n' \\<notin> (PDG_BS S)\\<close> \\<open>as \\<noteq> []\\<close>] obtain a' as' as''\n          where \"n'' -as'\\<rightarrow>* sourcenode a'\" and \"targetnode a' -as''\\<rightarrow>* n'\"\n          and \"valid_edge a'\" and [simp]:\"as = as'@a'#as''\" \n          and \"obs (targetnode a') (PDG_BS S) = {n'}\"\n          and more_than_one':\"\\<not> (\\<exists>m. obs (sourcenode a') (PDG_BS S) = {m} \\<or> \n          obs (sourcenode a') (PDG_BS S) = {})\"\n          by blast\n        from \\<open>n'' -as'\\<rightarrow>* sourcenode a'\\<close> \\<open>valid_edge a\\<close>\n        have \"n -a#as'\\<rightarrow>* sourcenode a'\" by(fastforce intro:path.Cons_path)\n        with \\<open>targetnode a' -as''\\<rightarrow>* n'\\<close> \\<open>obs (targetnode a') (PDG_BS S) = {n'}\\<close>\n          more_than_one' \\<open>valid_edge a'\\<close> show ?thesis\n          apply(rule_tac x=\"a'\" in exI)\n          apply(rule_tac x=\"a#as'\" in exI)\n          apply(rule_tac x=\"as''\" in exI)\n          by fastforce\n      qed\n    qed\n  qed simp\n  then obtain a as' as'' where \"valid_edge a\"\n    and \"obs (targetnode a) (PDG_BS S) = {nx}\"\n    and more_than_one:\"\\<not> (\\<exists>m. obs (sourcenode a) (PDG_BS S) = {m} \\<or> \n                         obs (sourcenode a) (PDG_BS S) = {})\"\n    by blast\n  have \"sourcenode a \\<notin> (PDG_BS S)\"\n  proof(rule ccontr)\n    assume \"\\<not> sourcenode a \\<notin> PDG_BS S\"\n    hence \"sourcenode a \\<in> PDG_BS S\" by simp\n    with \\<open>valid_edge a\\<close> have \"obs (sourcenode a) (PDG_BS S) = {sourcenode a}\"\n      by(fastforce intro!:n_in_obs)\n    with more_than_one show False by simp\n  qed\n  with \\<open>valid_edge a\\<close> \n  have \"obs (targetnode a) (PDG_BS S) \\<subseteq> obs (sourcenode a) (PDG_BS S)\"\n    by(rule edge_obs_subset)\n  with \\<open>obs (targetnode a) (PDG_BS S) = {nx}\\<close> \n  have \"nx \\<in> obs (sourcenode a) (PDG_BS S)\" by simp\n  with more_than_one obtain m  where \"m \\<in> obs (sourcenode a) (PDG_BS S)\"\n    and \"nx \\<noteq> m\" by auto\n  from \\<open>m \\<in> obs (sourcenode a) (PDG_BS S)\\<close> \n  have \"valid_node m\" by(fastforce dest:in_obs_valid)\n  from \\<open>obs (targetnode a) (PDG_BS S) = {nx}\\<close> have \"valid_node nx\" \n    by(fastforce dest:in_obs_valid)\n  show False\n  proof(cases \"m postdominates (sourcenode a)\")\n    case True\n    with \\<open>nx \\<in> obs (sourcenode a) (PDG_BS S)\\<close> \\<open>m \\<in> obs (sourcenode a) (PDG_BS S)\\<close>\n    have \"m postdominates nx\"\n      by(fastforce intro:postdominate_path_targetnode elim:obs.cases)\n    with \\<open>nx \\<noteq> m\\<close> have \"\\<not> nx postdominates m\" by(fastforce dest:postdominate_antisym)\n    have \"(_Exit_) -[]\\<rightarrow>* (_Exit_)\" by(fastforce intro:empty_path)\n    with \\<open>m postdominates nx\\<close> have \"nx \\<noteq> (_Exit_)\"\n      by(fastforce simp:postdominate_def sourcenodes_def)\n    have \"\\<not> nx postdominates (sourcenode a)\"\n    proof(rule ccontr)\n      assume \"\\<not> \\<not> nx postdominates sourcenode a\"\n      hence \"nx postdominates sourcenode a\" by simp\n      from \\<open>m \\<in> obs (sourcenode a) (PDG_BS S)\\<close> \\<open>nx \\<in> obs (sourcenode a) (PDG_BS S)\\<close>\n      obtain asx' where \"sourcenode a -asx'\\<rightarrow>* m\" and \"nx \\<notin> set(sourcenodes asx')\"\n        by(fastforce elim:obs.cases)\n      with \\<open>nx postdominates sourcenode a\\<close> have \"nx postdominates m\"\n        by(rule postdominate_path_targetnode)\n      with \\<open>\\<not> nx postdominates m\\<close> show False by simp\n    qed\n    with \\<open>nx \\<in> obs (sourcenode a) (PDG_BS S)\\<close> \\<open>valid_node nx\\<close> \\<open>nx \\<noteq> (_Exit_)\\<close> \n    show False by(fastforce dest:obs_postdominate)\n  next\n    case False\n    show False\n    proof(cases \"m = Exit\")\n      case True\n      from \\<open>m \\<in> obs (sourcenode a) (PDG_BS S)\\<close> \\<open>nx \\<in> obs (sourcenode a) (PDG_BS S)\\<close>\n      obtain xs where \"sourcenode a -xs\\<rightarrow>* m\" and \"nx \\<notin> set(sourcenodes xs)\"\n        by(fastforce elim:obsE)\n      obtain x' xs' where [simp]:\"xs = x'#xs'\"\n      proof(cases xs)\n        case Nil\n        with \\<open>sourcenode a -xs\\<rightarrow>* m\\<close> have [simp]:\"sourcenode a = m\" by fastforce\n        with \\<open>m \\<in> obs (sourcenode a) (PDG_BS S)\\<close> \n        have \"m \\<in> (PDG_BS S)\" by(metis obsE)\n        with \\<open>valid_node m\\<close> have \"obs m (PDG_BS S) = {m}\"\n          by(rule n_in_obs)\n        with \\<open>nx \\<in> obs (sourcenode a) (PDG_BS S)\\<close> \\<open>nx \\<noteq> m\\<close> have False\n          by fastforce\n        thus ?thesis by simp\n      qed blast\n      from \\<open>sourcenode a -xs\\<rightarrow>* m\\<close> have \"sourcenode a = sourcenode x'\" \n        and \"valid_edge x'\" and \"targetnode x' -xs'\\<rightarrow>* m\"\n        by(auto elim:path_split_Cons)\n      from \\<open>targetnode x' -xs'\\<rightarrow>* m\\<close> \\<open>nx \\<notin> set(sourcenodes xs)\\<close> \\<open>valid_edge x'\\<close> \n        \\<open>valid_node m\\<close> True\n      have \"\\<not> nx postdominates (targetnode x')\" \n        by(fastforce simp:postdominate_def sourcenodes_def)\n      from \\<open>nx \\<noteq> m\\<close> True have \"nx \\<noteq> (_Exit_)\" by simp\n      with \\<open>obs (targetnode a) (PDG_BS S) = {nx}\\<close>\n      have \"nx postdominates (targetnode a)\"\n        by(fastforce intro:obs_postdominate)\n      from \\<open>obs (targetnode a) (PDG_BS S) = {nx}\\<close>\n      obtain ys where \"targetnode a -ys\\<rightarrow>* nx\" \n        and \"\\<forall>nx' \\<in> set(sourcenodes ys). nx' \\<notin> (PDG_BS S)\"\n        and \"nx \\<in> (PDG_BS S)\" by(fastforce elim:obsE)\n      hence \"nx \\<notin> set(sourcenodes ys)\"by fastforce\n      have \"sourcenode a \\<noteq> nx\"\n      proof\n        assume \"sourcenode a = nx\"\n        from \\<open>nx \\<in> obs (sourcenode a) (PDG_BS S)\\<close>\n        have \"nx \\<in> (PDG_BS S)\" by -(erule obsE)\n        with \\<open>valid_node nx\\<close> have \"obs nx (PDG_BS S) = {nx}\" by -(erule n_in_obs)\n        with \\<open>sourcenode a = nx\\<close> \\<open>m \\<in> obs (sourcenode a) (PDG_BS S)\\<close> \n          \\<open>nx \\<noteq> m\\<close> show False by fastforce\n      qed\n      with \\<open>nx \\<notin> set(sourcenodes ys)\\<close> have \"nx \\<notin> set(sourcenodes (a#ys))\"\n        by(fastforce simp:sourcenodes_def)\n      from \\<open>valid_edge a\\<close> \\<open>targetnode a -ys\\<rightarrow>* nx\\<close>\n      have \"sourcenode a -a#ys\\<rightarrow>* nx\" by(fastforce intro:Cons_path)\n      from \\<open>sourcenode a -a#ys\\<rightarrow>* nx\\<close> \\<open>nx \\<notin> set(sourcenodes (a#ys))\\<close>\n        \\<open>nx postdominates (targetnode a)\\<close> \\<open>valid_edge x'\\<close>\n        \\<open>\\<not> nx postdominates (targetnode x')\\<close> \\<open>sourcenode a = sourcenode x'\\<close>\n      have \"(sourcenode a) controls\\<^sub>s nx\"\n        by(fastforce simp:standard_control_dependence_def)\n      with \\<open>nx \\<in> (PDG_BS S)\\<close> have \"sourcenode a \\<in> (PDG_BS S)\"\n        by(rule cd_closed)\n      with \\<open>valid_edge a\\<close> have \"obs (sourcenode a) (PDG_BS S) = {sourcenode a}\"\n        by(fastforce intro!:n_in_obs)\n      with \\<open>m \\<in> obs (sourcenode a) (PDG_BS S)\\<close>\n        \\<open>nx \\<in> obs (sourcenode a) (PDG_BS S)\\<close> \\<open>nx \\<noteq> m\\<close>\n      show False by simp\n    next\n      case False\n      with \\<open>m \\<in> obs (sourcenode a) (PDG_BS S)\\<close> \\<open>valid_node m\\<close>\n        \\<open>\\<not> m postdominates sourcenode a\\<close> \n      show False by(fastforce dest:obs_postdominate)\n    qed\n  qed\nqed\n\n\nlemma PDGBackwardSliceCorrect:\n  \"BackwardSlice sourcenode targetnode kind valid_edge\n        (_Entry_) Def Use state_val PDG_BS\"\nproof(unfold_locales)\n  fix n S assume \"n \\<in> PDG_BS S\"\n  thus \"valid_node n\" by(rule PDG_BS_valid_node)\nnext\n  fix n S assume \"valid_node n\" and \"n \\<in> S\"\n  thus \"n \\<in> PDG_BS S\" by(fastforce intro:PDG_path_Nil simp:PDG_BS_def)\nnext\n  fix n' S n V\n  assume \"n' \\<in> PDG_BS S\" and \"n influences V in n'\"\n  thus \"n \\<in> PDG_BS S\"\n    by(auto dest:PDG.PDG_path_ddep[OF PDG_scd,OF PDG.PDG_ddep_edge[OF PDG_scd]]\n            dest:PDG_path_Append simp:PDG_BS_def split:if_split_asm)\nnext\n  fix n S\n  have \"(\\<exists>m. obs n (PDG_BS S) = {m}) \\<or> obs n (PDG_BS S) = {}\" \n    by(rule obs_singleton)\n  thus \"finite (obs n (PDG_BS S))\" by fastforce\nnext\n  fix n S\n  have \"(\\<exists>m. obs n (PDG_BS S) = {m}) \\<or> obs n (PDG_BS S) = {}\" \n    by(rule obs_singleton)\n  thus \"card (obs n (PDG_BS S)) \\<le> 1\" by fastforce\nqed\n\nend\n\n\nsubsection\\<open>Weak control dependence\\<close>\n\ncontext WeakControlDependencePDG begin\n\nlemma Exit_in_obs_slice_node:\"(_Exit_) \\<in> obs n' (PDG_BS S) \\<Longrightarrow> (_Exit_) \\<in> S\"\n  by(auto elim:obsE PDG_path_CFG_path simp:PDG_BS_def split:if_split_asm)\n\n\nlemma cd_closed:\n  \"\\<lbrakk>n' \\<in> PDG_BS S; n weakly controls n'\\<rbrakk> \\<Longrightarrow> n \\<in> PDG_BS S\"\n  by(simp add:PDG_BS_def)(blast dest:PDG_cdep_edge PDG_path_Append PDG_path_cdep)\n\n\nlemma obs_strong_postdominate:\n  assumes \"n \\<in> obs n' (PDG_BS S)\" and \"n \\<noteq> (_Exit_)\" \n  shows \"n strongly-postdominates n'\"\nproof(rule ccontr)\n  assume \"\\<not> n strongly-postdominates n'\"\n  from \\<open>n \\<in> obs n' (PDG_BS S)\\<close> have \"valid_node n\" by(fastforce dest:in_obs_valid)\n  with \\<open>n \\<in> obs n' (PDG_BS S)\\<close> \\<open>n \\<noteq> (_Exit_)\\<close> have \"n strongly-postdominates n\"\n    by(fastforce intro:strong_postdominate_refl)\n  from \\<open>n \\<in> obs n' (PDG_BS S)\\<close> obtain as where \"n' -as\\<rightarrow>* n\"\n    and \"\\<forall>n' \\<in> set(sourcenodes as). n' \\<notin> (PDG_BS S)\"\n    and \"n \\<in> (PDG_BS S)\" by(erule obsE)\n  from \\<open>n strongly-postdominates n\\<close> \\<open>\\<not> n strongly-postdominates n'\\<close> \\<open>n' -as\\<rightarrow>* n\\<close>\n  obtain as' a as'' where [simp]:\"as = as'@a#as''\" and \"valid_edge a\"\n    and \"\\<not> n strongly-postdominates (sourcenode a)\" and \n    \"n strongly-postdominates (targetnode a)\"\n    by -(erule strong_postdominate_path_branch)\n  from \\<open>n \\<in> obs n' (PDG_BS S)\\<close> \\<open>\\<forall>n' \\<in> set(sourcenodes as). n' \\<notin> (PDG_BS S)\\<close> \n  have \"n \\<notin> set (sourcenodes (a#as''))\"\n    by(fastforce elim:obs.cases simp:sourcenodes_def)\n  from \\<open>n' -as\\<rightarrow>* n\\<close> have \"sourcenode a -a#as''\\<rightarrow>* n\"\n    by(fastforce dest:path_split_second)\n  from \\<open>\\<not> n strongly-postdominates (sourcenode a)\\<close> \\<open>valid_edge a\\<close> \\<open>valid_node n\\<close>\n  obtain a' where \"sourcenode a' = sourcenode a\"\n    and \"valid_edge a'\" and \"\\<not> n strongly-postdominates (targetnode a')\"\n    by(fastforce elim:not_strong_postdominate_predecessor_successor)\n  with \\<open>n strongly-postdominates (targetnode a)\\<close> \\<open>n \\<notin> set (sourcenodes (a#as''))\\<close>\n    \\<open>sourcenode a -a#as''\\<rightarrow>* n\\<close>\n  have \"sourcenode a weakly controls n\"\n    by(fastforce simp:weak_control_dependence_def)\n  with \\<open>n \\<in> obs n' (PDG_BS S)\\<close> have \"sourcenode a \\<in> (PDG_BS S)\"\n    by(fastforce intro:cd_closed PDG_cdep_edge elim:obs.cases)\n  with \\<open>\\<forall>n' \\<in> set(sourcenodes as). n' \\<notin> (PDG_BS S)\\<close>\n  show False by(simp add:sourcenodes_def)\nqed\n\n\nlemma obs_singleton:\"(\\<exists>m. obs n (PDG_BS S) = {m}) \\<or> obs n (PDG_BS S) = {}\"\nproof(rule ccontr)\n  assume \"\\<not> ((\\<exists>m. obs n (PDG_BS S) = {m}) \\<or> obs n (PDG_BS S) = {})\"\n  hence \"\\<exists>nx nx'. nx \\<in> obs n (PDG_BS S) \\<and> nx' \\<in> obs n (PDG_BS S) \\<and>\n    nx \\<noteq> nx'\" by auto\n  then obtain nx nx' where \"nx \\<in> obs n (PDG_BS S)\" and \"nx' \\<in> obs n (PDG_BS S)\"\n    and \"nx \\<noteq> nx'\" by auto\n  from \\<open>nx \\<in> obs n (PDG_BS S)\\<close> obtain as where \"n -as\\<rightarrow>* nx\" \n    and \"\\<forall>n' \\<in> set(sourcenodes as). n' \\<notin> (PDG_BS S)\" and \"nx \\<in> (PDG_BS S)\" \n    by(erule obsE)\n  from \\<open>n -as\\<rightarrow>* nx\\<close> have \"valid_node nx\" by(fastforce dest:path_valid_node)\n  with \\<open>nx \\<in> (PDG_BS S)\\<close> have \"obs nx (PDG_BS S) = {nx}\" by -(rule n_in_obs)\n  with \\<open>n -as\\<rightarrow>* nx\\<close> \\<open>nx \\<in> obs n (PDG_BS S)\\<close> \\<open>nx' \\<in> obs n (PDG_BS S)\\<close> \\<open>nx \\<noteq> nx'\\<close>\n  have \"as \\<noteq> []\" by(fastforce elim:path.cases)\n  with \\<open>n -as\\<rightarrow>* nx\\<close> \\<open>nx \\<in> obs n (PDG_BS S)\\<close> \\<open>nx' \\<in> obs n (PDG_BS S)\\<close> \n    \\<open>nx \\<noteq> nx'\\<close> \\<open>obs nx (PDG_BS S) = {nx}\\<close> \\<open>\\<forall>n' \\<in> set(sourcenodes as). n' \\<notin> (PDG_BS S)\\<close>\n  have \"\\<exists>a as' as''. n -as'\\<rightarrow>* sourcenode a \\<and> targetnode a -as''\\<rightarrow>* nx \\<and>\n                     valid_edge a \\<and> as = as'@a#as'' \\<and> \n                     obs (targetnode a) (PDG_BS S) = {nx} \\<and> \n                    (\\<not> (\\<exists>m. obs (sourcenode a) (PDG_BS S) = {m} \\<or> \n                       obs (sourcenode a) (PDG_BS S) = {}))\"\n  proof(induct arbitrary:nx' rule:path.induct)\n    case (Cons_path n'' as n' a n)\n    note [simp] = \\<open>sourcenode a = n\\<close>[THEN sym] \\<open>targetnode a = n''\\<close>[THEN sym]\n    note more_than_one = \\<open>n' \\<in> obs n (PDG_BS S)\\<close> \\<open>nx' \\<in> obs n (PDG_BS S)\\<close> \\<open>n' \\<noteq> nx'\\<close>\n    note IH = \\<open>\\<And>nx'. \\<lbrakk>n' \\<in> obs n'' (PDG_BS S); nx' \\<in> obs n'' (PDG_BS S); n' \\<noteq> nx'; \n      obs n' (PDG_BS S) = {n'}; \\<forall>n'\\<in>set (sourcenodes as). n' \\<notin> (PDG_BS S); as \\<noteq> []\\<rbrakk>\n      \\<Longrightarrow> \\<exists>a as' as''. n'' -as'\\<rightarrow>* sourcenode a \\<and> targetnode a -as''\\<rightarrow>* n' \\<and>\n      valid_edge a \\<and> as = as'@a#as'' \\<and> obs (targetnode a) (PDG_BS S) = {n'} \\<and>\n      (\\<not> (\\<exists>m. obs (sourcenode a) (PDG_BS S) = {m} \\<or> \n      obs (sourcenode a) (PDG_BS S) = {}))\\<close>\n    from \\<open>\\<forall>n'\\<in>set (sourcenodes (a#as)). n' \\<notin> (PDG_BS S)\\<close>\n    have \"\\<forall>n'\\<in>set (sourcenodes as). n' \\<notin> (PDG_BS S)\" and \"sourcenode a \\<notin> (PDG_BS S)\"\n      by(simp_all add:sourcenodes_def)\n    show ?case\n    proof(cases \"as = []\")\n      case True\n      with \\<open>n'' -as\\<rightarrow>* n'\\<close> have [simp]:\"n' = n''\" by(fastforce elim:path.cases)\n      from more_than_one\n      have \"\\<not> (\\<exists>m. obs (sourcenode a) (PDG_BS S) = {m} \\<or> \n               obs (sourcenode a) (PDG_BS S) = {})\"\n        by auto\n      with \\<open>obs n' (PDG_BS S) = {n'}\\<close> True \\<open>valid_edge a\\<close> show ?thesis\n        apply(rule_tac x=\"a\" in exI)\n        apply(rule_tac x=\"[]\" in exI)\n        apply(rule_tac x=\"[]\" in exI)\n        by(auto intro!:empty_path)\n    next\n      case False\n      hence \"as \\<noteq> []\" .\n      from \\<open>n'' -as\\<rightarrow>* n'\\<close> \\<open>\\<forall>n'\\<in>set (sourcenodes as). n' \\<notin> (PDG_BS S)\\<close> \n      have \"obs n' (PDG_BS S) \\<subseteq> obs n'' (PDG_BS S)\" by(rule path_obs_subset)\n      show ?thesis\n      proof(cases \"obs n' (PDG_BS S) = obs n'' (PDG_BS S)\")\n        case True\n        with \\<open>n'' -as\\<rightarrow>* n'\\<close> \\<open>valid_edge a\\<close> \\<open>obs n' (PDG_BS S) = {n'}\\<close> more_than_one\n        show ?thesis\n          apply(rule_tac x=\"a\" in exI)\n          apply(rule_tac x=\"[]\" in exI)\n          apply(rule_tac x=\"as\" in exI)\n          by(fastforce intro:empty_path)\n      next\n        case False\n        with \\<open>obs n' (PDG_BS S) \\<subseteq> obs n'' (PDG_BS S)\\<close>\n        have \"obs n' (PDG_BS S) \\<subset> obs n'' (PDG_BS S)\" by simp\n        with \\<open>obs n' (PDG_BS S) = {n'}\\<close> obtain ni where \"n' \\<in> obs n'' (PDG_BS S)\"\n          and \"ni \\<in> obs n'' (PDG_BS S)\" and \"n' \\<noteq> ni\" by auto\n        from IH[OF this \\<open>obs n' (PDG_BS S) = {n'}\\<close> \n          \\<open>\\<forall>n'\\<in>set (sourcenodes as). n' \\<notin> (PDG_BS S)\\<close> \\<open>as \\<noteq> []\\<close>] obtain a' as' as''\n          where \"n'' -as'\\<rightarrow>* sourcenode a'\" and \"targetnode a' -as''\\<rightarrow>* n'\"\n          and \"valid_edge a'\" and [simp]:\"as = as'@a'#as''\" \n          and \"obs (targetnode a') (PDG_BS S) = {n'}\"\n          and more_than_one':\"\\<not> (\\<exists>m. obs (sourcenode a') (PDG_BS S) = {m} \\<or> \n          obs (sourcenode a') (PDG_BS S) = {})\"\n          by blast\n        from \\<open>n'' -as'\\<rightarrow>* sourcenode a'\\<close> \\<open>valid_edge a\\<close>\n        have \"n -a#as'\\<rightarrow>* sourcenode a'\" by(fastforce intro:path.Cons_path)\n        with \\<open>targetnode a' -as''\\<rightarrow>* n'\\<close> \\<open>obs (targetnode a') (PDG_BS S) = {n'}\\<close>\n          more_than_one' \\<open>valid_edge a'\\<close> show ?thesis\n          apply(rule_tac x=\"a'\" in exI)\n          apply(rule_tac x=\"a#as'\" in exI)\n          apply(rule_tac x=\"as''\" in exI)\n          by fastforce\n      qed\n    qed\n  qed simp\n  then obtain a as' as'' where \"valid_edge a\"\n    and \"obs (targetnode a) (PDG_BS S) = {nx}\"\n    and more_than_one:\"\\<not> (\\<exists>m. obs (sourcenode a) (PDG_BS S) = {m} \\<or> \n                         obs (sourcenode a) (PDG_BS S) = {})\"\n    by blast\n  have \"sourcenode a \\<notin> (PDG_BS S)\"\n  proof(rule ccontr)\n    assume \"\\<not> sourcenode a \\<notin> PDG_BS S\"\n    hence \"sourcenode a \\<in> PDG_BS S\" by simp\n    with \\<open>valid_edge a\\<close> have \"obs (sourcenode a) (PDG_BS S) = {sourcenode a}\"\n      by(fastforce intro!:n_in_obs)\n    with more_than_one show False by simp\n  qed\n  with \\<open>valid_edge a\\<close> \n  have \"obs (targetnode a) (PDG_BS S) \\<subseteq> obs (sourcenode a) (PDG_BS S)\"\n    by(rule edge_obs_subset)\n  with \\<open>obs (targetnode a) (PDG_BS S) = {nx}\\<close> \n  have \"nx \\<in> obs (sourcenode a) (PDG_BS S)\" by simp\n  with more_than_one obtain m  where \"m \\<in> obs (sourcenode a) (PDG_BS S)\"\n    and \"nx \\<noteq> m\" by auto\n  from \\<open>m \\<in> obs (sourcenode a) (PDG_BS S)\\<close> \n  have \"valid_node m\" by(fastforce dest:in_obs_valid)\n  from \\<open>obs (targetnode a) (PDG_BS S) = {nx}\\<close> have \"valid_node nx\" \n    by(fastforce dest:in_obs_valid)\n  show False\n  proof(cases \"m strongly-postdominates (sourcenode a)\")\n    case True\n    with \\<open>nx \\<in> obs (sourcenode a) (PDG_BS S)\\<close> \\<open>m \\<in> obs (sourcenode a) (PDG_BS S)\\<close>\n    have \"m strongly-postdominates nx\"\n      by(fastforce intro:strong_postdominate_path_targetnode elim:obs.cases)\n    with \\<open>nx \\<noteq> m\\<close> have \"\\<not> nx strongly-postdominates m\" \n      by(fastforce dest:strong_postdominate_antisym)\n    have \"(_Exit_) -[]\\<rightarrow>* (_Exit_)\" by(fastforce intro:empty_path)\n    with \\<open>m strongly-postdominates nx\\<close> have \"nx \\<noteq> (_Exit_)\"\n      by(fastforce simp:strong_postdominate_def sourcenodes_def postdominate_def)\n    have \"\\<not> nx strongly-postdominates (sourcenode a)\"\n    proof(rule ccontr)\n      assume \"\\<not> \\<not> nx strongly-postdominates sourcenode a\"\n      hence \"nx strongly-postdominates sourcenode a\" by simp\n      from \\<open>m \\<in> obs (sourcenode a) (PDG_BS S)\\<close> \\<open>nx \\<in> obs (sourcenode a) (PDG_BS S)\\<close>\n      obtain asx' where \"sourcenode a -asx'\\<rightarrow>* m\" and \"nx \\<notin> set(sourcenodes asx')\"\n        by(fastforce elim:obs.cases)\n      with \\<open>nx strongly-postdominates sourcenode a\\<close> have \"nx strongly-postdominates m\"\n        by(rule strong_postdominate_path_targetnode)\n      with \\<open>\\<not> nx strongly-postdominates m\\<close> show False by simp\n    qed\n    with \\<open>nx \\<in> obs (sourcenode a) (PDG_BS S)\\<close> \\<open>valid_node nx\\<close> \\<open>nx \\<noteq> (_Exit_)\\<close> \n    show False by(fastforce dest:obs_strong_postdominate)\n  next\n    case False\n    show False\n    proof(cases \"m = Exit\")\n      case True\n      from \\<open>m \\<in> obs (sourcenode a) (PDG_BS S)\\<close> \\<open>nx \\<in> obs (sourcenode a) (PDG_BS S)\\<close>\n      obtain xs where \"sourcenode a -xs\\<rightarrow>* m\" and \"nx \\<notin> set(sourcenodes xs)\"\n        by(fastforce elim:obsE)\n      obtain x' xs' where [simp]:\"xs = x'#xs'\"\n      proof(cases xs)\n        case Nil\n        with \\<open>sourcenode a -xs\\<rightarrow>* m\\<close> have [simp]:\"sourcenode a = m\" by fastforce\n        with \\<open>m \\<in> obs (sourcenode a) (PDG_BS S)\\<close> \n        have \"m \\<in> (PDG_BS S)\" by (metis obsE)\n        with \\<open>valid_node m\\<close> have \"obs m (PDG_BS S) = {m}\"\n          by(rule n_in_obs)\n        with \\<open>nx \\<in> obs (sourcenode a) (PDG_BS S)\\<close> \\<open>nx \\<noteq> m\\<close> have False\n          by fastforce\n        thus ?thesis by simp\n      qed blast\n      from \\<open>sourcenode a -xs\\<rightarrow>* m\\<close> have \"sourcenode a = sourcenode x'\" \n        and \"valid_edge x'\" and \"targetnode x' -xs'\\<rightarrow>* m\"\n        by(auto elim:path_split_Cons)\n      from \\<open>targetnode x' -xs'\\<rightarrow>* m\\<close> \\<open>nx \\<notin> set(sourcenodes xs)\\<close> \\<open>valid_edge x'\\<close> \n        \\<open>valid_node m\\<close> True\n      have \"\\<not> nx strongly-postdominates (targetnode x')\" \n        by(fastforce simp:strong_postdominate_def postdominate_def sourcenodes_def)\n      from \\<open>nx \\<noteq> m\\<close> True have \"nx \\<noteq> (_Exit_)\" by simp\n      with \\<open>obs (targetnode a) (PDG_BS S) = {nx}\\<close>\n      have \"nx strongly-postdominates (targetnode a)\"\n        by(fastforce intro:obs_strong_postdominate)\n      from \\<open>obs (targetnode a) (PDG_BS S) = {nx}\\<close>\n      obtain ys where \"targetnode a -ys\\<rightarrow>* nx\" \n        and \"\\<forall>nx' \\<in> set(sourcenodes ys). nx' \\<notin> (PDG_BS S)\"\n        and \"nx \\<in> (PDG_BS S)\" by(fastforce elim:obsE)\n      hence \"nx \\<notin> set(sourcenodes ys)\"by fastforce\n      have \"sourcenode a \\<noteq> nx\"\n      proof\n        assume \"sourcenode a = nx\"\n        from \\<open>nx \\<in> obs (sourcenode a) (PDG_BS S)\\<close>\n        have \"nx \\<in> (PDG_BS S)\" by -(erule obsE)\n        with \\<open>valid_node nx\\<close> have \"obs nx (PDG_BS S) = {nx}\" by -(erule n_in_obs)\n        with \\<open>sourcenode a = nx\\<close> \\<open>m \\<in> obs (sourcenode a) (PDG_BS S)\\<close> \n          \\<open>nx \\<noteq> m\\<close> show False by fastforce\n      qed\n      with \\<open>nx \\<notin> set(sourcenodes ys)\\<close> have \"nx \\<notin> set(sourcenodes (a#ys))\"\n        by(fastforce simp:sourcenodes_def)\n      from \\<open>valid_edge a\\<close> \\<open>targetnode a -ys\\<rightarrow>* nx\\<close>\n      have \"sourcenode a -a#ys\\<rightarrow>* nx\" by(fastforce intro:Cons_path)\n      from \\<open>sourcenode a -a#ys\\<rightarrow>* nx\\<close> \\<open>nx \\<notin> set(sourcenodes (a#ys))\\<close>\n        \\<open>nx strongly-postdominates (targetnode a)\\<close> \\<open>valid_edge x'\\<close>\n        \\<open>\\<not> nx strongly-postdominates (targetnode x')\\<close> \\<open>sourcenode a = sourcenode x'\\<close>\n      have \"(sourcenode a) weakly controls nx\"\n        by(fastforce simp:weak_control_dependence_def)\n      with \\<open>nx \\<in> (PDG_BS S)\\<close> have \"sourcenode a \\<in> (PDG_BS S)\"\n        by(rule cd_closed)\n      with \\<open>valid_edge a\\<close> have \"obs (sourcenode a) (PDG_BS S) = {sourcenode a}\"\n        by(fastforce intro!:n_in_obs)\n      with \\<open>m \\<in> obs (sourcenode a) (PDG_BS S)\\<close>\n        \\<open>nx \\<in> obs (sourcenode a) (PDG_BS S)\\<close> \\<open>nx \\<noteq> m\\<close>\n      show False by simp\n    next\n      case False\n      with \\<open>m \\<in> obs (sourcenode a) (PDG_BS S)\\<close> \\<open>valid_node m\\<close>\n        \\<open>\\<not> m strongly-postdominates sourcenode a\\<close> \n      show False by(fastforce dest:obs_strong_postdominate)\n    qed\n  qed\nqed\n\n\nlemma WeakPDGBackwardSliceCorrect:\n  \"BackwardSlice sourcenode targetnode kind valid_edge\n        (_Entry_) Def Use state_val PDG_BS\"\nproof(unfold_locales)\n  fix n S assume \"n \\<in> PDG_BS S\"\n  thus \"valid_node n\" by(rule PDG_BS_valid_node)\nnext\n  fix n S assume \"valid_node n\" and \"n \\<in> S\"\n  thus \"n \\<in> PDG_BS S\" by(fastforce intro:PDG_path_Nil simp:PDG_BS_def)\nnext\n  fix n' S n V assume \"n' \\<in> PDG_BS S\" and \"n influences V in n'\"\n  thus \"n \\<in> PDG_BS S\"\n    by(auto dest:PDG.PDG_path_ddep[OF PDG_wcd,OF PDG.PDG_ddep_edge[OF PDG_wcd]]\n            dest:PDG_path_Append simp:PDG_BS_def split:if_split_asm)\nnext\n  fix n S\n  have \"(\\<exists>m. obs n (PDG_BS S) = {m}) \\<or> obs n (PDG_BS S) = {}\" \n    by(rule obs_singleton)\n  thus \"finite (obs n (PDG_BS S))\" by fastforce\nnext\n  fix n S\n  have \"(\\<exists>m. obs n (PDG_BS S) = {m}) \\<or> obs n (PDG_BS S) = {}\" \n    by(rule obs_singleton)\n  thus \"card (obs n (PDG_BS S)) \\<le> 1\" by fastforce\nqed\n\nend\n\n\nsubsection\\<open>Weak order dependence\\<close>\n\ncontext CFG_wf begin\n\nlemma obs_singleton: \n  (*assumes valid:\"valid_node n\"*)\n  shows \"(\\<exists>m. obs n (wod_backward_slice S) = {m}) \\<or>\n         obs n (wod_backward_slice S) = {}\"\nproof(rule ccontr)\n  let ?WOD_BS = \"wod_backward_slice S\"\n  assume \"\\<not> ((\\<exists>m. obs n ?WOD_BS = {m}) \\<or> obs n ?WOD_BS = {})\"\n  hence \"\\<exists>nx nx'. nx \\<in> obs n ?WOD_BS \\<and> nx' \\<in> obs n ?WOD_BS \\<and>\n    nx \\<noteq> nx'\" by auto\n  then obtain nx nx' where \"nx \\<in> obs n ?WOD_BS\" and \"nx' \\<in> obs n ?WOD_BS\"\n    and \"nx \\<noteq> nx'\" by auto\n  from \\<open>nx \\<in> obs n ?WOD_BS\\<close> obtain as where \"n -as\\<rightarrow>* nx\" \n    and \"\\<forall>n' \\<in> set(sourcenodes as). n' \\<notin> ?WOD_BS\" and \"nx \\<in> ?WOD_BS\" \n    by(erule obsE)\n  from \\<open>n -as\\<rightarrow>* nx\\<close> have \"valid_node nx\" by(fastforce dest:path_valid_node)\n  with \\<open>nx \\<in> ?WOD_BS\\<close> have \"obs nx ?WOD_BS = {nx}\" by -(rule n_in_obs)\n  with \\<open>n -as\\<rightarrow>* nx\\<close> \\<open>nx \\<in> obs n ?WOD_BS\\<close> \\<open>nx' \\<in> obs n ?WOD_BS\\<close> \\<open>nx \\<noteq> nx'\\<close> \n  have \"as \\<noteq> []\" by(fastforce elim:path.cases)\n  with \\<open>n -as\\<rightarrow>* nx\\<close> \\<open>nx \\<in> obs n ?WOD_BS\\<close> \\<open>nx' \\<in> obs n ?WOD_BS\\<close> \\<open>nx \\<noteq> nx'\\<close> \n    \\<open>obs nx ?WOD_BS = {nx}\\<close> \\<open>\\<forall>n' \\<in> set(sourcenodes as). n' \\<notin> ?WOD_BS\\<close>\n  have \"\\<exists>a as' as''. n -as'\\<rightarrow>* sourcenode a \\<and> targetnode a -as''\\<rightarrow>* nx \\<and>\n                     valid_edge a \\<and> as = as'@a#as'' \\<and> \n                     obs (targetnode a) ?WOD_BS = {nx} \\<and> \n                    (\\<not> (\\<exists>m. obs (sourcenode a) ?WOD_BS = {m} \\<or> \n                       obs (sourcenode a) ?WOD_BS = {}))\"\n  proof(induct arbitrary:nx' rule:path.induct)\n    case (Cons_path n'' as n' a n)\n    note [simp] = \\<open>sourcenode a = n\\<close>[THEN sym] \\<open>targetnode a = n''\\<close>[THEN sym]\n    note more_than_one = \\<open>n' \\<in> obs n (?WOD_BS)\\<close> \\<open>nx' \\<in> obs n (?WOD_BS)\\<close> \\<open>n' \\<noteq> nx'\\<close>\n    note IH = \\<open>\\<And>nx'. \\<lbrakk>n' \\<in> obs n'' (?WOD_BS); nx' \\<in> obs n'' (?WOD_BS); n' \\<noteq> nx'; \n      obs n' (?WOD_BS) = {n'}; \\<forall>n'\\<in>set (sourcenodes as). n' \\<notin> (?WOD_BS); as \\<noteq> []\\<rbrakk>\n      \\<Longrightarrow> \\<exists>a as' as''. n'' -as'\\<rightarrow>* sourcenode a \\<and> targetnode a -as''\\<rightarrow>* n' \\<and>\n      valid_edge a \\<and> as = as'@a#as'' \\<and> obs (targetnode a) (?WOD_BS) = {n'} \\<and>\n      (\\<not> (\\<exists>m. obs (sourcenode a) (?WOD_BS) = {m} \\<or> \n      obs (sourcenode a) (?WOD_BS) = {}))\\<close>\n    from \\<open>\\<forall>n'\\<in>set (sourcenodes (a#as)). n' \\<notin> (?WOD_BS)\\<close>\n    have \"\\<forall>n'\\<in>set (sourcenodes as). n' \\<notin> (?WOD_BS)\" and \"sourcenode a \\<notin> (?WOD_BS)\"\n      by(simp_all add:sourcenodes_def)\n    show ?case\n    proof(cases \"as = []\")\n      case True\n      with \\<open>n'' -as\\<rightarrow>* n'\\<close> have [simp]:\"n' = n''\" by(fastforce elim:path.cases)\n      from more_than_one\n      have \"\\<not> (\\<exists>m. obs (sourcenode a) (?WOD_BS) = {m} \\<or> \n               obs (sourcenode a) (?WOD_BS) = {})\"\n        by auto\n      with \\<open>obs n' (?WOD_BS) = {n'}\\<close> True \\<open>valid_edge a\\<close> show ?thesis\n        apply(rule_tac x=\"a\" in exI)\n        apply(rule_tac x=\"[]\" in exI)\n        apply(rule_tac x=\"[]\" in exI)\n        by(auto intro!:empty_path)\n    next\n      case False\n      hence \"as \\<noteq> []\" .\n      from \\<open>n'' -as\\<rightarrow>* n'\\<close> \\<open>\\<forall>n'\\<in>set (sourcenodes as). n' \\<notin> (?WOD_BS)\\<close> \n      have \"obs n' (?WOD_BS) \\<subseteq> obs n'' (?WOD_BS)\" by(rule path_obs_subset)\n      show ?thesis\n      proof(cases \"obs n' (?WOD_BS) = obs n'' (?WOD_BS)\")\n        case True\n        with \\<open>n'' -as\\<rightarrow>* n'\\<close> \\<open>valid_edge a\\<close> \\<open>obs n' (?WOD_BS) = {n'}\\<close> more_than_one\n        show ?thesis\n          apply(rule_tac x=\"a\" in exI)\n          apply(rule_tac x=\"[]\" in exI)\n          apply(rule_tac x=\"as\" in exI)\n          by(fastforce intro:empty_path)\n      next\n        case False\n        with \\<open>obs n' (?WOD_BS) \\<subseteq> obs n'' (?WOD_BS)\\<close>\n        have \"obs n' (?WOD_BS) \\<subset> obs n'' (?WOD_BS)\" by simp\n        with \\<open>obs n' (?WOD_BS) = {n'}\\<close> obtain ni where \"n' \\<in> obs n'' (?WOD_BS)\"\n          and \"ni \\<in> obs n'' (?WOD_BS)\" and \"n' \\<noteq> ni\" by auto\n        from IH[OF this \\<open>obs n' (?WOD_BS) = {n'}\\<close> \n          \\<open>\\<forall>n'\\<in>set (sourcenodes as). n' \\<notin> (?WOD_BS)\\<close> \\<open>as \\<noteq> []\\<close>] obtain a' as' as''\n          where \"n'' -as'\\<rightarrow>* sourcenode a'\" and \"targetnode a' -as''\\<rightarrow>* n'\"\n          and \"valid_edge a'\" and [simp]:\"as = as'@a'#as''\" \n          and \"obs (targetnode a') (?WOD_BS) = {n'}\"\n          and more_than_one':\"\\<not> (\\<exists>m. obs (sourcenode a') (?WOD_BS) = {m} \\<or> \n          obs (sourcenode a') (?WOD_BS) = {})\"\n          by blast\n        from \\<open>n'' -as'\\<rightarrow>* sourcenode a'\\<close> \\<open>valid_edge a\\<close>\n        have \"n -a#as'\\<rightarrow>* sourcenode a'\" by(fastforce intro:path.Cons_path)\n        with \\<open>targetnode a' -as''\\<rightarrow>* n'\\<close> \\<open>obs (targetnode a') (?WOD_BS) = {n'}\\<close>\n          more_than_one' \\<open>valid_edge a'\\<close> show ?thesis\n          apply(rule_tac x=\"a'\" in exI)\n          apply(rule_tac x=\"a#as'\" in exI)\n          apply(rule_tac x=\"as''\" in exI)\n          by fastforce\n      qed\n    qed\n  qed simp\n  then obtain a as' as'' where \"valid_edge a\"\n    and \"obs (targetnode a) (?WOD_BS) = {nx}\"\n    and more_than_one:\"\\<not> (\\<exists>m. obs (sourcenode a) (?WOD_BS) = {m} \\<or> \n                         obs (sourcenode a) (?WOD_BS) = {})\"\n    by blast\n  have \"sourcenode a \\<notin> (?WOD_BS)\"\n  proof(rule ccontr)\n    assume \"\\<not> sourcenode a \\<notin> ?WOD_BS\"\n    hence \"sourcenode a \\<in> ?WOD_BS\" by simp\n    with \\<open>valid_edge a\\<close> have \"obs (sourcenode a) (?WOD_BS) = {sourcenode a}\"\n      by(fastforce intro!:n_in_obs)\n    with more_than_one show False by simp\n  qed\n  with \\<open>valid_edge a\\<close> \n  have \"obs (targetnode a) (?WOD_BS) \\<subseteq> obs (sourcenode a) (?WOD_BS)\"\n    by(rule edge_obs_subset)\n  with \\<open>obs (targetnode a) (?WOD_BS) = {nx}\\<close> \n  have \"nx \\<in> obs (sourcenode a) (?WOD_BS)\" by simp\n  with more_than_one obtain m  where \"m \\<in> obs (sourcenode a) (?WOD_BS)\"\n    and \"nx \\<noteq> m\" by auto\n  with \\<open>nx \\<in> obs (sourcenode a) (?WOD_BS)\\<close> obtain as2 \n    where \"sourcenode a -as2\\<rightarrow>* m\" and \"nx \\<notin> set(sourcenodes as2)\" \n    by(fastforce elim:obsE)\n  from \\<open>nx \\<in> obs (sourcenode a) (?WOD_BS)\\<close> \\<open>m \\<in> obs (sourcenode a) (?WOD_BS)\\<close> \n  obtain as1 where \"sourcenode a -as1\\<rightarrow>* nx\" and \"m \\<notin> set(sourcenodes as1)\"\n    by(fastforce elim:obsE)\n  from \\<open>obs (targetnode a) (?WOD_BS) = {nx}\\<close> obtain asx \n    where \"targetnode a -asx\\<rightarrow>* nx\" by(fastforce elim:obsE)\n  have \"\\<forall>asx'. targetnode a -asx'\\<rightarrow>* m \\<longrightarrow> nx \\<in> set(sourcenodes asx')\"\n  proof(rule ccontr)\n    assume \"\\<not> (\\<forall>asx'. targetnode a -asx'\\<rightarrow>* m \\<longrightarrow> nx \\<in> set (sourcenodes asx'))\"\n    then obtain asx' where \"targetnode a -asx'\\<rightarrow>* m\" and \"nx \\<notin> set (sourcenodes asx')\"\n      by blast\n    show False\n    proof(cases \"\\<forall>nx \\<in> set(sourcenodes asx'). nx \\<notin> ?WOD_BS\")\n      case True\n      with \\<open>targetnode a -asx'\\<rightarrow>* m\\<close> \\<open>m \\<in> obs (sourcenode a) (?WOD_BS)\\<close> \n      have \"m \\<in> obs (targetnode a) ?WOD_BS\" by(fastforce intro:obs_elem elim:obsE)\n      with \\<open>nx \\<noteq> m\\<close> \\<open>obs (targetnode a) (?WOD_BS) = {nx}\\<close> show False by simp\n    next\n      case False\n      hence \"\\<exists>nx \\<in> set(sourcenodes asx'). nx \\<in> ?WOD_BS\" by blast\n      then obtain nx' ns ns' where \"sourcenodes asx' = ns@nx'#ns'\" and \"nx' \\<in> ?WOD_BS\"\n        and \"\\<forall>nx \\<in> set ns. nx \\<notin> ?WOD_BS\" by(fastforce elim!:split_list_first_propE)\n      from \\<open>sourcenodes asx' = ns@nx'#ns'\\<close> obtain ax ai ai' \n        where [simp]:\"asx' = ai@ax#ai'\" \"ns = sourcenodes ai\" \"nx' = sourcenode ax\"\n        by(fastforce elim:map_append_append_maps simp:sourcenodes_def)\n      from \\<open>targetnode a -asx'\\<rightarrow>* m\\<close> have \"targetnode a -ai\\<rightarrow>* sourcenode ax\"\n        by(fastforce dest:path_split)\n      with \\<open>nx' \\<in> ?WOD_BS\\<close> \\<open>\\<forall>nx \\<in> set ns. nx \\<notin> ?WOD_BS\\<close> \n      have \"nx' \\<in> obs (targetnode a) ?WOD_BS\" by(fastforce intro:obs_elem)\n      with \\<open>obs (targetnode a) (?WOD_BS) = {nx}\\<close> have \"nx' = nx\" by simp\n      with \\<open>nx \\<notin> set (sourcenodes asx')\\<close> show False by(simp add:sourcenodes_def)\n    qed\n  qed\n  with \\<open>nx \\<noteq> m\\<close> \\<open>sourcenode a -as1\\<rightarrow>* nx\\<close> \\<open>m \\<notin> set(sourcenodes as1)\\<close> \n    \\<open>sourcenode a -as2\\<rightarrow>* m\\<close> \\<open>nx \\<notin> set(sourcenodes as2)\\<close> \\<open>valid_edge a\\<close> \n    \\<open>targetnode a -asx\\<rightarrow>* nx\\<close>\n  have \"sourcenode a \\<longrightarrow>\\<^sub>w\\<^sub>o\\<^sub>d nx,m\" by(simp add:wod_def,blast)\n  with \\<open>nx \\<in> obs (sourcenode a) (?WOD_BS)\\<close> \\<open>m \\<in> obs (sourcenode a) (?WOD_BS)\\<close> \n  have \"sourcenode a \\<in> ?WOD_BS\" by(fastforce elim:cd_closed elim:obsE)\n  with \\<open>sourcenode a \\<notin> ?WOD_BS\\<close> show False by simp\nqed\n\n\nlemma WODBackwardSliceCorrect:\n  \"BackwardSlice sourcenode targetnode kind valid_edge\n        (_Entry_) Def Use state_val wod_backward_slice\"\nproof(unfold_locales)\n  fix n S assume \"n \\<in> wod_backward_slice S\"\n  thus \"valid_node n\" by(rule wod_backward_slice_valid_node)\nnext\n  fix n S assume \"valid_node n\" and \"n \\<in> S\"\n  thus \"n \\<in> wod_backward_slice S\" by(rule refl)\nnext\n  fix n' S n V assume \"n' \\<in> wod_backward_slice S\" \"n influences V in n'\"\n  thus \"n \\<in> wod_backward_slice S\"\n    by -(rule dd_closed)\nnext\n  fix n S\n  have \"(\\<exists>m. obs n (wod_backward_slice S) = {m}) \\<or> \n    obs n (wod_backward_slice S) = {}\" \n    by(rule obs_singleton)\n  thus \"finite (obs n (wod_backward_slice S))\" by fastforce\nnext\n  fix n S \n  have \"(\\<exists>m. obs n (wod_backward_slice S) = {m}) \\<or> obs n (wod_backward_slice S) = {}\" \n    by(rule obs_singleton)\n  thus \"card (obs n (wod_backward_slice S)) \\<le> 1\" by fastforce\nqed\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Slicing/StaticIntra/CDepInstantiations.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632979641571, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.26719087457622126}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory WhileLoopVarsPreserved imports\n  \"AutoCorres.AutoCorres\"\nbegin\n\nexternal_file \"while_loop_vars_preserved.c\"\ninstall_C_file \"while_loop_vars_preserved.c\"\n\nautocorres [ts_force nondet = loop] \"while_loop_vars_preserved.c\"\n\ncontext while_loop_vars_preserved begin\n\nlemma \"\\<lbrace> \\<lambda>s. True \\<rbrace> loop' var1 var2 var3 var4  \\<lbrace> \\<lambda>r s. r = var1 + var2 + var3 + var4 \\<rbrace>\"\n  apply (unfold loop'_def)\n  apply (subst whileLoop_add_inv [where I=\"\\<lambda>(meow, woof, neigh, ii, squeek) s.\n              ii = (var1 + var2 + var3 + var4 - (meow + woof + neigh + squeek))\"\n       and M=\"\\<lambda>((meow, woof, neigh, ii, squeek), s).\n                   unat meow + unat woof + unat neigh + unat squeek\"])\n  apply wp\n  apply (auto simp: word_gt_0)\n  done\n\nend\n\nend\n", "meta": {"author": "amblafont", "repo": "AutoCorres", "sha": "a8e96bff9fb22d633ff473401947ca84235d3b73", "save_path": "github-repos/isabelle/amblafont-AutoCorres", "path": "github-repos/isabelle/amblafont-AutoCorres/AutoCorres-a8e96bff9fb22d633ff473401947ca84235d3b73/autocorres/tests/proof-tests/WhileLoopVarsPreserved.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.26719086729594566}}
{"text": "section {*LR1\\_Property\\_Satisfaction\\_\\_convert\\_remaining\\_productions*}\ntheory\n  LR1_Property_Satisfaction__convert_remaining_productions\n\nimports\n  PRJ_12_04_06_06_10__ENTRY\n\nbegin\n\ndefinition restrictX :: \"\n  ('q, 't, 's) epda\n  \\<Rightarrow> ('q, 's, 't) PSplit\n  \\<Rightarrow> ('q, 's, 't) PSplit\"\n  where\n    \"restrictX G' S \\<equiv>\n  map\n    (\\<lambda>I. I \\<lparr>PSplitItem_prods :=\n              map\n                (\\<lambda>X. case X of\n                       teB p \\<Rightarrow> teA (prod_to_edge G' p)\n                       | teA p \\<Rightarrow> teA p) (PSplitItem_prods I)\\<rparr>)\n    S\"\n\nlemma restrictX_length: \"\n  length (restrictX G' S) = length S\"\n  apply(simp add: restrictX_def)\n  done\n\nlemma equal_split_prefix_hlp1_updated: \"\n  F2LR1inputx G G'\n  \\<Longrightarrow> split_TSstructure G\n  \\<Longrightarrow> cfgRM.derivation_initial G d1\n  \\<Longrightarrow> d1 n1 = Some (pair e1 \\<lparr>cfg_conf=v@[teB b]@x1\\<rparr>)\n  \\<Longrightarrow> cfgRM.derivation_initial G d2\n  \\<Longrightarrow> d2 n2 = Some (pair e2 \\<lparr>cfg_conf=v@[teB b]@x2\\<rparr>)\n  \\<Longrightarrow> EValidSplit G (S1@S1')\n  \\<Longrightarrow> EValidSplit G (S2@S2')\n  \\<Longrightarrow> length S1 = length (v@[teB b])\n  \\<Longrightarrow> length S2 = length (v@[teB b])\n  \\<Longrightarrow> v@[teB b] = Esplit_signature S1\n  \\<Longrightarrow> v@[teB b] = Esplit_signature S2\n  \\<Longrightarrow> x1 = Esplit_signature S1'\n  \\<Longrightarrow> x2 = Esplit_signature S2'\n  \\<Longrightarrow> S1R=restrict G' G (S1@S1') (length (v@[teB b]))\n  \\<Longrightarrow> S2R=restrict G' G (S2@S2') (length (v@[teB b]))\n  \\<Longrightarrow> S1RX=restrictX G' S1R\n  \\<Longrightarrow> S2RX=restrictX G' S2R\n  \\<Longrightarrow> ESplitItem_elem ((S1@S1') ! (length v)) = Some (teB b)\n  \\<Longrightarrow> PValidSplit G' G S1R\n  \\<Longrightarrow> ESplitItem_elem ((S2@S2') ! (length v)) = Some (teB b)\n  \\<Longrightarrow> PValidSplit G' G S2R\n  \\<Longrightarrow> i\\<le>length (v@[teB b])\n  \\<Longrightarrow> take i S1RX = take i S2RX\"\n  apply(induct i rule: less_induct)\n  apply(rename_tac x)(*strict*)\n  apply(clarsimp)\n  apply(case_tac x)\n   apply(rename_tac x)(*strict*)\n   apply(force)\n  apply(rename_tac x nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat)(*strict*)\n  apply(erule_tac\n      x=\"nat\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(rename_tac n)\n  apply(rename_tac n)(*strict*)\n  apply(rule_tac\n      t=\"take (Suc n) (restrictX G' (restrict G' G (S1 @ S1') (length (Esplit_signature S1))))\"\n      and s=\"take n (restrictX G' (restrict G' G (S1 @ S1') (length (Esplit_signature S1))))@[(restrictX G' (restrict G' G (S1 @ S1') (length (Esplit_signature S1))))!n]\"\n      in ssubst)\n   apply(rename_tac n)(*strict*)\n   apply(rule take_Suc_conv_app_nth)\n   apply(rule_tac\n      t=\"length (restrictX G' (restrict G' G (S1 @ S1') (length (Esplit_signature S1))))\"\n      in ssubst)\n    apply(rename_tac n)(*strict*)\n    apply(rule restrictX_length)\n   apply(rename_tac n)(*strict*)\n   apply (metis Suc_le_lessD append_length_inc length_Suc length_of_restrict take_n_vs_take_Suc_n zero_less_Suc)\n  apply(rename_tac n)(*strict*)\n  apply(rule_tac\n      t=\"take (Suc n) (restrictX G' (restrict G' G (S2 @ S2') (length (Esplit_signature S1))))\"\n      and s=\"take n (restrictX G' (restrict G' G (S2 @ S2') (length (Esplit_signature S1))))@[(restrictX G' (restrict G' G (S2 @ S2') (length (Esplit_signature S1))))!n]\"\n      in ssubst)\n   apply(rename_tac n)(*strict*)\n   apply(rule take_Suc_conv_app_nth)\n   apply(rule_tac\n      t=\"length (restrictX G' (restrict G' G (S2 @ S2') (length (Esplit_signature S1))))\"\n      in ssubst)\n    apply(rename_tac n)(*strict*)\n    apply(rule restrictX_length)\n   apply(rename_tac n)(*strict*)\n   apply (metis Suc_le_lessD append_length_inc length_Suc length_of_restrict take_n_vs_take_Suc_n zero_less_Suc)\n  apply(rename_tac n)(*strict*)\n  apply(subgoal_tac \"restrictX G' (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) )! n = restrictX G' (restrict G' G (S2 @ S2') (length (Esplit_signature S1))) ! n\")\n   apply(rename_tac n)(*strict*)\n   apply(force)\n  apply(rename_tac n)(*strict*)\n  apply(simp (no_asm) add: restrictX_def restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(case_tac \"length (Esplit_signature S1)\")\n   apply(rename_tac n)(*strict*)\n   apply(force)\n  apply(rename_tac n nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac k)\n  apply(rename_tac n k)(*strict*)\n  apply(subgoal_tac \"length(nat_seq 0 k) = SSx\" for SSx)\n   apply(rename_tac n k)(*strict*)\n   prefer 2\n   apply(rule nat_seq_length_prime)\n  apply(rename_tac n k)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"nat_seq 0 k ! n = SSX\" for SSX)\n   apply(rename_tac n k)(*strict*)\n   prefer 2\n   apply(rule nat_seq_nth_compute)\n    apply(rename_tac n k)(*strict*)\n    apply(force)\n   apply(rename_tac n k)(*strict*)\n   apply(force)\n  apply(rename_tac n k)(*strict*)\n  apply(clarsimp)\n  apply(simp add: restrict_newelem_def)\n  apply(subgoal_tac \"k = length v\")\n   apply(rename_tac n k)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"Suc k = length(v@[teB b])\")\n    apply(rename_tac n k)(*strict*)\n    apply(rule Suc_inject)\n    apply(rule_tac\n      t=\"Suc k\"\n      and s=\"length(v@[teB b])\"\n      in ssubst)\n     apply(rename_tac n k)(*strict*)\n     apply(force)\n    apply(rename_tac n k)(*strict*)\n    apply(simp (no_asm))\n   apply(rename_tac n k)(*strict*)\n   apply(subgoal_tac \"length SSS = length (Esplit_signature S1) \\<or> length SSS = Suc (length (Esplit_signature SSS)) \\<and> S1' = []\" for SSS)\n    apply(rename_tac n k)(*strict*)\n    prefer 2\n    apply(rule EValidSplit_Esplit_signature_length)\n    apply(force)\n   apply(rename_tac n k)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac n k)(*strict*)\n    apply(rule_tac\n      t=\"Suc k\"\n      and s=\"length S1\"\n      in ssubst)\n     apply(rename_tac n k)(*strict*)\n     apply(force)\n    apply(rename_tac n k)(*strict*)\n    apply(rule_tac\n      t=\"v@[teB b]\"\n      and s=\"Esplit_signature S1\"\n      in ssubst)\n     apply(rename_tac n k)(*strict*)\n     apply(force)\n    apply(rename_tac n k)(*strict*)\n    apply(force)\n   apply(rename_tac n k)(*strict*)\n   apply(force)\n  apply(rename_tac n k)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n)(*strict*)\n  apply(subgoal_tac \" ESplitItem_elem (S1 ! n) = Some ((v@[teB b])!n) \\<and> ESplitItem_elem (S2 ! n) = Some ((v@[teB b])!n) \")\n   apply(rename_tac n)(*strict*)\n   prefer 2\n   apply(rule conjI)\n    apply(rename_tac n)(*strict*)\n    apply(rule Esplit_signature_take_prefix_closureise)\n      apply(rename_tac n)(*strict*)\n      apply(force)\n     apply(rename_tac n)(*strict*)\n     apply(force)\n    apply(rename_tac n)(*strict*)\n    apply(force)\n   apply(rename_tac n)(*strict*)\n   apply(rule Esplit_signature_take_prefix_closureise)\n     apply(rename_tac n)(*strict*)\n     apply(force)\n    apply(rename_tac n)(*strict*)\n    apply(force)\n   apply(rename_tac n)(*strict*)\n   apply(force)\n  apply(rename_tac n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n)(*strict*)\n  apply(subgoal_tac \" let S1nr=restrict G' G (S1 @ S1') (Suc (length v)) ! n; S2nr=restrict G' G (S2 @ S2') (Suc (length v)) ! n in PSplitItem_elim S1nr @ [PSplitItem_from S1nr] @ PSplitItem_ignore S1nr = PSplitItem_elim S2nr @ [PSplitItem_from S2nr] @ PSplitItem_ignore S2nr \")\n   apply(rename_tac n)(*strict*)\n   prefer 2\n   apply(simp add: Let_def)\n   apply(case_tac n)\n    apply(rename_tac n)(*strict*)\n    apply(clarsimp)\n    apply(simp add: PValidSplit_def PValidSplit_initial_def)\n    apply(clarsimp)\n    apply(case_tac \"restrict G' G (S1 @ S1') (Suc (length v))\")\n     apply(force)\n    apply(rename_tac a list)(*strict*)\n    apply(clarsimp)\n    apply(case_tac \"restrict G' G (S2 @ S2') (Suc (length v))\")\n     apply(rename_tac a list)(*strict*)\n     apply(force)\n    apply(rename_tac a list aa lista)(*strict*)\n    apply(force)\n   apply(rename_tac n nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac nat)(*strict*)\n   apply(subgoal_tac \"restrictX G' (restrict G' G (S1 @ S1') (Suc (length v))) ! nat = restrictX G' (restrict G' G (S2 @ S2') (Suc (length v))) ! nat\")\n    apply(rename_tac nat)(*strict*)\n    prefer 2\n    apply(rule_tac\n      n=\"Suc nat\"\n      and m=\"Suc nat\"\n      in nth_equal_by_take_equal)\n      apply(rename_tac nat)(*strict*)\n      apply(force)\n     apply(rename_tac nat)(*strict*)\n     apply(force)\n    apply(rename_tac nat)(*strict*)\n    apply(force)\n   apply(rename_tac nat)(*strict*)\n   apply(thin_tac \"take (Suc nat) (restrictX G' (restrict G' G (S1 @ S1') (Suc (length v)))) = take (Suc nat) (restrictX G' (restrict G' G (S2 @ S2') (Suc (length v))))\")\n   apply(rename_tac nat)(*strict*)\n   apply(rename_tac n)\n   apply(rename_tac n)(*strict*)\n   apply(subgoal_tac \"PValidSplit_interlineX (restrict G' G (S1 @ S1') (Suc (length v)) ! n) (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc n)\\<and> PValidSplit_interlineX (restrict G' G (S2 @ S2') (Suc (length v)) ! n) (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc n)\")\n    apply(rename_tac n)(*strict*)\n    prefer 2\n    apply(simp add: PValidSplit_def PValidSplit_interline_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"n\"\n      in allE)+\n    apply(erule_tac\n      P=\"Suc n < length (restrict G' G (S1 @ S1') (Suc (length v)))\"\n      in impE)\n     apply(rename_tac n)(*strict*)\n     apply(simp add: restrict_def restrict_len_def restrict_map_def restrictX_def)\n    apply(rename_tac n)(*strict*)\n    apply(erule impE)\n     apply(rename_tac n)(*strict*)\n     apply(simp add: restrict_def restrict_len_def restrict_map_def restrictX_def)\n    apply(rename_tac n)(*strict*)\n    apply(force)\n   apply(rename_tac n)(*strict*)\n   apply(simp add: PValidSplit_interlineX_def)\n   apply(simp add: restrict_def restrict_len_def restrict_map_def restrictX_def)\n  apply(rename_tac n)(*strict*)\n  apply(simp add: Let_def)\n  apply(subgoal_tac \"ESplitItem_elim_prods (S2 ! n) = PSplitItem_elim_prods (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\")\n   apply(rename_tac n)(*strict*)\n   prefer 2\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def PValidSplit_def)\n   apply(rule_tac\n      t=\"map (\\<lambda>i. \\<lparr>PSplitItem_elim = ESplitItem_elim ((take (Suc (length v)) S2 @ take (Suc (length v) - length S2) S2') ! i), PSplitItem_from = hd (cropTol3l2 (the (ESplitItem_from ((take (Suc (length v)) S2 @ take (Suc (length v) - length S2) S2') ! i)) # restrict_newignore (take (Suc (length v)) S2 @ take (Suc (length v) - length S2) S2') i)), PSplitItem_ignore = restrict_newignore (take (Suc (length v)) S2 @ take (Suc (length v) - length S2) S2') i, PSplitItem_elim_prods = ESplitItem_elim_prods ((take (Suc (length v)) S2 @ take (Suc (length v) - length S2) S2') ! i), PSplitItem_prods = restrict_newprods G' G (take (Suc (length v)) S2 @ take (Suc (length v) - length S2) S2') i, PSplitItem_elem = restrict_newelem (take (Suc (length v)) S2 @ take (Suc (length v) - length S2) S2') i, PSplitItem_to = restrict_newto (take (Suc (length v)) S2 @ take (Suc (length v) - length S2) S2') i\\<rparr>) (nat_seq 0 (min (length S2) (Suc (length v)) + min (length S2') (Suc (length v) - length S2) - Suc 0)) ! n\"\n      in ssubst)\n    apply(rename_tac n)(*strict*)\n    apply(rule nth_map)\n    apply(force)\n   apply(rename_tac n)(*strict*)\n   apply(force)\n  apply(rename_tac n)(*strict*)\n  apply(subgoal_tac \"ESplitItem_elim_prods (S1 ! n) = PSplitItem_elim_prods (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\")\n   apply(rename_tac n)(*strict*)\n   prefer 2\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def PValidSplit_def)\n   apply(rule_tac\n      t=\"map (\\<lambda>i. \\<lparr>PSplitItem_elim = ESplitItem_elim ((take (Suc (length v)) S2 @ take (Suc (length v) - length S2) S2') ! i), PSplitItem_from = hd (cropTol3l2 (the (ESplitItem_from ((take (Suc (length v)) S2 @ take (Suc (length v) - length S2) S2') ! i)) # restrict_newignore (take (Suc (length v)) S2 @ take (Suc (length v) - length S2) S2') i)), PSplitItem_ignore = restrict_newignore (take (Suc (length v)) S2 @ take (Suc (length v) - length S2) S2') i, PSplitItem_elim_prods = ESplitItem_elim_prods ((take (Suc (length v)) S2 @ take (Suc (length v) - length S2) S2') ! i), PSplitItem_prods = restrict_newprods G' G (take (Suc (length v)) S2 @ take (Suc (length v) - length S2) S2') i, PSplitItem_elem = restrict_newelem (take (Suc (length v)) S2 @ take (Suc (length v) - length S2) S2') i, PSplitItem_to = restrict_newto (take (Suc (length v)) S2 @ take (Suc (length v) - length S2) S2') i\\<rparr>) (nat_seq 0 (min (length S2) (Suc (length v)) + min (length S2') (Suc (length v) - length S2) - Suc 0)) ! n\"\n      in ssubst)\n    apply(rename_tac n)(*strict*)\n    apply(rule nth_map)\n    apply(force)\n   apply(rename_tac n)(*strict*)\n   apply(force)\n  apply(rename_tac n)(*strict*)\n  apply(subgoal_tac \"ESplitItem_elim (S1 ! n) = ESplitItem_elim (S2 ! n) \\<and> ESplitItem_elim_prods (S1 ! n) = ESplitItem_elim_prods (S2 ! n)\")\n   apply(rename_tac n)(*strict*)\n   apply(clarsimp)\n   prefer 2\n   apply(subgoal_tac \"ESplitItem_elim (S1 ! n) = PSplitItem_elim (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\")\n    apply(rename_tac n)(*strict*)\n    prefer 2\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def PValidSplit_def)\n    apply(force)\n   apply(rename_tac n)(*strict*)\n   apply(subgoal_tac \"ESplitItem_elim (S2 ! n) = PSplitItem_elim (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\")\n    apply(rename_tac n)(*strict*)\n    prefer 2\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def PValidSplit_def)\n    apply(force)\n   apply(rename_tac n)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"ESplitItem_elem (S1 ! n) = Some (PSplitItem_elem (restrict G' G (S1 @ S1') (Suc (length v)) ! n))\")\n    apply(rename_tac n)(*strict*)\n    prefer 2\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def restrict_newelem_def PValidSplit_def)\n    apply(clarsimp)\n   apply(rename_tac n)(*strict*)\n   apply(subgoal_tac \"ESplitItem_elem (S2 ! n) = Some (PSplitItem_elem (restrict G' G (S2 @ S2') (Suc (length v)) ! n))\")\n    apply(rename_tac n)(*strict*)\n    prefer 2\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def restrict_newelem_def PValidSplit_def)\n    apply(clarsimp)\n   apply(rename_tac n)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n)(*strict*)\n   apply(case_tac \"ESplitItem_elem (S1 ! n)\")\n    apply(rename_tac n)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac n a)(*strict*)\n   apply(case_tac a)\n    apply(rename_tac n a aa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac n aa)(*strict*)\n    apply(rename_tac A)\n    apply(rename_tac n A)(*strict*)\n    apply(subgoal_tac \"EValidSplitItem G (S1 ! n)\")\n     apply(rename_tac n A)(*strict*)\n     prefer 2\n     apply(simp add: EValidSplit_def EValidSplit_ValidItem_def)\n    apply(rename_tac n A)(*strict*)\n    apply(subgoal_tac \"EValidSplitItem G (S2 ! n)\")\n     apply(rename_tac n A)(*strict*)\n     prefer 2\n     apply(simp add: EValidSplit_def EValidSplit_ValidItem_def)\n    apply(rename_tac n A)(*strict*)\n    apply(simp add: EValidSplitItem_def EValidSplitItem_gen_def)\n    apply(clarsimp)\n    apply(rename_tac n A d da)(*strict*)\n    apply(thin_tac \"(\\<exists>b. teB b = Esplit_signature S1 ! n) \\<longrightarrow> (\\<forall>i<length (ESplitItem_prods (S2 ! n)). hd (cfg_conf (the (get_configuration (da i)))) \\<noteq> Esplit_signature S1 ! n)\")\n    apply(rename_tac n A d da)(*strict*)\n    apply(thin_tac \"(\\<exists>b. teB b = Esplit_signature S1 ! n) \\<longrightarrow> (\\<forall>i<length (ESplitItem_prods (S1 ! n)). hd (cfg_conf (the (get_configuration (d i)))) \\<noteq> Esplit_signature S1 ! n)\")\n    apply(rename_tac n A d da)(*strict*)\n    apply(erule_tac\n      P=\"\\<exists>A. teA A = Esplit_signature S1 ! n\"\n      and Q=\"left_degen G d \\<and> PSplitItem_elim_prods (restrict G' G (S1 @ S1') (Suc (length v)) ! n) = []\"\n      in impE)\n     apply(rename_tac n A d da)(*strict*)\n     apply(rule_tac\n      x=\"A\"\n      in exI)\n     apply(force)\n    apply(rename_tac n A d da)(*strict*)\n    apply(erule impE)\n     apply(rename_tac n A d da)(*strict*)\n     apply(rule_tac\n      x=\"A\"\n      in exI)\n     apply(force)\n    apply(rename_tac n A d da)(*strict*)\n    apply(clarsimp)\n    apply(simp add: EValidSplitItem_def EValidSplitItem_elim_def)\n   apply(rename_tac n a ba)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n ba)(*strict*)\n   apply(rename_tac a)\n   apply(rename_tac n a)(*strict*)\n   apply(rule context_conjI)\n    apply(rename_tac n a)(*strict*)\n    prefer 2\n    apply(rename_tac n a)(*strict*)\n    apply(subgoal_tac \"PValidSplitItem G' G (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\")\n     apply(rename_tac n a)(*strict*)\n     prefer 2\n     apply(simp add: PValidSplit_def PValidSplit_ValidItem_def)\n     apply(clarsimp)\n     apply(erule_tac\n      x=\"(restrict G' G (S2 @ S2') (Suc (length v))) ! n\"\n      and A=\"set (restrict G' G (S2 @ S2') (Suc (length v)))\"\n      in ballE)\n      apply(rename_tac n a)(*strict*)\n      prefer 2\n      apply(subgoal_tac \" (restrict G' G (S2 @ S2') (Suc (length v))) ! n \\<in> set ((restrict G' G (S2 @ S2') (Suc (length v))))\")\n       apply(rename_tac n a)(*strict*)\n       apply(force)\n      apply(rename_tac n a)(*strict*)\n      apply(rule nth_mem)\n      apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def PValidSplit_def)\n      apply(force)\n     apply(rename_tac n a)(*strict*)\n     apply(force)\n    apply(rename_tac n a)(*strict*)\n    apply(subgoal_tac \"PValidSplitItem G' G (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\")\n     apply(rename_tac n a)(*strict*)\n     prefer 2\n     apply(simp add: PValidSplit_def PValidSplit_ValidItem_def)\n     apply(clarsimp)\n     apply(erule_tac\n      A=\"set (restrict G' G (S2 @ S2') (Suc (length v)))\"\n      and x=\"restrict G' G (S1 @ S1') (Suc (length v)) ! n\"\n      in ballE)\n      apply(rename_tac n a)(*strict*)\n      prefer 2\n      apply(subgoal_tac \"restrict G' G (S1 @ S1') (Suc (length v)) ! n \\<in> set (restrict G' G (S1 @ S1') (Suc (length v)))\")\n       apply(rename_tac n a)(*strict*)\n       apply(force)\n      apply(rename_tac n a)(*strict*)\n      apply(rule nth_mem)\n      apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def PValidSplit_def)\n      apply(force)\n     apply(rename_tac n a)(*strict*)\n     apply(force)\n    apply(rename_tac n a)(*strict*)\n    apply(subgoal_tac \"PValidSplitItem_elim G (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\")\n     apply(rename_tac n a)(*strict*)\n     prefer 2\n     apply(simp add: PValidSplitItem_def)\n    apply(rename_tac n a)(*strict*)\n    apply(subgoal_tac \"PValidSplitItem_elim G (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\")\n     apply(rename_tac n a)(*strict*)\n     prefer 2\n     apply(simp add: PValidSplitItem_def)\n    apply(rename_tac n a)(*strict*)\n    apply(simp add: PValidSplitItem_elim_def)\n    apply(rename_tac n a)(*strict*)\n    apply(rule_tac\n      t=\"ESplitItem_elim_prods (S1 ! n)\"\n      and s=\"PSplitItem_elim_prods (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\"\n      in ssubst)\n     apply(rename_tac n a)(*strict*)\n     apply(force)\n    apply(rename_tac n a)(*strict*)\n    apply(rule_tac\n      t=\"ESplitItem_elim_prods (S2 ! n)\"\n      and s=\"PSplitItem_elim_prods (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n      in ssubst)\n     apply(rename_tac n a)(*strict*)\n     apply(force)\n    apply(rename_tac n a)(*strict*)\n    apply(rule_tac\n      ns=\"PSplitItem_elim_prods (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\"\n      and v=\"PSplitItem_elim (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n      in elim_map_equal_by_CFGlm_unambiguous)\n            apply(rename_tac n a)(*strict*)\n            apply(simp add: F2LR1inputx_def)\n            apply(force)\n           apply(rename_tac n a)(*strict*)\n           apply(simp add: split_TSstructure_def)\n          apply(rename_tac n a)(*strict*)\n          apply(simp add: F2LR1inputx_def)\n          apply(simp add: split_TSstructure_def)\n          apply(rule cfgSTD_Nonblockingness_nonterminals_equal_cfgLM_accessible_nonterminals)\n            apply(rename_tac n a)(*strict*)\n            apply(force)\n           apply(rename_tac n a)(*strict*)\n           apply(force)\n          apply(rename_tac n a)(*strict*)\n          apply(force)\n         apply(rename_tac n a)(*strict*)\n         apply(simp add: F2LR1inputx_def)\n         apply(simp add: split_TSstructure_def)\n        apply(rename_tac n a)(*strict*)\n        apply(force)\n       apply(rename_tac n a)(*strict*)\n       apply(rule_tac\n      t=\"map (\\<lambda>x. []) (PSplitItem_elim_prods (restrict G' G (S1 @ S1') (Suc (length v)) ! n))\"\n      and s=\"map (\\<lambda>x. []) (PSplitItem_elim_prods (restrict G' G (S2 @ S2') (Suc (length v)) ! n))\"\n      in ssubst)\n        apply(rename_tac n a)(*strict*)\n        apply(rule map_empty_eq)\n        apply(rule_tac\n      t=\"length (PSplitItem_elim_prods (restrict G' G (S2 @ S2') (Suc (length v)) ! n))\"\n      and s=\"length (PSplitItem_elim (restrict G' G (S2 @ S2') (Suc (length v)) ! n))\"\n      in ssubst)\n         apply(rename_tac n a)(*strict*)\n         apply(force)\n        apply(rename_tac n a)(*strict*)\n        apply(rule_tac\n      t=\"length (PSplitItem_elim_prods (restrict G' G (S1 @ S1') (Suc (length v)) ! n))\"\n      and s=\"length (PSplitItem_elim (restrict G' G (S1 @ S1') (Suc (length v)) ! n))\"\n      in ssubst)\n         apply(rename_tac n a)(*strict*)\n         apply(force)\n        apply(rename_tac n a)(*strict*)\n        apply(force)\n       apply(rename_tac n a)(*strict*)\n       apply(force)\n      apply(rename_tac n a)(*strict*)\n      apply(force)\n     apply(rename_tac n a)(*strict*)\n     apply(force)\n    apply(rename_tac n a)(*strict*)\n    apply(force)\n   apply(rename_tac n a)(*strict*)\n   apply(rule equal_by_strict_prefix_alt)\n     apply(rename_tac n a)(*strict*)\n     prefer 3\n     apply(force)\n    apply(rename_tac n a)(*strict*)\n    apply(rule equal_split_prefix_hlp1_elim_eq_updated)\n                      apply(rename_tac n a)(*strict*)\n                      prefer 25\n                      apply(force)+\n   apply(rename_tac n a)(*strict*)\n   apply(rule equal_split_prefix_hlp1_elim_eq_updated)\n                      apply(rename_tac n a)(*strict*)\n                      prefer 25\n                      apply(force)+\n  apply(rename_tac n)(*strict*)\n  apply(subgoal_tac \"ESplitItem_elim (S1 ! n) = PSplitItem_elim (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\")\n   apply(rename_tac n)(*strict*)\n   prefer 2\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n   apply(force)\n  apply(rename_tac n)(*strict*)\n  apply(subgoal_tac \"ESplitItem_elim (S2 ! n) = PSplitItem_elim (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\")\n   apply(rename_tac n)(*strict*)\n   prefer 2\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n   apply(force)\n  apply(rename_tac n)(*strict*)\n  apply(subgoal_tac \"PValidSplitItem G' G (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\")\n   apply(rename_tac n)(*strict*)\n   prefer 2\n   apply(simp add: PValidSplit_def PValidSplit_ValidItem_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"restrict G' G (S2 @ S2') (Suc (length v)) ! n\"\n      and A=\"set (restrict G' G (S2 @ S2') (Suc (length v)))\"\n      in ballE)\n    apply(rename_tac n)(*strict*)\n    prefer 2\n    apply(subgoal_tac \"restrict G' G (S2 @ S2') (Suc (length v)) ! n \\<in> set (restrict G' G (S2 @ S2') (Suc (length v)))\")\n     apply(rename_tac n)(*strict*)\n     apply(force)\n    apply(rename_tac n)(*strict*)\n    apply(rule nth_mem)\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def PValidSplit_def)\n    apply(force)\n   apply(rename_tac n)(*strict*)\n   apply(force)\n  apply(rename_tac n)(*strict*)\n  apply(subgoal_tac \"PValidSplitItem G' G (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\")\n   apply(rename_tac n)(*strict*)\n   prefer 2\n   apply(simp add: PValidSplit_def PValidSplit_ValidItem_def)\n   apply(clarsimp)\n   apply(erule_tac\n      A=\"set (restrict G' G (S1 @ S1') (Suc (length v)))\"\n      and x=\"restrict G' G (S1 @ S1') (Suc (length v)) ! n\"\n      in ballE)\n    apply(rename_tac n)(*strict*)\n    prefer 2\n    apply(subgoal_tac \"restrict G' G (S1 @ S1') (Suc (length v)) ! n \\<in> set (restrict G' G (S1 @ S1') (Suc (length v)))\")\n     apply(rename_tac n)(*strict*)\n     apply(force)\n    apply(rename_tac n)(*strict*)\n    apply(rule nth_mem)\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def PValidSplit_def)\n    apply(force)\n   apply(rename_tac n)(*strict*)\n   apply(force)\n  apply(rename_tac n)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac n)(*strict*)\n   apply(subgoal_tac \"PSplitItem_from (restrict_map G' G (restrict_len (S1 @ S1') (Suc (length v))) ! n) = PSplitItem_from (restrict_map G' G (restrict_len (S2 @ S2') (Suc (length v))) ! n)\")\n    apply(rename_tac n)(*strict*)\n    prefer 2\n    apply(simp add: restrict_def)\n   apply(rename_tac n)(*strict*)\n   apply(simp add: restrict_map_def restrict_len_def PValidSplit_def)\n  apply(rename_tac n)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac n)(*strict*)\n   apply(subgoal_tac \"PSplitItem_ignore (restrict_map G' G (restrict_len (S1 @ S1') (Suc (length v))) ! n) = PSplitItem_ignore (restrict_map G' G (restrict_len (S2 @ S2') (Suc (length v))) ! n)\")\n    apply(rename_tac n)(*strict*)\n    prefer 2\n    apply(simp add: restrict_def)\n   apply(rename_tac n)(*strict*)\n   apply(simp add: restrict_map_def restrict_len_def PValidSplit_def)\n  apply(rename_tac n)(*strict*)\n  apply(subgoal_tac \"restrict_newprods G' G S1 n = PSplitItem_prods (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\")\n   apply(rename_tac n)(*strict*)\n   prefer 2\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def PValidSplit_def)\n   apply(force)\n  apply(rename_tac n)(*strict*)\n  apply(subgoal_tac \"restrict_newprods G' G S2 n = PSplitItem_prods (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\")\n   apply(rename_tac n)(*strict*)\n   prefer 2\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def PValidSplit_def)\n   apply(force)\n  apply(rename_tac n)(*strict*)\n  apply(subgoal_tac \"restrict_newto S1 n = PSplitItem_to (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\")\n   apply(rename_tac n)(*strict*)\n   prefer 2\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def PValidSplit_def)\n   apply(force)\n  apply(rename_tac n)(*strict*)\n  apply(subgoal_tac \"restrict_newto S2 n = PSplitItem_to (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\")\n   apply(rename_tac n)(*strict*)\n   prefer 2\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def PValidSplit_def)\n   apply(force)\n  apply(rename_tac n)(*strict*)\n  apply(subgoal_tac \"PSplitItem_from (restrict G' G (S1 @ S1') (Suc (length v)) ! n) = PSplitItem_from (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\")\n   apply(rename_tac n)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"PSplitItem_elim (restrict G' G (S1 @ S1') (Suc (length v)) ! n) = PSplitItem_elim (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\")\n    apply(rename_tac n)(*strict*)\n    apply(force)\n   apply(rename_tac n)(*strict*)\n   apply(force)\n  apply(rename_tac n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n)(*strict*)\n  apply(subgoal_tac \"\\<exists>ds \\<pi>s fw. cfgLMTDL G ds (Esplit_signature S1) \\<pi>s fw\")\n   apply(rename_tac n)(*strict*)\n   prefer 2\n   apply(simp add: cfgLMTDL_def)\n   apply(subgoal_tac \"\\<exists>ds f\\<pi> fw. cfgLM.trans_der_list SSG ds (map (\\<lambda>w. \\<lparr>cfg_conf = [w]\\<rparr>) (Esplit_signature S1)) f\\<pi> (map (\\<lambda>w. \\<lparr>cfg_conf = w\\<rparr>) fw) \\<and> setA (foldl (@) [] fw) = {}\" for SSG)\n    apply(rename_tac n)(*strict*)\n    prefer 2\n    apply(rule construct_elimininating_trans_der_list)\n       apply(rename_tac n)(*strict*)\n       apply(simp add: split_TSstructure_def)\n       apply(force)\n      apply(rename_tac n)(*strict*)\n      apply(simp add: split_TSstructure_def)\n     apply(rename_tac n)(*strict*)\n     apply(rule Esplit_signature_belongs_setA)\n     apply(force)\n    apply(rename_tac n)(*strict*)\n    apply(rule Esplit_signature_belongs_setB)\n    apply(force)\n   apply(rename_tac n)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n ds f\\<pi> fw)(*strict*)\n   apply(rule_tac\n      x=\"ds\"\n      in exI)\n   apply(rule_tac\n      x=\"f\\<pi>\"\n      in exI)\n   apply(rule_tac\n      x=\"map filterB fw\"\n      in exI)\n   apply(rule_tac\n      t=\"(map (\\<lambda>x. \\<lparr>cfg_conf = liftB x\\<rparr>) (map filterB fw))\"\n      and s=\"(map (\\<lambda>w. \\<lparr>cfg_conf = w\\<rparr>) fw)\"\n      in ssubst)\n    apply(rename_tac n ds f\\<pi> fw)(*strict*)\n    apply(rule listEqI)\n     apply(rename_tac n ds f\\<pi> fw)(*strict*)\n     apply(force)\n    apply(rename_tac n ds f\\<pi> fw i)(*strict*)\n    apply(clarsimp)\n    apply (metis setA_empty_foldl liftBDeConv2)\n   apply(rename_tac n ds f\\<pi> fw)(*strict*)\n   apply(force)\n  apply(rename_tac n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(case_tac \"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)=[]\")\n   apply(rename_tac n ds \\<pi>s fw)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac n ds \\<pi>s fw)(*strict*)\n    prefer 2\n    apply(rule_tac\n      i=\"n\"\n      and ?S1.0=\"S1\"\n      and n=\"length v\"\n      and v=\"v\"\n      and b=\"b\"\n      in e_derivation_can_be_embedded_minimally)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      prefer 2\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                     apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                     apply(force)\n                    apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                    apply(force)\n                   apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                   apply(force)\n                  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                  apply(force)\n                 apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                 apply(force)\n                apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                apply(force)\n               apply(rename_tac n ds \\<pi>s fw)(*strict*)\n               apply(force)\n              apply(rename_tac n ds \\<pi>s fw)(*strict*)\n              apply(force)\n             apply(rename_tac n ds \\<pi>s fw)(*strict*)\n             apply(force)\n            apply(rename_tac n ds \\<pi>s fw)(*strict*)\n            apply(force)\n           apply(rename_tac n ds \\<pi>s fw)(*strict*)\n           apply(force)\n          apply(rename_tac n ds \\<pi>s fw)(*strict*)\n          apply(force)\n         apply(rename_tac n ds \\<pi>s fw)(*strict*)\n         apply(force)\n        apply(rename_tac n ds \\<pi>s fw)(*strict*)\n        apply(force)\n       apply(rename_tac n ds \\<pi>s fw)(*strict*)\n       apply(force)\n      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac n ds \\<pi>s fw)(*strict*)\n    prefer 2\n    apply(rule_tac\n      i=\"n\"\n      and ?S1.0=\"S2\"\n      and n=\"length v\"\n      and v=\"v\"\n      and b=\"b\"\n      in e_derivation_can_be_embedded_minimally)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      prefer 2\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                     apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                     apply(force)\n                    apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                    apply(force)\n                   apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                   apply(force)\n                  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                  apply(force)\n                 apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                 apply(force)\n                apply(rename_tac n ds \\<pi>s fw)(*strict*)\n                apply(force)\n               apply(rename_tac n ds \\<pi>s fw)(*strict*)\n               apply(force)\n              apply(rename_tac n ds \\<pi>s fw)(*strict*)\n              apply(force)\n             apply(rename_tac n ds \\<pi>s fw)(*strict*)\n             apply(force)\n            apply(rename_tac n ds \\<pi>s fw)(*strict*)\n            apply(force)\n           apply(rename_tac n ds \\<pi>s fw)(*strict*)\n           apply(force)\n          apply(rename_tac n ds \\<pi>s fw)(*strict*)\n          apply(force)\n         apply(rename_tac n ds \\<pi>s fw)(*strict*)\n         apply(force)\n        apply(rename_tac n ds \\<pi>s fw)(*strict*)\n        apply(force)\n       apply(rename_tac n ds \\<pi>s fw)(*strict*)\n       apply(force)\n      apply(rename_tac n ds \\<pi>s fw)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n   apply(subgoal_tac \"Suc n\\<le>length v\")\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    prefer 2\n    apply(case_tac \"n=length v\")\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(subgoal_tac \"False\")\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     prefer 2\n     apply(rule_tac\n      n=\"length v\"\n      and S=\"S2\"\n      in restrict_newignore_last_empty)\n       apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n       apply(force)\n      apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(rule ESplitItem_to_not_empty_on_generating_line)\n         apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n         apply(force)\n        apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n        apply(force)\n       apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n       apply(force)\n      apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(subgoal_tac \"restrict_newignore S2 (length v) = PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\")\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(simp (no_asm_simp) add: restrict_def restrict_map_def restrict_len_def)\n    apply(rule_tac\n      t=\"nat_seq 0 (length v) ! length v\"\n      in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(rule nat_seq_nth_compute)\n      apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(simp (no_asm_simp))\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n   apply(subgoal_tac \"PSplitItem_to (restrict G' G (S2 @ S2') (Suc (length v)) ! n) = ESplitItem_to ((S2 @ S2') ! n)\")\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    prefer 2\n    apply(rule_tac\n      t=\"PSplitItem_to (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n      and s=\"restrict_newto (take (Suc (length v)) S2 @ take (Suc (length v) - length S2) S2') n\"\n      in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(rule_tac\n      t=\"(S2 @ S2') ! n\"\n      and s=\"S2!n\"\n      in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(rule nth_append_1)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(rule_tac\n      t=\"length S2\"\n      and s=\"Suc (length v)\"\n      in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(rule_tac\n      t=\"take (Suc (length v) - Suc (length v)) S2'\"\n      and s=\"[]\"\n      in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(rule_tac\n      t=\"take (Suc (length v)) S2\"\n      and s=\"S2\"\n      in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(rule take_all)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(simp (no_asm))\n    apply(rule nonemtpy_newignore_implies_newto_unchanged)\n    apply(rule_tac\n      t=\"restrict_newignore S2 n\"\n      and s=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n      in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(simp (no_asm_simp))\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n   apply(subgoal_tac \"PSplitItem_to (restrict G' G (S1 @ S1') (Suc (length v)) ! n) = ESplitItem_to ((S1 @ S1') ! n)\")\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    prefer 2\n    apply(rule_tac\n      t=\"PSplitItem_to (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\"\n      and s=\"restrict_newto (take (Suc (length v)) S1 @ take (Suc (length v) - length S1) S1') n\"\n      in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(rule_tac\n      t=\"(S1 @ S1') ! n\"\n      and s=\"S1!n\"\n      in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(rule nth_append_1)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(rule_tac\n      t=\"length S1\"\n      and s=\"Suc (length v)\"\n      in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(rule_tac\n      t=\"take (Suc (length v) - Suc (length v)) S1'\"\n      and s=\"[]\"\n      in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(rule_tac\n      t=\"take (Suc (length v)) S1\"\n      and s=\"S1\"\n      in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(rule take_all)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(simp (no_asm))\n    apply(rule nonemtpy_newignore_implies_newto_unchanged)\n    apply(rule_tac\n      t=\"restrict_newignore S1 n\"\n      and s=\"PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\"\n      in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(simp (no_asm_simp))\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n   apply(subgoal_tac \"restrict_newprods G' G S2 n = liftB (ESplitItem_prods (S2!n))\")\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    prefer 2\n    apply(case_tac \"ESplitItem_from (S2 ! n)\")\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(simp add: EValidSplit_def EValidSplit_producing_def)\n     apply(clarsimp)\n     apply(erule_tac\n      x=\"S2!n\"\n      and A=\"set (butlast (S2 @ S2'))\"\n      and P=\"\\<lambda>X. (\\<exists>y. ESplitItem_from X = Some y) \\<and> (\\<exists>y. ESplitItem_elem X = Some y)\"\n      in ballE)\n      apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n      prefer 2\n      apply(rule in_set_butlast_append2)\n       apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n       apply(force)\n      apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a)(*strict*)\n    apply(subgoal_tac \"EValidSplitItem_gen G (S2 ! n)\")\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a)(*strict*)\n     prefer 2\n     apply(simp add: EValidSplit_def EValidSplit_ValidItem_def EValidSplitItem_def)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a)(*strict*)\n    apply(simp (no_asm_use) only: EValidSplitItem_gen_def)\n    apply(erule exE)+\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n    apply(erule conjE)+\n    apply(rule_tac\n      A=\"a\"\n      in nonemtpy_newignore_implies_newprods_unchanged)\n       apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n       apply(simp add: split_TSstructure_def)\n      apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n      apply(rule_tac\n      t=\"restrict_newignore S2 n\"\n      and s=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n      in ssubst)\n       apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n       apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(simp (no_asm_simp))\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n   apply(rule_tac\n    t=\"the (ESplitItem_elem (S2 ! n)) # liftA (ESplitItem_to (S2 ! n))\"\n    and s=\"option_to_list (ESplitItem_elem (S2 ! n)) @ liftA (ESplitItem_to (S2 ! n))\"\n    in ssubst)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n    apply(simp (no_asm_simp))\n    apply(simp add: option_to_list_def)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n   apply(rule_tac\n    t=\"[teA a]\"\n    and s=\"liftA (option_to_list (ESplitItem_from (S2 ! n)))\"\n    in ssubst)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n    apply(rule_tac\n    t=\"ESplitItem_from (S2 ! n)\"\n    and s=\"Some a\"\n    in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n    apply(simp add: option_to_list_def)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n  apply(rule generation_derivation_has_always_nonterminal_at_front)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n     apply(simp add: split_TSstructure_def)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n   apply(blast)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(subgoal_tac \"restrict_newprods G' G S1 n = liftB (ESplitItem_prods (S1!n))\")\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  prefer 2\n  apply(case_tac \"ESplitItem_from (S1 ! n)\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n   apply(simp add: EValidSplit_def EValidSplit_producing_def)\n   apply(clarsimp)\n   apply(erule_tac\n    A=\"set (butlast (S1 @ S1'))\"\n    and x=\"S1!n\"\n    in ballE)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    prefer 2\n    apply(rule in_set_butlast_append2)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a)(*strict*)\n  apply(subgoal_tac \"EValidSplitItem_gen G (S1 ! n)\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a)(*strict*)\n   prefer 2\n   apply(simp add: EValidSplit_def EValidSplit_ValidItem_def EValidSplitItem_def)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a)(*strict*)\n  apply(simp (no_asm_use) only: EValidSplitItem_gen_def)\n  apply(erule exE)+\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n  apply(erule conjE)+\n  apply(rule_tac\n    A=\"a\"\n    in nonemtpy_newignore_implies_newprods_unchanged)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n     apply(simp add: split_TSstructure_def)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n    apply(rule_tac\n    t=\"restrict_newignore S1 n\"\n    and s=\"PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\"\n    in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(simp (no_asm_simp))\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n   apply(rule_tac\n    t=\"the (ESplitItem_elem (S1 ! n)) # liftA (ESplitItem_to (S1 ! n))\"\n    and s=\"option_to_list (ESplitItem_elem (S1 ! n)) @ liftA (ESplitItem_to (S1 ! n))\"\n    in ssubst)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n    apply(simp (no_asm_simp))\n    apply(simp add: option_to_list_def)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n   apply(rule_tac\n    t=\"[teA a]\"\n    and s=\"liftA (option_to_list (ESplitItem_from (S1 ! n)))\"\n    in ssubst)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n    apply(rule_tac\n    t=\"ESplitItem_from (S1 ! n)\"\n    and s=\"Some a\"\n    in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n    apply(simp add: option_to_list_def)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n  apply(rule generation_derivation_has_always_nonterminal_at_front)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n     apply(simp add: split_TSstructure_def)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n   apply(blast)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a d)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(rule_tac\n    t=\"PSplitItem_prods (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\"\n    and s=\"liftB (ESplitItem_prods (S1 ! n))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(rule_tac\n    t=\"liftB (ESplitItem_prods (S1 ! n))\"\n    and s=\"restrict_newprods G' G S1 n\"\n    in ssubst)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(simp (no_asm_simp))\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(rule_tac\n    t=\"PSplitItem_prods (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n    and s=\"liftB (ESplitItem_prods (S2 ! n))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(rule_tac\n    t=\"liftB (ESplitItem_prods (S2 ! n))\"\n    and s=\"restrict_newprods G' G S2 n\"\n    in ssubst)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(simp (no_asm_simp))\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(rule_tac\n    t=\"PSplitItem_to (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\"\n    and s=\"ESplitItem_to ((S1 @ S1') ! n)\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(rule_tac\n    t=\"PSplitItem_to (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n    and s=\"ESplitItem_to ((S2 @ S2') ! n)\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(rule_tac\n    t=\"(S1 @ S1') ! n\"\n    and s=\"S1!n\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(rule nth_append_1)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(rule_tac\n    t=\"(S2 @ S2') ! n\"\n    and s=\"S2!n\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(rule nth_append_1)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(rule_tac\n    t=\"liftB (ESplitItem_prods (S1 ! n)) = liftB (ESplitItem_prods (S2 ! n))\"\n    and s=\"(ESplitItem_prods (S1 ! n)) = (ESplitItem_prods (S2 ! n))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(rule order_antisym)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n   apply(simp (no_asm))\n   apply(rule impI)\n   apply(rule liftB_inj)\n   apply(blast)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(simp (no_asm))\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(rule_tac\n    t=\"map (case_DT_two_elements teA (\\<lambda>p. teA (prod_to_edge G' p))) (liftB (ESplitItem_prods (S1 ! n)))\"\n    and s=\"liftA(map (prod_to_edge G') (ESplitItem_prods (S1 ! n)))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(rule prod_to_edge_liftA_liftB)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(rule_tac\n    t=\"map (case_DT_two_elements teA (\\<lambda>p. teA (prod_to_edge G' p))) (liftB (ESplitItem_prods (S2 ! n)))\"\n    and s=\"liftA(map (prod_to_edge G') (ESplitItem_prods (S2 ! n)))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(rule prod_to_edge_liftA_liftB)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(thin_tac \"cfgLM.trans_der G e_d2a \\<lparr>cfg_conf = [teA (last (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n))) (ESplitItem_ignore ((S2 @ S2') ! n))))))]\\<rparr> e_\\<pi>2a \\<lparr>cfg_conf = liftB \\<alpha>2a @ teB b # vaa\\<rparr>\")\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(thin_tac \"cfgLM.trans_der G e_d2 \\<lparr>cfg_conf = [teA (last (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n))) (ESplitItem_ignore ((S1 @ S1') ! n))))))]\\<rparr> e_\\<pi>2 \\<lparr>cfg_conf = liftB \\<alpha>2 @ teB b # va\\<rparr>\")\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(case_tac \"ESplitItem_from (S1 ! n)\")\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(simp add: EValidSplit_def EValidSplit_producing_def)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(clarsimp)\n  apply(erule_tac\n    x=\"S1!n\"\n    and A=\"set (butlast (S1 @ S1'))\"\n    in ballE)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n   prefer 2\n   apply(rule in_set_butlast_append2)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a)(*strict*)\n  apply(case_tac \"ESplitItem_from (S2 ! n)\")\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a)(*strict*)\n  apply(simp add: EValidSplit_def EValidSplit_producing_def)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a)(*strict*)\n  apply(clarsimp)\n  apply(erule_tac\n    x=\"S2!n\"\n    and A=\"set (butlast (S2 @ S2'))\"\n    in ballE)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a)(*strict*)\n   prefer 2\n   apply(rule in_set_butlast_append2)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a aa)(*strict*)\n  apply(rename_tac F1 F2)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n  apply(rule_tac\n    t=\"liftA (map (prod_to_edge G') (ESplitItem_prods (S1 ! n))) = liftA (map (prod_to_edge G') (ESplitItem_prods (S2 ! n)))\"\n    and s=\" (map (prod_to_edge G') (ESplitItem_prods (S1 ! n))) = (map (prod_to_edge G') (ESplitItem_prods (S2 ! n)))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n  apply(rule order_antisym)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n   apply(simp (no_asm))\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n   apply(rule impI)\n   apply(rule liftA_inj)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n  apply(simp (no_asm))\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n  apply(subgoal_tac \"ESplitItem_prods (S1 ! n) = ESplitItem_prods (S2 ! n)\")\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n  apply(subgoal_tac \"option_to_list (ESplitItem_elem (S2 ! n)) @ liftA (ESplitItem_to (S2 ! n)) = option_to_list (ESplitItem_elem (S1 ! n)) @ liftA (ESplitItem_to (S1 ! n))\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n   apply(rule liftA_inj)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n   apply(rule_tac\n    w=\"option_to_list (ESplitItem_elem (S2 ! n))\"\n    in append_linj)\n   apply(rule_tac\n    t=\"option_to_list (ESplitItem_elem (S2 ! n)) @ liftA (ESplitItem_to (S2 ! n))\"\n    and s=\"option_to_list (ESplitItem_elem (S1 ! n)) @ liftA (ESplitItem_to (S1 ! n))\"\n    in ssubst)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n   apply(rule_tac\n    t=\"ESplitItem_elem (S1 ! n)\"\n    and s=\"ESplitItem_elem (S2 ! n)\"\n    in ssubst)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n  apply(subgoal_tac \"EValidSplitItem_gen G (S1 ! n)\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n   prefer 2\n   apply(simp add: EValidSplit_def EValidSplit_ValidItem_def EValidSplitItem_def)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n  apply(simp (no_asm_use) only: EValidSplitItem_gen_def)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n  apply(subgoal_tac \"EValidSplitItem_gen G (S2 ! n)\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n   prefer 2\n   apply(simp add: EValidSplit_def EValidSplit_ValidItem_def EValidSplitItem_def)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n  apply(simp (no_asm_use) only: EValidSplitItem_gen_def)\n  apply(erule exE)+\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n  apply(erule conjE)+\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n  apply(subgoal_tac \"da (length ((ESplitItem_prods (S1 ! n)))) = d (length((ESplitItem_prods (S1 ! n))))\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n   apply(simp add: cfgLM.trans_der_def)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n  apply(rule_tac\n    ?d2.0=\"da\"\n    and ?d1.0=\"d\"\n    and ?\\<pi>2.0=\"[]\"\n    in cfgLM_trans_der_coincide)\n      apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n      apply(simp add: split_TSstructure_def)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n    apply(rule_tac\n    t=\"liftA (option_to_list (Some F1))\"\n    and s=\"liftA (option_to_list (ESplitItem_from (S2 ! n)))\"\n    in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n    apply(rule_tac\n    f=\"liftA\"\n    in arg_cong)\n    apply(rule_tac\n    f=\"option_to_list\"\n    in arg_cong)\n    apply(rule_tac\n    t=\"ESplitItem_from (S2 ! n)\"\n    and s=\"Some (PSplitItem_from (restrict G' G (S2 @ S2') (Suc (length v)) ! n))\"\n    in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n     apply(simp (no_asm_simp))\n     apply(rule cropTol3l2_ID)\n     apply(rule_tac\n    t=\"restrict_newignore S2 n\"\n    and s=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n    in ssubst)\n      apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n     apply(rule_tac\n    t=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n    and s=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n    in ssubst)\n      apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(simp (no_asm_simp))\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n    apply(rule_tac\n    t=\"PSplitItem_from (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n    and s=\"PSplitItem_from (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\"\n    in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n    apply(rule_tac\n    t=\"Some F1\"\n    and s=\"ESplitItem_from (S1 ! n)\"\n    in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n    apply(rule_tac\n    t=\"ESplitItem_from (S1 ! n)\"\n    and s=\"Some (PSplitItem_from (restrict G' G (S1 @ S1') (Suc (length v)) ! n))\"\n    in ssubst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n     apply(simp (no_asm_simp))\n     apply(rule cropTol3l2_ID)\n     apply(rule_tac\n    t=\"restrict_newignore S1 n\"\n    and s=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n    in ssubst)\n      apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n     apply(rule_tac\n    t=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n    and s=\"PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\"\n    in ssubst)\n      apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(simp (no_asm_simp))\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 d da)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n  apply(case_tac \"F1\")\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q ba)(*strict*)\n  apply(rename_tac qF1 AF1)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 qF1 AF1)(*strict*)\n  apply(subgoal_tac \"False\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 qF1 AF1)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 qF1 AF1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n  apply(subgoal_tac \"ESplitItem_ignore (S1 ! n) = []\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"proper_l3_l2_seq (PSplitItem_elim (restrict G' G (S2 @ S2') (Suc (length v)) ! n) @ option_to_list (Some (cons_l2 qF1 AF1)) @ ESplitItem_ignore (S1 ! n))\")\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n    prefer 2\n    apply(subgoal_tac \"EValidSplitItem_belongs G (S1 ! n)\")\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n     prefer 2\n     apply(simp add: EValidSplit_def EValidSplit_ValidItem_def EValidSplitItem_def)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n    apply(simp add: EValidSplitItem_belongs_def)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n   apply(simp (no_asm_use) add: option_to_list_def)\n   apply(rule l2_in_proper_l3_l2_seq_at_end)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n  apply(subgoal_tac \"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n) = []\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n  apply(rule_tac\n    t=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n    and s=\"PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\"\n    in ssubst)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(simp (no_asm_simp))\n  apply(simp (no_asm) add: restrict_newignore_def new_post_sig_def)\n  apply(rule_tac\n    t=\"length (drop_and_crop (ESplitItem_to (S1 ! n) @ ESplitItem_ignore (S1 ! n)) (length (restrict_toberemovedX S1 ! Suc n)))\"\n    in ssubst)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n   apply(rule drop_and_crop_length)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q1 ba q2)(*strict*)\n  apply(case_tac \"F2\")\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q1 ba q2 q baa)(*strict*)\n  apply(rename_tac qF2 AF2)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q1 ba q2 qF2 AF2)(*strict*)\n  apply(subgoal_tac \"False\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q1 ba q2 qF2 AF2)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q1 ba q2 qF2 AF2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n  apply(subgoal_tac \"ESplitItem_ignore (S2 ! n) = []\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"proper_l3_l2_seq (PSplitItem_elim (restrict G' G (S2 @ S2') (Suc (length v)) ! n) @ option_to_list (Some (cons_l2 qF2 AF2)) @ ESplitItem_ignore (S2 ! n))\")\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n    prefer 2\n    apply(subgoal_tac \"EValidSplitItem_belongs G (S2 ! n)\")\n     apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n     prefer 2\n     apply(simp add: EValidSplit_def EValidSplit_ValidItem_def EValidSplitItem_def)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n    apply(simp add: EValidSplitItem_belongs_def)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n   apply(simp (no_asm_use) add: option_to_list_def)\n   apply(rule l2_in_proper_l3_l2_seq_at_end)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n  apply(subgoal_tac \"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n) = []\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(simp (no_asm_simp))\n  apply(simp (no_asm) add: restrict_newignore_def new_post_sig_def)\n  apply(rule_tac\n    t=\"length (drop_and_crop (ESplitItem_to (S2 ! n) @ ESplitItem_ignore (S2 ! n)) (length (restrict_toberemovedX S2 ! Suc n)))\"\n    in ssubst)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n   apply(rule drop_and_crop_length)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q1 ba q2 q1a baa q2a)(*strict*)\n  apply(rename_tac q11 A1 q12 q21 A2 q22)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n  prefer 2\n  apply(rule_tac\n    d=\"e_d1\"\n    and A=\"(cons_l3 q11 A1 q12)\"\n    and w=\"liftA(butlast (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n))) (ESplitItem_ignore ((S1 @ S1') ! n))))))\"\n    in from_derives_prefix)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n   apply(simp add: split_TSstructure_def)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n  apply(rule_tac\n    t=\"[teA (cons_l3   q11 A1 q12)] @ liftA (butlast (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n))) (ESplitItem_ignore ((S1 @ S1') ! n))))))\"\n    and s=\"liftA (option_to_list (ESplitItem_from ((S1 @ S1') ! n)) @ butlast (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n))) (ESplitItem_ignore ((S1 @ S1') ! n))))))\"\n    in ssubst)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n   apply(simp (no_asm))\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n   apply(simp (no_asm) add: liftA_commutes_over_concat)\n   apply(rule_tac\n    t=\"(S1 @ S1') ! n\"\n    and s=\"S1!n\"\n    in ssubst)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n    apply(rule nth_append_1)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n   apply(simp (no_asm_simp) add: option_to_list_def)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n  prefer 2\n  apply(rule_tac\n    d=\"e_d1a\"\n    and A=\"(cons_l3 q21 A2 q22)\"\n    and w=\"liftA(butlast (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n))) (ESplitItem_ignore ((S2 @ S2') ! n))))))\"\n    in from_derives_prefix)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n   apply(simp add: split_TSstructure_def)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n  apply(rule_tac\n    t=\"[teA (cons_l3   q21 A2 q22)] @ liftA (butlast (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n))) (ESplitItem_ignore ((S2 @ S2') ! n))))))\"\n    and s=\"liftA (option_to_list (ESplitItem_from ((S2 @ S2') ! n)) @ butlast (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n))) (ESplitItem_ignore ((S2 @ S2') ! n))))))\"\n    in ssubst)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n   apply(simp (no_asm))\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n   apply(simp (no_asm) add: liftA_commutes_over_concat)\n   apply(rule_tac\n    t=\"(S2 @ S2') ! n\"\n    and s=\"S2!n\"\n    in ssubst)\n    apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n    apply(rule nth_append_1)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n   apply(simp (no_asm_simp) add: option_to_list_def)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n  apply(thin_tac \"cfgLM.trans_der G e_d1 \\<lparr>cfg_conf = liftA (option_to_list (ESplitItem_from ((S1 @ S1') ! n)) @ butlast (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n))) (ESplitItem_ignore ((S1 @ S1') ! n))))))\\<rparr> e_\\<pi>1 \\<lparr>cfg_conf = liftB \\<alpha>1\\<rparr>\")\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n  apply(thin_tac \"cfgLM.trans_der G e_d1a \\<lparr>cfg_conf = liftA (option_to_list (ESplitItem_from ((S2 @ S2') ! n)) @ butlast (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n))) (ESplitItem_ignore ((S2 @ S2') ! n))))))\\<rparr> e_\\<pi>1a \\<lparr>cfg_conf = liftB \\<alpha>1a\\<rparr>\")\n  apply(rename_tac n ds \\<pi>s fw p_d e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 p_da e_d1a e_d2a vaa e_\\<pi>1a e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n  apply(subgoal_tac \"ESplitItem_from (S1 ! n) = ESplitItem_from (S2 ! n)\")\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n  prefer 2\n  apply(rule_tac\n    t=\"ESplitItem_from (S1 ! n)\"\n    and s=\"Some (PSplitItem_from (restrict G' G (S1 @ S1') (Suc (length v)) ! n))\"\n    in ssubst)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n   apply(simp (no_asm_simp))\n   apply(rule cropTol3l2_ID)\n   apply(rule_tac\n    t=\"restrict_newignore S1 n\"\n    and s=\"PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\"\n    in ssubst)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n   apply(rule_tac\n    t=\"PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\"\n    and s=\"PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\"\n    in ssubst)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n   apply(simp (no_asm_simp))\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n  apply(rule_tac\n    t=\"ESplitItem_from (S2 ! n)\"\n    and s=\"Some (PSplitItem_from (restrict G' G (S2 @ S2') (Suc (length v)) ! n))\"\n    in ssubst)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n   apply(simp (no_asm_simp))\n   apply(rule cropTol3l2_ID)\n   apply(rule_tac\n    t=\"restrict_newignore S2 n\"\n    and s=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n    in ssubst)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n   apply(rule_tac\n    t=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n    and s=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n    in ssubst)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n   apply(simp (no_asm_simp))\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n  prefer 2\n  apply(rule_tac\n    G=\"G'\"\n    and G'=\"G\"\n    and ?d1.0=\"d1a\"\n    and ?d2.0=\"d1aa\"\n    and ?x1.0=\"\\<alpha>2b@\\<alpha>2\"\n    and ?x2.0=\"\\<alpha>2c@\\<alpha>2a\"\n    in eliminating_derivations_are_equal_with_differing_future6)\n         apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n         apply(simp add: F2LR1inputx_def)\n        apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n        apply(simp add: F2LR1inputx_def)\n       apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n       apply(simp add: F2LR1inputx_def)\n      apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n      apply(simp add: F2LR1inputx_def)\n     apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n     apply(simp add: F2LR1inputx_def)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n  apply(subgoal_tac \"EValidSplitItem_gen G (S1 ! n)\")\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n  prefer 2\n  apply(simp add: EValidSplit_def EValidSplit_ValidItem_def EValidSplitItem_def)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n  apply(subgoal_tac \"EValidSplitItem_gen G (S2 ! n)\")\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n  prefer 2\n  apply(simp add: EValidSplit_def EValidSplit_ValidItem_def EValidSplitItem_def)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n  apply(simp add: EValidSplitItem_gen_def)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(rule_tac\n    v=\"\\<pi>1a\"\n    in equal_by_length_and_prefix_of_greater)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"strict_prefix \\<pi>1a (ESplitItem_prods (S1 ! n)) \\<or> SSX\" for SSX)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n    prefer 2\n    apply(rule_tac\n    b=\"\\<pi>2 @ e_\\<pi>2\"\n    and d=\"\\<pi>s ! n @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S1 @ S1') ! x)) @ ESplitItem_prods ((S1 @ S1') ! x) @ \\<pi>s ! x) (nat_seq (Suc n) (length v)))\"\n    in mutual_strict_prefix_prefix)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n    apply(rule sym)\n    apply(rule_tac\n    t=\"S1 ! n\"\n    and s=\"(S1@S1') ! n\"\n    in subst)\n     apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n     apply(rule nth_append_1)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(subgoal_tac \"False\")\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(simp add: strict_prefix_def)\n   apply(clarsimp)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n   apply(subgoal_tac \"c=[]\")\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n   apply(rule_tac\n    ?d1.0=\"d1a\"\n    and ?d2.0=\"d\"\n    in unique_generation_length)\n      apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n      apply(simp add: split_TSstructure_def)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"strict_prefix \\<pi>1a (ESplitItem_prods (S2 ! n)) \\<or> SSX\" for SSX)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   prefer 2\n   apply(rule_tac\n    b=\"\\<pi>2a @ e_\\<pi>2a\"\n    and d=\"\\<pi>s ! n @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S2 @ S2') ! x)) @ ESplitItem_prods ((S2 @ S2') ! x) @ \\<pi>s ! x) (nat_seq (Suc n) (length v)))\"\n    in mutual_strict_prefix_prefix)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(rule sym)\n   apply(rule_tac\n    t=\"S2 ! n\"\n    and s=\"(S2@S2') ! n\"\n    in subst)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n    apply(rule nth_append_1)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(subgoal_tac \"False\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(simp add: strict_prefix_def)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n  apply(subgoal_tac \"c=[]\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n  apply(rule_tac\n    ?d1.0=\"d1aa\"\n    and ?d2.0=\"da\"\n    in unique_generation_length)\n     apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n     apply(simp add: split_TSstructure_def)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(subgoal_tac \"prefix (ESplitItem_prods (S1 ! n)) \\<pi>1a\")\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"strict_prefix \\<pi>1a (ESplitItem_prods (S1 ! n)) \\<or> SSX\" for SSX)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   prefer 2\n   apply(rule_tac\n    b=\"\\<pi>2 @ e_\\<pi>2\"\n    and d=\"\\<pi>s ! n @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S1 @ S1') ! x)) @ ESplitItem_prods ((S1 @ S1') ! x) @ \\<pi>s ! x) (nat_seq (Suc n) (length v)))\"\n    in mutual_strict_prefix_prefix)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(rule sym)\n   apply(rule_tac\n    t=\"S1 ! n\"\n    and s=\"(S1@S1') ! n\"\n    in subst)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n    apply(rule nth_append_1)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(subgoal_tac \"False\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(simp add: strict_prefix_def)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n  apply(subgoal_tac \"c=[]\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n  apply(rule_tac\n    ?d1.0=\"d1a\"\n    and ?d2.0=\"d\"\n    in unique_generation_length)\n     apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n     apply(simp add: split_TSstructure_def)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(subgoal_tac \"prefix (ESplitItem_prods (S2 ! n)) \\<pi>1a\")\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"strict_prefix \\<pi>1a (ESplitItem_prods (S2 ! n)) \\<or> SSX\" for SSX)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   prefer 2\n   apply(rule_tac\n    b=\"\\<pi>2a @ e_\\<pi>2a\"\n    and d=\"\\<pi>s ! n @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S2 @ S2') ! x)) @ ESplitItem_prods ((S2 @ S2') ! x) @ \\<pi>s ! x) (nat_seq (Suc n) (length v)))\"\n    in mutual_strict_prefix_prefix)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(rule sym)\n   apply(rule_tac\n    t=\"S2 ! n\"\n    and s=\"(S2@S2') ! n\"\n    in subst)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n    apply(rule nth_append_1)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(subgoal_tac \"False\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(simp add: strict_prefix_def)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n  apply(subgoal_tac \"c=[]\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n  apply(rule_tac\n    ?d1.0=\"d1aa\"\n    and ?d2.0=\"da\"\n    in unique_generation_length)\n     apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n     apply(simp add: split_TSstructure_def)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(case_tac \"Esplit_signature S1 ! n\")\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n  apply(case_tac \"length (ESplitItem_prods (S1 ! n)) < length (ESplitItem_prods (S2 ! n))\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n   apply(subgoal_tac \"strict_prefix (ESplitItem_prods (S1 ! n)) (ESplitItem_prods (S2 ! n))\")\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n    prefer 2\n    apply(rule_tac\n    v=\"\\<pi>1a\"\n    in strict_prefix_from_prefix_of_longer_and_shorter)\n      apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n   apply(simp add: strict_prefix_def prefix_def)\n   apply(clarsimp)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n   apply(rule_tac\n    v=\"[]\"\n    and ?d1.0=\"d\"\n    and ?d2.0=\"da\"\n    in left_degen_repetitions_in_parallel_derivation)\n         apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n         apply(force)\n        apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n        apply(force)\n       apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n       apply(force)\n      apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n  apply(case_tac \"length (ESplitItem_prods (S2 ! n)) < length (ESplitItem_prods (S1 ! n))\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n   apply(subgoal_tac \"strict_prefix (ESplitItem_prods (S2 ! n)) (ESplitItem_prods (S1 ! n))\")\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n    prefer 2\n    apply(rule_tac\n    v=\"\\<pi>1a\"\n    in strict_prefix_from_prefix_of_longer_and_shorter)\n      apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n   apply(simp add: strict_prefix_def prefix_def)\n   apply(clarsimp)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n   apply(rule_tac\n    v=\"[]\"\n    and ?d1.0=\"da\"\n    and ?d2.0=\"d\"\n    in left_degen_repetitions_in_parallel_derivation)\n         apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n         apply(force)\n        apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n        apply(force)\n       apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n       apply(force)\n      apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"length (ESplitItem_prods (S1 ! n)) < length (ESplitItem_prods (S2 ! n))\")\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n  apply(subgoal_tac \"strict_prefix (ESplitItem_prods (S1 ! n)) (ESplitItem_prods (S2 ! n))\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n   prefer 2\n   apply(rule_tac\n    v=\"\\<pi>1a\"\n    in strict_prefix_from_prefix_of_longer_and_shorter)\n     apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n  apply(simp add: strict_prefix_def prefix_def)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n  apply(rule_tac\n    v=\"[]\"\n    and ?d1.0=\"d\"\n    and ?d2.0=\"da\"\n    in terminal_production_repetitions_in_parallel_derivation)\n       apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n       apply(force)\n      apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n  apply(case_tac \"length (ESplitItem_prods (S2 ! n)) < length (ESplitItem_prods (S1 ! n))\")\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n  apply(subgoal_tac \"strict_prefix (ESplitItem_prods (S2 ! n)) (ESplitItem_prods (S1 ! n))\")\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n   prefer 2\n   apply(rule_tac\n    v=\"\\<pi>1a\"\n    in strict_prefix_from_prefix_of_longer_and_shorter)\n     apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n  apply(simp add: strict_prefix_def prefix_def)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n  apply(rule_tac\n    v=\"[]\"\n    and ?d1.0=\"da\"\n    and ?d2.0=\"d\"\n    in terminal_production_repetitions_in_parallel_derivation)\n       apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n       apply(force)\n      apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw p_d e_\\<pi>2 p_da e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"fillOptL [] (last_back_state_if_l3_nonterminal []) = []\")\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  prefer 2\n  apply(simp add: fillOptL_def last_back_state_if_l3_nonterminal_def)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(rule_tac\n    t=\"PSplitItem_prods (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n    and s=\"restrict_newprods G' G (take (Suc (length v)) S2 @ take (Suc (length v) - length S2) S2') n\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(simp (no_asm) only: restrict_newprods_def)\n  apply(rule_tac\n    t=\"restrict_newignore (take (Suc (length v)) S2 @ take (Suc (length v) - length S2) S2') n\"\n    and s=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(rule_tac\n    t=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n    and s=\"[]\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(rule_tac\n    t=\"PSplitItem_prods (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\"\n    and s=\"restrict_newprods G' G (take (Suc (length v)) S1 @ take (Suc (length v) - length S1) S1') n\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(simp (no_asm) only: restrict_newprods_def)\n  apply(rule_tac\n    t=\"restrict_newignore (take (Suc (length v)) S1 @ take (Suc (length v) - length S1) S1') n\"\n    and s=\"PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(rule_tac\n    t=\"PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\"\n    and s=\"[]\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(rule_tac\n    t=\"PSplitItem_to (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\"\n    and s=\"restrict_newto S1 n\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(rule_tac\n    t=\"PSplitItem_to (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n    and s=\"restrict_newto S2 n\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(simp (no_asm) only: restrict_newto_def new_post_sig_def)\n  apply(rule_tac\n    t=\"ESplitItem_prods ((take (Suc (length v)) S1 @ take (Suc (length v) - length S1) S1') ! n)\"\n    and s=\"ESplitItem_prods (S1 ! n)\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(rule_tac\n    t=\"ESplitItem_prods ((take (Suc (length v)) S2 @ take (Suc (length v) - length S2) S2') ! n)\"\n    and s=\"ESplitItem_prods (S2 ! n)\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(subgoal_tac \"EValidSplitItem_gen G (S2 ! n)\")\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  prefer 2\n  apply(simp add: EValidSplit_def EValidSplit_ValidItem_def EValidSplitItem_def)\n  apply(rename_tac n ds \\<pi>s fw)(*strict*)\n  apply(simp (no_asm_use) only: EValidSplitItem_gen_def)\n  apply(erule exE)+\n  apply(rename_tac n ds \\<pi>s fw d)(*strict*)\n  apply(erule conjE)+\n  apply(subgoal_tac \"EValidSplitItem_gen G (S1 ! n)\")\n  apply(rename_tac n ds \\<pi>s fw d)(*strict*)\n  prefer 2\n  apply(simp add: EValidSplit_def EValidSplit_ValidItem_def EValidSplitItem_def)\n  apply(rename_tac n ds \\<pi>s fw d)(*strict*)\n  apply(simp (no_asm_use) only: EValidSplitItem_gen_def)\n  apply(erule exE)+\n  apply(rename_tac n ds \\<pi>s fw d da)(*strict*)\n  apply(erule conjE)+\n  apply(rename_tac d2x d1x)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x)(*strict*)\n  apply(case_tac \"ESplitItem_from (S1 ! n)\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x)(*strict*)\n  apply(clarsimp)\n  apply(simp add: option_to_list_def)\n  apply(subgoal_tac \"SSrenPI=[] \\<and> SSc2=\\<lparr>cfg_conf=[]\\<rparr>\" for SSrenPI SSc2)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x)(*strict*)\n  prefer 2\n  apply(rule_tac cfgLM_trans_der_from_empty)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x a)(*strict*)\n  apply(case_tac \"ESplitItem_from (S2 ! n)\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x a)(*strict*)\n  apply(clarsimp)\n  apply(simp add: option_to_list_def)\n  apply(subgoal_tac \"SSrenPI=[] \\<and> SSc2=\\<lparr>cfg_conf=[]\\<rparr>\" for SSrenPI SSc2)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x a)(*strict*)\n  prefer 2\n  apply(rule_tac cfgLM_trans_der_from_empty)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x a aa)(*strict*)\n  apply(rename_tac X1 X2)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(subgoal_tac \"cropTol3l2_single X1 = cropTol3l2_single X2\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    t=\"X1\"\n    and s=\"the(ESplitItem_from (S1 ! n))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule_tac\n    t=\"X2\"\n    and s=\"the(ESplitItem_from (S2 ! n))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule_tac\n    ?w1.0=\"restrict_newignore S1 n\"\n    and ?w2.0=\"restrict_newignore S2 n\"\n    in cropTol3l2_single_equal_from_cropTol3l2_equal)\n  apply(rule_tac\n    t=\"hd(cropTol3l2 (the (ESplitItem_from (S1 ! n)) # restrict_newignore S1 n))\"\n    and s=\"PSplitItem_from (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule_tac\n    t=\"hd(cropTol3l2 (the (ESplitItem_from (S2 ! n)) # restrict_newignore S2 n))\"\n    and s=\"PSplitItem_from (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(case_tac \"n=length v\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(simp (no_asm) add: restrict_toberemovedX_def)\n  apply(rule_tac\n    t=\"take (length (ESplitItem_to (S1 ! length v))) (drop_and_crop (ESplitItem_to (S1 ! length v) @ ESplitItem_ignore (S1 ! length v)) (length ((restrict_toberemoved S1 @ [tl (ESplitItem_to (last S1) @ ESplitItem_ignore (last S1))]) ! Suc (length v))))\"\n    and s=\"[cropTol3l2_single (hd (ESplitItem_to (S1 ! length v)))]\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(simp add: drop_and_crop_def butn_def)\n  apply(rule_tac\n    t=\"(restrict_toberemoved S1 @ [tl (ESplitItem_to (last S1) @ ESplitItem_ignore (last S1))]) ! Suc (length v)\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(rule nth_append_beyond)\n   apply(rule_tac\n    t=\"length (restrict_toberemoved S1)\"\n    in ssubst)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n    apply(rule length_restrict_toberemoved)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n    t=\"last S1\"\n    and s=\"S1!length v\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(rule last_nth3)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(subgoal_tac \"ESplitItem_to (S1 ! length v) \\<noteq> []\")\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   prefer 2\n   apply(rule ESplitItem_to_not_empty_on_generating_line)\n       apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(case_tac \"ESplitItem_to (S1 ! length v)\")\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 a list)(*strict*)\n  apply(clarsimp)\n  apply(simp add: cropTol3l2_def)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule_tac\n    t=\"take (length (ESplitItem_to (S2 ! length v))) (drop_and_crop (ESplitItem_to (S2 ! length v) @ ESplitItem_ignore (S2 ! length v)) (length ((restrict_toberemoved S2 @ [tl (ESplitItem_to (last S2) @ ESplitItem_ignore (last S2))]) ! Suc (length v))))\"\n    and s=\"[cropTol3l2_single (hd (ESplitItem_to (S2 ! length v)))]\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(simp add: drop_and_crop_def butn_def)\n  apply(rule_tac\n    t=\"(restrict_toberemoved S2 @ [tl (ESplitItem_to (last S2) @ ESplitItem_ignore (last S2))]) ! Suc (length v)\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(rule nth_append_beyond)\n   apply(rule_tac\n    t=\"length (restrict_toberemoved S2)\"\n    in ssubst)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n    apply(rule length_restrict_toberemoved)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n    t=\"last S2\"\n    and s=\"S2!length v\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(rule last_nth3)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(subgoal_tac \"ESplitItem_to (S2 ! length v) \\<noteq> []\")\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   prefer 2\n   apply(rule ESplitItem_to_not_empty_on_generating_line)\n       apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(case_tac \"ESplitItem_to (S2 ! length v)\")\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 a list)(*strict*)\n  apply(clarsimp)\n  apply(simp add: cropTol3l2_def)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"Esplit_signature S1 ! length v = teB b\")\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  prefer 2\n  apply(rule_tac t=\"Esplit_signature S1\" and s=\"v@[teB b]\" in ssubst)\n   apply(force)\n  apply(rule nth_append_length)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(subgoal_tac \"lastProduces d1x (ESplitItem_prods (S1 ! length v)) \\<and> lastProduces d2x (ESplitItem_prods (S2 ! length v))\")\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  prefer 2\n  apply(rule conjI)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(rule lastProduces_intro)\n     apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n     apply(simp add: split_TSstructure_def)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule lastProduces_intro)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n    apply(simp add: split_TSstructure_def)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    ?d1.0=\"d1x\"\n    and ?d2.0=\"d2x\"\n    in AX_equal_length_production_of_terminal_or_nonterminal)\n       apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n     apply(simp add: option_to_list_def)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n    apply(simp add: option_to_list_def)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    ?d1.0=\"d1x\"\n    and ?d2.0=\"d2x\"\n    in prod_to_edge_equality_for_terminal_and_nonterminal_generation)\n        apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n      apply(simp add: option_to_list_def)\n     apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n     apply(simp add: option_to_list_def)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(subgoal_tac \"only_l3_nonterminals (butlast (ESplitItem_to (S1 ! length v)))\")\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   prefer 2\n   apply(rule_tac\n    i=\"length((ESplitItem_prods (S1 ! length v)))\"\n    and d=\"d1x\"\n    in cfgLM.trans_der_position_detail)\n     apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n     apply(simp add: split_TSstructure_def)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e ci)(*strict*)\n  apply(case_tac ci)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e ci cfg_confa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e cfg_confa)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e cfg_confa)(*strict*)\n   prefer 2\n   apply(rule_tac\n    e=\"e\"\n    and v=\"cfg_confa\"\n    and \\<alpha>=\"[]\"\n    and w=\"[X1]\"\n    and d=\"d1x\"\n    and n=\"length((ESplitItem_prods (S1 ! length v)))\"\n    in only_l3_nonterminals_butlast_preserved)\n         apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e cfg_confa)(*strict*)\n         apply(force)\n        apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e cfg_confa)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e cfg_confa)(*strict*)\n       apply(clarsimp)\n       apply(simp add: option_to_list_def)\n      apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e cfg_confa)(*strict*)\n      apply(simp (no_asm))\n      apply(simp add: only_l3_nonterminals_def)\n     apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e cfg_confa)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e cfg_confa)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e cfg_confa)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e cfg_confa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v1 v2)(*strict*)\n  apply(simp add: cfgLM.trans_der_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v1 v2 ea)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(subgoal_tac \"v1=[b]\")\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v1 v2 ea)(*strict*)\n   prefer 2\n   apply(case_tac v1)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v1 v2 ea)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea)(*strict*)\n    apply(case_tac v2)\n     apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea a list)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v1 v2 ea a list)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea list)(*strict*)\n   apply(case_tac list)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea list)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea list a lista)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea a lista)(*strict*)\n   apply(case_tac \"ESplitItem_to (S1 ! length v)\")\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea a lista)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea a lista aa list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v1 v2 ea)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea)(*strict*)\n  apply(subgoal_tac \"v2=ESplitItem_to (S1 ! length v)\")\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea)(*strict*)\n  apply(rule liftA_inj)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(subgoal_tac \"only_l3_nonterminals (butlast (ESplitItem_to (S2 ! length v)))\")\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   prefer 2\n   apply(rule_tac\n    i=\"length((ESplitItem_prods (S2 ! length v)))\"\n    and d=\"d2x\"\n    in cfgLM.trans_der_position_detail)\n     apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n     apply(simp add: split_TSstructure_def)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e ci)(*strict*)\n  apply(case_tac ci)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e ci cfg_confa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e cfg_confa)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e cfg_confa)(*strict*)\n   prefer 2\n   apply(rule_tac\n    e=\"e\"\n    and v=\"cfg_confa\"\n    and \\<alpha>=\"[]\"\n    and w=\"[X2]\"\n    and d=\"d2x\"\n    and n=\"length((ESplitItem_prods (S2 ! length v)))\"\n    in only_l3_nonterminals_butlast_preserved)\n         apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e cfg_confa)(*strict*)\n         apply(force)\n        apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e cfg_confa)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e cfg_confa)(*strict*)\n       apply(clarsimp)\n       apply(simp add: option_to_list_def)\n      apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e cfg_confa)(*strict*)\n      apply(simp (no_asm))\n      apply(simp add: only_l3_nonterminals_def)\n     apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e cfg_confa)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e cfg_confa)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e cfg_confa)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e cfg_confa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v1 v2)(*strict*)\n  apply(simp add: cfgLM.trans_der_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v1 v2 ea)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(subgoal_tac \"v1=[b]\")\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v1 v2 ea)(*strict*)\n   prefer 2\n   apply(case_tac v1)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v1 v2 ea)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea)(*strict*)\n    apply(case_tac v2)\n     apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea a list)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v1 v2 ea a list)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea list)(*strict*)\n   apply(case_tac list)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea list)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea list a lista)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea a lista)(*strict*)\n   apply(case_tac \"ESplitItem_to (S2 ! length v)\")\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea a lista)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea a lista aa list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v1 v2 ea)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea)(*strict*)\n  apply(subgoal_tac \"v2=ESplitItem_to (S2 ! length v)\")\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2 e v2 ea)(*strict*)\n  apply(rule liftA_inj)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(subgoal_tac \"cropTol3l2_single (hd (ESplitItem_to (S1 ! length v))) = cropTol3l2_single (hd (ESplitItem_to (S2 ! length v)))\")\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    d1x=\"d1x\"\n    and d2x=\"d2x\"\n    in compatibel_derivation_compatible_first_nonterminal_at_end)\n         apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n         apply(force)\n        apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n       prefer 2\n       apply(simp add: option_to_list_def)\n      apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n      prefer 2\n      apply(simp add: option_to_list_def)\n     apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule conjI)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule_tac\n    t=\"map (case_DT_two_elements teA (\\<lambda>p. teA (prod_to_edge G' p))) (restrict_newprodsX G' G (ESplitItem_prods (S1 ! length v)) (Some (Esplit_signature S1 ! length v)) [cropTol3l2_single (hd (ESplitItem_to (S1 ! length v)))])\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(rule equal_split_prefix_hlp1_triv_eq)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule_tac\n    t=\"map (case_DT_two_elements teA (\\<lambda>p. teA (prod_to_edge G' p))) (restrict_newprodsX G' G (ESplitItem_prods (S2 ! length v)) (Some (Esplit_signature S1 ! length v)) [cropTol3l2_single (hd (ESplitItem_to (S2 ! length v)))])\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(rule equal_split_prefix_hlp1_triv_eq)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(subgoal_tac \"n<length v\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  prefer 2\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(clarsimp)\n  apply(simp (no_asm) add: restrict_toberemovedX_def)\n  apply(rule_tac\n    t=\"(restrict_toberemoved S1 @ [tl (ESplitItem_to (last S1) @ ESplitItem_ignore (last S1))]) ! Suc n\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule nth_append_1)\n  apply(rule_tac\n    t=\"length (restrict_toberemoved S1)\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule length_restrict_toberemoved)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule_tac\n    t=\"(restrict_toberemoved S2 @ [tl (ESplitItem_to (last S2) @ ESplitItem_ignore (last S2))]) ! Suc n\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule nth_append_1)\n  apply(rule_tac\n    t=\"length (restrict_toberemoved S2)\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule length_restrict_toberemoved)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(subgoal_tac \"length (ESplitItem_ignore (S1 ! n)) \\<le> length (restrict_toberemovedX S1 ! Suc n)\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"length (drop_and_crop (ESplitItem_to (S1 ! n) @ ESplitItem_ignore (S1 ! n)) (length (restrict_toberemovedX S1 ! Suc n))) \\<le> length (ESplitItem_to (S1 ! n))\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"restrict_newignore S1 n = []\")\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   prefer 2\n   apply(rule_tac\n    t=\"restrict_newignore S1 n\"\n    and s=\"PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! n)\"\n    in ssubst)\n    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(clarsimp)\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(simp add: restrict_newignore_def new_post_sig_def)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(subgoal_tac \"length (drop_and_crop (ESplitItem_to (S1 ! n) @ ESplitItem_ignore (S1 ! n)) (length (restrict_toberemovedX S1 ! Suc n))) \\<le> length (ESplitItem_to (S1 ! n))\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(subgoal_tac \"length (ESplitItem_to (S1 ! n) @ ESplitItem_ignore (S1 ! n)) - length (restrict_toberemovedX S1 ! Suc n) \\<le> length (ESplitItem_to (S1 ! n))\")\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule_tac\n    t=\"length (ESplitItem_to (S1 ! n) @ ESplitItem_ignore (S1 ! n)) - length (restrict_toberemovedX S1 ! Suc n)\"\n    in subst)\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(rule drop_and_crop_length)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(blast)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(subgoal_tac \"length (ESplitItem_ignore (S2 ! n)) \\<le> length (restrict_toberemovedX S2 ! Suc n)\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"length (drop_and_crop (ESplitItem_to (S2 ! n) @ ESplitItem_ignore (S2 ! n)) (length (restrict_toberemovedX S2 ! Suc n))) \\<le> length (ESplitItem_to (S2 ! n))\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"restrict_newignore S2 n = []\")\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   prefer 2\n   apply(rule_tac\n    t=\"restrict_newignore S2 n\"\n    and s=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! n)\"\n    in ssubst)\n    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(clarsimp)\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(simp add: restrict_newignore_def new_post_sig_def)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(subgoal_tac \"length (drop_and_crop (ESplitItem_to (S2 ! n) @ ESplitItem_ignore (S2 ! n)) (length (restrict_toberemovedX S2 ! Suc n))) \\<le> length (ESplitItem_to (S2 ! n))\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(subgoal_tac \"length (ESplitItem_to (S2 ! n) @ ESplitItem_ignore (S2 ! n)) - length (restrict_toberemovedX S2 ! Suc n) \\<le> length (ESplitItem_to (S2 ! n))\")\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule_tac\n    t=\"length (ESplitItem_to (S2 ! n) @ ESplitItem_ignore (S2 ! n)) - length (restrict_toberemovedX S2 ! Suc n)\"\n    in subst)\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(rule drop_and_crop_length)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(blast)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(subgoal_tac \"restrict_toberemovedX S1 ! Suc n = restrict_toberemoved S1 ! Suc n\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  prefer 2\n  apply(rule restrict_toberemovedX_equals_restrict_toberemoved)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(subgoal_tac \"restrict_toberemovedX S2 ! Suc n = restrict_toberemoved S2 ! Suc n\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  prefer 2\n  apply(rule restrict_toberemovedX_equals_restrict_toberemoved)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule_tac\n    t=\"take (length (ESplitItem_to (S2 ! n))) (drop_and_crop (ESplitItem_to (S2 ! n) @ ESplitItem_ignore (S2 ! n)) (length (restrict_toberemoved S2 ! Suc n)))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule take_all)\n  apply(rule_tac\n    t=\"length (drop_and_crop (ESplitItem_to (S2 ! n) @ ESplitItem_ignore (S2 ! n)) (length (restrict_toberemoved S2 ! Suc n)))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule drop_and_crop_length)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(simp (no_asm))\n  apply(rule_tac\n    t=\"restrict_toberemoved S2 ! Suc n\"\n    and s=\"restrict_toberemovedX S2 ! Suc n\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule_tac\n    t=\"take (length (ESplitItem_to (S1 ! n))) (drop_and_crop (ESplitItem_to (S1 ! n) @ ESplitItem_ignore (S1 ! n)) (length (restrict_toberemoved S1 ! Suc n)))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule take_all)\n  apply(rule_tac\n    t=\"length (drop_and_crop (ESplitItem_to (S1 ! n) @ ESplitItem_ignore (S1 ! n)) (length (restrict_toberemoved S1 ! Suc n)))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule drop_and_crop_length)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(simp (no_asm))\n  apply(rule_tac\n    t=\"restrict_toberemoved S1 ! Suc n\"\n    and s=\"restrict_toberemovedX S1 ! Suc n\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule_tac\n    t=\"drop_and_crop (ESplitItem_to (S1 ! n) @ ESplitItem_ignore (S1 ! n)) (length (restrict_toberemoved S1 ! Suc n))\"\n    and s=\" drop_and_crop (butn (ESplitItem_to (S1 ! n)) ((length (restrict_toberemoved S1 ! Suc n))-length(ESplitItem_ignore (S1 ! n))) ) 0\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(simp add: drop_and_crop_def butn_def)\n  apply(rule_tac\n    t=\"min (min (length (ESplitItem_to (S1 ! n))) (length (ESplitItem_to (S1 ! n)) + length (ESplitItem_ignore (S1 ! n)) - length (restrict_toberemoved S1 ! Suc n))) (length (ESplitItem_to (S1 ! n)) + length (ESplitItem_ignore (S1 ! n)) - length (restrict_toberemoved S1 ! Suc n))\"\n    and s=\"length (ESplitItem_to (S1 ! n)) + length (ESplitItem_ignore (S1 ! n)) - length (restrict_toberemoved S1 ! Suc n)\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    t=\"min (length (ESplitItem_to (S1 ! n))) (length (ESplitItem_to (S1 ! n)) + length (ESplitItem_ignore (S1 ! n)) - length (restrict_toberemoved S1 ! Suc n))\"\n    and s=\"length (ESplitItem_to (S1 ! n)) + length (ESplitItem_ignore (S1 ! n)) - length (restrict_toberemoved S1 ! Suc n)\"\n    in ssubst)\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule_tac\n    t=\"min (length (ESplitItem_to (S1 ! n))) (length (ESplitItem_to (S1 ! n)) + length (ESplitItem_ignore (S1 ! n)) - length (restrict_toberemoved S1 ! Suc n))\"\n    and s=\"(length (ESplitItem_to (S1 ! n)) + length (ESplitItem_ignore (S1 ! n)) - length (restrict_toberemoved S1 ! Suc n))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule Orderings.min_absorb2)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule Orderings.min_absorb1)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(rule_tac\n    t=\"drop_and_crop (ESplitItem_to (S2 ! n) @ ESplitItem_ignore (S2 ! n)) (length (restrict_toberemoved S2 ! Suc n))\"\n    and s=\" drop_and_crop (butn (ESplitItem_to (S2 ! n)) ((length (restrict_toberemoved S2 ! Suc n))-length(ESplitItem_ignore (S2 ! n))) ) 0\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(simp add: drop_and_crop_def butn_def)\n  apply(rule_tac\n    t=\"min (min (length (ESplitItem_to (S2 ! n))) (length (ESplitItem_to (S2 ! n)) + length (ESplitItem_ignore (S2 ! n)) - length (restrict_toberemoved S2 ! Suc n))) (length (ESplitItem_to (S2 ! n)) + length (ESplitItem_ignore (S2 ! n)) - length (restrict_toberemoved S2 ! Suc n))\"\n    and s=\"length (ESplitItem_to (S2 ! n)) + length (ESplitItem_ignore (S2 ! n)) - length (restrict_toberemoved S2 ! Suc n)\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    t=\"min (length (ESplitItem_to (S2 ! n))) (length (ESplitItem_to (S2 ! n)) + length (ESplitItem_ignore (S2 ! n)) - length (restrict_toberemoved S2 ! Suc n))\"\n    and s=\"length (ESplitItem_to (S2 ! n)) + length (ESplitItem_ignore (S2 ! n)) - length (restrict_toberemoved S2 ! Suc n)\"\n    in ssubst)\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    i=\"Suc n\"\n    and ?S1.0=\"S1\"\n    and n=\"length v\"\n    and v=\"v\"\n    and b=\"b\"\n    in e_derivation_can_be_embedded_minimally)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    prefer 2\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                   apply(force)\n                  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                  apply(force)\n                 apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                 apply(force)\n                apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                apply(force)\n               apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n               apply(force)\n              apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n              apply(force)\n             apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n             apply(force)\n            apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n            apply(force)\n           apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n           apply(force)\n          apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n          apply(force)\n         apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n         apply(force)\n        apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n        apply(force)\n       apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n       apply(force)\n      apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    i=\"Suc n\"\n    and ?S1.0=\"S2\"\n    and n=\"length v\"\n    and v=\"v\"\n    and b=\"b\"\n    in e_derivation_can_be_embedded_minimally)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    prefer 2\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                    apply(force)\n                   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                   apply(force)\n                  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                  apply(force)\n                 apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                 apply(force)\n                apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n                apply(force)\n               apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n               apply(force)\n              apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n              apply(force)\n             apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n             apply(force)\n            apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n            apply(force)\n           apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n           apply(force)\n          apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n          apply(force)\n         apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n         apply(force)\n        apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n        apply(force)\n       apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n       apply(force)\n      apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n  apply(thin_tac \"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc n) \\<noteq> [] \\<longrightarrow> (\\<exists>e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2. ESplitItem_prods ((S2 @ S2') ! Suc n) @ \\<pi>s ! Suc n @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S2 @ S2') ! x)) @ ESplitItem_prods ((S2 @ S2') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc n)) (length v))) = e_\\<pi>1 @ e_\\<pi>2 \\<and> (\\<exists>\\<alpha>1 \\<alpha>2. foldl (@) [] (drop (Suc n) (take (length v) fw)) = \\<alpha>1 @ \\<alpha>2 \\<and> cfgLM.trans_der G e_d1 \\<lparr>cfg_conf = liftA (option_to_list (ESplitItem_from ((S2 @ S2') ! Suc n)) @ butlast (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc n)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc n))) (ESplitItem_ignore ((S2 @ S2') ! Suc n))))))\\<rparr> e_\\<pi>1 \\<lparr>cfg_conf = liftB \\<alpha>1\\<rparr> \\<and> cfgLM.trans_der G e_d2 \\<lparr>cfg_conf = [teA (last (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc n)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc n))) (ESplitItem_ignore ((S2 @ S2') ! Suc n))))))]\\<rparr> e_\\<pi>2 \\<lparr>cfg_conf = liftB \\<alpha>2 @ teB b # va\\<rparr>))\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n  apply(thin_tac \"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc n) = [] \\<longrightarrow> (\\<exists>e_d va. cfgLM.trans_der G e_d \\<lparr>cfg_conf = liftA (option_to_list (ESplitItem_from ((S2 @ S2') ! Suc n)))\\<rparr> (ESplitItem_prods ((S2 @ S2') ! Suc n) @ \\<pi>s ! Suc n @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S2 @ S2') ! x)) @ ESplitItem_prods ((S2 @ S2') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc n)) (length v)))) \\<lparr>cfg_conf = liftB (foldl (@) [] (drop (Suc n) (take (length v) fw))) @ teB b # va\\<rparr>)\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n  apply(thin_tac \"PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc n) = [] \\<longrightarrow> (\\<exists>e_d va. cfgLM.trans_der G e_d \\<lparr>cfg_conf = liftA (option_to_list (ESplitItem_from ((S1 @ S1') ! Suc n)))\\<rparr> (ESplitItem_prods ((S1 @ S1') ! Suc n) @ \\<pi>s ! Suc n @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S1 @ S1') ! x)) @ ESplitItem_prods ((S1 @ S1') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc n)) (length v)))) \\<lparr>cfg_conf = liftB (foldl (@) [] (drop (Suc n) (take (length v) fw))) @ teB b # va\\<rparr>)\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n  apply(thin_tac \"PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc n) \\<noteq> [] \\<longrightarrow> (\\<exists>e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2. ESplitItem_prods ((S1 @ S1') ! Suc n) @ \\<pi>s ! Suc n @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S1 @ S1') ! x)) @ ESplitItem_prods ((S1 @ S1') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc n)) (length v))) = e_\\<pi>1 @ e_\\<pi>2 \\<and> (\\<exists>\\<alpha>1 \\<alpha>2. foldl (@) [] (drop (Suc n) (take (length v) fw)) = \\<alpha>1 @ \\<alpha>2 \\<and> cfgLM.trans_der G e_d1 \\<lparr>cfg_conf = liftA (option_to_list (ESplitItem_from ((S1 @ S1') ! Suc n)) @ butlast (fillOptL (PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc n)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc n))) (ESplitItem_ignore ((S1 @ S1') ! Suc n))))))\\<rparr> e_\\<pi>1 \\<lparr>cfg_conf = liftB \\<alpha>1\\<rparr> \\<and> cfgLM.trans_der G e_d2 \\<lparr>cfg_conf = [teA (last (fillOptL (PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc n)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc n))) (ESplitItem_ignore ((S1 @ S1') ! Suc n))))))]\\<rparr> e_\\<pi>2 \\<lparr>cfg_conf = liftB \\<alpha>2 @ teB b # va\\<rparr>))\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n  apply(simp add: fillWithPreContext_def)\n  apply(subgoal_tac \"\\<exists>Y1. ESplitItem_from (S1 ! Suc n)= Some Y1\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"(\\<forall>x\\<in> set (butlast (S1 @ S1')). (\\<exists>y. ESplitItem_from x = Some y) \\<and> (\\<exists>y. ESplitItem_elem x = Some y))\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n  prefer 2\n  apply(simp add: EValidSplit_def EValidSplit_producing_def)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n  apply(erule_tac\n    x=\"S1!Suc n\"\n    in ballE)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"S1 ! Suc n \\<in> set (butlast (S1 @ S1'))\")\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n  apply(thin_tac \"S1 ! Suc n \\<notin> set (butlast (S1 @ S1'))\")\n  apply(rule nth_in_butlast_append)\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n    S=\"S1\"\n    and S'=\"[]\"\n    in EValidSplit_continuation_not_empty)\n        apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n        apply(force)\n       apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n       apply(force)\n      apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n  prefer 2\n  apply(rule_tac\n    n=\"n\"\n    and X=\"Y1\"\n    and S=\"S1\"\n    and S'=\"S1'\"\n    and d=\"p_d\"\n    and v=\"v\"\n    and b=\"b\"\n    and \\<pi>=\"ESplitItem_prods ((S1 @ S1') ! Suc n) @ \\<pi>s ! Suc n @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S1 @ S1') ! x)) @ ESplitItem_prods ((S1 @ S1') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc n)) (length v)))\"\n    and tn=\"fillOptL (PSplitItem_to (restrict G' G (S1 @ S1') (Suc (length v)) ! length v)) (last_back_state_if_l3_nonterminal (take (Suc 0) (ESplitItem_to ((S1 @ S1') ! length v)))) @ tl (ESplitItem_to ((S1 @ S1') ! length v)) @ butn (restrict_toberemoved S1 ! length v) (length (restrict_toberemoved S1 ! Suc n))\"\n    in equal_split_prefix_hlp5_construct_relevant_cfgLMMIP)\n           apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n           apply(force)\n          apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n          apply(force)\n         apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n         apply(force)\n        apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n        apply(force)\n       apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n       apply(force)\n      apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n  apply(thin_tac \"cfgLMMIP G p_da (teA (fillOpt (PSplitItem_from (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc n)) (last_back_state_if_l3_nonterminal (option_to_list (ESplitItem_from ((S2 @ S2') ! Suc n))))) # liftA (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc n)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc n))) (ESplitItem_ignore ((S2 @ S2') ! Suc n)))))) (ESplitItem_prods ((S2 @ S2') ! Suc n) @ \\<pi>s ! Suc n @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S2 @ S2') ! x)) @ ESplitItem_prods ((S2 @ S2') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc n)) (length v)))) (liftB (foldl (@) [] (drop (Suc n) (take (length v) fw)) @ [b])) (liftA (fillOptL (PSplitItem_to (restrict G' G (S2 @ S2') (Suc (length v)) ! length v)) (last_back_state_if_l3_nonterminal (take (Suc 0) (ESplitItem_to ((S2 @ S2') ! length v)))) @ tl (ESplitItem_to ((S2 @ S2') ! length v)) @ butn (restrict_toberemoved S2 ! length v) (length (restrict_toberemoved S2 ! Suc n))))\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n  apply(rule_tac\n    t=\"teA Y1 # liftA (take (length (restrict_newignore S1 (Suc n))) (ESplitItem_ignore (S1 ! Suc n)))\"\n    and s=\"(teA (fillOpt (PSplitItem_from (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc n)) (last_back_state_if_l3_nonterminal (option_to_list (ESplitItem_from ((S1 @ S1') ! Suc n))))) # liftA (fillOptL (PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc n)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc n))) (ESplitItem_ignore ((S1 @ S1') ! Suc n))))))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n  prefer 2\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d Y1)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"nat_seq 0 (length v) ! Suc n = SSX\" for SSX)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d Y1)(*strict*)\n  prefer 2\n  apply(rule nat_seq_nth_compute)\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d Y1)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d Y1)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d Y1)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n    t=\"(S1 @ S1') ! Suc n\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d Y1)(*strict*)\n  apply(rule nth_append_1)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d Y1)(*strict*)\n  apply(clarsimp)\n  apply(simp add: option_to_list_def)\n  apply(rule conjI)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d Y1)(*strict*)\n  apply(rule fillOpt_single_with_last_back_state_if_l3_nonterminal)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d Y1)(*strict*)\n  apply(rule_tac\n    f=\"liftA\"\n    in arg_cong)\n  apply(simp (no_asm) add: restrict_newignore_def new_post_sig_def)\n  apply(rule_tac\n    t=\"length (drop_and_crop (ESplitItem_to (S1 ! Suc n) @ ESplitItem_ignore (S1 ! Suc n)) (length (restrict_toberemovedX S1 ! Suc (Suc n))))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d Y1)(*strict*)\n  apply(rule drop_and_crop_length)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d Y1)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n    t=\"drop (length (ESplitItem_to (S1 ! Suc n))) (drop_and_crop (ESplitItem_to (S1 ! Suc n) @ ESplitItem_ignore (S1 ! Suc n)) (length (restrict_toberemovedX S1 ! Suc (Suc n))))\"\n    and s=\" (drop_and_crop (ESplitItem_ignore (S1 ! Suc n)) (length (restrict_toberemovedX S1 ! Suc (Suc n))))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d Y1)(*strict*)\n  apply(rule cropTol3l2_drop_butn_drop_and_crop)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d Y1)(*strict*)\n  apply(simp add: drop_and_crop_def butn_def)\n  apply(rule fillOptL_with_last_back_state_if_l3_nonterminal_X)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n  apply(thin_tac \"cfgLMMIP G p_d (teA (fillOpt (PSplitItem_from (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc n)) (last_back_state_if_l3_nonterminal (option_to_list (ESplitItem_from ((S1 @ S1') ! Suc n))))) # liftA (fillOptL (PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc n)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc n))) (ESplitItem_ignore ((S1 @ S1') ! Suc n)))))) (ESplitItem_prods ((S1 @ S1') ! Suc n) @ \\<pi>s ! Suc n @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S1 @ S1') ! x)) @ ESplitItem_prods ((S1 @ S1') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc n)) (length v)))) (liftB (foldl (@) [] (drop (Suc n) (take (length v) fw)) @ [b])) (liftA (fillOptL (PSplitItem_to (restrict G' G (S1 @ S1') (Suc (length v)) ! length v)) (last_back_state_if_l3_nonterminal (take (Suc 0) (ESplitItem_to ((S1 @ S1') ! length v)))) @ tl (ESplitItem_to ((S1 @ S1') ! length v)) @ butn (restrict_toberemoved S1 ! length v) (length (restrict_toberemoved S1 ! Suc n))))\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n  apply(subgoal_tac \"\\<exists>Y2. ESplitItem_from (S2 ! Suc n)= Some Y2\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"(\\<forall>x\\<in> set (butlast (S2 @ S2')). (\\<exists>y. ESplitItem_from x = Some y) \\<and> (\\<exists>y. ESplitItem_elem x = Some y))\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n  prefer 2\n  apply(simp add: EValidSplit_def EValidSplit_producing_def)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n  apply(erule_tac\n    x=\"S2!Suc n\"\n    in ballE)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"S2 ! Suc n \\<in> set (butlast (S2 @ S2'))\")\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n  apply(thin_tac \"S2 ! Suc n \\<notin> set (butlast (S2 @ S2'))\")\n  apply(rule nth_in_butlast_append)\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d \\<pi>)(*strict*)\n  apply(rule_tac\n    S=\"S2\"\n    and S'=\"[]\"\n    in EValidSplit_continuation_not_empty)\n        apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d \\<pi>)(*strict*)\n        apply(force)\n       apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d \\<pi>)(*strict*)\n       apply(force)\n      apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d \\<pi>)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d \\<pi>)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d \\<pi>)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d \\<pi>)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d \\<pi>)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(rule_tac\n    t=\"map (case_DT_two_elements teA (\\<lambda>p. teA (prod_to_edge G' p))) (restrict_newprodsX G' G (ESplitItem_prods (S1 ! n)) (Some (Esplit_signature S1 ! n)) (drop_and_crop (butn (ESplitItem_to (S1 ! n)) (length (restrict_toberemoved S1 ! Suc n) - length (ESplitItem_ignore (S1 ! n)))) 0))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(rule equal_split_prefix_hlp1_triv_eq)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(rule_tac\n    t=\"map (case_DT_two_elements teA (\\<lambda>p. teA (prod_to_edge G' p))) (restrict_newprodsX G' G (ESplitItem_prods (S2 ! n)) (Some (Esplit_signature S1 ! n)) (drop_and_crop (butn (ESplitItem_to (S2 ! n)) (length (restrict_toberemoved S2 ! Suc n) - length (ESplitItem_ignore (S2 ! n)))) 0))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(rule equal_split_prefix_hlp1_triv_eq)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n  prefer 2\n  apply(rule_tac\n    n=\"n\"\n    and X=\"Y2\"\n    and S=\"S2\"\n    and S'=\"S2'\"\n    and d=\"p_da\"\n    and v=\"v\"\n    and b=\"b\"\n    and \\<pi>=\"ESplitItem_prods ((S2 @ S2') ! Suc n) @ \\<pi>s ! Suc n @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S2 @ S2') ! x)) @ ESplitItem_prods ((S2 @ S2') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc n)) (length v)))\"\n    and tn=\"fillOptL (PSplitItem_to (restrict G' G (S2 @ S2') (Suc (length v)) ! length v)) (last_back_state_if_l3_nonterminal (take (Suc 0) (ESplitItem_to ((S2 @ S2') ! length v)))) @ tl (ESplitItem_to ((S2 @ S2') ! length v)) @ butn (restrict_toberemoved S2 ! length v) (length (restrict_toberemoved S2 ! Suc n))\"\n    in equal_split_prefix_hlp5_construct_relevant_cfgLMMIP)\n           apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n           apply(force)\n          apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n          apply(force)\n         apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n         apply(force)\n        apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n        apply(force)\n       apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n       apply(force)\n      apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(rule_tac\n    t=\"teA Y2 # liftA (take (length (restrict_newignore S2 (Suc n))) (ESplitItem_ignore (S2 ! Suc n)))\"\n    and s=\"(teA (fillOpt (PSplitItem_from (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc n)) (last_back_state_if_l3_nonterminal (option_to_list (ESplitItem_from ((S2 @ S2') ! Suc n))))) # liftA (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc n)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc n))) (ESplitItem_ignore ((S2 @ S2') ! Suc n))))))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n  prefer 2\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"nat_seq 0 (length v) ! Suc n = SSX\" for SSX)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d Y2 \\<pi>)(*strict*)\n  prefer 2\n  apply(rule nat_seq_nth_compute)\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d Y2 \\<pi>)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n    t=\"(S2 @ S2') ! Suc n\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(rule nth_append_1)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(clarsimp)\n  apply(simp add: option_to_list_def)\n  apply(rule conjI)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(rule fillOpt_single_with_last_back_state_if_l3_nonterminal)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(rule_tac\n    f=\"liftA\"\n    in arg_cong)\n  apply(simp (no_asm) add: restrict_newignore_def new_post_sig_def)\n  apply(rule_tac\n    t=\"length (drop_and_crop (ESplitItem_to (S2 ! Suc n) @ ESplitItem_ignore (S2 ! Suc n)) (length (restrict_toberemovedX S2 ! Suc (Suc n))))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(rule drop_and_crop_length)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n    t=\"drop (length (ESplitItem_to (S2 ! Suc n))) (drop_and_crop (ESplitItem_to (S2 ! Suc n) @ ESplitItem_ignore (S2 ! Suc n)) (length (restrict_toberemovedX S2 ! Suc (Suc n))))\"\n    and s=\" (drop_and_crop (ESplitItem_ignore (S2 ! Suc n)) (length (restrict_toberemovedX S2 ! Suc (Suc n))))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(rule cropTol3l2_drop_butn_drop_and_crop)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(simp add: drop_and_crop_def butn_def)\n  apply(rule fillOptL_with_last_back_state_if_l3_nonterminal_X)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(thin_tac \"cfgLMMIP G p_da (teA (fillOpt (PSplitItem_from (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc n)) (last_back_state_if_l3_nonterminal (option_to_list (ESplitItem_from ((S2 @ S2') ! Suc n))))) # liftA (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc n)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc n))) (ESplitItem_ignore ((S2 @ S2') ! Suc n)))))) (ESplitItem_prods ((S2 @ S2') ! Suc n) @ \\<pi>s ! Suc n @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S2 @ S2') ! x)) @ ESplitItem_prods ((S2 @ S2') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc n)) (length v)))) (liftB (foldl (@) [] (drop (Suc n) (take (length v) fw)) @ [b])) (liftA (fillOptL (PSplitItem_to (restrict G' G (S2 @ S2') (Suc (length v)) ! length v)) (last_back_state_if_l3_nonterminal (take (Suc 0) (ESplitItem_to ((S2 @ S2') ! length v)))) @ tl (ESplitItem_to ((S2 @ S2') ! length v)) @ butn (restrict_toberemoved S2 ! length v) (length (restrict_toberemoved S2 ! Suc n))))\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi>)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d Y2 \\<pi> da \\<pi>')(*strict*)\n  apply(rename_tac Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)(*strict*)\n  apply(rule_tac\n    t=\"liftA (map (prod_to_edge G') (ESplitItem_prods (S1 ! n))) = liftA (map (prod_to_edge G') (ESplitItem_prods (S2 ! n)))\"\n    in ssubst)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)(*strict*)\n  apply(rule liftA_inj_equality)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)(*strict*)\n  apply(rule_tac\n    ?d1.0=\"d1x\"\n    and ?d2.0=\"d2x\"\n    and de=\"ds!n\"\n    and \\<alpha>e=\"fw!n\"\n    in equal_split_prefix_hlp2_withMIP_simplified)\n            apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)(*strict*)\n            apply(force)\n           apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)(*strict*)\n           apply(force)\n          apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)(*strict*)\n          apply(simp add: option_to_list_def)\n         apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)(*strict*)\n         apply(simp add: option_to_list_def)\n        apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)(*strict*)\n        apply(simp add: cfgLMTDL_def cfgLM.trans_der_list_def)\n        apply(clarsimp)\n        apply(erule_tac\n    x=\"n\"\n    in allE)\n        apply(clarsimp)\n        apply(force)\n       apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)(*strict*)\n       apply(force)\n      apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)(*strict*)\n     apply(case_tac \"Esplit_signature S1 ! n\")\n      apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y a)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y ba)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y ba)(*strict*)\n     apply(rule conjI)\n      apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y ba)(*strict*)\n      apply(rule lastProduces_intro)\n        apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y ba)(*strict*)\n        apply(simp add: split_TSstructure_def)\n        apply(force)\n       apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y ba)(*strict*)\n       apply(force)\n      apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y ba)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y ba)(*strict*)\n     apply(rule lastProduces_intro)\n       apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y ba)(*strict*)\n       apply(simp add: split_TSstructure_def)\n       apply(force)\n      apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y ba)(*strict*)\n      apply(force)\n     apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y ba)(*strict*)\n     apply(force)\n    apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)(*strict*)\n    apply(force)\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)(*strict*)\n   apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)(*strict*)\n  apply(case_tac \\<pi>1y)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)(*strict*)\n  prefer 2\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y a list)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 d2y \\<pi>2y)(*strict*)\n  apply(simp add: cfgLMMIP_def cfgLM.trans_der_def)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 d2y \\<pi>2y e ea ec)(*strict*)\n  apply(case_tac \"foldl (@) [] (drop (Suc n) (take (length v) fw))\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 d2y \\<pi>2y e ea ec)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"butn (ESplitItem_to (S1 ! n)) (length (restrict_toberemoved S1 ! Suc n) - length (ESplitItem_ignore (S1 ! n)))\")\n   apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 d2y \\<pi>2y e ea ec)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 d2y \\<pi>2y e ea ec a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 d2y \\<pi>2y e ea ec a list)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"butn (ESplitItem_to (S1 ! n)) (length (restrict_toberemoved S1 ! Suc n) - length (ESplitItem_ignore (S1 ! n)))\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 d2y \\<pi>2y e ea ec a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 d2y \\<pi>2y e ea ec a list aa lista)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)(*strict*)\n  apply(case_tac \\<pi>2y)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)(*strict*)\n  prefer 2\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y a list)(*strict*)\n  apply(force)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 p_d p_da Y1 d1y Y2 \\<pi>1y d2y \\<pi>2y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 \\<pi>1y d2y)(*strict*)\n  apply(simp add: cfgLMMIP_def cfgLM.trans_der_def)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 \\<pi>1y d2y e ea eb)(*strict*)\n  apply(case_tac \"foldl (@) [] (drop (Suc n) (take (length v) fw))\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 \\<pi>1y d2y e ea eb)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"butn (ESplitItem_to (S2 ! n)) (length (restrict_toberemoved S2 ! Suc n) - length (ESplitItem_ignore (S2 ! n)))\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 \\<pi>1y d2y e ea eb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 \\<pi>1y d2y e ea eb a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 \\<pi>1y d2y e ea eb a list)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"butn (ESplitItem_to (S2 ! n)) (length (restrict_toberemoved S2 ! Suc n) - length (ESplitItem_ignore (S2 ! n)))\")\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 \\<pi>1y d2y e ea eb a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n ds \\<pi>s fw d2x d1x X1 X2 Y1 d1y Y2 \\<pi>1y d2y e ea eb a list aa lista)(*strict*)\n  apply(clarsimp)\n  done\n\ntheorem equal_split_prefix_updated: \"\n  F2LR1inputx G G'\n  \\<Longrightarrow> split_TSstructure G\n  \\<Longrightarrow> cfgRM.derivation_initial G d1\n  \\<Longrightarrow> d1 n1 = Some (pair e1 \\<lparr>cfg_conf=v@[teB b]@x1\\<rparr>)\n  \\<Longrightarrow> cfgRM.derivation_initial G d2\n  \\<Longrightarrow> d2 n2 = Some (pair e2 \\<lparr>cfg_conf=v@[teB b]@x2\\<rparr>)\n  \\<Longrightarrow> EValidSplit G (S1@S1')\n  \\<Longrightarrow> EValidSplit G (S2@S2')\n  \\<Longrightarrow> length S1 = length (v@[teB b])\n  \\<Longrightarrow> length S2 = length (v@[teB b])\n  \\<Longrightarrow> v@[teB b] = Esplit_signature S1\n  \\<Longrightarrow> v@[teB b] = Esplit_signature S2\n  \\<Longrightarrow> x1 = Esplit_signature S1'\n  \\<Longrightarrow> x2 = Esplit_signature S2'\n  \\<Longrightarrow> S1R=restrict G' G (S1@S1') (length (v@[teB b]))\n  \\<Longrightarrow> S2R=restrict G' G (S2@S2') (length (v@[teB b]))\n  \\<Longrightarrow> restrictX G' S1R = restrictX G' S2R\"\n  apply(subgoal_tac \"ESplitItem_elem ((S1 @ S1') ! length v) = Some (teB b)\")\n   prefer 2\n   apply(rule equal_split_prefix_hlp2)\n           apply(force)\n          apply(force)\n         apply(force)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"PValidSplit G' G S1R\")\n   prefer 2\n   apply(rule equal_split_prefix_hlp3)\n            apply(force)\n           apply(force)\n          apply(force)\n         apply(force)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"ESplitItem_elem ((S2 @ S2') ! length v) = Some (teB b)\")\n   prefer 2\n   apply(rule_tac\n      ?d1.0=\"d2\"\n      in equal_split_prefix_hlp2)\n           apply(force)\n          apply(force)\n         apply(force)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"PValidSplit G' G S2R\")\n   prefer 2\n   apply(rule_tac\n      ?S1.0=\"S2\"\n      and ?d1.0=\"d2\"\n      in equal_split_prefix_hlp3)\n            apply(force)\n           apply(force)\n          apply(force)\n         apply(force)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"take (length (v@[teB b])) (restrictX G' S1R) = take (length (v@[teB b])) (restrictX G' S2R)\")\n   prefer 2\n   apply(rule_tac\n      ?d1.0=\"d1\"\n      and ?d2.0=\"d2\"\n      and S1'=\"S1'\"\n      and S2'=\"S2'\"\n      and ?S1.0=\"S1\"\n      and ?S2.0=\"S2\"\n      in equal_split_prefix_hlp1_updated)\n                      apply(force)\n                      apply(force)\n                      apply(force)\n                      apply(force)\n                     apply(force)\n                    apply(force)\n                   apply(force)\n                  apply(force)\n                 apply(force)\n                apply(force)\n               apply(force)\n              apply(force)\n             apply(force)\n            apply(force)\n           apply(force)\n          apply(force)\n         apply(force)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(rule_tac\n      t=\"restrictX G' S1R\"\n      and s=\"take (length (v @ [teB b])) (restrictX G' S1R)\"\n      in ssubst)\n   apply(simp add: restrict_def restrict_len_def restrict_map_def restrictX_def)\n   apply(case_tac \"length (Esplit_signature S1)\")\n    apply(clarsimp)\n   apply(rename_tac nat)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"length(nat_seq 0 nat) = SSx\" for SSx)\n    apply(rename_tac nat)(*strict*)\n    prefer 2\n    apply(rule nat_seq_length_prime)\n   apply(rename_tac nat)(*strict*)\n   apply(force)\n  apply(rule_tac\n      t=\"restrictX G' S2R\"\n      and s=\"take (length (v @ [teB b])) (restrictX G' S2R)\"\n      in ssubst)\n   apply(simp add: restrict_def restrict_len_def restrict_map_def restrictX_def)\n   apply(case_tac \"length (Esplit_signature S1)\")\n    apply(clarsimp)\n   apply(rename_tac nat)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"length(nat_seq 0 nat) = SSx\" for SSx)\n    apply(rename_tac nat)(*strict*)\n    prefer 2\n    apply(rule nat_seq_length_prime)\n   apply(rename_tac nat)(*strict*)\n   apply(force)\n  apply(force)\n  done\n\nlemma equal_split_prefix_hlp1: \"\n  F2LR1inputx G G'\n  \\<Longrightarrow> split_TSstructure G\n  \\<Longrightarrow> cfgRM.derivation_initial G d1\n  \\<Longrightarrow> d1 n1 = Some (pair e1 \\<lparr>cfg_conf=v@[teB b]@x1\\<rparr>)\n  \\<Longrightarrow> cfgRM.derivation_initial G d2\n  \\<Longrightarrow> d2 n2 = Some (pair e2 \\<lparr>cfg_conf=v@[teB b]@x2\\<rparr>)\n  \\<Longrightarrow> EValidSplit G (S1@S1')\n  \\<Longrightarrow> EValidSplit G (S2@S2')\n  \\<Longrightarrow> length S1 = length (v@[teB b])\n  \\<Longrightarrow> length S2 = length (v@[teB b])\n  \\<Longrightarrow> v@[teB b] = Esplit_signature S1\n  \\<Longrightarrow> v@[teB b] = Esplit_signature S2\n  \\<Longrightarrow> x1 = Esplit_signature S1'\n  \\<Longrightarrow> x2 = Esplit_signature S2'\n  \\<Longrightarrow> S1' \\<noteq> []\n  \\<Longrightarrow> S2' \\<noteq> []\n  \\<Longrightarrow> S1R=restrict G' G (S1@S1') (length (v@[teB b]))\n  \\<Longrightarrow> S2R=restrict G' G (S2@S2') (length (v@[teB b]))\n  \\<Longrightarrow> ESplitItem_elem ((S1@S1') ! (length v)) = Some (teB b)\n  \\<Longrightarrow> PValidSplit G' G S1R\n  \\<Longrightarrow> ESplitItem_elem ((S2@S2') ! (length v)) = Some (teB b)\n  \\<Longrightarrow> PValidSplit G' G S2R\n  \\<Longrightarrow> i<length (v@[teB b])\n  \\<Longrightarrow> S1R!i = S2R!i\"\n  apply(subgoal_tac \"restrictX G' S1R = restrictX G' S2R\")\n   prefer 2\n   apply(rule_tac\n      S1R=\"S1R\"\n      and S2R=\"S2R\"\n      and ?d1.0=\"d1\"\n      and ?d2.0=\"d2\"\n      in equal_split_prefix_updated)\n                  apply(force)\n                 apply(force)\n                apply(force)\n               apply(force)\n              apply(force)\n             apply(force)\n            prefer 7\n            apply(force)\n           apply(force)\n          prefer 6\n          apply(force)\n         apply(force)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"restrictX G' [S1R!i] = restrictX G' [S2R!i]\")\n   prefer 2\n   apply(rule_tac\n      t=\"restrictX G' [S1R!i]\"\n      and s=\"[(restrictX G' S1R) !i]\"\n      in subst)\n    apply(simp (no_asm) add: restrictX_def)\n    apply(rule_tac\n      t=\"map (\\<lambda>I. I\\<lparr>PSplitItem_prods := map (case_DT_two_elements teA (\\<lambda>p. teA (prod_to_edge G' p))) (PSplitItem_prods I)\\<rparr>) S1R ! i\"\n      in ssubst)\n     apply(rule nth_map)\n     apply(clarsimp)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(clarsimp)\n     apply(subgoal_tac \"length (nat_seq 0 (length (Esplit_signature S1) - Suc 0)) = SSx\" for SSx)\n      prefer 2\n      apply(rule nat_seq_length_prime)\n     apply(clarsimp)\n     apply(case_tac \"Esplit_signature S1\")\n      apply(clarsimp)\n     apply(rename_tac a list)(*strict*)\n     apply(clarsimp)\n    apply(clarsimp)\n   apply(rule_tac\n      t=\"restrictX G' [S2R!i]\"\n      and s=\"[(restrictX G' S2R) !i]\"\n      in subst)\n    apply(simp (no_asm) add: restrictX_def)\n    apply(rule_tac\n      t=\"map (\\<lambda>I. I\\<lparr>PSplitItem_prods := map (case_DT_two_elements teA (\\<lambda>p. teA (prod_to_edge G' p))) (PSplitItem_prods I)\\<rparr>) S2R ! i\"\n      in ssubst)\n     apply(rule nth_map)\n     apply(clarsimp)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(clarsimp)\n     apply(subgoal_tac \"length (nat_seq 0 (length (Esplit_signature S2) - Suc 0)) = SSx\" for SSx)\n      prefer 2\n      apply(rule nat_seq_length_prime)\n     apply(clarsimp)\n     apply(case_tac \"Esplit_signature S1\")\n      apply(clarsimp)\n     apply(rename_tac a list)(*strict*)\n     apply(clarsimp)\n    apply(clarsimp)\n   apply(force)\n  apply(clarsimp)\n  apply(subgoal_tac \"PSplitItem_prods (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i) = PSplitItem_prods (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i)\")\n   apply(case_tac \"restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i\")\n   apply(rename_tac PSplitItem_elim PSplitItem_from PSplitItem_ignore PSplitItem_elim_prods PSplitItem_prodsa PSplitItem_elem PSplitItem_to)(*strict*)\n   apply(case_tac \"restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i\")\n   apply(rename_tac PSplitItem_elim PSplitItem_from PSplitItem_ignore PSplitItem_elim_prods PSplitItem_prodsa PSplitItem_elem PSplitItem_to PSplitItem_elima PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prodsa PSplitItem_prodsaa PSplitItem_elema PSplitItem_toa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac PSplitItem_elim PSplitItem_from PSplitItem_ignore PSplitItem_elim_prods PSplitItem_elem PSplitItem_to PSplitItem_elima PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prodsa PSplitItem_prodsa PSplitItem_elema PSplitItem_toa)(*strict*)\n   apply(simp add: restrictX_def)\n  apply(subgoal_tac \"PSplitItem_from (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i) = PSplitItem_from (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i)\")\n   prefer 2\n   apply(case_tac \"restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i\")\n   apply(rename_tac PSplitItem_elim PSplitItem_froma PSplitItem_ignore PSplitItem_elim_prods PSplitItem_prods PSplitItem_elem PSplitItem_to)(*strict*)\n   apply(case_tac \"restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i\")\n   apply(rename_tac PSplitItem_elim PSplitItem_froma PSplitItem_ignore PSplitItem_elim_prods PSplitItem_prods PSplitItem_elem PSplitItem_to PSplitItem_elima PSplitItem_fromaa PSplitItem_ignorea PSplitItem_elim_prodsa PSplitItem_prodsa PSplitItem_elema PSplitItem_toa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac PSplitItem_elim PSplitItem_from PSplitItem_ignore PSplitItem_elim_prods PSplitItem_prods PSplitItem_elem PSplitItem_to PSplitItem_elima PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prodsa PSplitItem_prodsa PSplitItem_elema PSplitItem_toa)(*strict*)\n   apply(simp add: restrictX_def)\n  apply(subgoal_tac \"PSplitItem_to (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i) = PSplitItem_to (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i)\")\n   prefer 2\n   apply(case_tac \"restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i\")\n   apply(rename_tac PSplitItem_elim PSplitItem_froma PSplitItem_ignore PSplitItem_elim_prods PSplitItem_prods PSplitItem_elem PSplitItem_toa)(*strict*)\n   apply(case_tac \"restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i\")\n   apply(rename_tac PSplitItem_elim PSplitItem_froma PSplitItem_ignore PSplitItem_elim_prods PSplitItem_prods PSplitItem_elem PSplitItem_toa PSplitItem_elima PSplitItem_fromaa PSplitItem_ignorea PSplitItem_elim_prodsa PSplitItem_prodsa PSplitItem_elema PSplitItem_toaa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac PSplitItem_elim PSplitItem_ignore PSplitItem_elim_prods PSplitItem_prods PSplitItem_elem PSplitItem_to PSplitItem_elima PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prodsa PSplitItem_prodsa PSplitItem_elema PSplitItem_toa)(*strict*)\n   apply(simp add: restrictX_def)\n  apply(subgoal_tac \"PSplitItem_ignore (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i) = PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i)\")\n   prefer 2\n   apply(case_tac \"restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i\")\n   apply(rename_tac PSplitItem_elim PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prods PSplitItem_prods PSplitItem_elem PSplitItem_toa)(*strict*)\n   apply(case_tac \"restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i\")\n   apply(rename_tac PSplitItem_elim PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prods PSplitItem_prods PSplitItem_elem PSplitItem_toa PSplitItem_elima PSplitItem_fromaa PSplitItem_ignoreaa PSplitItem_elim_prodsa PSplitItem_prodsa PSplitItem_elema PSplitItem_toaa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac PSplitItem_elim PSplitItem_ignore PSplitItem_elim_prods PSplitItem_prods PSplitItem_elem PSplitItem_elima PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prodsa PSplitItem_prodsa PSplitItem_elema PSplitItem_toa)(*strict*)\n   apply(simp add: restrictX_def)\n  apply(subgoal_tac \"PSplitItem_elim (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i) = PSplitItem_elim (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i)\")\n   prefer 2\n   apply(case_tac \"restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i\")\n   apply(rename_tac PSplitItem_elima PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prods PSplitItem_prods PSplitItem_elem PSplitItem_toa)(*strict*)\n   apply(case_tac \"restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i\")\n   apply(rename_tac PSplitItem_elima PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prods PSplitItem_prods PSplitItem_elem PSplitItem_toa PSplitItem_elimaa PSplitItem_fromaa PSplitItem_ignoreaa PSplitItem_elim_prodsa PSplitItem_prodsa PSplitItem_elema PSplitItem_toaa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac PSplitItem_elim PSplitItem_elim_prods PSplitItem_prods PSplitItem_elem PSplitItem_elima PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prodsa PSplitItem_prodsa PSplitItem_elema PSplitItem_toa)(*strict*)\n   apply(simp add: restrictX_def)\n  apply(subgoal_tac \"PSplitItem_elem (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i) = PSplitItem_elem (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i)\")\n   prefer 2\n   apply(case_tac \"restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i\")\n   apply(rename_tac PSplitItem_elima PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prods PSplitItem_prods PSplitItem_elema PSplitItem_toa)(*strict*)\n   apply(case_tac \"restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i\")\n   apply(rename_tac PSplitItem_elima PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prods PSplitItem_prods PSplitItem_elema PSplitItem_toa PSplitItem_elimaa PSplitItem_fromaa PSplitItem_ignoreaa PSplitItem_elim_prodsa PSplitItem_prodsa PSplitItem_elemaa PSplitItem_toaa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac PSplitItem_elim_prods PSplitItem_prods PSplitItem_elem PSplitItem_elima PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prodsa PSplitItem_prodsa PSplitItem_elema PSplitItem_toa)(*strict*)\n   apply(simp add: restrictX_def)\n  apply(subgoal_tac \"PSplitItem_elim_prods (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i) = PSplitItem_elim_prods (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i)\")\n   prefer 2\n   apply(case_tac \"restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i\")\n   apply(rename_tac PSplitItem_elima PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prodsa PSplitItem_prods PSplitItem_elema PSplitItem_toa)(*strict*)\n   apply(case_tac \"restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i\")\n   apply(rename_tac PSplitItem_elima PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prodsa PSplitItem_prods PSplitItem_elema PSplitItem_toa PSplitItem_elimaa PSplitItem_fromaa PSplitItem_ignoreaa PSplitItem_elim_prodsaa PSplitItem_prodsa PSplitItem_elemaa PSplitItem_toaa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac PSplitItem_elim_prods PSplitItem_prods PSplitItem_elima PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prodsa PSplitItem_prodsa PSplitItem_elema PSplitItem_toa)(*strict*)\n   apply(simp add: restrictX_def)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(subgoal_tac \"length (nat_seq 0 (length (Esplit_signature S1) - Suc 0)) = SSx\" for SSx)\n   prefer 2\n   apply(rule nat_seq_length_prime)\n  apply(clarsimp)\n  apply(subgoal_tac \"Suc (length (Esplit_signature S1) - Suc 0) = length (Esplit_signature S1)\")\n   prefer 2\n   apply(case_tac \"Esplit_signature S1\")\n    apply(clarsimp)\n   apply(rename_tac a list)(*strict*)\n   apply(clarsimp)\n  apply(clarsimp)\n  apply(subgoal_tac \"nat_seq 0 (length (Esplit_signature S1) - Suc 0) ! i = SSX\" for SSX)\n   prefer 2\n   apply(rule nat_seq_nth_compute)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(simp (no_asm) add: restrict_newprods_def)\n  apply(subgoal_tac \"\\<exists>ds \\<pi>s fw. cfgLMTDL G ds (Esplit_signature S1) \\<pi>s fw\")\n   prefer 2\n   apply(simp add: cfgLMTDL_def)\n   apply(subgoal_tac \"\\<exists>ds f\\<pi> fw. cfgLM.trans_der_list SSG ds (map (\\<lambda>w. \\<lparr>cfg_conf = [w]\\<rparr>) (Esplit_signature S1)) f\\<pi> (map (\\<lambda>w. \\<lparr>cfg_conf = w\\<rparr>) fw) \\<and> setA (foldl (@) [] fw) = {}\" for SSG)\n    prefer 2\n    apply(rule construct_elimininating_trans_der_list)\n       apply(simp add: split_TSstructure_def)\n       apply(force)\n      apply(simp add: split_TSstructure_def)\n     apply(rule Esplit_signature_belongs_setA)\n     apply(force)\n    apply(rule Esplit_signature_belongs_setB)\n    apply(force)\n   apply(clarsimp)\n   apply(rename_tac ds f\\<pi> fw)(*strict*)\n   apply(rule_tac\n      x=\"ds\"\n      in exI)\n   apply(rule_tac\n      x=\"f\\<pi>\"\n      in exI)\n   apply(rule_tac\n      x=\"map filterB fw\"\n      in exI)\n   apply(rule_tac\n      t=\"(map (\\<lambda>x. \\<lparr>cfg_conf = liftB x\\<rparr>) (map filterB fw))\"\n      and s=\"(map (\\<lambda>w. \\<lparr>cfg_conf = w\\<rparr>) fw)\"\n      in ssubst)\n    apply(rename_tac ds f\\<pi> fw)(*strict*)\n    apply(rule listEqI)\n     apply(rename_tac ds f\\<pi> fw)(*strict*)\n     apply(force)\n    apply(rename_tac ds f\\<pi> fw ia)(*strict*)\n    apply(clarsimp)\n    apply (metis setA_empty_foldl liftBDeConv2)\n   apply(rename_tac ds f\\<pi> fw)(*strict*)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(case_tac \"restrict_newignore S1 i = []\")\n   apply(rename_tac ds \\<pi>s fw)(*strict*)\n   prefer 2\n   apply(rename_tac ds \\<pi>s fw)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"restrict_newignore S2 i \\<noteq> []\")\n    apply(rename_tac ds \\<pi>s fw)(*strict*)\n    prefer 2\n    apply(rule_tac\n      t=\"restrict_newignore S2 i\"\n      and s=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i)\"\n      in ssubst)\n     apply(rename_tac ds \\<pi>s fw)(*strict*)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(clarsimp)\n    apply(rename_tac ds \\<pi>s fw)(*strict*)\n    apply(rule_tac\n      t=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i)\"\n      and s=\"PSplitItem_ignore (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i)\"\n      in subst)\n     apply(rename_tac ds \\<pi>s fw)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw)(*strict*)\n    apply(rule_tac\n      t=\"PSplitItem_ignore (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i)\"\n      and s=\"restrict_newignore S1 i\"\n      in ssubst)\n     apply(rename_tac ds \\<pi>s fw)(*strict*)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(clarsimp)\n    apply(rename_tac ds \\<pi>s fw)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw)(*strict*)\n   apply(clarsimp)\n   apply(rule_tac\n      t=\"liftB (ESplitItem_prods (S1 ! i)) = liftB (ESplitItem_prods (S2 ! i))\"\n      and s=\"(ESplitItem_prods (S1 ! i)) = (ESplitItem_prods (S2 ! i))\"\n      in ssubst)\n    apply(rename_tac ds \\<pi>s fw)(*strict*)\n    apply(rule order_antisym)\n     apply(rename_tac ds \\<pi>s fw)(*strict*)\n     apply(simp (no_asm))\n     apply(rule impI)\n     apply(rule liftB_inj)\n     apply(blast)\n    apply(rename_tac ds \\<pi>s fw)(*strict*)\n    apply(simp (no_asm))\n   apply(rename_tac ds \\<pi>s fw)(*strict*)\n   apply(subgoal_tac \"i \\<le> length v\")\n    apply(rename_tac ds \\<pi>s fw)(*strict*)\n    prefer 2\n    apply (metis Suc_length less_not_refl less_trans_Suc trivNat)\n   apply(rename_tac ds \\<pi>s fw)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac ds \\<pi>s fw)(*strict*)\n    prefer 2\n    apply(rule_tac\n      i=\"i\"\n      and ?S1.0=\"S1\"\n      and n=\"length v\"\n      and v=\"v\"\n      and b=\"b\"\n      in e_derivation_can_be_embedded_minimally)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      prefer 2\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                     apply(rename_tac ds \\<pi>s fw)(*strict*)\n                     apply(force)\n                    apply(rename_tac ds \\<pi>s fw)(*strict*)\n                    apply(force)\n                   apply(rename_tac ds \\<pi>s fw)(*strict*)\n                   apply(force)\n                  apply(rename_tac ds \\<pi>s fw)(*strict*)\n                  apply(force)\n                 apply(rename_tac ds \\<pi>s fw)(*strict*)\n                 apply(force)\n                apply(rename_tac ds \\<pi>s fw)(*strict*)\n                apply(force)\n               apply(rename_tac ds \\<pi>s fw)(*strict*)\n               apply(force)\n              apply(rename_tac ds \\<pi>s fw)(*strict*)\n              apply(force)\n             apply(rename_tac ds \\<pi>s fw)(*strict*)\n             apply(force)\n            apply(rename_tac ds \\<pi>s fw)(*strict*)\n            apply(force)\n           apply(rename_tac ds \\<pi>s fw)(*strict*)\n           apply(force)\n          apply(rename_tac ds \\<pi>s fw)(*strict*)\n          apply(force)\n         apply(rename_tac ds \\<pi>s fw)(*strict*)\n         apply(force)\n        apply(rename_tac ds \\<pi>s fw)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac ds \\<pi>s fw)(*strict*)\n    prefer 2\n    apply(rule_tac\n      i=\"i\"\n      and ?S1.0=\"S2\"\n      and n=\"length v\"\n      and v=\"v\"\n      and b=\"b\"\n      in e_derivation_can_be_embedded_minimally)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      prefer 2\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                      apply(rename_tac ds \\<pi>s fw)(*strict*)\n                      apply(force)\n                     apply(rename_tac ds \\<pi>s fw)(*strict*)\n                     apply(force)\n                    apply(rename_tac ds \\<pi>s fw)(*strict*)\n                    apply(force)\n                   apply(rename_tac ds \\<pi>s fw)(*strict*)\n                   apply(force)\n                  apply(rename_tac ds \\<pi>s fw)(*strict*)\n                  apply(force)\n                 apply(rename_tac ds \\<pi>s fw)(*strict*)\n                 apply(force)\n                apply(rename_tac ds \\<pi>s fw)(*strict*)\n                apply(force)\n               apply(rename_tac ds \\<pi>s fw)(*strict*)\n               apply(force)\n              apply(rename_tac ds \\<pi>s fw)(*strict*)\n              apply(force)\n             apply(rename_tac ds \\<pi>s fw)(*strict*)\n             apply(force)\n            apply(rename_tac ds \\<pi>s fw)(*strict*)\n            apply(force)\n           apply(rename_tac ds \\<pi>s fw)(*strict*)\n           apply(force)\n          apply(rename_tac ds \\<pi>s fw)(*strict*)\n          apply(force)\n         apply(rename_tac ds \\<pi>s fw)(*strict*)\n         apply(force)\n        apply(rename_tac ds \\<pi>s fw)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n   apply(thin_tac \"PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! i) = [] \\<longrightarrow> (\\<exists>e_d va. cfgLM.trans_der G e_d \\<lparr>cfg_conf = liftA (option_to_list (ESplitItem_from ((S1 @ S1') ! i)))\\<rparr> (ESplitItem_prods ((S1 @ S1') ! i) @ \\<pi>s ! i @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S1 @ S1') ! x)) @ ESplitItem_prods ((S1 @ S1') ! x) @ \\<pi>s ! x) (nat_seq (Suc i) (length v)))) \\<lparr>cfg_conf = liftB (foldl (@) [] (drop i (take (length v) fw))) @ teB b # va\\<rparr>)\")\n   apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n   apply(thin_tac \"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! i) = [] \\<longrightarrow> (\\<exists>e_d va. cfgLM.trans_der G e_d \\<lparr>cfg_conf = liftA (option_to_list (ESplitItem_from ((S2 @ S2') ! i)))\\<rparr> (ESplitItem_prods ((S2 @ S2') ! i) @ \\<pi>s ! i @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S2 @ S2') ! x)) @ ESplitItem_prods ((S2 @ S2') ! x) @ \\<pi>s ! x) (nat_seq (Suc i) (length v)))) \\<lparr>cfg_conf = liftB (foldl (@) [] (drop i (take (length v) fw))) @ teB b # va\\<rparr>)\")\n   apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n   apply(subgoal_tac \"length (nat_seq 0 (length v)) = SSx\" for SSx)\n    apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n    prefer 2\n    apply(rule nat_seq_length_prime)\n   apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n   apply(subgoal_tac \"take (Suc (length v)) S1 = S1\")\n    apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n    prefer 2\n    apply(rule take_all)\n    apply (metis Esplit_signature_length_max Suc_length)\n   apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n   apply(subgoal_tac \"take (Suc (length v)) S2 = S2\")\n    apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n    prefer 2\n    apply(rule take_all)\n    apply (metis Esplit_signature_length_max Suc_length)\n   apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n   apply(subgoal_tac \"nat_seq 0 (length v) ! i = SSX\" for SSX)\n    apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n    prefer 2\n    apply(rule nat_seq_nth_compute)\n     apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n   apply(erule_tac\n      P=\"PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! i) \\<noteq> []\"\n      in impE)\n    apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(rule_tac\n      t=\"length S1\"\n      and s=\"Suc(length v)\"\n      in ssubst)\n     apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n     apply (metis Suc_length)\n    apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n    apply(rule_tac\n      t=\"min (length S1') (Suc (length v) - Suc (length v))\"\n      and s=\"0\"\n      in ssubst)\n     apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n    apply(rule_tac\n      t=\"min (Suc (length v)) (Suc (length v)) + 0 - Suc 0\"\n      and s=\"length v\"\n      in ssubst)\n     apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n   apply(erule impE)\n    apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(rule_tac\n      t=\"length S2\"\n      and s=\"Suc(length v)\"\n      in ssubst)\n     apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n     apply (metis Suc_length)\n    apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n    apply(rule_tac\n      t=\"min (length S2') (Suc (length v) - Suc (length v))\"\n      and s=\"0\"\n      in ssubst)\n     apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n    apply(rule_tac\n      t=\"min (Suc (length v)) (Suc (length v)) + 0 - Suc 0\"\n      and s=\"length v\"\n      in ssubst)\n     apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw p_d p_da)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n   apply(subgoal_tac \"Suc i\\<le>length v\")\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    prefer 2\n    apply(case_tac \"i=length v\")\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(subgoal_tac \"False\")\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     prefer 2\n     apply(rule_tac\n      n=\"length v\"\n      and S=\"S2\"\n      in restrict_newignore_last_empty)\n       apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n      apply (metis length_Suc)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(rule ESplitItem_to_not_empty_on_generating_line)\n         apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n         apply(force)\n        apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n   apply(subgoal_tac \"PSplitItem_to (restrict G' G (S2 @ S2') (Suc (length v)) ! i) = ESplitItem_to ((S2 @ S2') ! i)\")\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    prefer 2\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"length (Esplit_signature S1)\"\n      and s=\"Suc(length v)\"\n      in ssubst)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply (metis Suc_length)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"(S2 @ S2') ! i\"\n      and s=\"S2!i\"\n      in ssubst)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(rule nth_append_1)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(rule nonemtpy_newignore_implies_newto_unchanged)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n   apply(subgoal_tac \"PSplitItem_to (restrict G' G (S1 @ S1') (Suc (length v)) ! i) = ESplitItem_to ((S1 @ S1') ! i)\")\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    prefer 2\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"length (Esplit_signature S1)\"\n      and s=\"Suc(length v)\"\n      in ssubst)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply (metis Suc_length)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"(S1 @ S1') ! i\"\n      and s=\"S1!i\"\n      in ssubst)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(rule nth_append_1)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(rule_tac\n      t=\"take (Suc (length v)) S1\"\n      and s=\"S1\"\n      in ssubst)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(rule take_all)\n     apply (metis Suc_length nat_neq_iff trivNat)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(rule nonemtpy_newignore_implies_newto_unchanged)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n   apply(subgoal_tac \"Suc i < length S1\")\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    prefer 2\n    apply (metis Suc_n_not_n drop_length_append le_antisym le_trans length_append_empty1 list.simps(2) nat.inject trivNat)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n   apply(subgoal_tac \"Suc i < length S2\")\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    prefer 2\n    apply (metis Suc_n_not_n drop_length_append le_antisym le_trans length_append_empty1 list.simps(2) nat.inject trivNat)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n   apply(case_tac \"ESplitItem_from (S1 ! i)\")\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(simp add: EValidSplit_def EValidSplit_producing_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"S1!i\"\n      and A=\"set (butlast (S1 @ S1'))\"\n      in ballE)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     prefer 2\n     apply(rule in_set_butlast_append2)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a)(*strict*)\n   apply(case_tac \"ESplitItem_from (S2 ! i)\")\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a)(*strict*)\n    apply(simp add: EValidSplit_def EValidSplit_producing_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"S2!i\"\n      and A=\"set (butlast (S2 @ S2'))\"\n      in ballE)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a)(*strict*)\n     prefer 2\n     apply(rule in_set_butlast_append2)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a a aa)(*strict*)\n   apply(rename_tac F1 F2)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2)(*strict*)\n   apply(case_tac \"F1\")\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q ba)(*strict*)\n    apply(rename_tac qF1 AF1)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 qF1 AF1)(*strict*)\n    apply(subgoal_tac \"False\")\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 qF1 AF1)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 qF1 AF1)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n    apply(subgoal_tac \"ESplitItem_ignore (S1 ! i) = []\")\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n     prefer 2\n     apply(subgoal_tac \"proper_l3_l2_seq (ESplitItem_elim (S1 ! i) @ option_to_list (Some (cons_l2 qF1 AF1)) @ ESplitItem_ignore (S1 ! i))\")\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n      prefer 2\n      apply(subgoal_tac \"EValidSplitItem_belongs G (S1 ! i)\")\n       apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n       prefer 2\n       apply(simp add: EValidSplit_def EValidSplit_ValidItem_def EValidSplitItem_def)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n      apply(simp add: EValidSplitItem_belongs_def)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n     apply(simp (no_asm_use) add: option_to_list_def)\n     apply(rule l2_in_proper_l3_l2_seq_at_end)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n    apply(subgoal_tac \"restrict_newignore S1 i = []\")\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n    apply(simp (no_asm) add: restrict_newignore_def new_post_sig_def)\n    apply(rule_tac\n      t=\"length (drop_and_crop (ESplitItem_to (S1 ! i) @ ESplitItem_ignore (S1 ! i)) (length (restrict_toberemovedX S1 ! Suc i)))\"\n      in ssubst)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n     apply(rule drop_and_crop_length)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F2 qF1 AF1)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q1 ba q2)(*strict*)\n   apply(case_tac \"F2\")\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q1 ba q2 q baa)(*strict*)\n    apply(rename_tac qF2 AF2)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q1 ba q2 qF2 AF2)(*strict*)\n    apply(subgoal_tac \"False\")\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q1 ba q2 qF2 AF2)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q1 ba q2 qF2 AF2)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n    apply(subgoal_tac \"ESplitItem_ignore (S2 ! i) = []\")\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n     prefer 2\n     apply(subgoal_tac \"proper_l3_l2_seq (ESplitItem_elim (S2 ! i) @ option_to_list (Some (cons_l2 qF2 AF2)) @ ESplitItem_ignore (S2 ! i))\")\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n      prefer 2\n      apply(subgoal_tac \"EValidSplitItem_belongs G (S2 ! i)\")\n       apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n       prefer 2\n       apply(simp add: EValidSplit_def EValidSplit_ValidItem_def EValidSplitItem_def)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n      apply(simp add: EValidSplitItem_belongs_def)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n     apply(simp (no_asm_use) add: option_to_list_def)\n     apply(rule l2_in_proper_l3_l2_seq_at_end)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n    apply(subgoal_tac \"restrict_newignore S2 i = []\")\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n    apply(simp (no_asm) add: restrict_newignore_def new_post_sig_def)\n    apply(rule_tac\n      t=\"length (drop_and_crop (ESplitItem_to (S2 ! i) @ ESplitItem_ignore (S2 ! i)) (length (restrict_toberemovedX S2 ! Suc i)))\"\n      in ssubst)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n     apply(rule drop_and_crop_length)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a q1 ba q2 qF2 AF2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q1 ba q2 q1a baa q2a)(*strict*)\n   apply(subgoal_tac \"length (Esplit_signature S1) = Suc (length v)\")\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q1 ba q2 q1a baa q2a)(*strict*)\n    prefer 2\n    apply (metis Suc_length)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q1 ba q2 q1a baa q2a)(*strict*)\n   apply(subgoal_tac \"length (Esplit_signature S2) = Suc (length v)\")\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q1 ba q2 q1a baa q2a)(*strict*)\n    prefer 2\n    apply (metis Suc_length)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q1 ba q2 q1a baa q2a)(*strict*)\n   apply(rename_tac q11 A1 q12 q21 A2 q22)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n    prefer 2\n    apply(rule_tac\n      \\<alpha>=\"\\<alpha>1\"\n      and \\<pi>=\"e_\\<pi>1\"\n      and d=\"e_d1\"\n      and A=\"(cons_l3 q11 A1 q12)\"\n      and w=\"liftA(butlast (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! i)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! i))) (ESplitItem_ignore ((S1 @ S1') ! i))))))\"\n      in from_derives_prefix)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n     apply(simp add: split_TSstructure_def)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n    apply(rule_tac\n      t=\"[teA (cons_l3   q11 A1 q12)] @ liftA (butlast (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! i)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! i))) (ESplitItem_ignore ((S1 @ S1') ! i))))))\"\n      and s=\"liftA (option_to_list (ESplitItem_from ((S1 @ S1') ! i)) @ butlast (fillOptL (PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! i)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! i))) (ESplitItem_ignore ((S1 @ S1') ! i))))))\"\n      in ssubst)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n     apply(simp (no_asm))\n     apply(simp (no_asm) add: liftA_commutes_over_concat)\n     apply(rule_tac\n      t=\"(S1 @ S1') ! i\"\n      and s=\"S1!i\"\n      in ssubst)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n      apply(rule nth_append_1)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n     apply(simp (no_asm_simp) add: option_to_list_def)\n     apply(rule_tac\n      t=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! i)\"\n      and s=\"PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! i)\"\n      in ssubst)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n     apply(simp (no_asm))\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"e_d1a\"\n      and A=\"(cons_l3 q21 A2 q22)\"\n      and w=\"liftA(butlast (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! i)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! i))) (ESplitItem_ignore ((S2 @ S2') ! i))))))\"\n      in from_derives_prefix)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n     apply(simp add: split_TSstructure_def)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n    apply(rule_tac\n      t=\"[teA (cons_l3   q21 A2 q22)] @ liftA (butlast (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! i)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! i))) (ESplitItem_ignore ((S2 @ S2') ! i))))))\"\n      and s=\"liftA (option_to_list (ESplitItem_from ((S2 @ S2') ! i)) @ butlast (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! i)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! i))) (ESplitItem_ignore ((S2 @ S2') ! i))))))\"\n      in ssubst)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n     apply(simp (no_asm))\n     apply(simp (no_asm) add: liftA_commutes_over_concat)\n     apply(rule_tac\n      t=\"(S2 @ S2') ! i\"\n      and s=\"S2!i\"\n      in ssubst)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n      apply(rule nth_append_1)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n     apply(simp (no_asm_simp) add: option_to_list_def)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n   apply(thin_tac \"cfgLM.trans_der G e_d1a \\<lparr>cfg_conf = liftA (option_to_list (ESplitItem_from ((S2 @ S2') ! i)) @ butlast (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! i)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! i))) (ESplitItem_ignore ((S2 @ S2') ! i))))))\\<rparr> e_\\<pi>1a \\<lparr>cfg_conf = liftB \\<alpha>1a\\<rparr>\")\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n   apply(thin_tac \"cfgLM.trans_der G e_d1 \\<lparr>cfg_conf = liftA (option_to_list (ESplitItem_from ((S1 @ S1') ! i)) @ butlast (fillOptL (PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! i)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! i))) (ESplitItem_ignore ((S1 @ S1') ! i))))))\\<rparr> e_\\<pi>1 \\<lparr>cfg_conf = liftB \\<alpha>1\\<rparr>\")\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d1 e_d1a e_d2 e_d2a va vaa e_\\<pi>1 e_\\<pi>1a e_\\<pi>2 e_\\<pi>2a \\<alpha>1 \\<alpha>2 \\<alpha>1a \\<alpha>2a F1 F2 q11 A1 q12 q21 A2 q22)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n   apply(subgoal_tac \"ESplitItem_from (S1 ! i) = ESplitItem_from (S2 ! i)\")\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n    prefer 2\n    apply(rule_tac\n      t=\"ESplitItem_from (S1 ! i)\"\n      and s=\"Some (PSplitItem_from (restrict G' G (S1 @ S1') (Suc (length v)) ! i))\"\n      in ssubst)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(simp (no_asm_simp))\n     apply(rule cropTol3l2_ID)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n    apply(rule_tac\n      t=\"ESplitItem_from (S2 ! i)\"\n      and s=\"Some (PSplitItem_from (restrict G' G (S2 @ S2') (Suc (length v)) ! i))\"\n      in ssubst)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(simp (no_asm_simp))\n     apply(rule cropTol3l2_ID)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 q21 A2 q22 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n    prefer 2\n    apply(rule_tac\n      G=\"G'\"\n      and G'=\"G\"\n      and ?d1.0=\"d1a\"\n      and ?d2.0=\"d1aa\"\n      and ?x1.0=\"\\<alpha>2b@\\<alpha>2\"\n      and ?x2.0=\"\\<alpha>2c@\\<alpha>2a\"\n      in eliminating_derivations_are_equal_with_differing_future6)\n           apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n           apply(simp add: F2LR1inputx_def)\n          apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n          apply(simp add: F2LR1inputx_def)\n         apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n         apply(simp add: F2LR1inputx_def)\n        apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n        apply(simp add: F2LR1inputx_def)\n       apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n       apply(simp add: F2LR1inputx_def)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1 \\<pi>1a \\<pi>2 \\<alpha>1b \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n   apply(subgoal_tac \"EValidSplitItem_gen G (S1 ! i)\")\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n    prefer 2\n    apply(simp add: EValidSplit_def EValidSplit_ValidItem_def EValidSplitItem_def)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n   apply(subgoal_tac \"EValidSplitItem_gen G (S2 ! i)\")\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n    prefer 2\n    apply(simp add: EValidSplit_def EValidSplit_ValidItem_def EValidSplitItem_def)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c)(*strict*)\n   apply(simp add: EValidSplitItem_gen_def)\n   apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(simp add: option_to_list_def)\n   apply(rule_tac\n      v=\"\\<pi>1a\"\n      in equal_by_length_and_prefix_of_greater)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n     prefer 2\n     apply(subgoal_tac \"strict_prefix \\<pi>1a (ESplitItem_prods (S1 ! i)) \\<or> SSX\" for SSX)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n      prefer 2\n      apply(rule_tac\n      b=\"\\<pi>2 @ e_\\<pi>2\"\n      and d=\"\\<pi>s ! i @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S1 @ S1') ! x)) @ ESplitItem_prods ((S1 @ S1') ! x) @ \\<pi>s ! x) (nat_seq (Suc i) (length v)))\"\n      in mutual_strict_prefix_prefix)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n      apply(rule sym)\n      apply(rule_tac\n      t=\"S1 ! i\"\n      and s=\"(S1@S1') ! i\"\n      in subst)\n       apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n       apply(rule nth_append_1)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n     apply(erule disjE)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n     apply(subgoal_tac \"False\")\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n     apply(simp add: strict_prefix_def)\n     apply(clarsimp)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n     apply(subgoal_tac \"c=[]\")\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n     apply(rule_tac\n      ?d1.0=\"d1a\"\n      and ?d2.0=\"d\"\n      in unique_generation_length)\n        apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n        apply(simp add: split_TSstructure_def)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n    prefer 2\n    apply(subgoal_tac \"strict_prefix \\<pi>1a (ESplitItem_prods (S2 ! i)) \\<or> SSX\" for SSX)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n     prefer 2\n     apply(rule_tac\n      b=\"\\<pi>2a @ e_\\<pi>2a\"\n      and d=\"\\<pi>s ! i @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S2 @ S2') ! x)) @ ESplitItem_prods ((S2 @ S2') ! x) @ \\<pi>s ! x) (nat_seq (Suc i) (length v)))\"\n      in mutual_strict_prefix_prefix)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n     apply(rule sym)\n     apply(rule_tac\n      t=\"S2 ! i\"\n      and s=\"(S2@S2') ! i\"\n      in subst)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n      apply(rule nth_append_1)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n    apply(subgoal_tac \"False\")\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n    apply(simp add: strict_prefix_def)\n    apply(clarsimp)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n    apply(subgoal_tac \"c=[]\")\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n    apply(rule_tac\n      ?d1.0=\"d1aa\"\n      and ?d2.0=\"da\"\n      in unique_generation_length)\n       apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n       apply(simp add: split_TSstructure_def)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(subgoal_tac \"prefix (ESplitItem_prods (S1 ! i)) \\<pi>1a\")\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"strict_prefix \\<pi>1a (ESplitItem_prods (S1 ! i)) \\<or> SSX\" for SSX)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   prefer 2\n   apply(rule_tac\n    b=\"\\<pi>2 @ e_\\<pi>2\"\n    and d=\"\\<pi>s ! i @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S1 @ S1') ! x)) @ ESplitItem_prods ((S1 @ S1') ! x) @ \\<pi>s ! x) (nat_seq (Suc i) (length v)))\"\n    in mutual_strict_prefix_prefix)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(rule sym)\n   apply(rule_tac\n    t=\"S1 ! i\"\n    and s=\"(S1@S1') ! i\"\n    in subst)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n    apply(rule nth_append_1)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(subgoal_tac \"False\")\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(simp add: strict_prefix_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n  apply(subgoal_tac \"c=[]\")\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n  apply(rule_tac\n    ?d1.0=\"d1a\"\n    and ?d2.0=\"d\"\n    in unique_generation_length)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n     apply(simp add: split_TSstructure_def)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(subgoal_tac \"prefix (ESplitItem_prods (S2 ! i)) \\<pi>1a\")\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"strict_prefix \\<pi>1a (ESplitItem_prods (S2 ! i)) \\<or> SSX\" for SSX)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   prefer 2\n   apply(rule_tac\n    b=\"\\<pi>2a @ e_\\<pi>2a\"\n    and d=\"\\<pi>s ! i @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S2 @ S2') ! x)) @ ESplitItem_prods ((S2 @ S2') ! x) @ \\<pi>s ! x) (nat_seq (Suc i) (length v)))\"\n    in mutual_strict_prefix_prefix)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(rule sym)\n   apply(rule_tac\n    t=\"S2 ! i\"\n    and s=\"(S2@S2') ! i\"\n    in subst)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n    apply(rule nth_append_1)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(subgoal_tac \"False\")\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(simp add: strict_prefix_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n  apply(subgoal_tac \"c=[]\")\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n  apply(rule_tac\n    ?d1.0=\"d1aa\"\n    and ?d2.0=\"da\"\n    in unique_generation_length)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n     apply(simp add: split_TSstructure_def)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da c)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(subgoal_tac \" ESplitItem_elem (S1 ! i) = Some ((v@[teB b])!i) \\<and> ESplitItem_elem (S2 ! i) = Some ((v@[teB b])!i) \")\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  prefer 2\n  apply(rule conjI)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(rule Esplit_signature_take_prefix_closureise)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(rule Esplit_signature_take_prefix_closureise)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"Esplit_signature S1 ! i\")\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n  apply(case_tac \"length (ESplitItem_prods (S1 ! i)) < length (ESplitItem_prods (S2 ! i))\")\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n   apply(subgoal_tac \"strict_prefix (ESplitItem_prods (S1 ! i)) (ESplitItem_prods (S2 ! i))\")\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n    prefer 2\n    apply(rule_tac\n    v=\"\\<pi>1a\"\n    in strict_prefix_from_prefix_of_longer_and_shorter)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n   apply(simp add: strict_prefix_def prefix_def)\n   apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n   apply(rule_tac\n    v=\"[]\"\n    and ?d1.0=\"d\"\n    and ?d2.0=\"da\"\n    in left_degen_repetitions_in_parallel_derivation)\n         apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n         apply(force)\n        apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n  apply(case_tac \"length (ESplitItem_prods (S2 ! i)) < length (ESplitItem_prods (S1 ! i))\")\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n   apply(subgoal_tac \"strict_prefix (ESplitItem_prods (S2 ! i)) (ESplitItem_prods (S1 ! i))\")\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n    prefer 2\n    apply(rule_tac\n    v=\"\\<pi>1a\"\n    in strict_prefix_from_prefix_of_longer_and_shorter)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n   apply(simp add: strict_prefix_def prefix_def)\n   apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n   apply(rule_tac\n    v=\"[]\"\n    and ?d1.0=\"da\"\n    and ?d2.0=\"d\"\n    in left_degen_repetitions_in_parallel_derivation)\n         apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n         apply(force)\n        apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a c ca cb)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da a)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"length (ESplitItem_prods (S1 ! i)) < length (ESplitItem_prods (S2 ! i))\")\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n  apply(subgoal_tac \"strict_prefix (ESplitItem_prods (S1 ! i)) (ESplitItem_prods (S2 ! i))\")\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n   prefer 2\n   apply(rule_tac\n    v=\"\\<pi>1a\"\n    in strict_prefix_from_prefix_of_longer_and_shorter)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n  apply(simp add: strict_prefix_def prefix_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n  apply(rule_tac\n    v=\"[]\"\n    and ?d1.0=\"d\"\n    and ?d2.0=\"da\"\n    in terminal_production_repetitions_in_parallel_derivation)\n       apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n  apply(case_tac \"length (ESplitItem_prods (S2 ! i)) < length (ESplitItem_prods (S1 ! i))\")\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n  apply(subgoal_tac \"strict_prefix (ESplitItem_prods (S2 ! i)) (ESplitItem_prods (S1 ! i))\")\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n   prefer 2\n   apply(rule_tac\n    v=\"\\<pi>1a\"\n    in strict_prefix_from_prefix_of_longer_and_shorter)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n  apply(simp add: strict_prefix_def prefix_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n  apply(rule_tac\n    v=\"[]\"\n    and ?d1.0=\"da\"\n    and ?d2.0=\"d\"\n    in terminal_production_repetitions_in_parallel_derivation)\n       apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba c ca cb)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw p_d p_da e_d2 e_d2a va vaa e_\\<pi>2 e_\\<pi>2a \\<alpha>2 \\<alpha>2a q11 A1 q12 d1a d1aa \\<pi>1a \\<pi>2 \\<pi>2a \\<alpha>1c \\<alpha>2b \\<alpha>2c d da ba)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(subgoal_tac \"restrict_newignore S2 i = []\")\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  prefer 2\n  apply(rule_tac\n    t=\"restrict_newignore S2 i\"\n    and s=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i)\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(rule_tac\n    t=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i)\"\n    and s=\"PSplitItem_ignore (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i)\"\n    in subst)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(rule_tac\n    t=\"PSplitItem_ignore (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i)\"\n    and s=\"restrict_newignore S1 i\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"map (prod_to_edge G') (ESplitItem_prods (S1 ! i)) = map (prod_to_edge G') (ESplitItem_prods (S2 ! i))\")\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  prefer 2\n  apply(rule liftA_inj)\n  apply(rule_tac\n    t=\"liftA (map (prod_to_edge G') (ESplitItem_prods (S1 ! i)))\"\n    and s=\"PSplitItem_prods ((restrictX G' [restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i])!0)\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def restrictX_def)\n  apply(clarsimp)\n  apply(rule sym)\n  apply(simp add: restrict_newprods_def)\n  apply(rule equal_split_prefix_hlp1_triv_eq)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(rule_tac\n    t=\"liftA (map (prod_to_edge G') (ESplitItem_prods (S2 ! i)))\"\n    and s=\"PSplitItem_prods ((restrictX G' [restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i])!0)\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def restrictX_def)\n  apply(clarsimp)\n  apply(rule sym)\n  apply(simp add: restrict_newprods_def)\n  apply(rule equal_split_prefix_hlp1_triv_eq)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(subgoal_tac \"length (nat_seq 0 (length (ESplitItem_prods (S1 ! i)) - Suc 0)) = SSx\" for SSx)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  prefer 2\n  apply(rule nat_seq_length_prime)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(subgoal_tac \"length (nat_seq 0 (length (ESplitItem_prods (S2 ! i)) - Suc 0)) = SSx\" for SSx)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  prefer 2\n  apply(rule nat_seq_length_prime)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(subgoal_tac \"length (ESplitItem_prods (S1 ! i)) = length (ESplitItem_prods (S2 ! i))\")\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  prefer 2\n  apply (rule map_eq_imp_length_eq)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(simp only: restrict_newprodsX_def)\n  apply(subgoal_tac \" ESplitItem_prods (S1 ! i) = [] \\<longleftrightarrow> ESplitItem_prods (S2 ! i) = [] \")\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  prefer 2\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(case_tac \"ESplitItem_prods (S1 ! i) = []\")\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(rule_tac\n    t=\"(if ESplitItem_prods (S1 ! i) = [] then [] else map (\\<lambda>ia. if restrict_newprodsXX G ia (ESplitItem_prods (S1 ! i)) (ESplitItem_elem (S1 ! i)) (restrict_newto S1 i) then teB (ESplitItem_prods (S1 ! i) ! ia) else teA (THE e. e \\<in> F_DPDA_DRE__revert_F_SDPDA_TO_CFG_STD_1 G' (ESplitItem_prods (S1 ! i) ! ia))) (nat_seq 0 (length (ESplitItem_prods (S2 ! i)) - Suc 0)))\"\n    and s=\"map (\\<lambda>ia. if restrict_newprodsXX G ia (ESplitItem_prods (S1 ! i)) (ESplitItem_elem (S1 ! i)) (restrict_newto S1 i) then teB (ESplitItem_prods (S1 ! i) ! ia) else teA (THE e. e \\<in> F_DPDA_DRE__revert_F_SDPDA_TO_CFG_STD_1 G' (ESplitItem_prods (S1 ! i) ! ia))) (nat_seq 0 (length (ESplitItem_prods (S2 ! i)) - Suc 0))\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(rule_tac\n    t=\"(if ESplitItem_prods (S2 ! i) = [] then [] else map (\\<lambda>ia. if restrict_newprodsXX G ia (ESplitItem_prods (S2 ! i)) (ESplitItem_elem (S2 ! i)) (restrict_newto S2 i) then teB (ESplitItem_prods (S2 ! i) ! ia) else teA (THE e. e \\<in> F_DPDA_DRE__revert_F_SDPDA_TO_CFG_STD_1 G' (ESplitItem_prods (S2 ! i) ! ia))) (nat_seq 0 (length (ESplitItem_prods (S2 ! i)) - Suc 0)))\"\n    and s=\"(map (\\<lambda>ia. if restrict_newprodsXX G ia (ESplitItem_prods (S2 ! i)) (ESplitItem_elem (S2 ! i)) (restrict_newto S2 i) then teB (ESplitItem_prods (S2 ! i) ! ia) else teA (THE e. e \\<in> F_DPDA_DRE__revert_F_SDPDA_TO_CFG_STD_1 G' (ESplitItem_prods (S2 ! i) ! ia))) (nat_seq 0 (length (ESplitItem_prods (S2 ! i)) - Suc 0)))\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(rule listEqI)\n  apply(rename_tac ds \\<pi>s fw)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  apply(rule impI)\n  apply(simp (no_asm_use))\n  apply(rule_tac\n    t=\"(map SSf SSw)!ia\" for SSf SSw\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  apply(rule nth_map)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  apply(rule_tac\n    t=\"(map SSf SSw)!ia\" for SSf SSw\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  apply(rule nth_map)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  apply(subgoal_tac \"nat_seq 0 (length (ESplitItem_prods (S2 ! i)) - Suc 0) ! ia = SSX\" for SSX)\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  prefer 2\n  apply(rule nat_seq_nth_compute)\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  apply(subgoal_tac \"nat_seq 0 (length (ESplitItem_prods (S1 ! i)) - Suc 0) ! ia = SSX\" for SSX)\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  prefer 2\n  apply(rule nat_seq_nth_compute)\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  apply(case_tac \"ESplitItem_elem (S1 ! i)\")\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  apply(subgoal_tac \"False\")\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  apply(simp add: EValidSplit_def EValidSplit_producing_def)\n  apply(clarsimp)\n  apply(erule_tac\n    x=\"S1!i\"\n    and A=\"set (butlast (S1 @ S1'))\"\n    in ballE)\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  apply(subgoal_tac \"S1 ! i \\<in> set (butlast (S1 @ S1'))\")\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  apply(rule nth_in_butlast_append)\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia a)(*strict*)\n  apply(case_tac \"ESplitItem_elem (S2 ! i)\")\n  apply(rename_tac ds \\<pi>s fw ia a)(*strict*)\n  apply(subgoal_tac \"False\")\n  apply(rename_tac ds \\<pi>s fw ia a)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia a)(*strict*)\n  apply(simp add: EValidSplit_def EValidSplit_producing_def)\n  apply(clarsimp)\n  apply(erule_tac\n    x=\"S2!i\"\n    and A=\"set (butlast (S2 @ S2'))\"\n    in ballE)\n  apply(rename_tac ds \\<pi>s fw ia a)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia a)(*strict*)\n  apply(subgoal_tac \"S2 ! i \\<in> set (butlast (S2 @ S2'))\")\n  apply(rename_tac ds \\<pi>s fw ia a)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia a)(*strict*)\n  apply(rule nth_in_butlast_append)\n  apply(rename_tac ds \\<pi>s fw ia a)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia a)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia a aa)(*strict*)\n  apply(rename_tac X1 X2)\n  apply(rename_tac ds \\<pi>s fw ia X1 X2)(*strict*)\n  apply(subgoal_tac \"X1=X2\")\n  apply(rename_tac ds \\<pi>s fw ia X1 X2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    t=\"X1\"\n    and s=\"PSplitItem_elem (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i)\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X1 X2)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def restrict_newelem_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X1 X2)(*strict*)\n  apply(rule_tac\n    t=\"X2\"\n    and s=\"PSplitItem_elem (restrict G' G (S2 @ S2') (length (Esplit_signature S2)) ! i)\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X1 X2)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def restrict_newelem_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X1 X2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X1 X2)(*strict*)\n  apply(rename_tac X)\n  apply(rename_tac ds \\<pi>s fw ia X1 X)(*strict*)\n  apply(case_tac \"ESplitItem_from (S1 ! i)\")\n  apply(rename_tac ds \\<pi>s fw ia X1 X)(*strict*)\n  apply(simp add: EValidSplit_def EValidSplit_producing_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X)(*strict*)\n  apply(erule_tac\n    x=\"S1!i\"\n    and A=\"set (butlast (S1 @ S1'))\"\n    in ballE)\n  apply(rename_tac ds \\<pi>s fw ia X)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X)(*strict*)\n  apply(rule nth_in_butlast_append2)\n   apply(rename_tac ds \\<pi>s fw ia X)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X1 X a)(*strict*)\n  apply(case_tac \"ESplitItem_from (S2 ! i)\")\n  apply(rename_tac ds \\<pi>s fw ia X1 X a)(*strict*)\n  apply(simp add: EValidSplit_def EValidSplit_producing_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X a)(*strict*)\n  apply(erule_tac\n    x=\"S2!i\"\n    and A=\"set (butlast (S2 @ S2'))\"\n    in ballE)\n  apply(rename_tac ds \\<pi>s fw ia X a)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X a)(*strict*)\n  apply(rule nth_in_butlast_append2)\n   apply(rename_tac ds \\<pi>s fw ia X a)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X a)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X a)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X1 X a aa)(*strict*)\n  apply(rename_tac F1 F2)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2)(*strict*)\n  apply(subgoal_tac \"cropTol3l2_single F1 = cropTol3l2_single F2\")\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    t=\"cropTol3l2_single F1\"\n    and s=\"PSplitItem_from (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i)\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2)(*strict*)\n  apply(simp add: cropTol3l2_def)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2)(*strict*)\n  apply(rule_tac\n    t=\"cropTol3l2_single F2\"\n    and s=\"PSplitItem_from (restrict G' G (S2 @ S2') (length (Esplit_signature S2)) ! i)\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2)(*strict*)\n  apply(simp add: cropTol3l2_def)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2)(*strict*)\n  apply(subgoal_tac \"EValidSplitItem_gen G (S1 ! i)\")\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2)(*strict*)\n  prefer 2\n  apply(simp add: EValidSplit_def EValidSplit_ValidItem_def EValidSplitItem_def)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2)(*strict*)\n  apply(subgoal_tac \"EValidSplitItem_gen G (S2 ! i)\")\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2)(*strict*)\n  prefer 2\n  apply(simp add: EValidSplit_def EValidSplit_ValidItem_def EValidSplitItem_def)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2)(*strict*)\n  apply(simp (no_asm_use) only: EValidSplitItem_gen_def)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 d da)(*strict*)\n  apply(rename_tac dx1 dx2)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  apply(subgoal_tac \"restrict_newto S2 i = restrict_newto S1 i\")\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    t=\"restrict_newto S1 i\"\n    and s=\"PSplitItem_to (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i)\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  apply(rule_tac\n    t=\"restrict_newto S2 i\"\n    and s=\"PSplitItem_to (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i)\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  apply(subgoal_tac \"notfinishingL (ESplitItem_prods (S1 ! i))\")\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  prefer 2\n  apply(case_tac X)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2 a)(*strict*)\n  apply(rule_tac\n    xs=\"ESplitItem_to (S1 ! i)\"\n    in rev_cases)\n   apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2 a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 a)(*strict*)\n   apply(rule_tac\n    w=\"[]\"\n    and B=\"a\"\n    and d=\"dx1\"\n    in trans_der_notfinishingL)\n     apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 a)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 a)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 a)(*strict*)\n   apply(simp add: option_to_list_def)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2 a ys y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 a ys y)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(rule_tac\n    w=\"teA a#liftA ys\"\n    and B=\"y\"\n    and d=\"dx1\"\n    in trans_der_notfinishingL)\n    apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 a ys y)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 a ys y)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 a ys y)(*strict*)\n  apply(simp add: liftA_commutes_over_concat)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2 ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba)(*strict*)\n  apply(rule_tac\n    xs=\"ESplitItem_to (S1 ! i)\"\n    in rev_cases)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n    xs=\"ESplitItem_prods (S1 ! i)\"\n    in rev_cases)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y)(*strict*)\n   prefer 2\n   apply(rule_tac\n    G=\"G\"\n    and d=\"dx1\"\n    and i=\"length ys\"\n    and kleene_starT=\"False\"\n    and END=\"True\"\n    in cfgLM.trans_der_step_detail)\n     apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y)(*strict*)\n     apply(simp add: split_TSstructure_def)\n    apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y)(*strict*)\n  apply(simp add: cfgLM_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n  apply(subgoal_tac \"(\\<forall>d c \\<pi> c'. cfgLM.trans_der G d c \\<pi> c' \\<longrightarrow> (\\<exists>w1 w2. cfg_conf c = liftB w1 @ liftA w2) \\<longrightarrow> (\\<exists>w1 w2. cfg_conf c' = liftB w1 @ liftA w2))\")\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n   prefer 2\n   apply(simp add: split_TSstructure_def CFGtermLeft_def)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n  apply(erule_tac\n    x=\"dx1\"\n    in allE)\n  apply(erule_tac\n    x=\"\\<lparr>cfg_conf = [teA F1]\\<rparr>\"\n    in allE)\n  apply(erule_tac\n    x=\"ys\"\n    in allE)\n  apply(erule_tac\n    x=\"ci\"\n    in allE)\n  apply(erule impE)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n   apply(simp add: cfgLM.trans_der_def)\n   apply(rule conjI)\n    apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n    prefer 2\n    apply(simp add: option_to_list_def)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n   apply(rule_tac\n    m=\"Suc 0\"\n    and v=\"[Some y]\"\n    in get_labels_drop_tail)\n    apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n  apply(erule impE)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n   apply(rule_tac\n    x=\"[]\"\n    in exI)\n   apply(clarsimp)\n   apply(rule_tac\n    x=\"[X]\" for X\n    in exI)\n   apply(clarsimp)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r w1 w2)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(case_tac ci)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r w1 w2 cfg_confa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e l r w1 w2)(*strict*)\n  apply(thin_tac \"\\<forall>ia<length (ESplitItem_prods (S2 ! i)). hd (cfg_conf (the (get_configuration (dx2 ia)))) \\<noteq> teB ba\")\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e l r w1 w2)(*strict*)\n  apply(erule_tac\n    x=\"length ys\"\n    in allE)\n  apply(clarsimp)\n  apply(simp add: get_configuration_def)\n  apply(subgoal_tac \"l=liftB w1\")\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e l r w1 w2)(*strict*)\n   prefer 2\n   apply (metis split_decide1)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e l r w1 w2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e r w1 w2)(*strict*)\n  apply(case_tac w2)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e r w1 w2)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e r w1 w2 a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e w1 list)(*strict*)\n  apply(case_tac w1)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e w1 list)(*strict*)\n   prefer 2\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e w1 list a lista)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e w1 list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list)(*strict*)\n  apply(case_tac \"prod_rhs y\")\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list)(*strict*)\n   apply(clarsimp)\n   apply(case_tac list)\n    apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list a lista)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list a lista)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list)(*strict*)\n  apply(subgoal_tac \"LR1ProdFormSimp G\")\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list)(*strict*)\n   prefer 2\n   apply(simp add: split_TSstructure_def)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list)(*strict*)\n  apply(simp add: LR1ProdFormSimp_def)\n  apply(erule_tac\n    x=\"y\"\n    in ballE)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list baa A B)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list baa A B)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list baa A B)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list baa A B)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list baa A B)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y)(*strict*)\n  apply(rule_tac\n    w=\"teB ba#liftA ys\"\n    and B=\"y\"\n    and d=\"dx1\"\n    in trans_der_notfinishingL)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(simp add: liftA_commutes_over_concat)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  apply(subgoal_tac \"notfinishingL (ESplitItem_prods (S2 ! i))\")\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  prefer 2\n  apply(case_tac X)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2 a)(*strict*)\n  apply(rule_tac\n    xs=\"ESplitItem_to (S2 ! i)\"\n    in rev_cases)\n   apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2 a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 a)(*strict*)\n   apply(rule_tac\n    w=\"[]\"\n    and B=\"a\"\n    and d=\"dx2\"\n    in trans_der_notfinishingL)\n     apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 a)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 a)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 a)(*strict*)\n   apply(simp add: option_to_list_def)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2 a ys y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 a ys y)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(rule_tac\n    w=\"teA a#liftA ys\"\n    and B=\"y\"\n    and d=\"dx2\"\n    in trans_der_notfinishingL)\n    apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 a ys y)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 a ys y)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 a ys y)(*strict*)\n  apply(simp add: liftA_commutes_over_concat)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2 ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba)(*strict*)\n  apply(rule_tac\n    xs=\"ESplitItem_to (S2 ! i)\"\n    in rev_cases)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n    xs=\"ESplitItem_prods (S2 ! i)\"\n    in rev_cases)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y)(*strict*)\n   prefer 2\n   apply(rule_tac\n    G=\"G\"\n    and d=\"dx2\"\n    and i=\"length ys\"\n    and kleene_starT=\"False\"\n    and END=\"True\"\n    in cfgLM.trans_der_step_detail)\n     apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y)(*strict*)\n     apply(simp add: split_TSstructure_def)\n    apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y)(*strict*)\n  apply(simp add: cfgLM_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n  apply(subgoal_tac \"(\\<forall>d c \\<pi> c'. cfgLM.trans_der G d c \\<pi> c' \\<longrightarrow> (\\<exists>w1 w2. cfg_conf c = liftB w1 @ liftA w2) \\<longrightarrow> (\\<exists>w1 w2. cfg_conf c' = liftB w1 @ liftA w2))\")\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n   prefer 2\n   apply(simp add: split_TSstructure_def CFGtermLeft_def)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n  apply(erule_tac\n    x=\"dx2\"\n    in allE)\n  apply(erule_tac\n    x=\"\\<lparr>cfg_conf = [teA F2]\\<rparr>\"\n    in allE)\n  apply(erule_tac\n    x=\"ys\"\n    in allE)\n  apply(erule_tac\n    x=\"ci\"\n    in allE)\n  apply(erule impE)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n   apply(simp add: cfgLM.trans_der_def)\n   apply(rule conjI)\n    apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n    prefer 2\n    apply(simp add: option_to_list_def)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n   apply(rule_tac\n    m=\"Suc 0\"\n    and v=\"[Some y]\"\n    in get_labels_drop_tail)\n    apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n  apply(erule impE)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n   apply(rule_tac\n    x=\"[]\"\n    in exI)\n   apply(clarsimp)\n   apply(rule_tac\n    x=\"[X]\" for X\n    in exI)\n   apply(clarsimp)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r w1 w2)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(case_tac ci)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e ci l r w1 w2 cfg_confa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e l r w1 w2)(*strict*)\n  apply(thin_tac \"\\<forall>i<Suc (length ys). hd (cfg_conf (the (get_configuration (dx1 i)))) \\<noteq> teB ba\")\n  apply(erule_tac\n    x=\"length ys\"\n    in allE)\n  apply(clarsimp)\n  apply(simp add: get_configuration_def)\n  apply(subgoal_tac \"l=liftB w1\")\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e l r w1 w2)(*strict*)\n   prefer 2\n   apply (metis split_decide1)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e l r w1 w2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e r w1 w2)(*strict*)\n  apply(case_tac w2)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e r w1 w2)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e r w1 w2 a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e w1 list)(*strict*)\n  apply(case_tac w1)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e w1 list)(*strict*)\n   prefer 2\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e w1 list a lista)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e w1 list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list)(*strict*)\n  apply(case_tac \"prod_rhs y\")\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list)(*strict*)\n   apply(clarsimp)\n   apply(case_tac list)\n    apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list a lista)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list a lista)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list)(*strict*)\n  apply(subgoal_tac \"LR1ProdFormSimp G\")\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list)(*strict*)\n   prefer 2\n   apply(simp add: split_TSstructure_def)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list)(*strict*)\n  apply(simp add: LR1ProdFormSimp_def)\n  apply(erule_tac\n    x=\"y\"\n    in ballE)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list baa A B)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list baa A B)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list baa A B)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list baa A B)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y e list baa A B)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y)(*strict*)\n  apply(rule_tac\n    w=\"teB ba#liftA ys\"\n    and B=\"y\"\n    and d=\"dx2\"\n    in trans_der_notfinishingL)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba ys y)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(simp add: liftA_commutes_over_concat)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  apply(subgoal_tac \"\\<forall>p\\<in> set (butlast (ESplitItem_prods (S1 ! i))). \\<forall>b A. prod_rhs p \\<noteq> [teB b, teA A]\")\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  prefer 2\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 p ba A)(*strict*)\n  apply(rule_tac\n    xs=\"ESplitItem_prods (S1 ! i)\"\n    in rev_cases)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 p ba A)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 p ba A ys y)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>k<length ys. ys!k=p\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 p ba A ys y)(*strict*)\n  prefer 2\n  apply (metis in_set_conv_nth)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 p ba A ys y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k)(*strict*)\n  prefer 2\n  apply(rule_tac\n    G=\"G\"\n    and d=\"dx1\"\n    and i=\"k\"\n    and kleene_starT=\"False\"\n    and END=\"False\"\n    in cfgLM.trans_der_step_detail)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k)(*strict*)\n    apply(simp add: split_TSstructure_def)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k)(*strict*)\n  apply(simp add: cfgLM_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e ci ci' l r)(*strict*)\n  apply(subgoal_tac \"(ys @ [y]) ! k = ys!k\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e ci ci' l r)(*strict*)\n  prefer 2\n  apply(rule nth_append_1)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e ci ci' l r)(*strict*)\n  apply(clarsimp)\n  apply(case_tac ci)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e ci ci' l r cfg_confa)(*strict*)\n  apply(case_tac ci')\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e ci ci' l r cfg_confa cfg_confaa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n  apply(subgoal_tac \"(\\<forall>d c \\<pi> c'. cfgLM.trans_der G d c \\<pi> c' \\<longrightarrow> (\\<exists>w1 w2. cfg_conf c = liftB w1 @ liftA w2) \\<longrightarrow> (\\<exists>w1 w2. cfg_conf c' = liftB w1 @ liftA w2))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n  prefer 2\n  apply(simp add: split_TSstructure_def CFGtermLeft_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n  apply(erule_tac\n    x=\"dx1\"\n    in allE)\n  apply(erule_tac\n    x=\"\\<lparr>cfg_conf = [teA F1]\\<rparr>\"\n    in allE)\n  apply(erule_tac\n    x=\"take (Suc k) ys\"\n    in allE)\n  apply(erule_tac\n    x=\"\\<lparr>cfg_conf = l @ teB ba # teA A # r\\<rparr>\"\n    in allE)\n  apply(erule_tac\n    P=\"cfgLMTD G dx1 \\<lparr>cfg_conf = [teA F1]\\<rparr> (take (Suc k) ys) \\<lparr>cfg_conf = l @ teB ba # teA A # r\\<rparr>\"\n    in impE)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n  apply(rule_tac\n    t=\"min (length ys) (Suc k)\"\n    and s=\"Suc k\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n  apply(simp add: cfgLM.trans_der_def)\n  apply(simp add: option_to_list_def)\n  apply(rule_tac\n    t=\"min (length ys) (Suc k)\"\n    and s=\"Suc k\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r ea eb)(*strict*)\n  apply(rule_tac\n    m=\"length (ys@[y])-Suc k\"\n    and v=\"map Some (drop(Suc k)(ys@[y]))\"\n    in get_labels_drop_tail)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r ea eb)(*strict*)\n   apply(clarsimp)\n   apply (metis List.map_append append_take_drop_id_hlp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r ea eb)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n  apply(erule_tac\n    P=\"\\<exists>w1 w2. cfg_conf \\<lparr>cfg_conf = [teA F1]\\<rparr> = liftB w1 @ liftA w2\"\n    in impE)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n  apply(rule_tac\n    x=\"[]\"\n    in exI)\n  apply(clarsimp)\n  apply(rule_tac\n    x=\"[X]\" for X\n    in exI)\n  apply(clarsimp)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r w1 w2)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(case_tac X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 a)(*strict*)\n  apply(thin_tac \"left_degen G dx2\")\n  apply(simp add: left_degen_def sat_refined_def)\n  apply(erule_tac\n    x=\"k\"\n    in allE)+\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa)(*strict*)\n  apply(erule_tac\n    x=\"Suc k\"\n    in allE)+\n  apply(clarsimp)\n  apply(simp add: get_configuration_def)\n  apply(subgoal_tac \"\\<exists>w. cfg_get_history SSci @ w = cfg_get_history SScij\" for SSci SScij)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa)(*strict*)\n  prefer 2\n  apply(unfold cfgLM.trans_der_def)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa ea eb)(*strict*)\n  apply(fold cfgLM.trans_der_def)\n  apply(rule_tac\n    eij=\"ea\"\n    and cij=\"\\<lparr>cfg_conf = teB baa # liftA (ESplitItem_to (S1 ! i))\\<rparr>\"\n    and ci=\"\\<lparr>cfg_conf = liftB w1 @ liftA w2\\<rparr>\"\n    and ei=\"Some (ys!k)\"\n    and d=\"dx1\"\n    and i=\"Suc k\"\n    and j=\"length (ys@[y])-Suc k\"\n    in cfgLM.derivation_monotonically_inc)\n       apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa ea eb)(*strict*)\n       apply(simp add: split_TSstructure_def)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa ea eb)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa ea eb)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa ea eb)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa ea eb)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa ea eb)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa w)(*strict*)\n  apply(simp add: cfg_get_history_def)\n  apply(subgoal_tac \"maxTermPrefix (liftB w1 @ liftA w2) = w1\")\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa w)(*strict*)\n  prefer 2\n  apply (metis maxTermPrefix_drop_liftA maxTermPrefix_term_string)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa w)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"maxTermPrefix (teB baa # liftA (ESplitItem_to (S1 ! i))) = [baa]\")\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa w)(*strict*)\n  prefer 2\n  apply (metis maxTermPrefix_pull_out maxTermPrefix_liftA)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa w)(*strict*)\n  apply(case_tac l)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa w)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w1 w2 baa w)(*strict*)\n  apply(case_tac w1)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w1 w2 baa w)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w2 baa)(*strict*)\n   apply(case_tac w2)\n    apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w2 baa)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w2 baa a list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w1 w2 baa w a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa w a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w1 w2 baa w a list)(*strict*)\n  apply(case_tac a)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w1 w2 baa w a list aa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w1 w2 baa w a list bb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w1 w2 baa w list bb)(*strict*)\n  apply(case_tac w1)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w1 w2 baa w list bb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w2 baa list bb)(*strict*)\n  apply(case_tac w2)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w2 baa list bb)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w2 baa list bb a lista)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w1 w2 baa w list bb a lista)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  apply(subgoal_tac \"\\<forall>p\\<in> set (butlast (ESplitItem_prods (S2 ! i))). \\<forall>b A. prod_rhs p \\<noteq> [teB b, teA A]\")\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  prefer 2\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 p ba A)(*strict*)\n  apply(rule_tac\n    xs=\"ESplitItem_prods (S2 ! i)\"\n    in rev_cases)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 p ba A)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 p ba A ys y)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>k<length ys. ys!k=p\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 p ba A ys y)(*strict*)\n  prefer 2\n  apply (metis in_set_conv_nth)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 p ba A ys y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k)(*strict*)\n  prefer 2\n  apply(rule_tac\n    G=\"G\"\n    and d=\"dx2\"\n    and i=\"k\"\n    and kleene_starT=\"False\"\n    and END=\"False\"\n    in cfgLM.trans_der_step_detail)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k)(*strict*)\n    apply(simp add: split_TSstructure_def)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k)(*strict*)\n  apply(simp add: cfgLM_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e ci ci' l r)(*strict*)\n  apply(subgoal_tac \"(ys @ [y]) ! k = ys!k\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e ci ci' l r)(*strict*)\n  prefer 2\n  apply(rule nth_append_1)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e ci ci' l r)(*strict*)\n  apply(clarsimp)\n  apply(case_tac ci)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e ci ci' l r cfg_confa)(*strict*)\n  apply(case_tac ci')\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e ci ci' l r cfg_confa cfg_confaa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n  apply(subgoal_tac \"(\\<forall>d c \\<pi> c'. cfgLM.trans_der G d c \\<pi> c' \\<longrightarrow> (\\<exists>w1 w2. cfg_conf c = liftB w1 @ liftA w2) \\<longrightarrow> (\\<exists>w1 w2. cfg_conf c' = liftB w1 @ liftA w2))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n  prefer 2\n  apply(simp add: split_TSstructure_def CFGtermLeft_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n  apply(erule_tac\n    x=\"dx2\"\n    in allE)\n  apply(erule_tac\n    x=\"\\<lparr>cfg_conf = [teA F2]\\<rparr>\"\n    in allE)\n  apply(erule_tac\n    x=\"take (Suc k) ys\"\n    in allE)\n  apply(erule_tac\n    x=\"\\<lparr>cfg_conf = l @ teB ba # teA A # r\\<rparr>\"\n    in allE)\n  apply(erule_tac\n    P=\"cfgLMTD G dx2 \\<lparr>cfg_conf = [teA F2]\\<rparr> (take (Suc k) ys) \\<lparr>cfg_conf = l @ teB ba # teA A # r\\<rparr>\"\n    in impE)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n  apply(rule_tac\n    t=\"min (length ys) (Suc k)\"\n    and s=\"Suc k\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n  apply(simp add: cfgLM.trans_der_def)\n  apply(simp add: option_to_list_def)\n  apply(rule_tac\n    t=\"min (length ys) (Suc k)\"\n    and s=\"Suc k\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r ea eb)(*strict*)\n  apply(rule_tac\n    m=\"length (ys@[y])-Suc k\"\n    and v=\"map Some (drop(Suc k)(ys@[y]))\"\n    in get_labels_drop_tail)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r ea eb)(*strict*)\n   apply(clarsimp)\n   apply (metis List.map_append append_take_drop_id_hlp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r ea eb)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n  apply(erule_tac\n    P=\"\\<exists>w1 w2. cfg_conf \\<lparr>cfg_conf = [teA F2]\\<rparr> = liftB w1 @ liftA w2\"\n    in impE)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n  apply(rule_tac\n    x=\"[]\"\n    in exI)\n  apply(clarsimp)\n  apply(rule_tac\n    x=\"[X]\" for X\n    in exI)\n  apply(clarsimp)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r w1 w2)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(case_tac X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 a)(*strict*)\n  apply(thin_tac \"left_degen G dx1\")\n  apply(simp add: left_degen_def sat_refined_def)\n  apply(erule_tac\n    x=\"k\"\n    in allE)+\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa)(*strict*)\n  apply(erule_tac\n    x=\"Suc k\"\n    in allE)+\n  apply(clarsimp)\n  apply(simp add: get_configuration_def)\n  apply(subgoal_tac \"\\<exists>w. cfg_get_history SSci @ w = cfg_get_history SScij\" for SSci SScij)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa)(*strict*)\n  prefer 2\n  apply(unfold cfgLM.trans_der_def)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa ea eb)(*strict*)\n  apply(fold cfgLM.trans_der_def)\n  apply(rule_tac\n    eij=\"eb\"\n    and cij=\"\\<lparr>cfg_conf = teB baa # liftA (ESplitItem_to (S2 ! i))\\<rparr>\"\n    and ci=\"\\<lparr>cfg_conf = liftB w1 @ liftA w2\\<rparr>\"\n    and ei=\"Some (ys!k)\"\n    and d=\"dx2\"\n    and i=\"Suc k\"\n    and j=\"length (ys@[y])-Suc k\"\n    in cfgLM.derivation_monotonically_inc)\n       apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa ea eb)(*strict*)\n       apply(simp add: split_TSstructure_def)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa ea eb)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa ea eb)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa ea eb)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa ea eb)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa ea eb)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa w)(*strict*)\n  apply(simp add: cfg_get_history_def)\n  apply(subgoal_tac \"maxTermPrefix (liftB w1 @ liftA w2) = w1\")\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa w)(*strict*)\n  prefer 2\n  apply (metis maxTermPrefix_drop_liftA maxTermPrefix_term_string)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa w)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"maxTermPrefix (teB baa # liftA (ESplitItem_to (S2 ! i))) = [baa]\")\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa w)(*strict*)\n  prefer 2\n  apply (metis maxTermPrefix_pull_out maxTermPrefix_liftA)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa w)(*strict*)\n  apply(case_tac l)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa w)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w1 w2 baa w)(*strict*)\n  apply(case_tac w1)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w1 w2 baa w)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w2 baa)(*strict*)\n   apply(case_tac w2)\n    apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w2 baa)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w2 baa a list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w1 w2 baa w a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e l r w1 w2 baa w a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w1 w2 baa w a list)(*strict*)\n  apply(case_tac a)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w1 w2 baa w a list aa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w1 w2 baa w a list bb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w1 w2 baa w list bb)(*strict*)\n  apply(case_tac w1)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w1 w2 baa w list bb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w2 baa list bb)(*strict*)\n  apply(case_tac w2)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w2 baa list bb)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w2 baa list bb a lista)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ba A ys y k e r w1 w2 baa w list bb a lista)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  apply(subgoal_tac \"restrict_newprodsXX G (nat_seq 0 (length (ESplitItem_prods (S2 ! i)) - Suc 0) ! ia) (ESplitItem_prods (S1 ! i)) (ESplitItem_elem (S1 ! i)) (restrict_newto S1 i) \\<longleftrightarrow> restrict_newprodsXX G (nat_seq 0 (length (ESplitItem_prods (S2 ! i)) - Suc 0) ! ia) (ESplitItem_prods (S2 ! i)) (ESplitItem_elem (S2 ! i)) (restrict_newto S2 i)\")\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  prefer 2\n  apply(rule antisym)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n  apply(rule_tac\n    ?dx1.0=\"dx1\"\n    and ?dx2.0=\"dx2\"\n    and ?F1.0=\"F1\"\n    and ?F2.0=\"F2\"\n    in restrict_newprodsXX_implication)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n                    prefer 19\n                    apply(force)\n                   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n                   apply(force)\n                  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n                  apply(force)\n                 apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n                 apply(force)\n                apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n                apply(force)\n               apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n               apply(simp add: option_to_list_def)\n              apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n              apply(force)\n             apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n             apply(simp add: option_to_list_def)\n            apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n            apply(force)\n           apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n           apply(force)\n          apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n          apply(force)\n         apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n         apply(simp add: restrict_newto_def)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n        apply(rule_tac\n    t=\"restrict_newto S1 i\"\n    and s=\"restrict_newto S2 i\"\n    in ssubst)\n         apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n         apply(force)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n        apply(simp (no_asm) add: restrict_newto_def)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n       apply(rule newto_and_old_to_either_unmodified_or_cropTol3l2_of_prefix)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n      apply(rule_tac\n    t=\"restrict_newto S1 i\"\n    and s=\"restrict_newto S2 i\"\n    in ssubst)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n      apply(rule newto_and_old_to_either_unmodified_or_cropTol3l2_of_prefix)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n  apply(rule_tac\n    ?dx1.0=\"dx2\"\n    and ?dx2.0=\"dx1\"\n    and ?F1.0=\"F2\"\n    and ?F2.0=\"F1\"\n    in restrict_newprodsXX_implication)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n                    apply(force)\n                   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n                   prefer 19\n                   apply(force)\n                  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n                  apply(force)\n                 apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n                 apply(force)\n                apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n                apply(force)\n               apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n               apply(force)\n              apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n              apply(simp add: option_to_list_def)\n             apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n             apply(force)\n            apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n            apply(simp add: option_to_list_def)\n           apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n           apply(force)\n          apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n          apply(force)\n         apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n         apply(force)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n        apply(rule_tac\n    t=\"restrict_newto S1 i\"\n    and s=\"restrict_newto S2 i\"\n    in ssubst)\n         apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n         apply(force)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n        apply(simp (no_asm) add: restrict_newto_def)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n       apply(simp add: restrict_newto_def)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n      apply(rule_tac\n    t=\"restrict_newto S1 i\"\n    and s=\"restrict_newto S2 i\"\n    in ssubst)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n      apply(rule newto_and_old_to_either_unmodified_or_cropTol3l2_of_prefix)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n     apply(rule newto_and_old_to_either_unmodified_or_cropTol3l2_of_prefix)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  apply(case_tac \"restrict_newprodsXX G (nat_seq 0 (length (ESplitItem_prods (S2 ! i)) - Suc 0) ! ia) (ESplitItem_prods (S1 ! i)) (ESplitItem_elem (S1 ! i)) (restrict_newto S1 i)\")\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n  prefer 2\n  apply(rename_tac ds \\<pi>s fw ia X1 X F1 F2 dx1 dx2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n  apply(subgoal_tac \"(map (prod_to_edge G') (ESplitItem_prods (S1 ! i)))!ia = (map (prod_to_edge G') (ESplitItem_prods (S2 ! i)))!ia\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n  prefer 2\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n  apply(thin_tac \"map (prod_to_edge G') (ESplitItem_prods (S1 ! i)) = map (prod_to_edge G') (ESplitItem_prods (S2 ! i))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n  apply(clarsimp)\n  apply(simp add: prod_to_edge_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(simp add: restrict_newprodsXX_def)\n  apply(simp add: option_to_list_def)\n  apply(thin_tac \"nat_seq 0 (length (ESplitItem_prods (S2 ! i)) - Suc 0) ! ia = ia\")\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    i=\"ia\"\n    and d=\"dx1\"\n    in cfgLM.trans_der_position_detail)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n   apply(simp add: split_TSstructure_def)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci)(*strict*)\n  prefer 2\n  apply(rule_tac\n    ?e1.0=\"e\"\n    and cI=\"ci\"\n    and n=\"ia\"\n    and d=\"dx1\"\n    in cfgLM.trans_der_skip_prime)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci)(*strict*)\n     apply(simp add: split_TSstructure_def)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d)(*strict*)\n  apply(subgoal_tac \"prefix (realizable G (drop ia SSX)) (drop ia (ESplitItem_prods (S1 ! i)))\" for SSX)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d)(*strict*)\n  prefer 2\n  apply(rule realizable_prefix)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d)(*strict*)\n    apply(simp add: split_TSstructure_def)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d)(*strict*)\n  apply(rule_tac\n    t=\"cfg_productions G\"\n    and s=\"cfg_step_labels G\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d)(*strict*)\n   apply(simp add: cfg_step_labels_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d)(*strict*)\n  apply(rule cfgLM.trans_der_all_step_labels)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d)(*strict*)\n   apply(simp add: split_TSstructure_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d)(*strict*)\n  prefer 2\n  apply(rule_tac\n    i=\"ia\"\n    and d=\"dx2\"\n    in cfgLM.trans_der_position_detail)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d)(*strict*)\n   apply(simp add: split_TSstructure_def)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia)(*strict*)\n  prefer 2\n  apply(rule_tac\n    ?e1.0=\"ea\"\n    and cI=\"cia\"\n    and n=\"ia\"\n    and d=\"dx2\"\n    in cfgLM.trans_der_skip_prime)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia)(*strict*)\n     apply(simp add: split_TSstructure_def)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n  apply(subgoal_tac \"prefix (realizable G (drop ia SSX)) (drop ia (ESplitItem_prods (S2 ! i)))\" for SSX)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n  prefer 2\n  apply(rule realizable_prefix)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n    apply(simp add: split_TSstructure_def)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n  apply(rule_tac\n    t=\"cfg_productions G\"\n    and s=\"cfg_step_labels G\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n   apply(simp add: cfg_step_labels_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n  apply(rule cfgLM.trans_der_all_step_labels)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n   apply(simp add: split_TSstructure_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n  prefer 2\n  apply(rule_tac\n    \\<pi>=\"drop ia (ESplitItem_prods (S1 ! i))\"\n    in unique_existence_of_realizable)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n    apply(simp add: split_TSstructure_def)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n  apply(rule_tac\n    t=\"cfg_productions G\"\n    and s=\"cfg_step_labels G\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n   apply(simp add: cfg_step_labels_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n  apply(rule cfgLM.trans_der_all_step_labels)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n   apply(simp add: split_TSstructure_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n  prefer 2\n  apply(thin_tac \"\\<exists>!\\<pi>'. \\<exists>c. \\<pi>' \\<sqsubseteq> drop ia (ESplitItem_prods (S1 ! i)) \\<and> (\\<exists>d. cfgLM.trans_der G d \\<lparr>cfg_conf = [teA (prod_lhs (hd (drop ia (ESplitItem_prods (S1 ! i)))))]\\<rparr> \\<pi>' c) \\<and> (setA (cfg_conf c) = {} \\<or> \\<pi>' = drop ia (ESplitItem_prods (S1 ! i)))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n  apply(rule_tac\n    \\<pi>=\"drop ia (ESplitItem_prods (S2 ! i))\"\n    in unique_existence_of_realizable)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n    apply(simp add: split_TSstructure_def)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n  apply(rule_tac\n    t=\"cfg_productions G\"\n    and s=\"cfg_step_labels G\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n   apply(simp add: cfg_step_labels_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n  apply(rule cfgLM.trans_der_all_step_labels)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n   apply(simp add: split_TSstructure_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da)(*strict*)\n  apply(clarify)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n  apply(subgoal_tac \"realizable G (drop ia (ESplitItem_prods (S1 ! i))) = \\<pi>'\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n  prefer 2\n  apply(thin_tac \"\\<forall>y y'. (\\<exists>c. y \\<sqsubseteq> drop ia (ESplitItem_prods (S1 ! i)) \\<and> (\\<exists>d. cfgLM.trans_der G d \\<lparr>cfg_conf = [teA (prod_lhs (hd (drop ia (ESplitItem_prods (S1 ! i)))))]\\<rparr> y c) \\<and> (setA (cfg_conf c) = {} \\<or> y = drop ia (ESplitItem_prods (S1 ! i)))) \\<and> (\\<exists>c. y' \\<sqsubseteq> drop ia (ESplitItem_prods (S1 ! i)) \\<and> (\\<exists>d. cfgLM.trans_der G d \\<lparr>cfg_conf = [teA (prod_lhs (hd (drop ia (ESplitItem_prods (S1 ! i)))))]\\<rparr> y' c) \\<and> (setA (cfg_conf c) = {} \\<or> y' = drop ia (ESplitItem_prods (S1 ! i)))) \\<longrightarrow> y = y'\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n  apply(thin_tac \"\\<forall>y y'. (\\<exists>c. y \\<sqsubseteq> drop ia (ESplitItem_prods (S2 ! i)) \\<and> (\\<exists>d. cfgLM.trans_der G d \\<lparr>cfg_conf = [teA (prod_lhs (hd (drop ia (ESplitItem_prods (S2 ! i)))))]\\<rparr> y c) \\<and> (setA (cfg_conf c) = {} \\<or> y = drop ia (ESplitItem_prods (S2 ! i)))) \\<and> (\\<exists>c. y' \\<sqsubseteq> drop ia (ESplitItem_prods (S2 ! i)) \\<and> (\\<exists>d. cfgLM.trans_der G d \\<lparr>cfg_conf = [teA (prod_lhs (hd (drop ia (ESplitItem_prods (S2 ! i)))))]\\<rparr> y' c) \\<and> (setA (cfg_conf c) = {} \\<or> y' = drop ia (ESplitItem_prods (S2 ! i)))) \\<longrightarrow> y = y'\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n  apply(rule_tac\n    d=\"d\"\n    and da=\"db\"\n    in realizable_eq_from_existence)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n       apply(simp add: split_TSstructure_def)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n     apply(rule_tac\n    t=\"cfg_productions G\"\n    and s=\"cfg_step_labels G\"\n    in ssubst)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n      apply(simp add: cfg_step_labels_def)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n     apply(rule cfgLM.trans_der_all_step_labels)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n      apply(simp add: split_TSstructure_def)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n  apply(subgoal_tac \"realizable G (drop ia (ESplitItem_prods (S2 ! i))) = \\<pi>'a\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n  prefer 2\n  apply(thin_tac \"\\<forall>y y'. (\\<exists>c. y \\<sqsubseteq> drop ia (ESplitItem_prods (S1 ! i)) \\<and> (\\<exists>d. cfgLM.trans_der G d \\<lparr>cfg_conf = [teA (prod_lhs (hd (drop ia (ESplitItem_prods (S1 ! i)))))]\\<rparr> y c) \\<and> (setA (cfg_conf c) = {} \\<or> y = drop ia (ESplitItem_prods (S1 ! i)))) \\<and> (\\<exists>c. y' \\<sqsubseteq> drop ia (ESplitItem_prods (S1 ! i)) \\<and> (\\<exists>d. cfgLM.trans_der G d \\<lparr>cfg_conf = [teA (prod_lhs (hd (drop ia (ESplitItem_prods (S1 ! i)))))]\\<rparr> y' c) \\<and> (setA (cfg_conf c) = {} \\<or> y' = drop ia (ESplitItem_prods (S1 ! i)))) \\<longrightarrow> y = y'\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n  apply(thin_tac \"\\<forall>y y'. (\\<exists>c. y \\<sqsubseteq> drop ia (ESplitItem_prods (S2 ! i)) \\<and> (\\<exists>d. cfgLM.trans_der G d \\<lparr>cfg_conf = [teA (prod_lhs (hd (drop ia (ESplitItem_prods (S2 ! i)))))]\\<rparr> y c) \\<and> (setA (cfg_conf c) = {} \\<or> y = drop ia (ESplitItem_prods (S2 ! i)))) \\<and> (\\<exists>c. y' \\<sqsubseteq> drop ia (ESplitItem_prods (S2 ! i)) \\<and> (\\<exists>d. cfgLM.trans_der G d \\<lparr>cfg_conf = [teA (prod_lhs (hd (drop ia (ESplitItem_prods (S2 ! i)))))]\\<rparr> y' c) \\<and> (setA (cfg_conf c) = {} \\<or> y' = drop ia (ESplitItem_prods (S2 ! i)))) \\<longrightarrow> y = y'\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n  apply(rule_tac\n    d=\"da\"\n    and da=\"dc\"\n    in realizable_eq_from_existence)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n       apply(simp add: split_TSstructure_def)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n     apply(rule_tac\n    t=\"cfg_productions G\"\n    and s=\"cfg_step_labels G\"\n    in ssubst)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n      apply(simp add: cfg_step_labels_def)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n     apply(rule cfgLM.trans_der_all_step_labels)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n      apply(simp add: split_TSstructure_def)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n  apply(clarify)\n  apply(thin_tac \"\\<forall>y y'. (\\<exists>c. y \\<sqsubseteq> drop ia (ESplitItem_prods (S1 ! i)) \\<and> (\\<exists>d. cfgLM.trans_der G d \\<lparr>cfg_conf = [teA (prod_lhs (hd (drop ia (ESplitItem_prods (S1 ! i)))))]\\<rparr> y c) \\<and> (setA (cfg_conf c) = {} \\<or> y = drop ia (ESplitItem_prods (S1 ! i)))) \\<and> (\\<exists>c. y' \\<sqsubseteq> drop ia (ESplitItem_prods (S1 ! i)) \\<and> (\\<exists>d. cfgLM.trans_der G d \\<lparr>cfg_conf = [teA (prod_lhs (hd (drop ia (ESplitItem_prods (S1 ! i)))))]\\<rparr> y' c) \\<and> (setA (cfg_conf c) = {} \\<or> y' = drop ia (ESplitItem_prods (S1 ! i)))) \\<longrightarrow> y = y'\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n  apply(thin_tac \"\\<forall>y y'. (\\<exists>c. y \\<sqsubseteq> drop ia (ESplitItem_prods (S2 ! i)) \\<and> (\\<exists>d. cfgLM.trans_der G d \\<lparr>cfg_conf = [teA (prod_lhs (hd (drop ia (ESplitItem_prods (S2 ! i)))))]\\<rparr> y c) \\<and> (setA (cfg_conf c) = {} \\<or> y = drop ia (ESplitItem_prods (S2 ! i)))) \\<and> (\\<exists>c. y' \\<sqsubseteq> drop ia (ESplitItem_prods (S2 ! i)) \\<and> (\\<exists>d. cfgLM.trans_der G d \\<lparr>cfg_conf = [teA (prod_lhs (hd (drop ia (ESplitItem_prods (S2 ! i)))))]\\<rparr> y' c) \\<and> (setA (cfg_conf c) = {} \\<or> y' = drop ia (ESplitItem_prods (S2 ! i)))) \\<longrightarrow> y = y'\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n  apply(thin_tac \"(e = Some (ESplitItem_prods (S1 ! i) ! (ia - Suc 0))) = (ea = Some (ESplitItem_prods (S2 ! i) ! (ia - Suc 0)))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da \\<pi>' \\<pi>'a c ca db dc)(*strict*)\n  apply(thin_tac \"(0 < ia) = (ea = Some (ESplitItem_prods (S2 ! i) ! (ia - Suc 0)))\")\n  apply(thin_tac \"(e = None) = (ea = None)\")\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da c ca db dc)(*strict*)\n  apply(case_tac ci)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da c ca db dc cfg_confa)(*strict*)\n  apply(case_tac cia)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da c ca db dc cfg_confa cfg_confaa)(*strict*)\n  apply(rename_tac x1 x2)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e ci d ea cia da c ca db dc x1 x2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(subgoal_tac \"\\<exists>l'. liftA l' = x1\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    x=\"filterA x1\"\n    in exI)\n  apply (rule liftA_filterA)\n  apply(subgoal_tac \"(\\<forall>d c \\<pi> c'. cfgLM.trans_der G d c \\<pi> c' \\<longrightarrow> (\\<exists>w1 w2. cfg_conf c = liftB w1 @ liftA w2) \\<longrightarrow> (\\<exists>w1 w2. cfg_conf c' = liftB w1 @ liftA w2))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  prefer 2\n  apply(simp add: split_TSstructure_def CFGtermLeft_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(erule_tac\n    x=\"dx1\"\n    in allE)\n  apply(erule_tac\n    x=\"\\<lparr>cfg_conf = [teA F1]\\<rparr>\"\n    in allE)\n  apply(erule_tac\n    x=\"(take ia (ESplitItem_prods (S1 ! i)))\"\n    in allE)\n  apply(erule_tac\n    x=\"\\<lparr>cfg_conf=x1\\<rparr>\"\n    in allE)\n  apply(erule_tac\n    P=\"cfgLMTD G dx1 \\<lparr>cfg_conf = [teA F1]\\<rparr> (take ia (ESplitItem_prods (S1 ! i))) \\<lparr>cfg_conf = x1\\<rparr>\"\n    in impE)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(simp add: cfgLM.trans_der_def)\n  apply(rule_tac\n    t=\"min (length (ESplitItem_prods (S2 ! i))) ia\"\n    and s=\"ia\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 eb ec ed ee ef eg)(*strict*)\n  apply(rule_tac\n    m=\"length (ESplitItem_prods (S1 ! i))-ia\"\n    and v=\"map Some (drop ia (ESplitItem_prods (S1 ! i)))\"\n    in get_labels_drop_tail)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 eb ec ed ee ef eg)(*strict*)\n   apply(clarsimp)\n   apply (metis List.map_append append_take_drop_id)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 eb ec ed ee ef eg)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(erule_tac\n    P=\"\\<exists>w1 w2. cfg_conf \\<lparr>cfg_conf = [teA F1]\\<rparr> = liftB w1 @ liftA w2\"\n    in impE)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(rule_tac\n    x=\"[]\"\n    in exI)\n  apply(clarsimp)\n  apply(rule_tac\n    x=\"[X]\" for X\n    in exI)\n  apply(clarsimp)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 w1 w2)(*strict*)\n  apply(simp add: setAConcat setBConcat setA_liftB setA_liftA setB_liftA setB_liftB)\n  apply(case_tac w1)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 w1 w2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 w1 w2 a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. cfg_get_history SSci @ w = cfg_get_history SScij\" for SSci SScij)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list)(*strict*)\n  prefer 2\n  apply(unfold cfgLM.trans_der_def)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list eb ec ed ee ef eg)(*strict*)\n  apply(fold cfgLM.trans_der_def)\n  apply(rule_tac\n    eij=\"eb\"\n    and cij=\"\\<lparr>cfg_conf = X # liftA (ESplitItem_to (S1 ! i))\\<rparr>\"\n    and ei=\"e\"\n    and ci=\"\\<lparr>cfg_conf = teB a # liftB list @ liftA w2\\<rparr>\"\n    and d=\"dx1\"\n    and i=\"ia\"\n    and j=\"length (ESplitItem_prods (S1 ! i))-ia\"\n    in cfgLM.derivation_monotonically_inc)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list eb ec ed ee ef eg)(*strict*)\n       apply(simp add: split_TSstructure_def)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list eb ec ed ee ef eg)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list eb ec ed ee ef eg)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list eb ec ed ee ef eg)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list eb ec ed ee ef eg)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list eb ec ed ee ef eg)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list w)(*strict*)\n  apply(simp add: cfg_get_history_def)\n  apply(subgoal_tac \"maxTermPrefix (teB a # liftB list @ liftA w2) = a#list\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list w)(*strict*)\n  prefer 2\n  apply (metis maxTermPrefix_pull_out append_Nil2 maxTermPrefix_liftA maxTermPrefix_shift)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list w)(*strict*)\n  apply(clarsimp)\n  apply(case_tac X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list w aa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list w aa)(*strict*)\n  apply(subgoal_tac \"maxTermPrefix (teA aa # liftA (ESplitItem_to (S1 ! i))) = []\")\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list w aa)(*strict*)\n   apply(subgoal_tac \"a # list @ w = []\")\n    apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list w aa)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list w aa)(*strict*)\n   apply(rule_tac\n    t=\"a # list @ w\"\n    and s=\"maxTermPrefix (teA aa # liftA (ESplitItem_to (S1 ! i)))\"\n    in ssubst)\n    apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list w aa)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list w aa)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list w aa)(*strict*)\n  apply (metis liftA.simps(2) liftA_commutes_over_concat maxTermPrefix_liftA)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list w ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list w ba)(*strict*)\n  apply(subgoal_tac \"maxTermPrefix (teB ba # liftA (ESplitItem_to (S1 ! i))) = [ba]\")\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list w ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 ba)(*strict*)\n  apply(erule_tac\n    x=\"ia\"\n    in allE)+\n  apply(clarsimp)\n  apply(simp add: get_configuration_def)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc x2 w2 a list w ba)(*strict*)\n  apply (metis maxTermPrefix_pull_out liftA.simps(2) liftA_commutes_over_concat maxTermPrefix_liftA)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(subgoal_tac \"\\<exists>l'. liftA l' = x2\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    x=\"filterA x2\"\n    in exI)\n  apply (rule liftA_filterA)\n  apply(subgoal_tac \"(\\<forall>d c \\<pi> c'. cfgLM.trans_der G d c \\<pi> c' \\<longrightarrow> (\\<exists>w1 w2. cfg_conf c = liftB w1 @ liftA w2) \\<longrightarrow> (\\<exists>w1 w2. cfg_conf c' = liftB w1 @ liftA w2))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  prefer 2\n  apply(simp add: split_TSstructure_def CFGtermLeft_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(erule_tac\n    x=\"dx2\"\n    in allE)\n  apply(erule_tac\n    x=\"\\<lparr>cfg_conf = [teA F2]\\<rparr>\"\n    in allE)\n  apply(erule_tac\n    x=\"(take ia (ESplitItem_prods (S2 ! i)))\"\n    in allE)\n  apply(erule_tac\n    x=\"\\<lparr>cfg_conf=x2\\<rparr>\"\n    in allE)\n  apply(erule_tac\n    P=\"cfgLMTD G dx2 \\<lparr>cfg_conf = [teA F2]\\<rparr> (take ia (ESplitItem_prods (S2 ! i))) \\<lparr>cfg_conf = x2\\<rparr>\"\n    in impE)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(simp add: cfgLM.trans_der_def)\n  apply(rule_tac\n    t=\"min (length (ESplitItem_prods (S2 ! i))) ia\"\n    and s=\"ia\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 l' eb ec ed ee ef eg)(*strict*)\n  apply(rule_tac\n    m=\"length (ESplitItem_prods (S2 ! i))-ia\"\n    and v=\"map Some (drop ia (ESplitItem_prods (S2 ! i)))\"\n    in get_labels_drop_tail)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 l' eb ec ed ee ef eg)(*strict*)\n   apply(clarsimp)\n   apply (metis List.map_append append_take_drop_id)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 l' eb ec ed ee ef eg)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(erule_tac\n    P=\"\\<exists>w1 w2. cfg_conf \\<lparr>cfg_conf = [teA F2]\\<rparr> = liftB w1 @ liftA w2\"\n    in impE)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(rule_tac\n    x=\"[]\"\n    in exI)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x2 l')(*strict*)\n  apply(rule_tac\n    x=\"[X]\" for X\n    in exI)\n  apply(clarsimp)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc l' w1 w2)(*strict*)\n  apply(simp add: setAConcat setBConcat setA_liftB setA_liftA setB_liftA setB_liftB)\n  apply(case_tac w1)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc l' w1 w2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc l' w1 w2 a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. cfg_get_history SSci @ w = cfg_get_history SScij\" for SSci SScij)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list)(*strict*)\n  prefer 2\n  apply(unfold cfgLM.trans_der_def)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list eb ec ed ee ef eg)(*strict*)\n  apply(fold cfgLM.trans_der_def)\n  apply(rule_tac\n    eij=\"ec\"\n    and cij=\"\\<lparr>cfg_conf = X # liftA (ESplitItem_to (S2 ! i))\\<rparr>\"\n    and ei=\"ea\"\n    and ci=\"\\<lparr>cfg_conf = teB a # liftB list @ liftA w2\\<rparr>\"\n    and d=\"dx2\"\n    and i=\"ia\"\n    and j=\"length (ESplitItem_prods (S2 ! i))-ia\"\n    in cfgLM.derivation_monotonically_inc)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list eb ec ed ee ef eg)(*strict*)\n       apply(simp add: split_TSstructure_def)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list eb ec ed ee ef eg)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list eb ec ed ee ef eg)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list eb ec ed ee ef eg)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list eb ec ed ee ef eg)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list eb ec ed ee ef eg)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list w)(*strict*)\n  apply(simp add: cfg_get_history_def)\n  apply(subgoal_tac \"maxTermPrefix (teB a # liftB list @ liftA w2) = a#list\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list w)(*strict*)\n  prefer 2\n  apply (metis maxTermPrefix_pull_out append_Nil2 maxTermPrefix_liftA maxTermPrefix_shift)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list w)(*strict*)\n  apply(clarsimp)\n  apply(case_tac X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list w aa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list w aa)(*strict*)\n  apply(subgoal_tac \"maxTermPrefix (teA aa # liftA (ESplitItem_to (S2 ! i))) = []\")\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list w aa)(*strict*)\n   apply(subgoal_tac \"a # list @ w = []\")\n    apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list w aa)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list w aa)(*strict*)\n   apply(rule_tac\n    t=\"a # list @ w\"\n    and s=\"maxTermPrefix (teA aa # liftA (ESplitItem_to (S2 ! i)))\"\n    in ssubst)\n    apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list w aa)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list w aa)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list w aa)(*strict*)\n  apply (metis liftA.simps(2) liftA_commutes_over_concat maxTermPrefix_liftA)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list w ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list w ba)(*strict*)\n  apply(subgoal_tac \"maxTermPrefix (teB ba # liftA (ESplitItem_to (S2 ! i))) = [ba]\")\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list w ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 ba)(*strict*)\n  apply(erule_tac\n    x=\"ia\"\n    in allE)+\n  apply(clarsimp)\n  apply(simp add: get_configuration_def)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 e d ea da c ca db dc l' w2 a list w ba)(*strict*)\n  apply (metis maxTermPrefix_pull_out liftA.simps(2) liftA_commutes_over_concat maxTermPrefix_liftA)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc l' l'a)(*strict*)\n  apply(rename_tac x1 x2)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(subgoal_tac \"only_l3_nonterminals (butlast x1)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    e=\"e\"\n    and v=\"liftA x1\"\n    and \\<alpha>=\"[]\"\n    and w=\"[F1]\"\n    and d=\"dx1\"\n    and n=\"ia\"\n    in only_l3_nonterminals_butlast_preserved)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n      apply(clarsimp)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n     apply(clarsimp)\n     apply(simp add: only_l3_nonterminals_def)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 v1 v2)(*strict*)\n  apply(case_tac v1)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 v1 v2)(*strict*)\n  prefer 2\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 v1 v2 a list)(*strict*)\n  apply(case_tac x1)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 v1 v2 a list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 v1 v2 a list aa lista)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 v1 v2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 v2)(*strict*)\n  apply(subgoal_tac \"x1=v2\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 v2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 v2)(*strict*)\n  apply(rule_tac liftA_inj)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(subgoal_tac \"only_l3_nonterminals (butlast x2)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    e=\"ea\"\n    and v=\"liftA x2\"\n    and \\<alpha>=\"[]\"\n    and w=\"[F2]\"\n    and d=\"dx2\"\n    and n=\"ia\"\n    in only_l3_nonterminals_butlast_preserved)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n      apply(clarsimp)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n     apply(clarsimp)\n     apply(simp add: only_l3_nonterminals_def)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 v1 v2)(*strict*)\n  apply(case_tac v1)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 v1 v2)(*strict*)\n  prefer 2\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 v1 v2 a list)(*strict*)\n  apply(case_tac x2)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 v1 v2 a list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 v1 v2 a list aa lista)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 v1 v2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 v2)(*strict*)\n  apply(subgoal_tac \"x2=v2\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 v2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 v2)(*strict*)\n  apply(rule_tac liftA_inj)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(subgoal_tac \"length (realizable G (drop ia (ESplitItem_prods (S1 ! i)))) = length (realizable G (drop ia (ESplitItem_prods (S2 ! i))))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    ?d1.0=\"d\"\n    in realizable_length_eq)\n           apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n           apply(force)\n          apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n          apply(force)\n         apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n         apply (rule notfinishingL_drop)\n         apply(force)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n        apply (rule notfinishingL_drop)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n   apply (metis drop_map)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 p ba A)(*strict*)\n  apply(erule_tac\n    x=\"p\"\n    and A=\"set (butlast (ESplitItem_prods (S1 ! i)))\"\n    in ballE)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 p ba A)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 p ba A)(*strict*)\n  apply(subgoal_tac \"p \\<in> set (butlast (ESplitItem_prods (S1 ! i)))\")\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 p ba A)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 p ba A)(*strict*)\n  apply(rule_tac\n    A=\"set (butlast (drop ia (ESplitItem_prods (S1 ! i))))\"\n    in set_mp)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 p ba A)(*strict*)\n   apply (metis drop_butlast set_drop_subset)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 p ba A)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 p ba A)(*strict*)\n  apply(erule_tac\n    x=\"p\"\n    and A=\"set (butlast (ESplitItem_prods (S2 ! i)))\"\n    in ballE)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 p ba A)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 p ba A)(*strict*)\n  apply(subgoal_tac \"p \\<in> set (butlast (ESplitItem_prods (S2 ! i)))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 p ba A)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 p ba A)(*strict*)\n  apply(rule_tac\n    A=\"set (butlast (drop ia (ESplitItem_prods (S2 ! i))))\"\n    in set_mp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 p ba A)(*strict*)\n  apply (metis drop_butlast set_drop_subset)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 p ba A)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    ?d1.0=\"db\"\n    and ?d2.0=\"dc\"\n    in prod_to_edge_eq_implies_same_terminal_production2)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n    apply(rule notfinishingL_prefix)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n    apply(rule notfinishingL_drop)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n   apply(rule notfinishingL_prefix)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n   apply(rule notfinishingL_drop)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(rule_tac\n    t=\"drop ia (ESplitItem_prods (S1 ! i))\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n   apply(rule nth_drop2)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(rule_tac\n    t=\"drop ia (ESplitItem_prods (S2 ! i))\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n   apply(rule nth_drop2)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(simp (no_asm))\n  apply(rule same_source_edge_productions_have_similar_lhs)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n      apply(rule_tac\n    A=\"set (ESplitItem_prods (S1 ! i))\"\n    in set_mp)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n       apply(rule_tac\n    t=\"cfg_productions G\"\n    and s=\"cfg_step_labels G\"\n    in ssubst)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n        apply(simp add: cfg_step_labels_def)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n       apply(rule cfgLM.trans_der_all_step_labels)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n        apply(simp add: split_TSstructure_def)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n      apply(rule nth_mem)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n     apply(rule_tac\n    A=\"set (ESplitItem_prods (S2 ! i))\"\n    in set_mp)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n      apply(rule_tac\n    t=\"cfg_productions G\"\n    and s=\"cfg_step_labels G\"\n    in ssubst)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n       apply(simp add: cfg_step_labels_def)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n      apply(rule cfgLM.trans_der_all_step_labels)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n       apply(simp add: split_TSstructure_def)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n     apply(rule nth_mem)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n    apply(simp add: notfinishingL_def notfinishing_def)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n   apply(simp add: notfinishingL_def notfinishing_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(rule_tac\n    t=\"prod_to_edge G' ((ESplitItem_prods (S1 ! i)) ! ia)\"\n    and s=\"(map (prod_to_edge G') (ESplitItem_prods (S1 ! i)))!ia\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n   apply(metis nth_map)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(rule_tac\n    t=\"prod_to_edge G' ((ESplitItem_prods (S2 ! i)) ! ia)\"\n    and s=\"(map (prod_to_edge G') (ESplitItem_prods (S2 ! i)))!ia\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n   apply(metis nth_map)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(rule_tac\n    ?x1.0=\"(ESplitItem_prods (S1 ! i))\"\n    and ?x2.0=\"(ESplitItem_prods (S2 ! i))\"\n    in equal_by_same_length_and_equal_embedding)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 \\<alpha> v1 v2)(*strict*)\n  apply(case_tac c)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 \\<alpha> v1 v2 cfg_confa)(*strict*)\n  apply(case_tac ca)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da c ca db dc x1 x2 \\<alpha> v1 v2 cfg_confa cfg_confaa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 e d ea da db dc x1 x2 \\<alpha> v1 v2)(*strict*)\n  apply(simp add: setAConcat setBConcat setA_liftB setA_liftA setB_liftA setB_liftB)\n  apply(thin_tac \"(ia = 0) = (ea = None)\")\n  apply(rename_tac ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2)(*strict*)\n  apply(subgoal_tac \"derives G (drop ia (ESplitItem_prods (S1 ! i))) = liftB \\<alpha> @ liftA v1\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2)(*strict*)\n  prefer 2\n  apply(simp add: derives_def)\n  apply(rule_tac\n    t=\"(THE c. \\<exists>d. cfgLM.trans_der G d \\<lparr>cfg_conf = [teA (prod_lhs (hd (drop ia (ESplitItem_prods (S1 ! i)))))]\\<rparr> (realizable G (drop ia (ESplitItem_prods (S1 ! i)))) c)\"\n    and s=\"\\<lparr>cfg_conf = liftB \\<alpha> @ liftA v1\\<rparr>\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2)(*strict*)\n  apply(rule_tac\n    a=\"\\<lparr>cfg_conf = liftB \\<alpha> @ liftA v1\\<rparr>\"\n    in the_equality)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2)(*strict*)\n   apply(rule_tac\n    x=\"dz1\"\n    in exI)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2 x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2 x d)(*strict*)\n  apply(rule_tac\n    ?d1.0=\"d\"\n    and ?d2.0=\"dz1\"\n    in cfgLM_trans_der_unique_result)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2 x d)(*strict*)\n    apply(simp add: split_TSstructure_def)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2 x d)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2 x d)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2)(*strict*)\n  apply(subgoal_tac \"derives G (drop ia (ESplitItem_prods (S2 ! i))) = liftB \\<alpha> @ liftA v2\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2)(*strict*)\n  prefer 2\n  apply(simp add: derives_def)\n  apply(rule_tac\n    t=\"(THE c. \\<exists>d. cfgLM.trans_der G d \\<lparr>cfg_conf = [teA (prod_lhs (hd (drop ia (ESplitItem_prods (S2 ! i)))))]\\<rparr> (realizable G (drop ia (ESplitItem_prods (S2 ! i)))) c)\"\n    and s=\"\\<lparr>cfg_conf = liftB \\<alpha> @ liftA v2\\<rparr>\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2)(*strict*)\n  apply(rule_tac\n    a=\"\\<lparr>cfg_conf = liftB \\<alpha> @ liftA v2\\<rparr>\"\n    in the_equality)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2)(*strict*)\n   apply(rule_tac\n    x=\"dz2\"\n    in exI)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2 x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2 x d)(*strict*)\n  apply(rule_tac\n    ?d1.0=\"d\"\n    and ?d2.0=\"dz2\"\n    in cfgLM_trans_der_unique_result)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2 x d)(*strict*)\n    apply(simp add: split_TSstructure_def)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2 x d)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2 x d)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2)(*strict*)\n  apply(clarsimp)\n  apply(case_tac x1)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x2 \\<alpha> v1 v2)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x2 \\<alpha> v1 v2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    G=\"G\"\n    and d=\"dx1\"\n    and i=\"ia\"\n    and kleene_starT=\"False\"\n    and END=\"False\"\n    in cfgLM.trans_der_step_detail)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x2 \\<alpha> v1 v2)(*strict*)\n    apply(simp add: split_TSstructure_def)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x2 \\<alpha> v1 v2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x2 \\<alpha> v1 v2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x2 \\<alpha> v1 v2)(*strict*)\n  apply(simp add: cfgLM_step_relation_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x1 x2 \\<alpha> v1 v2 a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x2 \\<alpha> v1 v2 a list)(*strict*)\n  apply(rename_tac X1 x1)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x2 \\<alpha> v1 v2 X1 x1)(*strict*)\n  apply(case_tac x2)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x2 \\<alpha> v1 v2 X1 x1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1)(*strict*)\n  prefer 2\n  apply(rule_tac\n    G=\"G\"\n    and d=\"dx2\"\n    and i=\"ia\"\n    and kleene_starT=\"False\"\n    and END=\"False\"\n    in cfgLM.trans_der_step_detail)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1)(*strict*)\n    apply(simp add: split_TSstructure_def)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1)(*strict*)\n  apply(simp add: cfgLM_step_relation_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 x2 \\<alpha> v1 v2 X1 x1 a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 a list)(*strict*)\n  apply(rename_tac X2 x2)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  apply(subgoal_tac \"drop ia (ESplitItem_prods (S1 ! i)) = SSX\" for SSX)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  prefer 2\n  apply(rule nth_drop2)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  apply(subgoal_tac \"drop ia (ESplitItem_prods (S2 ! i)) = SSX\" for SSX)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  prefer 2\n  apply(rule nth_drop2)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \" (realizable G (ESplitItem_prods (S1 ! i) ! ia # drop (Suc ia) (ESplitItem_prods (S1 ! i)))) \\<noteq> []\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  prefer 2\n  apply(rule realizable_not_empty)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n   apply(simp add: split_TSstructure_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  apply(subgoal_tac \" (realizable G (ESplitItem_prods (S2 ! i) ! ia # drop (Suc ia) (ESplitItem_prods (S2 ! i)))) \\<noteq> []\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  prefer 2\n  apply(rule realizable_not_empty)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n   apply(simp add: split_TSstructure_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  apply(subgoal_tac \"X1 = prod_lhs(ESplitItem_prods (S1 ! i) ! ia)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    G=\"G\"\n    and d=\"dy1\"\n    and i=\"0\"\n    and kleene_starT=\"True\"\n    and END=\"False\"\n    in cfgLM.trans_der_step_detail)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n    apply(simp add: split_TSstructure_def)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    G=\"G\"\n    and d=\"dz1\"\n    and i=\"0\"\n    and kleene_starT=\"True\"\n    and END=\"False\"\n    in cfgLM.trans_der_step_detail)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n    apply(simp add: split_TSstructure_def)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2 e ea ci' ci'a)(*strict*)\n  apply(simp add: cfgLM_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2 e ea ci' ci'a l r la ra)(*strict*)\n  apply(case_tac l)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2 e ea ci' ci'a l r la ra)(*strict*)\n  prefer 2\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2 e ea ci' ci'a l r la ra a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2 e ea ci' ci'a l r la ra)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  apply(subgoal_tac \"X2 = prod_lhs(ESplitItem_prods (S2 ! i) ! ia)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    G=\"G\"\n    and d=\"dy2\"\n    and i=\"0\"\n    and kleene_starT=\"True\"\n    and END=\"False\"\n    in cfgLM.trans_der_step_detail)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n    apply(simp add: split_TSstructure_def)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    G=\"G\"\n    and d=\"dz2\"\n    and i=\"0\"\n    and kleene_starT=\"True\"\n    and END=\"False\"\n    in cfgLM.trans_der_step_detail)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n    apply(simp add: split_TSstructure_def)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 X2 x2 e ea ci' ci'a)(*strict*)\n  apply(simp add: cfgLM_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 X2 x2 e ea ci' ci'a l r la ra)(*strict*)\n  apply(case_tac l)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 X2 x2 e ea ci' ci'a l r la ra)(*strict*)\n  prefer 2\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 X2 x2 e ea ci' ci'a l r la ra a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 X2 x2 e ea ci' ci'a l r la ra)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 X1 x1 X2 x2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x2)(*strict*)\n  apply(rule_tac\n    xs=\"x1\"\n    in rev_cases)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x2)(*strict*)\n  apply(subgoal_tac \"False\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    d=\"dy1\"\n    and da=\"dy1\"\n    and \\<pi>'=\"(ESplitItem_prods (S1 ! i) ! ia # drop (Suc ia) (ESplitItem_prods (S1 ! i)))\"\n    in realizable_eq_from_existence)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n        apply(simp add: split_TSstructure_def)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n      apply(rule_tac\n    t=\"cfg_productions G\"\n    and s=\"cfg_step_labels G\"\n    in ssubst)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n       apply(simp add: cfg_step_labels_def)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n      apply(rule cfgLM.trans_der_all_step_labels)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n       apply(simp add: split_TSstructure_def)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n    apply(simp add: prefix_def)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<lparr>cfg_conf = X # liftA (ESplitItem_to (S1 ! i))\\<rparr> = \\<lparr>cfg_conf = liftB \\<alpha> @ liftA v1\\<rparr>\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    ?d1.0=\"dy1\"\n    and ?d2.0=\"dz1\"\n    in cfgLM_trans_der_unique_result)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n    apply(simp add: split_TSstructure_def)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n    x=\"X # liftA (ESplitItem_to (S1 ! i))\"\n    and v=\"X # liftA (restrict_newto S1 i)\"\n    in strict_prefix_contra)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n  apply(rule sym)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n  apply(thin_tac \"X # liftA (ESplitItem_to (S1 ! i)) = liftB \\<alpha> @ liftA v1\")\n  apply(clarsimp)\n  apply(subgoal_tac \"length (restrict_newto S1 i) \\<le> length (ESplitItem_to (S1 ! i))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n  apply (metis liftA_preserves_length)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2)(*strict*)\n  apply(simp (no_asm) add: restrict_newto_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x2 ys y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2 ys y)(*strict*)\n  apply(rename_tac x1 x1L)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2 x1 x1L)(*strict*)\n  apply(rule_tac\n    xs=\"x2\"\n    in rev_cases)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2 x1 x1L)(*strict*)\n  apply(subgoal_tac \"False\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2 x1 x1L)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2 x1 x1L)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n  prefer 2\n  apply(rule_tac\n    d=\"dy2\"\n    and da=\"dy2\"\n    and \\<pi>'=\"(ESplitItem_prods (S2 ! i) ! ia # drop (Suc ia) (ESplitItem_prods (S2 ! i)))\"\n    in realizable_eq_from_existence)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n        apply(simp add: split_TSstructure_def)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n      apply(rule_tac\n    t=\"cfg_productions G\"\n    and s=\"cfg_step_labels G\"\n    in ssubst)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n       apply(simp add: cfg_step_labels_def)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n      apply(rule cfgLM.trans_der_all_step_labels)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n       apply(simp add: split_TSstructure_def)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n    apply(simp add: prefix_def)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<lparr>cfg_conf = X # liftA (ESplitItem_to (S2 ! i))\\<rparr> = \\<lparr>cfg_conf = liftB \\<alpha> @ liftA v2\\<rparr>\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n  prefer 2\n  apply(rule_tac\n    ?d1.0=\"dy2\"\n    and ?d2.0=\"dz2\"\n    in cfgLM_trans_der_unique_result)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n    apply(simp add: split_TSstructure_def)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n    w=\"liftB \\<alpha> @ liftA v2\"\n    and x=\"X # liftA (ESplitItem_to (S2 ! i))\"\n    and v=\"X # liftA (restrict_newto S2 i)\"\n    in strict_prefix_contra)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n  apply(rule sym)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n  apply(thin_tac \"X # liftA (ESplitItem_to (S2 ! i)) = liftB \\<alpha> @ liftA v2\")\n  apply(clarsimp)\n  apply(rule_tac\n    t=\"restrict_newto S1 i\"\n    and s=\"restrict_newto S2 i\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n  apply(subgoal_tac \"length (restrict_newto S2 i) \\<le> length (ESplitItem_to (S2 ! i))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n  apply (metis liftA_preserves_length)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L)(*strict*)\n  apply(simp (no_asm) add: restrict_newto_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x2 x1 x1L ys y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L ys y)(*strict*)\n  apply(rename_tac x2 x2L)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L)(*strict*)\n  apply(case_tac \"ESplitItem_prods (S1 ! i) ! ia\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L prod_lhsa prod_rhsa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac X1 r1)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1)(*strict*)\n  apply(case_tac \"ESplitItem_prods (S2 ! i) ! ia\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 prod_lhsa prod_rhsa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 prod_lhs prod_rhsa)(*strict*)\n  apply(rename_tac X2 r2)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2)(*strict*)\n  apply(case_tac X1)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 X2 r2 q ba)(*strict*)\n  apply(rule only_l3_nonterminals_l2_at_front)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2)(*strict*)\n  apply(case_tac X2)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q baa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q1 ba q2 q baa)(*strict*)\n  apply(rule only_l3_nonterminals_l2_at_front)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n  prefer 2\n  apply(rule_tac\n    ?d1.0=\"dz1\"\n    and ?d2.0=\"dz2\"\n    in cropTol3l2_single_equal_of_compatible_derivations)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n    apply(rule_tac\n    x=\"ia\"\n    and ?x1.0=\"(ESplitItem_prods (S1 ! i))\"\n    and ?x2.0=\"(ESplitItem_prods (S2 ! i))\"\n    in equal_by_same_length_and_equal_embedding)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n       apply(rule_tac\n    t=\"drop ia (ESplitItem_prods (S1 ! i))\"\n    in ssubst)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n        apply(rule nth_drop2)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n      apply(rule_tac\n    t=\"drop ia (ESplitItem_prods (S2 ! i))\"\n    in ssubst)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n       apply(rule nth_drop2)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n   apply(rule notfinishingL_prefix)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n   apply(rule_tac\n    t=\"\\<lparr>prod_lhs = X1, prod_rhs = r1\\<rparr>\"\n    and s=\"ESplitItem_prods (S1 ! i) ! ia\"\n    in ssubst)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n   apply(rule_tac\n    t=\"SSX#SSY\" for SSX SSY\n    in subst)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n    apply(rule nth_drop2)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n   apply(rule notfinishingL_drop)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n  apply(rule notfinishingL_prefix)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n  apply(rule_tac\n    t=\"\\<lparr>prod_lhs = X2, prod_rhs = r2\\<rparr>\"\n    and s=\"ESplitItem_prods (S2 ! i) ! ia\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n  apply(rule_tac\n    t=\"SSX#SSY\" for SSX SSY\n    in subst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n   apply(rule nth_drop2)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n  apply(rule notfinishingL_drop)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n  apply(subgoal_tac \"q1a = q1 \\<and> ba = baa\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n  prefer 2\n  apply(simp add: cropTol3l2_single_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L X1 r1 X2 r2 q1 ba q2 q1a baa q2a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q1 q2 ba q2a)(*strict*)\n  apply(thin_tac \"cropTol3l2_single (cons_l3 q1 ba q2) = cropTol3l2_single (cons_l3 q1 ba q2a)\")\n  apply(rename_tac q q1 c q2)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(case_tac \"v1=[]\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(subgoal_tac \"v2=[]\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    ?d1.0=\"dz1\"\n    and ?d2.0=\"dz2\"\n    in compatible_derivation_reach_empty_configuration_synchronously_ext)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n    apply(rule_tac\n    x=\"ia\"\n    and ?x1.0=\"(ESplitItem_prods (S1 ! i))\"\n    and ?x2.0=\"(ESplitItem_prods (S2 ! i))\"\n    in equal_by_same_length_and_equal_embedding)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n       apply(rule_tac\n    t=\"drop ia (ESplitItem_prods (S1 ! i))\"\n    in ssubst)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n        apply(rule nth_drop2)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n      apply(rule_tac\n    t=\"drop ia (ESplitItem_prods (S2 ! i))\"\n    in ssubst)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n       apply(rule nth_drop2)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n   apply(rule notfinishingL_prefix)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n   apply(rule_tac\n    t=\"\\<lparr>prod_lhs = cons_l3 q c q1, prod_rhs = r1\\<rparr>\"\n    and s=\"ESplitItem_prods (S1 ! i) ! ia\"\n    in ssubst)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n   apply(rule_tac\n    t=\"SSX#SSY\" for SSX SSY\n    in subst)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n    apply(rule nth_drop2)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n   apply(rule notfinishingL_drop)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(rule notfinishingL_prefix)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(rule_tac\n    t=\"\\<lparr>prod_lhs = cons_l3 q c q2, prod_rhs = r2\\<rparr>\"\n    and s=\"ESplitItem_prods (S2 ! i) ! ia\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(rule_tac\n    t=\"SSX#SSY\" for SSX SSY\n    in subst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n   apply(rule nth_drop2)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(rule notfinishingL_drop)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    ?\\<pi>1'.0=\"[]\"\n    and ?\\<pi>2'.0=\"[]\"\n    and ?d1.0=\"dz1\"\n    and ?d2.0=\"dz2\"\n    in compatible_derivations_coincide_heavily)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(simp (no_asm))\n  apply(rule_tac\n    x=\"ia\"\n    and ?x1.0=\"(ESplitItem_prods (S1 ! i))\"\n    and ?x2.0=\"(ESplitItem_prods (S2 ! i))\"\n    in equal_by_same_length_and_equal_embedding)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n     apply(rule_tac\n    t=\"drop ia (ESplitItem_prods (S1 ! i))\"\n    in ssubst)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n      apply(rule nth_drop2)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n    apply(rule_tac\n    t=\"drop ia (ESplitItem_prods (S2 ! i))\"\n    in ssubst)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n     apply(rule nth_drop2)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q c q2)(*strict*)\n  apply(rename_tac q1 c q2)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n  apply(subgoal_tac \"realizable G (\\<lparr>prod_lhs = cons_l3 q1 c q2, prod_rhs = r1\\<rparr> # drop (Suc ia) (ESplitItem_prods (S1 ! i))) = realizable G (\\<lparr>prod_lhs = cons_l3 q1 c q2, prod_rhs = r2\\<rparr> # drop (Suc ia) (ESplitItem_prods (S2 ! i)))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    ?d1.0=\"dz1\"\n    and ?d2.0=\"dz2\"\n    in same_l3_source_and_same_target_liftB_and_same_prod_to_edge_implies_equal_prods)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n    apply(rule notfinishingL_prefix)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n    apply(rule_tac\n    t=\"\\<lparr>prod_lhs = cons_l3 q1 c q2, prod_rhs = r1\\<rparr>\"\n    and s=\"ESplitItem_prods (S1 ! i) ! ia\"\n    in ssubst)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n    apply(rule_tac\n    t=\"SSX#SSY\" for SSX SSY\n    in subst)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n     apply(rule nth_drop2)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n    apply(rule notfinishingL_drop)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n   apply(rule notfinishingL_prefix)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n   apply(rule_tac\n    t=\"\\<lparr>prod_lhs = cons_l3 q1 c q2, prod_rhs = r2\\<rparr>\"\n    and s=\"ESplitItem_prods (S2 ! i) ! ia\"\n    in ssubst)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n   apply(rule_tac\n    t=\"SSX#SSY\" for SSX SSY\n    in subst)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n    apply(rule nth_drop2)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n   apply(rule notfinishingL_drop)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n  apply(rule_tac\n    x=\"ia\"\n    and ?x1.0=\"(ESplitItem_prods (S1 ! i))\"\n    and ?x2.0=\"(ESplitItem_prods (S2 ! i))\"\n    in equal_by_same_length_and_equal_embedding)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n     apply(rule_tac\n    t=\"drop ia (ESplitItem_prods (S1 ! i))\"\n    in ssubst)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n      apply(rule nth_drop2)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n    apply(rule_tac\n    t=\"drop ia (ESplitItem_prods (S2 ! i))\"\n    in ssubst)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n     apply(rule nth_drop2)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2)(*strict*)\n  apply(simp add: prefix_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2 ca cb)(*strict*)\n  apply(case_tac \"realizable G (\\<lparr>prod_lhs = cons_l3 q1 c q2, prod_rhs = r1\\<rparr> # drop (Suc ia) (ESplitItem_prods (S1 ! i)))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2 ca cb)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2 ca cb a list)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"realizable G (\\<lparr>prod_lhs = cons_l3 q1 c q2, prod_rhs = r2\\<rparr> # drop (Suc ia) (ESplitItem_prods (S2 ! i)))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2 ca cb a list)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> x1 x1L x2 x2L r1 r2 q1 c q2 ca cb a list aa lista)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(case_tac \"v2=[]\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(subgoal_tac \"v1=[]\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    ?d1.0=\"dz2\"\n    and ?d2.0=\"dz1\"\n    in compatible_derivation_reach_empty_configuration_synchronously_ext)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n    apply(rule_tac\n    x=\"ia\"\n    and ?x1.0=\"(ESplitItem_prods (S2 ! i))\"\n    and ?x2.0=\"(ESplitItem_prods (S1 ! i))\"\n    in equal_by_same_length_and_equal_embedding)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n       apply(rule_tac\n    t=\"drop ia (ESplitItem_prods (S2 ! i))\"\n    in ssubst)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n        apply(rule nth_drop2)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n      apply(rule_tac\n    t=\"drop ia (ESplitItem_prods (S1 ! i))\"\n    in ssubst)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n       apply(rule nth_drop2)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n   apply(rule notfinishingL_prefix)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n   apply(rule_tac\n    t=\"\\<lparr>prod_lhs = cons_l3 q c q2, prod_rhs = r2\\<rparr>\"\n    and s=\"ESplitItem_prods (S2 ! i) ! ia\"\n    in ssubst)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n   apply(rule_tac\n    t=\"SSX#SSY\" for SSX SSY\n    in subst)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n    apply(rule nth_drop2)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n   apply(rule notfinishingL_drop)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(rule notfinishingL_prefix)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(rule_tac\n    t=\"\\<lparr>prod_lhs = cons_l3 q c q1, prod_rhs = r1\\<rparr>\"\n    and s=\"ESplitItem_prods (S1 ! i) ! ia\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(rule_tac\n    t=\"SSX#SSY\" for SSX SSY\n    in subst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n   apply(rule nth_drop2)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(rule notfinishingL_drop)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"i=length v\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw i X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(subgoal_tac \"ESplitItem_elem (S1 ! length v) = Some (teB b)\")\n  apply(rename_tac ds \\<pi>s fw i X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  prefer 2\n  apply (metis nth_append)\n  apply(rename_tac ds \\<pi>s fw i X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(case_tac \"ESplitItem_to (S1 ! length v)\")\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(subgoal_tac \"False\")\n   apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(simp add: EValidSplit_def EValidSplit_to_empty_def)\n  apply(clarsimp)\n  apply(erule_tac\n    x=\"S1!length v\"\n    and A=\"set (butlast (S1 @ S1'))\"\n    in ballE)\n   apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n   prefer 2\n   apply (metis nth_in_butlast_append)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 a list)(*strict*)\n  apply(case_tac \"ESplitItem_to (S2 ! length v)\")\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 a list)(*strict*)\n  apply(subgoal_tac \"False\")\n   apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 a list)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 a list)(*strict*)\n  apply(simp add: EValidSplit_def EValidSplit_to_empty_def)\n  apply(clarsimp)\n  apply(erule_tac\n    x=\"S2!length v\"\n    and A=\"set (butlast (S2 @ S2'))\"\n    in ballE)\n   apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 a list)(*strict*)\n   prefer 2\n   apply (metis nth_in_butlast_append)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 a list aa lista)(*strict*)\n  apply(rename_tac t1 t1s t2 t2s)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s)(*strict*)\n  apply(subgoal_tac \"restrict_newto S1 (length v) = [cropTol3l2_single (hd(ESplitItem_to (S1 ! length v)))]\")\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s)(*strict*)\n  prefer 2\n  apply(simp add: restrict_newto_def new_post_sig_def restrict_toberemovedX_def)\n  apply(rule_tac\n    t=\"(restrict_toberemoved S1 @ [tl (ESplitItem_to (last S1) @ ESplitItem_ignore (last S1))]) ! Suc (length v)\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s)(*strict*)\n   apply(rule nth_append_2)\n   apply (metis length_0_conv length_Suc length_restrict_toberemoved less_irrefl_nat less_zeroE trivNat)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s)(*strict*)\n  apply(rule_tac\n    t=\"Suc (length v) - length (restrict_toberemoved S1)\"\n    and s=\"0\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s)(*strict*)\n   apply(simp add: length_restrict_toberemoved)\n   apply (metis length_0_conv length_Suc length_restrict_toberemoved less_irrefl_nat less_zeroE trivNat)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s)(*strict*)\n  apply(clarsimp)\n  apply(simp add: drop_and_crop_def butn_def)\n  apply(rule_tac\n    t=\"last S1\"\n    and s=\"S1!length v\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s)(*strict*)\n   apply (metis length_Suc nth_last)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s)(*strict*)\n  apply(simp (no_asm) add: cropTol3l2_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s)(*strict*)\n  apply(clarsimp)\n  apply(simp add: strict_prefix_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s ca cb)(*strict*)\n  apply(rule_tac\n    xs=\"ca\"\n    in rev_cases)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s ca cb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s ca cb ys y)(*strict*)\n  apply(rule_tac\n    xs=\"cb\"\n    in rev_cases)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s ca cb ys y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s ca cb ys y ysa ya)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s ys ysa)(*strict*)\n  apply(case_tac \"v1\")\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s ys ysa)(*strict*)\n  prefer 2\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s ys ysa a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s ys ysa a list)(*strict*)\n  apply(case_tac \\<alpha>)\n   apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s ys ysa a list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s ys ysa a list aa lista)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw i F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1 t1s t2 t2s ys ysa)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(subgoal_tac \"i<length v\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  prefer 2\n  apply (metis Suc_inject Suc_lessI Suc_less_eq length_Suc)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(clarsimp)\n  apply(thin_tac \"(\\<lparr>prod_lhs = cons_l3 q c q1, prod_rhs = r1\\<rparr> # drop (Suc ia) (ESplitItem_prods (S1 ! i))) \\<sqsubseteq> (\\<lparr>prod_lhs = cons_l3 q c q1, prod_rhs = r1\\<rparr> # drop (Suc ia) (ESplitItem_prods (S1 ! i)))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(thin_tac \"(\\<lparr>prod_lhs = cons_l3 q c q2, prod_rhs = r2\\<rparr> # drop (Suc ia) (ESplitItem_prods (S2 ! i))) \\<sqsubseteq> (\\<lparr>prod_lhs = cons_l3 q c q2, prod_rhs = r2\\<rparr> # drop (Suc ia) (ESplitItem_prods (S2 ! i)))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(thin_tac \"derives G (\\<lparr>prod_lhs = cons_l3 q c q1, prod_rhs = r1\\<rparr> # drop (Suc ia) (ESplitItem_prods (S1 ! i))) = liftB \\<alpha> @ liftA v1\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(thin_tac \"derives G (\\<lparr>prod_lhs = cons_l3 q c q2, prod_rhs = r2\\<rparr> # drop (Suc ia) (ESplitItem_prods (S2 ! i))) = liftB \\<alpha> @ liftA v2\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2)(*strict*)\n  apply(simp add: strict_prefix_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 ca cb)(*strict*)\n  apply(rename_tac t1' t2')\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1' t2')(*strict*)\n  apply(rule_tac\n    xs=\"t1'\"\n    in rev_cases)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1' t2')(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1' t2' ys y)(*strict*)\n  apply(rule_tac\n    xs=\"t2'\"\n    in rev_cases)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1' t2' ys y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1' t2' ys y ysa ya)(*strict*)\n  apply(rename_tac bx1 bx1L bx2 bx2L)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 t1' t2' bx1 bx1L bx2 bx2L)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  apply(subgoal_tac \"case X of teA A \\<Rightarrow> \\<alpha> = [] | teB b \\<Rightarrow> \\<alpha>=[b]\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  prefer 2\n  apply(case_tac X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L a)(*strict*)\n  apply(case_tac \"\\<alpha>\")\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L a)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L a aa list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L ba)(*strict*)\n  apply(case_tac \"\\<alpha>\")\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L ba)(*strict*)\n  apply(case_tac v1)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L ba)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L ba a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L ba a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L ba list)(*strict*)\n  apply(case_tac list)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L ba list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L ba list a lista)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L ba a lista)(*strict*)\n  apply(case_tac \"restrict_newto S1 i\")\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L ba a lista)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L ba a lista aa list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  apply(subgoal_tac \"PValidSplit_interlineX (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! i) (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! Suc i)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"PValidSplit_interline (restrict G' G (S1 @ S1') (length (Esplit_signature S1)))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  prefer 2\n  apply(simp add: PValidSplit_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  apply(simp add: PValidSplit_interline_def)\n  apply(erule_tac\n    x=\"i\"\n    in allE)\n  apply(erule_tac\n    P=\"Suc i < length (restrict G' G (S1 @ S1') (length (Esplit_signature S1)))\"\n    in impE)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  prefer 2\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(rule_tac\n    t=\"Esplit_signature S1\"\n    and s=\"v @ [teB b]\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  apply(thin_tac \"v @ [teB b] = Esplit_signature S1\")\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  apply(subgoal_tac \"PValidSplit_interlineX (restrict G' G (S2 @ S2') (length (Esplit_signature S2)) ! i) (restrict G' G (S2 @ S2') (length (Esplit_signature S2)) ! Suc i)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"PValidSplit_interline (restrict G' G (S2 @ S2') (length (Esplit_signature S2)))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  prefer 2\n  apply(simp add: PValidSplit_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  apply(simp add: PValidSplit_interline_def)\n  apply(erule_tac\n    x=\"i\"\n    in allE)\n  apply(erule_tac\n    P=\"Suc i < length (restrict G' G (S2 @ S2') (length (Esplit_signature S1)))\"\n    in impE)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  prefer 2\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(rule_tac\n    t=\"Esplit_signature S1\"\n    and s=\"v @ [teB b]\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  apply(thin_tac \"v @ [teB b] = Esplit_signature S1\")\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  apply(simp add: PValidSplit_interlineX_def)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  prefer 2\n  apply(rule_tac\n    i=\"Suc i\"\n    and ?S1.0=\"S1\"\n    and n=\"length v\"\n    and v=\"v\"\n    and b=\"b\"\n    in e_derivation_can_be_embedded_minimally)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    prefer 2\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                   apply(force)\n                  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                  apply(force)\n                 apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                 apply(force)\n                apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                apply(force)\n               apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n               apply(force)\n              apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n              apply(force)\n             apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n             apply(force)\n            apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n            apply(force)\n           apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n           apply(force)\n          apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n          apply(force)\n         apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n         apply(force)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  prefer 2\n  apply(rule_tac\n    i=\"Suc i\"\n    and ?S1.0=\"S2\"\n    and n=\"length v\"\n    and v=\"v\"\n    and b=\"b\"\n    in e_derivation_can_be_embedded_minimally)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    prefer 2\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                    apply(force)\n                   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                   apply(force)\n                  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                  apply(force)\n                 apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                 apply(force)\n                apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n                apply(force)\n               apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n               apply(force)\n              apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n              apply(force)\n             apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n             apply(force)\n            apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n            apply(force)\n           apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n           apply(force)\n          apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n          apply(force)\n         apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n         apply(force)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L p_d p_da)(*strict*)\n  apply(rename_tac pd1 pd2)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2)(*strict*)\n  apply(erule conjE)+\n  apply(thin_tac \"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc i) \\<noteq> [] \\<longrightarrow> (\\<exists>e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 \\<alpha>1 \\<alpha>2. ESplitItem_prods ((S2 @ S2') ! Suc i) @ \\<pi>s ! Suc i @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S2 @ S2') ! x)) @ ESplitItem_prods ((S2 @ S2') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc i)) (length v))) = e_\\<pi>1 @ e_\\<pi>2 \\<and> foldl (@) [] (drop (Suc i) (take (length v) fw)) = \\<alpha>1 @ \\<alpha>2 \\<and> cfgLM.trans_der G e_d1 \\<lparr>cfg_conf = liftA (option_to_list (ESplitItem_from ((S2 @ S2') ! Suc i)) @ butlast (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc i)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc i))) (ESplitItem_ignore ((S2 @ S2') ! Suc i))))))\\<rparr> e_\\<pi>1 \\<lparr>cfg_conf = liftB \\<alpha>1\\<rparr> \\<and> cfgLM.trans_der G e_d2 \\<lparr>cfg_conf = [teA (last (fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc i)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc i))) (ESplitItem_ignore ((S2 @ S2') ! Suc i))))))]\\<rparr> e_\\<pi>2 \\<lparr>cfg_conf = liftB \\<alpha>2 @ [teB b] @ va\\<rparr>)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2)(*strict*)\n  apply(thin_tac \"PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc i) = [] \\<longrightarrow> drop (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc i))) (ESplitItem_ignore ((S2 @ S2') ! Suc i)) = ESplitItem_ignore ((S2 @ S2') ! Suc i) \\<and> (\\<exists>e_d va. cfgLM.trans_der G e_d \\<lparr>cfg_conf = liftA (option_to_list (ESplitItem_from ((S2 @ S2') ! Suc i)))\\<rparr> (ESplitItem_prods ((S2 @ S2') ! Suc i) @ \\<pi>s ! Suc i @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S2 @ S2') ! x)) @ ESplitItem_prods ((S2 @ S2') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc i)) (length v)))) \\<lparr>cfg_conf = liftB (foldl (@) [] (drop (Suc i) (take (length v) fw))) @ [teB b] @ va\\<rparr>)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2)(*strict*)\n  apply(thin_tac \"PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc i) \\<noteq> [] \\<longrightarrow> (\\<exists>e_d1 e_d2 va e_\\<pi>1 e_\\<pi>2 \\<alpha>1 \\<alpha>2. ESplitItem_prods ((S1 @ S1') ! Suc i) @ \\<pi>s ! Suc i @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S1 @ S1') ! x)) @ ESplitItem_prods ((S1 @ S1') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc i)) (length v))) = e_\\<pi>1 @ e_\\<pi>2 \\<and> foldl (@) [] (drop (Suc i) (take (length v) fw)) = \\<alpha>1 @ \\<alpha>2 \\<and> cfgLM.trans_der G e_d1 \\<lparr>cfg_conf = liftA (option_to_list (ESplitItem_from ((S1 @ S1') ! Suc i)) @ butlast (fillOptL (PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc i)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc i))) (ESplitItem_ignore ((S1 @ S1') ! Suc i))))))\\<rparr> e_\\<pi>1 \\<lparr>cfg_conf = liftB \\<alpha>1\\<rparr> \\<and> cfgLM.trans_der G e_d2 \\<lparr>cfg_conf = [teA (last (fillOptL (PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc i)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc i))) (ESplitItem_ignore ((S1 @ S1') ! Suc i))))))]\\<rparr> e_\\<pi>2 \\<lparr>cfg_conf = liftB \\<alpha>2 @ [teB b] @ va\\<rparr>)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2)(*strict*)\n  apply(thin_tac \"PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc i) = [] \\<longrightarrow> drop (length (PSplitItem_ignore (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc i))) (ESplitItem_ignore ((S1 @ S1') ! Suc i)) = ESplitItem_ignore ((S1 @ S1') ! Suc i) \\<and> (\\<exists>e_d va. cfgLM.trans_der G e_d \\<lparr>cfg_conf = liftA (option_to_list (ESplitItem_from ((S1 @ S1') ! Suc i)))\\<rparr> (ESplitItem_prods ((S1 @ S1') ! Suc i) @ \\<pi>s ! Suc i @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S1 @ S1') ! x)) @ ESplitItem_prods ((S1 @ S1') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc i)) (length v)))) \\<lparr>cfg_conf = liftB (foldl (@) [] (drop (Suc i) (take (length v) fw))) @ [teB b] @ va\\<rparr>)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2)(*strict*)\n  apply(clarsimp)\n  apply(simp add: fillWithPreContext_def)\n  apply(subgoal_tac \"\\<exists>Y1. ESplitItem_from (S1 ! Suc i)= Some Y1\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"(\\<forall>x\\<in> set (butlast (S1 @ S1')). (\\<exists>y. ESplitItem_from x = Some y) \\<and> (\\<exists>y. ESplitItem_elem x = Some y))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2)(*strict*)\n  prefer 2\n  apply(simp add: EValidSplit_def EValidSplit_producing_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2)(*strict*)\n  apply(erule_tac\n    x=\"S1!Suc i\"\n    in ballE)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"S1 ! Suc i \\<in> set (butlast (S1 @ S1'))\")\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2)(*strict*)\n  apply(thin_tac \"S1 ! Suc i \\<notin> set (butlast (S1 @ S1'))\")\n  apply(rule nth_in_butlast_append)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2)(*strict*)\n   apply (metis Suc_lessI append_Nil length_1_cons_nth length_Suc less_not_refl less_trans_Suc list.size(3) not_less_eq)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n  apply(subgoal_tac \"length S1 = Suc(length v)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n  prefer 2\n  apply (metis Suc_lessI append_Nil length_1_cons_nth length_Suc less_not_refl less_trans_Suc list.size(3) not_less_eq)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n  apply(subgoal_tac \"(S1 @ S1') ! Suc i = S1!Suc i\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n  prefer 2\n  apply(rule nth_append_1)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n  apply(subgoal_tac \"nat_seq 0 (length (Esplit_signature S1) - Suc 0) ! Suc i = SSX\" for SSX)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n  prefer 2\n  apply(rule nat_seq_nth_compute)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n  apply(subgoal_tac \"(fillOpt (PSplitItem_from (restrict G' G (S1 @ S1') (Suc (length v)) ! Suc i)) (last_back_state_if_l3_nonterminal (option_to_list (ESplitItem_from ((S1 @ S1') ! Suc i))))) = Y1\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n  prefer 2\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(simp add: option_to_list_def)\n  apply(rule fillOpt_hd_and_last_back_state)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n  apply(clarsimp)\n  apply(thin_tac \"fillOpt (PSplitItem_from (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! Suc i)) (last_back_state_if_l3_nonterminal (option_to_list (Some Y1))) = Y1\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n  apply(subgoal_tac \"\\<exists>Y2. ESplitItem_from (S2 ! Suc i)= Some Y2\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"(\\<forall>x\\<in> set (butlast (S2 @ S2')). (\\<exists>y. ESplitItem_from x = Some y) \\<and> (\\<exists>y. ESplitItem_elem x = Some y))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n  prefer 2\n  apply(simp add: EValidSplit_def EValidSplit_producing_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n  apply(erule_tac\n    x=\"S2!Suc i\"\n    in ballE)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"S2 ! Suc i \\<in> set (butlast (S2 @ S2'))\")\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n  apply(thin_tac \"S2 ! Suc i \\<notin> set (butlast (S2 @ S2'))\")\n  apply(rule nth_in_butlast_append)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n   apply (metis Suc_lessI append_Nil length_1_cons_nth length_Suc less_not_refl less_trans_Suc list.size(3) not_less_eq)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(subgoal_tac \"length S2 = Suc(length v)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  prefer 2\n  apply (metis Suc_lessI append_Nil length_1_cons_nth length_Suc less_not_refl less_trans_Suc list.size(3) not_less_eq)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(subgoal_tac \"(S2 @ S2') ! Suc i = S2!Suc i\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  prefer 2\n  apply(rule nth_append_1)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(subgoal_tac \"nat_seq 0 (length (Esplit_signature S2) - Suc 0) ! Suc i = SSX\" for SSX)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  prefer 2\n  apply(rule nat_seq_nth_compute)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(subgoal_tac \"(fillOpt (PSplitItem_from (restrict G' G (S2 @ S2') (Suc (length v)) ! Suc i)) (last_back_state_if_l3_nonterminal (option_to_list (ESplitItem_from ((S2 @ S2') ! Suc i))))) = Y2\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  prefer 2\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(simp add: option_to_list_def)\n  apply(rule fillOpt_hd_and_last_back_state)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(clarsimp)\n  apply(thin_tac \"fillOpt (PSplitItem_from (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i)) (last_back_state_if_l3_nonterminal (option_to_list (Some Y2))) = Y2\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(thin_tac \"fillOptL (PSplitItem_to (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! length v)) (last_back_state_if_l3_nonterminal (take (Suc 0) (ESplitItem_to ((S1 @ S1') ! length v)))) @ tl (ESplitItem_to ((S1 @ S1') ! length v)) @ butn (restrict_toberemoved S1 ! length v) (length (restrict_toberemoved S1 ! Suc i)) @ drop (length (PSplitItem_ignore (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S1 ! Suc i)) = ESplitItem_to ((S1 @ S1') ! length v) @ ESplitItem_ignore ((S1 @ S1') ! length v)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(thin_tac \"fillOptL (PSplitItem_to (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! length v)) (last_back_state_if_l3_nonterminal (take (Suc 0) (ESplitItem_to ((S2 @ S2') ! length v)))) @ tl (ESplitItem_to ((S2 @ S2') ! length v)) @ butn (restrict_toberemoved S2 ! length v) (length (restrict_toberemoved S2 ! Suc i)) @ drop (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S2 ! Suc i)) = ESplitItem_to ((S2 @ S2') ! length v) @ ESplitItem_ignore ((S2 @ S2') ! length v)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  prefer 2\n  apply(rule append_take_drop_id_C)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(clarsimp)\n  apply(thin_tac \"fillOptL (PSplitItem_ignore (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! Suc i)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S1 ! Suc i)))) = take (length (PSplitItem_ignore (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S1 ! Suc i))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  prefer 2\n  apply(rule append_take_drop_id_C)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(clarsimp)\n  apply(thin_tac \"fillOptL (PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i)) (last_back_state_if_l3_nonterminal (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S2 ! Suc i)))) = take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S2 ! Suc i))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(subgoal_tac \"length v1=length v2\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  prefer 2\n  apply(unfold cfgLM.trans_der_def)[1]\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 e ea eb ec ed ee)(*strict*)\n  apply(erule conjE)+\n  apply(rule_tac\n    ?x1.0=\"[]\"\n    and ?x2.0=\"[]\"\n    and n=\"length(\\<lparr>prod_lhs = cons_l3 q c q1, prod_rhs = r1\\<rparr> # drop (Suc ia) (ESplitItem_prods (S1 ! i)))\"\n    and ?v1.0=\"\\<alpha>\"\n    and ?v2.0=\"\\<alpha>\"\n    and ?w1.0=\"v1\"\n    and ?w2.0=\"v2\"\n    and q=\"q\"\n    and A=\"c\"\n    and ?q1.0=\"q1\"\n    and ?q2.0=\"q2\"\n    and G=\"G'\"\n    and G'=\"G\"\n    and ?d1.0=\"dz1\"\n    and ?d2.0=\"dz2\"\n    in cfgLM_positions_remain_compatible_l3l3)\n                apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 e ea eb ec ed ee)(*strict*)\n                apply(simp add: F2LR1inputx_def split_TSstructure_def)\n               apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 e ea eb ec ed ee)(*strict*)\n               apply(simp add: F2LR1inputx_def split_TSstructure_def)\n              apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 e ea eb ec ed ee)(*strict*)\n              apply(simp add: F2LR1inputx_def split_TSstructure_def)\n             apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 e ea eb ec ed ee)(*strict*)\n             apply(simp add: F2LR1inputx_def split_TSstructure_def)\n            apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 e ea eb ec ed ee)(*strict*)\n            apply(simp add: F2LR1inputx_def split_TSstructure_def)\n           apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 e ea eb ec ed ee)(*strict*)\n           apply(simp add: F2LR1inputx_def split_TSstructure_def)\n          apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 e ea eb ec ed ee)(*strict*)\n          apply(force)\n         apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 e ea eb ec ed ee)(*strict*)\n         apply(force)\n        apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 e ea eb ec ed ee)(*strict*)\n        apply(force)\n       apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 e ea eb ec ed ee)(*strict*)\n       apply(force)\n      apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 e ea eb ec ed ee)(*strict*)\n      apply(force)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 e ea eb ec ed ee)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 e ea eb ec ed ee)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 e ea eb ec ed ee)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 e ea eb ec ed ee)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(subgoal_tac \"ESplitItem_elim (S1 ! Suc i) @ hd (cropTol3l2 (Y1 # restrict_newignore S1 (Suc i))) # restrict_newignore S1 (Suc i) = restrict_newto S1 i\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    P=\"\\<lambda>X. X\"\n    and s=\"PSplitItem_elim (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! Suc i) @ PSplitItem_from (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! Suc i) # PSplitItem_ignore (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! Suc i) = PSplitItem_to (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i) @ PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i)\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(thin_tac \"PSplitItem_elim (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! Suc i) @ PSplitItem_from (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! Suc i) # PSplitItem_ignore (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! Suc i) = PSplitItem_to (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i) @ PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(subgoal_tac \"ESplitItem_elim (S2 ! Suc i) @ hd (cropTol3l2 (Y2 # restrict_newignore S2 (Suc i))) # restrict_newignore S2 (Suc i) = restrict_newto S2 i\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    P=\"\\<lambda>X. X\"\n    and s=\"PSplitItem_elim (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i) @ PSplitItem_from (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i) # PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i) = PSplitItem_to (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i) @ PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i)\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(thin_tac \"PSplitItem_elim (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i) @ PSplitItem_from (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i) # PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i) = PSplitItem_to (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i) @ PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! i)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(subgoal_tac \"restrictX G' [(restrict G' G (S1 @ S1') (length (Esplit_signature S1)))!(Suc i)] = restrictX G' [(restrict G' G (S2 @ S2') (length (Esplit_signature S2)))!(Suc i)]\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    t=\"restrictX G' [(restrict G' G (S1 @ S1') (length (Esplit_signature S1)))!(Suc i)]\"\n    and s=\"[(restrictX G' (restrict G' G (S1 @ S1') (length (Esplit_signature S1)))) !(Suc i)]\"\n    in subst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(simp (no_asm) add: restrictX_def)\n  apply(rule_tac\n    t=\"map (\\<lambda>I. I\\<lparr>PSplitItem_prods := map (case_DT_two_elements teA (\\<lambda>p. teA (prod_to_edge G' p))) (PSplitItem_prods I)\\<rparr>) (restrict G' G (S1 @ S1') (length (Esplit_signature S1))) ! (Suc i)\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n   apply(rule nth_map)\n   apply(clarsimp)\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(subgoal_tac \"length (nat_seq 0 (length (Esplit_signature S1) - Suc 0)) = SSx\" for SSx)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n   prefer 2\n   apply(rule nat_seq_length_prime)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(rule_tac\n    t=\"restrictX G' [(restrict G' G (S2 @ S2') (length (Esplit_signature S2)))!(Suc i)]\"\n    and s=\"[(restrictX G' (restrict G' G (S2 @ S2') (length (Esplit_signature S2)))) !(Suc i)]\"\n    in subst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(simp (no_asm) add: restrictX_def)\n  apply(rule_tac\n    t=\"map (\\<lambda>I. I\\<lparr>PSplitItem_prods := map (case_DT_two_elements teA (\\<lambda>p. teA (prod_to_edge G' p))) (PSplitItem_prods I)\\<rparr>) (restrict G' G (S2 @ S2') (length (Esplit_signature S2))) ! (Suc i)\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n   apply(rule nth_map)\n   apply(clarsimp)\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(subgoal_tac \"length (nat_seq 0 (length (Esplit_signature S2) - Suc 0)) = SSx\" for SSx)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n   prefer 2\n   apply(rule nat_seq_length_prime)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"PSplitItem_from (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! (Suc i)) = PSplitItem_from (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! (Suc i))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  prefer 2\n  apply(case_tac \"restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! (Suc i)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 PSplitItem_elima PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prodsa PSplitItem_prods PSplitItem_elema PSplitItem_toa)(*strict*)\n  apply(case_tac \"restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! (Suc i)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 PSplitItem_elima PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prodsa PSplitItem_prods PSplitItem_elema PSplitItem_toa PSplitItem_elimaa PSplitItem_fromaa PSplitItem_ignoreaa PSplitItem_elim_prodsaa PSplitItem_prodsa PSplitItem_elemaa PSplitItem_toaa)(*strict*)\n  apply(clarsimp)\n  apply(simp add: restrictX_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(subgoal_tac \"PSplitItem_ignore (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! (Suc i)) = PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! (Suc i))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  prefer 2\n  apply(case_tac \"restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! (Suc i)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 PSplitItem_elima PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prodsa PSplitItem_prods PSplitItem_elema PSplitItem_toa)(*strict*)\n  apply(case_tac \"restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! (Suc i)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 PSplitItem_elima PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prodsa PSplitItem_prods PSplitItem_elema PSplitItem_toa PSplitItem_elimaa PSplitItem_fromaa PSplitItem_ignoreaa PSplitItem_elim_prodsaa PSplitItem_prodsa PSplitItem_elemaa PSplitItem_toaa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 PSplitItem_elima PSplitItem_ignorea PSplitItem_elim_prodsa PSplitItem_prods PSplitItem_elema PSplitItem_toa PSplitItem_elimaa PSplitItem_froma PSplitItem_ignoreaa PSplitItem_elim_prodsaa PSplitItem_prodsa PSplitItem_elemaa PSplitItem_toaa)(*strict*)\n  apply(simp add: restrictX_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(subgoal_tac \"PSplitItem_elim (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! (Suc i)) = PSplitItem_elim (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! (Suc i))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  prefer 2\n  apply(case_tac \"restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! (Suc i)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 PSplitItem_elima PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prodsa PSplitItem_prods PSplitItem_elema PSplitItem_toa)(*strict*)\n  apply(case_tac \"restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! (Suc i)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 PSplitItem_elima PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prodsa PSplitItem_prods PSplitItem_elema PSplitItem_toa PSplitItem_elimaa PSplitItem_fromaa PSplitItem_ignoreaa PSplitItem_elim_prodsaa PSplitItem_prodsa PSplitItem_elemaa PSplitItem_toaa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 PSplitItem_elima PSplitItem_elim_prodsa PSplitItem_prods PSplitItem_elema PSplitItem_toa PSplitItem_elimaa PSplitItem_froma PSplitItem_ignorea PSplitItem_elim_prodsaa PSplitItem_prodsa PSplitItem_elemaa PSplitItem_toaa)(*strict*)\n  apply(simp add: restrictX_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(subgoal_tac \"ESplitItem_elim (S1 ! Suc i) = ESplitItem_elim (S2 ! Suc i)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    t=\"ESplitItem_elim (S1 ! Suc i)\"\n    and s=\"PSplitItem_elim (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! Suc i)\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(rule_tac\n    t=\"ESplitItem_elim (S2 ! Suc i)\"\n    and s=\"PSplitItem_elim (restrict G' G (S2 @ S2') (length (Esplit_signature S2)) ! Suc i)\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"EValidSplitItem_elim G (S1 ! Suc i)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"EValidSplitItem G (S1!Suc i)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"EValidSplit_ValidItem G (S1 @ S1')\")\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n   prefer 2\n   apply(simp add: EValidSplit_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(simp add: EValidSplit_ValidItem_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(simp add: EValidSplitItem_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(simp add: EValidSplitItem_elim_def)\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  prefer 2\n  apply(rule elim_map_to_trans_der)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n    prefer 4\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n   apply(simp add: F2LR1inputx_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(thin_tac \"elim_map G (ESplitItem_elim (S2 ! Suc i)) (ESplitItem_elim_prods (S1 ! Suc i)) (map (\\<lambda>x. []) (ESplitItem_elim_prods (S1 ! Suc i)))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2)(*strict*)\n  apply(erule exE)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 d)(*strict*)\n  apply(rename_tac delim)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n  prefer 2\n  apply(rule_tac\n    ?d1.0=\"delim\"\n    and ?d2.0=\"pd1\"\n    in cfgLMMIP_and_cfgLM_trans_der_append)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n  prefer 2\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n  apply(subgoal_tac \"(S1 @ S1') ! length v = S1!length v\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n  prefer 2\n  apply(rule nth_append_1)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n  apply(subgoal_tac \"ESplitItem_prods (S1 ! length v)\\<noteq>[]\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"EValidSplitItem_gen G ((S1@S1') ! (length v))\")\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n   prefer 2\n   apply(simp add: EValidSplit_def EValidSplit_ValidItem_def EValidSplitItem_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n  apply(simp add: EValidSplitItem_gen_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim d)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim d)(*strict*)\n   prefer 2\n   apply(rule cfgLM.trans_der_equal_conf_if_empty_prods)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim d)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"ESplitItem_from (S1 ! length v)\")\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim d)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim d a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n  apply(case_tac \"Suc(Suc i)\\<le>length v\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n  apply(subgoal_tac \"foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S1 @ S1') ! x)) @ ESplitItem_prods ((S1 @ S1') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc i)) (length v))) \\<noteq> []\")\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n   prefer 2\n   apply(rule_tac\n    n=\"Suc (Suc i)\"\n    and m=\"length v\"\n    in nat_seq_drop_last2)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim w)(*strict*)\n  apply(rule_tac\n    v=\"w\"\n    and n=\"length v\"\n    in foldl_map_not_empty_by_last)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim w)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim w)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n  apply(subgoal_tac \"length v= Suc i\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n  prefer 2\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n  apply(thin_tac \"cfgLMMIP G pd1 (teA Y1 # liftA (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S1 ! Suc i)))) (ESplitItem_prods (S1 ! Suc i) @ \\<pi>s ! Suc i @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S1 @ S1') ! x)) @ ESplitItem_prods ((S1 @ S1') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc i)) (length v)))) (liftB (foldl (@) [] (drop (Suc i) (take (length v) fw)) @ [b])) (liftA (fillOptL (PSplitItem_to (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! length v)) (last_back_state_if_l3_nonterminal (take (Suc 0) (ESplitItem_to ((S1 @ S1') ! length v)))) @ tl (ESplitItem_to ((S1 @ S1') ! length v)) @ butn (restrict_toberemoved S1 ! length v) (length (restrict_toberemoved S1 ! Suc i))))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd1 pd2 Y1 Y2 delim d)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim d)(*strict*)\n  apply(rename_tac pd1)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n  prefer 2\n  apply(rule_tac\n    ?d1.0=\"delim\"\n    and ?d2.0=\"pd2\"\n    in cfgLMMIP_and_cfgLM_trans_der_append)\n     apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n     apply(force)\n    apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n    apply(force)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n  prefer 2\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n  apply(subgoal_tac \"(S2 @ S2') ! length v = S2!length v\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n  prefer 2\n  apply(rule nth_append_1)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n  apply(subgoal_tac \"ESplitItem_prods (S2 ! length v)\\<noteq>[]\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"EValidSplitItem_gen G ((S2@S2') ! (length v))\")\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n   prefer 2\n   apply(simp add: EValidSplit_def EValidSplit_ValidItem_def EValidSplitItem_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n  apply(simp add: EValidSplitItem_gen_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1 d)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1 d)(*strict*)\n   prefer 2\n   apply(rule cfgLM.trans_der_equal_conf_if_empty_prods)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1 d)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"ESplitItem_from (S2 ! length v)\")\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1 d)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1 d a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n  apply(case_tac \"Suc(Suc i)\\<le>length v\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n  apply(subgoal_tac \"foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S2 @ S2') ! x)) @ ESplitItem_prods ((S2 @ S2') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc i)) (length v))) \\<noteq> []\")\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n   prefer 2\n   apply(rule_tac\n    n=\"Suc (Suc i)\"\n    and m=\"length v\"\n    in nat_seq_drop_last2)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1 w)(*strict*)\n  apply(rule_tac\n    v=\"w\"\n    and n=\"length v\"\n    in foldl_map_not_empty_by_last)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1 w)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1 w)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n  apply(subgoal_tac \"length v= Suc i\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n  prefer 2\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n  apply(thin_tac \"cfgLMMIP G pd2 (teA Y2 # liftA (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S2 ! Suc i)))) (ESplitItem_prods (S2 ! Suc i) @ \\<pi>s ! Suc i @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S2 @ S2') ! x)) @ ESplitItem_prods ((S2 @ S2') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc i)) (length v)))) (liftB (foldl (@) [] (drop (Suc i) (take (length v) fw)) @ [b])) (liftA (fillOptL (PSplitItem_to (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! length v)) (last_back_state_if_l3_nonterminal (take (Suc 0) (ESplitItem_to ((S2 @ S2') ! length v)))) @ tl (ESplitItem_to ((S2 @ S2') ! length v)) @ butn (restrict_toberemoved S2 ! length v) (length (restrict_toberemoved S2 ! Suc i))))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L pd2 Y1 Y2 delim pd1 d)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L Y1 Y2 delim pd1 d)(*strict*)\n  apply(rename_tac pd2)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L Y1 Y2 delim pd1 pd2)(*strict*)\n  apply(rule_tac\n    xs=\"restrict_newto S1 i\"\n    in rev_cases)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L Y1 Y2 delim pd1 pd2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L Y1 Y2 delim pd1 pd2 ys y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nts ntL)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx1L bx2 bx2L Y1 Y2 delim pd1 pd2 nts ntL)(*strict*)\n  apply (simp add:liftA_commutes_over_concat)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL)(*strict*)\n  apply(subgoal_tac \"restrict_newignore S1 (Suc i) = PSplitItem_ignore (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! Suc i)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL)(*strict*)\n  prefer 2\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL)(*strict*)\n  apply(subgoal_tac \"restrict_newignore S2 (Suc i) = PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S2)) ! Suc i)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL)(*strict*)\n  prefer 2\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL)(*strict*)\n  apply(subgoal_tac \"restrict_newignore S1 (Suc i) = restrict_newignore S2 (Suc i)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL)(*strict*)\n  prefer 2\n  apply(rule_tac\n    t=\"restrict_newignore S1 (Suc i)\"\n    and s=\"PSplitItem_ignore (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! Suc i)\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL)(*strict*)\n  apply(rule_tac\n    t=\"restrict_newignore S2 (Suc i)\"\n    and s=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S2)) ! Suc i)\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL)(*strict*)\n  apply(rule_tac\n    xs=\" (ESplitItem_elim (S2 ! Suc i)) @ Y1 # (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S1 ! Suc i)))\"\n    in rev_cases)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys y)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys y)(*strict*)\n  prefer 2\n  apply(rule_tac\n    \\<alpha>'=\"[]\"\n    and w=\"ys\"\n    and A=\"y\"\n    and d=\"pd1\"\n    and \\<alpha>=\"foldl (@) [] (drop (Suc i) (take (length v) fw))\"\n    and b=\"b\"\n    and v=\" (fillOptL (PSplitItem_to (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! length v)) (last_back_state_if_l3_nonterminal (take (Suc 0) (ESplitItem_to ((S1 @ S1') ! length v))))) @ (tl (ESplitItem_to ((S1 @ S1') ! length v))) @ (butn (restrict_toberemoved S1 ! length v) (length (restrict_toberemoved S1 ! Suc i)))\"\n    in cfgLMMIP_decompose_into_trans_der_and_cfgLMMIP)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys y)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys y)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys y)(*strict*)\n  apply(rule_tac\n    t=\"liftB [] @ liftA (ys @ [y])\"\n    and s=\"liftA (ESplitItem_elim (S2 ! Suc i)) @ teA Y1 # liftA (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S1 ! Suc i)))\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys y)(*strict*)\n  apply(rule_tac\n    t=\"ys@[y]\"\n    and s=\"ESplitItem_elim (S2 ! Suc i) @ Y1 # take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S1 ! Suc i))\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys y)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys y)(*strict*)\n  apply(thin_tac \"ESplitItem_elim (S2 ! Suc i) @Y1 # take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S1 ! Suc i)) = ys @ [y]\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys y)(*strict*)\n  apply (simp add:liftA_commutes_over_concat)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys y)(*strict*)\n  apply (simp add:liftA_commutes_over_concat)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys y)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys y \\<pi>1 \\<pi>2 \\<alpha>1 \\<alpha>2 d1a d2a)(*strict*)\n  apply(rename_tac ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a)(*strict*)\n  apply(erule conjE)+\n  apply(thin_tac \"cfgLMMIP G d12a [teA y1] \\<pi>12 (liftB (\\<alpha>12 @ [b])) (liftA (fillOptL (PSplitItem_to (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! length v)) (last_back_state_if_l3_nonterminal (take (Suc 0) (ESplitItem_to ((S1 @ S1') ! length v)))) @ tl (ESplitItem_to ((S1 @ S1') ! length v)) @ butn (restrict_toberemoved S1 ! length v) (length (restrict_toberemoved S1 ! Suc i))))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a)(*strict*)\n  apply(thin_tac \"cfgLMMIP G pd1 (liftA (ESplitItem_elim (S2 ! Suc i)) @ teA Y1 # liftA (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S1 ! Suc i)))) (foldl (@) [] (ESplitItem_elim_prods (S1 ! Suc i)) @ ESplitItem_prods (S1 ! Suc i) @ \\<pi>s ! Suc i @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S1 @ S1') ! x)) @ ESplitItem_prods ((S1 @ S1') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc i)) (length v)))) (liftB (foldl (@) [] (drop (Suc i) (take (length v) fw)) @ [b])) (liftA (fillOptL (PSplitItem_to (restrict G' G (S1 @ S1') (length (Esplit_signature S1)) ! length v)) (last_back_state_if_l3_nonterminal (take (Suc 0) (ESplitItem_to ((S1 @ S1') ! length v))))) @ liftA (tl (ESplitItem_to ((S1 @ S1') ! length v))) @ liftA (butn (restrict_toberemoved S1 ! length v) (length (restrict_toberemoved S1 ! Suc i))))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a)(*strict*)\n  apply(rule_tac\n    xs=\" (ESplitItem_elim (S2 ! Suc i)) @ Y2 # (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S2 ! Suc i)))\"\n    in rev_cases)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys y)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys y)(*strict*)\n  prefer 2\n  apply(rule_tac\n    \\<alpha>'=\"[]\"\n    and w=\"ys\"\n    and A=\"y\"\n    and d=\"pd2\"\n    and \\<alpha>=\"foldl (@) [] (drop (Suc i) (take (length v) fw))\"\n    and b=\"b\"\n    and v=\" (fillOptL (PSplitItem_to (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! length v)) (last_back_state_if_l3_nonterminal (take (Suc 0) (ESplitItem_to ((S2 @ S2') ! length v))))) @ (tl (ESplitItem_to ((S2 @ S2') ! length v))) @ (butn (restrict_toberemoved S2 ! length v) (length (restrict_toberemoved S2 ! Suc i)))\"\n    in cfgLMMIP_decompose_into_trans_der_and_cfgLMMIP)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys y)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys y)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys y)(*strict*)\n  apply(rule_tac\n    t=\"liftB [] @ liftA (ys @ [y])\"\n    and s=\"liftA (ESplitItem_elim (S2 ! Suc i)) @ teA Y2 # liftA (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S2 ! Suc i)))\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys y)(*strict*)\n  apply(rule_tac\n    t=\"ys@[y]\"\n    and s=\"ESplitItem_elim (S2 ! Suc i) @ Y2 # take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S2 ! Suc i))\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys y)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys y)(*strict*)\n  apply(thin_tac \"ESplitItem_elim (S2 ! Suc i) @ Y2 # take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S2 ! Suc i)) = ys @ [y]\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys y)(*strict*)\n  apply (simp add:liftA_commutes_over_concat)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys y)(*strict*)\n  apply (simp add:liftA_commutes_over_concat)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys y)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys y \\<pi>1 \\<pi>2 \\<alpha>1 \\<alpha>2 d1a d2a)(*strict*)\n  apply(rename_tac ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(erule conjE)+\n  apply(thin_tac \"cfgLMMIP G d22a [teA y2] \\<pi>22 (liftB (\\<alpha>22 @ [b])) (liftA (fillOptL (PSplitItem_to (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! length v)) (last_back_state_if_l3_nonterminal (take (Suc 0) (ESplitItem_to ((S2 @ S2') ! length v)))) @ tl (ESplitItem_to ((S2 @ S2') ! length v)) @ butn (restrict_toberemoved S2 ! length v) (length (restrict_toberemoved S2 ! Suc i))))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(thin_tac \"cfgLMMIP G pd2 (liftA (ESplitItem_elim (S2 ! Suc i)) @ teA Y2 # liftA (take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S2 ! Suc i)))) (foldl (@) [] (ESplitItem_elim_prods (S1 ! Suc i)) @ ESplitItem_prods (S2 ! Suc i) @ \\<pi>s ! Suc i @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S2 @ S2') ! x)) @ ESplitItem_prods ((S2 @ S2') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc i)) (length v)))) (liftB (foldl (@) [] (drop (Suc i) (take (length v) fw)) @ [b])) (liftA (fillOptL (PSplitItem_to (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! length v)) (last_back_state_if_l3_nonterminal (take (Suc 0) (ESplitItem_to ((S2 @ S2') ! length v))))) @ liftA (tl (ESplitItem_to ((S2 @ S2') ! length v))) @ liftA (butn (restrict_toberemoved S2 ! length v) (length (restrict_toberemoved S2 ! Suc i))))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(subgoal_tac \"prefix nts ys1\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  prefer 2\n  apply(rule_tac\n    A=\"ntL\"\n    and B=\"y1\"\n    in butlast_preserves_prefix_1)\n  apply(rule_tac\n    t=\"nts @ [ntL]\"\n    and s=\"ESplitItem_elim (S1 ! Suc i) @ hd (cropTol3l2 (Y1 # restrict_newignore S1 (Suc i))) # restrict_newignore S1 (Suc i)\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(rule_tac\n    t=\"ys1@[y1]\"\n    and s=\"ESplitItem_elim (S2 ! Suc i) @ Y1 # take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S1 ! Suc i))\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(rule prefix_butlast_drop)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(rule_tac\n    t=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i)\"\n    and s=\"restrict_newignore S1 (Suc i)\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(rule_tac\n    xs=\"restrict_newignore S1 (Suc i)\"\n    in rev_cases)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 delim y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a)(*strict*)\n  apply(simp add: prefix_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  apply(rule_tac\n    t=\"butlast (hd (cropTol3l2 (Y1 # restrict_newignore S1 (Suc i))) # restrict_newignore S1 (Suc i))\"\n    and s=\"Y1#ys\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  apply(rule_tac\n    t=\"restrict_newignore S1 (Suc i)\"\n    and s=\"ys@[y]\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  apply(thin_tac \"restrict_newignore S1 (Suc i) = ys @ [y]\")\n  apply(rule_tac\n    t=\"butlast SSX\" for SSX\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n   apply(rule_tac\n    w=\"hd (cropTol3l2 (Y1 # ys @ [y])) # ys\"\n    in butlast_direct)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  apply(simp add: cropTol3l2_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  apply(rule_tac\n    t=\"restrict_newignore S1 (Suc i)\"\n    and s=\"ys@[y]\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  prefer 2\n  apply(rule_tac\n    S=\"S1\"\n    and x=\"Suc i\"\n    in restrict_newignore_prefix_of_ESplitItem_ignore_butlast)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  prefer 2\n  apply(rule_tac\n    S=\"S1\"\n    and i=\"Suc i\"\n    in restrict_newignore_shorter_than_ESplitItem_ignore)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  apply(rule_tac\n    xs=\"ESplitItem_ignore (S1 ! Suc i)\"\n    in rev_cases)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n  apply(subgoal_tac \"prefix ys ysa\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n  prefer 2\n  apply(rule_tac\n    t=\"ys\"\n    and s=\"butlast(ys@[y])\"\n    in subst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n   apply(rule butlast_direct)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n  apply(rule_tac\n    t=\"ysa\"\n    and s=\"butlast(ysa@[ya])\"\n    in subst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n   apply(rule butlast_direct)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n  apply(rule_tac\n    t=\"ys@[y]\"\n    and s=\"restrict_newignore S1 (Suc i)\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n  apply(rule_tac\n    t=\"ysa@[ya]\"\n    and s=\"ESplitItem_ignore (S1 ! Suc i)\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. ys@w=ysa\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n  prefer 2\n  apply(simp add: prefix_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya w)(*strict*)\n  apply(rule_tac\n    t=\"ESplitItem_ignore (S1 ! Suc i)\"\n    and s=\"ys@w@[ya]\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya w)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya w)(*strict*)\n  apply(case_tac w)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya w)(*strict*)\n  apply(rule_tac\n    t=\"w\"\n    and s=\"[]\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya w)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya w)(*strict*)\n  apply(simp (no_asm))\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a ys y ysa ya w)(*strict*)\n  apply(simp (no_asm) add: prefix_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya w a list)(*strict*)\n  apply(rule_tac\n    t=\"w\"\n    and s=\"a#list\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya w a list)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya w a list)(*strict*)\n  apply(simp (no_asm))\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a ys y ysa ya w a list)(*strict*)\n  apply(simp (no_asm) add: prefix_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(subgoal_tac \"prefix nts ys2\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  prefer 2\n  apply(rule_tac\n    A=\"ntL\"\n    and B=\"y2\"\n    in butlast_preserves_prefix_1)\n  apply(rule_tac\n    t=\"nts @ [ntL]\"\n    and s=\"ESplitItem_elim (S2 ! Suc i) @ hd (cropTol3l2 (Y2 # restrict_newignore S2 (Suc i))) # restrict_newignore S2 (Suc i)\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(rule_tac\n    t=\"ys2@[y2]\"\n    and s=\"ESplitItem_elim (S2 ! Suc i) @ Y2 # take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S2)) ! Suc i))) (ESplitItem_ignore (S2 ! Suc i))\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(rule prefix_butlast_drop)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(rule_tac\n    t=\"PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S2)) ! Suc i)\"\n    and s=\"restrict_newignore S2 (Suc i)\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(rule_tac\n    xs=\"restrict_newignore S2 (Suc i)\"\n    in rev_cases)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 delim y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a)(*strict*)\n  apply(simp add: prefix_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  apply(rule_tac\n    t=\"butlast (hd (cropTol3l2 (Y2 # restrict_newignore S2 (Suc i))) # restrict_newignore S2 (Suc i))\"\n    and s=\"Y2#ys\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  apply(rule_tac\n    t=\"restrict_newignore S2 (Suc i)\"\n    and s=\"ys@[y]\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  apply(thin_tac \"restrict_newignore S2 (Suc i) = ys @ [y]\")\n  apply(rule_tac\n    t=\"butlast SSX\" for SSX\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n   apply(rule_tac\n    w=\"hd (cropTol3l2 (Y2 # ys @ [y])) # ys\"\n    in butlast_direct)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  apply(simp add: cropTol3l2_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  apply(rule_tac\n    t=\"restrict_newignore S2 (Suc i)\"\n    and s=\"ys@[y]\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  prefer 2\n  apply(rule_tac\n    S=\"S2\"\n    and x=\"Suc i\"\n    in restrict_newignore_prefix_of_ESplitItem_ignore_butlast)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  prefer 2\n  apply(rule_tac\n    S=\"S2\"\n    and i=\"Suc i\"\n    in restrict_newignore_shorter_than_ESplitItem_ignore)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  apply(rule_tac\n    xs=\"ESplitItem_ignore (S2 ! Suc i)\"\n    in rev_cases)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n  apply(subgoal_tac \"prefix ys ysa\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n  prefer 2\n  apply(rule_tac\n    t=\"ys\"\n    and s=\"butlast(ys@[y])\"\n    in subst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n   apply(rule butlast_direct)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n  apply(rule_tac\n    t=\"ysa\"\n    and s=\"butlast(ysa@[ya])\"\n    in subst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n   apply(rule butlast_direct)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n  apply(rule_tac\n    t=\"ys@[y]\"\n    and s=\"restrict_newignore S2 (Suc i)\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n  apply(rule_tac\n    t=\"ysa@[ya]\"\n    and s=\"ESplitItem_ignore (S2 ! Suc i)\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. ys@w=ysa\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n  prefer 2\n  apply(simp add: prefix_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya w)(*strict*)\n  apply(rule_tac\n    t=\"ESplitItem_ignore (S2 ! Suc i)\"\n    and s=\"ys@w@[ya]\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya w)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya w)(*strict*)\n  apply(case_tac w)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya w)(*strict*)\n  apply(rule_tac\n    t=\"w\"\n    and s=\"[]\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya w)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya w)(*strict*)\n  apply(simp (no_asm))\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a ys y ysa ya w)(*strict*)\n  apply(simp (no_asm) add: prefix_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya w a list)(*strict*)\n  apply(rule_tac\n    t=\"w\"\n    and s=\"a#list\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya w a list)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys y ysa ya w a list)(*strict*)\n  apply(simp (no_asm))\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a ys y ysa ya w a list)(*strict*)\n  apply(simp (no_asm) add: prefix_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(subgoal_tac \"\\<exists>ys1'. nts@ys1'=ys1\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  prefer 2\n  apply(simp add: prefix_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(subgoal_tac \"\\<exists>ys2'. nts@ys2'=ys2\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  prefer 2\n  apply(simp add: prefix_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2')(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2')(*strict*)\n  prefer 2\n  apply(rule_tac\n    G=\"G\"\n    and d=\"d11a\"\n    and ?w1.0=\"liftA nts\"\n    and ?w2.0=\"liftA ys1'\"\n    in cfgLM_trans_der_cfgLM_derivation_can_be_decomposed)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2')(*strict*)\n  apply(simp add: split_TSstructure_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2')(*strict*)\n  apply(rule_tac\n    t=\"liftA nts @ liftA ys1'\"\n    and s=\"liftA ys1\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2')(*strict*)\n  apply(rule_tac\n    t=\"ys1\"\n    and s=\"nts@ys1'\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2')(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2')(*strict*)\n  apply (simp (no_asm) add:liftA_commutes_over_concat)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2')(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2')(*strict*)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2' d1a d2a \\<pi>1 \\<pi>2 \\<alpha>1 \\<alpha>2)(*strict*)\n  apply(erule conjE)+\n  apply(rename_tac d1c d1d \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2' d1c d1d \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d)(*strict*)\n  apply(thin_tac \"cfgLM.trans_der G d1d \\<lparr>cfg_conf = liftA ys1'\\<rparr> \\<pi>1d \\<lparr>cfg_conf = liftB \\<alpha>1d\\<rparr>\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2' d1c d1d \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d)(*strict*)\n  apply(thin_tac \"cfgLM.trans_der G d11a \\<lparr>cfg_conf = liftA ys1\\<rparr> \\<pi>11 \\<lparr>cfg_conf = liftB \\<alpha>11\\<rparr>\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2' d1c d1d \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2' d1c d1d \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d)(*strict*)\n  prefer 2\n  apply(rule_tac\n    G=\"G\"\n    and d=\"d21a\"\n    and ?w1.0=\"liftA nts\"\n    and ?w2.0=\"liftA ys2'\"\n    in cfgLM_trans_der_cfgLM_derivation_can_be_decomposed)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2' d1c d1d \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d)(*strict*)\n  apply(simp add: split_TSstructure_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2' d1c d1d \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d)(*strict*)\n  apply(rule_tac\n    t=\"liftA nts @ liftA ys2'\"\n    and s=\"liftA ys2\"\n    in ssubst)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2' d1c d1d \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d)(*strict*)\n  apply(rule_tac\n    t=\"ys2\"\n    and s=\"nts@ys2'\"\n    in ssubst)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2' d1c d1d \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2' d1c d1d \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d)(*strict*)\n  apply (simp (no_asm) add:liftA_commutes_over_concat)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2' d1c d1d \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2' d1c d1d \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2' d1c d1d \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d1a d2a \\<pi>1 \\<pi>2 \\<alpha>1 \\<alpha>2)(*strict*)\n  apply(erule conjE)+\n  apply(rename_tac d2c d2d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2' d1c d1d \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c d2d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d)(*strict*)\n  apply(thin_tac \"cfgLM.trans_der G d2d \\<lparr>cfg_conf = liftA ys2'\\<rparr> \\<pi>2d \\<lparr>cfg_conf = liftB \\<alpha>2d\\<rparr>\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2' d1c d1d \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c d2d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d)(*strict*)\n  apply(thin_tac \"cfgLM.trans_der G d21a \\<lparr>cfg_conf = liftA ys2\\<rparr> \\<pi>21 \\<lparr>cfg_conf = liftB \\<alpha>21\\<rparr>\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim pd1 pd2 nts ntL ys1 y1 \\<pi>11 \\<pi>12 \\<alpha>11 \\<alpha>12 d11a d12a ys2 y2 \\<pi>21 \\<pi>22 \\<alpha>21 \\<alpha>22 d21a d22a ys1' ys2' d1c d1d \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c d2d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d)(*strict*)\n  apply(thin_tac \"nts \\<sqsubseteq> (nts @ ys1')\")\n  apply(thin_tac \"nts \\<sqsubseteq> (nts @ ys2')\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d)(*strict*)\n  apply(subgoal_tac \"suffix (liftA nts) bx1\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d)(*strict*)\n  prefer 2\n  apply(simp add: suffix_def)\n  apply(case_tac X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d a)(*strict*)\n  apply(case_tac v1)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d a)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d a aa list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d a list)(*strict*)\n  apply(rule_tac\n    x=\"liftA list\"\n    in exI)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d ba)(*strict*)\n  apply(rule_tac\n    x=\"liftA v1\"\n    in exI)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d)(*strict*)\n  apply(subgoal_tac \"suffix (liftA nts) bx2\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d)(*strict*)\n  prefer 2\n  apply(thin_tac \"suffix (liftA nts) bx1\")\n  apply(simp add: suffix_def)\n  apply(case_tac X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d a)(*strict*)\n  apply(case_tac v2)\n   apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d a)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d a aa list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 v1 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d a list)(*strict*)\n  apply(rule_tac\n    x=\"liftA list\"\n    in exI)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d ba)(*strict*)\n  apply(rule_tac\n    x=\"liftA v2\"\n    in exI)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d)(*strict*)\n  apply(simp add: suffix_def)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d ca cb)(*strict*)\n  apply(thin_tac \"cfgLM.trans_der G d2c \\<lparr>cfg_conf = ca @ bx1\\<rparr> \\<pi>2c \\<lparr>cfg_conf = liftB \\<alpha>2c\\<rparr>\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d ca cb)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d ca cb)(*strict*)\n  prefer 2\n  apply(rule liftA_append)\n  apply(rule sym)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx1 bx2 Y1 Y2 delim nts ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d d2c \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d ca cb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d cb l1 l2)(*strict*)\n  apply(thin_tac \"liftA (l1 @ l2) = liftA l1 @ liftA l2\")\n  apply(subgoal_tac \"bx2=liftA l2\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d cb l1 l2)(*strict*)\n  prefer 2\n  apply (rule equal_split_prefix_hlp1_hlp1)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d cb l1 l2)(*strict*)\n   apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d cb l1 l2)(*strict*)\n  prefer 2\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d cb l1 l2)(*strict*)\n  apply (metis liftA_preserves_length)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 bx2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d cb l1 l2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2)(*strict*)\n  prefer 2\n  apply(rule_tac\n    G=\"G\"\n    and d=\"d1c\"\n    and ?w1.0=\"liftA l1\"\n    and ?w2.0=\"liftA l2\"\n    in cfgLM_trans_der_cfgLM_derivation_can_be_decomposed)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2)(*strict*)\n  apply(simp add: split_TSstructure_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d1a d2a \\<pi>1 \\<pi>2 \\<alpha>1 \\<alpha>2)(*strict*)\n  apply(erule conjE)+\n  apply(rename_tac d3c d3d \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3d \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d)(*strict*)\n  apply(thin_tac \"cfgLM.trans_der G d3d \\<lparr>cfg_conf = liftA l2\\<rparr> \\<pi>3d \\<lparr>cfg_conf = liftB \\<alpha>3d\\<rparr> \")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3d \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d)(*strict*)\n  apply(thin_tac \"cfgLM.trans_der G d1c \\<lparr>cfg_conf = liftA l1 @ liftA l2\\<rparr> \\<pi>1c \\<lparr>cfg_conf = liftB \\<alpha>1c\\<rparr>\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3d \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3d \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d)(*strict*)\n  prefer 2\n  apply(rule_tac\n    w=\"[X]\"\n    and G=\"G\"\n    in trans_der_construct_elimininating_derivation_prime)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3d \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d)(*strict*)\n   apply(simp add: split_TSstructure_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3d \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d)(*strict*)\n  apply(simp add: F2LR1inputx_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d)(*strict*)\n  apply (metis reachable_and_eliminiable_implies_eliminable2 reachable_and_eliminiable_implies_reachable)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3d \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d)(*strict*)\n  apply(subgoal_tac \"\\<lparr>cfg_conf = X # liftA (ESplitItem_to (S1 ! i))\\<rparr> \\<in> cfg_configurations G\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3d \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d)(*strict*)\n  prefer 2\n  apply(rule cfgLM.trans_der_belongs_configurations2)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3d \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d)(*strict*)\n  apply(simp add: cfg_configurations_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3d \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3d \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d d \\<pi> va)(*strict*)\n  apply(rename_tac dX \\<pi>X vX)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3d \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d dX \\<pi>X vX)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3d \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d dX \\<pi>X vX)(*strict*)\n  prefer 2\n  apply(rule_tac\n    G=\"G\"\n    and ?d1.0=\"dX\"\n    and ?d2.0=\"d3c\"\n    in cfgLM_trans_der_biextend_prime)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3d \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d dX \\<pi>X vX)(*strict*)\n   apply(simp add: split_TSstructure_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3d \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d dX \\<pi>X vX)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3d \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d dX \\<pi>X vX)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3d \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d dX \\<pi>X vX)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3d \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d dX \\<pi>X vX d)(*strict*)\n  apply(rename_tac d3d)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3da \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d dX \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"cfgLM.trans_der G dX \\<lparr>cfg_conf = [X]\\<rparr> \\<pi>X \\<lparr>cfg_conf = liftB vX\\<rparr>\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3da \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d dX \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"cfgLM.trans_der G d3c \\<lparr>cfg_conf = liftA l1\\<rparr> \\<pi>3c \\<lparr>cfg_conf = liftB \\<alpha>3c\\<rparr>\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' d1c \\<pi>1c \\<pi>1d \\<alpha>1c \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 d3c d3da \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d dX \\<pi>X vX d3d)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"cfgLM.trans_der G delim \\<lparr>cfg_conf = liftA (ESplitItem_elim (S2 ! Suc i))\\<rparr> (foldl (@) [] (ESplitItem_elim_prods (S1 ! Suc i))) \\<lparr>cfg_conf = []\\<rparr>\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"\\<alpha>3c @ \\<alpha>3d @ \\<alpha>1d @ \\<alpha>12 = foldl (@) [] (drop (Suc i) (take (length v) fw))\")\n  apply(thin_tac \"\\<alpha>2c @ \\<alpha>2d @ \\<alpha>22 = foldl (@) [] (drop (Suc i) (take (length v) fw))\")\n  apply(thin_tac \"\\<pi>2c @ \\<pi>2d @ \\<pi>22 = foldl (@) [] (ESplitItem_elim_prods (S1 ! Suc i)) @ ESplitItem_prods (S2 ! Suc i) @ \\<pi>s ! Suc i @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S2 @ S2') ! x)) @ ESplitItem_prods ((S2 @ S2') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc i)) (length v)))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"ESplitItem_elim (S2 ! Suc i) @ Y2 # take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S2 ! Suc i)) = l1 @ l2 @ ys2' @ [y2]\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"restrict_newignore S2 (Suc i) = PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"restrict_newignore S1 (Suc i) = PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"ESplitItem_elim (S2 ! Suc i) @ Y1 # take (length (PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i))) (ESplitItem_ignore (S1 ! Suc i)) = l1 @ l2 @ ys1' @ [y1]\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"ESplitItem_elim (S2 ! Suc i) @ hd (cropTol3l2 (Y2 # PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i))) # PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i) = l1 @ l2 @ [ntL]\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"ESplitItem_elim (S2 ! Suc i) @ hd (cropTol3l2 (Y1 # PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i))) # PSplitItem_ignore (restrict G' G (S2 @ S2') (length (Esplit_signature S1)) ! Suc i) = l1 @ l2 @ [ntL]\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"\\<pi>3c @ \\<pi>3d @ \\<pi>1d @ \\<pi>12 = foldl (@) [] (ESplitItem_elim_prods (S1 ! Suc i)) @ ESplitItem_prods (S1 ! Suc i) @ \\<pi>s ! Suc i @ foldl (@) [] (map (\\<lambda>x. foldl (@) [] (ESplitItem_elim_prods ((S1 @ S1') ! x)) @ ESplitItem_prods ((S1 @ S1') ! x) @ \\<pi>s ! x) (nat_seq (Suc (Suc i)) (length v)))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"only_l3_nonterminals (cons_l3 q c q1 # x1)\")\n  apply(thin_tac \"only_l3_nonterminals (cons_l3 q c q2 # x2)\")\n  apply(thin_tac \"ESplitItem_from (S1 ! Suc i) = Some Y1\")\n  apply(thin_tac \"ESplitItem_from (S2 ! Suc i) = Some Y2\")\n  apply(thin_tac \"realizable G (\\<lparr>prod_lhs = cons_l3 q c q1, prod_rhs = r1\\<rparr> # drop (Suc ia) (ESplitItem_prods (S1 ! i))) = \\<lparr>prod_lhs = cons_l3 q c q1, prod_rhs = r1\\<rparr> # drop (Suc ia) (ESplitItem_prods (S1 ! i))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"realizable G (\\<lparr>prod_lhs = cons_l3 q c q2, prod_rhs = r2\\<rparr> # drop (Suc ia) (ESplitItem_prods (S2 ! i))) = \\<lparr>prod_lhs = cons_l3 q c q2, prod_rhs = r2\\<rparr> # drop (Suc ia) (ESplitItem_prods (S2 ! i))\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"(\\<exists>b. teB b = X) \\<longrightarrow> (\\<forall>ia<length (ESplitItem_prods (S2 ! i)). hd (cfg_conf (the (get_configuration (dx1 ia)))) \\<noteq> X)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"(\\<exists>A. teA A = X) \\<longrightarrow> left_degen G dx1 \\<and> ESplitItem_elim_prods (S1 ! i) = []\")\n  apply(thin_tac \"cfgLMTDL G ds (Esplit_signature S1) \\<pi>s fw\")\n  apply(thin_tac \"(\\<exists>b. teB b = X) \\<longrightarrow> (\\<forall>ia<length (ESplitItem_prods (S2 ! i)). hd (cfg_conf (the (get_configuration (dx2 ia)))) \\<noteq> X)\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"(\\<exists>A. teA A = X) \\<longrightarrow> left_degen G dx2 \\<and> ESplitItem_elim_prods (S2 ! i) = []\")\n  apply(thin_tac \"cfgLM.trans_der G dy2 \\<lparr>cfg_conf = teA (cons_l3   q c q2) # liftA x2 @ [teA x2L]\\<rparr> (\\<lparr>prod_lhs = cons_l3 q c q2, prod_rhs = r2\\<rparr> # drop (Suc ia) (ESplitItem_prods (S2 ! i))) \\<lparr>cfg_conf = X # liftA (ESplitItem_to (S2 ! i))\\<rparr>\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"cfgLM.trans_der G dy1 \\<lparr>cfg_conf = teA (cons_l3   q c q1) # liftA x1 @ [teA x1L]\\<rparr> (\\<lparr>prod_lhs = cons_l3 q c q1, prod_rhs = r1\\<rparr> # drop (Suc ia) (ESplitItem_prods (S1 ! i))) \\<lparr>cfg_conf = X # liftA (ESplitItem_to (S1 ! i))\\<rparr>\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"cfgLM.trans_der G dx1 \\<lparr>cfg_conf = [teA F1]\\<rparr> (ESplitItem_prods (S1 ! i)) \\<lparr>cfg_conf = X # liftA (ESplitItem_to (S1 ! i))\\<rparr>\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"cfgLM.trans_der G dx2 \\<lparr>cfg_conf = [teA F2]\\<rparr> (ESplitItem_prods (S2 ! i)) \\<lparr>cfg_conf = X # liftA (ESplitItem_to (S2 ! i))\\<rparr>\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"dx1 ia = Some (pair ex1 \\<lparr>cfg_conf = teA (cons_l3   q c q1) # liftA x1 @ [teA x1L]\\<rparr>)\")\n  apply(thin_tac \"dx2 ia = Some (pair ex2 \\<lparr>cfg_conf = teA (cons_l3   q c q2) # liftA x2 @ [teA x2L]\\<rparr>)\")\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  prefer 2\n  apply(rule_tac\n    ?v1.0=\"[]\"\n    and ?v4.0=\"[]\"\n    and G=\"G\"\n    and ?d1.0=\"dz1\"\n    and ?d2.0=\"d3d\"\n    in cfgLM_trans_der_concat_extend_prime)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n   apply(simp add: split_TSstructure_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  prefer 2\n  apply(rule_tac\n    ?v1.0=\"[]\"\n    and ?v4.0=\"[]\"\n    and G=\"G\"\n    and ?d1.0=\"dz2\"\n    and ?d2.0=\"d3d\"\n    in cfgLM_trans_der_concat_extend_prime)\n   apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n   apply(simp add: split_TSstructure_def)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(force)\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"cfgLM.trans_der G dz1 \\<lparr>cfg_conf = [teA (cons_l3   q c q1)]\\<rparr> (\\<lparr>prod_lhs = cons_l3 q c q1, prod_rhs = r1\\<rparr> # drop (Suc ia) (ESplitItem_prods (S1 ! i))) \\<lparr>cfg_conf = X # liftA l1\\<rparr>\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(thin_tac \"cfgLM.trans_der G dz2 \\<lparr>cfg_conf = [teA (cons_l3   q c q2)]\\<rparr> (\\<lparr>prod_lhs = cons_l3 q c q2, prod_rhs = r2\\<rparr> # drop (Suc ia) (ESplitItem_prods (S2 ! i))) \\<lparr>cfg_conf = X # liftA l1\\<rparr>\")\n  apply(rename_tac ds \\<pi>s fw ia X F1 F2 dx1 dx2 ex1 dy1 ex2 dy2 dz1 dz2 \\<alpha> v1 v2 x1 x1L x2 x2L r1 r2 q q1 c q2 Y1 Y2 delim ntL y1 \\<pi>12 \\<alpha>12 y2 \\<pi>22 \\<alpha>22 ys1' ys2' \\<pi>1d \\<alpha>1d \\<pi>2c \\<pi>2d \\<alpha>2c \\<alpha>2d l1 l2 \\<pi>3c \\<pi>3d \\<alpha>3c \\<alpha>3d \\<pi>X vX d3d)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q q1 c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d da)(*strict*)\n  apply(rename_tac d1x d2x)\n  apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q q1 c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q q1 c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n  prefer 2\n  apply(rule_tac\n    \\<pi>1'=\"[]\"\n    and \\<pi>2'=\"[]\"\n    and ?\\<alpha>1.0=\"vX@\\<alpha>3c\"\n    and ?\\<alpha>2.0=\"vX@\\<alpha>3c\"\n    and G=\"G\"\n    and G'=\"G'\"\n    and ?d1.0=\"d1x\"\n    and ?d2.0=\"d2x\"\n    in compatible_derivations_coincide_heavily)\n     apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q q1 c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n     apply(force)\n    apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q q1 c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n    apply(force)\n   apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q q1 c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n   apply (simp add: liftB_commutes_over_concat)\n  apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q q1 c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n  apply (simp add: liftB_commutes_over_concat)\n  apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q q1 c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n  apply(subgoal_tac \"map (prod_to_edge G') (\\<lparr>prod_lhs = cons_l3 q c q1, prod_rhs = r1\\<rparr> # drop (Suc ia) (ESplitItem_prods (S1 ! i)))= map (prod_to_edge G') (\\<lparr>prod_lhs = cons_l3 q c q2, prod_rhs = r2\\<rparr> # drop (Suc ia) (ESplitItem_prods (S2 ! i))) \")\n  apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q q1 c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n  apply(force)\n  apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q q1 c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n  apply (metis drop_map)\n  apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q q1 c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n  prefer 2\n  apply(rule_tac\n    \\<alpha>=\"vX@\\<alpha>3c\"\n    and G=\"G\"\n    and G'=\"G'\"\n    and ?d1.0=\"d1x\"\n    and ?d2.0=\"d2x\"\n    in same_l3_source_and_same_target_liftB_and_same_prod_to_edge_implies_equal_prods)\n       apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n       apply(assumption)\n      apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n      apply(assumption)\n     apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n     apply (simp add: liftB_commutes_over_concat)\n    apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n    apply (simp add: liftB_commutes_over_concat)\n   apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n   prefer 3\n   apply(subgoal_tac \"map (prod_to_edge G') (\\<lparr>prod_lhs = cons_l3 q c q2, prod_rhs = r1\\<rparr> # drop (Suc ia) (ESplitItem_prods (S1 ! i)))= map (prod_to_edge G') (\\<lparr>prod_lhs = cons_l3 q c q2, prod_rhs = r2\\<rparr> # drop (Suc ia) (ESplitItem_prods (S2 ! i))) \")\n    apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n    apply(force)\n   apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n   apply (metis drop_map)\n  apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n  apply(rule trans_der_notfinishingL_froml3_ext)\n    apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n    apply(force)\n   apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n   apply(force)\n  apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n  apply(force)\n  apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n  apply(rule trans_der_notfinishingL_froml3_ext)\n   apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n   apply(assumption)\n  apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n  apply(assumption)\n  apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n  apply(assumption)\n  apply(rename_tac ia X F1 F2 \\<alpha> v1 v2 r1 r2 q c q2 ntL l1 l2 \\<pi>3c \\<alpha>3c \\<pi>X vX d3d d1x d2x)(*strict*)\n  apply(clarsimp)\n  done\n\ntheorem equal_split_prefix: \"\n  F2LR1inputx G G'\n  \\<Longrightarrow> split_TSstructure G\n  \\<Longrightarrow> cfgRM.derivation_initial G d1\n  \\<Longrightarrow> d1 n1 = Some (pair e1 \\<lparr>cfg_conf=v@[teB b]@x1\\<rparr>)\n  \\<Longrightarrow> cfgRM.derivation_initial G d2\n  \\<Longrightarrow> d2 n2 = Some (pair e2 \\<lparr>cfg_conf=v@[teB b]@x2\\<rparr>)\n  \\<Longrightarrow> EValidSplit G (S1@S1')\n  \\<Longrightarrow> EValidSplit G (S2@S2')\n  \\<Longrightarrow> length S1 = length (v@[teB b])\n  \\<Longrightarrow> length S2 = length (v@[teB b])\n  \\<Longrightarrow> v@[teB b] = Esplit_signature S1\n  \\<Longrightarrow> v@[teB b] = Esplit_signature S2\n  \\<Longrightarrow> x1 = Esplit_signature S1'\n  \\<Longrightarrow> x2 = Esplit_signature S2'\n  \\<Longrightarrow> S1R=restrict G' G (S1@S1') (length (v@[teB b]))\n  \\<Longrightarrow> S2R=restrict G' G (S2@S2') (length (v@[teB b]))\n  \\<Longrightarrow> S1R = S2R\"\n  apply(subgoal_tac \"ESplitItem_elem ((S1 @ S1') ! length v) = Some (teB b)\")\n   prefer 2\n   apply(rule equal_split_prefix_hlp2)\n           apply(force)\n          apply(force)\n         apply(force)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"PValidSplit G' G S1R\")\n   prefer 2\n   apply(rule equal_split_prefix_hlp3)\n            apply(force)\n           apply(force)\n          apply(force)\n         apply(force)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"ESplitItem_elem ((S2 @ S2') ! length v) = Some (teB b)\")\n   prefer 2\n   apply(rule_tac\n      ?d1.0=\"d2\"\n      in equal_split_prefix_hlp2)\n           apply(force)\n          apply(force)\n         apply(force)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(subgoal_tac \"PValidSplit G' G S2R\")\n   prefer 2\n   apply(rule_tac\n      ?S1.0=\"S2\"\n      and ?d1.0=\"d2\"\n      in equal_split_prefix_hlp3)\n            apply(force)\n           apply(force)\n          apply(force)\n         apply(force)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(rule listEqI)\n   apply(clarsimp)\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n   apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(rule impI)\n  apply(subgoal_tac \"length (Esplit_signature S1) = length S1\")\n   apply(rename_tac i)(*strict*)\n   prefer 2\n   apply (metis length_Suc)\n  apply(rename_tac i)(*strict*)\n  apply(subgoal_tac \"length (v@[teB b]) = length S1\")\n   apply(rename_tac i)(*strict*)\n   prefer 2\n   apply (metis length_Suc)\n  apply(rename_tac i)(*strict*)\n  apply(rule_tac\n      ?d1.0=\"d1\"\n      and ?d2.0=\"d2\"\n      and S1'=\"S1'\"\n      and S2'=\"S2'\"\n      and ?S1.0=\"S1\"\n      and ?S2.0=\"S2\"\n      in equal_split_prefix_hlp1)\n                      apply(rename_tac i)(*strict*)\n                      apply(force)\n                      apply(rename_tac i)(*strict*)\n                      apply(force)\n                      apply(rename_tac i)(*strict*)\n                      apply(force)\n                     apply(rename_tac i)(*strict*)\n                     apply(force)\n                    apply(rename_tac i)(*strict*)\n                    apply(force)\n                   apply(rename_tac i)(*strict*)\n                   apply(force)\n                  apply(rename_tac i)(*strict*)\n                  apply(force)\n                 apply(rename_tac i)(*strict*)\n                 apply(force)\n                apply(rename_tac i)(*strict*)\n                apply(force)\n               apply(rename_tac i)(*strict*)\n               apply(force)\n              apply(rename_tac i)(*strict*)\n              apply(force)\n             apply(rename_tac i)(*strict*)\n             apply(force)\n            apply(rename_tac i)(*strict*)\n            apply(force)\n           apply(rename_tac i)(*strict*)\n           apply(force)\n          apply(rename_tac i)(*strict*)\n          defer\n          defer\n          apply(force)\n         apply(rename_tac i)(*strict*)\n         apply(force)\n        apply(rename_tac i)(*strict*)\n        apply(force)\n       apply(rename_tac i)(*strict*)\n       apply(force)\n      apply(rename_tac i)(*strict*)\n      apply(force)\n     apply(rename_tac i)(*strict*)\n     apply(force)\n    apply(rename_tac i)(*strict*)\n    apply(rule_tac\n      t=\"length (v @ [teB b])\"\n      and s=\"length S1R\"\n      in ssubst)\n     apply(rename_tac i)(*strict*)\n     apply(rule_tac\n      t=\"S1R\"\n      and s=\"restrict G' G (S1 @ S1') (length (v @ [teB b]))\"\n      in ssubst)\n      apply(rename_tac i)(*strict*)\n      apply(force)\n     apply(rename_tac i)(*strict*)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(clarsimp)\n     apply(rule_tac\n      t=\"length S1\"\n      and s=\"Suc (length v)\"\n      in ssubst)\n      apply(rename_tac i)(*strict*)\n      apply (metis length_Suc)\n     apply(rename_tac i)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"length (nat_seq 0 (length v)) =SSX\" for SSX)\n      apply(rename_tac i)(*strict*)\n      prefer 2\n      apply(rule nat_seq_length_prime)\n     apply(rename_tac i)(*strict*)\n     apply(force)\n    apply(rename_tac i)(*strict*)\n    apply(force)\n   apply(rename_tac i)(*strict*)\n   apply(case_tac \"S1'\")\n    apply(rename_tac i)(*strict*)\n    prefer 2\n    apply(rename_tac i a list)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac i)(*strict*)\n   apply(clarsimp)\n   apply(thin_tac \"EValidSplit G (S2 @ S2')\")\n   apply(simp add: EValidSplit_def EValidSplit_final_def)\n   apply(clarsimp)\n   apply(subgoal_tac \"last S1 = S1!length v\")\n    apply(rename_tac i)(*strict*)\n    prefer 2\n    apply (metis last_nth3 length_Suc)\n   apply(rename_tac i)(*strict*)\n   apply(clarsimp)\n   apply(simp add: EValidSplit_ValidItem_def)\n   apply(erule_tac\n      x=\"S1!length v\"\n      in ballE)\n    apply(rename_tac i)(*strict*)\n    prefer 2\n    apply (metis last_in_set)\n   apply(rename_tac i)(*strict*)\n   apply(simp add: EValidSplitItem_def)\n   apply(clarsimp)\n   apply(case_tac \"ESplitItem_from (S1 ! length v)\")\n    apply(rename_tac i)(*strict*)\n    apply(simp add: EValidSplitItem_gen_def)\n    apply(clarsimp)\n    apply(rename_tac i d)(*strict*)\n    apply(simp add: option_to_list_def)\n    apply(subgoal_tac \"SSrenPI=[] \\<and> SSc2=\\<lparr>cfg_conf=[]\\<rparr>\" for SSrenPI SSc2)\n     apply(rename_tac i d)(*strict*)\n     prefer 2\n     apply(rule_tac cfgLM_trans_der_from_empty)\n     apply(force)\n    apply(rename_tac i d)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac i a)(*strict*)\n   apply(rule_tac\n      b=\"b\"\n      and S=\"S1!length v\"\n      and G=\"G\"\n      and G'=\"G'\"\n      in EValidSplit_DERIVED_terminal_produce_produces_to)\n        apply(rename_tac i a)(*strict*)\n        apply(force)\n       apply(rename_tac i a)(*strict*)\n       apply(force)\n      apply(rename_tac i a)(*strict*)\n      apply(force)\n     apply(rename_tac i a)(*strict*)\n     apply(force)\n    apply(rename_tac i a)(*strict*)\n    apply(force)\n   apply(rename_tac i a)(*strict*)\n   apply(force)\n  apply(rename_tac i)(*strict*)\n  apply(case_tac \"S2'\")\n   apply(rename_tac i)(*strict*)\n   prefer 2\n   apply(rename_tac i a list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(clarsimp)\n  apply(thin_tac \"EValidSplit G (S1 @ S1')\")\n  apply(simp add: EValidSplit_def EValidSplit_final_def)\n  apply(clarsimp)\n  apply(subgoal_tac \"last S2 = S2!length v\")\n   apply(rename_tac i)(*strict*)\n   prefer 2\n   apply (metis last_nth3 length_Suc)\n  apply(rename_tac i)(*strict*)\n  apply(clarsimp)\n  apply(simp add: EValidSplit_ValidItem_def)\n  apply(erule_tac\n      x=\"S2!length v\"\n      in ballE)\n   apply(rename_tac i)(*strict*)\n   prefer 2\n   apply (metis last_in_set)\n  apply(rename_tac i)(*strict*)\n  apply(simp add: EValidSplitItem_def)\n  apply(clarsimp)\n  apply(case_tac \"ESplitItem_from (S2 ! length v)\")\n   apply(rename_tac i)(*strict*)\n   apply(simp add: EValidSplitItem_gen_def)\n   apply(clarsimp)\n   apply(rename_tac i d)(*strict*)\n   apply(simp add: option_to_list_def)\n   apply(subgoal_tac \"SSrenPI=[] \\<and> SSc2=\\<lparr>cfg_conf=[]\\<rparr>\" for SSrenPI SSc2)\n    apply(rename_tac i d)(*strict*)\n    prefer 2\n    apply(rule_tac cfgLM_trans_der_from_empty)\n    apply(force)\n   apply(rename_tac i d)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac i a)(*strict*)\n  apply(rule_tac\n      b=\"b\"\n      and S=\"S2!length v\"\n      and G=\"G\"\n      and G'=\"G'\"\n      in EValidSplit_DERIVED_terminal_produce_produces_to)\n       apply(rename_tac i a)(*strict*)\n       apply(force)\n      apply(rename_tac i a)(*strict*)\n      apply(force)\n     apply(rename_tac i a)(*strict*)\n     apply(force)\n    apply(rename_tac i a)(*strict*)\n    apply(force)\n   apply(rename_tac i a)(*strict*)\n   apply(force)\n  apply(rename_tac i a)(*strict*)\n  apply(force)\n  done\n\nhide_fact equal_split_prefix_hlp1\nhide_fact equal_split_prefix_hlp1_updated\nhide_fact equal_split_prefix_updated\nhide_fact restrictX_length\n  (* important equal_split_prefix *)\n\nend\n\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_12_04_06_06_10/LR1_Property_Satisfaction__convert_remaining_productions.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526514141571, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.26714158154106915}}
{"text": "theory flash69Rev imports flashPub\nbegin\nsection{*Main defintions*}\nlemma NI_FAckVsInv69:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n     have allCases:\"formEval   (neg ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const true )) )  s  \\<or>formEval  ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const true ))  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume b1:\"formEval  (neg ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const true )) )  s\"\nhave \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n    }\n\n    moreover\n                       {assume b1:\"formEval ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const true ))  s\"\n\n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''ShWbMsg_Cmd'') )  ( Const SHWB_FAck ))    ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n    }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_InvVsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_InvAck_1VsInv69:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1_HomeVsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_InvAck_2VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_GetXVsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_Nak1VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_Nak2VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_Nak3VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_PutX1VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv69:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10VsInv69:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10_homeVsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX11VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_GetVsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_Get_Nak1VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_Get_Nak2VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_Get_Nak3VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_Get_Put1VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_Get_Put2VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put3VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_PutVsInv69:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_PutXAcksDoneVsInv69:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_NakVsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Nak_ClearVsInv69:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Nak_HomeVsInv69:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_NakVsInv69:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_GetX ))     (neg ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iRule2)) )  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iRule2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_GetX ))    ( eqn ( IVar ( Para ''CacheState'' iInv2) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_GetX ))    ( eqn ( IVar ( Para ''CacheState'' iInv2) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iRule1) )  ( Const UNI_GetX )) \n          ( eqn ( IVar ( Para ''CacheState'' iInv2) )  ( Const CACHE_E ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iRule1) )   (Const iInv1))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n                  \n         have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iRule1) )  ( Const UNI_GetX )) \n          ( eqn ( IVar ( Para ''CacheState'' iInv2) )  ( Const CACHE_E ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iRule1) )   (Const iRule2))  ) ) \" in exI,auto)\n \n        \n        done\n          \n\n                 \n   \n  \n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_Nak_HomeVsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv1))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  )    ( eqn ( IVar ( Para ''CacheState'' iInv2) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv1))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  )    ( eqn ( IVar ( Para ''CacheState'' iInv2) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_PutXVsInv69:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_PutX_HomeVsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Nak1VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv1))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  )    ( eqn ( IVar ( Para ''CacheState'' iInv2) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv1))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  )    ( eqn ( IVar ( Para ''CacheState'' iInv2) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Nak2VsInv69:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))     (neg ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iRule2)) )  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iRule2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_Get ))    ( eqn ( IVar ( Para ''CacheState'' iInv2) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_Get ))    ( eqn ( IVar ( Para ''CacheState'' iInv2) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iRule1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Para ''CacheState'' iInv2) )  ( Const CACHE_E ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iRule1) )   (Const iInv1))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n        \n                 have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\"   (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iRule1) )  ( Const UNI_Get ))    \n          ( eqn ( IVar ( Para ''CacheState'' iInv2) )  ( Const CACHE_E ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iRule1) )   (Const iRule2))  ) )   \" in exI,auto)\n \n \n        \n        done\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Put1VsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Put2VsInv69:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutVsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                     have allCases:\"formEval  ( eqn ( IVar ( Para ''InvMarked'' iInv2) )  ( Const true ))  s  \\<or>formEval   (neg ( eqn ( IVar ( Para ''InvMarked'' iInv2) )  ( Const true )) )  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume c1:\"formEval ( eqn ( IVar ( Para ''InvMarked'' iInv2) )  ( Const true ))  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1  c1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n\n    moreover\n                       {assume c1:\"formEval  (neg ( eqn ( IVar ( Para ''InvMarked'' iInv2) )  ( Const true )) )  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1  c1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n   ultimately have \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutXVsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv1))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  )    ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_ReplaceVsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_ReplaceHomeVsInv69:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceHomeShrVldVsInv69:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceShrVldVsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_ShWbVsInv69:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_WbVsInv69:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_GetX1VsInv69:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_GetX2VsInv69:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX1VsInv69:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX2VsInv69:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX3VsInv69:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX4VsInv69:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_Get_GetVsInv69:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_Get_PutVsInv69:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_PutXVsInv69:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_ReplaceVsInv69:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_GetVsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma PI_Remote_GetXVsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma PI_Remote_PutXVsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_ReplaceVsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma StoreVsInv69:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma StoreHomeVsInv69:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv69  iInv1  iInv2 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash69Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526514141571, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.26714158154106915}}
{"text": "theory Proof_2_4\n  imports Requirements VCTheoryLemmas\nbegin\n\ntheorem proof_2_4: \"VC4 inv2 s0 requestButtonValue\"\n  apply(simp only: VC4_def inv2_def  R2_def extraInv_def)\nproof\n  print_state\n  assume \" ((toEnvP s0 \\<and>\n      (\\<forall>s1 s2 s3.\n          substate s1 s2 \\<and>\n          substate s2 s3 \\<and>\n          substate s3 s0 \\<and>\n          toEnvP s1 \\<and>\n          toEnvP s2 \\<and>\n          toEnvP s3 \\<and>\n          toEnvNum s1 s2 = Ctrl \\<and>\n          toEnvNum s2 s3 < T2 \\<and> getVarBool s1 minimalRed \\<noteq> PRESSED \\<and> getVarBool s2 minimalRed = PRESSED \\<longrightarrow>\n          getVarBool s3 minimalRed = PRESSED)) \\<and>\n     toEnvP s0 \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = minimalRed \\<longrightarrow>\n           0 < ltimeEnv s1 Ctrl \\<and> ltimeEnv s1 Ctrl \\<le> MINIMAL_RED_TIME_LIMIT) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = minimalRed \\<longrightarrow>\n           (\\<exists>s2. toEnvP s2 \\<and>\n                 substate s2 s1 \\<and>\n                 toEnvNum s2 s1 = ltimeEnv s1 Ctrl \\<and> getPstate s2 Ctrl = green \\<and> ltimeEnv s2 Ctrl = T2) \\<or>\n           (\\<forall>s2. toEnvP s2 \\<and> substate s2 s1 \\<longrightarrow> getPstate s2 Ctrl = minimalRed)) \\<and>\n     (\\<forall>s1 s2.\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         substate s1 s2 \\<and> substate s2 s0 \\<and> getPstate s2 Ctrl = minimalRed \\<and> toEnvNum s1 s2 < ltimeEnv s2 Ctrl \\<longrightarrow>\n         getPstate s1 Ctrl = minimalRed) \\<and>\n     (\\<forall>s1 s2.\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         substate s1 s2 \\<and>\n         substate s2 s0 \\<and> (\\<forall>s3. toEnvP s3 \\<and> substate s1 s3 \\<and> substate s3 s2 \\<longrightarrow> getPstate s3 Ctrl = minimalRed) \\<longrightarrow>\n         toEnvNum s1 s2 = ltimeEnv s2 Ctrl - ltimeEnv s1 Ctrl) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and>\n           substate s1 s0 \\<and> getPstate s1 Ctrl = redAfterMinimalRed \\<and> getVarBool s1 redAfterMinimalRed = NOT_PRESSED \\<longrightarrow>\n           (\\<exists>s2. toEnvP s2 \\<and>\n                 substate s2 s1 \\<and>\n                 getPstate s2 Ctrl = minimalRed \\<and>\n                 ltimeEnv s2 Ctrl = MINIMAL_RED_TIME_LIMIT \\<and>\n                 getVarBool s2 redAfterMinimalRed = NOT_PRESSED \\<and>\n                 (\\<forall>s3. toEnvP s3 \\<and> substate s2 s3 \\<and> substate s3 s1 \\<and> s2 \\<noteq> s3 \\<longrightarrow>\n                       getPstate s3 Ctrl = redAfterMinimalRed \\<and>\n                       getVarBool s3 redAfterMinimalRed = NOT_PRESSED \\<and> getVarBool s3 Ctrl = NOT_PRESSED))) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = redToGreen \\<longrightarrow>\n           0 < ltimeEnv s1 Ctrl \\<and> ltimeEnv s1 Ctrl \\<le> RED_TO_GREEN_TIME_LIMIT) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = redToGreen \\<longrightarrow>\n           (\\<exists>s2. toEnvP s2 \\<and>\n                 substate s2 s1 \\<and>\n                 toEnvNum s2 s1 = ltimeEnv s1 Ctrl \\<and>\n                 getPstate s2 Ctrl = redAfterMinimalRed \\<and>\n                 (getVarBool s2 redAfterMinimalRed = PRESSED \\<or> getVarBool s2 Ctrl = PRESSED))) \\<and>\n     (\\<forall>s1 s2.\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         substate s1 s2 \\<and> substate s2 s0 \\<and> toEnvNum s1 s2 < ltimeEnv s2 Ctrl \\<and> getPstate s2 Ctrl = redToGreen \\<longrightarrow>\n         getPstate s1 Ctrl = redToGreen) \\<and>\n     (\\<forall>s1 s2.\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         substate s1 s2 \\<and>\n         substate s2 s0 \\<and> (\\<forall>s3. toEnvP s3 \\<and> substate s1 s3 \\<and> substate s3 s2 \\<longrightarrow> getPstate s3 Ctrl = redToGreen) \\<longrightarrow>\n         toEnvNum s1 s2 = ltimeEnv s2 Ctrl - ltimeEnv s1 Ctrl) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = green \\<longrightarrow> 0 < ltimeEnv s1 Ctrl \\<and> ltimeEnv s1 Ctrl \\<le> T2) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = green \\<longrightarrow>\n           (\\<exists>s2. toEnvP s2 \\<and>\n                 substate s2 s1 \\<and>\n                 toEnvNum s2 s1 = ltimeEnv s1 Ctrl \\<and>\n                 getPstate s2 Ctrl = redToGreen \\<and> ltimeEnv s2 Ctrl = RED_TO_GREEN_TIME_LIMIT)) \\<and>\n     (\\<forall>s1 s2.\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         substate s1 s2 \\<and> substate s2 s0 \\<and> getPstate s2 Ctrl = green \\<and> toEnvNum s1 s2 < ltimeEnv s2 Ctrl \\<longrightarrow>\n         getPstate s1 Ctrl = green) \\<and>\n     (\\<forall>s1 s2.\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         substate s1 s2 \\<and>\n         substate s2 s0 \\<and> (\\<forall>s3. toEnvP s3 \\<and> substate s1 s3 \\<and> substate s3 s2 \\<longrightarrow> getPstate s3 Ctrl = green) \\<longrightarrow>\n         toEnvNum s1 s2 = ltimeEnv s2 Ctrl - ltimeEnv s1 Ctrl) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = green \\<longrightarrow> getVarBool s1 minimalRed = PRESSED) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl \\<noteq> green \\<longrightarrow> getVarBool s1 minimalRed = NOT_PRESSED) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<longrightarrow>\n           getPstate s1 Ctrl = minimalRed \\<or>\n           getPstate s1 Ctrl = redAfterMinimalRed \\<or> getPstate s1 Ctrl = redToGreen \\<or> getPstate s1 Ctrl = green) \\<and>\n     (\\<forall>s1 s2.\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         substate s1 s2 \\<and>\n         substate s2 s0 \\<and>\n         toEnvNum s1 s2 < ltimeEnv s2 Ctrl - Ctrl \\<and>\n         getPstate s2 Ctrl = minimalRed \\<and> getVarBool s2 redAfterMinimalRed = NOT_PRESSED \\<longrightarrow>\n         getVarBool s1 Ctrl = NOT_PRESSED) \\<and>\n     (\\<forall>s2. toEnvP s2 \\<and> substate s2 s0 \\<and> getPstate s2 Ctrl = minimalRed \\<and> getVarBool s2 redAfterMinimalRed = PRESSED \\<longrightarrow>\n           (\\<exists>s1. toEnvP s1 \\<and>\n                 substate s1 s2 \\<and> toEnvNum s1 s2 < ltimeEnv s2 Ctrl - Ctrl \\<and> getVarBool s1 Ctrl = PRESSED)) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = redAfterMinimalRed \\<and> getVarBool s1 redAfterMinimalRed \\<longrightarrow>\n           (\\<exists>s2. toEnvP s2 \\<and>\n                 substate s2 s1 \\<and>\n                 toEnvNum s2 s1 = Ctrl \\<and>\n                 getPstate s2 Ctrl = minimalRed \\<and>\n                 ltimeEnv s2 Ctrl = MINIMAL_RED_TIME_LIMIT \\<and>\n                 (getVarBool s2 redAfterMinimalRed \\<or> getVarBool s1 Ctrl = PRESSED))) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = green \\<longrightarrow>\n           getVarBool s1 redAfterMinimalRed = NOT_PRESSED)) \\<and>\n    env (setVarAny s0 requestButtonValue) requestButtonValue \\<and>\n    getPstate (setVarAny s0 requestButtonValue) Ctrl = minimalRed \\<and>\n    \\<not> getVarBool (setVarAny s0 requestButtonValue) Ctrl \\<and>\n    MINIMAL_RED_TIME_LIMIT \\<le> ltimeEnv (setVarAny s0 requestButtonValue) Ctrl\"\n  then obtain reqs0: \"(toEnvP s0 \\<and>\n      (\\<forall>s1 s2 s3.\n          substate s1 s2 \\<and>\n          substate s2 s3 \\<and>\n          substate s3 s0 \\<and>\n          toEnvP s1 \\<and>\n          toEnvP s2 \\<and>\n          toEnvP s3 \\<and>\n          toEnvNum s1 s2 = Ctrl \\<and>\n          toEnvNum s2 s3 < T2 \\<and> getVarBool s1 minimalRed \\<noteq> PRESSED \\<and> getVarBool s2 minimalRed = PRESSED \\<longrightarrow>\n          getVarBool s3 minimalRed = PRESSED))\" \nand ei0: \"toEnvP s0\"\nand ei1: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = minimalRed \\<longrightarrow>\n 0<ltimeEnv s1 Ctrl \\<and>  ltimeEnv s1 Ctrl \\<le> MINIMAL_RED_TIME_LIMIT) \" \nand ei2: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = minimalRed \\<longrightarrow>\n ((\\<exists> s2. toEnvP s2 \\<and> substate s2 s1 \\<and> toEnvNum s2 s1 = ltimeEnv s1 Ctrl  \\<and>\n getPstate s2 Ctrl = green \\<and> ltimeEnv s2 Ctrl = GREEN_TIME_LIMIT) \\<or>\n (\\<forall> s2. toEnvP s2 \\<and> substate s2 s1 \\<longrightarrow> getPstate s2 Ctrl = minimalRed))) \"\nand ei3: \"(\\<forall> s1 s2. toEnvP s1 \\<and> toEnvP s2 \\<and> substate s1 s2 \\<and> substate s2 s0 \\<and> getPstate s2 Ctrl = minimalRed \\<and>\n toEnvNum s1 s2 < ltimeEnv s2 Ctrl \\<longrightarrow> getPstate s1 Ctrl = minimalRed) \"\nand ei4: \"\\<forall> s1 s2. toEnvP s1 \\<and> toEnvP s2 \\<and> substate s1 s2 \\<and> substate s2 s0 \\<and>\n(\\<forall> s3. toEnvP s3 \\<and> substate s1 s3 \\<and> substate s3 s2 \\<longrightarrow> getPstate s3 Ctrl = minimalRed ) \\<longrightarrow>\ntoEnvNum s1 s2 = ltimeEnv s2 Ctrl - ltimeEnv s1 Ctrl\" \nand ei5: \"\\<forall> s1 . toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = redAfterMinimalRed \\<and>\n getVarBool s1 requestButtonPressed = False \\<longrightarrow>\n(\\<exists> s2. toEnvP s2 \\<and> substate s2 s1 \\<and> getPstate s2 Ctrl = minimalRed \\<and> ltimeEnv s2 Ctrl = MINIMAL_RED_TIME_LIMIT \\<and>\ngetVarBool s2 requestButtonPressed = False \\<and> (\\<forall> s3. toEnvP s3 \\<and> substate s2 s3 \\<and> substate s3 s1 \\<and> s2 \\<noteq> s3 \\<longrightarrow>\n getPstate s3 Ctrl = redAfterMinimalRed \\<and> \ngetVarBool s3 requestButtonPressed = False \\<and> getVarBool s3  requestButton = NOT_PRESSED))\"\nand ei6: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = redToGreen \\<longrightarrow>\n0< ltimeEnv s1 Ctrl \\<and> ltimeEnv s1 Ctrl \\<le> RED_TO_GREEN_TIME_LIMIT) \"\nand ei7: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = redToGreen \\<longrightarrow>\n(\\<exists> s2. toEnvP s2  \\<and> substate s2 s1 \\<and>\n toEnvNum s2 s1 = ltimeEnv s1 Ctrl  \\<and> getPstate s2 Ctrl = redAfterMinimalRed \\<and> \n(getVarBool s2 requestButtonPressed = True \\<or> getVarBool s2 requestButton = PRESSED)))\"\nand ei8: \"(\\<forall> s1 s2. toEnvP s1 \\<and> toEnvP s2 \\<and> substate s1 s2 \\<and> substate s2 s0 \\<and> toEnvNum s1 s2 < ltimeEnv s2 Ctrl \\<and>\n getPstate s2 Ctrl = redToGreen \\<longrightarrow> getPstate s1 Ctrl = redToGreen) \"\nand ei9: \"(\\<forall> s1 s2. toEnvP s1 \\<and> toEnvP s2 \\<and> substate s1 s2 \\<and> substate s2 s0 \\<and>\n(\\<forall> s3. toEnvP s3 \\<and> substate s1 s3 \\<and> substate s3 s2 \\<longrightarrow> getPstate s3 Ctrl = redToGreen) \\<longrightarrow>\ntoEnvNum s1 s2 = ltimeEnv s2 Ctrl - ltimeEnv s1 Ctrl) \"\nand ei10: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = green \\<longrightarrow>\n0 < ltimeEnv s1 Ctrl \\<and> ltimeEnv s1 Ctrl \\<le> GREEN_TIME_LIMIT)\"\nand ei11: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = green \\<longrightarrow>\n(\\<exists> s2. toEnvP s2 \\<and> substate s2 s1 \\<and> toEnvNum s2 s1 = ltimeEnv s1 Ctrl \\<and>\ngetPstate s2 Ctrl = redToGreen \\<and> ltimeEnv s2 Ctrl = RED_TO_GREEN_TIME_LIMIT)) \"\nand ei12: \"(\\<forall> s1 s2. toEnvP s1 \\<and> toEnvP s2 \\<and> substate s1 s2 \\<and> substate s2 s0 \\<and> getPstate s2 Ctrl = green \\<and>\ntoEnvNum s1 s2 < ltimeEnv s2 Ctrl \\<longrightarrow> getPstate s1 Ctrl = green)\"\nand ei13: \"(\\<forall> s1 s2. toEnvP s1 \\<and> toEnvP s2 \\<and> substate s1 s2 \\<and> substate s2 s0 \\<and> \n(\\<forall> s3. toEnvP s3 \\<and> substate s1 s3 \\<and> substate s3 s2 \\<longrightarrow> getPstate s3 Ctrl = green) \\<longrightarrow>\ntoEnvNum s1 s2 = ltimeEnv s2 Ctrl - ltimeEnv s1 Ctrl) \"\nand ei14: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = green \\<longrightarrow> getVarBool s1 trafficLight = GREEN) \"\nand ei15: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl \\<noteq> green \\<longrightarrow> getVarBool s1 trafficLight = RED) \"\nand ei16: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<longrightarrow>\n getPstate s1 Ctrl = minimalRed \\<or> getPstate s1 Ctrl = redAfterMinimalRed \\<or>\n getPstate s1 Ctrl = redToGreen \\<or> getPstate s1 Ctrl = green)\"\nand ei17: \"(\\<forall> s1 s2. toEnvP s1 \\<and> toEnvP s2 \\<and> substate s1 s2 \\<and> substate s2 s0 \\<and>\n toEnvNum s1 s2 < ltimeEnv s2 Ctrl - 1 \\<and>  getPstate s2 Ctrl = minimalRed \\<and>\n getVarBool s2 requestButtonPressed = False \\<longrightarrow> getVarBool s1 requestButton = NOT_PRESSED)\"\nand ei18: \"(\\<forall> s2. toEnvP s2  \\<and> substate s2 s0  \\<and>\n getPstate s2 Ctrl = minimalRed \\<and> getVarBool s2 requestButtonPressed = True \\<longrightarrow>\n(\\<exists> s1. toEnvP s1 \\<and> substate s1 s2 \\<and> toEnvNum s1 s2 < ltimeEnv s2 Ctrl - 1 \\<and> getVarBool s1 requestButton = PRESSED))\"\nand ei19: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = redAfterMinimalRed \\<and> getVarBool s1 requestButtonPressed \\<longrightarrow>\n(\\<exists> s2. toEnvP s2 \\<and> substate s2 s1 \\<and> toEnvNum s2 s1 = 1 \\<and> getPstate s2 Ctrl = minimalRed \\<and>\n ltimeEnv s2 Ctrl = MINIMAL_RED_TIME_LIMIT \\<and>\n (getVarBool s2 requestButtonPressed \\<or> getVarBool s1 requestButton = PRESSED)))\"\nand ei20: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = green \\<longrightarrow> getVarBool s1 requestButtonPressed = False)\"\nand vc: \" env (setVarAny s0 requestButtonValue) requestButtonValue \\<and>\n    getPstate (setVarAny s0 requestButtonValue) Ctrl = minimalRed \\<and>\n    \\<not> getVarBool (setVarAny s0 requestButtonValue) Ctrl \\<and>\n    MINIMAL_RED_TIME_LIMIT \\<le> ltimeEnv (setVarAny s0 requestButtonValue) Ctrl\"\n    by fast\n  show \" (toEnvP (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n     (\\<forall>s1 s2 s3.\n         substate s1 s2 \\<and>\n         substate s2 s3 \\<and>\n         substate s3 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         toEnvP s3 \\<and>\n         toEnvNum s1 s2 = Ctrl \\<and>\n         toEnvNum s2 s3 < T2 \\<and> getVarBool s1 minimalRed \\<noteq> PRESSED \\<and> getVarBool s2 minimalRed = PRESSED \\<longrightarrow>\n         getVarBool s3 minimalRed = PRESSED)) \\<and>\n    toEnvP (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n          getPstate s1 Ctrl = minimalRed \\<longrightarrow>\n          0 < ltimeEnv s1 Ctrl \\<and> ltimeEnv s1 Ctrl \\<le> MINIMAL_RED_TIME_LIMIT) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n          getPstate s1 Ctrl = minimalRed \\<longrightarrow>\n          (\\<exists>s2. toEnvP s2 \\<and>\n                substate s2 s1 \\<and>\n                toEnvNum s2 s1 = ltimeEnv s1 Ctrl \\<and> getPstate s2 Ctrl = green \\<and> ltimeEnv s2 Ctrl = T2) \\<or>\n          (\\<forall>s2. toEnvP s2 \\<and> substate s2 s1 \\<longrightarrow> getPstate s2 Ctrl = minimalRed)) \\<and>\n    (\\<forall>s1 s2.\n        toEnvP s1 \\<and>\n        toEnvP s2 \\<and>\n        substate s1 s2 \\<and>\n        substate s2 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n        getPstate s2 Ctrl = minimalRed \\<and> toEnvNum s1 s2 < ltimeEnv s2 Ctrl \\<longrightarrow>\n        getPstate s1 Ctrl = minimalRed) \\<and>\n    (\\<forall>s1 s2.\n        toEnvP s1 \\<and>\n        toEnvP s2 \\<and>\n        substate s1 s2 \\<and>\n        substate s2 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n        (\\<forall>s3. toEnvP s3 \\<and> substate s1 s3 \\<and> substate s3 s2 \\<longrightarrow> getPstate s3 Ctrl = minimalRed) \\<longrightarrow>\n        toEnvNum s1 s2 = ltimeEnv s2 Ctrl - ltimeEnv s1 Ctrl) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n          getPstate s1 Ctrl = redAfterMinimalRed \\<and> getVarBool s1 redAfterMinimalRed = NOT_PRESSED \\<longrightarrow>\n          (\\<exists>s2. toEnvP s2 \\<and>\n                substate s2 s1 \\<and>\n                getPstate s2 Ctrl = minimalRed \\<and>\n                ltimeEnv s2 Ctrl = MINIMAL_RED_TIME_LIMIT \\<and>\n                getVarBool s2 redAfterMinimalRed = NOT_PRESSED \\<and>\n                (\\<forall>s3. toEnvP s3 \\<and> substate s2 s3 \\<and> substate s3 s1 \\<and> s2 \\<noteq> s3 \\<longrightarrow>\n                      getPstate s3 Ctrl = redAfterMinimalRed \\<and>\n                      getVarBool s3 redAfterMinimalRed = NOT_PRESSED \\<and> getVarBool s3 Ctrl = NOT_PRESSED))) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n          getPstate s1 Ctrl = redToGreen \\<longrightarrow>\n          0 < ltimeEnv s1 Ctrl \\<and> ltimeEnv s1 Ctrl \\<le> RED_TO_GREEN_TIME_LIMIT) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n          getPstate s1 Ctrl = redToGreen \\<longrightarrow>\n          (\\<exists>s2. toEnvP s2 \\<and>\n                substate s2 s1 \\<and>\n                toEnvNum s2 s1 = ltimeEnv s1 Ctrl \\<and>\n                getPstate s2 Ctrl = redAfterMinimalRed \\<and>\n                (getVarBool s2 redAfterMinimalRed = PRESSED \\<or> getVarBool s2 Ctrl = PRESSED))) \\<and>\n    (\\<forall>s1 s2.\n        toEnvP s1 \\<and>\n        toEnvP s2 \\<and>\n        substate s1 s2 \\<and>\n        substate s2 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n        toEnvNum s1 s2 < ltimeEnv s2 Ctrl \\<and> getPstate s2 Ctrl = redToGreen \\<longrightarrow>\n        getPstate s1 Ctrl = redToGreen) \\<and>\n    (\\<forall>s1 s2.\n        toEnvP s1 \\<and>\n        toEnvP s2 \\<and>\n        substate s1 s2 \\<and>\n        substate s2 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n        (\\<forall>s3. toEnvP s3 \\<and> substate s1 s3 \\<and> substate s3 s2 \\<longrightarrow> getPstate s3 Ctrl = redToGreen) \\<longrightarrow>\n        toEnvNum s1 s2 = ltimeEnv s2 Ctrl - ltimeEnv s1 Ctrl) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n          getPstate s1 Ctrl = green \\<longrightarrow>\n          0 < ltimeEnv s1 Ctrl \\<and> ltimeEnv s1 Ctrl \\<le> T2) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n          getPstate s1 Ctrl = green \\<longrightarrow>\n          (\\<exists>s2. toEnvP s2 \\<and>\n                substate s2 s1 \\<and>\n                toEnvNum s2 s1 = ltimeEnv s1 Ctrl \\<and>\n                getPstate s2 Ctrl = redToGreen \\<and> ltimeEnv s2 Ctrl = RED_TO_GREEN_TIME_LIMIT)) \\<and>\n    (\\<forall>s1 s2.\n        toEnvP s1 \\<and>\n        toEnvP s2 \\<and>\n        substate s1 s2 \\<and>\n        substate s2 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n        getPstate s2 Ctrl = green \\<and> toEnvNum s1 s2 < ltimeEnv s2 Ctrl \\<longrightarrow>\n        getPstate s1 Ctrl = green) \\<and>\n    (\\<forall>s1 s2.\n        toEnvP s1 \\<and>\n        toEnvP s2 \\<and>\n        substate s1 s2 \\<and>\n        substate s2 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n        (\\<forall>s3. toEnvP s3 \\<and> substate s1 s3 \\<and> substate s3 s2 \\<longrightarrow> getPstate s3 Ctrl = green) \\<longrightarrow>\n        toEnvNum s1 s2 = ltimeEnv s2 Ctrl - ltimeEnv s1 Ctrl) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n          getPstate s1 Ctrl = green \\<longrightarrow>\n          getVarBool s1 minimalRed = PRESSED) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n          getPstate s1 Ctrl \\<noteq> green \\<longrightarrow>\n          getVarBool s1 minimalRed = NOT_PRESSED) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and> substate s1 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<longrightarrow>\n          getPstate s1 Ctrl = minimalRed \\<or>\n          getPstate s1 Ctrl = redAfterMinimalRed \\<or> getPstate s1 Ctrl = redToGreen \\<or> getPstate s1 Ctrl = green) \\<and>\n    (\\<forall>s1 s2.\n        toEnvP s1 \\<and>\n        toEnvP s2 \\<and>\n        substate s1 s2 \\<and>\n        substate s2 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n        toEnvNum s1 s2 < ltimeEnv s2 Ctrl - Ctrl \\<and>\n        getPstate s2 Ctrl = minimalRed \\<and> getVarBool s2 redAfterMinimalRed = NOT_PRESSED \\<longrightarrow>\n        getVarBool s1 Ctrl = NOT_PRESSED) \\<and>\n    (\\<forall>s2. toEnvP s2 \\<and>\n          substate s2 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n          getPstate s2 Ctrl = minimalRed \\<and> getVarBool s2 redAfterMinimalRed = PRESSED \\<longrightarrow>\n          (\\<exists>s1. toEnvP s1 \\<and>\n                substate s1 s2 \\<and> toEnvNum s1 s2 < ltimeEnv s2 Ctrl - Ctrl \\<and> getVarBool s1 Ctrl = PRESSED)) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n          getPstate s1 Ctrl = redAfterMinimalRed \\<and> getVarBool s1 redAfterMinimalRed \\<longrightarrow>\n          (\\<exists>s2. toEnvP s2 \\<and>\n                substate s2 s1 \\<and>\n                toEnvNum s2 s1 = Ctrl \\<and>\n                getPstate s2 Ctrl = minimalRed \\<and>\n                ltimeEnv s2 Ctrl = MINIMAL_RED_TIME_LIMIT \\<and>\n                (getVarBool s2 redAfterMinimalRed \\<or> getVarBool s1 Ctrl = PRESSED))) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n          getPstate s1 Ctrl = green \\<longrightarrow>\n          getVarBool s1 redAfterMinimalRed = NOT_PRESSED)\"\n    apply(rule conjI)\n     apply(rule conjI)\n    apply(simp)\n  proof(rule allI; rule allI; rule allI)\n    fix s1 s2 s3\n    show \"substate s1 s2 \\<and>\n         substate s2 s3 \\<and>\n         substate s3 (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         toEnvP s3 \\<and>\n         toEnvNum s1 s2 = Ctrl \\<and>\n         toEnvNum s2 s3 < T2 \\<and> getVarBool s1 minimalRed \\<noteq> PRESSED \\<and> getVarBool s2 minimalRed = PRESSED \\<longrightarrow>\n         getVarBool s3 minimalRed = PRESSED\"\n    proof cases\n      assume 1: \"s3 =  (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed))\"\n      from ei2 ei0 vc substate_refl have \" ((\\<exists> s2. toEnvP s2 \\<and> substate s2 s0\n \\<and> toEnvNum s2 s0 = ltimeEnv s0 Ctrl  \\<and>\n getPstate s2 Ctrl = green \\<and> ltimeEnv s2 Ctrl = GREEN_TIME_LIMIT) \\<or>\n (\\<forall> s2. toEnvP s2 \\<and> substate s2 s0 \\<longrightarrow> getPstate s2 Ctrl = minimalRed))\"\n        by auto\n      thus ?thesis\n      proof\n        assume \"\\<exists>s2. toEnvP s2 \\<and>\n         substate s2 s0 \\<and> toEnvNum s2 s0 = ltimeEnv s0 Ctrl \\<and> getPstate s2 Ctrl = green \\<and> ltimeEnv s2 Ctrl = T2\"\n        then obtain g where 2: \"toEnvP g \\<and>\n         substate g s0 \\<and> toEnvNum g s0 = ltimeEnv s0 Ctrl \\<and> getPstate g Ctrl = green \\<and> ltimeEnv g Ctrl = T2\" ..\n        show ?thesis\n        proof cases\n          assume 4: \"substate s2 g\" \n          from ei11 2 have \"(\\<exists> s2. toEnvP s2 \\<and> substate s2 g \\<and> toEnvNum s2 g = ltimeEnv g Ctrl \\<and>\ngetPstate s2 Ctrl = redToGreen \\<and> ltimeEnv s2 Ctrl = RED_TO_GREEN_TIME_LIMIT)\" by blast\n          then obtain rg where 3: \" toEnvP rg \\<and> substate rg g \\<and> toEnvNum rg g = ltimeEnv g Ctrl \\<and>\ngetPstate rg Ctrl = redToGreen \\<and> ltimeEnv rg Ctrl = RED_TO_GREEN_TIME_LIMIT\" ..\n          show ?thesis\n          proof cases\n            assume 5: \"substate s2 rg\"\n            from ei0 have \"0 < ltimeEnv s0 Ctrl\" by ((cases s0); auto)\n            with 2 3 toEnvNum3[of rg g s0] substate_trans[of rg g s0] have 6: \"toEnvNum rg s0 > T2\"\n              by auto\n            from 2 3 substate_trans have \"substate rg s0\" by blast\n            with 5 6 toEnvNum3[of s2 rg s0] substate_trans[of s2 rg s0] have \"toEnvNum s2 s0 > T2\"\n              by auto\n            with 1 show ?thesis by auto\n          next\n            assume 5: \"\\<not> (substate s2 rg)\"\n            with 3 4 substate_refl substate_total have 6: \"substate rg s2 \\<and> rg \\<noteq> s2\" by auto\n            show ?thesis\n            proof\n              assume 7: \"substate s1 s2 \\<and>\n         substate s2 s3 \\<and>\n         substate s3  (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         toEnvP s3 \\<and>\n         toEnvNum s1 s2 = Ctrl \\<and>\n         toEnvNum s2 s3 < T2 \\<and> getVarBool s1 minimalRed \\<noteq> PRESSED \\<and> getVarBool s2 minimalRed = PRESSED\"\n              show \"getVarBool s3 minimalRed = PRESSED\"\n              proof cases\n                assume 8: \"substate s1 rg\"\n               from ei0 have \"0 < ltimeEnv s0 Ctrl\" by ((cases s0); auto)\n            with 2 3 toEnvNum3[of rg g s0] substate_trans[of rg g s0] have 6: \"toEnvNum rg s0 > T2\"\n              by auto\n            from 2 3 substate_trans have \"substate rg s0\" by blast\n            with 8 6 toEnvNum3 have 9: \"toEnvNum s1 s0 > T2\" by auto\n            from 1 7 9 have 10: \"substate s2 s0\" by ((simp split: if_splits); auto)\n            with 7 9 toEnvNum3 have \"toEnvNum s2 s0 \\<ge> T2\" by auto\n            with 1 10 substate_refl toEnvNum3[of s2 s0 s3] have \"toEnvNum s2 s3 > T2\" by auto\n            with 7 show ?thesis by auto\n          next \n            assume 8: \"\\<not> substate s1 rg\"\n            from 4 7 substate_trans have 9: \"substate s1 g\" by blast\n            from 2 4 substate_trans have 10: \"substate s2 s0\" by blast\n            with 1 7 substate_refl substate_asym[of s0 s3]  have \"toEnvNum s2 s0 + 1 < T2\" by ((simp split: if_splits); auto)\n            with 7 10 toEnvNum3 have \"toEnvNum s1 s0 < T2\" by auto\n            with 2 9 toEnvNum3 have \"toEnvNum s1 g < ltimeEnv g Ctrl\" by auto\n            with 2 7 9 ei12 have \"getPstate s1 Ctrl = green\" by blast\n            with ei14 7 show ?thesis using 2 9 substate_trans by blast\n          qed\n        qed\n      qed\n    next\n      assume 4: \"\\<not> substate s2 g\"\n      show ?thesis\n      proof\n        assume 7: \"substate s1 s2 \\<and>\n         substate s2 s3 \\<and>\n         substate s3  (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         toEnvP s3 \\<and>\n         toEnvNum s1 s2 = Ctrl \\<and>\n         toEnvNum s2 s3 < T2 \\<and> getVarBool s1 minimalRed \\<noteq> PRESSED \\<and> getVarBool s2 minimalRed = PRESSED\"\n        have \"getVarBool s2 minimalRed =NOT_PRESSED\"\n        proof cases\n          assume 3: \"s2 =  (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed))\"\n          from vc have \"getPstate s0 Ctrl \\<noteq> green\" by auto\n          with ei0 substate_refl ei15 have \"getVarBool s0 trafficLight = RED\" by blast\n          with 3 show ?thesis by auto\n        next \n          assume 3: \"s2 \\<noteq>  (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed))\"\n          with 1 7 have 5: \"substate s2 s0\" by ((simp split: if_splits); auto)\n          from 4 2 5 substate_total substate_refl have 6: \"substate g s2 \\<and> s2 \\<noteq> g\" by blast\n          with 2 7 gtimeE_inj have 9: \"toEnvNum emptyState g \\<noteq> toEnvNum emptyState s2\" by blast\n           from 5 6 toEnvNum3 have \"toEnvNum s2 s0 \\<le> toEnvNum g s0\" by auto\n          from le_imp_less_or_eq[OF this]\n          show ?thesis\n          proof\n            assume \"toEnvNum s2 s0 < toEnvNum g s0\"\n            with 2 have 8: \"toEnvNum s2 s0 < ltimeEnv s0 Ctrl\" by auto\n            from vc have \"getPstate s0 Ctrl = minimalRed\" by auto\n            with ei3 7 ei0 5 substate_refl 8 have \"getPstate s2 Ctrl = minimalRed\" by blast\n            with 5 7 ei15 show ?thesis by auto\n          next \n            assume \"toEnvNum s2 s0 = toEnvNum g s0\"\n            with 9 have 10: \"toEnvNum emptyState g +toEnvNum g s0 \\<noteq> toEnvNum emptyState s2 +toEnvNum s2 s0\"\n              by auto\n            from emptyState_substate 5 toEnvNum3 have 11: \"toEnvNum emptyState s0 = toEnvNum emptyState s2 + toEnvNum s2 s0\"\n              by auto \n            from emptyState_substate 5 6 substate_trans[of g s2 s0]  toEnvNum3 \n            have  \"toEnvNum emptyState s0 = toEnvNum emptyState g + toEnvNum g s0\"\n              by auto\n            with 10 11 show ?thesis by auto\n          qed\n        qed\n        with 7 show \" getVarBool s3 minimalRed = PRESSED\" by auto\n      qed\n    qed\n  next\n    assume 2: \" \\<forall>s2. toEnvP s2 \\<and> substate s2 s0 \\<longrightarrow> getPstate s2 Ctrl = minimalRed \"\n    show \" \\<forall>s2. toEnvP s2 \\<and> substate s2 s0 \\<longrightarrow> getPstate s2 Ctrl = minimalRed \\<Longrightarrow>\n    substate s1 s2 \\<and>\n    substate s2 s3 \\<and>\n    substate s3\n      (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n    toEnvP s1 \\<and>\n    toEnvP s2 \\<and>\n    toEnvP s3 \\<and>\n    toEnvNum s1 s2 = Ctrl \\<and>\n    toEnvNum s2 s3 < T2 \\<and> getVarBool s1 minimalRed \\<noteq> PRESSED \\<and> getVarBool s2 minimalRed = PRESSED \\<longrightarrow>\n    getVarBool s3 minimalRed = PRESSED\"\n    proof cases\n       assume 3: \"s2 =   (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed))\"\n       from vc have \"getPstate s0 Ctrl \\<noteq> green\" by auto\n          with ei0 substate_refl ei15 have \"getVarBool s0 trafficLight = RED\" by blast\n          with 3 show ?thesis by auto\n        next \n          assume 3: \"s2 \\<noteq>   (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed))\"\n          show ?thesis\n          proof\n            assume 7: \"substate s1 s2 \\<and>\n    substate s2 s3 \\<and>\n    substate s3\n     (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n    toEnvP s1 \\<and>\n    toEnvP s2 \\<and>\n    toEnvP s3 \\<and>\n    toEnvNum s1 s2 = Ctrl \\<and>\n    toEnvNum s2 s3 < T2 \\<and> getVarBool s1 minimalRed \\<noteq> PRESSED \\<and> getVarBool s2 minimalRed = PRESSED\"\n            with 1  3 have \"substate s2 s0\" by ((simp split: if_splits); auto)\n            with 2 7 ei15  show \"  getVarBool s3 minimalRed = PRESSED\" by auto\n          qed\n        qed\n      qed\n    next\n      assume 1: \" s3 \\<noteq>\n   (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed))\"\n      show ?thesis\n      proof\n        print_state\n        assume 7: \"substate s1 s2 \\<and>\n    substate s2 s3 \\<and>\n    substate s3\n    (toEnv (setPstate (setVarAny s0 requestButtonValue) Ctrl redAfterMinimalRed)) \\<and>\n    toEnvP s1 \\<and>\n    toEnvP s2 \\<and>\n    toEnvP s3 \\<and>\n    toEnvNum s1 s2 = Ctrl \\<and>\n    toEnvNum s2 s3 < T2 \\<and> getVarBool s1 minimalRed \\<noteq> PRESSED \\<and> getVarBool s2 minimalRed = PRESSED\"\n        with 1 have \"substate s3 s0\" by ((simp split: if_splits); auto)\n        with 7 reqs0         show \" getVarBool s3 minimalRed = PRESSED\" by blast\n      qed\n    qed\n  next\n    (*prove extraInv*)\n", "meta": {"author": "ivchernenko", "repo": "post_vcgenerator", "sha": "fadfff131086870a027d6bd1c78b8d5a3baf183b", "save_path": "github-repos/isabelle/ivchernenko-post_vcgenerator", "path": "github-repos/isabelle/ivchernenko-post_vcgenerator/post_vcgenerator-fadfff131086870a027d6bd1c78b8d5a3baf183b/case-studies/trafficLights/Proof_2_4.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6619228758499942, "lm_q2_score": 0.40356685373537454, "lm_q1q2_score": 0.2671301324222531}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory LemmaBucket_C\nimports\n  \"Lib.Lib\"\n  \"Word_Lib.WordSetup\"\n  TypHeapLib\n  \"CParser.ArrayAssertion\"\nbegin\n\ndeclare word_neq_0_conv [simp del]\n\nlemma Ptr_not_null_pointer_not_zero: \"(Ptr p \\<noteq> NULL)=(p\\<noteq>0)\"\n by simp\n\nlemma hrs_mem_f: \"f (hrs_mem s) = hrs_mem (hrs_mem_update f s)\"\n  apply (cases s)\n  apply (clarsimp simp: hrs_mem_def hrs_mem_update_def)\n  done\n\nlemma hrs_mem_heap_update:\n     \"heap_update p v (hrs_mem s) = hrs_mem (hrs_mem_update (heap_update p v) s)\"\n  apply (rule hrs_mem_f)\n  done\n\nlemma addr_card_wb:\n  \"addr_card = 2 ^ word_bits\"\n  by (simp add: addr_card_def card_word word_bits_conv)\n\nlemma surj_Ptr [simp]:\n  \"surj Ptr\"\n  by (rule surjI [where f = ptr_val], simp)\n\nlemma inj_Ptr [simp]:\n  \"inj Ptr\"\n  apply (rule injI)\n  apply simp\n  done\n\nlemma bij_Ptr :\n  \"bij Ptr\"\n  by (simp add: bijI)\n\nlemma exec_Guard:\n  \"(G \\<turnstile> \\<langle>Guard Err S c, Normal s\\<rangle> \\<Rightarrow> s')\n       = (if s \\<in> S then G \\<turnstile> \\<langle>c, Normal s\\<rangle> \\<Rightarrow> s'\n                else s' = Fault Err)\"\n  by (auto split: if_split elim!: exec_elim_cases intro: exec.intros)\n\nlemma to_bytes_word8:\n  \"to_bytes (v :: word8) xs = [v]\"\n  by (simp add: to_bytes_def typ_info_word word_rsplit_same)\n\nlemma byte_ptr_guarded:\"ptr_val (x::8 word ptr) \\<noteq> 0 \\<Longrightarrow> c_guard x\"\n  unfolding c_guard_def c_null_guard_def ptr_aligned_def\n  by (clarsimp simp: intvl_Suc)\n\nlemma heap_update_list_append:\n  fixes v :: word8\n  shows \"heap_update_list s (xs @ ys) hp =\n  heap_update_list (s + of_nat (length xs)) ys (heap_update_list s xs hp)\"\nproof (induct xs arbitrary: ys rule: rev_induct)\n  case Nil\n  show ?case by simp\nnext\n  case (snoc v' vs')\n  show ?case\n    apply (simp add: snoc.hyps field_simps)\n    apply (rule arg_cong [where f = \"heap_update_list (1 + (s + of_nat (length vs'))) ys\"])\n    apply (rule ext)\n    apply simp\n    done\nqed\n\nlemma intvl_aligned_bottom_eq:\n  fixes p :: \"'a::len word\"\n  assumes al1: \"is_aligned x n\"\n  and     al2: \"is_aligned p bits\"\n  and      nb: \"\\<not> n < bits\"\n  and     off: \"off \\<le> 2 ^ bits\" \"off \\<noteq> 0\"\n  shows  \"(x \\<in> {p ..+ off}) = (x = p)\"\nproof (rule iffI)\n  assume \"x = p\"\n  thus \"x \\<in> {p ..+ off}\" using off\n    by (simp add: intvl_self)\nnext\n  assume x_in_intvl: \"x \\<in> {p ..+ off}\"\n\n  show \"x = p\"\n  proof cases\n    assume wb: \"bits < len_of TYPE('a)\"\n\n    from x_in_intvl obtain kp where xp: \"x = p + of_nat kp\" and kp: \"kp < off\"\n      by (clarsimp dest!: intvlD)\n\n    hence \"is_aligned (p + of_nat kp) n\" using al1 by simp\n    hence \"2 ^ n dvd unat (p + of_nat kp)\" unfolding is_aligned_def .\n    hence \"2 ^ n dvd unat p + kp\" using kp off wb\n      apply -\n      apply (subst (asm) iffD1 [OF unat_plus_simple])\n       apply (rule is_aligned_no_wrap' [OF al2])\n       apply (rule of_nat_power)\n        apply simp_all[2]\n      apply (subst (asm) unat_of_nat)\n      apply (subst (asm) mod_less)\n       apply (erule order_less_le_trans)\n       apply (erule order_trans)\n       apply simp\n      apply simp\n      done\n\n  moreover from al2 obtain q2 where pbits: \"p = 2 ^ bits * of_nat q2\"\n                                and q2: \"q2 < 2 ^ (len_of TYPE('a) - bits)\"\n    by (rule is_alignedE)\n\n  moreover from nb obtain kn where nbits: \"n = bits + kn\"\n    by (clarsimp simp: linorder_not_less le_iff_add)\n\n  ultimately have \"2 ^ bits dvd 2 ^ bits * q2 + kp\"\n    apply (simp add: power_add)\n    apply (simp add: unat_mult_power_lem [OF q2])\n    apply (erule dvd_mult_left)\n    done\n\n  hence \"2 ^ bits dvd kp\" by (simp add: dvd_reduce_multiple)\n  with kp have \"kp = 0\"\n    apply -\n    apply (erule contrapos_pp)\n    apply (simp add: linorder_not_less)\n    apply (drule (1) dvd_imp_le)\n    apply (erule order_trans [OF off(1)])\n    done\n\n  thus ?thesis using xp by simp\n  next\n    assume wb: \"\\<not> bits < len_of TYPE('a)\"\n    with assms\n    show ?thesis by (simp add: is_aligned_mask mask_def power_overflow)\n  qed\nqed\n\nlemma intvl_mem_weaken: \"x \\<in> {p..+a - n} \\<Longrightarrow> x \\<in> {p..+a}\"\n  apply -\n  apply (drule intvlD)\n  apply clarsimp\n  apply (rule intvlI)\n  apply simp\n  done\n\n\nlemma upto_intvl_eq:\n  fixes x :: \"'a::len word\"\n  assumes al: \"is_aligned x n\"\n  shows \"{x..+2 ^ n} = {x .. x + 2 ^ n - 1}\"\nproof cases\n  assume \"n < len_of TYPE('a)\"\n  with assms show ?thesis\n  unfolding intvl_def\n  apply simp\n  apply rule\n   apply clarsimp\n   apply (subgoal_tac \"of_nat k < (2 :: 'a word) ^ n\")\n    apply (intro conjI)\n     apply (erule (1) is_aligned_no_wrap')\n    apply (subst p_assoc_help)\n    apply (rule word_plus_mono_right)\n     apply (simp add: word_less_sub_1)\n    apply (simp add: field_simps is_aligned_no_overflow)\n   apply (simp add: of_nat_power)\n  apply clarsimp\n  apply (rule_tac x = \"unat (xa - x)\" in exI)\n  apply clarsimp\n  apply (rule unat_less_power, assumption)\n  apply (subst word_less_sub_le [symmetric])\n   apply assumption\n  apply (rule word_diff_ls'(4))\n   apply (simp add: field_simps)\n  apply assumption\n  done\nnext\n  assume \"\\<not> n < len_of TYPE('a)\"\n  with assms show ?thesis\n    apply (simp add: is_aligned_mask mask_def power_overflow intvl_def)\n    apply (rule set_eqI)\n    apply clarsimp\n    apply (rename_tac w)\n    apply (case_tac w)\n    apply (rename_tac m)\n    apply (rule_tac x=m in exI)\n    apply simp\n    apply (erule order_less_le_trans)\n    apply simp\n    done\nqed\n\nlemma upto_intvl_eq':\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk> x \\<le> x + (of_nat b - 1); b \\<noteq> 0; b \\<le> 2 ^ len_of TYPE('a)\\<rbrakk> \\<Longrightarrow> {x..+b} = {x .. x + of_nat b - 1}\"\n  unfolding intvl_def\n  apply rule\n   apply clarsimp\n   apply (subgoal_tac \"of_nat k \\<le> (of_nat (b - 1) :: 'a word)\")\n    apply (intro conjI)\n     apply (erule word_random)\n     apply simp\n    apply (subst field_simps [symmetric], rule word_plus_mono_right)\n     apply simp\n    apply assumption\n   apply (subst Word_Lemmas.of_nat_mono_maybe_le [symmetric])\n     apply simp\n    apply simp\n   apply simp\n  apply clarsimp\n  apply (rule_tac x = \"unat (xa - x)\" in exI)\n  apply simp\n  apply (simp add: unat_sub)\n  apply (rule nat_diff_less)\n   apply (subst (asm) word_le_nat_alt, erule order_le_less_trans)\n   apply (subst add_diff_eq[symmetric], subst unat_plus_if')\n   apply (simp add: no_olen_add_nat)\n   apply (simp add: le_eq_less_or_eq)\n   apply (erule disjE)\n    apply (subst unat_minus_one)\n     apply (erule (1) of_nat_neq_0)\n    apply (simp add: unat_of_nat)\n   apply (erule ssubst, rule unat_lt2p)\n  apply (simp add: word_le_nat_alt)\n  done\n\nlemma intvl_aligned_top:\n  fixes x :: \"'a::len word\"\n  assumes al1: \"is_aligned x n\"\n  and     al2: \"is_aligned p bits\"\n  and      nb: \"n \\<le> bits\"\n  and    offn: \"off < 2 ^ n\"\n  and      wb: \"bits < len_of TYPE('a)\"\n  shows  \"(x \\<in> {p ..+ 2 ^ bits - off}) = (x \\<in> {p ..+ 2 ^ bits})\"\nproof (rule iffI)\n  assume \"x \\<in> {p..+2 ^ bits - off}\"\n  thus \"x \\<in> {p..+2 ^ bits}\" by (rule intvl_mem_weaken)\nnext\n  assume asm: \"x \\<in> {p..+2 ^ bits}\"\n\n  show \"x \\<in> {p..+2 ^ bits - off}\"\n  proof (cases \"n = 0\")\n    case True\n    with offn asm show ?thesis by simp\n  next\n    case False\n\n    from asm have \"x \\<in> {p .. p + 2 ^ bits - 1}\"\n      by (simp add: upto_intvl_eq [OF al2])\n    then obtain q where xp: \"x = p + of_nat (q * 2 ^ n)\" and qb: \"q < 2 ^ (bits - n)\" using False nb\n      by (fastforce dest!: is_aligned_diff[OF al1 al2 wb,simplified field_simps])\n\n    have \"q * 2 ^ n < 2 ^ bits - off\"\n    proof -\n      show ?thesis using offn qb nb\n        apply (simp add: less_diff_conv)\n        apply (erule (1) nat_add_offset_less)\n        apply arith\n        done\n    qed\n\n    with xp show ?thesis\n      apply -\n      apply (erule ssubst)\n      apply (erule intvlI)\n      done\n  qed\nqed\n\nlemma intvl_nowrap:\n  fixes x :: \"'a::len word\"\n  shows \"\\<lbrakk>y \\<noteq> 0; unat y + z \\<le> 2 ^ len_of TYPE('a)\\<rbrakk> \\<Longrightarrow> x \\<notin> {x + y ..+ z}\"\n  apply clarsimp\n  apply (drule intvlD)\n  apply clarsimp\n  apply (simp add: unat_arith_simps)\n  apply (simp split: if_split_asm)\n  apply (simp add: unat_of_nat)\n  done\n\nlemma heap_update_list_update:\n  fixes v :: word8\n  shows \"x \\<noteq> y \\<Longrightarrow> heap_update_list s xs (hp(y := v)) x = heap_update_list s xs hp x\"\n  apply (induct xs rule: rev_induct)\n   apply simp\n  apply (simp add: heap_update_list_append cong: if_cong)\n  done\n\n(* FIXME: generalise *)\nlemma heap_update_list_append2:\n  \"length xs + length ys < 2 ^ word_bits \\<Longrightarrow>\n    heap_update_list s (xs @ ys) hp\n      = heap_update_list s xs (heap_update_list (s + of_nat (length xs)) ys hp)\"\nproof (induct xs arbitrary: hp s)\n  case Nil\n  show ?case by simp\nnext\n  case (Cons v' vs')\n\n  have \"(1 :: addr) + of_nat (length vs') = of_nat (length (v' # vs'))\"\n    by simp\n  also have \"\\<dots> \\<noteq> 0\" using Cons.prems\n    apply -\n    apply (rule of_nat_neq_0)\n    apply simp\n    apply (simp add: word_bits_conv)\n    done\n  finally have neq0: \"(1 :: addr) + of_nat (length vs') \\<noteq> 0\" .\n\n  have \"(1 :: addr) + of_nat (length vs') = of_nat (length (v' # vs'))\"\n    by simp\n  also have \"unat \\<dots> + length ys < 2 ^ word_bits\" using Cons.prems\n    apply (subst unat_of_nat)\n    apply (simp add: word_bits_conv)\n    done\n  finally have lt: \"unat ((1 :: addr) + of_nat (length vs')) + length ys < 2 ^ word_bits\" .\n\n  from Cons.prems have \"length vs' + length ys < 2 ^ word_bits\" by simp\n  thus ?case\n    apply simp\n    apply (subst Cons.hyps, assumption)\n    apply (rule arg_cong [where f = \"heap_update_list (s + 1) vs'\"])\n    apply (rule ext)\n    apply (case_tac \"x = s\")\n     apply simp\n     apply (subst heap_update_nmem_same)\n     apply (subst add.assoc)\n     apply (rule intvl_nowrap[OF neq0 order_less_imp_le\n                                      [OF lt[unfolded word_bits_def]]])\n    apply simp\n    apply (clarsimp simp: heap_update_list_update field_simps)\n   done\nqed\n\nlemma heap_update_word8:\n  \"heap_update p (v :: word8) hp = hp(ptr_val p := v)\"\n  unfolding heap_update_def by (simp add: to_bytes_word8)\n\nlemma index_foldr_update2:\n  \"\\<lbrakk> n \\<le> i; i < CARD('b::finite) \\<rbrakk> \\<Longrightarrow> index (foldr (\\<lambda>n arr. Arrays.update arr n m) [0..<n] (x :: ('a,'b) array)) i = index x i\"\n  apply (induct n arbitrary: x)\n   apply simp\n  apply simp\n  done\n\nlemma index_foldr_update:\n  \"\\<lbrakk> i < n; n \\<le> CARD('b::finite) \\<rbrakk> \\<Longrightarrow> index (foldr (\\<lambda>n arr. Arrays.update arr n m) [0..<n]  (x :: ('a,'b) array)) i = m\"\n  apply (induct n arbitrary: x)\n   apply simp\n  apply simp\n  apply (erule less_SucE)\n   apply simp\n  apply simp\n  apply (subst index_foldr_update2)\n    apply simp\n   apply simp\n  apply simp\n  done\n\nlemma intvl_disjoint1:\n  fixes a :: \"'a :: len word\"\n  assumes abc: \"a + of_nat b \\<le> c\"\n  and     alb: \"a \\<le> a + of_nat b\"\n  and     cld: \"c \\<le> c + of_nat d\"\n  and     blt: \"b < 2 ^ len_of TYPE('a)\"\n  and     dlt: \"d < 2 ^ len_of TYPE('a)\"\n  shows   \"{a..+b} \\<inter> {c..+d} = {}\"\nproof (rule disjointI, rule notI)\n  fix x y\n  assume x: \"x \\<in> {a..+b}\" and y: \"y \\<in> {c..+d}\" and xy: \"x = y\"\n\n  from x obtain kx where \"x = a + of_nat kx\" and kx: \"kx < b\"\n    by (clarsimp dest!: intvlD)\n\n  moreover from y obtain ky where \"y = c + of_nat ky\" and ky: \"ky < d\"\n    by (clarsimp dest!: intvlD)\n\n  ultimately have ac: \"a + of_nat kx = c + of_nat ky\" using xy by simp\n\n  have \"of_nat kx < (of_nat b :: 'a word)\" using blt kx\n    by (rule of_nat_mono_maybe)\n  hence \"a + of_nat kx < a + of_nat b\" using alb\n    by (rule word_plus_strict_mono_right)\n\n  also have \"\\<dots> \\<le> c\" by (rule abc)\n  also have \"\\<dots> \\<le> c + of_nat ky\" using cld dlt ky\n    by - (rule word_random [OF _ iffD1 [OF Word_Lemmas.of_nat_mono_maybe_le]], simp+ )\n  finally show False using ac by simp\nqed\n\nlemma intvl_disjoint2:\n  fixes a :: \"'a :: len word\"\n  assumes abc: \"a + of_nat b \\<le> c\"\n  and     alb: \"a \\<le> a + of_nat b\"\n  and     cld: \"c \\<le> c + of_nat d\"\n  and     blt: \"b < 2 ^ len_of TYPE('a)\"\n  and     dlt: \"d < 2 ^ len_of TYPE('a)\"\n  shows   \"{c..+d} \\<inter> {a..+b} = {}\"\n  using abc alb cld blt dlt\n  by (subst Int_commute, rule intvl_disjoint1)\n\n\nlemma intvl_off_disj:\n  fixes x :: addr\n  assumes ylt: \"y \\<le> off\"\n  and    zoff: \"z + off < 2 ^ word_bits\"\n  shows   \"{x ..+ y} \\<inter> {x + of_nat off ..+ z} = {}\"\n  using ylt zoff\n  apply (cases \"off = 0\")\n   apply simp\n  apply (rule contrapos_pp [OF TrueI])\n  apply (drule intvl_inter)\n  apply (erule disjE)\n   apply (cut_tac intvl_nowrap [where x = x and y = \"of_nat off :: addr\" and z = z])\n     apply simp\n    apply (rule of_nat_neq_0)\n     apply simp\n    apply (unfold word_bits_len_of)\n    apply simp\n   apply (simp add: unat_of_nat word_bits_conv)\n  apply (drule intvlD)\n  apply clarsimp\n  apply (drule (1) order_less_le_trans)\n  apply (drule unat_cong)\n  apply (simp add: unat_of_nat word_bits_conv)\n  done\n\n\nlemma list_map_comono:\n  assumes  s: \"list_map m \\<subseteq>\\<^sub>m list_map n\"\n  shows    \"m \\<le> n\"\n  using s\nproof (induct m arbitrary: n rule: rev_induct)\n  case Nil thus ?case unfolding list_map_def by simp\nnext\n  case (snoc x xs)\n\n  from snoc.prems have\n    sm: \"[length xs \\<mapsto> x] ++ list_map xs \\<subseteq>\\<^sub>m list_map n\"\n    unfolding list_map_def by simp\n\n  hence xsn: \"xs \\<le> n\"\n    by (rule snoc.hyps [OF map_add_le_mapE])\n\n  have \"list_map n (length xs) = Some x\" using sm\n    by (simp add: map_le_def list_map_def merge_dom2 set_zip)\n\n  hence \"length xs < length n\" and \"x = n ! length xs\"\n    by (auto simp add: list_map_eq split: if_split_asm)\n\n  thus \"xs @ [x] \\<le> n\" using xsn\n    by (simp add: append_one_prefix less_eq_list_def)\nqed\n\nlemma typ_slice_t_self:\n  \"td \\<in> fst ` set (typ_slice_t td m)\"\n  apply (cases td)\n  apply (simp split: if_split)\n  done\n\nlemma drop_heap_list_le2:\n  \"heap_list h n (x + of_nat k)\n      = drop k (heap_list h (n + k) x)\"\n  by (simp add: drop_heap_list_le)\n\nlemma index_fold_update:\n  \"\\<lbrakk> distinct xs; set xs \\<subseteq> {..< card (UNIV :: 'b set)}; n < card (UNIV :: 'b set) \\<rbrakk> \\<Longrightarrow>\n   index (foldr (\\<lambda>n (arr :: 'a['b :: finite]). Arrays.update arr n (f n (index arr n))) xs v) n\n     = (if n \\<in> set xs then f n (index v n) else index v n)\"\n  apply (induct xs)\n   apply simp\n  apply (rename_tac x xs)\n  apply (case_tac \"x = n\"; simp)\n  done\n\nlemma heap_update_list_id:\n  \"heap_list hp n ptr = xs \\<Longrightarrow> heap_update_list ptr xs hp = hp\"\n  apply (induct xs arbitrary: ptr n)\n   apply simp\n  apply simp\n  apply (case_tac n, simp_all)\n  apply (clarsimp simp add: fun_upd_idem)\n  done\n\nlemma size_td_list_map2: \"\\<And>f adjs. \\<lbrakk> \\<And>a. size_td_pair (f a) = size_td_pair a \\<rbrakk>\n                           \\<Longrightarrow> size_td_list (map f adjs) = size_td_list adjs\"\n  by (induct_tac adjs, simp_all)\n\nlemma hrs_mem_update_cong:\n  \"\\<lbrakk> \\<And>x. f x = f' x \\<rbrakk> \\<Longrightarrow> hrs_mem_update f = hrs_mem_update f'\"\n  by (simp add: hrs_mem_update_def)\n\nlemma Guard_no_cong:\n  \"\\<lbrakk> A=A'; c=c' \\<rbrakk> \\<Longrightarrow> Guard A P c = Guard A' P c'\"\n  by simp\n\nlemma heap_update_list_concat_fold:\n  assumes \"ptr' = ptr + of_nat (length ys)\"\n  shows \"heap_update_list ptr' xs (heap_update_list ptr ys s)\n    = heap_update_list ptr (ys @ xs) s\"\n  unfolding assms\n  apply (induct ys arbitrary: ptr s)\n   apply simp\n  apply simp\n  apply (elim meta_allE)\n  apply (erule trans[rotated])\n  apply (simp add: field_simps)\n  done\n\nlemma heap_update_list_concat_fold_hrs_mem:\n  \"ptr' = ptr + of_nat (length ys) \\<Longrightarrow>\n   hrs_mem_update (heap_update_list ptr' xs)\n        (hrs_mem_update (heap_update_list ptr ys) s)\n    = hrs_mem_update (heap_update_list ptr (ys @ xs)) s\"\n  by (simp add: hrs_mem_update_def split_def\n                heap_update_list_concat_fold)\n\nlemmas heap_update_list_concat_unfold\n    = heap_update_list_concat_fold[OF refl, symmetric]\n\nlemma coerce_heap_update_to_heap_updates:\n  assumes n: \"n = chunk * m\" and len: \"length xs = n\"\n  shows \"heap_update_list x xs\n      = (\\<lambda>s. foldl (\\<lambda>s n. heap_update_list (x + (of_nat n * of_nat chunk))\n                                      (take chunk (drop (n * chunk) xs)) s)\n                     s [0 ..< m])\"\n  using len[simplified n]\n  apply (induct m arbitrary: x xs)\n   apply (rule ext, simp)\n  apply (rule ext)\n  apply (simp only: upt_conv_Cons map_Suc_upt[symmetric])\n  apply (subgoal_tac \"\\<exists>ys zs. length ys = chunk \\<and> xs = ys @ zs\")\n   apply (clarsimp simp: heap_update_list_concat_unfold foldl_map\n                         field_simps)\n  apply (rule_tac x=\"take chunk xs\" in exI)\n  apply (rule_tac x=\"drop chunk xs\" in exI)\n  apply simp\n  done\n\nlemma update_ti_list_array':\n  \"\\<lbrakk> update_ti_list_t (map f [0 ..< n]) xs v = y;\n     \\<forall>n. size_td_pair (f n) = v3; length xs = v3 * n;\n     \\<forall>m xs v'. length xs = v3 \\<and> m < n \\<longrightarrow>\n       update_ti_pair_t (f m) xs v' = Arrays.update v' m (update_ti_t (g m) xs (index v' m)) \\<rbrakk>\n    \\<Longrightarrow> y = foldr (\\<lambda>n arr. Arrays.update arr n (update_ti_t (g n) (take v3 (drop (v3 * n) xs)) (index arr n))) [0 ..< n] v\"\n  apply (subgoal_tac \"\\<forall>ys. size_td_list (map f ys) = v3 * length ys\")\n   prefer 2\n   apply (rule allI, induct_tac ys, simp+)\n  apply (induct n arbitrary: xs y v)\n   apply simp\n  apply (simp add: access_ti_append)\n  apply (elim meta_allE, drule(1) meta_mp)\n  apply simp\n  apply (rule foldr_cong, (rule refl)+)\n  apply (simp add: take_drop)\n  apply (subst min.absorb1)\n   apply (fold mult_Suc_right, rule mult_le_mono2)\n   apply simp\n  apply simp\n  done\n\nlemma update_ti_list_array:\n  \"\\<lbrakk> update_ti_list_t (map f [0 ..< n]) xs v = (y :: 'a['b :: finite]);\n     \\<forall>n. size_td_pair (f n) = v3; length xs = v3 * n;\n     \\<forall>m xs v'. length xs = v3 \\<and> m < n \\<longrightarrow>\n       update_ti_pair_t (f m) xs v' = Arrays.update v' m (update_ti_t (g m) xs (index v' m));\n      n \\<le> card (UNIV :: 'b set) \\<rbrakk>\n    \\<Longrightarrow> \\<forall>m < n. update_ti_t (g m) (take v3 (drop (v3 * m) xs)) (index v m) = index y m\"\n  apply (subst update_ti_list_array'[where y=y], assumption+)\n  apply clarsimp\n  apply (subst index_fold_update)\n     apply clarsimp+\n  done\n\nlemma access_in_array:\n  fixes y :: \"('a :: c_type)['b :: finite]\"\n  assumes assms: \"h_val hp x = y\"\n                 \"n < card (UNIV :: 'b set)\"\n     and subst: \"\\<forall>xs v. length xs = size_of TYPE('a)\n                     \\<longrightarrow> update_ti_t (typ_info_t TYPE('a)) xs v = f xs\"\n  shows \"h_val hp\n           (Ptr (ptr_val x + of_nat (n * size_of TYPE('a)))) = index y n\"\n  using assms\n  apply (simp add: h_val_def drop_heap_list_le2 del: of_nat_mult)\n  apply (subst take_heap_list_le[symmetric, where n=\"card (UNIV :: 'b set) * size_of TYPE ('a)\"])\n   apply (fold mult_Suc, rule mult_le_mono1)\n   apply simp\n  apply (simp add: from_bytes_def typ_info_array')\n  apply (drule update_ti_list_array, simp+)\n     apply (simp add: size_of_def)\n    apply (clarsimp simp: update_ti_s_adjust_ti)\n    apply (rule refl)\n   apply simp\n  apply (drule spec, drule(1) mp)\n  apply (simp add: size_of_def ac_simps drop_take)\n  apply (subgoal_tac \"length v = size_of TYPE('a)\" for v)\n   apply (subst subst, assumption)\n   apply (subst(asm) subst, assumption)\n   apply simp\n  apply (simp add: size_of_def)\n  apply (subst le_diff_conv2)\n   apply simp\n  apply (fold mult_Suc, rule mult_le_mono1)\n  apply simp\n  done\n\nlemma access_ti_list_array:\n  \"\\<lbrakk> \\<forall>n. size_td_pair (f n) = v3; length xs = v3 * n;\n     \\<forall>m. m < n \\<and> v3 \\<le> length (drop (v3 * m) xs)\n        \\<longrightarrow> access_ti_pair (f m) (FCP g) (take v3 (drop (v3 * m) xs)) = (h m)\n          \\<rbrakk> \\<Longrightarrow>\n   access_ti_list (map f [0 ..< n]) (FCP g) xs\n     = foldl (@) [] (map h [0 ..< n])\"\n  apply (subgoal_tac \"\\<forall>ys. size_td_list (map f ys) = v3 * length ys\")\n   prefer 2\n   apply (rule allI, induct_tac ys, simp+)\n  apply (induct n arbitrary: xs)\n   apply simp\n  apply (simp add: access_ti_append)\n  apply (erule_tac x=\"take (v3 * n) xs\" in meta_allE)\n  apply simp\n  apply (frule spec, drule mp, rule conjI, rule lessI)\n   apply simp\n  apply simp\n  apply (erule meta_mp)\n  apply (auto simp add: drop_take)\n  done\n\nlemma take_drop_foldl_concat:\n  \"\\<lbrakk> \\<And>y. y < m \\<Longrightarrow> length (f y) = n; x < m \\<rbrakk>\n      \\<Longrightarrow> take n (drop (x * n) (foldl (@) [] (map f [0 ..< m]))) = f x\"\n  apply (subst split_upt_on_n, assumption)\n  apply (simp only: foldl_concat_concat map_append)\n  apply (subst drop_append_miracle)\n   apply (induct x, simp_all)[1]\n  apply simp\n  done\n\ndefinition\n  array_ptr_index :: \"(('a :: c_type)['b :: finite]) ptr \\<Rightarrow> bool \\<Rightarrow> nat \\<Rightarrow> 'a ptr\"\nwhere\n  \"array_ptr_index p coerce n = CTypesDefs.ptr_add (ptr_coerce p)\n    (if coerce \\<and> n \\<ge> CARD ('b) then 0 else of_nat n)\"\n\nlemmas array_ptr_index_simps\n    = array_ptr_index_def[where coerce=False, simplified]\n        array_ptr_index_def[where coerce=True, simplified]\n\nlemma heap_update_Array:\n  \"heap_update (p ::('a::packed_type['b::finite]) ptr) arr\n     = (\\<lambda>s. foldl (\\<lambda>s n. heap_update (array_ptr_index p False n)\n                                     (Arrays.index arr n) s) s [0 ..< card (UNIV :: 'b set)])\"\n  apply (rule ext, simp add: heap_update_def)\n  apply (subst coerce_heap_update_to_heap_updates\n                 [OF _ refl, where chunk=\"size_of TYPE('a)\" and m=\"card (UNIV :: 'b set)\"])\n   apply simp\n  apply (rule foldl_cong[OF refl refl])\n  apply (simp add: array_ptr_index_def CTypesDefs.ptr_add_def)\n  apply (rule_tac f=\"\\<lambda>xs. heap_update_list p xs s\" for p s in arg_cong)\n  apply (simp add: to_bytes_def size_of_def\n                   packed_type_access_ti)\n  apply (simp add: typ_info_array')\n  apply (subst fcp_eta[symmetric], subst access_ti_list_array)\n     apply simp\n    apply simp\n   apply (simp add: packed_type_access_ti size_of_def)\n   apply fastforce\n  apply (rule take_drop_foldl_concat)\n   apply (simp add: size_of_def)\n  apply simp\n  done\n\nlemma from_bytes_Array_element:\n  fixes p :: \"('a::mem_type['b::finite]) ptr\"\n  assumes less: \"of_nat n < card (UNIV :: 'b set)\"\n  assumes len: \"length bs = size_of TYPE('a) * CARD('b)\"\n  shows\n  \"index (from_bytes bs :: 'a['b]) n\n      = from_bytes (take (size_of TYPE('a)) (drop (n * size_of TYPE('a)) bs))\"\n  using less\n  apply (simp add: from_bytes_def size_of_def typ_info_array')\n  apply (subst update_ti_list_array'[OF refl])\n     apply simp\n    apply (simp add: len size_of_def)\n   apply (clarsimp simp: update_ti_s_adjust_ti)\n   apply (rule refl)\n  apply (simp add: split_upt_on_n[OF less])\n  apply (rule trans, rule foldr_does_nothing_to_xf[where xf=\"\\<lambda>s. index s n\"])\n   apply simp+\n  apply (subst foldr_does_nothing_to_xf[where xf=\"\\<lambda>s. index s n\"])\n   apply simp\n  apply (simp add: mult.commute)\n  apply (frule Suc_leI)\n  apply (drule_tac k=\"size_of TYPE('a)\" in mult_le_mono2)\n  apply (rule upd_rf)\n  apply (simp add: size_of_def len mult.commute)\n  done\n\nlemma heap_access_Array_element':\n  fixes p :: \"('a::mem_type['b::finite]) ptr\"\n  assumes less: \"of_nat n < card (UNIV :: 'b set)\"\n  shows\n  \"index (h_val hp p) n\n      = h_val hp (array_ptr_index p False n)\"\n  using less\n  apply (simp add: array_ptr_index_def CTypesDefs.ptr_add_def h_val_def)\n  apply (simp add: from_bytes_Array_element)\n  apply (simp add: drop_heap_list_le take_heap_list_le)\n  apply (subst take_heap_list_le)\n   apply (simp add: le_diff_conv2)\n   apply (drule Suc_leI)\n   apply (drule_tac k=\"size_of TYPE('a)\" in mult_le_mono2)\n   apply (simp add: mult.commute)\n  apply simp\n  done\n\nlemmas heap_access_Array_element\n    = heap_access_Array_element'[simplified array_ptr_index_simps]\n\nlemma heap_update_id:\n  \"h_val hp ptr = (v :: 'a :: packed_type)\n      \\<Longrightarrow> heap_update ptr v hp = hp\"\n  apply (simp add: h_val_def heap_update_def)\n  apply (rule heap_update_list_id[where n=\"size_of TYPE('a)\"])\n  apply clarsimp\n  apply (simp add: from_bytes_def to_bytes_def update_ti_t_def\n                   size_of_def field_access_update_same\n                   td_fafu_idem)\n  done\n\nlemma fold_cong':\n  \"a = b \\<Longrightarrow> xs = ys \\<Longrightarrow> (\\<And>x. x \\<in> set xs =simp=> f x = g x)\n    \\<Longrightarrow> fold f xs a = fold g ys b\"\n  unfolding simp_implies_def\n  by (metis fold_cong)\n\nlemma intvl_empty2:\n  \"({p ..+ n} = {}) = (n = 0)\"\n  by (auto simp add: intvl_def)\n\nlemma heap_update_list_commute:\n  \"{p ..+ length xs} \\<inter> {q ..+ length ys} = {}\n      \\<Longrightarrow> heap_update_list p xs (heap_update_list q ys hp)\n        = heap_update_list q ys (heap_update_list p xs hp)\"\n  apply (cases \"length xs < addr_card\")\n   apply (cases \"length ys < addr_card\")\n    apply (rule ext, simp add: heap_update_list_value)\n    apply blast\n   apply (simp_all add: addr_card intvl_overflow intvl_empty2)\n  done\n\nlemma heap_update_commute:\n  \"\\<lbrakk> {ptr_val p ..+ size_of TYPE('a)} \\<inter> {ptr_val q ..+ size_of TYPE('b)} = {};\n       wf_fd (typ_info_t TYPE('a)); wf_fd (typ_info_t TYPE('b)) \\<rbrakk>\n        \\<Longrightarrow> heap_update p v (heap_update q (u :: 'b :: c_type) h)\n              = heap_update q u (heap_update p (v :: 'a :: c_type) h)\"\n  apply (simp add: heap_update_def)\n  apply (simp add: heap_update_list_commute heap_list_update_disjoint_same\n                   to_bytes_def length_fa_ti size_of_def Int_commute)\n  done\n\nlemma heap_update_Array_update:\n  assumes n: \"n < CARD('b :: finite)\"\n  assumes size: \"CARD('b) * size_of TYPE('a :: packed_type) < 2 ^ addr_bitsize\"\n  shows \"heap_update p (Arrays.update (arr :: 'a['b]) n v) hp\n       = heap_update (array_ptr_index p False n) v (heap_update p arr hp)\"\nproof -\n\n  have P: \"\\<And>x k. \\<lbrakk> x < CARD('b); k < size_of TYPE('a) \\<rbrakk>\n         \\<Longrightarrow> unat (of_nat x * of_nat (size_of TYPE('a)) + (of_nat k :: addr))\n                 = x * size_of TYPE('a) + k\"\n    using size\n    apply (case_tac \"size_of TYPE('a)\", simp_all)\n    apply (case_tac \"CARD('b)\", simp_all)\n    apply (subst unat_add_lem[THEN iffD1])\n     apply (simp add: unat_word_ariths unat_of_nat less_Suc_eq_le)\n     apply (subgoal_tac \"Suc x * size_of TYPE('a) < 2 ^ addr_bitsize\", simp_all)\n     apply (erule order_le_less_trans[rotated], simp add: add_mono)\n    apply (subst unat_mult_lem[THEN iffD1])\n     apply (simp add: unat_of_nat unat_add_lem[THEN iffD1])\n     apply (rule order_less_le_trans, erule order_le_less_trans[rotated],\n            rule add_mono, simp+)\n      apply (simp add: less_Suc_eq_le trans_le_add2)\n     apply simp\n    apply (simp add: unat_of_nat unat_add_lem[THEN iffD1])\n    done\n\n  let ?key_upd = \"heap_update (array_ptr_index p False n) v\"\n  note commute = fold_commute_apply[where h=\"?key_upd\"\n      and xs=\"[Suc n ..< CARD('b)]\", where g=f' and f=f' for f']\n\n  show ?thesis using n\n    apply (simp add: heap_update_Array split_upt_on_n[OF n]\n                     foldl_conv_fold)\n    apply (subst commute)\n     apply (simp_all add: packed_heap_update_collapse\n                    cong: fold_cong')\n    apply (rule ext, simp)\n    apply (rule heap_update_commute, simp_all add: ptr_add_def)\n    apply (simp add: array_ptr_index_def CTypesDefs.ptr_add_def intvl_def Suc_le_eq)\n    apply (rule set_eqI, clarsimp)\n    apply (drule word_unat.Rep_inject[THEN iffD2])\n    apply (clarsimp simp: P nat_eq_add_iff1)\n    apply (case_tac x, simp_all add: less_Suc_eq_le Suc_diff_le)\n    done\nqed\n\nlemma heap_update_id_Array:\n  fixes arr :: \"('a :: packed_type)['b :: finite]\"\n  shows \"arr = h_val hp p\n    \\<Longrightarrow> heap_update p arr hp = hp\"\n  apply (simp add: heap_update_Array)\n  apply (rule foldl_does_nothing[where s=hp])\n  apply (simp add: heap_access_Array_element' heap_update_id)\n  done\n\nlemma heap_update_Array_element'':\n  fixes p' :: \"(('a :: packed_type)['b::finite]) ptr\"\n  fixes p :: \"('a :: packed_type) ptr\"\n  fixes hp w\n  assumes p: \"p = array_ptr_index p' False n\"\n  assumes n: \"n < CARD('b)\"\n  assumes size: \"CARD('b) * size_of TYPE('a) < 2 ^ addr_bitsize\"\n  shows \"heap_update p' (Arrays.update (h_val hp p') n w) hp\n       = heap_update p w hp\"\n  apply (subst heap_update_Array_update[OF n size])\n  apply (simp add: heap_update_id_Array p)\n  done\n\nlemmas heap_update_Array_element'\n    = heap_update_Array_element''[simplified array_ptr_index_simps]\n\nlemma array_count_size:\n  \"CARD('b :: array_max_count) * size_of TYPE('a :: array_outer_max_size) < 2 ^ addr_bitsize\"\n  using array_outer_max_size_ax[where 'a='a] array_max_count_ax[where 'a='b]\n  apply (clarsimp dest!: nat_le_Suc_less_imp)\n  apply (drule(1) mult_mono, simp+)\n  done\n\nlemmas heap_update_Array_element\n    = heap_update_Array_element'[OF refl _ array_count_size]\n\nlemma typ_slice_list_cut:\n  \"\\<lbrakk> (\\<forall>x \\<in> set xs. size_td (dt_fst x) = m); m \\<noteq> 0; n < (length xs * m) \\<rbrakk>\n    \\<Longrightarrow> typ_slice_list xs n =\n      typ_slice_pair (xs ! (n div m)) (n mod m)\"\n  apply (induct xs arbitrary: n, simp_all)\n  apply (intro conjI impI)\n   apply simp\n  apply (subgoal_tac \"\\<exists>n'. n = n' + m\")\n   apply clarsimp\n  apply (rule_tac x=\"n - m\" in exI)\n  apply simp\n  done\n\nlemma typ_slice_t_array:\n  \"\\<lbrakk> n < CARD('b); y < size_of TYPE('a) \\<rbrakk>\n   \\<Longrightarrow> typ_slice_t (export_uinfo (typ_info_t TYPE('a))) y \\<le>\n   typ_slice_t (export_uinfo (array_tag TYPE('a['b :: finite])))\n              (y + size_of TYPE('a :: mem_type) * n)\"\n  apply (simp add: array_tag_def array_tag_n_eq\n               split del: if_split)\n  apply (rule disjI2)\n  apply (subgoal_tac \"y + (size_of TYPE('a) * n) < CARD('b) * size_of TYPE('a)\")\n   apply (simp add: typ_slice_list_cut[where m=\"size_of TYPE('a)\"]\n                    map_td_list_map o_def size_of_def\n                    sz_nzero[unfolded size_of_def])\n   apply (simp add: export_uinfo_def[symmetric])\n  apply (rule_tac y=\"Suc n * size_of TYPE('a)\" in order_less_le_trans)\n   apply (simp add: size_of_def)\n  apply (simp only: size_of_def mult_le_mono1)\n  done\n\nlemma h_t_valid_Array_element':\n  \"\\<lbrakk> htd \\<Turnstile>\\<^sub>t (p :: (('a :: mem_type)['b :: finite]) ptr); coerce \\<or> n < CARD('b) \\<rbrakk>\n    \\<Longrightarrow> htd \\<Turnstile>\\<^sub>t array_ptr_index p coerce n\"\n  apply (clarsimp simp only: h_t_valid_def valid_footprint_def Let_def\n                             c_guard_def c_null_guard_def)\n  apply (subgoal_tac \"\\<exists>offs. array_ptr_index p coerce n = ptr_add (ptr_coerce p) (of_nat offs)\n        \\<and> offs < CARD ('b)\")\n   apply (clarsimp simp: size_td_array size_of_def typ_uinfo_t_def\n                         typ_info_array array_tag_def)\n   apply (intro conjI)\n     apply (clarsimp simp: CTypesDefs.ptr_add_def\n                           field_simps)\n     apply (drule_tac x=\"offs * size_of TYPE('a) + y\" in spec)\n     apply (drule mp)\n      apply (rule_tac y=\"Suc offs * size_of TYPE('a)\" in order_less_le_trans)\n       apply (simp add: size_of_def)\n      apply (simp only: size_of_def mult_le_mono1)\n     apply (clarsimp simp: field_simps)\n     apply (erule map_le_trans[rotated])\n     apply (rule list_map_mono)\n     apply (subst mult.commute, rule typ_slice_t_array[unfolded array_tag_def])\n      apply assumption\n     apply (simp add: size_of_def)\n    apply (simp add: ptr_aligned_def align_of_def align_td_array\n                     array_ptr_index_def\n                     CTypesDefs.ptr_add_def unat_word_ariths unat_of_nat)\n    using align_size_of[where 'a='a] align[where 'a='a]\n    apply (simp add: align_of_def size_of_def addr_card_def card_word)\n    apply (simp add: dvd_mod)\n   apply (thin_tac \"\\<forall>x. P x\" for P)\n   apply (clarsimp simp: intvl_def)\n   apply (drule_tac x=\"offs * size_of TYPE('a) + k\" in spec)\n   apply (drule mp)\n    apply (simp add: array_ptr_index_def CTypesDefs.ptr_add_def field_simps)\n   apply (erule notE)\n   apply (rule_tac y=\"Suc offs * size_of TYPE('a)\" in order_less_le_trans)\n    apply (simp add: size_of_def)\n   apply (simp only: size_of_def mult_le_mono1)\n  apply (auto simp add: array_ptr_index_def intro: exI[where x=0])\n  done\n\nlemma h_t_valid_Array_element:\n  \"\\<lbrakk> htd \\<Turnstile>\\<^sub>t (p :: (('a :: mem_type)['b :: finite]) ptr); 0 \\<le> n; n < int CARD('b) \\<rbrakk>\n    \\<Longrightarrow> htd \\<Turnstile>\\<^sub>t ((ptr_coerce p :: 'a ptr) +\\<^sub>p n)\"\n  apply (drule_tac n=\"nat n\" and coerce=False in h_t_valid_Array_element')\n   apply simp\n  apply (simp add: array_ptr_index_def)\n  done\n\nlemma ptr_safe_Array_element:\n  \"\\<lbrakk> ptr_safe (p :: (('a :: mem_type)['b :: finite]) ptr) htd; coerce \\<or> n < CARD('b) \\<rbrakk>\n    \\<Longrightarrow> ptr_safe (array_ptr_index p coerce n) htd\"\n  apply (simp add: ptr_safe_def)\n  apply (erule order_trans[rotated])\n  apply (subgoal_tac \"\\<exists>offs. array_ptr_index p coerce n = ptr_add (ptr_coerce p) (of_nat offs)\n        \\<and> offs < CARD ('b)\")\n   prefer 2\n   apply (auto simp: array_ptr_index_def intro: exI[where x=0])[1]\n  apply (clarsimp simp: s_footprint_def s_footprint_untyped_def\n                        CTypesDefs.ptr_add_def\n                        size_td_array size_of_def)\n  apply (rule_tac x=\"offs * size_of TYPE('a) + x\" in exI)\n  apply (simp add: size_of_def)\n  apply (rule conjI)\n   apply (rule_tac y=\"Suc offs * size_of TYPE('a)\" in order_less_le_trans)\n    apply (simp add: size_of_def)\n   apply (simp only: size_of_def)\n   apply (rule mult_le_mono1)\n   apply simp\n  apply (thin_tac \"coerce \\<or> P\" for P)\n  apply (elim disjE exE conjE, simp_all add: typ_uinfo_t_def)\n  apply (erule order_less_le_trans)\n  apply (rule prefix_length_le)\n  apply (rule order_trans, erule typ_slice_t_array)\n   apply (simp add: size_of_def)\n  apply (simp add: size_of_def field_simps typ_info_array)\n  done\n\nlemma from_bytes_eq:\n  \"from_bytes [x] = x\"\n  apply (clarsimp simp:from_bytes_def update_ti_t_def typ_info_word)\n  apply (simp add:word_rcat_def)\n  apply (simp add:bin_rcat_def)\n  by (metis len8 word_of_int_uint word_ubin.Abs_norm)\n\nlemma bytes_disjoint:\"(x::('a::c_type) ptr) \\<noteq> y \\<Longrightarrow> {ptr_val x + a ..+ 1} \\<inter> {ptr_val y + a ..+ 1} = {}\"\n  by (clarsimp simp:intvl_def)\n\nlemma byte_ptrs_disjoint:\"(x::('a::c_type) ptr) \\<noteq> y \\<Longrightarrow> \\<forall>i < of_nat (size_of TYPE('a)). ptr_val x + i \\<noteq> ptr_val y + i\"\n  by force\n\nlemma le_step:\"\\<lbrakk>(x::('a::len) word) < y + 1; x \\<noteq> y\\<rbrakk> \\<Longrightarrow> x < y\"\n  by (metis less_x_plus_1 max_word_max order_less_le)\n\nlemma ptr_add_disjoint:\n  \"\\<lbrakk> ptr_val y \\<notin> {ptr_val x ..+ size_of TYPE('a)};\n     ptr_val (x::('a::c_type) ptr) < ptr_val (y::('b::c_type) ptr);\n     a < of_nat (size_of TYPE('a)) \\<rbrakk> \\<Longrightarrow>\n   ptr_val x + a < ptr_val y\"\n  apply (erule swap)\n  apply (rule intvl_inter_le [where k=0 and ka=\"unat (ptr_val y - ptr_val x)\"])\n    apply clarsimp\n   apply (metis (hide_lams, mono_tags) add_diff_cancel2 add_diff_inverse diff_add_cancel\n              trans_less_add1 unat_less_helper word_le_less_eq word_less_add_right\n              word_of_nat_less word_unat.Rep_inverse)\n  apply simp\n  done\n\nlemma ptr_add_disjoint2:\n  \"\\<lbrakk> ptr_val x \\<notin> {ptr_val y ..+ size_of TYPE('a)};\n     ptr_val (y::('b::c_type) ptr) < ptr_val (x::('a::c_type) ptr);\n     a < of_nat (size_of TYPE('a)) \\<rbrakk> \\<Longrightarrow>\n   ptr_val y + a < ptr_val x\"\n  apply (erule swap)\n  apply (rule intvl_inter_le[where k=0 and ka=\"unat (ptr_val x - ptr_val y)\"])\n    apply clarsimp\n   apply (metis (no_types, hide_lams) add.commute less_imp_le less_le_trans not_le unat_less_helper\n                word_diff_ls'(4))\n  apply simp\n  done\n\nlemma ptr_aligned_is_aligned:\"\\<lbrakk>ptr_aligned (x::('a::c_type) ptr); align_of TYPE('a) = 2 ^ n\\<rbrakk> \\<Longrightarrow> is_aligned (ptr_val x) n\"\n  by (clarsimp simp: ptr_aligned_def is_aligned_def)\n\nlemma intvl_no_overflow:\n  assumes no_overflow: \"unat a + b < 2 ^ len_of TYPE('a::len)\"\n  shows \"(x \\<in> {(a :: 'a word) ..+ b}) = (a \\<le> x \\<and> x < (a + of_nat b))\"\nproof -\n  obtain \"sk\" :: \"'a word \\<Rightarrow> 'a word \\<Rightarrow> nat \\<Rightarrow> nat\"\n      where f1: \"\\<And>x y z. x \\<notin> {y..+z} \\<or> x = y + of_nat (sk x y z) \\<and> sk x y z < z\"\n    using [[metis_new_skolem]] by (metis intvlD)\n\n  have f2: \"\\<And>x. a + x < a + of_nat b \\<or> \\<not> x < of_nat b\"\n    using no_overflow\n    by (metis PackedTypes.of_nat_mono_maybe_le add_lessD1 le_add1\n            add.commute olen_add_eqv unat_of_nat_eq word_arith_nat_add\n            word_plus_strict_mono_right)\n\n  have f3: \"\\<forall>x y. y \\<notin> {x..+b} \\<or> of_nat (sk y x b) < (of_nat b :: 'a word)\"\n    using no_overflow f1\n    by (metis add_lessD1 add.commute of_nat_mono_maybe)\n\n  have \"x < a + of_nat b \\<or> \\<not> of_nat (sk x a b) < (of_nat b :: 'a word) \\<or> ?thesis\"\n    using f1 f2 by metis\n\n  hence \"x < a + of_nat b \\<or> ?thesis\"\n    using f3 by metis\n\n  thus \"?thesis\"\n    apply (rule disjE)\n     apply (rule iffI)\n      apply (clarsimp simp: intvl_def)\n      apply (clarsimp simp: unat_sub_if_size word_le_nat_alt word_less_nat_alt)\n      apply (cut_tac no_overflow)\n      apply (subgoal_tac \"k + (b + unat a) < 2 ^ len_of (TYPE('a)) + b\")\n       apply (subgoal_tac \"k + unat a < 2 ^ len_of (TYPE('a))\")\n        apply (metis add_lessD1 le_def less_not_refl2 add.commute unat_eq_of_nat word_arith_nat_add)\n       apply clarsimp\n      apply clarsimp\n     apply (clarsimp simp: intvl_def)\n     apply (rule exI [where x=\"unat (x  - a)\"])\n     apply (clarsimp simp: unat_sub_if_size word_le_nat_alt word_less_nat_alt)\n     apply (cut_tac no_overflow)\n     apply (metis diff_le_self le_add_diff_inverse le_diff_conv le_eq_less_or_eq le_unat_uoi add.commute nat_neq_iff unat_of_nat_eq word_arith_nat_add)\n    apply simp\n    done\nqed\n\n(* arg_cong specified for FCP because it does not apply as is. *)\nlemma FCP_arg_cong:\"f = g \\<Longrightarrow> FCP f = FCP g\"\n  by simp\n\nlemma h_val_id:\n    \"h_val (hrs_mem (hrs_mem_update (heap_update x y) s)) x = (y::'a::mem_type)\"\n  apply (subst hrs_mem_update)\n  apply (rule h_val_heap_update)\n  done\n\nlemma heap_update_id2:\n    \"hrs_mem_update (heap_update p ((h_val (hrs_mem s) p)::'a::packed_type)) s = s\"\n  apply (clarsimp simp:hrs_mem_update_def case_prod_beta)\n  apply (subst heap_update_id)\n   apply (simp add:hrs_mem_def)+\n  done\n\nlemma intvlI_unat:\"unat b < unat c \\<Longrightarrow> a + b \\<in> {a ..+ unat c}\"\n  by (metis intvlI word_unat.Rep_inverse)\n\nlemma neq_imp_bytes_disjoint:\n  \"\\<lbrakk> c_guard (x::'a::c_type ptr); c_guard y; unat j < align_of TYPE('a);\n        unat i < align_of TYPE('a); x \\<noteq> y; 2 ^ n = align_of TYPE('a); n < 32\\<rbrakk> \\<Longrightarrow>\n    ptr_val x + j \\<noteq> ptr_val y + i\"\n  apply (rule ccontr)\n  apply (subgoal_tac \"is_aligned (ptr_val x) n\")\n   apply (subgoal_tac \"is_aligned (ptr_val y) n\")\n    apply (subgoal_tac \"(ptr_val x + j && ~~ mask n) = (ptr_val y + i && ~~ mask n)\")\n     apply (subst (asm) neg_mask_add_aligned, simp, simp add: word_less_nat_alt)\n     apply (subst (asm) neg_mask_add_aligned, simp, simp add: word_less_nat_alt)\n     apply (clarsimp simp: is_aligned_neg_mask_eq)\n    apply simp\n   apply (clarsimp simp: c_guard_def ptr_aligned_def is_aligned_def)\n  apply (clarsimp simp: c_guard_def ptr_aligned_def is_aligned_def)\n  done\n\nlemma heap_update_list_base':\"heap_update_list p [] = id\"\n  by (rule ext, simp)\n\nlemma hrs_mem_update_id3: \"hrs_mem_update id = id\"\n  unfolding hrs_mem_update_def by simp\n\nabbreviation\n  ptr_span :: \"'a::mem_type ptr \\<Rightarrow> addr set\" where\n  \"ptr_span p \\<equiv> {ptr_val p ..+ size_of TYPE('a)}\"\n\nabbreviation (input)\n  cptr_type :: \"('a :: c_type) ptr \\<Rightarrow> 'a itself\"\nwhere\n  \"cptr_type p \\<equiv> TYPE('a)\"\n\nlemma ptr_retyp_valid_footprint_disjoint2:\n  \"\\<lbrakk>valid_footprint (ptr_retyp (q::'b::mem_type ptr) d) p s; {p..+size_td s} \\<inter> {ptr_val q..+size_of TYPE('b)} = {} \\<rbrakk>\n     \\<Longrightarrow> valid_footprint d p s\"\n  apply(clarsimp simp: valid_footprint_def Let_def)\n  apply (drule spec, drule (1) mp)\n  apply(subgoal_tac \"p + of_nat y \\<in> {p..+size_td s}\")\n  apply (subst (asm) ptr_retyp_d)\n    apply clarsimp\n    apply fast\n   apply (clarsimp simp add: ptr_retyp_d_eq_fst split: if_split_asm)\n   apply fast\n  apply (erule intvlI)\n  done\n\nlemma ptr_retyp_disjoint2:\n  \"\\<lbrakk>ptr_retyp (p::'a::mem_type ptr) d,g \\<Turnstile>\\<^sub>t q;\n    {ptr_val p..+size_of TYPE('a)} \\<inter> {ptr_val q..+size_of TYPE('b)} = {} \\<rbrakk>\n  \\<Longrightarrow> d,g \\<Turnstile>\\<^sub>t (q::'b::mem_type ptr)\"\napply(clarsimp simp: h_t_valid_def)\napply(erule ptr_retyp_valid_footprint_disjoint2)\napply(simp add: size_of_def)\napply fast\ndone\n\nlemma ptr_retyp_disjoint_iff:\n  \"{ptr_val p..+size_of TYPE('a)} \\<inter> {ptr_val q..+size_of TYPE('b)} = {}\n  \\<Longrightarrow> ptr_retyp (p::'a::mem_type ptr) d,g \\<Turnstile>\\<^sub>t q = d,g \\<Turnstile>\\<^sub>t (q::'b::mem_type ptr)\"\n  apply rule\n   apply (erule (1) ptr_retyp_disjoint2)\n  apply (erule (1) ptr_retyp_disjoint)\n  done\n\nlemma h_t_valid_ptr_retyp_eq:\n  \"\\<not> cptr_type p <\\<^sub>\\<tau> cptr_type p' \\<Longrightarrow> h_t_valid (ptr_retyp p td) g p'\n    = (if ptr_span p \\<inter> ptr_span p' = {} then h_t_valid td g p'\n        else field_of_t p' p \\<and> g p')\"\n  apply (clarsimp simp: ptr_retyp_disjoint_iff split: if_split)\n  apply (cases \"g p'\")\n   apply (rule iffI)\n    apply (rule ccontr, drule h_t_valid_neq_disjoint, rule ptr_retyp_h_t_valid, simp+)\n    apply (simp add: Int_commute)\n   apply (clarsimp simp: field_of_t_def field_of_def)\n   apply (drule sub_h_t_valid[where p=p, rotated], rule ptr_retyp_h_t_valid, simp, simp)\n   apply (erule(1) h_t_valid_guard_subst)\n  apply (simp add: h_t_valid_def)\n  done\n\nlemma field_lookup_list_Some_again:\n  \"dt_snd (xs ! i) = f\n    \\<Longrightarrow> i < length xs\n    \\<Longrightarrow> f \\<notin> dt_snd ` set ((take i xs))\n    \\<Longrightarrow> field_lookup_list xs [f] n\n        = Some (dt_fst (xs ! i), n + sum_list (map (size_td o dt_fst) (take i xs)))\"\n  apply (induct xs arbitrary: i n, simp_all)\n  apply (case_tac x1, simp)\n  apply (case_tac i, auto split: if_split)\n  done\n\nlemma field_lookup_array:\n  \"n < CARD('b) \\<Longrightarrow> field_lookup (typ_info_t TYPE(('a :: c_type)['b :: finite]))\n    [replicate n (CHR ''1'')] i = Some (adjust_ti (typ_info_t TYPE('a))\n        (\\<lambda>x. x.[n]) (\\<lambda>x f. Arrays.update f n x), i + n * size_of TYPE ('a))\"\n  apply (simp add: typ_info_array array_tag_def array_tag_n_eq)\n  apply (subst field_lookup_list_Some_again[where i=n],\n    auto simp add: take_map o_def sum_list_triv size_of_def)\n  done\n\nlemma field_of_t_refl:\n  \"field_of_t p p' = (p = p')\"\n  apply (safe, simp_all add: field_of_t_def)\n  apply (simp add: field_of_def)\n  apply (drule td_set_size_lte)\n  apply (simp add: unat_eq_0)\n  done\n\nlemma ptr_retyp_same_cleared_region:\n  fixes p :: \"'a :: mem_type ptr\" and p' :: \"'a :: mem_type ptr\"\n  assumes  ht: \"ptr_retyp p td, g \\<Turnstile>\\<^sub>t p'\"\n  shows \"p = p' \\<or> {ptr_val p..+ size_of TYPE('a)} \\<inter> {ptr_val p' ..+ size_of TYPE('a)} = {}\"\n  using ht\n  by (simp add: h_t_valid_ptr_retyp_eq[where p=p and p'=p'] field_of_t_refl\n         split: if_split_asm)\n\nlemma h_t_valid_ptr_retyp_inside_eq:\n  fixes p :: \"'a :: mem_type ptr\" and p' :: \"'a :: mem_type ptr\"\n  assumes inside: \"ptr_val p' \\<in> {ptr_val p ..+ size_of TYPE('a)}\"\n  and         ht: \"ptr_retyp p td, g \\<Turnstile>\\<^sub>t p'\"\n  shows   \"p = p'\"\n  using ptr_retyp_same_cleared_region[OF ht] inside mem_type_self[where p=p']\n  by blast\n\nlemma typ_slice_t_self_nth:\n  \"\\<exists>n < length (typ_slice_t td m). \\<exists>b. typ_slice_t td m ! n = (td, b)\"\n  using typ_slice_t_self [where td = td and m = m]\n  by (fastforce simp add: in_set_conv_nth)\n\nlemma ptr_retyp_other_cleared_region:\n  fixes p :: \"'a :: mem_type ptr\" and p' :: \"'b :: mem_type ptr\"\n  assumes  ht: \"ptr_retyp p td, g \\<Turnstile>\\<^sub>t p'\"\n  and   tdisj: \"typ_uinfo_t TYPE('a) \\<bottom>\\<^sub>t typ_uinfo_t TYPE('b :: mem_type)\"\n  and   clear: \"\\<forall>x \\<in> {ptr_val p ..+ size_of TYPE('a)}. \\<forall>n b. snd (td x) n \\<noteq> Some (typ_uinfo_t TYPE('b), b)\"\n  shows \"{ptr_val p'..+ size_of TYPE('b)} \\<inter> {ptr_val p ..+ size_of TYPE('a)} = {}\"\nproof (rule classical)\n  assume asm: \"{ptr_val p'..+ size_of TYPE('b)} \\<inter> {ptr_val p ..+ size_of TYPE('a)} \\<noteq> {}\"\n  then obtain mv where mvp: \"mv \\<in> {ptr_val p..+size_of TYPE('a)}\"\n    and mvp': \"mv \\<in> {ptr_val p'..+size_of TYPE('b)}\"\n      by blast\n\n  then obtain k' where mv: \"mv = ptr_val p' + of_nat k'\" and klt: \"k' < size_td (typ_info_t TYPE('b))\"\n    by (clarsimp dest!: intvlD simp: size_of_def typ_uinfo_size)\n\n  let ?mv = \"ptr_val p' + of_nat k'\"\n\n  obtain n b where nl: \"n < length (typ_slice_t (typ_uinfo_t TYPE('b)) k')\"\n    and tseq: \"typ_slice_t (typ_uinfo_t TYPE('b)) k' ! n = (typ_uinfo_t TYPE('b), b)\"\n    using typ_slice_t_self_nth [where td = \"typ_uinfo_t TYPE('b)\" and m = k']\n    by clarsimp\n\n  with ht have \"snd (ptr_retyp p td ?mv) n = Some (typ_uinfo_t TYPE('b), b)\"\n    unfolding h_t_valid_def\n    apply -\n    apply (clarsimp simp: valid_footprint_def Let_def)\n    apply (drule spec, drule mp [OF _ klt])\n    apply (clarsimp simp: map_le_def)\n    apply (drule bspec)\n    apply simp\n    apply simp\n    done\n\n  moreover {\n    assume \"snd (ptr_retyp p empty_htd ?mv) n = Some (typ_uinfo_t TYPE('b), b)\"\n    hence \"(typ_uinfo_t TYPE('b)) \\<in> fst ` set (typ_slice_t (typ_uinfo_t TYPE('a))\n                                                 (unat (ptr_val p' + of_nat k' - ptr_val p)))\"\n      using asm mv mvp\n      apply -\n      apply (rule_tac x = \"(typ_uinfo_t TYPE('b), b)\" in image_eqI)\n       apply simp\n      apply (fastforce simp add: ptr_retyp_footprint list_map_eq in_set_conv_nth split: if_split_asm)\n      done\n\n    with typ_slice_set have \"(typ_uinfo_t TYPE('b)) \\<in> fst ` td_set (typ_uinfo_t TYPE('a)) 0\"\n      by (rule subsetD)\n\n    hence False using tdisj by (clarsimp simp: tag_disj_def typ_tag_le_def)\n  } ultimately show ?thesis using mvp mvp' mv unfolding h_t_valid_def valid_footprint_def\n    apply -\n    apply (subst (asm) ptr_retyp_d_eq_snd)\n    apply (auto simp add: map_add_Some_iff clear)\n    done\nqed\n\nend\n", "meta": {"author": "NICTA", "repo": "l4v", "sha": "3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b", "save_path": "github-repos/isabelle/NICTA-l4v", "path": "github-repos/isabelle/NICTA-l4v/l4v-3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b/lib/clib/LemmaBucket_C.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6150878555160665, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.26693672851995126}}
{"text": "(*  Title:      HOL/TLA/Memory/MemoryImplementation.thy\n    Author:     Stephan Merz, University of Munich\n*)\n\nsection {* RPC-Memory example: Memory implementation *}\n\ntheory MemoryImplementation\nimports Memory RPC MemClerk\nbegin\n\ndatatype histState = histA | histB\n\ntype_synonym histType = \"(PrIds => histState) stfun\"  (* the type of the history variable *)\n\nconsts\n  (* the specification *)\n     (* channel (external) *)\n  memCh         :: \"memChType\"\n     (* internal variables *)\n  mm            :: \"memType\"\n\n  (* the state variables of the implementation *)\n     (* channels *)\n  (* same interface channel memCh *)\n  crCh          :: \"rpcSndChType\"\n  rmCh          :: \"rpcRcvChType\"\n     (* internal variables *)\n  (* identity refinement mapping for mm -- simply reused *)\n  rst           :: \"rpcStType\"\n  cst           :: \"mClkStType\"\n  ires          :: \"resType\"\n\ndefinition\n  (* auxiliary predicates *)\n  MVOKBARF      :: \"Vals => bool\"\n  where \"MVOKBARF v <-> (v : MemVal) | (v = OK) | (v = BadArg) | (v = RPCFailure)\"\n\ndefinition\n  MVOKBA        :: \"Vals => bool\"\n  where \"MVOKBA v <-> (v : MemVal) | (v = OK) | (v = BadArg)\"\n\ndefinition\n  MVNROKBA      :: \"Vals => bool\"\n  where \"MVNROKBA v <-> (v : MemVal) | (v = NotAResult) | (v = OK) | (v = BadArg)\"\n\ndefinition\n  (* tuples of state functions changed by the various components *)\n  e             :: \"PrIds => (bit * memOp) stfun\"\n  where \"e p = PRED (caller memCh!p)\"\n\ndefinition\n  c             :: \"PrIds => (mClkState * (bit * Vals) * (bit * rpcOp)) stfun\"\n  where \"c p = PRED (cst!p, rtrner memCh!p, caller crCh!p)\"\n\ndefinition\n  r             :: \"PrIds => (rpcState * (bit * Vals) * (bit * memOp)) stfun\"\n  where \"r p = PRED (rst!p, rtrner crCh!p, caller rmCh!p)\"\n\ndefinition\n  m             :: \"PrIds => ((bit * Vals) * Vals) stfun\"\n  where \"m p = PRED (rtrner rmCh!p, ires!p)\"\n\ndefinition\n  (* the environment action *)\n  ENext         :: \"PrIds => action\"\n  where \"ENext p = ACT (? l. #l : #MemLoc & Call memCh p #(read l))\"\n\n\ndefinition\n  (* specification of the history variable *)\n  HInit         :: \"histType => PrIds => stpred\"\n  where \"HInit rmhist p = PRED rmhist!p = #histA\"\n\ndefinition\n  HNext         :: \"histType => PrIds => action\"\n  where \"HNext rmhist p = ACT (rmhist!p)$ =\n                     (if (MemReturn rmCh ires p | RPCFail crCh rmCh rst p)\n                      then #histB\n                      else if (MClkReply memCh crCh cst p)\n                           then #histA\n                           else $(rmhist!p))\"\n\ndefinition\n  HistP         :: \"histType => PrIds => temporal\"\n  where \"HistP rmhist p = (TEMP Init HInit rmhist p\n                           & [][HNext rmhist p]_(c p,r p,m p, rmhist!p))\"\n\ndefinition\n  Hist          :: \"histType => temporal\"\n  where \"Hist rmhist = TEMP (ALL p. HistP rmhist p)\"\n\ndefinition\n  (* the implementation *)\n  IPImp          :: \"PrIds => temporal\"\n  where \"IPImp p = (TEMP (  Init ~Calling memCh p & [][ENext p]_(e p)\n                       & MClkIPSpec memCh crCh cst p\n                       & RPCIPSpec crCh rmCh rst p\n                       & RPSpec rmCh mm ires p\n                       & (ALL l. #l : #MemLoc --> MSpec rmCh mm ires l)))\"\n\ndefinition\n  ImpInit        :: \"PrIds => stpred\"\n  where \"ImpInit p = PRED (  ~Calling memCh p\n                          & MClkInit crCh cst p\n                          & RPCInit rmCh rst p\n                          & PInit ires p)\"\n\ndefinition\n  ImpNext        :: \"PrIds => action\"\n  where \"ImpNext p = (ACT  [ENext p]_(e p)\n                       & [MClkNext memCh crCh cst p]_(c p)\n                       & [RPCNext crCh rmCh rst p]_(r p)\n                       & [RNext rmCh mm ires p]_(m p))\"\n\ndefinition\n  ImpLive        :: \"PrIds => temporal\"\n  where \"ImpLive p = (TEMP  WF(MClkFwd memCh crCh cst p)_(c p)\n                        & SF(MClkReply memCh crCh cst p)_(c p)\n                        & WF(RPCNext crCh rmCh rst p)_(r p)\n                        & WF(RNext rmCh mm ires p)_(m p)\n                        & WF(MemReturn rmCh ires p)_(m p))\"\n\ndefinition\n  Implementation :: \"temporal\"\n  where \"Implementation = (TEMP ( (ALL p. Init (~Calling memCh p) & [][ENext p]_(e p))\n                               & MClkISpec memCh crCh cst\n                               & RPCISpec crCh rmCh rst\n                               & IRSpec rmCh mm ires))\"\n\ndefinition\n  (* the predicate S describes the states of the implementation.\n     slight simplification: two \"histState\" parameters instead of a\n     (one- or two-element) set.\n     NB: The second conjunct of the definition in the paper is taken care of by\n     the type definitions. The last conjunct is asserted separately as the memory\n     invariant MemInv, proved in Memory.thy. *)\n  S :: \"histType => bool => bool => bool => mClkState => rpcState => histState => histState => PrIds => stpred\"\n  where \"S rmhist ecalling ccalling rcalling cs rs hs1 hs2 p = (PRED\n                Calling memCh p = #ecalling\n              & Calling crCh p  = #ccalling\n              & (#ccalling --> arg<crCh!p> = MClkRelayArg<arg<memCh!p>>)\n              & (~ #ccalling & cst!p = #clkB --> MVOKBARF<res<crCh!p>>)\n              & Calling rmCh p  = #rcalling\n              & (#rcalling --> arg<rmCh!p> = RPCRelayArg<arg<crCh!p>>)\n              & (~ #rcalling --> ires!p = #NotAResult)\n              & (~ #rcalling & rst!p = #rpcB --> MVOKBA<res<rmCh!p>>)\n              & cst!p = #cs\n              & rst!p = #rs\n              & (rmhist!p = #hs1 | rmhist!p = #hs2)\n              & MVNROKBA<ires!p>)\"\n\ndefinition\n  (* predicates S1 -- S6 define special instances of S *)\n  S1            :: \"histType => PrIds => stpred\"\n  where \"S1 rmhist p = S rmhist False False False clkA rpcA histA histA p\"\n\ndefinition\n  S2            :: \"histType => PrIds => stpred\"\n  where \"S2 rmhist p = S rmhist True False False clkA rpcA histA histA p\"\n\ndefinition\n  S3            :: \"histType => PrIds => stpred\"\n  where \"S3 rmhist p = S rmhist True True False clkB rpcA histA histB p\"\n\ndefinition\n  S4            :: \"histType => PrIds => stpred\"\n  where \"S4 rmhist p = S rmhist True True True clkB rpcB histA histB p\"\n\ndefinition\n  S5            :: \"histType => PrIds => stpred\"\n  where \"S5 rmhist p = S rmhist True True False clkB rpcB histB histB p\"\n\ndefinition\n  S6            :: \"histType => PrIds => stpred\"\n  where \"S6 rmhist p = S rmhist True False False clkB rpcA histB histB p\"\n\ndefinition\n  (* The invariant asserts that the system is always in one of S1 - S6, for every p *)\n  ImpInv         :: \"histType => PrIds => stpred\"\n  where \"ImpInv rmhist p = (PRED (S1 rmhist p | S2 rmhist p | S3 rmhist p\n                                | S4 rmhist p | S5 rmhist p | S6 rmhist p))\"\n\ndefinition\n  resbar        :: \"histType => resType\"        (* refinement mapping *)\n  where\"resbar rmhist s p =\n                  (if (S1 rmhist p s | S2 rmhist p s)\n                   then ires s p\n                   else if S3 rmhist p s\n                   then if rmhist s p = histA\n                        then ires s p else MemFailure\n                   else if S4 rmhist p s\n                   then if (rmhist s p = histB & ires s p = NotAResult)\n                        then MemFailure else ires s p\n                   else if S5 rmhist p s\n                   then res (rmCh s p)\n                   else if S6 rmhist p s\n                   then if res (crCh s p) = RPCFailure\n                        then MemFailure else res (crCh s p)\n                   else NotAResult)\" (* dummy value *)\n\naxiomatization where\n  (* the \"base\" variables: everything except resbar and hist (for any index) *)\n  MI_base:       \"basevars (caller memCh!p,\n                           (rtrner memCh!p, caller crCh!p, cst!p),\n                           (rtrner crCh!p, caller rmCh!p, rst!p),\n                           (mm!l, rtrner rmCh!p, ires!p))\"\n\n(*\n    The main theorem is theorem \"Implementation\" at the end of this file,\n    which shows that the composition of a reliable memory, an RPC component, and\n    a memory clerk implements an unreliable memory. The files \"MIsafe.thy\" and\n    \"MIlive.thy\" contain lower-level lemmas for the safety and liveness parts.\n\n    Steps are (roughly) numbered as in the hand proof.\n*)\n\n(* --------------------------- automatic prover --------------------------- *)\n\ndeclare if_weak_cong [cong del]\n\n(* A more aggressive variant that tries to solve subgoals by assumption\n   or contradiction during the simplification.\n   THIS IS UNSAFE, BECAUSE IT DOESN'T RECORD THE CHOICES!!\n   (but it can be a lot faster than the default setup)\n*)\nML {*\n  val config_fast_solver = Attrib.setup_config_bool @{binding fast_solver} (K false);\n  val fast_solver = mk_solver \"fast_solver\" (fn ctxt =>\n    if Config.get ctxt config_fast_solver\n    then assume_tac ctxt ORELSE' (etac notE)\n    else K no_tac);\n*}\n\nsetup {* map_theory_simpset (fn ctxt => ctxt addSSolver fast_solver) *}\n\nML {* val temp_elim = make_elim oo temp_use *}\n\n\n\n(****************************** The history variable ******************************)\n\nsection \"History variable\"\n\nlemma HistoryLemma: \"|- Init(ALL p. ImpInit p) & [](ALL p. ImpNext p)\n         --> (EEX rmhist. Init(ALL p. HInit rmhist p)\n                          & [](ALL p. [HNext rmhist p]_(c p, r p, m p, rmhist!p)))\"\n  apply clarsimp\n  apply (rule historyI)\n      apply assumption+\n  apply (rule MI_base)\n  apply (tactic {* action_simp_tac (@{context} addsimps [@{thm HInit_def}]) [] [] 1 *})\n   apply (erule fun_cong)\n  apply (tactic {* action_simp_tac (@{context} addsimps [@{thm HNext_def}])\n    [@{thm busy_squareI}] [] 1 *})\n  apply (erule fun_cong)\n  done\n\nlemma History: \"|- Implementation --> (EEX rmhist. Hist rmhist)\"\n  apply clarsimp\n  apply (rule HistoryLemma [temp_use, THEN eex_mono])\n    prefer 3\n    apply (force simp: Hist_def HistP_def Init_def all_box [try_rewrite]\n      split_box_conj [try_rewrite])\n   apply (auto simp: Implementation_def MClkISpec_def RPCISpec_def\n     IRSpec_def MClkIPSpec_def RPCIPSpec_def RPSpec_def ImpInit_def\n     Init_def ImpNext_def c_def r_def m_def all_box [temp_use] split_box_conj [temp_use])\n  done\n\n(******************************** The safety part *********************************)\n\nsection \"The safety part\"\n\n(* ------------------------- Include lower-level lemmas ------------------------- *)\n\n(* RPCFailure notin MemVals U {OK,BadArg} *)\n\nlemma MVOKBAnotRF: \"MVOKBA x ==> x ~= RPCFailure\"\n  apply (unfold MVOKBA_def)\n  apply auto\n  done\n\n(* NotAResult notin MemVals U {OK,BadArg,RPCFailure} *)\n\nlemma MVOKBARFnotNR: \"MVOKBARF x ==> x ~= NotAResult\"\n  apply (unfold MVOKBARF_def)\n  apply auto\n  done\n\n(* ================ Si's are mutually exclusive ================================ *)\n(* Si and Sj are mutually exclusive for i # j. This helps to simplify the big\n   conditional in the definition of resbar when doing the step-simulation proof.\n   We prove a weaker result, which suffices for our purposes:\n   Si implies (not Sj), for j<i.\n*)\n\n(* --- not used ---\nlemma S1_excl: \"|- S1 rmhist p --> S1 rmhist p & ~S2 rmhist p & ~S3 rmhist p &\n    ~S4 rmhist p & ~S5 rmhist p & ~S6 rmhist p\"\n  by (auto simp: S_def S1_def S2_def S3_def S4_def S5_def S6_def)\n*)\n\nlemma S2_excl: \"|- S2 rmhist p --> S2 rmhist p & ~S1 rmhist p\"\n  by (auto simp: S_def S1_def S2_def)\n\nlemma S3_excl: \"|- S3 rmhist p --> S3 rmhist p & ~S1 rmhist p & ~S2 rmhist p\"\n  by (auto simp: S_def S1_def S2_def S3_def)\n\nlemma S4_excl: \"|- S4 rmhist p --> S4 rmhist p & ~S1 rmhist p & ~S2 rmhist p & ~S3 rmhist p\"\n  by (auto simp: S_def S1_def S2_def S3_def S4_def)\n\nlemma S5_excl: \"|- S5 rmhist p --> S5 rmhist p & ~S1 rmhist p & ~S2 rmhist p\n                         & ~S3 rmhist p & ~S4 rmhist p\"\n  by (auto simp: S_def S1_def S2_def S3_def S4_def S5_def)\n\nlemma S6_excl: \"|- S6 rmhist p --> S6 rmhist p & ~S1 rmhist p & ~S2 rmhist p\n                         & ~S3 rmhist p & ~S4 rmhist p & ~S5 rmhist p\"\n  by (auto simp: S_def S1_def S2_def S3_def S4_def S5_def S6_def)\n\n\n(* ==================== Lemmas about the environment ============================== *)\n\nlemma Envbusy: \"|- $(Calling memCh p) --> ~ENext p\"\n  by (auto simp: ENext_def Call_def)\n\n(* ==================== Lemmas about the implementation's states ==================== *)\n\n(* The following series of lemmas are used in establishing the implementation's\n   next-state relation (Step 1.2 of the proof in the paper). For each state Si, we\n   determine which component actions are possible and what state they result in.\n*)\n\n(* ------------------------------ State S1 ---------------------------------------- *)\n\nlemma S1Env: \"|- ENext p & $(S1 rmhist p) & unchanged (c p, r p, m p, rmhist!p)\n         --> (S2 rmhist p)$\"\n  by (force simp: ENext_def Call_def c_def r_def m_def\n    caller_def rtrner_def MVNROKBA_def S_def S1_def S2_def Calling_def)\n\nlemma S1ClerkUnch: \"|- [MClkNext memCh crCh cst p]_(c p) & $(S1 rmhist p) --> unchanged (c p)\"\n  using [[fast_solver]]\n  by (auto elim!: squareE [temp_use] dest!: MClkidle [temp_use] simp: S_def S1_def)\n\nlemma S1RPCUnch: \"|- [RPCNext crCh rmCh rst p]_(r p) & $(S1 rmhist p) --> unchanged (r p)\"\n  using [[fast_solver]]\n  by (auto elim!: squareE [temp_use] dest!: RPCidle [temp_use] simp: S_def S1_def)\n\nlemma S1MemUnch: \"|- [RNext rmCh mm ires p]_(m p) & $(S1 rmhist p) --> unchanged (m p)\"\n  using [[fast_solver]]\n  by (auto elim!: squareE [temp_use] dest!: Memoryidle [temp_use] simp: S_def S1_def)\n\nlemma S1Hist: \"|- [HNext rmhist p]_(c p,r p,m p,rmhist!p) & $(S1 rmhist p)\n         --> unchanged (rmhist!p)\"\n  by (tactic {* action_simp_tac (@{context} addsimps [@{thm HNext_def}, @{thm S_def},\n    @{thm S1_def}, @{thm MemReturn_def}, @{thm RPCFail_def}, @{thm MClkReply_def},\n    @{thm Return_def}]) [] [temp_use @{context} @{thm squareE}] 1 *})\n\n\n(* ------------------------------ State S2 ---------------------------------------- *)\n\nlemma S2EnvUnch: \"|- [ENext p]_(e p) & $(S2 rmhist p) --> unchanged (e p)\"\n  by (auto dest!: Envbusy [temp_use] simp: S_def S2_def)\n\nlemma S2Clerk: \"|- MClkNext memCh crCh cst p & $(S2 rmhist p) --> MClkFwd memCh crCh cst p\"\n  by (auto simp: MClkNext_def MClkRetry_def MClkReply_def S_def S2_def)\n\nlemma S2Forward: \"|- $(S2 rmhist p) & MClkFwd memCh crCh cst p\n         & unchanged (e p, r p, m p, rmhist!p)\n         --> (S3 rmhist p)$\"\n  by (tactic {* action_simp_tac (@{context} addsimps [@{thm MClkFwd_def},\n    @{thm Call_def}, @{thm e_def}, @{thm r_def}, @{thm m_def}, @{thm caller_def},\n    @{thm rtrner_def}, @{thm S_def}, @{thm S2_def}, @{thm S3_def}, @{thm Calling_def}]) [] [] 1 *})\n\nlemma S2RPCUnch: \"|- [RPCNext crCh rmCh rst p]_(r p) & $(S2 rmhist p) --> unchanged (r p)\"\n  by (auto simp: S_def S2_def dest!: RPCidle [temp_use])\n\nlemma S2MemUnch: \"|- [RNext rmCh mm ires p]_(m p) & $(S2 rmhist p) --> unchanged (m p)\"\n  by (auto simp: S_def S2_def dest!: Memoryidle [temp_use])\n\nlemma S2Hist: \"|- [HNext rmhist p]_(c p,r p,m p,rmhist!p) & $(S2 rmhist p)\n         --> unchanged (rmhist!p)\"\n  using [[fast_solver]]\n  by (auto elim!: squareE [temp_use] simp: HNext_def MemReturn_def RPCFail_def\n    MClkReply_def Return_def S_def S2_def)\n\n(* ------------------------------ State S3 ---------------------------------------- *)\n\nlemma S3EnvUnch: \"|- [ENext p]_(e p) & $(S3 rmhist p) --> unchanged (e p)\"\n  by (auto dest!: Envbusy [temp_use] simp: S_def S3_def)\n\nlemma S3ClerkUnch: \"|- [MClkNext memCh crCh cst p]_(c p) & $(S3 rmhist p) --> unchanged (c p)\"\n  by (auto dest!: MClkbusy [temp_use] simp: square_def S_def S3_def)\n\nlemma S3LegalRcvArg: \"|- S3 rmhist p --> IsLegalRcvArg<arg<crCh!p>>\"\n  by (auto simp: IsLegalRcvArg_def MClkRelayArg_def S_def S3_def)\n\nlemma S3RPC: \"|- RPCNext crCh rmCh rst p & $(S3 rmhist p)\n         --> RPCFwd crCh rmCh rst p | RPCFail crCh rmCh rst p\"\n  apply clarsimp\n  apply (frule S3LegalRcvArg [action_use])\n  apply (auto simp: RPCNext_def RPCReject_def RPCReply_def S_def S3_def)\n  done\n\nlemma S3Forward: \"|- RPCFwd crCh rmCh rst p & HNext rmhist p & $(S3 rmhist p)\n         & unchanged (e p, c p, m p)\n         --> (S4 rmhist p)$ & unchanged (rmhist!p)\"\n  by (tactic {* action_simp_tac (@{context} addsimps [@{thm RPCFwd_def},\n    @{thm HNext_def}, @{thm MemReturn_def}, @{thm RPCFail_def},\n    @{thm MClkReply_def}, @{thm Return_def}, @{thm Call_def}, @{thm e_def},\n    @{thm c_def}, @{thm m_def}, @{thm caller_def}, @{thm rtrner_def}, @{thm S_def},\n    @{thm S3_def}, @{thm S4_def}, @{thm Calling_def}]) [] [] 1 *})\n\nlemma S3Fail: \"|- RPCFail crCh rmCh rst p & $(S3 rmhist p) & HNext rmhist p\n         & unchanged (e p, c p, m p)\n         --> (S6 rmhist p)$\"\n  by (tactic {* action_simp_tac (@{context} addsimps [@{thm HNext_def},\n    @{thm RPCFail_def}, @{thm Return_def}, @{thm e_def}, @{thm c_def},\n    @{thm m_def}, @{thm caller_def}, @{thm rtrner_def}, @{thm MVOKBARF_def},\n    @{thm S_def}, @{thm S3_def}, @{thm S6_def}, @{thm Calling_def}]) [] [] 1 *})\n\nlemma S3MemUnch: \"|- [RNext rmCh mm ires p]_(m p) & $(S3 rmhist p) --> unchanged (m p)\"\n  by (auto simp: S_def S3_def dest!: Memoryidle [temp_use])\n\nlemma S3Hist: \"|- HNext rmhist p & $(S3 rmhist p) & unchanged (r p) --> unchanged (rmhist!p)\"\n  by (auto simp: HNext_def MemReturn_def RPCFail_def MClkReply_def\n    Return_def r_def rtrner_def S_def S3_def Calling_def)\n\n(* ------------------------------ State S4 ---------------------------------------- *)\n\nlemma S4EnvUnch: \"|- [ENext p]_(e p) & $(S4 rmhist p) --> unchanged (e p)\"\n  by (auto simp: S_def S4_def dest!: Envbusy [temp_use])\n\nlemma S4ClerkUnch: \"|- [MClkNext memCh crCh cst p]_(c p) & $(S4 rmhist p) --> unchanged (c p)\"\n  by (auto simp: S_def S4_def dest!: MClkbusy [temp_use])\n\nlemma S4RPCUnch: \"|- [RPCNext crCh rmCh rst p]_(r p) & $(S4 rmhist p) --> unchanged (r p)\"\n  using [[fast_solver]]\n  by (auto elim!: squareE [temp_use] dest!: RPCbusy [temp_use] simp: S_def S4_def)\n\nlemma S4ReadInner: \"|- ReadInner rmCh mm ires p l & $(S4 rmhist p) & unchanged (e p, c p, r p)\n         & HNext rmhist p & $(MemInv mm l)\n         --> (S4 rmhist p)$ & unchanged (rmhist!p)\"\n  by (tactic {* action_simp_tac (@{context} addsimps [@{thm ReadInner_def},\n    @{thm GoodRead_def}, @{thm BadRead_def}, @{thm HNext_def}, @{thm MemReturn_def},\n    @{thm RPCFail_def}, @{thm MClkReply_def}, @{thm Return_def}, @{thm e_def},\n    @{thm c_def}, @{thm r_def}, @{thm rtrner_def}, @{thm caller_def},\n    @{thm MVNROKBA_def}, @{thm S_def}, @{thm S4_def}, @{thm RdRequest_def},\n    @{thm Calling_def}, @{thm MemInv_def}]) [] [] 1 *})\n\nlemma S4Read: \"|- Read rmCh mm ires p & $(S4 rmhist p) & unchanged (e p, c p, r p)\n         & HNext rmhist p & (!l. $MemInv mm l)\n         --> (S4 rmhist p)$ & unchanged (rmhist!p)\"\n  by (auto simp: Read_def dest!: S4ReadInner [temp_use])\n\nlemma S4WriteInner: \"|- WriteInner rmCh mm ires p l v & $(S4 rmhist p) & unchanged (e p, c p, r p)           & HNext rmhist p\n         --> (S4 rmhist p)$ & unchanged (rmhist!p)\"\n  by (tactic {* action_simp_tac (@{context} addsimps [@{thm WriteInner_def},\n    @{thm GoodWrite_def}, @{thm BadWrite_def}, @{thm HNext_def}, @{thm MemReturn_def},\n    @{thm RPCFail_def}, @{thm MClkReply_def}, @{thm Return_def}, @{thm e_def},\n    @{thm c_def}, @{thm r_def}, @{thm rtrner_def}, @{thm caller_def}, @{thm MVNROKBA_def},\n    @{thm S_def}, @{thm S4_def}, @{thm WrRequest_def}, @{thm Calling_def}]) [] [] 1 *})\n\nlemma S4Write: \"|- Write rmCh mm ires p l & $(S4 rmhist p) & unchanged (e p, c p, r p)\n         & (HNext rmhist p)\n         --> (S4 rmhist p)$ & unchanged (rmhist!p)\"\n  by (auto simp: Write_def dest!: S4WriteInner [temp_use])\n\nlemma WriteS4: \"|- $ImpInv rmhist p & Write rmCh mm ires p l --> $S4 rmhist p\"\n  by (auto simp: Write_def WriteInner_def ImpInv_def\n    WrRequest_def S_def S1_def S2_def S3_def S4_def S5_def S6_def)\n\nlemma S4Return: \"|- MemReturn rmCh ires p & $S4 rmhist p & unchanged (e p, c p, r p)\n         & HNext rmhist p\n         --> (S5 rmhist p)$\"\n  by (auto simp: HNext_def MemReturn_def Return_def e_def c_def r_def\n    rtrner_def caller_def MVNROKBA_def MVOKBA_def S_def S4_def S5_def Calling_def)\n\nlemma S4Hist: \"|- HNext rmhist p & $S4 rmhist p & (m p)$ = $(m p) --> (rmhist!p)$ = $(rmhist!p)\"\n  by (auto simp: HNext_def MemReturn_def RPCFail_def MClkReply_def\n    Return_def m_def rtrner_def S_def S4_def Calling_def)\n\n(* ------------------------------ State S5 ---------------------------------------- *)\n\nlemma S5EnvUnch: \"|- [ENext p]_(e p) & $(S5 rmhist p) --> unchanged (e p)\"\n  by (auto simp: S_def S5_def dest!: Envbusy [temp_use])\n\nlemma S5ClerkUnch: \"|- [MClkNext memCh crCh cst p]_(c p) & $(S5 rmhist p) --> unchanged (c p)\"\n  by (auto simp: S_def S5_def dest!: MClkbusy [temp_use])\n\nlemma S5RPC: \"|- RPCNext crCh rmCh rst p & $(S5 rmhist p)\n         --> RPCReply crCh rmCh rst p | RPCFail crCh rmCh rst p\"\n  by (auto simp: RPCNext_def RPCReject_def RPCFwd_def S_def S5_def)\n\nlemma S5Reply: \"|- RPCReply crCh rmCh rst p & $(S5 rmhist p) & unchanged (e p, c p, m p,rmhist!p)\n       --> (S6 rmhist p)$\"\n  by (tactic {* action_simp_tac (@{context} addsimps [@{thm RPCReply_def},\n    @{thm Return_def}, @{thm e_def}, @{thm c_def}, @{thm m_def}, @{thm MVOKBA_def},\n    @{thm MVOKBARF_def}, @{thm caller_def}, @{thm rtrner_def}, @{thm S_def},\n    @{thm S5_def}, @{thm S6_def}, @{thm Calling_def}]) [] [] 1 *})\n\nlemma S5Fail: \"|- RPCFail crCh rmCh rst p & $(S5 rmhist p) & unchanged (e p, c p, m p,rmhist!p)\n         --> (S6 rmhist p)$\"\n  by (tactic {* action_simp_tac (@{context} addsimps [@{thm RPCFail_def},\n    @{thm Return_def}, @{thm e_def}, @{thm c_def}, @{thm m_def},\n    @{thm MVOKBARF_def}, @{thm caller_def}, @{thm rtrner_def},\n    @{thm S_def}, @{thm S5_def}, @{thm S6_def}, @{thm Calling_def}]) [] [] 1 *})\n\nlemma S5MemUnch: \"|- [RNext rmCh mm ires p]_(m p) & $(S5 rmhist p) --> unchanged (m p)\"\n  by (auto simp: S_def S5_def dest!: Memoryidle [temp_use])\n\nlemma S5Hist: \"|- [HNext rmhist p]_(c p, r p, m p, rmhist!p) & $(S5 rmhist p)\n         --> (rmhist!p)$ = $(rmhist!p)\"\n  using [[fast_solver]]\n  by (auto elim!: squareE [temp_use] simp: HNext_def MemReturn_def RPCFail_def\n    MClkReply_def Return_def S_def S5_def)\n\n(* ------------------------------ State S6 ---------------------------------------- *)\n\nlemma S6EnvUnch: \"|- [ENext p]_(e p) & $(S6 rmhist p) --> unchanged (e p)\"\n  by (auto simp: S_def S6_def dest!: Envbusy [temp_use])\n\nlemma S6Clerk: \"|- MClkNext memCh crCh cst p & $(S6 rmhist p)\n         --> MClkRetry memCh crCh cst p | MClkReply memCh crCh cst p\"\n  by (auto simp: MClkNext_def MClkFwd_def S_def S6_def)\n\nlemma S6Retry: \"|- MClkRetry memCh crCh cst p & HNext rmhist p & $S6 rmhist p\n         & unchanged (e p,r p,m p)\n         --> (S3 rmhist p)$ & unchanged (rmhist!p)\"\n  by (tactic {* action_simp_tac (@{context} addsimps [@{thm HNext_def},\n    @{thm MClkReply_def}, @{thm MClkRetry_def}, @{thm Call_def}, @{thm Return_def},\n    @{thm e_def}, @{thm r_def}, @{thm m_def}, @{thm caller_def}, @{thm rtrner_def},\n    @{thm S_def}, @{thm S6_def}, @{thm S3_def}, @{thm Calling_def}]) [] [] 1 *})\n\nlemma S6Reply: \"|- MClkReply memCh crCh cst p & HNext rmhist p & $S6 rmhist p\n         & unchanged (e p,r p,m p)\n         --> (S1 rmhist p)$\"\n  by (tactic {* action_simp_tac (@{context} addsimps [@{thm HNext_def},\n    @{thm MemReturn_def}, @{thm RPCFail_def}, @{thm Return_def}, @{thm MClkReply_def},\n    @{thm e_def}, @{thm r_def}, @{thm m_def}, @{thm caller_def}, @{thm rtrner_def},\n    @{thm S_def}, @{thm S6_def}, @{thm S1_def}, @{thm Calling_def}]) [] [] 1 *})\n\nlemma S6RPCUnch: \"|- [RPCNext crCh rmCh rst p]_(r p) & $S6 rmhist p --> unchanged (r p)\"\n  by (auto simp: S_def S6_def dest!: RPCidle [temp_use])\n\nlemma S6MemUnch: \"|- [RNext rmCh mm ires p]_(m p) & $(S6 rmhist p) --> unchanged (m p)\"\n  by (auto simp: S_def S6_def dest!: Memoryidle [temp_use])\n\nlemma S6Hist: \"|- HNext rmhist p & $S6 rmhist p & (c p)$ = $(c p) --> (rmhist!p)$ = $(rmhist!p)\"\n  by (auto simp: HNext_def MClkReply_def Return_def c_def rtrner_def S_def S6_def Calling_def)\n\n\nsection \"Correctness of predicate-action diagram\"\n\n\n(* ========== Step 1.1 ================================================= *)\n(* The implementation's initial condition implies the state predicate S1 *)\n\nlemma Step1_1: \"|- ImpInit p & HInit rmhist p --> S1 rmhist p\"\n  using [[fast_solver]]\n  by (auto elim!: squareE [temp_use] simp: MVNROKBA_def\n    MClkInit_def RPCInit_def PInit_def HInit_def ImpInit_def S_def S1_def)\n\n(* ========== Step 1.2 ================================================== *)\n(* Figure 16 is a predicate-action diagram for the implementation. *)\n\nlemma Step1_2_1: \"|- [HNext rmhist p]_(c p,r p,m p, rmhist!p) & ImpNext p\n         & ~unchanged (e p, c p, r p, m p, rmhist!p)  & $S1 rmhist p\n         --> (S2 rmhist p)$ & ENext p & unchanged (c p, r p, m p)\"\n  apply (tactic {* action_simp_tac (@{context} addsimps [@{thm ImpNext_def}]) []\n      (map (temp_elim @{context})\n        [@{thm S1ClerkUnch}, @{thm S1RPCUnch}, @{thm S1MemUnch}, @{thm S1Hist}]) 1 *})\n   using [[fast_solver]]\n   apply (auto elim!: squareE [temp_use] intro!: S1Env [temp_use])\n  done\n\nlemma Step1_2_2: \"|- [HNext rmhist p]_(c p,r p,m p, rmhist!p) & ImpNext p\n         & ~unchanged (e p, c p, r p, m p, rmhist!p) & $S2 rmhist p\n         --> (S3 rmhist p)$ & MClkFwd memCh crCh cst p\n             & unchanged (e p, r p, m p, rmhist!p)\"\n  apply (tactic {* action_simp_tac (@{context} addsimps [@{thm ImpNext_def}]) []\n    (map (temp_elim @{context})\n      [@{thm S2EnvUnch}, @{thm S2RPCUnch}, @{thm S2MemUnch}, @{thm S2Hist}]) 1 *})\n   using [[fast_solver]]\n   apply (auto elim!: squareE [temp_use] intro!: S2Clerk [temp_use] S2Forward [temp_use])\n  done\n\nlemma Step1_2_3: \"|- [HNext rmhist p]_(c p,r p,m p, rmhist!p) & ImpNext p\n         & ~unchanged (e p, c p, r p, m p, rmhist!p) & $S3 rmhist p\n         --> ((S4 rmhist p)$ & RPCFwd crCh rmCh rst p & unchanged (e p, c p, m p, rmhist!p))\n             | ((S6 rmhist p)$ & RPCFail crCh rmCh rst p & unchanged (e p, c p, m p))\"\n  apply (tactic {* action_simp_tac (@{context} addsimps [@{thm ImpNext_def}]) []\n    (map (temp_elim @{context}) [@{thm S3EnvUnch}, @{thm S3ClerkUnch}, @{thm S3MemUnch}]) 1 *})\n  apply (tactic {* action_simp_tac @{context} []\n    (@{thm squareE} ::\n      map (temp_elim @{context}) [@{thm S3RPC}, @{thm S3Forward}, @{thm S3Fail}]) 1 *})\n   apply (auto dest!: S3Hist [temp_use])\n  done\n\nlemma Step1_2_4: \"|- [HNext rmhist p]_(c p,r p,m p, rmhist!p) & ImpNext p\n              & ~unchanged (e p, c p, r p, m p, rmhist!p)\n              & $S4 rmhist p & (!l. $(MemInv mm l))\n         --> ((S4 rmhist p)$ & Read rmCh mm ires p & unchanged (e p, c p, r p, rmhist!p))\n             | ((S4 rmhist p)$ & (? l. Write rmCh mm ires p l) & unchanged (e p, c p, r p, rmhist!p))\n             | ((S5 rmhist p)$ & MemReturn rmCh ires p & unchanged (e p, c p, r p))\"\n  apply (tactic {* action_simp_tac (@{context} addsimps [@{thm ImpNext_def}]) []\n    (map (temp_elim @{context}) [@{thm S4EnvUnch}, @{thm S4ClerkUnch}, @{thm S4RPCUnch}]) 1 *})\n  apply (tactic {* action_simp_tac (@{context} addsimps [@{thm RNext_def}]) []\n    (@{thm squareE} ::\n      map (temp_elim @{context}) [@{thm S4Read}, @{thm S4Write}, @{thm S4Return}]) 1 *})\n  apply (auto dest!: S4Hist [temp_use])\n  done\n\nlemma Step1_2_5: \"|- [HNext rmhist p]_(c p,r p,m p, rmhist!p) & ImpNext p\n              & ~unchanged (e p, c p, r p, m p, rmhist!p) & $S5 rmhist p\n         --> ((S6 rmhist p)$ & RPCReply crCh rmCh rst p & unchanged (e p, c p, m p))\n             | ((S6 rmhist p)$ & RPCFail crCh rmCh rst p & unchanged (e p, c p, m p))\"\n  apply (tactic {* action_simp_tac (@{context} addsimps [@{thm ImpNext_def}]) []\n    (map (temp_elim @{context}) [@{thm S5EnvUnch}, @{thm S5ClerkUnch}, @{thm S5MemUnch}, @{thm S5Hist}]) 1 *})\n  apply (tactic {* action_simp_tac @{context} [] [@{thm squareE}, temp_elim @{context} @{thm S5RPC}] 1 *})\n   using [[fast_solver]]\n   apply (auto elim!: squareE [temp_use] dest!: S5Reply [temp_use] S5Fail [temp_use])\n  done\n\nlemma Step1_2_6: \"|- [HNext rmhist p]_(c p,r p,m p, rmhist!p) & ImpNext p\n              & ~unchanged (e p, c p, r p, m p, rmhist!p) & $S6 rmhist p\n         --> ((S1 rmhist p)$ & MClkReply memCh crCh cst p & unchanged (e p, r p, m p))\n             | ((S3 rmhist p)$ & MClkRetry memCh crCh cst p & unchanged (e p,r p,m p,rmhist!p))\"\n  apply (tactic {* action_simp_tac (@{context} addsimps [@{thm ImpNext_def}]) []\n    (map (temp_elim @{context}) [@{thm S6EnvUnch}, @{thm S6RPCUnch}, @{thm S6MemUnch}]) 1 *})\n  apply (tactic {* action_simp_tac @{context} []\n    (@{thm squareE} :: map (temp_elim @{context}) [@{thm S6Clerk}, @{thm S6Retry}, @{thm S6Reply}]) 1 *})\n     apply (auto dest: S6Hist [temp_use])\n  done\n\n(* --------------------------------------------------------------------------\n   Step 1.3: S1 implies the barred initial condition.\n*)\n\nsection \"Initialization (Step 1.3)\"\n\nlemma Step1_3: \"|- S1 rmhist p --> PInit (resbar rmhist) p\"\n  by (tactic {* action_simp_tac (@{context} addsimps [@{thm resbar_def},\n    @{thm PInit_def}, @{thm S_def}, @{thm S1_def}]) [] [] 1 *})\n\n(* ----------------------------------------------------------------------\n   Step 1.4: Implementation's next-state relation simulates specification's\n             next-state relation (with appropriate substitutions)\n*)\n\nsection \"Step simulation (Step 1.4)\"\n\nlemma Step1_4_1: \"|- ENext p & $S1 rmhist p & (S2 rmhist p)$ & unchanged (c p, r p, m p)\n         --> unchanged (rtrner memCh!p, resbar rmhist!p)\"\n  using [[fast_solver]]\n  by (auto elim!: squareE [temp_use] simp: c_def r_def m_def resbar_def)\n\nlemma Step1_4_2: \"|- MClkFwd memCh crCh cst p & $S2 rmhist p & (S3 rmhist p)$\n         & unchanged (e p, r p, m p, rmhist!p)\n         --> unchanged (rtrner memCh!p, resbar rmhist!p)\"\n  by (tactic {* action_simp_tac\n    (@{context} addsimps [@{thm MClkFwd_def}, @{thm e_def}, @{thm r_def}, @{thm m_def},\n    @{thm resbar_def}, @{thm S_def}, @{thm S2_def}, @{thm S3_def}]) [] [] 1 *})\n\nlemma Step1_4_3a: \"|- RPCFwd crCh rmCh rst p & $S3 rmhist p & (S4 rmhist p)$\n         & unchanged (e p, c p, m p, rmhist!p)\n         --> unchanged (rtrner memCh!p, resbar rmhist!p)\"\n  apply clarsimp\n  apply (drule S3_excl [temp_use] S4_excl [temp_use])+\n  apply (tactic {* action_simp_tac (@{context} addsimps [@{thm e_def},\n    @{thm c_def}, @{thm m_def}, @{thm resbar_def}, @{thm S_def}, @{thm S3_def}]) [] [] 1 *})\n  done\n\nlemma Step1_4_3b: \"|- RPCFail crCh rmCh rst p & $S3 rmhist p & (S6 rmhist p)$\n         & unchanged (e p, c p, m p)\n         --> MemFail memCh (resbar rmhist) p\"\n  apply clarsimp\n  apply (drule S6_excl [temp_use])\n  apply (auto simp: RPCFail_def MemFail_def e_def c_def m_def resbar_def)\n    apply (force simp: S3_def S_def)\n   apply (auto simp: Return_def)\n  done\n\nlemma Step1_4_4a1: \"|- $S4 rmhist p & (S4 rmhist p)$ & ReadInner rmCh mm ires p l\n         & unchanged (e p, c p, r p, rmhist!p) & $MemInv mm l\n         --> ReadInner memCh mm (resbar rmhist) p l\"\n  apply clarsimp\n  apply (drule S4_excl [temp_use])+\n  apply (tactic {* action_simp_tac (@{context} addsimps [@{thm ReadInner_def},\n    @{thm GoodRead_def}, @{thm BadRead_def}, @{thm e_def}, @{thm c_def}, @{thm m_def}]) [] [] 1 *})\n     apply (auto simp: resbar_def)\n       apply (tactic {* ALLGOALS (action_simp_tac\n                (@{context} addsimps [@{thm RPCRelayArg_def}, @{thm MClkRelayArg_def},\n                  @{thm S_def}, @{thm S4_def}, @{thm RdRequest_def}, @{thm MemInv_def}])\n                [] [@{thm impE}, @{thm MemValNotAResultE}]) *})\n  done\n\nlemma Step1_4_4a: \"|- Read rmCh mm ires p & $S4 rmhist p & (S4 rmhist p)$\n         & unchanged (e p, c p, r p, rmhist!p) & (!l. $(MemInv mm l))\n         --> Read memCh mm (resbar rmhist) p\"\n  by (force simp: Read_def elim!: Step1_4_4a1 [temp_use])\n\nlemma Step1_4_4b1: \"|- $S4 rmhist p & (S4 rmhist p)$ & WriteInner rmCh mm ires p l v\n         & unchanged (e p, c p, r p, rmhist!p)\n         --> WriteInner memCh mm (resbar rmhist) p l v\"\n  apply clarsimp\n  apply (drule S4_excl [temp_use])+\n  apply (tactic {* action_simp_tac (@{context} addsimps\n    [@{thm WriteInner_def}, @{thm GoodWrite_def}, @{thm BadWrite_def}, @{thm e_def},\n    @{thm c_def}, @{thm m_def}]) [] [] 1 *})\n     apply (auto simp: resbar_def)\n    apply (tactic {* ALLGOALS (action_simp_tac (@{context} addsimps\n      [@{thm RPCRelayArg_def}, @{thm MClkRelayArg_def}, @{thm S_def},\n      @{thm S4_def}, @{thm WrRequest_def}]) [] []) *})\n  done\n\nlemma Step1_4_4b: \"|- Write rmCh mm ires p l & $S4 rmhist p & (S4 rmhist p)$\n         & unchanged (e p, c p, r p, rmhist!p)\n         --> Write memCh mm (resbar rmhist) p l\"\n  by (force simp: Write_def elim!: Step1_4_4b1 [temp_use])\n\nlemma Step1_4_4c: \"|- MemReturn rmCh ires p & $S4 rmhist p & (S5 rmhist p)$\n         & unchanged (e p, c p, r p)\n         --> unchanged (rtrner memCh!p, resbar rmhist!p)\"\n  apply (tactic {* action_simp_tac (@{context} addsimps [@{thm e_def},\n    @{thm c_def}, @{thm r_def}, @{thm resbar_def}]) [] [] 1 *})\n  apply (drule S4_excl [temp_use] S5_excl [temp_use])+\n  using [[fast_solver]]\n  apply (auto elim!: squareE [temp_use] simp: MemReturn_def Return_def)\n  done\n\nlemma Step1_4_5a: \"|- RPCReply crCh rmCh rst p & $S5 rmhist p & (S6 rmhist p)$\n         & unchanged (e p, c p, m p)\n         --> unchanged (rtrner memCh!p, resbar rmhist!p)\"\n  apply clarsimp\n  apply (drule S5_excl [temp_use] S6_excl [temp_use])+\n  apply (auto simp: e_def c_def m_def resbar_def)\n   apply (auto simp: RPCReply_def Return_def S5_def S_def dest!: MVOKBAnotRF [temp_use])\n  done\n\nlemma Step1_4_5b: \"|- RPCFail crCh rmCh rst p & $S5 rmhist p & (S6 rmhist p)$\n         & unchanged (e p, c p, m p)\n         --> MemFail memCh (resbar rmhist) p\"\n  apply clarsimp\n  apply (drule S6_excl [temp_use])\n  apply (auto simp: e_def c_def m_def RPCFail_def Return_def MemFail_def resbar_def)\n   apply (auto simp: S5_def S_def)\n  done\n\nlemma Step1_4_6a: \"|- MClkReply memCh crCh cst p & $S6 rmhist p & (S1 rmhist p)$\n         & unchanged (e p, r p, m p)\n         --> MemReturn memCh (resbar rmhist) p\"\n  apply clarsimp\n  apply (drule S6_excl [temp_use])+\n  apply (tactic {* action_simp_tac (@{context} addsimps [@{thm e_def},\n    @{thm r_def}, @{thm m_def}, @{thm MClkReply_def}, @{thm MemReturn_def},\n    @{thm Return_def}, @{thm resbar_def}]) [] [] 1 *})\n    apply simp_all (* simplify if-then-else *)\n    apply (tactic {* ALLGOALS (action_simp_tac (@{context} addsimps\n      [@{thm MClkReplyVal_def}, @{thm S6_def}, @{thm S_def}]) [] [@{thm MVOKBARFnotNR}]) *})\n  done\n\nlemma Step1_4_6b: \"|- MClkRetry memCh crCh cst p & $S6 rmhist p & (S3 rmhist p)$\n         & unchanged (e p, r p, m p, rmhist!p)\n         --> MemFail memCh (resbar rmhist) p\"\n  apply clarsimp\n  apply (drule S3_excl [temp_use])+\n  apply (tactic {* action_simp_tac (@{context} addsimps [@{thm e_def}, @{thm r_def},\n    @{thm m_def}, @{thm MClkRetry_def}, @{thm MemFail_def}, @{thm resbar_def}]) [] [] 1 *})\n   apply (auto simp: S6_def S_def)\n  done\n\nlemma S_lemma: \"|- unchanged (e p, c p, r p, m p, rmhist!p)\n         --> unchanged (S rmhist ec cc rc cs rs hs1 hs2 p)\"\n  by (auto simp: e_def c_def r_def m_def caller_def rtrner_def S_def Calling_def)\n\nlemma Step1_4_7H: \"|- unchanged (e p, c p, r p, m p, rmhist!p)\n         --> unchanged (rtrner memCh!p, S1 rmhist p, S2 rmhist p, S3 rmhist p,\n                        S4 rmhist p, S5 rmhist p, S6 rmhist p)\"\n  apply clarsimp\n  apply (rule conjI)\n   apply (force simp: c_def)\n  apply (force simp: S1_def S2_def S3_def S4_def S5_def S6_def intro!: S_lemma [temp_use])\n  done\n\nlemma Step1_4_7: \"|- unchanged (e p, c p, r p, m p, rmhist!p)\n         --> unchanged (rtrner memCh!p, resbar rmhist!p, S1 rmhist p, S2 rmhist p,\n                        S3 rmhist p, S4 rmhist p, S5 rmhist p, S6 rmhist p)\"\n  apply (rule actionI)\n  apply (unfold action_rews)\n  apply (rule impI)\n  apply (frule Step1_4_7H [temp_use])\n  apply (auto simp: e_def c_def r_def m_def rtrner_def resbar_def)\n  done\n\n(* Frequently needed abbreviation: distinguish between idling and non-idling\n   steps of the implementation, and try to solve the idling case by simplification\n*)\nML {*\nfun split_idle_tac ctxt =\n  SELECT_GOAL\n   (TRY (rtac @{thm actionI} 1) THEN\n    Induct_Tacs.case_tac ctxt \"(s,t) |= unchanged (e p, c p, r p, m p, rmhist!p)\" 1 THEN\n    rewrite_goals_tac ctxt @{thms action_rews} THEN\n    forward_tac [temp_use ctxt @{thm Step1_4_7}] 1 THEN\n    asm_full_simp_tac ctxt 1);\n*}\n\nmethod_setup split_idle = {*\n  Method.sections (Simplifier.simp_modifiers @ Splitter.split_modifiers)\n    >> (K (SIMPLE_METHOD' o split_idle_tac))\n*}\n\n(* ----------------------------------------------------------------------\n   Combine steps 1.2 and 1.4 to prove that the implementation satisfies\n   the specification's next-state relation.\n*)\n\n(* Steps that leave all variables unchanged are safe, so I may assume\n   that some variable changes in the proof that a step is safe. *)\nlemma unchanged_safe: \"|- (~unchanged (e p, c p, r p, m p, rmhist!p)\n             --> [UNext memCh mm (resbar rmhist) p]_(rtrner memCh!p, resbar rmhist!p))\n         --> [UNext memCh mm (resbar rmhist) p]_(rtrner memCh!p, resbar rmhist!p)\"\n  apply (split_idle simp: square_def)\n  apply force\n  done\n(* turn into (unsafe, looping!) introduction rule *)\nlemmas unchanged_safeI = impI [THEN unchanged_safe [action_use]]\n\nlemma S1safe: \"|- $S1 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p)\n         --> [UNext memCh mm (resbar rmhist) p]_(rtrner memCh!p, resbar rmhist!p)\"\n  apply clarsimp\n  apply (rule unchanged_safeI)\n  apply (rule idle_squareI)\n  apply (auto dest!: Step1_2_1 [temp_use] Step1_4_1 [temp_use])\n  done\n\nlemma S2safe: \"|- $S2 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p)\n         --> [UNext memCh mm (resbar rmhist) p]_(rtrner memCh!p, resbar rmhist!p)\"\n  apply clarsimp\n  apply (rule unchanged_safeI)\n  apply (rule idle_squareI)\n  apply (auto dest!: Step1_2_2 [temp_use] Step1_4_2 [temp_use])\n  done\n\nlemma S3safe: \"|- $S3 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p)\n         --> [UNext memCh mm (resbar rmhist) p]_(rtrner memCh!p, resbar rmhist!p)\"\n  apply clarsimp\n  apply (rule unchanged_safeI)\n  apply (auto dest!: Step1_2_3 [temp_use])\n  apply (auto simp: square_def UNext_def dest!: Step1_4_3a [temp_use] Step1_4_3b [temp_use])\n  done\n\nlemma S4safe: \"|- $S4 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p)\n         & (!l. $(MemInv mm l))\n         --> [UNext memCh mm (resbar rmhist) p]_(rtrner memCh!p, resbar rmhist!p)\"\n  apply clarsimp\n  apply (rule unchanged_safeI)\n  apply (auto dest!: Step1_2_4 [temp_use])\n     apply (auto simp: square_def UNext_def RNext_def\n       dest!: Step1_4_4a [temp_use] Step1_4_4b [temp_use] Step1_4_4c [temp_use])\n  done\n\nlemma S5safe: \"|- $S5 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p)\n         --> [UNext memCh mm (resbar rmhist) p]_(rtrner memCh!p, resbar rmhist!p)\"\n  apply clarsimp\n  apply (rule unchanged_safeI)\n  apply (auto dest!: Step1_2_5 [temp_use])\n  apply (auto simp: square_def UNext_def dest!: Step1_4_5a [temp_use] Step1_4_5b [temp_use])\n  done\n\nlemma S6safe: \"|- $S6 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p)\n         --> [UNext memCh mm (resbar rmhist) p]_(rtrner memCh!p, resbar rmhist!p)\"\n  apply clarsimp\n  apply (rule unchanged_safeI)\n  apply (auto dest!: Step1_2_6 [temp_use])\n    apply (auto simp: square_def UNext_def RNext_def\n      dest!: Step1_4_6a [temp_use] Step1_4_6b [temp_use])\n  done\n\n(* ----------------------------------------------------------------------\n   Step 1.5: Temporal refinement proof, based on previous steps.\n*)\n\nsection \"The liveness part\"\n\n(* Liveness assertions for the different implementation states, based on the\n   fairness conditions. Prove subgoals of WF1 / SF1 rules as separate lemmas\n   for readability. Reuse action proofs from safety part.\n*)\n\n(* ------------------------------ State S1 ------------------------------ *)\n\nlemma S1_successors: \"|- $S1 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p)\n         --> (S1 rmhist p)$ | (S2 rmhist p)$\"\n  apply split_idle\n  apply (auto dest!: Step1_2_1 [temp_use])\n  done\n\n(* Show that the implementation can satisfy the high-level fairness requirements\n   by entering the state S1 infinitely often.\n*)\n\nlemma S1_RNextdisabled: \"|- S1 rmhist p -->\n         ~Enabled (<RNext memCh mm (resbar rmhist) p>_(rtrner memCh!p, resbar rmhist!p))\"\n  apply (tactic {* action_simp_tac (@{context} addsimps [@{thm angle_def},\n    @{thm S_def}, @{thm S1_def}]) [notI] [@{thm enabledE}, temp_elim @{context} @{thm Memoryidle}] 1 *})\n  apply force\n  done\n\nlemma S1_Returndisabled: \"|- S1 rmhist p -->\n         ~Enabled (<MemReturn memCh (resbar rmhist) p>_(rtrner memCh!p, resbar rmhist!p))\"\n  by (tactic {* action_simp_tac (@{context} addsimps [@{thm angle_def}, @{thm MemReturn_def},\n    @{thm Return_def}, @{thm S_def}, @{thm S1_def}]) [notI] [@{thm enabledE}] 1 *})\n\nlemma RNext_fair: \"|- []<>S1 rmhist p\n         --> WF(RNext memCh mm (resbar rmhist) p)_(rtrner memCh!p, resbar rmhist!p)\"\n  by (auto simp: WF_alt [try_rewrite] intro!: S1_RNextdisabled [temp_use]\n    elim!: STL4E [temp_use] DmdImplE [temp_use])\n\nlemma Return_fair: \"|- []<>S1 rmhist p\n         --> WF(MemReturn memCh (resbar rmhist) p)_(rtrner memCh!p, resbar rmhist!p)\"\n  by (auto simp: WF_alt [try_rewrite]\n    intro!: S1_Returndisabled [temp_use] elim!: STL4E [temp_use] DmdImplE [temp_use])\n\n(* ------------------------------ State S2 ------------------------------ *)\n\nlemma S2_successors: \"|- $S2 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p)\n         --> (S2 rmhist p)$ | (S3 rmhist p)$\"\n  apply split_idle\n  apply (auto dest!: Step1_2_2 [temp_use])\n  done\n\nlemma S2MClkFwd_successors: \"|- ($S2 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p))\n         & <MClkFwd memCh crCh cst p>_(c p)\n         --> (S3 rmhist p)$\"\n  by (auto simp: angle_def dest!: Step1_2_2 [temp_use])\n\nlemma S2MClkFwd_enabled: \"|- $S2 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p)\n         --> $Enabled (<MClkFwd memCh crCh cst p>_(c p))\"\n  apply (auto simp: c_def intro!: MClkFwd_ch_enabled [temp_use] MClkFwd_enabled [temp_use])\n     apply (cut_tac MI_base)\n     apply (blast dest: base_pair)\n    apply (simp_all add: S_def S2_def)\n  done\n\nlemma S2_live: \"|- [](ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p))\n         & WF(MClkFwd memCh crCh cst p)_(c p)\n         --> (S2 rmhist p ~> S3 rmhist p)\"\n  by (rule WF1 S2_successors S2MClkFwd_successors S2MClkFwd_enabled)+\n\n(* ------------------------------ State S3 ------------------------------ *)\n\nlemma S3_successors: \"|- $S3 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p)\n         --> (S3 rmhist p)$ | (S4 rmhist p | S6 rmhist p)$\"\n  apply split_idle\n  apply (auto dest!: Step1_2_3 [temp_use])\n  done\n\nlemma S3RPC_successors: \"|- ($S3 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p))\n         & <RPCNext crCh rmCh rst p>_(r p)\n         --> (S4 rmhist p | S6 rmhist p)$\"\n  apply (auto simp: angle_def dest!: Step1_2_3 [temp_use])\n  done\n\nlemma S3RPC_enabled: \"|- $S3 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p)\n         --> $Enabled (<RPCNext crCh rmCh rst p>_(r p))\"\n  apply (auto simp: r_def intro!: RPCFail_Next_enabled [temp_use] RPCFail_enabled [temp_use])\n    apply (cut_tac MI_base)\n    apply (blast dest: base_pair)\n   apply (simp_all add: S_def S3_def)\n  done\n\nlemma S3_live: \"|- [](ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p))\n         & WF(RPCNext crCh rmCh rst p)_(r p)\n         --> (S3 rmhist p ~> S4 rmhist p | S6 rmhist p)\"\n  by (rule WF1 S3_successors S3RPC_successors S3RPC_enabled)+\n\n(* ------------- State S4 -------------------------------------------------- *)\n\nlemma S4_successors: \"|- $S4 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p)\n        & (ALL l. $MemInv mm l)\n        --> (S4 rmhist p)$ | (S5 rmhist p)$\"\n  apply split_idle\n  apply (auto dest!: Step1_2_4 [temp_use])\n  done\n\n(* --------- State S4a: S4 /\\ (ires p = NotAResult) ------------------------ *)\n\nlemma S4a_successors: \"|- $(S4 rmhist p & ires!p = #NotAResult)\n         & ImpNext p & [HNext rmhist p]_(c p,r p,m p,rmhist!p) & (ALL l. $MemInv mm l)\n         --> (S4 rmhist p & ires!p = #NotAResult)$\n             | ((S4 rmhist p & ires!p ~= #NotAResult) | S5 rmhist p)$\"\n  apply split_idle\n  apply (auto dest!: Step1_2_4 [temp_use])\n  done\n\nlemma S4aRNext_successors: \"|- ($(S4 rmhist p & ires!p = #NotAResult)\n         & ImpNext p & [HNext rmhist p]_(c p,r p,m p,rmhist!p) & (ALL l. $MemInv mm l))\n         & <RNext rmCh mm ires p>_(m p)\n         --> ((S4 rmhist p & ires!p ~= #NotAResult) | S5 rmhist p)$\"\n  by (auto simp: angle_def\n    dest!: Step1_2_4 [temp_use] ReadResult [temp_use] WriteResult [temp_use])\n\nlemma S4aRNext_enabled: \"|- $(S4 rmhist p & ires!p = #NotAResult)\n         & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p) & (ALL l. $MemInv mm l)\n         --> $Enabled (<RNext rmCh mm ires p>_(m p))\"\n  apply (auto simp: m_def intro!: RNext_enabled [temp_use])\n   apply (cut_tac MI_base)\n   apply (blast dest: base_pair)\n  apply (simp add: S_def S4_def)\n  done\n\nlemma S4a_live: \"|- [](ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p)\n         & (ALL l. $MemInv mm l)) & WF(RNext rmCh mm ires p)_(m p)\n         --> (S4 rmhist p & ires!p = #NotAResult\n              ~> (S4 rmhist p & ires!p ~= #NotAResult) | S5 rmhist p)\"\n  by (rule WF1 S4a_successors S4aRNext_successors S4aRNext_enabled)+\n\n(* ---------- State S4b: S4 /\\ (ires p # NotAResult) --------------------------- *)\n\nlemma S4b_successors: \"|- $(S4 rmhist p & ires!p ~= #NotAResult)\n         & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p) & (ALL l. $MemInv mm l)\n         --> (S4 rmhist p & ires!p ~= #NotAResult)$ | (S5 rmhist p)$\"\n  apply (split_idle simp: m_def)\n  apply (auto dest!: WriteResult [temp_use] Step1_2_4 [temp_use] ReadResult [temp_use])\n  done\n\nlemma S4bReturn_successors: \"|- ($(S4 rmhist p & ires!p ~= #NotAResult)\n         & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p)\n         & (ALL l. $MemInv mm l)) & <MemReturn rmCh ires p>_(m p)\n         --> (S5 rmhist p)$\"\n  by (force simp: angle_def dest!: Step1_2_4 [temp_use] dest: ReturnNotReadWrite [temp_use])\n\nlemma S4bReturn_enabled: \"|- $(S4 rmhist p & ires!p ~= #NotAResult)\n         & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p)\n         & (ALL l. $MemInv mm l)\n         --> $Enabled (<MemReturn rmCh ires p>_(m p))\"\n  apply (auto simp: m_def intro!: MemReturn_enabled [temp_use])\n   apply (cut_tac MI_base)\n   apply (blast dest: base_pair)\n  apply (simp add: S_def S4_def)\n  done\n\nlemma S4b_live: \"|- [](ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p) & (!l. $MemInv mm l))\n         & WF(MemReturn rmCh ires p)_(m p)\n         --> (S4 rmhist p & ires!p ~= #NotAResult ~> S5 rmhist p)\"\n  by (rule WF1 S4b_successors S4bReturn_successors S4bReturn_enabled)+\n\n(* ------------------------------ State S5 ------------------------------ *)\n\nlemma S5_successors: \"|- $S5 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p)\n         --> (S5 rmhist p)$ | (S6 rmhist p)$\"\n  apply split_idle\n  apply (auto dest!: Step1_2_5 [temp_use])\n  done\n\nlemma S5RPC_successors: \"|- ($S5 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p))\n         & <RPCNext crCh rmCh rst p>_(r p)\n         --> (S6 rmhist p)$\"\n  by (auto simp: angle_def dest!: Step1_2_5 [temp_use])\n\nlemma S5RPC_enabled: \"|- $S5 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p)\n         --> $Enabled (<RPCNext crCh rmCh rst p>_(r p))\"\n  apply (auto simp: r_def intro!: RPCFail_Next_enabled [temp_use] RPCFail_enabled [temp_use])\n    apply (cut_tac MI_base)\n    apply (blast dest: base_pair)\n   apply (simp_all add: S_def S5_def)\n  done\n\nlemma S5_live: \"|- [](ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p))\n         & WF(RPCNext crCh rmCh rst p)_(r p)\n         --> (S5 rmhist p ~> S6 rmhist p)\"\n  by (rule WF1 S5_successors S5RPC_successors S5RPC_enabled)+\n\n(* ------------------------------ State S6 ------------------------------ *)\n\nlemma S6_successors: \"|- $S6 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p)\n         --> (S1 rmhist p)$ | (S3 rmhist p)$ | (S6 rmhist p)$\"\n  apply split_idle\n  apply (auto dest!: Step1_2_6 [temp_use])\n  done\n\nlemma S6MClkReply_successors:\n  \"|- ($S6 rmhist p & ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p))\n         & <MClkReply memCh crCh cst p>_(c p)\n         --> (S1 rmhist p)$\"\n  by (auto simp: angle_def dest!: Step1_2_6 [temp_use] MClkReplyNotRetry [temp_use])\n\nlemma MClkReplyS6:\n  \"|- $ImpInv rmhist p & <MClkReply memCh crCh cst p>_(c p) --> $S6 rmhist p\"\n  by (tactic {* action_simp_tac (@{context} addsimps [@{thm angle_def},\n    @{thm MClkReply_def}, @{thm Return_def}, @{thm ImpInv_def}, @{thm S_def},\n    @{thm S1_def}, @{thm S2_def}, @{thm S3_def}, @{thm S4_def}, @{thm S5_def}]) [] [] 1 *})\n\nlemma S6MClkReply_enabled: \"|- S6 rmhist p --> Enabled (<MClkReply memCh crCh cst p>_(c p))\"\n  apply (auto simp: c_def intro!: MClkReply_enabled [temp_use])\n     apply (cut_tac MI_base)\n     apply (blast dest: base_pair)\n    apply (tactic {* ALLGOALS (action_simp_tac (@{context}\n      addsimps [@{thm S_def}, @{thm S6_def}]) [] []) *})\n  done\n\nlemma S6_live: \"|- [](ImpNext p & [HNext rmhist p]_(c p,r p,m p, rmhist!p) & $(ImpInv rmhist p))\n         & SF(MClkReply memCh crCh cst p)_(c p) & []<>(S6 rmhist p)\n         --> []<>(S1 rmhist p)\"\n  apply clarsimp\n  apply (subgoal_tac \"sigma |= []<> (<MClkReply memCh crCh cst p>_ (c p))\")\n   apply (erule InfiniteEnsures)\n    apply assumption\n   apply (tactic {* action_simp_tac @{context} []\n     (map (temp_elim @{context}) [@{thm MClkReplyS6}, @{thm S6MClkReply_successors}]) 1 *})\n  apply (auto simp: SF_def)\n  apply (erule contrapos_np)\n  apply (auto intro!: S6MClkReply_enabled [temp_use] elim!: STL4E [temp_use] DmdImplE [temp_use])\n  done\n\n(* --------------- aggregate leadsto properties----------------------------- *)\n\nlemma S5S6LeadstoS6: \"sigma |= S5 rmhist p ~> S6 rmhist p\n      ==> sigma |= (S5 rmhist p | S6 rmhist p) ~> S6 rmhist p\"\n  by (auto intro!: LatticeDisjunctionIntro [temp_use] LatticeReflexivity [temp_use])\n\nlemma S4bS5S6LeadstoS6: \"[| sigma |= S4 rmhist p & ires!p ~= #NotAResult ~> S5 rmhist p;\n         sigma |= S5 rmhist p ~> S6 rmhist p |]\n      ==> sigma |= (S4 rmhist p & ires!p ~= #NotAResult) | S5 rmhist p | S6 rmhist p\n                    ~> S6 rmhist p\"\n  by (auto intro!: LatticeDisjunctionIntro [temp_use]\n    S5S6LeadstoS6 [temp_use] intro: LatticeTransitivity [temp_use])\n\nlemma S4S5S6LeadstoS6: \"[| sigma |= S4 rmhist p & ires!p = #NotAResult\n                  ~> (S4 rmhist p & ires!p ~= #NotAResult) | S5 rmhist p;\n         sigma |= S4 rmhist p & ires!p ~= #NotAResult ~> S5 rmhist p;\n         sigma |= S5 rmhist p ~> S6 rmhist p |]\n      ==> sigma |= S4 rmhist p | S5 rmhist p | S6 rmhist p ~> S6 rmhist p\"\n  apply (subgoal_tac \"sigma |= (S4 rmhist p & ires!p = #NotAResult) |\n    (S4 rmhist p & ires!p ~= #NotAResult) | S5 rmhist p | S6 rmhist p ~> S6 rmhist p\")\n   apply (erule_tac G = \"PRED ((S4 rmhist p & ires!p = #NotAResult) |\n     (S4 rmhist p & ires!p ~= #NotAResult) | S5 rmhist p | S6 rmhist p)\" in\n     LatticeTransitivity [temp_use])\n   apply (force simp: Init_defs intro!: ImplLeadsto_gen [temp_use] necT [temp_use])\n  apply (rule LatticeDisjunctionIntro [temp_use])\n   apply (erule LatticeTransitivity [temp_use])\n   apply (erule LatticeTriangle2 [temp_use])\n   apply assumption\n  apply (auto intro!: S4bS5S6LeadstoS6 [temp_use])\n  done\n\nlemma S3S4S5S6LeadstoS6: \"[| sigma |= S3 rmhist p ~> S4 rmhist p | S6 rmhist p;\n         sigma |= S4 rmhist p & ires!p = #NotAResult\n                  ~> (S4 rmhist p & ires!p ~= #NotAResult) | S5 rmhist p;\n         sigma |= S4 rmhist p & ires!p ~= #NotAResult ~> S5 rmhist p;\n         sigma |= S5 rmhist p ~> S6 rmhist p |]\n      ==> sigma |= S3 rmhist p | S4 rmhist p | S5 rmhist p | S6 rmhist p ~> S6 rmhist p\"\n  apply (rule LatticeDisjunctionIntro [temp_use])\n   apply (erule LatticeTriangle2 [temp_use])\n   apply (rule S4S5S6LeadstoS6 [THEN LatticeTransitivity [temp_use]])\n      apply (auto intro!: S4S5S6LeadstoS6 [temp_use] necT [temp_use]\n        intro: ImplLeadsto_gen [temp_use] simp: Init_defs)\n  done\n\nlemma S2S3S4S5S6LeadstoS6: \"[| sigma |= S2 rmhist p ~> S3 rmhist p;\n         sigma |= S3 rmhist p ~> S4 rmhist p | S6 rmhist p;\n         sigma |= S4 rmhist p & ires!p = #NotAResult\n                  ~> S4 rmhist p & ires!p ~= #NotAResult | S5 rmhist p;\n         sigma |= S4 rmhist p & ires!p ~= #NotAResult ~> S5 rmhist p;\n         sigma |= S5 rmhist p ~> S6 rmhist p |]\n      ==> sigma |= S2 rmhist p | S3 rmhist p | S4 rmhist p | S5 rmhist p | S6 rmhist p\n                   ~> S6 rmhist p\"\n  apply (rule LatticeDisjunctionIntro [temp_use])\n   apply (rule LatticeTransitivity [temp_use])\n    prefer 2 apply assumption\n   apply (rule S3S4S5S6LeadstoS6 [THEN LatticeTransitivity [temp_use]])\n       apply (auto intro!: S3S4S5S6LeadstoS6 [temp_use] necT [temp_use]\n         intro: ImplLeadsto_gen [temp_use] simp: Init_defs)\n  done\n\nlemma NotS1LeadstoS6: \"[| sigma |= []ImpInv rmhist p;\n         sigma |= S2 rmhist p ~> S3 rmhist p;\n         sigma |= S3 rmhist p ~> S4 rmhist p | S6 rmhist p;\n         sigma |= S4 rmhist p & ires!p = #NotAResult\n                  ~> S4 rmhist p & ires!p ~= #NotAResult | S5 rmhist p;\n         sigma |= S4 rmhist p & ires!p ~= #NotAResult ~> S5 rmhist p;\n         sigma |= S5 rmhist p ~> S6 rmhist p |]\n      ==> sigma |= ~S1 rmhist p ~> S6 rmhist p\"\n  apply (rule S2S3S4S5S6LeadstoS6 [THEN LatticeTransitivity [temp_use]])\n       apply assumption+\n  apply (erule INV_leadsto [temp_use])\n  apply (rule ImplLeadsto_gen [temp_use])\n  apply (rule necT [temp_use])\n  apply (auto simp: ImpInv_def Init_defs intro!: necT [temp_use])\n  done\n\nlemma S1Infinite: \"[| sigma |= ~S1 rmhist p ~> S6 rmhist p;\n         sigma |= []<>S6 rmhist p --> []<>S1 rmhist p |]\n      ==> sigma |= []<>S1 rmhist p\"\n  apply (rule classical)\n  apply (tactic {* asm_lr_simp_tac (@{context} addsimps\n    [temp_use @{context} @{thm NotBox}, temp_rewrite @{context} @{thm NotDmd}]) 1 *})\n  apply (auto elim!: leadsto_infinite [temp_use] mp dest!: DBImplBD [temp_use])\n  done\n\nsection \"Refinement proof (step 1.5)\"\n\n(* Prove invariants of the implementation:\n   a. memory invariant\n   b. \"implementation invariant\": always in states S1,...,S6\n*)\nlemma Step1_5_1a: \"|- IPImp p --> (ALL l. []$MemInv mm l)\"\n  by (auto simp: IPImp_def box_stp_act [temp_use] intro!: MemoryInvariantAll [temp_use])\n\nlemma Step1_5_1b: \"|- Init(ImpInit p & HInit rmhist p) & [](ImpNext p)\n         & [][HNext rmhist p]_(c p, r p, m p, rmhist!p) & [](ALL l. $MemInv mm l)\n         --> []ImpInv rmhist p\"\n  apply invariant\n   apply (auto simp: Init_def ImpInv_def box_stp_act [temp_use]\n     dest!: Step1_1 [temp_use] dest: S1_successors [temp_use] S2_successors [temp_use]\n     S3_successors [temp_use] S4_successors [temp_use] S5_successors [temp_use]\n     S6_successors [temp_use])\n  done\n\n(*** Initialization ***)\nlemma Step1_5_2a: \"|- Init(ImpInit p & HInit rmhist p) --> Init(PInit (resbar rmhist) p)\"\n  by (auto simp: Init_def intro!: Step1_1 [temp_use] Step1_3  [temp_use])\n\n(*** step simulation ***)\nlemma Step1_5_2b: \"|- [](ImpNext p & [HNext rmhist p]_(c p, r p, m p, rmhist!p)\n         & $ImpInv rmhist p & (!l. $MemInv mm l))\n         --> [][UNext memCh mm (resbar rmhist) p]_(rtrner memCh!p, resbar rmhist!p)\"\n  by (auto simp: ImpInv_def elim!: STL4E [temp_use]\n    dest!: S1safe [temp_use] S2safe [temp_use] S3safe [temp_use] S4safe [temp_use]\n    S5safe [temp_use] S6safe [temp_use])\n\n(*** Liveness ***)\nlemma GoodImpl: \"|- IPImp p & HistP rmhist p\n         -->   Init(ImpInit p & HInit rmhist p)\n             & [](ImpNext p & [HNext rmhist p]_(c p, r p, m p, rmhist!p))\n             & [](ALL l. $MemInv mm l) & []($ImpInv rmhist p)\n             & ImpLive p\"\n  apply clarsimp\n    apply (subgoal_tac \"sigma |= Init (ImpInit p & HInit rmhist p) & [] (ImpNext p) &\n      [][HNext rmhist p]_ (c p, r p, m p, rmhist!p) & [] (ALL l. $MemInv mm l)\")\n   apply (auto simp: split_box_conj [try_rewrite] box_stp_act [try_rewrite]\n       dest!: Step1_5_1b [temp_use])\n      apply (force simp: IPImp_def MClkIPSpec_def RPCIPSpec_def RPSpec_def\n        ImpLive_def c_def r_def m_def)\n      apply (force simp: IPImp_def MClkIPSpec_def RPCIPSpec_def RPSpec_def\n        HistP_def Init_def ImpInit_def)\n    apply (force simp: IPImp_def MClkIPSpec_def RPCIPSpec_def RPSpec_def\n      ImpNext_def c_def r_def m_def split_box_conj [temp_use])\n   apply (force simp: HistP_def)\n  apply (force simp: allT [temp_use] dest!: Step1_5_1a [temp_use])\n  done\n\n(* The implementation is infinitely often in state S1... *)\nlemma Step1_5_3a: \"|- [](ImpNext p & [HNext rmhist p]_(c p, r p, m p, rmhist!p))\n         & [](ALL l. $MemInv mm l)\n         & []($ImpInv rmhist p) & ImpLive p\n         --> []<>S1 rmhist p\"\n  apply (clarsimp simp: ImpLive_def)\n  apply (rule S1Infinite)\n   apply (force simp: split_box_conj [try_rewrite] box_stp_act [try_rewrite]\n     intro!: NotS1LeadstoS6 [temp_use] S2_live [temp_use] S3_live [temp_use]\n     S4a_live [temp_use] S4b_live [temp_use] S5_live [temp_use])\n  apply (auto simp: split_box_conj [temp_use] intro!: S6_live [temp_use])\n  done\n\n(* ... and therefore satisfies the fairness requirements of the specification *)\nlemma Step1_5_3b: \"|- [](ImpNext p & [HNext rmhist p]_(c p, r p, m p, rmhist!p))\n         & [](ALL l. $MemInv mm l) & []($ImpInv rmhist p) & ImpLive p\n         --> WF(RNext memCh mm (resbar rmhist) p)_(rtrner memCh!p, resbar rmhist!p)\"\n  by (auto intro!: RNext_fair [temp_use] Step1_5_3a [temp_use])\n\nlemma Step1_5_3c: \"|- [](ImpNext p & [HNext rmhist p]_(c p, r p, m p, rmhist!p))\n         & [](ALL l. $MemInv mm l) & []($ImpInv rmhist p) & ImpLive p\n         --> WF(MemReturn memCh (resbar rmhist) p)_(rtrner memCh!p, resbar rmhist!p)\"\n  by (auto intro!: Return_fair [temp_use] Step1_5_3a [temp_use])\n\n(* QED step of step 1 *)\nlemma Step1: \"|- IPImp p & HistP rmhist p --> UPSpec memCh mm (resbar rmhist) p\"\n  by (auto simp: UPSpec_def split_box_conj [temp_use]\n    dest!: GoodImpl [temp_use] intro!: Step1_5_2a [temp_use] Step1_5_2b [temp_use]\n    Step1_5_3b [temp_use] Step1_5_3c [temp_use])\n\n(* ------------------------------ Step 2 ------------------------------ *)\nsection \"Step 2\"\n\nlemma Step2_2a: \"|- Write rmCh mm ires p l & ImpNext p\n         & [HNext rmhist p]_(c p, r p, m p, rmhist!p)\n         & $ImpInv rmhist p\n         --> (S4 rmhist p)$ & unchanged (e p, c p, r p, rmhist!p)\"\n  apply clarsimp\n  apply (drule WriteS4 [action_use])\n   apply assumption\n  apply split_idle\n  apply (auto simp: ImpNext_def dest!: S4EnvUnch [temp_use] S4ClerkUnch [temp_use]\n    S4RPCUnch [temp_use])\n     apply (auto simp: square_def dest: S4Write [temp_use])\n  done\n\nlemma Step2_2: \"|-   (ALL p. ImpNext p)\n         & (ALL p. [HNext rmhist p]_(c p, r p, m p, rmhist!p))\n         & (ALL p. $ImpInv rmhist p)\n         & [EX q. Write rmCh mm ires q l]_(mm!l)\n         --> [EX q. Write memCh mm (resbar rmhist) q l]_(mm!l)\"\n  apply (auto intro!: squareCI elim!: squareE)\n  apply (assumption | rule exI Step1_4_4b [action_use])+\n    apply (force intro!: WriteS4 [temp_use])\n   apply (auto dest!: Step2_2a [temp_use])\n  done\n\nlemma Step2_lemma: \"|- [](  (ALL p. ImpNext p)\n            & (ALL p. [HNext rmhist p]_(c p, r p, m p, rmhist!p))\n            & (ALL p. $ImpInv rmhist p)\n            & [EX q. Write rmCh mm ires q l]_(mm!l))\n         --> [][EX q. Write memCh mm (resbar rmhist) q l]_(mm!l)\"\n  by (force elim!: STL4E [temp_use] dest!: Step2_2 [temp_use])\n\nlemma Step2: \"|- #l : #MemLoc & (ALL p. IPImp p & HistP rmhist p)\n         --> MSpec memCh mm (resbar rmhist) l\"\n  apply (auto simp: MSpec_def)\n   apply (force simp: IPImp_def MSpec_def)\n  apply (auto intro!: Step2_lemma [temp_use] simp: split_box_conj [temp_use] all_box [temp_use])\n     prefer 4\n     apply (force simp: IPImp_def MSpec_def)\n    apply (auto simp: split_box_conj [temp_use] elim!: allE dest!: GoodImpl [temp_use])\n  done\n\n(* ----------------------------- Main theorem --------------------------------- *)\nsection \"Memory implementation\"\n\n(* The combination of a legal caller, the memory clerk, the RPC component,\n   and a reliable memory implement the unreliable memory.\n*)\n\n(* Implementation of internal specification by combination of implementation\n   and history variable with explicit refinement mapping\n*)\nlemma Impl_IUSpec: \"|- Implementation & Hist rmhist --> IUSpec memCh mm (resbar rmhist)\"\n  by (auto simp: IUSpec_def Implementation_def IPImp_def MClkISpec_def\n    RPCISpec_def IRSpec_def Hist_def intro!: Step1 [temp_use] Step2 [temp_use])\n\n(* The main theorem: introduce hiding and eliminate history variable. *)\nlemma Implementation: \"|- Implementation --> USpec memCh\"\n  apply clarsimp\n  apply (frule History [temp_use])\n  apply (auto simp: USpec_def intro: eexI [temp_use] Impl_IUSpec [temp_use]\n    MI_base [temp_use] elim!: eexE)\n  done\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/TLA/Memory/MemoryImplementation.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6150878555160665, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.26693672851995126}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the GNU General Public License version 2. Note that NO WARRANTY is provided.\n * See \"LICENSE_GPLv2.txt\" for details.\n *\n * @TAG(NICTA_GPL)\n *)\n\ntheory MoreCorres\nimports \"../../lib/ExtraCorres\"\nbegin\n\n(* FIXME: move all of this into ExtraCorres *)\n\n(*\n * If both systems perform non-determinism where the splits are\n * equivalent, we can prove each pair separately.\n *)\nlemma corres_alternate_match:\n  \"\\<lbrakk> corres_underlying sr nf nf' r P P' a c;\n     corres_underlying sr nf nf' r P P' b d \\<rbrakk> \\<Longrightarrow>\n   corres_underlying sr nf nf' r P P' (a \\<sqinter> b) (c \\<sqinter> d)\"\n  apply (simp add: corres_underlying_def alternative_def)\n  apply (clarsimp)\n  apply (drule (1) bspec, clarsimp)+\n  apply fastforce\n  done\n\n(*\n * If the concrete system performs non-determinism where the abstract\n * system does not, we must show that both branches of the concrete\n * system refine the abstract system.\n *)\nlemma corres_alternate_split:\n  \"\\<lbrakk> corres_underlying sr nf nf' r P Q a x;\n     corres_underlying sr nf nf' r P' Q' a y \\<rbrakk> \\<Longrightarrow>\n   corres_underlying sr nf nf' r (P and P') (Q and Q') a (x \\<sqinter> y)\"\n  apply (simp add: corres_underlying_def alternative_def)\n  apply (clarsimp)\n  apply (drule (1) bspec, clarsimp)+\n  apply fastforce\n  done\n\n(*\n * Two select statements are equivalent if the concrete's select set is\n * a subset of the abstract's select set.\n *)\nlemma corres_select_equiv:\n  \"\\<lbrakk> \\<forall>a' \\<in> A'. \\<exists>a \\<in> A. r a a' \\<rbrakk> \\<Longrightarrow> corres_underlying sr nf nf' r \\<top> \\<top> (select A) (select A')\"\n  apply (clarsimp simp: corres_underlying_def)\n  apply (clarsimp simp: split_def)\n  apply (clarsimp simp: select_def)\n  done\n\n(*\n * Where there is an 'if' statement in the concrete system not present\n * in the abstract system, we must show that both branches are a  valid\n * refinement. Happily, we get to assume the outcome of the 'if'\n * statement when proving the refinement.\n *\n * This will likely need to be used with 'stronger_corres_guard_imp'.\n *)\nlemma corres_if_rhs:\n  \"\\<lbrakk>  G \\<Longrightarrow> corres_underlying sr nf nf' rvr P  Q  a b;\n     \\<not>G \\<Longrightarrow> corres_underlying sr nf nf' rvr P' Q' a c \\<rbrakk> \\<Longrightarrow>\n   corres_underlying sr nf nf' rvr\n       (\\<lambda>s. (G \\<longrightarrow> P s) \\<and> (\\<not>G \\<longrightarrow> P' s)) (\\<lambda>s. (G \\<longrightarrow> Q s) \\<and> (\\<not>G \\<longrightarrow> Q' s))\n       a (if G then b else c)\"\n  by (auto elim: corres_guard_imp)\n\n(* Bind distributes over non-deterministic choice. *)\nlemma alternative_bind_distrib: \"((f \\<sqinter> g) >>= h) = ((f >>= h) \\<sqinter> (g >>= h))\"\n  apply (auto simp: alternative_def bind_def split_def intro!: prod_eqI)\n  done\n\n(* Bind distributes over non-deterministic choice. *)\nlemma alternative_bind_distrib_2: \"(do f; (a \\<sqinter> b) od) = ((do f; a od) \\<sqinter> (do f; b od))\"\n  apply (auto simp: alternative_def bind_def split_def intro!: prod_eqI)\n  done\n\n(* \"bindE\" distributes over non-deterministic choice. *)\nlemma alternative_bindE_distrib: \"((f \\<sqinter> g) >>=E h) = ((f >>=E h) \\<sqinter> (g >>=E h))\"\n  by (simp add: bindE_def alternative_bind_distrib)\n\n(*\n * Two arbitrary return statements correspond if our return relation\n * doesn't care about them.\n *)\nlemma corres_return_dc [simp]:\n  \"corres_underlying sr nf nf' dc \\<top> \\<top> (return a) (return b)\"\n  apply (clarsimp simp: corres_underlying_def dc_def return_def)\n  done\n\n(* If our return relation doesn't matter, return statements are meaningless. *)\nlemma corres_return_dc_rhs:\n  \"corres_underlying sr nf nf' dc G G' P P' \\<Longrightarrow> corres_underlying sr nf nf' dc G G' P (do P'; return a od)\"\n  by (fastforce simp: corres_underlying_def dc_def return_def bind_def)\n\n(* If our return relation doesn't matter, return statements are meaningless. *)\nlemma corres_return_dc_lhs:\n  \"corres_underlying sr nf nf' dc G G' P P' \\<Longrightarrow> corres_underlying sr nf nf' dc G G' (do P; return a od) P'\"\n  apply (case_tac nf)\n   apply (clarsimp simp: corres_underlying_def dc_def return_def bind_def, force)\n  apply (clarsimp simp: corres_underlying_def dc_def return_def bind_def, force) (* slow 10s *)\n  done\n\n(* liftE distributes inside bind. *)\nlemma liftE_distrib: \"(liftE (A >>= (\\<lambda>_. B))) = ((liftE A) >>=E (\\<lambda>x. (liftE B)))\"\n  apply (clarsimp simp: liftE_def bindE_def)\n  apply (subst bind_assoc)+\n  apply (clarsimp simp: bind_def lift_def)\n  done\n\n(* liftE distributes inside alternate. *)\nlemma liftE_alternative_distrib: \"(liftE (a \\<sqinter> b)) = ((liftE a) \\<sqinter> (liftE b))\"\n  by (metis alternative_bind_distrib bindE_returnOk liftE_bindE)\n\nlemma corres_skip_catch:\n  \"corres_underlying sr nf nf' dc P P' f g \\<Longrightarrow>\n   corres_underlying sr nf nf' dc P P' f (g <catch> (\\<lambda>_. return x))\"\n  by (clarsimp simp: corres_underlying_def catch_def return_def bind_def \n                     split_def \n               split: sum.splits)\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/l4v/proof/drefine/MoreCorres.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.626124191181315, "lm_q2_score": 0.42632159254749036, "lm_q1q2_score": 0.2669302623169275}}
{"text": "(*  Title:      HOL/Auth/CertifiedEmail.thy\n    Author:     Giampaolo Bella, Christiano Longo and Lawrence C Paulson\n*)\n\nsection\\<open>The Certified Electronic Mail Protocol by Abadi et al.\\<close>\n\ntheory CertifiedEmail imports Public begin\n\nabbreviation\n  TTP :: agent where\n  \"TTP == Server\"\n\nabbreviation\n  RPwd :: \"agent \\<Rightarrow> key\" where\n  \"RPwd == shrK\"\n\n \n(*FIXME: the four options should be represented by pairs of 0 or 1.\n  Right now only BothAuth is modelled.*)\nconsts\n  NoAuth   :: nat\n  TTPAuth  :: nat\n  SAuth    :: nat\n  BothAuth :: nat\n\ntext\\<open>We formalize a fixed way of computing responses.  Could be better.\\<close>\ndefinition \"response\" :: \"agent \\<Rightarrow> agent \\<Rightarrow> nat \\<Rightarrow> msg\" where\n   \"response S R q == Hash \\<lbrace>Agent S, Key (shrK R), Nonce q\\<rbrace>\"\n\n\ninductive_set certified_mail :: \"event list set\"\n  where\n\n  Nil: \\<comment> \\<open>The empty trace\\<close>\n     \"[] \\<in> certified_mail\"\n\n| Fake: \\<comment> \\<open>The Spy may say anything he can say.  The sender field is correct,\n          but agents don't use that information.\\<close>\n      \"\\<lbrakk>evsf \\<in> certified_mail; X \\<in> synth(analz(spies evsf))\\<rbrakk> \n       \\<Longrightarrow> Says Spy B X # evsf \\<in> certified_mail\"\n\n| FakeSSL: \\<comment> \\<open>The Spy may open SSL sessions with TTP, who is the only agent\n    equipped with the necessary credentials to serve as an SSL server.\\<close>\n         \"\\<lbrakk>evsfssl \\<in> certified_mail; X \\<in> synth(analz(spies evsfssl))\\<rbrakk>\n          \\<Longrightarrow> Notes TTP \\<lbrace>Agent Spy, Agent TTP, X\\<rbrace> # evsfssl \\<in> certified_mail\"\n\n| CM1: \\<comment> \\<open>The sender approaches the recipient.  The message is a number.\\<close>\n \"\\<lbrakk>evs1 \\<in> certified_mail;\n    Key K \\<notin> used evs1;\n    K \\<in> symKeys;\n    Nonce q \\<notin> used evs1;\n    hs = Hash\\<lbrace>Number cleartext, Nonce q, response S R q, Crypt K (Number m)\\<rbrace>;\n    S2TTP = Crypt(pubEK TTP) \\<lbrace>Agent S, Number BothAuth, Key K, Agent R, hs\\<rbrace>\\<rbrakk>\n  \\<Longrightarrow> Says S R \\<lbrace>Agent S, Agent TTP, Crypt K (Number m), Number BothAuth, \n                 Number cleartext, Nonce q, S2TTP\\<rbrace> # evs1 \n        \\<in> certified_mail\"\n\n| CM2: \\<comment> \\<open>The recipient records \\<^term>\\<open>S2TTP\\<close> while transmitting it and her\n     password to \\<^term>\\<open>TTP\\<close> over an SSL channel.\\<close>\n \"\\<lbrakk>evs2 \\<in> certified_mail;\n    Gets R \\<lbrace>Agent S, Agent TTP, em, Number BothAuth, Number cleartext, \n             Nonce q, S2TTP\\<rbrace> \\<in> set evs2;\n    TTP \\<noteq> R;  \n    hr = Hash \\<lbrace>Number cleartext, Nonce q, response S R q, em\\<rbrace>\\<rbrakk>\n  \\<Longrightarrow> \n   Notes TTP \\<lbrace>Agent R, Agent TTP, S2TTP, Key(RPwd R), hr\\<rbrace> # evs2\n      \\<in> certified_mail\"\n\n| CM3: \\<comment> \\<open>\\<^term>\\<open>TTP\\<close> simultaneously reveals the key to the recipient and gives\n         a receipt to the sender.  The SSL channel does not authenticate \n         the client (\\<^term>\\<open>R\\<close>), but \\<^term>\\<open>TTP\\<close> accepts the message only \n         if the given password is that of the claimed sender, \\<^term>\\<open>R\\<close>.\n         He replies over the established SSL channel.\\<close>\n \"\\<lbrakk>evs3 \\<in> certified_mail;\n    Notes TTP \\<lbrace>Agent R, Agent TTP, S2TTP, Key(RPwd R), hr\\<rbrace> \\<in> set evs3;\n    S2TTP = Crypt (pubEK TTP) \n                     \\<lbrace>Agent S, Number BothAuth, Key k, Agent R, hs\\<rbrace>;\n    TTP \\<noteq> R;  hs = hr;  k \\<in> symKeys\\<rbrakk>\n  \\<Longrightarrow> \n   Notes R \\<lbrace>Agent TTP, Agent R, Key k, hr\\<rbrace> # \n   Gets S (Crypt (priSK TTP) S2TTP) # \n   Says TTP S (Crypt (priSK TTP) S2TTP) # evs3 \\<in> certified_mail\"\n\n| Reception:\n \"\\<lbrakk>evsr \\<in> certified_mail; Says A B X \\<in> set evsr\\<rbrakk>\n  \\<Longrightarrow> Gets B X#evsr \\<in> certified_mail\"\n\n\ndeclare Says_imp_knows_Spy [THEN analz.Inj, dest]\ndeclare analz_into_parts [dest]\n\n(*A \"possibility property\": there are traces that reach the end*)\nlemma \"\\<lbrakk>Key K \\<notin> used []; K \\<in> symKeys\\<rbrakk> \\<Longrightarrow> \n       \\<exists>S2TTP. \\<exists>evs \\<in> certified_mail.\n           Says TTP S (Crypt (priSK TTP) S2TTP) \\<in> set evs\"\napply (intro exI bexI)\napply (rule_tac [2] certified_mail.Nil\n                    [THEN certified_mail.CM1, THEN certified_mail.Reception,\n                     THEN certified_mail.CM2, \n                     THEN certified_mail.CM3]) \napply (possibility, auto) \ndone\n\n\nlemma Gets_imp_Says:\n \"\\<lbrakk>Gets B X \\<in> set evs; evs \\<in> certified_mail\\<rbrakk> \\<Longrightarrow> \\<exists>A. Says A B X \\<in> set evs\"\napply (erule rev_mp)\napply (erule certified_mail.induct, auto)\ndone\n\n\nlemma Gets_imp_parts_knows_Spy:\n     \"\\<lbrakk>Gets A X \\<in> set evs; evs \\<in> certified_mail\\<rbrakk> \\<Longrightarrow> X \\<in> parts(spies evs)\"\napply (drule Gets_imp_Says, simp)\napply (blast dest: Says_imp_knows_Spy parts.Inj) \ndone\n\nlemma CM2_S2TTP_analz_knows_Spy:\n \"\\<lbrakk>Gets R \\<lbrace>Agent A, Agent B, em, Number AO, Number cleartext, \n              Nonce q, S2TTP\\<rbrace> \\<in> set evs;\n    evs \\<in> certified_mail\\<rbrakk> \n  \\<Longrightarrow> S2TTP \\<in> analz(spies evs)\"\napply (drule Gets_imp_Says, simp) \napply (blast dest: Says_imp_knows_Spy analz.Inj) \ndone\n\nlemmas CM2_S2TTP_parts_knows_Spy = \n    CM2_S2TTP_analz_knows_Spy [THEN analz_subset_parts [THEN subsetD]]\n\nlemma hr_form_lemma [rule_format]:\n \"evs \\<in> certified_mail\n  \\<Longrightarrow> hr \\<notin> synth (analz (spies evs)) \\<longrightarrow>\n      (\\<forall>S2TTP. Notes TTP \\<lbrace>Agent R, Agent TTP, S2TTP, pwd, hr\\<rbrace>\n          \\<in> set evs \\<longrightarrow>\n      (\\<exists>clt q S em. hr = Hash \\<lbrace>Number clt, Nonce q, response S R q, em\\<rbrace>))\"\napply (erule certified_mail.induct)\napply (synth_analz_mono_contra, simp_all, blast+)\ndone \n\ntext\\<open>Cannot strengthen the first disjunct to \\<^term>\\<open>R\\<noteq>Spy\\<close> because\nthe fakessl rule allows Spy to spoof the sender's name.  Maybe can\nstrengthen the second disjunct with \\<^term>\\<open>R\\<noteq>Spy\\<close>.\\<close>\nlemma hr_form:\n \"\\<lbrakk>Notes TTP \\<lbrace>Agent R, Agent TTP, S2TTP, pwd, hr\\<rbrace> \\<in> set evs;\n    evs \\<in> certified_mail\\<rbrakk>\n  \\<Longrightarrow> hr \\<in> synth (analz (spies evs)) | \n      (\\<exists>clt q S em. hr = Hash \\<lbrace>Number clt, Nonce q, response S R q, em\\<rbrace>)\"\nby (blast intro: hr_form_lemma) \n\nlemma Spy_dont_know_private_keys [dest!]:\n    \"\\<lbrakk>Key (privateKey b A) \\<in> parts (spies evs); evs \\<in> certified_mail\\<rbrakk>\n     \\<Longrightarrow> A \\<in> bad\"\napply (erule rev_mp) \napply (erule certified_mail.induct, simp_all)\ntxt\\<open>Fake\\<close>\napply (blast dest: Fake_parts_insert_in_Un) \ntxt\\<open>Message 1\\<close>\napply blast  \ntxt\\<open>Message 3\\<close>\napply (frule_tac hr_form, assumption)\napply (elim disjE exE) \napply (simp_all add: parts_insert2) \n apply (force dest!: parts_insert_subset_Un [THEN [2] rev_subsetD] \n                     analz_subset_parts [THEN subsetD], blast) \ndone\n\nlemma Spy_know_private_keys_iff [simp]:\n    \"evs \\<in> certified_mail\n     \\<Longrightarrow> (Key (privateKey b A) \\<in> parts (spies evs)) = (A \\<in> bad)\"\nby blast \n\nlemma Spy_dont_know_TTPKey_parts [simp]:\n     \"evs \\<in> certified_mail \\<Longrightarrow> Key (privateKey b TTP) \\<notin> parts(spies evs)\" \nby simp\n\nlemma Spy_dont_know_TTPKey_analz [simp]:\n     \"evs \\<in> certified_mail \\<Longrightarrow> Key (privateKey b TTP) \\<notin> analz(spies evs)\"\nby auto\n\ntext\\<open>Thus, prove any goal that assumes that \\<^term>\\<open>Spy\\<close> knows a private key\nbelonging to \\<^term>\\<open>TTP\\<close>\\<close>\ndeclare Spy_dont_know_TTPKey_parts [THEN [2] rev_notE, elim!]\n\n\nlemma CM3_k_parts_knows_Spy:\n \"\\<lbrakk>evs \\<in> certified_mail;\n     Notes TTP \\<lbrace>Agent A, Agent TTP,\n                 Crypt (pubEK TTP) \\<lbrace>Agent S, Number AO, Key K, \n                 Agent R, hs\\<rbrace>, Key (RPwd R), hs\\<rbrace> \\<in> set evs\\<rbrakk>\n  \\<Longrightarrow> Key K \\<in> parts(spies evs)\"\napply (rotate_tac 1)\napply (erule rev_mp)\napply (erule certified_mail.induct, simp_all)\n   apply (blast  intro:parts_insertI)\ntxt\\<open>Fake SSL\\<close>\napply (blast dest: parts.Body) \ntxt\\<open>Message 2\\<close>\napply (blast dest!: Gets_imp_Says elim!: knows_Spy_partsEs)\ntxt\\<open>Message 3\\<close>\napply (metis parts_insertI)\ndone\n\nlemma Spy_dont_know_RPwd [rule_format]:\n    \"evs \\<in> certified_mail \\<Longrightarrow> Key (RPwd A) \\<in> parts(spies evs) \\<longrightarrow> A \\<in> bad\"\napply (erule certified_mail.induct, simp_all) \ntxt\\<open>Fake\\<close>\napply (blast dest: Fake_parts_insert_in_Un) \ntxt\\<open>Message 1\\<close>\napply blast  \ntxt\\<open>Message 3\\<close>\napply (frule CM3_k_parts_knows_Spy, assumption)\napply (frule_tac hr_form, assumption)\napply (elim disjE exE) \napply (simp_all add: parts_insert2) \napply (force dest!: parts_insert_subset_Un [THEN [2] rev_subsetD]\n                    analz_subset_parts [THEN subsetD])\ndone\n\n\nlemma Spy_know_RPwd_iff [simp]:\n    \"evs \\<in> certified_mail \\<Longrightarrow> (Key (RPwd A) \\<in> parts(spies evs)) = (A\\<in>bad)\"\nby (auto simp add: Spy_dont_know_RPwd) \n\nlemma Spy_analz_RPwd_iff [simp]:\n    \"evs \\<in> certified_mail \\<Longrightarrow> (Key (RPwd A) \\<in> analz(spies evs)) = (A\\<in>bad)\"\nby (metis Spy_know_RPwd_iff Spy_spies_bad_shrK analz.Inj analz_into_parts)\n\ntext\\<open>Unused, but a guarantee of sorts\\<close>\ntheorem CertAutenticity:\n     \"\\<lbrakk>Crypt (priSK TTP) X \\<in> parts (spies evs); evs \\<in> certified_mail\\<rbrakk> \n      \\<Longrightarrow> \\<exists>A. Says TTP A (Crypt (priSK TTP) X) \\<in> set evs\"\napply (erule rev_mp)\napply (erule certified_mail.induct, simp_all) \ntxt\\<open>Fake\\<close>\napply (blast dest: Spy_dont_know_private_keys Fake_parts_insert_in_Un)\ntxt\\<open>Message 1\\<close>\napply blast \ntxt\\<open>Message 3\\<close>\napply (frule_tac hr_form, assumption)\napply (elim disjE exE) \napply (simp_all add: parts_insert2 parts_insert_knows_A) \n apply (blast dest!: Fake_parts_sing_imp_Un, blast)\ndone\n\n\nsubsection\\<open>Proving Confidentiality Results\\<close>\n\nlemma analz_image_freshK [rule_format]:\n \"evs \\<in> certified_mail \\<Longrightarrow>\n   \\<forall>K KK. invKey (pubEK TTP) \\<notin> KK \\<longrightarrow>\n          (Key K \\<in> analz (Key`KK \\<union> (spies evs))) =\n          (K \\<in> KK | Key K \\<in> analz (spies evs))\"\napply (erule certified_mail.induct)\napply (drule_tac [6] A=TTP in symKey_neq_priEK) \napply (erule_tac [6] disjE [OF hr_form]) \napply (drule_tac [5] CM2_S2TTP_analz_knows_Spy) \nprefer 9\napply (elim exE)\napply (simp_all add: synth_analz_insert_eq\n                     subset_trans [OF _ subset_insertI]\n                     subset_trans [OF _ Un_upper2] \n                del: image_insert image_Un add: analz_image_freshK_simps)\ndone\n\n\nlemma analz_insert_freshK:\n  \"\\<lbrakk>evs \\<in> certified_mail;  KAB \\<noteq> invKey (pubEK TTP)\\<rbrakk> \\<Longrightarrow>\n      (Key K \\<in> analz (insert (Key KAB) (spies evs))) =\n      (K = KAB | Key K \\<in> analz (spies evs))\"\nby (simp only: analz_image_freshK analz_image_freshK_simps)\n\ntext\\<open>\\<^term>\\<open>S2TTP\\<close> must have originated from a valid sender\n    provided \\<^term>\\<open>K\\<close> is secure.  Proof is surprisingly hard.\\<close>\n\nlemma Notes_SSL_imp_used:\n     \"\\<lbrakk>Notes B \\<lbrace>Agent A, Agent B, X\\<rbrace> \\<in> set evs\\<rbrakk> \\<Longrightarrow> X \\<in> used evs\"\nby (blast dest!: Notes_imp_used)\n\n\n(*The weaker version, replacing \"used evs\" by \"parts (spies evs)\", \n   isn't inductive: message 3 case can't be proved *)\nlemma S2TTP_sender_lemma [rule_format]:\n \"evs \\<in> certified_mail \\<Longrightarrow>\n    Key K \\<notin> analz (spies evs) \\<longrightarrow>\n    (\\<forall>AO. Crypt (pubEK TTP)\n           \\<lbrace>Agent S, Number AO, Key K, Agent R, hs\\<rbrace> \\<in> used evs \\<longrightarrow>\n    (\\<exists>m ctxt q. \n        hs = Hash\\<lbrace>Number ctxt, Nonce q, response S R q, Crypt K (Number m)\\<rbrace> \\<and>\n        Says S R\n           \\<lbrace>Agent S, Agent TTP, Crypt K (Number m), Number AO,\n             Number ctxt, Nonce q,\n             Crypt (pubEK TTP)\n              \\<lbrace>Agent S, Number AO, Key K, Agent R, hs \\<rbrace>\\<rbrace> \\<in> set evs))\" \napply (erule certified_mail.induct, analz_mono_contra)\napply (drule_tac [5] CM2_S2TTP_parts_knows_Spy, simp)\napply (simp add: used_Nil Crypt_notin_initState, simp_all)\ntxt\\<open>Fake\\<close>\napply (blast dest: Fake_parts_sing [THEN subsetD]\n             dest!: analz_subset_parts [THEN subsetD])  \ntxt\\<open>Fake SSL\\<close>\napply (blast dest: Fake_parts_sing [THEN subsetD]\n             dest: analz_subset_parts [THEN subsetD])  \ntxt\\<open>Message 1\\<close>\napply (clarsimp, blast)\ntxt\\<open>Message 2\\<close>\napply (simp add: parts_insert2, clarify) \napply (metis parts_cut Un_empty_left usedI)\ntxt\\<open>Message 3\\<close> \napply (blast dest: Notes_SSL_imp_used used_parts_subset_parts) \ndone \n\nlemma S2TTP_sender:\n \"\\<lbrakk>Crypt (pubEK TTP) \\<lbrace>Agent S, Number AO, Key K, Agent R, hs\\<rbrace> \\<in> used evs;\n    Key K \\<notin> analz (spies evs);\n    evs \\<in> certified_mail\\<rbrakk>\n  \\<Longrightarrow> \\<exists>m ctxt q. \n        hs = Hash\\<lbrace>Number ctxt, Nonce q, response S R q, Crypt K (Number m)\\<rbrace> \\<and>\n        Says S R\n           \\<lbrace>Agent S, Agent TTP, Crypt K (Number m), Number AO,\n             Number ctxt, Nonce q,\n             Crypt (pubEK TTP)\n              \\<lbrace>Agent S, Number AO, Key K, Agent R, hs\\<rbrace>\\<rbrace> \\<in> set evs\" \nby (blast intro: S2TTP_sender_lemma) \n\n\ntext\\<open>Nobody can have used non-existent keys!\\<close>\nlemma new_keys_not_used [simp]:\n    \"\\<lbrakk>Key K \\<notin> used evs; K \\<in> symKeys; evs \\<in> certified_mail\\<rbrakk>\n     \\<Longrightarrow> K \\<notin> keysFor (parts (spies evs))\"\napply (erule rev_mp) \napply (erule certified_mail.induct, simp_all) \ntxt\\<open>Fake\\<close>\napply (force dest!: keysFor_parts_insert) \ntxt\\<open>Message 1\\<close>\napply blast \ntxt\\<open>Message 3\\<close>\napply (frule CM3_k_parts_knows_Spy, assumption)\napply (frule_tac hr_form, assumption) \napply (force dest!: keysFor_parts_insert)\ndone\n\n\ntext\\<open>Less easy to prove \\<^term>\\<open>m'=m\\<close>.  Maybe needs a separate unicity\ntheorem for ciphertexts of the form \\<^term>\\<open>Crypt K (Number m)\\<close>, \nwhere \\<^term>\\<open>K\\<close> is secure.\\<close>\nlemma Key_unique_lemma [rule_format]:\n     \"evs \\<in> certified_mail \\<Longrightarrow>\n       Key K \\<notin> analz (spies evs) \\<longrightarrow>\n       (\\<forall>m cleartext q hs.\n        Says S R\n           \\<lbrace>Agent S, Agent TTP, Crypt K (Number m), Number AO,\n             Number cleartext, Nonce q,\n             Crypt (pubEK TTP) \\<lbrace>Agent S, Number AO, Key K, Agent R, hs\\<rbrace>\\<rbrace>\n          \\<in> set evs \\<longrightarrow>\n       (\\<forall>m' cleartext' q' hs'.\n       Says S' R'\n           \\<lbrace>Agent S', Agent TTP, Crypt K (Number m'), Number AO',\n             Number cleartext', Nonce q',\n             Crypt (pubEK TTP) \\<lbrace>Agent S', Number AO', Key K, Agent R', hs'\\<rbrace>\\<rbrace>\n          \\<in> set evs \\<longrightarrow> R' = R \\<and> S' = S \\<and> AO' = AO \\<and> hs' = hs))\" \napply (erule certified_mail.induct, analz_mono_contra, simp_all)\n prefer 2\n txt\\<open>Message 1\\<close>\n apply (blast dest!: Says_imp_knows_Spy [THEN parts.Inj] new_keys_not_used Crypt_imp_keysFor)\ntxt\\<open>Fake\\<close>\napply (auto dest!: usedI S2TTP_sender analz_subset_parts [THEN subsetD]) \ndone\n\ntext\\<open>The key determines the sender, recipient and protocol options.\\<close>\nlemma Key_unique:\n      \"\\<lbrakk>Says S R\n           \\<lbrace>Agent S, Agent TTP, Crypt K (Number m), Number AO,\n             Number cleartext, Nonce q,\n             Crypt (pubEK TTP) \\<lbrace>Agent S, Number AO, Key K, Agent R, hs\\<rbrace>\\<rbrace>\n          \\<in> set evs;\n         Says S' R'\n           \\<lbrace>Agent S', Agent TTP, Crypt K (Number m'), Number AO',\n             Number cleartext', Nonce q',\n             Crypt (pubEK TTP) \\<lbrace>Agent S', Number AO', Key K, Agent R', hs'\\<rbrace>\\<rbrace>\n          \\<in> set evs;\n         Key K \\<notin> analz (spies evs);\n         evs \\<in> certified_mail\\<rbrakk>\n       \\<Longrightarrow> R' = R \\<and> S' = S \\<and> AO' = AO \\<and> hs' = hs\"\nby (rule Key_unique_lemma, assumption+)\n\n\nsubsection\\<open>The Guarantees for Sender and Recipient\\<close>\n\ntext\\<open>A Sender's guarantee:\n      If Spy gets the key then \\<^term>\\<open>R\\<close> is bad and \\<^term>\\<open>S\\<close> moreover\n      gets his return receipt (and therefore has no grounds for complaint).\\<close>\ntheorem S_fairness_bad_R:\n      \"\\<lbrakk>Says S R \\<lbrace>Agent S, Agent TTP, Crypt K (Number m), Number AO, \n                     Number cleartext, Nonce q, S2TTP\\<rbrace> \\<in> set evs;\n         S2TTP = Crypt (pubEK TTP) \\<lbrace>Agent S, Number AO, Key K, Agent R, hs\\<rbrace>;\n         Key K \\<in> analz (spies evs);\n         evs \\<in> certified_mail;\n         S\\<noteq>Spy\\<rbrakk>\n      \\<Longrightarrow> R \\<in> bad \\<and> Gets S (Crypt (priSK TTP) S2TTP) \\<in> set evs\"\napply (erule rev_mp)\napply (erule ssubst)\napply (erule rev_mp)\napply (erule certified_mail.induct, simp_all)\ntxt\\<open>Fake\\<close>\napply spy_analz\ntxt\\<open>Fake SSL\\<close>\napply spy_analz\ntxt\\<open>Message 3\\<close>\napply (frule_tac hr_form, assumption)\napply (elim disjE exE) \napply (simp_all add: synth_analz_insert_eq  \n                     subset_trans [OF _ subset_insertI]\n                     subset_trans [OF _ Un_upper2] \n                del: image_insert image_Un add: analz_image_freshK_simps) \napply (simp_all add: symKey_neq_priEK analz_insert_freshK)\napply (blast dest: Notes_SSL_imp_used S2TTP_sender Key_unique)+\ndone\n\ntext\\<open>Confidentially for the symmetric key\\<close>\ntheorem Spy_not_see_encrypted_key:\n      \"\\<lbrakk>Says S R \\<lbrace>Agent S, Agent TTP, Crypt K (Number m), Number AO, \n                     Number cleartext, Nonce q, S2TTP\\<rbrace> \\<in> set evs;\n         S2TTP = Crypt (pubEK TTP) \\<lbrace>Agent S, Number AO, Key K, Agent R, hs\\<rbrace>;\n         evs \\<in> certified_mail;\n         S\\<noteq>Spy; R \\<notin> bad\\<rbrakk>\n      \\<Longrightarrow> Key K \\<notin> analz(spies evs)\"\nby (blast dest: S_fairness_bad_R) \n\n\ntext\\<open>Agent \\<^term>\\<open>R\\<close>, who may be the Spy, doesn't receive the key\n until \\<^term>\\<open>S\\<close> has access to the return receipt.\\<close> \ntheorem S_guarantee:\n     \"\\<lbrakk>Says S R \\<lbrace>Agent S, Agent TTP, Crypt K (Number m), Number AO, \n                    Number cleartext, Nonce q, S2TTP\\<rbrace> \\<in> set evs;\n        S2TTP = Crypt (pubEK TTP) \\<lbrace>Agent S, Number AO, Key K, Agent R, hs\\<rbrace>;\n        Notes R \\<lbrace>Agent TTP, Agent R, Key K, hs\\<rbrace> \\<in> set evs;\n        S\\<noteq>Spy;  evs \\<in> certified_mail\\<rbrakk>\n     \\<Longrightarrow> Gets S (Crypt (priSK TTP) S2TTP) \\<in> set evs\"\napply (erule rev_mp)\napply (erule ssubst)\napply (erule rev_mp)\napply (erule certified_mail.induct, simp_all)\ntxt\\<open>Message 1\\<close>\napply (blast dest: Notes_imp_used) \ntxt\\<open>Message 3\\<close>\napply (blast dest: Notes_SSL_imp_used S2TTP_sender Key_unique S_fairness_bad_R) \ndone\n\n\ntext\\<open>If \\<^term>\\<open>R\\<close> sends message 2, and a delivery certificate exists, \n then \\<^term>\\<open>R\\<close> receives the necessary key.  This result is also important\n to \\<^term>\\<open>S\\<close>, as it confirms the validity of the return receipt.\\<close>\ntheorem RR_validity:\n  \"\\<lbrakk>Crypt (priSK TTP) S2TTP \\<in> used evs;\n     S2TTP = Crypt (pubEK TTP)\n               \\<lbrace>Agent S, Number AO, Key K, Agent R, \n                 Hash \\<lbrace>Number cleartext, Nonce q, r, em\\<rbrace>\\<rbrace>;\n     hr = Hash \\<lbrace>Number cleartext, Nonce q, r, em\\<rbrace>;\n     R\\<noteq>Spy;  evs \\<in> certified_mail\\<rbrakk>\n  \\<Longrightarrow> Notes R \\<lbrace>Agent TTP, Agent R, Key K, hr\\<rbrace> \\<in> set evs\"\napply (erule rev_mp)\napply (erule ssubst)\napply (erule ssubst)\napply (erule certified_mail.induct, simp_all)\ntxt\\<open>Fake\\<close> \napply (blast dest: Fake_parts_sing [THEN subsetD]\n             dest!: analz_subset_parts [THEN subsetD])  \ntxt\\<open>Fake SSL\\<close>\napply (blast dest: Fake_parts_sing [THEN subsetD]\n            dest!: analz_subset_parts [THEN subsetD])  \ntxt\\<open>Message 2\\<close>\napply (drule CM2_S2TTP_parts_knows_Spy, assumption)\napply (force dest: parts_cut)\ntxt\\<open>Message 3\\<close>\napply (frule_tac hr_form, assumption)\napply (elim disjE exE, simp_all) \napply (blast dest: Fake_parts_sing [THEN subsetD]\n             dest!: analz_subset_parts [THEN subsetD]) \ndone\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/Auth/CertifiedEmail.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.626124191181315, "lm_q2_score": 0.4263215925474903, "lm_q1q2_score": 0.2669302623169275}}
{"text": "(*  Title:      HOL/HOLCF/IOA/Storage/Impl.thy\n    Author:     Olaf Müller\n*)\n\nsection \\<open>The implementation of a memory\\<close>\n\ntheory Impl\nimports \"../IOA\" Action\nbegin\n\ndefinition\n  impl_sig :: \"action signature\" where\n  \"impl_sig = (UN l.{Free l} Un {New},\n               UN l.{Loc l},\n               {})\"\n\ndefinition\n  impl_trans :: \"(action, nat  * bool)transition set\" where\n  \"impl_trans =\n    {tr. let s = fst(tr); k = fst s; b = snd s;\n             t = snd(snd(tr)); k' = fst t; b' = snd t\n         in\n         case fst(snd(tr))\n         of\n         New       => k' = k & b'  |\n         Loc l     => b & l= k & k'= (Suc k) & ~b' |\n         Free l    => k'=k & b'=b}\"\n\ndefinition\n  impl_ioa :: \"(action, nat * bool)ioa\" where\n  \"impl_ioa = (impl_sig, {(0,False)}, impl_trans,{},{})\"\n\nlemma in_impl_asig:\n  \"New : actions(impl_sig) &\n    Loc l : actions(impl_sig) &\n    Free l : actions(impl_sig) \"\n  by (simp add: impl_sig_def actions_def asig_projections)\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/HOL/HOLCF/IOA/Storage/Impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5888891451980403, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.2669209822286648}}
{"text": "theory flash34Rev imports flashPub\nbegin\nsection{*Main defintions*}\nlemma NI_FAckVsInv34:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_InvVsInv34:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_InvAck_1VsInv34:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by(cut_tac a1 a2 a3 a4, auto) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto \n qed\n  lemma NI_InvAck_1_HomeVsInv34:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_InvAck_2VsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                     have allCases:\"formEval   (neg ( andForm ( eqn ( IVar ( Global ''Dir_local'') )  ( Const true ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  ) )  s  \\<or>formEval  ( andForm ( eqn ( IVar ( Global ''Dir_local'') )  ( Const true ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  )  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume c1:\"formEval  (neg ( andForm ( eqn ( IVar ( Global ''Dir_local'') )  ( Const true ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  ) )  s\"\nhave \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1  c1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n    }\n\n    moreover\n                       {assume c1:\"formEval ( andForm ( eqn ( IVar ( Global ''Dir_local'') )  ( Const true ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  )  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1  c1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n   ultimately have \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                     have allCases:\"formEval   (neg ( andForm ( eqn ( IVar ( Global ''Dir_local'') )  ( Const true ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  ) )  s  \\<or>formEval  ( andForm ( eqn ( IVar ( Global ''Dir_local'') )  ( Const true ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  )  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume c1:\"formEval  (neg ( andForm ( eqn ( IVar ( Global ''Dir_local'') )  ( Const true ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  ) )  s\"\nhave \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1  c1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n    }\n\n    moreover\n                       {assume c1:\"formEval ( andForm ( eqn ( IVar ( Global ''Dir_local'') )  ( Const true ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  )  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1  c1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n   ultimately have \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_GetXVsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak1VsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak2VsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak3VsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX1VsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv34:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10VsInv34:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10_homeVsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX11VsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_GetVsInv34:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Local_Get_Nak1VsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak2VsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak3VsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put1VsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put2VsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put3VsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_PutVsInv34:  \n  (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n\n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Put ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma NI_Local_PutXAcksDoneVsInv34:  \n  (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n\n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_PutX ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma NI_NakVsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Nak_ClearVsInv34:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_Nak_HomeVsInv34:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_Remote_GetX_NakVsInv34:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_Nak_HomeVsInv34:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Remote_GetX_PutXVsInv34:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iRule2) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''Dir_local'') )  ( Const true ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_PutX_HomeVsInv34:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Remote_Get_Nak1VsInv34:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Remote_Get_Nak2VsInv34:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Put1VsInv34:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Remote_Get_Put2VsInv34:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutVsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutXVsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_ReplaceVsInv34:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_ReplaceHomeVsInv34:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_ReplaceHomeShrVldVsInv34:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_ReplaceShrVldVsInv34:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_ShWbVsInv34:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_WbVsInv34:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_GetX_GetX1VsInv34:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_GetX_GetX2VsInv34:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_GetX_PutX1VsInv34:  \n  (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n\n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX2VsInv34:  \n  (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n\n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))    ( eqn ( IVar ( Para ''CacheState'' Home) )  ( Const CACHE_S ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX3VsInv34:  \n  (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n\n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX4VsInv34:  \n  (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n\n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))    ( eqn ( IVar ( Para ''CacheState'' Home) )  ( Const CACHE_S ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma PI_Local_Get_GetVsInv34:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_Get_PutVsInv34:  \n  (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n\n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma PI_Local_PutXVsInv34:  \n  (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n\n     have allCases:\"formEval  ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const true ))  s  \\<or>formEval   (neg ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const true )) )  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume b1:\"formEval ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const true ))  s\"\nhave \"?P2 s\"\n\n   \n  apply(cut_tac  a1  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n    }\n\n    moreover\n                       {assume b1:\"formEval  (neg ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const true )) )  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Local_ReplaceVsInv34:  \n  (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Remote_GetVsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_GetXVsInv34:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_PutXVsInv34:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma PI_Remote_ReplaceVsInv34:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma StoreVsInv34:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma StoreHomeVsInv34:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv34  iInv1 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash34Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.26692097568800194}}
{"text": "theory RG_Tran\nimports RG_Com\nbegin\n\nsubsection \\<open>Semantics of Component Programs\\<close>\n\nsubsubsection \\<open>Environment transitions\\<close>\n\ntype_synonym 'a conf = \"(('a com) option) \\<times> 'a\"\n\ninductive_set\n  etran :: \"('a conf \\<times> 'a conf) set\" \n  and etran' :: \"'a conf \\<Rightarrow> 'a conf \\<Rightarrow> bool\"  (\"_ -e\\<rightarrow> _\" [81,81] 80)\nwhere\n  \"P -e\\<rightarrow> Q \\<equiv> (P,Q) \\<in> etran\"\n| Env: \"(P, s) -e\\<rightarrow> (P, t)\"\n\nlemma etranE: \"c -e\\<rightarrow> c' \\<Longrightarrow> (\\<And>P s t. c = (P, s) \\<Longrightarrow> c' = (P, t) \\<Longrightarrow> Q) \\<Longrightarrow> Q\"\n  by (induct c, induct c', erule etran.cases, blast)\n\nsubsubsection \\<open>Component transitions\\<close>\n\ninductive_set\n  ctran :: \"('a conf \\<times> 'a conf) set\"\n  and ctran' :: \"'a conf \\<Rightarrow> 'a conf \\<Rightarrow> bool\"   (\"_ -c\\<rightarrow> _\" [81,81] 80)\n  and ctrans :: \"'a conf \\<Rightarrow> 'a conf \\<Rightarrow> bool\"   (\"_ -c*\\<rightarrow> _\" [81,81] 80)\nwhere\n  \"P -c\\<rightarrow> Q \\<equiv> (P,Q) \\<in> ctran\"\n| \"P -c*\\<rightarrow> Q \\<equiv> (P,Q) \\<in> ctran\\<^sup>*\"\n\n| Basic:  \"(Some(Basic f), s) -c\\<rightarrow> (None, f s)\"\n\n| Seq1:   \"(Some P0, s) -c\\<rightarrow> (None, t) \\<Longrightarrow> (Some(Seq P0 P1), s) -c\\<rightarrow> (Some P1, t)\"\n\n| Seq2:   \"(Some P0, s) -c\\<rightarrow> (Some P2, t) \\<Longrightarrow> (Some(Seq P0 P1), s) -c\\<rightarrow> (Some(Seq P2 P1), t)\"\n\n| CondT: \"s\\<in>b  \\<Longrightarrow> (Some(Cond b P1 P2), s) -c\\<rightarrow> (Some P1, s)\"\n| CondF: \"s\\<notin>b \\<Longrightarrow> (Some(Cond b P1 P2), s) -c\\<rightarrow> (Some P2, s)\"\n\n| WhileF: \"s\\<notin>b \\<Longrightarrow> (Some(While b P), s) -c\\<rightarrow> (None, s)\"\n| WhileT: \"s\\<in>b  \\<Longrightarrow> (Some(While b P), s) -c\\<rightarrow> (Some(Seq P (While b P)), s)\"\n\n| Await:  \"\\<lbrakk>s\\<in>b; (Some P, s) -c*\\<rightarrow> (None, t)\\<rbrakk> \\<Longrightarrow> (Some(Await b P), s) -c\\<rightarrow> (None, t)\" \n\nmonos \"rtrancl_mono\"\n\nsubsection \\<open>Semantics of Parallel Programs\\<close>\n\ntype_synonym 'a par_conf = \"('a par_com) \\<times> 'a\"\n\ninductive_set\n  par_etran :: \"('a par_conf \\<times> 'a par_conf) set\"\n  and par_etran' :: \"['a par_conf,'a par_conf] \\<Rightarrow> bool\" (\"_ -pe\\<rightarrow> _\" [81,81] 80)\nwhere\n  \"P -pe\\<rightarrow> Q \\<equiv> (P,Q) \\<in> par_etran\"\n| ParEnv:  \"(Ps, s) -pe\\<rightarrow> (Ps, t)\"\n\ninductive_set\n  par_ctran :: \"('a par_conf \\<times> 'a par_conf) set\"\n  and par_ctran' :: \"['a par_conf,'a par_conf] \\<Rightarrow> bool\" (\"_ -pc\\<rightarrow> _\" [81,81] 80)\nwhere\n  \"P -pc\\<rightarrow> Q \\<equiv> (P,Q) \\<in> par_ctran\"\n| ParComp: \"\\<lbrakk>i<length Ps; (Ps!i, s) -c\\<rightarrow> (r, t)\\<rbrakk> \\<Longrightarrow> (Ps, s) -pc\\<rightarrow> (Ps[i:=r], t)\"\n\nlemma par_ctranE: \"c -pc\\<rightarrow> c' \\<Longrightarrow>\n  (\\<And>i Ps s r t. c = (Ps, s) \\<Longrightarrow> c' = (Ps[i := r], t) \\<Longrightarrow> i < length Ps \\<Longrightarrow>\n     (Ps ! i, s) -c\\<rightarrow> (r, t) \\<Longrightarrow> P) \\<Longrightarrow> P\"\n  by (induct c, induct c', erule par_ctran.cases, blast)\n\nsubsection \\<open>Computations\\<close>\n\nsubsubsection \\<open>Sequential computations\\<close>\n\ntype_synonym 'a confs = \"'a conf list\"\n\ninductive_set cptn :: \"'a confs set\"\nwhere\n  CptnOne: \"[(P,s)] \\<in> cptn\"\n| CptnEnv: \"(P, t)#xs \\<in> cptn \\<Longrightarrow> (P,s)#(P,t)#xs \\<in> cptn\"\n| CptnComp: \"\\<lbrakk>(P,s) -c\\<rightarrow> (Q,t); (Q, t)#xs \\<in> cptn \\<rbrakk> \\<Longrightarrow> (P,s)#(Q,t)#xs \\<in> cptn\"\n\ndefinition cp :: \"('a com) option \\<Rightarrow> 'a \\<Rightarrow> ('a confs) set\" where\n  \"cp P s \\<equiv> {l. l!0=(P,s) \\<and> l \\<in> cptn}\"  \n\nsubsubsection \\<open>Parallel computations\\<close>\n\ntype_synonym 'a par_confs = \"'a par_conf list\"\n\ninductive_set par_cptn :: \"'a par_confs set\"\nwhere\n  ParCptnOne: \"[(P,s)] \\<in> par_cptn\"\n| ParCptnEnv: \"(P,t)#xs \\<in> par_cptn \\<Longrightarrow> (P,s)#(P,t)#xs \\<in> par_cptn\"\n| ParCptnComp: \"\\<lbrakk> (P,s) -pc\\<rightarrow> (Q,t); (Q,t)#xs \\<in> par_cptn \\<rbrakk> \\<Longrightarrow> (P,s)#(Q,t)#xs \\<in> par_cptn\"\n\ndefinition par_cp :: \"'a par_com \\<Rightarrow> 'a \\<Rightarrow> ('a par_confs) set\" where\n  \"par_cp P s \\<equiv> {l. l!0=(P,s) \\<and> l \\<in> par_cptn}\"  \n\nsubsection\\<open>Modular Definition of Computation\\<close>\n\ndefinition lift :: \"'a com \\<Rightarrow> 'a conf \\<Rightarrow> 'a conf\" where\n  \"lift Q \\<equiv> \\<lambda>(P, s). (if P=None then (Some Q,s) else (Some(Seq (the P) Q), s))\"\n\ninductive_set cptn_mod :: \"('a confs) set\"\nwhere\n  CptnModOne: \"[(P, s)] \\<in> cptn_mod\"\n| CptnModEnv: \"(P, t)#xs \\<in> cptn_mod \\<Longrightarrow> (P, s)#(P, t)#xs \\<in> cptn_mod\"\n| CptnModNone: \"\\<lbrakk>(Some P, s) -c\\<rightarrow> (None, t); (None, t)#xs \\<in> cptn_mod \\<rbrakk> \\<Longrightarrow> (Some P,s)#(None, t)#xs \\<in>cptn_mod\"\n| CptnModCondT: \"\\<lbrakk>(Some P0, s)#ys \\<in> cptn_mod; s \\<in> b \\<rbrakk> \\<Longrightarrow> (Some(Cond b P0 P1), s)#(Some P0, s)#ys \\<in> cptn_mod\"\n| CptnModCondF: \"\\<lbrakk>(Some P1, s)#ys \\<in> cptn_mod; s \\<notin> b \\<rbrakk> \\<Longrightarrow> (Some(Cond b P0 P1), s)#(Some P1, s)#ys \\<in> cptn_mod\"\n| CptnModSeq1: \"\\<lbrakk>(Some P0, s)#xs \\<in> cptn_mod; zs=map (lift P1) xs \\<rbrakk>\n                 \\<Longrightarrow> (Some(Seq P0 P1), s)#zs \\<in> cptn_mod\"\n| CptnModSeq2: \n  \"\\<lbrakk>(Some P0, s)#xs \\<in> cptn_mod; fst(last ((Some P0, s)#xs)) = None; \n  (Some P1, snd(last ((Some P0, s)#xs)))#ys \\<in> cptn_mod; \n  zs=(map (lift P1) xs)@ys \\<rbrakk> \\<Longrightarrow> (Some(Seq P0 P1), s)#zs \\<in> cptn_mod\"\n\n| CptnModWhile1: \n  \"\\<lbrakk> (Some P, s)#xs \\<in> cptn_mod; s \\<in> b; zs=map (lift (While b P)) xs \\<rbrakk> \n  \\<Longrightarrow> (Some(While b P), s)#(Some(Seq P (While b P)), s)#zs \\<in> cptn_mod\"\n| CptnModWhile2: \n  \"\\<lbrakk> (Some P, s)#xs \\<in> cptn_mod; fst(last ((Some P, s)#xs))=None; s \\<in> b; \n  zs=(map (lift (While b P)) xs)@ys; \n  (Some(While b P), snd(last ((Some P, s)#xs)))#ys \\<in> cptn_mod\\<rbrakk> \n  \\<Longrightarrow> (Some(While b P), s)#(Some(Seq P (While b P)), s)#zs \\<in> cptn_mod\"\n\nsubsection \\<open>Equivalence of Both Definitions.\\<close>\n\nlemma last_length: \"((a#xs)!(length xs))=last (a#xs)\"\n  by (induct xs) auto\n\nlemma div_seq [rule_format]: \"list \\<in> cptn_mod \\<Longrightarrow>\n (\\<forall>s P Q zs. list=(Some (Seq P Q), s)#zs \\<longrightarrow>\n  (\\<exists>xs. (Some P, s)#xs \\<in> cptn_mod  \\<and> (zs=(map (lift Q) xs) \\<or>\n  ( fst(((Some P, s)#xs)!length xs)=None \\<and> \n  (\\<exists>ys. (Some Q, snd(((Some P, s)#xs)!length xs))#ys \\<in> cptn_mod  \n  \\<and> zs=(map (lift (Q)) xs)@ys)))))\"\napply(erule cptn_mod.induct)\napply simp_all\n    apply clarify\n    apply(force intro:CptnModOne)\n   apply clarify\n   apply(erule_tac x=Pa in allE)\n   apply(erule_tac x=Q in allE)\n   apply simp\n   apply clarify\n   apply(erule disjE)\n    apply(rule_tac x=\"(Some Pa,t)#xsa\" in exI)\n    apply(rule conjI)\n     apply clarify\n     apply(erule CptnModEnv)\n    apply(rule disjI1)\n    apply(simp add:lift_def)\n   apply clarify\n   apply(rule_tac x=\"(Some Pa,t)#xsa\" in exI)\n   apply(rule conjI)\n    apply(erule CptnModEnv)\n   apply(rule disjI2)\n   apply(rule conjI)\n    apply(case_tac xsa,simp,simp)\n   apply(rule_tac x=\"ys\" in exI)\n   apply(rule conjI)\n    apply simp\n   apply(simp add:lift_def)\n  apply clarify\n  apply(erule ctran.cases,simp_all)\n apply clarify\n apply(rule_tac x=\"xs\" in exI)\n apply simp\n apply clarify\napply(rule_tac x=\"xs\" in exI)\napply(simp add: last_length)\ndone\n\nlemma cptn_onlyif_cptn_mod_aux [rule_format]:\n  \"\\<forall>s Q t xs.((Some a, s), Q, t) \\<in> ctran \\<longrightarrow> (Q, t) # xs \\<in> cptn_mod \n  \\<longrightarrow> (Some a, s) # (Q, t) # xs \\<in> cptn_mod\"\napply(induct a)\napply simp_all\n\\<comment> \\<open>basic\\<close>\napply clarify\napply(erule ctran.cases,simp_all)\napply(rule CptnModNone,rule Basic,simp)\napply clarify\napply(erule ctran.cases,simp_all)\n\\<comment> \\<open>Seq1\\<close>\napply(rule_tac xs=\"[(None,ta)]\" in CptnModSeq2)\n  apply(erule CptnModNone)\n  apply(rule CptnModOne)\n apply simp\napply simp\napply(simp add:lift_def)\n\\<comment> \\<open>Seq2\\<close>\napply(erule_tac x=sa in allE)\napply(erule_tac x=\"Some P2\" in allE)\napply(erule allE,erule impE, assumption)\napply(drule div_seq,simp)\napply clarify\napply(erule disjE)\n apply clarify\n apply(erule allE,erule impE, assumption)\n apply(erule_tac CptnModSeq1)\n apply(simp add:lift_def)\napply clarify \napply(erule allE,erule impE, assumption)\napply(erule_tac CptnModSeq2)\n  apply (simp add:last_length)\n apply (simp add:last_length)\napply(simp add:lift_def)\n\\<comment> \\<open>Cond\\<close>\napply clarify\napply(erule ctran.cases,simp_all)\napply(force elim: CptnModCondT)\napply(force elim: CptnModCondF)\n\\<comment> \\<open>While\\<close>\napply  clarify\napply(erule ctran.cases,simp_all)\napply(rule CptnModNone,erule WhileF,simp)\napply(drule div_seq,force)\napply clarify\napply (erule disjE)\n apply(force elim:CptnModWhile1)\napply clarify\napply(force simp add:last_length elim:CptnModWhile2)\n\\<comment> \\<open>await\\<close>\napply clarify\napply(erule ctran.cases,simp_all)\napply(rule CptnModNone,erule Await,simp+)\ndone\n\nlemma cptn_onlyif_cptn_mod [rule_format]: \"c \\<in> cptn \\<Longrightarrow> c \\<in> cptn_mod\"\napply(erule cptn.induct)\n  apply(rule CptnModOne)\n apply(erule CptnModEnv)\napply(case_tac P)\n apply simp\n apply(erule ctran.cases,simp_all)\napply(force elim:cptn_onlyif_cptn_mod_aux)\ndone\n\nlemma lift_is_cptn: \"c\\<in>cptn \\<Longrightarrow> map (lift P) c \\<in> cptn\"\napply(erule cptn.induct)\n  apply(force simp add:lift_def CptnOne)\n apply(force intro:CptnEnv simp add:lift_def)\napply(force simp add:lift_def intro:CptnComp Seq2 Seq1 elim:ctran.cases)\ndone\n\nlemma cptn_append_is_cptn [rule_format]: \n \"\\<forall>b a. b#c1\\<in>cptn \\<longrightarrow>  a#c2\\<in>cptn \\<longrightarrow> (b#c1)!length c1=a \\<longrightarrow> b#c1@c2\\<in>cptn\"\napply(induct c1)\n apply simp\napply clarify\napply(erule cptn.cases,simp_all)\n apply(force intro:CptnEnv)\napply(force elim:CptnComp)\ndone\n\nlemma last_lift: \"\\<lbrakk>xs\\<noteq>[]; fst(xs!(length xs - (Suc 0)))=None\\<rbrakk> \n \\<Longrightarrow> fst((map (lift P) xs)!(length (map (lift P) xs)- (Suc 0)))=(Some P)\"\n  by (cases \"(xs ! (length xs - (Suc 0)))\") (simp add:lift_def)\n\nlemma last_fst [rule_format]: \"P((a#x)!length x) \\<longrightarrow> \\<not>P a \\<longrightarrow> P (x!(length x - (Suc 0)))\" \n  by (induct x) simp_all\n\nlemma last_fst_esp: \n \"fst(((Some a,s)#xs)!(length xs))=None \\<Longrightarrow> fst(xs!(length xs - (Suc 0)))=None\" \napply(erule last_fst)\napply simp\ndone\n\nlemma last_snd: \"xs\\<noteq>[] \\<Longrightarrow> \n  snd(((map (lift P) xs))!(length (map (lift P) xs) - (Suc 0)))=snd(xs!(length xs - (Suc 0)))\"\n  by (cases \"(xs ! (length xs - (Suc 0)))\") (simp_all add:lift_def)\n\nlemma Cons_lift: \"(Some (Seq P Q), s) # (map (lift Q) xs) = map (lift Q) ((Some P, s) # xs)\"\n  by (simp add:lift_def)\n\nlemma Cons_lift_append: \n  \"(Some (Seq P Q), s) # (map (lift Q) xs) @ ys = map (lift Q) ((Some P, s) # xs)@ ys \"\n  by (simp add:lift_def)\n\nlemma lift_nth: \"i<length xs \\<Longrightarrow> map (lift Q) xs ! i = lift Q  (xs! i)\"\n  by (simp add:lift_def)\n\nlemma snd_lift: \"i< length xs \\<Longrightarrow> snd(lift Q (xs ! i))= snd (xs ! i)\"\n  by (cases \"xs!i\") (simp add:lift_def)\n\nlemma cptn_if_cptn_mod: \"c \\<in> cptn_mod \\<Longrightarrow> c \\<in> cptn\"\napply(erule cptn_mod.induct)\n        apply(rule CptnOne)\n       apply(erule CptnEnv)\n      apply(erule CptnComp,simp)\n     apply(rule CptnComp)\n      apply(erule CondT,simp)\n    apply(rule CptnComp)\n     apply(erule CondF,simp)\n\\<comment> \\<open>Seq1\\<close>\napply(erule cptn.cases,simp_all)\n  apply(rule CptnOne)\n apply clarify\n apply(drule_tac P=P1 in lift_is_cptn)\n apply(simp add:lift_def)\n apply(rule CptnEnv,simp)\napply clarify\napply(simp add:lift_def)\napply(rule conjI)\n apply clarify\n apply(rule CptnComp)\n  apply(rule Seq1,simp)\n apply(drule_tac P=P1 in lift_is_cptn)\n apply(simp add:lift_def)\napply clarify\napply(rule CptnComp)\n apply(rule Seq2,simp)\napply(drule_tac P=P1 in lift_is_cptn)\napply(simp add:lift_def)\n\\<comment> \\<open>Seq2\\<close>\napply(rule cptn_append_is_cptn)\n  apply(drule_tac P=P1 in lift_is_cptn)\n  apply(simp add:lift_def)\n apply simp\napply(simp split: if_split_asm)\napply(frule_tac P=P1 in last_lift)\n apply(rule last_fst_esp)\n apply (simp add:last_length)\napply(simp add:Cons_lift lift_def split_def last_conv_nth)\n\\<comment> \\<open>While1\\<close>\napply(rule CptnComp)\n apply(rule WhileT,simp)\napply(drule_tac P=\"While b P\" in lift_is_cptn)\napply(simp add:lift_def)\n\\<comment> \\<open>While2\\<close>\napply(rule CptnComp)\n apply(rule WhileT,simp)\napply(rule cptn_append_is_cptn)\n  apply(drule_tac P=\"While b P\" in lift_is_cptn)\n  apply(simp add:lift_def)\n apply simp\napply(simp split: if_split_asm)\napply(frule_tac P=\"While b P\" in last_lift)\n apply(rule last_fst_esp,simp add:last_length)\napply(simp add:Cons_lift lift_def split_def last_conv_nth)\ndone\n\ntheorem cptn_iff_cptn_mod: \"(c \\<in> cptn) = (c \\<in> cptn_mod)\"\napply(rule iffI)\n apply(erule cptn_onlyif_cptn_mod)\napply(erule cptn_if_cptn_mod)\ndone\n\nsection \\<open>Validity  of Correctness Formulas\\<close>\n\nsubsection \\<open>Validity for Component Programs.\\<close>\n\ntype_synonym 'a rgformula =\n  \"'a com \\<times> 'a set \\<times> ('a \\<times> 'a) set \\<times> ('a \\<times> 'a) set \\<times> 'a set\"\n\ndefinition assum :: \"('a set \\<times> ('a \\<times> 'a) set) \\<Rightarrow> ('a confs) set\" where\n  \"assum \\<equiv> \\<lambda>(pre, rely). {c. snd(c!0) \\<in> pre \\<and> (\\<forall>i. Suc i<length c \\<longrightarrow> \n               c!i -e\\<rightarrow> c!(Suc i) \\<longrightarrow> (snd(c!i), snd(c!Suc i)) \\<in> rely)}\"\n\ndefinition comm :: \"(('a \\<times> 'a) set \\<times> 'a set) \\<Rightarrow> ('a confs) set\" where\n  \"comm \\<equiv> \\<lambda>(guar, post). {c. (\\<forall>i. Suc i<length c \\<longrightarrow> \n               c!i -c\\<rightarrow> c!(Suc i) \\<longrightarrow> (snd(c!i), snd(c!Suc i)) \\<in> guar) \\<and> \n               (fst (last c) = None \\<longrightarrow> snd (last c) \\<in> post)}\"\n\ndefinition com_validity :: \"'a com \\<Rightarrow> 'a set \\<Rightarrow> ('a \\<times> 'a) set \\<Rightarrow> ('a \\<times> 'a) set \\<Rightarrow> 'a set \\<Rightarrow> bool\" \n                 (\"\\<Turnstile> _ sat [_, _, _, _]\" [60,0,0,0,0] 45) where\n  \"\\<Turnstile> P sat [pre, rely, guar, post] \\<equiv> \n   \\<forall>s. cp (Some P) s \\<inter> assum(pre, rely) \\<subseteq> comm(guar, post)\"\n\nsubsection \\<open>Validity for Parallel Programs.\\<close>\n\ndefinition All_None :: \"(('a com) option) list \\<Rightarrow> bool\" where\n  \"All_None xs \\<equiv> \\<forall>c\\<in>set xs. c=None\"\n\ndefinition par_assum :: \"('a set \\<times> ('a \\<times> 'a) set) \\<Rightarrow> ('a par_confs) set\" where\n  \"par_assum \\<equiv> \\<lambda>(pre, rely). {c. snd(c!0) \\<in> pre \\<and> (\\<forall>i. Suc i<length c \\<longrightarrow> \n             c!i -pe\\<rightarrow> c!Suc i \\<longrightarrow> (snd(c!i), snd(c!Suc i)) \\<in> rely)}\"\n\ndefinition par_comm :: \"(('a \\<times> 'a) set \\<times> 'a set) \\<Rightarrow> ('a par_confs) set\" where\n  \"par_comm \\<equiv> \\<lambda>(guar, post). {c. (\\<forall>i. Suc i<length c \\<longrightarrow>   \n        c!i -pc\\<rightarrow> c!Suc i \\<longrightarrow> (snd(c!i), snd(c!Suc i)) \\<in> guar) \\<and> \n         (All_None (fst (last c)) \\<longrightarrow> snd( last c) \\<in> post)}\"\n\ndefinition par_com_validity :: \"'a  par_com \\<Rightarrow> 'a set \\<Rightarrow> ('a \\<times> 'a) set \\<Rightarrow> ('a \\<times> 'a) set \n\\<Rightarrow> 'a set \\<Rightarrow> bool\"  (\"\\<Turnstile> _ SAT [_, _, _, _]\" [60,0,0,0,0] 45) where\n  \"\\<Turnstile> Ps SAT [pre, rely, guar, post] \\<equiv> \n   \\<forall>s. par_cp Ps s \\<inter> par_assum(pre, rely) \\<subseteq> par_comm(guar, post)\"\n\nsubsection \\<open>Compositionality of the Semantics\\<close>\n\nsubsubsection \\<open>Definition of the conjoin operator\\<close>\n\ndefinition same_length :: \"'a par_confs \\<Rightarrow> ('a confs) list \\<Rightarrow> bool\" where\n  \"same_length c clist \\<equiv> (\\<forall>i<length clist. length(clist!i)=length c)\"\n \ndefinition same_state :: \"'a par_confs \\<Rightarrow> ('a confs) list \\<Rightarrow> bool\" where\n  \"same_state c clist \\<equiv> (\\<forall>i <length clist. \\<forall>j<length c. snd(c!j) = snd((clist!i)!j))\"\n\ndefinition same_program :: \"'a par_confs \\<Rightarrow> ('a confs) list \\<Rightarrow> bool\" where\n  \"same_program c clist \\<equiv> (\\<forall>j<length c. fst(c!j) = map (\\<lambda>x. fst(nth x j)) clist)\"\n\ndefinition compat_label :: \"'a par_confs \\<Rightarrow> ('a confs) list \\<Rightarrow> bool\" where\n  \"compat_label c clist \\<equiv> (\\<forall>j. Suc j<length c \\<longrightarrow> \n         (c!j -pc\\<rightarrow> c!Suc j \\<and> (\\<exists>i<length clist. (clist!i)!j -c\\<rightarrow> (clist!i)! Suc j \\<and> \n                       (\\<forall>l<length clist. l\\<noteq>i \\<longrightarrow> (clist!l)!j -e\\<rightarrow> (clist!l)! Suc j))) \\<or> \n         (c!j -pe\\<rightarrow> c!Suc j \\<and> (\\<forall>i<length clist. (clist!i)!j -e\\<rightarrow> (clist!i)! Suc j)))\"\n\ndefinition conjoin :: \"'a par_confs \\<Rightarrow> ('a confs) list \\<Rightarrow> bool\"  (\"_ \\<propto> _\" [65,65] 64) where\n  \"c \\<propto> clist \\<equiv> (same_length c clist) \\<and> (same_state c clist) \\<and> (same_program c clist) \\<and> (compat_label c clist)\"\n\nsubsubsection \\<open>Some previous lemmas\\<close>\n\nlemma list_eq_if [rule_format]: \n  \"\\<forall>ys. xs=ys \\<longrightarrow> (length xs = length ys) \\<longrightarrow> (\\<forall>i<length xs. xs!i=ys!i)\"\n  by (induct xs) auto\n\nlemma list_eq: \"(length xs = length ys \\<and> (\\<forall>i<length xs. xs!i=ys!i)) = (xs=ys)\"\napply(rule iffI)\n apply clarify\n apply(erule nth_equalityI)\n apply simp+\ndone\n\nlemma nth_tl: \"\\<lbrakk> ys!0=a; ys\\<noteq>[] \\<rbrakk> \\<Longrightarrow> ys=(a#(tl ys))\"\n  by (cases ys) simp_all\n\nlemma nth_tl_if [rule_format]: \"ys\\<noteq>[] \\<longrightarrow> ys!0=a \\<longrightarrow> P ys \\<longrightarrow> P (a#(tl ys))\"\n  by (induct ys) simp_all\n\nlemma nth_tl_onlyif [rule_format]: \"ys\\<noteq>[] \\<longrightarrow> ys!0=a \\<longrightarrow> P (a#(tl ys)) \\<longrightarrow> P ys\"\n  by (induct ys) simp_all\n\nlemma seq_not_eq1: \"Seq c1 c2\\<noteq>c1\"\n  by (induct c1) auto\n\nlemma seq_not_eq2: \"Seq c1 c2\\<noteq>c2\"\n  by (induct c2) auto\n\nlemma if_not_eq1: \"Cond b c1 c2 \\<noteq>c1\"\n  by (induct c1) auto\n\nlemma if_not_eq2: \"Cond b c1 c2\\<noteq>c2\"\n  by (induct c2) auto\n\nlemmas seq_and_if_not_eq [simp] = seq_not_eq1 seq_not_eq2 \nseq_not_eq1 [THEN not_sym] seq_not_eq2 [THEN not_sym] \nif_not_eq1 if_not_eq2 if_not_eq1 [THEN not_sym] if_not_eq2 [THEN not_sym]\n\nlemma prog_not_eq_in_ctran_aux:\n  assumes c: \"(P,s) -c\\<rightarrow> (Q,t)\"\n  shows \"P\\<noteq>Q\" using c\n  by (induct x1 \\<equiv> \"(P,s)\" x2 \\<equiv> \"(Q,t)\" arbitrary: P s Q t) auto\n\nlemma prog_not_eq_in_ctran [simp]: \"\\<not> (P,s) -c\\<rightarrow> (P,t)\"\napply clarify\napply(drule prog_not_eq_in_ctran_aux)\napply simp\ndone\n\nlemma prog_not_eq_in_par_ctran_aux [rule_format]: \"(P,s) -pc\\<rightarrow> (Q,t) \\<Longrightarrow> (P\\<noteq>Q)\"\napply(erule par_ctran.induct)\napply(drule prog_not_eq_in_ctran_aux)\napply clarify\napply(drule list_eq_if)\n apply simp_all\napply force\ndone\n\nlemma prog_not_eq_in_par_ctran [simp]: \"\\<not> (P,s) -pc\\<rightarrow> (P,t)\"\napply clarify\napply(drule prog_not_eq_in_par_ctran_aux)\napply simp\ndone\n\nlemma tl_in_cptn: \"\\<lbrakk> a#xs \\<in>cptn; xs\\<noteq>[] \\<rbrakk> \\<Longrightarrow> xs\\<in>cptn\"\n  by (force elim: cptn.cases)\n\nlemma tl_zero[rule_format]: \n  \"P (ys!Suc j) \\<longrightarrow> Suc j<length ys \\<longrightarrow> ys\\<noteq>[] \\<longrightarrow> P (tl(ys)!j)\"\n  by (induct ys) simp_all\n\nsubsection \\<open>The Semantics is Compositional\\<close>\n\nlemma aux_if [rule_format]: \n  \"\\<forall>xs s clist. (length clist = length xs \\<and> (\\<forall>i<length xs. (xs!i,s)#clist!i \\<in> cptn) \n  \\<and> ((xs, s)#ys \\<propto> map (\\<lambda>i. (fst i,s)#snd i) (zip xs clist)) \n   \\<longrightarrow> (xs, s)#ys \\<in> par_cptn)\"\napply(induct ys)\n apply(clarify)\n apply(rule ParCptnOne)\napply(clarify)\napply(simp add:conjoin_def compat_label_def)\napply clarify\napply(erule_tac x=\"0\" and P=\"\\<lambda>j. H j \\<longrightarrow> (P j \\<or> Q j)\" for H P Q in all_dupE, simp)\napply(erule disjE)\n\\<comment> \\<open>first step is a Component step\\<close>\n apply clarify \n apply simp\n apply(subgoal_tac \"a=(xs[i:=(fst(clist!i!0))])\")\n  apply(subgoal_tac \"b=snd(clist!i!0)\",simp)\n   prefer 2\n   apply(simp add: same_state_def)\n   apply(erule_tac x=i in allE,erule impE,assumption, \n         erule_tac x=1 and P=\"\\<lambda>j. (H j) \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE, simp)\n  prefer 2\n  apply(simp add:same_program_def)\n  apply(erule_tac x=1 and P=\"\\<lambda>j. H j \\<longrightarrow> (fst (s j))=(t j)\" for H s t in allE,simp)\n  apply(rule nth_equalityI,simp)\n  apply clarify\n  apply(case_tac \"i=ia\",simp,simp)\n  apply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE)\n  apply(drule_tac t=i in not_sym,simp)\n  apply(erule etranE,simp)\n apply(rule ParCptnComp)\n  apply(erule ParComp,simp)\n\\<comment> \\<open>applying the induction hypothesis\\<close>\n apply(erule_tac x=\"xs[i := fst (clist ! i ! 0)]\" in allE)\n apply(erule_tac x=\"snd (clist ! i ! 0)\" in allE)\n apply(erule mp)\n apply(rule_tac x=\"map tl clist\" in exI,simp)\n apply(rule conjI,clarify)\n  apply(case_tac \"i=ia\",simp)\n   apply(rule nth_tl_if)\n     apply(force simp add:same_length_def length_Suc_conv)\n    apply simp\n   apply(erule allE,erule impE,assumption,erule tl_in_cptn)\n   apply(force simp add:same_length_def length_Suc_conv)\n  apply(rule nth_tl_if)\n    apply(force simp add:same_length_def length_Suc_conv)\n   apply(simp add:same_state_def)\n   apply(erule_tac x=ia in allE, erule impE, assumption, \n     erule_tac x=1 and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE)\n   apply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE)\n   apply(drule_tac t=i  in not_sym,simp)\n   apply(erule etranE,simp)\n  apply(erule allE,erule impE,assumption,erule tl_in_cptn)\n  apply(force simp add:same_length_def length_Suc_conv)\n apply(simp add:same_length_def same_state_def)\n apply(rule conjI)\n  apply clarify\n  apply(case_tac j,simp,simp)\n  apply(erule_tac x=ia in allE, erule impE, assumption,\n        erule_tac x=\"Suc(Suc nat)\" and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE,simp)\n  apply(force simp add:same_length_def length_Suc_conv)\n apply(rule conjI)\n  apply(simp add:same_program_def)\n  apply clarify\n  apply(case_tac j,simp)\n   apply(rule nth_equalityI,simp)\n   apply clarify\n   apply(case_tac \"i=ia\",simp,simp)\n  apply(erule_tac x=\"Suc(Suc nat)\" and P=\"\\<lambda>j. H j \\<longrightarrow> (fst (s j))=(t j)\" for H s t in allE,simp)\n  apply(rule nth_equalityI,simp,simp)\n  apply(force simp add:length_Suc_conv)\n apply(rule allI,rule impI)\n apply(erule_tac x=\"Suc j\" and P=\"\\<lambda>j. H j \\<longrightarrow> (I j \\<or> J j)\" for H I J in allE,simp)\n apply(erule disjE) \n  apply clarify\n  apply(rule_tac x=ia in exI,simp)\n  apply(case_tac \"i=ia\",simp)\n   apply(rule conjI)\n    apply(force simp add: length_Suc_conv)\n   apply clarify\n   apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE,erule impE,assumption)\n   apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE,erule impE,assumption)\n   apply simp\n   apply(case_tac j,simp)\n    apply(rule tl_zero)\n      apply(erule_tac x=l in allE, erule impE, assumption, \n            erule_tac x=1 and P=\"\\<lambda>j.  (H j) \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE,simp)\n      apply(force elim:etranE intro:Env)\n     apply force\n    apply force\n   apply simp\n   apply(rule tl_zero)\n     apply(erule tl_zero)\n      apply force\n     apply force\n    apply force\n   apply force\n  apply(rule conjI,simp)\n   apply(rule nth_tl_if)\n     apply force\n    apply(erule_tac x=ia  in allE, erule impE, assumption,\n          erule_tac x=1 and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE)\n    apply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE)\n    apply(drule_tac t=i  in not_sym,simp)\n    apply(erule etranE,simp)\n   apply(erule tl_zero)\n    apply force\n   apply force\n  apply clarify\n  apply(case_tac \"i=l\",simp)\n   apply(rule nth_tl_if)\n     apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n    apply simp\n   apply(erule_tac P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE,erule impE,assumption,erule impE,assumption)\n   apply(erule tl_zero,force)\n   apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n   apply(rule nth_tl_if)\n     apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n    apply(erule_tac x=l  in allE, erule impE, assumption,\n          erule_tac x=1 and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE)\n    apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE,erule impE, assumption,simp)\n    apply(erule etranE,simp)\n   apply(rule tl_zero)\n    apply force\n   apply force\n  apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n apply(rule disjI2)\n apply(case_tac j,simp)\n  apply clarify\n  apply(rule tl_zero)\n    apply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> I j\\<in>etran\" for H I in allE,erule impE, assumption)\n    apply(case_tac \"i=ia\",simp,simp)\n    apply(erule_tac x=ia  in allE, erule impE, assumption,\n    erule_tac x=1 and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE)\n    apply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE,erule impE, assumption,simp)\n    apply(force elim:etranE intro:Env)\n   apply force\n  apply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n apply simp\n apply clarify\n apply(rule tl_zero)\n   apply(rule tl_zero,force)\n    apply force\n   apply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n  apply force\n apply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n\\<comment> \\<open>first step is an environmental step\\<close>\napply clarify\napply(erule par_etran.cases)\napply simp\napply(rule ParCptnEnv)\napply(erule_tac x=\"Ps\" in allE)\napply(erule_tac x=\"t\" in allE)\napply(erule mp)\napply(rule_tac x=\"map tl clist\" in exI,simp)\napply(rule conjI)\n apply clarify\n apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<in> cptn\" for H I in allE,simp)\n apply(erule cptn.cases)\n   apply(simp add:same_length_def)\n   apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n  apply(simp add:same_state_def)\n  apply(erule_tac x=i  in allE, erule impE, assumption,\n   erule_tac x=1 and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE,simp)\n apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> J j \\<in>etran\" for H J in allE,simp)\n apply(erule etranE,simp)\napply(simp add:same_state_def same_length_def)\napply(rule conjI,clarify)\n apply(case_tac j,simp,simp)\n apply(erule_tac x=i  in allE, erule impE, assumption,\n       erule_tac x=\"Suc(Suc nat)\" and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE,simp)\n apply(rule tl_zero)\n   apply(simp)\n  apply force\n apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\napply(rule conjI)\n apply(simp add:same_program_def)\n apply clarify\n apply(case_tac j,simp)\n  apply(rule nth_equalityI,simp)\n  apply clarify\n  apply simp\n apply(erule_tac x=\"Suc(Suc nat)\" and P=\"\\<lambda>j. H j \\<longrightarrow> (fst (s j))=(t j)\" for H s t in allE,simp)\n apply(rule nth_equalityI,simp,simp)\n apply(force simp add:length_Suc_conv)\napply(rule allI,rule impI)\napply(erule_tac x=\"Suc j\" and P=\"\\<lambda>j. H j \\<longrightarrow> (I j \\<or> J j)\" for H I J in allE,simp)\napply(erule disjE) \n apply clarify\n apply(rule_tac x=i in exI,simp)\n apply(rule conjI)\n  apply(erule_tac x=i and P=\"\\<lambda>i. H i \\<longrightarrow> J i \\<in>etran\" for H J in allE, erule impE, assumption)\n  apply(erule etranE,simp)\n  apply(erule_tac x=i  in allE, erule impE, assumption,\n        erule_tac x=1 and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE,simp)\n  apply(rule nth_tl_if)\n   apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n  apply simp\n apply(erule tl_zero,force) \n  apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n apply clarify\n apply(erule_tac x=l and P=\"\\<lambda>i. H i \\<longrightarrow> J i \\<in>etran\" for H J in allE, erule impE, assumption)\n apply(erule etranE,simp)\n apply(erule_tac x=l  in allE, erule impE, assumption,\n       erule_tac x=1 and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE,simp)\n apply(rule nth_tl_if)\n   apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n  apply simp\n  apply(rule tl_zero,force)\n  apply force\n apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\napply(rule disjI2)\napply simp\napply clarify\napply(case_tac j,simp)\n apply(rule tl_zero)\n   apply(erule_tac x=i and P=\"\\<lambda>i. H i \\<longrightarrow> J i \\<in>etran\" for H J in allE, erule impE, assumption)\n   apply(erule_tac x=i and P=\"\\<lambda>i. H i \\<longrightarrow> J i \\<in>etran\" for H J in allE, erule impE, assumption)\n   apply(force elim:etranE intro:Env)\n  apply force\n apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\napply simp\napply(rule tl_zero)\n  apply(rule tl_zero,force)\n   apply force\n  apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n apply force\napply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\ndone\n\nlemma aux_onlyif [rule_format]: \"\\<forall>xs s. (xs, s)#ys \\<in> par_cptn \\<longrightarrow> \n  (\\<exists>clist. (length clist = length xs) \\<and> \n  (xs, s)#ys \\<propto> map (\\<lambda>i. (fst i,s)#(snd i)) (zip xs clist) \\<and> \n  (\\<forall>i<length xs. (xs!i,s)#(clist!i) \\<in> cptn))\"\napply(induct ys)\n apply(clarify)\n apply(rule_tac x=\"map (\\<lambda>i. []) [0..<length xs]\" in exI)\n apply(simp add: conjoin_def same_length_def same_state_def same_program_def compat_label_def)\n apply(rule conjI)\n  apply(rule nth_equalityI,simp,simp)\n apply(force intro: cptn.intros)\napply(clarify)\napply(erule par_cptn.cases,simp)\n apply simp\n apply(erule_tac x=\"xs\" in allE)\n apply(erule_tac x=\"t\" in allE,simp)\n apply clarify\n apply(rule_tac x=\"(map (\\<lambda>j. (P!j, t)#(clist!j)) [0..<length P])\" in exI,simp)\n apply(rule conjI)\n  prefer 2\n  apply clarify\n  apply(rule CptnEnv,simp)\n apply(simp add:conjoin_def same_length_def same_state_def)\n apply (rule conjI)\n  apply clarify\n  apply(case_tac j,simp,simp)\n apply(rule conjI)\n  apply(simp add:same_program_def)\n  apply clarify\n  apply(case_tac j,simp)\n   apply(rule nth_equalityI,simp,simp)\n  apply simp\n  apply(rule nth_equalityI,simp,simp)\n apply(simp add:compat_label_def)\n apply clarify\n apply(case_tac j,simp)\n  apply(simp add:ParEnv)\n  apply clarify\n  apply(simp add:Env)\n apply simp\n apply(erule_tac x=nat in allE,erule impE, assumption)\n apply(erule disjE,simp)\n  apply clarify\n  apply(rule_tac x=i in exI,simp)\n apply force\napply(erule par_ctran.cases,simp)\napply(erule_tac x=\"Ps[i:=r]\" in allE)\napply(erule_tac x=\"ta\" in allE,simp)\napply clarify\napply(rule_tac x=\"(map (\\<lambda>j. (Ps!j, ta)#(clist!j)) [0..<length Ps]) [i:=((r, ta)#(clist!i))]\" in exI,simp)\napply(rule conjI)\n prefer 2\n apply clarify\n apply(case_tac \"i=ia\",simp)\n  apply(erule CptnComp)\n  apply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> (I j \\<in> cptn)\" for H I in allE,simp)\n apply simp\n apply(erule_tac x=ia in allE)\n apply(rule CptnEnv,simp)\napply(simp add:conjoin_def)\napply (rule conjI)\n apply(simp add:same_length_def)\n apply clarify\n apply(case_tac \"i=ia\",simp,simp)\napply(rule conjI)\n apply(simp add:same_state_def)\n apply clarify\n apply(case_tac j, simp, simp (no_asm_simp))\n apply(case_tac \"i=ia\",simp,simp)\napply(rule conjI)\n apply(simp add:same_program_def)\n apply clarify\n apply(case_tac j,simp)\n  apply(rule nth_equalityI,simp,simp)\n apply simp\n apply(rule nth_equalityI,simp,simp)\n apply(erule_tac x=nat and P=\"\\<lambda>j. H j \\<longrightarrow> (fst (a j))=((b j))\" for H a b in allE)\n apply(case_tac nat)\n  apply clarify\n  apply(case_tac \"i=ia\",simp,simp)\n apply clarify\n apply(case_tac \"i=ia\",simp,simp)\napply(simp add:compat_label_def)\napply clarify\napply(case_tac j)\n apply(rule conjI,simp)\n  apply(erule ParComp,assumption)\n  apply clarify\n  apply(rule_tac x=i in exI,simp)\n apply clarify\n apply(rule Env)\napply simp\napply(erule_tac x=nat and P=\"\\<lambda>j. H j \\<longrightarrow> (P j \\<or> Q j)\" for H P Q in allE,simp)\napply(erule disjE)\n apply clarify\n apply(rule_tac x=ia in exI,simp)\n apply(rule conjI)\n  apply(case_tac \"i=ia\",simp,simp)\n apply clarify\n apply(case_tac \"i=l\",simp)\n  apply(case_tac \"l=ia\",simp,simp)\n  apply(erule_tac x=l in allE,erule impE,assumption,erule impE, assumption,simp)\n apply simp\n apply(erule_tac x=l in allE,erule impE,assumption,erule impE, assumption,simp)\napply clarify\napply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> (P j)\\<in>etran\" for H P in allE, erule impE, assumption)\napply(case_tac \"i=ia\",simp,simp)\ndone\n\nlemma one_iff_aux: \"xs\\<noteq>[] \\<Longrightarrow> (\\<forall>ys. ((xs, s)#ys \\<in> par_cptn) = \n (\\<exists>clist. length clist= length xs \\<and> \n ((xs, s)#ys \\<propto> map (\\<lambda>i. (fst i,s)#(snd i)) (zip xs clist)) \\<and> \n (\\<forall>i<length xs. (xs!i,s)#(clist!i) \\<in> cptn))) = \n (par_cp (xs) s = {c. \\<exists>clist. (length clist)=(length xs) \\<and>\n (\\<forall>i<length clist. (clist!i) \\<in> cp(xs!i) s) \\<and> c \\<propto> clist})\" \napply (rule iffI)\n apply(rule subset_antisym)\n  apply(rule subsetI) \n  apply(clarify)\n  apply(simp add:par_cp_def cp_def)\n  apply(case_tac x)\n   apply(force elim:par_cptn.cases)\n  apply simp\n  apply(rename_tac a list)\n  apply(erule_tac x=\"list\" in allE)\n  apply clarify\n  apply simp\n  apply(rule_tac x=\"map (\\<lambda>i. (fst i, s) # snd i) (zip xs clist)\" in exI,simp)\n apply(rule subsetI) \n apply(clarify)\n apply(case_tac x)\n  apply(erule_tac x=0 in allE)\n  apply(simp add:cp_def conjoin_def same_length_def same_program_def same_state_def compat_label_def)\n  apply clarify\n  apply(erule cptn.cases,force,force,force)\n apply(simp add:par_cp_def conjoin_def  same_length_def same_program_def same_state_def compat_label_def)\n apply clarify\n apply(erule_tac x=0 and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in all_dupE)\n apply(subgoal_tac \"a = xs\")\n  apply(subgoal_tac \"b = s\",simp)\n   prefer 3\n   apply(erule_tac x=0 and P=\"\\<lambda>j. H j \\<longrightarrow> (fst (s j))=((t j))\" for H s t in allE)\n   apply (simp add:cp_def)\n   apply(rule nth_equalityI,simp,simp)\n  prefer 2\n  apply(erule_tac x=0 in allE)\n  apply (simp add:cp_def)\n  apply(erule_tac x=0 and P=\"\\<lambda>j. H j \\<longrightarrow> (\\<forall>i. T i \\<longrightarrow> (snd (d j i))=(snd (e j i)))\" for H T d e in allE,simp)\n  apply(erule_tac x=0 and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE,simp)\n apply(erule_tac x=list in allE)\n apply(rule_tac x=\"map tl clist\" in exI,simp) \n apply(rule conjI)\n  apply clarify\n  apply(case_tac j,simp)\n   apply(erule_tac x=i  in allE, erule impE, assumption,\n        erule_tac x=\"0\" and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE,simp)\n  apply(erule_tac x=i  in allE, erule impE, assumption,\n        erule_tac x=\"Suc nat\" and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE)\n  apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n  apply(case_tac \"clist!i\",simp,simp)\n apply(rule conjI)\n  apply clarify\n  apply(rule nth_equalityI,simp,simp)\n  apply(case_tac j)\n   apply clarify\n   apply(erule_tac x=i in allE)\n   apply(simp add:cp_def)\n  apply clarify\n  apply simp\n  apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n  apply(case_tac \"clist!i\",simp,simp)\n apply(thin_tac \"H = (\\<exists>i. J i)\" for H J)\n apply(rule conjI)\n  apply clarify\n  apply(erule_tac x=j in allE,erule impE, assumption,erule disjE)\n   apply clarify\n   apply(rule_tac x=i in exI,simp)\n   apply(case_tac j,simp)\n    apply(rule conjI)\n     apply(erule_tac x=i in allE)\n     apply(simp add:cp_def)\n     apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n     apply(case_tac \"clist!i\",simp,simp)\n    apply clarify\n    apply(erule_tac x=l in allE)\n    apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE)\n    apply clarify\n    apply(simp add:cp_def)\n    apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n    apply(case_tac \"clist!l\",simp,simp)\n   apply simp\n   apply(rule conjI)\n    apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n    apply(case_tac \"clist!i\",simp,simp)\n   apply clarify\n   apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE)\n   apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n   apply(case_tac \"clist!l\",simp,simp)\n  apply clarify\n  apply(erule_tac x=i in allE)\n  apply(simp add:cp_def)\n  apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n  apply(case_tac \"clist!i\",simp)\n  apply(rule nth_tl_if,simp,simp)\n  apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (P j)\\<in>etran\" for H P in allE, erule impE, assumption,simp)\n  apply(simp add:cp_def)\n  apply clarify\n  apply(rule nth_tl_if)\n   apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n   apply(case_tac \"clist!i\",simp,simp)\n  apply force\n apply force\napply clarify\napply(rule iffI)\n apply(simp add:par_cp_def)\n apply(erule_tac c=\"(xs, s) # ys\" in equalityCE)\n  apply simp\n  apply clarify\n  apply(rule_tac x=\"map tl clist\" in exI)\n  apply simp\n  apply (rule conjI)\n   apply(simp add:conjoin_def cp_def)\n   apply(rule conjI)\n    apply clarify\n    apply(unfold same_length_def)\n    apply clarify\n    apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,simp)\n   apply(rule conjI)\n    apply(simp add:same_state_def)\n    apply clarify\n    apply(erule_tac x=i in allE, erule impE, assumption,\n       erule_tac x=j and P=\"\\<lambda>j. H j \\<longrightarrow> (snd (d j))=(snd (e j))\" for H d e in allE)\n    apply(case_tac j,simp)\n    apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n    apply(case_tac \"clist!i\",simp,simp)\n   apply(rule conjI)\n    apply(simp add:same_program_def)\n    apply clarify\n    apply(rule nth_equalityI,simp,simp)\n    apply(case_tac j,simp)\n    apply clarify\n    apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n    apply(case_tac \"clist!i\",simp,simp)\n   apply clarify\n   apply(simp add:compat_label_def)\n   apply(rule allI,rule impI)\n   apply(erule_tac x=j in allE,erule impE, assumption)\n   apply(erule disjE)\n    apply clarify\n    apply(rule_tac x=i in exI,simp)\n    apply(rule conjI)\n     apply(erule_tac x=i in allE)\n     apply(case_tac j,simp)\n      apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n      apply(case_tac \"clist!i\",simp,simp)\n     apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n     apply(case_tac \"clist!i\",simp,simp)\n    apply clarify\n    apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> I j \\<longrightarrow> J j\" for H I J in allE)\n    apply(erule_tac x=l and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE)\n    apply(case_tac \"clist!l\",simp,simp)\n    apply(erule_tac x=l in allE,simp)\n   apply(rule disjI2)\n   apply clarify\n   apply(rule tl_zero)\n     apply(case_tac j,simp,simp)\n     apply(rule tl_zero,force)   \n      apply force\n     apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n    apply force\n   apply(erule_tac x=i and P=\"\\<lambda>j. H j \\<longrightarrow> (length (s j) = t)\" for H s t in allE,force)\n  apply clarify\n  apply(erule_tac x=i in allE)\n  apply(simp add:cp_def)\n  apply(rule nth_tl_if)\n    apply(simp add:conjoin_def)\n    apply clarify\n    apply(simp add:same_length_def)\n    apply(erule_tac x=i in allE,simp)\n   apply simp\n  apply simp\n apply simp\napply clarify\napply(erule_tac c=\"(xs, s) # ys\" in equalityCE)\n apply(simp add:par_cp_def)\napply simp\napply(erule_tac x=\"map (\\<lambda>i. (fst i, s) # snd i) (zip xs clist)\" in allE)\napply simp\napply clarify\napply(simp add:cp_def)\ndone\n\ntheorem one: \"xs\\<noteq>[] \\<Longrightarrow> \n par_cp xs s = {c. \\<exists>clist. (length clist)=(length xs) \\<and> \n               (\\<forall>i<length clist. (clist!i) \\<in> cp(xs!i) s) \\<and> c \\<propto> clist}\"\napply(frule one_iff_aux)\napply(drule sym)\napply(erule iffD2)\napply clarify\napply(rule iffI)\n apply(erule aux_onlyif)\napply clarify\napply(force intro:aux_if)\ndone\n\nend", "meta": {"author": "SunHuan321", "repo": "uc-OS-verification", "sha": "760e159857c4015d6a9e3ccbe9f8247e4518862a", "save_path": "github-repos/isabelle/SunHuan321-uc-OS-verification", "path": "github-repos/isabelle/SunHuan321-uc-OS-verification/uc-OS-verification-760e159857c4015d6a9e3ccbe9f8247e4518862a/SIMP/RG_Tran.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.4532618480153861, "lm_q1q2_score": 0.2669209756880019}}
{"text": "theory Analyze_SQRL_Shorewall\nimports \n  \"../../Primitive_Matchers/Parser\"\nbegin\n\n\nsection\\<open>Example: SQRL Shorewall\\<close>\n\n\nparse_iptables_save SQRL_fw=\"iptables-saveakachan\"\n\n\nthm SQRL_fw_def\nthm SQRL_fw_FORWARD_default_policy_def\n\nvalue[code] \"map (\\<lambda>(c,rs). (c, map (quote_rewrite \\<circ> common_primitive_rule_toString) rs)) SQRL_fw\"\n\nlemma \"Semantics_Goto.terminal_chain (the ((map_of_string_ipv4 SQRL_fw) ''smurflog''))\" by eval\nlemma \"Semantics_Goto.terminal_chain (the ((map_of_string_ipv4 SQRL_fw) ''logflags''))\" by eval\nlemma \"Semantics_Goto.terminal_chain (the ((map_of_string_ipv4 SQRL_fw) ''reject''))\" by eval\n\n(*12.942s*)\nvalue[code] \"Semantics_Goto.rewrite_Goto SQRL_fw\"\n\ndefinition \"unfolded = unfold_ruleset_FORWARD SQRL_fw_FORWARD_default_policy (map_of_string_ipv4 (Semantics_Goto.rewrite_Goto SQRL_fw))\"\n\n(*\n(*2174.839s elapsed time, 3308.410s cpu time, 161.539s GC time*)\nvalue[code] \"unfolded\"*)\n(*0.561s*)\nvalue[code] \"let x = unfolded in ()\" (*pretty printing is slow, not the unfolding! ML forces evaluation of unfolded!*)\n(*39.149s*)\nvalue[code] \"map (quote_rewrite \\<circ> common_primitive_rule_toString) (unfolded)\"\n(*2.871s*)\nlemma \"length unfolded = 2649\" by eval\n\n\n(*17.554s*)\nvalue[code] \"map (quote_rewrite \\<circ> common_primitive_rule_toString) (upper_closure unfolded)\"\nlemma \"length (upper_closure unfolded) = 1986\" by eval\n\n\nvalue[code] \"upper_closure (packet_assume_new unfolded)\"\n\n(*28.550s*)\nlemma \"length (lower_closure unfolded) = 5715\" by eval\n\nlemma \"check_simple_fw_preconditions (upper_closure unfolded) = False\" by eval\nlemma \"\\<forall>m \\<in> get_match`set (upper_closure (packet_assume_new unfolded)). normalized_nnf_match m\" by eval\n\nlemma \"\\<forall>m \\<in> get_match`set (optimize_matches abstract_for_simple_firewall (upper_closure (packet_assume_new unfolded))). normalized_nnf_match m\" by eval\n\nlemma \"check_simple_fw_preconditions (upper_closure (optimize_matches abstract_for_simple_firewall (upper_closure (packet_assume_new unfolded))))\" by eval\nlemma \"length (to_simple_firewall (upper_closure (optimize_matches abstract_for_simple_firewall (upper_closure (packet_assume_new unfolded))))) = 1389\" by eval\n(*22.240s*)\nvalue[code] \"map simple_rule_ipv4_toString (to_simple_firewall (upper_closure (optimize_matches abstract_for_simple_firewall (upper_closure (packet_assume_new unfolded)))))\"\n\n(*25.480s*)\nvalue[code] \"map ipv4addr_wordinterval_toString (getParts (to_simple_firewall (upper_closure (optimize_matches abstract_for_simple_firewall (upper_closure (packet_assume_new unfolded))))))\"\n\n(*43.702s*)\nlemma \"length (to_simple_firewall (lower_closure (optimize_matches abstract_for_simple_firewall (lower_closure (packet_assume_new unfolded))))) = 5120\" by eval\n\n(*71.518s*)\nvalue[code] \"length (remdups_rev (to_simple_firewall (lower_closure (optimize_matches abstract_for_simple_firewall (lower_closure (packet_assume_new unfolded))))))\" (*not smaller*)\n\nvalue[code] \"map ipv4addr_wordinterval_toString (getParts (to_simple_firewall (lower_closure (optimize_matches abstract_for_simple_firewall (lower_closure (packet_assume_new unfolded))))))\"\n\nlemma \"simple_fw_valid (to_simple_firewall (lower_closure (optimize_matches abstract_for_simple_firewall (lower_closure (packet_assume_new unfolded)))))\" by eval\nlemma \"simple_fw_valid (to_simple_firewall (upper_closure (optimize_matches abstract_for_simple_firewall (lower_closure (packet_assume_new unfolded)))))\" by eval\n\nend\n", "meta": {"author": "diekmann", "repo": "Iptables_Semantics", "sha": "e0a2516bd885708fce875023b474ae341cbdee29", "save_path": "github-repos/isabelle/diekmann-Iptables_Semantics", "path": "github-repos/isabelle/diekmann-Iptables_Semantics/Iptables_Semantics-e0a2516bd885708fce875023b474ae341cbdee29/thy/Iptables_Semantics/Examples/SQRL_Shorewall/Analyze_SQRL_Shorewall.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6548947290421275, "lm_q2_score": 0.40733340004593027, "lm_q1q2_score": 0.26676049665288804}}
{"text": "theory Proofs_4\n  imports Requirements ExtraInv VCTheoryLemmas\nbegin\n\nthm extraInv_def\n\nlemma suspended_not_rotation_and_pressure:\n\"toEnvP s1 \\<and> substate s1 s \\<and> getPstate s1 Controller = Controller'suspended \\<and>\n(\\<forall>s1 s2 s3.\n    toEnvP s1 \\<and>\n    toEnvP s2 \\<and>\n    toEnvP s3 \\<and>\n    substate s1 s2 \\<and>\n    substate s2 s3 \\<and>\n    substate s3 s \\<and>\n    toEnvNum s1 s2 = ERROR \\<and> toEnvNum s1 s3 < ltime s3 ERROR \\<and> getPstate s3 ERROR = Controller'suspended \\<longrightarrow>\n    getPstate s1 ERROR = Controller'suspended \\<and> \\<not> getVarBool s2 pressure) \\<and>\n(\\<forall>s1. toEnvP s1 \\<and> substate s1 s \\<and> getPstate s1 ERROR = Controller'suspended \\<longrightarrow>\n      getVarBool s1 rotation = False \\<and> getVarBool s1 brake = True) \\<Longrightarrow>\n(\\<forall> s2 s3. toEnvP s2 \\<and> toEnvP s3 \\<and> substate s2 s3 \\<and> substate s3 s1 \\<and> toEnvNum s2 s3 = 1 \\<and>\ntoEnvNum s2 s1 < ltime s1 Controller \\<longrightarrow> \\<not>(getVarBool s2 rotation = True \\<and> getVarBool s3 pressure))\"\n  by blast\n\ndefinition inv4 where \"inv4 s \\<equiv> R4 s \\<and> extraInv s\"\n\ntheorem proof_4_1: \"VC1 inv4 s0\"\n  apply(simp only: VC1_def inv4_def R4_def extraInv_def)\n  by auto\n\ntheorem proof_4_2: \"VC2 R4 env s0 user_value pressure_value\"\n  apply(simp only: VC2_def R4_def)\n  by auto\n\ntheorem proof_4_3: \"VC3 R4 env s0 user_value pressure_value\"\n  apply(simp only: VC3_def R4_def)\n  apply auto\n  subgoal for s1 s2\n    apply(rule cut_rl[of \"toEnvNum s2 s0 < DELAY'TIMEOUT\"])\n    using substate_refl apply fast\n    by simp\n  done\n\ntheorem proof_4_5: \"VC5 inv4 env  s0 user_value pressure_value\"\n  apply(simp only: VC5_def)\n  by auto\n\ntheorem proof_4_6: \"VC6 R4 env s0 user_value pressure_value\"\n  apply(simp only: VC6_def R4_def)\n  by auto\n\ntheorem proof_4_7: \"VC7 inv4 env  s0 user_value pressure_value\"\n  apply(simp only: VC7_def)\n  by auto\n\ntheorem proof_4_8: \"VC8 R4 env s0 user_value pressure_value\"\n  apply(simp only: VC8_def R4_def)\n  apply auto\n  subgoal for s1 s2\n    apply(rule cut_rl[of \"toEnvNum s2 s0 < DELAY'TIMEOUT\"])\n    using substate_refl apply fast\n    by simp\n  done\n\ntheorem proof_4_9: \"VC9 R4 env s0 user_value pressure_value\"\n  apply(simp only: VC9_def R4_def)\n  apply auto\n  subgoal for s1 s2\n    apply(rule cut_rl[of \"toEnvNum s2 s0 < DELAY'TIMEOUT\"])\n    using substate_refl apply fast\n    by simp\n  done\n\ntheorem proof_4_10: \"VC10 R4 env s0 user_value pressure_value\"\n  apply(simp only: VC10_def R4_def)\n  apply auto\n  subgoal for s1 s2\n    apply(rule cut_rl[of \"toEnvNum s2 s0 < DELAY'TIMEOUT\"])\n    using substate_refl apply fast\n    by simp\n  done\n\ntheorem proof_4_11: \"VC11 inv4 env  s0 user_value pressure_value\"\n  apply(simp only: VC11_def)\n  by auto\n\ntheorem proof_4_14: \"VC14 R4 env s0 user_value pressure_value\"\n  apply(simp only: VC14_def R4_def)\n  apply auto\n  subgoal for s1 s2\n    apply(rule cut_rl[of \"toEnvNum s2 s0 < DELAY'TIMEOUT\"])\n    using substate_refl apply fast\n    by simp\n  done\n\nend", "meta": {"author": "ivchernenko", "repo": "post_vcgenerator", "sha": "fadfff131086870a027d6bd1c78b8d5a3baf183b", "save_path": "github-repos/isabelle/ivchernenko-post_vcgenerator", "path": "github-repos/isabelle/ivchernenko-post_vcgenerator/post_vcgenerator-fadfff131086870a027d6bd1c78b8d5a3baf183b/case-studies/revolvingDoor/Proofs_4.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318337259584, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.26674038821829293}}
{"text": "(*\n * Copyright 2016, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the GNU General Public License version 2. Note that NO WARRANTY is provided.\n * See \"LICENSE_GPLv2.txt\" for details.\n *\n * @TAG(NICTA_GPL)\n *)\n\ntheory BufferT\nimports\n  \"../impl/BilbyFs_Shallow_Desugar_Tuples\"\n  \"../impl/BilbyFs_ShallowConsts_Desugar_Tuples\"\n  \"../adt/WordArrayT\"\nbegin\n\n\ndefinition\n  buf_slice :: \"Buffer\\<^sub>T \\<Rightarrow> U32 \\<Rightarrow> U32 \\<Rightarrow> U8 list\"\nwhere\n \"buf_slice buf frm to \\<equiv> slice (unat frm) (unat to) (\\<alpha>wa $ data\\<^sub>f buf)\"\n\ndefinition\n  buf_sub_slice :: \"Buffer\\<^sub>T \\<Rightarrow> U32 \\<Rightarrow> U32 \\<Rightarrow> U8 list \\<Rightarrow> U8 list\"\nwhere\n \"buf_sub_slice buf frm to xs \\<equiv>\n take (length (\\<alpha>wa $ data\\<^sub>f buf)) (take (unat frm) (\\<alpha>wa $ data\\<^sub>f buf) @ \n (take (unat to - unat frm) (xs@replicate (unat to - unat frm) 0)) @\n  drop (max (unat to) (unat frm)) (\\<alpha>wa $ data\\<^sub>f buf))\"\n  \n\nlemma buf_sub_slice_length:\n  \"length (buf_sub_slice buf frm to xs) = length (\\<alpha>wa (data\\<^sub>f buf))\"\n  apply (simp add: buf_sub_slice_def)\n  apply(subst min_def)+\nusing [[linarith_split_limit=20]]\napply clarsimp (* take a while *)\napply safe\napply unat_arith+\ndone\n\ndefinition\n  buf_drop :: \"Buffer\\<^sub>T \\<Rightarrow> U32 \\<Rightarrow> U8 list\"\nwhere\n \"buf_drop buf offs \\<equiv> drop (unat offs) (\\<alpha>wa $ data\\<^sub>f buf)\"\n\ndefinition\n  buf_take :: \"Buffer\\<^sub>T \\<Rightarrow> U32 \\<Rightarrow> U8 list\"\nwhere\n \"buf_take buf offs \\<equiv> take (unat offs) (\\<alpha>wa $ data\\<^sub>f buf)\"\n\ndefinition\n  buf_update_bounded :: \"Buffer\\<^sub>T \\<Rightarrow> U8 list \\<Rightarrow> U8 list\"\nwhere\n \"buf_update_bounded buf buf_updated \\<equiv>\n    take (min (unat $ bound\\<^sub>f buf) (length $ \\<alpha>wa $ data\\<^sub>f buf)) buf_updated @\n    drop (min (unat $ bound\\<^sub>f buf) (length buf_updated)) (\\<alpha>wa $ data\\<^sub>f buf) \"\n\ndefinition\n  buf_memset' :: \"Buffer\\<^sub>T \\<Rightarrow> U32 \\<Rightarrow> U32 \\<Rightarrow> U8 \\<Rightarrow> U8 list\"\nwhere\n \"buf_memset' buf offs len v \\<equiv>\n   buf_update_bounded buf $ buf_take buf offs @ replicate (min (unat len) (unat (bound\\<^sub>f buf) - unat offs)) v @ buf_drop buf (offs+len)\"\n\n\nlemma buf_update_bounded_length:\n \"length (buf_update_bounded buf upd) = length (\\<alpha>wa $ data\\<^sub>f buf)\"\n  by (simp add: buf_bound_def buf_update_bounded_def buf_length_def)\n\nlemmas buf_simps = buf_take_def buf_drop_def buf_slice_def \n    buf_bound_def buf_update_bounded_def buf_length_def\n    buf_memset'_def buf_update_bounded_length\n    slice_def\n\nlemma drop_take_drop:\n  \"n \\<le> m \\<Longrightarrow> drop n (take m xs) @ drop m xs = drop n xs\"\n by (metis Nat.le_iff_add add.commute take_drop take_drop_append)\n\nlemma buf_memset_bound_assm_eq:\n  \"unat (bound\\<^sub>f buf) \\<le>  length (\\<alpha>wa (data\\<^sub>f buf)) \\<Longrightarrow>\n  offs \\<le> offs + len \\<Longrightarrow>\n  unat offs \\<le> unat (bound\\<^sub>f buf) \\<Longrightarrow>\n  offs + len \\<le> bound\\<^sub>f buf \\<Longrightarrow>\n  wordarray_set (data\\<^sub>f buf, offs, len, v) = WordArrayT.make (buf_memset' buf offs len v)\"\n unfolding buf_memset_def[unfolded tuple_simps sanitizers]\n   apply (simp add: Let_def wordarray_set_ret buf_simps min_absorb1)\n   apply (rule arg_cong[where f=WordArrayT.make])\n   apply (subgoal_tac \"(unat (bound\\<^sub>f buf) - unat offs) \\<ge> (unat len)\")\n    prefer 2\n    apply unat_arith\n   apply (simp add: min_absorb1 )\n   apply (subgoal_tac \"(unat (bound\\<^sub>f buf)) \\<le>\n            (unat offs + (unat len + (length (\\<alpha>wa (data\\<^sub>f buf)) - unat (offs + len))))\")\n   prefer 2\n   apply (unat_arith)\n  apply (simp add: min_absorb1 take_drop)\n  apply (subgoal_tac \" (unat offs + unat len) =  unat (offs + len)\")\n   apply (simp add: drop_take_drop)\n  apply unat_arith\n done\n\nlemma take_prefix_length:\n \"take n xs = take n ys \\<Longrightarrow>\n   n \\<le> length xs \\<Longrightarrow> n \\<le> length ys\"\nby (metis length_take min.absorb_iff2)\n\nlemma buf_bounded_update_bounded_prefix:\n \"unat (bound\\<^sub>f buf) \\<le> length (\\<alpha>wa (data\\<^sub>f buf)) \\<Longrightarrow>\n take (unat (bound\\<^sub>f buf)) xs = take (unat (bound\\<^sub>f buf)) ys \\<Longrightarrow>\n  buf_update_bounded buf xs = buf_update_bounded buf ys\"\n apply (simp add: buf_simps)\n apply (case_tac \"(unat (bound\\<^sub>f buf)) \\<le> (length xs)\")\n  apply (frule (1) take_prefix_length)\n  apply (simp add: min_absorb1)\n apply simp\ndone\n\nlemma buf_memset_bound:\n \"unat (bound\\<^sub>f buf) \\<le> length (\\<alpha>wa (data\\<^sub>f buf)) \\<Longrightarrow>\n    offs \\<le> offs + len \\<Longrightarrow>\n    offs < bound\\<^sub>f buf \\<Longrightarrow>\n    \\<not> offs + len < bound\\<^sub>f buf \\<Longrightarrow>\n    buf_memset' buf offs (bound\\<^sub>f buf - offs) v = buf_memset' buf offs len v\"\n  apply (simp add: buf_memset'_def)\n  apply (subgoal_tac \"unat (bound\\<^sub>f buf - offs) = unat (bound\\<^sub>f buf) - unat offs\")\n   prefer 2\n   apply unat_arith\n  apply (simp add: min_absorb2)\n  apply (subgoal_tac \"(unat len) \\<ge> (unat (bound\\<^sub>f buf) - unat offs)\")\n   prefer 2\n   apply unat_arith\n  apply simp\n  apply (rule buf_bounded_update_bounded_prefix)\n   apply (simp add: buf_simps)+\n done\n\nlemma take_n_m_double_append:\n \"n \\<le> m \\<Longrightarrow> n \\<le> length xs \\<Longrightarrow>\n    take n (take m xs @ ys ) = take n xs\"\n by simp\n\nlemma buf_memset_offs_bound:\n \"unat (bound\\<^sub>f buf) \\<le> length (\\<alpha>wa (data\\<^sub>f buf)) \\<Longrightarrow>\n   offs \\<le> offs + len \\<Longrightarrow>\n   \\<not> offs < bound\\<^sub>f buf \\<Longrightarrow>\n   buf_memset' buf (bound\\<^sub>f buf) len' v =\n   buf_memset' buf offs len v\"\n  apply (simp add: buf_memset'_def)\n  apply (rule buf_bounded_update_bounded_prefix)\n   apply simp\n  apply (simp only: buf_take_def )\n  apply (subst take_n_m_double_append)\n     apply simp\n    apply unat_arith\n   apply unat_arith\n  apply simp\n done\n\n\nlemma buf_memset_eq:\n  \"unat (bound\\<^sub>f buf) \\<le>  length (\\<alpha>wa (data\\<^sub>f buf)) \\<Longrightarrow>\n  offs \\<le> offs + len \\<Longrightarrow>\n  buf_memset (buf, offs, len, v) = buf\\<lparr>data\\<^sub>f:=WordArrayT.make (buf_memset' buf offs len v)\\<rparr>\"\n unfolding buf_memset_def[unfolded tuple_simps sanitizers]\n  apply (simp only: Let_def prod.case_eq_if prod.sel take\\<^sub>c\\<^sub>o\\<^sub>g\\<^sub>e\\<^sub>n\\<^sub>t_def)\n  apply (subst buf_memset_bound_assm_eq)\n      apply simp\n     apply ((case_tac \" offs < bound\\<^sub>f buf\", ((simp, unat_arith)+)[2])+)[3]\n  apply (rule arg_cong[where f=\"\\<lambda>v. data\\<^sub>f_update v buf\"])\n  apply (rule ext)\n  apply (rule arg_cong[where f=WordArrayT.make])\n  apply (case_tac \"offs < bound\\<^sub>f buf\")\n   apply (simp add: buf_memset_bound)\n  apply (simp add: buf_memset_offs_bound)\n done\n\nlemma buf_memset_length_eq:\n  \"unat (bound\\<^sub>f buf) \\<le> length (\\<alpha>wa (data\\<^sub>f buf)) \\<Longrightarrow>\n offs \\<le> offs + len \\<Longrightarrow>\nbuf_length (buf_memset (buf, offs, len, v)) = buf_length buf\"\n by (simp add: buf_length_def wordarray_length_ofnat[OF wordarray_length_ret] \n      buf_memset_eq wordarray_make buf_update_bounded_length buf_memset'_def)\n\nlemma buf_take_buf_slice_adjacent:\n \"st \\<le>  end \\<Longrightarrow> buf_take b st @ buf_slice b st end = buf_take b end\"\nby (simp add: buf_simps word_le_nat_alt) \n  (metis (no_types, lifting) append_take_drop_id min_def take_take)\n\nlemma length_buf_memset:\n  \"unat (bound\\<^sub>f wbuf) \\<le>  length (\\<alpha>wa (data\\<^sub>f wbuf)) \\<Longrightarrow>\n n < n + m \\<Longrightarrow>\nlength (\\<alpha>wa (data\\<^sub>f (buf_memset (wbuf, n, m, v)))) = length (\\<alpha>wa (data\\<^sub>f wbuf))\"\n by (simp add: buf_memset_eq buf_memset'_def wordarray_make buf_update_bounded_length)\n\nlemma buf_slice_n_n:\n  \"buf_slice buf n n = []\"\n  by (simp add: buf_simps)\n\nlemma buf_slice_0_eq_buf_take:\n \"buf_slice buf 0 n = buf_take buf n\"\n by (simp add: buf_simps)\n\n\nlemma buf_slice_out_of_buf_memset:\n \"frm \\<le> to \\<Longrightarrow> to \\<le> st \\<Longrightarrow> st \\<le> st + len \\<Longrightarrow> st \\<le> bound\\<^sub>f b \\<Longrightarrow> unat (bound\\<^sub>f b) = length (\\<alpha>wa (data\\<^sub>f b)) \\<Longrightarrow>\n  buf_slice (buf_memset (b, st, len, v)) frm to = buf_slice b frm to\"\n  apply (subst buf_memset_eq)\n   apply simp+\n  apply (simp add:  buf_simps wordarray_make min_absorb1 min_absorb2)\n  apply (simp only: unat_arith_simps)\n  apply (simp add: min_absorb1 min_absorb2)\n done\n\nlemma buf_update_boundedI:\n \"unat (buf_bound wbuf) \\<le> length (\\<alpha>wa (data\\<^sub>f wbuf)) \\<Longrightarrow>\n  length xs = length (\\<alpha>wa (data\\<^sub>f wbuf)) \\<Longrightarrow>\n  drop (unat (bound\\<^sub>f wbuf)) (\\<alpha>wa (data\\<^sub>f wbuf)) = drop (unat (bound\\<^sub>f wbuf)) xs \\<Longrightarrow>\n  P xs \\<Longrightarrow>\n  P (buf_update_bounded wbuf xs)\"\nby (simp add: buf_bound_def buf_update_bounded_def min_absorb1)\n\nlemma take_n_buf_sub_slice_n:\n \"unat n \\<le> length (\\<alpha>wa (data\\<^sub>f b)) \\<Longrightarrow> take (unat n) (buf_sub_slice b n t xs) = take (unat n) (\\<alpha>wa (data\\<^sub>f b))\"\n by (simp add: buf_sub_slice_def min_absorb1)\n\n lemma take_n_buf_sub_slice_m:\n \"unat m \\<le> length (\\<alpha>wa (data\\<^sub>f b)) \\<Longrightarrow> n \\<le> m \\<Longrightarrow>  take (unat n) (buf_sub_slice b m t xs) = take (unat n) (\\<alpha>wa (data\\<^sub>f b))\"\n by (simp add: buf_sub_slice_def min_absorb1 word_le_nat_alt) \n \n\nlemma slice_buf_sub_slice:\n \"frm \\<le> mid \\<Longrightarrow> mid \\<le> to \\<Longrightarrow> unat to \\<le> length (\\<alpha>wa (data\\<^sub>f b)) \\<Longrightarrow>\n  unat (to - mid) = length xs \\<Longrightarrow>\n slice (unat frm) (unat to) (buf_sub_slice b mid to xs) = buf_slice b frm mid @ take (unat to - unat mid) xs\"\n  apply (simp add: buf_simps buf_sub_slice_def min_absorb1 min_absorb2)\n  apply (subgoal_tac \"unat mid \\<le> length (\\<alpha>wa (data\\<^sub>f b))\")\n   apply (subgoal_tac \"unat frm \\<le> length (\\<alpha>wa (data\\<^sub>f b))\")\n    apply (subgoal_tac \"unat frm \\<le> unat mid\")\n  apply (simp add: buf_simps buf_sub_slice_def min_absorb1 min_absorb2 word_le_nat_alt)\n  apply unat_arith+\n done\n\nend\n", "meta": {"author": "crizkallah", "repo": "cogent", "sha": "cb16e8169d4389e32dc4aecf4eb9f57173264006", "save_path": "github-repos/isabelle/crizkallah-cogent", "path": "github-repos/isabelle/crizkallah-cogent/cogent-cb16e8169d4389e32dc4aecf4eb9f57173264006/impl/fs/bilby/proof/adt/BufferT.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318337259584, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.26674038821829293}}
{"text": "theory Proof_3_4\n  imports Proofs_3\nbegin\n\nthm VC4_def\n\ncontext\n  fixes s2 s0:: state\nfixes user_value pressure_value:: bool\nassumes toEnvPs2:  \"toEnvP s2 \\<and> toEnvP s0\" and extraInvs0: \"extraInv s0\" \nand vc: \" env (setVarAny s0 user_value pressure_value) \\<and>\n         getPstate (setVarAny s0 user_value pressure_value) ERROR = Controller'motionless \\<and>\n        \\<not>getVarBool (setVarAny s0 user_value pressure_value) user\"\nbegin\n\nlemma VC4_R3_ind_step_aux1: \" toEnvP s2a \\<Longrightarrow>\n         substate s2 s2a \\<and>\n         substate s2a\n         (toEnv (setVarAny s0 user'value pressure'value)) \\<and>\n         s2 \\<noteq> s2a \\<Longrightarrow>\n         substate s1 s2 \\<and>\n         substate s2\n          (toEnv (setVarAny s0 user'value pressure'value)) \\<and>\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         toEnvNum s1 s2 = ERROR \\<and>\n         DELAY'TIMEOUT =\n         toEnvNum s2\n          (toEnv (setVarAny s0 user'value pressure'value)) \\<and>\n         getVarBool s1 rotation = True \\<and>\n         \\<not> getVarBool s2 user \\<and>\n         (\\<forall>s4. toEnvP s4 \\<and> substate s2 s4 \\<and> substate s4 s2a \\<and> s4 \\<noteq> s2a \\<longrightarrow>\n               getVarBool s4 rotation = True \\<and> \\<not> getVarBool s4 user) \\<longrightarrow>\n         (\\<exists>s4. toEnvP s4 \\<and>\n               substate s2a s4 \\<and>\n               substate s4\n                (toEnv (setVarAny s0 user'value pressure'value)) \\<and>\n               toEnvNum s2 s4 \\<le> DELAY'TIMEOUT \\<and>\n               (getVarBool s4 rotation = False \\<or> getVarBool s4 user) \\<and>\n               (\\<forall>s3. toEnvP s3 \\<and> substate s2a s3 \\<and> substate s3 s4 \\<and> s3 \\<noteq> s4 \\<longrightarrow>\n                     getVarBool s3 rotation = True \\<and> \\<not> getVarBool s3 user)) \\<Longrightarrow>\n         substate s1 s2 \\<and>\n         substate s2\n          (toEnv (setVarAny s0 user'value pressure'value)) \\<and>\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         toEnvNum s1 s2 = ERROR \\<and>\n         DELAY'TIMEOUT =\n         toEnvNum s2\n          (toEnv (setVarAny s0 user'value pressure'value)) \\<and>\n         getVarBool s1 rotation = True \\<and>\n         \\<not> getVarBool s2 user \\<and>\n         (\\<forall>s4. toEnvP s4 \\<and> substate s2 s4 \\<and> substate s4 (predEnv s2a) \\<and> s4 \\<noteq> predEnv s2a \\<longrightarrow>\n               getVarBool s4 rotation = True \\<and> \\<not> getVarBool s4 user) \\<Longrightarrow>\n         \\<not> (getVarBool (predEnv s2a) rotation = False \\<or> getVarBool (predEnv s2a) user) \\<Longrightarrow>\n         toEnvP x \\<and>\n         substate s2a x \\<and>\n         substate x\n          (toEnv (setVarAny s0 user'value pressure'value)) \\<and>\n         toEnvNum s2 x \\<le> DELAY'TIMEOUT \\<and>\n         (getVarBool x rotation = False \\<or> getVarBool x user) \\<and>\n         (\\<forall>s3. toEnvP s3 \\<and> substate s2a s3 \\<and> substate s3 x \\<and> s3 \\<noteq> x \\<longrightarrow>\n               getVarBool s3 rotation = True \\<and> \\<not> getVarBool s3 user) \\<Longrightarrow>\n         \\<exists>s4. toEnvP s4 \\<and>\n              substate (predEnv s2a) s4 \\<and>\n              substate s4\n               (toEnv (setVarAny s0 user'value pressure'value)) \\<and>\n              toEnvNum s2 s4 \\<le> DELAY'TIMEOUT \\<and>\n              (getVarBool s4 rotation = False \\<or> getVarBool s4 user) \\<and>\n              (\\<forall>s3. toEnvP s3 \\<and> substate (predEnv s2a) s3 \\<and> substate s3 s4 \\<and> s3 \\<noteq> s4 \\<longrightarrow>\n                    getVarBool s3 rotation = True \\<and> \\<not> getVarBool s3 user)\"\n  apply(rule exI[of _ x])\n  by (smt (z3) predEnv_substate predEnv_substate_imp_eq_or_substate substate_trans)\n  \nlemma VC4_R3_ind_step: \" toEnvP s2a \\<Longrightarrow>\n           substate s2 s2a \\<and>\n           substate s2a\n            (toEnv (setVarAny s0 user'value pressure'value)) \\<and>\n           s2 \\<noteq> s2a \\<Longrightarrow>\n           substate s1 s2 \\<and>\n           substate s2\n           (toEnv (setVarAny s0 user'value pressure'value)) \\<and>\n           toEnvP s1 \\<and>\n           toEnvP s2 \\<and>\n           toEnvNum s1 s2 = ERROR \\<and>\n           DELAY'TIMEOUT =\n           toEnvNum s2\n            (toEnv (setVarAny s0 user'value pressure'value)) \\<and>\n           getVarBool s1 rotation = True \\<and>\n           \\<not> getVarBool s2 user \\<and>\n           (\\<forall>s4. toEnvP s4 \\<and> substate s2 s4 \\<and> substate s4 s2a \\<and> s4 \\<noteq> s2a \\<longrightarrow>\n                 getVarBool s4 rotation = True \\<and> \\<not> getVarBool s4 user) \\<longrightarrow>\n           (\\<exists>s4. toEnvP s4 \\<and>\n                 substate s2a s4 \\<and>\n                 substate s4\n                 (toEnv (setVarAny s0 user'value pressure'value)) \\<and>\n                 toEnvNum s2 s4 \\<le> DELAY'TIMEOUT \\<and>\n                 (getVarBool s4 rotation = False \\<or> getVarBool s4 user) \\<and>\n                 (\\<forall>s3. toEnvP s3 \\<and> substate s2a s3 \\<and> substate s3 s4 \\<and> s3 \\<noteq> s4 \\<longrightarrow>\n                       getVarBool s3 rotation = True \\<and> \\<not> getVarBool s3 user)) \\<Longrightarrow>\n           substate s1 s2 \\<and>\n           substate s2\n            (toEnv (setVarAny s0 user'value pressure'value)) \\<and>\n           toEnvP s1 \\<and>\n           toEnvP s2 \\<and>\n           toEnvNum s1 s2 = ERROR \\<and>\n           DELAY'TIMEOUT =\n           toEnvNum s2\n            (toEnv (setVarAny s0 user'value pressure'value)) \\<and>\n           getVarBool s1 rotation = True \\<and>\n           \\<not> getVarBool s2 user \\<and>\n           (\\<forall>s4. toEnvP s4 \\<and> substate s2 s4 \\<and> substate s4 (predEnv s2a) \\<and> s4 \\<noteq> predEnv s2a \\<longrightarrow>\n                 getVarBool s4 rotation = True \\<and> \\<not> getVarBool s4 user) \\<longrightarrow>\n           (\\<exists>s4. toEnvP s4 \\<and>\n                 substate (predEnv s2a) s4 \\<and>\n                 substate s4\n                  (toEnv (setVarAny s0 user'value pressure'value)) \\<and>\n                 toEnvNum s2 s4 \\<le> DELAY'TIMEOUT \\<and>\n                 (getVarBool s4 rotation = False \\<or> getVarBool s4 user) \\<and>\n                 (\\<forall>s3. toEnvP s3 \\<and> substate (predEnv s2a) s3 \\<and> substate s3 s4 \\<and> s3 \\<noteq> s4 \\<longrightarrow>\n                       getVarBool s3 rotation = True \\<and> \\<not> getVarBool s3 user))\"\n  apply(rule impI)\n  apply(cases \"(getVarBool (predEnv s2a) rotation = False \\<or> getVarBool (predEnv s2a) user)\")\n   apply(rule exI[of _ \"predEnv s2a\"])\n   apply(rule conjI)\n    apply(rule toEnvP_substate_pred_imp_toEnvP_pred[of s2])\n  using toEnvPs2 substate_eq_or_predEnv apply fast\n   apply(rule conjI)\n  using substate_refl apply fast\n   apply(rule conjI)\n  using predEnv_substate substate_trans apply fast\n   apply(rule conjI)\n    apply(rule cut_rl[of \"substate s2 (predEnv s2a) \\<and>\n substate (predEnv s2a)\n (toEnv (setVarAny s0 user'value pressure'value))\"])\n  using toEnvNum3[of s2 \"predEnv s2a\" \n\"(toEnv (setVarAny s0 user'value pressure'value))\"]\n     apply arith\n  using substate_eq_or_predEnv predEnv_substate substate_trans apply fast\n   apply(rule conjI)\n    apply assumption\n  using substate_asym apply fast\n  apply(rule exE[of \"\\<lambda> s4. toEnvP s4 \\<and>\n          substate s2a s4 \\<and>\n          substate s4\n          (toEnv (setVarAny s0 user'value pressure'value)) \\<and>\n          toEnvNum s2 s4 \\<le> DELAY'TIMEOUT \\<and>\n          (getVarBool s4 rotation = False \\<or> getVarBool s4 user) \\<and>\n          (\\<forall>s3. toEnvP s3 \\<and> substate s2a s3 \\<and> substate s3 s4 \\<and> s3 \\<noteq> s4 \\<longrightarrow>\n                getVarBool s3 rotation = True \\<and> \\<not> getVarBool s3 user)\"])\n  using substate_eq_or_predEnv apply blast\n  by ((rule VC4_R3_ind_step_aux1);blast)\n \nlemma VC4_R3_ind_proof:   \"toEnvP s5 \\<and>  substate s2 s5 \\<and>\n substate s5 (toEnv (setVarAny s0 user'value pressure'value))\n \\<longrightarrow> pred3 s1 s2 (toEnv (setVarAny s0 user'value pressure'value))\n s5\"\n  apply(induction rule: state_down_ind)\n  using toEnvPs2 apply simp\n   apply(simp only: pred3_def)\n   apply(rule impI)\n  apply(rule cut_rl[of \"getVarBool s0 rotation = False\"])\n    apply(rule cut_rl[of \"getVarBool s0 rotation = True \\<and> \\<not> getVarBool s0 user\"])\n     apply fast\n  apply(rule cut_rl[of \"substate s2 s0 \\<and>\n          substate s0\n           (toEnv (setVarAny s0 user'value pressure'value))\\<and>\n          s0 \\<noteq>\n          (toEnv (setVarAny s0 user'value pressure'value)) \"])\n  using toEnvPs2  apply fast\n  using substate_refl toEnvNum_id apply((simp split: if_splits);auto)\n  using extraInvs0 extraInv_def vc\n   apply (smt (verit) getPstate.simps(9) predEnv.simps(9) predEnv_substate substate_eq_or_predEnv toEnvPs2)\n apply(simp only: pred3_def)\n  by ((rule VC4_R3_ind_step);fast) \nend\n\n\nlemma VC4_R3: \" (((((toEnvP s0 \\<and>\n            (\\<forall>s1 s2.\n                substate s1 s2 \\<and>\n                substate s2 s0 \\<and>\n                toEnvP s1 \\<and>\n                toEnvP s2 \\<and>\n                toEnvNum s1 s2 = ERROR \\<and>\n                DELAY'TIMEOUT \\<le> toEnvNum s2 s0 \\<and> getVarBool s1 rotation = True \\<and> \\<not> getVarBool s2 user \\<longrightarrow>\n                (\\<exists>s4. toEnvP s4 \\<and>\n                      substate s2 s4 \\<and>\n                      substate s4 s0 \\<and>\n                      toEnvNum s2 s4 \\<le> DELAY'TIMEOUT \\<and>\n                      (getVarBool s4 rotation = False \\<or> getVarBool s4 user) \\<and>\n                      (\\<forall>s3. toEnvP s3 \\<and> substate s2 s3 \\<and> substate s3 s4 \\<and> s3 \\<noteq> s4 \\<longrightarrow>\n                            getVarBool s3 rotation = True \\<and> \\<not> getVarBool s3 user)))) \\<and>\n           extraInv s0) \\<and>\n          env (setVarAny s0 user_value pressure_value)) \\<and>\n         getPstate (setVarAny s0 user_value pressure_value) ERROR = Controller'motionless) \\<and>\n        \\<not>getVarBool (setVarAny s0 user_value pressure_value) user)  \\<Longrightarrow>\n       substate s1 s2 \\<and>\n       substate s2\n       (toEnv (setVarAny s0 user'value pressure'value)) \\<and>\n       toEnvP s1 \\<and>\n       toEnvP s2 \\<and>\n       toEnvNum s1 s2 = ERROR \\<and>\n       DELAY'TIMEOUT\n       \\<le> toEnvNum s2\n           (toEnv (setVarAny s0 user'value pressure'value)) \\<and>\n       getVarBool s1 rotation = True \\<and> \\<not> getVarBool s2 user \\<longrightarrow>\n       (\\<exists>s4. toEnvP s4 \\<and>\n             substate s2 s4 \\<and>\n             substate s4\n              (toEnv (setVarAny s0 user'value pressure'value)) \\<and>\n             toEnvNum s2 s4 \\<le> DELAY'TIMEOUT \\<and>\n             (getVarBool s4 rotation = False \\<or> getVarBool s4 user) \\<and>\n             (\\<forall>s3. toEnvP s3 \\<and> substate s2 s3 \\<and> substate s3 s4 \\<and> s3 \\<noteq> s4 \\<longrightarrow>\n                   getVarBool s3 rotation = True \\<and> \\<not> getVarBool s3 user))\"\n  apply(rule impI)\n  apply(rule disjE[of \"DELAY'TIMEOUT < toEnvNum s2 (toEnv (setVarAny s0 user'value pressure'value))\"\n\"DELAY'TIMEOUT = toEnvNum s2 (toEnv (setVarAny s0 user'value pressure'value))\"])\n  using le_imp_less_or_eq apply fast\n   apply(rule cut_rl[of \"substate s2 s0 \\<and> toEnvNum s2 s0 \\<ge> DELAY'TIMEOUT\"])\n  apply(rule cut_rl[of \"(\\<exists>s4. toEnvP s4 \\<and>\n                   substate s2 s4 \\<and>\n                   substate s4 s0 \\<and>\n                   toEnvNum s2 s4 \\<le> DELAY'TIMEOUT \\<and>\n                   (getVarBool s4 rotation = False \\<or> getVarBool s4 user) \\<and>\n                   (\\<forall>s3. toEnvP s3 \\<and> substate s2 s3 \\<and> substate s3 s4 \\<and> s3 \\<noteq> s4 \\<longrightarrow>\n                         getVarBool s3 rotation = True \\<and> \\<not> getVarBool s3 user))\"])\n  apply (metis substate.simps(10) substate.simps(2) substate.simps(3) substate.simps(9))\n    apply blast\n   apply(simp split: if_splits)\n  apply(rule cut_rl[of \"pred3 s1 s2 \n (toEnv (setVarAny s0 user'value pressure'value))\ns2\"])\n   apply(simp only: pred3_def)\n   apply (smt (z3) substate_asym)\n   apply(rule mp[of \"toEnvP s2 \\<and>  substate s2 s2 \\<and>\n substate s2 (toEnv (setVarAny s0 user'value pressure'value))\"])\n   apply((rule VC4_R3_ind_proof);blast)\n  using substate_refl by fast\n  \n  \n\ntheorem proof_3_4: \"VC4 inv3 env s0 user_value pressure_value\"\n  apply(simp only: VC4_def inv3_def R3_def)\n  apply(rule impI)\n  apply(rule conjI)\n  apply(rule conjI)\n   apply(simp)\n   apply((rule allI);(rule allI))\n   apply((rule VC4_R3);blast)", "meta": {"author": "ivchernenko", "repo": "post_vcgenerator", "sha": "fadfff131086870a027d6bd1c78b8d5a3baf183b", "save_path": "github-repos/isabelle/ivchernenko-post_vcgenerator", "path": "github-repos/isabelle/ivchernenko-post_vcgenerator/post_vcgenerator-fadfff131086870a027d6bd1c78b8d5a3baf183b/case-studies/revolvingDoor/Proof_3_4.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.603931819468636, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.2667403819212185}}
{"text": "theory ProcLemma\n  imports ProcSendCase\nbegin\n\n    (* ##### 3. process reduction validity for thread case ##### *)\n\ndefinition dsub_env :: \"'a state_env \\<Rightarrow> 'b state_env \\<Rightarrow> bool\" where\n  \"dsub_env s env = (\\<forall> x. env x \\<noteq> None \\<longrightarrow> s x \\<noteq> None)\"    \n  \nlemma id_dsub_env: \"dsub_env s s\"\n  apply (simp add: dsub_env_def)\n  done\n  \nlemma add_dsub_env: \"\\<lbrakk> dsub_env s env \\<rbrakk> \\<Longrightarrow> dsub_env (add_env s x v) env\"   \n  apply (simp add: dsub_env_def)\n  apply (simp add: add_env_def)\n  done      \n    \nlemma super_sub_use_env: \"\\<lbrakk> dsub_env s' s; sub_use_env s r_s \\<rbrakk> \\<Longrightarrow> sub_use_env s' r_s\"    \n  apply (simp add: dsub_env_def)\n  apply (simp add: sub_use_env_def)\n  apply (auto)\n  done  \n  \nlemma app_red_exp_dsub_env: \"\\<lbrakk> app_red_exp are (s1, e1) ax (s2, e2) \\<rbrakk> \\<Longrightarrow> dsub_env s2 s1\"\n  apply (case_tac are)\n        apply (auto)\n        apply (rule_tac id_dsub_env)\n       apply (rule_tac id_dsub_env)\n      apply (case_tac c)\n                  apply (auto)\n        apply (rule_tac add_dsub_env)\n        apply (rule_tac id_dsub_env)\n       apply (rule_tac id_dsub_env)\n      apply (rule_tac add_dsub_env)\n      apply (rule_tac add_dsub_env)\n      apply (rule_tac id_dsub_env)\n     apply (rule_tac id_dsub_env)\n    apply (rule_tac id_dsub_env)\n   apply (rule_tac id_dsub_env)\n  apply (case_tac c)\n              apply (auto)\n    apply (rule_tac id_dsub_env)  \n   apply (rule_tac add_dsub_env)\n   apply (rule_tac id_dsub_env)\n  done\n    \n  \n    (* MAIN PROCESS REDUCTION LEMMA *)\n   \nlemma srps_thread_case: \"\\<lbrakk>well_typed_system env delta p_map s1 ps1; valid_reduct app_red_exp; r_ax = ThreadAct; ps1 u = Some (app_hole h e1); wf_hole h;\n        ps2 = add_env ps1 u (app_hole h e2); app_red_exp are (s1, e1) ax (s2, e2)\\<rbrakk>\n       \\<Longrightarrow> \\<exists>r_s g_ax. (\\<exists>p_map'. well_typed_system (red_env env g_ax) (red_delta delta g_ax) p_map' s2 (add_env ps1 u (app_hole h e2))) \\<and> safe_act s1 r_s g_ax\"\n    (* prelim: well_formed_delta / mem_val_env *)\n  apply (cut_tac delta=\"delta\" in wts_well_formed_delta)\n   apply (simp add: well_typed_system_def)\n   apply (auto)\n  apply (cut_tac env=\"env\" in wts_mem_val_env)\n   apply (simp add: well_typed_system_def)\n   apply (auto)\n    (* case where action is performed on single thread 'u'. *)\n  apply (case_tac \"\\<not> (well_typed_state s1 env delta \\<and> well_typed_proc_set env delta p_map ps1 \\<and> sub_nres_map s1 p_map)\")\n   apply (simp add: well_typed_system_def)\n  apply (auto)\n    (* we start by obtaining the well-typedness and validity for thread 'u' *)\n  apply (simp add: well_typed_proc_set_def)\n  apply (auto)\n  apply (erule_tac x=\"u\" in allE)\n  apply (auto)\n  apply (case_tac \"p_map u\")\n   apply (auto)\n    (* using the gsre lemma, we know that the resulting expression will be well-typed. *)\n  apply (cut_tac env=\"env\" and ?r_s1.0=\"a\" and ?e1.0=\"app_hole h e1\" and tau=\"UnitTy\" and ?r_s2.0=\"r_s2\" and rx=\"rx\" and ?s1.0=\"s1\" and\n        delta=\"delta\" and ?e2.0=\"app_hole h e2\" and ax=\"ax\" and ?s2.0=\"s2\" and r_f=\"a\" in safe_full_red_exp)\n         apply (auto)\n    apply (simp add: sub_nres_map_def)\n    apply (simp add: nres_lookup_def)\n    apply (erule_tac x=\"u\" in allE)\n    apply (auto)\n   apply (rule_tac id_leq_use_env)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"g_ax\" in exI)  \n  apply (auto)\n  apply (rule_tac x=\"add_env p_map u (exp_red_use_env a g_ax)\" in exI)\n    (* prove that the resulting system is well-typed overall *)\n  apply (simp add: well_typed_system_def)\n    (* prove that the process set in particular remains well-typed *)\n  apply (simp add: well_typed_proc_set_def)\n  apply (auto)\n    (* prove that the new map still covers the state *)(*\n       apply (rule_tac add_full_nres_map)\n       apply (simp)*)\n    (* prove that it is still disjoint *)\n     apply (rule_tac disj_add_nres_map)\n      apply (simp)\n     apply (rule_tac ?s1.0=\"s1\" in red_sep_nres_map)\n         apply (auto)\n      apply (rule_tac r_x=\"infl_use_env a r_s2\" in leq_safe_act)\n       apply (simp)\n      apply (rule_tac lhs_infl_leq_use_env)\n      apply (rule_tac id_leq_use_env)\n     apply (simp add: sub_nres_map_def)\n     apply (erule_tac x=\"u\" in allE)\n     apply (erule_tac x=\"u\" in allE)\n     apply (simp add: nres_lookup_def)\n    (* prove that everything is still well-typed. we start with the original expressions from ps1 *)\n    apply (case_tac \"u \\<noteq> ua\")\n     apply (case_tac \"add_env ps1 u (app_hole h e2) ua\")\n      apply (auto)\n     apply (erule_tac x=\"ua\" in allE)\n     apply (simp add: add_env_def)\n     apply (case_tac \"p_map ua\")\n      apply (auto)\n     apply (rule_tac x=\"rxa\" in exI)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (rule_tac env'=\"env\" in well_typed_contain_env)\n      apply (rule_tac s=\"s1\" in red_contain_env)\n       apply (simp_all)\n      apply (simp add: well_typed_state_def)\n     apply (rule_tac s=\"s1\" and r_f=\"a\" in well_typed_red_deltax)\n         apply (auto)\n      apply (simp add: disj_nres_map_def)\n      apply (erule_tac x=\"u\" in allE)\n      apply (erule_tac x=\"ua\" in allE)\n      apply (auto)\n      apply (simp add: nres_lookup_def)\n     apply (simp add: well_typed_state_def)\n    (* - proving that it's still proper as well *)(*\n      apply (rule_tac s=\"s1\" in red_proper_exp)\n        apply (auto)\n      apply (simp add: well_typed_state_def)*)\n    (* - it's true for the modified res map by valid_reduct's def *)\n    apply (simp add: add_env_def)\n    apply (erule_tac x=\"u\" in allE)\n    apply (auto)\n    (* prove that each res map in p_map is still contained in s2. this is true for the original\n        res maps since s1 <: s2 *)\n   apply (simp add: sub_nres_map_def)\n   apply (auto)\n   apply (case_tac \"u \\<noteq> x\")\n    apply (rule_tac s=\"s1\" in super_sub_use_env)\n     apply (simp add: nres_lookup_def)\n     apply (simp add: add_env_def)\n     apply (rule_tac are=\"are\" in app_red_exp_dsub_env)\n     apply (auto)\n    (* - it's true for the modified res map by valid_exp *) \n    apply (simp add: nres_lookup_def)\n    apply (simp add: add_env_def)\n   apply (simp add: nres_lookup_def)\n   apply (simp add: add_env_def)\n    (* prove that each res map in p_map is disjoint from the new rs_map. this is true for the original\n        res maps by lemma *)(*\n   apply (case_tac \"u \\<noteq> ua\")\n    apply (simp add: add_env_def)\n    apply (auto)\n    apply (erule_tac x=\"ua\" in allE)\n    apply (erule_tac x=\"ua\" in allE)\n    apply (case_tac \"p_map ua\")\n     apply (auto)\n    apply (simp add: valid_exp_use_env_def)\n     apply (rule_tac p_map=\"p_map\" and u=\"u\" and v=\"ua\" and r_p=\"aa\" and r_s=\"a\" and ?s1.0=\"s1\" in red_sep_nres_map2)\n           apply (auto)\n      apply (rule_tac r_x=\"infl_use_env a r_s2\" in leq_safe_act)\n       apply (simp)\n      apply (rule_tac lhs_infl_leq_use_env)\n      apply (rule_tac id_leq_use_env)\n    (* - it's true for the modified res map by valid_reduct's def *)\n   apply (simp add: add_env_def)\n   apply (simp add: valid_exp_use_env_def)*)\n    (* - action safety *)\n  apply (rule_tac r_x=\"infl_use_env a r_s2\" in leq_safe_act)\n   apply (simp)\n  apply (rule_tac lhs_infl_leq_use_env)\n  apply (rule_tac id_leq_use_env)\n  done      \n      \n    (* ##### 4a. fork lemma: proves well-typedness of new thread ##### *)\n    \ndefinition unit_app_abbrev where\n  \"unit_app_abbrev e = (AppExp e (ConstExp UnitConst))\"\n    \n    (* this lemma allows us to type the expression passed into a fork so that it can be moved into another thread. since it will be\n        stored in another thread, the requirements must be contained by r_s1, yet completely removable from it.\n        from the previous lemma, we know that this can be taken from just the non-prim vars in e *)\n\nlemma safe_fork_lam: \"\\<lbrakk> well_typed env delta r_s1 (app_hole h (AppExp (ConstExp ForkConst) e)) tau r_s2 rx; well_formed_delta env delta; is_value e; is_own r \\<rbrakk> \\<Longrightarrow>\n  well_typed env delta (np_dom_use_env env delta e) (unit_app_abbrev e) UnitTy empty_use_env empty_use_env\"\n  apply (induct h arbitrary: env r_s1 r_s2 tau rx)\n    apply (auto)\n  apply (simp add: unit_app_abbrev_def)\n    (* base case *)\n  apply (cut_tac env=\"env\" and delta=\"delta\" and ?r_s1.0=\"r_s2a\" and e=\"e\" and tau=\"FunTy UnitTy UnitTy UsePerm a\" and ?r_s2.0=\"r_s3\" and rx=\"rx2\" in infl_sexp_wp)\n     apply (simp_all)\n   apply (rule_tac value_is_sexp)\n   apply (auto)\n  apply (rule_tac x=\"UsePerm\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"np_dom_use_env env delta e\" in exI)\n  apply (rule_tac x=\"np_dom_use_env env delta e\" in exI)\n  apply (auto)\n    (* the idea is that the infl_sexp_wp requirements are strictly greater than np_dom, and since np_dom is strong, there is an exact way of\n        subtracting to get to np_dom. (we do cheat a little by lifting rx2). *)\n   apply (rule_tac t=\"np_dom_use_env env delta e\" and s=\"diff_use_env (comp_use_env (lift_use_env rx2 ra) (infl_use_env r_s2a r_s3))\n    (diff_use_env (lift_use_env (comp_use_env (lift_use_env rx2 ra) (infl_use_env r_s2a r_s3)) r) (np_dom_use_env env delta e))\" in subst)\n    apply (rule_tac sfl_diff_use_env)\n      apply (simp add: np_dom_use_env_def)\n      apply (rule_tac strong_dom_use_env)\n     apply (simp add: leq_use_env_def)\n     apply (auto)\n    (* to prove that the infl_sexp_wp reqs are greater than np_dom, we use the fact that any npv must have a permission *)\n    apply (simp add: np_dom_use_env_def)\n    apply (simp add: dom_use_env_def)\n    apply (auto)\n    apply (case_tac \"comp_use_env (lift_use_env rx2 ra) (infl_use_env r_s2a r_s3) x \\<noteq> OwnPerm\")\n     apply (case_tac \"comp_use_env rx2 (infl_use_env r_s2a r_s3) x = NoPerm\")\n      apply (cut_tac x=\"x\" and env=\"env\" and e=\"e\" and ?r_s1.0=\"comp_use_env rx2 (infl_use_env r_s2a r_s3)\" in well_typed_no_npv_use)\n        apply (auto)\n    apply (cut_tac r_sa=\"lift_use_env rx2 ra\" and r_sb=\"infl_use_env r_s2a r_s3\" and x=\"x\" in comp_use_no_own_both)\n     apply (auto)\n    apply (case_tac \"rx2 x \\<noteq> NoPerm\")\n     apply (simp add: is_own_def)\n    apply (case_tac \"rx2 x\")\n      apply (auto)\n    apply (case_tac \"infl_use_env r_s2a r_s3 x \\<noteq> NoPerm\")\n     apply (simp add: infl_use_env_def)\n     apply (case_tac \"r_s2a x = OwnPerm \\<and> r_s3 x = NoPerm\")\n      apply (auto)\n    apply (cut_tac r_sa=\"rx2\" and r_sb=\"infl_use_env r_s2a r_s3\" and x=\"x\" in comp_use_none)\n      apply (auto)\n    (* with that in mind, we manipulate until we match the infl sexp lemma *)\n   apply (rule_tac well_typed_diff_perms)\n    apply (rule_tac rx=\"comp_use_env rx2 (infl_use_env r_s2a r_s3)\" in well_typed_incr_req)\n      apply (rule_tac r_s=\"comp_use_env rx2 (infl_use_env r_s2a r_s3)\" in well_typed_incr_simul_perm)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac comp_leq_use_env1)\n        apply (rule_tac self_lift_leq_use_env)\n       apply (rule_tac self_comp_leq_use_env2)\n      apply (simp)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac comp_leq_use_env1)\n      apply (rule_tac self_lift_leq_use_env)\n     apply (rule_tac self_comp_leq_use_env2)\n    apply (rule_tac id_leq_use_env)\n    (* next, we must show that the differential is actually subtractible, which is true since it removes all non-prim vars *)\n  apply (auto)\n   apply (case_tac \"np_dom_use_env env delta e x \\<noteq> OwnPerm\")\n    apply (simp add: np_dom_use_env_def)\n    apply (simp add: dom_use_env_def)\n   apply (cut_tac r_s=\"lift_use_env (comp_use_env (lift_use_env rx2 ra) (infl_use_env r_s2a r_s3)) r\" and\n       r_ex=\"np_dom_use_env env delta e\" and x=\"x\" in diff_use_none_ex)\n    apply (simp)\n   apply (simp add: own_env_vars_def)\n    (* lastly, we prove the various inequalities for application to a unit const *)\n  apply (rule_tac x=\"empty_use_env\" in exI)\n  apply (rule_tac x=\"np_dom_use_env env delta e\" in exI)\n  apply (auto)\n    apply (rule_tac id_leq_use_env)\n   apply (rule_tac leq_empty_use_env)\n  apply (rule_tac x=\"empty_use_env\" in exI)\n  apply (auto)\n         apply (rule_tac leq_empty_use_env)(*\n        apply (simp add: empty_use_env_def)\n       apply (simp add: unlim_def)*)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (rule_tac id_leq_use_env)\n      apply (rule_tac leq_empty_use_env)\n     apply (rule_tac disj_empty_use_env1)\n    apply (rule_tac leq_empty_use_env)\n   apply (rule_tac leq_empty_use_env)\n  apply (simp add: app_req_def)\n  apply (rule_tac leq_empty_use_env)\n  done      \n    \n    (* ##### 4b. fork lemma: if x is an npv in 'e', then we have ownership permissions for 'h (fork e)' ##### *)\n \nlemma safe_fork_own_npv_use: \"\\<lbrakk> well_typed env delta r_s1 (app_hole h (AppExp (ConstExp ForkConst) e)) tau r_s2 rx; well_formed_delta env delta;\n is_value e; x \\<in> non_prim_vars env delta e \\<rbrakk> \\<Longrightarrow> r_s1 x = OwnPerm\"\n  apply (induct h arbitrary: env r_s1 r_s2 tau rx)\n        apply (auto)\n    (* base case *)\n     apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s2a\" and e=\"e\" and ?r_s2.0=\"r_s3\" and rx=\"rx2\" in infl_sexp_wp)\n       apply (auto)\n      apply (rule_tac value_is_sexp)\n      apply (simp)\n     apply (case_tac \"comp_use_env rx2 (infl_use_env r_s2a r_s3) x = NoPerm\")\n      apply (cut_tac env=\"env\" and x=\"x\" and e=\"e\" and ?r_s1.0=\"comp_use_env rx2 (infl_use_env r_s2a r_s3)\" in well_typed_no_npv_use)\n        apply (auto)\n     apply (case_tac \"rx2 x \\<noteq> NoPerm\")\n      apply (cut_tac r_x=\"lift_use_env rx2 r\" and r_s=\"r_s1\" and x=\"x\" in leq_use_own)\n        apply (simp add: is_own_def)\n       apply (rule_tac r_sb=\"comp_use_env rx1 (lift_use_env rx2 r)\" in trans_leq_use_env)\n        apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n         apply (rule_tac r_sb=\"r_s2a\" in trans_leq_use_env)\n          apply (auto)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n      apply (rule_tac self_comp_leq_use_env2)\n     apply (case_tac \"infl_use_env r_s2a r_s3 x \\<noteq> NoPerm\")\n      apply (simp add: infl_use_env_def)\n      apply (case_tac \"r_s2a x = OwnPerm \\<and> r_s3 x = NoPerm\")\n       apply (auto)\n      apply (rule_tac r_x=\"r_s2a\" in leq_use_own)\n       apply (auto)\n     apply (cut_tac r_sa=\"rx2\" and r_sb=\"infl_use_env r_s2a r_s3\" and x=\"x\" in comp_use_none)\n       apply (auto)\n    (* rhs induct *)\n    apply (rule_tac r_x=\"r_s2a\" in leq_use_own)\n     apply (simp)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n    (* rhs pair *)\n    apply (rule_tac r_x=\"r_s2a\" in leq_use_own)\n    apply (simp)\n   apply (rule_tac well_typed_perm_leq)\n   apply (auto)\n  done    \n    \n    (* ##### 4c. fork lemma: proves well-typedness of original thread post-fork ##### *)\n\n    (* this lemma proves that e should be removable from the fork. combined with the previous lemmas, we can also remove the\n      permissions of e, and type the two resultant expressions disjointly. *)\n    \nlemma safe_fork_exp_ih: \"\\<lbrakk> well_typed env delta r_s1 (app_hole h (AppExp (ConstExp ForkConst) e)) tau r_s2 rx; well_formed_delta env delta; is_value e \\<rbrakk> \\<Longrightarrow>\n  well_typed env delta r_s1 (app_hole h (ConstExp UnitConst)) tau r_s2 rx\"\n  apply (induct h arbitrary: env r_s1 e tau r_s2 rx)\n        apply (auto)\n    (* base case *)\n        apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n         apply (rule_tac r_sb=\"r_s2a\" in trans_leq_use_env)\n          apply (simp)\n         apply (rule_tac diff_leq_use_env)\n         apply (rule_tac well_typed_perm_leq)\n         apply (auto)\n    (* lhs induct *)\n       apply (rule_tac x=\"t1\" in exI)\n       apply (rule_tac x=\"r\" in exI)\n       apply (rule_tac x=\"a\" in exI)\n       apply (rule_tac x=\"r_s2a\" in exI)\n       apply (rule_tac x=\"rx1\" in exI)\n       apply (auto)\n    (* rhs induct *)\n      apply (rule_tac x=\"t1\" in exI)\n      apply (rule_tac x=\"r\" in exI)\n      apply (rule_tac x=\"a\" in exI)\n      apply (rule_tac x=\"r_s2a\" in exI)\n      apply (rule_tac x=\"rx1\" in exI)\n      apply (auto)\n      apply (rule_tac x=\"rx2\" in exI)\n      apply (rule_tac x=\"r_s3\" in exI)\n      apply (auto)\n    (* if case *)\n     apply (rule_tac x=\"rx'\" in exI)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (auto)\n    (* lhs pair case *)\n    apply (rule_tac x=\"r_s2a\" in exI)\n    apply (rule_tac x=\"r_s3\" in exI)\n    apply (rule_tac x=\"rx1\" in exI)\n    apply (auto)\n    (* rhs pair case *)\n   apply (rule_tac x=\"r_s2a\" in exI)\n   apply (rule_tac x=\"r_s3\" in exI)\n   apply (rule_tac x=\"rx1\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"rx2\" in exI)\n   apply (auto)\n  done\n    \n    (* uses:\n        - safe_fork_hole_npv_use: to determine that if x is an np-var, it is not in h\n        - 4b (safe_fork_own_npv_use) to determine that if x is an np-var, we own it\n    *)\n  \nlemma safe_fork_exp: \"\\<lbrakk> well_typed env delta r_s1 (app_hole h (AppExp (ConstExp ForkConst) e)) tau r_s2 rx;\n  well_formed_delta env delta; sub_use_env s r_s1; wf_hole h; is_value e \\<rbrakk> \\<Longrightarrow>\n  well_typed env delta (diff_use_env r_s1 (np_dom_use_env env delta e)) (app_hole h (ConstExp UnitConst)) tau\n  (diff_use_env r_s2 (np_dom_use_env env delta e)) (diff_use_env rx (np_dom_use_env env delta e))\"\n  apply (rule_tac well_typed_diff_perms)\n   apply (rule_tac safe_fork_exp_ih)\n    apply (auto)\n  apply (simp add: non_prim_vars_def)\n  apply (auto)\n    (* we want to show that if x is in the dominator, it is not an np-var in h.\n        > if x is an np-var itself, it cannot be in e by lemma *)\n  apply (case_tac \"x \\<in> non_prim_vars env delta e\")\n   apply (cut_tac h=\"h\" and x=\"x\" and e=\"ConstExp UnitConst\" in app_hole_res_vars_rev)\n    apply (auto)\n   apply (cut_tac h=\"h\" and x=\"x\" and env=\"env\" and ?r_s1.0=\"r_s1\" and e=\"e\" in safe_fork_hole_npv_use)\n        apply (auto)\n  apply (simp add: own_env_vars_def)\n  apply (simp add: np_dom_use_env_def)\n  apply (simp add: dom_use_env_def)(*\n    (* otherwise, x is in the completion. we identify its ancestor z. *)\n  apply (case_tac \"\\<exists>xa. x = Loc xa \\<and> (\\<exists>l z. Loc z \\<in> non_prim_vars env e \\<and> path_lookup rs_map z l xa)\")\n   apply (auto)\n    (* we note that z is a np-var of e therefore r_s1 z = Own *)\n  apply (cut_tac x=\"Loc z\" and env=\"env\" in safe_fork_own_npv_use)\n     apply (auto)\n    (* x then is in the lookup map of some parent y. *)\n  apply (cut_tac rs_map=\"rs_map\" and z=\"z\" and x=\"xa\" in path_lookup_parent)\n     apply (auto)\n    (* with that in mind, by separation, x is disjoint from r_s1. *)\n  apply (case_tac \"r_s1 (Loc xa) \\<noteq> NoPerm\")\n   apply (simp add: valid_exp_use_env_def)\n   apply (simp add: sep_nres_map_def)\n   apply (auto)\n   apply (erule_tac x=\"y\" in allE)\n   apply (simp add: nres_lookup_def)\n   apply (simp add: strong_disj_use_env_def)\n   apply (erule_tac x=\"Loc xa\" in allE)\n   apply (auto)\n    (* by extension, x is not in 'h (fork e)' *)\n  apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s1\" and x=\"Loc xa\" in well_typed_no_npv_use)\n    apply (auto)\n  apply (simp add: non_prim_vars_def)\n    (* the very last part is showing that x not in 'h (fork e)' implies x not in 'h ()'. *)\n  apply (cut_tac x=\"Loc xa\" and h=\"h\" and e=\"ConstExp UnitConst\" in app_hole_res_vars_rev)\n   apply (auto)\n  apply (cut_tac x=\"Loc xa\" and h=\"h\" and e=\"AppExp (ConstExp ForkConst) e\" in app_hole_res_vars2)\n   apply (auto)*)\n  done\n\n    (* ##### 4d. fork lemma: structural lemma for thread-disjointness in fork case ###### *)\n    \nlemma alift_strong_disj_use_env1: \"\\<lbrakk> strong_disj_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> strong_disj_use_env (lift_use_env r_x r) r_s\"    \n  apply (simp add: strong_disj_use_env_def)\n  apply (auto)\n  apply (case_tac r)\n    apply (auto)\n  done\n  \n    (* a special lemma that makes it easier to comprehend our strategy for proving the disjointness of the fork *)\nlemma fork_disj_nres_map: \"\\<lbrakk> disj_nres_map p_map; p_map u = Some r_s; is_own r;\n  leq_use_env r_xa (lift_use_env r_s r); leq_use_env r_xb (lift_use_env r_s r);\n  strong_disj_use_env r_xa r_xb \\<rbrakk> \\<Longrightarrow> disj_nres_map (add_env (add_env p_map u r_xa) v r_xb)\"\n  apply (rule_tac disj_add_nres_map)\n   apply (rule_tac disj_add_nres_map)\n    apply (simp)\n    (* first we must prove the disjointness of the new assignment to u *)\n   apply (simp add: sep_nres_map_def)\n   apply (auto)\n   apply (case_tac \"u = x\")\n    apply (cut_tac rs_map=\"p_map\" and x=\"u\" in nres_rem_same)\n    apply (auto)\n    apply (rule_tac empty_strong_disj_use_env2)\n   apply (cut_tac rs_map=\"p_map\" and x=\"u\" and y=\"x\" in nres_rem_diff)\n    apply (auto)\n   apply (simp add: disj_nres_map_def)\n   apply (erule_tac x=\"u\" in allE)\n   apply (erule_tac x=\"x\" in allE)\n   apply (auto)\n   apply (rule_tac r_s=\"lift_use_env r_s r\" in strong_disj_leq_use_env1)\n    apply (rule_tac alift_strong_disj_use_env1)\n    apply (simp add: nres_lookup_def)\n   apply (simp)\n    (* next we prove the disjointness of v, starting with its disjointness to u *)\n  apply (simp add: sep_nres_map_def)\n  apply (auto)\n  apply (case_tac \"x = v\")\n   apply (cut_tac rs_map=\"add_env p_map u r_xa\" and x=\"v\" in nres_rem_same)\n   apply (auto)\n   apply (rule_tac empty_strong_disj_use_env2)\n  apply (case_tac \"x = u\")\n   apply (auto)\n   apply (case_tac \"\\<not> nres_lookup (add_env p_map u r_xa) u = r_xa\")\n    apply (simp add: nres_lookup_def)\n    apply (simp add: add_env_def)\n   apply (cut_tac rs_map=\"add_env p_map u r_xa\" and x=\"v\" and y=\"u\" in nres_rem_diff)\n    apply (auto)\n   apply (rule_tac comm_strong_disj_use_env)\n   apply (simp)\n    (* next we prove its disjointess to the rest of the map *)\n  apply (cut_tac rs_map=\"add_env p_map u r_xa\" and x=\"v\" and y=\"x\" in nres_rem_diff)\n   apply (auto)\n  apply (cut_tac rs_map=\"p_map\" and x=\"u\" and y=\"x\" and r_s=\"r_xa\" in nres_add_diff)\n   apply (auto)\n  apply (simp add: disj_nres_map_def)\n  apply (erule_tac x=\"u\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (rule_tac r_s=\"lift_use_env r_s r\" in strong_disj_leq_use_env1)\n   apply (rule_tac alift_strong_disj_use_env1)\n   apply (simp add: nres_lookup_def)\n  apply (simp)\n  done\n\n    (* ##### 4_X. process reduction validity for fork case ##### *)    \n  \nlemma lift_sep_nres_map: \"\\<lbrakk> sep_nres_map r_s rs_map \\<rbrakk> \\<Longrightarrow> sep_nres_map (lift_use_env r_s r) rs_map\"  \n  apply (simp add: sep_nres_map_def)\n  apply (auto)\n  apply (rule_tac alift_strong_disj_use_env1)\n  apply (auto)\n  done\n  \nlemma srps_fork_case: \"\\<lbrakk>well_typed_system env delta p_map s2 ps1; r_ax = ForkAct; ps1 u = Some (app_hole h (AppExp (ConstExp ForkConst) e));\n                wf_hole h; is_value e; ps2 = add_env (add_env ps1 u (app_hole h (ConstExp UnitConst))) v (AppExp e (ConstExp UnitConst)); fresh_var ps1 v;\n                s1 = s2\\<rbrakk>\n               \\<Longrightarrow> \\<exists>r_s g_ax. (\\<exists>p_map'. well_typed_system (red_env env g_ax) (red_delta delta g_ax) p_map' s2\n                                     (add_env (add_env ps1 u (app_hole h (ConstExp UnitConst))) v (AppExp e (ConstExp UnitConst)))) \\<and>\n                          safe_act s2 r_s g_ax\"\n    (* prelim: well_formed_delta / mem_val_env *)\n  apply (cut_tac delta=\"delta\" in wts_well_formed_delta)\n   apply (simp add: well_typed_system_def)\n   apply (auto)\n  apply (cut_tac env=\"env\" in wts_mem_val_env)\n   apply (simp add: well_typed_system_def)\n   apply (auto)\n    (* fork case. no resources are generated in this step *)\n  apply (rule_tac x=\"empty_use_env\" in exI)\n  apply (rule_tac x=\"NoResAct\" in exI)\n  apply (auto)\n  apply (simp add: well_typed_system_def)\n  apply (auto)\n    (* before we can give the new process map types, we have to get the well-typedness statement for h (fork e) *)\n  (*apply (case_tac \"\\<not> (case ps1 u of None \\<Rightarrow> True\n                     | Some e \\<Rightarrow> (case lookup_mem p_map u of None \\<Rightarrow> False\n                                 | Some (r_c, s') \\<Rightarrow> \\<exists>rx r_s r_s2. well_typed env r_s e UnitTy r_s2 rx \\<and> valid_use_env s2 rs_map r_c r_s))\")*)\n  apply (case_tac \"\\<not> (\n     disj_nres_map p_map \\<and> (\\<forall>u. case ps1 u of None \\<Rightarrow> True | Some e \\<Rightarrow>\n      (case p_map u of None \\<Rightarrow> False | Some r_s \\<Rightarrow> \\<exists>rx r_s2. well_typed env delta r_s e UnitTy r_s2 rx)))\")\n   apply (simp add: well_typed_proc_set_def)\n  apply (auto)\n  apply (case_tac \"\\<not> (case ps1 u of None \\<Rightarrow> True | Some e \\<Rightarrow> (case p_map u of None \\<Rightarrow> False | Some r_s \\<Rightarrow> \\<exists>rx r_s2. well_typed env delta r_s e UnitTy r_s2 rx))\")\n   apply (erule_tac x=\"u\" in allE)\n   apply (auto)\n  apply (case_tac \"p_map u\")\n   apply (auto)\n    (* using the fork lemmas, we can generate a type for e + a type for h () *)\n  apply (cut_tac eq_own)\n  apply (auto)\n  apply (cut_tac env=\"env\" and e=\"e\" and ?r_s1.0=\"a\" and tau=\"UnitTy\" and h=\"h\" and ?r_s2.0=\"r_s2\" and rx=\"rx\" and r=\"r\" in safe_fork_lam)\n     apply (auto)\n  apply (cut_tac env=\"env\" and e=\"e\" and ?r_s1.0=\"a\" and tau=\"UnitTy\" and h=\"h\" and ?r_s2.0=\"r_s2\" and rx=\"rx\" and s=\"s2\" in safe_fork_exp)\n       apply (auto)\n    apply (simp add: well_typed_state_def)\n    (* - complete proof that a is still valid *)\n   apply (simp add: well_typed_proc_set_def)\n   apply (simp add: sub_nres_map_def)\n   apply (erule_tac x=\"u\" in allE)\n   apply (erule_tac x=\"u\" in allE)\n   apply (simp add: nres_lookup_def)\n    (* - prelim: prove that (full_dom_use_env env rs_map e) \\<le> a (old complete map) *)(*\n  apply (cut_tac rs_map=\"rs_map\" and e=\"e\" and r_c=\"a\" and h=\"h\" and env=\"env\" in valid_full_dom_leq_use_env)\n      apply (auto)\n   apply (simp add: well_typed_state_def)*)\n    (* - prelim: np_dom_use_env env e \\<le> lift_use_env a r *)\n  apply (cut_tac r_sc=\"np_dom_use_env env delta e\" and r_sb=\"np_dom_use_env env delta (app_hole h (AppExp (ConstExp ForkConst) e))\" \n      and r_sa=\"lift_use_env a r\" in trans_leq_use_env)\n    apply (rule_tac wt_np_leq_use_env)\n     apply (auto)\n   apply (simp add: np_dom_use_env_def)\n   apply (rule_tac dist_dom_leq_use_env)\n   apply (auto)\n   apply (simp add: non_prim_vars_def)\n   apply (cut_tac x=\"x\" and e=\"AppExp (ConstExp ForkConst) e\" in app_hole_res_vars)\n    apply (auto)\n    (* we fill in the  new process map, by taking perms from 'u' [[ h () ]] and giving them to 'v' [[ e () ]] *)\n  apply (rule_tac x=\"add_env (add_env p_map u (diff_use_env a (np_dom_use_env env delta e))) v (np_dom_use_env env delta e)\" in exI)\n  apply (simp add: well_typed_proc_set_def)\n  apply (auto)\n    (* completeness of the new process map *)(*\n      apply (rule_tac add_full_nres_map)\n      apply (rule_tac add_full_nres_map)\n      apply (simp)*)\n    (* disjointness of the new process map *)\n     apply (rule_tac r_s=\"a\" and r=\"r\" in fork_disj_nres_map)\n          apply (auto)\n      apply (rule_tac lift_leq_use_env)\n      apply (rule_tac self_diff_leq_use_env)\n     apply (rule_tac r_s=\"np_dom_use_env env delta e\" in strong_disj_leq_use_env2)\n      apply (rule_tac reduce_strong_disj_use_env)\n       apply (simp add: disj_use_env_def)\n       apply (auto)\n        apply (rule_tac r_s=\"a\" in mini_disj_strong_use_env)\n         apply (rule_tac id_leq_use_env)\n        apply (simp add: np_dom_use_env_def)\n        apply (rule_tac strong_dom_use_env)\n       apply (rule_tac mini_disj_diff_use_env)\n      apply (simp add: np_dom_use_env_def)\n      apply (rule_tac strong_dom_use_env)\n     apply (rule_tac id_leq_use_env)\n    (* proving everything is still well-typed. we start with ua = v, ie the 'e ()' thread. *)\n    apply (case_tac \"ua = v\")\n     apply (case_tac \"\\<not> add_env (add_env ps1 u (app_hole h (ConstExp UnitConst))) v (AppExp e (ConstExp UnitConst)) ua =\n      Some (unit_app_abbrev e)\")\n      apply (simp add: add_env_def)\n      apply (simp add: unit_app_abbrev_def)\n     apply (auto)\n     apply (case_tac \"\\<not> (add_env (add_env p_map u (diff_use_env a (np_dom_use_env env delta e))) v (np_dom_use_env env delta e)) v =\n      Some (np_dom_use_env env delta e)\")\n      apply (simp add: add_env_def)\n     apply (auto)\n    (* - properness *)(*\n     apply (cut_tac rs_map=\"rs_map\" and h=\"h\" and e=\"AppExp (ConstExp ForkConst) e\" in proper_app_hole_split2)\n      apply (simp)\n     apply (simp add: unit_app_abbrev_def)\n     apply (simp add: proper_exp_def)*)\n    (* - well-typedness for ua = u, the 'h ()' thread*)\n    apply (case_tac \"ua = u\")\n     apply (case_tac \"\\<not> add_env (add_env ps1 u (app_hole h (ConstExp UnitConst))) v (AppExp e (ConstExp UnitConst)) ua =\n        Some (app_hole h (ConstExp UnitConst))\")\n      apply (simp add: add_env_def)\n     apply (auto)\n     apply (case_tac \"\\<not> (add_env (add_env p_map u (diff_use_env a (np_dom_use_env env delta e))) v (np_dom_use_env env delta e)) u =\n        Some (diff_use_env a (np_dom_use_env env delta e))\")\n      apply (simp add: add_env_def)\n     apply (auto)\n    (* - properness *)(*\n     apply (cut_tac rs_map=\"rs_map\" and h=\"h\" in proper_app_hole_split1)\n      apply (simp)\n     apply (rule_tac proper_app_hole_recon)\n      apply (simp)\n     apply (simp add: proper_exp_def)*)\n    (* - well-typedness for unaltered threads *)\n    apply (erule_tac x=\"ua\" in allE)\n    apply (case_tac \"\\<not> add_env (add_env ps1 u (app_hole h (ConstExp UnitConst))) v (AppExp e (ConstExp UnitConst)) ua = ps1 ua\")\n     apply (simp add: add_env_def)\n    apply (case_tac \"ps1 ua\")\n     apply (auto)\n    apply (case_tac \"\\<not> (add_env (add_env p_map u (diff_use_env a (np_dom_use_env env delta e))) v (np_dom_use_env env delta e)) ua =\n      p_map ua\")\n     apply (simp add: add_env_def)\n    apply (auto)(*\n    apply (erule_tac x=\"ua\" in allE)\n    apply (auto)*)\n    (* proving the new process map is contained in the state *)\n   apply (rule_tac add_sub_nres_map1)\n    apply (rule_tac add_sub_nres_map1)\n     apply (simp)\n    apply (rule_tac r_s=\"a\" in trans_sub_use_env)\n     apply (simp add: sub_nres_map_def)\n     apply (erule_tac x=\"u\" in allE)\n     apply (erule_tac x=\"u\" in allE)\n     apply (simp add: nres_lookup_def)\n    apply (rule_tac self_diff_leq_use_env)\n   apply (rule_tac r_s=\"lift_use_env a r\" in trans_sub_use_env)\n    apply (rule_tac lift_sub_use_env)\n    apply (simp add: sub_nres_map_def)\n    apply (erule_tac x=\"u\" in allE)\n    apply (erule_tac x=\"u\" in allE)\n    apply (simp add: nres_lookup_def)\n   apply (simp)\n    (* proving that separation still holds. we again start with ua = v, the 'e ()' thread *)(*\n  apply (case_tac \"ua = v\")\n   apply (simp add: add_env_def)\n   apply (rule_tac r_s=\"lift_use_env a r\" in leq_sep_nres_map)\n    apply (simp)\n   apply (rule_tac lift_sep_nres_map)\n   apply (erule_tac x=\"u\" in allE)\n   apply (simp)\n    (* - same for ua = u, ie the 'h ()' thread *)\n  apply (case_tac \"ua = u\")\n   apply (simp add: add_env_def)\n   apply (rule_tac r_s=\"a\" in leq_sep_nres_map)\n    apply (rule_tac self_diff_leq_use_env)\n   apply (erule_tac x=\"u\" in allE)\n   apply (simp)\n    (* - lastly prove separation for original threads *)\n  apply (simp add: add_env_def)*)\n  done\n    \n    (* ##### 5. final proof composition ##### *)  \n    \nlemma safe_red_proc_set: \"\\<lbrakk> well_typed_system env delta p_map s1 ps1; red_proc_set (s1, ps1) r_ax (s2, ps2); valid_reduct app_red_exp \\<rbrakk> \\<Longrightarrow>\n  (\\<exists> r_s g_ax p_map'. well_typed_system (red_env env g_ax) (red_delta delta g_ax) p_map' s2 ps2 \\<and> safe_act s1 r_s g_ax)\"\n    (* split over process reduction type. *)\n  apply (case_tac \"r_ax\")\n    apply (auto)\n    (* single thread action case. *)\n    apply (rule_tac srps_thread_case)\n          apply (auto)\n    (* fork case. *)\n   apply (rule_tac srps_fork_case)\n          apply (auto)\n    (* send case. *)\n  apply (rule_tac srps_send_case)\n                apply (auto)\ndone\n  \nend", "meta": {"author": "dcco", "repo": "perm_lang_thesis", "sha": "81661c97a0c43701c9ec0a75074d9553b2dd0263", "save_path": "github-repos/isabelle/dcco-perm_lang_thesis", "path": "github-repos/isabelle/dcco-perm_lang_thesis/perm_lang_thesis-81661c97a0c43701c9ec0a75074d9553b2dd0263/isa_code/ProcLemma.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6370308082623217, "lm_q2_score": 0.4186969093556867, "lm_q1q2_score": 0.26672283058378915}}
{"text": "theory Refine_C_AC\nimports\n  \"../lib/ComCorres\"\n  \"../AutoCorres/Impl\"\nbegin\n\nlemma refines: \"C_minimal \\<sqsubseteq> AC_minimal\"\nproof -\n  let ?m\\<^sub>A = \"minimalAC\" and ?m\\<^sub>C = \"Call minimal_'proc\"\n    and ?\\<Gamma> = \"minimal_global_addresses.\\<Gamma>\" and ?P = \"(\\<lambda>s. True)\"\n    and ?st = \"minimal.lift_global_heap \\<circ> globals\"\n    and ?rx = \"sint \\<circ> ret__int_'\"\n  have \"Run AC_minimal = lift_nd ?m\\<^sub>A\" unfolding AC_minimal_def by simp\n  moreover have \"Run C_minimal = lift_com ?m\\<^sub>C ?\\<Gamma>\" unfolding C_minimal_def by simp\n  moreover have \"\\<forall>s s\\<^sub>C. s\\<^sub>C \\<in> Init C_minimal s \\<longrightarrow>\n       ?P s\\<^sub>C \\<and> \\<not> snd (minimal.minimal' (?st s\\<^sub>C)) \\<and> ?st s\\<^sub>C \\<in> Init AC_minimal s\"\n    unfolding C_minimal_def AC_minimal_def minimal.minimal'_def\n    by (simp add: snd_return)\n  moreover have \"ac_corres ?st ?\\<Gamma> ?rx ?P ?m\\<^sub>A ?m\\<^sub>C\" using minimal.minimal'_ac_corres .\n  moreover have \"\\<forall>s\\<^sub>C'. Fin AC_minimal (?st s\\<^sub>C') = Fin C_minimal s\\<^sub>C'\"\n    unfolding AC_minimal_def C_minimal_def by simp\n  ultimately show ?thesis by (metis corres_refines snd_liftE)\nqed\n\nend", "meta": {"author": "CriticalTechnologiesInc", "repo": "SableModel", "sha": "a452a2b5e3636b612a4d04cfb6e2ab1c1a132639", "save_path": "github-repos/isabelle/CriticalTechnologiesInc-SableModel", "path": "github-repos/isabelle/CriticalTechnologiesInc-SableModel/SableModel-a452a2b5e3636b612a4d04cfb6e2ab1c1a132639/Proofs/Refine_C_AC.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6370307944803832, "lm_q2_score": 0.4186969093556867, "lm_q1q2_score": 0.2667228248133341}}
{"text": "(*  Title:       Aodv_Loop_Freedom.thy\n    License:     BSD 2-Clause. See LICENSE.\n    Author:      Timothy Bourke, Inria\n*)\n\nsection \"Lift and transfer invariants to show loop freedom\"\n\ntheory Aodv_Loop_Freedom\nimports AWN.OClosed_Transfer AWN.Qmsg_Lifting Global_Invariants Loop_Freedom\nbegin\n\nsubsection \\<open>Lift to parallel processes with queues\\<close>\n\nlemma par_step_no_change_on_send_or_receive:\n    fixes \\<sigma> s a \\<sigma>' s'\n  assumes \"((\\<sigma>, s), a, (\\<sigma>', s')) \\<in> oparp_sos i (oseqp_sos \\<Gamma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V i) (seqp_sos \\<Gamma>\\<^sub>Q\\<^sub>M\\<^sub>S\\<^sub>G)\"\n      and \"a \\<noteq> \\<tau>\"\n    shows \"\\<sigma>' i = \\<sigma> i\"\n  using assms by (rule qmsg_no_change_on_send_or_receive)\n\nlemma par_nhop_quality_increases:\n  shows \"opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg \\<Turnstile> (otherwith ((=)) {i} (orecvmsg (\\<lambda>\\<sigma> m.\n                                    msg_fresh \\<sigma> m \\<and> msg_zhops m)),\n                                  other quality_increases {i} \\<rightarrow>)\n                        global (\\<lambda>\\<sigma>. \\<forall>dip. let nhip = the (nhop (rt (\\<sigma> i)) dip)\n                                          in dip \\<in> vD (rt (\\<sigma> i)) \\<inter> vD (rt (\\<sigma> nhip)) \\<and> nhip \\<noteq> dip\n                                             \\<longrightarrow> (rt (\\<sigma> i)) \\<sqsubset>\\<^bsub>dip\\<^esub> (rt (\\<sigma> nhip)))\"\n    proof (rule lift_into_qmsg [OF seq_nhop_quality_increases])\n    show \"opaodv i \\<Turnstile>\\<^sub>A (otherwith ((=)) {i}\n                         (orecvmsg (\\<lambda>\\<sigma> m. msg_fresh \\<sigma> m \\<and> msg_zhops m)),\n                        other quality_increases {i} \\<rightarrow>)\n                       globala (\\<lambda>(\\<sigma>, _, \\<sigma>'). quality_increases (\\<sigma> i) (\\<sigma>' i))\"\n    proof (rule ostep_invariant_weakenE [OF oquality_increases], simp_all)\n      fix t :: \"(((nat \\<Rightarrow> state) \\<times> (state, msg, pseqp, pseqp label) seqp), msg seq_action) transition\"\n      assume \"onll \\<Gamma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V (\\<lambda>((\\<sigma>, _), _, (\\<sigma>', _)). \\<forall>j. quality_increases (\\<sigma> j) (\\<sigma>' j)) t\"\n      thus \"quality_increases (fst (fst t) i) (fst (snd (snd t)) i)\"\n        by (cases t) (clarsimp dest!: onllD, metis aodv_ex_label)\n    next\n      fix \\<sigma> \\<sigma>' a\n      assume \"otherwith ((=)) {i}\n                (orecvmsg (\\<lambda>\\<sigma> m. msg_fresh \\<sigma> m \\<and> msg_zhops m)) \\<sigma> \\<sigma>' a\"\n      thus \"otherwith quality_increases {i} (orecvmsg (\\<lambda>_. rreq_rrep_sn)) \\<sigma> \\<sigma>' a\"\n        by - (erule weaken_otherwith, auto)\n    qed\n  qed auto\n\nlemma par_rreq_rrep_sn_quality_increases:\n  \"opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. orecvmsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                            globala (\\<lambda>(\\<sigma>, _, \\<sigma>'). quality_increases (\\<sigma> i) (\\<sigma>' i))\"\n  proof -\n    have \"opaodv i \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. orecvmsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                globala (\\<lambda>(\\<sigma>, _, \\<sigma>'). quality_increases (\\<sigma> i) (\\<sigma>' i))\"\n      by (rule ostep_invariant_weakenE [OF olocal_quality_increases])\n         (auto dest!: onllD seqllD elim!: aodv_ex_labelE)\n    hence \"opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. orecvmsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                                   globala (\\<lambda>(\\<sigma>, _, \\<sigma>'). quality_increases (\\<sigma> i) (\\<sigma>' i))\"\n      by (rule lift_step_into_qmsg_statelessassm) simp_all\n    thus ?thesis by rule auto\n  qed\n\nlemma par_rreq_rrep_nsqn_fresh_any_step:\n  shows \"opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. orecvmsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>,\n                                   other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                                  globala (\\<lambda>(\\<sigma>, a, \\<sigma>'). anycast (msg_fresh \\<sigma>) a)\"\n  proof -\n    have \"opaodv i \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. (orecvmsg (\\<lambda>_. rreq_rrep_sn)) \\<sigma>, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                       globala (\\<lambda>(\\<sigma>, a, \\<sigma>'). anycast (msg_fresh \\<sigma>) a)\"\n    proof (rule ostep_invariant_weakenE [OF rreq_rrep_nsqn_fresh_any_step_invariant])\n      fix t\n      assume \"onll \\<Gamma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V (\\<lambda>((\\<sigma>, _), a, _). anycast (msg_fresh \\<sigma>) a) t\"\n      thus \"globala (\\<lambda>(\\<sigma>, a, \\<sigma>'). anycast (msg_fresh \\<sigma>) a) t\"\n        by (cases t) (clarsimp dest!: onllD, metis aodv_ex_label)\n    qed auto\n    hence \"opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. (orecvmsg (\\<lambda>_. rreq_rrep_sn)) \\<sigma>, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                                    globala (\\<lambda>(\\<sigma>, a, \\<sigma>'). anycast (msg_fresh \\<sigma>) a)\"\n      by (rule lift_step_into_qmsg_statelessassm) simp_all\n    thus ?thesis by rule auto\n  qed\n\nlemma par_anycast_msg_zhops:\n  shows \"opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. orecvmsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                                  globala (\\<lambda>(_, a, _). anycast msg_zhops a)\"\n  proof -\n    from anycast_msg_zhops initiali_aodv oaodv_trans aodv_trans\n      have \"opaodv i \\<Turnstile>\\<^sub>A (act TT, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                         seqll i (onll \\<Gamma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V (\\<lambda>(_, a, _). anycast msg_zhops a))\"\n        by (rule open_seq_step_invariant)\n    hence \"opaodv i \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. orecvmsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                            globala (\\<lambda>(_, a, _). anycast msg_zhops a)\"\n    proof (rule ostep_invariant_weakenE)\n      fix t :: \"(((nat \\<Rightarrow> state) \\<times> (state, msg, pseqp, pseqp label) seqp), msg seq_action) transition\"\n      assume \"seqll i (onll \\<Gamma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V (\\<lambda>(_, a, _). anycast msg_zhops a)) t\"\n      thus \"globala (\\<lambda>(_, a, _). anycast msg_zhops a) t\"\n        by (cases t) (clarsimp dest!: seqllD onllD, metis aodv_ex_label)\n    qed simp_all\n    hence \"opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. orecvmsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                                     globala (\\<lambda>(_, a, _). anycast msg_zhops a)\"\n      by (rule lift_step_into_qmsg_statelessassm) simp_all\n    thus ?thesis by rule auto\n  qed\n\nsubsection \\<open>Lift to nodes\\<close>\n\nlemma node_step_no_change_on_send_or_receive:\n  assumes \"((\\<sigma>, NodeS i P R), a, (\\<sigma>', NodeS i' P' R')) \\<in> onode_sos\n                                      (oparp_sos i (oseqp_sos \\<Gamma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V i) (seqp_sos \\<Gamma>\\<^sub>Q\\<^sub>M\\<^sub>S\\<^sub>G))\"\n      and \"a \\<noteq> \\<tau>\"\n    shows \"\\<sigma>' i = \\<sigma> i\"\n  using assms\n  by (cases a) (auto elim!: par_step_no_change_on_send_or_receive)\n\nlemma node_nhop_quality_increases:\n  shows \"\\<langle> i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R \\<rangle>\\<^sub>o \\<Turnstile>\n           (otherwith ((=)) {i}\n              (oarrivemsg (\\<lambda>\\<sigma> m. msg_fresh \\<sigma> m \\<and> msg_zhops m)),\n              other quality_increases {i}\n            \\<rightarrow>) global (\\<lambda>\\<sigma>. \\<forall>dip. let nhip = the (nhop (rt (\\<sigma> i)) dip)\n                                  in dip \\<in> vD (rt (\\<sigma> i)) \\<inter> vD (rt (\\<sigma> nhip)) \\<and> nhip \\<noteq> dip\n                                     \\<longrightarrow> (rt (\\<sigma> i)) \\<sqsubset>\\<^bsub>dip\\<^esub> (rt (\\<sigma> nhip)))\"\n  by (rule node_lift [OF par_nhop_quality_increases]) auto\n\nlemma node_quality_increases:\n  \"\\<langle> i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R \\<rangle>\\<^sub>o \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. oarrivemsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>,\n                                         other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n                            globala (\\<lambda>(\\<sigma>, _, \\<sigma>'). quality_increases (\\<sigma> i) (\\<sigma>' i))\"\n  by (rule node_lift_step_statelessassm [OF par_rreq_rrep_sn_quality_increases]) simp\n\nlemma node_rreq_rrep_nsqn_fresh_any_step:\n  shows \"\\<langle> i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R \\<rangle>\\<^sub>o \\<Turnstile>\\<^sub>A\n          (\\<lambda>\\<sigma> _. oarrivemsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n          globala (\\<lambda>(\\<sigma>, a, \\<sigma>'). castmsg (msg_fresh \\<sigma>) a)\"\n  by (rule node_lift_anycast_statelessassm [OF par_rreq_rrep_nsqn_fresh_any_step])\n\nlemma node_anycast_msg_zhops:\n  shows \"\\<langle> i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R \\<rangle>\\<^sub>o \\<Turnstile>\\<^sub>A\n          (\\<lambda>\\<sigma> _. oarrivemsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>, other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n          globala (\\<lambda>(_, a, _). castmsg msg_zhops a)\"\n  by (rule node_lift_anycast_statelessassm [OF par_anycast_msg_zhops])\n\nlemma node_silent_change_only:\n  shows \"\\<langle> i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R\\<^sub>i \\<rangle>\\<^sub>o \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. oarrivemsg (\\<lambda>_ _. True) \\<sigma>,\n                                               other (\\<lambda>_ _. True) {i} \\<rightarrow>)\n          globala (\\<lambda>(\\<sigma>, a, \\<sigma>'). a \\<noteq> \\<tau> \\<longrightarrow> \\<sigma>' i = \\<sigma> i)\"\n  proof (rule ostep_invariantI, simp (no_asm), rule impI)\n    fix \\<sigma> \\<zeta> a \\<sigma>' \\<zeta>'\n    assume or: \"(\\<sigma>, \\<zeta>) \\<in> oreachable (\\<langle>i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R\\<^sub>i\\<rangle>\\<^sub>o)\n                                    (\\<lambda>\\<sigma> _. oarrivemsg (\\<lambda>_ _. True) \\<sigma>)\n                                    (other (\\<lambda>_ _. True) {i})\"\n      and tr: \"((\\<sigma>, \\<zeta>), a, (\\<sigma>', \\<zeta>')) \\<in> trans (\\<langle>i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R\\<^sub>i\\<rangle>\\<^sub>o)\"\n      and \"a \\<noteq> \\<tau>\\<^sub>n\"\n    from or obtain p R where \"\\<zeta> = NodeS i p R\"\n      by - (drule node_net_state, metis)\n    with tr have \"((\\<sigma>, NodeS i p R), a, (\\<sigma>', \\<zeta>'))\n                     \\<in> onode_sos (oparp_sos i (trans (opaodv i)) (trans qmsg))\"\n      by simp\n    thus \"\\<sigma>' i = \\<sigma> i\" using \\<open>a \\<noteq> \\<tau>\\<^sub>n\\<close> \n      by (cases rule: onode_sos.cases)\n         (auto elim: qmsg_no_change_on_send_or_receive)\n  qed\n\nsubsection \\<open>Lift to partial networks\\<close>\n\nlemma arrive_rreq_rrep_nsqn_fresh_inc_sn [simp]:\n  assumes \"oarrivemsg (\\<lambda>\\<sigma> m. msg_fresh \\<sigma> m \\<and> P \\<sigma> m) \\<sigma> m\"\n    shows \"oarrivemsg (\\<lambda>_. rreq_rrep_sn) \\<sigma> m\"\n  using assms by (cases m) auto\n\nlemma opnet_nhop_quality_increases:\n  shows \"opnet (\\<lambda>i. opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg) p \\<Turnstile>\n           (otherwith ((=)) (net_tree_ips p)\n              (oarrivemsg (\\<lambda>\\<sigma> m. msg_fresh \\<sigma> m \\<and> msg_zhops m)),\n               other quality_increases (net_tree_ips p) \\<rightarrow>)\n              global (\\<lambda>\\<sigma>. \\<forall>i\\<in>net_tree_ips p. \\<forall>dip.\n                          let nhip = the (nhop (rt (\\<sigma> i)) dip)\n                          in dip \\<in> vD (rt (\\<sigma> i)) \\<inter> vD (rt (\\<sigma> nhip)) \\<and> nhip \\<noteq> dip\n                             \\<longrightarrow> (rt (\\<sigma> i)) \\<sqsubset>\\<^bsub>dip\\<^esub> (rt (\\<sigma> nhip)))\"\n  proof (rule pnet_lift [OF node_nhop_quality_increases])\n    fix i R\n    have \"\\<langle>i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R\\<rangle>\\<^sub>o \\<Turnstile>\\<^sub>A (\\<lambda>\\<sigma> _. oarrivemsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>,\n                                              other (\\<lambda>_ _. True) {i} \\<rightarrow>) globala (\\<lambda>(\\<sigma>, a, \\<sigma>').\n            castmsg (\\<lambda>m. msg_fresh \\<sigma> m \\<and> msg_zhops m) a)\"\n    proof (rule ostep_invariantI, simp (no_asm))\n      fix \\<sigma> s a \\<sigma>' s'\n      assume or: \"(\\<sigma>, s) \\<in> oreachable (\\<langle>i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R\\<rangle>\\<^sub>o)\n                                      (\\<lambda>\\<sigma> _. oarrivemsg (\\<lambda>_. rreq_rrep_sn) \\<sigma>)\n                                      (other (\\<lambda>_ _. True) {i})\"\n         and tr: \"((\\<sigma>, s), a, (\\<sigma>', s')) \\<in> trans (\\<langle>i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R\\<rangle>\\<^sub>o)\"\n         and am: \"oarrivemsg (\\<lambda>_. rreq_rrep_sn) \\<sigma> a\"\n      from or tr am have \"castmsg (msg_fresh \\<sigma>) a\"\n        by (auto dest!: ostep_invariantD [OF node_rreq_rrep_nsqn_fresh_any_step])\n      moreover from or tr am have \"castmsg (msg_zhops) a\"\n        by (auto dest!: ostep_invariantD [OF node_anycast_msg_zhops])\n      ultimately show \"castmsg (\\<lambda>m. msg_fresh \\<sigma> m \\<and> msg_zhops m) a\"\n        by (case_tac a) auto\n    qed\n    thus \"\\<langle>i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R\\<rangle>\\<^sub>o \\<Turnstile>\\<^sub>A\n            (\\<lambda>\\<sigma> _. oarrivemsg (\\<lambda>\\<sigma> m. msg_fresh \\<sigma> m \\<and> msg_zhops m) \\<sigma>,\n             other quality_increases {i} \\<rightarrow>) globala (\\<lambda>(\\<sigma>, a, _).\n               castmsg (\\<lambda>m. msg_fresh \\<sigma> m \\<and> msg_zhops m) a)\"\n      by rule auto\n  next\n    fix i R\n    show \"\\<langle>i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R\\<rangle>\\<^sub>o \\<Turnstile>\\<^sub>A\n            (\\<lambda>\\<sigma> _. oarrivemsg (\\<lambda>\\<sigma> m. msg_fresh \\<sigma> m \\<and> msg_zhops m) \\<sigma>,\n             other quality_increases {i} \\<rightarrow>) globala (\\<lambda>(\\<sigma>, a, \\<sigma>').\n               a \\<noteq> \\<tau> \\<and> (\\<forall>d. a \\<noteq> i:deliver(d)) \\<longrightarrow> \\<sigma> i = \\<sigma>' i)\"\n      by (rule ostep_invariant_weakenE [OF node_silent_change_only]) auto\n  next\n    fix i R\n    show \"\\<langle>i : opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg : R\\<rangle>\\<^sub>o \\<Turnstile>\\<^sub>A\n            (\\<lambda>\\<sigma> _. oarrivemsg (\\<lambda>\\<sigma> m. msg_fresh \\<sigma> m \\<and> msg_zhops m) \\<sigma>,\n             other quality_increases {i} \\<rightarrow>) globala (\\<lambda>(\\<sigma>, a, \\<sigma>').\n               a = \\<tau> \\<or> (\\<exists>d. a = i:deliver(d)) \\<longrightarrow> quality_increases (\\<sigma> i) (\\<sigma>' i))\"\n      by (rule ostep_invariant_weakenE [OF node_quality_increases]) auto\n  qed simp_all\n\nsubsection \\<open>Lift to closed networks\\<close>\n\nlemma onet_nhop_quality_increases:\n  shows \"oclosed (opnet (\\<lambda>i. opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg) p)\n           \\<Turnstile> (\\<lambda>_ _ _. True, other quality_increases (net_tree_ips p) \\<rightarrow>)\n              global (\\<lambda>\\<sigma>. \\<forall>i\\<in>net_tree_ips p. \\<forall>dip.\n                          let nhip = the (nhop (rt (\\<sigma> i)) dip)\n                          in dip \\<in> vD (rt (\\<sigma> i)) \\<inter> vD (rt (\\<sigma> nhip)) \\<and> nhip \\<noteq> dip\n                             \\<longrightarrow> (rt (\\<sigma> i)) \\<sqsubset>\\<^bsub>dip\\<^esub> (rt (\\<sigma> nhip)))\"\n  (is \"_ \\<Turnstile> (_, ?U \\<rightarrow>) ?inv\")\n  proof (rule inclosed_closed)\n    from opnet_nhop_quality_increases\n      show \"opnet (\\<lambda>i. opaodv i \\<langle>\\<langle>\\<^bsub>i\\<^esub> qmsg) p\n               \\<Turnstile> (otherwith ((=)) (net_tree_ips p) inoclosed, ?U \\<rightarrow>) ?inv\"\n    proof (rule oinvariant_weakenE)\n      fix \\<sigma> \\<sigma>' :: \"ip \\<Rightarrow> state\" and a :: \"msg node_action\"\n      assume \"otherwith ((=)) (net_tree_ips p) inoclosed \\<sigma> \\<sigma>' a\"\n      thus \"otherwith ((=)) (net_tree_ips p)\n              (oarrivemsg (\\<lambda>\\<sigma> m. msg_fresh \\<sigma> m \\<and> msg_zhops m)) \\<sigma> \\<sigma>' a\"\n      proof (rule otherwithEI)\n        fix \\<sigma> :: \"ip \\<Rightarrow> state\" and a :: \"msg node_action\"\n        assume \"inoclosed \\<sigma> a\"\n        thus \"oarrivemsg (\\<lambda>\\<sigma> m. msg_fresh \\<sigma> m \\<and> msg_zhops m) \\<sigma> a\"\n        proof (cases a)\n          fix ii ni ms\n          assume \"a = ii\\<not>ni:arrive(ms)\"\n          moreover with \\<open>inoclosed \\<sigma> a\\<close> obtain d di where \"ms = newpkt(d, di)\"\n            by (cases ms) auto\n          ultimately show ?thesis by simp\n        qed simp_all\n      qed\n    qed\n  qed\n\nsubsection \\<open>Transfer into the standard model\\<close>\n\ninterpretation aodv_openproc: openproc paodv opaodv id\n  rewrites \"aodv_openproc.initmissing = initmissing\"\n  proof -\n    show \"openproc paodv opaodv id\"\n    proof unfold_locales\n      fix i :: ip\n      have \"{(\\<sigma>, \\<zeta>). (\\<sigma> i, \\<zeta>) \\<in> \\<sigma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V i \\<and> (\\<forall>j. j \\<noteq> i \\<longrightarrow> \\<sigma> j \\<in> fst ` \\<sigma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V j)} \\<subseteq> \\<sigma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V'\"\n        unfolding \\<sigma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V_def \\<sigma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V'_def\n        proof (rule equalityD1)\n          show \"\\<And>f p. {(\\<sigma>, \\<zeta>). (\\<sigma> i, \\<zeta>) \\<in> {(f i, p)} \\<and> (\\<forall>j. j \\<noteq> i\n                      \\<longrightarrow> \\<sigma> j \\<in> fst ` {(f j, p)})} = {(f, p)}\"\n            by (rule set_eqI) auto\n        qed\n      thus \"{ (\\<sigma>, \\<zeta>) |\\<sigma> \\<zeta> s. s \\<in> init (paodv i)\n                             \\<and> (\\<sigma> i, \\<zeta>) = id s\n                             \\<and> (\\<forall>j. j\\<noteq>i \\<longrightarrow> \\<sigma> j \\<in> (fst o id) ` init (paodv j)) } \\<subseteq> init (opaodv i)\"\n        by simp\n    next\n      show \"\\<forall>j. init (paodv j) \\<noteq> {}\"\n        unfolding \\<sigma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V_def by simp\n    next\n      fix i s a s' \\<sigma> \\<sigma>'\n      assume \"\\<sigma> i = fst (id s)\"\n         and \"\\<sigma>' i = fst (id s')\"\n         and \"(s, a, s') \\<in> trans (paodv i)\"\n      then obtain q q' where \"s = (\\<sigma> i, q)\"\n                         and \"s' = (\\<sigma>' i, q')\"\n                         and \"((\\<sigma> i, q), a, (\\<sigma>' i, q')) \\<in> trans (paodv i)\" \n         by (cases s, cases s') auto\n      from this(3) have \"((\\<sigma>, q), a, (\\<sigma>', q')) \\<in> trans (opaodv i)\"\n        by simp (rule open_seqp_action [OF aodv_wf])\n\n      with \\<open>s = (\\<sigma> i, q)\\<close> and \\<open>s' = (\\<sigma>' i, q')\\<close>\n        show \"((\\<sigma>, snd (id s)), a, (\\<sigma>', snd (id s'))) \\<in> trans (opaodv i)\"\n          by simp\n    qed\n    then interpret opn: openproc paodv opaodv id .\n    have [simp]: \"\\<And>i. (SOME x. x \\<in> (fst o id) ` init (paodv i)) = aodv_init i\"\n      unfolding \\<sigma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V_def by simp\n    hence \"\\<And>i. openproc.initmissing paodv id i = initmissing i\"\n      unfolding opn.initmissing_def opn.someinit_def initmissing_def\n      by (auto split: option.split)\n    thus \"openproc.initmissing paodv id = initmissing\" ..\n  qed\n\ninterpretation aodv_openproc_par_qmsg: openproc_parq paodv opaodv id qmsg\n  rewrites \"aodv_openproc_par_qmsg.netglobal = netglobal\"\n    and \"aodv_openproc_par_qmsg.initmissing = initmissing\"\n  proof -\n    show \"openproc_parq paodv opaodv id qmsg\"\n      by (unfold_locales) simp\n    then interpret opq: openproc_parq paodv opaodv id qmsg .\n\n    have im: \"\\<And>\\<sigma>. openproc.initmissing (\\<lambda>i. paodv i \\<langle>\\<langle> qmsg) (\\<lambda>(p, q). (fst (id p), snd (id p), q)) \\<sigma>\n                                                                                    = initmissing \\<sigma>\"\n      unfolding opq.initmissing_def opq.someinit_def initmissing_def\n      unfolding \\<sigma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V_def \\<sigma>\\<^sub>Q\\<^sub>M\\<^sub>S\\<^sub>G_def by (clarsimp cong: option.case_cong)\n    thus \"openproc.initmissing (\\<lambda>i. paodv i \\<langle>\\<langle> qmsg) (\\<lambda>(p, q). (fst (id p), snd (id p), q)) = initmissing\"\n      by (rule ext)\n    have \"\\<And>P \\<sigma>. openproc.netglobal (\\<lambda>i. paodv i \\<langle>\\<langle> qmsg) (\\<lambda>(p, q). (fst (id p), snd (id p), q)) P \\<sigma>\n                                                                                = netglobal P \\<sigma>\"\n      unfolding opq.netglobal_def netglobal_def opq.initmissing_def initmissing_def opq.someinit_def\n      unfolding \\<sigma>\\<^sub>A\\<^sub>O\\<^sub>D\\<^sub>V_def \\<sigma>\\<^sub>Q\\<^sub>M\\<^sub>S\\<^sub>G_def\n      by (clarsimp cong: option.case_cong\n                   simp del: One_nat_def\n                   simp add: fst_initmissing_netgmap_default_aodv_init_netlift\n                                                  [symmetric, unfolded initmissing_def])\n    thus \"openproc.netglobal (\\<lambda>i. paodv i \\<langle>\\<langle> qmsg) (\\<lambda>(p, q). (fst (id p), snd (id p), q)) = netglobal\"\n      by auto\n  qed\n\nlemma net_nhop_quality_increases:\n  assumes \"wf_net_tree n\"\n  shows \"closed (pnet (\\<lambda>i. paodv i \\<langle>\\<langle> qmsg) n) \\<TTurnstile> netglobal\n                           (\\<lambda>\\<sigma>. \\<forall>i dip. let nhip = the (nhop (rt (\\<sigma> i)) dip)\n                                        in dip \\<in> vD (rt (\\<sigma> i)) \\<inter> vD (rt (\\<sigma> nhip)) \\<and> nhip \\<noteq> dip\n                                            \\<longrightarrow> (rt (\\<sigma> i)) \\<sqsubset>\\<^bsub>dip\\<^esub> (rt (\\<sigma> nhip)))\"\n        (is \"_ \\<TTurnstile> netglobal (\\<lambda>\\<sigma>. \\<forall>i. ?inv \\<sigma> i)\")\n  proof -\n    from \\<open>wf_net_tree n\\<close>\n      have proto: \"closed (pnet (\\<lambda>i. paodv i \\<langle>\\<langle> qmsg) n) \\<TTurnstile> netglobal (\\<lambda>\\<sigma>. \\<forall>i\\<in>net_tree_ips n. \\<forall>dip.\n                                            let nhip = the (nhop (rt (\\<sigma> i)) dip)\n                                            in dip \\<in> vD (rt (\\<sigma> i)) \\<inter> vD (rt (\\<sigma> nhip)) \\<and> nhip \\<noteq> dip\n                                                \\<longrightarrow> (rt (\\<sigma> i)) \\<sqsubset>\\<^bsub>dip\\<^esub> (rt (\\<sigma> nhip)))\"\n        by (rule aodv_openproc_par_qmsg.close_opnet [OF _ onet_nhop_quality_increases])\n    show ?thesis\n    unfolding invariant_def opnet_sos.opnet_tau1\n    proof (rule, simp only: aodv_openproc_par_qmsg.netglobalsimp\n                            fst_initmissing_netgmap_pair_fst, rule allI)\n      fix \\<sigma> i\n      assume sr: \"\\<sigma> \\<in> reachable (closed (pnet (\\<lambda>i. paodv i \\<langle>\\<langle> qmsg) n)) TT\"\n      hence \"\\<forall>i\\<in>net_tree_ips n. ?inv (fst (initmissing (netgmap fst \\<sigma>))) i\"\n        by - (drule invariantD [OF proto],\n              simp only: aodv_openproc_par_qmsg.netglobalsimp\n                         fst_initmissing_netgmap_pair_fst)\n      thus \"?inv (fst (initmissing (netgmap fst \\<sigma>))) i\"\n      proof (cases \"i\\<in>net_tree_ips n\")\n        assume \"i\\<notin>net_tree_ips n\"\n        from sr have \"\\<sigma> \\<in> reachable (pnet (\\<lambda>i. paodv i \\<langle>\\<langle> qmsg) n) TT\" ..\n        hence \"net_ips \\<sigma> = net_tree_ips n\" ..\n        with \\<open>i\\<notin>net_tree_ips n\\<close> have \"i\\<notin>net_ips \\<sigma>\" by simp\n        hence \"(fst (initmissing (netgmap fst \\<sigma>))) i = aodv_init i\"\n          by simp\n        thus ?thesis by simp\n      qed metis\n    qed\n  qed\n\nsubsection \\<open>Loop freedom of AODV\\<close>\n\ntheorem aodv_loop_freedom:\n  assumes \"wf_net_tree n\"\n  shows \"closed (pnet (\\<lambda>i. paodv i \\<langle>\\<langle> qmsg) n) \\<TTurnstile> netglobal (\\<lambda>\\<sigma>. \\<forall>dip. irrefl ((rt_graph \\<sigma> dip)\\<^sup>+))\"\n  using assms by (rule aodv_openproc_par_qmsg.netglobal_weakenE\n                          [OF net_nhop_quality_increases inv_to_loop_freedom])\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/AODV/Aodv_Loop_Freedom.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.4649015713733885, "lm_q1q2_score": 0.26670399308765474}}
{"text": "(*<*)\n(*\n   Title:  Theory  DataDependenciesCaseStudy.thy\n   Author: Maria Spichkova <maria.spichkova at rmit.edu.au>, 2014\n*)\n(*>*)\n\nsection \"Case Study: Verification of Properties\"\n \ntheory DataDependenciesCaseStudy\n  imports DataDependencies\nbegin\n\n\nsubsection \\<open>Correct composition of components\\<close>\n\n\\<comment> \\<open>the lemmas  AbstrLevels X Y with corresponding proofs can be composend\\<close>\n\\<comment> \\<open>and proven automatically, their proofs are identical\\<close>\nlemma AbstrLevels_A1_A11:\n  assumes \"sA1 \\<in> AbstrLevel i\"\n  shows \"sA11 \\<notin> AbstrLevel i\"\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n\nlemma AbstrLevels_A1_A12:\n  assumes \"sA1 \\<in> AbstrLevel i\"\n  shows \"sA12 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_A2_A21:\n  assumes \"sA2 \\<in> AbstrLevel i\"\n  shows \"sA21 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_A2_A22:\n  assumes \"sA2 \\<in> AbstrLevel i\"\n  shows \"sA22 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_A2_A23:\n  assumes \"sA2 \\<in> AbstrLevel i\"\n  shows \"sA23 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_A3_A31:\n  assumes \"sA3 \\<in> AbstrLevel i\"\n  shows \"sA31 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_A3_A32:\n  assumes \"sA3 \\<in> AbstrLevel i\"\n  shows \"sA32 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_A4_A41:\n  assumes \"sA4 \\<in> AbstrLevel i\"\n  shows \"sA41 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_A4_A42:\n  assumes \"sA4 \\<in> AbstrLevel i\"\n  shows \"sA42 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_A7_A71:\n  assumes \"sA7 \\<in> AbstrLevel i\"\n  shows \"sA71 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_A7_A72:\n  assumes \"sA7 \\<in> AbstrLevel i\"\n  shows \"sA72 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\nlemma AbstrLevels_A8_A81:\n  assumes \"sA8 \\<in> AbstrLevel i\"\n  shows \"sA81 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\nlemma AbstrLevels_A8_A82:\n  assumes \"sA8 \\<in> AbstrLevel i\"\n  shows \"sA82 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_A9_A91:\n  assumes \"sA9 \\<in> AbstrLevel i\"\n  shows \"sA91 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_A9_A92:\n  assumes \"sA9 \\<in> AbstrLevel i\"\n  shows \"sA92 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_A9_A93:\n  assumes \"sA9 \\<in> AbstrLevel i\"\n  shows \"sA93 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S1_A12:\n  assumes \"sS1 \\<in> AbstrLevel i\"\n  shows \"sA12 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S2_A11:\n  assumes \"sS2 \\<in> AbstrLevel i\"\n  shows \"sA11 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S3_A21:\n  assumes \"sS3 \\<in> AbstrLevel i\"\n  shows \"sA21 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S4_A23:\n  assumes \"sS4 \\<in> AbstrLevel i\"\n  shows \"sA23 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S5_A32:\n  assumes \"sS5 \\<in> AbstrLevel i\"\n  shows \"sA32 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S6_A22:\n  assumes \"sS6 \\<in> AbstrLevel i\"\n  shows \"sA22 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S6_A31:\n  assumes \"sS6 \\<in> AbstrLevel i\"\n  shows \"sA31 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S6_A41:\n  assumes \"sS6 \\<in> AbstrLevel i\"\n  shows \"sA41 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S7_A42:\n  assumes \"sS7 \\<in> AbstrLevel i\"\n  shows \"sA42 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S8_A5:\n  assumes \"sS8 \\<in> AbstrLevel i\"\n  shows \"sA5 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S9_A6:\n  assumes \"sS9 \\<in> AbstrLevel i\"\n  shows \"sA6 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S10_A71:\n  assumes \"sS10 \\<in> AbstrLevel i\"\n  shows \"sA71 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S11_A72:\n  assumes \"sS11 \\<in> AbstrLevel i\"\n  shows \"sA72 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S12_A81:\n  assumes \"sS12 \\<in> AbstrLevel i\"\n  shows \"sA81 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S12_A91:\n  assumes \"sS12 \\<in> AbstrLevel i\"\n  shows \"sA91 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S13_A92:\n  assumes \"sS13 \\<in> AbstrLevel i\"\n  shows \"sA92 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S14_A82:\n  assumes \"sS14 \\<in> AbstrLevel i\"\n  shows \"sA82 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S15_A93:\n  assumes \"sS15 \\<in> AbstrLevel i\"\n  shows \"sA93 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S1opt_A11:\n  assumes \"sS1opt \\<in> AbstrLevel i\"\n  shows \"sA11 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S1opt_A12:\n  assumes \"sS1opt \\<in> AbstrLevel i\"\n  shows \"sA12 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S4opt_A23:\n  assumes \"sS4opt \\<in> AbstrLevel i\"\n  shows \"sA23 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S4opt_A32:\n  assumes \"sS4opt \\<in> AbstrLevel i\"\n  shows \"sA32 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S4opt_A22:\n  assumes \"sS4opt \\<in> AbstrLevel i\"\n  shows \"sA22 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S4opt_A31:\n  assumes \"sS4opt \\<in> AbstrLevel i\"\n  shows \"sA31 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S4opt_A41:\n  assumes \"sS4opt \\<in> AbstrLevel i\"\n  shows \"sA41 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S7opt_A42:\n  assumes \"sS7opt \\<in> AbstrLevel i\"\n  shows \"sA42 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S7opt_A5:\n  assumes \"sS7opt \\<in> AbstrLevel i\"\n  shows \"sA5 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S11opt_A72:\n  assumes \"sS11opt \\<in> AbstrLevel i\"\n  shows \"sA72 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S11opt_A82:\n  assumes \"sS11opt \\<in> AbstrLevel i\"\n  shows \"sA82 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma AbstrLevels_S11opt_A93:\n  assumes \"sS11opt \\<in> AbstrLevel i\"\n  shows \"sA93 \\<notin> AbstrLevel i\"\n(*<*)\nusing assms \nby (induct i, simp add: AbstrLevel0, simp add:  AbstrLevel1, simp add:  AbstrLevel2,  simp add:  AbstrLevel3)\n(*>*)\n\n\nlemma correctCompositionDiffLevelsA1: \"correctCompositionDiffLevels sA1\"\n(*<*)by (simp add: correctCompositionDiffLevels_def AbstrLevels_A1_A11 AbstrLevels_A1_A12)(*>*)\n\n\nlemma correctCompositionDiffLevelsA2: \"correctCompositionDiffLevels sA2\"\n(*<*)by (simp add: correctCompositionDiffLevels_def AbstrLevels_A2_A21 AbstrLevels_A2_A22 AbstrLevels_A2_A23)(*>*)\n\n\nlemma correctCompositionDiffLevelsA3: \"correctCompositionDiffLevels sA3\"\n(*<*)by (simp add: correctCompositionDiffLevels_def AbstrLevels_A3_A31 AbstrLevels_A3_A32)(*>*)\n\n\nlemma correctCompositionDiffLevelsA4: \"correctCompositionDiffLevels sA4\"\n(*<*)by (simp add: correctCompositionDiffLevels_def AbstrLevels_A4_A41 AbstrLevels_A4_A42)(*>*)\n\n\n\\<comment> \\<open>lemmas  correctCompositionDiffLevelsX and corresponding proofs\\<close>\n\\<comment> \\<open>are identical for all elementary components, they can be constructed automatically\\<close> \nlemma correctCompositionDiffLevelsA5: \"correctCompositionDiffLevels sA5\"\n(*<*)by (simp add: correctCompositionDiffLevels_def) (*>*)\n\nlemma correctCompositionDiffLevelsA6: \"correctCompositionDiffLevels sA6\"\n(*<*)by (simp add: correctCompositionDiffLevels_def) (*>*)\n\nlemma correctCompositionDiffLevelsA7: \"correctCompositionDiffLevels sA7\"\n(*<*)by (simp add: correctCompositionDiffLevels_def AbstrLevels_A7_A71 AbstrLevels_A7_A72)(*>*)\n\nlemma correctCompositionDiffLevelsA8: \"correctCompositionDiffLevels sA8\"\n(*<*)by (simp add: correctCompositionDiffLevels_def AbstrLevels_A8_A81 AbstrLevels_A8_A82)(*>*)\n\nlemma correctCompositionDiffLevelsA9: \"correctCompositionDiffLevels sA9\"\n(*<*)by (simp add: correctCompositionDiffLevels_def AbstrLevels_A9_A91 AbstrLevels_A9_A92 AbstrLevels_A9_A93)(*>*)\n\n\n\nlemma correctCompositionDiffLevelsA12: \"correctCompositionDiffLevels sA12\"\n(*<*)by (simp add: correctCompositionDiffLevels_def) (*>*)\n\nlemma correctCompositionDiffLevelsA21: \"correctCompositionDiffLevels sA21\"\n(*<*)by (simp add: correctCompositionDiffLevels_def) (*>*)\n\nlemma correctCompositionDiffLevelsA22: \"correctCompositionDiffLevels sA22\"\n(*<*)by (simp add: correctCompositionDiffLevels_def) (*>*)\n\nlemma correctCompositionDiffLevelsA23: \"correctCompositionDiffLevels sA23\"\n(*<*)by (simp add: correctCompositionDiffLevels_def) (*>*)\n\nlemma correctCompositionDiffLevelsA31: \"correctCompositionDiffLevels sA31\"\n(*<*)by (simp add: correctCompositionDiffLevels_def) (*>*)\n\nlemma correctCompositionDiffLevelsA32: \"correctCompositionDiffLevels sA32\"\n(*<*)by (simp add: correctCompositionDiffLevels_def) (*>*)\n\nlemma correctCompositionDiffLevelsA41: \"correctCompositionDiffLevels sA41\"\n(*<*)by (simp add: correctCompositionDiffLevels_def) (*>*)\n\nlemma correctCompositionDiffLevelsA42: \"correctCompositionDiffLevels sA42\"\n(*<*)by (simp add: correctCompositionDiffLevels_def) (*>*)\n\nlemma correctCompositionDiffLevelsA71: \"correctCompositionDiffLevels sA71\"\n(*<*)by (simp add: correctCompositionDiffLevels_def) (*>*)\n\nlemma correctCompositionDiffLevelsA72: \"correctCompositionDiffLevels sA72\"\n(*<*)by (simp add: correctCompositionDiffLevels_def) (*>*)\n\nlemma correctCompositionDiffLevelsA81: \"correctCompositionDiffLevels sA81\"\n(*<*)by (simp add: correctCompositionDiffLevels_def) (*>*)\n\nlemma correctCompositionDiffLevelsA82: \"correctCompositionDiffLevels sA82\"\n(*<*)by (simp add: correctCompositionDiffLevels_def) (*>*)\n\nlemma correctCompositionDiffLevelsA91: \"correctCompositionDiffLevels sA91\"\n(*<*)by (simp add: correctCompositionDiffLevels_def) (*>*)\n\nlemma correctCompositionDiffLevelsA92: \"correctCompositionDiffLevels sA92\"\n(*<*)by (simp add: correctCompositionDiffLevels_def) (*>*)\n\n\n\nlemma correctCompositionDiffLevelsS1: \"correctCompositionDiffLevels sS1\"\n(*<*)by (simp add: correctCompositionDiffLevels_def AbstrLevels_S1_A12) (*>*)\n\nlemma correctCompositionDiffLevelsS2: \"correctCompositionDiffLevels sS2\"\n(*<*)by (simp add: correctCompositionDiffLevels_def AbstrLevels_S2_A11) (*>*)\n\nlemma correctCompositionDiffLevelsS3: \"correctCompositionDiffLevels sS3\"\n(*<*)by (simp add: correctCompositionDiffLevels_def AbstrLevels_S3_A21) (*>*)\n\nlemma correctCompositionDiffLevelsS4: \"correctCompositionDiffLevels sS4\"\n(*<*)by (simp add: correctCompositionDiffLevels_def AbstrLevels_S4_A23) (*>*)\n\nlemma correctCompositionDiffLevelsS5: \"correctCompositionDiffLevels sS5\"\n(*<*)by (simp add: correctCompositionDiffLevels_def AbstrLevels_S5_A32) (*>*)\n\nlemma correctCompositionDiffLevelsS6: \"correctCompositionDiffLevels sS6\"\n(*<*)by (simp add: correctCompositionDiffLevels_def  AbstrLevels_S6_A22 AbstrLevels_S6_A31 AbstrLevels_S6_A41) (*>*)\n\nlemma correctCompositionDiffLevelsS7: \"correctCompositionDiffLevels sS7\"\n(*<*)by (simp add: correctCompositionDiffLevels_def AbstrLevels_S7_A42) (*>*)\n\nlemma correctCompositionDiffLevelsS8: \"correctCompositionDiffLevels sS8\"\n(*<*)by (simp add: correctCompositionDiffLevels_def AbstrLevels_S8_A5) (*>*)\n\nlemma correctCompositionDiffLevelsS9: \"correctCompositionDiffLevels sS9\"\n(*<*)by (simp add: correctCompositionDiffLevels_def AbstrLevels_S9_A6) (*>*)\n\nlemma correctCompositionDiffLevelsS10: \"correctCompositionDiffLevels sS10\"\n(*<*)by (simp add: correctCompositionDiffLevels_def AbstrLevels_S10_A71) (*>*)\n\nlemma correctCompositionDiffLevelsS11: \"correctCompositionDiffLevels sS11\"\n(*<*)by (simp add: correctCompositionDiffLevels_def AbstrLevels_S11_A72) (*>*)\n\nlemma correctCompositionDiffLevelsS12: \"correctCompositionDiffLevels sS12\"\n(*<*)by (simp add: correctCompositionDiffLevels_def  AbstrLevels_S12_A81 AbstrLevels_S12_A91) (*>*)\n\nlemma correctCompositionDiffLevelsS13: \"correctCompositionDiffLevels sS13\"\n(*<*)by (simp add: correctCompositionDiffLevels_def AbstrLevels_S13_A92) (*>*)\n\nlemma correctCompositionDiffLevelsS14: \"correctCompositionDiffLevels sS14\"\n(*<*)by (simp add: correctCompositionDiffLevels_def AbstrLevels_S14_A82) (*>*)\n\nlemma correctCompositionDiffLevelsS15: \"correctCompositionDiffLevels sS15\"\n(*<*)by (simp add: correctCompositionDiffLevels_def AbstrLevels_S15_A93) (*>*)\n\nlemma correctCompositionDiffLevelsS1opt: \"correctCompositionDiffLevels sS1opt\"\n(*<*)by (simp add: correctCompositionDiffLevels_def  AbstrLevels_S1opt_A11 AbstrLevels_S1opt_A12) (*>*)\n\nlemma correctCompositionDiffLevelsS4opt: \"correctCompositionDiffLevels sS4opt\"\n(*<*)by (simp add: correctCompositionDiffLevels_def  AbstrLevels_S4opt_A22 \n      AbstrLevels_S4opt_A23  AbstrLevels_S4opt_A31  \n      AbstrLevels_S4opt_A32  AbstrLevels_S4opt_A41) (*>*)\n\n\n\nlemma correctCompositionDiffLevelsS11opt: \"correctCompositionDiffLevels sS11opt\"\n(*<*)by (simp add: correctCompositionDiffLevels_def  AbstrLevels_S11opt_A72 \n        AbstrLevels_S11opt_A82 AbstrLevels_S11opt_A93) (*>*)\n\nlemma correctCompositionDiffLevelsSYSTEM_holds:\n\"correctCompositionDiffLevelsSYSTEM\"\n(*<*)by (simp add: correctCompositionDiffLevelsSYSTEM_def, clarify, case_tac S, \nsimp add: correctCompositionDiffLevelsA1, \nsimp add: correctCompositionDiffLevelsA2,\nsimp add: correctCompositionDiffLevelsA3,\nsimp add: correctCompositionDiffLevelsA4,\nsimp add: correctCompositionDiffLevelsA5,\nsimp add: correctCompositionDiffLevelsA6,\nsimp add: correctCompositionDiffLevelsA7,\nsimp add: correctCompositionDiffLevelsA8,\nsimp add: correctCompositionDiffLevelsA9,\nsimp add: correctCompositionDiffLevelsA11,\nsimp add: correctCompositionDiffLevelsA12,\nsimp add: correctCompositionDiffLevelsA21,\nsimp add: correctCompositionDiffLevelsA22,\nsimp add: correctCompositionDiffLevelsA23,\nsimp add: correctCompositionDiffLevelsA31,\nsimp add: correctCompositionDiffLevelsA32,\nsimp add: correctCompositionDiffLevelsA41,\nsimp add: correctCompositionDiffLevelsA42,\nsimp add: correctCompositionDiffLevelsA71,\nsimp add: correctCompositionDiffLevelsA72,\nsimp add: correctCompositionDiffLevelsA81,\nsimp add: correctCompositionDiffLevelsA82,\nsimp add: correctCompositionDiffLevelsA91,\nsimp add: correctCompositionDiffLevelsA92,\nsimp add: correctCompositionDiffLevelsA93,\nsimp add: correctCompositionDiffLevelsS1,\nsimp add: correctCompositionDiffLevelsS2,\nsimp add: correctCompositionDiffLevelsS3,\nsimp add: correctCompositionDiffLevelsS4,\nsimp add: correctCompositionDiffLevelsS5,\nsimp add: correctCompositionDiffLevelsS6,\nsimp add: correctCompositionDiffLevelsS7,\nsimp add: correctCompositionDiffLevelsS8,\nsimp add: correctCompositionDiffLevelsS9,\nsimp add: correctCompositionDiffLevelsS10,\nsimp add: correctCompositionDiffLevelsS11,\nsimp add: correctCompositionDiffLevelsS12,\nsimp add: correctCompositionDiffLevelsS13,\nsimp add: correctCompositionDiffLevelsS14,\nsimp add: correctCompositionDiffLevelsS15,\nsimp add: correctCompositionDiffLevelsS1opt,\nsimp add: correctCompositionDiffLevelsS4opt,\nsimp add: correctCompositionDiffLevelsS7opt, \nsimp add: correctCompositionDiffLevelsS11opt)(*>*)\n\nlemma correctCompositionVARSYSTEM_holds:\n\"correctCompositionVARSYSTEM\"\nby (simp add: correctCompositionVARSYSTEM_def, clarify, case_tac S, (simp add: correctCompositionVAR_def)+)\n\nlemma correctDeCompositionVARSYSTEM_holds:\n\"correctDeCompositionVARSYSTEM\"\nby (simp add: correctDeCompositionVARSYSTEM_def, clarify, case_tac S, (simp add: correctDeCompositionVAR_def)+)\n\n\nsubsection \\<open>Correct specification of the relations between channels\\<close>\n\nlemma OUTfromChCorrect_data1: \"OUTfromChCorrect data1\"\nby (simp add: OUTfromChCorrect_def)\n\n\n\nlemma OUTfromChCorrect_data3: \"OUTfromChCorrect data3\"\nby (metis OUTfromCh.simps(3) OUTfromChCorrect_def)\n\nlemma OUTfromChCorrect_data4: \"OUTfromChCorrect data4\"\nby (metis IN.simps(2) OUT.simps(2) OUTfromCh.simps(4) OUTfromChCorrect_def insertI1 singleton_iff)\n\nlemma OUTfromChCorrect_data5: \"OUTfromChCorrect data5\"\nby  (simp add: OUTfromChCorrect_def, metis IN.simps(14) OUT.simps(14) insertI1)\n\nlemma OUTfromChCorrect_data6: \"OUTfromChCorrect data6\"\nby  (simp add: OUTfromChCorrect_def, metis IN.simps(15) OUT.simps(15) insertI1)\n\nlemma OUTfromChCorrect_data7: \"OUTfromChCorrect data7\"\nby (simp add: OUTfromChCorrect_def, metis IN.simps(16) OUT.simps(16) insertI1)\n\nlemma OUTfromChCorrect_data8: \"OUTfromChCorrect data8\"\nby (simp add: OUTfromChCorrect_def, metis IN.simps(18) OUT.simps(18) insertI1) \n\n \nlemma OUTfromChCorrect_data9: \"OUTfromChCorrect data9\"\nby (simp add: OUTfromChCorrect_def , metis IN.simps(33) OUT.simps(33) singleton_iff)\n\nlemma OUTfromChCorrect_data10: \"OUTfromChCorrect data10\"\nby (simp add: OUTfromChCorrect_def)\n\nlemma OUTfromChCorrect_data11: \"OUTfromChCorrect data11\"\nby (simp add: OUTfromChCorrect_def, metis (full_types) IN.simps(2) \nOUT.simps(2) OUT.simps(31) Un_empty_right Un_insert_left Un_insert_right insertI1)\n\nlemma OUTfromChCorrect_data12: \"OUTfromChCorrect data12\"\nby (simp add: OUTfromChCorrect_def)\n\nlemma OUTfromChCorrect_data13: \"OUTfromChCorrect data13\"\nby (simp add: OUTfromChCorrect_def)\n\nlemma OUTfromChCorrect_data14: \"OUTfromChCorrect data14\"\nby (metis OUTfromCh.simps(14) OUTfromChCorrect_def)\n\nlemma OUTfromChCorrect_data15: \"OUTfromChCorrect data15\"\nby (metis OUTfromCh.simps(15) OUTfromChCorrect_def)\n\nlemma OUTfromChCorrect_data16: \"OUTfromChCorrect data16\"\nby (metis OUTfromCh.simps(16) OUTfromChCorrect_def)\n\nlemma OUTfromChCorrect_data17: \"OUTfromChCorrect data17\"\nproof - \n  have \"data17 \\<in> OUT sA71 \\<and> data15 \\<in> IN sA71\"\n    by (metis IN.simps(19) OUT.simps(19) insertI1)  \n  thus ?thesis by (metis IN.simps(19) OUTfromCh.simps(17) OUTfromChCorrect_def) \nqed\n\nlemma OUTfromChCorrect_data18: \"OUTfromChCorrect data18\"\nby (simp add: OUTfromChCorrect_def, metis IN.simps(20) OUT.simps(20) insertI1)\n\nlemma OUTfromChCorrect_data19: \"OUTfromChCorrect data19\"\nby (metis OUTfromCh.simps(19) OUTfromChCorrect_def)\n\nlemma OUTfromChCorrect_data20: \"OUTfromChCorrect data20\"\nby  (simp add: OUTfromChCorrect_def, metis IN.simps(21) OUT.simps(21) insertI1 insert_subset subset_insertI)\n\nlemma OUTfromChCorrect_data21: \"OUTfromChCorrect data21\"\nby (simp add: OUTfromChCorrect_def, metis (full_types) \nIN.simps(22) OUT.simps(22) insertI1 insert_subset subset_insertI)\n\nlemma OUTfromChCorrect_data22: \"OUTfromChCorrect data22\"\nby (simp add: OUTfromChCorrect_def, metis (full_types) IN.simps(23) OUT.simps(23) insertI1)\n\nlemma OUTfromChCorrect_data23: \"OUTfromChCorrect data23\"\nby (simp add: OUTfromChCorrect_def, metis (full_types) IN.simps(9) OUT.simps(9) insert_subset subset_insertI)\n\nlemma OUTfromChCorrect_data24: \"OUTfromChCorrect data24\"\nby (simp add: OUTfromChCorrect_def, metis IN.simps(9) OUT.simps(9) insertI1 insert_subset subset_insertI)\n\nlemma OUTfromChCorrectSYSTEM_holds: \"OUTfromChCorrectSYSTEM\"\nby (simp add: OUTfromChCorrectSYSTEM_def,  clarify, case_tac x,\nsimp add: OUTfromChCorrect_data1, simp add: OUTfromChCorrect_data2, \nsimp add: OUTfromChCorrect_data3, simp add: OUTfromChCorrect_data4,  \nsimp add: OUTfromChCorrect_data5, simp add: OUTfromChCorrect_data6, \nsimp add: OUTfromChCorrect_data7, simp add: OUTfromChCorrect_data8,\nsimp add: OUTfromChCorrect_data9, simp add: OUTfromChCorrect_data10,\nsimp add: OUTfromChCorrect_data11, simp add: OUTfromChCorrect_data12,\nsimp add: OUTfromChCorrect_data13, simp add: OUTfromChCorrect_data14, \nsimp add: OUTfromChCorrect_data15, simp add: OUTfromChCorrect_data16,\nsimp add: OUTfromChCorrect_data17, simp add: OUTfromChCorrect_data18,\nsimp add: OUTfromChCorrect_data19, simp add: OUTfromChCorrect_data20,\nsimp add: OUTfromChCorrect_data21, simp add: OUTfromChCorrect_data22, \nsimp add: OUTfromChCorrect_data23, simp add: OUTfromChCorrect_data24)\n\nlemma OUTfromVCorrect1_data1: \"OUTfromVCorrect1 data1\"\nby (simp add: OUTfromVCorrect1_def)\n\nlemma OUTfromVCorrect1_data2: \"OUTfromVCorrect1 data2\"\nby (simp add: OUTfromVCorrect1_def)\n\nlemma OUTfromVCorrect1_data3: \"OUTfromVCorrect1 data3\"\nproof - \n  have \"data3 \\<in> OUT sA41 \\<and> stA4 \\<in> VAR sA41\"\n    by (metis OUT.simps(17) VAR.simps(17) insertI1) \n  thus ?thesis by (metis OUTfromV.simps(3) OUTfromVCorrect1_def VAR.simps(17)) \nqed\n\nlemma OUTfromVCorrect1_data4: \"OUTfromVCorrect1 data4\"\nby (simp add: OUTfromVCorrect1_def, metis (full_types) OUT.simps(2) VAR.simps(2) insertI1) \n\nlemma OUTfromVCorrect1_data5: \"OUTfromVCorrect1 data5\"\nby (simp add: OUTfromVCorrect1_def)\n\nlemma OUTfromVCorrect1_data6: \"OUTfromVCorrect1 data6\"\nby (simp add: OUTfromVCorrect1_def)\n\nlemma OUTfromVCorrect1_data7: \"OUTfromVCorrect1 data7\"\nby (simp add: OUTfromVCorrect1_def)\n\nlemma OUTfromVCorrect1_data8: \"OUTfromVCorrect1 data8\"\nby (simp add: OUTfromVCorrect1_def)\n\nlemma OUTfromVCorrect1_data9: \"OUTfromVCorrect1 data9\"\nby (simp add: OUTfromVCorrect1_def)\n\n\n\nlemma OUTfromVCorrect1_data11: \"OUTfromVCorrect1 data11\"\nby (simp add: OUTfromVCorrect1_def)\n\nlemma OUTfromVCorrect1_data12: \"OUTfromVCorrect1 data12\"\nproof - \n  have \"data12 \\<in> OUT sA22 \\<and> stA2 \\<in> VAR sA22\"\n    by (metis (full_types) OUT.simps(13) VAR.simps(13) insertCI) \n  thus ?thesis by (metis OUTfromV.simps(12) OUTfromVCorrect1_def VAR.simps(13)) \nqed\n\nlemma OUTfromVCorrect1_data13: \"OUTfromVCorrect1 data13\"\nby (simp add: OUTfromVCorrect1_def)\n\nlemma OUTfromVCorrect1_data14: \"OUTfromVCorrect1 data14\"\nby (simp add: OUTfromVCorrect1_def)\n\nlemma OUTfromVCorrect1_data15: \"OUTfromVCorrect1 data15\"\nproof -\n  have A6ch:\"data15 \\<in> OUT sA6 \\<and> stA6 \\<in> VAR sA6\"\n    by (metis OUT.simps(6) VAR.simps(6) insertI1) \n  thus ?thesis by (simp add: OUTfromVCorrect1_def, metis A6ch) \nqed\n\n\n\nlemma OUTfromVCorrect1_data17: \"OUTfromVCorrect1 data17\"\nby (simp add: OUTfromVCorrect1_def)\n\nlemma OUTfromVCorrect1_data18: \"OUTfromVCorrect1 data18\"\nby (simp add: OUTfromVCorrect1_def)\n\nlemma OUTfromVCorrect1_data19: \"OUTfromVCorrect1 data19\"\nby (simp add: OUTfromVCorrect1_def)\n\nlemma OUTfromVCorrect1_data20: \"OUTfromVCorrect1 data20\"\nby (simp add: OUTfromVCorrect1_def)\n\nlemma OUTfromVCorrect1_data21: \"OUTfromVCorrect1 data21\"\nby (simp add: OUTfromVCorrect1_def)\n\n\n\nlemma OUTfromVCorrect1_data23: \"OUTfromVCorrect1 data23\"\nby (simp add: OUTfromVCorrect1_def)\n\nlemma OUTfromVCorrect1_data24: \"OUTfromVCorrect1 data24\"\nby (simp add: OUTfromVCorrect1_def)\n\nlemma OUTfromVCorrect1SYSTEM_holds: \"OUTfromVCorrect1SYSTEM\"\nby (simp add: OUTfromVCorrect1SYSTEM_def, clarify, case_tac x, \nsimp add: OUTfromVCorrect1_data1, simp add: OUTfromVCorrect1_data2,\nsimp add: OUTfromVCorrect1_data3, simp add: OUTfromVCorrect1_data4, \nsimp add: OUTfromVCorrect1_data5, simp add: OUTfromVCorrect1_data6, \nsimp add: OUTfromVCorrect1_data7, simp add: OUTfromVCorrect1_data8, \nsimp add: OUTfromVCorrect1_data9, simp add: OUTfromVCorrect1_data10, \nsimp add: OUTfromVCorrect1_data11, simp add: OUTfromVCorrect1_data12, \nsimp add: OUTfromVCorrect1_data13, simp add: OUTfromVCorrect1_data14, \nsimp add: OUTfromVCorrect1_data15, simp add: OUTfromVCorrect1_data16, \nsimp add: OUTfromVCorrect1_data17, simp add: OUTfromVCorrect1_data18,\nsimp add: OUTfromVCorrect1_data19, simp add: OUTfromVCorrect1_data20,\nsimp add: OUTfromVCorrect1_data21, simp add: OUTfromVCorrect1_data22,\nsimp add: OUTfromVCorrect1_data23, simp add: OUTfromVCorrect1_data24)\n\nlemma OUTfromVCorrect2SYSTEM: \"OUTfromVCorrect2SYSTEM\"\nby (simp add: OUTfromVCorrect2SYSTEM_def, auto, case_tac x,\n      ((simp add: OUTfromVCorrect2_def, auto, case_tac v, auto) | \n       (simp add: OUTfromVCorrect2_def) )+)\n\nlemma OUTfromV_VARto_holds:\n\"OUTfromV_VARto\"\nby (simp add: OUTfromV_VARto_def, auto, (case_tac x, auto), (case_tac v, auto))\n\nlemma VARfromCorrectSYSTEM_holds:\n\"VARfromCorrectSYSTEM\"\nby (simp add: VARfromCorrectSYSTEM_def AbstrLevel0 AbstrLevel1)\n\nlemma VARtoCorrectSYSTEM_holds:\n\"VARtoCorrectSYSTEM\"\nby (simp add: VARtoCorrectSYSTEM_def AbstrLevel0 AbstrLevel1)\n\nlemma VARusefulSYSTEM_holds:\n\"VARusefulSYSTEM\"\nby (simp add: VARusefulSYSTEM_def, auto, case_tac v, auto)\n\n\nsubsection \\<open>Elementary components\\<close>\n\n\\<comment> \\<open>On the abstraction level 0 only the components sA5 and sA6 are elementary\\<close>\n\nlemma NOT_elementaryCompDD_sA1:  \"\\<not> elementaryCompDD sA1\" \nproof -\n  have \"outSetCorelated data2 \\<inter> outSetCorelated data10 = {}\"\n  by (metis OUTfromV.simps(2) inf_bot_left outSetCorelatedEmpty1) \n  thus ?thesis by (simp add: elementaryCompDD_def)\nqed\n\nlemma NOT_elementaryCompDD_sA2: \"\\<not> elementaryCompDD sA2\" \nproof -\n  have \"outSetCorelated data5 \\<inter> outSetCorelated data11 = {}\"\n  by (metis OUTfromV.simps(5) inf_bot_right inf_commute outSetCorelatedEmpty1)\n  thus ?thesis by (simp add: elementaryCompDD_def)\nqed \n\nlemma NOT_elementaryCompDD_sA3:  \"\\<not> elementaryCompDD sA3\" \nproof -\n  have \"outSetCorelated data6 \\<inter> outSetCorelated data7 = {}\"\n  by (metis OUTfromV.simps(7) inf_bot_right outSetCorelatedEmpty1) \n  thus ?thesis by (simp add: elementaryCompDD_def)\nqed\n\nlemma NOT_elementaryCompDD_sA4:  \"\\<not> elementaryCompDD sA4\" \nproof -\n  have \"outSetCorelated data3 \\<inter> outSetCorelated data8 = {}\"\n  by (metis OUTfromV.simps(8) inf_bot_left inf_commute outSetCorelatedEmpty1)\n  thus ?thesis by (simp add: elementaryCompDD_def)  \nqed\n\nlemma elementaryCompDD_sA5:  \"elementaryCompDD sA5\" \nby  (simp add: elementaryCompDD_def)\n\nlemma elementaryCompDD_sA6:  \"elementaryCompDD sA6\" \nproof -\n  have oSet15:\"outSetCorelated data15 \\<noteq> {}\" \n    by (simp add: outSetCorelated_def, auto)\n  have oSet16:\"outSetCorelated data16 \\<noteq> {}\"\n    by (simp add: outSetCorelated_def, auto)\n  have \"outSetCorelated data15 \\<inter> outSetCorelated data16 \\<noteq> {}\"\n    by (simp add: outSetCorelated_def, auto)\n  with oSet15 oSet16 show ?thesis by (simp add: elementaryCompDD_def, auto) \nqed\n\nlemma NOT_elementaryCompDD_sA7:  \"\\<not> elementaryCompDD sA7\" \nproof - \n  have \"outSetCorelated data17 \\<inter> outSetCorelated data18 = {}\"\n  by (metis (full_types) OUTfromV.simps(17) disjoint_iff_not_equal empty_iff outSetCorelatedEmpty1) \n  thus ?thesis by  (simp add: elementaryCompDD_def)\nqed\n\nlemma NOT_elementaryCompDD_sA8:  \"\\<not> elementaryCompDD sA8\" \nproof - \n  have \"outSetCorelated data20 \\<inter> outSetCorelated data21 = {}\"\n  by (metis OUTfromV.simps(21) inf_bot_right outSetCorelatedEmpty1)\n  thus ?thesis by  (simp add: elementaryCompDD_def)\nqed\n\nlemma NOT_elementaryCompDD_sA9:  \"\\<not> elementaryCompDD sA9\" \nproof - \n  have \"outSetCorelated data23 \\<inter> outSetCorelated data24 = {}\"\n  by (metis (full_types) OUTfromV.simps(23) disjoint_iff_not_equal empty_iff outSetCorelatedEmpty1)\n  thus ?thesis by  (simp add: elementaryCompDD_def)  \nqed\n\n\\<comment> \\<open>On the abstraction level 1 all components are elementary\\<close>\n\nlemma elementaryCompDD_sA11:  \"elementaryCompDD sA11\" \nby  (simp add: elementaryCompDD_def)\n\nlemma elementaryCompDD_sA12:  \"elementaryCompDD sA12\" \nby  (simp add: elementaryCompDD_def)\n\nlemma elementaryCompDD_sA21: \"elementaryCompDD sA21\" \nby  (simp add: elementaryCompDD_def)\n\nlemma elementaryCompDD_sA22: \"elementaryCompDD sA22\" \nproof - \n  have oSet4:\"outSetCorelated data4 \\<noteq> {}\"  \n    by (simp add: outSetCorelated_def, auto)\n  have oSet12:\"outSetCorelated data12 \\<noteq> {}\"  \n    by (simp add: outSetCorelated_def, auto)\n  have \"outSetCorelated data4 \\<inter> outSetCorelated data12 \\<noteq> {}\"\n    by (simp add: outSetCorelated_def, auto)\n  with oSet4 oSet12 show ?thesis \n    by  (simp add: elementaryCompDD_def, auto)\nqed \n\nlemma elementaryCompDD_sA23: \"elementaryCompDD sA23\" \nby  (simp add: elementaryCompDD_def)\n\nlemma elementaryCompDD_sA31: \"elementaryCompDD sA31\" \nby  (simp add: elementaryCompDD_def)\n\nlemma elementaryCompDD_sA32: \"elementaryCompDD sA32\" \nby  (simp add: elementaryCompDD_def)\n\n\nlemma elementaryCompDD_sA41: \"elementaryCompDD sA41\" \nby  (simp add: elementaryCompDD_def) \n\nlemma elementaryCompDD_sA42: \"elementaryCompDD sA42\" \nby  (simp add: elementaryCompDD_def)\n\nlemma elementaryCompDD_sA71: \"elementaryCompDD sA71\" \nby  (simp add: elementaryCompDD_def)\n\nlemma elementaryCompDD_sA72: \"elementaryCompDD sA72\" \nby  (simp add: elementaryCompDD_def)\n\nlemma elementaryCompDD_sA81: \"elementaryCompDD sA81\" \nby  (simp add: elementaryCompDD_def)\n\nlemma elementaryCompDD_sA82: \"elementaryCompDD sA82\" \nby  (simp add: elementaryCompDD_def)\n\nlemma elementaryCompDD_sA91: \"elementaryCompDD sA91\" \nby  (simp add: elementaryCompDD_def)\n\nlemma elementaryCompDD_sA92: \"elementaryCompDD sA92\" \nby  (simp add: elementaryCompDD_def)\n\nlemma elementaryCompDD_sA93: \"elementaryCompDD sA93\" \nby  (simp add: elementaryCompDD_def)\n\nsubsection \\<open>Source components\\<close>\n\n\\<comment> \\<open>Abstraction level 0\\<close>\n\nlemma A5_NotDSource_level0: \"isNotDSource level0 sA5\"\nby (simp add: isNotDSource_def, auto,  case_tac \"Z\", auto)\n\nlemma DSourcesA1_L0: \"DSources level0 sA1 = {}\"\nby (simp add: DSources_def, auto, case_tac \"x\", auto) \n\nlemma DSourcesA2_L0: \"DSources level0 sA2 = { sA1, sA4}\"\nby (simp add: DSources_def AbstrLevel0, auto) \n\nlemma DSourcesA3_L0: \"DSources level0 sA3 = { sA2 }\"\nby (simp add: DSources_def AbstrLevel0, auto) \n\nlemma DSourcesA4_L0: \"DSources level0 sA4 = { sA3 }\"\nby (simp add: DSources_def AbstrLevel0, auto) \n\nlemma DSourcesA5_L0: \"DSources level0 sA5 = { sA4 }\"\nby (simp add: DSources_def AbstrLevel0, auto)  \n\nlemma DSourcesA6_L0: \"DSources level0 sA6 = {}\"\nby (simp add: DSources_def, auto, case_tac \"x\", auto) \n\nlemma DSourcesA7_L0: \"DSources level0 sA7 = {sA6}\"\nby (simp add: DSources_def AbstrLevel0, auto) \n\nlemma DSourcesA8_L0: \"DSources level0 sA8 = {sA7, sA9}\"\nby (simp add: DSources_def AbstrLevel0, force)\n\nlemma DSourcesA9_L0: \"DSources level0 sA9 = {sA8}\"\nby (simp add: DSources_def AbstrLevel0, auto) \n\nlemma A1_DAcc_level0: \"DAcc level0 sA1 = { sA2 }\" \nby (simp add: DAcc_def  AbstrLevel0, auto)\n\nlemma A2_DAcc_level0: \"DAcc level0 sA2 = { sA3 }\" \nby (simp add: DAcc_def  AbstrLevel0, force)\n\nlemma A3_DAcc_level0: \"DAcc level0 sA3 = { sA4 }\" \nby (simp add: DAcc_def  AbstrLevel0, auto)\n\nlemma A4_DAcc_level0: \"DAcc level0 sA4 = { sA2, sA5 }\" \nby (simp add: DAcc_def  AbstrLevel0, auto)\n\nlemma A5_DAcc_level0: \"DAcc level0 sA5 = {}\" \nby (simp add: DAcc_def  AbstrLevel0, auto)\n\nlemma A6_DAcc_level0: \"DAcc level0 sA6 = { sA7 }\" \nby (simp add: DAcc_def  AbstrLevel0, auto)\n\nlemma A7_DAcc_level0: \"DAcc level0 sA7 = { sA8 }\" \nby (simp add: DAcc_def  AbstrLevel0, auto)\n\nlemma A8_DAcc_level0: \"DAcc level0 sA8 = { sA9 }\" \nby (simp add: DAcc_def  AbstrLevel0, auto)\n\nlemma A9_DAcc_level0: \"DAcc level0 sA9 = { sA8 }\" \nby (simp add: DAcc_def  AbstrLevel0, force)\n\nlemma A8_NSources:\n\"\\<forall> C \\<in> (AbstrLevel level0). (C \\<noteq> sA9 \\<and> C \\<noteq> sA8 \\<longrightarrow> sA8 \\<notin> (Sources level0 C))\"\nby (metis A8_DAcc_level0 A9_DAcc_level0 singleDSourceLoop)\n\nlemma A9_NSources:\n\"\\<forall> C \\<in> (AbstrLevel level0). (C \\<noteq> sA9 \\<and> C \\<noteq> sA8 \\<longrightarrow> sA9 \\<notin> (Sources level0 C))\"\nby (metis A8_DAcc_level0 A9_DAcc_level0 singleDSourceLoop)\n\nlemma A7_Acc:\n\"(Acc level0 sA7) = {sA8, sA9}\"\n  by (metis A7_DAcc_level0 A8_DAcc_level0 A9_DAcc_level0 AccDef AccSigleLoop insert_commute) \n\nlemma A7_NSources:\n\"\\<forall> C \\<in> (AbstrLevel level0). (C \\<noteq> sA9 \\<and> C \\<noteq> sA8 \\<longrightarrow> sA7 \\<notin> (Sources level0 C))\"\nby (metis A7_Acc Acc_Sources insert_iff singleton_iff)\n\nlemma A5_Acc: \"(Acc level0 sA5) = {}\"\nby (metis A5_NotDSource_level0 isNotDSource_EmptyAcc)\n\nlemma A6_Acc:\n\"(Acc level0 sA6) = {sA7, sA8, sA9}\"\nproof -\n  have daA6:  \"DAcc level0 sA6 = { sA7 }\"  by (rule A6_DAcc_level0)\n  hence \"(\\<Union> S \\<in> (DAcc level0 sA6). (Acc level0 S)) = (Acc level0 sA7)\"  by simp\n  hence aA6:\"(\\<Union> S \\<in> (DAcc level0 sA6). (Acc level0 S)) = { sA8, sA9 }\" by (simp add: A7_Acc)\n  have \"(Acc level0 sA6) = (DAcc level0 sA6) \\<union> (\\<Union> S \\<in> (DAcc level0 sA6). (Acc level0 S))\"  \n    by (rule AccDef)\n  with daA6 aA6 show ?thesis by auto\nqed\n\nlemma A6_NSources:\n\"\\<forall> C \\<in> (AbstrLevel level0). (C \\<noteq> sA9 \\<and> C \\<noteq> sA8 \\<and> C \\<noteq> sA7 \\<longrightarrow> sA6 \\<notin> (Sources level0 C))\"\nby (metis (full_types) A6_Acc A7_Acc Acc_SourcesNOT insert_iff singleton_iff)\n\nlemma SourcesA1_L0: \"Sources level0 sA1 = {}\"  \nby (simp add: DSourcesA1_L0 DSourcesEmptySources) \n     \nlemma SourcesA2_L0: \"Sources level0 sA2 = { sA1, sA2, sA3, sA4 }\"\nproof \n  show \"Sources level0 sA2 \\<subseteq> {sA1, sA2, sA3, sA4}\"\n  proof -\n    have A2level0:\"sA2 \\<in> (AbstrLevel level0)\" by (simp add: AbstrLevel0)\n    have sgA5:\"sA5 \\<notin> Sources level0 sA2\" \n      by (metis A5_NotDSource_level0 DSource_level NoDSourceNoSource \n            allNotDSource_NotSource isNotSource_Sources)\n     from A2level0 have sgA6:\"sA6 \\<notin> Sources level0 sA2\" by (simp add: A6_NSources)\n     from A2level0 have sgA7:\"sA7 \\<notin> Sources level0 sA2\" by (simp add: A7_NSources)\n     from A2level0 have sgA8:\"sA8 \\<notin> Sources level0 sA2\" by (simp add: A8_NSources)\n     from A2level0 have sgA9:\"sA9 \\<notin> Sources level0 sA2\" by (simp add: A9_NSources)\n     have \"Sources level0 sA2 \\<subseteq> {sA1, sA2, sA3, sA4, sA5, sA6, sA7, sA8, sA9}\"\n        by (metis AbstrLevel0 SourcesLevelX) \n     with sgA5 sgA6 sgA7 sgA8 sgA9 show \"Sources level0 sA2 \\<subseteq> {sA1, sA2, sA3, sA4}\"\n        by blast   \n  qed\nnext\n  show \"{sA1, sA2, sA3, sA4} \\<subseteq> Sources level0 sA2\"\n  proof -\n    have dsA4:\"{ sA3 } \\<subseteq> Sources level0 sA2\"\n       by (metis DSource_Sources DSourcesA2_L0 DSourcesA4_L0 \n             Sources_DSources insertI1 insert_commute subset_trans)\n    have \"{ sA2 } \\<subseteq> Sources level0 sA2\"\n      by (metis DSource_Sources DSourcesA2_L0 DSourcesA3_L0 \n             DSourcesA4_L0 Sources_DSources insertI1 \n             insert_commute subset_trans)\n    with dsA4 show \"{sA1, sA2, sA3, sA4} \\<subseteq> Sources level0 sA2\"\n       by (metis DSourcesA2_L0 Sources_DSources insert_subset)\n   qed\nqed\n        \nlemma SourcesA3_L0: \"Sources level0 sA3 = { sA1, sA2, sA3, sA4 }\"\nproof \n  show \"Sources level0 sA3 \\<subseteq> {sA1, sA2, sA3, sA4}\"\n  proof -\n    have a2:\"Sources level0 sA2 = { sA1, sA2, sA3, sA4}\" by (simp add: SourcesA2_L0)\n    have \"{ sA2 } \\<subseteq> DSources level0 sA3\" by (simp add: DSourcesA3_L0)\n    with a2 show \"Sources level0 sA3 \\<subseteq> {sA1, sA2, sA3, sA4}\"\n       by (metis DSource_Sources DSourcesA2_L0 DSourcesA4_L0 insertI1 insert_commute subset_trans)\n  qed\nnext\n   show \"{sA1, sA2, sA3, sA4} \\<subseteq> Sources level0 sA3\"\n   by (metis (full_types) DSource_Sources DSourcesA3_L0  SourcesA2_L0 insertI1)\nqed    \n             \nlemma SourcesA4_L0: \"Sources level0 sA4 = { sA1, sA2, sA3, sA4 }\"\nproof -\n  have  A3s:\"Sources level0 sA3 = { sA1, sA2, sA3, sA4 }\" by (rule  SourcesA3_L0)\n  have  \"Sources level0 sA4 = {sA3} \\<union> Sources level0 sA3\"\n    by (metis DSourcesA4_L0 Sources_singleDSource) \n  with A3s show ?thesis by auto\nqed  \n\nlemma SourcesA5_L0: \"Sources level0 sA5 = { sA1, sA2, sA3, sA4 }\"\nproof -  \n  have  A4s:\"Sources level0 sA4 = { sA1, sA2, sA3, sA4 }\" by (rule  SourcesA4_L0)\n  have  \"Sources level0 sA5 = {sA4} \\<union> Sources level0 sA4\"\n    by (metis DSourcesA5_L0 Sources_singleDSource) \n  with A4s show ?thesis by auto\nqed  \n\nlemma SourcesA6_L0: \"Sources level0 sA6 = {}\"  \nby (simp add: DSourcesA6_L0 DSourcesEmptySources) \n\nlemma SourcesA7_L0: \"Sources level0 sA7 = { sA6 }\"  \nby (metis DSourcesA7_L0 SourcesA6_L0 SourcesEmptyDSources SourcesOnlyDSources singleton_iff)\n\n \n\n\nlemma SourcesA9_L0: \"Sources level0 sA9 = { sA6, sA7, sA8, sA9 }\"  \nproof - \n  have \"(Sources level0 sA9) = (DSources level0 sA9) \\<union> (\\<Union> S \\<in> (DSources level0 sA9). (Sources level0 S))\" \n    by (rule SourcesDef)\n  hence sourcesA9:\"(Sources level0 sA9) = ({sA8} \\<union> (Sources level0 sA8))\" \n    by (simp add:  DSourcesA9_L0)\n   thus ?thesis  by (metis SourcesA8_L0 Un_insert_right insert_absorb2 insert_is_Un) \nqed\n \n\n\\<comment> \\<open>Abstraction level 1\\<close>\n\nlemma A12_NotSource_level1: \"isNotDSource level1 sA12\"\nby (simp add: isNotDSource_def, auto,  case_tac \"Z\", auto)\n\nlemma A21_NotSource_level1: \"isNotDSource level1 sA21\"\nby (simp add: isNotDSource_def, auto,  case_tac \"Z\", auto)\n\nlemma A5_NotSource_level1: \"isNotDSource level1 sA5\"\nby (simp add: isNotDSource_def, auto,  case_tac \"Z\", auto)\n\nlemma A92_NotSource_level1: \"isNotDSource level1 sA92\"\nby (simp add: isNotDSource_def, auto,  case_tac \"Z\", auto)\n\nlemma A93_NotSource_level1: \"isNotDSource level1 sA93\"\nby (simp add: isNotDSource_def, auto,  case_tac \"Z\", auto)\n\n\nlemma A11_DAcc_level1: \"DAcc level1 sA11 = { sA21, sA22, sA23 }\" \nby (simp add: DAcc_def  AbstrLevel1, auto)\n\nlemma A12_DAcc_level1: \"DAcc level1 sA12 = {}\" \nby (simp add: DAcc_def  AbstrLevel1, auto)\n\nlemma A21_DAcc_level1: \"DAcc level1 sA21 = {}\" \nby (simp add: DAcc_def  AbstrLevel1, auto)\n\nlemma A22_DAcc_level1: \"DAcc level1 sA22 = {sA31}\" \nby (simp add: DAcc_def  AbstrLevel1, auto)\n\nlemma A23_DAcc_level1: \"DAcc level1 sA23 = {sA32}\" \nby (simp add: DAcc_def  AbstrLevel1, auto)\n\nlemma A31_DAcc_level1: \"DAcc level1 sA31 = {sA41}\" \nby (simp add: DAcc_def  AbstrLevel1, auto)\n\nlemma A32_DAcc_level1: \"DAcc level1 sA32 = {sA41}\" \nby (simp add: DAcc_def  AbstrLevel1, auto)\n\nlemma A41_DAcc_level1: \"DAcc level1 sA41 = {sA22}\" \nby (simp add: DAcc_def  AbstrLevel1, auto)\n\nlemma A42_DAcc_level1: \"DAcc level1 sA42 = {sA5}\" \nby (simp add: DAcc_def  AbstrLevel1, auto)\n\nlemma A5_DAcc_level1: \"DAcc level1 sA5 = {}\" \nby (simp add: DAcc_def  AbstrLevel1, auto)\n\nlemma A6_DAcc_level1: \"DAcc level1 sA6 = {sA71, sA72}\" \nby (simp add: DAcc_def  AbstrLevel1, auto)\n\nlemma A71_DAcc_level1: \"DAcc level1 sA71 = {sA81}\" \nby (simp add: DAcc_def  AbstrLevel1, auto)\n\nlemma A72_DAcc_level1: \"DAcc level1 sA72 = {sA82}\" \nby (simp add: DAcc_def  AbstrLevel1, auto)\n\nlemma A81_DAcc_level1: \"DAcc level1 sA81 = {sA91, sA92}\" \nby (simp add: DAcc_def  AbstrLevel1, auto)\n\nlemma A82_DAcc_level1: \"DAcc level1 sA82 = {sA93}\" \nby (simp add: DAcc_def  AbstrLevel1, auto)\n\nlemma A91_DAcc_level1: \"DAcc level1 sA91 = {sA81}\" \nby (simp add: DAcc_def  AbstrLevel1, auto)\n\nlemma A92_DAcc_level1: \"DAcc level1 sA92 = {}\" \nby (simp add: DAcc_def  AbstrLevel1, auto)\n\nlemma A93_DAcc_level1: \"DAcc level1 sA93 = {}\" \nby (simp add: DAcc_def  AbstrLevel1, auto)\n\nlemma A42_NSources_L1:\n\"\\<forall> C \\<in> (AbstrLevel level1). C \\<noteq> sA5 \\<longrightarrow> sA42 \\<notin> (Sources level1 C)\"\nby (metis A42_DAcc_level1 A5_NotSource_level1 singleDSourceEmpty4isNotSource)\n\nlemma A5_NotSourceSet_level1 :\n\"\\<forall> C  \\<in> (AbstrLevel level1). sA5 \\<notin> (Sources level1 C)\"\nby (metis A5_NotSource_level1 isNotSource_Sources)\n\nlemma A92_NotSourceSet_level1 :\n\"\\<forall> C  \\<in> (AbstrLevel level1). sA92 \\<notin> (Sources level1 C)\" \nby (metis A92_NotSource_level1 isNotSource_Sources)\n\nlemma A93_NotSourceSet_level1 :\n\"\\<forall> C  \\<in> (AbstrLevel level1). sA93 \\<notin> (Sources level1 C)\" \nby (metis A93_NotSource_level1 isNotSource_Sources)\n\n\nlemma DSourcesA11_L1: \"DSources level1 sA11 = {}\"\nby (simp add: DSources_def, auto, case_tac \"x\", auto) \n\nlemma DSourcesA12_L1: \"DSources level1 sA12 = {}\"\nby (simp add: DSources_def AbstrLevel1, auto) \n\nlemma DSourcesA21_L1: \"DSources level1 sA21 = {sA11}\"\nby (simp add: DSources_def AbstrLevel1, auto) \n\nlemma DSourcesA22_L1: \"DSources level1 sA22 = {sA11, sA41}\"\nby (simp add: DSources_def AbstrLevel1, auto) \n\nlemma DSourcesA23_L1: \"DSources level1 sA23 = {sA11}\"\nby (simp add: DSources_def AbstrLevel1, auto) \n\nlemma DSourcesA31_L1: \"DSources level1 sA31 = { sA22 }\"\nby (simp add: DSources_def AbstrLevel1, auto) \n\nlemma DSourcesA32_L1: \"DSources level1 sA32 = { sA23 }\"\nby (simp add: DSources_def AbstrLevel1, auto) \n\nlemma DSourcesA41_L1: \"DSources level1 sA41 = { sA31, sA32 }\"\nby (simp add: DSources_def AbstrLevel1, auto) \n\nlemma DSourcesA42_L1: \"DSources level1 sA42 = {}\"\nby (simp add: DSources_def AbstrLevel1, auto) \n\nlemma DSourcesA5_L1: \"DSources level1 sA5 = { sA42 }\"\nby (simp add: DSources_def AbstrLevel1, auto)  \n\nlemma DSourcesA6_L1: \"DSources level1 sA6 = {}\"\nby (simp add: DSources_def AbstrLevel1, auto)  \n\nlemma DSourcesA71_L1: \"DSources level1 sA71 = { sA6 }\"\nby (simp add: DSources_def AbstrLevel1, auto)  \n\nlemma DSourcesA72_L1: \"DSources level1 sA72 = { sA6 }\"\nby (simp add: DSources_def AbstrLevel1, auto)  \n\nlemma DSourcesA81_L1: \"DSources level1 sA81 = { sA71, sA91 }\"\nby (simp add: DSources_def AbstrLevel1, auto)  \n\nlemma DSourcesA82_L1: \"DSources level1 sA82 = { sA72 }\"\nby (simp add: DSources_def AbstrLevel1, auto)  \n\nlemma DSourcesA91_L1: \"DSources level1 sA91 = { sA81 }\"\nby (simp add: DSources_def AbstrLevel1, auto)  \n\nlemma DSourcesA92_L1: \"DSources level1 sA92 = { sA81 }\"\nby (simp add: DSources_def AbstrLevel1, auto)  \n\nlemma DSourcesA93_L1: \"DSources level1 sA93 = { sA82 }\"\nby (simp add: DSources_def AbstrLevel1, auto)  \n\nlemma A82_Acc: \"(Acc level1 sA82) = {sA93}\"\nby (metis A82_DAcc_level1 A93_NotSource_level1 singleDSourceEmpty_Acc) \n\nlemma A82_NSources_L1:\n\"\\<forall> C \\<in> (AbstrLevel level1). (C \\<noteq> sA93 \\<longrightarrow> sA82 \\<notin> (Sources level1 C))\"\nby (metis A82_Acc Acc_Sources singleton_iff) \n\nlemma A72_Acc: \"(Acc level1 sA72) = {sA82, sA93}\"\nproof -\n  have daA72:  \"DAcc level1 sA72 = { sA82 }\"  by (rule A72_DAcc_level1)\n  hence \"(\\<Union> S \\<in> (DAcc level1 sA72). (Acc level1 S)) = (Acc level1 sA82)\"  by simp\n  hence aA72:\"(\\<Union> S \\<in> (DAcc level1 sA72). (Acc level1 S)) = { sA93 }\" by (simp add: A82_Acc)\n  have \"(Acc level1 sA72) = (DAcc level1 sA72) \\<union> (\\<Union> S \\<in> (DAcc level1 sA72). (Acc level1 S))\"  \n    by (rule AccDef)\n  with daA72 aA72 show ?thesis by auto\nqed\n\nlemma A72_NSources_L1:\n\"\\<forall> C \\<in> (AbstrLevel level1). (C \\<noteq> sA93 \\<and> C \\<noteq> sA82 \\<longrightarrow> sA72 \\<notin> (Sources level1 C))\"\nby (metis A72_Acc Acc_Sources insert_iff singleton_iff) \n\nlemma A92_Acc: \"(Acc level1 sA92) = {}\"\nby (metis A92_NotSource_level1 isNotDSource_EmptyAcc)\n\nlemma A92_NSources_L1:\n\"\\<forall> C \\<in> (AbstrLevel level1). (sA92 \\<notin> (Sources level1 C))\"\nby (metis A92_NotSourceSet_level1)\n \nlemma A91_Acc: \"(Acc level1 sA91) = {sA81, sA91, sA92}\"\nproof -\n  have da91:  \"DAcc level1 sA91 = { sA81 }\"  by (rule A91_DAcc_level1)\n  hence a91:\"(\\<Union> S \\<in> (DAcc level1 sA91). (Acc level1 S)) = (Acc level1 sA81)\"  by simp\n  have \"(Acc level1 sA91) = (DAcc level1 sA91) \\<union> (\\<Union> S \\<in> (DAcc level1 sA91). (Acc level1 S))\"  by (rule AccDef)\n  with da91 a91 have acc91:\"(Acc level1 sA91) = { sA81 } \\<union> (Acc level1 sA81)\" by simp\n  have da81:  \"DAcc level1 sA81 = { sA91, sA92 }\"  by (rule A81_DAcc_level1)\n  hence a81:\"(\\<Union> S \\<in> (DAcc level1 sA81). (Acc level1 S)) = (Acc level1 sA92) \\<union> (Acc level1 sA91)\"  by auto\n  have \"(Acc level1 sA81) = (DAcc level1 sA81) \\<union> (\\<Union> S \\<in> (DAcc level1 sA81). (Acc level1 S))\"  by (rule AccDef)\n  with da81 a81 have acc81: \"(Acc level1 sA81) = { sA91, sA92 }  \\<union> (Acc level1 sA91)\"\n    by (metis A92_Acc sup_bot.left_neutral)\n  from acc91 acc81 have \"(Acc level1 sA91) = { sA81 } \\<union> { sA91, sA92 }  \\<union> {sA91, sA81}\"\n   by (metis AccLoop)\n  thus ?thesis by auto\nqed\n\nlemma A91_NSources_L1:\n\"\\<forall> C \\<in> (AbstrLevel level1). (C \\<noteq> sA92 \\<and> C \\<noteq> sA91 \\<and> C \\<noteq> sA81 \\<longrightarrow> sA91 \\<notin> (Sources level1 C))\"\nproof -\n  have \"\\<forall> C \\<in> (AbstrLevel level1). (C \\<noteq> sA92 \\<and> C \\<noteq> sA91 \\<and> C \\<noteq> sA81  \\<longrightarrow> (C \\<notin> (Acc level1 sA91)))\"\n    by (metis A91_Acc insert_iff singleton_iff)\n  thus ?thesis  by (metis Acc_SourcesNOT) \nqed\n\nlemma A81_Acc: \"(Acc level1 sA81) = {sA81, sA91, sA92}\"\nproof -\n  have da91:  \"DAcc level1 sA91 = { sA81 }\"  by (rule A91_DAcc_level1)\n  hence a91:\"(\\<Union> S \\<in> (DAcc level1 sA91). (Acc level1 S)) = (Acc level1 sA81)\"  by simp\n  have \"(Acc level1 sA91) = (DAcc level1 sA91) \\<union> (\\<Union> S \\<in> (DAcc level1 sA91). (Acc level1 S))\"  by (rule AccDef)\n  with da91 a91 have acc91:\"(Acc level1 sA91) = { sA81 } \\<union> (Acc level1 sA81)\" by simp\n  have da81:  \"DAcc level1 sA81 = { sA91, sA92 }\"  by (rule A81_DAcc_level1)\n  hence a81:\"(\\<Union> S \\<in> (DAcc level1 sA81). (Acc level1 S)) = (Acc level1 sA92) \\<union> (Acc level1 sA91)\"  by auto\n  have \"(Acc level1 sA81) = (DAcc level1 sA81) \\<union> (\\<Union> S \\<in> (DAcc level1 sA81). (Acc level1 S))\"  by (rule AccDef)\n  with da81 a81 have acc81: \"(Acc level1 sA81) = { sA91, sA92 }  \\<union> (Acc level1 sA91)\"\n    by (metis A92_Acc sup_bot.left_neutral)\n  from acc81 acc91 have \"(Acc level1 sA81) =  { sA91, sA92 }  \\<union> { sA81 } \\<union> {sA81, sA91}\"\n   by (metis AccLoop)\n  thus ?thesis by auto\nqed\n\nlemma A81_NSources_L1:\n\"\\<forall> C \\<in> (AbstrLevel level1). (C \\<noteq> sA92 \\<and> C \\<noteq> sA91 \\<and> C \\<noteq> sA81 \\<longrightarrow> sA81 \\<notin> (Sources level1 C))\"\nproof -\n  have \"\\<forall> C \\<in> (AbstrLevel level1). (C \\<noteq> sA92 \\<and> C \\<noteq> sA91 \\<and> C \\<noteq> sA81  \\<longrightarrow> (C \\<notin> (Acc level1 sA81)))\"\n    by (metis A81_Acc insert_iff singleton_iff)\n  thus ?thesis  by (metis Acc_SourcesNOT) \nqed\n\nlemma A71_Acc: \"(Acc level1 sA71) = {sA81, sA91, sA92}\"\nproof -\n  have da71:  \"DAcc level1 sA71 = { sA81 }\"  by (rule A71_DAcc_level1)\n  hence a71:\"(\\<Union> S \\<in> (DAcc level1 sA71). (Acc level1 S)) = (Acc level1 sA81)\"  by simp\n  have \"(Acc level1 sA71) = (DAcc level1 sA71) \\<union> (\\<Union> S \\<in> (DAcc level1 sA71). (Acc level1 S))\"  by (rule AccDef)\n  with da71 a71 show ?thesis by (metis A91_Acc A91_DAcc_level1 AccDef) \nqed\n\nlemma A71_NSources_L1:\n\"\\<forall> C \\<in> (AbstrLevel level1). (C \\<noteq> sA92 \\<and> C \\<noteq> sA91 \\<and> C \\<noteq> sA81 \\<longrightarrow> sA71 \\<notin> (Sources level1 C))\"\nproof -\n  have \"\\<forall> C \\<in> (AbstrLevel level1). (C \\<noteq> sA92 \\<and> C \\<noteq> sA91 \\<and> C \\<noteq> sA81  \\<longrightarrow> (C \\<notin> (Acc level1 sA71)))\"\n    by (metis A71_Acc insert_iff singleton_iff)\n  thus ?thesis  by (metis Acc_SourcesNOT) \nqed\n\nlemma A6_Acc_L1:\n\"(Acc level1 sA6) = {sA71, sA72, sA81, sA82, sA91, sA92, sA93}\"\nproof -\n  have daA6:  \"DAcc level1 sA6 = { sA71, sA72 }\"  by (rule A6_DAcc_level1)\n  hence \"(\\<Union> S \\<in> (DAcc level1 sA6). (Acc level1 S)) = (Acc level1 sA71) \\<union> (Acc level1 sA72)\"  by simp\n  hence aA6:\"(\\<Union> S \\<in> (DAcc level1 sA6). (Acc level1 S)) = {sA81, sA91, sA92} \\<union> {sA82, sA93}\" \n    by (simp add: A71_Acc A72_Acc)\n  have \"(Acc level1 sA6) = (DAcc level1 sA6) \\<union> (\\<Union> S \\<in> (DAcc level1 sA6). (Acc level1 S))\"  \n    by (rule AccDef)\n  with daA6 aA6 show ?thesis by auto\nqed\n\nlemma A6_NSources_L1Acc:\n\"\\<forall> C \\<in> (AbstrLevel level1). (C \\<notin> (Acc level1 sA6) \\<longrightarrow> sA6 \\<notin> (Sources level1 C))\"\nby (metis Acc_SourcesNOT)\n\n\nlemma A6_NSources_L1:\n\"\\<forall> C \\<in> (AbstrLevel level1). (C \\<noteq> sA93 \\<and> C \\<noteq> sA92 \\<and> C \\<noteq> sA91 \\<and> C \\<noteq> sA82  \\<and> C \\<noteq> sA81 \\<and> C \\<noteq> sA72 \\<and> C \\<noteq> sA71 \n\\<longrightarrow> sA6 \\<notin> (Sources level1 C))\"\nproof -\n  have \"\\<forall> C \\<in> (AbstrLevel level1). \n  (C \\<noteq> sA93 \\<and> C \\<noteq> sA92 \\<and> C \\<noteq> sA91 \\<and> C \\<noteq> sA82  \\<and> C \\<noteq> sA81 \\<and> C \\<noteq> sA72 \\<and> C \\<noteq> sA71 \n  \\<longrightarrow> (C \\<notin> (Acc level1 sA6)))\"\n     by (metis A6_Acc_L1 empty_iff insert_iff)\n  thus ?thesis  by (metis Acc_SourcesNOT) \nqed\n\nlemma A5_Acc_L1: \"(Acc level1 sA5) = {}\"\nby (metis A5_NotSource_level1 isNotDSource_EmptyAcc)\n\n\nlemma SourcesA11_L1: \"Sources level1 sA11 = {}\"  \nby (simp add: DSourcesA11_L1 DSourcesEmptySources) \n\nlemma SourcesA12_L1: \"Sources level1 sA12 = {}\"  \nby (simp add: DSourcesA12_L1  DSourcesEmptySources) \n\nlemma SourcesA21_L1: \"Sources level1 sA21 = {sA11}\"\nby (simp add: DSourcesA21_L1 SourcesA11_L1  Sources_singleDSource) \n\nlemma SourcesA22_L1: \"Sources level1 sA22 = {sA11, sA22,  sA23, sA31, sA32, sA41}\"\nproof\n  show \"Sources level1 sA22 \\<subseteq> {sA11, sA22, sA23, sA31, sA32, sA41}\"\n  proof -\n     have A2level1:\"sA22 \\<in> (AbstrLevel level1)\" by (simp add: AbstrLevel1)\n     from A2level1 have sgA42:\"sA42 \\<notin> Sources level1 sA22\" by (metis A42_NSources_L1 CSet.distinct(347)) \n     have sgA5:\"sA5 \\<notin> Sources level1 sA22\"\n     by (metis A5_NotSource_level1 Acc_Sources all_not_in_conv isNotDSource_EmptyAcc)  \n     have sgA12:\"sA12 \\<notin> Sources level1 sA22\" by (metis A12_NotSource_level1 A2level1 isNotSource_Sources)   \n     have sgA21:\"sA21 \\<notin> Sources level1 sA22\"\n     by (metis A21_NotSource_level1 DAcc_DSourcesNOT NDSourceExistsDSource empty_iff isNotDSource_EmptyDAcc)\n     from A2level1 have sgA6:\"sA6 \\<notin> Sources level1 sA22\" by (simp add: A6_NSources_L1)\n     from A2level1 have sgA71:\"sA71 \\<notin> Sources level1 sA22\" by (simp add: A71_NSources_L1)\n     from A2level1 have sgA72:\"sA72 \\<notin> Sources level1 sA22\" by (simp add: A72_NSources_L1)\n     from A2level1 have sgA81:\"sA81 \\<notin> Sources level1 sA22\" by (simp add: A81_NSources_L1)\n     from A2level1 have sgA82:\"sA82 \\<notin> Sources level1 sA22\" by (simp add: A82_NSources_L1)\n     from A2level1 have sgA91:\"sA91 \\<notin> Sources level1 sA22\" by (simp add: A91_NSources_L1)\n     from A2level1 have sgA92:\"sA92 \\<notin> Sources level1 sA22\" by (simp add: A92_NSources_L1) \n     from A2level1 have sgA93:\"sA93 \\<notin> Sources level1 sA22\" by (metis A93_NotSourceSet_level1)  \n     have \"Sources level1 sA22 \\<subseteq> {sA11, sA12, sA21, sA22, sA23, sA31, sA32, \n        sA41, sA42, sA5, sA6, sA71, sA72, sA81, sA82, sA91, sA92, sA93}\"\n        by (metis AbstrLevel1 SourcesLevelX) \n     with sgA5 sgA12 sgA21 sgA42 sgA6 sgA71 sgA72 sgA81 sgA82 sgA91 sgA92 sgA93 show \n     \"Sources level1 sA22 \\<subseteq> {sA11, sA22, sA23, sA31, sA32, sA41}\"\n         by auto \n    qed\nnext \n  show \"{sA11, sA22, sA23, sA31, sA32, sA41} \\<subseteq> Sources level1 sA22\" \n  proof - \n    have sDef:\"(Sources level1 sA22) = (DSources level1 sA22) \\<union> (\\<Union> S \\<in> (DSources level1 sA22). (Sources level1 S))\" \n       by (rule SourcesDef) \n    have A11s: \"sA11 \\<in> Sources level1 sA22\" by (metis DSourceIsSource DSourcesA22_L1 insertI1)  \n    have A41s: \"sA41 \\<in> Sources level1 sA22\" by (metis (full_types) DSourceIsSource DSourcesA22_L1 insertCI)\n    have A31s: \"sA31 \\<in> Sources level1 sA22\" \n      by (metis (full_types) A41s DSourceIsSource DSourcesA41_L1 SourcesTrans insertCI)\n    have A32s: \"sA32 \\<in> Sources level1 sA22\"\n      by (metis A32_DAcc_level1 A41s DAcc_DSourcesNOT DSourceOfSource insertI1)\n    have A23s: \"sA23 \\<in> Sources level1 sA22\"  by (metis A32s DSourceOfSource DSourcesA32_L1 insertI1)\n    have A22s: \"sA22 \\<in> Sources level1 sA22\"  by (metis A31s DSourceOfSource DSourcesA31_L1 insertI1)\n    with A11s A22s A23s A31s A32s A41s show ?thesis by auto\n    qed\nqed \n\nlemma SourcesA23_L1: \"Sources level1 sA23 = {sA11}\"\nby (simp add: DSourcesA23_L1 SourcesA11_L1  Sources_singleDSource)  \n\nlemma SourcesA31_L1: \"Sources level1 sA31 = {sA11, sA22, sA23, sA31, sA32, sA41}\"\nby (metis DSourcesA31_L1 SourcesA22_L1 Sources_singleDSource Un_insert_right insert_absorb2 insert_is_Un)\n\nlemma SourcesA32_L1: \"Sources level1 sA32 = {sA11, sA23}\"\nby (metis DSourcesA32_L1 SourcesA23_L1 Sources_singleDSource Un_insert_right insert_is_Un)\n \nlemma SourcesA41_L1: \"Sources level1 sA41 = {sA11, sA22, sA23, sA31, sA32, sA41}\"\nby (metis DSourcesA41_L1 SourcesA31_L1 SourcesA32_L1 Sources_2DSources Un_absorb Un_commute Un_insert_left)\n\nlemma SourcesA42_L1: \"Sources level1 sA42 = {}\"  \nby (simp add: DSourcesA42_L1  DSourcesEmptySources) \n\nlemma SourcesA5_L1: \"Sources level1 sA5 = {sA42}\"\nby (simp add: DSourcesA5_L1 SourcesA42_L1  Sources_singleDSource) \n\nlemma SourcesA6_L1: \"Sources level1 sA6 = {}\"  \nby (simp add: DSourcesA6_L1 DSourcesEmptySources) \n\nlemma SourcesA71_L1: \"Sources level1 sA71 = {sA6}\"\nby (metis DSourcesA71_L1 SourcesA6_L1 SourcesEmptyDSources SourcesOnlyDSources singleton_iff)   \n\nlemma SourcesA81_L1: \"Sources level1 sA81 = {sA6, sA71, sA81, sA91}\"  \nproof - \n  have  dA81:\"DSources level1 sA81 = {sA71, sA91}\" by (rule DSourcesA81_L1)\n  have  dA91:\"DSources level1 sA91 = {sA81}\" by (rule DSourcesA91_L1)\n  have \"(Sources level1 sA81) = (DSources level1 sA81) \\<union> (\\<Union> S \\<in> (DSources level1 sA81). (Sources level1 S))\" \n    by (rule SourcesDef)\n  with dA81 have  \"(Sources level1 sA81) = ({sA71, sA91} \\<union> (Sources level1 sA71) \\<union> (Sources level1 sA91))\"\n    by (metis (hide_lams, no_types) SUP_empty UN_insert Un_insert_left sup_bot.left_neutral sup_commute)\n  hence sourcesA81:\"(Sources level1 sA81) = ({sA71, sA91, sA6} \\<union> (Sources level1 sA91))\"\n    by (metis SourcesA71_L1 insert_is_Un sup_assoc)\n  have \"(Sources level1 sA91) = (DSources level1 sA91) \\<union> (\\<Union> S \\<in> (DSources level1 sA91). (Sources level1 S))\" \n    by (rule SourcesDef)\n  with dA91 have \"(Sources level1 sA91) = ({sA81} \\<union> (Sources level1 sA81))\"  by simp\n  with sourcesA81 have \"(Sources level1 sA81) = {sA71, sA91, sA6} \\<union> {sA81} \\<union> {sA81, sA91}\"\n    by (metis SourcesLoop)  \n  thus  ?thesis by auto\nqed\n\n(*lemma Sources_singleDSource:\n  assumes \"DSources i S = {C}\" \n  shows    \"Sources i S = {C} \\<union> Sources i C\" *)\nlemma SourcesA91_L1: \"Sources level1 sA91 = {sA6, sA71, sA81, sA91}\"\nproof -\n  have  \"DSources level1 sA91 = {sA81}\" by (rule DSourcesA91_L1)\n  thus ?thesis by (metis SourcesA81_L1 Sources_singleDSource \n          Un_empty_left Un_insert_left insert_absorb2 insert_commute) \nqed\n\nlemma SourcesA92_L1: \"Sources level1 sA92 = {sA6, sA71, sA81, sA91}\"\nby (metis DSourcesA91_L1 DSourcesA92_L1 SourcesA91_L1 Sources_singleDSource) \n\nlemma SourcesA72_L1: \"Sources level1 sA72 = {sA6}\"\nby (metis DSourcesA6_L1 DSourcesA72_L1 SourcesOnlyDSources singleton_iff)   \n\nlemma SourcesA82_L1: \"Sources level1 sA82 = {sA6, sA72}\"  \nproof - \n  have  dA82:\"DSources level1 sA82 = {sA72}\" by (rule DSourcesA82_L1)\n  have \"(Sources level1 sA82) = (DSources level1 sA82) \\<union> (\\<Union> S \\<in> (DSources level1 sA82). (Sources level1 S))\" \n    by (rule SourcesDef)\n  with dA82 have \"(Sources level1 sA82) =  {sA72} \\<union> (Sources level1 sA72)\"  by simp\n  thus ?thesis by (metis SourcesA72_L1 Un_commute insert_is_Un) \nqed\n\nlemma SourcesA93_L1: \"Sources level1 sA93 = {sA6, sA72, sA82}\"\nby (metis DSourcesA93_L1 SourcesA82_L1 Sources_singleDSource Un_insert_right insert_is_Un)   \n\n\n\\<comment> \\<open>Abstraction level 2\\<close>\n\nlemma SourcesS1_L2: \"Sources level2 sS1 = {}\"\nproof -\n  have \"DSources level2 sS1 = {}\"  by (simp add: DSources_def AbstrLevel2, auto)\n  thus ?thesis  by (simp add: DSourcesEmptySources)\nqed\n\nlemma SourcesS2_L2: \"Sources level2 sS2 = {}\"\nproof -\n  have \"DSources level2 sS2 = {}\"  by (simp add: DSources_def AbstrLevel2, auto)\n  thus ?thesis  by (simp add: DSourcesEmptySources)\nqed\n\nlemma SourcesS3_L2: \"Sources level2 sS3 = {sS2}\"\nproof -\n  have DSourcesS3:\"DSources level2 sS3 = {sS2}\"  by (simp add: DSources_def AbstrLevel2, auto)\n  have \"Sources level2 sS2 = {}\"  by (rule SourcesS2_L2)\n  with DSourcesS3 show ?thesis  by  (simp add: Sources_singleDSource)\nqed\n\nlemma SourcesS4_L2:  \"Sources level2 sS4 = {sS2}\"\nproof -\n  have DSourcesS4:\"DSources level2 sS4 = {sS2}\" by (simp add: DSources_def AbstrLevel2, auto)\n  have \"Sources level2 sS2 = {}\"  by (rule SourcesS2_L2)\n  with DSourcesS4 show ?thesis  by  (simp add: Sources_singleDSource)\nqed\n\nlemma SourcesS5_L2:  \"Sources level2 sS5 = {sS2, sS4}\"\nproof -\n  have DSourcesS5:\"DSources level2 sS5 = {sS4}\"  by (simp add: DSources_def AbstrLevel2, auto)\n  have \"Sources level2 sS4 = {sS2}\" by (rule SourcesS4_L2)\n  with DSourcesS5 show ?thesis  by  (simp add: Sources_singleDSource)\nqed\n\nlemma SourcesS6_L2:  \"Sources level2 sS6 = {sS2, sS4, sS5}\"\nproof -\n  have DSourcesS6:\"DSources level2 sS6 = {sS2, sS5}\"  by (simp add: DSources_def AbstrLevel2, auto)\n  have SourcesS2:\"Sources level2 sS2 = {}\"  by (rule SourcesS2_L2)\n  have \"Sources level2 sS5 = {sS2, sS4}\"  by (rule SourcesS5_L2)\n  with  SourcesS2 DSourcesS6 show ?thesis  by (simp add: Sources_2DSources, auto)\nqed\n\nlemma SourcesS7_L2:  \"Sources level2 sS7 = {}\"\nproof -\n  have \"DSources level2 sS7 = {}\"  by (simp add: DSources_def AbstrLevel2, auto)\n  thus ?thesis  by (simp add: DSourcesEmptySources)\nqed\n\nlemma SourcesS8_L2:\n \"Sources level2 sS8 = {sS7}\"\nproof -\n  have DSourcesS8:\"DSources level2 sS8 = {sS7}\"  by (simp add: DSources_def AbstrLevel2, auto)\n  have \"Sources level2 sS7 = {}\"  by (rule SourcesS7_L2)\n  with DSourcesS8 show ?thesis  by  (simp add: Sources_singleDSource)\nqed\n\nlemma SourcesS9_L2:\n \"Sources level2 sS9 = {}\"\nproof -\n  have \"DSources level2 sS9 = {}\"  by (simp add: DSources_def AbstrLevel2, auto)\n  thus ?thesis  by (simp add: DSourcesEmptySources)\nqed\n\nlemma SourcesS10_L2: \"Sources level2 sS10 = {sS9}\"\nproof -\n  have DSourcesS10:\"DSources level2 sS10 = {sS9}\" by (simp add: DSources_def AbstrLevel2, auto)\n  have \"Sources level2 sS9 = {}\" by (rule SourcesS9_L2)\n  with DSourcesS10 show ?thesis  by  (simp add: Sources_singleDSource)\nqed\n\nlemma SourcesS11_L2: \"Sources level2 sS11 = {sS9}\"\nproof -\n  have DSourcesS11:\"DSources level2 sS11 = {sS9}\"  by (simp add: DSources_def AbstrLevel2, auto)\n  have \"Sources level2 sS9 = {}\"  by (rule SourcesS9_L2)\n  with DSourcesS11 show ?thesis  by  (simp add: Sources_singleDSource)\nqed\n\nlemma SourcesS12_L2: \"Sources level2 sS12 = {sS9, sS10}\"\nproof -\n  have DSourcesS12:\"DSources level2 sS12 = {sS10}\" by (simp add: DSources_def AbstrLevel2, auto)\n  have \"Sources level2 sS10 = {sS9}\"  by (rule SourcesS10_L2)\n  with DSourcesS12 show ?thesis  by  (simp add: Sources_singleDSource)\nqed\n\nlemma SourcesS13_L2: \"Sources level2 sS13 = {sS9, sS10, sS12}\"\nproof -\n  have DSourcesS13:\"DSources level2 sS13 = {sS12}\"  by (simp add: DSources_def AbstrLevel2, auto)\n  have \"Sources level2 sS12 = {sS9, sS10}\" by (rule SourcesS12_L2)\n  with DSourcesS13 show ?thesis by  (simp add: Sources_singleDSource)\nqed\n\nlemma SourcesS14_L2: \"Sources level2 sS14 = {sS9, sS11}\"\nproof -\n  have DSourcesS14:\"DSources level2 sS14 = {sS11}\"  by (simp add: DSources_def AbstrLevel2, auto)\n  have \"Sources level2 sS11 = {sS9}\"  by (rule SourcesS11_L2)\n  with DSourcesS14 show ?thesis  by  (simp add: Sources_singleDSource)\nqed\n\nlemma SourcesS15_L2: \"Sources level2 sS15 = {sS9, sS11, sS14}\"\nproof -\n  have DSourcesS15:\"DSources level2 sS15= {sS14}\"  by (simp add: DSources_def AbstrLevel2, auto)\n  have \"Sources level2 sS14 = {sS9, sS11}\"  by (rule SourcesS14_L2)\n  with DSourcesS15 show ?thesis by  (simp add: Sources_singleDSource)\nqed\n\n\nsubsection \\<open>Minimal sets of components to prove certain properties\\<close>\n\nlemma minSetOfComponentsTestL2p1:\n\"minSetOfComponents level2 {data10, data13} = {sS1}\"\nproof - \n  have outL2:\"outSetOfComponents level2 {data10, data13} = {sS1}\"\n    by (simp add: outSetOfComponents_def  AbstrLevel2, auto) \n  have \"Sources level2 sS1 = {}\" by (simp add: SourcesS1_L2)\n  with outL2 show ?thesis by (simp add:  minSetOfComponents_def)\nqed\n\nlemma NOT_noIrrelevantChannelsTestL2p1:\n\" \\<not> noIrrelevantChannels level2 {data10, data13}\"\nby (simp add: noIrrelevantChannels_def systemIN_def minSetOfComponentsTestL2p1 AbstrLevel2)\n\nlemma NOT_allNeededINChannelsTestL2p1:\n\"\\<not> allNeededINChannels  level2 {data10, data13}\"\nby (simp add: allNeededINChannels_def minSetOfComponentsTestL2p1  systemIN_def AbstrLevel2)\n\nlemma minSetOfComponentsTestL2p2:\n\"minSetOfComponents level2 {data1, data12} = {sS2, sS4, sS5, sS6}\"\nproof - \n  have outL2:\"outSetOfComponents level2 {data1, data12} = {sS6}\"\n    by (simp add: outSetOfComponents_def  AbstrLevel2, auto) \n  have \"Sources level2 sS6 = {sS2, sS4, sS5}\"\n    by  (simp add: SourcesS6_L2) \n  with outL2 show ?thesis \n    by (simp add:  minSetOfComponents_def) \nqed\n \nlemma noIrrelevantChannelsTestL2p2:\n\"noIrrelevantChannels level2  {data1, data12}\"\nby (simp add: noIrrelevantChannels_def systemIN_def minSetOfComponentsTestL2p2 AbstrLevel2)\n\nlemma allNeededINChannelsTestL2p2:\n\"allNeededINChannels  level2 {data1, data12}\"\nby (simp add: allNeededINChannels_def minSetOfComponentsTestL2p2  systemIN_def AbstrLevel2)\n\nlemma minSetOfComponentsTestL1p3:\n\"minSetOfComponents level1 {data1, data10, data11} = {sA12, sA11, sA21}\"\nproof - \n  have sg1:\"outSetOfComponents level1 {data1, data10, data11} = {sA12, sA21}\"\n    by (simp add: outSetOfComponents_def  AbstrLevel1, auto)  \n  have \"DSources level1 sA12 = {}\"\n    by (simp add: DSources_def AbstrLevel1, auto) \n  hence sg2:\"Sources level1 sA12 = {}\"\n    by (simp add: DSourcesEmptySources)  \n  have sg3:\"DSources level1 sA21 = {sA11}\"\n    by (simp add: DSources_def AbstrLevel1, auto) \n  have sg4:\"DSources level1 sA11 = {}\"\n    by (simp add: DSources_def AbstrLevel1, auto)  \n  hence \"Sources level1 sA21 = {sA11}\"\n    by (metis SourcesOnlyDSources sg3 singleton_iff)\n  from this and sg1 and sg2 show ?thesis\n     by (simp add:  minSetOfComponents_def, blast) \nqed\n\nlemma noIrrelevantChannelsTestL1p3:\n\"noIrrelevantChannels level1  {data1, data10, data11}\"\nby (simp add: noIrrelevantChannels_def systemIN_def minSetOfComponentsTestL1p3 AbstrLevel1)\n\nlemma allNeededINChannelsTestL1p3:\n\"allNeededINChannels  level1 {data1, data10, data11}\"\nby (simp add: allNeededINChannels_def minSetOfComponentsTestL1p3  systemIN_def AbstrLevel1)\n\nlemma minSetOfComponentsTestL2p3:\n\"minSetOfComponents level2 {data1, data10, data11} = {sS1, sS2, sS3}\"\nproof - \n  have sg1:\"outSetOfComponents level2 {data1, data10, data11} = {sS1, sS3}\"\n    by (simp add: outSetOfComponents_def  AbstrLevel2, auto)  \n  have sS1:\"Sources level2 sS1 = {}\" by (simp add: SourcesS1_L2)\n  have \"Sources level2 sS3 = {sS2}\" by (simp add: SourcesS3_L2)\n   with sg1 sS1 show ?thesis\n     by (simp add:  minSetOfComponents_def, blast) \nqed\n \nlemma noIrrelevantChannelsTestL2p3:\n\"noIrrelevantChannels level2  {data1, data10, data11}\"\nby (simp add: noIrrelevantChannels_def systemIN_def minSetOfComponentsTestL2p3 AbstrLevel2)\n\nlemma allNeededINChannelsTestL2p3:\n\"allNeededINChannels  level2 {data1, data10, data11}\"\nby (simp add: allNeededINChannels_def minSetOfComponentsTestL2p3  systemIN_def AbstrLevel2)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/ComponentDependencies/DataDependenciesCaseStudy.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.4649015713733885, "lm_q1q2_score": 0.26670399308765474}}
{"text": "theory func_cor_OSMboxPost\n  imports rg_cond\nbegin\n  \nlemma OSMboxPost_stable_pevent: \"stable  \\<lbrace>pevent \\<in> \\<acute>OSMailBoxs\\<rbrace> (OSMboxPost_rely t)\"\n  by(simp add:OSMboxPost_pre_def OSMboxPost_rely_def stable_def gvars_conf_stable_def gvars_conf_def)              \n\nlemma OSMboxPost_satRG_cond1_inv_stb : \" \\<lbrakk>inv V; cur V = Some t;  pevent \\<in> OSMailBoxs V; \n                                         wait_q (OSMailbox_info V pevent) \\<noteq> []\\<rbrakk> \\<Longrightarrow>\n     inv  (V\\<lparr>th := (th V)(t := hd (wait_q (OSMailbox_info V pevent))),\n          tmout := (tmout V)(hd (wait_q (OSMailbox_info V pevent)) := OS_ERR_NONE),\n          get_msg := get_msg V(hd (wait_q (OSMailbox_info V pevent)) \\<mapsto> y),\n          statPend := (statPend V)(hd (wait_q (OSMailbox_info V pevent)) := OS_STAT_PEND_OK),\n          OSMailbox_info := (OSMailbox_info V)(pevent := OSMailbox_info V pevent\\<lparr>wait_q := tl (wait_q (OSMailbox_info V pevent))\\<rparr>),\n          need_resched := (need_resched V)(t := True),\n          cur := Some (SOME ta. ta \\<noteq> hd (wait_q (OSMailbox_info V pevent)) \\<longrightarrow> ta \\<noteq> t \\<longrightarrow> thd_state V ta = READY),\n          thd_state := (thd_state V)\n            (hd (wait_q (OSMailbox_info V pevent)) := READY, t := READY,\n             SOME ta. ta \\<noteq> hd (wait_q (OSMailbox_info V pevent)) \\<longrightarrow> ta \\<noteq> t \\<longrightarrow> thd_state V ta = READY := RUNNING),\n          ret := (ret V)(t := OS_ERR_NONE)\\<rparr>)\"\n  apply (simp add: inv_def)\n  apply (rule conjI, simp add: inv_cur_def)\n   apply auto[1]\n  apply (rule conjI, simp add: inv_OS_Mem_info_def inv_OS_Mem_info_mp_def)\n  apply (simp add: inv_thd_waitq_def)\n  apply auto\n            apply (metis List.nth_tl Nitpick.size_list_simp(2) Suc_mono hd_conv_nth in_set_conv_nth \n            length_pos_if_in_set lessI list.set_sel(1) not_less_zero)\n           apply (metis Thread_State_Type.distinct(5) inv_cur_def list.set_sel(2))\n          apply (smt Thread_State_Type.distinct(3) list.set_sel(2) set_conv_nth tfl_some tl_def)\n         apply (simp add: list.set_sel(2))\n  using list.set_sel(1) apply blast\n       apply (metis Thread_State_Type.distinct(5) inv_cur_def)\n      apply (smt Thread_State_Type.distinct(3) set_conv_nth tfl_some)\n     apply (metis hd_Cons_tl set_ConsD)\n    apply (simp add: List.nth_tl Nitpick.size_list_simp(2))\n   apply (meson list.set_sel(2))\n  by (meson list.set_sel(2))\n\n\nlemma OSMboxPost_satRG_cond1: \"msg = Some y  \\<Longrightarrow>\n       \\<turnstile>\\<^sub>I (W\\<acute>th := \\<acute>th(t := hd (wait_q (\\<acute>OSMailbox_info pevent)));; \\<acute>tmout := \\<acute>tmout(\\<acute>th t := OS_ERR_NONE);;\n              \\<acute>get_msg := \\<acute>get_msg(\\<acute>th t \\<mapsto> y);;\n              \\<acute>statPend := \\<acute>statPend(\\<acute>th t := OS_STAT_PEND_OK);;\n              \\<acute>OSMailbox_info := \\<acute>OSMailbox_info(pevent := \\<acute>OSMailbox_info pevent\\<lparr>wait_q := tl (wait_q (\\<acute>OSMailbox_info pevent))\\<rparr>);;\n              \\<acute>thd_state := \\<acute>thd_state(\\<acute>th t := READY);;\n              \\<acute>need_resched := \\<acute>need_resched(t := True);;\n              IF \\<acute>need_resched t THEN reschedule FI;;\n              \\<acute>ret := \\<acute>ret (t := OS_ERR_NONE)) \n               sat\\<^sub>p [OSMboxPost_pre t \\<inter> \\<lbrace>pevent \\<in> \\<acute>OSMailBoxs\\<rbrace> \\<inter> \\<lbrace>\\<acute>cur = Some t\\<rbrace> \\<inter> \n                {V} \\<inter> {Va} \\<inter> \\<lbrace>wait_q (\\<acute>OSMailbox_info pevent) \\<noteq> []\\<rbrace>, {(s, t). s = t}, UNIV, \n               \\<lbrace>\\<acute>(Pair V) \\<in> OSMboxPost_guar t\\<rbrace> \\<inter> OSMboxPost_post t]\"\n  apply (case_tac \"(wait_q (OSMailbox_info V pevent) = [])\")\n  apply (smt CollectD Emptyprecond Int_insert_right_if1 disjoint_iff_not_equal inf_bot_right singletonD)\n  apply (case_tac \"(pevent \\<notin> OSMailBoxs V)\")\n   apply (simp add: Emptyprecond)\n  apply (case_tac \"V \\<notin> OSMboxPost_pre t \\<or> cur V \\<noteq> Some t\")\n   apply (simp add: Emptyprecond, clarsimp)\n  apply(simp add:reschedule_def)   \n    \\<comment> \\<open>use this method to extract the assumption \"wait_q (\\<acute>OSMailbox_info pevent) \\<noteq> []\" \\<close>\n  apply(rule Seq[where mid = \"let V9 = V\\<lparr>th := (th V)(t := hd (wait_q (OSMailbox_info V pevent))), \n  tmout := (tmout V)(hd (wait_q (OSMailbox_info V pevent)) := OS_ERR_NONE),\n get_msg := get_msg V(hd (wait_q (OSMailbox_info V pevent)) \\<mapsto> y),\n                                    statPend := (statPend V)(hd (wait_q (OSMailbox_info V pevent))\n                                     := OS_STAT_PEND_OK),\n                                    OSMailbox_info := (OSMailbox_info V)(pevent := OSMailbox_info V \n                                    pevent\\<lparr>wait_q := tl (wait_q (OSMailbox_info V pevent))\\<rparr>),\n                                    need_resched := (need_resched V)(t := True),\n                                    thd_state := (thd_state V)(hd (wait_q (OSMailbox_info V pevent))  \n                                    := READY, t := READY),\n                                    cur := Some (SOME ta. ta \\<noteq> hd (wait_q (OSMailbox_info V pevent)) \\<longrightarrow>\n                                    ta \\<noteq> t \\<longrightarrow> thd_state V ta = READY)\\<rparr> in\n                                    {V9\\<lparr>thd_state := (thd_state V9)(the (cur V9) := RUNNING)\\<rparr>}\"]) \n   apply(rule Seq[where mid = \"let V6 = V\\<lparr>th := (th V)(t := hd (wait_q (OSMailbox_info V pevent))), \n                                   tmout := (tmout V)(hd (wait_q (OSMailbox_info V pevent)) := OS_ERR_NONE),\n                                   get_msg := get_msg V(hd (wait_q (OSMailbox_info V pevent)) \\<mapsto> y),\n                                   statPend := (statPend V)(hd (wait_q (OSMailbox_info V pevent)) := \n                                   OS_STAT_PEND_OK),\n                                   OSMailbox_info := (OSMailbox_info V)(pevent := OSMailbox_info V \n                                    pevent\\<lparr>wait_q := tl (wait_q (OSMailbox_info V pevent))\\<rparr>),\n                                   thd_state := (thd_state V) (hd (wait_q (OSMailbox_info V pevent))\n                                    :=  READY)\\<rparr>  in\n                                    {V6\\<lparr>need_resched := (need_resched V6)( t := True)\\<rparr>}\"]) \n    apply(rule Seq[where mid = \"let V5 = V\\<lparr>th := (th V)(t := hd (wait_q (OSMailbox_info V pevent))), \n                                  tmout := (tmout V)(hd (wait_q (OSMailbox_info V pevent)) := OS_ERR_NONE),\n                                  get_msg := get_msg V(hd (wait_q (OSMailbox_info V pevent)) \\<mapsto> y),\n                                  statPend := (statPend V)(hd (wait_q (OSMailbox_info V pevent)) := \n                                  OS_STAT_PEND_OK),\n                                  OSMailbox_info := (OSMailbox_info V) (pevent := OSMailbox_info V pevent\n                                  \\<lparr>wait_q :=  tl (wait_q (OSMailbox_info V pevent))\\<rparr>)\\<rparr>  in\n                                  {V5\\<lparr>thd_state := (thd_state V5)((th V5) t := READY)\\<rparr>}\"]) \n     apply(rule Seq[where mid = \"let V4 = V\\<lparr>th := (th V)(t := hd (wait_q (OSMailbox_info V pevent))),\n                                 tmout := (tmout V)(hd (wait_q (OSMailbox_info V pevent)) := OS_ERR_NONE),\n                                 get_msg := get_msg V(hd (wait_q (OSMailbox_info V pevent)) \\<mapsto> y),\n                                 statPend := (statPend V)(hd (wait_q (OSMailbox_info V pevent)) := \n                                 OS_STAT_PEND_OK)\\<rparr> in\n                                 {V4\\<lparr>OSMailbox_info := (OSMailbox_info V4)(pevent := OSMailbox_info \n                                  V4 pevent \\<lparr>wait_q := tl (wait_q (OSMailbox_info V4 pevent))\\<rparr>)\\<rparr>} \n                                  (* \\<inter> \\<lbrace>wait_q (\\<acute>OSMailbox_info pevent) \\<noteq> []\\<rbrace>*)\"])  \n      apply(rule Seq[where mid = \"let V3 = V\\<lparr>th := (th V)(t := hd (wait_q (OSMailbox_info V pevent))), \n                                  tmout := (tmout V)(hd (wait_q (OSMailbox_info V pevent)) := OS_ERR_NONE),\n                                   get_msg := get_msg V(hd (wait_q (OSMailbox_info V pevent)) \\<mapsto> y)\\<rparr> \n                                   in  {V3\\<lparr>statPend := (statPend V3)((th V3) t := OS_STAT_PEND_OK)\\<rparr>} \n                                        \\<inter> \\<lbrace>wait_q (\\<acute>OSMailbox_info pevent) \\<noteq> []\\<rbrace>\"]) \n       apply(rule Seq[where mid = \"let V2 = V\\<lparr>th := (th V)(t := hd (wait_q (OSMailbox_info V pevent))), \n                                   tmout := (tmout V)(hd (wait_q (OSMailbox_info V pevent)) := OS_ERR_NONE)\\<rparr> \n                                   in {V2\\<lparr>get_msg := (get_msg V2)((th V2) t := msg)\\<rparr>} \\<inter> \n                                   \\<lbrace>wait_q (\\<acute>OSMailbox_info pevent) \\<noteq> []\\<rbrace>\"]) \n        apply(rule Seq[where mid = \"let V1 = V\\<lparr>th := (th V)(t :=  hd (wait_q((OSMailbox_info V) pevent)))\\<rparr> in\n                                      {V1\\<lparr>tmout := (tmout V1)((th V1) t := OS_ERR_NONE)\\<rparr>} \\<inter> \n                                      \\<lbrace>wait_q (\\<acute>OSMailbox_info pevent) \\<noteq> []\\<rbrace>\"]) \n         apply(rule Seq[where mid = \"{V\\<lparr>th := (th V)(t :=  hd (wait_q((OSMailbox_info V) pevent)))\\<rparr>} \n                                    \\<inter> \\<lbrace>wait_q (\\<acute>OSMailbox_info pevent) \\<noteq> []\\<rbrace>\"]) \n          apply(rule Basic) \n             apply auto \n           apply(simp add:stable_id2)  \n          apply(simp add:stable_id2)\n         apply(rule Basic)\n            apply auto\n          apply(simp add:stable_id2)\n         apply(simp add:stable_id2)\n        apply(rule Basic)\n           apply auto\n         apply(simp add:stable_id2) \n        apply(simp add:stable_id2)\n       apply(rule Basic)\n          apply auto\n        apply(simp add:stable_id2) \n       apply(simp add:stable_id2)\n      apply(rule Basic)\n         apply auto\n       apply(simp add:stable_id2)\n      apply(simp add:stable_id2)\n     apply(rule Basic)\n        apply auto\n      apply(simp add:stable_id2) \n     apply(simp add:stable_id2)\n    apply(rule Basic)\n       apply auto\n     apply(simp add:stable_id2) \n    apply(simp add:stable_id2)\n   apply(rule Cond)  \n   apply(simp add:stable_id2)\n     apply(rule Seq[where mid = \"let V8 = V\\<lparr>th := (th V)(t := hd (wait_q (OSMailbox_info V pevent))), \n                                tmout := (tmout V)(hd (wait_q (OSMailbox_info V pevent)) := OS_ERR_NONE),\n                                    get_msg := get_msg V(hd (wait_q (OSMailbox_info V pevent)) \\<mapsto> y),\n                                    statPend := (statPend V)(hd (wait_q (OSMailbox_info V pevent)) \n                                    := OS_STAT_PEND_OK),\n                                    OSMailbox_info := (OSMailbox_info V)(pevent := OSMailbox_info V \n                                    pevent\\<lparr>wait_q := tl (wait_q (OSMailbox_info V pevent))\\<rparr>),\n                                    need_resched := (need_resched V)(t := True),\n                                    thd_state := (thd_state V)\n                                    (hd (wait_q (OSMailbox_info V pevent)) := READY, t := READY)\\<rparr>  in\n                                 {V8 \\<lparr>cur :=  Some (SOME t. (thd_state V8) t = READY)\\<rparr>}\"]) \n      apply(rule Seq[where mid = \"let V7 = V\\<lparr>th := (th V)(t := hd (wait_q (OSMailbox_info V pevent))), \n                                  tmout := (tmout V)(hd (wait_q (OSMailbox_info V pevent)) := OS_ERR_NONE),\n                                  get_msg := get_msg V(hd (wait_q (OSMailbox_info V pevent)) \\<mapsto> y),\n                                  statPend := (statPend V)(hd (wait_q (OSMailbox_info V pevent)) \n                                  := OS_STAT_PEND_OK),\n                                  OSMailbox_info := (OSMailbox_info V)(pevent := OSMailbox_info V \n                                  pevent\\<lparr>wait_q := tl (wait_q (OSMailbox_info V pevent))\\<rparr>),\n                                  thd_state := (thd_state V)(hd (wait_q (OSMailbox_info V pevent)) \n                                  := READY), need_resched := (need_resched V)(t := True)\\<rparr>  in\n                                  {V7  \\<lparr>thd_state := (thd_state V7)((the (cur V7)) := READY)\\<rparr>}\"]) \n       apply(rule Basic) apply auto\n       apply(simp add:stable_id2) apply(simp add:stable_id2)\n     apply(rule Basic) apply auto\n      apply(simp add:stable_id2) apply(simp add:stable_id2)\n apply(rule Basic) apply auto\n     apply(simp add:stable_id2) apply(simp add:stable_id2)\n   apply(simp add:Emptyprecond)\n  apply(rule Basic)\n     apply(simp add:OSMboxPost_pre_def OSMboxPost_post_def OSMboxPost_guar_def)\n     apply (simp add: gvars_conf_stable_def gvars_conf_def)\n     apply auto[1]\n  using OSMboxPost_satRG_cond1_inv_stb apply blast\n      apply (simp add: lvars_nochange_def)\n     apply (simp add: OSMboxPost_satRG_cond1_inv_stb)\n    apply (simp add: stable_id2)\n   apply (simp add: stable_id2)\n  apply (simp add: stable_id2)\n  done\n\nlemma OSMboxPost_satRG_cond2: \"\n    msg = Some y \\<Longrightarrow>  \\<turnstile>\\<^sub>I (W IF \\<exists>y. msgPtr (\\<acute>OSMailbox_info pevent) = Some y \n                            THEN \\<acute>ret := \\<acute>ret(t := OS_ERR_MBOX_FULL)\n                            ELSE \\<acute>OSMailbox_info := \\<acute>OSMailbox_info(pevent := \\<acute>OSMailbox_info \n                            pevent\\<lparr>msgPtr := Some y\\<rparr>);; \n                            \\<acute>ret := \\<acute>ret(t := OK) \n                            FI) sat\\<^sub>p  [OSMboxPost_pre t \\<inter> \\<lbrace>pevent \\<in> \\<acute>OSMailBoxs\\<rbrace> \\<inter> \\<lbrace>\\<acute>cur = Some t\\<rbrace> \\<inter> {V} \\<inter> {Va} \\<inter>\n                         - \\<lbrace>wait_q (\\<acute>OSMailbox_info pevent) \\<noteq> []\\<rbrace>, {(s, t). s = t}, UNIV, \n                            \\<lbrace>\\<acute>(Pair V) \\<in> OSMboxPost_guar t\\<rbrace> \\<inter> OSMboxPost_post t]\"\n  apply (case_tac \"cur V \\<noteq> Some t\")\n   apply (simp add: Emptyprecond)\n  apply (case_tac \"V \\<notin> OSMboxPost_pre t\")\n  apply (simp add: Emptyprecond)\n  apply (rule Cond)\n    apply (simp add: stable_id2)\n    apply (rule Basic)\n       apply (simp add: OSMboxPost_guar_def gvars_conf_stable_def inv_def OSMboxPost_post_def \n       gvars_conf_def OSMboxPost_pre_def lvars_nochange_def)\n          apply (simp add: inv_cur_def inv_OS_Mem_info_def inv_OS_Mem_info_mp_def inv_thd_waitq_def)\n       apply auto[1]\n      apply simp\n     apply (simp add: stable_id2)\n    apply (simp add: stable_id2)\n   apply(rule Seq[where mid = \"{V\\<lparr> OSMailbox_info := (OSMailbox_info V)(pevent := OSMailbox_info V pevent\\<lparr>msgPtr := Some y\\<rparr>) \\<rparr>}\"])\n    apply (rule Basic)\n       apply (simp add: OSMboxPost_guar_def gvars_conf_stable_def inv_def OSMboxPost_post_def \n       gvars_conf_def OSMboxPost_pre_def lvars_nochange_def)\n       apply (simp add: inv_cur_def inv_OS_Mem_info_def inv_OS_Mem_info_mp_def inv_thd_waitq_def)\n       apply auto[1]\n      apply simp\n     apply (simp add: stable_id2)\n    apply (simp add: stable_id2)\n   apply (rule Basic)\n      apply auto[1]\n       apply (simp add: OSMboxPost_guar_def gvars_conf_stable_def inv_def OSMboxPost_post_def \n       gvars_conf_def OSMboxPost_pre_def lvars_nochange_def)\n       apply (simp add: inv_cur_def inv_OS_Mem_info_def inv_OS_Mem_info_mp_def inv_thd_waitq_def)\n       apply auto[1]\n      apply (simp add: OSMboxPost_post_def OSMboxPost_pre_def)\n      apply (simp add: inv_def inv_cur_def inv_OS_Mem_info_def inv_OS_Mem_info_mp_def inv_thd_waitq_def)\n      apply auto[1]\n     apply simp\n    apply (simp add: stable_id2)\n   apply (simp add: stable_id2)\n  apply simp\n  done\n\nlemma OSMboxPost_satRG: \"\\<Gamma> (OSMboxPost t pevent msg) \\<turnstile> OSMboxPost_RGCond t\"\n  apply (simp add:Evt_sat_RG_def)\n  apply (simp add:OSMboxPost_def OSMboxPost_RGCond_def)\n  apply(simp add:body_def Pre\\<^sub>f_def Post\\<^sub>f_def guard_def\n                 Rely\\<^sub>f_def Guar\\<^sub>f_def getrgformula_def)\n  apply(unfold stm_def)\n  apply auto  \n   apply (rule BasicEvt)\n     apply(simp add:body_def guard_def)\n     apply (rule Cond)\n        apply (simp add: OSMboxPost_pre_stable OSMboxPost_stable_pevent stable_int2)\n       apply (rule Await)\n         apply (simp add: OSMboxPost_pre_stable OSMboxPost_stable_pevent stable_int2)\n        apply (simp add: OSMboxPost_post_stable, clarsimp)\n       apply (rule Basic)\n     apply (simp add:guard_def OSMboxPost_guar_def gvars_conf_stable_def inv_def \n           OSMboxPost_post_def gvars_conf_def  OSMboxPost_pre_def lvars_nochange_def)\n          apply (simp add: inv_cur_def inv_OS_Mem_info_def inv_OS_Mem_info_mp_def inv_thd_waitq_def)\n          apply auto[1]\n         apply simp                                           \n        apply (simp add: stable_id2)\n       apply (simp add: stable_id2)\n      apply (simp add: Emptyprecond)\n     apply (simp add: OSMboxPost_guar_def)\n    apply (simp add: OSMboxPost_pre_stable)\n   apply (simp add: OSMboxPost_guar_def) \n  apply (rule BasicEvt)\n    apply(simp add:body_def guard_def)\n    apply (rule Cond)\n       apply (simp add: OSMboxPost_pre_stable OSMboxPost_stable_pevent stable_int2)\n      apply (simp add: Emptyprecond)\n     apply (rule Await)\n       apply (simp add: OSMboxPost_pre_stable OSMboxPost_stable_pevent stable_int2)\n      apply (simp add: OSMboxPost_post_stable, clarsimp)\n     apply (rule Await)\n       apply (simp add: stable_id2)\n      apply (simp add: stable_id2, clarsimp)\n     apply (rule Cond)\n  using stable_id2 apply blast\n       apply (simp add: OSMboxPost_satRG_cond1)\n      apply (simp add: OSMboxPost_satRG_cond2)\n     apply simp\n    apply (simp add: OSMboxPost_guar_def)\n   apply (simp add: OSMboxPost_pre_stable)\n  apply (simp add: OSMboxPost_guar_def)\n  done\n\nend", "meta": {"author": "SunHuan321", "repo": "uc-OS-verification", "sha": "760e159857c4015d6a9e3ccbe9f8247e4518862a", "save_path": "github-repos/isabelle/SunHuan321-uc-OS-verification", "path": "github-repos/isabelle/SunHuan321-uc-OS-verification/uc-OS-verification-760e159857c4015d6a9e3ccbe9f8247e4518862a/ucOS_mem_mailbox/func_cor_OSMboxPost.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6791787121629466, "lm_q2_score": 0.39233683016710835, "lm_q1q2_score": 0.2664668230469893}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory CustomWordAbs\nimports \"AutoCorres.AutoCorres\"\nbegin\n\nexternal_file \"custom_word_abs.c\"\ninstall_C_file \"custom_word_abs.c\"\n\nlemma [word_abs]:\n  \"\\<lbrakk> abstract_val P x sint x'; abstract_val Q y sint y' \\<rbrakk> \\<Longrightarrow>\n        abstract_val (P \\<and> Q) (max x y)\n          sint (x' xor (x' xor y') && - (if x' <s y' then (1 :: sword32) else 0))\"\n  apply (clarsimp simp: max_def word_sless_def word_sle_def)\n  done\n\nlemma [word_abs]:\n  \"\\<lbrakk> abstract_val P x unat x'; abstract_val Q y unat y' \\<rbrakk> \\<Longrightarrow>\n         abstract_val (P \\<and> Q \\<and> y < 32) (x mod (2 ^ y)) unat (x' && 2 ^ unat y' - (1 :: word32))\"\n  apply (clarsimp simp flip: shiftl_1 simp del: shiftl_Suc_0)\n  apply (fold mask_def)\n  apply (subst word_mod_2p_is_mask [symmetric])\n  apply (subst p2_gt_0)\n  by (auto simp: unat_mod)\n\nlemma [word_abs]:\n  \"\\<lbrakk> abstract_val P x unat (x' :: word32);\n     abstract_val Q y unat y' \\<rbrakk> \\<Longrightarrow>\n      abstract_val (P \\<and> Q) (x + y > UINT_MAX) id (x' + y' < x')\"\n  apply (subst not_le [symmetric], subst no_plus_overflow_unat_size)\n  apply (clarsimp simp: not_less UINT_MAX_def word_size)\n  apply arith\n  done\n\nautocorres [unsigned_word_abs = b c] \"custom_word_abs.c\"\n\ncontext custom_word_abs begin\n\nlemma \"a' x y = max x y\"\n  by (unfold a'_def, rule refl)\n\nlemma \"b' x 4 s = Some (x mod 16)\"\n  by (unfold b'_def, simp)\n\nlemma \"c' x y = (if UINT_MAX < x + y then 1 else 0)\"\n  by (unfold c'_def, simp)\n\nend\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/autocorres/tests/proof-tests/CustomWordAbs.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6187804337438502, "lm_q2_score": 0.4301473485858429, "lm_q1q2_score": 0.266166762931715}}
{"text": "(*  Title:      HOL/Auth/n_mutualExSimp_on_inis.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mutualExSimp Protocol Case Study*} \n\ntheory n_mutualExSimp_on_inis imports n_mutualExSimp_on_ini\nbegin\nlemma on_inis:\n  assumes b1: \"f \\<in> (invariants N)\" and b2: \"ini \\<in> {andList (allInitSpecs N)}\" and b3: \"formEval ini s\"\n  shows \"formEval f s\"\n  proof -\n  have c1: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__1  p__Inv3 p__Inv4)\\<or>\n    (\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__2  p__Inv4)\\<or>\n    (\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__3  p__Inv3 p__Inv4)\\<or>\n    (\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__4  p__Inv4)\\<or>\n    (\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__5  p__Inv3 p__Inv4)\"\n  apply (cut_tac b1, simp) done\n    moreover {\n      assume d1: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__1  p__Inv3 p__Inv4)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__1)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__2  p__Inv4)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__2)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__3  p__Inv3 p__Inv4)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__3)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__4  p__Inv4)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__4)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__5  p__Inv3 p__Inv4)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__5)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n  ultimately show \"formEval f s\"\n  by satx\nqed\n\nend\n", "meta": {"author": "lyj238Gmail", "repo": "newParaVerifier", "sha": "5c2d49bf8e6c46c60efa53c98b0ba5c577d59618", "save_path": "github-repos/isabelle/lyj238Gmail-newParaVerifier", "path": "github-repos/isabelle/lyj238Gmail-newParaVerifier/newParaVerifier-5c2d49bf8e6c46c60efa53c98b0ba5c577d59618/examples/n_mutualExSimp/n_mutualExSimp_on_inis.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6187804337438501, "lm_q2_score": 0.4301473485858429, "lm_q1q2_score": 0.26616676293171493}}
{"text": "(* Title: RTS/JVM_RTS/JVMSemantics.thy *)\n(* Author: Susannah Mansky, UIUC 2020 *)\n\nsection \"Instantiating @{term Semantics} with Jinja JVM\"\n\ntheory JVMSemantics\nimports \"../Common/Semantics\" \"../../JinjaDCI/JVM/JVMExec\"\nbegin\n\nfun JVMsmall :: \"jvm_prog \\<Rightarrow> jvm_state \\<Rightarrow> jvm_state set\" where\n\"JVMsmall P \\<sigma> = { \\<sigma>'. exec (P, \\<sigma>) = Some \\<sigma>' }\"\n\nlemma JVMsmall_prealloc_pres:\nassumes pre: \"preallocated (fst(snd \\<sigma>))\"\n  and \"\\<sigma>' \\<in> JVMsmall P \\<sigma>\"\nshows \"preallocated (fst(snd \\<sigma>'))\"\nusing exec_prealloc_pres[OF pre] assms by(cases \\<sigma>, cases \\<sigma>', auto)\n\nlemma JVMsmall_det: \"JVMsmall P \\<sigma> = {} \\<or> (\\<exists>\\<sigma>'. JVMsmall P \\<sigma> = {\\<sigma>'})\"\nby auto\n\ndefinition JVMendset :: \"jvm_state set\" where\n\"JVMendset \\<equiv> { (xp,h,frs,sh). frs = [] \\<or> (\\<exists>x. xp = Some x) }\"\n\nlemma JVMendset_final: \"\\<sigma> \\<in> JVMendset \\<Longrightarrow> \\<forall>P. JVMsmall P \\<sigma> = {}\"\n by(auto simp: JVMendset_def)\n\nlemma start_state_nend:\n \"start_state P \\<notin> JVMendset\"\n by(simp add: start_state_def JVMendset_def)\n\ninterpretation JVMSemantics: Semantics JVMsmall JVMendset\n by unfold_locales (auto dest: JVMendset_final)\n\nend", "meta": {"author": "susannahej", "repo": "rts", "sha": "df1ae3f62d804fb5fad524096f653eecac6d0581", "save_path": "github-repos/isabelle/susannahej-rts", "path": "github-repos/isabelle/susannahej-rts/rts-df1ae3f62d804fb5fad524096f653eecac6d0581/JVM_RTS/JVMSemantics.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297746074044134, "lm_q2_score": 0.42250463481418826, "lm_q1q2_score": 0.26608269051665046}}
{"text": "section {*FUNCTION\\_CONT\\_\\_Enforce\\_Controllability*}\ntheory\n  FUNCTION_CONT__Enforce_Controllability\n\nimports\n  PRJ_13_06__ENTRY\n\nbegin\n\ndefinition F_DPDA_EC__SpecInput :: \"\n  ('stateA, 'event, 'stackA) epda \n  \\<Rightarrow> (('stateB, 'event, nat) epda \\<times> 'event set) \n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_EC__SpecInput G X \\<equiv>\n  case X of \n  (P, \\<Sigma>UC) \\<Rightarrow> \n     valid_dpda G \n     \\<and> valid_dfa P \n     \\<and> epdaS.marked_language G \\<subseteq> epdaS.marked_language P \n     \\<and> epdaS.unmarked_language G \\<subseteq> epdaS.unmarked_language P \n     \\<and> nonblockingness_language (epdaS.unmarked_language G) (epdaS.marked_language G) \n     \\<and> \\<not> epdaH_livelock G \n     \\<and> epdaH.accessible G\"\n\ndefinition F_DPDA_EC__SpecOutput :: \"\n  ('stateA, 'event, 'stackA) epda \n  \\<Rightarrow> (('stateA, 'event, 'stackA) epda \\<times> ('stateB, 'event, nat) epda \\<times> 'event set) \n  \\<Rightarrow> (('stateA, 'event, 'stackA) epda option \\<times> bool) \n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_EC__SpecOutput Gi X R \\<equiv>\n  case X of \n  (G0, P, \\<Sigma>UC) \\<Rightarrow> \n    (case R of \n    (None, b) \\<Rightarrow> \n      des_langM \n        (Enforce_Marked_Controllable_Subset \n          \\<Sigma>UC \n          (epdaH.unmarked_language P) \n          (epda_to_des Gi)) \n       = {} \n      \\<and> \\<not> b \n  | (Some Go, b) \\<Rightarrow> \n      valid_dpda Go \n      \\<and> Enforce_Marked_Controllable_Subset \n          \\<Sigma>UC \n          (epdaH.unmarked_language P) \n          (epda_to_des Gi) \n         = epda_to_des Go \n      \\<and> \\<not> epdaH_livelock Go \n      \\<and> (b \\<longrightarrow> Gi = Go) \n      \\<and> b = epda_operational_controllable Gi P \\<Sigma>UC \n      \\<and> (b \\<longleftrightarrow> epda_to_des Gi = epda_to_des Go))\"\n\ndefinition F_DPDA_EC__F_DPDA_OTS__SpecInput :: \"\n  (('stateA, 'stateB) DT_tuple2, 'event, 'stackA) epda \n  \\<Rightarrow> (('stateA, 'event, 'stackA) epda \\<times> ('stateB, 'event, nat) epda) \n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_EC__F_DPDA_OTS__SpecInput G X \\<equiv>\n  case X of \n  (S, D) \\<Rightarrow> \n      valid_dpda G \n      \\<and> valid_dfa D \n      \\<and> nonblockingness_language (epdaH.unmarked_language G) (epdaH.marked_language G) \n      \\<and> epdaH_reflection_to_DFA_exists G D sel_tuple2_2 \n      \\<and> \\<not> epdaH_livelock G \n      \\<and> epda_to_des G = epda_to_des S\"\n\ndefinition F_DPDA_EC__F_DPDA_OTS__SpecOutput :: \"\n  ('stateC, 'event, 'stackC) epda \n  \\<Rightarrow> (('stateA, 'event, 'stackA) epda \\<times> ('stateB, 'event, nat) epda \\<times> 'event set) \n  \\<Rightarrow> (('stateA, 'event, 'stackA) epda option \\<times> bool) \n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_EC__F_DPDA_OTS__SpecOutput Gi X R \\<equiv>\n  case X of \n  (G0, P, \\<Sigma>UC) \\<Rightarrow> \n    (case R of \n    (None, b) \\<Rightarrow> \n        des_langM \n          (Enforce_Marked_Controllable_Subset \n            \\<Sigma>UC \n            (epdaH.unmarked_language P) \n            (epda_to_des Gi)) \n         = {} \n        \\<and> b = False \n  | (Some Go, b) \\<Rightarrow> \n      valid_dpda Go \n      \\<and> Enforce_Marked_Controllable_Subset \n          \\<Sigma>UC \n          (epdaH.unmarked_language P)\n          (epda_to_des Gi) \n         = (epda_to_des Go) \n      \\<and> \\<not> epdaH_livelock Go \n      \\<and> (b \\<longrightarrow> G0 = Go) \n      \\<and> b = epda_operational_controllable Gi P \\<Sigma>UC\n      \\<and> (b \\<longleftrightarrow> epda_to_des Gi = epda_to_des Go))\"\n\ndefinition F_DPDA_EC__F_DPDA_EUML__SpecInput :: \"\n  ((('stateA, 'stateB) DT_tuple2, 'stackA) DT_state_and_stack_or_state, 'event, 'stackA) epda \n  \\<Rightarrow> (('stateA, 'event, 'stackA) epda \\<times> ('stateB, 'event, nat) epda) \n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_EC__F_DPDA_EUML__SpecInput G X \\<equiv>\n  case X of \n  (S, D) \\<Rightarrow> \n      valid_dpda G \n      \\<and> valid_dfa D \n      \\<and> nonblockingness_language (epdaH.unmarked_language G) (epdaH.marked_language G) \n      \\<and> state_stack_unique_for_marking_states G \n      \\<and> state_stack_unique_for_stable_states G \n      \\<and> always_applicable_for_stable_states G \n      \\<and> some_edge_applicable G \n      \\<and> \\<not> epdaH_livelock G \n      \\<and> epdaH_reflection_to_DFA_exists G D (sel_tuple2_2 \\<circ> F_DPDA_OTS__get_state) \n      \\<and> corresponds_to_top_stack G F_DPDA_OTS__is_auxiliary F_DPDA_OTS__get_stack \n      \\<and> main_states_have_only_empty_steps G F_DPDA_OTS__is_main \n      \\<and> main_states_have_all_empty_steps G F_DPDA_OTS__is_main \n      \\<and> executing_edge_from_auxiliary_to_main_state G F_DPDA_OTS__is_auxiliary F_DPDA_OTS__is_main \n      \\<and> always_applicable_for_auxiliary_states G F_DPDA_OTS__is_auxiliary \n      \\<and> main_to_auxiliary_or_auxiliary_to_main G F_DPDA_OTS__is_main \n      \\<and> epda_to_des G = epda_to_des S\"\n\ndefinition F_DPDA_EC__F_DPDA_EUML__SpecOutput :: \"\n  ('stateC, 'event, 'stackC) epda \n  \\<Rightarrow> (('stateA, 'event, 'stackA) epda \\<times> ('stateB, 'event, nat) epda \\<times> 'event set) \n  \\<Rightarrow> (('stateA, 'event, 'stackA) epda option \\<times> bool) \n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_EC__F_DPDA_EUML__SpecOutput \\<equiv>\n  F_DPDA_EC__F_DPDA_OTS__SpecOutput\"\n\ndefinition F_DPDA_EC__F_DPDA_EA_OPT__SpecInput :: \"\n  (((('stateA, 'stateB) DT_tuple2, 'stackA) DT_state_and_stack_or_state) DT_state_or_state, 'event, 'stackA) epda \n  \\<Rightarrow> (('stateA, 'event, 'stackA) epda \\<times> ('stateB, 'event, nat) epda) \n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_EC__F_DPDA_EA_OPT__SpecInput G X \\<equiv>\n  case X of \n  (S, D) \\<Rightarrow> \n      valid_dpda G \n      \\<and> valid_dfa D \n      \\<and> nonblockingness_language (epdaH.unmarked_language G) (epdaH.marked_language G) \n      \\<and> state_stack_unique_for_marking_states G \n      \\<and> only_executing_edges_from_marking_states G \n      \\<and> \\<not> epdaH_livelock G \n      \\<and> epdaH_reflection_to_DFA_exists G D (sel_tuple2_2 \\<circ> F_DPDA_OTS__get_state \\<circ> F_DPDA_EUML__get_state) \n      \\<and> corresponds_to_top_stack G F_DPDA_EUML__is_auxiliary F_DPDA_EUML__get_stack \n      \\<and> main_states_have_only_empty_steps G F_DPDA_EUML__is_main \n      \\<and> main_states_have_all_empty_steps G F_DPDA_EUML__is_main \n      \\<and> executing_edge_from_auxiliary_to_main_state G F_DPDA_EUML__is_auxiliary F_DPDA_EUML__is_main \n      \\<and> always_applicable_for_auxiliary_states G F_DPDA_EUML__is_auxiliary \n      \\<and> main_to_auxiliary_or_auxiliary_to_main G F_DPDA_EUML__is_main \n      \\<and> epda_to_des G = epda_to_des S\"\n\ndefinition F_DPDA_EC__F_DPDA_EA_OPT__SpecOutput :: \"\n  ('stateC, 'event, 'stackC) epda \n  \\<Rightarrow> (('stateA, 'event, 'stackA) epda \\<times> ('stateB, 'event, nat) epda \\<times> 'event set) \n  \\<Rightarrow> (('stateA, 'event, 'stackA) epda option \\<times> bool) \n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_EC__F_DPDA_EA_OPT__SpecOutput \\<equiv>\n  F_DPDA_EC__F_DPDA_OTS__SpecOutput\"\n\ndefinition F_DPDA_EC__F_DPDA_RCS__SpecInput :: \"\n  (((('stateA, 'stateB) DT_tuple2, 'stackA) DT_state_and_stack_or_state) DT_state_or_state, 'event, 'stackA) epda \n  \\<Rightarrow> (('stateA, 'event, 'stackA) epda \\<times> ('stateB, 'event, nat) epda) \n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_EC__F_DPDA_RCS__SpecInput G X \\<equiv>\n  case X of \n  (S, D) \\<Rightarrow> \n      valid_dpda G \n      \\<and> valid_dfa D \n      \\<and> nonblockingness_language (epdaS.unmarked_language G) (epdaS.marked_language G) \n      \\<and> state_stack_unique_for_marking_states G \n      \\<and> only_executing_edges_from_marking_states G \n      \\<and> \\<not> epdaH_livelock G \n      \\<and> epdaH_reflection_to_DFA_exists G D (sel_tuple2_2 \\<circ> F_DPDA_OTS__get_state \\<circ> F_DPDA_EUML__get_state) \n      \\<and> corresponds_to_top_stack G F_DPDA_EUML__is_auxiliary F_DPDA_EUML__get_stack \n      \\<and> epdaH.accessible G \n      \\<and> main_states_can_be_left_with_empty_step G F_DPDA_EUML__is_main \n      \\<and> main_states_have_only_empty_steps G F_DPDA_EUML__is_main \n      \\<and> executing_edge_from_auxiliary_to_main_state G F_DPDA_EUML__is_auxiliary F_DPDA_EUML__is_main \n      \\<and> always_applicable_for_auxiliary_states G F_DPDA_EUML__is_auxiliary \n      \\<and> main_to_auxiliary_or_auxiliary_to_main G F_DPDA_EUML__is_main \n      \\<and> epda_to_des G = epda_to_des S\"\n\ndefinition F_DPDA_EC__F_DPDA_RCS__SpecOutput :: \"\n  ('stateC, 'event, 'stackC) epda \n  \\<Rightarrow> (('stateA, 'event, 'stackA) epda \\<times> ('stateB, 'event, nat) epda \\<times> 'event set) \n  \\<Rightarrow> (('stateA, 'event, 'stackA) epda option \\<times> bool) \n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_EC__F_DPDA_RCS__SpecOutput \\<equiv>\n  F_DPDA_EC__F_DPDA_EA_OPT__SpecOutput\"\n\ntheorem F_DPDA_EC__SOUND: \"\n  F_DPDA_EC__SpecInput S (P, \\<Sigma>UC) \n  \\<Longrightarrow> R = F_DPDA_EC S P \\<Sigma>UC \n  \\<Longrightarrow> F_DPDA_EC__SpecOutput S (S, P, \\<Sigma>UC) R\"\n  apply(simp add: F_DPDA_EC_def)\n  apply(clarsimp)\n  apply(rule_tac\n      SPo_F=\"F_DPDA_EC__SpecOutput\"\n      and SPi_F=\"F_DPDA_EC__SpecInput\"\n      and X=\"S\"\n      and Y=\"(S, P, \\<Sigma>UC)\"\n      and SEL_iF=\"\\<lambda>(S, P, \\<Sigma>UC). (P, \\<Sigma>UC)\"\n      and SEL_iH=\"\\<lambda>(S, P, \\<Sigma>UC). P\"\n      and SEL_iFH=\"\\<lambda>(S, P, \\<Sigma>UC). (S, P)\"\n      and SEL_oF=\"\\<lambda>(S, P, \\<Sigma>UC). (S, P, \\<Sigma>UC)\"\n      and SEL_oH=\"\\<lambda>(S, P, \\<Sigma>UC). (P, \\<Sigma>UC)\"\n      and SEL_oFH=\"\\<lambda>(S, P, \\<Sigma>UC). (S, P, \\<Sigma>UC)\"\n      and SPi_H=\"FUN_DPDA_DFA_PRODUCT__SpecInput2\"\n      and SPo_H=\"FUN_DPDA_DFA_PRODUCT__SpecOutput2\"\n      and SPi_FH=\"F_DPDA_EC__F_DPDA_OTS__SpecInput\"\n      and SPo_FH=\"F_DPDA_EC__F_DPDA_OTS__SpecOutput\"\n      and H=\"F_DPDA_DFA_PRODUCT\"\n      in decompose_sequential_execution_input_output_specification_args)\n             apply(force)\n            apply(force)\n           apply(force)\n          apply(force)\n         apply(force)\n        apply(force)\n       apply(force)\n      apply(simp add: FUN_DPDA_DFA_PRODUCT__SpecInput2_def F_DPDA_EC__SpecInput_def)\n      apply(clarsimp)\n      apply(rule_tac\n      t=\"epdaH.unmarked_language S\"\n      and s=\"epdaS.unmarked_language S\"\n      in ssubst)\n       apply (metis valid_dpda_to_valid_pda PDA_to_epda epdaS_to_epdaH_unmarked_language)\n      apply(rule_tac\n      t=\"epdaH.marked_language S\"\n      and s=\"epdaS.marked_language S\"\n      in ssubst)\n       apply (metis valid_dpda_to_valid_pda PDA_to_epda epdaS_to_epdaH_mlang)\n      apply(rule_tac\n      t=\"epdaH.marked_language P\"\n      and s=\"epdaS.marked_language P\"\n      in ssubst)\n       apply(simp add: valid_dfa_def)\n       apply (metis valid_dpda_to_valid_pda PDA_to_epda epdaS_to_epdaH_mlang)\n      apply(rule_tac\n      t=\"epdaH.unmarked_language P\"\n      and s=\"epdaS.unmarked_language P\"\n      in ssubst)\n       apply(simp add: valid_dfa_def)\n       apply (metis valid_dpda_to_valid_pda PDA_to_epda epdaS_to_epdaH_unmarked_language)\n      apply(force)\n     apply(rule_tac\n      ?Gi=\"S\"\n      and P=\"P\"\n      in F_DPDA_DFA_PRODUCT__SOUND2)\n     apply(force)\n    apply(simp add: FUN_DPDA_DFA_PRODUCT__SpecInput2_def F_DPDA_EC__SpecInput_def F_DPDA_EC__F_DPDA_OTS__SpecInput_def FUN_DPDA_DFA_PRODUCT__SpecOutput2_def epda_to_des_def)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"epdaH.unmarked_language S\"\n      and s=\"epdaS.unmarked_language S\"\n      in subst)\n     apply(rule epdaS_to_epdaH_unmarked_language)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rule_tac\n      t=\"epdaH.marked_language S\"\n      and s=\"epdaS.marked_language S\"\n      in subst)\n     apply(rule epdaS_to_epdaH_mlang)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rule_tac\n      t=\"epdaH.marked_language P\"\n      and s=\"epdaS.marked_language P\"\n      in subst)\n     apply(rule epdaS_to_epdaH_mlang)\n     apply(simp add: valid_dfa_def)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rule_tac\n      t=\"epdaH.unmarked_language P\"\n      and s=\"epdaS.unmarked_language P\"\n      in subst)\n     apply(rule epdaS_to_epdaH_unmarked_language)\n     apply(simp add: valid_dfa_def)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(force)\n   apply(rename_tac Pa)(*strict*)\n   apply(simp add: F_DPDA_EC__F_DPDA_OTS__SpecOutput_def F_DPDA_EC__SpecOutput_def)\n   apply(clarsimp)\n   apply(rename_tac Pa x y)(*strict*)\n   apply(subgoal_tac \"epdaH.unmarked_language (F_DPDA_DFA_PRODUCT S P) = epdaH.unmarked_language S\")\n    apply(rename_tac Pa x y)(*strict*)\n    prefer 2\n    apply(simp add: FUN_DPDA_DFA_PRODUCT__SpecOutput2_def F_DPDA_EC__SpecInput_def)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"epdaH.unmarked_language S\"\n      and s=\"epdaS.unmarked_language S\"\n      in subst)\n     apply(rename_tac Pa x y)(*strict*)\n     apply(rule epdaS_to_epdaH_unmarked_language)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rename_tac Pa x y)(*strict*)\n    apply(rule_tac\n      t=\"epdaH.marked_language S\"\n      and s=\"epdaS.marked_language S\"\n      in subst)\n     apply(rename_tac Pa x y)(*strict*)\n     apply(rule epdaS_to_epdaH_mlang)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rename_tac Pa x y)(*strict*)\n    apply(rule_tac\n      t=\"epdaH.marked_language P\"\n      and s=\"epdaS.marked_language P\"\n      in subst)\n     apply(rename_tac Pa x y)(*strict*)\n     apply(rule epdaS_to_epdaH_mlang)\n     apply(simp add: valid_dfa_def)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rename_tac Pa x y)(*strict*)\n    apply(rule_tac\n      t=\"epdaH.unmarked_language P\"\n      and s=\"epdaS.unmarked_language P\"\n      in subst)\n     apply(rename_tac Pa x y)(*strict*)\n     apply(rule epdaS_to_epdaH_unmarked_language)\n     apply(simp add: valid_dfa_def)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rename_tac Pa x y)(*strict*)\n    apply(force)\n   apply(rename_tac Pa x y)(*strict*)\n   apply(subgoal_tac \"epdaH.marked_language (F_DPDA_DFA_PRODUCT S P) = epdaH.marked_language S\")\n    apply(rename_tac Pa x y)(*strict*)\n    prefer 2\n    apply(thin_tac \"epdaH.unmarked_language (F_DPDA_DFA_PRODUCT S P) = epdaH.unmarked_language S\")\n    apply(unfold FUN_DPDA_DFA_PRODUCT__SpecOutput2_def F_DPDA_EC__SpecInput_def)[1]\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"epdaH.unmarked_language S\"\n      and s=\"epdaS.unmarked_language S\"\n      in subst)\n     apply(rename_tac Pa x y)(*strict*)\n     apply(rule epdaS_to_epdaH_unmarked_language)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rename_tac Pa x y)(*strict*)\n    apply(rule_tac\n      t=\"epdaH.marked_language S\"\n      and s=\"epdaS.marked_language S\"\n      in subst)\n     apply(rename_tac Pa x y)(*strict*)\n     apply(rule epdaS_to_epdaH_mlang)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rename_tac Pa x y)(*strict*)\n    apply(rule_tac\n      t=\"epdaH.marked_language P\"\n      and s=\"epdaS.marked_language P\"\n      in subst)\n     apply(rename_tac Pa x y)(*strict*)\n     apply(rule epdaS_to_epdaH_mlang)\n     apply(simp add: valid_dfa_def)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rename_tac Pa x y)(*strict*)\n    apply(rule_tac\n      t=\"epdaH.unmarked_language P\"\n      and s=\"epdaS.unmarked_language P\"\n      in subst)\n     apply(rename_tac Pa x y)(*strict*)\n     apply(rule epdaS_to_epdaH_unmarked_language)\n     apply(simp add: valid_dfa_def)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rename_tac Pa x y)(*strict*)\n    apply(force)\n   apply(rename_tac Pa x y)(*strict*)\n   apply(subgoal_tac \"epda_to_des (F_DPDA_DFA_PRODUCT S P) = epda_to_des S\")\n    apply(rename_tac Pa x y)(*strict*)\n    prefer 2\n    apply(simp add: epda_to_des_def)\n   apply(rename_tac Pa x y)(*strict*)\n   apply(case_tac x)\n    apply(rename_tac Pa x y)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac Pa x y a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac Pa a)(*strict*)\n   apply(rule_tac\n      t=\"epda_operational_controllable S P \\<Sigma>UC\"\n      and s=\"epda_operational_controllable (F_DPDA_DFA_PRODUCT S P) P \\<Sigma>UC\"\n      in ssubst)\n    apply(rename_tac Pa a)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac Pa a)(*strict*)\n   apply(rule epda_Cont_eq_to_epda_operational_controllable_eq2)\n      apply(rename_tac Pa a)(*strict*)\n      apply(simp add: F_DPDA_EC__SpecInput_def FUN_DPDA_DFA_PRODUCT__SpecOutput2_def)\n     apply(rename_tac Pa a)(*strict*)\n     apply(simp add: F_DPDA_EC__SpecInput_def FUN_DPDA_DFA_PRODUCT__SpecOutput2_def)\n    apply(rename_tac Pa a)(*strict*)\n    apply(simp add: F_DPDA_EC__SpecInput_def FUN_DPDA_DFA_PRODUCT__SpecOutput2_def)\n   apply(rename_tac Pa a)(*strict*)\n   apply(simp add: F_DPDA_EC__SpecInput_def FUN_DPDA_DFA_PRODUCT__SpecOutput2_def)\n  apply(rename_tac X)(*strict*)\n  apply(rename_tac S')\n  apply(rename_tac S')(*strict*)\n  apply(rule_tac\n      SPo_F=\"F_DPDA_EC__F_DPDA_OTS__SpecOutput\"\n      and SPi_F=\"F_DPDA_EC__F_DPDA_OTS__SpecInput\"\n      and H=\"F_DPDA_OTS\"\n      and X=\"S'\"\n      and Y=\"(S, P, \\<Sigma>UC)\"\n      and SEL_iF=\"\\<lambda>(S, P, \\<Sigma>UC). (S, P)\"\n      and SEL_iH=\"\\<lambda>(S, P, \\<Sigma>UC). P\"\n      and SEL_iFH=\"\\<lambda>(S, P, \\<Sigma>UC). (S, P)\"\n      and SEL_oF=\"\\<lambda>(S, P, \\<Sigma>UC). (S, P, \\<Sigma>UC)\"\n      and SEL_oH=\"\\<lambda>(S, P, \\<Sigma>UC). (P, \\<Sigma>UC)\"\n      and SEL_oFH=\"\\<lambda>(S, P, \\<Sigma>UC). (S, P, \\<Sigma>UC)\"\n      and SPi_H=\"F_DPDA_OTS__SpecInput\"\n      and SPo_H=\"F_DPDA_OTS__SpecOutput\"\n      and SPi_FH=\"F_DPDA_EC__F_DPDA_EUML__SpecInput\"\n      and SPo_FH=\"F_DPDA_EC__F_DPDA_EUML__SpecOutput\"\n      in decompose_sequential_execution_input_output_specification_args2_noHargs)\n             apply(rename_tac S')(*strict*)\n             apply(force)\n            apply(rename_tac S')(*strict*)\n            apply(force)\n           apply(rename_tac S')(*strict*)\n           apply(force)\n          apply(rename_tac S')(*strict*)\n          apply(force)\n         apply(rename_tac S')(*strict*)\n         apply(force)\n        apply(rename_tac S')(*strict*)\n        apply(force)\n       apply(rename_tac S')(*strict*)\n       apply(force)\n      apply(rename_tac S')(*strict*)\n      apply(simp add: F_DPDA_EC__F_DPDA_OTS__SpecInput_def F_DPDA_OTS__SpecInput_def)\n     apply(rename_tac S')(*strict*)\n     apply(rule F_DPDA_OTS__SOUND)\n     apply(force)\n    apply(rename_tac S')(*strict*)\n    apply(simp add: F_DPDA_EC__F_DPDA_EUML__SpecInput_def F_DPDA_OTS__SpecOutput_def F_DPDA_EC__F_DPDA_OTS__SpecInput_def epda_to_des_def)\n   apply(rename_tac S' Pa)(*strict*)\n   apply(simp add: F_DPDA_EC__F_DPDA_EUML__SpecOutput_def F_DPDA_EC__F_DPDA_EUML__SpecInput_def F_DPDA_OTS__SpecOutput_def F_DPDA_EC__F_DPDA_OTS__SpecInput_def F_DPDA_EC__F_DPDA_OTS__SpecOutput_def)\n   apply(clarsimp)\n   apply(rename_tac S' Pa x y)(*strict*)\n   apply(subgoal_tac \"epdaH.unmarked_language (F_DPDA_OTS S') = epdaH.unmarked_language S'\")\n    apply(rename_tac S' Pa x y)(*strict*)\n    prefer 2\n    apply(clarsimp)\n   apply(rename_tac S' Pa x y)(*strict*)\n   apply(subgoal_tac \"epdaH.marked_language (F_DPDA_OTS S') = epdaH.marked_language S'\")\n    apply(rename_tac S' Pa x y)(*strict*)\n    prefer 2\n    apply(clarsimp)\n   apply(rename_tac S' Pa x y)(*strict*)\n   apply(subgoal_tac \"epda_to_des (F_DPDA_OTS S') = epda_to_des S'\")\n    apply(rename_tac S' Pa x y)(*strict*)\n    prefer 2\n    apply(simp add: epda_to_des_def)\n   apply(rename_tac S' Pa x y)(*strict*)\n   apply(case_tac x)\n    apply(rename_tac S' Pa x y)(*strict*)\n    apply(clarify)\n    apply(simp (no_asm))\n    apply(rename_tac S' Pa y)(*strict*)\n    apply(simp (no_asm_use))\n    apply(rule conjI)\n     apply(rename_tac S' Pa y)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac S' Pa y)(*strict*)\n    apply(rule_tac\n      t=\"epda_to_des S'\"\n      and s=\"epda_to_des (F_DPDA_OTS S')\"\n      in ssubst)\n     apply(rename_tac S' Pa y)(*strict*)\n     apply(force)\n    apply(rename_tac S' Pa y)(*strict*)\n    apply(rule_tac\n      t=\"epdaH.unmarked_language S'\"\n      and s=\"epdaH.unmarked_language (F_DPDA_OTS S')\"\n      in ssubst)\n     apply(rename_tac S' Pa y)(*strict*)\n     apply(force)\n    apply(rename_tac S' Pa y)(*strict*)\n    apply(force)\n   apply(rename_tac S' Pa x y a)(*strict*)\n   apply(clarify)\n   apply(simp (no_asm))\n   apply(rename_tac S' Pa y a)(*strict*)\n   apply(simp (no_asm_use))\n   apply(rule conjI)\n    apply(rename_tac S' Pa y a)(*strict*)\n    apply(force)\n   apply(rename_tac S' Pa y a)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac S' Pa y a)(*strict*)\n    apply(force)\n   apply(rename_tac S' Pa y a)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac S' Pa y a)(*strict*)\n    apply(force)\n   apply(rename_tac S' Pa y a)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac S' Pa y a)(*strict*)\n    apply(force)\n   apply(rename_tac S' Pa y a)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac S' Pa y a)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac S' Pa y a)(*strict*)\n   apply(rule_tac\n      t=\"epda_operational_controllable S' P \\<Sigma>UC\"\n      and s=\"epda_operational_controllable (F_DPDA_OTS S') P \\<Sigma>UC\"\n      in ssubst)\n    apply(rename_tac S' Pa y a)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac S' Pa y a)(*strict*)\n   apply(rule epda_Cont_eq_to_epda_operational_controllable_eq2)\n      apply(rename_tac S' Pa y a)(*strict*)\n      apply(force)\n     apply(rename_tac S' Pa y a)(*strict*)\n     apply(force)\n    apply(rename_tac S' Pa y a)(*strict*)\n    apply(force)\n   apply(rename_tac S' Pa y a)(*strict*)\n   apply(force)\n  apply(rename_tac S' X)(*strict*)\n  apply(thin_tac \"F_DPDA_EC__F_DPDA_OTS__SpecInput S' (S, P)\")\n  apply(clarsimp)\n  apply(rename_tac X)(*strict*)\n  apply(rename_tac S')\n  apply(rename_tac S')(*strict*)\n  apply(rule_tac\n      SPo_F=\"F_DPDA_EC__F_DPDA_EUML__SpecOutput\"\n      and SPi_F=\"F_DPDA_EC__F_DPDA_EUML__SpecInput\"\n      and H=\"F_DPDA_EUML\"\n      and X=\"S'\"\n      and Y=\"(S, P, \\<Sigma>UC)\"\n      and SEL_iF=\"\\<lambda>(S, P, \\<Sigma>UC). (S, P)\"\n      and SEL_iH=\"\\<lambda>(S, P, \\<Sigma>UC). P\"\n      and SEL_iFH=\"\\<lambda>(S, P, \\<Sigma>UC). (S, P)\"\n      and SEL_oF=\"\\<lambda>(S, P, \\<Sigma>UC). (S, P, \\<Sigma>UC)\"\n      and SEL_oH=\"\\<lambda>(S, P, \\<Sigma>UC). (P, \\<Sigma>UC)\"\n      and SEL_oFH=\"\\<lambda>(S, P, \\<Sigma>UC). (S, P, \\<Sigma>UC)\"\n      and SPi_H=\"F_DPDA_EUML__SpecInput\"\n      and SPo_H=\"F_DPDA_EUML__SpecOutput\"\n      and SPi_FH=\"F_DPDA_EC__F_DPDA_EA_OPT__SpecInput\"\n      and SPo_FH=\"F_DPDA_EC__F_DPDA_EA_OPT__SpecOutput\"\n      in decompose_sequential_execution_input_output_specification_args2_noHargs)\n             apply(rename_tac S')(*strict*)\n             apply(force)\n            apply(rename_tac S')(*strict*)\n            apply(force)\n           apply(rename_tac S')(*strict*)\n           apply(force)\n          apply(rename_tac S')(*strict*)\n          apply(force)\n         apply(rename_tac S')(*strict*)\n         apply(force)\n        apply(rename_tac S')(*strict*)\n        apply(force)\n       apply(rename_tac S')(*strict*)\n       apply(force)\n      apply(rename_tac S')(*strict*)\n      apply(simp add: F_DPDA_EUML__SpecInput_def F_DPDA_EC__F_DPDA_EUML__SpecInput_def)\n     apply(rename_tac S')(*strict*)\n     apply(rule F_DPDA_EUML__SOUND)\n     apply(force)\n    apply(rename_tac S')(*strict*)\n    apply(simp add: F_DPDA_EC__F_DPDA_EA_OPT__SpecInput_def F_DPDA_EUML__SpecOutput_def F_DPDA_EC__F_DPDA_EUML__SpecInput_def epda_to_des_def)\n   apply(rename_tac S' Pa)(*strict*)\n   apply(simp add: F_DPDA_EC__F_DPDA_EUML__SpecOutput_def F_DPDA_EC__F_DPDA_EA_OPT__SpecOutput_def F_DPDA_EC__F_DPDA_EUML__SpecInput_def F_DPDA_EUML__SpecOutput_def F_DPDA_EC__F_DPDA_OTS__SpecOutput_def)\n   apply(clarsimp)\n   apply(rename_tac S' Pa x y)(*strict*)\n   apply(subgoal_tac \"epdaH.unmarked_language (F_DPDA_EUML S') = epdaH.unmarked_language S'\")\n    apply(rename_tac S' Pa x y)(*strict*)\n    prefer 2\n    apply(clarsimp)\n   apply(rename_tac S' Pa x y)(*strict*)\n   apply(subgoal_tac \"epdaH.marked_language (F_DPDA_EUML S') = epdaH.marked_language S'\")\n    apply(rename_tac S' Pa x y)(*strict*)\n    prefer 2\n    apply(clarsimp)\n   apply(rename_tac S' Pa x y)(*strict*)\n   apply(subgoal_tac \"epda_to_des (F_DPDA_EUML S') = epda_to_des S'\")\n    apply(rename_tac S' Pa x y)(*strict*)\n    prefer 2\n    apply(simp add: epda_to_des_def)\n   apply(rename_tac S' Pa x y)(*strict*)\n   apply(case_tac x)\n    apply(rename_tac S' Pa x y)(*strict*)\n    apply(clarify)\n    apply(simp (no_asm))\n    apply(rename_tac S' Pa y)(*strict*)\n    apply(simp (no_asm_use))\n    apply(rule conjI)\n     apply(rename_tac S' Pa y)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac S' Pa y)(*strict*)\n    apply(rule_tac\n      t=\"epda_to_des S'\"\n      and s=\"epda_to_des (F_DPDA_EUML S')\"\n      in ssubst)\n     apply(rename_tac S' Pa y)(*strict*)\n     apply(force)\n    apply(rename_tac S' Pa y)(*strict*)\n    apply(rule_tac\n      t=\"epdaH.unmarked_language S'\"\n      and s=\"epdaH.unmarked_language (F_DPDA_EUML S')\"\n      in ssubst)\n     apply(rename_tac S' Pa y)(*strict*)\n     apply(force)\n    apply(rename_tac S' Pa y)(*strict*)\n    apply(force)\n   apply(rename_tac S' Pa x y a)(*strict*)\n   apply(clarify)\n   apply(simp (no_asm))\n   apply(rename_tac S' Pa y a)(*strict*)\n   apply(simp (no_asm_use))\n   apply(rule conjI)\n    apply(rename_tac S' Pa y a)(*strict*)\n    apply(force)\n   apply(rename_tac S' Pa y a)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac S' Pa y a)(*strict*)\n    apply(force)\n   apply(rename_tac S' Pa y a)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac S' Pa y a)(*strict*)\n    apply(force)\n   apply(rename_tac S' Pa y a)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac S' Pa y a)(*strict*)\n    apply(force)\n   apply(rename_tac S' Pa y a)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac S' Pa y a)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac S' Pa y a)(*strict*)\n   apply(rule_tac\n      t=\"epda_operational_controllable S' P \\<Sigma>UC\"\n      and s=\"epda_operational_controllable (F_DPDA_EUML S') P \\<Sigma>UC\"\n      in ssubst)\n    apply(rename_tac S' Pa y a)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac S' Pa y a)(*strict*)\n   apply(rule epda_Cont_eq_to_epda_operational_controllable_eq2)\n      apply(rename_tac S' Pa y a)(*strict*)\n      apply(force)\n     apply(rename_tac S' Pa y a)(*strict*)\n     apply(force)\n    apply(rename_tac S' Pa y a)(*strict*)\n    apply(force)\n   apply(rename_tac S' Pa y a)(*strict*)\n   apply(force)\n  apply(rename_tac S' X)(*strict*)\n  apply(thin_tac \"F_DPDA_EC__F_DPDA_EUML__SpecInput S' (S, P)\")\n  apply(clarsimp)\n  apply(rename_tac X)(*strict*)\n  apply(rename_tac S')\n  apply(rename_tac S')(*strict*)\n  apply(rule_tac\n      SPo_F=\"F_DPDA_EC__F_DPDA_EA_OPT__SpecOutput\"\n      and SPi_F=\"F_DPDA_EC__F_DPDA_EA_OPT__SpecInput\"\n      and H=\"F_DPDA_EA_OPT\"\n      and X=\"S'\"\n      and Y=\"(S, P, \\<Sigma>UC)\"\n      and SEL_iF=\"\\<lambda>(S, P, \\<Sigma>UC). (S, P)\"\n      and SEL_iH=\"\\<lambda>(S, P, \\<Sigma>UC). P\"\n      and SEL_iFH=\"\\<lambda>(S, P, \\<Sigma>UC). (S, P)\"\n      and SEL_oF=\"\\<lambda>(S, P, \\<Sigma>UC). (S, P, \\<Sigma>UC)\"\n      and SEL_oH=\"\\<lambda>(S, P, \\<Sigma>UC). (P, \\<Sigma>UC)\"\n      and SEL_oFH=\"\\<lambda>(S, P, \\<Sigma>UC). (S, P, \\<Sigma>UC)\"\n      and SPi_H=\"F_DPDA_EA_OPT__SpecInput2\"\n      and SPo_H=\"F_DPDA_EA_OPT__SpecOutput2\"\n      and SPi_FH=\"F_DPDA_EC__F_DPDA_RCS__SpecInput\"\n      and SPo_FH=\"F_DPDA_EC__F_DPDA_RCS__SpecOutput\"\n      in decompose_sequential_execution_input_output_specification_args2_noHargs)\n             apply(rename_tac S')(*strict*)\n             apply(force)\n            apply(rename_tac S')(*strict*)\n            apply(force)\n           apply(rename_tac S')(*strict*)\n           apply(force)\n          apply(rename_tac S')(*strict*)\n          apply(force)\n         apply(rename_tac S')(*strict*)\n         apply(force)\n        apply(rename_tac S')(*strict*)\n        apply(force)\n       apply(rename_tac S')(*strict*)\n       apply(force)\n      apply(rename_tac S')(*strict*)\n      apply(simp add: F_DPDA_EA_OPT__SpecInput2_def F_DPDA_EC__F_DPDA_EA_OPT__SpecInput_def)\n      apply(clarsimp)\n      apply(rule_tac\n      s=\"epdaH.unmarked_language S'\"\n      and t=\"epdaS.unmarked_language S'\"\n      in ssubst)\n       apply(rename_tac S')(*strict*)\n       apply(rule epdaS_to_epdaH_unmarked_language)\n       apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n      apply(rename_tac S')(*strict*)\n      apply(rule_tac\n      s=\"epdaH.marked_language S'\"\n      and t=\"epdaS.marked_language S'\"\n      in ssubst)\n       apply(rename_tac S')(*strict*)\n       apply(rule epdaS_to_epdaH_mlang)     \n       apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n      apply(rename_tac S')(*strict*)\n      apply(force)\n     apply(rename_tac S')(*strict*)\n     apply(rule F_DPDA_EA_OPT__SOUND2)\n     apply(force)\n    apply(rename_tac S')(*strict*)\n    apply(simp add: F_DPDA_EC__F_DPDA_RCS__SpecInput_def F_DPDA_EA_OPT__SpecOutput2_def F_DPDA_EC__F_DPDA_EA_OPT__SpecInput_def epda_to_des_def F_DPDA_EC__SpecInput_def)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"epdaH.unmarked_language S\"\n      and s=\"epdaH.unmarked_language S'\"\n      in ssubst)\n     apply(rename_tac S')(*strict*)\n     apply(force)\n    apply(rename_tac S')(*strict*)\n    apply(rule_tac\n      t=\"epdaH.marked_language S\"\n      and s=\"epdaH.marked_language S'\"\n      in ssubst)\n     apply(rename_tac S')(*strict*)\n     apply(force)\n    apply(rename_tac S')(*strict*)\n    apply(rule_tac\n      t=\"epdaH.unmarked_language S'\"\n      and s=\"epdaS.unmarked_language S'\"\n      in subst)\n     apply(rename_tac S')(*strict*)\n     apply(rule epdaS_to_epdaH_unmarked_language)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rename_tac S')(*strict*)\n    apply(rule_tac\n      t=\"epdaH.unmarked_language (F_DPDA_EA_OPT S')\"\n      and s=\"epdaS.unmarked_language (F_DPDA_EA_OPT S')\"\n      in subst)\n     apply(rename_tac S')(*strict*)\n     apply(rule epdaS_to_epdaH_unmarked_language)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rename_tac S')(*strict*)\n    apply(rule_tac\n      t=\"epdaH.marked_language S'\"\n      and s=\"epdaS.marked_language S'\"\n      in subst)\n     apply(rename_tac S')(*strict*)\n     apply(rule epdaS_to_epdaH_mlang)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rename_tac S')(*strict*)\n    apply(rule_tac\n      t=\"epdaH.marked_language (F_DPDA_EA_OPT S')\"\n      and s=\"epdaS.marked_language (F_DPDA_EA_OPT S')\"\n      in subst)\n     apply(rename_tac S')(*strict*)\n     apply(rule epdaS_to_epdaH_mlang)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rename_tac S')(*strict*)\n    apply(force)\n   apply(rename_tac S' Pa)(*strict*)\n   apply(simp add: F_DPDA_EC__F_DPDA_RCS__SpecOutput_def F_DPDA_EC__F_DPDA_EA_OPT__SpecOutput_def F_DPDA_EC__F_DPDA_EA_OPT__SpecInput_def F_DPDA_EA_OPT__SpecOutput2_def F_DPDA_EC__SpecInput_def F_DPDA_EC__F_DPDA_EUML__SpecOutput_def F_DPDA_EC__F_DPDA_OTS__SpecOutput_def)\n   apply(clarsimp)\n   apply(rename_tac S' Pa x y)(*strict*)\n   apply(subgoal_tac \"epdaH.unmarked_language (F_DPDA_EA_OPT S') = epdaH.unmarked_language S'\")\n    apply(rename_tac S' Pa x y)(*strict*)\n    prefer 2\n    apply(rule_tac\n      t=\"epdaH.unmarked_language S'\"\n      and s=\"epdaS.unmarked_language S'\"\n      in subst)\n     apply(rename_tac S' Pa x y)(*strict*)\n     apply(rule epdaS_to_epdaH_unmarked_language)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rename_tac S' Pa x y)(*strict*)\n    apply(rule_tac\n      t=\"epdaH.unmarked_language (F_DPDA_EA_OPT S')\"\n      and s=\"epdaS.unmarked_language (F_DPDA_EA_OPT S')\"\n      in subst)\n     apply(rename_tac S' Pa x y)(*strict*)\n     apply(rule epdaS_to_epdaH_unmarked_language)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rename_tac S' Pa x y)(*strict*)\n    apply(force)\n   apply(rename_tac S' Pa x y)(*strict*)\n   apply(subgoal_tac \"epdaH.marked_language (F_DPDA_EA_OPT S') = epdaH.marked_language S'\")\n    apply(rename_tac S' Pa x y)(*strict*)\n    prefer 2\n    apply(rule_tac\n      t=\"epdaH.marked_language S'\"\n      and s=\"epdaS.marked_language S'\"\n      in subst)\n     apply(rename_tac S' Pa x y)(*strict*)\n     apply(rule epdaS_to_epdaH_mlang)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rename_tac S' Pa x y)(*strict*)\n    apply(rule_tac\n      t=\"epdaH.marked_language (F_DPDA_EA_OPT S')\"\n      and s=\"epdaS.marked_language (F_DPDA_EA_OPT S')\"\n      in subst)\n     apply(rename_tac S' Pa x y)(*strict*)\n     apply(rule epdaS_to_epdaH_mlang)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rename_tac S' Pa x y)(*strict*)\n    apply(force)\n   apply(rename_tac S' Pa x y)(*strict*)\n   apply(subgoal_tac \"epda_to_des (F_DPDA_EA_OPT S') = epda_to_des S'\")\n    apply(rename_tac S' Pa x y)(*strict*)\n    prefer 2\n    apply(simp add: epda_to_des_def)\n   apply(rename_tac S' Pa x y)(*strict*)\n   apply(case_tac x)\n    apply(rename_tac S' Pa x y)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac S' Pa x y a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac S' Pa a)(*strict*)\n   apply(rule_tac\n      t=\"epda_operational_controllable S' P \\<Sigma>UC\"\n      and s=\"epda_operational_controllable (F_DPDA_EA_OPT S') P \\<Sigma>UC\"\n      in ssubst)\n    apply(rename_tac S' Pa a)(*strict*)\n    apply(rule epda_Cont_eq_to_epda_operational_controllable_eq2)\n       apply(rename_tac S' Pa a)(*strict*)\n       apply(simp add: F_DPDA_EC__SpecInput_def FUN_DPDA_DFA_PRODUCT__SpecOutput2_def)\n      apply(rename_tac S' Pa a)(*strict*)\n      apply(simp add: F_DPDA_EC__SpecInput_def FUN_DPDA_DFA_PRODUCT__SpecOutput2_def)\n     apply(rename_tac S' Pa a)(*strict*)\n     apply(simp add: F_DPDA_EC__SpecInput_def FUN_DPDA_DFA_PRODUCT__SpecOutput2_def)\n    apply(rename_tac S' Pa a)(*strict*)\n    apply(simp add: F_DPDA_EC__SpecInput_def FUN_DPDA_DFA_PRODUCT__SpecOutput2_def)\n   apply(rename_tac S' Pa a)(*strict*)\n   apply(force)\n  apply(rename_tac S' X)(*strict*)\n  apply(thin_tac \"F_DPDA_EC__F_DPDA_EA_OPT__SpecInput S' (S, P)\")\n  apply(clarsimp)\n  apply(rename_tac X)(*strict*)\n  apply(rename_tac S')\n  apply(rename_tac S')(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac S')(*strict*)\n   prefer 2\n   apply(rule_tac\n      S=\"S'\"\n      and P=\"P\"\n      and \\<Sigma>UC=\"\\<Sigma>UC\"\n      in F_DPDA_RCS__SOUND)\n   apply(simp add: F_DPDA_EC__F_DPDA_RCS__SpecInput_def F_DPDA_RCS__SpecInput_def)\n  apply(rename_tac S')(*strict*)\n  apply(case_tac \"F_DPDA_RCS S' P \\<Sigma>UC\")\n  apply(rename_tac S' a b)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n   apply(rename_tac S' a b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac S' b)(*strict*)\n   apply(simp add: F_DPDA_EC__F_DPDA_EA_OPT__SpecOutput_def F_DPDA_EC__F_DPDA_RCS__SpecOutput_def F_DPDA_RCS__SpecOutput_def F_DPDA_EC__F_DPDA_RCS__SpecInput_def F_DPDA_EC__SpecInput_def F_DPDA_EC__F_DPDA_EUML__SpecOutput_def F_DPDA_EC__F_DPDA_OTS__SpecOutput_def)\n  apply(rename_tac S' a b aa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac S' b aa)(*strict*)\n  apply(thin_tac \"F_DPDA_RCS S' P \\<Sigma>UC = (Some aa, b)\")\n  apply(rename_tac S' b aa)(*strict*)\n  apply(simp add: F_DPDA_EC__F_DPDA_EA_OPT__SpecOutput_def F_DPDA_EC__F_DPDA_RCS__SpecOutput_def)\n  apply(case_tac b)\n   apply(rename_tac S' b aa)(*strict*)\n   apply(clarsimp)\n   apply(simp only: F_DPDA_EC__SpecInput_def F_DPDA_EC__F_DPDA_RCS__SpecInput_def F_DPDA_EC__F_DPDA_RCS__SpecOutput_def F_DPDA_EC__F_DPDA_EA_OPT__SpecOutput_def F_DPDA_RCS__SpecOutput_def F_DPDA_EC__F_DPDA_EUML__SpecOutput_def F_DPDA_EC__F_DPDA_OTS__SpecOutput_def)\n   apply(clarsimp)\n  apply(rename_tac S' b aa)(*strict*)\n  apply(clarsimp)\n  apply(simp only: F_DPDA_EC__SpecInput_def F_DPDA_EC__F_DPDA_RCS__SpecInput_def F_DPDA_EC__F_DPDA_RCS__SpecOutput_def F_DPDA_EC__F_DPDA_EA_OPT__SpecOutput_def F_DPDA_RCS__SpecOutput_def F_DPDA_EC__F_DPDA_EUML__SpecOutput_def F_DPDA_EC__F_DPDA_OTS__SpecOutput_def)\n  apply(clarsimp)\n  apply(rename_tac S'')\n  apply(rename_tac S' b S'')(*strict*)\n  apply(rule context_conjI)\n   apply(rename_tac S' b S'')(*strict*)\n   apply(rule F_EPDA_TC__preserves_DPDA)\n   apply(force)\n  apply(rename_tac S' b S'')(*strict*)\n  apply(rule context_conjI)\n   apply(rename_tac S' b S'')(*strict*)\n   apply(simp add: epda_to_des_def)\n   apply(rule conjI)\n    apply(rename_tac S' b S'')(*strict*)\n    apply(rule_tac\n      t=\"epdaH.unmarked_language S''\"\n      and s=\"epdaS.unmarked_language S''\"\n      in subst)\n     apply(rename_tac S' b S'')(*strict*)\n     apply(rule epdaS_to_epdaH_unmarked_language)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rename_tac S' b S'')(*strict*)\n    apply(rule_tac\n      t=\"epdaH.unmarked_language (F_EPDA_TC S'')\"\n      and s=\"epdaS.unmarked_language (F_EPDA_TC S'')\"\n      in subst)\n     apply(rename_tac S' b S'')(*strict*)\n     apply(rule epdaS_to_epdaH_unmarked_language)\n     apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n    apply(rename_tac S' b S'')(*strict*)\n    apply(rule F_EPDA_TC__preserves_unmarked_language)\n    apply (metis valid_dpda_to_valid_pda)\n   apply(rename_tac S' b S'')(*strict*)\n   apply(rule_tac\n      t=\"epdaH.marked_language S''\"\n      and s=\"epdaS.marked_language S''\"\n      in subst)\n    apply(rename_tac S' b S'')(*strict*)\n    apply(rule epdaS_to_epdaH_mlang)\n    apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n   apply(rename_tac S' b S'')(*strict*)\n   apply(rule_tac\n      t=\"epdaH.marked_language (F_EPDA_TC S'')\"\n      and s=\"epdaS.marked_language (F_EPDA_TC S'')\"\n      in subst)\n    apply(rename_tac S' b S'')(*strict*)\n    apply(rule epdaS_to_epdaH_mlang)\n    apply (metis valid_dpda_to_valid_pda PDA_to_epda)\n   apply(rename_tac S' b S'')(*strict*)\n   apply(rule F_EPDA_TC__preserves_lang)\n   apply (metis valid_dpda_to_valid_pda)\n  apply(rename_tac S' b S'')(*strict*)\n  apply(rule conjI)\n   apply(rename_tac S' b S'')(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac S' b S'')(*strict*)\n  apply(rule F_EPDA_TC__preserves_no_livelock)\n   apply(rename_tac S' b S'')(*strict*)\n   apply (metis valid_dpda_to_valid_pda)\n  apply(rename_tac S' b S'')(*strict*)\n  apply(force)\n  done\n\nend\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_13_06/FUNCTION_CONT__Enforce_Controllability.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297745935070806, "lm_q2_score": 0.4225046348141882, "lm_q1q2_score": 0.26608268464496293}}
{"text": "theory Compiler imports Compiler1 Compiler2 begin\n\ndefinition J2JVM :: \"'addr J_prog \\<Rightarrow> 'addr jvm_prog\"\nwhere [code del]: \"J2JVM \\<equiv> compP2 \\<circ> compP1\"\n\nlemma J2JVM_code [code]:\n  \"J2JVM = compP (\\<lambda>C M Ts T (pns, body). compMb2 (compE1 (this#pns) body))\"\nby(simp add: J2JVM_def compP2_def o_def compP_compP split_def)\n\nend", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/JinjaThreads/Compiler/Compiler.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631840431539, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.26604922152065086}}
{"text": "theory LocalChurchRosser\n  imports DirectDerivation\nbegin\n(* Fund. Alg. GT, PDF. P. 117\nhttps://link.springer.com/content/pdf/10.1007/3-540-31188-2.pdf?pdf=button\n *)\n(*  declare [[show_sorts]]\n *) \nlocale parallel_independence =\n  p\\<^sub>1: direct_derivation r\\<^sub>1 b\\<^sub>1 b\\<^sub>1' G g\\<^sub>1 D\\<^sub>1 m\\<^sub>1 c\\<^sub>1 H\\<^sub>1 f\\<^sub>1 h\\<^sub>1 +\n  p\\<^sub>2: direct_derivation r\\<^sub>2 b\\<^sub>2 b\\<^sub>2' G g\\<^sub>2 D\\<^sub>2 m\\<^sub>2 c\\<^sub>2 H\\<^sub>2 f\\<^sub>2 h\\<^sub>2\n  for r\\<^sub>1 b\\<^sub>1 b\\<^sub>1' G g\\<^sub>1 D\\<^sub>1 m\\<^sub>1 c\\<^sub>1 H\\<^sub>1 f\\<^sub>1 h\\<^sub>1 r\\<^sub>2 b\\<^sub>2 b\\<^sub>2' g\\<^sub>2 D\\<^sub>2 m\\<^sub>2 c\\<^sub>2 H\\<^sub>2 f\\<^sub>2 h\\<^sub>2 +\n  assumes\n    i: \\<open>\\<exists>i. morphism (lhs r\\<^sub>1) D\\<^sub>2 i \\<and> (\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>1\\<^esub>\\<^sub>V v) \\<and> (\\<forall>e \\<in> E\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^esub>\\<^sub>E e = \\<^bsub>g\\<^sub>1\\<^esub>\\<^sub>E e)\\<close> and\n    j: \\<open>\\<exists>j. morphism (lhs r\\<^sub>2) D\\<^sub>1 j \\<and> (\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> j\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>V v) \\<and> (\\<forall>e \\<in> E\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> j\\<^esub>\\<^sub>E e = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>E e)\\<close>\n\n\nlocale sequential_independence =\n  p\\<^sub>1: direct_derivation r\\<^sub>1 b\\<^sub>1 b\\<^sub>1' G g\\<^sub>1 D\\<^sub>1 m\\<^sub>1 c\\<^sub>1 H\\<^sub>1 f\\<^sub>1 h\\<^sub>1 +\n  p\\<^sub>2: direct_derivation r\\<^sub>2 b\\<^sub>2 b\\<^sub>2' H\\<^sub>1 g\\<^sub>2 D\\<^sub>2 m\\<^sub>2 c\\<^sub>2 H\\<^sub>2 f\\<^sub>2 h\\<^sub>2\n  for r\\<^sub>1 b\\<^sub>1 b\\<^sub>1' G g\\<^sub>1 D\\<^sub>1 m\\<^sub>1 c\\<^sub>1 H\\<^sub>1 f\\<^sub>1 h\\<^sub>1 r\\<^sub>2 b\\<^sub>2 b\\<^sub>2' g\\<^sub>2 D\\<^sub>2 m\\<^sub>2 c\\<^sub>2 H\\<^sub>2 f\\<^sub>2 h\\<^sub>2 +\n  assumes\n    i: \\<open>\\<exists>i. morphism (rhs r\\<^sub>1) D\\<^sub>2 i \\<and> (\\<forall>v \\<in> V\\<^bsub>rhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>V v) \\<and> (\\<forall>e \\<in> E\\<^bsub>rhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>E e)\\<close> and\n    j: \\<open>\\<exists>j. morphism (lhs r\\<^sub>2) D\\<^sub>1 j \\<and> (\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> j\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>V v) \\<and> (\\<forall>e \\<in> E\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> j\\<^esub>\\<^sub>E e = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>E e)\\<close> \n\n\n\ntheorem (in parallel_independence) church_rosser_1:\n  shows \\<open>\\<exists>(g' ::('o, 'm, 'p, 'n) pre_morph)\n           (D' :: ('k \\<times> 'u + 'e, 'l \\<times> 'v + 'f, 'g, 'h) pre_graph) \n           (m':: ('q, 'k \\<times> 'u + 'e, 'r, 'l \\<times> 'v + 'f) pre_morph)\n           (c':: ('k \\<times> 'u + 'e, 'm, 'l \\<times> 'v + 'f, 'n) pre_morph)\n           (H :: (('k \\<times> 'u + 's) + 'k \\<times> 'u + 'e, ('l \\<times> 'v + 't) + 'l \\<times> 'v + 'f, 'g, 'h) pre_graph)\n           (f':: ('s, ('k \\<times> 'u + 's) + 'k \\<times> 'u + 'e, 't, ('l \\<times> 'v + 't) + 'l \\<times> 'v + 'f) pre_morph)\n            h' \n            (g'')\n             (D'' ::('k \\<times> 'u + 's, 'l \\<times> 'v + 't, 'g, 'h) pre_graph)\n              m'' c'' \n            (H :: (('k \\<times> 'u + 's) + 'k \\<times> 'u + 'e, ('l \\<times> 'v + 't) + 'l \\<times> 'v + 'f, 'g, 'h) pre_graph)\n             f'' h''. \n                  sequential_independence r\\<^sub>1 b\\<^sub>1 b\\<^sub>1' G g\\<^sub>1 D\\<^sub>1 m\\<^sub>1 c\\<^sub>1 H\\<^sub>1 f\\<^sub>1 h\\<^sub>1 r\\<^sub>2 b\\<^sub>2 b\\<^sub>2' g' D' m' c' H f' h'\n                \\<and> sequential_independence r\\<^sub>2 b\\<^sub>2 b\\<^sub>2' G g\\<^sub>2 D\\<^sub>2 m\\<^sub>2 c\\<^sub>2 H\\<^sub>2 f\\<^sub>2 h\\<^sub>2 r\\<^sub>1 b\\<^sub>1 b\\<^sub>1' g'' D'' m'' c'' H f'' h''\\<close>\nproof -\n\n  interpret c\\<^sub>1: injective_morphism D\\<^sub>1 G c\\<^sub>1\n    using p\\<^sub>1.po1.b_inj_imp_g_inj p\\<^sub>1.r.k.injective_morphism_axioms by blast\n  interpret c\\<^sub>2: injective_morphism D\\<^sub>2 G c\\<^sub>2\n    using p\\<^sub>2.po1.b_inj_imp_g_inj p\\<^sub>2.r.k.injective_morphism_axioms by blast\n\n  interpret h\\<^sub>1: injective_morphism D\\<^sub>1 H\\<^sub>1 h\\<^sub>1\n    using p\\<^sub>1.po2.b_inj_imp_g_inj p\\<^sub>1.r.r.injective_morphism_axioms by blast\n  interpret h\\<^sub>2: injective_morphism D\\<^sub>2 H\\<^sub>2 h\\<^sub>2\n    using p\\<^sub>2.po2.b_inj_imp_g_inj p\\<^sub>2.r.r.injective_morphism_axioms by blast\n\n  obtain i\\<^sub>1 i\\<^sub>2 where \\<open>morphism (lhs r\\<^sub>1) D\\<^sub>2 i\\<^sub>1\\<close>  \n                      \\<open>\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>1\\<^esub>\\<^sub>V v\\<close> \\<open>\\<forall>e \\<in> E\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>g\\<^sub>1\\<^esub>\\<^sub>E e\\<close> and\n                     \\<open>morphism (lhs r\\<^sub>2) D\\<^sub>1 i\\<^sub>2\\<close>  \n                      \\<open>\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>V v\\<close> \\<open>\\<forall>e \\<in> E\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n    using i j by auto\n\n  interpret i\\<^sub>1: morphism \"lhs r\\<^sub>1\" D\\<^sub>2 i\\<^sub>1 \n    using \\<open>morphism (lhs r\\<^sub>1) D\\<^sub>2 i\\<^sub>1\\<close> by assumption\n\n  interpret i\\<^sub>1: injective_morphism \"lhs r\\<^sub>1\" D\\<^sub>2 i\\<^sub>1    \n  proof\n    show \\<open>inj_on \\<^bsub>i\\<^sub>1\\<^esub>\\<^sub>V V\\<^bsub>lhs r\\<^sub>1\\<^esub>\\<close>\n      using \\<open>\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>1\\<^esub>\\<^sub>V v\\<close>\n        c\\<^sub>2.inj_nodes p\\<^sub>1.gi.inj_nodes\n      by (simp add: inj_on_def morph_comp_def) metis\n  next\n    show \\<open>inj_on \\<^bsub>i\\<^sub>1\\<^esub>\\<^sub>E E\\<^bsub>lhs r\\<^sub>1\\<^esub>\\<close>\n      using \\<open>\\<forall>e \\<in> E\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>g\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n        c\\<^sub>2.inj_edges p\\<^sub>1.gi.inj_edges\n      by (simp add: inj_on_def morph_comp_def) metis\n  qed\n\n  interpret i\\<^sub>2: morphism \"lhs r\\<^sub>2\" D\\<^sub>1 i\\<^sub>2\n    using \\<open>morphism (lhs r\\<^sub>2) D\\<^sub>1 i\\<^sub>2\\<close>\n    by assumption\n\n  interpret i\\<^sub>2: injective_morphism \"lhs r\\<^sub>2\" D\\<^sub>1 i\\<^sub>2\n  proof\n    show \\<open>inj_on \\<^bsub>i\\<^sub>2\\<^esub>\\<^sub>V V\\<^bsub>lhs r\\<^sub>2\\<^esub>\\<close>\n      using \\<open>\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>V v\\<close>\n        c\\<^sub>1.inj_nodes p\\<^sub>2.gi.inj_nodes\n      by (simp add: inj_on_def morph_comp_def) metis\n  next\n    show \\<open>inj_on \\<^bsub>i\\<^sub>2\\<^esub>\\<^sub>E E\\<^bsub>lhs r\\<^sub>2\\<^esub>\\<close>\n      using \\<open>\\<forall>e \\<in> E\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n        c\\<^sub>1.inj_edges p\\<^sub>2.gi.inj_edges\n      by (simp add: inj_on_def morph_comp_def) metis\n  qed\n\n  interpret pb: pullback_construction D\\<^sub>1 G D\\<^sub>2 c\\<^sub>1 c\\<^sub>2 ..\n\n  interpret wf_b\\<^sub>1i\\<^sub>1: morphism \"interf r\\<^sub>1\" D\\<^sub>2 \"i\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>1\"\n    using wf_morph_comp[OF p\\<^sub>1.r.k.morphism_axioms i\\<^sub>1.morphism_axioms]\n    by assumption\n\n(* j1 start *)\n  have a: \\<open>\\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> m\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> (i\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>1)\\<^esub>\\<^sub>V v\\<close> if \\<open>v \\<in> V\\<^bsub>interf r\\<^sub>1\\<^esub>\\<close> for v\n    using that pb.pb.node_commutativity  \\<open>\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>1\\<^esub>\\<^sub>V v\\<close>\n      p\\<^sub>1.po1.node_commutativity p\\<^sub>1.r.k.morph_node_range\n    by (simp add: morph_comp_def pb.b_def pb.c_def pb.A_def)\n  have b: \\<open>\\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> m\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> (i\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>1)\\<^esub>\\<^sub>E e\\<close> if \\<open>e \\<in> E\\<^bsub>interf r\\<^sub>1\\<^esub>\\<close> for e\n    using that pb.pb.edge_commutativity  \\<open>\\<forall>e \\<in> E\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>g\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n      p\\<^sub>1.po1.edge_commutativity p\\<^sub>1.r.k.morph_edge_range\n    by (simp add: morph_comp_def pb.b_def pb.c_def pb.A_def)\n\n\n  obtain j\\<^sub>1 where \\<open>morphism (interf r\\<^sub>1) pb.A j\\<^sub>1\\<close>\n    and \\<open>\\<And>v. v\\<in>V\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>m\\<^sub>1\\<^esub>\\<^sub>V v\\<close> \\<open>\\<And>e. e\\<in>E\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>m\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n    and \\<open>\\<And>v. v\\<in>V\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>i\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>1\\<^esub>\\<^sub>V v\\<close>  \\<open>\\<And>e. e\\<in>E\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>i\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n    using pb.pb.universal_property_exist_gen[OF p\\<^sub>1.r.k.G.graph_axioms wf_b\\<^sub>1i\\<^sub>1.morphism_axioms p\\<^sub>1.po1.c.morphism_axioms a b]\n    by fast\n\n  interpret j\\<^sub>1: morphism \"interf r\\<^sub>1\" pb.A j\\<^sub>1\n    using \\<open>morphism (interf r\\<^sub>1) pb.A j\\<^sub>1\\<close> \n    by assumption\n  interpret j\\<^sub>1: injective_morphism \"interf r\\<^sub>1\" pb.A j\\<^sub>1\n  proof\n    show \\<open>inj_on \\<^bsub>j\\<^sub>1\\<^esub>\\<^sub>V V\\<^bsub>interf r\\<^sub>1\\<^esub>\\<close>\n      using \\<open>\\<And>v. v\\<in>V\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>m\\<^sub>1\\<^esub>\\<^sub>V v\\<close> p\\<^sub>1.d_inj.inj_nodes\n      by (simp add: morph_comp_def inj_on_def) metis\n  next\n    show \\<open>inj_on \\<^bsub>j\\<^sub>1\\<^esub>\\<^sub>E E\\<^bsub>interf r\\<^sub>1\\<^esub>\\<close>\n      using \\<open>\\<And>e. e\\<in>E\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>m\\<^sub>1\\<^esub>\\<^sub>E e\\<close> p\\<^sub>1.d_inj.inj_edges\n      by (simp add: morph_comp_def inj_on_def) metis\n  qed\n     \n(* j2 start *)\n\n  interpret b\\<^sub>2i\\<^sub>2: morphism \"interf r\\<^sub>2\" D\\<^sub>1 \"i\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>2\"\n    using wf_morph_comp[OF p\\<^sub>2.r.k.morphism_axioms i\\<^sub>2.morphism_axioms]\n    by assumption\n\n\n  have a: \\<open>\\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> (i\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>2)\\<^esub>\\<^sub>V v = \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> m\\<^sub>2\\<^esub>\\<^sub>V v\\<close> if \\<open>v \\<in> V\\<^bsub>interf r\\<^sub>2\\<^esub>\\<close> for v\n    using pb.pb.node_commutativity  \\<open>\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>V v\\<close>\n      p\\<^sub>2.po1.node_commutativity p\\<^sub>2.r.k.morph_node_range that\n    by (simp add: morph_comp_def pb.b_def pb.c_def pb.A_def)\n\n  have b: \\<open>\\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> (i\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>2)\\<^esub>\\<^sub>E e = \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> m\\<^sub>2\\<^esub>\\<^sub>E e\\<close> if \\<open>e \\<in> E\\<^bsub>interf r\\<^sub>2\\<^esub>\\<close> for e\n    using pb.pb.edge_commutativity  \\<open>\\<forall>e \\<in> E\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n      p\\<^sub>2.po1.edge_commutativity p\\<^sub>2.r.k.morph_edge_range that\n    by (simp add: morph_comp_def pb.b_def pb.c_def pb.A_def)\n\n  obtain j\\<^sub>2 where \\<open>morphism (interf r\\<^sub>2) pb.A j\\<^sub>2\\<close>\n    and \\<open>\\<And>v. v\\<in>V\\<^bsub>interf r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>m\\<^sub>2\\<^esub>\\<^sub>V v\\<close> \\<open>\\<And>e. e\\<in>E\\<^bsub>interf r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>m\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n    and j2c: \\<open>\\<And>v. v\\<in>V\\<^bsub>interf r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>i\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>2\\<^esub>\\<^sub>V v\\<close>  \\<open>\\<And>e. e\\<in>E\\<^bsub>interf r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>i\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n    using pb.pb.universal_property_exist_gen[OF p\\<^sub>2.r.k.G.graph_axioms p\\<^sub>2.po1.c.morphism_axioms b\\<^sub>2i\\<^sub>2.morphism_axioms a b]\n    by fast\n  interpret j\\<^sub>2: morphism \"interf r\\<^sub>2\" pb.A j\\<^sub>2\n    using \\<open>morphism (interf r\\<^sub>2) pb.A j\\<^sub>2\\<close> \n    by assumption\n\n  interpret j\\<^sub>2: injective_morphism \"interf r\\<^sub>2\" pb.A j\\<^sub>2\n  proof\n    show \\<open>inj_on \\<^bsub>j\\<^sub>2\\<^esub>\\<^sub>V V\\<^bsub>interf r\\<^sub>2\\<^esub>\\<close>\n      using \\<open>\\<And>v. v\\<in>V\\<^bsub>interf r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>m\\<^sub>2\\<^esub>\\<^sub>V v\\<close>  p\\<^sub>2.d_inj.inj_nodes\n      by (simp add: morph_comp_def inj_on_def) metis\n  next\n    show \\<open>inj_on \\<^bsub>j\\<^sub>2\\<^esub>\\<^sub>E E\\<^bsub>interf r\\<^sub>2\\<^esub>\\<close>\n      using \\<open>\\<And>e. e\\<in>E\\<^bsub>interf r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>m\\<^sub>2\\<^esub>\\<^sub>E e\\<close>  p\\<^sub>2.d_inj.inj_edges\n      by (simp add: morph_comp_def inj_on_def) metis\n  qed\n\n(* commutativity *)\n\n  interpret morphism \"interf r\\<^sub>1\" D\\<^sub>1 \"pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\"\n    using wf_morph_comp[OF j\\<^sub>1.morphism_axioms pb.b.morphism_axioms]\n    by assumption\n  interpret morphism \"lhs r\\<^sub>1\" G \"c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\"\n    using wf_morph_comp[OF i\\<^sub>1.morphism_axioms p\\<^sub>2.po1.g.morphism_axioms]\n    by assumption\n\n\n  interpret \"6+5\": pushout_diagram \"interf r\\<^sub>1\" D\\<^sub>1 \"lhs r\\<^sub>1\" G \"pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\" b\\<^sub>1 c\\<^sub>1 \"c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\"\n  proof \n    show \\<open>\\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> (pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1)\\<^esub>\\<^sub>V v = \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>1\\<^esub>\\<^sub>V v\\<close> if \\<open>v \\<in> V\\<^bsub>interf r\\<^sub>1\\<^esub>\\<close> for v\n      using that p\\<^sub>1.po1.node_commutativity \\<open>\\<And>v. v\\<in>V\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>m\\<^sub>1\\<^esub>\\<^sub>V v\\<close>\n        \\<open>\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>1\\<^esub>\\<^sub>V v\\<close>  p\\<^sub>1.r.k.morph_node_range\n      by (simp add: morph_comp_def)\n  next\n    show \\<open>\\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> (pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1)\\<^esub>\\<^sub>E e = \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>1\\<^esub>\\<^sub>E e\\<close> if \\<open>e \\<in> E\\<^bsub>interf r\\<^sub>1\\<^esub>\\<close> for e\n      using that p\\<^sub>1.po1.edge_commutativity \\<open>\\<And>e. e\\<in>E\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>m\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n        \\<open>\\<forall>e \\<in> E\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>g\\<^sub>1\\<^esub>\\<^sub>E e\\<close>  p\\<^sub>1.r.k.morph_edge_range\n      by (simp add: morph_comp_def)\n  next\n    show \\<open>Ex1M\n        (\\<lambda>xa. morphism (to_ngraph G) D' xa \\<and>\n               (\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>xa \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v) \\<and>\n               (\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>xa \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e) \\<and>\n               (\\<forall>v\\<in>V\\<^bsub>to_ngraph (lhs r\\<^sub>1)\\<^esub>. \\<^bsub>xa \\<circ>\\<^sub>\\<rightarrow> to_nmorph (c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1)\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v) \\<and>\n               (\\<forall>e\\<in>E\\<^bsub>to_ngraph (lhs r\\<^sub>1)\\<^esub>. \\<^bsub>xa \\<circ>\\<^sub>\\<rightarrow> to_nmorph (c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1)\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e))\n        (to_ngraph G)\\<close> if \\<open>graph D'\\<close> \\<open>morphism (to_ngraph (lhs r\\<^sub>1)) D' y\\<close> \\<open>morphism (to_ngraph D\\<^sub>1) D' x\\<close>\n        \n       \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (interf r\\<^sub>1)\\<^esub>. \\<^bsub>x \\<circ>\\<^sub>\\<rightarrow> to_nmorph (pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1)\\<^esub>\\<^sub>V v = \\<^bsub>y \\<circ>\\<^sub>\\<rightarrow> to_nmorph b\\<^sub>1\\<^esub>\\<^sub>V v\\<close>\n       \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (interf r\\<^sub>1)\\<^esub>. \\<^bsub>x \\<circ>\\<^sub>\\<rightarrow> to_nmorph (pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1)\\<^esub>\\<^sub>E e = \\<^bsub>y \\<circ>\\<^sub>\\<rightarrow> to_nmorph b\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n     for D' :: \"('g,'h) ngraph\" and x y\n    proof -\n\n      have \\<open>\\<^bsub>pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>m\\<^sub>1\\<^esub>\\<^sub>V v\\<close> if \\<open>v \\<in> V\\<^bsub>interf r\\<^sub>1\\<^esub>\\<close> for v\n        using that \\<open>\\<And>v. v\\<in>V\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>m\\<^sub>1\\<^esub>\\<^sub>V v\\<close> \n                   \\<open>\\<And>e. e\\<in>E\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>m\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n        by (simp add: morph_comp_def)\n\n      have \\<open>\\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>1\\<^esub>\\<^sub>V v\\<close> if \\<open>v \\<in> V\\<^bsub>lhs r\\<^sub>1\\<^esub>\\<close> for v\n        using that \\<open>\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>1\\<^esub>\\<^sub>V v\\<close> \n        by (simp add: morph_comp_def)\n\n(*  from here: *)\n\n      have a: \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (interf r\\<^sub>1)\\<^esub>. \\<^bsub>y \\<circ>\\<^sub>\\<rightarrow> to_nmorph b\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>x \\<circ>\\<^sub>\\<rightarrow> to_nmorph m\\<^sub>1\\<^esub>\\<^sub>V v\\<close>\n        using \\<open>\\<And>v. v\\<in>V\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>m\\<^sub>1\\<^esub>\\<^sub>V v\\<close>\n         \\<open>\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>1\\<^esub>\\<^sub>V v\\<close> that\n        by (simp add: morph_comp_def to_ngraph_def to_nmorph_def) \n      have b: \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (interf r\\<^sub>1)\\<^esub>. \\<^bsub>y \\<circ>\\<^sub>\\<rightarrow> to_nmorph b\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>x \\<circ>\\<^sub>\\<rightarrow> to_nmorph m\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n        using \\<open>\\<And>e. e\\<in>E\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>m\\<^sub>1\\<^esub>\\<^sub>E e\\<close>   \\<open>\\<forall>e \\<in> E\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>g\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n          that\n        by (simp add: morph_comp_def to_ngraph_def to_nmorph_def) \n\n      obtain u where \\<open>morphism (to_ngraph G) D' u\\<close>\n        and aa1: \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (lhs r\\<^sub>1)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close> \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (lhs r\\<^sub>1)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n        and aa2: \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close> \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n        using p\\<^sub>1.po1.universal_property[OF  \\<open>graph D'\\<close> \\<open>morphism (to_ngraph (lhs r\\<^sub>1)) D' y\\<close> \\<open>morphism (to_ngraph D\\<^sub>1) D' x\\<close> a b]\n        by fast\n\n\n(* used for technical reasons within the upcoming proof *)\n      have n: \\<open>morphism (to_ngraph G) D' u \\<and>\n            (\\<forall>v\\<in>V\\<^bsub>to_ngraph (lhs r\\<^sub>1)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v) \\<and>\n            (\\<forall>e\\<in>E\\<^bsub>to_ngraph (lhs r\\<^sub>1)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e) \\<and> (\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v) \\<and> (\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e)\\<close>\n            using \\<open>morphism (to_ngraph G) D' u\\<close> aa1(1) aa1(2) aa2(1) aa2(2) by force\n\n\n      show ?thesis\n      proof (rule_tac x = u in exI, safe)\n        show \\<open>morphism (to_ngraph G) D' u\\<close>\n          using \\<open>morphism (to_ngraph G) D' u\\<close> by assumption\n      next\n        show \\<open>\\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close> if \\<open>v \\<in> V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>\\<close> for v\n          using that \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close> \n          by simp\n      next\n        show \\<open>\\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close> if \\<open>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>\\<close> for e\n          using \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close> that \n          by simp\n      next\n        show \\<open>\\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph (c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1)\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close> if \\<open>v\\<in>V\\<^bsub>to_ngraph (lhs r\\<^sub>1)\\<^esub>\\<close> for v\n          using aa1(1)  \\<open>\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>1\\<^esub>\\<^sub>V v\\<close> that\n          by (auto simp add: to_nmorph_def morph_comp_def to_ngraph_def)\n      next\n        show \\<open>\\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph (c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1)\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close> if \\<open>e\\<in>E\\<^bsub>to_ngraph (lhs r\\<^sub>1)\\<^esub>\\<close> for e\n          using aa1(2)  \\<open>\\<forall>e \\<in> E\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>g\\<^sub>1\\<^esub>\\<^sub>E e\\<close> that\n          by (auto simp add: to_nmorph_def morph_comp_def to_ngraph_def)\n      next\n        show \\<open>\\<^bsub>ya\\<^esub>\\<^sub>E e = \\<^bsub>u\\<^esub>\\<^sub>E e\\<close>\n          if \\<open>morphism (to_ngraph G) D' ya\\<close>\n             \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close> \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n             \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (lhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph (c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1)\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close> \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (lhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph (c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1)\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n             \\<open> e \\<in> E\\<^bsub>to_ngraph G\\<^esub>\\<close>\n           for ya  e\n        proof -\n          have m:\\<open>morphism (to_ngraph G) D' ya \\<and>\n            (\\<forall>v\\<in>V\\<^bsub>to_ngraph (lhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v) \\<and>\n            (\\<forall>e\\<in>E\\<^bsub>to_ngraph (lhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e) \\<and> (\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v) \\<and> (\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e)\\<close>\n            using that\n          proof (intro conjI)\n            show \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (lhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close>\n              using \\<open>\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>1\\<^esub>\\<^sub>V v\\<close> that\n              by (simp add: morph_comp_def to_ngraph_def to_nmorph_def)\n          next\n            show \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (lhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n              using that \\<open>\\<forall>e \\<in> E\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>g\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n              by (simp add: morph_comp_def to_ngraph_def to_nmorph_def)\n          qed assumption\n\n          show ?thesis\n            using ex_eq[OF p\\<^sub>1.po1.universal_property[OF  \\<open>graph D'\\<close> \\<open>morphism (to_ngraph (lhs r\\<^sub>1)) D' y\\<close> \\<open>morphism (to_ngraph D\\<^sub>1) D' x\\<close> a b], OF n m] that\n            by simp\n        qed\n      next\n        show \\<open>\\<^bsub>ya\\<^esub>\\<^sub>V v = \\<^bsub>u\\<^esub>\\<^sub>V v\\<close>\n          if \\<open>morphism (to_ngraph G) D' ya\\<close>\n             \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close> \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n             \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (lhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph (c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1)\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close> \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (lhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph (c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1)\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n             \\<open>v \\<in> V\\<^bsub>to_ngraph G\\<^esub>\\<close>\n           for ya v\n        proof -\n          have m:\\<open>morphism (to_ngraph G) D' ya \\<and>\n            (\\<forall>v\\<in>V\\<^bsub>to_ngraph (lhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v) \\<and>\n            (\\<forall>e\\<in>E\\<^bsub>to_ngraph (lhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e) \\<and> (\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v) \\<and> (\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e)\\<close>\n            using that\n          proof (intro conjI)\n            show \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (lhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close>\n              using \\<open>\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>1\\<^esub>\\<^sub>V v\\<close> that\n              by (simp add: morph_comp_def to_ngraph_def to_nmorph_def)\n          next\n            show \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (lhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n              using that \\<open>\\<forall>e \\<in> E\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>g\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n              by (simp add: morph_comp_def to_ngraph_def to_nmorph_def)\n          qed assumption\n\n          show ?thesis\n            using ex_eq[OF p\\<^sub>1.po1.universal_property[OF  \\<open>graph D'\\<close> \\<open>morphism (to_ngraph (lhs r\\<^sub>1)) D' y\\<close> \\<open>morphism (to_ngraph D\\<^sub>1) D' x\\<close> a b], OF n m] that\n            by simp\n        qed\n      qed\n    qed\n  qed\n    \n\n(* show pb is also a pushout *)\n   interpret  inj_k: injective_morphism pb.A D\\<^sub>1 pb.b\n    using  pb.pb.g_inj_imp_b_inj[OF c\\<^sub>2.injective_morphism_axioms]\n    by assumption\n\n  interpret ink_l: injective_morphism pb.A D\\<^sub>2 pb.c\n    using pullback_diagram.g_inj_imp_b_inj[OF pb.pb.flip_diagram c\\<^sub>1.injective_morphism_axioms]\n    by assumption\n\n  have a: \\<open>\\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>1\\<^esub>\\<^sub>V v\\<close> if \\<open>v \\<in> V\\<^bsub>interf r\\<^sub>1\\<^esub>\\<close> for v\n    using that \"6+5.node_commutativity\"\n    by(simp add: morph_comp_def)\n  have b: \\<open>\\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>1\\<^esub>\\<^sub>E e\\<close> if \\<open>e \\<in> E\\<^bsub>interf r\\<^sub>1\\<^esub>\\<close> for e\n    using that \"6+5.edge_commutativity\"\n    by(simp add: morph_comp_def)\n\n\n(* experiment *)\n(*   have jointly_surj_nodes: \\<open>(\\<exists>v\\<in>V\\<^bsub>D\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>2\\<^esub>\\<^sub>V v = x) \\<or> (\\<exists>v\\<in>V\\<^bsub>D\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>1\\<^esub>\\<^sub>V v = x)\\<close>\n    if \\<open>x \\<in> V\\<^bsub>G\\<^esub>\\<close>  for x\n      using that \"6+5.joint_surjectivity_nodes\" p\\<^sub>1.po1.joint_surjectivity_nodes i\\<^sub>1.morph_node_range\n      by (fastforce simp add: morph_comp_def)\n \n  have jointly_surj_edges: \\<open>(\\<exists>e\\<in>E\\<^bsub>D\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>2\\<^esub>\\<^sub>E e = x) \\<or> (\\<exists>e\\<in>E\\<^bsub>D\\<^sub>1\\<^esub>. \\<^bsub>c\\<^sub>1\\<^esub>\\<^sub>E e = x)\\<close>\n    if \\<open>x \\<in> E\\<^bsub>G\\<^esub>\\<close>  for x\n    using that \"6+5.joint_surjectivity_edges\" p\\<^sub>1.po1.joint_surjectivity_edges i\\<^sub>1.morph_edge_range\n      by (fastforce simp add: morph_comp_def)\n *)\n(*   interpret pb_is_po: pushout_diagram pb.A D\\<^sub>1 D\\<^sub>2 G pb.b pb.c c\\<^sub>1 c\\<^sub>2\n    using po_characterization[OF inj_k.injective_morphism_axioms ink_l.injective_morphism_axioms\n        c\\<^sub>1.injective_morphism_axioms c\\<^sub>2.injective_morphism_axioms\n        pb.pb.node_commutativity pb.pb.edge_commutativity \n        pb.reduced_chain_condition_nodes pb.reduced_chain_condition_edges\n        jointly_surj_nodes jointly_surj_edges]\n    by fast\n *)\n\n(* till here (experiment) *)\n  interpret pbj1: injective_morphism \"interf r\\<^sub>1\" D\\<^sub>1 \"pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\"\n    using inj_comp_inj\n    using \"6+5.flip_diagram\" c\\<^sub>2.injective_morphism_axioms i\\<^sub>1.injective_morphism_axioms p\\<^sub>1.r.k.injective_morphism_axioms pushout_diagram.b_f_inj_imp_c_inj by blast\n\n  interpret \"6+5pb\": pullback_diagram \"interf r\\<^sub>1\" D\\<^sub>1 \"lhs r\\<^sub>1\" G \"pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\" b\\<^sub>1 c\\<^sub>1 \"c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\"\n    using \"6+5.pushout_pullback_inj_b\"[OF pbj1.injective_morphism_axioms]\n    using p\\<^sub>1.r.k.injective_morphism_axioms by fastforce\n\n\n  interpret sixpb: pullback_diagram \"interf r\\<^sub>1\" pb.A \"lhs r\\<^sub>1\" D\\<^sub>2 j\\<^sub>1 b\\<^sub>1 pb.c i\\<^sub>1\n    using pullback_decomposition[OF j\\<^sub>1.morphism_axioms _ pb.pb.pullback_diagram_axioms]\n    using \"6+5pb.pullback_diagram_axioms\" \\<open>\\<And>e. e \\<in> E\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>i\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>1\\<^esub>\\<^sub>E e\\<close> \\<open>\\<And>v. v \\<in> V\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>i\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>1\\<^esub>\\<^sub>V v\\<close> i\\<^sub>1.morphism_axioms by blast\n\n\n(* CLEANUP HERE *)\n\n have jointly_surj_nodes: \\<open>(\\<exists>v\\<in>V\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>i\\<^sub>1\\<^esub>\\<^sub>V v = x) \\<or> (\\<exists>v\\<in>V\\<^bsub>pb.A\\<^esub>. \\<^bsub>pb.c\\<^esub>\\<^sub>V v = x)\\<close>\n   if \\<open>x \\<in> V\\<^bsub>D\\<^sub>2\\<^esub>\\<close>  for x\n   using that c\\<^sub>2.inj_nodes p\\<^sub>2.po1.g.morph_node_range pb.reduced_chain_condition_nodes\n     \"6+5.joint_surjectivity_nodes\" p\\<^sub>1.po1.joint_surjectivity_nodes i\\<^sub>1.morph_node_range\n   by (auto simp add: morph_comp_def inj_on_def) metis\n\n  have jointly_surj_edges: \\<open>(\\<exists>e\\<in>E\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>i\\<^sub>1\\<^esub>\\<^sub>E e = x) \\<or> (\\<exists>e\\<in>E\\<^bsub>pb.A\\<^esub>. \\<^bsub>pb.c\\<^esub>\\<^sub>E e = x)\\<close>\n   if \\<open>x \\<in> E\\<^bsub>D\\<^sub>2\\<^esub>\\<close>  for x\n   using that c\\<^sub>2.inj_edges p\\<^sub>2.po1.g.morph_edge_range pb.reduced_chain_condition_edges\n     \"6+5.joint_surjectivity_edges\" p\\<^sub>1.po1.joint_surjectivity_edges i\\<^sub>1.morph_edge_range\n   by (auto simp add: morph_comp_def inj_on_def) metis\n\n  interpret six: pushout_diagram \"interf r\\<^sub>1\" pb.A \"lhs r\\<^sub>1\" D\\<^sub>2 j\\<^sub>1 b\\<^sub>1 pb.c i\\<^sub>1\n    using po_characterization[OF j\\<^sub>1.injective_morphism_axioms p\\<^sub>1.r.k.injective_morphism_axioms\n        ink_l.injective_morphism_axioms i\\<^sub>1.injective_morphism_axioms\n        \\<open>\\<And>v. v \\<in> V\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>i\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>1\\<^esub>\\<^sub>V v\\<close>\n        \\<open>\\<And>e. e \\<in> E\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>i\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n        sixpb.reduced_chain_condition_nodes sixpb.reduced_chain_condition_edges\n        jointly_surj_nodes jointly_surj_edges]\n    by blast\n\n  interpret morphism \"interf r\\<^sub>2\" D\\<^sub>2 \"pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\"\n    using wf_morph_comp[OF j\\<^sub>2.morphism_axioms pb.c.morphism_axioms]\n    by assumption\n\n  interpret morphism \"lhs r\\<^sub>2\" G \"c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\"\n  proof\n    show \\<open>\\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>E e \\<in> E\\<^bsub>G\\<^esub>\\<close> if \\<open>e \\<in> E\\<^bsub>lhs r\\<^sub>2\\<^esub>\\<close> for e\n      using that i\\<^sub>2.morph_edge_range p\\<^sub>1.po1.g.morph_edge_range\n      by (simp add: morph_comp_def)\n  next\n    show \\<open>\\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>V v \\<in> V\\<^bsub>G\\<^esub>\\<close> if \\<open>v \\<in> V\\<^bsub>lhs r\\<^sub>2\\<^esub>\\<close> for v\n      using that i\\<^sub>2.morph_node_range p\\<^sub>1.po1.g.morph_node_range\n      by (simp add: morph_comp_def)\n  next\n    show \\<open>\\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>V (s\\<^bsub>lhs r\\<^sub>2\\<^esub> e) = s\\<^bsub>G\\<^esub> (\\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>E e)\\<close> if \\<open>e \\<in> E\\<^bsub>lhs r\\<^sub>2\\<^esub>\\<close> for e\n      using that i\\<^sub>2.morph_edge_range i\\<^sub>2.source_preserve p\\<^sub>1.po1.g.source_preserve\n      by (simp add: morph_comp_def)\n  next\n    show \\<open>\\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>V (t\\<^bsub>lhs r\\<^sub>2\\<^esub> e) = t\\<^bsub>G\\<^esub> (\\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>E e)\\<close> if \\<open>e \\<in> E\\<^bsub>lhs r\\<^sub>2\\<^esub>\\<close> for e\n      using that i\\<^sub>2.morph_edge_range i\\<^sub>2.target_preserve p\\<^sub>1.po1.g.target_preserve\n      by (simp add: morph_comp_def)\n  next\n    show \\<open>l\\<^bsub>lhs r\\<^sub>2\\<^esub> v = l\\<^bsub>G\\<^esub> (\\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>V v)\\<close> if \\<open>v \\<in> V\\<^bsub>lhs r\\<^sub>2\\<^esub>\\<close> for v\n      using that  i\\<^sub>2.label_preserve i\\<^sub>2.morph_node_range p\\<^sub>1.po1.g.label_preserve\n      by (simp add: morph_comp_def)\n  next\n    show \\<open>m\\<^bsub>lhs r\\<^sub>2\\<^esub> e = m\\<^bsub>G\\<^esub> (\\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>E e)\\<close> if \\<open>e \\<in> E\\<^bsub>lhs r\\<^sub>2\\<^esub>\\<close> for e\n      using that i\\<^sub>2.mark_preserve i\\<^sub>2.morph_edge_range p\\<^sub>1.po1.g.mark_preserve\n      by (simp add: morph_comp_def)\n  qed\n\n \n\n  \n  \n  interpret \"7+5\": pushout_diagram \"interf r\\<^sub>2\" D\\<^sub>2 \"lhs r\\<^sub>2\" G \"pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\" b\\<^sub>2 c\\<^sub>2 \"c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\"\n  proof\n    show \\<open>\\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> (pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2)\\<^esub>\\<^sub>V v = \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>2\\<^esub>\\<^sub>V v\\<close> if \\<open>v \\<in> V\\<^bsub>interf r\\<^sub>2\\<^esub>\\<close> for v\n      using that p\\<^sub>2.po1.node_commutativity p\\<^sub>2.r.k.morph_node_range\n        \\<open>\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>V v\\<close> \\<open>\\<And>v. v\\<in>V\\<^bsub>interf r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>m\\<^sub>2\\<^esub>\\<^sub>V v\\<close> \n      by (simp add: morph_comp_def)\n  next\n    show \\<open>\\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> (pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2)\\<^esub>\\<^sub>E e = \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>2\\<^esub>\\<^sub>E e\\<close> if \\<open>e \\<in> E\\<^bsub>interf r\\<^sub>2\\<^esub>\\<close> for e\n      using that p\\<^sub>2.po1.edge_commutativity p\\<^sub>2.r.k.morph_edge_range\n        \\<open>\\<forall>e \\<in> E\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>E e\\<close> \\<open>\\<And>e. e\\<in>E\\<^bsub>interf r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\\<^esub>\\<^sub>E e= \\<^bsub>m\\<^sub>2\\<^esub>\\<^sub>E e\\<close> \n      by (simp add: morph_comp_def)\n  next\n    show \\<open>Ex1M\n        (\\<lambda>xa. morphism (to_ngraph G) D' xa \\<and>\n               (\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>xa \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v) \\<and>\n               (\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>xa \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e) \\<and> (\\<forall>v\\<in>V\\<^bsub>to_ngraph (lhs r\\<^sub>2)\\<^esub>. \\<^bsub>xa \\<circ>\\<^sub>\\<rightarrow> to_nmorph (c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2)\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v) \\<and> (\\<forall>e\\<in>E\\<^bsub>to_ngraph (lhs r\\<^sub>2)\\<^esub>. \\<^bsub>xa \\<circ>\\<^sub>\\<rightarrow> to_nmorph (c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2)\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e))\n        (to_ngraph G)\\<close>\n      if \\<open>graph D'\\<close>\n       \\<open>morphism (to_ngraph D\\<^sub>2) D' x\\<close>\n       \\<open>morphism (to_ngraph (lhs r\\<^sub>2)) D' y\\<close>\n       \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (interf r\\<^sub>2)\\<^esub>. \\<^bsub>x \\<circ>\\<^sub>\\<rightarrow> to_nmorph (pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2)\\<^esub>\\<^sub>V v = \\<^bsub>y \\<circ>\\<^sub>\\<rightarrow> to_nmorph b\\<^sub>2\\<^esub>\\<^sub>V v\\<close>\n       \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (interf r\\<^sub>2)\\<^esub>. \\<^bsub>x \\<circ>\\<^sub>\\<rightarrow> to_nmorph (pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2)\\<^esub>\\<^sub>E e = \\<^bsub>y \\<circ>\\<^sub>\\<rightarrow> to_nmorph b\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n     for D' :: \"('g,'h) ngraph\" and x y\n    proof -\n\n      have \\<open>\\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>m\\<^sub>2\\<^esub>\\<^sub>V v\\<close> if \\<open>v \\<in> V\\<^bsub>interf r\\<^sub>2\\<^esub>\\<close> for v\n        using that \\<open>\\<And>v. v\\<in>V\\<^bsub>interf r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>m\\<^sub>2\\<^esub>\\<^sub>V v\\<close> \n        by (simp add: morph_comp_def)\n\n     have \\<open>\\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>V v\\<close> if \\<open>v \\<in> V\\<^bsub>lhs r\\<^sub>2\\<^esub>\\<close> for v\n        using that \\<open>\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>V v\\<close> \n        by (simp add: morph_comp_def)\n\n     have a: \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (interf r\\<^sub>2)\\<^esub>. \\<^bsub>y \\<circ>\\<^sub>\\<rightarrow> to_nmorph b\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>x \\<circ>\\<^sub>\\<rightarrow> to_nmorph m\\<^sub>2\\<^esub>\\<^sub>V v\\<close>\n        using \\<open>\\<And>v. v\\<in>V\\<^bsub>interf r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>m\\<^sub>2\\<^esub>\\<^sub>V v\\<close>\n         \\<open>\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>V v\\<close> that\n        by (simp add: morph_comp_def to_ngraph_def to_nmorph_def) \n\n      have b: \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (interf r\\<^sub>2)\\<^esub>. \\<^bsub>y \\<circ>\\<^sub>\\<rightarrow> to_nmorph b\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>x \\<circ>\\<^sub>\\<rightarrow> to_nmorph m\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n        using \\<open>\\<And>e. e\\<in>E\\<^bsub>interf r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>m\\<^sub>2\\<^esub>\\<^sub>E e\\<close>   \\<open>\\<forall>e \\<in> E\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n          that\n        by (simp add: morph_comp_def to_ngraph_def to_nmorph_def) \n\n    obtain u where \\<open>morphism (to_ngraph G) D' u\\<close>\n        and aa1: \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (lhs r\\<^sub>2)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close> \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (lhs r\\<^sub>2)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n        and aa2: \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close> \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n        using p\\<^sub>2.po1.universal_property[OF  \\<open>graph D'\\<close> \\<open>morphism (to_ngraph (lhs r\\<^sub>2)) D' y\\<close> \\<open>morphism (to_ngraph D\\<^sub>2) D' x\\<close> a b]\n        by fast\n\n(* used for technical reasons within the upcoming proof *)\n      have n: \\<open>morphism (to_ngraph G) D' u \\<and>\n            (\\<forall>v\\<in>V\\<^bsub>to_ngraph (lhs r\\<^sub>2)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v) \\<and>\n            (\\<forall>e\\<in>E\\<^bsub>to_ngraph (lhs r\\<^sub>2)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e) \\<and> \n            (\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v) \\<and> (\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e)\\<close>\n        using \\<open>morphism (to_ngraph G) D' u\\<close> aa1(1) aa1(2) aa2(1) aa2(2) by force\n\n     show ?thesis\n      proof (rule_tac x = u in exI, safe)\n        show \\<open>morphism (to_ngraph G) D' u\\<close>\n          using \\<open>morphism (to_ngraph G) D' u\\<close> by assumption\n      next\n        show \\<open>\\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close> if \\<open>v \\<in> V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>\\<close> for v\n          using that \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close> \n          by simp\n      next\n        show \\<open>\\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close> if \\<open>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>\\<close> for e\n          using \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close> that \n          by simp\n      next\n        show \\<open>\\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph (c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2)\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close> if \\<open>v\\<in>V\\<^bsub>to_ngraph (lhs r\\<^sub>2)\\<^esub>\\<close> for v\n          using aa1(1)  \\<open>\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>V v\\<close> that\n          by (auto simp add: to_nmorph_def morph_comp_def to_ngraph_def)\n      next\n        show \\<open>\\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph (c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2)\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close> if \\<open>e\\<in>E\\<^bsub>to_ngraph (lhs r\\<^sub>2)\\<^esub>\\<close> for e\n          using aa1(2)  \\<open>\\<forall>e \\<in> E\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>E e\\<close> that\n          by (auto simp add: to_nmorph_def morph_comp_def to_ngraph_def)\n      next\n        show \\<open>\\<^bsub>ya\\<^esub>\\<^sub>E e = \\<^bsub>u\\<^esub>\\<^sub>E e\\<close>\n          if \\<open>morphism (to_ngraph G) D' ya\\<close>\n             \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close> \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n             \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (lhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph (c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2)\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close> \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (lhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph (c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2)\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n             \\<open> e \\<in> E\\<^bsub>to_ngraph G\\<^esub>\\<close>\n           for ya  e\n        proof -\n          have m:\\<open>morphism (to_ngraph G) D' ya \\<and>\n            (\\<forall>v\\<in>V\\<^bsub>to_ngraph (lhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v) \\<and>\n            (\\<forall>e\\<in>E\\<^bsub>to_ngraph (lhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e) \\<and> (\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v) \\<and> (\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e)\\<close>\n            using that\n          proof (intro conjI)\n            show \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (lhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close>\n              using \\<open>\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>V v\\<close> that\n              by (simp add: morph_comp_def to_ngraph_def to_nmorph_def)\n          next\n            show \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (lhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n              using that \\<open>\\<forall>e \\<in> E\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n              by (simp add: morph_comp_def to_ngraph_def to_nmorph_def)\n          qed assumption\n\n          show ?thesis\n            using ex_eq[OF p\\<^sub>2.po1.universal_property[OF  \\<open>graph D'\\<close> \\<open>morphism (to_ngraph (lhs r\\<^sub>2)) D' y\\<close> \\<open>morphism (to_ngraph D\\<^sub>2) D' x\\<close> a b], OF n m] that\n            by simp\n        qed\n      next\n        show \\<open>\\<^bsub>ya\\<^esub>\\<^sub>V v = \\<^bsub>u\\<^esub>\\<^sub>V v\\<close>\n          if \\<open>morphism (to_ngraph G) D' ya\\<close>\n             \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close> \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n             \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (lhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph (c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2)\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close> \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (lhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph (c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2)\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n             \\<open>v \\<in> V\\<^bsub>to_ngraph G\\<^esub>\\<close>\n           for ya v\n        proof -\n          have m:\\<open>morphism (to_ngraph G) D' ya \\<and>\n            (\\<forall>v\\<in>V\\<^bsub>to_ngraph (lhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v) \\<and>\n            (\\<forall>e\\<in>E\\<^bsub>to_ngraph (lhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e) \\<and> (\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v) \\<and> (\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph c\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e)\\<close>\n            using that\n          proof (intro conjI)\n            show \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (lhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close>\n              using \\<open>\\<forall>v \\<in> V\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>V v\\<close> that\n              by (simp add: morph_comp_def to_ngraph_def to_nmorph_def)\n          next\n            show \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (lhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph g\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n              using that \\<open>\\<forall>e \\<in> E\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>g\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n              by (simp add: morph_comp_def to_ngraph_def to_nmorph_def)\n          qed assumption\n\n          show ?thesis\n            using ex_eq[OF p\\<^sub>2.po1.universal_property[OF  \\<open>graph D'\\<close> \\<open>morphism (to_ngraph (lhs r\\<^sub>2)) D' y\\<close> \\<open>morphism (to_ngraph D\\<^sub>2) D' x\\<close> a b], OF n m] that\n            by simp\n        qed\n      qed\n    qed\n  qed\n\n\n  have a: \\<open>\\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>2\\<^esub>\\<^sub>V v\\<close> if \\<open>v \\<in> V\\<^bsub>interf r\\<^sub>2\\<^esub>\\<close> for v\n    using  \"7+5.node_commutativity\" that\n    by (simp add: morph_comp_def)\n\n  have b: \\<open>\\<^bsub>c\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>2\\<^esub>\\<^sub>E e\\<close> if \\<open>e \\<in> E\\<^bsub>interf r\\<^sub>2\\<^esub>\\<close> for e\n    using  \"7+5.edge_commutativity\" that\n    by (simp add: morph_comp_def)\n\n\n(* Experimental *)\n\n(* TODO: proof *)\n  interpret \"7+5pb\": pullback_diagram \"interf r\\<^sub>2\" D\\<^sub>2 \"lhs r\\<^sub>2\" G \"pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\" b\\<^sub>2 c\\<^sub>2 \"c\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\"\n    using \"7+5.flip_diagram\" \"7+5.pushout_pullback_inj_b\" c\\<^sub>1.injective_morphism_axioms i\\<^sub>2.injective_morphism_axioms inj_comp_inj p\\<^sub>2.r.k.injective_morphism_axioms pushout_diagram.b_f_inj_imp_c_inj by blast\n\n(* TODO Proof *)\n  interpret sevenpb: pullback_diagram \"interf r\\<^sub>2\" pb.A \"lhs r\\<^sub>2\" D\\<^sub>1 j\\<^sub>2 b\\<^sub>2 pb.b i\\<^sub>2\n   using pullback_decomposition[OF _ _ pb.pb.flip_diagram  \"7+5pb.pullback_diagram_axioms\"]\n   using i\\<^sub>2.morphism_axioms j2c(1) j2c(2) j\\<^sub>2.morphism_axioms by blast\n\n  have jointly_surj_nodes: \\<open>(\\<exists>v\\<in>V\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>i\\<^sub>2\\<^esub>\\<^sub>V v = x) \\<or> (\\<exists>v\\<in>V\\<^bsub>pb.A\\<^esub>. \\<^bsub>pb.b\\<^esub>\\<^sub>V v = x)\\<close>\n    if \\<open>x \\<in> V\\<^bsub>D\\<^sub>1\\<^esub>\\<close> for x\n    using that pb.reduced_chain_condition_nodes i\\<^sub>2.inj_nodes inj_k.inj_nodes \n      p\\<^sub>2.po1.joint_surjectivity_nodes \"7+5.joint_surjectivity_nodes\"\n      c\\<^sub>1.inj_nodes i\\<^sub>2.morph_node_range inj_on_def p\\<^sub>1.po1.g.morph_node_range\n    apply (auto simp add: morph_comp_def inj_on_def)\n    by metis\n\n\n  have jointly_surj_edges: \\<open>(\\<exists>e\\<in>E\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>i\\<^sub>2\\<^esub>\\<^sub>E e = x) \\<or> (\\<exists>e\\<in>E\\<^bsub>pb.A\\<^esub>. \\<^bsub>pb.b\\<^esub>\\<^sub>E e = x)\\<close>\n    if \\<open>x \\<in> E\\<^bsub>D\\<^sub>1\\<^esub>\\<close> for x\n       using that pb.reduced_chain_condition_edges i\\<^sub>2.inj_edges inj_k.inj_edges\n      p\\<^sub>2.po1.joint_surjectivity_edges \"7+5.joint_surjectivity_edges\"\n      c\\<^sub>1.inj_edges i\\<^sub>2.morph_edge_range inj_on_def p\\<^sub>1.po1.g.morph_edge_range\n    apply (auto simp add: morph_comp_def inj_on_def)\n    by metis\n\n\n(* pushout_diagram (interf r\\<^sub>2) pb.A (lhs r\\<^sub>2) D\\<^sub>1 j\\<^sub>2 b\\<^sub>2 pb.b i\\<^sub>2 *)\n  interpret seven: pushout_diagram \"interf r\\<^sub>2\" \"lhs r\\<^sub>2\" pb.A D\\<^sub>1 b\\<^sub>2 j\\<^sub>2 i\\<^sub>2 pb.b\n    using po_characterization[OF j\\<^sub>2.injective_morphism_axioms p\\<^sub>2.r.k.injective_morphism_axioms\ninj_k.injective_morphism_axioms i\\<^sub>2.injective_morphism_axioms\nj2c\nsevenpb.reduced_chain_condition_nodes sevenpb.reduced_chain_condition_edges\njointly_surj_nodes jointly_surj_edges]\n    using pushout_diagram.flip_diagram by blast\n\n\n  interpret acht: gluing \"interf r\\<^sub>1\" pb.A \"rhs r\\<^sub>1\" j\\<^sub>1 b\\<^sub>1' ..\n\n  interpret neun: gluing \"interf r\\<^sub>2\" pb.A \"rhs r\\<^sub>2\" j\\<^sub>2 b\\<^sub>2' ..\n\n  interpret ten: gluing pb.A neun.H acht.H neun.c acht.c ..\n\n  interpret h1b: morphism pb.A H\\<^sub>1 \"h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> pb.b\"\n    using wf_morph_comp[OF pb.b.morphism_axioms p\\<^sub>1.po2.g.morphism_axioms]\n    by assumption\n\n\n(* aaa and bbb belong to s\\<^sub>1 *)\n  have  aaa: \\<open>\\<forall>v\\<in>V\\<^bsub>interf r\\<^sub>1\\<^esub>. \\<^bsub>f\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>1'\\<^esub>\\<^sub>V v = \\<^bsub>h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>V v\\<close>\n    using p\\<^sub>1.po2.node_commutativity a \\<open>\\<And>v. v\\<in>V\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>m\\<^sub>1\\<^esub>\\<^sub>V v\\<close>\n    by (simp add: morph_comp_def) \n    \n  have bbb: \\<open>\\<forall>e\\<in>E\\<^bsub>interf r\\<^sub>1\\<^esub>. \\<^bsub>f\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow>  b\\<^sub>1'\\<^esub>\\<^sub>E e = \\<^bsub>h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n    using p\\<^sub>1.po2.edge_commutativity b \\<open>\\<And>e. e\\<in>E\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>m\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n    by (simp add: morph_comp_def) \n\n  obtain s\\<^sub>1 where\n    \\<open>morphism acht.H H\\<^sub>1 s\\<^sub>1\\<close> and\n    \\<open>\\<And>v. v \\<in> V\\<^bsub>pb.A\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.c\\<^esub>\\<^sub>V v = \\<^bsub>h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> pb.b\\<^esub>\\<^sub>V v\\<close>\n    \\<open>\\<And>e. e \\<in> E\\<^bsub>pb.A\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.c\\<^esub>\\<^sub>E e = \\<^bsub>h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> pb.b\\<^esub>\\<^sub>E e\\<close>\n(* and (2) = (8) + (11) *)\n    \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>V v\\<close>\n    \\<open>\\<And>e. e \\<in> E\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n     using acht.po.universal_property_exist_gen[OF p\\<^sub>1.po2.f.H.graph_axioms\n        p\\<^sub>1.po2.f.morphism_axioms\n        wf_morph_comp[OF pb.b.morphism_axioms p\\<^sub>1.po2.g.morphism_axioms] aaa bbb]\n    by auto\n\n  interpret s\\<^sub>1: morphism acht.H H\\<^sub>1 s\\<^sub>1\n    using \\<open>morphism acht.H H\\<^sub>1 s\\<^sub>1\\<close> by assumption\n\n  interpret morphism \"rhs r\\<^sub>1\" H\\<^sub>1 \"s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\"\n  proof\n    show \\<open>\\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>E e \\<in> E\\<^bsub>H\\<^sub>1\\<^esub>\\<close> if \\<open>e \\<in> E\\<^bsub>rhs r\\<^sub>1\\<^esub>\\<close> for e\n      using that \\<open>\\<And>e. e \\<in> E\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n        p\\<^sub>1.po2.f.morph_edge_range\n      by simp\n  next\n    show \\<open>\\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>V v \\<in> V\\<^bsub>H\\<^sub>1\\<^esub>\\<close> if \\<open>v \\<in> V\\<^bsub>rhs r\\<^sub>1\\<^esub>\\<close> for v\n      using that \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>V v\\<close>\n        p\\<^sub>1.po2.f.morph_node_range\n      by simp\n  next\n    show \\<open>\\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>V (s\\<^bsub>rhs r\\<^sub>1\\<^esub> e) = s\\<^bsub>H\\<^sub>1\\<^esub> (\\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>E e)\\<close> if \\<open>e \\<in> E\\<^bsub>rhs r\\<^sub>1\\<^esub>\\<close> for e\n      using that p\\<^sub>1.r.r.H.source_integrity  p\\<^sub>1.po2.f.source_preserve\n        \\<open>\\<And>e. e \\<in> E\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n        \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>V v\\<close> p\\<^sub>1.r.r.H.source_integrity \n      by simp\n  next\n    show \\<open>\\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>V (t\\<^bsub>rhs r\\<^sub>1\\<^esub> e) = t\\<^bsub>H\\<^sub>1\\<^esub> (\\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>E e)\\<close> if \\<open>e \\<in> E\\<^bsub>rhs r\\<^sub>1\\<^esub>\\<close> for e\n      using that p\\<^sub>1.r.r.H.target_integrity  p\\<^sub>1.po2.f.target_preserve\n        \\<open>\\<And>e. e \\<in> E\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n        \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>V v\\<close> p\\<^sub>1.r.r.H.target_integrity \n      by simp\n  next\n    show \\<open>l\\<^bsub>rhs r\\<^sub>1\\<^esub> v = l\\<^bsub>H\\<^sub>1\\<^esub> (\\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>V v)\\<close> if \\<open>v \\<in> V\\<^bsub>rhs r\\<^sub>1\\<^esub>\\<close> for v\n      using that p\\<^sub>1.po2.f.label_preserve\n        \\<open>\\<And>e. e \\<in> E\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n        \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>V v\\<close>\n      by simp\n  next\n    show \\<open> m\\<^bsub>rhs r\\<^sub>1\\<^esub> e = m\\<^bsub>H\\<^sub>1\\<^esub> (\\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>E e)\\<close> if \\<open>e \\<in> E\\<^bsub>rhs r\\<^sub>1\\<^esub>\\<close> for e\n      using that p\\<^sub>1.po2.f.mark_preserve\n        \\<open>\\<And>e. e \\<in> E\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n        \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>V v\\<close>\n      by simp\n  qed\n\n\n\n  interpret \"8+11\": pushout_diagram \"interf r\\<^sub>1\" \"rhs r\\<^sub>1\" D\\<^sub>1 H\\<^sub>1 b\\<^sub>1' \"pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\" \\<open>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<close> h\\<^sub>1\n  proof\n    show \\<open>\\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>1'\\<^esub>\\<^sub>V v = \\<^bsub>h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> (pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1)\\<^esub>\\<^sub>V v\\<close> if \\<open>v \\<in> V\\<^bsub>interf r\\<^sub>1\\<^esub>\\<close> for v\n      using that aaa\n        \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>V v\\<close> p\\<^sub>1.r.r.morph_node_range\n      by (simp add: morph_comp_def)\n  next\n    show \\<open>\\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>1'\\<^esub>\\<^sub>E e = \\<^bsub>h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> (pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1)\\<^esub>\\<^sub>E e\\<close> if \\<open>e \\<in> E\\<^bsub>interf r\\<^sub>1\\<^esub>\\<close> for e\n      using that bbb\n        \\<open>\\<And>e. e \\<in> E\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>E e\\<close> p\\<^sub>1.r.r.morph_edge_range\n      by (simp add: morph_comp_def)\n  next\n    show \\<open>Ex1M\n        (\\<lambda>xa. morphism (to_ngraph H\\<^sub>1) D' xa \\<and>\n              (\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>xa \\<circ>\\<^sub>\\<rightarrow> to_nmorph (s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h)\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v) \\<and>\n              (\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>xa \\<circ>\\<^sub>\\<rightarrow> to_nmorph (s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h)\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e) \\<and>\n              (\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>xa \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v) \\<and>\n              (\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>xa \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e))\n        (to_ngraph H\\<^sub>1)\\<close> \n      if  \\<open>graph D'\\<close>\n          \\<open>morphism (to_ngraph (rhs r\\<^sub>1)) D' x\\<close>\n          \\<open>morphism (to_ngraph D\\<^sub>1) D' y\\<close>\n          \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (interf r\\<^sub>1)\\<^esub>. \\<^bsub>x \\<circ>\\<^sub>\\<rightarrow> to_nmorph b\\<^sub>1'\\<^esub>\\<^sub>V v = \\<^bsub>y \\<circ>\\<^sub>\\<rightarrow> to_nmorph (pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1)\\<^esub>\\<^sub>V v\\<close>\n          \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (interf r\\<^sub>1)\\<^esub>. \\<^bsub>x \\<circ>\\<^sub>\\<rightarrow> to_nmorph b\\<^sub>1'\\<^esub>\\<^sub>E e = \\<^bsub>y \\<circ>\\<^sub>\\<rightarrow> to_nmorph (pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1)\\<^esub>\\<^sub>E e\\<close>\n        for D' :: \"('g,'h) ngraph\" and x y\n    proof -\n      have a: \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (interf r\\<^sub>1)\\<^esub>. \\<^bsub>x \\<circ>\\<^sub>\\<rightarrow> to_nmorph b\\<^sub>1'\\<^esub>\\<^sub>V v = \\<^bsub>y \\<circ>\\<^sub>\\<rightarrow> to_nmorph m\\<^sub>1\\<^esub>\\<^sub>V v\\<close>\n        using \\<open>\\<And>v. v\\<in>V\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>m\\<^sub>1\\<^esub>\\<^sub>V v\\<close> \n          \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (interf r\\<^sub>1)\\<^esub>. \\<^bsub>x \\<circ>\\<^sub>\\<rightarrow> to_nmorph b\\<^sub>1'\\<^esub>\\<^sub>V v = \\<^bsub>y \\<circ>\\<^sub>\\<rightarrow> to_nmorph (pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1)\\<^esub>\\<^sub>V v\\<close>\n        by (simp add: morph_comp_def to_nmorph_def to_ngraph_def)\n\n      have b:\\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (interf r\\<^sub>1)\\<^esub>. \\<^bsub>x \\<circ>\\<^sub>\\<rightarrow> to_nmorph b\\<^sub>1'\\<^esub>\\<^sub>E e = \\<^bsub>y \\<circ>\\<^sub>\\<rightarrow> to_nmorph m\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n        using \\<open>\\<And>e. e\\<in>E\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>m\\<^sub>1\\<^esub>\\<^sub>E e\\<close> \n          \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (interf r\\<^sub>1)\\<^esub>. \\<^bsub>x \\<circ>\\<^sub>\\<rightarrow> to_nmorph b\\<^sub>1'\\<^esub>\\<^sub>E e = \\<^bsub>y \\<circ>\\<^sub>\\<rightarrow> to_nmorph (pb.b \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1)\\<^esub>\\<^sub>E e\\<close>\n        by (simp add: morph_comp_def to_nmorph_def to_ngraph_def)\n \n      obtain u where \\<open>morphism (to_ngraph H\\<^sub>1) D' u\\<close>\n        and u1: \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close> \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n        and u2: \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close> \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n        using p\\<^sub>1.po2.universal_property[OF \\<open>graph D'\\<close> \\<open>morphism (to_ngraph (rhs r\\<^sub>1)) D' x\\<close>  \\<open>morphism (to_ngraph D\\<^sub>1) D' y\\<close> a b]\n        by fast\n\n      have m: \\<open>morphism (to_ngraph H\\<^sub>1) D' u \\<and>\n        (\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v) \\<and>\n        (\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e) \\<and> \n        (\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v) \\<and> \n        (\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e)\\<close>\n        using u1 u2  \\<open>morphism (to_ngraph H\\<^sub>1) D' u\\<close>\n        by fastforce\n\n      show ?thesis\n      proof (rule_tac x = u in exI, safe)\n        show \\<open>morphism (to_ngraph H\\<^sub>1) D' u\\<close>\n          using \\<open>morphism (to_ngraph H\\<^sub>1) D' u\\<close> by assumption\n      next\n        show \\<open>\\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph (s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h)\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close> if \\<open>v \\<in> V\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>\\<close> for v\n          using that \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close>\n            \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>V v\\<close>\n          by (fastforce simp add: morph_comp_def to_nmorph_def to_ngraph_def)\n      next\n        show \\<open>\\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph (s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h)\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close> if \\<open>e \\<in> E\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>\\<close> for e\n          using that \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n            \\<open>\\<And>e. e \\<in> E\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n          by (fastforce simp add: morph_comp_def to_nmorph_def to_ngraph_def)\n      next\n        show \\<open>\\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close> if \\<open>v \\<in> V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>\\<close> for v\n          using that \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close>\n          by simp\n      next\n        show \\<open>\\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close> if \\<open>e \\<in> E\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>\\<close> for e\n          using that \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n          by simp\n      next\n        show \\<open>\\<^bsub>ya\\<^esub>\\<^sub>E e = \\<^bsub>u\\<^esub>\\<^sub>E e\\<close>\n          if \\<open>morphism (to_ngraph H\\<^sub>1) D' ya\\<close>\n           \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph (s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h)\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close>\n           \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph (s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h)\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n           \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close>\n           \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n           \\<open>e \\<in> E\\<^bsub>to_ngraph H\\<^sub>1\\<^esub>\\<close> for ya e\n        proof -\n          have n: \\<open>morphism (to_ngraph H\\<^sub>1) D' ya \\<and>\n            (\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v) \\<and>\n            (\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e) \\<and> (\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v) \\<and> (\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e)\\<close>\n          proof (intro conjI)\n            show \\<open>morphism (to_ngraph H\\<^sub>1) D' ya\\<close>\n              using \\<open> morphism (to_ngraph H\\<^sub>1) D' ya\\<close> by assumption\n          next\n            show \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close>\n              using that \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close>\n                \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>V v\\<close>\n              by (fastforce simp add: morph_comp_def to_nmorph_def to_ngraph_def)\n          next\n            show \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n              using that \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n                \\<open>\\<And>e. e \\<in> E\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n              by (fastforce simp add: morph_comp_def to_nmorph_def to_ngraph_def)\n          next\n            show \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close>\n              using \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close> by assumption\n          next\n            show \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n              using that(5) by assumption\n          qed\n\n          show ?thesis\n            using that ex_eq[OF p\\<^sub>1.po2.universal_property[OF \\<open>graph D'\\<close> \\<open>morphism (to_ngraph (rhs r\\<^sub>1)) D' x\\<close>  \\<open>morphism (to_ngraph D\\<^sub>1) D' y\\<close> a b] n m]\n            by blast\n        qed\n      next\n        show \\<open>\\<^bsub>ya\\<^esub>\\<^sub>V v = \\<^bsub>u\\<^esub>\\<^sub>V v\\<close>\n          if \\<open>morphism (to_ngraph H\\<^sub>1) D' ya\\<close>\n           \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph (s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h)\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close>\n           \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph (s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h)\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n           \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close>\n           \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n           \\<open>v \\<in> V\\<^bsub>to_ngraph H\\<^sub>1\\<^esub>\\<close> for ya v\n        proof -\n          have n: \\<open>morphism (to_ngraph H\\<^sub>1) D' ya \\<and>\n            (\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v) \\<and>\n            (\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e) \\<and> (\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v) \\<and> (\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e)\\<close>\n          proof (intro conjI)\n            show \\<open>morphism (to_ngraph H\\<^sub>1) D' ya\\<close>\n              using \\<open> morphism (to_ngraph H\\<^sub>1) D' ya\\<close> by assumption\n          next\n            show \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close>\n              using that \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close>\n                \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>V v\\<close>\n              by (fastforce simp add: morph_comp_def to_nmorph_def to_ngraph_def)\n          next\n            show \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n              using that \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>1)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n                \\<open>\\<And>e. e \\<in> E\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n              by (fastforce simp add: morph_comp_def to_nmorph_def to_ngraph_def)\n          next\n            show \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close>\n              using \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close> by assumption\n          next\n            show \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>1\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n              using that(5) by blast\n          qed\n\n          show ?thesis\n            using that ex_eq[OF p\\<^sub>1.po2.universal_property[OF \\<open>graph D'\\<close> \\<open>morphism (to_ngraph (rhs r\\<^sub>1)) D' x\\<close>  \\<open>morphism (to_ngraph D\\<^sub>1) D' y\\<close> a b] n m]\n            by blast\n        qed\n      qed\n    qed\n  qed\n\n\n\n  interpret eleven:  pushout_diagram pb.A D\\<^sub>1 acht.H H\\<^sub>1 pb.b acht.c h\\<^sub>1 s\\<^sub>1\n    using pushout_decomposition[OF pb.b.morphism_axioms s\\<^sub>1.morphism_axioms acht.po.flip_diagram \"8+11.flip_diagram\"]\n      \\<open>\\<And>e. e \\<in> E\\<^bsub>pb.A\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.c\\<^esub>\\<^sub>E e = \\<^bsub>h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> pb.b\\<^esub>\\<^sub>E e\\<close> \\<open>\\<And>v. v \\<in> V\\<^bsub>pb.A\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.c\\<^esub>\\<^sub>V v = \\<^bsub>h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> pb.b\\<^esub>\\<^sub>V v\\<close>\n    by simp\n\n\n(* start of s\\<^sub>2 *)\n\n  have aaa2: \\<open>\\<forall>v\\<in>V\\<^bsub>interf r\\<^sub>2\\<^esub>. \\<^bsub>f\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>2'\\<^esub>\\<^sub>V v = \\<^bsub>h\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\\<^esub>\\<^sub>V v\\<close>\n    using p\\<^sub>2.po2.node_commutativity  \\<open>\\<And>v. v\\<in>V\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>V v = \\<^bsub>i\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>1\\<^esub>\\<^sub>V v\\<close>\n      \\<open>\\<And>v. v\\<in>V\\<^bsub>interf r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>m\\<^sub>2\\<^esub>\\<^sub>V v\\<close> \n    by (simp add: morph_comp_def) \n\n  have bbb2: \\<open>\\<forall>e\\<in>E\\<^bsub>interf r\\<^sub>2\\<^esub>. \\<^bsub>f\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>2'\\<^esub>\\<^sub>E e = \\<^bsub>h\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n    using p\\<^sub>2.po2.edge_commutativity  \\<open>\\<And>e. e\\<in>E\\<^bsub>interf r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\\<^esub>\\<^sub>E e = \\<^bsub>i\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n      \\<open>\\<And>e. e\\<in>E\\<^bsub>interf r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>m\\<^sub>2\\<^esub>\\<^sub>E e\\<close> \n    by (simp add: morph_comp_def)\n\n\n   obtain s\\<^sub>2 where\n    \\<open>morphism neun.H H\\<^sub>2 s\\<^sub>2\\<close> and\n    \\<open>\\<And>v. v \\<in> V\\<^bsub>pb.A\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.c\\<^esub>\\<^sub>V v = \\<^bsub>h\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> pb.c\\<^esub>\\<^sub>V v\\<close>\n    \\<open>\\<And>e. e \\<in> E\\<^bsub>pb.A\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.c\\<^esub>\\<^sub>E e = \\<^bsub>h\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> pb.c\\<^esub>\\<^sub>E e\\<close>\n(* (4) = (9)+(12) *)\n    \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>V v\\<close>\n    \\<open>\\<And>e. e \\<in> E\\<^bsub>rhs r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n     using neun.po.universal_property_exist_gen[OF p\\<^sub>2.po2.f.H.graph_axioms\n      p\\<^sub>2.po2.f.morphism_axioms\n      wf_morph_comp[OF pb.c.morphism_axioms p\\<^sub>2.po2.g.morphism_axioms] aaa2 bbb2]\n    by fast \n\n  interpret s\\<^sub>2: morphism neun.H H\\<^sub>2 s\\<^sub>2\n    using \\<open>morphism neun.H H\\<^sub>2 s\\<^sub>2\\<close> by assumption\n\n  interpret morphism \"rhs r\\<^sub>2\" H\\<^sub>2 \"s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\"\n  proof\n    show \\<open>\\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>E e \\<in> E\\<^bsub>H\\<^sub>2\\<^esub>\\<close> if \\<open>e \\<in> E\\<^bsub>rhs r\\<^sub>2\\<^esub>\\<close> for e\n      using that  \\<open>\\<And>e. e \\<in> E\\<^bsub>rhs r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>E e\\<close> p\\<^sub>2.po2.f.morph_edge_range\n      by simp\n  next\n    show \\<open>\\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>V v \\<in> V\\<^bsub>H\\<^sub>2\\<^esub>\\<close> if \\<open>v \\<in> V\\<^bsub>rhs r\\<^sub>2\\<^esub>\\<close> for v\n      using that \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>V v\\<close> p\\<^sub>2.po2.f.morph_node_range \n      by simp\n  next\n    show \\<open>\\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>V (s\\<^bsub>rhs r\\<^sub>2\\<^esub> e) = s\\<^bsub>H\\<^sub>2\\<^esub> (\\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>E e)\\<close> if \\<open>e \\<in> E\\<^bsub>rhs r\\<^sub>2\\<^esub>\\<close> for e\n      using that\n        \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>V v\\<close>\n        \\<open>\\<And>e. e \\<in> E\\<^bsub>rhs r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n        p\\<^sub>2.po2.f.source_preserve p\\<^sub>2.r.r.H.source_integrity\n      by simp\n  next\n    show \\<open>\\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>V (t\\<^bsub>rhs r\\<^sub>2\\<^esub> e) = t\\<^bsub>H\\<^sub>2\\<^esub> (\\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>E e)\\<close> if \\<open>e \\<in> E\\<^bsub>rhs r\\<^sub>2\\<^esub>\\<close> for e\n      using that \n        \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>V v\\<close>\n        \\<open>\\<And>e. e \\<in> E\\<^bsub>rhs r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n        p\\<^sub>2.po2.f.target_preserve p\\<^sub>2.r.r.H.target_integrity\n      by simp\n  next\n    show \\<open>l\\<^bsub>rhs r\\<^sub>2\\<^esub> v = l\\<^bsub>H\\<^sub>2\\<^esub> (\\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>V v)\\<close> if \\<open>v \\<in> V\\<^bsub>rhs r\\<^sub>2\\<^esub>\\<close> for v\n      using that \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>V v\\<close>\n        p\\<^sub>2.po2.f.label_preserve\n      by simp\n  next\n    show \\<open>m\\<^bsub>rhs r\\<^sub>2\\<^esub> e = m\\<^bsub>H\\<^sub>2\\<^esub> (\\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>E e)\\<close> if \\<open>e \\<in> E\\<^bsub>rhs r\\<^sub>2\\<^esub>\\<close> for e\n      using that \\<open>\\<And>e. e \\<in> E\\<^bsub>rhs r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n        p\\<^sub>2.po2.f.mark_preserve\n      by simp\n  qed\n\n\n  interpret \"9+12\": pushout_diagram \"interf r\\<^sub>2\" \"rhs r\\<^sub>2\" D\\<^sub>2 H\\<^sub>2 b\\<^sub>2' \"pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\" \"s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\" h\\<^sub>2\n  proof\n    show \\<open>\\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>2'\\<^esub>\\<^sub>V v = \\<^bsub>h\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> (pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2)\\<^esub>\\<^sub>V v\\<close>\n      if \\<open>v \\<in> V\\<^bsub>interf r\\<^sub>2\\<^esub>\\<close> for v\n      using that p\\<^sub>2.po2.node_commutativity aaa2  p\\<^sub>2.r.r.morph_node_range\n        \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>V v\\<close>\n      by (simp add: morph_comp_def)\n  next\n    show \\<open>\\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h \\<circ>\\<^sub>\\<rightarrow> b\\<^sub>2'\\<^esub>\\<^sub>E e = \\<^bsub>h\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> (pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2)\\<^esub>\\<^sub>E e\\<close> \n      if \\<open>e \\<in> E\\<^bsub>interf r\\<^sub>2\\<^esub>\\<close> for e\n      using that p\\<^sub>2.po2.edge_commutativity bbb2  p\\<^sub>2.r.r.morph_edge_range\n        \\<open>\\<And>e. e\\<in> E\\<^bsub>rhs r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n      by (simp add: morph_comp_def)\n  next\n    show \\<open>Ex1M\n        (\\<lambda>xa. morphism (to_ngraph H\\<^sub>2) D' xa \\<and>\n               (\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>xa \\<circ>\\<^sub>\\<rightarrow> to_nmorph (s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h)\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v) \\<and>\n               (\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>xa \\<circ>\\<^sub>\\<rightarrow> to_nmorph (s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h)\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e) \\<and> (\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>xa \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v) \\<and> (\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>xa \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e))\n        (to_ngraph H\\<^sub>2)\\<close>\n      if \\<open>graph D'\\<close>\n       \\<open>morphism (to_ngraph (rhs r\\<^sub>2)) D' x\\<close>\n       \\<open>morphism (to_ngraph D\\<^sub>2) D' y\\<close>\n       \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (interf r\\<^sub>2)\\<^esub>. \\<^bsub>x \\<circ>\\<^sub>\\<rightarrow> to_nmorph b\\<^sub>2'\\<^esub>\\<^sub>V v = \\<^bsub>y \\<circ>\\<^sub>\\<rightarrow> to_nmorph (pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2)\\<^esub>\\<^sub>V v\\<close>\n       \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (interf r\\<^sub>2)\\<^esub>. \\<^bsub>x \\<circ>\\<^sub>\\<rightarrow> to_nmorph b\\<^sub>2'\\<^esub>\\<^sub>E e = \\<^bsub>y \\<circ>\\<^sub>\\<rightarrow> to_nmorph (pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2)\\<^esub>\\<^sub>E e\\<close>\n     for D' :: \"('g,'h) ngraph\" and x y\n    proof -\n\n      have a: \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (interf r\\<^sub>2)\\<^esub>. \\<^bsub>x \\<circ>\\<^sub>\\<rightarrow> to_nmorph b\\<^sub>2'\\<^esub>\\<^sub>V v = \\<^bsub>y \\<circ>\\<^sub>\\<rightarrow> to_nmorph m\\<^sub>2\\<^esub>\\<^sub>V v\\<close>\n        using \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (interf r\\<^sub>2)\\<^esub>. \\<^bsub>x \\<circ>\\<^sub>\\<rightarrow> to_nmorph b\\<^sub>2'\\<^esub>\\<^sub>V v = \\<^bsub>y \\<circ>\\<^sub>\\<rightarrow> to_nmorph (pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2)\\<^esub>\\<^sub>V v\\<close>\n            \\<open>\\<And>v. v\\<in>V\\<^bsub>interf r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>m\\<^sub>2\\<^esub>\\<^sub>V v\\<close>\n          by (simp add: morph_comp_def to_nmorph_def to_ngraph_def)\n\n      have b: \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (interf r\\<^sub>2)\\<^esub>. \\<^bsub>x \\<circ>\\<^sub>\\<rightarrow> to_nmorph b\\<^sub>2'\\<^esub>\\<^sub>E e = \\<^bsub>y \\<circ>\\<^sub>\\<rightarrow> to_nmorph m\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n        using \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (interf r\\<^sub>2)\\<^esub>. \\<^bsub>x \\<circ>\\<^sub>\\<rightarrow> to_nmorph b\\<^sub>2'\\<^esub>\\<^sub>E e = \\<^bsub>y \\<circ>\\<^sub>\\<rightarrow> to_nmorph (pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2)\\<^esub>\\<^sub>E e\\<close>\n            \\<open>\\<And>e. e\\<in>E\\<^bsub>interf r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>pb.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>m\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n          by (simp add: morph_comp_def to_nmorph_def to_ngraph_def)\n\n        \n        \n        obtain u where \\<open>morphism (to_ngraph H\\<^sub>2) D' u\\<close>\n          and u1: \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close> \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close> \n          and u2: \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close> \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n          using p\\<^sub>2.po2.universal_property[OF  \\<open>graph D'\\<close> \\<open>morphism (to_ngraph (rhs r\\<^sub>2)) D' x\\<close> \\<open>morphism (to_ngraph D\\<^sub>2) D' y\\<close> a b]\n          by fast\n\n(* technical reasons *)\n        have m: \\<open>morphism (to_ngraph H\\<^sub>2) D' u \\<and>\n          (\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v) \\<and> \n          (\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e) \\<and> \n          (\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v) \\<and> \n          (\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e)\\<close>\n          using u1 u2 \\<open>morphism (to_ngraph H\\<^sub>2) D' u\\<close>\n          by fastforce\n\n        show ?thesis\n        proof (rule_tac x = u in exI, safe)\n          show \\<open>morphism (to_ngraph H\\<^sub>2) D' u\\<close>\n            using \\<open>morphism (to_ngraph H\\<^sub>2) D' u\\<close> by assumption\n        next\n          show \\<open>\\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph (s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h)\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close> if \\<open>v \\<in> V\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>\\<close> for v\n            using that \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close>\n              \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>V v\\<close>\n            by (auto simp add: morph_comp_def to_nmorph_def to_ngraph_def)\n        next\n          show \\<open>\\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph (s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h)\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close> if \\<open>e \\<in> E\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>\\<close> for e\n            using that \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n              \\<open>\\<And>e. e \\<in> E\\<^bsub>rhs r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n            by (auto simp add: morph_comp_def to_nmorph_def to_ngraph_def)\n        next\n          show \\<open>\\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close> if \\<open>v \\<in> V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>\\<close> for v\n            using that \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close>\n            by simp\n        next\n          show \\<open>\\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close> if \\<open>e \\<in> E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>\\<close> for e\n            using that \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n            by simp\n        next\n          show \\<open>\\<^bsub>ya\\<^esub>\\<^sub>E e = \\<^bsub>u\\<^esub>\\<^sub>E e\\<close>\n            if \\<open>morphism (to_ngraph H\\<^sub>2) D' ya\\<close>\n             \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph (s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h)\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close>\n             \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph (s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h)\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n             \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close>\n             \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n             \\<open>e \\<in> E\\<^bsub>to_ngraph H\\<^sub>2\\<^esub>\\<close>\n           for ya e\n          proof -\n        \n            have n: \\<open>morphism (to_ngraph H\\<^sub>2) D' ya \\<and>\n              (\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v) \\<and>\n              (\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e) \\<and> \n              (\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v) \\<and> \n              (\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e)\\<close>\n            proof (intro conjI)\n              show \\<open>morphism (to_ngraph H\\<^sub>2) D' ya\\<close>\n                using \\<open>morphism (to_ngraph H\\<^sub>2) D' ya\\<close>\n                by assumption\n            next\n              show \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close>\n                using \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close>\n                  \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph (s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h)\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close>\n                  \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>V v\\<close>\n                by (simp add: morph_comp_def to_ngraph_def to_nmorph_def)\n            next\n              show \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n                using \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n                  \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph (s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h)\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n                  \\<open>\\<And>e. e \\<in> E\\<^bsub>rhs r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n                by (simp add: morph_comp_def to_ngraph_def to_nmorph_def)\n            next\n              show \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close>\n                using \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close>\n                by assumption\n            next\n              show \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n                using \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n                by assumption\n            qed\n\n            show ?thesis\n              using that ex_eq[OF p\\<^sub>2.po2.universal_property[OF  \\<open>graph D'\\<close> \\<open>morphism (to_ngraph (rhs r\\<^sub>2)) D' x\\<close> \\<open>morphism (to_ngraph D\\<^sub>2) D' y\\<close> a b] n m]\n              by fast\n          qed\n        next\n          show \\<open>\\<^bsub>ya\\<^esub>\\<^sub>V v = \\<^bsub>u\\<^esub>\\<^sub>V v\\<close>\n            if \\<open>morphism (to_ngraph H\\<^sub>2) D' ya\\<close>\n             \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph (s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h)\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close>\n             \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph (s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h)\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n             \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close>\n             \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n             \\<open>v \\<in> V\\<^bsub>to_ngraph H\\<^sub>2\\<^esub>\\<close>\n           for ya v\n          proof -\n        \n            have n: \\<open>morphism (to_ngraph H\\<^sub>2) D' ya \\<and>\n              (\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v) \\<and>\n              (\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e) \\<and> \n              (\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v) \\<and> \n              (\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e)\\<close>\n            proof (intro conjI)\n              show \\<open>morphism (to_ngraph H\\<^sub>2) D' ya\\<close>\n                using \\<open>morphism (to_ngraph H\\<^sub>2) D' ya\\<close>\n                by assumption\n            next\n              show \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close>\n                using \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close>\n                  \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph (s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h)\\<^esub>\\<^sub>V v = \\<^bsub>x\\<^esub>\\<^sub>V v\\<close>\n                  \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>V v\\<close>\n                by (simp add: morph_comp_def to_ngraph_def to_nmorph_def)\n            next\n              show \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n                using \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>u \\<circ>\\<^sub>\\<rightarrow> to_nmorph f\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n                  \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph (rhs r\\<^sub>2)\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph (s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h)\\<^esub>\\<^sub>E e = \\<^bsub>x\\<^esub>\\<^sub>E e\\<close>\n                  \\<open>\\<And>e. e \\<in> E\\<^bsub>rhs r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n                by (simp add: morph_comp_def to_ngraph_def to_nmorph_def)\n            next\n              show \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close>\n                using \\<open>\\<forall>v\\<in>V\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>y\\<^esub>\\<^sub>V v\\<close>\n                by assumption\n            next\n              show \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n                using \\<open>\\<forall>e\\<in>E\\<^bsub>to_ngraph D\\<^sub>2\\<^esub>. \\<^bsub>ya \\<circ>\\<^sub>\\<rightarrow> to_nmorph h\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>y\\<^esub>\\<^sub>E e\\<close>\n                by assumption\n            qed\n\n            show ?thesis\n              using that ex_eq[OF p\\<^sub>2.po2.universal_property[OF  \\<open>graph D'\\<close> \\<open>morphism (to_ngraph (rhs r\\<^sub>2)) D' x\\<close> \\<open>morphism (to_ngraph D\\<^sub>2) D' y\\<close> a b] n m]\n              by fast\n          qed\n        qed\n      qed\n    qed\n\n\n  interpret twelve: pushout_diagram pb.A D\\<^sub>2 neun.H H\\<^sub>2 pb.c neun.c h\\<^sub>2 s\\<^sub>2\n   using pushout_decomposition[OF pb.c.morphism_axioms s\\<^sub>2.morphism_axioms neun.po.flip_diagram \"9+12.flip_diagram\"]\n      \\<open>\\<And>e. e \\<in> E\\<^bsub>pb.A\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.c\\<^esub>\\<^sub>E e = \\<^bsub>h\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> pb.c\\<^esub>\\<^sub>E e\\<close> \\<open>\\<And>v. v \\<in> V\\<^bsub>pb.A\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.c\\<^esub>\\<^sub>V v = \\<^bsub>h\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> pb.c\\<^esub>\\<^sub>V v\\<close>\n   by simp\n\n(* one side *)\n    interpret \"7+11\": pushout_diagram \"interf r\\<^sub>2\" acht.H \"lhs r\\<^sub>2\" H\\<^sub>1 \"acht.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\" b\\<^sub>2 s\\<^sub>1 \"h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\"\n      using pushout_composition[OF seven.flip_diagram eleven.flip_diagram ] by assumption\n\n    interpret \"9+10\": pushout_diagram \"interf r\\<^sub>2\" acht.H \"rhs r\\<^sub>2\" ten.H \"acht.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\" b\\<^sub>2' ten.h \"ten.c \\<circ>\\<^sub>\\<rightarrow> neun.h\"\n      using pushout_composition[OF neun.po.flip_diagram ten.po.pushout_diagram_axioms] by assumption\n\n(* flipped ones are needed for the sequential independence *)\n    interpret pushout_diagram \"interf r\\<^sub>2\" \"lhs r\\<^sub>2\" acht.H H\\<^sub>1 b\\<^sub>2 \"acht.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\" \"h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\" s\\<^sub>1\n      using \"7+11.flip_diagram\" by assumption\n\n    interpret pushout_diagram \"interf r\\<^sub>2\" \"rhs r\\<^sub>2\" acht.H ten.H b\\<^sub>2' \"acht.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\" \"ten.c \\<circ>\\<^sub>\\<rightarrow> neun.h\" ten.h\n      using \"9+10.flip_diagram\" by assumption\n\n(* show second direct derivation *)\n    interpret injective_morphism \"lhs r\\<^sub>2\" H\\<^sub>1 \"h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\"\n      using inj_comp_inj[OF i\\<^sub>2.injective_morphism_axioms h\\<^sub>1.injective_morphism_axioms]\n      by assumption\n\n    interpret direct_derivation r\\<^sub>2  b\\<^sub>2 b\\<^sub>2' H\\<^sub>1 \"h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\" acht.H \"acht.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\" s\\<^sub>1 ten.H \"ten.c \\<circ>\\<^sub>\\<rightarrow> neun.h\" ten.h\n      ..\n\n(* first seq. indep. *)\n    interpret p3: sequential_independence r\\<^sub>1 b\\<^sub>1 b\\<^sub>1' G g\\<^sub>1 D\\<^sub>1 m\\<^sub>1 c\\<^sub>1 H\\<^sub>1 f\\<^sub>1 h\\<^sub>1 r\\<^sub>2 b\\<^sub>2 b\\<^sub>2' \"h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\" acht.H \"acht.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>2\" s\\<^sub>1 ten.H \"ten.c \\<circ>\\<^sub>\\<rightarrow> neun.h\" ten.h\n    proof\n      show \\<open>\\<exists>i. morphism (rhs r\\<^sub>1) acht.H i \\<and>\n        (\\<forall>v\\<in>V\\<^bsub>rhs r\\<^sub>1\\<^esub>. \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>V v) \\<and> (\\<forall>e\\<in>E\\<^bsub>rhs r\\<^sub>1\\<^esub>. \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>E e)\\<close>\n      proof (rule_tac x = acht.h in exI, intro conjI)\n        show \\<open>morphism (rhs r\\<^sub>1) acht.H acht.h\\<close>\n          using acht.inc_h.morphism_axioms by assumption\n      next\n        show \\<open>\\<forall>v\\<in>V\\<^bsub>rhs r\\<^sub>1\\<^esub>. \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>V v\\<close>\n          by (simp add: \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>V v\\<close>)\n      next\n        show \\<open>\\<forall>e\\<in>E\\<^bsub>rhs r\\<^sub>1\\<^esub>. \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>E e\\<close>\n          by (simp add: \\<open>\\<And>e. e \\<in> E\\<^bsub>rhs r\\<^sub>1\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> acht.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>1\\<^esub>\\<^sub>E e\\<close>)\n      qed\n    next\n      show \\<open>\\<exists>j. morphism (lhs r\\<^sub>2) D\\<^sub>1 j \\<and>\n        (\\<forall>v\\<in>V\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> j\\<^esub>\\<^sub>V v = \\<^bsub>h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>V v) \\<and> (\\<forall>e\\<in>E\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> j\\<^esub>\\<^sub>E e = \\<^bsub>h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>E e)\\<close>\n      proof (rule_tac x = i\\<^sub>2 in exI, intro conjI)\n        show \\<open>morphism (lhs r\\<^sub>2) D\\<^sub>1 i\\<^sub>2\\<close>\n          using i\\<^sub>2.morphism_axioms by assumption\n      next\n        show \\<open>\\<forall>v\\<in>V\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>V v = \\<^bsub>h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>V v\\<close>\n          by simp\n      next\n        show \\<open>\\<forall>e\\<in>E\\<^bsub>lhs r\\<^sub>2\\<^esub>. \\<^bsub>h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>E e = \\<^bsub>h\\<^sub>1 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>2\\<^esub>\\<^sub>E e\\<close>\n          by simp\n      qed\n    qed\n\n\n\n\n    interpret \"6+12\": pushout_diagram \"interf r\\<^sub>1\" neun.H \"lhs r\\<^sub>1\" H\\<^sub>2 \"neun.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\" b\\<^sub>1 s\\<^sub>2 \"h\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\"\n      using pushout_composition[OF six.pushout_diagram_axioms twelve.flip_diagram ] by assumption\n    \n    interpret pushout_diagram \"interf r\\<^sub>1\" \"lhs r\\<^sub>1\" neun.H H\\<^sub>2 b\\<^sub>1 \"neun.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\" \"h\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\" s\\<^sub>2\n      using \"6+12.flip_diagram\" by assumption\n\n    interpret \"8+10\": pushout_diagram \"interf r\\<^sub>1\" neun.H \"rhs r\\<^sub>1\" ten.H \"neun.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\" b\\<^sub>1' ten.c \"ten.h \\<circ>\\<^sub>\\<rightarrow> acht.h\"\n      using pushout_composition[OF acht.po.flip_diagram ten.po.flip_diagram] by assumption\n\n    thm \"8+10.flip_diagram\"\n    interpret pushout_diagram \"interf r\\<^sub>1\" \"rhs r\\<^sub>1\" neun.H ten.H b\\<^sub>1' \"neun.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\" \"ten.h \\<circ>\\<^sub>\\<rightarrow> acht.h\" ten.c\n      using \"8+10.flip_diagram\" by assumption\n\n    interpret injective_morphism \"lhs r\\<^sub>1\" H\\<^sub>2 \"h\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\"\n      using inj_comp_inj[OF i\\<^sub>1.injective_morphism_axioms h\\<^sub>2.injective_morphism_axioms]\n      by assumption\n\n    interpret direct_derivation r\\<^sub>1 b\\<^sub>1 b\\<^sub>1' H\\<^sub>2 \"h\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\" neun.H \"neun.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\" s\\<^sub>2 ten.H \"ten.h \\<circ>\\<^sub>\\<rightarrow> acht.h\" ten.c\n      ..\n\n    interpret p4: sequential_independence r\\<^sub>2 b\\<^sub>2 b\\<^sub>2' G g\\<^sub>2 D\\<^sub>2 m\\<^sub>2 c\\<^sub>2 H\\<^sub>2 f\\<^sub>2 h\\<^sub>2 r\\<^sub>1 b\\<^sub>1 b\\<^sub>1' \"h\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\" neun.H \"neun.c \\<circ>\\<^sub>\\<rightarrow> j\\<^sub>1\" s\\<^sub>2 ten.H \"ten.h \\<circ>\\<^sub>\\<rightarrow> acht.h\" ten.c \n    proof\n      show \\<open>\\<exists>i. morphism (rhs r\\<^sub>2) neun.H i \\<and>\n        (\\<forall>v\\<in>V\\<^bsub>rhs r\\<^sub>2\\<^esub>. \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>V v) \\<and> (\\<forall>e\\<in>E\\<^bsub>rhs r\\<^sub>2\\<^esub>. \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>E e)\\<close>\n        using \\<open>\\<And>e. e \\<in> E\\<^bsub>rhs r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>E e = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>E e\\<close> \\<open>\\<And>v. v \\<in> V\\<^bsub>rhs r\\<^sub>2\\<^esub> \\<Longrightarrow> \\<^bsub>s\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> neun.h\\<^esub>\\<^sub>V v = \\<^bsub>f\\<^sub>2\\<^esub>\\<^sub>V v\\<close> neun.inc_h.morphism_axioms by blast\n    next\n      show \\<open>\\<exists>j. morphism (lhs r\\<^sub>1) D\\<^sub>2 j \\<and>\n        (\\<forall>v\\<in>V\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>h\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> j\\<^esub>\\<^sub>V v = \\<^bsub>h\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\\<^esub>\\<^sub>V v) \\<and> (\\<forall>e\\<in>E\\<^bsub>lhs r\\<^sub>1\\<^esub>. \\<^bsub>h\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> j\\<^esub>\\<^sub>E e = \\<^bsub>h\\<^sub>2 \\<circ>\\<^sub>\\<rightarrow> i\\<^sub>1\\<^esub>\\<^sub>E e)\\<close>\n        using i\\<^sub>1.morphism_axioms by blast\n    qed\n\n    show ?thesis\n      using p3.sequential_independence_axioms p4.sequential_independence_axioms\n     by fast\nqed\n\nend", "meta": {"author": "UoYCS-plasma", "repo": "DPO-Formalisation", "sha": "0bc86b77a3f2d8ca85b4a7d0de877dc19aa05c46", "save_path": "github-repos/isabelle/UoYCS-plasma-DPO-Formalisation", "path": "github-repos/isabelle/UoYCS-plasma-DPO-Formalisation/DPO-Formalisation-0bc86b77a3f2d8ca85b4a7d0de877dc19aa05c46/LocalChurchRosser.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631698328916, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.2660492152990641}}
{"text": "(* KEEP IT SIMPLE AND STUPID *)\n\ntheory NuPrime \\<comment> \\<open>The Primary Theory of the \\<nu>-System\\<close>\n  imports Main \"HOL-Library.Adhoc_Overloading\" NuHelpMath\nbegin\n\ntext \\<open>The fundamental theory for \\<nu>-system\\<close>\n\nsection Preliminary\n\n\nnamed_theorems \\<nu>elim \"\\<nu>-type elimination rules\"\nnamed_theorems \\<nu>def \\<open>primitive definitions used to unfold in proofs of primitive instructions.\\<close>\n  (* and \\<nu>address_def \\<open>primitive definitions for unfolding in proofs for address\\<close> *)\n  and \\<nu>post_construct and \\<nu>auto_destruct\nnamed_theorems typing_expn \"expansion theorems for abstractions\" and lrep_exps and nu_exps\n\nsection\\<open>Low representation for semantics\\<close>\n\nsubsection \\<open>Memory Pointer\\<close>\n\ndatatype msegment = Null (*address space*) nat | MSegment nat\ntype_synonym addr_space = nat\n  \\<comment> \\<open>Address space is a notion of the LLVM. The space 0 is the main memory of the device.\n    Space other than 0 is specified depending on platform, which may represent addresses on remote devices like display card\\<close>\n\ndatatype 'offset memaddr = memaddr (segment_of: msegment) (offset_of: 'offset ) (infixl \"|+\" 60)\ndeclare memaddr.sel[iff]\n\nabbreviation shift_addr :: \" 'a::plus memaddr \\<Rightarrow> 'a \\<Rightarrow> 'a memaddr\" (infixl \"||+\" 60)\n  where \"shift_addr addr delta \\<equiv> map_memaddr (\\<lambda>x. x + delta) addr\"\nlemma memaddr_forall[lrep_exps]: \"All P \\<longleftrightarrow> (\\<forall>base ofs. P (base  |+ ofs))\" by (metis memaddr.exhaust)\nlemma memaddr_exists[lrep_exps]: \"Ex P \\<longleftrightarrow> (\\<exists>base ofs. P (base  |+ ofs))\" by (metis memaddr.exhaust)\n\n\n\n(* subsection \\<open>Function table & Function pointer\\<close>\n\ntypedef fun_addr = \"UNIV :: nat set\" .. *)\n\nsubsection \\<open>Deep Value Model\\<close>\n\ndatatype \"value\" = DM_int nat nat | DM_pointer \"nat memaddr\" | DM_fusion \"value\" \"value\"\n  | DM_record \"value\" | DM_array \"value list\" | (* DM_fun_addr fun_addr | *) DM_void\n\nsubsection \\<open>Memory & Heap\\<close>\n\ndatatype resource_key = MemAddress \"nat memaddr\" | ChainDB_key nat\n\nlemma resource_key_forall: \"All P \\<longleftrightarrow> (\\<forall>addr. P (MemAddress addr)) \\<and> (\\<forall>n. P (ChainDB_key n))\" by (metis resource_key.exhaust)\nlemma resource_key_exists: \"Ex P \\<longleftrightarrow> (\\<exists>addr. P (MemAddress addr)) \\<or> (\\<exists>n. P (ChainDB_key n))\" by (metis resource_key.exhaust)\n\ntype_synonym heap = \"resource_key \\<rightharpoonup> value\"\n\nsubsection \\<open>State Model\\<close>\n\ndatatype 'a state = Success (dest_state: \"heap \\<times> 'a\") | Fail | PartialCorrect\ntext\\<open> The basic state of the \\<nu>-system virtual machine is represented by type \"('a::lrep) state\"}.\n  The valid state `Success` essentially has two major form, one without registers and another one with them,\n      \\<^item> \"StatOn (x1, x2, \\<cdots>, xn, void)\",\n  where \"(x1, x2, \\<cdots>, xn, void)\" represents the stack in the state, with @{term x\\<^sub>i} as the i-th element on the stack.\n  The @{term STrap} is trapped state due to invalid operations like zero division.\n  The negative state @{term PartialCorrect} represents the admissible error situation that is not considered in partial correctness.\n  For example, @{term PartialCorrect} may represents an admissible crash, and in that case the partial correctness certifies that\n    ``if the program exits normally, the output would be correct''.\\<close>\n\ndeclare state.split[split]\n\ntype_synonym ('a,'b) proc = \" (heap \\<times> 'a) \\<Rightarrow> 'b state\" (infix \"\\<longmapsto>\" 0)\n\n(* consts fun_table :: \" fun_addr \\<rightharpoonup> 'a \\<longmapsto> 'b \"\nconsts fun_addr_NULL :: fun_addr\n\nspecification (fun_table)\n  fun_addr_NULL: \"fun_table fun_addr_NULL = None\" by auto *)\n\n\ndefinition AvailableSegments :: \"heap \\<Rightarrow> msegment set\"\n  where \"AvailableSegments heap = {seg. \\<forall>ofs. heap (MemAddress (seg |+ ofs)) = None}\"\n\ndefinition Heap :: \"heap \\<Rightarrow> bool\" where \"Heap h \\<longleftrightarrow> infinite (AvailableSegments h)\"\n\nlemma [intro]: \"Heap h \\<Longrightarrow> Heap (h(k := v))\" proof -\n  have \"AvailableSegments h \\<subseteq> {(case k of MemAddress (seg |+ ofs) \\<Rightarrow> seg)} \\<union> (AvailableSegments (h(k := v)))\"\n    unfolding AvailableSegments_def by auto \n  then show \"Heap h \\<Longrightarrow> Heap (h(k := v))\" \n    unfolding Heap_def using infinite_super by auto\nqed\n\nlemma Heap_subset: \"h' \\<subseteq>\\<^sub>m h \\<Longrightarrow> Heap h \\<Longrightarrow> Heap h' \"\n  unfolding Heap_def subgoal premises prems proof -\n  have \"AvailableSegments h \\<subseteq> AvailableSegments h'\"\n    unfolding AvailableSegments_def using prems(1)\n    by (smt (verit, best) Collect_mono domIff map_le_def)\n  then show ?thesis using prems(2) using finite_subset by blast\nqed done\n\nlemma Heap_map_add: \"Heap (h1 ++ h2) \\<Longrightarrow> Heap h2\"\n  using Heap_subset map_le_map_add by blast\n\nlemma Heap_restrict[intro]: \"Heap h \\<Longrightarrow> Heap (h |` S)\"\n  by (metis domIff map_le_def restrict_map_def Heap_subset)\n\n\ntext \\<open>The semantic framework follows a style of shallow embedding, where semantics for different type (e.g. integers, floats)\n  are modelled by different Isabelle type. Model types are constrained by the base type class {\\it lrep} and types representing\n  objects that supports certain features are constrained by specific sub-classes which extend the base class {\\it lrep} finally. \\<close>\n\ndatatype llty = llty_int nat \\<comment> \\<open>int bits\\<close> | llty_pointer | llty_tup llty | llty_array llty nat | llty_nil | llty_fusion llty llty | Lty_fun_addr\n\nclass lrep =  \\<comment>\\<open>The basic class for types modelling concrete objects\\<close>\n  fixes llty :: \" 'a itself \\<Rightarrow> llty \"\n  fixes deepize :: \" 'a \\<Rightarrow> value \"\n  fixes shallowize :: \" value \\<Rightarrow> 'a \"\n  assumes deepize_inj[simp]: \" shallowize (deepize x) = x \"\n\nlemma [simp]: \"shallowize o deepize = id\" by fastforce\n\nlemma deepize_inj2[simp]: \"deepize a = deepize b \\<longleftrightarrow> a = b\"\n  using deepize_inj by metis\n\nabbreviation \"map_deepmodel f x \\<equiv> deepize (f (shallowize x))\"\n\nsyntax \"_LLTY_\" :: \"type \\<Rightarrow> logic\" (\"LLTY'(_')\")\ntranslations  \"LLTY('x)\" == \"CONST llty TYPE('x)\"\n\nclass ceq =  \\<comment> \\<open>equality comparison\\<close>\n  fixes ceqable :: \" heap \\<Rightarrow> 'a \\<Rightarrow> 'a \\<Rightarrow> bool\"\n    \\<comment> \\<open>Whether two values could be compared for equality. e.g. two INF cannot be compared; the dangling pointer also cannot\\<close>\n  fixes ceq :: \" 'a \\<Rightarrow> 'a \\<Rightarrow> bool\" \\<comment> \\<open>The equality of two values.\n    It is only valid when the two values could be compared, i.e., the @{term ceqable} for them is true.\\<close>\n  assumes ceqable_sym[simp]: \"ceqable h x y = ceqable h y x\"\n  assumes ceq_refl[intro]: \"ceqable h x x \\<Longrightarrow> ceq x x\"\n  assumes ceq_sym[simp]: \"ceqable h x y \\<Longrightarrow> ceq x y \\<longleftrightarrow> ceq y x\"\n  assumes ceq_trans: \"ceqable h x y \\<Longrightarrow> ceqable h y z \\<Longrightarrow> ceqable h x z\n    \\<Longrightarrow> ceq x y \\<Longrightarrow> ceq y z \\<Longrightarrow> ceq x z\"\n\n\nsubsection \\<open>The \\<nu>-type\\<close>\n\ntype_synonym ('a,'b) \\<nu> = \" 'b \\<Rightarrow> 'a set \"\n\nsubsubsection \\<open>Definitions\\<close>\n\ndatatype ('a,'b) typing = typing (typing_img: 'b ) (typing_nu: \"('a,'b) \\<nu>\") (\"_ \\<tycolon> _\" [18,18] 17) \\<comment>\\<open>shortcut keys \"<ty>\"\\<close>\nprimrec nu_of :: \"('a,'b) typing \\<Rightarrow> ('a,'b) \\<nu>\" where \"nu_of (x \\<tycolon> N) = N\"\nprimrec image_of :: \"('a,'b) typing \\<Rightarrow> 'b\" where \"image_of (x \\<tycolon> N) = x\"\n\ndefinition RepSet :: \"('a,'b) typing \\<Rightarrow> 'a set\" (\"\\<tort_lbrace> _ \\<tort_rbrace>\" [10] ) where \"\\<tort_lbrace> ty \\<tort_rbrace> = (case ty of (x \\<tycolon> N) \\<Rightarrow> N x)\"\ndefinition Refining :: \"'a \\<Rightarrow> ('a,'b) \\<nu> \\<Rightarrow>  'b \\<Rightarrow> bool\" (\"(_/ \\<nuLinkL> _  \\<nuLinkR>/ _)\" [27,15,27] 26) \\<comment>\\<open>shortcut keys \"--<\" and \">--\"\\<close>\n  where  \"(p \\<nuLinkL> N \\<nuLinkR> x) \\<longleftrightarrow> p \\<in> N x\"\ndefinition Inhabited :: \" 'a set \\<Rightarrow> bool\" where  \"Inhabited S = (\\<exists>p. p \\<in> S)\"\nabbreviation InhabitNu :: \" 'b \\<Rightarrow> ('a,'b) \\<nu> \\<Rightarrow> bool\" (\"_ \\<ratio> _\" [18,18] 17)  \\<comment>\\<open>shortcut keys \":TY:\"\\<close>\n  where  \" (x \\<ratio> T) \\<equiv> Inhabited \\<tort_lbrace>x \\<tycolon> T\\<tort_rbrace>\"\ntext \\<open>The @{term \"x \\<tycolon> N\"} is a predication specifying concrete values,\n  e.g. @{prop \" a_concrete_int32 \\<in> \\<tort_lbrace>(42::nat) \\<tycolon> N 32\\<tort_rbrace>\"} and also \"state \\<in> State (\\<tort_lbrace>42 \\<tycolon> N\\<tort_rbrace> \\<times> \\<tort_lbrace>24 \\<tycolon> N\\<tort_rbrace> \\<times> \\<cdots> )\".\n  It constitutes basic elements in specification.\n  The @{prop \"p \\<nuLinkL> N \\<nuLinkR> x\"} as the abbreviation of $p \\<in> (x \\<tycolon> N)$ is an abstraction between concrete value @{term p} and\n  abstracted {\\it image} @{term x} via the \\<nu>-{\\it abstractor} @{term N} which defines the abstraction relationship itself.\n  The next @{prop \" x \\<ratio> N\"} is a proposition stating @{term x} is an image of abstractor @{term N} and therefore\n  the \\<nu>-type @{term \"x \\<tycolon> N\"} is inhabited. Basically it is used to derive implicated conditions of images,\n  e.g. @{prop \"( 42 \\<ratio> N 32) \\<Longrightarrow> 42 < 2^32\"}\\<close>\n\nlemma [simp]: \"p \\<in> \\<tort_lbrace>x \\<tycolon> T\\<tort_rbrace> \\<longleftrightarrow> p \\<nuLinkL> T \\<nuLinkR> x\" unfolding RepSet_def Refining_def by simp\nlemma typing_inhabited: \"p \\<nuLinkL> T \\<nuLinkR> x \\<Longrightarrow> x \\<ratio> T\" unfolding Refining_def Inhabited_def RepSet_def by simp blast\n\n\nsubsubsection \\<open>Properties\\<close>\n\ndefinition \\<nu>Zero :: \"('a::{zero,lrep},'b) \\<nu> \\<Rightarrow> 'b \\<Rightarrow> bool\"\n  where [\\<nu>def]: \"\\<nu>Zero N x \\<longleftrightarrow> (0 \\<nuLinkL> N \\<nuLinkR> x )\"\n\ndefinition \\<nu>Equal :: \"('a::{lrep,ceq}, 'b) \\<nu> \\<Rightarrow> ('b \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow> ('b \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow> bool\"\n  where [\\<nu>def]: \"\\<nu>Equal N can_eq eq \\<longleftrightarrow> (\\<forall>p1 p2 x1 x2 heap.\n    can_eq x1 x2 \\<and> (p1 \\<nuLinkL> N \\<nuLinkR> x1) \\<and> (p2 \\<nuLinkL> N \\<nuLinkR> x2) \\<longrightarrow> ceqable heap p1 p2 \\<and> (ceq p1 p2 = eq x1 x2))\"\n\n\nsection\\<open>Structures for construction\\<close>\n\nsubsection \\<open>Stack structure\\<close>\n\ninstantiation prod :: (lrep,lrep) lrep begin\ndefinition llty_prod :: \"('a \\<times> 'b) itself \\<Rightarrow> llty\" where \"llty_prod _ = llty_fusion LLTY('a) LLTY('b)\"\ndefinition deepize_prod :: \" 'a \\<times> 'b \\<Rightarrow> value \" where\n  \"deepize_prod = (\\<lambda>(a,b). DM_fusion (deepize a) (deepize b))\"\ndefinition shallowize_prod :: \"value \\<Rightarrow> 'a \\<times> 'b\" where\n  \"shallowize_prod x = (case x of DM_fusion a b \\<Rightarrow> (shallowize a, shallowize b))\"\ninstance apply standard\n  subgoal for x by (cases x) (auto simp add: shallowize_prod_def deepize_prod_def) done\nend\n\n\nprimrec is_stack :: \"value \\<Rightarrow> bool\" where\n  \"is_stack (DM_fusion a b) \\<longleftrightarrow> is_stack b\"\n| \"is_stack DM_void \\<longleftrightarrow> True\"\n| \"is_stack (DM_int _ _) \\<longleftrightarrow> False\"\n| \"is_stack (DM_pointer _) \\<longleftrightarrow> False\"\n| \"is_stack (DM_record _) \\<longleftrightarrow> False\"\n| \"is_stack (DM_array _) \\<longleftrightarrow> False\"\n(* | \"is_stack (DM_fun_addr _) \\<longleftrightarrow> False\" *)\n\ntypedef stack = \"UNIV :: value list set\"\n  morphisms values_of stack ..\n\nsetup_lifting type_definition_stack\n\ndeclare values_of_inverse[simp] values_of_inject[simp]\nlemmas stack_inverse[simp] = stack_inverse[simplified]\nlemmas stack_inject[simp] = stack_inject[simplified]\n\nhide_fact stack.stack_inject stack.stack_inverse\n\nabbreviation stack_cat (infixr \"@\\<^sub>s\\<^sub>k\" 65) where \"(a @\\<^sub>s\\<^sub>k b) \\<equiv> stack (values_of a @ values_of b)\"\nabbreviation stack_cons (infixr \"#\\<^sub>s\\<^sub>k\" 65) where \"(a #\\<^sub>s\\<^sub>k b) \\<equiv> stack (a # values_of b)\"\n\nlemma [simp]:\n  \"values_of a = values_of b @ values_of c \\<longleftrightarrow> a = b @\\<^sub>s\\<^sub>k c\"\n  by (metis stack_inverse values_of_inverse)\n\n\nclass stack = lrep +\n  fixes stack_deepize :: \" 'a \\<Rightarrow> stack \"\n  fixes stack_shallowize :: \" stack \\<Rightarrow> 'a \"\n(*  assumes stack_is_stack[simp]: \"is_stack (deepize x)\" *)\n  assumes stack_deepize_inj[simp]: \"stack_shallowize (stack_deepize k) = k\"\n\ntext \\<open>The \\<^class>\\<open>stack\\<close> is an artificial constraint.\n  Though \\<^class>\\<open>stack\\<close> is identical to \\<^class>\\<open>lrep\\<close> in logic, most of types e.g. word, are only\n  instantiated to \\<^class>\\<open>lrep\\<close> but no \\<^class>\\<open>stack\\<close> deliberately, and only prod and void are\n  instantiated to stack by the instantiation (lrep,stack) :: stack and void::stack.\n  By this deliberate constraints, once a type of class stack, it must a recursive pair\n  ending with void.\\<close>\n\n\nlemma stack_deepize_inj[simp]:\n  \"stack_deepize k1 = stack_deepize k2 \\<longleftrightarrow> k1 = k2\"\n  by (metis stack_deepize_inj)\n  \ninstantiation prod :: (lrep,stack) stack begin\nprimrec stack_deepize_prod :: \" 'a \\<times> 'b \\<Rightarrow> stack \"\n  where \"stack_deepize_prod (a,b) = deepize a #\\<^sub>s\\<^sub>k stack_deepize b\"\ndefinition stack_shallowize_prod :: \" stack \\<Rightarrow> 'a \\<times> 'b \"\n  where [simp]: \"stack_shallowize_prod s = (case values_of s of (a#b) \\<Rightarrow> (shallowize a, stack_shallowize (stack b)))\"\ninstance by standard (simp_all add: pair_All)\nend\n\ninstantiation \"stack\" :: stack begin\n\nprimrec value_to_list :: \"value \\<Rightarrow> value list\" where\n  \"value_to_list DM_void = []\" | \"value_to_list (DM_fusion x l) =  x # (value_to_list l)\"\nprimrec list_to_value :: \"value list \\<Rightarrow> value\" where\n  \"list_to_value [] = DM_void\" | \"list_to_value (x # l) =  DM_fusion x (list_to_value l)\"\nlemma stack_bij_list:\n  \"value_to_list (list_to_value l) = l\"\n  by (induct l) simp_all\n\ndefinition deepize_stack :: \" stack \\<Rightarrow> value \" where [simp]: \"deepize_stack s = list_to_value (values_of s)\"\ndefinition shallowize_stack :: \" value \\<Rightarrow> stack \" where [simp]: \"shallowize_stack v = stack (value_to_list v)\"\ndefinition stack_deepize_stack :: \" stack \\<Rightarrow> stack \" where [simp]: \"stack_deepize_stack x = x\"\ndefinition stack_shallowize_stack :: \" stack \\<Rightarrow> stack \" where [simp]: \"stack_shallowize_stack x = x\"\ninstance by standard (simp_all add: stack_bij_list)\nend\n\n\nsubsection \\<open>The \\<nu>-System VM and Procedure construction structures\\<close>\n\ntype_synonym assn = \"(heap \\<times> stack) set\" \\<comment> \\<open>assertion\\<close>\n\nsubsubsection \\<open>Types specifying states\\<close>\n\ndefinition StrictStateTy :: \" (heap \\<times> 'a::lrep) set \\<Rightarrow> 'a state set\" (\"!\\<S> _\" [56] 55)\n  where \"!\\<S> T = {s. case s of Success x \\<Rightarrow> x \\<in> T | Fail \\<Rightarrow> False | PartialCorrect \\<Rightarrow> False}\"\ndefinition LooseStateTy :: \" (heap \\<times> 'a::lrep) set \\<Rightarrow> 'a state set\" (\"\\<S> _\" [56] 55)\n  where \"\\<S> T = {s. case s of Success x \\<Rightarrow> x \\<in> T | Fail \\<Rightarrow> False | PartialCorrect \\<Rightarrow> True}\"\n\nlemma StrictStateTy_expn[iff,\\<nu>def]: \"Success x \\<in> !\\<S> T \\<equiv> x \\<in> T\"  \"\\<not> (Fail \\<in> !\\<S> T)\"  \"\\<not> (PartialCorrect \\<in> !\\<S> T)\"\n  and LooseStateTy_expn[iff,\\<nu>def]: \"Success x \\<in> \\<S> T \\<equiv> x \\<in> T\"  \"\\<not> (Fail \\<in> \\<S> T)\"  \"(PartialCorrect \\<in> \\<S> T)\"\n  by (simp_all add: StrictStateTy_def LooseStateTy_def)\nlemma LooseStateTy_expn' : \"x \\<in> \\<S> T \\<longleftrightarrow> x = PartialCorrect \\<or> (\\<exists>x'. x = Success x' \\<and> x' \\<in> T)\"\n  by (cases x) simp_all\n\nlemma StrictStateTy_elim[elim]: \"s \\<in> !\\<S> T \\<Longrightarrow> (\\<And>x. s = Success x \\<Longrightarrow> x \\<in> T \\<Longrightarrow> C) \\<Longrightarrow> C\" by (cases s) auto\nlemma StrictStateTy_intro[intro]: \" x \\<in> T \\<Longrightarrow> Success x \\<in> !\\<S> T\" by simp\nlemma LooseStateTy_E[elim]:\n  \"s \\<in> \\<S> T \\<Longrightarrow> (\\<And>x. s = Success x \\<Longrightarrow> x \\<in> T \\<Longrightarrow> C) \\<Longrightarrow> (s = PartialCorrect \\<Longrightarrow> C) \\<Longrightarrow> C\" by (cases s) auto\nlemma LooseStateTy_I[intro]:\n  \" x \\<in> T \\<Longrightarrow> Success x \\<in> \\<S> T\" and [intro]: \"PartialCorrect \\<in> \\<S> T\" by simp_all\nlemma LooseStateTy_upgrade: \"s \\<in> \\<S> T \\<Longrightarrow> s \\<noteq> PartialCorrect \\<Longrightarrow> s \\<in> !\\<S> T\" by (cases s) auto\nlemma StrictStateTy_degrade: \"s \\<in> !\\<S> T \\<Longrightarrow> s \\<in> \\<S> T\" by (cases s) auto\nlemma LooseStateTy_introByStrict: \"(s \\<noteq> PartialCorrect \\<Longrightarrow> s \\<in> !\\<S> T) \\<Longrightarrow> s \\<in> \\<S> T\" by (cases s) auto\n\nsubsubsection \\<open>Shallow model and Deep model\\<close>\n\ndefinition Deepize :: \" 'a::lrep set \\<Rightarrow> value set \" where \"Deepize S = deepize ` S\"\ndefinition Shallowize :: \" value set \\<Rightarrow> 'a::lrep set \" where \"Shallowize S = { p. deepize p \\<in> S}\"\n\nlemma Shallowize_Deepize[simp]: \"Shallowize (Deepize S) = S \"\n  unfolding Deepize_def Shallowize_def by (simp add: image_iff set_eq_iff)\n\ndefinition Deepize' :: \" (heap \\<times> 'a::stack) set \\<Rightarrow> assn \" where \"Deepize' S = apsnd stack_deepize ` S\"\ndefinition Shallowize' :: \" assn \\<Rightarrow> (heap \\<times> 'a::stack) set \" where \"Shallowize' S = {(h,s). (h,stack_deepize s) \\<in> S}\"\n\nlemma Deepize'_expn: \"(h, s) \\<in> Deepize' M \\<longleftrightarrow> (\\<exists>s'. stack_deepize s' = s \\<and> (h, s') \\<in> M)\"\n  unfolding Deepize'_def image_iff Bex_def by auto\n\nlemma Shallowize'_expn[nu_exps]:\n  \"(h, s) \\<in> Shallowize' M \\<longleftrightarrow> (h, stack_deepize s) \\<in> M\"\n  unfolding Shallowize'_def by simp\n\nlemma Shallowize'_Deepize'[simp]: \"Shallowize' (Deepize' S) = S \"\n  unfolding Deepize'_def Shallowize'_def by (simp add: image_iff pair_exists Bex_def set_eq_iff)\n\nlemma Deepize'_Deepize'[simp]: \"Deepize' S = S\" for S :: \"assn\"\n  unfolding set_eq_iff pair_forall Deepize'_expn by simp\n\nlemma Deepize'_inj[simp]:\n  \"Deepize' A = Deepize' B \\<longleftrightarrow> A = B\"\n  unfolding set_eq_iff Deepize'_expn pair_forall by force\n\nsubsubsection \\<open>Stack Element and Heap Object\\<close>\n\nconsts Ele :: \" 'a set \\<Rightarrow> assn \" (\"ELE _\" [17] 16)\ntranslations \"ELE x \\<tycolon> T\" \\<rightleftharpoons> \"ELE \\<tort_lbrace>x \\<tycolon> T\\<tort_rbrace>\"\n\ndefinition Val_Ele :: \" 'a::lrep set \\<Rightarrow> assn \" (\"VAL _\" [17] 16) where\n  \"(VAL T) = { (Map.empty, stack [v]) | v. v \\<in> deepize ` T } \"\n\nadhoc_overloading Ele Val_Ele\ntranslations \"VAL x \\<tycolon> T\" => \"VAL \\<tort_lbrace>x \\<tycolon> T\\<tort_rbrace>\"\n\nlemma [nu_exps]:\n  \"(h,s) \\<in> (VAL V) \\<longleftrightarrow> h = Map.empty \\<and> (\\<exists>v. s = stack [deepize v] \\<and> v \\<in> V)\"\n  unfolding Val_Ele_def by simp blast\n\nlemma [elim!,\\<nu>elim]: \"Inhabited (VAL T) \\<Longrightarrow> (Inhabited T \\<Longrightarrow> C) \\<Longrightarrow> C\"\n  unfolding Inhabited_def by (simp add: pair_exists nu_exps)\n\n\ndefinition Obj_Ele :: \" heap set \\<Rightarrow> assn \" (\"OBJ _\" [17] 16) where\n  \"(OBJ T) = { (h, stack []) | h. h \\<in> T } \"\n\nadhoc_overloading Ele Obj_Ele\ntranslations \"OBJ x \\<tycolon> T\" => \"OBJ \\<tort_lbrace>x \\<tycolon> T\\<tort_rbrace>\"\n\nlemma [nu_exps]: \"(h, s) \\<in> (OBJ T) \\<longleftrightarrow> s = stack [] \\<and> h \\<in> T\"\n  unfolding Obj_Ele_def by simp\n\nlemma [nu_exps]: \"(h, s) \\<in> Shallowize' (OBJ T) \\<longleftrightarrow> s = stack [] \\<and> h \\<in> T\"\n  unfolding Obj_Ele_def Shallowize'_expn by simp\n\nlemma [elim!,\\<nu>elim]: \"Inhabited (OBJ T) \\<Longrightarrow> (Inhabited T \\<Longrightarrow> C) \\<Longrightarrow> C\"\n  unfolding Inhabited_def by (simp add: pair_exists nu_exps)\n\n\nsubsubsection \\<open>Separation\\<close>\n\ndefinition disjoint :: \" 'a set \\<Rightarrow> 'a set \\<Rightarrow> bool \" (infixl \"\\<perpendicular>\" 60) where \"disjoint A B \\<longleftrightarrow> (A \\<inter> B = {})\"\nlemma disjoint_rewL: \"A \\<perpendicular> B \\<longleftrightarrow> (\\<forall>x. x \\<in> A \\<longrightarrow> x \\<notin> B)\" unfolding disjoint_def by auto\nlemma disjoint_rewR: \"A \\<perpendicular> B \\<longleftrightarrow> (\\<forall>x. x \\<in> B \\<longrightarrow> x \\<notin> A)\" unfolding disjoint_def by auto\nlemma [elim]: \"A \\<perpendicular> B \\<Longrightarrow> ((\\<And>x. x \\<in> A \\<Longrightarrow> x \\<in> B \\<Longrightarrow> False) \\<Longrightarrow> C) \\<Longrightarrow> C\" unfolding disjoint_def by auto\n\nlemma disjoint_empty [iff]: \"{} \\<perpendicular> S\"  \"S \\<perpendicular> {}\" unfolding disjoint_def by auto\n\ndefinition Separation :: \"assn \\<Rightarrow> assn \\<Rightarrow> assn\" ( \"_/ \\<heavy_asterisk> _\" [13,14] 13)\n  where \"(T \\<heavy_asterisk> U) = {(h,s). (\\<exists>h1 h2 s1 s2. h = h1 ++ h2 \\<and> dom h1 \\<perpendicular> dom h2 \\<and> s = s1 @\\<^sub>s\\<^sub>k s2 \\<and> (h2,s2) \\<in> T \\<and> (h1,s1) \\<in> U) }\"\n\ntranslations\n  \"x \\<tycolon> T \\<heavy_asterisk> U\" \\<rightleftharpoons> \"CONST Ele \\<tort_lbrace>x \\<tycolon> T\\<tort_rbrace> \\<heavy_asterisk> U\"\n  \"T \\<heavy_asterisk> y \\<tycolon> U\" \\<rightleftharpoons> \"T \\<heavy_asterisk> CONST Ele \\<tort_lbrace>y \\<tycolon> U\\<tort_rbrace>\"\n\nlemma Separation_expn:\n  \"(h,s) \\<in> (T \\<heavy_asterisk> U) \\<longleftrightarrow> (\\<exists>h1 h2 s1 s2. h = h1 ++ h2 \\<and> dom h1 \\<perpendicular> dom h2 \\<and> s = s1 @\\<^sub>s\\<^sub>k s2 \\<and> (h2,s2) \\<in> T \\<and> (h1,s1) \\<in> U)\"\n  unfolding Separation_def by simp\n\nlemma Separation_expn_R:\n  \"(h,s) \\<in> (T \\<heavy_asterisk> U) \\<longleftrightarrow> (\\<exists>h1 h2 s1 s2. h = h1 ++ h2 \\<and> dom h1 \\<perpendicular> dom h2 \\<and> s = s1 @\\<^sub>s\\<^sub>k s2 \\<and> (h1,s2) \\<in> T \\<and> (h2,s1) \\<in> U)\"\n  unfolding Separation_def\n  by simp (metis disjoint_def disjoint_rewR map_add_comm) \n\nlemma Separation_expn_V[nu_exps]:\n  \"(h, stack (deepize v # r)) \\<in> (R \\<heavy_asterisk> VAL V) \\<longleftrightarrow> ((h, stack r) \\<in> R \\<and> v \\<in> V )\"\n  unfolding Separation_def Shallowize'_expn\n  by (simp add: nu_exps) force\n\nlemma Separation_expn_V':\n  \"(h, s) \\<in> (R \\<heavy_asterisk> VAL V) \\<longleftrightarrow> (\\<exists>v r. s = stack (deepize v # r) \\<and> (h, stack r) \\<in> R \\<and> v \\<in> V )\"\n  unfolding Separation_def Shallowize'_expn\n  by (simp add: nu_exps) force\n\nlemma Separation_expn_O[nu_exps]:\n  \"(h,s) \\<in> (R \\<heavy_asterisk> OBJ H) \\<longleftrightarrow>\n  (\\<exists>h1 h2. h = h1 ++ h2 \\<and> dom h1 \\<perpendicular> dom h2 \\<and> (h2,s) \\<in> Shallowize' R \\<and> h1 \\<in> H )\"\n  unfolding Separation_def Shallowize'_expn\n  by (simp add: nu_exps)\n\nlemma Separation_expn_O_R:\n  \"(h,s) \\<in> (R \\<heavy_asterisk> OBJ H) \\<longleftrightarrow>\n  (\\<exists>h1 h2. h = h1 ++ h2 \\<and> dom h1 \\<perpendicular> dom h2 \\<and> (h1,s) \\<in> Shallowize' R \\<and> h2 \\<in> H )\"\n  unfolding Separation_def Shallowize'_expn\n  by (simp add: nu_exps) (metis disjoint_def disjoint_rewR map_add_comm)\n\nlemma [elim!,\\<nu>elim]: \"Inhabited (T \\<heavy_asterisk> U) \\<Longrightarrow> (Inhabited T \\<Longrightarrow> Inhabited U \\<Longrightarrow> C) \\<Longrightarrow> C\"\n  unfolding Inhabited_def by (simp add: pair_exists nu_exps Separation_expn) blast\n\n\nlemma Separation_assoc[simp]: \"(A \\<heavy_asterisk> (B \\<heavy_asterisk> C)) = (A \\<heavy_asterisk> B \\<heavy_asterisk> C)\"\n  unfolding Separation_def set_eq_iff pair_forall\n  apply auto subgoal for h2 s2 h1a h2a s1a s2a\n    apply (rule exI [where x = \"h1a\"], rule exI [where x = \"h2a ++ h2\"],\n          simp add: disjoint_def inf_sup_distrib1 inf_sup_distrib2)\n    apply (rule exI [of _ s1a], rule exI [of _ \"s2a @\\<^sub>s\\<^sub>k s2\"], simp)\n    apply blast done\n  subgoal for h1 s1 h1a h2a s1a s2a\n    apply (rule exI [where x = \"h1 ++ h1a\"], rule exI [where x = \"h2a\"],\n          simp add: disjoint_def inf_sup_distrib1 inf_sup_distrib2)\n    apply (rule exI [of _ \"s1 @\\<^sub>s\\<^sub>k s1a\"], simp, blast)\n    done\n  done\n\nlemma Separation_comm:\n  \" (OBJ A \\<heavy_asterisk> B) = (B \\<heavy_asterisk> OBJ A) \"\n  \" (A' \\<heavy_asterisk> OBJ B') = (OBJ B' \\<heavy_asterisk> A') \"\n  unfolding Separation_def set_eq_iff pair_forall\n  by (simp_all add: disjoint_def nu_exps) (blast dest: map_add_comm)+\n\nlemma shallowize_ex: \"(\\<exists>x::('c::lrep). P x) \\<longleftrightarrow> (\\<exists>x. P (shallowize x))\"\n  using deepize_inj by metis\nlemma shallowize_ex': \"TERM TYPE('c) \\<Longrightarrow> (\\<exists>x::('c::lrep). P x) \\<longleftrightarrow> (\\<exists>x. P (shallowize x))\"\n  using shallowize_ex .\n\nlemma shallowize_all: \"(\\<forall>x::('c::lrep). P x) \\<longleftrightarrow> (\\<forall>x. P (shallowize x))\"\n  using deepize_inj by metis\nlemma shallowize_all': \"TERM TYPE('c) \\<Longrightarrow> (\\<forall>x::('c::lrep). P x) \\<longleftrightarrow> (\\<forall>x. P (shallowize x))\"\n  using shallowize_all .\n\n\nlemma Separation_E[elim]:\n  \"(h,s) \\<in> (T \\<heavy_asterisk> U) \\<Longrightarrow> (\\<And>h1 h2 s1 s2. h = h1 ++ h2 \\<Longrightarrow> dom h1 \\<perpendicular> dom h2 \\<Longrightarrow> s = s1 @\\<^sub>s\\<^sub>k s2\n      \\<Longrightarrow> (h2,s2) \\<in> T \\<Longrightarrow> (h1,s1) \\<in> U \\<Longrightarrow> C) \\<Longrightarrow> C \"\n  unfolding Separation_expn by simp blast\n\nlemma Separation_I[intro]:\n  \"(h2,s2) \\<in> T \\<Longrightarrow> (h1,s1) \\<in> U \\<Longrightarrow> dom h1 \\<perpendicular> dom h2 \\<Longrightarrow> s = s1 @\\<^sub>s\\<^sub>k s2 \\<Longrightarrow> (h1 ++ h2, s) \\<in> (T \\<heavy_asterisk> U)\"\n  unfolding Separation_expn by simp blast\n\nsubsubsection \\<open>Set style Heap predication\\<close>\n\ndefinition Heap' :: \"(heap \\<times> 's::stack) set \\<Rightarrow> (heap \\<times> 's::stack) set\"\n  where \"Heap' T = {(h,s). Heap h \\<and> (h,s) \\<in> T}\"\n\nlemma Heap'_expn[simp,\\<nu>def]: \"(h,s) \\<in> Heap' T \\<longleftrightarrow> Heap h \\<and> (h,s) \\<in> T\"\n  unfolding Heap'_def by simp\n\nsubsubsection \\<open>\\<nu>-Procedure\\<close>\n\ntext \\<open>An assertion identical to Hoare triple, in the language of \\<nu>-type. \n  \\<^const>\\<open>Heap'\\<close> and \\<^const>\\<open>Shallowize'\\<close> are auxiliary usage.\\<close>\n\ndefinition Procedure :: \"('c::stack \\<longmapsto> 'd::stack) \\<Rightarrow> assn \\<Rightarrow> assn \\<Rightarrow> bool\" (\"(2\\<^bold>p\\<^bold>r\\<^bold>o\\<^bold>c _/ \\<blangle>(2 _/  \\<longmapsto>  _ )\\<brangle>)\" [101,2,2] 100)\n  where [\\<nu>def]:\"Procedure f T U \\<longleftrightarrow>\n      (\\<forall>a M::assn. a \\<in> Heap' (Shallowize' (M \\<heavy_asterisk> T)) \\<longrightarrow> f a \\<in> \\<S> Heap' (Shallowize' (M \\<heavy_asterisk> U)))\"\n\n\ntranslations\n  \"\\<^bold>p\\<^bold>r\\<^bold>o\\<^bold>c f \\<blangle> a \\<tycolon> A \\<longmapsto> B \\<brangle>\" \\<rightleftharpoons> \"\\<^bold>p\\<^bold>r\\<^bold>o\\<^bold>c f \\<blangle> CONST Ele \\<tort_lbrace> a \\<tycolon> A \\<tort_rbrace> \\<longmapsto> B \\<brangle>\"\n  \"\\<^bold>p\\<^bold>r\\<^bold>o\\<^bold>c f \\<blangle> A \\<longmapsto> b \\<tycolon> B \\<brangle>\" \\<rightleftharpoons> \"\\<^bold>p\\<^bold>r\\<^bold>o\\<^bold>c f \\<blangle> A \\<longmapsto> CONST Ele \\<tort_lbrace> b \\<tycolon> B \\<tort_rbrace> \\<brangle>\"\n\ndefinition Map :: \" 'a set \\<Rightarrow> 'b set \\<Rightarrow> ('a \\<Rightarrow> 'b) set \" where \"Map A B = {f. \\<forall>a. a \\<in> A \\<longrightarrow> f a \\<in> B }\"\ndefinition Map' :: \"('a \\<Rightarrow> 'b) \\<Rightarrow> 'a set \\<Rightarrow> 'b set \\<Rightarrow> bool\" (\"(2\\<^bold>m\\<^bold>a\\<^bold>p _/ \\<blangle>(2 _/ \\<longmapsto> _ )\\<brangle>)\" [101,2,2] 100)\n  where [\\<nu>def]: \"\\<^bold>m\\<^bold>a\\<^bold>p f \\<blangle> T \\<longmapsto> U \\<brangle> \\<equiv> \\<forall>a. a \\<in> T \\<longrightarrow> f a \\<in> U\"\n\n\nsubsection \\<open>Primitive operations and instructions required in the system\\<close>\n\nsubsubsection \\<open>Elementary instructions\\<close>\n\ndefinition bind :: \" ('a::lrep) state \\<Rightarrow> ( 'a \\<longmapsto> 'b) \\<Rightarrow> ('b::lrep) state \" \\<comment>\\<open>monadic bind\\<close>\n  where \"bind s f = (case s of Success x \\<Rightarrow> f x | Fail \\<Rightarrow> Fail | PartialCorrect \\<Rightarrow> PartialCorrect)\"\ndefinition instr_comp :: \"(('a::lrep) \\<longmapsto> ('b::lrep)) \\<Rightarrow> ( 'b \\<longmapsto> ('c::lrep)) \\<Rightarrow> 'a \\<longmapsto> 'c\"  (\"_ \\<then>/ _\" [75,76] 75) \n  where \"instr_comp f g s = bind (f s) g\"\ndefinition nop :: \" ('a::lrep) \\<longmapsto> 'a\" where \"nop = Success\" \\<comment>\\<open>the instruction `no-operation`\\<close>\n\nlemma nop_\\<nu>app: \"\\<^bold>p\\<^bold>r\\<^bold>o\\<^bold>c nop \\<blangle> T \\<longmapsto> T \\<brangle>\" unfolding nop_def Procedure_def by auto\nlemma instr_comp[intro]: \"\\<^bold>p\\<^bold>r\\<^bold>o\\<^bold>c f \\<blangle> A \\<longmapsto> B \\<brangle> \\<Longrightarrow> \\<^bold>p\\<^bold>r\\<^bold>o\\<^bold>c g \\<blangle> B \\<longmapsto> C \\<brangle> \\<Longrightarrow> \\<^bold>p\\<^bold>r\\<^bold>o\\<^bold>c (f \\<then> g) \\<blangle> A \\<longmapsto> C \\<brangle>\"\n  unfolding instr_comp_def Procedure_def bind_def by (auto 0 4)\n\n\nsubsection \\<open>Top-level Construction Structures\\<close>\n\nsubsubsection \\<open>Construction Context & Code block\\<close>\n\ndefinition CurrentConstruction :: \" ('a::stack) state \\<Rightarrow> assn \\<Rightarrow> assn \\<Rightarrow> bool \"\n    (\"\\<^bold>c\\<^bold>u\\<^bold>r\\<^bold>r\\<^bold>e\\<^bold>n\\<^bold>t _ [_] \\<^bold>r\\<^bold>e\\<^bold>s\\<^bold>u\\<^bold>l\\<^bold>t\\<^bold>s \\<^bold>i\\<^bold>n/ _\" [1000,1000,11] 10)\n  where \"CurrentConstruction s R S \\<longleftrightarrow> s \\<in> !\\<S> Heap' (Shallowize' (R \\<heavy_asterisk> S))\"\ndefinition PendingConstruction :: \" (('a::stack) \\<longmapsto> ('b::stack)) \\<Rightarrow> 'a state \\<Rightarrow> assn \\<Rightarrow> assn \\<Rightarrow> bool \"\n    (\"\\<^bold>p\\<^bold>e\\<^bold>n\\<^bold>d\\<^bold>i\\<^bold>n\\<^bold>g _ \\<^bold>o\\<^bold>n _ [_] \\<^bold>r\\<^bold>e\\<^bold>s\\<^bold>u\\<^bold>l\\<^bold>t\\<^bold>s \\<^bold>i\\<^bold>n/ _\" [1000,1000,1000,5] 4)\n  where \"PendingConstruction f s R S \\<longleftrightarrow> bind s f \\<in> \\<S> Heap' (Shallowize' (R \\<heavy_asterisk> S))\"\ntranslations\n  \"\\<^bold>c\\<^bold>u\\<^bold>r\\<^bold>r\\<^bold>e\\<^bold>n\\<^bold>t blk [H] \\<^bold>r\\<^bold>e\\<^bold>s\\<^bold>u\\<^bold>l\\<^bold>t\\<^bold>s \\<^bold>i\\<^bold>n (x \\<tycolon> T)\" \\<rightleftharpoons> \"\\<^bold>c\\<^bold>u\\<^bold>r\\<^bold>r\\<^bold>e\\<^bold>n\\<^bold>t blk [H] \\<^bold>r\\<^bold>e\\<^bold>s\\<^bold>u\\<^bold>l\\<^bold>t\\<^bold>s \\<^bold>i\\<^bold>n CONST Ele \\<tort_lbrace> x \\<tycolon> T \\<tort_rbrace>\"\n  \"CONST PendingConstruction f s H (x \\<tycolon> T)\" \\<rightleftharpoons> \"CONST PendingConstruction f s H (CONST Ele \\<tort_lbrace> x \\<tycolon> T\\<tort_rbrace>)\"\n\nlemma CurrentConstruction_D: \"CurrentConstruction s H T \\<Longrightarrow> Inhabited T\"\n  unfolding CurrentConstruction_def Inhabited_def by (cases s) (auto 0 4 simp add: Shallowize'_expn)\n\n\ndefinition CodeBlock :: \" ('a::lrep) state \\<Rightarrow> ('b::lrep) state => ('b \\<longmapsto> 'a) \\<Rightarrow> bool\" where\n  CodeBlock_def: \"CodeBlock stat arg prog \\<longleftrightarrow> (bind arg prog = stat \\<and> stat \\<noteq> PartialCorrect)\"\nsyntax \"_codeblock_exp_\" :: \"idt \\<Rightarrow> logic \\<Rightarrow> logic \\<Rightarrow> bool\"  (\"(2\\<^bold>c\\<^bold>o\\<^bold>d\\<^bold>e\\<^bold>b\\<^bold>l\\<^bold>o\\<^bold>c\\<^bold>k _/  \\<^bold>a\\<^bold>s '\\<open>_'\\<close>/ \\<^bold>f\\<^bold>o\\<^bold>r \\<^bold>a\\<^bold>r\\<^bold>g\\<^bold>u\\<^bold>m\\<^bold>e\\<^bold>n\\<^bold>t\\<^bold>s '\\<open>_'\\<close>)\" [100,0,0] 3)\nsyntax \"_codeblock_\" :: \"idt \\<Rightarrow> logic \\<Rightarrow> bool\" (\"\\<^bold>c\\<^bold>o\\<^bold>d\\<^bold>e\\<^bold>b\\<^bold>l\\<^bold>o\\<^bold>c\\<^bold>k _ \\<^bold>f\\<^bold>o\\<^bold>r \\<^bold>a\\<^bold>r\\<^bold>g\\<^bold>u\\<^bold>m\\<^bold>e\\<^bold>n\\<^bold>t\\<^bold>s '\\<open>_'\\<close>\" [100,0] 3)\n\n\nsection \\<open>Rules for the construction\\<close>\n\nlemma frame: \"\\<^bold>p\\<^bold>r\\<^bold>o\\<^bold>c f \\<blangle> A \\<longmapsto> B \\<brangle> \\<Longrightarrow> \\<^bold>p\\<^bold>r\\<^bold>o\\<^bold>c f \\<blangle> M \\<heavy_asterisk> A \\<longmapsto> M \\<heavy_asterisk> B \\<brangle>\"\n  unfolding Procedure_def by simp\n\nlemma apply_proc: \"(\\<^bold>c\\<^bold>u\\<^bold>r\\<^bold>r\\<^bold>e\\<^bold>n\\<^bold>t blk [H] \\<^bold>r\\<^bold>e\\<^bold>s\\<^bold>u\\<^bold>l\\<^bold>t\\<^bold>s \\<^bold>i\\<^bold>n S) \\<Longrightarrow> \\<^bold>p\\<^bold>r\\<^bold>o\\<^bold>c f \\<blangle> S \\<longmapsto> T \\<brangle> \\<Longrightarrow> (\\<^bold>p\\<^bold>e\\<^bold>n\\<^bold>d\\<^bold>i\\<^bold>n\\<^bold>g f \\<^bold>o\\<^bold>n blk [H] \\<^bold>r\\<^bold>e\\<^bold>s\\<^bold>u\\<^bold>l\\<^bold>t\\<^bold>s \\<^bold>i\\<^bold>n T)\"\n  unfolding Procedure_def CurrentConstruction_def PendingConstruction_def bind_def by (auto 0 5)\n\nlemma accept_proc: \"\\<^bold>p\\<^bold>e\\<^bold>n\\<^bold>d\\<^bold>i\\<^bold>n\\<^bold>g f \\<^bold>o\\<^bold>n s [H] \\<^bold>r\\<^bold>e\\<^bold>s\\<^bold>u\\<^bold>l\\<^bold>t\\<^bold>s \\<^bold>i\\<^bold>n T \\<Longrightarrow> CodeBlock s' s f \\<Longrightarrow> \\<^bold>c\\<^bold>u\\<^bold>r\\<^bold>r\\<^bold>e\\<^bold>n\\<^bold>t s' [H] \\<^bold>r\\<^bold>e\\<^bold>s\\<^bold>u\\<^bold>l\\<^bold>t\\<^bold>s \\<^bold>i\\<^bold>n T\"\n  for s' :: \"('b::stack) state\"\n  unfolding CurrentConstruction_def PendingConstruction_def CodeBlock_def\n  by (simp add: LooseStateTy_upgrade)\n\nlemma reassemble_proc_0:\n  \"\\<^bold>c\\<^bold>u\\<^bold>r\\<^bold>r\\<^bold>e\\<^bold>n\\<^bold>t s [H] \\<^bold>r\\<^bold>e\\<^bold>s\\<^bold>u\\<^bold>l\\<^bold>t\\<^bold>s \\<^bold>i\\<^bold>n T \\<Longrightarrow> \\<^bold>p\\<^bold>e\\<^bold>n\\<^bold>d\\<^bold>i\\<^bold>n\\<^bold>g nop \\<^bold>o\\<^bold>n s [H] \\<^bold>r\\<^bold>e\\<^bold>s\\<^bold>u\\<^bold>l\\<^bold>t\\<^bold>s \\<^bold>i\\<^bold>n T\"\n  unfolding CurrentConstruction_def PendingConstruction_def CodeBlock_def nop_def bind_def by (cases s) simp+\n\nlemma reassemble_proc:\n  \"(\\<And>s'. CodeBlock s' s f \\<Longrightarrow> \\<^bold>p\\<^bold>e\\<^bold>n\\<^bold>d\\<^bold>i\\<^bold>n\\<^bold>g g \\<^bold>o\\<^bold>n s' [H] \\<^bold>r\\<^bold>e\\<^bold>s\\<^bold>u\\<^bold>l\\<^bold>t\\<^bold>s \\<^bold>i\\<^bold>n T) \\<Longrightarrow> \\<^bold>p\\<^bold>e\\<^bold>n\\<^bold>d\\<^bold>i\\<^bold>n\\<^bold>g (f \\<then> g) \\<^bold>o\\<^bold>n s [H] \\<^bold>r\\<^bold>e\\<^bold>s\\<^bold>u\\<^bold>l\\<^bold>t\\<^bold>s \\<^bold>i\\<^bold>n T\"\n  unfolding CurrentConstruction_def PendingConstruction_def CodeBlock_def bind_def instr_comp_def\n  by force\n\nlemma reassemble_proc_final:\n  \"(\\<And>s H. \\<^bold>c\\<^bold>u\\<^bold>r\\<^bold>r\\<^bold>e\\<^bold>n\\<^bold>t s [H] \\<^bold>r\\<^bold>e\\<^bold>s\\<^bold>u\\<^bold>l\\<^bold>t\\<^bold>s \\<^bold>i\\<^bold>n S \\<Longrightarrow> \\<^bold>p\\<^bold>e\\<^bold>n\\<^bold>d\\<^bold>i\\<^bold>n\\<^bold>g g \\<^bold>o\\<^bold>n s [H] \\<^bold>r\\<^bold>e\\<^bold>s\\<^bold>u\\<^bold>l\\<^bold>t\\<^bold>s \\<^bold>i\\<^bold>n T) \\<Longrightarrow> \\<^bold>p\\<^bold>r\\<^bold>o\\<^bold>c g \\<blangle> S \\<longmapsto> T \\<brangle>\"\n  unfolding CurrentConstruction_def PendingConstruction_def Procedure_def bind_def pair_All\n  by (metis StrictStateTy_intro state.simps(8))\n\nlemma rename_proc: \"f \\<equiv> f' \\<Longrightarrow> \\<^bold>p\\<^bold>r\\<^bold>o\\<^bold>c f' \\<blangle> U \\<longmapsto> \\<R> \\<brangle> \\<Longrightarrow> \\<^bold>p\\<^bold>r\\<^bold>o\\<^bold>c f \\<blangle> U \\<longmapsto> \\<R> \\<brangle>\" by fast\n\nend\n", "meta": {"author": "nusystem", "repo": "nu-system", "sha": "148c5a354ad8780cc4da9b91e1291414c91b2eda", "save_path": "github-repos/isabelle/nusystem-nu-system", "path": "github-repos/isabelle/nusystem-nu-system/nu-system-148c5a354ad8780cc4da9b91e1291414c91b2eda/NuPrime.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6654105587468141, "lm_q2_score": 0.3998116407397951, "lm_q1q2_score": 0.26603888725814756}}
{"text": "(* \n   Title: Psi-calculi   \n   Author/Maintainer: Jesper Bengtson (jebe@itu.dk), 2012\n*)\ntheory Weaken_Bisimulation\n  imports Weaken_Simulation Weaken_Stat_Imp\nbegin\n\ncontext weak\nbegin\n\nlemma weakenMonoCoinduct: \"\\<And>x y xa xb xc P Q \\<Psi>.\n                      x \\<le> y \\<Longrightarrow>\n                      (\\<Psi> \\<rhd> Q \\<leadsto>\\<^sub>w<{(xc, xb, xa). x xc xb xa}> P) \\<longrightarrow>\n                     (\\<Psi> \\<rhd> Q \\<leadsto>\\<^sub>w<{(xb, xa, xc). y xb xa xc}> P)\"\napply auto\napply(rule weakenSimMonotonic)\nby(auto dest: le_funE)\n\nlemma weakenMonoCoinduct2: \"\\<And>x y xa xb xc P Q \\<Psi>.\n                      x \\<le> y \\<Longrightarrow>\n                      (\\<Psi> \\<rhd> Q \\<lessapprox>\\<^sub>w<{(xc, xb, xa). x xc xb xa}> P) \\<longrightarrow>\n                     (\\<Psi> \\<rhd> Q \\<lessapprox>\\<^sub>w<{(xb, xa, xc). y xb xa xc}> P)\"\napply auto\napply(rule weakenStatImpMonotonic)\nby(auto dest: le_funE)\n\ncoinductive_set weakenBisim :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\" \nwhere\n  step: \"\\<lbrakk>\\<Psi> \\<rhd> P \\<lessapprox>\\<^sub>w<weakenBisim> Q; \\<Psi> \\<rhd> P \\<leadsto>\\<^sub>w<weakenBisim> Q;\n          \\<forall>\\<Psi>'. (\\<Psi> \\<otimes> \\<Psi>',  P, Q) \\<in> weakenBisim; (\\<Psi>, Q, P) \\<in> weakenBisim\\<rbrakk> \\<Longrightarrow> (\\<Psi>, P, Q) \\<in> weakenBisim\"\nmonos weakenMonoCoinduct weakenMonoCoinduct2\n\nabbreviation\n  weakenBisimJudge (\"_ \\<rhd> _ \\<approx>\\<^sub>w _\" [70, 70, 70] 65) where \"\\<Psi> \\<rhd> P \\<approx>\\<^sub>w Q \\<equiv> (\\<Psi>, P, Q) \\<in> weakenBisim\"\nabbreviation\n  weakenBisimNilJudge (\"_ \\<approx>\\<^sub>w _\" [70, 70] 65) where \"P \\<approx>\\<^sub>w Q \\<equiv> \\<one> \\<rhd> P \\<approx>\\<^sub>w Q\"\n\nlemma weakenBisimCoinductAux[consumes 1]:\n  fixes F :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   X :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n\n  assumes \"(\\<Psi>, P, Q) \\<in> X\"\n  and     \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> (\\<Psi> \\<rhd> P \\<lessapprox>\\<^sub>w<(X \\<union> weakenBisim)> Q) \\<and>\n                                    (\\<Psi> \\<rhd> P \\<leadsto>\\<^sub>w<(X \\<union> weakenBisim)> Q) \\<and>\n                                    (\\<forall>\\<Psi>'. (\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> X \\<or> (\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> weakenBisim) \\<and>\n                                    ((\\<Psi>, Q, P) \\<in> X \\<or> (\\<Psi>, Q, P) \\<in> weakenBisim)\"\n\n  shows \"(\\<Psi>, P, Q) \\<in> weakenBisim\"\nproof -\n  have \"X \\<union> weakenBisim = {(\\<Psi>, P, Q). (\\<Psi>, P, Q) \\<in> X \\<or> (\\<Psi>, P, Q) \\<in> weakenBisim}\" by auto\n  with assms show ?thesis\n    by coinduct (simp add: rtrancl_def)\nqed\n\nlemma weakenBisimCoinduct[consumes 1, case_names cStatImp cSim cExt cSym]:\n  fixes F :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   X :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n\n  assumes \"(\\<Psi>, P, Q) \\<in> X\"\n  and     \"\\<And>\\<Psi>' R S. (\\<Psi>', R, S) \\<in> X \\<Longrightarrow> \\<Psi>' \\<rhd> R \\<lessapprox>\\<^sub>w<(X \\<union> weakenBisim)> S\"\n  and     \"\\<And>\\<Psi>' R S. (\\<Psi>', R, S) \\<in> X \\<Longrightarrow> \\<Psi>' \\<rhd> R \\<leadsto>\\<^sub>w<(X \\<union> weakenBisim)> S\"\n  and     \"\\<And>\\<Psi>' R S \\<Psi>''. (\\<Psi>', R, S) \\<in> X \\<Longrightarrow> (\\<Psi>' \\<otimes> \\<Psi>'', R, S) \\<in> X \\<or> \\<Psi>' \\<otimes> \\<Psi>'' \\<rhd> R \\<approx>\\<^sub>w S\"\n  and     \"\\<And>\\<Psi>' R S. (\\<Psi>', R, S) \\<in> X \\<Longrightarrow> (\\<Psi>', S, R) \\<in> X \\<or> \\<Psi>' \\<rhd> S \\<approx>\\<^sub>w R\"\n\n  shows \"\\<Psi> \\<rhd> P \\<approx>\\<^sub>w Q\"\nproof -\n  have \"X \\<union> weakenBisim = {(\\<Psi>, P, Q). (\\<Psi>, P, Q) \\<in> X \\<or> (\\<Psi>, P, Q) \\<in> weakenBisim}\" by auto\n  with assms show ?thesis\n    by coinduct (simp add: rtrancl_def)\nqed\n\nlemma weakenBisimWeakCoinductAux[consumes 1]:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   X :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n\n  assumes \"(\\<Psi>, P, Q) \\<in> X\"\n  and     \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> \\<Psi> \\<rhd> P \\<lessapprox>\\<^sub>w<X> Q \\<and>\n                                     \\<Psi> \\<rhd> P \\<leadsto>\\<^sub>w<X> Q \\<and> (\\<forall>\\<Psi>'. (\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> X) \\<and> \n                                    (\\<Psi>, Q, P) \\<in> X\" \n\n  shows \"\\<Psi> \\<rhd> P \\<approx>\\<^sub>w Q\"\nusing assms\nby(coinduct rule: weakenBisimCoinductAux) (blast intro: weakenSimMonotonic weakenStatImpMonotonic)\n\nlemma weakenBisimE:\n  fixes P  :: \"('a, 'b, 'c) psi\"\n  and   Q  :: \"('a, 'b, 'c) psi\"\n  and   \\<Psi>  :: 'b\n  and   \\<Psi>' :: 'b\n\n  assumes \"\\<Psi> \\<rhd> P \\<approx>\\<^sub>w Q\"\n\n  shows \"\\<Psi> \\<rhd> P \\<lessapprox>\\<^sub>w<weakenBisim> Q\"\n  and   \"\\<Psi> \\<rhd> P \\<leadsto>\\<^sub>w<weakenBisim> Q\"\n  and   \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<approx>\\<^sub>w Q\"\n  and   \"\\<Psi> \\<rhd> Q \\<approx>\\<^sub>w P\"\nusing assms\nby(auto intro: weakenBisim.cases simp add: rtrancl_def)\n\nlemma weakenBisimWeakCoinduct[consumes 1, case_names cStatImp cSim cExt cSym]:\n  fixes F :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   X :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n\n  assumes \"(\\<Psi>, P, Q) \\<in> X\"\n  and     \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> \\<Psi> \\<rhd> P \\<lessapprox>\\<^sub>w<X> Q\"\n  and     \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> \\<Psi> \\<rhd> P \\<leadsto>\\<^sub>w<X> Q\"\n  and     \"\\<And>\\<Psi> P Q \\<Psi>'. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> (\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> X\"\n  and     \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> (\\<Psi>, Q, P) \\<in> X\"\n\n  shows \"(\\<Psi>, P, Q) \\<in> weakenBisim\"\nproof -\n  have \"X \\<union> weakenBisim = {(\\<Psi>, P, Q). (\\<Psi>, P, Q) \\<in> X \\<or> (\\<Psi>, P, Q) \\<in> weakenBisim}\" by auto\n  with assms show ?thesis\n    by(coinduct rule: weakenBisimWeakCoinductAux) blast\nqed\n\nlemma weakenBisimEqWeakBisim[simp]: \"weakenBisim = weakBisim\"\nproof auto\n  fix \\<Psi> P Q\n  assume \"\\<Psi> \\<rhd> P \\<approx>\\<^sub>w Q\" thus \"\\<Psi> \\<rhd> P \\<approx> Q\"\n  proof(coinduct rule: weakBisimWeakCoinduct)\n    case(cStatImp \\<Psi> P Q)\n    from \\<open>\\<Psi> \\<rhd> P \\<approx>\\<^sub>w Q\\<close> have \"\\<Psi> \\<rhd> P \\<lessapprox>\\<^sub>w<weakenBisim> Q\" by(rule weakenBisimE)\n    thus ?case using weakenBisimE(3) by(rule weakenStatImpWeakStatImp)\n  next\n    case(cSim \\<Psi> P Q)\n    from \\<open>\\<Psi> \\<rhd> P \\<approx>\\<^sub>w Q\\<close> weakenBisimE\n    show ?case by(rule weakenSimWeakSim)\n  next\n    case(cExt \\<Psi> P Q \\<Psi>')\n    thus ?case by(rule weakenBisimE)\n  next\n    case(cSym \\<Psi> P Q)\n    thus ?case by(rule weakenBisimE)\n  qed\nnext\n  fix \\<Psi> P Q\n  assume \"\\<Psi> \\<rhd> P \\<approx> Q\" thus \"\\<Psi> \\<rhd> P \\<approx>\\<^sub>w Q\"\n  proof(coinduct rule: weakenBisimWeakCoinduct)\n    case(cStatImp \\<Psi> P Q)\n    from \\<open>\\<Psi> \\<rhd> P \\<approx> Q\\<close> have \"\\<Psi> \\<rhd> P \\<lessapprox><weakBisim> Q\" by(rule weakBisimE)\n    thus ?case using statEqWeakBisim by(rule weakStatImpWeakenStatImp)\n  next\n    case(cSim \\<Psi> P Q)\n    from \\<open>\\<Psi> \\<rhd> P \\<approx> Q\\<close> have \"\\<Psi> \\<rhd> P \\<leadsto><weakBisim> Q\" by(rule weakBisimE)\n    thus ?case using statEqWeakBisim by(rule weakSimWeakenSim)\n  next\n    case(cExt \\<Psi> P Q \\<Psi>')\n    thus ?case by(rule weakBisimE)\n  next\n    case(cSym \\<Psi> P Q)\n    thus ?case by(rule weakBisimE)\n  qed\nqed\n\nlemma weakenTransitiveWeakCoinduct[case_names cStatImp cSim cExt cSym, case_conclusion bisim step, consumes 2]:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   X :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n\n  assumes p: \"(\\<Psi>, P, Q) \\<in> X\"\n  and Eqvt: \"eqvt X\"\n  and rStatImp: \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> \\<Psi> \\<rhd> P \\<lessapprox>\\<^sub>w<X> Q\"\n  and rSim: \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> \\<Psi> \\<rhd> P \\<leadsto>\\<^sub>w<({(\\<Psi>, P, Q) | \\<Psi> P Q. \\<exists>P' Q'. \\<Psi> \\<rhd> P \\<sim> P' \\<and>\n                                                                        (\\<Psi>, P', Q') \\<in> X \\<and>\n                                                                        \\<Psi> \\<rhd> Q' \\<sim> Q})> Q\"\n  and rExt: \"\\<And>\\<Psi> P Q \\<Psi>'. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> (\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> X\"\n  and rSym: \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> (\\<Psi>, Q, P) \\<in> X\"\n\n  shows \"\\<Psi> \\<rhd> P \\<approx>\\<^sub>w Q\"\nproof -\n  from p \\<open>eqvt X\\<close> have \"\\<Psi> \\<rhd> P \\<approx> Q\"\n  proof(coinduct rule: weakTransitiveWeakCoinduct)\n    case(cStatImp \\<Psi> P Q)\n    from \\<open>(\\<Psi>, P, Q) \\<in> X\\<close> have \"\\<Psi> \\<rhd> P \\<lessapprox>\\<^sub>w<X> Q\" by(rule rStatImp)\n    thus ?case using rExt by(rule weakenStatImpWeakStatImp)\n  next\n    case(cSim \\<Psi> P Q)\n    let ?Y = \"{(\\<Psi>, P, Q) | \\<Psi> P Q. \\<exists>P' Q'. \\<Psi> \\<rhd> P \\<sim> P' \\<and> (\\<Psi>, P', Q') \\<in> X \\<and> \\<Psi> \\<rhd> Q' \\<sim> Q}\"\n    note \\<open>(\\<Psi>, P, Q) \\<in> X\\<close>\n    moreover note rStatImp rSim\n    moreover have \"\\<And>\\<Psi> P Q \\<Psi>'. (\\<Psi>, P, Q) \\<in> ?Y \\<Longrightarrow> (\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> ?Y\"\n      by(blast dest: bisimE rExt)\n    ultimately show ?case using rSym by(rule weakenSimWeakSim)\n  next\n    case(cExt \\<Psi> P Q \\<Psi>')\n    thus ?case by(rule rExt) \n  next\n    case(cSym \\<Psi> P Q)\n    thus ?case by(rule rSym)\n  qed\n  thus ?thesis by(simp add: weakenBisimEqWeakBisim)\nqed\n\nlemma weakenTransitiveCoinduct[case_names cStatImp cSim cExt cSym, case_conclusion bisim step, consumes 2]:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   X :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n\n  assumes p: \"(\\<Psi>, P, Q) \\<in> X\"\n  and Eqvt: \"eqvt X\"\n  and rStatImp: \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> \\<Psi> \\<rhd> P \\<lessapprox>\\<^sub>w<(X \\<union> weakenBisim)> Q\"\n  and rSim: \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> \\<Psi> \\<rhd> P \\<leadsto>\\<^sub>w<({(\\<Psi>, P, Q) | \\<Psi> P Q. \\<exists>P' Q'. \\<Psi> \\<rhd> P \\<sim> P' \\<and>\n                                                                        (\\<Psi>, P', Q') \\<in> (X \\<union> weakenBisim) \\<and>\n                                                                        \\<Psi> \\<rhd> Q' \\<sim> Q})> Q\"\n  and rExt: \"\\<And>\\<Psi> P Q \\<Psi>'. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> (\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> X \\<union> weakenBisim\"\n  and rSym: \"\\<And>\\<Psi> P Q. (\\<Psi>, P, Q) \\<in> X \\<Longrightarrow> (\\<Psi>, Q, P) \\<in> X \\<union> weakenBisim\"\n\n  shows \"\\<Psi> \\<rhd> P \\<approx>\\<^sub>w Q\"\nproof -\n  from p have \"(\\<Psi>, P, Q) \\<in> X \\<union> weakenBisim\" by auto\n  moreover from \\<open>eqvt X\\<close> have \"eqvt(X \\<union> weakenBisim)\" by auto\n  ultimately show ?thesis\n  proof(coinduct rule: weakenTransitiveWeakCoinduct)\n    case(cStatImp \\<Psi> P Q)\n    thus ?case by(fastforce intro: rStatImp weakenBisimE(1) weakenStatImpMonotonic)\n  next\n    case(cSim \\<Psi> P Q)\n    thus ?case by(fastforce intro: rSim weakenBisimE(2) weakenSimMonotonic bisimReflexive)\n  next\n    case(cExt \\<Psi> P Q \\<Psi>')\n    thus ?case by(blast dest: weakenBisimE rExt) \n  next\n    case(cSym \\<Psi> P Q)\n    thus ?case by(blast dest: weakenBisimE rSym)\n  qed\nqed\n\nend\n\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Psi_Calculi/Weaken_Bisimulation.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.519521321952093, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.2658476869407446}}
{"text": "section \\<open>Refinement to Efficient Code\\<close>\n(*\n  Author: Peter Lammich\n  Inspired by previous version of Alexander Schimpf.\n*)\ntheory LTL_to_GBA_impl\nimports \n  LTL_to_GBA\n  Deriving.Compare_Instances\n  CAVA_Automata.Automata_Impl\n  CAVA_Base.CAVA_Code_Target\nbegin\n\nsubsection \\<open>Parametricity Setup Boilerplate\\<close>\n\nsubsubsection \\<open>LTL Formulas\\<close>\n\nderive linorder ltlr\n\ninductive_set ltlr_rel for R where\n  \"(True_ltlr, True_ltlr) \\<in> ltlr_rel R\"\n| \"(False_ltlr, False_ltlr) \\<in> ltlr_rel R\"\n| \"(a,a')\\<in>R \\<Longrightarrow> (Prop_ltlr a,Prop_ltlr a') \\<in> ltlr_rel R\"\n| \"(a,a')\\<in>R \\<Longrightarrow> (Nprop_ltlr a,Nprop_ltlr a') \\<in> ltlr_rel R\"\n| \"\\<lbrakk>(a,a')\\<in>ltlr_rel R; (b,b')\\<in>ltlr_rel R\\<rbrakk> \n  \\<Longrightarrow> (And_ltlr a b,And_ltlr a' b') \\<in> ltlr_rel R\"\n| \"\\<lbrakk>(a,a')\\<in>ltlr_rel R; (b,b')\\<in>ltlr_rel R\\<rbrakk> \n  \\<Longrightarrow> (Or_ltlr a b,Or_ltlr a' b') \\<in> ltlr_rel R\"\n| \"\\<lbrakk>(a,a')\\<in>ltlr_rel R\\<rbrakk> \\<Longrightarrow> (Next_ltlr a,Next_ltlr a') \\<in> ltlr_rel R\"\n| \"\\<lbrakk>(a,a')\\<in>ltlr_rel R; (b,b')\\<in>ltlr_rel R\\<rbrakk> \n  \\<Longrightarrow> (Until_ltlr a b,Until_ltlr a' b') \\<in> ltlr_rel R\"\n| \"\\<lbrakk>(a,a')\\<in>ltlr_rel R; (b,b')\\<in>ltlr_rel R\\<rbrakk> \n  \\<Longrightarrow> (Release_ltlr a b,Release_ltlr a' b') \\<in> ltlr_rel R\"\n\nlemmas ltlr_rel_induct[induct set] \n  = ltlr_rel.induct[simplified relAPP_def[of ltlr_rel, symmetric]]\nlemmas ltlr_rel_cases[cases set] \n  = ltlr_rel.cases[simplified relAPP_def[of ltlr_rel, symmetric]]\nlemmas ltlr_rel_intros \n  = ltlr_rel.intros[simplified relAPP_def[of ltlr_rel, symmetric]]\n\ninductive_simps ltlr_rel_left_simps[simplified relAPP_def[of ltlr_rel, symmetric]]: \n  \"(True_ltlr,z) \\<in> ltlr_rel R\"\n  \"(False_ltlr,z) \\<in> ltlr_rel R\"\n  \"(Prop_ltlr p, z) \\<in> ltlr_rel R\"\n  \"(Nprop_ltlr p, z) \\<in> ltlr_rel R\"\n  \"(And_ltlr a b, z) \\<in> ltlr_rel R\"\n  \"(Or_ltlr a b, z) \\<in> ltlr_rel R\"\n  \"(Next_ltlr a, z) \\<in> ltlr_rel R\"\n  \"(Until_ltlr a b, z) \\<in> ltlr_rel R\"\n  \"(Release_ltlr a b, z) \\<in> ltlr_rel R\"\n\nlemma ltlr_rel_sv[relator_props]: \n  assumes SV: \"single_valued R\"  \n  shows \"single_valued (\\<langle>R\\<rangle>ltlr_rel)\"\nproof (intro single_valuedI allI impI)\n  fix x y z\n  assume \"(x, y) \\<in> \\<langle>R\\<rangle>ltlr_rel\" \"(x, z) \\<in> \\<langle>R\\<rangle>ltlr_rel\"\n  then show \"y=z\"\n    apply (induction arbitrary: z)\n    apply (simp (no_asm_use) only: ltlr_rel_left_simps \n      | blast intro: single_valuedD[OF SV])+\n    done\nqed\n\nlemma ltlr_rel_id[relator_props]: \"\\<lbrakk> R = Id \\<rbrakk> \\<Longrightarrow> \\<langle>R\\<rangle>ltlr_rel = Id\"\nproof (intro equalityI subsetI, clarsimp_all)\n  fix a b\n  assume \"(a,b)\\<in>\\<langle>Id\\<rangle>ltlr_rel\"\n  then show \"a=b\"\n    by induction auto\nnext\n  fix a\n  show \"(a,a)\\<in>\\<langle>Id\\<rangle>ltlr_rel\"\n    by (induction a) (auto intro: ltlr_rel_intros)\nqed\n\nlemma ltlr_rel_id_simp[simp]:  \"\\<langle>Id\\<rangle>ltlr_rel = Id\" by (rule ltlr_rel_id) simp\n\nconsts i_ltlr :: \"interface \\<Rightarrow> interface\"\nlemmas [autoref_rel_intf] = REL_INTFI[of ltlr_rel i_ltlr]\n\nthm ltlr_rel_intros[no_vars]\n\nlemma ltlr_con_param[param, autoref_rules]:\n  \"(True_ltlr, True_ltlr) \\<in> \\<langle>R\\<rangle>ltlr_rel\"\n  \"(False_ltlr, False_ltlr) \\<in> \\<langle>R\\<rangle>ltlr_rel\"\n  \"(Prop_ltlr, Prop_ltlr) \\<in> R \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel\"\n  \"(Nprop_ltlr, Nprop_ltlr) \\<in> R \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel\"\n  \"(And_ltlr, And_ltlr) \\<in> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel\"\n  \"(Or_ltlr, Or_ltlr) \\<in> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel\"\n  \"(Next_ltlr, Next_ltlr) \\<in> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel\"\n  \"(Until_ltlr, Until_ltlr) \\<in> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel\"\n  \"(Release_ltlr, Release_ltlr) \\<in> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel\"\n  by (auto intro: ltlr_rel_intros)\n\nlemma case_ltlr_param[param, autoref_rules]: \n  \"(case_ltlr,case_ltlr) \\<in> Rv \\<rightarrow> Rv \\<rightarrow> (R \\<rightarrow> Rv)\n                \\<rightarrow> (R \\<rightarrow> Rv)\n                  \\<rightarrow> (\\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> Rv)\n                    \\<rightarrow> (\\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> Rv)\n                      \\<rightarrow> (\\<langle>R\\<rangle>ltlr_rel \\<rightarrow> Rv)\n                        \\<rightarrow> (\\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> Rv)\n                          \\<rightarrow> (\\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> Rv) \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> Rv\"\n  apply (clarsimp)\n  apply (case_tac ai, simp_all add: ltlr_rel_left_simps)\n  apply (clarsimp_all)\n  apply parametricity+\n  done\n\nlemma rec_ltlr_param[param, autoref_rules]: \n  \"(rec_ltlr,rec_ltlr) \\<in> Rv \\<rightarrow> Rv \\<rightarrow> (R \\<rightarrow> Rv)\n                \\<rightarrow> (R \\<rightarrow> Rv)\n                  \\<rightarrow> (\\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> Rv \\<rightarrow> Rv \\<rightarrow> Rv)\n                    \\<rightarrow> (\\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> Rv \\<rightarrow> Rv \\<rightarrow> Rv)\n                      \\<rightarrow> (\\<langle>R\\<rangle>ltlr_rel \\<rightarrow> Rv \\<rightarrow> Rv)\n                        \\<rightarrow> (\\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> Rv \\<rightarrow> Rv \\<rightarrow> Rv)\n                          \\<rightarrow> (\\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> Rv \\<rightarrow> Rv \\<rightarrow> Rv)\n                            \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> Rv\"\nproof (clarsimp, goal_cases)\n  case prems: 1\n  from prems(10)\n  show ?case \n    apply (induction)\n    using prems(1-9)\n    apply simp_all\n    apply parametricity+\n    done\nqed\n\nlemma case_ltlr_mono[refine_mono]: \n  assumes \"\\<phi> = True_ltlr \\<Longrightarrow> a\\<le>a'\"\n  assumes \"\\<phi> = False_ltlr \\<Longrightarrow> b\\<le>b'\"\n  assumes \"\\<And>p. \\<phi> = Prop_ltlr p \\<Longrightarrow> c p\\<le>c' p\"\n  assumes \"\\<And>p. \\<phi> = Nprop_ltlr p \\<Longrightarrow> d p\\<le>d' p\"\n  assumes \"\\<And>\\<mu> \\<nu>. \\<phi> = And_ltlr \\<mu> \\<nu> \\<Longrightarrow> e \\<mu> \\<nu>\\<le>e' \\<mu> \\<nu>\"\n  assumes \"\\<And>\\<mu> \\<nu>. \\<phi> = Or_ltlr \\<mu> \\<nu> \\<Longrightarrow> f \\<mu> \\<nu>\\<le>f' \\<mu> \\<nu>\"\n  assumes \"\\<And>\\<mu>. \\<phi> = Next_ltlr \\<mu> \\<Longrightarrow> g \\<mu>\\<le>g' \\<mu>\"\n  assumes \"\\<And>\\<mu> \\<nu>. \\<phi> = Until_ltlr \\<mu> \\<nu> \\<Longrightarrow> h \\<mu> \\<nu>\\<le>h' \\<mu> \\<nu>\"\n  assumes \"\\<And>\\<mu> \\<nu>. \\<phi> = Release_ltlr \\<mu> \\<nu> \\<Longrightarrow> i \\<mu> \\<nu>\\<le>i' \\<mu> \\<nu>\"\n  shows \"case_ltlr a b c d e f g h i \\<phi> \\<le> case_ltlr a' b' c' d' e' f' g' h' i' \\<phi>\"\n  using assms\n  apply (cases \\<phi>)\n  apply simp_all\n  done\n\n\nprimrec ltlr_eq where\n  \"ltlr_eq eq True_ltlr f \\<longleftrightarrow> (case f of True_ltlr \\<Rightarrow> True | _ \\<Rightarrow> False)\"\n| \"ltlr_eq eq False_ltlr f \\<longleftrightarrow> (case f of False_ltlr \\<Rightarrow> True | _ \\<Rightarrow> False)\"\n| \"ltlr_eq eq (Prop_ltlr p) f \\<longleftrightarrow> (case f of Prop_ltlr p' \\<Rightarrow> eq p p' | _ \\<Rightarrow> False)\"\n| \"ltlr_eq eq (Nprop_ltlr p) f \\<longleftrightarrow> (case f of Nprop_ltlr p' \\<Rightarrow> eq p p' | _ \\<Rightarrow> False)\"\n| \"ltlr_eq eq (And_ltlr \\<mu> \\<nu>) f \n  \\<longleftrightarrow> (case f of And_ltlr \\<mu>' \\<nu>' \\<Rightarrow> ltlr_eq eq \\<mu> \\<mu>' \\<and> ltlr_eq eq \\<nu> \\<nu>' | _ \\<Rightarrow> False)\"\n| \"ltlr_eq eq (Or_ltlr \\<mu> \\<nu>) f \n  \\<longleftrightarrow> (case f of Or_ltlr \\<mu>' \\<nu>' \\<Rightarrow> ltlr_eq eq \\<mu> \\<mu>' \\<and> ltlr_eq eq \\<nu> \\<nu>' | _ \\<Rightarrow> False)\"\n| \"ltlr_eq eq (Next_ltlr \\<phi>) f \n  \\<longleftrightarrow> (case f of Next_ltlr \\<phi>' \\<Rightarrow> ltlr_eq eq \\<phi> \\<phi>' | _ \\<Rightarrow> False)\"\n| \"ltlr_eq eq (Until_ltlr \\<mu> \\<nu>) f \n  \\<longleftrightarrow> (case f of Until_ltlr \\<mu>' \\<nu>' \\<Rightarrow> ltlr_eq eq \\<mu> \\<mu>' \\<and> ltlr_eq eq \\<nu> \\<nu>' | _ \\<Rightarrow> False)\"\n| \"ltlr_eq eq (Release_ltlr \\<mu> \\<nu>) f \n  \\<longleftrightarrow> (case f of \n    Release_ltlr \\<mu>' \\<nu>' \\<Rightarrow> ltlr_eq eq \\<mu> \\<mu>' \\<and> ltlr_eq eq \\<nu> \\<nu>' \n  | _ \\<Rightarrow> False)\"\n\nlemma ltlr_eq_autoref[autoref_rules]:\n  assumes EQP: \"(eq,(=)) \\<in> R \\<rightarrow> R \\<rightarrow> bool_rel\"\n  shows \"(ltlr_eq eq, (=)) \\<in> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> bool_rel\"\nproof (intro fun_relI)\n  fix \\<mu>' \\<mu> \\<nu>' \\<nu>\n  assume \"(\\<mu>',\\<mu>)\\<in>\\<langle>R\\<rangle>ltlr_rel\" and \"(\\<nu>',\\<nu>)\\<in>\\<langle>R\\<rangle>ltlr_rel\"\n  then show \"(ltlr_eq eq \\<mu>' \\<nu>', \\<mu>=\\<nu>)\\<in>bool_rel\"\n    apply (induction arbitrary: \\<nu>' \\<nu>)\n    apply (erule ltlr_rel_cases, simp_all) []\n    apply (erule ltlr_rel_cases, simp_all) []\n    apply (erule ltlr_rel_cases, \n      simp_all add: EQP[THEN fun_relD, THEN fun_relD, THEN IdD]) []\n    apply (erule ltlr_rel_cases, \n      simp_all add: EQP[THEN fun_relD, THEN fun_relD, THEN IdD]) []\n    apply (rotate_tac -1)\n    apply (erule ltlr_rel_cases, simp_all) []\n    apply (rotate_tac -1)\n    apply (erule ltlr_rel_cases, simp_all) []\n    apply (rotate_tac -1)\n    apply (erule ltlr_rel_cases, simp_all) []\n    apply (rotate_tac -1)\n    apply (erule ltlr_rel_cases, simp_all) []\n    apply (rotate_tac -1)\n    apply (erule ltlr_rel_cases, simp_all) []\n    done\nqed\n\nlemma ltlr_dflt_cmp[autoref_rules_raw]: \n  assumes \"PREFER_id R\"\n  shows\n  \"(dflt_cmp (\\<le>) (<), dflt_cmp (\\<le>) (<)) \n  \\<in> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> comp_res_rel\"\n  using assms\n  by simp\n\ntype_synonym\n  node_name_impl = node_name \n\nabbreviation (input) \"node_name_rel \\<equiv> Id :: (node_name_impl\\<times>node_name) set\"\n\nlemma case_ltlr_gtransfer:\n  assumes\n  \"\\<gamma> ai \\<le> a\"\n  \"\\<gamma> bi \\<le> b\"\n  \"\\<And>a. \\<gamma> (ci a) \\<le> c a\"\n  \"\\<And>a. \\<gamma> (di a) \\<le> d a\"\n  \"\\<And>ltlr1 ltlr2. \\<gamma> (ei ltlr1 ltlr2) \\<le> e ltlr1 ltlr2\"\n  \"\\<And>ltlr1 ltlr2. \\<gamma> (fi ltlr1 ltlr2) \\<le> f ltlr1 ltlr2\"\n  \"\\<And>ltlr. \\<gamma> (gi ltlr) \\<le> g ltlr\"\n  \"\\<And>ltlr1 ltlr2. \\<gamma> (hi ltlr1 ltlr2) \\<le> h ltlr1 ltlr2\"\n  \"\\<And>ltlr1 ltlr2. \\<gamma> (iiv ltlr1 ltlr2) \\<le> i ltlr1 ltlr2\"\n  shows \"\\<gamma> (case_ltlr ai bi ci di ei fi gi hi iiv \\<phi>) \n    \\<le> (case_ltlr a b c d e f g h i \\<phi>)\"\n  apply (cases \\<phi>)\n  apply (auto intro: assms)\n  done\n\nlemmas [refine_transfer] \n  = case_ltlr_gtransfer[where \\<gamma>=nres_of] case_ltlr_gtransfer[where \\<gamma>=RETURN]\n\nlemma [refine_transfer]:\n  assumes \n  \"ai \\<noteq> dSUCCEED\"\n  \"bi \\<noteq> dSUCCEED\"\n  \"\\<And>a. ci a \\<noteq> dSUCCEED\"\n  \"\\<And>a. di a \\<noteq> dSUCCEED\"\n  \"\\<And>ltlr1 ltlr2. ei ltlr1 ltlr2 \\<noteq> dSUCCEED\"\n  \"\\<And>ltlr1 ltlr2. fi ltlr1 ltlr2 \\<noteq> dSUCCEED\"\n  \"\\<And>ltlr. gi ltlr \\<noteq> dSUCCEED\"\n  \"\\<And>ltlr1 ltlr2. hi ltlr1 ltlr2 \\<noteq> dSUCCEED\"\n  \"\\<And>ltlr1 ltlr2. iiv ltlr1 ltlr2 \\<noteq> dSUCCEED\"\n  shows \"case_ltlr ai bi ci di ei fi gi hi iiv \\<phi> \\<noteq> dSUCCEED\"\n  apply (cases \\<phi>)\n  apply (simp_all add: assms)\n  done\n\nsubsubsection \\<open>Nodes\\<close>\n\nrecord 'a node_impl =\n  name_impl   :: node_name_impl\n  incoming_impl :: \"(node_name_impl,unit) RBT_Impl.rbt\"\n  new_impl :: \"'a frml list\"\n  old_impl :: \"'a frml list\"\n  next_impl :: \"'a frml list\"\n\ndefinition node_rel where node_rel_def_internal: \"node_rel Re R \\<equiv> {( \n  \\<lparr> name_impl = namei, \n    incoming_impl = inci, \n    new_impl = newi,\n    old_impl = oldi,\n    next_impl = nexti,\n    \\<dots> = morei\n  \\<rparr>, \n  \\<lparr> name = name,\n    incoming = inc,\n    new=new,\n    old=old,\n    next = next,\n    \\<dots> = more\n  \\<rparr> ) | namei name inci inc newi new oldi old nexti next morei more. \n    (namei,name)\\<in>node_name_rel \n  \\<and> (inci,inc)\\<in>\\<langle>node_name_rel\\<rangle>dflt_rs_rel \n  \\<and> (newi,new)\\<in>\\<langle>\\<langle>R\\<rangle>ltlr_rel\\<rangle>lss.rel\n  \\<and> (oldi,old)\\<in>\\<langle>\\<langle>R\\<rangle>ltlr_rel\\<rangle>lss.rel\n  \\<and> (nexti,next)\\<in>\\<langle>\\<langle>R\\<rangle>ltlr_rel\\<rangle>lss.rel\n  \\<and> (morei,more)\\<in>Re\n  }\"\n\nlemma node_rel_def: \"\\<langle>Re,R\\<rangle>node_rel = {( \n  \\<lparr> name_impl = namei, \n    incoming_impl = inci, \n    new_impl = newi,\n    old_impl = oldi,\n    next_impl = nexti,\n    \\<dots> = morei\n  \\<rparr>, \n  \\<lparr> name = name,\n    incoming = inc,\n    new=new,\n    old=old,\n    next = next,\n    \\<dots> = more\n  \\<rparr> ) | namei name inci inc newi new oldi old nexti next morei more. \n    (namei,name)\\<in>node_name_rel \n  \\<and> (inci,inc)\\<in>\\<langle>node_name_rel\\<rangle>dflt_rs_rel  \n  \\<and> (newi,new)\\<in>\\<langle>\\<langle>R\\<rangle>ltlr_rel\\<rangle>lss.rel\n  \\<and> (oldi,old)\\<in>\\<langle>\\<langle>R\\<rangle>ltlr_rel\\<rangle>lss.rel\n  \\<and> (nexti,next)\\<in>\\<langle>\\<langle>R\\<rangle>ltlr_rel\\<rangle>lss.rel\n  \\<and> (morei,more)\\<in>Re\n  }\" by (simp add: node_rel_def_internal relAPP_def)\n\n\nlemma node_rel_sv[relator_props]: \n  \"single_valued Re \\<Longrightarrow> single_valued R \\<Longrightarrow> single_valued (\\<langle>Re,R\\<rangle>node_rel)\"\n  apply (rule single_valuedI)\n  apply (simp add: node_rel_def)\n  apply (auto \n    dest: single_valuedD lss.rel_sv[OF ltlr_rel_sv] map2set_rel_sv[OF ahm_rel_sv] \n    dest: single_valuedD[\n      OF map2set_rel_sv[OF rbt_map_rel_sv[OF single_valued_Id single_valued_Id]]\n    ])\n  done\n\nconsts i_node :: \"interface \\<Rightarrow> interface \\<Rightarrow> interface\"\n\nlemmas [autoref_rel_intf] = REL_INTFI[of node_rel i_node]\n\nlemma [autoref_rules]: \"(node_impl_ext, node_ext) \\<in> \n  node_name_rel \n  \\<rightarrow> \\<langle>node_name_rel\\<rangle>dflt_rs_rel \n  \\<rightarrow> \\<langle>\\<langle>R\\<rangle>ltlr_rel\\<rangle>lss.rel \n  \\<rightarrow> \\<langle>\\<langle>R\\<rangle>ltlr_rel\\<rangle>lss.rel \n  \\<rightarrow> \\<langle>\\<langle>R\\<rangle>ltlr_rel\\<rangle>lss.rel \n  \\<rightarrow> Re \n  \\<rightarrow> \\<langle>Re,R\\<rangle>node_rel\"\n  unfolding node_rel_def\n  by auto\n\nlemma [autoref_rules]: \n  \"(node_impl.name_impl_update,node.name_update) \n  \\<in> (node_name_rel \\<rightarrow> node_name_rel) \\<rightarrow> \\<langle>Re,R\\<rangle>node_rel \\<rightarrow> \\<langle>Re,R\\<rangle>node_rel\"\n  \"(node_impl.incoming_impl_update,node.incoming_update) \n  \\<in> (\\<langle>node_name_rel\\<rangle>dflt_rs_rel \\<rightarrow> \\<langle>node_name_rel\\<rangle>dflt_rs_rel) \n    \\<rightarrow> \\<langle>Re,R\\<rangle>node_rel \n    \\<rightarrow> \\<langle>Re,R\\<rangle>node_rel\"\n  \"(node_impl.new_impl_update,node.new_update) \n  \\<in> (\\<langle>\\<langle>R\\<rangle>ltlr_rel\\<rangle>lss.rel \\<rightarrow> \\<langle>\\<langle>R\\<rangle>ltlr_rel\\<rangle>lss.rel) \\<rightarrow> \\<langle>Re,R\\<rangle>node_rel \\<rightarrow> \\<langle>Re,R\\<rangle>node_rel\"\n  \"(node_impl.old_impl_update,node.old_update) \n  \\<in> (\\<langle>\\<langle>R\\<rangle>ltlr_rel\\<rangle>lss.rel \\<rightarrow> \\<langle>\\<langle>R\\<rangle>ltlr_rel\\<rangle>lss.rel) \\<rightarrow> \\<langle>Re,R\\<rangle>node_rel \\<rightarrow> \\<langle>Re,R\\<rangle>node_rel\"\n  \"(node_impl.next_impl_update,node.next_update) \n  \\<in> (\\<langle>\\<langle>R\\<rangle>ltlr_rel\\<rangle>lss.rel \\<rightarrow> \\<langle>\\<langle>R\\<rangle>ltlr_rel\\<rangle>lss.rel) \\<rightarrow> \\<langle>Re,R\\<rangle>node_rel \\<rightarrow> \\<langle>Re,R\\<rangle>node_rel\"\n  \"(node_impl.more_update,node.more_update) \n  \\<in> (Re \\<rightarrow> Re) \\<rightarrow> \\<langle>Re,R\\<rangle>node_rel \\<rightarrow> \\<langle>Re,R\\<rangle>node_rel\"\n  unfolding node_rel_def\n  by (auto dest: fun_relD)\n\nterm name\nlemma [autoref_rules]:\n  \"(node_impl.name_impl,node.name)\\<in>\\<langle>Re,R\\<rangle>node_rel \\<rightarrow> node_name_rel\"\n  \"(node_impl.incoming_impl,node.incoming)\n  \\<in> \\<langle>Re,R\\<rangle>node_rel \\<rightarrow> \\<langle>node_name_rel\\<rangle>dflt_rs_rel\"\n  \"(node_impl.new_impl,node.new)\\<in>\\<langle>Re,R\\<rangle>node_rel \\<rightarrow> \\<langle>\\<langle>R\\<rangle>ltlr_rel\\<rangle>lss.rel\"\n  \"(node_impl.old_impl,node.old)\\<in>\\<langle>Re,R\\<rangle>node_rel \\<rightarrow> \\<langle>\\<langle>R\\<rangle>ltlr_rel\\<rangle>lss.rel\"\n  \"(node_impl.next_impl,node.next)\\<in>\\<langle>Re,R\\<rangle>node_rel \\<rightarrow> \\<langle>\\<langle>R\\<rangle>ltlr_rel\\<rangle>lss.rel\"\n  \"(node_impl.more, node.more)\\<in>\\<langle>Re,R\\<rangle>node_rel \\<rightarrow> Re\"\n  unfolding node_rel_def by auto\n\n\nsubsection \\<open>Massaging the Abstract Algorithm\\<close>\ntext \\<open>\n  In a first step, we do some refinement steps on the abstract data structures,\n  with the goal to make the algorithm more efficient.\n\\<close>\n\nsubsubsection \\<open>Creation of the Nodes\\<close>\ntext \\<open>\n  In the expand-algorithm, we replace nested conditionals by case-distinctions,\n  and slightly stratify the code.\n\\<close>\n\n\n\nabbreviation (input) \"expand2 exp n ns \\<phi> n1 nx1 n2 \\<equiv> do {\n    (nm, nds) \\<leftarrow> exp (\n      n\\<lparr> \n        new := insert n1 (new n), \n        old := insert \\<phi> (old n), \n        next := nx1 \\<union> next n \\<rparr>, \n      ns);\n    exp (n\\<lparr> name := nm, new := n2 \\<union> new n, old := {\\<phi>} \\<union> old n \\<rparr>, nds)\n  }\"\n\n\n\ndefinition \"expand_aimpl \\<equiv> REC\\<^sub>T (\\<lambda>expand (n,ns). \n      if new n = {} then ( \n        if (\\<exists>n'\\<in>ns. old n' = old n \\<and> next n' = next n) then \n          RETURN (name n, upd_incoming n ns)\n        else do {\n          ASSERT (n \\<notin> ns);\n          ASSERT (name n \\<notin> name`ns);\n          expand (\\<lparr> \n            name=expand_new_name (name n), \n            incoming={name n}, \n            new=next n, \n            old={}, \n            next={} \\<rparr>, \n            insert n ns)\n        }\n      ) else do { \n        \\<phi> \\<leftarrow> SPEC (\\<lambda>x. x\\<in>(new n));\n        let n = n\\<lparr> new := new n - {\\<phi>} \\<rparr>;\n        case \\<phi> of\n          prop\\<^sub>r(q) \\<Rightarrow> \n            if nprop\\<^sub>r(q)\\<in>old n then RETURN (name n, ns)\n            else expand (n\\<lparr> old := {\\<phi>} \\<union> old n \\<rparr>, ns)\n        | nprop\\<^sub>r(q) \\<Rightarrow> \n            if prop\\<^sub>r(q)\\<in>old n then RETURN (name n, ns)\n            else expand (n\\<lparr> old := {\\<phi>} \\<union> old n \\<rparr>, ns)\n        | true\\<^sub>r \\<Rightarrow> expand (n\\<lparr> old := {\\<phi>} \\<union> old n \\<rparr>, ns)\n        | false\\<^sub>r \\<Rightarrow> RETURN (name n, ns)\n        | \\<nu> and\\<^sub>r \\<mu> \\<Rightarrow> expand (n\\<lparr> \n            new := insert \\<nu> (insert \\<mu> (new n)), \n            old := {\\<phi>} \\<union> old n, \n            next := next n \\<rparr>, ns)\n        | X\\<^sub>r \\<nu> \\<Rightarrow> expand \n            (n\\<lparr> new := new n, old := {\\<phi>} \\<union> old n, next := insert \\<nu> (next n) \\<rparr>, ns)\n        | \\<mu> or\\<^sub>r \\<nu> \\<Rightarrow> expand2 expand n ns \\<phi> \\<mu> {} {\\<nu>}\n        | \\<mu> U\\<^sub>r \\<nu> \\<Rightarrow> expand2 expand n ns \\<phi> \\<mu> {\\<phi>} {\\<nu>}\n        | \\<mu> R\\<^sub>r \\<nu> \\<Rightarrow> expand2 expand n ns \\<phi> \\<nu> {\\<phi>} {\\<mu>,\\<nu>}\n        \\<^cancel>\\<open>| _ \\<Rightarrow> do {\n          (nm, nds) \\<leftarrow> expand (\n            n\\<lparr> \n              new := new1 \\<phi> \\<union> new n, \n              old := {\\<phi>} \\<union> old n, \n              next := next1 \\<phi> \\<union> next n \\<rparr>,\n            ns);\n          expand (n\\<lparr> name := nm, new := new2 \\<phi> \\<union> new n, old := {\\<phi>} \\<union> old n \\<rparr>, nds)\n        }\\<close>\n      }\n     )\"\n\n\nlemma expand_aimpl_refine:\n  fixes n_ns :: \"('a node \\<times> _)\"\n  defines \"R \\<equiv> Id \\<inter> {(_,(n,ns)). \\<forall>n'\\<in>ns. n > name n'}\"\n  defines \"R' \\<equiv> Id \\<inter> {(_,(n,ns)). \\<forall>n'\\<in>ns. name n > name n'}\"\n  assumes [refine]: \"(n_ns',n_ns)\\<in>R'\"\n  shows \"expand_aimpl n_ns' \\<le> \\<Down>R (expand\\<^sub>T n_ns)\"\n  using [[goals_limit = 1]]\nproof -\n  have [relator_props]: \"single_valued R\" \n    by (auto simp add: R_def intro: single_valuedI)\n  have [relator_props]: \"single_valued R'\" \n    by (auto simp add: R'_def intro: single_valuedI)\n\n  {\n    fix n :: \"'a node\" and ns and n' ns'\n    assume \"((n', ns'), (n, ns)) \\<in> R'\"\n    then have \"(RETURN (name n', ns') \\<le> \\<Down> R (RETURN (name n, ns)))\"\n      by (auto simp: R_def R'_def pw_le_iff refine_pw_simps)\n  } note aux = this\n\n\n  show ?thesis\n    unfolding expand_aimpl_def expand\\<^sub>T_def\n    apply refine_rcg\n    apply (simp add: R_def R'_def)\n    apply (simp add: R_def R'_def)\n    apply (auto simp add: R_def R'_def upd_incoming_def) []\n    apply (auto simp add: R_def R'_def upd_incoming_def) []\n    apply (auto simp add: R_def R'_def upd_incoming_def) []\n    apply rprems\n    apply (auto simp: R'_def expand_new_name_def) []\n    apply (simp add: R'_def)\n\n    apply (auto split: ltlr.split) []\n    apply (fastforce simp: R_def R'_def) []\n    apply (fastforce simp: R_def R'_def) []\n\n    apply (auto simp: R_def R'_def) []\n    apply (auto simp: R_def R'_def) []\n    apply (auto simp: R_def R'_def) []\n    apply (auto simp: R_def R'_def) []\n    apply (auto simp: R_def R'_def) []\n    apply (auto simp: R_def R'_def) []\n    apply (auto simp: R_def R'_def) []\n    apply (auto simp: R_def R'_def) []\n    apply (auto simp: R_def R'_def) []\n    apply (refine_rcg, rprems, (fastforce simp: R_def R'_def)+) []\n    apply (fastforce simp: R'_def) []\n    apply (refine_rcg, rprems, (fastforce simp: R_def R'_def)+) []\n    apply (refine_rcg, rprems, (fastforce simp: R_def R'_def)+) []\n    done\nqed\n\n\nthm create_graph_def\ndefinition \"create_graph_aimpl \\<phi> = do {\n  (_, nds) \\<leftarrow>\n  expand_aimpl\n   (\\<lparr>name = expand_new_name expand_init, incoming = {expand_init},\n       new = {\\<phi>}, old = {}, next = {}\\<rparr>,\n    {});\n  RETURN nds\n}\"\n\nlemma create_graph_aimpl_refine: \"create_graph_aimpl \\<phi> \\<le> \\<Down>Id (create_graph\\<^sub>T \\<phi>)\"\n  unfolding create_graph_aimpl_def create_graph\\<^sub>T_def\n  apply (refine_rcg expand_aimpl_refine)\n  apply auto\n  done\n\nsubsubsection \\<open>Creation of GBA from Nodes\\<close>\n\ntext \\<open>\n  We summarize creation of the GBA and renaming of the nodes into one step\n\\<close>\nlemma create_name_gba_alt: \"create_name_gba \\<phi> = do {\n  nds \\<leftarrow> create_graph\\<^sub>T \\<phi>;\n  ASSERT (nds_invars nds);\n  RETURN (gba_rename_ext (\\<lambda>_. ()) name (create_gba_from_nodes \\<phi> nds))\n  }\"\nproof -\n  have [simp]: \"\\<And>nds. g_V (create_gba_from_nodes \\<phi> nds) = nds\"\n    by (auto simp: create_gba_from_nodes_def)\n\n  show ?thesis\n    unfolding create_name_gba_def create_gba_def\n    by simp\nqed\n\ntext \\<open>In the following, we implement the componenents of the\n  renamed GBA separately.\n\\<close>\n\ntext \\<open>\\paragraph{Successor Function}\\<close>\n\ndefinition \"build_succ nds = \n  FOREACH \n    nds (\\<lambda>q' s.\n    FOREACH\n      (incoming q') (\\<lambda>qn s. \n        if qn=expand_init then \n          RETURN s \n        else \n          RETURN (s(qn \\<mapsto> insert (name q') (the_default {} (s qn))))\n    ) s\n  ) Map.empty\"\n\nlemma build_succ_aux1:\n  assumes [simp]: \"finite nds\"\n  assumes [simp]: \"\\<And>q. q\\<in>nds \\<Longrightarrow> finite (incoming q)\"\n  shows \"build_succ nds \\<le> SPEC (\\<lambda>r. r = (\\<lambda>qn. \n  dflt_None_set {qn'. \\<exists>q'. \n    q'\\<in>nds \\<and> qn' = name q' \\<and> qn\\<in>incoming q' \\<and> qn\\<noteq>expand_init \n  }))\"\n  unfolding build_succ_def\n  apply (refine_rcg refine_vcg \n    FOREACH_rule[where\n      I=\"\\<lambda>it s. s = (\\<lambda>qn. dflt_None_set {qn'. \\<exists>q'. q'\\<in>nds-it \\<and> qn' = name q' \n    \\<and> qn\\<in>incoming q' \\<and> qn\\<noteq>expand_init })\"])\n\n  apply (simp_all add: dflt_None_set_def) [2]\n  apply (rename_tac q' it s)\n  apply (rule_tac I=\"\\<lambda>it2 s. s = \n    (\\<lambda>qn. dflt_None_set (\n      {qn'. \\<exists>q'. q'\\<in>nds-it \\<and> qn' = name q' \\<and> qn\\<in>incoming q' \\<and> qn\\<noteq>expand_init } \\<union> \n      {qn' . qn'=name q' \\<and> qn\\<in>incoming q' - it2 \\<and> qn\\<noteq>expand_init} ))\" \n    in FOREACH_rule)\n\n  apply auto []\n\n  apply (simp_all add: dflt_None_set_def)\n\n  apply (refine_rcg refine_vcg)\n  apply (auto simp: dflt_None_set_def intro!: ext) []\n  apply (rule ext, (auto) [])+\n  done\n\nlemma build_succ_aux2:\n  assumes NINIT: \"expand_init \\<notin> name`nds\"\n  assumes CL: \"\\<And>nd. nd\\<in>nds \\<Longrightarrow> incoming nd \\<subseteq> insert expand_init (name`nds)\"\n  shows\n  \"(\\<lambda>qn. dflt_None_set \n    {qn'. \\<exists>q'. q'\\<in>nds \\<and> qn' = name q' \\<and> qn\\<in>incoming q' \\<and> qn\\<noteq>expand_init }) \n  = (\\<lambda>qn. dflt_None_set (succ_of_E \n       (rename_E name {(q, q'). q \\<in> nds \\<and> q' \\<in> nds \\<and> name q \\<in> incoming q'}) qn))\" \n  (is \"(\\<lambda>qn. dflt_None_set (?L qn)) = (\\<lambda>qn. dflt_None_set (?R qn))\")\n  apply (intro ext)\n  apply (fo_rule arg_cong)\nproof (intro ext equalityI subsetI)\n  fix qn x\n  assume \"x\\<in>?R qn\"\n  then show \"x\\<in>?L qn\" using NINIT\n    by (force simp: succ_of_E_def)\nnext\n  fix qn x\n  assume XL: \"x\\<in>?L qn\"\n  show \"x\\<in>?R qn\"\n  proof (cases \"qn = expand_init\")\n    case False\n    from XL obtain q' where \n      A: \"q'\\<in>nds\" \"qn\\<in>incoming q'\" \n      and [simp]: \"x=name q'\" \n      by auto\n    from False obtain q where B: \"q\\<in>nds\" and [simp]: \"qn = name q\"\n      using CL A by auto\n\n    from A B show \"x\\<in>?R qn\"\n      by (auto simp: succ_of_E_def image_def)\n  next\n    case [simp]: True\n    from XL show \"x\\<in>?R qn\" by simp\n  qed\nqed\n\nlemma build_succ_correct:\n  assumes NINIT: \"expand_init \\<notin> name`nds\"\n  assumes FIN: \"finite nds\"\n  assumes CL: \"\\<And>nd. nd\\<in>nds \\<Longrightarrow> incoming nd \\<subseteq> insert expand_init (name`nds)\"\n  shows \"build_succ nds \\<le> SPEC (\\<lambda>r. \n    E_of_succ (\\<lambda>qn. the_default {} (r qn)) \n    = rename_E (\\<lambda>u. name u) {(q, q'). q \\<in> nds \\<and> q' \\<in> nds \\<and> name q \\<in> incoming q'})\"\nproof -\n  from FIN CL have FIN': \"\\<And>q. q\\<in>nds \\<Longrightarrow> finite (incoming q)\"\n    by (metis finite_imageI finite_insert infinite_super)\n  \n  note build_succ_aux1[OF FIN FIN']\n  also note build_succ_aux2[OF NINIT CL]\n  finally show ?thesis\n    by (rule order_trans) auto\nqed\n\ntext \\<open>\\paragraph{ Accepting Sets}\\<close>\n\nprimrec until_frmlsr :: \"'a frml \\<Rightarrow> ('a frml \\<times> 'a frml) set\" where\n  \"until_frmlsr (\\<mu> and\\<^sub>r \\<psi>) = (until_frmlsr \\<mu>) \\<union> (until_frmlsr \\<psi>)\"\n| \"until_frmlsr (X\\<^sub>r \\<mu>) = until_frmlsr \\<mu>\"\n| \"until_frmlsr (\\<mu> U\\<^sub>r \\<psi>) = insert (\\<mu>, \\<psi>) ((until_frmlsr \\<mu>) \\<union> (until_frmlsr \\<psi>))\"\n| \"until_frmlsr (\\<mu> R\\<^sub>r \\<psi>) = (until_frmlsr \\<mu>) \\<union> (until_frmlsr \\<psi>)\"\n| \"until_frmlsr (\\<mu> or\\<^sub>r \\<psi>) = (until_frmlsr \\<mu>) \\<union> (until_frmlsr \\<psi>)\"\n| \"until_frmlsr (true\\<^sub>r) = {}\"\n| \"until_frmlsr (false\\<^sub>r) = {}\"\n| \"until_frmlsr (prop\\<^sub>r(_)) = {}\"\n| \"until_frmlsr (nprop\\<^sub>r(_)) = {}\"\n\nlemma until_frmlsr_correct: \n  \"until_frmlsr \\<phi> = {(\\<mu>, \\<eta>). Until_ltlr \\<mu> \\<eta> \\<in> subfrmlsr \\<phi>}\"\n  by (induct \\<phi>) auto\n\n\ndefinition \"build_F nds \\<phi> \n  \\<equiv> (\\<lambda>(\\<mu>,\\<eta>). name ` {q \\<in> nds. (Until_ltlr \\<mu> \\<eta> \\<in> old q \\<longrightarrow> \\<eta> \\<in> old q)}) `\n    until_frmlsr \\<phi>\"\n\nlemma build_F_correct: \"build_F nds \\<phi> = \n  {name ` A |A. \\<exists>\\<mu> \\<eta>. A = {q \\<in> nds. Until_ltlr \\<mu> \\<eta> \\<in> old q \\<longrightarrow> \\<eta> \\<in> old q} \\<and>\n                     Until_ltlr \\<mu> \\<eta> \\<in> subfrmlsr \\<phi>}\"\nproof -\n  have \"{name ` A |A. \\<exists>\\<mu> \\<eta>. A = {q \\<in> nds. Until_ltlr \\<mu> \\<eta> \\<in> old q \\<longrightarrow> \\<eta> \\<in> old q} \\<and>\n                     Until_ltlr \\<mu> \\<eta> \\<in> subfrmlsr \\<phi>}\n    = (\\<lambda>(\\<mu>,\\<eta>). name`{q\\<in>nds. Until_ltlr \\<mu> \\<eta> \\<in> old q \\<longrightarrow> \\<eta> \\<in> old q}) \n      ` {(\\<mu>, \\<eta>). Until_ltlr \\<mu> \\<eta> \\<in> subfrmlsr \\<phi>}\"\n    by auto\n  also have \"\\<dots> = (\\<lambda>(\\<mu>,\\<eta>). name`{q\\<in>nds. Until_ltlr \\<mu> \\<eta> \\<in> old q \\<longrightarrow> \\<eta> \\<in> old q}) \n      ` until_frmlsr \\<phi>\"\n    unfolding until_frmlsr_correct ..\n  finally show ?thesis\n    unfolding build_F_def by simp\nqed\n\ntext \\<open>\\paragraph{ Labeling Function }\\<close>\ndefinition \"pn_props ps \\<equiv> FOREACHi \n  (\\<lambda>it (P,N). P = {p. Prop_ltlr p \\<in> ps - it} \\<and> N = {p. Nprop_ltlr p \\<in> ps - it}) \n  ps (\\<lambda>p (P,N). \n    case p of Prop_ltlr p \\<Rightarrow> RETURN (insert p P,N)\n    | Nprop_ltlr p \\<Rightarrow> RETURN (P, insert p N)\n    | _ \\<Rightarrow> RETURN (P,N)\n  ) ({},{})\"\n\nlemma pn_props_correct: \n  assumes [simp]: \"finite ps\"\n  shows \"pn_props ps \\<le> SPEC(\\<lambda>r. r = \n  ({p. Prop_ltlr p \\<in> ps}, {p. Nprop_ltlr p \\<in> ps}))\"\n  unfolding pn_props_def\n  apply (refine_rcg refine_vcg)\n  apply (auto split: ltlr.split)\n  done\n\ndefinition \"pn_map nds \\<equiv> FOREACH nds \n  (\\<lambda>nd m. do {\n    PN \\<leftarrow> pn_props (old nd);\n    RETURN (m(name nd \\<mapsto> PN))\n  }) Map.empty\"\n\nlemma pn_map_correct: \n  assumes [simp]: \"finite nds\"\n  assumes FIN': \"\\<And>nd. nd\\<in>nds \\<Longrightarrow> finite (old nd)\"\n  assumes INJ: \"inj_on name nds\"\n  shows \"pn_map nds \\<le> SPEC (\\<lambda>r. \\<forall>qn. \n    case r qn of \n      None \\<Rightarrow> qn \\<notin> name`nds\n    | Some (P,N) \\<Rightarrow> qn \\<in> name`nds \n      \\<and> P = {p. Prop_ltlr p \\<in> old (the_inv_into nds name qn)}\n      \\<and> N = {p. Nprop_ltlr p \\<in> old (the_inv_into nds name qn)}\n  )\"\n  unfolding pn_map_def\n  apply (refine_rcg refine_vcg\n    FOREACH_rule[where I=\"\\<lambda>it r. \\<forall>qn. \n      case r qn of \n        None \\<Rightarrow> qn \\<notin> name`(nds - it)\n      | Some (P,N) \\<Rightarrow> qn \\<in> name`(nds - it)\n        \\<and> P = {p. Prop_ltlr p \\<in> old (the_inv_into nds name qn)}\n        \\<and> N = {p. Nprop_ltlr p \\<in> old (the_inv_into nds name qn)}\"]\n    order_trans[OF pn_props_correct]\n  )\n  apply simp_all\n  apply (blast dest: subsetD[THEN FIN']) []\n  apply (force \n    split: option.splits \n    simp: the_inv_into_f_f[OF INJ] it_step_insert_iff) []\n  apply (fastforce split: option.splits) []\n  done\n\n \ntext \\<open>\\paragraph{ Assembling the Implementation }\\<close>\n  \ndefinition \"cr_rename_gba nds \\<phi> \\<equiv> do {\n  let V = name ` nds;\n  let V0 = name ` {q \\<in> nds. expand_init \\<in> incoming q};\n  succmap \\<leftarrow> build_succ nds;\n  let E = E_of_succ (the_default {} o succmap);\n  let F = build_F nds \\<phi>;\n  pnm \\<leftarrow> pn_map nds;\n  let L = (\\<lambda>qn l. case pnm qn of \n      None \\<Rightarrow> False \n    | Some (P,N) \\<Rightarrow> (\\<forall>p\\<in>P. p\\<in>(l:::\\<^sub>r\\<langle>Id\\<rangle>fun_set_rel)) \\<and> (\\<forall>p\\<in>N. p\\<notin>l)\n  );\n  RETURN (\\<lparr> g_V = V, g_E=E, g_V0=V0, gbg_F = F, gba_L = L \\<rparr>)\n}\"\n\nlemma cr_rename_gba_refine:\n  assumes INV: \"nds_invars nds\"\n  assumes REL[simplified]: \"(nds',nds)\\<in>Id\" \"(\\<phi>',\\<phi>)\\<in>Id\"\n  shows \"cr_rename_gba nds' \\<phi>' \n  \\<le> \\<Down>Id (RETURN (gba_rename_ext (\\<lambda>_. ()) name (create_gba_from_nodes \\<phi> nds)))\"\n  unfolding RETURN_SPEC_conv\nproof (rule Id_SPEC_refine)\n  from INV have\n    NINIT: \"expand_init \\<notin> name`nds\"\n    and FIN: \"finite nds\"\n    and FIN': \"\\<And>nd. nd\\<in>nds \\<Longrightarrow> finite (old nd)\"\n    and CL: \"\\<And>nd. nd\\<in>nds \\<Longrightarrow> incoming nd \\<subseteq> insert expand_init (name`nds)\"\n    and INJ: \"inj_on name nds\"\n    unfolding nds_invars_def by auto\n  show \"cr_rename_gba nds' \\<phi>'\n    \\<le> SPEC (\\<lambda>x. x = gba_rename_ext (\\<lambda>_. ()) name (create_gba_from_nodes \\<phi> nds))\"\n    unfolding REL\n    unfolding cr_rename_gba_def\n    apply (refine_rcg refine_vcg\n      order_trans[OF build_succ_correct[OF NINIT FIN CL]]\n      order_trans[OF pn_map_correct[OF FIN FIN' INJ]]\n    )\n    unfolding gba_rename_ecnv_def gb_rename_ecnv_def \n      fr_rename_ext_def create_gba_from_nodes_def\n    apply simp\n    apply (intro conjI)\n    apply (simp add: comp_def)\n    apply (simp add: build_F_correct)\n    apply (intro ext)\n    apply (drule_tac x=qn in spec)\n    apply (auto simp: the_inv_into_f_f[OF INJ] split: option.split prod.split)\n    done\nqed\n\ndefinition \"create_name_gba_aimpl \\<phi> \\<equiv> do {\n  nds \\<leftarrow> create_graph_aimpl \\<phi>;\n  ASSERT (nds_invars nds);\n  cr_rename_gba nds \\<phi>\n}\"\n\n\nlemma create_name_gba_aimpl_refine: \n  \"create_name_gba_aimpl \\<phi> \\<le> \\<Down>Id (create_name_gba \\<phi>)\"\n  unfolding create_name_gba_aimpl_def create_name_gba_alt\n  apply (refine_rcg create_graph_aimpl_refine cr_rename_gba_refine)\n  by auto\n\nsubsection \\<open>Refinement to Efficient Data Structures\\<close>\n\nsubsubsection \\<open>Creation of GBA from Nodes\\<close>\n\nschematic_goal until_frmlsr_impl_aux:\n  assumes [relator_props, simp]: \"R=Id\"\n  shows \"(?c,until_frmlsr) \n  \\<in> \\<langle>(R::(_\\<times>_::linorder) set)\\<rangle>ltlr_rel \\<rightarrow> \\<langle>\\<langle>R\\<rangle>ltlr_rel \\<times>\\<^sub>r \\<langle>R\\<rangle>ltlr_rel\\<rangle>dflt_rs_rel\"\n  unfolding until_frmlsr_def\n  apply (autoref (keep_goal, trace))\n  done\nconcrete_definition until_frmlsr_impl uses until_frmlsr_impl_aux\nlemmas [autoref_rules] = until_frmlsr_impl.refine[OF PREFER_id_D]\n\n\n\n\nschematic_goal build_succ_impl_aux:\n  shows \"(?c,build_succ) \\<in> \n    \\<langle>\\<langle>Rm,R\\<rangle>node_rel\\<rangle>list_set_rel \n    \\<rightarrow> \\<langle>\\<langle>nat_rel,\\<langle>nat_rel\\<rangle>list_set_rel\\<rangle>iam_map_rel\\<rangle>nres_rel\"\n  unfolding build_succ_def[abs_def] expand_init_def\n  using [[autoref_trace_failed_id]]\n  apply (autoref (keep_goal, trace))\n  done\n\nconcrete_definition build_succ_impl uses build_succ_impl_aux\nlemmas [autoref_rules] = build_succ_impl.refine\n\n(* TODO: Post-processing should be on by default! *)\nschematic_goal build_succ_code_aux: \"RETURN ?c \\<le> build_succ_impl x\"\n  unfolding build_succ_impl_def\n  apply (refine_transfer (post))\n  done\n\nconcrete_definition build_succ_code uses build_succ_code_aux\nlemmas [refine_transfer] = build_succ_code.refine\n\n\n\n\nschematic_goal build_F_impl_aux:\n  assumes [relator_props]:  \"R = Id\"\n  shows \"(?c,build_F) \\<in> \n    \\<langle>\\<langle>Rm,R\\<rangle>node_rel\\<rangle>list_set_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>\\<langle>nat_rel\\<rangle>list_set_rel\\<rangle>list_set_rel\"\n  unfolding build_F_def[abs_def]\n  using [[autoref_trace_failed_id]]\n  apply (autoref (keep_goal, trace))\n  done\n\nconcrete_definition build_F_impl uses build_F_impl_aux\nlemmas [autoref_rules] = build_F_impl.refine[OF PREFER_id_D]\n\n\n\n\nschematic_goal pn_map_impl_aux:\n  shows \"(?c,pn_map) \\<in> \n    \\<langle>\\<langle>Rm,Id\\<rangle>node_rel\\<rangle>list_set_rel \n    \\<rightarrow> \\<langle>\\<langle>nat_rel,\\<langle>Id\\<rangle>list_set_rel \\<times>\\<^sub>r \\<langle>Id\\<rangle>list_set_rel\\<rangle>iam_map_rel\\<rangle>nres_rel\"\n  unfolding pn_map_def[abs_def] pn_props_def\n  using [[autoref_trace_failed_id]]\n  apply (autoref (keep_goal, trace))\n  done\n\nconcrete_definition pn_map_impl uses pn_map_impl_aux\nlemma pn_map_impl_autoref[autoref_rules]: \n  assumes \"PREFER_id R\"\n  shows \"(pn_map_impl,pn_map) \\<in> \n    \\<langle>\\<langle>Rm,R\\<rangle>node_rel\\<rangle>list_set_rel \n    \\<rightarrow> \\<langle>\\<langle>nat_rel,\\<langle>R\\<rangle>list_set_rel \\<times>\\<^sub>r \\<langle>R\\<rangle>list_set_rel\\<rangle>iam_map_rel\\<rangle>nres_rel\"\n  using assms pn_map_impl.refine by simp\n\nschematic_goal pn_map_code_aux: \"RETURN ?c \\<le> pn_map_impl x\"\n  unfolding pn_map_impl_def\n  apply (refine_transfer (post))\n  done\nconcrete_definition pn_map_code uses pn_map_code_aux\nlemmas [refine_transfer] = pn_map_code.refine \n\nschematic_goal cr_rename_gba_impl_aux:\n  assumes ID[relator_props]: \"R=Id\"\n  notes [autoref_tyrel del] = tyrel_dflt_linorder_set\n  notes [autoref_tyrel] = ty_REL[of \"\\<langle>nat_rel\\<rangle>list_set_rel\"]\n  shows \"(?c,cr_rename_gba) \\<in> \n    \\<langle>\\<langle>Rm,R\\<rangle>node_rel\\<rangle>list_set_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> (?R::(?'c \\<times> _) set)\"\n  unfolding ID\n  unfolding cr_rename_gba_def[abs_def] expand_init_def comp_def\n  using [[autoref_trace_failed_id]]\n  apply (autoref (keep_goal, trace))\n  done\nconcrete_definition cr_rename_gba_impl uses cr_rename_gba_impl_aux\n\nthm cr_rename_gba_impl.refine\n\nlemma cr_rename_gba_autoref[autoref_rules]:\n  assumes \"PREFER_id R\"\n  shows \"(cr_rename_gba_impl, cr_rename_gba) \\<in> \n    \\<langle>\\<langle>Rm, R\\<rangle>node_rel\\<rangle>list_set_rel \\<rightarrow> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow>\n    \\<langle>gbav_impl_rel_ext unit_rel nat_rel (\\<langle>R\\<rangle>fun_set_rel)\\<rangle>nres_rel\"\n  using assms cr_rename_gba_impl.refine[of R Rm] by simp\n\n\nschematic_goal cr_rename_gba_code_aux: \"RETURN ?c \\<le> cr_rename_gba_impl x y\"\n  unfolding cr_rename_gba_impl_def\n  apply (refine_transfer (post))\n  done\nconcrete_definition cr_rename_gba_code uses cr_rename_gba_code_aux\nlemmas [refine_transfer] = cr_rename_gba_code.refine \n\n\nsubsubsection \\<open>Creation of Graph\\<close>\n\ntext \\<open>\n  The implementation of the node-set. The relation enforces that there are no\n  different nodes with the same name. This effectively establishes an additional\n  invariant, made explicit by an assertion in the refined program. This invariant\n  allows for a more efficient implementation.\n\\<close>\ndefinition ls_nds_rel_def_internal: \n  \"ls_nds_rel R \\<equiv> \\<langle>R\\<rangle>list_set_rel \\<inter> {(_,s). inj_on name s}\"\nlemma ls_nds_rel_def: \"\\<langle>R\\<rangle>ls_nds_rel = \\<langle>R\\<rangle>list_set_rel \\<inter> {(_,s). inj_on name s}\"\n  by (simp add: relAPP_def ls_nds_rel_def_internal)\n\nlemmas [autoref_rel_intf] = REL_INTFI[of ls_nds_rel i_set]\n\nlemma ls_nds_rel_sv[relator_props]: \n  assumes \"single_valued R\" \n  shows \"single_valued (\\<langle>R\\<rangle>ls_nds_rel)\"\n  using list_set_rel_sv[OF assms]\n  unfolding ls_nds_rel_def\n  by (metis inf.cobounded1 single_valued_subset)\n\ncontext begin interpretation autoref_syn .\nlemma lsnds_empty_autoref[autoref_rules]:\n  assumes \"PREFER_id R\"\n  shows \"([],{})\\<in>\\<langle>R\\<rangle>ls_nds_rel\"\n  using assms\n  apply (simp add: ls_nds_rel_def)\n  by autoref\n\nlemma lsnds_insert_autoref[autoref_rules]:\n  assumes \"SIDE_PRECOND (name n \\<notin> name`ns)\"\n  assumes \"(n',n)\\<in>R\"\n  assumes \"(ns',ns)\\<in>\\<langle>R\\<rangle>ls_nds_rel\"\n  shows \"(n'#ns',(OP insert ::: R \\<rightarrow> \\<langle>R\\<rangle>ls_nds_rel \\<rightarrow> \\<langle>R\\<rangle>ls_nds_rel)$n$ns)\n   \\<in> \\<langle>R\\<rangle>ls_nds_rel\"\n  using assms\n  unfolding ls_nds_rel_def\n  apply simp\nproof (elim conjE, rule conjI)\n  assume [autoref_rules]: \"(n', n) \\<in> R\" \"(ns', ns) \\<in> \\<langle>R\\<rangle>list_set_rel\"\n  assume \"name n \\<notin> name ` ns\"\n    and \"inj_on name ns\"\n  then have \"n \\<notin> ns\" by (auto)\n  then show \"(n' # ns', insert n ns) \\<in> \\<langle>R\\<rangle>list_set_rel\"\n    by autoref\nqed auto\n\nlemma ls_nds_image_autoref_aux:\n  assumes [autoref_rules]: \"(fi,f) \\<in> Ra \\<rightarrow> Rb\"\n  assumes \"(l,s) \\<in> \\<langle>Ra\\<rangle>ls_nds_rel\"\n  assumes [simp]: \"\\<forall>x. name (f x) = name x\"\n  shows \"(map fi l, f`s) \\<in> \\<langle>Rb\\<rangle>ls_nds_rel\"\nproof -\n  from assms have \n    [autoref_rules]: \"(l,s)\\<in>\\<langle>Ra\\<rangle>list_set_rel\" \n      and INJ: \"(inj_on name s)\"\n    by (auto simp add: ls_nds_rel_def)\n  \n  have [simp]: \"inj_on f s\"\n    by (rule inj_onI) (metis INJ assms(3) inj_on_eq_iff)\n\n  have \"(map fi l, f`s) \\<in> \\<langle>Rb\\<rangle>list_set_rel\"\n    by (autoref (keep_goal))\n  moreover have \"inj_on name (f`s)\"\n    apply (rule inj_onI)\n    apply (auto simp: image_iff dest: inj_onD[OF INJ])\n    done\n  ultimately show ?thesis\n    by (auto simp: ls_nds_rel_def)\nqed  \n\nlemma ls_nds_image_autoref[autoref_rules]:\n  assumes \"(fi,f) \\<in> Ra \\<rightarrow> Rb\"\n  assumes \"SIDE_PRECOND (\\<forall>x. name (f x) = name x)\"\n  shows \"(map fi, (OP (`) ::: (Ra\\<rightarrow>Rb) \\<rightarrow> \\<langle>Ra\\<rangle>ls_nds_rel \\<rightarrow> \\<langle>Rb\\<rangle>ls_nds_rel)$f) \n    \\<in> \\<langle>Ra\\<rangle>ls_nds_rel \\<rightarrow> \\<langle>Rb\\<rangle>ls_nds_rel\"\n  using assms\n  unfolding autoref_tag_defs\n  using ls_nds_image_autoref_aux\n  by blast\n\nlemma list_set_autoref_to_list[autoref_ga_rules]: \n  shows \"is_set_to_sorted_list (\\<lambda>_ _. True) R ls_nds_rel id\"\n  unfolding is_set_to_list_def is_set_to_sorted_list_def ls_nds_rel_def\n    it_to_sorted_list_def list_set_rel_def br_def\n  by auto\n\n\nend\n\ncontext begin interpretation autoref_syn .\nlemma [autoref_itype]:\n  \"upd_incoming \n    ::\\<^sub>i \\<langle>Im, I\\<rangle>\\<^sub>ii_node \\<rightarrow>\\<^sub>i \\<langle>\\<langle>Im', I\\<rangle>\\<^sub>ii_node\\<rangle>\\<^sub>ii_set \\<rightarrow>\\<^sub>i \\<langle>\\<langle>Im', I\\<rangle>\\<^sub>ii_node\\<rangle>\\<^sub>ii_set\"\n  by simp\nend\n\nterm upd_incoming\nschematic_goal upd_incoming_impl_aux:\n  assumes \"REL_IS_ID R\"\n  shows \"(?c, upd_incoming)\\<in>\\<langle>Rm1,R\\<rangle>node_rel \n  \\<rightarrow> \\<langle>\\<langle>Rm2,R\\<rangle>node_rel\\<rangle>ls_nds_rel \n  \\<rightarrow> \\<langle>\\<langle>Rm2,R\\<rangle>node_rel\\<rangle>ls_nds_rel\"\n  using assms apply simp\n  unfolding upd_incoming_def[abs_def]\n  using [[autoref_trace_failed_id]]\n  apply (autoref (keep_goal))\n  done\n\nconcrete_definition upd_incoming_impl uses upd_incoming_impl_aux\nlemmas [autoref_rules] = upd_incoming_impl.refine[OF PREFER_D[of REL_IS_ID]]\n\n\nschematic_goal expand_impl_aux: \"(?c, expand_aimpl) \\<in> \n  \\<langle>unit_rel,Id\\<rangle>node_rel \\<times>\\<^sub>r \\<langle>\\<langle>unit_rel,Id\\<rangle>node_rel\\<rangle>ls_nds_rel \n  \\<rightarrow> \\<langle>nat_rel \\<times>\\<^sub>r \\<langle>\\<langle>unit_rel,Id\\<rangle>node_rel\\<rangle>ls_nds_rel\\<rangle>nres_rel\"\n  unfolding expand_aimpl_def[abs_def] expand_new_name_def\n  using [[autoref_trace_failed_id, autoref_trace_intf_unif]]\n  apply (autoref (trace,keep_goal))\n  done\n\nconcrete_definition expand_impl uses expand_impl_aux\n\ncontext begin interpretation autoref_syn .\nlemma [autoref_itype]: \"expand\\<^sub>T \n  ::\\<^sub>i \\<langle>\\<langle>i_unit, I\\<rangle>\\<^sub>ii_node, \\<langle>\\<langle>i_unit, I\\<rangle>\\<^sub>ii_node\\<rangle>\\<^sub>ii_set\\<rangle>\\<^sub>ii_prod \n  \\<rightarrow>\\<^sub>i \\<langle>\\<langle>i_nat,\\<langle>\\<langle>i_unit, I\\<rangle>\\<^sub>ii_node\\<rangle>\\<^sub>ii_set\\<rangle>\\<^sub>ii_prod\\<rangle>\\<^sub>ii_nres\" by simp\n\nlemma expand_autoref[autoref_rules]:\n  assumes ID: \"PREFER_id R\"\n  assumes A: \"(n_ns', n_ns) \n    \\<in> \\<langle>unit_rel,R\\<rangle>node_rel \\<times>\\<^sub>r \\<langle>\\<langle>unit_rel,R\\<rangle>node_rel\\<rangle>list_set_rel\"\n  assumes B: \"SIDE_PRECOND (\n    let (n,ns)=n_ns in inj_on name ns \\<and> (\\<forall>n'\\<in>ns. name n > name n')\n  )\"\n  shows \"(expand_impl n_ns', \n    (OP expand_aimpl\n    ::: \\<langle>unit_rel,R\\<rangle>node_rel \\<times>\\<^sub>r \\<langle>\\<langle>unit_rel,R\\<rangle>node_rel\\<rangle>list_set_rel \n    \\<rightarrow> \\<langle>nat_rel \\<times>\\<^sub>r \\<langle>\\<langle>unit_rel,R\\<rangle>node_rel\\<rangle>list_set_rel\\<rangle>nres_rel)$n_ns) \n  \\<in> \\<langle>nat_rel \\<times>\\<^sub>r \\<langle>\\<langle>unit_rel,R\\<rangle>node_rel\\<rangle>list_set_rel\\<rangle>nres_rel\"\nproof simp\n  from ID A B have \n    1: \"(n_ns, n_ns) \\<in> Id \\<inter> {(_,(n,ns)). \\<forall>n'\\<in>ns. name n > name n'}\"\n    and 2: \"(n_ns', n_ns) \n      \\<in> \\<langle>unit_rel,Id\\<rangle>node_rel \\<times>\\<^sub>r \\<langle>\\<langle>unit_rel,Id\\<rangle>node_rel\\<rangle>ls_nds_rel\"\n    unfolding ls_nds_rel_def\n    apply -\n    apply auto []\n    apply (cases n_ns')\n    apply auto []\n    done\n\n  have [simp]: \"single_valued (nat_rel \\<times>\\<^sub>r \\<langle>\\<langle>unit_rel, Id\\<rangle>node_rel\\<rangle>list_set_rel)\"\n    by tagged_solver\n\n\n  have [relator_props]: \"\\<And>R. single_valued (Id \\<inter> R)\"\n    by (metis IntE single_valuedD single_valuedI single_valued_Id)\n    \n  have [simp]: \"single_valued ((nat_rel \\<times>\\<^sub>r \\<langle>\\<langle>unit_rel, Id\\<rangle>node_rel\\<rangle>ls_nds_rel) O\n                          (Id \\<inter> {(_, n, ns). \\<forall>n'\\<in>ns. name n' < n}))\"\n    by (tagged_solver)\n    \n  from expand_impl.refine[THEN fun_relD, OF 2, THEN nres_relD]\n  show \"(expand_impl n_ns', expand_aimpl n_ns)\n    \\<in> \\<langle>nat_rel \\<times>\\<^sub>r \\<langle>\\<langle>unit_rel, R\\<rangle>node_rel\\<rangle>list_set_rel\\<rangle>nres_rel\"\n    apply -\n    apply (rule nres_relI)\n    using ID\n    apply (simp add: pw_le_iff refine_pw_simps)\n    apply (fastforce simp: ls_nds_rel_def)\n    done\nqed\n\nend\n\n\nschematic_goal expand_code_aux: \"RETURN ?c \\<le> expand_impl n_ns\"\n  unfolding expand_impl_def\n  by (refine_transfer the_resI)\nconcrete_definition expand_code uses expand_code_aux\nprepare_code_thms expand_code_def\nlemmas [refine_transfer] = expand_code.refine \n\n\nschematic_goal create_graph_impl_aux: \n  assumes ID: \"R=Id\"\n  shows \"(?c, create_graph_aimpl) \n    \\<in> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>\\<langle>\\<langle>unit_rel,R\\<rangle>node_rel\\<rangle>list_set_rel\\<rangle>nres_rel\"\n  unfolding ID\n  unfolding create_graph_aimpl_def[abs_def] expand_init_def expand_new_name_def\n  using [[autoref_trace_failed_id]]\n  apply (autoref (keep_goal))\n  done\nconcrete_definition create_graph_impl uses create_graph_impl_aux\n\nlemmas [autoref_rules] = create_graph_impl.refine[OF PREFER_id_D]\n\nschematic_goal create_graph_code_aux: \"RETURN ?c \\<le> create_graph_impl \\<phi>\" \n  unfolding create_graph_impl_def\n  by refine_transfer\nconcrete_definition create_graph_code uses create_graph_code_aux\nlemmas [refine_transfer] = create_graph_code.refine\n\n\nschematic_goal create_name_gba_impl_aux: \n  \"(?c, (create_name_gba_aimpl:: 'a::linorder ltlr \\<Rightarrow> _)) \n  \\<in> \\<langle>Id\\<rangle>ltlr_rel \\<rightarrow> (?R::(?'c\\<times>_) set)\"\n  unfolding create_name_gba_aimpl_def[abs_def]\n  using [[autoref_trace_failed_id]]\n  apply (autoref (keep_goal, trace))\n  done\nconcrete_definition create_name_gba_impl uses create_name_gba_impl_aux\n\nlemma create_name_gba_autoref[autoref_rules]:\n  assumes \"PREFER_id R\"\n  shows\n  \"(create_name_gba_impl, create_name_gba)\n  \\<in> \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>gbav_impl_rel_ext unit_rel nat_rel (\\<langle>R\\<rangle>fun_set_rel)\\<rangle>nres_rel\" \n  (is \"_:_\\<rightarrow>\\<langle>?R\\<rangle>nres_rel\")\nproof (intro fun_relI nres_relI)\n  fix \\<phi> \\<phi>'\n  assume A: \"(\\<phi>,\\<phi>')\\<in>\\<langle>R\\<rangle>ltlr_rel\"\n  from assms have RID[simp]: \"R=Id\" by simp\n    \n  note create_name_gba_impl.refine[THEN fun_relD,THEN nres_relD, OF A[unfolded RID]]\n  also note create_name_gba_aimpl_refine\n  finally show \"create_name_gba_impl \\<phi> \\<le> \\<Down> ?R (create_name_gba \\<phi>')\" by simp\nqed\n \nschematic_goal create_name_gba_code_aux: \"RETURN ?c \\<le> create_name_gba_impl \\<phi>\" \n  unfolding create_name_gba_impl_def\n  by (refine_transfer (post))\nconcrete_definition create_name_gba_code uses create_name_gba_code_aux\nlemmas [refine_transfer] = create_name_gba_code.refine\n\nschematic_goal create_name_igba_impl_aux: \n  assumes RID: \"R=Id\"\n  shows \"(?c,create_name_igba)\\<in>\n  \\<langle>R\\<rangle>ltlr_rel \\<rightarrow> \\<langle>igbav_impl_rel_ext unit_rel nat_rel (\\<langle>R\\<rangle>fun_set_rel)\\<rangle>nres_rel\"\n  unfolding RID\n  unfolding create_name_igba_def[abs_def]\n  using [[autoref_trace_failed_id]]\n  apply (autoref (trace, keep_goal))\n  done\nconcrete_definition create_name_igba_impl uses create_name_igba_impl_aux\nlemmas [autoref_rules] = create_name_igba_impl.refine[OF PREFER_id_D]\n\nschematic_goal create_name_igba_code_aux: \"RETURN ?c \\<le> create_name_igba_impl \\<phi>\" \n  unfolding create_name_igba_impl_def\n  by (refine_transfer (post))\nconcrete_definition create_name_igba_code uses create_name_igba_code_aux\nlemmas [refine_transfer] = create_name_igba_code.refine\n\nexport_code create_name_igba_code checking SML\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/LTL_to_GBA/LTL_to_GBA_impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5117166047041654, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.2658476869407446}}
{"text": "(******************************************************************************)\n(* Project: The Isabelle/UTP Proof System                                     *)\n(* File: Architecture_D2_3c.thy                                               *)\n(* Authors: Frank Zeyda and Simon Foster (University of York, UK)             *)\n(* Emails: frank.zeyda@york.ac.uk and simon.foster@york.ac.uk                 *)\n(******************************************************************************)\n\nsection {* Railways Architecture *}\n\ntheory Architecture_D2_3c\nimports fmi\nbegin recall_syntax\n\nsubsection {* Preliminaries *}\n\nsubsubsection {* Track Segments *}\n\ndefinition \"CDV1 = (1::fmi2Integer)\"\ndefinition \"CDV2 = (2::fmi2Integer)\"\ndefinition \"CDV3 = (3::fmi2Integer)\"\ndefinition \"CDV4 = (4::fmi2Integer)\"\ndefinition \"CDV5 = (5::fmi2Integer)\"\ndefinition \"CDV6 = (6::fmi2Integer)\"\ndefinition \"CDV7 = (7::fmi2Integer)\"\ndefinition \"CDV8 = (8::fmi2Integer)\"\ndefinition \"CDV9 = (9::fmi2Integer)\"\ndefinition \"CDV10 = (10::fmi2Integer)\"\ndefinition \"CDV11 = (11::fmi2Integer)\"\n\nsubsubsection {* Available Routes *}\n\ndefinition \"V1Q1 = (1::fmi2Integer)\"\ndefinition \"V1Q2 = (2::fmi2Integer)\"\ndefinition \"Q2V2 = (3::fmi2Integer)\"\ndefinition \"V1Q3 = (4::fmi2Integer)\"\ndefinition \"Q3V2 = (5::fmi2Integer)\"\n\nsubsubsection {* Signal Encoding *}\n\ndefinition \"RED == False\"\ndefinition \"GREEN == True\"\n\nfun signals :: \"(bool \\<times> bool \\<times> bool) \\<Rightarrow> fmi2Integer\" where\n\"signals (s1, s2, s3) =\n  (if s1 then 1 else 0) +\n  (if s2 then 2 else 0) +\n  (if s3 then 4 else 0)\"\n\nsubsubsection {* Switch Encoding *}\n\ndefinition \"STRAIGHT == False\"\ndefinition \"DIVERGING == True\"\n\nfun switches :: \"(bool \\<times> bool \\<times> bool \\<times> bool \\<times> bool) \\<Rightarrow> fmi2Integer\" where\n\"switches (sw1, sw2, sw3, sw4, sw5) =\n  (if sw1 then 1 else 0) +\n  (if sw2 then 2 else 0) +\n  (if sw3 then 4 else 0) +\n  (if sw4 then 8 else 0) +\n  (if sw5 then 16 else 0)\"\n\nsubsection {* Model Instantiation *}\n\nsubsubsection {* Railways FMUs *}\n\naxiomatization\n  train1 :: \"FMI2COMP\" and\n  train2 :: \"FMI2COMP\" and\n  merger :: \"FMI2COMP\" and\n  interlocking :: \"FMI2COMP\" where\n  fmus_distinct: \"distinct [train1, train2, merger, interlocking]\" and\n  FMI2COMP_def: \"FMI2COMP = {train1, train2, merger, interlocking}\"\n\noverloading\n  railways_FMUs \\<equiv> \"FMUs :: FMI2COMP list\"\nbegin\n  definition railways_FMUs :: \"FMI2COMP list\" where\n  \"railways_FMUs = [train1, train2, merger, interlocking]\"\nend\n\nparagraph {* Proof Support *}\n\nlemma fmu_simps [simp]:\n\"train1 \\<noteq> train2\"\n\"train1 \\<noteq> merger\"\n\"train1 \\<noteq> interlocking\"\n\"train2 \\<noteq> train1\"\n\"train2 \\<noteq> merger\"\n\"train2 \\<noteq> interlocking\"\n\"merger \\<noteq> train1\"\n\"merger \\<noteq> train2\"\n\"merger \\<noteq> interlocking\"\n\"interlocking \\<noteq> train1\"\n\"interlocking \\<noteq> train2\"\n\"interlocking \\<noteq> merger\"\nusing fmus_distinct apply (auto)\ndone\n\nsubsubsection {* Parameters *}\n\noverloading\n  railways_parameters \\<equiv> \"parameters :: (FMI2COMP \\<times> VAR \\<times> VAL) list\"\nbegin\n  definition railways_parameters :: \"(FMI2COMP \\<times> VAR \\<times> VAL) list\" where\n  \"railways_parameters = [\n    (train1, $max_speed:{fmi2Real}\\<^sub>u, InjU (4.16::real)),\n    (train2, $max_speed:{fmi2Real}\\<^sub>u, InjU (4.16::real)),\n    (train1, $fixed_route:{fmi2Integer}\\<^sub>u, InjU V1Q2),\n    (train2, $fixed_route:{fmi2Integer}\\<^sub>u, InjU Q3V2)]\"\nend\n\nsubsubsection {* Inputs and Outputs *}\n\noverloading\n  railways_inputs \\<equiv> \"inputs :: PORT list\"\nbegin\n  definition railways_inputs :: \"PORT list\" where\n  \"railways_inputs = [\n    (train1, $signals:{fmi2Integer}\\<^sub>u),\n    (train1, $switches:{fmi2Integer}\\<^sub>u),\n    (train2, $signals:{fmi2Integer}\\<^sub>u),\n    (train2, $switches:{fmi2Integer}\\<^sub>u),\n    (merger, $track_segment1:{fmi2Integer}\\<^sub>u),\n    (merger, $track_segment2:{fmi2Integer}\\<^sub>u),\n    (merger, $telecommand1:{fmi2Integer}\\<^sub>u),\n    (merger, $telecommand2:{fmi2Integer}\\<^sub>u),\n    (interlocking, $CDV:{fmi2Integer}\\<^sub>u),\n    (interlocking, $TC:{fmi2Integer}\\<^sub>u)]\"\nend\n\noverloading\n  railways_outputs \\<equiv> \"outputs :: PORT list\"\nbegin\n  definition railways_outputs :: \"PORT list\" where\n  \"railways_outputs = [\n    (train1, $track_segment:{fmi2Integer}\\<^sub>u),\n    (train1, $telecommand:{fmi2Integer}\\<^sub>u),\n    (train2, $track_segment:{fmi2Integer}\\<^sub>u),\n    (train2, $telecommand:{fmi2Integer}\\<^sub>u),\n    (merger, $CDV:{fmi2Integer}\\<^sub>u),\n    (merger, $TC:{fmi2Integer}\\<^sub>u),\n    (merger, $collision:{fmi2Boolean}\\<^sub>u),\n    (merger, $derailment:{fmi2Boolean}\\<^sub>u),\n    (interlocking, $signals:{fmi2Integer}\\<^sub>u),\n    (interlocking, $switches:{fmi2Integer}\\<^sub>u)]\"\nend\n\nsubsubsection {* Initial Values *}\n\ntext {* The following constants have to be defined as appropriate. *}\n\ndefinition \"initialSignals = InjU (signals (RED, RED, RED))\"\ndefinition \"initialSwitches =\n  InjU (switches (STRAIGHT, STRAIGHT, STRAIGHT, STRAIGHT, STRAIGHT))\"\ndefinition \"initialTrack1 = InjU CDV3\"\ndefinition \"initialTrack2 = InjU CDV2\"\n\noverloading\n  railways_initialValues \\<equiv> \"initialValues :: (PORT \\<times> VAL) list\"\nbegin\n  definition railways_initialValues :: \"(PORT \\<times> VAL) list\" where\n  \"railways_initialValues = [\n    ((train1, $signals:{fmi2Integer}\\<^sub>u), initialSignals),\n    ((train1, $switches:{fmi2Integer}\\<^sub>u), initialSwitches),\n    ((train2, $signals:{fmi2Integer}\\<^sub>u), initialSignals),\n    ((train2, $switches:{fmi2Integer}\\<^sub>u), initialSwitches),\n    ((merger, $track_segment1:{fmi2Integer}\\<^sub>u), initialTrack1),\n    ((merger, $track_segment2:{fmi2Integer}\\<^sub>u), initialTrack2),\n    ((merger, $telecommand1:{fmi2Integer}\\<^sub>u), undefined),\n    ((merger, $telecommand2:{fmi2Integer}\\<^sub>u), undefined),\n    ((interlocking, $CDV:{fmi2Integer}\\<^sub>u), undefined),\n    ((interlocking, $TC:{fmi2Integer}\\<^sub>u), undefined)]\"\nend\n\nsubsubsection {* Port Dependency Graph (\\<open>pdg\\<close>) *}\n\ndefinition pdg :: \"(PORT \\<times> PORT) list\" where\n\"pdg = [\n  ((train1, $track_segment:{fmi2Integer}\\<^sub>u), (merger, $track_segment1:{fmi2Integer}\\<^sub>u)),\n  ((train2, $track_segment:{fmi2Integer}\\<^sub>u), (merger, $track_segment2:{fmi2Integer}\\<^sub>u)),\n  ((train1, $telecommand:{fmi2Integer}\\<^sub>u), (merger, $telecommand1:{fmi2Integer}\\<^sub>u)),\n  ((train2, $telecommand:{fmi2Integer}\\<^sub>u), (merger, $telecommand2:{fmi2Integer}\\<^sub>u)),\n  ((merger, $CDV:{fmi2Integer}\\<^sub>u), (interlocking, $CDV:{fmi2Integer}\\<^sub>u)),\n  ((merger, $TC:{fmi2Integer}\\<^sub>u), (interlocking, $TC:{fmi2Integer}\\<^sub>u)),\n  ((interlocking, $signals:{fmi2Integer}\\<^sub>u), (train1, $signals:{fmi2Integer}\\<^sub>u)),\n  ((interlocking, $signals:{fmi2Integer}\\<^sub>u), (train2, $signals:{fmi2Integer}\\<^sub>u)),\n  ((interlocking, $switches:{fmi2Integer}\\<^sub>u), (train1, $switches:{fmi2Integer}\\<^sub>u)),\n  ((interlocking, $switches:{fmi2Integer}\\<^sub>u), (train2, $switches:{fmi2Integer}\\<^sub>u))\n]\"\n\nsubsubsection {* Internal Direct Dependencies (\\<open>idd\\<close>) *}\n\ndefinition idd :: \"(PORT \\<times> PORT) list\" where\n\"idd = [\n  ((merger, $track_segment1:{fmi2Integer}\\<^sub>u), (merger, $CDV:{fmi2Integer}\\<^sub>u)),\n  ((merger, $track_segment2:{fmi2Integer}\\<^sub>u), (merger, $CDV:{fmi2Integer}\\<^sub>u)),\n  ((merger, $telecommand1:{fmi2Integer}\\<^sub>u), (merger, $TC:{fmi2Integer}\\<^sub>u)),\n  ((merger, $telecommand2:{fmi2Integer}\\<^sub>u), (merger, $TC:{fmi2Integer}\\<^sub>u)),\n  ((interlocking, $CDV:{fmi2Integer}\\<^sub>u), (interlocking, $signals:{fmi2Integer}\\<^sub>u)),\n  ((interlocking, $CDV:{fmi2Integer}\\<^sub>u), (interlocking, $switches:{fmi2Integer}\\<^sub>u)),\n  ((interlocking, $TC:{fmi2Integer}\\<^sub>u), (interlocking, $signals:{fmi2Integer}\\<^sub>u)),\n  ((interlocking, $TC:{fmi2Integer}\\<^sub>u), (interlocking, $switches:{fmi2Integer}\\<^sub>u))\n]\"\nend", "meta": {"author": "isabelle-utp", "repo": "utp-main", "sha": "27bdf3aee6d4fc00c8fe4d53283d0101857e0d41", "save_path": "github-repos/isabelle/isabelle-utp-utp-main", "path": "github-repos/isabelle/isabelle-utp-utp-main/utp-main-27bdf3aee6d4fc00c8fe4d53283d0101857e0d41/fmi/Architecture_D2_3c.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.640635854839898, "lm_q2_score": 0.4148988457967689, "lm_q1q2_score": 0.2657990767491001}}
{"text": "(*  Title:      HOL/Auth/n_germanish_lemma_inv__3_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_germanish Protocol Case Study*} \n\ntheory n_germanish_lemma_inv__3_on_rules imports n_germanish_lemma_on_inv__3\nbegin\nsection{*All lemmas on causal relation between inv__3*}\nlemma lemma_inv__3_on_rules:\n  assumes b1: \"r \\<in> rules N\" and b2: \"(\\<exists> p__Inv0 p__Inv2. p__Inv0\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv0~=p__Inv2\\<and>f=inv__3  p__Inv0 p__Inv2)\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have c1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t1  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_t2  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_t3  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_t4  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_t5  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_t6 N i)\"\n  apply (cut_tac b1, auto) done\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t1  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_t1Vsinv__3) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t2  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_t2Vsinv__3) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t3  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_t3Vsinv__3) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t4  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_t4Vsinv__3) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t5  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_t5Vsinv__3) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_t6 N i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_t6Vsinv__3) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "paraVerifier", "repo": "paraVerifier", "sha": "5de62b433a160bf8d714e0a5085a38b9dd8899f0", "save_path": "github-repos/isabelle/paraVerifier-paraVerifier", "path": "github-repos/isabelle/paraVerifier-paraVerifier/paraVerifier-5de62b433a160bf8d714e0a5085a38b9dd8899f0/proof_scripts/germanish/n_germanish_lemma_inv__3_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6406358411176238, "lm_q2_score": 0.41489884579676883, "lm_q1q2_score": 0.2657990710557443}}
{"text": "section \\<open>Arrays with Dynamic Resizing\\<close>\ntheory Dynamic_Array\nimports \"Refine_Imperative_HOL.IICF_List\" \"Separation_Logic_Imperative_HOL.Array_Blit\" \"Refine_Imperative_HOL.IICF_Array\" \"Refine_Imperative_HOL.IICF_Map\"\nbegin\n\n(* TODO: Move to Array_Blit *)\ndefinition \"array_grow' a n x \\<equiv> do {\n  l\\<leftarrow>Array.len a;\n  a'\\<leftarrow>Array.new (l+n) x;\n  blit a 0 a' 0 l;\n  return a'\n}\"\n\nlemma array_grow'_rule[sep_heap_rules]:\n  shows \"\n    < a\\<mapsto>\\<^sub>ala > \n      array_grow' a n x \n    <\\<lambda>a'. a'\\<mapsto>\\<^sub>a (la @ replicate n x)>\\<^sub>t\"\n  unfolding array_grow'_def\n  by sep_auto\n\n(* TODO: Move to IICF_List *)\nsepref_decl_op list_grow: \n  \"\\<lambda>xs n x. xs@replicate n x\" :: \"\\<langle>A\\<rangle>list_rel \\<rightarrow> nat_rel \\<rightarrow> A \\<rightarrow> \\<langle>A\\<rangle>list_rel\" .\n\n\ndefinition \"nff_\\<alpha> dflt l i \\<equiv> if i<length l then l!i else dflt\"\ndefinition \"is_nff dflt f a \\<equiv> \\<exists>\\<^sub>Al. a \\<mapsto>\\<^sub>a l * \\<up>(f = nff_\\<alpha> dflt l)\"\n\ndefinition [code_unfold]: \"dyn_array_new_sz dflt n \\<equiv> Array.new n dflt\"\n\nlemma dyn_array_new_sz_rl[sep_heap_rules]: \n  \"<emp> dyn_array_new_sz dflt n <\\<lambda>r. is_nff dflt (\\<lambda>_. dflt) r>\"\n  unfolding dyn_array_new_sz_def is_nff_def nff_\\<alpha>_def\n  by sep_auto\n\ndefinition \"array_get_dyn dflt a i \\<equiv> do {\n  \\<^cancel>\\<open>\\<open>nth_oo dflt a i\\<close>\\<close>\n  l \\<leftarrow> Array.len a;\n  if i<l then Array.nth a i else return dflt\n  }\"\n\nlemma array_get_dyn_rule[sep_heap_rules]: \"\n  < is_nff dflt f a > \n    array_get_dyn dflt a i \n  < \\<lambda>r. is_nff dflt f a * \\<up>(r = f i) >\"\n  unfolding array_get_dyn_def nth_oo_def\n  by (sep_auto simp: nff_\\<alpha>_def is_nff_def)\n\ndefinition \"array_set_dyn dflt a i v \\<equiv> do {\n  l \\<leftarrow> Array.len a;\n  if i<l then \n    Array.upd i v a \n  else do {\n    let ns = max (2*l) (i+1);\n    a \\<leftarrow> array_grow a ns dflt;\n    Array.upd i v a\n  }\n}\"\n\nlemma nff_\\<alpha>_upd: \"\\<lbrakk>i < length l\\<rbrakk> \\<Longrightarrow> nff_\\<alpha> dflt (l[i := v]) = (nff_\\<alpha> dflt l)(i := v)\"\n  by (auto simp: nff_\\<alpha>_def)\n\n\n\nlemma array_set_dyn_rule[sep_heap_rules]: \"\n  < is_nff dflt f a >\n    array_set_dyn dflt a i v\n  <\\<lambda>r. is_nff dflt (f(i:=v)) r >\\<^sub>t  \n  \"\n  unfolding array_set_dyn_def is_nff_def upd_oo_def\n  by (sep_auto simp: nff_\\<alpha>_upd nff_\\<alpha>_append_default)\n\nend\n\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/VerifyThis2018/lib/Dynamic_Array.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.523420348936324, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.26579906319502644}}
{"text": "section \\<open>Lemmas concerning paths to instantiate locale Postdomination\\<close>\n\ntheory ValidPaths imports WellFormed \"../StaticInter/Postdomination\" begin\n\nsubsection \\<open>Intraprocedural paths from method entry and to method exit\\<close>\n\n\nabbreviation path :: \"wf_prog \\<Rightarrow> node \\<Rightarrow> edge list \\<Rightarrow> node \\<Rightarrow> bool\" (\"_ \\<turnstile> _ -_\\<rightarrow>* _\")\n  where \"wfp \\<turnstile> n -as\\<rightarrow>* n' \\<equiv> CFG.path sourcenode targetnode (valid_edge wfp) n as n'\"\n\ndefinition label_incrs :: \"edge list \\<Rightarrow> nat \\<Rightarrow> edge list\" (\"_ \\<oplus>s _\" 60)\n  where \"as \\<oplus>s i \\<equiv> map (\\<lambda>((p,n),et,(p',n')). ((p,n \\<oplus> i),et,(p',n' \\<oplus> i))) as\"\n\n\ndeclare One_nat_def [simp del]\n\n\n\nsubsubsection \\<open>From \\<open>prog\\<close> to \\<open>prog;;c\\<^sub>2\\<close>\\<close>\n\n\nlemma Proc_CFG_edge_SeqFirst_nodes_Label:\n  \"prog \\<turnstile> Label l -et\\<rightarrow>\\<^sub>p Label l' \\<Longrightarrow> prog;;c\\<^sub>2 \\<turnstile> Label l -et\\<rightarrow>\\<^sub>p Label l'\"\nproof(induct prog \"Label l\" et \"Label l'\" rule:Proc_CFG.induct)\n  case (Proc_CFG_SeqSecond c\\<^sub>2' n et n' c\\<^sub>1)\n  hence \"(c\\<^sub>1;; c\\<^sub>2');; c\\<^sub>2 \\<turnstile> n \\<oplus> #:c\\<^sub>1 -et\\<rightarrow>\\<^sub>p n' \\<oplus> #:c\\<^sub>1\"\n    by(fastforce intro:Proc_CFG_SeqFirst Proc_CFG.Proc_CFG_SeqSecond)\n  with \\<open>n \\<oplus> #:c\\<^sub>1 = Label l\\<close> \\<open>n' \\<oplus> #:c\\<^sub>1 = Label l'\\<close> show ?case by fastforce\nnext\n  case (Proc_CFG_CondThen c\\<^sub>1 n et n' b c\\<^sub>2')\n  hence \"if (b) c\\<^sub>1 else c\\<^sub>2';; c\\<^sub>2 \\<turnstile> n \\<oplus> 1 -et\\<rightarrow>\\<^sub>p n' \\<oplus> 1\"\n    by(fastforce intro:Proc_CFG_SeqFirst Proc_CFG.Proc_CFG_CondThen)\n  with \\<open>n \\<oplus> 1 = Label l\\<close> \\<open>n' \\<oplus> 1 = Label l'\\<close> show ?case by fastforce\nnext\n  case (Proc_CFG_CondElse c\\<^sub>1 n et n' b c\\<^sub>2')\n  hence \"if (b) c\\<^sub>2' else c\\<^sub>1 ;; c\\<^sub>2 \\<turnstile> n \\<oplus> #:c\\<^sub>2' + 1 -et\\<rightarrow>\\<^sub>p n' \\<oplus> (#:c\\<^sub>2' + 1)\"   \n    by(fastforce intro:Proc_CFG_SeqFirst Proc_CFG.Proc_CFG_CondElse)\n  with \\<open>n \\<oplus> #:c\\<^sub>2' + 1 = Label l\\<close> \\<open>n' \\<oplus> #:c\\<^sub>2' + 1 = Label l'\\<close> show ?case by fastforce\nnext\n  case (Proc_CFG_WhileBody c' n et n' b)\n  hence \"while (b) c';; c\\<^sub>2 \\<turnstile> n \\<oplus> 2 -et\\<rightarrow>\\<^sub>p n' \\<oplus> 2\"\n    by(fastforce intro:Proc_CFG_SeqFirst Proc_CFG.Proc_CFG_WhileBody)\n  with \\<open>n \\<oplus> 2 = Label l\\<close> \\<open>n' \\<oplus> 2 = Label l'\\<close> show ?case by fastforce\nnext\n  case (Proc_CFG_WhileBodyExit c' n et b)\n  hence \"while (b) c';; c\\<^sub>2 \\<turnstile> n \\<oplus> 2 -et\\<rightarrow>\\<^sub>p Label 0\"\n    by(fastforce intro:Proc_CFG_SeqFirst Proc_CFG.Proc_CFG_WhileBodyExit)\n  with \\<open>n \\<oplus> 2 = Label l\\<close> \\<open>0 = l'\\<close> show ?case by fastforce\nqed (auto intro:Proc_CFG.intros)\n\n\nlemma Proc_CFG_edge_SeqFirst_source_Label:\n  assumes \"prog \\<turnstile> Label l -et\\<rightarrow>\\<^sub>p n'\"\n  obtains nx where \"prog;;c\\<^sub>2 \\<turnstile> Label l -et\\<rightarrow>\\<^sub>p nx\"\nproof(atomize_elim)\n  from \\<open>prog \\<turnstile> Label l -et\\<rightarrow>\\<^sub>p n'\\<close> obtain n where \"prog \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'\" and \"Label l = n\"\n    by simp\n  thus \"\\<exists>nx. prog;;c\\<^sub>2 \\<turnstile> Label l -et\\<rightarrow>\\<^sub>p nx\"\n  proof(induct prog n et n' rule:Proc_CFG.induct)\n    case (Proc_CFG_SeqSecond c\\<^sub>2' n et n' c\\<^sub>1)\n    show ?case\n    proof(cases \"n' = Exit\")\n      case True\n      with \\<open>c\\<^sub>2' \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'\\<close> \\<open>n \\<noteq> Entry\\<close> have \"c\\<^sub>1;; c\\<^sub>2' \\<turnstile> n \\<oplus> #:c\\<^sub>1 -et\\<rightarrow>\\<^sub>p Exit \\<oplus> #:c\\<^sub>1\"\n        by(fastforce intro:Proc_CFG.Proc_CFG_SeqSecond)\n      moreover from \\<open>n \\<noteq> Entry\\<close> have \"n \\<oplus> #:c\\<^sub>1 \\<noteq> Entry\" by(cases n) auto\n      ultimately\n      have \"c\\<^sub>1;; c\\<^sub>2';; c\\<^sub>2 \\<turnstile> n \\<oplus> #:c\\<^sub>1 -et\\<rightarrow>\\<^sub>p Label (#:c\\<^sub>1;; c\\<^sub>2')\"\n        by(fastforce intro:Proc_CFG_SeqConnect)\n      with \\<open>Label l = n \\<oplus> #:c\\<^sub>1\\<close> show ?thesis by fastforce\n    next\n      case False\n      with Proc_CFG_SeqSecond\n      have \"(c\\<^sub>1;; c\\<^sub>2');; c\\<^sub>2 \\<turnstile> n \\<oplus> #:c\\<^sub>1 -et\\<rightarrow>\\<^sub>p n' \\<oplus> #:c\\<^sub>1\"\n        by(fastforce intro:Proc_CFG_SeqFirst Proc_CFG.Proc_CFG_SeqSecond)\n      with \\<open>Label l = n \\<oplus> #:c\\<^sub>1\\<close> show ?thesis by fastforce\n    qed\n  next\n    case (Proc_CFG_CondThen c\\<^sub>1 n et n' b c\\<^sub>2')\n    show ?case\n    proof(cases \"n' = Exit\")\n      case True\n      with \\<open>c\\<^sub>1 \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'\\<close> \\<open>n \\<noteq> Entry\\<close>\n      have \"if (b) c\\<^sub>1 else c\\<^sub>2' \\<turnstile> n \\<oplus> 1 -et\\<rightarrow>\\<^sub>p Exit \\<oplus> 1\"\n        by(fastforce intro:Proc_CFG.Proc_CFG_CondThen)\n      moreover from \\<open>n \\<noteq> Entry\\<close> have \"n \\<oplus> 1 \\<noteq> Entry\" by(cases n) auto\n      ultimately\n      have \"if (b) c\\<^sub>1 else c\\<^sub>2';; c\\<^sub>2 \\<turnstile> n \\<oplus> 1 -et\\<rightarrow>\\<^sub>p Label (#:if (b) c\\<^sub>1 else c\\<^sub>2')\"\n        by(fastforce intro:Proc_CFG_SeqConnect)\n      with \\<open>Label l = n \\<oplus> 1\\<close> show ?thesis by fastforce\n    next\n      case False\n      hence \"n' \\<oplus> 1 \\<noteq> Exit\" by(cases n') auto\n      with Proc_CFG_CondThen\n      have  \"if (b) c\\<^sub>1 else c\\<^sub>2';; c\\<^sub>2 \\<turnstile> Label l -et\\<rightarrow>\\<^sub>p n' \\<oplus> 1\"\n        by(fastforce intro:Proc_CFG_SeqFirst Proc_CFG.Proc_CFG_CondThen)\n      with \\<open>Label l = n \\<oplus> 1\\<close> show ?thesis by fastforce\n    qed\n  next\n    case (Proc_CFG_CondElse c\\<^sub>1 n et n' b c\\<^sub>2')\n    show ?case\n    proof(cases \"n' = Exit\")\n      case True\n      with \\<open>c\\<^sub>1 \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'\\<close> \\<open>n \\<noteq> Entry\\<close>\n      have \"if (b) c\\<^sub>2' else c\\<^sub>1 \\<turnstile> n \\<oplus> (#:c\\<^sub>2' + 1) -et\\<rightarrow>\\<^sub>p Exit \\<oplus> (#:c\\<^sub>2' + 1)\"\n        by(fastforce intro:Proc_CFG.Proc_CFG_CondElse)\n      moreover from \\<open>n \\<noteq> Entry\\<close> have \"n \\<oplus> (#:c\\<^sub>2' + 1) \\<noteq> Entry\" by(cases n) auto\n      ultimately\n      have \"if (b) c\\<^sub>2' else c\\<^sub>1;; c\\<^sub>2 \\<turnstile> n \\<oplus> (#:c\\<^sub>2' + 1) -et\\<rightarrow>\\<^sub>p \n        Label (#:if (b) c\\<^sub>2' else c\\<^sub>1)\"\n        by(fastforce intro:Proc_CFG_SeqConnect)\n      with \\<open>Label l = n \\<oplus> (#:c\\<^sub>2' + 1)\\<close> show ?thesis by fastforce\n    next\n      case False\n      hence \"n' \\<oplus> (#:c\\<^sub>2' + 1) \\<noteq> Exit\" by(cases n') auto\n      with Proc_CFG_CondElse\n      have  \"if (b) c\\<^sub>2' else c\\<^sub>1 ;; c\\<^sub>2 \\<turnstile> Label l -et\\<rightarrow>\\<^sub>p n' \\<oplus> (#:c\\<^sub>2' + 1)\"\n        by(fastforce intro:Proc_CFG_SeqFirst Proc_CFG.Proc_CFG_CondElse)\n      with \\<open>Label l = n \\<oplus> (#:c\\<^sub>2' + 1)\\<close> show ?thesis by fastforce\n    qed\n  qed (auto intro:Proc_CFG.intros)\nqed\n\n\nlemma Proc_CFG_edge_SeqFirst_target_Label:\n  \"\\<lbrakk>prog \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'; Label l' = n'\\<rbrakk> \\<Longrightarrow> prog;;c\\<^sub>2 \\<turnstile> n -et\\<rightarrow>\\<^sub>p Label l'\"\nproof(induct prog n et n' rule:Proc_CFG.induct)\n  case (Proc_CFG_SeqSecond c\\<^sub>2' n et n' c\\<^sub>1)\n  from \\<open>Label l' = n' \\<oplus> #:c\\<^sub>1\\<close> have \"n' \\<noteq> Exit\" by(cases n') auto\n  with Proc_CFG_SeqSecond\n  show ?case by(fastforce intro:Proc_CFG_SeqFirst intro:Proc_CFG.Proc_CFG_SeqSecond)\nnext\n  case (Proc_CFG_CondThen c\\<^sub>1 n et n' b c\\<^sub>2')\n  from \\<open>Label l' = n' \\<oplus> 1\\<close> have \"n' \\<noteq> Exit\" by(cases n') auto\n  with Proc_CFG_CondThen\n  show ?case by(fastforce intro:Proc_CFG_SeqFirst Proc_CFG.Proc_CFG_CondThen)\nqed (auto intro:Proc_CFG.intros)\n\n\nlemma PCFG_edge_SeqFirst_source_Label:\n  assumes \"prog,procs \\<turnstile> (p,Label l) -et\\<rightarrow> (p',n')\"\n  obtains nx where \"prog;;c\\<^sub>2,procs \\<turnstile> (p,Label l) -et\\<rightarrow> (p',nx)\"\nproof(atomize_elim)\n  from \\<open>prog,procs \\<turnstile> (p,Label l) -et\\<rightarrow> (p',n')\\<close>\n  show \"\\<exists>nx. prog;;c\\<^sub>2,procs \\<turnstile> (p,Label l) -et\\<rightarrow> (p',nx)\"\n  proof(induct \"(p,Label l)\" et \"(p',n')\" rule:PCFG.induct)\n    case (Main et)\n    from \\<open>prog \\<turnstile> Label l -IEdge et\\<rightarrow>\\<^sub>p n'\\<close>\n    obtain nx' where \"prog;;c\\<^sub>2 \\<turnstile> Label l -IEdge et\\<rightarrow>\\<^sub>p nx'\"\n      by(auto elim:Proc_CFG_edge_SeqFirst_source_Label)\n    with \\<open>Main = p\\<close> \\<open>Main = p'\\<close> show ?case \n      by(fastforce dest:PCFG.Main)\n  next\n    case (Proc ins outs c et ps)\n    from \\<open>containsCall procs prog ps p\\<close>\n    have \"containsCall procs (prog;;c\\<^sub>2) ps p\" by simp\n    with Proc show ?case by(fastforce dest:PCFG.Proc)\n  next\n    case (MainCall es rets nx ins outs c)\n    from \\<open>prog \\<turnstile> Label l -CEdge (p', es, rets)\\<rightarrow>\\<^sub>p nx\\<close>\n    obtain lx where [simp]:\"nx = Label lx\" by(fastforce dest:Proc_CFG_Call_Labels)\n    with \\<open>prog \\<turnstile> Label l -CEdge (p', es, rets)\\<rightarrow>\\<^sub>p nx\\<close>\n    have \"prog;;c\\<^sub>2 \\<turnstile> Label l -CEdge (p', es, rets)\\<rightarrow>\\<^sub>p Label lx\"\n      by(auto intro:Proc_CFG_edge_SeqFirst_nodes_Label)\n    with MainCall show ?case by(fastforce dest:PCFG.MainCall)\n  next\n    case (ProcCall ins outs c es' rets' l' ins' outs' c' ps)\n    from \\<open>containsCall procs prog ps p\\<close> \n    have \"containsCall procs (prog;;c\\<^sub>2) ps p\" by simp\n    with ProcCall show ?case by(fastforce intro:PCFG.ProcCall)\n  next\n    case (MainCallReturn px es rets)\n    from \\<open>prog \\<turnstile> Label l -CEdge (px, es, rets)\\<rightarrow>\\<^sub>p n'\\<close> \\<open>Main = p\\<close>\n    obtain nx'' where \"prog;;c\\<^sub>2 \\<turnstile> Label l -CEdge (px, es, rets)\\<rightarrow>\\<^sub>p nx''\"\n      by(auto elim:Proc_CFG_edge_SeqFirst_source_Label)\n    with MainCallReturn show ?case by(fastforce dest:PCFG.MainCallReturn)\n  next\n    case (ProcCallReturn ins outs c px' es' rets' ps)\n    from \\<open>containsCall procs prog ps p\\<close>\n    have \"containsCall procs (prog;;c\\<^sub>2) ps p\" by simp\n    with ProcCallReturn show ?case by(fastforce dest!:PCFG.ProcCallReturn)\n  qed\nqed\n\n\nlemma PCFG_edge_SeqFirst_target_Label:\n  \"prog,procs \\<turnstile> (p,n) -et\\<rightarrow> (p',Label l') \n  \\<Longrightarrow> prog;;c\\<^sub>2,procs \\<turnstile> (p,n) -et\\<rightarrow> (p',Label l')\"\nproof(induct \"(p,n)\" et \"(p',Label l')\" rule:PCFG.induct)\n  case Main\n  thus ?case by(fastforce dest:Proc_CFG_edge_SeqFirst_target_Label intro:PCFG.Main)\nnext\n  case (Proc ins outs c et ps)\n  from \\<open>containsCall procs prog ps p\\<close> \n  have \"containsCall procs (prog;;c\\<^sub>2) ps p\" by simp\n  with Proc show ?case by(fastforce dest:PCFG.Proc)\nnext\n  case MainReturn thus ?case\n    by(fastforce dest:Proc_CFG_edge_SeqFirst_target_Label \n               intro!:PCFG.MainReturn[simplified])\nnext\n  case (ProcReturn ins outs c lx es' rets' ins' outs' c' ps)\n  from \\<open>containsCall procs prog ps p'\\<close> \n  have \"containsCall procs (prog;;c\\<^sub>2) ps p'\" by simp\n  with ProcReturn show ?case by(fastforce intro:PCFG.ProcReturn)\nnext\n  case MainCallReturn thus ?case\n  by(fastforce dest:Proc_CFG_edge_SeqFirst_target_Label intro:PCFG.MainCallReturn)\nnext\n  case (ProcCallReturn ins outs c px' es' rets' ps)\n  from \\<open>containsCall procs prog ps p\\<close> \n  have \"containsCall procs (prog;;c\\<^sub>2) ps p\" by simp\n  with ProcCallReturn show ?case by(fastforce dest!:PCFG.ProcCallReturn)\nqed\n\n\nlemma path_SeqFirst:\n  assumes \"Rep_wf_prog wfp = (prog,procs)\" and \"Rep_wf_prog wfp' = (prog;;c\\<^sub>2,procs)\"\n  shows \"\\<lbrakk>wfp \\<turnstile> (p,n) -as\\<rightarrow>* (p,Label l); \\<forall>a \\<in> set as. intra_kind (kind a)\\<rbrakk>\n  \\<Longrightarrow> wfp' \\<turnstile> (p,n) -as\\<rightarrow>* (p,Label l)\"\nproof(induct \"(p,n)\" as \"(p,Label l)\" arbitrary:n rule:ProcCFG.path.induct)\n  case empty_path\n  from \\<open>CFG.valid_node sourcenode targetnode (valid_edge wfp) (p, Label l)\\<close> \n    \\<open>Rep_wf_prog wfp = (prog, procs)\\<close> \\<open>Rep_wf_prog wfp' = (prog;; c\\<^sub>2, procs)\\<close>\n  have \"CFG.valid_node sourcenode targetnode (valid_edge wfp') (p, Label l)\"\n    apply(auto simp:ProcCFG.valid_node_def valid_edge_def)\n    apply(erule PCFG_edge_SeqFirst_source_Label,fastforce)\n    by(drule PCFG_edge_SeqFirst_target_Label,fastforce)\n  thus ?case by(fastforce intro:ProcCFG.empty_path)\nnext\n  case (Cons_path n'' as a nx)\n  note IH = \\<open>\\<And>n. \\<lbrakk>n'' = (p, n); \\<forall>a\\<in>set as. intra_kind (kind a)\\<rbrakk>\n    \\<Longrightarrow> wfp' \\<turnstile> (p, n) -as\\<rightarrow>* (p, Label l)\\<close>\n  note [simp] = \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \\<open>Rep_wf_prog wfp' = (prog;;c\\<^sub>2,procs)\\<close>\n  from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> have wf:\"well_formed procs\" \n    by(fastforce intro:wf_wf_prog)\n  from \\<open>\\<forall>a\\<in>set (a # as). intra_kind (kind a)\\<close> have \"intra_kind (kind a)\"\n    and \"\\<forall>a\\<in>set as. intra_kind (kind a)\" by simp_all\n  from \\<open>valid_edge wfp a\\<close> \\<open>sourcenode a = (p, nx)\\<close> \\<open>targetnode a = n''\\<close>\n    \\<open>intra_kind (kind a)\\<close> wf \n  obtain nx' where \"n'' = (p,nx')\"\n    by(auto elim:PCFG.cases simp:valid_edge_def intra_kind_def)\n  from IH[OF this \\<open>\\<forall>a\\<in>set as. intra_kind (kind a)\\<close>]\n  have path:\"wfp' \\<turnstile> (p, nx') -as\\<rightarrow>* (p, Label l)\" .\n  have \"valid_edge wfp' a\"\n  proof(cases nx')\n    case (Label lx)\n    with \\<open>valid_edge wfp a\\<close> \\<open>sourcenode a = (p, nx)\\<close> \\<open>targetnode a = n''\\<close>\n      \\<open>n'' = (p,nx')\\<close> show ?thesis\n      by(fastforce intro:PCFG_edge_SeqFirst_target_Label \n                   simp:intra_kind_def valid_edge_def)\n  next\n    case Entry\n    with \\<open>valid_edge wfp a\\<close> \\<open>targetnode a = n''\\<close> \\<open>n'' = (p,nx')\\<close>\n      \\<open>intra_kind (kind a)\\<close> have False \n      by(auto elim:PCFG.cases simp:valid_edge_def intra_kind_def)\n    thus ?thesis by simp\n  next\n    case Exit\n    with path \\<open>\\<forall>a\\<in>set as. intra_kind (kind a)\\<close> have False \n      by(induct \"(p,nx')\" as \"(p,Label l)\" rule:ProcCFG.path.induct)\n    (auto elim!:PCFG.cases simp:valid_edge_def intra_kind_def)\n    thus ?thesis by simp\n  qed\n  with \\<open>sourcenode a = (p, nx)\\<close> \\<open>targetnode a = n''\\<close> \\<open>n'' = (p,nx')\\<close> path\n  show ?case by(fastforce intro:ProcCFG.Cons_path)\nqed\n\n\nsubsubsection \\<open>From \\<open>prog\\<close> to \\<open>c\\<^sub>1;;prog\\<close>\\<close>\n\nlemma Proc_CFG_edge_SeqSecond_source_not_Entry:\n  \"\\<lbrakk>prog \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'; n \\<noteq> Entry\\<rbrakk> \\<Longrightarrow> c\\<^sub>1;;prog \\<turnstile> n \\<oplus> #:c\\<^sub>1 -et\\<rightarrow>\\<^sub>p n' \\<oplus> #:c\\<^sub>1\"\nby(induct rule:Proc_CFG.induct)(fastforce intro:Proc_CFG_SeqSecond Proc_CFG.intros)+\n\n\nlemma PCFG_Main_edge_SeqSecond_source_not_Entry:\n  \"\\<lbrakk>prog,procs \\<turnstile> (Main,n) -et\\<rightarrow> (p',n'); n \\<noteq> Entry; intra_kind et; well_formed procs\\<rbrakk>\n  \\<Longrightarrow> c\\<^sub>1;;prog,procs \\<turnstile> (Main,n \\<oplus> #:c\\<^sub>1) -et\\<rightarrow> (p',n' \\<oplus> #:c\\<^sub>1)\"\nproof(induct \"(Main,n)\" et \"(p',n')\" rule:PCFG.induct)\n  case Main\n  thus ?case\n    by(fastforce dest:Proc_CFG_edge_SeqSecond_source_not_Entry intro:PCFG.Main)\nnext\n  case (MainCallReturn p es rets)\n  from \\<open>prog \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n'\\<close> \\<open>n \\<noteq> Entry\\<close>\n  have \"c\\<^sub>1;;prog \\<turnstile> n \\<oplus> #:c\\<^sub>1 -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n' \\<oplus> #:c\\<^sub>1\"\n    by(rule Proc_CFG_edge_SeqSecond_source_not_Entry)\n  with MainCallReturn show ?case by(fastforce intro:PCFG.MainCallReturn)\nqed (auto simp:intra_kind_def)\n\n\nlemma valid_node_Main_SeqSecond:\n  assumes \"CFG.valid_node sourcenode targetnode (valid_edge wfp) (Main,n)\"\n  and \"n \\<noteq> Entry\" and \"Rep_wf_prog wfp = (prog,procs)\" \n  and \"Rep_wf_prog wfp' = (c\\<^sub>1;;prog,procs)\"\n  shows \"CFG.valid_node sourcenode targetnode (valid_edge wfp') (Main, n \\<oplus> #:c\\<^sub>1)\"\nproof -\n  note [simp] = \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \\<open>Rep_wf_prog wfp' = (c\\<^sub>1;;prog,procs)\\<close>\n  from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> have wf:\"well_formed procs\" \n    by(fastforce intro:wf_wf_prog)\n  from \\<open>CFG.valid_node sourcenode targetnode (valid_edge wfp) (Main,n)\\<close>\n  obtain a where \"prog,procs \\<turnstile> sourcenode a -kind a\\<rightarrow> targetnode a\"\n    and \"(Main,n) = sourcenode a \\<or> (Main,n) = targetnode a\"\n    by(fastforce simp:ProcCFG.valid_node_def valid_edge_def)\n  from this \\<open>n \\<noteq> Entry\\<close> wf show ?thesis\n  proof(induct \"sourcenode a\" \"kind a\" \"targetnode a\" rule:PCFG.induct)\n    case (Main nx nx')\n    from \\<open>(Main,n) = sourcenode a \\<or> (Main,n) = targetnode a\\<close> show ?case\n    proof\n      assume \"(Main,n) = sourcenode a\"\n      with \\<open>(Main, nx) = sourcenode a\\<close>[THEN sym] have [simp]:\"nx = n\" by simp\n      from \\<open>n \\<noteq> Entry\\<close> \\<open>prog \\<turnstile> nx -IEdge (kind a)\\<rightarrow>\\<^sub>p nx'\\<close>\n      have \"c\\<^sub>1;;prog \\<turnstile> n \\<oplus> #:c\\<^sub>1 -IEdge (kind a)\\<rightarrow>\\<^sub>p nx' \\<oplus> #:c\\<^sub>1\"\n        by(fastforce intro:Proc_CFG_edge_SeqSecond_source_not_Entry)\n      hence \"c\\<^sub>1;;prog,procs \\<turnstile> (Main,n \\<oplus> #:c\\<^sub>1) -kind a\\<rightarrow> (Main,nx' \\<oplus> #:c\\<^sub>1)\"\n        by(rule PCFG.Main)\n      thus ?thesis by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n    next\n      assume \"(Main, n) = targetnode a\"\n      show ?thesis\n      proof(cases \"nx = Entry\")\n        case True\n        with \\<open>prog \\<turnstile> nx -IEdge (kind a)\\<rightarrow>\\<^sub>p nx'\\<close> \n        have \"nx' = Exit \\<or> nx' = Label 0\" by(fastforce dest:Proc_CFG_EntryD)\n        thus ?thesis\n        proof\n          assume \"nx' = Exit\"\n          with \\<open>(Main, n) = targetnode a\\<close> \\<open>(Main, nx') = targetnode a\\<close>[THEN sym]\n          show ?thesis by simp\n        next\n          assume \"nx' = Label 0\"\n          obtain l etx where \"c\\<^sub>1 \\<turnstile> Label l -IEdge etx\\<rightarrow>\\<^sub>p Exit\" and \"l \\<le> #:c\\<^sub>1\"\n            by(erule Proc_CFG_Exit_edge)\n          hence \"c\\<^sub>1;;prog \\<turnstile> Label l -IEdge etx\\<rightarrow>\\<^sub>p Label #:c\\<^sub>1\"\n            by(fastforce intro:Proc_CFG_SeqConnect)\n          with \\<open>nx' = Label 0\\<close> \n          have \"c\\<^sub>1;;prog,procs \\<turnstile> (Main,Label l) -etx\\<rightarrow> (Main,nx'\\<oplus>#:c\\<^sub>1)\"\n            by(fastforce intro:PCFG.Main)\n          with \\<open>(Main, n) = targetnode a\\<close> \\<open>(Main, nx') = targetnode a\\<close>[THEN sym]\n          show ?thesis\n            by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n        qed\n      next\n        case False\n        with \\<open>prog \\<turnstile> nx -IEdge (kind a)\\<rightarrow>\\<^sub>p nx'\\<close>\n        have \"c\\<^sub>1;;prog \\<turnstile> nx \\<oplus> #:c\\<^sub>1 -IEdge (kind a)\\<rightarrow>\\<^sub>p nx' \\<oplus> #:c\\<^sub>1\"\n          by(fastforce intro:Proc_CFG_edge_SeqSecond_source_not_Entry)\n        hence \"c\\<^sub>1;;prog,procs \\<turnstile> (Main,nx \\<oplus> #:c\\<^sub>1) -kind a\\<rightarrow> (Main,nx' \\<oplus> #:c\\<^sub>1)\"\n          by(rule PCFG.Main)\n        with \\<open>(Main, n) = targetnode a\\<close> \\<open>(Main, nx') = targetnode a\\<close>[THEN sym]\n        show ?thesis by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n      qed\n    qed\n  next\n    case (Proc p ins outs c nx n' ps)\n    from \\<open>(p, nx) = sourcenode a\\<close>[THEN sym] \\<open>(p, n') = targetnode a\\<close>[THEN sym]\n      \\<open>(Main, n) = sourcenode a \\<or> (Main, n) = targetnode a\\<close> \n      \\<open>(p, ins, outs, c) \\<in> set procs\\<close> \\<open>well_formed procs\\<close> have False by fastforce\n    thus ?case by simp\n  next\n    case (MainCall l p es rets n' ins outs c)\n    from \\<open>(p, ins, outs, c) \\<in> set procs\\<close> wf \\<open>(p, Entry) = targetnode a\\<close>[THEN sym]\n      \\<open>(Main, Label l) = sourcenode a\\<close>[THEN sym]\n      \\<open>(Main, n) = sourcenode a \\<or> (Main, n) = targetnode a\\<close>\n     have [simp]:\"n = Label l\" by fastforce\n    from \\<open>prog \\<turnstile> Label l -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n'\\<close>\n    have \"c\\<^sub>1;;prog \\<turnstile> Label l \\<oplus> #:c\\<^sub>1 -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n' \\<oplus> #:c\\<^sub>1\"\n      by -(rule Proc_CFG_edge_SeqSecond_source_not_Entry,auto)\n    with \\<open>(p, ins, outs, c) \\<in> set procs\\<close>\n    have \"c\\<^sub>1;;prog,procs \\<turnstile> (Main,Label (l + #:c\\<^sub>1)) \n      -(\\<lambda>s. True):(Main,n' \\<oplus> #:c\\<^sub>1)\\<hookrightarrow>\\<^bsub>p\\<^esub>map (\\<lambda>e cf. interpret e cf) es\\<rightarrow> (p,Entry)\"\n      by(fastforce intro:PCFG.MainCall)\n    thus ?case by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n  next\n    case (ProcCall p ins outs c l p' es' rets' l' ins' outs' c')\n    from \\<open>(p, Label l) = sourcenode a\\<close>[THEN sym]\n      \\<open>(p', Entry) = targetnode a\\<close>[THEN sym]  \\<open>well_formed procs\\<close>\n      \\<open>(p, ins, outs, c) \\<in> set procs\\<close> \\<open>(p', ins', outs', c') \\<in> set procs\\<close>\n      \\<open>(Main, n) = sourcenode a \\<or> (Main, n) = targetnode a\\<close>\n    have False by fastforce\n    thus ?case by simp\n  next\n    case (MainReturn l p es rets l' ins outs c)\n    from \\<open>(p, ins, outs, c) \\<in> set procs\\<close> wf \\<open>(p, Exit) = sourcenode a\\<close>[THEN sym]\n      \\<open>(Main, Label l') = targetnode a\\<close>[THEN sym]\n      \\<open>(Main, n) = sourcenode a \\<or> (Main, n) = targetnode a\\<close>\n    have [simp]:\"n = Label l'\" by fastforce\n    from \\<open>prog \\<turnstile> Label l -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p Label l'\\<close>\n    have \"c\\<^sub>1;;prog \\<turnstile> Label l \\<oplus> #:c\\<^sub>1 -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p Label l' \\<oplus> #:c\\<^sub>1\"\n      by -(rule Proc_CFG_edge_SeqSecond_source_not_Entry,auto)\n    with \\<open>(p, ins, outs, c) \\<in> set procs\\<close>\n    have \"c\\<^sub>1;;prog,procs \\<turnstile> (p,Exit) -(\\<lambda>cf. snd cf = (Main,Label l' \\<oplus> #:c\\<^sub>1))\\<hookleftarrow>\\<^bsub>p\\<^esub>\n      (\\<lambda>cf cf'. cf'(rets [:=] map cf outs))\\<rightarrow> (Main,Label (l' + #:c\\<^sub>1))\"\n      by(fastforce intro:PCFG.MainReturn)\n    thus ?case by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n  next\n    case (ProcReturn p ins outs c l p' es' rets' l' ins' outs' c' ps)\n    from \\<open>(p', Exit) = sourcenode a\\<close>[THEN sym] \n      \\<open>(p, Label l') = targetnode a\\<close>[THEN sym] \\<open>well_formed procs\\<close>\n      \\<open>(p, ins, outs, c) \\<in> set procs\\<close> \\<open>(p', ins', outs', c') \\<in> set procs\\<close>\n      \\<open>(Main, n) = sourcenode a \\<or> (Main, n) = targetnode a\\<close>\n    have False by fastforce\n    thus ?case by simp\n  next\n    case (MainCallReturn nx p es rets nx')\n    from \\<open>(Main,n) = sourcenode a \\<or> (Main,n) = targetnode a\\<close> show ?case\n    proof\n      assume \"(Main,n) = sourcenode a\"\n      with \\<open>(Main, nx) = sourcenode a\\<close>[THEN sym] have [simp]:\"nx = n\" by simp\n      from \\<open>n \\<noteq> Entry\\<close> \\<open>prog \\<turnstile> nx -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p nx'\\<close>\n      have \"c\\<^sub>1;;prog \\<turnstile> n \\<oplus> #:c\\<^sub>1 -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p nx' \\<oplus> #:c\\<^sub>1\"\n        by(fastforce intro:Proc_CFG_edge_SeqSecond_source_not_Entry)\n      hence \"c\\<^sub>1;;prog,procs \\<turnstile> (Main,n \\<oplus> #:c\\<^sub>1) -(\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow> (Main,nx' \\<oplus> #:c\\<^sub>1)\"\n        by -(rule PCFG.MainCallReturn)\n      thus ?thesis by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n    next\n      assume \"(Main, n) = targetnode a\"\n      from \\<open>prog \\<turnstile> nx -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p nx'\\<close>\n      have \"nx \\<noteq> Entry\" by(fastforce dest:Proc_CFG_Call_Labels)\n      with \\<open>prog \\<turnstile> nx -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p nx'\\<close>\n      have \"c\\<^sub>1;;prog \\<turnstile> nx \\<oplus> #:c\\<^sub>1 -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p nx' \\<oplus> #:c\\<^sub>1\"\n        by(fastforce intro:Proc_CFG_edge_SeqSecond_source_not_Entry)\n      hence \"c\\<^sub>1;;prog,procs \\<turnstile> (Main,nx \\<oplus> #:c\\<^sub>1) -(\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow> (Main,nx' \\<oplus> #:c\\<^sub>1)\"\n        by -(rule PCFG.MainCallReturn)\n      with \\<open>(Main, n) = targetnode a\\<close> \\<open>(Main, nx') = targetnode a\\<close>[THEN sym] \n      show ?thesis by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n    qed\n  next\n    case (ProcCallReturn p ins outs c nx p' es' rets' n' ps)\n    from \\<open>(p, nx) = sourcenode a\\<close>[THEN sym] \\<open>(p, n') = targetnode a\\<close>[THEN sym]\n      \\<open>(p, ins, outs, c) \\<in> set procs\\<close> \\<open>well_formed procs\\<close>\n      \\<open>(Main, n) = sourcenode a \\<or> (Main, n) = targetnode a\\<close>\n    have False by fastforce\n    thus ?case by simp\n  qed\nqed\n\n\nlemma path_Main_SeqSecond:\n  assumes \"Rep_wf_prog wfp = (prog,procs)\" and \"Rep_wf_prog wfp' = (c\\<^sub>1;;prog,procs)\"\n  shows \"\\<lbrakk>wfp \\<turnstile> (Main,n) -as\\<rightarrow>* (p',n'); \\<forall>a \\<in> set as. intra_kind (kind a); n \\<noteq> Entry\\<rbrakk>\n  \\<Longrightarrow> wfp' \\<turnstile> (Main,n \\<oplus> #:c\\<^sub>1) -as \\<oplus>s #:c\\<^sub>1\\<rightarrow>* (p',n' \\<oplus> #:c\\<^sub>1)\"\nproof(induct \"(Main,n)\" as \"(p',n')\" arbitrary:n rule:ProcCFG.path.induct)\n  case empty_path\n  from \\<open>CFG.valid_node sourcenode targetnode (valid_edge wfp) (Main, n')\\<close>\n    \\<open>n' \\<noteq> Entry\\<close> \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \n    \\<open>Rep_wf_prog wfp' = (c\\<^sub>1;;prog,procs)\\<close>\n  have \"CFG.valid_node sourcenode targetnode (valid_edge wfp') (Main, n' \\<oplus> #:c\\<^sub>1)\"\n    by(fastforce intro:valid_node_Main_SeqSecond)\n  with \\<open>Main = p'\\<close> show ?case\n    by(fastforce intro:ProcCFG.empty_path simp:label_incrs_def)\nnext\n  case (Cons_path n'' as a n)\n  note IH = \\<open>\\<And>n.  \\<lbrakk>n'' = (Main, n); \\<forall>a\\<in>set as. intra_kind (kind a); n \\<noteq> Entry\\<rbrakk> \n    \\<Longrightarrow> wfp' \\<turnstile> (Main, n \\<oplus> #:c\\<^sub>1) -as \\<oplus>s #:c\\<^sub>1\\<rightarrow>* (p', n' \\<oplus> #:c\\<^sub>1)\\<close>\n  note [simp] = \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \\<open>Rep_wf_prog wfp' = (c\\<^sub>1;;prog,procs)\\<close>\n  from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> have wf:\"well_formed procs\" \n    by(fastforce intro:wf_wf_prog)\n  from \\<open>\\<forall>a\\<in>set (a # as). intra_kind (kind a)\\<close> have \"intra_kind (kind a)\"\n    and \"\\<forall>a\\<in>set as. intra_kind (kind a)\" by simp_all\n  from \\<open>valid_edge wfp a\\<close> \\<open>sourcenode a = (Main, n)\\<close> \\<open>targetnode a = n''\\<close>\n    \\<open>intra_kind (kind a)\\<close> wf \n  obtain nx'' where \"n'' = (Main,nx'')\" and \"nx'' \\<noteq> Entry\"\n    by(auto elim!:PCFG.cases simp:valid_edge_def intra_kind_def)\n  from IH[OF \\<open>n'' = (Main,nx'')\\<close> \\<open>\\<forall>a\\<in>set as. intra_kind (kind a)\\<close> \\<open>nx'' \\<noteq> Entry\\<close>]\n  have path:\"wfp' \\<turnstile> (Main, nx'' \\<oplus> #:c\\<^sub>1) -as \\<oplus>s #:c\\<^sub>1\\<rightarrow>* (p', n' \\<oplus> #:c\\<^sub>1)\" .\n  from \\<open>valid_edge wfp a\\<close> \\<open>sourcenode a = (Main, n)\\<close> \\<open>targetnode a = n''\\<close>\n    \\<open>n'' = (Main,nx'')\\<close> \\<open>n \\<noteq> Entry\\<close> \\<open>intra_kind (kind a)\\<close> wf\n  have \"c\\<^sub>1;; prog,procs \\<turnstile> (Main, n \\<oplus> #:c\\<^sub>1) -kind a\\<rightarrow> (Main, nx'' \\<oplus> #:c\\<^sub>1)\"\n    by(fastforce intro:PCFG_Main_edge_SeqSecond_source_not_Entry simp:valid_edge_def)\n  with path \\<open>sourcenode a = (Main, n)\\<close> \\<open>targetnode a = n''\\<close> \\<open>n'' = (Main,nx'')\\<close>\n  show ?case apply(cases a) apply(clarsimp simp:label_incrs_def)\n    by(auto intro:ProcCFG.Cons_path simp:valid_edge_def)\nqed\n\n\nsubsubsection \\<open>From \\<open>prog\\<close> to \\<open>if (b) prog else c\\<^sub>2\\<close>\\<close>\n\nlemma Proc_CFG_edge_CondTrue_source_not_Entry:\n  \"\\<lbrakk>prog \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'; n \\<noteq> Entry\\<rbrakk> \\<Longrightarrow> if (b) prog else c\\<^sub>2 \\<turnstile> n \\<oplus> 1 -et\\<rightarrow>\\<^sub>p n' \\<oplus> 1\"\nby(induct rule:Proc_CFG.induct)(fastforce intro:Proc_CFG_CondThen Proc_CFG.intros)+\n\n\nlemma PCFG_Main_edge_CondTrue_source_not_Entry:\n  \"\\<lbrakk>prog,procs \\<turnstile> (Main,n) -et\\<rightarrow> (p',n'); n \\<noteq> Entry; intra_kind et; well_formed procs\\<rbrakk>\n  \\<Longrightarrow> if (b) prog else c\\<^sub>2,procs \\<turnstile> (Main,n \\<oplus> 1) -et\\<rightarrow> (p',n' \\<oplus> 1)\"\nproof(induct \"(Main,n)\" et \"(p',n')\" rule:PCFG.induct)\n  case Main\n  thus ?case by(fastforce dest:Proc_CFG_edge_CondTrue_source_not_Entry intro:PCFG.Main)\nnext\n  case (MainCallReturn p es rets)\n  from \\<open>prog \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n'\\<close> \\<open>n \\<noteq> Entry\\<close>\n  have \"if (b) prog else c\\<^sub>2 \\<turnstile> n \\<oplus> 1 -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n' \\<oplus> 1\"\n    by(rule Proc_CFG_edge_CondTrue_source_not_Entry)\n  with MainCallReturn show ?case by(fastforce intro:PCFG.MainCallReturn)\nqed (auto simp:intra_kind_def)\n\n\nlemma valid_node_Main_CondTrue:\n  assumes \"CFG.valid_node sourcenode targetnode (valid_edge wfp) (Main,n)\"\n  and \"n \\<noteq> Entry\" and \"Rep_wf_prog wfp = (prog,procs)\" \n  and \"Rep_wf_prog wfp' = (if (b) prog else c\\<^sub>2,procs)\"\n  shows \"CFG.valid_node sourcenode targetnode (valid_edge wfp') (Main, n \\<oplus> 1)\"\nproof -\n  note [simp] = \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \n    \\<open>Rep_wf_prog wfp' = (if (b) prog else c\\<^sub>2,procs)\\<close>\n  from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> have wf:\"well_formed procs\" \n    by(fastforce intro:wf_wf_prog)\n  from \\<open>CFG.valid_node sourcenode targetnode (valid_edge wfp) (Main,n)\\<close>\n  obtain a where \"prog,procs \\<turnstile> sourcenode a -kind a\\<rightarrow> targetnode a\"\n    and \"(Main,n) = sourcenode a \\<or> (Main,n) = targetnode a\"\n    by(fastforce simp:ProcCFG.valid_node_def valid_edge_def)\n  from this \\<open>n \\<noteq> Entry\\<close> wf show ?thesis\n  proof(induct \"sourcenode a\" \"kind a\" \"targetnode a\" rule:PCFG.induct)\n    case (Main nx nx')\n    from \\<open>(Main,n) = sourcenode a \\<or> (Main,n) = targetnode a\\<close> show ?case\n    proof\n      assume \"(Main,n) = sourcenode a\"\n      with \\<open>(Main, nx) = sourcenode a\\<close>[THEN sym] have [simp]:\"nx = n\" by simp\n      from \\<open>n \\<noteq> Entry\\<close> \\<open>prog \\<turnstile> nx -IEdge (kind a)\\<rightarrow>\\<^sub>p nx'\\<close>\n      have \"if (b) prog else c\\<^sub>2 \\<turnstile> n \\<oplus> 1 -IEdge (kind a)\\<rightarrow>\\<^sub>p nx' \\<oplus> 1\"\n        by(fastforce intro:Proc_CFG_edge_CondTrue_source_not_Entry)\n      hence \"if (b) prog else c\\<^sub>2,procs \\<turnstile> (Main,n \\<oplus> 1) -kind a\\<rightarrow> (Main,nx' \\<oplus> 1)\"\n        by(rule PCFG.Main)\n      thus ?thesis by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n    next\n      assume \"(Main, n) = targetnode a\"\n      show ?thesis\n      proof(cases \"nx = Entry\")\n        case True\n        with \\<open>prog \\<turnstile> nx -IEdge (kind a)\\<rightarrow>\\<^sub>p nx'\\<close>\n        have \"nx' = Exit \\<or> nx' = Label 0\" by(fastforce dest:Proc_CFG_EntryD)\n        thus ?thesis\n        proof\n          assume \"nx' = Exit\"\n          with \\<open>(Main, n) = targetnode a\\<close> \\<open>(Main, nx') = targetnode a\\<close>[THEN sym]\n          show ?thesis by simp\n        next\n          assume \"nx' = Label 0\"\n          have \"if (b) prog else c\\<^sub>2 \\<turnstile> Label 0 \n            -IEdge (\\<lambda>cf. state_check cf b (Some true))\\<^sub>\\<surd>\\<rightarrow>\\<^sub>p Label 1\"\n            by(rule Proc_CFG_CondTrue)\n          with \\<open>nx' = Label 0\\<close> \n          have \"if (b) prog else c\\<^sub>2,procs \\<turnstile> (Main,Label 0) \n            -(\\<lambda>cf. state_check cf b (Some true))\\<^sub>\\<surd>\\<rightarrow> (Main,nx' \\<oplus> 1)\" \n            by(fastforce intro:PCFG.Main)\n          with \\<open>(Main, n) = targetnode a\\<close> \\<open>(Main, nx') = targetnode a\\<close>[THEN sym]\n          show ?thesis\n            by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n        qed\n      next\n        case False\n        with \\<open>prog \\<turnstile> nx -IEdge (kind a)\\<rightarrow>\\<^sub>p nx'\\<close>\n        have \"if (b) prog else c\\<^sub>2 \\<turnstile> nx \\<oplus> 1 -IEdge (kind a)\\<rightarrow>\\<^sub>p nx' \\<oplus> 1\"\n          by(fastforce intro:Proc_CFG_edge_CondTrue_source_not_Entry)\n        hence \"if (b) prog else c\\<^sub>2,procs \\<turnstile> (Main,nx \\<oplus> 1) -kind a\\<rightarrow> \n          (Main,nx' \\<oplus> 1)\" by(rule PCFG.Main)\n        with \\<open>(Main, n) = targetnode a\\<close> \\<open>(Main, nx') = targetnode a\\<close>[THEN sym]\n        show ?thesis by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n      qed\n    qed\n  next\n    case (Proc p ins outs c nx n' ps)\n    from \\<open>(p, nx) = sourcenode a\\<close>[THEN sym] \\<open>(p, n') = targetnode a\\<close>[THEN sym]\n      \\<open>(p, ins, outs, c) \\<in> set procs\\<close> \\<open>well_formed procs\\<close>\n      \\<open>(Main, n) = sourcenode a \\<or> (Main, n) = targetnode a\\<close>\n    have False by fastforce\n    thus ?case by simp\n  next\n    case (MainCall l p es rets n' ins outs c)\n    from \\<open>(p, ins, outs, c) \\<in> set procs\\<close> \\<open>(p, Entry) = targetnode a\\<close>[THEN sym] \n      \\<open>(Main, Label l) = sourcenode a\\<close>[THEN sym] wf\n      \\<open>(Main, n) = sourcenode a \\<or> (Main, n) = targetnode a\\<close>\n    have [simp]:\"n = Label l\" by fastforce\n    from \\<open>prog \\<turnstile> Label l -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n'\\<close>\n    have \"if (b) prog else c\\<^sub>2 \\<turnstile> Label l \\<oplus> 1 -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n' \\<oplus> 1\"\n      by -(rule Proc_CFG_edge_CondTrue_source_not_Entry,auto)\n    with \\<open>(p, ins, outs, c) \\<in> set procs\\<close>\n    have \"if (b) prog else c\\<^sub>2,procs \\<turnstile> (Main,Label (l + 1)) \n      -(\\<lambda>s. True):(Main,n' \\<oplus> 1)\\<hookrightarrow>\\<^bsub>p\\<^esub>map (\\<lambda>e cf. interpret e cf) es\\<rightarrow> (p,Entry)\"\n      by(fastforce intro:PCFG.MainCall)\n    thus ?case by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n  next\n    case (ProcCall p ins outs c l p' es' rets' l' ins' outs' c' ps)\n    from \\<open>(p, Label l) = sourcenode a\\<close>[THEN sym] \n      \\<open>(p', Entry) = targetnode a\\<close>[THEN sym] \\<open>well_formed procs\\<close> \n      \\<open>(p, ins, outs, c) \\<in> set procs\\<close> \\<open>(p', ins', outs', c') \\<in> set procs\\<close>\n      \\<open>(Main, n) = sourcenode a \\<or> (Main, n) = targetnode a\\<close>\n    have False by fastforce\n    thus ?case by simp\n  next\n    case (MainReturn l p es rets l' ins outs c)\n    from \\<open>(p, ins, outs, c) \\<in> set procs\\<close> \\<open>(p, Exit) = sourcenode a\\<close>[THEN sym] \n      \\<open>(Main, Label l') = targetnode a\\<close>[THEN sym] wf\n      \\<open>(Main, n) = sourcenode a \\<or> (Main, n) = targetnode a\\<close>\n    have [simp]:\"n = Label l'\" by fastforce\n    from \\<open>prog \\<turnstile> Label l -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p Label l'\\<close>\n    have \"if (b) prog else c\\<^sub>2 \\<turnstile> Label l \\<oplus> 1 -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p Label l' \\<oplus> 1\"\n      by -(rule Proc_CFG_edge_CondTrue_source_not_Entry,auto)\n    with \\<open>(p, ins, outs, c) \\<in> set procs\\<close>\n    have \"if (b) prog else c\\<^sub>2,procs \\<turnstile> (p,Exit) -(\\<lambda>cf. snd cf = (Main,Label l' \\<oplus> 1))\\<hookleftarrow>\\<^bsub>p\\<^esub>\n      (\\<lambda>cf cf'. cf'(rets [:=] map cf outs))\\<rightarrow> (Main,Label (l' + 1))\"\n      by(fastforce intro:PCFG.MainReturn)\n    thus ?case by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n  next\n    case (ProcReturn p ins outs c l p' es' rets' l' ins' outs' c' ps)\n    from \\<open>(p', Exit) = sourcenode a\\<close>[THEN sym] \n      \\<open>(p, Label l') = targetnode a\\<close>[THEN sym] \\<open>well_formed procs\\<close>\n      \\<open>(p, ins, outs, c) \\<in> set procs\\<close> \\<open>(p', ins', outs', c') \\<in> set procs\\<close>\n      \\<open>(Main, n) = sourcenode a \\<or> (Main, n) = targetnode a\\<close>\n    have False by fastforce\n    thus ?case by simp\n  next\n    case (MainCallReturn nx p es rets nx')\n    from \\<open>(Main,n) = sourcenode a \\<or> (Main,n) = targetnode a\\<close> show ?case\n    proof\n      assume \"(Main,n) = sourcenode a\"\n      with \\<open>(Main, nx) = sourcenode a\\<close>[THEN sym] have [simp]:\"nx = n\" by simp\n      from \\<open>n \\<noteq> Entry\\<close> \\<open>prog \\<turnstile> nx -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p nx'\\<close>\n      have \"if (b) prog else c\\<^sub>2 \\<turnstile> n \\<oplus> 1 -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p nx' \\<oplus> 1\"\n        by(fastforce intro:Proc_CFG_edge_CondTrue_source_not_Entry)\n      hence \"if (b) prog else c\\<^sub>2,procs \\<turnstile> (Main,n \\<oplus> 1) -(\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow> \n        (Main,nx' \\<oplus> 1)\" by -(rule PCFG.MainCallReturn)\n      thus ?thesis by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n    next\n      assume \"(Main, n) = targetnode a\"\n      from \\<open>prog \\<turnstile> nx -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p nx'\\<close>\n      have \"nx \\<noteq> Entry\" by(fastforce dest:Proc_CFG_Call_Labels)\n      with \\<open>prog \\<turnstile> nx -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p nx'\\<close>\n      have \"if (b) prog else c\\<^sub>2 \\<turnstile> nx \\<oplus> 1 -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p nx' \\<oplus> 1\"\n        by(fastforce intro:Proc_CFG_edge_CondTrue_source_not_Entry)\n      hence \"if (b) prog else c\\<^sub>2,procs \\<turnstile> (Main,nx \\<oplus> 1) -(\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow> (Main,nx' \\<oplus> 1)\"\n        by -(rule PCFG.MainCallReturn)\n      with \\<open>(Main, n) = targetnode a\\<close> \\<open>(Main, nx') = targetnode a\\<close>[THEN sym]\n      show ?thesis by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n    qed\n  next\n    case (ProcCallReturn p ins outs c nx p' es' rets' n' ps)\n    from \\<open>(p, nx) = sourcenode a\\<close>[THEN sym] \\<open>(p, n') = targetnode a\\<close>[THEN sym]\n      \\<open>(p, ins, outs, c) \\<in> set procs\\<close> \\<open>well_formed procs\\<close>\n      \\<open>(Main, n) = sourcenode a \\<or> (Main, n) = targetnode a\\<close>\n    have False by fastforce\n    thus ?case by simp\n  qed\nqed\n\n\nlemma path_Main_CondTrue:\n  assumes \"Rep_wf_prog wfp = (prog,procs)\" \n  and \"Rep_wf_prog wfp' = (if (b) prog else c\\<^sub>2,procs)\"\n  shows \"\\<lbrakk>wfp \\<turnstile> (Main,n) -as\\<rightarrow>* (p',n'); \\<forall>a \\<in> set as. intra_kind (kind a); n \\<noteq> Entry\\<rbrakk>\n  \\<Longrightarrow> wfp' \\<turnstile> (Main,n \\<oplus> 1) -as \\<oplus>s 1\\<rightarrow>* (p',n' \\<oplus> 1)\"\nproof(induct \"(Main,n)\" as \"(p',n')\" arbitrary:n rule:ProcCFG.path.induct)\n  case empty_path\n  from \\<open>CFG.valid_node sourcenode targetnode (valid_edge wfp) (Main, n')\\<close>\n    \\<open>n' \\<noteq> Entry\\<close> \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \n    \\<open>Rep_wf_prog wfp' = (if (b) prog else c\\<^sub>2,procs)\\<close>\n  have \"CFG.valid_node sourcenode targetnode (valid_edge wfp') (Main, n' \\<oplus> 1)\" \n    by(fastforce intro:valid_node_Main_CondTrue)\n  with \\<open>Main = p'\\<close> show ?case\n    by(fastforce intro:ProcCFG.empty_path simp:label_incrs_def)\nnext\n  case (Cons_path n'' as a n)\n  note IH = \\<open>\\<And>n.  \\<lbrakk>n'' = (Main, n); \\<forall>a\\<in>set as. intra_kind (kind a); n \\<noteq> Entry\\<rbrakk> \n    \\<Longrightarrow> wfp' \\<turnstile> (Main, n \\<oplus> 1) -as \\<oplus>s 1\\<rightarrow>* (p', n' \\<oplus> 1)\\<close>\n  note [simp] = \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \n    \\<open>Rep_wf_prog wfp' = (if (b) prog else c\\<^sub>2,procs)\\<close>\n  from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> have wf:\"well_formed procs\" \n    by(fastforce intro:wf_wf_prog)\n  from \\<open>\\<forall>a\\<in>set (a # as). intra_kind (kind a)\\<close> have \"intra_kind (kind a)\"\n    and \"\\<forall>a\\<in>set as. intra_kind (kind a)\" by simp_all\n  from \\<open>valid_edge wfp a\\<close> \\<open>sourcenode a = (Main, n)\\<close> \\<open>targetnode a = n''\\<close>\n    \\<open>intra_kind (kind a)\\<close> wf \n  obtain nx'' where \"n'' = (Main,nx'')\" and \"nx'' \\<noteq> Entry\"\n    by(auto elim!:PCFG.cases simp:valid_edge_def intra_kind_def)\n  from IH[OF \\<open>n'' = (Main,nx'')\\<close> \\<open>\\<forall>a\\<in>set as. intra_kind (kind a)\\<close> \\<open>nx'' \\<noteq> Entry\\<close>]\n  have path:\"wfp' \\<turnstile> (Main, nx'' \\<oplus> 1) -as \\<oplus>s 1\\<rightarrow>* (p', n' \\<oplus> 1)\" .\n  from \\<open>valid_edge wfp a\\<close> \\<open>sourcenode a = (Main, n)\\<close> \\<open>targetnode a = n''\\<close>\n    \\<open>n'' = (Main,nx'')\\<close> \\<open>n \\<noteq> Entry\\<close> \\<open>intra_kind (kind a)\\<close> wf\n  have \"if (b) prog else c\\<^sub>2,procs \\<turnstile> (Main, n \\<oplus> 1) -kind a\\<rightarrow> (Main, nx'' \\<oplus> 1)\"\n    by(fastforce intro:PCFG_Main_edge_CondTrue_source_not_Entry simp:valid_edge_def)\n  with path \\<open>sourcenode a = (Main, n)\\<close> \\<open>targetnode a = n''\\<close> \\<open>n'' = (Main,nx'')\\<close>\n  show ?case\n    apply(cases a) apply(clarsimp simp:label_incrs_def)\n    by(auto intro:ProcCFG.Cons_path simp:valid_edge_def)\nqed\n\n\nsubsubsection \\<open>From \\<open>prog\\<close> to \\<open>if (b) c\\<^sub>1 else prog\\<close>\\<close>\n\nlemma Proc_CFG_edge_CondFalse_source_not_Entry:\n  \"\\<lbrakk>prog \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'; n \\<noteq> Entry\\<rbrakk> \n  \\<Longrightarrow> if (b) c\\<^sub>1 else prog \\<turnstile> n \\<oplus> (#:c\\<^sub>1 + 1) -et\\<rightarrow>\\<^sub>p n' \\<oplus> (#:c\\<^sub>1 + 1)\"\nby(induct rule:Proc_CFG.induct)(fastforce intro:Proc_CFG_CondElse Proc_CFG.intros)+\n\n\nlemma PCFG_Main_edge_CondFalse_source_not_Entry:\n  \"\\<lbrakk>prog,procs \\<turnstile> (Main,n) -et\\<rightarrow> (p',n'); n \\<noteq> Entry; intra_kind et; well_formed procs\\<rbrakk>\n  \\<Longrightarrow> if (b) c\\<^sub>1 else prog,procs \\<turnstile> (Main,n \\<oplus> (#:c\\<^sub>1 + 1)) -et\\<rightarrow> (p',n' \\<oplus> (#:c\\<^sub>1 + 1))\"\nproof(induct \"(Main,n)\" et \"(p',n')\" rule:PCFG.induct)\n  case Main\n  thus ?case \n    by(fastforce dest:Proc_CFG_edge_CondFalse_source_not_Entry intro:PCFG.Main)\nnext\n  case (MainCallReturn p es rets)\n  from \\<open>prog \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n'\\<close> \\<open>n \\<noteq> Entry\\<close>\n  have \"if (b) c\\<^sub>1 else prog \\<turnstile> n \\<oplus> (#:c\\<^sub>1 + 1) -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n' \\<oplus> (#:c\\<^sub>1 + 1)\"\n    by(rule Proc_CFG_edge_CondFalse_source_not_Entry)\n  with MainCallReturn show ?case by(fastforce intro:PCFG.MainCallReturn)\nqed (auto simp:intra_kind_def)\n\n\n\n\n\nlemma path_Main_CondFalse:\n  assumes \"Rep_wf_prog wfp = (prog,procs)\" \n  and \"Rep_wf_prog wfp' = (if (b) c\\<^sub>1 else prog,procs)\"\n  shows \"\\<lbrakk>wfp \\<turnstile> (Main,n) -as\\<rightarrow>* (p',n'); \\<forall>a \\<in> set as. intra_kind (kind a); n \\<noteq> Entry\\<rbrakk>\n  \\<Longrightarrow> wfp' \\<turnstile> (Main,n \\<oplus> (#:c\\<^sub>1 + 1)) -as \\<oplus>s (#:c\\<^sub>1 + 1)\\<rightarrow>* (p',n' \\<oplus> (#:c\\<^sub>1 + 1))\"\nproof(induct \"(Main,n)\" as \"(p',n')\" arbitrary:n rule:ProcCFG.path.induct)\n  case empty_path\n  from \\<open>CFG.valid_node sourcenode targetnode (valid_edge wfp) (Main, n')\\<close>\n    \\<open>n' \\<noteq> Entry\\<close> \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \n    \\<open>Rep_wf_prog wfp' = (if (b) c\\<^sub>1 else prog,procs)\\<close>\n  have \"CFG.valid_node sourcenode targetnode (valid_edge wfp') (Main, n' \\<oplus> (#:c\\<^sub>1 + 1))\"\n    by(fastforce intro:valid_node_Main_CondFalse)\n  with \\<open>Main = p'\\<close> show ?case\n    by(fastforce intro:ProcCFG.empty_path simp:label_incrs_def)\nnext\n  case (Cons_path n'' as a n)\n  note IH = \\<open>\\<And>n. \\<And>n.  \\<lbrakk>n'' = (Main, n); \\<forall>a\\<in>set as. intra_kind (kind a); n \\<noteq> Entry\\<rbrakk>\n    \\<Longrightarrow> wfp' \\<turnstile> (Main, n \\<oplus> (#:c\\<^sub>1 + 1)) -as \\<oplus>s (#:c\\<^sub>1 + 1)\\<rightarrow>* (p', n' \\<oplus> (#:c\\<^sub>1 + 1))\\<close>\n  note [simp] = \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \n    \\<open>Rep_wf_prog wfp' = (if (b) c\\<^sub>1 else prog,procs)\\<close>\n  from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> have wf:\"well_formed procs\" \n    by(fastforce intro:wf_wf_prog)\n  from \\<open>\\<forall>a\\<in>set (a # as). intra_kind (kind a)\\<close> have \"intra_kind (kind a)\"\n    and \"\\<forall>a\\<in>set as. intra_kind (kind a)\" by simp_all\n  from \\<open>valid_edge wfp a\\<close> \\<open>sourcenode a = (Main, n)\\<close> \\<open>targetnode a = n''\\<close>\n    \\<open>intra_kind (kind a)\\<close> wf \n  obtain nx'' where \"n'' = (Main,nx'')\" and \"nx'' \\<noteq> Entry\"\n    by(auto elim!:PCFG.cases simp:valid_edge_def intra_kind_def)\n  from IH[OF \\<open>n'' = (Main,nx'')\\<close> \\<open>\\<forall>a\\<in>set as. intra_kind (kind a)\\<close> \\<open>nx'' \\<noteq> Entry\\<close>]\n  have path:\"wfp' \\<turnstile> (Main, nx'' \\<oplus> (#:c\\<^sub>1 + 1)) -as \\<oplus>s (#:c\\<^sub>1 + 1)\\<rightarrow>* \n    (p', n' \\<oplus> (#:c\\<^sub>1 + 1))\" .\n  from \\<open>valid_edge wfp a\\<close> \\<open>sourcenode a = (Main, n)\\<close> \\<open>targetnode a = n''\\<close>\n    \\<open>n'' = (Main,nx'')\\<close> \\<open>n \\<noteq> Entry\\<close> \\<open>intra_kind (kind a)\\<close> wf\n  have \"if (b) c\\<^sub>1 else prog,procs \\<turnstile> (Main, n \\<oplus> (#:c\\<^sub>1 + 1)) -kind a\\<rightarrow> \n    (Main, nx'' \\<oplus> (#:c\\<^sub>1 + 1))\"\n    by(fastforce intro:PCFG_Main_edge_CondFalse_source_not_Entry simp:valid_edge_def)\n  with path \\<open>sourcenode a = (Main, n)\\<close> \\<open>targetnode a = n''\\<close> \\<open>n'' = (Main,nx'')\\<close>\n  show ?case\n    apply(cases a) apply(clarsimp simp:label_incrs_def)\n    by(auto intro:ProcCFG.Cons_path simp:valid_edge_def)\nqed\n\n\nsubsubsection \\<open>From \\<open>prog\\<close> to \\<open>while (b) prog\\<close>\\<close>\n\nlemma Proc_CFG_edge_WhileBody_source_not_Entry:\n  \"\\<lbrakk>prog \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'; n \\<noteq> Entry; n' \\<noteq> Exit\\<rbrakk> \n  \\<Longrightarrow> while (b) prog \\<turnstile> n \\<oplus> 2 -et\\<rightarrow>\\<^sub>p n' \\<oplus> 2\"\nby(induct rule:Proc_CFG.induct)(fastforce intro:Proc_CFG_WhileBody Proc_CFG.intros)+\n\n\nlemma PCFG_Main_edge_WhileBody_source_not_Entry:\n  \"\\<lbrakk>prog,procs \\<turnstile> (Main,n) -et\\<rightarrow> (p',n'); n \\<noteq> Entry; n' \\<noteq> Exit; intra_kind et; \n  well_formed procs\\<rbrakk> \\<Longrightarrow> while (b) prog,procs \\<turnstile> (Main,n \\<oplus> 2) -et\\<rightarrow> (p',n' \\<oplus> 2)\"\nproof(induct \"(Main,n)\" et \"(p',n')\" rule:PCFG.induct)\n  case Main\n  thus ?case \n    by(fastforce dest:Proc_CFG_edge_WhileBody_source_not_Entry intro:PCFG.Main)\nnext\n  case (MainCallReturn p es rets)\n  from \\<open>prog \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n'\\<close> \\<open>n \\<noteq> Entry\\<close> \\<open>n' \\<noteq> Exit\\<close>\n  have \"while (b) prog \\<turnstile> n \\<oplus> 2 -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n' \\<oplus> 2\"\n    by(rule Proc_CFG_edge_WhileBody_source_not_Entry)\n  with MainCallReturn show ?case by(fastforce intro:PCFG.MainCallReturn)\nqed (auto simp:intra_kind_def)\n\n\nlemma valid_node_Main_WhileBody:\n  assumes \"CFG.valid_node sourcenode targetnode (valid_edge wfp) (Main,n)\"\n  and \"n \\<noteq> Entry\" and \"Rep_wf_prog wfp = (prog,procs)\" \n  and \"Rep_wf_prog wfp' = (while (b) prog,procs)\"\n  shows \"CFG.valid_node sourcenode targetnode (valid_edge wfp') (Main, n \\<oplus> 2)\"\nproof -\n  note [simp] = \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \n    \\<open>Rep_wf_prog wfp' = (while (b) prog,procs)\\<close>\n  from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> have wf:\"well_formed procs\" \n    by(fastforce intro:wf_wf_prog)\n  from \\<open>CFG.valid_node sourcenode targetnode (valid_edge wfp) (Main,n)\\<close>\n  obtain a where \"prog,procs \\<turnstile> sourcenode a -kind a\\<rightarrow> targetnode a\"\n    and \"(Main,n) = sourcenode a \\<or> (Main,n) = targetnode a\"\n    by(fastforce simp:ProcCFG.valid_node_def valid_edge_def)\n  from this \\<open>n \\<noteq> Entry\\<close> wf show ?thesis\n  proof(induct \"sourcenode a\" \"kind a\" \"targetnode a\" rule:PCFG.induct)\n    case (Main nx nx')\n    from \\<open>(Main,n) = sourcenode a \\<or> (Main,n) = targetnode a\\<close> show ?case\n    proof\n      assume \"(Main,n) = sourcenode a\"\n      with \\<open>(Main, nx) = sourcenode a\\<close>[THEN sym] have [simp]:\"nx = n\" by simp\n      show ?thesis\n      proof(cases \"nx' = Exit\")\n        case True\n        with \\<open>n \\<noteq> Entry\\<close> \\<open>prog \\<turnstile> nx -IEdge (kind a)\\<rightarrow>\\<^sub>p nx'\\<close>\n        have \"while (b) prog \\<turnstile> n \\<oplus> 2 -IEdge (kind a)\\<rightarrow>\\<^sub>p Label 0\"\n          by(fastforce intro:Proc_CFG_WhileBodyExit)\n        hence \"while (b) prog,procs \\<turnstile> (Main,n \\<oplus> 2) -kind a\\<rightarrow> (Main,Label 0)\"\n          by(rule PCFG.Main)\n        thus ?thesis by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n      next\n        case False\n        with \\<open>n \\<noteq> Entry\\<close> \\<open>prog \\<turnstile> nx -IEdge (kind a)\\<rightarrow>\\<^sub>p nx'\\<close>\n        have \"while (b) prog \\<turnstile> n \\<oplus> 2 -IEdge (kind a)\\<rightarrow>\\<^sub>p nx' \\<oplus> 2\"\n          by(fastforce intro:Proc_CFG_edge_WhileBody_source_not_Entry)\n        hence \"while (b) prog,procs \\<turnstile> (Main,n \\<oplus> 2) -kind a\\<rightarrow> (Main,nx' \\<oplus> 2)\"\n          by(rule PCFG.Main)\n        thus ?thesis by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n      qed\n    next\n      assume \"(Main, n) = targetnode a\"\n      show ?thesis\n      proof(cases \"nx = Entry\")\n        case True\n        with \\<open>prog \\<turnstile> nx -IEdge (kind a)\\<rightarrow>\\<^sub>p nx'\\<close> \n        have \"nx' = Exit \\<or> nx' = Label 0\" by(fastforce dest:Proc_CFG_EntryD)\n        thus ?thesis\n        proof\n          assume \"nx' = Exit\"\n          with \\<open>(Main, n) = targetnode a\\<close> \\<open>(Main, nx') = targetnode a\\<close>[THEN sym]\n          show ?thesis by simp\n        next\n          assume \"nx' = Label 0\"\n          have \"while (b) prog \\<turnstile> Label 0 \n            -IEdge (\\<lambda>cf. state_check cf b (Some true))\\<^sub>\\<surd>\\<rightarrow>\\<^sub>p Label 2\"\n            by(rule Proc_CFG_WhileTrue)\n          hence \"while (b) prog,procs \\<turnstile> (Main,Label 0) \n            -(\\<lambda>cf. state_check cf b (Some true))\\<^sub>\\<surd>\\<rightarrow> (Main,Label 2)\"\n            by(fastforce intro:PCFG.Main)\n          with \\<open>(Main, n) = targetnode a\\<close> \\<open>(Main, nx') = targetnode a\\<close>[THEN sym]\n            \\<open>nx' = Label 0\\<close> show ?thesis\n            by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n        qed\n      next\n        case False\n        show ?thesis\n        proof(cases \"nx' = Exit\")\n          case True\n          with \\<open>(Main, n) = targetnode a\\<close> \\<open>(Main, nx') = targetnode a\\<close>[THEN sym]\n          show ?thesis by simp\n        next\n          case False\n          with \\<open>prog \\<turnstile> nx -IEdge (kind a)\\<rightarrow>\\<^sub>p nx'\\<close> \\<open>nx \\<noteq> Entry\\<close>\n          have \"while (b) prog \\<turnstile> nx \\<oplus> 2 -IEdge (kind a)\\<rightarrow>\\<^sub>p nx' \\<oplus> 2\"\n            by(fastforce intro:Proc_CFG_edge_WhileBody_source_not_Entry)\n          hence \"while (b) prog,procs \\<turnstile> (Main,nx \\<oplus> 2)  -kind a\\<rightarrow> \n            (Main,nx' \\<oplus> 2)\" by(rule PCFG.Main)\n          with \\<open>(Main, n) = targetnode a\\<close> \\<open>(Main, nx') = targetnode a\\<close>[THEN sym]\n          show ?thesis\n            by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n        qed\n      qed\n    qed\n  next\n    case (Proc p ins outs c nx n' ps)\n    from \\<open>(p, nx) = sourcenode a\\<close>[THEN sym] \\<open>(p, n') = targetnode a\\<close>[THEN sym]\n      \\<open>(Main, n) = sourcenode a \\<or> (Main, n) = targetnode a\\<close> \n      \\<open>(p, ins, outs, c) \\<in> set procs\\<close> \\<open>well_formed procs\\<close> \n    have False by fastforce\n    thus ?case by simp\n  next\n    case (MainCall l p es rets n' ins outs c)\n    from \\<open>(p, ins, outs, c) \\<in> set procs\\<close> \\<open>(p, Entry) = targetnode a\\<close>[THEN sym]\n      \\<open>(Main, Label l) = sourcenode a\\<close>[THEN sym] wf\n      \\<open>(Main, n) = sourcenode a \\<or> (Main, n) = targetnode a\\<close>\n    have [simp]:\"n = Label l\" by fastforce\n    from \\<open>prog \\<turnstile> Label l -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n'\\<close> have \"n' \\<noteq> Exit\"\n      by(fastforce dest:Proc_CFG_Call_Labels)\n    with \\<open>prog \\<turnstile> Label l -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n'\\<close>\n    have \"while (b) prog \\<turnstile> Label l \\<oplus> 2 -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p \n      n' \\<oplus> 2\" by -(rule Proc_CFG_edge_WhileBody_source_not_Entry,auto)\n    with \\<open>(p, ins, outs, c) \\<in> set procs\\<close>\n    have \"while (b) prog,procs \\<turnstile> (Main,Label l \\<oplus> 2) \n      -(\\<lambda>s. True):(Main,n' \\<oplus> 2)\\<hookrightarrow>\\<^bsub>p\\<^esub>map (\\<lambda>e cf. interpret e cf) es\\<rightarrow> (p,Entry)\"\n      by(fastforce intro:PCFG.MainCall)\n    thus ?case by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n  next\n    case (ProcCall p ins outs c l p' es' rets' l' ins' outs' c')\n    from \\<open>(p, Label l) = sourcenode a\\<close>[THEN sym]\n      \\<open>(p', Entry) = targetnode a\\<close>[THEN sym]  \\<open>well_formed procs\\<close>\n      \\<open>(p, ins, outs, c) \\<in> set procs\\<close> \\<open>(p', ins', outs', c') \\<in> set procs\\<close>\n      \\<open>(Main, n) = sourcenode a \\<or> (Main, n) = targetnode a\\<close>\n    have False by fastforce\n    thus ?case by simp\n  next\n    case (MainReturn l p es rets l' ins outs c)\n    from \\<open>(p, ins, outs, c) \\<in> set procs\\<close> \\<open>(p, Exit) = sourcenode a\\<close>[THEN sym]\n      \\<open>(Main, Label l') = targetnode a\\<close>[THEN sym] wf\n      \\<open>(Main, n) = sourcenode a \\<or> (Main, n) = targetnode a\\<close>\n    have [simp]:\"n = Label l'\" by fastforce\n    from \\<open>prog \\<turnstile> Label l -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p Label l'\\<close>\n    have \"while (b) prog \\<turnstile> Label l \\<oplus> 2 -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p \n      Label l' \\<oplus> 2\" by -(rule Proc_CFG_edge_WhileBody_source_not_Entry,auto)\n    with \\<open>(p, ins, outs, c) \\<in> set procs\\<close>\n    have \"while (b) prog,procs \\<turnstile> (p,Exit) -(\\<lambda>cf. snd cf = (Main,Label l' \\<oplus> 2))\\<hookleftarrow>\\<^bsub>p\\<^esub>\n      (\\<lambda>cf cf'. cf'(rets [:=] map cf outs))\\<rightarrow> (Main,Label l' \\<oplus> 2)\"\n      by(fastforce intro:PCFG.MainReturn)\n    thus ?case by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n  next\n    case (ProcReturn p ins outs c l p' es' rets' l' ins' outs' c' ps)\n    from \\<open>(p', Exit) = sourcenode a\\<close>[THEN sym] \n      \\<open>(p, Label l') = targetnode a\\<close>[THEN sym] \\<open>well_formed procs\\<close>\n      \\<open>(p, ins, outs, c) \\<in> set procs\\<close> \\<open>(p', ins', outs', c') \\<in> set procs\\<close>\n      \\<open>(Main, n) = sourcenode a \\<or> (Main, n) = targetnode a\\<close>\n    have False by fastforce\n    thus ?case by simp\n  next\n    case (MainCallReturn nx p es rets nx')\n    from \\<open>(Main,n) = sourcenode a \\<or> (Main,n) = targetnode a\\<close> show ?case\n    proof\n      assume \"(Main,n) = sourcenode a\"\n      with \\<open>(Main, nx) = sourcenode a\\<close>[THEN sym] have [simp]:\"nx = n\" by simp\n      from \\<open>prog \\<turnstile> nx -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p nx'\\<close> have \"nx' \\<noteq> Exit\"\n        by(fastforce dest:Proc_CFG_Call_Labels)\n      with \\<open>n \\<noteq> Entry\\<close> \\<open>prog \\<turnstile> nx -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p nx'\\<close>\n      have \"while (b) prog \\<turnstile> n \\<oplus> 2 -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p \n        nx' \\<oplus> 2\" by(fastforce intro:Proc_CFG_edge_WhileBody_source_not_Entry)\n      hence \"while (b) prog,procs \\<turnstile> (Main,n \\<oplus> 2) -(\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow> (Main,nx' \\<oplus> 2)\"\n        by -(rule PCFG.MainCallReturn)\n      thus ?thesis by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n    next\n      assume \"(Main, n) = targetnode a\"\n      from \\<open>prog \\<turnstile> nx -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p nx'\\<close>\n      have \"nx \\<noteq> Entry\" and \"nx' \\<noteq> Exit\" by(auto dest:Proc_CFG_Call_Labels)\n      with \\<open>prog \\<turnstile> nx -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p nx'\\<close>\n      have \"while (b) prog \\<turnstile> nx \\<oplus> 2 -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p \n        nx' \\<oplus> 2\" by(fastforce intro:Proc_CFG_edge_WhileBody_source_not_Entry)\n      hence \"while (b) prog,procs \\<turnstile> (Main,nx \\<oplus> 2) -(\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow> (Main,nx' \\<oplus> 2)\"\n        by -(rule PCFG.MainCallReturn)\n      with \\<open>(Main, n) = targetnode a\\<close> \\<open>(Main, nx') = targetnode a\\<close>[THEN sym] \n      show ?thesis by(simp add:ProcCFG.valid_node_def)(fastforce simp:valid_edge_def)\n    qed\n  next\n    case (ProcCallReturn p ins outs c nx p' es' rets' n' ps)\n    from \\<open>(p, nx) = sourcenode a\\<close>[THEN sym] \\<open>(p, n') = targetnode a\\<close>[THEN sym]\n      \\<open>(p, ins, outs, c) \\<in> set procs\\<close> \\<open>well_formed procs\\<close>\n      \\<open>(Main, n) = sourcenode a \\<or> (Main, n) = targetnode a\\<close>\n    have False by fastforce\n    thus ?case by simp\n  qed\nqed\n\n\nlemma path_Main_WhileBody:\n  assumes \"Rep_wf_prog wfp = (prog,procs)\" \n  and \"Rep_wf_prog wfp' = (while (b) prog,procs)\"\n  shows \"\\<lbrakk>wfp \\<turnstile> (Main,n) -as\\<rightarrow>* (p',n'); \\<forall>a \\<in> set as. intra_kind (kind a); \n    n \\<noteq> Entry; n' \\<noteq> Exit\\<rbrakk> \\<Longrightarrow> wfp' \\<turnstile> (Main,n \\<oplus> 2) -as \\<oplus>s 2\\<rightarrow>* (p',n' \\<oplus> 2)\"\nproof(induct \"(Main,n)\" as \"(p',n')\" arbitrary:n rule:ProcCFG.path.induct)\n  case empty_path\n  from \\<open>CFG.valid_node sourcenode targetnode (valid_edge wfp) (Main, n')\\<close>\n    \\<open>n' \\<noteq> Entry\\<close> \\<open>Rep_wf_prog wfp = (prog,procs)\\<close>\n    \\<open>Rep_wf_prog wfp' = (while (b) prog,procs)\\<close>\n  have \"CFG.valid_node sourcenode targetnode (valid_edge wfp') (Main, n' \\<oplus> 2)\" \n    by(fastforce intro:valid_node_Main_WhileBody)\n  with \\<open>Main = p'\\<close> show ?case\n    by(fastforce intro:ProcCFG.empty_path simp:label_incrs_def)\nnext\n  case (Cons_path n'' as a n)\n  note IH = \\<open>\\<And>n.  \\<lbrakk>n'' = (Main, n); \\<forall>a\\<in>set as. intra_kind (kind a); n \\<noteq> Entry; \n    n' \\<noteq> Exit\\<rbrakk> \\<Longrightarrow> wfp' \\<turnstile> (Main, n \\<oplus> 2) -as \\<oplus>s 2\\<rightarrow>* (p', n' \\<oplus> 2)\\<close>\n  note [simp] = \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \n     \\<open>Rep_wf_prog wfp' = (while (b) prog,procs)\\<close>\n  from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> have wf:\"well_formed procs\" \n    by(fastforce intro:wf_wf_prog)\n  from \\<open>\\<forall>a\\<in>set (a # as). intra_kind (kind a)\\<close> have \"intra_kind (kind a)\"\n    and \"\\<forall>a\\<in>set as. intra_kind (kind a)\" by simp_all\n  from \\<open>valid_edge wfp a\\<close> \\<open>sourcenode a = (Main, n)\\<close> \\<open>targetnode a = n''\\<close>\n    \\<open>intra_kind (kind a)\\<close> wf \n  obtain nx'' where \"n'' = (Main,nx'')\" and \"nx'' \\<noteq> Entry\"\n    by(auto elim!:PCFG.cases simp:valid_edge_def intra_kind_def)\n  from IH[OF \\<open>n'' = (Main,nx'')\\<close> \\<open>\\<forall>a\\<in>set as. intra_kind (kind a)\\<close> \n    \\<open>nx'' \\<noteq> Entry\\<close> \\<open>n' \\<noteq> Exit\\<close>]\n  have path:\"wfp' \\<turnstile> (Main, nx'' \\<oplus> 2) -as \\<oplus>s 2\\<rightarrow>* (p', n' \\<oplus> 2)\" .\n  with \\<open>n' \\<noteq> Exit\\<close> have \"nx'' \\<noteq> Exit\" by(fastforce dest:ProcCFGExit.path_Exit_source)\n  with \\<open>valid_edge wfp a\\<close> \\<open>sourcenode a = (Main, n)\\<close> \\<open>targetnode a = n''\\<close>\n    \\<open>n'' = (Main,nx'')\\<close> \\<open>n \\<noteq> Entry\\<close> \\<open>intra_kind (kind a)\\<close> wf\n  have \"while (b) prog,procs \\<turnstile> (Main, n \\<oplus> 2) -kind a\\<rightarrow> (Main, nx'' \\<oplus> 2)\"\n    by(fastforce intro:PCFG_Main_edge_WhileBody_source_not_Entry simp:valid_edge_def)\n  with path \\<open>sourcenode a = (Main, n)\\<close> \\<open>targetnode a = n''\\<close> \\<open>n'' = (Main,nx'')\\<close>\n  show ?case\n    apply(cases a) apply(clarsimp simp:label_incrs_def)\n    by(auto intro:ProcCFG.Cons_path simp:valid_edge_def)\nqed\n\n\nsubsubsection \\<open>Existence of intraprodecural paths\\<close>\n\nlemma Label_Proc_CFG_Entry_Exit_path_Main:\n  assumes \"Rep_wf_prog wfp = (prog,procs)\" and \"l < #:prog\"\n  obtains as as' where \"wfp \\<turnstile> (Main,Label l) -as\\<rightarrow>* (Main,Exit)\"\n  and \"\\<forall>a \\<in> set as. intra_kind (kind a)\"\n  and \"wfp \\<turnstile> (Main,Entry) -as'\\<rightarrow>* (Main,Label l)\"\n  and \"\\<forall>a \\<in> set as'. intra_kind (kind a)\"\nproof(atomize_elim)\n  from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> have wf:\"well_formed procs\" \n    by(fastforce intro:wf_wf_prog)\n  from \\<open>l < #:prog\\<close> \\<open>Rep_wf_prog wfp = (prog,procs)\\<close>\n  show \"\\<exists>as as'. wfp \\<turnstile> (Main, Label l) -as\\<rightarrow>* (Main, Exit) \\<and>\n    (\\<forall>a\\<in>set as. intra_kind (kind a)) \\<and>\n    wfp \\<turnstile> (Main, Entry) -as'\\<rightarrow>* (Main, Label l) \\<and> (\\<forall>a\\<in>set as'. intra_kind (kind a))\"\n  proof(induct prog arbitrary:l wfp)\n    case Skip\n    note [simp] = \\<open>Rep_wf_prog wfp = (Skip, procs)\\<close>\n    from \\<open>l < #:Skip\\<close> have [simp]:\"l = 0\" by simp\n    have \"wfp \\<turnstile> (Main,Entry) -[((Main,Entry),(\\<lambda>s. True)\\<^sub>\\<surd>,(Main,Label 0))]\\<rightarrow>* \n      (Main,Label 0)\" \n      by(fastforce intro:ProcCFG.path.intros Main Proc_CFG_Entry\n                   simp:valid_edge_def ProcCFG.valid_node_def)\n    moreover\n    have \"wfp \\<turnstile> (Main,Label l) -[((Main,Label l),\\<Up>id,(Main,Exit))]\\<rightarrow>* (Main,Exit)\" \n      by(fastforce intro:ProcCFG.path.intros Main Proc_CFG_Skip simp:valid_edge_def)\n    ultimately show ?case by(fastforce simp:intra_kind_def)\n  next\n    case (LAss V e)\n    note [simp] = \\<open>Rep_wf_prog wfp = (V:=e, procs)\\<close>\n    from \\<open>l < #:V:=e\\<close> have \"l = 0 \\<or> l = 1\" by auto\n    thus ?case\n    proof\n      assume [simp]:\"l = 0\"\n      have \"wfp \\<turnstile> (Main,Entry) -[((Main,Entry),(\\<lambda>s. True)\\<^sub>\\<surd>,(Main,Label 0))]\\<rightarrow>*\n        (Main,Label 0)\" \n        by(fastforce intro:ProcCFG.path.intros Main Proc_CFG_Entry\n                    simp:valid_edge_def ProcCFG.valid_node_def)\n      moreover\n      have \"wfp \\<turnstile> (Main,Label 0) \n        -((Main,Label 0),\\<Up>(\\<lambda>cf. update cf V e),(Main,Label 1))#\n        [((Main,Label 1),\\<Up>id,(Main,Exit))]\\<rightarrow>* (Main,Exit)\"\n        by(fastforce intro:ProcCFG.Cons_path ProcCFG.path.intros Main Proc_CFG_LAss \n          Proc_CFG_LAssSkip simp:valid_edge_def ProcCFG.valid_node_def)\n      ultimately show ?thesis by(fastforce simp:intra_kind_def)\n    next\n      assume [simp]:\"l = 1\"\n      have \"wfp \\<turnstile> (Main,Entry) -((Main,Entry),(\\<lambda>s. True)\\<^sub>\\<surd>,(Main,Label 0))#\n        [((Main,Label 0),\\<Up>(\\<lambda>cf. update cf V e),(Main,Label 1))]\\<rightarrow>* (Main,Label 1)\"\n        by(fastforce intro:ProcCFG.path.intros Main Proc_CFG_LAss ProcCFG.Cons_path \n          Main Proc_CFG_Entry simp:ProcCFG.valid_node_def valid_edge_def)\n      moreover\n      have \"wfp \\<turnstile> (Main,Label 1) -[((Main,Label 1),\\<Up>id,(Main,Exit))]\\<rightarrow>* \n        (Main,Exit)\" by(fastforce intro:ProcCFG.path.intros  Main Proc_CFG_LAssSkip\n        simp:valid_edge_def ProcCFG.valid_node_def)\n      ultimately show ?thesis by(fastforce simp:intra_kind_def)\n    qed\n  next\n    case (Seq c\\<^sub>1 c\\<^sub>2)\n    note IH1 = \\<open>\\<And>l wfp. \\<lbrakk>l < #:c\\<^sub>1; Rep_wf_prog wfp = (c\\<^sub>1, procs)\\<rbrakk> \\<Longrightarrow>\n      \\<exists>as as'. wfp \\<turnstile> (Main, Label l) -as\\<rightarrow>* (Main, Exit) \\<and> \n      (\\<forall>a\\<in>set as. intra_kind (kind a)) \\<and>\n      wfp \\<turnstile> (Main, Entry) -as'\\<rightarrow>* (Main, Label l) \\<and> (\\<forall>a\\<in>set as'. intra_kind (kind a))\\<close>\n    note IH2 = \\<open>\\<And>l wfp. \\<lbrakk>l < #:c\\<^sub>2; Rep_wf_prog wfp = (c\\<^sub>2, procs)\\<rbrakk> \\<Longrightarrow>\n      \\<exists>as as'. wfp \\<turnstile> (Main, Label l) -as\\<rightarrow>* (Main, Exit) \\<and> \n      (\\<forall>a\\<in>set as. intra_kind (kind a)) \\<and>\n      wfp \\<turnstile> (Main, Entry) -as'\\<rightarrow>* (Main, Label l) \\<and> (\\<forall>a\\<in>set as'. intra_kind (kind a))\\<close>\n    note [simp] = \\<open>Rep_wf_prog wfp = (c\\<^sub>1;; c\\<^sub>2, procs)\\<close>\n    show ?case\n    proof(cases \"l < #:c\\<^sub>1\")\n      case True\n      from \\<open>Rep_wf_prog wfp = (c\\<^sub>1;; c\\<^sub>2, procs)\\<close>\n      obtain wfp' where [simp]:\"Rep_wf_prog wfp' = (c\\<^sub>1, procs)\" by(erule wfp_Seq1)\n      from IH1[OF True this] obtain as as' \n        where path1:\"wfp' \\<turnstile> (Main, Label l) -as\\<rightarrow>* (Main, Exit)\"\n        and intra1:\"\\<forall>a\\<in>set as. intra_kind (kind a)\"\n        and path2:\"wfp' \\<turnstile> (Main, Entry) -as'\\<rightarrow>* (Main, Label l)\"\n        and intra2:\"\\<forall>a\\<in>set as'. intra_kind (kind a)\" by blast\n      from path1 have \"as \\<noteq> []\" by(fastforce elim:ProcCFG.path.cases)\n      then obtain ax asx where [simp]:\"as = asx@[ax]\"\n        by(cases as rule:rev_cases) fastforce+\n      with path1 have \"wfp' \\<turnstile> (Main, Label l) -asx\\<rightarrow>* sourcenode ax\"\n        and \"valid_edge wfp' ax\" and \"targetnode ax = (Main, Exit)\"\n        by(auto elim:ProcCFG.path_split_snoc)\n      from \\<open>valid_edge wfp' ax\\<close> \\<open>targetnode ax = (Main, Exit)\\<close>\n      obtain nx where \"sourcenode ax = (Main,nx)\" \n        by(fastforce elim:PCFG.cases simp:valid_edge_def)\n      with \\<open>wfp' \\<turnstile> (Main, Label l) -asx\\<rightarrow>* sourcenode ax\\<close> have \"nx \\<noteq> Entry\"\n        by fastforce\n      moreover\n      from \\<open>valid_edge wfp' ax\\<close> \\<open>sourcenode ax = (Main,nx)\\<close> have \"nx \\<noteq> Exit\"\n        by(fastforce intro:ProcCFGExit.Exit_source)\n      ultimately obtain lx where [simp]:\"nx = Label lx\" by(cases nx) auto\n      with \\<open>wfp' \\<turnstile> (Main, Label l) -asx\\<rightarrow>* sourcenode ax\\<close> \n        \\<open>sourcenode ax = (Main,nx)\\<close> intra1\n      have path3:\"wfp \\<turnstile> (Main, Label l) -asx\\<rightarrow>* (Main, Label lx)\"\n        by -(rule path_SeqFirst,auto)\n      from \\<open>valid_edge wfp' ax\\<close> \\<open>targetnode ax = (Main, Exit)\\<close>\n        \\<open>sourcenode ax = (Main,nx)\\<close> wf\n      obtain etx where \"c\\<^sub>1 \\<turnstile> Label lx -etx\\<rightarrow>\\<^sub>p Exit\" \n        by(fastforce elim!:PCFG.cases simp:valid_edge_def)\n      then obtain et where [simp]:\"etx = IEdge et\" \n        by(cases etx)(auto dest:Proc_CFG_Call_Labels)\n      with \\<open>c\\<^sub>1 \\<turnstile> Label lx -etx\\<rightarrow>\\<^sub>p Exit\\<close> have \"intra_kind et\"\n        by(fastforce intro:Proc_CFG_IEdge_intra_kind)\n      from \\<open>c\\<^sub>1 \\<turnstile> Label lx -etx\\<rightarrow>\\<^sub>p Exit\\<close> path3\n      have path4:\"wfp \\<turnstile> (Main, Label l) -asx@\n        [((Main, Label lx),et,(Main,Label 0 \\<oplus> #:c\\<^sub>1))] \\<rightarrow>* (Main,Label 0 \\<oplus> #:c\\<^sub>1)\"\n        by(fastforce intro:ProcCFG.path_Append ProcCFG.path.intros Proc_CFG_SeqConnect\n          Main simp:ProcCFG.valid_node_def valid_edge_def)\n      from \\<open>Rep_wf_prog wfp = (c\\<^sub>1;; c\\<^sub>2, procs)\\<close>\n      obtain wfp'' where [simp]:\"Rep_wf_prog wfp'' = (c\\<^sub>2, procs)\" by(erule wfp_Seq2)\n      from IH2[OF _ this,of \"0\"] obtain asx' \n        where \"wfp'' \\<turnstile> (Main, Label 0) -asx'\\<rightarrow>* (Main, Exit)\"\n        and \"\\<forall>a\\<in>set asx'. intra_kind (kind a)\" by blast\n      with path4 intra1 \\<open>intra_kind et\\<close> have \"wfp \\<turnstile> (Main, Label l) \n        -(asx@[((Main, Label lx),et,(Main,Label 0 \\<oplus> #:c\\<^sub>1))])@(asx' \\<oplus>s #:c\\<^sub>1)\\<rightarrow>*\n        (Main, Exit \\<oplus> #:c\\<^sub>1)\"\n        by -(erule ProcCFG.path_Append,rule path_Main_SeqSecond,auto)\n      moreover\n      from intra1 \\<open>intra_kind et\\<close> \\<open>\\<forall>a\\<in>set asx'. intra_kind (kind a)\\<close>\n      have \"\\<forall>a \\<in> set ((asx@[((Main, Label lx),et,(Main,Label #:c\\<^sub>1))])@(asx' \\<oplus>s #:c\\<^sub>1)).\n        intra_kind (kind a)\" by(auto simp:label_incrs_def)\n      moreover\n      from path2 intra2 have \"wfp \\<turnstile> (Main, Entry) -as'\\<rightarrow>* (Main, Label l)\"\n        by -(rule path_SeqFirst,auto)\n      ultimately show ?thesis using \\<open>\\<forall>a\\<in>set as'. intra_kind (kind a)\\<close> by fastforce\n    next\n      case False\n      hence \"#:c\\<^sub>1 \\<le> l\" by simp\n      then obtain l' where [simp]:\"l = l' + #:c\\<^sub>1\" and \"l' = l - #:c\\<^sub>1\" by simp\n      from \\<open>l < #:c\\<^sub>1;; c\\<^sub>2\\<close> have \"l' < #:c\\<^sub>2\" by simp\n      from \\<open>Rep_wf_prog wfp = (c\\<^sub>1;; c\\<^sub>2, procs)\\<close>\n      obtain wfp' where [simp]:\"Rep_wf_prog wfp' = (c\\<^sub>2, procs)\" by(erule wfp_Seq2)\n      from IH2[OF \\<open>l' < #:c\\<^sub>2\\<close> this] obtain as as' \n        where path1:\"wfp' \\<turnstile> (Main, Label l') -as\\<rightarrow>* (Main, Exit)\"\n        and intra1:\"\\<forall>a\\<in>set as. intra_kind (kind a)\"\n        and path2:\"wfp' \\<turnstile> (Main, Entry) -as'\\<rightarrow>* (Main, Label l')\"\n        and intra2:\"\\<forall>a\\<in>set as'. intra_kind (kind a)\" by blast\n      from path1 intra1\n      have \"wfp \\<turnstile> (Main, Label l' \\<oplus> #:c\\<^sub>1) -as \\<oplus>s #:c\\<^sub>1\\<rightarrow>* (Main, Exit \\<oplus> #:c\\<^sub>1)\"\n        by -(rule path_Main_SeqSecond,auto)\n      moreover\n      from path2 have \"as' \\<noteq> []\" by(fastforce elim:ProcCFG.path.cases)\n      with path2 obtain ax' asx' where [simp]:\"as' = ax'#asx'\"\n        and \"sourcenode ax' = (Main, Entry)\" and \"valid_edge wfp' ax'\" \n        and \"wfp' \\<turnstile> targetnode ax' -asx'\\<rightarrow>* (Main, Label l')\"\n        by -(erule ProcCFG.path_split_Cons,fastforce+)\n      from \\<open>wfp' \\<turnstile> targetnode ax' -asx'\\<rightarrow>* (Main, Label l')\\<close>\n      have \"targetnode ax' \\<noteq> (Main,Exit)\" by fastforce\n      with \\<open>valid_edge wfp' ax'\\<close> \\<open>sourcenode ax' = (Main, Entry)\\<close> wf\n      have \"targetnode ax' = (Main,Label 0)\"\n        by(fastforce elim:PCFG.cases dest:Proc_CFG_EntryD simp:valid_edge_def)\n      with \\<open>wfp' \\<turnstile> targetnode ax' -asx'\\<rightarrow>* (Main, Label l')\\<close> intra2\n      have path3:\"wfp \\<turnstile> (Main,Label 0 \\<oplus> #:c\\<^sub>1) -asx' \\<oplus>s #:c\\<^sub>1\\<rightarrow>* \n        (Main, Label l' \\<oplus> #:c\\<^sub>1)\" by -(rule path_Main_SeqSecond,auto)\n      from \\<open>Rep_wf_prog wfp = (c\\<^sub>1;; c\\<^sub>2, procs)\\<close>\n      obtain wfp'' where [simp]:\"Rep_wf_prog wfp'' = (c\\<^sub>1, procs)\" by(erule wfp_Seq1)\n      from IH1[OF _ this,of \"0\"] obtain xs \n        where \"wfp'' \\<turnstile> (Main, Label 0) -xs\\<rightarrow>* (Main, Exit)\"\n        and \"\\<forall>a\\<in>set xs. intra_kind (kind a)\" by blast\n      from \\<open>wfp'' \\<turnstile> (Main, Label 0) -xs\\<rightarrow>* (Main, Exit)\\<close> have \"xs \\<noteq> []\"\n        by(fastforce elim:ProcCFG.path.cases)\n      then obtain x xs' where [simp]:\"xs = xs'@[x]\"\n        by(cases xs rule:rev_cases) fastforce+\n      with \\<open>wfp'' \\<turnstile> (Main, Label 0) -xs\\<rightarrow>* (Main, Exit)\\<close>\n      have \"wfp'' \\<turnstile> (Main, Label 0) -xs'\\<rightarrow>* sourcenode x\"\n        and \"valid_edge wfp'' x\" and \"targetnode x = (Main, Exit)\"\n        by(auto elim:ProcCFG.path_split_snoc)\n      from \\<open>valid_edge wfp'' x\\<close> \\<open>targetnode x = (Main, Exit)\\<close>\n      obtain nx where \"sourcenode x = (Main,nx)\" \n        by(fastforce elim:PCFG.cases simp:valid_edge_def)\n      with \\<open>wfp'' \\<turnstile> (Main, Label 0) -xs'\\<rightarrow>* sourcenode x\\<close> have \"nx \\<noteq> Entry\"\n        by fastforce\n      from \\<open>valid_edge wfp'' x\\<close> \\<open>sourcenode x = (Main,nx)\\<close> have \"nx \\<noteq> Exit\"\n        by(fastforce intro:ProcCFGExit.Exit_source)\n      with \\<open>nx \\<noteq> Entry\\<close> obtain lx where [simp]:\"nx = Label lx\" by(cases nx) auto\n      from \\<open>wfp'' \\<turnstile> (Main, Label 0) -xs'\\<rightarrow>* sourcenode x\\<close> \n        \\<open>sourcenode x = (Main,nx)\\<close> \\<open>\\<forall>a\\<in>set xs. intra_kind (kind a)\\<close>\n      have \"wfp \\<turnstile> (Main, Entry) \n        -((Main, Entry),(\\<lambda>s. True)\\<^sub>\\<surd>,(Main, Label 0))#xs'\\<rightarrow>* sourcenode x\"\n        apply simp apply(rule path_SeqFirst[OF \\<open>Rep_wf_prog wfp'' = (c\\<^sub>1, procs)\\<close>])\n        apply(auto intro!:ProcCFG.Cons_path)\n        by(auto intro:Main Proc_CFG_Entry simp:valid_edge_def intra_kind_def)\n      with \\<open>valid_edge wfp'' x\\<close> \\<open>targetnode x = (Main, Exit)\\<close> path3\n        \\<open>sourcenode x = (Main,nx)\\<close> \\<open>nx \\<noteq> Entry\\<close> \\<open>sourcenode x = (Main,nx)\\<close> wf\n      have \"wfp \\<turnstile> (Main, Entry) -((((Main, Entry),(\\<lambda>s. True)\\<^sub>\\<surd>,(Main, Label 0))#xs')@\n        [(sourcenode x,kind x,(Main,Label #:c\\<^sub>1))])@(asx' \\<oplus>s #:c\\<^sub>1)\\<rightarrow>* \n        (Main, Label l' \\<oplus> #:c\\<^sub>1)\" \n        by(fastforce intro:ProcCFG.path_Append ProcCFG.path.intros Main \n          Proc_CFG_SeqConnect elim!:PCFG.cases dest:Proc_CFG_Call_Labels\n          simp:ProcCFG.valid_node_def valid_edge_def)\n      ultimately show ?thesis using intra1 intra2 \\<open>\\<forall>a\\<in>set xs. intra_kind (kind a)\\<close>\n        by(fastforce simp:label_incrs_def intra_kind_def)\n    qed\n  next\n    case (Cond b c\\<^sub>1 c\\<^sub>2)\n    note IH1 = \\<open>\\<And>l wfp. \\<lbrakk>l < #:c\\<^sub>1; Rep_wf_prog wfp = (c\\<^sub>1, procs)\\<rbrakk> \\<Longrightarrow>\n      \\<exists>as as'. wfp \\<turnstile> (Main, Label l) -as\\<rightarrow>* (Main, Exit) \\<and> \n      (\\<forall>a\\<in>set as. intra_kind (kind a)) \\<and>\n      wfp \\<turnstile> (Main, Entry) -as'\\<rightarrow>* (Main, Label l) \\<and> (\\<forall>a\\<in>set as'. intra_kind (kind a))\\<close>\n    note IH2 = \\<open>\\<And>l wfp. \\<lbrakk>l < #:c\\<^sub>2; Rep_wf_prog wfp = (c\\<^sub>2, procs)\\<rbrakk> \\<Longrightarrow>\n      \\<exists>as as'. wfp \\<turnstile> (Main, Label l) -as\\<rightarrow>* (Main, Exit) \\<and> \n      (\\<forall>a\\<in>set as. intra_kind (kind a)) \\<and>\n      wfp \\<turnstile> (Main, Entry) -as'\\<rightarrow>* (Main, Label l) \\<and> (\\<forall>a\\<in>set as'. intra_kind (kind a))\\<close>\n    note [simp] = \\<open>Rep_wf_prog wfp = (if (b) c\\<^sub>1 else c\\<^sub>2, procs)\\<close>\n    show ?case\n    proof(cases \"l = 0\")\n      case True\n      from \\<open>Rep_wf_prog wfp = (if (b) c\\<^sub>1 else c\\<^sub>2, procs)\\<close>\n      obtain wfp' where [simp]:\"Rep_wf_prog wfp' = (c\\<^sub>1, procs)\" by(erule wfp_CondTrue)\n      from IH1[OF _ this,of 0] obtain as \n        where path:\"wfp' \\<turnstile> (Main, Label 0) -as\\<rightarrow>* (Main, Exit)\"\n        and intra:\"\\<forall>a\\<in>set as. intra_kind (kind a)\" by blast\n      have \"if (b) c\\<^sub>1 else c\\<^sub>2,procs \\<turnstile> (Main,Label 0)\n        -(\\<lambda>cf. state_check cf b (Some true))\\<^sub>\\<surd>\\<rightarrow> (Main,Label 0 \\<oplus> 1)\"\n        by(fastforce intro:Main Proc_CFG_CondTrue)\n      with path intra have \"wfp \\<turnstile> (Main,Label 0)\n        -[((Main,Label 0),(\\<lambda>cf. state_check cf b (Some true))\\<^sub>\\<surd>,(Main,Label 0 \\<oplus> 1))]@\n        (as \\<oplus>s 1)\\<rightarrow>* (Main,Exit \\<oplus> 1)\"\n        apply - apply(rule ProcCFG.path_Append) apply(rule ProcCFG.path.intros)+\n        prefer 5 apply(rule path_Main_CondTrue)\n        apply(auto intro:ProcCFG.path.intros simp:valid_edge_def)\n        by(fastforce simp:ProcCFG.valid_node_def valid_edge_def)\n      moreover\n      have \"if (b) c\\<^sub>1 else c\\<^sub>2,procs \\<turnstile> (Main,Entry) -(\\<lambda>s. True)\\<^sub>\\<surd>\\<rightarrow> \n        (Main,Label 0)\" by(fastforce intro:Main Proc_CFG_Entry)\n      hence \"wfp \\<turnstile> (Main,Entry) -[((Main,Entry),(\\<lambda>s. True)\\<^sub>\\<surd>,(Main,Label 0))]\\<rightarrow>* \n        (Main,Label 0)\"\n        by(fastforce intro:ProcCFG.path.intros \n                    simp:ProcCFG.valid_node_def valid_edge_def)\n      ultimately show ?thesis using \\<open>l = 0\\<close> \\<open>\\<forall>a\\<in>set as. intra_kind (kind a)\\<close> \n        by(fastforce simp:label_incrs_def intra_kind_def)\n    next\n      case False\n      hence \"0 < l\" by simp\n      then obtain l' where [simp]:\"l = l' + 1\" and \"l' = l - 1\" by simp\n      show ?thesis\n      proof(cases \"l' < #:c\\<^sub>1\")\n        case True\n        from \\<open>Rep_wf_prog wfp = (if (b) c\\<^sub>1 else c\\<^sub>2, procs)\\<close>\n        obtain wfp' where [simp]:\"Rep_wf_prog wfp' = (c\\<^sub>1, procs)\" \n          by(erule wfp_CondTrue)\n        from IH1[OF True this] obtain as as' \n          where path1:\"wfp' \\<turnstile> (Main, Label l') -as\\<rightarrow>* (Main, Exit)\"\n          and intra1:\"\\<forall>a\\<in>set as. intra_kind (kind a)\"\n          and path2:\"wfp' \\<turnstile> (Main, Entry) -as'\\<rightarrow>* (Main, Label l')\"\n          and intra2:\"\\<forall>a\\<in>set as'. intra_kind (kind a)\" by blast\n        from path1 intra1\n        have \"wfp \\<turnstile> (Main, Label l' \\<oplus> 1) -as \\<oplus>s 1\\<rightarrow>* (Main, Exit \\<oplus> 1)\"\n          by -(rule path_Main_CondTrue,auto)\n        moreover\n        from path2 obtain ax' asx' where [simp]:\"as' = ax'#asx'\"\n          and \"sourcenode ax' = (Main,Entry)\" and \"valid_edge wfp' ax'\"\n          and \"wfp' \\<turnstile> targetnode ax' -asx'\\<rightarrow>* (Main, Label l')\"\n          by -(erule ProcCFG.path.cases,fastforce+)\n        with wf have \"targetnode ax' = (Main,Label 0)\"\n          by(fastforce elim:PCFG.cases dest:Proc_CFG_EntryD Proc_CFG_Call_Labels \n                      simp:valid_edge_def)\n        with \\<open>wfp' \\<turnstile> targetnode ax' -asx'\\<rightarrow>* (Main, Label l')\\<close> intra2\n        have \"wfp \\<turnstile> (Main,Entry) -((Main,Entry),(\\<lambda>s. True)\\<^sub>\\<surd>,(Main,Label 0))#\n          ((Main,Label 0),(\\<lambda>cf. state_check cf b (Some true))\\<^sub>\\<surd>,(Main,Label 0 \\<oplus> 1))#\n          (asx' \\<oplus>s 1)\\<rightarrow>* (Main,Label l' \\<oplus> 1)\"\n          apply - apply(rule ProcCFG.path.intros)+ apply(rule path_Main_CondTrue) \n          by(auto intro:Main Proc_CFG_Entry Proc_CFG_CondTrue simp:valid_edge_def)\n        ultimately show ?thesis using intra1 intra2\n          by(fastforce simp:label_incrs_def intra_kind_def)\n      next\n        case False\n        hence \"#:c\\<^sub>1 \\<le> l'\" by simp\n        then obtain l'' where [simp]:\"l' = l'' + #:c\\<^sub>1\" and \"l'' = l' - #:c\\<^sub>1\" by simp\n        from  \\<open>l < #:(if (b) c\\<^sub>1 else c\\<^sub>2)\\<close> have \"l'' < #:c\\<^sub>2\" by simp\n        from \\<open>Rep_wf_prog wfp = (if (b) c\\<^sub>1 else c\\<^sub>2, procs)\\<close>\n        obtain wfp'' where [simp]:\"Rep_wf_prog wfp'' = (c\\<^sub>2, procs)\" \n          by(erule wfp_CondFalse)\n        from IH2[OF \\<open>l'' < #:c\\<^sub>2\\<close> this] obtain as as' \n          where path1:\"wfp'' \\<turnstile> (Main, Label l'') -as\\<rightarrow>* (Main, Exit)\"\n          and intra1:\"\\<forall>a\\<in>set as. intra_kind (kind a)\"\n          and path2:\"wfp'' \\<turnstile> (Main, Entry) -as'\\<rightarrow>* (Main, Label l'')\"\n          and intra2:\"\\<forall>a\\<in>set as'. intra_kind (kind a)\" by blast\n        from path1 intra1\n        have \"wfp \\<turnstile> (Main, Label l'' \\<oplus> (#:c\\<^sub>1 + 1)) -as \\<oplus>s (#:c\\<^sub>1 + 1)\\<rightarrow>* \n          (Main, Exit \\<oplus> (#:c\\<^sub>1 + 1))\"\n          by -(rule path_Main_CondFalse,auto simp:add.assoc)\n        moreover\n        from path2 obtain ax' asx' where [simp]:\"as' = ax'#asx'\"\n          and \"sourcenode ax' = (Main,Entry)\" and \"valid_edge wfp'' ax'\"\n          and \"wfp'' \\<turnstile> targetnode ax' -asx'\\<rightarrow>* (Main, Label l'')\"\n          by -(erule ProcCFG.path.cases,fastforce+)\n        with wf have \"targetnode ax' = (Main,Label 0)\"\n          by(fastforce elim:PCFG.cases dest:Proc_CFG_EntryD Proc_CFG_Call_Labels \n                      simp:valid_edge_def)\n        with \\<open>wfp'' \\<turnstile> targetnode ax' -asx'\\<rightarrow>* (Main, Label l'')\\<close> intra2\n        have \"wfp \\<turnstile> (Main,Entry) -((Main,Entry),(\\<lambda>s. True)\\<^sub>\\<surd>,(Main,Label 0))#\n          ((Main,Label 0),(\\<lambda>cf. state_check cf b (Some false))\\<^sub>\\<surd>,\n          (Main,Label (#:c\\<^sub>1 + 1)))#(asx' \\<oplus>s (#:c\\<^sub>1 + 1))\\<rightarrow>* \n          (Main,Label l'' \\<oplus> (#:c\\<^sub>1 + 1))\"\n          apply - apply(rule ProcCFG.path.intros)+ apply(rule path_Main_CondFalse)\n          by(auto intro:Main Proc_CFG_Entry Proc_CFG_CondFalse simp:valid_edge_def)\n        ultimately show ?thesis using intra1 intra2\n          by(fastforce simp:label_incrs_def intra_kind_def add.assoc)\n      qed\n    qed\n  next\n    case (While b c')\n    note IH = \\<open>\\<And>l wfp. \\<lbrakk>l < #:c'; Rep_wf_prog wfp = (c', procs)\\<rbrakk> \\<Longrightarrow>\n      \\<exists>as as'. wfp \\<turnstile> (Main, Label l) -as\\<rightarrow>* (Main, Exit) \\<and>\n      (\\<forall>a\\<in>set as. intra_kind (kind a)) \\<and>\n      wfp \\<turnstile> (Main, Entry) -as'\\<rightarrow>* (Main, Label l) \\<and> (\\<forall>a\\<in>set as'. intra_kind (kind a))\\<close>\n    note [simp] = \\<open>Rep_wf_prog wfp = (while (b) c', procs)\\<close>\n    show ?case\n    proof(cases \"l = 0\")\n      case True\n      hence \"wfp \\<turnstile> (Main,Label l) - \n        ((Main,Label 0),(\\<lambda>cf. state_check cf b (Some false))\\<^sub>\\<surd>,(Main,Label 1))#\n        [((Main,Label 1),\\<Up>id,(Main,Exit))]\\<rightarrow>* (Main,Exit)\"\n        by(fastforce intro:ProcCFG.path.intros Main Proc_CFG_WhileFalseSkip \n          Proc_CFG_WhileFalse simp:valid_edge_def)\n      moreover\n      have \"while (b) c' \\<turnstile> Entry -IEdge (\\<lambda>s. True)\\<^sub>\\<surd>\\<rightarrow>\\<^sub>p Label 0\" by(rule Proc_CFG_Entry)\n      with \\<open>l = 0\\<close> have \"wfp \\<turnstile> (Main,Entry) \n        -[((Main,Entry),(\\<lambda>s. True)\\<^sub>\\<surd>,(Main,Label 0))]\\<rightarrow>* (Main,Label l)\"\n        by(fastforce intro:ProcCFG.path.intros Main \n                     simp:ProcCFG.valid_node_def valid_edge_def)\n      ultimately show ?thesis by(fastforce simp:intra_kind_def)\n    next\n      case False\n      hence \"1 \\<le> l\" by simp\n      thus ?thesis\n      proof(cases \"l < 2\")\n        case True\n        with \\<open>1 \\<le> l\\<close> have [simp]:\"l = 1\" by simp\n        have \"wfp \\<turnstile> (Main,Label l) -[((Main,Label 1),\\<Up>id,(Main,Exit))]\\<rightarrow>* (Main,Exit)\"\n          by(fastforce intro:ProcCFG.path.intros Main Proc_CFG_WhileFalseSkip \n                      simp:valid_edge_def)\n        moreover\n        have \"while (b) c' \\<turnstile> Label 0 -IEdge (\\<lambda>cf. state_check cf b (Some false))\\<^sub>\\<surd>\\<rightarrow>\\<^sub>p \n          Label 1\" by(rule Proc_CFG_WhileFalse)\n        hence \"wfp \\<turnstile> (Main,Entry) -((Main,Entry),(\\<lambda>s. True)\\<^sub>\\<surd>,(Main,Label 0))#\n          [((Main,Label 0),(\\<lambda>cf. state_check cf b (Some false))\\<^sub>\\<surd>,(Main,Label 1))]\\<rightarrow>*\n          (Main,Label l)\"\n          by(fastforce intro:ProcCFG.path.intros Main Proc_CFG_Entry \n                       simp:ProcCFG.valid_node_def valid_edge_def)\n        ultimately show ?thesis by(fastforce simp:intra_kind_def)\n      next\n        case False\n        with \\<open>1 \\<le> l\\<close> have \"2 \\<le> l\" by simp\n        then obtain l' where [simp]:\"l = l' + 2\" and \"l' = l - 2\" \n          by(simp del:add_2_eq_Suc')\n        from \\<open>l < #:while (b) c'\\<close> have \"l' < #:c'\" by simp\n        from \\<open>Rep_wf_prog wfp = (while (b) c', procs)\\<close>\n        obtain wfp' where [simp]:\"Rep_wf_prog wfp' = (c', procs)\" \n          by(erule wfp_WhileBody)\n        from IH[OF \\<open>l' < #:c'\\<close> this] obtain as as' \n          where path1:\"wfp' \\<turnstile> (Main, Label l') -as\\<rightarrow>* (Main, Exit)\"\n          and intra1:\"\\<forall>a\\<in>set as. intra_kind (kind a)\"\n          and path2:\"wfp' \\<turnstile> (Main, Entry) -as'\\<rightarrow>* (Main, Label l')\"\n          and intra2:\"\\<forall>a\\<in>set as'. intra_kind (kind a)\" by blast\n        from path1 have \"as \\<noteq> []\" by(fastforce elim:ProcCFG.path.cases)\n        with path1 obtain ax asx where [simp]:\"as = asx@[ax]\"\n          and \"wfp' \\<turnstile> (Main, Label l') -asx\\<rightarrow>* sourcenode ax\"\n          and \"valid_edge wfp' ax\" and \"targetnode ax = (Main, Exit)\"\n          by -(erule ProcCFG.path_split_snoc,fastforce+)\n        with wf obtain lx etx where \"sourcenode ax = (Main,Label lx)\"\n          and \"intra_kind (kind ax)\"\n          apply(auto elim!:PCFG.cases dest:Proc_CFG_Call_Labels simp:valid_edge_def)\n          by(case_tac n)(auto dest:Proc_CFG_IEdge_intra_kind)\n        with \\<open>wfp' \\<turnstile> (Main, Label l') -asx\\<rightarrow>* sourcenode ax\\<close> intra1\n        have \"wfp \\<turnstile> (Main, Label l' \\<oplus> 2) -asx \\<oplus>s 2\\<rightarrow>* (Main,Label lx \\<oplus> 2)\"\n          by -(rule path_Main_WhileBody,auto)\n        from \\<open>valid_edge wfp' ax\\<close> \\<open>sourcenode ax = (Main,Label lx)\\<close>\n          \\<open>targetnode ax = (Main, Exit)\\<close> \\<open>intra_kind (kind ax)\\<close> wf\n        have \"while (b) c',procs \\<turnstile> (Main,Label lx \\<oplus> 2) -kind ax\\<rightarrow> \n          (Main,Label 0)\"\n          by(fastforce intro!:Main Proc_CFG_WhileBodyExit elim!:PCFG.cases \n                        dest:Proc_CFG_Call_Labels simp:valid_edge_def)\n        hence \"wfp \\<turnstile> (Main,Label lx \\<oplus> 2) \n          -((Main,Label lx \\<oplus> 2),kind ax,(Main,Label 0))#\n          ((Main,Label 0),(\\<lambda>cf. state_check cf b (Some false))\\<^sub>\\<surd>,(Main,Label 1))#\n          [((Main,Label 1),\\<Up>id,(Main,Exit))]\\<rightarrow>* (Main,Exit)\"\n          by(fastforce intro:ProcCFG.path.intros Main Proc_CFG_WhileFalse \n            Proc_CFG_WhileFalseSkip simp:valid_edge_def)\n        with \\<open>wfp \\<turnstile> (Main, Label l' \\<oplus> 2) -asx \\<oplus>s 2\\<rightarrow>* (Main,Label lx \\<oplus> 2)\\<close>\n        have \"wfp \\<turnstile> (Main, Label l) -(asx \\<oplus>s 2)@\n          (((Main,Label lx \\<oplus> 2),kind ax,(Main,Label 0))#\n          ((Main,Label 0),(\\<lambda>cf. state_check cf b (Some false))\\<^sub>\\<surd>,(Main,Label 1))#\n          [((Main,Label 1),\\<Up>id,(Main,Exit))])\\<rightarrow>* (Main,Exit)\"\n          by(fastforce intro:ProcCFG.path_Append)\n        moreover\n        from path2 have \"as' \\<noteq> []\" by(fastforce elim:ProcCFG.path.cases)\n        with path2 obtain ax' asx' where [simp]:\"as' = ax'#asx'\"\n          and \"wfp' \\<turnstile> targetnode ax' -asx'\\<rightarrow>* (Main,Label l')\"\n          and \"valid_edge wfp' ax'\" and \"sourcenode ax' = (Main, Entry)\"\n          by -(erule ProcCFG.path_split_Cons,fastforce+)\n        with wf have \"targetnode ax' = (Main,Label 0)\" and \"intra_kind (kind ax')\"\n          by(fastforce elim!:PCFG.cases dest:Proc_CFG_Call_Labels \n            Proc_CFG_EntryD simp:intra_kind_def valid_edge_def)+\n        with \\<open>wfp' \\<turnstile> targetnode ax' -asx'\\<rightarrow>* (Main,Label l')\\<close> intra2\n        have \"wfp \\<turnstile> (Main, Label 0 \\<oplus> 2) -asx' \\<oplus>s 2\\<rightarrow>* (Main,Label l' \\<oplus> 2)\"\n          by -(rule path_Main_WhileBody,auto simp del:add_2_eq_Suc')\n        hence \"wfp \\<turnstile> (Main,Entry) -((Main,Entry),(\\<lambda>s. True)\\<^sub>\\<surd>,(Main,Label 0))#\n          ((Main,Label 0),(\\<lambda>cf. state_check cf b (Some true))\\<^sub>\\<surd>,(Main,Label 2))#\n          (asx' \\<oplus>s 2)\\<rightarrow>* (Main,Label l)\"\n          by(fastforce intro:ProcCFG.path.intros Main Proc_CFG_WhileTrue \n            Proc_CFG_Entry simp:valid_edge_def)\n        ultimately show ?thesis using \\<open>intra_kind (kind ax)\\<close> intra1 intra2\n          by(fastforce simp:label_incrs_def intra_kind_def)\n      qed\n    qed\n  next\n    case (Call p es rets)\n    note Rep [simp] = \\<open>Rep_wf_prog wfp = (Call p es rets, procs)\\<close>\n    have cC:\"containsCall procs (Call p es rets) [] p\" by simp\n    show ?case\n    proof(cases \"l = 0\")\n      case True\n      have \"wfp \\<turnstile> (Main,Label 0) -((Main,Label 0),(\\<lambda>s. False)\\<^sub>\\<surd>,(Main,Label 1))#\n        [((Main,Label 1),\\<Up>id,(Main,Exit))]\\<rightarrow>* (Main,Exit)\"\n        by(fastforce intro:ProcCFG.path.intros Main Proc_CFG_CallSkip MainCallReturn\n          Proc_CFG_Call simp:valid_edge_def)\n      moreover\n      have \"Call p es rets,procs \\<turnstile> (Main,Entry) -(\\<lambda>s. True)\\<^sub>\\<surd>\\<rightarrow> (Main,Label 0)\"\n        by(fastforce intro:Main Proc_CFG_Entry)\n      hence \"wfp \\<turnstile> (Main,Entry) -[((Main,Entry),(\\<lambda>s. True)\\<^sub>\\<surd>,(Main,Label 0))]\\<rightarrow>*\n        (Main,Label 0)\"\n        by(fastforce intro:ProcCFG.path.intros \n          simp:ProcCFG.valid_node_def valid_edge_def)\n      ultimately show ?thesis using \\<open>l = 0\\<close> by(fastforce simp:intra_kind_def)\n    next\n      case False\n      with \\<open>l < #:Call p es rets\\<close> have \"l = 1\" by simp\n      have \"wfp \\<turnstile> (Main,Label 1) -[((Main,Label 1),\\<Up>id,(Main,Exit))]\\<rightarrow>* (Main,Exit)\"\n        by(fastforce intro:ProcCFG.path.intros Main Proc_CFG_CallSkip\n                    simp:valid_edge_def)\n      moreover\n      have \"Call p es rets,procs \\<turnstile> (Main,Label 0) -(\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow> (Main,Label 1)\"\n        by(fastforce intro:MainCallReturn Proc_CFG_Call)\n      hence \"wfp \\<turnstile> (Main,Entry) -((Main,Entry),(\\<lambda>s. True)\\<^sub>\\<surd>,(Main,Label 0))#\n        [((Main,Label 0),(\\<lambda>s. False)\\<^sub>\\<surd>,(Main,Label 1))]\\<rightarrow>* (Main,Label 1)\"\n        by(fastforce intro:ProcCFG.path.intros Main Proc_CFG_Entry \n                    simp:ProcCFG.valid_node_def valid_edge_def)\n      ultimately show ?thesis using \\<open>l = 1\\<close> by(fastforce simp:intra_kind_def)\n    qed\n  qed\nqed\n\n\n\nsubsection \\<open>Lifting from edges in procedure Main to arbitrary procedures\\<close>\n\nlemma lift_edge_Main_Main:\n  \"\\<lbrakk>c,procs \\<turnstile> (Main, n) -et\\<rightarrow> (Main, n'); (p,ins,outs,c) \\<in> set procs;\n  containsCall procs prog ps p; well_formed procs\\<rbrakk> \n  \\<Longrightarrow> prog,procs \\<turnstile> (p, n) -et\\<rightarrow> (p, n')\"\nproof(induct \"(Main,n)\" et \"(Main,n')\" rule:PCFG.induct)\n  case Main thus ?case by(fastforce intro:Proc)\nnext\n  case MainCallReturn thus ?case by(fastforce intro:ProcCallReturn)\nqed auto\n\nlemma lift_edge_Main_Proc:\n  \"\\<lbrakk>c,procs \\<turnstile> (Main, n) -et\\<rightarrow> (q, n'); q \\<noteq> Main; (p,ins,outs,c) \\<in> set procs;\n  containsCall procs prog ps p; well_formed procs\\<rbrakk> \n  \\<Longrightarrow> \\<exists>et'. prog,procs \\<turnstile> (p, n) -et'\\<rightarrow> (q, n')\"\nproof(induct \"(Main,n)\" et \"(q,n')\" rule:PCFG.induct)\n  case (MainCall l esx retsx n'x insx outsx cx)\n  from \\<open>c \\<turnstile> Label l -CEdge (q, esx, retsx)\\<rightarrow>\\<^sub>p n'x\\<close> \n  obtain l' where [simp]:\"n'x = Label l'\" by(fastforce dest:Proc_CFG_Call_Labels)\n  with MainCall have \"prog,procs \\<turnstile> (p, n) \n    -(\\<lambda>s. True):(p,n'x)\\<hookrightarrow>\\<^bsub>q\\<^esub>map (\\<lambda>e cf. interpret e cf) esx\\<rightarrow> (q, n')\"\n    by(fastforce intro:ProcCall)\n  thus ?case by fastforce\nqed auto\n\nlemma lift_edge_Proc_Main:\n  \"\\<lbrakk>c,procs \\<turnstile> (q, n) -et\\<rightarrow> (Main, n'); q \\<noteq> Main; (p,ins,outs,c) \\<in> set procs;\n  containsCall procs prog ps p; well_formed procs\\<rbrakk> \n  \\<Longrightarrow> \\<exists>et'. prog,procs \\<turnstile> (q, n) -et'\\<rightarrow> (p, n')\"\nproof(induct \"(q,n)\" et \"(Main,n')\" rule:PCFG.induct)\n  case (MainReturn l esx retsx l' insx outsx cx)\n  note [simp] = \\<open>Exit = n\\<close>[THEN sym] \\<open>Label l' = n'\\<close>[THEN sym]\n  from MainReturn have \"prog,procs \\<turnstile> (q,Exit) -(\\<lambda>cf. snd cf = (p,Label l'))\\<hookleftarrow>\\<^bsub>q\\<^esub>\n    (\\<lambda>cf cf'. cf'(retsx [:=] map cf outsx))\\<rightarrow> (p,Label l')\"\n    by(fastforce intro!:ProcReturn)\n  thus ?case by fastforce\nqed auto\n\n\nfun lift_edge :: \"edge \\<Rightarrow> pname \\<Rightarrow> edge\"\nwhere \"lift_edge a p = ((p,snd(sourcenode a)),kind a,(p,snd(targetnode a)))\"\n\nfun lift_path :: \"edge list \\<Rightarrow> pname \\<Rightarrow> edge list\"\n  where \"lift_path as p = map (\\<lambda>a. lift_edge a p) as\"\n\n\nlemma lift_path_Proc: \n  assumes \"Rep_wf_prog wfp' = (c,procs)\" and \"Rep_wf_prog wfp = (prog,procs)\"\n  and \"(p,ins,outs,c) \\<in> set procs\" and \"containsCall procs prog ps p\"\n  shows \"\\<lbrakk>wfp' \\<turnstile> (Main,n) -as\\<rightarrow>* (Main,n'); \\<forall>a \\<in> set as. intra_kind (kind a)\\<rbrakk>\n  \\<Longrightarrow> wfp \\<turnstile> (p,n) -lift_path as p\\<rightarrow>* (p,n')\"\nproof(induct \"(Main,n)\" as \"(Main,n')\" arbitrary:n rule:ProcCFG.path.induct)\n  case empty_path\n  from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> have wf:\"well_formed procs\" \n    by(fastforce intro:wf_wf_prog)\n  from \\<open>CFG.valid_node sourcenode targetnode (valid_edge wfp') (Main, n')\\<close>\n    assms wf\n  have \"CFG.valid_node sourcenode targetnode (valid_edge wfp) (p,n')\"\n    apply(auto simp:ProcCFG.valid_node_def valid_edge_def)\n     apply(case_tac \"ab = Main\")\n      apply(fastforce dest:lift_edge_Main_Main)\n     apply(fastforce dest!:lift_edge_Main_Proc)\n    apply(case_tac \"a = Main\")\n     apply(fastforce dest:lift_edge_Main_Main)\n    by(fastforce dest!:lift_edge_Proc_Main)\n  thus ?case by(fastforce dest:ProcCFG.empty_path)\nnext\n  case (Cons_path m'' as a n)\n  note IH = \\<open>\\<And>n. \\<lbrakk>m'' = (Main, n); \\<forall>a\\<in>set as. intra_kind (kind a)\\<rbrakk>\n    \\<Longrightarrow> wfp \\<turnstile> (p, n) -lift_path as p\\<rightarrow>* (p, n')\\<close>\n  from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> have wf:\"well_formed procs\" \n    by(fastforce intro:wf_wf_prog)\n  from \\<open>\\<forall>a\\<in>set (a # as). intra_kind (kind a)\\<close> have \"intra_kind (kind a)\"\n    and \"\\<forall>a\\<in>set as. intra_kind (kind a)\" by simp_all\n  from \\<open>valid_edge wfp' a\\<close> \\<open>intra_kind (kind a)\\<close> \\<open>sourcenode a = (Main, n)\\<close> \n    \\<open>targetnode a = m''\\<close> \\<open>Rep_wf_prog wfp' = (c,procs)\\<close>\n  obtain n'' where \"m'' = (Main, n'')\"\n    by(fastforce elim:PCFG.cases simp:valid_edge_def intra_kind_def)\n  with \\<open>valid_edge wfp' a\\<close> \\<open>Rep_wf_prog wfp' = (c,procs)\\<close>\n    \\<open>sourcenode a = (Main, n)\\<close> \\<open>targetnode a = m''\\<close>\n    \\<open>(p,ins,outs,c) \\<in> set procs\\<close> \\<open>containsCall procs prog ps p\\<close> \n    \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> wf\n  have \"prog,procs \\<turnstile> (p, n) -kind a\\<rightarrow> (p, n'')\"\n    by(auto intro:lift_edge_Main_Main simp:valid_edge_def)  \n  from IH[OF \\<open>m'' = (Main, n'')\\<close> \\<open>\\<forall>a\\<in>set as. intra_kind (kind a)\\<close>]\n  have \"wfp \\<turnstile> (p, n'') -lift_path as p\\<rightarrow>* (p, n')\" .\n  with \\<open>prog,procs \\<turnstile> (p, n) -kind a\\<rightarrow> (p, n'')\\<close> \\<open>Rep_wf_prog wfp = (prog,procs)\\<close>\n    \\<open>sourcenode a = (Main, n)\\<close> \\<open>targetnode a = m''\\<close> \\<open>m'' = (Main, n'')\\<close>\n  show ?case by simp (rule ProcCFG.Cons_path,auto simp:valid_edge_def)\nqed\n\n\nsubsection \\<open>Existence of paths from Entry and to Exit\\<close>\n\nlemma Label_Proc_CFG_Entry_Exit_path_Proc:\n  assumes \"Rep_wf_prog wfp = (prog,procs)\" and \"l < #:c\"\n  and \"(p,ins,outs,c) \\<in> set procs\" and \"containsCall procs prog ps p\"\n  obtains as as' where \"wfp \\<turnstile> (p,Label l) -as\\<rightarrow>* (p,Exit)\"\n  and \"\\<forall>a \\<in> set as. intra_kind (kind a)\"\n  and \"wfp \\<turnstile> (p,Entry) -as'\\<rightarrow>* (p,Label l)\"\n  and \"\\<forall>a \\<in> set as'. intra_kind (kind a)\"\nproof(atomize_elim)\n  from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \\<open>(p,ins,outs,c) \\<in> set procs\\<close>\n    \\<open>containsCall procs prog ps p\\<close>\n  obtain wfp' where \"Rep_wf_prog wfp' = (c,procs)\" by(erule wfp_Call)\n  from this \\<open>l < #:c\\<close> obtain as as' where \"wfp' \\<turnstile> (Main,Label l) -as\\<rightarrow>* (Main,Exit)\"\n    and \"\\<forall>a \\<in> set as. intra_kind (kind a)\"\n    and \"wfp' \\<turnstile> (Main,Entry) -as'\\<rightarrow>* (Main,Label l)\"\n    and \"\\<forall>a \\<in> set as'. intra_kind (kind a)\" \n    by(erule Label_Proc_CFG_Entry_Exit_path_Main)\n  from \\<open>Rep_wf_prog wfp' = (c,procs)\\<close> \\<open>Rep_wf_prog wfp = (prog,procs)\\<close>\n    \\<open>(p,ins,outs,c) \\<in> set procs\\<close> \\<open>containsCall procs prog ps p\\<close>\n    \\<open>wfp' \\<turnstile> (Main,Label l) -as\\<rightarrow>* (Main,Exit)\\<close> \\<open>\\<forall>a \\<in> set as. intra_kind (kind a)\\<close>\n  have \"wfp \\<turnstile> (p,Label l) -lift_path as p\\<rightarrow>* (p,Exit)\"\n    by(fastforce intro:lift_path_Proc)\n  moreover\n  from \\<open>Rep_wf_prog wfp' = (c,procs)\\<close> \\<open>Rep_wf_prog wfp = (prog,procs)\\<close>\n    \\<open>(p,ins,outs,c) \\<in> set procs\\<close> \\<open>containsCall procs prog ps p\\<close>\n    \\<open>wfp' \\<turnstile> (Main,Entry) -as'\\<rightarrow>* (Main,Label l)\\<close> \\<open>\\<forall>a \\<in> set as'. intra_kind (kind a)\\<close>\n  have \"wfp \\<turnstile> (p,Entry) -lift_path as' p\\<rightarrow>* (p,Label l)\"\n    by(fastforce intro:lift_path_Proc)\n  moreover\n  from \\<open>\\<forall>a \\<in> set as. intra_kind (kind a)\\<close> \\<open>\\<forall>a \\<in> set as'. intra_kind (kind a)\\<close>\n  have \"\\<forall>a \\<in> set (lift_path as p). intra_kind (kind a)\"\n    and \"\\<forall>a \\<in> set (lift_path as' p). intra_kind (kind a)\" by auto\n  ultimately\n  show \"\\<exists>as as'. wfp \\<turnstile> (p, Label l) -as\\<rightarrow>* (p, Exit) \\<and>\n    (\\<forall>a\\<in>set as. intra_kind (kind a)) \\<and> wfp \\<turnstile> (p, Entry) -as'\\<rightarrow>* (p, Label l) \\<and>\n    (\\<forall>a\\<in>set as'. intra_kind (kind a))\" by fastforce\nqed\n\n\nlemma Entry_to_Entry_and_Exit_to_Exit: \n  assumes \"Rep_wf_prog wfp = (prog,procs)\"\n  and \"containsCall procs prog ps p\" and \"(p,ins,outs,c) \\<in> set procs\"\n  obtains as as' where \"CFG.valid_path' sourcenode targetnode kind\n      (valid_edge wfp) (get_return_edges wfp) (Main,Entry) as (p,Entry)\"\n  and \"CFG.valid_path' sourcenode targetnode kind\n      (valid_edge wfp) (get_return_edges wfp) (p,Exit) as' (Main,Exit)\"\nproof(atomize_elim)\n  from \\<open>containsCall procs prog ps p\\<close> \\<open>(p,ins,outs,c) \\<in> set procs\\<close>\n  show \"\\<exists>as as'. CFG.valid_path' sourcenode targetnode kind (valid_edge wfp)\n    (get_return_edges wfp) (Main, Entry) as (p, Entry) \\<and>\n    CFG.valid_path' sourcenode targetnode kind (valid_edge wfp)\n    (get_return_edges wfp) (p, Exit) as' (Main, Exit)\"\n  proof(induct ps arbitrary:p ins outs c rule:rev_induct)\n    case Nil\n    from \\<open>containsCall procs prog [] p\\<close>\n    obtain lx es rets lx' where \"prog \\<turnstile> Label lx -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p Label lx'\"\n      by(erule containsCall_empty_Proc_CFG_Call_edge)\n    with \\<open>(p, ins, outs, c) \\<in> set procs\\<close>\n    have \"prog,procs \\<turnstile> (Main,Label lx) -(\\<lambda>s. True):(Main,Label lx')\\<hookrightarrow>\\<^bsub>p\\<^esub>\n      map (\\<lambda>e cf. interpret e cf) es\\<rightarrow>  (p,Entry)\" \n      and \"prog,procs \\<turnstile> (p,Exit) -(\\<lambda>cf. snd cf = (Main,Label lx'))\\<hookleftarrow>\\<^bsub>p\\<^esub>\n      (\\<lambda>cf cf'. cf'(rets [:=] map cf outs))\\<rightarrow> (Main,Label lx')\"\n      by -(rule MainCall,assumption+,rule MainReturn)\n    with \\<open>Rep_wf_prog wfp = (prog,procs)\\<close>\n    have \"wfp \\<turnstile> (Main,Label lx) -[((Main,Label lx),\n      (\\<lambda>s. True):(Main,Label lx')\\<hookrightarrow>\\<^bsub>p\\<^esub>map (\\<lambda>e cf. interpret e cf) es,(p,Entry))]\\<rightarrow>* \n      (p,Entry)\"\n      and \"wfp \\<turnstile> (p,Exit) -[((p,Exit),(\\<lambda>cf. snd cf = (Main,Label lx'))\\<hookleftarrow>\\<^bsub>p\\<^esub>\n      (\\<lambda>cf cf'. cf'(rets [:=] map cf outs)),(Main,Label lx'))]\\<rightarrow>* (Main,Label lx')\"\n      by(fastforce intro:ProcCFG.path.intros \n        simp:ProcCFG.valid_node_def valid_edge_def)+\n    moreover\n    from \\<open>prog \\<turnstile> Label lx -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p Label lx'\\<close>\n    have \"lx < #:prog\" and \"lx' < #:prog\"\n      by(auto intro:Proc_CFG_sourcelabel_less_num_nodes \n                    Proc_CFG_targetlabel_less_num_nodes)\n    from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \\<open>lx < #:prog\\<close> obtain as \n      where \"wfp \\<turnstile> (Main,Entry) -as\\<rightarrow>* (Main,Label lx)\"\n      and \"\\<forall>a \\<in> set as. intra_kind (kind a)\"\n      by -(erule Label_Proc_CFG_Entry_Exit_path_Main)\n    moreover\n    from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \\<open>lx' < #:prog\\<close> obtain as' \n      where \"wfp \\<turnstile> (Main,Label lx') -as'\\<rightarrow>* (Main,Exit)\"\n      and \"\\<forall>a \\<in> set as'. intra_kind (kind a)\"\n      by -(erule Label_Proc_CFG_Entry_Exit_path_Main)\n    moreover\n    from \\<open>\\<forall>a \\<in> set as. intra_kind (kind a)\\<close> \n    have \"CFG.valid_path kind (get_return_edges wfp) \n      (as@[((Main,Label lx),(\\<lambda>s. True):(Main,Label lx')\\<hookrightarrow>\\<^bsub>p\\<^esub>\n      map (\\<lambda>e cf. interpret e cf) es,(p,Entry))])\"\n      by(fastforce intro:ProcCFG.same_level_path_valid_path_Append \n        ProcCFG.intras_same_level_path simp:ProcCFG.valid_path_def)\n    moreover\n    from \\<open>\\<forall>a \\<in> set as'. intra_kind (kind a)\\<close> \n    have \"CFG.valid_path kind (get_return_edges wfp) \n      ([((p,Exit),(\\<lambda>cf. snd cf = (Main,Label lx'))\\<hookleftarrow>\\<^bsub>p\\<^esub>\n      (\\<lambda>cf cf'. cf'(rets [:=] map cf outs)),(Main,Label lx'))]@as')\"\n      by(fastforce intro:ProcCFG.valid_path_same_level_path_Append \n        ProcCFG.intras_same_level_path simp:ProcCFG.valid_path_def)\n    ultimately show ?case by(fastforce intro:ProcCFG.path_Append simp:ProcCFG.vp_def)\n  next\n    case (snoc p' ps')\n    note IH = \\<open>\\<And>p ins outs c. \n      \\<lbrakk>containsCall procs prog ps' p; (p,ins,outs,c) \\<in> set procs\\<rbrakk>\n      \\<Longrightarrow> \\<exists>as as'. CFG.valid_path' sourcenode targetnode kind (valid_edge wfp)\n      (get_return_edges wfp) (Main, Entry) as (p, Entry) \\<and>\n      CFG.valid_path' sourcenode targetnode kind (valid_edge wfp)\n      (get_return_edges wfp) (p, Exit) as' (Main, Exit)\\<close>\n    from \\<open>containsCall procs prog (ps' @ [p']) p\\<close>\n    obtain ins' outs' c' where \"(p',ins',outs',c') \\<in> set procs\"\n      and \"containsCall procs c' [] p\" \n      and \"containsCall procs prog ps' p'\" by(auto elim:containsCallE)\n    from IH[OF \\<open>containsCall procs prog ps' p'\\<close> \\<open>(p',ins',outs',c') \\<in> set procs\\<close>] \n    obtain as as' where pathE:\"CFG.valid_path' sourcenode targetnode kind \n      (valid_edge wfp) (get_return_edges wfp) (Main, Entry) as (p', Entry)\"\n      and pathX:\"CFG.valid_path' sourcenode targetnode kind (valid_edge wfp)\n      (get_return_edges wfp) (p', Exit) as' (Main, Exit)\" by blast\n    from \\<open>containsCall procs c' [] p\\<close>\n    obtain lx es rets lx' where edge:\"c' \\<turnstile> Label lx -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p Label lx'\"\n      by(erule containsCall_empty_Proc_CFG_Call_edge)\n    hence \"lx < #:c'\" and \"lx' < #:c'\"\n      by(auto intro:Proc_CFG_sourcelabel_less_num_nodes \n                    Proc_CFG_targetlabel_less_num_nodes)\n    from \\<open>lx < #:c'\\<close> \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \\<open>(p',ins',outs',c') \\<in> set procs\\<close>\n      \\<open>containsCall procs prog ps' p'\\<close> obtain asx \n      where \"wfp \\<turnstile> (p',Entry) -asx\\<rightarrow>* (p',Label lx)\"\n      and \"\\<forall>a \\<in> set asx. intra_kind (kind a)\"\n      by(fastforce elim:Label_Proc_CFG_Entry_Exit_path_Proc)\n    with pathE have pathE2:\"CFG.valid_path' sourcenode targetnode kind \n      (valid_edge wfp) (get_return_edges wfp) (Main, Entry) (as@asx) (p', Label lx)\"\n      by(fastforce intro:ProcCFG.path_Append ProcCFG.valid_path_same_level_path_Append\n        ProcCFG.intras_same_level_path simp:ProcCFG.vp_def)\n    from \\<open>lx' < #:c'\\<close> \\<open>Rep_wf_prog wfp = (prog,procs)\\<close>\n      \\<open>(p',ins',outs',c') \\<in> set procs\\<close> \\<open>containsCall procs prog ps' p'\\<close> \n    obtain asx' where \"wfp \\<turnstile> (p',Label lx') -asx'\\<rightarrow>* (p',Exit)\"\n      and \"\\<forall>a \\<in> set asx'. intra_kind (kind a)\"\n      by(fastforce elim:Label_Proc_CFG_Entry_Exit_path_Proc)\n    with pathX have pathX2:\"CFG.valid_path' sourcenode targetnode kind \n      (valid_edge wfp) (get_return_edges wfp) (p', Label lx') (asx'@as') (Main, Exit)\"\n      by(fastforce intro:ProcCFG.path_Append ProcCFG.same_level_path_valid_path_Append\n        ProcCFG.intras_same_level_path simp:ProcCFG.vp_def)\n    from edge \\<open>(p,ins,outs,c) \\<in> set procs\\<close> \\<open>(p',ins',outs',c') \\<in> set procs\\<close>\n      \\<open>containsCall procs prog ps' p'\\<close>\n    have \"prog,procs \\<turnstile> (p',Label lx) -(\\<lambda>s. True):(p',Label lx')\\<hookrightarrow>\\<^bsub>p\\<^esub>\n      map (\\<lambda>e cf. interpret e cf) es\\<rightarrow> (p,Entry)\"\n      and \"prog,procs \\<turnstile> (p,Exit) -(\\<lambda>cf. snd cf = (p',Label lx'))\\<hookleftarrow>\\<^bsub>p\\<^esub>\n      (\\<lambda>cf cf'. cf'(rets [:=] map cf outs))\\<rightarrow> (p',Label lx')\"\n      by(fastforce intro:ProcCall ProcReturn)+\n    with \\<open>Rep_wf_prog wfp = (prog,procs)\\<close>\n    have path:\"wfp \\<turnstile> (p',Label lx) -[((p',Label lx),(\\<lambda>s. True):(p',Label lx')\\<hookrightarrow>\\<^bsub>p\\<^esub>\n      map (\\<lambda>e cf. interpret e cf) es,(p,Entry))]\\<rightarrow>* (p,Entry)\"\n      and path':\"wfp \\<turnstile> (p,Exit) -[((p,Exit),(\\<lambda>cf. snd cf = (p',Label lx'))\\<hookleftarrow>\\<^bsub>p\\<^esub>\n      (\\<lambda>cf cf'. cf'(rets [:=] map cf outs)),(p',Label lx'))]\\<rightarrow>* \n      (p',Label lx')\"\n      by(fastforce intro:ProcCFG.path.intros \n                  simp:ProcCFG.valid_node_def valid_edge_def)+\n    from path pathE2 have \"CFG.valid_path' sourcenode targetnode kind (valid_edge wfp)\n      (get_return_edges wfp) (Main, Entry) ((as@asx)@[((p',Label lx),\n      (\\<lambda>s. True):(p',Label lx')\\<hookrightarrow>\\<^bsub>p\\<^esub>map (\\<lambda>e cf. interpret e cf) es,(p,Entry))])\n      (p,Entry)\"\n      apply(unfold ProcCFG.vp_def) apply(rule conjI)\n       apply(fastforce intro:ProcCFG.path_Append)\n      by(unfold ProcCFG.valid_path_def,fastforce intro:ProcCFG.vpa_snoc_Call)\n    moreover\n    from path' pathX2 have \"CFG.valid_path' sourcenode targetnode kind \n      (valid_edge wfp) (get_return_edges wfp) (p,Exit)\n      ([((p,Exit),(\\<lambda>cf. snd cf = (p',Label lx'))\\<hookleftarrow>\\<^bsub>p\\<^esub>\n      (\\<lambda>cf cf'. cf'(rets [:=] map cf outs)),(p',Label lx'))]@(asx'@as')) (Main, Exit)\"\n      apply(unfold ProcCFG.vp_def) apply(rule conjI)\n       apply(fastforce intro:ProcCFG.path_Append)\n      by(simp add:ProcCFG.valid_path_def ProcCFG.valid_path_def)\n    ultimately show ?case by blast\n  qed\nqed\n\n\nlemma edge_valid_paths:\n  assumes \"prog,procs \\<turnstile> sourcenode a -kind a\\<rightarrow> targetnode a\"\n  and disj:\"(p,n) = sourcenode a \\<or> (p,n) = targetnode a\" \n  and [simp]:\"Rep_wf_prog wfp = (prog,procs)\"\n  shows \"\\<exists>as as'. CFG.valid_path' sourcenode targetnode kind (valid_edge wfp)\n                (get_return_edges wfp) (Main,Entry) as (p,n) \\<and>\n              CFG.valid_path' sourcenode targetnode kind (valid_edge wfp)\n                (get_return_edges wfp) (p,n) as' (Main,Exit)\"\nproof -\n  from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> have wf:\"well_formed procs\"\n    by(fastforce intro:wf_wf_prog)\n  from \\<open>prog,procs \\<turnstile> sourcenode a -kind a\\<rightarrow> targetnode a\\<close>\n  show ?thesis\n  proof(induct \"sourcenode a\" \"kind a\" \"targetnode a\" rule:PCFG.induct)\n    case (Main nx nx')\n    from \\<open>(Main, nx) = sourcenode a\\<close>[THEN sym] \\<open>(Main, nx') = targetnode a\\<close>[THEN sym]\n      disj have [simp]:\"p = Main\" by auto\n    have \"prog,procs \\<turnstile> (Main, Entry) -(\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow> (Main, Exit)\"\n      by(fastforce intro:PCFG.Main Proc_CFG_Entry_Exit)\n    hence EXpath:\"wfp \\<turnstile> (Main,Entry) -[((Main,Entry),(\\<lambda>s. False)\\<^sub>\\<surd>,(Main,Exit))]\\<rightarrow>*\n        (Main,Exit)\"\n      by(fastforce intro:ProcCFG.path.intros\n        simp:valid_edge_def ProcCFG.valid_node_def)\n    show ?case\n    proof(cases n)\n      case (Label l)\n      with \\<open>prog \\<turnstile> nx -IEdge (kind a)\\<rightarrow>\\<^sub>p nx'\\<close> \\<open>(Main, nx) = sourcenode a\\<close>[THEN sym]\n        \\<open>(Main, nx') = targetnode a\\<close>[THEN sym] disj\n      have \"l < #:prog\" by(auto intro:Proc_CFG_sourcelabel_less_num_nodes\n        Proc_CFG_targetlabel_less_num_nodes)\n      with \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \n      obtain as as' where \"wfp \\<turnstile> (Main,Entry) -as\\<rightarrow>* (Main,Label l)\"\n        and \"\\<forall>a \\<in> set as. intra_kind (kind a)\"\n        and \"wfp \\<turnstile> (Main,Label l) -as'\\<rightarrow>* (Main,Exit)\"\n        and \"\\<forall>a \\<in> set as'. intra_kind (kind a)\"\n        by -(erule Label_Proc_CFG_Entry_Exit_path_Main)+\n      with Label show ?thesis\n        apply(rule_tac x=\"as\" in exI) apply(rule_tac x=\"as'\" in exI) apply simp\n        by(fastforce intro:ProcCFG.intra_path_vp simp:ProcCFG.intra_path_def)\n    next\n      case Entry\n      hence \"wfp \\<turnstile> (Main,Entry) -[]\\<rightarrow>* (Main,n)\" by(fastforce intro:ProcCFG.empty_path)\n      with EXpath show ?thesis by(fastforce simp:ProcCFG.vp_def ProcCFG.valid_path_def)\n    next\n      case Exit\n      hence \"wfp \\<turnstile> (Main,n) -[]\\<rightarrow>* (Main,Exit)\" by(fastforce intro:ProcCFG.empty_path)\n      with Exit EXpath show ?thesis using Exit\n        apply(rule_tac x=\"[((Main,Entry),(\\<lambda>s. False)\\<^sub>\\<surd>,(Main,Exit))]\" in exI) \n        apply simp\n        by(fastforce intro:ProcCFG.intra_path_vp \n          simp:ProcCFG.intra_path_def intra_kind_def)\n    qed\n  next\n    case (Proc px ins outs c nx nx' ps)\n    from \\<open>(px, ins, outs, c) \\<in> set procs\\<close> wf have [simp]:\"px \\<noteq> Main\" by auto\n    from disj \\<open>(px, nx) = sourcenode a\\<close>[THEN sym] \\<open>(px, nx') = targetnode a\\<close>[THEN sym]\n    have [simp]:\"p = px\" by auto\n    from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \n      \\<open>containsCall procs prog ps px\\<close> \\<open>(px, ins, outs, c) \\<in> set procs\\<close>\n    obtain asx asx' where path:\"CFG.valid_path' sourcenode targetnode kind\n      (valid_edge wfp) (get_return_edges wfp) (Main,Entry) asx (px,Entry)\"\n      and path':\"CFG.valid_path' sourcenode targetnode kind\n      (valid_edge wfp) (get_return_edges wfp) (px,Exit) asx' (Main,Exit)\"\n      by -(erule Entry_to_Entry_and_Exit_to_Exit)+\n    from \\<open>containsCall procs prog ps px\\<close> \\<open>(px, ins, outs, c) \\<in> set procs\\<close>\n    have \"prog,procs \\<turnstile> (px, Entry) -(\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow> (px, Exit)\"\n      by(fastforce intro:PCFG.Proc Proc_CFG_Entry_Exit)\n    hence EXpath:\"wfp \\<turnstile> (px,Entry) -[((px,Entry),(\\<lambda>s. False)\\<^sub>\\<surd>,(px,Exit))]\\<rightarrow>* \n      (px,Exit)\" by(fastforce intro:ProcCFG.path.intros \n        simp:valid_edge_def ProcCFG.valid_node_def)\n    show ?case\n    proof(cases n)\n      case (Label l)\n      with \\<open>c \\<turnstile> nx -IEdge (kind a)\\<rightarrow>\\<^sub>p nx'\\<close> disj \\<open>(px, nx) = sourcenode a\\<close>[THEN sym]\n        \\<open>(px, nx') = targetnode a\\<close>[THEN sym]\n      have \"l < #:c\" by(auto intro:Proc_CFG_sourcelabel_less_num_nodes\n        Proc_CFG_targetlabel_less_num_nodes)\n      with \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \\<open>(px, ins, outs, c) \\<in> set procs\\<close> \n        \\<open>containsCall procs prog ps px\\<close>\n      obtain as as' where \"wfp \\<turnstile> (px,Entry) -as\\<rightarrow>* (px,Label l)\"\n        and \"\\<forall>a \\<in> set as. intra_kind (kind a)\"\n        and \"wfp \\<turnstile> (px,Label l) -as'\\<rightarrow>* (px,Exit)\"\n        and \"\\<forall>a \\<in> set as'. intra_kind (kind a)\"\n        by -(erule Label_Proc_CFG_Entry_Exit_path_Proc)+\n      with path path' show ?thesis using Label\n        apply(rule_tac x=\"asx@as\" in exI) apply(rule_tac x=\"as'@asx'\" in exI)\n        by(auto intro:ProcCFG.path_Append ProcCFG.valid_path_same_level_path_Append\n          ProcCFG.same_level_path_valid_path_Append ProcCFG.intras_same_level_path\n          simp:ProcCFG.vp_def)\n    next\n      case Entry\n      from EXpath path' have \"CFG.valid_path' sourcenode targetnode kind \n        (valid_edge wfp) (get_return_edges wfp) (px,Entry) \n        ([((px,Entry),(\\<lambda>s. False)\\<^sub>\\<surd>,(px,Exit))]@asx') (Main, Exit)\"\n        apply(unfold ProcCFG.vp_def) apply(erule conjE) apply(rule conjI)\n        by(fastforce intro:ProcCFG.path_Append \n          ProcCFG.same_level_path_valid_path_Append ProcCFG.intras_same_level_path\n          simp:intra_kind_def)+\n      with path Entry show ?thesis by simp blast\n    next\n      case Exit\n      with path EXpath path' show ?thesis\n        apply(rule_tac x=\"asx@[((px,Entry),(\\<lambda>s. False)\\<^sub>\\<surd>,(px,Exit))]\" in exI)\n        apply simp\n        by(fastforce intro:ProcCFG.path_Append \n          ProcCFG.valid_path_same_level_path_Append ProcCFG.intras_same_level_path\n          simp:ProcCFG.vp_def ProcCFG.intra_path_def intra_kind_def)\n    qed\n  next\n    case (MainCall l px es rets nx' ins outs c)\n    from disj show ?case\n    proof\n      assume \"(p,n) = sourcenode a\"\n      with \\<open>(Main, Label l) = sourcenode a\\<close>[THEN sym] \n      have [simp]:\"n = Label l\" \"p = Main\" by simp_all\n      with \\<open>prog \\<turnstile> Label l -CEdge (px, es, rets)\\<rightarrow>\\<^sub>p nx'\\<close> have \"l < #:prog\"\n        by(fastforce intro:Proc_CFG_sourcelabel_less_num_nodes)\n      with \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \n      obtain as as' where \"wfp \\<turnstile> (Main,Entry) -as\\<rightarrow>* (Main,Label l)\"\n        and \"\\<forall>a \\<in> set as. intra_kind (kind a)\"\n        and \"wfp \\<turnstile> (Main,Label l) -as'\\<rightarrow>* (Main,Exit)\"\n        and \"\\<forall>a \\<in> set as'. intra_kind (kind a)\"\n        by -(erule Label_Proc_CFG_Entry_Exit_path_Main)+\n      thus ?thesis \n        by(fastforce intro:ProcCFG.intra_path_vp simp:ProcCFG.intra_path_def)\n    next\n      assume \"(p,n) = targetnode a\"\n      with \\<open>(px, Entry) = targetnode a\\<close>[THEN sym] \n      have [simp]:\"n = Entry\" \"p = px\" by simp_all\n      from \\<open>prog \\<turnstile> Label l -CEdge (px, es, rets)\\<rightarrow>\\<^sub>p nx'\\<close>\n      have \"containsCall procs prog [] px\" \n        by(rule Proc_CFG_Call_containsCall)\n      with \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \\<open>(px, ins, outs, c) \\<in> set procs\\<close>\n      obtain as' where Xpath:\"CFG.valid_path' sourcenode targetnode kind\n        (valid_edge wfp) (get_return_edges wfp) (px,Exit) as' (Main,Exit)\"\n        by -(erule Entry_to_Entry_and_Exit_to_Exit)      \n      from \\<open>containsCall procs prog [] px\\<close> \\<open>(px, ins, outs, c) \\<in> set procs\\<close>\n      have \"prog,procs \\<turnstile> (px, Entry) -(\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow> (px, Exit)\"\n        by(fastforce intro:PCFG.Proc Proc_CFG_Entry_Exit)\n      hence \"wfp \\<turnstile> (px,Entry) -[((px,Entry),(\\<lambda>s. False)\\<^sub>\\<surd>,(px,Exit))]\\<rightarrow>* (px,Exit)\"\n        by(fastforce intro:ProcCFG.path.intros \n          simp:valid_edge_def ProcCFG.valid_node_def)\n      with Xpath have \"CFG.valid_path' sourcenode targetnode kind\n        (valid_edge wfp) (get_return_edges wfp) (px,Entry) \n        ([((px,Entry),(\\<lambda>s. False)\\<^sub>\\<surd>,(px,Exit))]@as') (Main,Exit)\"\n        apply(unfold ProcCFG.vp_def) apply(erule conjE) apply(rule conjI)\n        by(fastforce intro:ProcCFG.path_Append \n          ProcCFG.same_level_path_valid_path_Append ProcCFG.intras_same_level_path\n          simp:intra_kind_def)+\n      with \\<open>containsCall procs prog [] px\\<close> \\<open>Rep_wf_prog wfp = (prog,procs)\\<close>\n        \\<open>(px, ins, outs, c) \\<in> set procs\\<close>\n      show ?thesis by(fastforce elim:Entry_to_Entry_and_Exit_to_Exit)\n    qed\n  next\n    case (ProcCall px ins outs c l p' es' rets' l' ins' outs' c' ps)\n    from disj show ?case\n    proof\n      assume \"(p,n) = sourcenode a\"\n      with \\<open>(px, Label l) = sourcenode a\\<close>[THEN sym] \n      have [simp]:\"n = Label l\" \"p = px\" by simp_all\n      with \\<open>c \\<turnstile> Label l -CEdge (p', es', rets')\\<rightarrow>\\<^sub>p Label l'\\<close> have \"l < #:c\"\n        by(fastforce intro:Proc_CFG_sourcelabel_less_num_nodes)\n      from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \\<open>l < #:c\\<close> \n        \\<open>containsCall procs prog ps px\\<close> \\<open>(px, ins, outs, c) \\<in> set procs\\<close>\n      obtain as as' where \"wfp \\<turnstile> (px,Label l) -as\\<rightarrow>* (px,Exit)\"\n        and \"\\<forall>a \\<in> set as. intra_kind (kind a)\"\n        and \"wfp \\<turnstile> (px,Entry) -as'\\<rightarrow>* (px,Label l)\"\n        and \"\\<forall>a \\<in> set as'. intra_kind (kind a)\"\n        by -(erule Label_Proc_CFG_Entry_Exit_path_Proc)+\n      moreover\n      from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \\<open>containsCall procs prog ps px\\<close>\n        \\<open>(px, ins, outs, c) \\<in> set procs\\<close> obtain asx asx' \n        where\" CFG.valid_path' sourcenode targetnode kind\n        (valid_edge wfp) (get_return_edges wfp) (Main,Entry) asx (px,Entry)\"\n        and \"CFG.valid_path' sourcenode targetnode kind\n        (valid_edge wfp) (get_return_edges wfp) (px,Exit) asx' (Main,Exit)\"\n        by -(erule Entry_to_Entry_and_Exit_to_Exit)+\n      ultimately show ?thesis \n        apply(rule_tac x=\"asx@as'\" in exI) apply(rule_tac x=\"as@asx'\" in exI)\n        by(auto intro:ProcCFG.path_Append ProcCFG.valid_path_same_level_path_Append\n          ProcCFG.same_level_path_valid_path_Append ProcCFG.intras_same_level_path\n          simp:ProcCFG.vp_def)\n    next\n      assume \"(p,n) = targetnode a\"\n      with \\<open>(p', Entry) = targetnode a\\<close>[THEN sym] \n      have [simp]:\"n = Entry\" \"p = p'\" by simp_all\n      from \\<open>c \\<turnstile> Label l -CEdge (p', es', rets')\\<rightarrow>\\<^sub>p Label l'\\<close>\n      have \"containsCall procs c [] p'\" by(rule Proc_CFG_Call_containsCall)\n      with \\<open>containsCall procs prog ps px\\<close> \\<open>(px, ins, outs, c) \\<in> set procs\\<close>\n      have \"containsCall procs prog (ps@[px]) p'\"\n        by(rule containsCall_in_proc)\n      with \\<open>(p', ins', outs', c') \\<in> set procs\\<close>\n      have \"prog,procs \\<turnstile> (p', Entry) -(\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow> (p', Exit)\"\n        by(fastforce intro:PCFG.Proc Proc_CFG_Entry_Exit)\n      hence \"wfp \\<turnstile> (p',Entry) -[((p',Entry),(\\<lambda>s. False)\\<^sub>\\<surd>,(p',Exit))]\\<rightarrow>* (p',Exit)\"\n        by(fastforce intro:ProcCFG.path.intros \n          simp:valid_edge_def ProcCFG.valid_node_def)\n      moreover\n      from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \\<open>(p', ins', outs', c') \\<in> set procs\\<close>\n        \\<open>containsCall procs prog (ps@[px]) p'\\<close>\n      obtain as as' where \"CFG.valid_path' sourcenode targetnode kind\n        (valid_edge wfp) (get_return_edges wfp) (Main,Entry) as (p',Entry)\"\n        and \"CFG.valid_path' sourcenode targetnode kind\n        (valid_edge wfp) (get_return_edges wfp) (p',Exit) as' (Main,Exit)\"\n        by -(erule Entry_to_Entry_and_Exit_to_Exit)+\n      ultimately show ?thesis\n        apply(rule_tac x=\"as\" in exI)\n        apply(rule_tac x=\"[((p',Entry),(\\<lambda>s. False)\\<^sub>\\<surd>,(p',Exit))]@as'\" in exI)\n        apply(unfold ProcCFG.vp_def)\n        by(fastforce intro:ProcCFG.path_Append \n          ProcCFG.same_level_path_valid_path_Append ProcCFG.intras_same_level_path\n          simp:intra_kind_def)+\n    qed\n  next\n    case (MainReturn l px es rets l' ins outs c)\n    from disj show ?case\n    proof\n      assume \"(p,n) = sourcenode a\"\n      with \\<open>(px, Exit) = sourcenode a\\<close>[THEN sym] \n      have [simp]:\"n = Exit\" \"p = px\" by simp_all\n      from \\<open>prog \\<turnstile> Label l -CEdge (px, es, rets)\\<rightarrow>\\<^sub>p Label l'\\<close>\n      have \"containsCall procs prog [] px\" by(rule Proc_CFG_Call_containsCall)\n      with \\<open>(px, ins, outs, c) \\<in> set procs\\<close>\n      have \"prog,procs \\<turnstile> (px, Entry) -(\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow> (px, Exit)\"\n        by(fastforce intro:PCFG.Proc Proc_CFG_Entry_Exit)\n      hence \"wfp \\<turnstile> (px,Entry) -[((px,Entry),(\\<lambda>s. False)\\<^sub>\\<surd>,(px,Exit))]\\<rightarrow>* (px,Exit)\"\n        by(fastforce intro:ProcCFG.path.intros \n          simp:valid_edge_def ProcCFG.valid_node_def)\n      moreover\n      from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \\<open>(px, ins, outs, c) \\<in> set procs\\<close>\n        \\<open>containsCall procs prog [] px\\<close>\n      obtain as as' where \"CFG.valid_path' sourcenode targetnode kind\n        (valid_edge wfp) (get_return_edges wfp) (Main,Entry) as (px,Entry)\"\n        and \"CFG.valid_path' sourcenode targetnode kind\n        (valid_edge wfp) (get_return_edges wfp) (px,Exit) as' (Main,Exit)\"\n        by -(erule Entry_to_Entry_and_Exit_to_Exit)+\n      ultimately show ?thesis\n        apply(rule_tac x=\"as@[((px,Entry),(\\<lambda>s. False)\\<^sub>\\<surd>,(px,Exit))]\" in exI)\n        apply(rule_tac x=\"as'\" in exI)\n        apply(unfold ProcCFG.vp_def)\n        by(fastforce intro:ProcCFG.path_Append \n          ProcCFG.valid_path_same_level_path_Append ProcCFG.intras_same_level_path\n          simp:intra_kind_def)+\n    next\n      assume \"(p, n) = targetnode a\"\n      with \\<open>(Main, Label l') = targetnode a\\<close>[THEN sym] \n      have [simp]:\"n = Label l'\" \"p = Main\" by simp_all\n      with \\<open>prog \\<turnstile> Label l -CEdge (px, es, rets)\\<rightarrow>\\<^sub>p Label l'\\<close> have \"l' < #:prog\"\n        by(fastforce intro:Proc_CFG_targetlabel_less_num_nodes)\n      with \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \n      obtain as as' where \"wfp \\<turnstile> (Main,Entry) -as\\<rightarrow>* (Main,Label l')\"\n        and \"\\<forall>a \\<in> set as. intra_kind (kind a)\"\n        and \"wfp \\<turnstile> (Main,Label l') -as'\\<rightarrow>* (Main,Exit)\"\n        and \"\\<forall>a \\<in> set as'. intra_kind (kind a)\"\n        by -(erule Label_Proc_CFG_Entry_Exit_path_Main)+\n      thus ?thesis \n        by(fastforce intro:ProcCFG.intra_path_vp simp:ProcCFG.intra_path_def)\n    qed\n  next\n    case (ProcReturn px ins outs c l p' es' rets' l' ins' outs' c' ps)\n    from disj show ?case\n    proof\n      assume \"(p,n) = sourcenode a\"\n      with \\<open>(p', Exit) = sourcenode a\\<close>[THEN sym] \n      have [simp]:\"n = Exit\" \"p = p'\" by simp_all\n      from \\<open>c \\<turnstile> Label l -CEdge (p', es', rets')\\<rightarrow>\\<^sub>p Label l'\\<close>\n      have \"containsCall procs c [] p'\" by(rule Proc_CFG_Call_containsCall)\n      with \\<open>containsCall procs prog ps px\\<close> \\<open>(px, ins, outs, c) \\<in> set procs\\<close>\n      have \"containsCall procs prog (ps@[px]) p'\"\n        by(rule containsCall_in_proc)\n      with \\<open>(p', ins', outs', c') \\<in> set procs\\<close>\n      have \"prog,procs \\<turnstile> (p', Entry) -(\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow> (p', Exit)\"\n        by(fastforce intro:PCFG.Proc Proc_CFG_Entry_Exit)\n      hence \"wfp \\<turnstile> (p',Entry) -[((p',Entry),(\\<lambda>s. False)\\<^sub>\\<surd>,(p',Exit))]\\<rightarrow>* (p',Exit)\"\n        by(fastforce intro:ProcCFG.path.intros \n          simp:valid_edge_def ProcCFG.valid_node_def)\n      moreover\n      from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \\<open>(p', ins', outs', c') \\<in> set procs\\<close>\n        \\<open>containsCall procs prog (ps@[px]) p'\\<close>\n      obtain as as' where \"CFG.valid_path' sourcenode targetnode kind\n        (valid_edge wfp) (get_return_edges wfp) (Main,Entry) as (p',Entry)\"\n        and \"CFG.valid_path' sourcenode targetnode kind\n        (valid_edge wfp) (get_return_edges wfp) (p',Exit) as' (Main,Exit)\"\n        by -(erule Entry_to_Entry_and_Exit_to_Exit)+\n      ultimately show ?thesis\n        apply(rule_tac x=\"as@[((p',Entry),(\\<lambda>s. False)\\<^sub>\\<surd>,(p',Exit))]\" in exI)\n        apply(rule_tac x=\"as'\" in exI)\n        apply(unfold ProcCFG.vp_def)\n        by(fastforce intro:ProcCFG.path_Append \n          ProcCFG.valid_path_same_level_path_Append ProcCFG.intras_same_level_path\n          simp:intra_kind_def)+\n    next\n      assume \"(p, n) = targetnode a\"\n      with \\<open>(px, Label l') = targetnode a\\<close>[THEN sym] \n      have [simp]:\"n = Label l'\" \"p = px\" by simp_all\n      with \\<open>c \\<turnstile> Label l -CEdge (p', es', rets')\\<rightarrow>\\<^sub>p Label l'\\<close> have \"l' < #:c\"\n        by(fastforce intro:Proc_CFG_targetlabel_less_num_nodes)\n      from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \\<open>l' < #:c\\<close> \n        \\<open>containsCall procs prog ps px\\<close> \\<open>(px, ins, outs, c) \\<in> set procs\\<close>\n      obtain as as' where \"wfp \\<turnstile> (px,Label l') -as\\<rightarrow>* (px,Exit)\"\n        and \"\\<forall>a \\<in> set as. intra_kind (kind a)\"\n        and \"wfp \\<turnstile> (px,Entry) -as'\\<rightarrow>* (px,Label l')\"\n        and \"\\<forall>a \\<in> set as'. intra_kind (kind a)\"\n        by -(erule Label_Proc_CFG_Entry_Exit_path_Proc)+\n      moreover\n      from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \\<open>containsCall procs prog ps px\\<close>\n        \\<open>(px, ins, outs, c) \\<in> set procs\\<close> obtain asx asx' \n        where\" CFG.valid_path' sourcenode targetnode kind\n        (valid_edge wfp) (get_return_edges wfp) (Main,Entry) asx (px,Entry)\"\n        and \"CFG.valid_path' sourcenode targetnode kind\n        (valid_edge wfp) (get_return_edges wfp) (px,Exit) asx' (Main,Exit)\"\n        by -(erule Entry_to_Entry_and_Exit_to_Exit)+\n      ultimately show ?thesis \n        apply(rule_tac x=\"asx@as'\" in exI) apply(rule_tac x=\"as@asx'\" in exI)\n        by(auto intro:ProcCFG.path_Append ProcCFG.valid_path_same_level_path_Append\n          ProcCFG.same_level_path_valid_path_Append ProcCFG.intras_same_level_path\n          simp:ProcCFG.vp_def)\n    qed\n  next\n    case (MainCallReturn nx px es rets nx')\n    from \\<open>prog \\<turnstile> nx -CEdge (px, es, rets)\\<rightarrow>\\<^sub>p nx'\\<close> disj\n      \\<open>(Main, nx) = sourcenode a\\<close>[THEN sym] \\<open>(Main, nx') = targetnode a\\<close>[THEN sym]\n    obtain l where [simp]:\"n = Label l\" \"p = Main\"\n      by(fastforce dest:Proc_CFG_Call_Labels)\n    from \\<open>prog \\<turnstile> nx -CEdge (px, es, rets)\\<rightarrow>\\<^sub>p nx'\\<close> disj\n      \\<open>(Main, nx) = sourcenode a\\<close>[THEN sym] \\<open>(Main, nx') = targetnode a\\<close>[THEN sym]\n    have \"l < #:prog\" by(auto intro:Proc_CFG_sourcelabel_less_num_nodes\n      Proc_CFG_targetlabel_less_num_nodes)\n    with \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \n    obtain as as' where \"wfp \\<turnstile> (Main,Entry) -as\\<rightarrow>* (Main,Label l)\"\n      and \"\\<forall>a \\<in> set as. intra_kind (kind a)\"\n      and \"wfp \\<turnstile> (Main,Label l) -as'\\<rightarrow>* (Main,Exit)\"\n      and \"\\<forall>a \\<in> set as'. intra_kind (kind a)\"\n      by -(erule Label_Proc_CFG_Entry_Exit_path_Main)+\n    thus ?thesis\n      apply(rule_tac x=\"as\" in exI) apply(rule_tac x=\"as'\" in exI) apply simp\n      by(fastforce intro:ProcCFG.intra_path_vp simp:ProcCFG.intra_path_def)\n  next\n    case (ProcCallReturn px ins outs c nx p' es' rets' nx' ps)\n    from \\<open>(px, ins, outs, c) \\<in> set procs\\<close> wf have [simp]:\"px \\<noteq> Main\" by auto\n    from \\<open>c \\<turnstile> nx -CEdge (p', es', rets')\\<rightarrow>\\<^sub>p nx'\\<close> disj \n      \\<open>(px, nx) = sourcenode a\\<close>[THEN sym] \\<open>(px, nx') = targetnode a\\<close>[THEN sym]\n    obtain l where [simp]:\"n = Label l\" \"p = px\"\n      by(fastforce dest:Proc_CFG_Call_Labels)\n    from \\<open>c \\<turnstile> nx -CEdge (p', es', rets')\\<rightarrow>\\<^sub>p nx'\\<close> disj \n    \\<open>(px, nx) = sourcenode a\\<close>[THEN sym] \\<open>(px, nx') = targetnode a\\<close>[THEN sym]\n    have \"l < #:c\"\n      by(auto intro:Proc_CFG_sourcelabel_less_num_nodes\n        Proc_CFG_targetlabel_less_num_nodes)\n    with \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \\<open>(px, ins, outs, c) \\<in> set procs\\<close> \n      \\<open>containsCall procs prog ps px\\<close>\n    obtain as as' where \"wfp \\<turnstile> (px,Entry) -as\\<rightarrow>* (px,Label l)\"\n      and \"\\<forall>a \\<in> set as. intra_kind (kind a)\"\n      and \"wfp \\<turnstile> (px,Label l) -as'\\<rightarrow>* (px,Exit)\"\n      and \"\\<forall>a \\<in> set as'. intra_kind (kind a)\"\n      by -(erule Label_Proc_CFG_Entry_Exit_path_Proc)+\n    moreover\n    from \\<open>Rep_wf_prog wfp = (prog,procs)\\<close> \n      \\<open>containsCall procs prog ps px\\<close> \\<open>(px, ins, outs, c) \\<in> set procs\\<close>\n    obtain asx asx' where \"CFG.valid_path' sourcenode targetnode kind\n      (valid_edge wfp) (get_return_edges wfp) (Main,Entry) asx (px,Entry)\"\n      and \"CFG.valid_path' sourcenode targetnode kind\n      (valid_edge wfp) (get_return_edges wfp) (px,Exit) asx' (Main,Exit)\"\n      by -(erule Entry_to_Entry_and_Exit_to_Exit)+\n    ultimately show ?thesis\n      apply(rule_tac x=\"asx@as\" in exI) apply(rule_tac x=\"as'@asx'\" in exI)\n      by(auto intro:ProcCFG.path_Append ProcCFG.valid_path_same_level_path_Append\n        ProcCFG.same_level_path_valid_path_Append ProcCFG.intras_same_level_path\n        simp:ProcCFG.vp_def)\n  qed\nqed\n\n\n\nsubsection \\<open>Instantiating the \\<open>Postdomination\\<close> locale\\<close>\n\ninterpretation ProcPostdomination:\n  Postdomination sourcenode targetnode kind \"valid_edge wfp\" \"(Main,Entry)\"\n  get_proc \"get_return_edges wfp\" \"lift_procs wfp\" Main \"(Main,Exit)\"\n  for wfp\nproof -\n  from Rep_wf_prog[of wfp]\n  obtain prog procs where [simp]:\"Rep_wf_prog wfp = (prog,procs)\" \n    by(fastforce simp:wf_prog_def)\n  hence wf:\"well_formed procs\" by(fastforce intro:wf_wf_prog)\n  show \"Postdomination sourcenode targetnode kind (valid_edge wfp)\n    (Main, Entry) get_proc (get_return_edges wfp) (lift_procs wfp) Main (Main, Exit)\"\n  proof\n    fix m\n    assume \"CFG.valid_node sourcenode targetnode (valid_edge wfp) m\"\n    then obtain a where \"valid_edge wfp a\"\n      and \"m = sourcenode a \\<or> m = targetnode a\"\n      by(fastforce simp:ProcCFG.valid_node_def)\n    obtain p n where [simp]:\"m = (p,n)\" by(cases m) auto\n    from \\<open>valid_edge wfp a\\<close> \\<open>m = sourcenode a \\<or> m = targetnode a\\<close> \n      \\<open>Rep_wf_prog wfp = (prog,procs)\\<close>\n    show \"\\<exists>as. CFG.valid_path' sourcenode targetnode kind (valid_edge wfp)\n      (get_return_edges wfp) (Main, Entry) as m\"\n      by(auto dest!:edge_valid_paths simp:valid_edge_def)\n  next\n    fix m\n    assume \"CFG.valid_node sourcenode targetnode (valid_edge wfp) m\"\n    then obtain a where \"valid_edge wfp a\"\n      and \"m = sourcenode a \\<or> m = targetnode a\"\n      by(fastforce simp:ProcCFG.valid_node_def)\n    obtain p n where [simp]:\"m = (p,n)\" by(cases m) auto\n    from \\<open>valid_edge wfp a\\<close> \\<open>m = sourcenode a \\<or> m = targetnode a\\<close> \n      \\<open>Rep_wf_prog wfp = (prog,procs)\\<close>\n    show \"\\<exists>as. CFG.valid_path' sourcenode targetnode kind (valid_edge wfp)\n      (get_return_edges wfp) m as (Main,Exit)\"\n      by(auto dest!:edge_valid_paths simp:valid_edge_def)\n  next\n    fix n n'\n    assume mex1:\"CFGExit.method_exit sourcenode kind (valid_edge wfp) (Main,Exit) n\"\n      and mex2:\"CFGExit.method_exit sourcenode kind (valid_edge wfp) (Main,Exit) n'\"\n      and \"get_proc n = get_proc n'\"\n    from mex1 \n    have \"n = (Main,Exit) \\<or> (\\<exists>a Q p f. n = sourcenode a \\<and> valid_edge wfp a \\<and> \n      kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f)\" by(simp add:ProcCFGExit.method_exit_def)\n    thus \"n = n'\"\n    proof\n      assume \"n = (Main,Exit)\"\n      from mex2 have \"n' = (Main,Exit) \\<or> (\\<exists>a Q p f. n' = sourcenode a \\<and> \n        valid_edge wfp a \\<and> kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f)\" \n        by(simp add:ProcCFGExit.method_exit_def)\n      thus ?thesis\n      proof\n        assume \"n' = (Main,Exit)\"\n        with \\<open>n = (Main,Exit)\\<close> show ?thesis by simp\n      next\n        assume \"\\<exists>a Q p f. n' = sourcenode a \\<and> \n          valid_edge wfp a \\<and> kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\"\n        then obtain a Q p f where \"n' = sourcenode a\"\n          and \"valid_edge wfp a\" and \"kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\" by blast\n        from \\<open>valid_edge wfp a\\<close> \\<open>kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\\<close>\n        have \"get_proc (sourcenode a) = p\" by(rule ProcCFG.get_proc_return)\n        with \\<open>get_proc n = get_proc n'\\<close> \\<open>n = (Main,Exit)\\<close> \\<open>n' = sourcenode a\\<close>\n        have \"get_proc (Main,Exit) = p\" by simp\n        hence \"p = Main\" by simp\n        with \\<open>kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\\<close> have \"kind a = Q\\<hookleftarrow>\\<^bsub>Main\\<^esub>f\" by simp\n        with \\<open>valid_edge wfp a\\<close> have False by(rule ProcCFG.Main_no_return_source)\n        thus ?thesis by simp\n      qed\n    next\n      assume \"\\<exists>a Q p f. n = sourcenode a \\<and> \n        valid_edge wfp a \\<and> kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\"\n      then obtain a Q p f where \"n = sourcenode a\"\n        and \"valid_edge wfp a\" and \"kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\" by blast\n      from \\<open>valid_edge wfp a\\<close> \\<open>kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\\<close>\n      have \"get_proc (sourcenode a) = p\" by(rule ProcCFG.get_proc_return)\n      from mex2 have \"n' = (Main,Exit) \\<or> (\\<exists>a Q p f. n' = sourcenode a \\<and> \n        valid_edge wfp a \\<and> kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f)\" \n        by(simp add:ProcCFGExit.method_exit_def)\n      thus ?thesis\n      proof\n        assume \"n' = (Main,Exit)\"\n        from \\<open>get_proc (sourcenode a) = p\\<close> \\<open>get_proc n = get_proc n'\\<close>\n          \\<open>n' = (Main,Exit)\\<close> \\<open>n = sourcenode a\\<close>\n        have \"get_proc (Main,Exit) = p\" by simp\n        hence \"p = Main\" by simp\n        with \\<open>kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\\<close> have \"kind a = Q\\<hookleftarrow>\\<^bsub>Main\\<^esub>f\" by simp\n        with \\<open>valid_edge wfp a\\<close> have False by(rule ProcCFG.Main_no_return_source)\n        thus ?thesis by simp\n      next\n        assume \"\\<exists>a Q p f. n' = sourcenode a \\<and> \n          valid_edge wfp a \\<and> kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\"\n        then obtain a' Q' p' f' where \"n' = sourcenode a'\"\n          and \"valid_edge wfp a'\" and \"kind a' = Q'\\<hookleftarrow>\\<^bsub>p'\\<^esub>f'\" by blast\n        from \\<open>valid_edge wfp a'\\<close> \\<open>kind a' = Q'\\<hookleftarrow>\\<^bsub>p'\\<^esub>f'\\<close>\n        have \"get_proc (sourcenode a') = p'\" by(rule ProcCFG.get_proc_return)\n        with \\<open>get_proc n = get_proc n'\\<close> \\<open>get_proc (sourcenode a) = p\\<close>\n          \\<open>n = sourcenode a\\<close> \\<open>n' = sourcenode a'\\<close>\n        have \"p' = p\" by simp\n        from \\<open>valid_edge wfp a\\<close> \\<open>kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\\<close>\n        have \"sourcenode a = (p,Exit)\" by(auto elim:PCFG.cases simp:valid_edge_def)\n        from \\<open>valid_edge wfp a'\\<close> \\<open>kind a' = Q'\\<hookleftarrow>\\<^bsub>p'\\<^esub>f'\\<close>\n        have \"sourcenode a' = (p',Exit)\" by(auto elim:PCFG.cases simp:valid_edge_def)\n        with \\<open>n = sourcenode a\\<close> \\<open>n' = sourcenode a'\\<close> \\<open>p' = p\\<close>\n          \\<open>sourcenode a = (p,Exit)\\<close> show ?thesis by simp\n      qed\n    qed\n  qed\nqed\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/HRB-Slicing/Proc/ValidPaths.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.523420348936324, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.26579906319502644}}
{"text": "(*  Title:      SSA_Semantics.thy\n    Author:     Sebastian Ullrich\n*)\n\nsection \\<open>Proof of Semantic Equivalence\\<close>\n\ntheory SSA_Semantics imports Construct_SSA begin\n\ntype_synonym ('node, 'var) state = \"'var \\<rightharpoonup> 'node\"\n\ncontext CFG_SSA_Transformed\nbegin\n  declare invar[intro!]\n\n  definition step ::\n    \"'g \\<Rightarrow> 'node \\<Rightarrow> ('node, 'var) state \\<Rightarrow> ('node, 'var) state\"\n  where\n    \"step g m s v \\<equiv> if v \\<in> oldDefs g m then Some m else s v\"\n\n  inductive bs :: \"'g \\<Rightarrow> 'node list \\<Rightarrow> ('node, 'var) state \\<Rightarrow> bool\" (\"_ \\<turnstile> _\\<Down>_\" [50, 50, 50] 50)\n  where\n    \"g \\<turnstile> Entry g-ns\\<rightarrow>last ns \\<Longrightarrow> g \\<turnstile> ns\\<Down>(fold (step g) ns Map.empty)\"\n\n\n  definition ssaStep ::\n    \"'g \\<Rightarrow> 'node \\<Rightarrow> nat \\<Rightarrow> ('node, 'val) state \\<Rightarrow> ('node, 'val) state\"\n  where\n    \"ssaStep g m i s v \\<equiv>\n      if v \\<in> defs g m then\n        Some m\n      else\n        case phis g (m,v) of\n          Some phiParams \\<Rightarrow> s (phiParams ! i)\n        | None \\<Rightarrow> s v\"\n\n  inductive ssaBS :: \"'g \\<Rightarrow> 'node list \\<Rightarrow> ('node, 'val) state \\<Rightarrow> bool\" (\"_ \\<turnstile> _\\<Down>\\<^sub>s _\" [50, 50, 50] 50)\n  for\n    g :: 'g\n  where\n    empty: \"g \\<turnstile> [Entry g]\\<Down>\\<^sub>s(ssaStep g (Entry g) 0 Map.empty)\"\n  | snoc: \"\\<lbrakk>g \\<turnstile> ns\\<Down>\\<^sub>ss; last ns = old.predecessors g m ! i; m \\<in> set (\\<alpha>n g); i < length (old.predecessors g m)\\<rbrakk> \\<Longrightarrow>\n            g \\<turnstile> (ns@[m])\\<Down>\\<^sub>s(ssaStep g m i s)\"\n\n  lemma ssaBS_I:\n    assumes \"g \\<turnstile> Entry g-ns\\<rightarrow>n\"\n    obtains s where \"g \\<turnstile> ns\\<Down>\\<^sub>ss\"\n  using assms\n  proof (atomize_elim, induction rule:old.path2_rev_induct)\n    case (snoc ns m' m)\n    then obtain s where s: \"g \\<turnstile> ns\\<Down>\\<^sub>ss\" by auto\n    from snoc.hyps(2) obtain i where \"m' = old.predecessors g m ! i\" \"i < length (old.predecessors g m)\" by (auto simp:in_set_conv_nth)\n    with snoc.hyps snoc.prems s show ?case by -(rule exI, erule ssaBS.snoc, auto dest:old.path2_last)\n  qed (auto intro: ssaBS.empty)\n\n  lemma ssaBS_nonempty[simp]: \"\\<not> (g \\<turnstile> []\\<Down>\\<^sub>ss)\"\n  by (rule notI, cases rule: ssaBS.cases, auto)\n\n  lemma ssaBS_hd[simp]: \"g \\<turnstile> ns\\<Down>\\<^sub>ss \\<Longrightarrow> hd ns = Entry g\"\n  by (induction rule: ssaBS.induct, auto simp: hd_append)\n\n\n  lemma equiv_aux:\n    assumes \"g \\<turnstile> ns\\<Down>s\" \"g \\<turnstile> ns\\<Down>\\<^sub>ss'\" \"g \\<turnstile> last ns-ms\\<rightarrow>m\" \"v \\<in> allUses g m\" \"\\<forall>n \\<in> set (tl ms). var g v \\<notin> var g ` allDefs g n\"\n    shows \"s (var g v) = s' v\"\n  using assms(2) assms(1,3-) proof (induction arbitrary: v s ms m)\n    case empty\n    have \"v \\<in> defs g (Entry g)\"\n    proof-\n      from empty.prems(2,3) have \"defAss g m v\" by - (rule allUses_def_ass, auto)\n      with empty.prems(2) obtain n where n: \"n \\<in> set ms\" \"v \\<in> allDefs g n\" by - (drule defAssD, auto)\n      with empty.prems(4) have \"n \\<notin> set (tl ms)\" by auto\n      with empty.prems(2) n have \"n = Entry g\" by (cases ms, auto dest: old.path2_hd)\n      with n(2) show ?thesis by (auto simp: allDefs_def)\n    qed\n    with empty.prems(1) show ?case\n      by - (erule bs.cases, auto simp: step_def ssaStep_def oldDefs_def split: option.split)\n  next\n    case (snoc ns s' n i)\n    from snoc.prems(2) have[simp]: \"n \\<in> set (\\<alpha>n g)\" \"m \\<in> set (\\<alpha>n g)\" by auto\n    from snoc.prems(2,3) have[simp]: \"v \\<in> allVars g\" by - (rule allUses_in_allVars, auto)\n    from snoc.hyps(4) have[simp]: \"n \\<noteq> Entry g\" by (auto simp: Entry_no_predecessor)\n\n    show ?case\n    proof (cases \"var g v \\<in> var g ` allDefs g n\")\n      case True\n\n      have[simp]: \"defNode g v = n\" (is \"?n\\<^sub>v = _\")\n      proof-\n        from True obtain v' where v': \"v' \\<in> allDefs g n\" \"var g v' = var g v\" by auto\n        from snoc.prems(3) have \"defAss g m v\" by - (rule allUses_def_ass, auto)\n        moreover from snoc.prems(1) obtain ns' where ns': \"g \\<turnstile> Entry g-ns'\\<rightarrow>n\" \"set ns' \\<subseteq> set (ns@[n])\" \"distinct ns'\"\n          by (auto elim!: bs.cases intro: old.simple_path2)\n        ultimately have \"?n\\<^sub>v \\<in> set (ns'@tl ms)\"\n          using snoc.prems(2) by - (drule defAss_defNode, auto elim!: bs.cases dest: old.path2_app)\n        moreover {\n          let ?n'' = \"last (butlast ns')\"\n          assume asm: \"?n\\<^sub>v \\<in> set (butlast ns')\"\n          with ns'(1,3) have[simp]: \"?n\\<^sub>v \\<noteq> n\" by (cases ns' rule: rev_cases, auto dest!: old.path2_last)\n          from ns'(1) have \"length ns' \\<ge> 2\" by auto\n          with ns' have bns': \"g \\<turnstile> Entry g-butlast ns'\\<rightarrow>?n''\" \"?n'' \\<in> set (old.predecessors g n)\"\n            by (auto elim: old.path2_unsnoc)\n          with asm obtain ns'' where ns'': \"g \\<turnstile> ?n\\<^sub>v-ns''\\<rightarrow>?n''\" \"suffix ns'' (butlast ns')\" \"?n\\<^sub>v \\<notin> set (tl ns'')\"\n            by - (rule old.path2_split_first_last, auto)\n          with bns' snoc.prems(2) have \"g \\<turnstile> ?n\\<^sub>v-(ns''@[n])@tl ms\\<rightarrow>m\" by - (rule old.path2_app, auto)\n          hence \"defNode g v' \\<notin> set (tl (ns''@[n]@tl ms))\"\n            using v' snoc.prems(3,4) bns'(2) ns''(1,3)\n            by - (rule conventional''[of g v _ m], auto intro!: old.path2_app simp: old.path2_not_Nil)\n          with ns' ns''(1) v'(1) have False by (auto simp: old.path2_not_Nil)\n        } \n        ultimately show ?thesis using snoc.prems(4) ns'(1) by (cases ns' rule: rev_cases, auto dest: old.path2_last)\n      qed\n      from \\<open>v \\<in> allVars g\\<close> show ?thesis\n      proof (cases rule: defNode_cases)\n        case simpleDef\n        thus ?thesis using snoc.prems(1) by - (erule bs.cases, auto simp: step_def ssaStep_def oldDefs_def)\n      next\n        case phi\n        {\n          fix v'\n          assume asm: \"v' \\<in> defs g n\" \"var g v = var g v'\"\n          with phi have \"v' = v\" using allDefs_var_disjoint[of n g v' v]\n            by (cases, auto dest!: phi_phiDefs)\n          with asm(1) phi have False using simpleDefs_phiDefs_disjoint[of n g]\n            by (auto dest!: phi_phiDefs)\n        }\n        note 1 = this\n        {\n          fix vs\n          assume asm: \"g \\<turnstile> Entry g-ns @ [n]\\<rightarrow>n\" \"phis g (n, v) = Some vs\" \"var g v \\<notin> var g ` defs g n\"\n          let ?n' = \"last ns\"\n          from asm(1) have \"length ns \\<ge> 1\" by (cases ns, auto simp: old.path2_def)\n          hence \"g \\<turnstile> Entry g-ns\\<rightarrow>?n'\"\n            by - (rule old.path2_unsnoc[OF asm(1)], auto)\n          moreover have \"vs ! i \\<in> phiUses g ?n'\" using snoc.hyps(2,4) phis_wf[OF asm(2)]\n            by - (rule phiUsesI[OF _ asm(2)], auto simp: set_zip)\n          ultimately have \"fold (step g) ns Map.empty (var g (vs ! i)) = s' (vs ! i)\"\n          by - (rule snoc.IH[where ms1=\"[?n']\" and m1=\"?n'\"], auto intro!: bs.intros)\n          hence \"fold (step g) ns Map.empty (var g v) = s' (vs ! i)\" using phis_same_var[OF asm(2), of \"vs ! i\"] snoc.hyps(4) phis_wf[OF asm(2)]\n            by auto\n        }\n        thus ?thesis using phi snoc.prems(1)\n          by - (erule bs.cases, auto dest!: 1 simp: step_def ssaStep_def oldDefs_def phi_def)\n      qed\n    next\n      case False\n      hence \"phis g (n, v) = None\" by (auto simp: allDefs_def phiDefs_def)\n      moreover have \"fold (step g) ns Map.empty (var g v) = s' v\"\n      proof-\n        from snoc.hyps(1) have \"length ns \\<ge> 1\" by (cases ns, auto)\n        moreover from snoc.prems(2,4) False have \"\\<forall>n \\<in> set ms. var g v \\<notin> var g ` allDefs g n\"\n          by (cases ms, auto simp: phiDefs_def dest: old.path2_hd)\n        ultimately show ?thesis\n          using snoc.prems(1,2,3) by - (rule snoc.IH[where ms1=\"last ns#ms\"], auto elim!: bs.cases intro!: bs.intros elim: old.path2_unsnoc intro!: old.Cons_path2)\n      qed\n      ultimately show ?thesis\n        using snoc.prems(1) False by - (erule bs.cases, auto simp: step_def ssaStep_def oldDefs_def)\n    qed\n  qed\n\n  theorem equiv:\n    assumes \"g \\<turnstile> ns\\<Down>s\" \"g \\<turnstile> ns\\<Down>\\<^sub>ss'\" \"v \\<in> uses g (last ns)\"\n    shows \"s (var g v) = s' v\"\n  using assms by - (rule equiv_aux[where ms=\"[last ns]\"], auto elim!: bs.cases)\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Formal_SSA/SSA_Semantics.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621765155565326, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.26573154984762265}}
{"text": "section {*I\\_kparser\\_FS*}\ntheory\n  I_kparser_FS\n\nimports\n  I_kparser_base\n\nbegin\n\nrecord ('stack, 'event) parserFS_conf =\n  parserFS_conf_fixed :: \"'event list\"\n  parserFS_conf_stack :: \"'stack list\"\n  parserFS_conf_scheduler :: \"'event list\"\n\ndefinition parserFS_configurations :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserFS_conf set\"\n  where\n    \"parserFS_configurations G \\<equiv>\n  {\\<lparr>parserFS_conf_fixed = f,\n    parserFS_conf_stack = l,\n    parserFS_conf_scheduler = r\\<rparr>\n  | f l r.\n  set l \\<subseteq> parser_nonterms G\n  \\<and> f \\<in> parser_fixed_schedulers G\n  \\<and> r \\<in> parser_unfixed_schedulers G\n  \\<and> f @ r \\<in> parser_schedulers G}\"\n\ndefinition parserFS_step_relation :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserFS_conf\n  \\<Rightarrow> ('stack, 'event) parser_step_label\n  \\<Rightarrow> ('stack, 'event) parserFS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"parserFS_step_relation G c1 p c2 \\<equiv>\n  p \\<in> parser_rules G\n  \\<and> ((\\<exists>x. parserFS_conf_stack c1=x@(rule_lpop p) \\<and> parserFS_conf_stack c2=x@(rule_lpush p))\n  \\<and> (\\<exists>v. rule_rpop p=v@rule_rpush p \\<and>\n  ((\\<exists>popnew. parserFS_conf_fixed c1 @ popnew = rule_rpop p\n  \\<and> parserFS_conf_scheduler c1=popnew@parserFS_conf_scheduler c2\n  \\<and> parserFS_conf_fixed c2 = rule_rpush p)\n  \\<or>\n  (\\<exists>remainder. rule_rpop p @ remainder = parserFS_conf_fixed c1\n  \\<and> parserFS_conf_scheduler c1=parserFS_conf_scheduler c2\n  \\<and> parserFS_conf_fixed c2 = rule_rpush p@remainder)\n  )))\"\n\ndefinition parserFS_step_relation_ALT :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserFS_conf\n  \\<Rightarrow> ('stack, 'event) parser_step_label\n  \\<Rightarrow> ('stack, 'event) parserFS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"parserFS_step_relation_ALT G c1 e c2 \\<equiv>\n  e \\<in> parser_rules G\n  \\<and> (\\<exists>x. parserFS_conf_stack c1 = x @ rule_lpop e\n            \\<and> parserFS_conf_stack c2 = x @ rule_lpush e)\n  \\<and> (\\<exists>v. rule_rpop e = v @ rule_rpush e)\n  \\<and> ((\\<exists>popnew.\n        parserFS_conf_fixed c1 @ popnew = rule_rpop e\n        \\<and> parserFS_conf_scheduler c1 = popnew @ parserFS_conf_scheduler c2\n        \\<and> parserFS_conf_fixed c2 = rule_rpush e)\n     \\<or> (\\<exists>remainder.\n          rule_rpop e @ remainder = parserFS_conf_fixed c1\n          \\<and> parserFS_conf_scheduler c1=parserFS_conf_scheduler c2\n          \\<and> parserFS_conf_fixed c2 = rule_rpush e @ remainder)\n  )\"\n\nlemma parserFS_step_relation_ALT_vs_parserFS_step_relation: \"\n  parserFS_step_relation_ALT G c1 p c2 = parserFS_step_relation G c1 p c2\"\n  apply(simp add: parserFS_step_relation_ALT_def parserFS_step_relation_def)\n  done\n\ndefinition parserFS_step_relation_ALT2 :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserFS_conf\n  \\<Rightarrow> ('stack, 'event) parser_step_label\n  \\<Rightarrow> ('stack, 'event) parserFS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"parserFS_step_relation_ALT2 G c1 e c2 \\<equiv>\n  e \\<in> parser_rules G\n  \\<and> (\\<exists>x. parserFS_conf_stack c1 = x @ rule_lpop e\n            \\<and> parserFS_conf_stack c2 = x @ rule_lpush e)\n  \\<and> ((\\<exists>popnew.\n        parserFS_conf_fixed c1 @ popnew = rule_rpop e\n        \\<and> parserFS_conf_scheduler c1 = popnew @ parserFS_conf_scheduler c2\n        \\<and> parserFS_conf_fixed c2 = rule_rpush e)\n     \\<or> (\\<exists>remainder.\n          parserFS_conf_fixed c1 = rule_rpop e @ remainder\n          \\<and> parserFS_conf_scheduler c1 = parserFS_conf_scheduler c2\n          \\<and> parserFS_conf_fixed c2 = rule_rpush e @ remainder)\n  )\"\n\nlemma parserFS_step_relation_ALT2_vs_parserFS_step_relation_ALT: \"\n  valid_parser G\n  \\<Longrightarrow> parserFS_step_relation_ALT2 G c1 p c2 = parserFS_step_relation_ALT G c1 p c2\"\n  apply(simp add: parserFS_step_relation_ALT_def parserFS_step_relation_ALT2_def)\n  apply(rule order_antisym)\n   prefer 2\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: valid_parser_def)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"p\"\n      in ballE)+\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: valid_parser_step_label_def)\n  apply(erule conjE)+\n  apply(erule exE)+\n  apply(rename_tac x k xa)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac x k xa)(*strict*)\n   apply(rule_tac\n      x=\"xa\"\n      in exI)\n   apply(force)\n  apply(rename_tac x k xa)(*strict*)\n  apply(force)\n  done\n\ndefinition parserFS_step_relation_HFS_STYLE :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserFS_conf\n  \\<Rightarrow> ('stack, 'event) parser_step_label\n  \\<Rightarrow> ('stack, 'event) parserFS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"parserFS_step_relation_HFS_STYLE G c1 e c2 \\<equiv>\n  e \\<in> parser_rules G\n  \\<and> (\\<exists>x. parserFS_conf_stack c1 = x @ rule_lpop e\n            \\<and> parserFS_conf_stack c2 = x @ rule_lpush e)\n  \\<and> (\\<exists>x. parserFS_conf_scheduler c1 = rule_rpop e @ x\n         \\<and> parserFS_conf_scheduler c2 = rule_rpush e @ x)\n  \\<and> parserFS_conf_fixed c2\n      = rule_rpush e\n        @ drop\n            (length (rule_rpop e))\n            (parserFS_conf_fixed c1)\"\n\ndefinition parserFS_initial_configurations :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserFS_conf set\"\n  where\n    \"parserFS_initial_configurations G \\<equiv>\n  {c. parserFS_conf_fixed c = []\n      \\<and> parserFS_conf_stack c = [parser_initial G]}\n  \\<inter> parserFS_configurations G\"\n\ndefinition parserFS_marking_configurations :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> ('stack, 'event) parserFS_conf set\"\n  where\n    \"parserFS_marking_configurations G \\<equiv>\n  {c. \\<exists>f \\<in> parser_marking G. \\<exists>w.\n      parserFS_conf_stack c = w @ [f]\n      \\<and> parserFS_conf_fixed c @ parserFS_conf_scheduler c\n          = [parser_bottom G]}\n  \\<inter> parserFS_configurations G\"\n\ndefinition parserFS_marking_condition :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> (('stack, 'event) parser_step_label, ('stack, 'event) parserFS_conf)derivation\n  \\<Rightarrow> bool\"\n  where\n    \"parserFS_marking_condition G d \\<equiv>\n  (\\<exists>c.\n    d 0 =Some (pair None c)\n    \\<and> c \\<in> parserFS_configurations G)\n  \\<and> (\\<exists>i e c.\n      d i = Some (pair e c)\n      \\<and> c \\<in> parserFS_marking_configurations G)\"\n\ndefinition parserFS_marked_effect :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> (('stack, 'event) parser_step_label, ('stack, 'event) parserFS_conf)derivation\n  \\<Rightarrow> 'event list set\"\n  where\n    \"parserFS_marked_effect G d \\<equiv>\n  {w. \\<exists>c.\n      d 0 = Some (pair None c)\n      \\<and> w = butlast (parserFS_conf_scheduler c)}\"\n\ndefinition parserFS_unmarked_effect :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> (('stack, 'event) parser_step_label, ('stack, 'event) parserFS_conf)derivation\n  \\<Rightarrow> 'event list set\"\n  where\n    \"parserFS_unmarked_effect G d \\<equiv>\n  {w. \\<exists>c c' i e v.\n      d 0 = Some (pair None c)\n      \\<and> d i = Some (pair e c')\n      \\<and> v @ parserFS_conf_fixed c' @ parserFS_conf_scheduler c'\n          = parserFS_conf_scheduler c\n      \\<and> w = butlast_if_match\n              (v @ parserFS_conf_fixed c')\n              (parser_bottom G)}\"\n\ndefinition parserFS_get_destinations :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> (('stack, 'event) parser_step_label, ('stack, 'event) parserFS_conf)derivation_configuration\n  \\<Rightarrow> ('stack, 'event) parser_destinations set\"\n  where\n    \"parserFS_get_destinations G e \\<equiv>\n  case e of pair e c \\<Rightarrow>\n    state ` set (parserFS_conf_stack c)\n    \\<union> (case e of None \\<Rightarrow> {} | Some e' \\<Rightarrow> {rule e'})\"\n\ndefinition parserFS_string_state :: \"\n  ('stack, 'event) parserFS_conf\n  \\<Rightarrow> 'event list\"\n  where\n    \"parserFS_string_state c \\<equiv>\n  parserFS_conf_fixed c @ parserFS_conf_scheduler c\"\n\nlemma parserFS_inst_AX_initial_configuration_belongs: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> parserFS_initial_configurations G \\<subseteq> parserFS_configurations G)\"\n  apply(clarsimp)\n  apply(rename_tac G x)(*strict*)\n  apply(simp add: parserFS_initial_configurations_def)\n  done\n\nlemma parserFS_inst_AX_step_relation_preserves_belongs: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c1 e c2. parserFS_step_relation G c1 e c2 \\<longrightarrow> c1 \\<in> parserFS_configurations G \\<longrightarrow> e \\<in> parser_step_labels G \\<and> c2 \\<in> parserFS_configurations G))\"\n  apply(clarsimp)\n  apply(rename_tac G c1 e c2)(*strict*)\n  apply(rule context_conjI)\n   apply(rename_tac G c1 e c2)(*strict*)\n   apply(simp add: parser_step_labels_def parserFS_step_relation_def)\n  apply(rename_tac G c1 e c2)(*strict*)\n  apply(simp add: parserFS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac G e c2 f l r)(*strict*)\n  apply(simp add: parserFS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac G e c2 f r x v)(*strict*)\n  apply(simp add: parser_step_labels_def)\n  apply(subgoal_tac \"valid_parser_step_label G e\")\n   apply(rename_tac G e c2 f r x v)(*strict*)\n   prefer 2\n   apply(simp add: valid_parser_def)\n  apply(rename_tac G e c2 f r x v)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac G e c2 f r x v)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G e c2 f x v popnew)(*strict*)\n   apply(case_tac c2)\n   apply(rename_tac G e c2 f x v popnew parserFS_conf_fixeda parserFS_conf_stacka parserFS_conf_schedulera)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G e f x v popnew parserFS_conf_scheduler)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G e f x v popnew parserFS_conf_scheduler)(*strict*)\n    apply(simp add: valid_parser_step_label_def)\n   apply(rename_tac G e f x v popnew parserFS_conf_scheduler)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G e f x v popnew parserFS_conf_scheduler)(*strict*)\n    apply(simp add: parser_fixed_schedulers_def)\n    apply(simp add: prefix_closure_def prefix_def parser_schedulers_def)\n    apply(clarsimp)\n    apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc c)(*strict*)\n    apply(simp add: valid_parser_step_label_def)\n    apply(clarsimp)\n    apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc c k w)(*strict*)\n    apply(simp add: kPrefix_def)\n    apply(case_tac \"k-length w\")\n     apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc c k w)(*strict*)\n     apply(clarsimp)\n     apply(rule_tac\n      x=\"rule_rpush e @ [parser_bottom G]\"\n      in exI)\n     apply(rule conjI)\n      apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc c k w)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc c k w)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"parser_bottom G \\<in> set w\")\n      apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc c k w)(*strict*)\n      apply(force)\n     apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc c k w)(*strict*)\n     apply (metis elem_set_app in_set_takeD)\n    apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc c k w nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc c k w nat xa)(*strict*)\n    apply(rule_tac\n      x=\"rule_rpush e\"\n      in exI)\n    apply(clarsimp)\n    apply(rule_tac\n      x=\"xa\"\n      in exI)\n    apply(clarsimp)\n    apply(subgoal_tac \"set xa \\<subseteq> set w\")\n     apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc c k w nat xa)(*strict*)\n     apply(rule conjI)\n      apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc c k w nat xa)(*strict*)\n      apply (metis butlast_snoc subset_trans trivButLast)\n     apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc c k w nat xa)(*strict*)\n     apply (metis nset_diff subset_trans)\n    apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc c k w nat xa)(*strict*)\n    apply(rule_tac\n      t=\"w\"\n      and s=\"v@xa\"\n      in ssubst)\n     apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc c k w nat xa)(*strict*)\n     apply(rule_tac\n      v=\"[parser_bottom G]\"\n      in append_injr)\n     apply (metis concat_asso)\n    apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc c k w nat xa)(*strict*)\n    apply(force)\n   apply(rename_tac G e f x v popnew parserFS_conf_scheduler)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G e f x v popnew parserFS_conf_scheduler)(*strict*)\n    apply(simp add: parser_unfixed_schedulers_def)\n    apply(simp add: suffix_closure_def parser_schedulers_def)\n    apply(clarsimp)\n    apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc)(*strict*)\n    apply(simp add: suffix_def)\n    apply(clarsimp)\n    apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc c)(*strict*)\n    apply(rule_tac\n      x=\"vb @ [parser_bottom G]\"\n      in exI)\n    apply(rule conjI)\n     apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc c)(*strict*)\n     prefer 2\n     apply(rule_tac\n      x=\"f@popnew\"\n      in exI)\n     apply(rule sym)\n     apply(rule_tac\n      t=\"vb @ [parser_bottom G]\"\n      and s=\"f @ popnew @ parserFS_conf_scheduler\"\n      in ssubst)\n      apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc c)(*strict*)\n      apply(force)\n     apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc c)(*strict*)\n     apply(simp (no_asm))\n    apply(rename_tac G e f x v popnew parserFS_conf_scheduler vb vc c)(*strict*)\n    apply(force)\n   apply(rename_tac G e f x v popnew parserFS_conf_scheduler)(*strict*)\n   apply(simp add: parser_schedulers_def)\n   apply(clarsimp)\n   apply(rename_tac G e f x v popnew parserFS_conf_scheduler va)(*strict*)\n   apply(case_tac \"parserFS_conf_scheduler\")\n    apply(rename_tac G e f x v popnew parserFS_conf_scheduler va)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G e f x v popnew va)(*strict*)\n    apply(simp add: valid_parser_step_label_def)\n    apply(clarsimp)\n    apply(rename_tac G e f x v popnew va k w xb xc)(*strict*)\n    apply(simp add: kPrefix_def)\n    apply(case_tac \"k-length w\")\n     apply(rename_tac G e f x v popnew va k w xb xc)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"parser_bottom G \\<in> set w\")\n      apply(rename_tac G e f x v popnew va k w xb xc)(*strict*)\n      apply(force)\n     apply(rename_tac G e f x v popnew va k w xb xc)(*strict*)\n     apply (metis kPrefix_def take_reflects_mem)\n    apply(rename_tac G e f x v popnew va k w xb xc nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G e f x v popnew k w xb xc nat)(*strict*)\n    apply(rule_tac\n      x=\"xc\"\n      in exI)\n    apply(clarsimp)\n    apply(subgoal_tac \"set xc \\<subseteq> set w\")\n     apply(rename_tac G e f x v popnew k w xb xc nat)(*strict*)\n     apply(force)\n    apply(rename_tac G e f x v popnew k w xb xc nat)(*strict*)\n    apply (metis butlast_snoc_2 set_append2 snoc_eq_iff_butlast)\n   apply(rename_tac G e f x v popnew parserFS_conf_scheduler va a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. parserFS_conf_scheduler = w' @ [x']\")\n    apply(rename_tac G e f x v popnew parserFS_conf_scheduler va a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac G e f x v popnew parserFS_conf_scheduler va a list)(*strict*)\n   apply(thin_tac \"parserFS_conf_scheduler = a # list\")\n   apply(clarsimp)\n   apply(rename_tac G e f x v popnew w')(*strict*)\n   apply(simp add: valid_parser_step_label_def)\n   apply(clarsimp)\n   apply(rename_tac G e f x v popnew w' k w)(*strict*)\n   apply(simp add: kPrefix_def)\n   apply(case_tac \"k-length w\")\n    apply(rename_tac G e f x v popnew w' k w)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"parser_bottom G \\<in> set w\")\n     apply(rename_tac G e f x v popnew w' k w)(*strict*)\n     apply(force)\n    apply(rename_tac G e f x v popnew w' k w)(*strict*)\n    apply (metis nset_mp set_append2 set_take_subset)\n   apply(rename_tac G e f x v popnew w' k w nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G e f x v popnew w' k w nat xa)(*strict*)\n   apply(case_tac \"popnew\")\n    apply(rename_tac G e f x v popnew w' k w nat xa)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G e f x v popnew w' k w nat xa a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. popnew = w' @ [x']\")\n    apply(rename_tac G e f x v popnew w' k w nat xa a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac G e f x v popnew w' k w nat xa a list)(*strict*)\n   apply(thin_tac \"popnew = a # list\")\n   apply(clarsimp)\n  apply(rename_tac G e c2 f r x v)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G e c2 x v remainder)(*strict*)\n  apply(case_tac c2)\n  apply(rename_tac G e c2 x v remainder parserFS_conf_fixeda parserFS_conf_stacka parserFS_conf_schedulera)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G e x v remainder parserFS_conf_scheduler)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G e x v remainder parserFS_conf_scheduler)(*strict*)\n   apply(simp add: valid_parser_step_label_def)\n  apply(rename_tac G e x v remainder parserFS_conf_scheduler)(*strict*)\n  apply(simp add: parser_fixed_schedulers_def)\n  apply(simp add: prefix_closure_def prefix_def parser_schedulers_def)\n  apply(clarsimp)\n  apply(rename_tac G e x v remainder parserFS_conf_scheduler vb vc c)(*strict*)\n  apply(case_tac c)\n   apply(rename_tac G e x v remainder parserFS_conf_scheduler vb vc c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G e x v remainder parserFS_conf_scheduler vb vc)(*strict*)\n   apply(case_tac \"remainder\")\n    apply(rename_tac G e x v remainder parserFS_conf_scheduler vb vc)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G e x v parserFS_conf_scheduler vb vc)(*strict*)\n    apply(case_tac \"rule_rpush e\")\n     apply(rename_tac G e x v parserFS_conf_scheduler vb vc)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G e x parserFS_conf_scheduler vb vc)(*strict*)\n     apply(simp add: valid_parser_step_label_def)\n    apply(rename_tac G e x v parserFS_conf_scheduler vb vc a list)(*strict*)\n    apply(subgoal_tac \"\\<exists>w' x'. rule_rpush e = w' @ [x']\")\n     apply(rename_tac G e x v parserFS_conf_scheduler vb vc a list)(*strict*)\n     prefer 2\n     apply(rule NonEmptyListHasTailElem)\n     apply(force)\n    apply(rename_tac G e x v parserFS_conf_scheduler vb vc a list)(*strict*)\n    apply(thin_tac \"rule_rpush e = a # list\")\n    apply(clarsimp)\n    apply(rename_tac G e x v parserFS_conf_scheduler vb w')(*strict*)\n    apply(subgoal_tac \"parserFS_conf_scheduler=[]\")\n     apply(rename_tac G e x v parserFS_conf_scheduler vb w')(*strict*)\n     prefer 2\n     apply(case_tac parserFS_conf_scheduler)\n      apply(rename_tac G e x v parserFS_conf_scheduler vb w')(*strict*)\n      apply(clarsimp)\n     apply(rename_tac G e x v parserFS_conf_scheduler vb w' a list)(*strict*)\n     apply(subgoal_tac \"\\<exists>w' x'. parserFS_conf_scheduler = w' @ [x']\")\n      apply(rename_tac G e x v parserFS_conf_scheduler vb w' a list)(*strict*)\n      prefer 2\n      apply(rule NonEmptyListHasTailElem)\n      apply(force)\n     apply(rename_tac G e x v parserFS_conf_scheduler vb w' a list)(*strict*)\n     apply(thin_tac \"parserFS_conf_scheduler = a # list\")\n     apply(clarsimp)\n    apply(rename_tac G e x v parserFS_conf_scheduler vb w')(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G e x v w')(*strict*)\n    apply(rule_tac\n      x=\"w' @ [parser_bottom G]\"\n      in exI)\n    apply(force)\n   apply(rename_tac G e x v remainder parserFS_conf_scheduler vb vc a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. remainder= w' @ [x']\")\n    apply(rename_tac G e x v remainder parserFS_conf_scheduler vb vc a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac G e x v remainder parserFS_conf_scheduler vb vc a list)(*strict*)\n   apply(thin_tac \"remainder = a # list\")\n   apply(clarsimp)\n   apply(rename_tac G e x v parserFS_conf_scheduler vb w')(*strict*)\n   apply(subgoal_tac \"parserFS_conf_scheduler=[]\")\n    apply(rename_tac G e x v parserFS_conf_scheduler vb w')(*strict*)\n    prefer 2\n    apply(case_tac parserFS_conf_scheduler)\n     apply(rename_tac G e x v parserFS_conf_scheduler vb w')(*strict*)\n     apply(clarsimp)\n    apply(rename_tac G e x v parserFS_conf_scheduler vb w' a list)(*strict*)\n    apply(subgoal_tac \"\\<exists>w' x'. parserFS_conf_scheduler = w' @ [x']\")\n     apply(rename_tac G e x v parserFS_conf_scheduler vb w' a list)(*strict*)\n     prefer 2\n     apply(rule NonEmptyListHasTailElem)\n     apply(force)\n    apply(rename_tac G e x v parserFS_conf_scheduler vb w' a list)(*strict*)\n    apply(thin_tac \"parserFS_conf_scheduler = a # list\")\n    apply(clarsimp)\n   apply(rename_tac G e x v parserFS_conf_scheduler vb w')(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G e x v w')(*strict*)\n   apply(rule_tac\n      x=\"rule_rpush e @ w' @ [parser_bottom G]\"\n      in exI)\n   apply(force)\n  apply(rename_tac G e x v remainder parserFS_conf_scheduler vb vc c a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. c= w' @ [x']\")\n   apply(rename_tac G e x v remainder parserFS_conf_scheduler vb vc c a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac G e x v remainder parserFS_conf_scheduler vb vc c a list)(*strict*)\n  apply(thin_tac \"c = a # list\")\n  apply(clarsimp)\n  apply(rename_tac G e x v remainder parserFS_conf_scheduler vb w')(*strict*)\n  apply(case_tac \"remainder\")\n   apply(rename_tac G e x v remainder parserFS_conf_scheduler vb w')(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G e x v parserFS_conf_scheduler vb w')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G e x v parserFS_conf_scheduler vb w')(*strict*)\n    apply(rule_tac\n      x=\"rule_rpush e@[parser_bottom G]\"\n      in exI)\n    apply(force)\n   apply(rename_tac G e x v parserFS_conf_scheduler vb w')(*strict*)\n   apply(case_tac \"parserFS_conf_scheduler\")\n    apply(rename_tac G e x v parserFS_conf_scheduler vb w')(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G e x v vb w')(*strict*)\n    apply(simp add: valid_parser_step_label_def)\n    apply(clarsimp)\n    apply(rename_tac G e x v vb w' k w xb xc)(*strict*)\n    apply(subgoal_tac \"parser_bottom G \\<in> set (rule_rpush e)\")\n     apply(rename_tac G e x v vb w' k w xb xc)(*strict*)\n     apply(force)\n    apply(rename_tac G e x v vb w' k w xb xc)(*strict*)\n    apply(rule_tac\n      t=\"rule_rpush e\"\n      and s=\"xc @ [parser_bottom G]\"\n      in ssubst)\n     apply(rename_tac G e x v vb w' k w xb xc)(*strict*)\n     apply(force)\n    apply(rename_tac G e x v vb w' k w xb xc)(*strict*)\n    apply (metis Nil_is_append_conv last_in_set last_snoc not_Cons_self2)\n   apply(rename_tac G e x v parserFS_conf_scheduler vb w' a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. parserFS_conf_scheduler= w' @ [x']\")\n    apply(rename_tac G e x v parserFS_conf_scheduler vb w' a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac G e x v parserFS_conf_scheduler vb w' a list)(*strict*)\n   apply(thin_tac \"parserFS_conf_scheduler = a # list\")\n   apply(clarsimp)\n  apply(rename_tac G e x v remainder parserFS_conf_scheduler vb w' a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. remainder= w' @ [x']\")\n   apply(rename_tac G e x v remainder parserFS_conf_scheduler vb w' a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac G e x v remainder parserFS_conf_scheduler vb w' a list)(*strict*)\n  apply(thin_tac \"remainder = a # list\")\n  apply(clarsimp)\n  apply(rename_tac G e x v parserFS_conf_scheduler vb w' w'a x')(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G e x v parserFS_conf_scheduler vb w' w'a x')(*strict*)\n   apply(rule_tac\n      x=\"rule_rpush e @ w'a @ [x']@[parser_bottom G]\"\n      in exI)\n   apply(force)\n  apply(rename_tac G e x v parserFS_conf_scheduler vb w' w'a x')(*strict*)\n  apply(case_tac \"parserFS_conf_scheduler\")\n   apply(rename_tac G e x v parserFS_conf_scheduler vb w' w'a x')(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G e x v parserFS_conf_scheduler vb w' w'a x' a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. parserFS_conf_scheduler= w' @ [x']\")\n   apply(rename_tac G e x v parserFS_conf_scheduler vb w' w'a x' a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac G e x v parserFS_conf_scheduler vb w' w'a x' a list)(*strict*)\n  apply(thin_tac \"parserFS_conf_scheduler = a # list\")\n  apply(clarsimp)\n  done\n\ninterpretation \"parserFS\" : loc_autFS_0\n  (* TSstructure *)\n  \"valid_parser\"\n  (* configurations *)\n  \"parserFS_configurations\"\n  (* initial_configurations *)\n  \"parserFS_initial_configurations\"\n  (* step_labels *)\n  \"parser_step_labels\"\n  (* step_relation *)\n  \"parserFS_step_relation\"\n  (* effects *)\n  \"parser_markers\"\n  (* marking_condition *)\n  \"parserFS_marking_condition\"\n  (* marked_effect *)\n  \"parserFS_marked_effect\"\n  (* unmarked_effect *)\n  \"parserFS_unmarked_effect\"\n  (* destinations *)\n  \"parser_destinations\"\n  (* get_destinations *)\n  \"parserFS_get_destinations\"\n  apply(simp add: LOCALE_DEFS parser_interpretations)\n  apply(simp add: parserFS_inst_AX_initial_configuration_belongs parserFS_inst_AX_step_relation_preserves_belongs )\n  done\n\nlemma parserFS_input_decreases: \"\n  valid_parser G\n  \\<Longrightarrow> parserFS.derivation G d\n  \\<Longrightarrow> parserFS.belongs G d\n  \\<Longrightarrow> d i = Some (pair e c)\n  \\<Longrightarrow> d j = Some (pair e' c')\n  \\<Longrightarrow> i\\<le>j\n  \\<Longrightarrow> \\<exists>w. parserFS_conf_scheduler c = w @ parserFS_conf_scheduler c'\"\n  apply(induct \"j-i\" arbitrary: i e c)\n   apply(rename_tac i e c)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x i e c)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d i = Some (pair e1 c1) \\<and> d (Suc i) = Some (pair (Some e2) c2) \\<and> parserFS_step_relation G c1 e2 c2\")\n   apply(rename_tac x i e c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"j\"\n      in parserFS.step_detail_before_some_position)\n     apply(rename_tac x i e c)(*strict*)\n     apply(force)\n    apply(rename_tac x i e c)(*strict*)\n    apply(force)\n   apply(rename_tac x i e c)(*strict*)\n   apply(force)\n  apply(rename_tac x i e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x i e c e2 c2)(*strict*)\n  apply(erule_tac\n      x=\"Suc i\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"Some e2\"\n      in meta_allE)\n  apply(erule_tac\n      x=\"c2\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(erule meta_impE)\n   apply(rename_tac x i e c e2 c2)(*strict*)\n   apply(force)\n  apply(rename_tac x i e c e2 c2)(*strict*)\n  apply(erule meta_impE)\n   apply(rename_tac x i e c e2 c2)(*strict*)\n   apply(force)\n  apply(rename_tac x i e c e2 c2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x i e c e2 c2 w)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. parserFS_conf_scheduler c = w @ parserFS_conf_scheduler c2\")\n   apply(rename_tac x i e c e2 c2 w)(*strict*)\n   apply(force)\n  apply(rename_tac x i e c e2 c2 w)(*strict*)\n  apply(simp add: parserFS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac x i e c e2 c2 w xa v)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac x i e c e2 c2 w xa v)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x i e c e2 c2 w xa v)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma parserFS_input_with_fixed_decreases: \"\n  valid_parser G\n  \\<Longrightarrow> parserFS.derivation G d\n  \\<Longrightarrow> parserFS.belongs G d\n  \\<Longrightarrow> d i = Some (pair e c)\n  \\<Longrightarrow> d j = Some (pair e' c')\n  \\<Longrightarrow> i\\<le>j\n  \\<Longrightarrow> \\<exists>w. parserFS_conf_fixed c @ parserFS_conf_scheduler c = w @ parserFS_conf_fixed c' @ parserFS_conf_scheduler c'\"\n  apply(induct \"j-i\" arbitrary: i e c)\n   apply(rename_tac i e c)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x i e c)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d i = Some (pair e1 c1) \\<and> d (Suc i) = Some (pair (Some e2) c2) \\<and> parserFS_step_relation G c1 e2 c2\")\n   apply(rename_tac x i e c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"j\"\n      in parserFS.step_detail_before_some_position)\n     apply(rename_tac x i e c)(*strict*)\n     apply(force)\n    apply(rename_tac x i e c)(*strict*)\n    apply(force)\n   apply(rename_tac x i e c)(*strict*)\n   apply(force)\n  apply(rename_tac x i e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x i e c e2 c2)(*strict*)\n  apply(erule_tac\n      x=\"Suc i\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"Some e2\"\n      in meta_allE)\n  apply(erule_tac\n      x=\"c2\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(erule meta_impE)\n   apply(rename_tac x i e c e2 c2)(*strict*)\n   apply(force)\n  apply(rename_tac x i e c e2 c2)(*strict*)\n  apply(erule meta_impE)\n   apply(rename_tac x i e c e2 c2)(*strict*)\n   apply(force)\n  apply(rename_tac x i e c e2 c2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x i e c e2 c2 w)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. parserFS_conf_fixed c @ parserFS_conf_scheduler c = w @ parserFS_conf_fixed c2 @ parserFS_conf_scheduler c2\")\n   apply(rename_tac x i e c e2 c2 w)(*strict*)\n   apply(force)\n  apply(rename_tac x i e c e2 c2 w)(*strict*)\n  apply(thin_tac \"parserFS_conf_fixed c2 @ parserFS_conf_scheduler c2 = w @ parserFS_conf_fixed c' @ parserFS_conf_scheduler c'\")\n  apply(rename_tac x i e c e2 c2 w)(*strict*)\n  apply(simp add: parserFS_step_relation_def)\n  apply(rename_tac x i e c e2 c2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x i e c e2 c2 xa v)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac x i e c e2 c2 xa v)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x i e c e2 c2 xa v)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x i e c e2 c2 xa v remainder)(*strict*)\n  apply(rule_tac\n      x=\"v\"\n      in exI)\n  apply(force)\n  done\n\nlemma parserFS_inst_AX_effect_inclusion1: \"\n  (\\<forall>M. valid_parser M \\<longrightarrow>\n         (\\<forall>f. ATS.derivation_initial parserFS_initial_configurations\n               parserFS_step_relation M f \\<longrightarrow>\n              parserFS_marking_condition M f \\<longrightarrow>\n              parserFS_marked_effect M f \\<subseteq> parserFS_unmarked_effect M f))\"\n  apply(clarsimp)\n  apply(rename_tac M f x)(*strict*)\n  apply(simp add: parserFS_unmarked_effect_def parserFS_marked_effect_def parserFS_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac M f c i e cb)(*strict*)\n  apply(rule_tac\n      x=\"cb\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac M f c i e cb)(*strict*)\n   apply(force)\n  apply(rename_tac M f c i e cb)(*strict*)\n  apply(simp add: parserFS_marking_configurations_def parserFS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac M f i e fa l r fb w fc ra)(*strict*)\n  apply(subgoal_tac \"fa=[]\")\n   apply(rename_tac M f i e fa l r fb w fc ra)(*strict*)\n   prefer 2\n   apply(simp add: parserFS.derivation_initial_def)\n   apply(clarsimp)\n   apply(simp add: parserFS_initial_configurations_def)\n  apply(rename_tac M f i e fa l r fb w fc ra)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac M f i e l r fb w fc ra)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. r=w @ ra\")\n   apply(rename_tac M f i e l r fb w fc ra)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"\\<exists>x. parserFS_conf_scheduler \\<lparr>parserFS_conf_fixed = [], parserFS_conf_stack = l, parserFS_conf_scheduler = r\\<rparr> = x @ parserFS_conf_scheduler \\<lparr>parserFS_conf_fixed = fc, parserFS_conf_stack = w @ [fb], parserFS_conf_scheduler = ra\\<rparr>\")\n    apply(rename_tac M f i e l r fb w fc ra)(*strict*)\n    prefer 2\n    apply(rule parserFS_input_decreases)\n         apply(rename_tac M f i e l r fb w fc ra)(*strict*)\n         apply(force)\n        apply(rename_tac M f i e l r fb w fc ra)(*strict*)\n        apply(rule parserFS.derivation_initial_is_derivation)\n        apply(force)\n       apply(rename_tac M f i e l r fb w fc ra)(*strict*)\n       apply(rule parserFS.derivation_initial_belongs)\n        apply(rename_tac M f i e l r fb w fc ra)(*strict*)\n        apply(force)\n       apply(rename_tac M f i e l r fb w fc ra)(*strict*)\n       apply(force)\n      apply(rename_tac M f i e l r fb w fc ra)(*strict*)\n      apply(force)\n     apply(rename_tac M f i e l r fb w fc ra)(*strict*)\n     apply(force)\n    apply(rename_tac M f i e l r fb w fc ra)(*strict*)\n    apply(force)\n   apply(rename_tac M f i e l r fb w fc ra)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac M f i e l r fb w fc ra)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac M f i e l fb w fc ra wa)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. w@fc@ra=wa@ra\")\n   apply(rename_tac M f i e l fb w fc ra wa)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"\\<exists>x. parserFS_conf_fixed \\<lparr>parserFS_conf_fixed = [], parserFS_conf_stack = l, parserFS_conf_scheduler = wa @ ra\\<rparr> @ parserFS_conf_scheduler \\<lparr>parserFS_conf_fixed = [], parserFS_conf_stack = l, parserFS_conf_scheduler = wa @ ra\\<rparr> = x @ parserFS_conf_fixed \\<lparr>parserFS_conf_fixed = fc, parserFS_conf_stack = w @ [fb], parserFS_conf_scheduler = ra\\<rparr> @ parserFS_conf_scheduler \\<lparr>parserFS_conf_fixed = fc, parserFS_conf_stack = w @ [fb], parserFS_conf_scheduler = ra\\<rparr>\")\n    apply(rename_tac M f i e l fb w fc ra wa)(*strict*)\n    prefer 2\n    apply(rule parserFS_input_with_fixed_decreases)\n         apply(rename_tac M f i e l fb w fc ra wa)(*strict*)\n         apply(force)\n        apply(rename_tac M f i e l fb w fc ra wa)(*strict*)\n        apply(rule parserFS.derivation_initial_is_derivation)\n        apply(force)\n       apply(rename_tac M f i e l fb w fc ra wa)(*strict*)\n       apply(rule parserFS.derivation_initial_belongs)\n        apply(rename_tac M f i e l fb w fc ra wa)(*strict*)\n        apply(force)\n       apply(rename_tac M f i e l fb w fc ra wa)(*strict*)\n       apply(force)\n      apply(rename_tac M f i e l fb w fc ra wa)(*strict*)\n      apply(force)\n     apply(rename_tac M f i e l fb w fc ra wa)(*strict*)\n     apply(force)\n    apply(rename_tac M f i e l fb w fc ra wa)(*strict*)\n    apply(force)\n   apply(rename_tac M f i e l fb w fc ra wa)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac M f i e l fb w fc ra wa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac M f i e l fb w fc ra wa wb)(*strict*)\n  apply(case_tac ra)\n   apply(rename_tac M f i e l fb w fc ra wa wb)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac M f i e l fb w wb)(*strict*)\n   apply (metis butlast_if_match_direct)\n  apply(rename_tac M f i e l fb w fc ra wa wb a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. ra = w' @ [x']\")\n   apply(rename_tac M f i e l fb w fc ra wa wb a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac M f i e l fb w fc ra wa wb a list)(*strict*)\n  apply(thin_tac \"ra = a # list\")\n  apply(clarsimp)\n  apply(rename_tac M f i e l fb w wa)(*strict*)\n  apply(simp add: parser_unfixed_schedulers_def parser_schedulers_def)\n  apply(clarsimp)\n  apply (metis butlast_if_match_direct2_prime)\n  done\n\nlemma parserFS_inst_lang_sound: \"\n  (\\<forall>M. valid_parser M \\<longrightarrow> parserFS.unmarked_language M \\<subseteq> parser_markers M)\"\n  apply(clarsimp)\n  apply(rename_tac M x)(*strict*)\n  apply(simp add: parserFS.unmarked_language_def parserFS_unmarked_effect_def parser_markers_def)\n  apply(clarsimp)\n  apply(rename_tac M xa d c c' i v e)(*strict*)\n  apply(subgoal_tac \"c \\<in> parserFS_configurations M\")\n   apply(rename_tac M xa d c c' i v e)(*strict*)\n   apply(subgoal_tac \"c' \\<in> parserFS_configurations M\")\n    apply(rename_tac M xa d c c' i v e)(*strict*)\n    apply(simp add: parserFS_configurations_def parser_unfixed_schedulers_def parser_schedulers_def suffix_closure_def suffix_def parser_fixed_schedulers_def prefix_closure_def prefix_def)\n    apply(clarsimp)\n    apply(rename_tac M xa d i v e f fa l la ra ve ca vg vh cb cc vj \"cd\")(*strict*)\n    apply(rule_tac\n      A=\"set (v@fa)\"\n      in set_mp)\n     apply(rename_tac M xa d i v e f fa l la ra ve ca vg vh cb cc vj \"cd\")(*strict*)\n     prefer 2\n     apply (metis set_butlast_if_match_is_subset subsetD)\n    apply(rename_tac M xa d i v e f fa l la ra ve ca vg vh cb cc vj \"cd\")(*strict*)\n    apply(simp add: valid_parser_def)\n    apply (metis append_Nil2 butlast_if_match_direct butlast_if_match_pull_out set_app_subset set_concat_subset set_subset_in2 subset_trans)\n   apply(rename_tac M xa d c c' i v e)(*strict*)\n   apply(rule parserFS.belongs_configurations)\n    apply(rename_tac M xa d c c' i v e)(*strict*)\n    apply(rule parserFS.derivation_initial_belongs)\n     apply(rename_tac M xa d c c' i v e)(*strict*)\n     apply(force)\n    apply(rename_tac M xa d c c' i v e)(*strict*)\n    apply(force)\n   apply(rename_tac M xa d c c' i v e)(*strict*)\n   apply(force)\n  apply(rename_tac M xa d c c' i v e)(*strict*)\n  apply(rule parserFS.belongs_configurations)\n   apply(rename_tac M xa d c c' i v e)(*strict*)\n   apply(rule parserFS.derivation_initial_belongs)\n    apply(rename_tac M xa d c c' i v e)(*strict*)\n    apply(force)\n   apply(rename_tac M xa d c c' i v e)(*strict*)\n   apply(force)\n  apply(rename_tac M xa d c c' i v e)(*strict*)\n  apply(force)\n  done\n\nlemma parserFS_inst_AX_marking_condition_implies_existence_of_effect: \"\n  (\\<forall>M. valid_parser M \\<longrightarrow>\n         (\\<forall>f. ATS.derivation_initial parserFS_initial_configurations\n               parserFS_step_relation M f \\<longrightarrow>\n              parserFS_marking_condition M f \\<longrightarrow>\n              parserFS_marked_effect M f \\<noteq> {}))\"\n  apply(simp add: parserFS_marking_condition_def parserFS_marked_effect_def)\n  apply(clarsimp)\n  done\n\nlemma parserFS_inst_AX_unmarked_effect_persists: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow>\n         (\\<forall>d. ATS.derivation_initial parserFS_initial_configurations\n               parserFS_step_relation G d \\<longrightarrow>\n              (\\<forall>n. parserFS_unmarked_effect G (derivation_take d n)\n                   \\<subseteq> parserFS_unmarked_effect G d)))\"\n  apply(clarsimp)\n  apply(rename_tac G d n xa)(*strict*)\n  apply(simp add: parserFS_unmarked_effect_def derivation_take_def)\n  apply(clarsimp)\n  apply(rename_tac G d n c c' i v e)(*strict*)\n  apply(case_tac \"i\\<le>n\")\n   apply(rename_tac G d n c c' i v e)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G d n c c' i v e)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n      x=\"c'\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G d n c c' i v e)(*strict*)\n   apply(force)\n  apply(rename_tac G d n c c' i v e)(*strict*)\n  apply(rule_tac\n      x=\"v\"\n      in exI)\n  apply(clarsimp)\n  done\n\nlemma parserFS_inst_ATS_axioms: \"\n  ATS_Language_axioms valid_parser parserFS_initial_configurations\n     parserFS_step_relation parser_markers parserFS_marking_condition\n     parserFS_marked_effect parserFS_unmarked_effect \"\n  apply(simp add: ATS_Language_axioms_def)\n  apply(simp add: parserFS_inst_AX_effect_inclusion1 parserFS_inst_lang_sound parserFS_inst_AX_marking_condition_implies_existence_of_effect parserFS_inst_AX_unmarked_effect_persists )\n  done\n\ninterpretation \"parserFS\" : loc_autFS_1\n  (* TSstructure *)\n  \"valid_parser\"\n  (* configurations *)\n  \"parserFS_configurations\"\n  (* initial_configurations *)\n  \"parserFS_initial_configurations\"\n  (* step_labels *)\n  \"parser_step_labels\"\n  (* step_relation *)\n  \"parserFS_step_relation\"\n  (* effects *)\n  \"parser_markers\"\n  (* marking_condition *)\n  \"parserFS_marking_condition\"\n  (* marked_effect *)\n  \"parserFS_marked_effect\"\n  (* unmarked_effect *)\n  \"parserFS_unmarked_effect\"\n  (* destinations *)\n  \"parser_destinations\"\n  (* get_destinations *)\n  \"parserFS_get_destinations\"\n  apply(simp add: LOCALE_DEFS parser_interpretations)\n  apply(simp add: parserFS_inst_AX_initial_configuration_belongs parserFS_inst_AX_step_relation_preserves_belongs parserFS_inst_ATS_axioms )\n  done\n\nlemma parserFS_inst_AX_marking_can_not_be_disabled: \"\n  (\\<forall>G d. (\\<exists>n. parserFS_marking_condition G (derivation_take d n)) \\<longrightarrow> parserFS_marking_condition G d)\"\n  apply(clarsimp)\n  apply(rename_tac G d n)(*strict*)\n  apply(simp add: parserFS_marking_condition_def derivation_take_def)\n  apply(clarsimp)\n  apply(rename_tac G d n c i e ca)(*strict*)\n  apply(case_tac \"i\\<le>n\")\n   apply(rename_tac G d n c i e ca)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G d n c i e ca)(*strict*)\n  apply(rule_tac\n      x=\"i\"\n      in exI)\n  apply(rule_tac\n      x=\"e\"\n      in exI)\n  apply(rule_tac\n      x=\"ca\"\n      in exI)\n  apply(clarsimp)\n  done\n\nlemma parserFS_inst_AX_marked_effect_persists: \"\n  (\\<forall>G d n. parserFS_marked_effect G (derivation_take d n) \\<subseteq> parserFS_marked_effect G d)\"\n  apply(clarsimp)\n  apply(rename_tac G d n x)(*strict*)\n  apply(simp add: parserFS_marked_effect_def derivation_take_def)\n  done\n\nlemma parserFS_inst_accept: \"\n  \\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d. parserFS.derivation_initial G d \\<longrightarrow> parserFS_marking_condition G d = (\\<exists>i e c. d i = Some (pair e c) \\<and> c \\<in> parserFS_marking_configurations G))\"\n  apply(clarsimp)\n  apply(rename_tac G d)(*strict*)\n  apply(simp add: parserFS_marking_condition_def)\n  apply(rule order_antisym)\n   apply(rename_tac G d)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G d)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G d i e c)(*strict*)\n  apply(simp add: parserFS.derivation_initial_def)\n  apply(clarsimp)\n  apply(case_tac \"d 0\")\n   apply(rename_tac G d i e c)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G d i e c a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac G d i e c a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G d i e c b)(*strict*)\n  apply(simp add: parserFS_initial_configurations_def)\n  done\n\nlemma parserFS_inst_AX_string_state_decreases: \"\n  \\<forall>G. valid_parser G \\<longrightarrow>\n        (\\<forall>c1. c1 \\<in> parserFS_configurations G \\<longrightarrow>\n              (\\<forall>e c2. parserFS_step_relation G c1 e c2 \\<longrightarrow>\n                      (\\<exists>w. parserFS_string_state c1 =\n                           w @ parserFS_string_state c2)))\"\n  apply(clarsimp)\n  apply(rename_tac M c1 e c2)(*strict*)\n  apply(simp add: parserFS_string_state_def parserFS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac M c1 e c2 x v)(*strict*)\n  apply(subgoal_tac \"valid_parser_step_label M e\")\n   apply(rename_tac M e c1 c2 x v)(*strict*)\n   prefer 2\n   apply(rename_tac M c1 e c2 x v)(*strict*)\n   apply(simp add: valid_parser_def)\n  apply(rename_tac M e c1 c2 x v)(*strict*)\n  apply(simp add: valid_parser_step_label_def)\n  apply(clarsimp)\n  apply(rename_tac M e c1 c2 x v k w)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac M e c1 c2 x v k w)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac M e c1 c2 x v k w popnew)(*strict*)\n   apply(rule_tac\n      x=\"v\"\n      in exI)\n   apply(force)\n  apply(rename_tac M e c1 c2 x v k w)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac M e c1 c2 x v k w remainder)(*strict*)\n  apply(rule_tac\n      x=\"v\"\n      in exI)\n  apply(force)\n  done\n\nlemma parserFS_inst_lang_finite: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> parserFS.finite_marked_language G = parserFS.marked_language G)\"\n  apply(clarsimp)\n  apply(rename_tac G)(*strict*)\n  apply(simp add: parserFS.finite_marked_language_def parserFS.marked_language_def)\n  apply(rule order_antisym)\n   apply(rename_tac G)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G x d n)(*strict*)\n   apply(rule_tac\n      x=\"d\"\n      in exI)\n   apply(clarsimp)\n   apply(simp add: parserFS.derivation_initial_def)\n  apply(rename_tac G)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G x d)(*strict*)\n  apply(simp add: parserFS_marked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G d c)(*strict*)\n  apply(simp add: parserFS_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac G d c i e ca)(*strict*)\n  apply(rule_tac\n      x=\"derivation_take d i\"\n      in exI)\n  apply(rule context_conjI)\n   apply(rename_tac G d c i e ca)(*strict*)\n   apply(rule parserFS.derivation_take_preserves_derivation_initial)\n   apply(force)\n  apply(rename_tac G d c i e ca)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G d c i e ca)(*strict*)\n   apply(rule_tac\n      x=\"c\"\n      in exI)\n   apply(clarsimp)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac G d c i e ca)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G d c i e ca)(*strict*)\n   apply(rule_tac\n      x=\"c\"\n      in exI)\n   apply(clarsimp)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac G d c i e ca)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G d c i e ca)(*strict*)\n   apply(rule_tac\n      x=\"i\"\n      in exI)\n   apply(rule_tac\n      x=\"e\"\n      in exI)\n   apply(rule_tac\n      x=\"ca\"\n      in exI)\n   apply(clarsimp)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac G d c i e ca)(*strict*)\n  apply(rule_tac\n      x=\"i\"\n      in exI)\n  apply(rule maximum_of_domain_derivation_take)\n  apply(force)\n  done\n\nlemma parserFS_inst_AX_unmarked_language_finite: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> parserFS.finite_unmarked_language G = parserFS.unmarked_language G)\"\n  apply(clarsimp)\n  apply(rename_tac G)(*strict*)\n  apply(simp add: parserFS.finite_unmarked_language_def parserFS.unmarked_language_def)\n  apply(rule order_antisym)\n   apply(rename_tac G)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G x d n)(*strict*)\n   apply(rule_tac\n      x=\"d\"\n      in exI)\n   apply(clarsimp)\n   apply(simp add: parserFS.derivation_initial_def)\n  apply(rename_tac G)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G x d)(*strict*)\n  apply(simp add: parserFS_unmarked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G d c c' i v e)(*strict*)\n  apply(rule_tac\n      x=\"derivation_take d i\"\n      in exI)\n  apply(rule context_conjI)\n   apply(rename_tac G d c c' i v e)(*strict*)\n   apply(rule parserFS.derivation_take_preserves_derivation_initial)\n   apply(force)\n  apply(rename_tac G d c c' i v e)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G d c c' i v e)(*strict*)\n   apply(rule_tac\n      x=\"c\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac G d c c' i v e)(*strict*)\n    apply(simp add: derivation_take_def)\n   apply(rename_tac G d c c' i v e)(*strict*)\n   apply(rule_tac\n      x=\"c'\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac G d c c' i v e)(*strict*)\n    apply(simp add: derivation_take_def)\n    apply(force)\n   apply(rename_tac G d c c' i v e)(*strict*)\n   apply(rule_tac\n      x=\"v\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac G d c c' i v e)(*strict*)\n  apply(rule_tac\n      x=\"i\"\n      in exI)\n  apply(rule maximum_of_domain_derivation_take)\n  apply(force)\n  done\n\nlemma parserFS_inst_ATS_Language_by_Finite_Derivations_axioms: \"\n  ATS_Language_by_Finite_Derivations_axioms valid_parser\n     parserFS_initial_configurations parserFS_step_relation\n     parserFS_marking_condition parserFS_marked_effect\n     parserFS_unmarked_effect \"\n  apply(simp add: ATS_Language_by_Finite_Derivations_axioms_def)\n  apply(simp add: parserFS_inst_lang_finite parserFS_inst_AX_unmarked_language_finite )\n  done\n\nlemma parserFS_inst_ATS_String_State_Modification_axioms: \"\n  ATS_String_State_Modification_axioms valid_parser parserFS_configurations\n     parserFS_step_relation True parserFS_string_state\"\n  apply(simp add: ATS_String_State_Modification_axioms_def)\n  apply(simp add: parserFS_inst_AX_string_state_decreases )\n  done\n\ninterpretation \"parserFS\" : loc_autFS_2\n  (* TSstructure *)\n  \"valid_parser\"\n  (* configurations *)\n  \"parserFS_configurations\"\n  (* initial_configurations *)\n  \"parserFS_initial_configurations\"\n  (* step_labels *)\n  \"parser_step_labels\"\n  (* step_relation *)\n  \"parserFS_step_relation\"\n  (* effects *)\n  \"parser_markers\"\n  (* marking_condition *)\n  \"parserFS_marking_condition\"\n  (* marked_effect *)\n  \"parserFS_marked_effect\"\n  (* unmarked_effect *)\n  \"parserFS_unmarked_effect\"\n  (* destinations *)\n  \"parser_destinations\"\n  (* get_destinations *)\n  \"parserFS_get_destinations\"\n  (* decreasing *)\n  \"True\"\n  (* string_state *)\n  \"parserFS_string_state\"\n  apply(simp add: LOCALE_DEFS parser_interpretations)\n  apply(simp add: parserFS_inst_AX_initial_configuration_belongs parserFS_inst_AX_step_relation_preserves_belongs )\n  apply(simp add: parserFS_inst_ATS_axioms parserFS_inst_ATS_String_State_Modification_axioms parserFS_inst_ATS_Language_by_Finite_Derivations_axioms )\n  done\n\ndefinition parserFS_get_scheduler :: \"\n  ('stack, 'event) parserFS_conf\n  \\<Rightarrow> 'event list\"\n  where\n    \"parserFS_get_scheduler c \\<equiv>\n  parserFS_conf_fixed c @ parserFS_conf_scheduler c\"\n\ndefinition parserFS_set_unfixed_scheduler :: \"\n  ('stack, 'event) parserFS_conf\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> ('stack, 'event) parserFS_conf\"\n  where\n    \"parserFS_set_unfixed_scheduler c sUF \\<equiv>\n  c \\<lparr>parserFS_conf_scheduler := sUF\\<rparr>\"\n\ndefinition parserFS_get_unfixed_scheduler :: \"\n  ('stack, 'event) parserFS_conf\n  \\<Rightarrow> 'event list\"\n  where\n    \"parserFS_get_unfixed_scheduler c \\<equiv>\n  parserFS_conf_scheduler c\"\n\nlemma parserFS_inst_AX_get_scheduler_closed: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c. c \\<in> parserFS_configurations G \\<longrightarrow> parserFS_get_scheduler c \\<in> parser_schedulers G))\"\n  apply(clarsimp)\n  apply(rename_tac G c)(*strict*)\n  apply(simp add: parserFS_get_scheduler_def parserFS_configurations_def parser_schedulers_def prefix_def)\n  apply(clarsimp)\n  done\n\nlemma parserFS_inst_schedUF_closed: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c. c \\<in> parserFS_configurations G \\<longrightarrow> parserFS_get_unfixed_scheduler c \\<in> parser_unfixed_schedulers G))\"\n  apply(simp add: parserFS_get_unfixed_scheduler_def parser_unfixed_schedulers_def parserFS_configurations_def)\n  apply(clarsimp)\n  done\n\nlemma parserFS_inst_AX_set_unfixed_scheduler_set: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c. c \\<in> parserFS_configurations G \\<longrightarrow> (\\<forall>sUF1. sUF1 \\<in> parser_unfixed_schedulers G \\<longrightarrow> (\\<forall>sUF2. sUF2 \\<in> parser_unfixed_schedulers G \\<longrightarrow> parserFS_set_unfixed_scheduler (parserFS_set_unfixed_scheduler c sUF1) sUF2 = parserFS_set_unfixed_scheduler c sUF2))))\"\n  apply(simp add: parserFS_set_unfixed_scheduler_def)\n  done\n\nlemma parserFS_inst_AX_get_set_unfixed_scheduler: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c. c \\<in> parserFS_configurations G \\<longrightarrow> (\\<forall>sUF. sUF \\<in> parser_unfixed_schedulers G \\<longrightarrow> parserFS_get_unfixed_scheduler (parserFS_set_unfixed_scheduler c sUF) = sUF)))\"\n  apply(simp add: parserFS_get_unfixed_scheduler_def parserFS_set_unfixed_scheduler_def)\n  done\n\nlemma parserFS_inst_AX_set_unfixed_scheduler_get: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c1. c1 \\<in> parserFS_configurations G \\<longrightarrow> (\\<forall>c2. c2 \\<in> parserFS_configurations G \\<longrightarrow> (\\<exists>sUF\\<in> parser_unfixed_schedulers G. parserFS_set_unfixed_scheduler c1 sUF = parserFS_set_unfixed_scheduler c2 sUF) \\<longrightarrow> parserFS_set_unfixed_scheduler c1 (parserFS_get_unfixed_scheduler c2) = c2)))\"\n  apply(clarsimp)\n  apply(rename_tac G c1 c2 sUF)(*strict*)\n  apply(simp add: parserFS_set_unfixed_scheduler_def parserFS_get_unfixed_scheduler_def parserFS_configurations_def prefix_def)\n  apply(clarsimp)\n  done\n\nlemma parserFS_inst_AX_unfixed_scheduler_extendable_quasi_preserved_by_set_unfixed_scheduler : \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c1. c1 \\<in> parserFS_configurations G \\<longrightarrow> (\\<forall>c2. c2 \\<in> parserFS_configurations G \\<longrightarrow> parserFS_get_unfixed_scheduler c1 \\<sqsupseteq> [parser_bottom G] \\<longrightarrow> parserFS_set_unfixed_scheduler c1 (parserFS_get_unfixed_scheduler c2) = c2 \\<longrightarrow> parserFS_get_unfixed_scheduler c2 \\<sqsupseteq> [parser_bottom G])))\"\n  apply(clarsimp)\n  apply(rename_tac G c1 c2)(*strict*)\n  apply(simp add: parserFS_get_unfixed_scheduler_def parserFS_set_unfixed_scheduler_def parserFS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac G fa la r ra)(*strict*)\n  apply(simp add: parser_schedulers_def)\n  apply(clarsimp)\n  apply(rename_tac G fa la r ra v va)(*strict*)\n  apply(simp add: suffix_def)\n  apply(clarsimp)\n  apply(rename_tac G fa la ra va c)(*strict*)\n  apply(case_tac ra)\n   apply(rename_tac G fa la ra va c)(*strict*)\n   apply(force)\n  apply(rename_tac G fa la ra va c a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. ra = w' @ [x']\")\n   apply(rename_tac G fa la ra va c a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac G fa la ra va c a list)(*strict*)\n  apply(thin_tac \"ra = a # list\")\n  apply(force)\n  done\n\nlemma parserFS_unfixed_is_reduced_by_single_step: \"\n  valid_parser G\n  \\<Longrightarrow> c1 \\<in> parserFS_configurations G\n  \\<Longrightarrow> valid_parser_step_label G e\n  \\<Longrightarrow> c2 \\<in> parserFS_configurations G\n  \\<Longrightarrow> parserFS_step_relation G c1 e c2\n  \\<Longrightarrow> parserFS_get_unfixed_scheduler c1 \\<sqsupseteq> parserFS_get_unfixed_scheduler c2\"\n  apply(simp add: parserFS_step_relation_def)\n  apply(simp add: parserFS_get_unfixed_scheduler_def parserFS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac f fa r ra x v)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac f fa r ra x v)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac f ra x v popnew)(*strict*)\n   apply(simp add: suffix_def)\n  apply(rename_tac f fa r ra x v)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ra x v remainder)(*strict*)\n  apply(simp add: suffix_def)\n  done\n\nlemma parserFS_unfixed_is_reduced_by_steps: \"\n  valid_parser G\n  \\<Longrightarrow> parserFS.derivation G d\n  \\<Longrightarrow> parserFS.belongs G d\n  \\<Longrightarrow> d n = Some (pair e c)\n  \\<Longrightarrow> d m = Some (pair e' c')\n  \\<Longrightarrow> n\\<le>m\n  \\<Longrightarrow> suffix (parserFS_get_unfixed_scheduler c) (parserFS_get_unfixed_scheduler c')\"\n  apply(induct \"m-n\" arbitrary: n m e c e' c')\n   apply(rename_tac n m e c e' c')(*strict*)\n   apply(clarsimp)\n   apply(rename_tac n e' c')(*strict*)\n   apply(simp add: suffix_def)\n  apply(rename_tac x n m e c e' c')(*strict*)\n  apply(erule_tac\n      x=\"Suc n\"\n      in meta_allE)\n  apply(erule_tac\n      x=\"m\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d n = Some (pair e1 c1) \\<and> d (Suc n) = Some (pair (Some e2) c2) \\<and> parserFS_step_relation G c1 e2 c2\")\n   apply(rename_tac x n m e c e' c')(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"m\"\n      in parserFS.step_detail_before_some_position)\n     apply(rename_tac x n m e c e' c')(*strict*)\n     apply(force)\n    apply(rename_tac x n m e c e' c')(*strict*)\n    apply(force)\n   apply(rename_tac x n m e c e' c')(*strict*)\n   apply(force)\n  apply(rename_tac x n m e c e' c')(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x n m e c e' c' e2 c2)(*strict*)\n  apply(erule_tac\n      x=\"Some e2\"\n      in meta_allE)\n  apply(erule_tac\n      x=\"c2\"\n      in meta_allE)\n  apply(erule_tac\n      x=\"e'\"\n      in meta_allE)\n  apply(erule_tac\n      x=\"c'\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(erule_tac meta_impE)\n   apply(rename_tac x n m e c e' c' e2 c2)(*strict*)\n   apply(force)\n  apply(rename_tac x n m e c e' c' e2 c2)(*strict*)\n  apply(erule_tac meta_impE)\n   apply(rename_tac x n m e c e' c' e2 c2)(*strict*)\n   apply(force)\n  apply(rename_tac x n m e c e' c' e2 c2)(*strict*)\n  apply(subgoal_tac \"parserFS_get_unfixed_scheduler c \\<sqsupseteq> parserFS_get_unfixed_scheduler c2\")\n   apply(rename_tac x n m e c e' c' e2 c2)(*strict*)\n   apply(simp add: suffix_def)\n   apply(force)\n  apply(rename_tac x n m e c e' c' e2 c2)(*strict*)\n  apply(rule parserFS_unfixed_is_reduced_by_single_step)\n      apply(rename_tac x n m e c e' c' e2 c2)(*strict*)\n      apply(force)\n     apply(rename_tac x n m e c e' c' e2 c2)(*strict*)\n     apply (metis parserFS.belongs_configurations)\n    apply(rename_tac x n m e c e' c' e2 c2)(*strict*)\n    prefer 2\n    apply (metis parserFS.belongs_configurations)\n   apply(rename_tac x n m e c e' c' e2 c2)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac x n m e c e' c' e2 c2)(*strict*)\n  apply(simp add: parserFS_step_relation_def valid_parser_def)\n  done\n\nlemma parserFS_inst_AX_unfixed_scheduler_right_quotient_split: \"\n  \\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d. parserFS.derivation G d \\<longrightarrow> parserFS.belongs G d \\<longrightarrow> (\\<forall>n e1 c1. d n = Some (pair e1 c1) \\<longrightarrow> (\\<forall>m e2 c2. d m = Some (pair e2 c2) \\<longrightarrow> (\\<forall>k e3 c3. d k = Some (pair e3 c3) \\<longrightarrow> n \\<le> m \\<longrightarrow> m \\<le> k \\<longrightarrow> the (right_quotient_word (parserFS_get_unfixed_scheduler c1) (parserFS_get_unfixed_scheduler c3)) = the (right_quotient_word (parserFS_get_unfixed_scheduler c1) (parserFS_get_unfixed_scheduler c2)) @ the (right_quotient_word (parserFS_get_unfixed_scheduler c2) (parserFS_get_unfixed_scheduler c3))))))\"\n  apply(clarsimp)\n  apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3)(*strict*)\n  apply(subgoal_tac \"suffix (parserFS_get_unfixed_scheduler c1) (parserFS_get_unfixed_scheduler c2)\")\n   apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3)(*strict*)\n   prefer 2\n   apply(rule parserFS_unfixed_is_reduced_by_steps)\n        apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3)(*strict*)\n        apply(force)\n       apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3)(*strict*)\n       apply(force)\n      apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3)(*strict*)\n      apply(force)\n     apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3)(*strict*)\n     apply(force)\n    apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3)(*strict*)\n    apply(force)\n   apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3)(*strict*)\n   apply(force)\n  apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3)(*strict*)\n  apply(subgoal_tac \"suffix (parserFS_get_unfixed_scheduler c2) (parserFS_get_unfixed_scheduler c3)\")\n   apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3)(*strict*)\n   prefer 2\n   apply(rule parserFS_unfixed_is_reduced_by_steps)\n        apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3)(*strict*)\n        apply(force)\n       apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3)(*strict*)\n       apply(force)\n      apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3)(*strict*)\n      apply(force)\n     apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3)(*strict*)\n     apply(force)\n    apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3)(*strict*)\n    apply(force)\n   apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3)(*strict*)\n   apply(force)\n  apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3)(*strict*)\n  apply(simp add: suffix_def)\n  apply(clarsimp)\n  apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3 c ca)(*strict*)\n  apply(rule_tac\n      t=\"right_quotient_word (c @ ca @ parserFS_get_unfixed_scheduler c3) (parserFS_get_unfixed_scheduler c3)\"\n      and s=\"Some(c@ca)\"\n      in ssubst)\n   apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3 c ca)(*strict*)\n   apply(rule right_quotient_word_Some_by_append)\n   apply(force)\n  apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3 c ca)(*strict*)\n  apply(rule_tac\n      t=\"right_quotient_word (c @ ca @ parserFS_get_unfixed_scheduler c3) (ca@parserFS_get_unfixed_scheduler c3)\"\n      and s=\"Some c\"\n      in ssubst)\n   apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3 c ca)(*strict*)\n   apply(rule right_quotient_word_Some_by_append)\n   apply(force)\n  apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3 c ca)(*strict*)\n  apply(rule_tac\n      t=\"right_quotient_word (ca @ parserFS_get_unfixed_scheduler c3) (parserFS_get_unfixed_scheduler c3)\"\n      and s=\"Some ca\"\n      in ssubst)\n   apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3 c ca)(*strict*)\n   apply(rule right_quotient_word_Some_by_append)\n   apply(force)\n  apply(rename_tac G d n e1 c1 m e2 c2 k e3 c3 c ca)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma parserFS_inst_ATS_SchedUF_SB_axioms: \"\n  ATS_SchedUF_SB_axioms valid_parser parserFS_configurations\n     parser_step_labels parserFS_step_relation (@)\n     parser_unfixed_schedulers right_quotient_word\n     parser_unfixed_scheduler_extendable parserFS_set_unfixed_scheduler\n     parserFS_get_unfixed_scheduler\"\n  apply(simp add: ATS_SchedUF_SB_axioms_def)\n  apply(simp add: parserFS_inst_schedUF_closed parserFS_inst_AX_set_unfixed_scheduler_set parserFS_inst_AX_get_set_unfixed_scheduler parserFS_inst_AX_set_unfixed_scheduler_get )\n  apply(rule conjI, rule parserFS_inst_AX_unfixed_scheduler_extendable_quasi_preserved_by_set_unfixed_scheduler)\n  apply(rule parserFS_inst_AX_unfixed_scheduler_right_quotient_split)\n  done\n\nlemma parserFS_inst_AX_fixed_scheduler_extendable_translates_backwards: \"\n  \\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c1. c1 \\<in> parserFS_configurations G \\<longrightarrow> (\\<forall>e c2. parserFS_step_relation G c1 e c2 \\<longrightarrow> \\<not> parserFS_conf_fixed c2 \\<sqsupseteq> [parser_bottom G] \\<longrightarrow> \\<not> parserFS_conf_fixed c1 \\<sqsupseteq> [parser_bottom G]))\"\n  apply(clarsimp)\n  apply(rename_tac G c1 e c2)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. parserFS_string_state c1 = w @ parserFS_string_state c2\")\n   apply(rename_tac G c1 e c2)(*strict*)\n   prefer 2\n   apply(rule parserFS.AX_string_state_decreases)\n      apply(rename_tac G c1 e c2)(*strict*)\n      apply(force)\n     apply(rename_tac G c1 e c2)(*strict*)\n     apply(force)\n    apply(rename_tac G c1 e c2)(*strict*)\n    apply(simp add: parser_step_labels_def parserFS_step_relation_def)\n   apply(rename_tac G c1 e c2)(*strict*)\n   apply(force)\n  apply(rename_tac G c1 e c2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G c1 e c2 w)(*strict*)\n  apply(subgoal_tac \"valid_parser_step_label G e\")\n   apply(rename_tac G c1 e c2 w)(*strict*)\n   prefer 2\n   apply(simp add: parserFS_step_relation_def valid_parser_def)\n  apply(rename_tac G c1 e c2 w)(*strict*)\n  apply(subgoal_tac \"c2 \\<in> parserFS_configurations G\")\n   apply(rename_tac G c1 e c2 w)(*strict*)\n   prefer 2\n   apply(rule parserFS.AX_step_relation_preserves_belongsC)\n     apply(rename_tac G c1 e c2 w)(*strict*)\n     apply(force)\n    apply(rename_tac G c1 e c2 w)(*strict*)\n    apply(force)\n   apply(rename_tac G c1 e c2 w)(*strict*)\n   apply(force)\n  apply(rename_tac G c1 e c2 w)(*strict*)\n  apply(simp add: parserFS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac G c1 e c2 w x v)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac G c1 e c2 w x v)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G c1 e c2 w x v popnew)(*strict*)\n   apply(simp add: suffix_def)\n   apply(clarsimp)\n   apply(rename_tac G c1 e c2 w x v popnew c)(*strict*)\n   apply(case_tac popnew)\n    apply(rename_tac G c1 e c2 w x v popnew c)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G c1 e c2 w x v c)(*strict*)\n    apply(case_tac \"rule_rpush e\")\n     apply(rename_tac G c1 e c2 w x v c)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G c1 e c2 w x c)(*strict*)\n     apply(simp add: valid_parser_step_label_def)\n    apply(rename_tac G c1 e c2 w x v c a list)(*strict*)\n    apply(subgoal_tac \"\\<exists>w' x'. rule_rpush e = w' @ [x']\")\n     apply(rename_tac G c1 e c2 w x v c a list)(*strict*)\n     prefer 2\n     apply(rule NonEmptyListHasTailElem)\n     apply(force)\n    apply(rename_tac G c1 e c2 w x v c a list)(*strict*)\n    apply(thin_tac \"rule_rpush e = a # list\")\n    apply(force)\n   apply(rename_tac G c1 e c2 w x v popnew c a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. popnew = w' @ [x']\")\n    apply(rename_tac G c1 e c2 w x v popnew c a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac G c1 e c2 w x v popnew c a list)(*strict*)\n   apply(thin_tac \"popnew = a # list\")\n   apply(clarsimp)\n   apply(rename_tac G c1 e c2 w x v c w' x')(*strict*)\n   apply(simp add: valid_parser_step_label_def)\n   apply(clarsimp)\n   apply(rename_tac G c1 e c2 w x v c w' x' k wa)(*strict*)\n   apply(simp add: kPrefix_def)\n   apply(subgoal_tac \"parser_bottom G \\<in> set wa\")\n    apply(rename_tac G c1 e c2 w x v c w' x' k wa)(*strict*)\n    apply(subgoal_tac \"parser_bottom G \\<notin> set wa\")\n     apply(rename_tac G c1 e c2 w x v c w' x' k wa)(*strict*)\n     apply(force)\n    apply(rename_tac G c1 e c2 w x v c w' x' k wa)(*strict*)\n    apply (metis not_in_diff)\n   apply(rename_tac G c1 e c2 w x v c w' x' k wa)(*strict*)\n   apply(case_tac \"k-length wa\")\n    apply(rename_tac G c1 e c2 w x v c w' x' k wa)(*strict*)\n    apply(clarsimp)\n    apply (metis take_reflects_mem)\n   apply(rename_tac G c1 e c2 w x v c w' x' k wa nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G c1 e c2 w x v)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G c1 e c2 w x v remainder)(*strict*)\n  apply(simp add: suffix_def)\n  apply(clarsimp)\n  apply(rename_tac G c1 e c2 w x v remainder c)(*strict*)\n  apply(simp add: parserFS_string_state_def)\n  apply(clarsimp)\n  apply(rename_tac G c1 e c2 w x remainder c)(*strict*)\n  apply(case_tac c1)\n  apply(rename_tac G c1 e c2 w x remainder c parserFS_conf_fixeda parserFS_conf_stacka parserFS_conf_schedulera)(*strict*)\n  apply(case_tac c2)\n  apply(rename_tac G c1 e c2 w x remainder c parserFS_conf_fixeda parserFS_conf_stacka parserFS_conf_schedulera parserFS_conf_fixedaa parserFS_conf_stackaa parserFS_conf_scheduleraa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G e w x remainder c parserFS_conf_schedulera)(*strict*)\n  apply(rename_tac r)\n  apply(rename_tac G e w x remainder c r)(*strict*)\n  apply(case_tac remainder)\n   apply(rename_tac G e w x remainder c r)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G e w x c r)(*strict*)\n   apply(case_tac \"rule_rpush e\")\n    apply(rename_tac G e w x c r)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G e x c r)(*strict*)\n    apply(simp add: valid_parser_step_label_def)\n   apply(rename_tac G e w x c r a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. rule_rpush e = w' @ [x']\")\n    apply(rename_tac G e w x c r a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac G e w x c r a list)(*strict*)\n   apply(thin_tac \"rule_rpush e = a # list\")\n   apply(force)\n  apply(rename_tac G e w x remainder c r a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. remainder = w' @ [x']\")\n   apply(rename_tac G e w x remainder c r a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac G e w x remainder c r a list)(*strict*)\n  apply(thin_tac \"remainder = a # list\")\n  apply(clarsimp)\n  done\n\nlemma parserFS_inst_ATS_SchedF_SB_axioms: \"\n  ATS_SchedF_SB_axioms valid_parser parserFS_configurations\n     parserFS_step_relation parser_fixed_scheduler_extendable\n     parserFS_conf_fixed\"\n  apply(simp add: ATS_SchedF_SB_axioms_def)\n  apply(simp add: parserFS_inst_AX_fixed_scheduler_extendable_translates_backwards )\n  done\n\nlemma parserFS_inst_AX_not_extendable_fixed_scheduler_implies_empty_unfixed_scheduler: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c. c \\<in> parserFS_configurations G \\<longrightarrow> parserFS_conf_fixed c \\<sqsupseteq> [parser_bottom G] \\<longrightarrow> parserFS_get_unfixed_scheduler c = []))\"\n  apply(clarsimp)\n  apply(rename_tac G c)(*strict*)\n  apply(simp add: parserFS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac G f l r)(*strict*)\n  apply(simp add: parserFS_get_unfixed_scheduler_def)\n  apply(simp add: prefix_def suffix_def)\n  apply(clarsimp)\n  apply(rename_tac G l r c)(*strict*)\n  apply(simp add: parser_schedulers_def)\n  apply(clarsimp)\n  apply(rename_tac G l r c v)(*strict*)\n  apply(case_tac r)\n   apply(rename_tac G l r c v)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G l r c v a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. r = w' @ [x']\")\n   apply(rename_tac G l r c v a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac G l r c v a list)(*strict*)\n  apply(thin_tac \"r = a # list\")\n  apply(clarsimp)\n  done\n\nlemma parserFS_inst_extendable_implies_notempty_unfixed: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c. c \\<in> parserFS_configurations G \\<longrightarrow> \\<not> parserFS_conf_fixed c \\<sqsupseteq> [parser_bottom G] \\<longrightarrow> parserFS_get_unfixed_scheduler c \\<noteq> []))\"\n  apply(clarsimp)\n  apply(rename_tac G c)(*strict*)\n  apply(simp add: parserFS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac G f l r)(*strict*)\n  apply(simp add: parserFS_get_unfixed_scheduler_def)\n  apply(simp add: suffix_def prefix_def)\n  apply(clarsimp)\n  apply(rename_tac G f l)(*strict*)\n  apply(simp add: parser_schedulers_def)\n  done\n\nlemma parserFS_inst_AX_get_scheduler_vs_get_fixed_scheduler_and_get_unfixed_scheduler: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c. c \\<in> parserFS_configurations G \\<longrightarrow> parserFS_get_scheduler c = parserFS_conf_fixed c @ parserFS_get_unfixed_scheduler c))\"\n  apply(clarsimp)\n  apply(rename_tac G c)(*strict*)\n  apply(simp add: parserFS_configurations_def prefix_def)\n  apply(clarsimp)\n  apply(rename_tac G f l r)(*strict*)\n  apply(simp add: parserFS_get_unfixed_scheduler_def)\n  apply(simp add: parserFS_get_scheduler_def)\n  done\n\nlemma parserFS_inst_AX_unfixed_scheduler_extendable_vs_fixed_scheduler_extendable: \"\n  \\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c. c \\<in> parserFS_configurations G \\<longrightarrow> parserFS_get_unfixed_scheduler c \\<sqsupseteq> [parser_bottom G] = (\\<not> parserFS_conf_fixed c \\<sqsupseteq> [parser_bottom G]))\"\n  apply(clarsimp)\n  apply(rename_tac G c)(*strict*)\n  apply(simp add: prefix_def suffix_def parserFS_configurations_def parserFS_get_unfixed_scheduler_def)\n  apply(clarsimp)\n  apply(rename_tac G f l r)(*strict*)\n  apply(simp add: parser_schedulers_def parser_unfixed_schedulers_def parser_fixed_schedulers_def prefix_closure_def suffix_closure_def prefix_def suffix_def)\n  apply(clarsimp)\n  apply(rename_tac G f l r vb vc c vd ca)(*strict*)\n  apply(rule order_antisym)\n   apply(rename_tac G f l r vb vc c vd ca)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G f l r vb vc c vd ca)(*strict*)\n  apply(clarsimp)\n  apply(case_tac r)\n   apply(rename_tac G f l r vb vc c vd ca)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G f l r vb vc c vd ca a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. r = w' @ [x']\")\n   apply(rename_tac G f l r vb vc c vd ca a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac G f l r vb vc c vd ca a list)(*strict*)\n  apply(thin_tac \"r = a # list\")\n  apply(clarsimp)\n  done\n\nlemma parserFS_inst_AX_equal_up_to_unfixed_scheduler_implies_equal_fixed_scheduler: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>c1. c1 \\<in> parserFS_configurations G \\<longrightarrow> (\\<forall>c2. c2 \\<in> parserFS_configurations G \\<longrightarrow> parserFS_set_unfixed_scheduler c1 (parserFS_get_unfixed_scheduler c2) = c2 \\<longrightarrow> parserFS_conf_fixed c1 = parserFS_conf_fixed c2)))\"\n  apply(simp add: parserFS_set_unfixed_scheduler_def parserFS_get_unfixed_scheduler_def)\n  apply(clarsimp)\n  apply(rename_tac G c1 c2)(*strict*)\n  apply(case_tac c1)\n  apply(rename_tac G c1 c2 parserFS_conf_fixeda parserFS_conf_stack parserFS_conf_schedulera)(*strict*)\n  apply(case_tac c2)\n  apply(rename_tac G c1 c2 parserFS_conf_fixeda parserFS_conf_stack parserFS_conf_schedulera parserFS_conf_fixedaa parserFS_conf_stacka parserFS_conf_scheduleraa)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma parserFS_inst_ATS_Sched_axioms: \"\n  ATS_Sched_axioms valid_parser parserFS_configurations\n     parser_scheduler_fragments parser_empty_scheduler_fragment (@)\n     parser_schedulers parser_schedulers parser_empty_scheduler\n     parserFS_get_scheduler (@)\"\n  apply(simp add: ATS_Sched_axioms_def)\n  apply(simp add: parser_inst_AX_join_fixed_scheduler_unfixed_scheduler_closed parser_inst_AX_extend_scheduler_closed parser_inst_AX_empty_scheduler_in_schedulers parserFS_inst_AX_get_scheduler_closed )\n  done\n\nlemma parserFS_inst_ATS_Sched_SB_axioms: \"\n  ATS_Sched_SB_axioms valid_parser parserFS_configurations\n     parser_fixed_scheduler_extendable parser_empty_unfixed_scheduler\n     parser_unfixed_scheduler_extendable parserFS_get_scheduler (@)\n     parserFS_set_unfixed_scheduler parserFS_get_unfixed_scheduler\n     parserFS_conf_fixed\"\n  apply(simp add: ATS_Sched_SB_axioms_def)\n  apply(simp add: parserFS_inst_AX_not_extendable_fixed_scheduler_implies_empty_unfixed_scheduler parserFS_inst_extendable_implies_notempty_unfixed parserFS_inst_AX_get_scheduler_vs_get_fixed_scheduler_and_get_unfixed_scheduler parserFS_inst_AX_unfixed_scheduler_extendable_vs_fixed_scheduler_extendable )\n  apply(rule parserFS_inst_AX_equal_up_to_unfixed_scheduler_implies_equal_fixed_scheduler)\n  done\n\nprint_locale loc_autFS_3\ninterpretation \"parserFS\" : loc_autFS_3\n  (* TSstructure *)\n  \"valid_parser\"\n  (* configurations *)\n  \"parserFS_configurations\"\n  (* initial_configurations *)\n  \"parserFS_initial_configurations\"\n  (* step_labels *)\n  \"parser_step_labels\"\n  (* step_relation *)\n  \"parserFS_step_relation\"\n  (* effects *)\n  \"parser_markers\"\n  (* marking_condition *)\n  \"parserFS_marking_condition\"\n  (* marked_effect *)\n  \"parserFS_marked_effect\"\n  (* unmarked_effect *)\n  \"parserFS_unmarked_effect\"\n  (* destinations *)\n  \"parser_destinations\"\n  (* get_destinations *)\n  \"parserFS_get_destinations\"\n  (* decreasing *)\n  \"True\"\n  (* string_state *)\n  \"parserFS_string_state\"\n  (* fixed_schedulers *)\n  \"parser_fixed_schedulers\"\n  (* empty_fixed_scheduler *)\n  \"parser_empty_fixed_scheduler\"\n  (* fixed_scheduler_extendable *)\n  \"parser_fixed_scheduler_extendable\"\n  (* scheduler_fragments *)\n  \"parser_scheduler_fragments\"\n  (* empty_scheduler_fragment *)\n  \"parser_empty_scheduler_fragment\"\n  (* join_scheduler_fragments *)\n  \"append\"\n  (* unfixed_schedulers *)\n  \"parser_unfixed_schedulers\"\n  (* empty_unfixed_scheduler *)\n  \"parser_empty_unfixed_scheduler\"\n  (* unfixed_scheduler_right_quotient_word *)\n  \"right_quotient_word\"\n  (* extend_unfixed_scheduler *)\n  \"append\"\n  (* unfixed_scheduler_extendable *)\n  \"parser_unfixed_scheduler_extendable\"\n  (* schedulers *)\n  \"parser_schedulers\"\n  (* initial_schedulers *)\n  \"parser_schedulers\"\n  (* empty_scheduler *)\n  \"parser_empty_scheduler\"\n  (* get_scheduler *)\n  \"parserFS_get_scheduler\"\n  (* join_fixed_scheduler_unfixed_scheduler *)\n  \"append\"\n  (* extend_scheduler *)\n  \"append\"\n  (* set_unfixed_scheduler *)\n  \"parserFS_set_unfixed_scheduler\"\n  (* get_unfixed_scheduler *)\n  \"parserFS_get_unfixed_scheduler\"\n  (* get_fixed_scheduler *)\n  \"parserFS_conf_fixed\"\n  apply(simp add: LOCALE_DEFS parser_interpretations)\n  apply(simp add: parserFS_inst_AX_initial_configuration_belongs parserFS_inst_AX_step_relation_preserves_belongs )\n  apply(simp add: parserFS_inst_ATS_axioms parserFS_inst_ATS_String_State_Modification_axioms parserFS_inst_ATS_Language_by_Finite_Derivations_axioms parserFS_inst_ATS_SchedUF_SB_axioms parserFS_inst_ATS_SchedF_SB_axioms parserFS_inst_ATS_Sched_axioms parserFS_inst_ATS_Sched_SB_axioms )\n  done\n\ndefinition parserFS_get_fixed_scheduler_DB :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> (('stack, 'event) parser_step_label, ('stack, 'event) parserFS_conf) derivation\n  \\<Rightarrow> nat\n  \\<Rightarrow> 'event list\"\n  where\n    \"parserFS_get_fixed_scheduler_DB G d n \\<equiv>\n  parserFS_conf_fixed (the (get_configuration (d n)))\"\n\ndefinition parserFS_set_unfixed_scheduler_DB :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> (('stack, 'event) parser_step_label, ('stack, 'event) parserFS_conf) derivation\n  \\<Rightarrow> nat\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> ('stack, 'event) parserFS_conf\"\n  where\n    \"parserFS_set_unfixed_scheduler_DB G d n sUF \\<equiv>\n  parserFS_set_unfixed_scheduler\n    (the (get_configuration (d n))) sUF\"\n\ndefinition parserFS_get_unfixed_scheduler_DB :: \"\n  ('stack, 'event, 'marker) parser\n  \\<Rightarrow> (('stack, 'event) parser_step_label, ('stack, 'event) parserFS_conf) derivation\n  \\<Rightarrow> nat\n  \\<Rightarrow> 'event list\"\n  where\n    \"parserFS_get_unfixed_scheduler_DB G d n \\<equiv>\n  parserFS_conf_scheduler (the (get_configuration (d n)))\"\n\nlemma parserFS_inst_AX_set_unfixed_scheduler_DB_preserves_initial_configurations: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d. parserFS.derivation G d \\<longrightarrow> (\\<forall>c. d 0 = Some (pair None c) \\<longrightarrow> c \\<in> parserFS_initial_configurations G \\<longrightarrow> (\\<forall>sUF. sUF \\<in> parser_unfixed_schedulers G \\<longrightarrow> parserFS_get_unfixed_scheduler_DB G d 0 \\<sqsupseteq> [parser_bottom G] \\<longrightarrow> sUF \\<sqsupseteq> [parser_bottom G] \\<longrightarrow> parserFS_set_unfixed_scheduler_DB G d 0 sUF \\<in> parserFS_initial_configurations G))))\"\n  apply(clarsimp)\n  apply(rename_tac G d c sUF)(*strict*)\n  apply(simp add: get_configuration_def parserFS_set_unfixed_scheduler_DB_def parserFS_initial_configurations_def parserFS_configurations_def parserFS_get_fixed_scheduler_DB_def parser_unfixed_schedulers_def parser_schedulers_def suffix_closure_def suffix_def prefix_def)\n  apply(clarsimp)\n  apply(rename_tac G d ca cb cc vc \"cd\")(*strict*)\n  apply(simp add: parserFS_set_unfixed_scheduler_def)\n  apply(rule_tac\n      x=\"cb @ [parser_bottom G]\"\n      in exI)\n  apply(force)\n  done\n\nlemma parserFS_inst_AX_get_unfixed_scheduler_DB_extendable_on_initial_configuration: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d. parserFS.derivation_initial G d \\<longrightarrow> parserFS_get_unfixed_scheduler_DB G d 0 \\<sqsupseteq> [parser_bottom G]))\"\n  apply(clarsimp)\n  apply(rename_tac G d)(*strict*)\n  apply(simp add: parserFS_get_unfixed_scheduler_DB_def)\n  apply(subgoal_tac \"\\<exists>c. d 0 = Some (pair None c)\")\n   apply(rename_tac G d)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G d c)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(subgoal_tac \"c \\<in> parserFS_configurations G\")\n    apply(rename_tac G d c)(*strict*)\n    apply(simp add: parserFS_configurations_def parserFS_get_scheduler_def)\n    apply(clarsimp)\n    apply(rename_tac G d f l r)(*strict*)\n    apply(simp add: suffix_def)\n    apply(simp add: parser_unfixed_schedulers_def parser_fixed_schedulers_def parser_schedulers_def prefix_def suffix_def prefix_closure_def suffix_closure_def)\n    apply(clarsimp)\n    apply(rename_tac G d f l r vb vc c vd ca)(*strict*)\n    apply(simp add: parserFS.derivation_initial_def)\n    apply(simp add: parserFS_initial_configurations_def)\n   apply(rename_tac G d c)(*strict*)\n   apply (metis parserFS.belongs_configurations parserFS.derivation_initial_belongs)\n  apply(rename_tac G d)(*strict*)\n  apply (metis parserFS.derivation_initial_is_derivation parserFS.some_position_has_details_at_0)\n  done\n\nlemma parserFS_inst_AX_get_unfixed_scheduler_DB_closed: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d. parserFS.derivation G d \\<longrightarrow> parserFS.belongs G d \\<longrightarrow> (\\<forall>n. (\\<exists>e c. d n = Some (pair e c)) \\<longrightarrow> parserFS_get_unfixed_scheduler_DB G d n \\<in> parser_unfixed_schedulers G)))\"\n  apply(clarsimp)\n  apply(rename_tac G d n e c)(*strict*)\n  apply(simp add: parser_unfixed_schedulers_def parserFS_get_unfixed_scheduler_DB_def)\n  apply(simp add: get_configuration_def)\n  apply(subgoal_tac \"c \\<in> parserFS_configurations G\")\n   apply(rename_tac G d n e c)(*strict*)\n   prefer 2\n   apply(rule parserFS.belongs_configurations)\n    apply(rename_tac G d n e c)(*strict*)\n    apply(force)\n   apply(rename_tac G d n e c)(*strict*)\n   apply(force)\n  apply(rename_tac G d n e c)(*strict*)\n  apply(simp add: prefix_closure_def prefix_def parser_fixed_schedulers_def parser_unfixed_schedulers_def suffix_closure_def suffix_def parserFS_configurations_def parser_schedulers_def)\n  apply(clarsimp)\n  apply(rename_tac G d n e f l r vb vc ca vd cb)(*strict*)\n  apply(force)\n  done\n\nlemma parserFS_inst_get_unfixed_scheduler_DB_constructs_right_quotient: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d. parserFS.derivation_initial G d \\<longrightarrow> (\\<forall>n. (\\<exists>y. d n = Some y) \\<longrightarrow> (\\<forall>j. parserFS_get_unfixed_scheduler_DB G d j \\<sqsupseteq> [parser_bottom G] \\<longrightarrow> (\\<forall>i\\<le>j. j \\<le> n \\<longrightarrow> the (right_quotient_word (parserFS_get_unfixed_scheduler_DB G d i) (parserFS_get_unfixed_scheduler_DB G d j)) \\<in> parser_scheduler_fragments G)))))\"\n  apply(clarsimp)\n  apply(rename_tac G d n y j i)(*strict*)\n  apply(simp add: parserFS_get_unfixed_scheduler_DB_def)\n  apply(subgoal_tac \"\\<exists>e c. d i = Some (pair e c)\")\n   apply(rename_tac G d n y j i)(*strict*)\n   apply(subgoal_tac \"\\<exists>e c. d j = Some (pair e c)\")\n    apply(rename_tac G d n y j i)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G d n y j i e ea c ca)(*strict*)\n    apply(simp add: get_configuration_def)\n    apply(subgoal_tac \"\\<exists>w. parserFS_conf_scheduler c = w @ parserFS_conf_scheduler ca\")\n     apply(rename_tac G d n y j i e ea c ca)(*strict*)\n     prefer 2\n     apply(rule_tac\n      j=\"j\"\n      in parserFS_input_decreases)\n          apply(rename_tac G d n y j i e ea c ca)(*strict*)\n          apply(force)\n         apply(rename_tac G d n y j i e ea c ca)(*strict*)\n         apply(rule parserFS.derivation_initial_is_derivation)\n         apply(force)\n        apply(rename_tac G d n y j i e ea c ca)(*strict*)\n        apply(rule parserFS.derivation_initial_belongs)\n         apply(rename_tac G d n y j i e ea c ca)(*strict*)\n         apply(force)\n        apply(rename_tac G d n y j i e ea c ca)(*strict*)\n        apply(force)\n       apply(rename_tac G d n y j i e ea c ca)(*strict*)\n       apply(force)\n      apply(rename_tac G d n y j i e ea c ca)(*strict*)\n      apply(force)\n     apply(rename_tac G d n y j i e ea c ca)(*strict*)\n     apply(force)\n    apply(rename_tac G d n y j i e ea c ca)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G d n y j i e ea c ca w)(*strict*)\n    apply(subgoal_tac \"the (right_quotient_word (w @ parserFS_conf_scheduler ca) (parserFS_conf_scheduler ca))=w\")\n     apply(rename_tac G d n y j i e ea c ca w)(*strict*)\n     apply(clarsimp)\n     apply(simp add: parser_scheduler_fragments_def)\n     apply(subgoal_tac \"c \\<in> parserFS_configurations G\")\n      apply(rename_tac G d n y j i e ea c ca w)(*strict*)\n      apply(subgoal_tac \"ca \\<in> parserFS_configurations G\")\n       apply(rename_tac G d n y j i e ea c ca w)(*strict*)\n       apply(simp add: parserFS_configurations_def)\n       apply(clarsimp)\n       apply(rename_tac G d n y j i e ea w f fa l la ra)(*strict*)\n       apply(simp add: prefix_closure_def prefix_def parser_schedulers_def parser_unfixed_schedulers_def parser_fixed_schedulers_def suffix_closure_def suffix_def)\n       apply(clarsimp)\n      apply(rename_tac G d n y j i e ea c ca w)(*strict*)\n      apply (metis parserFS.belongs_configurations parserFS.derivation_initial_belongs)\n     apply(rename_tac G d n y j i e ea c ca w)(*strict*)\n     apply (metis parserFS.belongs_configurations parserFS.derivation_initial_belongs)\n    apply(rename_tac G d n y j i e ea c ca w)(*strict*)\n    apply (metis right_quotient_word_removes_right_addition option.sel)\n   apply(rename_tac G d n y j i)(*strict*)\n   apply(rule parserFS.pre_some_position_is_some_position)\n     apply(rename_tac G d n y j i)(*strict*)\n     apply(simp add: parserFS.derivation_initial_def)\n     apply(force)\n    apply(rename_tac G d n y j i)(*strict*)\n    apply(force)\n   apply(rename_tac G d n y j i)(*strict*)\n   apply(force)\n  apply(rename_tac G d n y j i)(*strict*)\n  apply(rule parserFS.pre_some_position_is_some_position)\n    apply(rename_tac G d n y j i)(*strict*)\n    apply(simp add: parserFS.derivation_initial_def)\n    apply(force)\n   apply(rename_tac G d n y j i)(*strict*)\n   apply(force)\n  apply(rename_tac G d n y j i)(*strict*)\n  apply(force)\n  done\n\nlemma parserFS_parser_fixed_input_length_recN_with_derivation_take: \"\n  i\\<le>n\n  \\<Longrightarrow> parserFS.derivation M d\n  \\<Longrightarrow> parser_fixed_input_length_recN (derivation_take d n) i = parser_fixed_input_length_recN d i\"\n  apply(induct i)\n   apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"d (Suc i)\")\n   apply(rename_tac i)(*strict*)\n   apply(clarsimp)\n   apply(simp add: derivation_take_def)\n  apply(rename_tac i a)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d i = Some (pair e1 c1) \\<and> d (Suc i) = Some (pair (Some e2) c2) \\<and> parserFS_step_relation M c1 e2 c2\")\n   apply(rename_tac i a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc i\"\n      in parserFS.step_detail_before_some_position)\n     apply(rename_tac i a)(*strict*)\n     apply(force)\n    apply(rename_tac i a)(*strict*)\n    apply(force)\n   apply(rename_tac i a)(*strict*)\n   apply(force)\n  apply(rename_tac i a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i e1 e2 c1 c2)(*strict*)\n  apply(simp add: derivation_take_def)\n  done\n\nlemma parserFS_inst_AX_get_unfixed_scheduler_DB_invariant_under_derivation_take: \"\n  \\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d. parserFS.derivation_initial G d \\<longrightarrow> (\\<forall>n m. n \\<le> m \\<longrightarrow> parserFS_get_unfixed_scheduler_DB G d n = parserFS_get_unfixed_scheduler_DB G (derivation_take d m) n))\"\n  apply(clarsimp)\n  apply(rename_tac G d n m)(*strict*)\n  apply(simp add: parserFS_get_unfixed_scheduler_DB_def)\n  apply(rule_tac\n      t=\"parser_fixed_input_length_recN (derivation_take d m) n\"\n      and s=\"parser_fixed_input_length_recN d n\"\n      in ssubst)\n   apply(rename_tac G d n m)(*strict*)\n   defer\n   apply(simp add: derivation_take_def)\n  apply(rename_tac G d n m)(*strict*)\n  apply (metis parserFS.derivation_initial_is_derivation parserFS_parser_fixed_input_length_recN_with_derivation_take)\n  done\n\nlemma parserFS_inst_ATS_SchedUF_DB_axioms: \"\n  ATS_SchedUF_DB_axioms valid_parser parserFS_configurations\n     parserFS_initial_configurations parser_step_labels\n     parserFS_step_relation parser_scheduler_fragments\n     parser_unfixed_schedulers right_quotient_word\n     parser_unfixed_scheduler_extendable parserFS_set_unfixed_scheduler_DB\n     parserFS_get_unfixed_scheduler_DB\"\n  apply(simp add: ATS_SchedUF_DB_axioms_def)\n  apply(simp add: parserFS_inst_AX_set_unfixed_scheduler_DB_preserves_initial_configurations parserFS_inst_AX_get_unfixed_scheduler_DB_extendable_on_initial_configuration parserFS_inst_AX_get_unfixed_scheduler_DB_closed parserFS_inst_get_unfixed_scheduler_DB_constructs_right_quotient )\n  apply(rule parserFS_inst_AX_get_unfixed_scheduler_DB_invariant_under_derivation_take)\n  done\n\nlemma parserFS_parser_fixed_input_length_recN_with_derivation_append: \"\n  i\\<le>n\n  \\<Longrightarrow> parserFS.derivation M d1\n  \\<Longrightarrow> parser_fixed_input_length_recN (derivation_append d1 d2 n) i = parser_fixed_input_length_recN d1 i\"\n  apply(induct i)\n   apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(clarsimp)\n  apply(simp add: derivation_append_def)\n  apply(case_tac \"d1 (Suc i)\")\n   apply(rename_tac i)(*strict*)\n   apply(clarsimp)\n   apply(simp add: derivation_append_def)\n  apply(rename_tac i a)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d1 i = Some (pair e1 c1) \\<and> d1 (Suc i) = Some (pair (Some e2) c2) \\<and> parserFS_step_relation M c1 e2 c2\")\n   apply(rename_tac i a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc i\"\n      in parserFS.step_detail_before_some_position)\n     apply(rename_tac i a)(*strict*)\n     apply(force)\n    apply(rename_tac i a)(*strict*)\n    apply(force)\n   apply(rename_tac i a)(*strict*)\n   apply(force)\n  apply(rename_tac i a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i e1 e2 c1 c2)(*strict*)\n  apply(simp add: derivation_append_def)\n  done\n\nlemma parserFS_inst_AX_get_fixed_scheduler_DB_restrict: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>x n. x \\<le> n \\<longrightarrow> (\\<forall>d1. parserFS.derivation G d1 \\<longrightarrow> (\\<forall>d2. parserFS_get_fixed_scheduler_DB G (derivation_append d1 d2 n) x = parserFS_get_fixed_scheduler_DB G d1 x))))\"\n  apply(clarsimp)\n  apply(rename_tac G x n d1 d2)(*strict*)\n  apply(simp add: parserFS_get_fixed_scheduler_DB_def parserFS_get_scheduler_def)\n  apply(rule_tac\n      t=\"derivation_append d1 d2 n x\"\n      and s=\"d1 x\"\n      in ssubst)\n   apply(rename_tac G x n d1 d2)(*strict*)\n   apply(simp add: derivation_append_def)\n  apply(rename_tac G x n d1 d2)(*strict*)\n  apply(rule_tac\n      t=\"parser_fixed_input_length_recN (derivation_append d1 d2 n) x\"\n      and s=\"parser_fixed_input_length_recN d1 x\"\n      in ssubst)\n   apply(rename_tac G x n d1 d2)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G x n d1 d2)(*strict*)\n  apply (metis parserFS_parser_fixed_input_length_recN_with_derivation_append)\n  done\n\nlemmas dom_abbreviation =\n  parser_fixed_schedulers_def\n  parser_unfixed_schedulers_def\n  parser_schedulers_def\n  prefix_def\n  prefix_closure_def\n  suffix_closure_def\n  suffix_def\n\nlemma parserFS_inst_AX_schedF_db_extendable_translates_backwards: \"\n  \\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d1. parserFS.derivation G d1 \\<longrightarrow> parserFS.belongs G d1 \\<longrightarrow> (\\<forall>n x. (\\<exists>y. d1 (n + x) = Some y) \\<longrightarrow> \\<not> parserFS_get_fixed_scheduler_DB G d1 (n + x) \\<sqsupseteq> [parser_bottom G] \\<longrightarrow> \\<not> parserFS_get_fixed_scheduler_DB G d1 n \\<sqsupseteq> [parser_bottom G]))\"\n  apply(clarsimp)\n  apply(rename_tac G d1 n x y)(*strict*)\n  apply(simp add: parserFS_get_fixed_scheduler_DB_def)\n  apply(case_tac y)\n  apply(rename_tac G d1 n x y option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G d1 n x option b)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d1 n = Some (pair e c)\")\n   apply(rename_tac G d1 n x option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G d1 n x option b e c)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(subgoal_tac \"c \\<in> parserFS_configurations G\")\n    apply(rename_tac G d1 n x option b e c)(*strict*)\n    apply(subgoal_tac \"b \\<in> parserFS_configurations G\")\n     apply(rename_tac G d1 n x option b e c)(*strict*)\n     apply(subgoal_tac \"parserFS_conf_scheduler c = []\")\n      apply(rename_tac G d1 n x option b e c)(*strict*)\n      apply(subgoal_tac \"parserFS_conf_scheduler b = []\")\n       apply(rename_tac G d1 n x option b e c)(*strict*)\n       apply(subgoal_tac \"parserFS_conf_fixed b \\<sqsupseteq> [parser_bottom G]\")\n        apply(rename_tac G d1 n x option b e c)(*strict*)\n        apply(force)\n       apply(rename_tac G d1 n x option b e c)(*strict*)\n       apply(simp add: parserFS_configurations_def)\n       apply(clarsimp)\n       apply(rename_tac G d1 n x option e f fa l la)(*strict*)\n       apply(simp add: dom_abbreviation)\n      apply(rename_tac G d1 n x option b e c)(*strict*)\n      apply(subgoal_tac \"\\<exists>w. parserFS_conf_scheduler c = w @ parserFS_conf_scheduler b\")\n       apply(rename_tac G d1 n x option b e c)(*strict*)\n       prefer 2\n       apply(rule_tac\n      j=\"n+x\"\n      in parserFS_input_decreases)\n            apply(rename_tac G d1 n x option b e c)(*strict*)\n            apply(force)\n           apply(rename_tac G d1 n x option b e c)(*strict*)\n           apply(force)\n          apply(rename_tac G d1 n x option b e c)(*strict*)\n          apply(force)\n         apply(rename_tac G d1 n x option b e c)(*strict*)\n         apply(force)\n        apply(rename_tac G d1 n x option b e c)(*strict*)\n        apply(force)\n       apply(rename_tac G d1 n x option b e c)(*strict*)\n       apply(force)\n      apply(rename_tac G d1 n x option b e c)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac G d1 n x option b e c)(*strict*)\n     apply(simp add: parserFS_configurations_def)\n     apply(clarsimp)\n     apply(rename_tac G d1 n x option e f fa l la r ra)(*strict*)\n     apply(simp add: dom_abbreviation)\n     apply(clarsimp)\n     apply(rename_tac G d1 n x option e fa l la r ra c vc ve vf ca vg cb vh cc vi \"cd\")(*strict*)\n     apply(case_tac r)\n      apply(rename_tac G d1 n x option e fa l la r ra c vc ve vf ca vg cb vh cc vi \"cd\")(*strict*)\n      apply(force)\n     apply(rename_tac G d1 n x option e fa l la r ra c vc ve vf ca vg cb vh cc vi \"cd\" a list)(*strict*)\n     apply(subgoal_tac \"\\<exists>w' x'. r = w' @ [x']\")\n      apply(rename_tac G d1 n x option e fa l la r ra c vc ve vf ca vg cb vh cc vi \"cd\" a list)(*strict*)\n      prefer 2\n      apply(rule NonEmptyListHasTailElem)\n      apply(force)\n     apply(rename_tac G d1 n x option e fa l la r ra c vc ve vf ca vg cb vh cc vi \"cd\" a list)(*strict*)\n     apply(thin_tac \"r = a # list\")\n     apply(clarsimp)\n    apply(rename_tac G d1 n x option b e c)(*strict*)\n    apply (metis parserFS.belongs_configurations)\n   apply(rename_tac G d1 n x option b e c)(*strict*)\n   apply (metis parserFS.belongs_configurations)\n  apply(rename_tac G d1 n x option b)(*strict*)\n  apply(rule parserFS.pre_some_position_is_some_position)\n    apply(rename_tac G d1 n x option b)(*strict*)\n    apply(simp add: parserFS.derivation_initial_def)\n   apply(rename_tac G d1 n x option b)(*strict*)\n   apply(force)\n  apply(rename_tac G d1 n x option b)(*strict*)\n  apply(force)\n  done\n\nlemma parserFS_inst_AX_get_fixed_scheduler_DB_in_fixed_schedulers: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d. parserFS.derivation G d \\<longrightarrow> parserFS.belongs G d \\<longrightarrow> (\\<forall>n. (\\<exists>y. d n = Some y) \\<longrightarrow> parserFS_get_fixed_scheduler_DB G d n \\<in> parser_fixed_schedulers G)))\"\n  apply(clarsimp)\n  apply(rename_tac G d n y)(*strict*)\n  apply(simp add: parserFS_get_fixed_scheduler_DB_def get_configuration_def)\n  apply(case_tac y)\n  apply(rename_tac G d n y option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G d n option b)(*strict*)\n  apply(subgoal_tac \"b \\<in> parserFS_configurations G\")\n   apply(rename_tac G d n option b)(*strict*)\n   prefer 2\n   apply (metis parserFS.belongs_configurations)\n  apply(rename_tac G d n option b)(*strict*)\n  apply(simp add: parserFS_get_scheduler_def parserFS_configurations_def parser_fixed_schedulers_def)\n  apply(clarsimp)\n  done\n\nlemma parserFS_inst_ATS_SchedF_DB_axioms: \"\n  ATS_SchedF_DB_axioms valid_parser parserFS_configurations\n     parser_step_labels parserFS_step_relation parser_fixed_schedulers\n     parser_fixed_scheduler_extendable parserFS_get_fixed_scheduler_DB\"\n  apply(simp add: ATS_SchedF_DB_axioms_def)\n  apply(simp add: parserFS_inst_AX_get_fixed_scheduler_DB_in_fixed_schedulers parserFS_inst_AX_get_fixed_scheduler_DB_restrict parserFS_inst_AX_schedF_db_extendable_translates_backwards )\n  done\n\nlemma parserFS_inst_AX_join_fixed_scheduler_unfixed_scheduler_closed_prime: \"\n  \\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d. parserFS.derivation_initial G d \\<longrightarrow> (\\<forall>n. (\\<exists>y. d n = Some y) \\<longrightarrow> parserFS_get_fixed_scheduler_DB G d n @ parserFS_get_unfixed_scheduler_DB G d n \\<in> parser_schedulers G))\"\n  apply(clarsimp)\n  apply(rename_tac G d n y)(*strict*)\n  apply(simp add: parserFS_get_fixed_scheduler_DB_def parserFS_get_scheduler_def)\n  apply(case_tac y)\n  apply(rename_tac G d n y option b)(*strict*)\n  apply(simp add: get_configuration_def parserFS_get_unfixed_scheduler_DB_def parserFS_get_scheduler_def)\n  apply(subgoal_tac \"b \\<in> parserFS_configurations G\")\n   apply(rename_tac G d n y option b)(*strict*)\n   prefer 2\n   apply (metis parserFS.belongs_configurations parserFS.derivation_initial_belongs)\n  apply(rename_tac G d n y option b)(*strict*)\n  apply(simp add: parserFS_configurations_def)\n  apply(clarsimp)\n  done\n\nlemma parserFS_inst_AX_get_fixed_scheduler_DB_and_get_unfixed_scheduler_DB_vs_get_scheduler_nth: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d. parserFS.derivation G d \\<longrightarrow> (\\<forall>n. (\\<exists>y. d n = Some y) \\<longrightarrow> parserFS_get_fixed_scheduler_DB G d n @ parserFS_get_unfixed_scheduler_DB G d n = ATS_Sched.get_scheduler_nth parserFS_get_scheduler d n)))\"\n  apply(clarsimp)\n  apply(rename_tac G d n y)(*strict*)\n  apply(simp add: parserFS.get_scheduler_nth_def)\n  apply(case_tac y)\n  apply(rename_tac G d n y option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G d n option b)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(simp add: parserFS_get_fixed_scheduler_DB_def)\n  apply(simp add: parserFS_get_unfixed_scheduler_DB_def)\n  apply(simp add: get_configuration_def)\n  apply(simp add: parserFS_get_scheduler_def)\n  done\n\nlemma parserFS_inst_AX_sched_modification_preserves_steps: \"\n  \\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>dh n. maximum_of_domain dh n \\<longrightarrow> parserFS.derivation G dh \\<longrightarrow> parserFS.belongs G dh \\<longrightarrow> (\\<forall>sUF. sUF \\<in> parser_unfixed_schedulers G \\<longrightarrow> (\\<exists>sF. \\<not> sF \\<sqsupseteq> [parser_bottom G]) \\<longrightarrow> sUF \\<sqsupseteq> [parser_bottom G] \\<longrightarrow> (\\<forall>m e2 c2. dh (Suc m) = Some (pair (Some e2) c2) \\<longrightarrow> (\\<forall>e1 c1. dh m = Some (pair e1 c1) \\<longrightarrow> parserFS_step_relation G c1 e2 c2 \\<longrightarrow> parserFS_step_relation G (parserFS_set_unfixed_scheduler_DB G dh m (the (right_quotient_word (parserFS_get_unfixed_scheduler_DB G dh m) (parserFS_get_unfixed_scheduler_DB G dh n)) @ sUF)) e2 (parserFS_set_unfixed_scheduler_DB G dh (Suc m) (the (right_quotient_word (parserFS_get_unfixed_scheduler_DB G dh (Suc m)) (parserFS_get_unfixed_scheduler_DB G dh n)) @ sUF))))))\"\n  apply(clarsimp)\n  apply(rename_tac G dh n sUF sF m e2 c2 e1 c1)(*strict*)\n  apply(simp add: get_configuration_def parserFS_set_unfixed_scheduler_DB_def parserFS_get_fixed_scheduler_DB_def parserFS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v)(*strict*)\n  apply(simp add: parserFS_set_unfixed_scheduler_def)\n  apply(simp add: parserFS_get_unfixed_scheduler_DB_def)\n  apply(clarsimp)\n  apply(simp add: get_configuration_def)\n  apply(subgoal_tac \"\\<exists>e c. dh n= Some (pair e c)\")\n   apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v)(*strict*)\n   prefer 2\n   apply(rule parserFS.some_position_has_details_before_max_dom)\n     apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v)(*strict*)\n     apply(force)\n    apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v)(*strict*)\n    apply(force)\n   apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v)(*strict*)\n   apply(force)\n  apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. parserFS_conf_scheduler c1 = w @ parserFS_conf_scheduler c2\")\n   apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      j=\"Suc m\"\n      in parserFS_input_decreases)\n        apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c)(*strict*)\n        apply(force)\n       apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c)(*strict*)\n       apply(force)\n      apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c)(*strict*)\n      apply(force)\n     apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c)(*strict*)\n     apply(force)\n    apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c)(*strict*)\n    apply(force)\n   apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c)(*strict*)\n   apply(force)\n  apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w)(*strict*)\n  apply(subgoal_tac \"Suc m\\<le>n\")\n   apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w)(*strict*)\n   apply(subgoal_tac \"\\<exists>w. parserFS_conf_scheduler c2 = w @ parserFS_conf_scheduler c\")\n    apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w)(*strict*)\n    prefer 2\n    apply(rule_tac\n      j=\"n\"\n      in parserFS_input_decreases)\n         apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w)(*strict*)\n         apply(force)\n        apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w)(*strict*)\n        apply(force)\n       apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w)(*strict*)\n       apply(force)\n      apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w)(*strict*)\n      apply(force)\n     apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w)(*strict*)\n     apply(force)\n    apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w)(*strict*)\n    apply(force)\n   apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w wa)(*strict*)\n   apply(subgoal_tac \"the (right_quotient_word (w @ wa @ parserFS_conf_scheduler c) (parserFS_conf_scheduler c))=w@wa\")\n    apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w wa)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"the (right_quotient_word (wa @ parserFS_conf_scheduler c) (parserFS_conf_scheduler c))=wa\")\n     apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w wa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c wa remainder)(*strict*)\n     apply(force)\n    apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w wa)(*strict*)\n    apply (metis right_quotient_word_removes_right_addition option.sel)\n   apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w wa)(*strict*)\n   apply(rule_tac\n      t=\"w @ wa @ parserFS_conf_scheduler c\"\n      and s=\"(w @ wa) @ parserFS_conf_scheduler c\"\n      in ssubst)\n    apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w wa)(*strict*)\n    apply(force)\n   apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w wa)(*strict*)\n   apply (metis right_quotient_word_removes_right_addition option.sel)\n  apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w)(*strict*)\n  apply(rule parserFS.allPreMaxDomSome_prime)\n    apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w)(*strict*)\n    apply(force)\n   apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w)(*strict*)\n   apply(force)\n  apply(rename_tac G dh n sUF sF m e2 c2 e1 c1 x v e c w)(*strict*)\n  apply(force)\n  done\n\nlemma parserFS_inst_AX_fixed_scheduler_extendable_vs_unfixed_scheduler_extendable_DB: \"\n   \\<forall>G::('stack, 'event, 'marker) parser.\n       valid_parser G \\<longrightarrow>\n       (\\<forall>d::(('stack, 'event) parser_step_label,\n                   ('stack, 'event) parserFS_conf) derivation.\n           ATS.derivation_initial parserFS_initial_configurations\n            parserFS_step_relation G d \\<longrightarrow>\n           (\\<forall>n::nat.\n               (\\<exists>y::(('stack, 'event) parser_step_label,\n                    ('stack, 'event) parserFS_conf) derivation_configuration.\n                   d n = Some y) \\<longrightarrow>\n               (\\<not> parserFS_get_fixed_scheduler_DB G d n \\<sqsupseteq> [parser_bottom G]) =\n               parserFS_get_unfixed_scheduler_DB G d n \\<sqsupseteq> [parser_bottom G]))\"\n  apply(clarsimp)\n  apply(rename_tac G d n y)(*strict*)\n  apply(simp add: parserFS_get_fixed_scheduler_DB_def parserFS_get_unfixed_scheduler_DB_def get_configuration_def)\n  apply(case_tac y)\n  apply(rename_tac G d n y option conf)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G d n option conf)(*strict*)\n  apply(rename_tac e c)\n  apply(rename_tac G d n e c)(*strict*)\n  apply(simp add: suffix_def)\n  apply(subgoal_tac \"c \\<in> parserFS_configurations G\")\n   apply(rename_tac G d n e c)(*strict*)\n   prefer 2\n   apply (metis parserFS.derivation_initial_configurations)\n  apply(rename_tac G d n e c)(*strict*)\n  apply(rule antisym)\n   apply(rename_tac G d n e c)(*strict*)\n   apply(clarsimp)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac G d n e c ca cb)(*strict*)\n   apply(subgoal_tac \"c \\<notin> parserFS_configurations G\")\n    apply(rename_tac G d n e c ca cb)(*strict*)\n    prefer 2\n    apply(simp add: parserFS_configurations_def parser_schedulers_def)\n    apply(clarsimp)\n   apply(rename_tac G d n e c ca cb)(*strict*)\n   apply(force)\n  apply(rename_tac G d n e c)(*strict*)\n  apply(simp add: parserFS_configurations_def parser_schedulers_def)\n  apply(clarsimp)\n  apply(rename_tac G d n e f l r v)(*strict*)\n  apply(rule_tac\n      xs=\"r\"\n      in rev_cases)\n   apply(rename_tac G d n e f l r v)(*strict*)\n   prefer 2\n   apply(rename_tac G d n e f l r v ys y)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G d n e f l r v)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma parserFS_inst_ATS_Sched_DB0_axioms: \"\n  ATS_Sched_DB0_axioms valid_parser parserFS_configurations\n     parserFS_initial_configurations parser_step_labels\n     parserFS_step_relation parser_fixed_scheduler_extendable\n     parser_unfixed_schedulers right_quotient_word (@)\n     parser_unfixed_scheduler_extendable parser_schedulers\n     parserFS_get_scheduler (@) parserFS_set_unfixed_scheduler_DB\n     parserFS_get_unfixed_scheduler_DB parserFS_get_fixed_scheduler_DB\"\n  apply(simp add: ATS_Sched_DB0_axioms_def)\n  apply(simp add: parserFS_inst_AX_join_fixed_scheduler_unfixed_scheduler_closed_prime parserFS_inst_AX_get_fixed_scheduler_DB_and_get_unfixed_scheduler_DB_vs_get_scheduler_nth parserFS_inst_AX_sched_modification_preserves_steps parserFS_inst_AX_fixed_scheduler_extendable_vs_unfixed_scheduler_extendable_DB )\n  done\n\nprint_locale loc_autFS_4\ninterpretation \"parserFS\" : loc_autFS_4\n  (* TSstructure *)\n  \"valid_parser\"\n  (* configurations *)\n  \"parserFS_configurations\"\n  (* initial_configurations *)\n  \"parserFS_initial_configurations\"\n  (* step_labels *)\n  \"parser_step_labels\"\n  (* step_relation *)\n  \"parserFS_step_relation\"\n  (* effects *)\n  \"parser_markers\"\n  (* marking_condition *)\n  \"parserFS_marking_condition\"\n  (* marked_effect *)\n  \"parserFS_marked_effect\"\n  (* unmarked_effect *)\n  \"parserFS_unmarked_effect\"\n  (* destinations *)\n  \"parser_destinations\"\n  (* get_destinations *)\n  \"parserFS_get_destinations\"\n  (* decreasing *)\n  \"True\"\n  (* string_state *)\n  \"parserFS_string_state\"\n  (* fixed_schedulers *)\n  \"parser_fixed_schedulers\"\n  (* empty_fixed_scheduler *)\n  \"parser_empty_fixed_scheduler\"\n  (* fixed_scheduler_extendable *)\n  \"parser_fixed_scheduler_extendable\"\n  (* scheduler_fragments *)\n  \"parser_scheduler_fragments\"\n  (* empty_scheduler_fragment *)\n  \"parser_empty_scheduler_fragment\"\n  (* join_scheduler_fragments *)\n  \"append\"\n  (* unfixed_schedulers *)\n  \"parser_unfixed_schedulers\"\n  (* empty_unfixed_scheduler *)\n  \"parser_empty_unfixed_scheduler\"\n  (* unfixed_scheduler_right_quotient_word *)\n  \"right_quotient_word\"\n  (* extend_unfixed_scheduler *)\n  \"append\"\n  (* unfixed_scheduler_extendable *)\n  \"parser_unfixed_scheduler_extendable\"\n  (* schedulers *)\n  \"parser_schedulers\"\n  (* initial_schedulers *)\n  \"parser_schedulers\"\n  (* empty_scheduler *)\n  \"parser_empty_scheduler\"\n  (* get_scheduler *)\n  \"parserFS_get_scheduler\"\n  (* join_fixed_scheduler_unfixed_scheduler *)\n  \"append\"\n  (* extend_scheduler *)\n  \"append\"\n  (* set_unfixed_scheduler *)\n  \"parserFS_set_unfixed_scheduler\"\n  (* get_unfixed_scheduler *)\n  \"parserFS_get_unfixed_scheduler\"\n  (* get_fixed_scheduler *)\n  \"parserFS_conf_fixed\"\n  (* set_unfixed_scheduler_DB *)\n  \"parserFS_set_unfixed_scheduler_DB\"\n  (* get_unfixed_scheduler_DB *)\n  \"parserFS_get_unfixed_scheduler_DB\"\n  (* get_fixed_scheduler_DB *)\n  \"parserFS_get_fixed_scheduler_DB\"\n  apply(simp add: LOCALE_DEFS parser_interpretations)\n  apply(simp add: parserFS_inst_AX_initial_configuration_belongs parserFS_inst_AX_step_relation_preserves_belongs )\n  apply(simp add: parserFS_inst_ATS_axioms parserFS_inst_ATS_String_State_Modification_axioms parserFS_inst_ATS_Language_by_Finite_Derivations_axioms parserFS_inst_ATS_SchedUF_SB_axioms parserFS_inst_ATS_SchedF_SB_axioms parserFS_inst_ATS_Sched_SB_axioms parserFS_inst_ATS_SchedUF_DB_axioms parserFS_inst_ATS_SchedF_DB_axioms parserFS_inst_ATS_Sched_DB0_axioms parserFS_inst_ATS_Sched_axioms )\n  done\n\nlemma parserFS_inst_AX_replace_unfixed_scheduler_DB_sound: \"\n  \\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d n. maximum_of_domain d n \\<longrightarrow> parserFS.derivation_initial G d \\<longrightarrow> parserFS_get_unfixed_scheduler_DB G d n \\<sqsupseteq> [parser_bottom G] \\<longrightarrow> (\\<forall>sUF. sUF \\<in> parser_unfixed_schedulers G \\<longrightarrow> sUF \\<sqsupseteq> [parser_bottom G] \\<longrightarrow> parserFS_get_unfixed_scheduler_DB G (ATS_SchedUF_DB.replace_unfixed_scheduler_DB right_quotient_word (@) parserFS_set_unfixed_scheduler_DB parserFS_get_unfixed_scheduler_DB G d sUF n) n = sUF))\"\n  apply(clarsimp)\n  apply(rename_tac G d n sUF)(*strict*)\n  apply(simp add: parserFS_get_unfixed_scheduler_DB_def)\n  apply(simp add: parserFS.replace_unfixed_scheduler_DB_def)\n  apply(simp add: parserFS.map_unfixed_scheduler_DB_def)\n  apply(subgoal_tac \"\\<exists>e c. d n = Some (pair e c)\")\n   apply(rename_tac G d n sUF)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G d n sUF e c)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(rule_tac\n      t=\"right_quotient_word (parserFS_get_unfixed_scheduler_DB G d n) (parserFS_get_unfixed_scheduler_DB G d n)\"\n      and s=\"Some []\"\n      in ssubst)\n    apply(rename_tac G d n sUF e c)(*strict*)\n    apply(rule right_quotient_word_Some_by_append)\n    apply(force)\n   apply(rename_tac G d n sUF e c)(*strict*)\n   apply(clarsimp)\n   apply(simp add: parserFS_set_unfixed_scheduler_DB_def parserFS_set_unfixed_scheduler_def)\n  apply(rename_tac G d n sUF)(*strict*)\n  apply(rule parserFS.some_position_has_details_before_max_dom)\n    apply(rename_tac G d n sUF)(*strict*)\n    apply(rule parserFS.derivation_initial_is_derivation)\n    apply(force)\n   apply(rename_tac G d n sUF)(*strict*)\n   apply(force)\n  apply(rename_tac G d n sUF)(*strict*)\n  apply(force)\n  done\n\nlemma parserFS_inst_ATS_Sched_DB_axioms: \"\n  ATS_Sched_DB_axioms valid_parser parserFS_initial_configurations\n     parserFS_step_relation parser_unfixed_schedulers right_quotient_word (@)\n     parser_unfixed_scheduler_extendable parserFS_set_unfixed_scheduler_DB\n     parserFS_get_unfixed_scheduler_DB \"\n  apply(simp add: ATS_Sched_DB_axioms_def)\n  apply(rule parserFS_inst_AX_replace_unfixed_scheduler_DB_sound)\n  done\n\nprint_locale loc_autFS_5\ninterpretation \"parserFS\" : loc_autFS_5\n  (* TSstructure *)\n  \"valid_parser\"\n  (* configurations *)\n  \"parserFS_configurations\"\n  (* initial_configurations *)\n  \"parserFS_initial_configurations\"\n  (* step_labels *)\n  \"parser_step_labels\"\n  (* step_relation *)\n  \"parserFS_step_relation\"\n  (* effects *)\n  \"parser_markers\"\n  (* marking_condition *)\n  \"parserFS_marking_condition\"\n  (* marked_effect *)\n  \"parserFS_marked_effect\"\n  (* unmarked_effect *)\n  \"parserFS_unmarked_effect\"\n  (* destinations *)\n  \"parser_destinations\"\n  (* get_destinations *)\n  \"parserFS_get_destinations\"\n  (* decreasing *)\n  \"True\"\n  (* string_state *)\n  \"parserFS_string_state\"\n  (* fixed_schedulers *)\n  \"parser_fixed_schedulers\"\n  (* empty_fixed_scheduler *)\n  \"parser_empty_fixed_scheduler\"\n  (* fixed_scheduler_extendable *)\n  \"parser_fixed_scheduler_extendable\"\n  (* scheduler_fragments *)\n  \"parser_scheduler_fragments\"\n  (* empty_scheduler_fragment *)\n  \"parser_empty_scheduler_fragment\"\n  (* join_scheduler_fragments *)\n  \"append\"\n  (* unfixed_schedulers *)\n  \"parser_unfixed_schedulers\"\n  (* empty_unfixed_scheduler *)\n  \"parser_empty_unfixed_scheduler\"\n  (* unfixed_scheduler_right_quotient_word *)\n  \"right_quotient_word\"\n  (* extend_unfixed_scheduler *)\n  \"append\"\n  (* unfixed_scheduler_extendable *)\n  \"parser_unfixed_scheduler_extendable\"\n  (* schedulers *)\n  \"parser_schedulers\"\n  (* initial_schedulers *)\n  \"parser_schedulers\"\n  (* empty_scheduler *)\n  \"parser_empty_scheduler\"\n  (* get_scheduler *)\n  \"parserFS_get_scheduler\"\n  (* join_fixed_scheduler_unfixed_scheduler *)\n  \"append\"\n  (* extend_scheduler *)\n  \"append\"\n  (* set_unfixed_scheduler *)\n  \"parserFS_set_unfixed_scheduler\"\n  (* get_unfixed_scheduler *)\n  \"parserFS_get_unfixed_scheduler\"\n  (* get_fixed_scheduler *)\n  \"parserFS_conf_fixed\"\n  (* set_unfixed_scheduler_DB *)\n  \"parserFS_set_unfixed_scheduler_DB\"\n  (* get_unfixed_scheduler_DB *)\n  \"parserFS_get_unfixed_scheduler_DB\"\n  (* get_fixed_scheduler_DB *)\n  \"parserFS_get_fixed_scheduler_DB\"\n  apply(simp add: LOCALE_DEFS parser_interpretations)\n  apply(simp add: parserFS_inst_AX_initial_configuration_belongs parserFS_inst_AX_step_relation_preserves_belongs )\n  apply(simp add: parserFS_inst_ATS_axioms parserFS_inst_ATS_String_State_Modification_axioms parserFS_inst_ATS_Language_by_Finite_Derivations_axioms parserFS_inst_ATS_SchedUF_SB_axioms parserFS_inst_ATS_SchedF_SB_axioms parserFS_inst_ATS_Sched_SB_axioms parserFS_inst_ATS_SchedUF_DB_axioms parserFS_inst_ATS_SchedF_DB_axioms parserFS_inst_ATS_Sched_DB0_axioms parserFS_inst_ATS_Sched_DB_axioms parserFS_inst_ATS_Sched_axioms )\n  done\n\nlemma parserFS_inst_AX_state_based_vs_derivation_based_get_fixed_scheduler: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d. parserFS.derivation_initial G d \\<longrightarrow> (\\<forall>n e c. d n = Some (pair e c) \\<longrightarrow> parserFS_get_fixed_scheduler_DB G d n = parserFS_conf_fixed c)))\"\n  apply(clarsimp)\n  apply(rename_tac G d n e c)(*strict*)\n  apply(simp add: parserFS_get_fixed_scheduler_DB_def get_configuration_def parserFS_get_scheduler_def)\n  done\n\nlemma parserFS_inst_ATS_SchedF_SDB_axioms: \"\n  ATS_SchedF_SDB_axioms valid_parser parserFS_initial_configurations parserFS_step_relation parserFS_conf_fixed parserFS_get_fixed_scheduler_DB \"\n  apply(simp add: ATS_SchedF_SDB_axioms_def)\n  apply(rule parserFS_inst_AX_state_based_vs_derivation_based_get_fixed_scheduler)\n  done\n\nlemma parserFS_inst_AX_get_unfixed_scheduler_set_unfixed_scheduler_DB_sound: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d. parserFS.derivation_initial G d \\<longrightarrow> (\\<forall>n. (\\<exists>y. d n = Some y) \\<longrightarrow> parserFS_get_unfixed_scheduler_DB G d n \\<sqsupseteq> [parser_bottom G] \\<longrightarrow> (\\<forall>sUF. sUF \\<in> parser_unfixed_schedulers G \\<longrightarrow> parserFS_get_unfixed_scheduler (parserFS_set_unfixed_scheduler_DB G d n sUF) = sUF))))\"\n  apply(clarsimp)\n  apply(rename_tac G d n y sUF)(*strict*)\n  apply(simp add: parserFS_set_unfixed_scheduler_def parserFS_get_unfixed_scheduler_def parserFS_set_unfixed_scheduler_DB_def get_configuration_def)\n  done\n\nlemma parserFS_inst_AX_set_unfixed_scheduler_set_unfixed_scheduler_DB_sound: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d. parserFS.derivation_initial G d \\<longrightarrow> (\\<forall>n. (\\<exists>y. d n = Some y) \\<longrightarrow> parserFS_get_unfixed_scheduler_DB G d n \\<sqsupseteq> [parser_bottom G] \\<longrightarrow> (\\<forall>sUF. sUF \\<in> parser_unfixed_schedulers G \\<longrightarrow> parserFS_set_unfixed_scheduler (the (get_configuration (d n))) sUF = parserFS_set_unfixed_scheduler_DB G d n sUF))))\"\n  apply(clarsimp)\n  apply(rename_tac G d n y sUF)(*strict*)\n  apply(simp add: parserFS_get_scheduler_def parserFS_set_unfixed_scheduler_def parserFS_get_fixed_scheduler_DB_def parserFS_get_unfixed_scheduler_def parserFS_set_unfixed_scheduler_DB_def get_configuration_def)\n  done\n\nlemma parserFS_inst_AX_state_based_vs_derivation_based_get_unfixed_scheduler: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d. parserFS.derivation_initial G d \\<longrightarrow> (\\<forall>n e c. d n = Some (pair e c) \\<longrightarrow> parserFS_get_unfixed_scheduler_DB G d n = parserFS_get_unfixed_scheduler c)))\"\n  apply(clarsimp)\n  apply(rename_tac G d n e c)(*strict*)\n  apply(simp add: parserFS_get_unfixed_scheduler_def parserFS_get_unfixed_scheduler_DB_def get_configuration_def)\n  done\n\nlemma parserFS_inst_AX_state_based_vs_derivation_based_set_unfixed_scheduler: \"\n  (\\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d. parserFS.derivation_initial G d \\<longrightarrow> (\\<forall>n e c. d n = Some (pair e c) \\<longrightarrow> (\\<forall>sUF. parserFS_set_unfixed_scheduler_DB G d n sUF = parserFS_set_unfixed_scheduler c sUF))))\"\n  apply(clarsimp)\n  apply(rename_tac G d n e c sUF)(*strict*)\n  apply(simp add: parserFS_set_unfixed_scheduler_DB_def get_configuration_def parserFS_set_unfixed_scheduler_def)\n  done\n\nlemma parserFS_inst_ATS_SchedUF_SDB_axioms: \"\n  ATS_SchedUF_SDB_axioms valid_parser parserFS_initial_configurations\n     parserFS_step_relation parser_unfixed_schedulers\n     parser_unfixed_scheduler_extendable parserFS_set_unfixed_scheduler\n     parserFS_get_unfixed_scheduler parserFS_set_unfixed_scheduler_DB\n     parserFS_get_unfixed_scheduler_DB \"\n  apply(simp add: ATS_SchedUF_SDB_axioms_def)\n  apply(simp add: parserFS_inst_AX_get_unfixed_scheduler_set_unfixed_scheduler_DB_sound parserFS_inst_AX_set_unfixed_scheduler_set_unfixed_scheduler_DB_sound parserFS_inst_AX_state_based_vs_derivation_based_get_unfixed_scheduler parserFS_inst_AX_state_based_vs_derivation_based_set_unfixed_scheduler )\n  done\n\nlemma parserFS_inst_AX_unfixed_scheduler_extendable_get_unfixed_scheduler_equal_get_unfixed_scheduler_DB_on_initial_derivations: \"\n  \\<forall>G. valid_parser G \\<longrightarrow> (\\<forall>d. parserFS.derivation_initial G d \\<longrightarrow> (\\<forall>n. (\\<exists>y. d n = Some y) \\<longrightarrow> (parserFS_get_unfixed_scheduler_DB G d n \\<sqsupseteq> [parser_bottom G] = ATS_SchedUF_SB.get_unfixed_scheduler_nth parserFS_get_unfixed_scheduler d n \\<sqsupseteq> [parser_bottom G])))\"\n  apply(clarsimp)\n  apply(rename_tac G d n y)(*strict*)\n  apply(simp add: suffix_def)\n  apply(subgoal_tac \"\\<exists>e c. d n = Some (pair e c)\")\n   apply(rename_tac G d n y)(*strict*)\n   prefer 2\n   apply(case_tac y)\n   apply(rename_tac G d n y option b)(*strict*)\n   apply(force)\n  apply(rename_tac G d n y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G d n e c)(*strict*)\n  apply(simp add: parserFS_get_unfixed_scheduler_DB_def get_configuration_def parserFS.get_unfixed_scheduler_nth_def parserFS_get_unfixed_scheduler_def parserFS_get_scheduler_def)\n  done\n\nlemma parserFS_inst_ATS_Sched_SDB_axioms: \"\n  ATS_Sched_SDB_axioms valid_parser parserFS_initial_configurations\n     parserFS_step_relation parser_unfixed_scheduler_extendable\n     parserFS_get_unfixed_scheduler parserFS_get_unfixed_scheduler_DB \"\n  apply(simp add: ATS_Sched_SDB_axioms_def)\n  apply(simp add: parserFS_inst_AX_unfixed_scheduler_extendable_get_unfixed_scheduler_equal_get_unfixed_scheduler_DB_on_initial_derivations)\n  done\n\ninterpretation \"parserFS\" : loc_autFS_6\n  (* TSstructure *)\n  \"valid_parser\"\n  (* configurations *)\n  \"parserFS_configurations\"\n  (* initial_configurations *)\n  \"parserFS_initial_configurations\"\n  (* step_labels *)\n  \"parser_step_labels\"\n  (* step_relation *)\n  \"parserFS_step_relation\"\n  (* effects *)\n  \"parser_markers\"\n  (* marking_condition *)\n  \"parserFS_marking_condition\"\n  (* marked_effect *)\n  \"parserFS_marked_effect\"\n  (* unmarked_effect *)\n  \"parserFS_unmarked_effect\"\n  (* destinations *)\n  \"parser_destinations\"\n  (* get_destinations *)\n  \"parserFS_get_destinations\"\n  (* decreasing *)\n  \"True\"\n  (* string_state *)\n  \"parserFS_string_state\"\n  (* fixed_schedulers *)\n  \"parser_fixed_schedulers\"\n  (* empty_fixed_scheduler *)\n  \"parser_empty_fixed_scheduler\"\n  (* fixed_scheduler_extendable *)\n  \"parser_fixed_scheduler_extendable\"\n  (* scheduler_fragments *)\n  \"parser_scheduler_fragments\"\n  (* empty_scheduler_fragment *)\n  \"parser_empty_scheduler_fragment\"\n  (* join_scheduler_fragments *)\n  \"append\"\n  (* unfixed_schedulers *)\n  \"parser_unfixed_schedulers\"\n  (* empty_unfixed_scheduler *)\n  \"parser_empty_unfixed_scheduler\"\n  (* unfixed_scheduler_right_quotient_word *)\n  \"right_quotient_word\"\n  (* extend_unfixed_scheduler *)\n  \"append\"\n  (* unfixed_scheduler_extendable *)\n  \"parser_unfixed_scheduler_extendable\"\n  (* schedulers *)\n  \"parser_schedulers\"\n  (* initial_schedulers *)\n  \"parser_schedulers\"\n  (* empty_scheduler *)\n  \"parser_empty_scheduler\"\n  (* get_scheduler *)\n  \"parserFS_get_scheduler\"\n  (* join_fixed_scheduler_unfixed_scheduler *)\n  \"append\"\n  (* extend_scheduler *)\n  \"append\"\n  (* set_unfixed_scheduler *)\n  \"parserFS_set_unfixed_scheduler\"\n  (* get_unfixed_scheduler *)\n  \"parserFS_get_unfixed_scheduler\"\n  (* get_fixed_scheduler *)\n  \"parserFS_conf_fixed\"\n  (* set_unfixed_scheduler_DB *)\n  \"parserFS_set_unfixed_scheduler_DB\"\n  (* get_unfixed_scheduler_DB *)\n  \"parserFS_get_unfixed_scheduler_DB\"\n  (* get_fixed_scheduler_DB *)\n  \"parserFS_get_fixed_scheduler_DB\"\n  apply(simp add: LOCALE_DEFS parser_interpretations)\n  apply(simp add: parserFS_inst_AX_initial_configuration_belongs parserFS_inst_AX_step_relation_preserves_belongs )\n  apply(simp add: parserFS_inst_ATS_axioms parserFS_inst_ATS_String_State_Modification_axioms parserFS_inst_ATS_Language_by_Finite_Derivations_axioms parserFS_inst_ATS_SchedUF_SB_axioms parserFS_inst_ATS_SchedF_SB_axioms parserFS_inst_ATS_Sched_SB_axioms parserFS_inst_ATS_SchedUF_DB_axioms parserFS_inst_ATS_SchedF_DB_axioms parserFS_inst_ATS_Sched_DB0_axioms parserFS_inst_ATS_Sched_DB_axioms parserFS_inst_ATS_SchedF_SDB_axioms parserFS_inst_ATS_SchedUF_SDB_axioms parserFS_inst_ATS_Sched_SDB_axioms parserFS_inst_ATS_Sched_axioms parserFS_inst_AX_get_scheduler_closed )\n  done\n\ntheorem parserFS_dependency_between_determinism_properties_main: \"\n  valid_parser G\n  \\<Longrightarrow> parserFS.is_forward_target_deterministic_accessible G\"\n  apply(simp add: parserFS.is_forward_target_deterministic_accessible_def parserFS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac c c1 c2 e x v)(*strict*)\n  apply(case_tac c)\n  apply(rename_tac c c1 c2 e x v parserFS_conf_fixeda parserFS_conf_stacka parserFS_conf_schedulera)(*strict*)\n  apply(case_tac c1)\n  apply(rename_tac c c1 c2 e x v parserFS_conf_fixeda parserFS_conf_stacka parserFS_conf_schedulera parserFS_conf_fixedaa parserFS_conf_stackaa parserFS_conf_scheduleraa)(*strict*)\n  apply(case_tac c2)\n  apply(rename_tac c c1 c2 e x v parserFS_conf_fixeda parserFS_conf_stacka parserFS_conf_schedulera parserFS_conf_fixedaa parserFS_conf_stackaa parserFS_conf_scheduleraa parserFS_conf_fixedb parserFS_conf_stackb parserFS_conf_schedulerb)(*strict*)\n  apply(case_tac e)\n  apply(rename_tac c c1 c2 e x v parserFS_conf_fixeda parserFS_conf_stacka parserFS_conf_schedulera parserFS_conf_fixedaa parserFS_conf_stackaa parserFS_conf_scheduleraa parserFS_conf_fixedb parserFS_conf_stackb parserFS_conf_schedulerb rule_lpopa rule_rpopa rule_lpusha rule_rpusha)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x v parserFS_conf_fixed parserFS_conf_scheduler parserFS_conf_fixeda parserFS_conf_schedulera parserFS_conf_fixedb parserFS_conf_schedulerb rule_lpop rule_lpush rule_rpush)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac x v parserFS_conf_fixed parserFS_conf_scheduler parserFS_conf_fixeda parserFS_conf_schedulera parserFS_conf_fixedb parserFS_conf_schedulerb rule_lpop rule_lpush rule_rpush)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac x v parserFS_conf_fixed parserFS_conf_scheduler parserFS_conf_fixeda parserFS_conf_schedulera parserFS_conf_fixedb parserFS_conf_schedulerb rule_lpop rule_lpush rule_rpush)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac x v parserFS_conf_fixed parserFS_conf_schedulera parserFS_conf_schedulerb rule_lpop rule_lpush rule_rpush popnew popnewa)(*strict*)\n    apply(subgoal_tac \"popnew=popnewa\")\n     apply(rename_tac x v parserFS_conf_fixed parserFS_conf_schedulera parserFS_conf_schedulerb rule_lpop rule_lpush rule_rpush popnew popnewa)(*strict*)\n     prefer 2\n     apply (metis same_append_eq)\n    apply(rename_tac x v parserFS_conf_fixed parserFS_conf_schedulera parserFS_conf_schedulerb rule_lpop rule_lpush rule_rpush popnew popnewa)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac x v parserFS_conf_fixed parserFS_conf_scheduler parserFS_conf_fixeda parserFS_conf_schedulera parserFS_conf_fixedb parserFS_conf_schedulerb rule_lpop rule_lpush rule_rpush)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x v parserFS_conf_fixed parserFS_conf_scheduler parserFS_conf_fixeda parserFS_conf_schedulera parserFS_conf_fixedb parserFS_conf_schedulerb rule_lpop rule_lpush rule_rpush)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac x v parserFS_conf_fixed parserFS_conf_scheduler parserFS_conf_fixeda parserFS_conf_schedulera parserFS_conf_fixedb parserFS_conf_schedulerb rule_lpop rule_lpush rule_rpush)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x v parserFS_conf_fixed parserFS_conf_scheduler parserFS_conf_fixeda parserFS_conf_schedulera parserFS_conf_fixedb parserFS_conf_schedulerb rule_lpop rule_lpush rule_rpush)(*strict*)\n  apply(clarsimp)\n  done\n\nlemmas parserFS_interpretations =\n  parser_interpretations\n  parserFS_inst_AX_initial_configuration_belongs\n  parserFS_inst_AX_step_relation_preserves_belongs\n  parserFS_inst_ATS_axioms\n  parserFS_inst_ATS_String_State_Modification_axioms\n  parserFS_inst_ATS_Language_by_Finite_Derivations_axioms\n  parserFS_inst_ATS_SchedUF_SB_axioms\n  parserFS_inst_ATS_SchedF_SB_axioms\n  parserFS_inst_ATS_Sched_SB_axioms\n  parserFS_inst_ATS_SchedUF_DB_axioms\n  parserFS_inst_ATS_SchedF_DB_axioms\n  parserFS_inst_ATS_Sched_DB0_axioms\n  parserFS_inst_ATS_Sched_DB_axioms\n  parserFS_inst_ATS_SchedF_SDB_axioms\n  parserFS_inst_ATS_SchedUF_SDB_axioms\n  parserFS_inst_ATS_Sched_SDB_axioms\n  parserFS_inst_ATS_Sched_axioms\n  parserFS_inst_AX_get_scheduler_closed\n\nend\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_08/I_kparser_FS.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5273165382362518, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.26571805743928106}}
{"text": "section Parser\ntheory IpRoute_Parser\nimports Routing_Table \n  \"../IP_Addresses/IP_Address_Parser\"\nkeywords \"parse_ip_route\" \"parse_ip_6_route\" :: thy_decl\nbegin\ntext\\<open>This helps to read the output of the \\texttt{ip route} command into a @{typ \"32 routing_rule list\"}.\\<close>\n\ndefinition empty_rr_hlp :: \"('a::len) prefix_match \\<Rightarrow> 'a routing_rule\" where\n  \"empty_rr_hlp pm = routing_rule.make pm default_metric (routing_action.make '''' None)\"\n\nlemma empty_rr_hlp_alt:\n  \"empty_rr_hlp pm = \\<lparr> routing_match = pm, metric = 0, routing_action = \\<lparr>output_iface = [], next_hop = None\\<rparr>\\<rparr>\"\n  unfolding empty_rr_hlp_def routing_rule.defs default_metric_def routing_action.defs ..\n\ndefinition routing_action_next_hop_update :: \"'a word \\<Rightarrow> 'a routing_rule \\<Rightarrow> ('a::len) routing_rule\"\n  where\n  \"routing_action_next_hop_update h pk = pk\\<lparr> routing_action := (routing_action pk)\\<lparr> next_hop := Some h\\<rparr> \\<rparr>\"\nlemma \"routing_action_next_hop_update h pk = routing_action_update (next_hop_update (\\<lambda>_. (Some h))) (pk::32 routing_rule)\"\n  by(simp add: routing_action_next_hop_update_def)\n\ndefinition routing_action_oiface_update :: \"string \\<Rightarrow> 'a routing_rule \\<Rightarrow> ('a::len) routing_rule\"\n  where\n  \"routing_action_oiface_update h pk = routing_action_update (output_iface_update (\\<lambda>_. h)) (pk::'a routing_rule)\"\nlemma \"routing_action_oiface_update h pk = pk\\<lparr> routing_action := (routing_action pk)\\<lparr> output_iface :=  h\\<rparr> \\<rparr>\"\n  by(simp add: routing_action_oiface_update_def)\n\n(* Could be moved to Bitmagic *)\ndefinition \"default_prefix = PrefixMatch 0 0\"\nlemma default_prefix_matchall: \"prefix_match_semantics default_prefix ip\"\n  unfolding default_prefix_def by (simp add: valid_prefix_00 zero_prefix_match_all)\n\ndefinition \"sanity_ip_route (r::('a::len) prefix_routing) \\<equiv> correct_routing r \\<and> unambiguous_routing r \\<and> list_all (op \\<noteq> '''' \\<circ> routing_oiface) r\"\ntext\\<open>The parser ensures that @{const sanity_ip_route} holds for any ruleset that is imported.\\<close>\n\n(* Hide all the ugly ml in a file with the right extension *)\n(*Depends on the function parser_ipv4 from IP_Address_Parser*)\nML_file \"IpRoute_Parser.ml\"\n                  \nML\\<open>\n  Outer_Syntax.local_theory @{command_keyword parse_ip_route}\n  \"Load a file generated by ip route and make the routing table definition available as isabelle term\"\n  (Parse.binding --| @{keyword \"=\"} -- Parse.string >> register_ip_route 32)\n\\<close>\n\nML\\<open>\n  Outer_Syntax.local_theory @{command_keyword parse_ip_6_route}\n  \"Load a file generated by ip -6 route and make the routing table definition available as isabelle term\"\n  (Parse.binding --| @{keyword \"=\"} -- Parse.string >> register_ip_route 128)\n\\<close>\n\nparse_ip_route \"rtbl_parser_test1\" = \"ip-route-ex\"\nlemma  \"sanity_ip_route rtbl_parser_test1\" by eval (* checked by parse_ip_route alread *)\n\nlemma \"rtbl_parser_test1 =\n  [\\<lparr>routing_match = PrefixMatch 0xFFFFFF00 32, metric = 0, routing_action = \\<lparr>output_iface = ''tun0'', next_hop = None\\<rparr>\\<rparr>,\n  \\<lparr>routing_match = PrefixMatch 0xA0D2AA0 28, metric = 303, routing_action = \\<lparr>output_iface = ''ewlan'', next_hop = None\\<rparr>\\<rparr>,\n  \\<lparr>routing_match = PrefixMatch 0xA0D2500 24, metric = 0, routing_action = \\<lparr>output_iface = ''tun0'', next_hop = Some 0xFFFFFF00\\<rparr>\\<rparr>,\n  \\<lparr>routing_match = PrefixMatch 0xA0D2C00 24, metric = 0, routing_action = \\<lparr>output_iface = ''tun0'', next_hop = Some 0xFFFFFF00\\<rparr>\\<rparr>,\n  \\<lparr>routing_match = PrefixMatch 0 0, metric = 303, routing_action = \\<lparr>output_iface = ''ewlan'', next_hop = Some 0xA0D2AA1\\<rparr>\\<rparr>]\"\nby eval\n\nparse_ip_6_route \"rtbl_parser_test2\" = \"ip-6-route-ex\"\nvalue[code] rtbl_parser_test2\nlemma  \"sanity_ip_route rtbl_parser_test2\" by eval\n\nend\n", "meta": {"author": "diekmann", "repo": "Iptables_Semantics", "sha": "e0a2516bd885708fce875023b474ae341cbdee29", "save_path": "github-repos/isabelle/diekmann-Iptables_Semantics", "path": "github-repos/isabelle/diekmann-Iptables_Semantics/Iptables_Semantics-e0a2516bd885708fce875023b474ae341cbdee29/thy/Routing/IpRoute_Parser.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5273165382362518, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.26571805743928106}}
{"text": "theory ReynoldsList\n  imports Refinement\nbegin\n\nno_notation pmult (infixl \"*\" 80)\n  and times (infixl \"*\" 70)\n  and Set.image (infixr \"`\" 90)\n  and sup (infixl \"+\" 65)\n  and pmult_one (\"1\")\n  and bot (\"\\<bottom>\")\n  and sep_impl (infix \"-*\" 55)\n\nno_notation Set.image (infixr \"`\" 90)\n  and times (infixl \"*\" 70)\n\n(* List *)\nprimrec list' :: \"nat \\<Rightarrow> nat list \\<Rightarrow> 'a pred\" where\n  \"list' i [] = \\<lbrace>i = 0\\<rbrace> \\<sqinter> emp\"\n| \"list' i (y#ys) = \\<lbrace>i \\<noteq> 0\\<rbrace> \\<sqinter> (EXS j. \\<lbrace>i [\\<mapsto>] [y,j]\\<rbrace> * list' j ys)\"\n\nsyntax\n  \"_list\" :: \"nat \\<Rightarrow> nat list \\<Rightarrow> bool\" (\"list _ _\")\n\ntranslations\n  \"list x xs\" == \"|(`(CONST curry (CONST list' x xs)))|\"\n\nlemma list_cong: \"list' x xs (a, h) \\<Longrightarrow> x' = x \\<Longrightarrow> xs' = xs \\<Longrightarrow> h' = h \\<Longrightarrow> list' x' xs' (a, h')\"\n  by force\n\nlemma list_cong_ex: \"list' x xs (a, h) \\<Longrightarrow> x' = x \\<Longrightarrow> h' = h \\<Longrightarrow> \\<exists>xs. list' x' xs (a, h')\"\n  by force\n\nlemma empty_list: \"list' i a (s, h) \\<Longrightarrow> i = 0 \\<Longrightarrow> a = []\"\n  by (metis (mono_tags, lifting) PairE inf1E list'.simps(2) list.exhaust old.prod.case)\n\nlemma list_i_null: \"list' 0 a (s, h) \\<Longrightarrow> a = [] \\<and> h = Map.empty\"\n  by (induct a, simp_all add: emp_def)\n\nlemma list_i_not_null: \"list' i a (s, h) \\<Longrightarrow> i \\<noteq> 0 \\<Longrightarrow> a \\<noteq> []\"\n  by (induct a, simp_all add: emp_def)\n\nlemma list_i_not_null_var: \"list' i x (s, h) \\<Longrightarrow> i \\<noteq> 0 \\<Longrightarrow> (\\<exists>y ys. x = y#ys)\"\n  apply (auto dest!: list_i_not_null)\n  by (metis list.exhaust)\n\nlemma sep_conj_s_preserving: \n  assumes \"(\\<And>h. P (s, h) \\<Longrightarrow> P (s', h))\" and  \"(\\<And>h. Q (s, h) \\<Longrightarrow> Q (s', h))\" \n  shows \"((P * Q) (s, h) \\<Longrightarrow> (P * Q) (s', h))\"\n  using assms by (auto simp add: sep_conj_def ortho_def split: option.splits) \n\nlemma list_s_preserving: \"list' n as (s :: 'a, h) \\<Longrightarrow> list' n as (s' :: 'a, h)\"\n  apply (induct as arbitrary: n h)\n  by (auto simp add: emp_def intro: sep_conj_s_preserving [of _ s])\n\nrecord list_state =\n  i :: nat\n  j :: nat\n  k :: nat\n\n\n\nlemma [simp]: \"list' n as (j_update m s, h) = list' n as (s, h)\"\n  by (auto intro: list_s_preserving)\n\nlemma [simp]: \"list' n as (k_update m s, h) = list' n as (s, h)\"\n  by (auto intro: list_s_preserving)\n\nlemma heap_div: \"h1 \\<bottom> h2 \\<Longrightarrow> h1 a = Some b \\<Longrightarrow> (h1 ++ h2) a = Some b\"\n  apply (auto simp: ortho_def)\n  by (auto simp: map_add_def split: option.splits)\n\nlemma heap_div_var: \"h1 \\<bottom> h2 \\<Longrightarrow> h2 a = Some b \\<Longrightarrow> (h1 ++ h2) a = Some b\"\n  by (auto simp: ortho_def)\n\nlemma heap_ortho_div2: \"[x \\<mapsto> y, z \\<mapsto> w] \\<bottom> h \\<Longrightarrow> [x \\<mapsto> y] \\<bottom> [z \\<mapsto> w] \\<Longrightarrow>([x \\<mapsto> y, z \\<mapsto> w] ++ h)(x := None, z := None) = h\"\napply (simp add: fun_upd_def ortho_def map_add_def)\napply (rule ext)\napply (case_tac \"xa = z\")\napply auto\napply force\napply force\nby (metis option.exhaust option.simps(4) option.simps(5))\n \nlemma heap_div_the: \"h1 \\<bottom> h2 \\<Longrightarrow> h1 a = Some b \\<Longrightarrow> the ((h1 ++ h2) a) = b\"\n  apply (auto simp: ortho_def)\n  by (auto simp: map_add_def split: option.splits)\n  \n\n\nlemma [iff]: \"x \\<sqinter> emp = (\\<lambda>(s, h). x (s, h) \\<and> emp (s, h))\"\n  by auto\n\nlemma \"q s \\<Longrightarrow> (p \\<sqinter> q) s = p s \\<and> q s\"\n  by auto\n\nlemma pred_infI: \"p s \\<and> q s \\<Longrightarrow> (p \\<sqinter> q) s\"\n  by auto\n\nlemma pred_infD: \"(p \\<sqinter> q) s \\<Longrightarrow> p s \\<and> q s\"\n  by auto\n\nlemma listI: \"p \\<noteq> 0 \\<Longrightarrow>  h1 \\<bottom> h2 \\<Longrightarrow> is_heap_list p [q, r] (s, h1) \\<Longrightarrow> list' r ns (s, h2) \\<Longrightarrow> list' p (q#ns) (s, h1 ++ h2)\"\n  by (force simp: sep_conj_eq)\n\ndeclare sep_conj_eq [simp] emp_def[simp]\nnotation \n  pred_ex (binder \"\\<exists> \" 10)\n  and inf (infixl \"\\<and>\" 75)\n\nlemma \"\\<lbrakk>\\<lbrace>list `i Ao\\<rbrace> , \\<lbrace> list `j (rev Ao)\\<rbrace>\\<rbrakk> \\<sqsubseteq>\n    `j := 0;\n    while `i \\<noteq> 0\n    do\n      `k := @(`i + 1);\n      @(`i + 1) := `j;\n      `j := `i;\n      `i := `k\n    od\" \nproof -\n  have \"\\<lbrakk> \\<lbrace>list `i Ao\\<rbrace>, \\<lbrace>list `j (rev Ao)\\<rbrace> \\<rbrakk> \\<sqsubseteq> \n      `j := 0; \n      \\<lbrakk>\\<exists>A B. (\\<lbrace> list `i A \\<rbrace> * \\<lbrace> list `j B \\<rbrace>) \\<and> \\<lbrace>(rev Ao) = (rev A) @ B \\<rbrace>, \n        \\<lbrace> list `j (rev Ao) \\<rbrace> \\<rbrakk>\" \n      (is \"... \\<sqsubseteq> ?p\")\n    by refinement force\n  also have \"?p \\<sqsubseteq> \n        `j := 0;\n        while `i \\<noteq> 0 do\n          \\<lbrakk>(\\<exists>A B. (\\<lbrace> list `i A \\<rbrace> * \\<lbrace> list `j B \\<rbrace>) \\<and> \\<lbrace>(rev Ao) = (rev A) @ B \\<rbrace>) \\<and> \\<lbrace>`i \\<noteq> 0\\<rbrace>, \n            \\<exists>A B. (\\<lbrace> list `i A \\<rbrace> * \\<lbrace> list `j B \\<rbrace>) \\<and> \\<lbrace>(rev Ao) = (rev A) @ B \\<rbrace>\\<rbrakk>\n        od\" (is \"... \\<sqsubseteq> ?p\")\n    by refinement (auto dest!: list_i_null)\n  also have \"?p \\<sqsubseteq> \n        `j := 0;\n        while `i \\<noteq> 0 do\n          \\<lbrakk>(\\<exists>a A B k. (\\<lbrace>`i [\\<mapsto>] [a,k]\\<rbrace> * \\<lbrace> list k A \\<rbrace> * \\<lbrace> list `j B \\<rbrace>) \\<and> \\<lbrace>(rev Ao) = (rev (a#A)) @ B \\<rbrace>) \\<and> \\<lbrace>`i \\<noteq> 0\\<rbrace>, \n            \\<exists>A B. (\\<lbrace> list `i A \\<rbrace> * \\<lbrace> list `j B \\<rbrace>) \\<and> \\<lbrace>(rev Ao) = (rev A) @ B \\<rbrace>\\<rbrakk>\n        od\" (is \"... \\<sqsubseteq> ?p\")\n    by refinement (frule list_i_not_null_var, fastforce+)\n  also have \"?p \\<sqsubseteq> \n        `j := 0;\n        while `i \\<noteq> 0 do\n          `k := @(`i + 1);\n          \\<lbrakk>(\\<exists> a A B. (\\<lbrace>`i [\\<mapsto>] [a,`k]\\<rbrace> * \\<lbrace> list `k A \\<rbrace> * \\<lbrace> list `j B \\<rbrace>) \\<and> \\<lbrace>(rev Ao) = (rev (a#A)) @ B \\<rbrace>) \\<and> \\<lbrace>`i \\<noteq> 0\\<rbrace>, \n            \\<exists> A B. (\\<lbrace> list `i A \\<rbrace> * \\<lbrace> list `j B \\<rbrace>) \\<and> \\<lbrace>(rev Ao) = (rev A) @ B \\<rbrace>\\<rbrakk>\n        od\" (is \"... \\<sqsubseteq> ?p\")\n    apply refinement  \n    apply (rule_tac x=x in exI, rule_tac x=xa in exI, rule_tac x=xb in exI)\n    apply (subgoal_tac \"the ((h1a ++ h2a ++ h2) (Suc (i a))) = xc\")\n    by (auto simp add: is_singleton_def intro!: heap_div_the heap_divider)\n  also have \"?p \\<sqsubseteq> \n        `j := 0;\n        while `i \\<noteq> 0 do\n          `k := @(`i + 1);\n          @(`i + 1) := `j;\n          \\<lbrakk>(\\<exists> a A B. (\\<lbrace>`i [\\<mapsto>] [a,`j]\\<rbrace> * \\<lbrace> list `k A \\<rbrace> * \\<lbrace> list `j B \\<rbrace>) \\<and> \\<lbrace>(rev Ao) = (rev (a#A)) @ B \\<rbrace>) \\<and> \\<lbrace>`i \\<noteq> 0\\<rbrace>, \n            \\<exists> A B. (\\<lbrace> list `i A \\<rbrace> * \\<lbrace> list `j B \\<rbrace>) \\<and> \\<lbrace>(rev Ao) = (rev A) @ B \\<rbrace>\\<rbrakk>\n        od\" (is \"... \\<sqsubseteq> ?p\")\n        by refinement (force simp: spec_def ht_def mono_def)\n  also have \"?p \\<sqsubseteq> \n        `j := 0;\n        while `i \\<noteq> 0 do\n          `k := @(`i + 1);\n          @(`i + 1) := `j;\n          \\<lbrakk>(\\<exists>a A B. (\\<lbrace> list `k A \\<rbrace> * \\<lbrace>`i [\\<mapsto>] [a,`j]\\<rbrace> * \\<lbrace> list `j B \\<rbrace>) \\<and> \\<lbrace>(rev Ao) = (rev (a#A)) @ B \\<rbrace>) \\<and> \\<lbrace>`i \\<noteq> 0\\<rbrace>, \n            \\<exists>A B. (\\<lbrace> list `i A \\<rbrace> * \\<lbrace> list `j B \\<rbrace>) \\<and> \\<lbrace>(rev Ao) = (rev A) @ B \\<rbrace>\\<rbrakk>\n        od\" (is \"... \\<sqsubseteq> ?p\")\n    by refinement (subst mult_commute, force)\n  also have \"?p \\<sqsubseteq> \n        `j := 0;\n        while `i \\<noteq> 0 do\n          `k := @(`i + 1);\n          @(`i + 1) := `j;\n          \\<lbrakk>(\\<exists>a A B. (\\<lbrace> list `k A \\<rbrace> * \\<lbrace> list `i (a#B) \\<rbrace>) \\<and> \\<lbrace>(rev Ao) = (rev A) @ (a#B) \\<rbrace>) \\<and> \\<lbrace>`i \\<noteq> 0\\<rbrace>, \n            \\<exists>A B. (\\<lbrace> list `i A \\<rbrace> * \\<lbrace> list `j B \\<rbrace>) \\<and> \\<lbrace>(rev Ao) = (rev A) @ B \\<rbrace>\\<rbrakk>\n        od\" (is \"... \\<sqsubseteq> ?p\")\n    apply refinement\n    apply (rule_tac x=x in exI, rule_tac x=xa in exI, rule_tac x=xb in exI)\n    apply (auto simp only: sep_conj_eq)\n    apply (rule_tac x=h1a in exI, rule_tac x=\"h2a ++ h2\" in exI)\n    apply (auto simp del: list'.simps is_heap_list.simps intro!: listI)\n    apply (force simp add: is_singleton_def ortho_def)\n    by (force simp add: is_singleton_def ortho_def intro: listI)\n  also have \"?p \\<sqsubseteq> \n        `j := 0;\n        while `i \\<noteq> 0 do\n          `k := @(`i + 1);\n          @(`i + 1) := `j;\n          \\<lbrakk>(\\<exists>A B. (\\<lbrace> list `k A \\<rbrace> * \\<lbrace> list `i B \\<rbrace>) \\<and> \\<lbrace>(rev Ao) = (rev A) @ B \\<rbrace>) \\<and> \\<lbrace>`i \\<noteq> 0\\<rbrace>, \n            \\<exists>A B. (\\<lbrace> list `i A \\<rbrace> * \\<lbrace> list `j B \\<rbrace>) \\<and> \\<lbrace>(rev Ao) = (rev A) @ B \\<rbrace>\\<rbrakk>\n        od\" (is \"... \\<sqsubseteq> ?p\")\n    by refinement (force simp only: sep_conj_eq)\n  also have nine: \"?p \\<sqsubseteq> \n        `j := 0;\n        while `i \\<noteq> 0 do\n          `k := @(`i + 1);\n          @(`i + 1) := `j;\n          `j := `i;\n          \\<lbrakk>(\\<exists>A B. (\\<lbrace> list `k A \\<rbrace> * \\<lbrace> list `j B \\<rbrace>) \\<and> \\<lbrace>(rev Ao) = (rev A) @ B \\<rbrace>) \\<and> \\<lbrace>`i \\<noteq> 0\\<rbrace>, \n            \\<exists>A B. (\\<lbrace> list `i A \\<rbrace> * \\<lbrace> list `j B \\<rbrace>) \\<and> \\<lbrace>(rev Ao) = (rev A) @ B \\<rbrace>\\<rbrakk>\n        od\" (is \"... \\<sqsubseteq> ?p\")\n    by refinement auto\n  also have ten: \"?p \\<sqsubseteq> \n        `j := 0;\n        while `i \\<noteq> 0 do\n          `k := @(`i + 1);\n          @(`i + 1) := `j;\n          `j := `i;\n          `i := `k\n        od\"\n        by refinement auto\n  finally show ?thesis .\nqed\n\n\nlemma \"\\<turnstile> \\<lbrace>list `i Ao\\<rbrace>\n      `j := 0;\n      while `i \\<noteq> 0\n      inv \\<exists>A B. (\\<lbrace> list `i A \\<rbrace> * \\<lbrace> list `j B \\<rbrace>) \\<and> \\<lbrace>(rev Ao) = (rev A) @ B \\<rbrace>\n      do\n        `k := @(`i + 1);\n        @(`i + 1) := `j;\n        `j := `i;\n        `i := `k\n      od\n   \\<lbrace> list `j (rev Ao)\\<rbrace>\" \napply hoare\napply force\napply (clarsimp dest!: list_i_null)\napply clarsimp\napply (frule list_i_not_null_var, simp)\napply (clarsimp simp add: is_singleton_def)\napply (rule_tac x=ys in exI, rule_tac x=\"y # xa\" in exI)\napply (subgoal_tac \"the (([i a \\<mapsto> y, Suc (i a) \\<mapsto> x] ++ h2a ++ h2) (Suc (i a))) = x\")\napply auto\nprefer 2\napply (force intro!: heap_div_the heap_divider)\napply (rule_tac x=h2a in exI, rule_tac x=\"[i a \\<mapsto> y, Suc (i a) \\<mapsto> j a] ++ h2\" in exI)\napply (auto simp add: is_singleton_def ortho_def intro!: listI)\nby (metis domIff empty_map_add fun_upd_upd map_add_upd_left)\n\nhide_const i j k\n\nrecord list_dealloc_state =\n  x :: nat\n  y :: nat\n\nlemma [simp]: \"list' n as (x_update m s, h) = list' n as (s, h)\"\n  by (auto intro: list_s_preserving)\n\nlemma [simp]: \"list' n as (y_update m s, h) = list' n as (s, h)\"\n  by (auto intro: list_s_preserving)\n\nlemma list_dealloc: \" \\<turnstile> \\<lbrace> list `x xs \\<rbrace>\n  while `x \\<noteq> 0\n  inv \\<lbrace> \\<exists>xs. list `x xs \\<rbrace>\n  do\n    `y := `x;\n    `x := @(`x + 1);\n    dispose `y;\n    dispose (`y + 1)\n  od\n  ( emp )\"\napply hoare\napply (auto simp: mono_def dispose_comm_def list_i_null, frule list_i_not_null_var)\nby (auto simp: is_singleton_def, auto intro!: list_cong_ex heap_div_the heap_ortho_div2)\n\nhide_const x y\n\nlemma \"\\<turnstile> ( \\<lbrace> x [\\<mapsto>] [b, j] \\<rbrace> * \\<lbrace> list i as \\<rbrace> ) @x := a ( \\<lbrace> x [\\<mapsto>] [a, j] \\<rbrace> * \\<lbrace> list i as \\<rbrace> )\"\n  by (simp only: is_heap_list.simps(2) curry_conv split_eta) hoare\n\n\nend\n", "meta": {"author": "victorgomes", "repo": "sep-logic", "sha": "32d8cf0c96ab651bb419ff8a0081ac70f34e188a", "save_path": "github-repos/isabelle/victorgomes-sep-logic", "path": "github-repos/isabelle/victorgomes-sep-logic/sep-logic-32d8cf0c96ab651bb419ff8a0081ac70f34e188a/Tool/ReynoldsList.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.26571804995290604}}
{"text": "section \\<open>Transition Systems\\<close>\n\ntheory Transition_System_Extensions\nimports\n  \"Basics/Word_Prefixes\"\n  \"Extensions/Set_Extensions\"\n  \"Extensions/Relation_Extensions\"\n  Transition_Systems_and_Automata.Transition_System\n  Transition_Systems_and_Automata.Transition_System_Extra\n  Transition_Systems_and_Automata.Transition_System_Construction\nbegin\n\n  context transition_system_initial\n  begin\n\n    definition cycles :: \"'state \\<Rightarrow> 'transition list set\"\n      where \"cycles p \\<equiv> {w. path w p \\<and> target w p = p}\"\n\n    lemma cyclesI[intro!]:\n      assumes \"path w p\" \"target w p = p\"\n      shows \"w \\<in> cycles p\"\n      using assms unfolding cycles_def by auto\n    lemma cyclesE[elim!]:\n      assumes \"w \\<in> cycles p\"\n      obtains \"path w p\" \"target w p = p\"\n      using assms unfolding cycles_def by auto\n\n    inductive_set executable :: \"'transition set\"\n      where executable: \"p \\<in> nodes \\<Longrightarrow> enabled a p \\<Longrightarrow> a \\<in> executable\"\n\n    lemma executableI_step[intro!]:\n      assumes \"p \\<in> nodes\" \"enabled a p\"\n      shows \"a \\<in> executable\"\n      using executable assms by this\n    lemma executableI_words_fin[intro!]:\n      assumes \"p \\<in> nodes\" \"path w p\"\n      shows \"set w \\<subseteq> executable\"\n      using assms by (induct w arbitrary: p, auto del: subsetI)\n    lemma executableE[elim?]:\n      assumes \"a \\<in> executable\"\n      obtains p\n      where \"p \\<in> nodes\" \"enabled a p\"\n      using assms by induct auto\n\n  end\n\n  locale transition_system_interpreted =\n    transition_system ex en\n    for ex :: \"'action \\<Rightarrow> 'state \\<Rightarrow> 'state\"\n    and en :: \"'action \\<Rightarrow> 'state \\<Rightarrow> bool\"\n    and int :: \"'state \\<Rightarrow> 'interpretation\"\n  begin\n\n    definition visible :: \"'action set\"\n      where \"visible \\<equiv> {a. \\<exists> q. en a q \\<and> int q \\<noteq> int (ex a q)}\"\n\n    lemma visibleI[intro]:\n      assumes \"en a q\" \"int q \\<noteq> int (ex a q)\"\n      shows \"a \\<in> visible\"\n      using assms unfolding visible_def by auto\n    lemma visibleE[elim]:\n      assumes \"a \\<in> visible\"\n      obtains q\n      where \"en a q\" \"int q \\<noteq> int (ex a q)\"\n      using assms unfolding visible_def by auto\n\n    abbreviation \"invisible \\<equiv> - visible\"\n\n    lemma execute_fin_word_invisible:\n      assumes \"path w p\" \"set w \\<subseteq> invisible\"\n      shows \"int (target w p) = int p\"\n      using assms by (induct w arbitrary: p rule: list.induct, auto)\n    lemma execute_inf_word_invisible:\n      assumes \"run w p\" \"k \\<le> l\" \"\\<And> i. k \\<le> i \\<Longrightarrow> i < l \\<Longrightarrow> w !! i \\<notin> visible\"\n      shows \"int ((p ## trace w p) !! k) = int ((p ## trace w p) !! l)\"\n    proof -\n      have \"(p ## trace w p) !! l = target (stake l w) p\" by simp\n      also have \"stake l w = stake k w @ stake (l - k) (sdrop k w)\" using assms(2) by simp\n      also have \"target \\<dots> p = target (stake (l - k) (sdrop k w)) (target (stake k w) p)\"\n        unfolding fold_append comp_apply by rule\n      also have \"int \\<dots> = int (target (stake k w) p)\"\n      proof (rule execute_fin_word_invisible)\n        have \"w = stake l w @- sdrop l w\" by simp\n        also have \"stake l w = stake k w @ stake (l - k) (sdrop k w)\" using assms(2) by simp\n        finally have 1: \"run (stake k w @- stake (l - k) (sdrop k w) @- sdrop l w) p\"\n          unfolding shift_append using assms(1) by simp\n        show \"path (stake (l - k) (sdrop k w)) (target (stake k w) p)\" using 1 by auto\n        show \"set (stake (l - k) (sdrop k w)) \\<subseteq> invisible\" using assms(3) by (auto simp: set_stake_snth)\n      qed\n      also have \"\\<dots> = int ((p ## trace w p) !! k)\" by simp\n      finally show ?thesis by rule\n    qed\n\n  end\n\n  locale transition_system_complete =\n    transition_system_initial ex en init +\n    transition_system_interpreted ex en int\n    for ex :: \"'action \\<Rightarrow> 'state \\<Rightarrow> 'state\"\n    and en :: \"'action \\<Rightarrow> 'state \\<Rightarrow> bool\"\n    and init :: \"'state \\<Rightarrow> bool\"\n    and int :: \"'state \\<Rightarrow> 'interpretation\"\n  begin\n\n    definition language :: \"'interpretation stream set\"\n      where \"language \\<equiv> {smap int (p ## trace w p) |p w. init p \\<and> run w p}\"\n\n    lemma languageI[intro!]:\n      assumes \"w = smap int (p ## trace v p)\" \"init p\" \"run v p\"\n      shows \"w \\<in> language\"\n      using assms unfolding language_def by auto\n    lemma languageE[elim!]:\n      assumes \"w \\<in> language\"\n      obtains p v\n      where \"w = smap int (p ## trace v p)\" \"init p\" \"run v p\"\n      using assms unfolding language_def by auto\n\n  end\n\n  locale transition_system_finite_nodes =\n    transition_system_initial ex en init\n    for ex :: \"'action \\<Rightarrow> 'state \\<Rightarrow> 'state\"\n    and en :: \"'action \\<Rightarrow> 'state \\<Rightarrow> bool\"\n    and init :: \"'state \\<Rightarrow> bool\"\n    +\n    assumes reachable_finite: \"finite nodes\"\n\n  locale transition_system_cut =\n    transition_system_finite_nodes ex en init\n    for ex :: \"'action \\<Rightarrow> 'state \\<Rightarrow> 'state\"\n    and en :: \"'action \\<Rightarrow> 'state \\<Rightarrow> bool\"\n    and init :: \"'state \\<Rightarrow> bool\"\n    +\n    fixes cuts :: \"'action set\"\n    assumes cycles_cut: \"p \\<in> nodes \\<Longrightarrow> w \\<in> cycles p \\<Longrightarrow> w \\<noteq> [] \\<Longrightarrow> set w \\<inter> cuts \\<noteq> {}\"\n  begin\n\n    inductive scut :: \"'state \\<Rightarrow> 'state \\<Rightarrow> bool\"\n      where scut: \"p \\<in> nodes \\<Longrightarrow> en a p \\<Longrightarrow> a \\<notin> cuts \\<Longrightarrow> scut p (ex a p)\"\n\n    declare scut.intros[intro!]\n    declare scut.cases[elim!]\n\n    lemma scut_reachable:\n      assumes \"scut p q\"\n      shows \"p \\<in> nodes\" \"q \\<in> nodes\"\n      using assms by auto\n    lemma scut_trancl:\n      assumes \"scut\\<^sup>+\\<^sup>+ p q\"\n      obtains w\n      where \"path w p\" \"target w p = q\" \"set w \\<inter> cuts = {}\" \"w \\<noteq> []\"\n    using assms\n    proof (induct arbitrary: thesis)\n      case (base q)\n      show ?case using base by force\n    next\n      case (step q r)\n      obtain w where 1: \"path w p\" \"target w p = q\" \"set w \\<inter> cuts = {}\" \"w \\<noteq> []\"\n        using step(3) by this\n      obtain a where 2: \"en a q\" \"a \\<notin> cuts\" \"ex a q = r\" using step(2) by auto\n      show ?case\n      proof (rule step(4))\n        show \"path (w @ [a]) p\" using 1 2 by auto\n        show \"target (w @ [a]) p = r\" using 1 2 by auto\n        show \"set (w @ [a]) \\<inter> cuts = {}\" using 1 2 by auto\n        show \"w @ [a] \\<noteq> []\" by auto\n      qed\n    qed\n\n    sublocale wellfounded_relation \"scut\\<inverse>\\<inverse>\"\n    proof (unfold_locales, intro finite_acyclic_wf_converse[to_pred] acyclicI[to_pred], safe)\n      have 1: \"{(p, q). scut p q} \\<subseteq> nodes \\<times> nodes\" using scut_reachable by blast\n      have 2: \"finite (nodes \\<times> nodes)\"\n        using finite_cartesian_product reachable_finite by blast\n      show \"finite {(p, q). scut p q}\" using 1 2 by blast\n    next\n      fix p\n      assume 1: \"scut\\<^sup>+\\<^sup>+ p p\"\n      have 2: \"p \\<in> nodes\" using 1 tranclE[to_pred] scut_reachable by metis\n      obtain w where 3: \"path w p\" \"target w p = p\" \"set w \\<inter> cuts = {}\" \"w \\<noteq> []\"\n        using scut_trancl 1 by this\n      have 4: \"w \\<in> cycles p\" using 3(1, 2) by auto\n      have 5: \"set w \\<inter> cuts \\<noteq> {}\" using cycles_cut 2 4 3(4) by this\n      show \"False\" using 3(3) 5 by simp\n    qed\n\n    lemma no_cut_scut:\n      assumes \"p \\<in> nodes\" \"en a p\" \"a \\<notin> cuts\"\n      shows \"scut\\<inverse>\\<inverse> (ex a p) p\"\n      using assms by auto\n\n  end\n\n  locale transition_system_sticky =\n    transition_system_complete ex en init int +\n    transition_system_cut ex en init sticky\n    for ex :: \"'action \\<Rightarrow> 'state \\<Rightarrow> 'state\"\n    and en :: \"'action \\<Rightarrow> 'state \\<Rightarrow> bool\"\n    and init :: \"'state \\<Rightarrow> bool\"\n    and int :: \"'state \\<Rightarrow> 'interpretation\"\n    and sticky :: \"'action set\"\n    +\n    assumes executable_visible_sticky: \"executable \\<inter> visible \\<subseteq> sticky\"\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Partial_Order_Reduction/Transition_System_Extensions.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.26571804995290604}}
{"text": "(*  Title:       BDD\n\n    Author:      Veronika Ortner and Norbert Schirmer, 2004\n    Maintainer:  Norbert Schirmer,  norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  \nRepointProof.thy\n\nCopyright (C) 2004-2008 Veronika Ortner and Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nheader {* Proof of Procedure Repoint *}\ntheory RepointProof imports ProcedureSpecs begin\n\nhide_const (open) DistinctTreeProver.set_of tree.Node tree.Tip\n\nlemma (in Repoint_impl) Repoint_modifies:\n  shows \"\\<forall>\\<sigma>. \\<Gamma>\\<turnstile>{\\<sigma>} \\<acute>p :==  PROC Repoint (\\<acute>p)\n        {t. t may_only_modify_globals \\<sigma> in [low,high]}\"\n  apply (hoare_rule HoarePartial.ProcRec1)\n  apply (vcg spec=modifies)\n  done\n\nlemma low_high_exchange_dag: \nassumes pt_same: \"\\<forall>pt. pt \\<notin> set_of lt \\<longrightarrow> low pt = lowa pt \\<and> high pt = higha pt\"\nassumes pt_changed: \"\\<forall>pt \\<in> set_of lt. lowa pt = (rep \\<propto> low) pt \\<and> \n                            higha pt = (rep \\<propto> high) pt\"\nassumes rep_pt: \"\\<forall>pt \\<in> set_of rt. rep pt = pt\"\nshows \"\\<And>q.  Dag q (rep \\<propto> low) (rep \\<propto> high) rt \\<Longrightarrow> \n            Dag q (rep \\<propto> lowa) (rep \\<propto> higha) rt\"\nusing rep_pt\nproof (induct rt)\n  case Tip thus ?case by simp\nnext\n  case (Node lrt q' rrt)\n  have \"Dag q (rep \\<propto> low) (rep \\<propto> high) (Node lrt q' rrt)\" by fact\n  then obtain \n    q': \"q = q'\"  and\n    q_notNull: \"q \\<noteq> Null\" and \n    lrt: \"Dag ((rep \\<propto> low) q) (rep \\<propto> low) (rep \\<propto> high) lrt\" and\n    rrt: \"Dag ((rep \\<propto> high) q) (rep \\<propto> low) (rep \\<propto> high) rrt\" \n    by auto\n  have rlowa_rlow: \"((rep \\<propto> lowa) q) = ((rep \\<propto> low) q)\"\n  proof (cases \"q \\<in> set_of lt\")\n    case True\n    note q_in_lt=this\n    with pt_changed have lowa_q: \"lowa q = (rep \\<propto> low) q\"\n      by simp\n    thus \"(rep \\<propto> lowa) q = (rep \\<propto> low) q\"\n    proof (cases \"low q = Null\")\n      case True\n      with lowa_q have \"lowa q = Null\"\n        by (simp add: null_comp_def)\n      with True show ?thesis\n        by (simp add: null_comp_def)\n    next\n      assume lq_nNull: \"low q \\<noteq> Null\"\n      show ?thesis\n      proof (cases \"(rep \\<propto> low) q = Null\")\n        case True \n        with lowa_q have \"lowa q = Null\"\n          by simp\n        with True show ?thesis\n          by (simp add: null_comp_def)\n      next\n        assume rlq_nNull: \"(rep \\<propto> low) q \\<noteq> Null\"\n        with lrt lowa_q have \"lowa q \\<in> set_of lrt\"\n          by auto\n        with Node.prems Node have \"lowa q \\<in> set_of (Node lrt q' rrt)\"\n          by simp\n        with Node.prems have \"rep (lowa q) = lowa q\"\n          by auto\n        with lowa_q rlq_nNull show ?thesis\n          by (simp add: null_comp_def)\n      qed\n    qed\n  next\n    assume q_notin_lt: \" q \\<notin> set_of lt\"\n    with pt_same have \"low q = lowa q\"\n      by auto\n    thus ?thesis\n      by (simp add: null_comp_def)\n  qed\n  have rhigha_rhigh: \"((rep \\<propto> higha) q) = ((rep \\<propto> high) q)\"\n  proof (cases \"q \\<in> set_of lt\")\n    case True\n    note q_in_lt=this\n    with pt_changed have higha_q: \"higha q = (rep \\<propto> high) q\"\n      by simp\n    thus ?thesis\n    proof (cases \"high q = Null\")\n      case True\n      with higha_q have \"higha q = Null\"\n        by (simp add: null_comp_def)\n      with True show ?thesis\n        by (simp add: null_comp_def)\n    next\n      assume hq_nNull: \"high q \\<noteq> Null\"\n      show ?thesis\n      proof (cases \"(rep \\<propto> high) q = Null\")\n        case True \n        with higha_q have \"higha q = Null\"\n          by simp\n        with True show ?thesis\n          by (simp add: null_comp_def)\n      next\n        assume rhq_nNull: \"(rep \\<propto> high) q \\<noteq> Null\"\n        with rrt higha_q have \"higha q \\<in> set_of rrt\"\n          by auto\n        with Node.prems Node have \"higha q \\<in> set_of (Node lrt q' rrt)\"\n          by simp\n        with Node.prems have \"rep (higha q) = higha q\"\n          by auto\n        with higha_q rhq_nNull show ?thesis\n          by (simp add: null_comp_def)\n      qed\n    qed\n  next\n    assume q_notin_lt: \" q \\<notin> set_of lt\"\n    with pt_same have \"high q = higha q\"\n      by auto\n    thus ?thesis\n      by (simp add: null_comp_def)\n  qed\n  with rrt have rhigha_mixed_dag: \n    \"Dag ((rep \\<propto> higha) q) (rep \\<propto> low) (rep \\<propto> high) rrt\"\n    by simp\n  from lrt rlowa_rlow have rlowa_mixed_dag: \n    \" Dag ((rep \\<propto> lowa) q) (rep \\<propto> low) (rep \\<propto> high) lrt\"\n    by simp\n  from Node.prems have lrt_rep_eq: \" \\<forall>pt\\<in>set_of lrt. rep pt = pt\"\n    by simp\n  from Node.prems have rrt_rep_eq: \"\\<forall>pt\\<in>set_of rrt. rep pt = pt\"\n    by simp\n  from rlowa_mixed_dag lrt_rep_eq have lowa_lrt: \n    \" Dag ((rep \\<propto> lowa) q) (rep \\<propto> lowa) (rep \\<propto> higha) lrt\"\n    apply -\n    apply (rule Node.hyps)\n    apply auto\n    done\n  from rhigha_mixed_dag rrt_rep_eq have higha_rrt: \n    \" Dag ((rep \\<propto> higha) q) (rep \\<propto> lowa) (rep \\<propto> higha) rrt\"\n    apply -\n    apply (rule Node.hyps)\n    apply auto\n    done\n  with lowa_lrt q' q_notNull \n  show \" Dag q (rep \\<propto> lowa) (rep \\<propto> higha) (Node lrt q' rrt)\"\n    by simp\nqed\n\n(*lemma Repoint_spec :\nincludes Repoint_impl \nshows  \n  \"\\<forall>\\<sigma> rept. \\<Gamma>\\<turnstile> \\<lbrace>\\<sigma>. (Dag ((\\<^bsup>\\<sigma>\\<^esup>rep \\<propto> id) \\<^bsup>\\<sigma>\\<^esup>p) (\\<^bsup>\\<sigma>\\<^esup>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>low) (\\<^bsup>\\<sigma>\\<^esup>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>high) rept) \n  \\<and> (\\<forall> no \\<in> set_of rept. \\<^bsup>\\<sigma>\\<^esup>rep no = no) \\<rbrace>\n  \\<acute>p :== CALL Repoint (\\<acute>p)\n  \\<lbrace>Dag \\<acute>p \\<acute>low \\<acute>high rept \\<and>\n  (\\<forall>pt. pt \\<notin> set_of rept \\<longrightarrow> \\<^bsup>\\<sigma>\\<^esup>low pt = \\<acute>low pt \\<and> \\<^bsup>\\<sigma>\\<^esup>high pt = \\<acute>high pt)\\<rbrace>\"\napply (hoare_rule CallRec1_SamePost)\napply (vcg)\napply  (rule conjI)\napply  clarify\nprefer 2\napply (intro impI allI )\napply (simp add: null_comp_def)\napply (rule conjI)\nprefer 2\napply (clarsimp)\napply clarify\n*)\n\n\n\nlemma (in Repoint_impl) Repoint_spec':\nshows \n  \"\\<forall>\\<sigma>. \\<Gamma>\\<turnstile> {\\<sigma>}\n  \\<acute>p :== PROC Repoint (\\<acute>p)\n  \\<lbrace>\\<forall> rept. ((Dag ((\\<^bsup>\\<sigma>\\<^esup>rep \\<propto> id) \\<^bsup>\\<sigma>\\<^esup>p) (\\<^bsup>\\<sigma>\\<^esup>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>low) (\\<^bsup>\\<sigma>\\<^esup>rep \\<propto> \\<^bsup>\\<sigma>\\<^esup>high) rept) \n  \\<and> (\\<forall> no \\<in> set_of rept. \\<^bsup>\\<sigma>\\<^esup>rep no = no))\n  \\<longrightarrow> Dag \\<acute>p \\<acute>low \\<acute>high rept \\<and>\n  (\\<forall>pt. pt \\<notin> set_of rept \\<longrightarrow> \\<^bsup>\\<sigma>\\<^esup>low pt = \\<acute>low pt \\<and> \\<^bsup>\\<sigma>\\<^esup>high pt = \\<acute>high pt)\\<rbrace>\"\napply (hoare_rule HoarePartial.ProcRec1)\napply vcg\napply  (rule conjI)\napply  clarify\nprefer 2\napply (intro impI allI )\napply (simp add: null_comp_def)\napply (rule conjI)\nprefer 2\napply (clarsimp)\napply clarify\nproof -\n  fix low high p rep lowa higha pa lowb highb pb rept\n  assume p_nNull: \"p \\<noteq> Null\"\n  assume rp_nNull: \" rep p \\<noteq> Null\"\n  assume rec_spec_lrept: \n    \"\\<forall>rept. Dag ((rep \\<propto> id) (low (rep p))) (rep \\<propto> low) (rep \\<propto> high) rept\n    \\<and> (\\<forall>no\\<in>set_of rept. rep no = no)\n    \\<longrightarrow> Dag pa lowa higha rept \\<and> \n        (\\<forall>pt. pt \\<notin> set_of rept \\<longrightarrow> low pt = lowa pt \\<and> high pt = higha pt)\"\n  assume rec_spec_rrept: \n    \"\\<forall>rept. Dag ((rep \\<propto> id) (higha (rep p))) (rep \\<propto> lowa(rep p := pa)) (rep \\<propto> higha) rept\n    \\<and> (\\<forall>no\\<in>set_of rept. rep no = no)\n    \\<longrightarrow> Dag pb lowb highb rept \\<and> \n        (\\<forall>pt. pt \\<notin> set_of rept \\<longrightarrow> (lowa(rep p := pa)) pt = lowb pt \\<and> higha pt = highb pt)\"\n  assume rept_dag: \"Dag ((rep \\<propto> id) p) (rep \\<propto> low) (rep \\<propto> high) rept\"\n  assume rno_rept: \"\\<forall>no\\<in>set_of rept. rep no = no\"\n  show \" Dag (rep p) lowb (highb(rep p := pb)) rept \\<and> \n    (\\<forall>pt. pt \\<notin> set_of rept \\<longrightarrow> low pt = lowb pt \\<and> high pt = (highb(rep p := pb)) pt)\"\n  proof -\n    from rp_nNull rept_dag p_nNull obtain lrept rrept where\n      rept_def: \"rept = Node lrept (rep p) rrept\"\n      by auto\n    with rept_dag p_nNull have lrept_dag: \n      \"Dag ((rep \\<propto> low) (rep p)) (rep \\<propto> low) (rep \\<propto> high) lrept\"\n      by simp\n    from rept_def rept_dag p_nNull have rrept_dag: \n      \"Dag ((rep \\<propto> high) (rep p)) (rep \\<propto> low) (rep \\<propto> high) rrept\"\n      by simp\n    from rno_rept rept_def have rno_lrept: \"\\<forall> no \\<in> set_of lrept. rep no = no\"\n      by auto\n    from rno_rept rept_def have rno_rrept: \"\\<forall> no \\<in> set_of rrept. rep no = no\"\n      by auto\n    have repoint_post_low: \n      \" Dag pa lowa higha lrept \\<and> \n      (\\<forall>pt. pt \\<notin> set_of lrept \\<longrightarrow> low pt = lowa pt \\<and> high pt = higha pt)\"\n    proof -\n      from lrept_dag have \" Dag ((rep \\<propto> id) (low (rep p))) (rep \\<propto> low) (rep \\<propto> high) lrept\"\n        by (simp add: id_trans)\n      with  rec_spec_lrept rno_lrept show ?thesis\n        apply -\n        apply (erule_tac x=lrept in allE)\n        apply (erule impE)\n        apply simp\n        apply assumption\n        done\n    qed\n    hence low_lowa_nc: \"(\\<forall>pt. pt \\<notin> set_of lrept \\<longrightarrow> low pt = lowa pt \\<and> high pt = higha pt)\"\n      by simp\n    from lrept_dag  repoint_post_low obtain \n      pa_def: \"pa = (rep \\<propto> low) (rep p)\" and\n      lowa_higha_def: \"(\\<forall> no \\<in> set_of lrept. lowa no = (rep \\<propto> low) no \\<and> higha no = (rep \\<propto> high) no)\"\n      apply -\n      apply (drule Dags_eq_hp_eq)\n      apply auto\n      done\n    from rept_dag have rept_DAG: \"DAG rept\"\n      by (rule Dag_is_DAG)\n    with rept_def have rp_notin_lrept: \"rep p \\<notin> set_of lrept\"\n      by simp\n    from rept_DAG rept_def have rp_notin_rrept: \"rep p \\<notin> set_of rrept\"\n      by simp\n    have \"Dag ((rep \\<propto> id) (higha (rep p))) (rep \\<propto> lowa(rep p := pa)) (rep \\<propto> higha) rrept\"\n    proof -\n      from low_lowa_nc rp_notin_lrept have \"(rep \\<propto> high) (rep p) = (rep \\<propto> higha) (rep p)\"\n        by (auto simp add: null_comp_def)\n      with rrept_dag have higha_mixed_rrept: \n        \"Dag ((rep \\<propto> id) (higha (rep p))) (rep \\<propto> low) (rep \\<propto> high) rrept\"\n        by (simp add: id_trans)\n      thm low_high_exchange_dag\n      with low_lowa_nc lowa_higha_def rno_rrept have lowa_higha_rrept:\n        \"Dag ((rep \\<propto> id) (higha (rep p))) (rep \\<propto> lowa) (rep \\<propto> higha) rrept\"\n        apply -\n        apply (rule low_high_exchange_dag)\n        apply auto\n        done\n      have \"Dag ((rep \\<propto> id) (higha (rep p))) (rep \\<propto> lowa) (rep \\<propto> higha) rrept = \n        Dag ((rep \\<propto> id) (higha (rep p))) (rep \\<propto> lowa(rep p := pa)) (rep \\<propto> higha) rrept\"\n      proof -\n        have \"\\<forall> no \\<in> set_of rrept. (rep \\<propto> lowa) no = (rep \\<propto> lowa(rep p := pa)) no \\<and>\n          (rep \\<propto> higha) no = (rep \\<propto> higha) no\"\n        proof \n          fix no\n          assume no_in_rrept: \"no \\<in> set_of rrept\"\n          with rp_notin_rrept have \"no \\<noteq> rep p\" \n            by blast\n          thus \"(rep \\<propto> lowa) no = (rep \\<propto> lowa(rep p := pa)) no \\<and> \n            (rep \\<propto> higha) no = (rep \\<propto> higha) no\"\n            by (simp add: null_comp_def)\n        qed\n        thus ?thesis\n          by (rule heaps_eq_Dag_eq)\n      qed\n      with lowa_higha_rrept show ?thesis\n        by simp\n    qed\n    with rec_spec_rrept rno_rrept have repoint_rrept: \"Dag pb lowb highb rrept \\<and> \n      (\\<forall>pt. pt \\<notin> set_of rrept \\<longrightarrow> \n      (lowa(rep p := pa)) pt = lowb pt \\<and> higha pt = highb pt)\"\n      apply -\n      apply (erule_tac x=rrept in allE)\n      apply (erule impE)\n      apply simp\n      apply assumption\n      done\n    then have ab_nc: \"(\\<forall>pt. pt \\<notin> set_of rrept \\<longrightarrow> \n      (lowa(rep p := pa)) pt = lowb pt \\<and> higha pt = highb pt)\"\n      by simp\n    from repoint_rrept rrept_dag obtain\n      pb_def: \"pb = ((rep \\<propto> high) (rep p))\" and\n      lowb_highb_def: \"(\\<forall> no \\<in> set_of rrept. lowb no = (rep \\<propto> low) no \\<and> highb no = (rep \\<propto> high) no)\"\n      apply -\n      apply (drule Dags_eq_hp_eq)\n      apply auto\n      done\n    have rept_end_dag: \" Dag (rep p) lowb (highb(rep p := pb)) rept\"\n    proof -\n      have \"\\<forall> no \\<in> set_of rept. lowb no = (rep \\<propto> low) no \\<and> (highb(rep p := pb)) no = (rep \\<propto> high) no\"\n      proof\n        fix no\n        assume no_in_rept: \" no \\<in> set_of rept\"\n        show \"lowb no = (rep \\<propto> low) no \\<and> (highb(rep p := pb)) no = (rep \\<propto> high) no\"\n        proof (cases \"no \\<in> set_of rrept\")\n          case True\n          with lowb_highb_def pb_def show ?thesis\n            by simp\n        next\n          assume no_notin_rrept: \" no \\<notin> set_of rrept\"\n          show ?thesis\n          proof (cases \"no \\<in> set_of lrept\")\n            case True\n            with no_notin_rrept rp_notin_lrept ab_nc\n            have ab_nc_no: \"lowa no = lowb no \\<and> higha no = highb no\"\n              apply -\n              apply (erule_tac x=no in allE)\n              apply (erule impE)\n              apply simp\n              apply (subgoal_tac \"no \\<noteq> rep p\")\n              apply simp\n              apply blast\n              done\n            from lowa_higha_def True have \n              \"lowa no = (rep \\<propto> low) no \\<and> higha no = (rep \\<propto> high) no\"\n              by auto\n            with ab_nc_no have \"lowb no = (rep \\<propto> low) no \\<and> highb no =(rep \\<propto> high) no\" \n              by simp\n            with rp_notin_lrept True show ?thesis\n              apply (subgoal_tac \"no \\<noteq> rep p\")\n              apply simp\n              apply blast\n              done\n          next\n            assume no_notin_lrept: \" no \\<notin> set_of lrept\"\n            with no_in_rept rept_def no_notin_rrept have no_rp: \"no = rep p\"\n              by simp\n            with rp_notin_lrept low_lowa_nc have a_nc:  \n              \"low no = lowa no \\<and> high no = higha no\"\n              by auto\n            from rp_notin_rrept no_rp ab_nc have \n              \"(lowa(rep p := pa)) no = lowb no \\<and> higha no = highb no\"\n              by auto\n            with a_nc pa_def no_rp have \"(rep \\<propto> low) no = lowb no \\<and> high no = highb no\"\n              by auto\n            with pb_def no_rp show ?thesis\n              by simp\n          qed\n        qed\n      qed\n      with rept_dag have \" Dag (rep p) lowb (highb(rep p := pb)) rept = \n        Dag (rep p) (rep \\<propto> low) (rep \\<propto> high) rept\"      \n        apply -\n        thm heaps_eq_Dag_eq\n        apply (rule heaps_eq_Dag_eq)\n        apply auto\n        done\n      with rept_dag p_nNull show ?thesis\n        by simp\n    qed\n    have \"(\\<forall>pt. pt \\<notin> set_of rept \\<longrightarrow> low pt = lowb pt \\<and> high pt = (highb(rep p := pb)) pt)\"\n    proof (intro allI impI)\n      fix pt\n      assume pt_notin_rept: \"pt \\<notin> set_of rept\"\n      with rept_def obtain\n        pt_notin_lrept: \"pt \\<notin> set_of lrept\" and\n        pt_notin_rrept: \"pt \\<notin> set_of rrept\" and\n        pt_neq_rp: \"pt \\<noteq> rep p\"\n        by simp\n      with low_lowa_nc ab_nc show \"low pt = lowb pt \\<and> high pt = (highb(rep p := pb)) pt\"\n        by auto\n    qed\n    with rept_end_dag show ?thesis\n      by simp\n  qed\nqed\n        \nlemma (in Repoint_impl) Repoint_spec:\nshows \n  \"\\<forall>\\<sigma> rept. \\<Gamma>\\<turnstile> \\<lbrace>\\<sigma>. Dag ((\\<acute>rep \\<propto> id) \\<acute>p) (\\<acute>rep \\<propto> \\<acute>low) (\\<acute>rep \\<propto> \\<acute>high) rept \n  \\<and> (\\<forall> no \\<in> set_of rept. \\<acute>rep no = no) \\<rbrace> \n  \\<acute>p :== PROC Repoint (\\<acute>p)\n  \\<lbrace>Dag \\<acute>p \\<acute>low \\<acute>high rept \\<and>\n  (\\<forall>pt. pt \\<notin> set_of rept \\<longrightarrow> \\<^bsup>\\<sigma>\\<^esup>low pt = \\<acute>low pt \\<and> \\<^bsup>\\<sigma>\\<^esup>high pt = \\<acute>high pt)\\<rbrace>\"\napply (hoare_rule HoarePartial.ProcRec1)\napply vcg\napply (rule conjI)\nprefer 2\napply  (clarsimp simp add: null_comp_def)\napply clarify\napply (rule conjI)\nprefer 2\napply  clarsimp\napply clarify\nproof -\n  fix rept low high rep p\n  assume rept_dag: \"Dag ((rep \\<propto> id) p) (rep \\<propto> low) (rep \\<propto> high) rept\"\n  assume rno_rept: \"\\<forall>no\\<in>set_of rept. rep no = no\"\n  assume p_nNull: \"p \\<noteq> Null\"\n  assume rp_nNull: \" rep p \\<noteq> Null\"\n  show \"\\<exists>lrept.\n             Dag ((rep \\<propto> id) (low (rep p))) (rep \\<propto> low) (rep \\<propto> high) lrept \\<and>\n             (\\<forall>no\\<in>set_of lrept. rep no = no) \\<and>\n             (\\<forall>lowa higha pa.\n                 Dag pa lowa higha lrept \\<and>\n                 (\\<forall>pt. pt \\<notin> set_of lrept \\<longrightarrow>\n                       low pt = lowa pt \\<and> high pt = higha pt) \\<longrightarrow>\n                 (\\<exists>rrept.\n                     Dag ((rep \\<propto> id) (higha (rep p))) (rep \\<propto> lowa(rep p := pa))\n                      (rep \\<propto> higha) rrept \\<and>\n                     (\\<forall>no\\<in>set_of rrept. rep no = no) \\<and>\n                     (\\<forall>lowb highb pb.\n                         Dag pb lowb highb rrept \\<and>\n                         (\\<forall>pt. pt \\<notin> set_of rrept \\<longrightarrow>\n                               (lowa(rep p := pa)) pt = lowb pt \\<and>\n                               higha pt = highb pt) \\<longrightarrow>\n                         Dag (rep p) lowb (highb(rep p := pb)) rept \\<and>\n                         (\\<forall>pt. pt \\<notin> set_of rept \\<longrightarrow>\n                               low pt = lowb pt \\<and>\n                               high pt = (highb(rep p := pb)) pt))))\" \n  proof -\n    from rp_nNull rept_dag p_nNull obtain lrept rrept where\n      rept_def: \"rept = Node lrept (rep p) rrept\"\n      by auto\n    with rept_dag p_nNull have lrept_dag: \n      \"Dag ((rep \\<propto> low) (rep p)) (rep \\<propto> low) (rep \\<propto> high) lrept\"\n      by simp\n    from rept_def rept_dag p_nNull have rrept_dag: \n      \"Dag ((rep \\<propto> high) (rep p)) (rep \\<propto> low) (rep \\<propto> high) rrept\"\n      by simp\n    from rno_rept rept_def have rno_lrept: \"\\<forall> no \\<in> set_of lrept. rep no = no\"\n      by auto\n    from rno_rept rept_def have rno_rrept: \"\\<forall> no \\<in> set_of rrept. rep no = no\"\n      by auto\n    show ?thesis\n      apply (rule_tac x=lrept in exI)\n      apply (rule conjI)\n      apply  (simp add: id_trans lrept_dag)\n      apply (rule conjI)\n      apply (rule rno_lrept)\n      apply clarify\n    proof -\n      case (goal1 lowa higha pa)\n      have lrepta: \"Dag pa lowa higha lrept\" by fact\n      have low_lowa_nc: \n        \"\\<forall>pt. pt \\<notin> set_of lrept \\<longrightarrow> low pt = lowa pt \\<and> high pt = higha pt\" by fact\n      from lrept_dag lrepta  obtain \n        pa_def: \"pa = (rep \\<propto> low) (rep p)\" and\n        lowa_higha_def: \"\\<forall>no \\<in> set_of lrept. \n        lowa no = (rep \\<propto> low) no \\<and> higha no = (rep \\<propto> high) no\"\n        apply -\n        apply (drule Dags_eq_hp_eq)\n        apply auto\n        done\n      from rept_dag have rept_DAG: \"DAG rept\"\n        by (rule Dag_is_DAG)\n      with rept_def have rp_notin_lrept: \"rep p \\<notin> set_of lrept\"\n        by simp\n      from rept_DAG rept_def have rp_notin_rrept: \"rep p \\<notin> set_of rrept\"\n        by simp\n      have rrepta: \"Dag ((rep \\<propto> id) (higha (rep p))) \n                       (rep \\<propto> lowa(rep p := pa)) (rep \\<propto> higha) rrept\"\n      proof -\n        from low_lowa_nc rp_notin_lrept \n        have \"(rep \\<propto> high) (rep p) = (rep \\<propto> higha) (rep p)\"\n          by (auto simp add: null_comp_def)\n        with rrept_dag have higha_mixed_rrept: \n          \"Dag ((rep \\<propto> id) (higha (rep p))) (rep \\<propto> low) (rep \\<propto> high) rrept\"\n          by (simp add: id_trans)\n        thm low_high_exchange_dag\n        with low_lowa_nc lowa_higha_def rno_rrept \n        have lowa_higha_rrept:\n            \"Dag ((rep \\<propto> id) (higha (rep p))) (rep \\<propto> lowa) (rep \\<propto> higha) rrept\"\n          apply -\n          apply (rule low_high_exchange_dag)\n          apply auto\n          done\n        have \"Dag ((rep \\<propto> id) (higha (rep p))) (rep \\<propto> lowa) (rep \\<propto> higha) rrept = \n              Dag ((rep \\<propto> id) (higha (rep p))) \n                      (rep \\<propto> lowa(rep p := pa)) (rep \\<propto> higha) rrept\"\n        proof -\n          have \"\\<forall>no \\<in> set_of rrept. \n                    (rep \\<propto> lowa) no = (rep \\<propto> lowa(rep p := pa)) no \\<and>\n                    (rep \\<propto> higha) no = (rep \\<propto> higha) no\"\n          proof \n            fix no\n            assume no_in_rrept: \"no \\<in> set_of rrept\"\n            with rp_notin_rrept have \"no \\<noteq> rep p\" \n              by blast\n            thus \"(rep \\<propto> lowa) no = (rep \\<propto> lowa(rep p := pa)) no \\<and> \n              (rep \\<propto> higha) no = (rep \\<propto> higha) no\"\n              by (simp add: null_comp_def)\n          qed\n          thus ?thesis\n            by (rule heaps_eq_Dag_eq)\n        qed\n        with lowa_higha_rrept show ?thesis\n          by simp\n      qed\n      show ?case\n        apply (rule_tac x=rrept in exI)\n        apply (rule conjI)\n        apply  (rule rrepta)\n        apply (rule conjI)\n        apply  (rule rno_rrept)\n        apply clarify\n      proof -\n        case (goal1 lowb highb pb)\n        have rreptb: \"Dag pb lowb highb rrept\" by fact\n        have ab_nc: \"\\<forall>pt. pt \\<notin> set_of rrept \\<longrightarrow> \n                        (lowa(rep p := pa)) pt = lowb pt \\<and> higha pt = highb pt\" by fact\n        from rreptb rrept_dag obtain\n          pb_def: \"pb = ((rep \\<propto> high) (rep p))\" and\n          lowb_highb_def: \"\\<forall>no \\<in> set_of rrept. \n                              lowb no = (rep \\<propto> low) no \\<and> highb no = (rep \\<propto> high) no\"\n          apply -\n          apply (drule Dags_eq_hp_eq)\n          apply auto\n          done\n        have rept_end_dag: \" Dag (rep p) lowb (highb(rep p := pb)) rept\"\n        proof -\n          have \"\\<forall>no \\<in> set_of rept. \n                lowb no = (rep \\<propto> low) no \\<and> (highb(rep p := pb)) no = (rep \\<propto> high) no\"\n          proof\n            fix no\n            assume no_in_rept: \" no \\<in> set_of rept\"\n            show \"lowb no = (rep \\<propto> low) no \\<and> \n                  (highb(rep p := pb)) no = (rep \\<propto> high) no\"\n            proof (cases \"no \\<in> set_of rrept\")\n              case True\n              with lowb_highb_def pb_def show ?thesis\n                by simp\n            next\n              assume no_notin_rrept: \" no \\<notin> set_of rrept\"\n              show ?thesis\n              proof (cases \"no \\<in> set_of lrept\")\n                case True\n                with no_notin_rrept rp_notin_lrept ab_nc\n                have ab_nc_no: \"lowa no = lowb no \\<and> higha no = highb no\"\n                  apply -\n                  apply (erule_tac x=no in allE)\n                  apply (erule impE)\n                  apply simp\n                  apply (subgoal_tac \"no \\<noteq> rep p\")\n                  apply simp\n                  apply blast\n                  done\n                from lowa_higha_def True have \n                  \"lowa no = (rep \\<propto> low) no \\<and> higha no = (rep \\<propto> high) no\"\n                  by auto\n                with ab_nc_no \n                have \"lowb no = (rep \\<propto> low) no \\<and> highb no =(rep \\<propto> high) no\" \n                  by simp\n                with rp_notin_lrept True show ?thesis\n                  apply (subgoal_tac \"no \\<noteq> rep p\")\n                  apply simp\n                  apply blast\n                  done\n              next\n                assume no_notin_lrept: \" no \\<notin> set_of lrept\"\n                with no_in_rept rept_def no_notin_rrept have no_rp: \"no = rep p\"\n                  by simp\n                with rp_notin_lrept low_lowa_nc \n                have a_nc: \"low no = lowa no \\<and> high no = higha no\"\n                  by auto\n                from rp_notin_rrept no_rp ab_nc \n                have \"(lowa(rep p := pa)) no = lowb no \\<and> higha no = highb no\"\n                  by auto\n                with a_nc pa_def no_rp \n                have \"(rep \\<propto> low) no = lowb no \\<and> high no = highb no\"\n                  by auto\n                with pb_def no_rp show ?thesis\n                  by simp\n              qed\n            qed\n          qed\n          with rept_dag \n          have \"Dag (rep p) lowb (highb(rep p := pb)) rept = \n                Dag (rep p) (rep \\<propto> low) (rep \\<propto> high) rept\"      \n            apply -\n            apply (rule heaps_eq_Dag_eq)\n            apply auto\n            done\n          with rept_dag p_nNull show ?thesis\n            by simp\n        qed\n        have \"(\\<forall>pt. pt \\<notin> set_of rept \\<longrightarrow> low pt = lowb pt \\<and> \n                    high pt = (highb(rep p := pb)) pt)\"\n        proof (intro allI impI)\n          fix pt\n          assume pt_notin_rept: \"pt \\<notin> set_of rept\"\n          with rept_def obtain\n            pt_notin_lrept: \"pt \\<notin> set_of lrept\" and\n            pt_notin_rrept: \"pt \\<notin> set_of rrept\" and\n            pt_neq_rp: \"pt \\<noteq> rep p\"\n            by simp\n          with low_lowa_nc ab_nc \n          show \"low pt = lowb pt \\<and> high pt = (highb(rep p := pb)) pt\"\n            by auto\n        qed\n        with rept_end_dag show ?case\n          by simp\n      qed\n    qed\n  qed\nqed\n\nlemma (in Repoint_impl) Repoint_spec_total:\nshows \n  \"\\<forall>\\<sigma> rept. \\<Gamma>\\<turnstile>\\<^sub>t \\<lbrace>\\<sigma>. Dag ((\\<acute>rep \\<propto> id) \\<acute>p) (\\<acute>rep \\<propto> \\<acute>low) (\\<acute>rep \\<propto> \\<acute>high) rept \n  \\<and> (\\<forall> no \\<in> set_of rept. \\<acute>rep no = no) \\<rbrace> \n  \\<acute>p :== PROC Repoint (\\<acute>p)\n  \\<lbrace>Dag \\<acute>p \\<acute>low \\<acute>high rept \\<and>\n  (\\<forall>pt. pt \\<notin> set_of rept \\<longrightarrow> \\<^bsup>\\<sigma>\\<^esup>low pt = \\<acute>low pt \\<and> \\<^bsup>\\<sigma>\\<^esup>high pt = \\<acute>high pt)\\<rbrace>\"\n\napply (hoare_rule HoareTotal.ProcRec1\n          [where r=\"measure (\\<lambda>(s,p). size \n                       (dag ((\\<^bsup>s\\<^esup>rep \\<propto> id) \\<^bsup>s\\<^esup>p) (\\<^bsup>s\\<^esup>rep \\<propto> \\<^bsup>s\\<^esup>low) (\\<^bsup>s\\<^esup>rep \\<propto> \\<^bsup>s\\<^esup>high)))\"])\napply vcg\napply (rule conjI)\nprefer 2\napply  (clarsimp simp add: null_comp_def)\napply clarify\napply (rule conjI)\nprefer 2\napply  clarsimp\napply clarify\nproof -\n  fix rept low high rep p\n  assume rept_dag: \"Dag ((rep \\<propto> id) p) (rep \\<propto> low) (rep \\<propto> high) rept\"\n  assume rno_rept: \"\\<forall>no\\<in>set_of rept. rep no = no\"\n  assume p_nNull: \"p \\<noteq> Null\"\n  assume rp_nNull: \" rep p \\<noteq> Null\"\n  show \"\\<exists>lrept.\n             Dag ((rep \\<propto> id) (low (rep p))) (rep \\<propto> low) (rep \\<propto> high) lrept \\<and>\n             (\\<forall>no\\<in>set_of lrept. rep no = no) \\<and>\n             size (dag ((rep \\<propto> id) (low (rep p))) (rep \\<propto> low) (rep \\<propto> high))\n             < size (dag ((rep \\<propto> id) p) (rep \\<propto> low) (rep \\<propto> high)) \\<and>\n             (\\<forall>lowa higha pa.\n                 Dag pa lowa higha lrept \\<and>\n                 (\\<forall>pt. pt \\<notin> set_of lrept \\<longrightarrow>\n                       low pt = lowa pt \\<and> high pt = higha pt) \\<longrightarrow>\n                 (\\<exists>rrept.\n                     Dag ((rep \\<propto> id) (higha (rep p))) (rep \\<propto> lowa(rep p := pa))\n                      (rep \\<propto> higha) rrept \\<and>\n                     (\\<forall>no\\<in>set_of rrept. rep no = no) \\<and>\n                     size (dag ((rep \\<propto> id) (higha (rep p)))\n                            (rep \\<propto> lowa(rep p := pa)) (rep \\<propto> higha))\n                     < size (dag ((rep \\<propto> id) p) (rep \\<propto> low) (rep \\<propto> high)) \\<and>\n                     (\\<forall>lowb highb pb.\n                         Dag pb lowb highb rrept \\<and>\n                         (\\<forall>pt. pt \\<notin> set_of rrept \\<longrightarrow>\n                               (lowa(rep p := pa)) pt = lowb pt \\<and>\n                               higha pt = highb pt) \\<longrightarrow>\n                         Dag (rep p) lowb (highb(rep p := pb)) rept \\<and>\n                         (\\<forall>pt. pt \\<notin> set_of rept \\<longrightarrow>\n                               low pt = lowb pt \\<and>\n                               high pt = (highb(rep p := pb)) pt))))\"\n  proof -\n    from rp_nNull rept_dag p_nNull obtain lrept rrept where\n      rept_def: \"rept = Node lrept (rep p) rrept\"\n      by auto\n    with rept_dag p_nNull have lrept_dag: \n      \"Dag ((rep \\<propto> low) (rep p)) (rep \\<propto> low) (rep \\<propto> high) lrept\"\n      by simp\n    from rept_def rept_dag p_nNull have rrept_dag: \n      \"Dag ((rep \\<propto> high) (rep p)) (rep \\<propto> low) (rep \\<propto> high) rrept\"\n      by simp\n    from rno_rept rept_def have rno_lrept: \"\\<forall> no \\<in> set_of lrept. rep no = no\"\n      by auto\n    from rno_rept rept_def have rno_rrept: \"\\<forall> no \\<in> set_of rrept. rep no = no\"\n      by auto\n    show ?thesis\n      apply (rule_tac x=lrept in exI)\n      apply (rule conjI)\n      apply  (simp add: id_trans lrept_dag)\n      apply (rule conjI)\n      apply (rule rno_lrept)\n      apply (rule conjI)\n      using rept_dag rept_def\n      apply  (simp only: Dag_dag)\n      apply  (clarsimp simp add: id_trans Dag_dag)\n      apply clarify\n    proof -\n      case (goal1 lowa higha pa)\n      have lrepta: \"Dag pa lowa higha lrept\" by fact\n      have low_lowa_nc: \n        \"\\<forall>pt. pt \\<notin> set_of lrept \\<longrightarrow> low pt = lowa pt \\<and> high pt = higha pt\" by fact\n      from lrept_dag lrepta  obtain \n        pa_def: \"pa = (rep \\<propto> low) (rep p)\" and\n        lowa_higha_def: \"\\<forall>no \\<in> set_of lrept. \n        lowa no = (rep \\<propto> low) no \\<and> higha no = (rep \\<propto> high) no\"\n        apply -\n        apply (drule Dags_eq_hp_eq)\n        apply auto\n        done\n      from rept_dag have rept_DAG: \"DAG rept\"\n        by (rule Dag_is_DAG)\n      with rept_def have rp_notin_lrept: \"rep p \\<notin> set_of lrept\"\n        by simp\n      from rept_DAG rept_def have rp_notin_rrept: \"rep p \\<notin> set_of rrept\"\n        by simp\n      have rrepta: \"Dag ((rep \\<propto> id) (higha (rep p))) \n                       (rep \\<propto> lowa(rep p := pa)) (rep \\<propto> higha) rrept\"\n      proof -\n        from low_lowa_nc rp_notin_lrept \n        have \"(rep \\<propto> high) (rep p) = (rep \\<propto> higha) (rep p)\"\n          by (auto simp add: null_comp_def)\n        with rrept_dag have higha_mixed_rrept: \n          \"Dag ((rep \\<propto> id) (higha (rep p))) (rep \\<propto> low) (rep \\<propto> high) rrept\"\n          by (simp add: id_trans)\n        thm low_high_exchange_dag\n        with low_lowa_nc lowa_higha_def rno_rrept \n        have lowa_higha_rrept:\n            \"Dag ((rep \\<propto> id) (higha (rep p))) (rep \\<propto> lowa) (rep \\<propto> higha) rrept\"\n          apply -\n          apply (rule low_high_exchange_dag)\n          apply auto\n          done\n        have \"Dag ((rep \\<propto> id) (higha (rep p))) (rep \\<propto> lowa) (rep \\<propto> higha) rrept = \n              Dag ((rep \\<propto> id) (higha (rep p))) \n                      (rep \\<propto> lowa(rep p := pa)) (rep \\<propto> higha) rrept\"\n        proof -\n          have \"\\<forall>no \\<in> set_of rrept. \n                    (rep \\<propto> lowa) no = (rep \\<propto> lowa(rep p := pa)) no \\<and>\n                    (rep \\<propto> higha) no = (rep \\<propto> higha) no\"\n          proof \n            fix no\n            assume no_in_rrept: \"no \\<in> set_of rrept\"\n            with rp_notin_rrept have \"no \\<noteq> rep p\" \n              by blast\n            thus \"(rep \\<propto> lowa) no = (rep \\<propto> lowa(rep p := pa)) no \\<and> \n              (rep \\<propto> higha) no = (rep \\<propto> higha) no\"\n              by (simp add: null_comp_def)\n          qed\n          thus ?thesis\n            by (rule heaps_eq_Dag_eq)\n        qed\n        with lowa_higha_rrept show ?thesis\n          by simp\n      qed\n      show ?case\n        apply (rule_tac x=rrept in exI)\n        apply (rule conjI)\n        apply  (rule rrepta)\n        apply (rule conjI)\n        apply  (rule rno_rrept)\n        apply (rule conjI)\n        using rept_dag rept_def rrepta\n        apply  (simp only: Dag_dag)\n        apply  (clarsimp simp add: id_trans Dag_dag)\n        apply clarify\n      proof -\n        case (goal1 lowb highb pb)\n        have rreptb: \"Dag pb lowb highb rrept\" by fact\n        have ab_nc: \"\\<forall>pt. pt \\<notin> set_of rrept \\<longrightarrow> \n                        (lowa(rep p := pa)) pt = lowb pt \\<and> higha pt = highb pt\" by fact\n        from rreptb rrept_dag obtain\n          pb_def: \"pb = ((rep \\<propto> high) (rep p))\" and\n          lowb_highb_def: \"\\<forall>no \\<in> set_of rrept. \n                              lowb no = (rep \\<propto> low) no \\<and> highb no = (rep \\<propto> high) no\"\n          apply -\n          apply (drule Dags_eq_hp_eq)\n          apply auto\n          done\n        have rept_end_dag: \" Dag (rep p) lowb (highb(rep p := pb)) rept\"\n        proof -\n          have \"\\<forall>no \\<in> set_of rept. \n                lowb no = (rep \\<propto> low) no \\<and> (highb(rep p := pb)) no = (rep \\<propto> high) no\"\n          proof\n            fix no\n            assume no_in_rept: \" no \\<in> set_of rept\"\n            show \"lowb no = (rep \\<propto> low) no \\<and> \n                  (highb(rep p := pb)) no = (rep \\<propto> high) no\"\n            proof (cases \"no \\<in> set_of rrept\")\n              case True\n              with lowb_highb_def pb_def show ?thesis\n                by simp\n            next\n              assume no_notin_rrept: \" no \\<notin> set_of rrept\"\n              show ?thesis\n              proof (cases \"no \\<in> set_of lrept\")\n                case True\n                with no_notin_rrept rp_notin_lrept ab_nc\n                have ab_nc_no: \"lowa no = lowb no \\<and> higha no = highb no\"\n                  apply -\n                  apply (erule_tac x=no in allE)\n                  apply (erule impE)\n                  apply simp\n                  apply (subgoal_tac \"no \\<noteq> rep p\")\n                  apply simp\n                  apply blast\n                  done\n                from lowa_higha_def True have \n                  \"lowa no = (rep \\<propto> low) no \\<and> higha no = (rep \\<propto> high) no\"\n                  by auto\n                with ab_nc_no \n                have \"lowb no = (rep \\<propto> low) no \\<and> highb no =(rep \\<propto> high) no\" \n                  by simp\n                with rp_notin_lrept True show ?thesis\n                  apply (subgoal_tac \"no \\<noteq> rep p\")\n                  apply simp\n                  apply blast\n                  done\n              next\n                assume no_notin_lrept: \" no \\<notin> set_of lrept\"\n                with no_in_rept rept_def no_notin_rrept have no_rp: \"no = rep p\"\n                  by simp\n                with rp_notin_lrept low_lowa_nc \n                have a_nc: \"low no = lowa no \\<and> high no = higha no\"\n                  by auto\n                from rp_notin_rrept no_rp ab_nc \n                have \"(lowa(rep p := pa)) no = lowb no \\<and> higha no = highb no\"\n                  by auto\n                with a_nc pa_def no_rp \n                have \"(rep \\<propto> low) no = lowb no \\<and> high no = highb no\"\n                  by auto\n                with pb_def no_rp show ?thesis\n                  by simp\n              qed\n            qed\n          qed\n          with rept_dag \n          have \"Dag (rep p) lowb (highb(rep p := pb)) rept = \n                Dag (rep p) (rep \\<propto> low) (rep \\<propto> high) rept\"      \n            apply -\n            apply (rule heaps_eq_Dag_eq)\n            apply auto\n            done\n          with rept_dag p_nNull show ?thesis\n            by simp\n        qed\n        have \"(\\<forall>pt. pt \\<notin> set_of rept \\<longrightarrow> low pt = lowb pt \\<and> \n                    high pt = (highb(rep p := pb)) pt)\"\n        proof (intro allI impI)\n          fix pt\n          assume pt_notin_rept: \"pt \\<notin> set_of rept\"\n          with rept_def obtain\n            pt_notin_lrept: \"pt \\<notin> set_of lrept\" and\n            pt_notin_rrept: \"pt \\<notin> set_of rrept\" and\n            pt_neq_rp: \"pt \\<noteq> rep p\"\n            by simp\n          with low_lowa_nc ab_nc \n          show \"low pt = lowb pt \\<and> high pt = (highb(rep p := pb)) pt\"\n            by auto\n        qed\n        with rept_end_dag show ?case\n          by simp\n      qed\n    qed\n  qed\nqed\n     \nend", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/BDD/RepointProof.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.26571804995290604}}
{"text": "(*  Title:    HOL/Library/Conditional_Parametricity.thy\n    Author:   Jan Gilcher, Andreas Lochbihler, Dmitriy Traytel, ETH Zürich\n\nA conditional parametricity prover\n*)\n\ntheory Conditional_Parametricity\nimports \"MainRLT\"\nkeywords \"parametric_constant\" :: thy_decl\nbegin\n\ncontext includes lifting_syntax begin\n\nqualified definition Rel_match :: \"('a \\<Rightarrow> 'b \\<Rightarrow> bool) \\<Rightarrow> 'a \\<Rightarrow> 'b \\<Rightarrow> bool\" where\n  \"Rel_match R x y = R x y\"\n\nnamed_theorems parametricity_preprocess\n\nlemma bi_unique_Rel_match [parametricity_preprocess]:\n  \"bi_unique A = Rel_match (A ===> A ===> (=)) (=) (=)\"\n  unfolding bi_unique_alt_def2 Rel_match_def ..\n\nlemma bi_total_Rel_match [parametricity_preprocess]:\n  \"bi_total A = Rel_match ((A ===> (=)) ===> (=)) All All\"\n  unfolding bi_total_alt_def2 Rel_match_def ..\n\nlemma is_equality_Rel: \"is_equality A \\<Longrightarrow> Transfer.Rel A t t\"\n  by (fact transfer_raw)\n\nlemma Rel_Rel_match: \"Transfer.Rel R x y \\<Longrightarrow> Rel_match R x y\"\n  unfolding Rel_match_def Rel_def .\n\nlemma Rel_match_Rel: \"Rel_match R x y \\<Longrightarrow> Transfer.Rel R x y\"\n  unfolding Rel_match_def Rel_def .\n\nlemma Rel_Rel_match_eq: \"Transfer.Rel R x y = Rel_match R x y\"\n  using Rel_Rel_match Rel_match_Rel by fast\n\nlemma Rel_match_app:\n  assumes \"Rel_match (A ===> B) f g\" and \"Transfer.Rel A x y\"\n  shows \"Rel_match B (f x) (g y)\"\n  using assms Rel_match_Rel Rel_app Rel_Rel_match by fast\n\nend\n\nML_file \\<open>conditional_parametricity.ML\\<close>\n\nend\n", "meta": {"author": "dtraytel", "repo": "HOLRLT", "sha": "e9029da59bb3af0c835604a65308498f9696a364", "save_path": "github-repos/isabelle/dtraytel-HOLRLT", "path": "github-repos/isabelle/dtraytel-HOLRLT/HOLRLT-e9029da59bb3af0c835604a65308498f9696a364/HOLRLT/Library/Conditional_Parametricity.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6224593452091672, "lm_q2_score": 0.42632159254749025, "lm_q1q2_score": 0.26536785934564017}}
{"text": "(*  Title:      JinjaDCI/Common/WellForm.thy\n\n    Author:     Tobias Nipkow, Susannah Mansky\n    Copyright   2003 Technische Universitaet Muenchen, 2019-20 UIUC\n\n    Based on the Jinja theory J/WellForm.thy by Tobias Nipkow\n*)\n\nsection \\<open> Generic Well-formedness of programs \\<close>\n\ntheory WellForm imports TypeRel SystemClasses begin\n\ntext \\<open>\\noindent This theory defines global well-formedness conditions\nfor programs but does not look inside method bodies.  Hence it works\nfor both Jinja and JVM programs. Well-typing of expressions is defined\nelsewhere (in theory @{text WellType}).\n\nBecause Jinja does not have method overloading, its policy for method\noverriding is the classical one: \\emph{covariant in the result type\nbut contravariant in the argument types.} This means the result type\nof the overriding method becomes more specific, the argument types\nbecome more general.\n\\<close>\n\ntype_synonym 'm wf_mdecl_test = \"'m prog \\<Rightarrow> cname \\<Rightarrow> 'm mdecl \\<Rightarrow> bool\"\n\ndefinition wf_fdecl :: \"'m prog \\<Rightarrow> fdecl \\<Rightarrow> bool\"\nwhere\n  \"wf_fdecl P \\<equiv> \\<lambda>(F,b,T). is_type P T\"\n\ndefinition wf_mdecl :: \"'m wf_mdecl_test \\<Rightarrow> 'm wf_mdecl_test\"\nwhere\n  \"wf_mdecl wf_md P C \\<equiv> \\<lambda>(M,b,Ts,T,m).\n  (\\<forall>T\\<in>set Ts. is_type P T) \\<and> is_type P T \\<and> wf_md P C (M,b,Ts,T,m)\"\n\ndefinition wf_clinit :: \"'m mdecl list \\<Rightarrow> bool\" where\n\"wf_clinit ms = (\\<exists>m. (clinit,Static,[],Void,m)\\<in>set ms)\"\n\ndefinition wf_cdecl :: \"'m wf_mdecl_test \\<Rightarrow> 'm prog \\<Rightarrow> 'm cdecl \\<Rightarrow> bool\"\nwhere\n  \"wf_cdecl wf_md P  \\<equiv>  \\<lambda>(C,(D,fs,ms)).\n  (\\<forall>f\\<in>set fs. wf_fdecl P f) \\<and>  distinct_fst fs \\<and>\n  (\\<forall>m\\<in>set ms. wf_mdecl wf_md P C m) \\<and>  distinct_fst ms \\<and>\n  (C \\<noteq> Object \\<longrightarrow>\n   is_class P D \\<and> \\<not> P \\<turnstile> D \\<preceq>\\<^sup>* C \\<and>\n   (\\<forall>(M,b,Ts,T,m)\\<in>set ms.\n      \\<forall>D' b' Ts' T' m'. P \\<turnstile> D sees M,b':Ts' \\<rightarrow> T' = m' in D' \\<longrightarrow>\n                       b = b' \\<and> P \\<turnstile> Ts' [\\<le>] Ts \\<and> P \\<turnstile> T \\<le> T')) \\<and>\n  wf_clinit ms\"\n\ndefinition wf_syscls :: \"'m prog \\<Rightarrow> bool\"\nwhere\n  \"wf_syscls P  \\<equiv>  {Object} \\<union> sys_xcpts \\<subseteq> set(map fst P)\"\n\ndefinition wf_prog :: \"'m wf_mdecl_test \\<Rightarrow> 'm prog \\<Rightarrow> bool\"\nwhere\n  \"wf_prog wf_md P  \\<equiv>  wf_syscls P \\<and> (\\<forall>c \\<in> set P. wf_cdecl wf_md P c) \\<and> distinct_fst P\"\n\n\nsubsection\\<open> Well-formedness lemmas \\<close>\n\nlemma class_wf: \n  \"\\<lbrakk>class P C = Some c; wf_prog wf_md P\\<rbrakk> \\<Longrightarrow> wf_cdecl wf_md P (C,c)\"\n(*<*)by (unfold wf_prog_def class_def) (fast dest: map_of_SomeD)(*>*)\n\n\nlemma class_Object [simp]: \n  \"wf_prog wf_md P \\<Longrightarrow> \\<exists>C fs ms. class P Object = Some (C,fs,ms)\"\n(*<*)by (unfold wf_prog_def wf_syscls_def class_def)\n        (auto simp: map_of_SomeI)\n(*>*)\n\n\nlemma is_class_Object [simp]:\n  \"wf_prog wf_md P \\<Longrightarrow> is_class P Object\"\n(*<*)by (simp add: is_class_def)(*>*)\n\nlemma is_class_supclass:\nassumes wf: \"wf_prog wf_md P\" and sub: \"P \\<turnstile> C \\<preceq>\\<^sup>* D\"\nshows \"is_class P C \\<Longrightarrow> is_class P D\"\n(*<*)\nusing sub proof(induct)\n  case step then show ?case\n    by(auto simp:wf_cdecl_def is_class_def dest!:class_wf[OF _ wf] subcls1D)\nqed simp\n(*>*)\n\nlemma is_class_xcpt:\n  \"\\<lbrakk> C \\<in> sys_xcpts; wf_prog wf_md P \\<rbrakk> \\<Longrightarrow> is_class P C\"\n(*<*)\nby (fastforce intro!: map_of_SomeI\n              simp add: wf_prog_def wf_syscls_def is_class_def class_def)\n(*>*)\n\n\nlemma subcls1_wfD:\nassumes sub1: \"P \\<turnstile> C \\<prec>\\<^sup>1 D\" and wf: \"wf_prog wf_md P\"\nshows \"D \\<noteq> C \\<and> (D,C) \\<notin> (subcls1 P)\\<^sup>+\"\n(*<*)\nproof -\n  obtain fs ms where \"C \\<noteq> Object\" and cls: \"class P C = \\<lfloor>(D, fs, ms)\\<rfloor>\"\n    using subcls1D[OF sub1] by clarify\n  then show ?thesis using wf class_wf[OF cls wf] r_into_trancl[OF sub1]\n    by(force simp add: wf_cdecl_def reflcl_trancl [THEN sym]\n             simp del: reflcl_trancl)\nqed\n(*>*)\n\n\nlemma wf_cdecl_supD: \n  \"\\<lbrakk>wf_cdecl wf_md P (C,D,r); C \\<noteq> Object\\<rbrakk> \\<Longrightarrow> is_class P D\"\n(*<*)by (auto simp: wf_cdecl_def)(*>*)\n\n\nlemma subcls_asym:\n  \"\\<lbrakk> wf_prog wf_md P; (C,D) \\<in> (subcls1 P)\\<^sup>+ \\<rbrakk> \\<Longrightarrow> (D,C) \\<notin> (subcls1 P)\\<^sup>+\"\n(*<*)by(erule tranclE; fast dest!: subcls1_wfD intro: trancl_trans)(*>*)\n\n\nlemma subcls_irrefl:\n  \"\\<lbrakk> wf_prog wf_md P; (C,D) \\<in> (subcls1 P)\\<^sup>+ \\<rbrakk> \\<Longrightarrow> C \\<noteq> D\"\n(*<*)by (erule trancl_trans_induct) (auto dest: subcls1_wfD subcls_asym)(*>*)\n\n\nlemma acyclic_subcls1:\n  \"wf_prog wf_md P \\<Longrightarrow> acyclic (subcls1 P)\"\n(*<*)by (unfold acyclic_def) (fast dest: subcls_irrefl)(*>*)\n\n\nlemma wf_subcls1:\n  \"wf_prog wf_md P \\<Longrightarrow> wf ((subcls1 P)\\<inverse>)\"\n(*<*)\nproof -\n  assume wf: \"wf_prog wf_md P\"\n  have \"finite (subcls1 P)\" by(rule finite_subcls1)\n  then have fin': \"finite ((subcls1 P)\\<inverse>)\" by(subst finite_converse)\n\n  from wf have \"acyclic (subcls1 P)\" by(rule acyclic_subcls1)\n  then have acyc': \"acyclic ((subcls1 P)\\<inverse>)\" by (subst acyclic_converse)\n\n  from fin' acyc' show ?thesis by (rule finite_acyclic_wf)\nqed\n(*>*)\n\n\nlemma single_valued_subcls1:\n  \"wf_prog wf_md G \\<Longrightarrow> single_valued (subcls1 G)\"\n(*<*)\nby(auto simp:wf_prog_def distinct_fst_def single_valued_def dest!:subcls1D)\n(*>*)\n\n\nlemma subcls_induct: \n  \"\\<lbrakk> wf_prog wf_md P; \\<And>C. \\<forall>D. (C,D) \\<in> (subcls1 P)\\<^sup>+ \\<longrightarrow> Q D \\<Longrightarrow> Q C \\<rbrakk> \\<Longrightarrow> Q C\"\n(*<*)\n  (is \"?A \\<Longrightarrow> PROP ?P \\<Longrightarrow> _\")\nproof -\n  assume p: \"PROP ?P\"\n  assume ?A then have wf: \"wf_prog wf_md P\" by assumption\n  have wf':\"wf (((subcls1 P)\\<^sup>+)\\<inverse>)\" using wf_trancl[OF wf_subcls1[OF wf]]\n    by(simp only: trancl_converse)\n  show ?thesis using wf_induct[where a = C and P = Q, OF wf' p] by simp\nqed\n(*>*)\n\n\nlemma subcls1_induct_aux:\nassumes \"is_class P C\" and wf: \"wf_prog wf_md P\" and QObj: \"Q Object\"\nshows\n \"\\<lbrakk> \\<And>C D fs ms.\n    \\<lbrakk> C \\<noteq> Object; is_class P C; class P C = Some (D,fs,ms) \\<and>\n      wf_cdecl wf_md P (C,D,fs,ms) \\<and> P \\<turnstile> C \\<prec>\\<^sup>1 D \\<and> is_class P D \\<and> Q D\\<rbrakk> \\<Longrightarrow> Q C \\<rbrakk>\n  \\<Longrightarrow> Q C\"\n(*<*)\n  (is \"PROP ?P \\<Longrightarrow> _\")\nproof -\n  assume p: \"PROP ?P\"\n  have \"class P C \\<noteq> None \\<longrightarrow> Q C\"\n  proof(induct rule: subcls_induct[OF wf])\n    case (1 C)\n    have \"class P C \\<noteq> None \\<Longrightarrow> Q C\"\n    proof(cases \"C = Object\")\n      case True\n      then show ?thesis using QObj by fast\n    next\n      case False\n      assume nNone: \"class P C \\<noteq> None\"\n      then have is_cls: \"is_class P C\" by(simp add: is_class_def)\n      obtain D fs ms where cls: \"class P C = \\<lfloor>(D, fs, ms)\\<rfloor>\" using nNone by safe\n      also have wfC: \"wf_cdecl wf_md P (C, D, fs, ms)\" by(rule class_wf[OF cls wf])\n      moreover have D: \"is_class P D\" by(rule wf_cdecl_supD[OF wfC False])\n      moreover have \"P \\<turnstile> C \\<prec>\\<^sup>1 D\" by(rule subcls1I[OF cls False])\n      moreover have \"class P D \\<noteq> None\" using D by(simp add: is_class_def)\n      ultimately show ?thesis using 1 by (auto intro: p[OF False is_cls])\n    qed\n  then show \"class P C \\<noteq> None \\<longrightarrow> Q C\" by simp\n  qed\n  thus ?thesis using assms by(unfold is_class_def) simp\nqed\n(*>*)\n\n(* FIXME can't we prove this one directly?? *)\nlemma subcls1_induct [consumes 2, case_names Object Subcls]:\n  \"\\<lbrakk> wf_prog wf_md P; is_class P C; Q Object;\n    \\<And>C D. \\<lbrakk>C \\<noteq> Object; P \\<turnstile> C \\<prec>\\<^sup>1 D; is_class P D; Q D\\<rbrakk> \\<Longrightarrow> Q C \\<rbrakk>\n  \\<Longrightarrow> Q C\"\n(*<*)by (erule (2) subcls1_induct_aux) blast(*>*)\n\n\nlemma subcls_C_Object:\nassumes \"class\": \"is_class P C\" and wf: \"wf_prog wf_md P\"\nshows \"P \\<turnstile> C \\<preceq>\\<^sup>* Object\"\n(*<*)\nusing wf \"class\"\nproof(induct rule: subcls1_induct)\n  case Subcls\n  then show ?case by(simp add: converse_rtrancl_into_rtrancl)\nqed fast\n(*>*)\n\n\nlemma is_type_pTs:\nassumes \"wf_prog wf_md P\" and \"(C,S,fs,ms) \\<in> set P\" and \"(M,b,Ts,T,m) \\<in> set ms\"\nshows \"set Ts \\<subseteq> types P\"\n(*<*)\nproof\n  from assms have \"wf_mdecl wf_md P C (M,b,Ts,T,m)\" \n    by (unfold wf_prog_def wf_cdecl_def) auto\n  hence \"\\<forall>t \\<in> set Ts. is_type P t\" by (unfold wf_mdecl_def) auto\n  moreover fix t assume \"t \\<in> set Ts\"\n  ultimately have \"is_type P t\" by blast\n  thus \"t \\<in> types P\" ..\nqed\n(*>*)\n\nlemma wf_supercls_distinct_app:\nassumes wf:\"wf_prog wf_md P\"\n  and nObj: \"C \\<noteq> Object\" and cls: \"class P C = \\<lfloor>(D, fs, ms)\\<rfloor>\"\n  and super: \"supercls_lst P (C#Cs)\" and dist: \"distinct (C#Cs)\"\nshows \"distinct (D#C#Cs)\"\nproof -\n  have \"\\<not> P \\<turnstile> D \\<preceq>\\<^sup>* C\" using subcls1_wfD[OF subcls1I[OF cls nObj] wf]\n    by (simp add: rtrancl_eq_or_trancl)\n  then show ?thesis using assms by auto\nqed\n\n\nsubsection\\<open> Well-formedness and method lookup \\<close>\n\nlemma sees_wf_mdecl:\nassumes wf: \"wf_prog wf_md P\" and sees: \"P \\<turnstile> C sees M,b:Ts\\<rightarrow>T = m in D\"\nshows \"wf_mdecl wf_md P D (M,b,Ts,T,m)\"\n(*<*)\nusing wf visible_method_exists[OF sees] proof(cases b)\nqed (fastforce simp:wf_cdecl_def dest!:class_wf dest:map_of_SomeD)+\n(*>*)\n\nlemma sees_method_mono [rule_format (no_asm)]: \nassumes sub: \"P \\<turnstile> C' \\<preceq>\\<^sup>* C\" and wf: \"wf_prog wf_md P\"\nshows \"\\<forall>D b Ts T m. P \\<turnstile> C sees M,b:Ts\\<rightarrow>T = m in D \\<longrightarrow>\n     (\\<exists>D' Ts' T' m'. P \\<turnstile> C' sees M,b:Ts'\\<rightarrow>T' = m' in D' \\<and> P \\<turnstile> Ts [\\<le>] Ts' \\<and> P \\<turnstile> T' \\<le> T)\"\n(*<*)\n  (is \"\\<forall>D b Ts T m. ?P C D b Ts T m \\<longrightarrow> ?Q C' D b Ts T m\")\nproof(rule disjE[OF rtranclD[OF sub]])\n  assume \"C' = C\"\n  then show ?thesis using assms by fastforce\nnext\n  assume \"C' \\<noteq> C \\<and> (C', C) \\<in> (subcls1 P)\\<^sup>+\"\n  then have neq: \"C' \\<noteq> C\" and subcls1: \"(C', C) \\<in> (subcls1 P)\\<^sup>+\" by simp+\n  show ?thesis proof(induct rule: trancl_trans_induct[OF subcls1])\n    case (2 x y z)\n    then have zy: \"\\<And>D b Ts T m. ?P z D b Ts T m \\<Longrightarrow> ?Q y D b Ts T m\" by blast\n    have \"\\<And>D b Ts T m. ?P z D b Ts T m \\<Longrightarrow> ?Q x D b Ts T m\"\n    proof -\n      fix D b Ts T m assume P: \"?P z D b Ts T m\"\n      then show \"?Q x D b Ts T m\" using zy[OF P] 2(2)\n        by(fast elim: widen_trans widens_trans)\n    qed\n    then show ?case by blast\n  next\n    case (1 x y)\n    have \"\\<And>D b Ts T m. ?P y D b Ts T m \\<Longrightarrow> ?Q x D b Ts T m\"\n    proof -\n      fix D b Ts T m assume P: \"?P y D b Ts T m\"\n      then obtain Mm where sees: \"P \\<turnstile> y sees_methods Mm\" and\n                           M: \"Mm M = \\<lfloor>((b, Ts, T, m), D)\\<rfloor>\"\n        by(clarsimp simp:Method_def)\n      obtain fs ms where nObj: \"x \\<noteq> Object\" and\n                         cls: \"class P x = \\<lfloor>(y, fs, ms)\\<rfloor>\"\n        using subcls1D[OF 1] by clarsimp\n      have x_meth: \"P \\<turnstile> x sees_methods Mm ++ (map_option (\\<lambda>m. (m, x)) \\<circ> map_of ms)\"\n        using sees_methods_rec[OF cls nObj sees] by simp\n      show \"?Q x D b Ts T m\" proof(cases \"map_of ms M\")\n        case None\n        then have \"\\<exists>m'. P \\<turnstile> x sees M, b :  Ts\\<rightarrow>T = m' in D\" using M x_meth\n          by(fastforce simp add:Method_def map_add_def split:option.split)\n        then show ?thesis by auto\n      next\n        case (Some a)\n        then obtain b' Ts' T' m' where a: \"a = (b',Ts',T',m')\" by(cases a)\n        then have \"(\\<exists>m' Mm. P \\<turnstile> y sees_methods Mm \\<and> Mm M = \\<lfloor>((b, Ts, T, m'), D)\\<rfloor>)\n              \\<longrightarrow> b' = b \\<and> P \\<turnstile> Ts [\\<le>] Ts' \\<and> P \\<turnstile> T' \\<le> T\"\n          using nObj class_wf[OF cls wf] map_of_SomeD[OF Some]\n          by(clarsimp simp: wf_cdecl_def Method_def) fast\n        then show ?thesis using Some a sees M x_meth\n          by(fastforce simp:Method_def map_add_def split:option.split)\n      qed\n    qed\n    then show ?case by simp\n  qed\nqed\n(*>*)\n\n\nlemma sees_method_mono2:\n  \"\\<lbrakk> P \\<turnstile> C' \\<preceq>\\<^sup>* C; wf_prog wf_md P;\n     P \\<turnstile> C sees M,b:Ts\\<rightarrow>T = m in D; P \\<turnstile> C' sees M,b':Ts'\\<rightarrow>T' = m' in D' \\<rbrakk>\n  \\<Longrightarrow> b = b' \\<and> P \\<turnstile> Ts [\\<le>] Ts' \\<and> P \\<turnstile> T' \\<le> T\"\n(*<*)by(blast dest:sees_method_mono sees_method_fun)(*>*)\n\nlemma mdecls_visible:\nassumes wf: \"wf_prog wf_md P\" and \"class\": \"is_class P C\"\nshows \"\\<And>D fs ms. class P C = Some(D,fs,ms)\n         \\<Longrightarrow> \\<exists>Mm. P \\<turnstile> C sees_methods Mm \\<and> (\\<forall>(M,b,Ts,T,m) \\<in> set ms. Mm M = Some((b,Ts,T,m),C))\"\n(*<*)\nusing wf \"class\"\nproof (induct rule:subcls1_induct)\n  case Object\n  with wf have dfst:\"distinct_fst ms\"\n    by (unfold class_def wf_prog_def wf_cdecl_def) (fastforce dest:map_of_SomeD)\n  with dfst have \"distinct_fst ms\"\n    by(blast dest: distinct_fst_appendD)\n  with Object show ?case by(fastforce intro!: sees_methods_Object map_of_SomeI)\nnext\n  case Subcls\n  with wf have dfst:\"distinct_fst ms\"\n    by (unfold class_def wf_prog_def wf_cdecl_def) (fastforce dest:map_of_SomeD)\n  with dfst have \"distinct_fst ms\"\n    by(blast dest: distinct_fst_appendD)\n  with Subcls show ?case\n    by(fastforce elim:sees_methods_rec dest:subcls1D map_of_SomeI\n                simp:is_class_def)\nqed\n(*>*)\n\nlemma mdecl_visible:\nassumes wf: \"wf_prog wf_md P\" and C: \"(C,S,fs,ms) \\<in> set P\" and  m: \"(M,b,Ts,T,m) \\<in> set ms\"\nshows \"P \\<turnstile> C sees M,b:Ts\\<rightarrow>T = m in C\"\n(*<*)\nproof -\n  from wf C have \"class\": \"class P C = Some (S,fs,ms)\"\n    by (auto simp add: wf_prog_def class_def is_class_def intro: map_of_SomeI)\n  from \"class\" have \"is_class P C\" by(auto simp:is_class_def)                   \n  with assms \"class\" show ?thesis\n    by(bestsimp simp:Method_def dest:mdecls_visible)\nqed\n(*>*)\n\n\nlemma Call_lemma:\nassumes sees: \"P \\<turnstile> C sees M,b:Ts\\<rightarrow>T = m in D\" and sub: \"P \\<turnstile> C' \\<preceq>\\<^sup>* C\" and wf: \"wf_prog wf_md P\"\nshows \"\\<exists>D' Ts' T' m'.\n       P \\<turnstile> C' sees M,b:Ts'\\<rightarrow>T' = m' in D' \\<and> P \\<turnstile> Ts [\\<le>] Ts' \\<and> P \\<turnstile> T' \\<le> T \\<and> P \\<turnstile> C' \\<preceq>\\<^sup>* D'\n       \\<and> is_type P T' \\<and> (\\<forall>T\\<in>set Ts'. is_type P T) \\<and> wf_md P D' (M,b,Ts',T',m')\"\n(*<*)\nusing assms sees_method_mono[OF sub wf sees]\nby(fastforce intro:sees_method_decl_above dest:sees_wf_mdecl\n             simp: wf_mdecl_def)\n(*>*)\n\n\nlemma wf_prog_lift:\n  assumes wf: \"wf_prog (\\<lambda>P C bd. A P C bd) P\"\n  and rule:\n  \"\\<And>wf_md C M b Ts C T m bd.\n   wf_prog wf_md P \\<Longrightarrow>\n   P \\<turnstile> C sees M,b:Ts\\<rightarrow>T = m in C \\<Longrightarrow>\n   set Ts \\<subseteq>  types P \\<Longrightarrow>\n   bd = (M,b,Ts,T,m) \\<Longrightarrow>\n   A P C bd \\<Longrightarrow>\n   B P C bd\"\n  shows \"wf_prog (\\<lambda>P C bd. B P C bd) P\"\n(*<*)\nproof -\n  have \"\\<And>c. c\\<in>set P \\<Longrightarrow> wf_cdecl A P c \\<Longrightarrow> wf_cdecl B P c\"\n  proof -\n    fix c assume \"c\\<in>set P\" and \"wf_cdecl A P c\"\n    then show \"wf_cdecl B P c\"\n     using rule[OF wf mdecl_visible[OF wf] is_type_pTs[OF wf]]\n     by (auto simp: wf_cdecl_def wf_mdecl_def)\n  qed\n  then show ?thesis using wf by (clarsimp simp: wf_prog_def)\nqed\n(*>*)\n\nlemma wf_sees_clinit:\nassumes wf:\"wf_prog wf_md P\" and ex: \"class P C = Some a\"\nshows \"\\<exists>m. P \\<turnstile> C sees clinit,Static:[] \\<rightarrow> Void = m in C\"\nproof -\n  from ex obtain D fs ms where \"a = (D,fs,ms)\" by(cases a)\n  then have sP: \"(C, D, fs, ms) \\<in> set P\" using ex map_of_SomeD[of P C a] by(simp add: class_def)\n  then have \"wf_clinit ms\" using assms by(unfold wf_prog_def wf_cdecl_def, auto)\n  then obtain m where sm: \"(clinit, Static, [], Void, m) \\<in> set ms\" by (meson wf_clinit_def)\n  then have \"P \\<turnstile> C sees clinit,Static:[] \\<rightarrow> Void = m in C\"\n    using mdecl_visible[OF wf sP sm] by simp\n  then show ?thesis by(rule exI)\nqed\n(*>*)\n\nlemma wf_sees_clinit1:\nassumes wf:\"wf_prog wf_md P\" and ex: \"class P C = Some a\"\nand \"P \\<turnstile> C sees clinit,b:Ts \\<rightarrow> T = m in D\"\nshows \"b = Static \\<and> Ts = [] \\<and> T = Void \\<and> D = C\"\nproof -\n  obtain m' where sees: \"P \\<turnstile> C sees clinit,Static:[] \\<rightarrow> Void = m' in C\"\n    using wf_sees_clinit[OF wf ex] by clarify\n  then show ?thesis using sees wf by (meson assms(3) sees_method_fun)\nqed\n\nlemma wf_NonStatic_nclinit:\nassumes wf: \"wf_prog wf_md P\" and meth: \"P \\<turnstile> C sees M,NonStatic:Ts\\<rightarrow>T=(mxs,mxl,ins,xt) in D\"\nshows \"M \\<noteq> clinit\"\nproof -\n  from sees_method_is_class[OF meth] obtain a where cls: \"class P C = Some a\"\n    by(clarsimp simp: is_class_def)\n  with wf wf_sees_clinit[OF wf cls]\n   obtain m where \"P \\<turnstile> C sees clinit,Static:[]\\<rightarrow>Void=m in C\" by clarsimp\n  with meth show ?thesis by(auto dest: sees_method_fun)\nqed\n\nsubsection\\<open> Well-formedness and field lookup \\<close>\n\nlemma wf_Fields_Ex:\nassumes wf: \"wf_prog wf_md P\" and \"is_class P C\"\nshows \"\\<exists>FDTs. P \\<turnstile> C has_fields FDTs\"\n(*<*)\nusing assms proof(induct rule:subcls1_induct)\n  case Object\n  then show ?case using class_Object[OF wf]\n    by(blast intro:has_fields_Object)\nnext\n  case Subcls\n  then show ?case by(blast intro:has_fields_rec dest:subcls1D)\nqed\n(*>*)\n\n\nlemma has_fields_types:\n  \"\\<lbrakk> P \\<turnstile> C has_fields FDTs; (FD,b,T) \\<in> set FDTs; wf_prog wf_md P \\<rbrakk> \\<Longrightarrow> is_type P T\"\n(*<*)\nproof(induct rule:Fields.induct)\nqed(fastforce dest!: class_wf simp: wf_cdecl_def wf_fdecl_def)+\n(*>*)\n\nlemma sees_field_is_type:\n  \"\\<lbrakk> P \\<turnstile> C sees F,b:T in D; wf_prog wf_md P \\<rbrakk> \\<Longrightarrow> is_type P T\"\n(*<*)\n  by (meson has_field_def has_fields_types has_visible_field map_of_SomeD)\n(*>*)\n\n\nlemma wf_syscls:\n  \"set SystemClasses \\<subseteq> set P \\<Longrightarrow> wf_syscls P\"\n(*<*)\nby (force simp: image_def SystemClasses_def wf_syscls_def sys_xcpts_def\n                ObjectC_def NullPointerC_def ClassCastC_def OutOfMemoryC_def\n                NoClassDefFoundC_def\n                IncompatibleClassChangeC_def NoSuchFieldC_def NoSuchMethodC_def)\n(*>*)\n\n\nsubsection\\<open> Well-formedness and subclassing \\<close>\n\nlemma wf_subcls_nCls:\nassumes wf: \"wf_prog wf_md P\" and ns: \"\\<not> is_class P C\"\nshows \"\\<lbrakk> P \\<turnstile> D \\<preceq>\\<^sup>* D'; D \\<noteq> C \\<rbrakk> \\<Longrightarrow> D' \\<noteq> C\"\nproof(induct rule: rtrancl.induct)\n  case (rtrancl_into_rtrancl a b c)\n  with ns show ?case by(clarsimp dest!: subcls1D wf_cdecl_supD[OF class_wf[OF _ wf]])\nqed(simp)\n\nlemma wf_subcls_nCls':\nassumes wf: \"wf_prog wf_md P\" and ns: \"\\<not>is_class P C\\<^sub>0\"\nshows \"\\<And>cd D'. cd \\<in> set P \\<Longrightarrow> \\<not>P \\<turnstile> fst cd \\<preceq>\\<^sup>* C\\<^sub>0\"\nproof -\n  fix cd D' assume cd: \"cd \\<in> set P\"\n  then have cls: \"is_class P (fst cd)\" using class_exists_equiv is_class_def by blast\n  with wf_subcls_nCls[OF wf ns] ns show \"\\<not>P \\<turnstile> fst cd \\<preceq>\\<^sup>* C\\<^sub>0\" by(cases \"fst cd = D'\", auto)\nqed\n\nlemma wf_nclass_nsub:\n \"\\<lbrakk> wf_prog wf_md P; is_class P C; \\<not>is_class P C' \\<rbrakk> \\<Longrightarrow> \\<not>P \\<turnstile> C \\<preceq>\\<^sup>* C'\"\n by(rule notI, auto dest: wf_subcls_nCls[where C=C' and D=C])\n\nlemma wf_sys_xcpt_nsub_Start:\nassumes wf: \"wf_prog wf_md P\" and ns: \"\\<not>is_class P Start\" and sx: \"C \\<in> sys_xcpts\"\nshows \"\\<not>P \\<turnstile> C \\<preceq>\\<^sup>* Start\"\nproof -\n  have Cns: \"C \\<noteq> Start\" using Start_nsys_xcpts sx by clarsimp\n  show ?thesis using wf_subcls_nCls[OF wf ns _ Cns] by auto\nqed\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/JinjaDCI/Common/WellForm.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185351961015, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.265344183796649}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      ClosureEx.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2006-2008 Norbert Schirmer\nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\ntheory ClosureEx\nimports \"../Vcg\" \"../Simpl_Heap\" Closure\nbegin\n\n\nrecord globals =\n cnt_' :: \"ref \\<Rightarrow> nat\"\n alloc_' :: \"ref list\"\n free_' :: \"nat\"\nrecord 'g vars = \"'g state\" +\n p_':: ref\n r_':: nat\n n_':: nat\n m_':: nat\n c_':: \"(string \\<times> ref) list \\<times> string\"\n d_':: \"(string \\<times> ref) list \\<times> string\"\n e_':: \"(string \\<times> nat) list \\<times> string\"\n\n\ndefinition \"var\\<^sub>n = [''n''\\<mapsto> (\\<lambda>x. n_'_update (\\<lambda>_. x)),\n                    ''m''\\<mapsto> (\\<lambda>x. m_'_update (\\<lambda>_. x))]\"\ndefinition \"upd\\<^sub>n = gen_upd var\\<^sub>n\"\n\nlemma upd\\<^sub>n_ap: \"upd\\<^sub>n (fst (ap es (es',p))) = upd\\<^sub>n es' \\<circ> upd\\<^sub>n es\"\n  by (simp add: upd\\<^sub>n_def gen_upd_ap)\n\n\nlemma\n\"\\<Gamma>\\<turnstile>\\<lbrace>\\<acute>n=n\\<^sub>0 \\<and> (\\<forall>i j. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>n=i \\<and> \\<acute>m=j\\<rbrace> callClosure upd\\<^sub>n \\<acute>e \\<lbrace>\\<acute>r=i + j\\<rbrace>)\\<rbrace>\n      \\<acute>e :== (ap [(''n'',\\<acute>n)] \\<acute>e)\n   \\<lbrace>\\<forall>j. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>m=j\\<rbrace> callClosure upd\\<^sub>n \\<acute>e \\<lbrace>\\<acute>r=n\\<^sub>0 + j\\<rbrace>\\<rbrace>\"\napply vcg_step\napply clarify\napply (rule ap_closure [where var=var\\<^sub>n, folded upd\\<^sub>n_def])\napply clarsimp\napply (rename_tac s s')\napply (erule_tac x=\"n_' s\" in allE)\napply (erule_tac x=\"m_' s'\" in allE)\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply (assumption)\napply (simp add: upd\\<^sub>n_def gen_upd_def var\\<^sub>n_def)\ndone\n\n\ndefinition \"var = [''p''\\<mapsto> (\\<lambda>x. p_'_update (\\<lambda>_. x))]\"\ndefinition \"upd = gen_upd var\"\n\nprocedures Inc(p|r) =\n \"\\<acute>p\\<rightarrow>\\<acute>cnt :== \\<acute>p\\<rightarrow>\\<acute>cnt + 1;;\n  \\<acute>r :== \\<acute>p\\<rightarrow>\\<acute>cnt\"\n\nlemma (in Inc_impl)\n \"\\<forall>i p. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>p\\<rightarrow>\\<acute>cnt = i\\<rbrace> \\<acute>r :== PROC Inc(\\<acute>p) \\<lbrace>\\<acute>r=i+1 \\<and> \\<acute>p\\<rightarrow>\\<acute>cnt = i+1\\<rbrace>\"\n  apply vcg\n  apply simp\n  done\n\nprocedures (imports Inc_signature) NewCounter(|c) =\n\"\\<acute>p :== NEW 1 [\\<acute>cnt :== 0];;\n \\<acute>c :== ([(''p'',\\<acute>p)],Inc_'proc)\"\n\n\nlocale NewCounter_impl' = NewCounter_impl + Inc_impl\nlemma (in NewCounter_impl')\nshows\n  \"\\<forall>alloc. \\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free\\<rbrace> \\<acute>c :== PROC NewCounter()\n          \\<lbrace>\\<exists>p. p\\<rightarrow>\\<acute>cnt = 0 \\<and>\n               (\\<forall>i. \\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = i\\<rbrace> callClosure upd \\<acute>c \\<lbrace>\\<acute>r=i+1 \\<and> p\\<rightarrow>\\<acute>cnt = i+1\\<rbrace>)\\<rbrace>\"\napply vcg\napply simp\napply (rule_tac x=\"new (set alloc)\" in exI)\napply simp\napply (simp add: callClosure_def)\napply vcg_step\napply vcg_step\napply vcg_step\napply vcg_step\napply (simp add: upd_def var_def gen_upd_def)\ndone\n\nlemma (in NewCounter_impl')\n\nshows\n  \"\\<forall>alloc. \\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free\\<rbrace> \\<acute>c :== PROC NewCounter()\n          \\<lbrace>\\<exists>p. p\\<rightarrow>\\<acute>cnt = 0 \\<and>\n               (\\<forall>i. \\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = i\\<rbrace> callClosure upd \\<acute>c \\<lbrace>\\<acute>r=i+1 \\<and> p\\<rightarrow>\\<acute>cnt = i+1\\<rbrace>)\\<rbrace>\"\napply vcg\napply simp\napply (rule_tac x=\"new (set alloc)\" in exI)\napply simp\napply (simp add: callClosure_def)\napply vcg_step\napply vcg_step\napply vcg_step\napply vcg_step\napply (simp add: upd_def var_def gen_upd_def)\ndone\n\nlemma (in NewCounter_impl')\nshows NewCounter_spec:\n  \"\\<forall>alloc. \\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free \\<and> \\<acute>alloc=alloc\\<rbrace> \\<acute>c :== PROC NewCounter()\n          \\<lbrace>\\<exists>p. p \\<notin> set alloc \\<and> p \\<in> set \\<acute>alloc \\<and> p \\<noteq> Null \\<and> p\\<rightarrow>\\<acute>cnt = 0 \\<and>\n               (\\<forall>i. \\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = i\\<rbrace> callClosure upd \\<acute>c \\<lbrace>\\<acute>r=i+1 \\<and> p\\<rightarrow>\\<acute>cnt = i+1\\<rbrace>)\\<rbrace>\"\napply vcg\napply clarsimp\napply (rule_tac x=\"new (set alloc)\" in exI)\napply simp\napply (simp add: callClosure_def)\napply vcg_step\napply vcg_step\napply vcg_step\napply vcg_step\napply (simp add: upd_def var_def gen_upd_def)\ndone\n\n\n\nlemma \"\\<Gamma>\\<turnstile>\\<lbrace>\\<exists>p. p \\<noteq> Null \\<and> p\\<rightarrow>\\<acute>cnt = i \\<and>\n              (\\<forall>i. \\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = i\\<rbrace> callClosure upd \\<acute>c \\<lbrace>\\<acute>r=i+1 \\<and> p\\<rightarrow>\\<acute>cnt = i+1\\<rbrace>)\\<rbrace>\n           dynCallClosure (\\<lambda>s. s) upd c_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>)\n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>r_' := r_' t\\<rparr>))\n           \\<lbrace>\\<acute>r=i+1\\<rbrace>\"\napply (rule conseq_extract_pre)\napply clarify\napply (rule dynCallClosureFix)\napply (simp only: Ball_def)\nprefer 3\napply (assumption)\nprefer 2\napply vcg_step\napply vcg_step\napply (simp only: simp_thms)\napply clarsimp\ndone\n\nlemma (in NewCounter_impl')\n shows \"\\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free\\<rbrace>\n             \\<acute>c :== CALL NewCounter ();;\n             dynCallClosure (\\<lambda>s. s) upd c_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>)\n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>r_' := r_' t\\<rparr>))\n           \\<lbrace>\\<acute>r=1\\<rbrace>\"\napply vcg_step\napply (rule dynCallClosure)\nprefer 2\napply vcg_step\napply vcg_step\napply vcg_step\napply clarsimp\napply (erule_tac x=0 in allE)\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply (assumption)\napply simp\ndone\n\n\nlemma (in NewCounter_impl')\n shows \"\\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free\\<rbrace>\n             \\<acute>c :== CALL NewCounter ();;\n             dynCallClosure (\\<lambda>s. s) upd c_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>)\n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>r_' := r_' t\\<rparr>));;\n             dynCallClosure (\\<lambda>s. s) upd c_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>)\n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>r_' := r_' t\\<rparr>))\n           \\<lbrace>\\<acute>r=2\\<rbrace>\"\napply vcg_step\napply (rule dynCallClosure)\nprefer 2\napply vcg_step\napply vcg_step\napply vcg_step\napply (rule dynCallClosure)\napply vcg_step\napply vcg_step\napply vcg_step\n\napply clarsimp\napply (subgoal_tac \"\\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = 0\\<rbrace> callClosure upd (c_' t) \\<lbrace>\\<acute>r = Suc 0 \\<and> p\\<rightarrow>\\<acute>cnt = Suc 0\\<rbrace>\")\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply assumption\napply clarsimp\napply (erule_tac x=1 in allE)\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply assumption\napply clarsimp\napply (erule allE)\napply assumption\ndone\n\n\nlemma (in NewCounter_impl')\n shows \"\\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free\\<rbrace>\n             \\<acute>c :== CALL NewCounter ();;\n             \\<acute>d :== \\<acute>c;;\n             dynCallClosure (\\<lambda>s. s) upd c_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>)\n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>n_' := r_' t\\<rparr>));;\n             dynCallClosure (\\<lambda>s. s) upd d_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>)\n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>m_' := r_' t\\<rparr>));;\n             \\<acute>r :== \\<acute>n + \\<acute>m\n           \\<lbrace>\\<acute>r=3\\<rbrace>\"\n\napply vcg_step\napply vcg_step\napply (rule dynCallClosure)\nprefer 2\napply vcg_step\napply vcg_step\napply vcg_step\napply (rule dynCallClosure)\napply vcg_step\napply vcg_step\napply vcg_step\napply vcg_step\napply clarsimp\napply (subgoal_tac \"\\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = 0\\<rbrace> callClosure upd (c_' t) \\<lbrace>\\<acute>r = Suc 0 \\<and> p\\<rightarrow>\\<acute>cnt = Suc 0\\<rbrace>\")\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply assumption\napply clarsimp\napply (erule_tac x=1 in allE)\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply assumption\napply clarsimp\napply (erule allE)\napply assumption\ndone\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/c-parser/Simpl/ex/ClosureEx.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185351961015, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.265344183796649}}
{"text": "theory PhiSem_Mem_OO\n  imports PhiSem_OO_Class_Algebra\nbegin\n\nchapter \\<open>Object Oriented Programming Model\\<close>\n\nsection \\<open>Semantics & Fictions\\<close>\n\nsubsection \\<open>Models\\<close>\n\n(*not ready to use*)\n\nsubsubsection \\<open>Type\\<close>\n\nvirtual_datatype \\<phi>OO_ty =\n  T_ref :: unit\n\ndebt_axiomatization T_ref :: \\<open>unit type_entry\\<close>\n  where \\<phi>OO_ty_ax: \\<open>\\<phi>OO_ty TY_CONS_OF T_ref\\<close>\n\ninterpretation \\<phi>OO_ty TY_CONS_OF \\<open>TYPE(TY_N)\\<close> \\<open>TYPE(TY)\\<close> T_ref using \\<phi>OO_ty_ax .\n\n(*does user really need to input the semantic type manually?*)\nabbreviation \\<open>reference \\<equiv> T_ref.mk ()\\<close>\n\n\nsubsubsection \\<open>Value\\<close>\n\ndeclare [[typedef_overloaded]]\n\ndatatype object_ref = object_ref (\"class\": \\<open>class\\<close>) (\"instance_id\": nat) | Nil\nhide_const (open) \"class\" instance_id\n\nlemma object_ref_all:\n  \\<open>All P \\<longleftrightarrow> (\\<forall>cls i. P (object_ref cls i)) \\<and> P Nil\\<close>\n  by (metis object_ref.exhaust)\n\nlemma object_ref_ex:\n  \\<open>Ex P \\<longleftrightarrow> (\\<exists>cls i. P (object_ref cls i)) \\<or> P Nil\\<close>\n  by (metis object_ref.exhaust)\n\n\ndeclare [[typedef_overloaded = false]]\n\n\nparagraph \\<open>Properties\\<close>\n\nprimrec of_class\n  where \\<open>of_class cls (object_ref cls' _) \\<longleftrightarrow> cls = cls'\\<close>\n  | \\<open>of_class _ Nil \\<longleftrightarrow> True\\<close>\n\ninstantiation object_ref :: zero begin\ndefinition \\<open>zero_object_ref = Nil\\<close>\ninstance ..\nend\n\n\nparagraph \\<open>The Model\\<close>\n\nvirtual_datatype \\<phi>OO_val =\n  V_ref :: \\<open>object_ref\\<close>\n\ndebt_axiomatization V_ref :: \\<open>object_ref value_entry\\<close>\n  where \\<phi>OO_val_ax: \\<open>\\<phi>OO_val VAL_CONS_OF V_ref\\<close>\n\ninterpretation \\<phi>OO_val VAL_CONS_OF \\<open>TYPE(VAL_N)\\<close> \\<open>TYPE(VAL)\\<close> V_ref using \\<phi>OO_val_ax .\n\ndebt_axiomatization\n        WT_ref[simp]: \\<open>Well_Type reference = UNIV\\<close>\n  and   zero_ref[simp]: \\<open>Zero reference = Some (V_ref.mk Nil)\\<close>\n  and   Can_EqCompare_ref[simp]: \\<open>Can_EqCompare res (V_ref.mk ref1) (V_ref.mk ref2)\\<close>\n  and   EqCompare_ref[simp]:     \\<open>EqCompare (V_ref.mk ref1) (V_ref.mk ref2) \\<longleftrightarrow> ref1 = ref2\\<close>\n\n\n\nsubsubsection \\<open>Resource\\<close>\n\ntype_synonym object_heap = \\<open>(object_ref \\<Rightarrow> field_name \\<Rightarrow> VAL nosep option)\\<close>\n\ndefinition \\<open>Valid_Objs = {h::object_heap. h Nil = 1} \\<inter> {h. finite (dom1 h)}\n       \\<inter> {h. (\\<forall>cls id. dom (h (object_ref cls id)) = {} \\<or>\n                       dom (h (object_ref cls id)) = dom (class.fields_of cls) ) }\\<close>\n\nlemma In_Valid_Objs[simp]:\n  \\<open>h \\<in> Valid_Objs \\<longleftrightarrow> h Nil = 1 \\<and> finite (dom1 h) \\<and>\n     ((\\<forall>cls id. dom (h (object_ref cls id)) = {} \\<or> dom (h (object_ref cls id)) = dom (class.fields_of cls) ))\\<close>\n  unfolding Valid_Objs_def by simp\n\nresource_space \\<phi>OO =\n  Objs :: \\<open>Valid_Objs\\<close> (partial_map_resource2)\n  by (standard; simp)\n\nlemma objref_infinite_cls:\n  \\<open>infinite {a. a \\<noteq> Nil \\<and> object_ref.class a = cls}\\<close>\n  using inj_on_finite[where A = \\<open>UNIV::nat set\\<close> and B = \\<open>{a. a \\<noteq> Nil \\<and> object_ref.class a = cls}\\<close>\n        and f = \\<open>\\<lambda>n. object_ref cls n\\<close>]\n  using inj_def by fastforce\n\nlemma Sep_Closed_Valid_Objs[simp]:\n  \\<open>Sep_Closed Valid_Objs\\<close>\n  unfolding Valid_Objs_def\n  apply (rule Sep_Closed_inter, rule Sep_Closed_inter)\n  apply (simp add: Sep_Closed_def times_fun)\n   apply simp\n  apply simp\n  apply (rule Sep_Closed_pointwise[where P=\\<open>\\<lambda>k v.\n          case k of object_ref cls i \\<Rightarrow> dom v = {} \\<or> dom v = dom (class.fields_of cls)\n                  | _ \\<Rightarrow> True\\<close>,\n      simplified object_ref_all, simplified])\n  apply (clarsimp simp add: dom_mult one_partial_map[symmetric])\n  by (metis dom_1 sup.idem sup_bot.right_neutral sup_commute)\n\n\n(*\nlemma Valid_Objs_1[simp]: \\<open>1 \\<in> Valid_Objs\\<close>\n  unfolding Valid_Objs_def one_fun_def by (simp add: dom1_def one_fun_def)\n*)\n\nlemma obj_map_freshness:\n  \\<open>finite (dom1 f) \\<Longrightarrow> \\<exists>k. f k = 1 \\<and> k \\<noteq> Nil \\<and> object_ref.class k = cls\\<close>\n  unfolding dom1_def\n  by (metis (mono_tags, lifting) finite_subset mem_Collect_eq objref_infinite_cls subsetI)\n\n\n\nfiction_space \\<phi>OO_fic =\n  OO_share :: RES.Objs.share_fiction (share_fiction_for_partial_mapping_resource2 RES.Objs) ..\n\nlemma \"__case_prod_ref_field__\":\n  \\<open>(\\<lambda>(x, y). (1(ref := 1(field \\<mapsto> n \\<Znrres> v))) x y) = 1((ref,field) \\<mapsto> n \\<Znrres> v)\\<close>\n  unfolding fun_eq_iff by simp\n\n\nsection \\<open>\\<phi>Types\\<close>\n\nsubsection \\<open>Reference\\<close>\n\n(*Do we really need the class annotation here?*)\n\ndefinition Ref :: \\<open>class \\<Rightarrow> (VAL, object_ref) \\<phi>\\<close>\n  where \\<open>Ref cls ref = ({ V_ref.mk ref } \\<s>\\<u>\\<b>\\<j> of_class cls ref)\\<close>\n\nlemma \\<phi>Ref_expns[\\<phi>expns]:\n  \\<open>v \\<in> (ref \\<Ztypecolon> Ref cls) \\<longleftrightarrow> v = V_ref.mk ref \\<and> of_class cls ref\\<close>\n  unfolding Ref_def \\<phi>Type_def by (simp add: \\<phi>expns)\n\nlemma \\<phi>Ref_inhabited[\\<phi>inhabitance_rule, elim!]:\n  \\<open>Inhabited (ref \\<Ztypecolon> Ref cls) \\<Longrightarrow> (of_class cls ref \\<Longrightarrow> C) \\<Longrightarrow> C\\<close>\n  unfolding Inhabited_def by (simp add: \\<phi>expns)\n\nlemma \\<phi>Ref_zero[\\<phi>reason 1000]:\n  \\<open>\\<phi>Zero reference (Ref cls) Nil\\<close>\n  unfolding \\<phi>Zero_def by (simp add: \\<phi>expns)\n\nlemma \\<phi>Ref_eq[\\<phi>reason 1000]:\n  \\<open>\\<phi>Equal (Ref cls) (\\<lambda>_ _. True) (=)\\<close>\n  unfolding \\<phi>Equal_def by (simp add: \\<phi>expns)\n\nlemma \\<phi>Ref_semty[\\<phi>reason 1000]:\n  \\<open>\\<phi>SemType (ref \\<Ztypecolon> Ref cls) reference\\<close>\n  unfolding \\<phi>SemType_def by (simp add: \\<phi>expns)\n\n\nsubsection \\<open>Object\\<close>\n\nparagraph \\<open>Fields in A Object\\<close>\n\nnotation FIC.OO_share.\\<phi> (\"obj: _\" [52] 51)\n\nsection \\<open>Instructions\\<close>\n\nparagraph \\<open>Reference Value\\<close>\n\n(* definition \\<open>\\<phi>M_getV_ref v F = \\<phi>M_getV reference V_ref.dest v F\\<close> *)\n\nparagraph \\<open>Allocation\\<close>\n\ndefinition initial_value_of_class\n  where \\<open>initial_value_of_class cls = map_option (map_nosep (the o Zero)) o class.fields_of cls\\<close>\n\nlemma dom_initial_value_of_class:\n  \\<open>dom (initial_value_of_class cls) = dom (class.fields_of cls)\\<close>\n  unfolding initial_value_of_class_def dom_def set_eq_iff by simp\n\ndefinition op_obj_allocate :: \\<open>class \\<Rightarrow> VAL proc\\<close>\n  where \\<open>op_obj_allocate cls =\n      RES.Objs.\\<phi>R_allocate_res_entry (\\<lambda>ref. ref \\<noteq> Nil \\<and> object_ref.class ref = cls)\n            (initial_value_of_class cls) (\\<lambda>ref. Return (\\<phi>arg (V_ref.mk ref)))\\<close>\n\n\nparagraph \\<open>Load Field\\<close>\n\ndefinition op_obj_load_field :: \\<open>field_name \\<Rightarrow> TY \\<Rightarrow> (VAL,VAL) proc'\\<close>\n  where \\<open>op_obj_load_field field TY v =\n    \\<phi>M_getV reference V_ref.dest v (\\<lambda>ref.\n    RES.Objs.\\<phi>R_get_res_entry ref field (\\<lambda>v.\n    \\<phi>M_assert (nosep.dest v \\<in> Well_Type TY) \\<ggreater>\n    Return (\\<phi>arg (nosep.dest v))))\\<close>\n\n\nparagraph \\<open>Store Field\\<close>\n\ndefinition op_obj_store_field :: \\<open>field_name \\<Rightarrow> TY \\<Rightarrow> (VAL \\<times> VAL, unit) proc'\\<close>\n  where \\<open>op_obj_store_field field TY =\n    \\<phi>M_caseV (\\<lambda>vstore vref.\n    \\<phi>M_getV TY id vstore (\\<lambda>store.\n    \\<phi>M_getV reference V_ref.dest vref (\\<lambda>ref.\n    RES.Objs.\\<phi>R_get_res_entry ref field (\\<lambda>v. \\<phi>M_assert (nosep.dest v \\<in> Well_Type TY))\n \\<ggreater> RES.Objs.\\<phi>R_set_res (map_fun_at (map_fun_at (\\<lambda>_. Some (nosep store)) field) ref)\n)))\\<close>\n\nparagraph \\<open>Dispose\\<close>\n\ndefinition op_obj_dispose :: \\<open>class \\<Rightarrow> (VAL, unit) proc'\\<close>\n  where \\<open>op_obj_dispose cls vref =\n    \\<phi>M_getV reference V_ref.dest vref (\\<lambda>ref.\n    RES.Objs.\\<phi>R_get_res (\\<lambda>m.\n    \\<phi>M_assert ((ref \\<in> dom1 m \\<or> class.fields_of cls = 1) \\<and> object_ref.class ref = cls))\n \\<ggreater> RES.Objs.\\<phi>R_set_res (\\<lambda>f. f(ref := 1))\n)\\<close>\n\n\nsection \\<open>Specification of Instructions\\<close>\n\nparagraph \\<open>Reference Value\\<close>\n\nlemma \\<phi>M_getV_ref:\n  \\<open> (of_class cls ref \\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> F ref \\<lbrace> X \\<longmapsto> Y \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E)\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> \\<phi>M_getV reference V_ref.dest raw F \\<lbrace> X\\<heavy_comma> ref \\<Ztypecolon> Val raw (Ref cls) \\<longmapsto> Y \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\\<close>\n  by (cases raw; simp; rule; simp add: \\<phi>expns)\n\n\nparagraph \\<open>Allocation\\<close>\n\nlemma op_obj_allocate:\n  \\<open>\\<p>\\<r>\\<o>\\<c> op_obj_allocate cls\n      \\<lbrace> Void \\<longmapsto> \\<lambda>ret. \\<exists>*ref. to_share o initial_value_of_class cls \\<Ztypecolon> obj: ref \\<^bold>\\<rightarrow> Identity\\<heavy_comma> ref \\<Ztypecolon> Val ret (Ref cls) \\<rbrace>\\<close>\n  unfolding \\<phi>Procedure_Hybrid_DL op_obj_allocate_def\n  apply (clarsimp simp add: \\<phi>expns del: subsetI)\n  apply (rule RES.Objs.\\<phi>R_allocate_res_entry)\n  apply (clarsimp)\n  using obj_map_freshness apply blast\n  \n  apply (clarsimp simp add: one_fun_def dom_initial_value_of_class)\n\n  prefer 2 apply assumption\n\n  apply (simp add: \\<phi>expns Return_def det_lift_def del: set_mult_expn)\n  subgoal premises prems for r res k res' proof -\n    have t: \\<open>of_class cls k\\<close>\n      by (metis object_ref.collapse of_class.simps(1) prems(3))\n    show ?thesis\n      using t FIC.OO_share.expand[where x=\\<open>1(k := initial_value_of_class cls)\\<close>, simplified] prems\n      using FIC.OO_share.sep_disj_fiction by fastforce\n  qed .\n\nparagraph \\<open>Load Field\\<close>\n\nlemma op_obj_load_field_raw_\\<phi>app:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> v \\<in> Well_Type TY\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_obj_load_field field TY raw \\<lbrace>\n      nosep v \\<Ztypecolon> obj: ref \\<^bold>\\<rightarrow> field \\<^bold>\\<rightarrow> n \\<Znrres> \\<coercion> Identity \\<heavy_comma> ref \\<Ztypecolon> \\<v>\\<a>\\<l>[raw] (Ref cls)\n  \\<longmapsto> nosep v \\<Ztypecolon> obj: ref \\<^bold>\\<rightarrow> field \\<^bold>\\<rightarrow> n \\<Znrres> \\<coercion> Identity \\<heavy_comma> \\<v>\\<a>\\<l> v \\<Ztypecolon> Identity\n\\<rbrace>\\<close>\n  unfolding op_obj_load_field_def Premise_def\n  by (rule \\<phi>M_getV_ref, rule, rule \\<phi>SEQ, rule \\<phi>M_assert, simp, rule, simp add: Identity_expn)\n\nproc (nodef) op_obj_load_field:\n  assumes A: \\<open>\\<phi>SemType (x \\<Ztypecolon> T) TY\\<close>\n  input  \\<open>x \\<Ztypecolon> obj: ref \\<^bold>\\<rightarrow> field \\<^bold>\\<rightarrow> n \\<Znrres> \\<coercion> T \\<heavy_comma> ref \\<Ztypecolon> Val raw (Ref cls)\\<close>\n  output \\<open>x \\<Ztypecolon> obj: ref \\<^bold>\\<rightarrow> field \\<^bold>\\<rightarrow> n \\<Znrres> \\<coercion> T \\<heavy_comma> \\<v>\\<a>\\<l> x \\<Ztypecolon> T\\<close>\n  \\<medium_left_bracket> \\<open>obj: _\\<close> to Identity \\<exists>v\n  have [simp]: \\<open>v \\<in> Well_Type TY\\<close> using A[unfolded \\<phi>SemType_def subset_iff] \\<phi> by blast  \n  ;; $ref op_obj_load_field_raw[where TY=TY]\n  \\<medium_right_bracket> by (simp add: Nosep_expns the_\\<phi>lemmata) .\n  \n\nparagraph \\<open>Store Field\\<close>\n\nlemma op_obj_store_field_raw_\\<phi>app:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> v \\<in> Well_Type TY\n\\<Longrightarrow> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> u \\<in> Well_Type TY\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_obj_store_field field TY (\\<phi>V_pair rawu rawref) \\<lbrace>\n      nosep v \\<Ztypecolon> obj: ref \\<^bold>\\<rightarrow> field \\<^bold>\\<rightarrow> \\<coercion> Identity \\<heavy_comma> ref \\<Ztypecolon> Val rawref (Ref cls)\\<heavy_comma> u \\<Ztypecolon> Val rawu Identity\n  \\<longmapsto> nosep u \\<Ztypecolon> obj: ref \\<^bold>\\<rightarrow> field \\<^bold>\\<rightarrow> \\<coercion> Identity\n\\<rbrace>\\<close>\n  unfolding op_obj_store_field_def Premise_def\n  apply (cases rawref; cases rawu; simp, rule, rule, simp add: Identity_expn Premise_def,\n          rule \\<phi>M_getV_ref, rule, rule, rule \\<phi>M_assert, simp, simp add: Identity_expn)\n  apply (rule FIC.OO_share.\\<phi>R_set_res[where P=\"\\<lambda>m. field \\<in> dom (m ref)\"])\n  apply (cases ref; clarsimp simp add: map_fun_at_def dom1_def)\n  apply (smt (verit, del_insts) Collect_cong dom_1 dom_eq_empty_conv insert_dom option.distinct(1))\n  using RES.Objs.raw_unit_assertion_implies by blast\n\n\nproc (nodef) op_obj_store_field:\n  assumes A: \\<open>\\<phi>SemType (x \\<Ztypecolon> T) TY\\<close>\n  assumes B: \\<open>\\<phi>SemType (y \\<Ztypecolon> U) TY\\<close>\n  input  \\<open>x \\<Ztypecolon> obj: ref \\<^bold>\\<rightarrow> field \\<^bold>\\<rightarrow> \\<coercion> T \\<heavy_comma> \\<v>\\<a>\\<l> ref \\<Ztypecolon> Ref cls \\<heavy_comma> \\<v>\\<a>\\<l> y \\<Ztypecolon> U\\<close>\n  output \\<open>y \\<Ztypecolon> obj: ref \\<^bold>\\<rightarrow> field \\<^bold>\\<rightarrow> \\<coercion> U\\<close>\n  \\<medium_left_bracket> to Identity \\<exists>u\n    \\<open>obj: _\\<close> to Identity \\<exists>v\n    op_obj_store_field_raw[where TY=TY]\n      affirm using A[unfolded \\<phi>SemType_def subset_iff] \\<phi> by blast ;;\n      affirm using B[unfolded \\<phi>SemType_def subset_iff] \\<phi> by blast\n  \\<medium_right_bracket> by (simp add: Nosep_expns the_\\<phi>lemmata) .\n\n\nparagraph \\<open>Dispose\\<close>\n\nlemma op_obj_dispose:\n  \\<open> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> ref \\<noteq> Nil\n\\<Longrightarrow> \\<p>\\<r>\\<e>\\<m>\\<i>\\<s>\\<e> dom fields = dom (class.fields_of cls)\n\\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> op_obj_dispose cls rawv\n    \\<lbrace> to_share o fields \\<Ztypecolon> obj: ref \\<^bold>\\<rightarrow> Identity \\<heavy_comma> ref \\<Ztypecolon> Val rawv (Ref cls) \\<longmapsto> \\<lambda>ret. Void \\<rbrace>\\<close>\n  unfolding op_obj_dispose_def Premise_def\n  apply (rule \\<phi>M_getV_ref)\n  apply (rule \\<phi>SEQ[where B=\\<open>\\<lambda>_. to_share \\<circ> fields \\<Ztypecolon> obj: ref \\<^bold>\\<rightarrow> Identity\\<close>])\n  apply (clarsimp simp add: \\<phi>expns zero_set_def \\<phi>Procedure_Hybrid_DL del: subsetI)\n  apply (rule RES.Objs.\\<phi>R_get_res, simp, simp add: dom1_def)\n  subgoal premises prems for r res proof -\n    have t1: \\<open>object_ref.class ref = cls\\<close>\n      by (metis object_ref.collapse of_class.simps(1) prems(1) prems(3))\n    have t3: \\<open>fields = Map.empty \\<Longrightarrow> class.fields_of cls = Map.empty\\<close> \n      subgoal premises prem proof -\n        have \\<open>dom fields = {}\\<close> by (simp add: prem)\n        then have \\<open>dom (class.fields_of cls) = {}\\<close> using prems(2) by simp\n        then show ?thesis by fastforce\n      qed .\n    have t4: \\<open>r ## FIC.OO_share.mk (1(ref := to_share \\<circ> fields))\\<close>\n      using prems(6) by blast\n    have t2: \\<open>RES.Objs.get res ref = 1 \\<Longrightarrow> class.fields_of cls = 1\\<close>\n      unfolding one_fun_def one_option_def\n      apply (cases \\<open>fields = Map.empty\\<close>)\n      using t3 apply blast\n      using FIC.OO_share.partial_implies[where x=\\<open>1(ref := fields)\\<close> and n=1, simplified,\n            OF \\<open>r \\<in> FIC.SPACE\\<close>, OF t4, OF \\<open>\\<s>\\<t>\\<a>\\<t>\\<e> res \\<i>\\<s> _\\<close>]\n            nonsepable_partial_map_subsumption_L2\n      by (metis domIff map_le_def)\n    show ?thesis by (simp add: t1 t2 prems Return_def det_lift_def)\n  qed\n  apply (rule FIC.OO_share.\\<phi>R_dispose_res[where P=\\<open>\\<lambda>_. True\\<close>])\n  apply (clarsimp simp add: one_fun_def)\n  apply (cases ref; simp)\n  using RES.Objs.get_res_Valid[simplified Valid_Objs_def, simplified]\n    RES.Objs.raw_unit_assertion_implies'[where f=fields]\n  by (smt (z3) domIff map_le_antisym map_le_def)\n\nend\n", "meta": {"author": "xqyww123", "repo": "phi-system", "sha": "c8dca186bcc8ac2c9b38d813fc0f0dfec486ebab", "save_path": "github-repos/isabelle/xqyww123-phi-system", "path": "github-repos/isabelle/xqyww123-phi-system/phi-system-c8dca186bcc8ac2c9b38d813fc0f0dfec486ebab/Phi_Semantics/PhiSem_Mem_OO.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6113819874558603, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.26532845047081294}}
{"text": "theory Old_Tau_Chain\n  imports Old_Semantics \"NewPsi.Tau_Chain\"\nbegin\n\ncontext old_psi begin\n\nabbreviation old_tau_chain :: \"'b \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow> bool\" (\"_ \\<rhd> _ \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau>\\<^sub>O _\" [80, 80, 80] 80)\nwhere \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau>\\<^sub>O P' \\<equiv> (P, P') \\<in> {(P, P'). \\<Psi> \\<rhd> P \\<longmapsto>\\<^sub>O \\<tau> \\<prec> P'}^*\"\n\nabbreviation old_tau_step_chain :: \"'b \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow> bool\" (\"_ \\<rhd> _ \\<Longrightarrow>\\<^sub>\\<tau>\\<^sub>O _\" [80, 80, 80] 80)\nwhere \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau>\\<^sub>O P' \\<equiv> (P, P') \\<in> {(P, P'). \\<Psi> \\<rhd> P \\<longmapsto>\\<^sub>O \\<tau> \\<prec> P'}^+\"\n\nabbreviation old_tau_context_chain :: \"('a, 'b, 'c) psi \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow> bool\" (\"_ \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau>\\<^sub>O _\" [80, 80] 80)\nwhere \"P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau>\\<^sub>O P' \\<equiv> \\<one> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau>\\<^sub>O P'\"\nabbreviation old_tau_context_step_chain :: \"('a, 'b, 'c) psi \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow> bool\" (\"_ \\<Longrightarrow>\\<^sub>\\<tau>\\<^sub>O _\" [80, 80] 80)\nwhere \"P \\<Longrightarrow>\\<^sub>\\<tau>\\<^sub>O P' \\<equiv> \\<one> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau>\\<^sub>O P'\"\n\nlemmas tau_chain_induct[consumes 1, case_names tau_base tau_step] = rtrancl.induct[of _ _ \"{(P, P'). \\<Psi> \\<rhd> P \\<longmapsto>None @ \\<tau> \\<prec> P'}\", simplified] for \\<Psi>\nlemmas tau_step_chain_induct[consumes 1, case_names tau_base tau_step] = trancl.induct[of _ _ \"{(P, P'). \\<Psi> \\<rhd> P \\<longmapsto>None @ \\<tau> \\<prec> P'}\", simplified] for \\<Psi>\n\ndefinition old_weak_transition :: \"'b \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow>  ('a, 'b, 'c) psi \\<Rightarrow> 'a action \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow> bool\" (\"_ : _ \\<rhd> _ \\<Longrightarrow>\\<^sub>O _ \\<prec> _\" [80, 80, 80, 80, 80] 80)\nwhere\n  \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<^sub>O \\<alpha> \\<prec> P' \\<equiv> \\<exists>P''. \\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau>\\<^sub>O P'' \\<and> (insert_assertion (extract_frame Q) \\<Psi>) \\<hookrightarrow>\\<^sub>F (insert_assertion (extract_frame P'') \\<Psi>) \\<and>\n                                          \\<Psi> \\<rhd> P'' \\<longmapsto>\\<^sub>O \\<alpha> \\<prec> P'\"\n\nlemma old_tau_chain_new:\n  shows \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau>\\<^sub>O P' = \\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n  by(rule Set.eqset_imp_iff)\n    (metis old_semantics_tau_sound old_semantics_complete)\n\nlemma old_tau_step_chain_new:\n  shows \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau>\\<^sub>O P' = \\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n  by(rule Set.eqset_imp_iff)\n    (metis old_semantics_tau_sound old_semantics_complete)\n\nlemma old_weak_transition_sound:\n  assumes \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<^sub>O \\<alpha> \\<prec> P'\"\n  shows   \"\\<exists>\\<pi>. \\<Psi> : Q \\<rhd> P \\<Longrightarrow> \\<pi> @ \\<alpha> \\<prec> P'\"\n  using assms\n  by(force simp add: old_weak_transition_def weak_transition_def\n                     old_tau_chain_new old_tau_step_chain_new\n           dest: old_semantics_sound)\n\nlemma old_weak_transition_tau_sound:\n  assumes \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<^sub>O \\<tau> \\<prec> P'\"\n  shows   \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow> None @ \\<tau> \\<prec> P'\"\n  using assms\n  by(force simp add: old_weak_transition_def weak_transition_def\n                     old_tau_chain_new old_tau_step_chain_new\n           dest: old_semantics_tau_sound)\n\nlemma old_weak_transition_complete:\n  assumes \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow> \\<pi> @ \\<alpha> \\<prec> P'\"\n  shows   \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<^sub>O \\<alpha> \\<prec> P'\"\n  using assms\n  by(force simp add: old_weak_transition_def weak_transition_def\n                     old_tau_chain_new old_tau_step_chain_new\n           dest: old_semantics_complete)\n\nend\n\nend", "meta": {"author": "IlmariReissumies", "repo": "newpsi", "sha": "201517d55b6ed1632a5bff2a585367278b5bc67b", "save_path": "github-repos/isabelle/IlmariReissumies-newpsi", "path": "github-repos/isabelle/IlmariReissumies-newpsi/newpsi-201517d55b6ed1632a5bff2a585367278b5bc67b/Old_Tau_Chain.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6113819591324416, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.2653284381789743}}
{"text": "theory newParallel\n  imports ContinuousInv BigStepParallel Complementlemma\n\nbegin\n\n\ninductive out_inv_assn :: \"(gstate \\<Rightarrow> bool) \\<Rightarrow> (gstate \\<Rightarrow> real \\<Rightarrow>  bool) \\<Rightarrow> cname \\<Rightarrow> tassn\" (\"Outinv\\<^sub>t\") where\n  \"r s  \\<Longrightarrow> g s v \\<Longrightarrow> Outinv\\<^sub>t r g ch [OutBlock ch v]\"\n| \"(d::real) > 0 \\<Longrightarrow> r s  \\<Longrightarrow> g s v \\<Longrightarrow> Outinv\\<^sub>t r g ch [WaitBlk (ereal d) (\\<lambda>_. s) ({ch}, {}), OutBlock ch v]\"\n| \"r s  \\<Longrightarrow>Outinv\\<^sub>t r g ch  [WaitBlk \\<infinity> (\\<lambda>_. s) ({ch}, {})]\"\n\ninductive in_inv_assn :: \"(gstate \\<Rightarrow> bool) \\<Rightarrow> (gstate \\<Rightarrow> real \\<Rightarrow> bool) \\<Rightarrow> cname  \\<Rightarrow> tassn\" (\"Ininv\\<^sub>t\") where\n  \"r s  \\<Longrightarrow> g s v\\<Longrightarrow> Ininv\\<^sub>t r g ch [InBlock ch v]\"\n| \"(d::real) > 0 \\<Longrightarrow> r s  \\<Longrightarrow> g s v \\<Longrightarrow> Ininv\\<^sub>t r g ch [WaitBlk (ereal d) (\\<lambda>_. s) ({}, {ch}), InBlock ch v]\"\n| \"r s  \\<Longrightarrow> Ininv\\<^sub>t r g ch  [WaitBlk \\<infinity> (\\<lambda>_. s) ({}, {ch})]\"\n\ninductive io_inv_assn :: \"(gstate \\<Rightarrow>  bool) \\<Rightarrow> (gstate \\<Rightarrow> real \\<Rightarrow> bool) \\<Rightarrow> cname \\<Rightarrow> tassn\" (\"IOinv\\<^sub>t\") where\n  \"r s  \\<Longrightarrow> g s v \\<Longrightarrow> IOinv\\<^sub>t r g ch [IOBlock ch v]\"\n\ninductive wait_inv_assn :: \"(gstate \\<Rightarrow> real \\<Rightarrow> bool) \\<Rightarrow> (real \\<Rightarrow> bool) \\<Rightarrow> rdy_info \\<Rightarrow> tassn\" (\"Waitinv\\<^sub>t\") where\n  \"dp 0 \\<Longrightarrow> Waitinv\\<^sub>t r dp rdy []\"\n| \"d > 0 \\<Longrightarrow> dp d \\<Longrightarrow> (\\<forall>t\\<in>{0..d}. r (p t) t) \\<Longrightarrow> Waitinv\\<^sub>t r dp rdy [WaitBlk (ereal d) p rdy]\" \n\ninductive wait_out_inv_assn ::\"(gstate \\<Rightarrow> real \\<Rightarrow> bool) \\<Rightarrow> (real \\<Rightarrow> bool) \\<Rightarrow> (gstate \\<Rightarrow> real \\<Rightarrow> bool) \n                                          \\<Rightarrow> rdy_info \\<Rightarrow> cname  \\<Rightarrow> tassn\" (\"WaitOutinv\\<^sub>t\") where\n  \"dp 0 \\<Longrightarrow> \\<exists> s. r s 0 \\<and> g s v \\<Longrightarrow> WaitOutinv\\<^sub>t r dp g rdy ch [OutBlock ch v]\"\n| \"d > 0 \\<Longrightarrow> dp d \\<Longrightarrow> (\\<forall>t\\<in>{0..d}. r (p t) t) \\<Longrightarrow> g (p d) v \n                \\<Longrightarrow> WaitOutinv\\<^sub>t r dp g rdy ch [WaitBlk (ereal d) p rdy, OutBlock ch v]\"\n\ninductive sb2gsb :: \"(state \\<Rightarrow> bool) \\<Rightarrow> (gstate \\<Rightarrow> bool)\" where\n \"p s \\<Longrightarrow> sb2gsb p (State s)\"\n\ninductive srb2gsrb :: \"(state \\<Rightarrow> real \\<Rightarrow> bool) \\<Rightarrow> (gstate \\<Rightarrow> real \\<Rightarrow> bool)\" where\n \"p s v \\<Longrightarrow> srb2gsrb p (State s) v\"\n\ninductive pgsb2gsb :: \"(gstate \\<Rightarrow> bool) \\<Rightarrow> (gstate \\<Rightarrow> bool) \\<Rightarrow> (gstate \\<Rightarrow> bool)\" where\n \"r1 s \\<Longrightarrow> r2 s' \\<Longrightarrow> pgsb2gsb r1 r2 (ParState s s') \"\n\ninductive pgsrb2gsrb :: \"(gstate \\<Rightarrow> real \\<Rightarrow> bool) \\<Rightarrow> (gstate \\<Rightarrow> real \\<Rightarrow> bool) \\<Rightarrow> (gstate \\<Rightarrow> real \\<Rightarrow> bool)\" where\n \"r1 s v \\<Longrightarrow> r2 s' v \\<Longrightarrow> pgsrb2gsrb r1 r2 (ParState s s') v\"\n\ninductive gsb2gsrb :: \"(gstate \\<Rightarrow> bool) \\<Rightarrow> (gstate \\<Rightarrow> real \\<Rightarrow> bool)\" where\n \"r s \\<Longrightarrow> gsb2gsrb r s t\"\n\nlemma combine_assn_emp_ininv:\n  \"ch \\<in> chs \\<Longrightarrow> combine_assn chs emp\\<^sub>t (Ininv\\<^sub>t r g ch @\\<^sub>t P) = false\\<^sub>A\"\n  unfolding combine_assn_def\n  apply (rule ext)\n  apply (auto simp add: false_assn_def emp_assn_def join_assn_def elim!: in_inv_assn.cases)\n  by (auto elim: sync_elims)\n\nlemma combine_assn_ininv_emp:\n  \"ch \\<in> chs \\<Longrightarrow> combine_assn chs (Ininv\\<^sub>t r g ch @\\<^sub>t P) emp\\<^sub>t = false\\<^sub>A\"\n  unfolding combine_assn_def\n  apply (rule ext)\n  apply (auto simp add: false_assn_def emp_assn_def join_assn_def elim!: in_inv_assn.cases)\n  by (auto elim: sync_elims)\n\nlemma combine_assn_emp_outinv:\n  \"ch \\<in> chs \\<Longrightarrow> combine_assn chs emp\\<^sub>t (Outinv\\<^sub>t r g ch @\\<^sub>t P) = false\\<^sub>A\"\n  unfolding combine_assn_def\n  apply (rule ext)\n  apply (auto simp add: false_assn_def emp_assn_def join_assn_def elim!: out_inv_assn.cases)\n  by (auto elim: sync_elims)\n\nlemma combine_assn_outinv_emp:\n  \"ch \\<in> chs \\<Longrightarrow> combine_assn chs (Outinv\\<^sub>t r g ch @\\<^sub>t P) emp\\<^sub>t= false\\<^sub>A\"\n  unfolding combine_assn_def\n  apply (rule ext)\n  apply (auto simp add: false_assn_def emp_assn_def join_assn_def elim!: out_inv_assn.cases)\n  by (auto elim: sync_elims)\n\nlemma combine_assn_ininv_outinv:\n  \"ch \\<in> chs \\<Longrightarrow>\n   combine_assn chs (Ininv\\<^sub>t r1 g1 ch @\\<^sub>t P) (Outinv\\<^sub>t r2 g2 ch @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t\n   (IOinv\\<^sub>t (pgsb2gsb r1 r2) (pgsrb2gsrb g1 g2) ch @\\<^sub>t combine_assn chs P Q)\"\n  unfolding combine_assn_def\n  apply (auto simp add: entails_tassn_def join_assn_def pure_assn_def conj_assn_def io_inv_assn.simps\n                        out_inv_assn.simps in_inv_assn.simps pgsb2gsb.simps pgsrb2gsrb.simps)\n          apply (auto elim: sync_elims)\n  subgoal for tr tr1 tr2 s1 v1 s2 v2\n    apply(rule exI[where x= \"[IOBlock ch v1]\"])\n    apply auto\n     apply(rule exI[where x= \"ParState s1 s2\"])\n    using combine_blocks_pairE apply blast\n    by (meson combine_blocks_pairE)\n  done\n\nlemma combine_assn_emp_waitinv:\n  \"combine_assn chs emp\\<^sub>t (Waitinv\\<^sub>t  p dp rdy @\\<^sub>t P) \\<Longrightarrow>\\<^sub>t combine_assn chs emp\\<^sub>t P\"\n  unfolding combine_assn_def\n  apply (auto simp add: entails_tassn_def wait_inv_assn.simps emp_assn_def \njoin_assn_def false_assn_def)\n  by (auto elim: sync_elims)\n\nlemma combine_assn_waitinv_emp:\n  \"combine_assn chs  (Waitinv\\<^sub>t  p dp rdy @\\<^sub>t P) emp\\<^sub>t \\<Longrightarrow>\\<^sub>t combine_assn chs  P emp\\<^sub>t\"\n  unfolding combine_assn_def\n  apply (auto simp add: entails_tassn_def wait_inv_assn.simps emp_assn_def \njoin_assn_def false_assn_def)\n  by (auto elim: sync_elims)\n\nlemma combine_assn_waitinv_ininv:\n  assumes \"ch \\<in> chs\"\n    and \"compat_rdy rdy1 ({}, {ch})\"\n  shows \"combine_assn chs (Waitinv\\<^sub>t r1 dp rdy1 @\\<^sub>t P) (Ininv\\<^sub>t r2 g ch @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t\n   (Waitinv\\<^sub>t (pgsrb2gsrb r1 (gsb2gsrb r2)) dp (merge_rdy rdy1 ({}, {ch})) @\\<^sub>t\n    combine_assn chs P (Ininv\\<^sub>t r2 g ch @\\<^sub>t Q))\"\nproof-\n  have *:\"(Waitinv\\<^sub>t (pgsrb2gsrb r1 (gsb2gsrb r2)) dp (merge_rdy rdy1 ({}, {ch})) @\\<^sub>t\n    combine_assn chs P (Ininv\\<^sub>t r2 g ch @\\<^sub>t Q)) tr\" if\n        \"(Waitinv\\<^sub>t r1 dp rdy1 @\\<^sub>t P) tr1\" \"(Ininv\\<^sub>t r2 g ch @\\<^sub>t Q) tr2\" \n        \"combine_blocks chs tr1 tr2 tr\" for tr tr1 tr2\n  proof-\n    from that(1)[unfolded join_assn_def]\n    obtain tr11 tr12 where a: \"Waitinv\\<^sub>t r1 dp rdy1 tr11\" \"P tr12\" \"tr1 = tr11 @ tr12\"\n      by auto\n    from that(2)[unfolded join_assn_def]\n    obtain tr21 tr22 where b: \"Ininv\\<^sub>t r2 g ch tr21\" \"Q tr22\" \"tr2 = tr21 @ tr22\"\n      by auto\n    have d:\"(Waitinv\\<^sub>t (pgsrb2gsrb r1 (gsb2gsrb r2)) dp (merge_rdy rdy1 ({}, {ch})) @\\<^sub>t\n     combine_assn chs P (Ininv\\<^sub>t r2 g ch @\\<^sub>t Q)) tr\" if \n        \"0 < d2\" \"0<d\" \"dp d\"\n        \"combine_blocks chs (WaitBlk (ereal d) p rdy1 # tr12)\n          (WaitBlk (ereal d2) (\\<lambda>_. s) ({}, {ch}) # InBlock ch v # tr22) tr\" \n        \"\\<forall>t\\<in>{0..d}. r1 (p t) t\"\n        \"r2 s \"  \"g s v \"\n      for d p s v d2\n    proof -\n      have \"d < d2 \\<or> d = d2 \\<or> d > d2\" by auto\n      then show ?thesis\n      proof (elim disjE)\n        assume d1: \"d < d2\"\n        have d1': \"ereal d < ereal d2\"\n          using d1 by auto\n        show ?thesis\n          using that(4)\n          apply (elim combine_blocks_waitE3)\n             apply (rule that(2)) apply (rule d1') using assms(2) apply simp\n          subgoal for blks'\n            apply (subst join_assn_def)\n            apply (rule exI[where x=\"[WaitBlk d (\\<lambda>t. ParState (p t) s) (merge_rdy rdy1 ({}, {ch}))]\"])\n            apply (rule exI[where x=blks'])\n            apply (rule conjI)\n            subgoal \n              apply(auto simp add:wait_inv_assn.simps pgsrb2gsrb.simps gsb2gsrb.simps)\n              apply(rule exI[where x=\"d\"])\n              apply(rule exI[where x=\"(\\<lambda>t. ParState (p t) s)\"])\n              using that by auto\n            apply (rule conjI)\n             prefer 2 subgoal using d1 by auto\n            unfolding combine_assn_def\n            apply (rule exI[where x=tr12])\n            apply (rule exI[where x=\"WaitBlk (d2 - d) (\\<lambda>_. s) ({}, {ch}) # InBlock ch v # tr22\"])\n            apply (rule conjI)\n            subgoal by (rule a(2))\n            apply (rule conjI)\n             prefer 2 subgoal by auto\n            apply (subst join_assn_def)\n            apply (rule exI[where x=\"[WaitBlk (d2 - d) (\\<lambda>_. s) ({}, {ch}), InBlock ch v]\"])\n            apply (rule exI[where x=tr22])\n            using b(2) d1 that by (auto intro: in_inv_assn.intros)\n          done\n      next\n        assume d2: \"d = d2\"\n        show ?thesis\n          using that(4) unfolding d2[symmetric]\n          apply (elim combine_blocks_waitE2)\n          using assms(2) apply simp\n          subgoal for blks'\n            apply (subst join_assn_def)\n            apply (rule exI[where x=\"[WaitBlk d (\\<lambda>t. ParState (p t) s) (merge_rdy rdy1 ({}, {ch}))]\"])\n            apply (rule exI[where x=blks'])\n            apply (rule conjI)\n            subgoal using that apply (auto simp add: wait_inv_assn.simps pgsrb2gsrb.simps gsb2gsrb.simps)\n              by blast\n            apply (rule conjI)\n             prefer 2 subgoal by auto\n            unfolding combine_assn_def\n            apply (rule exI[where x=tr12])\n            apply (rule exI[where x=\"InBlock ch v # tr22\"])\n            apply (rule conjI)\n            subgoal using a(2) by auto\n            apply (rule conjI)\n            subgoal apply (subst join_assn_def)\n              apply (rule exI[where x=\"[InBlock ch v]\"])\n              apply (rule exI[where x=tr22])\n              by (auto intro: in_inv_assn.intros b(2) that)\n            by auto\n          done\n      next\n        assume d3: \"d > d2\"\n        have d3': \"ereal d > ereal d2\"\n          using d3  by auto\n        show ?thesis\n          using that(4)\n          apply (elim combine_blocks_waitE4)\n          apply (rule that(1)) apply (rule d3')\n           using assms(2) apply simp\n          apply (elim combine_blocks_pairE2')\n          using assms by auto\n      qed\n        qed\n      have e: \"(Waitinv\\<^sub>t (pgsrb2gsrb r1 (gsb2gsrb r2)) dp (merge_rdy rdy1 ({}, {ch})) @\\<^sub>t\n     combine_assn chs P (Ininv\\<^sub>t r2 g ch @\\<^sub>t Q)) tr\" if \n        \"combine_blocks chs (WaitBlk (ereal d) p rdy1 # tr12)\n          (WaitBlk \\<infinity> (\\<lambda>_. s) ({}, {ch}) # tr22) tr\" \"0 < d \" \"dp d\" \n          \"\\<forall>t\\<in>{0..d}. r1 (p t) t\" \"r2 s\" for d p s\n      proof -\n      have e1: \"\\<infinity> - ereal d = \\<infinity>\"\n        by auto\n      show ?thesis\n        using that\n        apply (elim combine_blocks_waitE3)\n           apply auto using assms(2) apply simp\n        subgoal for blks'\n          apply (subst join_assn_def)\n          apply (rule exI[where x=\"[WaitBlk d (\\<lambda>t. ParState (p t) s) (merge_rdy rdy1 ({}, {ch}))]\"])\n          apply (rule exI[where x=blks'])\n          apply (rule conjI)\n            subgoal apply(simp add: wait_inv_assn.simps pgsrb2gsrb.simps gsb2gsrb.simps) by blast\n            apply (rule conjI)\n             prefer 2 apply simp\n            unfolding combine_assn_def\n            apply (rule exI[where x=tr12])\n            apply (rule exI[where x=\"WaitBlk \\<infinity> (\\<lambda>_. s) ({}, {ch}) # tr22\"])\n            apply (rule conjI)\n            subgoal by (rule a(2))\n            apply (rule conjI)\n             prefer 2 apply auto\n            apply (subst join_assn_def)\n            apply (rule exI[where x=\"[WaitBlk \\<infinity> (\\<lambda>_. s) ({}, {ch})]\"])\n            apply (rule exI[where x=tr22])\n            using b(2) apply (auto intro: in_inv_assn.intros)\n          done\n        done\n    qed\n    show ?thesis\n      using a(1) apply (cases rule: wait_inv_assn.cases)\n      using b(1) apply (cases rule: in_inv_assn.cases)\n      subgoal for s v\n        apply(auto simp add: combine_assn_def join_assn_def)\n        apply(rule exI[where x= \"[]\"])\n        apply (auto simp add: wait_inv_assn.simps)\n        apply(rule exI[where x= \"tr12\"])\n        apply (auto simp add: a)\n        apply(rule exI[where x= \"tr2\"])\n        apply auto\n         apply(rule exI[where x= \"tr21\"])\n         apply auto\n        using b apply auto\n        using that a b by auto\n subgoal for d s v\n        apply(auto simp add: combine_assn_def join_assn_def)\n        apply(rule exI[where x= \"[]\"])\n        apply (auto simp add: wait_inv_assn.simps)\n        apply(rule exI[where x= \"tr12\"])\n        apply (auto simp add: a)\n        apply(rule exI[where x= \"tr2\"])\n        apply auto\n         apply(rule exI[where x= \"tr21\"])\n         apply auto\n        using b apply auto\n        using that a b by auto\n      subgoal for d \n        apply(auto simp add: combine_assn_def join_assn_def)\n        apply(rule exI[where x= \"[]\"])\n        apply (auto simp add: wait_inv_assn.simps)\n        apply(rule exI[where x= \"tr12\"])\n        apply (auto simp add: a)\n        apply(rule exI[where x= \"tr2\"])\n        apply auto\n         apply(rule exI[where x= \"tr21\"])\n         apply auto\n        using b apply auto\n        using that a b by auto\n      using b(1) apply (cases rule: in_inv_assn.cases)\n      subgoal for s v d p\n        apply(auto simp add: combine_assn_def join_assn_def)\n        by (metis Cons_eq_appendI a(3) assms(1) b(3)  combine_blocks_pairE2' that(3))\n      subgoal for d p d2 s v\n        apply(rule d[of d2 d p s v])\n        using that a b by auto\n      subgoal for d p s\n        apply(rule e[of d p s])\n        using that a b by auto\n      done\n  qed\nshow ?thesis\n    apply (subst combine_assn_def)\n    apply (auto simp add: entails_tassn_def)\n  using * by auto\nqed\n\nlemma combine_assn_waitoutinv_emp:\n  assumes \"ch \\<in> chs\"\n  shows \"combine_assn chs (WaitOutinv\\<^sub>t r dp g rdy ch @\\<^sub>t P) emp\\<^sub>t \\<Longrightarrow>\\<^sub>t false\\<^sub>A\"\n  unfolding combine_assn_def\n  apply (auto simp add: entails_tassn_def join_assn_def emp_assn_def false_assn_def wait_out_inv_assn.simps)\n  using assms by (auto elim: sync_elims)\n        \nlemma combine_assn_waitoutinv_ininv:\n  assumes \"ch \\<in> chs\"\n    and \"ch \\<in> fst rdy\"\n  shows \"combine_assn chs (WaitOutinv\\<^sub>t rr dp g1 rdy ch @\\<^sub>t P) (Ininv\\<^sub>t r g2 ch @\\<^sub>t Q) \\<Longrightarrow>\\<^sub>t \n         (IOinv\\<^sub>t (pgsb2gsb (\\<lambda> s. rr s 0) r) (pgsrb2gsrb g1 g2) ch @\\<^sub>t combine_assn chs P Q)\"\nproof-\n  have *:\"(IOinv\\<^sub>t (pgsb2gsb (\\<lambda> s. rr s 0) r) (pgsrb2gsrb g1 g2) ch @\\<^sub>t combine_assn chs P Q) tr\"\n    if \"(WaitOutinv\\<^sub>t rr dp g1 rdy ch @\\<^sub>t P) tr1\" \"(Ininv\\<^sub>t r g2 ch @\\<^sub>t Q) tr2\" \"combine_blocks chs tr1 tr2 tr\" for tr tr1 tr2\n  proof -\n    from that(1)[unfolded join_assn_def]\n    obtain tr11 tr12 where a: \"WaitOutinv\\<^sub>t rr dp g1 rdy ch tr11\" \"P tr12\" \"tr1 = tr11 @ tr12\"\n      by auto\n    from that(2)[unfolded join_assn_def]\n    obtain tr21 tr22 where b: \"Ininv\\<^sub>t r g2 ch tr21\" \"Q tr22\" \"tr2 = tr21 @ tr22\"\n      by auto\n    show ?thesis\n      using a(1) apply (cases rule: wait_out_inv_assn.cases)\n      subgoal for v\n        using b(1) apply (cases rule: in_inv_assn.cases)\n        subgoal for s' v'\n          using that(3) unfolding a(3) b(3) apply auto\n          apply (elim combine_blocks_pairE) using assms(1) apply auto\n          apply (auto simp add: conj_assn_def pure_assn_def join_assn_def)\n          apply (rule exI[where x=\"[IOBlock ch v']\"])\n          apply (auto intro: io_assn.intros)\n          unfolding combine_assn_def using a(2) b(2) apply auto\n          subgoal for s tr'\n            using io_inv_assn.intros[of \"(pgsb2gsb (\\<lambda>s. rr s 0) r)\" \"ParState s s'\" \"(pgsrb2gsrb g1 g2)\" v ch]\n            by(auto simp add:pgsb2gsb.simps pgsrb2gsrb.simps)\n          done\n        subgoal for d s' v'\n          using that(3) unfolding a(3) b(3) apply auto\n          apply (elim combine_blocks_pairE2) using assms by auto\n        subgoal for s'\n          using that(3) unfolding a(3) b(3) apply auto\n          apply (elim combine_blocks_pairE2) by (rule assms)\n        done\n      using b(1) apply (cases rule: in_inv_assn.cases)\n      using that(3) unfolding a(3) b(3) apply auto\n      subgoal apply (elim combine_blocks_pairE2') by (rule assms)\n      subgoal for d' apply (elim combine_blocks_waitE1)\n        using assms(2) apply (cases rdy) by auto\n      subgoal apply (elim combine_blocks_waitE1)\n        using assms(2) apply (cases rdy) by auto\n      done\n  qed\nshow ?thesis\n    apply (subst combine_assn_def)\n    apply (auto simp add: entails_tassn_def)\n    using * by auto\nqed\n\nend", "meta": {"author": "bzhan", "repo": "mars", "sha": "d10e489a8ddf128a4cbac13291efdece458d732d", "save_path": "github-repos/isabelle/bzhan-mars", "path": "github-repos/isabelle/bzhan-mars/mars-d10e489a8ddf128a4cbac13291efdece458d732d/lunarlander_sl/newParallel.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6334102636778403, "lm_q2_score": 0.41869690935568665, "lm_q1q2_score": 0.26520691975608224}}
{"text": "(*  Title:      HOL/Auth/n_mutualExFsm_lemma_inv__4_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mutualExFsm Protocol Case Study*} \n\ntheory n_mutualExFsm_lemma_inv__4_on_rules imports n_mutualExFsm_lemma_on_inv__4\nbegin\nsection{*All lemmas on causal relation between inv__4*}\nlemma lemma_inv__4_on_rules:\n  assumes b1: \"r \\<in> rules N\" and b2: \"(\\<exists> p__Inv0. p__Inv0\\<le>N\\<and>f=inv__4  p__Inv0)\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have c1: \"(\\<exists> i. i\\<le>N\\<and>r=n_fsm  i)\"\n  apply (cut_tac b1, auto) done\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_fsm  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_fsmVsinv__4) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "lyj238Gmail", "repo": "newParaVerifier", "sha": "5c2d49bf8e6c46c60efa53c98b0ba5c577d59618", "save_path": "github-repos/isabelle/lyj238Gmail-newParaVerifier", "path": "github-repos/isabelle/lyj238Gmail-newParaVerifier/newParaVerifier-5c2d49bf8e6c46c60efa53c98b0ba5c577d59618/examples/n_mutualExFsm/n_mutualExFsm_lemma_inv__4_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6334102636778401, "lm_q2_score": 0.4186969093556867, "lm_q1q2_score": 0.26520691975608224}}
{"text": "theory SolverP1\n  imports InferRange\nbegin\n  \n  (* ## to move *)\n\ndefinition sub_list where\n  \"sub_list l1 l2 = (\\<forall> x. list_contain l1 x \\<longrightarrow> list_contain l2 x)\"  \n  \nlemma append_sub_list1: \"\\<lbrakk> sub_list (l1 @ l2) lx \\<rbrakk> \\<Longrightarrow> sub_list l1 lx\"  \n  apply (induct l1)\n   apply (auto)\n   apply (simp add: sub_list_def)\n  apply (simp add: sub_list_def)\n  done\n\nlemma append_sub_list2: \"\\<lbrakk> sub_list (l1 @ l2) lx \\<rbrakk> \\<Longrightarrow> sub_list l2 lx\"  \n  apply (induct l1)\n   apply (auto)\n  apply (simp add: sub_list_def)\n  done\n    \nlemma id_sub_list: \"sub_list l l\"    \n  apply (simp add: sub_list_def)\n  done    \n  \n    (* phase 1: type unification *)  \n  \ndatatype perm_crn2 =\n  LeqCrn2 x_perm s_perm\n  | DisjCrn2 x_perm x_perm\n  | MiniDisjCrn2 x_perm x_perm\n  \nfun unify_subset where\n  \"unify_subset [] = []\"\n| \"unify_subset (c # c_t) = (case c of\n    UnifyCrn tau1 tau2 \\<Rightarrow> (tau1, tau2) # (unify_subset c_t)\n    | cx \\<Rightarrow> unify_subset c_t\n  )\"\n  \nfun eval_perm where\n  \"eval_perm p_sub (SPerm p) = p\"\n| \"eval_perm p_sub (SVar r) = p_sub r\"  \n  \nfun eval_permx where\n  \"eval_permx p_sub (XPerm p) = eval_perm p_sub p\"  \n| \"eval_permx p_sub (XType a) = NoPerm\"\n| \"eval_permx p_sub (XComp px qx) = union_perm (eval_permx p_sub px) (eval_permx p_sub qx)\"  \n| \"eval_permx p_sub (XLift px q) = (if eval_perm p_sub q = OwnPerm \\<and> eval_permx p_sub px \\<noteq> NoPerm then OwnPerm else eval_permx p_sub px)\"\n| \"eval_permx p_sub (XIfZero px qx) = (if eval_permx p_sub px = NoPerm then NoPerm else eval_permx p_sub qx)\"  \n  \nfun sol_sat_crn2 where\n  \"sol_sat_crn2 p_sub (LeqCrn2 px q) = (leq_perm (eval_permx p_sub px) (eval_perm p_sub q))\"  \n| \"sol_sat_crn2 p_sub (DisjCrn2 px qx) = (mini_disj_perm (eval_permx p_sub px) (eval_permx p_sub qx) \\<and>\n  mini_disj_perm (eval_permx p_sub qx) (eval_permx p_sub px))\"  \n| \"sol_sat_crn2 p_sub (MiniDisjCrn2 px qx) = (mini_disj_perm (eval_permx p_sub px) (eval_permx p_sub qx))\"  \n  \nfun sol_sat2 where\n  \"sol_sat2 p_sub [] = True\"  \n| \"sol_sat2 p_sub (c # c_t) = (sol_sat_crn2 p_sub c \\<and> sol_sat2 p_sub c_t)\"     \n    \n  (* occurs *)\n  \nfun occurs where\n  \"occurs (VarScheme b) a = (a = b)\"\n| \"occurs (ArrayScheme tau) a = (occurs tau a)\"\n| \"occurs (PairScheme t1 t2 r) a = (occurs t1 a \\<or> occurs t2 a)\"  \n| \"occurs (FunScheme t1 t2 r af) a = (occurs t1 a \\<or> occurs t2 a)\"  \n| \"occurs (ChanScheme tau c_end) a = (occurs tau a)\"\n| \"occurs tau a = False\"\n  \nfun sol_subst_type :: \"type_subst \\<Rightarrow> s_type \\<Rightarrow> s_type\" where\n  \"sol_subst_type t_sub (VarScheme x) = (case t_sub x of\n    None \\<Rightarrow> VarScheme x\n    | Some tau \\<Rightarrow> tau\n  )\"\n| \"sol_subst_type t_sub (ArrayScheme tau) = ArrayScheme (sol_subst_type t_sub tau)\"  \n| \"sol_subst_type t_sub (PairScheme t1 t2 p) = PairScheme (sol_subst_type t_sub t1) (sol_subst_type t_sub t2) p\"\n| \"sol_subst_type t_sub (FunScheme t1 t2 p q) = FunScheme (sol_subst_type t_sub t1) (sol_subst_type t_sub t2) p q\"  \n| \"sol_subst_type t_sub (ChanScheme tau c_end) = ChanScheme (sol_subst_type t_sub tau) c_end\"\n| \"sol_subst_type t_sub tau_v = tau_v\"\n  \nfun sol_subst_eq_list where\n  \"sol_subst_eq_list t_sub [] = []\"  \n| \"sol_subst_eq_list t_sub ((t1, t2) # c_t) = ((sol_subst_type t_sub t1, sol_subst_type t_sub t2) # (sol_subst_eq_list t_sub c_t))\"  \n  \nfun as_perm_s where\n  \"as_perm_s (AffConst a) = (SPerm (as_perm a))\"\n| \"as_perm_s (AffVar r) = (SVar r)\"  \n \ndefinition add_list where\n  \"add_list l x = (if list_contain l x then l else x # l)\"  \n\nfun rem_list where\n  \"rem_list [] x = []\"    \n| \"rem_list (y # l) x = (if x = y then l else y # (rem_list l x))\"  \n  \nfun union_list where\n  \"union_list [] l2 = l2\"\n| \"union_list (x # l1) l2 = add_list (union_list l1 l2) x\"    \n  \nfun tvar_type_l where\n  \"tvar_type_l (VarScheme a) = [a]\"\n  | \"tvar_type_l (ArrayScheme tau) = tvar_type_l tau\"\n  | \"tvar_type_l (PairScheme t1 t2 p) = union_list (tvar_type_l t1) (tvar_type_l t2)\"\n  | \"tvar_type_l (FunScheme t1 t2 p a) = union_list (tvar_type_l t1) (tvar_type_l t2)\"\n  | \"tvar_type_l (ChanScheme tau c_end) = tvar_type_l tau\"\n  | \"tvar_type_l tau = []\"\n\nfun tvar_eq_list where\n  \"tvar_eq_list [] = []\"\n| \"tvar_eq_list ((t1, t2) # c_t) = union_list (union_list (tvar_type_l t1) (tvar_type_l t2)) (tvar_eq_list c_t)\"\n    \ndefinition tvar_total where  \n  \"tvar_total c_list = length (tvar_eq_list c_list)\"\n\nfun type_cons :: \"s_type \\<Rightarrow> nat\" where\n  \"type_cons (ArrayScheme tau) = type_cons tau + 1\"\n| \"type_cons (PairScheme t1 t2 p) = (type_cons t1) + (type_cons t2) + 1\"\n| \"type_cons (FunScheme t1 t2 p q) = (type_cons t1) + (type_cons t2) + 1\"  \n| \"type_cons (ChanScheme tau c_end) = type_cons tau + 1\"\n| \"type_cons (VarScheme a) = 0\"\n| \"type_cons tau = 1\"\n  \nfun lcons_list where\n  \"lcons_list [] = 0\"\n| \"lcons_list ((t1, t2) # c_t) = (type_cons t1) + (lcons_list c_t)\"\n  \ndefinition unify_rel where\n  \"unify_rel = measures [tvar_total, lcons_list, length]\"  \n  \nlemma contain_rem_list_length: \"\\<lbrakk> list_contain l x \\<rbrakk> \\<Longrightarrow> length (rem_list l x) + 1 = length l\"  \n  apply (induct l)\n   apply (auto)\n  done\n  \nlemma rem_sub_list: \"\\<lbrakk> sub_list l1 l2; \\<not> list_contain l1 x \\<rbrakk> \\<Longrightarrow> sub_list l1 (rem_list l2 x)\"    \n  apply (simp add: sub_list_def)\n  apply (auto)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (auto)\n  apply (induct l2)\n   apply (auto)\n  done\n    \nlemma add_sub_list: \"\\<lbrakk> sub_list l1 l2 \\<rbrakk> \\<Longrightarrow> sub_list l1 (add_list l2 x)\"    \n  apply (simp add: sub_list_def)\n  apply (auto)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (auto)\n  apply (induct l2)\n   apply (auto)\n   apply (simp add: add_list_def)\n  apply (simp add: add_list_def)\n  done\n  \nlemma union_list_contain1: \"\\<lbrakk> list_contain l1 x \\<rbrakk> \\<Longrightarrow> list_contain (union_list l1 l2) x\"    \n  apply (induct l1 arbitrary: l2)\n   apply (auto)\n   apply (simp add: add_list_def)\n  apply (simp add: add_list_def)\n  done\n    \nlemma union_list_contain2: \"\\<lbrakk> list_contain l2 x \\<rbrakk> \\<Longrightarrow> list_contain (union_list l1 l2) x\"    \n  apply (induct l1 arbitrary: l2)\n   apply (auto)\n  apply (simp add: add_list_def)\n  done    \n  \nlemma dist_union_list_contain: \"\\<lbrakk> list_contain (union_list l1 l2) x \\<rbrakk> \\<Longrightarrow> list_contain l1 x \\<or> list_contain l2 x\"    \n  apply (induct l1 arbitrary: l2)\n   apply (auto)\n  apply (simp add: add_list_def)\n  apply (case_tac \"list_contain (union_list l1 l2) a\")\n   apply (auto)\n  done        \n    \nlemma union_sub_list1: \"\\<lbrakk> sub_list la lb \\<rbrakk> \\<Longrightarrow> sub_list la (union_list lb lc)\"\n  apply (simp add: sub_list_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (rule_tac union_list_contain1)\n  apply (simp)\n  done\n    \nlemma union_sub_list2: \"\\<lbrakk> sub_list la lc \\<rbrakk> \\<Longrightarrow> sub_list la (union_list lb lc)\"\n  apply (simp add: sub_list_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (rule_tac union_list_contain2)\n  apply (simp)\n  done    \n  \nlemma dist_union_sub_list: \"\\<lbrakk> sub_list la lc; sub_list lb lc \\<rbrakk> \\<Longrightarrow> sub_list (union_list la lb) lc\"    \n  apply (simp add: sub_list_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (cut_tac ?l1.0=\"la\" and ?l2.0=\"lb\" and x=\"x\" in dist_union_list_contain)\n   apply (auto)\n  done\n    \nlemma union_sub_list_rev: \"\\<lbrakk> sub_list (union_list la lb) lc \\<rbrakk> \\<Longrightarrow> sub_list la lc \\<and> sub_list lb lc\"      \n  apply (simp add: sub_list_def)\n  apply (auto)\n   apply (erule_tac x=\"x\" in allE)\n   apply (auto)\n   apply (cut_tac ?l1.0=\"la\" in union_list_contain1)\n    apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (cut_tac ?l2.0=\"lb\" in union_list_contain2)\n   apply (auto)\n  done\n    \nlemma sub_list_less_length: \"\\<lbrakk> fresh_in_list l1; sub_list l1 l2 \\<rbrakk> \\<Longrightarrow> length l1 \\<le> length l2\"  \n  apply (induct l1 arbitrary: l2)\n   apply (auto)\n    (* because a # l1 is a sub_list of l2, l2 must contain a *)\n  apply (case_tac \"\\<not> list_contain l2 a\")\n   apply (simp add: sub_list_def)\n   apply (auto)\n    (* we can replace length l2 with length (l2 - a) + 1 *)\n  apply (rule_tac t=\"length l2\" and s=\"length (rem_list l2 a) + 1\" in subst)\n   apply (rule_tac contain_rem_list_length)\n   apply (auto)\n    (* lastly, it remains to show that l1 is a sub-list of (l2 - a) *)\n  apply (cut_tac ?l1.0=\"l1\" and ?l2.0=\"l2\" and x=\"a\" in rem_sub_list)\n    apply (simp add: sub_list_def)\n   apply (auto)\n  done\n \nlemma union_fresh_list: \"\\<lbrakk> fresh_in_list l1; fresh_in_list l2 \\<rbrakk> \\<Longrightarrow> fresh_in_list (union_list l1 l2)\"    \n  apply (induct l1)\n   apply (auto)\n  apply (simp add: add_list_def)\n  done\n\nlemma tvar_type_fresh_list: \"fresh_in_list (tvar_type_l tau)\"    \n  apply (induct tau)\n         apply (auto)\n   apply (rule_tac union_fresh_list)\n    apply (auto)\n  apply (rule_tac union_fresh_list)\n   apply (auto)\n  done\n\nlemma tvar_eq_fresh_list: \"fresh_in_list (tvar_eq_list c_list)\"    \n  apply (induct c_list)\n   apply (auto)\n  apply (rule_tac union_fresh_list)\n  apply (rule_tac union_fresh_list)\n    apply (rule_tac tvar_type_fresh_list)\n   apply (rule_tac tvar_type_fresh_list)\n  apply (simp)\n  done\n    \nlemma cons_less_tvar_total: \"tvar_total c_list \\<le> tvar_total (c # c_list)\"  \n  apply (simp add: tvar_total_def)\n  apply (case_tac c)\n  apply (auto)\n  apply (rule_tac sub_list_less_length)\n   apply (rule_tac tvar_eq_fresh_list)\n  apply (rule_tac union_sub_list2)\n  apply (rule_tac id_sub_list)\n  done\n\nlemma orient_less_tvar_total: \"tvar_total ((c2, c1) # c_list) \\<le> tvar_total ((c1, c2) # c_list)\"      \n  apply (simp add: tvar_total_def)\n  apply (rule_tac sub_list_less_length)\n   apply (rule_tac union_fresh_list)\n    apply (rule_tac union_fresh_list)\n     apply (rule_tac tvar_type_fresh_list)\n    apply (rule_tac tvar_type_fresh_list)\n   apply (rule_tac tvar_eq_fresh_list)\n  apply (rule_tac dist_union_sub_list)\n   apply (rule_tac union_sub_list1)\n   apply (rule_tac dist_union_sub_list)\n    apply (rule_tac union_sub_list2)\n    apply (rule_tac id_sub_list)\n   apply (rule_tac union_sub_list1)\n   apply (rule_tac id_sub_list)\n  apply (rule_tac union_sub_list2)\n  apply (rule_tac id_sub_list)\n  done\n    \nlemma simp_unify_rel: \"(c_list, (x, y) # c_list) \\<in> unify_rel\"\n  apply (simp add: unify_rel_def)\n  apply (auto)\n  apply (cut_tac c_list=\"c_list\" and c=\"(x, y)\" in cons_less_tvar_total)\n  apply (auto)\n  done\n    \nlemma orient_unify_rel: \"\\<lbrakk> \\<forall> b. x \\<noteq> VarScheme b \\<rbrakk> \\<Longrightarrow> ((VarScheme a, x) # c_list, (x, VarScheme a) # c_list) \\<in> unify_rel\"    \n  apply (simp add: unify_rel_def)\n  apply (auto)\n   apply (cut_tac ?c2.0=\"VarScheme a\" and ?c1.0=\"x\" and c_list=\"c_list\" in orient_less_tvar_total)\n   apply (auto)\n  apply (case_tac x)\n         apply (auto)\n  done\n\nlemma sol_subst_type_sub_list: \"\\<lbrakk> sub_list (tvar_type_l tau) l; sub_list (tvar_type_l tau_x) l \\<rbrakk> \\<Longrightarrow>\n  sub_list (tvar_type_l (sol_subst_type (add_env empty_env x tau_x) tau)) l\"    \n  apply (induct tau)\n         apply (auto)\n    apply (case_tac \"x = xa\")\n     apply (simp add: add_env_def)\n    apply (simp add: add_env_def)\n    apply (simp add: empty_env_def)\n   apply (cut_tac la=\"tvar_type_l tau1\" and lb=\"tvar_type_l tau2\" and lc=\"l\" in union_sub_list_rev)\n    apply (auto)\n   apply (rule_tac dist_union_sub_list)\n    apply (simp_all)\n  apply (cut_tac la=\"tvar_type_l tau1\" and lb=\"tvar_type_l tau2\" and lc=\"l\" in union_sub_list_rev)\n   apply (auto)\n  apply (rule_tac dist_union_sub_list)\n   apply (simp_all)\n  done\n\nlemma sol_subst_sub_list: \"\\<lbrakk> sub_list (tvar_type_l tau) l; sub_list (tvar_eq_list c_list) l \\<rbrakk> \\<Longrightarrow>\n  sub_list (tvar_eq_list (sol_subst_eq_list (add_env empty_env x tau) c_list)) l\"   \n  apply (induct c_list arbitrary: l)\n   apply (auto)\n  apply (cut_tac la=\"union_list (tvar_type_l a) (tvar_type_l b)\" and lb=\"tvar_eq_list c_list\" and lc=\"l\" in union_sub_list_rev)\n   apply (auto)\n  apply (cut_tac la=\"tvar_type_l a\" and lb=\"tvar_type_l b\" and lc=\"l\" in union_sub_list_rev)\n   apply (auto)\n  apply (rule_tac dist_union_sub_list)\n   apply (rule_tac dist_union_sub_list)\n    apply (rule_tac sol_subst_type_sub_list)\n     apply (auto)\n  apply (rule_tac sol_subst_type_sub_list)\n   apply (auto)\n  done\n    \nlemma occurs_list_contain: \"\\<lbrakk> \\<not> occurs tau x \\<rbrakk> \\<Longrightarrow> \\<not> list_contain (tvar_type_l tau) x\"    \n  apply (induct tau)\n         apply (auto)\n   apply (cut_tac ?l1.0=\"tvar_type_l tau1\" and ?l2.0=\"tvar_type_l tau2\" in dist_union_list_contain)\n    apply (auto)\n  apply (cut_tac ?l1.0=\"tvar_type_l tau1\" and ?l2.0=\"tvar_type_l tau2\" in dist_union_list_contain)\n   apply (auto)\n  done\n    \nlemma sol_subst_type_list_contain: \"\\<lbrakk> \\<not> occurs tau_x x \\<rbrakk> \\<Longrightarrow>\n  \\<not> list_contain (tvar_type_l (sol_subst_type (add_env empty_env x tau_x) tau)) x\"\n  apply (induct tau)\n         apply (auto)\n    apply (simp add: add_env_def)\n    apply (case_tac \"x = xa\")\n     apply (auto)\n     apply (simp add: occurs_list_contain)\n    apply (simp add: empty_env_def)\n   apply (cut_tac ?l1.0=\"tvar_type_l (sol_subst_type (add_env empty_env x tau_x) tau1)\" and\n      ?l2.0=\"tvar_type_l (sol_subst_type (add_env empty_env x tau_x) tau2)\" in dist_union_list_contain)\n    apply (auto)\n  apply (cut_tac ?l1.0=\"tvar_type_l (sol_subst_type (add_env empty_env x tau_x) tau1)\" and\n      ?l2.0=\"tvar_type_l (sol_subst_type (add_env empty_env x tau_x) tau2)\" in dist_union_list_contain)\n   apply (auto)\n  done\n    \nlemma sol_subst_list_contain: \"\\<lbrakk> \\<not> occurs tau x \\<rbrakk> \\<Longrightarrow>\n  \\<not> list_contain (tvar_eq_list (sol_subst_eq_list (add_env empty_env x tau) c_list)) x\"    \n  apply (induct c_list)\n   apply (auto)\n  apply (cut_tac ?l1.0=\"union_list (tvar_type_l (sol_subst_type (add_env empty_env x tau) a)) (tvar_type_l (sol_subst_type (add_env empty_env x tau) b))\"\n      and ?l2.0=\"tvar_eq_list (sol_subst_eq_list (add_env empty_env x tau) c_list)\" and x=\"x\" in dist_union_list_contain)\n   apply (auto)\n  apply (cut_tac ?l1.0=\"tvar_type_l (sol_subst_type (add_env empty_env x tau) a)\"\n      and ?l2.0=\"tvar_type_l (sol_subst_type (add_env empty_env x tau) b)\" and x=\"x\" in dist_union_list_contain)\n   apply (auto)\n   apply (cut_tac tau_x=\"tau\" and tau=\"a\" and x=\"x\" in sol_subst_type_list_contain)\n    apply (auto)\n  apply (cut_tac tau_x=\"tau\" and tau=\"b\" and x=\"x\" in sol_subst_type_list_contain)\n   apply (auto)\n  done\n    \nlemma eur_less_tvar_total: \"\\<lbrakk> \\<not> occurs tau x \\<rbrakk> \\<Longrightarrow>\n  length (tvar_eq_list (sol_subst_eq_list (add_env empty_env x tau) c_list)) \\<le>\n  length (rem_list (union_list (add_list (tvar_type_l tau) x) (tvar_eq_list c_list)) x)\"    \n  apply (rule_tac sub_list_less_length)\n   apply (rule_tac tvar_eq_fresh_list)\n  apply (rule_tac rem_sub_list)\n   apply (rule_tac sol_subst_sub_list)\n    apply (rule_tac union_sub_list1)\n    apply (rule_tac add_sub_list)\n    apply (rule_tac id_sub_list)    \n   apply (rule_tac union_sub_list2)\n   apply (rule_tac id_sub_list)\n  apply (rule_tac sol_subst_list_contain)\n  apply (simp)\n  done\n    \nlemma elim_unify_rel: \"\\<lbrakk> \\<not> occurs tau x \\<rbrakk> \\<Longrightarrow>\n  (sol_subst_eq_list (add_env empty_env x tau) c_list, (VarScheme x, tau) # c_list) \\<in> unify_rel\"\n  apply (case_tac \"\\<not> length (tvar_eq_list (sol_subst_eq_list (add_env empty_env x tau) c_list))\n     < length (union_list (add_list (tvar_type_l tau) x) (tvar_eq_list c_list))\")\n   apply (cut_tac tau=\"tau\" and x=\"x\" and c_list=\"c_list\" in eur_less_tvar_total)\n    apply (simp)\n   apply (cut_tac l=\"union_list (add_list (tvar_type_l tau) x) (tvar_eq_list c_list)\" and x=\"x\" in contain_rem_list_length)\n    apply (rule_tac union_list_contain1)\n    apply (simp add: add_list_def)\n   apply (auto)\n  apply (simp add: unify_rel_def)\n  apply (auto)\n    apply (simp_all add: tvar_total_def)\n  done\n    \nlemma dist_ut_term_less_length: \"\n  length (union_list (union_list (tvar_type_l t1) (tvar_type_l t2)) (union_list (union_list (tvar_type_l s1) (tvar_type_l s2)) (tvar_eq_list c_t))) \\<le>\n  length (union_list (union_list (union_list (tvar_type_l t1) (tvar_type_l s1)) (union_list (tvar_type_l t2) (tvar_type_l s2))) (tvar_eq_list c_t))\"    \n  apply (rule_tac sub_list_less_length)\n   apply (rule_tac union_fresh_list)\n    apply (rule_tac union_fresh_list)\n     apply (rule_tac tvar_type_fresh_list)\n    apply (rule_tac tvar_type_fresh_list)\n   apply (rule_tac union_fresh_list)\n    apply (rule_tac union_fresh_list)\n     apply (rule_tac tvar_type_fresh_list)\n    apply (rule_tac tvar_type_fresh_list)\n   apply (rule_tac tvar_eq_fresh_list)\n  apply (rule_tac dist_union_sub_list)\n   apply (rule_tac union_sub_list1)\n   apply (rule_tac dist_union_sub_list)\n    apply (rule_tac union_sub_list1)\n    apply (rule_tac union_sub_list1)\n    apply (rule_tac id_sub_list)\n   apply (rule_tac union_sub_list2)\n   apply (rule_tac union_sub_list1)\n   apply (rule_tac id_sub_list)\n  apply (rule_tac dist_union_sub_list)\n   apply (rule_tac union_sub_list1)\n   apply (rule_tac dist_union_sub_list)\n    apply (rule_tac union_sub_list1)\n    apply (rule_tac union_sub_list2)\n    apply (rule_tac id_sub_list)\n   apply (rule_tac union_sub_list2)\n   apply (rule_tac union_sub_list2)\n   apply (rule_tac id_sub_list)\n  apply (rule_tac union_sub_list2)\n  apply (rule_tac id_sub_list)\n  done\n    \nfunction unify_type where\n  \"unify_type [] = Some (empty_env, [])\"\n| \"unify_type ((tau1, tau2) # c_t) = (case (tau1, tau2) of\n    (VarScheme a, tau_x) \\<Rightarrow>\n      if tau_x = VarScheme a then unify_type c_t\n      else if occurs tau_x a then None\n      else (case unify_type (sol_subst_eq_list (add_env empty_env a tau_x) c_t) of\n        None \\<Rightarrow> None\n        | Some (sigma, p_list) \\<Rightarrow> Some (add_env sigma a (sol_subst_type sigma tau_x), p_list)\n      )\n    | (tau_x, VarScheme a) \\<Rightarrow> unify_type ((VarScheme a, tau_x) # c_t)\n    | (ArrayScheme t, ArrayScheme s) \\<Rightarrow> unify_type ((t, s) # c_t)\n    | (PairScheme t1 t2 p, PairScheme s1 s2 q) \\<Rightarrow> (case unify_type ((t1, s1) # (t2, s2) # c_t) of\n      None \\<Rightarrow> None\n      | Some (sigma, p_list) \\<Rightarrow> Some (sigma, (p, q) # p_list)\n    )\n    | (FunScheme t1 t2 p a, FunScheme s1 s2 q b) \\<Rightarrow> (case unify_type ((t1, s1) # (t2, s2) # c_t) of\n      None \\<Rightarrow> None\n      | Some (sigma, p_list) \\<Rightarrow> Some (sigma, (p, q) # (as_perm_s a, as_perm_s b) # p_list)\n    )\n    | (ChanScheme t c_end, ChanScheme s c_end') \\<Rightarrow> if c_end = c_end' then unify_type ((t, s) # c_t) else None\n    | (t1, t2) \\<Rightarrow> if t1 = t2 then unify_type c_t else None\n  )\"\n  by pat_completeness auto\ntermination\n  apply (relation \"unify_rel\")\n                      apply (auto)\n    (* simple cases *)\n                  apply (simp add: unify_rel_def)\n                 apply (simp_all add: simp_unify_rel)\n             apply (simp_all add: orient_unify_rel)\n    (* elim case *)\n      apply (simp add: elim_unify_rel)\n    (* decomp cases *)\n     apply (simp add: unify_rel_def)\n     apply (simp add: tvar_total_def)\n    apply (simp add: unify_rel_def)\n    apply (cut_tac ?t1.0=\"x61\" and ?t2.0=\"x61a\" and ?s1.0=\"x62\" and ?s2.0=\"x62a\" and c_t=\"c_t\" in dist_ut_term_less_length)\n    apply (simp add: tvar_total_def)\n    apply (auto)\n   apply (simp add: unify_rel_def)\n   apply (cut_tac ?t1.0=\"x71\" and ?t2.0=\"x71a\" and ?s1.0=\"x72\" and ?s2.0=\"x72a\" and c_t=\"c_t\" in dist_ut_term_less_length)\n   apply (simp add: tvar_total_def)\n   apply (auto)\n  apply (simp add: unify_rel_def)\n  apply (simp add: tvar_total_def)\n  done\n\nfun perm_subst_type where\n  \"perm_subst_type p_sub (ArrayScheme tau) = ArrayScheme (perm_subst_type p_sub tau)\"\n| \"perm_subst_type p_sub (PairScheme t1 t2 r) = PairScheme (perm_subst_type p_sub t1) (perm_subst_type p_sub t2) (SPerm (sol_subst_perm p_sub r))\"\n| \"perm_subst_type p_sub (FunScheme t1 t2 r a) =\n  FunScheme (perm_subst_type p_sub t1) (perm_subst_type p_sub t2) (SPerm (sol_subst_perm p_sub r)) (AffConst (sol_subst_aff p_sub a))\"    \n| \"perm_subst_type p_sub (ChanScheme tau c_end) = ChanScheme (perm_subst_type p_sub tau) c_end\"\n| \"perm_subst_type p_sub tau_v = tau_v\"  \n  \nfun type_eq_sat_f where\n  \"type_eq_sat_f t_sub p_sub [] = True\"\n| \"type_eq_sat_f t_sub p_sub ((a, b) # c_t) = (perm_subst_type p_sub (sol_subst_type t_sub a) =\n  perm_subst_type p_sub (sol_subst_type t_sub b) \\<and> type_eq_sat_f t_sub p_sub c_t)\"\n  \ndefinition type_eq_sat where\n  \"type_eq_sat t_sub p_sub c_list = type_eq_sat_f t_sub p_sub c_list\" \n  \nfun type_contains_f where\n  \"type_contains_f tau tau' = (if tau = tau' then True else case tau' of\n    ArrayScheme tau_x \\<Rightarrow> type_contains_f tau tau_x\n    | PairScheme t1 t2 r \\<Rightarrow> type_contains_f tau t1 \\<or> type_contains_f tau t2\n    | FunScheme t1 t2 p q \\<Rightarrow> type_contains_f tau t1 \\<or> type_contains_f tau t2\n    | ChanScheme tau_x c_end \\<Rightarrow> type_contains_f tau tau_x\n    | tau_x \\<Rightarrow> False\n  )\"\n  \ndefinition type_contains where\n  \"type_contains tau tau' = type_contains_f tau tau'\"  \n  \n    (* if a is in tau, then t_sub(tau) will contain t_sub(a) *)(*\nlemma occurs_type_contains: \"\\<lbrakk> occurs tau a; t_sub a = Some tau_x \\<rbrakk> \\<Longrightarrow> type_contains tau_x (part_subst_type t_sub tau)\"  \n  apply (induct tau)\n         apply (auto)\n        apply (simp add: type_contains_def)\n  done*)\n    \nlemma array_no_self: \"ArrayScheme tau \\<noteq> tau\"  \n  apply (induct tau)\n         apply (auto)\n  done\n\nlemma pair_no_self1: \"PairScheme t1 t2 r \\<noteq> t1\"  \n  apply (induct t1)\n         apply (auto)\n  done\n\nlemma pair_no_self2: \"PairScheme t1 t2 r \\<noteq> t2\"  \n  apply (induct t2)\n         apply (auto)\n  done    \n    \nlemma fun_no_self1: \"FunScheme t1 t2 p q \\<noteq> t1\"  \n  apply (induct t1)\n         apply (auto)\n  done\n\nlemma fun_no_self2: \"FunScheme t1 t2 p q \\<noteq> t2\"  \n  apply (induct t2)\n         apply (auto)\n  done\n    \nlemma chan_no_self: \"ChanScheme tau c_end \\<noteq> tau\"  \n  apply (induct tau)\n         apply (auto)\n  done\n    \nlemma type_contains_less_cons: \"\\<lbrakk> type_contains tau tau'; tau \\<noteq> tau' \\<rbrakk> \\<Longrightarrow> type_cons tau < type_cons tau'\"\n  apply (induct tau')\n         apply (auto)\n         apply (simp add: type_contains_def)\n        apply (simp add: type_contains_def)\n       apply (simp add: type_contains_def)\n      apply (simp add: type_contains_def)\n     apply (case_tac \"tau = tau'\")\n      apply (auto)\n     apply (simp add: type_contains_def)\n    apply (case_tac \"tau = tau'1\")\n     apply (auto)\n    apply (case_tac \"tau = tau'2\")\n     apply (auto)\n    apply (simp add: type_contains_def)\n    apply (auto)\n   apply (case_tac \"tau = tau'1\")\n    apply (auto)\n   apply (case_tac \"tau = tau'2\")\n    apply (auto)\n   apply (simp add: type_contains_def)\n   apply (auto)\n  apply (case_tac \"tau = tau'\")\n   apply (auto)\n  apply (simp add: type_contains_def)\n  done\n    \nlemma trans_type_contains: \"\\<lbrakk> type_contains tau_a tau_b; type_contains tau_b tau_c \\<rbrakk> \\<Longrightarrow> type_contains tau_a tau_c\"    \n  apply (induct tau_c)\n         apply (auto)\n    (* int case *)\n         apply (simp add: type_contains_def)\n         apply (case_tac tau_b)\n                apply (auto)\n         apply (case_tac tau_a)\n                apply (auto)\n    (* unit case *)\n        apply (simp add: type_contains_def)\n        apply (case_tac tau_b)\n               apply (auto)\n        apply (case_tac tau_a)\n               apply (auto)\n    (* bool case *)\n       apply (simp add: type_contains_def)\n       apply (case_tac tau_b)\n              apply (auto)\n       apply (case_tac tau_a)\n              apply (auto)\n    (* var case *)\n      apply (simp add: type_contains_def)\n      apply (case_tac tau_b)\n             apply (auto)\n      apply (case_tac tau_a)\n             apply (auto)\n      apply (case_tac \"x4 = x\")\n       apply (auto)\n      apply (case_tac \"x4a = x\")\n       apply (auto)\n    (* array case *)\n     apply (case_tac \"\\<not> type_contains tau_b tau_c\")\n      apply (case_tac \"tau_b \\<noteq> tau_c\")\n       apply (simp add: type_contains_def)\n       apply (case_tac tau_b)\n              apply (auto)\n       apply (case_tac \"x5 = tau_c\")\n        apply (auto)\n      apply (simp add: type_contains_def)\n     apply (simp add: type_contains_def)\n    (* pair case *)\n    apply (case_tac \"type_contains tau_b tau_c1\")\n     apply (auto)\n     apply (simp add: type_contains_def)\n    apply (case_tac \"type_contains tau_b tau_c2\")\n     apply (auto)\n     apply (simp add: type_contains_def)\n    apply (case_tac \"tau_b \\<noteq> PairScheme tau_c1 tau_c2 x3\")\n     apply (simp add: type_contains_def)\n    apply (auto)\n    (* fun case *)\n   apply (case_tac \"type_contains tau_b tau_c1\")\n    apply (auto)\n    apply (simp add: type_contains_def)\n   apply (case_tac \"type_contains tau_b tau_c2\")\n    apply (auto)\n    apply (simp add: type_contains_def)\n   apply (case_tac \"tau_b \\<noteq> FunScheme tau_c1 tau_c2 x3 x4a\")\n    apply (simp add: type_contains_def)\n   apply (auto)\n    (* chan case *)\n  apply (case_tac \"type_contains tau_b tau_c\")\n   apply (auto)\n   apply (simp add: type_contains_def)\n  apply (case_tac \"tau_b \\<noteq> ChanScheme tau_c x2\")\n   apply (simp add: type_contains_def)\n  apply (auto)\n  done\n\nlemma occurs_less_cons_ih: \"\\<lbrakk> occurs tau a; tau \\<noteq> VarScheme a; t_sub a = Some tau_x \\<rbrakk> \\<Longrightarrow> type_cons tau_x < type_cons (sol_subst_type t_sub tau)\"    \n  apply (induct tau)\n         apply (auto)\n       apply (case_tac \"tau = VarScheme a\")\n        apply (auto)\n      apply (case_tac \"tau1 = VarScheme a\")\n       apply (auto)\n     apply (case_tac \"tau2 = VarScheme a\")\n      apply (auto)\n    apply (case_tac \"tau1 = VarScheme a\")\n     apply (auto)\n   apply (case_tac \"tau2 = VarScheme a\")\n    apply (auto)\n  apply (case_tac \"tau = VarScheme a\")\n   apply (auto)\n  done\n    \nlemma occurs_less_cons: \"\\<lbrakk> occurs tau a; tau \\<noteq> VarScheme a \\<rbrakk> \\<Longrightarrow> type_cons (sol_subst_type t_sub (VarScheme a)) < type_cons (sol_subst_type t_sub tau)\"      \n  apply (auto)\n  apply (case_tac \"t_sub a\")\n   apply (auto)\n   apply (case_tac tau)\n          apply (auto)\n  apply (rule_tac occurs_less_cons_ih)\n    apply (auto)\n  done\n  \n    (*\n      base case - in the base case, say that we have array(a). obviously array(t_sub(a)) \\<noteq> t_sub(a).\n      inductive case - say that we have array(tau), where t_sub(tau) \\<noteq> t_sub(a).\n        we want to show that array(t_sub(tau)) \\<noteq> t_sub(a) either. this would only be possible if t_sub(tau) was\n        smaller than t_sub(a). so we want to know that t_sub(tau) is not contained in t_sub(a)\n    *)\nlemma occurs_not_sub_contains: \"\\<lbrakk> occurs tau a; tau \\<noteq> VarScheme a; t_sub a = Some tau_x \\<rbrakk> \\<Longrightarrow> \\<not> type_contains (sol_subst_type t_sub tau) tau_x\"\n  apply (induct tau)\n         apply (auto)\n    (* array case. say that tau = a. then we must show that array(t_sub(a)) \\<notin> t_sub(a). *)\n       apply (case_tac \"tau = VarScheme a\")\n        apply (simp)\n        apply (cut_tac tau=\"ArrayScheme tau_x\" and tau'=\"tau_x\" in type_contains_less_cons)\n          apply (auto)\n        apply (simp add: array_no_self)\n    (* - otherwise, we use containment transitivity *)\n       apply (cut_tac tau_a=\"sol_subst_type t_sub tau\" and tau_b=\"ArrayScheme (sol_subst_type t_sub tau)\" and tau_c=\"tau_x\" in trans_type_contains)\n         apply (simp add: type_contains_def)\n        apply (auto)\n    (* pair case 1. *)\n      apply (case_tac \"tau1 = VarScheme a\")\n       apply (simp)\n       apply (cut_tac tau=\"PairScheme tau_x (sol_subst_type t_sub tau2) x3\" and tau'=\"tau_x\" in type_contains_less_cons)\n         apply (auto)\n       apply (simp add: pair_no_self1)\n      apply (cut_tac tau_a=\"sol_subst_type t_sub tau1\" and tau_b=\"PairScheme (sol_subst_type t_sub tau1) (sol_subst_type t_sub tau2) x3\"\n        and tau_c=\"tau_x\" in trans_type_contains)\n        apply (simp add: type_contains_def)\n       apply (auto)\n    (* pair case 2. *)\n      apply (case_tac \"tau2 = VarScheme a\")\n      apply (simp)\n      apply (cut_tac tau=\"PairScheme (sol_subst_type t_sub tau1) tau_x x3\" and tau'=\"tau_x\" in type_contains_less_cons)\n        apply (auto)\n      apply (simp add: pair_no_self2)\n     apply (cut_tac tau_a=\"sol_subst_type t_sub tau2\" and tau_b=\"PairScheme (sol_subst_type t_sub tau1) (sol_subst_type t_sub tau2) x3\"\n        and tau_c=\"tau_x\" in trans_type_contains)\n       apply (simp add: type_contains_def)\n      apply (auto)\n    (* fun case 1. *)\n    apply (case_tac \"tau1 = VarScheme a\")\n     apply (simp)\n     apply (cut_tac tau=\"FunScheme (sol_subst_type t_sub tau1) (sol_subst_type t_sub tau2) x3 x4a\" and tau'=\"tau_x\" in type_contains_less_cons)\n       apply (auto)\n     apply (simp add: fun_no_self1)\n    apply (cut_tac tau_a=\"sol_subst_type t_sub tau1\" and tau_b=\"FunScheme (sol_subst_type t_sub tau1) (sol_subst_type t_sub tau2) x3 x4a\"\n        and tau_c=\"tau_x\" in trans_type_contains)\n      apply (simp add: type_contains_def)\n     apply (auto)\n    (* fun case 2. *)\n   apply (case_tac \"tau2 = VarScheme a\")\n    apply (simp)\n    apply (cut_tac tau=\"FunScheme (sol_subst_type t_sub tau1) tau_x x3 x4a\" and tau'=\"tau_x\" in type_contains_less_cons)\n      apply (auto)\n    apply (simp add: fun_no_self2)\n   apply (cut_tac tau_a=\"sol_subst_type t_sub tau2\" and tau_b=\"FunScheme (sol_subst_type t_sub tau1) (sol_subst_type t_sub tau2) x3 x4a\"\n        and tau_c=\"tau_x\" in trans_type_contains)\n     apply (simp add: type_contains_def)\n    apply (auto)\n    (* chan case. *)\n  apply (case_tac \"tau = VarScheme a\")\n   apply (simp)\n   apply (cut_tac tau=\"ChanScheme tau_x x2\" and tau'=\"tau_x\" in type_contains_less_cons)\n     apply (auto)\n   apply (simp add: chan_no_self)\n  apply (cut_tac tau_a=\"sol_subst_type t_sub tau\" and tau_b=\"ChanScheme (sol_subst_type t_sub tau) x2\" and tau_c=\"tau_x\" in trans_type_contains)\n    apply (simp add: type_contains_def)\n   apply (auto)\n  done\n    \n    (* if a is in tau, and a \\<noteq> tau, then t_sub(a) \\<noteq> t_sub(tau) *)\nlemma occurs_not_sub_eq: \"\\<lbrakk> occurs tau a; tau \\<noteq> VarScheme a \\<rbrakk> \\<Longrightarrow> (sol_subst_type t_sub (VarScheme a)) \\<noteq> sol_subst_type t_sub tau\"  \n  apply (auto)\n  apply (case_tac \"t_sub a\")\n   apply (auto)\n   apply (case_tac tau)\n          apply (auto)\n  apply (cut_tac t_sub=\"t_sub\" and tau=\"tau\" and a=\"a\" and tau_x=\"sol_subst_type t_sub tau\" in occurs_not_sub_contains)\n     apply (auto)\n  apply (simp add: type_contains_def)\n  done\n    \nlemma sol_subst_type_eq: \"\\<lbrakk> perm_subst_type p_sub (sol_subst_type t_sub (VarScheme a)) = perm_subst_type p_sub (sol_subst_type t_sub t) \\<rbrakk> \\<Longrightarrow>\n  perm_subst_type p_sub (sol_subst_type t_sub (sol_subst_type (add_env empty_env a t) tau)) = perm_subst_type p_sub (sol_subst_type t_sub tau)\"    \n  apply (induct tau)\n         apply (auto)\n  apply (simp add: add_env_def)\n  apply (simp add: empty_env_def)\n  apply (auto)\n  done\n    \nlemma intern_sol_subst_type_eq_sat: \"\\<lbrakk> type_eq_sat_f t_sub p_sub c_list;\n  perm_subst_type p_sub (sol_subst_type t_sub (VarScheme a)) = perm_subst_type p_sub (sol_subst_type t_sub tau) \\<rbrakk> \\<Longrightarrow>\n  type_eq_sat_f t_sub p_sub (sol_subst_eq_list (add_env empty_env a tau) c_list)\"\n  apply (induct c_list)\n   apply (auto)\n  apply (simp add: sol_subst_type_eq)\n  done\n    \nlemma perm_subst_same_cons: \"type_cons tau = type_cons (perm_subst_type p_sub tau)\"    \n  apply (induct tau)\n         apply (auto)\n  done\n    \n    (*\nlemma unify_type_unsat: \"\\<lbrakk> unify_type c_list = None \\<rbrakk> \\<Longrightarrow> \\<not> type_eq_sat t_sub p_sub c_list\"\n  apply (simp add: type_eq_sat_def)\n  apply (induct rule: unify_type.pelims)\n    apply (auto)\n    *)\n\nlemma unify_type_unsat: \"\\<lbrakk> unify_type c_list = None \\<rbrakk> \\<Longrightarrow> \\<not> type_eq_sat t_sub p_sub c_list\"\n  apply (simp add: type_eq_sat_def)\n  apply (induct rule: wf_induct [where r=unify_rel])\n   apply (auto)\n   apply (simp add: unify_rel_def)\n  apply (case_tac x)\n   apply (auto)\n    (* elim case *)\n  apply (case_tac \"\\<exists> a'. a = VarScheme a'\")\n   apply (auto)\n   apply (case_tac \"b = VarScheme a'\")\n    apply (auto)\n    apply (simp add: simp_unify_rel)\n   apply (case_tac \"occurs b a'\")\n    apply (auto)\n    apply (cut_tac t_sub=\"t_sub\" and tau=\"b\" and a=\"a'\" in occurs_less_cons)\n      apply (auto)\n    apply (cut_tac tau=\"sol_subst_type t_sub (VarScheme a')\" and p_sub=\"p_sub\" in perm_subst_same_cons)\n    apply (cut_tac tau=\"sol_subst_type t_sub b\" and p_sub=\"p_sub\" in perm_subst_same_cons)\n    apply (auto)\n   apply (case_tac \"unify_type (sol_subst_eq_list (add_env empty_env a' b) list)\")\n    apply (auto)\n    (* - here we have to prove that if list[b / a'] is unsolvable, then list itself is unsatisfiable.\n        we know that 'a \\<rightarrow> t_sub('b) in t_sub by the current equality, which we can use to relate the two.\n     *)\n   apply (erule_tac x=\"sol_subst_eq_list (add_env empty_env a' b) list\" in allE)\n   apply (simp add: elim_unify_rel)\n   apply (simp add: intern_sol_subst_type_eq_sat)\n    (* orient case *)\n  apply (case_tac \"\\<exists> b'. b = VarScheme b'\")\n   apply (auto)\n   apply (erule_tac x=\" (VarScheme b', a) # list\" in allE)\n   apply (simp add: orient_unify_rel)\n   apply (case_tac a)\n          apply (auto)\n    (* decomp case. int *)\n  apply (case_tac a)\n         apply (auto)\n        apply (case_tac b)\n               apply (auto)\n        apply (simp add: simp_unify_rel)\n    (* - unit case *)\n       apply (case_tac b)\n              apply (auto)\n       apply (simp add: simp_unify_rel)\n    (* - bool case *)\n      apply (case_tac b)\n             apply (auto)\n      apply (simp add: simp_unify_rel)\n    (* - array case *)\n     apply (case_tac b)\n            apply (auto)\n     apply (erule_tac x=\"(x5, x5a) # list\" in allE)\n     apply (simp add: unify_rel_def)\n     apply (simp add: tvar_total_def)\n    (* - pair case *)\n    apply (case_tac b)\n           apply (auto)\n    apply (erule_tac x=\"(x61, x61a) # (x62, x62a) # list\" in allE)\n    apply (simp add: unify_rel_def)\n    apply (cut_tac ?t1.0=\"x61\" and ?t2.0=\"x61a\" and ?s1.0=\"x62\" and ?s2.0=\"x62a\" and c_t=\"list\" in dist_ut_term_less_length)\n    apply (simp add: tvar_total_def)\n    apply (auto)\n    (* - fun case *)\n   apply (case_tac b)\n          apply (auto)\n   apply (erule_tac x=\"(x71, x71a) # (x72, x72a) # list\" in allE)\n   apply (simp add: unify_rel_def)\n   apply (cut_tac ?t1.0=\"x71\" and ?t2.0=\"x71a\" and ?s1.0=\"x72\" and ?s2.0=\"x72a\" and c_t=\"list\" in dist_ut_term_less_length)\n   apply (simp add: tvar_total_def)\n   apply (auto)\n    (* - chan case *)\n  apply (case_tac b)\n         apply (auto)\n  apply (erule_tac x=\"(x81, x81a) # list\" in allE)\n  apply (simp add: unify_rel_def)\n  apply (simp add: tvar_total_def)\n  done\n\nlemma add_env_eq: \"\\<lbrakk> env x = Some tau \\<rbrakk> \\<Longrightarrow> env = add_env env x tau\"  \n  apply (case_tac \"\\<forall> x'. env x' = add_env env x tau x'\")\n   apply (auto)\n  apply (simp add: add_env_def)\n  apply (case_tac \"x = x'\")\n   apply (auto)\n  done\n  \nfun perm_eq_sat_f where\n  \"perm_eq_sat_f p_sub [] = True\"\n| \"perm_eq_sat_f p_sub ((p, q) # p_t) = (sol_subst_perm p_sub p = sol_subst_perm p_sub q \\<and> perm_eq_sat_f p_sub p_t)\"    \n  \ndefinition perm_eq_sat where\n  \"perm_eq_sat p_sub c_list = perm_eq_sat_f p_sub c_list\"  \n  \nfun apply_type_subst where\n  \"apply_type_subst t_sub a = (case t_sub a of\n    None \\<Rightarrow> VarScheme a\n    | Some tau \\<Rightarrow> tau\n  )\"\n  \ntype_synonym perm_var_subst = \"s_perm subst_env\" \n  \nfun equiv_scheme where\n  \"equiv_scheme (ArrayScheme tau) tau' = (\\<exists> tau_x. tau' = ArrayScheme tau_x \\<and> equiv_scheme tau tau_x)\"\n| \"equiv_scheme (PairScheme t1 t2 r) tau' = (\\<exists> t1x t2x q. tau' = PairScheme t1x t2x q \\<and> equiv_scheme t1 t1x \\<and> equiv_scheme t2 t2x)\"\n| \"equiv_scheme (FunScheme t1 t2 r a) tau' = (\\<exists> t1x t2x q a'. tau' = FunScheme t1x t2x q a' \\<and> equiv_scheme t1 t1x \\<and> equiv_scheme t2 t2x)\"\n| \"equiv_scheme (ChanScheme tau c_end) tau' = (\\<exists> tau_x. tau' = ChanScheme tau_x c_end \\<and> equiv_scheme tau tau_x)\"\n| \"equiv_scheme tau tau' = (tau = tau')\"  \n    \nlemma id_equiv_scheme: \"equiv_scheme tau tau\"  \n  apply (induct tau)\n         apply (auto)\n  done\n    \ndefinition equiv_sub where\n  \"equiv_sub t_sub t_sub' = (\\<forall> x. apply_type_subst t_sub x = apply_type_subst t_sub' x)\"\n\ndefinition subst_compose where\n  \"subst_compose t_sub t_sub' = (\\<lambda> x. case t_sub x of\n    None \\<Rightarrow> t_sub' x\n    | Some tau \\<Rightarrow> Some (sol_subst_type t_sub' tau)\n  )\"    \n    (*\nfun perm_var_subst_perm where\n  \"perm_var_subst_perm p_sub (SPerm p) = SPerm p\"\n| \"perm_var_subst_perm p_sub (SVar r) = (case p_sub r of\n    None \\<Rightarrow> SVar r\n    | Some p \\<Rightarrow> p\n  )\"  \n \nfun as_aff_s where\n  \"as_aff_s (SPerm p) = AffConst (as_aff p)\"  \n| \"as_aff_s (SVar r) = AffVar r\"  \n  \nfun perm_var_subst_aff where\n  \"perm_var_subst_aff p_sub (AffConst a) = AffConst a\"\n| \"perm_var_subst_aff p_sub (AffVar r) = (case p_sub r of\n    None \\<Rightarrow> AffVar r\n    | Some p \\<Rightarrow> as_aff_s p\n  )\"\n  \nfun perm_var_subst_type where\n  \"perm_var_subst_type p_sub (ArrayScheme tau) = ArrayScheme (perm_var_subst_type p_sub tau)\"  \n| \"perm_var_subst_type p_sub (PairScheme t1 t2 r) =\n  PairScheme (perm_var_subst_type p_sub t1) (perm_var_subst_type p_sub t2) (perm_var_subst_perm p_sub r)\"  \n| \"perm_var_subst_type p_sub (FunScheme t1 t2 r a) =\n  FunScheme (perm_var_subst_type p_sub t1) (perm_var_subst_type p_sub t2) (perm_var_subst_perm p_sub r) (perm_var_subst_aff p_sub a)\"  \n| \"perm_var_subst_type p_sub (ChanScheme tau c_end) = ChanScheme (perm_var_subst_type p_sub tau) c_end\"  \n| \"perm_var_subst_type p_sub tau = tau\"  *)\n  \ndefinition perm_compose where\n  \"perm_compose p_sub t_sub = (\\<lambda> x. case t_sub x of\n    None \\<Rightarrow> None\n    | Some tau \\<Rightarrow> Some (perm_subst_type p_sub tau)\n  )\"  \n  \nlemma empty_compose_equiv_sub: \"equiv_sub (subst_compose empty_env t_sub) t_sub\"  \n  apply (simp add: equiv_sub_def)\n  apply (simp add: subst_compose_def)\n  apply (simp add: empty_env_def)(*\n  apply (auto)\n  apply (rule_tac id_equiv_scheme)*)\n  done\n    \ndefinition wf_sub where\n  \"wf_sub t_sub = (\\<forall> x. case t_sub x of\n    None \\<Rightarrow> True\n    | Some tau_x \\<Rightarrow> (\\<forall> y. case t_sub y of\n      None \\<Rightarrow> True\n      | Some tau \\<Rightarrow> x \\<notin> tvar_type tau\n    )\n  )\"\n  \ndefinition type_sub_range where\n  \"type_sub_range t_sub = { x | x. \\<exists> y. case t_sub y of None \\<Rightarrow> False | Some tau \\<Rightarrow> x \\<in> tvar_type tau }\"  \n  \nlemma tvar_type_occurs: \"\\<lbrakk> a \\<in> tvar_type tau \\<rbrakk> \\<Longrightarrow> occurs tau a\" \n  apply (induct tau)\n         apply (auto)\n  done\n    \nlemma sol_subst_tvar_type: \"\\<lbrakk> a \\<notin> tvar_type tau; a \\<notin> type_sub_range t_sub \\<rbrakk> \\<Longrightarrow> a \\<notin> tvar_type (sol_subst_type t_sub tau)\"    \n  apply (induct tau)\n         apply (auto)\n  apply (case_tac \"t_sub x\")\n   apply (auto)\n  apply (simp add: type_sub_range_def)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  done\n    \nlemma wf_sol_subst_tvar_type: \"\\<lbrakk> wf_sub t_sub; t_sub x = Some tau' \\<rbrakk> \\<Longrightarrow> x \\<notin> tvar_type (sol_subst_type t_sub tau)\"    \n  apply (induct tau)\n         apply (auto)\n  apply (case_tac \"t_sub xa\")\n   apply (auto)\n  apply (simp add: wf_sub_def)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (auto)\n  done\n    \nlemma add_wf_sub: \"\\<lbrakk> \\<not> occurs tau a; a \\<notin> type_sub_range t_sub; wf_sub t_sub \\<rbrakk> \\<Longrightarrow> wf_sub (add_env t_sub a (sol_subst_type t_sub tau))\"\n    (* we must show that for all x in the new t_sub, x does not appear on the right-hand side of any assignment y *)\n  apply (simp add: wf_sub_def)\n  apply (auto)\n  apply (simp add: add_env_def)\n  apply (auto)\n    (* x = a, x = y (showing a does not appear in tau) *)\n    apply (case_tac \"a \\<in> tvar_type tau\")\n     apply (simp add: tvar_type_occurs)\n    apply (cut_tac a=\"a\" and tau=\"tau\" in sol_subst_tvar_type)\n    apply (auto)\n    (* x = a, x \\<noteq> y (showing a does not appear on the right-hand side of anything else) *)\n   apply (case_tac \"t_sub y\")\n    apply (auto)\n   apply (simp add: type_sub_range_def)\n   apply (erule_tac x=\"y\" in allE)\n   apply (auto)\n    (* x \\<noteq> a *)\n  apply (case_tac \"t_sub x\")\n   apply (auto)\n  apply (simp add: add_env_def)\n    (* a = y (showing that none of the xs appear in the right-hand side of tau) *)\n  apply (auto)\n   apply (simp add: type_sub_range_def)\n   apply (erule_tac x=\"x\" in allE)\n   apply (auto)\n   apply (cut_tac x=\"x\" and t_sub=\"t_sub\" and tau=\"tau\" and tau'=\"aa\" in wf_sol_subst_tvar_type)\n     apply (auto)\n   apply (simp add: wf_sub_def)\n    (* a \\<noteq> y (showing that none of the xs appear on the right-hand side of another) *)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  done\n    \nlemma dist_sol_subst_type_list_contain: \"\\<lbrakk> \\<not> occurs tau_x x; \\<not> occurs tau x \\<rbrakk> \\<Longrightarrow>\n  \\<not> list_contain (tvar_type_l (sol_subst_type (add_env empty_env a tau_x) tau)) x\"    \n  apply (induct tau)\n         apply (auto)\n    apply (simp add: add_env_def)\n    apply (case_tac \"a = xa\")\n     apply (auto)\n     apply (cut_tac tau=\"tau_x\" and x=\"x\" in occurs_list_contain)\n      apply (auto)\n    apply (simp add: empty_env_def)\n   apply (cut_tac ?l1.0=\"tvar_type_l (sol_subst_type (add_env empty_env a tau_x) tau1)\"\n      and ?l2.0=\"tvar_type_l (sol_subst_type (add_env empty_env a tau_x) tau2)\" and x=\"x\" in dist_union_list_contain)\n    apply (auto)\n  apply (cut_tac ?l1.0=\"tvar_type_l (sol_subst_type (add_env empty_env a tau_x) tau1)\"\n      and ?l2.0=\"tvar_type_l (sol_subst_type (add_env empty_env a tau_x) tau2)\" and x=\"x\" in dist_union_list_contain)\n   apply (auto)\n  done\n    \nlemma occurs_list_contain_rev: \"\\<lbrakk> \\<not> list_contain (tvar_type_l tau) x\\<rbrakk> \\<Longrightarrow> \\<not> occurs tau x\"    \n  apply (induct tau)\n         apply (auto)\n     apply (case_tac \"list_contain (tvar_type_l tau1) x\")\n      apply (cut_tac ?l1.0=\"tvar_type_l tau1\" and x=\"x\" in union_list_contain1)\n       apply (auto)\n    apply (case_tac \"list_contain (tvar_type_l tau2) x\")\n     apply (cut_tac ?l2.0=\"tvar_type_l tau2\" and x=\"x\" in union_list_contain2)\n      apply (auto)\n   apply (case_tac \"list_contain (tvar_type_l tau1) x\")\n    apply (cut_tac ?l1.0=\"tvar_type_l tau1\" and x=\"x\" in union_list_contain1)\n     apply (auto)\n  apply (case_tac \"list_contain (tvar_type_l tau2) x\")\n   apply (cut_tac ?l2.0=\"tvar_type_l tau2\" and x=\"x\" in union_list_contain2)\n    apply (auto)\n  done\n    \nlemma dist_sol_subst_list_contain: \"\\<lbrakk> \\<not> list_contain (tvar_eq_list c_list) x; \\<not> occurs tau x \\<rbrakk> \\<Longrightarrow>\n  \\<not> list_contain (tvar_eq_list (sol_subst_eq_list (add_env empty_env a tau) c_list)) x\"    \n  apply (induct c_list)\n   apply (auto)\n  apply (cut_tac ?l1.0=\"union_list (tvar_type_l (sol_subst_type (add_env empty_env a tau) aa)) (tvar_type_l (sol_subst_type (add_env empty_env a tau) b))\"\n      and ?l2.0=\"tvar_eq_list (sol_subst_eq_list (add_env empty_env a tau) c_list)\" and x=\"x\" in dist_union_list_contain)\n   apply (auto)\n  apply (cut_tac ?l1.0=\"tvar_type_l (sol_subst_type (add_env empty_env a tau) aa) \"\n      and ?l2.0=\"tvar_type_l (sol_subst_type (add_env empty_env a tau) b)\" and x=\"x\" in dist_union_list_contain)\n    apply (auto)\n    (* list containment for t1 *)\n    apply (cut_tac a=\"a\" and tau_x=\"tau\" and tau=\"aa\" and x=\"x\" in dist_sol_subst_type_list_contain)\n      apply (auto)\n    apply (cut_tac tau=\"aa\" and x=\"x\" in occurs_list_contain_rev)\n     apply (auto)\n    apply (cut_tac ?l1.0=\"tvar_type_l aa\" and ?l2.0=\"tvar_type_l b\" and x=\"x\" in union_list_contain1)\n     apply (auto)\n    apply (cut_tac ?l1.0=\"union_list (tvar_type_l aa) (tvar_type_l b)\" and ?l2.0=\"tvar_eq_list c_list\" and x=\"x\" in union_list_contain1)\n     apply (auto)\n    (* list containment for t2 *)\n   apply (cut_tac a=\"a\" and tau_x=\"tau\" and tau=\"b\" and x=\"x\" in dist_sol_subst_type_list_contain)\n     apply (auto)\n   apply (cut_tac tau=\"b\" and x=\"x\" in occurs_list_contain_rev)\n    apply (auto)\n   apply (cut_tac ?l1.0=\"tvar_type_l aa\" and ?l2.0=\"tvar_type_l b\" and x=\"x\" in union_list_contain2)\n    apply (auto)\n   apply (cut_tac ?l1.0=\"union_list (tvar_type_l aa) (tvar_type_l b)\" and ?l2.0=\"tvar_eq_list c_list\" and x=\"x\" in union_list_contain1)\n    apply (auto)\n    (* list containment for remainder *)\n  apply (case_tac \"list_contain (tvar_eq_list c_list) x\")\n   apply (cut_tac ?l1.0=\"union_list (tvar_type_l aa) (tvar_type_l b)\" and ?l2.0=\"tvar_eq_list c_list\" and x=\"x\" in union_list_contain2)\n    apply (auto)\n  done\n    \nlemma tvar_type_l_rel: \"\\<lbrakk> x \\<in> tvar_type tau \\<rbrakk> \\<Longrightarrow> list_contain (tvar_type_l tau) x\"    \n  apply (cut_tac tau=\"tau\" and a=\"x\" in tvar_type_occurs)\n   apply (auto)\n  apply (case_tac \"\\<not> list_contain (tvar_type_l tau) x\")\n   apply (cut_tac tau=\"tau\" and x=\"x\" in occurs_list_contain_rev)\n    apply (auto)\n  done\n\n(*\n    \\<not> list_contain (add_list (tvar_eq_list list) b') x; x \\<in> type_sub_range t_sub; list_contain (union_list (add_list [] b') (tvar_eq_list list)) x\n\n\\<not> list_contain (union_list (union_list (tvar_type_l x5) [b']) (tvar_eq_list list)) x; x \\<in> type_sub_range t_sub;\n        list_contain (union_list (add_list (tvar_type_l x5) b') (tvar_eq_list list)) \n\n*)\n    \nlemma orient_list_contain1: \"\\<lbrakk> \\<not> list_contain (add_list (tvar_eq_list list) y) x \\<rbrakk> \\<Longrightarrow> \\<not> list_contain (union_list (add_list [] y) (tvar_eq_list list)) x\"    \n  apply (auto)\n  apply (simp add: add_list_def)\n  done\n    \nlemma add_union_list_contain: \"\\<lbrakk> list_contain (add_list l a) x \\<rbrakk> \\<Longrightarrow> list_contain (union_list l [a]) x\"    \n  apply (induct l)\n   apply (auto)\n   apply (simp add: add_list_def)\n  apply (simp add: add_list_def)\n  apply (auto)\n   apply (case_tac \"a = aa \\<or> list_contain l a\")\n    apply (auto)\n  apply (case_tac \"a = aa \\<or> list_contain l a\")\n   apply (auto)\n  apply (case_tac \"list_contain l a\")\n   apply (auto)\n  done\n    \nlemma orient_list_contain2: \"\\<lbrakk> \\<not> list_contain (union_list (union_list l [a]) (tvar_eq_list list)) x \\<rbrakk> \\<Longrightarrow>\n  \\<not> list_contain (union_list (add_list l a) (tvar_eq_list list)) x\"    \n  apply (auto)\n  apply (cut_tac ?l1.0=\"add_list l a\" and ?l2.0=\"tvar_eq_list list\" and x=\"x\" in dist_union_list_contain)\n   apply (auto)\n   apply (cut_tac ?l1.0=\"union_list l [a]\" and ?l2.0=\"tvar_eq_list list\" and x=\"x\" in union_list_contain1)\n    apply (auto)\n   apply (rule_tac add_union_list_contain)\n   apply (auto)\n  apply (cut_tac ?l1.0=\"union_list l [a]\" and ?l2.0=\"tvar_eq_list list\" and x=\"x\" in union_list_contain2)\n   apply (auto)\n  done    \n\nlemma dist_union_list_contain_split: \"\\<lbrakk> \\<not> list_contain la x; \\<not> list_contain lb x \\<rbrakk> \\<Longrightarrow> \\<not> list_contain (union_list la lb) x\"    \n  apply (auto)\n  apply (cut_tac ?l1.0=\"la\" and ?l2.0=\"lb\" in dist_union_list_contain)\n   apply (auto)\n  done\n\nlemma dist_union_list_contain_split_ex: \"\\<lbrakk> list_contain (union_list la lb) x; list_contain la x \\<longrightarrow> X; list_contain lb x \\<longrightarrow> X \\<rbrakk> \\<Longrightarrow> X\"    \n  apply (auto)\n  apply (cut_tac ?l1.0=\"la\" and ?l2.0=\"lb\" in dist_union_list_contain)\n   apply (auto)\n  done    \n    \nlemma dist_ut_list_contain: \"\\<lbrakk> list_contain (union_list (union_list (tvar_type_l x61) (tvar_type_l x61a))\n  (union_list (union_list (tvar_type_l x62) (tvar_type_l x62a)) (tvar_eq_list list))) x \\<rbrakk> \\<Longrightarrow> list_contain (union_list (union_list\n  (union_list (tvar_type_l x61) (tvar_type_l x62)) (union_list (tvar_type_l x61a) (tvar_type_l x62a))) (tvar_eq_list list)) x\"    \n  apply (rule_tac dist_union_list_contain_split_ex)\n    apply (auto)\n   apply (rule_tac union_list_contain1)\n   apply (rule_tac la=\"tvar_type_l x61\" in dist_union_list_contain_split_ex)\n     apply (auto)\n    apply (rule_tac union_list_contain1)\n    apply (rule_tac union_list_contain1)\n    apply (simp)\n   apply (rule_tac union_list_contain2)\n   apply (rule_tac union_list_contain1)\n   apply (simp)\n  apply (rule_tac la=\"union_list (tvar_type_l x62) (tvar_type_l x62a)\" in dist_union_list_contain_split_ex)\n    apply (auto)\n   apply (rule_tac union_list_contain1)\n   apply (rule_tac la=\"tvar_type_l x62\" in dist_union_list_contain_split_ex)\n     apply (auto)\n    apply (rule_tac union_list_contain1)\n    apply (rule_tac union_list_contain2)\n    apply (simp)\n   apply (rule_tac union_list_contain2)\n   apply (rule_tac union_list_contain2)\n   apply (simp)\n  apply (rule_tac union_list_contain2)\n  apply (simp)\n  done\n    \nlemma dist_ut_list_contain_rev: \"\\<lbrakk> \\<not> list_contain (union_list (union_list\n  (union_list (tvar_type_l x61) (tvar_type_l x62)) (union_list (tvar_type_l x61a) (tvar_type_l x62a))) (tvar_eq_list list)) x \\<rbrakk> \\<Longrightarrow>\n  \\<not> list_contain (union_list (union_list (tvar_type_l x61) (tvar_type_l x61a))\n  (union_list (union_list (tvar_type_l x62) (tvar_type_l x62a)) (tvar_eq_list list))) x\"\n  apply (auto)\n  apply (simp add: dist_ut_list_contain)\n  done\n    \ndefinition utsr_res where\n  \"utsr_res t_sub x = (x \\<notin> type_sub_range t_sub \\<and> t_sub x = None)\"\n    \nlemma unify_type_sub_range_ih: \"\\<lbrakk> unify_type c_list = Some (t_sub, p_eq); \\<not> list_contain (tvar_eq_list c_list) x \\<rbrakk> \\<Longrightarrow> utsr_res t_sub x\" \n  apply (induct arbitrary: t_sub p_eq rule: wf_induct [where r=unify_rel])\n   apply (simp add: unify_rel_def) \n  apply (case_tac xa)\n   apply (auto)\n   apply (simp add: utsr_res_def)\n   apply (simp add: type_sub_range_def)\n   apply (simp add: empty_env_def)\n    (* var case. delete *)\n  apply (case_tac \"\\<exists> a'. a = VarScheme a'\")\n   apply (auto)\n   apply (case_tac \"b = VarScheme a'\")\n    apply (auto)\n    apply (erule_tac x=\"list\" in allE)\n    apply (simp add: simp_unify_rel)\n    apply (auto)\n    apply (cut_tac ?l1.0=\"add_list [a'] a'\" and ?l2.0=\"tvar_eq_list list\" and x=\"x\" in union_list_contain2)\n     apply (auto)\n    (* - occurs *)\n   apply (case_tac \"occurs b a'\")\n    apply (auto)\n    (* - elim *)\n   apply (case_tac \"unify_type (sol_subst_eq_list (add_env empty_env a' b) list)\")\n    apply (auto)\n   apply (erule_tac x=\"sol_subst_eq_list (add_env empty_env a' b) list\" in allE)\n   apply (auto)\n     apply (simp add: elim_unify_rel)\n    apply (cut_tac a=\"a'\" and tau=\"b\" and c_list=\"list\" and x=\"x\" in dist_sol_subst_list_contain)\n      apply (auto)\n     apply (cut_tac ?l1.0=\"add_list (tvar_type_l b) a'\" and ?l2.0=\"tvar_eq_list list\" and x=\"x\" in union_list_contain2)\n      apply (auto)\n    apply (cut_tac tau=\"b\" and x=\"x\" in occurs_list_contain_rev)\n     apply (auto)\n     apply (cut_tac ?l1.0=\"add_list (tvar_type_l b) a'\" and ?l2.0=\"tvar_eq_list list\" and x=\"x\" in union_list_contain1)\n     apply (auto)\n    apply (simp add: add_list_def)\n   apply (simp add: utsr_res_def)\n   apply (auto)\n    apply (simp add: type_sub_range_def)\n    apply (simp add: add_env_def)\n    apply (auto)\n    apply (case_tac \"a' = y\")\n     apply (auto)\n    apply (cut_tac a=\"x\" and t_sub=\"a\" and tau=\"b\" in sol_subst_tvar_type)\n      apply (auto)\n     apply (cut_tac tau=\"b\" and x=\"x\" in tvar_type_l_rel)\n      apply (auto)\n     apply (cut_tac ?l1.0=\"add_list (tvar_type_l b) y\" and ?l2.0=\"tvar_eq_list list\" and x=\"x\" in union_list_contain1)\n      apply (auto)\n     apply (simp add: add_list_def)\n    apply (simp add: type_sub_range_def)\n   apply (simp add: add_env_def)\n   apply (auto)\n   apply (case_tac \"list_contain (add_list (tvar_type_l b) x) x\")\n    apply (cut_tac ?l1.0=\"add_list (tvar_type_l b) x\" and ?l2.0=\"tvar_eq_list list\" and x=\"x\" in union_list_contain1)\n     apply (auto)\n   apply (simp add: add_list_def)\n   apply (case_tac \"list_contain (tvar_type_l b) x\")\n    apply (auto)\n    (* orient case *)\n  apply (case_tac \"\\<exists> b'. b = VarScheme b'\")\n   apply (auto)\n   apply (erule_tac x=\"(VarScheme b', a) # list\" in allE)\n   apply (auto)\n    apply (simp add: orient_unify_rel)\n   apply (case_tac a)\n    apply (auto)\n         apply (simp add: orient_list_contain1)\n        apply (simp add: orient_list_contain1)\n       apply (simp add: orient_list_contain1)\n      apply (simp add: orient_list_contain2)\n     apply (simp add: orient_list_contain2)\n    apply (simp add: orient_list_contain2)\n   apply (simp add: orient_list_contain2)\n    (* decomp case *)\n  apply (case_tac a)\n         apply (auto)\n        apply (case_tac b)\n               apply (auto)\n        apply (erule_tac x=\"list\" in allE)\n        apply (auto)\n        apply (simp add: simp_unify_rel)\n       apply (case_tac b)\n              apply (auto)\n       apply (erule_tac x=\"list\" in allE)\n       apply (auto)\n       apply (simp add: simp_unify_rel)\n      apply (case_tac b)\n             apply (auto)\n      apply (erule_tac x=\"list\" in allE)\n      apply (auto)\n      apply (simp add: simp_unify_rel)\n    (* - array case *)\n     apply (case_tac b)\n            apply (auto)\n     apply (erule_tac x=\"(x5, x5a) # list\" in allE)\n     apply (simp add: unify_rel_def)\n     apply (simp add: tvar_total_def)\n    (* - pair case *)\n    apply (case_tac b)\n           apply (auto)\n    apply (erule_tac x=\"(x61, x61a) # (x62, x62a) # list\" in allE)\n    apply (auto)\n     apply (simp add: unify_rel_def)\n     apply (cut_tac ?t1.0=\"x61\" and ?t2.0=\"x61a\" and ?s1.0=\"x62\" and ?s2.0=\"x62a\" and c_t=\"list\" in dist_ut_term_less_length)\n     apply (simp add: tvar_total_def)\n    apply (simp add: dist_ut_list_contain_rev)\n    apply (case_tac \"unify_type ((x61, x61a) # (x62, x62a) # list)\")\n     apply (auto)\n    (* - fun case *)\n   apply (case_tac b)\n          apply (auto)\n   apply (erule_tac x=\"(x71, x71a) # (x72, x72a) # list\" in allE)\n    apply (auto)\n    apply (simp add: unify_rel_def)\n    apply (cut_tac ?t1.0=\"x71\" and ?t2.0=\"x71a\" and ?s1.0=\"x72\" and ?s2.0=\"x72a\" and c_t=\"list\" in dist_ut_term_less_length)\n    apply (simp add: tvar_total_def)\n   apply (simp add: dist_ut_list_contain_rev)\n   apply (case_tac \"unify_type ((x71, x71a) # (x72, x72a) # list)\")\n    apply (auto)\n    (* - chan case *)\n  apply (case_tac b)\n         apply (auto)\n  apply (erule_tac x=\"(x81, x81a) # list\" in allE)\n  apply (auto)\n   apply (simp add: unify_rel_def)\n   apply (simp add: tvar_total_def)\n  apply (case_tac \"x82 = x82a\")\n   apply (auto)\n  done\n    \nlemma unify_type_sub_range: \"\\<lbrakk> unify_type c_list = Some (t_sub, p_eq); \\<not> list_contain (tvar_eq_list c_list) x \\<rbrakk> \\<Longrightarrow> x \\<notin> type_sub_range t_sub\"     \n  apply (cut_tac x=\"x\" and t_sub=\"t_sub\" in unify_type_sub_range_ih)\n    apply (auto)\n  apply (simp add: utsr_res_def)\n  done\n\nlemma unify_type_sub_dom: \"\\<lbrakk> unify_type c_list = Some (t_sub, p_eq); \\<not> list_contain (tvar_eq_list c_list) x \\<rbrakk> \\<Longrightarrow> t_sub x = None\"     \n  apply (cut_tac x=\"x\" and t_sub=\"t_sub\" in unify_type_sub_range_ih)\n    apply (auto)\n  apply (simp add: utsr_res_def)\n  done\n  \nlemma unify_type_wf_sub: \"\\<lbrakk> unify_type c_list = Some (t_sub, p_eq) \\<rbrakk> \\<Longrightarrow> wf_sub t_sub\"  \n  apply (induct arbitrary: t_sub p_eq rule: wf_induct [where r=unify_rel])\n   apply (simp add: unify_rel_def) \n  apply (case_tac x)\n   apply (auto)\n   apply (simp add: wf_sub_def)\n   apply (simp add: empty_env_def)\n    (* var case. delete *)\n  apply (case_tac \"\\<exists> a'. a = VarScheme a'\")\n   apply (auto)\n   apply (case_tac \"b = VarScheme a'\")\n    apply (auto)\n    apply (erule_tac x=\"list\" in allE)\n    apply (simp add: simp_unify_rel)\n    (* - occurs *)\n   apply (case_tac \"occurs b a'\")\n    apply (auto)\n    (* - elim *)\n   apply (case_tac \"unify_type (sol_subst_eq_list (add_env empty_env a' b) list)\")\n    apply (auto)\n   apply (erule_tac x=\"sol_subst_eq_list (add_env empty_env a' b) list\" in allE)\n   apply (simp add: elim_unify_rel)\n   apply (rule_tac add_wf_sub)\n     apply (auto)\n   apply (cut_tac t_sub=\"a\" and x=\"a'\" in unify_type_sub_range)\n     apply (auto)\n   apply (cut_tac x=\"a'\" and c_list=\"list\" in sol_subst_list_contain)\n    apply (auto)\n    (* orient case *)\n  apply (case_tac \"\\<exists> b'. b = VarScheme b'\")\n   apply (auto)\n   apply (erule_tac x=\"(VarScheme b', a) # list\" in allE)\n   apply (simp add: orient_unify_rel)\n   apply (case_tac a)\n          apply (auto)\n    (* decomp case *)\n  apply (case_tac a)\n         apply (auto)\n        apply (case_tac b)\n               apply (auto)\n        apply (erule_tac x=\"list\" in allE)\n        apply (auto)\n        apply (simp add: simp_unify_rel)\n       apply (case_tac b)\n              apply (auto)\n       apply (erule_tac x=\"list\" in allE)\n       apply (auto)\n       apply (simp add: simp_unify_rel)\n      apply (case_tac b)\n             apply (auto)\n      apply (erule_tac x=\"list\" in allE)\n      apply (auto)\n      apply (simp add: simp_unify_rel)\n    (* - array case *)\n     apply (case_tac b)\n            apply (auto)\n     apply (erule_tac x=\"(x5, x5a) # list\" in allE)\n     apply (simp add: unify_rel_def)\n     apply (simp add: tvar_total_def)\n    (* - pair case *)\n    apply (case_tac b)\n           apply (auto)\n    apply (erule_tac x=\"(x61, x61a) # (x62, x62a) # list\" in allE)\n    apply (auto)\n     apply (simp add: unify_rel_def)\n     apply (cut_tac ?t1.0=\"x61\" and ?t2.0=\"x61a\" and ?s1.0=\"x62\" and ?s2.0=\"x62a\" and c_t=\"list\" in dist_ut_term_less_length)\n     apply (simp add: tvar_total_def)\n    apply (case_tac \"unify_type ((x61, x61a) # (x62, x62a) # list)\")\n     apply (auto)\n    (* - fun case *)\n   apply (case_tac b)\n          apply (auto)\n   apply (erule_tac x=\"(x71, x71a) # (x72, x72a) # list\" in allE)\n    apply (auto)\n    apply (simp add: unify_rel_def)\n    apply (cut_tac ?t1.0=\"x71\" and ?t2.0=\"x71a\" and ?s1.0=\"x72\" and ?s2.0=\"x72a\" and c_t=\"list\" in dist_ut_term_less_length)\n    apply (simp add: tvar_total_def)\n   apply (case_tac \"unify_type ((x71, x71a) # (x72, x72a) # list)\")\n    apply (auto)\n    (* - chan case *)\n  apply (case_tac b)\n         apply (auto)\n  apply (erule_tac x=\"(x81, x81a) # list\" in allE)\n  apply (auto)\n   apply (simp add: unify_rel_def)\n   apply (simp add: tvar_total_def)\n  apply (case_tac \"x82 = x82a\")\n   apply (auto)\n  done\n    \nlemma occurs_tvar_type: \"occurs tau x \\<Longrightarrow> x \\<in> tvar_type tau\"    \n  apply (induct tau)\n         apply (auto)\n  done\n    \n    (* \\<lbrakk>x4a \\<noteq> x4; unify_type (sol_subst_eq_list (add_env empty_env x4a (VarScheme x4)) list) = Some (a, p_eq); perm_eq_sat p_sub p_eq;\n        equiv_sub (subst_compose a t_sub') t_subx; t_subx x4a = None; type_eq_sat_f t_subx p_sub list; t_subx x4 = Some (VarScheme x4a)\\<rbrakk>\n       \\<Longrightarrow> equiv_sub (subst_compose (add_env a x4a (case a x4 of None \\<Rightarrow> VarScheme x4 | Some tau \\<Rightarrow> tau)) (add_env t_sub' x4 (VarScheme x4a))) t_subx *)\n  \nlemma cancel_add_env: \"\\<lbrakk> env x = Some tau \\<rbrakk> \\<Longrightarrow> add_env env x tau = env\"    \n  apply (case_tac \"\\<forall> y. add_env env x tau y = env y\")  \n   apply (auto)\n  apply (simp add: add_env_def)\n  apply (case_tac \"x = y\")\n   apply (auto)\n  done\n    \nlemma add_sol_subst_type: \"\\<lbrakk> \\<not> occurs tau a \\<rbrakk> \\<Longrightarrow>\n  sol_subst_type (add_env t_sub a t) tau = sol_subst_type t_sub tau\"    \n  apply (induct tau)\n         apply (auto)\n  apply (simp add: add_env_def)\n  done\n    \nlemma comm_equiv_scheme: \"equiv_scheme tau tau' \\<Longrightarrow> equiv_scheme tau' tau\"    \n  apply (induct tau arbitrary: tau')\n         apply (auto)\n  done\n\nlemma trans_equiv_scheme: \"\\<lbrakk> equiv_scheme ta tb; equiv_scheme tb tc \\<rbrakk> \\<Longrightarrow> equiv_scheme ta tc\"    \n  apply (induct ta arbitrary: tb tc)\n         apply (auto)\n  done\n\nlemma perm_subst_equiv_scheme: \"\\<lbrakk> perm_subst_type p_sub tau = perm_subst_type p_sub tau' \\<rbrakk> \\<Longrightarrow> equiv_scheme tau tau'\"    \n  apply (induct tau arbitrary: tau')  \n         apply (auto)\n         apply (case_tac tau')\n                apply (auto)\n        apply (case_tac tau')\n               apply (auto)\n       apply (case_tac tau')\n              apply (auto)\n      apply (case_tac tau')\n             apply (auto)\n     apply (case_tac tau')\n            apply (auto)\n    apply (case_tac tau')\n           apply (auto)\n   apply (case_tac tau')\n          apply (auto)\n  apply (case_tac tau')\n         apply (auto)\n  done\n    \nlemma expand_subst_compose: \"sol_subst_type (subst_compose t_sub t_sub') tau = sol_subst_type t_sub' (sol_subst_type t_sub tau)\"    \n  apply (induct tau)\n         apply (auto)\n  apply (simp add: subst_compose_def)\n  apply (case_tac \"t_sub x\")\n   apply (auto)\n  done\n    \nlemma double_perm_subst_type: \"perm_subst_type p_sub tau = perm_subst_type p_sub (perm_subst_type p_sub tau)\"    \n  apply (induct tau)\n         apply (auto)\n  done\n  \nlemma compose_perm_subst_type: \"perm_subst_type p_sub (sol_subst_type t_sub tau) = perm_subst_type p_sub (sol_subst_type (perm_compose p_sub t_sub) tau)\"\n  apply (induct tau)\n         apply (auto)\n  apply (simp add: perm_compose_def)\n  apply (case_tac \"t_sub x\")\n   apply (auto)\n  apply (rule_tac double_perm_subst_type)\n  done    \n    \n    (* say that we encounter constraint { a = b }. in our solution we want to select { a \\<rightarrow> b }, but the given solution selects { b \\<rightarrow> a }.\n        we can translate one solution to the other by adding { b \\<rightarrow> a } to the composition.  *)\nlemma add_compose_equiv_sub: \"\\<lbrakk> equiv_sub (perm_compose p_sub (subst_compose t_sub t_sub')) (perm_compose p_sub t_subx);\n  apply_type_subst t_subx a = VarScheme a; t_subx b = Some (VarScheme a); a \\<noteq> b; wf_sub t_sub \\<rbrakk> \\<Longrightarrow>\n  equiv_sub (perm_compose p_sub (subst_compose (add_env t_sub a (VarScheme b)) (add_env t_sub' b (VarScheme a)))) (perm_compose p_sub t_subx)\"    \n  apply (simp add: equiv_sub_def)\n  apply (auto)\n  apply (simp add: perm_compose_def)\n  apply (simp add: subst_compose_def)\n  apply (simp add: add_env_def)\n  apply (auto)\n    (* x = a *)\n   apply (case_tac \"t_subx a\")\n    apply (auto)\n    (* x = b, there exists some c where t_sub: b \\<rightarrow> c, t_sub': c \\<rightarrow> x, where x is some var (meaning c is some var).\n        whether b = c or not, the correct result follows\n    *)\n  apply (case_tac \"x = b\")\n   apply (auto)\n   apply (case_tac \"t_sub b\")\n    apply (auto)\n    apply (simp add: add_env_def)\n   apply (erule_tac x=\"b\" in allE)\n   apply (auto)\n   apply (case_tac aa)\n          apply (auto)\n   apply (simp add: add_env_def)\n    (* otherwise, say t_sub: x \\<rightarrow> x. this case is unchanged by NEW t_sub' *)\n  apply (case_tac \"t_sub x\")\n   apply (auto)\n   apply (erule_tac x=\"x\" in allE)\n   apply (auto)\n   apply (simp add: add_env_def)\n    (* say that b occurs in t_sub(x). for this to work, we want t_sub': b \\<rightarrow> a how can we show this? say that this was not the case.\n        t_subx: b \\<rightarrow> a, which means that either t_sub: b \\<rightarrow> c and t_sub': c \\<rightarrow> a, OR t_sub: b \\<rightarrow> a.\n          both are impossible since we can assume by construction of t_sub that it is \"well-formed\", namely that\n          all variables with an assignment do not appear on the RHS of a substitution.\n    *)\n  apply (case_tac \"occurs aa b\")\n   apply (case_tac \"t_sub' b \\<noteq> Some (VarScheme a)\")\n    apply (case_tac \"t_sub b = None\")\n     apply (erule_tac x=\"b\" in allE)\n     apply (auto)\n     apply (case_tac \"t_sub' b\")\n      apply (auto)\n     apply (case_tac aaa)\n            apply (auto)\n    apply (simp add: wf_sub_def)\n    apply (erule_tac x=\"n\" in allE)\n    apply (erule_tac x=\"b\" in allE)\n    apply (auto)\n    apply (erule_tac x=\"x\" in allE)\n    apply (auto)\n    apply (cut_tac occurs_tvar_type)\n     apply (auto)\n    (* knowing that t_sub': b \\<rightarrow> a, t_sub' is unchanged *)\n   apply (simp add: cancel_add_env)\n   apply (erule_tac x=\"x\" in allE)\n   apply (auto)\n    (* lastly, we can analyze the case where t_sub: x \\<rightarrow> anything else *)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (case_tac \"t_subx x\")\n   apply (auto)\n   apply (case_tac aa)\n          apply (auto)\n   apply (simp add: add_env_def)\n  apply (simp add: add_sol_subst_type)\n  done\n    \nlemma equiv_sub_type: \"\\<lbrakk> equiv_sub t_sub t_sub' \\<rbrakk> \\<Longrightarrow> sol_subst_type t_sub tau = sol_subst_type t_sub' tau\"    \n  apply (induct tau)\n         apply (auto)\n  apply (simp add: equiv_sub_def)\n  done    \n    \nlemma as_perm_sol_subst_aff: \"sol_subst_perm p_sub (as_perm_s a) = as_perm (sol_subst_aff p_sub a)\"    \n  apply (case_tac a)\n   apply (auto)\n  apply (case_tac \"p_sub x2\")\n    apply (auto)\n  done    \n    \nlemma id_equiv_sub: \"equiv_sub t_sub t_sub\"    \n  apply (simp add: equiv_sub_def)\n  done\n  \nlemma comm_equiv_sub: \"equiv_sub t_sub t_sub' \\<Longrightarrow> equiv_sub t_sub' t_sub\"    \n  apply (simp add: equiv_sub_def)\n  done    \n    \nlemma empty_subst_compose: \"subst_compose empty_env t_sub = t_sub\"    \n  apply (case_tac \"\\<forall> x. subst_compose empty_env t_sub x = t_sub x\")  \n   apply (auto)\n  apply (simp add: subst_compose_def)\n  apply (simp add: empty_env_def)\n  done\n    \ndefinition uts_res where\n  \"uts_res t_sub t_subx p_sub p_eq = ((\\<exists> t_sub'. equiv_sub (perm_compose p_sub (subst_compose t_sub t_sub')) (perm_compose p_sub t_subx)) \\<and> perm_eq_sat p_sub p_eq)\"       \n\n    (* if unification returns successfully, and the constraint list is satisfiable, then the satisfying type substitution of the solution\n          will be a specialization of the one returned by type substitution, and the permission substitution will satisfy p_eq *)\nlemma unify_type_sat: \"\\<lbrakk> unify_type c_list = Some (t_sub, p_eq); type_eq_sat t_subx p_sub c_list \\<rbrakk> \\<Longrightarrow> uts_res t_sub t_subx p_sub p_eq\"\n  apply (induct arbitrary: t_sub p_eq rule: wf_induct [where r=unify_rel])\n   apply (simp add: unify_rel_def)\n  apply (case_tac x)\n   apply (auto)\n   apply (simp add: uts_res_def)\n   apply (simp add: perm_eq_sat_def)\n   apply (rule_tac x=\"t_subx\" in exI)\n   apply (simp add: empty_subst_compose)\n   apply (rule_tac id_equiv_sub)\n    (* elim case *)\n  apply (case_tac \"\\<exists> a'. a = VarScheme a'\")\n   apply (auto)\n    (* - delete case *)\n   apply (case_tac \"b = VarScheme a'\")\n    apply (auto)\n    apply (erule_tac x=\"list\" in allE)\n    apply (simp add: simp_unify_rel)\n    apply (simp add: type_eq_sat_def)\n    (* - occurs case *)\n   apply (case_tac \"occurs b a'\")\n    apply (auto)\n    (* - standard case *)\n   apply (case_tac \"unify_type (sol_subst_eq_list (add_env empty_env a' b) list)\")\n    apply (auto)\n   apply (erule_tac x=\"sol_subst_eq_list (add_env empty_env a' b) list\" in allE)\n   apply (auto)\n     apply (simp add: elim_unify_rel)\n    apply (simp add: type_eq_sat_def)\n    apply (auto)\n    apply (simp add: intern_sol_subst_type_eq_sat)\n   apply (simp add: uts_res_def)\n   apply (auto)\n    (* > say that t_subx a' = None (or to itself). since 'a = b, this would only be the case if b was another variable, and t_subx b = a' *)\n   apply (case_tac \"apply_type_subst t_subx a' = VarScheme a'\")\n    apply (simp add: type_eq_sat_def)\n    apply (auto)\n    apply (case_tac b)\n           apply (auto)\n    apply (case_tac \"t_subx x4\")\n     apply (auto)\n    apply (case_tac aa)\n           apply (auto)\n    (* > say that t_sub doesn't map b. then t_sub(b) = b\n        we know that [[ a o t_sub' = t_subx ]]. so then [[ a + { 'a: b } o t_sub' + { b: 'a } =  t_subx ]] ('a = x4a, b = x4) *)\n    apply (case_tac \"a x4\")\n     apply (auto)\n     apply (rule_tac x=\"add_env t_sub' x4 (VarScheme x4a)\" in exI)\n     apply (cut_tac t_sub=\"a\" and t_sub'=\"t_sub'\" and t_subx=\"t_subx\" and a=\"x4a\" and b=\"x4\" and p_sub=\"p_sub\" in add_compose_equiv_sub)\n          apply (auto)\n     apply (rule_tac unify_type_wf_sub)\n     apply (auto)\n    (* > otherwise, we have t_sub mapping b to some variable c. *)\n    apply (case_tac \"\\<not> (\\<exists> c. a x4 = Some (VarScheme c))\")\n     apply (simp add: equiv_sub_def)\n     apply (simp add: perm_compose_def)\n     apply (simp add: subst_compose_def)\n     apply (erule_tac x=\"x4\" in allE)\n     apply (auto)\n     apply (case_tac aa)\n            apply (auto)\n    (* > say that c = a. this is impossible since then a would be in t_sub's range *)\n    apply (case_tac \"c = x4a\")\n     apply (cut_tac x=\"x4a\" and c_list=\"sol_subst_eq_list (add_env empty_env x4a (VarScheme x4)) list\" in unify_type_sub_range)\n       apply (auto)\n      apply (cut_tac x=\"x4a\" and c_list=\"list\" in sol_subst_list_contain)\n       apply (auto)\n     apply (simp add: type_sub_range_def)\n     apply (erule_tac x=\"x4\" in allE)\n     apply (auto)\n    (* > we claim [[ a + { 'a: t_sub(b) = c } o t_sub' + { c: 'a } = t_subx ]] should work *)\n    apply (rule_tac x=\"add_env t_sub' c (VarScheme x4a)\" in exI)\n    apply (cut_tac t_sub=\"a\" and t_sub'=\"t_sub'\" and t_subx=\"t_subx\" and a=\"x4a\" and b=\"c\" in add_compose_equiv_sub)\n         apply (auto)\n    (* >> t_sub: c \\<rightarrow> c by well-formedness *)\n     apply (case_tac \"a c \\<noteq> None\")\n      apply (cut_tac c_list=\"sol_subst_eq_list (add_env empty_env x4a (VarScheme x4)) list\" and t_sub=\"a\" in unify_type_wf_sub)\n       apply (auto)\n      apply (simp add: wf_sub_def)\n      apply (erule_tac x=\"c\" in allE)\n      apply (auto)\n      apply (erule_tac x=\"x4\" in allE)\n      apply (auto)\n    (* >> t_subx: c \\<rightarrow> a, since t_sub: b \\<rightarrow> c and t_subx: b \\<rightarrow> a, meaning t_sub': c \\<rightarrow> a *)\n     apply (case_tac \"t_sub' c \\<noteq> Some (VarScheme x4a)\")\n      apply (simp add: equiv_sub_def)\n      apply (simp add: perm_compose_def)\n      apply (simp add: subst_compose_def)\n      apply (erule_tac x=\"x4\" in allE)\n      apply (auto)\n      apply (case_tac \"t_sub' c\")\n       apply (auto)\n      apply (case_tac aa)\n             apply (auto)\n    (* >> using equivalence to put these facts together *)\n     apply (simp add: equiv_sub_def)\n     apply (erule_tac x=\"c\" in allE)\n     apply (simp add: perm_compose_def)\n     apply (simp add: subst_compose_def)\n     apply (case_tac \"t_subx c\")\n      apply (auto)\n     apply (case_tac aa)\n            apply (auto)\n    apply (rule_tac unify_type_wf_sub)\n    apply (auto)\n      (* > otherwise, we know that t_subx(a') maps to something besides a'. we know that t_sub(a') = None,\n          meaning that t_sub'(a') = t_subx(a'), meaning that we shouldn't have to change the mapping. *)\n   apply (case_tac \"t_subx a'\")\n    apply (auto)\n   apply (rule_tac x=\"t_sub'\" in exI)\n   apply (case_tac \"a a' \\<noteq> None\")\n    apply (cut_tac t_sub=\"a\" and x=\"a'\" in unify_type_sub_dom)\n      apply (auto)\n    apply (cut_tac x=\"a'\" and tau=\"b\" and c_list=\"list\" in sol_subst_list_contain)\n     apply (auto)\n   apply (case_tac \"\\<not> perm_subst_type p_sub (apply_type_subst t_sub' a') = perm_subst_type p_sub aa\")\n    apply (simp add: equiv_sub_def)\n    apply (simp add: perm_compose_def)\n    apply (simp add: subst_compose_def)\n    apply (erule_tac x=\"a'\" in allE)\n    apply (auto)\n    apply (case_tac \"t_sub' a'\")\n     apply (auto)\n   apply (simp add: equiv_sub_def)\n   apply (simp add: perm_compose_def)\n   apply (simp add: subst_compose_def)\n   apply (case_tac \"\\<not> equiv_sub (perm_compose p_sub (subst_compose a t_sub')) (perm_compose p_sub t_subx)\")\n    apply (simp add: equiv_sub_def)\n    apply (simp add: perm_compose_def)\n    apply (simp add: subst_compose_def)\n   apply (auto)\n   apply (simp add: add_env_def)\n   apply (auto)\n    (* >> we utilize the equations to show equality *)\n   apply (simp add: type_eq_sat_def)\n   apply (auto)\n   apply (rule_tac t=\"sol_subst_type t_sub' (sol_subst_type a b)\" and s=\"sol_subst_type (subst_compose a t_sub') b\" in subst)\n    apply (rule_tac expand_subst_compose)\n   apply (cut_tac p_sub=\"p_sub\" and t_sub=\"subst_compose a t_sub'\" and tau=\"b\" in compose_perm_subst_type)\n   apply (auto)\n   apply (cut_tac p_sub=\"p_sub\" and t_sub=\"t_subx\" and tau=\"b\" in compose_perm_subst_type)\n   apply (auto)\n     (* >> we manipulate to activate this lemma concerning application of equivalent substitutions *)\n   apply (rule_tac t=\"sol_subst_type (perm_compose p_sub (subst_compose a t_sub')) b\" and s=\"sol_subst_type (perm_compose p_sub t_subx) b\" in subst)\n    apply (rule_tac equiv_sub_type)\n    apply (rule_tac comm_equiv_sub)\n    apply (auto)\n      (* orient case *)\n  apply (case_tac \"\\<exists> b'. b = VarScheme b'\")\n   apply (auto)\n   apply (erule_tac x=\"(VarScheme b', a) # list\" in allE)\n   apply (simp add: orient_unify_rel)\n   apply (simp add: type_eq_sat_def)\n   apply (case_tac a)\n          apply (auto)\n      (* decomp cases. primitives *)    \n  apply (case_tac a)\n         apply (auto)\n        apply (case_tac b)\n               apply (auto)\n        apply (erule_tac x=\"list\" in allE)\n        apply (auto)\n         apply (simp add: simp_unify_rel)\n        apply (simp add: type_eq_sat_def)\n       apply (case_tac b)\n              apply (auto)\n       apply (erule_tac x=\"list\" in allE)\n       apply (auto)\n        apply (simp add: simp_unify_rel)\n       apply (simp add: type_eq_sat_def)\n      apply (case_tac b)\n             apply (auto)\n      apply (erule_tac x=\"list\" in allE)\n      apply (auto)\n       apply (simp add: simp_unify_rel)\n      apply (simp add: type_eq_sat_def)\n    (* - array case *)\n     apply (case_tac b)\n            apply (auto)\n     apply (erule_tac x=\"(x5, x5a) # list\" in allE)\n     apply (simp add: unify_rel_def)\n     apply (simp add: tvar_total_def)\n     apply (simp add: type_eq_sat_def)\n    (* - pair case *)\n    apply (case_tac b)\n           apply (auto)\n    apply (erule_tac x=\"(x61, x61a) # (x62, x62a) # list\" in allE)\n    apply (auto)\n     apply (simp add: unify_rel_def)\n     apply (cut_tac ?t1.0=\"x61\" and ?t2.0=\"x61a\" and ?s1.0=\"x62\" and ?s2.0=\"x62a\" and c_t=\"list\" in dist_ut_term_less_length)\n     apply (simp add: tvar_total_def)\n    apply (simp add: type_eq_sat_def)\n    apply (case_tac \"unify_type ((x61, x61a) # (x62, x62a) # list)\")\n     apply (auto)\n    apply (simp add: uts_res_def)\n    apply (simp add: perm_eq_sat_def)\n    (* - fun case *)\n   apply (case_tac b)\n          apply (auto)\n   apply (erule_tac x=\"(x71, x71a) # (x72, x72a) # list\" in allE)\n    apply (auto)\n    apply (simp add: unify_rel_def)\n    apply (cut_tac ?t1.0=\"x71\" and ?t2.0=\"x71a\" and ?s1.0=\"x72\" and ?s2.0=\"x72a\" and c_t=\"list\" in dist_ut_term_less_length)\n    apply (simp add: tvar_total_def)\n   apply (simp add: type_eq_sat_def)\n   apply (case_tac \"unify_type ((x71, x71a) # (x72, x72a) # list)\")\n    apply (auto)\n   apply (simp add: uts_res_def)\n   apply (simp add: perm_eq_sat_def)\n   apply (simp add: as_perm_sol_subst_aff)\n    (* - chan case *)\n  apply (case_tac b)\n         apply (auto)\n  apply (erule_tac x=\"(x81, x81a) # list\" in allE)\n  apply (auto)\n   apply (simp add: unify_rel_def)\n   apply (simp add: tvar_total_def)\n  apply (simp add: type_eq_sat_def)\n  done\n    \n\nfun as_scheme where\n  \"as_scheme IntTy = IntScheme\"  \n| \"as_scheme UnitTy = UnitScheme\"  \n| \"as_scheme BoolTy = BoolScheme\"  \n| \"as_scheme (ArrayTy tau) = ArrayScheme (as_scheme tau)\"  \n| \"as_scheme (PairTy t1 t2 r) = PairScheme (as_scheme t1) (as_scheme t2) (SPerm r)\"  \n| \"as_scheme (FunTy t1 t2 r a) = FunScheme (as_scheme t1) (as_scheme t2) (SPerm r) (AffConst a)\"  \n| \"as_scheme (ChanTy tau c_end) = ChanScheme (as_scheme tau) c_end\"  \n  \ndefinition indir_sub where\n  \"indir_sub t_sub = (\\<lambda> x. case t_sub x of None \\<Rightarrow> None | Some tau \\<Rightarrow> Some (as_scheme tau))\"  \n  \nlemma cancel_perm_as_scheme: \"perm_subst_type p_sub (as_scheme tau) = as_scheme tau\"  \n  apply (induct tau)\n        apply (auto)\n  done\n  \nlemma dir_perm_subst_type: \"\\<lbrakk> dir_subst_type t_sub p_sub tau tau' \\<rbrakk> \\<Longrightarrow>\n  perm_subst_type p_sub (sol_subst_type (indir_sub t_sub) tau) = as_scheme tau'\"  \n  apply (induct tau arbitrary: tau')\n         apply (auto)\n  apply (simp add: indir_sub_def)\n  apply (rule_tac cancel_perm_as_scheme)\n  done\n\nlemma dir_sol_type_eq_sat: \"\\<lbrakk> dir_sol_sat t_sub p_sub c_list \\<rbrakk> \\<Longrightarrow> type_eq_sat (indir_sub t_sub) p_sub (unify_subset c_list)\"  \n  apply (induct c_list)\n   apply (auto)\n   apply (simp add: type_eq_sat_def)\n  apply (simp add: type_eq_sat_def)\n  apply (case_tac a)\n       apply (auto)\n  apply (simp add: dir_perm_subst_type)\n  done    \n    \nlemma dist_add_sol_subst_type: \"sol_subst_type t_sub (sol_subst_type (add_env empty_env a tau) tau') =\n  sol_subst_type (add_env t_sub a (sol_subst_type t_sub tau)) tau'\"\n  apply (induct tau')\n         apply (auto)\n  apply (simp add: add_env_def)\n  apply (auto)\n  apply (simp add: empty_env_def)\n  done\n  \nlemma extern_sol_subst_type_eq_sat: \"\\<lbrakk> \\<not> occurs tau a; type_eq_sat t_sub p_sub (sol_subst_eq_list (add_env empty_env a tau) c_list) \\<rbrakk>\n       \\<Longrightarrow> type_eq_sat (add_env t_sub a (sol_subst_type t_sub tau)) p_sub ((VarScheme a, tau) # c_list)\" \n  apply (simp add: type_eq_sat_def)\n  apply (auto)\n   apply (simp add: add_sol_subst_type)\n   apply (simp add: add_env_def)\n  apply (induct c_list)\n   apply (auto)\n  apply (simp add: dist_add_sol_subst_type)\n  done\n    (*\n      sat 1: if type unification succeeds, and the constraint list is satisfiable, then our type substitution will be most general\n      sat 2: if type unification succeeds, our type substitution will satisfy\n    *)\n    \nlemma unify_type_satx: \"\\<lbrakk> unify_type c_list = Some (t_sub, p_eq); perm_eq_sat p_sub p_eq \\<rbrakk> \\<Longrightarrow>\n  type_eq_sat t_sub p_sub c_list\"\n  apply (induct arbitrary: t_sub p_eq rule: wf_induct [where r=unify_rel])\n   apply (simp add: unify_rel_def)\n  apply (case_tac x)\n   apply (auto)\n   apply (simp add: type_eq_sat_def)\n    (* var case *)\n  apply (case_tac \"\\<exists> a'. a = VarScheme a'\")\n   apply (auto)\n    (* - delete case *)\n   apply (case_tac \"b = VarScheme a'\")\n    apply (auto)\n    apply (erule_tac x=\"list\" in allE)\n    apply (simp add: simp_unify_rel)\n    apply (simp add: type_eq_sat_def)\n    (* - occurs case *)\n   apply (case_tac \"occurs b a'\")\n    apply (auto)\n    (* - elim case *)\n   apply (erule_tac x=\"sol_subst_eq_list (add_env empty_env a' b) list\" in allE)\n   apply (simp add: elim_unify_rel)\n   apply (case_tac \"unify_type (sol_subst_eq_list (add_env empty_env a' b) list)\")\n    apply (auto)\n   apply (rule_tac extern_sol_subst_type_eq_sat)\n    apply (auto)\n    (* orient case *)\n  apply (case_tac \"\\<exists> b'. b = VarScheme b'\")\n   apply (auto)\n   apply (erule_tac x=\"(VarScheme b', a) # list\" in allE)\n   apply (simp add: orient_unify_rel)\n   apply (simp add: type_eq_sat_def)\n   apply (case_tac a)\n          apply (auto)\n    (* decomp case *)\n  apply (case_tac a)\n         apply (auto)\n        apply (case_tac b)\n               apply (auto)\n        apply (erule_tac x=\"list\" in allE)\n        apply (auto)\n         apply (simp add: simp_unify_rel)\n        apply (simp add: type_eq_sat_def)\n       apply (case_tac b)\n              apply (auto)\n       apply (erule_tac x=\"list\" in allE)\n       apply (auto)\n        apply (simp add: simp_unify_rel)\n       apply (simp add: type_eq_sat_def)\n      apply (case_tac b)\n             apply (auto)\n      apply (erule_tac x=\"list\" in allE)\n      apply (auto)\n       apply (simp add: simp_unify_rel)\n      apply (simp add: type_eq_sat_def)\n    (* - array case *)\n     apply (case_tac b)\n            apply (auto)\n     apply (erule_tac x=\"(x5, x5a) # list\" in allE)\n     apply (simp add: unify_rel_def)\n     apply (simp add: tvar_total_def)\n     apply (simp add: type_eq_sat_def)\n    (* - pair case *)\n    apply (case_tac b)\n           apply (auto)\n    apply (erule_tac x=\"(x61, x61a) # (x62, x62a) # list\" in allE)\n    apply (auto)\n     apply (simp add: unify_rel_def)\n     apply (cut_tac ?t1.0=\"x61\" and ?t2.0=\"x61a\" and ?s1.0=\"x62\" and ?s2.0=\"x62a\" and c_t=\"list\" in dist_ut_term_less_length)\n     apply (simp add: tvar_total_def)\n    apply (simp add: perm_eq_sat_def)\n    apply (case_tac \"unify_type ((x61, x61a) # (x62, x62a) # list)\")\n     apply (auto)\n    apply (simp add: type_eq_sat_def)\n    (* - fun case *)\n   apply (case_tac b)\n          apply (auto)\n   apply (erule_tac x=\"(x71, x71a) # (x72, x72a) # list\" in allE)\n    apply (auto)\n    apply (simp add: unify_rel_def)\n    apply (cut_tac ?t1.0=\"x71\" and ?t2.0=\"x71a\" and ?s1.0=\"x72\" and ?s2.0=\"x72a\" and c_t=\"list\" in dist_ut_term_less_length)\n    apply (simp add: tvar_total_def)\n   apply (simp add: perm_eq_sat_def)\n   apply (case_tac \"unify_type ((x71, x71a) # (x72, x72a) # list)\")\n    apply (auto)\n   apply (simp add: type_eq_sat_def)\n    apply (auto)\n   apply (simp add: as_perm_sol_subst_aff)\n   apply (case_tac \"sol_subst_aff p_sub x74\")\n     apply (auto)\n     apply (case_tac \"sol_subst_aff p_sub x74a\")\n       apply (auto)\n    apply (case_tac \"sol_subst_aff p_sub x74a\")\n      apply (auto)\n   apply (case_tac \"sol_subst_aff p_sub x74a\")\n     apply (auto)\n    (* - chan case *)\n  apply (case_tac b)\n         apply (auto)\n  apply (erule_tac x=\"(x81, x81a) # list\" in allE)\n  apply (auto)\n   apply (simp add: unify_rel_def)\n   apply (simp add: tvar_total_def)\n  apply (case_tac \"x82 = x82a\")\n   apply (auto)\n  apply (simp add: type_eq_sat_def)\n  done\n\n\nend", "meta": {"author": "anon-ef", "repo": "perm_lang_ef2", "sha": "0fcb6e4c175193cc7b94f297a8aaa605f502d711", "save_path": "github-repos/isabelle/anon-ef-perm_lang_ef2", "path": "github-repos/isabelle/anon-ef-perm_lang_ef2/perm_lang_ef2-0fcb6e4c175193cc7b94f297a8aaa605f502d711/perm_ref/SolverP1.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.585101139733739, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.26520402387162323}}
{"text": "(*<*)(*:maxLineLen=68:*)\nsection \\<open>Lazy Streams\\<close>\n\ntheory Stream\nimports inc.LNat inc.SetPcpo\nbegin\n\nsection \\<open>The Datatype of Lazy Streams\\<close>\n\ndefault_sort countable\n\n(* deletes the Rule \"1 = Suc 0\" *)\n declare One_nat_def[simp del]\n\n(* declare [[show_types]] *)\ntext \\<open>\\<open>discr u\\<close> lifts an arbitrary type \\<open>'a\\<close> to the\n  discrete \\<open>pcpo\\<close> and the usual rest operator \\<open>rt\\<close> on streams.\\<close>\n(*>*)\nsection\\<open>Streams\\<close> text\\<open>\\label{sec:stream}\\<close>\n\ntext\\<open>The verification framework focus is based on the streams of \nmessages and stream processing functions. This section will shortly\nintroduce the implementation of streams in Isabelle and mention and\nexplain a few important functions and their properties. Some of \nthese will play a major role in the definition of \\glspl{sb} and \nothers will be used to ease the verification process of components.\nFor an in depth explanation I refer to \\cite{Stu16}.\\<close>\n\ntext\\<open>The stream domain in Isabelle is defined with the \\<open>domain\\<close>\ncommand provided by the \\<open>HOLCF\\<close> package. This automatically\ninstantiates our type as a \\gls{pcpo}.\\<close>\n\ndomain\n  'a stream = lscons (lshd::\"'a discr u\") (lazy srt::\"'a stream\") \n                                        (infixr \"&&\" 65)\n\ntext\\<open>The message type is lifted to a discrete \\gls{cpo} to generate\nthe same prefix order from FOCUS streams.\\<close>\n\nsubsection\\<open>Function over streams\\<close> text\\<open>\\label{subsec:sfun}\\<close>\n\ntext\\<open> The following table gives an overview about the main functions\ndefined for @{type stream}s. Some of them are introduced in detail \nfor their later usage in the Isabelle framework.\\<close>\n\n(*<*)\n\n(* ----------------------------------------------------------------------- *)\nsection \\<open>Signatures of Stream Processing Functions\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>Continuous function from stream to stream and shortcut \nfor input and output of the same type:\\<close>\ntype_synonym ('in, 'out) spf = \"('in stream \\<rightarrow> 'out stream)\"\ntype_synonym 'm spfo      = \"('m, 'm) spf\"\n\ntext \\<open>Same for general SPFs which are not continuous by definition:\\<close>\ntype_synonym ('in, 'out) gspf = \"('in stream \\<Rightarrow> 'out stream)\"\ntype_synonym 'm gspfo      = \"('m, 'm) gspf\"\n\ntext \\<open>Again for list processing functions:\\<close>\ntype_synonym ('in, 'out) lpf = \"('in list \\<Rightarrow> 'out list)\"\ntype_synonym 'm lpfo      = \"('m, 'm) lpf\"\n\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>Some abbreviations\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>The empty stream is denoted as \\<open>\\<epsilon>\\<close>.\\<close>\nabbreviation\n  sbot ::  \"'a stream\"  (\"\\<epsilon>\")\n    where \"sbot \\<equiv> \\<bottom>\"\n\ntext \\<open>@{term stake}: This operator is generated by the \\<open>domain\\<close>\n  command. It retrieves the first \\<open>n\\<close> elements of a stream\n  (or less, if the stream is shorter).\\<close>\nabbreviation\n  stake :: \"nat \\<Rightarrow> 'a spfo\"\n    where \"stake \\<equiv> stream_take\"\n\n\n(* ----------------------------------------------------------------------- *)\nsection \\<open>Common functions on streams\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>Conversion of function with lifted values to a partial function:\\<close>\ndefinition fup2map :: \"('a \\<Rightarrow> 'b::cpo u) \\<Rightarrow> ('a \\<rightharpoonup> 'b)\" where\n\"fup2map f a \\<equiv> if (f a = \\<bottom>) then None else Some (SOME x. up\\<cdot>x = f a)\" \n\ntext \\<open>@{term sup'}: Construct a stream by a single element.\\<close>\ndefinition sup'       :: \"'a \\<Rightarrow> 'a stream\" (\"\\<up>_\" [1000] 999) where\n\"sup' a \\<equiv> updis a && \\<epsilon>\"\n\ntext \\<open>@{term sconc}: Concatenate two streams over the same type.\n  For infinite streams, arbitrary other streams can be appended\n  without changing the stream.\\<close>\ndefinition sconc      :: \"'a stream \\<Rightarrow> 'a spfo\" where\n\"sconc \\<equiv> fix\\<cdot>(\\<Lambda> h. (\\<lambda> s1. \\<Lambda> s2. \n                      if s1 = \\<epsilon> then s2 else  (lshd\\<cdot>s1) && (h (srt\\<cdot>s1)\\<cdot>s2)))\"\n\nabbreviation sconc_abbr :: \"'a stream \\<Rightarrow> 'a stream \\<Rightarrow> 'a stream\" (\"(_ \\<bullet> _)\" [66,65] 65)\nwhere \"s1 \\<bullet> s2 \\<equiv> sconc s1\\<cdot>s2\"\n\ntext \\<open>@{term shd}: Retrieve the first element of a stream.\n  For \\<open>\\<epsilon>\\<close>, the result is not defined.\\<close>\ndefinition shd        :: \"'a stream \\<Rightarrow> 'a\" where\n\"shd s \\<equiv> THE a. lshd\\<cdot>s = updis a\"\n\ntext \\<open>@{term slookahd}: Apply function to head of stream.\n  If the stream is empty, \\<open>\\<bottom>\\<close> is returned.\n  This function is especially useful for defining own stream-processing\n  functions.\\<close>\ndefinition slookahd   :: \"'a stream \\<rightarrow> ('a \\<Rightarrow> 'b) \\<rightarrow> ('b::pcpo)\" where\n\"slookahd \\<equiv> \\<Lambda> s f. if s = \\<epsilon> then \\<bottom> else f (shd s)\"  \n\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>Conversion of lists to streams and induced order on lists\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>Lists can be converted to streams by the function @{term list2s}:\\<close>\n\nprimrec list2s :: \"'a list \\<Rightarrow> 'a stream\"\nwhere\n  list2s_0:   \"list2s [] = \\<epsilon>\" |\n  list2s_Suc: \"list2s (a#as) = updis a && (list2s as)\"\n\nabbreviation stream_abbrev :: \"'a list \\<Rightarrow> 'a stream\" (\"<_>\" [1000] 999)\nwhere \"<l> == list2s l\"\n\ntext \\<open>The data type \\<open>list\\<close> is a partial order with the operator \n  \\<open>\\<sqsubseteq>\\<close> derived from streams:\\<close>\ninstantiation list :: (countable) po\nbegin\n\n  definition sq_le_list:\n    \"s \\<sqsubseteq> t \\<equiv> (list2s s \\<sqsubseteq> list2s t)\"\n\n  (* list2s is a bijection *)\n  lemma list2s_inj[simp]: \"(list2s l = list2s l') = (l = l')\"\n  apply (rule iffI)\n  apply (simp add: atomize_imp)\n  apply (rule_tac x=\"l'\" in spec)\n  apply (induct l, simp)\n  apply (rule allI)\n  apply (induct_tac x, simp+)\n  apply (rule allI)\n  by (induct_tac x, simp+)\n\ninstance\napply (intro_classes)\napply (simp add: sq_le_list)+\napply (rule_tac y=\"list2s y\" in below_trans,assumption+)\napply (simp add: sq_le_list)\napply (rule list2s_inj [THEN iffD1])\nby (rule po_eq_conv [THEN iffD2],rule conjI,assumption+)\n\nend\n\n\n(* ----------------------------------------------------------------------- *)\ntext \\<open>Typical functions known from lists:\\<close>\n(* ----------------------------------------------------------------------- *)\n(*>*)\n\nsubsubsection\\<open>Length of Streams\\<close>\n\ntext \\<open>@{term slen}: Retrieve the length of a stream. It is defined\nas the number of its elements or \\<open>\\<infinity>\\<close> for infinite streams.\\<close>\n\ndefinition slen:: \"'a stream \\<rightarrow> lnat\" where\n\"slen \\<equiv> fix\\<cdot>(\\<Lambda> h. strictify\\<cdot>(\\<Lambda> s. lnsuc\\<cdot>(h\\<cdot>(srt\\<cdot>s))))\"\n\ntext\\<open>Resulting from the prefix order, a few key properties can be \nformulated using the length. One of these is an equality property:\nIf two streams are in an order and have the same length, there are \nequal. Abbreviation \\<open>#\\<close> is used for obtaining the length of a \nstream.\\<close>\n\nabbreviation slen_abbr :: \"'a stream \\<Rightarrow> lnat\" (\"#_\" [1000] 999)\nwhere \"#s == slen\\<cdot>s\"\n\n(*<*)\n\ntext \\<open>@{term sdrop}: Remove the first \\<open>n\\<close> elements\n  of the stream.\\<close>\ndefinition sdrop      :: \"nat \\<Rightarrow> 'a spfo\" where\n\"sdrop n \\<equiv> Fix.iterate n\\<cdot>srt\"\n\n(*>*)\nsubsubsection\\<open>Stream elements\\<close>\n\ntext\\<open>The element of a stream at position \\<open>n\\<close> can be accessed by\ndropping the first \\<open>n\\<close> elements of the stream. We start counting\npositions at 0.\\<close>\n\ndefinition snth :: \"nat \\<Rightarrow> 'a stream \\<Rightarrow> 'a\" where\n\"snth k s \\<equiv> shd (sdrop k\\<cdot>s)\" \n\ntext\\<open>Obtaining the elements of a stream with @{const snth} is often\nused in the verification process of components behaviour.\\<close>\n\n(*<*)\ntext\\<open>@{term sfoot}: Get the last element of a not empty, finite stream\\<close>\ndefinition sfoot      :: \"'a stream \\<Rightarrow> 'a\" where\n\"sfoot s = snth (THE a. lnsuc\\<cdot>(Fin a) = #s) s\"\n(*>*)\n\nsubsubsection\\<open>A Streams Values\\<close>\n\ntext \\<open>The values of a stream are a set of messages of type \\<open>'a\\<close> that\noccur at any position in the stream.\\<close>\n\ndefinition sValues :: \"'a stream \\<rightarrow> 'a set\" where\n\"sValues \\<equiv> \\<Lambda> s. {snth n s | n. Fin n < #s}\" \n\ntext\\<open>The definition of @{const sValues} is straight forward with the\nusage of @{const snth}.\\<close>\n\n(*<*)\ntext \\<open>@{term sntimes}: Repeat the given stream \\<open>n\\<close> times.\\<close>\ntext \\<open>(Only listed as a constant below for reference;\n  Use \\<open>sntimes\\<close> with same signature instead).\\<close>\n(* consts sntimes_    :: \"nat \\<Rightarrow> 'a stream \\<Rightarrow> 'a stream\" *)\n\ntext \\<open>@{term sinftimes}: Concatenate a stream infinitely often to itself.\\<close>\ndefinition sinftimes  :: \"'a stream \\<Rightarrow> 'a stream\" (\"_\\<^sup>\\<infinity>\") where\n \"sinftimes \\<equiv> fix\\<cdot>(\\<Lambda> h. (\\<lambda>s. \n                        if s = \\<epsilon> then \\<epsilon> else (s \\<bullet> (h s))))\"                         \n(*>*)                        \nsubsubsection\\<open>Applying functions element wise\\<close>\n\ntext \\<open>Similar to @{const map} on lists we can define a mapping that\napplies a function to each element of a stream. The \\<open>n\\<close>th element of\nthe output stream is equal to applying the mapping function to the\n\\<open>n\\<close>th element of the input stream.\\<close>\n\ndefinition smap:: \"('a \\<Rightarrow> 'b) \\<Rightarrow> 'a stream \\<rightarrow> 'b stream\" where\n\"smap f \\<equiv> fix\\<cdot>(\\<Lambda> h s. slookahd\\<cdot>s\\<cdot>(\\<lambda> a. \n                       \\<up>(f a) \\<bullet> (h\\<cdot>(srt\\<cdot>s))))\"\n\ntext\\<open>An automatons semantic can sometimes be represented by a \n@{const smap} mapping.\\<close>\n\n(*<*)\ntext \\<open>@{term sfilter}: Remove all elements from the stream which are\n  not included in the given set.\\<close>\ndefinition sfilter    :: \"'a set \\<Rightarrow> 'a spfo\" where\n\"sfilter M \\<equiv> fix\\<cdot>(\\<Lambda> h s. slookahd\\<cdot>s\\<cdot>(\\<lambda> a. \n                          (if (a \\<in> M) then \\<up>a \\<bullet> (h\\<cdot>(srt\\<cdot>s)) else h\\<cdot>(srt\\<cdot>s))))\"\n\ntext \\<open>@{term stakewhile}: Take the first elements of a stream as\n  long as the given function evaluates to \\<open>true\\<close>.\\<close>\ndefinition stakewhile :: \"('a \\<Rightarrow> bool) \\<Rightarrow> 'a spfo\" where\n\"stakewhile f \\<equiv> fix\\<cdot>(\\<Lambda> h s. slookahd\\<cdot>s\\<cdot>(\\<lambda> a. if (f a) then \\<up>a \\<bullet> h\\<cdot>(srt\\<cdot>s) else \\<epsilon>))\"\n\ntext \\<open>@{term sdropwhile}: Drop the first elements of a stream as\n  long as the given function evaluates to \\<open>true\\<close>.\\<close>\ndefinition sdropwhile :: \"('a \\<Rightarrow> bool) \\<Rightarrow> 'a spfo\" where\n\"sdropwhile f \\<equiv> fix\\<cdot>(\\<Lambda> h s. slookahd\\<cdot>s\\<cdot>(\\<lambda> a. \n                          if (f a) then h\\<cdot>(srt\\<cdot>s) else s))\"\n\ntext \\<open>Two streams can be combined into one stream by using tuples as elements.\\<close>\n\ntext \\<open>@{term szip}: Zip two streams into one stream.\\<close>\ndefinition szip       :: \"'a stream \\<rightarrow> 'b stream \\<rightarrow> ('a \\<times> 'b) stream\" where\n \"szip \\<equiv> fix\\<cdot>(\\<Lambda> h s1 s2. slookahd\\<cdot>s1\\<cdot>(\\<lambda> a. slookahd\\<cdot>s2\\<cdot>(\\<lambda> b.\n                     \\<up>(a,b) \\<bullet> (h\\<cdot>(srt\\<cdot>s1)\\<cdot>(srt\\<cdot>s2)))))\"\n\ntext\\<open>Takes a function and 2 streams, merges the 2 streams according to the function\\<close>\ndefinition merge:: \"('a  \\<Rightarrow> 'b \\<Rightarrow> 'c) \\<Rightarrow> 'a stream \\<rightarrow> 'b stream \\<rightarrow> 'c stream\" where\n\"merge f \\<equiv> \\<Lambda> s1 s2 . smap (\\<lambda> s3. f (fst s3) (snd s3))\\<cdot>(szip\\<cdot>s1\\<cdot>s2)\"\n\ntext \\<open>@{term sprojfst}: Access the first stream of two zipped streams.\\<close>\ndefinition sprojfst   :: \"(('a \\<times> 'b),'a) spf\" where\n\"sprojfst \\<equiv> \\<Lambda> x. smap fst\\<cdot>x\"\n\ntext \\<open>@{term sprojsnd}: Access the second stream of two zipped streams.\\<close>\ndefinition sprojsnd   :: \"(('a \\<times> 'b),'b) spf\" where\n\"sprojsnd \\<equiv> \\<Lambda> x. smap snd\\<cdot>x\"\n\ntext \\<open>The following two functions are \"delayed\" variants\n  of @{term stakewhile} and @{term sdropwhile}.\\<close>\n\ntext \\<open>@{term stwbl}: Take while predicate holds but also keep\n  first element violating condition.\\<close>\ndefinition stwbl      :: \"('a \\<Rightarrow> bool) \\<Rightarrow> 'a spfo\" where\n\"stwbl f \\<equiv> fix\\<cdot>(\\<Lambda> h s. slookahd\\<cdot>s\\<cdot>(\\<lambda> a. \n                          if (f a) then \\<up>a \\<bullet>  h\\<cdot>(srt\\<cdot>s) else \\<up>a))\"\n\ntext \\<open>@{term srtdw}: Rest (\\<open>srt\\<close>) of stream after dropwhile.\\<close>\ndefinition srtdw      :: \"('a \\<Rightarrow> bool) \\<Rightarrow> 'a spfo\" where\n\"srtdw f \\<equiv> \\<Lambda> x. srt\\<cdot>(sdropwhile f\\<cdot>x)\"\n\ntext \\<open>@{term srcdups}: Remove successive duplicate values from stream.\\<close>\ndefinition srcdups    :: \"'a spfo\" where\n\"srcdups \\<equiv> fix\\<cdot>(\\<Lambda> h s. slookahd\\<cdot>s\\<cdot>(\\<lambda> a. \n                        \\<up>a \\<bullet>  h\\<cdot>(sdropwhile (\\<lambda> z. z = a)\\<cdot>(srt\\<cdot>s))))\"\n\n(* Takes a nat indicating the number of elements to scan, a reducing\n function, an initial initial element, and an input stream. Returns\na stream consisting of the partial reductions of the input stream.*)\nprimrec SSCANL::\n\"nat \\<Rightarrow> ('o \\<Rightarrow> 'i \\<Rightarrow> 'o) \\<Rightarrow> 'o \\<Rightarrow> 'i stream \\<Rightarrow> 'o stream\" where\n  SSCANL_zero_def: \"SSCANL 0 f q s = \\<epsilon>\" |\n  \"SSCANL (Suc n) f q s = (if s=\\<epsilon> then \\<epsilon> \n                           else \\<up>(f q (shd s)) \\<bullet> \n                                (SSCANL n f (f q (shd s)) (srt\\<cdot>s)))\"\n\ntext \\<open>@{term sscanl}: Apply a function elementwise to the input\nstream. Behaves like \\<open>map\\<close>, but also takes the previously generated\noutput element as additional input to the function. For the first \ncomputation, an initial value is provided.\\<close>\ndefinition sscanl :: \"('o \\<Rightarrow> 'i \\<Rightarrow> 'o) \\<Rightarrow> 'o \\<Rightarrow> ('i, 'o) spf\" where\n\"sscanl f q \\<equiv> \\<Lambda> s. \\<Squnion>i. SSCANL i f q s\"\n(*>*)\n\n(*<*)\n(* scanline Advanced :D  *)\n(* or stateful ... *)\n(* The user has more control. Instead of the last output ('b) a \nstate ('s) is used as next input *)\ndefinition sscanlA ::\n \"('s \\<Rightarrow>'a \\<Rightarrow> ('b \\<times>'s)) \\<Rightarrow> 's  \\<Rightarrow> 'a stream \\<rightarrow> 'b stream\" where\n\"sscanlA f s0 \\<equiv> \\<Lambda> s. sprojfst\\<cdot>(sscanl (\\<lambda>(_,b). f b) (undefined, s0)\\<cdot>s)\"\n(*>*)\nsubsubsection\\<open>Applying state-based functions element wise\\<close>\n\ntext\\<open>One can also apply a state dependent function, like the \ntransition function of a deterministic automaton, to process the\nstreams elements. The \\<open>n+1\\<close>th output element then depends on the \n\\<open>n\\<close>th ouput state, because the state based function may act \ndifferently depending on its state. Hence, we also need an initial \nstate to start computing the output.\\<close>\n\ndefinition sscanlAg ::\n\"('s \\<Rightarrow>'a \\<Rightarrow> ('s \\<times>'b)) \\<Rightarrow> 's \\<Rightarrow> 'a stream \\<rightarrow> ('s\\<times>'b) stream\" where\n\"sscanlAg f s0 \\<equiv> \\<Lambda> s. (sscanl (\\<lambda>(b,_). f b) (s0, undefined)\\<cdot>s)\"\n\ntext\\<open>We first defined the general state-based @{const sscanlAg}.\nThe definition calls @{const sscanl} internally, @{const sscanl}\ncomputes the output of each element depending on the input and the \noutput of the last element. Likewise, it needs an initial output \nelement it starts with. The general state-based function however \nonly needs the previous output state, not the whole output.\\<close>\n\ntext\\<open>Since the semantic of an deterministic automaton does not \nreturn its states in each step but behaves similar in other cases,\nwe define another state-based function, that calls @{const sscanlAg}\nbut reduces its output to the message output stream. Hence, the \nstate stream is omitted.\\<close> \n\ndefinition %invisible sscanlAfst ::\n\"('s \\<Rightarrow>'a \\<Rightarrow> ('s\\<times>'b)) \\<Rightarrow> 's \\<Rightarrow> 'a stream \\<rightarrow> 's stream\" where\n\"sscanlAfst f s0 \\<equiv> \\<Lambda> s. sprojfst\\<cdot>(sscanlAg f s0\\<cdot>s)\"\n\ndefinition sscanlAsnd ::\n\"('s \\<Rightarrow>'a \\<Rightarrow> ('s \\<times>'b)) \\<Rightarrow> 's  \\<Rightarrow> 'a stream \\<rightarrow> 'b stream\" where\n\"sscanlAsnd f s0 \\<equiv> \\<Lambda> s. sprojsnd\\<cdot>(sscanlAg f s0\\<cdot>s)\"\n\ntext\\<open>A deterministic automatons semantic can then be represented by\na @{const sscanlAsnd} mapping.\\<close> \n(*<*)\n(*\ndefinition sscanlAg :: \"('s \\<Rightarrow>'a::countable \\<Rightarrow> ('s::countable \\<times>'b::countable)) \\<Rightarrow>'s   \\<Rightarrow> 'a stream \\<rightarrow> ('s\\<times>'b) stream\" where\n\"sscanlAg f s0 \\<equiv> \\<Lambda> s. (sscanl (\\<lambda>(b,_). f b) (s0, undefined)\\<cdot>s)\"\n\ndefinition sscanlAsnd :: \"('s \\<Rightarrow>'a::countable \\<Rightarrow> ('s::countable \\<times>'b::countable)) \\<Rightarrow> 's  \\<Rightarrow> 'a stream \\<rightarrow> 'b stream\" where\n\"sscanlAsnd f s0 \\<equiv> \\<Lambda> s. sprojsnd\\<cdot>(sscanlAg f s0\\<cdot>s)\"\n\ndefinition sscanlAfst :: \"('s \\<Rightarrow>'a::countable \\<Rightarrow> ('s::countable \\<times>'b::countable)) \\<Rightarrow>'s  \\<Rightarrow> 'a stream \\<rightarrow> 's stream\" where\n\"sscanlAfst f s0 \\<equiv> \\<Lambda> s. sprojfst\\<cdot>(sscanlAg f s0\\<cdot>s)\"\n*)\ntext \\<open>@{term siterate}: Create a stream by repeated application of\n  a function to an element. The generated stream starts with \\<open>a\\<close>,\n  \\<open>f(a)\\<close>, \\<open>f(f(a))\\<close>, and so on.\\<close>\ndefinition siterate   :: \"('a \\<Rightarrow> 'a) \\<Rightarrow> 'a \\<Rightarrow> 'a stream\" where\n\"siterate f (a::'a) \\<equiv> \\<up>a \\<bullet> sscanl (\\<lambda>a (b::'a). f a) a\\<cdot>(SOME x. #x = \\<infinity>)\"\n\ntext \\<open>Alternative definition similar to @{term siterate},\nit is more general than @{term siterate}\\<close>\ndefinition siterateBlock:: \"('a stream \\<Rightarrow> 'a stream) \\<Rightarrow> 'a stream \\<Rightarrow> 'a stream\" where\n\"siterateBlock f \\<equiv> fix \\<cdot> (\\<Lambda> h. (\\<lambda>s. s \\<bullet> (h (f s))))\"\n\n\n(* ----------------------------------------------------------------------- *)\ntext \\<open>Conversion between lists and streams and the processing functions:\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>@{term list2s}: Convert a list to a (finite) stream.\\<close>\ntext \\<open>(Only listed as a constant below for reference;\n  Use \\<open>list2s\\<close> with same signature instead).\\<close>\n(* consts list2s_   :: \"'a list \\<Rightarrow> 'a stream\" *)\n\ntext \\<open>@{term s2list}: Convert a stream to a list. Result for\n  infinite streams is undefined.\\<close>\ndefinition s2list     :: \"'a stream \\<Rightarrow> 'a list\" where\n\"s2list s \\<equiv> if #s \\<noteq> \\<infinity> then SOME l. list2s l = s else undefined\"\n\ntext \\<open>@{term slpf2spf}: Convert a list-processing function to a\n  stream-processing function.\\<close>\ndefinition slpf2spf   ::\"('in,'out) lpf \\<Rightarrow> ('in,'out) spf\" where\n\"slpf2spf f \\<equiv> \n    if monofun f \n      then \\<Lambda> s. (\\<Squnion>k. list2s (f (s2list (stake k\\<cdot>s)))) \n      else undefined\"\n\ntext \\<open>@{term sislivespf}: Liveness predicate for SPFs. A SPF\n  is considered live if all finite inputs are mapped to finite outputs.\\<close>\ndefinition sislivespf ::\"('in,'out) spf \\<Rightarrow> bool\" where\n\"sislivespf f \\<equiv> (\\<forall>x. #(f\\<cdot>x) = \\<infinity> \\<longrightarrow> #x = \\<infinity>)\"\n\ntext \\<open>@{term sspf2lpf}: Convert a stream-processing function\n  to a list-processing function.\\<close>\ndefinition sspf2lpf   ::\"('in,'out) spf \\<Rightarrow> ('in,'out) lpf\" where\n\"sspf2lpf f \\<equiv>  if sislivespf f then (\\<lambda>x. s2list (f\\<cdot>(list2s x))) else undefined\"\n\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>Syntactic sugar and helpers\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>The following abbreviations define infix and prefix operators\n  for a more intuitive usage.\\<close>\n\nabbreviation sfilter_abbr :: \"'a set \\<Rightarrow> 'a stream \\<Rightarrow> 'a stream\" (\"(_ \\<ominus> _)\" [66,65] 65)\nwhere \"F \\<ominus> s \\<equiv> sfilter F\\<cdot>s\"\n\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>Definition of stream manipulating functions\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>In this section, the definitions for the previously\n  declared functions are given.\\<close>\n\ntext \\<open>A typical procedure is to define a primary recursive function\n  first and then define the stream-processing via the least upper\n  bound of the function values for the prefixes of a stream.\\<close>\n\n(* concatenates a stream to itself n times *)\nprimrec sntimes :: \"nat \\<Rightarrow> 'a stream \\<Rightarrow> 'a stream\" where\n  \"sntimes 0 s = \\<epsilon>\" |\n  \"sntimes (Suc n) s = (sconc s)\\<cdot>(sntimes n s)\"\n  \n(* Abbreviation for sntimes *)\nabbreviation sntimes_abbr :: \"nat \\<Rightarrow> 'a stream \\<Rightarrow> 'a stream\" (\"_\\<star>_\" [60,80] 90)\nwhere \"(n \\<star> s)  == (sntimes n s)\"\n\ntext \\<open>In most cases, stream-processing functions or operators\n  on streams are defined using the continuous fixed point operator.\\<close>\n\n\n(* ----------------------------------------------------------------------- *)\nsection \\<open>Stream - basics\\<close>\n(* --------------------------------------\\<Squnion>--------------------------------- *)\n\ntext \\<open>In the following, lemmas on streams and their operators\n  are proven. In most cases, the stated lemma is shortly summarized\n  in natural language. Where this is not the case, the lemma\n  itself is mostly self-explanatory.\\<close>\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>Fundamental properties of @{term stake}\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>Some aliases of auto-generated lemmas are introduced:\\<close>\nlemmas scases' = stream.exhaust\nlemmas sinjects' = stream.injects\nlemmas sinverts' = stream.inverts\n\ntext \\<open>Each stream is the least upper bound of its prefixes.\n  As we we are in a CPO, upper bounds of chains always exist.\\<close>\nlemma reach_stream: \"(\\<Squnion>i. stake i\\<cdot>s) = s\"\napply (rule stream.take_lemma [OF spec [where x=s]])\napply (induct_tac n, simp, rule allI)\napply (rule_tac y=x in scases', simp)\napply (subst lub_range_shift [where j=\"Suc 0\", THEN sym],simp+)\nby (subst contlub_cfun_arg [THEN sym], auto)\n\n(* if two streams xs and ys are identical for any prefix that is a multiple of y long, then the two\n   streams are identical for any prefix *)\nlemma gstake2stake: assumes \"\\<forall>i. stake (i*y)\\<cdot>xs = stake (i*y)\\<cdot>ys\" and \"y\\<noteq>0\"\n  shows \"\\<forall>i. stake i\\<cdot>xs = stake i\\<cdot>ys\"\nproof \n  fix i\n  obtain k where \"\\<exists>l. k = y*l\" and \"k\\<ge>i\" by (metis One_nat_def Suc_le_eq assms(2) gr0I mult.commute mult_le_mono2 nat_mult_1_right)\n  thus \"stake i\\<cdot>xs = stake i\\<cdot>ys\" by (metis assms(1) min_def mult.commute stream.take_take) \nqed\n\n(* stake is monotone *)\nlemma stake_mono: assumes \"i\\<le>j\"\n  shows \"stake i\\<cdot>s \\<sqsubseteq> stake j\\<cdot>s\"\nby (metis assms min_def stream.take_below stream.take_take)\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>Construction by concatenation and more\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>Basic properties of \\<open>\\<up>_\\<close> constructor\\<close>\n\n(* shd composed with \\<up> is the identity. *)\n\n\nlemma [simp]: \"<[a]> = \\<up>a\"\n  by(simp add: sup'_def)\n\n(* the singleton stream is never equal to the empty stream *)\nlemma [simp]: \"\\<up>a \\<noteq> \\<epsilon>\"\nby (simp add: sup'_def)\n\n(* the rest of the singleton stream is empty *)\nlemma [simp]: \"srt\\<cdot>(\\<up>a) = \\<epsilon>\"\nby (simp add: sup'_def)\n\ntext \\<open> Basic properties of concatenation \\<close>\nlemma reduce_seq: (*never simp*)\n  assumes \"s1 = s2\"\n  shows \"s \\<bullet> s1 = s \\<bullet> s2\"\n  by (simp add: assms)\n\n(* the empty stream is the identity element with respect to concatenation *)\nlemma sconc_fst_empty[simp]:\"\\<epsilon> \\<bullet> s = s\"\napply (subst sconc_def [THEN fix_eq2])\nby (simp add: cont2cont_LAM)\n\n(* the lazy stream constructor and concatenation are associative *) \nlemma sconc_scons': \"(updis a && as) \\<bullet> s = updis a && (as \\<bullet> s)\"\napply (subst sconc_def [THEN fix_eq2])\nby (simp add: cont2cont_LAM)\n\n(* the lazy stream constructor is equivalent to concatenation with a singleton stream *)\nlemma lscons_conv: \"updis a && s = \\<up>a \\<bullet> s\"\napply (subst sconc_def [THEN fix_eq2])\napply (simp add:  sup'_def)\nby (simp add: cont2cont_LAM)\n\n(* concatenation with respect to singleton streams is associative *)\nlemma sconc_scons[simp]: \"(\\<up>a \\<bullet> as) \\<bullet> s = \\<up>a \\<bullet> (as \\<bullet> s)\"\napply (subst sconc_def [THEN fix_eq2])\nby (simp add: sconc_scons' sup'_def cont2cont_LAM)\n\ntext \\<open>If a predicate P holds for empty and non-empty streams, it holds for all streams\\<close>\nlemma scases [case_names bottom scons]: \"\\<And>x P. \\<lbrakk>x = \\<epsilon> \\<Longrightarrow> P; \\<And>a s. x = \\<up>a \\<bullet> s \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\napply (rule_tac y=x in scases', simp+)\napply (rule_tac p=u in upE, simp+)\napply (case_tac \"xa\")\nby (auto simp add: sup'_def sconc_scons')\n\n(* Single element streams commute with the stake operation. *)\nlemma stake_Suc[simp]: \"stake (Suc n)\\<cdot>(\\<up>a \\<bullet> as) = \\<up>a \\<bullet> stake n\\<cdot>as\"\nby (simp add: sconc_scons' sup'_def)\n\n(* see also sconc_fst_empty *)\nlemma sconc_snd_empty[simp]: \"s \\<bullet> \\<epsilon> = s\"\napply (rule stream.take_lemma [OF spec [where x = \"s\"]])\napply (induct_tac n, simp)\napply (rule allI, simp)\nby (rule_tac x=x in scases, simp+)\n\n(* shd is the inverse of prepending a singleton *)\nlemma shd1[simp]: \"shd (\\<up>a \\<bullet> s) = a\"\nby (simp add: sconc_scons' shd_def sup'_def)\n\n(* prepending an element a to a stream and extracting it with lshd is equivalent to imposing the\n   discrete order on a *)\nlemma lshd_updis [simp]: \"lshd\\<cdot>(\\<up>a \\<bullet> s) = updis a\"\nby (metis lscons_conv stream.sel_rews(4))\n\n(* srt is the inverse of appending to a singleton *)\nlemma [simp]: \"srt\\<cdot>(\\<up>a\\<bullet>as) = as\"\nby (simp add: sconc_scons' sup'_def)\n\n(* appending to a singleton is monotone *)\nlemma [simp]: \"\\<up>a \\<sqsubseteq> \\<up>a \\<bullet> s\"\napply (subst sconc_snd_empty [of \"\\<up>a\", THEN sym])\nby (rule monofun_cfun_arg, simp)\n\ntext \\<open>Properties of discrete partial orders\\<close>\n\n(* updis is a bijection *)\nlemma updis_eq: \"(updis a = updis b) = (a = b)\"\nby simp\n\n(* the discrete order only considers equal elements to be ordered *)\nlemma updis_eq2: \"(updis a \\<sqsubseteq> updis b) = (a = b)\"\nby simp\n\ntext \\<open>Mapping a stream to head and rest is injective\\<close>\nlemma inject_scons: \"\\<up>a \\<bullet> s1 = \\<up>b \\<bullet> s2 \\<Longrightarrow> a = b \\<and> s1 = s2\"\napply (subst updis_eq [THEN sym])\napply (rule sinjects' [THEN iffD1], simp)\nby (simp add: sconc_scons' sup'_def)\n\ntext \\<open>\\<open>\\<sqsubseteq>\\<close> applied to head and rest\\<close>\nlemma less_all_sconsD: \"\\<up>a \\<bullet> as \\<sqsubseteq> \\<up>b \\<bullet> bs \\<Longrightarrow> a = b \\<and> as \\<sqsubseteq> bs\"\napply (subst updis_eq2 [THEN sym])\napply (rule sinverts' [THEN iffD1], simp)\nby (simp add: sconc_scons' sup'_def)\n\n(* appending to a singleton stream can never yield the empty stream *)\nlemma [simp]: \"\\<epsilon> \\<noteq> \\<up>a \\<bullet> as\"\napply (rule ccontr, simp)\napply (drule po_eq_conv [THEN iffD1])\napply (erule conjE)\nby (simp add: sconc_scons' sup'_def)\n\n(* appending to a singleton stream can never yield the empty stream *)\nlemma [simp]: \"\\<up>a \\<bullet> as \\<noteq> \\<epsilon>\"\nby (rule notI, drule sym, simp)\n\ntext \\<open>Characterizations of equality with \\<open>\\<sqsubseteq>\\<close>, head and rest\\<close>\n\n(* singleton streams are only in an ordered relation if the two elements are equal *)\nlemma [simp]: \"(\\<up>a \\<sqsubseteq> \\<up>b) = (a = b)\"\napply (rule iffI)\nby (insert less_all_sconsD [of a \\<epsilon> b \\<epsilon>], simp+)\n\n(* length of a stream is smaller than length of this stream concatenated with another stream  *)\nlemma [simp]: \"#as \\<sqsubseteq> #(as \\<bullet> ys)\"\n  by (metis minimal monofun_cfun_arg sconc_snd_empty)\n\n(* uparrow is a bijection *)\nlemma [simp]: \"(\\<up>a = \\<up>b) = (a = b)\"\napply (rule iffI)\nby (insert inject_scons [of a \\<epsilon> b \\<epsilon>], simp+)\n\n(* appending a stream x to a singleton stream and producing another singleton stream implies that \n   the two singleton streams are equal and x was empty *)\nlemma [simp]: \"(\\<up>a \\<bullet> x = \\<up>c) = (a = c \\<and> x = \\<epsilon>)\"\nby (rule iffI, insert inject_scons [of a x c \\<epsilon>], simp+)\n\n(* of course we can also swap the expressions to the left and right of the equality sign *)\nlemma [simp]: \"(\\<up>c = \\<up>a \\<bullet> x) = (a = c \\<and> x = \\<epsilon>)\"\nby (rule iffI, insert inject_scons [of c \\<epsilon> a x], simp+)\n\n(* if an appended stream x to a singleton stream is in relation with another singleton stream, this implies that \n   a and b are equal and x was empty *)\nlemma [simp]: \"(\\<up>a \\<bullet> x \\<sqsubseteq> \\<up>b) = (a = b \\<and> x = \\<epsilon>)\" \nby (rule iffI, insert less_all_sconsD [of a x b \\<epsilon>], simp+)\n\n(* if a singleton stream is the prefix of another stream then the heads of the two streams must match *)\nlemma [simp]: \"(\\<up>a \\<sqsubseteq> \\<up>b \\<bullet> x) = (a = b)\" \nby (rule iffI, insert less_all_sconsD [of a \\<epsilon> b x], simp+)\n\n(* if x isn't empty then concatenating head and rest leaves the stream unchanged *)\nlemma surj_scons: \"x\\<noteq>\\<epsilon> \\<Longrightarrow> \\<up>(shd x) \\<bullet> (srt\\<cdot>x) = x\"\nby (rule_tac x=x in scases, simp+)\n\n(* the head of ordered streams are equal *)\nlemma below_shd: \"x \\<sqsubseteq> y \\<and> x \\<noteq> \\<epsilon> \\<Longrightarrow> shd x = shd y\"\n  by (metis below_bottom_iff less_all_sconsD surj_scons)\n\n(* the head of ordered streams are equal *)\nlemma below_shd_alt: \"x \\<sqsubseteq> y \\<and> x \\<noteq> \\<epsilon> \\<Longrightarrow> shd y = shd x\"\n  using below_shd by fastforce\n\ntext \\<open>Characterizations of \\<open>\\<sqsubseteq>\\<close> with head and rest\\<close>\n\n(* any nonempty prefix of a stream y is still a prefix when ignoring the first element *)\nlemma less_fst_sconsD: \"\\<up>a \\<bullet> as \\<sqsubseteq> y \\<Longrightarrow> \\<exists>ry. y = \\<up>a \\<bullet> ry \\<and> as \\<sqsubseteq> ry\"\napply (rule_tac x=y in scases, simp+) \napply (rule_tac x=\"s\" in exI)\nby (drule less_all_sconsD, simp)\n\n(* the prefix of any non-empty stream is either empty or shares the same first element *)\nlemma less_snd_sconsD: \n  \"x \\<sqsubseteq> \\<up>a\\<bullet>as \\<Longrightarrow> (x = \\<epsilon>) \\<or> (\\<exists>rx. x = \\<up>a\\<bullet>rx \\<and> rx \\<sqsubseteq> as)\"\napply (rule_tac x=x in scases, simp+) \napply (rule_tac x=\"s\" in exI)\nby (drule less_all_sconsD, simp)\n\n(* semantically equivalent to less_fst_sconsD *)\nlemma lessD: \n  \"x \\<sqsubseteq> y \\<Longrightarrow> (x = \\<epsilon>) \\<or> (\\<exists>a q w. x = \\<up>a\\<bullet>q \\<and> y = \\<up>a\\<bullet>w \\<and> q \\<sqsubseteq> w)\"\napply (rule_tac x=x in scases, simp+)  \napply (rule_tac x=\"a\" in exI)\napply (rule_tac x=\"s\" in exI, simp)\nby (drule less_fst_sconsD, simp)\n\n(* if ts is a prefix of xs and ts is not bottom, then lshd\\<cdot>ts is equal to lshd\\<cdot>xs *)\nlemma lshd_eq: \"ts\\<sqsubseteq>xs \\<Longrightarrow> ts\\<noteq>\\<bottom> \\<Longrightarrow> lshd\\<cdot>ts = lshd\\<cdot>xs\"\n  using lessD by fastforce\n  \n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term slen}\\<close>\n(* ----------------------------------------------------------------------- *)\n\n(* the length of the empty stream is zero *)\nlemma strict_slen[simp]:\"#\\<epsilon> = 0\"\nby (subst slen_def [THEN fix_eq2], simp add: lnzero_def)\n\n(* prepending a singleton stream increases the length by 1 *)\nlemma slen_scons[simp]: \"#(\\<up>a\\<bullet>as) = lnsuc\\<cdot>(#as)\" \nby (subst slen_def [THEN fix_eq2], simp add: lnle_def)\n\n(* the singleton stream has length 1 *)\nlemma [simp]: \"#(\\<up>a) = Fin (Suc 0)\"\napply (subst sconc_snd_empty [of \"\\<up>a\", THEN sym])\nby (subst slen_scons, simp+)\n\ntext \\<open>The rest of infinite streams is infinite as well\\<close>\nlemma inf_scase:\"#s = \\<infinity> \\<Longrightarrow> \\<exists>a as. s = \\<up>a \\<bullet> as \\<and> #as = \\<infinity>\"\nby (rule_tac x=s in scases, auto)\n \n(* only the empty stream has length 0 *)\nlemma slen_empty_eq[simp]: \"(#x = 0) = (x = \\<epsilon>)\"\nby (rule_tac x=x in scases, auto)\n\ntext \\<open>Appending to an inifite stream does not change its \\<open>n\\<close>th element\\<close>\nlemma sconc_fst_inf_lemma: \"\\<forall>x. #x=\\<infinity> \\<longrightarrow> stake n\\<cdot>(x\\<bullet>y) = stake n\\<cdot>x\"\napply (induct_tac n, auto)\nby (rule_tac x=x in scases, auto)\n\ntext \\<open>Appending to an infinite stream does not change the stream\\<close>\nlemma sconc_fst_inf[simp]: \"#x=\\<infinity> \\<Longrightarrow> x\\<bullet>y = x\"\napply (rule stream.take_lemma)\nby (rule sconc_fst_inf_lemma [rule_format])\n\ntext \\<open>For finite streams, their lengths are added on concatenation\\<close>\nlemma slen_sconc_all_finite: \n  \"\\<forall>x y n. #x = Fin k \\<and> #y = Fin n \\<longrightarrow> #(x\\<bullet>y) = Fin (k+n)\" \napply (induct_tac k, auto)\nby (rule_tac x=x in scases, auto)\n\ntext \\<open>Streams with infinite prefixes are infinite\\<close>\nlemma mono_fst_infD: \"\\<lbrakk>#x = \\<infinity>; x \\<sqsubseteq> y\\<rbrakk> \\<Longrightarrow> #y = \\<infinity> \"\napply (drule monofun_cfun_arg [of _ _ slen])\nby (rule lnat_po_eq_conv [THEN iffD1], simp)\n\ntext \\<open>For @{term \"s \\<sqsubseteq> t\"} with @{term s} and @{term t} of\n  equal length, all finite prefixes are identical\\<close>\nlemma stake_eq_slen_eq_and_less: \n  \"\\<forall>s t. #s = #t \\<and> s \\<sqsubseteq> t \\<longrightarrow> stake n\\<cdot>s = stake n\\<cdot>t\"\napply (induct_tac n, auto)\napply (rule_tac x=s in scases, auto)\napply (rule_tac x=t in scases, auto)\nby (drule less_all_sconsD, auto)\n\ntext \\<open>For @{term \"s \\<sqsubseteq> t\"} with @{term s} and @{term t} of\n  equal length, @{term s} and @{term t} are identical\\<close>\nlemma eq_slen_eq_and_less: \"\\<lbrakk>#s = #t; s \\<sqsubseteq> t\\<rbrakk> \\<Longrightarrow> s = t\"\napply (rule stream.take_lemma)\nby (rule stake_eq_slen_eq_and_less [rule_format], rule conjI)\n\ntext \\<open>Infinite prefixes are equal to the original stream\\<close>\nlemma eq_less_and_fst_inf: \"\\<lbrakk>s1 \\<sqsubseteq> s2; #s1 = \\<infinity>\\<rbrakk> \\<Longrightarrow> s1 = s2\"\napply (rule eq_slen_eq_and_less, simp) \napply (rule sym)\nby (rule mono_fst_infD [of \"s1\" \"s2\"])\n\n(*\nlemma s1: \"chain S \\<Longrightarrow> \\<not> finite_chain S \\<Longrightarrow> \\<forall>i. \\<exists>j\\<ge>i. S i \\<sqsubseteq> S j\"\nby auto\n\nlemma \"chain S \\<Longrightarrow> \\<not> finite_chain S \\<Longrightarrow> \\<exists>k. #(S k) = \\<infinity>\"\napply (simp add: finite_chain_def max_in_chain_def )\napply (subgoal_tac \"chain S \\<Longrightarrow> \\<not> finite_chain S \\<Longrightarrow> \\<forall>i. \\<exists>j\\<ge>i. S i \\<sqsubseteq> S j\")\nprefer 2\napply (simp add: s1, simp)\n*)\n\n(* if Fin n is smaller than the length of as, then Fin n is also smaller than lnsuc\\<cdot>(#as) *)\nlemma [simp]: \"Fin n < #as \\<Longrightarrow> Fin n < lnsuc\\<cdot>(#as)\"\n  by (smt below_antisym below_trans less_lnsuc lnle_def lnless_def)\n\ntext \\<open>For infinite streams, \\<open>stake n\\<close> returns \\<open>n\\<close> elements\\<close>\nlemma slen_stake_fst_inf[rule_format]: \n  \"\\<forall>x. #x = \\<infinity> \\<longrightarrow> #(stake n\\<cdot>x) = Fin n\"\napply (induct_tac n, auto)\nby (rule_tac x=x in scases, auto)\n\n(* mapping a stream to its length is a monotone function *)\nlemma mono_slen: \"x \\<sqsubseteq> y \\<Longrightarrow> #x \\<le> #y\"\nby (drule_tac x = x and y = y and f = slen \n  in monofun_cfun_arg, simp)\n\ntext \\<open>A stream is shorter than \\<open>n+1\\<close> iff its rest is shorter than \\<open>n\\<close>\\<close>\nlemma slen_rt_ile_eq: \"(#x \\<le> Fin (Suc n)) = (#(srt\\<cdot>x) \\<le> Fin n)\"  \nby (rule_tac x=x in scases, auto)\n\ntext \\<open>If \\<open>#x < #y\\<close>, this also applies to the streams' rests (for nonempty, finite x)\\<close>\nlemma smono_slen_rt_lemma: \n  \"#x = Fin k \\<and> x \\<noteq> \\<epsilon> \\<and> #x < #y \\<longrightarrow> #(srt\\<cdot>x) < #(srt\\<cdot>y)\"\napply (induct_tac k, auto)\napply (rule_tac x=x in scases, auto)\nby (rule_tac x=y in scases, auto)\n\ntext \\<open>If \\<open>#x < #y\\<close>, this also applies to the streams' rests (for finite x)\\<close>\nlemma smono_slen_rt: \"\\<lbrakk>x \\<noteq> \\<epsilon>; #x < #y\\<rbrakk> \\<Longrightarrow> #(srt\\<cdot>x) < #(srt\\<cdot>y)\"\napply (rule_tac x=\"#x\" in lncases, auto) \nby (rule smono_slen_rt_lemma [rule_format], simp)\n\ntext \\<open>Infinite elements of a stream chain are equal to the LUB\\<close>\nlemma inf2max: \"\\<lbrakk>chain Y; #(Y k) = \\<infinity>\\<rbrakk> \\<Longrightarrow> Y k = (\\<Squnion>i. Y i)\"\napply (subgoal_tac \"Y k \\<sqsubseteq> (\\<Squnion>i. Y i)\")\napply (drule eq_less_and_fst_inf, assumption+)\nby (rule is_ub_thelub)\n\ntext \\<open>\\<open>stake n\\<close> returns at most \\<open>n\\<close> elements\\<close>\nlemma ub_slen_stake[simp]: \"#(stake n\\<cdot>x) \\<le> Fin n\"\napply (rule spec [where x = x])\napply (induct_tac n, auto)\nby (rule_tac x=x in scases, auto)\n\ntext \\<open>\\<open>stake\\<close> always returns finite streams\\<close>\nlemma [simp]: \"#(stake n\\<cdot>x) \\<noteq> \\<infinity>\"\nproof (rule notI)\n  assume inf: \"#(stake n\\<cdot>x) = \\<infinity>\"\n  have \"#(stake n\\<cdot>x) \\<le> Fin n\" by (rule ub_slen_stake)\n  thus False using inf by simp\nqed\n\ntext \\<open>\\<open>stake\\<close>ing at least \\<open>#x\\<close> elements returns \\<open>x\\<close> again\\<close>\nlemma fin2stake_lemma: \"\\<forall>x k. #x = Fin k \\<and> k\\<le>i \\<longrightarrow> stake i\\<cdot>x = x\"\napply (induct_tac i, auto)\napply (rule_tac x=x in scases, auto)\nby (case_tac \"k\", auto)\n\ntext \\<open>\\<open>stake\\<close>ing \\<open>#x\\<close> elements returns \\<open>x\\<close> again\\<close>\nlemma fin2stake:\"#x = Fin n \\<Longrightarrow> stake n\\<cdot>x = x\"\n  by (rule fin2stake_lemma [rule_format, of \"x\" \"n\" \"n\"], simp)\n\ntext \\<open>\\<open>stake\\<close>ing only on element from an empty stream is the same as the stream consisting of \n      \\<open>shd\\<close> of the stream\\<close>\nlemma stake2shd:\"s\\<noteq>\\<epsilon> \\<Longrightarrow> stake (Suc 0)\\<cdot>s = \\<up>(shd s)\"\n  by(rule scases[of s],simp_all add: Nat.One_nat_def)\n\nlemma stake2shd2:\"s\\<noteq>\\<epsilon> \\<Longrightarrow> stake 1\\<cdot>s = \\<up>(shd s)\"\n  by(simp add: Nat.One_nat_def stake2shd)\n\n(* if the stream is not empty, it holds that its length is lnsuc\\<cdot>(#(srt\\<cdot>s)) *)\nlemma srt_decrements_length : \"s \\<noteq> \\<epsilon> \\<Longrightarrow> #s = lnsuc\\<cdot>(#(srt\\<cdot>s))\" by (metis slen_scons surj_scons)\n\n(* the empty stream is the shortest *)\nlemma empty_is_shortest : \"Fin n < #s \\<Longrightarrow> s \\<noteq> \\<epsilon>\" by (metis Fin_0 less_le lnle_Fin_0 strict_slen)\n\n(* if Fin (Suc n) is smaller than length of s, then also Fin n is smaller than length of s *)\nlemma convert_inductive_asm : \"Fin (Suc n) < #s \\<Longrightarrow> Fin n < #s\" by (metis Fin_leq_Suc_leq less_le not_le)\n\n(* only the empty stream has length zero *)\nlemma only_empty_has_length_0 : \"#s \\<noteq> 0 \\<Longrightarrow> s \\<noteq> \\<epsilon>\" by simp\n\n\n(* ----------------------------------------------------------------------- *)\nsection \\<open>Basic induction rules\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>induction for all prefixes\\<close>\nlemma stakeind: \n  \"\\<forall>x. (P \\<epsilon> \\<and> (\\<forall>a s. P s \\<longrightarrow> P (\\<up>a \\<bullet> s))) \\<longrightarrow> P (stake n\\<cdot>x)\"\nby (induct_tac n, auto, rule_tac x=x in scases, auto)\n\ntext \\<open>induction for finite streams\\<close>\nlemma finind:\n  \"\\<lbrakk>#x = Fin n; P \\<epsilon>; \\<And>a s. P s \\<Longrightarrow> P (\\<up>a \\<bullet> s)\\<rbrakk> \\<Longrightarrow> P x\"\napply (drule fin2stake)\napply (drule sym, erule ssubst)\napply (rule stakeind [rule_format])\napply (rule conjI, assumption)\napply (rule allI)+\nby (rule impI, simp)\n\ntext \\<open>induction for infinite streams and admissable predicates\\<close>\nlemma ind: \n  \"\\<lbrakk>adm P; P \\<epsilon>; \\<And>a s. P s  \\<Longrightarrow> P (\\<up>a \\<bullet> s)\\<rbrakk> \\<Longrightarrow> P x\"\napply (unfold adm_def)\napply (erule_tac x=\"\\<lambda>i. stake i\\<cdot>x\" in allE, auto)\napply (simp add: stakeind)\nby (simp add: reach_stream)\n\nlemma finind2: \"#s = Fin k \\<Longrightarrow> P \\<epsilon> \\<Longrightarrow> (\\<And>t a. #t < \\<infinity> \\<Longrightarrow> P t \\<Longrightarrow> P (\\<up>a \\<bullet> t)) \\<Longrightarrow> P s\"\nproof -\n  assume \"#s = Fin k\" and \"P \\<epsilon>\" and \"\\<And>t a. #t < \\<infinity> \\<Longrightarrow> P t \\<Longrightarrow> P (\\<up>a \\<bullet> t)\"\n  then show \"P s\"\n  proof (induction k arbitrary: s)\n    case 0\n    then show ?case\n      by auto\n  next\n    case (Suc k)\n    then obtain a t where \"s = \\<up>a \\<bullet> t\" and \"#t = Fin k\"\n      by (metis Fin_Suc bot_is_0 lnat.con_rews lnat.sel_rews(2) slen_empty_eq srt_decrements_length surj_scons)\n    then show ?case\n      by (simp add: Suc.IH Suc.prems(2) Suc.prems(3))\n  qed\nqed\n\nlemma finind3: \"#s < \\<infinity> \\<Longrightarrow> P \\<epsilon> \\<Longrightarrow> (\\<And>t a. #t < \\<infinity> \\<Longrightarrow> P t \\<Longrightarrow> P (\\<up>a \\<bullet> t)) \\<Longrightarrow> P s\"\n  by (metis finind2 less_le ninf2Fin)\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>Other properties of @{term stake}\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>composition of \\<open>stake\\<close>\\<close>\nlemma stakeostake[simp]: \"stake k\\<cdot>(stake n\\<cdot>x) = stake (min k n)\\<cdot>x\"\napply (rule_tac x=\"n\" in spec)\napply (rule_tac x=\"k\" in spec)\napply (rule ind [of _ x], simp+)\napply (rule allI)+\napply (case_tac \"xa\", simp+)\nby (case_tac \"x\", simp+)\n\n(* stake always returns a prefix of the input stream *)\nlemma ub_stake[simp]: \"stake n\\<cdot>x \\<sqsubseteq> x\"\nby (rule stream.take_below)\n\n(* definition of stake *)\nlemma stake_suc: \"stake (Suc n)\\<cdot>s = (stake 1\\<cdot>s) \\<bullet> stake n\\<cdot>(srt\\<cdot>s)\"\nby (metis (no_types, lifting) One_nat_def Rep_cfun_strict1 sconc_snd_empty stake_Suc stream.sel_rews(2) stream.take_0 stream.take_strict surj_scons)\n\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term sdrop}\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>basic properties of @{term sdrop}\\<close>\n\n(* dropping n\\<cdot>\\<epsilon> is the empty stream *)\nlemma strict_sdrop[simp]: \"sdrop n\\<cdot>\\<epsilon> = \\<epsilon>\"\nby (simp add: sdrop_def, induct_tac n, auto)\n\n(* dropping 0\\<cdot>s returns s *)\nlemma sdrop_0[simp]: \"sdrop 0\\<cdot>s = s\"\nby (simp add: sdrop_def)\n\n(* dropping an additional element is equivalent to calling srt *)\nlemma sdrop_back_rt: \"sdrop (Suc n)\\<cdot>s = srt\\<cdot>(sdrop n\\<cdot>s)\"\nby (simp add: sdrop_def)\n\n(* dropping an additional element is equivalent to sdrop with srt as part of the stream *)\nlemma sdrop_forw_rt: \"sdrop (Suc n)\\<cdot>s = sdrop n\\<cdot>(srt\\<cdot>s)\"\napply (simp add: sdrop_def)\nby (subst iterate_Suc2 [THEN sym], simp)\n\n(* dropping n + 1 elements from a non-empty stream is equivalent to dropping n items from the rest *)\nlemma sdrop_scons[simp]: \"sdrop (Suc n)\\<cdot>(\\<up>a \\<bullet> as) = sdrop n\\<cdot>as\"\nby (simp add: sdrop_forw_rt)\n\n(* if dropping n items produces the empty stream then the stream contains n elements or less *)\nlemma sdrop_stakel1: \"\\<forall>s. sdrop n\\<cdot>s = \\<epsilon> \\<longrightarrow> stake n\\<cdot>s = s\"\napply (induct_tac n, auto)\nby (rule_tac x=s in scases, auto)\n\n(* dropping k+x elements is equivalent to dropping x elements first and then k elements *) \nlemma sdrop_plus: \"sdrop (k+x)\\<cdot>xs = sdrop k\\<cdot>(sdrop x\\<cdot>xs)\"\nby (simp add: iterate_iterate sdrop_def)\n\ntext \\<open>Dropping from infinite streams still returns infinite streams\\<close>\nlemma fair_sdrop[rule_format]: \n  \"\\<forall>x. #x = \\<infinity> \\<longrightarrow> #(sdrop n\\<cdot>x) = \\<infinity>\"\napply (induct_tac n, simp, clarify)\nby (rule_tac x=x in scases, auto)\n\ntext \\<open>streams can be split by @{term stake} and @{term sdrop}\\<close>\nlemma split_streaml1[simp]: \n  \"stake n\\<cdot>s \\<bullet> sdrop n\\<cdot>s = s\"\napply (rule spec [where x = s])\napply (induct_tac n, auto)\nby (rule_tac x=x in scases, auto)\n\ntext \\<open>@{term sdrop} may only create infinite outputs for infinite inputs\\<close>\nlemma fair_sdrop_rev:\n  \"#(sdrop k\\<cdot>x) = \\<infinity> \\<Longrightarrow> #x = \\<infinity>\"\napply (simp add: atomize_imp)\napply (rule_tac x=\"x\" in spec)\napply (induct_tac k, simp)\napply (rule allI, rule impI)\napply (rule_tac x=\"x\" in scases, simp)\nby (erule_tac x=\"s\" in allE, simp)\n\ntext \\<open>construct @{term \"sdrop j\"} from @{term \"sdrop k\"} (with @{term \"j \\<le> k\"})\\<close>\nlemma sdropl5:\n  \"j \\<le> k \\<Longrightarrow> sdrop j\\<cdot>(stake k\\<cdot>x) \\<bullet> sdrop k\\<cdot>x = sdrop j\\<cdot>x\"\napply (simp add: atomize_imp)\napply (rule_tac x=\"j\" in spec)\napply (rule_tac x=\"x\" in spec)\napply (induct_tac k, auto)\napply (rule_tac x=\"x\" in scases, auto)\nby (case_tac \"xa\", auto)\n\ntext \\<open>Dropping as inverse of prepending a finite stream\\<close>\nlemma sdropl6:\n  \"#x = Fin k \\<Longrightarrow> sdrop k\\<cdot>(x \\<bullet> y) = y\"\napply (simp add: atomize_imp)\napply (rule_tac x=\"x\" in spec)\napply (rule_tac x=\"y\" in spec)\napply (induct_tac k, auto)\nby (rule_tac x=\"xa\" in scases, auto)\n\n(* relation between srt and drop *)\nlemma srt_drop : \"srt\\<cdot>(sdrop n\\<cdot>s) = sdrop (Suc n)\\<cdot>s\" by (simp add: sdrop_back_rt)\n\n(* sdrop n\\<cdot>s should not result in the empty stream *)\nlemma drop_not_all : \"Fin n < #s \\<Longrightarrow> sdrop n\\<cdot>s \\<noteq> \\<epsilon>\"\nproof (induct n)\n  show \"Fin 0 < #s \\<Longrightarrow> sdrop 0\\<cdot>s \\<noteq> \\<epsilon>\" by auto\n  \n  have \"\\<And> n. Fin n < #s \\<Longrightarrow> #(sdrop n\\<cdot>s) = lnsuc\\<cdot>(#(srt\\<cdot>(sdrop n\\<cdot>s)))\" by (metis not_le sdrop_stakel1 srt_decrements_length ub_slen_stake)\n  hence \"\\<And> n. Fin n < #s \\<Longrightarrow> sdrop n\\<cdot>s \\<noteq> \\<epsilon>\" using only_empty_has_length_0 by fastforce\n  thus \"\\<And> n. (Fin n < #s \\<Longrightarrow> sdrop n\\<cdot>s \\<noteq> \\<epsilon>) \\<Longrightarrow> Fin (Suc n) < #s \\<Longrightarrow> sdrop (Suc n)\\<cdot>s \\<noteq> \\<epsilon>\" by simp\nqed\n\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term snth}\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>Basic properties of @{term snth}\\<close>\n\n(* the element k + 1 of the stream s is identical to the element k of the rest of s *)\nlemma snth_rt: \"snth (Suc k) s = snth k (srt\\<cdot>s)\"\napply (simp add: snth_def)\nby (subst sdrop_forw_rt,rule refl)\n\n(* semantically equivalent to snth_rt *)\nlemma snth_scons[simp]: \"snth (Suc k) (\\<up>a \\<bullet> s) = snth k s\"\nby (simp add: snth_rt)\n\n(* indexing starts at 0, so the 0'th element is equal to the head *)\nlemma snth_shd[simp]: \"snth 0 s = shd s\"\nby (simp add: snth_def)\n\ntext \\<open>If two streams of same length agree on every element,\n  all their finite prefixes are equal\\<close>\nlemma snths_eq_lemma [rule_format]: \n  \"\\<forall>x y. #x = #y \\<and> (\\<forall>n. Fin n < #x \\<longrightarrow> snth n x = snth n y) \n           \\<longrightarrow> stake k\\<cdot>x = stake k\\<cdot>y\"\napply (induct_tac k, auto)\napply (rule_tac x=x in scases, auto)\napply (rule_tac x=y in scases, auto)\napply (erule_tac x=\"s\" in allE)\napply (erule_tac x=\"sa\" in allE, auto)\napply (erule_tac x=\"Suc na\" in allE, simp)\nby (erule_tac x=\"0\" in allE, auto)\n\ntext \\<open>If two streams of same length agree on every element, they are equal\\<close>\nlemma snths_eq: \n  \"\\<lbrakk>#x = #y; \\<forall>n. Fin n < #x \\<longrightarrow> snth n x = snth n y\\<rbrakk> \\<Longrightarrow> x = y\"\napply (rule stream.take_lemma)\nby (rule snths_eq_lemma, auto)\n\n(* easy to use rule to show equality on infinite streams *)\n(* if two finite streams x, s are identical at every position then x and s are identical *) \nlemma sinf_snt2eq: assumes \"#s=\\<infinity>\" and \"#x=\\<infinity>\" and \"\\<And>i. (snth i s = snth i x)\"\n  shows \"s=x\"\nby (simp add: assms snths_eq)\n\nlemma snthp_shd: assumes\"\\<And>n.  P(snth n s)\"\n  shows\"P(shd s)\"\n  by (metis assms snth_shd)\n\nlemma snthp_shd2:  assumes\"\\<And>n.  P(snth n (\\<up>m \\<bullet> s))\"\n  shows\"P(m)\"\n  by (metis assms shd1 snth_shd)\n\nlemma snthp_snth: assumes\"\\<And>n.  P(snth n (\\<up>m \\<bullet> s))\"\n      shows\"P(snth n(s))\"\n  by (metis assms snth_scons)\n\nlemma snthp_srt:  assumes\"\\<And>n. P(snth n (s))\"\n      shows\"P(snth n(srt\\<cdot>s))\"\n  by (metis assms snth_rt)\n(* ----------------------------------------------------------------------- *)\nsection \\<open>Further lemmas\\<close>\n(* ----------------------------------------------------------------------- *)\n\n(* concatenation is associative *)\nlemma assoc_sconc[simp]: \"(s1\\<bullet>s2)\\<bullet>s3 = s1\\<bullet>s2\\<bullet>s3\"\napply (rule_tac x=\"#s1\" in lncases, auto)\nby (rule finind [of \"s1\"], auto)\n\n(* 2 very specific lemmas, used in \\<open>stake_add\\<close> *)\n  lemma stake_conc: \"stake i\\<cdot>s \\<bullet> x = stake (Suc i)\\<cdot>s \\<Longrightarrow> x = stake 1\\<cdot>(sdrop i\\<cdot>s)\"\n  apply (induction i arbitrary: s)\n  apply (simp add: One_nat_def)\n  by (smt assoc_sconc inject_scons sdrop_forw_rt stake_Suc stream.take_strict strict_sdrop surj_scons) \n    \n  lemma stake_concat:\"stake i\\<cdot>s \\<bullet> stake (Suc j)\\<cdot>(sdrop i\\<cdot>s) = stake (Suc i)\\<cdot>s \\<bullet> stake j\\<cdot>(sdrop (Suc i)\\<cdot>s)\"\n  proof -\n    obtain x where x_def: \"stake i\\<cdot>s \\<bullet> x = stake (Suc i)\\<cdot>s\" \n      by (metis (no_types, hide_lams) Suc_n_not_le_n linear min_def split_streaml1 stream.take_take)  \n    thus ?thesis\n      by (smt One_nat_def Rep_cfun_strict1 assoc_sconc sconc_snd_empty sdrop_back_rt stake_Suc stake_conc stream.take_0 stream.take_strict strict_sdrop surj_scons)\n  qed\n\n(* for arbitrary natural numbers i, j and any streams s the following lemma holds: *)\nlemma stake_add: \"stake (i+j)\\<cdot>s = (stake i\\<cdot>s) \\<bullet> (stake j\\<cdot>(sdrop i\\<cdot>s))\"\napply (induction i arbitrary: j)\napply simp\nby (metis add_Suc_shift stake_concat)\n\ntext \\<open>Finite, equal streams agree on all postfixes\\<close>\nlemma inject_sconc: \"\\<lbrakk>#x = Fin k; x \\<bullet> y = x \\<bullet> z\\<rbrakk> \\<Longrightarrow> y = z\"\napply (simp add: atomize_imp)\napply (rule_tac x=x in spec)\napply (induct_tac k, auto)\napply (rule_tac x=x in scases, auto)\nby (drule inject_scons, auto)\n\nlemma sconc_inj: assumes \"#s < \\<infinity>\" \n  shows \"inj (Rep_cfun (sconc s))\"\n  by (meson assms injI inject_sconc lnat_well_h2)\n\n(* x is a prefix of x \\<bullet> y*) \nlemma sconc_prefix [simp]: \"x \\<sqsubseteq> x \\<bullet> y\"\napply (rule_tac x=\"#x\" in lncases, auto)\napply (rule finind [of x], auto)\nby (rule monofun_cfun_arg)\n\ntext \\<open>Prepending to infinite streams produces infinite streams again\\<close>\nlemma slen_sconc_snd_inf: \"#y=\\<infinity> \\<Longrightarrow> #(x \\<bullet> y) = \\<infinity>\"\napply (rule_tac x=\"#x\" in lncases, auto)\nby (rule finind [of \"x\"], auto)\n\n(* stake n results in a stream of length n, so sdrop n then results in the empty stream *)\nlemma sdropostake: \"sdrop n\\<cdot>(stake n\\<cdot>s) = \\<epsilon>\"\napply (rule spec [where x = n])\napply (rule ind [of _ s], auto)\nby (case_tac x, auto)\n\n(* for all x it holds that if (P \\<epsilon> \\<and> (\\<forall>a s. P s \\<longrightarrow> P (s \\<bullet> \\<up>a))) then it follows that P applied to stake n\\<cdot>x is true *)\nlemma stakeind2: \n  \"\\<forall>x. (P \\<epsilon> \\<and> (\\<forall>a s. P s \\<longrightarrow> P (s \\<bullet> \\<up>a))) \\<longrightarrow> P (stake n\\<cdot>x)\"\n  apply(induction n)\n   apply simp\n  apply auto\n  apply (subst stake_suc)\n  by (metis (no_types, lifting) sconc_snd_empty sdrop_back_rt sdropostake split_streaml1 stake_suc surj_scons)\n\n(* if P is admissible and P holds for the empty stream and \\<And>a s. P s implies P (s \\<bullet> \\<up>a) then P also holds for x *)\nlemma ind2: assumes \"adm P\" and \"P \\<epsilon>\"  and \"\\<And>a s. P s  \\<Longrightarrow> P (s \\<bullet> \\<up>a)\"\n  shows \"P x\"\nby (metis assms(1) assms(2) assms(3) stakeind2 stream.take_induct)\n\n(* if P holds for bottom and it holds that lscons: \"(\\<And>x xs. x\\<noteq>\\<bottom>\\<Longrightarrow>P xs \\<Longrightarrow> P (x&&xs))\" and the length of xs is finite, then P holds also for xs *)\nlemma stream_fin_induct: assumes Bot: \"P \\<bottom>\" and lscons: \"(\\<And>x xs. x\\<noteq>\\<bottom>\\<Longrightarrow>P xs \\<Longrightarrow> P (x&&xs))\" and fin: \"#xs<\\<infinity>\"\n  shows \"P xs\"\n  by (metis finind infI lnless_def sconc_fst_empty sconc_scons' sup'_def up_defined assms)\n\n(* if length of s is finite => P holds for s => P is admissible => P holds for s *)  \nlemma stream_infs: \"(\\<And>s. #s<\\<infinity> \\<Longrightarrow> P s) \\<Longrightarrow> adm P \\<Longrightarrow> P s\"\n  by (metis inf_less_eq leI notinfI3 slen_stake_fst_inf stream.take_induct)\n\nlemma slen_stake: \"#s \\<ge> Fin n \\<Longrightarrow> #(stake n\\<cdot>s) = Fin n\"\nproof (induction n)\n  case 0\n  then show ?case\n    by simp\nnext\n  case (Suc n)\n  assume \"#s \\<ge> Fin (Suc n)\"\n  then have \"#s \\<ge> Fin n\"\n    by (simp add: Suc.prems Fin_leq_Suc_leq)\n  obtain r where \"stake (Suc n)\\<cdot>s = (stake n\\<cdot>s) \\<bullet> r\"\n    by (metis (no_types) Rep_cfun_strict1 sconc_snd_empty stake_concat stream.take_0)\n  then have \"r \\<noteq> \\<epsilon>\"\n    by (metis (mono_tags, lifting) Fin_02bot Fin_Suc One_nat_def Suc.prems \\<open>Fin n \\<le> #s\\<close> bot_is_0 drop_not_all inject_Fin lnle_def lnless_def n_not_Suc_n only_empty_has_length_0 sdropostake slen_scons srt_drop stake_Suc stake_conc strictI surj_scons)\n  have \"#((stake n\\<cdot>s) \\<bullet> r) \\<ge> Fin (Suc n)\"\n  proof -\n    have f1: \"#(stake n\\<cdot>s) = Fin n\"\n      using Suc.IH \\<open>Fin n \\<le> #s\\<close> by fastforce\n    have f2: \"\\<forall>s sa. (sa::'a stream) \\<sqsubseteq> sa \\<bullet> s\"\n      by simp\n    have \"\\<exists>n. stake n\\<cdot>s \\<bullet> r \\<noteq> stake n\\<cdot>s \\<and> Fin n = Fin n\"\n      using f1 by (metis \\<open>r \\<noteq> \\<epsilon>\\<close> inject_sconc sconc_snd_empty)\n    then have \"#(stake n\\<cdot>s \\<bullet> r) \\<noteq> Fin n\"\n      by (metis Suc.IH \\<open>Fin n \\<le> #s\\<close> \\<open>r \\<noteq> \\<epsilon>\\<close> fin2stake sdropl6 sdropostake)\n    then show ?thesis\n      using f2 f1 by (metis (no_types) less2lnleD lnless_def monofun_cfun_arg)\n  qed\n  then show ?case\n    by (metis \\<open>stake (Suc n)\\<cdot>s = stake n\\<cdot>s \\<bullet> r\\<close> dual_order.antisym ub_slen_stake)\nqed\n\n(* ----------------------------------------------------------------------- *)\nsection \\<open>Additional lemmas for approximation, chains and continuity\\<close> \n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>A finite prefix of length @{term \"k\"} is created by @{term \"stake k\"}\\<close>\nlemma approxl1:\n  \"\\<forall>s1 s2. s1 \\<sqsubseteq> s2 \\<and> #s1 = Fin k \\<longrightarrow> stake k\\<cdot>s2 = s1\"\napply (induct_tac k, auto)\napply (rule_tac x=s1 in scases, auto)\napply (rule_tac x=s2 in scases, auto)\napply (erule_tac x=\"s\" in allE)\napply (erule_tac x=\"sa\" in allE)\nby (drule less_all_sconsD, auto)\n\ntext \\<open>A prefix of a stream is equal to the original one or a finite prefix\\<close>\nlemma approxl2:\n  \"s1 \\<sqsubseteq> s2 \\<Longrightarrow> (s1 = s2) \\<or> (\\<exists>n. stake n\\<cdot>s2 = s1 \\<and> Fin n = #s1)\"\napply (rule_tac x=\"#s1\" in lncases, auto)\napply (rule eq_less_and_fst_inf, assumption+)\nby (insert approxl1 \n  [rule_format, of \"s1\" \"s2\"], auto)\n\ntext \\<open>In infinite chains, all streams are finite\\<close>\nlemma inf_chainl1:\n  \"\\<lbrakk>chain Y; \\<not>finite_chain Y\\<rbrakk> \\<Longrightarrow> \\<exists>k. #(Y i) = Fin k\"\napply (rule ccontr, simp, frule infI)\napply (frule_tac k=\"i\" in inf2max, assumption)\napply (frule_tac i=\"i\" in max_in_chainI3, simp+)\nby (simp add: finite_chain_def)\n\ntext \\<open>Each prefix of a stream can be expanded to the original stream\\<close>\nlemma approxl3: \"s1 \\<sqsubseteq> s2 \\<Longrightarrow> \\<exists>t. s1\\<bullet>t = s2\"\napply (rule_tac x=\"#s1\" in lncases, simp)\napply (drule eq_less_and_fst_inf, simp+)\napply (subst approxl1 \n  [rule_format, of \"s1\" \"s2\", THEN sym], simp+)\nby (rule_tac x=\"sdrop k\\<cdot>s2\" in exI, simp)\n\ntext \\<open>In infinite chains, there is an element which is a true prefix of another one\\<close>\nlemma inf_chainl2:\n  \"\\<lbrakk>chain Y; \\<not> finite_chain Y\\<rbrakk> \\<Longrightarrow> \\<exists>j. Y k \\<sqsubseteq> Y j \\<and> #(Y k) < #(Y j)\"\napply (auto simp add: finite_chain_def max_in_chain_def)\napply (erule_tac x=\"k\" in allE, auto)\napply (frule_tac i=k and j=j in chain_mono, assumption)\napply (rule_tac x=\"j\" in exI, simp)\napply (auto simp add: lnless_def)\napply (rule mono_slen, assumption)\nby (frule eq_slen_eq_and_less, simp+)\n\ntext \\<open>In infinite chains, the length of the streams is unbounded\\<close>\nlemma inf_chainl3:\n  \"chain Y \\<and> \\<not>finite_chain Y \\<longrightarrow> (\\<exists>k. Fin n \\<le> #(Y k))\"\napply (induct_tac n, auto)\napply (case_tac \"Fin n = #(Y k)\")\napply (frule_tac k=k in inf_chainl2, auto)\napply (rule_tac x=\"j\" in exI)\napply (drule sym)\napply (rule_tac x=\"#(Y j)\" in lncases, auto)\napply (rule_tac x=\"k\" in exI)\nby (rule_tac x=\"#(Y k)\" in lncases, auto)\n\ntext \\<open>In infinite chains, the lub is infinite\\<close>\nlemma inf_chainl4:\n  \"\\<lbrakk>chain Y; \\<not>finite_chain Y\\<rbrakk> \\<Longrightarrow> #(lub(range Y)) = \\<infinity>\"\napply (rule_tac x=\"#(Lub Y)\" in lncases, auto)\napply (frule_tac n = \"Suc k\" in inf_chainl3 \n  [rule_format, OF conjI], assumption, erule exE)\napply (subgoal_tac \"Y ka \\<sqsubseteq> (Lub Y)\")\napply (drule monofun_cfun_arg [of _ _ slen], simp)\napply (frule_tac x = \"Fin (Suc k)\" and \n  y = \"#(Y ka)\" and z = \"Fin k\" in trans_lnle, simp+)\nby (rule is_ub_thelub)\n\ntext \\<open>Each chain becomes finite by mapping @{term \"stake n\"} to every element\\<close>\nlemma finite_chain_stake: \n  \"chain Y \\<Longrightarrow> finite_chain (\\<lambda>i. stake n\\<cdot>(Y i))\"\napply (frule ch2ch_Rep_cfunR [of _ \"stake n\"])\napply (rule ccontr)\napply (frule inf_chainl4 [of \"\\<lambda>i. stake n\\<cdot>(Y i)\"],assumption)\nby (simp add: contlub_cfun_arg [THEN sym])\n\ntext \\<open>every finite prefix of the lub is also prefix of some element in the chain\\<close>\nlemma lub_approx: \n  \"chain Y \\<Longrightarrow> \\<exists>k. stake n\\<cdot>(lub (range Y)) = stake n\\<cdot>(Y k)\"\napply (subst contlub_cfun_arg, assumption)\napply (frule finite_chain_stake [of _ n])\napply (simp add: finite_chain_def, auto)\napply (rule_tac x=\"i\" in exI)\nby (rule lub_finch1  \n  [THEN lub_eqI, of \"\\<lambda>i. stake n\\<cdot>(Y i)\"], auto)\n\ntext \\<open>If @{term f} is monotone and for each @{term x} there is a finite prefix\n  @{term y} such that @{term \"f x = f y\"}, @{term f} is continuous\\<close>\nlemma pr_contI: \n  \"\\<lbrakk>monofun f; \\<forall>x.\\<exists>n. (f x) = f (stake n\\<cdot>x)\\<rbrakk> \\<Longrightarrow> cont f\"\napply (rule contI2, assumption)\napply (rule allI, rule impI)\napply (erule_tac x=\"lub (range Y)\" in allE, erule exE)\napply (frule_tac n = n in lub_approx, erule exE)\napply (subgoal_tac \"f (stake n\\<cdot>(Y k)) \\<sqsubseteq> f (Y k)\")\napply (subgoal_tac \"f (Y k) \\<sqsubseteq> (\\<Squnion>i. f (Y i))\")\napply (drule_tac x=\"f (stake n\\<cdot>(Y k))\" and \n  y=\"f (Y k)\" and z = \"\\<Squnion>i. f (Y i)\" in below_trans)\napply (rule is_ub_thelub)\napply (rule_tac f=f in ch2ch_monofun, assumption+)\napply (clarsimp)\napply (rule is_ub_thelub)\napply (rule_tac f=f in ch2ch_monofun, assumption+)\nby (rule_tac f = f in monofunE, simp+)\n\ntext \\<open>For continuous functions, each finite prefix of @{term \"f\\<cdot>x\"} only\n  depends on a finite prefix of @{term \"x\"}\\<close>\nlemma fun_approxl1: \n  \"\\<exists>j. stake k\\<cdot>(f\\<cdot>x) = stake k\\<cdot>(f\\<cdot>(stake j\\<cdot>x))\"\napply (subgoal_tac \"f\\<cdot>x = (\\<Squnion>i. f\\<cdot>(stake i\\<cdot>x))\")\napply (erule ssubst)\napply (rule lub_approx)\napply (rule chain_monofun)\napply (rule ch2ch_Rep_cfunL)\napply (rule stream.chain_take)\napply (subst contlub_cfun_arg [THEN sym])\napply (rule ch2ch_Rep_cfunL)\napply (rule stream.chain_take)\napply (subst reach_stream)\nby (rule refl)\n\ntext \\<open>For continuous functions, any finite output for stream @{term \"x\"} can also be\n  obtained by some finite prefix of @{term \"x\"}\\<close>\nlemma fun_approxl2: \"#(f\\<cdot>x) = Fin k \\<Longrightarrow> \\<exists>j. f\\<cdot>x = f\\<cdot>(stake j\\<cdot>x)\" \napply (insert fun_approxl1 [of k \"f\" x], auto)\napply (rule_tac x=\"j\" in exI)\napply (frule fin2stake [THEN sym], simp)\napply (rule stream.take_lemma, simp)\napply (case_tac \"n \\<le> k\")\napply (simp add: min_def)+\napply (rule po_eq_conv [THEN iffD2])\napply (rule conjI)\napply (rule monofun_cfun_fun)\napply (rule chain_mono)\napply (rule stream.chain_take, simp+)\napply (subgoal_tac \"f\\<cdot>(stake j\\<cdot>x) \\<sqsubseteq> f\\<cdot>x\")\napply (rule below_trans, auto)\napply (drule sym, drule sym, simp)\nby (rule monofun_cfun_arg, simp)\n\n(* if two streams are unequal, it holds for a finite stream a that a \\<bullet> s1 is unequal to a \\<bullet> s2 *)\nlemma sconc_neq_h: assumes \"s1 \\<noteq> s2\"\n  shows \"#a < \\<infinity> \\<longrightarrow> a \\<bullet> s1 \\<noteq> a \\<bullet> s2\"\n  apply(rule ind [of _a ])\n    apply(rule admI)\n    apply (rule impI)\n    apply (metis inf_chainl4 l42 neq_iff)\n   apply (simp add: assms)\n  by (metis inf_ub inject_scons less_le sconc_scons slen_sconc_snd_inf)\n\n(* if two streams are unequal and a stream a has finite lenght, it holds that a \\<bullet> s1 is unequal to a \\<bullet> s2 *)  \nlemma sconc_neq: assumes \"s1 \\<noteq> s2\" and \"#a < \\<infinity>\"\n  shows \"a \\<bullet> s1 \\<noteq> a \\<bullet> s2\"\nusing assms(1) assms(2) sconc_neq_h by blast\n\nlemma stake_prefix: \"#s < \\<infinity> \\<Longrightarrow> t \\<noteq> \\<epsilon> \\<Longrightarrow> s = t \\<bullet> u \\<Longrightarrow> \\<exists>k. t = stake (Suc k)\\<cdot>s\"\nproof -\n  assume \"#s < \\<infinity>\" and \"t \\<noteq> \\<epsilon>\" and \"s = t \\<bullet> u\"\n  then obtain k where \"t = stake k\\<cdot>s\"\n    by (metis approxl2 fin2stake inf_less_eq minimal monofun_cfun_arg ninf2Fin not_le sconc_snd_empty)\n  then obtain l where \"k = Suc l\"\n    by (metis Rep_cfun_strict1 \\<open>t \\<noteq> \\<epsilon>\\<close> not0_implies_Suc stream.take_0)\n  thus ?thesis\n    using \\<open>t = stake k\\<cdot>s\\<close> by blast\nqed\n\nlemma stake_prefix2: \"#s = Fin n \\<Longrightarrow> s = stake n\\<cdot>(s \\<bullet> t)\"\n  by (metis approxl1 minimal monofun_cfun_arg sconc_snd_empty)\n\nlemma slen_conc: \"#s < \\<infinity> \\<Longrightarrow> t \\<noteq> \\<epsilon> \\<Longrightarrow> #s \\<ge> Fin n \\<Longrightarrow> #(s \\<bullet> t) > Fin n\"\n  by (metis (no_types, hide_lams) stake_prefix2 infI less_le less_le_trans mono_slen sconc_neq sconc_snd_empty stream.take_below)\n\nlemma stake_srt_conc [simp]: \"srt\\<cdot>((stake 1\\<cdot>s)\\<bullet>(s)) = s\"\n  apply (cases s)\n  apply simp\n  by (metis One_nat_def Rep_cfun_strict1 lscons_conv sconc_snd_empty stake_Suc stream.con_rews(2) stream.sel_rews(5) stream.take_0 surj_scons)\n\n(* ----------------------------------------------------------------------- *)\nsection \\<open>Lemmas for the remaining definitions\\<close>\n(* ----------------------------------------------------------------------- *)\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term slookahd}\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>@{term slookahd} is continuous\\<close>\nlemma cont_slookahd[simp]: \"cont (\\<lambda> s. if s=\\<epsilon> then \\<bottom> else eq (shd s))\"\napply (rule pr_contI)\napply (rule monofunI, auto)\napply (rule_tac x=x in scases, auto)\napply (rule_tac x=y in scases, auto)\napply (drule less_all_sconsD, simp)\napply (rule_tac x=x in scases, auto)\nby (rule_tac x=\"Suc 0\" in exI, auto)\n\n(* slookahd applied to the empty stream results in the bottom element for any function eq *)\nlemma strict_slookahd[simp]: \"slookahd\\<cdot>\\<epsilon>\\<cdot>eq = \\<bottom>\"\nby (simp add: slookahd_def cont2cont_LAM)\n\n(* if s isn't the empty stream, the function eq will be applied to the head of s *)\nlemma slookahd_scons[simp]: \"s\\<noteq>\\<epsilon> \\<Longrightarrow> slookahd\\<cdot>s\\<cdot>eq = eq (shd s)\"\nby (simp add: slookahd_def cont2cont_LAM)\n\n(* the constant function that always returns the empty stream unifies the two cases of slookahd *)\nlemma strict2_slookahd[simp]: \"slookahd\\<cdot>xs\\<cdot>(\\<lambda>y. \\<epsilon>) = \\<epsilon>\"\nby (cases xs, simp_all)\n\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term sinftimes}\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>basic properties of @{term sntimes} and @{term sinftimes}\\<close>\n\n(* repeating the empty stream produces the empty stream again for any n*)\nlemma sntimes_eps[simp]: \"sntimes n \\<epsilon> = \\<epsilon>\"\nby (induct_tac n, simp+)\n\n(* after repeating the stream \\<up>s n-times the head is s *)\n  (* n>0 otherwise \\<open>0 \\<star> \\<up>s = \\<epsilon>\\<close> *)\nlemma shd_sntime [simp]: assumes \"n>0\" shows \"shd (n \\<star> \\<up>s) = s\"\nby (metis assms gr0_implies_Suc shd1 sntimes.simps(2))\n\n(* infinitely cycling the empty stream produces the empty stream again *)\nlemma strict_icycle[simp]: \"sinftimes \\<epsilon> = \\<epsilon>\"\nby (subst sinftimes_def [THEN fix_eq2], auto)\n\n(* repeating a stream infinitely often is equivalent to repeating it once and then infinitely often *)\nlemma sinftimes_unfold: \"sinftimes s = s \\<bullet> sinftimes s\"\nby (subst sinftimes_def [THEN fix_eq2], auto)\n\ntext \\<open>For nonempty @{term s}, @{term \"sinftimes s\"} is infinite\\<close>\nlemma slen_sinftimes: \"s \\<noteq> \\<epsilon> \\<Longrightarrow> #(sinftimes s) = \\<infinity>\"\napply (rule ccontr)\napply (rule_tac x=\"#(sinftimes s)\" in lncases, auto)\napply (rule_tac x=\"#s\" in lncases)\napply (insert sinftimes_unfold [of s], auto)\nby (insert slen_sconc_all_finite \n  [rule_format, of \"s\" _ \"sinftimes s\"], force)\n\n(* lenght of sinftimes of (\\<up>a) is infinity *)\nlemma [simp]: \"#(sinftimes (\\<up>a)) = \\<infinity>\" \nby (simp add: slen_sinftimes)\n\n(* converting the element x to a singleton stream, repeating the singleton and re-extracting x with\n   lshd is equivalent to imposing the discrete order on x *)\nlemma lshd_sinf [simp]: \"lshd\\<cdot>\\<up>x\\<^sup>\\<infinity> = updis x\"\nby (metis lshd_updis sinftimes_unfold)\n\n(* the infinite repetition of the stream x has the same head as x *)\nlemma shd_sinf[simp]: \"shd (x\\<^sup>\\<infinity>) = shd x\"\nby (metis assoc_sconc shd1 sinftimes_unfold strict_icycle surj_scons)\n\n(* srt has no effect on an infinite constant stream of x *)\nlemma srt_sinf [simp]: \"srt\\<cdot>\\<up>x\\<^sup>\\<infinity> = ((\\<up>x)\\<^sup>\\<infinity>)\"\nby (metis lscons_conv sinftimes_unfold stream.sel_rews(5) up_defined)\n\n(* if the stream x contains y elements then the first y elements of the infinite repetition of x will\n   be x again *)\nlemma stake_y [simp]: assumes \"#x = Fin y\"\n    shows \"stake y\\<cdot>(sinftimes x) = x\"\nby (metis approxl1 assms minimal monofun_cfun_arg sconc_snd_empty sinftimes_unfold)\n\n(* the infinite repetitions of the singleton stream \\<up>s consists only of the element s *)\nlemma snth_sinftimes[simp]: \"snth i ((\\<up>s)\\<^sup>\\<infinity>) = s\"\napply (induction i)\napply (simp) \nby (simp add: snth_rt)\n\n(* dropping any finite number of elements from an infinite constant stream doesn't affect the stream *)\nlemma sdrops_sinf[simp]: \"sdrop i\\<cdot>((\\<up>x)\\<^sup>\\<infinity>) = ((\\<up>x)\\<^sup>\\<infinity>)\"\napply (induction i)\napply(simp)\nby (simp add: sdrop_forw_rt)\n\n(* for a finite natural number \"i\", following relation between sntimes and stake holds:  *)\nlemma sntimes_stake: \"i \\<star> \\<up>x = stake i\\<cdot>((\\<up>x)\\<^sup>\\<infinity>)\"\napply(induction i)\napply simp\nby (metis sinftimes_unfold sntimes.simps(2) stake_Suc) \n\n(* for every finite number \"i\" is sntimes \\<noteq> sinftimes. *)\nlemma snNEqSinf [simp]: \"i \\<star> \\<up>x \\<noteq> ((\\<up>x)\\<^sup>\\<infinity>)\"\nby (metis lshd_sinf sdropostake sdrops_sinf sntimes_stake stream.sel_rews(3) up_defined)\n\n(* for every natural number i, dropping the first (i*y) elements results in the same infinite stream *)\n  (* the first i \"blocks\" of x are dropped *)\nlemma sdrop_sinf[simp]: assumes \"Fin y = #x\"\n  shows \"sdrop (i * y)\\<cdot>(sinftimes x) = sinftimes x\"\napply(induction i)\napply(simp)\nby (metis assms mult_Suc sdrop_plus sdropl6 sinftimes_unfold) \n\n(* repeating the empty stream again produces the empty stream *)\nlemma sinf_notEps[simp]: assumes \"xs \\<noteq> \\<epsilon>\" shows \"(sinftimes xs) \\<noteq> \\<epsilon>\"\nusing assms slen_sinftimes by fastforce\n\n(* sinftimes has no effect on streams that are already infinite *)\n(* removed simp because of lemma stakewhile_sinftimes_lemma*)\nlemma sinf_inf: assumes \"#s = \\<infinity>\" \n  shows \"s\\<^sup>\\<infinity> = s\"\nby (metis assms sconc_fst_inf sinftimes_unfold)\n\n(* sinftimes is idempotent *)\nlemma sinf_dupE [simp]: \"(sinftimes s)\\<^sup>\\<infinity> = (s\\<^sup>\\<infinity>)\"\nusing sinf_inf slen_sinftimes by force\n\n(* alternative unfold rule for sntimes, new element is appended on the end *)\nlemma sntimes_Suc2: \"(Suc i) \\<star> s = (i\\<star>s) \\<bullet> s\"\napply (induction i)\napply simp\nby (metis assoc_sconc sntimes.simps(2))\n\n(* Blockwise stake from sinftimes to sntimes. *)\nlemma sinf2sntimes: assumes \"Fin y = #x\"\n  shows \"stake (i*y)\\<cdot>(x\\<^sup>\\<infinity>) = i\\<star>x\"\napply(induction i)\napply simp\nby (metis assms mult_Suc sdrop_plus sdrop_sinf sntimes.simps(2) stake_add stake_y) \n\n(* for any natural number i, sntimes is a prefix of sinftimes *)\nlemma snT_le_sinfT [simp]: \"i\\<star>s \\<sqsubseteq> (s\\<^sup>\\<infinity>)\"\nby (metis minimal monofun_cfun_arg ninf2Fin sconc_fst_inf sconc_snd_empty sinf2sntimes sinf_inf sntimes.simps(2) sntimes_Suc2 ub_stake)\n\n(* repeating the stream s i times produces a prefix of repeating s i+1 times *)\nlemma sntimes_leq: \"i\\<star>s \\<sqsubseteq> (Suc i)\\<star>s\"\nby (metis minimal monofun_cfun_arg sconc_snd_empty sntimes_Suc2)\n\n(* the repetitions of a stream constitute a chain *)\nlemma sntimes_chain: \"chain (\\<lambda>i. i\\<star>s)\"\nby (meson po_class.chainI sntimes_leq)\n\n(* xs is an infinite repetition of the finite stream x. Then dropping any fixed number i of repetitions\n   of x leaves xs unchanged. *)\nlemma sdrop_sinf2: assumes \"xs = x\\<bullet>xs\" and \"#x = Fin y\"\n  shows \"sdrop (y*i)\\<cdot>xs = xs\"\napply (induction i)\napply simp \nby (metis assms mult_Suc_right sdrop_plus sdropl6) \n\n(* the recursive definition for a stream (xs = x\\<bullet>xs) is identical to the infinite repetition of x at\n   every multiple of the length of x *)\nlemma stake_eq_sinf: assumes \"xs = x\\<bullet>xs\" and \"#x = Fin y\" \n  shows \"stake (i*y)\\<cdot>xs = stake (i*y)\\<cdot>(sinftimes x)\"\nproof (induction i)\n  case 0 thus ?case by simp\nnext\n  case (Suc i) \n  have drop_xs:\"sdrop (i*y)\\<cdot>xs = xs\" by (metis assms mult.commute sdrop_sinf2) \n\n  have \"stake (Suc i * y)\\<cdot>xs  =  stake (i*y)\\<cdot>xs \\<bullet> stake y\\<cdot>(sdrop (i*y)\\<cdot>xs)\" by (metis add.commute mult_Suc stake_add) \n  hence eq1:\"stake (Suc i * y)\\<cdot>xs =  stake (i*y)\\<cdot>xs \\<bullet> x\"  by (metis approxl1 assms drop_xs minimal monofun_cfun_arg sconc_snd_empty)\n  \n  have \"stake (Suc i * y)\\<cdot>(sinftimes x) = stake (i*y)\\<cdot>(sinftimes x) \\<bullet> stake y\\<cdot>(sdrop (i*y)\\<cdot>(sinftimes x))\"  \n    by (metis add.commute mult_Suc stake_add)\n  hence eq2:\"stake (Suc i * y)\\<cdot>(sinftimes x) =  stake (i*y)\\<cdot>(sinftimes x) \\<bullet> x\" by (simp add: assms(2)) \n\n  thus ?case using Suc.IH eq1 by auto \nqed\n\n(* when repeating a stream s a different number of times, one of the repetitions will be a prefix of\n   the other *)\nlemma stake_sntimes2sntimes: assumes \"j\\<le>k\" and \"#s = Fin y\"\n  shows \"stake (j*y)\\<cdot>(k\\<star>s) = j\\<star>s\"\nby (smt assms(1) assms(2) min_def mult_le_mono1 sinf2sntimes stakeostake)\n\n(* for a stream s, a natural y and an arbitrary natural j, apply blockwise stake sntimes. *)\nlemma lubStake2sn: assumes \"#s = Fin y\"\n  shows \"(\\<Squnion> i. stake (y*j)\\<cdot>(i\\<star>s)) = j\\<star>s\" (is \"(\\<Squnion>i. ?c i) = _\")\nproof -\n  have \"max_in_chain j (\\<lambda>i. ?c i)\" by (simp add: assms max_in_chainI mult.commute stake_sntimes2sntimes) \n  thus ?thesis by (simp add: assms maxinch_is_thelub mult.commute sntimes_chain stake_sntimes2sntimes)  \nqed\n\n(* building block of the lemma sntimesLub_Fin *)\nlemma sntimesChain: assumes \"#s = Fin y\" and \"y \\<noteq> 0\"\n  shows \"\\<forall>j. stake (y*j)\\<cdot>(\\<Squnion> i. i\\<star>s) = stake (y*j)\\<cdot> (s\\<^sup>\\<infinity>)\"\nby (metis assms(1) contlub_cfun_arg lubStake2sn mult.commute sinf2sntimes sntimes_chain)\n\n(* proof for lemma sntimesLub_Fin *)\nlemma sntimesLub_Fin: assumes \"#s = Fin y\" and \"y \\<noteq> 0\"\n  shows \"(\\<Squnion> i. i\\<star>s) = (s\\<^sup>\\<infinity>)\"\nproof - \n  have  \"\\<forall>j. stake (j*y)\\<cdot>(\\<Squnion> i. i\\<star>s) = stake (j*y)\\<cdot> (s\\<^sup>\\<infinity>)\" by (metis assms(1) assms(2) mult.commute sntimesChain) \n  hence \"\\<forall>j. stake j\\<cdot>(\\<Squnion> i. i\\<star>s) = stake j\\<cdot> (s\\<^sup>\\<infinity>)\" using assms by (metis gstake2stake)\n  thus ?thesis by (simp add:  stream.take_lemma)\nqed\n\n(* for any stream s the LUB of sntimes is sinftimes *)\nlemma sntimesLub[simp]:\"(\\<Squnion> i. i\\<star>s) = (s\\<^sup>\\<infinity>)\"\napply(cases \"#s = \\<infinity>\")\napply (metis inf2max sconc_fst_inf sinf_inf sntimes.simps(2) sntimes_chain)\nby (metis Fin_0 lncases lub_eq_bottom_iff slen_empty_eq sntimesLub_Fin sntimes_chain sntimes_eps strict_icycle)\n\n(* shows that any recursive definition with the following form is equal to sinftimes *)\nlemma rek2sinftimes: assumes \"xs = x \\<bullet> xs\" and \"x\\<noteq>\\<epsilon>\"\n  shows \"xs = sinftimes x\"\nproof (cases \"#x = \\<infinity>\")\n  case True thus ?thesis by (metis assms(1) sconc_fst_inf sinftimes_unfold)\nnext\n  case False \n  obtain y where y_def: \"Fin y = #x \\<and> y\\<noteq>0\"  by (metis False Fin_02bot assms(2) infI lnzero_def slen_empty_eq)\n  hence \"\\<forall>i. stake (i*y)\\<cdot>xs = stake (i*y)\\<cdot>(x\\<^sup>\\<infinity>)\" using assms(1) stake_eq_sinf by fastforce  \n  hence \"\\<forall>i. stake i\\<cdot>xs = stake i\\<cdot>(x\\<^sup>\\<infinity>)\" using gstake2stake y_def by blast \n  thus ?thesis by (simp add: stream.take_lemma)\nqed\n\n(* specializes the result from rek2sinftimes to singleton streams *)\nlemma s2sinftimes: assumes \"xs = \\<up>x \\<bullet> xs\"\n  shows \"xs = ((\\<up>x)\\<^sup>\\<infinity>)\"\nusing assms rek2sinftimes by fastforce\n\n(* shows that the infinite repetition of a stream x is the least fixed point of iterating (\\<Lambda> s. x \\<bullet> s),\n   which maps streams to streams *)\nlemma fix2sinf[simp]: \"fix\\<cdot>(\\<Lambda> s. x \\<bullet> s) = (x\\<^sup>\\<infinity>)\"\n  by (metis eta_cfun fix_eq fix_strict rek2sinftimes sconc_snd_empty strict_icycle)\n\nlemma snth_bool_sinftimes: \"snth (Suc n) ((\\<up>bool \\<bullet> \\<up>(\\<not> bool))\\<^sup>\\<infinity>) = (\\<not> snth n ((\\<up>bool \\<bullet> \\<up>(\\<not>bool))\\<^sup>\\<infinity>))\"\n  apply (induction n)\n  apply (metis assoc_sconc shd1 sinftimes_unfold snth_scons snth_shd)\n  by (metis (no_types, hide_lams) sconc_fst_empty sconc_scons' sinftimes_unfold snth_scons sup'_def)\n\nlemma sinftimes_srt: \"srt\\<cdot>((\\<up>a \\<bullet> \\<up>b)\\<^sup>\\<infinity>) = ((\\<up>b \\<bullet> \\<up>a)\\<^sup>\\<infinity>)\"\n  apply (subst sinftimes_unfold, simp)\n  by (metis (no_types, lifting) assoc_sconc rek2sinftimes sinftimes_unfold strictI)\n  \nlemma sinftimes_snth:\"(n mod 2 = 0 \\<longrightarrow> snth n ((\\<up>a \\<bullet> \\<up>b)\\<^sup>\\<infinity>) = a) \\<and> (n mod 2 = 1 \\<longrightarrow> snth n ((\\<up>a \\<bullet> \\<up>b)\\<^sup>\\<infinity>) = b)\"\nproof(induction n arbitrary: a b)\n  case 0\n  then show ?case \n    by simp\nnext\n  case (Suc n)\n  moreover obtain m where m_def:\"n\\<noteq>0 \\<Longrightarrow> n = Suc m\"\n    using not0_implies_Suc by auto\n  ultimately show ?case\n    apply(cases \"n = 0\")\n    apply(subst sinftimes_unfold, simp)\n    apply (metis sconc_scons shd1 sinftimes_unfold snth_scons snth_shd)\n    apply auto\n    apply(subst sinftimes_unfold, simp)\n    apply (simp add: snth_rt)\n    apply (metis One_nat_def even_Suc parity_cases sinftimes_srt)\n    apply(subst sinftimes_unfold, simp)\n    apply (simp add: snth_rt)\n    by (metis One_nat_def even_Suc parity_cases sinftimes_srt)\nqed\n\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term smap}\\<close>\n(* ----------------------------------------------------------------------- *)\n\n(* smapping a function to the empty stream gives us the empty stream *)\nlemma strict_smap[simp]: \"smap f\\<cdot>\\<epsilon> = \\<epsilon>\"\nby (subst smap_def [THEN fix_eq2], simp)\n\n(* smap distributes over concatenation *)\nlemma smap_scons[simp]: \"smap f\\<cdot>(\\<up>a \\<bullet> s) = \\<up>(f a) \\<bullet> smap f\\<cdot>s\"\nby (subst smap_def [THEN fix_eq2], simp)\n\n(* if \\<And>a as. f\\<cdot>(\\<up>a \\<bullet> as) is equal to \\<up>(g a) \\<bullet> f\\<cdot>as and f applied to bottom returns the bottom element, then\n f applied to s is the same as applying smap to g\\<cdot>s *)\nlemma rek2smap: assumes \"\\<And>a as. f\\<cdot>(\\<up>a \\<bullet> as) = \\<up>(g a) \\<bullet> f\\<cdot>as\"\n  and \"f\\<cdot>\\<bottom> = \\<bottom>\"\n  shows \"f\\<cdot>s = smap g\\<cdot>s\"\napply(rule ind [of _s])\nby(simp_all add: assms)\n\n(* mapping f over a singleton stream is equivalent to applying f to the only element in the stream *) \nlemma [simp]: \"smap f\\<cdot>(\\<up>a) = \\<up>(f a)\"\nby (subst smap_def [THEN fix_eq2], simp)\n\n(* smap leaves the length of a stream unchanged *)\nlemma slen_smap[simp]: \"#(smap f\\<cdot>x) = #x\"\nby (rule ind [of _ x], auto)\n\ntext \\<open>@{term smap} maps each element @{term x} to @{term \"f(x)\"}\\<close>\nlemma smap_snth_lemma:\n  \"Fin n < #s \\<Longrightarrow> snth n (smap f\\<cdot>s) = f (snth n s)\"\napply (simp add: atomize_imp)\napply (rule_tac x=\"s\" in spec)\napply (induct_tac n, simp+)\nby (rule allI, rule_tac x=\"x\" in scases, simp+)+\n\ntext\\<open>Doing smap in two passes, applying h in the first pass and g in the second is\nequivalent to applying g \\<circ> h in a single pass\\<close>\nlemma smaps2smap: \"smap g\\<cdot>(smap h\\<cdot>xs) =  smap (\\<lambda> x. g (h x))\\<cdot>xs\"\nby (simp add: smap_snth_lemma snths_eq)\n\ntext \\<open>@{term sdrop} after @{term smap} is like @{term smap} after @{term sdrop}\\<close>\nlemma sdrop_smap[simp]: \"sdrop k\\<cdot>(smap f\\<cdot>s) = smap f\\<cdot>(sdrop k\\<cdot>s)\"\napply (rule_tac x=\"k\" in spec)\napply (rule ind [of _ s], simp+)\napply (rule allI)\nby (case_tac \"x\", simp+)\n\ntext \\<open>@{term \"smap f\"} is a homomorphism on streams with respect to concatenation\\<close>\nlemma smap_split: \"smap f\\<cdot>(a \\<bullet> b) = (smap f\\<cdot>a) \\<bullet> (smap f\\<cdot>b)\"\nproof (rule lncases [of \"#a\"], simp)\n  fix k assume \"#a = Fin k\"\n  thus ?thesis by (rule finind [of \"a\"], simp_all)\nqed\n\n(* smap distributes over infinite repetition *)\nlemma smap2sinf[simp]: \"smap f\\<cdot>(x\\<^sup>\\<infinity>)= ((smap f\\<cdot>x)\\<^sup>\\<infinity>)\"\nby (metis (no_types) rek2sinftimes sinftimes_unfold slen_empty_eq slen_smap smap_split strict_icycle)\n\n(* smap and infinity *)\nlemma l5: \"smap g\\<cdot>((\\<up>x)\\<^sup>\\<infinity>) = ((\\<up>(g x))\\<^sup>\\<infinity>)\"\n  by simp\n\n(* for any nonempty stream it holds that smap f to stream s is \\<up>(f (shd s)) \\<bullet> smap f\\<cdot>(srt\\<cdot>s) *) \nlemma smap_hd_rst : \"s \\<noteq> \\<epsilon> \\<Longrightarrow> smap f\\<cdot>s = \\<up>(f (shd s)) \\<bullet> smap f\\<cdot>(srt\\<cdot>s)\" by (metis smap_scons surj_scons)\n\n\n\n\nlemma smap_inj:\"inj f \\<Longrightarrow> inj (Rep_cfun (smap f))\"\n  apply(rule injI)\n  apply(rule snths_eq,auto)\n  apply (metis slen_smap)\n  by (metis inj_eq slen_smap smap_snth_lemma)\n\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term sprojfst} and @{term sprojsnd}\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>basic properties of @{term sprojfst}\\<close>\n\n(* sprojfst extracts the first element of the first tuple in any non-empty stream of tuples *)\nlemma sprojfst_scons[simp]: \"sprojfst\\<cdot>(\\<up>(x, y) \\<bullet> s) = \\<up>x \\<bullet> sprojfst\\<cdot>s\"\nby (unfold sprojfst_def, simp)\n\n(* the empty stream is a fixed point of sprojfst *)\nlemma strict_sprojfst[simp]: \"sprojfst\\<cdot>\\<epsilon> = \\<epsilon>\"\nby (unfold sprojfst_def, simp)\n\n(* sprojfst extracts the first element of any singleton tuple-stream *)\nlemma [simp]: \"sprojfst\\<cdot>(\\<up>(a,b)) = \\<up>a\"\nby (simp add: sprojfst_def)\n\ntext \\<open>same properties for @{term sprojsnd}\\<close>\n\n(* sprojsnd extracts the second element of the first tuple in any non-empty stream of tuples *)\nlemma sprojsnd_scons[simp]: \"sprojsnd\\<cdot>(\\<up>(x,y) \\<bullet> s) = \\<up>y \\<bullet> sprojsnd\\<cdot>s\"\nby (unfold sprojsnd_def, simp)\n\n(* the empty stream is a fixed point of sprojsnd *)\nlemma strict_sprojsnd[simp]: \"sprojsnd\\<cdot>\\<epsilon> = \\<epsilon>\"\nby (unfold sprojsnd_def, simp)\n\n(* sprojsnd extracts the second element of any singleton tuple-stream *)\nlemma [simp]: \"sprojsnd\\<cdot>(\\<up>(a,b)) = \\<up>b\"\n  by (simp add: sprojsnd_def)\n\nlemma sprojsnd_shd:\n  assumes \"s \\<noteq> \\<epsilon>\"\n  shows \"shd (sprojsnd\\<cdot>s) = snd (shd s)\"\n  by (metis assms prod.collapse shd1 sprojsnd_scons surj_scons)\n\nlemma sconc_sprojsnd_shd: \n  shows \"shd (sprojsnd\\<cdot>(\\<up>a \\<bullet> s)) = snd a\"\n  by (simp add: sprojsnd_shd)\n\ntext \\<open>@{term sprojfst} / @{term sprojsnd} and @{term srt} commute\\<close>\n\n(* commutativity of sprojsnd and srt *)\nlemma rt_Sproj_2_eq: \"sprojsnd\\<cdot>(srt\\<cdot>x) = srt\\<cdot>(sprojsnd\\<cdot>x)\"\nby (rule ind [of _ x], auto)\n\n(* commutativity of sprojsnd and srt *)\nlemma rt_Sproj_1_eq: \"sprojfst\\<cdot>(srt\\<cdot>x) = srt\\<cdot>(sprojfst\\<cdot>x)\"\nby (rule ind [of _ x], auto)\n\ntext \\<open>length of projections and the empty stream\\<close>\n\n(* relation between sprojsnd and sprojfst with respect to the length operator *)\nlemma slen_sprojs_eq: \"#(sprojsnd\\<cdot>x) = #(sprojfst\\<cdot>x)\"\nby (rule ind [of _ \"x\"], auto)\n\n(* if sprojfst\\<cdot>x is the empty stream, then x was already empty *)\nlemma strict_rev_sprojfst: \"sprojfst\\<cdot>x = \\<epsilon> \\<Longrightarrow> x = \\<epsilon>\"\nby (rule ccontr, rule_tac x=x in scases, auto)\n\n(* if sprojsnd\\<cdot>x is the empty stream, then x was already empty *)\nlemma strict_rev_sprojsnd: \"sprojsnd\\<cdot>x = \\<epsilon> \\<Longrightarrow> x = \\<epsilon>\"\nby (rule ccontr, rule_tac x=x in scases, auto)\n\n(* sprojfst does not change the length of x *)\nlemma slen_sprojfst: \"#(sprojfst\\<cdot>x) = #x\"\nby (rule ind [of _ \"x\"], auto)\n\n(* sprojsnd does not change the length of x *)\nlemma slen_sprojsnd: \"#(sprojsnd\\<cdot>x) = #x\"\nby (rule ind [of _ \"x\"], auto)\n\n(* updis does not change the length *)\nlemma slen_updis_eq: \"#s1 = #s2 \\<Longrightarrow> #(updis x1 && s1) = #(updis x2 && s2)\"\n  by (simp add: lscons_conv)\n\n(* helper lemma for deconstruct_infstream *)\nlemma deconstruct_infstream_h:\n  assumes \"#s = \\<infinity>\" obtains x xs where \"(updis x) && xs = s \\<and> #xs = \\<infinity>\"\n  using assms inf_scase lscons_conv by blast\n\n(* deconstruction of infinite streams *)\nlemma deconstruct_infstream:\n  assumes \"#s = \\<infinity>\" obtains x xs where \"(updis x) && xs = s \\<and> #xs = \\<infinity> \\<and> xs \\<noteq> \\<epsilon>\"\n  by (metis Inf'_neq_0 assms deconstruct_infstream_h slen_empty_eq)\n\ntext \\<open>Behaviour of projections on the n-th element in a stream\\<close>\n\nlemma sprojfst_shd[simp]: assumes \"s\\<noteq>\\<epsilon>\" shows \"shd (sprojfst\\<cdot>s) = fst (shd s)\"\n  by (metis assms prod.collapse shd1 sprojfst_scons surj_scons)\n\nlemma sprojfst_snth[simp]: assumes \"Fin n < #s\" shows \"snth n (sprojfst\\<cdot>s) = fst (snth n s)\"\n  using assms\nproof(induction n arbitrary: s)\n  case 0\n  then show ?case\n    apply simp\n    apply(rule sprojfst_shd)\n    by auto\nnext\n  case (Suc n)\n  then show ?case\n    apply(simp add: snth_rt)\n    by (metis not_less rt_Sproj_1_eq slen_rt_ile_eq)\nqed\n\nlemma sprojfst_shd2[simp]: \"shd (sprojfst\\<cdot>(\\<up>a \\<bullet> s)) = fst (a)\"\n  by simp\n\nlemma sprojsnd_snth:\n  assumes \"Fin n < #s\" \n  shows \"snth n (sprojsnd\\<cdot>s) = snd (snth n s)\"\n  using assms\n  apply (induction n arbitrary: s)\n  using sprojsnd_shd apply force\n  by (metis leD leI rt_Sproj_2_eq slen_rt_ile_eq snth_rt)\n\nlemma sprojsnd_shd2[simp]: \"shd (sprojsnd\\<cdot>(\\<up>a \\<bullet> s)) = snd (a)\"\n  by (simp add: sconc_sprojsnd_shd)\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term sfilter}\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>basic properties of @{term sfilter}\\<close>\n\n(* note that M is a set, not a predicate *)\nlemma strict_sfilter[simp]: \"sfilter M\\<cdot>\\<epsilon> = \\<epsilon>\"\nby (subst sfilter_def [THEN fix_eq2], simp)\n\n(* if the head of a stream is in M, then sfilter will keep the head *)\nlemma sfilter_in[simp]: \n  \"a \\<in> M \\<Longrightarrow> sfilter M\\<cdot>(\\<up>a \\<bullet> s) = \\<up>a \\<bullet> sfilter M\\<cdot>s\" \nby (subst sfilter_def [THEN fix_eq2], simp)\n\n(* if the head of a stream isn't in M, then sfilter will discard the head *)\nlemma sfilter_nin[simp]: \n  \"a \\<notin> M \\<Longrightarrow> sfilter M\\<cdot>(\\<up>a \\<bullet> s) = sfilter M\\<cdot>s\" \nby (subst sfilter_def [THEN fix_eq2], simp)\n\n(* if the sole element in a singleton stream is in M then sfilter is a no-op *)\nlemma [simp]: \"a \\<in> M \\<Longrightarrow> sfilter M\\<cdot>(\\<up>a) = \\<up>a\"\nby (subst sfilter_def [THEN fix_eq2], simp)\n\n(* if the sole element in a singleton stream is not in M then sfilter produces the empty stream *)\nlemma [simp]: \"a \\<notin> M \\<Longrightarrow> sfilter M\\<cdot>(\\<up>a) = \\<epsilon>\"\nby (subst sfilter_def [THEN fix_eq2], simp)\n\ntext \\<open>@{term sfilter} and @{term sinftimes}\\<close>\n\n(* filtering all elements that aren't in {a} from a stream consisting only of the element a has no effect *)\nlemma sfilter_sinftimes_in[simp]: \n  \"sfilter {a}\\<cdot>(sinftimes (\\<up>a)) = sinftimes (\\<up>a)\"\napply (rule stream.take_lemma)\napply (induct_tac n, auto)\napply (subst sinftimes_unfold, simp)\napply (rule sym)\nby (subst sinftimes_unfold, simp)\n\n(* if the element a isn't in the set F then filtering a stream of infinitely many a's using F will\n   produce the empty stream *)\nlemma sfilter_sinftimes_nin:\n  \"a \\<notin> F \\<Longrightarrow> (F \\<ominus> (sinftimes (\\<up>a))) = \\<epsilon>\"\nproof -\n  assume a_nin_F: \"a \\<notin> F\"\n  have \"\\<And>i. (F \\<ominus> (stake i\\<cdot>(sinftimes (\\<up>a)))) = \\<epsilon>\"\n  proof (induct_tac i, simp_all)\n    fix n assume \"F \\<ominus> (stake n\\<cdot>(sinftimes (\\<up>a))) = \\<epsilon>\"\n    hence \"F \\<ominus> (stake (Suc n)\\<cdot>(\\<up>a \\<bullet> sinftimes (\\<up>a))) = \\<epsilon>\" using a_nin_F by simp\n    thus \"F \\<ominus> stake (Suc n)\\<cdot>(sinftimes (\\<up>a)) = \\<epsilon>\" by (subst sinftimes_unfold)\n  qed\n  hence \"(F \\<ominus> (\\<Squnion>i. stake i\\<cdot>(sinftimes (\\<up>a)))) = \\<epsilon>\" by (simp add:contlub_cfun_arg)\n  thus ?thesis by (simp add: reach_stream)\nqed\n\ntext \\<open>Filtering a postfix is at most as long as filtering the whole stream\\<close>\nlemma slen_sfilter_sdrop_ile: \n  \"#(sfilter X\\<cdot>(sdrop n\\<cdot>p)) \\<le> #(sfilter X\\<cdot>p)\"\napply (rule spec [where x = \"n\"])\napply (rule ind [of _ p], auto)\napply (subst lnle_def, simp del: lnle_conv)\napply (case_tac \"x\", auto)\napply (case_tac \"a \\<in> X\", auto)\napply (erule_tac x=\"nat\" in allE)\nby (rule trans_lnle, auto)\n\ntext \\<open>If the filtered stream is infinite, each filtered postfix is infinite\\<close>\nlemma slen_sfilter_sdrop: \n  \"\\<forall>p X. #(sfilter X\\<cdot>p) = \\<infinity> \\<longrightarrow> #(sfilter X\\<cdot>(sdrop n\\<cdot>p)) = \\<infinity>\" \napply (induct_tac n, auto)\napply (rule_tac x=p in scases, auto)\nby (case_tac \"a\\<in>X\", auto)\n\ntext \\<open>@{term sfilter} on @{term \"stake n\"} returns \\<open>\\<epsilon>\\<close> if none of the first\n  @{term n} elements is included in the filter\\<close>\nlemma sfilter_empty_snths_nin_lemma: \n  \"\\<forall>p. (\\<forall>n. Fin n < #p \\<longrightarrow> snth n p \\<notin> X) \\<longrightarrow> sfilter X\\<cdot>(stake k\\<cdot>p) = \\<epsilon>\"\napply (induct_tac k, auto)\napply (rule_tac x=p in scases, auto)\napply (case_tac \"a\\<in>X\", auto)\napply (erule_tac x=\"0\" in allE, simp)\napply (case_tac \"n\", auto)\napply (erule_tac x=\"s\" in allE, auto)\nby (erule_tac x=\"Suc n\" in allE, auto)\n\ntext \\<open>@{term sfilter} returns \\<open>\\<epsilon>\\<close> if no element is included in the filter\\<close>\nlemma ex_snth_in_sfilter_nempty:\n  \"(\\<forall>n. Fin n < #p \\<longrightarrow> snth n p \\<notin> X) \\<Longrightarrow> sfilter X\\<cdot>p = \\<epsilon>\"\napply (subgoal_tac \"sfilter X\\<cdot>p = (\\<Squnion>k. sfilter X\\<cdot>(stake k\\<cdot>p))\")\napply (erule ssubst)\napply (subst lub_eq_bottom_iff, simp)\napply (subst sfilter_empty_snths_nin_lemma, simp+)\napply (subst contlub_cfun_arg [THEN sym], simp)\nby (simp add: reach_stream)\n\ntext \\<open>@{term sfilter} returns the original streams if every element is included in the filter\\<close>\nlemma sfilter_snths_in_lemma: \n  \"\\<forall>p. (\\<forall>n. Fin n < #p \\<longrightarrow> snth n p \\<in> X) \\<longrightarrow> sfilter X\\<cdot>(stake k\\<cdot>p) = stake k\\<cdot>p\"\n  apply (induct_tac k, auto)\n  apply (rule_tac x=p in scases, auto)\n  apply (case_tac \"a\\<in>X\", auto)\n   apply (case_tac \"n\", auto)\n   apply (erule_tac x=\"s\" in allE, auto)\n   apply (erule_tac x=\"Suc n\" in allE, auto)\n  by (erule_tac x=\"0\" in allE, simp)\n\nlemma sfilter_snths_in_stream_lemma:assumes a1:\" \\<And> n . Fin n <#p  \\<Longrightarrow> snth n p \\<in> X\" \n  shows  \" p =  sfilter X\\<cdot>(p)\"\n  apply (subst reach_stream [THEN sym], rule sym)\n  apply (subst reach_stream [THEN sym],case_tac \"#p=\\<infinity>\")\n   apply(smt Inf.INF_cong a1 approxl1 assms monofun_cfun_arg sfilter_snths_in_lemma slen_stake_fst_inf stream.take_below)\n  by (metis (no_types, hide_lams) assms infI  fin2stake sfilter_snths_in_lemma)\n\ntext \\<open>The filtered stream is at most as long as the original one\\<close>\nlemma slen_sfilterl1: \"#(sfilter S\\<cdot>x) \\<le> #x\"\napply (rule ind [of _ x], auto)\napply (subst lnle_def, simp del: lnle_conv)\napply (case_tac \"a \\<in> S\", auto)\nby (rule trans_lnle, auto)\n\ntext \\<open>If the filtered stream is infinite, the original one is infinite as well\\<close>\nlemma sfilterl4:\n  \"#(sfilter X\\<cdot>x) = \\<infinity> \\<Longrightarrow> #x = \\<infinity>\"\nby (insert slen_sfilterl1 [of X x], auto)\n\ntext \\<open>Prepending to the original stream never shortens the filtered result\\<close>\nlemma sfilterl2: \n  \"\\<forall>z. #(sfilter X\\<cdot>s) \\<le> #(sfilter X\\<cdot>((stake n\\<cdot>z) \\<bullet> s))\"\napply (induct_tac n, auto)\napply (rule_tac x=z in scases, auto)\napply (case_tac \"a\\<in>X\", auto)\napply (erule_tac x=\"sa\" in allE)\nby (drule trans_lnle, auto) \n\ntext \\<open>The filtered result is not changed by concatenating streams which are\n  filtered to \\<open>\\<epsilon>\\<close>\\<close>\nlemma sfilterl3:\n  \"\\<forall>s. #s = Fin k \\<and> sfilter S\\<cdot>s = \\<epsilon> \\<longrightarrow> \n       sfilter S\\<cdot>(s\\<bullet>Z) = sfilter S\\<cdot>Z\" \napply (induct_tac k, auto)\napply (rule_tac x=s in scases, auto)\nby (case_tac \"a \\<in> S\", auto)\n\ntext \\<open>A stream can be split by @{term stake} and @{term sdrop} for filtering\\<close>\nlemma split_sfilter: \"sfilter X\\<cdot>x = sfilter X\\<cdot>(stake n\\<cdot>x) \\<bullet> sfilter X\\<cdot>(sdrop n\\<cdot>x)\"\napply (rule_tac x=x in spec)\napply (induct_tac n, simp)\napply (rule allI)\napply (rule_tac x=x in scases, simp)\napply (erule_tac x=\"s\" in allE, auto)\nby (case_tac \"a \\<in> X\", auto)\n\ntext \\<open>double filtering\\<close>\nlemma int_sfilterl1[simp]: \"sfilter S\\<cdot>(sfilter M\\<cdot>s) = sfilter (S \\<inter> M)\\<cdot>s\"\napply (rule ind [of _ s], auto)\napply (case_tac \"a \\<in> S \\<inter> M\", auto)\nby (case_tac \"a \\<in> M\", auto)\n\ntext \\<open>Streams can be split for filtering\\<close>\nlemma add_sfilter:\n  \"#x = Fin k \\<Longrightarrow> sfilter t\\<cdot>(x \\<bullet> y) = sfilter t\\<cdot>x \\<bullet> sfilter t\\<cdot>y\"\napply (simp add: atomize_imp)\napply (rule_tac x=\"y\" in spec)\napply (rule_tac x=\"x\" in spec)\napply (induct_tac k, auto)\napply (rule_tac x=\"x\" in scases, auto)\nby (case_tac \"a \\<in> t\", auto)\n\ntext \\<open>After applying @{term \"smap f\"}, all elements are in the range of @{term f}\\<close>\nlemma sfilter_smap_nrange: \n  \"m \\<notin> range f \\<Longrightarrow> sfilter {m}\\<cdot>(smap f\\<cdot>x) = \\<epsilon>\"\napply (rule ex_snth_in_sfilter_nempty [rule_format], simp)\napply (subst smap_snth_lemma, simp+)\napply (rule notI)\napply (drule sym)\nby (drule_tac f=\"f\" in range_eqI, simp)\n\nlemma sfilter_lub_inf: assumes \"\\<And>n. \\<exists>i. Fin n \\<le> #(A \\<ominus> (Y i))\" and \"chain Y\"\n  shows \" #(A \\<ominus> (\\<Squnion>i. Y i)) = \\<infinity>\"\nproof(rule ccontr)\n  assume as: \"#(A \\<ominus> (\\<Squnion>i::nat. Y i)) \\<noteq> \\<infinity>\"\n  obtain n where n_def:\"#(A \\<ominus> (\\<Squnion>i. Y i)) = Fin n\"\n    using as lncases by auto\n  obtain i where i_def:\"Fin (Suc n) \\<le>  #(A \\<ominus> (Y i))\"\n    using assms(1) by blast\n  have \"#(A \\<ominus> (Y i)) \\<le> #(A \\<ominus> (\\<Squnion>i::nat. Y i))\"\n    using assms(2) cont_pref_eq1I is_ub_thelub mono_slen by blast\n  thus False\n    using dual_order.trans i_def n_def by fastforce\nqed\n\nlemma snth_filter: \"Fin n < #s \\<Longrightarrow> snth n s\\<in>A \\<Longrightarrow> sfilter A\\<cdot>s \\<noteq>\\<bottom>\"\n  apply(induction n arbitrary: s)\n  apply auto\n  apply (metis lnsuc_neq_0_rev sfilter_in slen_scons strict_slen surj_scons)\n  apply(simp add: snth_rt)\n  by (metis Fin_02bot Fin_Suc inject_Fin lnzero_def n_not_Suc_n not_le only_empty_has_length_0 sfilter_in sfilter_nin slen_rt_ile_eq slen_scons stream.sel_rews(2) strictI surj_scons)\n\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term stakewhile}\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>basic properties of @{term stakewhile}\\<close>\n\n(* stakewhile f to an empty stream returns the empty stream *)\nlemma strict_stakewhile[simp]: \"stakewhile f\\<cdot>\\<epsilon> = \\<epsilon>\"\nby (subst stakewhile_def [THEN fix_eq2], simp)\n\n(* if the head a passes the predicate f, then the result of stakewhile will start with \\<up>a *)\nlemma stakewhile_t[simp]: \"f a \\<Longrightarrow> stakewhile f\\<cdot>(\\<up>a \\<bullet> s) = \\<up>a \\<bullet> stakewhile f\\<cdot>s\"\nby (subst stakewhile_def [THEN fix_eq2], simp)\n\n(* if the head a fails the predicate f, then stakewhile will produce the empty stream *)\nlemma stakewhile_f[simp]: \"\\<not>f a \\<Longrightarrow> stakewhile f\\<cdot>(\\<up>a \\<bullet> s) = \\<epsilon>\"\nby (subst stakewhile_def [THEN fix_eq2], simp)\n\n(* if the element a passes the predicate f, then stakewhile applied to \\<up>a is a no-op *)\nlemma [simp]: \"f a \\<Longrightarrow> stakewhile f\\<cdot>(\\<up>a) = \\<up>a\"\nby (subst stakewhile_def [THEN fix_eq2], simp)\n\n(* if the element a fails the predicate f, then stakewhile applied to \\<up>a will produce the empty stream *)\nlemma [simp]: \"\\<not>f a \\<Longrightarrow> stakewhile f\\<cdot>(\\<up>a) = \\<epsilon>\"\nby (subst stakewhile_def [THEN fix_eq2], simp)\n\n(* stakewhile can't increase the length of a stream *)\nlemma stakewhile_less [simp]: \"#(stakewhile f\\<cdot>s)\\<le>#s\"\napply(rule ind [of _ s], auto)\napply (metis (mono_tags, lifting) admI inf_chainl4 inf_ub l42)\nby (metis bot_is_0 lnle_def lnsuc_lnle_emb minimal slen_empty_eq slen_scons stakewhile_f stakewhile_t)\n\n(* stakewhile doesn't take elements past an element that fails the predicate f *)\nlemma stakewhile_slen[simp]: \"\\<not>f (snth n s) \\<Longrightarrow> #(stakewhile f\\<cdot>s)\\<le>Fin n\"\napply(induction n arbitrary: s)\napply (metis Fin_02bot lnat_po_eq_conv lnzero_def sdrop_0 slen_empty_eq snth_def stakewhile_f strict_stakewhile surj_scons)\nby (smt inject_scons slen_rt_ile_eq snth_rt stakewhile_f stakewhile_t stream.take_strict strict_stakewhile surj_scons ub_slen_stake)\n\n(* the prefix of the constant stream of x's whose elements aren't equal to x is empty *)\nlemma [simp]: \"stakewhile (\\<lambda>a. a \\<noteq> x)\\<cdot>\\<up>x\\<^sup>\\<infinity> = \\<epsilon>\"\nby (metis (full_types)sinftimes_unfold stakewhile_f)\n\n(* stakewhile produces a prefix of the input *)\nlemma stakewhile_below[simp]: \"stakewhile f\\<cdot>s \\<sqsubseteq> s\"\napply(induction s)\napply(simp+)\nby (smt minimal monofun_cfun_arg stakewhile_f stakewhile_t stream.con_rews(2) stream.sel_rews(5) surj_scons)\n\n(* if stakewhile leaves a stream s unchanged, then every element must pass the predicate f *) \nlemma stakewhile_id_snth: assumes \"stakewhile f\\<cdot>s = s\" and \"Fin n < #s\"\nshows \"f (snth n s)\"\nby (metis Fin_leq_Suc_leq assms(1) assms(2) less2eq less2lnleD lnless_def stakewhile_slen)\n\n(* if stakewhile produces a result of length n or greater, then the nth element in s must pass f *)\nlemma stakewhile_snth[simp]: assumes  \"Fin n < #(stakewhile f\\<cdot>s)\"\nshows \"f (snth n s)\"\nby (meson assms not_less stakewhile_slen)\n\n(* if stakewhile changes the stream s, then there must be an element in s that fails the predicate f *)\nlemma stakewhile_notin [simp]: \n  shows \"stakewhile f\\<cdot>s \\<noteq> s \\<Longrightarrow> #(stakewhile f\\<cdot>s) = Fin n \\<Longrightarrow> \\<not> f (snth n s)\"\n  apply(induction n arbitrary:s)\n   apply (metis Fin_02bot lnat.con_rews slen_scons snth_shd stakewhile_t surj_scons)\n  by (smt Fin_02bot Fin_Suc approxl2 inject_scons lnat.con_rews lnat_po_eq_conv lnsuc_lnle_emb lnzero_def slen_empty_eq slen_rt_ile_eq snth_rt snth_shd stakewhile_below stakewhile_slen stakewhile_t stream.take_strict surj_scons ub_slen_stake)\n\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term stwbl}\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>basic properties for @{term stwbl}\\<close>\n\n(* stwbl f to an empty stream returns the empty stream *) \nlemma strict_stwbl[simp]: \"stwbl f\\<cdot>\\<epsilon> = \\<epsilon>\"\nby (subst stwbl_def [THEN fix_eq2], simp)\n\n(* if the head a passes the predicate f, then the result of stwbl will start with \\<up>a *)\nlemma stwbl_t[simp]: \"f a \\<Longrightarrow> stwbl f\\<cdot>(\\<up>a \\<bullet> s) = \\<up>a \\<bullet> stwbl f\\<cdot>s\"\nby (subst stwbl_def [THEN fix_eq2], simp)\n\n(* if the head a fails the predicate f, then stwbl will produce only \\<up>a *)\nlemma stwbl_f[simp]: \"\\<not> f a \\<Longrightarrow> stwbl f\\<cdot>(\\<up>a \\<bullet> s) = \\<up>a\"\nby (subst stwbl_def [THEN fix_eq2], simp)\n\n(* if s is not empty, then stwbl f also does not return the empty stream *)\nlemma stwbl_notEps: \"s\\<noteq>\\<epsilon> \\<Longrightarrow> (stwbl f\\<cdot>s)\\<noteq>\\<epsilon>\"\nby (smt lnat.con_rews lnzero_def sconc_snd_empty slen_scons strict_slen stwbl_f stwbl_t surj_scons)\n\n(* if stwbl f applied to s returns the empty stream, then s was empty *)\nlemma stwbl_eps: \"stwbl f\\<cdot>s = \\<epsilon> \\<longleftrightarrow> s=\\<epsilon>\"\nusing strict_stwbl stwbl_notEps by blast\n\ntext \\<open>@{term sfilter} after @{term stakewhile}: produce the empty stream\\<close>\nlemma sfilter_twl1[simp]: \n  \"sfilter X\\<cdot>(stakewhile (\\<lambda>x. x\\<notin>X)\\<cdot>p) = \\<epsilon>\"\napply (rule ind [of _ p], auto)\nby (case_tac \"a\\<in>X\", auto)\n\ntext \\<open>@{term sfilter} after @{term stakewhile}: redundant filtering\\<close>\nlemma sfilter_twl2[simp]: \n  \"sfilter X\\<cdot>(stakewhile (\\<lambda>x. x\\<in>X)\\<cdot>p) = stakewhile (\\<lambda>x. x\\<in>X)\\<cdot>p\"\napply (rule ind [of _ p], auto)\nby (case_tac \"a\\<in>X\", auto)\n\ntext \\<open>If @{term \"stakewhile (\\<lambda>p. p = t)\"} returns an infinite stream, all prefixes\n  of the original stream only consist of \"@{term t}\"s\\<close>\nlemma stakewhile_sinftimes_lemma: \n  \"\\<forall>z. #(stakewhile (\\<lambda>p. p = t)\\<cdot>z) = \\<infinity> \\<longrightarrow> stake n\\<cdot>z = stake n\\<cdot>(sinftimes (\\<up>t))\"\napply (induct_tac n, auto)\napply (subst sinftimes_unfold, simp)\napply (rule_tac x=z in scases, auto)\nby (case_tac \"a=t\", auto)\n\ntext \\<open>If @{term \"stakewhile (\\<lambda>p. p = t)\"} returns an infinite stream, the original stream\n  is an infinite \"@{term t}\"-stream\\<close>\nlemma stakewhile_sinftimesup: \n  \"#(stakewhile (\\<lambda>p. p = t)\\<cdot>z) = \\<infinity> \\<Longrightarrow> z = sinftimes (\\<up>t)\"\napply (rule stream.take_lemma)\nby (rule stakewhile_sinftimes_lemma [rule_format])\n\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term sdropwhile}\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>basic properties for @{term sdropwhile}\\<close>\n\n(* sdropwhile f applied to the empty stream returns the empty stream *)\nlemma strict_sdropwhile[simp]: \"sdropwhile f\\<cdot>\\<epsilon> = \\<epsilon>\"\nby (subst sdropwhile_def [THEN fix_eq2], simp)\n\n(* if the head a passes the predicate f, then the result of sdropwhile will drop the head *)\nlemma sdropwhile_t[simp]: \"f a \\<Longrightarrow> sdropwhile f\\<cdot>(\\<up>a \\<bullet> s) = sdropwhile f\\<cdot>s\"\nby (subst sdropwhile_def [THEN fix_eq2], simp)\n\n(* if the head a fails the predicate f, then the result of sdropwhile will start with \\<up>a *)\nlemma sdropwhile_f[simp]: \"\\<not>f a \\<Longrightarrow> sdropwhile f\\<cdot>(\\<up>a \\<bullet> s) = \\<up>a \\<bullet> s\"\nby (subst sdropwhile_def [THEN fix_eq2], simp)\n\n(* if the only element in a singleton stream passes the predicate f, then sdropwhile will produce\n   the empty stream *)\nlemma [simp]: \"f a \\<Longrightarrow> sdropwhile f\\<cdot>(\\<up>a) = \\<epsilon>\"\nby (subst sdropwhile_def [THEN fix_eq2], simp)\n\n(* if the only element in a singleton stream fails the predicate f, then sdropwhile will be a no-op *)\nlemma [simp]: \"\\<not>f a \\<Longrightarrow> sdropwhile f\\<cdot>(\\<up>a) = \\<up>a\"\nby (subst sdropwhile_def [THEN fix_eq2], simp)\n\ntext \\<open>special cases of @{term sfilter} after @{term sdropwhile}\\<close>\n\n(* the elements removed by sdropwhile are a subset of the elements removed by sfilter *)\nlemma sfilter_dwl1[simp]: \n  \"sfilter X\\<cdot>(sdropwhile (\\<lambda>x. x\\<notin>X)\\<cdot>p) = sfilter X\\<cdot>p\"\napply (rule ind [of _ p], auto)\nby (case_tac \"a\\<in>X\", auto)\n\n(* the elements kept by sfilter are a subset of the elements kept by sdropwhile *)\nlemma sfilter_dwl2:\n  \"sfilter T\\<cdot>s \\<noteq> \\<epsilon> \\<Longrightarrow> sdropwhile (\\<lambda>a. a \\<notin> T)\\<cdot>s \\<noteq> \\<epsilon>\"\napply (rule notI)\napply (erule notE)\napply (subst sfilter_dwl1 [THEN sym])\nby simp\n\ntext \\<open>Construct @{term stwbl} from @{term stakewhile}, @{term stake} and @{term sdropwhile}\\<close>\nlemma stwbl_stakewhile: \"stwbl f\\<cdot>s = stakewhile f\\<cdot>s \\<bullet> (stake (Suc 0)\\<cdot>(sdropwhile f\\<cdot>s))\"\napply (rule stream.take_lemma)\napply (rule_tac x=\"s\" in spec)\napply (induct_tac n, simp+)\napply (rule allI)\napply (rule_tac x=\"x\" in scases, simp+)\nby (case_tac \"f a\", simp+)\n\ntext \\<open>Constructing @{term sdropwhile} from @{term stakewhile} and @{term sdrop}\\<close>\nlemma stakewhile_sdropwhilel1:\n  \"\\<forall>x. #(stakewhile f\\<cdot>x) = Fin n \\<longrightarrow> sdropwhile f\\<cdot>x = sdrop n\\<cdot>x\"  \napply (induct_tac n, auto)\napply (rule_tac x=x in scases, auto)\napply (case_tac \"f a\", auto)\napply (rule_tac x=x in scases, auto)\nby (case_tac \"f a\", auto)\n\ntext \\<open>@{term sdropwhile} is idempotent\\<close>\nlemma sdropwhile_idem: \"sdropwhile f\\<cdot>(sdropwhile f\\<cdot>x) = sdropwhile f\\<cdot>x\"\napply (rule ind [of _ x], auto)\nby (case_tac \"f a\", auto)\n\ntext \\<open>@{term stakewhile} after @{term sdropwhile} gives the empty stream\\<close>\nlemma tdw[simp]: \"stakewhile f\\<cdot>(sdropwhile f\\<cdot>s) = \\<epsilon>\"\napply (rule ind [of _ s], auto)\nby (case_tac \"f a\", auto)\n\n(* relation between stakewhile and sdropwhile *)\nlemma stakewhileDropwhile: \"stakewhile f\\<cdot>s \\<bullet> (sdropwhile f\\<cdot>s) = s \"\napply(rule ind [of _s])\napply (rule admI)\napply (metis (no_types, lifting) approxl2 inf_chainl4 lub_eqI lub_finch2 sconc_fst_inf split_streaml1 stakewhile_below stakewhile_sdropwhilel1)\napply simp\nby (metis assoc_sconc sconc_fst_empty sdropwhile_f sdropwhile_t stakewhile_t tdw)\n\ntext \\<open>For the head of @{term \"sdropwhile f\\<cdot>x\"}, @{term f} does not hold\\<close>\nlemma sdropwhile_resup: \"sdropwhile f\\<cdot>x = \\<up>a \\<bullet> s \\<Longrightarrow> \\<not> f a\"\napply (subgoal_tac \"sdropwhile f\\<cdot>(\\<up>a \\<bullet> s) = \\<up>a \\<bullet> s\")\napply (case_tac \"f a\", auto)\napply rotate_tac\napply (drule cfun_arg_cong [of _ _ \"stakewhile f\"], simp)\napply (drule sym, simp)\nby (rule sdropwhile_idem)\n\ntext \\<open>elimination rule for @{term sfilter} after @{term sdropwhile}\\<close>\nlemma sfilter_srtdwl3[simp]: \n  \"sfilter X\\<cdot>(srt\\<cdot>(sdropwhile (\\<lambda>x. x\\<notin>X)\\<cdot>p)) = srt\\<cdot>(sfilter X\\<cdot>p)\"\napply (rule ind [of _ p], auto)\nby (case_tac \"a\\<in>X\", auto)\n\ntext \\<open>Further results concerning @{term sfilter}\\<close>\n\ntext \\<open>After filtering by filter @{term T}, the head of the result is in @{term T}\n  (for non-empty results)\\<close>\nlemma sfilter_ne_resup: \"sfilter T\\<cdot>s \\<noteq> \\<epsilon> \\<Longrightarrow> shd (sfilter T\\<cdot>s) \\<in> T\"\napply (subst sfilter_dwl1 [THEN sym])\napply (rule_tac x=\"sdropwhile (\\<lambda>x. x \\<notin> T)\\<cdot>s\" in scases, auto)\napply (drule sfilter_dwl2, simp)\napply (rule_tac x=\"s\" in scases, auto)\napply (case_tac \"aa \\<in> T\", auto)\napply (drule inject_scons, simp)\nby (drule sdropwhile_resup, simp)\n\ntext \\<open>same result for @{term sconc} syntax\\<close>\nlemma sfilter_resl2:\n  \"sfilter T\\<cdot>s = \\<up>a \\<bullet> as \\<Longrightarrow> a \\<in> T\"\napply (case_tac \"sfilter T\\<cdot>s = \\<epsilon>\", simp)\nby (drule sfilter_ne_resup, simp)\n\ntext \\<open>After filtering with filter @{term T}, each element is in @{term T}\\<close>\nlemma sfilterl7:\n  \"\\<lbrakk>Fin n < #x; sfilter T\\<cdot>s = x\\<rbrakk> \\<Longrightarrow> snth n x \\<in> T\"\napply (simp add: atomize_imp)\napply (rule_tac x=\"s\" in spec)\napply (rule_tac x=\"x\" in spec)\napply (induct_tac n, auto)\napply (rule sfilter_ne_resup)\napply (rule_tac x=\"sfilter T\\<cdot>xa\" in scases, auto)\napply (rule_tac x=\"xa\" in scases, auto)\napply (simp add: Fin_Suc [THEN sym] del: Fin_Suc)\napply (case_tac \"a \\<in> T\", auto)\napply (case_tac \"sfilter T\\<cdot>s = \\<epsilon>\",simp+)\napply (simp add: Fin_Suc [THEN sym] del: Fin_Suc)\napply (rule_tac x=\"sfilter T\\<cdot>s\" in scases, auto)\napply (erule_tac x=\"sa\" in allE,simp+)\napply (frule sfilter_resl2)\napply (drule mp)\nby (rule_tac x=\"srt\\<cdot>(sdropwhile (\\<lambda>x. x\\<notin>T)\\<cdot>s)\" in exI,simp+)\n\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term srtdw}\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>basic properties of @{term srtdw}\\<close>\n\n(* srtdw f applied to the empty stream always returns the empty stream *)\nlemma [simp]: \"srtdw f\\<cdot>\\<epsilon> = \\<epsilon>\"\nby (simp add: srtdw_def)\n\n(* the rest of any singleton stream is the empty stream, regardless of whether the only element in\n   the stream was dropped *)\nlemma [simp]: \"srtdw f\\<cdot>(\\<up>a) = \\<epsilon>\"\napply (simp add: srtdw_def)\nby (case_tac \"f a\", auto)\n\n(* if the head a passes the predicate f, srtdw will drop the head *)\nlemma [simp]: \"f a \\<Longrightarrow> srtdw f\\<cdot>(\\<up>a\\<bullet>as) = srtdw f\\<cdot>as\"\nby (auto simp add: srtdw_def)\n\n(* if the head a fails the predicate f, srtdw will produce the rest of the stream *)\nlemma [simp]: \"\\<not> f a \\<Longrightarrow> srtdw f\\<cdot>(\\<up>a\\<bullet>as) = as\"\nby (simp add: srtdw_def)\n\ntext \\<open>@{term \"sfilter M\"} after @{term \"srtdw (\\<lambda>x. x \\<notin> M)\"} almost behaves\n  like @{term \"sfilter M\"} alone\\<close>\nlemma sfilterl8:\n  \"sfilter M\\<cdot>x \\<noteq> \\<epsilon> \\<Longrightarrow>\n    #(sfilter M\\<cdot>x) = lnsuc\\<cdot>(#(sfilter M\\<cdot>(srtdw (\\<lambda>x. x \\<notin> M)\\<cdot>x)))\"\napply (simp add: atomize_imp)\napply (rule ind [of _ x], simp+)\napply (rule impI)\nby (case_tac \"a \\<in> M\", simp+)\n\ntext \\<open>similar result for infinite streams\\<close>\nlemma sfilter_srtdwl2:\n  \"#(sfilter X\\<cdot>s) = \\<infinity> \\<Longrightarrow> #(sfilter X\\<cdot>(srtdw (\\<lambda>a. a \\<notin> X)\\<cdot>s)) = \\<infinity>\"\napply (case_tac \"sfilter X\\<cdot>s = \\<epsilon>\", auto)\nby (drule sfilterl8, auto)\n\ntext \\<open>streams can be split by @{term stwbl} and @{term srtdw}\\<close>\nlemma stwbl_srtdw: \"stwbl f\\<cdot>s \\<bullet> srtdw f\\<cdot>s = s\"\napply (rule stream.take_lemma)\napply (rule_tac x=\"s\" in spec)\napply (induct_tac n, simp+)\napply (rule allI)\napply (rule_tac x=\"x\" in scases, simp+)\nby (case_tac \"f a\", simp+)\n\n(* the length of srtdw f\\<cdot>x is always smaller than the length of x *)\nlemma slen_srtdw: \"#(srtdw f\\<cdot>x) \\<le> #x\"\napply (rule ind [of _ x])\napply (subst lnle_conv [THEN sym], simp del: lnle_conv, simp)\napply (case_tac \"f a\", simp+)\nby (rule trans_lnle, simp+)\n\n(* stwbl produces a prefix of the input *)\nlemma stwbl_below [simp]: \"stwbl f\\<cdot>s \\<sqsubseteq> s\"\nby (metis (no_types) minimal monofun_cfun_arg sconc_snd_empty stwbl_srtdw)\n\n(* relation between srtdw and stwbl *) \nlemma srtdw_stwbl [simp]: \"srtdw f\\<cdot> (stwbl f\\<cdot>s) = \\<epsilon>\" (is \"?F s\")\nproof(rule ind [of _s ])\n  show \"adm ?F\" by simp\n  show \"?F \\<epsilon>\" by simp\n  fix a\n  fix s\n  assume IH: \"?F s\"\n  thus \"?F (\\<up>a \\<bullet> s)\" \n  proof (cases \"f a\")\n    case True thus ?thesis by (simp add: IH)\n  next\n    case False thus ?thesis by simp\n  qed\nqed\n\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term srcdups}\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>Basic simplification rules for @{term srcdups}\\<close>\n\n(* srcdups applied to the empty stream returns the empty stream *)\nlemma strict_srcdups[simp]: \"srcdups\\<cdot>\\<epsilon> = \\<epsilon>\" \nby (subst srcdups_def [THEN fix_eq2], simp)\n\n(* a singleton stream can't possibly contain duplicates *)\nlemma [simp]: \"srcdups\\<cdot>(\\<up>a) = \\<up>a\"\nby (subst srcdups_def [THEN fix_eq2], simp)\n\n(* if the head a of a stream is followed by a duplicate, only one of the two elements will be kept by srcdups *)\nlemma srcdups_eq[simp]: \"srcdups\\<cdot>(\\<up>a\\<bullet>\\<up>a\\<bullet>s) = srcdups\\<cdot>(\\<up>a\\<bullet>s)\" \napply (subst srcdups_def [THEN fix_eq2], simp)\nby (rule sym, subst srcdups_def [THEN fix_eq2], simp)\n\n(* if the head a of a stream is followed by a distinct element, both elements will be keypt by srcdups *)\nlemma srcdups_neq[simp]: \n  \"a\\<noteq>b \\<Longrightarrow> srcdups\\<cdot>(\\<up>a \\<bullet> \\<up>b \\<bullet> s) = \\<up>a \\<bullet>  srcdups\\<cdot>(\\<up>b \\<bullet> s)\" \n  by (subst srcdups_def [THEN fix_eq2], simp)\n    \nlemma srcdups_slen [simp]: \"#(srcdups\\<cdot>s) \\<le> #s\"\n  apply (rule ind [of _ s])\n  apply (simp_all)\n  apply (metis (mono_tags, lifting) admI inf_chainl4 inf_ub l42)\n  apply (rule_tac x=s in scases, simp_all)\n  apply (case_tac \"a = aa\", simp_all)\n  using less_lnsuc order.trans by blast\n    \n(*Used for ABP-Composition of sender and receiver*)\nlemma srcdups_eq2:\"a=b \\<Longrightarrow> srcdups\\<cdot>(\\<up>a\\<bullet>\\<up>b\\<bullet>s) = srcdups\\<cdot>(\\<up>b\\<bullet>s)\"\n  by simp\n    \nlemma srcdups_ex:\"\\<exists>y. srcdups\\<cdot>(\\<up>a\\<bullet>s) = \\<up>a\\<bullet>y\"\n  by(subst srcdups_def [THEN fix_eq2], auto)\n    \nlemma srcdups_shd[simp]:\"shd (srcdups\\<cdot>(\\<up>a\\<bullet>s)) = a\"\n  by(subst srcdups_def [THEN fix_eq2],auto)\n\nlemma srcdups_srt:\"srt\\<cdot>(srcdups\\<cdot>(\\<up>a\\<bullet>s)) = (srcdups\\<cdot>(sdropwhile (\\<lambda>z. z = a)\\<cdot>s))\"\n  by(subst srcdups_def [THEN fix_eq2], auto)\n    \nlemma srcdups_shd2[simp]:\"s\\<noteq>\\<epsilon> \\<Longrightarrow> shd (srcdups\\<cdot>s) = shd s\"\n  by(subst srcdups_def [THEN fix_eq2],auto)\n\nlemma srcdups_srt2:\"s\\<noteq>\\<epsilon> \\<Longrightarrow> srt\\<cdot>(srcdups\\<cdot>s) = (srcdups\\<cdot>(sdropwhile (\\<lambda>z. z = shd s)\\<cdot>(srt\\<cdot>s)))\"\n  by(subst srcdups_def [THEN fix_eq2],auto)\n\nlemma srcdups_imposs_h:\"Fin 1 < #(srcdups\\<cdot>s) \\<Longrightarrow> shd(srcdups\\<cdot>s)\\<noteq>shd(srt\\<cdot>(srcdups\\<cdot>s))\"\n  apply (cases \"s=\\<epsilon>\")\n  using empty_is_shortest apply fastforce\n  apply (subst srcdups_srt2,auto)\n  apply (subgoal_tac \"srcdups\\<cdot>(sdropwhile (\\<lambda>z. z = shd s)\\<cdot>(srt\\<cdot>s))\\<noteq>\\<epsilon>\")\n  apply (metis (mono_tags, lifting) sdropwhile_resup srcdups_shd2 strict_srcdups surj_scons)\nproof -\n  assume a1: \"s \\<noteq> \\<epsilon>\"\n  assume a2: \"Fin 1 < #(srcdups\\<cdot>s)\"\n  have f1:\"Fin 0 = 0\"\n    using Fin_02bot bot_is_0 by presburger\n  then have \"lnsuc\\<cdot>0 = Fin (Suc 0)\"\n    by (metis Fin_Suc)\n  then show \"srcdups\\<cdot> (sdropwhile (\\<lambda>a. a = shd s)\\<cdot>(srt\\<cdot>s)) \\<noteq> \\<epsilon>\"\n    using a2 a1 f1\n    by (metis Suc_leI less2nat not_le not_one_le_zero srcdups_srt2 srt_decrements_length strict_slen zero_le_one)\nqed\n\nlemma srcdups_imposs:\"srcdups\\<cdot>(\\<up>a \\<bullet> s) \\<noteq> \\<up>a \\<bullet> \\<up>a \\<bullet> y\"\n  apply(cases \"#(srcdups\\<cdot>(\\<up>a \\<bullet>s)) < Fin 1 \")  \n  apply (metis One_nat_def bot_is_0 lnat.con_rews neq02Suclnle not_less slen_scons)\n  apply(insert srcdups_imposs_h[of \"\\<up>a\\<bullet> s\"])\n  by (metis Fin_02bot Fin_Suc One_nat_def lnat.con_rews lnat.sel_rews(2) lscons_conv neq_iff shd1 \n      slen_scons stream.sel_rews(5) up_defined)  \n  \nlemma srcdupsimposs: \"srcdups\\<cdot>(\\<up>a \\<bullet> s) \\<noteq> \\<up>a \\<bullet> \\<up>a \\<bullet> srcdups\\<cdot>s\"\n  by (simp add: srcdups_imposs)\n   \nlemma srcdupsimposs2_h2:\"\\<forall>x. srcdups\\<cdot>(\\<up>a \\<bullet> s)\\<noteq> \\<up>a \\<bullet> \\<up>a \\<bullet> x\"\n  by (simp add: srcdups_imposs)\n \nlemma srcdupsimposs2: \"srcdups\\<cdot>(\\<up>a \\<bullet> s) \\<noteq> \\<up>a \\<bullet> \\<up>a \\<bullet> s\"\n  by(simp add: srcdups_imposs) \n    \nlemma srcdups_anotb_h:\"srcdups\\<cdot>(\\<up>a\\<bullet>\\<up>b) = \\<up>a \\<bullet> \\<up>b \\<Longrightarrow> a \\<noteq> b\"\n  by (metis sconc_snd_empty srcdups_imposs)\n  \nlemma srcdups_anotb:\"srcdups\\<cdot>(\\<up>a \\<bullet> \\<up>b \\<bullet> s) = \\<up>a \\<bullet> \\<up>b \\<bullet> s \\<Longrightarrow> a\\<noteq> b\"\n  using srcdupsimposs2_h2 by auto\n\nlemma srcdups2srcdups: \"srcdups\\<cdot>(srcdups\\<cdot>s) = srcdups\\<cdot>s\"\nproof(induction rule: ind [of _ s])\n  case 1\n  then show ?case \n    by simp\nnext\n  case 2\n  then show ?case \n    by simp\nnext\n  case (3 a s)\n  have f1:\"a = shd s \\<Longrightarrow> s\\<noteq>\\<epsilon>\\<Longrightarrow> srcdups\\<cdot>(\\<up>a \\<bullet> s) = srcdups\\<cdot>s\"\n    using srcdups_eq[of \"shd s\" \"srt\\<cdot>s\"] surj_scons[of s] by auto\n  have f2:\"a=shd s \\<Longrightarrow> s\\<noteq>\\<epsilon> \\<Longrightarrow> srcdups\\<cdot>(srcdups\\<cdot>(\\<up>a \\<bullet> s)) = srcdups\\<cdot>(\\<up>a \\<bullet> s)\"\n    using f1 \"3.IH\" by auto\n  moreover have\"a\\<noteq>shd s \\<Longrightarrow> srcdups\\<cdot>(\\<up>a \\<bullet> s) = \\<up>a\\<bullet>srcdups\\<cdot>s\"\n    by (metis srcdups_neq srcdups_shd srcdups_srt strict_sdropwhile surj_scons)\n  ultimately have f3:\"a\\<noteq> shd s \\<Longrightarrow>srcdups\\<cdot>(srcdups\\<cdot>(\\<up>a \\<bullet> s)) = srcdups\\<cdot>(\\<up>a \\<bullet> s)\"\n  proof -\n    assume a1: \"a \\<noteq> shd s\"\n    then have f2: \"srcdups\\<cdot>(\\<up>a \\<bullet> s) = \\<up>a \\<bullet> srcdups\\<cdot>s\"\n      by (metis \\<open>a \\<noteq> shd s \\<Longrightarrow> srcdups\\<cdot>(\\<up>a \\<bullet> s) = \\<up>a \\<bullet> srcdups\\<cdot>s\\<close>)\n    obtain ss :: \"'a stream \\<Rightarrow> 'a \\<Rightarrow> 'a stream\" where\n      f3: \"\\<forall>a s. srcdups\\<cdot>(\\<up>a \\<bullet> s) = \\<up>a \\<bullet> ss s a\"\n      by (meson srcdups_ex)\n    then have f4: \"\\<up>(shd s) \\<bullet> srt\\<cdot>s = s \\<longrightarrow> srcdups\\<cdot>(\\<up>a \\<bullet> s) = \\<up>a \\<bullet> \\<up>(shd s) \\<bullet> ss (srt\\<cdot>s) (shd s)\"\n      using f2 by metis\n    have f5: \"\\<up>(shd s) \\<bullet> srt\\<cdot>s = s \\<longrightarrow> srcdups\\<cdot>(\\<up>(shd s) \\<bullet> ss (srt\\<cdot>s) (shd s)) = srcdups\\<cdot>s\"\n      using f3 by (metis \"3.IH\")\n    { assume \"\\<up>a \\<bullet> s \\<noteq> srcdups\\<cdot>(\\<up>a \\<bullet> s)\"\n      then have \"s \\<noteq> \\<epsilon>\"\n        by force\n      then have ?thesis\n        using f5 f4 f2 a1 by (simp add: surj_scons) }\n    then show ?thesis\n      by fastforce\n  qed\n  then show ?case\n    using f2 by fastforce\nqed\n  \nlemma srcdups_prefix_neq:\"x \\<sqsubseteq> y \\<Longrightarrow> srcdups\\<cdot>x \\<noteq>x \\<Longrightarrow> srcdups\\<cdot>y \\<noteq> y\"\nproof(induction arbitrary: y rule: ind [of _ x])\n    case 1\n    then show ?case \n      by simp\n  next\n    case 2\n    then show ?case\n      by simp\n  next\n    case (3 a s)\n    have f1:\"a=shd s \\<Longrightarrow> srcdups\\<cdot>(\\<up>a \\<bullet> s) = srcdups\\<cdot>s\"\n      by (metis \"3.prems\"(2) srcdups_eq2 srcdups_shd srcdups_srt strict_sdropwhile strict_srcdups surj_scons)\n    have f2:\"a\\<noteq>shd s \\<Longrightarrow> srcdups\\<cdot>(\\<up>a \\<bullet> s) = \\<up>a \\<bullet> srcdups\\<cdot>s\"\n      by (metis srcdups_neq srcdups_shd srcdups_srt strict_sdropwhile surj_scons)\n    then have f3:\"a\\<noteq>shd s\\<Longrightarrow> srcdups\\<cdot>s \\<noteq> s\"\n      using \"3.prems\" by auto\n    show ?case\n      by (smt \"3.IH\" \"3.prems\"(1) f1 f2 f3 less_fst_sconsD lscons_conv scases srcdups2srcdups \n         srcdups_eq srcdups_ex srcdups_srt srcdupsimposs2 stream.con_rews(2) stream.sel_rews(5) \n         sup'_def surj_scons)\nqed\n\nlemma srcdups_smap_adm [simp]: \n  \"adm (\\<lambda>a. srcdups\\<cdot>(smap f\\<cdot>(srcdups\\<cdot>a)) = smap f\\<cdot>(srcdups\\<cdot>a) \n    \\<longrightarrow> srcdups\\<cdot>(smap f\\<cdot>a) = smap f\\<cdot>(srcdups\\<cdot>a))\"\n  apply (rule adm_imp, auto)\n  apply(rule adm_upward)\n  apply rule+\n  using srcdups_prefix_neq\n  by (metis monofun_cfun_arg)\n    \nlemma srcdups_smap_com_h:\"s\\<noteq>\\<epsilon> \\<Longrightarrow> a \\<noteq> shd s \\<Longrightarrow> srcdups\\<cdot>(smap f\\<cdot>(srcdups\\<cdot>(\\<up>a \\<bullet> s))) = smap f\\<cdot>(srcdups\\<cdot>(\\<up>a \\<bullet> s)) \\<Longrightarrow>f (shd s) \\<noteq> f a\"\n  apply(cases \"shd(srt\\<cdot>s) \\<noteq> shd s\")\n  apply (insert srcdups_neq[of a \"shd s\" \"srt\\<cdot>s\"] surj_scons[of s], simp)\n  apply (metis smap_scons srcdups_ex srcdupsimposs2_h2)\n  apply (insert srcdups_neq[of a \"shd s\" \"srt\\<cdot>s\"] surj_scons[of s], simp)\n  apply(insert srcdups_ex[of \"shd s\" \"srt\\<cdot>s\"],auto)\n  by (simp add: srcdupsimposs2_h2)\n\nlemma srcdups_smap_com:\n  shows \"srcdups\\<cdot>(smap f\\<cdot>(srcdups\\<cdot>s)) = smap f\\<cdot>(srcdups\\<cdot>s) \\<Longrightarrow> srcdups\\<cdot>(smap f\\<cdot>s)= smap f\\<cdot>(srcdups\\<cdot>s)\"\n  proof(induction rule: ind [of _ s])\n    case 1\n    then show ?case \n      by simp\n  next\n    case 2\n    then show ?case \n      by simp\n  next\n    case (3 a s)\n    have s_eps: \"s = \\<bottom> \\<Longrightarrow>  srcdups\\<cdot>(\\<up>(f a) \\<bullet> smap f\\<cdot>s) = smap f\\<cdot>(srcdups\\<cdot>(\\<up>a \\<bullet> s))\" by simp\n    hence f1: \"shd s = a \\<Longrightarrow> ?case\"  \n      by (metis \"3.IH\" \"3.prems\" smap_scons srcdups_eq surj_scons)\n    have h1: \"s\\<noteq>\\<bottom> \\<Longrightarrow> s = (\\<up>(shd s) \\<bullet> srt\\<cdot>s)\" by (simp add: surj_scons)\n    have h2: \"s\\<noteq>\\<bottom> \\<Longrightarrow> shd s\\<noteq>a \\<Longrightarrow>f (shd s) \\<noteq> f a \\<Longrightarrow> srcdups\\<cdot>(smap f\\<cdot>(\\<up>a \\<bullet> (\\<up>(shd s) \\<bullet> srt\\<cdot>s))) = smap f\\<cdot>(srcdups\\<cdot>(\\<up>a \\<bullet>  (\\<up>(shd s) \\<bullet> srt\\<cdot>s)))\"\n    proof -\n      assume a1: \"f (shd s) \\<noteq> f a\"\n      assume a2: \"s \\<noteq> \\<epsilon>\"\n      assume a3: \"shd s \\<noteq> a\"\n      have f4: \"s = \\<up>(shd s) \\<bullet> srt\\<cdot>s\"\n        using a2 by (metis h1)\n      obtain ss :: \"'b stream \\<Rightarrow> 'b \\<Rightarrow> 'b stream\" where\n        f5: \"\\<forall>b s. srcdups\\<cdot>(\\<up>b \\<bullet> s) = \\<up>b \\<bullet> ss s b\"\n        by (meson srcdups_ex)\n      then have f6: \"\\<up>(shd s) \\<bullet> ss (srt\\<cdot>s) (shd s) = srcdups\\<cdot>s\"\n        using f4 by metis\n      have f7: \"srcdups\\<cdot> (\\<up>(f a) \\<bullet> \\<up>(f (shd s)) \\<bullet> smap f\\<cdot> (ss (srt\\<cdot>s) (shd s))) = \\<up>(f a) \\<bullet> srcdups\\<cdot> (\\<up>(f (shd s)) \\<bullet> smap f\\<cdot> (ss (srt\\<cdot>s) (shd s)))\"\n        using a1 by auto\n      have f8: \"\\<up>a \\<bullet> \\<up>(shd s) \\<bullet> ss (srt\\<cdot>s) (shd s) = srcdups\\<cdot>(\\<up>a \\<bullet> \\<up>(shd s) \\<bullet> srt\\<cdot>s)\"\n        using f5 a3 by (metis (no_types) srcdups_neq)\n      then have f9: \"\\<up>(f a) \\<bullet> \\<up>(f (shd s)) \\<bullet> smap f\\<cdot> (ss (srt\\<cdot>s) (shd s)) = smap f\\<cdot>(srcdups\\<cdot>(\\<up>a \\<bullet> s))\"\n        using f4 by (metis (no_types) smap_scons)\n      then obtain ssa :: \"'a stream \\<Rightarrow> 'a \\<Rightarrow> 'a stream\" where\n        f10: \"\\<up>(f a) \\<bullet> ssa (\\<up>(f (shd s)) \\<bullet> ssa (smap f\\<cdot>(ss (srt\\<cdot>s) (shd s))) (f (shd s))) (f a) = srcdups\\<cdot>(smap f\\<cdot>(srcdups\\<cdot>(\\<up>a \\<bullet> s)))\"\n        by (simp add: \"3.prems\")\n      then have f11: \"\\<up>(f a) \\<bullet> ssa (\\<up>(f (shd s)) \\<bullet> ssa (smap f\\<cdot>(ss (srt\\<cdot>s) (shd s))) (f (shd s))) (f a) = srcdups\\<cdot> (\\<up>(f a) \\<bullet> \\<up>(f (shd s)) \\<bullet> smap f\\<cdot> (ss (srt\\<cdot>s) (shd s)))\"\n        using f9 by presburger\n      have \"\\<up>(f a) \\<bullet> ssa (\\<up>(f (shd s)) \\<bullet> ssa (smap f\\<cdot>(ss (srt\\<cdot>s) (shd s))) (f (shd s))) (f a) = \\<up>(f a) \\<bullet> smap f\\<cdot>(srcdups\\<cdot>s)\"\n        using f10 f8 f6 f4 by (metis (no_types) \"3.prems\" smap_scons)\n      then have \"srcdups\\<cdot>(smap f\\<cdot>s) = smap f\\<cdot>(srcdups\\<cdot>s)\"\n        using f11 f7 f6 by (metis (no_types) \"3.IH\" inject_scons smap_scons)\n      then have \"srcdups\\<cdot> (smap f\\<cdot>(\\<up>a \\<bullet> \\<up>(shd s) \\<bullet> srt\\<cdot>s)) = smap f\\<cdot> (\\<up>a \\<bullet> \\<up>(shd s) \\<bullet> ss (srt\\<cdot>s) (shd s))\"\n        using f6 f4 a1 by (metis (no_types) smap_scons srcdups_neq)\n      then show ?thesis\n        using f8 by presburger\n    qed\n    have f2: \"s\\<noteq>\\<bottom> \\<Longrightarrow> shd s\\<noteq>a \\<Longrightarrow>f (shd s) \\<noteq> f a \\<Longrightarrow> ?case\"\n      using h1 h2 by auto\n    have f3: \"s\\<noteq>\\<bottom> \\<Longrightarrow> shd s\\<noteq>a \\<Longrightarrow>f (shd s) = f a \\<Longrightarrow> ?case\"\n      by (simp add: \"3.prems\" srcdups_smap_com_h)\n    then show ?case using f1 f2 by fastforce\n  qed\n\nlemma srcdups_nbot: \"s\\<noteq>\\<bottom>\\<Longrightarrow>srcdups\\<cdot>s \\<noteq> \\<bottom>\"\n  by (metis lscons_conv srcdups_ex stream.con_rews(2) surj_scons)\n  \nlemma srcdups_fin: assumes \"#(srcdups\\<cdot>s)<\\<infinity>\" and \"#s=\\<infinity>\"\n  obtains x where \"srcdups\\<cdot>x = srcdups\\<cdot>s\" and \"x\\<sqsubseteq>s\" and \"#x < \\<infinity>\"\nproof -\n  obtain n where \"srcdups\\<cdot>(stake n\\<cdot>s) = srcdups\\<cdot>s\"\n    by (metis assms(1) fun_approxl2 min.strict_order_iff ninf2Fin)\n  thus ?thesis\n    using lnless_def that by auto \nqed\n\nlemma srcdups_step: \"srcdups\\<cdot>(\\<up>a \\<bullet> s) = \\<up>a \\<bullet> srcdups\\<cdot>(sdropwhile (\\<lambda>x. x=a)\\<cdot>s)\"\n  apply(rule ind [of _ s], simp_all)\n  by (metis lscons_conv srcdups_ex srcdups_srt stream.sel_rews(5) up_defined) \n\nlemma snprefix: \"\\<not>x\\<sqsubseteq>y \\<Longrightarrow> lshd\\<cdot>x=lshd\\<cdot>y \\<Longrightarrow> \\<not>(srt\\<cdot>x)\\<sqsubseteq>(srt\\<cdot>y)\"\n  apply auto\n  by (metis lshd_updis monofun_cfun_arg stream.sel_rews(2) stream.sel_rews(3) sup'_def surj_scons)\n\nlemma srcdups_consec_noteq: \"Fin (Suc n) < #(srcdups\\<cdot>xs) \\<Longrightarrow> snth n (srcdups\\<cdot>xs) \\<noteq> snth (Suc n) (srcdups\\<cdot>xs)\"\nproof\n  fix n :: nat\n  assume \"Fin (Suc n) < #(srcdups\\<cdot>xs)\" and \"snth n (srcdups\\<cdot>xs) = snth (Suc n) (srcdups\\<cdot>xs)\"\n  then obtain a s where \"sdrop n\\<cdot>(srcdups\\<cdot>xs) = \\<up>a \\<bullet> \\<up>a \\<bullet> s\"\n    by (metis convert_inductive_asm drop_not_all sdrop_back_rt snth_def surj_scons)\n  then have p: \"srcdups\\<cdot>(sdrop n\\<cdot>(srcdups\\<cdot>xs)) \\<noteq> sdrop n\\<cdot>(srcdups\\<cdot>xs)\"\n    by (simp add: srcdupsimposs2_h2)\n  have not_p: \"srcdups\\<cdot>(sdrop n\\<cdot>(srcdups\\<cdot>xs)) = sdrop n\\<cdot>(srcdups\\<cdot>xs)\"\n  proof -\n    have \"srcdups\\<cdot>(sdrop n\\<cdot>(srcdups\\<cdot>xs)) = sdrop n\\<cdot>(srcdups\\<cdot>(srcdups\\<cdot>xs))\"\n    proof (induction n)\n      case 0\n      then show ?case\n        by simp\n    next\n      case (Suc n)\n      then show ?case\n        by (metis sdrop_back_rt srcdups2srcdups srcdups_srt2 stream.sel_rews(2))\n    qed\n    thus \"srcdups\\<cdot>(sdrop n\\<cdot>(srcdups\\<cdot>xs)) = sdrop n\\<cdot>(srcdups\\<cdot>xs)\"\n      by (simp add: srcdups2srcdups)\n  qed\n  thus \"False\"\n    using p by auto\nqed\n\nlemma bool_stream_snth:\n  fixes s t :: \"bool stream\" and n :: nat and a :: bool\n  shows \"s = \\<up>a \\<bullet> t \\<longrightarrow> Fin n < #(srcdups\\<cdot>s) \\<longrightarrow> snth n (srcdups\\<cdot>s) = (even n = a)\"\nproof (induction n)\n  case 0\n  then show ?case\n    by simp\nnext\n  case (Suc n)\n  then show ?case\n    using convert_inductive_asm even_Suc srcdups_consec_noteq by blast\nqed\n\nlemma srcdups_snth_stake_fin: \"\\<And>s n. #s = Fin k \\<Longrightarrow> k > (Suc n) \\<Longrightarrow> snth n s \\<noteq> snth (Suc n) s \\<Longrightarrow> srcdups\\<cdot>(stake (Suc n)\\<cdot>s) \\<noteq> srcdups\\<cdot>s\"\nproof (induction k rule: less_induct)\n  case (less k)\n  then show ?case\n  proof (cases \"k \\<le> Suc 0\")\n    case True\n    then show ?thesis\n      using less.prems(2) by linarith\n  next\n    case False\n    then obtain a b t where \"s = \\<up>a \\<bullet> \\<up>b \\<bullet> t\"\n      by (metis drop_not_all leI le_SucI less.prems(1) less2nat_lemma sdrop_0 sdrop_back_rt surj_scons)\n    obtain l where \"k = Suc l\"\n      using Suc_less_eq2 less.prems(2) by blast\n    then have \"l < k\"\n      by simp\n    moreover have \"#(\\<up>b \\<bullet> t) = Fin l\"\n      using \\<open>k = Suc l\\<close> \\<open>s = \\<up>a \\<bullet> \\<up>b \\<bullet> t\\<close> less.prems(1) by auto\n    then show ?thesis\n    proof (cases n)\n      case 0\n      then have \"srcdups\\<cdot>(stake (Suc n)\\<cdot>s) = \\<up>a\"\n        by (simp add: \\<open>s = \\<up>a \\<bullet> \\<up>b \\<bullet> t\\<close>)\n      moreover have \"srcdups\\<cdot>s \\<noteq> \\<up>a\"\n      proof -\n        have \"snth 0 s \\<noteq> snth (Suc 0) s\"\n          using \"0\" less.prems(3) by blast\n        then have \"a \\<noteq> b\"\n          by (simp add: \\<open>s = \\<up>a \\<bullet> \\<up>b \\<bullet> t\\<close>)\n        then have \"srcdups\\<cdot>s = \\<up>a \\<bullet> srcdups\\<cdot>(\\<up>b \\<bullet> t)\"\n          using \\<open>s = \\<up>a \\<bullet> \\<up>b \\<bullet> t\\<close> srcdups_neq by blast\n        then show ?thesis\n          using srcdups_nbot by force\n      qed\n      ultimately show ?thesis\n        by auto\n    next\n      case (Suc m)\n      have \"Suc m < l\"\n        using Suc \\<open>k = Suc l\\<close> less.prems(2) by blast\n      moreover have \"snth m (\\<up>b \\<bullet> t) \\<noteq> snth (Suc m) (\\<up>b \\<bullet> t)\"\n      proof -\n        have \"\\<up>b \\<bullet> t = srt\\<cdot>s\"\n          by (simp add: \\<open>s = \\<up>a \\<bullet> \\<up>b \\<bullet> t\\<close>)\n        then show ?thesis\n          by (metis (no_types) Suc less.prems(3) sdrop_forw_rt snth_def)\n      qed\n      ultimately have \"srcdups\\<cdot>(stake (Suc m)\\<cdot>(\\<up>b \\<bullet> t)) \\<noteq> srcdups\\<cdot>(\\<up>b \\<bullet> t)\"\n        using \\<open>#(\\<up>b \\<bullet> t) = Fin l\\<close> \\<open>l < k\\<close> less.IH by blast\n      then have \"srcdups\\<cdot>(\\<up>b \\<bullet> (stake m\\<cdot>t)) \\<noteq> srcdups\\<cdot>(\\<up>b \\<bullet> t)\"\n        by simp\n      then have \"srcdups\\<cdot>s \\<noteq> \\<up>a \\<bullet> (srcdups\\<cdot>(\\<up>b \\<bullet> (stake m\\<cdot>t)))\"\n        by (metis (no_types, lifting) \\<open>s = \\<up>a \\<bullet> \\<up>b \\<bullet> t\\<close> inject_scons srcdups2srcdups srcdups_eq srcdups_neq srcdups_step)\n      then show ?thesis\n      proof -\n        { assume \"a \\<noteq> b\"\n          then have \"srcdups\\<cdot>(\\<up>a \\<bullet> \\<up>b \\<bullet> stake m\\<cdot>t) \\<noteq> srcdups\\<cdot>s\"\n            using \\<open>srcdups\\<cdot>s \\<noteq> \\<up>a \\<bullet> srcdups\\<cdot>(\\<up>b \\<bullet> stake m\\<cdot>t)\\<close> by auto\n          then have ?thesis\n            using Suc \\<open>s = \\<up>a \\<bullet> \\<up>b \\<bullet> t\\<close> by force }\n        then show ?thesis\n          using Suc \\<open>s = \\<up>a \\<bullet> \\<up>b \\<bullet> t\\<close> \\<open>srcdups\\<cdot>(\\<up>b \\<bullet> stake m\\<cdot>t) \\<noteq> srcdups\\<cdot>(\\<up>b \\<bullet> t)\\<close> by fastforce\n      qed\n    qed\n  qed\nqed\n\nlemma srcdups_end_neq: \"#s < \\<infinity> \\<Longrightarrow> a \\<noteq> b \\<Longrightarrow> srcdups\\<cdot>(s \\<bullet> \\<up>a \\<bullet> \\<up>b) = srcdups\\<cdot>(s \\<bullet> \\<up>a) \\<bullet> \\<up>b\"\nproof (rule finind3 [of s], simp+)\n  assume \"#s < \\<infinity>\" and \"a \\<noteq> b\"\n  then show \"srcdups\\<cdot>(\\<up>a \\<bullet> \\<up>b) = \\<up>a \\<bullet> \\<up>b\"\n    by (metis lscons_conv srcdups_neq srcdups_step strict_sdropwhile strict_srcdups sup'_def)\nnext\n  fix t :: \"'a stream\" and c :: 'a\n  assume \"#t < \\<infinity>\" and \"srcdups\\<cdot>(t \\<bullet> \\<up>a \\<bullet> \\<up>b) = srcdups\\<cdot>(t \\<bullet> \\<up>a) \\<bullet> \\<up>b\"\n  then have \"srcdups\\<cdot>(\\<up>c \\<bullet> (t \\<bullet> \\<up>a)) \\<bullet> \\<up>b = srcdups\\<cdot>(\\<up>c \\<bullet> (t \\<bullet> \\<up>a \\<bullet> \\<up>b))\"\n  proof (cases \"t = \\<epsilon>\")\n    case True\n    then show ?thesis\n      by (metis (no_types, lifting) \\<open>srcdups\\<cdot>(t \\<bullet> \\<up>a \\<bullet> \\<up>b) = srcdups\\<cdot>(t \\<bullet> \\<up>a) \\<bullet> \\<up>b\\<close> assoc_sconc inject_scons sconc_snd_empty srcdups_eq srcdups_neq)\n  next\n    case False\n    then have not_empty: \"t \\<noteq> \\<epsilon>\"\n      by simp\n    then show ?thesis\n    proof (cases \"c = shd t\")\n      case True\n      then show ?thesis\n        by (metis False \\<open>srcdups\\<cdot>(t \\<bullet> \\<up>a \\<bullet> \\<up>b) = srcdups\\<cdot>(t \\<bullet> \\<up>a) \\<bullet> \\<up>b\\<close> sconc_scons srcdups_eq surj_scons)\n    next\n      case False\n      then have \"srcdups\\<cdot>(\\<up>c \\<bullet> (t \\<bullet> \\<up>a \\<bullet> \\<up>b)) = \\<up>c \\<bullet> srcdups\\<cdot>(t \\<bullet> \\<up>a \\<bullet> \\<up>b)\"\n      proof -\n        have \"\\<up>(shd t) \\<bullet> srt\\<cdot>t = t\"\n          using not_empty surj_scons by blast\n        then show ?thesis\n          by (metis (no_types) False assoc_sconc srcdups_neq)\n      qed\n      then show ?thesis\n      proof -\n        have \"\\<up>(shd t) \\<bullet> srt\\<cdot>t = t\"\n          by (meson not_empty surj_scons)\n        then show ?thesis\n          by (metis (no_types) False \\<open>srcdups\\<cdot>(t \\<bullet> \\<up>a \\<bullet> \\<up>b) = srcdups\\<cdot>(t \\<bullet> \\<up>a) \\<bullet> \\<up>b\\<close> assoc_sconc srcdups_neq)\n      qed\n    qed\n  qed\n  thus \"srcdups\\<cdot>((\\<up>c \\<bullet> t) \\<bullet> \\<up>a \\<bullet> \\<up>b) = srcdups\\<cdot>((\\<up>c \\<bullet> t) \\<bullet> \\<up>a) \\<bullet> \\<up>b\"\n    by simp\nqed\n\nlemma srcdups_end_eq: \"srcdups\\<cdot>(s \\<bullet> \\<up>a \\<bullet> \\<up>a) = srcdups\\<cdot>(s \\<bullet> \\<up>a)\"\nproof (cases \"#s < \\<infinity>\")\n  case True\n  then show ?thesis\n  proof (rule finind3, simp)\n    show \"srcdups\\<cdot>(\\<up>a \\<bullet> \\<up>a) = \\<up>a\"\n      by (simp add: srcdups_step)\n  next\n    fix t :: \"'a stream\" and b :: 'a\n    assume \"#t < \\<infinity>\" and \"srcdups\\<cdot>(t \\<bullet> \\<up>a \\<bullet> \\<up>a) = srcdups\\<cdot>(t \\<bullet> \\<up>a)\"\n    then show \"srcdups\\<cdot>((\\<up>b \\<bullet> t) \\<bullet> \\<up>a \\<bullet> \\<up>a) = srcdups\\<cdot>((\\<up>b \\<bullet> t) \\<bullet> \\<up>a)\"\n    proof (cases \"t = \\<epsilon>\")\n      case True\n      then show ?thesis\n        by (metis sconc_snd_empty srcdups_eq srcdups_neq)\n    next\n      case False\n      then have 1: \"t \\<noteq> \\<epsilon>\"\n        by simp\n      then show ?thesis\n      proof(cases \"shd t = b\")\n        case True\n        then show ?thesis\n          by (metis False \\<open>srcdups\\<cdot>(t \\<bullet> \\<up>a \\<bullet> \\<up>a) = srcdups\\<cdot>(t \\<bullet> \\<up>a)\\<close> assoc_sconc srcdups_eq surj_scons)\n      next\n        case False\n        have \"t \\<noteq> \\<epsilon>\"\n          by (simp add: \"1\")\n        then have \"srcdups\\<cdot>(\\<up>b \\<bullet> t \\<bullet> \\<up>a \\<bullet> \\<up>a) = \\<up>b \\<bullet> srcdups\\<cdot>(t \\<bullet> \\<up>a \\<bullet> \\<up>a)\"\n          by (metis (no_types, lifting) False assoc_sconc srcdups_neq surj_scons)\n        then show ?thesis\n          by (metis (no_types, lifting) \"1\" False \\<open>srcdups\\<cdot>(t \\<bullet> \\<up>a \\<bullet> \\<up>a) = srcdups\\<cdot>(t \\<bullet> \\<up>a)\\<close> sconc_scons srcdups_neq surj_scons)\n      qed\n    qed\n  qed\nnext\n  case False\n  then show ?thesis\n    by (simp add: less_le)\nqed\n\nlemma srcdups_sntimes: \"n > 0 \\<Longrightarrow> srcdups\\<cdot>(sntimes n (\\<up>a)) = \\<up>a\"\nproof (induction n)\n  case 0\n  then show ?case\n    by simp\nnext\n  case (Suc n)\n  then show ?case\n  proof (cases \"n > 0\")\n    case True\n    then show ?thesis\n      by (metis Suc.IH gr0_implies_Suc sntimes.simps(2) srcdups_eq)\n  next\n    case False\n    then show ?thesis\n      by auto\n  qed\nqed\n\nlemma srcdups_sntimes_prefix: \"n > 0 \\<Longrightarrow> srcdups\\<cdot>((sntimes n (\\<up>a)) \\<bullet> s) = \\<up>a \\<bullet> srcdups\\<cdot>(sdropwhile (\\<lambda>x. x=a)\\<cdot>s)\"\nproof (induction n)\n  case 0\n  then show ?case\n    by simp\nnext\n  case (Suc n)\n  then show ?case\n  proof (cases \"n > 1\")\n    case True\n    then obtain m where \"n = Suc m\" and \"m > 0\"\n      by (metis One_nat_def Suc_lessE)\n    then have \"srcdups\\<cdot>((sntimes (Suc n) (\\<up>a)) \\<bullet> s) = srcdups\\<cdot>((sntimes n (\\<up>a)) \\<bullet> s)\"\n      by (simp add: \\<open>n = Suc m\\<close>)\n    then show ?thesis\n      using Suc.IH \\<open>n = Suc m\\<close> zero_less_Suc by auto \n  next\n    case False\n    have \"srcdups\\<cdot>(\\<up>a \\<bullet> s) = \\<up>a \\<bullet> srcdups\\<cdot>(sdropwhile (\\<lambda>x. x=a)\\<cdot>s)\"\n      using srcdups_step by blast\n    moreover have \"sntimes 1 (\\<up>a) = \\<up>a\"\n      by (simp add: One_nat_def)\n    ultimately show ?thesis\n      by (metis (no_types, lifting) False One_nat_def Suc_lessI assoc_sconc neq0_conv sntimes.simps(2) srcdups_eq)\n  qed\nqed\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term sscanl}\\<close>\n(* ----------------------------------------------------------------------- *)\n\n(* SSCANL with the empty stream results in the empty stream *)\nlemma SSCANL_empty[simp]: \"SSCANL n f q \\<epsilon> = \\<epsilon>\"\nby (induct_tac n, auto)\n\ntext \\<open>monotonicity of SSCANL\\<close>\nlemma mono_SSCANL: \n  \"\\<forall> x y q. x \\<sqsubseteq> y \\<longrightarrow> SSCANL n f q x \\<sqsubseteq> SSCANL n f q y\"\napply (induct_tac n, auto)\napply (drule lessD, erule disjE, simp)\napply (erule exE)+\napply (erule conjE)+\nby (simp, rule monofun_cfun_arg, simp)\n\ntext \\<open>result of @{term \"SSCANL n\"} only depends on first @{term n}\n  elements of input stream\\<close>\nlemma contlub_SSCANL:\n  \"\\<forall>f q s. SSCANL n f q s = SSCANL n f q (stake n\\<cdot>s)\"\napply (induct_tac n, auto)\napply (rule_tac x=s in scases)\napply auto\napply (rule_tac x=s in scases)\nby auto\n\ntext \\<open>@{term SSCANL} is a chain. This means that, for all fixed inputs,\n  @{term \"SSCANL i\"} returns a prefix of @{term \"SSCANL (Suc i)\"}\\<close>\nlemma chain_SSCANL: \"chain SSCANL\"\napply (rule chainI)\napply (subst fun_below_iff)+\napply (induct_tac i, auto)\napply (rule monofun_cfun_arg)\napply (erule_tac x=\"x\" in allE)\napply (erule_tac x=\"x xa (shd xb)\" in allE)\nby (erule_tac x=\"srt\\<cdot>xb\" in allE, auto)\n\ntext \\<open>@{term sscanl} is a continuous function\\<close>\nlemma cont_lub_SSCANL: \"cont (\\<lambda>s. \\<Squnion>i. SSCANL i f q s)\" \napply (rule cont2cont_lub)\napply (rule ch2ch_fun)\napply (rule chainI)\napply (rule fun_belowD [of _ _ \"q\"])\napply (rule fun_belowD [of _ _ \"f\"])\napply (rule chainE)\napply (rule chain_SSCANL)\napply (rule pr_contI)\napply (rule monofunI)\napply (rule mono_SSCANL [rule_format], assumption)\napply (rule allI)\napply (rule_tac x=\"i\" in exI)\nby (rule contlub_SSCANL [rule_format])\n\ntext \\<open>Basic simplification rules for @{term sscanl}\\<close>\n(* sscanl applied to the empty stream returns the empty stream *)\nlemma sscanl_empty[simp]: \"sscanl f q\\<cdot>\\<epsilon> = \\<epsilon>\"\napply (simp add: sscanl_def)\napply (subst beta_cfun, rule cont_lub_SSCANL)\nby (subst is_lub_const \n  [THEN lub_eqI, of \"\\<epsilon>\", THEN sym], simp)\n\n(* scanning \\<up>a\\<bullet>s using q as the initial element is equivalent to computing \\<up>(f q a) and appending the\n   result of scanning s with (f q a) as the initial element *)\nlemma sscanl_scons[simp]: \n  \"sscanl f q\\<cdot>(\\<up>a\\<bullet>s) = \\<up>(f q a) \\<bullet> sscanl f (f q a)\\<cdot>s\"  \napply (simp add: sscanl_def)\napply (subst beta_cfun, rule cont_lub_SSCANL)+\napply (subst contlub_cfun_arg)\napply (rule ch2ch_fun, rule ch2ch_fun)\napply (rule chainI)\napply (rule fun_belowD [of _ _ \"f\"])\napply (rule chain_SSCANL [THEN chainE])\napply (subst lub_range_shift [where j=\"Suc 0\", THEN sym])\napply (rule ch2ch_fun, rule ch2ch_fun)\napply (rule chainI)\napply (rule fun_belowD [of _ _ \"f\"])\nby (rule chain_SSCANL [THEN chainE], simp)\n\n(* scanning a singleton stream is equivalent to computing \\<up>(f a b) *)\nlemma sscanl_one[simp]: \"sscanl f a\\<cdot>(\\<up>b) = \\<up>(f a b)\"\nby (insert sscanl_scons [of f a b \\<epsilon>], auto)\n\ntext \\<open>applying @{term sscanl} never shortens the stream\\<close>\nlemma fair2_sscanl: \"#x \\<le> #(sscanl f a\\<cdot>x)\"\napply (rule spec [where x = a])\napply (rule ind [of _ x], auto)\nby (subst lnle_def, simp del: lnle_conv)\n\n(* The first element of the result of sscanl_h is (f q (shd s)) *)\nlemma sscanl_shd: \"s\\<noteq>\\<epsilon> \\<Longrightarrow> shd (sscanl f q\\<cdot>s) = (f q (shd s))\"\nby (metis shd1 sscanl_scons surj_scons)\n\n(* dropping the first element of the result of sscanl is equivalent to beginning the scan with \n   (f a (shd s)) as the initial element and proceeding with the rest of the input *)\nlemma sscanl_srt: \"srt\\<cdot>(sscanl f a\\<cdot>s) = sscanl f (f a (shd s)) \\<cdot>(srt\\<cdot>s) \"\nby (metis (no_types, lifting) sconc_fst_empty sconc_scons' sscanl_empty sscanl_scons stream.sel_rews(2) stream.sel_rews(5) sup'_def surj_scons up_defined)\n\n(* the n + 1'st element produced by sscanl is the result of mering the n + 1'st item of s with the n'th\n   element produced by sscanl *)\nlemma sscanl_snth:  \"Fin (Suc n) < #s \\<Longrightarrow> snth (Suc n) (sscanl f a\\<cdot>s) = f (snth n (sscanl f a\\<cdot>s)) (snth (Suc n) s)\"\napply(induction n arbitrary:  a s)\napply (smt Fin_02bot Fin_leq_Suc_leq less2lnleD less_lnsuc lnat_po_eq_conv lnless_def lnzero_def shd1 slen_empty_eq slen_rt_ile_eq snth_scons snth_shd sscanl_scons surj_scons)\nby (smt Fin_Suc lnat_po_eq_conv lnle_def lnless_def lnsuc_lnle_emb lnzero_def minimal slen_scons snth_scons sscanl_scons strict_slen surj_scons)\n\n(* the result of sscanl has the same length as the input stream x *)\nlemma fair_sscanl[simp]: \"#(sscanl f a\\<cdot>x) = #x\"\napply (rule spec [where x = a])\nby (rule ind [of _ x], auto)\n\n(* Verification of sscanl with sscanl_nth *)\n\nprimrec sscanl_nth :: \"nat \\<Rightarrow> ('a \\<Rightarrow> 'a  \\<Rightarrow> 'a) \\<Rightarrow> 'a  \\<Rightarrow> 'a stream \\<Rightarrow> 'a\" where\n\"sscanl_nth 0 f q s =  f q (shd s)\" |\n\"sscanl_nth (Suc n) f q s = sscanl_nth n f (f q (shd s)) (srt\\<cdot>s)\"\n\n(* Nth element of sscanl is equal to sscanl_nth *)\nlemma sscanl2sscanl_nth:\n  \"Fin n<#s \\<Longrightarrow> snth n (sscanl f q\\<cdot>s) = sscanl_nth n f q s\"\nproof (induction n arbitrary: q s, auto)\n  fix q :: \"'a\" and s :: \"'a stream\" and k :: \"lnat\"\n  assume a1: \"#s = lnsuc\\<cdot>k\"\n  hence h1: \"s \\<noteq> \\<epsilon>\"\n    using lnsuc_neq_0_rev strict_slen by auto\n  thus \"shd (sscanl f q\\<cdot>s) = f q (shd s)\"\n    by (simp add: sscanl_shd)\nnext\n  fix n :: \"nat\" and  q :: \"'a\" and s :: \"'a stream\"\n  assume a2: \"\\<And>q s. Fin n < #s \\<Longrightarrow> snth n (sscanl f q\\<cdot>s) = sscanl_nth n f q s\"\n  assume a3: \"Fin (Suc n) < #s\"\n  thus \"snth (Suc n) (sscanl f q\\<cdot>s) = sscanl_nth n f (f q (shd s)) (srt\\<cdot>s)\"\n    by (metis a2 a3 leI not_less slen_rt_ile_eq snth_rt sscanl_srt)\nqed\n\nlemma sscan_ntimes_loop:\n  assumes \"\\<And>r. sscanl f state\\<cdot>(s \\<bullet> r) = out \\<bullet> (sscanl f state\\<cdot>r)\" \n  shows \"sscanl f state\\<cdot>(sntimes n s) = sntimes n out\"\n  using assms\n  by (induction n, simp_all)\n\nlemma sscanl_inftimes_loop:\n  assumes \"\\<And>r. sscanl f state\\<cdot>(s \\<bullet> r) = out \\<bullet> (sscanl f state\\<cdot>r)\"\n  shows \"sscanl f state\\<cdot>(sinftimes s) = sinftimes out\"\n  using assms\n  by (metis rek2sinftimes sinftimes_unfold slen_empty_eq sscanl_empty fair_sscanl strict_icycle) \n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term szip}\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>Basic simplification rules of @{term szip}\\<close>\n\n(* szip applied to \\<epsilon>\\<cdot>s returns the empty stream *)\nlemma strict_szip_fst[simp]: \"szip\\<cdot>\\<epsilon>\\<cdot>s = \\<epsilon>\"\nby (subst szip_def [THEN fix_eq2],simp)\n\n(* szip applied to s\\<cdot>\\<epsilon> returns the empty stream *)\nlemma strict_szip_snd[simp]: \"szip\\<cdot>s\\<cdot>\\<epsilon> = \\<epsilon>\"\nby (subst szip_def [THEN fix_eq2], simp)\n\n(* unfolding szip *)\nlemma szip_scons[simp]: \"szip\\<cdot>(\\<up>a\\<bullet>s1)\\<cdot>(\\<up>b\\<bullet>s2) = \\<up>(a,b) \\<bullet> (szip\\<cdot>s1\\<cdot>s2)\"\nby (subst szip_def [THEN fix_eq2], simp)\n\n(* rules for szip *)\nlemma [simp]: \"szip\\<cdot>(\\<up>a)\\<cdot>(\\<up>b \\<bullet> y) = \\<up>(a,b)\"\nby (subst szip_def [THEN fix_eq2], simp)\n\n(* rules for szip *)\nlemma [simp]: \"szip\\<cdot>(\\<up>a \\<bullet> x)\\<cdot>(\\<up>b) = \\<up>(a,b)\"\nby (subst szip_def [THEN fix_eq2], simp)\n\n(* rules for szip *)\nlemma [simp]: \"szip\\<cdot>(\\<up>a)\\<cdot>(\\<up>b) = \\<up>(a,b)\"\nby (subst szip_def [THEN fix_eq2], simp)\n\ntext \\<open>If @{term szip} returns an empty stream, an input stream was empty\\<close>\nlemma strict_rev_szip: \"szip\\<cdot>x\\<cdot>y = \\<epsilon> \\<Longrightarrow> x = \\<epsilon> \\<or> y = \\<epsilon>\"\napply (rule_tac x=x in scases, auto)\nby (rule_tac x=y in scases, auto)\n\ntext \\<open>@{term sprojfst} and @{term sprojsnd} are \"inverse\" functions of\n  @{term szip} - if the other zipped stream is infinite\\<close>\nlemma sprojfst_szipl1[rule_format]: \n  \"\\<forall>x. #x = \\<infinity> \\<longrightarrow> sprojfst\\<cdot>(szip\\<cdot>i\\<cdot>x) = i\"\napply (rule ind [of _ i], auto)\nby (rule_tac x=x in scases, auto)\n\n(* analogous for sprojsnd *)\nlemma sprojsnd_szipl1[rule_format]: \n  \"\\<forall>x. #x = \\<infinity> \\<longrightarrow> sprojsnd\\<cdot>(szip\\<cdot>x\\<cdot>i) = i\"\napply (rule ind [of _ i], auto)\nby (rule_tac x=x in scases, auto)\n\n(* zipping the infinite constant streams \\<up>x\\<infinity> and \\<up>y\\<infinity> is equivalent to infinitely repeating the tuple\n   \\<up>(x, y) *)\nlemma szip2sinftimes[simp]: \"szip\\<cdot>((\\<up>x)\\<^sup>\\<infinity>)\\<cdot>((\\<up>y)\\<^sup>\\<infinity>) = ((\\<up>(x, y))\\<^sup>\\<infinity>) \"\nby (metis s2sinftimes sinftimes_unfold szip_scons)\n\n(* the length of szip\\<cdot>as\\<cdot>bs is the minimum of the lengths of as and bs *)\nlemma szip_len [simp]: \"#(szip\\<cdot>as\\<cdot>bs) = min (#as) (#bs)\"\napply(induction as arbitrary: bs)\napply(rule admI)\napply auto[1]\napply (metis inf_chainl4 inf_less_eq lub_eqI lub_finch2 min_def slen_sprojsnd sprojsnd_szipl1)\napply simp\napply(case_tac \"bs=\\<epsilon>\")\napply auto[1]\nproof -\n  fix u :: \"'a discr u\"\n  fix as:: \"'a stream\"\n  fix bs:: \"'b stream\"\n  assume as1: \"u \\<noteq> \\<bottom>\" and \n    as2: \"(\\<And>bs::'b stream. #(szip\\<cdot>as\\<cdot>bs) = min (#as) (#bs))\" and as3: \"bs \\<noteq> \\<epsilon>\" \n  obtain a where a_def: \"updis a = u\" by (metis (mono_tags)as1 lshd_updis stream.sel_rews(4) stream.sel_rews(5) surj_scons)\n  obtain b bs2 where b_def: \"bs = \\<up>b \\<bullet> bs2\" by (metis as3 surj_scons) \n  hence \"#(szip\\<cdot>(\\<up>a \\<bullet> as)\\<cdot>(\\<up>b \\<bullet> bs2)) = min (#(\\<up>a \\<bullet> as)) (#(\\<up>b \\<bullet> bs2))\" by (simp add: as2 min_def) \n  thus \"#(szip\\<cdot>(u && as)\\<cdot>bs) = min (#(u && as)) (#bs)\" by (metis a_def b_def lscons_conv) \nqed\n\nlemma szip_nth: \"Fin n < #s1 \\<Longrightarrow> Fin n < #s2 \\<Longrightarrow> snth n (szip\\<cdot>s1\\<cdot>s2) = (snth n s1, snth n s2)\"\n  apply(induction n arbitrary: s1 s2)\n  apply auto\n   apply (metis lnsuc_neq_0 only_empty_has_length_0 shd1 surj_scons szip_scons)\n  apply(simp add: snth_rt)\n  by (smt empty_is_shortest leD not_le only_empty_has_length_0 only_empty_has_length_0 only_empty_has_length_0 slen_rt_ile_eq slen_rt_ile_eq snth_rt snth_scons stream.sel_rews(2) stream.sel_rews(2) strict_slen strict_slen strict_slen strict_szip_snd surj_scons surj_scons szip_scons)\n\nlemma szip_sdrop: \"sdrop n\\<cdot>(szip\\<cdot>s\\<cdot>t) = szip\\<cdot>(sdrop n\\<cdot>s)\\<cdot>(sdrop n\\<cdot>t)\"\n  apply(induction n arbitrary: s t, simp)\n  by (metis (no_types, lifting) sdrop_forw_rt sdrop_scons stream.sel_rews(2) strict_szip_fst \n            strict_szip_snd surj_scons szip_scons)\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term sscanlA}\\<close>\n(* ----------------------------------------------------------------------- *)\n\nlemma sscanla_cont: \"cont (\\<lambda>s. sprojfst\\<cdot>(sscanl (\\<lambda>(_,b). f b) (undefined, s0)\\<cdot>s))\"\n  by simp\n\nlemma sscanla_len [simp]: \"#(sscanlA f s0\\<cdot>s) = #s\"\n  by (simp add: sscanlA_def slen_sprojfst)\n\nlemma sscanla_bot [simp]: \"sscanlA f s0\\<cdot>\\<bottom> = \\<bottom>\"\n  by (simp add: sscanlA_def)\n\nlemma sscanla_step [simp]: \"sscanlA f s0\\<cdot>(\\<up>a \\<bullet> as) = \\<up>(fst (f s0 a)) \\<bullet> sscanlA f (snd (f s0 a))\\<cdot>as\"\n  apply(simp add: sscanlA_def sprojfst_def)\nproof -\n  have \"(case f s0 a of (a, x) \\<Rightarrow> f x) = (case (undefined::'a, snd (f s0 a)) of (a, x) \\<Rightarrow> f x)\"\nby (metis (no_types) old.prod.case prod.collapse)\n  then have \"\\<up>(shd as) \\<bullet> srt\\<cdot>as = as \\<longrightarrow> sscanl (\\<lambda>(a, y). f y) (f s0 a)\\<cdot>as = sscanl (\\<lambda>(a, y). f y) (undefined, snd (f s0 a))\\<cdot> (\\<up>(shd as) \\<bullet> srt\\<cdot>as)\"\n    by (metis (no_types) sscanl_scons)\n  then show \"\\<up>(fst (f s0 a)) \\<bullet> smap fst\\<cdot> (sscanl (\\<lambda>(a, y). f y) (f s0 a)\\<cdot> as) = \\<up>(fst (f s0 a)) \\<bullet> smap fst\\<cdot> (sscanl (\\<lambda>(a, y). f y) (undefined, snd (f s0 a))\\<cdot> as)\"\n    using surj_scons by force\nqed\n\nlemma sscanla_one [simp]: \"sscanlA f b\\<cdot>(\\<up>x) = \\<up>(fst (f b x))\"\n  apply(simp add: sscanlA_def)\n  by (metis prod.collapse sconc_snd_empty sprojfst_scons strict_sprojfst)\n\nlemma sscanla_shd: \"s\\<noteq>\\<epsilon> \\<Longrightarrow> shd (sscanlA f q\\<cdot>s) = fst (f q (shd s))\"\n  by (metis shd1 sscanla_step surj_scons)\n\nlemma sscanla_srt: \"srt\\<cdot>(sscanlA f a\\<cdot>s) = sscanlA f (snd (f a (shd s)))\\<cdot>(srt\\<cdot>s)\"\n  by (metis (no_types, lifting) sconc_fst_empty sconc_scons' sscanla_bot sscanla_step stream.sel_rews(2) stream.sel_rews(5) sup'_def surj_scons up_defined)\n\nlemma sscanla_ntimes_loop:\n  assumes \"\\<And>r. sscanlA f state\\<cdot>(s \\<bullet> r) = out \\<bullet> (sscanlA f state\\<cdot>r)\" \n  shows \"sscanlA f state\\<cdot>(sntimes n s) = sntimes n out\"\n  using assms\n  by (induction n, simp_all)\n\nlemma sscanla_inftimes_loop:\n  assumes \"\\<And>r. sscanlA f state\\<cdot>(s \\<bullet> r) = out \\<bullet> (sscanlA f state\\<cdot>r)\"\n  shows \"sscanlA f state\\<cdot>(sinftimes s) = sinftimes out\"\n  using assms\n  by (metis rek2sinftimes sinftimes_unfold slen_empty_eq sscanla_bot sscanla_len strict_icycle) \n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term sscanlAg}\\<close>\n(* ----------------------------------------------------------------------- *)\n\nlemma sscanlag_cont: \"cont (\\<lambda>s. (sscanl (\\<lambda>(b,_). f b) (s0, undefined)\\<cdot>s))\"\n  by simp\n\nlemma sscanlag_len [simp]: \"#(sscanlAg f s0\\<cdot>s) = #s\"\n  by(simp add: sscanlAg_def slen_sprojsnd)\n\nlemma sscanlag_bot [simp]: \"sscanlAg f s0\\<cdot>\\<bottom> = \\<bottom>\"\n  by (simp add: sscanlAg_def)\n\n\nlemma sscanlag_one [simp]: \"sscanlAg f b\\<cdot>(\\<up>x) = \\<up>(fst(f b x), snd (f b x))\"\n  by(simp add: sscanlAg_def)\n\nlemma sscanlag_step [simp]: \"sscanlAg f s0\\<cdot>(\\<up>a \\<bullet> as) = \\<up>((f s0 a)) \\<bullet> sscanlAg f (fst (f s0 a))\\<cdot>as\"\n  apply(simp add: sscanlAg_def sprojfst_def)\n  by (smt case_prod_conv prod.collapse sscanl_empty sscanl_scons surj_scons)\n\nlemma sscanlag_shd: \"s\\<noteq>\\<epsilon> \\<Longrightarrow> shd (sscanlAg f q\\<cdot>s) = (f q (shd s))\"\n  by (metis shd1 sscanlag_step surj_scons)\n\nlemma sscanlag_srt: \"srt\\<cdot>(sscanlAg f a\\<cdot>s) = sscanlAg f (fst (f a (shd s)))\\<cdot>(srt\\<cdot>s)\"\n  by (metis (no_types, lifting) sconc_fst_empty sconc_scons' sscanlag_bot sscanlag_step stream.sel_rews(2) stream.sel_rews(5) sup'_def surj_scons up_defined)\n\nlemma snth_sscanlAg:\n  assumes \"Fin (Suc j)<#i\"\n    shows \"snth (Suc j) (sscanlAg f s0\\<cdot>i) = f (fst (snth j (sscanlAg f s0\\<cdot>i))) (snth (Suc j) i)\"\n  apply(simp add: sscanlAg_def)\n  by (metis (mono_tags, lifting) assms case_prod_conv prod.exhaust_sel sscanl_snth)\n\nlemma sscanlag_ntimes_loop:\n  assumes \"\\<And>r. sscanlAg f state\\<cdot>(s \\<bullet> r) = out \\<bullet> (sscanlAg f state\\<cdot>r)\" \n  shows \"sscanlAg f state\\<cdot>(sntimes n s) = sntimes n out\"\n  using assms\n  by (induction n, simp_all)\n\nlemma sscanlag_inftimes_loop:\n  assumes \"\\<And>r. sscanlAg f state\\<cdot>(s \\<bullet> r) = out \\<bullet> (sscanlAg f state\\<cdot>r)\"\n  shows \"sscanlAg f state\\<cdot>(sinftimes s) = sinftimes out\"\n  using assms\n  by (metis rek2sinftimes sinftimes_unfold slen_empty_eq sscanlag_bot sscanlag_len strict_icycle) \n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term sscanlAfst}\\<close>\n(* ----------------------------------------------------------------------- *)\n\nlemma sscanlafst_cont: \"cont (\\<lambda>s. sprojfst\\<cdot>(sscanlAg (\\<lambda>(_,b). f b) (undefined, s0)\\<cdot>s))\"\n  by simp\n\nlemma sscanlafst_len [simp]: \"#(sscanlAfst f s0\\<cdot>s) = #s\"\n  by (simp add: sscanlAfst_def slen_sprojfst)\n\nlemma sscanlafst_bot [simp]: \"sscanlAfst f s0\\<cdot>\\<bottom> = \\<bottom>\"\n  by (simp add: sscanlAfst_def)\n\nlemma sscanlafst_step [simp]: \"sscanlAfst f s0\\<cdot>(\\<up>a \\<bullet> as) = \\<up>(fst (f s0 a)) \\<bullet> sscanlAfst f (fst (f s0 a))\\<cdot>as\"\n  apply (simp add: sscanlAfst_def sprojfst_def sscanlAg_def) \n  by (smt approxl2 case_prod_conv eta_cfun fair_sscanl fin2stake prod.collapse sconc_prefix sconc_snd_empty slen_scons slen_smap smap_hd_rst sprojfst_def sscanl_empty sscanl_shd sscanl_srt strict_sprojfst)\n\nlemma sscanlafst_one [simp]: \"sscanlAfst f b\\<cdot>(\\<up>x) = \\<up>(fst (f b x))\"\n  apply(simp add: sscanlAfst_def)\n  by (metis prod.collapse sconc_snd_empty sprojfst_scons strict_sprojfst)\n\nlemma sscanlafst_shd: \"s\\<noteq>\\<epsilon> \\<Longrightarrow> shd (sscanlAfst f q\\<cdot>s) = fst (f q (shd s))\"\n  by (metis shd1 sscanlafst_step surj_scons)\n\nlemma sscanlafst_srt: \"srt\\<cdot>(sscanlAfst f a\\<cdot>s) = sscanlAfst f (fst (f a (shd s)))\\<cdot>(srt\\<cdot>s)\"\n  by (metis (no_types, lifting) sconc_fst_empty sconc_scons' sscanlafst_bot sscanlafst_step stream.sel_rews(2) stream.sel_rews(5) sup'_def surj_scons up_defined)\n\nlemma sscanlafst_snth: assumes \"Fin (Suc n) < #s\" and \"s2 = fst (shd (sscanlAg f state\\<cdot>s))\"\n  shows \"snth (Suc n) (sscanlAfst f state\\<cdot>s) = snth n (sscanlAfst f s2\\<cdot>(srt\\<cdot>s))\"\n  apply(simp add: assms sscanlAfst_def)\n  apply(subst sprojfst_snth)\n  apply(simp add: assms)\n  apply (meson assms(1) leD leI slen_rt_ile_eq)\n  apply(subst snth_sscanlAg)\n  apply(simp add: assms)\n  by (metis (no_types, lifting) assms(1) empty_is_shortest shd1 snth_scons snth_sscanlAg sscanlag_step surj_scons)\n\nlemma sscanlafst_ntimes_loop:\n  assumes \"\\<And>r. sscanlAfst f state\\<cdot>(s \\<bullet> r) = out \\<bullet> (sscanlAfst f state\\<cdot>r)\" \n  shows \"sscanlAfst f state\\<cdot>(sntimes n s) = sntimes n out\"\n  using assms\n  by (induction n, simp_all)\n\nlemma sscanlafst_inftimes_loop:\n  assumes \"\\<And>r. sscanlAfst f state\\<cdot>(s \\<bullet> r) = out \\<bullet> (sscanlAfst f state\\<cdot>r)\"\n  shows \"sscanlAfst f state\\<cdot>(sinftimes s) = sinftimes out\"\n  using assms\n  by (metis rek2sinftimes sinftimes_unfold slen_empty_eq sscanlafst_bot sscanlafst_len strict_icycle) \n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term sscanlAsnd}\\<close>\n(* ----------------------------------------------------------------------- *)\n\nlemma sscanlasnd_cont: \"cont (\\<lambda>s. sprojsnd\\<cdot>(sscanl (\\<lambda>(b,_). f b) (s0, undefined)\\<cdot>s))\"\n  by simp\n\nlemma sscanlasnd_len [simp]: \"#(sscanlAsnd f s0\\<cdot>s) = #s\"\n  by(simp add: sscanlAsnd_def slen_sprojsnd)\n\nlemma sscanlasnd_bot [simp]: \"sscanlAsnd f s0\\<cdot>\\<bottom> = \\<bottom>\"\n  by (simp add: sscanlAsnd_def)\n\nlemma sscanlasnd_step [simp]: \"sscanlAsnd f s0\\<cdot>(\\<up>a \\<bullet> as) = \\<up>(snd (f s0 a)) \\<bullet> sscanlAsnd f (fst (f s0 a))\\<cdot>as\"\n  apply(simp add: sscanlAsnd_def sprojsnd_def sscanlAg_def)\nproof -\n  have \"(case f s0 a of (x, a) \\<Rightarrow> f x) = (case (fst (f s0 a), undefined::'a) of (x, a) \\<Rightarrow> f x)\"\n    by (metis (no_types) old.prod.case prod.collapse)\n  then have \"\\<up>(shd as) \\<bullet> srt\\<cdot>as = as \\<longrightarrow>(sscanl (\\<lambda>(b, uu). f b) (f s0 a)\\<cdot>as)= (sscanl (\\<lambda>(b, uu). f b) (fst (f s0 a), undefined)\\<cdot>as)\"\n    by (metis (no_types) sscanl_scons)\n  then show \"\\<up>(snd (f s0 a)) \\<bullet> smap snd\\<cdot>(sscanl (\\<lambda>(b, uu). f b) (f s0 a)\\<cdot>as) = \\<up>(snd (f s0 a)) \\<bullet> smap snd\\<cdot>(sscanl (\\<lambda>(b, uu). f b) (fst (f s0 a), undefined)\\<cdot>as)\"\n    using surj_scons by force\nqed\n\nlemma sscanlasnd_one [simp]: \"sscanlAsnd f b\\<cdot>(\\<up>x) = \\<up>(snd (f b x))\"\n  apply(simp add: sscanlAsnd_def)\n  by (metis eq_snd_iff sconc_snd_empty sprojsnd_scons strict_sprojsnd)\n\nlemma sscanlasnd_shd: \"s\\<noteq>\\<epsilon> \\<Longrightarrow> shd (sscanlAsnd f q\\<cdot>s) = snd (f q (shd s))\"\n  by (metis shd1 sscanlasnd_step surj_scons)\n\nlemma sscanlasnd_srt: \"srt\\<cdot>(sscanlAsnd f a\\<cdot>s) = sscanlAsnd f (fst (f a (shd s)))\\<cdot>(srt\\<cdot>s)\"\n  by (metis (no_types, lifting) sconc_fst_empty sconc_scons' sscanlasnd_bot sscanlasnd_step stream.sel_rews(2) stream.sel_rews(5) sup'_def surj_scons up_defined)\n\nlemma sscanlasnd_snth: assumes \"Fin (Suc n)<#s\" and \"s2 = fst(shd(sscanlAg f state\\<cdot>s))\"\n  shows \"snth (Suc n) (sscanlAsnd f state\\<cdot>s) = snth n (sscanlAsnd f s2\\<cdot>(srt\\<cdot>s))\"\n  apply(simp add: assms sscanlAsnd_def)\n  apply(subst sprojsnd_snth)\n   apply(simp add: assms)\n  by (metis assms(1) empty_is_shortest eta_cfun rt_Sproj_2_eq smap_snth_lemma snth_rt sprojsnd_def sscanlag_len sscanlag_shd sscanlag_srt)\n\nlemma sscanlasnd_snth2:\n  assumes \"Fin (Suc n) < #(\\<up>a \\<bullet> s)\"\n  shows \"snth (Suc n) (sscanlAsnd f state\\<cdot>(\\<up>a \\<bullet> s)) = snth n (sscanlAsnd f (fst (f state a))\\<cdot>s)\"\n  using assms\n  apply (induction s arbitrary: a rule: ind)\n  by simp_all\n\nlemma sscanlasnd_ntimes_loop:\n  assumes \"\\<And>r. sscanlAsnd f state\\<cdot>(s \\<bullet> r) = out \\<bullet> (sscanlAsnd f state\\<cdot>r)\" \n  shows \"sscanlAsnd f state\\<cdot>(sntimes n s) = sntimes n out\"\n  using assms\n  by (induction n, simp_all)\n\nlemma sscanlasnd_inftimes_loop:\n  assumes \"\\<And>r. sscanlAsnd f state\\<cdot>(s \\<bullet> r) = out \\<bullet> (sscanlAsnd f state\\<cdot>r)\"\n  shows \"sscanlAsnd f state\\<cdot>(sinftimes s) = sinftimes out\"\n  using assms\n  by (metis rek2sinftimes sinftimes_unfold slen_empty_eq sscanlasnd_bot sscanlasnd_len strict_icycle) \n\nlemma sscanlasnd2sinftimes:\n  assumes \"#s=\\<infinity>\"\n    and \"sscanlAsnd f state\\<cdot>s = out \\<bullet> (sscanlAsnd f state\\<cdot>s)\"\n    and \"out \\<noteq> \\<epsilon>\"\n  shows \"sscanlAsnd f state\\<cdot>s = sinftimes out\"\n  using assms rek2sinftimes by auto\n\nlemma sscanl2smap:\n  assumes \"\\<And>e. fst(f s e) = s\"\n  and \"g = (\\<lambda>a. snd(f s a))\"\nshows\"sscanlAsnd f s = smap g\"\n  apply(rule cfun_eqI)\n  by(induct_tac x rule: ind,simp_all add: assms)\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term merge}\\<close>\n(* ----------------------------------------------------------------------- *)\n\n(* unfolding of merge function *)\nlemma merge_unfold: \"merge f\\<cdot>(\\<up>x \\<bullet> xs)\\<cdot>(\\<up>y\\<bullet> ys) = \\<up>(f x y) \\<bullet> merge f\\<cdot>xs\\<cdot>ys\"\n  by(simp add: merge_def)\n\n(* relation between merge and snth *)\nlemma merge_snth[simp]: \"Fin n <#xs \\<Longrightarrow>Fin n < #ys \\<Longrightarrow> snth n (merge f\\<cdot>xs\\<cdot>ys) = f (snth n xs) (snth n ys)\"\n  apply(induction n arbitrary:xs ys)\n   apply (metis Fin_02bot merge_unfold lnless_def lnzero_def shd1 slen_empty_eq snth_shd surj_scons)\n  by (smt Fin_Suc Fin_leq_Suc_leq Suc_eq_plus1_left merge_unfold inject_lnsuc less2eq less2lnleD lnle_conv lnless_def lnsuc_lnle_emb sconc_snd_empty sdropostake shd1 slen_scons snth_rt snth_scons split_streaml1 stream.take_strict surj_scons ub_slen_stake)\n\n(* merge applied to f\\<cdot>\\<epsilon>\\<cdot>ys return the empty stream *)\nlemma merge_eps1[simp]: \"merge f\\<cdot>\\<epsilon>\\<cdot>ys = \\<epsilon>\"\n  by(simp add: merge_def)\n\n(* merge applied to f\\<cdot>xs\\<cdot>\\<epsilon> also returns the empty stream *)\nlemma merge_eps2[simp]: \"merge f\\<cdot>xs\\<cdot>\\<epsilon> = \\<epsilon>\"\n  by(simp add: merge_def)\n\n(* relation between srt and merge *)\nlemma [simp]: \"srt\\<cdot>(merge f\\<cdot>(\\<up>a \\<bullet> as)\\<cdot>(\\<up>b \\<bullet> bs)) = merge f\\<cdot>as\\<cdot>bs\"\n  by (simp add: merge_unfold)\n\n(* the length of merge f\\<cdot>as\\<cdot>bs is the minimum of the lengths of as and bs *)\nlemma merge_len [simp]: \"#(merge f\\<cdot>as\\<cdot>bs) = min (#as) (#bs)\"\nby(simp add: merge_def)\n\n(* the merge function is commutative *)\nlemma merge_commutative: assumes \"\\<And> a b. f a b = f b a\"\n  shows \"merge f\\<cdot>as\\<cdot>bs = merge f\\<cdot>bs\\<cdot>as\"\n  apply(rule snths_eq)\n   apply (simp add: min.commute)\n  by (simp add: assms)\n  \n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term siterate}\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>@{term siterate} is defined by running @{term sscanl} on an arbitrary\n  infinite stream. Only the stream length is relevant for the result\\<close>\nlemma siterate_inv_lemma:\n  \"\\<forall>x z a. #z = #x \n     \\<longrightarrow> stake n\\<cdot>(sscanl (\\<lambda>a b. f a) a\\<cdot>x) = \n        stake n\\<cdot>(sscanl (\\<lambda>a b. f a) a\\<cdot>z)\"\napply (induct_tac n, auto)\napply (rule_tac x=x in scases, auto)\nby (rule_tac x=z in scases, auto)\n\ntext \\<open>@{term siterate} is well-defined (because it is independent of\n  the infinite stream on which @{term sscanl} is applied)\\<close>\nlemma siterate_def2:\n  \"#x = \\<infinity> \\<Longrightarrow> siterate f a = \\<up>a \\<bullet> sscanl (\\<lambda>a b. f a) a\\<cdot>x\"\napply (subst siterate_def)\napply (rule someI2_ex)\napply (rule_tac x=\"sinftimes (\\<up>(SOME a. True))\" in exI, simp)\napply (rule cfun_arg_cong)\napply (rule stream.take_lemma)\nby (rule siterate_inv_lemma [rule_format], simp)\n\ntext \\<open>unfolding of @{term siterate} definition\\<close>\nlemma siterate_scons: \"siterate f a = \\<up>a \\<bullet> siterate f (f a)\"\napply (rule stream.take_lemma [OF spec [where x=\"a\"]])\napply (induct_tac n, auto)\napply (insert siterate_def2 [of _ f], atomize)\napply (erule_tac x=\"sinftimes (\\<up>x)\" in allE, auto)\nby (subst sinftimes_unfold, simp)\n\n(* to define the nth element of siterate we define a helper function \\<open>niterate\\<close> *)\n(* \\<open>iterate\\<close> cannot be used, because the function is only about CPO's, maybe some\nof those lemmata about niterate could be in Prelude, but not all of them *)\nprimrec niterate :: \"nat \\<Rightarrow> ('a::type \\<Rightarrow> 'a) \\<Rightarrow> ('a \\<Rightarrow> 'a)\" where\n    \"niterate 0 = (\\<lambda> F x. x)\"\n  | \"niterate (Suc n) = (\\<lambda> F x. F (niterate n F x))\"\n\n(* niterate applied to the successor of n is the same as applying niterate to n F *)\nlemma niterate_Suc2: \"niterate (Suc n) F x = niterate n F (F x)\"\napply(induction n)\nby(simp_all)\n\n(* relation between iterate and niterate *)\nlemma niter2iter: \"iterate g\\<cdot>h\\<cdot>x = niterate g (Rep_cfun h) x\"\napply (induction g)\nby(simp_all)\n  \n(* iterate and the empty stream *)\nlemma iterate_eps [simp]: assumes \"g \\<epsilon> = \\<epsilon>\"\n  shows \"(iterate i\\<cdot>(\\<Lambda> h. (\\<lambda>s. s \\<bullet> h (g s)))\\<cdot>\\<bottom>) \\<epsilon> = \\<epsilon>\" \nusing assms by (induction i, auto)\n  \n(* fix and the empty stream *)\nlemma fix_eps [simp]: assumes \"g \\<epsilon> = \\<epsilon>\"\n  shows \"(\\<mu> h. (\\<lambda>s. s \\<bullet> h (g s))) \\<epsilon> = \\<epsilon>\"\nproof -\n  have aI: \"max_in_chain 0 (\\<lambda>i. (iterate i\\<cdot>(\\<Lambda> h. (\\<lambda>s. s \\<bullet> h (g s)))\\<cdot>\\<bottom>) \\<epsilon> )\" by (simp add: max_in_chainI assms)\n  hence \"(\\<Squnion>i. (iterate i\\<cdot>(\\<Lambda> h. (\\<lambda>s. s \\<bullet> h (g s)))\\<cdot>\\<bottom>) \\<epsilon>) = \\<epsilon>\"  using assms by auto \n  hence \" (\\<Squnion> i. iterate i\\<cdot>(\\<Lambda> h. (\\<lambda>s. s \\<bullet> h (g s)))\\<cdot>\\<bottom>) \\<epsilon> = \\<epsilon>\" by (simp add: lub_fun) \n  thus ?thesis using fix_def2 by (metis (no_types, lifting) lub_eq)\nqed\n\n(* beginning the iteration of the function h with the element (h x) is equivalent to beginning the\n   iteration with x and dropping the head of the iteration *)\nlemma siterate_sdrop: \"siterate h (h x) = sdrop 1\\<cdot>(siterate h x)\"\nby (metis One_nat_def sdrop_0 sdrop_scons siterate_scons)\n\n(* iterating the function h infinitely often after having already iterated i times is equivalent to\n   beginning the iteration with x and then dropping i elements from the resulting stream *)\nlemma siterate_drop2iter: \"siterate h (niterate i h x) = sdrop i\\<cdot>(siterate h x)\"\napply (induction i)\napply (simp add: One_nat_def)\nby (simp add: sdrop_back_rt siterate_sdrop One_nat_def)\n\n(* the head of iterating the function g on x doesn't have any applications of g *)\nlemma shd_siter[simp]: \"shd (siterate g x) = x\"\nby (simp add: siterate_def)\n\n(* dropping i elements from the infinite iteration of the function g on x and then extracting the head\n   is equivalent to computing the i'th iteration via niterate *)\nlemma shd_siters: \"shd (sdrop i\\<cdot>(siterate g x)) = niterate i g x\"\nby (metis shd_siter siterate_drop2iter)   \n\ntext \\<open>Addition of two numbers using @{term \"siterate Suc\"}\\<close>\nlemma snth_siterate_Suc: \"snth k (siterate Suc j) = k + j\"\napply (rule_tac x=\"j\" in spec)\napply (induct_tac k, simp)\napply (rule allI)\nby (subst siterate_scons, simp)+\n\n(* applying snth to k and siterate Suc 0 returns k *)\nlemma snth_siterate_Suc_0[simp]: \"snth k (siterate Suc 0) = k\"\nby (simp add: snth_siterate_Suc)\n\n(* relation between sdrop and siterate *)\nlemma sdrop_siterate:\n  \"sdrop k\\<cdot>(siterate Suc j) = siterate Suc (j + k)\"\napply (rule_tac x=\"j\" in spec)\napply (induct_tac k, simp+)\napply (rule allI)\nby (subst siterate_scons, simp)\n\ntext \\<open>@{term siterate} only creates infinite outputs\\<close>\nlemma [simp]: \"#(siterate f k) = \\<infinity>\"\napply (rule infI)\napply (rule allI)\napply (rule_tac x=\"k\" in spec)\napply (induct_tac k, simp+)\nby (subst siterate_scons, simp)+\n\n(* the i'th element of the infinite stream of iterating the function g on x can alternatively be found\n   with (niterate i g x) *)\nlemma snth_siter: \"snth i (siterate g x) = niterate i g x\"\nby (simp add: shd_siters snth_def)\n\n(* dropping j elements from the stream x and then extracting the i'th element is equivalent to extracting\n   the i+j'th element directly *)\nlemma snth_sdrop: \"snth i (sdrop j\\<cdot>x) = snth (i+j) x\"\nby (simp add: sdrop_plus snth_def)\n\n(* extracting the i+1'st element from the stream of iterating the function g on x is equivalent to extracting\n   the i'th element and then applying g one more time *)\nlemma snth_snth_siter: \"snth (Suc i) (siterate g x) = g (snth i (siterate g x))\"\nby (simp add: snth_siter)\n\n(* dropping the first element from the chain of iterates is equivalent to shifting the chain by applying g *)\nlemma sdrop_siter:  \"sdrop 1\\<cdot>(siterate g x) = smap g\\<cdot>(siterate g x)\"\napply(rule sinf_snt2eq)\napply (simp add: fair_sdrop) \napply simp\nby (simp add: smap_snth_lemma snth_sdrop snth_snth_siter One_nat_def)\n\n(* if the functions g and h commute then g also commutes with any number of iterations of h *)\nlemma iterate_insert: assumes \"\\<forall>z. h (g z) = g (h z)\"\n  shows \"niterate i h (g x) = g (niterate i h x)\"\nusing assms by (induction i, auto)\n\n(* lifts iterate_insert from particular iterations to streams of iterations *)\nlemma siterate_smap:  assumes \"\\<forall>z. g (h z) = h (g z)\"\n  shows \"smap g\\<cdot>(siterate h x) = siterate h (g x)\"\napply (rule sinf_snt2eq, auto)\nby (simp add: assms smap_snth_lemma snth_siter iterate_insert)\n\n(* iterating the function g on x is equivalent to the stream produced by concatenating \\<up>x and the \n   iteration of g on x shifted by another application of g *)\nlemma siterate_unfold: \"siterate g x = \\<up>x \\<bullet> smap g\\<cdot>(siterate g x)\"\nby (metis siterate_scons siterate_smap)\n\n(* iterating the identity function produces an infinite constant stream of the element x *)\nlemma siter2sinf: \"siterate id x = sinftimes (\\<up>x)\"\nby (metis id_apply s2sinftimes siterate_scons)\n\n(* dropping i and iterating the identity function returns siterate id x *)\nlemma \"sdrop i\\<cdot>(siterate id x) = siterate id x\"\n  by (smt sdrops_sinf siter2sinf)\n\n(* if g acts as the identity for the element x then iterating g on x produces an infinite constant\n   stream of x *)\nlemma siter2sinf2: assumes \"g x = x\"\n  shows \"siterate g x = sinftimes (\\<up>x)\"\nby (smt assms s2sinftimes siterate_scons)\n\n(* shows the equivalence of an alternative recursive definition of iteration *)\nlemma rek2niter: assumes \"xs = \\<up>x \\<bullet> (smap g\\<cdot>xs)\"\n  shows \"snth i xs = niterate i g x\"\nproof (induction i)\n  case 0 thus ?case by (metis assms niterate.simps(1) shd1 snth_shd)\nnext\n  case (Suc i) \n  have \"#xs = \\<infinity>\" by (metis Inf'_def assms below_refl fix_least_below inf_less_eq lnle_def slen_scons slen_smap)\n  thus ?case by (metis Fin_neq_inf Suc assms inf_ub lnle_def lnless_def niterate.simps(2) smap_snth_lemma snth_scons)\nqed\n\n(* important *)\n(* recursively mapping the function g over the rest of xs is equivalent to the stream of iterations of g on x *)\nlemma rek2siter: assumes \"xs = \\<up>x \\<bullet> (smap g\\<cdot>xs)\"\n  shows \"xs = siterate g x\" \napply (rule sinf_snt2eq, auto)\napply (metis Inf'_def assms fix_least inf_less_eq lnle_conv slen_scons slen_smap) \nby (metis assms rek2niter snth_siter)\n\n(* shows that siterate produces the least fixed point of the alternative recursive definition *)\nlemma fixrek2siter: \"fix\\<cdot>(\\<Lambda> s . (\\<up>x \\<bullet> smap g\\<cdot>s)) =  siterate g x\"\nby (metis (no_types) cfcomp1 cfcomp2 fix_eq rek2siter)\n\n(* dropping elements from a stream of iterations is equivalent to adding iterations to every element *)\nlemma sdrop2smap: \"sdrop i\\<cdot>(siterate g x) = smap (niterate i g)\\<cdot>(siterate g x)\"\nby (simp add: iterate_insert siterate_drop2iter siterate_smap)\n\n\n(* ----------------------------------------------------------------------- *)\nsection \\<open>Adm simp rules\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext\\<open>For functions g and h producing sets the following predicate is admissible\\<close>\nlemma adm_subsetEq [simp]: \"adm (\\<lambda>s. g\\<cdot>s \\<subseteq> h\\<cdot>s)\"\nby (metis (full_types) SetPcpo.less_set_def adm_below cont_Rep_cfun2)\n\ntext\\<open>For a function g producing sets and a set cs the following predicate is admissible\\<close>\nlemma adm_subsetEq_rc [simp]: \"adm (\\<lambda>s. g\\<cdot>s \\<subseteq> cs)\"\nby (metis (no_types, lifting) adm_def chain_monofun contlub_cfun_arg lub_below set_cpo_simps(1))\n\ntext\\<open>For a function h producing sets and a set cs the following predicate is admissible\\<close>\nlemma adm_subsetEq_lc [simp]: \"adm (\\<lambda>s. cs \\<subseteq> h\\<cdot>s)\"\nby (simp add: adm_subst adm_superset)\n\ntext\\<open>For a set cs and a function g producing sets, the following predicate is admissible\\<close>\nlemma adm_subsetNEq_rc [simp]: \"adm (\\<lambda>s. \\<not> g\\<cdot>s \\<subseteq> cs)\"\n  apply(rule admI)\n  apply(rule+)\n  by (metis SetPcpo.less_set_def is_ub_thelub monofun_cfun_arg subset_eq)\n\ntext\\<open>For a function g over streams, the admissiblity of the following predicate over streams holds\\<close>\nlemma sValues_adm2[simp]: \"adm (\\<lambda>a. sValues\\<cdot>(g\\<cdot>a) \\<subseteq> sValues\\<cdot>a)\"\napply(rule admI)\nby (smt SetPcpo.less_set_def ch2ch_Rep_cfunR contlub_cfun_arg is_ub_thelub lub_below subset_iff)\n\n(* admissibility of finstream *)\nlemma adm_finstream [simp]: \"adm (\\<lambda>s. #s<\\<infinity> \\<longrightarrow> P s)\"\napply(rule admI)\napply auto\nusing inf_chainl4 lub_eqI lub_finch2 by fastforce\n\n(* admissibility of fin below *)\nlemma adm_fin_below: \"adm (\\<lambda>x . \\<not> Fin n \\<sqsubseteq> # x)\"\n  apply(rule admI)\n  apply auto\n  by (metis inf_chainl3 finite_chain_def maxinch_is_thelub)\n\n(* admissibility of fin below for special case of \\<le> *)\nlemma adm_fin_below2: \"adm (\\<lambda>x . \\<not> Fin n \\<le> # x)\"\nby(simp only: lnle_def adm_fin_below)\n\n\n(* ----------------------------------------------------------------------- *)\nsection \\<open>New @{term sfilter} lemmata and @{term sfoot}\\<close>\n(* ----------------------------------------------------------------------- *)\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>New @{term sfilter} lemmata\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext\\<open>Appending the singleton stream \\<up>a increases the length of the stream y by one\\<close>\nlemma slen_lnsuc: \n  shows \"#(y \\<bullet> \\<up>a) = lnsuc\\<cdot>(#y)\"\n  apply(induction y)\n    apply (smt admI fold_inf inf_chainl4 lub_eqI lub_finch2 sconc_fst_inf)\n   apply (metis sconc_fst_empty sconc_snd_empty slen_scons)\n  by (metis (no_types, lifting) assoc_sconc slen_scons stream.con_rews(2) stream.sel_rews(5) surj_scons)\n\n\n(* if filtering the stream s2 with the set A produces infinitely many elements then prepending any\n   finite stream s1 to s2 will still produce infinitely many elements *)\nlemma sfilter_conc2[simp]: assumes \"#(sfilter A\\<cdot>s2) = \\<infinity>\" and \"#s1 < \\<infinity>\"\n  shows \"#(sfilter A\\<cdot>(s1\\<bullet>s2)) = \\<infinity>\"\nproof -\n  have \"(sfilter A\\<cdot>(s1\\<bullet>s2)) = ((sfilter A\\<cdot>s1) \\<bullet> (sfilter A\\<cdot>s2))\"\n    using add_sfilter assms(2) lnless_def ninf2Fin by fastforce \n  thus ?thesis by (simp add: assms(1) slen_sconc_snd_inf) \nqed\n\n(* if the stream z is a prefix of another non-empty stream (y\\<bullet>\\<up>a) but isn't equal to it, then z is\n   also a prefix of y *)\nlemma below_conc: assumes \"z \\<sqsubseteq> (y\\<bullet>\\<up>a)\" and \"z\\<noteq>(y\\<bullet>\\<up>a)\"\n  shows \"z\\<sqsubseteq>y\"\nproof(cases \"#y = \\<infinity>\")\n  case True thus ?thesis using assms(1) sconc_fst_inf by auto  \nnext\n  case False \n  obtain n_y where \"Fin n_y= #y\" using False ninf2Fin by fastforce\n  have \"#z \\<le> #(y\\<bullet>\\<up>a)\" using assms(1) mono_slen by blast\n  have \"#z \\<noteq> #(y\\<bullet>\\<up>a)\" using assms(1) assms(2) eq_slen_eq_and_less by blast\n  hence \"#z < #(y\\<bullet>\\<up>a)\" using \\<open>#z \\<le> #(y \\<bullet> \\<up>a)\\<close> lnle_def lnless_def by blast \n  obtain n_z where nz_def: \"Fin n_z = #z\" using approxl2 assms(1) assms(2) by blast \n  have \"#y < #(y \\<bullet> \\<up>a)\"\n    by (metis \\<open>Fin n_y = #y\\<close> eq_slen_eq_and_less inject_sconc lnless_def minimal monofun_cfun_arg sconc_snd_empty stream.con_rews(2) sup'_def up_defined)\n  have \"#y < \\<infinity>\" by (simp add: False lnless_def) \n  hence \"Fin n_z \\<le> #y\" by (metis Fin_Suc \\<open>#z < #(y \\<bullet> \\<up>a)\\<close> less2lnleD lnsuc_lnle_emb nz_def slen_lnsuc) \n  have \"\\<And>s. stake n_y\\<cdot>(y \\<bullet> s) = y\" by (simp add: \\<open>Fin n_y = #y\\<close> approxl1)\n  hence \"stake n_z\\<cdot>y = stake n_z\\<cdot>(y\\<bullet>\\<up>a)\" by (metis \\<open>Fin n_y = #y\\<close> \\<open>Fin n_z \\<le> #y\\<close> less2nat min_def stakeostake)\n  thus ?thesis by (metis \\<open>Fin n_z = #z\\<close> approxl1 assms(1) stream.take_below) \nqed\n\n(* for any set A and singleton stream \\<up>a the following predicate over streams is admissible *)\nlemma sfilter_conc_adm: \"adm (\\<lambda>b. #b<\\<infinity> \\<longrightarrow> #(A \\<ominus> b) < #(A \\<ominus> b \\<bullet> \\<up>a))\" (is \"adm ?F\")\nby (metis (mono_tags, lifting) admI inf_chainl4 lnless_def lub_eqI lub_finch2)\n\n(* the element a is kept when filtering with A, so (x \\<bullet> \\<up>a) produces a larger result than just x,\n   provided that x is finite *)\nlemma sfilter_conc: assumes \"a\\<in>A\" \n  shows \"#x<\\<infinity> \\<Longrightarrow> #(A \\<ominus> x) < #(A \\<ominus> (x \\<bullet> \\<up>a))\" (is \"_ \\<Longrightarrow> ?F x\")\n  proof(induction x)\n    show \"adm (\\<lambda>b. #b < \\<infinity> \\<longrightarrow> #(A \\<ominus> b) < #(A \\<ominus> b \\<bullet> \\<up>a))\" using sfilter_conc_adm by blast\n   show \"?F \\<epsilon>\" using assms(1) lnless_def by auto\n  next\n  fix u :: \"'a discr u\"\n  fix s :: \"'a stream\"\n  assume \"u\\<noteq>\\<bottom>\" and \"#s<\\<infinity> \\<Longrightarrow> ?F s\" and \"#(u && s) < \\<infinity>\"\n  obtain ua where \"(updis ua) = u\" by (metis \\<open>u \\<noteq> \\<bottom>\\<close> discr.exhaust upE)\n  hence \"u && s = \\<up>ua \\<bullet>s\" using lscons_conv by blast\n  thus \"?F (u&&s)\"\n  by (smt \\<open>#(u && s) < \\<infinity>\\<close> \\<open>#s < \\<infinity> \\<Longrightarrow> #(A \\<ominus> s) < #(A \\<ominus> s \\<bullet> \\<up>a)\\<close> assoc_sconc fold_inf lnat.sel_rews(2) lnless_def monofun_cfun_arg sfilter_in sfilter_nin slen_scons)\nqed\n\n(* for any finite stream s and set A, if filtering s with A doesn't produce the empty stream, then\n   filtering and infinite repetition are associative *)\nlemma sfilter_sinf [simp]: assumes \"#s<\\<infinity>\" and \"(A \\<ominus> s) \\<noteq> \\<epsilon>\"\n  shows \"A \\<ominus> (s\\<^sup>\\<infinity>) = ((A \\<ominus> s)\\<^sup>\\<infinity>)\"\nby (metis add_sfilter assms(1) assms(2) infI lnless_def rek2sinftimes sinftimes_unfold)\n\n(* if filtering the stream s with the set A produces infinitely many elements, then filtering the \n   rest of s with A also produces infinitely many elements *)\nlemma sfilter_srt_sinf [simp]: assumes \"#(A \\<ominus> s) = \\<infinity>\" \n  shows  \"#(A \\<ominus> (srt\\<cdot>s)) = \\<infinity>\"\nby (smt assms inf_scase inject_scons sfilter_in sfilter_nin stream.sel_rews(2) surj_scons) \n  \n(* additional snth--lemma *)\nlemma sfilter_ntimes [simp]: \"#({True} \\<ominus> ((sntimes n (\\<up>False))\\<bullet>ora2)) = #({True} \\<ominus> ora2)\"\n  apply(induction n)\n    by auto\n\n(* snth to sntimes *)\nlemma snth2sntimes: \"(\\<And>i. i<n \\<Longrightarrow> snth i s = False) \\<Longrightarrow> Fin n < #s \\<Longrightarrow> (sntimes n (\\<up>False)) \\<sqsubseteq> s\"\nproof(induction n arbitrary: s)\n  case 0\n  then show ?case by auto\nnext\n  case (Suc n)\n    have \"shd s = False\"\n      using Suc.prems snth_shd by blast\n     hence \"s = \\<up>False \\<bullet> (srt\\<cdot>s)\"\n       using Suc.prems(2) empty_is_shortest surj_scons by force\n    have \"(\\<And>i. i < n \\<Longrightarrow> snth i (srt\\<cdot>s) = False)\"\n      using Suc.prems snth_rt by auto\n     hence \"n\\<star>\\<up>False \\<sqsubseteq> (srt\\<cdot>s)\"\n       by (meson Suc.IH Suc.prems(2) linorder_not_le slen_rt_ile_eq)\n     hence \"\\<up>False \\<bullet> (n\\<star>\\<up>False) \\<sqsubseteq> \\<up>False \\<bullet> (srt\\<cdot>s)\"\n       by (simp add: monofun_cfun_arg)\n     then show ?case\n       using \\<open>s = \\<up>False \\<bullet> srt\\<cdot>s\\<close> by auto\nqed  \n\n(* length of sntimes *)\nlemma sntimes_len [simp]: \"#(n\\<star>\\<up>a) = Fin n\"\n  apply(induction n)\n  by auto\n\n(* if length of a stream is Fin n, then snth (n+m) (xs\\<bullet>ys) is equal to snth m ys *)\nlemma snth_scons2: assumes \"#xs = Fin n\"\n  shows \"snth (n+m) (xs\\<bullet>ys) = snth m ys\"\n  apply(simp add: snth_def)\n  by (simp add: add.commute assms sdrop_plus sdropl6)\n\n(* if ({True} \\<ominus> s) is unequal to bottom, then (sntimes n (\\<up>False)) \\<bullet> \\<up>True is a prefix of s *)    \nlemma sbool_ntimes_f: assumes \"({True} \\<ominus> s) \\<noteq>\\<bottom>\"\n  obtains n where \"(sntimes n (\\<up>False)) \\<bullet> \\<up>True \\<sqsubseteq> s\"\nproof -\n  have h1: \"\\<exists>i. snth i s = True\"\n    by (metis assms ex_snth_in_sfilter_nempty singletonD)\n  obtain n where \"Fin n < #s\" and n_def: \"n = Least (\\<lambda>i. snth i s = True)\"\n    by (smt assms ex_snth_in_sfilter_nempty less2nat not_less not_less_Least not_less_iff_gr_or_eq singletonD trans_lnless)\n  have \"snth n s = True\"\n    using LeastI h1 n_def by force\n  have \"\\<And>i. i<n \\<Longrightarrow> snth i s \\<noteq> True\" using not_less_Least n_def by fastforce\n  hence\"\\<And>i. i<n \\<Longrightarrow> snth i s = False\" by auto      \n  hence \"(sntimes n (\\<up>False)) \\<sqsubseteq> s\"\n    using \\<open>Fin n < #s\\<close> snth2sntimes by blast\n  obtain xs where xs_def: \"s = (sntimes n (\\<up>False)) \\<bullet> xs\"\n    using \\<open>n\\<star>\\<up>False \\<sqsubseteq> s\\<close> approxl3 by auto\n  hence \"xs\\<noteq>\\<bottom>\"\n    by (metis assms sfilter_ntimes slen_empty_eq strict_sfilter)\n  have \"shd xs = snth n s\"\n    by (simp add: sdropl6 snth_def xs_def)\n  hence \"shd xs = True\"\n    using \\<open>snth n s = True\\<close> by auto   \n  thus ?thesis\n    by (metis (full_types)\\<open>xs \\<noteq> \\<epsilon>\\<close> lscons_conv minimal monofun_cfun_arg sup'_def surj_scons that xs_def)\n  qed\n\n(* ----------------------------------------------------------------------- *)\nsection \\<open>@{term sfoot}\\<close>\n(* ----------------------------------------------------------------------- *)\n\n(* appending the singleton stream \\<up>a to a finite stream s causes sfoot to extract a again *)\nlemma sfoot1[simp]: assumes \"xs = s\\<bullet>(\\<up>a)\" and \"#xs < \\<infinity>\"\n   shows \"sfoot xs = a\"\nproof -\n  have \"xs \\<noteq> \\<epsilon>\" using assms(1) strictI by force\n  obtain n where n_def: \"Fin n = #xs\" by (metis assms(2) lncases lnless_def) \n  hence \"n>0\" using assms(2) gr0I using Fin_02bot \\<open>xs \\<noteq> \\<epsilon>\\<close> lnzero_def slen_empty_eq by fastforce \n  hence \"(THE n'. lnsuc\\<cdot>(Fin n') = #xs) = n-1\" by (metis (mono_tags, lifting) Fin_Suc Suc_diff_1 n_def inject_Fin inject_lnsuc the_equality)\n  have \"snth (n-1) xs = a\" by (metis Fin_0 Fin_Suc Suc_diff_1 assms(1) n_def bot_is_0 inject_lnsuc lnat.con_rews lscons_conv neq0_conv sdropl6 shd1 slen_lnsuc snth_def sup'_def)\n  thus ?thesis by (metis \\<open>(THE n'. lnsuc\\<cdot>(Fin n') = #xs) = n - 1\\<close> sfoot_def)\nqed\n\n(* sfoot extracts the element a from any finite stream ending with \\<up>a *)\nlemma sfoot12 [simp]: assumes \"#s<\\<infinity>\"\n  shows \"sfoot (s\\<bullet>\\<up>a) = a\"\nby (metis assms fold_inf inject_lnsuc lnless_def monofun_cfun_arg sfoot1 slen_lnsuc)\n\n(* sfoot extracts a from the singleton stream \\<up>a *)\nlemma sfoot_one [simp]: \"sfoot (\\<up>a) = a\"\nby (metis Inf'_neq_0 inf_ub lnle_def lnless_def sconc_fst_empty sfoot12 strict_slen)\n\n(* concatenating finite streams produces another finite stream *)\nlemma sconc_slen [simp]: assumes \"#s<\\<infinity>\" and \"#xs<\\<infinity>\"\n  shows \"#(s\\<bullet>xs) < \\<infinity>\"\nby (metis Fin_neq_inf assms(1) assms(2) infI inf_ub lnle_def lnless_def slen_sconc_all_finite)\n\nlemma sconc_slen2: \"\\<And>(s1::'a stream) s2::'a stream. #(s1 \\<bullet> s2) = #s1 + #s2\"\nproof - \n  fix s1::\"'a stream\"\n  fix s2::\"'a stream\"\n\n  have \"#s1 = \\<infinity> \\<Longrightarrow> #(s1 \\<bullet> s2) = #s1 + #s2\"\n    by (simp add: plus_lnatInf_r)\n  moreover\n  have \"#s2 = \\<infinity> \\<Longrightarrow> #(s1 \\<bullet> s2) = #s1 + #s2\"\n    by (simp add: slen_sconc_snd_inf)\n  moreover\n  have \"#s1 \\<noteq> \\<infinity> \\<Longrightarrow> #s2 \\<noteq> \\<infinity> \\<Longrightarrow> #(s1 \\<bullet> s2) = #s1 + #s2\"\n  proof-\n    assume \"#s1 \\<noteq> \\<infinity>\"\n    then obtain l_s1 where l_s1_def: \"Fin l_s1 = #s1\"\n      using infI by metis\n    assume \" #s2 \\<noteq> \\<infinity>\"\n    then obtain l_s2 where l_s2_def: \"Fin l_s2 =  #s2\"\n      using infI by metis\n    show ?thesis\n      using l_s1_def l_s2_def by (metis lnat_plus_fin slen_sconc_all_finite)\n  qed\n\n  then show \"#(s1 \\<bullet> s2) = #s1 + #s2\"\n    using calculation by linarith\nqed\n\n(* if the foot of a non-empty stream xs is a, then xs consists of another stream s (possibly empty)\n   concatenated with \\<up>a *)\nlemma sfoot2 [simp]: assumes \"sfoot xs = a\" and \"xs\\<noteq>\\<epsilon>\"\n  shows \"\\<exists>s. xs = s \\<bullet> \\<up>a\"\nproof (cases \"#xs = \\<infinity>\")\n  case True thus ?thesis by (metis sconc_fst_inf) \nnext\n  case False \n  obtain n where \"#xs = Fin n\" using False lncases by auto\n  hence \"(THE n'. lnsuc\\<cdot>(Fin n') = #xs) = n-1\"\n    by (smt Fin_02bot Fin_Suc Suc_diff_1 assms(2) bot_is_0 inject_Fin inject_lnsuc neq0_conv slen_empty_eq the_equality)\n  have \"stake (n-1)\\<cdot>xs \\<bullet> \\<up>(snth (n-1) xs) = xs\"\n    by (smt Fin_0 Fin_Suc Inf'_def Suc_diff_1 \\<open>#xs = Fin n\\<close> assms(2) fin2stake fix_least_below lnle_def neq0_conv notinfI3 sconc_snd_empty sdrop_back_rt sdropostake slen_empty_eq snth_def split_streaml1 surj_scons ub_slen_stake)\n  thus ?thesis by (metis \\<open>(THE n'. lnsuc\\<cdot>(Fin n') = #xs) = n - 1\\<close> assms(1) sfoot_def) \nqed\n\n(* when sfoot is applied to the concatenation of two finite streams s and xs, and xs is not empty,\n   then sfoot will produce the foot of xs *)\nlemma sfoot_conc [simp]: assumes \"#s<\\<infinity>\" and \"#xs<\\<infinity>\" and \"xs\\<noteq>\\<epsilon>\"\n  shows \"sfoot (s\\<bullet>xs) = sfoot xs\"\nby (metis (no_types, hide_lams) assms(1) assms(2) assms(3) assoc_sconc sconc_slen sfoot1 sfoot2)\n\n(* if the finite stream s contains more than one element then the foot of s will be the foot of the\n   rest of s *)\nlemma sfoot_sdrop: assumes \"Fin 1<#s\" and \"#s<\\<infinity>\"\n  shows \"sfoot (srt\\<cdot>s) = sfoot s\"\nproof -\n  obtain s' where \"s = s' \\<bullet> \\<up>(sfoot s)\" by (metis assms(1) below_antisym bot_is_0 lnless_def minimal sfoot2 strict_slen)\n  hence \"s' \\<noteq> \\<epsilon>\"\n    by (metis Fin_02bot Fin_Suc One_nat_def assms(1) lnless_def lnzero_def slen_lnsuc strict_slen)\n  hence \"srt\\<cdot>s = srt\\<cdot>s' \\<bullet> \\<up>(sfoot s)\"\n    by (smt \\<open>s = s' \\<bullet> \\<up>(sfoot s)\\<close> assoc_sconc inject_scons sconc_snd_empty strictI surj_scons)\n  thus ?thesis\n    by (metis \\<open>s = s' \\<bullet> \\<up>(sfoot s)\\<close> \\<open>s' \\<noteq> \\<epsilon>\\<close> assms(2) inf_ub lnle_conv lnless_def sconc_snd_empty sfoot1 slen_sconc_snd_inf strictI surj_scons) \nqed\n\n(* if length of xs is finite, then it holds that sfoot (\\<up>a \\<bullet> \\<up>b \\<bullet> xs) = sfoot (\\<up>b \\<bullet> xs) *)\nlemma [simp]: assumes \"#xs < \\<infinity>\"\n  shows \"sfoot (\\<up>a \\<bullet> \\<up>b \\<bullet> xs) = sfoot (\\<up>b \\<bullet> xs)\"\nusing assms lnless_def by auto \n\n(* the foot of any stream s is the nth element of s for some natural number n *)\nlemma sfoot_exists [simp]:\"\\<exists>n. snth n s = sfoot s\"\nby (metis sfoot_def)\n\n(* if the stream s contains n+1 elements then the foot of s will be found at index n *)\nlemma  sfoot_exists2: \n  shows \"Fin (Suc n) = #s \\<Longrightarrow> snth n s = sfoot s\"\n  apply(induction n arbitrary: s)\n   apply (metis (mono_tags, lifting) Fin_02bot Fin_Suc Zero_lnless_infty inject_lnsuc lnzero_def sconc_fst_empty sconc_snd_empty sfoot12 slen_empty_eq slen_scons snth_shd surj_scons)\n  by (smt Fin_Suc Fin_neq_inf fold_inf inf_ub inject_lnsuc lnat.con_rews lnle_conv lnless_def lnzero_def sconc_snd_empty sfoot_conc slen_scons snth_rt strict_slen surj_scons)\n\ntext \\<open>Streams can be split for filtering\\<close>\nlemma add_sfilter2: assumes \"#x < \\<infinity>\" \n  shows \"sfilter A\\<cdot>(x \\<bullet> y) = sfilter A\\<cdot>x \\<bullet> sfilter A\\<cdot>y\"\nby (metis (no_types) add_sfilter assms lncases lnless_def)\n\n(* if lenght of s is Fin (Suc n), then it holds that (stake n\\<cdot>s) \\<bullet> \\<up>(sfoot s) = s *)\nlemma sfood_id: assumes\"#s = Fin (Suc n)\"\n  shows \"(stake n\\<cdot>s) \\<bullet> \\<up>(sfoot s) = s\"\n  using assms apply(induction n arbitrary: s)\n   apply simp\n   apply (metis Fin_02bot Fin_Suc lnat.sel_rews(2) lnsuc_neq_0_rev lnzero_def lscons_conv sfoot_exists2 slen_scons snth_shd strict_slen sup'_def surj_scons)\n  apply (subst stake_suc)\n  apply simp\n  by (smt Fin_02bot Fin_Suc One_nat_def Rep_cfun_strict1 Zero_not_Suc leI lnat.sel_rews(2) lnle_Fin_0 lnzero_def notinfI3 sconc_snd_empty sfoot_sdrop slen_rt_ile_eq slen_scons stake_Suc stream.take_0 strict_slen surj_scons)\n\nlemma footind: \"#s = Fin k \\<Longrightarrow> P \\<epsilon> \\<Longrightarrow> (\\<And>t a. #t < \\<infinity> \\<Longrightarrow> P t \\<Longrightarrow> P (t \\<bullet> \\<up>a)) \\<Longrightarrow> P s\"\nproof -\n  assume \"#s = Fin k\" and \"P \\<epsilon>\" and \"\\<And>t a. #t < \\<infinity> \\<Longrightarrow> P t \\<Longrightarrow> P (t \\<bullet> \\<up>a)\"\n  then show \"P s\"\n  proof (induction k arbitrary: s rule: less_induct)\n    case (less k)\n    then have IH: \"\\<And>t. #t < Fin k \\<Longrightarrow> P \\<epsilon> \\<Longrightarrow> (\\<And>u b. #u < \\<infinity> \\<Longrightarrow> P u \\<Longrightarrow> P (u \\<bullet> \\<up>b)) \\<Longrightarrow> P t\"\n      by (meson lnat_well_h1)\n    then show ?case\n    proof (cases \"k = 0\")\n      case True\n      then show ?thesis\n        using less.prems(1) less.prems(2) by force\n    next\n      case False\n      then obtain u b where \"s = u \\<bullet> \\<up>b\"\n        using less.prems(1) sfoot2 by force\n      then have \"#u < Fin k\"\n        by (metis fold_inf leI less.prems(1) ln_less lnsuc_lnle_emb notinfI3 slen_lnsuc)\n      then show ?thesis\n        by (metis IH \\<open>s = u \\<bullet> \\<up>b\\<close> inf_ub less.prems(2) less.prems(3) less_le not_less)\n    qed\n  qed\nqed\n\nlemma footind2: \"#s < \\<infinity> \\<Longrightarrow> P \\<epsilon> \\<Longrightarrow> (\\<And>t a. #t < \\<infinity> \\<Longrightarrow> P t \\<Longrightarrow> P (t \\<bullet> \\<up>a)) \\<Longrightarrow> P s\"\n  by (metis footind infI less_le)\n\nlemma srcdups_sfoot:\n  \"s \\<noteq> \\<epsilon> \\<Longrightarrow> #s < \\<infinity> \\<Longrightarrow> sfoot (srcdups\\<cdot>s) = sfoot s\"\nproof (rule footind2, simp+)\n  fix t :: \"'a stream\" and a :: 'a\n  assume \"#t < \\<infinity>\" and \"sfoot (srcdups\\<cdot>t) = sfoot t\"\n  show \"sfoot (srcdups\\<cdot>(t \\<bullet> \\<up>a)) = a\"\n  proof (rule footind2 [of t], auto, simp add: \\<open>#t < \\<infinity>\\<close>)\n    fix t :: \"'a stream\" and b :: 'a\n    assume \"#t < \\<infinity>\" and \"sfoot (srcdups\\<cdot>(t \\<bullet> \\<up>a)) = a\"\n    then show \"sfoot (srcdups\\<cdot>(t \\<bullet> \\<up>b \\<bullet> \\<up>a)) = a\"\n    proof -\n      have \"\\<And>l. l < \\<infinity> \\<or> l = \\<infinity>\"\n        by (meson inf_less_eq le_less_linear)\n      then show ?thesis\n        by (metis (no_types) Fin_Suc \\<open>#t < \\<infinity>\\<close> \\<open>sfoot (srcdups\\<cdot>(t \\<bullet> \\<up>a)) = a\\<close> lnat_well_h2 notinfI3 sfoot12 slen_lnsuc srcdups_end_eq srcdups_end_neq srcdups_slen)\n    qed\n  qed\nqed\n\nlemma sfoot_end:\n  fixes s and a\n  assumes \"#s < \\<infinity>\" and \"s \\<noteq> \\<epsilon>\"\n  shows \"\\<exists>t n. s = t \\<bullet> (sntimes n (\\<up>(sfoot s))) \\<and> (t = \\<epsilon> \\<or> sfoot s \\<noteq> sfoot t)\"\n  apply (rule footind2)\n  apply (simp add: assms(1))\n   apply (metis sconc_fst_empty sntimes.simps(1))\nproof -\n  fix t :: \"'a stream\" and a :: 'a\n  assume \"#t < \\<infinity>\" and \"\\<exists>ta n. t = ta \\<bullet> (sntimes n (\\<up>(sfoot t))) \\<and> (ta = \\<epsilon> \\<or> sfoot t \\<noteq> sfoot ta)\"\n  then obtain u n where \"t = u \\<bullet> (sntimes n (\\<up>(sfoot t)))\" and \"u = \\<epsilon> \\<or> sfoot t \\<noteq> sfoot u\"\n    by blast\n  then have expr: \"t \\<bullet> \\<up>a = u \\<bullet> (sntimes n (\\<up>(sfoot t))) \\<bullet> \\<up>a\"\n    by (metis assoc_sconc)\n  then show \"\\<exists>ta n. ((t \\<bullet> \\<up>a) =(ta \\<bullet> (n\\<star>(\\<up>(sfoot (t \\<bullet> \\<up>a)))))) \\<and> ((ta = \\<epsilon>) \\<or> (sfoot (t \\<bullet> \\<up>a) \\<noteq> sfoot ta))\"\n  proof (cases \"a = sfoot t\")\n    case True\n    then have \"t \\<bullet> \\<up>a = u \\<bullet> (sntimes (Suc n) (\\<up>(sfoot t)))\"\n      by (metis expr sntimes_Suc2)\n    then show ?thesis\n      by (metis True \\<open>#t < \\<infinity>\\<close> \\<open>u = \\<epsilon> \\<or> sfoot t \\<noteq> sfoot u\\<close> sfoot12)\n  next\n    case False\n    then have \"t \\<bullet> \\<up>a = (u \\<bullet> (sntimes n (\\<up>(sfoot t)))) \\<bullet> (sntimes (Suc 0) (\\<up>(sfoot (t \\<bullet> \\<up>a))))\"\n      using \\<open>#t < \\<infinity>\\<close> \\<open>t = u \\<bullet> (n\\<star>\\<up>(sfoot t))\\<close> by auto\n    then show ?thesis\n      by (metis False \\<open>#t < \\<infinity>\\<close> \\<open>t = u \\<bullet> (n\\<star>\\<up>(sfoot t))\\<close> sfoot12)\n  qed\nqed\n\nlemma srcdups_split_fin: \"#s = Fin k \\<Longrightarrow> Suc n < k \\<Longrightarrow> snth n s \\<noteq> snth (Suc n) s \\<Longrightarrow> srcdups\\<cdot>s = srcdups\\<cdot>(stake (Suc n)\\<cdot>s) \\<bullet> (srcdups\\<cdot>(sdrop (Suc n)\\<cdot>s))\"\nproof (induction k arbitrary: n s)\n  case 0\n  then show ?case\n    by auto\nnext\n  case (Suc k)\n  then obtain a t where \"s = \\<up>a \\<bullet> t\"\n    by (metis Fin_0 Suc_neq_Zero strict_slen surj_scons)\n  assume \"snth n s \\<noteq> snth (Suc n) s\"\n  then have \"Suc n < Suc k\"\n    using Suc.prems(2) by blast\n  then show ?case\n  proof (cases \"k > 1\")\n    case True\n    then obtain a b t where \"s = \\<up>a \\<bullet> \\<up>b \\<bullet> t\"\n    proof -\n      assume a1: \"\\<And>a b t. s = \\<up>a \\<bullet> \\<up>b \\<bullet> t \\<Longrightarrow> thesis\"\n      have \"#(\\<epsilon>::'a stream) = \\<bottom>\"\n        using bot_is_0 by auto\n      then show ?thesis\n        using a1 by (metis Fin_Suc Suc.prems(1) True inject_lnsuc less2nat_lemma lnat.con_rews lnle_def minimal not_le srt_decrements_length surj_scons)\n    qed\n    then have \"t \\<noteq> \\<epsilon>\"\n      using Suc.prems(1) True by force\n    then show ?thesis\n    proof (cases \"n = 0\")\n      case True\n      then have \"a \\<noteq> b\"\n        using Suc.prems(3) \\<open>s = \\<up>a \\<bullet> \\<up>b \\<bullet> t\\<close> by auto\n      then show ?thesis\n        using True \\<open>s = \\<up>a \\<bullet> \\<up>b \\<bullet> t\\<close> by auto\n    next\n      case False\n      then obtain m where \"n = Suc m\"\n        using not0_implies_Suc by blast\n      have \"#(\\<up>b \\<bullet> t) = Fin k\"\n        using Suc.prems(1) \\<open>s = \\<up>a \\<bullet> \\<up>b \\<bullet> t\\<close> by auto\n      moreover have \"snth n s = snth m (\\<up>b \\<bullet> t)\"\n        by (simp add: \\<open>n = Suc m\\<close> \\<open>s = \\<up>a \\<bullet> \\<up>b \\<bullet> t\\<close>)\n      ultimately have \"srcdups\\<cdot>(\\<up>b \\<bullet> t) = srcdups\\<cdot>(stake n\\<cdot>(\\<up>b \\<bullet> t)) \\<bullet> (srcdups\\<cdot>(sdrop n\\<cdot>(\\<up>b \\<bullet> t)))\"\n        by (metis Suc.IH Suc.prems(2) Suc.prems(3) Suc_less_SucD \\<open>n = Suc m\\<close> \\<open>s = \\<up>a \\<bullet> \\<up>b \\<bullet> t\\<close> snth_scons)\n      then show ?thesis\n      proof (cases \"srcdups\\<cdot>s = srcdups\\<cdot>(\\<up>b \\<bullet> t)\")\n        case True\n        then show ?thesis\n        proof -\n          have \"a = b\"\n            by (metis (no_types) True \\<open>s = \\<up>a \\<bullet> \\<up>b \\<bullet> t\\<close> srcdups_shd)\n          then show ?thesis\n            by (simp add: \\<open>n = Suc m\\<close> \\<open>s = \\<up>a \\<bullet> \\<up>b \\<bullet> t\\<close> \\<open>srcdups\\<cdot>(\\<up>b \\<bullet> t) = srcdups\\<cdot> (stake n\\<cdot> (\\<up>b \\<bullet> t)) \\<bullet> srcdups\\<cdot> (sdrop n\\<cdot>(\\<up>b \\<bullet> t))\\<close>)\n        qed\n      next\n        case False\n        then show ?thesis\n        proof -\n          have \"a \\<noteq> b\"\n            using False \\<open>s = \\<up>a \\<bullet> \\<up>b \\<bullet> t\\<close> srcdups_eq2 by blast\n          then show ?thesis\n            by (simp add: \\<open>n = Suc m\\<close> \\<open>s = \\<up>a \\<bullet> \\<up>b \\<bullet> t\\<close> \\<open>srcdups\\<cdot>(\\<up>b \\<bullet> t) = srcdups\\<cdot> (stake n\\<cdot> (\\<up>b \\<bullet> t)) \\<bullet> srcdups\\<cdot> (sdrop n\\<cdot>(\\<up>b \\<bullet> t))\\<close>)\n        qed\n      qed\n    qed\n  next\n    case False\n    then have \"k \\<le> 1\"\n      by auto\n    then show ?thesis\n    proof (cases \"k = 0\")\n      case True\n      then show ?thesis\n        using Suc.prems(2) by blast\n    next\n      case False\n      then have \"k = 1\"\n        using \\<open>k \\<le> 1\\<close> by auto\n      then obtain a b where \"s = \\<up>a \\<bullet> \\<up>b\"\n        by (metis One_nat_def Rep_cfun_strict1 Suc.prems(1) \\<open>\\<And>thesis. (\\<And>a t. s = \\<up>a \\<bullet> t \\<Longrightarrow> thesis) \\<Longrightarrow> thesis\\<close> sconc_snd_empty sfood_id stake_Suc stream.take_0)\n      then have \"a \\<noteq> b\"\n        using Suc.prems(2) Suc.prems(3) \\<open>k = 1\\<close> by auto\n      then have \"srcdups\\<cdot>s = \\<up>a \\<bullet> \\<up>b\"\n        by (metis \\<open>s = \\<up>a \\<bullet> \\<up>b\\<close> lscons_conv srcdups_neq srcdups_step strict_sdropwhile strict_srcdups sup'_def)\n      then show ?thesis\n        using Suc.prems(2) \\<open>k = 1\\<close> \\<open>s = \\<up>a \\<bullet> \\<up>b\\<close> by auto\n    qed\n  qed\nqed\n\nlemma srcdups_split_inf: \"#s = \\<infinity> \\<Longrightarrow> snth n s \\<noteq> snth (Suc n) s \\<Longrightarrow> srcdups\\<cdot>s = srcdups\\<cdot>(stake (Suc n)\\<cdot>s) \\<bullet> (srcdups\\<cdot>(sdrop (Suc n)\\<cdot>s))\"\nproof (induction n arbitrary: s)\n  case 0\n  then obtain a b t where \"s = \\<up>a \\<bullet> \\<up>b \\<bullet> t\" and \"a \\<noteq> b\"\n    by (metis inf_scase shd1 snth_scons snth_shd)\n  then show ?case\n    by auto\nnext\n  case (Suc n)\n  obtain a t where \"s = \\<up>a \\<bullet> t\"\n    using Suc.prems(1) inf_scase by blast\n  then have \"#t = \\<infinity>\"\n    using Suc.prems(1) by auto\n  moreover have \"snth n t \\<noteq> snth (Suc n) t\"\n    using Suc.prems(2) \\<open>s = \\<up>a \\<bullet> t\\<close> by auto\n  ultimately have \"srcdups\\<cdot>t = srcdups\\<cdot>(stake (Suc n)\\<cdot>t) \\<bullet> (srcdups\\<cdot>(sdrop (Suc n)\\<cdot>t))\"\n    using Suc.IH by blast\n  then show ?case\n  proof (cases \"a = shd t\")\n    case True\n    then have \"srcdups\\<cdot>s = srcdups\\<cdot>t\"\n      by (metis Inf'_neq_0 \\<open>#t = \\<infinity>\\<close> \\<open>s = \\<up>a \\<bullet> t\\<close> slen_empty_eq srcdups_eq surj_scons)\n    then show ?thesis\n      using True \\<open>#t = \\<infinity>\\<close> \\<open>s = \\<up>a \\<bullet> t\\<close> \\<open>srcdups\\<cdot>t = srcdups\\<cdot> (stake (Suc n)\\<cdot>t) \\<bullet> srcdups\\<cdot>(sdrop (Suc n)\\<cdot>t)\\<close> inf_scase by fastforce\n  next\n    case False\n    then have \"srcdups\\<cdot>s = \\<up>a \\<bullet> srcdups\\<cdot>t\"\n      by (metis Inf'_neq_0 \\<open>#t = \\<infinity>\\<close> \\<open>s = \\<up>a \\<bullet> t\\<close> slen_empty_eq srcdups_neq surj_scons)\n    then show ?thesis\n      using False \\<open>#t = \\<infinity>\\<close> \\<open>s = \\<up>a \\<bullet> t\\<close> \\<open>srcdups\\<cdot>t = srcdups\\<cdot> (stake (Suc n)\\<cdot>t) \\<bullet> srcdups\\<cdot>(sdrop (Suc n)\\<cdot>t)\\<close> inf_scase by fastforce\n  qed\nqed\n\nlemma srcdups_split2: \"Fin (Suc n) < #s \\<Longrightarrow> snth n s \\<noteq> snth (Suc n) s \\<Longrightarrow> srcdups\\<cdot>s = srcdups\\<cdot>(stake (Suc n)\\<cdot>s) \\<bullet> (srcdups\\<cdot>(sdrop (Suc n)\\<cdot>s))\"\n  by (metis less2nat ninf2Fin not_le srcdups_split_fin srcdups_split_inf)\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term sValues}\\<close>\n(* ----------------------------------------------------------------------- *)\n\n(* sValues equality rule *)\nlemma sValues_eq: \"{z. \\<exists>n. Fin n < #s \\<and> z = snth n s} = {snth n s |n. Fin n < #s}\"\nby auto\n\n(* another sValues equality rule *)\nlemma sValues_eq2: \"{snth n s |n. Fin n < #s} = {z. \\<exists>n. Fin n < #s \\<and> z = snth n s}\"\nby auto\n\ntext \\<open>A stream and its prefix agree on their first elements\\<close>\nlemma snth_less: \"\\<lbrakk>Fin n < #x; x \\<sqsubseteq> y\\<rbrakk> \\<Longrightarrow> snth n x = snth n y\"\napply (simp add: atomize_imp)\napply (rule_tac x=\"x\" in spec)\napply (rule_tac x=\"y\" in spec)\napply (induct_tac n, auto)\nby (drule lessD, auto)+\n\nlemma slen_snth_prefix: \"#s > Fin n \\<Longrightarrow> snth n s = snth n (s \\<bullet> t)\"\n  by (simp add: monofun_cfun_arg snth_less)\n\nlemma srcdups_sconc: \n  \"#xs < \\<infinity> \\<Longrightarrow> xs \\<noteq> \\<epsilon> \\<Longrightarrow> \n    srcdups\\<cdot>(xs \\<bullet> ys) = (srcdups\\<cdot>xs) \\<bullet> (srcdups\\<cdot>(sdropwhile (\\<lambda>x. x=sfoot xs)\\<cdot>ys))\"\nproof -\n  assume \"#xs < \\<infinity>\" and \"xs \\<noteq> \\<epsilon>\"\n  then obtain t n where \"xs = t \\<bullet> (sntimes n (\\<up>(sfoot xs)))\" and \"t = \\<epsilon> \\<or> sfoot t \\<noteq> sfoot xs\"\n    using sfoot_end by fastforce\n  then show ?thesis\n  proof (cases \"t = \\<epsilon>\")\n    case True\n    then have \"xs \\<bullet> ys = (sntimes n (\\<up>(sfoot xs))) \\<bullet> ys\"\n      using \\<open>xs = t \\<bullet> (n\\<star>\\<up>(sfoot xs))\\<close> by auto\n    then have \"srcdups\\<cdot>(xs \\<bullet> ys) = (\\<up>(sfoot xs)) \\<bullet> srcdups\\<cdot>(sdropwhile (\\<lambda>x. x=sfoot xs)\\<cdot>ys)\"\n      by (metis Fin_02bot True \\<open>xs = t \\<bullet>( n\\<star>\\<up>(sfoot xs))\\<close> \\<open>xs \\<noteq> \\<epsilon>\\<close> lnzero_def neq0_conv sconc_fst_empty slen_empty_eq sntimes_len srcdups_sntimes_prefix)\n    then show ?thesis\n      by (metis Fin_02bot True \\<open>xs = t \\<bullet> (n\\<star>\\<up>(sfoot xs))\\<close> \\<open>xs \\<noteq> \\<epsilon>\\<close> lnzero_def neq0_conv sconc_fst_empty slen_empty_eq sntimes_len srcdups_sntimes)\n  next\n    case False\n    then obtain k where \"#t = Fin (Suc k)\"\n      by (metis Fin_02bot \\<open>t = \\<epsilon> \\<or> sfoot t \\<noteq> sfoot xs\\<close> \\<open>xs = t \\<bullet> (n\\<star>\\<up>(sfoot xs))\\<close> bot_is_0 ninf2Fin not0_implies_Suc sconc_fst_inf slen_empty_eq)\n    then show ?thesis\n    proof (cases \"ys = \\<epsilon>\")\n      case True\n      then show ?thesis\n        by simp\n    next\n      case False\n      have \"snth k (xs \\<bullet> ys) \\<noteq> snth (Suc k) (xs \\<bullet> ys)\"\n      proof\n        assume \"snth k (xs \\<bullet> ys) = snth (Suc k) (xs \\<bullet> ys)\"\n        then have \"snth k xs = snth (Suc k) xs\"\n          by (metis Fin_02bot Fin_Suc Suc_neq_Zero \\<open>#t = Fin (Suc k)\\<close> \\<open>#xs < \\<infinity>\\<close> \\<open>t = \\<epsilon> \\<or> sfoot t \\<noteq> sfoot xs\\<close> \\<open>xs = t \\<bullet> (n\\<star>\\<up>(sfoot xs))\\<close> stake_prefix slen_snth_prefix inject_Fin le2lnle leI less_le lnless_def lnzero_def monofun_cfun_arg notinfI3 sfoot_exists2 stream.take_below strict_slen)\n        then show \"False\"\n          by (metis Fin_02bot Fin_Suc Suc_neq_Zero \\<open>#t = Fin (Suc k)\\<close> \\<open>t = \\<epsilon> \\<or> sfoot t \\<noteq> sfoot xs\\<close> \\<open>xs = t \\<bullet> (n\\<star>\\<up>(sfoot xs))\\<close> slen_snth_prefix inject_Fin leI ln_less lnzero_def neq0_conv notinfI3 sconc_snd_empty sdropl6 sfoot_exists2 shd_sntime slen_empty_eq snth_def sntimes_len)\n      qed\n      moreover have \"Fin (Suc k) < #(xs \\<bullet> ys)\"\n        by (metis False \\<open>#t = Fin (Suc k)\\<close> \\<open>#xs < \\<infinity>\\<close> \\<open>xs = t \\<bullet> (n\\<star>\\<up>(sfoot xs))\\<close> minimal mono_slen monofun_cfun_arg sconc_snd_empty slen_conc)\n      ultimately have \"srcdups\\<cdot>(xs \\<bullet> ys) = srcdups\\<cdot>(stake (Suc k)\\<cdot>(xs \\<bullet> ys)) \\<bullet> srcdups\\<cdot>(sdrop (Suc k)\\<cdot>(xs \\<bullet> ys))\"\n        using srcdups_split2 by blast\n      then have \"srcdups\\<cdot>(xs \\<bullet> ys) = srcdups\\<cdot>t \\<bullet> srcdups\\<cdot>((sntimes n (\\<up>(sfoot xs))) \\<bullet> ys)\"\n        by (metis \\<open>#t = Fin (Suc k)\\<close> \\<open>xs = t \\<bullet> (n\\<star>\\<up>(sfoot xs))\\<close> assoc_sconc stake_prefix2 sdropl6)\n      then have \"srcdups\\<cdot>(xs \\<bullet> ys) = srcdups\\<cdot>t \\<bullet> \\<up>(sfoot xs) \\<bullet> srcdups\\<cdot>(sdropwhile (\\<lambda>x. x=sfoot xs)\\<cdot>ys)\"\n        by (metis \\<open>t = \\<epsilon> \\<or> sfoot t \\<noteq> sfoot xs\\<close> \\<open>xs = t \\<bullet> (n\\<star>\\<up>(sfoot xs))\\<close> \\<open>xs \\<noteq> \\<epsilon>\\<close> neq0_conv sconc_snd_empty sntimes.simps(1) srcdups_sntimes_prefix)\n      moreover have \"srcdups\\<cdot>xs = srcdups\\<cdot>t \\<bullet> \\<up>(sfoot xs)\"\n      proof -\n        have \"srcdups\\<cdot>xs = srcdups\\<cdot>t \\<bullet> srcdups\\<cdot>(sntimes n (\\<up>(sfoot xs)))\"\n          by (metis \\<open>#t = Fin (Suc k)\\<close> \\<open>snth k (xs \\<bullet> ys) \\<noteq> snth (Suc k) (xs \\<bullet> ys)\\<close> \\<open>xs = t \\<bullet> (n\\<star>\\<up>(sfoot xs))\\<close> convert_inductive_asm slen_snth_prefix stake_prefix2 not_less notinfI3 sconc_snd_empty sdropl6 slen_conc srcdups_split2 strict_srcdups ub_slen_stake)\n        then show ?thesis\n          by (metis \\<open>t = \\<epsilon> \\<or> sfoot t \\<noteq> sfoot xs\\<close> \\<open>xs = t \\<bullet> (n\\<star>\\<up>(sfoot xs))\\<close> \\<open>xs \\<noteq> \\<epsilon>\\<close> neq0_conv sconc_snd_empty sntimes.simps(1) srcdups_sntimes)\n      qed\n      ultimately show ?thesis\n        by simp\n    qed\n  qed\nqed\n\ntext \\<open>monotonicity of @{term sValues}\\<close>\nlemma sValues_mono: \"monofun (\\<lambda>s. {snth n s |n. Fin n < #s})\"\napply (simp add: sValues_eq2)\napply (rule monofunI)\napply (rule_tac x=\"#x\" in lncases)\napply (drule eq_less_and_fst_inf, simp+)\napply (simp add: atomize_imp)\napply (rule_tac x=\"y\" in spec)\napply (rule_tac x=\"x\" in spec)\napply (induct_tac k, simp+)\napply (auto simp add: less_set_def)\napply (drule lessD, auto)\napply (erule_tac x=\"q\" in allE)\napply (erule_tac x=\"w\" in allE, auto)\napply (case_tac \"na\", auto)\napply (rule_tac x=\"0\" in exI, auto)\napply (frule_tac f=\"slen\" in monofun_cfun_arg, simp)\napply (rule_tac x=\"Suc nat\" in exI, auto)\napply (rule_tac x=\"#w\" in lncases, auto)\nby (rule snth_less, auto)\n\ntext \\<open>In infinite chains, the length of the streams is unbounded\\<close>\nlemma inf_chainl3rf:\n  \"\\<lbrakk>chain Y; \\<not>finite_chain Y\\<rbrakk> \\<Longrightarrow> \\<exists>k. Fin n \\<le> #(Y k)\"\nby (rule inf_chainl3 [rule_format], auto)\n\ntext \\<open>@{term sValues} is a continuous function\\<close>\nlemma sValues_cont: \"cont (\\<lambda>s. {snth n s | n. Fin n < #s})\"\napply (rule contI2)\napply (rule sValues_mono)\napply (simp add: sValues_eq2)\napply (rule allI, rule impI)\napply (simp add: less_set_def)\napply (auto simp add: lub_eq_Union) \napply (case_tac \"finite_chain Y\")\napply (subst lub_finch2 [THEN lub_eqI], simp)\napply (rule_tac x=\"LEAST i. max_in_chain i Y\" in exI)\napply (rule_tac x=\"n\" in exI, simp)\napply (subst lub_finch2 [THEN lub_eqI, THEN sym], simp+)\napply (frule_tac n=\"Suc n\" in inf_chainl3rf, simp+)\napply (erule exE)\napply (rule_tac x=\"k\" in exI)\napply (rule_tac x=\"n\" in exI)\napply (rule conjI)\napply (rule_tac x=\"#(Y k)\" in lncases, simp+)\napply (rule sym)\napply (rule snth_less)\napply (rule_tac x=\"#(Y k)\" in lncases, simp+)\nby (rule is_ub_thelub)\n\ntext \\<open>@{term sValues} is a continuous function\\<close>\nlemma sValues_def2: \"sValues\\<cdot>s = {snth n s | n. Fin n < #s}\"\napply (subst sValues_def)\napply (subst beta_cfun)\nby (rule sValues_cont, simp)\n\n(* continuity of sValues *)\nlemma sValues_cont2: \"\\<forall>Y. chain Y \\<longrightarrow> sValues\\<cdot>(\\<Squnion> i. Y i) = (\\<Squnion> i. sValues\\<cdot>(Y i))\"\nby (simp add: contlub_cfun_arg)\n\nlemma srcdups_bool_prefix:\n  fixes xs :: \"bool stream\" and ys :: \"bool stream\"\n  assumes \"lshd\\<cdot>(srcdups\\<cdot>xs) = lshd\\<cdot>(srcdups\\<cdot>ys)\" and \"#(srcdups\\<cdot>xs) \\<le> #(srcdups\\<cdot>ys)\"\n  shows \"(srcdups\\<cdot>xs) \\<sqsubseteq> (srcdups\\<cdot>ys)\"\nproof (rule scases [of xs])\n  assume \"xs = \\<epsilon>\"\n  then have \"srcdups\\<cdot>xs = \\<epsilon>\"\n    by simp\n  thus \"srcdups\\<cdot>xs \\<sqsubseteq> srcdups\\<cdot>ys\"\n    by simp\nnext\n  fix a :: bool and s :: \"bool stream\"\n  assume \"xs = \\<up>a \\<bullet> s\"\n  have \"lshd\\<cdot>(srcdups\\<cdot>ys) = updis a\"\n    by (metis \\<open>xs = \\<up>a \\<bullet> s\\<close> assms(1) lshd_updis srcdups_step)\n  then have \"lshd\\<cdot>ys = updis a\"\n    by (metis lshd_updis srcdups_shd2 stream.sel_rews(3) strict_srcdups surj_scons up_defined)\n  then have \"\\<forall>n. Fin n < #(srcdups\\<cdot>ys) \\<longrightarrow> snth n (srcdups\\<cdot>ys) = (even n = a)\"\n    by (metis (no_types, lifting) bool_stream_snth lshd_updis stream.sel_rews(3) sup'_def surj_scons)\n  then have ys_expr: \"\\<forall>n. Fin n < #(srcdups\\<cdot>xs) \\<longrightarrow> snth n (srcdups\\<cdot>ys) = (even n = a)\"\n    using assms(2) less_le_trans by blast\n  then have first_n_eq: \"\\<forall>n. Fin n < #(srcdups\\<cdot>xs) \\<longrightarrow> snth n (srcdups\\<cdot>xs) = snth n (srcdups\\<cdot>ys)\"\n    using \\<open>xs = \\<up>a \\<bullet> s\\<close> bool_stream_snth by blast\n  then show \"srcdups\\<cdot>xs \\<sqsubseteq> srcdups\\<cdot>ys\"\n  proof (cases \"#(srcdups\\<cdot>xs) < \\<infinity>\")\n    case False\n    then have \"#(srcdups\\<cdot>xs) = #(srcdups\\<cdot>ys)\"\n      using assms(2) less_le by fastforce\n    then have \"\\<forall>k. snth k (srcdups\\<cdot>xs) = snth k (srcdups\\<cdot>ys)\"\n      by (metis False Fin_neq_inf first_n_eq inf_ub order.not_eq_order_implies_strict)\n    then have \"srcdups\\<cdot>xs = srcdups\\<cdot>ys\"\n      by (simp add: \\<open>\\<forall>k. snth k (srcdups\\<cdot>xs) = snth k (srcdups\\<cdot>ys)\\<close> \\<open>#(srcdups\\<cdot>xs) = #(srcdups\\<cdot>ys)\\<close> snths_eq)\n    thus \"srcdups\\<cdot>xs \\<sqsubseteq> srcdups\\<cdot>ys\"\n      by simp\n  next\n    case True\n    then obtain k where \"#(srcdups\\<cdot>xs) = Fin k\"\n      using lnat_well_h2 by blast\n    then have eq_len: \"#(srcdups\\<cdot>xs) = #(stake k\\<cdot>(srcdups\\<cdot>ys))\"\n      using assms(2) slen_stake by force\n    have \"\\<forall>n. Fin n < #(srcdups\\<cdot>xs) \\<longrightarrow> snth n (srcdups\\<cdot>xs) = snth n (stake k\\<cdot>(srcdups\\<cdot>ys))\"\n      by (metis eq_len first_n_eq snth_less stream.take_below)\n    then have \"srcdups\\<cdot>xs = stake k\\<cdot>(srcdups\\<cdot>ys)\"\n      by (simp add: \\<open>\\<forall>n. Fin n < #(srcdups\\<cdot>xs) \\<longrightarrow> snth n (srcdups\\<cdot>xs) = snth n (stake k\\<cdot>(srcdups\\<cdot>ys))\\<close> eq_len snths_eq)\n    thus ?thesis\n      by simp\n  qed\nqed\n\nlemma srcdups_snth_stake_inf: \"#s = \\<infinity> \\<Longrightarrow> snth n s \\<noteq> snth (Suc n) s \\<Longrightarrow> srcdups\\<cdot>(stake (Suc n)\\<cdot>s) \\<noteq> srcdups\\<cdot>s\"\nproof\n  assume \"#s = \\<infinity>\" and \"snth n s \\<noteq> snth (Suc n) s\" and \"srcdups\\<cdot>(stake (Suc n)\\<cdot>s) = srcdups\\<cdot>s\"\n  have \"#(stake (Suc (Suc n))\\<cdot>s) = Fin (Suc (Suc n))\"\n    by (simp add: \\<open>#s = \\<infinity>\\<close> slen_stake_fst_inf)\n  moreover have \"Suc (Suc n) > Suc n\"\n    by simp\n  moreover have \"snth n (stake (Suc (Suc n))\\<cdot>s) \\<noteq> snth (Suc n) (stake (Suc (Suc n))\\<cdot>s)\"\n    by (metis Fin_leq_Suc_leq Suc_n_not_le_n \\<open>snth n s \\<noteq> snth (Suc n) s\\<close> calculation(1) less2nat_lemma not_le snth_less stream.take_below)\n  ultimately have \"srcdups\\<cdot>(stake (Suc n)\\<cdot>(stake (Suc (Suc n))\\<cdot>s)) \\<noteq> srcdups\\<cdot>(stake (Suc (Suc n))\\<cdot>s)\"\n    using srcdups_snth_stake_fin by blast\n  then have \"srcdups\\<cdot>(stake (Suc n)\\<cdot>s) \\<noteq> srcdups\\<cdot>(stake (Suc (Suc n))\\<cdot>s)\"\n    by (simp add: min_def)\n  moreover have \"srcdups\\<cdot>(stake (Suc (Suc n))\\<cdot>s) = srcdups\\<cdot>s\"\n  proof (rule ccontr)\n    assume \"srcdups\\<cdot>(stake (Suc (Suc n))\\<cdot>s) \\<noteq> srcdups\\<cdot>s\"\n    moreover have \"srcdups\\<cdot>(stake (Suc n)\\<cdot>s) \\<sqsubseteq> srcdups\\<cdot>(stake (Suc (Suc n))\\<cdot>s)\"\n      by (simp add: less_imp_le_nat monofun_cfun_arg stake_mono)\n    ultimately have \"srcdups\\<cdot>(stake (Suc n)\\<cdot>s) \\<noteq> srcdups\\<cdot>s\"\n      by (metis below_antisym monofun_cfun_arg stream.take_below)\n    then show \"False\"\n      by (simp add: \\<open>srcdups\\<cdot>(stake (Suc n)\\<cdot>s) = srcdups\\<cdot>s\\<close>)\n  qed\n  ultimately show \"False\"\n    by (simp add: \\<open>srcdups\\<cdot>(stake (Suc n)\\<cdot>s) = srcdups\\<cdot>s\\<close>)\nqed\n\n\ntext \\<open>Basic properties of @{term sValues}\\<close>\n\n(* sValues applied to the empty stream returns the empty set *)\nlemma [simp]: \"sValues\\<cdot>\\<epsilon> = {}\"\nby (auto simp add: sValues_def2 lnless_def)\n\n(* the head of any stream is always an element of the domain *)\nlemma sValues2un[simp]: \"sValues\\<cdot>(\\<up>z \\<bullet> s) = {z} \\<union> sValues\\<cdot>s\"\napply (auto simp add: sValues_def2)\napply (case_tac \"n\", auto)\napply (rule_tac x=\"0\" in exI, auto)\nby (rule_tac x=\"Suc n\" in exI, auto)\n\nlemma srcdups_dom_h: assumes \"sValues\\<cdot>(srcdups\\<cdot>s) = sValues\\<cdot>s\"\n  shows \"sValues\\<cdot>(srcdups\\<cdot>(\\<up>a \\<bullet> s)) = insert a (sValues\\<cdot>s)\"\nproof (cases \"shd s = a\")\n  case True\n  have \"srcdups\\<cdot>(\\<up>a \\<bullet> \\<up>a \\<bullet> srt\\<cdot>s) = srcdups\\<cdot>(\\<up>a \\<bullet> srt\\<cdot>s)\"\n    using srcdups_eq by blast\n  hence \"a \\<in> sValues\\<cdot>(srcdups\\<cdot>(\\<up>a \\<bullet> srt\\<cdot>s))\"\n    by (simp add: srcdups_step) \n  then show ?thesis\n    by (metis True Un_insert_left assms insert_absorb2 sValues2un srcdups_eq srcdups_step strict_sdropwhile sup_bot.left_neutral surj_scons)\nnext\n  case False\n  then show ?thesis\n    by (metis (no_types, lifting) assms insert_is_Un sValues2un srcdups_neq srcdups_step strict_sdropwhile surj_scons)\nqed\n  \nlemma srcdups_dom [simp]: \"sValues\\<cdot>(srcdups\\<cdot>xs) = sValues\\<cdot>xs\"\napply(rule ind, simp_all)\n  by (simp add: srcdups_dom_h)  \n\n(* only the empty stream has no elements in its domain *)\nlemma strict_sValues_rev: \"sValues\\<cdot>s = {} \\<Longrightarrow> s = \\<epsilon>\"\napply (auto simp add: sValues_def2)\napply (rule_tac x=\"s\" in scases, auto)\nby (metis Fin_02bot gr_0 lnzero_def)\n\nlemma sValues_notempty:\"s\\<noteq>\\<epsilon> \\<longleftrightarrow> sValues\\<cdot>s\\<noteq>{}\"\n  using strict_sValues_rev by auto\n\n(* the infinite repetition of a only has a in its domain *)\n(*with new lemmata not necessary:\n apply (subst sinftimes_unfold, simp)*)\n(*apply (induct_tac n, auto)\napply (subst sinftimes_unfold, simp)\napply (rule_tac x=\"0\" in exI)\nby (subst sinftimes_unfold, simp)*)\nlemma [simp]: \"sValues\\<cdot>(sinftimes (\\<up>a)) = {a}\"\nby (auto simp add: sValues_def2)\n\n(* any singleton stream of z only has z in its domain *)\nlemma [simp]: \"sValues\\<cdot>(\\<up>z) = {z}\"\nby (auto simp add: sValues_def2)\n\n(* if an element z is in the domain of a stream s, then z is the n'th element of s for some n *)\nlemma sValues2snth: \"z \\<in> sValues\\<cdot>s \\<Longrightarrow> \\<exists>n. snth n s = z\"\nby (auto simp add: sValues_def2)\n\n(* if the natural number n is less than the length of the stream s, then snth n s is in the domain of s *)\nlemma snth2sValues: \"Fin n < #s \\<Longrightarrow> snth n s \\<in> sValues\\<cdot>s\"\n  by (auto simp add: sValues_def2)\n\nlemma smap_well:\"sValues\\<cdot>x\\<subseteq>range f \\<Longrightarrow>  \\<exists>s. smap f\\<cdot>s = x\"\n  apply(rule_tac x = \"smap (inv f)\\<cdot>x\" in exI)\n  by (simp add: snths_eq smap_snth_lemma f_inv_into_f snth2sValues subset_eq)\n\nlemma smap_inv_id[simp]: \"sValues\\<cdot>s \\<subseteq> range F \\<Longrightarrow> smap (F \\<circ> (inv F))\\<cdot>s = s\"\n  apply (induction s  rule: ind )\n  by(simp_all add: f_inv_into_f)\n\nlemma smap_inv_eq[simp]:\"inj F \\<Longrightarrow> smap (inv F \\<circ> F)\\<cdot>x = x\"\n  by (metis inv_o_cancel smap_inv_id subset_UNIV surj_id surj_iff)\n\n(* checking if the domain of a stream x isn't a subset of another set M is an admissible predicate *)\nlemma [simp]: \"adm (\\<lambda>x. \\<not> sValues\\<cdot>x \\<subseteq> M)\"\napply (rule admI)\napply (rule notI)\napply (frule_tac x=\"0\" in is_ub_thelub)\napply (frule_tac f=\"sValues\" in monofun_cfun_arg)\nby (erule_tac x=\"0\" in allE, auto simp add: less_set_def)\n\ntext \\<open>filtering with a superset of the stream's domain does not change the stream\\<close>\nlemma sfilter_sValuesl3:\n  \"sValues\\<cdot>s \\<subseteq> X \\<longrightarrow> sfilter X\\<cdot>s = s\"\napply (rule impI)\napply (rule stream.take_lemma)\napply (simp add: atomize_imp)\napply (rule_tac x=\"s\" in spec)\napply (rule_tac x=\"X\" in spec)\napply (induct_tac n, simp+)\napply (rule allI)+\napply (rule impI)\nby (rule_tac x=\"xa\" in scases, simp+)\n\ntext \\<open>filtering with the stream's domain does not change the stream\\<close>\nlemma sfilter_sValuesl4 [simp]:\n  \"sfilter (sValues\\<cdot>s)\\<cdot>s = s\"\nby (rule sfilter_sValuesl3 [rule_format, of \"s\" \"sValues\\<cdot>s\"], simp)\n\nlemma sfilter_fin: assumes \"#(A \\<ominus> s) < \\<infinity>\" \n  shows \"\\<exists>n. (A \\<ominus> (sdrop n\\<cdot>s)) = \\<bottom>\"\n  apply(rule ccontr)\n  apply auto\n  by (metis assms fun_approxl2 lnat_well_h2 sconc_neq_h sconc_snd_empty split_sfilter)\n\nlemma s_one_dom_inf: assumes \"sValues\\<cdot>s = {x}\" and \"#s = \\<infinity>\"\n    shows \"s = ((\\<up>x)\\<^sup>\\<infinity>)\"\n  by (metis Fin_02bot Fin_Suc Suc_n_not_le_n assms(1) assms(2) bot_is_0 inject_Fin less_or_eq_imp_le sinftimes_unfold singleton_iff slen_scons slen_sinftimes snth2sValues snth_sinftimes snths_eq strict_icycle strict_slen)\n\nlemma sfilter_bot_dom: \"(A \\<ominus> s) = \\<bottom> \\<Longrightarrow> sValues\\<cdot>s \\<subseteq> UNIV - A\"\n  apply(induction s rule: ind)\n    apply auto\n  by (metis DiffD2 inject_scons rev_subsetD sfilter_in sfilter_nin strictI)\n\ntext \\<open>The domain of a concatenated stream is the union of the single domains\\<close>\nlemma sValues_sconc2un:\n  \"#x = Fin k \\<Longrightarrow> sValues\\<cdot>(x \\<bullet> y) = sValues\\<cdot>x \\<union> sValues\\<cdot>y\"\napply (simp add: atomize_imp)\napply (rule_tac x=\"x\" in spec)\napply (induct_tac k, simp+)\napply (rule allI, rule impI)\nby (rule_tac x=\"x\" in scases, simp+)\n\n(* sValues applied to s1\\<bullet>s2 is a subset of the union of sValues s1 and sValues s2 *)\nlemma sconc_sValues: \"sValues\\<cdot>(s1\\<bullet>s2) \\<subseteq> sValues\\<cdot>s1 \\<union> sValues\\<cdot>s2\"\nby (metis SetPcpo.less_set_def below_refl lncases sconc_fst_inf sValues_sconc2un sup.coboundedI1)\n\n(* relation between sValues and sfoot *)\nlemma sfoot_dom: assumes \"#s = Fin (Suc n)\" and \"sValues\\<cdot>s\\<subseteq>A\"\n  shows \"sfoot s\\<in>A\"\nby (metis Suc_n_not_le_n assms(1) assms(2) contra_subsetD leI less2nat_lemma sfoot_exists2 snth2sValues)\n\n(* stakewhile doesn't include the element a that failed the predicate f in the result *)\nlemma stakewhile_dom[simp]:assumes \"\\<not>f a\"\n  shows \"a\\<notin>sValues\\<cdot>(stakewhile f\\<cdot>s)\"\nby (smt assms below_antisym lnle_conv lnless_def mem_Collect_eq sValues_def2 snth_less stakewhile_below stakewhile_slen)\n\nlemma srcdups_sconc_duplicates:\n  assumes \"#xs < \\<infinity>\" and \"xs \\<noteq> \\<epsilon>\" and \"srcdups\\<cdot>xs = srcdups\\<cdot>(xs \\<bullet> ys)\"\n  shows \"sValues\\<cdot>ys \\<subseteq> {sfoot xs}\"\nproof -\n  have \"srcdups\\<cdot>(xs \\<bullet> ys) = (srcdups\\<cdot>xs) \\<bullet> (srcdups\\<cdot>(sdropwhile (\\<lambda>x. x=sfoot xs)\\<cdot>ys))\"\n    using assms(1) assms(2) srcdups_sconc by blast\n  then have \"srcdups\\<cdot>xs = srcdups\\<cdot>xs \\<bullet> (srcdups\\<cdot>(sdropwhile (\\<lambda>x. x=sfoot xs)\\<cdot>ys))\"\n    using assms(3) by presburger\n  moreover have \"#(srcdups\\<cdot>xs) < \\<infinity>\"\n    by (meson assms(1) leD leI srcdups_slen trans_lnle)\n  ultimately have \"srcdups\\<cdot>(sdropwhile (\\<lambda>x. x=sfoot xs)\\<cdot>ys) = \\<epsilon>\"\n    using sconc_neq_h by fastforce\n  then have \"sdropwhile (\\<lambda>x. x=sfoot xs)\\<cdot>ys = \\<epsilon>\"\n    using srcdups_nbot by blast\n  then show ?thesis\n    by (metis (full_types) insertI1 sconc_snd_empty stakewhileDropwhile stakewhile_dom subsetI)\nqed\n\n(* if stakewhile changes the stream s, which is a prefix of the stream s', then stakewhile of s and s'\n   produce the same result *)\nlemma stakewhile_finite_below: \nshows \"stakewhile f\\<cdot>s \\<noteq> s \\<Longrightarrow> s\\<sqsubseteq>s' \\<Longrightarrow> stakewhile f\\<cdot>s = stakewhile f\\<cdot>s'\"\napply(induction s)\napply simp+\nby (smt approxl1 approxl2 lnless_def monofun_cfun_arg rev_below_trans snth_less stakewhile_below stakewhile_notin stakewhile_snth)\n\n(* if there is an element in the stream s that fails the predicate f, then stakewhile will change s *)\nlemma stakewhile_noteq[simp]: assumes \"\\<not>f (snth n s)\" and \"Fin n < #s\"\n  shows \"stakewhile f\\<cdot>s \\<noteq> s\"\nproof (rule ccontr)\n  assume \"\\<not> stakewhile f\\<cdot>s \\<noteq> s\"\n  hence \"sValues\\<cdot>(stakewhile f\\<cdot>s) = sValues\\<cdot>s\" by simp\n  hence \"(snth n s)\\<in>sValues\\<cdot>(stakewhile f\\<cdot>s)\" by (simp add: assms(2) snth2sValues)\n  thus False by (simp add: assms(1)) \nqed\n\n(* if there's an element a in the domain of s which fails the predicate f, then stwbl will produce a\n   finite result *)\nlemma stwbl_fin [simp]: assumes \"a\\<in>sValues\\<cdot>s\" and \"\\<not> f a\"\n  shows \"#(stwbl f\\<cdot>s) < \\<infinity>\"\nby (metis assms(1) assms(2) inf_ub lnle_conv lnless_def notinfI3 sconc_slen sValues2snth stakewhile_slen stwbl_stakewhile ub_slen_stake)\n\n(* stwbl keeps at least all the elements that stakewhile keeps *)\nlemma stakewhile_stwbl [simp]: \"stakewhile f\\<cdot>(stwbl f\\<cdot>s) = stakewhile f\\<cdot>s\"\nproof -\n  have \"\\<And>s sa. (s::'a stream) \\<sqsubseteq> s \\<bullet> sa\"\n    by simp\n  then have \"stakewhile f\\<cdot>(stwbl f\\<cdot>s) = stwbl f\\<cdot>s \\<longrightarrow> stakewhile f\\<cdot>(stwbl f\\<cdot>s) = stakewhile f\\<cdot>s\"\n    by (metis (no_types) below_antisym monofun_cfun_arg stwbl_below stwbl_stakewhile)\n  then show ?thesis\n    using stakewhile_finite_below stwbl_below by blast\nqed\n\n(* sValues applied to sntimes n s is a subset of sValues applied to s *)\nlemma sntimes_sValues1[simp]: \"sValues\\<cdot>(sntimes n s) \\<subseteq> sValues\\<cdot>s\"\nproof (induction n)\n  case 0 thus ?case by simp\nnext\n  case (Suc n) thus ?case using sconc_sValues sntimes.simps(2) sup.orderE by auto\nqed\n\n(* if filtering everything except z from the stream x doesn't produce the empty stream, then z must\n   be an element of the domain of x *)\nlemma sfilter2dom:\n  \"sfilter {z}\\<cdot>x \\<noteq> \\<epsilon> \\<Longrightarrow> z \\<in> sValues\\<cdot>x\"\napply (subgoal_tac \"\\<exists>k. snth k x = z \\<and> Fin k < #x\", erule exE)\napply (erule conjE)\napply (drule sym, simp)\napply (rule snth2sValues, simp)\napply (rule ccontr, simp)\nby (insert ex_snth_in_sfilter_nempty [of x \"{z}\"], auto)\n\ntext \\<open>For injective functions @{term f} with @{term \"f(y) = x\"}, @{term x} can only\n  be contained in @{term \"smap f\\<cdot>s\"} if the original stream contained @{term y}\\<close>\nlemma sValues_smapl1: \"\\<lbrakk>x \\<in> sValues\\<cdot>(smap f\\<cdot>s); inj f; f y = x\\<rbrakk> \\<Longrightarrow> y \\<in> sValues\\<cdot>s\" \n  by (smt mem_Collect_eq sValues_def2 slen_smap smap_snth_lemma the_inv_f_f)\n    (*\napply (auto simp add: sValues_def2)\napply (rule_tac x=\"n\" in exI, simp)\napply (simp add: smap_snth_lemma)\nby (simp add: inj_on_def) *)\n\n(* appending another stream xs can't shrink the domain of a stream x *)\nlemma sValues_sconc[simp]: \"sValues\\<cdot>x \\<subseteq> sValues\\<cdot>(x \\<bullet> xs)\"\nby (metis minimal monofun_cfun_arg sconc_snd_empty set_cpo_simps(1))\n\n(* repeating a stream doesn't add elements to the domain *)\nlemma sinftimes_sValues[simp]: \"sValues\\<cdot>(sinftimes s) \\<subseteq> sValues\\<cdot>s\"\nby (smt chain_monofun contlub_cfun_arg lub_below set_cpo_simps(1) sntimesLub sntimes_chain sntimes_sValues1)\n\n(* repeating a stream doesn't remove elements from the domain either *)\nlemma sinf_sValues [simp]: \"sValues\\<cdot>(s\\<^sup>\\<infinity>) = sValues\\<cdot>s\"\nby (metis antisym_conv sValues_sconc sinftimes_sValues sinftimes_unfold)\n\n(* sfilter doesn't add elements to the domain *)\nlemma sbfilter_sbdom[simp]: \"sValues\\<cdot>(sfilter A\\<cdot>s) \\<subseteq> sValues\\<cdot>s\"\napply(rule ind [of _s], auto)\nby (metis (mono_tags, lifting) UnE contra_subsetD sValues2un sfilter_in sfilter_nin singletonD)\n\n(* smap can only produce elements in the range of the mapped function f *)\nlemma smap_sValues_range [simp]: \"sValues\\<cdot>(smap f\\<cdot>s) \\<subseteq> range f\"\nby (smt mem_Collect_eq range_eqI sValues_def2 slen_smap smap_snth_lemma subsetI)\n\n(* every element produced by (smap f) is in the image of the function f *)\nlemma smap_sValues: \"sValues\\<cdot>(smap f\\<cdot>s) =  f ` sValues\\<cdot>s\"\napply(rule)\napply (smt image_eqI mem_Collect_eq sValues_def2 slen_smap smap_snth_lemma subsetI)\nby (smt image_subset_iff mem_Collect_eq sValues_def2 slen_smap smap_snth_lemma)\n\n(* lemmas for SB *)\n(* if the stream a is a prefix of the stream b then a's domain is a subset of b's *)\nlemma sValues_prefix [simp]: \"a \\<sqsubseteq> b \\<Longrightarrow> sValues\\<cdot>a \\<subseteq> sValues\\<cdot>b\"\nby (metis SetPcpo.less_set_def monofun_cfun_arg)\n\n(* the lub of a chain of streams contains any elements contained in any stream in the chain *)\nlemma sValues_chain2lub: \"chain S \\<Longrightarrow> sValues\\<cdot>(S i) \\<subseteq> sValues\\<cdot>(\\<Squnion> j. S j)\"\nusing sValues_prefix is_ub_thelub by auto\n\n(* if every element in a chain S is a prefix of s then also the least upper bound in the chain S if prefix of s *)\nlemma lubChainpre: \"chain S \\<Longrightarrow> S i  \\<Longrightarrow> \\<forall>i. S i \\<sqsubseteq> s \\<Longrightarrow> (\\<Squnion> j. S j) \\<sqsubseteq> s\"\nby (simp add: lub_below)\n\n(* if every element in a chain S is a prefix of s, then the domain of S i is a subset of the domain of s *)\nlemma sValues_chainprefix: \"chain S \\<Longrightarrow> \\<forall>i. S i \\<sqsubseteq> s \\<Longrightarrow> \\<forall>i. sValues\\<cdot>(S i) \\<subseteq> sValues\\<cdot>s\"\nby simp\n\n(* if every element in a chain S is a prefix of s, then the domain of the lub is a subset of the domain of s *)\nlemma sValues_chainlub: \"chain S \\<Longrightarrow>  \\<forall>i. S i \\<sqsubseteq> s \\<Longrightarrow> sValues\\<cdot>(\\<Squnion> j. S j) \\<subseteq> sValues\\<cdot>s\"\nusing sValues_prefix lub_below by blast\n\n(* streams appearing later in the chain S contain the elements of preceding streams *)\nlemma sValues_chain_below: \"chain S \\<Longrightarrow> i \\<le> j \\<Longrightarrow> sValues\\<cdot>(S i) \\<subseteq> sValues\\<cdot>(S j)\"\nby (simp add: po_class.chain_mono)\n\n(* for two elements i, j with i \\<le> j in a chain S it holds that the domain of S i is a subset of the domain of S j *)\nlemma sValues_lub2union: \"chain S \\<Longrightarrow> finite_chain S \\<Longrightarrow> sValues\\<cdot>(\\<Squnion> j. S j) \\<subseteq> (\\<Union>i. sValues\\<cdot>(S i))\"\nusing l42 by fastforce\n\n(* important *)\n(* the lub doesn't have any elements that don't appear somewhere in the chain *)\nlemma sValues_lub: \"chain S \\<Longrightarrow> sValues\\<cdot>(\\<Squnion> j. S j) = (\\<Union>i. sValues\\<cdot>(S i))\"\napply (simp add: contlub_cfun_arg)\nby (simp add: lub_eq_Union)\n\nlemma sscanlasnd_smap_state_loop:\n  assumes\"\\<And>e. e \\<in> sValues\\<cdot>s \\<Longrightarrow> fst (f state e) = state\"\nshows \"sscanlAsnd f state\\<cdot>(s) = smap (\\<lambda>e. snd (f state e))\\<cdot>s\"\n  using assms\n  apply (induction s rule: ind)\n  apply (rule adm_imp)\n  apply (rule admI)\n  apply (meson sValues_chain2lub set_rev_mp)\n  by simp_all\n\n(* core lemma for exchanging transition function (general lemma) *) \nlemma sscanla_exchange_f:\n  assumes \"\\<And>e state. P e \\<Longrightarrow> F1 state e = F2 state e\" \n    and \"\\<forall>x \\<in> sValues\\<cdot>s. P x\"\n  shows \"sscanlAsnd F1 state\\<cdot>s = sscanlAsnd F2 state\\<cdot>s\"\n  using assms\n  apply (induction s arbitrary: state rule: ind)\n  apply (rule adm_imp, simp)+\n  apply (rule admI)\n  apply (meson sValues_chain2lub subsetCE)\n  by simp_all\n\ntext \\<open>Let i in N be an index of the chain S of streams and B a set of messages.\\<close>\nlemma l44: assumes \"chain S\" and \"\\<forall>i. sValues\\<cdot>(S i) \\<subseteq> B\"\n  shows \"sValues\\<cdot>(\\<Squnion> j. S j) \\<subseteq> B\"\nby (metis (mono_tags, lifting) UN_E assms sValues_lub subsetCE subsetI)\n\n(* helper lemma *)\nlemma l6: \"chain S \\<Longrightarrow> \\<forall>i. sValues\\<cdot>(S i) \\<subseteq> B \\<Longrightarrow> sValues\\<cdot>(\\<Squnion> j. S (j + (SOME k. A))) \\<subseteq> B\"\nby (simp add: l44 lub_range_shift)\n\n(* dropping elements can't increase the domain *)\nlemma sdrop_sValues[simp]: \"sValues\\<cdot>(sdrop n\\<cdot>s)\\<subseteq>sValues\\<cdot>s\"\nby (metis Un_upper2 approxl2 sValues_prefix sValues_sconc2un sdrop_0 sdropostake split_streaml1 stream.take_below)\n\n(* if none of the elements in the domain of the stream s are in the set A, then filtering s with A\n   produces the empty stream *)\nlemma sfilter_sValues_eps: \"sValues\\<cdot>s \\<inter> A = {} \\<Longrightarrow> (A \\<ominus> s) = \\<epsilon>\"\nby (meson disjoint_iff_not_equal ex_snth_in_sfilter_nempty snth2sValues)\n\n(* if x in sValues\\<cdot>(A\\<ominus>s) then x is in A *)\nlemma sValues_sfilter1: assumes \"x\\<in>sValues\\<cdot>(A\\<ominus>s)\" \nshows \"x\\<in>A\"\nby (smt assms mem_Collect_eq sValues_def2 sfilterl7)\n\n(* if u is not bottom then sValues\\<cdot>s\\<subseteq>sValues\\<cdot>(u && s) *)\nlemma sValues_subset: assumes \"u\\<noteq>\\<bottom>\"\nshows \"sValues\\<cdot>s\\<subseteq>sValues\\<cdot>(u && s)\"\nby (metis Un_upper2 assms sValues2un stream.con_rews(2) stream.sel_rews(5) surj_scons)\n\n(* if u is not bottom then sValues\\<cdot>(A\\<ominus>s)\\<subseteq>sValues\\<cdot>(A \\<ominus> (u && s)) *)\nlemma sValues_sfilter_subset: assumes \"u\\<noteq>\\<bottom>\"\nshows \"sValues\\<cdot>(A\\<ominus>s)\\<subseteq>sValues\\<cdot>(A \\<ominus> (u && s))\"\nby (smt Un_upper2 assms eq_iff sValues2un sfilter_in sfilter_nin stream.con_rews(2) stream.sel_rews(5) surj_scons)\n\n(* if x in A then x\\<in>sValues\\<cdot>s implies x\\<in>(sValues\\<cdot>(A \\<ominus> s)) *)\nlemma sValues_sfilter2: assumes  \"x\\<in>A\"\nshows \"x\\<in>sValues\\<cdot>s \\<Longrightarrow> x\\<in>(sValues\\<cdot>(A \\<ominus> s))\"\napply(induction s)\napply(rule admI)\napply rule\n  apply (metis (mono_tags, lifting) UN_iff ch2ch_Rep_cfunR contlub_cfun_arg sValues_lub)\napply simp\nby (smt UnE assms empty_iff insert_iff sconc_sValues sValues2un sValues_sconc sValues_sfilter_subset sfilter_in stream.con_rews(2) stream.sel_rews(5) subsetCE surj_scons)\n\n(* sValues applied to A\\<ominus>s returns the intersection of sValues applied to s and A *)\nlemma sValues_sfilter[simp]: \"sValues\\<cdot>(A\\<ominus>s) = sValues\\<cdot>s \\<inter> A\"\napply rule\napply (meson IntI sbfilter_sbdom sValues_sfilter1 subset_iff)\napply rule\n  by (simp add: sValues_sfilter2)\n\n(* if sfilter of A\\<cdot>s is s then sValues\\<cdot>s is a subset of A *)\nlemma sfilterEq2sValues_h: \"sfilter A\\<cdot>s = s \\<longrightarrow> sValues\\<cdot>s \\<subseteq> A\"\n  apply(rule ind [of _s])\n    apply (smt admI inf.orderI sValues_sfilter)\n   apply(simp)\n  apply(rule)\n  by (metis inf.orderI sValues_sfilter)\n\n(* sfilter of A\\<cdot>s is s implies that sValues\\<cdot>s is a subset of A *)\nlemma sfilterEq2sValues: \"sfilter A\\<cdot>s = s \\<Longrightarrow> sValues\\<cdot>s \\<subseteq> A\"\n  by (simp add: sfilterEq2sValues_h)\n\n(* if \\<forall>a\\<in>sValues\\<cdot>s. f a then stwbl applied to f\\<cdot>s returns s *)\nlemma stwbl_id_help:\n  shows \"(\\<forall>a\\<in>sValues\\<cdot>s. f a) \\<longrightarrow> stwbl f\\<cdot>s = s\"\n  apply (rule ind [of _s])\n    apply(rule adm_imp)\n     apply(rule admI, rule+)\n     using sValues_chain2lub apply blast\n    apply(rule admI)\n    apply (metis cont2contlubE cont_Rep_cfun2 lub_eq)\n   using strict_stwbl apply blast\n  apply rule+\n  by simp\n\n(* \\<And> a. a\\<in>sValues\\<cdot>s \\<Longrightarrow> f a implies that stwbl applied to f\\<cdot>s is s *)\nlemma stwbl_id [simp]: \"(\\<And> a. a\\<in>sValues\\<cdot>s \\<Longrightarrow> f a) \\<Longrightarrow> stwbl f\\<cdot>s = s\"\nby (simp add: stwbl_id_help)\n\n(* if a in sValues s and \\<not>f a then it holds that \\<exists>x. (stwbl f\\<cdot>s) = stakewhile f\\<cdot>s \\<bullet> \\<up>x *)\nlemma stwbl2stakewhile: assumes \"a\\<in>sValues\\<cdot>s\" and \"\\<not>f a\"\n  shows \"\\<exists>x. (stwbl f\\<cdot>s) = stakewhile f\\<cdot>s \\<bullet> \\<up>x\" \nproof -\n  have \"#(stwbl f\\<cdot>s) < \\<infinity>\" using assms(1) assms(2) snth2sValues stwbl_fin by blast\n  hence \"stwbl f\\<cdot>s \\<noteq> \\<epsilon>\" by (metis assms(1) assms(2) stakewhile_dom strict_stakewhile stwbl_notEps) \n  thus ?thesis\n    by (smt Fin_02bot approxl2 assms(1) assms(2) bottomI lnle_def lnzero_def mem_Collect_eq sconc_snd_empty sValues_def2 sdrop_0 slen_empty_eq slen_rt_ile_eq split_streaml1 stakewhile_below stakewhile_noteq stakewhile_sdropwhilel1 stwbl_notEps stwbl_stakewhile surj_scons tdw ub_slen_stake) \nqed\n\n(* if a in sValues s and \\<not>f a it holds that \\<not> f (sfoot (stwbl f\\<cdot>s)) *)\nlemma stwbl_sfoot: assumes \"a\\<in>sValues\\<cdot>s\" and \"\\<not>f a\"\n  shows \"\\<not> f (sfoot (stwbl f\\<cdot>s))\" \nproof(rule ccontr)\n  assume \"\\<not> \\<not> f (sfoot (stwbl f\\<cdot>s))\"\n  hence \"f (sfoot (stwbl f\\<cdot>s))\" by blast\n  obtain x where x_def:\"(stwbl f\\<cdot>s) = stakewhile f\\<cdot>s \\<bullet> \\<up>x\"\n    using assms(1) assms(2) stwbl2stakewhile by blast\n  hence \"sfoot (stwbl f\\<cdot>s) = x\"\n    using assms(1) assms(2) sfoot1 stwbl_fin by blast\n  have \"stakewhile f\\<cdot>s \\<bullet> \\<up>x \\<sqsubseteq> s\" by (metis stwbl_below x_def)\n  have \"f x\"\n    using \\<open>f (sfoot (stwbl f\\<cdot>s))\\<close> \\<open>sfoot (stwbl f\\<cdot>s) = x\\<close> by blast\n  thus False\n    by (metis approxl2 assms(1) assms(2) inject_sconc sconc_snd_empty sdropwhile_resup stakewhileDropwhile stakewhile_below stakewhile_dom stakewhile_stwbl x_def)\n(*    by (smt Fin_02bot \\<open>sfoot (stwbl f\\<cdot>s) = x\\<close> approxl2 assms(1) assms(2) assoc_sconc bottomI lnle_def lnzero_def sconc_fst_empty sconc_snd_empty sdrop_0 sdropwhile_t sfoot1 slen_empty_eq slen_rt_ile_eq split_streaml1 stakewhile_below stakewhile_dom stakewhile_sdropwhilel1 stakewhile_stwbl stream.take_strict strict_stakewhile stwbl_fin stwbl_notEps stwbl_stakewhile surj_scons tdw ub_slen_stake) *)\nqed\n\n(* stwbl applied to f and stwbl f\\<cdot>s returns stwbl f\\<cdot>s *)\nlemma stwbl2stbl[simp]: \"stwbl f\\<cdot>(stwbl f\\<cdot>s) = stwbl f\\<cdot>s\"\n  apply(rule ind [of _s])\n    apply simp_all\n  by (metis sconc_snd_empty stwbl_f stwbl_t)\n\n(* (\\<lambda>x. b \\<notin> sValues\\<cdot>x) is admissible *)\nlemma adm_nsValues [simp]:  \"adm (\\<lambda>x. b \\<notin> sValues\\<cdot>x)\"\nproof (rule admI)\n  fix Y\n  assume as1: \"chain Y\" and as2: \"\\<forall>i. b\\<notin>sValues\\<cdot>(Y i)\"\n  thus \"b\\<notin>sValues\\<cdot>(\\<Squnion>i. Y i)\"\n  proof (cases \"finite_chain Y\")\n    case True thus ?thesis using as1 as2 l42 by fastforce \n  next\n    case False\n    hence \"#(\\<Squnion>i. Y i) = \\<infinity>\" using as1 inf_chainl4 by blast\n    hence \"\\<And>n. snth n (\\<Squnion>i. Y i) \\<noteq> b\"\n    proof -\n      fix n\n      obtain j where \"Fin n < # (Y j)\"  by (metis False inf_chainl2 as1 inf_chainl3rf less_le) \n      hence \"snth n (Y j) \\<noteq>b\" using as2 snth2sValues by blast\n      thus \"snth n (\\<Squnion>i. Y i) \\<noteq> b\" using \\<open>Fin n < #(Y j)\\<close> as1 is_ub_thelub snth_less by blast\n    qed\n    thus ?thesis using sValues2snth by blast \n  qed\nqed\n\n(* strdw_filter helper lemma *)\nlemma strdw_filter_h: \"b\\<in>sValues\\<cdot>s \\<longrightarrow> lnsuc\\<cdot>(#({b} \\<ominus> srtdw (\\<lambda>a. a \\<noteq> b)\\<cdot>s)) = #({b} \\<ominus> s)\"\nproof(rule ind [of _s])\n  have \"adm (\\<lambda>a. lnsuc\\<cdot>(#({b} \\<ominus> srtdw (\\<lambda>a. a \\<noteq> b)\\<cdot>a)) = #({b} \\<ominus> a))\" by simp\n  thus \"adm (\\<lambda>a. b \\<in> sValues\\<cdot>a \\<longrightarrow> lnsuc\\<cdot>(#({b} \\<ominus> srtdw (\\<lambda>a. a \\<noteq> b)\\<cdot>a)) = #({b} \\<ominus> a))\" by simp\n  show \"b \\<in> sValues\\<cdot>\\<epsilon> \\<longrightarrow> lnsuc\\<cdot>(#({b} \\<ominus> srtdw (\\<lambda>a. a \\<noteq> b)\\<cdot>\\<epsilon>)) = #({b} \\<ominus> \\<epsilon>)\" by simp\n  fix a \n  fix s\n  assume IH: \" b \\<in> sValues\\<cdot>s \\<longrightarrow> lnsuc\\<cdot>(#({b} \\<ominus> srtdw (\\<lambda>a. a \\<noteq> b)\\<cdot>s)) = #({b} \\<ominus> s)\"\n  show \" b \\<in> sValues\\<cdot>(\\<up>a \\<bullet> s) \\<longrightarrow> lnsuc\\<cdot>(#({b} \\<ominus> srtdw (\\<lambda>a. a \\<noteq> b)\\<cdot>(\\<up>a \\<bullet> s))) = #({b} \\<ominus> \\<up>a \\<bullet> s)\"\n  proof (cases \"a=b\")\n    case True thus ?thesis by simp \n  next\n    case False\n    hence f1:\"#({b} \\<ominus> \\<up>a \\<bullet> s) = #({b} \\<ominus> s)\" using sfilter_nin singletonD by auto\n    hence f2:\"#({b} \\<ominus> srtdw (\\<lambda>a. a \\<noteq> b)\\<cdot>(\\<up>a \\<bullet> s)) = #({b} \\<ominus> srtdw (\\<lambda>a. a \\<noteq> b)\\<cdot>(s))\" using False by auto\n    hence \"b \\<in> sValues\\<cdot>(\\<up>a \\<bullet> s) \\<Longrightarrow> b\\<in>sValues\\<cdot>s\" using False by auto\n    thus ?thesis using IH f2 local.f1 by auto \n  qed\nqed\n\n(* strdw filter lemma *)\nlemma strdw_filter: \"b\\<in>sValues\\<cdot>s \\<Longrightarrow> lnsuc\\<cdot>(#({b} \\<ominus> srtdw (\\<lambda>a. a \\<noteq> b)\\<cdot>s)) = #({b} \\<ominus> s)\"\nby(simp add: strdw_filter_h)\n\n(* length of stwbl filter *)\nlemma stwbl_filterlen[simp]: \"b\\<in>sValues\\<cdot>ts \\<longrightarrow> #({b} \\<ominus> stwbl (\\<lambda>a. a \\<noteq> b)\\<cdot>ts) = Fin 1\"\n  apply(rule ind [of _ ts])\n    apply(rule adm_imp)\n     apply simp\n    apply simp\n   apply simp\n  apply auto\n  by (metis (mono_tags, lifting) Fin_02bot Fin_Suc One_nat_def lnzero_def sconc_snd_empty sfilter_in sfilter_nin singletonD singletonI slen_scons strict_sfilter strict_slen stwbl_f stwbl_t)\n\n(* srtdw concatenation *)\nlemma srtdw_conc: \"b\\<in>sValues\\<cdot>ts  \\<Longrightarrow> (srtdw (\\<lambda>a. a \\<noteq> b)\\<cdot>(ts \\<bullet> as)) = srtdw (\\<lambda>a. a \\<noteq> b)\\<cdot>(ts) \\<bullet> as\"\n  apply(induction ts arbitrary: as)\n    apply (rule adm_imp)\n     apply auto\n   apply(rule admI)\n   apply rule+\n   apply (metis (no_types, lifting) approxl3 assoc_sconc is_ub_thelub)\nproof -\n  fix u ts as\n  assume as1: \"u \\<noteq> \\<bottom>\" and as2: \"(\\<And>as. b \\<in> sValues\\<cdot>ts \\<Longrightarrow> srtdw (\\<lambda>a. a \\<noteq> b)\\<cdot>(ts \\<bullet> as) = srtdw (\\<lambda>a. a \\<noteq> b)\\<cdot>ts \\<bullet> as)\"\n       and as3: \"b \\<in> sValues\\<cdot>(u && ts)\"\n  obtain a where a_def: \"updis a = u\" by (metis Exh_Up as1 discr.exhaust) \n  have \"a\\<noteq>b \\<Longrightarrow> b\\<in>sValues\\<cdot>ts\" by (metis UnE a_def as3 lscons_conv sValues2un singletonD) \n  hence \"a\\<noteq>b \\<Longrightarrow> srtdw (\\<lambda>a. a \\<noteq> b)\\<cdot>(\\<up>a\\<bullet> (ts \\<bullet> as)) = srtdw (\\<lambda>a. a \\<noteq> b)\\<cdot>(\\<up>a\\<bullet> ts) \\<bullet> as \" using as2 a_def by auto\n  thus \"srtdw (\\<lambda>a. a \\<noteq> b)\\<cdot>((u && ts) \\<bullet> as) = srtdw (\\<lambda>a. a \\<noteq> b)\\<cdot>(u && ts) \\<bullet> as \"\n    by (smt a_def inject_scons lscons_conv sconc_scons stwbl_f stwbl_srtdw) \nqed\n\n(* stwbl concatenation *)\nlemma stwbl_conc[simp]: \"b\\<in>sValues\\<cdot>ts \\<Longrightarrow>\n    (stwbl (\\<lambda>a. a \\<noteq> b)\\<cdot>(stwbl (\\<lambda>a. a \\<noteq> b)\\<cdot>ts \\<bullet> xs)) =\n    (stwbl (\\<lambda>a. a \\<noteq> b)\\<cdot>(ts))\"\n  apply(induction ts)\n    apply(rule adm_imp)\n     apply simp\n    apply(rule admI)\n    apply (metis (no_types, lifting) ch2ch_Rep_cfunR contlub_cfun_arg inf_chainl4 lub_eqI lub_finch2 sconc_fst_inf stwbl2stbl)\n   apply simp\n  by (smt UnE assoc_sconc sValues2un singletonD stream.con_rews(2) stream.sel_rews(5) stwbl_f stwbl_t surj_scons)\n\n\n(* ----------------------------------------------------------------------- *)\nsection \\<open>@{term siterateBlock}\\<close>\n(* ----------------------------------------------------------------------- *)\n\n(* block-iterating the function f on the stream x is equivalent to the stream produced by concatenating x\n   and the iteration of f on x shifted by another application of f *)\nlemma siterateBlock_unfold: \"siterateBlock f x = x \\<bullet> siterateBlock f (f x)\"\nby(subst siterateBlock_def [THEN fix_eq2], auto)\n\n(* if g doesn't change the length of the input, then iterating g doesn't either *)\nlemma niterate_len[simp]: assumes \"\\<forall>z. #z = #(g z)\" \n  shows \"#((niterate i g) x) = #x\"\nusing assms by(induction i, auto)\n\n(* dropping i blocks from siterateBlock g x is equivalent to beginning siterateBlock after i iterations\n   of g have already been applied *)\nlemma siterateBlock_sdrop2: assumes \"#x = Fin y\" and \"\\<forall>z. #z = #(g z)\" \n  shows \"sdrop (y*i)\\<cdot>(siterateBlock g x) = siterateBlock g ((niterate i g) x)\"\napply (induction i, auto)\nby (metis assms(1) assms(2) niterate_len sdrop_plus sdropl6 siterateBlock_unfold)\n\n(* the y*i'th element of siterateBlock is the same as the head of the i'th iteration *)\nlemma siterateBlock_snth: assumes \"#x = Fin y\" and \"\\<forall>z. #z = #(g z)\" and \"#x > Fin 0\" \n  shows \"snth (y*i) (siterateBlock g x) = shd ((niterate i g) x)\"\nproof -\n  have eq1: \"sdrop (y*i)\\<cdot>(siterateBlock g x) = siterateBlock g ((niterate i g) x)\" using assms(1) assms(2) siterateBlock_sdrop2 by blast \n\n  have \"#((niterate i g) x) > 0\" by (metis Fin_02bot assms(2) assms(3) lnzero_def niterate_len)  \n  hence \"shd (siterateBlock g ((niterate i g) x)) = shd (((niterate i g) x))\" by (metis Fin_0 minimal monofun_cfun_arg sconc_snd_empty siterateBlock_unfold snth_less snth_shd)\n  thus ?thesis by (simp add: eq1 snth_def) \nqed\n\n(* dropping a single block from siterateBlock is equivalent to beginning the iteration with (g x) *)\nlemma siterateBlock_sdrop: assumes \"#x = Fin y\"\n  shows \"sdrop y\\<cdot>(siterateBlock g x) = siterateBlock g (g x)\"\nby (metis assms sdropl6 siterateBlock_unfold)\n\n(* block-iterating the function g on the empty stream produces the empty stream again *)\nlemma siterateBlock_eps[simp]: assumes \"g \\<epsilon> = \\<epsilon>\"\n  shows \"siterateBlock g \\<epsilon> = \\<epsilon>\" \nby(simp add: siterateBlock_def assms)\n\n(* block-iterating the identity on the element x is equivalent to infinitely repeating x *)\nlemma siterateBlock2sinf: \"siterateBlock id x = sinftimes x\"\nby (metis id_apply rek2sinftimes siterateBlock_eps siterateBlock_unfold strict_icycle)\n\n(* siterateBlock doesn't affect infinite streams *)\nlemma siterBlock_inf [simp]: assumes \"#s = \\<infinity>\"\n  shows \"siterateBlock f s = s\"\nby (metis assms sconc_fst_inf siterateBlock_unfold)\n\n(* the first element of siterateBlock doesn't have any applications of g *)\nlemma siterateBlock_shd [simp]: \"shd (siterateBlock g (\\<up>x)) = x\"\nby (metis shd1 siterateBlock_unfold)\n\n(* helper lemma for siterateBlock2siter *)\nlemma siterateBlock2niter: \"snth i (siterateBlock (\\<lambda>s. (smap g\\<cdot>s)) (\\<up>x)) = niterate i g x\" (is \"snth i (?B) = ?N i\")\nproof -\n  have f1: \"#(\\<up>x) = Fin 1\" by simp\n  have \"\\<forall>z. #z = #((\\<lambda>s. (smap g\\<cdot>s)) z)\" by simp \n  hence f2: \" snth (i) (siterateBlock (\\<lambda>s. (smap g\\<cdot>s)) (\\<up>x)) = shd (niterate i (\\<lambda>s. (smap g\\<cdot>s)) (\\<up>x))\"\n  by (metis Fin_0 Fin_Suc One_nat_def f1 lnat.con_rews lnless_def lnzero_def minimal nat_mult_1 siterateBlock_snth) \n  \n  have \"shd (niterate i (\\<lambda>s. (smap g\\<cdot>s)) (\\<up>x)) = niterate i g x\"\n  proof (induction i)\n    case 0 thus ?case by simp\n  next\n    case (Suc i) thus ?case\n    by (smt Fin_0 f1 inject_scons neq0_conv niterate.simps(2) niterate_len slen_smap smap_scons strict_slen surj_scons zero_less_one) \n  qed\n  thus ?thesis by (simp add: f2) \nqed\n\n(* siterateBlock creates an infinitely long stream *)\nlemma siterateBlock_len [simp]: \"#(siterateBlock (\\<lambda>s. (smap g\\<cdot>s)) (\\<up>x)) = \\<infinity>\"\napply (rule infI)\napply (rule allI)\napply (rule_tac x=\"x\" in spec)\napply (induct_tac k, simp+)\napply (metis bot_is_0 lnat.con_rews siterateBlock_unfold slen_scons strict_slen)\nby (metis Fin_Suc lnat.sel_rews(2) sconc_snd_empty siterateBlock_unfold slen_scons smap_scons strict_smap)\n\n(* iterating the identity function commutes with any function f *)\nlemma siterateBlock_smap: \"siterateBlock id (smap f\\<cdot>x) =  smap f\\<cdot>(siterateBlock id x)\"\nby (simp add: siterateBlock2sinf)\n\n(* converting x to a singleton stream and applying siterateBlock using smap g is equivalent to\n   iterating using g directly on x *)\nlemma siterateBlock2siter [simp]: \"siterateBlock (\\<lambda>s. (smap g\\<cdot>s)) (\\<up>x) = siterate g x\" \napply (rule sinf_snt2eq, auto)\nby (simp add: siterateBlock2niter snth_siter) \n\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term sislivespf}\\<close>\n(* ----------------------------------------------------------------------- *)\n\ntext \\<open>Some different formulations and implications of the @{term sislivespf} definition\\<close>\n(* if length of f\\<cdot>x is infinite then also length of x is infinite, and then sislivespf f holds *)\nlemma sislivespfI:\n  \"(\\<And>x. #(f\\<cdot>x) = \\<infinity> \\<Longrightarrow> #x = \\<infinity>) \\<Longrightarrow> sislivespf f\"\nby (simp add: sislivespf_def)\n\n(* if length of x is finite then also length of f\\<cdot>x is finite, and then it holds that sislivespf f *)\nlemma sislivespfI2:\n  \"(\\<And>k. \\<forall>x. #x = Fin k \\<longrightarrow> #(f\\<cdot>x) \\<noteq> \\<infinity>) \\<Longrightarrow> sislivespf f\"\napply (rule sislivespfI)\nby (rule_tac x=\"#x\" in lncases, simp+)\n\n(* if sislivespf f holds and length of x is finite, then also length of f\\<cdot>x is finite *)\nlemma sislivespfD1:\n  \"\\<lbrakk>sislivespf f; #x = Fin k\\<rbrakk> \\<Longrightarrow> #(f\\<cdot>x) \\<noteq> \\<infinity>\"\napply (rule notI)\nby (simp add: sislivespf_def)\n\n(* if sislivespf f holds and f\\<cdot>x has infinite length, then x has infinite length *)\nlemma sislivespfD2:\n  \"\\<lbrakk>sislivespf f; #(f\\<cdot>x) = \\<infinity>\\<rbrakk> \\<Longrightarrow> #x = \\<infinity>\"\nby (simp add: sislivespf_def)\n\n\n(* ----------------------------------------------------------------------- *)\nsection \\<open>Lemmas on lists and streams\\<close>\n(* ----------------------------------------------------------------------- *)\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>@{term list2s}\\<close>\n(* ----------------------------------------------------------------------- *)\n\n(* consing onto a list is equivalent to prepending an element to a stream *)\nlemma [simp]: \"list2s (a#as) = \\<up>a \\<bullet> list2s as\"\nby (simp add: lscons_conv)\n\ndeclare list2s_Suc [simp del]\n\n(* infinite lists don't exist *)\nlemma [simp]: \"#(list2s x) \\<noteq> \\<infinity>\"\nby (induct x, simp+)\n\ntext \\<open>Every finite stream can be converted to a list\\<close>\nlemma s2list_ex: \n  \"#s = Fin k \\<Longrightarrow> \\<exists>l. list2s l = s\"\napply (simp add: atomize_imp)\napply (rule_tac x=\"s\" in spec)\napply (induct_tac k, simp+)\napply (rule_tac x=\"[]\" in exI, simp+)\napply (rule allI, rule impI)\napply (rule_tac x=\"x\" in scases, simp+)\napply (erule_tac x=\"s\" in allE)\napply (drule mp)\napply (simp add: Fin_Suc [THEN sym] del: Fin_Suc)\napply (erule exE)\nby (rule_tac x=\"a # l\" in exI, simp)\n\n(* the empty stream corresponds to the empty list *)\nlemma [simp]: \"s2list \\<epsilon> = []\"\napply (simp add: s2list_def)\napply (rule someI2_ex)\napply (rule_tac x=\"[]\" in exI, simp)\napply (simp add: atomize_imp)\nby (induct_tac x, simp+)\n\n(* the singleton stream corresponds to the singleton list *)\nlemma [simp]: \"s2list (\\<up>a) = [a]\"\napply (simp add: s2list_def)\napply (rule someI2_ex)\napply (rule_tac x=\"[a]\" in exI, simp)\napply (simp add: atomize_imp)\napply (induct_tac x, auto)\nby (case_tac \"list\", simp+)\n\n(* the empty list is the bottom element for lists *)\nlemma [simp]: \"[] \\<sqsubseteq> l\"\nby (simp add: sq_le_list)\n\ntext \\<open>The prefix relation translates from lists to streams\\<close>\nlemma list2s_emb: \"\\<lbrakk>#s \\<noteq> \\<infinity>; #s' \\<noteq> \\<infinity>\\<rbrakk> \\<Longrightarrow> (s2list s \\<sqsubseteq> s2list s') = (s \\<sqsubseteq> s')\"\napply (simp add: s2list_def)\napply (rule someI2_ex)\napply (rule_tac x=\"#s'\" in lncases, simp) \napply (frule s2list_ex, simp)\napply (rule someI2_ex)\napply (rule_tac x=\"#s\" in lncases, simp) \napply (frule s2list_ex, simp)\napply (rule iffI)\napply (drule sym, drule sym, simp)\napply (simp add: sq_le_list)\nby (simp add: sq_le_list)\n\ntext \\<open>@{term list2s} is monotone\\<close>\nlemma list2s_mono: \"l \\<sqsubseteq> l' \\<Longrightarrow> list2s l \\<sqsubseteq> list2s l'\"\nby (simp add: sq_le_list)\n\ntext \\<open>Prepending a fixed element to a list is a monotone function\\<close>\nlemma monofun_lcons: \"monofun (\\<lambda>l. a # l)\"\napply (rule monofunI)\napply (simp add: atomize_imp)\napply (rule_tac x=\"a\" in spec)\napply (induct_tac x, simp+)\napply (rule allI)\napply (simp add: sq_le_list)\napply (rule allI)\napply (rule impI)\napply (simp add: sq_le_list)\nby (rule monofun_cfun_arg, simp)\n\ntext \\<open>Head and rest on streams translate to head and rest on lists\\<close>\nlemma s2list2lcons: \"#s \\<noteq> \\<infinity> \\<Longrightarrow> s2list (\\<up>a \\<bullet> s) = a # (s2list s)\"\napply (rule_tac x=\"#s\" in lncases, simp+)\napply (simp add: atomize_imp)\napply (rule_tac x=\"s\" in spec)\napply (rule_tac x=\"a\" in spec)\napply (induct_tac k, simp+)\napply (rule allI,rule allI, rule impI)\napply (rule_tac x=\"xa\" in scases, simp+)\napply (simp add: s2list_def)\napply (rule someI2_ex)\napply (frule s2list_ex, simp)\napply (rule someI2_ex)\napply (frule s2list_ex)\napply (erule exE)\napply (rule_tac x=\"x#a#l\" in exI, simp+)\nby (rule list2s_inj [THEN iffD1], simp)\n\ntext \\<open>@{term s2list} is left-inverse to @{term list2s}\\<close>\nlemma [simp]: \"s2list (list2s l) = l\"\napply (induct_tac l, simp+)\nby (subst s2list2lcons, simp+)\n\ntext \\<open>Evaluation of @{term list2s} from right to left\\<close>\nlemma slistl5[simp]: \"list2s (l @ [m]) = list2s l \\<bullet> \\<up>m\"\nby (induct_tac l, simp+)\n\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>List- and stream-processing functions\\<close>\n(* ----------------------------------------------------------------------- *)\n\n(* concatenating streams corresponds to concatenating lists *)\nlemma listConcat: \"<l1> \\<bullet> <l2> = <(l1 @ l2)>\"\napply(induction l1)\nby auto\n\n(* smap for streams is equivalent to map for lists *)\nlemma smap2map: \"smap g\\<cdot>(<ls>) = <(map g ls)>\"\napply(induction ls)\nby auto\n\n(* the notion of length is the same for streams as for lists *)\nlemma list2streamFin: \"#(<ls>) = Fin (length ls)\"\napply(induction ls)\nby auto\n\ntext \\<open>Monotone list-processing functions induce monotone stream-processing functions\n  by applying them to the stream's k-element prefix\\<close>\nlemma mono_slpf2spf:\n  \"monofun f \\<Longrightarrow> monofun (\\<lambda>s. list2s (f (s2list (stake k\\<cdot>s))))\"\napply (rule monofunI)\napply (simp add: atomize_imp)\napply (rule_tac x=\"y\" in spec)\napply (rule_tac x=\"x\" in spec)\napply (induct_tac k, simp+)\napply (rule impI)\napply (drule mp, assumption)\napply (rule allI)+\napply (rule impI)\napply (drule lessD, simp)\napply (erule disjE, simp)\napply (rule list2s_mono)\napply (rule_tac f=\"f\" in monofunE,simp+)\napply (erule exE)+\napply (erule conjE)\napply (erule exE,simp)\napply (erule conjE)\napply (rule list2s_mono)\napply (rule_tac f=\"f\" in monofunE,simp+)\napply (rule_tac x=\"xa\" in scases,simp)\napply (subst list2s_emb,simp+)\napply (rule monofun_cfun_arg)+\nby simp\n\ntext \\<open>Applying a monotone list-processing function to the @{term k}-element prefix of a stream\n  is monotone with respect to @{term k}\\<close>\nlemma chain_slpf2spf:\n  \"monofun f \\<Longrightarrow> list2s (f (s2list (stake i\\<cdot>x))) \\<sqsubseteq> list2s (f (s2list (stake (Suc i)\\<cdot>x)))\"\napply (rule list2s_mono)\napply (rule_tac f=\"f\" in monofunE,simp+)\napply (subst list2s_emb,simp+)\nby (rule chainE, simp)\n\ntext \\<open>Now, a list-processing function is converted to a stream-processing one by building\n  the LUB of applying the function to all prefixes of the stream\\<close>\nlemma slpf2spfl_contl:\n  \"monofun f \\<Longrightarrow> \n  cont (\\<lambda>s. (\\<Squnion>k. list2s (f (s2list (stake k\\<cdot>s)))))\"\napply (rule cont2cont_lub)\napply (rule chainI)\napply (rule chain_slpf2spf, simp)\napply (rule pr_contI) \napply (rule mono_slpf2spf, assumption) \napply (rule allI)\nby (rule_tac x=\"k\" in exI, simp)\n\ntext \\<open>The output function of @{term slpf2spf} is continuous\\<close>\nlemma slpf2spf_cont:\n  \"monofun f \\<Longrightarrow> \n     (\\<Lambda> s. (\\<Squnion>k. list2s (f (s2list (stake k\\<cdot>s)))))\\<cdot>s = (\\<Squnion>k. list2s (f (s2list (stake k\\<cdot>s))))\"\napply (subst beta_cfun)\nby (rule slpf2spfl_contl, assumption, simp)\n\ntext \\<open>Applying @{term \"slpf2spf f\"} to an element @{term x}\\<close>\nlemma slpf2spf_def2:\n  \"monofun f \\<Longrightarrow> slpf2spf f\\<cdot>x = (\\<Squnion>k. list2s (f (s2list (stake k\\<cdot>x))))\"\napply (simp add: slpf2spf_def)\nby (rule slpf2spf_cont)\n\ntext \\<open>The output of @{term slpf2spf} is live\\<close>\nlemma sislivespf_slpf2spf:\n  \"monofun f \\<Longrightarrow> sislivespf (slpf2spf f)\"\napply (rule sislivespfI)\napply (rule_tac x=\"#x\" in lncases, assumption)\napply (simp add: slpf2spf_def2)\napply (subgoal_tac \n  \"finite_chain (\\<lambda>k. list2s (f (s2list (stake k\\<cdot>x))))\")\napply (simp add: finite_chain_def)\napply (erule conjE, erule exE)\napply (frule lub_finch1, simp+)\napply (frule lub_eqI, simp)\napply (simp add: finite_chain_def, rule conjI)\napply (rule chainI)\napply (rule chain_slpf2spf, assumption)\napply (rule_tac x=\"k\" in exI)\napply (simp add: max_in_chain_def)\napply (rule allI, rule impI)\napply (subgoal_tac \"stake j\\<cdot>x = stake k\\<cdot>x\", simp)\napply (subst fin2stake [THEN sym], simp+)\nby (simp add: min_def)\n\ntext \\<open>Any live stream-processing function can be converted to a monotone\n  list-processing function\\<close>\nlemma sspf2lpf_mono: \n  \"sislivespf f \\<Longrightarrow> monofun (sspf2lpf f)\"\napply (rule monofunI)\napply (simp add: sspf2lpf_def)\napply (subst list2s_emb)\napply (rule notI, frule sislivespfD2, simp+)+\napply (rule monofun_cfun_arg)\nby (simp add: sq_le_list)\n\ntext \\<open>The result of applying continuous functions to infinite inputs\n  does not change on even longer inputs\\<close>\nlemma monofun_spf_ubl[simp]:\n  \"#(f\\<cdot>x) = \\<infinity> \\<Longrightarrow> f\\<cdot>(x \\<bullet> y) = f\\<cdot>x\"\napply (rule sym)\napply (rule eq_less_and_fst_inf [of \"f\\<cdot>x\"])\nby (rule monofun_cfun_arg, auto)\n\ntext \\<open>Some special results about @{term smap} and injective functions\n  on streams of natural successors\\<close>\nlemma inj_sfilter_smap_siteratel1:\n  \"inj f \\<Longrightarrow> sfilter {f j}\\<cdot>(smap f\\<cdot>(siterate Suc (Suc (k + j)))) = \\<epsilon>\"\napply (rule ex_snth_in_sfilter_nempty [rule_format])\napply (simp add: atomize_imp)\napply (rule impI)\napply (subst smap_snth_lemma, simp+)\napply (simp add: snth_siterate_Suc)\napply (rule notI)\nby (frule_tac x=\"Suc (n+(k+j))\" and y=\"j\" in injD, simp+)\n\n(* an element m can't appear infinitely often in a stream produced by mapping an injective function f\n   over the natural numbers *)\nlemma inj_sfilter_smap_siteratel2[simp]:\n  \"inj f \\<Longrightarrow> #(sfilter {m}\\<cdot>(smap f\\<cdot>(siterate Suc j))) \\<noteq> \\<infinity>\"\napply (case_tac \"m\\<in>range f\")\napply (rule_tac b=\"m\" and f=\"f\" in rangeE, simp+)\napply (rule notI)\napply (drule_tac n=\"Suc x\" in slen_sfilter_sdrop [rule_format], simp)\napply (simp add: sdrop_siterate)\napply (simp add: inj_sfilter_smap_siteratel1)\nby (simp add: sfilter_smap_nrange)\n\n\n(* ----------------------------------------------------------------------- *)\nsubsection \\<open>compact lemmas\\<close>\n(* ----------------------------------------------------------------------- *)\n\n(* finite chains have lub  *)\nlemma finChainapprox: assumes \"chain Y\" and \"# (\\<Squnion>i. Y i) =Fin  k\" \n  shows \"\\<exists>i. Y i = (\\<Squnion>i. Y i)\"\n  using assms(1) assms(2) inf_chainl4 lub_eqI lub_finch2 by fastforce\n\n(* finite streams are compact *)\nlemma finCompact: assumes \"#s = Fin k\"\n  shows \"compact s\"\n  proof (rule compactI2)\n  fix Y assume as1: \"chain Y\" and as2: \"s \\<sqsubseteq> (\\<Squnion>i. Y i)\"\n  show \"\\<exists>i. s \\<sqsubseteq> Y i\" by (metis approxl2 as1 as2 assms finChainapprox lub_approx stream.take_below)\nqed\n\n(* the empty stream is compact *)\nlemma \"compact \\<epsilon>\"\n  by simp\n\n(* \\<up>x is compact *)\nlemma \"compact (\\<up>x)\"\n  by (simp add: sup'_def)\n\n(* not so compact stuff *)\nlemma nCompact: assumes \"chain Y\" and \"\\<forall>i. (Y i \\<sqsubseteq> x)\" and \"\\<forall>i.  (Y i \\<noteq> x)\" and \"x \\<sqsubseteq> (\\<Squnion>i. Y i)\"\n  shows \"\\<not>(compact x)\"\n  by (meson assms below_antisym compactD2)\n\n(* infinite streams are not compact *)\nlemma infNCompact: assumes \"#s = \\<infinity>\"\n  shows\"\\<not> (compact s)\"\n  proof (rule nCompact)\n     show \"chain (\\<lambda>i. stake i\\<cdot>s)\" by simp\n    show \"\\<forall>i. stake i\\<cdot>s \\<sqsubseteq> s\" by simp\n   show \"\\<forall>i. stake i\\<cdot>s \\<noteq> s\" by (metis Inf'_neq_0 assms fair_sdrop sdropostake strict_slen)\n  show \"s \\<sqsubseteq> (\\<Squnion> i. stake i\\<cdot>s)\" by (simp add: reach_stream)\nqed\n\n(* sinftimes (\\<up>x) is not compact *)\nlemma \"\\<not> (compact (sinftimes (\\<up>x)))\"\n  by (simp add: infNCompact slen_sinftimes)\n\n(* add function *)\ndefinition add:: \"nat stream \\<rightarrow> nat stream \\<rightarrow> nat stream\" where\n\"add \\<equiv> \\<Lambda> s1 s2 . smap (\\<lambda> s3. (fst s3) + (snd s3))\\<cdot>(szip\\<cdot>s1\\<cdot>s2)\"\n\n(* add is continuous *)\nlemma \"cont (\\<lambda> s1 s2 . smap (\\<lambda> s3. (fst s3) + (snd s3))\\<cdot>(szip\\<cdot>s1\\<cdot>s2))\"\nby simp\n\n(* add returns the same result as merge plus *)\nlemma \"add = merge plus\"\nby(simp add: add_def merge_def)\n\n(* unfolding rule for add *)\nlemma add_unfold: \"add\\<cdot>(\\<up>x \\<bullet> xs)\\<cdot>(\\<up>y\\<bullet> ys) = \\<up>(x+y) \\<bullet> add\\<cdot>xs\\<cdot>ys\"\n  by(simp add: add_def)\n\n(* relation between snth and add *)\nlemma add_snth: \"Fin n <#xs \\<Longrightarrow>Fin n < #ys \\<Longrightarrow> snth n (add\\<cdot>xs\\<cdot>ys) = snth n xs + snth n ys\"\n  apply(induction n arbitrary: xs ys)\n   apply (metis Fin_02bot add_unfold lnless_def lnzero_def shd1 slen_empty_eq snth_shd surj_scons)\n  by (smt Fin_Suc Fin_leq_Suc_leq Suc_eq_plus1_left add_unfold inject_lnsuc less2eq less2lnleD lnle_conv lnless_def lnsuc_lnle_emb sconc_snd_empty sdropostake shd1 slen_scons snth_rt snth_scons split_streaml1 stream.take_strict surj_scons ub_slen_stake)\n\n(* add applied to the empty stream always returns the empty stream *)\nlemma add_eps1[simp]: \"add\\<cdot>\\<epsilon>\\<cdot>ys = \\<epsilon>\"\n  by(simp add: add_def)\n\n(* add applied to the empty stream always returns the empty stream *)\nlemma add_eps2[simp]: \"add\\<cdot>xs\\<cdot>\\<epsilon> = \\<epsilon>\"\n  by(simp add: add_def)\n\n(* relation between srt and add *)\nlemma [simp]: \"srt\\<cdot>(add\\<cdot>(\\<up>a \\<bullet> as)\\<cdot>(\\<up>b \\<bullet> bs)) = add\\<cdot>as\\<cdot>bs\"\n  by (simp add: add_unfold)\n\n(* helper lemma for commutativity of add *)\nlemma add_commu_helper: assumes \"\\<And>y. add\\<cdot>x\\<cdot>y = add\\<cdot>y\\<cdot>x\"\n  shows \"add\\<cdot>(\\<up>a \\<bullet> x)\\<cdot>y = add\\<cdot>y\\<cdot>(\\<up>a \\<bullet> x)\"\n  apply(cases \"y = \\<epsilon>\")\n   apply auto[1]\n  by (metis (no_types, lifting) Groups.add_ac(2) assms add_unfold surj_scons)\n\n(* the add function is commutative *)\nlemma add_commutative: \"add\\<cdot>x\\<cdot>y = add\\<cdot>y\\<cdot>x\"\n  apply(induction x arbitrary: y)\n    apply(simp_all)\n  by (metis add_commu_helper stream.con_rews(2) stream.sel_rews(5) surj_scons)\n\n(* relation between add, lnsuc and srt *)\nlemma add_len: assumes \"xs\\<noteq>\\<bottom>\" and \"u\\<noteq>\\<bottom>\"\n  shows \"#(add\\<cdot>xs\\<cdot>(u && ys)) = lnsuc\\<cdot>(#(add\\<cdot>(srt\\<cdot>xs)\\<cdot>ys))\"\n  by (metis (no_types, lifting) add_unfold assms(1) assms(2) slen_scons stream.con_rews(2) stream.sel_rews(5) surj_scons)\n\n(* helper lemma for add_slen *)\nlemma add_slen_help [simp]: \"#xs \\<sqsubseteq> #ys \\<Longrightarrow> #(add\\<cdot>xs\\<cdot>ys) = #xs\"\n  apply(induction xs arbitrary: ys)\n    apply(rule admI)\n    apply rule+\n    apply (smt ch2ch_Rep_cfunL ch2ch_Rep_cfunR contlub_cfun_arg contlub_cfun_fun lub_below_iff lub_eq)\n   apply(simp)\n  proof -\n  fix u\n  fix xs ys :: \"nat stream\"\n  assume as1: \"u \\<noteq> \\<bottom>\" and as2: \"(\\<And>ys. #xs \\<sqsubseteq> #ys \\<Longrightarrow> #(add\\<cdot>xs\\<cdot>ys) = #xs)\" and as3: \" #(u && xs) \\<sqsubseteq> #ys\"\n  obtain a where a_def: \"updis a = u\" by (metis as1 discr.exhaust upE)\n  show \"#(add\\<cdot>(u && xs)\\<cdot>ys) = #(u && xs)\"\n  proof (cases \"ys = \\<epsilon>\")\n   case True thus ?thesis using add_eps2 as3 bot_is_0 bottomI strict_slen by auto\n  next\n  case False\n  hence \"#(add\\<cdot>xs\\<cdot>(srt\\<cdot>ys)) = #xs\" by (metis a_def as2 as3 lnat.inverts lscons_conv slen_scons surj_scons)\n  thus ?thesis by (metis False \\<open>updis a = u\\<close> add_unfold lscons_conv slen_scons surj_scons)\n  qed\nqed\n\n(* the length of the stream returned by add is the minimum of the length of the two input streams of add *)\nlemma add_slen [simp]: \"#(add\\<cdot>x\\<cdot>y) = min (#x) (#y)\"\n  apply(cases \"#x\\<le>#y\")\n   apply (metis add_slen_help lnle_def min.commute min_absorb2)\n  by (metis add_commutative add_slen_help linear lnle_def min.absorb2)\n\n(* if the stream has infinite length, the length of the stream returned by add is the length of the second input stream of add *)\nlemma add_slen_sinf [simp]: \n  shows \" #xs = \\<infinity> \\<Longrightarrow> #(add\\<cdot>xs\\<cdot>ys) =(#ys)\"\n  by (simp add: min.absorb2)\n\n(* relation between snth and add *)\nlemma snth_add: \"Fin n < #ys \\<Longrightarrow> snth n (add\\<cdot>\\<up>x\\<^sup>\\<infinity>\\<cdot>ys) = snth n (smap (\\<lambda>z. z + x)\\<cdot>ys)\"\n  apply(induction n arbitrary: ys)\n   apply (smt Fin_02bot add.commute add_unfold lnless_def lnzero_def shd1 sinftimes_unfold slen_empty_eq smap_snth_lemma snth_shd surj_scons)\n  by (smt Fin_Suc add_slen_sinf add_unfold lnle_conv lnless_def lnsuc_lnle_emb sinftimes_unfold slen_empty_eq slen_scons slen_sinftimes slen_smap smap_snth_lemma snth_scons strict_icycle surj_scons)\n\n(* relation between add and smap *)\nlemma add2smap: \"add\\<cdot>((\\<up>x)\\<^sup>\\<infinity>)\\<cdot>ys = smap (\\<lambda>z. z+x)\\<cdot>ys\"\n  apply(rule snths_eq)\n   apply auto[1]\n  by (metis add_slen_sinf lnat.con_rews lnzero_def lscons_conv slen_empty_eq slen_scons slen_sinftimes snth_add sup'_def)\n\n(* helper lemma for add2smapsu *)\nlemma add2smapsuc_helper:\" Suc = (\\<lambda>z. z+1)\"\nby auto\n\n(* relation between add and smap applied to (Suc)\\<cdot>sc *)\nlemma inf_srcdups_stake_snth_sdrop:\n  assumes \"#s = \\<infinity>\" and \"srcdups\\<cdot>s = srcdups\\<cdot>(stake k\\<cdot>s)\"\n  shows \"snth n (sdrop k\\<cdot>s) = snth k s\"\nproof (induction n)\n  case 0\n  then show ?case\n    by (simp add: snth_def)\nnext\n  case (Suc n)\n  then have \"snth (Suc n) (sdrop k\\<cdot>s) \\<noteq> snth k s \\<Longrightarrow> False\"\n  proof -\n    assume \"snth (Suc n) (sdrop k\\<cdot>s) \\<noteq> snth k s\"\n    have \"#s = \\<infinity>\"\n      by (simp add: assms(1))\n    moreover have \"snth (n + k) s \\<noteq> snth (n + k + 1) s\"\n      by (metis Suc.IH Suc.prems Suc_eq_plus1 \\<open>snth (Suc n) (sdrop k\\<cdot>s) \\<noteq> snth k s\\<close> semiring_normalization_rules(23) snth_sdrop)\n    ultimately have \"srcdups\\<cdot>(stake (n + k + 1)\\<cdot>s) \\<noteq> srcdups\\<cdot>s\"\n      by (metis add2smapsuc_helper srcdups_snth_stake_inf)\n    moreover have \"srcdups\\<cdot>(stake (n + k + 1)\\<cdot>s) = srcdups\\<cdot>(stake k\\<cdot>s)\"\n    proof -\n      have \"srcdups\\<cdot>(stake k\\<cdot>s) \\<sqsubseteq> srcdups\\<cdot>(stake (n + k + 1)\\<cdot>s)\"\n      proof -\n        have \"k + (1 + n) = n + k + 1\"\n          by simp\n        then show ?thesis\n          by (metis (no_types) minimal monofun_cfun_arg sconc_snd_empty stake_add)\n      qed\n      then show ?thesis\n        by (metis assms(2) below_antisym monofun_cfun_arg stream.take_below)\n    qed\n    ultimately show \"False\"\n      by (simp add: assms(2))\n  qed\n  then show ?case\n    by blast\nqed\n\nlemma srcdups_split:\n  assumes \"#(srcdups\\<cdot>s) < \\<infinity>\" and \"#s = \\<infinity>\"\n  obtains n where \"s = (stake n\\<cdot>s) \\<bullet> ((\\<up>(snth n s))\\<^sup>\\<infinity>)\"\nproof -\n  obtain k where \"srcdups\\<cdot>s = srcdups\\<cdot>(stake k\\<cdot>s)\"\n    by (meson assms(1) fun_approxl2 lnat_well_h2)\n  then have \"sdrop k\\<cdot>s \\<noteq> srt\\<cdot>(sdrop k\\<cdot>s) \\<Longrightarrow> False\"\n  proof -\n    assume \"sdrop k\\<cdot>s \\<noteq> srt\\<cdot>(sdrop k\\<cdot>s)\"\n    moreover have \"#(sdrop k\\<cdot>s) = #(srt\\<cdot>(sdrop k\\<cdot>s))\"\n      by (metis assms(2) fair_sdrop sdrop_back_rt)\n    ultimately obtain n where \"snth n (sdrop k\\<cdot>s) \\<noteq> snth n (srt\\<cdot>(sdrop k\\<cdot>s))\"\n      using snths_eq by blast\n    moreover have \"snth n (srt\\<cdot>(sdrop k\\<cdot>s)) = snth k s\"\n      by (metis \\<open>srcdups\\<cdot>s = srcdups\\<cdot>(stake k\\<cdot>s)\\<close> assms(2) inf_srcdups_stake_snth_sdrop snth_rt)\n    then show \"False\"\n      by (metis (no_types) \\<open>snth n (srt\\<cdot>(sdrop k\\<cdot>s)) = snth k s\\<close> \\<open>srcdups\\<cdot>s = srcdups\\<cdot>(stake k\\<cdot>s)\\<close> assms(2) calculation inf_srcdups_stake_snth_sdrop)\n  qed\n  then have \"sdrop k\\<cdot>s = \\<up>(snth k s) \\<bullet> (sdrop k\\<cdot>s)\"\n    by (metis Inf'_neq_0 assms(2) fair_sdrop snth_def strict_slen surj_scons)\n  then have \"sdrop k\\<cdot>s = ((\\<up>(snth k s))\\<^sup>\\<infinity>)\"\n    using s2sinftimes by blast\n  then have \"s = (stake k\\<cdot>s) \\<bullet> ((\\<up>(snth k s))\\<^sup>\\<infinity>)\"\n    by (metis split_streaml1)\n  thus ?thesis\n    by (metis that)\nqed\n\nlemma add2smapsuc:\"add\\<cdot>((\\<up>1)\\<^sup>\\<infinity>)\\<cdot>s=smap (Suc)\\<cdot>s\"\n  by (metis add_eps2 add_unfold plus_1_eq_Suc rek2smap sinftimes_unfold)\n\n(* relation between add and smap *)\nlemma add2smap_f: \"add\\<cdot>((\\<up>x)\\<^sup>\\<infinity>) = smap (\\<lambda>z. z+x)\"\napply(rule cfun_eqI)\nby (metis (no_types, lifting) add_commutative add_eps2 add_unfold rek2smap sinftimes_unfold)\n\n(* relation between shd and updis *)\nlemma shd_updis:\"shd (u && s) = (THE a. updis a= u)\"\nby(simp add: shd_def the_equality, metis)\n\n(* smap applied to the identity + stream returns the stream *)\nlemma smap_id:\"smap (id)\\<cdot>s = s\"\napply(induction s, auto)\napply(simp add: smap_hd_rst)\nusing stream.con_rews(2) surj_scons by fastforce\n\n(* smap applied to the identity + stream returns the identity + stream *)\nlemma smapid2ID_h:\"smap id\\<cdot> s = ID\\<cdot> s\"\napply(simp add: ID_def)\nby(rule snths_eq, auto, simp add: smap_id)\n\n(* smap applied to the identity returns the identity *)\nlemma smapid2ID:\"smap id= ID\"\nby(rule cfun_eqI, simp add: smapid2ID_h)\n\n(* add applied to \\<up>0\\<infinity>\\<cdot>s returns the identity + stream *)\nlemma add2ID_h:\"add\\<cdot>((\\<up>0)\\<^sup>\\<infinity>)\\<cdot>s=ID\\<cdot>s\"\nproof(induction s rule: ind)\n  case 1\n  then show ?case \n    by simp\nnext\ncase 2\n  then show ?case\n    by simp\nnext\n  case (3 a s)\n  then show ?case\n    by (metis ID1 add_unfold semiring_normalization_rules(5) sinftimes_unfold)\nqed\n\n(* add applied to \\<up>0\\<infinity> returns the identity *)\nlemma add2ID:\"add\\<cdot>\\<up>0\\<^sup>\\<infinity> = ID\"\nby (simp add: add2ID_h cfun_eqI)\n\n(*\n(* Setup type relator for streams*)\n\n(* TODO: Remove Warning\n  https://fa.isabelle.narkive.com/wKVBUrdK/isabelle-setup-lifting-no-relator-for-the-type-warning\n  HOL/Library/Quotient_Set.thy \n  *)\ndefinition \"rel_stream R x y \\<equiv> \\<forall>(e1::'e::countable) (e2::'f::countable). R e1 e2 \\<longrightarrow> e1\\<in> sValues\\<cdot>x \\<longleftrightarrow> e2\\<in> sValues\\<cdot>y\" (*Does not work*)\n\ndefinition vstream :: \"('a \\<Rightarrow> 'b) \\<Rightarrow> 'b stream \\<Rightarrow> 'a stream\" (*Probably also does not work*)\n  where \"vstream f s \\<equiv> smap (inv f)\\<cdot>s\"\n\nlemma stream_quotient [quot_thm]:\n  assumes \"Quotient3 R Abs Rep\"\n  shows \"Quotient3 (rel_stream R) (vstream Rep) (vstream Abs)\"\nproof (rule Quotient3I)\n  from assms have \"\\<And>x. Abs (Rep x) = x\" by (rule Quotient3_abs_rep)\n  then show \"\\<And>xs. vstream Rep (vstream Abs xs) = xs\"\n    unfolding vstream_def sorry\nnext\n  show \"\\<And>xs. rel_stream R (vstream Abs xs) (vstream Abs xs)\"\n    unfolding rel_stream_def vstream_def\n    apply auto sorry\nnext\n  fix r s\n  show \"rel_stream R r s = (rel_stream R r r \\<and> rel_stream R s s \\<and> vstream Rep r = vstream Rep s)\"\n    unfolding rel_stream_def vstream_def set_eq_iff\n    apply auto sorry\nqed\n\ndeclare [[mapQ3 stream = (rel_stream, stream_quotient)]]\n*)\n\nend\n(*>*)", "meta": {"author": "yyisgladiator", "repo": "demo", "sha": "2a57300dfa7268721c78c233ee6b0a5454acce1f", "save_path": "github-repos/isabelle/yyisgladiator-demo", "path": "github-repos/isabelle/yyisgladiator-demo/demo-2a57300dfa7268721c78c233ee6b0a5454acce1f/src/stream/Stream.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632979641571, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.265071134311433}}
{"text": "theory DiscreteSyntax\n  imports Complex_Main\n         Permutation\n         Ordinary_Differential_Equations.Flow\nbegin\n(*Ordinary_Differential_Equations.Flow*)\n\nsubsection \\<open>Syntax\\<close>\n\ntype_synonym sample_time = int\ntype_synonym var = char \ntype_synonym offset = nat\ntype_synonym outupd = \"real list \\<Rightarrow> real\"\n\n\\<comment> \\<open>input vars, output vars, input time offsets, sample time, output functions\\<close>\ndatatype block = Block \"var list\" \"var list\" \"offset list\" \"sample_time\"\n         \"outupd list\" \n(*offset is a para to get pre value, e.g. y(kn) = s((k-1)n).\n  we assume each output corresponds to a same offset for all inputs*)\n\n\n\nfun get_inputs :: \"block \\<Rightarrow> var list\" where\n  \"get_inputs (Block a _ _ _ _) = a\"\n\nfun get_outputs :: \"block \\<Rightarrow> var list\" where\n  \"get_outputs (Block _ c _ _ _) = c\"\n\nfun get_sample_time :: \"block \\<Rightarrow> sample_time\" where\n  \"get_sample_time (Block _ _ _ c _) = c\"\n\nfun get_offsets :: \"block \\<Rightarrow> offset list\" where \n  \"get_offsets (Block _ _ c _ _) = c\"\n\nfun get_outupd :: \"block \\<Rightarrow> outupd list\" where\n  \"get_outupd (Block _ _ _ _ d) = d\"\n\n\ndefinition \"Available b = ((length (get_offsets b)) = (length (get_outputs b))\n    \\<and> ((length (get_outputs b)) = (length (get_outupd b)))\n    \\<and> (\\<forall>i j. i < j \\<and> j < (length (get_outputs b)) \\<and> j \\<ge> 0 \n  \\<longrightarrow> (nth (get_outputs b) i) \\<noteq> (nth (get_outputs b) j)) \\<and> ((\\<forall>i. i \\<ge> 0 \\<and> i < (length (get_offsets b))\n  \\<longrightarrow>  ((nth (get_offsets b) i) \\<ge> 0)) \\<and> \n  (set (get_outputs b) \\<inter> set (get_inputs b) = {}) \\<and> (get_sample_time b \\<ge>  0)))\"\n\ndefinition \"Unique bl = (\\<forall>i j. i < j \\<and> j < (length bl) \\<and> i \\<ge> 0 \\<longrightarrow> (nth bl i) \\<noteq> (nth bl j))\"\n\ndefinition \"Unique' bl = distinct bl\"\n\nlemma Unique'_eq: \"Unique bl \\<Longrightarrow> Unique' bl\"\n  unfolding Unique_def Unique'_def\nproof(induction bl)\n  case Nil\n  then show ?case by simp\nnext\n  case (Cons a bl)\n  then show ?case unfolding distinct.simps\n    by (metis Suc_less_eq bot_nat_0.extremum in_set_conv_nth \n        length_Cons nth_Cons_0 nth_Cons_Suc zero_less_Suc)\nqed\n\nlemma Unique_eq: \"Unique' bl \\<Longrightarrow> Unique bl\"\n  unfolding Unique_def Unique'_def\nproof(induction bl)\n  case Nil\n  then show ?case by simp\nnext\n  case (Cons a bl)\n  then show ?case unfolding distinct.simps\n    by (metis Cons.prems index_first index_nth_id)\nqed\n\nlemma Unique_lemma: \"Unique (a#bl) \\<Longrightarrow> Unique bl\"\n  unfolding Unique_def\n  by (metis Suc_less_eq bot_nat_0.extremum length_Cons nth_Cons_Suc)\n\nlemma Unique_lemma2: \"Unique (bl@[a]) \\<Longrightarrow> Unique bl\"\n  unfolding Unique_def\n  by (smt (verit, del_insts) Suc_lessD length_append_singleton lessI less_trans_Suc nth_append)\n\nlemma Unique_remove: \"a \\<in> set bl \\<Longrightarrow> Unique bl \\<Longrightarrow> Unique (remove1 a bl)\"\nproof(induction bl)\n  case Nil\n  then show ?case by simp\nnext\n  case (Cons b bl)\n  then show ?case\n  proof(cases \"a = b\")\n    case True\n    then show ?thesis using Cons(3) Unique_lemma by auto\n  next\n    case False\n    have 1: \"Unique (remove1 a bl)\"\n      using Cons False Unique_lemma by fastforce\n    have 2: \"\\<forall>j. j < (length bl) \\<and> j \\<ge> 0 \\<longrightarrow> b \\<noteq> (nth bl j)\"\n      using Cons(3) unfolding Unique_def\n      by (metis Suc_less_eq bot_nat_0.extremum length_Cons nth_Cons_0 nth_Cons_Suc zero_less_Suc)\n    have 3: \"\\<forall>j. j < (length (remove1 a bl)) \\<and> j \\<ge> 0 \\<longrightarrow> b \\<noteq> (nth (remove1 a bl) j)\"\n      using 2 \n      by (metis in_set_conv_nth le0 notin_set_remove1)\n    have 4: \"remove1 a (b # bl) = b#(remove1 a bl)\"\n      using False by auto\n    have 5: \"Unique (b#(remove1 a bl))\"\n      using 1 3 by (smt (verit, best) Suc_leI Unique_def add_diff_cancel_left' \n          bot_nat_0.extremum le_0_eq le_imp_less_Suc length_Cons less_Suc_eq \n          less_Suc_eq_0_disj nth_Cons' plus_1_eq_Suc)\n    then show ?thesis using 4 by auto\n  qed\nqed\n\nlemma Unique_add: \"\\<forall>j. j < (length bl) \\<and> j \\<ge> 0 \\<longrightarrow> b \\<noteq> (nth bl j) \\<Longrightarrow>\n  Unique bl \\<Longrightarrow> Unique (b#bl)\"\n  by (smt (verit, best) Suc_leI Unique_def add_diff_cancel_left' \n          bot_nat_0.extremum le_0_eq le_imp_less_Suc length_Cons less_Suc_eq \n          less_Suc_eq_0_disj nth_Cons' plus_1_eq_Suc)\n\nlemma Unique_add2: \"\\<forall>j. j < (length bl) \\<and> j \\<ge> 0 \\<longrightarrow> b \\<noteq> (nth bl j) \\<Longrightarrow>\n  Unique bl \\<Longrightarrow> Unique (bl@[b])\"\n  by (smt (verit, ccfv_threshold) Suc_less_eq Unique_def length_append_singleton \n      less_Suc_eq less_trans_Suc nth_append nth_append_length)\n\nlemma Unique_Cons: \"Unique (al@bl) \\<Longrightarrow> Unique bl\"\nproof(induction al)\n  case Nil\n  then show ?case by simp\nnext\n  case (Cons a al)\n  then show ?case using Unique_lemma by force\nqed\n\nlemma Unique_rev: \"Unique bl \\<Longrightarrow> Unique (rev bl)\"\n  unfolding Unique_def using rev_nth apply simp\n  by (smt (verit, ccfv_SIG) Suc_lessD diff_less_mono2 less_imp_diff_less \n      less_trans_Suc not_less_eq rev_nth)\n\nlemma Unique_Cons2: \"Unique (al@bl) \\<Longrightarrow> Unique al\"\n  subgoal premises pre\nproof -\n  have 1: \"rev (al@bl) = rev bl @ rev al\"\n    by auto\n  have 2: \"Unique (rev al)\"\n    using Unique_rev Unique_Cons 1 pre by fastforce\n  then show ?thesis using Unique_rev by force\nqed\n  done\n\nlemma Unique_k : \"b \\<in> set bl \\<Longrightarrow> Unique bl \\<Longrightarrow> \n\\<forall>j. j < (length (remove1 b bl)) \\<and> j \\<ge> 0 \\<longrightarrow> b \\<noteq> (nth (remove1 b bl) j)\"\nproof(induction bl)\n  case Nil\n  then show ?case by simp\nnext\n  case (Cons a bl)\n  then show ?case\n  proof(cases \"b = a\")\n    case True\n    then show ?thesis apply simp using Cons(3) unfolding Unique_def\n      by (metis Suc_less_eq bot_nat_0.extremum length_Cons nth_Cons_0 nth_Cons_Suc zero_less_Suc)\n  next\n    case False\n    have 1: \"\\<forall>j. j < length (remove1 b bl) \\<and> 0 \\<le> j \\<longrightarrow> b \\<noteq> remove1 b bl ! j\"\n      using Cons False Unique_lemma by (metis set_ConsD)\n    then show ?thesis using False\n      by (metis bot_nat_0.extremum in_set_conv_nth remove1.simps(2) set_ConsD)\n  qed\nqed\n\nlemma Unique_perm: \"Unique bl \\<Longrightarrow> bl <~~> cl \\<Longrightarrow> Unique cl\"\nproof(induction cl arbitrary: bl)\n  case Nil\n  then show ?case by simp\nnext\n  case (Cons c cl)\n  have 1: \"Unique cl\"\n  proof -\n    have tmp1: \"Unique (remove1 c bl)\"\n      using Cons by (metis Unique_remove remove1_idem)\n    show ?thesis using Cons tmp1 by (metis perm_remove_perm remove_hd)\n  qed\n  have 2: \"\\<forall>j. j < (length (remove1 c bl)) \\<and> j \\<ge> 0 \\<longrightarrow> c \\<noteq> (nth (remove1 c bl) j)\"\n    using Unique_k Cons(2,3) by (metis notin_set_remove1 nth_mem)\n  have 3: \"c \\<notin> set cl\"\n    using Cons(2,3) 1 by (meson Unique'_def Unique'_eq distinct.simps(2) distinct_perm)\n  have 4: \"\\<forall>j. j < (length cl) \\<and> j \\<ge> 0 \\<longrightarrow> c \\<noteq> (nth cl j)\"\n    using 3 by force\n  then show ?case using 1 Unique_add by metis\nqed\n\n\ndefinition \"wf0 bl = (Unique bl \\<and> (\\<forall>b \\<in> set bl. Available b))\"\n\nlemma wf0_lemma: \"wf0 (a#bl) \\<Longrightarrow> wf0 bl\"\n  unfolding wf0_def using Unique_lemma by auto\n\nlemma wf0_Permutation: \"bl <~~> bl' \\<Longrightarrow> wf0 bl \\<Longrightarrow> wf0 bl'\"\nproof(induction bl arbitrary:bl')\n  case Nil\n  then show ?case by simp\nnext\n  case (Cons a bl)\n  have 1: \"bl <~~> remove1 a bl'\"\n    using Cons(2) perm_remove_perm by (metis remove_hd)\n  have 2: \"wf0 (remove1 a bl')\"\n    using 1 Cons wf0_lemma by presburger\n  have 3: \"a \\<notin> set (remove1 a bl')\"\n    using Cons(2,3) unfolding wf0_def Unique_def apply simp\n    by (metis \"1\" One_nat_def Suc_eq_plus1 Suc_less_eq add_diff_cancel_right' \n        in_set_conv_nth nth_Cons_0 perm_sym prem_seteq zero_less_Suc)\n  have 4: \"Available a\"\n    using Cons(3) unfolding wf0_def by simp\n  have 5: \"\\<forall>i. i < length (remove1 a bl') \\<and> 0 \\<le> i \\<longrightarrow> remove1 a bl' ! i \\<noteq> a\"\n    using 3 by (metis nth_mem)\n  have 6: \"(\\<forall>i j. i < j \\<and> j < length bl' \\<and> 0 \\<le> i \\<longrightarrow> bl' ! i \\<noteq> bl' ! j)\"\n    using 5 2 apply simp\n  proof(induction bl')\n    case Nil\n    then show ?case by simp\n  next\n    case (Cons b bl')\n    then show ?case\n    proof(cases \"a = b\")\n      case True\n      have tmp1: \"\\<forall>i j. i < j \\<and> j < length bl' \\<longrightarrow> bl' ! i \\<noteq> bl' ! j\"\n        using Cons True by (simp add: wf0_def Unique_def)\n      then show ?thesis using Cons(2) True\n        using length_Cons less_Suc_eq_0_disj less_nat_zero_code by fastforce\n    next\n      case False\n      have tmp1: \"remove1 a (b # bl') = b#(remove1 a bl')\"\n        using False by simp\n      have tmp2: \"wf0 (remove1 a bl')\"\n        using Cons(3) tmp1 by (metis wf0_lemma)\n      have tmp3: \"\\<forall>i<length (remove1 a bl'). remove1 a bl' ! i \\<noteq> a\"\n        using Cons(2) tmp1 by auto\n      have tmp4: \"\\<forall>i j. i < j \\<and> j < length bl' \\<longrightarrow> bl' ! i \\<noteq> bl' ! j\"\n        using tmp2 tmp3 Cons(1) by simp\n      have tmp5: \"\\<forall>i<length (remove1 a bl'). remove1 a bl' ! i \\<noteq>  b\"\n        using Cons(3) tmp1 \n        by (metis wf0_def Suc_leI Unique_def add_diff_cancel_left' bot_nat_0.extremum_unique \n            le_imp_less_Suc length_Cons nth_Cons_0 nth_Cons_pos plus_1_eq_Suc zero_less_Suc)\n      have tmp6: \"\\<forall>i<length bl'. bl' ! i \\<noteq>  b\"\n        using tmp5 False by (metis in_set_conv_nth in_set_remove1)\n      then show ?thesis using tmp4 using less_Suc_eq_0_disj by fastforce\n    qed\n  qed\n  then show ?case using Cons(3) 2 unfolding wf0_def Unique_def using 3 4 \n    by (meson Cons.prems(1) perm_sym prem_seteq)\nqed\n\nlemma wf0_Cons: \"wf0 (bl@cl) \\<Longrightarrow> wf0 bl\"\n  unfolding wf0_def using Unique_Cons Unique_Cons2 by auto\n\nlemma Unique_Permutation: \"bl <~~> bl' \\<Longrightarrow> Unique bl \\<Longrightarrow> Unique bl'\"\nproof(induction bl arbitrary:bl')\n  case Nil\n  then show ?case by simp\nnext\n  case (Cons a bl)\n  have 1: \"bl <~~> remove1 a bl'\"\n    using Cons(2) perm_remove_perm by (metis remove_hd)\n  have 2: \"Unique (remove1 a bl')\"\n    using 1 Cons by (meson Unique_lemma)\n  have 3: \"a \\<notin> set (remove1 a bl')\"\n    using Cons(2,3) unfolding wf0_def Unique_def apply simp\n    by (metis \"1\" One_nat_def Suc_eq_plus1 Suc_less_eq add_diff_cancel_right' \n        in_set_conv_nth nth_Cons_0 perm_sym prem_seteq zero_less_Suc)\n  have 5: \"\\<forall>i. i < length (remove1 a bl') \\<and> 0 \\<le> i \\<longrightarrow> remove1 a bl' ! i \\<noteq> a\"\n    using 3 by (metis nth_mem)\n  have 6: \"(\\<forall>i j. i < j \\<and> j < length bl' \\<and> 0 \\<le> i \\<longrightarrow> bl' ! i \\<noteq> bl' ! j)\"\n    using 5 2 apply simp\n  proof(induction bl')\n    case Nil\n    then show ?case by simp\n  next\n    case (Cons b bl')\n    then show ?case\n    proof(cases \"a = b\")\n      case True\n      have tmp1: \"\\<forall>i j. i < j \\<and> j < length bl' \\<longrightarrow> bl' ! i \\<noteq> bl' ! j\"\n        using Cons True by (simp add: wf0_def Unique_def)\n      then show ?thesis using Cons(2) True\n        using length_Cons less_Suc_eq_0_disj less_nat_zero_code by fastforce\n    next\n      case False\n      have tmp1: \"remove1 a (b # bl') = b#(remove1 a bl')\"\n        using False by simp\n      have tmp2: \"Unique (remove1 a bl')\"\n        using Cons(3) tmp1 using Unique_lemma by force\n      have tmp3: \"\\<forall>i<length (remove1 a bl'). remove1 a bl' ! i \\<noteq> a\"\n        using Cons(2) tmp1 by auto\n      have tmp4: \"\\<forall>i j. i < j \\<and> j < length bl' \\<longrightarrow> bl' ! i \\<noteq> bl' ! j\"\n        using tmp2 tmp3 Cons(1) by simp\n      have tmp5: \"\\<forall>i<length (remove1 a bl'). remove1 a bl' ! i \\<noteq>  b\"\n        using Cons(3) tmp1 \n        by (metis Suc_leI Unique_def add_diff_cancel_left' bot_nat_0.extremum_unique \n            le_imp_less_Suc length_Cons nth_Cons_0 nth_Cons_pos plus_1_eq_Suc zero_less_Suc)\n      have tmp6: \"\\<forall>i<length bl'. bl' ! i \\<noteq>  b\"\n        using tmp5 False by (metis in_set_conv_nth in_set_remove1)\n      then show ?thesis using tmp4 using less_Suc_eq_0_disj by fastforce\n    qed\n  qed\n  then show ?case using Cons(3) 2 unfolding wf0_def Unique_def using 3 \n    by (meson Cons.prems(1) perm_sym prem_seteq)\nqed\n\nprimrec pair_input_offset :: \"var list \\<Rightarrow> offset \\<Rightarrow> (var \\<times> offset) list\" where\n\"pair_input_offset [] os = []\" |\n\"pair_input_offset (v#vl) os = (v, os) # pair_input_offset vl os\"\n\nfun Inputs :: \"block list \\<Rightarrow> var set\" where\n  \"Inputs [] = {}\"\n| \"Inputs (b#bl) = set (get_inputs b) \\<union> Inputs bl\"\n\nlemma Inputs_base: \"Inputs (l@[a]) = Inputs l \\<union> set (get_inputs a)\"\nproof(induction l)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons b l)\n  then show ?case\n    by auto\nqed\n\nlemma Inputs_Cons: \"Inputs (a@b) = Inputs a \\<union> Inputs b\"\nproof(induction a)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons b l)\n  then show ?case\n    by auto\nqed\n\nlemma Inputs_base3: \"a \\<in> set bl \\<Longrightarrow>\nInputs (removeAll a bl) \\<union> set (get_inputs a) = Inputs bl\"\nproof(induction bl)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons b l)\n  then show ?case\n  proof(cases \"a \\<notin> set l\")\n    case True\n    then show ?thesis using Cons by auto\n  next\n    case False\n    have 1: \"Inputs (removeAll a l) \\<union> set (get_inputs a) = Inputs l\"\n      using False Cons by auto\n    then show ?thesis using Cons False by auto\n  qed\nqed\n\nlemma Inputs_eq: \"set al = set bl \\<Longrightarrow> Inputs al = Inputs bl\"\nproof(induction al arbitrary:bl)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons a al)\n  then show ?case\n  proof(cases \"a \\<in> set al\")\n    case True\n    then show ?thesis using Cons(1)[of bl]\n      by (metis Cons.IH Cons.prems insert_absorb list.simps(15))\n  next\n    case False\n    then show ?thesis using Cons(1)[of \"removeAll a bl\"] Cons(2) Inputs_base3\n      by (metis removeAll.simps(2) removeAll_id remove_code(1))\n  qed\nqed\n\nlemma Inputs_rev : \"Inputs (rev bl) = Inputs bl\"\nproof(induction bl)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons a bl)\n  then show ?case unfolding Inputs.simps rev.simps using Inputs_base by auto\nqed\n\nfun Outputs :: \"block list \\<Rightarrow> var set\" where\n  \"Outputs [] = {}\"\n| \"Outputs (b#bl) = set (get_outputs b) \\<union> Outputs bl\"\n\nlemma Outputs_base: \"Outputs (l@[a]) = Outputs l \\<union> set (get_outputs a)\"\nproof(induction l)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons b l)\n  then show ?case\n    by auto\nqed\n\nlemma Outputs_Cons: \"Outputs (a@b) = Outputs a \\<union> Outputs b\"\nproof(induction a)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons b l)\n  then show ?case\n    by auto\nqed\n\nlemma Outputs_base2: \"a \\<in> set bl \\<Longrightarrow>\nOutputs (remove1 a bl) \\<union> set (get_outputs a) = Outputs bl\"\nproof(induction bl)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons b l)\n  then show ?case\n  proof(cases \"a = b\")\n    case True\n    then show ?thesis by (simp add: sup_commute)\n  next\n    case False\n    have 1: \"Outputs (remove1 a l) \\<union> set (get_outputs a) = Outputs l\"\n      using False Cons by auto\n    then show ?thesis using Cons False by auto\n  qed\nqed\n\nlemma Outputs_base3: \"a \\<in> set bl \\<Longrightarrow>\nOutputs (removeAll a bl) \\<union> set (get_outputs a) = Outputs bl\"\nproof(induction bl)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons b l)\n  then show ?case\n  proof(cases \"a \\<notin> set l\")\n    case True\n    then show ?thesis using Cons by auto\n  next\n    case False\n    have 1: \"Outputs (removeAll a l) \\<union> set (get_outputs a) = Outputs l\"\n      using False Cons by auto\n    then show ?thesis using Cons False by auto\n  qed\nqed\n\nlemma Outputs_eq: \"set al = set bl \\<Longrightarrow> Outputs al = Outputs bl\"\nproof(induction al arbitrary:bl)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons a al)\n  then show ?case\n  proof(cases \"a \\<in> set al\")\n    case True\n    then show ?thesis using Cons(1)[of bl]\n      by (metis Cons.IH Cons.prems insert_absorb list.simps(15))\n  next\n    case False\n    then show ?thesis using Cons(1)[of \"removeAll a bl\"] Cons(2) Outputs_base3\n      by (metis removeAll.simps(2) removeAll_id remove_code(1))\n  qed\nqed\n\nlemma Outputs_remove: \"a \\<in> set bl \\<Longrightarrow>\nOutputs (a#(remove1 a bl))  = Outputs bl\"\nproof(induction bl)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons b l)\n  then show ?case\n  proof(cases \"a = b\")\n    case True\n    then show ?thesis by (simp add: sup_commute)\n  next\n    case False\n    have 1: \"Outputs (remove1 a l) \\<union> set (get_outputs a) = Outputs l\"\n      using False Cons by auto\n    then show ?thesis using Cons False by auto\n  qed\nqed\n\nlemma Outputs_perm: \"al <~~> bl \\<Longrightarrow> Outputs al = Outputs bl\"\nproof(induction al arbitrary:bl)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons a al)\n  have 1: \"al <~~> remove1 a bl\"\n    using Cons(2) by (metis perm_remove_perm remove_hd)\n  have 2: \"a \\<in> set bl\"\n    using Cons(2) by (simp add: prem_seteq)\n  then show ?case using Cons(1)[of \"remove1 a bl\"] 1 Outputs_remove by simp\nqed\n\nlemma Outputs_rev : \"Outputs (rev bl) = Outputs bl\"\nproof(induction bl)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons a bl)\n  then show ?case unfolding Outputs.simps rev.simps using Outputs_base by auto\nqed\n\nfun wf_block :: \"block \\<Rightarrow> bool\" where\n  \"wf_block (Block a b c d e) = (length b = length c & length c = length e & length b > 0)\"\ndefinition \"Graph As = (\\<forall>b \\<in> As. length (get_outputs b) > 0 \\<and>\n(\\<forall>x\\<in>As. (\\<forall>y\\<in>As. (x \\<noteq> y \\<longrightarrow> ((set (get_outputs x)) \\<inter> (set (get_outputs y))= {})))))\"\n\ndefinition \"wf1 bl = (wf0 bl \\<and> Graph (set bl))\"\n\nlemma Graph_lemma: \"Graph (set (a # bl)) \\<Longrightarrow> Graph (set bl)\"\n  by (meson Graph_def list.set_intros(2))\n\nlemma Graph_lemma2: \"Unique (a#bl) \\<Longrightarrow>\nGraph (set (a # bl)) \\<Longrightarrow> \\<forall>x \\<in> (Outputs bl). x \\<notin> set (get_outputs a)\"\n  unfolding Graph_def Unique_def\nproof(induction bl)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons b bl)\n  have 1: \"\\<forall>i j. i < j \\<and> j < length (a # bl) \\<and> 0 \\<le> i \\<longrightarrow> (a # bl) ! i \\<noteq> (a # bl) ! j\"\n    using Cons(2) \n    by (smt (verit, best) Suc_leI diff_Suc_1 le_eq_less_or_eq le_imp_less_Suc \n        length_Cons nth_Cons' order_le_less_trans)\n  have 3: \"\\<forall>x\\<in>set (a # bl). \\<forall>y\\<in>set (a # bl). x \\<noteq> y \\<longrightarrow> set (get_outputs x) \\<inter> set (get_outputs y) = {}\"\n    using Cons(3) by simp\n  have 4: \"\\<forall>x\\<in>Outputs bl. x \\<notin> set (get_outputs a)\"\n    using 1 3 Cons(1) Cons.prems(2) list.set_intros(1) by auto\n  have 5: \"set (get_outputs a) \\<inter> set (get_outputs b) = {}\"\n    using Cons(3) \n    by (metis Cons.prems(1) One_nat_def Suc_less_eq length_Cons length_pos_if_in_set \n        list.set_intros(1) list.set_intros(2) nth_Cons_0 nth_Cons_Suc of_nat_0 \n        of_nat_0_le_iff zero_less_one)\n  then show ?case using 4 by auto\n    \nqed\n\nlemma Graph_Permutation: \"bl <~~> bl' \\<Longrightarrow> Graph (set bl) \\<Longrightarrow> Graph (set bl')\"\n  unfolding Graph_def using prem_seteq by (metis perm_sym)\n\ntype_synonym sorted_block_list = \"block list\" \n\n(*Two blocks A and B, give the outputs of B, the inputs of A and the offsets of A(inputs)*)\nfun check_offset :: \"var list \\<Rightarrow> var list \\<Rightarrow> offset list \\<Rightarrow> bool\" where\n\"check_offset [] il ol = False\" |\n\"check_offset vl il [] = False\" |\n\"check_offset vl il ol = (if ((set vl) \\<inter> (set il) \\<noteq> {}) \\<and> (\\<exists>d \\<in> set ol. d = 0) then True \n else False)\"\n\n(*can also defined as a definition*)\nfun besorted :: \"block list \\<Rightarrow> bool\" where\n\"besorted [] = True\" |\n\"besorted (b # bl) = (besorted bl \\<and> (\\<forall> a. a \\<in> set bl \\<longrightarrow> \n            (check_offset (get_outputs a) (get_inputs b) (get_offsets b) ) = False))\"\n\nlemma besorted_remove1: \"besorted (a#bl) \\<Longrightarrow> besorted bl\"\nproof(induction bl)\n  case Nil\n  then show ?case by simp\nnext\n  case (Cons b bl)\n  then show ?case unfolding besorted.simps by meson\nqed\n\nlemma besorted_remove2: \"besorted bl \\<Longrightarrow> besorted (remove1 b bl)\"\nproof(induction bl)\n  case Nil\n  then show ?case by simp\nnext\n  case (Cons a bl)\n  have 1: \"besorted (remove1 b bl)\"\n    using besorted_remove1 Cons by simp\n  show ?case\n  proof(cases \"a = b\")\n    case True\n    then show ?thesis using Cons(2) besorted_remove1 by (metis remove_hd)\n  next\n    case False\n    have 2: \"besorted (remove1 b (a # bl)) = besorted (a#remove1 b bl)\"\n      using False by simp\n    have 3: \"\\<forall>x. x \\<in> set (remove1 b bl) \\<longrightarrow> x \\<in> set bl\"\n      by (meson notin_set_remove1)\n    then show ?thesis using Cons(2) 2 unfolding besorted.simps using 1 by blast\n  qed\nqed\n\nlemma besorted_last: \"besorted (bl@[a]) \\<Longrightarrow> (\\<forall> b. b \\<in> set bl \\<longrightarrow> \n            (check_offset (get_outputs a) (get_inputs b) (get_offsets b)) = False)\"\nproof(induction bl)\n  case Nil\n  then show ?case by simp\nnext\n  case (Cons b bl)\n  have 1: \"\\<forall>b. b \\<in> set bl \\<longrightarrow> check_offset (get_outputs a) (get_inputs b) (get_offsets b) = False\"\n    using Cons by simp\n  have 2: \"check_offset (get_outputs a) (get_inputs b) (get_offsets b) = False\"\n    using Cons(2) by simp\n  then show ?case using 1 by simp\nqed\n\n(*offset < 0 means we have all the inputs in the beginning of the execution cycle, so we remove them\nout of the in-degree and only keep those inputs where offset = 0*)\n\ndefinition get_block_indegree :: \"block \\<Rightarrow> block list \\<Rightarrow> var set\" where\n  \"get_block_indegree b bl = (if 0 \\<in> set (get_offsets b) \\<or> (get_sample_time b = 0) then \n(set (get_inputs b) - set (get_outputs b)) \\<inter> Outputs bl else {})\"\n\nlemma get_block_indegree_perm: \"bl <~~> bl' \\<Longrightarrow> get_block_indegree b bl = get_block_indegree b bl'\"\n  unfolding get_block_indegree_def using Outputs_perm by presburger\n\n\ntype_synonym indegreeMap = \"block \\<Rightarrow> var set\"\n\nfun get_indegrees :: \"block list \\<Rightarrow> block list \\<Rightarrow> indegreeMap \\<Rightarrow> indegreeMap\" where\n  \"get_indegrees [] bl f = f\" |\n  \"get_indegrees (b#bl) cl f = get_indegrees bl cl (f(b := (get_block_indegree b cl)))\"\n\n(*give a block \"b\" and the deleted block list \"bl\", we delete the inputs from block \"b\"*)\nfun delete_block_indegree :: \"block \\<Rightarrow> block list \\<Rightarrow> indegreeMap \\<Rightarrow> var set\" where\n  \"delete_block_indegree b cl f = f b - (Outputs cl)\"\n\n(*the first block list \"bl\" is the remaining blocks and the second block list \"cl\" is the sorted blocks*)\nfun delete_indegrees :: \"block list \\<Rightarrow> block list \\<Rightarrow> indegreeMap \\<Rightarrow> indegreeMap\" where\n  \"delete_indegrees [] cl f = f\" |\n  \"delete_indegrees (b#bl) cl f = delete_indegrees bl cl (f(b := (delete_block_indegree b cl f)))\"\n\n\nfun find_0indegree_blocks :: \"block list \\<Rightarrow> block list \\<Rightarrow> sorted_block_list  \n   \\<Rightarrow> (block option  \\<times> block list)\" where\n  \"find_0indegree_blocks al [] cl = (None,[])\" |\n  \"find_0indegree_blocks al (b#bl) cl  = (let x = find_0indegree_blocks al bl cl in \n                      (if (get_block_indegree b al -  (Outputs cl) = {}) then \n                         (Some b, bl) else (fst x, b#(snd x))))\"\n\nlemma length_find_0indegree: \"(fst (find_0indegree_blocks al bl cl)) \\<noteq> None \\<Longrightarrow> length (snd (find_0indegree_blocks al bl cl))\n                               < length bl\"\nproof (induction bl arbitrary: cl)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons a bl)\n  then show ?case \n  proof (cases \"(get_block_indegree a al -  (Outputs cl) = {}) \")\n    case True\n    then show ?thesis using Cons True by auto\n  next\n    case False\n    have 1: \"length (snd (find_0indegree_blocks al bl cl)) < length bl\"\n      using Cons(1,2) False unfolding find_0indegree_blocks.simps by force\n    have 2: \"length (snd (find_0indegree_blocks al (a # bl) cl)) = length (snd (find_0indegree_blocks al bl cl)) + 1\"\n      unfolding find_0indegree_blocks.simps using False\n      by (smt (verit, best) add.commute length_Cons plus_1_eq_Suc snd_conv)\n    then show ?thesis using 1 by simp\n  qed\nqed\n\nlemma find_0indegree_block_lemma : \"find_0indegree_blocks al bl cl = (Some b, dl) \\<Longrightarrow>\n  get_block_indegree b al -  (Outputs cl) = {}\"\nproof(induction bl arbitrary: dl)\n  case Nil\n  then show ?case by simp\nnext\n  case (Cons a bl)\n  then show ?case unfolding find_0indegree_blocks.simps\n  proof(cases \"get_block_indegree a al - Outputs cl = {}\")\n    case True\n    then show ?thesis using Cons(2) unfolding find_0indegree_blocks.simps by simp\n  next\n    case False\n    have 1: \"find_0indegree_blocks al bl cl = (Some b, (remove1 a dl))\"\n      using Cons(2) unfolding find_0indegree_blocks.simps apply simp\n      by (smt (verit) False diff_shunt_var fst_eqD prod.exhaust_sel remove_hd snd_eqD)\n    then show ?thesis using Cons(1) by simp\n  qed\nqed\n\nlemma find_0indegree_block_lemma2 : \"find_0indegree_blocks al bl cl = (Some b, dl) \\<Longrightarrow>\n  dl = (remove1 b bl)\"\nproof(induction bl arbitrary: dl)\n  case Nil\n  then show ?case by simp\nnext\n  case (Cons a bl)\n  then show ?case unfolding find_0indegree_blocks.simps\n  proof(cases \"get_block_indegree a al - Outputs cl = {}\")\n    case True\n    then show ?thesis using Cons(2) unfolding find_0indegree_blocks.simps by simp\n  next\n    case False\n    have 1: \"find_0indegree_blocks al bl cl = (Some b, (remove1 a dl))\"\n      using Cons(2) unfolding find_0indegree_blocks.simps apply simp\n      by (smt (verit) False diff_shunt_var fst_eqD prod.exhaust_sel remove_hd snd_eqD)\n    have 2: \"hd dl = a\"\n      using Cons(2) unfolding find_0indegree_blocks.simps apply simp\n      by (smt (verit, best) False diff_shunt_var list.sel(1) snd_conv)\n    have 3: \"dl = a # tl dl\"\n      using 2 1 Cons.prems False list.exhaust_sel by auto\n    have 4: \"(remove1 a dl) = remove1 b bl\"\n      using Cons(1) 1 by simp\n    then show ?thesis using Cons(1) 3 by (metis \"1\" False find_0indegree_block_lemma remove1.simps(2))\n  qed\nqed\n\nlemma find_0indegree_lemma4: \"(fst (find_0indegree_blocks al bl cl)) \\<noteq> None \\<Longrightarrow> \nlength (snd (find_0indegree_blocks al bl cl))+1 = length bl\"\nproof (induction bl arbitrary: cl)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons a bl)\n  then show ?case \n  proof (cases \"(get_block_indegree a al -  (Outputs cl) = {}) \")\n    case True\n    then show ?thesis using Cons True by auto\n  next\n    case False\n    have 1: \"length (snd (find_0indegree_blocks al bl cl))+1 = length bl\"\n      using Cons(1,2) False unfolding find_0indegree_blocks.simps by force\n    have 2: \"length (snd (find_0indegree_blocks al (a # bl) cl)) = length (snd (find_0indegree_blocks al bl cl)) + 1\"\n      unfolding find_0indegree_blocks.simps using False\n      by (smt (verit, best) add.commute length_Cons plus_1_eq_Suc snd_conv)\n    then show ?thesis using 1 by simp\n  qed\nqed\n\nlemma find_0indegree_lemma3: \"(fst (find_0indegree_blocks al bl cl)) \\<noteq> None \n\\<Longrightarrow> set (the (fst (find_0indegree_blocks al bl cl))#(snd (find_0indegree_blocks al bl cl)))\n                               = set bl\"\nproof (induction bl)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons a bl)\n  then show ?case \n  proof (cases \"(get_block_indegree a al - (Outputs cl) = {}) \")\n    case True\n    then show ?thesis using Cons True by auto\n  next\n    case False\n    have 1: \"fst (find_0indegree_blocks al bl cl) \\<noteq> None\"\n      using Cons(2) unfolding find_0indegree_blocks.simps using False by auto\n    have 2: \"set (the (fst (find_0indegree_blocks al bl cl)) # \n      snd (find_0indegree_blocks al bl cl)) = set bl\"\n      using Cons(1) 1 by simp\n    have 3: \"the (fst (let x = find_0indegree_blocks al bl cl\n                   in if get_block_indegree a al - Outputs cl = {} then (Some a, bl)\n                      else (fst x, a # snd x))) = the (fst (find_0indegree_blocks al bl cl))\"\n      using False by (smt (verit, best) fst_conv)\n    have 4: \"snd (let x = find_0indegree_blocks al bl cl\n              in if get_block_indegree a al - Outputs cl = {} then (Some a, bl)\n                 else (fst x, a # snd x)) = a#(snd (find_0indegree_blocks al bl cl))\"\n      using False by (smt (verit, best) snd_conv)\n    have 5: \"set (the (fst (let x = find_0indegree_blocks al bl cl\n                   in if get_block_indegree a al - Outputs cl = {} then (Some a, bl)\n                      else (fst x, a # snd x))) #\n         snd (let x = find_0indegree_blocks al bl cl\n              in if get_block_indegree a al - Outputs cl = {} then (Some a, bl)\n                 else (fst x, a # snd x))) = set (the (fst (find_0indegree_blocks al bl cl))#\n        (a#(snd (find_0indegree_blocks al bl cl))))\"\n      using 3 4 by presburger\n    have 6: \"set (the (fst (find_0indegree_blocks al bl cl)) # (a#(snd (find_0indegree_blocks al bl cl)))) \n        = set (a#bl)\"\n      using 2 by auto\n    then show ?thesis unfolding find_0indegree_blocks.simps using 5 by auto\n  qed\nqed\n\n\n\nfunction topological_sort :: \"block list \\<Rightarrow> block list \\<Rightarrow> sorted_block_list \\<Rightarrow> sorted_block_list\" where\n\"topological_sort al bl cl = (let x = (find_0indegree_blocks al bl cl) in \n                           (if (fst x = None) then cl else\n                                (topological_sort al (snd x) (cl@[the (fst x)]))))\"\n  by pat_completeness auto \n\ntermination \n  apply (relation \"measures[(\\<lambda>(a::block list, b::block list, c::block list). length b)]\", auto)\n  subgoal for al bl cl\n    using length_find_0indegree[of al bl cl] \n    by auto\n  done\n  \nlemma \"topological_sort [] [] [] = []\"\n  using topological_sort.psimps by auto\n\ndefinition besorted_change:: \"block list \\<Rightarrow> bool\"\n  where \"besorted_change dl =  (\\<forall> i j. (i<j \\<and> j < (length dl) \\<and> j \\<ge> 0) \\<longrightarrow> \n            (check_offset (get_outputs (dl ! j)) (get_inputs (dl ! i)) (get_offsets (dl ! i))) = False)\"\n\nlemma besorted_equiv: \"besorted dl \\<equiv> besorted_change dl\"\nproof(induction dl)\n  case Nil\n  then show ?case unfolding besorted_change_def by simp\nnext\n  case (Cons d dl)\n  have 1: \"besorted (d # dl) \\<Longrightarrow> besorted_change (d # dl)\"\n    unfolding besorted_change_def besorted.simps apply clarify\n    subgoal premises pre for i j\n    proof(cases \"i = 0\")\n      case True\n      then show ?thesis apply simp using pre(2,3,4,5) by simp\n    next\n      case False\n      have tmp1: \"i > 0 \\<and> i < length (d # dl)\"\n        using pre False by simp\n      then show ?thesis using Cons pre(1,3,4,5) unfolding besorted_change_def\n        using less_Suc_eq_0_disj by force\n    qed\n    done\n  have 2: \"besorted_change (d # dl) \\<Longrightarrow> besorted (d # dl)\"\n    subgoal premises pre\n    proof -\n      have tmp1: \"besorted_change dl\" \n        using pre unfolding besorted_change_def\n        by (metis Suc_less_eq length_Cons nth_Cons_Suc zero_le)\n      have tmp2: \"besorted dl\"\n        using Cons tmp1 by simp\n      have tmp3: \"\\<forall>a. a \\<in> set dl \\<longrightarrow> check_offset (get_outputs a) (get_inputs d) (get_offsets d) = False\"\n        using pre unfolding besorted_change_def by (metis Suc_leI bot_nat_0.extremum in_set_conv_nth \n            le_imp_less_Suc length_Cons nth_Cons_0 nth_Cons_Suc)\n      show ?thesis unfolding besorted.simps using tmp2 tmp3 by simp\n    qed\n    done\n  then show ?case using 1 by blast\nqed\n\ndefinition after_0indegree :: \"block list \\<Rightarrow> block list \\<Rightarrow> bool\" where\n\"after_0indegree al bl = (\\<forall> i. (i \\<ge> 0 \\<and> i < length bl) \\<longrightarrow> (get_block_indegree (bl ! i) al -  (Outputs (take i bl)) = {}))\"\n\nlemma topo_besorted: \"topological_sort al bl cl = dl \\<Longrightarrow> after_0indegree al cl\n                \\<Longrightarrow> besorted_change cl \\<Longrightarrow> Outputs al = Outputs bl \\<union> Outputs cl \\<Longrightarrow>\n                \\<forall>i j. i\\<in> set bl \\<and> j \\<in> set cl \\<longrightarrow> \n    check_offset (get_outputs i) (get_inputs j) (get_offsets j) = False \\<Longrightarrow>  Unique (bl@cl)\n  \\<Longrightarrow> Graph (set (bl@cl)) \\<Longrightarrow> besorted_change dl\"\nproof (induction bl arbitrary: cl dl rule: wf_induct[of \"{(x, y). length x < length y}\"])\n  case 1\n  then show ?case unfolding wf_def\n    by (metis case_prodD length_induct mem_Collect_eq) \nnext\n  case (2 x)\n  then show ?case\n  proof (induction x arbitrary: cl dl)\n    case Nil\n    then show ?case  using topological_sort.psimps by auto\n  next\n    case (Cons a bl)\n     then show ?case using topological_sort.psimps[of al \"a#bl\" cl]\n     proof (cases \"fst (find_0indegree_blocks al (a # bl) cl) = None\")\n      case True\n      then show ?thesis using Cons topological_sort.psimps[of al \"a#bl\" cl] by auto\n    next\n      case False\n      note FF = False\n      then show ?thesis using Cons\n      proof (cases \" (get_block_indegree a al - (Outputs cl) = {})\")\n        case True\n        note FT = True\n        have 1: \"(find_0indegree_blocks al (a # bl) cl) = (Some a, bl)\"\n          using True unfolding find_0indegree_blocks.simps by simp\n        have 2: \"topological_sort al (a # bl) cl = topological_sort al bl (cl@[a])\"\n          using 1 topological_sort.psimps[of al \"a#bl\" cl] by simp\n        have 3: \"topological_sort al bl (cl@[a]) = dl\"\n          using 2 Cons(3) by simp\n        have \"besorted_change (cl@[a])\" \n        proof -\n              have tmp1: \"\\<forall>b \\<in> set cl.\n          check_offset (get_outputs a) (get_inputs b) (get_offsets b) = False\"\n                using Cons(7) by auto\n              show ?thesis using Cons(5) tmp1 unfolding after_0indegree_def besorted_change_def\n                by (simp add: nth_append)\n        qed\n        moreover have \"after_0indegree al (cl@[a])\" using Cons(4,3) True unfolding after_0indegree_def\n          by (simp add: nth_append)\n        moreover have \"(bl, a # bl) \\<in> {a. case a of (x, y) \\<Rightarrow> length x < length y}\"\n          by auto\n        moreover have \" Outputs al = Outputs bl \\<union> Outputs (cl @ [a])\" using Cons(6) \n          using Outputs.simps(2) Outputs_base by blast\n        moreover have \"\\<forall>i j. i \\<in> set bl \\<and> j \\<in> set (cl @ [a]) \\<longrightarrow>\n          check_offset (get_outputs i) (get_inputs j) (get_offsets j) = False\" \n        proof -\n        have tmp1: \"0 \\<notin> set (get_offsets a) \\<Longrightarrow> \\<forall>i. i \\<in> set bl \\<longrightarrow>\n        check_offset (get_outputs i) (get_inputs a) (get_offsets a) = False\"\n          by (metis (mono_tags, opaque_lifting) check_offset.elims(2))\n        have tmp2: \"Outputs bl \\<inter> Outputs cl = {}\"\n        proof -\n          have tmp1: \"Unique (bl @ cl)\"\n            using Cons(8) Unique_lemma by simp\n          have tmp2: \"Graph (set (bl@cl))\"\n            using Cons(9) Graph_lemma by (metis Cons_eq_appendI)\n          show ?thesis using tmp1 tmp2 apply simp\n          proof(induction bl)\n            case Nil\n            then show ?case by simp\n          next\n            case (Cons b bl)\n            have tmp1: \"set (get_outputs b) \\<inter> Outputs cl = {}\"\n            proof -\n              have \"Graph (set (b#cl))\"\n                using Cons(3) unfolding Graph_def by auto\n              moreover have \"\\<forall>j. j < (length cl) \\<and> j \\<ge> 0 \\<longrightarrow> b \\<noteq> (nth cl j)\"\n              proof -\n                have tmp1: \"\\<forall>j. j < (length (bl@cl)) \\<and> j \\<ge> 0 \\<longrightarrow> b \\<noteq> (nth (bl@cl) j)\"\n                  using Cons(2) unfolding Unique_def by force\n                then show ?thesis by (metis UnI2 in_set_conv_nth set_append zero_le)\n              qed\n              ultimately show ?thesis apply simp\n              proof(induction cl)\n                case Nil\n                then show ?case by simp\n              next\n                case (Cons c cl)\n                have tmp1: \"set (get_outputs b) \\<inter> Outputs cl = {}\"\n                  using Cons unfolding Graph_def \n                  by (metis in_set_conv_nth insert_iff list.simps(15))\n                have tmp2: \"b \\<noteq> c\"\n                  using Cons(3) by auto\n                have tmp3: \"set (get_outputs b) \\<inter> set (get_outputs c) = {}\"\n                  using Cons(2) tmp2 unfolding Graph_def \n                  by (meson insertI1 insertI2 list.set_intros(1))\n                then show ?case using tmp1 by auto\n              qed\n            qed\n            have tmp2: \"Graph (set bl \\<union> set cl)\"\n              using Cons(3) unfolding Graph_def by simp\n            have tmp3: \"Unique (bl @ cl)\"\n              using Cons(2) Unique_lemma by simp\n            have tmp4: \"Outputs bl \\<inter> Outputs cl = {}\"\n              using tmp2 tmp3 Cons(1) by simp\n            then show ?case unfolding Outputs.simps using tmp1 by auto\n          qed\n        qed\n        have tmp3_1: \"set (get_outputs a) \\<inter> (Outputs bl) = {}\"\n          using Cons(8,9) unfolding Unique_def Graph_def\n          by (smt (verit) Cons.prems(7) Graph_def Graph_lemma2 UnI1 Unique_Cons2 \n              disjoint_iff_not_equal set_append)\n        have tmp3_2: \"set (get_outputs a) \\<inter> (Outputs cl) = {}\"\n          using Cons(8,9)\n        proof(induction cl)\n          case Nil\n          then show ?case by simp\n        next\n          case (Cons c cl)\n          have tmp1: \"remove1 c ((a # bl) @ c # cl) = (a#bl)@cl\"\n            using Cons(2) unfolding Unique_def\n            by (metis Cons.prems(1) Un_iff Unique_k bot_nat_0.extremum in_set_conv_nth \n                list.set_intros(1) remove1_append remove_hd set_append)\n          have tmp2: \"Unique ((a # bl) @ cl)\"\n            using Cons(2) Unique_remove tmp1 by (metis remove1_idem)\n          have tmp3: \"set (get_outputs a) \\<inter> Outputs cl = {}\"\n            using Cons(1,3) tmp2 unfolding Graph_def by auto\n          have tmp4: \"set (get_outputs a) \\<inter> set (get_outputs c) = {}\"\n            using Cons(2,3) unfolding Unique_def Graph_def \n            by (metis Cons.prems(1) Unique_k append_Cons bot_nat_0.extremum in_set_conv_decomp \n                length_Cons list.set_intros(1) nth_Cons_0 tmp1 zero_less_Suc)\n          then show ?case using tmp3 unfolding Outputs.simps by auto\n        qed\n          have tmp3: \"0 \\<in> set (get_offsets a) \\<Longrightarrow> set (get_inputs a) \\<inter> (Outputs bl) = {}\"\n            using Cons(6) tmp2 FT tmp3_1 tmp3_2 unfolding get_block_indegree_def Outputs.simps by auto\n          have tmp4: \"0 \\<in> set (get_offsets a) \\<Longrightarrow> \\<forall>i. i \\<in> set bl \\<longrightarrow>\n        check_offset (get_outputs i) (get_inputs a) (get_offsets a) = False\"\n            apply clarify subgoal premises pre for i \n            proof(cases \"(get_outputs i) = []\")\n              case True\n              then show ?thesis by simp\n            next\n              case False\n              have 1: \"(get_outputs i) = hd (get_outputs i) # tl (get_outputs i)\"\n                using False by simp\n              then show ?thesis\n              proof(cases \"(get_offsets a) = []\")\n                case True\n                then show ?thesis using 1 pre(1) by fastforce\n              next\n                case False\n                have 2: \"(get_offsets a) = (hd (get_offsets a)) # (tl (get_offsets a))\"\n                  using False by simp\n                then show ?thesis using check_offset.simps(3)[of \"hd (get_outputs i)\" \n                      \"tl (get_outputs i)\" \"(get_inputs a)\" \"hd (get_offsets a)\" \n                      \"tl (get_offsets a)\"] 1 tmp3 pre Outputs_base2 by auto\n              qed\n            qed\n            done\n          show ?thesis using FT Cons(7) tmp1 tmp4 unfolding get_block_indegree_def\n          using insert_iff list.set(2) set_append by auto\n        qed\n        moreover have \"Unique (bl @ cl @ [a])\"\n        proof -\n          have tmp1: \"\\<forall>j. j < (length (bl@cl)) \\<and> j \\<ge> 0 \\<longrightarrow> a \\<noteq> (nth (bl@cl) j)\"\n            using Cons(8) unfolding Unique_def by (metis Suc_leI append_Cons \n                le_imp_less_Suc le_zero_eq length_Cons nth_Cons_0 nth_Cons_Suc)\n          then show ?thesis using Unique_lemma Cons(8) Unique_add2\n            by (metis append.assoc append_Cons)\n        qed\n        moreover have \"Graph (set (bl @ cl @ [a]))\" using Cons(9) by simp\n        ultimately show ?thesis using Cons(1)[of \"cl@[a]\" dl] Cons(2) 3 by metis\n      next\n        case False\n        have 1: \"\\<exists>c. fst (find_0indegree_blocks al (a # bl) cl) = Some c\"\n          using FF by simp\n        show ?thesis using 1 apply clarify\n          subgoal premises pre for c\n          proof -\n            have 2: \"get_block_indegree c al - Outputs cl = {}\"\n              using find_0indegree_block_lemma pre by (metis prod.collapse)\n            have 3: \"snd (find_0indegree_blocks al (a # bl) cl) = remove1 c (a#bl)\"\n              using pre find_0indegree_block_lemma2 by (metis prod.exhaust_sel)\n            have 4: \"topological_sort al (a # bl) cl = topological_sort al (remove1 c (a#bl)) (cl@[c])\"\n              using topological_sort.psimps[of al \"a#bl\" cl] pre 3 by simp\n            have 5: \"topological_sort al (remove1 c (a#bl)) (cl@[c]) = dl\"\n              using 4 Cons(3) by simp\n            have 6: \"c \\<in> set (a#bl)\"\n              by (metis \"3\" FF length_find_0indegree less_irrefl_nat remove1_idem)\n            have 7: \"(remove1 c (a#bl), a # bl) \\<in> {a. case a of (x, y) \\<Rightarrow> length x < length y}\"\n              by (metis \"3\" FF case_prodI length_find_0indegree mem_Collect_eq)\n            have 8: \"besorted_change (cl@[c])\" \n            proof -\n                  have tmp1: \"\\<forall>b \\<in> set cl.\n              check_offset (get_outputs c) (get_inputs b) (get_offsets b) = False\"\n                    using Cons(7) 6 by auto\n                  show ?thesis using Cons(5) tmp1 unfolding after_0indegree_def besorted_change_def\n                    by (simp add: nth_append)\n            qed\n            have 9: \"after_0indegree al (cl@[c])\" using Cons(4,3) 2 unfolding after_0indegree_def\n              by (simp add: nth_append)\n            have 10: \" Outputs al = Outputs (remove1 c (a#bl)) \\<union> Outputs (cl @ [c])\" using Cons(6) \n              using Outputs.simps(2) Outputs_base2 6 Outputs_base by auto\n            have 11: \"\\<forall>i j. i \\<in> set (remove1 c (a#bl)) \\<and> j \\<in> set (cl @ [c]) \\<longrightarrow>\n                check_offset (get_outputs i) (get_inputs j) (get_offsets j) = False\"\n            proof -\n              have tmp1: \"0 \\<notin> set (get_offsets c) \\<Longrightarrow> \\<forall>i. i \\<in> set (remove1 c (a#bl)) \\<longrightarrow>\n              check_offset (get_outputs i) (get_inputs c) (get_offsets c) = False\"\n                by (metis (mono_tags, opaque_lifting) check_offset.elims(2))\n              have tmp2: \"Outputs bl \\<inter> Outputs cl = {}\"\n              proof -\n                have tmp1: \"Unique (bl @ cl)\"\n                  using Cons(8) Unique_lemma by simp\n                have tmp2: \"Graph (set (bl@cl))\"\n                  using Cons(9) Graph_lemma by (metis Cons_eq_appendI)\n                show ?thesis using tmp1 tmp2 apply simp\n                proof(induction bl)\n                  case Nil\n                  then show ?case by simp\n                next\n                  case (Cons b bl)\n                  have tmp1: \"set (get_outputs b) \\<inter> Outputs cl = {}\"\n                  proof -\n                    have \"Graph (set (b#cl))\"\n                      using Cons(3) unfolding Graph_def by auto\n                    moreover have \"\\<forall>j. j < (length cl) \\<and> j \\<ge> 0 \\<longrightarrow> b \\<noteq> (nth cl j)\"\n                    proof -\n                      have tmp1: \"\\<forall>j. j < (length (bl@cl)) \\<and> j \\<ge> 0 \\<longrightarrow> b \\<noteq> (nth (bl@cl) j)\"\n                        using Cons(2) unfolding Unique_def by force\n                      then show ?thesis by (metis UnI2 in_set_conv_nth set_append zero_le)\n                    qed\n                    ultimately show ?thesis apply simp\n                    proof(induction cl)\n                      case Nil\n                      then show ?case by simp\n                    next\n                      case (Cons c cl)\n                      have tmp1: \"set (get_outputs b) \\<inter> Outputs cl = {}\"\n                        using Cons unfolding Graph_def \n                        by (metis in_set_conv_nth insert_iff list.simps(15))\n                      have tmp2: \"b \\<noteq> c\"\n                        using Cons(3) by auto\n                      have tmp3: \"set (get_outputs b) \\<inter> set (get_outputs c) = {}\"\n                        using Cons(2) tmp2 unfolding Graph_def \n                        by (meson insertI1 insertI2 list.set_intros(1))\n                      then show ?case using tmp1 by auto\n                    qed\n                  qed\n                  have tmp2: \"Graph (set bl \\<union> set cl)\"\n                    using Cons(3) unfolding Graph_def by simp\n                  have tmp3: \"Unique (bl @ cl)\"\n                    using Cons(2) Unique_lemma by simp\n                  have tmp4: \"Outputs bl \\<inter> Outputs cl = {}\"\n                    using tmp2 tmp3 Cons(1) by simp\n                  then show ?case unfolding Outputs.simps using tmp1 by auto\n                qed\n              qed\n              have tmp3: \"set (get_outputs a) \\<inter> Outputs cl = {}\"\n              proof -\n                have tmp1: \"\\<forall>j. j < (length cl) \\<and> j \\<ge> 0 \\<longrightarrow> a \\<noteq> (nth cl j)\"\n                proof -\n                  have \"\\<forall>j. j < (length (bl@cl)) \\<and> j \\<ge> 0 \\<longrightarrow> a \\<noteq> (nth (bl@cl) j)\"\n                    using Cons(8) unfolding Unique_def by force\n                  then show ?thesis by (metis UnI2 in_set_conv_nth set_append zero_le)\n                qed\n                have \"Unique (a#cl)\"\n                  using Cons(8) Unique_Cons Unique_add tmp1 by metis\n                moreover have \"Graph (set (a#cl))\"\n                  using Cons(9) unfolding Graph_def\n                  by (metis UnCI UnI1 list.set_intros(1) set_ConsD set_append)\n                ultimately show ?thesis apply simp\n                proof(induction cl)\n                  case Nil\n                  then show ?case by simp\n                next\n                  case (Cons c cl)\n                  have tmp1: \"a \\<noteq> c\"\n                    using Cons(2) unfolding Unique_def by (metis Cons.prems(1) Unique_k \n                   length_greater_0_conv list.set_intros(1) neq_Nil_conv nth_Cons_0 remove_hd zero_le)\n                  have tmp2: \"Unique (a # cl)\"\n                    using tmp1 Unique_remove Cons(2) by force\n                  have tmp3: \"Graph (insert a (set cl))\"\n                    using Cons(3) unfolding Graph_def tmp1 by simp\n                  have tmp4: \"set (get_outputs a) \\<inter> Outputs cl = {}\"\n                    using Cons(1) tmp2 tmp3 by simp\n                  have tmp5: \"set (get_outputs a) \\<inter> set (get_outputs c) = {}\"\n                    using Cons(3) unfolding Graph_def\n                    by (metis insert_iff list.simps(15) tmp1)\n                  then show ?case using tmp4 unfolding Outputs.simps by auto\n                qed\n              qed\n              have tmp4_1: \"set (get_outputs c) \\<inter> Outputs cl = {}\"\n                using Cons(8,9) unfolding Unique_def Graph_def \n                by (metis \"6\" Outputs_base2 UnCI disjoint_iff_not_equal set_ConsD tmp2 tmp3)\n              have tmp4_2: \"set (get_outputs c) \\<inter> (Outputs (remove1 c (a#bl))) = {}\" \n                using 6 Cons(8,9)\n              proof(induction bl)\n                case Nil\n                then show ?case by auto\n              next\n                case (Cons b bl)\n                then show ?case\n                proof(cases \"c = b\")\n                  case True\n                  have tmp1: \"remove1 c (a # b # bl) = a#bl\"\n                    using Cons(3) unfolding Unique_def True by simp\n                  have tmp2: \"Unique (b # bl)\"\n                    using Cons(3) Unique_lemma by (metis Unique_Cons2)\n                  have tmp3: \"Graph (set (b # bl))\"\n                    using Cons(4) unfolding Graph_def \n                    by (metis UnI1 list.set_intros(2) set_append)\n                  have tmp4: \"set (get_outputs c) \\<inter> Outputs bl = {}\"\n                    using tmp2 tmp3 True\n                  proof(induction bl)\n                    case Nil\n                    then show ?case by simp\n                  next\n                    case (Cons d bl)\n                    have tmp1: \"Unique (b#bl)\"\n                      using Cons(2) unfolding Unique_def\n                      by (metis (no_types, lifting) Unique_def Unique_remove list.set_intros(1) \n                          remove1.simps(2) set_subset_Cons subset_code(1))\n                    have tmp2: \"Graph (set (b # bl))\"\n                      using Cons(3) unfolding Graph_def by auto\n                    have tmp3: \"set (get_outputs c) \\<inter> Outputs bl = {}\"\n                      using Cons(1,4) tmp1 tmp2 by simp\n                    then show ?case unfolding Outputs.simps using Cons(2,3) unfolding Unique_def Graph_def\n                      by (metis Cons.prems(1) Cons.prems(2) Graph_lemma2 Int_emptyI Outputs.simps(2) True)\n                  qed\n                  then show ?thesis using True tmp1 \n                    using \"2\" Cons.prems(3) False Graph_def list.set_intros(1) set_append by auto\n                next\n                  case False\n                  note F1 = False\n                  have tmp1: \"c \\<in> set (a # bl)\"\n                    using Cons(2) False by auto\n                  have tmp2: \"Unique ((a # bl) @ cl)\"\n                    using Cons(3) unfolding Unique_def\n                    by (smt (z3) Suc_leI add_diff_cancel_left' append_Cons bot_nat_0.extremum \n                        le_imp_less_Suc length_Cons less_Suc_eq nth_Cons_0 nth_Cons_pos plus_1_eq_Suc)\n                  have tmp3: \"set (get_outputs c) \\<inter> Outputs (remove1 c (a # bl)) = {}\"\n                    using Cons(1,4) tmp1 tmp2 unfolding Graph_def by auto\n                  have tmp4: \"set (get_outputs c) \\<inter> set (get_outputs b) = {}\"\n                    using False Cons(4) unfolding Graph_def\n                    by (metis Cons.prems(1) Un_iff list.set_intros(1) notin_set_remove1 remove_hd set_append)\n                  then show ?thesis using False\n                  proof(cases \"c = a\")\n                    case True\n                    then show ?thesis using tmp3 tmp4 by auto\n                  next\n                    case False\n                    then show ?thesis using F1 tmp3 tmp4 by auto\n                  qed\n                qed\n              qed\n              have tmp4: \"0 \\<in> set (get_offsets c) \\<Longrightarrow> \n                set (get_inputs c) \\<inter> (Outputs (remove1 c (a#bl))) = {}\"\n                using Cons(6) 2 tmp2 tmp3 tmp4_1 tmp4_2 unfolding get_block_indegree_def\n                by (smt (verit, ccfv_threshold) \"6\" Diff_Int_distrib2 Diff_iff Int_iff Outputs.simps(2)\n                    Outputs_base2 UnCI Un_iff disjoint_iff_not_equal empty_iff)\n              have tmp5: \"0 \\<in> set (get_offsets c) \\<Longrightarrow> \\<forall>i. i \\<in> set (remove1 c (a#bl)) \\<longrightarrow>\n            check_offset (get_outputs i) (get_inputs c) (get_offsets c) = False\"\n                apply clarify subgoal premises pre for i \n                proof(cases \"(get_outputs i) = []\")\n                  case True\n                  then show ?thesis by simp\n                next\n                  case False\n                  have 1: \"(get_outputs i) = hd (get_outputs i) # tl (get_outputs i)\"\n                    using False by simp\n                  then show ?thesis\n                  proof(cases \"(get_offsets c) = []\")\n                    case True\n                    then show ?thesis using 1 pre(1) by fastforce\n                  next\n                    case False\n                    have 2: \"(get_offsets c) = (hd (get_offsets c)) # (tl (get_offsets c))\"\n                      using False by simp\n                    then show ?thesis using check_offset.simps(3)[of \"hd (get_outputs i)\" \n                          \"tl (get_outputs i)\" \"(get_inputs c)\" \"hd (get_offsets c)\" \n                          \"tl (get_offsets c)\"] 1 tmp4 pre Outputs_base2 by auto\n                  qed\n                qed\n                done\n              show ?thesis using tmp1 tmp5 Cons(7)\n                by (metis Un_iff empty_iff list.set(1) notin_set_remove1 set_ConsD set_append)\n            qed\n            have 12: \"Unique ((remove1 c (a#bl)) @ cl @ [c])\"\n            proof -\n              have tmp1: \"c \\<in> set ((a # bl) @ cl)\"\n                using 6 by auto\n              have tmp2: \"(remove1 c (a#bl)) @ cl = remove1 c ((a#bl)@ cl)\"\n                using 6by (metis remove1_append)\n              have tmp3: \"\\<forall>j. j < (length ((remove1 c (a#bl)) @ cl)) \\<and> j \\<ge> 0 \\<longrightarrow> c \\<noteq> (nth ((remove1 c (a#bl)) @ cl) j)\"\n                using Cons(8) tmp1 Unique_k tmp2 by metis\n              have tmp4: \"Unique ((remove1 c (a#bl)) @ cl)\"\n                using Cons(8) Unique_remove tmp1 by (metis tmp2)\n              then show ?thesis using tmp3 Unique_add2 by (metis append.assoc)\n            qed\n            have 13: \"Graph (set ((remove1 c (a#bl)) @ cl @ [c]))\"\n            proof -\n              have tmp1: \"set ((remove1 c (a#bl))@[c]) = set (a#bl)\"\n              proof -\n                have \"\\<forall>x \\<in> set ((remove1 c (a#bl))@[c]) . x \\<in> set (a#bl)\"\n                  apply clarify subgoal for x using 6\n                    by (metis Un_iff empty_iff in_set_remove1 list.set(1) remove_hd set_append)\n                  done\n                moreover have \"\\<forall>x \\<in> set (a#bl). x \\<in> set ((remove1 c (a#bl))@[c])\"\n                  apply clarify subgoal for x using 6\n                    by (metis Un_iff in_set_remove1 list.set_intros(1) set_append)\n                  done\n                ultimately show ?thesis by auto\n              qed\n              have tmp2: \"set ((remove1 c (a#bl)) @ cl @ [c]) = set ((a # bl) @ cl)\"\n                using tmp1 using inf_sup_aci(7) by auto\n              then show ?thesis using Cons(9) by simp\n            qed\n            show ?thesis using Cons(2) 7 5 8 9 10 11 12 13 by blast\n          qed\n          done\n      qed\n    qed\n  qed\nqed\n\n definition sortDiag :: \"block list \\<Rightarrow> sorted_block_list\" where\n\"sortDiag bl = topological_sort bl bl []\"\n\n\ndefinition \"loop_free bl = (length (sortDiag bl) = length bl)\"\n\ndeclare loop_free_def [simp]\n\nlemma sort_is_sorted : \"Unique bl \\<Longrightarrow> Graph (set bl) \\<Longrightarrow> besorted (sortDiag bl)\"\n  subgoal premises pre\nproof -\n  have 1: \"after_0indegree bl []\"\n    unfolding after_0indegree_def get_block_indegree_def by simp\n  have 2: \"besorted_change []\"\n    unfolding besorted_change_def by simp\n  have 3: \"Outputs bl = Outputs bl \\<union> Outputs []\"\n    by simp\n  have 4: \"\\<forall>i j. i \\<in> set bl \\<and> j \\<in> set [] \\<longrightarrow>\n        check_offset (get_outputs i) (get_inputs j) (get_offsets j) = False\"\n    by simp\n  show ?thesis\n    using  topo_besorted[of bl bl \"[]\"] unfolding sortDiag_def using 1 2 3 4 pre(1,2)\n    using besorted_equiv by simp\nqed\n  done\n\nlemma sort_subset: \"length (topological_sort al bl cl) = length (bl@cl) \\<Longrightarrow>\nset (bl@cl) = set (topological_sort al bl cl)\"\nproof(induction bl arbitrary: cl rule: wf_induct[of \"{(x, y). length x < length y}\"])\n  case 1\n  then show ?case unfolding wf_def\n    by (metis (no_types, lifting) case_prodD length_induct mem_Collect_eq)\nnext\n  case (2 bl)\n  then show ?case\n  proof(cases \"bl = []\")\n    case True\n    then show ?thesis by simp\n  next\n    case False\n    have 3: \"length (snd (find_0indegree_blocks al bl cl)) < length bl\"\n      using 2(2) unfolding loop_free_def sortDiag_def using topological_sort.simps[of al bl cl]\n      by (smt (verit) False append_Nil append_eq_append_conv length_find_0indegree)\n    have 4: \"topological_sort al bl cl = (let x = find_0indegree_blocks al bl cl in \n      topological_sort al (snd x) (cl @ [the (fst x)]))\"\n      using topological_sort.simps[of al bl cl] 2(2) False\n      by (smt (verit) append.left_neutral append_eq_append_conv)\n    have 5: \"fst (find_0indegree_blocks al bl cl) \\<noteq> None\"\n      using 4 topological_sort.simps[of al bl cl] \"2.prems\" False append_eq_append_conv2 by fastforce\n    have 6: \"length (bl@cl) = length (let x = find_0indegree_blocks al bl cl in \n      ((snd x)@(cl @ [the (fst x)])))\"\n      using find_0indegree_lemma4 5 by force\n    have 7: \"(let x = find_0indegree_blocks al bl cl in length \n      (topological_sort al (snd x) (cl @ [the (fst x)])) = length ((snd x)@(cl @ [the (fst x)])))\"\n      using 2(2) 4 6 by metis\n    have 8: \"set (bl) = set (let x = find_0indegree_blocks al bl cl in \n      ((snd x)@([the (fst x)])))\"\n      using 5 find_0indegree_lemma3 by (metis append_Cons append_Nil inf_sup_aci(5) set_append)\n    have 9: \"set (bl @ cl) = set (let x = find_0indegree_blocks al bl cl in \n      ((snd x)@(cl@[the (fst x)])))\"\n      using 8 by (metis append_assoc inf_sup_aci(5) set_append)\n    then show ?thesis using 2(1) 3 6 4 7 by (metis case_prodI mem_Collect_eq)\n  qed\nqed\n\nlemma toposort_perm: \"length (topological_sort al bl cl) = length (bl@cl) \\<Longrightarrow>\n(bl@cl) <~~> (topological_sort al bl cl)\"\nproof(induction bl arbitrary: cl rule: wf_induct[of \"{(x, y). length x < length y}\"])\n  case 1\n  then show ?case unfolding wf_def\n    by (metis (no_types, lifting) case_prodD length_induct mem_Collect_eq)\nnext\n  case (2 bl)\n  then show ?case\n  proof(cases \"bl = []\")\n    case True\n    then show ?thesis by simp\n  next\n    case False\n    have 3: \"length (snd (find_0indegree_blocks al bl cl)) < length bl\"\n      using 2(2) unfolding loop_free_def sortDiag_def using topological_sort.simps[of al bl cl]\n      by (smt (verit) False append_Nil append_eq_append_conv length_find_0indegree)\n    have 4: \"topological_sort al bl cl = (let x = find_0indegree_blocks al bl cl in \n      topological_sort al (snd x) (cl @ [the (fst x)]))\"\n      using topological_sort.simps[of al bl cl] 2(2) False\n      by (smt (verit) append.left_neutral append_eq_append_conv)\n    have 5: \"fst (find_0indegree_blocks al bl cl) \\<noteq> None\"\n      using 4 topological_sort.simps[of al bl cl] \"2.prems\" False append_eq_append_conv2 by fastforce\n    have 6: \"length (bl@cl) = length (let x = find_0indegree_blocks al bl cl in \n      ((snd x)@(cl @ [the (fst x)])))\"\n      using find_0indegree_lemma4 5 by force\n    have 7: \"length (let x = find_0indegree_blocks al bl cl in snd x @ cl @ [the (fst x)]) = \n      length (let x = find_0indegree_blocks al bl cl in topological_sort al (snd x) (cl @ [the (fst x)]))\"\n      using 4 6 2(2) by presburger\n    have 8: \"(let x = find_0indegree_blocks al bl cl in \n      (topological_sort al (snd x) (cl @ [the (fst x)])) <~~> ((snd x)@(cl @ [the (fst x)])))\"\n      using 2(1) 3 7 by (metis case_prodI mem_Collect_eq perm_sym)\n    have 9: \"(bl@cl) <~~> (let x = find_0indegree_blocks al bl cl in \n      ((snd x)@(cl @ [the (fst x)])))\"\n      using find_0indegree_block_lemma2 find_0indegree_lemma4 5 perm_remove3  by (smt (verit, \n        del_insts) find_0indegree_lemma3 list.set_intros(1) option.collapse prod.exhaust_sel)\n    then show ?thesis using 4 8 by (metis perm.trans perm_sym)\n  qed\nqed\n\nlemma sort_perm: \"loop_free bl \\<Longrightarrow> bl <~~> sortDiag bl\"\n  using toposort_perm unfolding loop_free_def sortDiag_def\n  by (metis append.right_neutral)\n\ntype_synonym timed_vars = \"var \\<Rightarrow> real \\<Rightarrow> real\"\n\ntype_synonym behav = \"timed_vars \\<Rightarrow> bool\"\n\ndefinition \"internal bl = {x . (\\<exists> A \\<in> set bl . \\<exists> B \\<in> set bl . x \\<in> set (get_outputs A) \\<and> x \\<in> set (get_inputs B))}\"\n\n\\<comment> \\<open>remove those vars in s in order to find the inputs and outputs for a diagram\\<close>\nprimrec remove_set :: \"var set \\<Rightarrow> var list \\<Rightarrow> var list\" where \n\"remove_set s [] = []\" |\n\"remove_set s (v#vl) = (if (v \\<in> s) then remove_set s vl else (v # remove_set s vl))\"\n\nprimrec in_blocklist ::  \"var set \\<Rightarrow> block list \\<Rightarrow> var list\" where\n\"in_blocklist vs [] = []\" |\n\"in_blocklist vs (b#bl) = (remove_set vs (get_inputs b)) @ (in_blocklist vs bl)\"\n\n\\<comment> \\<open>The input vars of a diagram\\<close>\ndefinition in_diag :: \"block list \\<Rightarrow> var list\" where \n\"in_diag bl = in_blocklist (internal bl) bl\"\n\nprimrec out_blocklist ::  \"var set \\<Rightarrow> block list \\<Rightarrow> var list\" where\n\"out_blocklist vs [] = []\" |\n\"out_blocklist vs (b#bl) = (remove_set vs (get_outputs b)) @ (out_blocklist vs bl)\"\n\n\\<comment> \\<open>The output vars of a digram\\<close>\ndefinition out_diag :: \"block list \\<Rightarrow> var list\" where \n\"out_diag bl = out_blocklist (internal bl) bl\"\n\ndefinition connected_blocks :: \"block \\<Rightarrow> block \\<Rightarrow> bool\" where\n\"connected_blocks a b = (if (set (get_outputs a) \\<inter> set (get_inputs b) \\<noteq> {}) \\<or> (set (get_outputs b) \\<inter> set (get_inputs a) \\<noteq> {})\n                           then True else False)\"\n\n\\<comment> \\<open>get those blocks whose sample_time = -1 \\<close>\nprimrec get_inherited_blocks :: \"block list \\<Rightarrow> block list\" where\n\"get_inherited_blocks [] = []\" |\n\"get_inherited_blocks (b#bl) = (if (get_sample_time b = -1) then (b#(get_inherited_blocks bl)) else (get_inherited_blocks bl))\"\n\n\\<comment> \\<open>get those blocks whose sample_time \\<noteq> -1 \\<close>\nprimrec get_definite_blocks :: \"block list \\<Rightarrow> block list\" where\n\"get_definite_blocks [] = []\" |\n\"get_definite_blocks (b#bl) = (if (get_sample_time b \\<noteq> -1) then (b#(get_definite_blocks bl)) else (get_definite_blocks bl))\"\n\n\\<comment> \\<open>The sample time of a variable is the same as the sample time of the corresponding block. \\<close>\nprimrec sample_time_var :: \"var \\<Rightarrow> block list \\<Rightarrow> sample_time\" where\n\"sample_time_var x [] = -1\" |\n\"sample_time_var x (b#bl) = (if ((x \\<in> set (get_outputs b) \\<or> x \\<in> set (get_inputs b)) \\<and> get_sample_time b \\<noteq> -1)\n                               then get_sample_time b else sample_time_var x bl)\"\n\n\\<comment> \\<open>True => the sample time of all the vars are unknown\\<close>\nprimrec unknown_st_vars :: \"var list \\<Rightarrow> block list \\<Rightarrow> bool\" where\n\"unknown_st_vars [] bl =  True\" |\n\"unknown_st_vars (a#al) bl = (if sample_time_var a bl \\<noteq> -1 then False else unknown_st_vars al bl) \"\n\nfun gcd' :: \"int \\<Rightarrow> int \\<Rightarrow> int\" where\n  \"gcd' x y = (if x = 0 \\<and> y = 0 then 0 else (if x = -1 then y else (if y = -1 then x\nelse gcd x y)))\"\n\n\\<comment> \\<open>This function is only used when the sample time of some var is known \\<close>\nprimrec sample_time_vars :: \"var list \\<Rightarrow> block list \\<Rightarrow> sample_time\" where\n\"sample_time_vars [] bl = -1\" |\n\"sample_time_vars (v # vl) bl = (if sample_time_var v bl = -1 then sample_time_vars vl bl \n                                    else gcd' (sample_time_var v bl) (sample_time_vars vl bl))\"\n\ndefinition update_sample_time :: \"block \\<Rightarrow> sample_time \\<Rightarrow> block\" where\n\"update_sample_time b s = Block (get_inputs b) (get_outputs b) (get_offsets b) s (get_outupd b)\"\n\n\\<comment> \\<open>compute the sample time of an inherited block from its inputs\\<close>\nprimrec compute_st_forward :: \"block list \\<Rightarrow> block list \\<Rightarrow> block list\" where\n\"compute_st_forward []  bl = bl\" |\n\"compute_st_forward (a # al) bl = (if (get_sample_time a = -1 \\<and> \\<not> unknown_st_vars (get_inputs a) bl) \n         then compute_st_forward al (bl@[update_sample_time a (sample_time_vars (get_inputs a) bl)]) \n         else compute_st_forward al (bl@[a]))\"\n\n\\<comment> \\<open>compute the sample time of an inherited block from its outputs backward (reverse blocks at first)\\<close>\nprimrec compute_st_backward :: \"block list \\<Rightarrow> block list \\<Rightarrow> block list\" where\n\"compute_st_backward []  bl = bl\" |\n\"compute_st_backward (a # al) bl = (if (get_sample_time a = -1 \\<and> \\<not> unknown_st_vars (get_outputs a) bl) \n         then compute_st_backward al (bl@[update_sample_time a (sample_time_vars (get_outputs a) bl)]) \n         else compute_st_backward al (bl@[a]))\"\n\nfun compSt :: \"block list \\<Rightarrow> block list \\<Rightarrow> block list\" where\n\"compSt al bl = compute_st_backward (get_inherited_blocks (compute_st_forward al bl)) \n  (get_definite_blocks (compute_st_forward al bl))\"\n\nend", "meta": {"author": "bzhan", "repo": "mars", "sha": "d10e489a8ddf128a4cbac13291efdece458d732d", "save_path": "github-repos/isabelle/bzhan-mars", "path": "github-repos/isabelle/bzhan-mars/mars-d10e489a8ddf128a4cbac13291efdece458d732d/Semantics_Simulink/DiscreteSyntax.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.265071127088915}}
{"text": "theory\n  Refine_Info\n  imports\n    Refine_Unions\n    Refine_Vector_List\nbegin\n\nconsts i_info::\"interface\\<Rightarrow>interface\\<Rightarrow>interface\"\n\ndefinition info_rel_internal: \"info_rel I S = (I \\<times>\\<^sub>r S) O br snd top\"\nlemma info_rel_def: \"\\<langle>I, S\\<rangle>info_rel = (I \\<times>\\<^sub>r S) O br snd top\"\n  by (auto simp: relAPP_def info_rel_internal)\nlemmas [autoref_rel_intf] = REL_INTFI[of \"info_rel\" i_info]\n\nlemma info_rel_br: \"\\<langle>br a I, (br b J)\\<rangle>info_rel = br (\\<lambda>y. b (snd y)) (\\<lambda>x. I (fst x) \\<and> J (snd x))\"\n  by (auto simp: info_rel_def br_def prod_rel_def)\n\nlemma sv_info_rel[relator_props]:\n  \"single_valued S \\<Longrightarrow>single_valued I \\<Longrightarrow> single_valued (\\<langle>I, S\\<rangle>info_rel)\"\n  by (auto simp: info_rel_def intro!: relator_props)\n\ndefinition [simp]: \"op_info_is_empty = is_empty\"\ncontext includes autoref_syntax begin\n\n\nlemma op_set_isEmpty_info_rel_set[autoref_rules]:\n  \"GEN_OP empty_i (is_empty) (A \\<rightarrow> bool_rel) \\<Longrightarrow> (\\<lambda>x. empty_i (snd x), op_info_is_empty) \\<in> \\<langle>I, A\\<rangle>info_rel \\<rightarrow> bool_rel\"\n  by (auto simp: info_rel_def br_def op_set_isEmpty_def[abs_def] dest: fun_relD)\n\ndefinition [refine_vcg_def]: \"get_info X = SPEC (\\<lambda>(h, Y). Y = X)\"\nlemma get_info_autoref[autoref_rules]:\n  shows \"(\\<lambda>x. RETURN x, get_info) \\<in> \\<langle>I, A\\<rangle>info_rel \\<rightarrow> \\<langle>I \\<times>\\<^sub>r A\\<rangle>nres_rel\"\n  by (force simp: get_info_def info_rel_def nres_rel_def br_def intro!: RETURN_SPEC_refine)\n\ndefinition with_info::\"'b \\<Rightarrow> 'a set \\<Rightarrow> 'a set\"\n  where [simp, refine_vcg_def]: \"with_info h x = x\"\n\nlemma with_stepsize_autoref[autoref_rules]:\n  \"((\\<lambda>h x. (h, x)), with_info) \\<in> R \\<rightarrow> A \\<rightarrow> \\<langle>R, A\\<rangle>info_rel\"\n  by (auto simp: info_rel_def br_def intro!: prod_relI)\n\ndefinition with_half_stepsizes::\"'a set \\<Rightarrow> 'a set\"\n  where [simp, refine_vcg_def]: \"with_half_stepsizes x = x\"\nlemma with_half_stepsize_autoref[autoref_rules]:\n  \"((map (\\<lambda>(h, x). (h/2, x))), with_half_stepsizes) \\<in>\n  clw_rel (\\<langle>rnv_rel, A\\<rangle>info_rel) \\<rightarrow> clw_rel (\\<langle>rnv_rel, A\\<rangle>info_rel)\"\n  if  [unfolded autoref_tag_defs, relator_props]: \"single_valued A\"\n  unfolding with_half_stepsizes_def\n  apply (rule lift_clw_rel_map)\n     apply (rule relator_props)+\n  by (auto simp: info_rel_def br_def prod_rel_def)\n\ndefinition with_infos::\"'b \\<Rightarrow> 'a set \\<Rightarrow> 'a set\"\n  where [simp, refine_vcg_def]: \"with_infos h x = x\"\nlemma with_infos_autoref[autoref_rules]:\n  \"(\\<lambda>h. map (Pair h), with_infos) \\<in> R \\<rightarrow> clw_rel A \\<rightarrow> clw_rel (\\<langle>R, A\\<rangle>info_rel)\"\n  if [unfolded autoref_tag_defs, relator_props]: \"PREFER single_valued A\" \"PREFER single_valued R\"\n  unfolding with_infos_def\n  apply (rule fun_relI)\n  apply (rule lift_clw_rel_map)\n     apply (rule relator_props)+\n  by (auto simp: info_rel_def br_def prod_rel_def)\n\nabbreviation \"with_stepsize \\<equiv> (with_info::real\\<Rightarrow>_)\"\n\ndefinition split_with_info::\"'a set \\<Rightarrow> ('c \\<times> 'a set \\<times> 'a set) nres\"\n  where [refine_vcg_def]: \"split_with_info X = SPEC (\\<lambda>(S, Y, YS). X = Y \\<union> YS)\"\n\ncontext includes autoref_syntax begin\nlemma split_with_info_appr_plane_autoref[autoref_rules]:\n  assumes \"PREFER single_valued A\"\n  assumes \"PREFER single_valued S\"\n  assumes \"(xs, X) \\<in> clw_rel (\\<langle>A,S\\<rangle>info_rel)\"\n  shows\n    \"(if xs = [] then SUCCEED else let s = fst (hd xs); (a, b) = List.partition (\\<lambda>(sctn, _). sctn = s) xs in RETURN (s, map snd a, b),\n    split_with_info $ X) \\<in>\n    \\<langle>A \\<times>\\<^sub>r clw_rel S \\<times>\\<^sub>r clw_rel (\\<langle>A, S\\<rangle>info_rel)\\<rangle>nres_rel\"\n  using assms\n  by (fastforce simp: Let_def split_with_info_def split_beta'\n      lw_rel_def Union_rel_br info_rel_br ex_br_conj_iff Id_br[where 'a=\"'a sctn\"]\n      split: if_splits\n      elim!: single_valued_as_brE\n      intro!: nres_relI RETURN_SPEC_refine brI hd_in_set\n      dest!: brD )\n\ndefinition\n  \"explicit_info_set X0 =\n    do {\n      e \\<leftarrow> isEmpty_spec X0;\n      (_, _, Xis) \\<leftarrow> WHILE\\<^bsup>\\<lambda>(e, X, Y).\n          (e \\<longrightarrow> X = {}) \\<and>\n          X0 = X \\<union> (\\<Union>(sctn, IS)\\<in>Y. IS)\\<^esup>\n        (\\<lambda>(e, X, Y). \\<not>e)\n        (\\<lambda>(e, X, Y).\n          do {\n            (sctn, S, X') \\<leftarrow> split_with_info X;\n            e \\<leftarrow> isEmpty_spec X';\n            RETURN (e, X', insert (sctn, S) Y)\n          }\n        )\n        (e, X0, {});\n      RETURN Xis\n    }\"\n\nschematic_goal explicit_info_setc:\n  fixes po :: \"'d \\<Rightarrow> 'a::executable_euclidean_space set\"\n  assumes [THEN PREFER_sv_D, relator_props]: \"PREFER single_valued A\"\n  assumes [THEN PREFER_sv_D, relator_props]: \"PREFER single_valued S\"\n  assumes [autoref_rules]: \"(XSi, XS) \\<in> clw_rel (\\<langle>S, A\\<rangle>info_rel)\"\n  shows \"(nres_of ?f, explicit_info_set $ XS) \\<in> \\<langle>\\<langle>S \\<times>\\<^sub>r clw_rel A\\<rangle>list_wset_rel\\<rangle>nres_rel\"\n  unfolding autoref_tag_defs\n  unfolding explicit_info_set_def\n  including art\n  by autoref_monadic\nconcrete_definition explicit_info_setc for XSi uses explicit_info_setc\nlemmas [autoref_rules] = explicit_info_setc.refine\n\nlemma explicit_info_set[THEN order_trans, refine_vcg]:\n  \"explicit_info_set X \\<le> SPEC (\\<lambda>R. X = (\\<Union>(sctn, IS) \\<in> R. IS))\"\n  unfolding explicit_info_set_def\n  by (refine_vcg) (auto simp: split_beta' subset_iff)\n\nlemmas [relator_props del] = sv_info_rel\nlemma sv_info_rel'[relator_props]:\n  \"single_valued S \\<Longrightarrow> single_valued (\\<langle>I, S\\<rangle>info_rel)\"\n  by (auto simp: info_rel_def single_valued_def br_def)\n\nlemma\n  is_empty_info_rel_autoref[autoref_rules]:\n  \"GEN_OP ie is_empty (A \\<rightarrow> bool_rel) \\<Longrightarrow> (\\<lambda>x. ie(snd x), is_empty) \\<in> \\<langle>R, A\\<rangle>info_rel \\<rightarrow> bool_rel\"\n  by (force simp: info_rel_def br_def dest: fun_relD)\n\ndefinition with_coll_infos::\"'c set \\<Rightarrow> 'a set \\<Rightarrow> 'a set nres\"\n  where [simp, refine_vcg_def]: \"with_coll_infos h x = SPEC (\\<lambda>r. r = x)\"\n\nlemma with_coll_infos_autoref[autoref_rules]:\n  \"((\\<lambda>ri ai. nres_of (if ri = [] then dSUCCEED else dRETURN (List.product ri ai))), with_coll_infos) \\<in>\n    clw_rel R \\<rightarrow> clw_rel A \\<rightarrow> \\<langle>clw_rel (\\<langle>R, A\\<rangle>info_rel)\\<rangle>nres_rel\"\n  if \"PREFER single_valued R\" \"PREFER single_valued A\"\n  using that\n  by (force simp: relcomp_unfold nres_rel_def info_rel_br list_wset_rel_def Union_rel_br\n      Id_arbitrary_interface_def RETURN_RES_refine_iff set_rel_br\n      elim!: single_valued_as_brE\n      intro!: brI dest!: brD\n      split: if_splits)\n\nend\n\nend", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Ordinary_Differential_Equations/Refinement/Refine_Info.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.265071127088915}}
{"text": "section {* Abstract syntax for Hybrid CSP. *}\n\ntheory HHL1\n  imports  HCSP_Com\nbegin\n\nconsts \nspec :: \"fform => proc => fform => fform => prop\"   (\"{_}_{_;_}\" 80)\nspecP2 :: \"fform => fform => proc => fform => fform => fform  => fform => prop\"   (\"{_, _}_{_, _ ; _, _}\" 80)\nspecP3 :: \"fform => fform => fform => proc => fform => fform => fform => fform => fform => fform => prop\"(\"{_,_,_}_{_,_,_; _,_,_}\" 80)\nspecP4 :: \"fform => fform => fform => fform => proc => fform => fform => fform => fform => fform  => fform => fform  => fform => prop\"   (\"{_,_,_,_}_{_,_,_,_ ; _,_,_,_}\" 80)\nspecP5 :: \"fform => fform => fform => fform => fform => proc => fform => fform => fform => fform => fform => fform  => fform => fform  => fform => fform  => prop\"   (\"{_,_,_,_,_}_{_,_,_,_,_ ; _,_,_,_,_}\" 80)\nspecP6 :: \"fform => fform => fform => fform => fform => fform => proc => fform => fform => fform => fform => fform => fform => fform  => fform => fform => fform => fform => fform  => prop\"   (\"{_,_,_,_,_,_}_{_,_,_,_,_,_ ; _,_,_,_,_,_}\" 80)\n\n(*List rules, p do not have exp1. If p have exp1, it must be eliminated by consequence rule firstly.*)\naxiomatization where\nListEmpty : \"{p} empty(exp1) {exp1[=](List [])[&]p; (l [=] (Real 0))}\" and\nListAdd : \"{exp1[=](List ls)[&]p} (addL exp1 exp2) {(exp1[=](List (exp2#ls)))[&]p; (l [=] (Real 0))}\" and\nListDel : \"|- exp1[=](List (tl(ls)))[&]p [-->] post\n  ==> {exp1[=](List ls)[&]p} (delL(exp1)) {post; (l [=] (Real 0))}\" and\nListEmptya : \"{p} empty(exp1) {p; (l [=] (Real 0))}\" and\nListAdda : \"{p} (addL exp1 exp2) {p; (l [=] (Real 0))}\" and\nListDela : \"{p} (delL(exp1)) {p; (l [=] (Real 0))}\"\naxiomatization where\nEmpty: \"EL [=] List [] |- isEmpty(EL)\"\n\n(*Skip rule*)\naxiomatization where\nSkip : \"|- ((l [=] (Real 0)) [-->] G) ==> {p} Skip {p; G}\" \n\n\n(*Assignment rule*)\naxiomatization where\nAssign  :\" [| ~inPairForm ([(e, f)], q); |-(p [-->] (substF ([(e, f)]) (q)))\n        [&]   ((l [=] (Real 0)) [-->] G)|] ==>\n       {p} (e := f) {q; G}\"\n\n\n(*Example*)\nlemma \"{WTrue} (RVar ''x'') := (Real 2) {((RVar ''x'') [=] (Real 2)); (l [=] (Real 0))}\"\napply (cut_tac p = \"WTrue\" and e = \"(RVar ''x'')\" and f = \"(Real 2)\" and \n                q = \"((RVar ''x'') [=] (Real 2))\" and G = \"(l [=] (Real 0))\" in Assign, auto)\napply (rule Trans,auto)\ndone\n\n\n\n(*Continuous rule*)\naxiomatization where\nContinue : \"|- (Init [-->] FF)\n           [&] ((p [&] close(FF) [&] close([~]b)) [-->] q)\n           [&] ((((l [=] Real 0) [|] (high (close(FF) [&] p [&] close(b)))) [&] Rg) [-->] G)\n           ==> {Init [&] p} <FF&&b> : Rg {q; G}\" and\nContinueT : \"|- (Init[&]p [-->]FF[&]b)\n           [&] ((p [&] close(FF) [&] close(b) [&] close([~]b)) [-->] q)\n           [&] ((((l [=] Real 0) [|] (high (close(FF) [&] p [&] close(b)))) [&] Rg) [-->] G)\n           ==> {Init [&] p} <FF&&(b)> : Rg {q; G}\" and\nContinueF : \"|- (p[-->][~]b) [&] (p[-->]q) [&] ((l[=](Real 0))[-->]G)\n           ==> {p} <FF&&b> : Rg {q; G}\"\n\n(*Continuous rule 2*)\naxiomatization where\nContinue2 : \"|- (Init [-->] FF)\n           [&] ((p [&] close(FF) [&] close([~]b)) [-->] q)\n           [&] ((((l [=] Real 0) [|] (high (close(FF) [&] p [&] close(b)))) [&] Rg) [-->] G)\n[&] (exeFlow (D,b,F1) [-->]FF)\n           ==> {Init [&] p} <D&&FF&&b> : Rg {q; G}\"  and\nContinue2T : \"|- (Init[&]p [-->] FF[&]b)\n           [&] ((p [&] close(FF) [&] close(b) [&] close([~]b)) [-->] q)\n           [&] ((((l [=] Real 0) [|] (high (close(FF) [&] p [&] close(b)))) [&] Rg) [-->] G)\n[&](exeFlow (D,b,FF) [-->]FF)\n           ==> {Init [&] p} <D&&FF&&(b)> : Rg {q; G}\" and\nContinue2F : \"|- (p[-->][~]b) [&] (p[-->]q) [&] ((l[=](Real 0))[-->]G)\n           ==> {p} <D&&FF&&b> : Rg {q; G}\"\n\n(*Sequential rule*)\naxiomatization where\nSequence : \"[| {p} P {m; H}; {m} Q {q; G} |] ==>\n             {p} P; (m, H); Q {q; H [^] G}\" \naxiomatization where\nSequence1 : \"[| {p} P {m; H}; {m} Q {q; G} |] ==>\n             {p} P; M; Q {q; H [^] G}\" \n\n(*Case rule*)\naxiomatization where\nCase : \"[| {p [&] b} P {q; G}; {p [&] ([~]b)} P {q; G}|] \n             ==> {p} P {q; G}\"\n         \n\n(*Conditional rule*)\naxiomatization where\nConditionF : \" [| |-(p [-->] [~] b); |- (p [-->] q); |- ((l [=] Real 0) [-->] G) |]\n             ==> {p} IF b P {q; G}\"\nand\nConditionT :  \"[| |-(p [-->] b); {p} P {q; G} |]\n             ==> {p} IF b P {q; G}\"\nand\nCondition : \"[| {p [&] b} IF b P {q; G}; {p [&] ([~]b)} IF b P {q; G}|] \n             ==> {p} IF b P {q; G}\"\naxiomatization where\nConditionT2 :  \"[| |-(pn [-->] b); {pm,pn} (Pm||Pn) {qm,qn; Gm,Gn} |]\n  ==> {pm,pn} (Pm||(IF b Pn)) {qm,qn; Gm,Gn}\" and\nConditionT2a :  \"[| |-(pm [-->] b); {pm,pn} (Pm||Pn) {qm,qn; Gm,Gn} |]\n  ==> {pm,pn} ((IF b Pm)||Pn) {qm,qn; Gm,Gn}\"\n\n\n(*Nondeterministic rule*)\naxiomatization where\nNondeterministic :\n\"{p [&] b} P {q;G}\n  ==> {p} NON i x : b P {q; G}\"\n\n(*Communication rule*)\n(*H in the rule denotes the common interval range.*)\naxiomatization where\nCommunication : \"[| ~inPairForm ([(x, e)], ry);\n                    {px, py} (Px || Py) {qx, qy; Hx, Hy}; \n                    |- (qx [-->] rx) [&] (qy [-->] (substF ([(x, e)]) (ry)));\n                    |- ((Hx [^] (high (qx))) [-->] Gx) [&] ((Hy [^] (high (qy))) [-->] Gy);\n                    |- ((((Hx [^] (high (qx))) [&] Hy) [|]((Hy [^] (high (qy))) [&] Hx)) [-->] H)\n                 |]\n              ==>   {px, py} ((Px; (qx, Hx); ch !! e) || (Py; (qy, Hy); ch ?? x)) {rx, ry; \n                    Gx [&] H, Gy [&] H}\"\naxiomatization where\nCommunication1 : \"[| ~inPairForm ([(x, e)], ry);\n                    {px, py} (Px || Py) {qx, qy; Hx, Hy}; \n                    |- (qx [-->] rx) [&] (qx[&]qy [-->] (substF ([(x, e)]) (ry)));\n                    |- ((Hx [^] (high (qx))) [-->] Gx) [&] ((Hy [^] (high (qy))) [-->] Gy);\n                    |- ((((Hx [^] (high (qx))) [&] Hy) [|]((Hy [^] (high (qy))) [&] Hx)) [-->] H)\n                 |]\n              ==>   {px, py} ((Px; (qx, Hx); ch !! e) || (Py; (qy, Hy); ch ?? x)) {rx, ry; \n                    Gx [&] H, Gy [&] H}\"\naxiomatization where\nCommunicationSim : \"[| ~inPairForm ([(x, e)], ry);\n  |- (px [-->] rx) [&] (px[&]py [-->] (substF ([(x, e)]) (ry))) |]\n  ==>  {px, py} ((ch !! e) || (ch ?? x)) {rx, ry;(l[=](Real 0)), (l[=](Real 0))}\"\naxiomatization where\nCommunicationC : \"[| ~inPairForm ([(x, e)], ry);\n                    {qx} (Px) {rx; (l[=](Real 0))}; \n                    |- (px [&] py) [-->] (substF ([(x, e)]) (qx));\n                    |- py [-->] ry;\n                    |- (l[=](Real 0)) [-->] Hx;\n                    |- (l[=](Real 0)) [-->] My;\n                    |- (l[=](Real 0)) [-->] My;\n                   contain(Pm,(ch ?? x))|]\n              ==>   {px, py} (( Pm; (qx, Hx); Px) || (ch !! e))\n                    {rx, ry; Mx, My}\"\n\n(*Communication interrupt rule*)\nprimrec contain :: \"proc => proc => bool\" where\n\"contain (Skip,p) = False\" |\n\"contain (Stop,p) = False\" |\n\"contain (x:=e,p) = False\" |\n\"contain ((Ch!!e),p) = ((Ch!!e)=p)\" |\n\"contain ((Ch??x),p) = ((Ch??x)=p)\" |\n\"contain ((q;m;r),p) = False\" |\n\"contain ((IF b q),p) = False\" |\n\"contain ((NON i x : b q),p) = False\" |\n\"contain ((q [[ r),p) = (if contain(q,p) then True else contain(r,p))\" |\n\"contain ((q << r),p) = False\" |\n\"contain ((q || r),p) = False\" |\n\"contain ((q*),p) = False\" |\n\"contain ((q**n),p) = False\" |\n\"contain ((<FF && b> : g),p) = False\" |\n\"contain ((q |> b r),p) = False\" |\n\"contain ((q [[> r),p) = False\"\n\n(**)\naxiomatization where\nCommunicationI1 : \"[| ~inPairForm ([(x, e)], ry);\n                    |- Hy [-->] H;\n                    |- rg [-->] H[^]WTrue;\n                    {px, py} (Px || Py) {qx, qy; Hx, Hy}; \n                    |- Init [&] pre [<->] qx;\n                    |- pre [&] Init [&] b [-->] FF;\n                    |- (pre [&] close(FF) [&] close(b)) [-->] rx;\n                    |- (qy [&] pre [&] close(FF) [&] close(b)) [-->] (substF ([(x, e)]) (ry));\n                    |- (Hx [^] ((((l [=] Real 0) [|] (high (close(FF) [&] pre [&] close(b)))) [&] H)) [-->] Gx);\n                    |- Hy [-->] Gy;\n                    |- Hx [-->] Hxm;\n                    |- Hy [-->] Hym;\n                    contain(P,(ch !! e))\n                 |]\n              ==>   {px, py} (( Px; (qx, Hxm); (<FF && b> :rg) [[> P) || (Py; (qy, Hym); ch ?? x))\n                    {rx, ry; Gx, Gy}\"\naxiomatization where\nCommunicationI2 : \"[| ~inPairForm ([(x, e)], ry);\n                    |- Hy [-->] H;\n                    |- rg [-->] H[^]WTrue;\n                    {px, py} (Px || Py) {qx, qy; Hx, Hy}; \n                    |- Init [&] pre [<->] qx;\n                    |- pre [&] Init [&] b [-->] FF;\n                    |- (qy [&] pre [&] close(FF) [&] close(b)) [-->] (substF ([(x, e)]) (rx));\n                    |- qy [-->] ry;\n                    |- Hx [^] ((((l [=] Real 0) [|] (high (close(FF) [&] pre [&] close(b)))) [&] H)) [-->] Gx;\n                    |- Hy [-->] Gy;\n                    |- Hx [-->] Hxm;\n                    |- Hy [-->] Hym;\n                    contain(P,(ch ?? x))\n                 |]\n              ==>   {px, py} (( Px; (qx, Hxm); (<FF && b> :rg) [[> P) || (Py; (qy, Hym); ch !! e))\n                    {rx, ry; Gx, Gy}\"\n\n(*Parallel rule*)\n(*It is valid only when there are not communications occurring in P3 and P4.*)\naxiomatization where\nParallel1: \"[| {px, py} (Px || Py) {qx, qy; Hx, Hy}; {qx} Qx {rx; Gx}; {qy} Qy {ry; Gy} |]\n           ==>  {px, py} ((Px; (qx, Hx); Qx) || (Py; (qy, Hy); Qy)) {rx, ry; Hx [^] Gx, Hy [^] Gy}\"\n\n(*It is valid only when there are no communications occurring in P1 and P2.*)\naxiomatization where\nParallel2: \"[| {px} Px {qx; Hx}; {py} Py {qy; Hy}|]\n           ==> {px, py} (Px || Py) {qx, qy; Hx, Hy}\"\n(*It is valid in any case*)\naxiomatization where\nParallel3: \"[| {px, py} (Px || Py) {qx, qy; Hx[&](l[=](Real m)), Hy[&](l[=](Real m))};\n               {qx, qy} (Qx || Qy) {rx, ry; Mx, My};\n               |- (Hx[&](l[=](Real m))) [-->] HL;\n               |- (Hy[&](l[=](Real m))) [-->] HR;\n               |- ((Hx[&](l[=](Real m))) [^] Mx) [-->] Gx;\n               |- ((Hy[&](l[=](Real m))) [^] My) [-->] Gy\n            |]\n           ==> {px, py} (Px;(qx,HL);Qx) || (Py;(qy,HR);Qy) {rx, ry; Gx, Gy}\"\n\n(*Repetition rule*)\naxiomatization where\nRep : \"[| {px} (Px) {px; Hx}; |- Hx [^] Hx [-->] Hx|]\n           ==>  {px} (Px*) {px; Hx} \"\naxiomatization where\nRepetition : \"[| {px, py} (Px || Py) {px, py; Hx, Hy};\n                 |- Hx [^] Hx [-->] Hx; |- Hy [^] Hy [-->] Hy|]\n           ==>  {px, py} ((Px*) || (Py*)) {px, py; Hx, Hy} \"\n\naxiomatization where\nRepetition0 : \"(Pm**(0)) == Skip\" and\nRepetition1 : \"(Pm**(Suc(0))) == Pm\" and\nRepetitionN : \"(Pm**(am+1)) == (Pm; M; Pm**am)\"\n\naxiomatization where\nRepetitionA2 : \"{p1,p2} ((Pm**(am+1))||(Pn**(an+1))) {p1,p2; Ha,Hb}\n==> {p1,p2} ((Pm***)||(Pn***)) {p1,p2; Ha,Hb}\"\n\naxiomatization where\nRepetitionG2 : \"[| {p1,p2} ((Pm***)||(Pn***)) {p1,p2; Ha,Hb}; |- Ha [^] Ha [-->] Ha; |- Hb [^] Hb [-->] Hb|]\n==> {p1,p2} (Pm*||Pn*) {p1,p2; Ha,Hb}\"\n\naxiomatization where\nRepetitionA6 : \"{p1,p2,p3,p4,p5,p6} ((Pm**(am+1))||(Pn**(an+1))||(Po**(ao+1))||(Pp**(ap+1))||(Pq**(aq+1))||(Pr**(ar+1))) {p1,p2,p3,p4,p5,p6; Ha,Hb,Hc,Hd,He,Hf}\n==> {p1,p2,p3,p4,p5,p6} ((Pm***)||(Pn***)||(Po***)||(Pp***)||(Pq***)||(Pr***)) {p1,p2,p3,p4,p5,p6; Ha,Hb,Hc,Hd,He,Hf}\"\n\naxiomatization where\nRepetitionG6 : \"[| {p1,p2,p3,p4,p5,p6} ((Pm***)||(Pn***)||(Po***)||(Pp***)||(Pq***)||(Pr***)) {p1,p2,p3,p4,p5,p6; Ha,Hb,Hc,Hd,He,Hf}; |- Ha [^] Ha [-->] Ha; |- Hb [^] Hb [-->] Hb; |- Hc [^] Hc [-->] Hc; |- Hd [^] Hd [-->] Hd; |- He [^] He [-->] He; |- Hf [^] Hf [-->] Hf|]\n==> {p1,p2,p3,p4,p5,p6} (Pm*||Pn*||Po*||Pp*||Pq*||Pr*) {p1,p2,p3,p4,p5,p6; Ha,Hb,Hc,Hd,He,Hf}\"\n\n(*N times repetition request post and history holds for any middle state to ensure RepetitionG holds.*)\naxiomatization where\nRepetitionT1a : \"{px, py} ((Px;M;Pz) || Py) {qx, qy; Hx, Hy}\n           ==>  {px, py} (((Px**1);M;Pz) || Py) {qx, qy; Hx, Hy}\" and\nRepetitionTna : \"[| {px, py} (((Px**m);(qx,H);Px;M;P) || Py) {qx, qy; Hx, Hy};\n                 |- Hx [^] Hx [-->] Hx;\n                 |- H [-->] Hx|]\n           ==>  {px, py} (((Px**(m+1));M;P) || Py) {qx, qy; Hx, Hy}\" and\nRepetitionG : \"[| {px, py} (Px**(m+1) || Py**(n+1)) {px, py; Hx, Hy};\n                 |- Hx [^] Hx [-->] Hx; |- Hy [^] Hy [-->] Hy|]\n           ==>  {px, py} ((Px* ) || (Py* )) {px, py; Hx, Hy} \" and\nRepetitionE : \"[| {px, py} (((P;M;(Px**(n+1)));(qx,Hx);(Px* )) || Py) {qx, qy; Hx, Hy}|]\n           ==>  {px, py} ((P;M;(Px* )) || Py) {qx, qy; Hx, Hy} \"\n\n(*Structure rule*)\naxiomatization where\nStructure : \"{px, py} (Px || Py) {qx, qy; Hx, Hy}\n           ==> {py, px} (Py || Px) {qy, qx; Hy, Hx}\" and\nstructR : \"{px, py} Q||((Px;Mx;Py);My;Pz) {qx, qy; Hx, Hy}\n           ==> {px, py} Q||(Px;Mx;Py;My;Pz){qx, qy; Hx, Hy}\" and\nstructL : \"{px, py} ((Px;Mx;Py);My;Pz)||Q {qx, qy; Hx, Hy}\n           ==> {px, py} (Px;Mx;Py;My;Pz)||Q{qx, qy; Hx, Hy}\" and\nstructSkipL : \"{px, py} (Skip;(px,l[=](Real 0));P)||Q {qx, qy; Hx, Hy}\n           == {px, py} P||Q{qx, qy; Hx, Hy}\" and\nstructSkipR : \"{px, py} (P;(qx,Hx);Skip)||Q {qx, qy; Hx, Hy}\n           == {px, py} P||Q{qx, qy; Hx, Hy}\" and\nEquality2: \"[| Pm==Qm; Pn==Qn; {p1,p2} (Qm||Qn) {p1,p2; Ha,Hb}|]\n==> {p1,p2} (Pm||Pn) {p1,p2; Ha,Hb}\" and\nEquality6: \"[| Pm==Qm; Pn==Qn; Po==Qo; Pp==Qp; Pq==Qq; Pr==Qr; {p1,p2,p3,p4,p5,p6} (Qm||Qn||Qo||Qp||Qq||Qr) {p1,p2,p3,p4,p5,p6; Ha,Hb,Hc,Hd,He,Hf}|]\n==> {p1,p2,p3,p4,p5,p6} (Pm||Pn||Po||Pp||Pq||Pr) {p1,p2,p3,p4,p5,p6; Ha,Hb,Hc,Hd,He,Hf}\"\n\n\n(*Consequence rule*)\naxiomatization where\nConsequenceS : \"[| {px} P {qx; Hx}; |- ((p [-->] px) [&] (qx [-->] q) [&] (Hx [-->] H))|]\n            ==> {p} P {q; H}\"\nand\nConsequenceP : \"[| {px, py} (Px || Py) {qx, qy; Hx, Hy}; \n                   |- ((p [-->] px) [&] (r [-->] py) [&] (qx [-->] q) [&] (qy [-->] s) \n                       [&] (Hx [-->] H) [&] (Hy [-->] G))|]\n            ==> {p, r} (Px || Py) {q, s; H, G}\"\nand\nConsequence6 : \"[|{qa,qb,qc,qd,qe,qf} (Pm||Pn||Po||Pp||Pq||Pr) {ra,rb,rc,rd,re,rf; Ha,Hb,Hc,Hd,He,Hf}; |- (q1[-->]qa) [&] (q2[-->]qb) [&] (q3[-->]qc) [&] (q4[-->]qd)  [&] (q5[-->]qe) [&] (q6[-->]qf); |- (ra[-->]r1) [&] (rb[-->]r2) [&] (rc[-->]r3) [&] (rd[-->]r4)  [&] (re[-->]r5) [&] (rf[-->]r6); |- (Ha[-->]H1) [&] (Hb[-->]H2) [&] (Hc[-->]H3) [&] (Hd[-->]H4) [&] (He[-->]H5) [&] (Hf[-->]H6)|]\n==> {q1,q2,q3,q4,q5,q6} (Pm||Pn||Po||Pp||Pq||Pr) {r1,r2,r3,r4,r5,r6; H1,H2,H3,H4,H5,H6}\"\n\n(*added rules for parallel with more entities*)\naxiomatization where\nParallel23: \"[| {p1,p2} (Pm||Pn) {q1,q2; H1,H2};\n                {p3} Po {q3; H3}|]\n       ==> {p1,p2,p3} (Pm||Pn||Po) {q1,q2,q3; H1,H2,H3}\" and\nParallel24: \"[| {p1,p2,p3} (Pm||Pn||Po) {q1,q2,q3; H1,H2,H3};\n                {p4} Pp {q4; H4}|]\n       ==> {p1,p2,p3,p4} (Pm||Pn||Po||Pp) {q1,q2,q3,q4; H1,H2,H3,H4}\" and\nParallel25: \"[| {p1,p2,p3,p4} (Pm||Pn||Po||Pp) {q1,q2,q3,q4; H1,H2,H3,H4};\n                {p5} Pq {q5; H5}|]\n       ==> {p1,p2,p3,p4,p5} (Pm||Pn||Po||Pp||Pq) {q1,q2,q3,q4,q5; H1,H2,H3,H4,H5}\" and\nParallel26: \"[| {p1,p2,p3,p4,p5} (Pm||Pn||Po||Pp||Pq) {q1,q2,q3,q4,q5; H1,H2,H3,H4,H5};\n                {p6} Pr {q6; H6}|]\n       ==> {p1,p2,p3,p4,p5,p6} (Pm||Pn||Po||Pp||Pq||Pr) {q1,q2,q3,q4,q5,q6; H1,H2,H3,H4,H5,H6}\"\naxiomatization where\nParallelSeq6: \"[| {p1,p2,p3,p4,p5,p6} (Pm||Pn||Po||Pp||Pq||Pr) {q1,q2,q3,q4,q5,q6; Ha,Hb,Hc,Hd,He,Hf}; {r1,r2,r3,r4,r5,r6} (Qm||Qn||Qo||Qp||Qq||Qr) {p1,p2,p3,p4,p5,p6; G1,G2,G3,G4,G5,G6}; |- (G1[^]Ha) [-->] M1; |- (G2[^]Hb) [-->] M2; |- (G3[^]Hc) [-->] M3; |- (G4[^]Hd) [-->] M4; |- (G5[^]He) [-->] M5; |- (G6[^]Hf) [-->] M6|]\n           ==> {r1,r2,r3,r4,r5,r6} ((Qm;(p1,G1);Pm)||(Qn;(p2,G2);Pn)||(Qo;(p3,G3);Po)||(Qp;(p4,G4);Pp)||(Qq;(p5,G5);Pq)||(Qr;(p6,G6);Pr)) {q1,q2,q3,q4,q5,q6; M1,M2,M3,M4,M5,M6}\"\n\naxiomatization where\nParallelSeq6a: \"[|{p1}Pm{q1; Ha}; {p2}Pn{q2; Hb}; {p3}Po{q3; Hc}; {p4}Pp{q4; Hd}; {p5}Pq{q5; He}; {p6}Pr{q6; Hf}|]\n==>  {p1,p2,p3,p4,p5,p6} (Pm||Pn||Po||Pp||Pq||Pr) {q1,q2,q3,q4,q5,q6; Ha,Hb,Hc,Hd,He,Hf}\"\n\naxiomatization where\nParallelSeq12a: \"[| {p1,p2,p3,p4,p5,p6} (Pm||Pn||Po||Pp||Pq||Pr) {q1,q2,q3,q4,q5,q6; Ha,Hb,Hc,Hd,He,Hf}; {r1,r2} (Qm||Qn) {p1,p2; G1,G2}; |- (G1[^]Ha) [-->] M1; |- (G2[^]Hb) [-->] M2|]\n           ==> {r1,r2,p3,p4,p5,p6} ((Qm;(p1,G1);Pm)||(Qn;(p2,G2);Pn)||(Po)||(Pp)||(Pq)||(Pr)) {q1,q2,q3,q4,q5,q6; M1,M2,Hc,Hd,He,Hf}\" and\nParallelSeq25a: \"[| {p1,p2,p3,p4,p6} (Pm||Pn||Po||Pp||Pr) {q1,q2,q3,q4,q6; Ha,Hb,Hc,Hd,Hf}; {r2,r5} (Qn||Qq) {p2,p5; G2,G5}; |- (G2[^]Hb) [-->] M2|]\n           ==> {p1,r2,p3,p4,r5,p6} ((Pm)||(Qn;(p2,G2);Pn)||(Po)||(Pp)||(Qq)||(Pr)) {q1,q2,q3,q4,p5,q6; Ha,M2,Hc,Hd,G5,Hf}\" and\nParallelSeq23a: \"[| {p1,p2,p4,p6} (Pm||Pn||Pp||Pr) {q1,q2,q4,q6; Ha,Hb,Hd,Hf}; {r2,r3} (Qn||Qo) {p2,p3; G2,G3}; |- (G2[^]Hb) [-->] M2|]\n           ==> {p1,r2,r3,p4,p6} ((Pm)||(Qn;(p2,G2);Pn)||(Qo)||(Pp)||(Pr)) {q1,q2,p3,q4,q6; Ha,M2,G3,Hd,Hf}\" and\nParallelSeq23b: \"[| {p1,p2,p6} (Pm||Pn||Pr) {q1,q2,q6; Ha,Hb,Hf}; {r2,r4} (Qn||Qp) {p2,p4; G2,G4}; |- (G2[^]Hb) [-->] M2|]\n           ==> {p1,r2,r4,p6} ((Pm)||(Qn;(p2,G2);Pn)||(Qp)||(Pr)) {q1,q2,p4,q6; Ha,M2,G4,Hf}\" and\nParallelSeq23c: \"[| {p1,p2} (Pm||Pn) {q1,q2; Ha,Hb}; {r2,r6} (Qn||Qr) {p2,p6; G2,G6}; |- (G2[^]Hb) [-->] M2|]\n           ==> {p1,r2,r6} ((Pm)||(Qn;(p2,G2);Pn)||(Qr)) {q1,q2,p6; Ha,M2,G6}\"\n\naxiomatization where\nParallelSeq6b: \"[| {p1,p2,p3,p4,p5,p6} (Pm||Pn||Po||Pp||Pq||Pr) {q1,q2,q3,q4,q5,q6; Ha,Hb,Hc,Hd,He,Hf}; {q1,q2}Qn||Rn{r1,r2; Ga,Gb}; |- Ha[^]Ga [-->]Ma; |- Hb[^]Gb [-->]Mb|]\n           ==>  {p1,p2,p3,p4,p5,p6} ((Pm;(q1,Ha);Qn)||(Pn;(q2,Hb);Rn)||Po||Pp||Pq||Pr) {r1,r2,q3,q4,q5,q6; Ma,Mb,Hc,Hd,He,Hf}\"\naxiomatization where\nConsequenceP5 : \"[| {pa,pb,pc,pd,pe} P {qa,qb,qc,qd,qe; Ha,Hb,Hc,Hd,He}; \n                   |- (p1 [-->] pa) [&] (p2 [-->] pb) [&] (p3 [-->] pc) [&] (p4 [-->] pd) [&] (p5 [-->] pe);\n                   |- (qa [-->] q1) [&] (qb [-->] q2) [&] (qc [-->] q3) [&] (qd [-->] q4) [&] (qe [-->] q5);\n                   |- (Ha [-->] H1) [&] (Hb [-->] H2) [&] (Hc [-->] H3) [&] \n                      (Hd [-->] H4) [&] (He [-->] H5) |]\n            ==> {p1,p2,p3,p4,p5} P {q1,q2,q3,q4,q5; H1,H2,H3,H4,H5}\"\naxiomatization where\nRepetition5 : \"[| {p1,p2,p3,p4,p5} (((Pm||Pn)||Po)||Pp)||Pq {q1,q2,q3,q4,q5; H1,H2,H3,H4,H5};\n                  |- H1 [^] H1 [-->] H1; |- H2 [^] H2 [-->] H2; |- H3 [^] H3 [-->] H3;\n                  |- H4 [^] H4 [-->] H4; |- H5 [^] H5 [-->] H5|]\n           ==> {p1,p2,p3,p4,p5} (((Pm*||Pn*)||Po*)||Pp*)||Pq* {q1,q2,q3,q4,q5; H1,H2,H3,H4,H5}\"\naxiomatization where\nParallel113: \"[| {p1,p2,p3} ((Pm||Pn)||Po) {q,q2,q3; H,H2,H3};\n                  {q} Q {qx; Hx}; |- (H[^]Hx) [-->] Hy|]\n           ==> {p1,p2,p3} (((Pm;(q,H);Q)||Pn)||Po) {qx,q2,q3; Hy,H2,H3}\"\naxiomatization where\nParallel115: \"[| {p1,p2,p3,p4,p5} (((Pm||Pn)||Po)||Pp)||Pq {q,q2,q3,q4,q5; H,H2,H3,H4,H5};\n                  {q} Q {qx; Hx}; |- (H[^]Hx) [-->] Hy|]\n           ==> {p1,p2,p3,p4,p5} ((((Pm;(q,H);Q)||Pn)||Po)||Pp)||Pq {qx,q2,q3,q4,q5; Hy,H2,H3,H4,H5}\"\naxiomatization where\nParallel13: \"[| {p1,p2,p3} (Pm||Pn)||Po {q1,q2,q3; H1,H2,H3};\n                  {q3} Q {qx; Hx}; |- (H3[^]Hx) [-->] Hy|]\n           ==> {p1,p2,p3} (Pm||Pn)||(Po;(q3,H3);Q) {q1,q2,qx; H1,H2,Hy}\"\naxiomatization where\nParallel14: \"[| {p1,p2,p3,p4} ((Pm||Pn)||Po)||Pp {q1,q2,q3,q4; H1,H2,H3,H4};\n                  {q4} Q {qx; Hx}; |- (H4[^]Hx) [-->] Hy|]\n           ==> {p1,p2,p3,p4} ((Pm||Pn)||Po)||(Pp;(q4,H4);Q) {q1,q2,q3,qx; H1,H2,H3,Hy}\"\naxiomatization where\nParallel15: \"[| {p1,p2,p3,p4,p5} (((Pm||Pn)||Po)||Pp)||Pq {q1,q2,q3,q4,q5; H1,H2,H3,H4,H5};\n                  {q5} Q {qx; Hx}; |- (H5[^]Hx) [-->] Hy|]\n           ==> {p1,p2,p3,p4,p5} (((Pm||Pn)||Po)||Pp)||(Pq;(q5,H5);Q) {q1,q2,q3,q4,qx; H1,H2,H3,H4,Hy}\"\naxiomatization where\nCommunication3 : \"[| ~inPairForm ([(x, e)], qy);\n                    {p1,p2,p3} (Pm||Pn)||Po {q1,q2,q3; H1,H2,H3};\n                    |- (q1 [-->] qx) [&] (q3 [-->] (substF ([(x, e)]) (qy)));\n                    |- ((H1 [^] (high (q1))) [-->] Hx) [&] ((H3 [^] (high (q3))) [-->] Hy);\n                    |- ((((H1 [^] (high (q1))) [&] H3) [|]((H3 [^] (high (q3))) [&] H1)) [-->] H);\n                    |- Hx [&] H [-->] Ha;\n                    |- Hy [&] H [-->] Hb\n                  |]\n               ==>  {p1,p2,p3} ((Pm;(q1, H1);ch!!e)||Pn)||(Po;(q3, H3);ch??x) \n                    {qx,q2,qy; Ha,H2,Hb}\"\naxiomatization where\nCommunication4 : \"[| ~inPairForm ([(x, e)], qy);\n                    {p1,p2,p3,p4} ((Pm||Pn)||Po)||Pp {q1,q2,q3,q4; H1,H2,H3,H4};\n                    |- (q1 [-->] qx) [&] (q4 [-->] (substF ([(x, e)]) (qy)));\n                    |- ((H1 [^] (high (q1))) [-->] Hx) [&] ((H4 [^] (high (q4))) [-->] Hy);\n                    |- ((((H1 [^] (high (q1))) [&] H4) [|]((H4 [^] (high (q4))) [&] H1)) [-->] H);\n                    |- Hx [&] H [-->] Ha;\n                    |- Hy [&] H [-->] Hb\n                  |]\n               ==>  {p1,p2,p3,p4} (((Pm;(q1, H1);ch!!e)||Pn)||Po)||(Pp;(q4, H4);ch??x) \n                    {qx,q2,q3,qy; Ha,H2,H3,Hb}\"\naxiomatization where\nCommunication5 : \"[| ~inPairForm ([(x, e)], qy);\n                    {p1,p2,p3,p4,p5} (((Pm||Pn)||Po)||Pp)||Pq {q1,q2,q3,q4,q5; H1,H2,H3,H4,H5};\n                    |- (q1 [-->] qx) [&] (q5 [-->] (substF ([(x, e)]) (qy)));\n                    |- ((H1 [^] (high (q1))) [-->] Hx) [&] ((H5 [^] (high (q5))) [-->] Hy);\n                    |- ((((H1 [^] (high (q1))) [&] H5) [|]((H5 [^] (high (q5))) [&] H1)) [-->] H);\n                    |- Hx [&] H [-->] Ha;\n                    |- Hy [&] H [-->] Hb\n                  |]\n               ==>  {p1,p2,p3,p4,p5} ((((Pm;(q1, H1);ch!!e)||Pn)||Po)||Pp)||(Pq;(q5, H5);ch??x) \n                    {qx,q2,q3,q4,qy; Ha,H2,H3,H4,Hb}\"\n\n(*important derived rules*)\nlemma structSkipEL : \"{px, py} (Skip;(px,l[=](Real 0));P)||Q {qx, qy; Hx, Hy}\n           ==> {px, py} P||Q{qx, qy; Hx, Hy}\"\napply (cut_tac px=px and py=py and P=P and Q=Q and qx=qx and qy=qy and Hx=Hx and Hy=Hy in structSkipL,auto)\ndone\n\nlemma structSkipIL : \"{px, py} P||Q{qx, qy; Hx, Hy}\n           ==> {px, py} (Skip;(px,l[=](Real 0));P)||Q {qx, qy; Hx, Hy}\"\napply (cut_tac px=px and py=py and P=P and Q=Q and qx=qx and qy=qy and Hx=Hx and Hy=Hy in structSkipL,auto)\ndone\n\nlemma structSkipER : \"{px, py} (P;(qx,Hx);Skip)||Q {qx, qy; Hx, Hy}\n           ==> {px, py} P||Q{qx, qy; Hx, Hy}\"\napply (cut_tac px=px and py=py and P=P and Q=Q and qx=qx and qy=qy and Hx=Hx and Hy=Hy in structSkipR,auto)\ndone\n\nlemma structSkipIR : \"{px, py} P||Q{qx, qy; Hx, Hy}\n           ==> {px, py} (P;(qx,Hx);Skip)||Q {qx, qy; Hx, Hy}\"\napply (cut_tac px=px and py=py and P=P and Q=Q and qx=qx and qy=qy and Hx=Hx and Hy=Hy in structSkipR,auto)\ndone\n\nlemma RepetitionT1 : \"{px, py} (Px || Py) {qx, qy; Hx, Hy}\n           ==>  {px, py} (Px**1 || Py) {qx, qy; Hx, Hy}\"\napply (rule structSkipER)\napply (rule RepetitionT1a)\napply (rule structSkipIR,auto)\ndone\n\nlemma RepetitionTn : \"[| {px, py} (((Px**m);(qx,H);Px) || Py) {qx, qy; Hx, Hy};\n                 |- Hx [^] Hx [-->] Hx;\n                 |- H [-->] Hx|]\n           ==>  {px, py} (Px**(m+1) || Py) {qx, qy; Hx, Hy}\"\napply (rule structSkipER)\napply (cut_tac H=\"H\" in RepetitionTna,auto)\napply (rule structL)\napply (rule structSkipIR,auto)\ndone\n\nlemma Parallel4: \"[| {py} Py {qy; Hy[&](l[=](Real 0))};\n               {qx, qy} (Qx || Qy) {rx, ry; Mx, My};\n               |- (Hy[&](l[=](Real 0))) [-->] HR;\n               |- ((Hy[&](l[=](Real 0))) [^] My) [-->] Gy\n            |]\n           ==> {qx, py} (Qx) || (Py;(qy,HR);Qy) {rx, ry; Mx, Gy}\"\napply (rule structSkipEL)\napply (cut_tac m=0 and Hx=\"l [=] Real 0\" in Parallel3,auto)\napply (rule Parallel2,auto)\napply (rule Skip)\n(*1*)\napply (rule impR)\napply (rule conjR)\napply (rule basic)+\napply (rule impR)\napply (rule conjL)\napply (rule basic)\napply (rule impR)\napply (rule LC1)\napply (rule LL3a)\napply (rule basic)\ndone\n\nlemma Parallel1a: \"[| {px, py} (Px || Py) {qx, qy; Hx, Hy}; {qy} Qy {ry; Gy}; |- Hy [^] Gy [-->] G |]\n           ==>  {px, py} ((Px) || (Py; (qy, Hy); Qy)) {qx, ry; Hx, G}\"\napply (rule structSkipER)\napply (subgoal_tac \"{px, py}(Px;(qx, Hx);Skip)||(Py;(qy, Hy);Qy){qx,ry; (Hx [^] l [=] Real 0), Hy [^] Gy}\")\napply (cut_tac px=px and py=py and qx=qx and qy=ry and Hx=\"Hx [^] l [=] Real 0\" and Hy=\"Hy [^] Gy\" in ConsequenceP,auto)\napply (rule conjR)\napply (rule impR)\napply (rule basic)\napply (rule conjR)\napply (rule impR)\napply (rule basic)\napply (rule conjR)\napply (rule impR)\napply (rule basic)\napply (rule conjR)\napply (rule impR)\napply (rule basic)\napply (rule conjR)\napply (rule impR)\napply (rule LL4)\napply (rule basic)\napply assumption\n(*start*)\napply (cut_tac px=px and py=py and Px=Px and qx=qx and Hx=\"Hx\" and Qx=Skip and Py=Py and qy=qy and Hy=Hy and Qy=Qy and rx=qx and ry=ry and Gx=\"(l [=] Real 0)\" and Gy=Gy in Parallel1,auto)\napply (rule Skip)\napply (rule impR)\napply (rule basic)\ndone\n\nlemma CommunicationI1b : \"[| ~inPairForm ([(x, e)], ry);\n                    |- Hy [-->] H;\n                    |- rg [-->] H[^]WTrue;\n                    {py} ( Py) {qy; Hy}; \n                    |- Init [&] pre [<->] qx;\n                    |- pre [&] Init [&] b [-->] FF;\n                    |- (pre [&] close(FF) [&] close(b)) [-->] rx;\n                    |- (qy [&] pre [&] close(FF) [&] close(b) [-->] (substF ([(x, e)]) (ry)));\n                    |- ((((l [=] Real 0) [|] (high (close(FF) [&] pre [&] close(b)))) [&] H) [-->] Gx);\n                    |- Hy [-->] Gy;\n                    |- Hy [-->] Hym;\n                    contain(P,(ch !! e))\n                 |]\n              ==>   {qx, py} (((<FF && b> :rg) [[> P) || (Py; (qy, Hym); ch ?? x))\n                    {rx, ry; Gx, Gy}\"\napply (rule structSkipEL)\napply (cut_tac Hx=\"l [=] Real 0\" and Init=Init in CommunicationI1,auto)\napply (rule Parallel2,auto)\napply (rule Skip)\napply (rule impR)\napply (rule basic)\napply (cut_tac P=\"((l [=] Real 0 [|] high (close(FF) [&] pre [&] close(b))) [&] H) [-->] Gx\" in cut,auto)\napply (rule thinR,auto)\napply (rule impR)\napply (rule LL3a)\napply (rule impL)\napply (rule basic)+\napply (rule impR)\napply (rule basic)\ndone\n\nlemma structSkipELR : \"{px, py} Q||(Skip;(py,l[=](Real 0));P) {qx, qy; Hx, Hy}\n           ==> {px, py} Q||P{qx, qy; Hx, Hy}\"\napply (rule Structure)\napply (rule structSkipEL)\napply (rule Structure)\napply assumption\ndone\n\nlemma CommunicationI1a : \"[| ~inPairForm ([(x, e)], ry);\n                       |- Init [&] pre [<->] px;\n                       |- pre [&] Init [&] b [-->] FF;\n                       |- (pre [&] close(FF) [&] close(b)) [-->] rx;\n                       (*|- px [-->] rx;*)\n                       |- py [&] pre [&] close(FF) [&] close(b) [-->] (substF ([(x, e)]) (ry));\n                       |- (l[=]Real 0) [-->] Gx;\n                       |- (l[=]Real 0) [-->] Gy;\n                       contain(Px,(ch !! e))|]\n              ==>   {px, py} (((<FF && b> :rg) [[> Px) || (ch ?? x)) {rx, ry; Gx, Gy}\"\napply (rule structSkipEL)\napply (rule structSkipELR)\napply (cut_tac H=\"l [=] Real 0\" and Hx=\"l [=] Real 0\" in CommunicationI1,auto)\napply (rule impR)\napply (rule basic)\napply (rule impR)\napply (rule RL3a)\napply (simp add: True_def)\napply (rule impR)\napply (rule basic)\napply (rule Parallel2)\napply (rule Skip)\napply (rule impR)\napply (rule basic)\napply (rule Skip)\napply (rule impR)\napply (rule basic)\napply (rule impR)\napply (rule LL3a)\napply (rule conjL)\napply (rule thinL)\napply (cut_tac P=\"l [=] Real 0 [-->] Gx\" in cut,auto)\napply (rule thinL)\napply (rule thinR,auto)\napply (rule impL)\napply (rule basic)+\napply (rule impR)\napply (rule basic)\napply (rule impR)\napply (rule basic)\ndone\n\nlemma CommunicationI2a : \"[| ~inPairForm ([(x, e)], ry);\n                       |- Init [&] pre [<->] px;\n                       |- pre [&] Init [&] b [-->] FF;\n                       |- py [&] pre [&] close(FF) [&] close(b) [-->] (substF ([(x, e)]) (rx));\n                       |- py [-->] ry;\n                       |- (l[=]Real 0) [-->] Gx;\n                       |- (l[=]Real 0) [-->] Gy;\n                       contain(Px,(ch ?? x))|]\n              ==>   {px, py} (( (<FF && b> :rg) [[> Px) || (ch !! e)) {rx, ry; Gx, Gy}\"\napply (rule structSkipEL)\napply (rule structSkipELR)\napply (cut_tac H=\"l [=] Real 0\" and Hx=\"l [=] Real 0\" in CommunicationI2,auto)\napply (rule impR)\napply (rule basic)\napply (rule impR)\napply (rule RL3a)\napply (simp add: True_def)\napply (rule impR)\napply (rule basic)\napply (rule Parallel2)\napply (rule Skip)\napply (rule impR)\napply (rule basic)\napply (rule Skip)\napply (rule impR)\napply (rule basic)\napply (rule impR)\napply (rule LL3a)\napply (rule conjL)\napply (rule thinL)\napply (cut_tac P=\"l [=] Real 0 [-->] Gx\" in cut,auto)\napply (rule thinL)\napply (rule thinR,auto)\napply (rule impL)\napply (rule basic)+\napply (rule impR)\napply (rule basic)\napply (rule impR)\napply (rule basic)\ndone\n\nend\n", "meta": {"author": "bzhan", "repo": "mars", "sha": "d10e489a8ddf128a4cbac13291efdece458d732d", "save_path": "github-repos/isabelle/bzhan-mars", "path": "github-repos/isabelle/bzhan-mars/mars-d10e489a8ddf128a4cbac13291efdece458d732d/HHLProver/HHL1.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5428632683808532, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.2650711198663969}}
{"text": "(*\n * Copyright 2014, General Dynamics C4 Systems\n *\n * SPDX-License-Identifier: GPL-2.0-only\n *)\n\n(* Title:   Confinement_S\n * Description: confinement proof of the security model\n *)\n\ntheory Confine_S\nimports System_S\nbegin\n\n(* These translate Create into all_rights *)\ndefinition\n  extra_rights :: \"cap \\<Rightarrow> cap\" where\n  \"extra_rights c \\<equiv>\n  if (Create \\<in> rights c)\n  then c\\<lparr>rights := all_rights\\<rparr>\n  else c\"\n\n\nlemma extra_rights_idem [simp]:\n  \"(extra_rights (extra_rights c)) = (extra_rights c)\"\n  apply (clarsimp simp add: extra_rights_def)\n  done\n\nlemma extra_rights_image_idem [simp]:\n  \"(extra_rights ` (extra_rights ` S)) = (extra_rights ` S)\"\n  by (rule set_eqI) (simp add: image_iff)\n\nlemma extra_rights_empty_rights_ident [simp]:\n   \"extra_rights \\<lparr> target = e, rights = {} \\<rparr> = \\<lparr> target = e, rights = {} \\<rparr>\"\n  by (simp add: extra_rights_def)\n\nlemma entity_extra_rights [simp]:\n  \"target (extra_rights c) = target c\"\n  by (simp add: extra_rights_def)\n\nlemma rights_extra_rights:\n  \"rights (extra_rights c) =\n   (if Create \\<in> (rights c)\n    then all_rights\n    else rights c)\"\n  by (simp add: extra_rights_def)\n\n(* The following two definitions both translate Create into all_rights *)\n\n(* A cap is in a set, or a cap with more access is. *)\ndefinition\n  cap_in_caps :: \"cap \\<Rightarrow> cap set \\<Rightarrow> bool\" (infix \"\\<in>cap\" 50) where\n  \"c \\<in>cap C \\<equiv> \\<exists>c' \\<in> C. target c = target c' \\<and> rights (extra_rights c) \\<subseteq> rights (extra_rights c')\"\n\nabbreviation not_cap_in_caps where\n  \"not_cap_in_caps x A \\<equiv> ~ (x \\<in>cap A)\" \\<comment> \\<open>non-membership\\<close>\n\nnotation (input) cap_in_caps (infix \":cap\" 50)\nnotation (latex output)  cap_in_caps (infix \"\\<in>\\<^sub>c\\<^sub>a\\<^sub>p\" 50)\n\nnotation\n  not_cap_in_caps  (\"(\\<notin>cap)\") and\n  not_cap_in_caps  (\"(_/ \\<notin>cap _)\" [51, 51] 50)\n\nnotation (latex output)\n  not_cap_in_caps  (\"(\\<notin>\\<^sub>c\\<^sub>a\\<^sub>p)\") and\n  not_cap_in_caps  (infix \"\\<notin>\\<^sub>c\\<^sub>a\\<^sub>p\" 50)\n\n(* A set of caps \"caps\" have less (or equal) access to an entity as \"cap\" does. *)\ndefinition\n  caps_dominated_by :: \"cap set \\<Rightarrow> cap \\<Rightarrow> bool\" (infix \"\\<le>cap\" 50) where\n  \"caps \\<le>cap cap \\<equiv> \\<forall>cap' \\<in> caps. target cap' = target cap \\<longrightarrow> rights (extra_rights cap') \\<subseteq> rights (extra_rights cap)\"\n\nnotation (input) caps_dominated_by (infix \"<=cap\" 50)\nnotation (latex output) caps_dominated_by (infix \"\\<unlhd>\\<^sub>c\\<^sub>a\\<^sub>p\" 50)\n\ndefinition\n  shares_caps :: \"state \\<Rightarrow> entity_id \\<Rightarrow> entity_id \\<Rightarrow> bool\" where\n  \"shares_caps s e\\<^sub>x e\\<^sub>y \\<equiv> \\<exists>e\\<^sub>i . (e\\<^sub>x, e\\<^sub>i) \\<in> store_connected s \\<and> (e\\<^sub>y, e\\<^sub>i) \\<in> store_connected s\"\n\ndefinition\n  leak :: \"state \\<Rightarrow> entity_id \\<Rightarrow> entity_id \\<Rightarrow> bool\" (\"_ \\<turnstile> _ \\<rightarrow> _\") where\n  \"leak s e\\<^sub>x e\\<^sub>y \\<equiv> take_cap e\\<^sub>x \\<in>cap caps_of s e\\<^sub>y \\<or> grant_cap e\\<^sub>y \\<in>cap caps_of s e\\<^sub>x \\<or> shares_caps s e\\<^sub>x e\\<^sub>y\"\n\n\ndefinition\n  directly_tgs_connected :: \"state \\<Rightarrow> (entity_id \\<times> entity_id) set\" where\n  \"directly_tgs_connected s \\<equiv> {(e\\<^sub>x, e\\<^sub>y). leak s e\\<^sub>x e\\<^sub>y \\<or> leak s e\\<^sub>y e\\<^sub>x}\"\n\nlemma directly_tgs_connected_def2:\n  \"(e\\<^sub>x, e\\<^sub>y) \\<in> directly_tgs_connected s = (leak s e\\<^sub>x e\\<^sub>y \\<or> leak s e\\<^sub>y e\\<^sub>x)\"\n  by (simp add: directly_tgs_connected_def)\n\nabbreviation\n  in_directly_tgs_connected :: \"state \\<Rightarrow> entity_id \\<Rightarrow> entity_id \\<Rightarrow> bool\" (\"_ \\<turnstile> _ \\<leftrightarrow> _\" [60,0,60] 61)\nwhere\n  \"s \\<turnstile> x \\<leftrightarrow> y \\<equiv> (x,y) \\<in> directly_tgs_connected s\"\n\ndefinition\n  tgs_connected :: \"state \\<Rightarrow> (entity_id \\<times> entity_id) set\" where\n  \"tgs_connected s \\<equiv> (directly_tgs_connected s)\\<^sup>*\"\n\nabbreviation\n  in_tgs_connected :: \"state \\<Rightarrow> entity_id \\<Rightarrow> entity_id \\<Rightarrow> bool\" (\"_ \\<turnstile> _ \\<leftrightarrow>* _\" [60,0,60] 61)\nwhere\n  \"s \\<turnstile> x \\<leftrightarrow>* y == (x,y) \\<in> tgs_connected s\"\n\nnotation (latex output)\n  in_tgs_connected (\"_ \\<turnstile> _ \\<leftrightarrow>\\<^sup>* _\" [60,0,60] 61)\n\ntranslations\n  \"\\<not> (s \\<turnstile> x \\<leftrightarrow> y)\" <= \"(x,y) \\<notin> CONST directly_tgs_connected s\"\n  \"\\<not> (s \\<turnstile> x \\<leftrightarrow>* y)\" <= \"(x,y) \\<notin> CONST tgs_connected s\"\n\nlemma shares_caps_sym [simp]:\n \"shares_caps s y x = shares_caps s x y\"\n  by (auto simp: shares_caps_def)\n\nlemma directly_tgs_connected_def4:\n  \"s \\<turnstile> e\\<^sub>x \\<leftrightarrow> e\\<^sub>y = (take_cap e\\<^sub>x \\<in>cap caps_of s e\\<^sub>y \\<or> take_cap e\\<^sub>y \\<in>cap caps_of s e\\<^sub>x \\<or>\n                  grant_cap e\\<^sub>y \\<in>cap caps_of s e\\<^sub>x \\<or> grant_cap e\\<^sub>x \\<in>cap caps_of s e\\<^sub>y \\<or>\n                  shares_caps s e\\<^sub>x e\\<^sub>y)\"\n  by (auto simp: directly_tgs_connected_def leak_def)\n\n(* Note: e\\<^sub>0 is unused. *)\ndefinition\n  generalOperation ::\n  \"entity_id \\<Rightarrow> entity_id \\<Rightarrow> cap \\<Rightarrow> right set \\<Rightarrow> modify_state\" where\n  \"generalOperation e\\<^sub>0 e\\<^sub>1 c r s \\<equiv>\n  s (e\\<^sub>1 \\<mapsto> Entity ( insert (diminish r (extra_rights c)) (direct_caps_of s e\\<^sub>1) ))\"\n\nlemma is_entity_general [simp]:\n  \"is_entity s e\\<^sub>1 \\<Longrightarrow> is_entity (generalOperation e\\<^sub>0 e\\<^sub>1 c r s) e' = is_entity s e'\"\n  by (simp add: is_entity_def generalOperation_def)\n\ndefinition\n  make_entity :: \"entity_id \\<Rightarrow> modify_state\" where\n  \"make_entity n s \\<equiv>\n  s (n \\<mapsto> null_entity)\"\n\nlemma direct_caps_of_store_connected_eq:\n  \"\\<forall> e. direct_caps_of s e = direct_caps_of s' e\n  \\<Longrightarrow> store_connected s = store_connected s'\"\n  by (simp add: store_connected_def store_connected_direct_def\n                direct_caps_of_def)\n\nlemma direct_caps_of_caps_of_eq:\n  \"\\<forall> e. direct_caps_of s e = direct_caps_of s' e \\<Longrightarrow> caps_of s e = caps_of s' e\"\n  by (simp add: caps_of_def store_connected_def store_connected_direct_def\n                direct_caps_of_def)\n\nlemma direct_caps_of_caps_of_eq2:\n  \"\\<lbrakk>\\<forall> e. direct_caps_of s e = direct_caps_of s' e; c \\<in>cap caps_of s e\\<rbrakk> \\<Longrightarrow> c \\<in>cap caps_of s' e\"\n  apply (drule direct_caps_of_caps_of_eq)\n  apply (simp add: cap_in_caps_def)\n  by auto\n\nlemma direct_caps_of_directly_tgs_connected_eq:\n  \"\\<forall> e. direct_caps_of s e = direct_caps_of s' e \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow> y = s' \\<turnstile> x \\<leftrightarrow> y\"\n  apply (simp add: directly_tgs_connected_def4 shares_caps_def)\n  apply rule\n   apply (erule disjE, drule (1) direct_caps_of_caps_of_eq2, clarsimp)+\n   apply (drule direct_caps_of_store_connected_eq, clarsimp)\n  apply (erule disjE, drule direct_caps_of_caps_of_eq2 [rotated, where s=s' and s'=s], simp+)+\n  apply (drule direct_caps_of_store_connected_eq, simp)\n  done\n\nlemma direct_caps_of_make_entity:\n  \"\\<not> is_entity s n \\<Longrightarrow> direct_caps_of (make_entity n s) e = direct_caps_of s e\"\n  by (simp add: direct_caps_of_def make_entity_def is_entity_def\n                null_entity_def)\n\nlemma caps_of_make_entity:\n  \"\\<not> is_entity s n \\<Longrightarrow> caps_of (make_entity n s) e = caps_of s e\"\n  apply (rule direct_caps_of_caps_of_eq)\n  apply clarsimp\n  apply (erule direct_caps_of_make_entity)\n  done\n\nlemma caps_of_make_entity2:\n  \"\\<lbrakk>\\<not> is_entity s n; c \\<in> caps_of (make_entity n s) e\\<rbrakk> \\<Longrightarrow> c \\<in> caps_of s e\"\n  apply (drule caps_of_make_entity)\n  apply fastforce\n  done\n\nlemma directly_tgs_connected_make_entity:\n \"\\<not> is_entity s n \\<Longrightarrow> make_entity n s \\<turnstile> x \\<leftrightarrow> y = s \\<turnstile> x \\<leftrightarrow> y\"\n  apply (rule direct_caps_of_directly_tgs_connected_eq)\n  apply clarsimp\n  apply (drule (1) direct_caps_of_make_entity)\n  done\n\nlemma directly_tgs_connected_make_entity2:\n \"\\<lbrakk>\\<not> is_entity s n; make_entity n s \\<turnstile> x \\<leftrightarrow> y\\<rbrakk> \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow> y\"\n  apply (drule directly_tgs_connected_make_entity)\n  apply fastforce\n  done\n\nlemma diminish_extra_rights [simp]:\n  \"diminish (rights c) (extra_rights c) = c\"\n  by (simp add: diminish_def all_rights_def rights_extra_rights)\n\nlemma diminish_extra_rights2 [simp]:\n  \"diminish (r \\<inter> rights c) (extra_rights c) = diminish r c\"\n  apply (simp add: diminish_def extra_rights_def all_rights_def)\n  apply (simp add: Int_commute)\n  apply (subgoal_tac \"rights c \\<inter> (r \\<inter> rights c) = r \\<inter> rights c\")\n   apply simp\n  apply fastforce\n  done\n\nlemma create_general_helper:\n  \"Create \\<in> rights c\\<^sub>2 \\<Longrightarrow>\n   \\<lparr>target = target c\\<^sub>2, rights = UNIV\\<rparr> = c\\<^sub>2\\<lparr>rights := UNIV\\<rparr>\"\n  by auto\n\nlemma extra_rights_full_cap [simp]:\n  \"extra_rights (full_cap e) = full_cap e\"\n  by (simp add: extra_rights_def)\n\nlemma create_general_alt:\n  \"createOperation e c\\<^sub>1 c\\<^sub>2 s =\n   make_entity (target c\\<^sub>2)\n               (generalOperation  e (target c\\<^sub>1) (full_cap (target c\\<^sub>2)) (all_rights) s)\"\n  by (simp add: createOperation_def generalOperation_def make_entity_def)\n\nlemma create_general:\n  \"Create \\<in> rights c\\<^sub>2 \\<Longrightarrow> createOperation e c\\<^sub>1 c\\<^sub>2 s =\n   make_entity (target c\\<^sub>2)\n               (generalOperation  e (target c\\<^sub>1) c\\<^sub>2 (all_rights) s)\"\n  by (simp add: createOperation_def generalOperation_def make_entity_def\n                full_cap_def all_rights_def diminish_def\n                extra_rights_def create_general_helper null_entity_def)\n\nlemma take_general:\n  \"takeOperation e c\\<^sub>1 c\\<^sub>2 r s =\n   generalOperation (target c\\<^sub>1) e c\\<^sub>2 (r \\<inter> rights c\\<^sub>2) s\"\n  by (simp add: takeOperation_def generalOperation_def)\n\nlemma grant_general:\n  \"grantOperation e c\\<^sub>1 c\\<^sub>2 r s =\n   generalOperation e (target c\\<^sub>1) c\\<^sub>2 (r \\<inter> rights c\\<^sub>2) s\"\n  by (simp add: grantOperation_def generalOperation_def)\n\nlemma copy_general:\n  \"copyOperation e c\\<^sub>1 c\\<^sub>2 r s =\n   generalOperation e (target c\\<^sub>1) c\\<^sub>2 (r \\<inter> rights c\\<^sub>2) s\"\n  by (simp add: copyOperation_def generalOperation_def)\n\n(* Lemmas on the directly_tgs_connected predicate *)\nlemma directly_tgs_connected_comm:\n  \"s \\<turnstile> x \\<leftrightarrow> y \\<Longrightarrow> s \\<turnstile> y \\<leftrightarrow> x\"\n  by(auto simp: directly_tgs_connected_def)\n\nlemma tgs_connected_refl [simp]:\n  \"s \\<turnstile> x \\<leftrightarrow>* x\"\n  by (metis tgs_connected_def rtrancl.rtrancl_refl)\n\nlemma tgs_connected_comm:\n  \"s \\<turnstile> x \\<leftrightarrow>* y \\<Longrightarrow> s \\<turnstile> y \\<leftrightarrow>* x\"\n  apply(simp add: tgs_connected_def)\n  apply(erule rtrancl_induct, simp)\n  apply(case_tac \"s \\<turnstile> z \\<leftrightarrow> y\")\n   apply(simp add: directly_tgs_connected_comm)\n  apply(simp add: directly_tgs_connected_comm)\n  done\n\nlemma tgs_connected_comm_eq:\n  \"s \\<turnstile> x \\<leftrightarrow>* y = s \\<turnstile> y \\<leftrightarrow>* x\"\n  by (metis tgs_connected_comm)\n\nlemmas tgs_connected_trans =\n       rtrancl_trans [where r=\"directly_tgs_connected s\"  for s, simplified tgs_connected_def[symmetric]]\n\nlemmas directly_tgs_connected_rtrancl_into_rtrancl =\n       rtrancl_into_rtrancl [where r=\"directly_tgs_connected s\" for s, simplified tgs_connected_def[symmetric]]\n\nlemma take_caps_directly_tgs_connected:\n  \"\\<lbrakk>c \\<in> caps_of s e; Take \\<in> rights c\\<rbrakk> \\<Longrightarrow> s \\<turnstile> e \\<leftrightarrow> target c\"\n  by (auto simp: directly_tgs_connected_def leak_def take_cap_def cap_in_caps_def extra_rights_def all_rights_def)\n\nlemma grant_caps_directly_tgs_connected:\n  \"\\<lbrakk>c \\<in> caps_of s e; Grant \\<in> rights c\\<rbrakk> \\<Longrightarrow> s \\<turnstile> e \\<leftrightarrow> target c\"\n  by (auto simp: directly_tgs_connected_def leak_def grant_cap_def cap_in_caps_def extra_rights_def all_rights_def)\n\nlemma create_caps_directly_tgs_connected:\n  \"\\<lbrakk>c \\<in> caps_of s e; Create \\<in> rights c\\<rbrakk> \\<Longrightarrow> s \\<turnstile> e \\<leftrightarrow> target c\"\n  by (auto simp: directly_tgs_connected_def leak_def cap_in_caps_def rights_extra_rights all_rights_def)\n\nlemma store_connected_directly_tgs_connected:\n  \"(x, y) \\<in> store_connected s \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow> y\"\n  by (auto simp: directly_tgs_connected_def leak_def shares_caps_def store_connected_def)\n\n(* Lemmas on caps *)\n\nlemma cap_in_caps_insert [simp]:\n  \"c \\<in>cap insert c' S = (target c = target c' \\<and>\n  rights (extra_rights c) \\<subseteq> rights (extra_rights c') \\<or> c \\<in>cap S)\"\n  by (simp add: cap_in_caps_def)\n\nlemma cap_in_caps_singleton [simp]:\n  \"c \\<in>cap {c'} = (target c = target c' \\<and> rights (extra_rights c) \\<subseteq> rights (extra_rights c'))\"\n  by (simp add: cap_in_caps_def)\n\nlemma not_in [simp]:\n  \"{} \\<le>cap c\"\n  by(simp add: caps_dominated_by_def)\n\nlemma extra_rights_diminish:\n  \"x \\<in> rights (extra_rights (diminish r c))\n   \\<Longrightarrow> x \\<in> rights (extra_rights c)\"\n  by (auto simp: rights_extra_rights all_rights_def split:if_split_asm)\n\n(* Lemmas on system operations *)\n\ndefinition\n  in_store_connected :: \"state \\<Rightarrow> entity_id \\<Rightarrow> entity_id \\<Rightarrow> bool\" where\n  \"in_store_connected s x y \\<equiv> (x, y) \\<in> store_connected s\"\n\n(* Lemmas about the general operation *)\n\nlemma direct_caps_of_generalOp:\n  \"direct_caps_of (generalOperation e\\<^sub>0 e\\<^sub>1 c r s) e =\n  (if e = e\\<^sub>1\n   then insert (diminish r (extra_rights c)) (direct_caps_of s (e\\<^sub>1))\n   else direct_caps_of s e)\"\n  by (clarsimp simp: generalOperation_def direct_caps_of_def split:option.splits)\n\nlemma direct_caps_of_generalOp2:\n  \"\\<lbrakk>c' \\<in> direct_caps_of (generalOperation e\\<^sub>0 e\\<^sub>1 c r s) x\\<rbrakk> \\<Longrightarrow>\n   c' \\<in> direct_caps_of s x \\<or> (c' \\<in>cap {c} \\<and> x = e\\<^sub>1)\"\n  apply (clarsimp simp: direct_caps_of_generalOp extra_rights_diminish\n           split:if_split_asm)\n  apply (drule extra_rights_diminish)\n  by simp\n\nlemma store_connected_direct_generalOp:\n  \"\\<lbrakk>(x, y) \\<in> store_connected_direct (generalOperation e\\<^sub>0 e\\<^sub>1 c r s)\\<rbrakk> \\<Longrightarrow>\n   (x, y) \\<in> store_connected_direct s \\<or>\n   (x = e\\<^sub>1 \\<and> y = target c \\<and> Store \\<in> rights (extra_rights c))\"\n  by (auto simp: store_connected_direct_def direct_caps_of_generalOp all_rights_def\n          split: if_split_asm)\n\nlemma store_connected_generalOp:\n  \"\\<lbrakk>(x, y) \\<in> store_connected (generalOperation e\\<^sub>0 e\\<^sub>1 c r s)\\<rbrakk> \\<Longrightarrow>\n   (x, y) \\<in> store_connected s \\<or>\n   ((x, e\\<^sub>1) \\<in> store_connected s \\<and>\n   (e\\<^sub>1, target c) \\<in> store_connected_direct (generalOperation e\\<^sub>0 e\\<^sub>1 c r s) \\<and>\n   (target c, y) \\<in> store_connected s)\"\n  apply (unfold store_connected_def)\n  apply (erule rtrancl_induct)\n   apply clarsimp\n  apply (clarsimp)\n  apply (fold store_connected_def)\n  apply (subgoal_tac \"(y, z) \\<in> store_connected_direct s\")\n   apply (clarsimp simp: store_connected_def)\n   apply (erule disjE)\n    apply fastforce\n   apply clarsimp\n   apply (erule notE)\n   apply fastforce\n  apply (frule store_connected_direct_generalOp)\n  apply (clarsimp simp: store_connected_def)\n  done\n\n\nlemma store_connected_generalOp_not_new:\n  \"\\<lbrakk>(e\\<^sub>1, target c) \\<in> store_connected_direct (generalOperation e\\<^sub>0 e\\<^sub>1 c r s);\n   c \\<in> caps_of s e\\<^sub>0\\<rbrakk> \\<Longrightarrow>\n   (e\\<^sub>1, target c) \\<in> store_connected_direct s \\<or>\n   (e\\<^sub>0, target c) \\<in> store_connected s \\<or>\n   Create \\<in> rights c\"\n  apply (drule store_connected_direct_generalOp)\n  apply (clarsimp simp: rights_extra_rights split:if_split_asm)\n   apply (drule (1) store_caps_store_connected, simp)\n  done\n\nlemma store_connected_generalOp2:\n  \"\\<lbrakk>(x, y) \\<in> store_connected (generalOperation e\\<^sub>0 e\\<^sub>1 c r s);\n   c \\<in> caps_of s e\\<^sub>0; s \\<turnstile> e\\<^sub>0 \\<leftrightarrow> e\\<^sub>1\\<rbrakk> \\<Longrightarrow>\n   s \\<turnstile> x \\<leftrightarrow>* y\"\n  apply (drule store_connected_generalOp)\n  apply (erule disjE)\n   apply (simp add: tgs_connected_def)\n   apply (drule store_connected_directly_tgs_connected, simp)\n  apply clarsimp\n  apply (drule store_connected_directly_tgs_connected [where x=x and y=e\\<^sub>1])\n  apply (drule store_connected_directly_tgs_connected [where x=\"target c\" and y=y])\n  apply (drule (1) store_connected_generalOp_not_new)\n  apply (erule disjE)\n   apply (drule store_connected_direct_in_store_connected)\n   apply (drule store_connected_directly_tgs_connected [where x=e\\<^sub>1 and y=\"target c\"])\n   apply (simp add: tgs_connected_def)\n  apply (drule directly_tgs_connected_comm [where x=\"e\\<^sub>0\" and y=\"e\\<^sub>1\"])\n  apply (erule disjE)\n   apply (drule store_connected_directly_tgs_connected [where x=e\\<^sub>0 and y=\"target c\"])\n   apply (simp add: tgs_connected_def)\n  apply (drule (1) create_caps_directly_tgs_connected)\n  apply (simp add: tgs_connected_def)\n  done\n\nlemma shares_caps_of_generalOp:\n  \"\\<lbrakk>shares_caps (generalOperation e\\<^sub>0 e\\<^sub>1 c r s) x y;\n   c \\<in> caps_of s e\\<^sub>0; s \\<turnstile> e\\<^sub>0 \\<leftrightarrow> e\\<^sub>1\\<rbrakk>\n  \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow>* y\"\n  apply (clarsimp simp: shares_caps_def)\n  apply (frule (2) store_connected_generalOp2 [where x=x])\n  apply (drule (2) store_connected_generalOp2 [where x=y])\n  apply (drule tgs_connected_comm [where x=y])\n  apply (simp add: tgs_connected_def)\n  done\n\nlemma caps_of_generalOp:\n  \"\\<lbrakk>c' \\<in> caps_of (generalOperation e\\<^sub>0 e\\<^sub>1 c r s) x;\n   c \\<in> caps_of s e\\<^sub>0; s \\<turnstile> e\\<^sub>0 \\<leftrightarrow> e\\<^sub>1\\<rbrakk>\n  \\<Longrightarrow> \\<exists>z. (x,z) \\<in> tgs_connected s \\<and> c' \\<in>cap caps_of s z\"\n  apply (simp add: caps_of_def[where e=x])\n  apply clarsimp\n  apply (frule (2) store_connected_generalOp2)\n  apply (drule direct_caps_of_generalOp2)\n  apply (erule disjE)\n   apply (drule direct_cap_in_cap)\n   apply (fastforce simp: cap_in_caps_def)\n  apply (subgoal_tac \"s \\<turnstile> x \\<leftrightarrow>* e\\<^sub>0\")\n   apply (subgoal_tac \"c' \\<in>cap caps_of s e\\<^sub>0\")\n    apply fastforce\n   apply (fastforce simp: cap_in_caps_def)\n  apply clarsimp\n  apply (drule directly_tgs_connected_comm [where x=\"e\\<^sub>0\" and y=\"e\\<^sub>1\"])\n  apply (simp add: tgs_connected_def)\n  done\n\nlemma take_cap_generalOp:\n  \"\\<lbrakk>take_cap y \\<in>cap caps_of (generalOperation e\\<^sub>0 e\\<^sub>1 c r s) x;\n   c \\<in> caps_of s e\\<^sub>0; s \\<turnstile> e\\<^sub>0 \\<leftrightarrow> e\\<^sub>1\\<rbrakk>\n  \\<Longrightarrow> \\<exists>z.  s \\<turnstile> x \\<leftrightarrow>* z \\<and> take_cap y \\<in>cap caps_of s z\"\n  apply (simp add: cap_in_caps_def)\n  apply clarsimp\n  apply (drule (2) caps_of_generalOp)\n  apply (fastforce simp: cap_in_caps_def)\n  done\n\nlemma grant_cap_generalOp:\n  \"\\<lbrakk>grant_cap y \\<in>cap caps_of (generalOperation e\\<^sub>0 e\\<^sub>1 c r s) x;\n   c \\<in> caps_of s e\\<^sub>0; s \\<turnstile> e\\<^sub>0 \\<leftrightarrow> e\\<^sub>1\\<rbrakk>\n  \\<Longrightarrow> \\<exists>z.  s \\<turnstile> x \\<leftrightarrow>* z \\<and> grant_cap y \\<in>cap caps_of s z\"\n  apply (simp add: cap_in_caps_def)\n  apply clarsimp\n  apply (drule (2) caps_of_generalOp)\n  apply (fastforce simp: cap_in_caps_def)\n  done\n\nlemma take_cap_generalOp2:\n  \"\\<lbrakk>take_cap y \\<in>cap caps_of (generalOperation e\\<^sub>0 e\\<^sub>1 c r s) x;\n   c \\<in> caps_of s e\\<^sub>0; s \\<turnstile> e\\<^sub>0 \\<leftrightarrow> e\\<^sub>1\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in> tgs_connected s\"\n  apply (drule (2) take_cap_generalOp)\n  apply clarsimp\n  apply (subgoal_tac \"s \\<turnstile> z \\<leftrightarrow> y\")\n   apply (simp add: tgs_connected_def)\n  apply (simp add: directly_tgs_connected_def leak_def)\n  done\n\nlemma grant_cap_generalOp2:\n  \"\\<lbrakk>grant_cap y \\<in>cap caps_of (generalOperation e\\<^sub>0 e\\<^sub>1 c r s) x;\n   c \\<in> caps_of s e\\<^sub>0; s \\<turnstile> e\\<^sub>0 \\<leftrightarrow> e\\<^sub>1\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in> tgs_connected s\"\n  apply (drule (2) grant_cap_generalOp)\n  apply clarsimp\n  apply (subgoal_tac \"s \\<turnstile> z \\<leftrightarrow> y\")\n   apply (simp add: tgs_connected_def)\n  apply (simp add: directly_tgs_connected_def leak_def)\n  done\n\nlemma generalOp_directly_tgs_connected:\n \"\\<lbrakk>generalOperation e\\<^sub>0 e\\<^sub>1 c r s \\<turnstile> x \\<leftrightarrow> y;\n   c \\<in> caps_of s e\\<^sub>0; s \\<turnstile> e\\<^sub>0 \\<leftrightarrow> e\\<^sub>1\\<rbrakk>\n  \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow>* y\"\n  apply (simp add: directly_tgs_connected_def [where s=\"generalOperation e\\<^sub>0 e\\<^sub>1 c r s\"] leak_def)\n  apply safe\n       apply (rule tgs_connected_comm)\n       apply (drule (3) take_cap_generalOp2)\n      apply (drule (3) grant_cap_generalOp2)\n     apply (erule (2) shares_caps_of_generalOp)\n    apply (drule (3) take_cap_generalOp2)\n   apply (rule tgs_connected_comm)\n   apply (drule (3) grant_cap_generalOp2)\n  apply (erule (2) shares_caps_of_generalOp)\n  done\n\n\n\n(* results from general operation *)\n\nlemma create_legal_directly_tgs_connected:\n  \"legal (SysCreate e c\\<^sub>1 c\\<^sub>2) s \\<Longrightarrow> s  \\<turnstile> target c\\<^sub>1 \\<leftrightarrow> e\"\n  apply clarsimp\n  apply (rule directly_tgs_connected_comm)\n  apply (drule (1) create_caps_directly_tgs_connected)\n  apply (drule (1) store_caps_store_connected)\n  apply (drule (1) store_connected_directly_tgs_connected)\n  done\n\nlemma take_legal_directly_tgs_connected:\n  \"legal (SysTake e c\\<^sub>1 c\\<^sub>2 r) s \\<Longrightarrow> s  \\<turnstile> target c\\<^sub>1 \\<leftrightarrow> e\"\n  apply clarsimp\n  apply (rule directly_tgs_connected_comm)\n  apply (drule (2) take_caps_directly_tgs_connected)\n  done\n\nlemma grant_legal_directly_tgs_connected:\n  \"legal (SysGrant e c\\<^sub>1 c\\<^sub>2 r) s \\<Longrightarrow> s \\<turnstile> e \\<leftrightarrow> target c\\<^sub>1\"\n  apply clarsimp\n  apply (drule (2) grant_caps_directly_tgs_connected)\n  done\n\nlemma copy_legal_directly_tgs_connected:\n  \"legal (SysCopy e c\\<^sub>1 c\\<^sub>2 r) s \\<Longrightarrow> s \\<turnstile> e \\<leftrightarrow> target c\\<^sub>1\"\n  apply clarsimp\n  apply (drule (1) store_caps_store_connected)\n  apply (drule (1) store_connected_directly_tgs_connected)\n  done\n\nlemma caps_of_create:\n  \"\\<lbrakk>c' \\<in> caps_of (createOperation e c\\<^sub>1 c\\<^sub>2 s) x; legal (SysCreate e c\\<^sub>1 c\\<^sub>2) s\\<rbrakk>\n  \\<Longrightarrow> \\<exists>z. (x,z) \\<in> tgs_connected s \\<and> c' \\<in>cap caps_of s z\"\n  apply (frule create_legal_directly_tgs_connected)\n  apply (clarsimp simp: create_general)\n  apply (drule caps_of_make_entity2 [rotated], clarsimp)\n  apply (drule (1) caps_of_generalOp)\n   apply (drule (2) directly_tgs_connected_comm)\n  done\n\nlemma caps_of_take:\n  \"\\<lbrakk>c' \\<in> caps_of (takeOperation e c\\<^sub>1 c\\<^sub>2 r s) x; legal (SysTake e c\\<^sub>1 c\\<^sub>2 r) s\\<rbrakk>\n  \\<Longrightarrow> \\<exists>z. (x,z) \\<in> tgs_connected s \\<and> c' \\<in>cap caps_of s z\"\n  apply (frule take_legal_directly_tgs_connected)\n  apply (clarsimp simp: take_general)\n  apply (drule (2) caps_of_generalOp)\n   apply (drule (1) directly_tgs_connected_comm)\n  done\n\nlemma caps_of_grant:\n  \"\\<lbrakk>c' \\<in> caps_of (grantOperation e c\\<^sub>1 c\\<^sub>2 r s) x; legal (SysGrant e c\\<^sub>1 c\\<^sub>2 r) s\\<rbrakk>\n  \\<Longrightarrow> \\<exists>z. (x,z) \\<in> tgs_connected s \\<and> c' \\<in>cap caps_of s z\"\n  apply (frule grant_legal_directly_tgs_connected)\n  apply (clarsimp simp: grant_general)\n  apply (drule (2) caps_of_generalOp)\n   apply (drule (1) directly_tgs_connected_comm)\n  done\n\nlemma caps_of_copy:\n  \"\\<lbrakk>c' \\<in> caps_of (copyOperation e c\\<^sub>1 c\\<^sub>2 r s) x; legal (SysCopy e c\\<^sub>1 c\\<^sub>2 r) s\\<rbrakk>\n  \\<Longrightarrow> \\<exists>z. (x,z) \\<in> tgs_connected s \\<and> c' \\<in>cap caps_of s z\"\n  apply (frule copy_legal_directly_tgs_connected)\n  apply (clarsimp simp: copy_general)\n  apply (drule (2) caps_of_generalOp)\n   apply (drule (1) directly_tgs_connected_comm)\n  done\n\nlemma create_directly_tgs_connected:\n \"\\<lbrakk>createOperation e c\\<^sub>1 c\\<^sub>2 s \\<turnstile> x \\<leftrightarrow> y; legal (SysCreate e c\\<^sub>1 c\\<^sub>2) s\\<rbrakk>\n  \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow>* y\"\n  apply (frule create_legal_directly_tgs_connected)\n  apply (clarsimp simp: create_general)\n  apply (drule directly_tgs_connected_make_entity2 [rotated], clarsimp)\n  apply (drule (1) generalOp_directly_tgs_connected)\n   apply (drule (2) directly_tgs_connected_comm)\n  done\n\nlemma take_directly_tgs_connected:\n \"\\<lbrakk>takeOperation e c\\<^sub>1 c\\<^sub>2 r s \\<turnstile> x \\<leftrightarrow> y; legal (SysTake e c\\<^sub>1 c\\<^sub>2 r) s\\<rbrakk>\n  \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow>* y\"\n  apply (frule take_legal_directly_tgs_connected)\n  apply (clarsimp simp: take_general)\n  apply (drule (3) generalOp_directly_tgs_connected)\n  done\n\nlemma grant_directly_tgs_connected:\n \"\\<lbrakk>grantOperation e c\\<^sub>1 c\\<^sub>2 r s \\<turnstile> x \\<leftrightarrow> y; legal (SysGrant e c\\<^sub>1 c\\<^sub>2 r) s\\<rbrakk>\n  \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow>* y\"\n  apply (frule grant_legal_directly_tgs_connected)\n  apply (clarsimp simp: grant_general)\n  apply (drule (3) generalOp_directly_tgs_connected)\n  done\n\nlemma copy_directly_tgs_connected:\n \"\\<lbrakk>copyOperation e c\\<^sub>1 c\\<^sub>2 r s \\<turnstile> x \\<leftrightarrow> y; legal (SysCopy e c\\<^sub>1 c\\<^sub>2 r) s\\<rbrakk>\n  \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow>* y\"\n  apply (frule copy_legal_directly_tgs_connected)\n  apply (clarsimp simp: copy_general)\n  apply (drule (3) generalOp_directly_tgs_connected)\n  done\n\n\n\nlemma create_conTrans:\n  \"\\<lbrakk>s' \\<in> step cmd s; (x, y) \\<in> directly_tgs_connected s'; cmd = (SysCreate e c\\<^sub>1 c\\<^sub>2)\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in> tgs_connected s\"\n  apply(clarsimp simp: step_def split: if_split_asm)\n   apply (erule disjE, fastforce simp: tgs_connected_def, clarsimp)\n   apply (drule create_directly_tgs_connected, clarsimp, assumption)\n  apply (simp add: tgs_connected_def)\n  done\n\nlemma take_conTrans:\n  \"\\<lbrakk>s' \\<in> step cmd s; (x, y) \\<in> directly_tgs_connected s'; cmd = (SysTake e c\\<^sub>1 c\\<^sub>2 r)\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in> tgs_connected s\"\n  apply(clarsimp simp: step_def split: if_split_asm)\n   apply (erule disjE, fastforce simp: tgs_connected_def, clarsimp)\n   apply (drule take_directly_tgs_connected, clarsimp, assumption)\n  apply (simp add: tgs_connected_def)\n  done\n\nlemma grant_conTrans:\n  \"\\<lbrakk>s' \\<in> step cmd s; (x, y) \\<in> directly_tgs_connected s'; cmd = (SysGrant e c\\<^sub>1 c\\<^sub>2 r)\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in> tgs_connected s\"\n  apply(clarsimp simp: step_def split: if_split_asm)\n   apply (erule disjE, fastforce simp: tgs_connected_def, clarsimp)\n   apply (drule grant_directly_tgs_connected, clarsimp, assumption)\n  apply (simp add: tgs_connected_def)\n  done\n\nlemma copy_conTrans:\n  \"\\<lbrakk>s' \\<in> step cmd s; (x, y) \\<in> directly_tgs_connected s'; cmd = (SysCopy e c\\<^sub>1 c\\<^sub>2 r)\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in> tgs_connected s\"\n  apply(clarsimp simp: step_def split: if_split_asm)\n   apply (erule disjE, fastforce simp: tgs_connected_def, clarsimp)\n   apply (drule copy_directly_tgs_connected, clarsimp, assumption)\n  apply (simp add: tgs_connected_def)\n  done\n\n(* Lemmas about destroy *)\n\nlemma direct_caps_of_destroy:\n  \"c \\<in> direct_caps_of (s(e := None)) x \\<Longrightarrow> c \\<in> direct_caps_of s x\"\n  by (simp add: direct_caps_of_def split: option.splits split: if_split_asm)\n\nlemma store_connected_destroy:\n \"(x, y) \\<in> store_connected (s(e := None)) \\<Longrightarrow> (x, y) \\<in> store_connected s\"\n  apply (simp add: store_connected_def)\n  apply (erule rtrancl_induct)\n   apply simp\n  apply (fold store_connected_def)\n  apply (subgoal_tac \"(y,z) \\<in> store_connected_direct s\")\n   apply (fastforce simp: store_connected_def)\n  apply (simp add: store_connected_direct_def)\n  apply clarsimp\n  by (metis direct_caps_of_destroy)\n\nlemma shares_caps_destroy:\n  \"shares_caps (destroyOperation e c s) x y\n  \\<Longrightarrow> shares_caps s x y\"\n  apply (clarsimp simp: shares_caps_def destroyOperation_def)\n  apply (frule store_connected_destroy [where x=x])\n  apply (drule store_connected_destroy [where x=y])\n  by auto\n\nlemma caps_of_destroy:\n  \"c \\<in> caps_of (destroyOperation e' c' s) e \\<Longrightarrow>\n  c \\<in> caps_of s e\"\n  apply (clarsimp simp add: destroyOperation_def caps_of_def)\n  apply (rule_tac x=x in exI)\n  apply (drule direct_caps_of_destroy)\n  apply simp\n  apply (erule store_connected_destroy)\n  done\n\nlemma destroy_directly_tgs_connected:\n  \"\\<lbrakk>s' \\<in> step (SysDestroy e c) s; (x, y) \\<in> directly_tgs_connected s'\\<rbrakk> \\<Longrightarrow>\n  (x, y) \\<in> directly_tgs_connected s\"\n  apply(clarsimp simp: step_def split: if_split_asm)\n  apply(erule disjE, simp)\n  apply(simp add: directly_tgs_connected_def leak_def)\n  apply (erule disjE)\n   apply(fastforce simp add: cap_in_caps_def dest!: caps_of_destroy)\n  apply (erule disjE)\n   apply(fastforce simp add: cap_in_caps_def dest!: caps_of_destroy)\n  apply (erule disjE)\n   apply (drule shares_caps_destroy, simp)\n  apply (erule disjE)\n   apply(fastforce simp add: cap_in_caps_def dest!: caps_of_destroy)\n  apply (erule disjE)\n   apply(fastforce simp add: cap_in_caps_def dest!: caps_of_destroy)\n  apply (drule shares_caps_destroy, simp)\n  done\n\nlemma destroy_conTrans:\n  \"\\<lbrakk>s' \\<in> step cmd s; (x, y) \\<in> directly_tgs_connected s'; cmd = (SysDestroy e c)\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in>  directly_tgs_connected s\"\n  by(auto dest!: destroy_directly_tgs_connected)\n\n\n(* lemmas about remove *)\n\nlemma direct_caps_of_remove:\n  \"c \\<in> direct_caps_of (removeOperation e c\\<^sub>1 c\\<^sub>2 s) x \\<Longrightarrow>\n  c \\<in> direct_caps_of s x\"\n  by (clarsimp simp: removeOperation_simpler direct_caps_of_def\n              split: option.splits if_split_asm)\n\nlemma direct_caps_of_remove_eq:\n  \"direct_caps_of (removeOperation e c\\<^sub>1 c\\<^sub>2 s) x =\n  ( if   is_entity s (target c\\<^sub>1) \\<and> x = target c\\<^sub>1\n   then  direct_caps_of s (target c\\<^sub>1) - {c\\<^sub>2}\n   else  direct_caps_of s x )\"\n  by(simp add: direct_caps_of_def is_entity_def removeOperation_def)\n\nlemma store_connected_remove [rule_format]:\n  \"(x, y) \\<in> store_connected (s(e \\<mapsto> Entity C')) \\<Longrightarrow>\n  s e = Some (Entity C) \\<longrightarrow> C' \\<subseteq> C \\<longrightarrow> (x, y) \\<in> store_connected s\"\n  apply (unfold store_connected_def)\n  apply (erule rtrancl_induct)\n   apply simp\n  apply clarsimp\n  apply (subgoal_tac \"(y,z) \\<in> store_connected_direct s\")\n   apply (erule rtrancl_trans)\n   apply fastforce\n  apply (fold store_connected_def)\n  apply (clarsimp simp add: store_connected_direct_def)\n  apply (fastforce simp: direct_caps_of_def\n                  split: option.splits if_split_asm)\n  done\n\nlemma caps_of_remove:\n  \"c \\<in> caps_of (removeOperation e c\\<^sub>1 c\\<^sub>2 s) x \\<Longrightarrow>\n  c \\<in> caps_of s x\"\n  apply (clarsimp simp: caps_of_def)\n  apply (rule_tac x=xa in exI)\n  apply (drule direct_caps_of_remove)\n  apply (simp add: removeOperation_simpler\n            split: option.splits)\n  apply (erule (1) store_connected_remove)\n  apply blast\n  done\n\n(* Might equal either  \"caps s (target c\\<^sub>1) - {c\\<^sub>2}\" or \"caps s x\" depending if the caps are duplicated.*)\nlemma caps_of_remove2:\n  \"caps_of (removeOperation e c\\<^sub>1 c\\<^sub>2 s) x \\<subseteq> caps_of s x\"\n  apply(simp add: caps_of_def is_entity_def removeOperation_def direct_caps_of_def)\n  apply (clarsimp split: if_split_asm)\n   apply (auto dest!: store_connected_remove)\n  done\n\nlemma shares_caps_remove:\n  \"shares_caps (removeOperation e c\\<^sub>1 c\\<^sub>2 s) x y\n  \\<Longrightarrow> shares_caps s x y\"\n  apply (clarsimp simp: shares_caps_def removeOperation_simpler\n                 split:option.splits)\n  apply (frule (1) store_connected_remove [where x=x], clarsimp)\n  apply (drule (1) store_connected_remove [where x=y], clarsimp)\n  by auto\n\nlemma remove_directly_tgs_connected:\n  \"\\<lbrakk>s' \\<in> step (SysRemove e c\\<^sub>1 c\\<^sub>2) s; (x, y) \\<in> directly_tgs_connected s'\\<rbrakk> \\<Longrightarrow>\n  (x, y) \\<in> directly_tgs_connected s\"\n  apply(simp add: step_def split: if_split_asm)\n  apply(erule disjE, simp)\n  apply(simp add: directly_tgs_connected_def leak_def)\n  apply(simp add: cap_in_caps_def)\n  apply(clarsimp)\n  apply safe\n     prefer 3\n     apply (drule shares_caps_remove, simp)\n    prefer 5\n    apply (drule shares_caps_remove, simp)\n   apply(auto dest!: caps_of_remove)\n  done\n\nlemma remove_conTrans:\n  \"\\<lbrakk>s' \\<in> step cmd s; (x, y) \\<in> directly_tgs_connected s'; cmd = (SysRemove e c\\<^sub>1 c\\<^sub>2)\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in>  directly_tgs_connected s\"\n  by(auto dest!: remove_directly_tgs_connected)\n\nlemma direct_caps_of_removeSet:\n  \"c' \\<in> direct_caps_of (removeSetOperation e c C s) x \\<Longrightarrow>\n  c' \\<in> direct_caps_of s x\"\n  by (clarsimp simp: removeSetOperation_simpler direct_caps_of_def\n              split: option.splits if_split_asm)\n\nlemma caps_of_removeSet:\n  \"c' \\<in> caps_of (removeSetOperation e c C s) x \\<Longrightarrow>\n  c' \\<in> caps_of s x\"\n  apply (clarsimp simp: caps_of_def)\n  apply (rule_tac x=xa in exI)\n  apply (drule direct_caps_of_removeSet)\n  apply (simp add: removeSetOperation_simpler split: option.splits)\n  apply (erule (1) store_connected_remove)\n  apply blast\n  done\n\nlemma shares_caps_removeSet:\n  \"shares_caps (removeSetOperation e c C s) x y\n  \\<Longrightarrow> shares_caps s x y\"\n  apply (clarsimp simp: shares_caps_def removeSetOperation_simpler split:option.splits)\n  apply (frule (1) store_connected_remove [where x=x], clarsimp)\n  apply (drule (1) store_connected_remove [where x=y], clarsimp)\n  by auto\n\nlemma removeSet_connected:\n  \" \\<lbrakk>s' \\<in> step (SysRemoveSet e c C) s; s' \\<turnstile> x \\<leftrightarrow> y\\<rbrakk> \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow> y\"\n  apply(simp add: step_def split: if_split_asm)\n  apply(erule disjE, simp)\n  apply(simp add: directly_tgs_connected_def leak_def)\n  apply(simp add: cap_in_caps_def)\n  apply(clarsimp)\n  apply safe\n     prefer 3\n     apply (drule shares_caps_removeSet, simp)\n    prefer 5\n    apply (drule shares_caps_removeSet, simp)\n   apply (auto dest!: caps_of_removeSet)\n  done\n\nlemma removeSet_conTrans:\n  \"\\<lbrakk>s' \\<in> step cmd s; s' \\<turnstile> x \\<leftrightarrow> y; cmd = (SysRemoveSet n c C)\\<rbrakk>\n  \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow> y\"\n  by(auto dest!: removeSet_connected)\n\n(* lemmas about revoke *)\nlemma direct_caps_of_removeSetOfCaps:\n  \"c' \\<in> direct_caps_of (removeSetOfCaps cap_map s) x \\<Longrightarrow>\n  c' \\<in> direct_caps_of s x\"\n  by (clarsimp simp: removeSetOfCaps_def direct_caps_of_def\n              split: option.splits if_split_asm)\nthm store_connected_remove\n\nlemma store_connected_removeSetOfCaps:\n  \"(x, y) \\<in> store_connected (\\<lambda>e. if is_entity s e\n                                 then Some (Entity (direct_caps_of s e - cap_map e))\n                                 else None) \\<Longrightarrow>\n    (x, y) \\<in> store_connected s\"\n  apply (unfold store_connected_def)\n  apply (erule rtrancl_induct)\n   apply simp\n  apply (subgoal_tac \"(y,z) \\<in> store_connected_direct s\")\n   apply (erule rtrancl_trans)\n   apply fastforce\n  apply (fold store_connected_def)\n  apply (clarsimp simp add: store_connected_direct_def)\n  apply (fastforce simp: direct_caps_of_def\n                  split: option.splits if_split_asm)\n  done\n\nlemma caps_of_removeSetOfCaps:\n  \"c' \\<in> caps_of (removeSetOfCaps cap_map s) x \\<Longrightarrow>\n  c' \\<in> caps_of s x\"\n  apply (clarsimp simp: caps_of_def)\n  apply (rule_tac x=xa in exI)\n  apply (drule direct_caps_of_removeSetOfCaps)\n  apply (simp add: removeSetOfCaps_def split: option.splits)\n  apply (erule store_connected_removeSetOfCaps)\n  done\n\nlemma caps_of_revoke:\n  \"\\<lbrakk>s' \\<in> revokeOperation sub c\\<^sub>1 s ;  c \\<in> caps_of s' e \\<rbrakk>\n  \\<Longrightarrow> c \\<in> caps_of s e\"\n  apply (clarsimp simp: revokeOperation_def\n                 split: if_split_asm)\n  apply (drule (1) caps_of_removeSetOfCaps)\n  done\n\nlemma direct_caps_of_revoke:\n  \"\\<lbrakk>s' \\<in> revokeOperation e c s; c' \\<in> direct_caps_of s' x\\<rbrakk>\n   \\<Longrightarrow> c' \\<in> direct_caps_of s x\"\n  apply (clarsimp simp: revokeOperation_def\n                 split: if_split_asm)\n  apply (drule (1) direct_caps_of_removeSetOfCaps)\n  done\n\nlemma store_connected_revoke:\n \"\\<lbrakk>(x, y) \\<in> store_connected s'; s' \\<in> revokeOperation e c s\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in> store_connected s\"\n  apply (simp add: store_connected_def)\n  apply (erule rtrancl_induct)\n   apply simp\n  apply (fold store_connected_def)\n  apply (subgoal_tac \"(y,z) \\<in> store_connected_direct s\")\n   apply (fastforce simp: store_connected_def)\n  apply (clarsimp simp: store_connected_direct_def)\n  apply (metis direct_caps_of_revoke)\n  done\n\nlemma shares_caps_revoke:\n  \"\\<lbrakk>shares_caps s' x y; s' \\<in> revokeOperation e c s\\<rbrakk>\n  \\<Longrightarrow> shares_caps s x y\"\n  apply (clarsimp simp: shares_caps_def)\n  apply (frule (1) store_connected_revoke [where x=x])\n  apply (drule (1) store_connected_revoke [where x=y])\n  by auto\n\nlemma removeOperation_entity_ids [simp]:\n  \"is_entity (removeOperation e c c' s) e' = is_entity s e'\"\n  by (simp add: is_entity_def removeOperation_def)\n\nlemma removeSetOfCaps_entity_ids [simp]:\n  \"is_entity (removeSetOfCaps cap_map s) e' = is_entity s e'\"\n  by (simp add: is_entity_def removeSetOfCaps_def)\n\nlemma revoke_entities:\n  \"s' \\<in> revokeOperation sub c\\<^sub>1 s \\<Longrightarrow> is_entity s' e = is_entity s e\"\n  by (clarsimp simp: revokeOperation_def split: if_split_asm)\n\nlemma revoke_directly_tgs_connected:\n  \"\\<lbrakk>s' \\<in> step (SysRevoke n c\\<^sub>1) s; (x, y) \\<in> directly_tgs_connected s'\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in>  directly_tgs_connected s\"\n  apply (simp add: step_def split: if_split_asm)\n  apply (erule disjE, simp)\n  apply (simp add: directly_tgs_connected_def leak_def)\n  apply (erule disjE)\n   apply(auto simp add: cap_in_caps_def dest!: caps_of_revoke)[1]\n  apply (erule disjE)\n   apply(auto simp add: cap_in_caps_def dest!: caps_of_revoke)[1]\n  apply (erule disjE)\n   apply (drule (1) shares_caps_revoke, simp)\n  apply (erule disjE)\n   apply(auto simp add: cap_in_caps_def dest!: caps_of_revoke)[1]\n  apply (erule disjE)\n   apply(auto simp add: cap_in_caps_def dest!: caps_of_revoke)[1]\n  apply (drule (1) shares_caps_revoke, simp)\n  done\n\nlemma revoke_conTrans:\n  \"\\<lbrakk>s' \\<in> step cmd s; (x, y) \\<in> directly_tgs_connected s'; cmd = (SysRevoke n c\\<^sub>1)\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in>  directly_tgs_connected s\"\n  by(auto dest!: revoke_directly_tgs_connected)\n\n\n\n(* lemmas about grant *)\n\nlemma is_entity_grant [simp]:\n  \"is_entity s (target c\\<^sub>1) \\<Longrightarrow>\n  is_entity (grantOperation e c\\<^sub>1 c\\<^sub>2 r s) e' = is_entity s e'\"\n  by (simp add: is_entity_def grantOperation_def)\n\nlemma is_entity_destroy:\n  \"is_entity (destroyOperation e' c s) e \\<Longrightarrow> is_entity s e\"\n  by (simp add: destroyOperation_def is_entity_def split: if_split_asm)\n\n\n(********************************************\n ********************************************\n ***** Connected transitively preserved *****\n ********************************************\n ********************************************)\n\nlemma connected_tgs_connected:\n  \"\\<lbrakk>s' \\<in> step cmd s; (e\\<^sub>x, e\\<^sub>y) \\<in> directly_tgs_connected s'\\<rbrakk> \\<Longrightarrow>\n  (e\\<^sub>x, e\\<^sub>y) \\<in> tgs_connected s\"\n  apply(case_tac \"(e\\<^sub>x, e\\<^sub>y) \\<in> directly_tgs_connected s\")\n   apply(simp add: tgs_connected_def)\n   apply(case_tac cmd)\n         apply(rule create_conTrans, fastforce+)\n        apply(rule take_conTrans, fastforce+)\n       apply(rule grant_conTrans, fastforce+)\n      apply(frule copy_conTrans, fastforce+)\n     apply(frule remove_conTrans, fastforce+)\n    apply(frule removeSet_conTrans, fastforce+)\n   apply(frule revoke_conTrans, fastforce+)\n  apply(frule destroy_conTrans, fastforce+)\n  done\n\nlemma tgs_connected_preserved_step:\n  \"\\<lbrakk>s' \\<in> step cmd s; s' \\<turnstile> x \\<leftrightarrow>* z\\<rbrakk> \\<Longrightarrow> s \\<turnstile> x \\<leftrightarrow>* z\"\n  thm rtrancl_induct [where r=\"directly_tgs_connected s'\" and a=x and b=z and P=\"\\<lambda>z. (x, z) \\<in> (directly_tgs_connected s)\\<^sup>*\", simplified,\n                      simplified tgs_connected_def [symmetric]]\n  apply(erule rtrancl_induct [where r=\"directly_tgs_connected s'\",\n                              simplified tgs_connected_def [symmetric]], simp)\n  apply(case_tac \"s \\<turnstile> y \\<leftrightarrow>* z\")\n   apply (erule (1) tgs_connected_trans)\n  apply (simp add: connected_tgs_connected)\n  done\n\nlemma leakImplyConnected:\n  \"leak s\\<^sub>i e\\<^sub>x e\\<^sub>i \\<Longrightarrow> (e\\<^sub>x, e\\<^sub>i) \\<in> directly_tgs_connected s\\<^sub>i\"\n by(simp add: directly_tgs_connected_def)\n\nlemma leakImplyConnectedTrans:\n  \"leak s\\<^sub>i e\\<^sub>x e\\<^sub>i \\<Longrightarrow> (e\\<^sub>x, e\\<^sub>i) \\<in> tgs_connected s\\<^sub>i\"\n  by(simp add: tgs_connected_def, frule leakImplyConnected, auto)\n\n\nlemma tgs_connected_preserved [rule_format]:\n  \"\\<forall>s'. s' \\<in> execute cmds s \\<longrightarrow>\n    s' \\<turnstile> x \\<leftrightarrow>* y \\<longrightarrow>\n    s \\<turnstile> x \\<leftrightarrow>* y\"\n  apply(induct_tac cmds, simp)\n  apply clarsimp\n  apply(rename_tac cmd cmds s'' s')\n  apply(erule_tac x=s' in allE)\n  apply(simp add: tgs_connected_preserved_step)\n  done\n\nlemma leak_conTrans [rule_format]:\n  \"\\<lbrakk>s \\<in> execute cmds s\\<^sub>0; leak s x y\\<rbrakk>\n  \\<Longrightarrow> (x, y) \\<in> tgs_connected s\\<^sub>0\"\n  by (auto intro: leakImplyConnectedTrans tgs_connected_preserved)\n\nlemma leakage_rule:\n  \"\\<lbrakk>s' \\<in> execute cmds s; \\<not> s \\<turnstile> x \\<leftrightarrow>* y\\<rbrakk> \\<Longrightarrow> \\<not> (s' \\<turnstile> x \\<rightarrow> y)\"\n  by(auto simp add: leak_conTrans)\n\n\n\n\n(*******************************************\n *******************************************\n *****      Authority confinement     *****\n *******************************************\n *******************************************)\n\nlemma caps_of_op:\n  \"\\<lbrakk>s' \\<in> step cmd s; c' \\<in> caps_of s' x\\<rbrakk>\n  \\<Longrightarrow> \\<exists>z. s \\<turnstile> x \\<leftrightarrow>* z \\<and> c' \\<in>cap caps_of s z\"\n  apply (simp add: step_def split:if_split_asm)\n   prefer 2\n   apply (fastforce simp: cap_in_caps_def tgs_connected_def rights_extra_rights)\n  apply (erule disjE)\n   apply (fastforce simp: cap_in_caps_def tgs_connected_def rights_extra_rights)\n  apply (case_tac cmd)\n         apply (simp add: caps_of_create)\n        apply (simp add: caps_of_take)\n       apply (simp add: caps_of_grant)\n      apply (simp add: caps_of_copy)\n     apply (clarsimp, drule caps_of_remove)\n     apply (fastforce simp: cap_in_caps_def tgs_connected_def rights_extra_rights)\n    apply (clarsimp, drule caps_of_removeSet)\n    apply (fastforce simp: cap_in_caps_def tgs_connected_def rights_extra_rights)\n   apply (clarsimp, drule (1) caps_of_revoke)\n   apply (fastforce simp: cap_in_caps_def tgs_connected_def rights_extra_rights)\n  apply (clarsimp, drule caps_of_destroy)\n  apply (fastforce simp: cap_in_caps_def tgs_connected_def rights_extra_rights)\n  done\n\nlemma authority_confinement_induct_step:\n  \"\\<lbrakk>s' \\<in> step cmd s;\n    \\<forall>e\\<^sub>i. s \\<turnstile> e\\<^sub>x \\<leftrightarrow>* e\\<^sub>i \\<longrightarrow> caps_of s e\\<^sub>i \\<le>cap c\\<rbrakk>\n  \\<Longrightarrow> caps_of s' e\\<^sub>x \\<le>cap c\"\n  apply (clarsimp simp: caps_dominated_by_def)\n  apply (drule (1) caps_of_op)\n  apply (fastforce simp: cap_in_caps_def)\n  done\n\nlemma authority_confinement_helper:\n  \"s' \\<in> execute cmds s \\<longrightarrow>\n   (\\<forall>e\\<^sub>i. s \\<turnstile> e\\<^sub>x \\<leftrightarrow>* e\\<^sub>i \\<longrightarrow> caps_of s e\\<^sub>i \\<le>cap c) \\<longrightarrow>\n   (\\<forall>e\\<^sub>i. s' \\<turnstile> e\\<^sub>x \\<leftrightarrow>* e\\<^sub>i \\<longrightarrow> caps_of s' e\\<^sub>i \\<le>cap c)\"\nproof (induct cmds arbitrary: s')\ncase Nil\n  show ?case by clarsimp\nnext\ncase (Cons cmd cmds s')\nshow ?case\n  apply clarsimp\n  apply (rule authority_confinement_induct_step, assumption)\n  apply clarsimp\n  apply (rule Cons.hyps[rule_format], simp_all)\n  apply (drule(1) tgs_connected_preserved_step)\n  apply (simp add: tgs_connected_def)\n  done\nqed\n\nlemma authority_confinement:\n  \"\\<lbrakk>s' \\<in> execute cmds s;\n    \\<forall>e\\<^sub>i. s \\<turnstile> e\\<^sub>x \\<leftrightarrow>* e\\<^sub>i \\<longrightarrow> caps_of s e\\<^sub>i \\<le>cap c\\<rbrakk>\n  \\<Longrightarrow> caps_of s' e\\<^sub>x \\<le>cap c\"\n  by (erule authority_confinement_helper [rule_format, where e\\<^sub>x=e\\<^sub>x], simp_all)\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/spec/take-grant/Confine_S.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6442251064863695, "lm_q2_score": 0.411110869232168, "lm_q1q2_score": 0.26484794350879737}}
{"text": "(* @TAG(OTHER_LGPL) *)\n\n(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      ClosureEx.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2006-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\ntheory ClosureEx\nimports \"../Vcg\" \"../Simpl_Heap\" Closure\nbegin\n\n\nrecord globals = \n cnt_' :: \"ref \\<Rightarrow> nat\"\n alloc_' :: \"ref list\"\n free_' :: \"nat\"\nrecord 'g vars = \"'g state\" +\n p_':: ref\n r_':: nat\n n_':: nat\n m_':: nat\n c_':: \"(string \\<times> ref) list \\<times> string\"\n d_':: \"(string \\<times> ref) list \\<times> string\"\n e_':: \"(string \\<times> nat) list \\<times> string\"\n\n\ndefinition \"var\\<^sub>n = [''n''\\<mapsto> (\\<lambda>x. n_'_update (\\<lambda>_. x)),\n                    ''m''\\<mapsto> (\\<lambda>x. m_'_update (\\<lambda>_. x))]\"\ndefinition \"upd\\<^sub>n = gen_upd var\\<^sub>n\"\n\nlemma upd\\<^sub>n_ap: \"upd\\<^sub>n (fst (ap es (es',p))) = upd\\<^sub>n es' \\<circ> upd\\<^sub>n es\"\n  by (simp add: upd\\<^sub>n_def gen_upd_ap)\n\n\nlemma\n\"\\<Gamma>\\<turnstile>\\<lbrace>\\<acute>n=n\\<^sub>0 \\<and> (\\<forall>i j. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>n=i \\<and> \\<acute>m=j\\<rbrace> callClosure upd\\<^sub>n \\<acute>e \\<lbrace>\\<acute>r=i + j\\<rbrace>)\\<rbrace> \n      \\<acute>e :== (ap [(''n'',\\<acute>n)] \\<acute>e) \n   \\<lbrace>\\<forall>j. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>m=j\\<rbrace> callClosure upd\\<^sub>n \\<acute>e \\<lbrace>\\<acute>r=n\\<^sub>0 + j\\<rbrace>\\<rbrace>\"\napply vcg_step\napply clarify\napply (rule ap_closure [where var=var\\<^sub>n, folded upd\\<^sub>n_def])\napply clarsimp\napply (rename_tac s s')\napply (erule_tac x=\"n_' s\" in allE) \napply (erule_tac x=\"m_' s'\" in allE) \napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply (assumption)\napply (simp add: upd\\<^sub>n_def gen_upd_def var\\<^sub>n_def)\ndone\n\n\ndefinition \"var = [''p''\\<mapsto> (\\<lambda>x. p_'_update (\\<lambda>_. x))]\"\ndefinition \"upd = gen_upd var\"\n\nprocedures Inc(p|r) =\n \"\\<acute>p\\<rightarrow>\\<acute>cnt :== \\<acute>p\\<rightarrow>\\<acute>cnt + 1;;\n  \\<acute>r :== \\<acute>p\\<rightarrow>\\<acute>cnt\"\n\nlemma (in Inc_impl)\n \"\\<forall>i p. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>p\\<rightarrow>\\<acute>cnt = i\\<rbrace> \\<acute>r :== PROC Inc(\\<acute>p) \\<lbrace>\\<acute>r=i+1 \\<and> \\<acute>p\\<rightarrow>\\<acute>cnt = i+1\\<rbrace>\"\n  apply vcg\n  apply simp\n  done\n  \nprocedures (imports Inc_signature) NewCounter(|c) =\n\"\\<acute>p :== NEW 1 [\\<acute>cnt :== 0];;\n \\<acute>c :== ([(''p'',\\<acute>p)],Inc_'proc)\" \n\n\nlocale NewCounter_impl' = NewCounter_impl + Inc_impl\nlemma (in NewCounter_impl')\nshows \n  \"\\<forall>alloc. \\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free\\<rbrace> \\<acute>c :== PROC NewCounter() \n          \\<lbrace>\\<exists>p. p\\<rightarrow>\\<acute>cnt = 0 \\<and>\n               (\\<forall>i. \\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = i\\<rbrace> callClosure upd \\<acute>c \\<lbrace>\\<acute>r=i+1 \\<and> p\\<rightarrow>\\<acute>cnt = i+1\\<rbrace>)\\<rbrace>\"\napply vcg\napply simp\napply (rule_tac x=\"new (set alloc)\" in exI)\napply simp\napply (simp add: callClosure_def)\napply vcg_step\napply vcg_step\napply vcg_step\napply vcg_step\napply (simp add: upd_def var_def gen_upd_def)\ndone\n\nlemma (in NewCounter_impl')\n\nshows \n  \"\\<forall>alloc. \\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free\\<rbrace> \\<acute>c :== PROC NewCounter() \n          \\<lbrace>\\<exists>p. p\\<rightarrow>\\<acute>cnt = 0 \\<and>\n               (\\<forall>i. \\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = i\\<rbrace> callClosure upd \\<acute>c \\<lbrace>\\<acute>r=i+1 \\<and> p\\<rightarrow>\\<acute>cnt = i+1\\<rbrace>)\\<rbrace>\"\napply vcg\napply simp\napply (rule_tac x=\"new (set alloc)\" in exI)\napply simp\napply (simp add: callClosure_def)\napply vcg_step\napply vcg_step\napply vcg_step\napply vcg_step\napply (simp add: upd_def var_def gen_upd_def)\ndone\n\nlemma (in NewCounter_impl')\nshows NewCounter_spec:\n  \"\\<forall>alloc. \\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free \\<and> \\<acute>alloc=alloc\\<rbrace> \\<acute>c :== PROC NewCounter() \n          \\<lbrace>\\<exists>p. p \\<notin> set alloc \\<and> p \\<in> set \\<acute>alloc \\<and> p \\<noteq> Null \\<and> p\\<rightarrow>\\<acute>cnt = 0 \\<and>\n               (\\<forall>i. \\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = i\\<rbrace> callClosure upd \\<acute>c \\<lbrace>\\<acute>r=i+1 \\<and> p\\<rightarrow>\\<acute>cnt = i+1\\<rbrace>)\\<rbrace>\"\napply vcg\napply clarsimp\napply (rule_tac x=\"new (set alloc)\" in exI)\napply simp\napply (simp add: callClosure_def)\napply vcg_step\napply vcg_step\napply vcg_step\napply vcg_step\napply (simp add: upd_def var_def gen_upd_def)\ndone\n\n\n\nlemma \"\\<Gamma>\\<turnstile>\\<lbrace>\\<exists>p. p \\<noteq> Null \\<and> p\\<rightarrow>\\<acute>cnt = i \\<and>\n              (\\<forall>i. \\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = i\\<rbrace> callClosure upd \\<acute>c \\<lbrace>\\<acute>r=i+1 \\<and> p\\<rightarrow>\\<acute>cnt = i+1\\<rbrace>)\\<rbrace>\n           dynCallClosure (\\<lambda>s. s) upd c_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>) \n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>r_' := r_' t\\<rparr>))\n           \\<lbrace>\\<acute>r=i+1\\<rbrace>\"\napply (rule conseq_extract_pre)\napply clarify\napply (rule dynCallClosureFix)\napply (simp only: Ball_def)\nprefer 3\napply (assumption)\nprefer 2\napply vcg_step\napply vcg_step\napply (simp only: simp_thms)\napply clarsimp\ndone\n\nlemma (in NewCounter_impl')\n shows \"\\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free\\<rbrace> \n             \\<acute>c :== CALL NewCounter ();;\n             dynCallClosure (\\<lambda>s. s) upd c_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>) \n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>r_' := r_' t\\<rparr>))\n           \\<lbrace>\\<acute>r=1\\<rbrace>\"\napply vcg_step\napply (rule dynCallClosure)\nprefer 2\napply vcg_step\napply vcg_step\napply vcg_step\napply clarsimp\napply (erule_tac x=0 in allE)\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply (assumption)\napply simp\ndone\n\n\nlemma (in NewCounter_impl')\n shows \"\\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free\\<rbrace> \n             \\<acute>c :== CALL NewCounter ();;\n             dynCallClosure (\\<lambda>s. s) upd c_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>) \n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>r_' := r_' t\\<rparr>));;\n             dynCallClosure (\\<lambda>s. s) upd c_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>) \n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>r_' := r_' t\\<rparr>))\n           \\<lbrace>\\<acute>r=2\\<rbrace>\"\napply vcg_step\napply (rule dynCallClosure)\nprefer 2\napply vcg_step\napply vcg_step\napply vcg_step\napply (rule dynCallClosure)\napply vcg_step\napply vcg_step\napply vcg_step\n\napply clarsimp\napply (subgoal_tac \"\\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = 0\\<rbrace> callClosure upd (c_' t) \\<lbrace>\\<acute>r = Suc 0 \\<and> p\\<rightarrow>\\<acute>cnt = Suc 0\\<rbrace>\")\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply assumption\napply clarsimp\napply (erule_tac x=1 in allE)\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply assumption\napply clarsimp\napply (erule allE)\napply assumption\ndone\n\n\nlemma (in NewCounter_impl')\n shows \"\\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free\\<rbrace> \n             \\<acute>c :== CALL NewCounter ();;\n             \\<acute>d :== \\<acute>c;;\n             dynCallClosure (\\<lambda>s. s) upd c_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>) \n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>n_' := r_' t\\<rparr>));;\n             dynCallClosure (\\<lambda>s. s) upd d_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>) \n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>m_' := r_' t\\<rparr>));;\n             \\<acute>r :== \\<acute>n + \\<acute>m\n           \\<lbrace>\\<acute>r=3\\<rbrace>\"\n\napply vcg_step\napply vcg_step\napply (rule dynCallClosure)\nprefer 2\napply vcg_step\napply vcg_step\napply vcg_step\napply (rule dynCallClosure)\napply vcg_step\napply vcg_step\napply vcg_step\napply vcg_step\napply clarsimp\napply (subgoal_tac \"\\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = 0\\<rbrace> callClosure upd (c_' t) \\<lbrace>\\<acute>r = Suc 0 \\<and> p\\<rightarrow>\\<acute>cnt = Suc 0\\<rbrace>\")\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply assumption\napply clarsimp\napply (erule_tac x=1 in allE)\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply assumption\napply clarsimp\napply (erule allE)\napply assumption\ndone\n\nend", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/c-parser/Simpl/ex/ClosureEx.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5467381372136563, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.2648290649809923}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory CustomWordAbs\nimports \"AutoCorres.AutoCorres\"\nbegin\n\nexternal_file \"custom_word_abs.c\"\ninstall_C_file \"custom_word_abs.c\"\n\nlemma [word_abs]:\n  \"\\<lbrakk> abstract_val P x sint x'; abstract_val Q y sint y' \\<rbrakk> \\<Longrightarrow>\n        abstract_val (P \\<and> Q) (max x y)\n          sint (x' xor (x' xor y') && - (if x' <s y' then (1 :: sword32) else 0))\"\n  apply (clarsimp simp: max_def word_sless_def word_sle_def)\n  done\n\nlemma [word_abs]:\n  \"\\<lbrakk> abstract_val P x unat x'; abstract_val Q y unat y' \\<rbrakk> \\<Longrightarrow>\n         abstract_val (P \\<and> Q \\<and> y < 32) (x mod (2 ^ y)) unat (x' && 2 ^ unat y' - (1 :: word32))\"\n  apply (clarsimp simp del: shiftl_1 simp: shiftl_1 [symmetric])\n  apply (fold mask_def)\n  apply (subst word_mod_2p_is_mask [symmetric])\n  apply (subst p2_gt_0)\n  by (auto simp: unat_mod)\n\nlemma [word_abs]:\n  \"\\<lbrakk> abstract_val P x unat (x' :: word32);\n     abstract_val Q y unat y' \\<rbrakk> \\<Longrightarrow>\n      abstract_val (P \\<and> Q) (x + y > UINT_MAX) id (x' + y' < x')\"\n  apply (subst not_le [symmetric], subst no_plus_overflow_unat_size)\n  apply (clarsimp simp: not_less UINT_MAX_def word_size)\n  apply arith\n  done\n\nautocorres [unsigned_word_abs = b c] \"custom_word_abs.c\"\n\ncontext custom_word_abs begin\n\nlemma \"a' x y = max x y\"\n  by (unfold a'_def, rule refl)\n\nlemma \"b' x 4 s = Some (x mod 16)\"\n  by (unfold b'_def, simp)\n\nlemma \"c' x y = (if UINT_MAX < x + y then 1 else 0)\"\n  by (unfold c'_def, simp)\n\nend\n\nend\n", "meta": {"author": "NICTA", "repo": "l4v", "sha": "3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b", "save_path": "github-repos/isabelle/NICTA-l4v", "path": "github-repos/isabelle/NICTA-l4v/l4v-3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b/tools/autocorres/tests/proof-tests/CustomWordAbs.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6150878555160665, "lm_q2_score": 0.43014734858584286, "lm_q1q2_score": 0.264578410197588}}
{"text": "(* trans_semantics.thy *)\n(* William Mansky *)\n(* Semantics for the revised specification language PTRANS. *)\n\ntheory trans_semantics\nimports trans_flowgraph\nbegin\n\n(* matches a total valuation of metavariables with a partial one *)\ndefinition part_matches where \"part_matches \\<sigma> t \\<equiv> \\<forall>x y. t x = Some y \\<longrightarrow> \\<sigma> x = y\"\n\n(* extends a partial valuation with another valuation over a given domain *)\ndefinition part_extend where \"part_extend t d \\<sigma> \\<equiv> \\<lambda>x. if x\\<in>d then Some (\\<sigma> x) else t x\"\n\n(* The pieces that must be provided by the target language to give semantics to transformations. *) \nlocale TRANS_basics = (* give SCEx a type annotation, parameterize by 'valuation? *)\n  fixes subst::\"(('thread, ('node, 'edge_type, 'instr) flowgraph) map) \\<Rightarrow> ('metavar \\<Rightarrow> 'object) \\<Rightarrow> 'pattern \\<rightharpoonup> 'instr\"\n    and node_subst::\"(('thread, ('node, 'edge_type, 'instr) flowgraph) map) \\<Rightarrow> ('metavar \\<Rightarrow> 'object) \\<Rightarrow> \n                     'metavar node_lit \\<rightharpoonup> 'node\"\n    and type_subst::\"('metavar \\<Rightarrow> 'object) \\<Rightarrow> 'edge_type_expr \\<rightharpoonup> 'edge_type\"\n    and pred_fv::\"'pred \\<Rightarrow> 'metavar set\"\n    and eval_pred::\"(('thread, ('node, 'edge_type, 'instr) flowgraph) map) \\<Rightarrow> ('thread, 'node) map \\<Rightarrow> \n                    ('metavar \\<Rightarrow> 'object) \\<Rightarrow> 'pred \\<Rightarrow> bool\"\n    and instr_edges::\"'instr \\<Rightarrow> ('edge_type \\<Rightarrow> nat) set\" \n    and Seq::'edge_type\n  assumes infinite_nodes [simp]: \"\\<not>finite (UNIV::'node set)\"\n      and infinite_mvars [simp]: \"\\<not>finite (UNIV::'metavar set)\"\n      and pred_same_subst: \"\\<lbrakk>\\<forall>x\\<in>pred_fv p. \\<sigma> x = \\<sigma>' x; pre_tCFG CFGs\\<rbrakk> \\<Longrightarrow> \n eval_pred CFGs q \\<sigma> p = eval_pred CFGs q \\<sigma>' p\"\nbegin\n\nlemmas fresh_nodes = infinite_nodes [THEN fresh_new]\nlemmas fresh_mvars = infinite_mvars [THEN fresh_new]\n\nprimrec subst_list where\n\"subst_list G \\<sigma> [] = Some []\" | \n\"subst_list G \\<sigma> (p # rest) = (case (subst G \\<sigma> p, subst_list G \\<sigma> rest) of \n   (Some i, Some irest) \\<Rightarrow> Some (i # irest) | _ \\<Rightarrow> None)\"\n\nprimrec models where\n\"models _ _ _ SCTrue = True\" |\n\"models CFGs \\<sigma> q (SCPred p) = eval_pred CFGs q \\<sigma> p\" |\n\"models CFGs \\<sigma> q (\\<phi>1 \\<and>sc \\<phi>2) = (models CFGs \\<sigma> q \\<phi>1 \\<and> models CFGs \\<sigma> q \\<phi>2)\" |\n\"models CFGs \\<sigma> q (\\<not>sc \\<phi>) = (\\<not>models CFGs \\<sigma> q \\<phi>)\" |\n\"models CFGs \\<sigma> q (A \\<phi>1 \\<U> \\<phi>2) = (\\<forall>l \\<in> pre_tCFG.Paths CFGs q. \\<exists>i. models CFGs \\<sigma> (l i) \\<phi>2 \\<and>\n (\\<forall>j<i. models CFGs \\<sigma> (l j) \\<phi>1))\" |\n\"models CFGs \\<sigma> q (E \\<phi>1 \\<U> \\<phi>2) = (\\<exists>l \\<in> pre_tCFG.Paths CFGs q. \\<exists>i. models CFGs \\<sigma> (l i) \\<phi>2 \\<and>\n (\\<forall>j<i. models CFGs \\<sigma> (l j) \\<phi>1))\" |\n\"models CFGs \\<sigma> q (A \\<phi>1 \\<B> \\<phi>2) = (\\<forall>l \\<in> pre_tCFG.RPaths CFGs q. \\<exists>i. models CFGs \\<sigma> (l i) \\<phi>2 \\<and>\n (\\<forall>j<i. models CFGs \\<sigma> (l j) \\<phi>1))\" |\n\"models CFGs \\<sigma> q (E \\<phi>1 \\<B> \\<phi>2) = (\\<exists>l \\<in> pre_tCFG.RPaths CFGs q. \\<exists>i. models CFGs \\<sigma> (l i) \\<phi>2 \\<and>\n (\\<forall>j<i. models CFGs \\<sigma> (l j) \\<phi>1))\" |\n\"models CFGs \\<sigma> q (SCEx x \\<phi>) = (\\<exists>obj. models CFGs (\\<sigma>(x := obj)) q \\<phi>)\"\n\nabbreviation \"side_cond_sf \\<psi> \\<sigma> CFGs \\<equiv> models CFGs \\<sigma> (start_points CFGs) \\<psi>\"\n\nlemma cond_same_subst: \"\\<lbrakk>\\<forall>x\\<in>cond_fv pred_fv P. \\<sigma> x = \\<sigma>' x; pre_tCFG CFGs\\<rbrakk> \\<Longrightarrow> \n models CFGs \\<sigma> q P = models CFGs \\<sigma>' q P\"\napply (induct P arbitrary: \\<sigma> \\<sigma>' q, simp+)\napply (erule pred_same_subst, simp)\napply (metis (lifting, mono_tags) UnI1 UnI2 cond_fv.simps(3) models.simps(3))\napply simp\napply (smt UnI1 UnI2 cond_fv.simps(5) models.simps(5))\napply (smt UnI1 UnI2 cond_fv.simps(6) models.simps(6))\napply (smt UnI1 UnI2 cond_fv.simps(7) models.simps(7))\napply (smt UnI1 UnI2 cond_fv.simps(8) models.simps(8))\napply auto\napply (rule_tac x=obj in exI, smt DiffI fun_upd_def singletonE)+\ndone\n\nlemma cond_gen: \"\\<lbrakk>models CFGs \\<sigma> q P; \\<forall>x\\<in>cond_fv pred_fv P. \\<sigma> x = \\<sigma>' x; pre_tCFG CFGs\\<rbrakk> \\<Longrightarrow> \n models CFGs \\<sigma>' q P\"\nby (drule cond_same_subst, simp, force)\n\nend\n\n(* Utility functions for actions. *)\nfun update_list where\n\"update_list f [] = f\" |\n\"update_list f ((x,y) # rest) = update_list (f(x := y)) rest\"\n\nlemma update_list_past [simp]: \"x \\<notin> fst ` set l \\<Longrightarrow> update_list f l x = f x\"\nby (induct l arbitrary: f, auto)\n\nlemma update_list_i: \"\\<lbrakk>distinct (map fst l); (x, y) \\<in> set l\\<rbrakk> \\<Longrightarrow> update_list f l x = y\"\nby (induct l arbitrary: f, auto)\n\ndefinition \"remap_succ x y e \\<equiv> let (n,s,t) = e in if x = n then (y,s,t) else e\"\n\ncontext TRANS_basics begin\n\ndefinition \"rep_edges es ll \\<equiv> if ll = [] then es else\n  {remap_succ (hd ll) (last ll) e | e. e\\<in>es} \\<union>\n  {(u,v,Seq) | u v. (\\<exists>a. ll!a = u \\<and> ll!(a+1) = v \\<and> (a+1) < length ll)}\"\n\nlemma rep_one_edge [simp]: \"rep_edges es [n] = es\"\nby (auto simp add: rep_edges_def remap_succ_def)\n\nlemma rep_edges_out [simp]: \"n \\<notin> set ll \\<Longrightarrow> ((n, b, c) \\<in> rep_edges es ll) = ((n, b, c) \\<in> es)\"\nby (auto simp add: rep_edges_def remap_succ_def, force+)\n\nlemma rep_out_edges_out [simp]: \"n \\<notin> set ll \\<Longrightarrow> out_edges (rep_edges es ll) n = out_edges es n\"\nby (simp add: out_edges_def)\n\nlemma rep_out_edges_in: \"\\<lbrakk>n = ll ! i; i < length ll - 1; distinct ll; i = 0 \\<or> (\\<forall>n' e. (n, n', e) \\<notin> es)\\<rbrakk> \\<Longrightarrow> \n  out_edges (rep_edges es ll) n = {(ll ! (i + 1), Seq)}\"\napply (clarsimp simp add: rep_edges_def remap_succ_def out_edges_def)\napply (case_tac \"ll = []\", simp+)\napply (simp add: last_conv_nth, rule set_eqI, rule iffI, clarsimp)\napply (erule_tac Q=\n           \"b = Seq \\<and> (\\<exists>aa. ll ! aa = ll ! i \\<and> ll ! Suc aa = a \\<and> Suc aa < length ll)\"\n           in disjE, clarsimp)\n(* I think this works in 2015, while the above works in 2014, argh!\napply (erule_tac P=\"\\<exists>aa. _ aa\" in disjE, clarsimp)\n*)\napply (case_tac \"hd ll = aa\", simp add: nth_eq_iff_index_eq, force simp add: hd_conv_nth)\napply (clarsimp simp add: nth_eq_iff_index_eq)\napply auto\ndone\n\ncorollary rep_out_edge_in: \"\\<lbrakk>(n, n', e) \\<in> rep_edges es ll; n = ll ! i; i < length ll - 1; distinct ll; \n  i = 0 \\<or> (\\<forall>n' e. (n, n', e) \\<notin> es)\\<rbrakk> \\<Longrightarrow> n' = ll ! (i + 1) \\<and> e = Seq\"\napply (frule rep_out_edges_in, simp+)\nby (metis out_edge prod.sel(1) prod.sel(2) singletonD)\n\nlemma rep_out_edges_last: \"\\<lbrakk>n = last ll; ll \\<noteq> []; distinct ll; \\<forall>n' e. (n, n', e) \\<notin> es\\<rbrakk> \\<Longrightarrow> \n  out_edges (rep_edges es ll) n = out_edges es (hd ll)\"\napply (clarsimp simp add: rep_edges_def remap_succ_def out_edges_def)\napply (rule set_eqI, rule iffI, clarsimp)\napply (erule disjE, clarsimp)\napply (case_tac \"hd ll = aa\", clarsimp+)\napply (simp add: last_conv_nth nth_eq_iff_index_eq)\napply (clarsimp simp add: nth_eq_iff_index_eq)\napply auto\ndone\n\nlemma rep_out_by_t [simp]: \"n \\<notin> set ll \\<Longrightarrow> out_by_t (rep_edges es ll) t n = out_by_t es t n\"\nby (simp add: out_edges_by_t)\n\n(* Actions are defined by their effects on one of the CFGs in a tCFG. *)\nfun action_sf where\n\"action_sf (AAddEdge n m e) \\<sigma> CFGs = (case (node_subst CFGs \\<sigma> n, node_subst CFGs \\<sigma> m, type_subst \\<sigma> e) of \n   (Some u, Some v, Some ty) \\<Rightarrow> if u \\<notin> nodes CFGs \\<or> u \\<in> exits CFGs \\<or> v \\<in> starts CFGs\n    then None else \n   (case CFGs (thread_of u CFGs) of Some G \\<Rightarrow> \n    if v \\<in> Nodes G then Some (CFGs(thread_of u CFGs \\<mapsto> G\\<lparr>Edges := Edges G \\<union> {(u,v,ty)}\\<rparr>)) else None \n | _ \\<Rightarrow> None) | _ \\<Rightarrow> None)\" |\n\"action_sf (ARemoveEdge n m e) \\<sigma> CFGs = (case (node_subst CFGs \\<sigma> n, node_subst CFGs \\<sigma> m, type_subst \\<sigma> e) of \n   (Some u, Some v, Some ty) \\<Rightarrow> if u \\<notin> nodes CFGs then None else \n   (case CFGs (thread_of u CFGs) of Some G \\<Rightarrow> \n   Some (CFGs(thread_of u CFGs \\<mapsto> G\\<lparr>Edges := Edges G - {(u,v,ty)}\\<rparr>)) | _ \\<Rightarrow> None)\n | _ \\<Rightarrow> None)\" |\n\"action_sf (AReplace m pl) \\<sigma> CFGs = (if pl = [] then (\n case node_subst CFGs \\<sigma> m of Some l \\<Rightarrow> if l \\<notin> nodes CFGs \\<or> l \\<in> starts CFGs \\<or> l \\<in> exits CFGs then None \n   else (case CFGs (thread_of l CFGs) of Some G \\<Rightarrow> \n   Some (CFGs(thread_of l CFGs \\<mapsto> G\\<lparr>Nodes := Nodes G - {l}, Edges := {(u,v,t). (u,v,t) \\<in> Edges G \\<and> u \\<noteq> l \\<and> v \\<noteq> l}\\<rparr>)) | _ \\<Rightarrow> None)\n     | _ \\<Rightarrow> None)\n else case (node_subst CFGs \\<sigma> m, subst_list CFGs \\<sigma> pl) of \n   (Some l, Some il) \\<Rightarrow> if l \\<notin> nodes CFGs \\<or> l \\<in> exits CFGs then None else\n   (case CFGs (thread_of l CFGs) of Some G \\<Rightarrow>\n   let ll = new (nodes CFGs) (length il - 1)\n    in Some (CFGs(thread_of l CFGs \\<mapsto> G\\<lparr>Nodes := Nodes G \\<union> set ll, Edges := rep_edges (Edges G) (l#ll), \n                        Label := update_list (Label G) (zip (l#ll) il)\\<rparr>)) | _ \\<Rightarrow> None)\n   | _ \\<Rightarrow> None)\" |\n\"action_sf (ASplitEdge n m e i) \\<sigma> CFGs = (case (node_subst CFGs \\<sigma> n,node_subst CFGs \\<sigma> m,type_subst \\<sigma> e,subst CFGs \\<sigma> i) of\n   (Some u, Some v, Some ty, Some j) \\<Rightarrow>\n   (if (u,v,ty) \\<in> edges CFGs then (case CFGs (thread_of u CFGs) of Some G \\<Rightarrow>\n    (let q = hd (new (nodes CFGs) 1)\n    in Some (CFGs(thread_of u CFGs \\<mapsto> G\\<lparr>Nodes := Nodes G \\<union> {q}, Edges := (Edges G - {(u,v,ty)}) \\<union> {(u,q,ty),(q,v,Seq)}, \n                        Label := (Label G)(q := j)\\<rparr>))) | _ \\<Rightarrow> None)\n    else None) | _ \\<Rightarrow> None)\"\n\n(* semantics for lists of actions *)\nprimrec part_comp :: \"('a \\<rightharpoonup> 'a) list \\<Rightarrow> 'a \\<rightharpoonup> 'a\" where \n\"part_comp ([]::('a \\<rightharpoonup> 'a) list) x = Some x\" |\n\"part_comp (f#rest) x = (case f x of None \\<Rightarrow> None | Some y \\<Rightarrow> part_comp rest y)\"\n\ndefinition action_list_sf\nwhere \"action_list_sf Al \\<sigma> CFGs \\<equiv> part_comp (map (\\<lambda>a G. action_sf a \\<sigma> G) Al) CFGs\"\n\n(* Recursive (fixpoint) application of a transformation *)\ninductive apply_some::\"(('metavar \\<rightharpoonup> 'object) \\<Rightarrow> 'a \\<Rightarrow> 'a set) \\<Rightarrow>\n ('metavar \\<rightharpoonup> 'object) \\<Rightarrow> 'a \\<Rightarrow> 'a \\<Rightarrow> bool\" where\napply_none: \"apply_some T \\<tau> G G\" |\napply_more: \"\\<lbrakk>G' \\<in> T \\<tau> G; apply_some T \\<tau> G' G''\\<rbrakk> \\<Longrightarrow> apply_some T \\<tau> G G''\"\n\n(* Transformations apply actions when their conditions are met. *)\nprimrec trans_sf where\n\"trans_sf (TIf al p) \\<tau> CFGs = {CFGs' | CFGs' \\<sigma>. Some CFGs' = action_list_sf al \\<sigma> CFGs \\<and>\n    side_cond_sf p \\<sigma> CFGs \\<and> part_matches \\<sigma> \\<tau>}\" |\n\"trans_sf (TMatch p T) \\<tau> CFGs = {CFGs' | CFGs' \\<sigma>. side_cond_sf p \\<sigma> CFGs \\<and> part_matches \\<sigma> \\<tau> \\<and> \n      CFGs' \\<in> trans_sf T (part_extend \\<tau> (cond_fv pred_fv p) \\<sigma>) CFGs}\" |\n\"trans_sf (TChoice T1 T2) \\<tau> CFGs = (trans_sf T1 \\<tau> CFGs) \\<union> (trans_sf T2 \\<tau> CFGs)\" |\n\"trans_sf (TThen T1 T2) \\<tau> CFGs = {CFGs'' | CFGs' CFGs''. CFGs' \\<in> trans_sf T1 \\<tau> CFGs \\<and> CFGs'' \\<in> trans_sf T2 \\<tau> CFGs'}\" |\n\"trans_sf (TApplyAll T) \\<tau> CFGs = {CFGs'. apply_some (trans_sf T) \\<tau> CFGs CFGs'} - \n {CFGs' | CFGs' CFGs''. CFGs' \\<noteq> CFGs'' \\<and> CFGs'' \\<in> trans_sf T \\<tau> CFGs'}\"\n\nlemma fst_set_zip [simp]: \"length a = length b \\<Longrightarrow> fst ` set (zip a b) = set a\"\napply (induct a arbitrary: b, clarsimp+)\napply (case_tac b, simp+)\ndone\n\nlemma subst_last [simp]: \"\\<lbrakk>subst_list CFGs \\<sigma> l = Some l'; l \\<noteq> []\\<rbrakk> \\<Longrightarrow> \n  subst CFGs \\<sigma> (last l) = Some (last l')\"\napply (induct l arbitrary: l', simp, clarsimp split: option.splits)\napply (case_tac l, simp, clarsimp split: option.splits)\ndone\n\nlemma subst_nth [simp]: \"\\<lbrakk>subst_list CFGs \\<sigma> l = Some l'; i < length l'\\<rbrakk> \\<Longrightarrow> \n  subst CFGs \\<sigma> (l ! i) = Some (l' ! i)\"\napply (induct l arbitrary: l' i, simp, clarsimp split: option.splits)\napply (case_tac i, simp+)\ndone\n\nlemma subst_length [simp]: \"subst_list CFGs \\<sigma> l = Some l' \\<Longrightarrow> length l = length l'\"\nby (induct l arbitrary: l', auto split: option.splits)\n\nlemma replace_CFGs: \"\\<lbrakk>action_sf (AReplace m pl) \\<sigma> CFGs = Some CFGs'; pl \\<noteq> []; \n  \\<forall>p\\<in>set (butlast pl). \\<forall>i. subst CFGs \\<sigma> p = Some i \\<longrightarrow> instr_edges i = {no_edges(Seq := 1)};\n  \\<forall>i n. subst CFGs \\<sigma> (last pl) = Some i \\<and> node_subst CFGs \\<sigma> m = Some n \\<longrightarrow> \n    instr_edges i = instr_edges (Label (the (CFGs (thread_of n CFGs))) n);\n  tCFG CFGs instr_edges Seq\\<rbrakk> \\<Longrightarrow> tCFG CFGs' instr_edges Seq\"\nproof - assume \"tCFG CFGs instr_edges Seq\" then interpret tCFG .\nshow \"\\<lbrakk>action_sf (AReplace m pl) \\<sigma> CFGs = Some CFGs'; pl \\<noteq> []; \n  \\<forall>p\\<in>set (butlast pl). \\<forall>i. subst CFGs \\<sigma> p = Some i \\<longrightarrow> instr_edges i = {no_edges(Seq := 1)};\n  \\<forall>i n. subst CFGs \\<sigma> (last pl) = Some i \\<and> node_subst CFGs \\<sigma> m = Some n \\<longrightarrow> \n    instr_edges i = instr_edges (Label (the (CFGs (thread_of n CFGs))) n);\n  tCFG CFGs instr_edges Seq\\<rbrakk> \\<Longrightarrow> tCFG CFGs' instr_edges Seq\"\napply (cut_tac nodes_finite)\napply (clarsimp simp add: Let_def split: option.splits if_splits)\napply (rename_tac l ll g)\napply (unfold_locales, auto)\napply (case_tac \"t \\<noteq> thread_of l CFGs\", simp, erule CFGs)\napply (clarsimp, frule CFGs, clarsimp simp add: is_flowgraph_def flowgraph_def)\napply (rule context_conjI, clarsimp simp add: pointed_graph_def)\napply (rule conjI, clarsimp simp add: rep_edges_def remap_succ_def)\napply (case_tac \"new (nodes CFGs) (length ll - Suc 0) = []\", clarsimp)\napply (case_tac \"length ll - Suc 0\", force)\napply (simp add: Let_def)\napply clarsimp\napply (erule disjE, force)\napply clarsimp\napply (case_tac a, simp+)\napply (frule node_of_graph, simp+)\napply (rule conjI, clarsimp simp add: in_edges_def rep_edges_def remap_succ_def)\napply (rule conjI, clarsimp, case_tac \"length ll - 1\")\napply (metis One_nat_def gr_implies_not0)\napply (simp add: Let_def)\napply (clarsimp, rule conjI, force, clarsimp)\napply (cut_tac S=\"nodes CFGs\" and m=\"Start g\" in new_nodes_are_new, simp+)\napply (simp add: set_conv_nth)\napply (rule_tac x=aa in exI, rule conjI, erule sym, simp+)\napply (metis nodes_by_graph)\napply (clarsimp simp add: out_edges_def rep_edges_def remap_succ_def)\napply (rule conjI, clarsimp, case_tac \"length ll - 1\")\napply (metis One_nat_def gr_implies_not0)\napply (simp add: Let_def)\napply (clarsimp, rule conjI, clarsimp)\napply (rule conjI, clarsimp)\napply (cut_tac S=\"nodes CFGs\" and m=\"Exit g\" in new_nodes_are_new, simp+)\napply (drule_tac as=\"new (nodes CFGs) (length ll - Suc 0)\" in last_in_set, simp+)\napply (metis nodes_by_graph)\napply metis\napply clarsimp\napply (case_tac aa, clarsimp)\napply (metis exits_by_graph)\napply clarsimp\napply (cut_tac S=\"nodes CFGs\" and m=\"Exit g\" in new_nodes_are_new, simp+)\napply (simp add: set_conv_nth, rule exI, rule conjI, erule sym, simp+)\napply (metis nodes_by_graph)\n(* now flowgraph_axioms *)\napply (case_tac \"ll = []\", clarsimp)\napply (clarsimp simp add: flowgraph_axioms_def)\napply (subgoal_tac \"distinct (l # new (nodes CFGs) (length ll - 1))\")\napply ((rule conjI, clarsimp)+)\napply (case_tac \"u = l\", clarsimp)\napply (case_tac \"length ll - 1 = 0\", simp)\napply (case_tac ll, simp+)\napply (case_tac pl, simp, clarsimp split: option.splits)\napply (case_tac list, simp_all split: option.splits, clarsimp)\napply (rename_tac lrest)\napply (simp add: rep_edges_def remap_succ_def out_edges_def)\napply (rule conjI, clarsimp simp add: Let_def, clarsimp intro!: ext simp add: edge_types_def)\napply (subgoal_tac \"l \\<noteq> last (let n' = SOME n. n \\<notin> nodes CFGs in n' # \n  new (insert n' (nodes CFGs)) (length lrest))\", clarsimp)\napply (rule_tac s=\"{SOME n. n \\<notin> nodes CFGs}\" in subst, simp_all, rule set_eqI, rule iffI, \n  clarsimp simp add: Let_def)\napply (rule_tac x=0 in exI, simp)\napply clarsimp\napply (case_tac ab, simp+)\napply (cut_tac m=l and S=\"nodes CFGs\" and n=\"Suc (length lrest)\" in new_nodes_are_new2, simp+)\napply (force simp add: Let_def set_conv_nth)\napply (clarsimp simp add: Let_def)\napply (cut_tac S=\"nodes CFGs\" and n=\"Suc (length lrest)\" in new_nodes_are_new, simp+, \n  simp add: set_conv_nth Let_def, rule_tac x=nat in exI, simp+)\napply clarsimp+\napply (subgoal_tac \"u \\<notin> set (l # new (nodes CFGs) (length ll - Suc 0))\", simp, clarsimp)\napply (cut_tac S=\"nodes CFGs\" in new_nodes_are_new, simp+)\napply (metis nodes_by_graph)\napply (clarsimp simp add: set_conv_nth)\napply (cut_tac l=\"zip (l # new (nodes CFGs) (length ll - Suc 0)) ll\" and f=\"Label g\" and\n  x=\"new (nodes CFGs) (length ll - Suc 0) ! i\" in update_list_i, simp+)\napply (clarsimp, cut_tac S=\"nodes CFGs\" in new_nodes_are_new, simp+)\napply (simp add: set_zip, rule_tac x=\"Suc i\" in exI, force)\napply simp\napply (case_tac \"Suc i = length ll - 1\", clarsimp simp add: last_conv_nth)\napply (clarsimp simp add: rep_edges_def remap_succ_def out_edges_def, rule conjI, clarsimp)\napply (case_tac ll, simp+)\napply (case_tac list, simp, simp add: Let_def)\napply clarsimp\napply (erule_tac x=l in allE, simp add: node_of_graph, erule impE)\napply (metis exits_by_graph)\napply (rule_tac s=\"{(u, t). (l, u, t) \\<in> Edges g}\" in subst, simp_all)\napply (subgoal_tac \"new (nodes CFGs) (length ll - Suc 0) ! i = \n  last (new (nodes CFGs) (length ll - Suc 0))\", simp)\napply (rule set_eqI, rule iffI, clarsimp simp add: last_conv_nth, metis)\napply clarsimp\napply (erule disjE, clarsimp)\napply (case_tac \"l = aa\", simp, clarsimp)\napply (drule pointed_graph.edges_ok, simp, clarsimp)\napply (cut_tac S=\"nodes CFGs\" and m=\"new (nodes CFGs) (length ll - 1) ! i\" in new_nodes_are_new, \n  simp+)\napply (force simp add: set_conv_nth)\napply (metis (hide_lams, no_types) One_nat_def nodes_by_graph)\napply clarsimp\napply (case_tac aa, clarsimp)\napply (cut_tac S=\"nodes CFGs\" and n=\"length ll - Suc 0\" in new_nodes_are_new, simp+, \n  rule last_in_set, clarsimp+)\napply (cut_tac S1=\"nodes CFGs\" and i=i and j=nat and n1=\"length ll - 1\" in \n  nth_eq_iff_index_eq [OF new_nodes_diff], simp+)\napply (simp add: last_conv_nth, case_tac ll, simp+)\napply (case_tac list, simp+)\napply (erule_tac x=\"pl ! Suc i\" in allE, erule impE)\napply (rule_tac x=\"Suc i\" in exI, simp add: nth_butlast)\napply (clarsimp simp add: out_edges_def rep_edges_def remap_succ_def)\napply (rule conjI, clarsimp, case_tac \"length ll - 1\", simp, simp add: Let_def)\napply (subgoal_tac \"new (nodes CFGs) (length ll - Suc 0) ! i \\<noteq>\n  last (new (nodes CFGs) (length ll - Suc 0))\", simp)\napply (clarsimp intro!: ext simp add: edge_types_def, rule conjI, clarsimp)\napply (rule_tac s=\"{new (nodes CFGs) (length ll - Suc 0) ! Suc i}\" in subst, simp_all, rule set_eqI,\n  rule iffI, clarsimp)\napply (erule_tac x=\"Suc i\" and P=\"\\<lambda>ab. new (nodes CFGs) (length ll - Suc 0) ! ab = \n  new (nodes CFGs) (length ll - Suc 0) ! Suc i \\<longrightarrow> (l # new (nodes CFGs)\n       (length ll - Suc 0)) ! ab = new (nodes CFGs) (length ll - Suc 0) ! i \n        \\<longrightarrow> \\<not> Suc ab < length ll\" in allE, clarsimp+)\napply (erule disjE, clarsimp)\napply (drule pointed_graph.edges_ok, simp, clarsimp)\napply (cut_tac S=\"nodes CFGs\" and m=\"new (nodes CFGs) (length ll - 1) ! i\" in new_nodes_are_new, \n  simp+)\napply (force simp add: set_conv_nth)\napply (metis (hide_lams, no_types) One_nat_def nodes_by_graph)\napply clarsimp\napply (case_tac a, simp+)\napply (cut_tac S1=\"nodes CFGs\" and i=nat and j=i and n1=\"length ll - 1\" in \n  nth_eq_iff_index_eq [OF new_nodes_diff], simp+)\napply clarsimp\napply (rule_tac s=\"{}\" in subst, simp_all, clarsimp)\napply (drule pointed_graph.edges_ok, simp, clarsimp)\napply (cut_tac S=\"nodes CFGs\" and m=\"new (nodes CFGs) (length ll - 1) ! i\" in new_nodes_are_new, \n  simp+)\napply (force simp add: set_conv_nth)\napply (metis (hide_lams, no_types) One_nat_def nodes_by_graph)\napply (case_tac \"new (nodes CFGs) (length ll - Suc 0) = []\", case_tac \"length ll - 1\", simp, \n  simp add: Let_def)\napply (clarsimp simp add: last_conv_nth)\napply (cut_tac S1=\"nodes CFGs\" and i=i and j=\"length ll - (Suc (Suc 0))\" and n1=\"length ll - 1\" in \n  nth_eq_iff_index_eq [OF new_nodes_diff], simp+)\napply (clarsimp simp add: rep_edges_def remap_succ_def, rule conjI, clarsimp)\napply (case_tac \"length ll - 1\", simp, simp add: Let_def)\napply (clarsimp, (rule conjI, clarsimp)+)\napply (drule pointed_graph.edges_ok, simp, clarsimp)\napply (cut_tac S=\"nodes CFGs\" and m=\"last (new (nodes CFGs) (length ll - 1))\" in new_nodes_are_new, \n  simp+, rule last_in_set, simp+, force)\napply clarsimp+\napply (case_tac a, clarsimp+)\napply (cut_tac S1=\"nodes CFGs\" and i=nat and j=\"Suc nat\" and n1=\"length ll - 1\" in \n  nth_eq_iff_index_eq [OF new_nodes_diff], simp+)\napply (rule conjI, clarsimp)\napply (cut_tac S=\"nodes CFGs\" in new_nodes_are_new, simp+)\napply (rule new_nodes_diff, simp+)\n(* tCFG axioms *)\napply (clarsimp split: if_splits)\napply (erule disjE, cut_tac disjoint, simp_all, simp add: Int_def)\napply (cut_tac S=\"nodes CFGs\" in new_nodes_are_new, simp+, simp add: nodes_by_graph)\napply (erule disjE, cut_tac disjoint, simp_all, simp add: Int_def)\napply (cut_tac S=\"nodes CFGs\" in new_nodes_are_new, simp+, simp add: nodes_by_graph)\napply (cut_tac disjoint, simp_all, simp add: Int_def)\ndone\nqed\n\nlemma apply_some_transfer [rule_format]: \"\\<lbrakk>P G; \\<forall>\\<tau> G G'. G' \\<in> T \\<tau> G \\<longrightarrow> P G \\<longrightarrow> P G'; apply_some T \\<tau> G G'\\<rbrakk> \\<Longrightarrow>\n  P G'\"\nby (drule_tac P=\"\\<lambda>T' \\<tau> G G'. T' = T \\<and> P G \\<longrightarrow> P G'\" in apply_some.induct, auto)\n\nlemma action_disjoint: \"\\<lbrakk>action_sf a \\<sigma> G = Some G'; pre_tCFG G\\<rbrakk> \\<Longrightarrow> pre_tCFG G'\"\napply (frule pre_tCFG.nodes_finite)\napply (case_tac a, auto split: if_splits option.splits simp add: Let_def intro!: pre_tCFG.disjoint_change)\napply (frule pre_tCFG.graphs, simp, clarsimp simp add: pointed_graph_def)\napply (rule conjI, metis)\napply (rule conjI, metis starts_by_graph)\napply (rule conjI, metis exits_by_graph)\napply (simp add: in_edges_def out_edges_def)\napply (cut_tac S=\"nodes G\" in new_nodes_are_new, simp+)\napply (frule pre_tCFG.graphs, simp, clarsimp simp add: pointed_graph_def)\napply (rename_tac m pl l ll g)\napply (rule conjI, clarsimp simp add: rep_edges_def remap_succ_def)\napply (rule conjI, clarsimp)\napply (case_tac \"length ll - 1\", force, simp add: Let_def)\napply clarsimp\napply (erule disjE, force)\napply clarsimp\napply (case_tac aa, simp add: pre_tCFG.node_of_graph, simp)\napply (simp add: in_edges_def out_edges_def rep_edges_def remap_succ_def)\napply (rule conjI, clarsimp)\napply (case_tac \"length ll - 1\", force, simp add: Let_def)\napply (clarsimp, (rule conjI, clarsimp+)+)\napply (drule pre_tCFG.graphs, simp)\napply (simp, drule pointed_graph.has_start, cut_tac S=\"nodes G\" and n=\"length ll - Suc 0\" \n  in new_nodes_are_new, simp+)\napply (simp add: set_conv_nth, rule_tac x=aa in exI, simp)\napply (simp add: nodes_by_graph)\napply (clarsimp, (rule conjI, clarsimp+)+)\napply (drule pre_tCFG.graphs, simp+)\napply (drule pointed_graph.has_exit, cut_tac S=\"nodes G\" and n=\"length ll - Suc 0\"\n  in new_nodes_are_new, simp+)\napply (rule last_in_set, simp+)\napply (simp add: nodes_by_graph)\napply force\napply clarsimp\napply (case_tac aa, simp add: exits_by_graph)\napply (drule pre_tCFG.graphs, simp+)\napply (drule pointed_graph.has_exit, cut_tac S=\"nodes G\" and n=\"length ll - Suc 0\"\n  in new_nodes_are_new, simp+)\napply (simp add: set_conv_nth, rule_tac x=nat in exI, simp)\napply (simp add: nodes_by_graph)\napply (frule pre_tCFG.graphs, simp, clarsimp simp add: pointed_graph_def)\napply (rule conjI, metis)\napply (simp add: in_edges_def out_edges_def)\napply (frule pre_tCFG.graphs, simp, clarsimp simp add: pointed_graph_def)\napply (rule conjI, clarsimp simp add: exits_by_graph)\napply (clarsimp simp add: in_edges_def out_edges_def)\napply (metis pre_tCFG.node_of_graph starts_by_graph)\napply (cut_tac A=\"nodes G\" in fresh_new, simp+)\napply (frule pre_tCFG.graphs, simp, clarsimp simp add: pointed_graph_def)\napply (cut_tac A=\"nodes G\" in fresh_new, simp+)\napply (rule conjI, clarsimp simp add: nodes_by_graph, clarsimp simp add: out_edges_def)\napply (rename_tac n m e i u v ty j g)\napply (rule conjI, clarsimp simp add: edges_def ran_def)\napply (frule_tac t=aa in pre_tCFG.graphs, simp+, drule pointed_graph.edges_ok, simp+)\napply (case_tac \"aa = thread_of (Exit g) G\", simp+)\napply (drule pre_tCFG.disjoint, simp_all, simp add: Int_def)\napply (clarsimp simp add: edges_def ran_def)\napply (frule_tac t=aa in pre_tCFG.graphs, simp+, drule pointed_graph.edges_ok, simp+)\napply (simp add: pre_tCFG.thread_of_correct)\napply (clarsimp, rule conjI, metis)\napply (clarsimp simp add: in_edges_def)\napply (rule conjI, clarsimp simp add: nodes_by_graph, clarsimp)\ndone\n\nlemma actions_disjoint: \"\\<lbrakk>action_list_sf list \\<sigma> G = Some G'; pre_tCFG G\\<rbrakk> \\<Longrightarrow> pre_tCFG G'\"\napply (induct list arbitrary: G G', simp_all add: action_list_sf_def split: option.splits)\napply (drule action_disjoint, simp+)\ndone\n\nlemma trans_disjoint: \"\\<lbrakk>G' \\<in> trans_sf T \\<tau> G; pre_tCFG G\\<rbrakk> \\<Longrightarrow> pre_tCFG G'\"\napply (induct T arbitrary: \\<tau> G G', simp_all, clarsimp)\napply (drule sym, drule actions_disjoint, simp+)\napply auto\napply (cut_tac P=pre_tCFG and T=\"trans_sf T\" in apply_some_transfer, force, simp+)+\ndone\n\nend\n\nlemma option_if1 [simp]: \"((if P then None else x) = Some y) = (\\<not>P \\<and> x = Some y)\"\nby simp\n\nlemma option_if2: \"((if P then x else None) = Some y) = (P \\<and> x = Some y)\"\nby simp\n\nlemma part_extend_matches: \"\\<lbrakk>part_matches \\<sigma>' (part_extend \\<tau> S \\<sigma>); x \\<in> S\\<rbrakk> \\<Longrightarrow> \\<sigma>' x = \\<sigma> x\"\nby (simp add: part_matches_def part_extend_def)\n\nlemma option_Some1: \"((case a of None \\<Rightarrow> None | Some b \\<Rightarrow> f b) = Some c) = \n  (\\<exists>b. a = Some b \\<and> f b = Some c)\"\nby (auto split: option.splits)\n\nlemma option_Some2: \"(Some c = (case a of None \\<Rightarrow> None | Some b \\<Rightarrow> f b)) = \n  (\\<exists>b. a = Some b \\<and> f b = Some c)\"\nby (auto split: option.splits)\n\nend", "meta": {"author": "liyili2", "repo": "timed-relaxed-memory-model", "sha": "6d85bc75d8b04228b3e581b945e3f672395f0c66", "save_path": "github-repos/isabelle/liyili2-timed-relaxed-memory-model", "path": "github-repos/isabelle/liyili2-timed-relaxed-memory-model/timed-relaxed-memory-model-6d85bc75d8b04228b3e581b945e3f672395f0c66/trans_semantics.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6261241772283034, "lm_q2_score": 0.42250463481418826, "lm_q1q2_score": 0.2645403668481784}}
{"text": "theory Primitive_Abstract\nimports\n  Common_Primitive_toString\n  Transform\n  Conntrack_State_Transform\nbegin\n\nsection\\<open>Abstracting over Primitives\\<close>\n\n\n\ntext\\<open>Abstract over certain primitives. The first parameter is a function\n  @{typ \"'i::len common_primitive negation_type \\<Rightarrow> bool\"} to select the primitives to be abstracted over.\n  The @{typ \"'i::len common_primitive\"} is wrapped in a @{typ \"'i::len common_primitive negation_type\"} to let the function\n  selectively abstract only over negated, non-negated, or both kinds of primitives.\n  This functions requires a @{const normalized_nnf_match}.\n\\<close>\n(*requires toString function!*)\nfun abstract_primitive\n  :: \"('i::len common_primitive negation_type \\<Rightarrow> bool) \\<Rightarrow> 'i common_primitive match_expr \\<Rightarrow> 'i common_primitive match_expr\"\nwhere\n  \"abstract_primitive _     MatchAny = MatchAny\" |\n  \"abstract_primitive disc (Match a) =\n      (if\n         disc (Pos a)\n       then\n         Match (Extra (common_primitive_toString ipaddr_generic_toString a))\n       else\n         (Match a))\" |\n  \"abstract_primitive disc (MatchNot (Match a)) =\n      (if\n         disc (Neg a)\n       then\n         Match (Extra (''! ''@common_primitive_toString ipaddr_generic_toString a))\n       else\n         (MatchNot (Match a)))\" |\n  \"abstract_primitive disc (MatchNot m) = MatchNot (abstract_primitive disc m)\" |\n  \"abstract_primitive disc (MatchAnd m1 m2) = MatchAnd (abstract_primitive disc m1) (abstract_primitive disc m2)\"\n\n\ntext\\<open>For example, a simple firewall requires that no negated interfaces and protocols occur in the \n      expression.\\<close>\ndefinition abstract_for_simple_firewall :: \"'i::len common_primitive match_expr \\<Rightarrow> 'i common_primitive match_expr\"\n  where \"abstract_for_simple_firewall \\<equiv> abstract_primitive (\\<lambda>r. case r\n                of Pos a \\<Rightarrow> is_CT_State a \\<or> is_L4_Flags a\n                |  Neg a \\<Rightarrow> is_Iiface a \\<or> is_Oiface a \\<or> is_Prot a \\<or> is_CT_State a \\<or> is_L4_Flags a)\"\n\n\nlemma abstract_primitive_preserves_normalized:\n  \"normalized_src_ports m \\<Longrightarrow> normalized_src_ports (abstract_primitive disc m)\"\n  \"normalized_dst_ports m \\<Longrightarrow> normalized_dst_ports (abstract_primitive disc m)\"\n  \"normalized_src_ips m \\<Longrightarrow> normalized_src_ips (abstract_primitive disc m)\"\n  \"normalized_dst_ips m \\<Longrightarrow> normalized_dst_ips (abstract_primitive disc m)\"\n  \"normalized_nnf_match m \\<Longrightarrow> normalized_nnf_match (abstract_primitive disc m)\"\n  by(induction disc m rule: abstract_primitive.induct) (simp_all)\nlemma abstract_primitive_preserves_nodisc:\n  \"\\<not> has_disc disc' m \\<Longrightarrow> (\\<forall>str. \\<not> disc' (Extra str)) \\<Longrightarrow> \\<not> has_disc disc' (abstract_primitive disc m)\"\n  by(induction disc m rule: abstract_primitive.induct)(simp_all)\nlemma abstract_primitive_preserves_nodisc_nedgated:\n  \"\\<not> has_disc_negated disc' neg m \\<Longrightarrow> (\\<forall>str. \\<not> disc' (Extra str)) \\<Longrightarrow> \\<not> has_disc_negated disc' neg (abstract_primitive disc m)\"\n  by(induction disc m arbitrary: neg rule: abstract_primitive.induct) simp+\n\nlemma abstract_primitive_nodisc:\n  \"\\<forall>x. disc' x \\<longrightarrow> disc (Pos x) \\<and> disc (Neg x)  \\<Longrightarrow> (\\<forall>str. \\<not> disc' (Extra str)) \\<Longrightarrow> \\<not> has_disc disc' (abstract_primitive disc m)\"\n  by(induction disc m rule: abstract_primitive.induct) auto\n  \nlemma abstract_primitive_preserves_not_has_disc_negated:\n  \"\\<forall>a. \\<not> disc (Extra a)\\<Longrightarrow> \\<not> has_disc_negated disc neg m \\<Longrightarrow> \\<not> has_disc_negated disc neg (abstract_primitive sel_f m)\"\nby(induction sel_f m arbitrary: neg rule: abstract_primitive.induct) simp+\n\nlemma abstract_for_simple_firewall_preserves_nodisc_negated:\n  \"\\<forall>a. \\<not> disc (Extra a)\\<Longrightarrow> \\<not> has_disc_negated disc False m \\<Longrightarrow> \\<not> has_disc_negated disc False (abstract_for_simple_firewall m)\"\nunfolding abstract_for_simple_firewall_def\nusing abstract_primitive_preserves_nodisc_nedgated by blast\n\ntext\\<open>The function @{const ctstate_assume_state} can be used to fix a state and hence remove all state matches from the ruleset.\n      It is therefore advisable to create a simple firewall for a fixed state, e.g. with @{const ctstate_assume_new} before\n      calling to @{const abstract_for_simple_firewall}.\\<close>\nlemma not_hasdisc_ctstate_assume_state: \"\\<not> has_disc is_CT_State (ctstate_assume_state s m)\"\n  by(induction m rule: ctstate_assume_state.induct) (simp_all)\n\n\nlemma abstract_for_simple_firewall_hasdisc: fixes m :: \"'i::len common_primitive match_expr\"\n  shows \"\\<not> has_disc is_CT_State (abstract_for_simple_firewall m)\"\n  and   \"\\<not> has_disc is_L4_Flags (abstract_for_simple_firewall m)\"\n  unfolding abstract_for_simple_firewall_def\n  apply(induction \"(\\<lambda>r:: 'i common_primitive negation_type. case r of Pos a \\<Rightarrow> is_CT_State a | Neg a \\<Rightarrow> is_Iiface a \\<or> is_Oiface a \\<or> is_Prot a \\<or> is_CT_State a)\" m rule: abstract_primitive.induct)\n  apply(simp_all)\n  done\n\nlemma abstract_for_simple_firewall_negated_ifaces_prots: fixes m :: \"'i::len common_primitive match_expr\"\n  shows  \"normalized_nnf_match m \\<Longrightarrow> \\<not> has_disc_negated (\\<lambda>a. is_Iiface a \\<or> is_Oiface a) False (abstract_for_simple_firewall m)\"\n  and \"normalized_nnf_match m \\<Longrightarrow> \\<not> has_disc_negated is_Prot False (abstract_for_simple_firewall m)\"\n  unfolding abstract_for_simple_firewall_def\n  apply(induction \"(\\<lambda>r:: 'i common_primitive negation_type. case r of Pos a \\<Rightarrow> is_CT_State a | Neg a \\<Rightarrow> is_Iiface a \\<or> is_Oiface a \\<or> is_Prot a \\<or> is_CT_State a)\" m rule: abstract_primitive.induct)\n  apply(simp_all)\n  done\n\n\ncontext\nbegin\n  private lemma abstract_primitive_in_doubt_allow_Allow: \n    \"primitive_matcher_generic \\<beta> \\<Longrightarrow> normalized_nnf_match m \\<Longrightarrow> \n      matches (\\<beta>, in_doubt_allow) m action.Accept p \\<Longrightarrow>\n      matches (\\<beta>, in_doubt_allow) (abstract_primitive disc m) action.Accept p\"\n     by(induction disc m rule: abstract_primitive.induct)\n       (simp_all add: bunch_of_lemmata_about_matches(1) primitive_matcher_generic.Extra_single)\n  \n  private lemma abstract_primitive_in_doubt_allow_Allow2: \n    \"primitive_matcher_generic \\<beta> \\<Longrightarrow> normalized_nnf_match m \\<Longrightarrow> \n      \\<not> matches (\\<beta>, in_doubt_allow) m action.Drop p \\<Longrightarrow>\n      \\<not> matches (\\<beta>, in_doubt_allow) (abstract_primitive disc m) action.Drop p\"\n     proof(induction disc m rule: abstract_primitive.induct)\n     case(5 m1 m2) thus ?case by (auto simp add: bunch_of_lemmata_about_matches(1))\n     qed(simp_all add: bunch_of_lemmata_about_matches(1) primitive_matcher_generic.Extra_single)\n\n  private lemma abstract_primitive_in_doubt_allow_Deny: \n    \"primitive_matcher_generic \\<beta> \\<Longrightarrow> normalized_nnf_match m \\<Longrightarrow>\n      matches (\\<beta>, in_doubt_allow) (abstract_primitive disc m) action.Drop p \\<Longrightarrow>\n      matches (\\<beta>, in_doubt_allow) m action.Drop p\"\n     apply(induction disc m rule: abstract_primitive.induct)\n           apply (simp_all add: bunch_of_lemmata_about_matches(1))\n       apply(auto simp add: primitive_matcher_generic.Extra_single primitive_matcher_generic.Extra_single_not split: if_split_asm)\n     done\n  \n  private lemma abstract_primitive_in_doubt_allow_Deny2: \n    \"primitive_matcher_generic \\<beta> \\<Longrightarrow> normalized_nnf_match m \\<Longrightarrow> \n      \\<not> matches (\\<beta>, in_doubt_allow) (abstract_primitive disc m) action.Accept p \\<Longrightarrow>\n      \\<not> matches (\\<beta>, in_doubt_allow) m action.Accept p\"\n     apply(induction disc m rule: abstract_primitive.induct)\n           apply (simp_all add: bunch_of_lemmata_about_matches(1))\n       apply(auto simp add: primitive_matcher_generic.Extra_single primitive_matcher_generic.Extra_single_not split: if_split_asm)\n     done\n  \n  theorem abstract_primitive_in_doubt_allow_generic:\n    fixes \\<beta>::\"('i::len common_primitive, ('i, 'a) tagged_packet_scheme) exact_match_tac\"\n    assumes generic: \"primitive_matcher_generic \\<beta>\"\n       and n: \"\\<forall> r \\<in> set rs. normalized_nnf_match (get_match r)\"\n       and simple: \"simple_ruleset rs\"\n    defines \"\\<gamma> \\<equiv> (\\<beta>, in_doubt_allow)\" and \"abstract disc \\<equiv> optimize_matches (abstract_primitive disc)\"\n    shows   \"{p. \\<gamma>,p\\<turnstile> \\<langle>abstract disc rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Decision FinalDeny} \\<subseteq> {p. \\<gamma>,p\\<turnstile> \\<langle>rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Decision FinalDeny}\"\n                (is ?deny)\n      and   \"{p. \\<gamma>,p\\<turnstile> \\<langle>rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Decision FinalAllow} \\<subseteq> {p. \\<gamma>,p\\<turnstile> \\<langle>abstract disc rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Decision FinalAllow}\"\n                (is ?allow)\n    proof -\n      from simple have \"good_ruleset rs\" using simple_imp_good_ruleset by fast\n      from optimize_matches_simple_ruleset simple simple_imp_good_ruleset have\n       good: \"good_ruleset (optimize_matches (abstract_primitive disc) rs)\" by fast\n\n      let ?\\<gamma>=\"(\\<beta>, in_doubt_allow) :: ('i::len common_primitive, ('i, 'a) tagged_packet_scheme) match_tac\"\n        --\\<open>type signature is needed, otherwise @{const in_doubt_allow} would be for arbitrary packet\\<close>\n\n      have abstract_primitive_in_doubt_allow_help1:\n        \"approximating_bigstep_fun \\<gamma> p (optimize_matches (abstract_primitive disc) rs) Undecided = Decision FinalAllow\"\n        if prem: \"approximating_bigstep_fun \\<gamma> p rs Undecided = Decision FinalAllow\" for p\n        proof -\n          from simple have \"wf_ruleset \\<gamma> p rs\" using good_imp_wf_ruleset simple_imp_good_ruleset by fast\n          from this simple prem n show ?thesis\n            unfolding \\<gamma>_def\n            proof(induction ?\\<gamma> p rs Undecided rule: approximating_bigstep_fun_induct_wf)\n            case (MatchAccept p m a rs)\n              from MatchAccept.prems\n                abstract_primitive_in_doubt_allow_Allow[OF generic] MatchAccept.hyps have\n                \"matches ?\\<gamma> (abstract_primitive disc m) action.Accept p\" by simp\n              thus ?case\n              apply(simp add: MatchAccept.hyps(2))\n              using optimize_matches_matches_fst by fastforce \n            next\n            case (Nomatch p m a rs) thus ?case\n              proof(cases \"matches ?\\<gamma> (abstract_primitive disc m) a p\")\n                case False with Nomatch show ?thesis\n                  apply(simp add: optimize_matches_def)\n                  using simple_ruleset_tail by blast\n                next\n                case True\n                  from Nomatch.prems(1) have \"a = action.Accept \\<or> a = action.Drop\" by(simp add: simple_ruleset_def)\n                  from Nomatch.hyps(1) Nomatch.prems(3) abstract_primitive_in_doubt_allow_Allow2[OF generic] have\n                    \"a = action.Drop \\<Longrightarrow> \\<not> matches ?\\<gamma> (abstract_primitive disc m) action.Drop p\" by simp\n                  with True \\<open>a = action.Accept \\<or> a = action.Drop\\<close> have \"a = action.Accept\" by blast\n                  with True show ?thesis\n                    using optimize_matches_matches_fst by fastforce \n                qed\n            qed(simp_all add: simple_ruleset_def)\n      qed\n\n      have abstract_primitive_in_doubt_allow_help2:\n        \"approximating_bigstep_fun \\<gamma> p rs Undecided = Decision FinalDeny\"\n        if prem: \"approximating_bigstep_fun \\<gamma> p (optimize_matches (abstract_primitive disc) rs) Undecided = Decision FinalDeny\"\n        for p\n        proof -\n          from simple have \"wf_ruleset \\<gamma> p rs\" using good_imp_wf_ruleset simple_imp_good_ruleset by fast\n          from this simple prem n show ?thesis\n            unfolding \\<gamma>_def\n            proof(induction ?\\<gamma> p rs Undecided rule: approximating_bigstep_fun_induct_wf)\n            case Empty thus ?case by(simp add: optimize_matches_def)\n            next\n            case (MatchAccept p m a rs)\n              from MatchAccept.prems abstract_primitive_in_doubt_allow_Allow[OF generic] MatchAccept.hyps have\n                1: \"matches ?\\<gamma> (abstract_primitive disc m) action.Accept p\" by simp\n              with MatchAccept have \"approximating_bigstep_fun ?\\<gamma> p\n                (Rule (abstract_primitive disc m) action.Accept # (optimize_matches (abstract_primitive disc) rs)) Undecided = Decision FinalDeny\"\n                using optimize_matches_matches_fst by metis\n              with 1 have False by(simp)\n              thus ?case ..\n            next\n            case (Nomatch p m a rs) thus ?case\n              proof(cases \"matches ?\\<gamma> (abstract_primitive disc m) a p\")\n                case False\n                with Nomatch.prems(2) have \"approximating_bigstep_fun ?\\<gamma> p (optimize_matches (abstract_primitive disc) rs) Undecided = Decision FinalDeny\"\n                  by(simp add: optimize_matches_def split: if_split_asm)\n                with Nomatch have IH: \"approximating_bigstep_fun ?\\<gamma> p rs Undecided = Decision FinalDeny\"\n                  using simple_ruleset_tail by auto\n                with Nomatch(1) show ?thesis by simp\n                next\n                case True\n                  from Nomatch.prems(2) True have 1: \"approximating_bigstep_fun ?\\<gamma> p\n                    (Rule (abstract_primitive disc m) a # (optimize_matches (abstract_primitive disc) rs)) Undecided = Decision FinalDeny\"\n                    using optimize_matches_matches_fst by metis\n                    \n                  from Nomatch.prems(1) have \"a = action.Accept \\<or> a = action.Drop\" by(simp add: simple_ruleset_def)\n                  from Nomatch.hyps(1) Nomatch.prems(3) abstract_primitive_in_doubt_allow_Allow2[OF generic] have\n                    \"a = action.Drop \\<Longrightarrow> \\<not> matches ?\\<gamma> (abstract_primitive disc m) action.Drop p\" by simp\n                  with True \\<open>a = action.Accept \\<or> a = action.Drop\\<close> have \"a = action.Accept\" by blast\n                  with 1 True have False by simp\n                  thus ?thesis ..\n                qed\n            qed(simp_all add: simple_ruleset_def)\n      qed\n  \n      from good approximating_semantics_iff_fun_good_ruleset abstract_primitive_in_doubt_allow_help1 \\<open>good_ruleset rs\\<close> show ?allow\n        unfolding abstract_def by fast\n      from good approximating_semantics_iff_fun_good_ruleset abstract_primitive_in_doubt_allow_help2 \\<open>good_ruleset rs\\<close> \\<gamma>_def show ?deny \n        unfolding abstract_def by fast\n    qed\n  corollary abstract_primitive_in_doubt_allow:\n    assumes \"\\<forall> r \\<in> set rs. normalized_nnf_match (get_match r)\" and \"simple_ruleset rs\"\n    defines \"\\<gamma> \\<equiv> (common_matcher, in_doubt_allow)\" and \"abstract disc \\<equiv> optimize_matches (abstract_primitive disc)\"\n    shows   \"{p. \\<gamma>,p\\<turnstile> \\<langle>abstract disc rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Decision FinalDeny} \\<subseteq> {p. \\<gamma>,p\\<turnstile> \\<langle>rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Decision FinalDeny}\"\n      and   \"{p. \\<gamma>,p\\<turnstile> \\<langle>rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Decision FinalAllow} \\<subseteq> {p. \\<gamma>,p\\<turnstile> \\<langle>abstract disc rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Decision FinalAllow}\"\n    unfolding \\<gamma>_def abstract_def\n    using assms abstract_primitive_in_doubt_allow_generic[OF primitive_matcher_generic_common_matcher] by blast+\nend\n\n\ncontext\nbegin\n  private lemma abstract_primitive_in_doubt_deny_Deny:\n    \"primitive_matcher_generic \\<beta> \\<Longrightarrow> normalized_nnf_match m \\<Longrightarrow> \n      matches (\\<beta>, in_doubt_deny) m action.Drop p \\<Longrightarrow>\n      matches (\\<beta>, in_doubt_deny) (abstract_primitive disc m) action.Drop p\"\n     by(induction disc m rule: abstract_primitive.induct)\n       (simp_all add: bunch_of_lemmata_about_matches(1) primitive_matcher_generic.Extra_single)\n  \n  private lemma abstract_primitive_in_doubt_deny_Deny2:\n    \"primitive_matcher_generic \\<beta> \\<Longrightarrow> normalized_nnf_match m \\<Longrightarrow> \n      \\<not> matches (\\<beta>, in_doubt_deny) m action.Accept p \\<Longrightarrow>\n      \\<not> matches (\\<beta>, in_doubt_deny) (abstract_primitive disc m) action.Accept p\"\n     proof(induction disc m rule: abstract_primitive.induct)\n     case(5 m1 m2) thus ?case by (auto simp add: bunch_of_lemmata_about_matches(1))\n     qed(simp_all add: bunch_of_lemmata_about_matches(1) primitive_matcher_generic.Extra_single)\n  \n  private lemma abstract_primitive_in_doubt_deny_Allow: \n    \"primitive_matcher_generic \\<beta> \\<Longrightarrow> normalized_nnf_match m \\<Longrightarrow>\n      matches (\\<beta>, in_doubt_deny) (abstract_primitive disc m) action.Accept p \\<Longrightarrow>\n      matches (\\<beta>, in_doubt_deny) m action.Accept p\"\n     apply(induction disc m rule: abstract_primitive.induct)\n           apply (simp_all add: bunch_of_lemmata_about_matches(1))\n       apply(auto simp add: primitive_matcher_generic.Extra_single primitive_matcher_generic.Extra_single_not split: if_split_asm)\n     done\n  \n  private lemma abstract_primitive_in_doubt_deny_Allow2: \n    \"primitive_matcher_generic \\<beta> \\<Longrightarrow> normalized_nnf_match m \\<Longrightarrow> \n      \\<not> matches (\\<beta>, in_doubt_deny) (abstract_primitive disc m) action.Drop p \\<Longrightarrow>\n      \\<not> matches (\\<beta>, in_doubt_deny) m action.Drop p\"\n     apply(induction disc m rule: abstract_primitive.induct)\n           apply (simp_all add: bunch_of_lemmata_about_matches(1))\n       apply(auto simp add: primitive_matcher_generic.Extra_single primitive_matcher_generic.Extra_single_not split: if_split_asm)\n     done\n\n  theorem abstract_primitive_in_doubt_deny_generic:\n    fixes \\<beta>::\"('i::len common_primitive, ('i, 'a) tagged_packet_scheme) exact_match_tac\"\n    assumes generic: \"primitive_matcher_generic \\<beta>\"\n        and n: \"\\<forall> r \\<in> set rs. normalized_nnf_match (get_match r)\"\n        and simple: \"simple_ruleset rs\"\n    defines \"\\<gamma> \\<equiv> (\\<beta>, in_doubt_deny)\" and \"abstract disc \\<equiv> optimize_matches (abstract_primitive disc)\"\n    shows   \"{p. \\<gamma>,p\\<turnstile> \\<langle>abstract disc rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Decision FinalAllow} \\<subseteq> {p. \\<gamma>,p\\<turnstile> \\<langle>rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Decision FinalAllow}\"\n             (is ?allow)\n    and     \"{p. \\<gamma>,p\\<turnstile> \\<langle>rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Decision FinalDeny} \\<subseteq> {p. \\<gamma>,p\\<turnstile> \\<langle>abstract disc rs, Undecided\\<rangle> \\<Rightarrow>\\<^sub>\\<alpha> Decision FinalDeny}\"\n             (is ?deny)\n    proof -\n      from simple have \"good_ruleset rs\" using simple_imp_good_ruleset by fast\n      from optimize_matches_simple_ruleset simple simple_imp_good_ruleset have\n        good: \"good_ruleset (optimize_matches (abstract_primitive disc) rs)\" by fast\n\n      let ?\\<gamma>=\"(\\<beta>, in_doubt_deny) :: ('i::len common_primitive, ('i, 'a) tagged_packet_scheme) match_tac\"\n        --\\<open>type signature is needed, otherwise @{const in_doubt_allow} would be for arbitrary packet\\<close>\n      \n      have abstract_primitive_in_doubt_deny_help1:\n        \"approximating_bigstep_fun \\<gamma> p (optimize_matches (abstract_primitive disc) rs) Undecided = Decision FinalDeny\"\n        if prem: \"approximating_bigstep_fun \\<gamma> p rs Undecided = Decision FinalDeny\" for p\n        proof -\n          from simple have \"wf_ruleset \\<gamma> p rs\" using good_imp_wf_ruleset simple_imp_good_ruleset by fast\n          from this simple prem n show ?thesis\n            unfolding \\<gamma>_def\n            proof(induction ?\\<gamma> p rs Undecided rule: approximating_bigstep_fun_induct_wf)\n            case (MatchDrop p m a rs)\n              from MatchDrop.prems abstract_primitive_in_doubt_deny_Deny[OF generic] MatchDrop.hyps have\n                \"matches ?\\<gamma> (abstract_primitive disc m) action.Drop p\" by simp\n              thus ?case \n              apply(simp add: MatchDrop.hyps(2))\n              using optimize_matches_matches_fst by fastforce\n            next\n            case (Nomatch p m a rs) thus ?case\n              proof(cases \"matches ?\\<gamma> (abstract_primitive disc m) a p\")\n                case False with Nomatch show ?thesis\n                  apply(simp add: optimize_matches_def)\n                  using simple_ruleset_tail by blast\n                next\n                case True\n                  from Nomatch.prems(1) have \"a = action.Accept \\<or> a = action.Drop\" by(simp add: simple_ruleset_def)\n                  from Nomatch.hyps(1) Nomatch.prems(3) abstract_primitive_in_doubt_deny_Deny2[OF generic] have\n                    \"a = action.Accept \\<Longrightarrow> \\<not> matches ?\\<gamma> (abstract_primitive disc m) action.Accept p\" by(simp)\n                  with True \\<open>a = action.Accept \\<or> a = action.Drop\\<close> have \"a = action.Drop\" by blast\n                  with True show ?thesis using optimize_matches_matches_fst by fastforce\n                qed\n            qed(simp_all add: simple_ruleset_def)\n      qed\n\n      have abstract_primitive_in_doubt_deny_help2:\n        \"approximating_bigstep_fun \\<gamma> p rs Undecided = Decision FinalAllow\"\n        if prem: \"approximating_bigstep_fun \\<gamma> p (optimize_matches (abstract_primitive disc) rs) Undecided = Decision FinalAllow\"\n        for p\n        proof -\n          from simple have \"wf_ruleset ?\\<gamma> p rs\" using good_imp_wf_ruleset simple_imp_good_ruleset by fast\n          from this simple prem n show ?thesis\n            unfolding \\<gamma>_def\n            proof(induction ?\\<gamma> p rs Undecided rule: approximating_bigstep_fun_induct_wf)\n            case Empty thus ?case by(simp add: optimize_matches_def)\n            next\n            case (MatchAccept p m a rs) thus ?case by auto\n            next\n            case (MatchDrop p m a rs)\n              from MatchDrop.prems abstract_primitive_in_doubt_deny_Deny[OF generic] MatchDrop.hyps have\n                1: \"matches ?\\<gamma> (abstract_primitive disc m) action.Drop p\" by simp\n              from MatchDrop have \"approximating_bigstep_fun ?\\<gamma> p\n                (Rule (abstract_primitive disc m) action.Drop # (optimize_matches (abstract_primitive disc) rs)) Undecided = Decision FinalAllow\"\n              using optimize_matches_matches_fst 1 by fastforce\n              with 1 have False by(simp)\n              thus ?case ..\n            next\n            case (Nomatch p m a rs) thus ?case\n              proof(cases \"matches ?\\<gamma> (abstract_primitive disc m) a p\")\n                case False \n                with Nomatch.prems(2) have \"approximating_bigstep_fun ?\\<gamma> p (optimize_matches (abstract_primitive disc) rs) Undecided = Decision FinalAllow\"\n                  by(simp add: optimize_matches_def split: if_split_asm)\n                with Nomatch have IH: \"approximating_bigstep_fun ?\\<gamma> p rs Undecided = Decision FinalAllow\"\n                  using simple_ruleset_tail by auto\n                with Nomatch(1) show ?thesis by simp\n                next\n                case True\n                  from Nomatch.prems(2) True have 1: \"approximating_bigstep_fun ?\\<gamma> p\n                    (Rule (abstract_primitive disc m) a # (optimize_matches (abstract_primitive disc) rs)) Undecided = Decision FinalAllow\"\n                    using optimize_matches_matches_fst by metis\n                  from Nomatch.prems(1) have \"a = action.Accept \\<or> a = action.Drop\" by(simp add: simple_ruleset_def)\n                  from Nomatch.hyps(1) Nomatch.prems(3) abstract_primitive_in_doubt_deny_Deny2[OF generic] have\n                    \"a = action.Accept \\<Longrightarrow> \\<not> matches ?\\<gamma> (abstract_primitive disc m) action.Accept p\" by simp\n                  with True \\<open>a = action.Accept \\<or> a = action.Drop\\<close> have \"a = action.Drop\" by blast\n                  with 1 True have False by force\n                  thus ?thesis ..\n                qed\n            qed(simp_all add: simple_ruleset_def)\n      qed\n\n      from good approximating_semantics_iff_fun_good_ruleset abstract_primitive_in_doubt_deny_help1 \\<open>good_ruleset rs\\<close> show ?deny\n        unfolding abstract_def by fast\n      from good approximating_semantics_iff_fun_good_ruleset abstract_primitive_in_doubt_deny_help2 \\<open>good_ruleset rs\\<close> show ?allow\n        unfolding abstract_def by fast\n    qed\nend\n\n\n\nend", "meta": {"author": "diekmann", "repo": "Iptables_Semantics", "sha": "e0a2516bd885708fce875023b474ae341cbdee29", "save_path": "github-repos/isabelle/diekmann-Iptables_Semantics", "path": "github-repos/isabelle/diekmann-Iptables_Semantics/Iptables_Semantics-e0a2516bd885708fce875023b474ae341cbdee29/thy/Iptables_Semantics/Primitive_Matchers/Primitive_Abstract.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6261241772283033, "lm_q2_score": 0.4225046348141882, "lm_q1q2_score": 0.26454036684817833}}
{"text": "theory Mockup_Test_Abs_Sys\n  imports Abstract_System More_Eisbach_Tools\nbegin\n  typedecl state\n  typedecl program\n  typedecl location\n\n  consts step :: \"program \\<Rightarrow> state \\<Rightarrow> state\"\n  consts halted :: \"program \\<Rightarrow> state \\<Rightarrow> bool\"\n  consts location :: \"state \\<Rightarrow> location\"\n\n\n\n\n  definition \"stepse \\<pi> \\<equiv> doE { s\\<leftarrow>sget; sput (step \\<pi> s) }\"\n\n\n  global_interpretation det_system \"stepse \\<pi>\" \"halted \\<pi>\" for \\<pi>\n    defines yields = yields'\n    .\n\n  declare yields_unfold[code]\n\n  interpretation cfg_system \"stepse \\<pi>\" \"halted \\<pi>\" \"\\<lambda>_. True\" location\n    apply unfold_locales by (rule is_weak_invarI) simp\n\n\nmethod vcg_clarify = (intro impI conjI)?, (((rule exI, rule conjI, assumption)+ | (simp add: prep_precond_conv))+)?\nmethod vcg_step_aux = (rule wps_rls linvar_unfoldI, (assumption+)?); kbxfer?\nmethod vcg_step = vcg_clarify, vcg_step_aux\nmethod vcg = (vcg_step+, vcg_clarify)\n\n  term htriple\n\n  lemma \"htriple \\<pi> (\\<lambda>s. location s = foo) Q\"\n    apply (rule floyd_htripleI[where \\<Theta>=\"[\n      foo \\<mapsto> \\<lambda>s. \\<not> halted \\<pi> s \\<and> \\<Phi>\\<^sub>1 s,\n      bar \\<mapsto> \\<lambda>s. halted \\<pi> s \\<and> \\<Phi>\\<^sub>2 s,\n      bar2 \\<mapsto> \\<lambda>s. halted \\<pi> s \\<and> \\<Phi>\\<^sub>3 s\n      ]\"])\n\n    subgoal\n      apply (rule linvar_unfoldI)\n      apply simp\n      sorry\n\n    subgoal\n      apply (rule floyd_invarI)\n      apply (intro floyd_vcsI; (clarsimp simp: )?)\n\n      apply (subst stepse_def[abs_def])\n      apply (simp add: wps_eqs)\n\n      apply (rule linvar_unfoldI)\n      apply clarsimp apply (intro impI conjI; simp?)\n\n      prefer 16\n      apply (subst stepse_def[abs_def])\n      apply (simp add: wps_eqs)\n      sorry\n\n    subgoal for s\n      apply (clarsimp split: if_splits)\n      sorry\n\n    oops\n\n\n\n  term \"yields \\<pi>\"\n\n\n\n\n\nend\n\n", "meta": {"author": "ssrg-vt", "repo": "Luce-src", "sha": "f7f1ef0fd07bba48bcb3d5e32404db6013a5f1bc", "save_path": "github-repos/isabelle/ssrg-vt-Luce-src", "path": "github-repos/isabelle/ssrg-vt-Luce-src/Luce-src-f7f1ef0fd07bba48bcb3d5e32404db6013a5f1bc/tacas2020_artifact/isabelle/Monads/Mockup_Test_Abs_Sys.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.46101677931231594, "lm_q1q2_score": 0.2644753717647745}}
{"text": "(*  Title:      HOL/UNITY/Comp/AllocImpl.thy\n    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory\n    Copyright   1998  University of Cambridge\n*)\n\nsection{*Implementation of a multiple-client allocator from a single-client allocator*}\n\ntheory AllocImpl imports AllocBase \"../Follows\" \"../PPROD\" begin\n\n\n(** State definitions.  OUTPUT variables are locals **)\n\n(*Type variable 'b is the type of items being merged*)\nrecord 'b merge =\n  In   :: \"nat => 'b list\"  (*merge's INPUT histories: streams to merge*)\n  Out  :: \"'b list\"         (*merge's OUTPUT history: merged items*)\n  iOut :: \"nat list\"        (*merge's OUTPUT history: origins of merged items*)\n\nrecord ('a,'b) merge_d =\n  \"'b merge\" +\n  dummy :: 'a       (*dummy field for new variables*)\n\ndefinition non_dummy :: \"('a,'b) merge_d => 'b merge\" where\n    \"non_dummy s = (|In = In s, Out = Out s, iOut = iOut s|)\"\n\nrecord 'b distr =\n  In  :: \"'b list\"          (*items to distribute*)\n  iIn :: \"nat list\"         (*destinations of items to distribute*)\n  Out :: \"nat => 'b list\"   (*distributed items*)\n\nrecord ('a,'b) distr_d =\n  \"'b distr\" +\n  dummy :: 'a       (*dummy field for new variables*)\n\nrecord allocState =\n  giv :: \"nat list\"   (*OUTPUT history: source of tokens*)\n  ask :: \"nat list\"   (*INPUT: tokens requested from allocator*)\n  rel :: \"nat list\"   (*INPUT: tokens released to allocator*)\n\nrecord 'a allocState_d =\n  allocState +\n  dummy    :: 'a                (*dummy field for new variables*)\n\nrecord 'a systemState =\n  allocState +\n  mergeRel :: \"nat merge\"\n  mergeAsk :: \"nat merge\"\n  distr    :: \"nat distr\"\n  dummy    :: 'a                  (*dummy field for new variables*)\n\n\n(** Merge specification (the number of inputs is Nclients) ***)\n\ndefinition\n  (*spec (10)*)\n  merge_increasing :: \"('a,'b) merge_d program set\"\n  where \"merge_increasing =\n         UNIV guarantees (Increasing merge.Out) Int (Increasing merge.iOut)\"\n\ndefinition\n  (*spec (11)*)\n  merge_eqOut :: \"('a,'b) merge_d program set\"\n  where \"merge_eqOut =\n         UNIV guarantees\n         Always {s. length (merge.Out s) = length (merge.iOut s)}\"\n\ndefinition\n  (*spec (12)*)\n  merge_bounded :: \"('a,'b) merge_d program set\"\n  where \"merge_bounded =\n         UNIV guarantees\n         Always {s. \\<forall>elt \\<in> set (merge.iOut s). elt < Nclients}\"\n\ndefinition\n  (*spec (13)*)\n  merge_follows :: \"('a,'b) merge_d program set\"\n  where \"merge_follows =\n         (\\<Inter>i \\<in> lessThan Nclients. Increasing (sub i o merge.In))\n         guarantees\n         (\\<Inter>i \\<in> lessThan Nclients.\n          (%s. sublist (merge.Out s)\n                       {k. k < size(merge.iOut s) & merge.iOut s! k = i})\n          Fols (sub i o merge.In))\"\n\ndefinition\n  (*spec: preserves part*)\n  merge_preserves :: \"('a,'b) merge_d program set\"\n  where \"merge_preserves = preserves merge.In Int preserves merge_d.dummy\"\n\ndefinition\n  (*environmental constraints*)\n  merge_allowed_acts :: \"('a,'b) merge_d program set\"\n  where \"merge_allowed_acts =\n       {F. AllowedActs F =\n            insert Id (UNION (preserves (funPair merge.Out merge.iOut)) Acts)}\"\n\ndefinition\n  merge_spec :: \"('a,'b) merge_d program set\"\n  where \"merge_spec = merge_increasing Int merge_eqOut Int merge_bounded Int\n                   merge_follows Int merge_allowed_acts Int merge_preserves\"\n\n(** Distributor specification (the number of outputs is Nclients) ***)\n\ndefinition\n  (*spec (14)*)\n  distr_follows :: \"('a,'b) distr_d program set\"\n  where \"distr_follows =\n         Increasing distr.In Int Increasing distr.iIn Int\n         Always {s. \\<forall>elt \\<in> set (distr.iIn s). elt < Nclients}\n         guarantees\n         (\\<Inter>i \\<in> lessThan Nclients.\n          (sub i o distr.Out) Fols\n          (%s. sublist (distr.In s)\n                       {k. k < size(distr.iIn s) & distr.iIn s ! k = i}))\"\n\ndefinition\n  distr_allowed_acts :: \"('a,'b) distr_d program set\"\n  where \"distr_allowed_acts =\n       {D. AllowedActs D = insert Id (UNION (preserves distr.Out) Acts)}\"\n\ndefinition\n  distr_spec :: \"('a,'b) distr_d program set\"\n  where \"distr_spec = distr_follows Int distr_allowed_acts\"\n\n(** Single-client allocator specification (required) ***)\n\ndefinition\n  (*spec (18)*)\n  alloc_increasing :: \"'a allocState_d program set\"\n  where \"alloc_increasing = UNIV  guarantees  Increasing giv\"\n\ndefinition\n  (*spec (19)*)\n  alloc_safety :: \"'a allocState_d program set\"\n  where \"alloc_safety =\n         Increasing rel\n         guarantees  Always {s. tokens (giv s) \\<le> NbT + tokens (rel s)}\"\n\ndefinition\n  (*spec (20)*)\n  alloc_progress :: \"'a allocState_d program set\"\n  where \"alloc_progress =\n         Increasing ask Int Increasing rel Int\n         Always {s. \\<forall>elt \\<in> set (ask s). elt \\<le> NbT}\n         Int\n         (\\<Inter>h. {s. h \\<le> giv s & h pfixGe (ask s)}\n                 LeadsTo\n                 {s. tokens h \\<le> tokens (rel s)})\n         guarantees  (\\<Inter>h. {s. h \\<le> ask s} LeadsTo {s. h pfixLe giv s})\"\n\ndefinition\n  (*spec: preserves part*)\n  alloc_preserves :: \"'a allocState_d program set\"\n  where \"alloc_preserves = preserves rel Int\n                        preserves ask Int\n                        preserves allocState_d.dummy\"\n\n\ndefinition\n  (*environmental constraints*)\n  alloc_allowed_acts :: \"'a allocState_d program set\"\n  where \"alloc_allowed_acts =\n       {F. AllowedActs F = insert Id (UNION (preserves giv) Acts)}\"\n\ndefinition\n  alloc_spec :: \"'a allocState_d program set\"\n  where \"alloc_spec = alloc_increasing Int alloc_safety Int alloc_progress Int\n                   alloc_allowed_acts Int alloc_preserves\"\n\nlocale Merge =\n  fixes M :: \"('a,'b::order) merge_d program\"\n  assumes\n    Merge_spec:  \"M  \\<in> merge_spec\"\n\nlocale Distrib =\n  fixes D :: \"('a,'b::order) distr_d program\"\n  assumes\n    Distrib_spec:  \"D \\<in> distr_spec\"\n\n\n(****\n#  {** Network specification ***}\n\n#    {*spec (9.1)*}\n#    network_ask :: \"'a systemState program set\n#       \"network_ask == \\<Inter>i \\<in> lessThan Nclients.\n#                           Increasing (ask o sub i o client)\n#                           guarantees[ask]\n#                           (ask  Fols (ask o sub i o client))\"\n\n#    {*spec (9.2)*}\n#    network_giv :: \"'a systemState program set\n#       \"network_giv == \\<Inter>i \\<in> lessThan Nclients.\n#                           Increasing giv\n#                           guarantees[giv o sub i o client]\n#                           ((giv o sub i o client) Fols giv)\"\n\n#    {*spec (9.3)*}\n#    network_rel :: \"'a systemState program set\n#       \"network_rel == \\<Inter>i \\<in> lessThan Nclients.\n#                           Increasing (rel o sub i o client)\n#                           guarantees[rel]\n#                           (rel  Fols (rel o sub i o client))\"\n\n#    {*spec: preserves part*}\n#       network_preserves :: \"'a systemState program set\n#       \"network_preserves == preserves giv  Int\n#                             (\\<Inter>i \\<in> lessThan Nclients.\n#                              preserves (funPair rel ask o sub i o client))\"\n\n#    network_spec :: \"'a systemState program set\n#       \"network_spec == network_ask Int network_giv Int\n#                        network_rel Int network_preserves\"\n\n\n#  {** State mappings **}\n#    sysOfAlloc :: \"((nat => merge) * 'a) allocState_d => 'a systemState\"\n#       \"sysOfAlloc == %s. let (cl,xtr) = allocState_d.dummy s\n#                          in (| giv = giv s,\n#                                ask = ask s,\n#                                rel = rel s,\n#                                client   = cl,\n#                                dummy    = xtr|)\"\n\n\n#    sysOfClient :: \"(nat => merge) * 'a allocState_d => 'a systemState\"\n#       \"sysOfClient == %(cl,al). (| giv = giv al,\n#                                    ask = ask al,\n#                                    rel = rel al,\n#                                    client   = cl,\n#                                    systemState.dummy = allocState_d.dummy al|)\"\n****)\n\n\ndeclare subset_preserves_o [THEN subsetD, intro]\ndeclare funPair_o_distrib [simp]\ndeclare Always_INT_distrib [simp]\ndeclare o_apply [simp del]\n\n\nsubsection{*Theorems for Merge*}\n\ncontext Merge\nbegin\n\nlemma Merge_Allowed:\n     \"Allowed M = (preserves merge.Out) Int (preserves merge.iOut)\"\napply (cut_tac Merge_spec)\napply (auto simp add: merge_spec_def merge_allowed_acts_def Allowed_def\n                      safety_prop_Acts_iff)\ndone\n\nlemma M_ok_iff [iff]:\n     \"M ok G = (G \\<in> preserves merge.Out & G \\<in> preserves merge.iOut &\n                     M \\<in> Allowed G)\"\nby (auto simp add: Merge_Allowed ok_iff_Allowed)\n\n\nlemma Merge_Always_Out_eq_iOut:\n     \"[| G \\<in> preserves merge.Out; G \\<in> preserves merge.iOut; M \\<in> Allowed G |]\n      ==> M Join G \\<in> Always {s. length (merge.Out s) = length (merge.iOut s)}\"\napply (cut_tac Merge_spec)\napply (force dest: guaranteesD simp add: merge_spec_def merge_eqOut_def)\ndone\n\nlemma Merge_Bounded:\n     \"[| G \\<in> preserves merge.iOut; G \\<in> preserves merge.Out; M \\<in> Allowed G |]\n      ==> M Join G \\<in> Always {s. \\<forall>elt \\<in> set (merge.iOut s). elt < Nclients}\"\napply (cut_tac Merge_spec)\napply (force dest: guaranteesD simp add: merge_spec_def merge_bounded_def)\ndone\n\nlemma Merge_Bag_Follows_lemma:\n     \"[| G \\<in> preserves merge.iOut; G \\<in> preserves merge.Out; M \\<in> Allowed G |]\n  ==> M Join G \\<in> Always\n          {s. (\\<Sum>i \\<in> lessThan Nclients. bag_of (sublist (merge.Out s)\n                                  {k. k < length (iOut s) & iOut s ! k = i})) =\n              (bag_of o merge.Out) s}\"\napply (rule Always_Compl_Un_eq [THEN iffD1])\napply (blast intro: Always_Int_I [OF Merge_Always_Out_eq_iOut Merge_Bounded])\napply (rule UNIV_AlwaysI, clarify)\napply (subst bag_of_sublist_UN_disjoint [symmetric])\n  apply (simp)\n apply blast\napply (simp add: set_conv_nth)\napply (subgoal_tac\n       \"(\\<Union>i \\<in> lessThan Nclients. {k. k < length (iOut x) & iOut x ! k = i}) =\n       lessThan (length (iOut x))\")\n apply (simp (no_asm_simp) add: o_def)\napply blast\ndone\n\nlemma Merge_Bag_Follows:\n     \"M \\<in> (\\<Inter>i \\<in> lessThan Nclients. Increasing (sub i o merge.In))\n          guarantees\n             (bag_of o merge.Out) Fols\n             (%s. \\<Sum>i \\<in> lessThan Nclients. (bag_of o sub i o merge.In) s)\"\napply (rule Merge_Bag_Follows_lemma [THEN Always_Follows1, THEN guaranteesI], auto)\napply (rule Follows_setsum)\napply (cut_tac Merge_spec)\napply (auto simp add: merge_spec_def merge_follows_def o_def)\napply (drule guaranteesD)\n  prefer 3\n  apply (best intro: mono_bag_of [THEN mono_Follows_apply, THEN subsetD], auto)\ndone\n\nend\n\n\nsubsection{*Theorems for Distributor*}\n\ncontext Distrib\nbegin\n\nlemma Distr_Increasing_Out:\n     \"D \\<in> Increasing distr.In Int Increasing distr.iIn Int\n          Always {s. \\<forall>elt \\<in> set (distr.iIn s). elt < Nclients}\n          guarantees\n          (\\<Inter>i \\<in> lessThan Nclients. Increasing (sub i o distr.Out))\"\napply (cut_tac Distrib_spec)\napply (simp add: distr_spec_def distr_follows_def)\napply clarify\napply (blast intro: guaranteesI Follows_Increasing1 dest: guaranteesD)\ndone\n\nlemma Distr_Bag_Follows_lemma:\n     \"[| G \\<in> preserves distr.Out;\n         D Join G \\<in> Always {s. \\<forall>elt \\<in> set (distr.iIn s). elt < Nclients} |]\n  ==> D Join G \\<in> Always\n          {s. (\\<Sum>i \\<in> lessThan Nclients. bag_of (sublist (distr.In s)\n                                  {k. k < length (iIn s) & iIn s ! k = i})) =\n              bag_of (sublist (distr.In s) (lessThan (length (iIn s))))}\"\napply (erule Always_Compl_Un_eq [THEN iffD1])\napply (rule UNIV_AlwaysI, clarify)\napply (subst bag_of_sublist_UN_disjoint [symmetric])\n  apply (simp (no_asm))\n apply blast\napply (simp add: set_conv_nth)\napply (subgoal_tac\n       \"(\\<Union>i \\<in> lessThan Nclients. {k. k < length (iIn x) & iIn x ! k = i}) =\n        lessThan (length (iIn x))\")\n apply (simp (no_asm_simp))\napply blast\ndone\n\nlemma D_ok_iff [iff]:\n     \"D ok G = (G \\<in> preserves distr.Out & D \\<in> Allowed G)\"\napply (cut_tac Distrib_spec)\napply (auto simp add: distr_spec_def distr_allowed_acts_def Allowed_def\n                      safety_prop_Acts_iff ok_iff_Allowed)\ndone\n\nlemma Distr_Bag_Follows:\n \"D \\<in> Increasing distr.In Int Increasing distr.iIn Int\n      Always {s. \\<forall>elt \\<in> set (distr.iIn s). elt < Nclients}\n      guarantees\n       (\\<Inter>i \\<in> lessThan Nclients.\n        (%s. \\<Sum>i \\<in> lessThan Nclients. (bag_of o sub i o distr.Out) s)\n        Fols\n        (%s. bag_of (sublist (distr.In s) (lessThan (length(distr.iIn s))))))\"\napply (rule guaranteesI, clarify)\napply (rule Distr_Bag_Follows_lemma [THEN Always_Follows2], auto)\napply (rule Follows_setsum)\napply (cut_tac Distrib_spec)\napply (auto simp add: distr_spec_def distr_follows_def o_def)\napply (drule guaranteesD)\n  prefer 3\n  apply (best intro: mono_bag_of [THEN mono_Follows_apply, THEN subsetD], auto)\ndone\n\nend\n\n\nsubsection{*Theorems for Allocator*}\n\nlemma alloc_refinement_lemma:\n     \"!!f::nat=>nat. (\\<Inter>i \\<in> lessThan n. {s. f i \\<le> g i s})\n      \\<subseteq> {s. (SUM x: lessThan n. f x) \\<le> (SUM x: lessThan n. g x s)}\"\napply (induct_tac \"n\")\napply (auto simp add: lessThan_Suc)\ndone\n\nlemma alloc_refinement:\n\"(\\<Inter>i \\<in> lessThan Nclients. Increasing (sub i o allocAsk) Int\n                           Increasing (sub i o allocRel))\n  Int\n  Always {s. \\<forall>i. i<Nclients -->\n              (\\<forall>elt \\<in> set ((sub i o allocAsk) s). elt \\<le> NbT)}\n  Int\n  (\\<Inter>i \\<in> lessThan Nclients.\n   \\<Inter>h. {s. h \\<le> (sub i o allocGiv)s & h pfixGe (sub i o allocAsk)s}\n        LeadsTo {s. tokens h \\<le> (tokens o sub i o allocRel)s})\n  \\<subseteq>\n (\\<Inter>i \\<in> lessThan Nclients. Increasing (sub i o allocAsk) Int\n                           Increasing (sub i o allocRel))\n  Int\n  Always {s. \\<forall>i. i<Nclients -->\n              (\\<forall>elt \\<in> set ((sub i o allocAsk) s). elt \\<le> NbT)}\n  Int\n  (\\<Inter>hf. (\\<Inter>i \\<in> lessThan Nclients.\n         {s. hf i \\<le> (sub i o allocGiv)s & hf i pfixGe (sub i o allocAsk)s})\n  LeadsTo {s. (\\<Sum>i \\<in> lessThan Nclients. tokens (hf i)) \\<le>\n              (\\<Sum>i \\<in> lessThan Nclients. (tokens o sub i o allocRel)s)})\"\napply (auto simp add: ball_conj_distrib)\napply (rename_tac F hf)\napply (rule LeadsTo_weaken_R [OF Finite_stable_completion alloc_refinement_lemma], blast, blast)\napply (subgoal_tac \"F \\<in> Increasing (tokens o (sub i o allocRel))\")\n apply (simp add: Increasing_def o_assoc)\napply (blast intro: mono_tokens [THEN mono_Increasing_o, THEN subsetD])\ndone\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/UNITY/Comp/AllocImpl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318337259584, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.2644155486683554}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\n(*\n * This file contains theorems for dealing with a \"simply\" lifted\n * heap, where each byte of memory can be accessed as one (and only)\n * type.\n *\n * This is a simpler model of Tuch's \"lift_t\" model, where nested\n * struct fields cannot be directly accessed as pointers.\n *)\n\ntheory TypHeapSimple\nimports\n  \"CLib.TypHeapLib\"\nbegin\n\n(*\n * Each address in the heap can contain one of three things:\n *\n *   - A type tag, which inidicates that this address is the first\n *     byte of an object;\n *\n *   - A footprint, which indicates that this address is a latter byte\n *     of an object;\n *\n *   - Nothing, which indicates that this address does not fall inside\n *     an object.\n *)\ndatatype heap_typ_contents =\n    HeapType typ_uinfo\n  | HeapFootprint\n  | HeapEmpty\n\n(*\n * Given a Tuch-style heap representation (where each memory location\n * contains a set of different types, representing nested field types)\n * calculate a single top-level type of the heap.\n *\n * We just want to commit to a single type for this heap location,\n * and nothing more.\n *)\ndefinition\n  heap_type_tag :: \"heap_typ_desc \\<Rightarrow> addr \\<Rightarrow> heap_typ_contents\"\nwhere\n  \"heap_type_tag d a \\<equiv>\n     (if fst (d a) = False \\<or> (\\<forall>x. (snd (d a)) x = None) \\<or> (\\<forall>x. (snd (d a)) x \\<noteq> None) then\n       HeapEmpty\n     else\n       case (snd (d a)) (GREATEST x. snd (d a) x \\<noteq> None) of\n         Some (_, False) \\<Rightarrow> HeapFootprint\n       | Some (x, True) \\<Rightarrow> HeapType x\n       | None \\<Rightarrow> HeapEmpty)\"\n\n(*\n * Determine if the heap has a valid footprint for the given type at\n * the given address.\n *\n * A valid footprint means that the user has committed that the given\n * memory location will only be used for the given type.\n *\n * A \"simple\" footprint differs from the Tuch-style because we only\n * commit to a single type, and have no support for accessing nested\n * structures.\n *)\ndefinition\n  valid_simple_footprint :: \"heap_typ_desc \\<Rightarrow> addr \\<Rightarrow> typ_uinfo \\<Rightarrow> bool\"\nwhere\n  \"valid_simple_footprint d x t \\<equiv>\n    heap_type_tag d x = HeapType t \\<and>\n      (\\<forall>y. y \\<in> {x + 1..+  (size_td t)- Suc 0} \\<longrightarrow> heap_type_tag d y = HeapFootprint)\"\n\nlemma valid_simple_footprintI:\n  \"\\<lbrakk> heap_type_tag d x = HeapType t; \\<And>y. y \\<in> {x + 1..+(size_td t) - Suc 0} \\<Longrightarrow> heap_type_tag d y = HeapFootprint \\<rbrakk>\n      \\<Longrightarrow> valid_simple_footprint d x t\"\n  by (clarsimp simp: valid_simple_footprint_def)\n\nlemma valid_simple_footprintD:\n  \"valid_simple_footprint d x t \\<Longrightarrow> heap_type_tag d x = HeapType t\"\n  by (simp add: valid_simple_footprint_def)\n\nlemma valid_simple_footprintD2:\n  \"\\<lbrakk> valid_simple_footprint d x t; y \\<in> {x + 1..+(size_td t) - Suc 0} \\<rbrakk> \\<Longrightarrow> heap_type_tag d y = HeapFootprint\"\n  by (simp add: valid_simple_footprint_def)\n\nlemma typ_slices_not_empty:\n    \"typ_slices (x::('a::{mem_type} itself)) \\<noteq> []\"\n  apply (clarsimp simp: typ_slices_def)\n  done\n\nlemma last_typ_slice_t:\n    \"(last (typ_slice_t t 0)) = (t, True)\"\n  apply (case_tac t)\n  apply clarsimp\n  done\n\nlemma if_eqI:\n \"\\<lbrakk> a \\<Longrightarrow> x = z; \\<not> a \\<Longrightarrow> y = z \\<rbrakk> \\<Longrightarrow> (if a then x else y) = z\"\n  by simp\n\nlemma heap_type_tag_ptr_retyp:\n    \"snd (s (ptr_val t)) = Map.empty \\<Longrightarrow>\n        heap_type_tag (ptr_retyp (t :: 'a::mem_type ptr) s) (ptr_val t) = HeapType (typ_uinfo_t TYPE('a))\"\n  apply (unfold ptr_retyp_def heap_type_tag_def)\n  apply (subst htd_update_list_index, fastforce, fastforce)+\n  apply (rule if_eqI)\n   apply clarsimp\n   apply (erule disjE)\n    apply (erule_tac x=0 in allE)\n    apply clarsimp\n   apply (erule_tac x=\"length (typ_slice_t (typ_uinfo_t TYPE('a)) 0)\" in allE)\n   apply (clarsimp simp: list_map_eq)\n  apply (clarsimp simp: list_map_eq last_conv_nth [simplified, symmetric] last_typ_slice_t\n            split: option.splits if_split_asm prod.splits)\n  done\n\nlemma not_snd_last_typ_slice_t:\n    \"k \\<noteq> 0 \\<Longrightarrow> \\<not> snd (last (typ_slice_t z k))\"\n  by (case_tac z, clarsimp)\n\nlemma heap_type_tag_ptr_retyp_rest:\n    \"\\<lbrakk> snd (s (ptr_val t + k)) = Map.empty; 0 < k; unat k < size_td (typ_uinfo_t TYPE('a)) \\<rbrakk> \\<Longrightarrow>\n        heap_type_tag (ptr_retyp (t :: 'a::mem_type ptr) s) (ptr_val t + k) = HeapFootprint\"\n  apply (unfold ptr_retyp_def heap_type_tag_def)\n  apply (subst htd_update_list_index, simp, clarsimp,\n      metis intvlI size_of_def word_unat.Rep_inverse)+\n  apply (rule if_eqI)\n   apply clarsimp\n   apply (erule disjE)\n    apply (erule_tac x=0 in allE)\n    apply (clarsimp simp: size_of_def)\n   apply (erule_tac x=\"length (typ_slice_t (typ_uinfo_t TYPE('a)) (unat k))\" in allE)\n   apply (clarsimp simp: size_of_def list_map_eq)\n  apply (clarsimp simp: list_map_eq last_conv_nth [simplified, symmetric] size_of_def\n      split: option.splits if_split_asm prod.splits bool.splits)\n   apply (metis surj_pair)\n  apply (subst (asm) (2) surjective_pairing)\n  apply (subst (asm) not_snd_last_typ_slice_t)\n   apply clarsimp\n   apply unat_arith\n  apply simp\n  done\n\nlemma typ_slices_addr_card [simp]:\n    \"length (typ_slices (x::('a::{mem_type} itself))) < addr_card\"\n  apply (clarsimp simp: typ_slices_def)\n  done\n\nlemma htd_update_list_same':\n  \"\\<lbrakk>0 < unat k; unat k \\<le> addr_card - length v\\<rbrakk> \\<Longrightarrow> htd_update_list (p + k) v h p = h p\"\n  apply (insert htd_update_list_same [where v=v and p=p and h=h and k=\"unat k\"])\n  apply clarsimp\n  done\n\nlemma unat_less_impl_less:\n    \"unat a < unat b \\<Longrightarrow> a < b\"\n  by unat_arith\n\nlemma valid_simple_footprint_ptr_retyp:\n    \"\\<lbrakk> \\<forall>k < size_td (typ_uinfo_t TYPE('a)). snd (s (ptr_val t + of_nat k)) = Map.empty;\n        1 \\<le> size_td (typ_uinfo_t TYPE('a));\n        size_td (typ_uinfo_t TYPE('a)) < addr_card \\<rbrakk>\n        \\<Longrightarrow> valid_simple_footprint (ptr_retyp (t :: 'a::mem_type ptr) s) (ptr_val t) (typ_uinfo_t TYPE('a))\"\n  apply (clarsimp simp: valid_simple_footprint_def)\n  apply (rule conjI)\n   apply (subst heap_type_tag_ptr_retyp)\n    apply (erule allE [where x=\"0\"])\n    apply clarsimp\n   apply clarsimp\n  apply (clarsimp simp: intvl_def)\n  apply (erule_tac x=\"k + 1\" in allE)\n  apply (erule impE)\n   apply (metis One_nat_def less_diff_conv)\n  apply (subst add.assoc, subst heap_type_tag_ptr_retyp_rest)\n     apply clarsimp\n    apply (case_tac \"1 + of_nat k = (0 :: addr)\")\n     apply (metis add.left_neutral intvlI intvl_Suc_nmem size_of_def)\n    apply unat_arith\n   apply clarsimp\n   apply (metis lt_size_of_unat_simps size_of_def Suc_eq_plus1 One_nat_def less_diff_conv of_nat_Suc)\n  apply simp\n  done\n\n(* Determine if the given pointer is valid in the given heap. *)\ndefinition\n  heap_ptr_valid :: \"heap_typ_desc \\<Rightarrow> 'a::c_type ptr \\<Rightarrow> bool\"\nwhere\n  \"heap_ptr_valid d p \\<equiv>\n      valid_simple_footprint d (ptr_val (p::'a ptr)) (typ_uinfo_t TYPE('a))\n        \\<and> c_guard p\"\n\n(*\n * Lift a heap from raw bytes and a heap description into\n * higher-level objects.\n *\n * This differs from Tuch's \"lift_t\" because we only support\n * simple lifting; that is, each byte in the heap may only\n * be accessed as a single type. Accessing struct fields by\n * their pointers is not supported.\n *)\ndefinition\n  simple_lift :: \"heap_raw_state \\<Rightarrow> ('a::c_type) ptr \\<Rightarrow> 'a option\"\nwhere\n  \"simple_lift s p = (\n     if (heap_ptr_valid (hrs_htd s) p) then\n       (Some (h_val (hrs_mem s) p))\n     else\n       None)\"\n\nlemma simple_lift_heap_ptr_valid:\n  \"simple_lift s p = Some x \\<Longrightarrow> heap_ptr_valid (hrs_htd s) p\"\n  apply (clarsimp simp: simple_lift_def split: if_split_asm)\n  done\n\nlemma simple_lift_c_guard:\n  \"simple_lift s p = Some x \\<Longrightarrow> c_guard p\"\n  apply (clarsimp simp: simple_lift_def heap_ptr_valid_def split: if_split_asm)\n  done\n\n(* Two valid footprints will either overlap completely or not at all. *)\nlemma valid_simple_footprint_neq:\n  assumes valid_p: \"valid_simple_footprint d p s\"\n      and valid_q: \"valid_simple_footprint d q t\"\n      and neq: \"p \\<noteq> q\"\n  shows \"p \\<notin> {q..+ (size_td t)}\"\nproof -\n  have heap_type_p: \"heap_type_tag d p = HeapType s\"\n    apply (metis valid_p valid_simple_footprint_def)\n    done\n\n  have heap_type_q: \"heap_type_tag d q = HeapType t\"\n    apply (metis valid_q valid_simple_footprint_def)\n    done\n\n  have heap_type_q_footprint:\n    \"\\<And>x. x \\<in> {(q + 1)..+(size_td t - Suc 0)} \\<Longrightarrow> heap_type_tag d x = HeapFootprint\"\n    apply (insert valid_q)\n    apply (simp add: valid_simple_footprint_def)\n    done\n\n  show ?thesis\n    using heap_type_q_footprint heap_type_p neq\n         intvl_neq_start heap_type_q\n    by (metis heap_typ_contents.simps(2))\nqed\n\n(* Two valid footprints with different types will never overlap. *)\nlemma valid_simple_footprint_type_neq:\n  \"\\<lbrakk> valid_simple_footprint d p s;\n     valid_simple_footprint d q t;\n     s \\<noteq> t \\<rbrakk> \\<Longrightarrow>\n   p \\<notin> {q..+ (size_td t)}\"\n  apply (subgoal_tac \"p \\<noteq> q\")\n   apply (rule valid_simple_footprint_neq, simp_all)[1]\n  apply (clarsimp simp: valid_simple_footprint_def)\n  done\n\nlemma valid_simple_footprint_neq_disjoint:\n  \"\\<lbrakk> valid_simple_footprint d p s; valid_simple_footprint d q t; p \\<noteq> q \\<rbrakk> \\<Longrightarrow>\n      {p..+(size_td s)} \\<inter> {q..+ (size_td t)} = {}\"\n  apply (rule ccontr)\n  apply (fastforce simp: valid_simple_footprint_neq dest!: intvl_inter)\n  done\n\nlemma valid_simple_footprint_type_neq_disjoint:\n  \"\\<lbrakk> valid_simple_footprint d p s;\n     valid_simple_footprint d q t;\n     s \\<noteq> t \\<rbrakk> \\<Longrightarrow>\n   {p..+(size_td s)} \\<inter> {q..+ (size_td t)} = {}\"\n  apply (subgoal_tac \"p \\<noteq> q\")\n   apply (rule valid_simple_footprint_neq_disjoint, simp_all)[1]\n  apply (clarsimp simp: valid_simple_footprint_def)\n  done\n\nlemma heap_ptr_valid_neq_disjoint:\n  \"\\<lbrakk> heap_ptr_valid d (p::'a::c_type ptr);\n     heap_ptr_valid d (q::'b::c_type ptr);\n     ptr_val p \\<noteq> ptr_val q \\<rbrakk> \\<Longrightarrow>\n   {ptr_val p..+size_of TYPE('a)} \\<inter>\n          {ptr_val q..+size_of TYPE('b)} = {}\"\n  apply (clarsimp simp only: size_of_tag [symmetric])\n  apply (rule valid_simple_footprint_neq_disjoint [where d=\"d\"])\n    apply (clarsimp simp: heap_ptr_valid_def)\n   apply (clarsimp simp: heap_ptr_valid_def)\n  apply simp\n  done\n\nlemma heap_ptr_valid_type_neq_disjoint:\n  \"\\<lbrakk> heap_ptr_valid d (p::'a::c_type ptr);\n     heap_ptr_valid d (q::'b::c_type ptr);\n     typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('b) \\<rbrakk> \\<Longrightarrow>\n   {ptr_val p..+size_of TYPE('a)} \\<inter>\n          {ptr_val q..+size_of TYPE('b)} = {}\"\n  apply (subgoal_tac \"ptr_val p \\<noteq> ptr_val q\")\n   apply (rule heap_ptr_valid_neq_disjoint, auto)[1]\n  apply (clarsimp simp: heap_ptr_valid_def valid_simple_footprint_def)\n  done\n\n(* If we update one pointer in the heap, other valid pointers will be unaffected. *)\nlemma heap_ptr_valid_heap_update_other:\n  assumes val_p: \"heap_ptr_valid d (p::'a::mem_type ptr)\"\n      and val_q: \"heap_ptr_valid d (q::'b::c_type ptr)\"\n      and neq: \"ptr_val p \\<noteq> ptr_val q\"\n  shows \"h_val (heap_update p v h) q = h_val h q\"\n  apply (clarsimp simp: h_val_def heap_update_def)\n  apply (subst heap_list_update_disjoint_same)\n   apply simp\n   apply (rule heap_ptr_valid_neq_disjoint [OF val_p val_q neq])\n  apply simp\n  done\n\n(* If we update one type in the heap, other types will be unaffected. *)\nlemma heap_ptr_valid_heap_update_other_typ:\n  assumes val_p: \"heap_ptr_valid d (p::'a::mem_type ptr)\"\n      and val_q: \"heap_ptr_valid d (q::'b::c_type ptr)\"\n      and neq: \"typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('b)\"\n  shows \"h_val (heap_update p v h) q = h_val h q\"\n  apply (clarsimp simp: h_val_def heap_update_def)\n  apply (subst heap_list_update_disjoint_same)\n   apply simp\n   apply (rule heap_ptr_valid_type_neq_disjoint [OF val_p val_q neq])\n  apply simp\n  done\n\n(* Updating the raw heap is equivalent to updating the lifted heap. *)\nlemma simple_lift_heap_update:\n  \"\\<lbrakk> heap_ptr_valid (hrs_htd h) p \\<rbrakk> \\<Longrightarrow>\n      simple_lift (hrs_mem_update (heap_update p v) h)\n          = (simple_lift h)(p := Some (v::'a::mem_type))\"\n  apply (rule ext)\n  apply (clarsimp simp: simple_lift_def hrs_mem_update h_val_heap_update)\n  apply (fastforce simp: heap_ptr_valid_heap_update_other)\n  done\n\n(* Updating the raw heap of one type doesn't affect the lifted heap of other types. *)\nlemma simple_lift_heap_update_other:\n  \"\\<lbrakk> heap_ptr_valid (hrs_htd d) (p::'b::mem_type ptr);\n     typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('b) \\<rbrakk> \\<Longrightarrow>\n   simple_lift (hrs_mem_update (heap_update p v) d) = ((simple_lift d)::'a::c_type typ_heap)\"\n  apply (rule ext)+\n  apply (clarsimp simp: simple_lift_def h_val_heap_update hrs_mem_update)\n  apply (auto intro: heap_ptr_valid_heap_update_other_typ)\n  done\n\nlemma h_val_simple_lift:\n  \"simple_lift h p = Some v \\<Longrightarrow> h_val (hrs_mem h) p = v\"\n  apply (clarsimp simp: simple_lift_def split: if_split_asm)\n  done\n\nlemma h_val_field_simple_lift:\n  \"\\<lbrakk> simple_lift h (pa :: 'a ptr) = Some (v::'a::mem_type);\n     \\<exists>t. field_ti TYPE('a) f = Some t;\n     export_uinfo (the (field_ti TYPE('a) f)) = export_uinfo (typ_info_t TYPE('b :: mem_type)) \\<rbrakk> \\<Longrightarrow>\n   h_val (hrs_mem h) (Ptr &(pa\\<rightarrow>f) :: 'b :: mem_type ptr) = from_bytes (access_ti\\<^sub>0 (the (field_ti TYPE('a) f)) v)\"\n  apply (clarsimp simp: simple_lift_def split: if_split_asm)\n  apply (clarsimp simp: h_val_field_from_bytes)\n  done\n\nlemma simple_lift_heap_update':\n  \"simple_lift h p = Some v' \\<Longrightarrow>\n      simple_lift (hrs_mem_update (heap_update (p::('a::{mem_type}) ptr) v) h)\n          = (simple_lift h)(p := Some v)\"\n  apply (rule simple_lift_heap_update)\n  apply (erule simple_lift_heap_ptr_valid)\n  done\n\nlemma simple_lift_hrs_mem_update_None [simp]:\n    \"(simple_lift (hrs_mem_update a hp) x = None) = (simple_lift hp x = None)\"\n  apply (clarsimp simp: simple_lift_def)\n  done\n\nlemma simple_lift_data_eq:\n   \"\\<lbrakk> h_val (hrs_mem h) p = h_val (hrs_mem h') p';\n     heap_ptr_valid (hrs_htd h) p = heap_ptr_valid (hrs_htd h') p' \\<rbrakk> \\<Longrightarrow>\n    simple_lift h p = simple_lift h' p'\"\n  apply (clarsimp simp: simple_lift_def)\n  done\n\nlemma h_val_heap_update_disjoint:\n  \"\\<lbrakk> {ptr_val p ..+ size_of TYPE('a::c_type)}\n        \\<inter> {ptr_val q ..+ size_of TYPE('b::mem_type)} = {} \\<rbrakk> \\<Longrightarrow>\n      h_val (heap_update (q :: 'b ptr) r h) (p :: 'a ptr) = h_val h p\"\n  apply (clarsimp simp: h_val_def)\n  apply (clarsimp simp: heap_update_def)\n  apply (subst heap_list_update_disjoint_same)\n   apply clarsimp\n   apply blast\n   apply clarsimp\n  done\n\nlemma update_ti_t_valid_size:\n  \"size_of TYPE('b) = size_td t \\<Longrightarrow>\n   update_ti_t t (to_bytes_p (val::'b::mem_type)) obj = update_ti t (to_bytes_p val) obj\"\n  apply (clarsimp simp: update_ti_t_def to_bytes_p_def)\n  done\n\nlemma h_val_field_from_bytes':\n  \"\\<lbrakk> field_ti TYPE('a::{mem_type}) f = Some t;\n     export_uinfo t = export_uinfo (typ_info_t TYPE('b::{mem_type})) \\<rbrakk> \\<Longrightarrow>\n    h_val h (Ptr &(pa\\<rightarrow>f) :: 'b ptr) = from_bytes (access_ti\\<^sub>0 t (h_val h pa))\"\n  apply (insert h_val_field_from_bytes[where f=f and pa=pa and t=t and h=\"(h,x)\"\n                                         and 'a='a and 'b='b for x])\n  apply (clarsimp simp: hrs_mem_def)\n  done\n\nlemma simple_lift_super_field_update_lookup:\n  fixes dummy :: \"'b :: mem_type\"\n  assumes \"field_lookup (typ_info_t TYPE('b::mem_type)) f 0 = Some (s,n)\"\n    and \"typ_uinfo_t TYPE('a) = export_uinfo s\"\n    and \"simple_lift h p = Some v'\"\n  shows \"(super_field_update_t (Ptr (&(p\\<rightarrow>f))) (v::'a::mem_type) ((simple_lift h)::'b ptr \\<Rightarrow> 'b option)) =\n          ((simple_lift h)(p \\<mapsto> field_update (field_desc s) (to_bytes_p v) v'))\"\nproof -\n  from assms have [simp]: \"unat (of_nat n :: addr) = n\"\n     apply (subst unat_of_nat)\n     apply (subst mod_less)\n      apply (drule td_set_field_lookupD)+\n      apply (drule td_set_offset_size)+\n      apply (subst len_of_addr_card)\n      apply (subst (asm) size_of_def [symmetric, where t=\"TYPE('b)\"])+\n      apply (subgoal_tac \"size_of TYPE('b) < addr_card\")\n       apply arith\n      apply simp\n     apply simp\n     done\n  from assms show ?thesis\n    apply (clarsimp simp: super_field_update_t_def)\n    apply (rule ext)\n    apply (clarsimp simp: field_lvalue_def split: option.splits)\n    apply (safe, simp_all)\n       apply (frule_tac v=v and v'=v' in update_field_update)\n       apply (clarsimp simp: field_of_t_def field_of_def typ_uinfo_t_def)\n       apply (frule_tac m=0 in field_names_SomeD2)\n        apply simp\n       apply clarsimp\n       apply (simp add: field_typ_def field_typ_untyped_def)\n       apply (frule field_lookup_export_uinfo_Some)\n       apply (frule_tac s=k in field_lookup_export_uinfo_Some)\n       apply simp\n       apply (drule (1) field_lookup_inject)\n        apply (subst typ_uinfo_t_def [symmetric, where t=\"TYPE('b)\"])\n        apply simp\n       apply simp\n      apply (drule field_of_t_mem)+\n      apply (case_tac h)\n      apply (clarsimp simp: simple_lift_def split: if_split_asm)\n      apply (drule (1) heap_ptr_valid_neq_disjoint)\n       apply simp\n      apply fast\n     apply (clarsimp simp: field_of_t_def field_of_def)\n     apply (subst (asm) td_set_field_lookup)\n      apply simp\n     apply simp\n     apply (frule field_lookup_export_uinfo_Some)\n     apply (simp add: typ_uinfo_t_def)\n    apply (clarsimp simp: field_of_t_def field_of_def)\n    apply (subst (asm) td_set_field_lookup)\n     apply simp\n    apply simp\n    apply (frule field_lookup_export_uinfo_Some)\n    apply (simp add: typ_uinfo_t_def)\n    done\nqed\n\nlemma field_offset_addr_card:\n  \"\\<exists>x. field_lookup (typ_info_t TYPE('a::mem_type)) f 0 = Some x\n    \\<Longrightarrow> field_offset TYPE('a) f < addr_card\"\n  apply (clarsimp simp: field_offset_def field_offset_untyped_def typ_uinfo_t_def)\n  apply (subst field_lookup_export_uinfo_Some)\n   apply assumption\n  apply (frule td_set_field_lookupD)\n  apply (drule td_set_offset_size)\n  apply (insert max_size [where ?'a=\"'a\"])\n  apply (clarsimp simp: size_of_def)\n  done\n\nlemma unat_of_nat_field_offset:\n  \"\\<exists>x. field_lookup (typ_info_t TYPE('a::mem_type)) f 0 = Some x \\<Longrightarrow>\n      unat (of_nat (field_offset TYPE('a) f)  :: addr) = field_offset TYPE('a) f\"\n  apply (subst word_unat.Abs_inverse)\n   apply (clarsimp simp: unats_def)\n   apply (insert field_offset_addr_card [where f=f and ?'a=\"'a\"])[1]\n   apply (fastforce simp: addr_card)\n  apply simp\n  done\n\nlemma field_of_t_field_lookup:\n  assumes a: \"field_lookup (typ_info_t TYPE('a::mem_type)) f 0 = Some (s, n)\"\n  assumes b: \"export_uinfo s = typ_uinfo_t TYPE('b::mem_type)\"\n  assumes n: \"n = field_offset TYPE('a) f\"\n  shows \"field_of_t (Ptr &(ptr\\<rightarrow>f) :: ('b ptr)) (ptr :: 'a ptr)\"\n  apply (clarsimp simp del: field_lookup_offset_eq\n      simp: field_of_t_def field_of_def)\n  apply (subst td_set_field_lookup)\n   apply (rule wf_desc_typ_tag)\n  apply (rule exI [where x=f])\n  using a[simplified n] b\n  apply (clarsimp simp: typ_uinfo_t_def)\n  apply (subst field_lookup_export_uinfo_Some)\n   apply assumption\n  apply (clarsimp simp del: field_lookup_offset_eq\n      simp: field_lvalue_def unat_of_nat_field_offset)\n  done\n\nlemma simple_lift_field_update':\n  fixes val :: \"'b :: mem_type\" and ptr :: \"'a :: mem_type ptr\"\n  assumes   fl: \"field_lookup (typ_info_t TYPE('a)) f 0 =\n                     Some (adjust_ti (typ_info_t TYPE('b)) xf xfu, n)\"\n  and   xf_xfu: \"fg_cons xf xfu\"\n  and       cl: \"simple_lift hp ptr = Some z\"\n  shows \"(simple_lift (hrs_mem_update (heap_update (Ptr &(ptr\\<rightarrow>f)) val) hp)) =\n                simple_lift hp(ptr \\<mapsto> xfu val z)\"\n    (is \"?LHS = ?RHS\")\nproof (rule ext)\n  fix p\n\n  have eui: \"typ_uinfo_t TYPE('b) =\n       export_uinfo (adjust_ti (typ_info_t TYPE('b)) xf xfu)\"\n    using xf_xfu\n    apply (subst export_tag_adjust_ti2 [OF _ wf_lf wf_desc])\n    apply (simp add: fg_cons_def )\n    apply (rule meta_eq_to_obj_eq [OF typ_uinfo_t_def])\n    done\n\n  have n_is_field_offset: \"n = field_offset TYPE('a) f\"\n    apply (insert field_lookup_offset_eq [OF fl])\n    apply (clarsimp)\n    done\n\n  have equal_case: \"?LHS ptr = ?RHS ptr\"\n    apply (insert cl)\n    apply (clarsimp simp: simple_lift_def split: if_split_asm)\n    apply (clarsimp simp: hrs_mem_update)\n    apply (subst h_val_super_update_bs)\n     apply (rule field_of_t_field_lookup [OF fl])\n      apply (clarsimp simp: eui)\n     apply (clarsimp simp: n_is_field_offset)\n    apply clarsimp\n    apply (unfold from_bytes_def)\n    apply (subst fi_fu_consistentD [where f=f and s=\"adjust_ti (typ_info_t TYPE('b)) xf xfu\"])\n        apply (clarsimp simp: fl)\n        apply (clarsimp simp: n_is_field_offset field_lvalue_def)\n        apply (metis unat_of_nat_field_offset fl)\n       apply clarsimp\n      apply (clarsimp simp: size_of_def)\n     apply (clarsimp simp: size_of_def)\n    apply clarsimp\n    apply (subst update_ti_s_from_bytes)\n     apply clarsimp\n    apply (subst update_ti_adjust_ti)\n     apply (rule xf_xfu)\n    apply (subst update_ti_s_from_bytes)\n     apply clarsimp\n    apply clarsimp\n    apply (clarsimp simp: h_val_def)\n    done\n\n  show \"?LHS p = ?RHS p\"\n    apply (case_tac \"p = ptr\")\n     apply (erule ssubst)\n     apply (rule equal_case)\n    apply (insert cl)\n    apply (clarsimp simp: simple_lift_def hrs_mem_update split: if_split_asm)\n    apply (rule h_val_heap_update_disjoint)\n    apply (insert field_tag_sub [OF fl, where p=ptr])\n    apply (clarsimp simp: size_of_def)\n    apply (clarsimp simp: heap_ptr_valid_def)\n    apply (frule (1) valid_simple_footprint_neq_disjoint, fastforce)\n    apply clarsimp\n    apply blast\n    done\nqed\n\nlemma simple_lift_field_update:\n  fixes val :: \"'b :: mem_type\" and ptr :: \"'a :: mem_type ptr\"\n  assumes   fl: \"field_ti TYPE('a) f =\n                     Some (adjust_ti (typ_info_t TYPE('b)) xf (xfu o (\\<lambda>x _. x)))\"\n  and   xf_xfu: \"fg_cons xf (xfu o (\\<lambda>x _. x))\"\n  and       cl: \"simple_lift hp ptr = Some z\"\n  shows \"(simple_lift (hrs_mem_update (heap_update (Ptr &(ptr\\<rightarrow>f)) val) hp)) =\n                simple_lift hp(ptr \\<mapsto> xfu (\\<lambda>_. val) z)\"\n    (is \"?LHS = ?RHS\")\n  apply (insert fl [unfolded field_ti_def])\n  apply (clarsimp split: option.splits)\n  apply (subst simple_lift_field_update' [where xf=xf and xfu=\"xfu o (\\<lambda>x _. x)\" and z=z])\n     apply (clarsimp simp: o_def split: option.splits)\n     apply (rule refl)\n    apply (rule xf_xfu)\n   apply (rule cl)\n  apply clarsimp\n  done\n\nlemma simple_heap_diff_types_impl_diff_ptrs:\n  \"\\<lbrakk> heap_ptr_valid h (p::('a::c_type) ptr);\n     heap_ptr_valid h (q::('b::c_type) ptr);\n     typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('b) \\<rbrakk> \\<Longrightarrow>\n   ptr_val p \\<noteq> ptr_val q\"\n  apply (clarsimp simp: heap_ptr_valid_def)\n  apply (clarsimp simp: valid_simple_footprint_def)\n  done\n\nlemma h_val_update_regions_disjoint:\n  \"\\<lbrakk> { ptr_val p ..+ size_of TYPE('a) } \\<inter> { ptr_val x ..+ size_of TYPE('b)} = {} \\<rbrakk> \\<Longrightarrow>\n        h_val (heap_update p (v::('a::mem_type)) h) x = h_val h (x::('b::c_type) ptr)\"\n  apply (clarsimp simp: heap_update_def)\n  apply (clarsimp simp: h_val_def)\n  apply (subst heap_list_update_disjoint_same)\n   apply clarsimp\n  apply clarsimp\n  done\n\nlemma simple_lift_field_update_t:\n  fixes    val :: \"'b :: mem_type\" and ptr :: \"'a :: mem_type ptr\"\n  assumes  fl: \"field_ti TYPE('a) f = Some t\"\n  and      diff: \"typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('c :: c_type)\"\n  and      eu: \"export_uinfo t = export_uinfo (typ_info_t TYPE('b))\"\n  and      cl: \"simple_lift hp ptr = Some z\"\n  shows \"((simple_lift (hrs_mem_update (heap_update (Ptr &(ptr\\<rightarrow>f)) val) hp)) :: 'c ptr \\<Rightarrow> 'c option) =\n             simple_lift hp\"\n  apply (rule ext)\n  apply (case_tac \"simple_lift hp x\")\n   apply clarsimp\n  apply (case_tac \"ptr_val x = ptr_val ptr\")\n   apply clarsimp\n   apply (clarsimp simp: simple_lift_def hrs_mem_update split: if_split_asm)\n   apply (cut_tac simple_lift_heap_ptr_valid [OF cl])\n   apply (drule (1) simple_heap_diff_types_impl_diff_ptrs [OF _ _ diff])\n   apply simp\n  apply (clarsimp simp: simple_lift_def hrs_mem_update split: if_split_asm)\n  apply (rule field_ti_field_lookupE [OF fl])\n  apply (frule_tac p=ptr in field_tag_sub)\n  apply (clarsimp simp: h_val_def heap_update_def)\n  apply (subst heap_list_update_disjoint_same)\n   apply clarsimp\n   apply (cut_tac simple_lift_heap_ptr_valid [OF cl])\n   apply (drule (2) heap_ptr_valid_neq_disjoint)\n   apply (clarsimp simp: export_size_of [unfolded typ_uinfo_t_def, OF eu])\n   apply blast\n  apply simp\n  done\n\nlemma simple_lift_heap_update_other':\n  \"\\<lbrakk> simple_lift h (p::'b::mem_type ptr) = Some v';\n     typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('b) \\<rbrakk> \\<Longrightarrow>\n   simple_lift (hrs_mem_update (heap_update p v) h) = ((simple_lift h)::'a::c_type typ_heap)\"\n  apply (rule simple_lift_heap_update_other)\n   apply (erule simple_lift_heap_ptr_valid)\n  apply simp\n  done\n\n(* If you update bytes inside an object of one type, it won't affect\n * heaps of other types. *)\nlemma simple_lift_heap_update_bytes_in_other:\n  \"\\<lbrakk> simple_lift h (p::'b::mem_type ptr) = Some v';\n     typ_uinfo_t TYPE('b) \\<noteq> typ_uinfo_t TYPE('c);\n     { ptr_val q ..+ size_of TYPE('a)} \\<subseteq> {ptr_val p  ..+ size_of TYPE('b) }  \\<rbrakk> \\<Longrightarrow>\n   simple_lift (hrs_mem_update (heap_update (q::'a::mem_type ptr) v) h) = ((simple_lift h)::'c::mem_type typ_heap)\"\n  apply (rule ext)\n  apply (clarsimp simp: simple_lift_def split: if_split_asm)\n  apply (drule (1) heap_ptr_valid_type_neq_disjoint, simp)\n  apply (clarsimp simp: hrs_mem_update)\n  apply (rule h_val_heap_update_disjoint)\n  apply blast\n  done\n\nlemma typ_name_neq:\n    \"typ_name (export_uinfo (typ_info_t TYPE('a::c_type)))\n        \\<noteq> typ_name (export_uinfo (typ_info_t TYPE('b::c_type)))\n    \\<Longrightarrow> typ_uinfo_t TYPE('a) \\<noteq> typ_uinfo_t TYPE('b)\"\n  apply (metis typ_uinfo_t_def)\n  done\n\nlemma of_nat_mod_div_decomp:\n  \"of_nat k\n        = of_nat (k div size_of TYPE('b)) * of_nat (size_of TYPE('b::mem_type)) +\n              of_nat (k mod size_of TYPE('b))\"\n  by (metis mod_div_decomp of_nat_add of_nat_mult)\n\nlemma c_guard_array_c_guard:\n  \"\\<lbrakk> \\<And>x. x < CARD('a) \\<Longrightarrow> c_guard (ptr_coerce p +\\<^sub>p int x :: 'b ptr) \\<rbrakk> \\<Longrightarrow> c_guard ( p :: ('b :: mem_type, 'a :: finite) array ptr)\"\n  apply atomize\n  apply (clarsimp simp: c_guard_def)\n  apply (rule conjI)\n   apply (drule_tac x=0 in spec)\n   apply (clarsimp simp: ptr_aligned_def align_of_def align_td_array)\n  apply (simp add: c_null_guard_def)\n  apply (clarsimp simp: intvl_def)\n  apply (drule_tac x=\"k div size_of TYPE('b)\" in spec)\n  apply (erule impE)\n   apply (metis (full_types) less_nat_zero_code mult_is_0 neq0_conv td_gal_lt)\n  apply clarsimp\n  apply (drule_tac x=\"k mod size_of TYPE('b)\" in spec)\n  apply (clarsimp simp: CTypesDefs.ptr_add_def)\n  apply (subst (asm) add.assoc)\n  apply (subst (asm) of_nat_mod_div_decomp [symmetric])\n  apply clarsimp\n  done\n\nlemma heap_list_update_list':\n  \"\\<lbrakk> n + x \\<le> length v; length v < addr_card; q = (p + of_nat x) \\<rbrakk> \\<Longrightarrow>\n      heap_list (heap_update_list p v h) n q = take n (drop x v)\"\n  by (metis heap_list_update_list)\n\nlemma outside_intvl_range:\n    \"p \\<notin> {a ..+ b} \\<Longrightarrow> p < a \\<or> p \\<ge> a + of_nat b\"\n  apply (clarsimp simp: intvl_def not_le not_less)\n  apply (drule_tac x=\"unat (p-a)\" in spec)\n  apply clarsimp\n  apply (metis add_diff_cancel2 le_less_linear le_unat_uoi\n      mpl_lem not_add_less2 unat_mono word_less_minus_mono_left)\n  done\n\nlemma first_in_intvl:\n  \"b \\<noteq> 0 \\<Longrightarrow> a \\<in> {a ..+ b}\"\n  by (force simp: intvl_def)\n\nlemma zero_not_in_intvl_no_overflow:\n  \"0 \\<notin> {a :: 'a::len word ..+ b} \\<Longrightarrow> unat a + b \\<le> 2 ^ len_of TYPE('a)\"\n  apply (rule ccontr)\n  apply (simp add: intvl_def not_le)\n  apply (drule_tac x=\"2 ^ len_of TYPE('a) - unat a\" in spec)\n  apply (clarsimp simp: not_less)\n  apply (erule disjE)\n  apply (metis (erased, hide_lams) diff_add_inverse less_imp_add_positive of_nat_2p of_nat_add\n           unat_lt2p word_neq_0_conv word_unat.Rep_inverse)\n  apply (metis le_add_diff_inverse le_antisym le_diff_conv le_refl\n           less_imp_le_nat add.commute not_add_less1 unat_lt2p)\n  done\n\nlemma intvl_split:\n  \"\\<lbrakk> n \\<ge> a \\<rbrakk> \\<Longrightarrow> { p :: ('a :: len) word ..+ n } = { p ..+ a } \\<union> { p + of_nat a ..+ (n - a)}\"\n  apply (rule set_eqI, rule iffI)\n   apply (clarsimp simp: intvl_def not_less)\n   apply (rule_tac x=k in exI)\n   apply clarsimp\n   apply (rule classical)\n   apply (drule_tac x=\"k - a\" in spec)\n   apply (clarsimp simp: not_less)\n   apply (metis diff_less_mono not_less)\n  apply (clarsimp simp: intvl_def not_less)\n  apply (rule_tac x=\"unat (x - p)\" in exI)\n  apply clarsimp\n  apply (erule disjE)\n   apply clarsimp\n   apply (metis le_unat_uoi less_or_eq_imp_le not_less order_trans)\n  apply clarsimp\n  apply (metis le_def le_eq_less_or_eq le_unat_uoi less_diff_conv\n    add.commute of_nat_add)\n  done\n\nlemma heap_ptr_valid_range_not_NULL:\n  \"heap_ptr_valid htd (p :: ('a :: c_type) ptr)\n      \\<Longrightarrow> 0 \\<notin> {ptr_val p ..+ size_of TYPE('a)}\"\n  apply (clarsimp simp: heap_ptr_valid_def)\n  apply (metis c_guard_def c_null_guard_def)\n  done\n\nlemma heap_ptr_valid_last_byte_no_overflow:\n  \"heap_ptr_valid htd (p :: ('a :: c_type) ptr)\n      \\<Longrightarrow> unat (ptr_val p) + size_of TYPE('a) \\<le> 2 ^ len_of TYPE(addr_bitsize)\"\n  by (metis c_guard_def c_null_guard_def heap_ptr_valid_def\n        zero_not_in_intvl_no_overflow)\n\nlemma heap_ptr_valid_intersect_array:\n  \"\\<lbrakk> \\<forall>j < n. heap_ptr_valid htd (p +\\<^sub>p int j);\n        heap_ptr_valid htd (q :: ('a :: c_type) ptr) \\<rbrakk>\n         \\<Longrightarrow> (\\<exists>m < n. q = (p +\\<^sub>p int m))\n    \\<or> ({ptr_val p ..+ size_of TYPE ('a) * n} \\<inter> {ptr_val q ..+ size_of TYPE ('a :: c_type)} = {})\"\n  apply (induct n)\n   apply clarsimp\n  apply atomize\n  apply simp\n  apply (case_tac \"n = 0\")\n   apply clarsimp\n   apply (metis heap_ptr_valid_neq_disjoint ptr_val_inj)\n  apply (erule disjE)\n   apply (metis less_Suc_eq)\n  apply (case_tac \"q = p +\\<^sub>p int n\")\n   apply force\n  apply (frule_tac x=n in spec)\n  apply (erule impE, simp)\n  apply (drule (1) heap_ptr_valid_neq_disjoint)\n  apply simp\n  apply (simp add: CTypesDefs.ptr_add_def)\n  apply (rule disjI2)\n  apply (cut_tac a=\" of_nat n * of_nat (size_of TYPE('a))\"\n      and p=\"ptr_val p\" and n=\"n * size_of TYPE('a) + size_of TYPE('a)\" in intvl_split)\n   apply clarsimp\n  apply (clarsimp simp: field_simps Int_Un_distrib2)\n  apply (metis IntI emptyE intvl_empty intvl_inter intvl_self neq0_conv)\n  done\n\n(* Simplification rules for dealing with \"lift_simple\". *)\n\nlemmas simple_lift_simps =\n  typ_name_neq\n  simple_lift_c_guard\n  h_val_simple_lift\n  simple_lift_heap_update'\n  simple_lift_heap_update_other'\n  c_guard_field\n  h_val_field_simple_lift\n  simple_lift_field_update\n  simple_lift_field_update_t\n  c_guard_array_field\n  nat_to_bin_string_simps\n\n(* Old name for the above simpset. *)\nlemmas typ_simple_heap_simps = simple_lift_simps\n\nend\n", "meta": {"author": "amblafont", "repo": "AutoCorres", "sha": "a8e96bff9fb22d633ff473401947ca84235d3b73", "save_path": "github-repos/isabelle/amblafont-AutoCorres", "path": "github-repos/isabelle/amblafont-AutoCorres/AutoCorres-a8e96bff9fb22d633ff473401947ca84235d3b73/autocorres/TypHeapSimple.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318337259584, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.2644155486683554}}
{"text": "theory TopoS_Composition_Theory\nimports TopoS_Interface TopoS_Helper\nbegin\n\nsection{*Composition Theory*}\n\ntext{*Several invariants may apply to one policy. *}\n\ntext{*The security invariants are all collected in a list. \nThe list corresponds to the security requirements. \nThe list should have the type @{typ \"('v graph \\<Rightarrow> bool) list\"}, i.e.\\ a list of predicates over the policy. \nWe need in instantiated security invariant, i.e.\\ get rid of @{typ \"'a\"} and @{typ \"'b\"}*}\n\n --{*An instance (configured) a security invariant I.e.\\ a concrete security requirement, in different terminology. *}\n record ('v) SecurityInvariant_configured =\n    c_sinvar::\"('v) graph \\<Rightarrow> bool\"\n    c_offending_flows::\"('v) graph \\<Rightarrow> ('v \\<times> 'v) set set\"\n    c_isIFS::\"bool\"\n\n  --{*  parameters 1-3 are the @{text \"SecurityInvariant\"}:\n      @{text sinvar} @{text \"\\<bottom>\"} @{text \"receiver_violation\"}\n\n      Fourth parameter is the host attribute mapping @{text nP}\n\n      \n      TODO: probably check @{text \"wf_graph\"} here and optionally some host-attribute sanity checker as in DomainHierachy.\n      *}\n  fun new_configured_SecurityInvariant ::\n    \"((('v::vertex) graph \\<Rightarrow> ('v \\<Rightarrow> 'a) \\<Rightarrow> bool) \\<times> 'a \\<times> bool \\<times> ('v \\<Rightarrow> 'a)) \\<Rightarrow> ('v SecurityInvariant_configured) option\" where \n      \"new_configured_SecurityInvariant (sinvar, defbot, receiver_violation, nP) = \n        ( \n        if SecurityInvariant sinvar defbot receiver_violation then \n          Some \\<lparr> \n            c_sinvar = (\\<lambda>G. sinvar G nP),\n            c_offending_flows = (\\<lambda>G. SecurityInvariant_withOffendingFlows.set_offending_flows sinvar G nP),\n            c_isIFS = receiver_violation\n          \\<rparr>\n        else None\n        )\"\n\n   declare new_configured_SecurityInvariant.simps[simp del]\n\n   lemma new_configured_TopoS_sinvar_correct:\n   \"SecurityInvariant sinvar defbot receiver_violation \\<Longrightarrow> \n   c_sinvar (the (new_configured_SecurityInvariant (sinvar, defbot, receiver_violation, nP))) = (\\<lambda>G. sinvar G nP)\"\n   by(simp add: Let_def new_configured_SecurityInvariant.simps)\n\n   lemma new_configured_TopoS_offending_flows_correct:\n   \"SecurityInvariant sinvar defbot receiver_violation \\<Longrightarrow> \n   c_offending_flows (the (new_configured_SecurityInvariant (sinvar, defbot, receiver_violation, nP))) = \n   (\\<lambda>G. SecurityInvariant_withOffendingFlows.set_offending_flows sinvar G nP)\"\n   by(simp add: Let_def new_configured_SecurityInvariant.simps)\n\n\ntext{* We now collect all the core properties of a security invariant, but without the @{typ \"'a\"} @{typ \"'b\"} \n      types, so it is instantiated with a concrete configuration.*}\nlocale configured_SecurityInvariant =\n  fixes m :: \"('v::vertex) SecurityInvariant_configured\"\n  assumes\n    --\"As in SecurityInvariant definition\"\n    valid_c_offending_flows:\n    \"c_offending_flows m G = {F. F \\<subseteq> (edges G) \\<and> \\<not> c_sinvar m G \\<and> c_sinvar m (delete_edges G F) \\<and> \n      (\\<forall> (e1, e2) \\<in> F. \\<not> c_sinvar m (add_edge e1 e2 (delete_edges G F)))}\"\n  and\n    --\"A empty network can have no security violations\"\n    defined_offending:\n    \"\\<lbrakk> wf_graph \\<lparr> nodes = N, edges = {} \\<rparr> \\<rbrakk> \\<Longrightarrow> c_sinvar m \\<lparr> nodes = N, edges = {}\\<rparr>\"\n  and\n    --\"prohibiting more does not decrease security\"\n    mono_sinvar:\n    \"\\<lbrakk> wf_graph \\<lparr> nodes = N, edges = E \\<rparr>; E' \\<subseteq> E; c_sinvar m \\<lparr> nodes = N, edges = E \\<rparr> \\<rbrakk> \\<Longrightarrow> \n      c_sinvar m \\<lparr> nodes = N, edges = E' \\<rparr>\"\n  begin\n    (*compatibility with other definitions*)\n    lemma sinvar_monoI: \n    \"SecurityInvariant_withOffendingFlows.sinvar_mono (\\<lambda> (G::('v::vertex) graph) (nP::'v \\<Rightarrow> 'a). c_sinvar m G)\"\n      apply(simp add: SecurityInvariant_withOffendingFlows.sinvar_mono_def, clarify)\n      by(fact mono_sinvar)\n\n    text{* if the network where nobody communicates with anyone fulfilles its security requirement,\n          the offending flows are always defined. *}\n    lemma defined_offending': \n      \"\\<lbrakk> wf_graph G; \\<not> c_sinvar m G \\<rbrakk> \\<Longrightarrow> c_offending_flows m G \\<noteq> {}\"\n      proof -\n        assume a1: \"wf_graph G\"\n        and    a2: \"\\<not> c_sinvar m G\"\n        have subst_set_offending_flows: \n        \"\\<And>nP. SecurityInvariant_withOffendingFlows.set_offending_flows (\\<lambda>G nP. c_sinvar m G) G nP = c_offending_flows m G\"\n        by(simp add: valid_c_offending_flows fun_eq_iff \n            SecurityInvariant_withOffendingFlows.set_offending_flows_def\n            SecurityInvariant_withOffendingFlows.is_offending_flows_min_set_def\n            SecurityInvariant_withOffendingFlows.is_offending_flows_def)\n\n        from a1 have wfG_empty: \"wf_graph \\<lparr>nodes = nodes G, edges = {}\\<rparr>\" by(simp add:wf_graph_def)\n\n        from a1 have \"\\<And>nP. \\<not> c_sinvar m G \\<Longrightarrow> SecurityInvariant_withOffendingFlows.set_offending_flows (\\<lambda>G nP. c_sinvar m G) G nP \\<noteq> {}\"\n          apply(frule_tac finite_distinct_list[OF wf_graph.finiteE])\n          apply(erule_tac exE)\n          apply(rename_tac list_edges)\n          apply(rule_tac ff=\"list_edges\" in SecurityInvariant_withOffendingFlows.mono_imp_set_offending_flows_not_empty[OF sinvar_monoI])\n          by(auto simp add: SecurityInvariant_withOffendingFlows.is_offending_flows_def delete_edges_simp2 defined_offending[OF wfG_empty])\n      \n          thus ?thesis by(simp add: a2 subst_set_offending_flows)\n    qed\n\n    (* The offending flows definitions are equal, compatibility *)\n    lemma subst_offending_flows: \"\\<And> nP. SecurityInvariant_withOffendingFlows.set_offending_flows (\\<lambda>G nP. c_sinvar m G) G nP = c_offending_flows m G\"\n      apply (unfold SecurityInvariant_withOffendingFlows.set_offending_flows_def\n            SecurityInvariant_withOffendingFlows.is_offending_flows_min_set_def\n            SecurityInvariant_withOffendingFlows.is_offending_flows_def)\n      by(simp add: valid_c_offending_flows)\n\n    text{* all the @{term SecurityInvariant_preliminaries} stuff must hold, for an arbitrary @{term nP} *}\n    lemma SecurityInvariant_preliminariesD:\n      \"SecurityInvariant_preliminaries (\\<lambda> (G::('v::vertex) graph) (nP::'v \\<Rightarrow> 'a). c_sinvar m G)\"\n      proof(unfold_locales, goal_cases)\n      case 1 thus ?case using defined_offending' by(simp add: subst_offending_flows)\n      next case 2 thus ?case by(fact mono_sinvar)\n      next case 3 thus ?case by(fact SecurityInvariant_withOffendingFlows.sinvar_mono_imp_is_offending_flows_mono[OF sinvar_monoI])\n      qed\n\n    lemma negative_mono:\n     \"\\<And> N E' E. wf_graph \\<lparr> nodes = N, edges = E \\<rparr> \\<Longrightarrow> \n        E' \\<subseteq> E \\<Longrightarrow> \\<not> c_sinvar m \\<lparr> nodes = N, edges = E' \\<rparr> \\<Longrightarrow> \\<not> c_sinvar m \\<lparr> nodes = N, edges = E \\<rparr>\"\n     by(blast dest: mono_sinvar)\n\n    \n    subsection{*Reusing Lemmata*}\n      lemmas mono_extend_set_offending_flows =\n      SecurityInvariant_preliminaries.mono_extend_set_offending_flows[OF SecurityInvariant_preliminariesD, simplified subst_offending_flows]\n      text{*@{thm mono_extend_set_offending_flows [no_vars]}*}\n\n      lemmas offending_flows_union_mono =\n      SecurityInvariant_preliminaries.offending_flows_union_mono[OF SecurityInvariant_preliminariesD, simplified subst_offending_flows]\n      text{*@{thm offending_flows_union_mono [no_vars]}*}\n\n      lemmas sinvar_valid_remove_flattened_offending_flows =\n      SecurityInvariant_preliminaries.sinvar_valid_remove_flattened_offending_flows[OF SecurityInvariant_preliminariesD, simplified subst_offending_flows]\n      text{*@{thm sinvar_valid_remove_flattened_offending_flows [no_vars]}*}\n\n      lemmas sinvar_valid_remove_SOME_offending_flows =\n      SecurityInvariant_preliminaries.sinvar_valid_remove_SOME_offending_flows[OF SecurityInvariant_preliminariesD, simplified subst_offending_flows]\n      text{*@{thm sinvar_valid_remove_SOME_offending_flows [no_vars]}*}\n\n\n      lemmas sinvar_valid_remove_minimalize_offending_overapprox =\n      SecurityInvariant_preliminaries.sinvar_valid_remove_minimalize_offending_overapprox[OF SecurityInvariant_preliminariesD, simplified subst_offending_flows]\n      text{*@{thm sinvar_valid_remove_minimalize_offending_overapprox [no_vars]}*}\n      \n\n      lemmas empty_offending_contra =\n      SecurityInvariant_withOffendingFlows.empty_offending_contra[where sinvar=\"(\\<lambda>G nP. c_sinvar m G)\", simplified subst_offending_flows]\n      text{*@{thm empty_offending_contra [no_vars]}*}\n\n      lemmas Un_set_offending_flows_bound_minus_subseteq = \n      SecurityInvariant_preliminaries.Un_set_offending_flows_bound_minus_subseteq[OF SecurityInvariant_preliminariesD, simplified subst_offending_flows]\n      text{*@{thm Un_set_offending_flows_bound_minus_subseteq [no_vars]}*}\n\n      lemmas Un_set_offending_flows_bound_minus_subseteq' = \n      SecurityInvariant_preliminaries.Un_set_offending_flows_bound_minus_subseteq'[OF SecurityInvariant_preliminariesD, simplified subst_offending_flows]\n      text{*@{thm Un_set_offending_flows_bound_minus_subseteq' [no_vars]}*}\nend\n\nthm configured_SecurityInvariant_def\ntext{*@{thm configured_SecurityInvariant_def [no_vars]}*}\n\nthm configured_SecurityInvariant.mono_sinvar\ntext{*@{thm configured_SecurityInvariant.mono_sinvar [no_vars]}*}\n\n\n\ntext{* \n  Naming convention:\n    m :: network security requirement\n    M :: network security requirement list\n*}\n\n  text{* The function @{term new_configured_SecurityInvariant} takes some tuple and if it returns a result,\n         the locale assumptions are automatically fulfilled. *}\n  theorem new_configured_SecurityInvariant_sound: \n  \"\\<lbrakk> new_configured_SecurityInvariant (sinvar, defbot, receiver_violation, nP) = Some m \\<rbrakk> \\<Longrightarrow>\n    configured_SecurityInvariant m\"\n    proof -\n      assume a: \"new_configured_SecurityInvariant (sinvar, defbot, receiver_violation, nP) = Some m\"\n      hence NetModel: \"SecurityInvariant sinvar defbot receiver_violation\"\n        by(simp add: new_configured_SecurityInvariant.simps split: if_split_asm)\n      hence NetModel_p: \"SecurityInvariant_preliminaries sinvar\" by(simp add: SecurityInvariant_def)\n\n      from a have c_eval: \"c_sinvar m = (\\<lambda>G. sinvar G nP)\"\n         and c_offending: \"c_offending_flows m = (\\<lambda>G. SecurityInvariant_withOffendingFlows.set_offending_flows sinvar G nP)\"\n         and \"c_isIFS m = receiver_violation\"\n        by(auto simp add: new_configured_SecurityInvariant.simps NetModel split: if_split_asm)\n\n      have monoI: \"SecurityInvariant_withOffendingFlows.sinvar_mono sinvar\"\n        apply(simp add: SecurityInvariant_withOffendingFlows.sinvar_mono_def, clarify)\n        by(fact SecurityInvariant_preliminaries.mono_sinvar[OF NetModel_p])\n      from SecurityInvariant_withOffendingFlows.valid_empty_edges_iff_exists_offending_flows[OF monoI, symmetric]\n            SecurityInvariant_preliminaries.defined_offending[OF NetModel_p]\n      have eval_empty_graph: \"\\<And> N nP. wf_graph \\<lparr>nodes = N, edges = {}\\<rparr> \\<Longrightarrow> sinvar \\<lparr>nodes = N, edges = {}\\<rparr> nP\"\n      by fastforce\n\n       show ?thesis\n        apply(unfold_locales)\n          apply(simp add: c_eval c_offending SecurityInvariant_withOffendingFlows.set_offending_flows_def SecurityInvariant_withOffendingFlows.is_offending_flows_min_set_def SecurityInvariant_withOffendingFlows.is_offending_flows_def)\n         apply(simp add: c_eval eval_empty_graph)\n        apply(simp add: c_eval,drule(3) SecurityInvariant_preliminaries.mono_sinvar[OF NetModel_p])\n        done\n   qed\n\ntext{* All security invariants are valid according to the definition *}\ndefinition valid_reqs :: \"('v::vertex) SecurityInvariant_configured list \\<Rightarrow> bool\" where\n  \"valid_reqs M \\<equiv> \\<forall> m \\<in> set M. configured_SecurityInvariant m\"\n\n subsection {*Algorithms*}\n    text{*A (generic) security invariant corresponds to a type of security requirements (type: @{typ \"'v graph \\<Rightarrow> ('v \\<Rightarrow> 'a) \\<Rightarrow> bool\"}).\n          A configured security invariant is a security requirement in a scenario specific setting (type: @{typ \"'v graph \\<Rightarrow> bool\"}).\n          I.e., it is a security requirement as listed in the requirements document.\n          All security requirements are fulfilled for a fixed policy @{term G} if all security requirements are fulfilled for @{term G}. *}\n\n\n    text{*Get all possible offending flows from all security requirements *}\n    definition get_offending_flows :: \"'v SecurityInvariant_configured list \\<Rightarrow> 'v graph \\<Rightarrow> (('v \\<times> 'v) set set)\" where\n      \"get_offending_flows M G = (\\<Union>m\\<in>set M. c_offending_flows m G)\"  \n\n    (*Note: only checks sinvar, not eval!! No 'a 'b type variables here*)\n    definition all_security_requirements_fulfilled :: \"('v::vertex) SecurityInvariant_configured list \\<Rightarrow> 'v graph \\<Rightarrow> bool\" where\n      \"all_security_requirements_fulfilled M G \\<equiv> \\<forall>m \\<in> set M. (c_sinvar m) G\"\n    \n    text{* Generate a valid topology from the security requirements *}\n    (*constant G, remove after algorithm*)\n    fun generate_valid_topology :: \"'v SecurityInvariant_configured list \\<Rightarrow> 'v graph \\<Rightarrow> 'v graph\" where\n      \"generate_valid_topology [] G = G\" |\n      \"generate_valid_topology (m#Ms) G = delete_edges (generate_valid_topology Ms G) (\\<Union> (c_offending_flows m G))\"\n\n     -- \"return all Access Control Strategy models from a list of models\"\n    definition get_ACS :: \"('v::vertex) SecurityInvariant_configured list \\<Rightarrow> 'v SecurityInvariant_configured list\" where\n      \"get_ACS M \\<equiv> [m \\<leftarrow> M. \\<not> c_isIFS m]\"\n     -- \"return all Information Flows Strategy models from a list of models\"\n    definition get_IFS :: \"('v::vertex) SecurityInvariant_configured list \\<Rightarrow> 'v SecurityInvariant_configured list\" where\n      \"get_IFS M \\<equiv> [m \\<leftarrow> M. c_isIFS m]\"\n    lemma get_ACS_union_get_IFS: \"set (get_ACS M) \\<union> set (get_IFS M) = set M\"\n      by(auto simp add: get_ACS_def get_IFS_def)\n  \n\n   subsection{*Lemmata*}\n    lemma valid_reqs1: \"valid_reqs (m # M) \\<Longrightarrow> configured_SecurityInvariant m\"\n      by(simp add: valid_reqs_def)\n    lemma valid_reqs2: \"valid_reqs (m # M) \\<Longrightarrow> valid_reqs M\"\n      by(simp add: valid_reqs_def)\n    lemma get_offending_flows_alt1: \"get_offending_flows M G = \\<Union> {c_offending_flows m G | m. m \\<in> set M}\"\n      apply(simp add: get_offending_flows_def)\n      by fastforce\n    lemma get_offending_flows_un: \"\\<Union> get_offending_flows M G = (\\<Union>m\\<in>set M. \\<Union>c_offending_flows m G)\"\n      apply(simp add: get_offending_flows_def)\n      by blast\n  \n  \n    lemma all_security_requirements_fulfilled_mono:\n      \"\\<lbrakk> valid_reqs M; E' \\<subseteq> E; wf_graph \\<lparr> nodes = V, edges = E \\<rparr> \\<rbrakk> \\<Longrightarrow>  \n        all_security_requirements_fulfilled M \\<lparr> nodes = V, edges = E \\<rparr> \\<Longrightarrow>\n        all_security_requirements_fulfilled M \\<lparr> nodes = V, edges = E' \\<rparr>\"\n        apply(induction M arbitrary: E' E)\n         apply(simp_all add: all_security_requirements_fulfilled_def)\n        apply(rename_tac m M E' E)\n        apply(rule conjI)\n         apply(erule(2) configured_SecurityInvariant.mono_sinvar[OF valid_reqs1])\n         apply(simp_all)\n        apply(drule valid_reqs2)\n        apply blast\n        done\n\n    subsection{* generate valid topology *}\n    (*\n      lemma generate_valid_topology_def_delete_multiple: \n        \"generate_valid_topology M G = delete_edges (generate_valid_topology M G) (\\<Union> (get_offending_flows M G))\"\n        proof(induction M arbitrary: G)\n          case Nil\n            thus ?case by(simp add: get_offending_flows_def)\n          next\n          case (Cons m M)\n            from Cons[simplified delete_edges_simp2 get_offending_flows_def] \n            have \"edges (generate_valid_topology M G) = edges (generate_valid_topology M G) - \\<Union>(\\<Union>m\\<in>set M. c_offending_flows m G)\"\n              by (metis graph.select_convs(2))\n            thus ?case\n              apply(simp add: get_offending_flows_def delete_edges_simp2)\n              by blast\n        qed*)\n      lemma generate_valid_topology_nodes:\n      \"nodes (generate_valid_topology M G) = (nodes G)\"\n        apply(induction M arbitrary: G)\n         by(simp_all add: graph_ops)\n\n      lemma generate_valid_topology_def_alt:\n        \"generate_valid_topology M G = delete_edges G (\\<Union> (get_offending_flows M G))\"\n        proof(induction M arbitrary: G)\n          case Nil\n            thus ?case by(simp add: get_offending_flows_def)\n          next\n          case (Cons m M)\n            from Cons[simplified delete_edges_simp2 get_offending_flows_def] \n            have \"edges (generate_valid_topology M G) = edges G - \\<Union>(\\<Union>m\\<in>set M. c_offending_flows m G)\"\n              by (metis graph.select_convs(2))\n            thus ?case\n              apply(simp add: get_offending_flows_def delete_edges_simp2)\n              apply(rule)\n               apply(simp add: generate_valid_topology_nodes)\n              by blast\n        qed\n    \n      lemma wf_graph_generate_valid_topology: \"wf_graph G \\<Longrightarrow> wf_graph (generate_valid_topology M G)\"\n        proof(induction M arbitrary: G)\n        qed(simp_all)\n  \n     lemma generate_valid_topology_mono_models:\n      \"edges (generate_valid_topology (m#M) \\<lparr> nodes = V, edges = E \\<rparr>) \\<subseteq> edges (generate_valid_topology M \\<lparr> nodes = V, edges = E \\<rparr>)\"\n        proof(induction M arbitrary: E m)\n        case Nil thus ?case by(simp add: delete_edges_simp2) fastforce\n        case Cons thus ?case by(simp add: delete_edges_simp2) blast\n      qed\n     \n      lemma generate_valid_topology_subseteq_edges:\n      \"edges (generate_valid_topology M G) \\<subseteq> (edges G)\"\n        proof(induction M arbitrary: G)\n        case Cons thus ?case by (simp add: delete_edges_simp2) blast\n        qed(simp)\n\n      text{* @{term generate_valid_topology} generates a valid topology (Policy)! *}\n      theorem generate_valid_topology_sound:\n      \"\\<lbrakk> valid_reqs M; wf_graph \\<lparr>nodes = V, edges = E\\<rparr> \\<rbrakk> \\<Longrightarrow> \n      all_security_requirements_fulfilled M (generate_valid_topology M \\<lparr>nodes = V, edges = E\\<rparr>)\"\n        proof(induction M arbitrary: V E)\n          case Nil\n          thus ?case by(simp add: all_security_requirements_fulfilled_def)\n        next\n          case (Cons m M)\n          from valid_reqs1[OF Cons(2)] have validReq: \"configured_SecurityInvariant m\" .\n\n          from Cons(3) have valid_rmUnOff: \"wf_graph \\<lparr>nodes = V, edges = E - (\\<Union>c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>) \\<rparr>\"\n            by(simp add: wf_graph_remove_edges)\n          \n          from configured_SecurityInvariant.sinvar_valid_remove_flattened_offending_flows[OF validReq Cons(3)]\n          have valid_eval_rmUnOff: \"c_sinvar m \\<lparr>nodes = V, edges = E - (\\<Union>c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>) \\<rparr>\" .\n    \n          from generate_valid_topology_subseteq_edges have edges_gentopo_subseteq: \n            \"(edges (generate_valid_topology M \\<lparr>nodes = V, edges = E\\<rparr>)) - (\\<Union>c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>)\n               \\<subseteq>\n            E - (\\<Union>c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>)\"  by fastforce\n    \n          from configured_SecurityInvariant.mono_sinvar[OF validReq valid_rmUnOff edges_gentopo_subseteq valid_eval_rmUnOff]\n          have \"c_sinvar m \\<lparr>nodes = V, edges = (edges (generate_valid_topology M \\<lparr>nodes = V, edges = E\\<rparr>)) - (\\<Union>c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>) \\<rparr>\" .\n          from this have goal1: \n            \"c_sinvar m (delete_edges (generate_valid_topology M \\<lparr>nodes = V, edges = E\\<rparr>) (\\<Union>c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>))\"\n               by(simp add: delete_edges_simp2 generate_valid_topology_nodes)\n    \n          from valid_reqs2[OF Cons(2)] have \"valid_reqs M\" .\n          from Cons.IH[OF `valid_reqs M` Cons(3)] have IH:\n            \"all_security_requirements_fulfilled M (generate_valid_topology M \\<lparr>nodes = V, edges = E\\<rparr>)\" .\n\n          have generate_valid_topology_EX_graph_record:\n            \"\\<exists> hypE. (generate_valid_topology M \\<lparr>nodes = V, edges = E\\<rparr>) = \\<lparr>nodes = V, edges = hypE\\<rparr> \"\n              apply(induction M arbitrary: V E)\n               by(simp_all add: delete_edges_simp2 generate_valid_topology_nodes)\n              \n          from generate_valid_topology_EX_graph_record obtain E_IH where  E_IH_prop:\n            \"(generate_valid_topology M \\<lparr>nodes = V, edges = E\\<rparr>) = \\<lparr>nodes = V, edges = E_IH\\<rparr>\" by blast\n    \n          from wf_graph_generate_valid_topology[OF Cons(3)] E_IH_prop\n          have valid_G_E_IH: \"wf_graph \\<lparr>nodes = V, edges = E_IH\\<rparr>\" by metis\n    \n          -- \"@{thm IH[simplified E_IH_prop]}\"\n          -- \"@{thm all_security_requirements_fulfilled_mono[OF `valid_reqs M` _  valid_G_E_IH IH[simplified E_IH_prop]]}\"\n    \n          from all_security_requirements_fulfilled_mono[OF `valid_reqs M` _  valid_G_E_IH IH[simplified E_IH_prop]] have mono_rule:\n            \"\\<And> E'. E' \\<subseteq> E_IH \\<Longrightarrow> all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = E'\\<rparr>\" .\n    \n          have \"all_security_requirements_fulfilled M \n            (delete_edges (generate_valid_topology M \\<lparr>nodes = V, edges = E\\<rparr>) (\\<Union>c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>))\"\n            apply(subst E_IH_prop)\n            apply(simp add: delete_edges_simp2)\n            apply(rule mono_rule)\n            by fast\n    \n          from this have goal2:\n            \"(\\<forall>ma\\<in>set M.\n            c_sinvar ma (delete_edges (generate_valid_topology M \\<lparr>nodes = V, edges = E\\<rparr>) (\\<Union>c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>)))\"\n            by(simp add: all_security_requirements_fulfilled_def)\n    \n          from goal1 goal2 \n          show  \"all_security_requirements_fulfilled (m # M) (generate_valid_topology (m # M) \\<lparr>nodes = V, edges = E\\<rparr>)\" \n          by (simp add: all_security_requirements_fulfilled_def)\n       qed\n\n\n  lemma generate_valid_topology_as_set: \n  \"generate_valid_topology M G = delete_edges G (\\<Union>m \\<in> set M. (\\<Union> (c_offending_flows m G)))\"\n   apply(induction M arbitrary: G)\n    apply(simp_all add: delete_edges_simp2 generate_valid_topology_nodes) by fastforce\n\n  lemma c_offending_flows_subseteq_edges: \"configured_SecurityInvariant m \\<Longrightarrow> \\<Union>c_offending_flows m G \\<subseteq> edges G\"\n    apply(clarify)\n    apply(simp only: configured_SecurityInvariant.valid_c_offending_flows)\n    apply(thin_tac \"configured_SecurityInvariant x\" for x)\n    by auto\n\n\n  text{*Does it also generate a maximum topology? It does, if the security invariants are in ENF-form. That means, if \n        all security invariants can be expressed as a predicate over the edges, \n        @{term \"\\<exists>P. \\<forall>G. c_sinvar m G = (\\<forall>(v1,v2) \\<in> edges G. P (v1,v2))\"}*}\n  definition max_topo :: \"('v::vertex) SecurityInvariant_configured list \\<Rightarrow> 'v graph \\<Rightarrow> bool\" where\n    \"max_topo M G \\<equiv> all_security_requirements_fulfilled M G \\<and> (\n      \\<forall> (v1, v2) \\<in> (nodes G \\<times> nodes G) - (edges G). \\<not> all_security_requirements_fulfilled M (add_edge v1 v2 G))\"\n\n  lemma unique_offending_obtain: \n    assumes m: \"configured_SecurityInvariant m\" and unique: \"c_offending_flows m G = {F}\"\n    obtains P where \"F = {(v1, v2) \\<in> edges G. \\<not> P (v1, v2)}\" and \"c_sinvar m G = (\\<forall>(v1,v2) \\<in> edges G. P (v1, v2))\" and \n                    \"(\\<forall>(v1,v2) \\<in> edges G - F. P (v1, v2))\"\n    proof -\n    assume EX: \"(\\<And>P. F = {(v1, v2). (v1, v2) \\<in> edges G \\<and> \\<not> P (v1, v2)} \\<Longrightarrow> c_sinvar m G = (\\<forall>(v1, v2)\\<in>edges G. P (v1, v2)) \\<Longrightarrow> \\<forall>(v1, v2)\\<in>edges G - F. P (v1, v2) \\<Longrightarrow> thesis)\"\n\n    from unique c_offending_flows_subseteq_edges[OF m] have \"F \\<subseteq> edges G\" by force\n    from this obtain P where \"F = {e \\<in> edges G. \\<not> P e}\" by (metis double_diff set_diff_eq subset_refl)\n    hence 1: \"F = {(v1, v2) \\<in> edges G. \\<not> P (v1, v2)}\" by auto\n\n    from configured_SecurityInvariant.valid_c_offending_flows[OF m] have \"c_offending_flows m G =\n          {F. F \\<subseteq> edges G \\<and> \\<not> c_sinvar m G \\<and> c_sinvar m (delete_edges G F) \\<and> \n              (\\<forall>(e1, e2)\\<in>F. \\<not> c_sinvar m (add_edge e1 e2 (delete_edges G F)))}\" .\n\n    from this unique have \"\\<not> c_sinvar m G\" and 2: \"c_sinvar m (delete_edges G F)\" and \n                          3: \"(\\<forall>(e1, e2)\\<in>F. \\<not> c_sinvar m (add_edge e1 e2 (delete_edges G F)))\" by auto\n\n    from this `F = {e \\<in> edges G. \\<not> P e}` have x3: \"\\<forall> e \\<in> edges G - F. P e\" by (metis (lifting) mem_Collect_eq set_diff_eq)\n    hence 4: \"\\<forall>(v1,v2) \\<in> edges G - F. P (v1, v2)\" by blast\n\n    have \"F \\<noteq> {}\" by (metis assms(1) assms(2) configured_SecurityInvariant.empty_offending_contra insertCI)\n    from this `F = {e \\<in> edges G. \\<not> P e}` `\\<not> c_sinvar m G` have 5: \"c_sinvar m G = (\\<forall>(v1,v2) \\<in> edges G. P (v1, v2))\"\n      apply(simp add: graph_ops)\n      by(blast)\n\n    from EX[of P] unique 1 x3 5 show ?thesis by fast\n  qed\n\n  lemma enf_offending_flows:\n    assumes vm: \"configured_SecurityInvariant m\" and enf: \"\\<forall>G. c_sinvar m G = (\\<forall>e \\<in> edges G. P e)\"\n    shows \"\\<forall>G. c_offending_flows m G = (if c_sinvar m G then {} else {{e \\<in> edges G. \\<not> P e}})\"\n    proof -\n      { fix G\n        from vm configured_SecurityInvariant.valid_c_offending_flows have offending_formaldef:\n          \"c_offending_flows m G =\n            {F. F \\<subseteq> edges G \\<and> \\<not> c_sinvar m G \\<and> c_sinvar m (delete_edges G F) \\<and>\n                (\\<forall>(e1, e2)\\<in>F. \\<not> c_sinvar m (add_edge e1 e2 (delete_edges G F)))}\" by auto\n        have \"c_offending_flows m G = (if c_sinvar m G then {} else {{e \\<in> edges G. \\<not> P e}})\"\n          proof(cases \"c_sinvar m G\")\n          case True thus ?thesis --{*@{term \"{}\"}*}\n            by(simp add: offending_formaldef)\n          next\n          case False thus ?thesis by(auto simp add: offending_formaldef graph_ops enf)\n        qed\n      } thus ?thesis by simp\n    qed\n      \n      \nlemma enf_not_fulfilled_if_in_offending:\n  assumes validRs: \"valid_reqs M\"\n    and   wfG:     \"wf_graph G\"\n    and   enf:     \"\\<forall>m \\<in> set M. \\<exists>P. \\<forall>G. c_sinvar m G = (\\<forall>e \\<in> edges G. P e)\"\n    shows \"\\<forall>x \\<in> (\\<Union>m\\<in>set M. \\<Union>c_offending_flows m (fully_connected G)).\n                \\<not> all_security_requirements_fulfilled M \\<lparr> nodes = V, edges = insert x E\\<rparr>\"\n   unfolding all_security_requirements_fulfilled_def\n   proof(simp, clarify, rename_tac m F a b)\n     let ?G=\"(fully_connected G)\"\n     fix m F v1 v2\n     assume \"m \\<in> set M\" and \"F \\<in> c_offending_flows m ?G\" and \"(v1, v2) \\<in> F\"\n       \n    from validRs have valid_mD:\"\\<And>m. m \\<in> set M \\<Longrightarrow> configured_SecurityInvariant m \" \n      by(simp add: valid_reqs_def)\n    \n     from `m \\<in> set M` valid_mD have \"configured_SecurityInvariant m\" by simp\n\n     from enf `m \\<in> set M` obtain P where enf_m: \"\\<forall>G. c_sinvar m G = (\\<forall>e\\<in>edges G. P e)\" by blast\n     \n     from `(v1, v2) \\<in> F` have \"F \\<noteq> {}\" by auto\n\n     from enf_offending_flows[OF `configured_SecurityInvariant m` `\\<forall>G. c_sinvar m G = (\\<forall>e\\<in>edges G. P e)`] have\n      offending: \"\\<And>G. c_offending_flows m G = (if c_sinvar m G then {} else {{e \\<in> edges G. \\<not> P e}})\" by simp\n     from `F \\<in> c_offending_flows m ?G` `F \\<noteq> {}` have \"F = {e \\<in> edges ?G. \\<not> P e}\"\n       by(simp split: if_split_asm add: offending)\n     from this `(v1, v2) \\<in> F`  have \"\\<not> P (v1, v2)\" by simp\n\n     from this enf_m have \"\\<not> c_sinvar m \\<lparr>nodes = V, edges = insert (v1, v2) E\\<rparr>\" by(simp)\n     thus \"\\<exists>m\\<in>set M. \\<not> c_sinvar m \\<lparr>nodes = V, edges = insert (v1, v2) E\\<rparr>\" using `m \\<in> set M`\n      apply(rule_tac x=\"m\" in bexI)\n       by simp_all\nqed\n        \n\n theorem generate_valid_topology_max_topo: \"\\<lbrakk> valid_reqs M; wf_graph G;\n      \\<forall>m \\<in> set M. \\<exists>P. \\<forall>G. c_sinvar m G = (\\<forall>e \\<in> edges G. P e)\\<rbrakk> \\<Longrightarrow> \n      max_topo M (generate_valid_topology M (fully_connected G))\"\n  proof -\n    let ?G=\"(fully_connected G)\"\n    assume validRs: \"valid_reqs M\"\n    and    wfG:       \"wf_graph G\"\n    and enf: \"\\<forall>m \\<in> set M. \\<exists>P. \\<forall>G. c_sinvar m G = (\\<forall>e \\<in> edges G. P e)\"\n\n    obtain V E where VE_prop: \"\\<lparr> nodes = V, edges = E \\<rparr> = generate_valid_topology M ?G\" by (metis graph.cases)\n    hence VE_prop_asset:\n      \"\\<lparr> nodes = V, edges = E \\<rparr> = \\<lparr> nodes = V, edges = V \\<times> V - (\\<Union>m\\<in>set M. \\<Union>c_offending_flows m ?G)\\<rparr>\"\n      by(simp add: fully_connected_def generate_valid_topology_as_set delete_edges_simp2)\n\n    from VE_prop_asset have E_prop: \"E =  V \\<times> V - (\\<Union>m\\<in>set M. \\<Union>c_offending_flows m ?G)\" by fast\n    from VE_prop have V_prop: \"nodes G = V\"\n      by (simp add: fully_connected_def delete_edges_simp2 generate_valid_topology_def_alt)\n    from VE_prop have V_full_prop: \"nodes (generate_valid_topology M ?G) = V\" by (metis graph.select_convs(1))\n    from VE_prop have E_full_prop: \"edges (generate_valid_topology M ?G) = E\" by (metis graph.select_convs(2))\n\n    from VE_prop wf_graph_generate_valid_topology[OF fully_connected_wf[OF wfG]]\n    have wfG_VE: \"wf_graph \\<lparr> nodes = V, edges = E \\<rparr>\" by force\n\n    from generate_valid_topology_sound[OF validRs wfG_VE] fully_connected_wf[OF wfG] have VE_all_valid: \n      \"all_security_requirements_fulfilled M \\<lparr> nodes = V, edges = V \\<times> V - (\\<Union>m\\<in>set M. \\<Union>c_offending_flows m ?G)\\<rparr>\"\n      by (metis VE_prop VE_prop_asset fully_connected_def generate_valid_topology_sound validRs)\n    hence goal1: \"all_security_requirements_fulfilled M (generate_valid_topology M (fully_connected G))\" by (metis VE_prop VE_prop_asset)\n\n    from validRs have valid_mD:\"\\<And>m. m \\<in> set M \\<Longrightarrow> configured_SecurityInvariant m \" \n      by(simp add: valid_reqs_def)\n\n    from c_offending_flows_subseteq_edges[where G=\"?G\"] validRs have hlp1: \"(\\<Union>m\\<in>set M. \\<Union>c_offending_flows m ?G) \\<subseteq> V \\<times> V\"\n      apply(simp add: fully_connected_def V_prop)\n      using valid_reqs_def by blast\n    have \"\\<And>A B. A - (A - B) = B \\<inter> A\" by fast \n    from E_prop hlp1 have \"V \\<times> V - E = (\\<Union>m\\<in>set M. \\<Union>c_offending_flows m ?G)\" by force\n\n\n    from enf_not_fulfilled_if_in_offending[OF validRs wfG enf]\n    have \"\\<forall>(v1, v2) \\<in> (\\<Union>m\\<in>set M. \\<Union>c_offending_flows m ?G).\n       \\<not> all_security_requirements_fulfilled M \\<lparr> nodes = V, edges = E \\<union> {(v1, v2)}\\<rparr>\" by simp\n          \n    from this `V \\<times> V - E = (\\<Union>m\\<in>set M. \\<Union>c_offending_flows m ?G)` have \"\\<forall>(v1, v2) \\<in> V \\<times> V - E.\n         \\<not> all_security_requirements_fulfilled M \\<lparr> nodes = V, edges = E \\<union> {(v1, v2)}\\<rparr>\" by simp\n    hence goal2: \"(\\<forall>(v1, v2)\\<in>nodes (generate_valid_topology M ?G) \\<times> nodes (generate_valid_topology M ?G) -\n                edges (generate_valid_topology M ?G).\n        \\<not> all_security_requirements_fulfilled M (add_edge v1 v2 (generate_valid_topology M ?G)))\"\n    proof(unfold V_full_prop E_full_prop graph_ops)\n      assume a: \"\\<forall>(v1, v2)\\<in>V \\<times> V - E. \\<not> all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = E \\<union> {(v1, v2)}\\<rparr>\"\n      have \"\\<forall>(v1, v2)\\<in>V \\<times> V - E.  V \\<union> {v1, v2} = V\" by blast\n      hence \"\\<forall>(v1, v2)\\<in>V \\<times> V - E. \\<lparr>nodes = V \\<union> {v1, v2}, edges = {(v1, v2)} \\<union> E\\<rparr> = \\<lparr>nodes = V, edges = E \\<union> {(v1, v2)}\\<rparr>\" by blast\n      from this a show \"\\<forall>(v1, v2)\\<in>V \\<times> V - E. \\<not> all_security_requirements_fulfilled M \\<lparr>nodes = V \\<union> {v1, v2}, edges = {(v1, v2)} \\<union> E\\<rparr>\"\n        --\"TODO: this should be trivial ...\"\n        apply(simp)\n        apply(rule ballI)\n        apply(erule_tac x=x and A=\"V \\<times> V - E\" in ballE)\n         prefer 2 apply(simp; fail)\n        apply(erule_tac x=x and A=\"V \\<times> V - E\" in ballE)\n         prefer 2 apply(simp; fail)\n        apply(clarify)\n        by presburger\n    qed\n     \n    from goal1 goal2 show ?thesis\n      unfolding max_topo_def by presburger\n  qed\n\n  lemma enf_all_valid_policy_subset_of_max:\n    assumes validRs: \"valid_reqs M\"\n    and     wfG:     \"wf_graph G\"\n    and     enf:     \"\\<forall>m \\<in> set M. \\<exists>P. \\<forall>G. c_sinvar m G = (\\<forall>e \\<in> edges G. P e)\"\n    and     nodesG': \"nodes G = nodes G'\"\n    shows \"\\<lbrakk> wf_graph G';\n        all_security_requirements_fulfilled M G'\\<rbrakk> \\<Longrightarrow> \n        edges G' \\<subseteq> edges (generate_valid_topology M (fully_connected G))\"\n    using nodesG' apply(cases \"generate_valid_topology M (fully_connected G)\", rename_tac V E, simp)\n    apply(cases \"G'\", rename_tac V' E', simp)\n    apply(subgoal_tac \"nodes G = V\")\n     prefer 2\n     apply (metis fully_connected_def generate_valid_topology_nodes graph.select_convs(1))\n    apply(simp)\n  proof(rule ccontr)\n    fix V E V' E'\n    assume a5: \"all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = E'\\<rparr>\" and\n           a6: \"generate_valid_topology M (fully_connected G) = \\<lparr>nodes = V, edges = E\\<rparr>\" and\n           a10: \"wf_graph \\<lparr>nodes = V, edges = E'\\<rparr>\" and\n           contr: \"\\<not> E' \\<subseteq> E\"\n    \n    from wfG a6 have \"wf_graph \\<lparr>nodes = V, edges = E\\<rparr>\"\n      by (metis fully_connected_wf wf_graph_generate_valid_topology)\n    with a10 have EE'subsets: \"fst ` E \\<subseteq> V \\<and> snd ` E \\<subseteq> V \\<and> fst ` E' \\<subseteq> V \\<and> snd ` E' \\<subseteq> V\"\n      by(simp add: wf_graph_def)\n    hence EE'subsets': \"E \\<subseteq> V \\<times> V \\<and> E' \\<subseteq> V \\<times> V\" by auto\n    \n    from generate_valid_topology_max_topo[OF validRs wfG enf]\n      have m1: \"all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = E\\<rparr>\" and\n           m2: \"(\\<forall>x\\<in>V \\<times> V - E. case x of (v1, v2) \\<Rightarrow> \\<not> all_security_requirements_fulfilled M (add_edge v1 v2 \\<lparr>nodes = V, edges = E\\<rparr>))\"\n      by(simp add: max_topo_def a6)+\n        \n    from m2 have m2': \"\\<forall>x\\<in>V \\<times> V - E. \\<not> all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = insert x E\\<rparr>\"\n      apply(simp add: add_edge_def)\n      apply(rule ballI, rename_tac x)\n      apply(erule_tac x=x in ballE, simp_all)\n      apply(case_tac x, simp)\n      by (simp add: insert_absorb)\n    \n     show False\n       proof(cases \"V = {}\")\n         case True\n         with EE'subsets a10 have \"E = {}\" and \"E' = {}\"\n           by(simp add: wf_graph_def)+\n         with True contr show ?thesis by simp\n       next\n         case False\n         with EE'subsets' contr obtain x where x: \"x \\<in> E' \\<and> x \\<notin> E \\<and> x \\<in> V \\<times> V\"\n           by blast\n         from m2' x have \"\\<not> all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = insert x E\\<rparr>\"\n           by (simp)\n         \n         from a6 x have x_offedning: \"x \\<in> (\\<Union>m\\<in>set M. \\<Union>c_offending_flows m (fully_connected G))\"\n           apply(simp add: generate_valid_topology_as_set delete_edges_simp2 fully_connected_def)\n           by blast\n  \n         from enf_not_fulfilled_if_in_offending[OF validRs wfG enf] x_offedning have\n           1: \"\\<not> all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = insert x myE\\<rparr>\" for myE by blast\n         \n         from x have insertxE': \"insert x E' = E'\" by blast\n         with a5 have\n           \"all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = insert x E'\\<rparr>\" by simp\n         with insertxE' all_security_requirements_fulfilled_mono[OF validRs _ a10 a5] have \n           2: \"all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = insert x {}\\<rparr>\" by blast\n         from 1 2 show ?thesis by blast\n       qed\n  qed\n    \n\n\n   subsection{* More Lemmata *}\n     lemma (in configured_SecurityInvariant) c_sinvar_valid_imp_no_offending_flows: \n      \"c_sinvar m G \\<Longrightarrow> c_offending_flows m G = {}\"\n        by(simp add: valid_c_offending_flows)\n\n     lemma all_security_requirements_fulfilled_imp_no_offending_flows:\n        \"valid_reqs M \\<Longrightarrow> all_security_requirements_fulfilled M G \\<Longrightarrow> (\\<Union>m\\<in>set M. \\<Union>c_offending_flows m G) = {}\"\n        proof(induction M)\n        case Cons thus ?case\n          unfolding all_security_requirements_fulfilled_def\n          apply(simp)\n          by(blast dest: valid_reqs2 valid_reqs1 configured_SecurityInvariant.c_sinvar_valid_imp_no_offending_flows)\n        qed(simp)\n\n    corollary all_security_requirements_fulfilled_imp_get_offending_empty:\n      \"valid_reqs M \\<Longrightarrow> all_security_requirements_fulfilled M G \\<Longrightarrow> get_offending_flows M G = {}\"\n      apply(frule(1) all_security_requirements_fulfilled_imp_no_offending_flows)\n      apply(simp add: get_offending_flows_def)\n      apply(thin_tac \"all_security_requirements_fulfilled M G\")\n      apply(simp add: valid_reqs_def)\n      apply(clarify)\n      using configured_SecurityInvariant.empty_offending_contra by fastforce\n  \n    corollary generate_valid_topology_does_nothing_if_valid:\n      \"\\<lbrakk> valid_reqs M; all_security_requirements_fulfilled M G\\<rbrakk> \\<Longrightarrow> \n          generate_valid_topology M G = G\"\n      by(simp add: generate_valid_topology_as_set graph_ops all_security_requirements_fulfilled_imp_no_offending_flows)\n\n\n    lemma mono_extend_get_offending_flows: \"\\<lbrakk> valid_reqs M;\n         wf_graph \\<lparr>nodes = V, edges = E\\<rparr>;\n         E' \\<subseteq> E;\n         F' \\<in> get_offending_flows M \\<lparr>nodes = V, edges = E'\\<rparr> \\<rbrakk> \\<Longrightarrow>\n       \\<exists>F\\<in>get_offending_flows M \\<lparr>nodes = V, edges = E\\<rparr>. F' \\<subseteq> F\"\n     proof(induction M)\n     case Nil thus ?case by(simp add: get_offending_flows_def)\n     next\n     case (Cons m M)\n      from Cons.prems have \"configured_SecurityInvariant m\"\n                       and \"valid_reqs M\" using valid_reqs2 valid_reqs1 by blast+\n      from Cons.prems(4) have\n        \"F' \\<in> c_offending_flows m \\<lparr>nodes = V, edges = E'\\<rparr> \\<or>\n         (F' \\<in> get_offending_flows M \\<lparr>nodes = V, edges = E'\\<rparr>)\"\n       by(simp add: get_offending_flows_def)\n      from this show ?case\n       proof(elim disjE, goal_cases)\n       case 1\n         with `configured_SecurityInvariant m` Cons.prems(2,3,4) obtain F where\n           \"F\\<in>c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>\" and \"F' \\<subseteq> F\"\n           by(blast dest: configured_SecurityInvariant.mono_extend_set_offending_flows)\n         hence \"F\\<in>get_offending_flows (m # M) \\<lparr>nodes = V, edges = E\\<rparr>\"\n           by (simp add: get_offending_flows_def)\n         with `F' \\<subseteq> F` show ?case by blast\n       next\n       case 2 with Cons `valid_reqs M` show ?case by(simp add: get_offending_flows_def) blast\n       qed\n     qed\n\n     lemma get_offending_flows_subseteq_edges: \"valid_reqs M \\<Longrightarrow> F \\<in> get_offending_flows M \\<lparr>nodes = V, edges = E\\<rparr> \\<Longrightarrow> F \\<subseteq> E\"\n      apply(induction M)\n       apply(simp add: get_offending_flows_def)\n      apply(simp add: get_offending_flows_def)\n      apply(frule valid_reqs2, drule valid_reqs1)\n      apply(simp add: configured_SecurityInvariant.valid_c_offending_flows)\n      by blast\n\n    thm configured_SecurityInvariant.offending_flows_union_mono\n    lemma get_offending_flows_union_mono: \"\\<lbrakk>valid_reqs M; \n      wf_graph \\<lparr>nodes = V, edges = E\\<rparr>; E' \\<subseteq> E \\<rbrakk> \\<Longrightarrow>\n      \\<Union>get_offending_flows M \\<lparr>nodes = V, edges = E'\\<rparr> \\<subseteq> \\<Union>get_offending_flows M \\<lparr>nodes = V, edges = E\\<rparr>\"\n      apply(induction M)\n       apply(simp add: get_offending_flows_def)\n      apply(frule valid_reqs2, drule valid_reqs1)\n      apply(drule(2) configured_SecurityInvariant.offending_flows_union_mono)\n      apply(simp add: get_offending_flows_def)\n      by auto\n\n    thm configured_SecurityInvariant.Un_set_offending_flows_bound_minus_subseteq'\n    lemma Un_set_offending_flows_bound_minus_subseteq':\"\\<lbrakk>valid_reqs M; \n      wf_graph \\<lparr>nodes = V, edges = E\\<rparr>; E' \\<subseteq> E;\n      \\<Union>get_offending_flows M \\<lparr>nodes = V, edges = E\\<rparr> \\<subseteq> X \\<rbrakk> \\<Longrightarrow> \\<Union>get_offending_flows M \\<lparr>nodes = V, edges = E - E'\\<rparr> \\<subseteq> X - E'\"\n      proof(induction M)\n      case Nil thus ?case by (simp add: get_offending_flows_def)\n      next\n      case (Cons m M)\n        from Cons.prems(1) valid_reqs2 have \"valid_reqs M\" by force\n        from Cons.prems(1) valid_reqs1 have \"configured_SecurityInvariant m\" by force\n        from Cons.prems(4) have \"\\<Union>get_offending_flows M \\<lparr>nodes = V, edges = E\\<rparr> \\<subseteq> X\" by(simp add: get_offending_flows_def)\n        from Cons.IH[OF `valid_reqs M` Cons.prems(2) Cons.prems(3) `\\<Union>get_offending_flows M \\<lparr>nodes = V, edges = E\\<rparr> \\<subseteq> X`] have IH: \"\\<Union>get_offending_flows M \\<lparr>nodes = V, edges = E - E'\\<rparr> \\<subseteq> X - E'\" .\n        from Cons.prems(4) have \"\\<Union>c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> \\<subseteq> X\" by(simp add: get_offending_flows_def)\n        from configured_SecurityInvariant.Un_set_offending_flows_bound_minus_subseteq'[OF `configured_SecurityInvariant m` Cons.prems(2) `\\<Union>c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> \\<subseteq> X`] have \"\\<Union>c_offending_flows m \\<lparr>nodes = V, edges = E - E'\\<rparr> \\<subseteq> X - E'\" .\n        from this IH show ?case by(simp add: get_offending_flows_def)\n      qed\n\n \n\n\n (*ENF has uniquely defined offending flows*)\n lemma ENF_uniquely_defined_offedning: \"valid_reqs M \\<Longrightarrow> wf_graph G \\<Longrightarrow> \n      \\<forall>m \\<in> set M. \\<exists>P. \\<forall>G. c_sinvar m G = (\\<forall>e \\<in> edges G. P e) \\<Longrightarrow> \n      \\<forall>m \\<in> set M. \\<forall>G. \\<not> c_sinvar m G \\<longrightarrow>  (\\<exists>OFF. c_offending_flows m G = {OFF})\"\n apply -\n apply(induction M)\n  apply(simp; fail)\n apply(rename_tac m M)\n apply(frule valid_reqs1)\n apply(drule valid_reqs2)\n apply(simp)\n apply(elim conjE)\n apply(erule_tac x=m in ballE)\n  apply(simp_all; fail)\n apply(erule exE, rename_tac P)\n apply(drule_tac P=P in enf_offending_flows)\n  apply(simp; fail)\n apply(simp; fail)\n done\n\n lemma assumes \"configured_SecurityInvariant m\"\n       and \"\\<forall>G. \\<not> c_sinvar m G \\<longrightarrow> (\\<exists>OFF. c_offending_flows m G = {OFF})\"\n       shows \"\\<exists>OFF_P. \\<forall>G. c_offending_flows m G = (if c_sinvar m G then {} else {OFF_P G})\"\n proof -\n   from assms have \"\\<exists>OFF_P. \n          c_offending_flows m G = (if c_sinvar m G then {} else {OFF_P G})\" for G\n     apply(erule_tac x=G in allE)\n     apply(cases \"c_sinvar m G\")\n      apply(drule configured_SecurityInvariant.c_sinvar_valid_imp_no_offending_flows, simp)\n      apply(simp; fail)\n     apply(simp)\n     by meson\n   with assms show ?thesis by metis\n qed\n (*TODO: generate_valid_topology_max_topo for sinvars with unique offending flows in general*)\n\n\n\n   text{*Hilber's eps operator example*}\n   lemma \"(SOME x. x : {1::nat, 2, 3}) = x \\<Longrightarrow> x = 1 \\<or> x = 2 \\<or> x = 3\"\n     proof -\n      have \"(SOME x. x \\<in> {1::nat, 2, 3}) \\<in> {1::nat, 2, 3}\" unfolding some_in_eq by simp\n      thus \"(SOME x. x : {1::nat, 2, 3}) = x \\<Longrightarrow> x = 1 \\<or> x = 2 \\<or> x = 3\" by fast\n     qed\n\n  (*TODO: remove the offending flows from the graph for each iteration. requires proof arbitrary: G\n          allows to put expensive invariants at back of list and hope that sinvar is true until the are evaluated*)\n  text{*Only removing one offending flow should be enough*}\n  fun generate_valid_topology_SOME :: \"'v SecurityInvariant_configured list \\<Rightarrow> 'v graph \\<Rightarrow> 'v graph\" where\n    \"generate_valid_topology_SOME [] G = G\" |\n    \"generate_valid_topology_SOME (m#Ms) G = (if c_sinvar m G\n      then generate_valid_topology_SOME Ms G\n      else delete_edges (generate_valid_topology_SOME Ms G) (SOME F. F \\<in> c_offending_flows m G)\n      )\"\n\n  lemma generate_valid_topology_SOME_nodes: \"nodes (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>) = V\"\n    proof(induction M)\n    qed(simp_all add: delete_edges_simp2)\n\n  theorem generate_valid_topology_SOME_sound:\n    \"\\<lbrakk> valid_reqs M; wf_graph \\<lparr>nodes = V, edges = E\\<rparr> \\<rbrakk> \\<Longrightarrow> \n    all_security_requirements_fulfilled M (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>)\"\n      proof(induction M)\n        case Nil\n        thus ?case by(simp add: all_security_requirements_fulfilled_def)\n      next\n        case (Cons m M)\n        from valid_reqs1[OF Cons(2)] have validReq: \"configured_SecurityInvariant m\" .\n        \n        from configured_SecurityInvariant.sinvar_valid_remove_SOME_offending_flows[OF validReq] have\n         \"c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> \\<noteq> {} \\<Longrightarrow>\n           c_sinvar m \\<lparr>nodes = V, edges = E - (SOME F. F \\<in> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>)\\<rparr>\" .\n\n        have generate_valid_topology_SOME_edges: \"edges (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>) \\<subseteq> E\"\n          for M::\"'a SecurityInvariant_configured list\" and V E\n          proof(induction M)\n          qed(auto simp add: delete_edges_simp2)\n\n        from configured_SecurityInvariant.mono_sinvar[OF validReq Cons.prems(2),\n              of \"edges (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>)\"]\n            generate_valid_topology_SOME_edges\n          have \"c_sinvar m \\<lparr>nodes = V, edges = E\\<rparr> \\<Longrightarrow>\n            c_sinvar m \\<lparr>nodes = V, edges = edges (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>)\\<rparr>\"\n          by simp\n        moreover from configured_SecurityInvariant.defined_offending'[OF validReq Cons.prems(2)] have not_sinvar_off:\n          \"\\<not> c_sinvar m \\<lparr>nodes = V, edges = E\\<rparr> \\<Longrightarrow> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> \\<noteq> {}\" by blast\n        ultimately have goal_sinvar_m:\n          \"c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> = {} \\<Longrightarrow> \n              c_sinvar m (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>)\"\n           using generate_valid_topology_SOME_nodes \n           by (metis graph.select_convs(1) graph.select_convs(2) graph_eq_intro)\n\n        from valid_reqs2[OF Cons(2)] have \"valid_reqs M\" .\n        from Cons.IH[OF `valid_reqs M` Cons(3)] have IH:\n          \"all_security_requirements_fulfilled M (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>)\" .\n\n        have goal_rm_SOME_m: \"c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> \\<noteq> {} \\<Longrightarrow>\n            c_sinvar m (delete_edges (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>)\n                                      (SOME F. F \\<in> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>))\"\n        proof - (*sledgehammered*)\n          assume a1: \"c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> \\<noteq> {}\"\n          have f2: \"(\\<forall>r ra p. \\<not> r \\<subseteq> ra \\<or> (p::'a \\<times> 'a) \\<notin> r \\<or> p \\<in> ra) = (\\<forall>r ra p. \\<not> r \\<subseteq> ra \\<or> (p::'a \\<times> 'a) \\<notin> r \\<or> p \\<in> ra)\"\n            by meson\n          have f3: \"wf_graph \\<lparr>nodes = V, edges = E - (SOME r. r \\<in> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>)\\<rparr>\"\n            by (simp add: Cons.prems(2) wf_graph_remove_edges)\n          have \"edges (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>) - (SOME r. r \\<in> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>) \\<subseteq> E - (SOME r. r \\<in> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>)\"\n            using f2 generate_valid_topology_SOME_edges[of M V E] by blast\n          then have \"c_sinvar m \\<lparr>nodes = V, edges = edges (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>) - (SOME r. r \\<in> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>)\\<rparr>\"\n            using f3 a1 \\<open>c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> \\<noteq> {} \\<Longrightarrow> c_sinvar m \\<lparr>nodes = V, edges = E - (SOME F. F \\<in> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>)\\<rparr>\\<close> configured_SecurityInvariant.negative_mono validReq by blast\n          then show \"c_sinvar m (delete_edges (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>) (SOME r. r \\<in> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>))\"\n            by (simp add: generate_valid_topology_SOME_nodes graph_ops(5))\n        qed\n\n        have wf_graph_generate_valid_topology_SOME: \"wf_graph G \\<Longrightarrow> wf_graph (generate_valid_topology_SOME M G)\"\n          for G (*TODO: tune*)\n          apply(cases G)\n          apply(simp add: wf_graph_def generate_valid_topology_SOME_nodes)\n          using generate_valid_topology_SOME_edges by (meson dual_order.trans image_mono rev_finite_subset) \n\n        { assume notempty: \"c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> \\<noteq> {}\"\n          hence \"\\<exists> hypE. (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>) = \\<lparr>nodes = V, edges = hypE\\<rparr>\"\n            proof(induction M arbitrary: V E)\n            qed(simp_all add: delete_edges_simp2 generate_valid_topology_SOME_nodes)\n          from this obtain E_IH where E_IH_prop:\n            \"(generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>) = \\<lparr>nodes = V, edges = E_IH\\<rparr>\" by blast\n    \n          from wf_graph_generate_valid_topology_SOME[OF Cons(3)] E_IH_prop\n          have valid_G_E_IH: \"wf_graph \\<lparr>nodes = V, edges = E_IH\\<rparr>\" by simp\n    \n          from all_security_requirements_fulfilled_mono[OF `valid_reqs M` _ valid_G_E_IH ] IH E_IH_prop\n          have mono_rule: \"E' \\<subseteq> E_IH \\<Longrightarrow> all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = E'\\<rparr>\" for E' by simp\n  \n          have \"all_security_requirements_fulfilled M\n            (delete_edges (generate_valid_topology_SOME M \\<lparr>nodes = V, edges = E\\<rparr>)\n                          (SOME F. F \\<in> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr>))\"\n            unfolding E_IH_prop by(auto simp add: delete_edges_simp2 intro:mono_rule)\n        } note goal_fulfilled_M=this\n\n        have no_offending: \"c_sinvar m \\<lparr>nodes = V, edges = E\\<rparr> \\<Longrightarrow> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> = {}\"\n          by (simp add: configured_SecurityInvariant.c_sinvar_valid_imp_no_offending_flows validReq)\n\n        show \"all_security_requirements_fulfilled (m # M) (generate_valid_topology_SOME (m # M) \\<lparr>nodes = V, edges = E\\<rparr>)\"\n        apply(simp add: all_security_requirements_fulfilled_def)\n        apply(intro conjI impI)\n           subgoal using goal_sinvar_m no_offending by blast\n          subgoal using IH by(simp add: all_security_requirements_fulfilled_def; fail)\n         subgoal using goal_rm_SOME_m not_sinvar_off by blast \n        subgoal using goal_fulfilled_M not_sinvar_off by(simp add: all_security_requirements_fulfilled_def)\n        done\n     qed\n\n    \n   lemma generate_valid_topology_SOME_def_alt:\n      \"generate_valid_topology_SOME M G = delete_edges G (\\<Union>m \\<in> set M. if c_sinvar m G then {} else (SOME F. F \\<in> c_offending_flows m G))\"\n      proof(induction M arbitrary: G)\n        case Nil\n          thus ?case by(simp add: get_offending_flows_def)\n        next\n        case (Cons m M)\n          from Cons[simplified delete_edges_simp2 get_offending_flows_def] \n          have IH :\"edges (generate_valid_topology_SOME M G) =\n                   edges G - (\\<Union>m\\<in>set M. if c_sinvar m G then {} else SOME F. F \\<in> c_offending_flows m G)\"\n            by simp\n          hence \"\\<not> c_sinvar m G \\<Longrightarrow> \n                    edges (generate_valid_topology_SOME (m # M) G) =\n                    (edges G) - (\\<Union>m\\<in>set (m#M). if c_sinvar m G then {} else SOME F. F \\<in> c_offending_flows m G)\"\n            apply(simp add: get_offending_flows_def delete_edges_simp2)\n            by blast\n          with Cons.IH show ?case by(simp add: get_offending_flows_def delete_edges_simp2)\n      qed\n\n    lemma generate_valid_topology_SOME_superset:\n      \"\\<lbrakk> valid_reqs M; wf_graph G \\<rbrakk> \\<Longrightarrow> \n      edges (generate_valid_topology M G) \\<subseteq> edges (generate_valid_topology_SOME M G)\"\n    proof -\n      have isabelle2016_1_helper:\n        \"x \\<in> (\\<Union>m\\<in>set M. if c_sinvar m G then {} else SOME F. F \\<in> c_offending_flows m G) \\<longleftrightarrow>\n          (\\<exists>m\\<in>set M. \\<not> c_sinvar m G \\<and> (c_sinvar m G \\<or> x \\<in> (SOME F. F \\<in> c_offending_flows m G)))\"\n        for x by auto\n      have 1: \"m\\<in>set M \\<Longrightarrow> \\<not> c_sinvar m G \\<and> (c_sinvar m G \\<or> x \\<in> (SOME F. F \\<in> c_offending_flows m G)) \\<Longrightarrow>\n            c_offending_flows m G \\<noteq> {} \\<Longrightarrow>\n            x \\<in> \\<Union>(\\<Union>m\\<in>set M. c_offending_flows m G)\"\n      for x m\n      apply(simp)\n      apply(rule_tac x=m in bexI)\n      apply(simp_all)\n       using some_in_eq by blast\n     \n      show \"valid_reqs M \\<Longrightarrow> wf_graph G \\<Longrightarrow> ?thesis\"\n      unfolding generate_valid_topology_SOME_def_alt generate_valid_topology_def_alt\n      apply(rule delete_edges_edges_mono)\n      apply(simp add: delete_edges_simp2 get_offending_flows_def)\n      apply(rule)\n      apply(subst(asm) isabelle2016_1_helper)\n      apply(erule bexE, rename_tac m)\n      apply(subgoal_tac \"c_offending_flows m G \\<noteq> {}\")\n       using 1 apply blast\n      by (simp add: configured_SecurityInvariant.defined_offending' valid_reqs_def)\n    qed\n\n\n\n\n  text{*Notation:\n    @{const generate_valid_topology_SOME}: non-deterministic choice\n    @{text generate_valid_topology_some}: executable which selects always the same\n    *}\n  fun generate_valid_topology_some :: \"'v SecurityInvariant_configured list \\<Rightarrow> ('v\\<times>'v) list \\<Rightarrow> 'v graph \\<Rightarrow> 'v graph\" where\n    \"generate_valid_topology_some [] _ G = G\" |\n    \"generate_valid_topology_some (m#Ms) Es G = (if c_sinvar m G\n      then generate_valid_topology_some Ms Es G\n      else delete_edges (generate_valid_topology_some Ms Es G) (set (minimalize_offending_overapprox (c_sinvar m) Es [] G))\n      )\"\n  theorem generate_valid_topology_some_sound:\n    \"\\<lbrakk> valid_reqs M; wf_graph \\<lparr>nodes = V, edges = E\\<rparr>; set Es = E; distinct Es \\<rbrakk> \\<Longrightarrow> \n    all_security_requirements_fulfilled M (generate_valid_topology_some M Es \\<lparr>nodes = V, edges = E\\<rparr>)\"\n      proof(induction M)\n        case Nil\n        thus ?case by(simp add: all_security_requirements_fulfilled_def)\n      next\n        case (Cons m M)\n        from valid_reqs1[OF Cons(2)] have validReq: \"configured_SecurityInvariant m\" .\n         \n        from configured_SecurityInvariant.sinvar_valid_remove_minimalize_offending_overapprox[OF\n          validReq Cons.prems(2) _  Cons.prems(3) Cons.prems(4)] have rm_off_valid:\n         \"\\<not> c_sinvar m \\<lparr>nodes = V, edges = E\\<rparr>\\<Longrightarrow>\n           c_sinvar m \\<lparr>nodes = V, edges = E - (set (minimalize_offending_overapprox (c_sinvar m) Es [] \\<lparr>nodes = V, edges = E\\<rparr>))\\<rparr>\"\n        apply(subst(asm) minimalize_offending_overapprox_boundnP[symmetric]) (*TODO: type for nP unspecified!*)\n        by blast\n\n        have generate_valid_topology_some_nodes: \"nodes (generate_valid_topology_some M Es \\<lparr>nodes = V, edges = E\\<rparr>) = V\"\n          for M::\"'a SecurityInvariant_configured list\" and V E\n          proof(induction M)\n          qed(simp_all add: delete_edges_simp2)\n\n\n        have generate_valid_topology_some_edges: \"edges (generate_valid_topology_some M Es \\<lparr>nodes = V, edges = E\\<rparr>) \\<subseteq> E\"\n          for M::\"'a SecurityInvariant_configured list\" and V E\n          proof(induction M)\n          qed(auto simp add: delete_edges_simp2)\n        \n        from configured_SecurityInvariant.mono_sinvar[OF validReq Cons.prems(2),\n              of \"edges (generate_valid_topology_some M Es \\<lparr>nodes = V, edges = E\\<rparr>)\"]\n            generate_valid_topology_some_edges\n          have \"c_sinvar m \\<lparr>nodes = V, edges = E\\<rparr> \\<Longrightarrow>\n            c_sinvar m \\<lparr>nodes = V, edges = edges (generate_valid_topology_some M Es \\<lparr>nodes = V, edges = E\\<rparr>)\\<rparr>\"\n          by simp\n        moreover from configured_SecurityInvariant.defined_offending'[OF validReq Cons.prems(2)] have not_sinvar_off:\n          \"\\<not> c_sinvar m \\<lparr>nodes = V, edges = E\\<rparr> \\<Longrightarrow> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> \\<noteq> {}\" by blast\n        ultimately have goal_sinvar_m:\n          \"c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> = {} \\<Longrightarrow> \n              c_sinvar m (generate_valid_topology_some M Es \\<lparr>nodes = V, edges = E\\<rparr>)\"\n           using generate_valid_topology_some_nodes \n           by (metis graph.select_convs(1) graph.select_convs(2) graph_eq_intro)\n\n  \n        from valid_reqs2[OF Cons(2)] have \"valid_reqs M\" .\n        from Cons.IH[OF `valid_reqs M` Cons(3)] Cons.prems have IH:\n          \"all_security_requirements_fulfilled M (generate_valid_topology_some M Es \\<lparr>nodes = V, edges = E\\<rparr>)\" by simp\n\n \n\n\n        have wf_graph_generate_valid_topology_some: \"wf_graph G \\<Longrightarrow> wf_graph (generate_valid_topology_some M Es G)\"\n          for G (*TODO: tune*)\n          apply(cases G)\n          apply(simp add: wf_graph_def generate_valid_topology_some_nodes)\n          using generate_valid_topology_some_edges by (meson dual_order.trans image_mono rev_finite_subset) \n\n        \n        { assume notempty: \"c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> \\<noteq> {}\"\n          hence \"\\<exists> hypE. (generate_valid_topology_some M Es \\<lparr>nodes = V, edges = E\\<rparr>) = \\<lparr>nodes = V, edges = hypE\\<rparr>\"\n            proof(induction M arbitrary: V E)\n            qed(simp_all add: delete_edges_simp2 generate_valid_topology_some_nodes)\n          from this obtain E_IH where E_IH_prop:\n            \"(generate_valid_topology_some M Es \\<lparr>nodes = V, edges = E\\<rparr>) = \\<lparr>nodes = V, edges = E_IH\\<rparr>\" by blast\n    \n          from wf_graph_generate_valid_topology_some[OF Cons(3)] E_IH_prop\n          have valid_G_E_IH: \"wf_graph \\<lparr>nodes = V, edges = E_IH\\<rparr>\" by simp\n    \n          from all_security_requirements_fulfilled_mono[OF `valid_reqs M` _ valid_G_E_IH ] IH E_IH_prop\n          have mono_rule: \"E' \\<subseteq> E_IH \\<Longrightarrow> all_security_requirements_fulfilled M \\<lparr>nodes = V, edges = E'\\<rparr>\" for E' by simp\n  \n          have \"all_security_requirements_fulfilled M\n            (delete_edges (generate_valid_topology_some M Es \\<lparr>nodes = V, edges = E\\<rparr>)\n                          (set (minimalize_offending_overapprox (c_sinvar m) Es [] \\<lparr>nodes = V, edges = E\\<rparr>)))\"\n            unfolding E_IH_prop by(auto simp add: delete_edges_simp2 intro:mono_rule)\n        } note goal_fulfilled_M=this\n\n        have no_offending: \"c_sinvar m \\<lparr>nodes = V, edges = E\\<rparr> \\<Longrightarrow> c_offending_flows m \\<lparr>nodes = V, edges = E\\<rparr> = {}\"\n          by (simp add: configured_SecurityInvariant.c_sinvar_valid_imp_no_offending_flows validReq)\n\n        show \"all_security_requirements_fulfilled (m # M) (generate_valid_topology_some (m # M) Es \\<lparr>nodes = V, edges = E\\<rparr>)\"\n        apply(simp add: all_security_requirements_fulfilled_def)\n        apply(intro conjI impI)\n           subgoal using goal_sinvar_m no_offending by blast\n          subgoal using IH by(simp add: all_security_requirements_fulfilled_def; fail)\n         subgoal using rm_off_valid by (metis (no_types, lifting) Cons.prems(2) Diff_mono \n            configured_SecurityInvariant.mono_sinvar delete_edges_simp2 generate_valid_topology_some_edges\n            generate_valid_topology_some_nodes order_refl validReq wf_graph_remove_edges) (*TODO!*)\n        subgoal using goal_fulfilled_M not_sinvar_off by(simp add: all_security_requirements_fulfilled_def)\n        done\n     qed\n\n\n\nend\n", "meta": {"author": "diekmann", "repo": "topoS", "sha": "4303ebd95a501283c02fd513c109e645a48ad080", "save_path": "github-repos/isabelle/diekmann-topoS", "path": "github-repos/isabelle/diekmann-topoS/topoS-4303ebd95a501283c02fd513c109e645a48ad080/thy/Network_Security_Policy_Verification/TopoS_Composition_Theory.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6370307944803832, "lm_q2_score": 0.41489884579676883, "lm_q1q2_score": 0.26430334136690964}}
{"text": "section {*I\\_epda\\_S\\_HS*}\ntheory\n  I_epda_S_HS\n\nimports\n  I_epda_S\n  I_epda_HS\n\nbegin\n\ndefinition epdaS_vs_epdaHS_TSstructure_rel :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"epdaS_vs_epdaHS_TSstructure_rel G1 G2 \\<equiv>\n  valid_epda G1\n  \\<and> G1 = G2\"\ndeclare epdaS_vs_epdaHS_TSstructure_rel_def [simp add]\n\ndefinition epdaS_vs_epdaHS_effect_rel :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> bool\"\n  where\n    \"epdaS_vs_epdaHS_effect_rel G1 G2 o1 o2 \\<equiv>\n  G1 = G2\n  \\<and> o1 = o2\"\ndeclare epdaS_vs_epdaHS_effect_rel_def [simp add]\n\ndefinition epdaS_vs_epdaHS_label_relation :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda_step_label\n  \\<Rightarrow> ('state, 'event, 'stack) epda_step_label\n  \\<Rightarrow> bool\"\n  where\n    \"epdaS_vs_epdaHS_label_relation G1 G2 e1 e2 \\<equiv>\n  e1 = e2\n  \\<and> e1 \\<in> epda_delta G1\"\ndeclare epdaS_vs_epdaHS_label_relation_def [simp add]\n\ndefinition epdaHS2epdaS_derivation :: \"\n  (('state, 'event, 'stack) epda_step_label, ('state, 'event, 'stack) epdaHS_conf) derivation\n  \\<Rightarrow> (('state, 'event, 'stack) epda_step_label, ('state, 'event, 'stack) epdaS_conf) derivation\"\n  where\n    \"epdaHS2epdaS_derivation d \\<equiv>\n  (\\<lambda>n. case d n of\n  None \\<Rightarrow> None\n  | Some (pair e c) \\<Rightarrow>\n    Some (pair e\n      \\<lparr>epdaS_conf_state = epdaHS_conf_state c,\n      epdaS_conf_scheduler = epdaHS_conf_scheduler c,\n      epdaS_conf_stack = epdaHS_conf_stack c\\<rparr>))\"\n\ndefinition epdaS_vs_epdaHS_derivation_bisimulation :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> ('state, 'event, 'stack) epda\n  \\<Rightarrow> (('state, 'event, 'stack) epda_step_label, ('state, 'event, 'stack) epdaS_conf) derivation\n  \\<Rightarrow> (('state, 'event, 'stack) epda_step_label, ('state, 'event, 'stack) epdaHS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"epdaS_vs_epdaHS_derivation_bisimulation G1 G2 d1 d2 \\<equiv>\n  valid_epda G1\n  \\<and> G1 = G2\n  \\<and> epdaHS.derivation_initial G2 d2\n  \\<and> (\\<exists>n. maximum_of_domain d2 n)\n  \\<and> epdaHS2epdaS_derivation d2 = d1\"\ndeclare epdaS_vs_epdaHS_derivation_bisimulation_def [simp add]\n\nlemma epdaHS2epdaS_derivation_preserves_derivation_initial: \"\n  valid_epda P\n  \\<Longrightarrow> epdaHS.derivation_initial P d\n  \\<Longrightarrow> epdaS.derivation_initial P (epdaHS2epdaS_derivation d)\"\n  apply(simp add: epdaHS2epdaS_derivation_def)\n  apply(simp add: epdaS.derivation_initial_def)\n  apply(rule conjI)\n   prefer 2\n   apply(simp add: epdaHS.derivation_initial_def)\n   apply(clarsimp)\n   apply(case_tac \"d 0\")\n    apply(clarsimp)\n   apply(rename_tac a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac b)(*strict*)\n   apply(simp add: epdaS_initial_configurations_def epdaHS_initial_configurations_def)\n   apply(clarsimp)\n   apply(simp add: epdaS_configurations_def epdaHS_configurations_def)\n   apply(clarsimp)\n  apply(simp add: epdaS.derivation_def)\n  apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(case_tac \"i\")\n   apply(rename_tac i)(*strict*)\n   apply(clarsimp)\n   apply(simp add: epdaHS.derivation_initial_def)\n   apply(clarsimp)\n   apply(case_tac \"d 0\")\n    apply(clarsimp)\n   apply(rename_tac a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac a option b)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac i nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat)(*strict*)\n  apply(case_tac \"d (Suc nat)\")\n   apply(rename_tac nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac nat a)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d nat = Some (pair e1 c1) \\<and> d (Suc nat) = Some (pair (Some e2) c2) \\<and> epdaHS_step_relation P c1 e2 c2\")\n   apply(rename_tac nat a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m = \"Suc nat\"\n      in epdaHS.step_detail_before_some_position)\n     apply(rename_tac nat a)(*strict*)\n     apply(simp add: epdaHS.derivation_initial_def)\n    apply(rename_tac nat a)(*strict*)\n    apply(force)\n   apply(rename_tac nat a)(*strict*)\n   apply(force)\n  apply(rename_tac nat a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat e1 e2 c1 c2)(*strict*)\n  apply(simp add: epdaS_step_relation_def epdaHS_step_relation_def)\n  done\n\nlemma epdaHS2epdaS_derivation_preserves_step_labels: \"\n  valid_epda G\n  \\<Longrightarrow> epdaHS.derivation G d\n  \\<Longrightarrow> d n = Some (pair e c)\n  \\<Longrightarrow> \\<exists>c. (epdaHS2epdaS_derivation d) n = Some (pair e c)\"\n  apply(induct n arbitrary: e c)\n   apply(rename_tac e c)(*strict*)\n   apply(simp add: epdaHS2epdaS_derivation_def)\n  apply(rename_tac n e c)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d n = Some (pair e1 c1) \\<and> d (Suc n) = Some (pair (Some e2) c2) \\<and> epdaHS_step_relation G c1 e2 c2\")\n   apply(rename_tac n e c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m = \"Suc n\"\n      in epdaHS.step_detail_before_some_position)\n     apply(rename_tac n e c)(*strict*)\n     apply(force)\n    apply(rename_tac n e c)(*strict*)\n    apply(force)\n   apply(rename_tac n e c)(*strict*)\n   apply(force)\n  apply(rename_tac n e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n c e1 e2 c1)(*strict*)\n  apply(erule_tac\n      x = \"e1\"\n      in meta_allE)\n  apply(erule_tac\n      x = \"c1\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(rename_tac n c e1 e2 c1 ca)(*strict*)\n  apply(simp add: epdaHS2epdaS_derivation_def)\n  done\n\nlemma epdaHS2epdaS_derivation_preserves_maximum_of_domain: \"\n  valid_epda G\n  \\<Longrightarrow> maximum_of_domain d n\n  \\<Longrightarrow> maximum_of_domain (epdaHS2epdaS_derivation d) n\"\n  apply(simp add: maximum_of_domain_def epdaHS2epdaS_derivation_def)\n  apply(clarsimp)\n  apply(rename_tac y)(*strict*)\n  apply(case_tac y)\n  apply(rename_tac y option b)(*strict*)\n  apply(clarsimp)\n  done\n\ndefinition epdaS2epdaHS_derivation :: \"\n  ('state, 'event, 'q) epda\n  \\<Rightarrow> (('state, 'event, 'stack) epda_step_label, ('state, 'event, 'stack) epdaS_conf) derivation\n  \\<Rightarrow> (('state, 'event, 'stack) epda_step_label, ('state, 'event, 'stack) epdaHS_conf) derivation\"\n  where\n    \"epdaS2epdaHS_derivation G d \\<equiv>\n  (\\<lambda>n. case d n of\n  None \\<Rightarrow> None\n  | Some (pair e c) \\<Rightarrow>\n    Some (pair e\n      \\<lparr>epdaHS_conf_state = epdaS_conf_state c,\n      epdaHS_conf_history = the(right_quotient_word\n        (epdaS_conf_scheduler(the(get_configuration(d 0))))\n        (epdaS_conf_scheduler c)),\n      epdaHS_conf_scheduler = epdaS_conf_scheduler c,\n      epdaHS_conf_stack = epdaS_conf_stack c\\<rparr>))\"\n\nlemma epdaS2epdaHS_derivation_preserves_derivation_initial: \"\n  valid_epda P\n  \\<Longrightarrow> epdaS.derivation_initial P d\n  \\<Longrightarrow> epdaHS.derivation_initial P (epdaS2epdaHS_derivation P d)\"\n  apply(simp add: epdaS2epdaHS_derivation_def)\n  apply(simp add: epdaHS.derivation_initial_def)\n  apply(rule conjI)\n   prefer 2\n   apply(simp add: epdaS.derivation_initial_def)\n   apply(clarsimp)\n   apply(case_tac \"d 0\")\n    apply(clarsimp)\n   apply(rename_tac a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac b)(*strict*)\n   apply(simp add: epdaS_initial_configurations_def epdaHS_initial_configurations_def)\n   apply(clarsimp)\n   apply(simp add: epdaS_configurations_def epdaHS_configurations_def)\n   apply(clarsimp)\n   apply(rename_tac i)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(simp add: right_quotient_word_def)\n  apply(simp add: epdaHS.derivation_def)\n  apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(case_tac \"i\")\n   apply(rename_tac i)(*strict*)\n   apply(clarsimp)\n   apply(simp add: epdaS.derivation_initial_def)\n   apply(clarsimp)\n   apply(case_tac \"d 0\")\n    apply(clarsimp)\n   apply(rename_tac a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac a option b)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac i nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat)(*strict*)\n  apply(case_tac \"d (Suc nat)\")\n   apply(rename_tac nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac nat a)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d nat = Some (pair e1 c1) \\<and> d (Suc nat) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation P c1 e2 c2\")\n   apply(rename_tac nat a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m = \"Suc nat\"\n      in epdaS.step_detail_before_some_position)\n     apply(rename_tac nat a)(*strict*)\n     apply(simp add: epdaS.derivation_initial_def)\n    apply(rename_tac nat a)(*strict*)\n    apply(force)\n   apply(rename_tac nat a)(*strict*)\n   apply(force)\n  apply(rename_tac nat a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac nat e1 e2 c1 c2)(*strict*)\n  apply(simp add: epdaS_step_relation_def epdaHS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac nat e1 e2 c1 c2 w)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. d 0 = Some (pair None c)\")\n   apply(rename_tac nat e1 e2 c1 c2 w)(*strict*)\n   prefer 2\n   apply(rule epdaS.some_position_has_details_at_0)\n   apply(simp add: epdaS.derivation_initial_def)\n   apply(force)\n  apply(rename_tac nat e1 e2 c1 c2 w)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n  apply(subgoal_tac \"valid_epda_step_label P e2\")\n   apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n   prefer 2\n   apply(simp add: valid_epda_def)\n  apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n  apply(simp add: valid_epda_step_label_def)\n  apply(subgoal_tac \"\\<exists>w. epdaS_string_state c = w @ (epdaS_string_state c1)\")\n   apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      j = \"nat\"\n      in epdaS.derivation_monotonically_dec)\n        apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n        apply(force)\n       apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n       apply(force)\n      apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n      apply(rule epdaS.derivation_initial_belongs)\n       apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n       apply(force)\n      apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n      apply(force)\n     apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n     apply(simp add: epdaS.derivation_initial_def)\n    apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n    apply(force)\n   apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n   apply(force)\n  apply(rename_tac nat e1 e2 c1 c2 w c)(*strict*)\n  apply(simp add: epdaS_string_state_def)\n  apply(clarsimp)\n  apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. epdaS_string_state c1 = w @ (epdaS_string_state c2)\")\n   apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n   prefer 2\n   apply(rule_tac\n      j = \"Suc 0\"\n      in epdaS.derivation_monotonically_dec)\n        apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n        apply(force)\n       apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n       apply(force)\n      apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n      apply(rule epdaS.derivation_initial_belongs)\n       apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n       apply(force)\n      apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n      apply(force)\n     apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n     apply(simp add: epdaS.derivation_initial_def)\n    apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n    apply(force)\n   apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n   apply(force)\n  apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n  apply(subgoal_tac \"c \\<in> epdaS_configurations P\")\n   apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n   prefer 2\n   apply(rule epdaS.belongs_configurations)\n    apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n    apply(rule epdaS.derivation_initial_belongs)\n     apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n     apply(force)\n    apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n    apply(force)\n   apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n   apply(force)\n  apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n  apply(simp add: epdaS_string_state_def)\n  apply(rule_tac\n      t = \"right_quotient_word (wa @ option_to_list (edge_event e2) @ epdaS_conf_scheduler c2) (epdaS_conf_scheduler c2)\"\n      and s = \"Some(wa @ option_to_list (edge_event e2))\"\n      in ssubst)\n   apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n   apply(rule right_quotient_word_Some_by_append)\n   apply(force)\n  apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n  apply(clarsimp)\n  apply(rule sym)\n  apply(rule_tac\n      t = \"right_quotient_word (wa @ option_to_list (edge_event e2) @ epdaS_conf_scheduler c2) (option_to_list (edge_event e2) @ epdaS_conf_scheduler c2)\"\n      and s = \"Some wa\"\n      in ssubst)\n   apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n   apply(rule right_quotient_word_Some_by_append)\n   apply(force)\n  apply(rename_tac nat e1 e2 c1 c2 w c wa)(*strict*)\n  apply(force)\n  done\n\nlemma epdaS2epdaHS_derivation_preserves_maximum_of_domain: \"\n  valid_epda G\n  \\<Longrightarrow> maximum_of_domain d n\n  \\<Longrightarrow> maximum_of_domain (epdaS2epdaHS_derivation G d) n\"\n  apply(simp add: maximum_of_domain_def epdaS2epdaHS_derivation_def)\n  apply(clarsimp)\n  apply(rename_tac y)(*strict*)\n  apply(case_tac y)\n  apply(rename_tac y option b)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma epda_S_HS_relation_coincide_hlp: \"\n  valid_epda G2\n  \\<Longrightarrow> epdaHS.derivation_initial G2 d2\n  \\<Longrightarrow> maximum_of_domain d2 x\n  \\<Longrightarrow> epdaS2epdaHS_derivation G2 (epdaHS2epdaS_derivation d2) xa = d2 xa\"\n  apply(induct xa)\n   apply(simp add: epdaHS2epdaS_derivation_def epdaS2epdaHS_derivation_def)\n   apply(subgoal_tac \"\\<exists>c. d2 0 = Some (pair None c)\")\n    apply(clarsimp)\n    apply(rename_tac c)(*strict*)\n    apply(case_tac c)\n    apply(rename_tac c epdaHS_conf_statea epdaHS_conf_history epdaHS_conf_schedulera epdaHS_conf_stacka)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac epdaHS_conf_state epdaHS_conf_history epdaHS_conf_scheduler epdaHS_conf_stack)(*strict*)\n    apply(simp add: epdaHS.derivation_initial_def)\n    apply(clarsimp)\n    apply(simp add: epdaHS_initial_configurations_def)\n    apply(clarsimp)\n    apply(rename_tac epdaHS_conf_scheduler)(*strict*)\n    apply(simp add: get_configuration_def)\n    apply(simp add: butlast_if_match_def right_quotient_word_def)\n   apply(simp add: epdaHS.derivation_initial_def)\n   apply(clarsimp)\n   apply(case_tac \"d2 0\")\n    apply(clarsimp)\n   apply(rename_tac a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac a option b)(*strict*)\n   apply(force)\n  apply(rename_tac xa)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"d2 (Suc xa)\")\n   apply(rename_tac xa)(*strict*)\n   apply(clarsimp)\n   apply(simp add: epdaHS2epdaS_derivation_def epdaS2epdaHS_derivation_def)\n  apply(rename_tac xa a)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d2 xa = Some (pair e1 c1) \\<and> d2 (Suc xa) = Some (pair (Some e2) c2) \\<and> epdaHS_step_relation G2 c1 e2 c2\")\n   apply(rename_tac xa a)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m = \"Suc xa\"\n      in epdaHS.step_detail_before_some_position)\n     apply(rename_tac xa a)(*strict*)\n     apply(simp add: epdaHS.derivation_initial_def)\n    apply(rename_tac xa a)(*strict*)\n    apply(force)\n   apply(rename_tac xa a)(*strict*)\n   apply(force)\n  apply(rename_tac xa a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac xa e1 e2 c1 c2)(*strict*)\n  apply(simp add: epdaS2epdaHS_derivation_def)\n  apply(simp add: epdaHS2epdaS_derivation_def epdaS2epdaHS_derivation_def)\n  apply(subgoal_tac \"\\<exists> c. d2 0 = Some (pair None c)\")\n   apply(rename_tac xa e1 e2 c1 c2)(*strict*)\n   prefer 2\n   apply(simp add: epdaHS.derivation_initial_def)\n   apply(clarsimp)\n   apply(case_tac \"d2 0\")\n    apply(rename_tac xa e1 e2 c1 c2)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac xa e1 e2 c1 c2 a)(*strict*)\n   apply(case_tac a)\n   apply(rename_tac xa e1 e2 c1 c2 a option b)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac xa e1 e2 c1 c2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac xa e1 e2 c1 c2 c)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(subgoal_tac \"\\<exists>w. epdaHS_string_state c = w @ epdaHS_string_state c1\")\n   apply(rename_tac xa e1 e2 c1 c2 c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d = \"d2\"\n      in epdaHS.derivation_monotonically_dec)\n        apply(rename_tac xa e1 e2 c1 c2 c)(*strict*)\n        apply(force)\n       apply(rename_tac xa e1 e2 c1 c2 c)(*strict*)\n       apply(force)\n      apply(rename_tac xa e1 e2 c1 c2 c)(*strict*)\n      apply(rule epdaHS.derivation_initial_belongs)\n       apply(rename_tac xa e1 e2 c1 c2 c)(*strict*)\n       apply(force)\n      apply(rename_tac xa e1 e2 c1 c2 c)(*strict*)\n      apply(force)\n     apply(rename_tac xa e1 e2 c1 c2 c)(*strict*)\n     apply(simp add: epdaHS.derivation_initial_def)\n    apply(rename_tac xa e1 e2 c1 c2 c)(*strict*)\n    apply(force)\n   apply(rename_tac xa e1 e2 c1 c2 c)(*strict*)\n   apply(force)\n  apply(rename_tac xa e1 e2 c1 c2 c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac xa e1 e2 c1 c2 c w)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. epdaHS_string_state c1 = w @ epdaHS_string_state c2\")\n   apply(rename_tac xa e1 e2 c1 c2 c w)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d = \"d2\"\n      and i = \"xa\"\n      and j = \"Suc 0\"\n      in epdaHS.derivation_monotonically_dec)\n        apply(rename_tac xa e1 e2 c1 c2 c w)(*strict*)\n        apply(force)\n       apply(rename_tac xa e1 e2 c1 c2 c w)(*strict*)\n       apply(force)\n      apply(rename_tac xa e1 e2 c1 c2 c w)(*strict*)\n      apply(rule epdaHS.derivation_initial_belongs)\n       apply(rename_tac xa e1 e2 c1 c2 c w)(*strict*)\n       apply(force)\n      apply(rename_tac xa e1 e2 c1 c2 c w)(*strict*)\n      apply(force)\n     apply(rename_tac xa e1 e2 c1 c2 c w)(*strict*)\n     apply(simp add: epdaHS.derivation_initial_def)\n    apply(rename_tac xa e1 e2 c1 c2 c w)(*strict*)\n    apply(force)\n   apply(rename_tac xa e1 e2 c1 c2 c w)(*strict*)\n   apply(force)\n  apply(rename_tac xa e1 e2 c1 c2 c w)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac xa e1 e2 c1 c2 c w wa)(*strict*)\n  apply(simp add: epdaHS_string_state_def)\n  apply(simp add: epdaHS_step_relation_def)\n  apply(subgoal_tac \"valid_epda_step_label G2 e2\")\n   apply(rename_tac xa e1 e2 c1 c2 c w wa)(*strict*)\n   prefer 2\n   apply(simp add: valid_epda_def)\n  apply(rename_tac xa e1 e2 c1 c2 c w wa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac xa e1 e2 c2 c w wb)(*strict*)\n  apply(simp add: valid_epda_step_label_def)\n  apply(clarsimp)\n  apply(case_tac c2)\n  apply(rename_tac xa e1 e2 c2 c w wb epdaHS_conf_statea epdaHS_conf_historya epdaHS_conf_schedulera epdaHS_conf_stacka)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac xa e1 e2 c w wb epdaHS_conf_schedulera)(*strict*)\n  apply(rule_tac\n      t = \"right_quotient_word (w @ option_to_list (edge_event e2) @ epdaHS_conf_schedulera) epdaHS_conf_schedulera\"\n      and s = \"Some(w @ option_to_list (edge_event e2))\"\n      in ssubst)\n   apply(rename_tac xa e1 e2 c w wb epdaHS_conf_schedulera)(*strict*)\n   apply(rule right_quotient_word_Some_by_append)\n   apply(force)\n  apply(rename_tac xa e1 e2 c w wb epdaHS_conf_schedulera)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n      t = \"right_quotient_word (w @ option_to_list (edge_event e2) @ epdaHS_conf_schedulera) (option_to_list (edge_event e2) @ epdaHS_conf_schedulera)\"\n      and s = \"Some w\"\n      in ssubst)\n   apply(rename_tac xa e1 e2 c w wb epdaHS_conf_schedulera)(*strict*)\n   apply(rule right_quotient_word_Some_by_append)\n   apply(force)\n  apply(rename_tac xa e1 e2 c w wb epdaHS_conf_schedulera)(*strict*)\n  apply(force)\n  done\n\ncorollary epda_S_HS_relation_coincide: \"\n  (\\<lambda>G1 G2 d1 d2. (valid_epda G1) \\<and> (G1 = G2) \\<and> epdaHS.derivation_initial G2 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n) \\<and> epdaHS2epdaS_derivation d2 = d1) = (\\<lambda>G1 G2 d1 d2. (valid_epda G1) \\<and> (G1 = G2) \\<and> epdaS.derivation_initial G1 d1 \\<and> (\\<exists>n. maximum_of_domain d1 n) \\<and> epdaS2epdaHS_derivation G1 d1 = d2)\"\n  apply(rule ext)+\n  apply(rename_tac G1 G2 d1 d2)(*strict*)\n  apply(rule order_antisym)\n   apply(rename_tac G1 G2 d1 d2)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac G2 d1 x)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G2 d1 x)(*strict*)\n    apply (metis epdaS2epdaHS_derivation_preserves_derivation_initial)\n   apply(rename_tac G2 d1 x)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G2 d1 x)(*strict*)\n    apply (metis epdaS2epdaHS_derivation_preserves_maximum_of_domain)\n   apply(rename_tac G2 d1 x)(*strict*)\n   apply(simp add: epdaS2epdaHS_derivation_def epdaHS2epdaS_derivation_def)\n   apply(rule ext)\n   apply(rename_tac G2 d1 x n)(*strict*)\n   apply(case_tac \"d1 n\")\n    apply(rename_tac G2 d1 x n)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G2 d1 x n a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac G2 d1 x n a option b)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 G2 d1 d2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G2 d2 x)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G2 d2 x)(*strict*)\n   apply (metis epdaHS2epdaS_derivation_preserves_derivation_initial)\n  apply(rename_tac G2 d2 x)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G2 d2 x)(*strict*)\n   apply (metis epdaHS2epdaS_derivation_preserves_maximum_of_domain)\n  apply(rename_tac G2 d2 x)(*strict*)\n  apply(rule ext)\n  apply(rename_tac G2 d2 x xa)(*strict*)\n  apply(rule epda_S_HS_relation_coincide_hlp)\n    apply(rename_tac G2 d2 x xa)(*strict*)\n    apply(force)+\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_AX_initial_contained1: \"\n  (\\<forall>G1. valid_epda G1 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<exists>c2. epdaHS.derivation_initial G1 (der1 c2) \\<and> Ex (maximum_of_domain (der1 c2)) \\<and> epdaHS2epdaS_derivation (der1 c2) = der1 c1)))\"\n  apply(clarsimp)\n  apply(rename_tac G1 c1)(*strict*)\n  apply(rule_tac\n      x = \"\\<lparr>epdaHS_conf_state = epdaS_conf_state c1, epdaHS_conf_history = [], epdaHS_conf_scheduler = epdaS_conf_scheduler c1, epdaHS_conf_stack = epdaS_conf_stack c1\\<rparr>\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 c1)(*strict*)\n   apply(simp add: epdaHS.derivation_initial_def)\n   apply(rule conjI)\n    apply(rename_tac G1 c1)(*strict*)\n    apply(rule epdaHS.der1_is_derivation)\n   apply(rename_tac G1 c1)(*strict*)\n   apply(simp add: der1_def)\n   apply(simp add: epdaHS_initial_configurations_def epdaHS_configurations_def epdaS_initial_configurations_def epdaS_configurations_def)\n   apply(clarsimp)\n  apply(rename_tac G1 c1)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 c1)(*strict*)\n   apply(rule_tac\n      x = \"0\"\n      in exI)\n   apply (metis der1_maximum_of_domain)\n  apply(rename_tac G1 c1)(*strict*)\n  apply(rule ext)\n  apply(rename_tac G1 c1 x)(*strict*)\n  apply(simp add: epdaHS2epdaS_derivation_def der1_def der1_def)\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_AX_initial_contained2: \"\n  (\\<forall>G1. valid_epda G1 \\<longrightarrow> (\\<forall>c2. c2 \\<in> epdaHS_initial_configurations G1 \\<longrightarrow> epdaHS.derivation_initial G1 (der1 c2) \\<and> Ex (maximum_of_domain (der1 c2)) \\<and> (\\<exists>c1. epdaHS2epdaS_derivation (der1 c2) = der1 c1)))\"\n  apply(clarsimp)\n  apply(rename_tac G1 c2)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 c2)(*strict*)\n   apply(simp add: epdaHS.derivation_initial_def)\n   apply(rule conjI)\n    apply(rename_tac G1 c2)(*strict*)\n    apply(rule epdaHS.der1_is_derivation)\n   apply(rename_tac G1 c2)(*strict*)\n   apply(simp add: der1_def)\n  apply(rename_tac G1 c2)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 c2)(*strict*)\n   apply(rule_tac\n      x = \"0\"\n      in exI)\n   apply (metis der1_maximum_of_domain)\n  apply(rename_tac G1 c2)(*strict*)\n  apply(rule_tac\n      x = \"X\" for X\n      in exI)\n  apply(simp add: epdaHS2epdaS_derivation_def der1_def der1_def)\n  apply(rule ext)\n  apply(rename_tac G1 c2 n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 c2)(*strict*)\n  apply(force)\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_on_derivation_initial1: \"\n  (\\<forall>G1 d1. valid_epda G1 \\<and> (\\<exists>d2. epdaHS.derivation_initial G1 d2 \\<and> Ex (maximum_of_domain d2) \\<and> epdaHS2epdaS_derivation d2 = d1) \\<longrightarrow> epdaS.derivation_initial G1 d1)\"\n  apply(clarsimp)\n  apply(rename_tac G1 d2 x)(*strict*)\n  apply (metis epdaHS2epdaS_derivation_preserves_derivation_initial)\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_on_finite1: \"\n  (\\<forall>G1 d1. valid_epda G1 \\<and> (\\<exists>d2. epdaHS.derivation_initial G1 d2 \\<and> Ex (maximum_of_domain d2) \\<and> epdaHS2epdaS_derivation d2 = d1) \\<longrightarrow> Ex (maximum_of_domain d1))\"\n  apply(clarsimp)\n  apply(rename_tac G1 d2 x)(*strict*)\n  apply(rule_tac\n      x = \"x\"\n      in exI)\n  apply (metis epdaHS2epdaS_derivation_preserves_maximum_of_domain)\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_equal_length: \"\n  (\\<forall>G1 d2. valid_epda G1 \\<and> epdaHS.derivation_initial G1 d2 \\<and> Ex (maximum_of_domain d2) \\<longrightarrow> (\\<forall>n1. maximum_of_domain (epdaHS2epdaS_derivation d2) n1 \\<longrightarrow> (\\<forall>n2. maximum_of_domain d2 n2 \\<longrightarrow> n1 = n2)))\"\n  apply(clarsimp)\n  apply(rename_tac G1 d2 n1 x n2)(*strict*)\n  apply (metis epdaS.derivation_initial_is_derivation epdaS.maximum_of_domainUnique epdaHS2epdaS_derivation_preserves_derivation_initial epdaHS2epdaS_derivation_preserves_maximum_of_domain)\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_simulate12: \"\n  (\\<forall>G1 d2. valid_epda G1 \\<and> epdaHS.derivation_initial G1 d2 \\<and> Ex (maximum_of_domain d2) \\<longrightarrow> (\\<forall>n. maximum_of_domain (epdaHS2epdaS_derivation d2) n \\<longrightarrow> maximum_of_domain d2 n \\<longrightarrow> (\\<forall>e1 c1'. epdaS_step_relation G1 (the (get_configuration (epdaHS2epdaS_derivation d2 n))) e1 c1' \\<longrightarrow> (\\<exists>c2'. epdaHS_step_relation G1 (the (get_configuration (d2 n))) e1 c2' \\<and> e1 \\<in> epda_delta G1 \\<and> (let d2' = derivation_append d2 (der2 (the (get_configuration (d2 n))) e1 c2') n in epdaHS.derivation_initial G1 d2' \\<and> Ex (maximum_of_domain d2') \\<and> epdaHS2epdaS_derivation d2' = derivation_append (epdaHS2epdaS_derivation d2) (der2 (the (get_configuration (epdaHS2epdaS_derivation d2 n))) e1 c1') n)))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 d2 n x e1 c1')(*strict*)\n  apply(subgoal_tac \"n = x\")\n   apply(rename_tac G1 d2 n x e1 c1')(*strict*)\n   prefer 2\n   apply (metis epdaS_vs_epdaHS_inst_AX_equal_length)\n  apply(rename_tac G1 d2 n x e1 c1')(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 d2 x e1 c1')(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d2 x = Some (pair e c)\")\n   apply(rename_tac G1 d2 x e1 c1')(*strict*)\n   prefer 2\n   apply(rule epdaHS.some_position_has_details_before_max_dom)\n     apply(rename_tac G1 d2 x e1 c1')(*strict*)\n     apply(simp add: epdaHS.derivation_initial_def)\n     apply(force)\n    apply(rename_tac G1 d2 x e1 c1')(*strict*)\n    apply(force)\n   apply(rename_tac G1 d2 x e1 c1')(*strict*)\n   apply(force)\n  apply(rename_tac G1 d2 x e1 c1')(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 d2 x e1 c1' e c)(*strict*)\n  apply(rule_tac\n      x = \"\\<lparr>epdaHS_conf_state = epdaS_conf_state c1', epdaHS_conf_history = epdaHS_conf_history c@(option_to_list(edge_event e1)), epdaHS_conf_scheduler = epdaS_conf_scheduler c1', epdaHS_conf_stack = epdaS_conf_stack c1'\\<rparr>\"\n      in exI)\n  apply(rule context_conjI)\n   apply(rename_tac G1 d2 x e1 c1' e c)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(simp add: epdaHS2epdaS_derivation_def)\n   apply(simp add: epdaHS_step_relation_def epdaS_step_relation_def get_configuration_def)\n  apply(rename_tac G1 d2 x e1 c1' e c)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 d2 x e1 c1' e c)(*strict*)\n   apply(simp add: epdaS_step_relation_def)\n  apply(rename_tac G1 d2 x e1 c1' e c)(*strict*)\n  apply(simp add: Let_def)\n  apply(rule context_conjI)\n   apply(rename_tac G1 d2 x e1 c1' e c)(*strict*)\n   apply(simp add: epdaHS.derivation_initial_def)\n   apply(rule conjI)\n    apply(rename_tac G1 d2 x e1 c1' e c)(*strict*)\n    apply(rule epdaHS.derivation_append_preserves_derivation)\n      apply(rename_tac G1 d2 x e1 c1' e c)(*strict*)\n      apply(force)\n     apply(rename_tac G1 d2 x e1 c1' e c)(*strict*)\n     apply (rule epdaHS.der2_is_derivation)\n     apply(force)\n    apply(rename_tac G1 d2 x e1 c1' e c)(*strict*)\n    apply(clarsimp)\n    apply(simp add: der2_def get_configuration_def)\n   apply(rename_tac G1 d2 x e1 c1' e c)(*strict*)\n   apply(simp add: derivation_append_def)\n  apply(rename_tac G1 d2 x e1 c1' e c)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 d2 x e1 c1' e c)(*strict*)\n   apply(rule_tac\n      x = \"x+Suc 0\"\n      in exI)\n   apply (metis Nat.add_0_right add_Suc_right concat_has_max_dom der2_maximum_of_domain)\n  apply(rename_tac G1 d2 x e1 c1' e c)(*strict*)\n  apply(rule ext)\n  apply(rename_tac G1 d2 x e1 c1' e c xa)(*strict*)\n  apply(simp add: derivation_append_def epdaHS2epdaS_derivation_def derivation_append_def)\n  apply(case_tac \"xa \\<le> x\")\n   apply(rename_tac G1 d2 x e1 c1' e c xa)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 d2 x e1 c1' e c xa)(*strict*)\n  apply(clarsimp)\n  apply(simp add: der2_def der2_def)\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_simulate21: \"\n  (\\<forall>G1 d2. valid_epda G1 \\<and> epdaHS.derivation_initial G1 d2 \\<and> Ex (maximum_of_domain d2) \\<longrightarrow> (\\<forall>n. maximum_of_domain (epdaHS2epdaS_derivation d2) n \\<longrightarrow> maximum_of_domain d2 n \\<longrightarrow> (\\<forall>e2 c2'. epdaHS_step_relation G1 (the (get_configuration (d2 n))) e2 c2' \\<longrightarrow> (\\<exists>c1'. epdaS_step_relation G1 (the (get_configuration (epdaHS2epdaS_derivation d2 n))) e2 c1' \\<and> e2 \\<in> epda_delta G1 \\<and> (let d2' = derivation_append d2 (der2 (the (get_configuration (d2 n))) e2 c2') n in epdaHS.derivation_initial G1 d2' \\<and> Ex (maximum_of_domain d2') \\<and> epdaHS2epdaS_derivation d2' = derivation_append (epdaHS2epdaS_derivation d2) (der2 (the (get_configuration (epdaHS2epdaS_derivation d2 n))) e2 c1') n)))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 d2 n x e2 c2')(*strict*)\n  apply(subgoal_tac \"n = x\")\n   apply(rename_tac G1 d2 n x e2 c2')(*strict*)\n   prefer 2\n   apply (metis epdaS_vs_epdaHS_inst_AX_equal_length)\n  apply(rename_tac G1 d2 n x e2 c2')(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 d2 x e2 c2')(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d2 x = Some (pair e c)\")\n   apply(rename_tac G1 d2 x e2 c2')(*strict*)\n   prefer 2\n   apply(rule epdaHS.some_position_has_details_before_max_dom)\n     apply(rename_tac G1 d2 x e2 c2')(*strict*)\n     apply(simp add: epdaHS.derivation_initial_def)\n     apply(force)\n    apply(rename_tac G1 d2 x e2 c2')(*strict*)\n    apply(force)\n   apply(rename_tac G1 d2 x e2 c2')(*strict*)\n   apply(force)\n  apply(rename_tac G1 d2 x e2 c2')(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 d2 x e2 c2' e c)(*strict*)\n  apply(rule_tac\n      x = \"\\<lparr>epdaS_conf_state = epdaHS_conf_state c2', epdaS_conf_scheduler = epdaHS_conf_scheduler c2', epdaS_conf_stack = epdaHS_conf_stack c2'\\<rparr>\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 d2 x e2 c2' e c)(*strict*)\n   apply(simp add: epdaS_step_relation_def epdaHS_step_relation_def get_configuration_def epdaHS2epdaS_derivation_def get_configuration_def)\n  apply(rename_tac G1 d2 x e2 c2' e c)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 d2 x e2 c2' e c)(*strict*)\n   apply(simp add: epdaS_step_relation_def epdaHS_step_relation_def get_configuration_def epdaHS2epdaS_derivation_def get_configuration_def)\n  apply(rename_tac G1 d2 x e2 c2' e c)(*strict*)\n  apply(simp add: Let_def)\n  apply(rule context_conjI)\n   apply(rename_tac G1 d2 x e2 c2' e c)(*strict*)\n   apply(simp add: epdaHS.derivation_initial_def)\n   apply(rule conjI)\n    apply(rename_tac G1 d2 x e2 c2' e c)(*strict*)\n    apply(rule epdaHS.derivation_append_preserves_derivation)\n      apply(rename_tac G1 d2 x e2 c2' e c)(*strict*)\n      apply(force)\n     apply(rename_tac G1 d2 x e2 c2' e c)(*strict*)\n     apply (metis epdaHS.der2_is_derivation)\n    apply(rename_tac G1 d2 x e2 c2' e c)(*strict*)\n    apply(clarsimp)\n    apply(simp add: der2_def get_configuration_def)\n   apply(rename_tac G1 d2 x e2 c2' e c)(*strict*)\n   apply(simp add: derivation_append_def)\n  apply(rename_tac G1 d2 x e2 c2' e c)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 d2 x e2 c2' e c)(*strict*)\n   apply(rule_tac\n      x = \"x+Suc 0\"\n      in exI)\n   apply (metis Nat.add_0_right add_Suc_right concat_has_max_dom der2_maximum_of_domain)\n  apply(rename_tac G1 d2 x e2 c2' e c)(*strict*)\n  apply(rule ext)\n  apply(rename_tac G1 d2 x e2 c2' e c xa)(*strict*)\n  apply(simp add: derivation_append_def epdaHS2epdaS_derivation_def derivation_append_def)\n  apply(case_tac \"xa \\<le> x\")\n   apply(rename_tac G1 d2 x e2 c2' e c xa)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 d2 x e2 c2' e c xa)(*strict*)\n  apply(clarsimp)\n  apply(simp add: der2_def der2_def)\n  done\n\nlemma epdaS_vs_epdaHS_inst_hlp_bisimulation_compatible_with_crop: \"\n  valid_epda G1\n  \\<Longrightarrow> epdaHS.derivation_initial G1 dh\n  \\<Longrightarrow> maximum_of_domain dh x\n  \\<Longrightarrow> maximum_of_domain (epdaHS2epdaS_derivation dh) n\n  \\<Longrightarrow> derivation_append_fit (epdaHS2epdaS_derivation dh) dc n\n  \\<Longrightarrow> epdaHS.derivation_initial G1 dc'\n  \\<Longrightarrow> epdaHS2epdaS_derivation dc' = derivation_append (epdaHS2epdaS_derivation dh) dc n\n  \\<Longrightarrow> maximum_of_domain dc' xb\n  \\<Longrightarrow> xa \\<le> n\n  \\<Longrightarrow> dh xa = dc' xa\"\n  apply(subgoal_tac \"x = n\")\n   apply(subgoal_tac \"x\\<le>xb\")\n    apply(clarsimp)\n    apply(induct xa)\n     apply(clarsimp)\n     apply(subgoal_tac \"epdaHS2epdaS_derivation dc' 0 = derivation_append (epdaHS2epdaS_derivation dh) dc n 0\")\n      prefer 2\n      apply(force)\n     apply(thin_tac \"epdaHS2epdaS_derivation dc' = derivation_append (epdaHS2epdaS_derivation dh) dc n\")\n     apply(simp add: epdaHS2epdaS_derivation_def derivation_append_def)\n     apply(subgoal_tac \"\\<exists>c. dc' 0 = Some (pair None c)\")\n      apply(subgoal_tac \"\\<exists>c. dh 0 = Some (pair None c)\")\n       apply(clarsimp)\n       apply(rename_tac c ca)(*strict*)\n       apply(simp add: epdaHS.derivation_initial_def epdaS.derivation_initial_def)\n       apply(clarsimp)\n       apply(simp add: epdaHS_initial_configurations_def)\n      apply(clarsimp)\n      apply(rename_tac c)(*strict*)\n      apply(rule epdaHS.some_position_has_details_at_0)\n      apply(simp add: epdaHS.derivation_initial_def)\n      apply(force)\n     apply(rule epdaHS.some_position_has_details_at_0)\n     apply(simp add: epdaHS.derivation_initial_def)\n     apply(force)\n    apply(rename_tac xa)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"epdaHS2epdaS_derivation dc' xa = derivation_append (epdaHS2epdaS_derivation dh) dc n xa\")\n     apply(rename_tac xa)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac xa)(*strict*)\n    apply(subgoal_tac \"epdaHS2epdaS_derivation dc' (Suc xa) = derivation_append (epdaHS2epdaS_derivation dh) dc n (Suc xa)\")\n     apply(rename_tac xa)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac xa)(*strict*)\n    apply(thin_tac \"epdaHS2epdaS_derivation dc' = derivation_append (epdaHS2epdaS_derivation dh) dc n\")\n    apply(rename_tac xa)(*strict*)\n    apply(subgoal_tac \"\\<exists>e c. dc' (Suc xa) = Some (pair e c)\")\n     apply(rename_tac xa)(*strict*)\n     apply(subgoal_tac \"\\<exists>e c. dh (Suc xa) = Some (pair e c)\")\n      apply(rename_tac xa)(*strict*)\n      apply(simp add: epdaHS2epdaS_derivation_def derivation_append_def)\n      apply(clarsimp)\n      apply(rename_tac xa ea c ca)(*strict*)\n      apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. dh xa = Some (pair e1 c1) \\<and> dh (Suc xa) = Some (pair (Some e2) c2) \\<and> epdaHS_step_relation G1 c1 e2 c2\")\n       apply(rename_tac xa ea c ca)(*strict*)\n       prefer 2\n       apply(rule_tac\n      m = \"Suc xa\"\n      in epdaHS.step_detail_before_some_position)\n         apply(rename_tac xa ea c ca)(*strict*)\n         apply(simp add: epdaHS.derivation_initial_def)\n        apply(rename_tac xa ea c ca)(*strict*)\n        apply(force)\n       apply(rename_tac xa ea c ca)(*strict*)\n       apply(force)\n      apply(rename_tac xa ea c ca)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac xa c ca e1 e2 c1)(*strict*)\n      apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. dc' xa = Some (pair e1 c1) \\<and> dc' (Suc xa) = Some (pair (Some e2) c2) \\<and> epdaHS_step_relation G1 c1 e2 c2\")\n       apply(rename_tac xa c ca e1 e2 c1)(*strict*)\n       prefer 2\n       apply(rule_tac\n      m = \"Suc xa\"\n      in epdaHS.step_detail_before_some_position)\n         apply(rename_tac xa c ca e1 e2 c1)(*strict*)\n         apply(simp add: epdaHS.derivation_initial_def)\n        apply(rename_tac xa c ca e1 e2 c1)(*strict*)\n        apply(force)\n       apply(rename_tac xa c ca e1 e2 c1)(*strict*)\n       apply(force)\n      apply(rename_tac xa c ca e1 e2 c1)(*strict*)\n      apply(clarsimp)\n      apply(simp add: epdaHS_step_relation_def)\n     apply(rename_tac xa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac xa e c)(*strict*)\n     apply(rule epdaHS.some_position_has_details_before_max_dom)\n       apply(rename_tac xa e c)(*strict*)\n       apply(simp add: epdaHS.derivation_initial_def)\n       apply(force)\n      apply(rename_tac xa e c)(*strict*)\n      apply(force)\n     apply(rename_tac xa e c)(*strict*)\n     apply(force)\n    apply(rename_tac xa)(*strict*)\n    apply(rule epdaHS.some_position_has_details_before_max_dom)\n      apply(rename_tac xa)(*strict*)\n      apply(simp add: epdaHS.derivation_initial_def)\n      apply(force)\n     apply(rename_tac xa)(*strict*)\n     apply(force)\n    apply(rename_tac xa)(*strict*)\n    apply(rule_tac\n      j = \"n\"\n      in le_trans)\n     apply(rename_tac xa)(*strict*)\n     apply(force)\n    apply(rename_tac xa)(*strict*)\n    apply(force)\n   apply(clarsimp)\n   apply(rule_tac\n      ?d1.0 = \"(epdaHS2epdaS_derivation dh)\"\n      and ?d2.0 = \"dc\"\n      in epdaS.derivation_append_minimal_maximum_of_domain)\n       apply(force)+\n      prefer 4\n      apply(force)\n     apply(rule epdaS.derivation_initial_is_derivation)\n     apply(rule_tac\n      t = \"derivation_append (epdaHS2epdaS_derivation dh) dc n\"\n      and s = \"epdaHS2epdaS_derivation dc'\"\n      in ssubst)\n      apply(force)\n     apply (metis epdaHS2epdaS_derivation_preserves_derivation_initial)\n    apply(rule_tac\n      t = \"derivation_append (epdaHS2epdaS_derivation dh) dc n\"\n      and s = \"epdaHS2epdaS_derivation dc'\"\n      in ssubst)\n     apply(force)\n    apply (metis epdaHS2epdaS_derivation_preserves_maximum_of_domain)\n   apply(force)\n  apply (metis epdaS_vs_epdaHS_inst_AX_equal_length)\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_bisimulation_compatible_with_crop1: \"\n  (\\<forall>G1. valid_epda G1 \\<longrightarrow> (\\<forall>dh. epdaHS.derivation_initial G1 dh \\<and> Ex (maximum_of_domain dh) \\<longrightarrow> (\\<forall>n. maximum_of_domain (epdaHS2epdaS_derivation dh) n \\<longrightarrow> (\\<forall>dc. derivation_append_fit (epdaHS2epdaS_derivation dh) dc n \\<longrightarrow> (\\<forall>dc'. epdaHS.derivation_initial G1 dc' \\<and> Ex (maximum_of_domain dc') \\<and> epdaHS2epdaS_derivation dc' = derivation_append (epdaHS2epdaS_derivation dh) dc n \\<longrightarrow> (\\<forall>x\\<le>n. dh x = dc' x))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 dh n x dc dc' xa xb)(*strict*)\n  apply(rule epdaS_vs_epdaHS_inst_hlp_bisimulation_compatible_with_crop)\n          apply(rename_tac G1 dh n x dc dc' xa xb)(*strict*)\n          apply(force)+\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_bisimulation_compatible_with_crop2: \"\n  (\\<forall>G1. valid_epda G1 \\<longrightarrow> (\\<forall>dh. epdaHS.derivation_initial G1 dh \\<and> Ex (maximum_of_domain dh) \\<longrightarrow> (\\<forall>n. maximum_of_domain dh n \\<longrightarrow> (\\<forall>dc'. derivation_append_fit dh dc' n \\<longrightarrow> epdaHS.derivation_initial G1 (derivation_append dh dc' n) \\<and> Ex (maximum_of_domain (derivation_append dh dc' n)) \\<longrightarrow> (\\<forall>x\\<le>n. epdaHS2epdaS_derivation dh x = epdaHS2epdaS_derivation (derivation_append dh dc' n) x)))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 dh n x dc' xa xb)(*strict*)\n  apply(simp add: epdaHS2epdaS_derivation_def)\n  apply(subgoal_tac \"\\<exists>e c. dh xa = Some (pair e c)\")\n   apply(rename_tac G1 dh n x dc' xa xb)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 dh n x dc' xa xb e c)(*strict*)\n   apply(simp add: derivation_append_def)\n  apply(rename_tac G1 dh n x dc' xa xb)(*strict*)\n  apply(subgoal_tac \"x = n\")\n   apply(rename_tac G1 dh n x dc' xa xb)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 dh n dc' xa xb)(*strict*)\n   apply(rule epdaHS.some_position_has_details_before_max_dom)\n     apply(rename_tac G1 dh n dc' xa xb)(*strict*)\n     apply(rule epdaHS.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac G1 dh n dc' xa xb)(*strict*)\n    apply(force)\n   apply(rename_tac G1 dh n dc' xa xb)(*strict*)\n   apply(force)\n  apply(rename_tac G1 dh n x dc' xa xb)(*strict*)\n  apply(rule epdaHS.maximum_of_domainUnique)\n    apply(rename_tac G1 dh n x dc' xa xb)(*strict*)\n    apply(rule epdaHS.derivation_initial_is_derivation)\n    apply(force)\n   apply(rename_tac G1 dh n x dc' xa xb)(*strict*)\n   apply(force)\n  apply(rename_tac G1 dh n x dc' xa xb)(*strict*)\n  apply(force)\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_accept_id1: \"\n  (\\<forall>G1 d2. valid_epda G1 \\<and> epdaHS.derivation_initial G1 d2 \\<and> Ex (maximum_of_domain d2) \\<longrightarrow> epdaS_marking_condition G1 (epdaHS2epdaS_derivation d2) \\<longrightarrow> epdaHS_marking_condition G1 d2)\"\n  apply(clarsimp)\n  apply(rename_tac G1 d2 x)(*strict*)\n  apply(simp add: epdaS_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac G1 d2 x i e c)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d2 i = Some (pair e c)\")\n   apply(rename_tac G1 d2 x i e c)(*strict*)\n   prefer 2\n   apply(simp add: epdaHS2epdaS_derivation_def)\n   apply(case_tac \"d2 i\")\n    apply(rename_tac G1 d2 x i e c)(*strict*)\n    apply(force)\n   apply(rename_tac G1 d2 x i e c a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac G1 d2 x i e c a option b)(*strict*)\n   apply(force)\n  apply(rename_tac G1 d2 x i e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 d2 x i e c ea ca)(*strict*)\n  apply(simp add: epdaHS_marking_condition_def)\n  apply(rule_tac\n      x = \"i\"\n      in exI)\n  apply(rule_tac\n      x = \"ea\"\n      in exI)\n  apply(rule_tac\n      x = \"ca\"\n      in exI)\n  apply(rule context_conjI)\n   apply(rename_tac G1 d2 x i e c ea ca)(*strict*)\n   apply(simp add: epdaHS2epdaS_derivation_def)\n  apply(rename_tac G1 d2 x i e c ea ca)(*strict*)\n  apply(clarsimp)\n  apply(simp add: epdaHS_marking_configurations_def epdaS_marking_configurations_def)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(rename_tac G1 d2 x i e c ea ca)(*strict*)\n   apply(simp add: epdaHS2epdaS_derivation_def)\n   apply(force)\n  apply(rename_tac G1 d2 x i e c ea ca)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 d2 x i e c ea ca)(*strict*)\n   apply(simp add: epdaHS2epdaS_derivation_def)\n   apply(clarsimp)\n  apply(rename_tac G1 d2 x i e c ea ca)(*strict*)\n  apply(rule epdaHS.belongs_configurations)\n   apply(rename_tac G1 d2 x i e c ea ca)(*strict*)\n   apply(rule epdaHS.derivation_initial_belongs)\n    apply(rename_tac G1 d2 x i e c ea ca)(*strict*)\n    apply(force)\n   apply(rename_tac G1 d2 x i e c ea ca)(*strict*)\n   apply(force)\n  apply(rename_tac G1 d2 x i e c ea ca)(*strict*)\n  apply(force)\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_accept_id2: \"\n  (\\<forall>G1 d2. valid_epda G1 \\<and> epdaHS.derivation_initial G1 d2 \\<and> Ex (maximum_of_domain d2) \\<longrightarrow> epdaHS_marking_condition G1 d2 \\<longrightarrow> epdaS_marking_condition G1 (epdaHS2epdaS_derivation d2))\"\n  apply(clarsimp)\n  apply(rename_tac G1 d2 x)(*strict*)\n  apply(simp add: epdaHS_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac G1 d2 x i e c)(*strict*)\n  apply(simp add: epdaS_marking_condition_def)\n  apply(rule_tac\n      x = \"i\"\n      in exI)\n  apply(subgoal_tac \"\\<exists>e c. epdaHS2epdaS_derivation d2 i = Some (pair e c)\")\n   apply(rename_tac G1 d2 x i e c)(*strict*)\n   prefer 2\n   apply(simp add: epdaHS2epdaS_derivation_def)\n  apply(rename_tac G1 d2 x i e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 d2 x i e c ea ca)(*strict*)\n  apply(simp add: epdaHS_marking_configurations_def epdaS_marking_configurations_def)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(rename_tac G1 d2 x i e c ea ca)(*strict*)\n   apply(simp add: epdaHS2epdaS_derivation_def)\n   apply(clarsimp)\n  apply(rename_tac G1 d2 x i e c ea ca)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 d2 x i e c ea ca)(*strict*)\n   apply(simp add: epdaHS2epdaS_derivation_def)\n   apply(clarsimp)\n  apply(rename_tac G1 d2 x i e c ea ca)(*strict*)\n  apply(rule_tac\n      d = \"epdaHS2epdaS_derivation d2\"\n      in epdaS.belongs_configurations)\n   apply(rename_tac G1 d2 x i e c ea ca)(*strict*)\n   apply(rule epdaS.derivation_initial_belongs)\n    apply(rename_tac G1 d2 x i e c ea ca)(*strict*)\n    apply(force)\n   apply(rename_tac G1 d2 x i e c ea ca)(*strict*)\n   apply (metis epdaHS2epdaS_derivation_preserves_derivation_initial)\n  apply(rename_tac G1 d2 x i e c ea ca)(*strict*)\n  apply(force)\n  done\n\nlemma epdaHS2epdaS_derivation_reflects_string_state_delta: \"\n  valid_epda G\n  \\<Longrightarrow> epdaHS.derivation_initial G d\n  \\<Longrightarrow> d i = Some (pair ei ci)\n  \\<Longrightarrow> d j = Some (pair ej cj)\n  \\<Longrightarrow> i\\<le>j\n  \\<Longrightarrow> epdaS_string_state ci' = w @ epdaS_string_state cj'\n  \\<Longrightarrow> (epdaHS2epdaS_derivation d) i = Some (pair ei ci')\n  \\<Longrightarrow> (epdaHS2epdaS_derivation d) j = Some (pair ej cj')\n  \\<Longrightarrow> epdaHS_string_state ci = w @ epdaHS_string_state cj\"\n  apply(induct \"j-i\" arbitrary: j ej cj cj' w)\n   apply(rename_tac j ej cj cj' w)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x j ej cj cj' w)(*strict*)\n  apply(clarsimp)\n  apply(case_tac j)\n   apply(rename_tac x j ej cj cj' w)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x j ej cj cj' w nat)(*strict*)\n  apply(erule_tac\n      x = \"nat\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(rename_tac x ej cj cj' w nat)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d nat = Some (pair e1 c1) \\<and> d (Suc nat) = Some (pair (Some e2) c2) \\<and> epdaHS_step_relation G c1 e2 c2\")\n   apply(rename_tac x ej cj cj' w nat)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m = \"Suc nat\"\n      in epdaHS.step_detail_before_some_position)\n     apply(rename_tac x ej cj cj' w nat)(*strict*)\n     apply(rule epdaHS.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac x ej cj cj' w nat)(*strict*)\n    apply(force)\n   apply(rename_tac x ej cj cj' w nat)(*strict*)\n   apply(force)\n  apply(rename_tac x ej cj cj' w nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x cj cj' w nat e1 e2 c1)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d nat = Some (pair e c)\")\n   apply(rename_tac x cj cj' w nat e1 e2 c1)(*strict*)\n   apply(subgoal_tac \"\\<exists>e c. (epdaHS2epdaS_derivation d) nat = Some (pair e c)\")\n    apply(rename_tac x cj cj' w nat e1 e2 c1)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n    apply(erule_tac\n      x = \"e\"\n      in meta_allE)\n    apply(clarsimp)\n    apply(erule_tac\n      x = \"c1\"\n      in meta_allE)\n    apply(clarsimp)\n    apply(erule_tac\n      x = \"c\"\n      in meta_allE)\n    apply(clarsimp)\n    apply(subgoal_tac \"\\<exists>w. epdaHS_string_state c1 = w @ epdaHS_string_state cj\")\n     apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n     prefer 2\n     apply(rule_tac\n      j = \"Suc 0\"\n      in epdaHS.derivation_monotonically_dec)\n          apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n          apply(force)\n         apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n         apply(force)\n        apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n        apply(rule epdaHS.derivation_initial_belongs)\n         apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n         apply(force)\n        apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n        apply(force)\n       apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n       apply(rule epdaHS.derivation_initial_is_derivation)\n       apply(force)\n      apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n      apply(force)\n     apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n     apply(force)\n    apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n    apply(subgoal_tac \"\\<exists>w. epdaHS_string_state ci = w @ epdaHS_string_state c1\")\n     apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n     prefer 2\n     apply(rule_tac\n      j = \"nat-i\"\n      in epdaHS.derivation_monotonically_dec)\n          apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n          apply(force)\n         apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n         apply(force)\n        apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n        apply(rule epdaHS.derivation_initial_belongs)\n         apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n         apply(force)\n        apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n        apply(force)\n       apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n       apply(rule epdaHS.derivation_initial_is_derivation)\n       apply(force)\n      apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n      apply(force)\n     apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n     apply(force)\n    apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb)(*strict*)\n    apply(subgoal_tac \"\\<exists>w. epdaS_string_state c = w @ epdaS_string_state cj'\")\n     apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb)(*strict*)\n     prefer 2\n     apply(rule_tac\n      d = \"epdaHS2epdaS_derivation d\"\n      and j = \"Suc 0\"\n      in epdaS.derivation_monotonically_dec)\n          apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb)(*strict*)\n          apply(force)\n         apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb)(*strict*)\n         apply(force)\n        apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb)(*strict*)\n        apply(rule epdaS.derivation_initial_belongs)\n         apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb)(*strict*)\n         apply(force)\n        apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb)(*strict*)\n        apply (metis epdaHS2epdaS_derivation_preserves_derivation_initial)\n       apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb)(*strict*)\n       apply(rule epdaS.derivation_initial_is_derivation)\n       apply (metis epdaHS2epdaS_derivation_preserves_derivation_initial)\n      apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb)(*strict*)\n      apply(force)\n     apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb)(*strict*)\n     apply(force)\n    apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb wc)(*strict*)\n    apply(subgoal_tac \"\\<exists>w. epdaS_string_state ci' = w @ epdaS_string_state c\")\n     apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb wc)(*strict*)\n     prefer 2\n     apply(rule_tac\n      d = \"epdaHS2epdaS_derivation d\"\n      and j = \"nat-i\"\n      in epdaS.derivation_monotonically_dec)\n          apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb wc)(*strict*)\n          apply(force)\n         apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb wc)(*strict*)\n         apply(force)\n        apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb wc)(*strict*)\n        apply(rule epdaS.derivation_initial_belongs)\n         apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb wc)(*strict*)\n         apply(force)\n        apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb wc)(*strict*)\n        apply (metis epdaHS2epdaS_derivation_preserves_derivation_initial)\n       apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb wc)(*strict*)\n       apply(rule epdaS.derivation_initial_is_derivation)\n       apply (metis epdaHS2epdaS_derivation_preserves_derivation_initial)\n      apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb wc)(*strict*)\n      apply(force)\n     apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb wc)(*strict*)\n     apply(force)\n    apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa wb wc)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wb wc wd)(*strict*)\n    apply(erule_tac\n      x = \"wd\"\n      in meta_allE)\n    apply(clarsimp)\n    apply(erule meta_impE)\n     apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wb wc wd)(*strict*)\n     apply(force)\n    apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wb wc wd)(*strict*)\n    apply(erule meta_impE)\n     apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wb wc wd)(*strict*)\n     apply(simp add: epdaHS2epdaS_derivation_def)\n    apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wb wc wd)(*strict*)\n    apply(erule meta_impE)\n     apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wb wc wd)(*strict*)\n     apply(force)\n    apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wb wc wd)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wc wd)(*strict*)\n    apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. epdaHS2epdaS_derivation d nat = Some (pair e1 c1) \\<and> epdaHS2epdaS_derivation d (Suc nat) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation G c1 e2 c2\")\n     apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wc wd)(*strict*)\n     prefer 2\n     apply(rule_tac\n      m = \"Suc nat\"\n      in epdaS.step_detail_before_some_position)\n       apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wc wd)(*strict*)\n       apply(rule epdaS.derivation_initial_is_derivation)\n       apply (metis epdaHS2epdaS_derivation_preserves_derivation_initial)\n      apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wc wd)(*strict*)\n      apply(force)\n     apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wc wd)(*strict*)\n     apply(force)\n    apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wc wd)(*strict*)\n    apply(clarsimp)\n    apply(simp add: epdaS_string_state_def epdaHS_string_state_def epdaS_step_relation_def epdaHS_step_relation_def)\n   apply(rename_tac x cj cj' w nat e1 e2 c1)(*strict*)\n   apply(clarsimp)\n   apply(simp add: epdaHS2epdaS_derivation_def)\n  apply(rename_tac x cj cj' w nat e1 e2 c1)(*strict*)\n  apply(simp add: epdaHS2epdaS_derivation_def)\n  done\n\nlemma epdaHS2epdaS_derivation_preserves_string_state_delta: \"\n  valid_epda G\n  \\<Longrightarrow> epdaHS.derivation_initial G d\n  \\<Longrightarrow> d i = Some (pair ei ci)\n  \\<Longrightarrow> d j = Some (pair ej cj)\n  \\<Longrightarrow> i\\<le>j\n  \\<Longrightarrow> epdaHS_string_state ci = w @ epdaHS_string_state cj\n  \\<Longrightarrow> (epdaHS2epdaS_derivation d) i = Some (pair ei ci')\n  \\<Longrightarrow> (epdaHS2epdaS_derivation d) j = Some (pair ej cj')\n  \\<Longrightarrow> epdaS_string_state ci' = w @ epdaS_string_state cj'\"\n  apply(induct \"j-i\" arbitrary: j ej cj cj' w)\n   apply(rename_tac j ej cj cj' w)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x j ej cj cj' w)(*strict*)\n  apply(clarsimp)\n  apply(case_tac j)\n   apply(rename_tac x j ej cj cj' w)(*strict*)\n   apply(force)\n  apply(rename_tac x j ej cj cj' w nat)(*strict*)\n  apply(erule_tac\n      x = \"nat\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(rename_tac x ej cj cj' w nat)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d nat = Some (pair e1 c1) \\<and> d (Suc nat) = Some (pair (Some e2) c2) \\<and> epdaHS_step_relation G c1 e2 c2\")\n   apply(rename_tac x ej cj cj' w nat)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m = \"Suc nat\"\n      in epdaHS.step_detail_before_some_position)\n     apply(rename_tac x ej cj cj' w nat)(*strict*)\n     apply(rule epdaHS.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac x ej cj cj' w nat)(*strict*)\n    apply(force)\n   apply(rename_tac x ej cj cj' w nat)(*strict*)\n   apply(force)\n  apply(rename_tac x ej cj cj' w nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x cj cj' w nat e1 e2 c1)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d nat = Some (pair e c)\")\n   apply(rename_tac x cj cj' w nat e1 e2 c1)(*strict*)\n   apply(subgoal_tac \"\\<exists>e c. (epdaHS2epdaS_derivation d) nat = Some (pair e c)\")\n    apply(rename_tac x cj cj' w nat e1 e2 c1)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n    apply(erule_tac\n      x = \"e\"\n      in meta_allE)\n    apply(clarsimp)\n    apply(erule_tac\n      x = \"c1\"\n      in meta_allE)\n    apply(clarsimp)\n    apply(erule_tac\n      x = \"c\"\n      in meta_allE)\n    apply(clarsimp)\n    apply(subgoal_tac \"\\<exists>w. epdaHS_string_state c1 = w @ epdaHS_string_state cj\")\n     apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n     prefer 2\n     apply(rule_tac\n      j = \"Suc 0\"\n      in epdaHS.derivation_monotonically_dec)\n          apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n          apply(force)\n         apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n         apply(force)\n        apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n        apply(rule epdaHS.derivation_initial_belongs)\n         apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n         apply(force)\n        apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n        apply(force)\n       apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n       apply(rule epdaHS.derivation_initial_is_derivation)\n       apply(force)\n      apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n      apply(force)\n     apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n     apply(force)\n    apply(rename_tac x cj cj' w nat e1 e2 c1 e c)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n    apply(subgoal_tac \"\\<exists>w. epdaHS_string_state ci = w @ epdaHS_string_state c1\")\n     apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n     prefer 2\n     apply(rule_tac\n      j = \"nat-i\"\n      in epdaHS.derivation_monotonically_dec)\n          apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n          apply(force)\n         apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n         apply(force)\n        apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n        apply(rule epdaHS.derivation_initial_belongs)\n         apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n         apply(force)\n        apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n        apply(force)\n       apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n       apply(rule epdaHS.derivation_initial_is_derivation)\n       apply(force)\n      apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n      apply(force)\n     apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n     apply(force)\n    apply(rename_tac x cj cj' w nat e1 e2 c1 e c wa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wb)(*strict*)\n    apply(erule_tac\n      x = \"wb\"\n      in meta_allE)\n    apply(clarsimp)\n    apply(erule meta_impE)\n     apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wb)(*strict*)\n     apply(force)\n    apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wb)(*strict*)\n    apply(erule meta_impE)\n     apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wb)(*strict*)\n     apply(simp add: epdaHS2epdaS_derivation_def)\n    apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wb)(*strict*)\n    apply(erule meta_impE)\n     apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wb)(*strict*)\n     apply(force)\n    apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wb)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. epdaHS2epdaS_derivation d nat = Some (pair e1 c1) \\<and> epdaHS2epdaS_derivation d (Suc nat) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation G c1 e2 c2\")\n     apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wb)(*strict*)\n     prefer 2\n     apply(rule_tac\n      m = \"Suc nat\"\n      in epdaS.step_detail_before_some_position)\n       apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wb)(*strict*)\n       apply(rule epdaS.derivation_initial_is_derivation)\n       apply (metis epdaHS2epdaS_derivation_preserves_derivation_initial)\n      apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wb)(*strict*)\n      apply(force)\n     apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wb)(*strict*)\n     apply(force)\n    apply(rename_tac x cj cj' nat e1 e2 c1 e c wa wb)(*strict*)\n    apply(clarsimp)\n    apply(simp add: epdaS_string_state_def epdaHS_string_state_def epdaS_step_relation_def epdaHS_step_relation_def)\n   apply(rename_tac x cj cj' w nat e1 e2 c1)(*strict*)\n   apply(clarsimp)\n   apply(simp add: epdaHS2epdaS_derivation_def)\n  apply(rename_tac x cj cj' w nat e1 e2 c1)(*strict*)\n  apply(rule_tac\n      m = \"Suc nat\"\n      in epdaHS.pre_some_position_is_some_position)\n    apply(rename_tac x cj cj' w nat e1 e2 c1)(*strict*)\n    apply(rule epdaHS.derivation_initial_is_derivation)\n    apply(force)\n   apply(rename_tac x cj cj' w nat e1 e2 c1)(*strict*)\n   apply(force)\n  apply(rename_tac x cj cj' w nat e1 e2 c1)(*strict*)\n  apply(force)\n  done\n\nlemma epdaHS_get_unfixed_scheduler_DB_with_derivation_take: \"\n  valid_epda G\n  \\<Longrightarrow> epdaHS.derivation G d\n  \\<Longrightarrow> epdaHS_get_unfixed_scheduler_DB G d n = epdaHS_get_unfixed_scheduler_DB G (derivation_take d n) n\"\n  apply(simp add: epdaHS_get_unfixed_scheduler_DB_def)\n  apply(simp add: derivation_take_def)\n  done\n\nlemma derivation_take_distributes_over_epdaS2epdaHS_derivation: \"\n  derivation_take (epdaS2epdaHS_derivation G d) n = epdaS2epdaHS_derivation G (derivation_take d n)\"\n  apply(rule ext)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: derivation_take_def epdaS2epdaHS_derivation_def derivation_take_def)\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_unAX_marked_effect_id1: \"\n  (\\<forall>G1 d2. valid_epda G1 \\<and> epdaHS.derivation_initial G1 d2 \\<and> Ex (maximum_of_domain d2) \\<longrightarrow> (\\<forall>o1. o1 \\<in> epdaS_unmarked_effect G1 (epdaHS2epdaS_derivation d2) \\<longrightarrow> o1 \\<in> epdaHS_unmarked_effect G1 d2))\"\n  apply(clarsimp)\n  apply(rename_tac G1 d2 o1 x)(*strict*)\n  apply(simp add: epdaS_unmarked_effect_def epdaHS_unmarked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G1 d2 o1 x c c' i e)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d2 i = Some (pair e c)\")\n   apply(rename_tac G1 d2 o1 x c c' i e)(*strict*)\n   apply(subgoal_tac \"\\<exists>c. d2 0 = Some (pair None c)\")\n    apply(rename_tac G1 d2 o1 x c c' i e)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 d2 o1 x c c' i e ea ca cb)(*strict*)\n    apply(rule_tac\n      x = \"cb\"\n      in exI)\n    apply(rule conjI)\n     apply(rename_tac G1 d2 o1 x c c' i e ea ca cb)(*strict*)\n     apply(rule_tac\n      x = \"i\"\n      in exI)\n     apply(rule_tac\n      x = \"ea\"\n      in exI)\n     apply(clarsimp)\n    apply(rename_tac G1 d2 o1 x c c' i e ea ca cb)(*strict*)\n    apply(simp add: epdaHS2epdaS_derivation_def)\n    apply(clarsimp)\n   apply(rename_tac G1 d2 o1 x c c' i e)(*strict*)\n   apply(simp add: epdaHS2epdaS_derivation_def)\n   apply(clarsimp)\n   apply(rename_tac G1 d2 o1 x c i e ca)(*strict*)\n   apply(case_tac \"d2 0\")\n    apply(rename_tac G1 d2 o1 x c i e ca)(*strict*)\n    apply(force)\n   apply(rename_tac G1 d2 o1 x c i e ca a)(*strict*)\n   apply(case_tac a)\n   apply(rename_tac G1 d2 o1 x c i e ca a option b)(*strict*)\n   apply(force)\n  apply(rename_tac G1 d2 o1 x c c' i e)(*strict*)\n  apply(simp add: epdaHS2epdaS_derivation_def)\n  apply(case_tac \"d2 i\")\n   apply(rename_tac G1 d2 o1 x c c' i e)(*strict*)\n   apply(force)\n  apply(rename_tac G1 d2 o1 x c c' i e a)(*strict*)\n  apply(case_tac a)\n  apply(rename_tac G1 d2 o1 x c c' i e a option b)(*strict*)\n  apply(force)\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_unAX_marked_effect_id2: \"\n  (\\<forall>G1 d2. valid_epda G1 \\<and> epdaHS.derivation_initial G1 d2 \\<and> Ex (maximum_of_domain d2) \\<longrightarrow> (\\<forall>o2. o2 \\<in> epdaHS_unmarked_effect G1 d2 \\<longrightarrow> o2 \\<in> epdaS_unmarked_effect G1 (epdaHS2epdaS_derivation d2)))\"\n  apply(clarsimp)\n  apply(rename_tac G1 d2 o2 x)(*strict*)\n  apply(simp add: epdaS_unmarked_effect_def epdaHS_unmarked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G1 d2 o2 x c c' i e)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. epdaHS2epdaS_derivation d2 i = Some (pair e c)\")\n   apply(rename_tac G1 d2 o2 x c c' i e)(*strict*)\n   apply(subgoal_tac \"\\<exists>c. epdaHS2epdaS_derivation d2 0 = Some (pair None c)\")\n    apply(rename_tac G1 d2 o2 x c c' i e)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 d2 o2 x c c' i e ea ca cb)(*strict*)\n    apply(rule_tac\n      x = \"cb\"\n      in exI)\n    apply(rule conjI)\n     apply(rename_tac G1 d2 o2 x c c' i e ea ca cb)(*strict*)\n     apply(rule_tac\n      x = \"i\"\n      in exI)\n     apply(rule_tac\n      x = \"ea\"\n      in exI)\n     apply(clarsimp)\n    apply(rename_tac G1 d2 o2 x c c' i e ea ca cb)(*strict*)\n    apply(simp add: epdaHS2epdaS_derivation_def)\n    apply(clarsimp)\n   apply(rename_tac G1 d2 o2 x c c' i e)(*strict*)\n   apply(case_tac \"d2 0\")\n    apply(rename_tac G1 d2 o2 x c c' i e)(*strict*)\n    apply(force)\n   apply(rename_tac G1 d2 o2 x c c' i e a)(*strict*)\n   apply(case_tac a)\n   apply(rename_tac G1 d2 o2 x c c' i e a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 d2 o2 x c c' i e ea ca)(*strict*)\n   apply(subgoal_tac \"\\<exists>c. d2 0 = Some (pair None c)\")\n    apply(rename_tac G1 d2 o2 x c c' i e ea ca)(*strict*)\n    apply(simp add: epdaHS2epdaS_derivation_def)\n   apply(rename_tac G1 d2 o2 x c c' i e ea ca)(*strict*)\n   apply(case_tac \"d2 0\")\n    apply(rename_tac G1 d2 o2 x c c' i e ea ca)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G1 d2 o2 x c c' i e ea ca a)(*strict*)\n   apply(case_tac a)\n   apply(rename_tac G1 d2 o2 x c c' i e ea ca a option b)(*strict*)\n   apply(force)\n  apply(rename_tac G1 d2 o2 x c c' i e)(*strict*)\n  apply(simp add: epdaHS2epdaS_derivation_def)\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_marked_effect_id1: \"\n  (\\<forall>G1 d2. valid_epda G1 \\<and> epdaHS.derivation_initial G1 d2 \\<and> Ex (maximum_of_domain d2) \\<longrightarrow> (\\<forall>o1. o1 \\<in> epdaS_marked_effect G1 (epdaHS2epdaS_derivation d2) \\<longrightarrow> epdaS_marking_condition G1 (epdaHS2epdaS_derivation d2) \\<longrightarrow> o1 \\<in> epdaHS_marked_effect G1 d2))\"\n  apply(clarsimp)\n  apply(rename_tac G1 d2 o1 x)(*strict*)\n  apply(simp add: epdaS_marked_effect_def epdaHS_marked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G1 d2 x c)(*strict*)\n  apply(simp add: epdaS_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac G1 d2 x c i e ca)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d2 i = Some (pair e c)\")\n   apply(rename_tac G1 d2 x c i e ca)(*strict*)\n   prefer 2\n   apply(simp add: epdaHS2epdaS_derivation_def)\n   apply(case_tac \"d2 i\")\n    apply(rename_tac G1 d2 x c i e ca)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G1 d2 x c i e ca a)(*strict*)\n   apply(case_tac a)\n   apply(rename_tac G1 d2 x c i e ca a option b)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 d2 x c i e ca)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. d2 0 = Some (pair None c)\")\n   apply(rename_tac G1 d2 x c i e ca)(*strict*)\n   prefer 2\n   apply(rule epdaHS.some_position_has_details_at_0)\n   apply(rule epdaHS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac G1 d2 x c i e ca)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 d2 x c i e ca ea cb cc)(*strict*)\n  apply(simp add: epdaHS2epdaS_derivation_def)\n  apply(clarsimp)\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_marked_effect_id2: \"\n  \\<forall>G1 d2. valid_epda G1 \\<and> epdaHS.derivation_initial G1 d2 \\<and> Ex (maximum_of_domain d2) \\<longrightarrow> (\\<forall>o2. o2 \\<in> epdaHS_marked_effect G1 d2 \\<longrightarrow> epdaHS_marking_condition G1 d2 \\<longrightarrow> o2 \\<in> epdaS_marked_effect G1 (epdaHS2epdaS_derivation d2))\"\n  apply(clarsimp)\n  apply(rename_tac G1 d2 o2 x)(*strict*)\n  apply(simp add: epdaS_marked_effect_def epdaHS_marked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G1 d2 x c)(*strict*)\n  apply(simp add: epdaHS_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac G1 d2 x c i e ca)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. epdaHS2epdaS_derivation d2 i = Some (pair e c)\")\n   apply(rename_tac G1 d2 x c i e ca)(*strict*)\n   prefer 2\n   apply(simp add: epdaHS2epdaS_derivation_def)\n  apply(rename_tac G1 d2 x c i e ca)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. d2 0 = Some (pair None c)\")\n   apply(rename_tac G1 d2 x c i e ca)(*strict*)\n   prefer 2\n   apply(rule epdaHS.some_position_has_details_at_0)\n   apply(rule epdaHS.derivation_initial_is_derivation)\n   apply(force)\n  apply(rename_tac G1 d2 x c i e ca)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. epdaHS2epdaS_derivation d2 0 = Some (pair None c)\")\n   apply(rename_tac G1 d2 x c i e ca)(*strict*)\n   prefer 2\n   apply(simp add: epdaHS2epdaS_derivation_def)\n  apply(rename_tac G1 d2 x c i e ca)(*strict*)\n  apply(case_tac \"d2 0\")\n   apply(rename_tac G1 d2 x c i e ca)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 d2 x c i e ca a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 d2 x c i e ca ea cb cc)(*strict*)\n  apply(simp add: epdaHS2epdaS_derivation_def)\n  apply(clarsimp)\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_step_labels_unique1: \"\n  (\\<forall>G1 G2 e1 e21 e22. valid_epda G1 \\<and> G1 = G2 \\<longrightarrow> e1 \\<in> epda_step_labels G1 \\<longrightarrow> e21 \\<in> epda_step_labels G2 \\<longrightarrow> e22 \\<in> epda_step_labels G2 \\<longrightarrow> e1 = e21 \\<and> e1 \\<in> epda_delta G1 \\<longrightarrow> e1 = e22 \\<and> e1 \\<in> epda_delta G1 \\<longrightarrow> e21 = e22)\"\n  apply(clarsimp)\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_step_labels_unique2: \"\n  (\\<forall>G1 G2 e11 e12 e2. valid_epda G1 \\<and> G1 = G2 \\<longrightarrow> e11 \\<in> epda_step_labels G1 \\<longrightarrow> e12 \\<in> epda_step_labels G1 \\<longrightarrow> e2 \\<in> epda_step_labels G2 \\<longrightarrow> e11 = e2 \\<and> e11 \\<in> epda_delta G1 \\<longrightarrow> e12 = e2 \\<and> e12 \\<in> epda_delta G1 \\<longrightarrow> e11 = e12)\"\n  apply(clarsimp)\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_step_labels_exists1: \"\n  (\\<forall>G1 G2 e1. valid_epda G1 \\<and> G1 = G2 \\<longrightarrow> e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<exists>e2\\<in> epda_step_labels G2. e1 = e2 \\<and> e1 \\<in> epda_delta G1))\"\n  apply(clarsimp)\n  apply(rename_tac G1 e1)(*strict*)\n  apply(simp add: epda_step_labels_def)\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_step_labels_exists2: \"\n  (\\<forall>G1 G2 e2. valid_epda G1 \\<and> G1 = G2 \\<longrightarrow> e2 \\<in> epda_step_labels G2 \\<longrightarrow> (\\<exists>e1\\<in> epda_step_labels G1. e1 = e2 \\<and> e1 \\<in> epda_delta G1))\"\n  apply(clarsimp)\n  apply(rename_tac G1 e2)(*strict*)\n  apply(simp add: epda_step_labels_def)\n  done\n\nlemma drop_map_nat_seq: \"\n  drop i (map f (nat_seq x j)) = map f (nat_seq (x+i) j)\"\n  apply(case_tac \"x\\<le>j\")\n   apply(rule listEqI)\n    apply(clarsimp)\n    apply (metis diff_diff_left nat_seq_length_prime)\n   apply(rename_tac ia)(*strict*)\n   apply(clarsimp)\n   apply(rule_tac\n      t = \"nat_seq x j ! (i + ia)\"\n      and s = \"x+(i+ia)\"\n      in ssubst)\n    apply(rename_tac ia)(*strict*)\n    apply(rule nat_seq_nth_compute)\n     apply(rename_tac ia)(*strict*)\n     apply(force)\n    apply(rename_tac ia)(*strict*)\n    apply (metis Suc_eq_plus1 diff_diff_left le_diff_conv2 less_diff_conv nat_seq_length_prime add.assoc add.commute not_less_eq trivNat)\n   apply(rename_tac ia)(*strict*)\n   apply(rule_tac\n      t = \"map f (nat_seq (x + i) j) ! ia\"\n      and s = \"f (nat_seq (x + i) j ! ia)\"\n      in ssubst)\n    apply(rename_tac ia)(*strict*)\n    apply (metis Suc_eq_plus1 diff_diff_left nat_seq_length_prime nth_map)\n   apply(rename_tac ia)(*strict*)\n   apply(rule_tac\n      t = \"nat_seq (x + i) j ! ia\"\n      and s = \"(x+i)+ia\"\n      in ssubst)\n    apply(rename_tac ia)(*strict*)\n    apply(rule nat_seq_nth_compute)\n     apply(rename_tac ia)(*strict*)\n     apply (metis Suc_eq_plus1 diff_diff_left diff_is_0_eq' less_eq_Suc_le less_zeroE nat_seq_length_prime trivNat)\n    apply(rename_tac ia)(*strict*)\n    apply (metis Suc_eq_plus1 add_leE diff_diff_left le_diff_conv2 less_diff_conv nat_seq_length_prime not_less_eq trivNat)\n   apply(rename_tac ia)(*strict*)\n   apply (metis add.commute add.left_commute)\n  apply(rule_tac\n      t = \"nat_seq x j\"\n      and s = \"[]\"\n      in ssubst)\n   apply (metis nat_seqEmpty trivNat)\n  apply(clarsimp)\n  apply(metis nat_seqEmpty trans_less_add1 trivNat)\n  done\n\nlemma epdaHS_history_computation_by_folding_of_edges: \"\n  valid_epda G\n  \\<Longrightarrow> epdaHS.derivation G d\n  \\<Longrightarrow> d i = Some (pair e c)\n  \\<Longrightarrow> d j = Some (pair e' c')\n  \\<Longrightarrow> i\\<le>j\n  \\<Longrightarrow> epdaHS_conf_history c' = epdaHS_conf_history c @ (foldl append [] (map (\\<lambda>e. option_to_list(edge_event(the e))) (drop i (get_labels d j))))\"\n  apply(induct \"j-i\" arbitrary: i e c)\n   apply(rename_tac i e c)(*strict*)\n   apply(clarsimp)\n   apply(rule_tac\n      t = \"drop j (get_labels d j)\"\n      and s = \"[]\"\n      in ssubst)\n    apply(clarsimp)\n    apply (metis get_labels_length eq_imp_le)\n   apply(clarsimp)\n  apply(rename_tac x i e c)(*strict*)\n  apply(clarsimp)\n  apply(erule_tac\n      x = \"Suc i\"\n      in meta_allE)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d i = Some (pair e1 c1) \\<and> d (Suc i) = Some (pair (Some e2) c2) \\<and> epdaHS_step_relation G c1 e2 c2\")\n   apply(rename_tac x i e c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m = \"j\"\n      in epdaHS.step_detail_before_some_position)\n     apply(rename_tac x i e c)(*strict*)\n     apply(simp add: epdaHS.derivation_initial_def)\n    apply(rename_tac x i e c)(*strict*)\n    apply(force)\n   apply(rename_tac x i e c)(*strict*)\n   apply(force)\n  apply(rename_tac x i e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x i e c e2 c2)(*strict*)\n  apply(erule_tac\n      x = \"Some e2\"\n      in meta_allE)\n  apply(erule_tac\n      x = \"c2\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(erule meta_impE)\n   apply(rename_tac x i e c e2 c2)(*strict*)\n   apply(force)\n  apply(rename_tac x i e c e2 c2)(*strict*)\n  apply(erule meta_impE)\n   apply(rename_tac x i e c e2 c2)(*strict*)\n   apply(force)\n  apply(rename_tac x i e c e2 c2)(*strict*)\n  apply(simp add: get_labels_def)\n  apply(rule_tac\n      t = \"drop i (map (\\<lambda>i. get_label (d i)) (nat_seq (Suc 0) j))\"\n      and s = \"map (\\<lambda>i. get_label (d i)) (nat_seq (Suc 0 + i) j)\"\n      in ssubst)\n   apply(rename_tac x i e c e2 c2)(*strict*)\n   apply(rule drop_map_nat_seq)\n  apply(rename_tac x i e c e2 c2)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"drop (Suc i) (map (\\<lambda>i. get_label (d i)) (nat_seq (Suc 0) j)) = map (\\<lambda>i. get_label (d i)) (nat_seq (Suc 0 + Suc i) j)\")\n   apply(rename_tac x i e c e2 c2)(*strict*)\n   prefer 2\n   apply(rule drop_map_nat_seq)\n  apply(rename_tac x i e c e2 c2)(*strict*)\n  apply(clarsimp)\n  apply(thin_tac \"drop (Suc i) (map (\\<lambda>i. get_label (d i)) (nat_seq (Suc 0) j)) = map (\\<lambda>i. get_label (d i)) (nat_seq (Suc (Suc i)) j)\")\n  apply(rename_tac x i e c e2 c2)(*strict*)\n  apply(thin_tac \"epdaHS_conf_history c' = epdaHS_conf_history c2 @ foldl (@) [] (map ((\\<lambda>e. option_to_list (edge_event (the e))) \\<circ> (\\<lambda>i. get_label (d i))) (nat_seq (Suc (Suc i)) j))\")\n  apply(rename_tac x i e c e2 c2)(*strict*)\n  apply(rule_tac\n      t = \"nat_seq (Suc i) j\"\n      and s = \"[Suc i]@nat_seq (Suc (Suc i)) j\"\n      in ssubst)\n   apply(rename_tac x i e c e2 c2)(*strict*)\n   apply(rule_tac\n      n = \"x\"\n      in nat_seq_drop_first)\n      apply(rename_tac x i e c e2 c2)(*strict*)\n      apply(force)\n     apply(rename_tac x i e c e2 c2)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac x i e c e2 c2)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac x i e c e2 c2)(*strict*)\n   apply(force)\n  apply(rename_tac x i e c e2 c2)(*strict*)\n  apply(rule_tac\n      t = \"foldl (@) [] (map ((\\<lambda>e. option_to_list (edge_event (the e))) \\<circ> (\\<lambda>i. get_label (d i))) ([Suc i] @ nat_seq (Suc (Suc i)) j))\"\n      and s = \"((\\<lambda>e. option_to_list (edge_event (the e))) \\<circ> (\\<lambda>i. get_label (d i))) (Suc i) @ foldl (@) [] (map ((\\<lambda>e. option_to_list (edge_event (the e))) \\<circ> (\\<lambda>i. get_label (d i))) (nat_seq (Suc (Suc i)) j))\"\n      in ssubst)\n   apply(rename_tac x i e c e2 c2)(*strict*)\n   apply (metis ConsApp concat_conv_foldl maps_def maps_simps(1))\n  apply(rename_tac x i e c e2 c2)(*strict*)\n  apply(rule_tac\n      t = \"epdaHS_conf_history c2\"\n      and s = \"epdaHS_conf_history c @ ((\\<lambda>e. option_to_list (edge_event (the e))) \\<circ> (\\<lambda>i. get_label (d i))) (Suc i)\"\n      in ssubst)\n   apply(rename_tac x i e c e2 c2)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac x i e c e2 c2)(*strict*)\n  apply(clarsimp)\n  apply(simp add: get_label_def)\n  apply(simp add: epdaHS_step_relation_def)\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_bisimulation_compatible_with_replace_and_schedF1: \"\n  (\\<forall>G1. valid_epda G1 \\<longrightarrow> (\\<forall>dh. epdaHS.derivation_initial G1 dh \\<and> Ex (maximum_of_domain dh) \\<longrightarrow> (\\<forall>n. maximum_of_domain (epdaHS2epdaS_derivation dh) n \\<longrightarrow> (\\<forall>sUF. sUF \\<in> epda_effects G1 \\<longrightarrow> (\\<forall>dc dc'. epdaHS.derivation_initial G1 dc' \\<and> Ex (maximum_of_domain dc') \\<and> epdaHS2epdaS_derivation dc' = derivation_append (ATS_SchedUF_DB.replace_unfixed_scheduler_DB right_quotient_word (@) epdaS_set_unfixed_scheduler_DB epdaS_get_unfixed_scheduler_DB G1 (epdaHS2epdaS_derivation dh) sUF n) dc n \\<longrightarrow> (\\<forall>x\\<le>n. epdaHS_get_fixed_scheduler_DB G1 dh x = epdaHS_get_fixed_scheduler_DB G1 dc' x \\<and> ATS_SchedUF_DB.replace_unfixed_scheduler_DB right_quotient_word (@) epdaHS_set_unfixed_scheduler_DB epdaHS_get_unfixed_scheduler_DB G1 dh (epdaHS_get_unfixed_scheduler_DB G1 dc' n) n x = dc' x))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 dh n x sUF dc dc' xa xb)(*strict*)\n  apply(simp add: epdaHS_get_fixed_scheduler_DB_def)\n  apply(simp add: epdaHS.replace_unfixed_scheduler_DB_def epdaHS.map_unfixed_scheduler_DB_def)\n  apply(subgoal_tac \"n = x\")\n   apply(rename_tac G1 dh n x sUF dc dc' xa xb)(*strict*)\n   prefer 2\n   apply (metis epdaS_vs_epdaHS_inst_AX_equal_length)\n  apply(rename_tac G1 dh n x sUF dc dc' xa xb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. dh xa = Some (pair e c)\")\n   apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n   prefer 2\n   apply(rule epdaHS.some_position_has_details_before_max_dom)\n     apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n     apply(simp add: epdaHS.derivation_initial_def)\n     apply(force)\n    apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n    apply(force)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n   apply(force)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. dh x = Some (pair e c)\")\n   apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n   prefer 2\n   apply(rule epdaHS.some_position_has_details_before_max_dom)\n     apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n     apply(simp add: epdaHS.derivation_initial_def)\n     apply(force)\n    apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n    apply(force)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n   apply(force)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n  apply(subgoal_tac \"x\\<le>xb\")\n   apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea c ca)(*strict*)\n   apply(case_tac \"xb<x\")\n    apply(rename_tac G1 dh x sUF dc dc' xa xb e ea c ca)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea c ca)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"(\\<exists>y. epdaHS2epdaS_derivation dh x = Some y) \\<and>       epdaHS2epdaS_derivation dh (Suc x) = None\")\n    apply(rename_tac G1 dh x sUF dc dc' xa xb e ea c ca)(*strict*)\n    prefer 2\n    apply(simp add: maximum_of_domain_def)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea c ca)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea c ca y)(*strict*)\n   apply(subgoal_tac \"epdaHS2epdaS_derivation dc' (Suc xb) = derivation_append (ATS_SchedUF_DB.replace_unfixed_scheduler_DB right_quotient_word (@) epdaS_set_unfixed_scheduler_DB epdaS_get_unfixed_scheduler_DB G1 (epdaHS2epdaS_derivation dh) sUF x) dc x (Suc xb)\")\n    apply(rename_tac G1 dh x sUF dc dc' xa xb e ea c ca y)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea c ca y)(*strict*)\n   apply(thin_tac \"epdaHS2epdaS_derivation dc' = derivation_append (ATS_SchedUF_DB.replace_unfixed_scheduler_DB right_quotient_word (@) epdaS_set_unfixed_scheduler_DB epdaS_get_unfixed_scheduler_DB G1 (epdaHS2epdaS_derivation dh) sUF x) dc x\")\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea c ca y)(*strict*)\n   apply(simp add: epdaHS2epdaS_derivation_def)\n   apply(simp add: derivation_append_def)\n   apply(rename_tac G1 dh x sUF dc' xa xb e ea c ca y)(*strict*)\n   apply(simp add: epdaS_set_unfixed_scheduler_DB_def epdaHS2epdaS_derivation_def epdaS.replace_unfixed_scheduler_DB_def epdaS.map_unfixed_scheduler_DB_def get_configuration_def epdaS_get_unfixed_scheduler_DB_def epdaS_get_scheduler_def)\n   apply(case_tac \"dh (Suc xb)\")\n    apply(rename_tac G1 dh x sUF dc' xa xb e ea c ca y)(*strict*)\n    prefer 2\n    apply(rename_tac G1 dh x sUF dc' xa xb e ea c ca y a)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 dh x sUF dc' xa xb e ea c ca a)(*strict*)\n    apply(case_tac a)\n    apply(rename_tac G1 dh x sUF dc' xa xb e ea c ca a option conf)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 dh x sUF dc' xa xb e ea c ca option conf)(*strict*)\n    apply(simp add: maximum_of_domain_def)\n   apply(rename_tac G1 dh x sUF dc' xa xb e ea c ca y)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 dh x sUF dc' xa xb e ea c ca)(*strict*)\n   apply(case_tac \"Suc xb = x\")\n    apply(rename_tac G1 dh x sUF dc' xa xb e ea c ca)(*strict*)\n    apply(force)\n   apply(rename_tac G1 dh x sUF dc' xa xb e ea c ca)(*strict*)\n   apply(rule_tac\n      M = \"G1\"\n      and d = \"dh\"\n      and n = \"x\"\n      and i = \"Suc xb\"\n      in epdaHS.derivationNoFromNone2)\n      apply(rename_tac G1 dh x sUF dc' xa xb e ea c ca)(*strict*)\n      apply(rule epdaHS.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac G1 dh x sUF dc' xa xb e ea c ca)(*strict*)\n     apply(force)\n    apply(rename_tac G1 dh x sUF dc' xa xb e ea c ca)(*strict*)\n    apply(force)\n   apply(rename_tac G1 dh x sUF dc' xa xb e ea c ca)(*strict*)\n   apply(force)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. dc' xb = Some (pair e c)\")\n   apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n   prefer 2\n   apply(rule epdaHS.some_position_has_details_before_max_dom)\n     apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n     apply(simp add: epdaHS.derivation_initial_def)\n     apply(force)\n    apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n    apply(force)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n   apply(force)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. dc' x = Some (pair e c)\")\n   apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n   prefer 2\n   apply(rule epdaHS.some_position_has_details_before_max_dom)\n     apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n     apply(simp add: epdaHS.derivation_initial_def)\n     apply(force)\n    apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n    apply(force)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n   apply(force)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. dc' xa = Some (pair e c)\")\n   apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"epdaHS2epdaS_derivation dc' xa = derivation_append (ATS_SchedUF_DB.replace_unfixed_scheduler_DB right_quotient_word (@) epdaS_set_unfixed_scheduler_DB epdaS_get_unfixed_scheduler_DB G1 (epdaHS2epdaS_derivation dh) sUF x) dc x xa\")\n    apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n   apply(thin_tac \"epdaHS2epdaS_derivation dc' = derivation_append (ATS_SchedUF_DB.replace_unfixed_scheduler_DB right_quotient_word (@) epdaS_set_unfixed_scheduler_DB epdaS_get_unfixed_scheduler_DB G1 (epdaHS2epdaS_derivation dh) sUF x) dc x\")\n   apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n   apply(simp add: epdaHS2epdaS_derivation_def)\n   apply(clarsimp)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec c ca cb cc)(*strict*)\n   apply(case_tac \"dc' xa\")\n    apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec c ca cb cc)(*strict*)\n    apply(clarsimp)\n    apply(simp add: derivation_append_def)\n    apply(rename_tac G1 dh x sUF dc' xa xb e ea eb ec c ca cb cc)(*strict*)\n    apply(simp add: epdaS_set_unfixed_scheduler_DB_def epdaHS2epdaS_derivation_def epdaS.replace_unfixed_scheduler_DB_def epdaS.map_unfixed_scheduler_DB_def get_configuration_def epdaS_get_unfixed_scheduler_DB_def epdaS_get_scheduler_def)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec c ca cb cc a)(*strict*)\n   apply(case_tac a)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec c ca cb cc a option b)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\")(*strict*)\n  apply(subgoal_tac \"\\<exists>c. dc' 0 = Some (pair None c)\")\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\")(*strict*)\n   prefer 2\n   apply (metis epdaHS.derivation_initial_is_derivation epdaHS.some_position_has_details_at_0)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\")(*strict*)\n  apply(subgoal_tac \"\\<exists>c. dh 0 = Some (pair None c)\")\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\")(*strict*)\n   prefer 2\n   apply (metis epdaHS.derivation_initial_is_derivation epdaHS.some_position_has_details_at_0)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\")(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n  apply(subgoal_tac \"epdaHS_conf_history c = epdaHS_conf_history cd\")\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n   apply(subgoal_tac \"epdaHS2epdaS_derivation dc' xa = derivation_append (ATS_SchedUF_DB.replace_unfixed_scheduler_DB right_quotient_word (@) epdaS_set_unfixed_scheduler_DB epdaS_get_unfixed_scheduler_DB G1 (epdaHS2epdaS_derivation dh) sUF x) dc x xa\")\n    apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n   apply(subgoal_tac \"epdaHS2epdaS_derivation dc' x = derivation_append (ATS_SchedUF_DB.replace_unfixed_scheduler_DB right_quotient_word (@) epdaS_set_unfixed_scheduler_DB epdaS_get_unfixed_scheduler_DB G1 (epdaHS2epdaS_derivation dh) sUF x) dc x x\")\n    apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n   apply(thin_tac \"epdaHS2epdaS_derivation dc' = derivation_append (ATS_SchedUF_DB.replace_unfixed_scheduler_DB right_quotient_word (@) epdaS_set_unfixed_scheduler_DB epdaS_get_unfixed_scheduler_DB G1 (epdaHS2epdaS_derivation dh) sUF x) dc x\")\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n   apply(simp add: derivation_append_def)\n   apply(rename_tac G1 dh x sUF dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n   apply(simp add: epdaS_set_unfixed_scheduler_DB_def epdaHS2epdaS_derivation_def epdaS.replace_unfixed_scheduler_DB_def epdaS.map_unfixed_scheduler_DB_def get_configuration_def epdaS_get_unfixed_scheduler_DB_def epdaS_get_scheduler_def)\n   apply(subgoal_tac \"right_quotient_word (epdaHS_conf_scheduler ca) (epdaHS_conf_scheduler ca) = Some []\")\n    apply(rename_tac G1 dh x sUF dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n    prefer 2\n    apply(rule right_quotient_word_Some_by_append)\n    apply(force)\n   apply(rename_tac G1 dh x sUF dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n   apply(simp add: epdaHS_get_scheduler_def epdaHS_set_unfixed_scheduler_DB_def epdaHS_get_unfixed_scheduler_DB_def get_configuration_def)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n  apply(rule_tac\n      t = \"epdaHS_conf_history c\"\n      and s = \"epdaHS_conf_history cf @ (foldl append [] (map (\\<lambda>e. option_to_list(edge_event(the e))) (drop 0 (get_labels dh xa))))\"\n      in ssubst)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n   apply(rule epdaHS_history_computation_by_folding_of_edges)\n       apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n       apply(force)\n      apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n      apply(rule epdaHS.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n     apply(force)\n    apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n    apply(force)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n   apply(force)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n  apply(rule_tac\n      t = \"epdaHS_conf_history cd\"\n      and s = \"epdaHS_conf_history ce @ (foldl append [] (map (\\<lambda>e. option_to_list(edge_event(the e))) (drop 0 (get_labels dc' xa))))\"\n      in ssubst)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n   apply(rule epdaHS_history_computation_by_folding_of_edges)\n       apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n       apply(force)\n      apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n      apply(rule epdaHS.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n     apply(force)\n    apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n    apply(force)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n   apply(force)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n  apply(rule_tac\n      t = \"epdaHS_conf_history cf\"\n      and s = \"[]\"\n      in ssubst)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n   apply(simp add: epdaHS.derivation_initial_def epdaHS_initial_configurations_def)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n  apply(rule_tac\n      t = \"epdaHS_conf_history ce\"\n      and s = \"[]\"\n      in ssubst)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n   apply(simp add: epdaHS.derivation_initial_def epdaHS_initial_configurations_def)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n  apply(clarsimp)\n  apply(rule_tac\n      t = \"get_labels dc' xa\"\n      and s = \"get_labels dh xa\"\n      in ssubst)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf)(*strict*)\n  apply(simp add: get_labels_def)\n  apply(clarsimp)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf xc)(*strict*)\n  apply(subgoal_tac \"Suc 0\\<le>xc \\<and> xc\\<le>xa\")\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf xc)(*strict*)\n   prefer 2\n   apply (metis nat_seq_in_interval)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf xc)(*strict*)\n  apply(clarsimp)\n  apply(simp add: get_label_def)\n  apply(subgoal_tac \"\\<exists>e c. dc' xc = Some (pair e c)\")\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf xc)(*strict*)\n   prefer 2\n   apply(rule epdaHS.some_position_has_details_before_max_dom)\n     apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf xc)(*strict*)\n     apply(simp add: epdaHS.derivation_initial_def)\n     apply(force)\n    apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf xc)(*strict*)\n    apply(force)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf xc)(*strict*)\n   apply(force)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf xc)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. dh xc = Some (pair e c)\")\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf xc)(*strict*)\n   prefer 2\n   apply(rule epdaHS.some_position_has_details_before_max_dom)\n     apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf xc)(*strict*)\n     apply(simp add: epdaHS.derivation_initial_def)\n     apply(force)\n    apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf xc)(*strict*)\n    apply(force)\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf xc)(*strict*)\n   apply(force)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf xc)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf xc ee ef cg ch)(*strict*)\n  apply(subgoal_tac \"epdaHS2epdaS_derivation dc' xc = derivation_append (ATS_SchedUF_DB.replace_unfixed_scheduler_DB right_quotient_word (@) epdaS_set_unfixed_scheduler_DB epdaS_get_unfixed_scheduler_DB G1 (epdaHS2epdaS_derivation dh) sUF x) dc x xc\")\n   apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf xc ee ef cg ch)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf xc ee ef cg ch)(*strict*)\n  apply(thin_tac \"epdaHS2epdaS_derivation dc' = derivation_append (ATS_SchedUF_DB.replace_unfixed_scheduler_DB right_quotient_word (@) epdaS_set_unfixed_scheduler_DB epdaS_get_unfixed_scheduler_DB G1 (epdaHS2epdaS_derivation dh) sUF x) dc x\")\n  apply(rename_tac G1 dh x sUF dc dc' xa xb e ea eb ec ed c ca cb cc \"cd\" ce cf xc ee ef cg ch)(*strict*)\n  apply(simp add: epdaHS2epdaS_derivation_def)\n  apply(simp add: derivation_append_def epdaS.replace_unfixed_scheduler_DB_def epdaS.map_unfixed_scheduler_DB_def)\n  done\n\nlemma epdaS_vs_epdaHS_inst_AX_bisimulation_compatible_with_replace_and_schedF2: \"\n   \\<forall>G1. valid_epda G1 \\<longrightarrow>\n         (\\<forall>dh. ATS.derivation_initial epdaHS_initial_configurations\n                epdaHS_step_relation G1 dh \\<and>\n               Ex (maximum_of_domain dh) \\<longrightarrow>\n               (\\<forall>n. maximum_of_domain dh n \\<longrightarrow>\n                    (\\<forall>sUF'.\n                        sUF' \\<in> epda_effects G1 \\<longrightarrow>\n                        (\\<forall>dc. (\\<exists>dc'. ATS.derivation_initial\n                                      epdaHS_initial_configurations\n                                      epdaHS_step_relation G1\n                                      (derivation_append\n (ATS_SchedUF_DB.replace_unfixed_scheduler_DB right_quotient_word (@)\n   epdaHS_set_unfixed_scheduler_DB epdaHS_get_unfixed_scheduler_DB G1 dh sUF'\n   n)\n dc' n) \\<and>\n                                     Ex (maximum_of_domain\n   (derivation_append\n     (ATS_SchedUF_DB.replace_unfixed_scheduler_DB right_quotient_word (@)\n       epdaHS_set_unfixed_scheduler_DB epdaHS_get_unfixed_scheduler_DB G1 dh\n       sUF' n)\n     dc' n)) \\<and>\n                                     epdaHS2epdaS_derivation\n                                      (derivation_append\n (ATS_SchedUF_DB.replace_unfixed_scheduler_DB right_quotient_word (@)\n   epdaHS_set_unfixed_scheduler_DB epdaHS_get_unfixed_scheduler_DB G1 dh sUF'\n   n)\n dc' n) =\n                                     dc) \\<longrightarrow>\n                              (\\<forall>x\\<le>n. epdaS_get_fixed_scheduler_DB G1\n(epdaHS2epdaS_derivation dh) x =\n                                      epdaS_get_fixed_scheduler_DB G1 dc x \\<and>\n                                      ATS_SchedUF_DB.replace_unfixed_scheduler_DB\nright_quotient_word (@) epdaS_set_unfixed_scheduler_DB epdaS_get_unfixed_scheduler_DB G1\n(epdaHS2epdaS_derivation dh) (epdaS_get_unfixed_scheduler_DB G1 dc n) n x =\n                                      dc x)))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 dh n x sUF' dc' xa xb)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 dh n x sUF' dc' xa xb)(*strict*)\n   apply(simp add: epdaS_get_fixed_scheduler_DB_def)\n  apply(rename_tac G1 dh n x sUF' dc' xa xb)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. dh xa = Some (pair e c)\")\n   apply(rename_tac G1 dh n x sUF' dc' xa xb)(*strict*)\n   prefer 2\n   apply(rule epdaHS.some_position_has_details_before_max_dom)\n     apply(rename_tac G1 dh n x sUF' dc' xa xb)(*strict*)\n     apply(simp add: epdaHS.derivation_initial_def)\n     apply(force)\n    apply(rename_tac G1 dh n x sUF' dc' xa xb)(*strict*)\n    apply(force)\n   apply(rename_tac G1 dh n x sUF' dc' xa xb)(*strict*)\n   apply(subgoal_tac \"n = x\")\n    apply(rename_tac G1 dh n x sUF' dc' xa xb)(*strict*)\n    apply(force)\n   apply(rename_tac G1 dh n x sUF' dc' xa xb)(*strict*)\n   apply (metis epdaHS.derivation_initial_is_derivation epdaHS.maximum_of_domainUnique)\n  apply(rename_tac G1 dh n x sUF' dc' xa xb)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. dh n = Some (pair e c)\")\n   apply(rename_tac G1 dh n x sUF' dc' xa xb)(*strict*)\n   prefer 2\n   apply(rule epdaHS.some_position_has_details_before_max_dom)\n     apply(rename_tac G1 dh n x sUF' dc' xa xb)(*strict*)\n     apply(simp add: epdaHS.derivation_initial_def)\n     apply(force)\n    apply(rename_tac G1 dh n x sUF' dc' xa xb)(*strict*)\n    apply(force)\n   apply(rename_tac G1 dh n x sUF' dc' xa xb)(*strict*)\n   apply(subgoal_tac \"n = x\")\n    apply(rename_tac G1 dh n x sUF' dc' xa xb)(*strict*)\n    apply(force)\n   apply(rename_tac G1 dh n x sUF' dc' xa xb)(*strict*)\n   apply (metis epdaHS.derivation_initial_is_derivation epdaHS.maximum_of_domainUnique)\n  apply(rename_tac G1 dh n x sUF' dc' xa xb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 dh n x sUF' dc' xa xb e ea c ca)(*strict*)\n  apply(simp add: epdaS.replace_unfixed_scheduler_DB_def)\n  apply(simp add: epdaS.map_unfixed_scheduler_DB_def)\n  apply(simp add: epdaHS2epdaS_derivation_def)\n  apply(simp add: epdaS_get_scheduler_def epdaS_get_unfixed_scheduler_DB_def epdaS_set_unfixed_scheduler_DB_def get_configuration_def derivation_append_def)\n  apply(simp add: epdaHS.replace_unfixed_scheduler_DB_def)\n  apply(simp add: epdaHS.map_unfixed_scheduler_DB_def epdaHS_set_unfixed_scheduler_DB_def get_configuration_def epdaHS_get_unfixed_scheduler_DB_def epdaHS_get_scheduler_def)\n  apply (metis right_quotient_word_full option.sel)\n  done\n\nlemma epdaS_vs_epdaHS_inst_ATS_Bisimulation_Derivation_Strong2_axioms: \"\n  ATS_Bisimulation_Derivation_Strong2_axioms valid_epda epdaS_initial_configurations\n     epda_step_labels epdaS_step_relation epdaS_marking_condition epdaS_marked_effect\n     epdaS_unmarked_effect epda_effects right_quotient_word (@)\n     epda_unfixed_scheduler_extendable epdaS_set_unfixed_scheduler_DB\n     epdaS_get_unfixed_scheduler_DB epdaS_get_fixed_scheduler_DB valid_epda\n     epdaHS_initial_configurations epda_step_labels epdaHS_step_relation\n     epdaHS_marking_condition epdaHS_marked_effect epdaHS_unmarked_effect epda_effects\n     right_quotient_word (@) epda_unfixed_scheduler_extendable\n     epdaHS_set_unfixed_scheduler_DB epdaHS_get_unfixed_scheduler_DB\n     epdaHS_get_fixed_scheduler_DB epdaS_vs_epdaHS_TSstructure_rel epdaS_vs_epdaHS_effect_rel\n     epdaS_vs_epdaHS_label_relation epdaS_vs_epdaHS_derivation_bisimulation \"\n  apply(unfold ATS_Bisimulation_Derivation_Strong2_def ATS_Bisimulation_Derivation_Strong1_axioms_def ATS_Bisimulation_Derivation_Strong2_axioms_def )\n  apply(simp add: epdaS_vs_epdaHS_inst_AX_AX_initial_contained1 epdaS_vs_epdaHS_inst_AX_AX_initial_contained2 epdaS_vs_epdaHS_inst_AX_on_derivation_initial1 epdaS_vs_epdaHS_inst_AX_on_finite1 epdaS_vs_epdaHS_inst_AX_equal_length epdaS_vs_epdaHS_inst_AX_simulate12 epdaS_vs_epdaHS_inst_AX_simulate21 )\n  apply(simp add: epdaS_vs_epdaHS_inst_AX_bisimulation_compatible_with_crop1 epdaS_vs_epdaHS_inst_AX_bisimulation_compatible_with_crop2 )\n  apply(simp add: epdaS_vs_epdaHS_inst_AX_bisimulation_compatible_with_replace_and_schedF1 epdaS_vs_epdaHS_inst_AX_bisimulation_compatible_with_replace_and_schedF2 )\n  apply(simp add: epdaS_vs_epdaHS_inst_AX_accept_id1 epdaS_vs_epdaHS_inst_AX_accept_id2 epdaS_vs_epdaHS_inst_AX_unAX_marked_effect_id1 epdaS_vs_epdaHS_inst_AX_unAX_marked_effect_id2 epdaS_vs_epdaHS_inst_AX_marked_effect_id1 epdaS_vs_epdaHS_inst_AX_marked_effect_id2 )\n  apply(simp add: epdaS_vs_epdaHS_inst_AX_step_labels_exists2 epda_step_labels_def )\n  done\n\ninterpretation \"epdaS_vs_epdaHS\" : ATS_Bisimulation_Derivation_Strong2\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaS_configurations\"\n  (* initial_configurations1 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaS_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaS_unmarked_effect\"\n  (* fixed_schedulers1 *)\n  epda_fixed_schedulers\n  (* empty_fixed_scheduler1 *)\n  epda_empty_fixed_scheduler\n  (* fixed_scheduler_extendable1 *)\n  epda_fixed_scheduler_extendable\n  (* scheduler_fragments1 *)\n  \"epda_effects\"\n  (* empty_scheduler_fragment1 *)\n  epda_empty_scheduler_fragment\n  (* join_scheduler_fragments1 *)\n  \"append\"\n  (* unfixed_schedulers1 *)\n  \"epda_effects\"\n  (* empty_unfixed_scheduler1 *)\n  epda_empty_unfixed_scheduler\n  (* unfixed_scheduler_right_quotient1 *)\n  \"right_quotient_word\"\n  (* extend_unfixed_scheduler1 *)\n  \"append\"\n  (* unfixed_scheduler_extendable1 *)\n  epda_unfixed_scheduler_extendable\n  (* schedulers1 *)\n  \"epda_effects\"\n  (* initial_schedulers1 *)\n  \"epda_effects\"\n  (* empty_scheduler1 *)\n  epda_empty_scheduler\n  (* get_scheduler1 *)\n  \"epdaS_get_scheduler\"\n  (* join_fixed_scheduler_unfixed_scheduler1 *)\n  \"append\"\n  (* join_scheduler_fragments1_sched *)\n  \"append\"\n  (* set_unfixed_scheduler_DB1 *)\n  \"epdaS_set_unfixed_scheduler_DB\"\n  (* get_unfixed_scheduler_DB1 *)\n  \"epdaS_get_unfixed_scheduler_DB\"\n  (* get_fixed_scheduler_DB1 *)\n  \"epdaS_get_fixed_scheduler_DB\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaHS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaHS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaHS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaHS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaHS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaHS_unmarked_effect\"\n  (* fixed_schedulers2 *)\n  epda_fixed_schedulers\n  (* empty_fixed_scheduler2 *)\n  epda_empty_fixed_scheduler\n  (* fixed_scheduler_extendable2 *)\n  epda_fixed_scheduler_extendable\n  (* scheduler_fragments2 *)\n  \"epda_effects\"\n  (* empty_scheduler_fragment2 *)\n  epda_empty_scheduler_fragment\n  (* join_scheduler_fragments2 *)\n  \"append\"\n  (* unfixed_schedulers2 *)\n  \"epda_effects\"\n  (* empty_unfixed_scheduler2 *)\n  epda_empty_unfixed_scheduler\n  (* unfixed_scheduler_right_quotient2 *)\n  \"right_quotient_word\"\n  (* extend_unfixed_scheduler2 *)\n  \"append\"\n  (* unfixed_scheduler_extendable2 *)\n  epda_unfixed_scheduler_extendable\n  (* schedulers2 *)\n  \"epda_effects\"\n  (* initial_schedulers2 *)\n  \"epda_effects\"\n  (* empty_scheduler2 *)\n  epda_empty_scheduler\n  (* get_scheduler2 *)\n  \"epdaHS_get_scheduler\"\n  (* join_fixed_scheduler_unfixed_scheduler2 *)\n  \"append\"\n  (* extend_scheduler2 *)\n  \"append\"\n  (* set_unfixed_scheduler_DB2 *)\n  \"epdaHS_set_unfixed_scheduler_DB\"\n  (* get_unfixed_scheduler_DB2 *)\n  \"epdaHS_get_unfixed_scheduler_DB\"\n  (* get_fixed_scheduler_DB2 *)\n  \"epdaHS_get_fixed_scheduler_DB\"\n  (* TSstructure_rel *)\n  epdaS_vs_epdaHS_TSstructure_rel\n  (* effect_rel *)\n  epdaS_vs_epdaHS_effect_rel\n  (* label_relation *)\n  epdaS_vs_epdaHS_label_relation\n  (* derivation_bisimulation *)\n  epdaS_vs_epdaHS_derivation_bisimulation\n  apply(simp add: LOCALE_DEFS epdaS_interpretations epdaHS_interpretations0 LOCALE_DEFS)\n  apply(simp add: epdaS_vs_epdaHS_inst_ATS_Bisimulation_Derivation_Strong2_axioms)\n  done\n\ntheorem epdaS_vs_epdaHS_Nonblockingness_and_lang_transfer: \"\n  valid_epda G\n  \\<Longrightarrow> (epdaHS.Nonblockingness_linear_DB G \\<longleftrightarrow> epdaS.Nonblockingness_linear_DB G)\n  \\<and> epdaHS.unmarked_language G = epdaS.unmarked_language G\n  \\<and> epdaHS.marked_language G = epdaS.marked_language G\"\n  apply(rule conjI)\n   apply(rule antisym)\n    apply(clarsimp)\n    apply(rule epdaS_vs_epdaHS.Nonblockingness_translation2)\n     apply(force)\n    apply(force)\n   apply(clarsimp)\n   apply(rule epdaS_vs_epdaHS.Nonblockingness_translation1)\n    apply(force)\n   apply(force)\n  apply(rule conjI)\n   apply(rule order_antisym)\n    apply(rule_tac\n      t = \"epdaHS.unmarked_language G\"\n      and s = \"epdaHS.finite_unmarked_language G\"\n      in ssubst)\n     apply (metis epdaHS.AX_unmarked_language_finite)\n    apply(clarsimp)\n    apply(rename_tac x)(*strict*)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac x)(*strict*)\n     prefer 2\n     apply(rule epdaS_vs_epdaHS.ATS_Bisimulation_Derivation_Strong1_unmarked_language_translation2)\n      apply(rename_tac x)(*strict*)\n      apply(force)\n     apply(rename_tac x)(*strict*)\n     apply(force)\n    apply(rename_tac x)(*strict*)\n    apply(force)\n   apply(rule_tac\n      t = \"epdaS.unmarked_language G\"\n      and s = \"epdaS.finite_unmarked_language G\"\n      in ssubst)\n    apply (metis epdaS.AX_unmarked_language_finite)\n   apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac x)(*strict*)\n    prefer 2\n    apply(rule epdaS_vs_epdaHS.ATS_Bisimulation_Derivation_Strong1_unmarked_language_translation1)\n     apply(rename_tac x)(*strict*)\n     apply(force)\n    apply(rename_tac x)(*strict*)\n    apply(force)\n   apply(rename_tac x)(*strict*)\n   apply(force)\n  apply(rule order_antisym)\n   apply(rule_tac\n      t = \"epdaHS.marked_language G\"\n      and s = \"epdaHS.finite_marked_language G\"\n      in ssubst)\n    apply (metis epdaHS.AX_marked_language_finite)\n   apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac x)(*strict*)\n    prefer 2\n    apply(rule epdaS_vs_epdaHS.ATS_Bisimulation_Derivation_Strong1_marked_language_translation2)\n     apply(rename_tac x)(*strict*)\n     apply(force)\n    apply(rename_tac x)(*strict*)\n    apply(force)\n   apply(rename_tac x)(*strict*)\n   apply(force)\n  apply(rule_tac\n      t = \"epdaS.marked_language G\"\n      and s = \"epdaS.finite_marked_language G\"\n      in ssubst)\n   apply (metis epdaS.AX_marked_language_finite)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(rule epdaS_vs_epdaHS.ATS_Bisimulation_Derivation_Strong1_marked_language_translation1)\n    apply(rename_tac x)(*strict*)\n    apply(force)\n   apply(rename_tac x)(*strict*)\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(force)\n  done\n\ntheorem epdaS_vs_epdaHS_is_forward_deterministic_accessible_preserved: \"\n  valid_epda G\n  \\<Longrightarrow> epdaS.is_forward_deterministic_accessible G\n  \\<Longrightarrow> epdaHS.is_forward_deterministic_accessible G\"\n  apply(simp add: epdaS.is_forward_deterministic_accessible_def epdaHS.is_forward_deterministic_accessible_def)\n  apply(rule conjI)\n   apply(rule epdaHS_is_forward_target_deterministic_accessible)\n   apply(force)\n  apply(clarsimp)\n  apply(rule epdaS_vs_epdaHS.preserve_FEdetermR1)\n   apply(force)\n  apply(force)\n  done\n\nend\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_07/I_epda_S_HS.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.476579651063676, "lm_q1q2_score": 0.26424934071595463}}
{"text": "(* \n   Title: The pi-calculus   \n   Author/Maintainer: Jesper Bengtson (jebe.dk), 2012\n*)\ntheory Weak_Late_Step_Semantics\n  imports Late_Tau_Chain\nbegin\n\ndefinition inputTransition :: \"pi \\<Rightarrow> name \\<Rightarrow> pi \\<Rightarrow> name \\<Rightarrow> name \\<Rightarrow> pi \\<Rightarrow> bool\" (\"_ \\<Longrightarrow>\\<^sub>l_ in _\\<rightarrow>_<_> \\<prec> _\" [80, 80, 80, 80, 80] 80)\nwhere \"P \\<Longrightarrow>\\<^sub>lu in P'' \\<rightarrow>a<x> \\<prec> P' \\<equiv> \\<exists>P'''. P \\<Longrightarrow>\\<^sub>\\<tau> P''' \\<and> P''' \\<longmapsto>a<x> \\<prec> P'' \\<and> P''[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n\ndefinition transition :: \"(pi \\<times> Late_Semantics.residual) set\" where\n  \"transition \\<equiv> {x. \\<exists>P P' \\<alpha> P'' P'''. P \\<Longrightarrow>\\<^sub>\\<tau> P' \\<and> P' \\<longmapsto>\\<alpha> \\<prec> P'' \\<and> P'' \\<Longrightarrow>\\<^sub>\\<tau> P''' \\<and> x = (P, \\<alpha> \\<prec> P''')}  \\<union>\n                {x. \\<exists>P P' a y P'' P'''. P \\<Longrightarrow>\\<^sub>\\<tau> P' \\<and> (P' \\<longmapsto>(a<\\<nu>y> \\<prec> P'')) \\<and> P'' \\<Longrightarrow>\\<^sub>\\<tau> P''' \\<and> x = (P, (a<\\<nu>y> \\<prec> P'''))}\"\n\nabbreviation weakTransition_judge :: \"pi \\<Rightarrow> Late_Semantics.residual \\<Rightarrow> bool\" (\"_ \\<Longrightarrow>\\<^sub>l _\" [80, 80] 80)\n  where \"P \\<Longrightarrow>\\<^sub>l Rs \\<equiv> (P, Rs) \\<in> transition\"\n\nlemma weakNonInput[dest]:\n  fixes P  :: pi\n  and   a  :: name\n  and   x  :: name\n  and   P' :: pi\n\n  assumes \"P \\<Longrightarrow>\\<^sub>la<x> \\<prec> P'\"\n \n  shows False\nusing assms\nby(auto simp add: transition_def residual.inject)\n\nlemma transitionI:\n  fixes P    :: pi\n  and   P''' :: pi\n  and   \\<alpha>    :: freeRes\n  and   P''  :: pi\n  and   P'   :: pi\n  and   a    :: name\n  and   x    :: name\n  and   u    :: name\n\n  shows \"\\<lbrakk>P \\<Longrightarrow>\\<^sub>\\<tau> P'''; P''' \\<longmapsto>\\<alpha> \\<prec> P''; P'' \\<Longrightarrow>\\<^sub>\\<tau> P'\\<rbrakk> \\<Longrightarrow> P \\<Longrightarrow>\\<^sub>l\\<alpha> \\<prec> P'\"\n  and   \"\\<lbrakk>P \\<Longrightarrow>\\<^sub>\\<tau> P'''; P''' \\<longmapsto>a<\\<nu>x> \\<prec> P''; P'' \\<Longrightarrow>\\<^sub>\\<tau> P'\\<rbrakk> \\<Longrightarrow> P \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> P'\"\n  and   \"\\<lbrakk>P \\<Longrightarrow>\\<^sub>\\<tau> P'''; P''' \\<longmapsto>a<x> \\<prec> P''; P''[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> P'\\<rbrakk> \\<Longrightarrow> P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>a<x> \\<prec> P'\"\nproof -\n  assume \"P \\<Longrightarrow>\\<^sub>\\<tau> P'''\" and \"P''' \\<longmapsto> \\<alpha> \\<prec> P''\" and \"P'' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n  thus \"P \\<Longrightarrow>\\<^sub>l \\<alpha> \\<prec> P'\"\n    by(force simp add: transition_def)\nnext\n  assume \"P \\<Longrightarrow>\\<^sub>\\<tau> P'''\" and \"P''' \\<longmapsto>a<\\<nu>x> \\<prec> P''\" and \"P'' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n  thus \"P \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> P'\"\n    by(force simp add: transition_def)\nnext\n  assume \"P \\<Longrightarrow>\\<^sub>\\<tau> P'''\" and \"P''' \\<longmapsto>a<x> \\<prec> P''\" and \"P''[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n  thus \"P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>a<x> \\<prec> P'\" \n    by(force simp add: inputTransition_def)\nqed\n\nlemma transitionE:\n  fixes P  :: pi\n  and   \\<alpha>  :: freeRes\n  and   P'  :: pi\n  and   P'' :: pi\n  and   a   :: name\n  and   u   :: name\n  and   x   :: name\n\n  shows \"P \\<Longrightarrow>\\<^sub>l\\<alpha> \\<prec> P' \\<Longrightarrow> \\<exists>P'' P'''. P \\<Longrightarrow>\\<^sub>\\<tau> P'' \\<and> P'' \\<longmapsto>\\<alpha> \\<prec> P''' \\<and> P''' \\<Longrightarrow>\\<^sub>\\<tau> P'\" (is \"_ \\<Longrightarrow> ?thesis1\")\n  and   \"\\<lbrakk>P \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> P'; x \\<sharp> P\\<rbrakk> \\<Longrightarrow> \\<exists>P'' P'''. P \\<Longrightarrow>\\<^sub>\\<tau> P''' \\<and> P''' \\<longmapsto>a<\\<nu>x> \\<prec> P'' \\<and> P'' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n  and   \"\\<lbrakk>P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>a<x> \\<prec> P'\\<rbrakk> \\<Longrightarrow> \\<exists>P'''. P \\<Longrightarrow>\\<^sub>\\<tau> P''' \\<and> P''' \\<longmapsto>a<x> \\<prec> P'' \\<and> P''[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> P'\"\nproof -\n  assume \"P \\<Longrightarrow>\\<^sub>l\\<alpha> \\<prec> P'\"\n  thus ?thesis1 by(auto simp add: transition_def residual.inject)\nnext\n  assume \"P \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> P'\" and \"x \\<sharp> P\"\n  thus \"\\<exists>P'' P'''. P \\<Longrightarrow>\\<^sub>\\<tau> P''' \\<and> P''' \\<longmapsto>a<\\<nu>x> \\<prec> P'' \\<and> P'' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n  using [[hypsubst_thin = true]]\n    apply(auto simp add: transition_def residualInject name_abs_eq)\n    apply(rule_tac x=\"[(x, y)] \\<bullet> P''\" in exI)\n    apply(rule_tac x=P' in exI)\n    apply(clarsimp)\n    apply(auto)\n    apply(subgoal_tac \"x \\<sharp> P''\")\n    apply(simp add: alphaBoundResidual name_swap)\n    using freshChain\n    apply(force dest: freshBoundDerivative)\n    using eqvtChainI\n    by simp\nnext\n  assume PTrans: \"P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>a<x> \\<prec> P'\"\n  thus \"\\<exists>P'''. P \\<Longrightarrow>\\<^sub>\\<tau> P''' \\<and> P''' \\<longmapsto> a<x> \\<prec> P'' \\<and> P''[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n    by(auto simp add: inputTransition_def)\nqed\n\nlemma alphaInput:\n  fixes P   :: pi\n  and   u   :: name\n  and   P'' :: pi\n  and   a   :: name\n  and   x   :: name\n  and   P'  :: pi\n  and   y   :: name\n\n  assumes PTrans:  \"P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>a<x> \\<prec> P'\"\n  and     yFreshP: \"y \\<sharp> P\"\n\n  shows \"P \\<Longrightarrow>\\<^sub>lu in ([(x, y)] \\<bullet> P'')\\<rightarrow>a<y> \\<prec> P'\"\nproof(cases \"x=y\")\n  assume \"x=y\"\n  with PTrans show ?thesis by simp\nnext\n  assume xineqy: \"x\\<noteq>y\"\n  from PTrans obtain P''' where PChain: \"P \\<Longrightarrow>\\<^sub>\\<tau> P'''\"\n                            and P'''Trans: \"P''' \\<longmapsto>a<x> \\<prec> P''\"\n                            and P''Chain: \"P''[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n    by(blast dest: transitionE)\n\n  from PChain yFreshP have \"y \\<sharp> P'''\" by(rule freshChain)\n  with P'''Trans xineqy have yFreshP'': \"y \\<sharp> P''\" by(blast dest: freshBoundDerivative)\n\n  with P'''Trans have \"P''' \\<longmapsto>a<y> \\<prec> [(x, y)] \\<bullet> P''\" by(simp add: alphaBoundResidual)\n  moreover from P''Chain yFreshP'' have \"([(x, y)] \\<bullet> P'')[y::=u] \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n    by(simp add: renaming name_swap)\n  ultimately show ?thesis using PChain by(blast intro: transitionI)\nqed\n\nlemma tauActionChain:\n  fixes P  :: pi\n  and   P' :: pi\n  \n  shows \"P \\<Longrightarrow>\\<^sub>l\\<tau> \\<prec> P' \\<Longrightarrow> P \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n  and   \"P \\<noteq> P' \\<Longrightarrow> P \\<Longrightarrow>\\<^sub>\\<tau> P' \\<Longrightarrow> P \\<Longrightarrow>\\<^sub>l\\<tau> \\<prec> P'\"\nproof -\n  assume \"P \\<Longrightarrow>\\<^sub>l\\<tau> \\<prec> P'\"\n  then obtain P'' P''' where \"P \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n                         and \"P'' \\<longmapsto>\\<tau> \\<prec> P'''\"\n                         and \"P''' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n    by(blast dest: transitionE)\n  thus \"P \\<Longrightarrow>\\<^sub>\\<tau> P'\" by auto\nnext\n  assume \"P \\<Longrightarrow>\\<^sub>\\<tau> P'\" and \"P \\<noteq> P'\" \n  thus \"P \\<Longrightarrow>\\<^sub>l\\<tau> \\<prec> P'\"\n  proof(induct rule: tauChainInduct)\n    case id\n    thus ?case by simp\n  next\n    case(ih P'' P''')\n    have \"P \\<Longrightarrow>\\<^sub>\\<tau> P''\" and \"P'' \\<longmapsto> \\<tau> \\<prec> P'''\" by fact+\n    moreover have \"P''' \\<Longrightarrow>\\<^sub>\\<tau> P'''\" by simp\n    ultimately show ?case by(rule transitionI)\n  qed\nqed\n\nlemma singleActionChain:\n  fixes P  :: pi\n  and   a  :: name\n  and   x  :: name\n  and   \\<alpha>  :: freeRes\n  and   u  :: name\n \n  shows \"P \\<longmapsto>a<\\<nu>x> \\<prec> P' \\<Longrightarrow> P \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> P'\"\n  and   \"\\<lbrakk>P \\<longmapsto>a<x> \\<prec> P'\\<rbrakk> \\<Longrightarrow> P \\<Longrightarrow>\\<^sub>lu in P'\\<rightarrow>a<x> \\<prec> P'[x::=u]\"\n  and   \"P \\<longmapsto>\\<alpha> \\<prec> P' \\<Longrightarrow> P \\<Longrightarrow>\\<^sub>l\\<alpha> \\<prec> P'\"\nproof -  \n  assume \"P \\<longmapsto>a<\\<nu>x> \\<prec> P'\"\n  moreover have \"P \\<Longrightarrow>\\<^sub>\\<tau> P\" by simp\n  moreover have \"P' \\<Longrightarrow>\\<^sub>\\<tau> P'\" by simp\n  ultimately show \"P \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> P'\" by(blast intro: transitionI)\nnext\n  assume \"P \\<longmapsto>a<x> \\<prec> P'\"\n  moreover have \"P \\<Longrightarrow>\\<^sub>\\<tau> P\" by simp\n  moreover have \"P'[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> P'[x::=u]\" by simp\n  ultimately show \"P \\<Longrightarrow>\\<^sub>lu in P'\\<rightarrow>a<x> \\<prec> P'[x::=u]\" by(blast intro: transitionI)\nnext\n  assume \"P \\<longmapsto>\\<alpha> \\<prec> P'\"\n  moreover have \"P \\<Longrightarrow>\\<^sub>\\<tau> P\" by simp\n  moreover have \"P' \\<Longrightarrow>\\<^sub>\\<tau> P'\" by simp\n  ultimately show \"P \\<Longrightarrow>\\<^sub>l\\<alpha> \\<prec> P'\"  by(blast intro: transitionI)\nqed\n\nlemma Tau:\n  fixes P :: pi\n\n  shows \"\\<tau>.(P) \\<Longrightarrow>\\<^sub>l \\<tau> \\<prec>  P\"\nproof -\n  have \"\\<tau>.(P) \\<Longrightarrow>\\<^sub>\\<tau> \\<tau>.(P)\" by simp\n  moreover have \"\\<tau>.(P) \\<longmapsto>\\<tau> \\<prec> P\" by(rule transitions.Tau)\n  moreover have \"P \\<Longrightarrow>\\<^sub>\\<tau> P\" by simp\n  ultimately show ?thesis by(rule transitionI)\nqed\n\nlemma Input:\n  fixes a :: name\n  and   x :: name\n  and   u :: name\n  and   P :: pi\n\n  shows \"a<x>.P \\<Longrightarrow>\\<^sub>lu in P\\<rightarrow>a<x> \\<prec> P[x::=u]\"\nproof -\n  have \"a<x>.P \\<Longrightarrow>\\<^sub>\\<tau> a<x>.P\" by simp\n  moreover have \"a<x>.P \\<longmapsto> a<x> \\<prec> P\" by(rule Input)\n  moreover have \"P[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> P[x::=u]\" by simp\n  ultimately show ?thesis by(rule transitionI)\nqed\n\nlemma Output:\n  fixes a :: name\n  and   b :: name\n  and   P :: pi\n\n  shows \"a{b}.P \\<Longrightarrow>\\<^sub>la[b] \\<prec> P\"\nproof -\n  have \"a{b}.P \\<Longrightarrow>\\<^sub>\\<tau> a{b}.P\" by simp\n  moreover have \"a{b}.P \\<longmapsto>a[b] \\<prec> P\" by(rule transitions.Output)\n  moreover have \"P \\<Longrightarrow>\\<^sub>\\<tau> P\" by simp\n  ultimately show ?thesis by(rule transitionI)\nqed\n\nlemma Match:\n  fixes P  :: pi\n  and   Rs :: residual\n  and   a  :: name\n  and   u  :: name\n  and   b  :: name\n  and   x  :: name\n  and   P' :: pi\n\n  shows \"P \\<Longrightarrow>\\<^sub>l Rs \\<Longrightarrow> [a\\<frown>a]P \\<Longrightarrow>\\<^sub>l Rs\"\n  and   \"P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>b<x> \\<prec> P' \\<Longrightarrow> [a\\<frown>a]P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>b<x> \\<prec> P'\"\nproof -\n  assume PTrans: \"P \\<Longrightarrow>\\<^sub>l Rs\"\n  thus \"[a\\<frown>a]P \\<Longrightarrow>\\<^sub>l Rs\"\n  proof(nominal_induct avoiding: P rule: residual.strong_inducts)\n    case(BoundR b x P')\n    have PTrans: \"P \\<Longrightarrow>\\<^sub>l b\\<guillemotleft>x\\<guillemotright> \\<prec> P'\" and xFreshP: \"x \\<sharp> P\" by fact+\n    from PTrans obtain b' where beq: \"b = BoundOutputS b'\" by(cases b) auto\n    with PTrans xFreshP obtain P'' P''' where PTrans: \"P \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n                                          and P''Trans: \"P'' \\<longmapsto>b'<\\<nu>x> \\<prec> P'''\"\n                                          and P'''Trans: \"P''' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n      by(blast dest: transitionE)\n    show ?case\n    proof(cases \"P = P''\")\n      assume \"P = P''\"\n      moreover have \"[a\\<frown>a]P \\<Longrightarrow>\\<^sub>\\<tau> [a\\<frown>a]P\" by simp\n      moreover from P''Trans have \"[a\\<frown>a]P'' \\<longmapsto> b'<\\<nu>x> \\<prec> P'''\" by(rule Match)\n      ultimately show ?thesis using beq P'''Trans by(blast intro: transitionI)\n    next\n      assume \"P \\<noteq> P''\"\n      with PTrans have \"[a\\<frown>a]P \\<Longrightarrow>\\<^sub>\\<tau> P''\" by(rule matchChain)\n      thus ?thesis using beq P''Trans P'''Trans by(blast intro: transitionI)\n    qed\n  next\n    case(FreeR \\<alpha> P')\n    have \"P \\<Longrightarrow>\\<^sub>l \\<alpha> \\<prec> P'\" by fact\n\n    then obtain P'' P''' where PTrans: \"P \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n                           and P''Trans: \"P'' \\<longmapsto> \\<alpha> \\<prec> P'''\"\n                           and P'''Trans: \"P''' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n      by(blast dest: transitionE)\n    show ?case\n    proof(cases \"P = P''\")\n      assume \"P = P''\"\n      moreover have \"[a\\<frown>a]P \\<Longrightarrow>\\<^sub>\\<tau> [a\\<frown>a]P\" by simp\n      moreover from P''Trans have \"[a\\<frown>a]P'' \\<longmapsto> \\<alpha> \\<prec> P'''\" by(rule transitions.Match)\n      ultimately show ?thesis using P'''Trans by(blast intro: transitionI)\n    next\n      assume \"P \\<noteq> P''\"\n      with PTrans have \"[a\\<frown>a]P \\<Longrightarrow>\\<^sub>\\<tau> P''\" by(rule matchChain)\n      thus ?thesis using P''Trans P'''Trans by(rule transitionI)\n    qed\n  qed\nnext\n  assume \"P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>b<x> \\<prec> P'\"\n  then obtain P''' where PChain: \"P \\<Longrightarrow>\\<^sub>\\<tau> P'''\"\n                     and P'''Trans: \"P''' \\<longmapsto>b<x> \\<prec> P''\"\n                     and P''Chain: \"P''[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n    by(blast dest: transitionE)\n  show \"[a\\<frown>a]P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>b<x> \\<prec> P'\"\n  proof(cases \"P=P'''\")\n    assume \"P=P'''\"\n    moreover have \"[a\\<frown>a]P \\<Longrightarrow>\\<^sub>\\<tau> [a\\<frown>a]P\" by simp\n    moreover from P'''Trans have \"[a\\<frown>a]P''' \\<longmapsto>b<x> \\<prec> P''\" by(rule Late_Semantics.Match)\n    ultimately show ?thesis using P''Chain by(blast intro: transitionI)\n  next\n    assume \"P \\<noteq> P'''\"\n    with PChain have \"[a\\<frown>a]P \\<Longrightarrow>\\<^sub>\\<tau> P'''\" by(rule matchChain)\n    thus ?thesis using P'''Trans P''Chain by(rule transitionI)\n  qed\nqed\n\nlemma Mismatch:\n  fixes P  :: pi\n  and   Rs :: residual\n  and   a  :: name\n  and   c  :: name\n  and   u  :: name\n  and   b  :: name\n  and   x  :: name\n  and   P' :: pi\n\n  shows \"\\<lbrakk>P \\<Longrightarrow>\\<^sub>l Rs; a \\<noteq> c\\<rbrakk> \\<Longrightarrow> [a\\<noteq>c]P \\<Longrightarrow>\\<^sub>l Rs\"\n  and   \"\\<lbrakk>P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>b<x> \\<prec> P'; a \\<noteq> c\\<rbrakk> \\<Longrightarrow> [a\\<noteq>c]P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>b<x> \\<prec> P'\"\nproof -\n  assume PTrans: \"P \\<Longrightarrow>\\<^sub>l Rs\"\n     and aineqc: \"a \\<noteq> c\"\n  thus \"[a\\<noteq>c]P \\<Longrightarrow>\\<^sub>l Rs\"\n  proof(nominal_induct avoiding: P rule: residual.strong_inducts)\n    case(BoundR b x P')\n    have PTrans: \"P \\<Longrightarrow>\\<^sub>l b\\<guillemotleft>x\\<guillemotright> \\<prec> P'\" and xFreshP: \"x \\<sharp> P\" by fact+\n    from PTrans obtain b' where beq: \"b = BoundOutputS b'\" by(cases b, auto)\n    with PTrans xFreshP obtain P'' P''' where PTrans: \"P \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n                                          and P''Trans: \"P'' \\<longmapsto>b'<\\<nu>x> \\<prec> P'''\"\n                                          and P'''Trans: \"P''' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n      by(blast dest: transitionE)\n    show ?case\n    proof(cases \"P = P''\")\n      assume \"P = P''\"\n      moreover have \"[a\\<noteq>c]P \\<Longrightarrow>\\<^sub>\\<tau> [a\\<noteq>c]P\" by simp\n      moreover from P''Trans aineqc have \"[a\\<noteq>c]P'' \\<longmapsto>b'<\\<nu>x> \\<prec> P'''\" by(rule transitions.Mismatch)\n      ultimately show ?thesis using beq P'''Trans by(blast intro: transitionI)\n    next\n      assume \"P \\<noteq> P''\"\n      with PTrans aineqc have \"[a\\<noteq>c]P \\<Longrightarrow>\\<^sub>\\<tau> P''\" by(rule mismatchChain)\n      thus ?thesis using beq P''Trans P'''Trans by(blast intro: transitionI)\n    qed\n  next\n    case(FreeR \\<alpha> P')\n    have \"P \\<Longrightarrow>\\<^sub>l \\<alpha> \\<prec> P'\" by fact\n\n    then obtain P'' P''' where PTrans: \"P \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n                           and P''Trans: \"P'' \\<longmapsto> \\<alpha> \\<prec> P'''\"\n                           and P'''Trans: \"P''' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n      by(blast dest: transitionE)\n    show ?case\n    proof(cases \"P = P''\")\n      assume \"P = P''\"\n      moreover have \"[a\\<noteq>c]P \\<Longrightarrow>\\<^sub>\\<tau> [a\\<noteq>c]P\" by simp\n      moreover from P''Trans \\<open>a \\<noteq> c\\<close> have \"[a\\<noteq>c]P'' \\<longmapsto> \\<alpha> \\<prec> P'''\" by(rule transitions.Mismatch)\n      ultimately show ?thesis using P'''Trans by(blast intro: transitionI)\n    next\n      assume \"P \\<noteq> P''\"\n      with PTrans aineqc have \"[a\\<noteq>c]P \\<Longrightarrow>\\<^sub>\\<tau> P''\" by(rule mismatchChain)\n      thus ?thesis using P''Trans P'''Trans by(rule transitionI)\n    qed\n  qed\nnext\n  assume aineqc: \"a \\<noteq> c\"\n  assume \"P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>b<x> \\<prec> P'\"\n  then obtain P''' where PChain: \"P \\<Longrightarrow>\\<^sub>\\<tau> P'''\"\n                     and P'''Trans: \"P''' \\<longmapsto>b<x> \\<prec> P''\"\n                     and P''Chain: \"P''[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n    by(blast dest: transitionE)\n  show \"[a\\<noteq>c]P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>b<x> \\<prec> P'\"\n  proof(cases \"P=P'''\")\n    assume \"P=P'''\"\n    moreover have \"[a\\<noteq>c]P \\<Longrightarrow>\\<^sub>\\<tau> [a\\<noteq>c]P\" by simp\n    moreover from P'''Trans aineqc have \"[a\\<noteq>c]P''' \\<longmapsto>b<x> \\<prec> P''\" by(rule Late_Semantics.Mismatch)\n    ultimately show ?thesis using P''Chain by(blast intro: transitionI)\n  next\n    assume \"P \\<noteq> P'''\"\n    with PChain aineqc have \"[a\\<noteq>c]P \\<Longrightarrow>\\<^sub>\\<tau> P'''\" by(rule mismatchChain)\n    thus ?thesis using P'''Trans P''Chain by(rule transitionI)\n  qed\nqed\n\nlemma Open:\n  fixes P  :: pi\n  and   a  :: name\n  and   b  :: name\n  and   P' :: pi\n\n  assumes Trans:  \"P \\<Longrightarrow>\\<^sub>la[b] \\<prec> P'\"\n  and     aInEqb: \"a \\<noteq> b\"\n\n  shows \"<\\<nu>b>P \\<Longrightarrow>\\<^sub>la<\\<nu>b> \\<prec> P'\"\nproof -\n  from Trans obtain P'' P''' where A: \"P \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n                               and B: \"P'' \\<longmapsto>a[b] \\<prec> P'''\"\n                               and C: \"P''' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n    by(force dest: transitionE)\n  from A have \"<\\<nu>b>P \\<Longrightarrow>\\<^sub>\\<tau> <\\<nu>b>P''\" by(rule ResChain)\n  moreover from B aInEqb have \"<\\<nu>b>P'' \\<longmapsto>a<\\<nu>b> \\<prec> P'''\" by(rule Open)\n  ultimately show ?thesis using C by(force simp add: transition_def)\nqed\n\nlemma Sum1:\n  fixes P   :: pi\n  and   Rs  :: residual\n  and   Q   :: pi\n  and   u   :: name\n  and   P'' :: pi\n  and   a   :: name\n  and   x   :: name\n  and   P'  :: pi\n\n  shows \"P \\<Longrightarrow>\\<^sub>l Rs \\<Longrightarrow> P \\<oplus> Q \\<Longrightarrow>\\<^sub>l Rs\"\n  and   \"P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>a<x> \\<prec> P' \\<Longrightarrow> P \\<oplus> Q \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>a<x> \\<prec> P'\"\nproof -\n  assume \"P \\<Longrightarrow>\\<^sub>l Rs\"\n  thus \"P \\<oplus> Q \\<Longrightarrow>\\<^sub>l Rs\"\n  proof(nominal_induct avoiding: P rule: residual.strong_inducts)\n    case(BoundR a x P' P)\n    have PTrans: \"P \\<Longrightarrow>\\<^sub>la\\<guillemotleft>x\\<guillemotright> \\<prec> P'\"\n     and xFreshP: \"x \\<sharp> P\" by fact+\n    from PTrans obtain a' where aeq: \"a = BoundOutputS a'\" by(cases a, auto)\n    with PTrans xFreshP obtain P'' P''' where PTrans: \"P \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n                                          and P''Trans: \"P'' \\<longmapsto>a'<\\<nu>x> \\<prec> P'''\"\n                                          and P'''Trans: \"P''' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n      by(blast dest: transitionE)\n    show ?case\n    proof(cases \"P = P''\")\n      assume \"P = P''\"\n      moreover have \"P \\<oplus> Q \\<Longrightarrow>\\<^sub>\\<tau> P \\<oplus> Q\" by simp\n      moreover from P''Trans have \"P'' \\<oplus> Q \\<longmapsto>a'<\\<nu>x> \\<prec> P'''\" by(rule transitions.Sum1)\n      ultimately show ?thesis using P'''Trans aeq by(blast intro: transitionI)\n    next\n      assume \"P \\<noteq> P''\"\n      with PTrans have \"P \\<oplus> Q \\<Longrightarrow>\\<^sub>\\<tau> P''\" by(rule sum1Chain)\n      thus ?thesis using P''Trans P'''Trans aeq by(blast intro: transitionI)\n    qed\n  next\n    case(FreeR \\<alpha> P')\n    have \"P \\<Longrightarrow>\\<^sub>l \\<alpha> \\<prec> P'\" by fact\n\n    then obtain P'' P''' where PTrans: \"P \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n                           and P''Trans: \"P'' \\<longmapsto> \\<alpha> \\<prec> P'''\"\n                           and P'''Trans: \"P''' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n      by(blast dest: transitionE)\n    show ?case\n    proof(cases \"P = P''\")\n      assume \"P = P''\"\n      moreover have \"P \\<oplus> Q \\<Longrightarrow>\\<^sub>\\<tau> P \\<oplus> Q\" by simp\n      moreover from P''Trans have \"P'' \\<oplus> Q \\<longmapsto> \\<alpha> \\<prec> P'''\" by(rule transitions.Sum1)\n      ultimately show ?thesis using P'''Trans by(blast intro: transitionI)\n    next\n      assume \"P \\<noteq> P''\"\n      with PTrans have \"P \\<oplus> Q \\<Longrightarrow>\\<^sub>\\<tau> P''\" by(rule sum1Chain)\n      thus ?thesis using P''Trans P'''Trans by(rule transitionI)\n    qed\n  qed\nnext\n  assume \"P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>a<x> \\<prec> P'\"\n  then obtain P''' where PChain: \"P \\<Longrightarrow>\\<^sub>\\<tau> P'''\"\n                     and P'''Trans: \"P''' \\<longmapsto>a<x> \\<prec> P''\"\n                     and P''Chain: \"P''[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n    by(blast dest: transitionE)\n  show \"P \\<oplus> Q \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>a<x> \\<prec> P'\"\n  proof(cases \"P = P'''\")\n    assume \"P = P'''\"\n    moreover have \"P \\<oplus> Q \\<Longrightarrow>\\<^sub>\\<tau> P \\<oplus> Q\" by simp\n    moreover from P'''Trans have \"P''' \\<oplus> Q \\<longmapsto>a<x> \\<prec> P''\" by(rule transitions.Sum1)\n    ultimately show ?thesis using P''Chain by(blast intro: transitionI)\n  next\n    assume \"P \\<noteq> P'''\"\n    with PChain have \"P \\<oplus> Q \\<Longrightarrow>\\<^sub>\\<tau> P'''\" by(rule sum1Chain)\n    thus ?thesis using P'''Trans P''Chain by(blast intro: transitionI)\n  qed\nqed\n\nlemma Sum2:\n  fixes Q  :: pi\n  and   Rs :: residual\n  and   P  :: pi\n  and   u  :: name\n  and   Q'' :: pi\n  and   a  :: name\n  and   x  :: name\n  and   Q' :: pi\n\n  shows \"Q \\<Longrightarrow>\\<^sub>l Rs \\<Longrightarrow> P \\<oplus> Q \\<Longrightarrow>\\<^sub>l Rs\"\n  and   \"Q \\<Longrightarrow>\\<^sub>lu in Q''\\<rightarrow>a<x> \\<prec> Q' \\<Longrightarrow> P \\<oplus> Q \\<Longrightarrow>\\<^sub>lu in Q''\\<rightarrow>a<x> \\<prec> Q'\"\nproof -\n  assume \"Q \\<Longrightarrow>\\<^sub>l Rs\"\n  thus \"P \\<oplus> Q \\<Longrightarrow>\\<^sub>l Rs\"\n  proof(nominal_induct avoiding: Q rule: residual.strong_inducts)\n    case(BoundR a x Q' Q)\n    have QTrans: \"Q \\<Longrightarrow>\\<^sub>la\\<guillemotleft>x\\<guillemotright> \\<prec> Q'\"\n     and xFreshQ: \"x \\<sharp> Q\" by fact+\n    from QTrans obtain a' where aeq: \"a = BoundOutputS a'\" by(cases a, auto)\n    with QTrans xFreshQ obtain Q'' Q''' where QTrans: \"Q \\<Longrightarrow>\\<^sub>\\<tau> Q''\"\n                                          and Q''Trans: \"Q'' \\<longmapsto>a'<\\<nu>x> \\<prec> Q'''\"\n                                          and Q'''Trans: \"Q''' \\<Longrightarrow>\\<^sub>\\<tau> Q'\"\n      by(blast dest: transitionE)\n    show ?case\n    proof(cases \"Q = Q''\")\n      assume \"Q = Q''\"\n      moreover have \"P \\<oplus> Q \\<Longrightarrow>\\<^sub>\\<tau> P \\<oplus> Q\" by simp\n      moreover from Q''Trans have \"P \\<oplus> Q'' \\<longmapsto>a'<\\<nu>x> \\<prec> Q'''\" by(rule transitions.Sum2)\n      ultimately show ?thesis using Q'''Trans aeq by(blast intro: transitionI)\n    next\n      assume \"Q \\<noteq> Q''\"\n      with QTrans have \"P \\<oplus> Q \\<Longrightarrow>\\<^sub>\\<tau> Q''\" by(rule sum2Chain)\n      thus ?thesis using Q''Trans Q'''Trans aeq by(blast intro: transitionI)\n    qed\n  next\n    case(FreeR \\<alpha> Q')\n    have \"Q \\<Longrightarrow>\\<^sub>l \\<alpha> \\<prec> Q'\" by fact\n\n    then obtain Q'' Q''' where QTrans: \"Q \\<Longrightarrow>\\<^sub>\\<tau> Q''\"\n                           and Q''Trans: \"Q'' \\<longmapsto> \\<alpha> \\<prec> Q'''\"\n                           and Q'''Trans: \"Q''' \\<Longrightarrow>\\<^sub>\\<tau> Q'\"\n      by(blast dest: transitionE)\n    show ?case\n    proof(cases \"Q = Q''\")\n      assume \"Q = Q''\"\n      moreover have \"P \\<oplus> Q \\<Longrightarrow>\\<^sub>\\<tau> P \\<oplus> Q\" by simp\n      moreover from Q''Trans have \"P \\<oplus> Q'' \\<longmapsto> \\<alpha> \\<prec> Q'''\" by(rule transitions.Sum2)\n      ultimately show ?thesis using Q'''Trans by(blast intro: transitionI)\n    next\n      assume \"Q \\<noteq> Q''\"\n      with QTrans have \"P \\<oplus> Q \\<Longrightarrow>\\<^sub>\\<tau> Q''\" by(rule sum2Chain)\n      thus ?thesis using Q''Trans Q'''Trans by(rule transitionI)\n    qed\n  qed\nnext\n  assume \"Q \\<Longrightarrow>\\<^sub>lu in Q''\\<rightarrow>a<x> \\<prec> Q'\"\n  then obtain Q''' where QChain: \"Q \\<Longrightarrow>\\<^sub>\\<tau> Q'''\"\n                     and Q'''Trans: \"Q''' \\<longmapsto>a<x> \\<prec> Q''\"\n                     and Q''Chain: \"Q''[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> Q'\"\n    by(blast dest: transitionE)\n  show \"P \\<oplus> Q \\<Longrightarrow>\\<^sub>lu in Q''\\<rightarrow>a<x> \\<prec> Q'\"\n  proof(cases \"Q = Q'''\")\n    assume \"Q = Q'''\"\n    moreover have \"P \\<oplus> Q \\<Longrightarrow>\\<^sub>\\<tau> P \\<oplus> Q\" by simp\n    moreover from Q'''Trans have \"P \\<oplus> Q''' \\<longmapsto>a<x> \\<prec> Q''\" by(rule transitions.Sum2)\n    ultimately show ?thesis using Q''Chain by(blast intro: transitionI)\n  next\n    assume \"Q \\<noteq> Q'''\"\n    with QChain have \"P \\<oplus> Q \\<Longrightarrow>\\<^sub>\\<tau> Q'''\" by(rule sum2Chain)\n    thus ?thesis using Q'''Trans Q''Chain by(blast intro: transitionI)\n  qed\nqed\n\nlemma Par1B:\n  fixes P  :: pi\n  and   a  :: name\n  and   x  :: name\n  and   P' :: pi\n  and   u  :: name\n  and   P'' :: pi\n\n  shows \"\\<lbrakk>P \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> P'; x \\<sharp> Q\\<rbrakk> \\<Longrightarrow> P \\<parallel> Q \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> (P' \\<parallel> Q)\"\n  and   \"\\<lbrakk>P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>a<x> \\<prec> P'; x \\<sharp> Q\\<rbrakk> \\<Longrightarrow> P \\<parallel> Q \\<Longrightarrow>\\<^sub>lu in (P'' \\<parallel> Q)\\<rightarrow>a<x> \\<prec> P' \\<parallel> Q\"\nproof -\n  assume PTrans: \"P \\<Longrightarrow>\\<^sub>l a<\\<nu>x> \\<prec> P'\"\n  assume xFreshQ: \"x \\<sharp> Q\"\n\n  have Goal: \"\\<And>P a x P' Q. \\<lbrakk>P \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> P'; x \\<sharp> P; x \\<sharp> Q\\<rbrakk> \\<Longrightarrow> P \\<parallel> Q \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> (P' \\<parallel> Q)\"\n  proof -\n    fix P a x P' Q\n    assume PTrans: \"P \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> P'\"\n    assume xFreshP: \"x \\<sharp> P\"\n    assume xFreshQ: \"x \\<sharp> (Q::pi)\"\n\n    from PTrans xFreshP obtain P'' P''' where PTrans: \"P \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n                                          and P''Trans: \"P'' \\<longmapsto>a<\\<nu>x> \\<prec> P'''\"\n                                          and P'''Trans: \"P''' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n      by(blast dest: transitionE)\n    from PTrans have \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>\\<tau> P'' \\<parallel> Q\" by(rule Par1Chain)\n    moreover from P''Trans xFreshQ have \"P'' \\<parallel> Q \\<longmapsto>a<\\<nu>x> \\<prec> (P''' \\<parallel> Q)\" by(rule Par1B)\n    moreover from P'''Trans have \"P''' \\<parallel> Q \\<Longrightarrow>\\<^sub>\\<tau> P' \\<parallel> Q\" by(rule Par1Chain)\n    ultimately show \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> (P' \\<parallel> Q)\" by(rule transitionI)\n  qed\n  \n  have \"\\<exists>c::name. c \\<sharp> (P, P', Q)\" by(blast intro: name_exists_fresh)\n  then obtain c::name where cFreshP: \"c \\<sharp> P\" and cFreshP': \"c \\<sharp> P'\" and cFreshQ: \"c \\<sharp> Q\"\n    by(force simp add: fresh_prod)\n\n  from cFreshP' have \"a<\\<nu>x> \\<prec> P' = a<\\<nu>c> \\<prec> ([(x, c)] \\<bullet> P')\" by(rule alphaBoundResidual)\n  moreover have \"a<\\<nu>x> \\<prec> (P' \\<parallel> Q) = a<\\<nu>c> \\<prec> (([(x, c)] \\<bullet> P') \\<parallel> Q)\"\n  proof -\n    from cFreshP' cFreshQ have \"c \\<sharp> P' \\<parallel> Q\" by simp\n    hence \"a<\\<nu>x> \\<prec> (P' \\<parallel> Q) = a<\\<nu>c> \\<prec> ([(x, c)] \\<bullet> (P' \\<parallel> Q))\" by(rule alphaBoundResidual)\n    with cFreshQ xFreshQ show ?thesis by(simp add: name_fresh_fresh)\n  qed\n  ultimately show \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>l a<\\<nu>x> \\<prec> P' \\<parallel> Q\" using PTrans cFreshP cFreshQ by(force intro: Goal)\nnext\n  assume PTrans: \"P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>a<x> \\<prec> P'\"\n     and xFreshQ: \"x \\<sharp> Q\"\n  from PTrans obtain P''' where PChain: \"P \\<Longrightarrow>\\<^sub>\\<tau> P'''\"\n                            and P'''Trans: \"P''' \\<longmapsto>a<x> \\<prec> P''\"\n                            and P''Chain: \"P''[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n    by(blast dest: transitionE)\n  from PChain have \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>\\<tau> P''' \\<parallel> Q\" by(rule Par1Chain)\n  moreover from P'''Trans xFreshQ have \"P''' \\<parallel> Q \\<longmapsto>a<x> \\<prec> (P'' \\<parallel> Q)\" by(rule Par1B)\n  moreover have \"(P'' \\<parallel> Q)[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> P' \\<parallel> Q\"\n  proof - \n    from P''Chain have \"P''[x::=u] \\<parallel> Q \\<Longrightarrow>\\<^sub>\\<tau> P' \\<parallel> Q\" by(rule Par1Chain)\n    with xFreshQ show ?thesis by(simp add: forget)\n  qed\n  ultimately show \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>lu in (P'' \\<parallel> Q)\\<rightarrow>a<x> \\<prec> (P' \\<parallel> Q)\" by(rule transitionI)\nqed\n\nlemma Par1F:\n  fixes P  :: pi\n  and   \\<alpha>  :: freeRes\n  and   P' :: pi\n\n  assumes PTrans: \"P \\<Longrightarrow>\\<^sub>l\\<alpha> \\<prec> P'\"\n\n  shows \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>l\\<alpha> \\<prec> (P' \\<parallel> Q)\"\nproof -\n  from PTrans obtain P'' P''' where PTrans: \"P \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n                                and P''Trans: \"P'' \\<longmapsto>\\<alpha> \\<prec> P'''\"\n                                and P'''Trans: \"P''' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n    by(blast dest: transitionE)\n  from PTrans have \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>\\<tau> P'' \\<parallel> Q\" by(rule Par1Chain)\n  moreover from P''Trans have \"P'' \\<parallel> Q \\<longmapsto>\\<alpha> \\<prec> (P''' \\<parallel> Q)\" by(rule transitions.Par1F)\n  moreover from P'''Trans have \"P''' \\<parallel> Q \\<Longrightarrow>\\<^sub>\\<tau> P' \\<parallel> Q\" by(rule Par1Chain)\n  ultimately show ?thesis by(rule transitionI)\nqed\n\nlemma Par2B:\n  fixes Q  :: pi\n  and   a  :: name\n  and   x  :: name\n  and   Q' :: pi\n  and   P  :: pi\n  and   u  :: name\n  and   Q'' :: pi\n\n  shows \"Q \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> Q' \\<Longrightarrow> x \\<sharp> P \\<Longrightarrow> P \\<parallel> Q \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> (P \\<parallel> Q')\"\n  and   \"Q \\<Longrightarrow>\\<^sub>lu in Q''\\<rightarrow>a<x> \\<prec> Q' \\<Longrightarrow> x \\<sharp> P \\<Longrightarrow> P \\<parallel> Q \\<Longrightarrow>\\<^sub>lu in (P \\<parallel> Q'')\\<rightarrow>a<x> \\<prec> P \\<parallel> Q'\"\nproof -\n  assume QTrans: \"Q \\<Longrightarrow>\\<^sub>l a<\\<nu>x> \\<prec> Q'\"\n  assume xFreshP: \"x \\<sharp> P\"\n\n  have Goal: \"\\<And>Q a x Q' P. \\<lbrakk>Q \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> Q'; x \\<sharp> Q; x \\<sharp> P\\<rbrakk> \\<Longrightarrow> P \\<parallel> Q \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> (P \\<parallel> Q')\"\n  proof -\n    fix Q a x Q' P\n    assume QTrans: \"Q \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> Q'\"\n    assume xFreshQ: \"x \\<sharp> Q\"\n    assume xFreshP: \"x \\<sharp> (P::pi)\"\n\n    from QTrans xFreshQ obtain Q'' Q''' where QTrans: \"Q \\<Longrightarrow>\\<^sub>\\<tau> Q''\"\n                                          and Q''Trans: \"Q'' \\<longmapsto>a<\\<nu>x> \\<prec> Q'''\"\n                                          and Q'''Trans: \"Q''' \\<Longrightarrow>\\<^sub>\\<tau> Q'\"\n      by(blast dest: transitionE)\n    from QTrans have \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>\\<tau> P \\<parallel> Q''\" by(rule Par2Chain)\n    moreover from Q''Trans xFreshP have \"P \\<parallel> Q'' \\<longmapsto>a<\\<nu>x> \\<prec> (P \\<parallel> Q''')\" by(rule Par2B)\n    moreover from Q'''Trans have \"P \\<parallel> Q''' \\<Longrightarrow>\\<^sub>\\<tau> P \\<parallel> Q'\" by(rule Par2Chain)\n    ultimately show \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> (P \\<parallel> Q')\" by(rule transitionI)\n  qed\n  \n  have \"\\<exists>c::name. c \\<sharp> (Q, Q', P)\" by(blast intro: name_exists_fresh)\n  then obtain c::name where cFreshQ: \"c \\<sharp> Q\" and cFreshQ': \"c \\<sharp> Q'\" and cFreshP: \"c \\<sharp> P\"\n    by(force simp add: fresh_prod)\n\n  from cFreshQ' have \"a<\\<nu>x> \\<prec> Q' = a<\\<nu>c> \\<prec> ([(x, c)] \\<bullet> Q')\" by(rule alphaBoundResidual)\n  moreover have \"a<\\<nu>x> \\<prec> (P \\<parallel> Q') = a<\\<nu>c> \\<prec> (P \\<parallel> ([(x, c)] \\<bullet> Q'))\"\n  proof -\n    from cFreshQ' cFreshP have \"c \\<sharp> P \\<parallel> Q'\" by simp\n    hence \"a<\\<nu>x> \\<prec> (P \\<parallel> Q') = a<\\<nu>c> \\<prec> ([(x, c)] \\<bullet> (P \\<parallel> Q'))\" by(rule alphaBoundResidual)\n    with cFreshP xFreshP show ?thesis by(simp add: name_fresh_fresh)\n  qed\n  ultimately show \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>l a<\\<nu>x> \\<prec> P \\<parallel> Q'\" using QTrans cFreshQ cFreshP by(force intro: Goal)\nnext\n  assume QTrans: \"Q \\<Longrightarrow>\\<^sub>lu in Q''\\<rightarrow>a<x> \\<prec> Q'\"\n     and xFreshP: \"x \\<sharp> P\"\n  from QTrans obtain Q''' where QChain: \"Q \\<Longrightarrow>\\<^sub>\\<tau> Q'''\"\n                            and Q'''Trans: \"Q''' \\<longmapsto>a<x> \\<prec> Q''\"\n                            and Q''Chain: \"Q''[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> Q'\"\n    by(blast dest: transitionE)\n  from QChain have \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>\\<tau> P \\<parallel> Q'''\" by(rule Par2Chain)\n  moreover from Q'''Trans xFreshP have \"P \\<parallel> Q''' \\<longmapsto>a<x> \\<prec> (P \\<parallel> Q'')\" by(rule Par2B)\n  moreover have \"(P \\<parallel> Q'')[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> P \\<parallel> Q'\"\n  proof - \n    from Q''Chain have \"P \\<parallel> (Q''[x::=u]) \\<Longrightarrow>\\<^sub>\\<tau> P \\<parallel> Q'\" by(rule Par2Chain)\n    with xFreshP show ?thesis by(simp add: forget)\n  qed\n  ultimately show \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>lu in (P \\<parallel> Q'')\\<rightarrow>a<x> \\<prec> (P \\<parallel> Q')\" by(rule transitionI)\nqed\n\nlemma Par2F:\n  fixes Q :: pi\n  and   \\<alpha>  :: freeRes\n  and   Q' :: pi\n\n  assumes QTrans: \"Q \\<Longrightarrow>\\<^sub>l\\<alpha> \\<prec> Q'\"\n\n  shows \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>l\\<alpha> \\<prec> (P \\<parallel> Q')\"\nproof -\n  from QTrans obtain Q'' Q''' where QTrans: \"Q \\<Longrightarrow>\\<^sub>\\<tau> Q''\"\n                                and Q''Trans: \"Q'' \\<longmapsto>\\<alpha> \\<prec> Q'''\"\n                                and Q'''Trans: \"Q''' \\<Longrightarrow>\\<^sub>\\<tau> Q'\"\n    by(blast dest: transitionE)\n  from QTrans have \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>\\<tau> P \\<parallel> Q''\" by(rule Par2Chain)\n  moreover from Q''Trans have \"P \\<parallel> Q'' \\<longmapsto>\\<alpha> \\<prec> (P \\<parallel> Q''')\" by(rule transitions.Par2F)\n  moreover from Q'''Trans have \"P \\<parallel> Q''' \\<Longrightarrow>\\<^sub>\\<tau> P \\<parallel> Q'\" by(rule Par2Chain)\n  ultimately show ?thesis by(rule transitionI)\nqed\n\nlemma Comm1:\n  fixes P  :: pi\n  and   b  :: name\n  and   P'' :: pi\n  and   a  :: name\n  and   x  :: name\n  and   P' :: pi\n  and   Q  :: pi\n  and   Q' :: pi\n  \n  assumes PTrans: \"P \\<Longrightarrow>\\<^sub>lb in P'' \\<rightarrow>a<x> \\<prec> P'\"\n  and     QTrans: \"Q \\<Longrightarrow>\\<^sub>la[b] \\<prec> Q'\"\n\n  shows \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>l\\<tau> \\<prec> P' \\<parallel> Q'\"\nproof -\n  from PTrans obtain P''' where PChain: \"P \\<Longrightarrow>\\<^sub>\\<tau> P'''\"\n                            and P'''Trans: \"P''' \\<longmapsto>a<x> \\<prec> P''\"\n                            and P''Chain: \"P''[x::=b] \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n    by(blast dest: transitionE)\n  from QTrans obtain Q'' Q''' where QChain: \"Q \\<Longrightarrow>\\<^sub>\\<tau> Q'''\"\n                                and Q'''Trans: \"Q''' \\<longmapsto>a[b] \\<prec> Q''\"\n                                and Q''Chain: \"Q'' \\<Longrightarrow>\\<^sub>\\<tau> Q'\"\n    by(blast dest: transitionE)\n\n  from PChain QChain have \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>\\<tau> P''' \\<parallel> Q'''\" by(rule chainPar)\n  moreover from P'''Trans Q'''Trans have \"P''' \\<parallel> Q''' \\<longmapsto>\\<tau> \\<prec> P''[x::=b] \\<parallel> Q''\"\n    by(rule Comm1)\n  moreover from P''Chain Q''Chain have \"P''[x::=b] \\<parallel> Q'' \\<Longrightarrow>\\<^sub>\\<tau> P' \\<parallel> Q'\" by(rule chainPar)\n  ultimately show ?thesis by(rule transitionI)\nqed\n\nlemma Comm2:\n  fixes P  :: pi\n  and   a  :: name\n  and   b  :: name\n  and   P' :: pi\n  and   Q  :: pi\n  and   x  :: name\n  and   Q'' :: pi\n  and   Q' :: pi\n  \n  assumes PTrans: \"P \\<Longrightarrow>\\<^sub>la[b] \\<prec> P'\"\n  and     QTrans: \"Q \\<Longrightarrow>\\<^sub>lb in Q''\\<rightarrow>a<x> \\<prec> Q'\"\n\n  shows \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>l\\<tau> \\<prec> P' \\<parallel> Q'\"\nproof -\n  from PTrans obtain P'' P''' where PChain: \"P \\<Longrightarrow>\\<^sub>\\<tau> P'''\"\n                                and P'''Trans: \"P''' \\<longmapsto>a[b] \\<prec> P''\"\n                                and P''Chain: \"P'' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n    by(blast dest: transitionE)\n  from QTrans obtain Q''' where QChain: \"Q \\<Longrightarrow>\\<^sub>\\<tau> Q'''\"\n                            and Q'''Trans: \"Q''' \\<longmapsto>a<x> \\<prec> Q''\"\n                            and Q''Chain: \"Q''[x::=b] \\<Longrightarrow>\\<^sub>\\<tau> Q'\"\n    by(blast dest: transitionE)\n\n  from PChain QChain have \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>\\<tau> P''' \\<parallel> Q'''\" by(rule chainPar)\n  moreover from P'''Trans Q'''Trans have \"P''' \\<parallel> Q''' \\<longmapsto>\\<tau> \\<prec> P'' \\<parallel> (Q''[x::=b])\"\n    by(rule Comm2)\n  moreover from P''Chain Q''Chain have \"P'' \\<parallel> (Q''[x::=b]) \\<Longrightarrow>\\<^sub>\\<tau> P' \\<parallel> Q'\" by(rule chainPar)\n  ultimately show ?thesis by(rule transitionI)\nqed\n\nlemma Close1:\n  fixes P  :: pi\n  and   y  :: name\n  and   P'' :: pi\n  and   a  :: name\n  and   x  :: name\n  and   P' :: pi\n  and   Q  :: pi\n  and   Q' :: pi\n  \n  assumes PTrans: \"P \\<Longrightarrow>\\<^sub>ly in P''\\<rightarrow>a<x> \\<prec> P'\"\n  and     QTrans: \"Q \\<Longrightarrow>\\<^sub>la<\\<nu>y> \\<prec> Q'\"\n  and     yFreshP: \"y \\<sharp> P\"\n  and     yFreshQ: \"y \\<sharp> Q\"\n\n  shows \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>l\\<tau> \\<prec> <\\<nu>y>(P' \\<parallel> Q')\"\nproof -\n  from PTrans obtain P''' where PChain: \"P \\<Longrightarrow>\\<^sub>\\<tau> P'''\"\n                            and P'''Trans: \"P''' \\<longmapsto>a<x> \\<prec> P''\"\n                            and P''Chain: \"P''[x::=y] \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n    by(blast dest: transitionE)\n  from QTrans yFreshQ obtain Q'' Q''' where QChain: \"Q \\<Longrightarrow>\\<^sub>\\<tau> Q'''\"\n                                        and Q'''Trans: \"Q''' \\<longmapsto>a<\\<nu>y> \\<prec> Q''\"\n                                        and Q''Chain: \"Q'' \\<Longrightarrow>\\<^sub>\\<tau> Q'\"\n    by(blast dest: transitionE)\n  \n  from PChain yFreshP have yFreshP''': \"y \\<sharp> P'''\" by(rule freshChain)\n  \n  from PChain QChain have \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>\\<tau> P''' \\<parallel> Q'''\" by(rule chainPar)\n  moreover from P'''Trans Q'''Trans yFreshP''' have \"P''' \\<parallel> Q''' \\<longmapsto>\\<tau> \\<prec> <\\<nu>y>(P''[x::=y] \\<parallel> Q'')\"\n    by(rule Close1)\n  moreover have \"<\\<nu>y>(P''[x::=y] \\<parallel> Q'') \\<Longrightarrow>\\<^sub>\\<tau> <\\<nu>y>(P' \\<parallel> Q')\"\n  proof -\n    from P''Chain Q''Chain have \"P''[x::=y] \\<parallel> Q'' \\<Longrightarrow>\\<^sub>\\<tau> P' \\<parallel> Q'\" by(rule chainPar)\n    thus ?thesis by(rule ResChain)\n  qed\n  ultimately show \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>l\\<tau> \\<prec> <\\<nu>y>(P' \\<parallel> Q')\" by(rule transitionI)\nqed\n\nlemma Close2:\n  fixes P  :: pi\n  and   y  :: name\n  and   a  :: name\n  and   x  :: name\n  and   P' :: pi\n  and   Q  :: pi\n  and   Q'' :: pi\n  and   Q' :: pi\n  \n  assumes PTrans: \"P \\<Longrightarrow>\\<^sub>la<\\<nu>y> \\<prec> P'\"\n  and     QTrans: \"Q \\<Longrightarrow>\\<^sub>ly in Q''\\<rightarrow>a<x> \\<prec> Q'\"\n  and     yFreshP: \"y \\<sharp> P\"\n  and     yFreshQ: \"y \\<sharp> Q\"\n\n  shows \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>l\\<tau> \\<prec> <\\<nu>y>(P' \\<parallel> Q')\"\nproof -\n  from PTrans yFreshP obtain P'' P''' where PChain: \"P \\<Longrightarrow>\\<^sub>\\<tau> P'''\"\n                                        and P'''Trans: \"P''' \\<longmapsto>a<\\<nu>y> \\<prec> P''\"\n                                        and P''Chain: \"P'' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n    by(blast dest: transitionE)\n\n  from QTrans obtain Q''' where QChain: \"Q \\<Longrightarrow>\\<^sub>\\<tau> Q'''\"\n                            and Q'''Trans: \"Q''' \\<longmapsto>a<x> \\<prec> Q''\"\n                            and Q''Chain: \"Q''[x::=y] \\<Longrightarrow>\\<^sub>\\<tau> Q'\"\n    by(blast dest: transitionE)\n  \n  from QChain yFreshQ have yFreshQ''': \"y \\<sharp> Q'''\" by(rule freshChain)\n  \n  from PChain QChain have \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>\\<tau> P''' \\<parallel> Q'''\" by(rule chainPar)\n  moreover from P'''Trans Q'''Trans yFreshQ''' have \"P''' \\<parallel> Q''' \\<longmapsto>\\<tau> \\<prec> <\\<nu>y>(P'' \\<parallel> (Q''[x::=y]))\"\n    by(rule Close2)\n  moreover have \"<\\<nu>y>(P'' \\<parallel> (Q''[x::=y])) \\<Longrightarrow>\\<^sub>\\<tau> <\\<nu>y>(P' \\<parallel> Q')\"\n  proof -\n    from P''Chain Q''Chain have \"P'' \\<parallel> (Q''[x::=y]) \\<Longrightarrow>\\<^sub>\\<tau> P' \\<parallel> Q'\" by(rule chainPar)\n    thus ?thesis by(rule ResChain)\n  qed\n  ultimately show \"P \\<parallel> Q \\<Longrightarrow>\\<^sub>l\\<tau> \\<prec> <\\<nu>y>(P' \\<parallel> Q')\" by(rule transitionI)\nqed\n\nlemma ResF:\n  fixes P  :: pi\n  and   \\<alpha>  :: freeRes\n  and   P' :: pi\n  and   x  :: name\n\n  assumes PTrans: \"P \\<Longrightarrow>\\<^sub>l\\<alpha> \\<prec> P'\"\n  and     xFreshAlpha: \"x \\<sharp> \\<alpha>\"\n\n  shows \"<\\<nu>x>P \\<Longrightarrow>\\<^sub>l\\<alpha> \\<prec> <\\<nu>x>P'\"\nproof -\n  from PTrans obtain P'' P''' where PChain: \"P \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n                                and P''Trans: \"P'' \\<longmapsto>\\<alpha> \\<prec> P'''\"\n                                and P'''Chain: \"P''' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n    by(blast dest: transitionE)\n\n  from PChain have \"<\\<nu>x>P \\<Longrightarrow>\\<^sub>\\<tau> <\\<nu>x>P''\" by(rule ResChain)\n  moreover from P''Trans xFreshAlpha have \"<\\<nu>x>P'' \\<longmapsto>\\<alpha> \\<prec> <\\<nu>x>P'''\"\n    by(rule transitions.ResF)\n  moreover from P'''Chain have \"<\\<nu>x>P''' \\<Longrightarrow>\\<^sub>\\<tau> <\\<nu>x>P'\" by(rule ResChain)\n  ultimately show ?thesis by(rule transitionI)\nqed\n\nlemma ResB:\n  fixes P  :: pi\n  and   a  :: name\n  and   x  :: name\n  and   P' :: pi\n  and   y  :: name\n  and   u  :: name\n  and   P'' :: pi\n\n  shows \"\\<lbrakk>P \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> P'; y \\<noteq> a; y \\<noteq> x; x \\<sharp> P\\<rbrakk> \\<Longrightarrow> <\\<nu>y>P \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> (<\\<nu>y>P')\"\n  and   \"\\<lbrakk>P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>a<x> \\<prec> P'; y \\<noteq> a; y \\<noteq> x; y \\<noteq> u\\<rbrakk> \\<Longrightarrow> <\\<nu>y>P \\<Longrightarrow>\\<^sub>lu in (<\\<nu>y>P'')\\<rightarrow>a<x> \\<prec> (<\\<nu>y>P')\"\nproof -\n  assume PTrans: \"P \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> P'\"\n     and yineqa: \"y \\<noteq> a\"\n     and yineqx: \"y \\<noteq> x\"\n     and xFreshP: \"x \\<sharp> P\"\n\n  from PTrans xFreshP obtain P'' P''' where PChain: \"P \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n                                        and P''Trans: \"P'' \\<longmapsto>a<\\<nu>x> \\<prec> P'''\"\n                                        and P'''Chain: \"P''' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n    by(blast dest: transitionE)\n\n  from PChain have \"<\\<nu>y>P \\<Longrightarrow>\\<^sub>\\<tau> <\\<nu>y>P''\" by(rule ResChain)\n  moreover from P''Trans yineqa yineqx have \"<\\<nu>y>P'' \\<longmapsto>a<\\<nu>x> \\<prec> (<\\<nu>y>P''')\"\n    by(force intro: ResB)\n  moreover from P'''Chain have \"<\\<nu>y>P''' \\<Longrightarrow>\\<^sub>\\<tau> <\\<nu>y>P'\" by(rule ResChain)\n  ultimately show \"<\\<nu>y>P \\<Longrightarrow>\\<^sub>l a<\\<nu>x> \\<prec> <\\<nu>y>P'\" by(rule transitionI)\nnext\n  assume PTrans: \"P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>a<x> \\<prec> P'\"\n     and yineqa: \"y \\<noteq> a\"\n     and yineqx: \"y \\<noteq> x\"\n     and yinequ: \"y \\<noteq> u\" \n\n  from PTrans obtain P''' where PChain: \"P \\<Longrightarrow>\\<^sub>\\<tau> P'''\"\n                            and P'''Trans: \"P''' \\<longmapsto>a<x> \\<prec> P''\"\n                            and P''Chain: \"P''[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n    by(blast dest: transitionE)\n\n  from PChain have \"<\\<nu>y>P \\<Longrightarrow>\\<^sub>\\<tau> <\\<nu>y>P'''\" by(rule ResChain)\n  moreover from P'''Trans yineqa yineqx have \"<\\<nu>y>P''' \\<longmapsto>a<x> \\<prec> (<\\<nu>y>P'')\"\n    by(force intro: ResB)\n  moreover have \"(<\\<nu>y>P'')[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> <\\<nu>y>P'\"\n  proof -\n    from P''Chain have \"<\\<nu>y>(P''[x::=u]) \\<Longrightarrow>\\<^sub>\\<tau> <\\<nu>y>P'\" by(rule ResChain)\n    with yineqx yinequ show ?thesis by(simp add: eqvt_subs[THEN sym])\n  qed\n  ultimately show \"<\\<nu>y>P \\<Longrightarrow>\\<^sub>lu in (<\\<nu>y>P'')\\<rightarrow>a<x> \\<prec> <\\<nu>y>P'\" by(rule transitionI)\nqed\n\nlemma Bang:\n  fixes P  :: pi\n  and   Rs :: residual\n  and   u  :: name\n  and   P'' :: pi\n  and   a  :: name\n  and   x  :: name\n  and   P' :: pi\n\n  shows \"P \\<parallel> !P \\<Longrightarrow>\\<^sub>l Rs \\<Longrightarrow> !P \\<Longrightarrow>\\<^sub>l Rs\"\n  and   \"P \\<parallel> !P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>a<x> \\<prec> P' \\<Longrightarrow> !P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>a<x> \\<prec> P'\"\nproof -\n  assume \"P \\<parallel> !P \\<Longrightarrow>\\<^sub>l Rs\"\n  thus \"!P \\<Longrightarrow>\\<^sub>l Rs\"\n  proof(nominal_induct avoiding: P rule: residual.strong_inducts)\n    case(BoundR a x P' P)\n    assume xFreshP: \"x \\<sharp> P\"\n    assume PTrans: \"P \\<parallel> !P \\<Longrightarrow>\\<^sub>la\\<guillemotleft>x\\<guillemotright> \\<prec> P'\"\n    from PTrans obtain a' where aeq: \"a = BoundOutputS a'\" by(cases a, auto)\n\n    with PTrans xFreshP obtain P'' P''' where PChain: \"P \\<parallel> !P \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n                                          and P''Trans: \"P'' \\<longmapsto>a'<\\<nu>x> \\<prec> P'''\"\n                                          and P'''Chain: \"P''' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n      by(force dest: transitionE)\n\n    show \"!P \\<Longrightarrow>\\<^sub>la\\<guillemotleft>x\\<guillemotright> \\<prec> P'\"\n    proof(cases \"P'' = P \\<parallel> !P\")\n      assume \"P'' = P \\<parallel> !P\"\n      moreover with P''Trans have \"!P \\<longmapsto>a'<\\<nu>x> \\<prec> P'''\" by(blast intro: transitions.Bang)\n      ultimately show ?thesis using PChain P'''Chain aeq by(simp, rule_tac transitionI, auto)\n    next\n      assume \"P'' \\<noteq> P \\<parallel> !P\"\n      with PChain have \"!P \\<Longrightarrow>\\<^sub>\\<tau> P''\" by(rule bangChain)\n      with P''Trans P'''Chain aeq show ?thesis by(blast intro: transitionI)\n    qed\n  next\n    fix \\<alpha> P' P\n    assume \"P \\<parallel> !P \\<Longrightarrow>\\<^sub>l\\<alpha> \\<prec> P'\"\n    \n    then obtain P'' P''' where PChain: \"P \\<parallel> !P \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n                           and P''Trans: \"P'' \\<longmapsto>\\<alpha> \\<prec> P'''\"\n                           and P'''Chain: \"P''' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n      by(force dest: transitionE)\n\n\n    show \"!P \\<Longrightarrow>\\<^sub>l\\<alpha> \\<prec> P'\"\n    proof(cases \"P'' = P \\<parallel> !P\")\n      assume \"P'' = P \\<parallel> !P\"\n      moreover with P''Trans have \"!P \\<longmapsto>\\<alpha> \\<prec> P'''\" by(blast intro: transitions.Bang)\n      ultimately show ?thesis using PChain P'''Chain by(rule_tac transitionI, auto)\n    next\n      assume \"P'' \\<noteq> P \\<parallel> !P\"\n      with PChain have \"!P \\<Longrightarrow>\\<^sub>\\<tau> P''\" by(rule bangChain)\n      with P''Trans P'''Chain show ?thesis by(blast intro: transitionI)\n    qed\n  qed\nnext\n  assume \"P \\<parallel> !P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>a<x> \\<prec> P'\"\n\n  then obtain P''' where PChain: \"P \\<parallel> !P \\<Longrightarrow>\\<^sub>\\<tau> P'''\"\n                     and P'''Trans: \"P''' \\<longmapsto>a<x> \\<prec> P''\"\n                     and P''Chain: \"P''[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n    by(force dest: transitionE)\n  \n  show \"!P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>a<x> \\<prec> P'\"\n  proof(cases \"P''' = P \\<parallel> !P\")\n    assume \"P''' = P \\<parallel> !P\"\n    moreover with P'''Trans have \"!P \\<longmapsto>a<x> \\<prec> P''\" by(blast intro: transitions.Bang)\n    ultimately show ?thesis using PChain P''Chain by(rule_tac transitionI, auto)\n  next\n    assume \"P''' \\<noteq> P \\<parallel> !P\"\n    with PChain have \"!P \\<Longrightarrow>\\<^sub>\\<tau> P'''\" by(rule bangChain)\n    with P'''Trans P''Chain show ?thesis by(blast intro: transitionI)\n  qed\nqed\n\nlemma tauTransitionChain:\n  fixes P  :: pi\n  and   P' :: pi\n\n  assumes \"P \\<Longrightarrow>\\<^sub>l\\<tau> \\<prec> P'\"\n\n  shows \"P \\<Longrightarrow>\\<^sub>\\<tau> P'\"\nusing assms\nby(auto simp add: transition_def residualInject)\n\nlemma chainTransitionAppend:\n  fixes P   :: pi\n  and   P'  :: pi\n  and   Rs  :: residual\n  and   a   :: name\n  and   x   :: name\n  and   P'' :: pi\n  and   u   :: name\n  and   P''' :: pi\n  and   \\<alpha>   :: freeRes\n\n  shows \"P \\<Longrightarrow>\\<^sub>\\<tau> P' \\<Longrightarrow> P' \\<Longrightarrow>\\<^sub>l Rs \\<Longrightarrow> P \\<Longrightarrow>\\<^sub>l Rs\"\n  and   \"P \\<Longrightarrow>\\<^sub>\\<tau> P'' \\<Longrightarrow> P'' \\<Longrightarrow>\\<^sub>lu in P'''\\<rightarrow>a<x> \\<prec> P' \\<Longrightarrow> P \\<Longrightarrow>\\<^sub>lu in P'''\\<rightarrow>a<x> \\<prec> P'\"\n  and   \"P \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> P'' \\<Longrightarrow> P'' \\<Longrightarrow>\\<^sub>\\<tau> P' \\<Longrightarrow> x \\<sharp> P \\<Longrightarrow> P \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> P'\"\n  and   \"P \\<Longrightarrow>\\<^sub>lu in P'''\\<rightarrow>a<x> \\<prec> P'' \\<Longrightarrow> P'' \\<Longrightarrow>\\<^sub>\\<tau> P' \\<Longrightarrow> P \\<Longrightarrow>\\<^sub>lu in P'''\\<rightarrow>a<x> \\<prec> P'\"\n  and   \"P \\<Longrightarrow>\\<^sub>l\\<alpha> \\<prec> P'' \\<Longrightarrow> P'' \\<Longrightarrow>\\<^sub>\\<tau> P' \\<Longrightarrow> P \\<Longrightarrow>\\<^sub>l\\<alpha> \\<prec> P'\"\nproof -\n  assume \"P \\<Longrightarrow>\\<^sub>\\<tau> P'\" and \"P' \\<Longrightarrow>\\<^sub>l Rs\"\n  thus \"P \\<Longrightarrow>\\<^sub>l Rs\"\n    by(auto simp add: transition_def residualInject) (blast dest: rtrancl_trans)+\nnext\n  assume \"P \\<Longrightarrow>\\<^sub>\\<tau> P''\" and \"P'' \\<Longrightarrow>\\<^sub>lu in P'''\\<rightarrow>a<x> \\<prec> P'\"\n  thus \"P \\<Longrightarrow>\\<^sub>lu in P'''\\<rightarrow>a<x> \\<prec> P'\"\n    apply(auto simp add: inputTransition_def residualInject)\n    by(blast dest: rtrancl_trans)+\nnext\n  assume PTrans: \"P \\<Longrightarrow>\\<^sub>l a<\\<nu>x> \\<prec> P''\" \n  assume P''Chain: \"P'' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n  assume xFreshP: \"x \\<sharp> P\"\n\n  from PTrans xFreshP obtain P''' P'''' where PChain: \"P \\<Longrightarrow>\\<^sub>\\<tau> P'''\"\n                                          and P'''Trans: \"P''' \\<longmapsto>a<\\<nu>x> \\<prec> P''''\"\n                                          and P''''Chain: \"P'''' \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n    by(blast dest: transitionE)\n\n  from P''''Chain P''Chain have \"P'''' \\<Longrightarrow>\\<^sub>\\<tau> P'\" by auto\n  with PChain P'''Trans show \"P \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> P'\" by(rule transitionI)\nnext\n  assume PTrans: \"P \\<Longrightarrow>\\<^sub>lu in P'''\\<rightarrow>a<x> \\<prec> P''\" \n  assume P''Chain: \"P'' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n\n  from PTrans obtain P'''' where PChain: \"P \\<Longrightarrow>\\<^sub>\\<tau> P''''\"\n                             and P''''Trans: \"P'''' \\<longmapsto>a<x> \\<prec> P'''\"\n                             and P'''Chain: \"P'''[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n    by(blast dest: transitionE)\n\n  from P'''Chain P''Chain have \"P'''[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> P'\" by auto\n  with PChain P''''Trans show \"P \\<Longrightarrow>\\<^sub>lu in P'''\\<rightarrow>a<x> \\<prec> P'\" by(blast intro: transitionI)\nnext\n  assume PTrans: \"P \\<Longrightarrow>\\<^sub>l\\<alpha> \\<prec> P''\" \n  assume P''Chain: \"P'' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n\n  from PTrans obtain P''' P'''' where PChain: \"P \\<Longrightarrow>\\<^sub>\\<tau> P'''\"\n                                  and P'''Trans: \"P''' \\<longmapsto>\\<alpha> \\<prec> P''''\"\n                                  and P''''Chain: \"P'''' \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n    by(blast dest: transitionE)\n\n  from P''''Chain P''Chain have \"P'''' \\<Longrightarrow>\\<^sub>\\<tau> P'\" by auto\n  with PChain P'''Trans show \"P \\<Longrightarrow>\\<^sub>l\\<alpha> \\<prec> P'\" by(rule transitionI)\nqed\n\nlemma freshInputTransition:\n  fixes P  :: pi\n  and   a  :: name\n  and   x  :: name\n  and   u  :: name\n  and   P'' :: pi\n  and   P' :: pi\n  and   c  :: name\n\n  assumes PTrans: \"P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>a<x> \\<prec> P'\"\n  and     cFreshP: \"c \\<sharp> P\"\n  and     cinequ: \"c \\<noteq> u\"\n\n  shows \"c \\<sharp> P'\"\nproof -\n\n  from PTrans obtain P''' where PChain: \"P \\<Longrightarrow>\\<^sub>\\<tau> P'''\"\n                            and P'''Trans: \"P''' \\<longmapsto>a<x> \\<prec> P''\"\n                            and P''Chain: \"P''[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n    by(blast dest: transitionE)\n\n  from PChain cFreshP have cFreshP''': \"c \\<sharp> P'''\" by(rule freshChain)\n  show \"c \\<sharp> P'\"\n  proof(cases \"x=c\")\n    assume xeqc: \"x=c\"\n    from cinequ have \"c \\<sharp> P''[c::=u]\" apply - by(rule fresh_fact2)\n    with P''Chain xeqc show ?thesis by(force intro: freshChain)\n  next\n    assume xineqc: \"x\\<noteq>c\"\n    with P'''Trans cFreshP''' have \"c \\<sharp> P''\" by(blast dest: freshBoundDerivative)\n    with cinequ have \"c \\<sharp> P''[x::=u]\"\n      apply -\n      apply(rule fresh_fact1)\n      by simp\n    with P''Chain show ?thesis by(rule freshChain)\n  qed\nqed\n\nlemma freshBoundOutputTransition:\n  fixes P  :: pi\n  and   a  :: name\n  and   x  :: name\n  and   P' :: pi\n  and   c  :: name\n\n  assumes PTrans: \"P \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> P'\"\n  and     cFreshP: \"c \\<sharp> P\"\n  and     cineqx: \"c \\<noteq> x\"\n\n  shows \"c \\<sharp> P'\"\nproof -\n  have Goal: \"\\<And>P a x P' c. \\<lbrakk>P \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> P'; x \\<sharp> P; c \\<sharp> P; c \\<noteq> x\\<rbrakk> \\<Longrightarrow> c \\<sharp> P'\"\n  proof -\n    fix P a x P' c\n    assume PTrans: \"P \\<Longrightarrow>\\<^sub>la<\\<nu>x> \\<prec> P'\"\n    assume xFreshP: \"x \\<sharp> P\"\n    assume cFreshP: \"(c::name) \\<sharp> P\"\n    assume cineqx: \"c \\<noteq> x\"\n\n    from PTrans xFreshP obtain P'' P''' where PTrans: \"P \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n                                          and P''Trans: \"P'' \\<longmapsto>a<\\<nu>x> \\<prec> P'''\"\n                                          and P'''Trans: \"P''' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n      by(blast dest: transitionE)\n\n    from PTrans cFreshP have \"c \\<sharp> P''\" by(rule freshChain)\n    with P''Trans cineqx have \"c \\<sharp> P'''\" by(blast dest: Late_Semantics.freshBoundDerivative)\n    with P'''Trans show \"c \\<sharp> P'\" by(rule freshChain)\n  qed\n\n  have \"\\<exists>d::name. d \\<sharp> (P, P', c)\" by(blast intro: name_exists_fresh)\n  then obtain d::name where dFreshP: \"d \\<sharp> P\" and dFreshP': \"d \\<sharp> P'\" and cineqd: \"c \\<noteq> d\"\n    by(force simp add: fresh_prod)\n\n  from PTrans dFreshP' have \"P \\<Longrightarrow>\\<^sub>la<\\<nu>d> \\<prec> ([(x, d)] \\<bullet> P')\" by(simp add: alphaBoundResidual)\n  hence \"c \\<sharp> [(x, d)] \\<bullet> P'\" using dFreshP cFreshP cineqd by(rule Goal)\n  with cineqd cineqx show ?thesis by(simp add: name_fresh_left name_calc)\nqed\n\nlemma freshTauTransition:\n  fixes P :: pi\n  and   c :: name\n\n  assumes PTrans: \"P \\<Longrightarrow>\\<^sub>l\\<tau> \\<prec> P'\"\n  and     cFreshP: \"c \\<sharp> P\"\n\n  shows \"c \\<sharp> P'\"\nproof -\n  from PTrans have \"P \\<Longrightarrow>\\<^sub>\\<tau> P'\" by(rule tauTransitionChain)\n  thus ?thesis using cFreshP by(rule freshChain)\nqed\n\nlemma freshOutputTransition:\n  fixes P  :: pi\n  and   a  :: name\n  and   b  :: name\n  and   P' :: pi\n  and   c  :: name\n\n  assumes PTrans: \"P \\<Longrightarrow>\\<^sub>la[b] \\<prec> P'\"\n  and     cFreshP: \"c \\<sharp> P\"\n\n  shows \"c \\<sharp> P'\"\nproof -\n  from PTrans obtain P'' P''' where PTrans: \"P \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n                                and P''Trans: \"P'' \\<longmapsto>a[b] \\<prec> P'''\"\n                                and P'''Trans: \"P''' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n      by(blast dest: transitionE)\n\n    from PTrans cFreshP have \"c \\<sharp> P''\" by(rule freshChain)\n    with P''Trans have \"c \\<sharp> P'''\" by(blast dest: Late_Semantics.freshFreeDerivative)\n    with P'''Trans show ?thesis by(rule freshChain)\nqed\n\nlemma eqvtI:\n  fixes P    :: pi\n  and   Rs   :: residual\n  and   perm :: \"name prm\"\n  and   u    :: name\n  and   P''  :: pi\n  and   a    :: name\n  and   x    :: name\n  and   P'   :: pi\n\n  shows \"P \\<Longrightarrow>\\<^sub>l Rs \\<Longrightarrow> (perm \\<bullet> P) \\<Longrightarrow>\\<^sub>l (perm \\<bullet> Rs)\"\n  and   \"P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>a<x> \\<prec> P' \\<Longrightarrow> (perm \\<bullet> P) \\<Longrightarrow>\\<^sub>l(perm \\<bullet> u) in (perm \\<bullet> P'')\\<rightarrow>(perm \\<bullet> a)<(perm \\<bullet> x)> \\<prec> (perm \\<bullet> P')\"\nproof -\n  assume \"P \\<Longrightarrow>\\<^sub>l Rs\"\n  thus \"(perm \\<bullet> P) \\<Longrightarrow>\\<^sub>l (perm \\<bullet> Rs)\"\n  proof(nominal_induct Rs avoiding: P rule: residual.strong_inducts)\n    case(BoundR a x P' P)\n    have PTrans: \"P \\<Longrightarrow>\\<^sub>la\\<guillemotleft>x\\<guillemotright> \\<prec> P'\" by fact\n    moreover then obtain b where aeqb: \"a = BoundOutputS b\" by(cases a, auto)\n    moreover have \"x \\<sharp> P\" by fact\n    ultimately obtain P'' P''' where PTrans: \"P \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n                               and P''Trans: \"P'' \\<longmapsto>b<\\<nu>x> \\<prec> P'''\"\n                              and P'''Trans: \"P''' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n      by(blast dest: transitionE)\n\n    from PTrans have \"(perm \\<bullet> P) \\<Longrightarrow>\\<^sub>\\<tau> (perm \\<bullet> P'')\" by(rule eqvtChainI)\n    moreover from P''Trans have \"(perm \\<bullet> P'') \\<longmapsto> (perm \\<bullet> (b<\\<nu>x> \\<prec> P'''))\"\n      by(rule eqvts)\n    moreover from P'''Trans have \"(perm \\<bullet> P''') \\<Longrightarrow>\\<^sub>\\<tau> (perm \\<bullet> P')\" by(rule eqvtChainI)\n    ultimately show ?case using aeqb by(force intro: transitionI)\n  next\n    case(FreeR \\<alpha> P' P)\n    have \"P \\<Longrightarrow>\\<^sub>l\\<alpha> \\<prec> P'\" by fact\n    then obtain P'' P''' where PTrans: \"P \\<Longrightarrow>\\<^sub>\\<tau> P''\"\n                           and P''Trans: \"P'' \\<longmapsto>\\<alpha> \\<prec> P'''\"\n                           and P'''Trans: \"P''' \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n      by(blast dest: transitionE)\n\n    from PTrans have \"(perm \\<bullet> P) \\<Longrightarrow>\\<^sub>\\<tau> (perm \\<bullet> P'')\" by(rule eqvtChainI)\n    moreover from P''Trans have \"(perm \\<bullet> P'') \\<longmapsto> (perm \\<bullet> (\\<alpha> \\<prec> P'''))\"\n      by(rule eqvts)\n    moreover from P'''Trans have \"(perm \\<bullet> P''') \\<Longrightarrow>\\<^sub>\\<tau> (perm \\<bullet> P')\" by(rule eqvtChainI)\n    ultimately show ?case by(force intro: transitionI)\n  qed\nnext\n  assume \"P \\<Longrightarrow>\\<^sub>lu in P''\\<rightarrow>a<x> \\<prec> P'\"\n\n  then obtain P''' where PChain: \"P \\<Longrightarrow>\\<^sub>\\<tau> P'''\"\n                     and P'''Trans: \"P''' \\<longmapsto>a<x> \\<prec> P''\"\n                     and P''Chain: \"P''[x::=u] \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n      by(blast dest: transitionE)\n\n    from PChain have \"(perm \\<bullet> P) \\<Longrightarrow>\\<^sub>\\<tau> (perm \\<bullet> P''')\" by(rule eqvtChainI)\n    moreover from P'''Trans have \"(perm \\<bullet> P''') \\<longmapsto> (perm \\<bullet> (a<x> \\<prec> P''))\"\n      by(rule eqvts)\n    moreover from P''Chain have \"(perm \\<bullet> P''[x::=u]) \\<Longrightarrow>\\<^sub>\\<tau> (perm \\<bullet> P')\" by(rule eqvtChainI)\n    ultimately show \"(perm \\<bullet> P) \\<Longrightarrow>\\<^sub>l(perm \\<bullet> u) in (perm \\<bullet> P'')\\<rightarrow>(perm \\<bullet> a)<(perm \\<bullet> x)> \\<prec> (perm \\<bullet> P')\"\n      by(force intro: transitionI simp add: eqvt_subs[THEN sym] perm_bij)\nqed\n\nlemmas freshTransition = freshBoundOutputTransition freshOutputTransition\n                         freshInputTransition freshTauTransition\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Pi_Calculus/Weak_Late_Step_Semantics.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5583270090337583, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.2639119517211647}}
{"text": "(*\n    File:        dAlpha.thy\n    Time-stamp:  <2016-01-12T14:47:32Z>\n    Author:      JRF\n    Web:         http://jrf.cocolog-nifty.com/software/2016/01/post.html\n    Logic Image: Logics_ZF (of Isabelle2020)\n*)\n\ntheory dAlpha imports dLambda begin\n\ndefinition dSkeltonEq :: \"[i, i] => o\" where\n\"dSkeltonEq(M, N) == M: dTerm & N: dTerm &\n   (ALL l. (EX x. <l, TdVar(x)>: dOcc(M))\n                    <-> (EX x. <l, TdVar(x)>: dOcc(N))) &\n   (ALL l. (EX n. <l, TdBound(n)>: dOcc(M))\n                    <-> (EX n. <l, TdBound(n)>: dOcc(N))) &\n   (ALL l. <l, TdLam>: dOcc(M) <-> <l, TdLam>: dOcc(N)) &\n   (ALL l. <l, TdApp>: dOcc(M) <-> <l, TdApp>: dOcc(N))\"\n\ndefinition dAlpha :: \"[i, i]=>o\" where\n\"dAlpha(M, N) == dSkeltonEq(M, N) &\n   (ALL l x. <l, TdVar(x)>: dOcc(M) <-> <l, TdVar(x)>: dOcc(N)) &\n   (ALL l m. (EX T U. dBoundBy(<l, T>, <m, U>, M))\n                     <-> (EX T U. dBoundBy(<l, T>, <m, U>, N)))\"\n\n\n(** dSkeltonEq **)\nlemma dSkeltonEqD1:\n  \"dSkeltonEq(M, N) ==> M: dTerm\"\napply (unfold dSkeltonEq_def)\napply (erule conjunct1)\ndone\n\nlemma dSkeltonEqD2:\n  \"dSkeltonEq(M, N) ==> N: dTerm\"\napply (unfold dSkeltonEq_def)\napply (erule conjunct2 [THEN conjunct1])\ndone\n\nlemma dSkeltonEq_TdVarD:\n  \"[| dSkeltonEq(M, N); <l, TdVar(x)>: dOcc(M) |]\n      ==> EX x. <l, TdVar(x)>: dOcc(N)\"\napply (unfold dSkeltonEq_def)\napply blast\ndone\n\nlemma dSkeltonEq_TdBoundD:\n  \"[| dSkeltonEq(M, N); <l, TdBound(n)>: dOcc(M) |]\n      ==> EX n. <l, TdBound(n)>: dOcc(N)\"\napply (unfold dSkeltonEq_def)\napply blast\ndone\n\nlemma dSkeltonEq_TdLamD:\n  \"[| dSkeltonEq(M, N); <l, TdLam>: dOcc(M) |]\n      ==> <l, TdLam>: dOcc(N)\"\napply (unfold dSkeltonEq_def)\napply blast\ndone\n\nlemma dSkeltonEq_TdAppD:\n  \"[| dSkeltonEq(M, N); <l, TdApp>: dOcc(M) |]\n      ==> <l, TdApp>: dOcc(N)\"\napply (unfold dSkeltonEq_def)\napply blast\ndone\n\nlemma dSkeltonEq_refl:\n  \"M: dTerm ==> dSkeltonEq(M, M)\"\napply (unfold dSkeltonEq_def)\napply blast\ndone\n\nlemma dSkeltonEq_sym:\n  \"dSkeltonEq(M, N) ==> dSkeltonEq(N, M)\"\napply (unfold dSkeltonEq_def)\napply blast\ndone\n\nlemma dSkeltonEq_trans:\n  \"[| dSkeltonEq(M, N); dSkeltonEq(N, L) |] ==> dSkeltonEq(M, L)\"\napply (unfold dSkeltonEq_def)\napply (erule conjE)+\napply ((erule spec [THEN iff_trans], erule spec)\n       | (assumption | rule conjI allI))+\ndone\n\nlemma dSkeltonEq_dVarI:\n  \"[| x: LVariable; y: LVariable |] ==> dSkeltonEq(dVar(x), dVar(y))\"\napply (unfold dSkeltonEq_def)\napply (assumption | rule dTerm.intros conjI)+\napply (blast elim!: dTag.free_elims dOcc_dTermEs\n         intro: dOcc_dTermIs)+\ndone\n\nlemma dSkeltonEq_dBoundI:\n  \"[| n: nat; m: nat |] ==> dSkeltonEq(dBound(n), dBound(m))\"\napply (unfold dSkeltonEq_def)\napply (assumption | rule dTerm.intros conjI)+\napply (blast elim!: dTag.free_elims dOcc_dTermEs\n         intro: dOcc_dTermIs)+\ndone\n\nlemma dSkeltonEq_dLamI:\n  \"dSkeltonEq(M, N) ==> dSkeltonEq(dLam(M), dLam(N))\"\napply (unfold dSkeltonEq_def)\napply (erule conjE)+\napply (assumption | rule dTerm.intros conjI)\napply (safe elim!: dTag.free_elims dOcc_dTermEs)\napply (blast intro: dOcc_dTermIs)+\ndone\n\nlemma dSkeltonEq_dAppI:\n  \"[| dSkeltonEq(A, C); dSkeltonEq(B, D)|]\n      ==> dSkeltonEq(dApp(A, B), dApp(C, D))\"\napply (unfold dSkeltonEq_def)\napply (erule conjE)+\napply (assumption | rule dTerm.intros conjI)\napply (safe elim!: dTag.free_elims dOcc_dTermEs)\napply (blast intro!: dOcc_dTermIs)+\ndone\n\nlemmas dSkeltonEq_LTermIs = dSkeltonEq_dVarI dSkeltonEq_dBoundI\n                          dSkeltonEq_dLamI dSkeltonEq_dAppI\n\nlemma dSkeltonEq_dVarE:\n  assumes major: \"dSkeltonEq(dVar(x), N)\"\n  and prem:\n     \"!! y B. [| N = dVar(y); x: LVariable; y: LVariable |] ==> R\"\n  shows \"R\"\napply (insert major)\napply (unfold dSkeltonEq_def)\napply (elim dTerm_typeEs conjE)\napply (subgoal_tac \"EX y. <[], TdVar(y)>: dOcc(N)\"\n                   \"EX y: LVariable.  N = dVar(y)\")\nprefer 3\napply (erule spec [THEN iffD1])\napply (assumption | rule exI dOcc_dTermIs)+\nprefer 2\napply (erule exE)\napply (erule_tac a=\"N\" in dTerm.cases)\nprefer 4\napply hypsubst\napply (blast elim!: dTag.free_elims list.free_elims dOcc_dTermEs)\nprefer 3\napply hypsubst\napply (blast elim!: dTag.free_elims list.free_elims dOcc_dTermEs)\nprefer 2\napply (blast elim!: dTag.free_elims list.free_elims dOcc_dTermEs)\napply (assumption | rule bexI)+\napply (erule bexE)\napply (rule prem)\napply assumption+\ndone\n\nlemma dSkeltonEq_dBoundE:\n  assumes major: \"dSkeltonEq(dBound(n), N)\"\n  and prem: \"!! m B. [| N = dBound(m); n: nat; m: nat |] ==> R\"\n  shows \"R\"\napply (insert major)\napply (unfold dSkeltonEq_def)\napply (elim dTerm_typeEs conjE)\napply (subgoal_tac \"EX m. <[], TdBound(m)>: dOcc(N)\"\n                   \"EX m: nat.  N = dBound(m)\")\nprefer 3\napply (erule spec [THEN iffD1])\napply (assumption | rule exI dOcc_dTermIs)+\nprefer 2\napply (erule exE)\napply (erule_tac a=\"N\" in dTerm.cases)\nprefer 4\napply hypsubst\napply (blast elim!: dTag.free_elims list.free_elims dOcc_dTermEs)\nprefer 3\napply hypsubst\napply (blast elim!: dTag.free_elims list.free_elims dOcc_dTermEs)\nprefer 1\napply (blast elim!: dTag.free_elims list.free_elims dOcc_dTermEs)\napply (assumption | rule bexI)+\napply (erule bexE)\napply (rule prem)\napply assumption+\ndone\n\nlemma dSkeltonEq_dLamE:\n  assumes major: \"dSkeltonEq(dLam(A), N)\"\n  and prem: \"!! y B. [| N = dLam(B); dSkeltonEq(A, B) |] ==> R\"\n  shows \"R\"\napply (insert major)\napply (unfold dSkeltonEq_def)\napply (elim dTerm_typeEs conjE)\napply (subgoal_tac \"<[], TdLam>: dOcc(N)\"\n                   \"EX B: dTerm. N = dLam(B)\")\nprefer 3\napply (erule spec [THEN iffD1])\napply (assumption | rule exI dOcc_dTermIs)+\nprefer 2\napply (erule_tac a=\"N\" in dTerm.cases)\nprefer 4\napply hypsubst\napply (blast elim!: dTag.free_elims list.free_elims dOcc_dTermEs)\nprefer 3\napply hypsubst\napply (blast elim!: dTag.free_elims list.free_elims dOcc_dTermEs)\nprefer 2\napply hypsubst\napply (blast elim!: dTag.free_elims list.free_elims dOcc_dTermEs)\napply hypsubst\napply (blast elim!: dTag.free_elims list.free_elims dOcc_dTermEs)\napply (elim bexE)\napply hypsubst\napply (rule prem)\napply assumption\napply (unfold dSkeltonEq_def)\napply (intro conjI)\napply assumption+\n\napply (intro allI iffI)\napply (erule exE)\napply (drule spec [THEN iffD1], rule exI, erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\napply (erule exE)\napply (drule spec [THEN iffD2], rule exI, erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\n\napply (intro allI iffI)\napply (erule exE)\napply (drule spec [THEN iffD1], rule exI, erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\napply (erule exE)\napply (drule spec [THEN iffD2], rule exI, erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\n\napply (intro allI iffI)\napply (drule spec [THEN iffD1], erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\napply (drule spec [THEN iffD2], erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\n\napply (intro allI iffI)\napply (drule spec [THEN iffD1], erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\napply (drule spec [THEN iffD2], erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\ndone\n\nlemma dSkeltonEq_dAppE:\n  assumes major: \"dSkeltonEq(dApp(A, B), N)\"\n  and prem:\n   \"!! C D. [| N = dApp(C, D); dSkeltonEq(A, C); dSkeltonEq(B, D) |]\n            ==> R\"\n  shows \"R\"\napply (insert major)\napply (unfold dSkeltonEq_def)\napply (elim dTerm_typeEs conjE)\napply (subgoal_tac \"<[], TdApp>: dOcc(N)\"\n                   \"EX C: dTerm.  EX D: dTerm. N = dApp(C, D)\")\nprefer 3\napply (erule spec [THEN iffD1])\napply (assumption | rule dOcc_dTermIs)+\nprefer 2\napply (erule_tac a=\"N\" in dTerm.cases)\napply hypsubst\napply (blast elim!: dTag.free_elims dOcc_dTermEs)\napply (blast elim!: dTag.free_elims dOcc_dTermEs)\napply (blast elim!: dTag.free_elims list.free_elims dOcc_dTermEs)\napply (blast elim!: dTag.free_elims list.free_elims dOcc_dTermEs)\n\napply (elim bexE)\napply (rule prem)\napply assumption\napply (unfold dSkeltonEq_def)\n\napply hypsubst\napply (intro conjI)\napply assumption+\n\napply (intro allI iffI)\napply (erule exE)\napply (drule spec [THEN iffD1], rule exI, erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\napply (erule exE)\napply (drule spec [THEN iffD2], rule exI, erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\n\napply (intro allI iffI)\napply (erule exE)\napply (drule spec [THEN iffD1], rule exI, erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\napply (erule exE)\napply (drule spec [THEN iffD2], rule exI, erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\n\napply (intro allI iffI)\napply (drule spec [THEN iffD1], erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\napply (drule spec [THEN iffD2], erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\n\napply (intro allI iffI)\napply (drule spec [THEN iffD1], erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\napply (drule spec [THEN iffD2], erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\n\napply hypsubst\napply (intro conjI)\napply assumption+\n\napply (intro allI iffI)\napply (erule exE)\napply (drule spec [THEN iffD1], rule exI, erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\napply (erule exE)\napply (drule spec [THEN iffD2], rule exI, erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\n\napply (intro allI iffI)\napply (erule exE)\napply (drule spec [THEN iffD1], rule exI, erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\napply (erule exE)\napply (drule spec [THEN iffD2], rule exI, erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\n\napply (intro allI iffI)\napply (drule spec [THEN iffD1], erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\napply (drule spec [THEN iffD2], erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\n\napply (intro allI iffI)\napply (drule spec [THEN iffD1], erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\napply (drule spec [THEN iffD2], erule dOcc_dTermIs)\napply (blast elim!: list.free_elims dTag.free_elims dOcc_dTermEs)\n\ndone\n\nlemmas dSkeltonEq_dTermEs = dSkeltonEq_dVarE dSkeltonEq_dBoundE\n                            dSkeltonEq_dLamE dSkeltonEq_dAppE\n\nlemma dSkeltonEq_skelton:\n  assumes major: \"dSkeltonEq(M, N)\"\n  and prem: \"<l, T>: dOcc(M)\"\n  shows \"EX U. <l, U>: dOcc(N)\"\napply (insert dOcc_typeD2 [OF prem major [THEN dSkeltonEqD1]] prem)\napply (erule dTag.cases)\napply hypsubst\napply (drule major [THEN dSkeltonEq_TdVarD])\napply (erule exE)\napply (erule exI)\napply hypsubst\napply (drule major [THEN dSkeltonEq_TdBoundD])\napply (erule exE)\napply (erule exI)\napply hypsubst\napply (drule major [THEN dSkeltonEq_TdLamD])\napply (erule exI)\napply hypsubst\napply (drule major [THEN dSkeltonEq_TdAppD])\napply (erule exI)\ndone\n\nlemmas dTerm_Occ_ind_cond_Occ_not_empty_lemma\n  = Occ_ind_cond_Occ_not_empty_lemma [OF dTerm_Occ_ind_cond]\n\nlemma dSkeltonEq_dLamDeg_lemma:\n  assumes major: \"dSkeltonEq(M, N)\"\n  and prem1: \"<l, T>: dOcc(M)\"\n  and prem2: \"<l @ x, U>: dOcc(M)\"\n  shows \"dLamDeg(x, dsubterm(M, l)) = dLamDeg(x, dsubterm(N, l))\"\napply (rule prem2 [THEN rev_mp])\napply (rule prem1 [THEN rev_mp])\napply (rule major [THEN rev_mp])\napply (rule_tac x=\"N\" in spec)\napply (rule_tac x=\"T\" in spec)\napply (rule_tac x=\"l\" and A=\"list(nat)\" in bspec)\napply (rule_tac x=\"x\" and A=\"list(nat)\" in bspec)\nprefer 3\nprefer 3\napply (rule dOcc_typeD1 [OF prem2 major [THEN dSkeltonEqD1], \n        THEN app_typeD])\napply (rule dOcc_typeD1 [OF prem1 major [THEN dSkeltonEqD1]])+\napply (rule major [THEN dSkeltonEqD1, THEN dTerm.induct])\napply (safe elim!: dSkeltonEq_dTermEs ConsE dOcc_dTermEs\n         dTag.free_elims)\napply (simp_all add: dTerm.intros dSkeltonEqD1 dSkeltonEqD2)\napply (safe elim!: list.free_elims ConsE)\n\napply (frule dSkeltonEqD1 [THEN dTerm_Occ_ind_cond_Occ_not_empty_lemma])\napply (erule bexE)\napply (drule_tac x6=\"l\" and x5=\"[]\" and x3=\"B\" in bspec [THEN bspec, THEN spec, THEN spec,\n       THEN mp, THEN mp, THEN mp])\napply (assumption | rule list.intros)+\napply simp\napply (simp add: dSkeltonEqD1 dSkeltonEqD2)\n\napply (frule dSkeltonEqD1 [THEN dTerm_Occ_ind_cond_Occ_not_empty_lemma])\napply (erule bexE)\napply (drule_tac x6=\"l\" and x5=\"[]\" and x3=\"C\" in bspec [THEN bspec, THEN spec, THEN spec,\n       THEN mp, THEN mp, THEN mp], erule_tac [4] asm_rl)\napply (assumption | rule list.intros)+\napply simp\napply (simp add: dSkeltonEqD1 dSkeltonEqD2)\n\napply (frule_tac M=\"N\" in dSkeltonEqD1 [THEN dTerm_Occ_ind_cond_Occ_not_empty_lemma])\napply (erule bexE)\napply (drule_tac x6=\"l\" and x5=\"[]\" and x3=\"D\" in bspec [THEN bspec, THEN spec, THEN spec,\n       THEN mp, THEN mp, THEN mp], erule_tac [4] asm_rl)\napply (assumption | rule list.intros)+\napply simp\napply (simp add: dSkeltonEqD1 dSkeltonEqD2)\ndone\n\n\n(** dAlpha **)\nlemma dAlphaD1:\n  \"dAlpha(M, N) ==> dSkeltonEq(M, N)\"\napply (unfold dAlpha_def)\napply (erule conjunct1)\ndone\n\nlemma dAlphaD2:\n  \"[| dAlpha(M, N); <l, TdVar(x)>: dOcc(M) |] ==> <l, TdVar(x)>: dOcc(N)\"\napply (unfold dAlpha_def)\napply blast\ndone\n\nlemma dAlphaD3:\n  \"[| dAlpha(M, N); dBoundBy(<l, T>, <m, U>, M) |]\n      ==> EX n. dBoundBy(<l, TdBound(n)>, <m, TdLam>, N)\"\napply (unfold dAlpha_def)\napply (drule conjunct2 [THEN conjunct2])\napply (drule spec [THEN spec, THEN iffD1])\napply (erule exI [THEN exI])\napply (elim exE)\napply (rule_tac M=\"N\" in dBoundByE)\napply assumption\napply safe\napply (erule exI)\ndone\n\nlemma dAlpha_dBoundByD:\n  assumes major: \"dAlpha(M, N)\"\n  and prem: \"dBoundBy(<l, T>, <m, U>, M)\"\n  shows \"dBoundBy(<l, T>, <m, U>, N)\"\napply (rule prem [THEN dBoundByE])\napply (insert dAlphaD3 [OF major prem])\napply (safe elim!: dBoundByE dest!: app_right_inj\n            elim!: dTag.free_elims)\napply (erule dOcc_typeD1)\napply assumption\napply (frule major [THEN dAlphaD1, THEN dSkeltonEq_dLamDeg_lemma], assumption)\napply (simp only: succ_inject_iff)\napply (assumption | rule refl dBoundByI)+\ndone\n\nlemma dAlphaI:\n  assumes prem1: \"dSkeltonEq(M, N)\"\n  and prem2: \"!! l x. <l, TdVar(x)>: dOcc(M) <-> <l, TdVar(x)>: dOcc(N)\"\n  and prem3: \"!! l m. (EX x. dBoundBy(<l, TdBound(x)>, <m, TdLam>, M))\n               <-> (EX x. dBoundBy(<l, TdBound(x)>, <m, TdLam>, N))\"\n  shows \"dAlpha(M, N)\"\napply (unfold dAlpha_def)\napply (rule prem1 [THEN conjI])\napply (rule allI [THEN allI, THEN conjI])\napply (rule prem2)\napply safe\napply (rule_tac [2] dBoundByE, erule_tac [2] asm_rl)\napply (rule_tac [1] dBoundByE, erule_tac [1] asm_rl)\napply safe\napply (drule exI [THEN prem3 [THEN iffD1]])\napply (drule_tac [2] exI [THEN prem3 [THEN iffD2]])\napply blast+\ndone\n\nlemma dAlpha_dPropI:\n  assumes prem1: \"M: dProp\"\n  and prem2: \"N: dProp\"\n  and prem3:\n     \"!! l. <l, TdLam>: dOcc(M) <-> <l, TdLam>: dOcc(N)\"\n  and prem4:\n     \"!! l. <l, TdApp>: dOcc(M) <-> <l, TdApp>: dOcc(N)\"\n  and prem5:\n     \"!! l x. <l, TdVar(x)>: dOcc(M) <-> <l, TdVar(x)>: dOcc(N)\"\n  and prem6:\n     \"!! l m. (EX x. dBoundBy(<l, TdBound(x)>, <m, TdLam>, M))\n              <-> (EX x. dBoundBy(<l, TdBound(x)>, <m, TdLam>, N))\"\n  shows \"dAlpha(M, N)\"\napply (rule dAlphaI)\napply (erule_tac [2] asm_rl | rule_tac [2] prem5 prem6)+\napply (unfold dSkeltonEq_def)\napply (assumption | rule conjI prem1 prem2 dPropD1)+\napply (rule_tac [2] conjI)\napply (rule_tac [3] conjI)\napply (rule_tac [4] allI)\napply (rule_tac [3] allI)\napply (rule_tac [2] allI)\napply (rule_tac [1] allI)\napply (erule_tac [3] asm_rl | rule_tac [3] prem3 prem4)+\napply safe\napply (drule prem5 [THEN iffD1], erule exI)\napply (drule prem5 [THEN iffD2], erule exI)\napply (drule prem1 [THEN dProp_dBoundBy_lemma1])\napply (drule_tac [2] prem2 [THEN dProp_dBoundBy_lemma1])\napply safe\napply (drule exI [THEN prem6 [THEN iffD1]])\napply (drule_tac [2] exI [THEN prem6 [THEN iffD2]])\napply (blast elim!: dBoundByE)+\ndone\n\nlemma dAlpha_refl:\n  \"M: dTerm ==> dAlpha(M, M)\"\napply (unfold dAlpha_def)\napply (blast intro: dSkeltonEq_refl)\ndone\n\nlemma dAlpha_sym:\n  \"dAlpha(M, N) ==> dAlpha(N, M)\"\napply (unfold dAlpha_def)\napply (blast intro: dSkeltonEq_sym)\ndone\n\nlemma dAlpha_trans:\n  \"[| dAlpha(M, N); dAlpha(N, L) |] ==> dAlpha(M, L)\"\napply (unfold dAlpha_def)\napply (blast intro: dSkeltonEq_trans)\ndone\n\nlemmas dTerm_Occ_ind_cond_Occ_inj = Occ_ind_cond_Occ_inj [OF\n  dTerm_Occ_ind_cond]\n\nlemma dAlpha_imp_dProp_eq:\n  assumes major: \"dAlpha(M, N)\"\n  and prem1: \"M: dProp\"\n  and prem2: \"N: dProp\"\n  shows \"M = N\"\napply (insert prem1 [THEN dPropD1] prem2 [THEN dPropD1])\napply (rule dTerm_Occ_ind_cond_Occ_inj [THEN iffD1])\napply (assumption | rule equalityI)+\napply (rule_tac [2] subsetI)\napply (rule_tac [1] subsetI)\napply (rule_tac [2] dOcc_domain [THEN subsetD, THEN SigmaE],\n       erule_tac [3] asm_rl)\napply (rule_tac [1] dOcc_domain [THEN subsetD, THEN SigmaE],\n       erule_tac [2] asm_rl)\nprefer 3\napply assumption+\napply (erule_tac [2] dTag.cases)\napply (erule_tac [1] dTag.cases)\nprefer 6\napply hypsubst\napply (drule prem2 [THEN dProp_dBoundBy_lemma1])\napply (erule exE)\napply (drule major [THEN dAlpha_sym, THEN dAlpha_dBoundByD])\ndefer 1\ndefer 6\ndefer 6\nprefer 2\napply hypsubst\napply (drule prem1 [THEN dProp_dBoundBy_lemma1])\napply (erule exE)\napply (drule major [THEN dAlpha_dBoundByD])\nprefer 2\napply (safe elim!: dBoundByE dTag.free_elims)\n\napply (erule major [THEN dAlphaD2])\napply (erule major [THEN dAlphaD1, THEN dSkeltonEq_TdLamD])\napply (erule major [THEN dAlphaD1, THEN dSkeltonEq_TdAppD])\napply (erule major [THEN dAlpha_sym, THEN dAlphaD2])\napply (erule major [THEN dAlpha_sym, THEN dAlphaD1, THEN dSkeltonEq_TdLamD])\napply (erule major [THEN dAlpha_sym, THEN dAlphaD1, THEN dSkeltonEq_TdAppD])\ndone\n\nlemma dAlpha_dProp_iff:\n  assumes prem1: \"M: dProp\"\n  and prem2: \"N: dProp\"\n  shows \"dAlpha(M, N) <-> M = N\"\napply (rule iffI)\nprefer 2\napply hypsubst\napply (rule prem2 [THEN dPropD1, THEN dAlpha_refl])\napply (erule dAlpha_imp_dProp_eq)\napply (rule prem1 prem2)+\ndone\n\n\n(** Rules for depth induction **)\nlemmas dTerm_Occ_Term_cons = Occ_Term_cons [OF\n  dTerm_Occ_ind_cond dTerm_Term_cons_inj_cond]\n\nlemma depth_ind_dLam:\n  \"[| dOcc(dLam(M)) <= Occ_fbs_op(dTag, Z); M: dTerm |]\n     ==> dOcc(M) <= domain(Z) * dTag\"\napply (rule_tac P=\"%x. x <= domain(Z) * dTag\" in ssubst)\napply (erule_tac [2] b=\"0\" in Occ_subtree_Occ_fbs_op_lemma)\napply (simp add: dTerm_Occ_Term_cons Occ_subtree_Occ_cons\n        dTerm_cons_eqns_sym)\ndone\n\nlemma depth_ind_dApp1:\n  \"[| dOcc(dApp(M, N)) <= Occ_fbs_op(dTag, Z); M: dTerm; N: dTerm |]\n     ==> dOcc(M) <= domain(Z) * dTag\"\napply (rule_tac P=\"%x. x <= domain(Z) * dTag\" in ssubst)\napply (erule_tac [2] b=\"0\" in Occ_subtree_Occ_fbs_op_lemma)\napply (simp add: dTerm_Occ_Term_cons Occ_subtree_Occ_cons\n        dTerm_cons_eqns_sym)\ndone\n\nlemma depth_ind_dApp2:\n  \"[| dOcc(dApp(M, N)) <= Occ_fbs_op(dTag, Z); M: dTerm; N: dTerm |]\n     ==> dOcc(N) <= domain(Z) * dTag\"\napply (rule_tac P=\"%x. x <= domain(Z) * dTag\" in ssubst)\napply (erule_tac [2] b=\"1\" in Occ_subtree_Occ_fbs_op_lemma)\napply (simp add: dTerm_Occ_Term_cons Occ_subtree_Occ_cons\n        dTerm_cons_eqns_sym)\ndone\n\nlemma depth_ind_dSubst_dVar_lemma:\n  assumes major: \"<l, T>: dOcc(dSubst(M, n, dVar(x)))\"\n  and prem1: \"M: dTerm\"\n  and prem2: \"x: LVariable\"\n  and prem3: \"n: nat\"\n  shows \"EX T. <l, T>: dOcc(M)\"\napply (insert prem2)\napply (rule major [THEN rev_mp])\napply (rule prem3 [THEN [2] bspec])\napply (rule_tac x=\"l\" in spec)\napply (rule prem1 [THEN dTerm.induct])\napply (rule_tac [2] ballI [THEN allI])\napply (case_tac [2] \"xaa = n\")\napply (case_tac [3] \"xaa < n\")\napply (simp_all del: all_simps ball_simps)\napply (safe elim!: dOcc_dTermEs)\napply (blast intro!: dOcc_dTermIs)+\ndone\n\nlemma depth_ind_dSubst_dVar:\n  assumes major: \"dOcc(M) <= domain(Z) * dTag\"\n  and prem1: \"M: dTerm\"\n  and prem2: \"x: LVariable\"\n  and prem3: \"n: nat\"\n  shows \"dOcc(dSubst(M, n, dVar(x))) <= domain(Z) * dTag\"\napply (rule subsetI)\napply (rule dOcc_domain [THEN subsetD, THEN SigmaE])\nprefer 2 apply assumption\napply (assumption | rule dSubst_type prem1 prem2 prem3 dTerm.intros)+\napply hypsubst\napply (frule depth_ind_dSubst_dVar_lemma)\napply (erule_tac [4] exE)\napply (rule_tac [4] SigmaI)\napply (erule_tac [4] major [THEN subsetD, THEN SigmaD1])\napply (assumption | rule prem2 prem3 prem1)+\ndone\n\nend\n", "meta": {"author": "JRF-2018", "repo": "isabelle_TheLambda", "sha": "e89eff1cbbf26da9bc6a3af603ae9d099d97c1ad", "save_path": "github-repos/isabelle/JRF-2018-isabelle_TheLambda", "path": "github-repos/isabelle/JRF-2018-isabelle_TheLambda/isabelle_TheLambda-e89eff1cbbf26da9bc6a3af603ae9d099d97c1ad/dAlpha.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5583269943353745, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.2639119447734815}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |               December 2004               |\n            |                   June 2005  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |                October 2005  (modified)   |\n            |                  April 2006  (modified)   |\n            |                  March 2007  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory CSP_F_law_step\nimports CSP_F_domain CSP_T.CSP_T_law_step\nbegin\n\n(*****************************************************************\n\n         1. step laws\n         2.\n         3. \n         4. \n\n *****************************************************************)\n\n(*********************************************************\n                    stop expansion\n *********************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspF_STOP_step: \"STOP =F[M1,M2] ? :{} -> Pf\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_STOP_step)\napply (simp add: failures_iff)\ndone\n\n(* to avoide producing free variables in tactics *)\n\nlemma cspF_STOP_step_DIV: \"STOP =F[M1,M2] ? x:{} -> DIV\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_STOP_step)\napply (simp add: failures_iff)\ndone\n\n\n(*********************************************************\n                    Act_prefix expansion\n *********************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspF_Act_prefix_step: \"a -> P =F[M,M] ? x:{a} -> P\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Act_prefix_step)\napply (simp add: failures_iff)\ndone\n\n(*********************************************************\n                    Ext choice expansion\n *********************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspF_Ext_choice_step:\n  \"(? :X -> Pf) [+] (? :Y -> Qf) =F[M,M]\n      ? x:(X Un Y) -> \n                (IF (x : X & x : Y) THEN (Pf x |~| Qf x)\n                 ELSE IF (x : X) THEN Pf x\n                 ELSE Qf x)\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Ext_choice_step)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_failures)\n apply (elim disjE conjE exE)\n apply (simp_all)\n apply (force)\n apply (rule_tac x=\"a\" in exI)\n apply (rule_tac x=\"sa\" in exI)\n apply (simp)\n apply (rule_tac x=\"a\" in exI)\n apply (rule_tac x=\"sa\" in exI)\n apply (simp)\n apply (simp add: in_traces)\n apply (simp add: in_traces)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_failures)\n apply (elim disjE conjE exE)\n apply (simp_all)\n apply (force)\n\n apply (case_tac \"a : Y\")\n apply (simp_all add: in_failures)\n\n apply (case_tac \"a : X\")\n apply (simp_all add: in_failures)\ndone\n\n(*********************************************************\n                    Parallel expansion\n *********************************************************)\n\n(* set 1 *)\n\nlemma cspF_Parallel_step_set1:\n  \"[| Ya - insert Tick (Ev ` X) = Za - insert Tick (Ev ` X) ;\n       Ev ` Y Int Ya = {}; Ev ` Z Int Za = {} |]\n   ==> Ev ` (X Int Y Int Z) Int (Ya Un Za) = {}\"\nby (auto)\n\n(* set 2 *)\n\nlemma cspF_Parallel_step_set2:\n  \"[| Ya - insert Tick (Ev ` X) = Za - insert Tick (Ev ` X) ;\n       Ev ` Y Int Ya = {}; Ev ` Z Int Za = {} |]\n   ==> Ev ` (Y - X) Int (Ya Un Za) = {}\"\napply (rule equalityI)\n apply (rule subsetI)\n apply (simp add: inj_image_diff_dist)\n apply (simp add: in_Ev_set)\n apply (elim conjE exE)\n\n apply (erule disjE)\n  apply (fast)\n    (* *)\n  apply (simp)\n   apply (case_tac \"Ev a : Ya\")\n   apply (fast)\n   apply (rotate_tac 1)\n   apply (erule equalityE)\n   apply (rotate_tac -1)\n   apply (erule subsetE)\n   apply (drule_tac x=\"Ev a\" in bspec, fast)\n   apply (simp)\n  apply (fast)\ndone\n\n(* set 3 *)\n\nlemma cspF_Parallel_step_set3:\n  \"[| Ya - insert Tick (Ev ` X) = Za - insert Tick (Ev ` X) ;\n       Ev ` Y Int Ya = {}; Ev ` Z Int Za = {} |]\n   ==> Ev ` (Z - X) Int (Ya Un Za) = {}\"\napply (rule equalityI)\n apply (rule subsetI)\n apply (simp add: inj_image_diff_dist)\n apply (simp add: in_Ev_set)\n apply (elim conjE exE)\n apply (erule disjE)\n  apply (simp)\n   apply (case_tac \"Ev a : Za\")\n   apply (fast)\n   apply (rotate_tac 1)\n   apply (erule equalityE)\n   apply (erule subsetE)\n   apply (drule_tac x=\"Ev a\" in bspec, fast)\n   apply (simp)\n  apply (fast)\n    (* *)\n  apply (simp)\ndone\n\n(* set 4 *)\n\nlemma cspF_Parallel_step_set4:\n  \"Ev ` (X Int Y Int Z Un (Y - X) Un (Z - X)) Int Xa = {} \n   ==> Xa =\n       Xa - insert Tick (Ev ` X) Un (Xa Int insert Tick (Ev ` X) - Ev ` Y) Un\n      (Xa - insert Tick (Ev ` X) Un (Xa Int insert Tick (Ev ` X) - Ev ` Z))\"\nby (auto)\n\n(* set 5 *)\n\nlemma cspF_Parallel_step_set5:\n  \"Ev ` (X Int Y Int Z Un (Y - X) Un (Z - X)) Int Xa = {} \n   ==> Ev ` Y Int\n      (Xa - insert Tick (Ev ` X) Un (Xa Int insert Tick (Ev ` X) - Ev ` Y)) = {} &\n       Ev ` Z Int\n      (Xa - insert Tick (Ev ` X) Un (Xa Int insert Tick (Ev ` X) - Ev ` Z)) = {}\"\nby (auto)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspF_Parallel_step: \n  \"(? :Y -> Pf) |[X]| (? :Z -> Qf) =F[M,M]\n      ? x:((X Int Y Int Z) Un (Y - X) Un (Z - X))\n         -> IF (x : X) THEN (Pf x |[X]| Qf x)\n               ELSE IF (x : Y & x : Z) THEN ((Pf x |[X]| ? x:Z -> Qf x)\n                                     |~| (? x:Y -> Pf x |[X]| Qf x))\n               ELSE IF (x : Y) THEN (Pf x |[X]| ? x:Z -> Qf x)\n               ELSE (? x:Y -> Pf x |[X]| Qf x)\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Parallel_step)\napply (rule order_antisym)\n\n(* => *)\napply (rule)\napply (simp add: in_failures)\napply (elim disjE conjE exE)\n\n (* (nil,nil) *)\n apply (simp add: image_Un Int_Un_distrib2)\n apply (simp add: cspF_Parallel_step_set1\n                  cspF_Parallel_step_set2\n                  cspF_Parallel_step_set3)\n\n (* (nil,Ev) *)\n apply (simp)\n apply (insert trace_nil_or_Tick_or_Ev)\n apply (drule_tac x=\"s\" in spec)\n\n apply (erule disjE, simp)\n apply (erule disjE, simp)\n apply (elim conjE exE, simp)\n apply (simp add: par_tr_head)\n \n apply (rule_tac x=\"aa\" in exI)\n apply (rule_tac x=\"sc\" in exI)\n apply (simp)\n\n apply (case_tac \"aa : Y\")\n  apply (simp)\n  apply (rule disjI2)\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"<>\" in exI)\n  apply (rule_tac x=\"sb\" in exI)\n  apply (simp)\n  (* \"aa ~: Y\" *)\n  apply (simp)\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"<>\" in exI)\n  apply (rule_tac x=\"sb\" in exI)\n  apply (simp)\n\n (* (Ev,nil) *)\n apply (simp)\n apply (drule_tac x=\"s\" in spec)\n\n apply (erule disjE, simp)\n apply (erule disjE, simp)\n apply (elim conjE exE, simp)\n apply (simp add: par_tr_head)\n \n apply (rule_tac x=\"a\" in exI)\n apply (rule_tac x=\"sc\" in exI)\n apply (simp)\n\n apply (case_tac \"a : Z\")\n  apply (simp)\n  apply (rule disjI1)\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"sb\" in exI)\n  apply (rule_tac x=\"<>\" in exI)\n  apply (simp)\n  (* \"a ~: Z\" *)\n  apply (simp)\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"sb\" in exI)\n  apply (rule_tac x=\"<>\" in exI)\n  apply (simp)\n\n (* (Ev,Ev) *)\n apply (drule_tac x=\"s\" in spec)\n apply (erule disjE, simp)\n apply (erule disjE, simp)\n apply (elim conjE exE, simp)\n apply (simp add: par_tr_head)\n apply (elim disjE conjE exE, simp)\n\n  (* sync *)\n  apply (rule_tac x=\"aa\" in exI)\n  apply (rule_tac x=\"sd\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"sb\" in exI)\n  apply (rule_tac x=\"sc\" in exI)\n  apply (simp)\n\n  (* left *)\n  apply (simp)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"sd\" in exI)\n  apply (simp)\n\n  apply (case_tac \"a : Z\")\n   apply (simp)\n   apply (rule disjI1)\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev aa> ^^^ sc\" in exI)\n   apply (simp)\n   (* \"a ~: Z\" *)\n   apply (simp)\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev aa> ^^^ sc\" in exI)\n   apply (simp)\n\n  (* right *)\n  apply (simp)\n  apply (rule_tac x=\"aa\" in exI)\n  apply (rule_tac x=\"sd\" in exI)\n  apply (simp)\n\n  apply (case_tac \"aa : Y\")\n   apply (simp)\n   apply (rule disjI2)\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"sc\" in exI)\n   apply (simp)\n   (* \"aa ~: Y\" *)\n   apply (simp)\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"sc\" in exI)\n   apply (simp)\n\n(* <= *)\n\napply (rule)\napply (simp add: in_failures)\napply (elim disjE conjE exE)\n\n (* nil *)\n apply (simp)\n apply (rule_tac x=\"(Xa - insert Tick (Ev ` X)) Un\n                   ((Xa Int insert Tick (Ev ` X)) - Ev ` Y)\" in exI)\n apply (rule_tac x=\"(Xa - insert Tick (Ev ` X)) Un\n                   ((Xa Int insert Tick (Ev ` X)) - Ev ` Z)\" in exI)\n apply (simp add: cspF_Parallel_step_set4)\n apply (rule conjI, force)\n apply (simp add: cspF_Parallel_step_set5)\n\n (* sync *)\n apply (simp add: in_failures)\n apply (elim conjE exE, simp)\n apply (rule_tac x=\"Ya\" in exI)\n apply (rule_tac x=\"Za\" in exI)\n apply (simp)\n apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n apply (simp add: par_tr_head)\n\n (* left *)\n apply (case_tac \"a : Z\")\n  apply (simp add: in_failures)\n  apply (erule disjE)\n   apply (elim conjE exE, simp)\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n   (* *)\n   apply (elim conjE exE, simp)\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n  (* \"a ~: Z\" *)\n  apply (simp add: in_failures)\n  apply (elim conjE exE, simp)\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n  apply (rule_tac x=\"t\" in exI)\n  apply (simp add: par_tr_head)\n\n (* right *)\n apply (case_tac \"a : Y\")\n  apply (simp add: in_failures)\n  apply (erule disjE)\n   apply (elim conjE exE, simp)\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI)\n   apply (simp add: par_tr_head)\n   (* *)\n   apply (elim conjE exE, simp)\n   apply (rule_tac x=\"Ya\" in exI)\n   apply (rule_tac x=\"Za\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n   apply (simp add: par_tr_head)\n  (* \"a ~: Y\" *)\n  apply (simp add: in_failures)\n  apply (elim conjE exE, simp)\n  apply (rule_tac x=\"Ya\" in exI)\n  apply (rule_tac x=\"Za\" in exI)\n  apply (simp)\n  apply (rule_tac x=\"sb\" in exI)\n  apply (rule_tac x=\"<Ev a> ^^^ t\" in exI)\n  apply (simp add: par_tr_head)\ndone\n\n(*********************************************************\n                      Hide expansion\n *********************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspF_Hiding_step: \n  \"(? :Y -> Pf) -- X =F[M,M] \n      IF (Y Int X = {}) THEN (? x:Y -> (Pf x -- X))\n                         ELSE ((? x:(Y-X) -> (Pf x -- X)) \n                               [> (! x:(Y Int X) .. (Pf x -- X)))\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Hiding_step)\napply (rule order_antisym)\n\n (* => *)\n apply (rule)\n apply (simp add: in_failures)\n apply (elim conjE exE)\n apply (erule disjE)\n  (* not hidden *)\n  apply (simp)\n  apply (case_tac \"Y Int X ~= {}\", fast)\n  apply (simp)\n  apply (fast)\n  (* hidden *)\n  apply (elim conjE exE)\n   apply (simp)\n\n  apply (case_tac \"a : X\")\n  apply (case_tac \"Y Int X = {}\", fast)\n   apply (simp)\n   apply (case_tac \"sb --tr X = <>\")\n   apply (rule disjI1)\n   apply (simp)\n   apply (rule_tac x=\"a\" in bexI)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (simp)\n   apply (simp)\n\n   apply (rule disjI2)\n   apply (simp)\n   apply (rule disjI2)\n   apply (rule_tac x=\"a\" in bexI)\n   apply (rule_tac x=\"sb\" in exI)\n   apply (simp)\n   apply (simp)\n\n  (* a ~: X *)\n   apply (case_tac \"Y Int X = {}\")\n    apply (simp)\n    apply (fast)\n   (* Y Int X ~= {} *)\n    apply (simp)\n    apply (fast)\n\n (* <= *)\n apply (rule)\n apply (case_tac \"Y Int X = {}\")\n  apply (simp add: in_failures)\n  apply (erule disjE)\n   apply (rule_tac x=\"<>\" in exI)\n   apply (simp)\n   apply (fast)\n  (* *)\n   apply (elim conjE exE)\n   apply (case_tac \"a : X\", fast)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (simp)\n\n (* Y Int X ~= {} *)\n apply (simp add: in_failures_IF)\n apply (simp add: in_failures_Timeout)\n apply (elim disjE)\n  (* 1 *)\n  apply (simp add: in_failures)\n  apply (elim conjE exE bexE)\n  apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n  apply (simp)\n\n  (* 2 *)\n  apply (simp add: in_failures)\n  apply (elim conjE, simp)\n  apply (elim conjE exE)\n  apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n  apply (simp)\n  (* 3 *)\n  apply (simp add: in_failures)\n  apply (simp add: in_traces)\ndone\n\n(*********************************************************\n                    Renaming expansion\n *********************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspF_Renaming_step:\n  \"(? :X -> Pf) [[r]] =F[M,M] \n    ? y:(r `` X) -> (! x:{x. x:X & (x,y):r} .. (Pf x)[[r]])\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Renaming_step)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_failures)\n apply (elim disjE conjE exE)\n  (* 1 *)\n  apply (simp add: ren_inv_def)\n  apply (force)\n  (* 2 *)\n  apply (simp add: ren_tr_decompo)\n  apply (elim conjE exE)\n  apply (rule disjI2)\n  apply (rule_tac x=\"b\" in exI)\n  apply (rule_tac x=\"t\" in exI)\n  apply (simp)\n  apply (fast)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_failures)\n apply (elim disjE conjE exE)\n  (* 1 *)\n  apply (simp add: ren_inv_def)\n  apply (force)\n  (* 2 *)\n  apply (rule_tac x=\"<Ev aa> ^^^ sb\" in exI)\n  apply (simp)\ndone\n\n(*********************************************************\n            Sequential composition expansion\n *********************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspF_Seq_compo_step: \n  \"(? :X -> Pf) ;; Q =F[M,M] ? x:X -> (Pf x ;; Q)\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Seq_compo_step)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_failures)\n apply (elim conjE exE disjE)\n\n apply (simp_all)\n apply (insert trace_nil_or_Tick_or_Ev)\n apply (drule_tac x=\"sa\" in spec)\n apply (erule disjE)\n apply (simp add: in_traces)\n apply (erule disjE)\n apply (simp)\n\n apply (elim conjE exE)\n apply (simp)\n apply (rule_tac x=\"a\" in exI)\n apply (rule_tac x=\"sb ^^^ t\" in exI)\n apply (simp add: appt_assoc)\n apply (simp add: in_traces)\n apply (fast)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_failures)\n apply (erule disjE)\n (* 1 *)\n  apply (rule disjI1)\n  apply (simp)\n  apply (fast)\n\n (* 2 *)\n  apply (elim conjE exE disjE)\n\n  (* 2-1 *)\n   apply (simp)\n\n  (* 2-2 *)\n   apply (rule disjI2)\n   apply (simp)\n   apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n   apply (rule_tac x=\"t\" in exI, simp)\n   apply (simp add: appt_assoc)\n   apply (simp add: in_traces)\ndone\n\n(*********************************************************\n                    Depth_rest expansion\n *********************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspF_Depth_rest_step:\n  \"(? :X -> Pf) |. (Suc n) =F[M,M] ? x:X -> (Pf x |. n)\"\napply (simp add: cspF_cspT_semantics)\napply (simp add: cspT_Depth_rest_step)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_failures)\n apply (elim disjE conjE exE)\n apply (simp_all)\n apply (rule_tac x=\"a\" in exI)\n apply (rule_tac x=\"sb\" in exI)\n apply (simp)\n apply (rule disjI2)\n apply (insert trace_nil_or_Tick_or_Ev)\n apply (drule_tac x=\"sa\" in spec)\n apply (elim conjE exE disjE)\n apply (simp_all)\n apply (simp add: appt_assoc)\n apply (force)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_failures)\n apply (elim disjE conjE exE)\n apply (simp_all)\n apply (rule_tac x=\"<Ev a> ^^^ sb\" in exI)\n apply (simp add: appt_assoc)\ndone\n\n(*********************************************************)\n\nlemmas cspF_step = cspF_STOP_step       cspF_Act_prefix_step \n                   cspF_Ext_choice_step cspF_Parallel_step\n                   cspF_Hiding_step     cspF_Renaming_step\n                   cspF_Seq_compo_step  cspF_Depth_rest_step\n\nlemmas cspF_light_step = cspF_STOP_step  cspF_Act_prefix_step \n\n\nlemmas cspF_step_rw = cspF_STOP_step_DIV       cspF_Act_prefix_step \n                   cspF_Ext_choice_step cspF_Parallel_step\n                   cspF_Hiding_step     cspF_Renaming_step\n                   cspF_Seq_compo_step  cspF_Depth_rest_step\n\nlemmas cspF_light_step_rw = cspF_STOP_step_DIV  cspF_Act_prefix_step \n\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/CSP_F/CSP_F_law_step.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5583269796369904, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.26391193782579825}}
{"text": "theory Incredible_Predicate_Tasks\nimports\n  Incredible_Completeness\n  Incredible_Predicate\n  \"~~/src/HOL/Eisbach/Eisbach\"\nbegin\n\ndeclare One_nat_def [simp del]\n\ncontext ND_Rules_Inst begin\nlemma eff_NatRuleI:\n  \"nat_rule rule c ants\n    \\<Longrightarrow> entail = (\\<Gamma> \\<turnstile> subst s (freshen a c))\n    \\<Longrightarrow> hyps = ((\\<lambda>ant. ((\\<lambda>p. subst s (freshen a p)) |`| a_hyps ant |\\<union>| \\<Gamma> \\<turnstile> subst s (freshen a (a_conc ant)))) |`| ants)\n    \\<Longrightarrow> (\\<And> ant f. ant |\\<in>| ants \\<Longrightarrow> f |\\<in>| \\<Gamma> \\<Longrightarrow> freshenLC a ` (a_fresh ant) \\<inter> lconsts f = {})\n    \\<Longrightarrow> (\\<And> ant. ant |\\<in>| ants \\<Longrightarrow> freshenLC a ` (a_fresh ant) \\<inter> subst_lconsts s = {})\n    \\<Longrightarrow> eff (NatRule rule) entail hyps\"\n  by (drule eff.intros(2)) simp_all\nend\n\ncontext Abstract_Task begin\nlemma  natEff_InstI:\n  \"rule = (r,c)\n  \\<Longrightarrow> c \\<in> set (consequent r)\n  \\<Longrightarrow> antec = f_antecedent r\n  \\<Longrightarrow> natEff_Inst rule c antec\"\n  by (metis natEff_Inst.intros)\nend\n\ncontext begin\n\ntext \\<open>A typical task with local constants:: @{text \"\\<forall>x. Q x \\<longrightarrow> Q x\"}\\<close>\n\ntext \\<open>First the task is defined as an @{term Abstract_Task}.\\<close>\n\ninterpretation task: Abstract_Task\n  \"curry to_nat :: nat \\<Rightarrow> var \\<Rightarrow> var\"\n  map_lc\n  lc\n  \"closed\"\n  subst\n  lc_subst\n  map_lc_subst\n  \"Var 0 []\"\n  antecedent\n  consequent\n  prop_rules\n  \"[]\"\n  \"[ForallX (imp (Q x) (Q x))]\"\nby unfold_locales auto\n\ntext \\<open>Then we show, that this task has a proof within our formalization of natural deduction\n  by giving a concrete proof tree.\\<close>\n\nabbreviation lx :: \"nat\" where \"lx \\<equiv> to_nat (1::nat,0::nat)\"\n\nabbreviation base_tree :: \"((form fset \\<times> form) \\<times> (prop_rule \\<times> form) NatRule) tree\" where\n  \"base_tree \\<equiv> Node ({|Q (LC lx)|} \\<turnstile> Q (LC lx), Axiom) {||}\"\n\nabbreviation imp_tree :: \"((form fset \\<times> form) \\<times> (prop_rule \\<times> form) NatRule) tree\" where\n  \"imp_tree \\<equiv> Node ({||} \\<turnstile> imp (Q (LC lx)) (Q (LC lx)), NatRule (impI, imp X Y)) {|base_tree|}\"\n\nabbreviation solution_tree :: \"((form fset \\<times> form) \\<times> (prop_rule \\<times> form) NatRule) tree\" where\n  \"solution_tree \\<equiv> Node ({||} \\<turnstile> ForallX (imp (Q x) (Q x)), NatRule (allI, ForallX (P x))) {|imp_tree|}\"\n\nabbreviation s1 where \"s1 \\<equiv> [(12, ([9], imp (Q x) (Q x)))] \"\nabbreviation s2 where \"s2 \\<equiv> [(10, ([], Q (LC lx))), (11, ([], Q (LC lx)))] \"\n\nlemma fv_subst_s1[simp]: \"fv_subst s1 = {}\"\n  by (simp add: fv_subst_def)\n\nlemma subst1_simps[simp]:\n  \"subst s1 (P (LC n)) = imp (Q (LC n)) (Q (LC n))\"\n  \"subst s1 (ForallX (P x)) = ForallX (imp (Q x) (Q x))\"\n  by simp_all\n\nlemma subst2_simps[simp]:\n    \"subst s2 X = Q (LC lx)\" \n    \"subst s2 Y = Q (LC lx)\"\n    \"subst s2 (imp X Y) = imp (subst s2 X) (subst s2 Y)\"\n  by simp_all\n\nlemma substI1: \"ForallX (imp (Q x) (Q x)) = subst s1 (predicate.freshen 1 (ForallX (P x)))\"\n  by (auto simp add: predicate.freshen_def Let_def)\n\nlemma substI2: \"imp (Q (LC lx)) (Q (LC lx)) = subst s2 (predicate.freshen 2 (imp X Y))\"\n  by (auto simp add: predicate.freshen_def Let_def)\n\ndeclare subst.simps[simp del]\n\nlemma \"task.solved\"\n  unfolding task.solved_def\napply clarsimp\napply (rule_tac x=\"{||}\" in exI)\napply clarsimp\napply (rule_tac x=\"solution_tree\" in exI)\napply clarsimp\napply (rule conjI)\n\n apply (rule task.wf)\n   apply (solves \\<open>(auto simp add: stream.set_map task.n_rules_def)[1]\\<close>)\n  apply clarsimp\n  apply (rule task.eff_NatRuleI)\n      apply (solves \\<open>rule task.natEff_Inst.intros;simp\\<close>)\n     apply clarsimp     \n     apply (rule conjI)\n      apply (solves \\<open>simp\\<close>)\n     apply (solves \\<open>rule substI1\\<close>)\n    apply (simp add: predicate.f_antecedent_def predicate.freshen_def)\n    apply (subst antecedent.sel(2))\n    apply (solves \\<open>simp\\<close>)\n   apply (solves \\<open>simp\\<close>)\n  apply (solves \\<open>simp\\<close>)\n apply simp\n\n apply (rule task.wf)\n   apply (solves \\<open>(auto simp add: stream.set_map task.n_rules_def)[1]\\<close>)\n  apply clarsimp\n  apply (rule task.eff_NatRuleI)\n      apply (solves \\<open>rule task.natEff_Inst.intros; simp\\<close>)\n     apply clarsimp     \n     apply (rule conjI)\n      apply (solves \\<open>simp\\<close>)\n     apply (solves \\<open>rule substI2\\<close>)\n    apply (solves \\<open>simp add: predicate.f_antecedent_def predicate.freshen_def\\<close>)\n   apply (solves \\<open>simp\\<close>)\n  apply (solves \\<open>simp add: predicate.f_antecedent_def\\<close>)\n apply simp\n\n apply (solves \\<open>(auto intro: task.wf intro!: task.eff.intros(1))[1]\\<close>)\napply (solves \\<open>(rule tfinite.intros, simp)+\\<close>)\ndone\n\nabbreviation vertices where \"vertices \\<equiv> {|0::nat,1,2 |}\"\nfun nodeOf  where \n    \"nodeOf n = [Conclusion (ForallX (imp (Q x) (Q x))), \n                 Rule allI, \n                 Rule impI] ! n \"\n\nfun inst  where \n    \"inst n = [[],s1,s2] ! n\"\n\n\ninterpretation task: Vertex_Graph task.nodes task.inPorts task.outPorts vertices nodeOf.\n\nabbreviation e1 :: \"(nat, form, nat) edge'\"\n  where \"e1 \\<equiv> ((1,Reg (ForallX (P x))), (0,plain_ant (ForallX (imp (Q x) (Q x)))))\"\nabbreviation e2  :: \"(nat, form, nat) edge'\"\n  where \"e2 \\<equiv> ((2,Reg (imp X Y)), (1,allI_input))\"\nabbreviation e3  :: \"(nat, form, nat) edge'\"\n  where \"e3 \\<equiv> ((2,Hyp X (impI_input)), (2,impI_input))\"\nabbreviation task_edges :: \"(nat, form, nat) edge' set\" where \"task_edges \\<equiv> {e1, e2, e3}\"\n\n\ninterpretation task: Scoped_Graph task.nodes task.inPorts task.outPorts vertices nodeOf task_edges task.hyps\n  by standard (auto simp add: predicate.f_consequent_def predicate.f_antecedent_def)\n\ninterpretation task: Instantiation\n  task.inPorts\n  task.outPorts\n  nodeOf\n  task.hyps\n  task.nodes\n  task_edges\n  vertices\n  task.labelsIn\n  task.labelsOut\n  \"curry to_nat :: nat \\<Rightarrow> var \\<Rightarrow> var\"\n  map_lc\n  lc\n  \"closed\"\n  subst\n  lc_subst\n  map_lc_subst\n  \"Var 0 []\"\n  \"id\"\n  \"inst\"\nby unfold_locales simp\n\ntext \\<open>Finally we can also show that there is a proof graph for this task.\\<close>\n\ninterpretation Well_Scoped_Graph\n  task.nodes\n  task.inPorts\n  task.outPorts\n  vertices\n  nodeOf\n  task_edges\n  task.hyps\nby standard (auto split: if_splits)\n\nlemma no_path_01[simp]: \"task.path 0 v pth \\<longleftrightarrow> (pth = [] \\<and> v = 0)\"\n  by (cases pth) (auto simp add: task.path_cons_simp)\nlemma no_path_12[simp]: \"\\<not> task.path 1 2 pth\"\n  by (cases pth) (auto simp add: task.path_cons_simp)\n\ninterpretation Acyclic_Graph\n  task.nodes\n  task.inPorts\n  task.outPorts\n  vertices\n  nodeOf\n  task_edges\n  task.hyps\nproof\n  fix v pth \n  assume \"task.path v v pth\" and \"task.hyps_free pth\"\n  thus \"pth = []\"\n    by (cases pth) (auto simp add: task.path_cons_simp predicate.f_antecedent_def)\nqed\n\ninterpretation Saturated_Graph\n  task.nodes\n  task.inPorts\n  task.outPorts\n  vertices\n  nodeOf\n  task_edges\nby standard\n   (auto simp add: predicate.f_consequent_def predicate.f_antecedent_def) \n\ninterpretation Pruned_Port_Graph\n  task.nodes\n  task.inPorts\n  task.outPorts\n  vertices\n  nodeOf\n  task_edges\nproof\n  fix v\n  assume \"v |\\<in>| vertices\"\n  hence \"\\<exists> pth. task.path v 0 pth\"\n    apply auto\n    apply (rule exI[where x = \"[e1]\"], auto simp add: task.path_cons_simp)\n    apply (rule exI[where x = \"[e2,e1]\"], auto simp add: task.path_cons_simp)\n    done\n  moreover\n  have \"task.terminal_vertex 0\" by auto\n  ultimately\n  show \"\\<exists>pth v'. task.path v v' pth \\<and> task.terminal_vertex v'\" by blast\nqed\n\ninterpretation Well_Shaped_Graph\n  task.nodes\n  task.inPorts\n  task.outPorts\n  vertices\n  nodeOf task_edges\n  task.hyps\n..\n\ninterpretation Solution\n  task.inPorts\n  task.outPorts\n  nodeOf\n  task.hyps\n  task.nodes\n  vertices\n  task.labelsIn\n  task.labelsOut\n  \"curry to_nat :: nat \\<Rightarrow> var \\<Rightarrow> var\"\n  map_lc\n  lc\n  \"closed\"\n  subst\n  lc_subst\n  map_lc_subst\n  \"Var 0 []\"\n  id\n  inst\n  task_edges\nby standard\n   (auto simp add: task.labelAtOut_def task.labelAtIn_def predicate.freshen_def, subst antecedent.sel, simp)\n\ninterpretation Proof_Graph\n  task.nodes\n  task.inPorts\n  task.outPorts\n  vertices\n  nodeOf\n  task_edges\n  task.hyps\n  task.labelsIn\n  task.labelsOut\n  \"curry to_nat :: nat \\<Rightarrow> var \\<Rightarrow> var\"\n  map_lc\n  lc\n  \"closed\"\n  subst\n  lc_subst\n  map_lc_subst\n  \"Var 0 []\"\n  id\n  inst\n..\n\nlemma path_20:\n  assumes \"task.path 2 0 pth\"\n  shows \"(1, allI_input) \\<in> snd ` set pth\"\nproof-\n  { fix v\n    assume \"task.path v 0 pth\"\n    hence \"v = 0 \\<or> v = 1 \\<or> (1, allI_input) \\<in> snd ` set pth\"\n    by (induction v \"0::nat\" pth rule: task.path.induct) auto\n  }\n  from this[OF assms]\n  show ?thesis by auto\nqed\n\nlemma scope_21: \"2 \\<in> task.scope (1, allI_input)\"\n  by (auto intro!: task.scope.intros elim: path_20 simp add: task.outPortsRule_def predicate.f_antecedent_def predicate.f_consequent_def)\n\ninterpretation Scoped_Proof_Graph\n  \"curry to_nat :: nat \\<Rightarrow> var \\<Rightarrow> var\"\n  map_lc\n  lc\n  \"closed\"\n  subst\n  lc_subst\n  map_lc_subst\n  \"Var 0 []\"\n  task.inPorts\n  task.outPorts\n  nodeOf\n  task.hyps\n  task.nodes\n  vertices\n  task.labelsIn\n  task.labelsOut\n  id\n  inst\n  task_edges\n  task.local_vars\nby standard (auto simp add: predicate.f_antecedent_def scope_21)\n\ninterpretation Tasked_Proof_Graph\n  \"curry to_nat :: nat \\<Rightarrow> var \\<Rightarrow> var\"\n  map_lc\n  lc\n  \"closed\"\n  subst\n  lc_subst\n  map_lc_subst\n  \"Var 0 []\"\n  antecedent\n  consequent\n  prop_rules\n  \"[]\"\n  \"[ForallX (imp (Q x) (Q x))]\"\n  vertices\n  nodeOf\n  task_edges\n  id\n  inst\nby unfold_locales auto\n\nend\n\nend", "meta": {"author": "nomeata", "repo": "isa-incredible", "sha": "10eb1d938879778196cc69bf86b1ed0d979512cc", "save_path": "github-repos/isabelle/nomeata-isa-incredible", "path": "github-repos/isabelle/nomeata-isa-incredible/isa-incredible-10eb1d938879778196cc69bf86b1ed0d979512cc/Incredible_Predicate_Tasks.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5117166047041654, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.2638512725916295}}
{"text": "(* \n   Title: Psi-calculi   \n   Based on the AFP entry by Jesper Bengtson (jebe@itu.dk), 2012\n*)\ntheory Weak_Sim_Pres\n  imports Sim_Pres Weak_Simulation Weak_Stat_Imp\nbegin\n\ncontext env begin\n\nlemma weak_inputPres:\n  fixes \\<Psi>    :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   Rel  :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   xvec :: \"name list\"\n  and   N    :: 'a\n\n  assumes PRelQ: \"\\<And>Tvec \\<Psi>'. length xvec = length Tvec \\<Longrightarrow> (\\<Psi> \\<otimes> \\<Psi>', P[xvec::=Tvec], Q[xvec::=Tvec]) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.P \\<leadsto><Rel> M\\<lparr>\\<lambda>*xvec N\\<rparr>.Q\"\nproof(induct rule: weakSimI2)\n  case(c_act \\<Psi>' \\<alpha> \\<pi> Q')\n  from `\\<Psi> \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> Q'` show ?case\n  proof(induct rule: input_cases)\n    case(c_input K Tvec)\n    from `\\<Psi> \\<turnstile> K \\<leftrightarrow> M` `set xvec \\<subseteq> supp N` `length xvec = length Tvec` `distinct xvec`\n    have \"\\<Psi> : (M\\<lparr>\\<lambda>*xvec N\\<rparr>.Q) \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.P \\<Longrightarrow>Some(\\<langle>\\<epsilon>; \\<epsilon>, M\\<rangle>) @ K\\<lparr>(N[xvec::=Tvec])\\<rparr> \\<prec> (P[xvec::=Tvec])\"\n      by(rule_tac weak_input) auto\n    moreover have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P[xvec::=Tvec] \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau>  P[xvec::=Tvec]\" by simp\n    moreover from `length xvec = length Tvec` have \"(\\<Psi> \\<otimes> \\<Psi>',  P[xvec::=Tvec], Q[xvec::=Tvec]) \\<in> Rel\"\n      by(rule PRelQ)\n    ultimately show ?case by blast\n  qed\nnext\n  case(c_tau Q')\n  from `\\<Psi> \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.Q \\<longmapsto>None @ \\<tau> \\<prec> Q'` have False by auto\n  thus ?case by simp\nqed\n\nlemma weak_outputPres:\n  fixes \\<Psi>    :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   Rel  :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   N    :: 'a\n\n  assumes PRelQ: \"\\<And>\\<Psi>'. (\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> M\\<langle>N\\<rangle>.P \\<leadsto><Rel> M\\<langle>N\\<rangle>.Q\"\nproof(induct rule: weakSimI2)\n  case(c_act \\<Psi>' \\<alpha> \\<pi> Q')\n  from `\\<Psi> \\<rhd> M\\<langle>N\\<rangle>.Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> Q'` show ?case\n  proof(induct rule: output_cases)\n    case(c_output K)\n    from `\\<Psi> \\<turnstile> M \\<leftrightarrow> K` \n    have \"\\<Psi> : (M\\<langle>N\\<rangle>.Q) \\<rhd> M\\<langle>N\\<rangle>.P \\<Longrightarrow>Some(\\<langle>\\<epsilon>; \\<epsilon>, M\\<rangle>) @ K\\<langle>N\\<rangle> \\<prec> P\" by(rule weak_output) auto\n    moreover have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau>  P\" by simp\n    moreover have \"(\\<Psi> \\<otimes> \\<Psi>',  P, Q) \\<in> Rel\" by(rule PRelQ)\n    ultimately show ?case by blast\n  qed\nnext\n  case(c_tau Q')\n  from  `\\<Psi> \\<rhd> M\\<langle>N\\<rangle>.Q \\<longmapsto>None @ \\<tau> \\<prec> Q'` have False by auto\n  thus ?case by simp\nqed\n\nlemma res_tau_cases[consumes 3, case_names c_res]:\n  fixes \\<Psi>    :: 'b\n  and   x    :: name\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   C    :: \"'d::fs_name\"\n\n  assumes Trans: \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<longmapsto>None @ \\<tau> \\<prec> P'\"\n  and     \"x \\<sharp> \\<Psi>\"\n  and     \"x \\<sharp> P'\"\n  and     rScope:  \"\\<And>P'. \\<lbrakk>\\<Psi> \\<rhd> P \\<longmapsto>None @ \\<tau> \\<prec> P'\\<rbrakk> \\<Longrightarrow> Prop (\\<lparr>\\<nu>x\\<rparr>P')\"\n\n  shows \"Prop P'\"\nproof -\n  note Trans `x \\<sharp> \\<Psi>`\n  moreover have \"x \\<sharp> (\\<tau>)\" by simp\n  moreover note `x \\<sharp> P'`\n  moreover have \"bn(\\<tau>) \\<sharp>* \\<Psi>\" and \"bn(\\<tau>) \\<sharp>* P\" and \"bn(\\<tau>) \\<sharp>* subject(\\<tau>)\" and \"bn(\\<tau>) = []\" by simp+\n  ultimately show ?thesis\n    by(induct rule: res_cases) (auto intro: rScope dest: tau_no_provenance')\nqed\n\nthm output_provenance\n\nlemma weak_output_provenance_Some:\n  assumes \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<pi> @ M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P''\"\n  shows \"\\<exists>\\<pi>'. \\<pi> = Some \\<pi>'\"\n  using assms\n  by(auto elim!: weak_transitionE dest!: output_provenance\n          simp add: residual_inject)\n\nlemma weakResPres:\n  fixes \\<Psi>    :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   Rel  :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   x    :: name\n  and   Rel' :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n\n  assumes PSimQ: \"\\<Psi> \\<rhd> P \\<leadsto><Rel> Q\"\n  and     \"eqvt Rel'\"\n  and     \"x \\<sharp> \\<Psi>\"\n  and     \"Rel \\<subseteq> Rel'\"\n  and     C1: \"\\<And>\\<Psi>' R S y. \\<lbrakk>(\\<Psi>', R, S) \\<in> Rel; y \\<sharp> \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', \\<lparr>\\<nu>y\\<rparr>R, \\<lparr>\\<nu>y\\<rparr>S) \\<in> Rel'\"\n\n  shows   \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<leadsto><Rel'> \\<lparr>\\<nu>x\\<rparr>Q\"\nproof -\n  note `eqvt Rel'` `x \\<sharp> \\<Psi>`\n  moreover have \"x \\<sharp> \\<lparr>\\<nu>x\\<rparr>P\" and \"x \\<sharp> \\<lparr>\\<nu>x\\<rparr>Q\" by(simp add: abs_fresh)+ \n  ultimately show ?thesis\n  proof(induct rule: weakSimIFresh[of _ _ _ _ _ \"()\"])\n    case(c_act \\<alpha> \\<pi> Q' \\<Psi>')\n    from `bn \\<alpha> \\<sharp>* \\<lparr>\\<nu>x\\<rparr>P` `bn \\<alpha> \\<sharp>* \\<lparr>\\<nu>x\\<rparr>Q` `x \\<sharp> \\<alpha>` have \"bn \\<alpha> \\<sharp>* P\" and \"bn \\<alpha> \\<sharp>* Q\" by simp+\n    from `\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> Q'` `x \\<sharp> \\<Psi>` `x \\<sharp> \\<alpha>` `x \\<sharp> Q'` `bn \\<alpha> \\<sharp>* \\<Psi>` `bn \\<alpha> \\<sharp>* Q` `bn \\<alpha> \\<sharp>* subject \\<alpha>` `bn \\<alpha> \\<sharp>* P` `x \\<sharp> \\<alpha>`\n    show ?case\n    proof(induct rule: res_cases)\n      case(c_open M \\<pi> xvec1 xvec2 y N Q')\n      from `bn(M\\<lparr>\\<nu>*(xvec1@y#xvec2)\\<rparr>\\<langle>N\\<rangle>) \\<sharp>* P` have \"xvec1 \\<sharp>* P\" and \"xvec2 \\<sharp>* P\" and \"y \\<sharp> P\" by simp+\n      from `x \\<sharp> (M\\<lparr>\\<nu>*(xvec1@y#xvec2)\\<rparr>\\<langle>N\\<rangle>)` have \"x \\<sharp> xvec1\" and \"x \\<noteq> y\" and \"x \\<sharp> xvec2\" and \"x \\<sharp> M\" by simp+\n      from PSimQ `\\<Psi> \\<rhd> Q \\<longmapsto>Some \\<pi> @ M\\<lparr>\\<nu>*(xvec1@xvec2)\\<rparr>\\<langle>([(x, y)] \\<bullet> N)\\<rangle> \\<prec> ([(x, y)] \\<bullet> Q')` `xvec1 \\<sharp>* \\<Psi>` `xvec2 \\<sharp>* \\<Psi>` `xvec1 \\<sharp>* P` `xvec2 \\<sharp>* P` `\\<alpha> \\<noteq> \\<tau>`\n      obtain P'' P' \\<pi>' where PTrans: \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<pi>' @ M\\<lparr>\\<nu>*(xvec1@xvec2)\\<rparr>\\<langle>([(x, y)] \\<bullet> N)\\<rangle> \\<prec> P''\"\n                      and P''Chain: \"\\<Psi> \\<otimes> ([(x, y)] \\<bullet> \\<Psi>') \\<rhd> P'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" and P'RelQ': \"(\\<Psi> \\<otimes> ([(x, y)] \\<bullet> \\<Psi>'), P', ([(x, y)] \\<bullet> Q')) \\<in> Rel\"\n        by (fastforce dest: weakSimE)\n      from PTrans obtain \\<pi>'' where \\<pi>': \"\\<pi>' = Some \\<pi>''\"\n        by(blast dest: weak_output_provenance_Some)\n      from PTrans have \"([(x, y)] \\<bullet> \\<Psi>) : ([(x, y)] \\<bullet> Q) \\<rhd> ([(x, y)] \\<bullet> P) \\<Longrightarrow>([(x, y)] \\<bullet> \\<pi>') @ ([(x, y)] \\<bullet> (M\\<lparr>\\<nu>*(xvec1@xvec2)\\<rparr>\\<langle>([(x, y)] \\<bullet> N)\\<rangle>)) \\<prec> ([(x, y)] \\<bullet> P'')\"\n        by(rule eqvts)\n      with `x \\<sharp> \\<Psi>` `y \\<sharp> \\<Psi>` `x \\<sharp> M` `y \\<sharp> M` `x \\<sharp> xvec1` `y \\<sharp> xvec1` `x \\<sharp> xvec2` `y \\<sharp> xvec2`\n      have \"\\<Psi> : ([(x, y)] \\<bullet> Q) \\<rhd> ([(x, y)] \\<bullet> P) \\<Longrightarrow>Some([(x, y)] \\<bullet> \\<pi>'') @ M\\<lparr>\\<nu>*(xvec1@xvec2)\\<rparr>\\<langle>N\\<rangle> \\<prec> ([(x, y)] \\<bullet> P'')\"\n        by(simp add: eqvts \\<pi>')\n      hence \"\\<Psi> : \\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> Q) \\<rhd> \\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> P) \\<Longrightarrow>Some(\\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> \\<pi>'')) @ M\\<lparr>\\<nu>*(xvec1@y#xvec2)\\<rparr>\\<langle>N\\<rangle> \\<prec> ([(x, y)] \\<bullet> P'')\"\n        using `y \\<in> supp N` `y \\<sharp> \\<Psi>` `y \\<sharp> M` `y \\<sharp> xvec1` `y \\<sharp> xvec2`\n        by(rule weak_open)\n      with `y \\<sharp> P` `y \\<sharp> Q` have \"\\<Psi> : \\<lparr>\\<nu>x\\<rparr>Q \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<Longrightarrow>Some(\\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> \\<pi>'')) @ M\\<lparr>\\<nu>*(xvec1@y#xvec2)\\<rparr>\\<langle>N\\<rangle> \\<prec> ([(x, y)] \\<bullet> P'')\"\n        by(simp add: alpha_res)\n      moreover from P''Chain have \"([(x, y)] \\<bullet> (\\<Psi> \\<otimes> ([(x, y)] \\<bullet> \\<Psi>'))) \\<rhd> ([(x, y)] \\<bullet> P'') \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> ([(x, y)] \\<bullet> P')\"\n        by(rule eqvts)\n      with `x \\<sharp> \\<Psi>` `y \\<sharp> \\<Psi>` have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> ([(x, y)] \\<bullet> P'') \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> ([(x, y)] \\<bullet> P')\" by(simp add: eqvts)\n      moreover from P'RelQ' `Rel \\<subseteq> Rel'` have \"(\\<Psi> \\<otimes> ([(x, y)] \\<bullet> \\<Psi>'), P', ([(x, y)] \\<bullet> Q')) \\<in> Rel'\" by auto\n      with `eqvt Rel'` have \"([(x, y)] \\<bullet> (\\<Psi> \\<otimes> ([(x, y)] \\<bullet> \\<Psi>'), P', ([(x, y)] \\<bullet> Q'))) \\<in> Rel'\" by(rule eqvtI)\n      with `x \\<sharp> \\<Psi>` `y \\<sharp> \\<Psi>` have \" (\\<Psi> \\<otimes> \\<Psi>', [(x, y)] \\<bullet> P', Q') \\<in> Rel'\" by(simp add: eqvts)\n      ultimately show ?case by blast\n    next\n      case(c_res \\<pi> Q')\n      from PSimQ `\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> Q'` `bn \\<alpha> \\<sharp>* \\<Psi>` `bn \\<alpha> \\<sharp>* P` `\\<alpha> \\<noteq> \\<tau>`\n      obtain P'' P' \\<pi>' where PTrans: \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<pi>' @ \\<alpha> \\<prec> P''\"\n                      and P''Chain: \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" and P'RelQ': \"(\\<Psi> \\<otimes> \\<Psi>', P', Q') \\<in> Rel\"\n        by(blast dest: weakSimE)\n      from PTrans `x \\<sharp> \\<Psi>` `x \\<sharp> \\<alpha>`  have \"\\<Psi> : \\<lparr>\\<nu>x\\<rparr>Q \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<Longrightarrow>map_option (F_res x) \\<pi>' @ \\<alpha> \\<prec> \\<lparr>\\<nu>x\\<rparr>P''\"\n        by(rule_tac weak_scope)\n      moreover from P''Chain  `x \\<sharp> \\<Psi>` `x \\<sharp> \\<Psi>'` have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> \\<lparr>\\<nu>x\\<rparr>P'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>x\\<rparr>P'\"\n        by(rule_tac tau_chain_res_pres) auto\n      moreover from P'RelQ' `x \\<sharp> \\<Psi>` `x \\<sharp> \\<Psi>'` have \"(\\<Psi> \\<otimes> \\<Psi>', \\<lparr>\\<nu>x\\<rparr>P', \\<lparr>\\<nu>x\\<rparr>Q') \\<in> Rel'\" \n        apply(rule_tac C1) by(auto simp add: fresh_left calc_atm)\n      ultimately show ?case by blast\n    qed\n  next\n    case(c_tau Q')\n    from `\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>Q \\<longmapsto>None @ \\<tau> \\<prec> Q'` `x \\<sharp> \\<Psi>` `x \\<sharp> Q'`\n    show ?case\n    proof(induct rule: res_tau_cases)\n      case(c_res Q')\n      from PSimQ `\\<Psi> \\<rhd> Q \\<longmapsto>None @ \\<tau> \\<prec> Q'` obtain P' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" and P'RelQ': \"(\\<Psi>, P', Q') \\<in> Rel\" \n        by(blast dest: weakSimE)\n      from PChain `x \\<sharp> \\<Psi>` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>x\\<rparr>P'\" by(rule tau_chain_res_pres)\n      moreover from P'RelQ' `x \\<sharp> \\<Psi>` have \"(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>P', \\<lparr>\\<nu>x\\<rparr>Q') \\<in> Rel'\" by(rule C1)\n      ultimately show ?case by blast\n    qed\n  qed\nqed\n\nlemma weakResChainPres:\n  fixes \\<Psi>    :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   Rel  :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   xvec :: \"name list\"\n\n  assumes PSimQ: \"\\<Psi> \\<rhd> P \\<leadsto><Rel> Q\"\n  and     \"eqvt Rel\"\n  and     \"xvec \\<sharp>* \\<Psi>\"\n  and     C1:    \"\\<And>\\<Psi>' R S yvec. \\<lbrakk>(\\<Psi>', R, S) \\<in> Rel; yvec \\<sharp>* \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', \\<lparr>\\<nu>*yvec\\<rparr>R, \\<lparr>\\<nu>*yvec\\<rparr>S) \\<in> Rel\"\n\n  shows   \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>P \\<leadsto><Rel> \\<lparr>\\<nu>*xvec\\<rparr>Q\"\nusing `xvec \\<sharp>* \\<Psi>`\nproof(induct xvec)\n  case Nil\n  from PSimQ show ?case by simp\nnext\n  case(Cons x xvec)\n  from `(x#xvec) \\<sharp>* \\<Psi>` have \"x \\<sharp> \\<Psi>\" and \"xvec \\<sharp>* \\<Psi>\" by simp+\n  from `xvec \\<sharp>* \\<Psi> \\<Longrightarrow> \\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>P \\<leadsto><Rel> \\<lparr>\\<nu>*xvec\\<rparr>Q` `xvec \\<sharp>* \\<Psi>`\n  have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>P \\<leadsto><Rel> \\<lparr>\\<nu>*xvec\\<rparr>Q\" by simp\n  moreover note `eqvt Rel` `x \\<sharp> \\<Psi>`\n  moreover have \"Rel \\<subseteq> Rel\" by simp\n  moreover have \"\\<And>\\<Psi> P Q x. \\<lbrakk>(\\<Psi>, P, Q) \\<in> Rel; x \\<sharp> \\<Psi>\\<rbrakk> \\<Longrightarrow> (\\<Psi>, \\<lparr>\\<nu>*[x]\\<rparr>P, \\<lparr>\\<nu>*[x]\\<rparr>Q) \\<in> Rel\"\n    by(rule_tac yvec=\"[x]\" in C1) auto\n  hence \"\\<And>\\<Psi> P Q x. \\<lbrakk>(\\<Psi>, P, Q) \\<in> Rel; x \\<sharp> \\<Psi>\\<rbrakk> \\<Longrightarrow> (\\<Psi>, \\<lparr>\\<nu>x\\<rparr>P, \\<lparr>\\<nu>x\\<rparr>Q) \\<in> Rel\"\n    by simp\n  ultimately have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>*xvec\\<rparr>P) \\<leadsto><Rel> \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>*xvec\\<rparr>Q)\"\n    by(rule weakResPres)\n  thus ?case by simp\nqed\n\nlemma parTauCases[consumes 1, case_names c_par1 c_par2 c_comm1 c_comm2]:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   R :: \"('a, 'b, 'c) psi\"\n  and   C :: \"'d::fs_name\"\n\n  assumes Trans: \"\\<Psi> \\<rhd> P \\<parallel> Q \\<longmapsto>None @ \\<tau> \\<prec> R\"\n  and     rPar1: \"\\<And>P' A\\<^sub>Q \\<Psi>\\<^sub>Q. \\<lbrakk>\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<longmapsto>None @ \\<tau> \\<prec> P';  extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>; distinct A\\<^sub>Q;\n                       A\\<^sub>Q \\<sharp>* \\<Psi>; A\\<^sub>Q \\<sharp>* P; A\\<^sub>Q \\<sharp>* Q; A\\<^sub>Q \\<sharp>* C\\<rbrakk> \\<Longrightarrow> Prop (P' \\<parallel> Q)\"\n  and     rPar2: \"\\<And>Q' A\\<^sub>P \\<Psi>\\<^sub>P. \\<lbrakk>\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<longmapsto>None @ \\<tau> \\<prec> Q'; extract_frame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>; distinct A\\<^sub>P;\n                       A\\<^sub>P \\<sharp>* \\<Psi>; A\\<^sub>P \\<sharp>* P;  A\\<^sub>P \\<sharp>* Q; A\\<^sub>P \\<sharp>* C\\<rbrakk> \\<Longrightarrow> Prop (P \\<parallel> Q')\"\n  and     rComm1: \"\\<And>\\<Psi>\\<^sub>Q M N P' A\\<^sub>P \\<Psi>\\<^sub>P K xvec Q' A\\<^sub>Q yvec zvec.\n           \\<lbrakk>\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<longmapsto>Some(\\<langle>A\\<^sub>P; yvec, K\\<rangle>) @ M\\<lparr>N\\<rparr> \\<prec> P'; extract_frame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>; distinct A\\<^sub>P;\n            \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<longmapsto>Some(\\<langle>A\\<^sub>Q; zvec, M\\<rangle>) @ K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'; extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>; distinct A\\<^sub>Q;\n            distinct xvec; distinct yvec; distinct zvec;\n            A\\<^sub>P \\<sharp>* \\<Psi>;  A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q;  A\\<^sub>P \\<sharp>* P;  A\\<^sub>P \\<sharp>* M;  A\\<^sub>P \\<sharp>* N;  A\\<^sub>P \\<sharp>* P';  A\\<^sub>P \\<sharp>* Q;  A\\<^sub>P \\<sharp>* xvec;  A\\<^sub>P \\<sharp>* Q'; A\\<^sub>P \\<sharp>* A\\<^sub>Q;  A\\<^sub>P \\<sharp>* C; \n            A\\<^sub>Q \\<sharp>* \\<Psi>;  A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P; A\\<^sub>Q \\<sharp>* P;  A\\<^sub>Q \\<sharp>* K;  A\\<^sub>Q \\<sharp>* N;  A\\<^sub>Q \\<sharp>* P';  A\\<^sub>Q \\<sharp>* Q;  A\\<^sub>Q \\<sharp>* xvec;  A\\<^sub>Q \\<sharp>* Q'; A\\<^sub>Q \\<sharp>* C; \n            xvec \\<sharp>* \\<Psi>;  xvec \\<sharp>* \\<Psi>\\<^sub>P; xvec \\<sharp>* P;  xvec \\<sharp>* M;  xvec \\<sharp>* K; xvec \\<sharp>* Q;  xvec \\<sharp>* \\<Psi>\\<^sub>Q;  xvec \\<sharp>* C; yvec \\<sharp>* C; zvec \\<sharp>* C;\n            yvec \\<sharp>* \\<Psi>; yvec \\<sharp>* \\<Psi>\\<^sub>P; yvec \\<sharp>* \\<Psi>\\<^sub>Q; yvec \\<sharp>* P; yvec \\<sharp>* M; yvec \\<sharp>* xvec;\n            yvec \\<sharp>* Q; yvec \\<sharp>* A\\<^sub>P; yvec \\<sharp>* A\\<^sub>Q; yvec \\<sharp>* P'; yvec \\<sharp>* Q'; yvec \\<sharp>* zvec;\n            zvec \\<sharp>* \\<Psi>; zvec \\<sharp>* \\<Psi>\\<^sub>P; zvec \\<sharp>* \\<Psi>\\<^sub>Q; zvec \\<sharp>* P; zvec \\<sharp>* K; zvec \\<sharp>* xvec;\n            zvec \\<sharp>* Q; zvec \\<sharp>* A\\<^sub>P; zvec \\<sharp>* A\\<^sub>Q; zvec \\<sharp>* P'; zvec \\<sharp>* Q'\\<rbrakk> \\<Longrightarrow>\n            Prop (\\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> Q'))\"\n  and     rComm2: \"\\<And>\\<Psi>\\<^sub>Q M xvec N P' A\\<^sub>P \\<Psi>\\<^sub>P K Q' A\\<^sub>Q yvec zvec.\n           \\<lbrakk>\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<longmapsto>Some(\\<langle>A\\<^sub>P; yvec, K\\<rangle>) @ M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'; extract_frame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>; distinct A\\<^sub>P;\n            \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<longmapsto>Some(\\<langle>A\\<^sub>Q; zvec, M\\<rangle>) @ K\\<lparr>N\\<rparr> \\<prec> Q'; extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>; distinct A\\<^sub>Q;\n            distinct xvec; distinct yvec; distinct zvec;\n            A\\<^sub>P \\<sharp>* \\<Psi>;  A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q;  A\\<^sub>P \\<sharp>* P;  A\\<^sub>P \\<sharp>* M;  A\\<^sub>P \\<sharp>* N;  A\\<^sub>P \\<sharp>* P';  A\\<^sub>P \\<sharp>* Q;  A\\<^sub>P \\<sharp>* xvec;  A\\<^sub>P \\<sharp>* Q'; A\\<^sub>P \\<sharp>* A\\<^sub>Q;  A\\<^sub>P \\<sharp>* C; \n            A\\<^sub>Q \\<sharp>* \\<Psi>;  A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P; A\\<^sub>Q \\<sharp>* P;  A\\<^sub>Q \\<sharp>* K;  A\\<^sub>Q \\<sharp>* N;  A\\<^sub>Q \\<sharp>* P';  A\\<^sub>Q \\<sharp>* Q;  A\\<^sub>Q \\<sharp>* xvec;  A\\<^sub>Q \\<sharp>* Q'; A\\<^sub>Q \\<sharp>* C; \n            xvec \\<sharp>* \\<Psi>;  xvec \\<sharp>* \\<Psi>\\<^sub>P; xvec \\<sharp>* P;  xvec \\<sharp>* M;  xvec \\<sharp>* K;  xvec \\<sharp>* Q;  xvec \\<sharp>* \\<Psi>\\<^sub>Q;  xvec \\<sharp>* C; yvec \\<sharp>* C; zvec \\<sharp>* C;\n            yvec \\<sharp>* \\<Psi>; yvec \\<sharp>* \\<Psi>\\<^sub>P; yvec \\<sharp>* \\<Psi>\\<^sub>Q; yvec \\<sharp>* P; yvec \\<sharp>* M; yvec \\<sharp>* xvec;\n            yvec \\<sharp>* Q; yvec \\<sharp>* A\\<^sub>P; yvec \\<sharp>* A\\<^sub>Q; yvec \\<sharp>* P'; yvec \\<sharp>* Q'; yvec \\<sharp>* zvec;\n            zvec \\<sharp>* \\<Psi>; zvec \\<sharp>* \\<Psi>\\<^sub>P; zvec \\<sharp>* \\<Psi>\\<^sub>Q; zvec \\<sharp>* P; zvec \\<sharp>* K; zvec \\<sharp>* xvec;\n            zvec \\<sharp>* Q; zvec \\<sharp>* A\\<^sub>P; zvec \\<sharp>* A\\<^sub>Q; zvec \\<sharp>* P'; zvec \\<sharp>* Q'\\<rbrakk> \\<Longrightarrow>\n            Prop (\\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> Q'))\"\n\n  shows \"Prop R\"\nproof -\n  from Trans obtain \\<alpha> where \"\\<Psi> \\<rhd> P \\<parallel> Q \\<longmapsto>None @ \\<alpha> \\<prec> R\" and \"bn \\<alpha> \\<sharp>* \\<Psi>\" and \"bn \\<alpha> \\<sharp>* P\" and \"bn \\<alpha> \\<sharp>* Q\" and \"bn \\<alpha> \\<sharp>* subject \\<alpha>\" and \"\\<alpha> = \\<tau>\" by auto\n  thus ?thesis using rPar1 rPar2 rComm1 rComm2\n    by(induct rule: par_cases[where C=C]) (auto simp add: residual_inject dest: tau_no_provenance'')\nqed\n\nlemma weakParPres:\n  fixes \\<Psi>    :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   Rel  :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   R    :: \"('a, 'b, 'c) psi\"\n  and   Rel' :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  \n  assumes PRelQ: \"\\<And>A\\<^sub>R \\<Psi>\\<^sub>R. \\<lbrakk>extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>; A\\<^sub>R \\<sharp>* \\<Psi>; A\\<^sub>R \\<sharp>* P; A\\<^sub>R \\<sharp>* Q\\<rbrakk> \\<Longrightarrow> (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, P, Q) \\<in> Rel\" \n  and     Eqvt:  \"eqvt Rel\"\n  and     Eqvt': \"eqvt Rel'\"\n\n  and     Sim:    \"\\<And>\\<Psi>' S T. (\\<Psi>', S, T) \\<in> Rel \\<Longrightarrow> \\<Psi>' \\<rhd> S \\<leadsto><Rel> T\"\n  and     Sym:    \"\\<And>\\<Psi>' S T. (\\<Psi>', S, T) \\<in> Rel \\<Longrightarrow> (\\<Psi>', T, S) \\<in> Rel\"\n  and     Ext:    \"\\<And>\\<Psi>' S T \\<Psi>'. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel\\<rbrakk> \\<Longrightarrow> (\\<Psi>' \\<otimes> \\<Psi>'', S, T) \\<in> Rel\"\n  and     StatImp: \"\\<And>\\<Psi>' S T. (\\<Psi>', S, T) \\<in> Rel \\<Longrightarrow> \\<Psi>' \\<rhd> S \\<lessapprox><Rel> T\"\n  and     C1: \"\\<And>\\<Psi>' S T A\\<^sub>U \\<Psi>\\<^sub>U U. \\<lbrakk>(\\<Psi>' \\<otimes> \\<Psi>\\<^sub>U, S, T) \\<in> Rel; extract_frame U = \\<langle>A\\<^sub>U, \\<Psi>\\<^sub>U\\<rangle>; A\\<^sub>U \\<sharp>* \\<Psi>'; A\\<^sub>U \\<sharp>* S; A\\<^sub>U \\<sharp>* T\\<rbrakk> \\<Longrightarrow> (\\<Psi>', S \\<parallel> U, T \\<parallel> U) \\<in> Rel'\"\n  and     C2: \"\\<And>\\<Psi>' S T xvec. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel'; xvec \\<sharp>* \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', \\<lparr>\\<nu>*xvec\\<rparr>S, \\<lparr>\\<nu>*xvec\\<rparr>T) \\<in> Rel'\"\n  and     C3: \"\\<And>\\<Psi>' S T \\<Psi>''. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel; \\<Psi>' \\<simeq> \\<Psi>''\\<rbrakk> \\<Longrightarrow> (\\<Psi>'', S, T) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> P \\<parallel> R \\<leadsto><Rel'> Q \\<parallel> R\"\nproof -\n  from Eqvt' show ?thesis\n  proof(induct rule: weakSimI[where C=\"()\"])\n    case(c_act \\<Psi>' \\<alpha> \\<pi> QR)\n    from `bn \\<alpha> \\<sharp>* (P \\<parallel> R)` `bn \\<alpha> \\<sharp>* (Q \\<parallel> R)`\n    have \"bn \\<alpha> \\<sharp>* P\" and \"bn \\<alpha> \\<sharp>* Q\" and \"bn \\<alpha> \\<sharp>* R\"\n      by simp+\n    from `\\<Psi> \\<rhd> Q \\<parallel> R \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> QR` `bn \\<alpha> \\<sharp>* \\<Psi>` `bn \\<alpha> \\<sharp>* Q`  `bn \\<alpha> \\<sharp>* R` `bn \\<alpha> \\<sharp>* subject \\<alpha>` `\\<alpha> \\<noteq> \\<tau>` show ?case\n    proof(induct rule: par_cases[where C=\"(P, R, \\<Psi>')\"])\n      case(c_par1 Q' \\<pi> A\\<^sub>R \\<Psi>\\<^sub>R)\n      from `A\\<^sub>R \\<sharp>* (P, R, \\<Psi>')` have \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* \\<Psi>'\" by simp+\n      have FrR: \"extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by fact\n      from `A\\<^sub>R \\<sharp>* \\<alpha>` `bn \\<alpha> \\<sharp>* R` FrR\n      have \"bn \\<alpha> \\<sharp>* \\<Psi>\\<^sub>R\" by(drule_tac extract_frame_fresh_chain) auto\n      have QTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> Q'\" by fact\n      from FrR `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* Q` have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<leadsto><Rel> Q\"\n        by(blast intro: PRelQ Sim)\n      then obtain P'' P' \\<pi>' where PTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R : Q \\<rhd> P \\<Longrightarrow>\\<pi>' @ \\<alpha> \\<prec> P''\"\n                           and P''Chain: \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<rhd> P'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" and P'RelQ': \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>', P', Q') \\<in> Rel\"\n        using QTrans `bn \\<alpha> \\<sharp>* \\<Psi>` `bn \\<alpha> \\<sharp>* \\<Psi>\\<^sub>R` `bn \\<alpha> \\<sharp>* P` `bn \\<alpha> \\<sharp>* R` `A\\<^sub>R \\<sharp>* \\<alpha>` `\\<alpha> \\<noteq> \\<tau>`\n        by(drule_tac \\<Psi>'=\\<Psi>' in weakSimE(1)) auto\n\n      from PTrans QTrans `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* Q` `A\\<^sub>R \\<sharp>* \\<alpha>` `bn \\<alpha> \\<sharp>* subject \\<alpha>` `distinct(bn \\<alpha>)` \n      have \"A\\<^sub>R \\<sharp>* P''\" and \"A\\<^sub>R \\<sharp>* Q'\"\n        by(fastforce dest: weak_fresh_chain_derivative free_fresh_chain_derivative)+\n      with P''Chain have \"A\\<^sub>R \\<sharp>* P'\" by(force dest: tau_chain_fresh_chain)\n      \n      from PTrans FrR `bn \\<alpha> \\<sharp>* R` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* \\<alpha>` `A\\<^sub>R \\<sharp>* Q` \n      have \"\\<Psi> : Q \\<parallel> R \\<rhd> P \\<parallel> R \\<Longrightarrow>append_at_end_prov_option \\<pi>' A\\<^sub>R @ \\<alpha> \\<prec> (P'' \\<parallel> R)\"\n        by(rule_tac weak_par1)\n      moreover from P''Chain have \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" \n        by(metis tau_chain_stat_eq Associativity Commutativity Composition)\n      with FrR have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P'' \\<parallel> R \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P' \\<parallel> R\" using `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* \\<Psi>'` `A\\<^sub>R \\<sharp>* P''`\n        by(rule_tac tau_chain_par1) auto\n      \n      moreover from P'RelQ' have \"((\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>R, P', Q') \\<in> Rel\" \n        by(metis C3 composition_sym Associativity Commutativity)\n      hence \"(\\<Psi> \\<otimes> \\<Psi>', P' \\<parallel> R, Q' \\<parallel> R) \\<in> Rel'\" using FrR `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* \\<Psi>'` `A\\<^sub>R \\<sharp>* P'` `A\\<^sub>R \\<sharp>* Q'`\n        by(rule_tac C1) auto\n      ultimately show ?case by blast\n    next\n      case(c_par2 R' \\<pi> A\\<^sub>Q \\<Psi>\\<^sub>Q)\n      from `A\\<^sub>Q \\<sharp>* (P, R, \\<Psi>')` have \"A\\<^sub>Q \\<sharp>* P\" and \"A\\<^sub>Q \\<sharp>* R\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>'\" by simp+\n      obtain A\\<^sub>P \\<Psi>\\<^sub>P where FrP: \"extract_frame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" and \"A\\<^sub>P \\<sharp>* (\\<Psi>, A\\<^sub>Q, \\<Psi>\\<^sub>Q, \\<alpha>, R)\"\n        by(rule fresh_frame)\n      hence \"A\\<^sub>P \\<sharp>* \\<Psi>\" and \"A\\<^sub>P \\<sharp>* A\\<^sub>Q\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q\" and \"A\\<^sub>P \\<sharp>* \\<alpha>\" and \"A\\<^sub>P \\<sharp>* R\"\n        by simp+\n\n      have FrQ: \"extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" by fact\n      from `A\\<^sub>Q \\<sharp>* P` FrP `A\\<^sub>P \\<sharp>* A\\<^sub>Q` have \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P\"\n        by(drule_tac extract_frame_fresh_chain) auto\n\n      from FrP FrQ `bn \\<alpha> \\<sharp>* P` `bn \\<alpha> \\<sharp>* Q` `A\\<^sub>P \\<sharp>* \\<alpha>` `A\\<^sub>Q \\<sharp>* \\<alpha>`\n      have \"bn \\<alpha> \\<sharp>* \\<Psi>\\<^sub>P\" and \"bn \\<alpha> \\<sharp>* \\<Psi>\\<^sub>Q\"\n        by(force dest: extract_frame_fresh_chain)+\n      \n      obtain A\\<^sub>R \\<Psi>\\<^sub>R where FrR: \"extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" and \"A\\<^sub>R \\<sharp>* (\\<Psi>, P, Q, A\\<^sub>Q, A\\<^sub>P, \\<Psi>\\<^sub>Q, \\<Psi>\\<^sub>P, \\<alpha>, R, \\<Psi>')\" \n                      and \"distinct A\\<^sub>R\"\n        by(rule fresh_frame)\n      then have \"A\\<^sub>R \\<sharp>* \\<Psi>\" and \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* Q\" and \"A\\<^sub>R \\<sharp>* A\\<^sub>Q\" and  \"A\\<^sub>R \\<sharp>* A\\<^sub>P\" and  \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q\" and  \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P\"\n            and \"A\\<^sub>R \\<sharp>* \\<alpha>\" and \"A\\<^sub>R \\<sharp>* R\" and \"A\\<^sub>R \\<sharp>* \\<Psi>'\"\n        by simp+\n\n      from `A\\<^sub>Q \\<sharp>* R`  FrR `A\\<^sub>R \\<sharp>* A\\<^sub>Q` have \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R\" by(drule_tac extract_frame_fresh_chain) auto\n      from `A\\<^sub>P \\<sharp>* R` `A\\<^sub>R \\<sharp>* A\\<^sub>P` FrR  have \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R\" by(drule_tac extract_frame_fresh_chain) auto\n\n      moreover from `\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> R'` FrR `distinct A\\<^sub>R` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* Q` `A\\<^sub>R \\<sharp>* R` `A\\<^sub>R \\<sharp>* \\<alpha>` `A\\<^sub>R \\<sharp>* \\<Psi>'`\n                 `bn \\<alpha> \\<sharp>* \\<Psi>` `bn \\<alpha> \\<sharp>* P` `bn \\<alpha> \\<sharp>* Q` `bn \\<alpha> \\<sharp>* R` `bn \\<alpha> \\<sharp>* subject \\<alpha>` `distinct(bn \\<alpha>)`\n      obtain p \\<Psi>'' A\\<^sub>R' \\<Psi>\\<^sub>R' where S: \"set p \\<subseteq> set(bn \\<alpha>) \\<times> set(bn(p \\<bullet> \\<alpha>))\" and \"(p \\<bullet> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>'' \\<simeq> \\<Psi>\\<^sub>R'\"\n                              and FrR': \"extract_frame R' = \\<langle>A\\<^sub>R', \\<Psi>\\<^sub>R'\\<rangle>\"\n                              and \"bn(p \\<bullet> \\<alpha>) \\<sharp>* \\<Psi>\" and \"bn(p \\<bullet> \\<alpha>) \\<sharp>* P\" and \"bn(p \\<bullet> \\<alpha>) \\<sharp>* Q\"\n                              and \"A\\<^sub>R' \\<sharp>* \\<Psi>\" and \"A\\<^sub>R' \\<sharp>* P\" and \"A\\<^sub>R' \\<sharp>* Q\" and \"A\\<^sub>R' \\<sharp>* \\<Psi>'\" and \"distinct_perm p\"\n        by(rule_tac C=\"(\\<Psi>, \\<Psi>', P, Q)\" and C'=\"(\\<Psi>, P, Q)\" in expand_frame) (assumption | simp)+\n\n      from FrR `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* Q`\n      have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, P, Q) \\<in> Rel\" by(rule PRelQ)\n      hence \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, Q, P) \\<in> Rel\" by(rule Sym)\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<lessapprox><Rel> P\" by(rule StatImp)\n      then obtain P' P'' where PChain: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n                           and QimpP': \"insert_assertion(extract_frame Q) (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<hookrightarrow>\\<^sub>F insert_assertion(extract_frame P') (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R)\"\n                          and P'Chain: \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> ((p \\<bullet> \\<Psi>'') \\<otimes> (p \\<bullet> \\<Psi>')) \\<rhd> P' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\"\n                          and P'RelQ: \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> ((p \\<bullet> \\<Psi>'') \\<otimes> (p \\<bullet> \\<Psi>')), Q, P'') \\<in> Rel\"\n        by(rule weak_stat_impE)\n      obtain A\\<^sub>P' \\<Psi>\\<^sub>P' where FrP': \"extract_frame P' = \\<langle>A\\<^sub>P', \\<Psi>\\<^sub>P'\\<rangle>\" and \"A\\<^sub>P' \\<sharp>* \\<Psi>\" and \"A\\<^sub>P' \\<sharp>* \\<Psi>\\<^sub>R\" and \"A\\<^sub>P' \\<sharp>* \\<Psi>\\<^sub>Q\"\n                        and \"A\\<^sub>P' \\<sharp>* A\\<^sub>Q\" and \"A\\<^sub>P' \\<sharp>* R\" and \"A\\<^sub>P' \\<sharp>* A\\<^sub>R\" and \"A\\<^sub>P' \\<sharp>* \\<alpha>\"\n        by(rule_tac C=\"(\\<Psi>, \\<Psi>\\<^sub>R, \\<Psi>\\<^sub>Q, A\\<^sub>Q, R, A\\<^sub>R, \\<alpha>)\" in fresh_frame) auto\n\n      from PChain `A\\<^sub>R \\<sharp>* P` `A\\<^sub>Q \\<sharp>* P` `bn \\<alpha> \\<sharp>* P` have \"A\\<^sub>Q \\<sharp>* P'\" and \"A\\<^sub>R \\<sharp>* P'\" and \"bn \\<alpha> \\<sharp>* P'\"\n        by(force intro: tau_chain_fresh_chain)+\n      from `A\\<^sub>R \\<sharp>* P'` `A\\<^sub>P' \\<sharp>* A\\<^sub>R` `A\\<^sub>Q \\<sharp>* P'` `A\\<^sub>P' \\<sharp>* A\\<^sub>Q` FrP' have \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P'\" and \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P'\"\n        by(force dest: extract_frame_fresh_chain)+\n\n      from PChain FrR `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P` have \"\\<Psi> \\<rhd> P \\<parallel> R \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P' \\<parallel> R\" by(rule tau_chain_par1)\n      moreover have \"insert_assertion (extract_frame(Q \\<parallel> R)) \\<Psi> \\<hookrightarrow>\\<^sub>F insert_assertion(extract_frame(P' \\<parallel> R)) \\<Psi>\"\n      proof -\n        have \"\\<langle>A\\<^sub>Q, \\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle>\"\n          by(metis Associativity Composition Commutativity Assertion_stat_eq_trans Assertion_stat_eq_sym frame_nil_stat_eq frame_res_chain_pres)\n        moreover from QimpP' FrQ FrP' `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>P' \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>P' \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>` \n        have \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P'\\<rangle>\" using fresh_comp_chain by simp\n        moreover have \"\\<langle>A\\<^sub>P', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P'\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P', \\<Psi> \\<otimes> \\<Psi>\\<^sub>P' \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n          by(metis Associativity Composition Commutativity Assertion_stat_eq_trans Assertion_stat_eq_sym frame_nil_stat_eq frame_res_chain_pres)\n        ultimately have \"\\<langle>A\\<^sub>Q, \\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P', \\<Psi> \\<otimes> \\<Psi>\\<^sub>P' \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n          by(rule Frame_stat_eq_imp_compose)\n        hence \"\\<langle>(A\\<^sub>R@A\\<^sub>Q), \\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>(A\\<^sub>R@A\\<^sub>P'), \\<Psi> \\<otimes> \\<Psi>\\<^sub>P' \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n          by(force intro: frame_imp_res_chain_pres simp add: frame_chain_append)\n        with FrQ FrR FrP' `A\\<^sub>R \\<sharp>* A\\<^sub>Q` `A\\<^sub>P' \\<sharp>* A\\<^sub>R` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P'` `A\\<^sub>P' \\<sharp>* \\<Psi>\\<^sub>R` \n                          `A\\<^sub>P' \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* \\<Psi>` \n        show ?thesis\n          by(simp add: frame_chain_append) (metis frame_imp_chain_comm Frame_stat_imp_trans)\n      qed\n      moreover have RTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P' \\<rhd> R \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> R'\"\n      proof -\n        have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> R'\" by fact\n        moreover have \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P') \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n        proof -\n          have \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle>\"\n            by(metis frame_int_associativity Commutativity Frame_stat_eq_trans frame_int_composition_sym Frame_stat_eq_sym)\n          moreover with FrP' FrQ QimpP' `A\\<^sub>P' \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>P' \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R`\n          have \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P'\\<rangle>\" using fresh_comp_chain\n            by simp\n          moreover have \"\\<langle>A\\<^sub>P', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P'\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P') \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n            by(metis frame_int_associativity Commutativity Frame_stat_eq_trans frame_int_composition_sym frame_int_associativity[THEN Frame_stat_eq_sym])\n          ultimately show ?thesis\n            by(rule Frame_stat_eq_imp_compose)\n        qed\n        ultimately show ?thesis\n          using `A\\<^sub>P' \\<sharp>* \\<Psi>` `A\\<^sub>P' \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P'` `A\\<^sub>P' \\<sharp>* R` `A\\<^sub>Q \\<sharp>* R` `A\\<^sub>P' \\<sharp>* \\<alpha>` `A\\<^sub>Q \\<sharp>* \\<alpha>`\n                `A\\<^sub>P' \\<sharp>* A\\<^sub>R` `A\\<^sub>R \\<sharp>* A\\<^sub>Q` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P'` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P'` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P'` FrR `distinct A\\<^sub>R`\n          by(force intro: transfer_frame)\n      qed\n      hence \"\\<Psi> \\<rhd> P' \\<parallel> R \\<longmapsto>append_at_front_prov_option \\<pi> A\\<^sub>P' @ \\<alpha> \\<prec> (P' \\<parallel> R')\" using FrP' `bn \\<alpha> \\<sharp>* P'` `A\\<^sub>P' \\<sharp>* \\<Psi>` `A\\<^sub>P' \\<sharp>* R` `A\\<^sub>P' \\<sharp>* \\<alpha>` `A\\<^sub>P' \\<sharp>* \\<alpha>`\n        by(rule_tac Par2)\n      ultimately have \"\\<Psi> : (Q \\<parallel> R) \\<rhd> P \\<parallel> R \\<Longrightarrow>append_at_front_prov_option \\<pi> A\\<^sub>P' @ \\<alpha> \\<prec> (P' \\<parallel> R')\"\n        by(rule_tac weak_transitionI)\n      moreover from PChain P'Chain `bn \\<alpha> \\<sharp>* P'` `bn(p \\<bullet> \\<alpha>) \\<sharp>* P` `A\\<^sub>R' \\<sharp>* P` \n      have \"bn \\<alpha> \\<sharp>* P''\" and \"bn(p \\<bullet> \\<alpha>) \\<sharp>* P'\" and \"bn(p \\<bullet> \\<alpha>) \\<sharp>* P''\" and \"A\\<^sub>R' \\<sharp>* P'\" and \"A\\<^sub>R' \\<sharp>* P''\" \n        by(metis tau_chain_fresh_chain)+\n      from P'Chain have \"(p \\<bullet> ((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> (p \\<bullet> \\<Psi>'') \\<otimes> (p \\<bullet> \\<Psi>'))) \\<rhd> (p \\<bullet> P') \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> (p \\<bullet> P'')\"\n        by(rule eqvts)\n      with `bn \\<alpha> \\<sharp>* \\<Psi>` `bn(p \\<bullet> \\<alpha>) \\<sharp>* \\<Psi>` `bn \\<alpha> \\<sharp>* P'` `bn(p \\<bullet> \\<alpha>) \\<sharp>* P'` `bn \\<alpha> \\<sharp>* P''` `bn(p \\<bullet> \\<alpha>) \\<sharp>* P''`\n            S `distinct_perm p`\n      have \"(\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> \\<Psi>'' \\<otimes> \\<Psi>' \\<rhd> P' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\"\n        by(simp add: eqvts)\n      hence \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>'' \\<rhd> P' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" \n        by(rule tau_chain_stat_eq) (metis Associativity Commutativity Composition Assertion_stat_eq_trans)\n      with `(p \\<bullet> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>'' \\<simeq> \\<Psi>\\<^sub>R'` have \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>R' \\<rhd> P' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" by(metis tau_chain_stat_eq composition_sym)\n      hence \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P' \\<parallel> R' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'' \\<parallel> R'\" using FrR' `A\\<^sub>R' \\<sharp>* \\<Psi>` `A\\<^sub>R' \\<sharp>* \\<Psi>'` `A\\<^sub>R' \\<sharp>* P'` by(rule_tac tau_chain_par1) auto\n      moreover from P'RelQ have \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> (p \\<bullet> \\<Psi>'') \\<otimes> (p \\<bullet> \\<Psi>'), P'', Q) \\<in> Rel\" by(rule Sym)\n      with `eqvt Rel` have \"(p \\<bullet> ((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> (p \\<bullet> \\<Psi>'') \\<otimes> (p \\<bullet> \\<Psi>'), P'', Q)) \\<in> Rel\" by(rule eqvtI)\n      with `bn \\<alpha> \\<sharp>* \\<Psi>` `bn(p \\<bullet> \\<alpha>) \\<sharp>* \\<Psi>` `bn \\<alpha> \\<sharp>* P''` `bn(p \\<bullet> \\<alpha>) \\<sharp>* P''` `bn \\<alpha> \\<sharp>* Q` `bn(p \\<bullet> \\<alpha>) \\<sharp>* Q` S `distinct_perm p`\n      have \"((\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> \\<Psi>'' \\<otimes> \\<Psi>', P'', Q) \\<in> Rel\" by(simp add: eqvts)\n      with `(p \\<bullet> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>'' \\<simeq> \\<Psi>\\<^sub>R'` have \"((\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>R', P'', Q) \\<in> Rel\" \n        by(rule_tac C3, auto) (metis Associativity Commutativity Composition Assertion_stat_eq_trans)\n      with FrR' `A\\<^sub>R' \\<sharp>* \\<Psi>`  `A\\<^sub>R' \\<sharp>* \\<Psi>'` `A\\<^sub>R' \\<sharp>* P''` `A\\<^sub>R' \\<sharp>* Q` \n      have \"(\\<Psi> \\<otimes> \\<Psi>', P'' \\<parallel> R', Q \\<parallel> R') \\<in> Rel'\" by(rule_tac C1) auto\n      ultimately show ?case by blast\n    next\n      case c_comm1\n      from `\\<tau> \\<noteq> \\<tau>` have False by simp\n      thus ?case by simp\n    next\n      case c_comm2\n      from `\\<tau> \\<noteq> \\<tau>` have False by simp\n      thus ?case by simp\n    qed\n  next\n    case(c_tau QR)\n    from `\\<Psi> \\<rhd> Q \\<parallel> R \\<longmapsto>None @ \\<tau> \\<prec> QR` show ?case\n    proof(induct rule: parTauCases[where C=\"(P, R)\"])\n      case(c_par1 Q' A\\<^sub>R \\<Psi>\\<^sub>R)\n      from `A\\<^sub>R \\<sharp>* (P, R)` have \"A\\<^sub>R \\<sharp>* P\"\n        by simp+\n      have FrR: \" extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by fact\n      with `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* Q` have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<leadsto><Rel> Q\"\n        by(blast intro: PRelQ Sim)\n      moreover have QTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>None @ \\<tau> \\<prec> Q'\" by fact\n      ultimately obtain P' where PChain: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" and P'RelQ': \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, P', Q') \\<in> Rel\"\n        by(force dest: weakSimE)\n      from PChain QTrans `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* Q` have \"A\\<^sub>R \\<sharp>* P'\" and \"A\\<^sub>R \\<sharp>* Q'\"\n        by(force dest: free_fresh_chain_derivative tau_chain_fresh_chain)+\n      from PChain FrR `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P` have \"\\<Psi> \\<rhd> P \\<parallel> R \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> (P' \\<parallel> R)\"\n        by(rule tau_chain_par1)\n      moreover from P'RelQ' FrR `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P'` `A\\<^sub>R \\<sharp>* Q'` have \"(\\<Psi>, P' \\<parallel> R, Q' \\<parallel> R) \\<in> Rel'\" by(rule C1)\n      ultimately show ?case by blast\n    next\n      case(c_par2 R' A\\<^sub>Q \\<Psi>\\<^sub>Q)\n      from `A\\<^sub>Q \\<sharp>* (P, R)` have \"A\\<^sub>Q \\<sharp>* P\" and \"A\\<^sub>Q \\<sharp>* R\" by simp+\n      obtain A\\<^sub>P \\<Psi>\\<^sub>P where FrP: \"extract_frame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" and \"A\\<^sub>P \\<sharp>* (\\<Psi>, A\\<^sub>Q, \\<Psi>\\<^sub>Q, R)\"\n        by(rule fresh_frame)\n      hence \"A\\<^sub>P \\<sharp>* \\<Psi>\" and \"A\\<^sub>P \\<sharp>* A\\<^sub>Q\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q\" and \"A\\<^sub>P \\<sharp>* R\"\n        by simp+\n      \n      have FrQ: \"extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" by fact\n      from `A\\<^sub>Q \\<sharp>* P` FrP `A\\<^sub>P \\<sharp>* A\\<^sub>Q` have \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P\"\n        by(drule_tac extract_frame_fresh_chain) auto\n      \n      obtain A\\<^sub>R \\<Psi>\\<^sub>R where FrR: \"extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" and \"A\\<^sub>R \\<sharp>* (\\<Psi>, P, Q, A\\<^sub>Q, A\\<^sub>P, \\<Psi>\\<^sub>Q, \\<Psi>\\<^sub>P, R)\" and \"distinct A\\<^sub>R\"\n        by(rule fresh_frame)\n      then have \"A\\<^sub>R \\<sharp>* \\<Psi>\" and \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* Q\" and \"A\\<^sub>R \\<sharp>* A\\<^sub>Q\" and  \"A\\<^sub>R \\<sharp>* A\\<^sub>P\" and  \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q\" and  \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P\"\n            and \"A\\<^sub>R \\<sharp>* R\"\n        by simp+\n\n      from `A\\<^sub>Q \\<sharp>* R`  FrR `A\\<^sub>R \\<sharp>* A\\<^sub>Q` have \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R\" by(drule_tac extract_frame_fresh_chain) auto\n      from `A\\<^sub>P \\<sharp>* R` `A\\<^sub>R \\<sharp>* A\\<^sub>P` FrR  have \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R\" by(drule_tac extract_frame_fresh_chain) auto\n\n      moreover from `\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>None @ \\<tau> \\<prec> R'` FrR `distinct A\\<^sub>R` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* Q` `A\\<^sub>R \\<sharp>* R`\n      obtain \\<Psi>' A\\<^sub>R' \\<Psi>\\<^sub>R' where \"\\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'\" and FrR': \"extract_frame R' = \\<langle>A\\<^sub>R', \\<Psi>\\<^sub>R'\\<rangle>\"\n                           and \"A\\<^sub>R' \\<sharp>* \\<Psi>\" and \"A\\<^sub>R' \\<sharp>* P\" and \"A\\<^sub>R' \\<sharp>* Q\"\n        by(rule_tac C=\"(\\<Psi>, P, Q, R)\" in expand_tau_frame) (assumption | simp)+\n\n      from FrR `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* Q`\n      obtain P' P'' where PChain: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n                      and QimpP': \"insert_assertion(extract_frame Q) (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<hookrightarrow>\\<^sub>F insert_assertion(extract_frame P') (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R)\"\n                      and P'Chain: \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<rhd> P' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\"\n                      and P'RelQ: \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>', Q, P'') \\<in> Rel\"\n        by(metis StatImp PRelQ Sym weak_stat_impE)\n      obtain A\\<^sub>P' \\<Psi>\\<^sub>P' where FrP': \"extract_frame P' = \\<langle>A\\<^sub>P', \\<Psi>\\<^sub>P'\\<rangle>\" and \"A\\<^sub>P' \\<sharp>* \\<Psi>\" and \"A\\<^sub>P' \\<sharp>* \\<Psi>\\<^sub>R\" and \"A\\<^sub>P' \\<sharp>* \\<Psi>\\<^sub>Q\"\n                        and \"A\\<^sub>P' \\<sharp>* A\\<^sub>Q\" and \"A\\<^sub>P' \\<sharp>* R\" and \"A\\<^sub>P' \\<sharp>* A\\<^sub>R\"\n        by(rule_tac C=\"(\\<Psi>, \\<Psi>\\<^sub>R, \\<Psi>\\<^sub>Q, A\\<^sub>Q, R, A\\<^sub>R)\" in fresh_frame) auto\n\n      from PChain P'Chain `A\\<^sub>R \\<sharp>* P` `A\\<^sub>Q \\<sharp>* P` `A\\<^sub>R' \\<sharp>* P` have \"A\\<^sub>Q \\<sharp>* P'\" and \"A\\<^sub>R \\<sharp>* P'\" and \"A\\<^sub>R' \\<sharp>* P'\" and \"A\\<^sub>R' \\<sharp>* P''\"\n        by(force intro: tau_chain_fresh_chain)+\n      from `A\\<^sub>R \\<sharp>* P'` `A\\<^sub>P' \\<sharp>* A\\<^sub>R` `A\\<^sub>Q \\<sharp>* P'` `A\\<^sub>P' \\<sharp>* A\\<^sub>Q` FrP' have \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P'\" and \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P'\"\n        by(force dest: extract_frame_fresh_chain)+\n      \n      from PChain FrR `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P` have \"\\<Psi> \\<rhd> P \\<parallel> R \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P' \\<parallel> R\" by(rule tau_chain_par1)\n      moreover have RTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P' \\<rhd> R \\<longmapsto>None @ \\<tau> \\<prec> R'\"\n      proof -\n        have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>None @ \\<tau> \\<prec> R'\" by fact\n        moreover have \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P') \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n        proof -\n          have \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle>\"\n            by(metis frame_int_associativity Commutativity Frame_stat_eq_trans frame_int_composition_sym Frame_stat_eq_sym)\n          moreover with FrP' FrQ QimpP' `A\\<^sub>P' \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>P' \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R`\n          have \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P'\\<rangle>\" using fresh_comp_chain\n            by simp\n          moreover have \"\\<langle>A\\<^sub>P', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P'\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P') \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n            by(metis frame_int_associativity Commutativity Frame_stat_eq_trans frame_int_composition_sym frame_int_associativity[THEN Frame_stat_eq_sym])\n          ultimately show ?thesis\n            by(rule Frame_stat_eq_imp_compose)\n        qed\n        ultimately show ?thesis\n          using `A\\<^sub>P' \\<sharp>* \\<Psi>` `A\\<^sub>P' \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P'` `A\\<^sub>P' \\<sharp>* R` `A\\<^sub>Q \\<sharp>* R` \n                `A\\<^sub>P' \\<sharp>* A\\<^sub>R` `A\\<^sub>R \\<sharp>* A\\<^sub>Q` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P'` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P'` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P'` FrR `distinct A\\<^sub>R`\n          by(force intro: transfer_tau_frame)\n      qed\n      hence \"\\<Psi> \\<rhd> P' \\<parallel> R \\<longmapsto>None @ \\<tau> \\<prec> (P' \\<parallel> R')\" using FrP' `A\\<^sub>P' \\<sharp>* \\<Psi>` `A\\<^sub>P' \\<sharp>* R`\n        by(rule_tac Par2[where \\<pi>=None,simplified]) auto\n      moreover from P'Chain have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<rhd> P' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" \n        by(rule tau_chain_stat_eq) (metis Associativity)\n      with `\\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'` have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R' \\<rhd> P' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" by(metis tau_chain_stat_eq composition_sym)\n      hence \"\\<Psi> \\<rhd> P' \\<parallel> R' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'' \\<parallel> R'\" using FrR' `A\\<^sub>R' \\<sharp>* \\<Psi>` `A\\<^sub>R' \\<sharp>* P'` by(rule_tac tau_chain_par1)\n      ultimately have \"\\<Psi> \\<rhd> P \\<parallel> R \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> (P'' \\<parallel> R')\"\n        by(fastforce dest: rtrancl_into_rtrancl)\n\n      moreover from P'RelQ `\\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'` have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R', P'', Q) \\<in> Rel\" by(blast intro: C3 Associativity composition_sym Sym)\n      with FrR' `A\\<^sub>R' \\<sharp>* \\<Psi>` `A\\<^sub>R' \\<sharp>* P''` `A\\<^sub>R' \\<sharp>* Q` have \"(\\<Psi>, P'' \\<parallel> R', Q \\<parallel> R') \\<in> Rel'\" by(rule_tac C1) \n      ultimately show ?case by blast\n    next\n      case(c_comm1 \\<Psi>\\<^sub>R M N Q' A\\<^sub>Q \\<Psi>\\<^sub>Q K xvec R' A\\<^sub>R yvec zvec)\n      have  FrQ: \"extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" by fact\n      from `A\\<^sub>Q \\<sharp>* (P, R)` have \"A\\<^sub>Q \\<sharp>* P\" and \"A\\<^sub>Q \\<sharp>* R\" by simp+\n\n      have  FrR: \"extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by fact\n      from `A\\<^sub>R \\<sharp>* (P, R)` have \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* R\" by simp+\n      from `xvec \\<sharp>* (P, R)` have \"xvec \\<sharp>* P\" and \"xvec \\<sharp>* R\" by simp+\n\n      from `zvec \\<sharp>* (P, R)` have \"zvec \\<sharp>* P\" and \"zvec \\<sharp>* R\" by simp+\n\n      have QTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>Some (\\<langle>A\\<^sub>Q; yvec, K\\<rangle>) @ M\\<lparr>N\\<rparr> \\<prec> Q'\" and RTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>Some (\\<langle>A\\<^sub>R; zvec, M\\<rangle>) @ K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> R'\"\n        by fact+\n      from RTrans FrR `distinct A\\<^sub>R` `A\\<^sub>R \\<sharp>* R` `A\\<^sub>R \\<sharp>* xvec` `A\\<^sub>R \\<sharp>* N` `xvec \\<sharp>* R` `xvec \\<sharp>* Q` `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>R \\<sharp>* Q`\n                      `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q` `xvec \\<sharp>* K` `A\\<^sub>R \\<sharp>* K` `A\\<^sub>R \\<sharp>* R` `xvec \\<sharp>* R` `A\\<^sub>R \\<sharp>* P` `xvec \\<sharp>* P` `yvec \\<sharp>* xvec`\n                       `A\\<^sub>Q \\<sharp>* A\\<^sub>R` `A\\<^sub>Q \\<sharp>* xvec` `xvec \\<sharp>* K` `distinct xvec` `A\\<^sub>R \\<sharp>* N`  `zvec \\<sharp>* xvec` `zvec \\<sharp>* A\\<^sub>R` `yvec \\<sharp>* A\\<^sub>R`\n      obtain p \\<Psi>' A\\<^sub>R' \\<Psi>\\<^sub>R' where S: \"set p \\<subseteq> set xvec \\<times> set(p \\<bullet> xvec)\" and FrR': \"extract_frame R' = \\<langle>A\\<^sub>R', \\<Psi>\\<^sub>R'\\<rangle>\"\n                             and \"(p \\<bullet> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'\" and \"A\\<^sub>R' \\<sharp>* Q\" and \"A\\<^sub>R' \\<sharp>* \\<Psi>\" and \"(p \\<bullet> xvec) \\<sharp>* \\<Psi>\"\n                             and \"(p \\<bullet> xvec) \\<sharp>* Q\" and \"(p \\<bullet> xvec) \\<sharp>* \\<Psi>\\<^sub>Q\" and \"(p \\<bullet> xvec) \\<sharp>* K\" and \"(p \\<bullet> xvec) \\<sharp>* R\" and \"(p \\<bullet> xvec) \\<sharp>* zvec\" and \"(p \\<bullet> xvec) \\<sharp>* yvec\" and \"(p \\<bullet> xvec) \\<sharp>* N\"\n                             and \"(p \\<bullet> xvec) \\<sharp>* P\" and \"(p \\<bullet> xvec) \\<sharp>* A\\<^sub>Q\" and \"A\\<^sub>R' \\<sharp>* P\" and \"A\\<^sub>R' \\<sharp>* N\" and \"(p \\<bullet> xvec) \\<sharp>* xvec\"\n                             and \"distinct_perm p\"\n        by(rule_tac C=\"(\\<Psi>, Q, \\<Psi>\\<^sub>Q, K, R, P, A\\<^sub>Q)\" and C'=\"(\\<Psi>, Q, \\<Psi>\\<^sub>Q, K, R, P, A\\<^sub>Q,zvec,yvec)\" in expand_frame) (assumption | simp)+\n      from `A\\<^sub>R \\<sharp>* \\<Psi>` have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> \\<Psi>)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n      with `xvec \\<sharp>* \\<Psi>` `(p \\<bullet> xvec) \\<sharp>* \\<Psi>` S have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>\" by simp\n      from `A\\<^sub>R \\<sharp>* P` have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> P)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n      with `xvec \\<sharp>* P` `(p \\<bullet> xvec) \\<sharp>* P` S have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* P\" by simp\n      from `A\\<^sub>R \\<sharp>* Q` have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> Q)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n      with `xvec \\<sharp>* Q` `(p \\<bullet> xvec) \\<sharp>* Q` S have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* Q\" by simp\n      from `A\\<^sub>R \\<sharp>* R` have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> R)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n      with `xvec \\<sharp>* R` `(p \\<bullet> xvec) \\<sharp>* R` S have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* R\" by simp\n      from `A\\<^sub>R \\<sharp>* K` have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> K)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n      with `xvec \\<sharp>* K` `(p \\<bullet> xvec) \\<sharp>* K` S have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* K\" by simp\n\n      from `A\\<^sub>Q \\<sharp>* xvec` `(p \\<bullet> xvec) \\<sharp>* A\\<^sub>Q` `A\\<^sub>Q \\<sharp>* M` S have \"A\\<^sub>Q \\<sharp>* (p \\<bullet> M)\" by(simp add: fresh_chain_simps)\n      from `A\\<^sub>Q \\<sharp>* xvec` `(p \\<bullet> xvec) \\<sharp>* A\\<^sub>Q` `A\\<^sub>Q \\<sharp>* A\\<^sub>R` S have \"A\\<^sub>Q \\<sharp>* (p \\<bullet> A\\<^sub>R)\" by(simp add: fresh_chain_simps)\n\n      from QTrans S `xvec \\<sharp>* Q` `(p \\<bullet> xvec) \\<sharp>* Q` have \"(p \\<bullet> (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R)) \\<rhd> Q \\<longmapsto> Some (\\<langle>A\\<^sub>Q; yvec, K\\<rangle>) @ (p \\<bullet> M)\\<lparr>N\\<rparr> \\<prec> Q'\"\n        by(rule_tac input_perm_frame_subject) (assumption | auto simp add: fresh_star_def)+\n      with `xvec \\<sharp>* \\<Psi>` `(p \\<bullet> xvec) \\<sharp>* \\<Psi>` S have QTrans: \"(\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<rhd> Q \\<longmapsto> Some (\\<langle>A\\<^sub>Q; yvec, K\\<rangle>) @ (p \\<bullet> M)\\<lparr>N\\<rparr> \\<prec> Q'\"\n        by(simp add: eqvts)\n      from FrR have \"(p \\<bullet> extract_frame R) = p \\<bullet> \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by simp\n      with `xvec \\<sharp>* R` `(p \\<bullet> xvec) \\<sharp>* R` S have FrR: \"extract_frame R = \\<langle>(p \\<bullet> A\\<^sub>R), (p \\<bullet> \\<Psi>\\<^sub>R)\\<rangle>\"\n        by(simp add: eqvts)\n\n      from FrR `(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>` `(p \\<bullet> A\\<^sub>R) \\<sharp>* P` `(p \\<bullet> A\\<^sub>R) \\<sharp>* Q`\n      have \"\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R) \\<rhd> P \\<leadsto><Rel> Q\" by(force intro: Sim PRelQ)\n\n      with QTrans obtain \\<pi> P' P'' where PTrans: \"\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R) : Q \\<rhd> P \\<Longrightarrow>\\<pi> @ (p \\<bullet> M)\\<lparr>N\\<rparr> \\<prec> P''\"\n                                  and P''Chain: \"(\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> \\<Psi>' \\<rhd> P'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n                                  and P'RelQ': \"((\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> \\<Psi>', P', Q') \\<in> Rel\"\n        by(drule_tac weakSimE) auto\n      from PTrans QTrans `A\\<^sub>R' \\<sharp>* P` `A\\<^sub>R' \\<sharp>* Q` `A\\<^sub>R' \\<sharp>* N` have \"A\\<^sub>R' \\<sharp>* P''\" and \"A\\<^sub>R' \\<sharp>* Q'\"\n        by(auto dest: weak_input_fresh_chain_derivative input_fresh_chain_derivative)\n\n      from RTrans have \"(p \\<bullet> xvec) \\<sharp>* R'\" using `(p\\<bullet>xvec) \\<sharp>* R` `(p\\<bullet>xvec) \\<sharp>* N` `distinct xvec` `(p\\<bullet>xvec) \\<sharp>* xvec` `xvec \\<sharp>* K`\n        by(auto dest!: output_fresh_chain_derivative)\n\n      from RTrans have RTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto> Some (\\<langle>(p\\<bullet>A\\<^sub>R); zvec, (p\\<bullet>M)\\<rangle>) @ K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> R'\"\n        using S `xvec \\<sharp>* \\<Psi>` `(p\\<bullet>xvec) \\<sharp>* \\<Psi>` `xvec \\<sharp>* \\<Psi>\\<^sub>Q` `(p\\<bullet>xvec) \\<sharp>* \\<Psi>\\<^sub>Q` `xvec \\<sharp>* K` `(p\\<bullet>xvec) \\<sharp>* K`\n              `distinct_perm p` `xvec \\<sharp>* R` `(p\\<bullet>xvec) \\<sharp>* R` `(p\\<bullet>xvec) \\<sharp>* N` `(p\\<bullet>xvec) \\<sharp>* xvec` `(p \\<bullet> xvec) \\<sharp>* R'` `(p \\<bullet> xvec) \\<sharp>* zvec` `zvec \\<sharp>* xvec`\n        by(subst perm_bool[where pi=p,symmetric]) (simp add: eqvts residual_inject bound_output_chain_alpha''[symmetric])\n\n      from `zvec \\<sharp>* A\\<^sub>R` have \"(p\\<bullet>A\\<^sub>R) \\<sharp>* zvec\"\n        using S `zvec \\<sharp>* xvec` `(p\\<bullet>xvec) \\<sharp>* zvec`\n        by(subst (asm) perm_bool[where pi=p,symmetric]) (simp add: eqvts)\n\n      have \"zvec \\<sharp>* (p\\<bullet>\\<Psi>\\<^sub>R)\" using `zvec \\<sharp>* xvec` `zvec \\<sharp>* \\<Psi>\\<^sub>R` `(p\\<bullet>xvec) \\<sharp>* zvec` S\n        by(simp add: fresh_chain_simps)\n      from PTrans FrQ RTrans FrR `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* P` `A\\<^sub>Q \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* R` `A\\<^sub>Q \\<sharp>* (p \\<bullet> M)` `A\\<^sub>Q \\<sharp>* (p \\<bullet> A\\<^sub>R)`\n           `(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>` `(p \\<bullet> A\\<^sub>R) \\<sharp>* P` `(p \\<bullet> A\\<^sub>R) \\<sharp>* Q` `(p \\<bullet> A\\<^sub>R) \\<sharp>* R` `(p \\<bullet> A\\<^sub>R) \\<sharp>* K` `xvec \\<sharp>* P` `distinct A\\<^sub>R`\n           `(p \\<bullet> A\\<^sub>R) \\<sharp>* zvec` `distinct zvec` `zvec \\<sharp>* \\<Psi>` `zvec \\<sharp>* R` `zvec \\<sharp>* P` `A\\<^sub>Q \\<sharp>* xvec` `zvec \\<sharp>* A\\<^sub>Q`\n           `zvec \\<sharp>* (p\\<bullet>\\<Psi>\\<^sub>R)`\n      have \"\\<Psi> \\<rhd> P \\<parallel> R \\<Longrightarrow>\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(P'' \\<parallel> R')\" by(rule_tac weak_comm1) (assumption|simp)+\n\n      moreover from P''Chain `A\\<^sub>R' \\<sharp>* P''` have \"A\\<^sub>R' \\<sharp>* P'\" by(rule tau_chain_fresh_chain)\n      from `(p \\<bullet> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'` have \"(\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> \\<Psi>' \\<simeq> \\<Psi> \\<otimes> \\<Psi>\\<^sub>R'\"\n        by(metis Associativity Assertion_stat_eq_trans Assertion_stat_eq_sym composition_sym)\n      with P''Chain have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R' \\<rhd> P'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" by(rule tau_chain_stat_eq)\n      hence \"\\<Psi> \\<rhd> P'' \\<parallel> R' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P' \\<parallel> R'\" using FrR' `A\\<^sub>R' \\<sharp>* \\<Psi>` `A\\<^sub>R' \\<sharp>* P''` by(rule tau_chain_par1)\n      hence \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(P'' \\<parallel> R') \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> R')\" using `xvec \\<sharp>* \\<Psi>` by(rule tau_chain_res_chain_pres)\n      ultimately have \"\\<Psi> \\<rhd> P \\<parallel> R \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> R')\"\n        by auto\n      moreover from P'RelQ' `(p \\<bullet> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'` have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R', P', Q') \\<in> Rel\"  by(metis C3 Associativity composition_sym)\n      with FrR' `A\\<^sub>R' \\<sharp>* P'` `A\\<^sub>R' \\<sharp>* Q'` `A\\<^sub>R' \\<sharp>* \\<Psi>` have \"(\\<Psi>, P' \\<parallel> R', Q' \\<parallel> R') \\<in> Rel'\" by(rule_tac C1)\n      with `xvec \\<sharp>* \\<Psi>` have \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> R'), \\<lparr>\\<nu>*xvec\\<rparr>(Q' \\<parallel> R')) \\<in> Rel'\"\n        by(rule_tac C2)\n      ultimately show ?case by blast\n    next\n      case(c_comm2 \\<Psi>\\<^sub>R M xvec N Q' A\\<^sub>Q \\<Psi>\\<^sub>Q K R' A\\<^sub>R yvec zvec)\n      have  FrQ: \"extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" by fact\n      from `A\\<^sub>Q \\<sharp>* (P, R)` have \"A\\<^sub>Q \\<sharp>* P\" and \"A\\<^sub>Q \\<sharp>* R\" by simp+\n\n      have  FrR: \"extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by fact\n      from `A\\<^sub>R \\<sharp>* (P, R)` have \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* R\" by simp+\n      from `xvec \\<sharp>* (P, R)` have \"xvec \\<sharp>* P\" and \"xvec \\<sharp>* R\" by simp+\n      from `yvec \\<sharp>* (P, R)` have \"yvec \\<sharp>* P\" and \"yvec \\<sharp>* R\" by simp+\n      from `zvec \\<sharp>* (P, R)` have \"zvec \\<sharp>* P\" and \"zvec \\<sharp>* R\" by simp+\n\n      have QTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>Some (\\<langle>A\\<^sub>Q; yvec, K\\<rangle>) @ M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'\" and RTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>Some (\\<langle>A\\<^sub>R; zvec, M\\<rangle>) @ K\\<lparr>N\\<rparr> \\<prec> R'\"\n        by fact+\n\n      from RTrans FrR `distinct A\\<^sub>R` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* R` `A\\<^sub>R \\<sharp>* Q'` `A\\<^sub>R \\<sharp>* N` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* xvec` `A\\<^sub>R \\<sharp>* K` `yvec \\<sharp>* A\\<^sub>R` `zvec \\<sharp>* A\\<^sub>R`\n      obtain \\<Psi>' A\\<^sub>R' \\<Psi>\\<^sub>R' where  ReqR': \"\\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'\" and FrR': \"extract_frame R' = \\<langle>A\\<^sub>R', \\<Psi>\\<^sub>R'\\<rangle>\" \n                           and \"A\\<^sub>R' \\<sharp>* \\<Psi>\" and \"A\\<^sub>R' \\<sharp>* P\" and \"A\\<^sub>R' \\<sharp>* Q'\" and \"A\\<^sub>R' \\<sharp>* N\" and \"A\\<^sub>R' \\<sharp>* xvec\" and \"A\\<^sub>R' \\<sharp>* yvec\" and \"A\\<^sub>R' \\<sharp>* zvec\"\n        by(rule_tac C=\"(\\<Psi>, P, Q', N, xvec, yvec, zvec)\" and C'=\"(\\<Psi>, P, Q', N, xvec)\" in expand_frame) (assumption | simp)+\n\n      from FrR `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* Q` have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<leadsto><Rel> Q\" by(force intro: Sim PRelQ)\n\n      with QTrans `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* \\<Psi>\\<^sub>R` `xvec \\<sharp>* P`\n      obtain P'' P' \\<pi> where PTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R : Q \\<rhd> P \\<Longrightarrow>\\<pi> @ M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P''\"\n                      and P''Chain: \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<rhd> P'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n                      and P'RelQ': \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>', P', Q') \\<in> Rel\"\n        by(fastforce dest: weakSimE)\n      from PTrans obtain P''' where PChain: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'''\"\n                                and QimpP''': \"insert_assertion (extract_frame Q) (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<hookrightarrow>\\<^sub>F insert_assertion (extract_frame P''') (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R)\"\n                                and P'''Trans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P''' \\<longmapsto>\\<pi> @ M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P''\"\n        by(rule weak_transitionE)\n      \n      from PChain `A\\<^sub>R \\<sharp>* P` have \"A\\<^sub>R \\<sharp>* P'''\" by(rule tau_chain_fresh_chain)\n\n      obtain A\\<^sub>P''' \\<Psi>\\<^sub>P''' where FrP''': \"extract_frame P''' = \\<langle>A\\<^sub>P''', \\<Psi>\\<^sub>P'''\\<rangle>\" and \"A\\<^sub>P''' \\<sharp>* (\\<Psi>, A\\<^sub>Q, \\<Psi>\\<^sub>Q, A\\<^sub>R, \\<Psi>\\<^sub>R, M, N, K, R, P''', Q, xvec,yvec,zvec,\\<pi>)\" and \"distinct A\\<^sub>P'''\"\n        by(rule fresh_frame)\n      hence \"A\\<^sub>P''' \\<sharp>* \\<Psi>\" and \"A\\<^sub>P''' \\<sharp>* A\\<^sub>Q\" and \"A\\<^sub>P''' \\<sharp>* \\<Psi>\\<^sub>Q\" and \"A\\<^sub>P''' \\<sharp>* M\" and \"A\\<^sub>P''' \\<sharp>* R\"\n        and \"A\\<^sub>P''' \\<sharp>* N\" and \"A\\<^sub>P''' \\<sharp>* K\" and \"A\\<^sub>P''' \\<sharp>* A\\<^sub>R\" and \"A\\<^sub>P''' \\<sharp>* P'''\" and \"A\\<^sub>P''' \\<sharp>* xvec\" and \"A\\<^sub>P''' \\<sharp>* \\<Psi>\\<^sub>R\"\n        and \"A\\<^sub>P''' \\<sharp>* yvec\" and \"A\\<^sub>P''' \\<sharp>* zvec\" and \"A\\<^sub>P''' \\<sharp>* \\<pi>\" and \"A\\<^sub>P''' \\<sharp>* Q\"\n        by simp+\n      from P'''Trans `extract_frame P''' = \\<langle>A\\<^sub>P''',\\<Psi>\\<^sub>P'''\\<rangle>` `distinct A\\<^sub>P'''`\n           `A\\<^sub>P''' \\<sharp>* \\<Psi>` `A\\<^sub>P''' \\<sharp>* A\\<^sub>Q` `A\\<^sub>P''' \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>P''' \\<sharp>* M` `A\\<^sub>P''' \\<sharp>* R` `A\\<^sub>P''' \\<sharp>* Q`\n           `A\\<^sub>P''' \\<sharp>* N` `A\\<^sub>P''' \\<sharp>* K` `A\\<^sub>P''' \\<sharp>* A\\<^sub>R` `A\\<^sub>P''' \\<sharp>* P'''` `A\\<^sub>P''' \\<sharp>* xvec` `A\\<^sub>P''' \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>P''' \\<sharp>* \\<pi>` `A\\<^sub>P''' \\<sharp>* zvec`\n      obtain tvec K' where \\<pi>: \"\\<pi> = Some(\\<langle>A\\<^sub>P'''; tvec, K'\\<rangle>)\" and \"distinct tvec\" and \"tvec \\<sharp>* A\\<^sub>P'''\"\n                              \"tvec \\<sharp>* \\<Psi>\" \"tvec \\<sharp>* A\\<^sub>Q\" \"tvec \\<sharp>* \\<Psi>\\<^sub>Q\" \"tvec \\<sharp>* M\" \"tvec \\<sharp>* R\" \"tvec \\<sharp>* Q\"\n                              \"tvec \\<sharp>* N\" \"tvec \\<sharp>* K\" \"tvec \\<sharp>* A\\<^sub>R\" \"tvec \\<sharp>* P'''\" \"tvec \\<sharp>* xvec\" \"tvec \\<sharp>* \\<Psi>\\<^sub>R\" \"tvec \\<sharp>* zvec\"\n                     and MeqK: \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P''' \\<turnstile> K' \\<leftrightarrow> M\"\n        unfolding residual_inject\n        by(frule_tac output_provenance'[where C=\"(\\<Psi>,A\\<^sub>Q,\\<Psi>\\<^sub>Q,M,R,Q,N,K,A\\<^sub>R,P''',xvec,\\<Psi>\\<^sub>R,A\\<^sub>P''',zvec)\"]) auto\n      from P'''Trans have P'''Trans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P''' \\<longmapsto> Some(\\<langle>A\\<^sub>P'''; tvec, K'\\<rangle>) @ M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P''\"\n        unfolding \\<pi>.\n      from MeqK have MeqK': \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P''' \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> K' \\<leftrightarrow> M\"\n        by(metis stat_eq_ent Associativity associativity_sym)\n\n      from `A\\<^sub>R \\<sharp>* P'''` `A\\<^sub>P''' \\<sharp>* A\\<^sub>R` `extract_frame P''' = \\<langle>A\\<^sub>P''',\\<Psi>\\<^sub>P'''\\<rangle>` \n      have \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P'''\"\n        by(auto dest: extract_frame_fresh_chain)\n\n      have \"zvec \\<sharp>* P'''\" using `zvec \\<sharp>* P` PChain\n        by(rule_tac tau_chain_fresh_chain)\n\n      from `zvec \\<sharp>* P'''` `A\\<^sub>P''' \\<sharp>* zvec` `extract_frame P''' = \\<langle>A\\<^sub>P''',\\<Psi>\\<^sub>P'''\\<rangle>` \n      have \"zvec \\<sharp>* \\<Psi>\\<^sub>P'''\"\n        by(auto dest: extract_frame_fresh_chain)\n\n      have \"A\\<^sub>R \\<sharp>* K'\" using P'''Trans\n          `A\\<^sub>R \\<sharp>* P'''` `A\\<^sub>P''' \\<sharp>* A\\<^sub>R` `tvec \\<sharp>* A\\<^sub>R`\n        by(auto dest!: trans_fresh_provenance simp add: frame_chain_fresh_chain'')\n      have \"zvec \\<sharp>* K'\" using P'''Trans\n          `zvec \\<sharp>* P'''` `A\\<^sub>P''' \\<sharp>* zvec` `tvec \\<sharp>* zvec`\n        by(auto dest!: trans_fresh_provenance simp add: frame_chain_fresh_chain'')\n     from `tvec \\<sharp>* A\\<^sub>P'''` `extract_frame P''' = \\<langle>A\\<^sub>P''',\\<Psi>\\<^sub>P'''\\<rangle>` `tvec \\<sharp>* P'''`\n      have \"tvec \\<sharp>* \\<Psi>\\<^sub>P'''\"\n        by(force dest: extract_frame_fresh_chain)\n\n      have \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle>\" \n        by(metis frame_res_chain_pres frame_nil_stat_eq Commutativity Assertion_stat_eq_trans Composition Associativity)\n      moreover with QimpP''' FrP''' FrQ `A\\<^sub>P''' \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>P''' \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R`\n      have \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P''', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P'''\\<rangle>\" using fresh_comp_chain\n        by simp\n      moreover have \"\\<langle>A\\<^sub>P''', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P'''\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P''', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P''') \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n        by(metis frame_res_chain_pres frame_nil_stat_eq Commutativity Assertion_stat_eq_trans Composition Associativity)\n      ultimately have QImpP''': \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P''', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P''') \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n        by(rule Frame_stat_eq_imp_compose)\n      from PChain FrR `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P` have \"\\<Psi> \\<rhd> P \\<parallel> R \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''' \\<parallel> R\" by(rule tau_chain_par1)\n      moreover from RTrans FrR P'''Trans MeqK' QImpP''' FrP''' FrQ `distinct A\\<^sub>P'''` `distinct A\\<^sub>R` `A\\<^sub>P''' \\<sharp>* A\\<^sub>R` `A\\<^sub>Q \\<sharp>* A\\<^sub>R`\n        `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P'''` `A\\<^sub>R \\<sharp>* Q` `A\\<^sub>R \\<sharp>* R` `A\\<^sub>R \\<sharp>* K` `A\\<^sub>P''' \\<sharp>* \\<Psi>` `A\\<^sub>P''' \\<sharp>* R`\n        `A\\<^sub>P''' \\<sharp>* P'''` `A\\<^sub>P''' \\<sharp>* M` `A\\<^sub>Q \\<sharp>* R`  `A\\<^sub>Q \\<sharp>* M` `A\\<^sub>R \\<sharp>* xvec` `xvec \\<sharp>* M` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P'''`\n        `A\\<^sub>R \\<sharp>* K'` `distinct zvec` `zvec \\<sharp>* A\\<^sub>R` `zvec \\<sharp>* \\<Psi>` `zvec \\<sharp>* \\<Psi>\\<^sub>P'''` `zvec \\<sharp>* K'` `zvec \\<sharp>* R`\n         `A\\<^sub>P''' \\<sharp>* zvec` `zvec \\<sharp>* A\\<^sub>Q`\n      have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P''' \\<rhd> R \\<longmapsto>Some (\\<langle>A\\<^sub>R; zvec, M\\<rangle>) @ K'\\<lparr>N\\<rparr> \\<prec> R'\"\n        by(rule_tac comm2_aux) (assumption | simp)+\n      with P'''Trans FrP''' have \"\\<Psi> \\<rhd> P''' \\<parallel> R \\<longmapsto>None @ \\<tau> \\<prec> \\<lparr>\\<nu>*xvec\\<rparr>(P'' \\<parallel> R')\" using FrR `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P'''` `A\\<^sub>R \\<sharp>* R`\n          `xvec \\<sharp>* R` `A\\<^sub>P''' \\<sharp>* \\<Psi>` `A\\<^sub>P''' \\<sharp>* P'''` `A\\<^sub>P''' \\<sharp>* R` `A\\<^sub>P''' \\<sharp>* M` `A\\<^sub>R \\<sharp>* K'` `A\\<^sub>P''' \\<sharp>* A\\<^sub>R`\n          `tvec \\<sharp>* \\<Psi>` `tvec \\<sharp>* \\<Psi>\\<^sub>P'''` `tvec \\<sharp>* R` `zvec \\<sharp>* \\<Psi>` `zvec \\<sharp>* P'''` `zvec \\<sharp>* \\<Psi>\\<^sub>R`\n        by(rule_tac Comm2) assumption+\n      moreover from P'''Trans `A\\<^sub>R \\<sharp>* P'''` `A\\<^sub>R \\<sharp>* xvec` `xvec \\<sharp>* M` `distinct xvec` have \"A\\<^sub>R \\<sharp>* P''\"\n        by(rule_tac output_fresh_chain_derivative) auto\n\n      from PChain `A\\<^sub>R' \\<sharp>* P` have \"A\\<^sub>R' \\<sharp>* P'''\" by(rule tau_chain_fresh_chain)\n      with P'''Trans have \"A\\<^sub>R' \\<sharp>* P''\" using `A\\<^sub>R' \\<sharp>* xvec` `xvec \\<sharp>* M` `distinct xvec`\n        by(rule_tac output_fresh_chain_derivative) auto\n\n      with P''Chain have \"A\\<^sub>R' \\<sharp>* P'\" by(rule tau_chain_fresh_chain)\n      from `\\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'` have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<simeq> \\<Psi> \\<otimes> \\<Psi>\\<^sub>R'\"\n        by(metis Associativity Assertion_stat_eq_trans Assertion_stat_eq_sym composition_sym)\n      with P''Chain have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R' \\<rhd> P'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" by(rule tau_chain_stat_eq)\n      hence \"\\<Psi> \\<rhd> P'' \\<parallel> R' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P' \\<parallel> R'\" using FrR' `A\\<^sub>R' \\<sharp>* \\<Psi>` `A\\<^sub>R' \\<sharp>* P''` \n        by(rule tau_chain_par1)\n      hence \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(P'' \\<parallel> R') \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> R')\" \n        using `xvec \\<sharp>* \\<Psi>` by(rule tau_chain_res_chain_pres)\n      ultimately have \"\\<Psi> \\<rhd> P \\<parallel> R \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> R')\" by(drule_tac tau_act_tau_chain) auto\n      moreover from P'RelQ' `\\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'` have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R', P', Q') \\<in> Rel\"  by(metis C3 Associativity composition_sym)\n      with FrR' `A\\<^sub>R' \\<sharp>* P'` `A\\<^sub>R' \\<sharp>* Q'` `A\\<^sub>R' \\<sharp>* \\<Psi>` have \"(\\<Psi>, P' \\<parallel> R', Q' \\<parallel> R') \\<in> Rel'\" by(rule_tac C1)\n      with `xvec \\<sharp>* \\<Psi>` have \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> R'), \\<lparr>\\<nu>*xvec\\<rparr>(Q' \\<parallel> R')) \\<in> Rel'\"\n        by(rule_tac C2)\n      ultimately show ?case by blast\n    qed\n  qed\nqed\nno_notation relcomp (infixr \"O\" 75)\nlemma weakSimBangPres:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   Rel :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Rel' :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Rel'' :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n\n  assumes \"(\\<Psi>, P, Q) \\<in> Rel\"\n  and     \"eqvt Rel''\"\n  and     \"guarded P\"\n  and     \"guarded Q\"\n  and     Rel'Rel: \"Rel' \\<subseteq> Rel\"\n\n  and     FrameParPres: \"\\<And>\\<Psi>' \\<Psi>\\<^sub>U S T U A\\<^sub>U. \\<lbrakk>(\\<Psi>' \\<otimes> \\<Psi>\\<^sub>U, S, T) \\<in> Rel; extract_frame U = \\<langle>A\\<^sub>U, \\<Psi>\\<^sub>U\\<rangle>; A\\<^sub>U \\<sharp>* \\<Psi>'; A\\<^sub>U \\<sharp>* S; A\\<^sub>U \\<sharp>* T\\<rbrakk> \\<Longrightarrow>\n                                            (\\<Psi>', U \\<parallel> S, U \\<parallel> T) \\<in> Rel\"\n  and     C1: \"\\<And>\\<Psi>' S T U. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel; guarded S; guarded T\\<rbrakk> \\<Longrightarrow> (\\<Psi>', U \\<parallel> !S, U \\<parallel> !T) \\<in> Rel''\"\n  and     ResPres: \"\\<And>\\<Psi>' S T xvec. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel; xvec \\<sharp>* \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', \\<lparr>\\<nu>*xvec\\<rparr>S, \\<lparr>\\<nu>*xvec\\<rparr>T) \\<in> Rel\"\n  and     ResPres': \"\\<And>\\<Psi>' S T xvec. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel'; xvec \\<sharp>* \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', \\<lparr>\\<nu>*xvec\\<rparr>S, \\<lparr>\\<nu>*xvec\\<rparr>T) \\<in> Rel'\"\n\n  and     Closed: \"\\<And>\\<Psi>' S T p. (\\<Psi>', S, T) \\<in> Rel \\<Longrightarrow> ((p::name prm) \\<bullet> \\<Psi>', p \\<bullet> S, p \\<bullet> T) \\<in> Rel\"\n  and     Closed': \"\\<And>\\<Psi>' S T p. (\\<Psi>', S, T) \\<in> Rel' \\<Longrightarrow> ((p::name prm) \\<bullet> \\<Psi>', p \\<bullet> S, p \\<bullet> T) \\<in> Rel'\"\n  and     StatEq: \"\\<And>\\<Psi>' S T \\<Psi>''. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel; \\<Psi>' \\<simeq> \\<Psi>''\\<rbrakk> \\<Longrightarrow> (\\<Psi>'', S, T) \\<in> Rel\"\n  and     StatEq': \"\\<And>\\<Psi>' S T \\<Psi>''. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel'; \\<Psi>' \\<simeq> \\<Psi>''\\<rbrakk> \\<Longrightarrow> (\\<Psi>'', S, T) \\<in> Rel'\"\n  and     Trans: \"\\<And>\\<Psi>' S T U. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel; (\\<Psi>', T, U) \\<in> Rel\\<rbrakk> \\<Longrightarrow> (\\<Psi>', S, U) \\<in> Rel\"\n  and     Trans': \"\\<And>\\<Psi>' S T U. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel'; (\\<Psi>', T, U) \\<in> Rel'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', S, U) \\<in> Rel'\"\n\n  and     cSim: \"\\<And>\\<Psi>' S T. (\\<Psi>', S, T) \\<in> Rel \\<Longrightarrow> \\<Psi>' \\<rhd> S \\<leadsto><Rel> T\"\n  and     cExt: \"\\<And>\\<Psi>' S T \\<Psi>''. (\\<Psi>', S, T) \\<in> Rel \\<Longrightarrow> (\\<Psi>' \\<otimes> \\<Psi>'', S, T) \\<in> Rel\"\n  and     cExt': \"\\<And>\\<Psi>' S T \\<Psi>''. (\\<Psi>', S, T) \\<in> Rel' \\<Longrightarrow> (\\<Psi>' \\<otimes> \\<Psi>'', S, T) \\<in> Rel'\"\n  and     cSym: \"\\<And>\\<Psi>' S T. (\\<Psi>', S, T) \\<in> Rel \\<Longrightarrow> (\\<Psi>', T, S) \\<in> Rel\"\n  and     cSym': \"\\<And>\\<Psi>' S T. (\\<Psi>', S, T) \\<in> Rel' \\<Longrightarrow> (\\<Psi>', T, S) \\<in> Rel'\"\n\n  and     ParPres: \"\\<And>\\<Psi>' S T U. (\\<Psi>', S, T) \\<in> Rel \\<Longrightarrow> (\\<Psi>', S \\<parallel> U, T \\<parallel> U) \\<in> Rel\"\n  and     ParPres2: \"\\<And>\\<Psi>' S T. (\\<Psi>', S, T) \\<in> Rel \\<Longrightarrow> (\\<Psi>', S \\<parallel> S, T \\<parallel> T) \\<in> Rel\"\n  and     ParPres': \"\\<And>\\<Psi>' S T U. (\\<Psi>', S, T) \\<in> Rel' \\<Longrightarrow> (\\<Psi>', U \\<parallel> S, U \\<parallel> T) \\<in> Rel'\"\n\n  and     Assoc: \"\\<And>\\<Psi>' S T U. (\\<Psi>', S \\<parallel> (T \\<parallel> U), (S \\<parallel> T) \\<parallel> U) \\<in> Rel\"\n  and     Assoc': \"\\<And>\\<Psi>' S T U. (\\<Psi>', S \\<parallel> (T \\<parallel> U), (S \\<parallel> T) \\<parallel> U) \\<in> Rel'\"\n  and     ScopeExt: \"\\<And>xvec \\<Psi>' T S. \\<lbrakk>xvec \\<sharp>* \\<Psi>'; xvec \\<sharp>* T\\<rbrakk> \\<Longrightarrow> (\\<Psi>', \\<lparr>\\<nu>*xvec\\<rparr>(S \\<parallel> T), (\\<lparr>\\<nu>*xvec\\<rparr>S) \\<parallel> T) \\<in> Rel\"\n  and     ScopeExt': \"\\<And>xvec \\<Psi>' T S. \\<lbrakk>xvec \\<sharp>* \\<Psi>'; xvec \\<sharp>* T\\<rbrakk> \\<Longrightarrow> (\\<Psi>', \\<lparr>\\<nu>*xvec\\<rparr>(S \\<parallel> T), (\\<lparr>\\<nu>*xvec\\<rparr>S) \\<parallel> T) \\<in> Rel'\"\n\n  and     Compose: \"\\<And>\\<Psi>' S T U O. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel; (\\<Psi>', T, U) \\<in> Rel''; (\\<Psi>', U, O) \\<in> Rel'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', S, O) \\<in> Rel''\"\n\n  and     rBangActE: \"\\<And>\\<Psi>' S \\<alpha> \\<pi> S'. \\<lbrakk>\\<Psi>' \\<rhd> !S \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> S'; guarded S; bn \\<alpha> \\<sharp>* S; \\<alpha> \\<noteq> \\<tau>; bn \\<alpha> \\<sharp>* subject \\<alpha>\\<rbrakk> \\<Longrightarrow> \\<exists>T \\<pi>'. \\<Psi>' \\<rhd> S \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> T \\<and> (\\<one>, S', T \\<parallel> !S) \\<in> Rel'\"\n  and     rBangTauE: \"\\<And>\\<Psi>' S S'. \\<lbrakk>\\<Psi>' \\<rhd> !S \\<longmapsto>None @ \\<tau> \\<prec> S'; guarded S\\<rbrakk> \\<Longrightarrow> \\<exists>T. \\<Psi>' \\<rhd> S \\<parallel> S \\<longmapsto> None @ \\<tau> \\<prec> T \\<and> (\\<one>, S', T \\<parallel> !S) \\<in> Rel'\"\n  and     rBangTauI: \"\\<And>\\<Psi>' S S'. \\<lbrakk>\\<Psi>' \\<rhd> S \\<parallel> S \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> S'; guarded S\\<rbrakk> \\<Longrightarrow> \\<exists>T. \\<Psi>' \\<rhd> !S \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> T \\<and> (\\<Psi>', T, S' \\<parallel> !S) \\<in> Rel'\"\n  shows \"\\<Psi> \\<rhd> R \\<parallel> !P \\<leadsto><Rel''> R \\<parallel> !Q\"\nusing `eqvt Rel''`\nproof(induct rule: weakSimI[where C=\"()\"])\n  case(c_act \\<Psi>' \\<alpha> \\<pi> RQ')\n  from `bn \\<alpha> \\<sharp>* (R \\<parallel> !P)` `bn \\<alpha> \\<sharp>* (R \\<parallel> !Q)` have \"bn \\<alpha> \\<sharp>* P\" and \"bn \\<alpha> \\<sharp>* (!Q)\" and \"bn \\<alpha> \\<sharp>* Q\" and \"bn \\<alpha> \\<sharp>* R\"\n    by simp+\n  from `\\<Psi> \\<rhd> R \\<parallel> !Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> RQ'` `bn \\<alpha> \\<sharp>* \\<Psi>` `bn \\<alpha> \\<sharp>* R` `bn \\<alpha> \\<sharp>* !Q` `bn \\<alpha> \\<sharp>* subject \\<alpha>` `\\<alpha> \\<noteq> \\<tau>` show ?case\n  proof(induct rule: par_cases[where C=\"(\\<Psi>', P, Q, R)\"])\n    case(c_par1 R' \\<pi>' A\\<^sub>Q \\<Psi>\\<^sub>Q)\n    from `extract_frame (!Q) = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>` have \"A\\<^sub>Q = []\" and \"\\<Psi>\\<^sub>Q = \\<one>\" by simp+\n    with `\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> R'` `\\<Psi>\\<^sub>Q = \\<one>` `bn \\<alpha> \\<sharp>* \\<Psi>` `bn \\<alpha> \\<sharp>* P`\n    have \"\\<Psi> \\<rhd> R \\<parallel> !P \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> (R' \\<parallel> !P)\"\n     by(drule_tac Par1[where Q=\"!P\" and A\\<^sub>Q=\"[]\",simplified, unfolded map_option.id[unfolded id_def]])\n       auto\n    hence \"\\<Psi> : R \\<parallel> !Q \\<rhd> R \\<parallel> !P \\<Longrightarrow>\\<pi>' @ \\<alpha> \\<prec> R' \\<parallel> !P\" by(rule_tac transition_weak_transition) auto\n    moreover have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> R' \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> R' \\<parallel> !P\" by auto\n    moreover from `(\\<Psi>, P, Q) \\<in> Rel` have \"(\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> Rel\" by(rule cExt)\n    hence \"(\\<Psi> \\<otimes> \\<Psi>', R' \\<parallel> !P, R' \\<parallel> !Q) \\<in> Rel''\" using `guarded P` `guarded Q` \n      by(rule C1)\n    ultimately show ?case by blast\n  next\n    case(c_par2 Q' \\<pi>' A\\<^sub>R \\<Psi>\\<^sub>R)\n    from `A\\<^sub>R \\<sharp>* (\\<Psi>', P, Q, R)` have \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* Q\" and \"A\\<^sub>R \\<sharp>* \\<Psi>'\" and \"A\\<^sub>R \\<sharp>* R\" by simp+\n    have FrR: \"extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by fact\n    with `bn \\<alpha> \\<sharp>* R` `A\\<^sub>R \\<sharp>* \\<alpha>` have \"bn \\<alpha> \\<sharp>* \\<Psi>\\<^sub>R\" by(auto dest: extract_frame_fresh_chain)\n    \n    obtain A\\<^sub>Q \\<Psi>\\<^sub>Q where FrQ: \"extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R\" and \"A\\<^sub>Q \\<sharp>* A\\<^sub>R\"\n      by(rule_tac C=\"(\\<Psi>, \\<Psi>\\<^sub>R, A\\<^sub>R)\" in fresh_frame) auto\n    from FrQ `guarded Q` have \"\\<Psi>\\<^sub>Q \\<simeq> \\<one>\" and \"supp \\<Psi>\\<^sub>Q = ({}::name set)\" by(blast dest: guarded_stat_eq)+\n    hence \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>Q\" by(auto simp add: fresh_star_def fresh_def)\n\n    from `\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !Q \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> Q'` `guarded Q` `bn \\<alpha> \\<sharp>* Q` `\\<alpha> \\<noteq> \\<tau>` `bn \\<alpha> \\<sharp>* subject \\<alpha>`\n    obtain T \\<pi>'' where QTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>\\<pi>'' @ \\<alpha> \\<prec> T\" and \"(\\<one>, Q', T \\<parallel> !Q) \\<in> Rel'\" \n      by(blast dest: rBangActE)\n    \n    from `(\\<Psi>, P, Q) \\<in> Rel` have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, P, Q) \\<in> Rel\" by(rule cExt)\n    with QTrans `bn \\<alpha> \\<sharp>* \\<Psi>` `bn \\<alpha> \\<sharp>* \\<Psi>\\<^sub>R` `bn \\<alpha> \\<sharp>* P` `\\<alpha> \\<noteq> \\<tau>`\n    obtain P'' \\<pi>''' S where PTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R : Q \\<rhd> P \\<Longrightarrow>\\<pi>''' @ \\<alpha> \\<prec> P''\" \n                   and P''Chain: \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<rhd> P'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> S\"\n                   and SRelT: \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>', S, T) \\<in> Rel\"\n      by(blast dest: cSim weakSimE)\n    from PTrans have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<one> : Q \\<rhd> P \\<Longrightarrow>\\<pi>''' @ \\<alpha> \\<prec> P''\"\n      by(metis weak_transition_stat_eq Identity Assertion_stat_eq_sym)\n    hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R : Q \\<parallel> !P \\<rhd> P \\<parallel> !P \\<Longrightarrow>\\<pi>''' @ \\<alpha> \\<prec> P'' \\<parallel> !P\" using `bn \\<alpha> \\<sharp>* P` \n      by(force intro: weak_par1[where A\\<^sub>Q=\"[]\",simplified,unfolded map_option.id[unfolded id_def]])\n    then obtain \\<pi>'''' where \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R : Q \\<parallel> !P \\<rhd> !P \\<Longrightarrow>\\<pi>'''' @ \\<alpha> \\<prec> P'' \\<parallel> !P\" using `guarded P`\n      by(rule weak_bang)\n    hence \"\\<Psi> : R \\<parallel> (Q \\<parallel> !P) \\<rhd> R \\<parallel> !P \\<Longrightarrow>append_at_front_prov_option \\<pi>'''' A\\<^sub>R @ \\<alpha> \\<prec> R \\<parallel> (P'' \\<parallel> !P)\" \n      using FrR `bn \\<alpha> \\<sharp>* R` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* Q``A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* \\<alpha>` `A\\<^sub>R \\<sharp>* \\<alpha>`\n      by(rule_tac weak_par2) auto\n    moreover have \"insert_assertion (extract_frame(R \\<parallel> !Q)) \\<Psi> \\<hookrightarrow>\\<^sub>F insert_assertion (extract_frame(R \\<parallel> (Q \\<parallel> !P))) \\<Psi>\"\n    proof -\n      have \"insert_assertion (extract_frame(R \\<parallel> !P)) \\<Psi> = \\<langle>A\\<^sub>R, \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<one>\\<rangle>\" using FrR `A\\<^sub>R \\<sharp>* \\<Psi>`\n        by auto\n      moreover from `\\<Psi>\\<^sub>Q \\<simeq> \\<one>` have \"\\<langle>A\\<^sub>R, \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<one>\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>R, \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<one>\\<rangle>\"\n        by(rule_tac frame_res_chain_pres, auto) (metis Identity composition_sym Assertion_stat_eq_trans Assertion_stat_eq_sym)\n      moreover have \"\\<langle>A\\<^sub>R, \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<one>\\<rangle> \\<simeq>\\<^sub>F \\<lparr>\\<nu>*A\\<^sub>Q\\<rparr>(\\<langle>A\\<^sub>R, \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<one>\\<rangle>)\" using `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>Q \\<sharp>* A\\<^sub>R` fresh_comp_chain\n        by(subst frame_res_fresh_chain[where xvec=A\\<^sub>Q, THEN Frame_stat_eq_sym]) auto\n      moreover have \"\\<lparr>\\<nu>*A\\<^sub>Q\\<rparr>(\\<langle>A\\<^sub>R, \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<one>\\<rangle>) \\<simeq>\\<^sub>F \\<lparr>\\<nu>*A\\<^sub>R\\<rparr>(\\<langle>A\\<^sub>Q, \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<one>\\<rangle>)\"\n        by(rule frame_res_chain_comm)\n      moreover have \"insert_assertion (extract_frame(R \\<parallel> (Q \\<parallel> !P))) \\<Psi> = \\<langle>(A\\<^sub>R@A\\<^sub>Q), \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<one>\\<rangle>\" \n        using FrR FrQ `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* A\\<^sub>R` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R`  `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q`  fresh_comp_chain\n        by auto\n      ultimately have \"insert_assertion (extract_frame(R \\<parallel> !P)) \\<Psi> \\<simeq>\\<^sub>F insert_assertion (extract_frame(R \\<parallel> (Q \\<parallel> !P))) \\<Psi>\"\n        by(auto simp add: frame_chain_append) (blast dest: Frame_stat_eq_trans)\n      thus ?thesis by(simp add: Frame_stat_eq_def)\n    qed\n    ultimately have \"\\<Psi> : R \\<parallel> !Q \\<rhd> R \\<parallel> !P \\<Longrightarrow>append_at_front_prov_option \\<pi>'''' A\\<^sub>R @ \\<alpha> \\<prec> R \\<parallel> (P'' \\<parallel> !P)\" \n      by(rule weak_transition_frame_imp)\n\n    moreover from PTrans `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* \\<alpha>` `bn \\<alpha> \\<sharp>* subject \\<alpha>` `distinct(bn \\<alpha>)`\n    have \"A\\<^sub>R \\<sharp>* P''\" by(force dest: weak_fresh_chain_derivative)\n    with P''Chain have \"A\\<^sub>R \\<sharp>* S\" by(force dest: tau_chain_fresh_chain)\n    from `\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>_ @ \\<alpha> \\<prec> T` `A\\<^sub>R \\<sharp>* Q` `A\\<^sub>R \\<sharp>* \\<alpha>` `bn \\<alpha> \\<sharp>* subject \\<alpha>` `distinct(bn \\<alpha>)` have \"A\\<^sub>R \\<sharp>* T\"\n      by(force dest: free_fresh_chain_derivative)\n\n    from P''Chain have \"((\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<one> \\<rhd> P'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> S\" \n      by(rule tau_chain_stat_eq) (metis Associativity Commutativity Composition Assertion_stat_eq_trans Assertion_stat_eq_sym Identity)\n    hence \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P'' \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> S \\<parallel> !P\"\n      by(rule_tac tau_chain_par1) auto\n    hence \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> R \\<parallel> (P'' \\<parallel> !P) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> R \\<parallel> (S \\<parallel> !P)\" using FrR `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* \\<Psi>'` `A\\<^sub>R \\<sharp>* P''` `A\\<^sub>R \\<sharp>* P`\n      by(rule_tac tau_chain_par2) auto\n    moreover have \"(\\<Psi> \\<otimes> \\<Psi>', R \\<parallel> (S \\<parallel> !P), R \\<parallel> Q') \\<in> Rel''\"\n    proof -\n      from `((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>', S, T) \\<in> Rel` have \"((\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>R, S, T) \\<in> Rel\"\n        by(rule StatEq) (metis Associativity Commutativity Composition Assertion_stat_eq_trans Assertion_stat_eq_sym)\n      with FrR `A\\<^sub>R \\<sharp>* \\<Psi>`  `A\\<^sub>R \\<sharp>* \\<Psi>'` `A\\<^sub>R \\<sharp>* S` `A\\<^sub>R \\<sharp>* T` have \"(\\<Psi> \\<otimes> \\<Psi>', R \\<parallel> S, R \\<parallel> T) \\<in> Rel\"\n        by(rule_tac FrameParPres) auto\n      hence \"(\\<Psi> \\<otimes> \\<Psi>', R \\<parallel> T, R \\<parallel> S) \\<in> Rel\" by(rule cSym)\n      hence \"(\\<Psi> \\<otimes> \\<Psi>', (R \\<parallel> T) \\<parallel> !P, (R \\<parallel> S) \\<parallel> !P) \\<in> Rel\" by(rule ParPres)\n      hence \"(\\<Psi> \\<otimes> \\<Psi>', (R \\<parallel> S) \\<parallel> !P, (R \\<parallel> T) \\<parallel> !P) \\<in> Rel\" by(rule cSym)\n      hence \"(\\<Psi> \\<otimes> \\<Psi>', R \\<parallel> (S \\<parallel> !P), (R \\<parallel> T) \\<parallel> !P) \\<in> Rel\" by(metis Trans Assoc)\n      moreover from `(\\<Psi>, P, Q) \\<in> Rel` have \"(\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> Rel\" by(rule cExt)\n      hence \"(\\<Psi> \\<otimes> \\<Psi>', (R \\<parallel> T) \\<parallel> !P, (R \\<parallel> T) \\<parallel> !Q) \\<in> Rel''\" using `guarded P` `guarded Q` by(rule C1)\n      moreover from `(\\<one>, Q', T \\<parallel> !Q) \\<in> Rel'` have \"(\\<one> \\<otimes> \\<Psi> \\<otimes> \\<Psi>', Q', T \\<parallel> !Q) \\<in> Rel'\" by(rule cExt')\n      hence \"(\\<Psi> \\<otimes> \\<Psi>', Q', T \\<parallel> !Q) \\<in> Rel'\" \n        by(rule StatEq') (metis Identity Assertion_stat_eq_sym Commutativity Assertion_stat_eq_trans)\n      hence \"(\\<Psi> \\<otimes> \\<Psi>', R \\<parallel> Q', R \\<parallel> (T \\<parallel> !Q)) \\<in> Rel'\" by(rule ParPres')\n      hence \"(\\<Psi> \\<otimes> \\<Psi>', R \\<parallel> Q', (R \\<parallel> T) \\<parallel> !Q) \\<in> Rel'\" by(metis Trans' Assoc')\n      hence \"(\\<Psi> \\<otimes> \\<Psi>', (R \\<parallel> T) \\<parallel> !Q, R \\<parallel> Q') \\<in> Rel'\" by(rule cSym')\n      ultimately show ?thesis by(rule_tac Compose)\n    qed\n    ultimately show ?case by blast\n  next\n    case c_comm1\n    from `\\<tau> \\<noteq> \\<tau>` have False by simp\n    thus ?case by simp\n  next\n    case c_comm2\n    from `\\<tau> \\<noteq> \\<tau>` have False by simp\n    thus ?case by simp\n  qed\nnext\n  case(c_tau RQ')\n  from `\\<Psi> \\<rhd> R \\<parallel> !Q \\<longmapsto>None @ \\<tau> \\<prec> RQ'` show ?case\n  proof(induct rule: parTauCases[where C=\"(P, Q, R)\"])\n    case(c_par1 R' A\\<^sub>Q \\<Psi>\\<^sub>Q)\n    from `extract_frame (!Q) = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>` have \"A\\<^sub>Q = []\" and \"\\<Psi>\\<^sub>Q = \\<one>\" by simp+\n    with `\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>None @ \\<tau> \\<prec> R'` `\\<Psi>\\<^sub>Q = \\<one>`\n    have \"\\<Psi> \\<rhd> R \\<parallel> !P \\<longmapsto>None @ \\<tau> \\<prec> (R' \\<parallel> !P)\" by(rule_tac Par1[where \\<pi>=None,simplified]) (assumption | simp)+\n    hence \"\\<Psi> \\<rhd> R \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> R' \\<parallel> !P\" by auto\n    moreover from `(\\<Psi>, P, Q) \\<in> Rel` `guarded P` `guarded Q` have \"(\\<Psi>, R' \\<parallel> !P, R' \\<parallel> !Q) \\<in> Rel''\"\n      by(rule C1)\n    ultimately show ?case by blast\n  next\n    case(c_par2 Q' A\\<^sub>R \\<Psi>\\<^sub>R)\n    from `A\\<^sub>R \\<sharp>* (P, Q, R)` have \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* Q\" and \"A\\<^sub>R \\<sharp>* R\" by simp+\n    have FrR: \"extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by fact\n    \n    obtain A\\<^sub>Q \\<Psi>\\<^sub>Q where FrQ: \"extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R\" and \"A\\<^sub>Q \\<sharp>* A\\<^sub>R\"\n      by(rule_tac C=\"(\\<Psi>, \\<Psi>\\<^sub>R, A\\<^sub>R)\" in fresh_frame) auto\n    from FrQ `guarded Q` have \"\\<Psi>\\<^sub>Q \\<simeq> \\<one>\" and \"supp \\<Psi>\\<^sub>Q = ({}::name set)\" by(blast dest: guarded_stat_eq)+\n    hence \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>Q\" by(auto simp add: fresh_star_def fresh_def)\n\n    from `\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !Q \\<longmapsto>None @ \\<tau> \\<prec> Q'` `guarded Q` \n    obtain T where QTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<parallel> Q \\<longmapsto>None @ \\<tau> \\<prec> T\" and \"(\\<one>, Q', T \\<parallel> !Q) \\<in> Rel'\" \n      by(blast dest: rBangTauE)\n    \n    from `(\\<Psi>, P, Q) \\<in> Rel` have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, P, Q) \\<in> Rel\" by(rule cExt)\n    hence \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, P \\<parallel> P, Q \\<parallel> Q) \\<in> Rel\" by(rule ParPres2)\n    with QTrans \n    obtain S where PTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<parallel> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> S\" and SRelT: \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, S, T) \\<in> Rel\"\n      by(blast dest: cSim weakSimE)\n    from PTrans `guarded P` obtain U where PChain: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> U\" and \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, U, S \\<parallel> !P) \\<in> Rel'\"\n      by(blast dest: rBangTauI)\n    from PChain `A\\<^sub>R \\<sharp>* P` have \"A\\<^sub>R \\<sharp>* U\" by(force dest: tau_chain_fresh_chain)\n    from `\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> U` FrR `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P` have \"\\<Psi> \\<rhd> R \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> R \\<parallel> U\"\n      by(rule_tac tau_chain_par2) auto\n    moreover from PTrans `A\\<^sub>R \\<sharp>* P` have \"A\\<^sub>R \\<sharp>* S\" by(force dest: tau_chain_fresh_chain)\n    from QTrans `A\\<^sub>R \\<sharp>* Q` have \"A\\<^sub>R \\<sharp>* T\" by(force dest: tau_fresh_chain_derivative)\n    have \"(\\<Psi>, R \\<parallel> U, R \\<parallel> Q') \\<in> Rel''\"\n    proof -\n      from `(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, U, S \\<parallel> !P) \\<in> Rel'` Rel'Rel have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, U, S \\<parallel> !P) \\<in> Rel\"\n        by auto\n      hence \"(\\<Psi>, R \\<parallel> U, R \\<parallel> (S \\<parallel> !P)) \\<in> Rel\" using FrR `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* U` `A\\<^sub>R \\<sharp>* S` `A\\<^sub>R \\<sharp>* P`\n        by(rule_tac FrameParPres) auto\n\n      moreover from `(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, S, T) \\<in> Rel` FrR `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* S` `A\\<^sub>R \\<sharp>* T` have \"(\\<Psi>, R \\<parallel> S, R \\<parallel> T) \\<in> Rel\"\n        by(rule_tac FrameParPres) auto\n      hence \"(\\<Psi>, R \\<parallel> T, R \\<parallel> S) \\<in> Rel\" by(rule cSym)\n      hence \"(\\<Psi>, (R \\<parallel> T) \\<parallel> !P, (R \\<parallel> S) \\<parallel> !P) \\<in> Rel\" by(rule ParPres)\n      hence \"(\\<Psi>, (R \\<parallel> S) \\<parallel> !P, (R \\<parallel> T) \\<parallel> !P) \\<in> Rel\" by(rule cSym)\n      hence \"(\\<Psi>, R \\<parallel> (S \\<parallel> !P), (R \\<parallel> T) \\<parallel> !P) \\<in> Rel\" by(metis Trans Assoc)\n      ultimately have \"(\\<Psi>, R \\<parallel> U, (R \\<parallel> T) \\<parallel> !P) \\<in> Rel\" by(rule Trans)\n      moreover from `(\\<Psi>, P, Q) \\<in> Rel` have \"(\\<Psi>, (R \\<parallel> T) \\<parallel> !P, (R \\<parallel> T) \\<parallel> !Q) \\<in> Rel''\" using `guarded P` `guarded Q` by(rule C1)\n      moreover from `(\\<one>, Q', T \\<parallel> !Q) \\<in> Rel'` have \"(\\<one> \\<otimes> \\<Psi>, Q', T \\<parallel> !Q) \\<in> Rel'\" by(rule cExt')\n      hence \"(\\<Psi>, Q', T \\<parallel> !Q) \\<in> Rel'\" \n        by(rule StatEq') (metis Identity Assertion_stat_eq_sym Commutativity Assertion_stat_eq_trans)\n      hence \"(\\<Psi>, R \\<parallel> Q', R \\<parallel> (T \\<parallel> !Q)) \\<in> Rel'\" by(rule ParPres')\n      hence \"(\\<Psi>, R \\<parallel> Q', (R \\<parallel> T) \\<parallel> !Q) \\<in> Rel'\" by(metis Trans' Assoc')\n      hence \"(\\<Psi>, (R \\<parallel> T) \\<parallel> !Q, R \\<parallel> Q') \\<in> Rel'\" by(rule cSym')\n      ultimately show ?thesis by(rule_tac Compose)\n    qed\n    ultimately show ?case by blast\n  next\n    case(c_comm1 \\<Psi>\\<^sub>Q M N R' A\\<^sub>R \\<Psi>\\<^sub>R K xvec Q' A\\<^sub>Q yvec zvec)\n    from `A\\<^sub>R \\<sharp>* (P, Q, R)` have \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* Q\" and \"A\\<^sub>R \\<sharp>* R\" by simp+\n    from `xvec \\<sharp>* (P, Q, R)` have \"xvec \\<sharp>* P\" and \"xvec \\<sharp>* Q\" and \"xvec \\<sharp>* R\" by simp+\n    from `yvec \\<sharp>* (P, Q, R)` have \"yvec \\<sharp>* P\" and \"yvec \\<sharp>* Q\" and \"yvec \\<sharp>* R\" by simp+\n    have FrQ: \"extract_frame(!Q) = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" by fact\n    have FrR: \"extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by fact\n    from `\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>Some (\\<langle>A\\<^sub>R; yvec, K\\<rangle>) @ M\\<lparr>N\\<rparr> \\<prec> R'` FrR `distinct A\\<^sub>R` `A\\<^sub>R \\<sharp>* R` `A\\<^sub>R \\<sharp>* N` `A\\<^sub>R \\<sharp>* xvec` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* Q` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* M`\n    obtain A\\<^sub>R' \\<Psi>\\<^sub>R' \\<Psi>' where FrR': \"extract_frame R' = \\<langle>A\\<^sub>R', \\<Psi>\\<^sub>R'\\<rangle>\" and \"\\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'\" and \"A\\<^sub>R' \\<sharp>* xvec\" and \"A\\<^sub>R' \\<sharp>* P\" and \"A\\<^sub>R' \\<sharp>* Q\" and \"A\\<^sub>R' \\<sharp>* \\<Psi>\"\n      by(rule_tac C=\"(\\<Psi>, xvec, P, Q)\" and C'=\"(\\<Psi>, xvec, P, Q)\" in expand_frame) auto\n    from `(\\<Psi>, P, Q) \\<in> Rel` have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, P, Q) \\<in> Rel\" by(rule cExt)\n    moreover from `\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !Q \\<longmapsto>Some (\\<langle>A\\<^sub>Q; zvec, M\\<rangle>) @ K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'` `guarded Q` `xvec \\<sharp>* Q` `xvec \\<sharp>* K`\n    obtain S \\<pi> where QTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>\\<pi> @ K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> S\" and \"(\\<one>, Q', S \\<parallel> !Q) \\<in> Rel'\"\n      by(fastforce dest: rBangActE)\n\n    ultimately obtain P' \\<pi>' T where PTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R : Q \\<rhd> P \\<Longrightarrow>\\<pi>' @ K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\" and P'Chain: \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<rhd> P' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> T\" and \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>', T, S) \\<in> Rel\"\n      using `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* \\<Psi>\\<^sub>R` `xvec \\<sharp>* P`\n      by(drule_tac cSim) (fastforce dest!: weakSimE(1))\n\n    from PTrans `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* xvec` `A\\<^sub>R' \\<sharp>* P` `A\\<^sub>R' \\<sharp>* xvec` `xvec \\<sharp>* K` `distinct xvec`\n    have \"A\\<^sub>R \\<sharp>* P'\" and  \"A\\<^sub>R' \\<sharp>* P'\"\n      by(force dest: weak_output_fresh_chain_derivative)+\n    with P'Chain have \"A\\<^sub>R' \\<sharp>* T\" by(force dest: tau_chain_fresh_chain)+\n    from QTrans `A\\<^sub>R' \\<sharp>* Q` `A\\<^sub>R' \\<sharp>* xvec` `xvec \\<sharp>* K` `distinct xvec` \n    have \"A\\<^sub>R' \\<sharp>* S\" by(force dest: output_fresh_chain_derivative)\n\n    from QTrans obtain A\\<^sub>Q' \\<Psi>\\<^sub>Q' tvec M'' where FrQ': \"extract_frame Q = \\<langle>A\\<^sub>Q', \\<Psi>\\<^sub>Q'\\<rangle>\"\n      and \\<pi>: \"\\<pi> = Some(\\<langle>A\\<^sub>Q'; tvec, M''\\<rangle>)\" and \"distinct A\\<^sub>Q'\" and \"distinct tvec\"\n      and \"A\\<^sub>Q' \\<sharp>* \\<Psi>\" and \"A\\<^sub>Q' \\<sharp>* tvec\" and M'eqK: \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q' \\<turnstile> M'' \\<leftrightarrow> K\"\n      and \"A\\<^sub>Q' \\<sharp>* Q\" and \"A\\<^sub>Q' \\<sharp>* \\<Psi>\\<^sub>R\" and \"A\\<^sub>Q' \\<sharp>* A\\<^sub>R\" and \"A\\<^sub>Q' \\<sharp>* M\" and \"A\\<^sub>Q' \\<sharp>* R\" and \"A\\<^sub>Q' \\<sharp>* K\"\n      and \"A\\<^sub>Q' \\<sharp>* xvec\" and \"A\\<^sub>Q' \\<sharp>* yvec\"\n      unfolding residual_inject\n      by(drule_tac output_provenance[where C=\"(\\<Psi>,Q,\\<Psi>\\<^sub>R, A\\<^sub>R, K, M, R, xvec, yvec)\"]) auto\n\n    from PTrans obtain P'' where PChain: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\"\n                             and NilImpP'': \"\\<langle>A\\<^sub>Q', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q'\\<rangle> \\<hookrightarrow>\\<^sub>F insert_assertion (extract_frame P'') (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R)\"\n                             and P''Trans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P'' \\<longmapsto>\\<pi>' @ K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n      using FrQ' `A\\<^sub>Q' \\<sharp>* \\<Psi>` `A\\<^sub>Q' \\<sharp>* \\<Psi>\\<^sub>R` fresh_comp_chain\n      by(drule_tac weak_transitionE) auto\n\n    from FrQ' `guarded Q` have \"\\<Psi>\\<^sub>Q' \\<simeq> \\<one>\" and \"supp \\<Psi>\\<^sub>Q' = ({}::name set)\" by(blast dest: guarded_stat_eq)+\n    hence \"A\\<^sub>Q' \\<sharp>* \\<Psi>\\<^sub>Q'\" by(auto simp add: fresh_star_def fresh_def)\n\n    from P''Trans obtain A\\<^sub>P'' \\<Psi>\\<^sub>P'' uvec M' where FrP'': \"extract_frame P'' = \\<langle>A\\<^sub>P'', \\<Psi>\\<^sub>P''\\<rangle>\"\n      and \\<pi>': \"\\<pi>' = Some(\\<langle>A\\<^sub>P''; uvec, M'\\<rangle>)\" and \"distinct A\\<^sub>P''\" and \"distinct uvec\"\n      and \"A\\<^sub>P'' \\<sharp>* \\<Psi>\" and \"A\\<^sub>P'' \\<sharp>* uvec\" and M'eqK: \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P'' \\<turnstile> M' \\<leftrightarrow> K\"\n      and \"A\\<^sub>P'' \\<sharp>* Q\" and \"A\\<^sub>P'' \\<sharp>* \\<Psi>\\<^sub>R\" and \"A\\<^sub>P'' \\<sharp>* A\\<^sub>R\" and \"A\\<^sub>P'' \\<sharp>* M\" and \"A\\<^sub>P'' \\<sharp>* R\" and \"A\\<^sub>P'' \\<sharp>* K\"\n      and \"A\\<^sub>P'' \\<sharp>* xvec\" and \"A\\<^sub>P'' \\<sharp>* yvec\" and \"A\\<^sub>P'' \\<sharp>* P\" and \"A\\<^sub>P'' \\<sharp>* P''\"\n      and \"uvec \\<sharp>* Q\" and \"uvec \\<sharp>* \\<Psi>\\<^sub>R\" and \"uvec \\<sharp>* A\\<^sub>R\" and \"uvec \\<sharp>* M\" and \"uvec \\<sharp>* R\" and \"uvec \\<sharp>* K\"\n      and \"uvec \\<sharp>* xvec\" and \"uvec \\<sharp>* yvec\" and \"uvec \\<sharp>* \\<Psi>\" and \"uvec \\<sharp>* P\" and \"uvec \\<sharp>* P''\"\n      unfolding residual_inject\n      by(drule_tac output_provenance[where C=\"(\\<Psi>,Q,\\<Psi>\\<^sub>R, A\\<^sub>R, K, M, R, xvec, yvec,P)\"]) auto\n\n    from FrP'' `uvec \\<sharp>* P''` `A\\<^sub>P'' \\<sharp>* uvec` have \"uvec \\<sharp>* \\<Psi>\\<^sub>P''\" by(force dest: extract_frame_fresh_chain)\n\n    from M'eqK have M'eqK': \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> M' \\<leftrightarrow> K\"\n      by (meson Assertion_stat_eq_def Assertion_stat_imp_def Associativity associativity_sym)\n\n    from `A\\<^sub>R \\<sharp>* P` PChain have \"A\\<^sub>R \\<sharp>* P''\" by(rule_tac tau_chain_fresh_chain)\n    from `yvec \\<sharp>* P` PChain have \"yvec \\<sharp>* P''\" by(rule_tac tau_chain_fresh_chain)\n\n    from FrP'' `A\\<^sub>R \\<sharp>* P''` `A\\<^sub>P'' \\<sharp>* A\\<^sub>R` have \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P''\" by(auto dest: extract_frame_fresh_chain)\n\n    from FrP'' `yvec \\<sharp>* P''` `A\\<^sub>P'' \\<sharp>* yvec` have \"yvec \\<sharp>* \\<Psi>\\<^sub>P''\" by(auto dest: extract_frame_fresh_chain)\n    \n    from `A\\<^sub>R \\<sharp>* P''` P''Trans have \"A\\<^sub>R \\<sharp>* \\<pi>'\" by(rule_tac trans_fresh_provenance)\n    hence \"A\\<^sub>R \\<sharp>* M'\" unfolding \\<pi>'\n      using `A\\<^sub>P'' \\<sharp>* A\\<^sub>R` using `uvec \\<sharp>* A\\<^sub>R`\n      by (simp add: frame_chain_fresh_chain'')\n    from `yvec \\<sharp>* P''` P''Trans have \"yvec \\<sharp>* \\<pi>'\" by(rule_tac trans_fresh_provenance)\n    hence \"yvec \\<sharp>* M'\" unfolding \\<pi>'\n      using `A\\<^sub>P'' \\<sharp>* yvec` using `uvec \\<sharp>* yvec`\n      by (simp add: frame_chain_fresh_chain'')\n\n    from FrQ' `A\\<^sub>R \\<sharp>* Q` `A\\<^sub>Q' \\<sharp>* A\\<^sub>R` have \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q'\" by(auto dest: extract_frame_fresh_chain)\n\n    from PChain have \"\\<Psi> \\<rhd> R \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (P' \\<parallel> !P))\"\n    proof(induct rule: tau_chain_cases)\n      case tau_base\n      from FrP'' `guarded P` `P = P''` have \"\\<Psi>\\<^sub>P'' \\<simeq> \\<one>\" and \"supp \\<Psi>\\<^sub>P'' = ({}::name set)\" by(blast dest: guarded_stat_eq)+\n\n      with `\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>_ @ M\\<lparr>N\\<rparr> \\<prec> R'` FrQ\n      have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<rhd> R \\<longmapsto>Some (\\<langle>A\\<^sub>R; yvec, K\\<rangle>) @ M\\<lparr>N\\<rparr> \\<prec> R'\"\n        using Assertion_stat_eq_sym composition_sym\n        by(force elim: stat_eq_transition)\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<rhd> R \\<longmapsto>Some (\\<langle>A\\<^sub>R; yvec, K\\<rangle>) @ M'\\<lparr>N\\<rparr> \\<prec> R'\"\n        using `extract_frame R = _` `\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> M' \\<leftrightarrow> K`\n              Frame_stat_imp_refl `distinct A\\<^sub>R` `A\\<^sub>R \\<sharp>* A\\<^sub>Q` `A\\<^sub>R \\<sharp>* A\\<^sub>Q` `A\\<^sub>R \\<sharp>* \\<Psi>`\n              `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P''` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P''` `A\\<^sub>R \\<sharp>* R` `A\\<^sub>R \\<sharp>* M'`\n              `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* R` `A\\<^sub>Q \\<sharp>* K` `A\\<^sub>Q \\<sharp>* R` `A\\<^sub>Q \\<sharp>* K`\n              `distinct  yvec` iffD1[OF fresh_chain_sym, OF `yvec \\<sharp>* A\\<^sub>R`]\n              `A\\<^sub>R \\<sharp>* M'` `yvec \\<sharp>* \\<Psi>` `yvec \\<sharp>* \\<Psi>\\<^sub>P''` `yvec \\<sharp>* M'`\n              `yvec \\<sharp>* R` `yvec \\<sharp>* A\\<^sub>Q` `yvec \\<sharp>* A\\<^sub>Q`\n        by(rule comm2_aux)\n      hence \"\\<Psi> \\<otimes> \\<one> \\<rhd> R \\<longmapsto>Some (\\<langle>A\\<^sub>R; yvec, K\\<rangle>) @ M'\\<lparr>N\\<rparr> \\<prec> R'\"\n        using Assertion_stat_eq_sym composition_sym `\\<Psi>\\<^sub>P'' \\<simeq> \\<one>`\n        by(force elim: stat_eq_transition)\n      moreover note FrR\n      moreover from P''Trans `P = P''` have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<longmapsto>\\<pi>' @ K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\" by simp\n      hence \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<one> \\<rhd> P \\<longmapsto>\\<pi>' @ K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\" by(rule stat_eq_transition) (metis Identity Assertion_stat_eq_sym)\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<parallel> !P \\<longmapsto>\\<pi>' @ K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> (P' \\<parallel> !P)\" using `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* \\<Psi>\\<^sub>R` `xvec \\<sharp>* P`\n        by(rule_tac Par1[where Q=\"!P\" and A\\<^sub>Q=\"[]\",simplified,unfolded map_option.id[unfolded id_def]]) auto\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !P \\<longmapsto>Some(\\<langle>\\<epsilon>, \\<langle>(A\\<^sub>P'' @ uvec), M'\\<rangle>\\<rangle>) @ K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> (P' \\<parallel> !P)\" using `guarded P`\n       unfolding \\<pi>'\n       by(rule Bang[where \\<pi>=\\<pi>', unfolded \\<pi>',simplified])\n      ultimately have \"\\<Psi> \\<rhd> R \\<parallel> !P \\<longmapsto>None @ \\<tau> \\<prec> \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (P' \\<parallel> !P))\" using `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* R` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* M` `xvec \\<sharp>* R`\n        `yvec \\<sharp>* \\<Psi>` `yvec \\<sharp>* \\<Psi>\\<^sub>R` `yvec \\<sharp>* P` `A\\<^sub>P'' \\<sharp>* \\<Psi>` `uvec \\<sharp>* \\<Psi>` `A\\<^sub>P'' \\<sharp>* R` `uvec \\<sharp>* R`\n        by(force intro: Comm1[where A\\<^sub>Q=\"[]\" and zvec = \"A\\<^sub>P'' @ uvec\",simplified])\n      thus ?case by(rule tau_act_tau_chain)\n    next\n      case tau_step\n      from `\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P''` have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<one> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P''\" by(rule tau_step_chain_stat_eq) (metis Identity Assertion_stat_eq_sym)\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<parallel> !P \\<Longrightarrow>\\<^sub>\\<tau> P'' \\<parallel> !P\" by(rule_tac tau_step_chain_par1) auto\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !P \\<Longrightarrow>\\<^sub>\\<tau> P'' \\<parallel> !P\" using `guarded P` by(rule tau_step_chain_bang)\n      hence  \"\\<Psi> \\<rhd> R \\<parallel> !P \\<Longrightarrow>\\<^sub>\\<tau> R \\<parallel> (P'' \\<parallel> !P)\" using FrR `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P`\n        by(rule_tac tau_step_chain_par2) auto\n      moreover have \"\\<Psi> \\<rhd> R \\<parallel> (P'' \\<parallel> !P) \\<longmapsto>None @ \\<tau> \\<prec> \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (P' \\<parallel> !P))\"\n      proof -\n        from FrQ `\\<Psi>\\<^sub>Q' \\<simeq> \\<one>` `\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>_ @ M\\<lparr>N\\<rparr> \\<prec> R'` have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q' \\<rhd> R \\<longmapsto>Some (\\<langle>A\\<^sub>R; yvec, K\\<rangle>) @ M\\<lparr>N\\<rparr> \\<prec> R'\"\n          by simp (metis stat_eq_transition Assertion_stat_eq_sym composition_sym)\n        moreover from P''Trans have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<one> \\<rhd> P'' \\<longmapsto>\\<pi>' @ K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n          by(rule stat_eq_transition) (metis Identity Assertion_stat_eq_sym)\n        hence P''PTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P'' \\<parallel> !P \\<longmapsto>\\<pi>' @ K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> (P' \\<parallel> !P)\" using `xvec \\<sharp>* P`\n          by(rule_tac Par1[where A\\<^sub>Q=\"[]\" and Q=\"!P\",simplified,unfolded map_option.id[unfolded id_def]]) auto\n        moreover from FrP'' have FrP''P: \"extract_frame(P'' \\<parallel> !P) = \\<langle>A\\<^sub>P'', \\<Psi>\\<^sub>P'' \\<otimes> \\<one>\\<rangle>\"\n          by auto\n        moreover from `_ \\<otimes> _ \\<otimes> _ \\<turnstile> M' \\<leftrightarrow> K` have \"\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P'' \\<otimes> \\<one>) \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> M' \\<leftrightarrow> K\"\n          using Assertion_stat_eq_sym Composition Identity composition_sym stat_eq_ent by blast\n        moreover have \"\\<langle>A\\<^sub>Q', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q') \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P'' \\<otimes> \\<one>)) \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n        proof -\n          have \"\\<langle>A\\<^sub>Q', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q') \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>Q', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q'\\<rangle>\"\n            by(rule_tac frame_res_chain_pres, simp)\n              (metis Associativity Commutativity Composition Assertion_stat_eq_trans Assertion_stat_eq_sym)\n          moreover from NilImpP'' FrQ FrP'' `A\\<^sub>P'' \\<sharp>* \\<Psi>` `A\\<^sub>P'' \\<sharp>* \\<Psi>\\<^sub>R` fresh_comp_chain have \"\\<langle>A\\<^sub>Q', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q'\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P''\\<rangle>\"\n            by auto\n          moreover have \"\\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P''\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<otimes> \\<one>) \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n            by(rule frame_res_chain_pres, simp) \n              (metis Identity Assertion_stat_eq_sym Associativity Commutativity Composition Assertion_stat_eq_trans)\n          ultimately show ?thesis by(rule Frame_stat_eq_imp_compose)\n        qed\n        ultimately have RTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<otimes> \\<one> \\<rhd> R \\<longmapsto>Some (\\<langle>A\\<^sub>R; yvec, K\\<rangle>) @ M'\\<lparr>N\\<rparr> \\<prec> R'\"\n          using FrR FrQ' `distinct A\\<^sub>R` `distinct A\\<^sub>P''` `A\\<^sub>P'' \\<sharp>* A\\<^sub>R` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P''` `A\\<^sub>R \\<sharp>* Q` `A\\<^sub>R \\<sharp>* R`  `A\\<^sub>R \\<sharp>* M` `A\\<^sub>Q' \\<sharp>* R` `A\\<^sub>Q' \\<sharp>* K` `A\\<^sub>Q' \\<sharp>* A\\<^sub>R` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>P'' \\<sharp>* P` `A\\<^sub>R \\<sharp>* xvec`\n                     `A\\<^sub>P'' \\<sharp>* \\<Psi>` `A\\<^sub>P'' \\<sharp>* R`  `A\\<^sub>P'' \\<sharp>* P''` `A\\<^sub>P'' \\<sharp>* K` `xvec \\<sharp>* K` `distinct xvec` FrR\n                     `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P''` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q'` `A\\<^sub>R \\<sharp>* M'` `distinct yvec` `yvec \\<sharp>* A\\<^sub>R`\n                     `yvec \\<sharp>* \\<Psi>` `yvec \\<sharp>* \\<Psi>\\<^sub>P''` `yvec \\<sharp>* M'` `yvec \\<sharp>* R` `A\\<^sub>P'' \\<sharp>* yvec` `A\\<^sub>Q' \\<sharp>* yvec`\n          by(rule_tac A\\<^sub>Q=\"A\\<^sub>Q'\" in comm2_aux) (assumption | simp | force)+\n        note RTrans FrR P''PTrans FrP''P\n        thus ?thesis using `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* R` `A\\<^sub>R \\<sharp>* P''` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* M'` `A\\<^sub>P'' \\<sharp>* A\\<^sub>R` `A\\<^sub>P'' \\<sharp>* \\<Psi>` `A\\<^sub>P'' \\<sharp>* R` `A\\<^sub>P'' \\<sharp>* P''` `A\\<^sub>P'' \\<sharp>* P` `A\\<^sub>P'' \\<sharp>* K` `xvec \\<sharp>* R` `yvec \\<sharp>* \\<Psi>` `yvec \\<sharp>* \\<Psi>\\<^sub>R` `yvec \\<sharp>* P''` `yvec \\<sharp>* P` `uvec \\<sharp>* \\<Psi>` `uvec \\<sharp>* R` `uvec \\<sharp>* \\<Psi>\\<^sub>P''`\n          unfolding \\<pi>'\n          by(rule_tac Comm1) (assumption | simp | force)+\n      qed\n      ultimately show ?thesis\n        by(drule_tac tau_act_tau_chain) auto\n    qed\n\n    moreover from P'Chain have \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>') \\<otimes> \\<one> \\<rhd> P' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> T\"\n      by(rule tau_chain_stat_eq) (metis Identity Assertion_stat_eq_sym)\n    hence \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<rhd> P' \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> T \\<parallel> !P\"\n      by(rule_tac tau_chain_par1) auto\n    hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<rhd> P' \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> T \\<parallel> !P\"\n      by(rule tau_chain_stat_eq) (metis Associativity)\n    hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R' \\<rhd> P' \\<parallel> !P\\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> T \\<parallel> !P\" using `\\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'`\n      by(rule_tac tau_chain_stat_eq) (auto intro: composition_sym)\n    hence \"\\<Psi> \\<rhd> R' \\<parallel> (P' \\<parallel> !P) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> R' \\<parallel> (T \\<parallel> !P)\" using FrR' `A\\<^sub>R' \\<sharp>* \\<Psi>` `A\\<^sub>R' \\<sharp>* P` `A\\<^sub>R' \\<sharp>* P'`\n      by(rule_tac tau_chain_par2) auto\n    hence \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (P' \\<parallel> !P)) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (T \\<parallel> !P))\" using `xvec \\<sharp>* \\<Psi>`\n      by(rule tau_chain_res_chain_pres)\n    ultimately have \"\\<Psi> \\<rhd> R \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (T \\<parallel> !P))\"\n      by auto\n    moreover have \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (T \\<parallel> !P)), \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> Q')) \\<in> Rel''\"\n    proof -\n      from `((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>', T, S) \\<in> Rel` have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>', T, S) \\<in> Rel\"\n        by(rule StatEq) (metis Associativity)\n      hence \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R', T, S) \\<in> Rel\" using `\\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'`\n        by(rule_tac StatEq) (auto dest: composition_sym)\n\n      with FrR' `A\\<^sub>R' \\<sharp>* \\<Psi>` `A\\<^sub>R' \\<sharp>* S` `A\\<^sub>R' \\<sharp>* T` have \"(\\<Psi>, R' \\<parallel> T, R' \\<parallel> S) \\<in> Rel\"\n        by(rule_tac FrameParPres) auto\n      hence \"(\\<Psi>, (R' \\<parallel> T) \\<parallel> !P, (R' \\<parallel> S) \\<parallel> !P) \\<in> Rel\" by(rule ParPres)\n      hence \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>((R' \\<parallel> T) \\<parallel> !P), \\<lparr>\\<nu>*xvec\\<rparr>((R' \\<parallel> S) \\<parallel> !P)) \\<in> Rel\" using `xvec \\<sharp>* \\<Psi>`\n        by(rule ResPres)\n      hence \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> T) \\<parallel> !P, (\\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> S)) \\<parallel> !P) \\<in> Rel\" using `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* P`\n        by(force intro: Trans ScopeExt)\n      hence \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (T \\<parallel> !P)), (\\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> S)) \\<parallel> !P) \\<in> Rel\" using `xvec \\<sharp>* \\<Psi>`\n        by(force intro: Trans ResPres Assoc)\n\n      moreover from `(\\<Psi>, P, Q) \\<in> Rel` `guarded P` `guarded Q` have \"(\\<Psi>, (\\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> S)) \\<parallel> !P, (\\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> S)) \\<parallel> !Q) \\<in> Rel''\"\n        by(rule C1)\n      moreover from `(\\<one>, Q', S \\<parallel> !Q) \\<in> Rel'` have \"(\\<one> \\<otimes> \\<Psi>, Q', S \\<parallel> !Q) \\<in> Rel'\" by(rule cExt')\n      hence \"(\\<Psi>, Q', S \\<parallel> !Q) \\<in> Rel'\" \n        by(rule StatEq') (metis Identity Assertion_stat_eq_sym Commutativity Assertion_stat_eq_trans)\n      hence \"(\\<Psi>, R' \\<parallel> Q', R' \\<parallel> (S \\<parallel> !Q)) \\<in> Rel'\" by(rule ParPres')\n      hence \"(\\<Psi>, R' \\<parallel> Q', (R' \\<parallel> S) \\<parallel> !Q) \\<in> Rel'\" by(metis Trans' Assoc')\n      hence \"(\\<Psi>, (R' \\<parallel> S) \\<parallel> !Q, R' \\<parallel> Q') \\<in> Rel'\" by(rule cSym')\n      hence \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>((R' \\<parallel> S) \\<parallel> !Q), \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> Q')) \\<in> Rel'\" using `xvec \\<sharp>* \\<Psi>`\n        by(rule ResPres')\n      hence \"(\\<Psi>, (\\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> S)) \\<parallel> !Q, \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> Q')) \\<in> Rel'\" using `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* Q`\n        by(force intro: Trans' ScopeExt'[THEN cSym'])\n      ultimately show ?thesis by(rule_tac Compose)\n    qed\n    ultimately show ?case by blast\n  next\n    case(c_comm2 \\<Psi>\\<^sub>Q M xvec N R' A\\<^sub>R \\<Psi>\\<^sub>R K Q' A\\<^sub>Q yvec zvec)\n    from `A\\<^sub>R \\<sharp>* (P, Q, R)` have \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* Q\" and \"A\\<^sub>R \\<sharp>* R\" by simp+\n    from `xvec \\<sharp>* (P, Q, R)` have \"xvec \\<sharp>* P\" and \"xvec \\<sharp>* Q\" and \"xvec \\<sharp>* R\" by simp+\n    from `yvec \\<sharp>* (P, Q, R)` have \"yvec \\<sharp>* P\" and \"yvec \\<sharp>* Q\" and \"yvec \\<sharp>* R\" by simp+\n    from `zvec \\<sharp>* (P, Q, R)` have \"zvec \\<sharp>* P\" and \"zvec \\<sharp>* Q\" and \"zvec \\<sharp>* R\" by simp+\n    have FrQ: \"extract_frame(!Q) = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" by fact\n    have FrR: \"extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by fact\n    from `\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>_ @ M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> R'` FrR `distinct A\\<^sub>R` `A\\<^sub>R \\<sharp>* R` `A\\<^sub>R \\<sharp>* N` `A\\<^sub>R \\<sharp>* xvec` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* Q` `A\\<^sub>R \\<sharp>* \\<Psi>` `xvec \\<sharp>* R` `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* P` `xvec \\<sharp>* Q` `xvec \\<sharp>* M` `distinct xvec` `A\\<^sub>R \\<sharp>* M`\n    obtain p A\\<^sub>R' \\<Psi>\\<^sub>R' \\<Psi>' where FrR': \"extract_frame R' = \\<langle>A\\<^sub>R', \\<Psi>\\<^sub>R'\\<rangle>\" and \"(p \\<bullet> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'\" and \"A\\<^sub>R' \\<sharp>* xvec\" and \"A\\<^sub>R' \\<sharp>* P\" and \"A\\<^sub>R' \\<sharp>* Q\" and \"A\\<^sub>R' \\<sharp>* \\<Psi>\" and S: \"set p \\<subseteq> set xvec \\<times> set(p \\<bullet> xvec)\" and \"distinct_perm p\" and \"(p \\<bullet> xvec) \\<sharp>* N\" and \"(p \\<bullet> xvec) \\<sharp>* Q\" and \"(p \\<bullet> xvec) \\<sharp>* R'\" and \"(p \\<bullet> xvec) \\<sharp>* P\" and \"(p \\<bullet> xvec) \\<sharp>* \\<Psi>\" and \"A\\<^sub>R' \\<sharp>* N\" and \"A\\<^sub>R' \\<sharp>* xvec\" and \"A\\<^sub>R' \\<sharp>* (p \\<bullet> xvec)\"\n      by(rule_tac C=\"(\\<Psi>, P, Q)\"  and C'=\"(\\<Psi>, P, Q)\" in expand_frame) (assumption | simp)+\n\n    from `\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>_ @ M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> R'` S `(p \\<bullet> xvec) \\<sharp>* N` `(p \\<bullet> xvec) \\<sharp>* R'`\n    have  RTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto> Some (\\<langle>A\\<^sub>R; yvec, K\\<rangle>) @ M\\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> (p \\<bullet> R')\"\n      by(simp add: bound_output_chain_alpha'' residual_inject)\n    from `(\\<Psi>, P, Q) \\<in> Rel` have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, P, Q) \\<in> Rel\" by(rule cExt)\n    moreover from `\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !Q \\<longmapsto>_ @ K\\<lparr>N\\<rparr> \\<prec> Q'` S `(p \\<bullet> xvec) \\<sharp>* Q`  `xvec \\<sharp>* Q` `distinct_perm p`\n    have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !Q \\<longmapsto>Some (\\<langle>A\\<^sub>Q; zvec, M\\<rangle>) @ K\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> (p \\<bullet> Q')\" \n      by(rule_tac input_alpha) auto\n    then obtain \\<pi> S where QTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>\\<pi> @ K\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> S\" and \"(\\<one>, (p \\<bullet> Q'), S \\<parallel> !Q) \\<in> Rel'\" \n      using `guarded Q`\n      by(fastforce dest: rBangActE)\n    ultimately obtain P' \\<pi>' T where PTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R : Q \\<rhd> P \\<Longrightarrow>\\<pi>' @ K\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> P'\" \n                             and P'Chain: \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> (p \\<bullet> \\<Psi>') \\<rhd> P' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> T\" \n                             and \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> (p \\<bullet> \\<Psi>'), T, S) \\<in> Rel\"\n      by(fastforce dest: cSim dest!: weakSimE(1))\n\n    from `A\\<^sub>R' \\<sharp>* N` `A\\<^sub>R' \\<sharp>* xvec` `A\\<^sub>R' \\<sharp>* (p \\<bullet> xvec)` S have \"A\\<^sub>R' \\<sharp>* (p \\<bullet> N)\"\n      by(simp add: fresh_chain_simps)\n    with PTrans `A\\<^sub>R' \\<sharp>* P` have \"A\\<^sub>R' \\<sharp>* P'\" by(force dest: weak_input_fresh_chain_derivative)\n    with P'Chain have \"A\\<^sub>R' \\<sharp>* T\" by(force dest: tau_chain_fresh_chain)+\n    from QTrans `A\\<^sub>R' \\<sharp>* Q` `A\\<^sub>R' \\<sharp>* (p \\<bullet> N)` have \"A\\<^sub>R' \\<sharp>* S\" by(force dest: input_fresh_chain_derivative)\n\n    obtain A\\<^sub>Q' \\<Psi>\\<^sub>Q' where FrQ': \"extract_frame Q = \\<langle>A\\<^sub>Q', \\<Psi>\\<^sub>Q'\\<rangle>\" and \"A\\<^sub>Q' \\<sharp>* \\<Psi>\" and \"A\\<^sub>Q' \\<sharp>* \\<Psi>\\<^sub>R\" and \"A\\<^sub>Q' \\<sharp>* A\\<^sub>R\" and \"A\\<^sub>Q' \\<sharp>* M\" and \"A\\<^sub>Q' \\<sharp>* R\" and \"A\\<^sub>Q' \\<sharp>* xvec\" and \"A\\<^sub>Q' \\<sharp>* yvec\" and \"A\\<^sub>Q' \\<sharp>* K\"\n      by(rule_tac C=\"(\\<Psi>, \\<Psi>\\<^sub>R, A\\<^sub>R, K, M, R, xvec, yvec)\" in fresh_frame) auto\n    from FrQ' `guarded Q` have \"\\<Psi>\\<^sub>Q' \\<simeq> \\<one>\" and \"supp \\<Psi>\\<^sub>Q' = ({}::name set)\" by(blast dest: guarded_stat_eq)+\n    hence \"A\\<^sub>Q' \\<sharp>* \\<Psi>\\<^sub>Q'\" by(auto simp add: fresh_star_def fresh_def)\n\n    from PTrans obtain P'' where PChain: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\"\n                             and NilImpP'': \"\\<langle>A\\<^sub>Q', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q'\\<rangle> \\<hookrightarrow>\\<^sub>F insert_assertion (extract_frame P'') (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R)\"\n                             and P''Trans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P'' \\<longmapsto>\\<pi>' @ K\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> P'\"\n      using FrQ' `A\\<^sub>Q' \\<sharp>* \\<Psi>` `A\\<^sub>Q' \\<sharp>* \\<Psi>\\<^sub>R` fresh_comp_chain\n      by(drule_tac weak_transitionE) auto\n\n    from `(p \\<bullet> xvec) \\<sharp>* P` `xvec \\<sharp>* P` PChain have \"(p \\<bullet> xvec) \\<sharp>* P''\" and \"xvec \\<sharp>* P''\" \n      by(force dest: tau_chain_fresh_chain)+\n    from `(p \\<bullet> xvec) \\<sharp>* N` `distinct_perm p` have \"xvec \\<sharp>* (p \\<bullet> N)\"\n      by(subst pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst, where pi=p, symmetric]) simp\n    with P''Trans `xvec \\<sharp>* P''` have \"xvec \\<sharp>* P'\" by(force dest: input_fresh_chain_derivative)\n    hence \"(p \\<bullet> xvec) \\<sharp>* (p \\<bullet> P')\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n\n    from P''Trans obtain A\\<^sub>P'' \\<Psi>\\<^sub>P'' uvec M' where FrP'': \"extract_frame P'' = \\<langle>A\\<^sub>P'', \\<Psi>\\<^sub>P''\\<rangle>\"\n      and \\<pi>': \"\\<pi>' = Some(\\<langle>A\\<^sub>P''; uvec, M'\\<rangle>)\" and \"distinct A\\<^sub>P''\" and \"distinct uvec\"\n      and \"A\\<^sub>P'' \\<sharp>* \\<Psi>\" and \"A\\<^sub>P'' \\<sharp>* uvec\" and M'eqK: \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P'' \\<turnstile> K \\<leftrightarrow> M'\"\n      and \"A\\<^sub>P'' \\<sharp>* Q\" and \"A\\<^sub>P'' \\<sharp>* \\<Psi>\\<^sub>R\" and \"A\\<^sub>P'' \\<sharp>* A\\<^sub>R\" and \"A\\<^sub>P'' \\<sharp>* M\" and \"A\\<^sub>P'' \\<sharp>* R\" and \"A\\<^sub>P'' \\<sharp>* K\"\n      and \"A\\<^sub>P'' \\<sharp>* xvec\" and \"A\\<^sub>P'' \\<sharp>* yvec\" and \"A\\<^sub>P'' \\<sharp>* P\" and \"A\\<^sub>P'' \\<sharp>* P''\" and \"A\\<^sub>P'' \\<sharp>* p\"\n      and \"uvec \\<sharp>* Q\" and \"uvec \\<sharp>* \\<Psi>\\<^sub>R\" and \"uvec \\<sharp>* A\\<^sub>R\" and \"uvec \\<sharp>* M\" and \"uvec \\<sharp>* R\" and \"uvec \\<sharp>* K\"\n      and \"uvec \\<sharp>* xvec\" and \"uvec \\<sharp>* yvec\" and \"uvec \\<sharp>* \\<Psi>\" and \"uvec \\<sharp>* P\" and \"uvec \\<sharp>* P''\" and \"uvec \\<sharp>* p\"\n      by(drule_tac input_provenance[where C=\"(\\<Psi>,Q,\\<Psi>\\<^sub>R, A\\<^sub>R, K, M, R, xvec, yvec,P,p)\"]) auto\n\n    from FrP'' `uvec \\<sharp>* P''` `A\\<^sub>P'' \\<sharp>* uvec` have \"uvec \\<sharp>* \\<Psi>\\<^sub>P''\" by(force dest: extract_frame_fresh_chain)\n\n    from M'eqK have M'eqK': \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> K \\<leftrightarrow> M'\"\n      by (meson Assertion_stat_eq_def Assertion_stat_imp_def Associativity associativity_sym)\n\n    from `A\\<^sub>R \\<sharp>* P` PChain have \"A\\<^sub>R \\<sharp>* P''\" by(rule_tac tau_chain_fresh_chain)\n    from `yvec \\<sharp>* P` PChain have \"yvec \\<sharp>* P''\" by(rule_tac tau_chain_fresh_chain)\n\n    from FrP'' `A\\<^sub>R \\<sharp>* P''` `A\\<^sub>P'' \\<sharp>* A\\<^sub>R` have \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P''\" by(auto dest: extract_frame_fresh_chain)\n\n    from FrP'' `yvec \\<sharp>* P''` `A\\<^sub>P'' \\<sharp>* yvec` have \"yvec \\<sharp>* \\<Psi>\\<^sub>P''\" by(auto dest: extract_frame_fresh_chain)\n\n    from `A\\<^sub>R \\<sharp>* P''` P''Trans have \"A\\<^sub>R \\<sharp>* \\<pi>'\" by(rule_tac trans_fresh_provenance)\n    hence \"A\\<^sub>R \\<sharp>* M'\" unfolding \\<pi>'\n      using `A\\<^sub>P'' \\<sharp>* A\\<^sub>R` using `uvec \\<sharp>* A\\<^sub>R`\n      by (simp add: frame_chain_fresh_chain'')\n    from `yvec \\<sharp>* P''` P''Trans have \"yvec \\<sharp>* \\<pi>'\" by(rule_tac trans_fresh_provenance)\n    hence \"yvec \\<sharp>* M'\" unfolding \\<pi>'\n      using `A\\<^sub>P'' \\<sharp>* yvec` using `uvec \\<sharp>* yvec`\n      by (simp add: frame_chain_fresh_chain'')\n\n    from FrQ' `A\\<^sub>R \\<sharp>* Q` `A\\<^sub>Q' \\<sharp>* A\\<^sub>R` have \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q'\" by(auto dest: extract_frame_fresh_chain)\n\n    from PChain have \"\\<Psi> \\<rhd> R \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> R') \\<parallel> (P' \\<parallel> !P))\"\n    proof(induct rule: tau_chain_cases)\n      case tau_base\n      from FrP'' `guarded P` `P = P''` have \"\\<Psi>\\<^sub>P'' \\<simeq> \\<one>\" and \"supp \\<Psi>\\<^sub>P'' = ({}::name set)\" by(blast dest: guarded_stat_eq)+\n      with RTrans FrQ have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<rhd> R \\<longmapsto>Some (\\<langle>A\\<^sub>R; yvec, K\\<rangle>) @ M\\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> (p \\<bullet> R')\"\n        using Assertion_stat_eq_sym composition_sym\n        by(force elim: stat_eq_transition)\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<rhd> R \\<longmapsto>Some (\\<langle>A\\<^sub>R; yvec, K\\<rangle>) @ M'\\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> (p \\<bullet> R')\"\n        using `extract_frame R = _` `\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> K \\<leftrightarrow> M'`\n              Frame_stat_imp_refl `distinct A\\<^sub>R` `A\\<^sub>R \\<sharp>* A\\<^sub>Q` `A\\<^sub>R \\<sharp>* A\\<^sub>Q` `A\\<^sub>R \\<sharp>* \\<Psi>`\n              `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P''` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P''` `A\\<^sub>R \\<sharp>* R` `A\\<^sub>R \\<sharp>* M'`\n              `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* R` `A\\<^sub>Q \\<sharp>* K` `A\\<^sub>Q \\<sharp>* R` `A\\<^sub>Q \\<sharp>* K`\n              `distinct  yvec` iffD1[OF fresh_chain_sym, OF `yvec \\<sharp>* A\\<^sub>R`]\n              `A\\<^sub>R \\<sharp>* M'` `yvec \\<sharp>* \\<Psi>` `yvec \\<sharp>* \\<Psi>\\<^sub>P''` `yvec \\<sharp>* M'`\n              `yvec \\<sharp>* R` `yvec \\<sharp>* A\\<^sub>Q` `yvec \\<sharp>* A\\<^sub>Q`\n        by(rule comm1_aux)\n      hence \"\\<Psi> \\<otimes> \\<one> \\<rhd> R \\<longmapsto>Some (\\<langle>A\\<^sub>R; yvec, K\\<rangle>) @ M'\\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> (p \\<bullet> R')\"\n        using Assertion_stat_eq_sym composition_sym `\\<Psi>\\<^sub>P'' \\<simeq> \\<one>`\n        by(force elim: stat_eq_transition)\n      moreover note FrR\n      moreover from P''Trans `P = P''` have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<longmapsto>\\<pi>' @ K\\<lparr>(p \\<bullet> N)\\<rparr>\\<prec> P'\" by simp\n      hence \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<one> \\<rhd> P \\<longmapsto>\\<pi>' @ K\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> P'\" \n        by(rule stat_eq_transition) (metis Identity Assertion_stat_eq_sym)\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<parallel> !P \\<longmapsto>\\<pi>' @ K\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> (P' \\<parallel> !P)\"\n        by(rule_tac Par1[where Q=\"!P\" and A\\<^sub>Q=\"[]\",simplified,unfolded map_option.id[unfolded id_def]]) auto\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !P \\<longmapsto>Some(\\<langle>\\<epsilon>, \\<langle>(A\\<^sub>P'' @ uvec), M'\\<rangle>\\<rangle>) @ K\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> (P' \\<parallel> !P)\" using `guarded P`\n       unfolding \\<pi>'\n       by(rule Bang[where \\<pi>=\\<pi>', unfolded \\<pi>',simplified])\n      ultimately have \"\\<Psi> \\<rhd> R \\<parallel> !P \\<longmapsto>None @ \\<tau> \\<prec> \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> R') \\<parallel> (P' \\<parallel> !P))\" using `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* R` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* M` `(p \\<bullet> xvec) \\<sharp>* P`\n        `yvec \\<sharp>* \\<Psi>` `yvec \\<sharp>* \\<Psi>\\<^sub>R` `yvec \\<sharp>* P` `A\\<^sub>P'' \\<sharp>* \\<Psi>` `uvec \\<sharp>* \\<Psi>` `A\\<^sub>P'' \\<sharp>* R` `uvec \\<sharp>* R`\n        by(force intro: Comm2[where A\\<^sub>Q=\"[]\" and zvec = \"A\\<^sub>P'' @ uvec\",simplified])\n      thus ?case by(rule tau_act_tau_chain)\n    next\n      case tau_step\n      from `\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P''` have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<one> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P''\" by(rule tau_step_chain_stat_eq) (metis Identity Assertion_stat_eq_sym)\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<parallel> !P \\<Longrightarrow>\\<^sub>\\<tau> P'' \\<parallel> !P\" by(rule_tac tau_step_chain_par1) auto\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !P \\<Longrightarrow>\\<^sub>\\<tau> P'' \\<parallel> !P\" using `guarded P` by(rule tau_step_chain_bang)\n      hence  \"\\<Psi> \\<rhd> R \\<parallel> !P \\<Longrightarrow>\\<^sub>\\<tau> R \\<parallel> (P'' \\<parallel> !P)\" using FrR `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P`\n        by(rule_tac tau_step_chain_par2) auto\n      moreover have \"\\<Psi> \\<rhd> R \\<parallel> (P'' \\<parallel> !P) \\<longmapsto>None @ \\<tau> \\<prec> \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> R') \\<parallel> (P' \\<parallel> !P))\"\n      proof -\n        from FrQ `\\<Psi>\\<^sub>Q' \\<simeq> \\<one>` RTrans have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q' \\<rhd> R \\<longmapsto>Some (\\<langle>A\\<^sub>R; yvec, K\\<rangle>) @ M\\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> (p \\<bullet> R')\"\n          by simp (metis stat_eq_transition Assertion_stat_eq_sym composition_sym)\n        moreover from P''Trans have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<one> \\<rhd> P'' \\<longmapsto>\\<pi>' @ K\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> P'\"\n          by(rule stat_eq_transition) (metis Identity Assertion_stat_eq_sym)\n        hence P''PTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P'' \\<parallel> !P \\<longmapsto>\\<pi>' @ K\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> (P' \\<parallel> !P)\"\n          by(rule_tac Par1[where Q=\"!P\" and A\\<^sub>Q=\"[]\",simplified,unfolded map_option.id[unfolded id_def]]) auto\n        moreover from FrP'' have FrP''P: \"extract_frame(P'' \\<parallel> !P) = \\<langle>A\\<^sub>P'', \\<Psi>\\<^sub>P'' \\<otimes> \\<one>\\<rangle>\"\n          by auto\n        moreover from `_ \\<otimes> _ \\<otimes> _ \\<turnstile> K \\<leftrightarrow> M'` have \"\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P'' \\<otimes> \\<one>) \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> K \\<leftrightarrow> M'\"\n          using Assertion_stat_eq_sym Composition Identity composition_sym stat_eq_ent by blast\n        moreover have \"\\<langle>A\\<^sub>Q', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q') \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P'' \\<otimes> \\<one>)) \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n        proof -\n          have \"\\<langle>A\\<^sub>Q', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q') \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>Q', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q'\\<rangle>\"\n            by(rule_tac frame_res_chain_pres, simp)\n              (metis Associativity Commutativity Composition Assertion_stat_eq_trans Assertion_stat_eq_sym)\n          moreover from NilImpP'' FrQ FrP'' `A\\<^sub>P'' \\<sharp>* \\<Psi>` `A\\<^sub>P'' \\<sharp>* \\<Psi>\\<^sub>R` fresh_comp_chain have \"\\<langle>A\\<^sub>Q', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q'\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P''\\<rangle>\"\n            by auto\n          moreover have \"\\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P''\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<otimes> \\<one>) \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n            by(rule frame_res_chain_pres, simp) \n              (metis Identity Assertion_stat_eq_sym Associativity Commutativity Composition Assertion_stat_eq_trans)\n          ultimately show ?thesis by(rule Frame_stat_eq_imp_compose)\n        qed\n        ultimately have RTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<otimes> \\<one> \\<rhd> R \\<longmapsto>Some (\\<langle>A\\<^sub>R; yvec, K\\<rangle>) @ M'\\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> (p \\<bullet> R')\"\n          using FrR FrQ' `distinct A\\<^sub>R` `distinct A\\<^sub>P''` `A\\<^sub>P'' \\<sharp>* A\\<^sub>R` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P''` `A\\<^sub>R \\<sharp>* Q` `A\\<^sub>R \\<sharp>* R`  `A\\<^sub>R \\<sharp>* M` `A\\<^sub>Q' \\<sharp>* R` `A\\<^sub>Q' \\<sharp>* K` `A\\<^sub>Q' \\<sharp>* A\\<^sub>R` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>P'' \\<sharp>* P`\n                     `A\\<^sub>P'' \\<sharp>* \\<Psi>` `A\\<^sub>P'' \\<sharp>* R`  `A\\<^sub>P'' \\<sharp>* P''` `A\\<^sub>P'' \\<sharp>* K` FrR `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P''` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q'` `A\\<^sub>R \\<sharp>* M'` `distinct yvec` `yvec \\<sharp>* A\\<^sub>R`\n                     `yvec \\<sharp>* \\<Psi>` `yvec \\<sharp>* \\<Psi>\\<^sub>P''` `yvec \\<sharp>* M'` `yvec \\<sharp>* R` `A\\<^sub>P'' \\<sharp>* yvec` `A\\<^sub>Q' \\<sharp>* yvec`\n          by(rule_tac A\\<^sub>Q=\"A\\<^sub>Q'\" in comm1_aux) (assumption | simp | force)+\n        note RTrans FrR P''PTrans FrP''P\n        thus ?thesis using `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* R` `A\\<^sub>R \\<sharp>* P''` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* M'` `A\\<^sub>P'' \\<sharp>* A\\<^sub>R` `A\\<^sub>P'' \\<sharp>* \\<Psi>` `A\\<^sub>P'' \\<sharp>* R` `A\\<^sub>P'' \\<sharp>* P''` `A\\<^sub>P'' \\<sharp>* P` `A\\<^sub>P'' \\<sharp>* K` `(p \\<bullet> xvec) \\<sharp>* P''` `(p \\<bullet> xvec) \\<sharp>* P`\n                           `yvec \\<sharp>* \\<Psi>` `yvec \\<sharp>* \\<Psi>\\<^sub>R` `yvec \\<sharp>* P` `A\\<^sub>P'' \\<sharp>* \\<Psi>` `uvec \\<sharp>* \\<Psi>` `A\\<^sub>P'' \\<sharp>* R` `uvec \\<sharp>* R`  `yvec \\<sharp>* P''` `uvec \\<sharp>* \\<Psi>\\<^sub>P''`\n          unfolding \\<pi>'\n          by(rule_tac Comm2) (assumption | simp | force)+\n      qed\n      ultimately show ?thesis\n        by(drule_tac tau_act_tau_chain) auto\n    qed\n    hence \"\\<Psi> \\<rhd> R \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> ((p \\<bullet> P') \\<parallel> !P))\" \n      using `xvec \\<sharp>* P` `(p \\<bullet> xvec) \\<sharp>* P` `(p \\<bullet> xvec) \\<sharp>* (p \\<bullet> P')` `(p \\<bullet> xvec) \\<sharp>* R'` S `distinct_perm p`\n      by(subst res_chain_alpha[where p=p]) auto\n    moreover from P'Chain have \"(p \\<bullet> ((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> (p \\<bullet> \\<Psi>'))) \\<rhd> (p \\<bullet> P') \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> (p \\<bullet> T)\"\n      by(rule tau_chain_eqvt)\n    with `xvec \\<sharp>* \\<Psi>` `(p \\<bullet> xvec) \\<sharp>* \\<Psi>` S `distinct_perm p`\n    have \"(\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> \\<Psi>' \\<rhd> (p \\<bullet> P') \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> (p \\<bullet> T)\" by(simp add: eqvts)\n    hence \"((\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> \\<Psi>') \\<otimes> \\<one> \\<rhd> (p \\<bullet> P') \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> (p \\<bullet> T)\"\n      by(rule tau_chain_stat_eq) (metis Identity Assertion_stat_eq_sym)\n    hence \"(\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> \\<Psi>' \\<rhd> (p \\<bullet> P') \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> (p \\<bullet> T) \\<parallel> !P\"\n      by(rule_tac tau_chain_par1) auto\n    hence \"\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<rhd> (p \\<bullet> P') \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> (p \\<bullet> T) \\<parallel> !P\"\n      by(rule tau_chain_stat_eq) (metis Associativity)\n    hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R' \\<rhd> (p \\<bullet> P') \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> (p \\<bullet> T) \\<parallel> !P\" using `(p \\<bullet> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<simeq>  \\<Psi>\\<^sub>R'`\n      by(rule_tac tau_chain_stat_eq) (auto intro: composition_sym)\n    hence \"\\<Psi> \\<rhd> R' \\<parallel> ((p \\<bullet> P') \\<parallel> !P) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> R' \\<parallel> ((p \\<bullet> T) \\<parallel> !P)\" \n      using FrR' `A\\<^sub>R' \\<sharp>* \\<Psi>` `A\\<^sub>R' \\<sharp>* P` `A\\<^sub>R' \\<sharp>* P'` `A\\<^sub>R' \\<sharp>* xvec` `A\\<^sub>R' \\<sharp>* (p \\<bullet> xvec)` S\n      by(rule_tac tau_chain_par2) (auto simp add: fresh_chain_simps)\n    hence \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> ((p \\<bullet> P') \\<parallel> !P)) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> ((p \\<bullet> T) \\<parallel> !P))\" using `xvec \\<sharp>* \\<Psi>`\n      by(rule tau_chain_res_chain_pres)\n    ultimately have \"\\<Psi> \\<rhd> R \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> ((p \\<bullet> T) \\<parallel> !P))\"\n      by auto\n    moreover have \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> ((p \\<bullet> T) \\<parallel> !P)), \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> Q')) \\<in> Rel''\"\n    proof -\n      from `((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> (p \\<bullet> \\<Psi>'), T, S) \\<in> Rel` \n      have \"(p \\<bullet> ((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> (p \\<bullet> \\<Psi>')), (p \\<bullet> T), (p \\<bullet> S)) \\<in> Rel\"\n        by(rule Closed)\n      with `xvec \\<sharp>* \\<Psi>` `(p \\<bullet> xvec) \\<sharp>* \\<Psi>` `distinct_perm p` S\n      have \"((\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> \\<Psi>', p \\<bullet> T, p \\<bullet> S) \\<in> Rel\"\n        by(simp add: eqvts)\n      hence \"(\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>', p \\<bullet> T, p \\<bullet> S) \\<in> Rel\"\n        by(rule StatEq) (metis Associativity)\n      hence \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R', p \\<bullet> T, p \\<bullet> S) \\<in> Rel\" using `(p \\<bullet> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'`\n        by(rule_tac StatEq) (auto dest: composition_sym)\n      moreover from `A\\<^sub>R' \\<sharp>* S` `A\\<^sub>R' \\<sharp>* T` `A\\<^sub>R' \\<sharp>* xvec` `A\\<^sub>R' \\<sharp>* (p \\<bullet> xvec)` S\n      have \"A\\<^sub>R' \\<sharp>* (p \\<bullet> S)\" and \"A\\<^sub>R' \\<sharp>* (p \\<bullet> T)\"\n        by(simp add: fresh_chain_simps)+\n      ultimately have \"(\\<Psi>, R' \\<parallel> (p \\<bullet> T), R' \\<parallel> (p \\<bullet> S)) \\<in> Rel\" using FrR' `A\\<^sub>R' \\<sharp>* \\<Psi>`\n        by(rule_tac FrameParPres) auto\n      hence \"(\\<Psi>, (R' \\<parallel> (p \\<bullet> T)) \\<parallel> !P, (R' \\<parallel> (p \\<bullet> S)) \\<parallel> !P) \\<in> Rel\" by(rule ParPres)\n      hence \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>((R' \\<parallel> (p \\<bullet> T)) \\<parallel> !P), \\<lparr>\\<nu>*xvec\\<rparr>((R' \\<parallel> (p \\<bullet> S)) \\<parallel> !P)) \\<in> Rel\" \n        using `xvec \\<sharp>* \\<Psi>`\n        by(rule ResPres)\n      hence \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (p \\<bullet> T)) \\<parallel> !P, (\\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (p \\<bullet> S))) \\<parallel> !P) \\<in> Rel\" \n        using `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* P`\n        by(force intro: Trans ScopeExt)\n      hence \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> ((p \\<bullet> T) \\<parallel> !P)), (\\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (p \\<bullet> S))) \\<parallel> !P) \\<in> Rel\"\n        using `xvec \\<sharp>* \\<Psi>`\n        by(force intro: Trans ResPres Assoc)\n      moreover from `(\\<Psi>, P, Q) \\<in> Rel` `guarded P` `guarded Q` \n      have \"(\\<Psi>, (\\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (p \\<bullet> S))) \\<parallel> !P, (\\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (p \\<bullet> S))) \\<parallel> !Q) \\<in> Rel''\"\n        by(rule C1)\n      moreover from `(\\<one>, (p \\<bullet> Q'), S \\<parallel> !Q) \\<in> Rel'` \n      have \"(p \\<bullet> \\<one>, p \\<bullet> p \\<bullet> Q', p \\<bullet> (S \\<parallel> !Q)) \\<in> Rel'\" by(rule Closed')\n      with `xvec \\<sharp>* Q` `(p \\<bullet> xvec) \\<sharp>* Q` S `distinct_perm p` \n        have \"(\\<one>, Q', (p \\<bullet> S) \\<parallel> !Q) \\<in> Rel'\" by(simp add: eqvts)\n      hence \"(\\<one> \\<otimes> \\<Psi>, Q', (p \\<bullet> S) \\<parallel> !Q) \\<in> Rel'\" by(rule cExt')\n      hence \"(\\<Psi>, Q', (p \\<bullet> S) \\<parallel> !Q) \\<in> Rel'\" \n        by(rule StatEq') (metis Identity Assertion_stat_eq_sym Commutativity Assertion_stat_eq_trans)\n      hence \"(\\<Psi>, R' \\<parallel> Q', R' \\<parallel> ((p \\<bullet> S) \\<parallel> !Q)) \\<in> Rel'\" by(rule ParPres')\n      hence \"(\\<Psi>, R' \\<parallel> Q', (R' \\<parallel> (p \\<bullet> S)) \\<parallel> !Q) \\<in> Rel'\" by(metis Trans' Assoc')\n      hence \"(\\<Psi>, (R' \\<parallel> (p \\<bullet> S)) \\<parallel> !Q, R' \\<parallel> Q') \\<in> Rel'\" by(rule cSym')\n      hence \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>((R' \\<parallel> (p \\<bullet> S)) \\<parallel> !Q), \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> Q')) \\<in> Rel'\" using `xvec \\<sharp>* \\<Psi>`\n        by(rule ResPres')\n      hence \"(\\<Psi>, (\\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (p \\<bullet> S))) \\<parallel> !Q, \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> Q')) \\<in> Rel'\" using `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* Q`\n        by(force intro: Trans' ScopeExt'[THEN cSym'])\n      ultimately show ?thesis by(rule_tac Compose)\n    qed\n    ultimately show ?case by blast\n  qed\nqed\nnotation relcomp (infixr \"O\" 75)\nend\n\nend\n", "meta": {"author": "IlmariReissumies", "repo": "newpsi", "sha": "201517d55b6ed1632a5bff2a585367278b5bc67b", "save_path": "github-repos/isabelle/IlmariReissumies-newpsi", "path": "github-repos/isabelle/IlmariReissumies-newpsi/newpsi-201517d55b6ed1632a5bff2a585367278b5bc67b/Weak_Sim_Pres.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.519521321952093, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.2638190910332891}}
{"text": "(*\n * Copyright (C) 2014, National ICT Australia Limited. All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are\n * met:\n *\n *  * Redistributions of source code must retain the above copyright\n *    notice, this list of conditions and the following disclaimer.\n *\n *  * Redistributions in binary form must reproduce the above copyright\n *    notice, this list of conditions and the following disclaimer in the\n *    documentation and/or other materials provided with the distribution.\n *\n *  * The name of National ICT Australia Limited nor the names of its\n *    contributors may be used to endorse or promote products derived from\n *    this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS\n * IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\n * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A\n * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n *)\n\ntheory WordLemmaBucket\nimports\n  Lib\n  MoreDivides\n  Aligned\n  HOLLemmaBucket\n  DistinctPropLemmaBucket\n  \"~~/src/HOL/Library/Sublist\"\n  \"~~/src/HOL/Library/Prefix_Order\"\nbegin\n\n(* Setup \"quickcheck\" to support words. *)\n\nquickcheck_generator word\n  constructors:\n    \"zero_class.zero :: ('a::len) word\",\n    \"numeral :: num \\<Rightarrow> ('a::len) word\",\n    \"uminus :: ('a::len) word \\<Rightarrow> ('a::len) word\"\n\ninstantiation Enum.finite_1 :: len\nbegin\n  definition \"len_of_finite_1 (x :: Enum.finite_1 itself) \\<equiv> (1 :: nat)\"\n  instance\n    by (default, auto simp: len_of_finite_1_def)\nend\n\ninstantiation Enum.finite_2 :: len\nbegin\n  definition \"len_of_finite_2 (x :: Enum.finite_2 itself) \\<equiv> (2 :: nat)\"\n  instance\n    by (default, auto simp: len_of_finite_2_def)\nend\n\ninstantiation Enum.finite_3 :: len\nbegin\n  definition \"len_of_finite_3 (x :: Enum.finite_3 itself) \\<equiv> (4 :: nat)\"\n  instance\n    by (default, auto simp: len_of_finite_3_def)\nend\n\n(* Provide wf and less_induct for word.\n   wf may be more useful in loop proofs, less_induct in recursion proofs. *)\nlemma word_less_wf: \"wf {(a, b). a < (b :: ('a::len) word)}\"\n  apply (rule wf_subset)\n  apply (rule wf_measure)\n  apply safe\n  apply (subst in_measure)\n  apply (erule unat_mono)\n  done\n\nlemma word_less_induct:\n  \"\\<lbrakk> \\<And>x::('a::len) word. (\\<And>y. y < x \\<Longrightarrow> P y) \\<Longrightarrow> P x \\<rbrakk> \\<Longrightarrow> P a\"\n  using word_less_wf\n  apply induct\n  apply blast\n  done\n\ninstantiation word :: (len) wellorder\nbegin\ninstance\n  apply (intro_classes)\n  apply (metis word_less_induct)\n  done\nend\n\n\nlemma word_plus_mono_left:\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk>y \\<le> z; x \\<le> x + z\\<rbrakk> \\<Longrightarrow> y + x \\<le> z + x\"\n  by unat_arith\n\nlemma word_2p_mult_inc:\n  assumes x: \"2 * 2 ^ n < (2::'a::len word) * 2 ^ m\"\n  assumes suc_n: \"Suc n < len_of TYPE('a::len)\"\n  assumes suc_m: \"Suc m < len_of TYPE('a::len)\"\n  assumes 2: \"unat (2::'a::len word) = 2\"\n  shows \"2^n < (2::'a::len word)^m\"\nproof -\n  from suc_n\n  have \"(2::nat) * 2 ^ n mod 2 ^ len_of TYPE('a::len) = 2 * 2^n\"\n    apply (subst mod_less)\n     apply (subst power_Suc[symmetric])\n     apply (rule power_strict_increasing)\n      apply simp\n     apply simp\n    apply simp\n    done\n  moreover\n  from suc_m\n  have \"(2::nat) * 2 ^ m mod 2 ^ len_of TYPE('a::len) = 2 * 2^m\"\n    apply (subst mod_less)\n     apply (subst power_Suc[symmetric])\n     apply (rule power_strict_increasing)\n      apply simp\n     apply simp\n    apply simp\n    done\n  ultimately\n  have \"2 * 2 ^ n < (2::nat) * 2 ^ m\" using x\n    apply (unfold word_less_nat_alt)\n    apply simp\n    apply (subst (asm) unat_word_ariths(2))+\n    apply (subst (asm) 2)+\n    apply (subst (asm) word_unat_power, subst (asm) unat_of_nat)+\n    apply (simp add: mod_mult_right_eq[symmetric])\n    done\n  with suc_n suc_m\n  show ?thesis\n    unfolding word_less_nat_alt\n    apply (subst word_unat_power, subst unat_of_nat)+\n    apply simp\n    done\nqed\n\n\n\nlemma word_shiftl_add_distrib:\n  fixes x :: \"'a :: len word\"\n  shows \"(x + y) << n = (x << n) + (y << n)\"\n  by (simp add: shiftl_t2n ring_distribs)\n\nlemma upper_bits_unset_is_l2p:\n  \"n < word_bits \\<Longrightarrow> (\\<forall>n' \\<ge> n. n' < word_bits \\<longrightarrow> \\<not> p !! n') = ((p::word32) < 2 ^ n)\"\n  apply (rule iffI)\n   prefer 2\n   apply (clarsimp simp: word_bits_def)\n   apply (drule bang_is_le)\n   apply (drule_tac y=p in order_le_less_trans, assumption)\n   apply (drule word_power_increasing)\n      apply simp\n     apply simp\n    apply simp\n   apply simp\n  apply (subst mask_eq_iff_w2p [symmetric])\n   apply (clarsimp simp: word_size word_bits_def)\n  apply (rule word_eqI)\n  apply (clarsimp simp: word_size word_bits_def)\n  apply (case_tac \"na < n\", auto)\n  done\n\nlemma up_ucast_inj:\n  \"\\<lbrakk> ucast x = (ucast y::'b::len word); len_of TYPE('a) \\<le> len_of TYPE ('b) \\<rbrakk> \\<Longrightarrow> x = (y::'a::len word)\"\n  apply (subst (asm) bang_eq)\n  apply (fastforce simp: nth_ucast word_size intro: word_eqI)\n  done\n\nlemma up_ucast_inj_eq:\n  \"len_of TYPE('a) \\<le> len_of TYPE ('b) \\<Longrightarrow> (ucast x = (ucast y::'b::len word)) = (x = (y::'a::len word))\"\n  by (fastforce dest: up_ucast_inj)\n\nlemma ucast_up_inj:\n  \"\\<lbrakk> ucast x = (ucast y :: 'b::len word); len_of TYPE('a) \\<le> len_of TYPE('b) \\<rbrakk>\n  \\<Longrightarrow> x = (y :: 'a::len word)\"\n  apply (subst (asm) bang_eq)\n  apply (rule word_eqI)\n  apply (simp add: word_size nth_ucast)\n  apply (erule_tac x=n in allE)\n  apply simp\n  done\n\nlemma ucast_8_32_inj:\n  \"inj (ucast ::  8 word \\<Rightarrow> 32 word)\"\n  apply (rule down_ucast_inj)\n  apply (clarsimp simp: is_down_def target_size source_size)\n  done\n\nlemma no_plus_overflow_neg:\n  \"(x :: ('a :: len) word) < -y \\<Longrightarrow> x \\<le> x + y\"\n  apply (simp add: no_plus_overflow_uint_size\n                   word_less_alt uint_word_ariths\n                   word_size)\n  apply (subst(asm) zmod_zminus1_eq_if)\n  apply (simp split: split_if_asm)\n  done\n\nlemma ucast_ucast_eq:\n  fixes x :: \"'a::len word\"\n  fixes y :: \"'b::len word\"\n  shows\n  \"\\<lbrakk> ucast x = (ucast (ucast y::'a::len word)::'c::len word);\n    len_of TYPE('a) \\<le> len_of TYPE('b);\n    len_of TYPE('b) \\<le> len_of TYPE('c) \\<rbrakk> \\<Longrightarrow>\n  x = ucast y\"\n  apply (rule word_eqI)\n  apply (subst (asm) bang_eq)\n  apply (erule_tac x=n in allE)\n  apply (simp add: nth_ucast word_size)\n  done\n\n(******** GeneralLib ****************)\n\n\nlemma neq_into_nprefixeq:\n  \"\\<lbrakk> x \\<noteq> take (length x) y \\<rbrakk> \\<Longrightarrow> \\<not> x \\<le> y\"\n  by (clarsimp simp: prefixeq_def less_eq_list_def)\n\nlemma distinct_suffixeq:\n  assumes dx: \"distinct xs\"\n  and     pf: \"suffixeq ys xs\"\n  shows   \"distinct ys\"\n  using dx pf by (clarsimp elim!: suffixeqE)\n\nlemma suffixeq_map:\n  assumes pf: \"suffixeq ys xs\"\n  shows   \"suffixeq (map f ys) (map f xs)\"\n  using pf by (auto elim!: suffixeqE intro: suffixeqI)\n\nlemma suffixeq_drop [simp]:\n  \"suffixeq (drop n as) as\"\n  unfolding suffixeq_def\n  apply (rule exI [where x = \"take n as\"])\n  apply simp\n  done\n\nlemma suffixeq_take:\n  \"suffixeq ys xs \\<Longrightarrow> xs = take (length xs - length ys) xs @ ys\"\n  by (clarsimp elim!: suffixeqE)\n\nlemma suffixeq_eqI:\n  \"\\<lbrakk> suffixeq xs as; suffixeq xs bs; length as = length bs;\n    take (length as - length xs) as \\<le> take (length bs - length xs) bs\\<rbrakk> \\<Longrightarrow> as = bs\"\n  by (clarsimp elim!: prefixE suffixeqE)\n\nlemma suffixeq_Cons_mem:\n  \"suffixeq (x # xs) as \\<Longrightarrow> x \\<in> set as\"\n  apply (drule suffixeq_set_subset)\n  apply simp\n  done\n\nlemma list_induct_suffixeq [case_names Nil Cons]:\n  assumes nilr: \"P []\"\n  and    consr: \"\\<And>x xs. \\<lbrakk>P xs; suffixeq (x # xs) as \\<rbrakk> \\<Longrightarrow> P (x # xs)\"\n  shows  \"P as\"\nproof -\n  def as' == as\n\n  have \"suffixeq as as'\" unfolding as'_def by simp\n  thus ?thesis\n  proof (induct as)\n    case Nil show ?case by fact\n  next\n    case (Cons x xs)\n\n    show ?case\n    proof (rule consr)\n      from Cons.prems show \"suffixeq (x # xs) as\" unfolding as'_def .\n      hence \"suffixeq xs as'\" by (auto dest: suffixeq_ConsD simp: as'_def)\n      thus \"P xs\" using Cons.hyps by simp\n    qed\n  qed\nqed\n\ntext {* Parallel etc. and lemmas for list prefix *}\n\nlemma prefix_induct [consumes 1, case_names Nil Cons]:\n  fixes prefix\n  assumes np: \"prefix \\<le> lst\"\n  and base:   \"\\<And>xs. P [] xs\"\n  and rl:     \"\\<And>x xs y ys. \\<lbrakk> x = y; xs \\<le> ys; P xs ys \\<rbrakk> \\<Longrightarrow> P (x#xs) (y#ys)\"\n  shows \"P prefix lst\"\n  using np\nproof (induct prefix arbitrary: lst)\n  case Nil show ?case by fact\nnext\n  case (Cons x xs)\n\n  have prem: \"(x # xs) \\<le> lst\" by fact\n  then obtain y ys where lv: \"lst = y # ys\"\n    by (rule prefixE, auto)\n\n  have ih: \"\\<And>lst. xs \\<le> lst \\<Longrightarrow> P xs lst\" by fact\n\n  show ?case using prem\n    by (auto simp: lv intro!: rl ih)\nqed\n\nlemma not_prefix_cases:\n  fixes prefix\n  assumes pfx: \"\\<not> prefix \\<le> lst\"\n  and c1: \"\\<lbrakk> prefix \\<noteq> []; lst = [] \\<rbrakk> \\<Longrightarrow> R\"\n  and c2: \"\\<And>a as x xs. \\<lbrakk> prefix = a#as; lst = x#xs; x = a; \\<not> as \\<le> xs\\<rbrakk> \\<Longrightarrow> R\"\n  and c3: \"\\<And>a as x xs. \\<lbrakk> prefix = a#as; lst = x#xs; x \\<noteq> a\\<rbrakk> \\<Longrightarrow> R\"\n  shows \"R\"\nproof (cases prefix)\n  case Nil thus ?thesis using pfx by simp\nnext\n  case (Cons a as)\n\n  have c: \"prefix = a#as\" by fact\n\n  show ?thesis\n  proof (cases lst)\n    case Nil thus ?thesis\n      by (intro c1, simp add: Cons)\n  next\n    case (Cons x xs)\n    show ?thesis\n    proof (cases \"x = a\")\n      case True\n      show ?thesis\n      proof (intro c2)\n     \tshow \"\\<not> as \\<le> xs\" using pfx c Cons True\n\t  by simp\n      qed fact+\n    next\n      case False\n      show ?thesis by (rule c3) fact+\n    qed\n  qed\nqed\n\nlemma not_prefix_induct [consumes 1, case_names Nil Neq Eq]:\n  fixes prefix\n  assumes np: \"\\<not> prefix \\<le> lst\"\n  and base:   \"\\<And>x xs. P (x#xs) []\"\n  and r1:     \"\\<And>x xs y ys. x \\<noteq> y \\<Longrightarrow> P (x#xs) (y#ys)\"\n  and r2:     \"\\<And>x xs y ys. \\<lbrakk> x = y; \\<not> xs \\<le> ys; P xs ys \\<rbrakk> \\<Longrightarrow> P (x#xs) (y#ys)\"\n  shows \"P prefix lst\"\n  using np\nproof (induct lst arbitrary: prefix)\n  case Nil thus ?case\n    by (auto simp: neq_Nil_conv elim!: not_prefix_cases intro!: base)\nnext\n  case (Cons y ys)\n\n  have npfx: \"\\<not> prefix \\<le> (y # ys)\" by fact\n  then obtain x xs where pv: \"prefix = x # xs\"\n    by (rule not_prefix_cases) auto\n\n  have ih: \"\\<And>prefix. \\<not> prefix \\<le> ys \\<Longrightarrow> P prefix ys\" by fact\n\n  show ?case using npfx\n    by (simp only: pv) (erule not_prefix_cases, auto intro: r1 r2 ih)\nqed\n\ntext {* right-padding a word to a certain length *}\n\nlemma bl_pad_to_prefix:\n  \"bl \\<le> bl_pad_to bl sz\"\n  by (simp add: bl_pad_to_def)\n\nlemma same_length_is_parallel:\n  assumes len: \"\\<forall>y \\<in> set as. length y = x\"\n  shows  \"\\<forall>x \\<in> set as. \\<forall>y \\<in> set as - {x}. x \\<parallel> y\"\nproof (rule, rule)\n  fix x y\n  assume xi: \"x \\<in> set as\" and yi: \"y \\<in> set as - {x}\"\n  from len obtain q where len': \"\\<forall>y \\<in> set as. length y = q\" ..\n\n  show \"x \\<parallel> y\"\n  proof (rule not_equal_is_parallel)\n    from xi yi show \"x \\<noteq> y\" by auto\n    from xi yi len' show \"length x = length y\" by (auto dest: bspec)\n  qed\nqed\n\ntext {* Lemmas about words *}\n\nlemma word_bits_len_of: \"len_of TYPE (32) = word_bits\"\n  by (simp add: word_bits_conv)\n\nlemmas unat_power_lower32 [simp] = unat_power_lower[where 'a=32, unfolded word_bits_len_of]\n\nlemma eq_zero_set_bl: \"(w = 0) = (True \\<notin> set (to_bl w))\"\n  apply (subst word_bl.Rep_inject[symmetric])\n  apply (subst to_bl_0)\n  apply (rule iffI)\n   apply clarsimp\n  apply (drule list_of_false)\n  apply simp\n  done\n\nlemmas and_bang = word_and_nth\n\nlemma of_drop_to_bl:\n  \"of_bl (drop n (to_bl x)) = (x && mask (size x - n))\"\n  apply (clarsimp simp: bang_eq and_bang test_bit_of_bl\n                        rev_nth\n                  cong: rev_conj_cong)\n  apply (safe, simp_all add: word_size to_bl_nth)\n  done\n\nlemma less_is_drop_replicate:\n  fixes x :: \"'a :: len word\"\n  assumes lt: \"x < 2 ^ n\"\n  shows   \"to_bl x = replicate (len_of TYPE('a) - n) False @ drop (len_of TYPE('a) - n) (to_bl x)\"\nproof -\n  show ?thesis\n    apply (subst less_mask_eq [OF lt, symmetric])\n    apply (subst bl_and_mask)\n    apply simp\n    done\nqed\n\nlemma word_add_offset_less:\n  fixes x :: \"'a :: len word\"\n  assumes yv: \"y < 2 ^ n\"\n  and     xv: \"x < 2 ^ m\"\n  and     mnv: \"sz < len_of TYPE('a :: len)\"\n  and    xv': \"x < 2 ^ (len_of TYPE('a :: len) - n)\"\n  and     mn: \"sz = m + n\"\n  shows   \"x * 2 ^ n + y < 2 ^ sz\"\nproof (subst mn)\n  from mnv mn have nv: \"n < len_of TYPE('a)\" and mv: \"m < len_of TYPE('a)\"  by auto\n\n  have uy: \"unat y < 2 ^ n\"\n     by (rule order_less_le_trans [OF unat_mono [OF yv] order_eq_refl],\n       rule unat_power_lower[OF nv])\n\n  have ux: \"unat x < 2 ^ m\"\n     by (rule order_less_le_trans [OF unat_mono [OF xv] order_eq_refl],\n       rule unat_power_lower[OF mv])\n\n  thus \"x * 2 ^ n + y < 2 ^ (m + n)\" using ux uy nv mnv xv'\n  apply (subst word_less_nat_alt)\n  apply (subst unat_word_ariths word_bits_len_of)+\n  apply (subst mod_less)\n   apply (simp add: unat_power_lower)\n   apply (subst mult.commute)\n   apply (rule nat_less_power_trans [OF _ order_less_imp_le [OF nv]])\n    apply (rule order_less_le_trans [OF unat_mono [OF xv']])\n    apply (cases \"n = 0\")\n       apply (simp add: unat_power_lower)\n      apply (simp add: unat_power_lower)\n    apply (subst unat_power_lower[OF nv])\n    apply (subst mod_less)\n   apply (erule order_less_le_trans [OF nat_add_offset_less], assumption)\n    apply (rule mn)\n   apply simp\n  apply (simp add: mn mnv unat_power_lower)\n  apply (erule nat_add_offset_less)\n  apply simp+\n  done\nqed\n\nlemma word_less_power_trans:\n  fixes n :: \"'a :: len word\"\n  assumes nv: \"n < 2 ^ (m - k)\"\n  and     kv: \"k \\<le> m\"\n  and     mv: \"m < len_of TYPE ('a)\"\n  shows \"2 ^ k * n < 2 ^ m\"\n  using nv kv mv\n  apply -\n  apply (subst word_less_nat_alt)\n  apply (subst unat_word_ariths)\n  apply (subst mod_less)\n   apply (simp add: unat_power_lower)\n   apply (rule nat_less_power_trans)\n    apply (erule order_less_trans [OF unat_mono])\n    apply (simp add: unat_power_lower)\n   apply simp\n  apply (simp add: unat_power_lower)\n  apply (rule nat_less_power_trans)\n   apply (subst unat_power_lower[where 'a = 'a, symmetric])\n    apply simp\n   apply (erule unat_mono)\n  apply simp\n  done\n\nlemma word_less_sub_le[simp]:\n  fixes x :: \"'a :: len word\"\n  assumes nv: \"n < len_of TYPE('a)\"\n  shows \"(x \\<le> 2 ^ n - 1) = (x < 2 ^ n)\"\nproof -\n  have \"Suc (unat ((2::'a word) ^ n - 1)) = unat ((2::'a word) ^ n)\" using nv\n    by (metis Suc_pred' power_2_ge_iff unat_gt_0 unat_minus_one word_not_simps(1))\n\n  thus ?thesis using nv\n    apply -\n    apply (subst word_le_nat_alt)\n    apply (subst less_Suc_eq_le [symmetric])\n    apply (erule ssubst)\n    apply (subst word_less_nat_alt)\n    apply (rule refl)\n    done\nqed\n\nlemmas word32_less_sub_le[simp] =\n       word_less_sub_le[where 'a = 32, folded word_bits_def]\n\nlemma Suc_unat_diff_1:\n  fixes x :: \"'a :: len word\"\n  assumes lt: \"1 \\<le> x\"\n  shows \"Suc (unat (x - 1)) = unat x\"\nproof -\n  have \"0 < unat x\"\n    by (rule order_less_le_trans [where y = 1], simp, subst unat_1 [symmetric], rule iffD1 [OF word_le_nat_alt lt])\n\n  thus ?thesis\n    by ((subst unat_sub [OF lt])+, simp only:  unat_1)\nqed\n\nlemma word_div_sub:\n  fixes x :: \"'a :: len word\"\n  assumes yx: \"y \\<le> x\"\n  and     y0: \"0 < y\"\n  shows \"(x - y) div y = x div y - 1\"\n  apply (rule word_unat.Rep_eqD)\n  apply (subst unat_div)\n  apply (subst unat_sub [OF yx])\n  apply (subst unat_sub)\n   apply (subst word_le_nat_alt)\n   apply (subst unat_div)\n   apply (subst le_div_geq)\n     apply (rule order_le_less_trans [OF _ unat_mono [OF y0]])\n     apply simp\n    apply (subst word_le_nat_alt [symmetric], rule yx)\n   apply simp\n  apply (subst unat_div)\n  apply (subst le_div_geq [OF _ iffD1 [OF word_le_nat_alt yx]])\n   apply (rule order_le_less_trans [OF _ unat_mono [OF y0]])\n   apply simp\n  apply simp\n  done\n\nlemma word_mult_less_mono1:\n  fixes i :: \"'a :: len word\"\n  assumes ij: \"i < j\"\n  and    knz: \"0 < k\"\n  and    ujk: \"unat j * unat k < 2 ^ len_of TYPE ('a)\"\n  shows  \"i * k < j * k\"\nproof -\n  from ij ujk knz have jk: \"unat i * unat k < 2 ^ len_of TYPE ('a)\"\n    by (auto intro: order_less_subst2 simp: word_less_nat_alt elim: mult_less_mono1)\n\n  thus ?thesis using ujk knz ij\n    by (auto simp: word_less_nat_alt iffD1 [OF unat_mult_lem])\nqed\n\nlemma word_mult_less_dest:\n  fixes i :: \"'a :: len word\"\n  assumes ij: \"i * k < j * k\"\n  and    uik: \"unat i * unat k < 2 ^ len_of TYPE ('a)\"\n  and    ujk: \"unat j * unat k < 2 ^ len_of TYPE ('a)\"\n  shows  \"i < j\"\n  using uik ujk ij\n  by (auto simp: word_less_nat_alt iffD1 [OF unat_mult_lem] elim: mult_less_mono1)\n\nlemma word_mult_less_cancel:\n  fixes k :: \"'a :: len word\"\n  assumes knz: \"0 < k\"\n  and    uik: \"unat i * unat k < 2 ^ len_of TYPE ('a)\"\n  and    ujk: \"unat j * unat k < 2 ^ len_of TYPE ('a)\"\n  shows \"(i * k < j * k) = (i < j)\"\n  by (rule iffI [OF word_mult_less_dest [OF _ uik ujk] word_mult_less_mono1 [OF _ knz ujk]])\n\nlemma Suc_div_unat_helper:\n  assumes szv: \"sz < len_of TYPE('a :: len)\"\n  and   usszv: \"us \\<le> sz\"\n  shows \"2 ^ (sz - us) = Suc (unat (((2::'a :: len word) ^ sz - 1) div 2 ^ us))\"\nproof -\n  note usv = order_le_less_trans [OF usszv szv]\n\n  from usszv obtain q where qv: \"sz = us + q\" by (auto simp: le_iff_add)\n\n  have \"Suc (unat (((2:: 'a word) ^ sz - 1) div 2 ^ us)) =\n    (2 ^ us + unat ((2:: 'a word) ^ sz - 1)) div 2 ^ us\"\n    apply (subst unat_div unat_power_lower[OF usv])+\n    apply (subst div_add_self1, simp+)\n    done\n\n  also have \"\\<dots> = ((2 ^ us - 1) + 2 ^ sz) div 2 ^ us\" using szv\n    apply (subst unat_minus_one)\n     apply (simp add: p2_eq_0)\n    apply (simp add: unat_power_lower)\n    done\n\n  also have \"\\<dots> = 2 ^ q + ((2 ^ us - 1) div 2 ^ us)\"\n    apply (subst qv)\n    apply (subst power_add)\n    apply (subst div_mult_self2)\n    apply simp\n    apply (rule refl)\n    done\n\n  also have \"\\<dots> = 2 ^ (sz - us)\" using qv by simp\n\n  finally show ?thesis ..\nqed\n\nlemma upto_enum_red':\n  assumes lt: \"1 \\<le> X\"\n  shows \"[(0::'a :: len word) .e. X - 1] =  map of_nat [0 ..< unat X]\"\nproof -\n  have lt': \"unat X < 2 ^ len_of TYPE('a)\"\n    by (rule unat_lt2p)\n\n  show ?thesis\n    apply (subst upto_enum_red)\n    apply (simp del: upt.simps)\n    apply (subst Suc_unat_diff_1 [OF lt])\n    apply (rule map_cong [OF refl])\n    apply (rule toEnum_of_nat)\n    apply simp\n    apply (erule order_less_trans [OF _ lt'])\n    done\nqed\n\nlemma upto_enum_red2:\n  assumes szv: \"sz < len_of TYPE('a :: len)\"\n  shows \"[(0:: 'a :: len word) .e. 2 ^ sz - 1] =\n  map of_nat [0 ..< 2 ^ sz]\" using szv\n  apply (subst unat_power_lower[OF szv, symmetric])\n  apply (rule upto_enum_red')\n  apply (subst word_le_nat_alt, simp add: unat_power_lower)\n  done\n\n(* FIXME: WordEnum.upto_enum_step_def is fixed to word32. *)\nlemma upto_enum_step_red:\n  assumes szv: \"sz < word_bits\"\n  and   usszv: \"us \\<le> sz\"\n  shows \"[0 , 2 ^ us .e. 2 ^ sz - 1] =\n  map (\\<lambda>x. of_nat x * 2 ^ us) [0 ..< 2 ^ (sz - us)]\" using szv\n  unfolding upto_enum_step_def\n  apply (subst if_not_P)\n   apply (rule leD)\n   apply (subst word_le_nat_alt)\n   apply (subst unat_minus_one)\n    apply (simp add: p2_eq_0 word_bits_def)\n   apply simp\n  apply simp\n  apply (subst upto_enum_red)\n  apply (simp del: upt.simps)\n  apply (subst Suc_div_unat_helper [where 'a = 32, folded word_bits_def, OF szv usszv, symmetric])\n  apply clarsimp\n  apply (subst toEnum_of_nat)\n   apply (subst word_bits_len_of)\n   apply (erule order_less_trans)\n   using szv\n   apply simp\n  apply simp\n  done\n\nlemma upto_enum_word:\n  \"[x .e. y] = map of_nat [unat x ..< Suc (unat y)]\"\n  apply (subst upto_enum_red)\n  apply clarsimp\n  apply (subst toEnum_of_nat)\n   prefer 2\n   apply (rule refl)\n  apply (erule disjE, simp)\n  apply clarsimp\n  apply (erule order_less_trans)\n  apply simp\n  done\n\ntext {* Lemmas about upto and upto_enum *}\n\nlemma word_upto_Cons_eq:\n  \"\\<lbrakk>x = z; x < y; Suc (unat y) < 2 ^ len_of TYPE('a)\\<rbrakk>\n   \\<Longrightarrow> [x::'a::len word .e. y] = z # [x + 1 .e. y]\"\n  apply (subst upto_enum_red)\n  apply (subst upt_conv_Cons)\n   apply (simp)\n   apply (drule unat_mono)\n   apply arith\n  apply (simp only: list.map)\n  apply (subst list.inject)\n  apply rule\n   apply (rule to_from_enum)\n   apply (subst upto_enum_red)\n  apply (rule map_cong [OF _ refl])\n  apply (rule arg_cong2 [where f = \"\\<lambda>x y. [x ..< y]\"])\n   apply unat_arith\n  apply simp\n  done\n\nlemma distinct_enum_upto:\n  \"distinct [(0 :: 'a::len word) .e. b]\"\nproof -\n  have \"\\<And>(b::'a word). [0 .e. b] = sublist enum {..< Suc (fromEnum b)}\"\n    apply (subst upto_enum_red)\n    apply (subst sublist_upt_eq_take)\n    apply (subst enum_word_def)\n    apply (subst take_map)\n    apply (subst take_upt)\n     apply (simp only: add_0 fromEnum_unat)\n     apply (rule order_trans [OF _ order_eq_refl])\n      apply (rule Suc_leI [OF unat_lt2p])\n     apply simp\n    apply clarsimp\n    apply (rule toEnum_of_nat)\n    apply (erule order_less_trans [OF _ unat_lt2p])\n    done\n\n  thus ?thesis\n    by (rule ssubst) (rule distinct_sublistI, simp)\nqed\n\nlemma upto_enum_set_conv [simp]:\n  fixes a :: \"'a :: len word\"\n  shows \"set [a .e. b] = {x. a \\<le> x \\<and> x \\<le> b}\"\n  apply (subst upto_enum_red)\n  apply (subst set_map)\n  apply safe\n    apply simp\n    apply clarsimp\n    apply (erule disjE)\n     apply simp\n     apply (erule iffD2 [OF word_le_nat_alt])\n    apply clarsimp\n    apply (erule word_unat.Rep_cases [OF unat_le [OF order_less_imp_le]])\n    apply simp\n    apply (erule iffD2 [OF word_le_nat_alt])\n   apply simp\n\n   apply clarsimp\n   apply (erule disjE)\n    apply simp\n   apply clarsimp\n   apply (rule word_unat.Rep_cases [OF unat_le  [OF order_less_imp_le]])\n    apply assumption\n   apply simp\n   apply (erule order_less_imp_le [OF iffD2 [OF word_less_nat_alt]])\n  apply clarsimp\n  apply (rule_tac x=\"fromEnum x\" in image_eqI)\n   apply clarsimp\n  apply clarsimp\n  apply (rule conjI)\n   apply (subst word_le_nat_alt [symmetric])\n   apply simp\n  apply safe\n   apply (simp add: word_le_nat_alt [symmetric])\n  apply (simp add: word_less_nat_alt [symmetric])\n  done\n\nlemma upto_enum_less:\n  assumes xin: \"x \\<in> set [(a::'a::len word).e.2 ^ n - 1]\"\n  and     nv:  \"n < len_of TYPE('a::len)\"\n  shows   \"x < 2 ^ n\"\nproof (cases n)\n  case 0\n  thus ?thesis using xin\n    by (simp add: upto_enum_set_conv)\nnext\n  case (Suc m)\n  show ?thesis using xin nv by simp\nqed\n\nlemma upto_enum_len_less:\n  \"\\<lbrakk> n \\<le> length [a, b .e. c]; n \\<noteq> 0 \\<rbrakk> \\<Longrightarrow> a \\<le> c\"\n  unfolding upto_enum_step_def\n  by (simp split: split_if_asm)\n\nlemma length_upto_enum_step:\n  fixes x :: word32\n  shows \"x \\<le> z \\<Longrightarrow> length [x , y .e. z] = (unat ((z - x) div (y - x))) + 1\"\n  unfolding upto_enum_step_def\n  by (simp add: upto_enum_red)\n\nlemma length_upto_enum_one:\n  fixes x :: word32\n  assumes lt1: \"x < y\" and lt2: \"z < y\" and lt3: \"x \\<le> z\"\n  shows \"[x , y .e. z] = [x]\"\nunfolding upto_enum_step_def\nproof (subst upto_enum_red, subst if_not_P [OF leD [OF lt3]], clarsimp, rule)\n  show \"unat ((z - x) div (y - x)) = 0\"\n  proof (subst unat_div, rule div_less)\n    have syx: \"unat (y - x) = unat y - unat x\"\n      by (rule unat_sub [OF order_less_imp_le]) fact\n    moreover have \"unat (z - x) = unat z - unat x\"\n      by (rule unat_sub) fact\n\n    ultimately show \"unat (z - x) < unat (y - x)\"\n      using lt3\n      apply simp\n      apply (rule diff_less_mono[OF unat_mono, OF lt2])\n      apply (simp add: word_le_nat_alt[symmetric])\n      done\n  qed\n\n  thus \"toEnum (unat ((z - x) div (y - x))) * (y - x) = 0\" by simp\nqed\n\nlemma map_length_unfold_one:\n  fixes x :: \"'a::len word\"\n  assumes xv: \"Suc (unat x) < 2 ^ len_of TYPE('a)\"\n  and     ax: \"a < x\"\n  shows   \"map f [a .e. x] = f a # map f [a + 1 .e. x]\"\n  by (subst word_upto_Cons_eq, auto, fact+)\n\nlemma upto_enum_triv [simp]:\n  \"[x .e. x] = [x]\"\n  unfolding upto_enum_def by simp\n\n\n\nlemma of_nat_unat [simp]:\n  \"of_nat \\<circ> unat = id\"\n  by (rule ext, simp)\n\nlemma Suc_unat_minus_one [simp]:\n  \"x \\<noteq> 0 \\<Longrightarrow> Suc (unat (x - 1)) = unat x\"\n  by (metis Suc_diff_1 unat_gt_0 unat_minus_one)\n\ntext {* Lemmas about alignment *}\n\nlemma word_bits_size:\n  \"size (w::word32) = word_bits\"\n  by (simp add: word_bits_def word_size)\n\ntext {* Lemmas about defs in the specs *}\n\nlemma and_commute:\n  \"(X and Y) = (Y and X)\"\n  unfolding pred_conj_def by (auto simp: fun_eq_iff)\n\nlemma ptr_add_0 [simp]:\n  \"ptr_add ref 0 = ref \"\n  unfolding ptr_add_def by simp\n\n(* Other word lemmas *)\n\nlemma word_add_le_dest:\n  fixes i :: \"'a :: len word\"\n  assumes le: \"i + k \\<le> j + k\"\n  and    uik: \"unat i + unat k < 2 ^ len_of TYPE ('a)\"\n  and    ujk: \"unat j + unat k < 2 ^ len_of TYPE ('a)\"\n  shows  \"i \\<le> j\"\n  using uik ujk le\n  by (auto simp: word_le_nat_alt iffD1 [OF unat_add_lem] elim: add_le_mono1)\n\nlemma mask_shift:\n  \"(x && ~~ mask y) >> y = x >> y\"\n  apply (rule word_eqI)\n  apply (simp add: nth_shiftr word_size)\n  apply safe\n  apply (drule test_bit.Rep[simplified, rule_format])\n  apply (simp add: word_size word_ops_nth_size)\n  done\n\nlemma word_add_le_mono1:\n  fixes i :: \"'a :: len word\"\n  assumes ij: \"i \\<le> j\"\n  and    ujk: \"unat j + unat k < 2 ^ len_of TYPE ('a)\"\n  shows  \"i + k \\<le> j + k\"\nproof -\n  from ij ujk have jk: \"unat i + unat k < 2 ^ len_of TYPE ('a)\"\n    by (auto elim: order_le_less_subst2 simp: word_le_nat_alt elim: add_le_mono1)\n\n  thus ?thesis using ujk ij\n    by (auto simp: word_le_nat_alt iffD1 [OF unat_add_lem])\nqed\n\nlemma word_add_le_mono2:\n  fixes i :: \"('a :: len) word\"\n  shows \"\\<lbrakk>i \\<le> j; unat j + unat k < 2 ^ len_of TYPE('a)\\<rbrakk> \\<Longrightarrow> k + i \\<le> k + j\"\n  by (subst field_simps, subst field_simps, erule (1) word_add_le_mono1)\n\nlemma word_add_le_iff:\n  fixes i :: \"'a :: len word\"\n  assumes uik: \"unat i + unat k < 2 ^ len_of TYPE ('a)\"\n  and     ujk: \"unat j + unat k < 2 ^ len_of TYPE ('a)\"\n  shows  \"(i + k \\<le> j + k) = (i \\<le> j)\"\nproof\n  assume \"i \\<le> j\"\n  show \"i + k \\<le> j + k\" by (rule word_add_le_mono1) fact+\nnext\n  assume \"i + k \\<le> j + k\"\n  show \"i \\<le> j\" by (rule word_add_le_dest) fact+\nqed\n\nlemma word_add_less_mono1:\n  fixes i :: \"'a :: len word\"\n  assumes ij: \"i < j\"\n  and    ujk: \"unat j + unat k < 2 ^ len_of TYPE ('a)\"\n  shows  \"i + k < j + k\"\nproof -\n  from ij ujk have jk: \"unat i + unat k < 2 ^ len_of TYPE ('a)\"\n    by (auto elim: order_le_less_subst2 simp: word_less_nat_alt elim: add_less_mono1)\n\n  thus ?thesis using ujk ij\n    by (auto simp: word_less_nat_alt iffD1 [OF unat_add_lem])\nqed\n\nlemma word_add_less_dest:\n  fixes i :: \"'a :: len word\"\n  assumes le: \"i + k < j + k\"\n  and    uik: \"unat i + unat k < 2 ^ len_of TYPE ('a)\"\n  and    ujk: \"unat j + unat k < 2 ^ len_of TYPE ('a)\"\n  shows  \"i < j\"\n  using uik ujk le\n  by (auto simp: word_less_nat_alt iffD1 [OF unat_add_lem] elim: add_less_mono1)\n\nlemma word_add_less_iff:\n  fixes i :: \"'a :: len word\"\n  assumes uik: \"unat i + unat k < 2 ^ len_of TYPE ('a)\"\n  and     ujk: \"unat j + unat k < 2 ^ len_of TYPE ('a)\"\n  shows  \"(i + k < j + k) = (i < j)\"\nproof\n  assume \"i < j\"\n  show \"i + k < j + k\" by (rule word_add_less_mono1) fact+\nnext\n  assume \"i + k < j + k\"\n  show \"i < j\" by (rule word_add_less_dest) fact+\nqed\n\nlemma shiftr_div_2n':\n  \"unat (w >> n) = unat w div 2 ^ n\"\n  apply (unfold unat_def)\n  apply (subst shiftr_div_2n)\n  apply (subst nat_div_distrib)\n   apply simp\n  apply (simp add: nat_power_eq)\n  done\n\nlemma shiftl_shiftr_id:\n  assumes nv: \"n < len_of TYPE('a :: len)\"\n  and     xv: \"x < 2 ^ (len_of TYPE('a :: len) - n)\"\n  shows \"x << n >> n = (x::'a::len word)\"\n  apply (simp add: shiftl_t2n)\n  apply (rule word_unat.Rep_eqD)\n  apply (subst shiftr_div_2n')\n  apply (cases n)\n   apply simp\n  apply (subst iffD1 [OF unat_mult_lem])+\n   apply (subst unat_power_lower[OF nv])\n   apply (rule nat_less_power_trans [OF _ order_less_imp_le [OF nv]])\n   apply (rule order_less_le_trans [OF unat_mono [OF xv] order_eq_refl])\n   apply (rule unat_power_lower)\n   apply simp\n  apply (subst unat_power_lower[OF nv])\n  apply simp\n  done\n\nlemma word_mult_less_iff:\n  fixes i :: \"'a :: len word\"\n  assumes knz: \"0 < k\"\n  and     uik: \"unat i * unat k < 2 ^ len_of TYPE ('a)\"\n  and     ujk: \"unat j * unat k < 2 ^ len_of TYPE ('a)\"\n  shows  \"(i * k < j * k) = (i < j)\"\nproof\n  assume \"i < j\"\n  show \"i * k < j * k\" by (rule word_mult_less_mono1) fact+\nnext\n  assume p: \"i * k < j * k\"\n\n  have \"0 < unat k\" using knz by (simp add: word_less_nat_alt)\n  thus \"i < j\" using p\n    by (clarsimp simp: word_less_nat_alt iffD1 [OF unat_mult_lem uik]\n      iffD1 [OF unat_mult_lem ujk])\nqed\n\nlemma word_le_imp_diff_le:\n  fixes n :: \"'a::len word\"\n  shows \"\\<lbrakk>k \\<le> n; n \\<le> m\\<rbrakk> \\<Longrightarrow> n - k \\<le> m\"\n  by (clarsimp simp: unat_sub word_le_nat_alt intro!: le_imp_diff_le)\n\nlemma word_less_imp_diff_less:\n  fixes n :: \"'a::len word\"\n  shows \"\\<lbrakk>k \\<le> n; n < m\\<rbrakk> \\<Longrightarrow> n - k < m\"\n  by (clarsimp simp: unat_sub word_less_nat_alt\n             intro!: less_imp_diff_less)\n\nlemma word_mult_le_mono1:\n  fixes i :: \"'a :: len word\"\n  assumes ij: \"i \\<le> j\"\n  and    knz: \"0 < k\"\n  and    ujk: \"unat j * unat k < 2 ^ len_of TYPE ('a)\"\n  shows  \"i * k \\<le> j * k\"\nproof -\n  from ij ujk knz have jk: \"unat i * unat k < 2 ^ len_of TYPE ('a)\"\n    by (auto elim: order_le_less_subst2 simp: word_le_nat_alt elim: mult_le_mono1)\n\n  thus ?thesis using ujk knz ij\n    by (auto simp: word_le_nat_alt iffD1 [OF unat_mult_lem])\nqed\n\nlemma word_mult_le_iff:\n  fixes i :: \"'a :: len word\"\n  assumes knz: \"0 < k\"\n  and     uik: \"unat i * unat k < 2 ^ len_of TYPE ('a)\"\n  and     ujk: \"unat j * unat k < 2 ^ len_of TYPE ('a)\"\n  shows  \"(i * k \\<le> j * k) = (i \\<le> j)\"\nproof\n  assume \"i \\<le> j\"\n  show \"i * k \\<le> j * k\" by (rule word_mult_le_mono1) fact+\nnext\n  assume p: \"i * k \\<le> j * k\"\n\n  have \"0 < unat k\" using knz by (simp add: word_less_nat_alt)\n  thus \"i \\<le> j\" using p\n    by (clarsimp simp: word_le_nat_alt iffD1 [OF unat_mult_lem uik]\n      iffD1 [OF unat_mult_lem ujk])\nqed\n\nlemma word_diff_less:\n  fixes n :: \"'a :: len word\"\n  shows \"\\<lbrakk>0 < n; 0 < m; n \\<le> m\\<rbrakk> \\<Longrightarrow> m - n < m\"\n  apply (subst word_less_nat_alt)\n  apply (subst unat_sub)\n   apply assumption\n  apply (rule diff_less)\n   apply (simp_all add: word_less_nat_alt)\n   done\n\nlemma MinI:\n  assumes fa: \"finite A\"\n  and     ne: \"A \\<noteq> {}\"\n  and     xv: \"m \\<in> A\"\n  and    min: \"\\<forall>y \\<in> A. m \\<le> y\"\n  shows \"Min A = m\" using fa ne xv min\nproof (induct A arbitrary: m rule: finite_ne_induct)\n  case singleton thus ?case by simp\nnext\n  case (insert y F)\n\n  from insert.prems have yx: \"m \\<le> y\" and fx: \"\\<forall>y \\<in> F. m \\<le> y\" by auto\n  have \"m \\<in> insert y F\" by fact\n  thus ?case\n  proof\n    assume mv: \"m = y\"\n\n    have mlt: \"m \\<le> Min F\"\n      by (rule iffD2 [OF Min_ge_iff [OF insert.hyps(1) insert.hyps(2)] fx])\n\n    show ?case\n      apply (subst Min_insert [OF insert.hyps(1) insert.hyps(2)])\n      apply (subst mv [symmetric])\n      apply (rule iffD2 [OF linorder_min_same1 mlt])\n      done\n  next\n    assume \"m \\<in> F\"\n    hence mf: \"Min F = m\"\n      by (rule insert.hyps(4) [OF _ fx])\n\n    show ?case\n      apply (subst Min_insert [OF insert.hyps(1) insert.hyps(2)])\n      apply (subst mf)\n      apply (rule iffD2 [OF linorder_min_same2 yx])\n      done\n  qed\nqed\n\nlemma length_upto_enum [simp]:\n  fixes a :: \"('a :: len) word\"\n  shows \"length [a .e. b] = Suc (unat b) - unat a\"\n  apply (simp add: word_le_nat_alt upto_enum_red)\n  apply (clarsimp simp: Suc_diff_le)\n  done\n\nlemma length_upto_enum_less_one:\n  \"\\<lbrakk>a \\<le> b; b \\<noteq> 0\\<rbrakk>\n  \\<Longrightarrow> length [a .e. b - 1] = unat (b - a)\"\n  apply clarsimp\n  apply (subst unat_sub[symmetric], assumption)\n  apply clarsimp\n  done\n\nlemma drop_upto_enum:\n  \"drop (unat n) [0 .e. m] = [n .e. m]\"\n  apply (clarsimp simp: upto_enum_def)\n  apply (induct m, simp)\n  by (metis drop_map drop_upt plus_nat.add_0)\n\nlemma distinct_enum_upto' [simp]:\n  \"distinct [a::'a::len word .e. b]\"\n  apply (subst drop_upto_enum [symmetric])\n  apply (rule distinct_drop)\n  apply (rule distinct_enum_upto)\n  done\n\nlemma length_interval:\n  \"\\<lbrakk>set xs = {x. (a::'a::len word) \\<le> x \\<and> x \\<le> b}; distinct xs\\<rbrakk>\n  \\<Longrightarrow> length xs = Suc (unat b) - unat a\"\n  apply (frule distinct_card)\n  apply (subgoal_tac \"set xs = set [a .e. b]\")\n   apply (cut_tac distinct_card [where xs=\"[a .e. b]\"])\n    apply (subst (asm) length_upto_enum)\n    apply clarsimp\n   apply (rule distinct_enum_upto')\n  apply simp\n  done\n\nlemma not_empty_eq:\n  \"(S \\<noteq> {}) = (\\<exists>x. x \\<in> S)\"\n  by auto\n\nlemma range_subset_lower:\n  fixes c :: \"'a ::linorder\"\n  shows \"\\<lbrakk> {a..b} \\<subseteq> {c..d}; x \\<in> {a..b} \\<rbrakk> \\<Longrightarrow> c \\<le> a\"\n  apply (frule (1) subsetD)\n  apply (rule classical)\n  apply clarsimp\n  done\n\nlemma range_subset_upper:\n  fixes c :: \"'a ::linorder\"\n  shows \"\\<lbrakk> {a..b} \\<subseteq> {c..d}; x \\<in> {a..b} \\<rbrakk> \\<Longrightarrow> b \\<le> d\"\n  apply (frule (1) subsetD)\n  apply (rule classical)\n  apply clarsimp\n  done\n\nlemma range_subset_eq:\n  fixes a::\"'a::linorder\"\n  assumes non_empty: \"a \\<le> b\"\n  shows \"({a..b} \\<subseteq> {c..d}) = (c \\<le> a \\<and> b \\<le> d)\"\n  apply (insert non_empty)\n  apply (rule iffI)\n   apply (frule range_subset_lower [where x=a], simp)\n   apply (drule range_subset_upper [where x=a], simp)\n   apply simp\n  apply auto\n  done\n\nlemma range_eq:\n  fixes a::\"'a::linorder\"\n  assumes non_empty: \"a \\<le> b\"\n  shows \"({a..b} = {c..d}) = (a = c \\<and> b = d)\"\n  by (metis atLeastatMost_subset_iff eq_iff non_empty)\n\nlemma range_strict_subset_eq:\n  fixes a::\"'a::linorder\"\n  assumes non_empty: \"a \\<le> b\"\n  shows \"({a..b} \\<subset> {c..d}) = (c \\<le> a \\<and> b \\<le> d \\<and> (a = c \\<longrightarrow> b \\<noteq> d))\"\n  apply (insert non_empty)\n  apply (subst psubset_eq)\n  apply (subst range_subset_eq, assumption+)\n  apply (subst range_eq, assumption+)\n  apply simp\n  done\n\nlemma range_subsetI:\n  fixes x :: \"'a :: order\"\n  assumes xX: \"X \\<le> x\"\n  and     yY: \"y \\<le> Y\"\n  shows   \"{x .. y} \\<subseteq> {X .. Y}\"\n  using xX yY by auto\n\nlemma set_False [simp]:\n  \"(set bs \\<subseteq> {False}) = (True \\<notin> set bs)\" by auto\n\ndeclare of_nat_power [simp del]\n\n(* TODO: move to word *)\nlemma unat_of_bl_length:\n  \"unat (of_bl xs :: 'a::len word) < 2 ^ (length xs)\"\nproof (cases \"length xs < len_of TYPE('a)\")\n  case True\n  hence \"(of_bl xs::'a::len word) < 2 ^ length xs\"\n    by (simp add: of_bl_length_less)\n  with True\n  show ?thesis\n    by (simp add: word_less_nat_alt word_unat_power unat_of_nat)\nnext\n  case False\n  have \"unat (of_bl xs::'a::len word) < 2 ^ len_of TYPE('a)\"\n    by (simp split: unat_split)\n  also\n  from False\n  have \"len_of TYPE('a) \\<le> length xs\" by simp\n  hence \"2 ^ len_of TYPE('a) \\<le> (2::nat) ^ length xs\"\n    by (rule power_increasing) simp\n  finally\n  show ?thesis .\nqed\n\nlemma is_aligned_0'[simp]:\n  \"is_aligned 0 n\"\n  by (simp add: is_aligned_def)\n\nlemma p_assoc_help:\n  fixes p :: \"'a::{ring,power,numeral,one}\"\n  shows \"p + 2^sz - 1 = p + (2^sz - 1)\"\n  by simp\n\nlemma word_add_increasing:\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk> p + w \\<le> x; p \\<le> p + w \\<rbrakk> \\<Longrightarrow> p \\<le> x\"\n  by unat_arith\n\nlemma word_random:\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk> p \\<le> p + x'; x \\<le> x' \\<rbrakk> \\<Longrightarrow> p \\<le> p + x\"\n  by unat_arith\n\nlemma word_sub_mono:\n  \"\\<lbrakk> a \\<le> c; d \\<le> b; a - b \\<le> a; c - d \\<le> c \\<rbrakk>\n    \\<Longrightarrow> (a - b) \\<le> (c - d :: ('a :: len) word)\"\n  by unat_arith\n\nlemma power_not_zero:\n  \"n < len_of TYPE('a::len) \\<Longrightarrow> (2 :: 'a word) ^ n \\<noteq> 0\"\n  by (metis p2_gt_0 word_neq_0_conv)\n\nlemma word_gt_a_gt_0:\n  \"a < n \\<Longrightarrow> (0 :: 'a::len word) < n\"\n  apply (case_tac \"n = 0\")\n   apply clarsimp\n  apply (clarsimp simp: word_neq_0_conv)\n  done\n\nlemma word_shift_nonzero:\n  \"\\<lbrakk> (x\\<Colon>'a\\<Colon>len word) \\<le> 2 ^ m; m + n < len_of TYPE('a\\<Colon>len); x \\<noteq> 0\\<rbrakk>\n   \\<Longrightarrow> x << n \\<noteq> 0\"\n  apply (simp only: word_neq_0_conv word_less_nat_alt\n                    shiftl_t2n mod_0 unat_word_ariths\n                    unat_power_lower word_le_nat_alt)\n  apply (subst mod_less)\n   apply (rule order_le_less_trans)\n    apply (erule mult_le_mono2)\n   apply (subst power_add[symmetric])\n   apply (rule power_strict_increasing)\n    apply simp\n   apply simp\n  apply simp\n  done\n\nlemma word_power_less_1 [simp]:\n  \"sz < len_of TYPE('a\\<Colon>len) \\<Longrightarrow> (2::'a word) ^ sz - 1 < 2 ^ sz\"\n  apply (simp add: word_less_nat_alt word_bits_def)\n  apply (subst unat_minus_one)\n  apply (simp add: word_unat.Rep_inject [symmetric])\n  apply simp\n  done\n\nlemmas word32_power_less_1[simp] =\n       word_power_less_1[where 'a = 32, folded word_bits_def]\n\nlemma nasty_split_lt:\n  \"\\<lbrakk> (x :: 'a:: len word) < 2 ^ (m - n); n \\<le> m; m < len_of TYPE('a\\<Colon>len) \\<rbrakk>\n     \\<Longrightarrow> x * 2 ^ n + (2 ^ n - 1) \\<le> 2 ^ m - 1\"\n  apply (simp only: add_diff_eq word_bits_def)\n  apply (subst mult_1[symmetric], subst distrib_right[symmetric])\n  apply (rule word_sub_mono)\n     apply (rule order_trans)\n      apply (rule word_mult_le_mono1)\n        apply (rule inc_le)\n        apply assumption\n       apply (subst word_neq_0_conv[symmetric])\n       apply (rule power_not_zero)\n       apply (simp add: word_bits_def)\n      apply (subst unat_power_lower, simp)+\n      apply (subst power_add[symmetric])\n      apply (rule power_strict_increasing)\n       apply (simp add: word_bits_def)\n      apply simp\n     apply (subst power_add[symmetric])\n     apply simp\n    apply simp\n   apply (rule word_sub_1_le)\n   apply (subst mult.commute)\n   apply (subst shiftl_t2n[symmetric])\n   apply (rule word_shift_nonzero)\n     apply (erule inc_le)\n    apply (simp add: word_bits_def)\n   apply (unat_arith)\n  apply (drule word_power_less_1[unfolded word_bits_def])\n  apply simp\n  done\n\nlemma nasty_split_less:\n  \"\\<lbrakk>m \\<le> n; n \\<le> nm; nm < len_of TYPE('a\\<Colon>len); x < 2 ^ (nm - n)\\<rbrakk>\n   \\<Longrightarrow> (x :: 'a word) * 2 ^ n + (2 ^ m - 1) < 2 ^ nm\"\n  apply (simp only: word_less_sub_le[symmetric])\n  apply (rule order_trans [OF _ nasty_split_lt])\n     apply (rule word_plus_mono_right)\n      apply (rule word_sub_mono)\n         apply (simp add: word_le_nat_alt)\n        apply simp\n       apply (simp add: word_sub_1_le[OF power_not_zero])\n      apply (simp add: word_sub_1_le[OF power_not_zero])\n     apply (rule is_aligned_no_wrap')\n      apply (rule is_aligned_mult_triv2)\n     apply simp\n    apply (erule order_le_less_trans, simp)\n   apply simp+\n  done\n\nlemma int_not_emptyD:\n  \"A \\<inter> B \\<noteq> {} \\<Longrightarrow> \\<exists>x. x \\<in> A \\<and> x \\<in> B\"\n  by (erule contrapos_np, clarsimp simp: disjoint_iff_not_equal)\n\nlemma unat_less_power:\n  fixes k :: \"'a::len word\"\n  assumes szv: \"sz < len_of TYPE('a)\"\n  and     kv:  \"k < 2 ^ sz\"\n  shows   \"unat k < 2 ^ sz\"\n  using szv unat_mono [OF kv] by simp\n\n(* This should replace some crud \\<dots> search for unat_of_nat *)\nlemma unat_mult_power_lem:\n  assumes kv: \"k < 2 ^ (len_of TYPE('a::len) - sz)\"\n  shows \"unat (2 ^ sz * of_nat k :: (('a::len) word)) = 2 ^ sz * k\"\nproof cases\n  assume szv: \"sz < len_of TYPE('a::len)\"\n  show ?thesis\n  proof (cases \"sz = 0\")\n    case True\n    thus ?thesis using kv szv\n     by (simp add: unat_of_nat)\n  next\n    case False\n    hence sne: \"0 < sz\" ..\n\n    have uk: \"unat (of_nat k :: 'a word) = k\"\n      apply (subst unat_of_nat)\n      apply (simp add: nat_mod_eq less_trans[OF kv] sne)\n      done\n\n    show ?thesis using szv\n      apply (subst iffD1 [OF unat_mult_lem])\n      apply (simp add: uk nat_less_power_trans[OF kv order_less_imp_le [OF szv]])+\n      done\n  qed\nnext\n  assume \"\\<not> sz < len_of TYPE('a)\"\n  with kv show ?thesis by (simp add: not_less power_overflow)\nqed\n\nlemma aligned_add_offset_no_wrap:\n  fixes off :: \"('a::len) word\"\n  and     x :: \"'a word\"\n  assumes al: \"is_aligned x sz\"\n  and   offv: \"off < 2 ^ sz\"\n  shows  \"unat x + unat off < 2 ^ len_of TYPE('a)\"\nproof cases\n  assume szv: \"sz < len_of TYPE('a)\"\n  from al obtain k where xv: \"x = 2 ^ sz * (of_nat k)\"\n    and kl: \"k < 2 ^ (len_of TYPE('a) - sz)\"\n    by (auto elim: is_alignedE)\n\n  show ?thesis using szv\n    apply (subst xv)\n    apply (subst unat_mult_power_lem[OF kl])\n    apply (subst mult.commute, rule nat_add_offset_less)\n      apply (rule less_le_trans[OF unat_mono[OF offv, simplified]])\n      apply (erule eq_imp_le[OF unat_power_lower])\n     apply (rule kl)\n    apply simp\n   done\nnext\n  assume \"\\<not> sz < len_of TYPE('a)\"\n  with offv show ?thesis by (simp add: not_less power_overflow )\nqed\n\nlemma aligned_add_offset_mod:\n  fixes x :: \"('a::len) word\"\n  assumes al: \"is_aligned x sz\"\n  and     kv: \"k < 2 ^ sz\"\n  shows   \"(x + k) mod 2 ^ sz = k\"\nproof cases\n  assume szv: \"sz < len_of TYPE('a)\"\n\n  have ux: \"unat x + unat k < 2 ^ len_of TYPE('a)\"\n    by (rule aligned_add_offset_no_wrap) fact+\n\n  show ?thesis using al szv\n    apply -\n    apply (erule is_alignedE)\n    apply (subst word_unat.Rep_inject [symmetric])\n    apply (subst unat_mod)\n    apply (subst iffD1 [OF unat_add_lem], rule ux)\n    apply simp\n    apply (subst unat_mult_power_lem, assumption+)\n    apply (subst mod_add_left_eq)\n    apply (simp)\n    apply (rule mod_less[OF less_le_trans[OF unat_mono], OF kv])\n    apply (erule eq_imp_le[OF unat_power_lower])\n    done\nnext\n  assume \"\\<not> sz < len_of TYPE('a)\"\n  with al show ?thesis\n    by (simp add: not_less power_overflow is_aligned_mask mask_def\n                  word_mod_by_0)\nqed\n\nlemma word_plus_mcs_4:\n  \"\\<lbrakk>v + x \\<le> w + x; x \\<le> v + x\\<rbrakk> \\<Longrightarrow> v \\<le> (w::'a::len word)\"\n  by uint_arith\n\nlemma word_plus_mcs_3:\n  \"\\<lbrakk>v \\<le> w; x \\<le> w + x\\<rbrakk> \\<Longrightarrow> v + x \\<le> w + (x::'a::len word)\"\n  by unat_arith\n\n\n\n    have rl: \"\\<And>(p::'a word) k w. \\<lbrakk>uint p + uint k < 2 ^ len_of TYPE('a); w = p + k; w \\<le> p + (2 ^ sz - 1) \\<rbrakk>\n      \\<Longrightarrow> k < 2 ^ sz\"\n      apply -\n      apply simp\n      apply (subst (asm) add.commute, subst (asm) add.commute, drule word_plus_mcs_4)\n      apply (subst add.commute, subst no_plus_overflow_uint_size)\n      apply (simp add: word_size_bl)\n      apply (erule iffD1 [OF word_less_sub_le[OF szv]])\n      done\n\n    from xb obtain kx where\n      kx: \"z = x + kx\" and\n      kxl: \"uint x + uint kx < 2 ^ len_of TYPE('a)\"\n      by (clarsimp dest!: word_le_exists')\n\n    from yb obtain ky where\n      ky: \"z = y + ky\" and\n      kyl: \"uint y + uint ky < 2 ^ len_of TYPE('a)\"\n      by (clarsimp dest!: word_le_exists')\n\n    have \"x = y\"\n    proof -\n      have \"kx = z mod 2 ^ sz\"\n      proof (subst kx, rule sym, rule aligned_add_offset_mod)\n        show \"kx < 2 ^ sz\" by (rule rl) fact+\n      qed fact+\n\n      also have \"\\<dots> = ky\"\n      proof (subst ky, rule aligned_add_offset_mod)\n        show \"ky < 2 ^ sz\"\n          using kyl ky yt by (rule rl)\n      qed fact+\n\n      finally have kxky: \"kx = ky\" .\n      moreover have \"x + kx = y + ky\" by (simp add: kx [symmetric] ky [symmetric])\n      ultimately show ?thesis by simp\n    qed\n\n    thus False using neq by simp\n  qed\nnext\n  assume \"\\<not> sz < len_of TYPE('a)\"\n  with neq alx aly\n  have False by (simp add: is_aligned_mask mask_def power_overflow)\n  thus ?thesis ..\nqed\n\nlemma less_two_pow_divD:\n  \"\\<lbrakk> (x :: nat) < 2 ^ n div 2 ^ m \\<rbrakk>\n    \\<Longrightarrow> n \\<ge> m \\<and> (x < 2 ^ (n - m))\"\n  apply (rule context_conjI)\n   apply (rule ccontr)\n   apply (simp add: div_less power_strict_increasing)\n  apply (simp add: power_sub)\n  done\n\nlemma less_two_pow_divI:\n  \"\\<lbrakk> (x :: nat) < 2 ^ (n - m); m \\<le> n \\<rbrakk> \\<Longrightarrow> x < 2 ^ n div 2 ^ m\"\n  by (simp add: power_sub)\n\nlemma word_less_two_pow_divI:\n  \"\\<lbrakk> (x :: 'a::len word) < 2 ^ (n - m); m \\<le> n; n < len_of TYPE('a) \\<rbrakk> \\<Longrightarrow> x < 2 ^ n div 2 ^ m\"\n  apply (simp add: word_less_nat_alt)\n  apply (subst unat_word_ariths)\n  apply (subst mod_less)\n   apply (rule order_le_less_trans [OF div_le_dividend])\n   apply (rule unat_lt2p)\n  apply (simp add: power_sub)\n  done\n\nlemma word_less_two_pow_divD:\n  \"\\<lbrakk> (x :: 'a::len word) < 2 ^ n div 2 ^ m \\<rbrakk>\n     \\<Longrightarrow> n \\<ge> m \\<and> (x < 2 ^ (n - m))\"\n  apply (cases \"n < len_of TYPE('a)\")\n   apply (cases \"m < len_of TYPE('a)\")\n    apply (simp add: word_less_nat_alt)\n    apply (subst(asm) unat_word_ariths)\n    apply (subst(asm) mod_less)\n     apply (rule order_le_less_trans [OF div_le_dividend])\n     apply (rule unat_lt2p)\n    apply (clarsimp dest!: less_two_pow_divD)\n   apply (simp add: power_overflow)\n   apply (simp add: word_div_def)\n  apply (simp add: power_overflow word_div_def)\n  done\n\nlemma of_nat_less_two_pow_div_set:\n  \"\\<lbrakk> n < len_of TYPE('a) \\<rbrakk> \\<Longrightarrow>\n   {x. x < (2 ^ n div 2 ^ m :: 'a::len word)}\n      = of_nat ` {k. k < 2 ^ n div 2 ^ m}\"\n  apply (simp add: image_def)\n  apply (safe dest!: word_less_two_pow_divD less_two_pow_divD\n             intro!: word_less_two_pow_divI)\n   apply (rule_tac x=\"unat x\" in exI)\n   apply (simp add: power_sub[symmetric])\n   apply (subst unat_power_lower[symmetric, where 'a='a])\n    apply simp\n   apply (erule unat_mono)\n  apply (subst word_unat_power)\n  apply (rule of_nat_mono_maybe)\n   apply (rule power_strict_increasing)\n    apply simp\n   apply simp\n  apply assumption\n  done\n\n(* FIXME: generalise! *)\nlemma upto_2_helper:\n  \"{0..<2 :: word32} = {0, 1}\"\n  apply (safe, simp_all)\n  apply unat_arith\n  done\n\n(* TODO: MOVE to word *)\nlemma  word_less_power_trans2:\n  fixes n :: \"'a::len word\"\n  shows \"\\<lbrakk>n < 2 ^ (m - k); k \\<le> m; m < len_of TYPE('a)\\<rbrakk> \\<Longrightarrow> n * 2 ^ k < 2 ^ m\"\n  by (subst field_simps, rule word_less_power_trans)\n\nlemma ucast_less:\n  \"len_of TYPE('b) < len_of TYPE('a) \\<Longrightarrow>\n   (ucast (x :: ('b :: len) word) :: (('a :: len) word)) < 2 ^ len_of TYPE('b)\"\n  apply (subst mask_eq_iff_w2p[symmetric])\n   apply (simp add: word_size)\n  apply (rule word_eqI)\n  apply (simp add: word_size nth_ucast)\n  apply safe\n  apply (simp add: test_bit.Rep[simplified])\n  done\n\nlemma ucast_less_shiftl_helper:\n  \"\\<lbrakk> len_of TYPE('b) + 2 < word_bits;\n     2 ^ (len_of TYPE('b) + 2) \\<le> n\\<rbrakk>\n    \\<Longrightarrow> (ucast (x :: ('b :: len) word) << 2) < (n :: word32)\"\n  apply (erule order_less_le_trans[rotated])\n  apply (cut_tac ucast_less[where x=x and 'a=32])\n   apply (simp only: shiftl_t2n field_simps)\n   apply (rule word_less_power_trans2)\n     apply (simp_all add: word_bits_def)\n  done\n\nlemma ucast_range_less:\n  \"len_of TYPE('a :: len) < len_of TYPE('b :: len) \\<Longrightarrow>\n   range (ucast :: 'a word \\<Rightarrow> 'b word)\n       = {x. x < 2 ^ len_of TYPE ('a)}\"\n  apply safe\n   apply (erule ucast_less)\n  apply (simp add: image_def)\n  apply (rule_tac x=\"ucast x\" in exI)\n  apply (drule less_mask_eq)\n  apply (rule word_eqI)\n  apply (drule_tac x=n in word_eqD)\n  apply (simp add: word_size nth_ucast)\n  done\n\nlemma word_power_less_diff:\n  \"\\<lbrakk>2 ^ n * q < (2::'a::len word) ^ m; q < 2 ^ (len_of TYPE('a) - n)\\<rbrakk> \\<Longrightarrow> q < 2 ^ (m - n)\"\n  apply (case_tac \"m \\<ge> len_of TYPE('a)\")\n   apply (simp add: power_overflow)\n  apply (case_tac \"n \\<ge> len_of TYPE('a)\")\n   apply (simp add: power_overflow)\n  apply (cases \"n = 0\")\n   apply simp\n  apply (subst word_less_nat_alt)\n  apply (subst unat_power_lower)\n   apply simp\n  apply (rule nat_power_less_diff)\n  apply (simp add: word_less_nat_alt)\n  apply (subst (asm) iffD1 [OF unat_mult_lem])\n   apply (simp add:nat_less_power_trans)\n  apply simp\n  done\n\nlemmas word_diff_ls' = word_diff_ls [where xa=x and x=x for x, simplified]\n\nlemmas word_l_diffs = word_l_diffs [where xa=x and x=x for x, simplified]\n\nlemma is_aligned_diff:\n  fixes m :: \"'a::len word\"\n  assumes alm: \"is_aligned m s1\"\n  and     aln: \"is_aligned n s2\"\n  and    s2wb: \"s2 < len_of TYPE('a)\"\n  and      nm: \"m \\<in> {n .. n + (2 ^ s2 - 1)}\"\n  and    s1s2: \"s1 \\<le> s2\"\n  and     s10: \"0 < s1\" (* Probably can be folded into the proof \\<dots> *)\n  shows  \"\\<exists>q. m - n = of_nat q * 2 ^ s1 \\<and> q < 2 ^ (s2 - s1)\"\nproof -\n  have rl: \"\\<And>m s. \\<lbrakk> m < 2 ^ (len_of TYPE('a) - s); s < len_of TYPE('a) \\<rbrakk> \\<Longrightarrow> unat ((2::'a word) ^ s * of_nat m) = 2 ^ s * m\"\n  proof -\n    fix m :: nat and  s\n    assume m: \"m < 2 ^ (len_of TYPE('a) - s)\" and s: \"s < len_of TYPE('a)\"\n    hence \"unat ((of_nat m) :: 'a word) = m\"\n      apply (subst unat_of_nat)\n      apply (subst mod_less)\n       apply (erule order_less_le_trans)\n       apply (rule power_increasing)\n        apply simp_all\n      done\n\n    thus \"?thesis m s\" using s m\n      apply (subst iffD1 [OF unat_mult_lem])\n      apply (simp add: nat_less_power_trans)+\n      done\n  qed\n  have s1wb: \"s1 < len_of TYPE('a)\" using s2wb s1s2 by simp\n  from alm obtain mq where mmq: \"m = 2 ^ s1 * of_nat mq\" and mq: \"mq < 2 ^ (len_of TYPE('a) - s1)\"\n    by (auto elim: is_alignedE simp: field_simps)\n  from aln obtain nq where nnq: \"n = 2 ^ s2 * of_nat nq\" and nq: \"nq < 2 ^ (len_of TYPE('a) - s2)\"\n    by (auto elim: is_alignedE simp: field_simps)\n  from s1s2 obtain sq where sq: \"s2 = s1 + sq\" by (auto simp: le_iff_add)\n\n  note us1 = rl [OF mq s1wb]\n  note us2 = rl [OF nq s2wb]\n\n  from nm have \"n \\<le> m\" by clarsimp\n  hence \"(2::'a word) ^ s2 * of_nat nq \\<le> 2 ^ s1 * of_nat mq\" using nnq mmq by simp\n  hence \"2 ^ s2 * nq \\<le> 2 ^ s1 * mq\" using s1wb s2wb\n    by (simp add: word_le_nat_alt us1 us2)\n  hence nqmq: \"2 ^ sq * nq \\<le> mq\" using sq by (simp add: power_add)\n\n  have \"m - n = 2 ^ s1 * of_nat mq - 2 ^ s2 * of_nat nq\" using mmq nnq by simp\n  also have \"\\<dots> = 2 ^ s1 * of_nat mq - 2 ^ s1 * 2 ^ sq * of_nat nq\" using sq by (simp add: power_add)\n  also have \"\\<dots> = 2 ^ s1 * (of_nat mq - 2 ^ sq * of_nat nq)\" by (simp add: field_simps)\n  also have \"\\<dots> = 2 ^ s1 * of_nat (mq - 2 ^ sq * nq)\" using s1wb s2wb us1 us2 nqmq\n    by (simp add:  word_unat_power)\n  finally have mn: \"m - n = of_nat (mq - 2 ^ sq * nq) * 2 ^ s1\" by simp\n  moreover\n  from nm have \"m - n \\<le> 2 ^ s2 - 1\"\n    by - (rule word_diff_ls', (simp add: field_simps)+)\n  hence \"(2::'a word) ^ s1 * of_nat (mq - 2 ^ sq * nq) < 2 ^ s2\" using mn s2wb by (simp add: field_simps word_less_sub_le)\n  hence \"of_nat (mq - 2 ^ sq * nq) < (2::'a word) ^ (s2 - s1)\"\n  proof (rule word_power_less_diff)\n    have mm: \"mq - 2 ^ sq * nq < 2 ^ (len_of TYPE('a) - s1)\" using mq by simp\n    moreover from s10 have \"len_of TYPE('a) - s1 < len_of TYPE('a)\"\n      by (rule diff_less, simp)\n    ultimately show \"of_nat (mq - 2 ^ sq * nq) < (2::'a word) ^ (len_of TYPE('a) - s1)\"\n      apply (simp add: word_less_nat_alt)\n      apply (subst unat_of_nat)\n      apply (subst mod_less)\n       apply (erule order_less_le_trans)\n       apply simp+\n      done\n  qed\n  hence \"mq - 2 ^ sq * nq < 2 ^ (s2 - s1)\" using mq s2wb\n    apply (simp add: word_less_nat_alt)\n    apply (subst (asm) unat_of_nat)\n    apply (subst (asm) mod_less)\n    apply (rule order_le_less_trans)\n    apply (rule diff_le_self)\n    apply (erule order_less_le_trans)\n    apply simp\n    apply assumption\n    done\n  ultimately show ?thesis by auto\nqed\n\nlemma word_less_sub_1:\n  \"x < (y :: ('a :: len) word) \\<Longrightarrow> x \\<le> y - 1\"\n  apply (erule udvd_minus_le')\n   apply (simp add: udvd_def)+\n  done\n\nlemma word_sub_mono2:\n  \"\\<lbrakk> a + b \\<le> c + d; c \\<le> a; b \\<le> a + b; d \\<le> c + d \\<rbrakk>\n    \\<Longrightarrow> b \\<le> (d :: ('a :: len) word)\"\n  apply (drule(1) word_sub_mono)\n    apply simp\n   apply simp\n  apply simp\n  done\n\n\n\nlemma word_subset_less:\n  \"\\<lbrakk> {x .. x + r - 1} \\<subseteq> {y .. y + s - 1};\n     x \\<le> x + r - 1; y \\<le> y + (s :: ('a :: len) word) - 1;\n     s \\<noteq> 0 \\<rbrakk>\n     \\<Longrightarrow> r \\<le> s\"\n  apply (frule subsetD[where c=x])\n   apply simp\n  apply (drule subsetD[where c=\"x + r - 1\"])\n   apply simp\n  apply (clarsimp simp: add_diff_eq[symmetric])\n  apply (drule(1) word_sub_mono2)\n    apply (simp_all add: olen_add_eqv[symmetric])\n  apply (erule word_le_minus_cancel)\n  apply (rule ccontr)\n  apply (simp add: word_not_le)\n  done\n\nlemma two_power_strict_part_mono:\n  \"strict_part_mono {..31} (\\<lambda>x. (2 :: word32) ^ x)\"\n  by (simp | subst strict_part_mono_by_steps)+\n\nlemma uint_power_lower:\n  \"n < len_of TYPE('a) \\<Longrightarrow> uint (2 ^ n :: 'a :: len word) = (2 ^ n :: int)\"\n  by (simp add: uint_nat int_power)\n\nlemma power_le_mono:\n  \"\\<lbrakk>2 ^ n \\<le> (2::'a::len word) ^ m; n < len_of TYPE('a); m < len_of TYPE('a)\\<rbrakk>\n   \\<Longrightarrow> n \\<le> m\"\n  apply (clarsimp simp add: le_less)\n  apply safe\n  apply (simp add: word_less_nat_alt)\n  apply (simp only: uint_arith_simps(3))\n  apply (drule uint_power_lower)+\n  apply simp\n  done\n\nlemma sublist_equal_part:\n  \"xs \\<le> ys \\<Longrightarrow> take (length xs) ys = xs\"\n  by (clarsimp simp: prefixeq_def less_eq_list_def)\n\nlemma take_n_subset_le:\n  \"\\<lbrakk> {x. take n (to_bl x) = take n xs} \\<subseteq> {y :: word32. take m (to_bl y) = take m ys};\n     n \\<le> 32; m \\<le> 32; length xs = 32; length ys = 32 \\<rbrakk>\n    \\<Longrightarrow> m \\<le> n\"\n  apply (rule ccontr, simp add: le_def)\n  apply (simp add: subset_iff)\n  apply (drule spec[where x=\"of_bl (take n xs @ take (32 - n) (map Not (drop n ys)))\"])\n  apply (simp add: word_bl.Abs_inverse)\n  apply (subgoal_tac \"\\<exists>p. m = n + p\")\n   apply clarsimp\n   apply (simp add: take_add take_map_Not)\n  apply (rule exI[where x=\"m - n\"])\n  apply simp\n  done\n\nlemma two_power_eq:\n  \"\\<lbrakk>n < len_of TYPE('a); m < len_of TYPE('a)\\<rbrakk>\n   \\<Longrightarrow> ((2::'a::len word) ^ n = 2 ^ m) = (n = m)\"\n  apply safe\n  apply (rule order_antisym)\n   apply (simp add: power_le_mono[where 'a='a])+\n  done\n\nlemma less_list_def': \"(xs < ys) = (prefix xs ys)\"\n  apply (metis prefix_order.eq_iff prefix_def less_list_def less_eq_list_def)\n  done\n\nlemma prefix_length_less:\n  \"xs < ys \\<Longrightarrow> length xs < length ys\"\n  apply (clarsimp simp: less_list_def' prefix_def)\n  apply (frule prefixeq_length_le)\n  apply (rule ccontr, simp)\n  apply (clarsimp simp: prefixeq_def)\n  done\n\nlemmas strict_prefix_simps [simp, code] = prefix_simps [folded less_list_def']\nlemmas take_strict_prefix = take_prefix [folded less_list_def']\n\nlemma not_prefix_longer:\n  \"\\<lbrakk> length xs > length ys \\<rbrakk> \\<Longrightarrow> \\<not> xs \\<le> ys\"\n  by (clarsimp dest!: prefix_length_le)\n\nlemma of_bl_length:\n  \"length xs < len_of TYPE('a) \\<Longrightarrow> of_bl xs < (2 :: 'a::len word) ^ length xs\"\n  by (simp add: of_bl_length_less)\n\n(* FIXME: do we need this? *)\nlemma power_overflow_simp [simp]:\n  \"(2 ^ n = (0::'a :: len word)) = (len_of TYPE ('a) \\<le> n)\"\n  by (rule WordLib.p2_eq_0)\n\nlemma unat_of_nat_eq:\n  \"x < 2 ^ len_of TYPE('a) \\<Longrightarrow> unat (of_nat x ::'a::len word) = x\"\n  by (simp add: unat_of_nat)\n\nlemmas unat_of_nat32 = unat_of_nat_eq[where 'a=32, unfolded word_bits_len_of]\n\nlemma unat_eq_of_nat:\n  \"n < 2 ^ len_of TYPE('a) \\<Longrightarrow> (unat (x :: 'a::len word) = n) = (x = of_nat n)\"\n  by (subst unat_of_nat_eq[where x=n, symmetric], simp+)\n\nlemma unat_less_helper:\n  \"x < of_nat n \\<Longrightarrow> unat x < n\"\n  apply (simp add: word_less_nat_alt)\n  apply (erule order_less_le_trans)\n  apply (simp add: unat_of_nat)\n  done\n\nlemma of_nat_0:\n  \"\\<lbrakk>of_nat n = (0::('a::len) word); n < 2 ^ len_of (TYPE('a))\\<rbrakk> \\<Longrightarrow> n = 0\"\n  by (drule unat_of_nat_eq, simp)\n\nlemma of_nat32_0:\n  \"\\<lbrakk>of_nat n = (0::word32); n < 2 ^ word_bits\\<rbrakk> \\<Longrightarrow> n = 0\"\n  by (erule of_nat_0, simp add: word_bits_def)\n\nlemma unat_mask_2_less_4:\n  \"unat (p && mask 2 :: word32) < 4\"\n  apply (rule unat_less_helper)\n  apply (rule order_le_less_trans, rule word_and_le1)\n  apply (simp add: mask_def)\n  done\n\nlemma minus_one_helper3:\n  \"x < y \\<Longrightarrow> x \\<le> (y :: ('a :: len) word) - 1\"\n  apply (simp add: word_less_nat_alt word_le_nat_alt)\n  apply (subst unat_minus_one)\n   apply clarsimp\n  apply arith\n  done\n\nlemma minus_one_helper:\n  \"\\<lbrakk> x \\<le> y; x \\<noteq> 0 \\<rbrakk> \\<Longrightarrow> x - 1 < (y :: ('a :: len) word)\"\n  apply (simp add: word_less_nat_alt word_le_nat_alt)\n  apply (subst unat_minus_one)\n   apply assumption\n  apply (cases \"unat x\")\n   apply (simp add: unat_eq_zero)\n  apply arith\n  done\n\nlemma minus_one_helper5:\n  fixes x :: \"'a::len word\"\n  shows \"\\<lbrakk>y \\<noteq> 0; x \\<le> y - 1 \\<rbrakk> \\<Longrightarrow> x < y\"\n  by (metis leD minus_one_helper not_leE)\n\nlemma plus_one_helper[elim!]:\n  \"x < n + (1 :: ('a :: len) word) \\<Longrightarrow> x \\<le> n\"\n  apply (simp add: word_less_nat_alt word_le_nat_alt field_simps)\n  apply (case_tac \"1 + n = 0\")\n   apply simp\n  apply (subst(asm) unatSuc, assumption)\n  apply arith\n  done\n\n\n\nlemma not_greatest_aligned:\n  \"\\<lbrakk> x < y; is_aligned x n; is_aligned y n \\<rbrakk>\n      \\<Longrightarrow> x + 2 ^ n \\<noteq> 0\"\n  apply (rule notI)\n  apply (erule is_aligned_get_word_bits[where p=y])\n   apply (simp add: eq_diff_eq[symmetric])\n   apply (frule minus_one_helper3)\n   apply (drule le_minus'[where a=\"x\" and c=\"y - x\" and b=\"- 1\" for x y, simplified])\n   apply (simp add: field_simps)\n   apply (frule is_aligned_less_sz[where a=y])\n     apply clarsimp\n   apply (erule notE)\n   apply (rule minus_one_helper5)\n    apply simp\n   apply (metis is_aligned_no_overflow minus_one_helper3 order_le_less_trans)\n  apply simp\n  done\n\nlemma of_nat_inj:\n  \"\\<lbrakk>x < 2 ^ len_of TYPE('a); y < 2 ^ len_of TYPE('a)\\<rbrakk> \\<Longrightarrow>\n   (of_nat x = (of_nat y :: 'a :: len word)) = (x = y)\"\n  by (simp add: word_unat.norm_eq_iff [symmetric])\n\nlemma map_prefixI:\n  \"xs \\<le> ys \\<Longrightarrow> map f xs \\<le> map f ys\"\n  by (clarsimp simp: less_eq_list_def prefixeq_def)\n\nlemma if_Some_None_eq_None:\n  \"((if P then Some v else None) = None) = (\\<not> P)\"\n  by simp\n\nlemma CollectPairFalse [iff]:\n  \"{(a,b). False} = {}\"\n  by (simp add: split_def)\n\n\n\nlemma if_P_True1:\n  \"Q \\<Longrightarrow> (if P then True else Q)\"\n  by simp\n\nlemma if_P_True2:\n  \"Q \\<Longrightarrow> (if P then Q else True)\"\n  by simp\n\nlemma list_all2_induct [consumes 1, case_names Nil Cons]:\n  assumes lall: \"list_all2 Q xs ys\"\n  and     nilr: \"P [] []\"\n  and    consr: \"\\<And>x xs y ys. \\<lbrakk>list_all2 Q xs ys; Q x y; P xs ys\\<rbrakk> \\<Longrightarrow> P (x # xs) (y # ys)\"\n  shows  \"P xs ys\"\n  using lall\nproof (induct rule: list_induct2 [OF list_all2_lengthD [OF lall]])\n  case 1 thus ?case by auto fact+\nnext\n  case (2 x xs y ys)\n\n  show ?case\n  proof (rule consr)\n    from \"2.prems\" show \"list_all2 Q xs ys\" and \"Q x y\" by simp_all\n    thus \"P xs ys\" by (intro \"2.hyps\")\n  qed\nqed\n\nlemma list_all2_induct_suffixeq [consumes 1, case_names Nil Cons]:\n  assumes lall: \"list_all2 Q as bs\"\n  and     nilr: \"P [] []\"\n  and    consr: \"\\<And>x xs y ys.\n  \\<lbrakk>list_all2 Q xs ys; Q x y; P xs ys; suffixeq (x # xs) as; suffixeq (y # ys) bs\\<rbrakk>\n  \\<Longrightarrow> P (x # xs) (y # ys)\"\n  shows  \"P as bs\"\nproof -\n  def as' == as\n  def bs' == bs\n\n  have \"suffixeq as as' \\<and> suffixeq bs bs'\" unfolding as'_def bs'_def by simp\n  thus ?thesis using lall\n  proof (induct rule: list_induct2 [OF list_all2_lengthD [OF lall]])\n    case 1 show ?case by fact\n  next\n    case (2 x xs y ys)\n\n    show ?case\n    proof (rule consr)\n      from \"2.prems\" show \"list_all2 Q xs ys\" and \"Q x y\" by simp_all\n      thus \"P xs ys\" using \"2.hyps\" \"2.prems\" by (auto dest: suffixeq_ConsD)\n      from \"2.prems\" show \"suffixeq (x # xs) as\" and \"suffixeq (y # ys) bs\"\n\tby (auto simp: as'_def bs'_def)\n    qed\n  qed\nqed\n\nlemma distinct_prop_enum:\n  \"\\<lbrakk> \\<And>x y. \\<lbrakk> x \\<le> stop; y \\<le> stop; x \\<noteq> y \\<rbrakk>\n             \\<Longrightarrow> P x y \\<rbrakk>\n     \\<Longrightarrow> distinct_prop P [(0 :: word32) .e. stop]\"\n  apply (simp add: upto_enum_def distinct_prop_map\n              del: upt.simps)\n  apply (rule distinct_prop_distinct)\n   apply simp\n  apply (simp add: less_Suc_eq_le del: upt.simps)\n  apply (erule_tac x=\"of_nat x\" in meta_allE)\n  apply (erule_tac x=\"of_nat y\" in meta_allE)\n  apply (frule_tac y=x in unat_le)\n  apply (frule_tac y=y in unat_le)\n  apply (erule word_unat.Rep_cases)+\n  apply (simp add: toEnum_of_nat[OF unat_lt2p]\n                   word_le_nat_alt)\n  done\n\nlemma distinct_prop_enum_step:\n  \"\\<lbrakk> \\<And>x y. \\<lbrakk> x \\<le> stop div step; y \\<le> stop div step; x \\<noteq> y \\<rbrakk>\n             \\<Longrightarrow> P (x * step) (y * step) \\<rbrakk>\n     \\<Longrightarrow> distinct_prop P [0, step .e. stop]\"\n  apply (simp add: upto_enum_step_def distinct_prop_map)\n  apply (rule distinct_prop_enum)\n  apply simp\n  done\n\nlemma if_apply_def2:\n  \"(if P then F else G) = (\\<lambda>x. (P \\<longrightarrow> F x) \\<and> (\\<not> P \\<longrightarrow> G x))\"\n  by simp\n\nlemma case_bool_If:\n  \"case_bool P Q b = (if b then P else Q)\"\n  by simp\n\nlemma option_case_If:\n  \"case_option P (\\<lambda>x. Q) v = (if v = None then P else Q)\"\n  by clarsimp\n\nlemma option_case_If2:\n  \"case_option P Q v = If (v \\<noteq> None) (Q (the v)) P\"\n  by (simp split: option.split)\n\nlemma if3_fold:\n  \"(if P then x else if Q then y else x)\n     = (if P \\<or> \\<not> Q then x else y)\"\n  by simp\n\nlemma word32_shift_by_2:\n  \"x * 4 = (x::word32) << 2\"\n  by (simp add: shiftl_t2n)\n\n(* TODO: move to Aligned *)\nlemma add_mask_lower_bits:\n  \"\\<lbrakk>is_aligned (x :: 'a :: len word) n;\n    \\<forall>n' \\<ge> n. n' < len_of TYPE('a) \\<longrightarrow> \\<not> p !! n'\\<rbrakk> \\<Longrightarrow> x + p && ~~mask n = x\"\n  apply (subst word_plus_and_or_coroll)\n   apply (rule word_eqI)\n   apply (clarsimp simp: word_size is_aligned_nth)\n   apply (erule_tac x=na in allE)+\n   apply simp\n  apply (rule word_eqI)\n  apply (clarsimp simp: word_size is_aligned_nth nth_mask word_ops_nth_size)\n  apply (erule_tac x=na in allE)+\n  apply (case_tac \"na < n\")\n   apply simp\n  apply simp\n  done\n\nlemma findSomeD:\n  \"find P xs = Some x \\<Longrightarrow> P x \\<and> x \\<in> set xs\"\n  by (induct xs) (auto split: split_if_asm)\n\nlemma findNoneD:\n  \"find P xs = None \\<Longrightarrow> \\<forall>x \\<in> set xs. \\<not>P x\"\n  by (induct xs) (auto split: split_if_asm)\n\nlemma dom_upd:\n  \"dom (\\<lambda>x. if x = y then None else f x) = dom f - {y}\"\n  by (rule set_eqI) (auto split: split_if_asm)\n\nlemma ran_upd:\n  \"\\<lbrakk> inj_on f (dom f); f y = Some z \\<rbrakk> \\<Longrightarrow> ran (\\<lambda>x. if x = y then None else f x) = ran f - {z}\"\n  apply (rule set_eqI)\n  apply (unfold ran_def)\n  apply simp\n  apply (rule iffI)\n   apply clarsimp\n   apply (rule conjI, blast)\n   apply clarsimp\n   apply (drule_tac x=a and y=y in inj_onD, simp)\n     apply blast\n    apply blast\n   apply simp\n  apply clarsimp\n  apply (rule_tac x=a in exI)\n  apply clarsimp\n  done\n\nlemma maxBound_word:\n  \"(maxBound::'a::len word) = -1\"\n  apply (simp add: maxBound_def enum_word_def)\n  apply (subst last_map)\n   apply clarsimp\n  apply simp\n  done\n\nlemma minBound_word:\n  \"(minBound::'a::len word) = 0\"\n  apply (simp add: minBound_def enum_word_def)\n  apply (subst map_upt_unfold)\n   apply simp\n  apply simp\n  done\n\nlemma maxBound_max_word:\n  \"(maxBound::'a::len word) = max_word\"\n  apply (subst maxBound_word)\n  apply (subst max_word_minus [symmetric])\n  apply (rule refl)\n  done\n\n\n\nlemma is_aligned_andI1:\n  \"is_aligned x n \\<Longrightarrow> is_aligned (x && y) n\"\n  by (simp add: is_aligned_nth)\n\nlemma is_aligned_andI2:\n  \"is_aligned y n \\<Longrightarrow> is_aligned (x && y) n\"\n  by (simp add: is_aligned_nth)\n\nlemma is_aligned_shiftl:\n  \"is_aligned w (n - m) \\<Longrightarrow> is_aligned (w << m) n\"\n  by (simp add: is_aligned_nth nth_shiftl)\n\nlemma is_aligned_shiftr:\n  \"is_aligned w (n + m) \\<Longrightarrow> is_aligned (w >> m) n\"\n  by (simp add: is_aligned_nth nth_shiftr)\n\nlemma is_aligned_shiftl_self:\n  \"is_aligned (p << n) n\"\n  by (rule is_aligned_shiftl) simp\n\nlemma is_aligned_neg_mask_eq:\n  \"is_aligned p n \\<Longrightarrow> p && ~~ mask n = p\"\n  apply (simp add: is_aligned_nth)\n  apply (rule word_eqI)\n  apply (clarsimp simp: word_size word_ops_nth_size)\n  apply fastforce\n  done\n\nlemma rtrancl_insert:\n  assumes x_new: \"\\<And>y. (x,y) \\<notin> R\"\n  shows \"R^* `` insert x S = insert x (R^* `` S)\"\nproof -\n  have \"R^* `` insert x S = R^* `` ({x} \\<union> S)\" by simp\n  also\n  have \"R^* `` ({x} \\<union> S) = R^* `` {x} \\<union> R^* `` S\"\n    by (subst Image_Un) simp\n  also\n  have \"R^* `` {x} = {x}\"\n    apply (clarsimp simp: Image_singleton)\n    apply (rule set_eqI, clarsimp)\n    apply (rule iffI)\n     apply (drule rtranclD)\n     apply (erule disjE, simp)\n     apply clarsimp\n     apply (drule tranclD)\n     apply (clarsimp simp: x_new)\n    apply fastforce\n    done\n  finally\n  show ?thesis by simp\nqed\n\nlemma ran_del_subset:\n  \"y \\<in> ran (f (x := None)) \\<Longrightarrow> y \\<in> ran f\"\n  by (auto simp: ran_def split: split_if_asm)\n\nlemma trancl_sub_lift:\n  assumes sub: \"\\<And>p p'. (p,p') \\<in> r \\<Longrightarrow> (p,p') \\<in> r'\"\n  shows \"(p,p') \\<in> r^+ \\<Longrightarrow> (p,p') \\<in> r'^+\"\n  by (fastforce intro: trancl_mono sub)\n\nlemma trancl_step_lift:\n  assumes x_step: \"\\<And>p p'. (p,p') \\<in> r' \\<Longrightarrow> (p,p') \\<in> r \\<or> (p = x \\<and> p' = y)\"\n  assumes y_new: \"\\<And>p'. \\<not>(y,p') \\<in> r\"\n  shows \"(p,p') \\<in> r'^+ \\<Longrightarrow> (p,p') \\<in> r^+ \\<or> ((p,x) \\<in> r^+ \\<and> p' = y) \\<or> (p = x \\<and> p' = y)\"\n  apply (erule trancl_induct)\n   apply (drule x_step)\n   apply fastforce\n  apply (erule disjE)\n   apply (drule x_step)\n   apply (erule disjE)\n    apply (drule trancl_trans, drule r_into_trancl, assumption)\n    apply blast\n   apply clarsimp\n  apply (erule disjE)\n   apply clarsimp\n   apply (drule x_step)\n   apply (erule disjE)\n    apply (simp add: y_new)\n   apply simp\n  apply clarsimp\n  apply (drule x_step)\n  apply (simp add: y_new)\n  done\n\nlemma upto_enum_step_shift:\n  \"\\<lbrakk> is_aligned p n \\<rbrakk> \\<Longrightarrow>\n  ([p , p + 2 ^ m .e. p + 2 ^ n - 1])\n      = map (op + p) [0, 2 ^ m .e. 2 ^ n - 1]\"\n  apply (erule is_aligned_get_word_bits)\n   prefer 2\n   apply (simp add: map_idI)\n  apply (clarsimp simp: upto_enum_step_def)\n  apply (frule is_aligned_no_overflow)\n  apply (simp add: linorder_not_le [symmetric])\n  done\n\nlemma upto_enum_step_shift_red:\n  \"\\<lbrakk> is_aligned p sz; sz < word_bits; us \\<le> sz \\<rbrakk>\n     \\<Longrightarrow> [p, p + 2 ^ us .e. p + 2 ^ sz - 1]\n          = map (\\<lambda>x. p + of_nat x * 2 ^ us) [0 ..< 2 ^ (sz - us)]\"\n  apply (subst upto_enum_step_shift, assumption)\n  apply (simp add: upto_enum_step_red)\n  done\n\nlemma div_to_mult_word_lt:\n  \"\\<lbrakk> (x :: ('a :: len) word) \\<le> y div z \\<rbrakk> \\<Longrightarrow> x * z \\<le> y\"\n  apply (cases \"z = 0\")\n   apply simp\n  apply (simp add: word_neq_0_conv)\n  apply (rule order_trans)\n   apply (erule(1) word_mult_le_mono1)\n   apply (simp add: unat_div)\n   apply (rule order_le_less_trans [OF div_mult_le])\n   apply simp\n  apply (rule word_div_mult_le)\n  done\n\nlemma upto_enum_step_subset:\n  \"set [x, y .e. z] \\<subseteq> {x .. z}\"\n  apply (clarsimp simp: upto_enum_step_def linorder_not_less)\n  apply (drule div_to_mult_word_lt)\n  apply (rule conjI)\n   apply (erule word_random[rotated])\n   apply simp\n  apply (rule order_trans)\n   apply (erule word_plus_mono_right)\n   apply simp\n  apply simp\n  done\n\nlemma shiftr_less_t2n':\n  fixes x :: \"('a :: len) word\"\n  shows \"\\<lbrakk> x && mask (n + m) = x; m < len_of TYPE('a) \\<rbrakk>\n              \\<Longrightarrow> (x >> n) < 2 ^ m\"\n  apply (subst mask_eq_iff_w2p[symmetric])\n   apply (simp add: word_size)\n  apply (rule word_eqI)\n  apply (drule_tac x=\"na + n\" in word_eqD)\n  apply (simp add: nth_shiftr word_size)\n  apply safe\n  done\n\nlemma shiftr_less_t2n:\n  fixes x :: \"('a :: len) word\"\n  shows \"x < 2 ^ (n + m) \\<Longrightarrow> (x >> n) < 2 ^ m\"\n  apply (rule shiftr_less_t2n')\n   apply (erule less_mask_eq)\n  apply (rule ccontr)\n  apply (simp add: not_less)\n  apply (subst (asm) p2_eq_0[symmetric])\n  apply (simp add: power_add)\n  done\n\nlemma shiftr_eq_0:\n  \"n \\<ge> len_of TYPE('a :: len) \\<Longrightarrow> ((w::('a::len word)) >> n) = 0\"\napply (cut_tac shiftr_less_t2n'[of w n 0], simp)\n apply (simp add: mask_eq_iff)\napply (simp add: lt2p_lem)\napply simp\ndone\n\nlemma shiftr_not_mask_0:\n  \"n+m\\<ge>len_of TYPE('a :: len) \\<Longrightarrow> ((w::('a::len word)) >> n) && ~~ mask m = 0\"\n  apply (simp add: and_not_mask shiftr_less_t2n shiftr_shiftr)\n  apply (subgoal_tac \"w >> n + m = 0\", simp)\n  apply (simp add: le_mask_iff[symmetric] mask_def le_def)\n  apply (subst (asm) p2_gt_0[symmetric])\n  apply (simp add: power_add not_less)\ndone\n\nlemma shiftl_less_t2n:\n  fixes x :: \"('a :: len) word\"\n  shows \"\\<lbrakk> x < (2 ^ (m - n)); m < len_of TYPE('a) \\<rbrakk> \\<Longrightarrow> (x << n) < 2 ^ m\"\n  apply (subst mask_eq_iff_w2p[symmetric])\n   apply (simp add: word_size)\n  apply (drule less_mask_eq)\n  apply (rule word_eqI)\n  apply (drule_tac x=\"na - n\" in word_eqD)\n  apply (simp add: nth_shiftl word_size)\n  apply (cases \"n \\<le> m\")\n   apply safe\n   apply simp\n  apply simp\n  done\n\nlemma shiftl_less_t2n':\n  \"(x::'a::len word) < 2 ^ m \\<Longrightarrow> m+n < len_of TYPE('a) \\<Longrightarrow> x << n < 2 ^ (m + n)\"\nby (rule shiftl_less_t2n) simp_all\n\nlemma ucast_ucast_mask:\n  \"(ucast :: ('a :: len) word \\<Rightarrow> ('b :: len) word) (ucast x) = x && mask (len_of TYPE ('a))\"\n  apply (rule word_eqI)\n  apply (simp add: nth_ucast word_size)\n  done\n\nlemma ucast_ucast_len:\n  \"\\<lbrakk> x < 2 ^ len_of TYPE('b) \\<rbrakk> \\<Longrightarrow>\n  ucast (ucast x::'b::len word) = (x::'a::len word)\"\n  apply (subst ucast_ucast_mask)\n  apply (erule less_mask_eq)\n  done\n\nlemma unat_ucast: \"unat (ucast x :: ('a :: len0) word) = unat x mod 2 ^ (len_of TYPE('a))\"\n  apply (simp add: unat_def ucast_def)\n  apply (subst word_uint.eq_norm)\n  apply (subst nat_mod_distrib)\n    apply simp\n   apply simp\n  apply (subst nat_power_eq)\n   apply simp\n  apply simp\n  done\n\nlemma sints_subset:\n  \"m \\<le> n \\<Longrightarrow> sints m \\<subseteq> sints n\"\n  apply (simp add: sints_num)\n  apply clarsimp\n  apply (rule conjI)\n   apply (erule order_trans[rotated])\n   apply simp\n  apply (erule order_less_le_trans)\n  apply simp\n  done\n\nlemma up_scast_inj:\n      \"\\<lbrakk> scast x = (scast y :: ('b :: len) word); size x \\<le> len_of TYPE('b) \\<rbrakk>\n         \\<Longrightarrow> x = y\"\n  apply (simp add: scast_def)\n  apply (subst(asm) word_sint.Abs_inject)\n    apply (erule subsetD [OF sints_subset])\n    apply (simp add: word_size)\n   apply (erule subsetD [OF sints_subset])\n   apply (simp add: word_size)\n  apply simp\n  done\n\nlemma up_scast_inj_eq:\n  \"len_of TYPE('a) \\<le> len_of TYPE ('b) \\<Longrightarrow> (scast x = (scast y::'b::len word)) = (x = (y::'a::len word))\"\n  by (fastforce dest: up_scast_inj simp: word_size)\n\nlemma nth_bounded:\n  \"\\<lbrakk>(x :: 'a :: len word) !! n; x < 2 ^ m; m \\<le> len_of TYPE ('a)\\<rbrakk> \\<Longrightarrow> n < m\"\n  apply (frule test_bit_size)\n  apply (clarsimp simp: test_bit_bl word_size)\n  apply (simp add: nth_rev)\n  apply (subst(asm) is_aligned_add_conv[OF is_aligned_0',\n                                        simplified add_0_left, rotated])\n   apply assumption+\n  apply (simp only: to_bl_0 word_bits_len_of)\n  apply (simp add: nth_append split: split_if_asm)\n  done\n\nlemma is_aligned_add_or:\n  \"\\<lbrakk>is_aligned p n; d < 2 ^ n\\<rbrakk> \\<Longrightarrow> p + d = p || d\"\n  apply (rule word_plus_and_or_coroll)\n  apply (erule is_aligned_get_word_bits)\n   apply (rule word_eqI)\n   apply (clarsimp simp add: is_aligned_nth)\n   apply (frule(1) nth_bounded)\n    apply simp+\n  done\n\nlemma two_power_increasing:\n  \"\\<lbrakk> n \\<le> m; m < len_of TYPE('a) \\<rbrakk> \\<Longrightarrow> (2 :: 'a :: len word) ^ n \\<le> 2 ^ m\"\n  by (simp add: word_le_nat_alt)\n\nlemma is_aligned_add_less_t2n:\n  \"\\<lbrakk>is_aligned (p\\<Colon>'a\\<Colon>len word) n; d < 2^n; n \\<le> m; p < 2^m\\<rbrakk> \\<Longrightarrow> p + d < 2^m\"\n  apply (case_tac \"m < len_of TYPE('a)\")\n   apply (subst mask_eq_iff_w2p[symmetric])\n    apply (simp add: word_size)\n   apply (simp add: is_aligned_add_or word_ao_dist less_mask_eq)\n   apply (subst less_mask_eq)\n    apply (erule order_less_le_trans)\n    apply (erule(1) two_power_increasing)\n   apply simp\n  apply (simp add: power_overflow)\n  done\n\n(* FIXME: generalise? *)\nlemma le_2p_upper_bits:\n  \"\\<lbrakk> (p::word32) \\<le> 2^n - 1; n < word_bits \\<rbrakk> \\<Longrightarrow> \\<forall>n'\\<ge>n. n' < word_bits \\<longrightarrow> \\<not> p !! n'\"\n  apply (subst upper_bits_unset_is_l2p, assumption)\n  apply simp\n  done\n\nlemma ran_upd':\n  \"\\<lbrakk>inj_on f (dom f); f y = Some z\\<rbrakk>\n  \\<Longrightarrow> ran (f (y := None)) = ran f - {z}\"\n  apply (drule (1) ran_upd)\n  apply (simp add: ran_def)\n  done\n\n(* FIXME: generalise? *)\nlemma le2p_bits_unset:\n  \"p \\<le> 2 ^ n - 1 \\<Longrightarrow> \\<forall>n'\\<ge>n. n' < word_bits \\<longrightarrow> \\<not> (p::word32) !! n'\"\n  apply (case_tac \"n < word_bits\")\n   apply (frule upper_bits_unset_is_l2p [where p=p])\n   apply simp_all\n  done\n\nlemma aligned_offset_non_zero:\n  \"\\<lbrakk> is_aligned x n; y < 2 ^ n; x \\<noteq> 0 \\<rbrakk> \\<Longrightarrow> x + y \\<noteq> 0\"\n  apply (cases \"y = 0\")\n   apply simp\n  apply (subst word_neq_0_conv)\n  apply (subst gt0_iff_gem1)\n  apply (erule is_aligned_get_word_bits)\n   apply (subst field_simps[symmetric], subst plus_le_left_cancel_nowrap)\n     apply (rule is_aligned_no_wrap')\n      apply simp\n     apply (rule minus_one_helper)\n      apply simp\n     apply assumption\n    apply (erule (1) is_aligned_no_wrap')\n   apply (simp add: gt0_iff_gem1 [symmetric] word_neq_0_conv)\n  apply simp\n  done\n\nlemma le_imp_power_dvd_int:\n  \"n \\<le> m \\<Longrightarrow> (b ^ n :: int) dvd b ^ m\"\n  apply (simp add: dvd_def)\n  apply (rule exI[where x=\"b ^ (m - n)\"])\n  apply (simp add: power_add[symmetric])\n  done\n\n    (* FIXME: this is identical to mask_eqs(1), unnecessary? *)\nlemma mask_inner_mask:\n  \"((p && mask n) + q) && mask n\n       = (p + q) && mask n\"\n  apply (rule mask_eqs(1))\n  done\n\nlemma mask_add_aligned:\n  \"is_aligned p n\n     \\<Longrightarrow> (p + q) && mask n = q && mask n\"\n  apply (simp add: is_aligned_mask)\n  apply (subst mask_inner_mask [symmetric])\n  apply simp\n  done\n\nlemma take_prefix:\n  \"(take (length xs) ys = xs) = (xs \\<le> ys)\"\nproof (induct xs arbitrary: ys)\n  case Nil thus ?case by simp\nnext\n  case Cons thus ?case by (cases ys) auto\nqed\n\nlemma rel_comp_Image:\n  \"(R O R') `` S = R' `` (R `` S)\"\n  by blast\n\nlemma trancl_power:\n  \"x \\<in> r^+ = (\\<exists>n > 0. x \\<in> r^^n)\"\n  apply (cases x)\n  apply simp\n  apply (rule iffI)\n   apply (drule tranclD2)\n   apply (clarsimp simp: rtrancl_is_UN_relpow)\n   apply (rule_tac x=\"Suc n\" in exI)\n   apply fastforce\n  apply clarsimp\n  apply (case_tac n, simp)\n  apply clarsimp\n  apply (drule relpow_imp_rtrancl)\n  apply fastforce\n  done\n\nlemma take_is_prefix:\n  \"take n xs \\<le> xs\"\n  apply (simp add: less_eq_list_def prefixeq_def)\n  apply (rule_tac x=\"drop n xs\" in exI)\n  apply simp\n  done\n\nlemma cart_singleton_empty:\n  \"(S \\<times> {e} = {}) = (S = {})\"\n  by blast\n\nlemma word_div_1:\n  \"(n :: ('a :: len) word) div 1 = n\"\n  by (simp add: word_div_def)\n\nlemma word_minus_one_le:\n  \"-1 \\<le> (x :: ('a :: len) word) = (x = -1)\"\n  apply (insert word_n1_ge[where y=x])\n  apply safe\n  apply (erule(1) order_antisym)\n  done\n\nlemmas word32_minus_one_le =\n    word_minus_one_le[where 'a=32, simplified]\n\nlemma mask_out_sub_mask:\n  \"(x && ~~ mask n) = x - (x && mask n)\"\n  by (simp add: field_simps word_plus_and_or_coroll2)\n\nlemma is_aligned_addD1:\n  assumes al1: \"is_aligned (x + y) n\"\n  and     al2: \"is_aligned (x::'a::len word) n\"\n  shows \"is_aligned y n\"\n  using al2\nproof (rule is_aligned_get_word_bits)\n  assume \"x = 0\" thus ?thesis using al1 by simp\nnext\n  assume nv: \"n < len_of TYPE('a)\"\n  from al1 obtain q1\n    where xy: \"x + y = 2 ^ n * of_nat q1\" and \"q1 < 2 ^ (len_of TYPE('a) - n)\"\n    by (rule is_alignedE)\n  moreover from al2 obtain q2\n    where x: \"x = 2 ^ n * of_nat q2\" and \"q2 < 2 ^ (len_of TYPE('a) - n)\"\n    by (rule is_alignedE)\n  ultimately have \"y = 2 ^ n * (of_nat q1 - of_nat q2)\"\n    by (simp add: field_simps)\n  thus ?thesis using nv by (simp add: is_aligned_mult_triv1)\nqed\n\nlemmas is_aligned_addD2 =\n       is_aligned_addD1[OF subst[OF add.commute,\n                                 of \"%x. is_aligned x n\" for n]]\n\nlemma is_aligned_add:\n  \"\\<lbrakk>is_aligned p n; is_aligned q n\\<rbrakk> \\<Longrightarrow> is_aligned (p + q) n\"\n  by (simp add: is_aligned_mask mask_add_aligned)\n\nlemma my_BallE: \"\\<lbrakk> \\<forall>x \\<in> A. P x; y \\<in> A; P y \\<Longrightarrow> Q \\<rbrakk> \\<Longrightarrow> Q\"\n  by (simp add: Ball_def)\n\nlemma word_le_add:\n  fixes x :: \"'a :: len word\"\n  shows \"x \\<le> y \\<Longrightarrow> \\<exists>n. y = x + of_nat n\"\n  apply (rule exI [where x = \"unat (y - x)\"])\n  apply simp\n  done\n\n\n\nlemma zipWith_nth:\n  \"\\<lbrakk> n < min (length xs) (length ys) \\<rbrakk> \\<Longrightarrow> zipWith f xs ys ! n = f (xs ! n) (ys ! n)\"\n  unfolding zipWith_def by simp\n\nlemma length_zipWith:\n  \"length (zipWith f xs ys) = min (length xs) (length ys)\"\n  unfolding zipWith_def by simp\n\nlemma distinct_prop_nth:\n  \"\\<lbrakk> distinct_prop P ls; n < n'; n' < length ls \\<rbrakk> \\<Longrightarrow> P (ls ! n) (ls ! n')\"\n  apply (induct ls arbitrary: n n')\n   apply simp\n  apply simp\n  apply (case_tac n')\n   apply simp\n  apply simp\n  apply (case_tac n)\n   apply simp\n  apply simp\n  done\n\nlemma shiftl_mask_is_0 :\n  \"(x << n) && mask n = 0\"\n  apply (rule iffD1 [OF is_aligned_mask])\n  apply (rule is_aligned_shiftl_self)\n  done\n\nlemma word_power_nonzero:\n  \"\\<lbrakk> (x :: word32) < 2 ^ (word_bits - n); n < word_bits; x \\<noteq> 0 \\<rbrakk> \\<Longrightarrow> x * 2 ^ n \\<noteq> 0\"\n  apply (cases \"n = 0\")\n   apply simp\n  apply (simp only: word_neq_0_conv word_less_nat_alt\n                    shiftl_t2n mod_0 unat_word_ariths\n                    unat_power_lower word_le_nat_alt word_bits_def)\n  apply (unfold word_bits_len_of)\n  apply (subst mod_less)\n   apply (subst mult.commute, erule nat_less_power_trans)\n   apply simp\n  apply simp\n  done\n\nlemmas unat_mult_simple = iffD1 [OF unat_mult_lem [where 'a = 32, unfolded word_bits_len_of]]\n\ndefinition\n  sum_map :: \"('a \\<Rightarrow> 'b) \\<Rightarrow> ('c \\<Rightarrow> 'd) \\<Rightarrow> 'a + 'c \\<Rightarrow> 'b + 'd\" where\n \"sum_map f g x \\<equiv> case x of Inl v \\<Rightarrow> Inl (f v) | Inr v' \\<Rightarrow> Inr (g v')\"\n\nlemma sum_map_simps[simp]:\n  \"sum_map f g (Inl v) = Inl (f v)\"\n  \"sum_map f g (Inr w) = Inr (g w)\"\n  by (simp add: sum_map_def)+\n\nlemma if_and_helper:\n  \"(If x v v') && v'' = If x (v && v'') (v' && v'')\"\n  by (simp split: split_if)\n\nlemma unat_Suc2:\n  fixes n :: \"('a :: len) word\"\n  shows\n  \"n \\<noteq> -1 \\<Longrightarrow> unat (n + 1) = Suc (unat n)\"\n  apply (subst add.commute, rule unatSuc)\n  apply (subst eq_diff_eq[symmetric], simp add: minus_equation_iff)\n  done\n\nlemmas unat_eq_1\n    = unat_eq_0 word_unat.Rep_inject[where y=1, simplified]\n\nlemma cart_singleton_image:\n  \"S \\<times> {s} = (\\<lambda>v. (v, s)) ` S\"\n  by auto\n\nlemma singleton_eq_o2s:\n  \"({x} = set_option v) = (v = Some x)\"\n  by (cases v, auto)\n\nlemma ran_option_map_restrict_eq:\n  \"\\<lbrakk> x \\<in> ran (option_map f o g); x \\<notin> ran (option_map f o (g |` (- {y}))) \\<rbrakk>\n        \\<Longrightarrow> \\<exists>v. g y = Some v \\<and> f v = x\"\n  apply (clarsimp simp: elim!: ranE)\n  apply (rename_tac w z)\n  apply (case_tac \"w = y\")\n   apply clarsimp\n  apply (erule notE, rule_tac a=w in ranI)\n  apply (simp add: restrict_map_def)\n  done\n\nlemma option_set_singleton_eq:\n  \"(set_option opt = {v}) = (opt = Some v)\"\n  by (cases opt, simp_all)\n\nlemmas option_set_singleton_eqs\n    = option_set_singleton_eq\n      trans[OF eq_commute option_set_singleton_eq]\n\nlemma option_map_comp2:\n  \"option_map (f o g) = option_map f o option_map g\"\n  by (simp add: option.map_comp fun_eq_iff)\n\nlemma rshift_sub_mask_eq:\n  \"(a >> (size a - b)) && mask b = a >> (size a - b)\"\n  using shiftl_shiftr2[where a=a and b=0 and c=\"size a - b\"]\n  apply (cases \"b < size a\")\n   apply simp\n  apply (simp add: linorder_not_less mask_def word_size\n                   p2_eq_0[THEN iffD2])\n  done\n\nlemma shiftl_shiftr3:\n  \"b \\<le> c \\<Longrightarrow> a << b >> c = (a >> c - b) && mask (size a - c)\"\n  apply (cases \"b = c\")\n   apply (simp add: shiftl_shiftr1)\n  apply (simp add: shiftl_shiftr2)\n  done\n\nlemma and_mask_shiftr_comm:\n  \"m\\<le>size w \\<Longrightarrow> (w && mask m) >> n = (w >> n) && mask (m-n)\"\n   by (simp add: and_mask shiftr_shiftr) (simp add: word_size shiftl_shiftr3)\n\n\n\nlemma and_not_mask_twice:\n  \"(w && ~~ mask n) && ~~ mask m = w && ~~ mask (max m n)\"\napply (simp add: and_not_mask)\napply (case_tac \"n<m\")\n apply (simp_all add: shiftl_shiftr2 shiftl_shiftr1 not_less max_def\n                      shiftr_shiftr shiftl_shiftl)\n apply (cut_tac and_mask_shiftr_comm\n                [where w=w and m=\"size w\" and n=m, simplified,symmetric])\n apply (simp add: word_size mask_def)\napply (cut_tac and_mask_shiftr_comm\n               [where w=w and m=\"size w\" and n=n, simplified,symmetric])\napply (simp add: word_size mask_def)\ndone\n\n(* FIXME: move *)\nlemma word_less_cases:\n  \"x < y \\<Longrightarrow> x = y - 1 \\<or> x < y - (1 ::'a::len word)\"\n  apply (drule word_less_sub_1)\n  apply (drule order_le_imp_less_or_eq)\n  apply auto\n  done\n\nlemma eq_eqI:\n  \"a = b \\<Longrightarrow> (a = x) = (b = x)\"\n  by simp\n\nlemma mask_and_mask:\n  \"mask a && mask b = mask (min a b)\"\n  apply (rule word_eqI)\n  apply (simp add: word_size)\n  done\n\nlemma mask_eq_0_eq_x:\n  \"(x && w = 0) = (x && ~~ w = x)\"\n  using word_plus_and_or_coroll2[where x=x and w=w]\n  by auto\n\nlemma mask_eq_x_eq_0:\n  \"(x && w = x) = (x && ~~ w = 0)\"\n  using word_plus_and_or_coroll2[where x=x and w=w]\n  by auto\n\ndefinition\n  \"limited_and (x :: ('a :: len) word) y = (x && y = x)\"\n\nlemma limited_and_eq_0:\n  \"\\<lbrakk> limited_and x z; y && ~~ z = y \\<rbrakk> \\<Longrightarrow> x && y = 0\"\n  unfolding limited_and_def\n  apply (subst arg_cong2[where f=\"op &&\"])\n    apply (erule sym)+\n  apply (simp(no_asm) add: word_bw_assocs word_bw_comms word_bw_lcs)\n  done\n\nlemma limited_and_eq_id:\n  \"\\<lbrakk> limited_and x z; y && z = z \\<rbrakk> \\<Longrightarrow> x && y = x\"\n  unfolding limited_and_def\n  by (erule subst, fastforce simp: word_bw_lcs word_bw_assocs word_bw_comms)\n\nlemma lshift_limited_and:\n  \"limited_and x z \\<Longrightarrow> limited_and (x << n) (z << n)\"\n  unfolding limited_and_def\n  by (simp add: shiftl_over_and_dist[symmetric])\n\nlemma rshift_limited_and:\n  \"limited_and x z \\<Longrightarrow> limited_and (x >> n) (z >> n)\"\n  unfolding limited_and_def\n  by (simp add: shiftr_over_and_dist[symmetric])\n\nlemmas limited_and_simps1 = limited_and_eq_0 limited_and_eq_id\n\nlemmas is_aligned_limited_and\n    = is_aligned_neg_mask_eq[unfolded mask_def, folded limited_and_def]\n\nlemma compl_of_1: \"~~ 1 = (-2 :: ('a :: len) word)\"\n  apply (rule word_bool_alg.compl_eq_compl_iff[THEN iffD1])\n  apply simp\n  done\n\nlemmas limited_and_simps = limited_and_simps1\n       limited_and_simps1[OF is_aligned_limited_and]\n       limited_and_simps1[OF lshift_limited_and]\n       limited_and_simps1[OF rshift_limited_and]\n       limited_and_simps1[OF rshift_limited_and, OF is_aligned_limited_and]\n       compl_of_1 shiftl_shiftr1[unfolded word_size mask_def]\n       shiftl_shiftr2[unfolded word_size mask_def]\n\nlemma isRight_sum_case: \"isRight x \\<Longrightarrow> case_sum f g x = g (theRight x)\"\n  by (clarsimp simp add: isRight_def)\n\nlemma split_word_eq_on_mask:\n  \"(x = y) = (x && m = y && m \\<and> x && ~~ m = y && ~~ m)\"\n  apply safe\n  apply (rule word_eqI)\n  apply (drule_tac x=n in word_eqD)+\n  apply (simp add: word_size word_ops_nth_size)\n  apply auto\n  done\n\nlemma inj_case_bool:\n  \"inj (case_bool a b) = (a \\<noteq> b)\"\n  by (auto dest: inj_onD[where x=True and y=False]\n          intro: inj_onI split: bool.split_asm)\n\nlemma zip_map2:\n  \"zip as (map f bs) = map (\\<lambda>(a, b). (a, f b)) (zip as bs)\"\n  apply (induct bs arbitrary: as)\n   apply simp\n  apply (case_tac as)\n   apply simp\n  apply simp\n  done\n\nlemma zip_same: \"zip xs xs = map (\\<lambda>v. (v, v)) xs\"\n  by (induct xs, simp+)\n\nlemma foldl_fun_upd:\n  \"foldl (\\<lambda>s r. s (r := g r)) f rs\n     = (\\<lambda>x. if x \\<in> set rs then g x else f x)\"\n  apply (induct rs arbitrary: f)\n   apply simp\n  apply (auto simp: fun_eq_iff split: split_if)\n  done\n\nlemma all_rv_choice_fn_eq_pred:\n  \"\\<lbrakk> \\<And>rv. P rv \\<Longrightarrow> \\<exists>fn. f rv = g fn \\<rbrakk>\n    \\<Longrightarrow> \\<exists>fn. \\<forall>rv. P rv \\<longrightarrow> f rv = g (fn rv)\"\n  apply (rule_tac x=\"\\<lambda>rv. SOME h. f rv = g h\" in exI)\n  apply (clarsimp split: split_if)\n  apply (erule meta_allE, drule(1) meta_mp, elim exE)\n  apply (erule someI)\n  done\n\nlemma ex_const_function:\n  \"\\<exists>f. \\<forall>s. f (f' s) = v\"\n  by force\n\nlemma sum_to_zero:\n  \"(a :: 'a :: ring) + b = 0 \\<Longrightarrow> a = (- b)\"\n  by (drule arg_cong[where f=\"\\<lambda> x. x - a\"], simp)\n\nlemma nat_le_Suc_less_imp:\n  \"x < y \\<Longrightarrow> x \\<le> y - Suc 0\"\n  by arith\n\nlemma list_case_If2:\n  \"case_list f g xs = If (xs = []) f (g (hd xs) (tl xs))\"\n  by (simp split: list.split)\n\nlemma length_ineq_not_Nil:\n  \"length xs > n \\<Longrightarrow> xs \\<noteq> []\"\n  \"length xs \\<ge> n \\<Longrightarrow> n \\<noteq> 0 \\<longrightarrow> xs \\<noteq> []\"\n  \"\\<not> length xs < n \\<Longrightarrow> n \\<noteq> 0 \\<longrightarrow> xs \\<noteq> []\"\n  \"\\<not> length xs \\<le> n \\<Longrightarrow> xs \\<noteq> []\"\n  by auto\n\nlemma numeral_eqs:\n  \"2 = Suc (Suc 0)\"\n  \"3 = Suc (Suc (Suc 0))\"\n  \"4 = Suc (Suc (Suc (Suc 0)))\"\n  \"5 = Suc (Suc (Suc (Suc (Suc 0))))\"\n  \"6 = Suc (Suc (Suc (Suc (Suc (Suc 0)))))\"\n  by simp+\n\nlemma psubset_singleton:\n  \"(S \\<subset> {x}) = (S = {})\"\n  by blast\n\nlemma ucast_not_helper:\n  fixes a::word8\n  assumes a: \"a \\<noteq> 0xFF\"\n  shows \"ucast a \\<noteq> (0xFF::word32)\"\nproof\n  assume \"ucast a = (0xFF::word32)\"\n  also\n  have \"(0xFF::word32) = ucast (0xFF::word8)\" by simp\n  finally\n  show False using a\n    apply -\n    apply (drule up_ucast_inj, simp)\n    apply simp\n    done\nqed\n\nlemma length_takeWhile_ge:\n  \"length (takeWhile f xs) = n\n     \\<Longrightarrow> length xs = n \\<or> (length xs > n \\<and> \\<not> f (xs ! n))\"\n  apply (induct xs arbitrary: n)\n   apply simp\n  apply (simp split: split_if_asm)\n  apply (case_tac n, simp_all)\n  done\n\nlemma length_takeWhile_le:\n  \"\\<not> f (xs ! n) \\<Longrightarrow>\n     length (takeWhile f xs) \\<le> n\"\n  apply (induct xs arbitrary: n)\n   apply simp\n  apply (clarsimp split: split_if)\n  apply (case_tac n, simp_all)\n  done\n\nlemma length_takeWhile_gt:\n  \"n < length (takeWhile f xs)\n       \\<Longrightarrow> (\\<exists>ys zs. length ys = Suc n \\<and> xs = ys @ zs \\<and> takeWhile f xs = ys @ takeWhile f zs)\"\n  apply (induct xs arbitrary: n)\n   apply simp\n  apply (simp split: split_if_asm)\n  apply (case_tac n, simp_all)\n   apply (rule_tac x=\"[a]\" in exI)\n   apply simp\n  apply (erule meta_allE, drule(1) meta_mp)\n  apply clarsimp\n  apply (rule_tac x=\"a # ys\" in exI)\n  apply simp\n  done\n\nlemma hd_drop_conv_nth2:\n  \"n < length xs \\<Longrightarrow> hd (drop n xs) = xs ! n\"\n  by (rule hd_drop_conv_nth, clarsimp+)\n\nlemma map_upt_eq_vals_D:\n  \"\\<lbrakk> map f [0 ..< n] = ys; m < length ys \\<rbrakk> \\<Longrightarrow> f m = ys ! m\"\n  by clarsimp\n\nlemma length_le_helper:\n  \"\\<lbrakk> n \\<le> length xs; n \\<noteq> 0 \\<rbrakk> \\<Longrightarrow> xs \\<noteq> [] \\<and> n - 1 \\<le> length (tl xs)\"\n  by (cases xs, simp_all)\n\nlemma all_ex_eq_helper:\n  \"(\\<forall>v. (\\<exists>v'. v = f v' \\<and> P v v') \\<longrightarrow> Q v)\n      = (\\<forall>v'. P (f v') v' \\<longrightarrow> Q (f v'))\"\n  by auto\n\nlemma less_4_cases:\n  \"(x::word32) < 4 \\<Longrightarrow> x=0 \\<or> x=1 \\<or> x=2 \\<or> x=3\"\n  apply clarsimp\n  apply (drule word_less_cases, erule disjE, simp, simp)+\n  done\n\nlemma if_n_0_0:\n  \"((if P then n else 0) \\<noteq> 0) = (P \\<and> n \\<noteq> 0)\"\n  by (simp split: split_if)\n\nlemma insert_dom:\n  assumes fx: \"f x = Some y\"\n  shows   \"insert x (dom f) = dom f\"\n  unfolding dom_def using fx by auto\n\nlemma map_comp_subset_dom:\n  \"dom (prj \\<circ>\\<^sub>m f) \\<subseteq> dom f\"\n  unfolding dom_def\n  by (auto simp: map_comp_Some_iff)\n\nlemmas map_comp_subset_domD = subsetD [OF map_comp_subset_dom]\n\nlemma dom_map_comp:\n  \"x \\<in> dom (prj \\<circ>\\<^sub>m f) = (\\<exists>y z. f x = Some y \\<and> prj y = Some z)\"\n  by (fastforce simp: dom_def map_comp_Some_iff)\n\nlemma option_map_Some_eq2:\n  \"(Some y = option_map f x) = (\\<exists>z. x = Some z \\<and> f z = y)\"\n  by (metis map_option_eq_Some)\n\nlemma option_map_eq_dom_eq:\n  assumes ome: \"option_map f \\<circ> g = option_map f \\<circ> g'\"\n  shows   \"dom g = dom g'\"\nproof (rule set_eqI)\n  fix x\n  {\n    assume \"x \\<in> dom g\"\n    hence \"Some (f (the (g x))) = (option_map f \\<circ> g) x\"\n      by (auto simp: map_option_case split: option.splits)\n    also have \"\\<dots> = (option_map f \\<circ> g') x\" by (simp add: ome)\n    finally have \"x \\<in> dom g'\"\n      by (auto simp: map_option_case split: option.splits)\n  } moreover\n  {\n    assume \"x \\<in> dom g'\"\n    hence \"Some (f (the (g' x))) = (option_map f \\<circ> g') x\"\n      by (auto simp: map_option_case split: option.splits)\n    also have \"\\<dots> = (option_map f \\<circ> g) x\" by (simp add: ome)\n    finally have \"x \\<in> dom g\"\n      by (auto simp: map_option_case split: option.splits)\n  } ultimately show \"(x \\<in> dom g) = (x \\<in> dom g')\" by auto\nqed\n\nlemma map_comp_eqI:\n  assumes dm: \"dom g = dom g'\"\n  and     fg: \"\\<And>x. x \\<in> dom g' \\<Longrightarrow> f (the (g' x)) = f (the (g x))\"\n  shows  \"f \\<circ>\\<^sub>m g = f \\<circ>\\<^sub>m g'\"\n  apply (rule ext)\n  apply (case_tac \"x \\<in> dom g\")\n   apply (frule subst [OF dm])\n   apply (clarsimp split: option.splits)\n   apply (frule domI [where m = g'])\n   apply (drule fg)\n   apply simp\n  apply (frule subst [OF dm])\n  apply clarsimp\n  apply (drule not_sym)\n  apply (clarsimp simp: map_comp_Some_iff)\n  done\n\nlemma is_aligned_0:\n  \"is_aligned 0 n\"\n  unfolding is_aligned_def\n  by simp\n\nlemma compD:\n  \"\\<lbrakk>f \\<circ> g = f \\<circ> g'; g x = v \\<rbrakk> \\<Longrightarrow> f (g' x) = f v\"\n  apply clarsimp\n  apply (subgoal_tac \"(f (g x)) = (f \\<circ> g) x\")\n   apply simp\n  apply (simp (no_asm))\n  done\n\nlemma option_map_comp_eqE:\n  assumes om: \"option_map f \\<circ> mp = option_map f \\<circ> mp'\"\n  and     p1: \"\\<lbrakk> mp x = None; mp' x = None \\<rbrakk> \\<Longrightarrow> P\"\n  and     p2: \"\\<And>v v'. \\<lbrakk> mp x = Some v; mp' x = Some v'; f v = f v' \\<rbrakk> \\<Longrightarrow> P\"\n  shows \"P\"\nproof (cases \"mp x\")\n  case None\n  hence \"x \\<notin> dom mp\" by (simp add: domIff)\n  hence \"mp' x = None\" by (simp add: option_map_eq_dom_eq [OF om] domIff)\n  with None show ?thesis by (rule p1)\nnext\n  case (Some v)\n  hence \"x \\<in> dom mp\" by clarsimp\n  then obtain v' where Some': \"mp' x = Some v'\" by (clarsimp simp add: option_map_eq_dom_eq [OF om])\n  with Some show ?thesis\n  proof (rule p2)\n    show \"f v = f v'\" using Some' compD [OF om, OF Some] by simp\n  qed\nqed\n\nlemma Some_the:\n  \"x \\<in> dom f \\<Longrightarrow> f x = Some (the (f x))\"\n  by clarsimp\n\nlemma map_comp_update:\n  \"f \\<circ>\\<^sub>m (g(x \\<mapsto> v)) = (f \\<circ>\\<^sub>m g)(x := f v)\"\n  apply (rule ext)\n  apply clarsimp\n  apply (case_tac \"g xa\")\n   apply simp\n  apply simp\n  done\n\nlemma restrict_map_eqI:\n  assumes req: \"A |` S = B |` S\"\n  and     mem: \"x \\<in> S\"\n  shows   \"A x = B x\"\nproof -\n  from mem have \"A x = (A |` S) x\" by simp\n  also have \"\\<dots> = (B |` S) x\" using req by simp\n  also have \"\\<dots> = B x\" using mem by simp\n  finally show ?thesis .\nqed\n\nlemma word_or_zero:\n  \"(a || b = 0) = (a = 0 \\<and> b = 0)\"\n  apply (safe, simp_all)\n   apply (rule word_eqI, drule_tac x=n in word_eqD, simp)+\n  done\n\nlemma aligned_shiftr_mask_shiftl:\n  \"is_aligned x n \\<Longrightarrow> ((x >> n) && mask v) << n = x && mask (v + n)\"\n  apply (rule word_eqI)\n  apply (simp add: word_size nth_shiftl nth_shiftr)\n  apply (subgoal_tac \"\\<forall>m. x !! m \\<longrightarrow> m \\<ge> n\")\n   apply auto[1]\n  apply (clarsimp simp: is_aligned_mask)\n  apply (drule_tac x=m in word_eqD)\n  apply (frule test_bit_size)\n  apply (simp add: word_size)\n  done\n\nlemma word_and_1_shiftl:\n  fixes x :: \"('a :: len) word\" shows\n  \"x && (1 << n) = (if x !! n then (1 << n) else 0)\"\n  apply (rule word_eqI)\n  apply (simp add: word_size nth_shiftl word_nth_1 split: split_if\n              del: shiftl_t2n shiftl_1)\n  apply auto\n  done\n\nlemmas word_and_1_shiftls\n    = word_and_1_shiftl[where n=0, simplified]\n      word_and_1_shiftl[where n=1, simplified]\n      word_and_1_shiftl[where n=2, simplified]\n\nlemma word_and_mask_shiftl:\n  \"x && (mask n << m) = ((x >> m) && mask n) << m\"\n  apply (rule word_eqI)\n  apply (simp add: word_size nth_shiftl nth_shiftr)\n  apply auto\n  done\n\nlemma toEnum_eq_to_fromEnum_eq:\n  fixes v :: \"'a :: enum\" shows\n  \"n \\<le> fromEnum (maxBound :: 'a) \\<Longrightarrow> (toEnum n = v) = (n = fromEnum v)\"\n  apply (rule iffI)\n   apply (drule arg_cong[where f=fromEnum])\n   apply simp\n  apply (drule arg_cong[where f=\"toEnum :: nat \\<Rightarrow> 'a\"])\n  apply simp\n  done\n\nlemma if_Const_helper:\n  \"If P (Con x) (Con y) = Con (If P x y)\"\n  by (simp split: split_if)\n\nlemmas if_Some_helper = if_Const_helper[where Con=Some]\n\nlemma expand_restrict_map_eq:\n  \"(m |` S = m' |` S) = (\\<forall>x. x \\<in> S \\<longrightarrow> m x = m' x)\"\n  by (simp add: fun_eq_iff restrict_map_def split: split_if)\n\nlemma unat_ucast_8_32:\n  fixes x :: \"word8\"\n  shows \"unat (ucast x :: word32) = unat x\"\n  unfolding ucast_def unat_def\n  apply (subst int_word_uint)\n  apply (subst mod_pos_pos_trivial)\n    apply simp\n   apply (rule lt2p_lem)\n   apply simp\n  apply simp\n  done\n\nlemma disj_imp_rhs:\n  \"(P \\<Longrightarrow> Q) \\<Longrightarrow> (P \\<or> Q) = Q\"\n  by blast\n\nlemma remove1_filter:\n  \"distinct xs \\<Longrightarrow> remove1 x xs = filter (\\<lambda>y. x \\<noteq> y) xs\"\n  apply (induct xs)\n   apply simp\n  apply clarsimp\n  apply (rule sym, rule filter_True)\n  apply clarsimp\n  done\n\nlemma if_then_1_else_0:\n  \"((if P then 1 else 0) = (0 :: word32)) = (\\<not> P)\"\n  by simp\n\nlemma if_then_0_else_1:\n  \"((if P then 0 else 1) = (0 :: word32)) = (P)\"\n  by simp\n\nlemmas if_then_simps = if_then_0_else_1 if_then_1_else_0\n\n\n\nlemma nat_less_cases':\n  \"(x::nat) < y \\<Longrightarrow> x = y - 1 \\<or> x < y - 1\"\n  by (fastforce intro: nat_less_cases)\n\nlemma word32_FF_is_mask:\n  \"0xFF = mask 8 \"\n  by (simp add: mask_def)\n\nlemma filter_to_shorter_upto:\n  \"n \\<le> m \\<Longrightarrow> filter (\\<lambda>x. x < n) [0 ..< m] = [0 ..< n]\"\n  apply (induct m)\n   apply simp\n  apply clarsimp\n  apply (erule le_SucE)\n   apply simp\n  apply simp\n  done\n\nlemma in_emptyE: \"\\<lbrakk> A = {}; x \\<in> A \\<rbrakk> \\<Longrightarrow> P\" by blast\n\nlemma ucast_of_nat_small:\n  \"x < 2 ^ len_of TYPE('a) \\<Longrightarrow>\n     ucast (of_nat x :: ('a :: len) word) = (of_nat x :: ('b :: len) word)\"\n  apply (rule sym, subst word_unat.inverse_norm)\n  apply (simp add: ucast_def word_of_int[symmetric]\n                   of_nat_nat[symmetric] unat_def[symmetric])\n  apply (simp add: unat_of_nat)\n  done\n\nlemma word_le_make_less:\n  fixes x :: \"('a :: len) word\"\n  shows \"y \\<noteq> -1 \\<Longrightarrow> (x \\<le> y) = (x < (y + 1))\"\n  apply safe\n  apply (erule plus_one_helper2)\n  apply (simp add: eq_diff_eq[symmetric])\n  done\n\nlemma Ball_emptyI:\n  \"S = {} \\<Longrightarrow> (\\<forall>x \\<in> S. P x)\"\n  by simp\n\nlemma allfEI:\n  \"\\<lbrakk> \\<forall>x. P x; \\<And>x. P (f x) \\<Longrightarrow> Q x \\<rbrakk> \\<Longrightarrow> \\<forall>x. Q x\"\n  by fastforce\n\nlemma arith_is_1:\n  \"\\<lbrakk> x \\<le> Suc 0; x > 0 \\<rbrakk> \\<Longrightarrow> x = 1\"\n  by arith\n\n(* sjw: combining lemmas here :( *)\nlemma cart_singleton_empty2:\n  \"({x} \\<times> S = {}) = (S = {})\"\n  \"({} = S \\<times> {e}) = (S = {})\"\n  by auto\n\nlemma cases_simp_conj:\n  \"((P \\<longrightarrow> Q) \\<and> (\\<not> P \\<longrightarrow> Q) \\<and> R) = (Q \\<and> R)\"\n  by fastforce\n\nlemma domE :\n  \"\\<lbrakk> x \\<in> dom m; \\<And>r. \\<lbrakk>m x = Some r\\<rbrakk> \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P\"\n  by clarsimp\n\nlemma dom_eqD:\n  \"\\<lbrakk> f x = Some v; dom f = S \\<rbrakk> \\<Longrightarrow> x \\<in> S\"\n  by clarsimp\n\nlemma exception_set_finite:\n  \"finite {x. P x} \\<Longrightarrow> finite {x. (x = y \\<longrightarrow> Q x) \\<and> P x}\"\n  \"finite {x. P x} \\<Longrightarrow> finite {x. x \\<noteq> y \\<longrightarrow> P x}\"\n   apply (simp add: Collect_conj_eq)\n  apply (subst imp_conv_disj, subst Collect_disj_eq)\n  apply simp\n  done\n\nlemma exfEI:\n  \"\\<lbrakk> \\<exists>x. P x; \\<And>x. P x \\<Longrightarrow> Q (f x) \\<rbrakk> \\<Longrightarrow> \\<exists>x. Q x\"\n  by fastforce\n\nlemma finite_word: \"finite (S :: (('a :: len) word) set)\"\n  by (rule finite)\n\nlemma if_f:\n  \"(if a then f b else f c) = f (if a then b else c)\"\n  by simp\n\nlemma in_16_range:\n  \"0 \\<in> S \\<Longrightarrow> r \\<in> (\\<lambda>x. r + x * (16 :: word32)) ` S\"\n  \"n - 1 \\<in> S \\<Longrightarrow> (r + (16 * n - 16)) \\<in> (\\<lambda>x :: word32. r + x * 16) ` S\"\n  by (clarsimp simp: image_def\n              elim!: bexI[rotated])+\n\ndefinition\n  \"modify_map m p f \\<equiv> m (p := option_map f (m p))\"\n\nlemma modify_map_id:\n  \"modify_map m p id = m\"\n  by (auto simp add: modify_map_def map_option_case split: option.splits)\n\nlemma modify_map_addr_com:\n  assumes com: \"x \\<noteq> y\"\n  shows \"modify_map (modify_map m x g) y f = modify_map (modify_map m y f) x g\"\n  by (rule ext)\n     (simp add: modify_map_def option_map_def com split: option.splits)\n\nlemma modify_map_dom :\n  \"dom (modify_map m p f) = dom m\"\n  unfolding modify_map_def\n  apply (cases \"m p\")\n   apply simp\n   apply (simp add: dom_def)\n  apply simp\n  apply (rule insert_absorb)\n  apply (simp add: dom_def)\n  done\n\nlemma modify_map_None:\n  \"m x = None \\<Longrightarrow> modify_map m x f = m\"\n  by (rule ext) (simp add: modify_map_def)\n\nlemma modify_map_ndom :\n  \"x \\<notin> dom m \\<Longrightarrow> modify_map m x f = m\"\n  by (rule modify_map_None) clarsimp\n\nlemma modify_map_app:\n  \"(modify_map m p f) q = (if p = q then option_map f (m p) else m q)\"\n  unfolding modify_map_def by simp\n\nlemma modify_map_apply:\n  \"m p = Some x \\<Longrightarrow> modify_map m p f = m (p \\<mapsto> f x)\"\n  by (simp add: modify_map_def)\n\nlemma modify_map_com:\n  assumes com: \"\\<And>x. f (g x) = g (f x)\"\n  shows \"modify_map (modify_map m x g) y f = modify_map (modify_map m y f) x g\"\n  using assms by (auto simp: modify_map_def map_option_case split: option.splits)\n\nlemma modify_map_comp:\n  \"modify_map m x (f o g) = modify_map (modify_map m x g) x f\"\n  by (rule ext) (simp add: modify_map_def option.map_comp)\n\nlemma modify_map_exists_eq:\n  \"(\\<exists>cte. modify_map m p' f p= Some cte) = (\\<exists>cte. m p = Some cte)\"\n  by (auto simp: modify_map_def split: if_splits)\n\nlemma modify_map_other:\n  \"p \\<noteq> q \\<Longrightarrow> (modify_map m p f) q = (m q)\"\n  by (simp add: modify_map_app)\n\nlemma modify_map_same:\n  \"(modify_map m p f) p = (option_map f (m p))\"\n  by (simp add: modify_map_app)\n\nlemma next_update_is_modify:\n  \"\\<lbrakk> m p = Some cte'; cte = f cte' \\<rbrakk> \\<Longrightarrow> (m(p \\<mapsto> cte)) = (modify_map m p f)\"\n  unfolding modify_map_def by simp\n\nlemma nat_power_minus_less:\n  \"a < 2 ^ (x - n) \\<Longrightarrow> (a :: nat) < 2 ^ x\"\n  apply (erule order_less_le_trans)\n  apply simp\n  done\n\nlemma neg_rtranclI:\n  \"\\<lbrakk> x \\<noteq> y; (x, y) \\<notin> R\\<^sup>+ \\<rbrakk> \\<Longrightarrow> (x, y) \\<notin> R\\<^sup>*\"\n  apply (erule contrapos_nn)\n  apply (drule rtranclD)\n  apply simp\n  done\n\nlemma neg_rtrancl_into_trancl:\n  \"\\<not> (x, y) \\<in> R\\<^sup>* \\<Longrightarrow> \\<not> (x, y) \\<in> R\\<^sup>+\"\n  by (erule contrapos_nn, erule trancl_into_rtrancl)\n\nlemma set_neqI:\n  \"\\<lbrakk> x \\<in> S; x \\<notin> S' \\<rbrakk> \\<Longrightarrow> S \\<noteq> S'\"\n  by clarsimp\n\nlemma set_pair_UN:\n  \"{x. P x} = UNION {xa. \\<exists>xb. P (xa, xb)} (\\<lambda>xa. {xa} \\<times> {xb. P (xa, xb)})\"\n  apply safe\n  apply (rule_tac a=a in UN_I)\n   apply blast+\n  done\n\nlemma singleton_elemD:\n  \"S = {x} \\<Longrightarrow> x \\<in> S\"\n  by simp\n\nlemma word_to_1_set:\n  \"{0 ..< (1 :: ('a :: len) word)} = {0}\"\n  by fastforce\n\nlemma ball_ran_eq:\n  \"(\\<forall>y \\<in> ran m. P y) = (\\<forall>x y. m x = Some y \\<longrightarrow> P y)\"\n  by (auto simp add: ran_def)\n\nlemma cart_helper:\n  \"({} = {x} \\<times> S) = (S = {})\"\n  by blast\n\nlemmas converse_trancl_induct' = converse_trancl_induct [consumes 1, case_names base step]\n\nlemma disjCI2: \"(\\<not> P \\<Longrightarrow> Q) \\<Longrightarrow> P \\<or> Q\" by blast\n\nlemma insert_UNIV :\n  \"insert x UNIV = UNIV\"\n  by blast\n\nlemma not_singletonE:\n  \"\\<lbrakk> \\<forall>p. S \\<noteq> {p}; S \\<noteq> {}; \\<And>p p'. \\<lbrakk> p \\<noteq> p'; p \\<in> S; p' \\<in> S \\<rbrakk> \\<Longrightarrow> R \\<rbrakk> \\<Longrightarrow> R\"\n  by blast\n\nlemma not_singleton_oneE:\n  \"\\<lbrakk> \\<forall>p. S \\<noteq> {p}; p \\<in> S; \\<And>p'. \\<lbrakk> p \\<noteq> p'; p' \\<in> S \\<rbrakk> \\<Longrightarrow> R \\<rbrakk> \\<Longrightarrow> R\"\n  apply (erule not_singletonE)\n   apply clarsimp\n  apply (case_tac \"p = p'\")\n   apply fastforce\n  apply fastforce\n  done\n\nlemma interval_empty:\n  \"({m..n} = {}) = (\\<not> m \\<le> (n::'a::order))\"\n  apply (rule iffI)\n   apply clarsimp\n  apply auto\n  done\n\nlemma range_subset_eq2:\n  \"{a :: word32 .. b} \\<noteq> {} \\<Longrightarrow> ({a .. b} \\<subseteq> {c .. d}) = (c \\<le> a \\<and> b \\<le> d)\"\n  by (simp add: interval_empty)\n\nlemma singleton_eqD: \"A = {x} \\<Longrightarrow> x \\<in> A\" by blast\n\nlemma ball_ran_fun_updI:\n  \"\\<lbrakk> \\<forall>v \\<in> ran m. P v; \\<forall>v. y = Some v \\<longrightarrow> P v \\<rbrakk>\n        \\<Longrightarrow> \\<forall>v \\<in> ran (m (x := y)). P v\"\n  by (auto simp add: ran_def)\n\nlemma ball_ran_modify_map_eq:\n  \"\\<lbrakk> \\<forall>v. m x = Some v \\<longrightarrow> P (f v) = P v \\<rbrakk>\n        \\<Longrightarrow> (\\<forall>v \\<in> ran (modify_map m x f). P v) = (\\<forall>v \\<in> ran m. P v)\"\n  apply (simp add: ball_ran_eq)\n  apply (rule iff_allI)\n  apply (auto simp: modify_map_def)\n  done\n\nlemma disj_imp: \"(P \\<or> Q) = (\\<not>P \\<longrightarrow> Q)\" by blast\n\nlemma eq_singleton_redux:\n  \"\\<lbrakk> S = {x} \\<rbrakk> \\<Longrightarrow> x \\<in> S\"\n  by simp\n\nlemma if_eq_elem_helperE:\n  \"\\<lbrakk> x \\<in> (if P then S else S');\n    \\<lbrakk> P;   x \\<in> S  \\<rbrakk> \\<Longrightarrow> a = b;\n    \\<lbrakk> \\<not> P; x \\<in> S' \\<rbrakk> \\<Longrightarrow> a = c\n   \\<rbrakk> \\<Longrightarrow> a = (if P then b else c)\"\n  by fastforce\n\nlemma if_option_Some :\n  \"((if P then None else Some x) = Some y) = (\\<not>P \\<and> x = y)\"\n  by simp\n\nlemma insert_minus_eq:\n  \"x \\<notin> A \\<Longrightarrow> A - S = (A - (S - {x}))\"\n  by auto\n\nlemma map2_Cons_2_3:\n  \"(map2 f xs (y # ys) = (z # zs)) = (\\<exists>x xs'. xs = x # xs' \\<and> f x y = z \\<and> map2 f xs' ys = zs)\"\n  by (case_tac xs, simp_all)\n\nlemma map2_xor_replicate_False:\n  \"map2 (\\<lambda>(x\\<Colon>bool) y\\<Colon>bool. x = (\\<not> y)) xs (replicate n False) = take n xs\"\n  apply (induct xs arbitrary: n)\n   apply simp\n  apply (case_tac n)\n   apply (simp add: map2_def)\n  apply simp\n  done\n\nlemma modify_map_K_D:\n  \"modify_map m p (\\<lambda>x. y) p' = Some v \\<Longrightarrow> (m (p \\<mapsto> y)) p' = Some v\"\n  by (simp add: modify_map_def split: split_if_asm)\n\nlemmas tranclE2' = tranclE2 [consumes 1, case_names base trancl]\n\nlemma weak_imp_cong:\n  \"\\<lbrakk> P = R; Q = S \\<rbrakk> \\<Longrightarrow> (P \\<longrightarrow> Q) = (R \\<longrightarrow> S)\"\n  by simp\n\nlemma Collect_Diff_restrict_simp:\n  \"T - {x \\<in> T. Q x} = T - {x. Q x}\"\n  by (auto intro: Collect_cong)\n\nlemma Collect_Int_pred_eq:\n  \"{x \\<in> S. P x} \\<inter> {x \\<in> T. P x} = {x \\<in> (S \\<inter> T). P x}\"\n  by (simp add: Collect_conj_eq [symmetric] conj_ac)\n\nlemma Collect_restrict_predR:\n  \"{x. P x} \\<inter> T = {} \\<Longrightarrow> {x. P x} \\<inter> {x \\<in> T. Q x} = {}\"\n  apply (subst Collect_conj_eq [symmetric])\n  apply (simp add: disjoint_iff_not_equal)\n  apply rule\n  apply (drule_tac x = x in spec)\n  apply clarsimp\n  apply (drule (1) bspec)\n  apply simp\n  done\n\nlemma Diff_Un2:\n  assumes emptyad: \"A \\<inter> D = {}\"\n  and     emptybc: \"B \\<inter> C = {}\"\n  shows   \"(A \\<union> B) - (C \\<union> D) = (A - C) \\<union> (B - D)\"\nproof -\n  have \"(A \\<union> B) - (C \\<union> D) = (A \\<union> B - C) \\<inter> (A \\<union> B - D)\"\n    by (rule Diff_Un)\n  also have \"\\<dots> = ((A - C) \\<union> B) \\<inter> (A \\<union> (B - D))\" using emptyad emptybc\n    by (simp add: Un_Diff Diff_triv)\n  also have \"\\<dots> = (A - C) \\<union> (B - D)\"\n  proof -\n    have \"(A - C) \\<inter> (A \\<union> (B - D)) = A - C\" using  emptyad emptybc\n      by (metis Diff_Int2 Diff_Int_distrib2 inf_sup_absorb)\n    moreover\n    have \"B \\<inter> (A \\<union> (B - D)) = B - D\" using emptyad emptybc\n      by (metis Int_Diff Un_Diff Un_Diff_Int Un_commute Un_empty_left inf_sup_absorb)\n    ultimately show ?thesis\n      by (simp add: Int_Un_distrib2)\n  qed\n  finally show ?thesis .\nqed\n\nlemma ballEI:\n  \"\\<lbrakk> \\<forall>x \\<in> S. Q x; \\<And>x. \\<lbrakk> x \\<in> S; Q x \\<rbrakk> \\<Longrightarrow> P x \\<rbrakk> \\<Longrightarrow> \\<forall>x \\<in> S. P x\"\n  by auto\n\nlemma dom_if_None:\n  \"dom (\\<lambda>x. if P x then None else f x)\n     = dom f - {x. P x}\"\n  by (simp add: dom_def, fastforce)\n\nlemma notemptyI:\n  \"x \\<in> S \\<Longrightarrow> S \\<noteq> {}\"\n  by clarsimp\n\nlemma plus_Collect_helper:\n  \"op + x ` {xa. P (xa :: ('a :: len) word)} = {xa. P (xa - x)}\"\n  by (fastforce simp add: image_def)\n\nlemma plus_Collect_helper2:\n  \"op + (- x) ` {xa. P (xa :: ('a :: len) word)} = {xa. P (x + xa)}\"\n  by (simp add: field_simps plus_Collect_helper)\n\nlemma restrict_map_Some_iff:\n  \"((m |` S) x = Some y) = (m x = Some y \\<and> x \\<in> S)\"\n  by (cases \"x \\<in> S\", simp_all)\n\nlemma context_case_bools:\n  \"\\<lbrakk> \\<And>v. P v \\<Longrightarrow> R v; \\<lbrakk> \\<not> P v; \\<And>v. P v \\<Longrightarrow> R v \\<rbrakk> \\<Longrightarrow> R v \\<rbrakk> \\<Longrightarrow> R v\"\n  by (cases \"P v\", simp_all)\n\nlemma inj_on_fun_upd_strongerI:\n  \"\\<lbrakk>inj_on f A; y \\<notin> f ` (A - {x})\\<rbrakk> \\<Longrightarrow> inj_on (f(x := y)) A\"\n  apply (simp add: inj_on_def)\n  apply blast\n  done\n\nlemma less_handy_casesE:\n  \"\\<lbrakk> m < n; m = 0 \\<Longrightarrow> R;\n     \\<And>m' n'. \\<lbrakk> n = Suc n'; m = Suc m'; m < n \\<rbrakk> \\<Longrightarrow> R \\<rbrakk>\n     \\<Longrightarrow> R\"\n  apply (case_tac n, simp_all)\n  apply (case_tac m, simp_all)\n  done\n\nlemma subset_drop_Diff_strg:\n  \"(A \\<subseteq> C) \\<longrightarrow> (A - B \\<subseteq> C)\"\n  by blast\n\nlemma word32_count_from_top:\n  \"n \\<noteq> 0 \\<Longrightarrow> {0 ..< n :: word32} = {0 ..< n - 1} \\<union> {n - 1}\"\n  apply (rule set_eqI, rule iffI)\n   apply simp\n   apply (drule minus_one_helper3)\n   apply (rule disjCI)\n   apply simp\n  apply simp\n  apply (erule minus_one_helper5)\n  apply fastforce\n  done\n\nlemma Int_Union_empty:\n  \"(\\<And>x. x \\<in> S \\<Longrightarrow> A \\<inter> P x = {}) \\<Longrightarrow> A \\<inter> (\\<Union>x \\<in> S. P x) = {}\"\n  by auto\n\nlemma UN_Int_empty:\n  \"(\\<And>x. x \\<in> S \\<Longrightarrow> P x \\<inter> T = {}) \\<Longrightarrow> (\\<Union>x \\<in> S. P x) \\<inter> T = {}\"\n  by auto\n\nlemma disjointI:\n  \"\\<lbrakk>\\<And>x y. \\<lbrakk> x \\<in> A; y \\<in> B \\<rbrakk> \\<Longrightarrow> x \\<noteq> y \\<rbrakk> \\<Longrightarrow> A \\<inter> B = {}\"\n  by auto\n\nlemma UN_disjointI:\n  assumes rl: \"\\<And>x y. \\<lbrakk> x \\<in> A; y \\<in> B \\<rbrakk> \\<Longrightarrow> P x \\<inter> Q y = {}\"\n  shows \"(\\<Union>x \\<in> A. P x) \\<inter> (\\<Union>x \\<in> B. Q x) = {}\"\n  apply (rule disjointI)\n  apply clarsimp\n  apply (drule (1) rl)\n  apply auto\n  done\n\nlemma UN_set_member:\n  assumes sub: \"A \\<subseteq> (\\<Union>x \\<in> S. P x)\"\n  and      nz: \"A \\<noteq> {}\"\n  shows    \"\\<exists>x \\<in> S. P x \\<inter> A \\<noteq> {}\"\nproof -\n  from nz obtain z where zA: \"z \\<in> A\" by fastforce\n  with sub obtain x where \"x \\<in> S\" and \"z \\<in> P x\" by auto\n  hence \"P x \\<inter> A \\<noteq> {}\" using zA by auto\n  thus ?thesis using sub nz by auto\nqed\n\nlemma append_Cons_cases [consumes 1, case_names pre mid post]:\n  \"\\<lbrakk>(x, y) \\<in> set (as @ b # bs);\n  (x, y) \\<in> set as \\<Longrightarrow> R;\n  \\<lbrakk>(x, y) \\<notin> set as; (x, y) \\<notin> set bs; (x, y) = b\\<rbrakk> \\<Longrightarrow> R;\n  (x, y) \\<in> set bs \\<Longrightarrow> R\\<rbrakk>\n  \\<Longrightarrow> R\" by auto\n\nlemma cart_singletons:\n  \"{a} \\<times> {b} = {(a, b)}\"\n  by blast\n\nlemma disjoint_subset_neg1:\n  \"\\<lbrakk> B \\<inter> C = {}; A \\<subseteq> B; A \\<noteq> {} \\<rbrakk> \\<Longrightarrow> \\<not> A \\<subseteq> C\"\n  by auto\n\nlemma disjoint_subset_neg2:\n  \"\\<lbrakk> B \\<inter> C = {}; A \\<subseteq> C; A \\<noteq> {} \\<rbrakk> \\<Longrightarrow> \\<not> A \\<subseteq> B\"\n  by auto\n\nlemma iffE2:\n  \"\\<lbrakk> P = Q; \\<lbrakk> P; Q \\<rbrakk> \\<Longrightarrow> R; \\<lbrakk> \\<not> P; \\<not> Q \\<rbrakk> \\<Longrightarrow> R \\<rbrakk> \\<Longrightarrow> R\"\n  by blast\n\nlemma minus_one_helper2:\n  \"\\<lbrakk> x - 1 < y \\<rbrakk> \\<Longrightarrow> x \\<le> (y :: ('a :: len) word)\"\n  apply (cases \"x = 0\")\n   apply simp\n  apply (simp add: word_less_nat_alt word_le_nat_alt)\n  apply (subst(asm) unat_minus_one)\n   apply (simp add: word_less_nat_alt)\n  apply (cases \"unat x\")\n   apply (simp add: unat_eq_zero)\n  apply arith\n  done\n\nlemma mod_mod_power:\n  fixes k :: nat\n  shows \"k mod 2 ^ m mod 2 ^ n = k mod 2 ^ (min m n)\"\nproof (cases \"m \\<le> n\")\n  case True\n\n  hence \"k mod 2 ^ m mod 2 ^ n = k mod 2 ^ m\"\n    apply -\n    apply (subst mod_less [where n = \"2 ^ n\"])\n    apply (rule order_less_le_trans [OF mod_less_divisor])\n    apply simp+\n    done\n  also have \"\\<dots> = k mod  2 ^ (min m n)\" using True by simp\n  finally show ?thesis .\nnext\n  case False\n  hence \"n < m\" by simp\n  then obtain d where md: \"m = n + d\"\n    by (auto dest: less_imp_add_positive)\n  hence \"k mod 2 ^ m = 2 ^ n * (k div 2 ^ n mod 2 ^ d) + k mod 2 ^ n\"\n    by (simp add: mod_mult2_eq power_add)\n  hence \"k mod 2 ^ m mod 2 ^ n = k mod 2 ^ n\"\n    by (simp add: mod_add_left_eq)\n  thus ?thesis using False\n    by simp\nqed\nlemma word_div_less:\n  fixes m :: \"'a :: len word\"\n  shows \"m < n \\<Longrightarrow> m div n = 0\"\n  apply (rule word_unat.Rep_eqD)\n  apply (simp add: word_less_nat_alt unat_div)\n  done\n\nlemma word_must_wrap:\n  \"\\<lbrakk> x \\<le> n - 1; n \\<le> x \\<rbrakk> \\<Longrightarrow> n = (0 :: ('a :: len) word)\"\n  apply (rule ccontr)\n  apply (drule(1) order_trans)\n  apply (drule word_sub_1_le)\n  apply (drule(1) order_antisym)\n  apply simp\n  done\n\nlemma upt_add_eq_append':\n  assumes a1: \"i \\<le> j\" and a2: \"j \\<le> k\"\n  shows \"[i..<k] = [i..<j] @ [j..<k]\"\n  using a1 a2\n  by (clarsimp simp: le_iff_add intro!:  upt_add_eq_append)\n\nlemma range_subset_card:\n  \"\\<lbrakk> {a :: ('a :: len) word .. b} \\<subseteq> {c .. d}; b \\<ge> a \\<rbrakk>\n     \\<Longrightarrow> d \\<ge> c \\<and> d - c \\<ge> b - a\"\n  apply (subgoal_tac \"a \\<in> {a .. b}\")\n   apply (frule(1) range_subset_lower)\n   apply (frule(1) range_subset_upper)\n   apply (rule context_conjI, simp)\n   apply (rule word_sub_mono, assumption+)\n    apply (erule word_sub_le)\n   apply (erule word_sub_le)\n  apply simp\n  done\n\nlemma less_1_simp:\n  \"n - 1 < m = (n \\<le> (m :: ('a :: len) word) \\<and> n \\<noteq> 0)\"\n  by unat_arith\n\nlemma alignUp_div_helper:\n  fixes a :: \"'a::len word\"\n  assumes kv: \"k < 2 ^ (len_of TYPE('a) - n)\"\n  and     xk: \"x = 2 ^ n * of_nat k\"\n  and    le: \"a \\<le> x\"\n  and    sz: \"n < len_of TYPE('a)\"\n  and   anz: \"a mod 2 ^ n \\<noteq> 0\"\n  shows \"a div 2 ^ n < of_nat k\"\nproof -\n  have kn: \"unat (of_nat k :: 'a word) * unat ((2::'a word) ^ n)\n            < 2 ^ len_of TYPE('a)\"\n    using xk kv sz\n    apply (subst unat_of_nat_eq)\n     apply (erule order_less_le_trans)\n     apply simp\n    apply (subst unat_power_lower, simp add: word_bits_def)\n    apply (subst mult.commute)\n    apply (rule nat_less_power_trans)\n     apply simp\n    apply simp\n    done\n\n  have \"unat a div 2 ^ n * 2 ^ n \\<noteq> unat a\"\n  proof -\n    have \"unat a = unat a div 2 ^ n * 2 ^ n + unat a mod 2 ^ n\"\n      by (simp add: mod_div_equality)\n    also have \"\\<dots> \\<noteq> unat a div 2 ^ n * 2 ^ n\" using sz anz\n      by (simp add: unat_arith_simps word_bits_def)\n    finally show ?thesis ..\n  qed\n\n  hence \"a div 2 ^ n * 2 ^ n < a\" using sz anz\n    apply (subst word_less_nat_alt)\n    apply (subst unat_word_ariths)\n    apply (subst unat_div)\n    apply simp\n    apply (rule order_le_less_trans [OF mod_le_dividend])\n    apply (erule order_le_neq_trans [OF div_mult_le])\n    done\n\n  also from xk le have \"\\<dots> \\<le> of_nat k * 2 ^ n\" by (simp add: field_simps)\n  finally show ?thesis using sz kv\n    apply -\n    apply (erule word_mult_less_dest [OF _ _ kn])\n    apply (simp add: unat_div)\n    apply (rule order_le_less_trans [OF div_mult_le])\n    apply (rule unat_lt2p)\n    done\nqed\n\nlemma nat_mod_power_lem:\n  fixes a :: nat\n  shows \"1 < a \\<Longrightarrow> a ^ n mod a ^ m = (if m \\<le> n then 0 else a ^ n)\"\n  by (clarsimp, clarsimp simp add: le_iff_add power_add)\n\nlemma power_mod_div:\n  fixes x :: \"nat\"\n  shows \"x mod 2 ^ n div 2 ^ m = x div 2 ^ m mod 2 ^ (n - m)\" (is \"?LHS = ?RHS\")\nproof (cases \"n \\<le> m\")\n  case True\n  hence \"?LHS = 0\"\n    apply -\n    apply (rule div_less)\n    apply (rule order_less_le_trans [OF mod_less_divisor])\n     apply simp\n    apply simp\n    done\n  also have \"\\<dots> = ?RHS\" using True\n    by simp\n  finally show ?thesis .\nnext\n  case False\n  hence lt: \"m < n\" by simp\n  then obtain q where nv: \"n = m + q\" and \"0 < q\"\n    by (auto dest: less_imp_Suc_add)\n\n  hence \"x mod 2 ^ n = 2 ^ m * (x div 2 ^ m mod 2 ^ q) + x mod 2 ^ m\"\n    by (simp add: power_add mod_mult2_eq)\n\n  hence \"?LHS = x div 2 ^ m mod 2 ^ q\"\n    by (simp add: div_add1_eq)\n\n  also have \"\\<dots> = ?RHS\" using nv\n    by simp\n\n  finally show ?thesis .\nqed\n\nlemma word_power_mod_div:\n  fixes x :: \"'a::len word\"\n  shows \"\\<lbrakk> n < len_of TYPE('a); m < len_of TYPE('a)\\<rbrakk>\n  \\<Longrightarrow> x mod 2 ^ n div 2 ^ m = x div 2 ^ m mod 2 ^ (n - m)\"\n  apply (simp add: word_arith_nat_div unat_mod power_mod_div)\n  apply (subst unat_arith_simps(3))\n  apply (subst unat_mod)\n  apply (subst unat_of_nat)+\n  apply (simp add: mod_mod_power min.commute)\n  done\n\n(* FIXME: stronger version of GenericLib.p_assoc_help *)\nlemma x_power_minus_1:\n  fixes x :: \"'a :: {ab_group_add, power, numeral, one}\"\n  shows \"x + (2::'a) ^ n - (1::'a) = x + (2 ^ n - 1)\" by simp\n\nlemma nat_le_power_trans:\n  fixes n :: nat\n  shows \"\\<lbrakk>n \\<le> 2 ^ (m - k); k \\<le> m\\<rbrakk> \\<Longrightarrow> 2 ^ k * n \\<le> 2 ^ m\"\n  apply (drule order_le_imp_less_or_eq)\n  apply (erule disjE)\n   apply (drule (1) nat_less_power_trans)\n   apply (erule order_less_imp_le)\n  apply (simp add: power_add [symmetric])\n  done\n\nlemma nat_diff_add:\n  fixes i :: nat\n  shows \"\\<lbrakk> i + j = k \\<rbrakk> \\<Longrightarrow> i = k - j\"\n  by arith\n\nlemma word_range_minus_1':\n  fixes a :: \"'a :: len word\"\n  shows \"a \\<noteq> 0 \\<Longrightarrow> {a - 1<..b} = {a..b}\"\n  by (simp add: greaterThanAtMost_def atLeastAtMost_def greaterThan_def atLeast_def less_1_simp)\n\nlemma word_range_minus_1:\n  fixes a :: word32\n  shows \"b \\<noteq> 0 \\<Longrightarrow> {a..b - 1} = {a..<b}\"\n  apply (simp add: atLeastLessThan_def atLeastAtMost_def atMost_def lessThan_def)\n  apply (rule arg_cong [where f = \"\\<lambda>x. {a..} \\<inter> x\"])\n  apply rule\n   apply clarsimp\n   apply (erule contrapos_pp)\n   apply (simp add: linorder_not_less linorder_not_le word_must_wrap)\n  apply (clarsimp)\n  apply (drule minus_one_helper3)\n  apply (auto simp: word_less_sub_1)\n  done\n\nlemma ucast_nat_def:\n  \"of_nat (unat x) = (ucast :: ('a :: len) word \\<Rightarrow> ('b :: len) word) x\"\n  by (simp add: ucast_def word_of_int_nat unat_def)\n\nlemma delete_remove1 :\n  \"delete x xs = remove1 x xs\"\n  by (induct xs, auto)\n\nlemma list_case_If:\n  \"(case xs of [] \\<Rightarrow> P | _ \\<Rightarrow> Q)\n    = (if xs = [] then P else Q)\"\n  by (clarsimp simp: neq_Nil_conv)\n\nlemma remove1_Nil_in_set:\n  \"\\<lbrakk> remove1 x xs = []; xs \\<noteq> [] \\<rbrakk> \\<Longrightarrow> x \\<in> set xs\"\n  by (induct xs) (auto split: split_if_asm)\n\nlemma remove1_empty:\n  \"(remove1 v xs = []) = (xs = [v] \\<or> xs = [])\"\n  by (cases xs, simp_all)\n\nlemma set_remove1:\n  \"x \\<in> set (remove1 y xs) \\<Longrightarrow> x \\<in> set xs\"\n  apply (induct xs)\n   apply simp\n  apply (case_tac \"y = a\")\n   apply clarsimp+\n  done\n\nlemma If_rearrage:\n  \"(if P then if Q then x else y else z)\n     = (if P \\<and> Q then x else if P then y else z)\"\n  by simp\n\nlemma cases_simp_left:\n  \"((P \\<longrightarrow> Q) \\<and> (\\<not> P \\<longrightarrow> Q) \\<and> R) = (Q \\<and> R)\"\n  by fastforce\n\nlemma disjI2_strg:\n  \"Q \\<longrightarrow> (P \\<or> Q)\"\n  by simp\n\nlemma eq_2_32_0:\n  \"(2 ^ 32 :: word32) = 0\"\n  by simp\n\nlemma eq_imp_strg:\n  \"P t \\<longrightarrow> (t = s \\<longrightarrow> P s)\"\n  by clarsimp\n\nlemma if_fun_split:\n  \"(if P then \\<lambda>s. Q s else (\\<lambda>s. R s)) = (\\<lambda>s. (P \\<longrightarrow> Q s) \\<and> (\\<not>P \\<longrightarrow> R s))\"\n  by simp\n\nlemma i_hate_words_helper:\n  \"i \\<le> (j - k :: nat) \\<Longrightarrow> i \\<le> j\"\n  by simp\n\nlemma i_hate_words:\n  \"unat (a :: 'a word) \\<le> unat (b :: ('a :: len) word) - Suc 0\n    \\<Longrightarrow> a \\<noteq> -1\"\n  apply (frule i_hate_words_helper)\n  apply (subst(asm) word_le_nat_alt[symmetric])\n  apply (clarsimp simp only: word_minus_one_le)\n  apply (simp only: linorder_not_less[symmetric])\n  apply (erule notE)\n  apply (rule diff_Suc_less)\n  apply (subst neq0_conv[symmetric])\n  apply (subst unat_eq_0)\n  apply (rule notI, drule arg_cong[where f=\"op + 1\"])\n  apply simp\n  done\n\nlemma if_both_strengthen:\n  \"P \\<and> Q \\<longrightarrow> (if G then P else Q)\"\n  by simp\n\nlemma if_both_strengthen2:\n  \"P s \\<and> Q s \\<longrightarrow> (if G then P else Q) s\"\n  by simp\n\nlemma if_swap:\n  \"(if P then Q else R) = (if \\<not>P then R else Q)\" by simp\n\nlemma ignore_if:\n  \"(y and z) s \\<Longrightarrow> (if x then y else z) s\"\n  by (clarsimp simp: pred_conj_def)\n\nlemma imp_consequent:\n  \"P \\<longrightarrow> Q \\<longrightarrow> P\" by simp\n\nlemma list_case_helper:\n  \"xs \\<noteq> [] \\<Longrightarrow> case_list f g xs = g (hd xs) (tl xs)\"\n  by (cases xs, simp_all)\n\nlemma list_cons_rewrite:\n  \"(\\<forall>x xs. L = x # xs \\<longrightarrow> P x xs) = (L \\<noteq> [] \\<longrightarrow> P (hd L) (tl L))\"\n  by (auto simp: neq_Nil_conv)\n\nlemma list_not_Nil_manip:\n  \"\\<lbrakk> xs = y # ys; case xs of [] \\<Rightarrow> False | (y # ys) \\<Rightarrow> P y ys \\<rbrakk> \\<Longrightarrow> P y ys\"\n  by simp\n\nlemma ran_ball_triv:\n  \"\\<And>P m S. \\<lbrakk> \\<forall>x \\<in> (ran S). P x ; m \\<in> (ran S) \\<rbrakk> \\<Longrightarrow> P m\"\n  by blast\n\nlemma singleton_tuple_cartesian:\n  \"({(a, b)} = S \\<times> T) = ({a} = S \\<and> {b} = T)\"\n  \"(S \\<times> T = {(a, b)}) = ({a} = S \\<and> {b} = T)\"\n  by blast+\n\nlemma strengthen_ignore_if:\n  \"A s \\<and> B s \\<longrightarrow> (if P then A else B) s\"\n  by clarsimp\n\nlemma sum_case_True :\n  \"(case r of Inl a \\<Rightarrow> True | Inr b \\<Rightarrow> f b)\n  = (\\<forall>b. r = Inr b \\<longrightarrow> f b)\"\n  by (cases r) auto\n\nlemma sym_ex_elim:\n  \"F x = y \\<Longrightarrow> \\<exists>x. y = F x\"\n  by auto\n\nlemma tl_drop_1 :\n  \"tl xs = drop 1 xs\"\n  by (simp add: drop_Suc)\n\nlemma upt_lhs_sub_map:\n  \"[x ..< y] = map (op + x) [0 ..< y - x]\"\n  apply (induct y)\n   apply simp\n  apply (clarsimp simp: Suc_diff_le)\n  done\n\nlemma upto_0_to_4:\n  \"[0..<4] = 0 # [1..<4]\"\n  apply (subst upt_rec)\n  apply simp\n  done\n\nlemma disjEI:\n  \"\\<lbrakk> P \\<or> Q; P \\<Longrightarrow> R; Q \\<Longrightarrow> S \\<rbrakk>\n     \\<Longrightarrow> R \\<or> S\"\n  by fastforce\n\nlemma dom_fun_upd2:\n  \"s x = Some z \\<Longrightarrow> dom (s (x \\<mapsto> y)) = dom s\"\n  by (simp add: insert_absorb domI)\n\nlemma foldl_True :\n  \"foldl op \\<or> True bs\"\n  by (induct bs) auto\n\nlemma image_set_comp:\n  \"f ` {g x | x. Q x} = (f \\<circ> g) ` {x. Q x}\"\n  by fastforce\n\nlemma mutual_exE:\n  \"\\<lbrakk> \\<exists>x. P x; \\<And>x. P x \\<Longrightarrow> Q x \\<rbrakk> \\<Longrightarrow> \\<exists>x. Q x\"\n  apply clarsimp\n  apply blast\n  done\n\nlemma nat_diff_eq:\n  fixes x :: nat\n  shows \"\\<lbrakk> x - y = x - z; y < x\\<rbrakk> \\<Longrightarrow> y = z\"\n  by arith\n\nlemma overflow_plus_one_self:\n  \"(1 + p \\<le> p) = (p = (-1 :: word32))\"\n  apply (safe, simp_all)\n  apply (rule ccontr)\n  apply (drule plus_one_helper2)\n   apply (rule notI)\n   apply (drule arg_cong[where f=\"\\<lambda>x. x - 1\"])\n   apply simp\n  apply (simp add: field_simps)\n  done\n\nlemma plus_1_less:\n  \"(x + 1 \\<le> (x :: ('a :: len) word)) = (x = -1)\"\n  apply (rule iffI)\n   apply (rule ccontr)\n   apply (cut_tac plus_one_helper2[where x=x, OF order_refl])\n    apply simp\n   apply clarsimp\n   apply (drule arg_cong[where f=\"\\<lambda>x. x - 1\"])\n   apply simp\n  apply simp\n  done\n\nlemma pos_mult_pos_ge:\n  \"[|x > (0::int); n>=0 |] ==> n * x >= n*1\"\n  apply (simp only: mult_left_mono)\n  done\n\nlemma If_eq_obvious:\n  \"x \\<noteq> z \\<Longrightarrow> ((if P then x else y) = z) = (\\<not> P \\<and> y = z)\"\n  by simp\n\nlemma Some_to_the:\n  \"v = Some x \\<Longrightarrow> x = the v\"\n  by simp\n\nlemma dom_if_Some:\n  \"dom (\\<lambda>x. if P x then Some (f x) else g x) = {x. P x} \\<union> dom g\"\n  by fastforce\n\nlemma dom_insert_absorb:\n  \"x \\<in> dom f \\<Longrightarrow> insert x (dom f) = dom f\" by auto\n\nlemma emptyE2:\n  \"\\<lbrakk> S = {}; x \\<in> S \\<rbrakk> \\<Longrightarrow> P\"\n  by simp\n\nlemma mod_div_equality_div_eq:\n  \"a div b * b = (a - (a mod b) :: int)\"\n  by (simp add: field_simps)\n\nlemma zmod_helper:\n  \"n mod m = k \\<Longrightarrow> ((n :: int) + a) mod m = (k + a) mod m\"\n  by (clarsimp simp: pull_mods)\n\nlemma int_div_sub_1:\n  \"\\<lbrakk> m \\<ge> 1 \\<rbrakk> \\<Longrightarrow> (n - (1 :: int)) div m = (if m dvd n then (n div m) - 1 else n div m)\"\n  apply (subgoal_tac \"m = 0 \\<or> (n - (1 :: int)) div m = (if m dvd n then (n div m) - 1 else n div m)\")\n   apply fastforce\n  apply (subst mult_cancel_right[symmetric])\n  apply (simp only: left_diff_distrib split: split_if)\n  apply (simp only: mod_div_equality_div_eq)\n  apply (clarsimp simp: field_simps dvd_mult_div_cancel)\n  apply (clarsimp simp: dvd_eq_mod_eq_0)\n  apply (cases \"m = 1\")\n   apply simp\n  apply (subst mod_diff_eq, simp add: zmod_minus1 mod_pos_pos_trivial)\n  apply clarsimp\n  apply (subst diff_add_cancel[where b=1, symmetric])\n  apply (subst push_mods(1))\n  apply (simp add: field_simps mod_pos_pos_trivial)\n  apply (rule mod_pos_pos_trivial)\n   apply (subst add_0_right[where a=0, symmetric])\n   apply (rule add_mono)\n    apply simp\n   apply simp\n  apply (cases \"(n - 1) mod m = m - 1\")\n   apply (drule zmod_helper[where a=1])\n   apply simp\n  apply (subgoal_tac \"1 + (n - 1) mod m \\<le> m\")\n   apply simp\n  apply (subst field_simps, rule zless_imp_add1_zle)\n  apply simp\n  done\n\nlemmas nat_less_power_trans_16 =\n   subst [OF mult.commute, where P=\"\\<lambda>x. x < v\" for v,\n          OF nat_less_power_trans[where k=4, simplified]]\n\nlemmas nat_less_power_trans_256 =\n   subst [OF mult.commute, where P=\"\\<lambda>x. x < v\" for v,\n          OF nat_less_power_trans[where k=8, simplified]]\nlemmas nat_less_power_trans_4096 =\n   subst [OF mult.commute, where P=\"\\<lambda>x. x < v\" for v,\n          OF nat_less_power_trans[where k=12, simplified]]\n\nlemma ptr_add_image_multI:\n  \"\\<lbrakk> \\<And>x y. (x * val = y * val') = (x * val'' = y); x * val'' \\<in> S \\<rbrakk> \\<Longrightarrow>\n     ptr_add ptr (x * val) \\<in> (\\<lambda>p. ptr_add ptr (p * val')) ` S\"\n  apply (simp add: image_def)\n  apply (erule rev_bexI)\n  apply (rule arg_cong[where f=\"ptr_add ptr\"])\n  apply simp\n  done\n\nlemma shift_times_fold:\n  \"(x :: word32) * (2 ^ n) << m = x << (m + n)\"\n  by (simp add: shiftl_t2n ac_simps power_add)\n\nlemma word_plus_strict_mono_right:\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk>y < z; x \\<le> x + z\\<rbrakk> \\<Longrightarrow> x + y < x + z\"\n  by unat_arith\n\nlemma comp_upd_simp:\n  \"(f \\<circ> (g (x := y))) = ((f \\<circ> g) (x := f y))\"\n  by (rule ext, simp add: o_def)\n\nlemma dom_option_map:\n  \"dom (option_map f o m) = dom m\"\n  by (simp add: dom_def)\n\nlemma drop_imp:\n  \"P \\<Longrightarrow> (A \\<longrightarrow> P) \\<and> (B \\<longrightarrow> P)\" by blast\n\nlemma inj_on_fun_updI2:\n  \"\\<lbrakk> inj_on f A; y \\<notin> f ` (A - {x}) \\<rbrakk>\n       \\<Longrightarrow> inj_on (f(x := y)) A\"\n  apply (rule inj_onI)\n  apply (simp split: split_if_asm)\n   apply (erule notE, rule image_eqI, erule sym)\n   apply simp\n  apply (erule(3) inj_onD)\n  done\n\nlemma inj_on_fun_upd_elsewhere:\n  \"x \\<notin> S \\<Longrightarrow> inj_on (f (x := y)) S = inj_on f S\"\n  apply (simp add: inj_on_def)\n  apply blast\n  done\n\nlemma not_Some_eq_tuple:\n  \"(\\<forall>y z. x \\<noteq> Some (y, z)) = (x = None)\"\n  by (cases x, simp_all)\n\nlemma ran_option_map:\n  \"ran (option_map f o m) = f ` ran m\"\n  by (auto simp add: ran_def)\n\nlemma All_less_Ball:\n  \"(\\<forall>x < n. P x) = (\\<forall>x\\<in>{..< n}. P x)\"\n  by fastforce\n\nlemma Int_image_empty:\n  \"\\<lbrakk> \\<And>x y. f x \\<noteq> g y \\<rbrakk>\n       \\<Longrightarrow> f ` S \\<inter> g ` T = {}\"\n  by auto\n\nlemma Max_prop:\n  \"\\<lbrakk> Max S \\<in> S \\<Longrightarrow> P (Max S); (S :: ('a :: {finite, linorder}) set) \\<noteq> {} \\<rbrakk> \\<Longrightarrow> P (Max S)\"\n  apply (erule meta_mp)\n  apply (rule Max_in)\n   apply simp\n  apply assumption\n  done\n\nlemma Min_prop:\n  \"\\<lbrakk> Min S \\<in> S \\<Longrightarrow> P (Min S); (S :: ('a :: {finite, linorder}) set) \\<noteq> {} \\<rbrakk> \\<Longrightarrow> P (Min S)\"\n  apply (erule meta_mp)\n  apply (rule Min_in)\n   apply simp\n  apply assumption\n  done\n\ndefinition\n  is_inv :: \"('a \\<rightharpoonup> 'b) \\<Rightarrow> ('b \\<rightharpoonup> 'a) \\<Rightarrow> bool\" where\n  \"is_inv f g \\<equiv> ran f = dom g \\<and> (\\<forall>x y. f x = Some y \\<longrightarrow> g y = Some x)\"\n\nlemma is_inv_NoneD:\n  assumes \"g x = None\"\n  assumes \"is_inv f g\"\n  shows \"x \\<notin> ran f\"\nproof -\n  from assms\n  have \"x \\<notin> dom g\" by (auto simp: ran_def)\n  moreover\n  from assms\n  have \"ran f = dom g\"\n    by (simp add: is_inv_def)\n  ultimately\n  show ?thesis by simp\nqed\n\nlemma is_inv_SomeD:\n  \"\\<lbrakk> f x = Some y; is_inv f g \\<rbrakk> \\<Longrightarrow> g y = Some x\"\n  by (simp add: is_inv_def)\n\nlemma is_inv_com:\n  \"is_inv f g \\<Longrightarrow> is_inv g f\"\n  apply (unfold is_inv_def)\n  apply safe\n    apply (clarsimp simp: ran_def dom_def set_eq_iff)\n    apply (erule_tac x=a in allE)\n    apply clarsimp\n   apply (clarsimp simp: ran_def dom_def set_eq_iff)\n   apply blast\n  apply (clarsimp simp: ran_def dom_def set_eq_iff)\n  apply (erule_tac x=x in allE)\n  apply clarsimp\n  done\n\nlemma is_inv_inj:\n  \"is_inv f g \\<Longrightarrow> inj_on f (dom f)\"\n  apply (frule is_inv_com)\n  apply (clarsimp simp: inj_on_def)\n  apply (drule (1) is_inv_SomeD)\n  apply (drule_tac f=f in is_inv_SomeD, assumption)\n  apply simp\n  done\n\nlemma is_inv_None_upd:\n  \"\\<lbrakk> is_inv f g; g x = Some y\\<rbrakk> \\<Longrightarrow> is_inv (f(y := None)) (g(x := None))\"\n  apply (subst is_inv_def)\n  apply (clarsimp simp add: dom_upd)\n  apply (drule is_inv_SomeD, erule is_inv_com)\n  apply (frule is_inv_inj)\n  apply (simp add: ran_upd')\n  apply (rule conjI)\n   apply (simp add: is_inv_def)\n  apply (drule (1) is_inv_SomeD)\n  apply (clarsimp simp: is_inv_def)\n  done\n\nlemma is_inv_inj2:\n  \"is_inv f g \\<Longrightarrow> inj_on g (dom g)\"\n  apply (drule is_inv_com)\n  apply (erule is_inv_inj)\n  done\n\nlemma range_convergence1:\n  \"\\<lbrakk> \\<forall>z. x < z \\<and> z \\<le> y \\<longrightarrow> P z; \\<forall>z > y. P (z :: 'a :: linorder) \\<rbrakk>\n     \\<Longrightarrow> \\<forall>z > x. P z\"\n  apply clarsimp\n  apply (case_tac \"z \\<le> y\")\n   apply simp\n  apply (simp add: linorder_not_le)\n  done\n\nlemma range_convergence2:\n  \"\\<lbrakk> \\<forall>z. x < z \\<and> z \\<le> y \\<longrightarrow> P z; \\<forall>z. z > y \\<and> z < w \\<longrightarrow> P (z :: 'a :: linorder) \\<rbrakk>\n     \\<Longrightarrow> \\<forall>z. z > x \\<and> z < w \\<longrightarrow> P z\"\n  apply (cut_tac range_convergence1[where P=\"\\<lambda>z. z < w \\<longrightarrow> P z\" and x=x and y=y])\n    apply simp\n   apply simp\n  apply simp\n  done\n\nlemma replicate_minus:\n  \"k < n \\<Longrightarrow> replicate n False = replicate (n - k) False @ replicate k False\"\n  by (subst replicate_add [symmetric]) simp\n\nlemmas map_pair_split_imageI\n  = map_prod_imageI[where f=\"split f\" and g=\"split g\"\n                    and a=\"(a, b)\" and b=\"(c, d)\" for a b c d f g, simplified]\n\nlemma word_div_mult:\n  fixes c :: word32\n  shows \"\\<lbrakk>0 < c; a < b * c \\<rbrakk> \\<Longrightarrow> a div c < b\"\n  apply (simp add: word_less_nat_alt unat_div)\n  apply (subst td_gal_lt [symmetric])\n   apply assumption\n  apply (erule order_less_le_trans)\n  apply (subst unat_word_ariths)\n  apply (unfold word_bits_len_of)\n  apply (rule mod_le_dividend)\n  done\n\nlemma word_less_power_trans_ofnat:\n  \"\\<lbrakk>n < 2 ^ (m - k); k \\<le> m; m < len_of TYPE('a)\\<rbrakk>\n   \\<Longrightarrow> of_nat n * 2 ^ k < (2::'a::len word) ^ m\"\n  apply (subst mult.commute)\n  apply (rule word_less_power_trans)\n    apply (simp add: word_less_nat_alt)\n    apply (subst unat_of_nat_eq)\n     apply (erule order_less_trans)\n     apply (simp add: unat_power_lower)+\n    done\n\nlemma upto_enum_step_red':\n  \"\\<lbrakk> c < word_bits; b \\<le> c; is_aligned a c \\<rbrakk> \\<Longrightarrow>\n  [a, a + 2 ^ b .e. a + 2 ^ c - 1] = map (op + a) [0, 2 ^ b .e. 2 ^ c - 1]\"\n  unfolding upto_enum_step_def\n  by (auto simp: upto_enum_word dest:is_aligned_no_overflow)\n\nlemma div_power_helper:\n  \"\\<lbrakk> x \\<le> y; y < word_bits \\<rbrakk> \\<Longrightarrow> (2 ^ y - 1) div (2 ^ x :: word32) = 2 ^ (y - x) - 1\"\n  apply (rule word_uint.Rep_eqD)\n  apply (simp only: uint_word_ariths uint_div uint_power_lower word_bits_len_of)\n  apply (subst mod_pos_pos_trivial, fastforce, fastforce)+\n  apply (subst mod_pos_pos_trivial)\n    apply (simp add: le_diff_eq uint_2p_alt[where 'a=32, unfolded word_bits_len_of])\n   apply (rule less_1_helper)\n   apply (rule power_increasing)\n    apply (simp add: word_bits_def)\n   apply simp\n  apply (subst mod_pos_pos_trivial)\n    apply (simp add: uint_2p_alt[where 'a=32, unfolded word_bits_len_of])\n   apply (rule less_1_helper)\n   apply (rule power_increasing)\n    apply (simp add: word_bits_def)\n   apply simp\n  apply (subst int_div_sub_1)\n    apply simp\n   apply (simp add: uint_2p_alt[where 'a=32, unfolded word_bits_len_of])\n  apply (subst power_0[symmetric, where a=2])\n  apply (simp add: uint_2p_alt[where 'a=32, unfolded word_bits_len_of]\n                   le_imp_power_dvd_int power_sub_int)\n  done\n\nlemma n_less_word_bits:\n  \"(n < word_bits) = (n < 32)\"\n  by (simp add: word_bits_def)\n\nlemma of_nat_less_pow:\n  \"\\<lbrakk> x < 2 ^ n; n < word_bits \\<rbrakk> \\<Longrightarrow> of_nat x < (2 :: word32) ^ n\"\n  apply (subst word_unat_power)\n  apply (rule of_nat_mono_maybe)\n   apply (rule power_strict_increasing)\n    apply (simp add: word_bits_def)\n   apply simp\n  apply assumption\n  done\n\nlemma power_helper:\n  \"\\<lbrakk> (x :: word32) < 2 ^ (m - n); n \\<le> m; m < word_bits \\<rbrakk> \\<Longrightarrow> x * (2 ^ n) < 2 ^ m\"\n  apply (drule word_mult_less_mono1[where k=\"2 ^ n\"])\n    apply (simp add: word_neq_0_conv[symmetric] word_bits_def)\n   apply (simp only: unat_power_lower[where 'a=32, unfolded word_bits_len_of]\n                     power_add[symmetric])\n   apply (rule power_strict_increasing)\n    apply (simp add: word_bits_def)\n   apply simp\n  apply (simp add: power_add[symmetric] del: power_add)\n  done\n\nlemma word_1_le_power:\n  \"n < len_of TYPE('a) \\<Longrightarrow> (1 :: 'a :: len word) \\<le> 2 ^ n\"\n  by (rule inc_le[where i=0, simplified], erule iffD2[OF p2_gt_0])\n\nlemma enum_word_div:\n  fixes v :: \"('a :: len) word\" shows\n  \"\\<exists>xs ys. enum = xs @ [v] @ ys\n             \\<and> (\\<forall>x \\<in> set xs. x < v)\n             \\<and> (\\<forall>y \\<in> set ys. v < y)\"\n  apply (simp only: enum_word_def)\n  apply (subst upt_add_eq_append'[where j=\"unat v\"])\n    apply simp\n   apply (rule order_less_imp_le, simp)\n  apply (simp add: upt_conv_Cons)\n  apply (intro exI conjI)\n    apply fastforce\n   apply clarsimp\n   apply (drule of_nat_mono_maybe[rotated, where 'a='a])\n    apply simp\n   apply simp\n  apply (clarsimp simp: Suc_le_eq)\n  apply (drule of_nat_mono_maybe[rotated, where 'a='a])\n   apply simp\n  apply simp\n  done\n\nlemma less_x_plus_1:\n  fixes x :: \"('a :: len) word\" shows\n  \"x \\<noteq> max_word \\<Longrightarrow> (y < (x + 1)) = (y < x \\<or> y = x)\"\n  apply (rule iffI)\n   apply (rule disjCI)\n   apply (drule plus_one_helper)\n   apply simp\n  apply (subgoal_tac \"x < x + 1\")\n   apply (erule disjE, simp_all)\n  apply (rule plus_one_helper2 [OF order_refl])\n  apply (rule notI, drule max_word_wrap)\n  apply simp\n  done\n\nlemma of_bool_nth:\n  \"of_bool (x !! v) = (x >> v) && 1\"\n  apply (rule word_eqI)\n  apply (simp add: nth_shiftr cong: rev_conj_cong)\n  done\n\nlemma unat_1_0:\n  \"1 \\<le> (x::word32) = (0 < unat x)\"\n  by (auto simp add: word_le_nat_alt)\n\nlemma x_less_2_0_1:\n  fixes x :: word32 shows\n  \"x < 2 \\<Longrightarrow> x = 0 \\<or> x = 1\"\n  by unat_arith\n\nlemma Collect_int_vars:\n  \"{s. P rv s} \\<inter> {s. rv = xf s} = {s. P (xf s) s} \\<inter> {s. rv = xf s}\"\n  by auto\n\nlemma if_0_1_eq:\n  \"((if P then 1 else 0) = (case Q of True \\<Rightarrow> of_nat 1 | False \\<Rightarrow> of_nat 0)) = (P = Q)\"\n  by (simp add: case_bool_If split: split_if)\n\nlemma modify_map_exists_cte :\n  \"(\\<exists>cte. modify_map m p f p' = Some cte) = (\\<exists>cte. m p' = Some cte)\"\n  by (simp add: modify_map_def)\n\nlemmas word_add_le_iff2 = word_add_le_iff [folded no_olen_add_nat]\n\nlemma mask_32_max_word :\n  shows \"mask 32 = (max_word :: word32)\"\n  unfolding mask_def\n  by (simp add: max_word_def)\n\nlemma dom_eqI:\n  assumes c1: \"\\<And>x y. P x = Some y \\<Longrightarrow> \\<exists>y. Q x = Some y\"\n  and     c2: \"\\<And>x y. Q x = Some y \\<Longrightarrow> \\<exists>y. P x = Some y\"\n  shows \"dom P = dom Q\"\n  unfolding dom_def by (auto simp: c1 c2)\n\nlemma dvd_reduce_multiple:\n  fixes k :: nat\n  shows \"(k dvd k * m + n) = (k dvd n)\"\n  apply (induct m)\n   apply simp\n  apply simp\n  apply (subst add.assoc, subst add.commute)\n  apply (subst dvd_reduce)\n  apply assumption\n  done\n\nlemma image_iff:\n  \"inj f \\<Longrightarrow> f x \\<in> f ` S = (x \\<in> S)\"\n  apply rule\n   apply (erule imageE)\n   apply (simp add: inj_eq)\n  apply (erule imageI)\n  done\n\n\n\nlemma of_nat_n_less_equal_power_2:\n  \"n < len_of TYPE('a::len) \\<Longrightarrow> ((of_nat n)::'a word) < 2 ^ n\"\n  apply (induct n)\n   apply clarsimp\n  apply clarsimp\n  apply (metis WordLemmaBucket.of_nat_power\n               n_less_equal_power_2 of_nat_Suc power_Suc)\n  done\n\nlemma of_nat32_n_less_equal_power_2:\n \"n < 32 \\<Longrightarrow> ((of_nat n)::32 word) < 2 ^ n\"\n  by (rule of_nat_n_less_equal_power_2, clarsimp simp: word_size)\n\nlemma map_comp_restrict_map_Some_iff:\n  \"((g \\<circ>\\<^sub>m (m |` S)) x = Some y) = ((g \\<circ>\\<^sub>m m) x = Some y \\<and> x \\<in> S)\"\n  by (auto simp add: map_comp_Some_iff restrict_map_Some_iff)\n\nlemma range_subsetD:\n  fixes a :: \"'a :: order\"\n  shows \"\\<lbrakk> {a..b} \\<subseteq> {c..d}; a \\<le> b \\<rbrakk> \\<Longrightarrow> c \\<le> a \\<and> b \\<le> d\"\n  apply (rule conjI)\n   apply (drule subsetD [where c = a])\n    apply simp\n   apply simp\n  apply (drule subsetD [where c = b])\n   apply simp\n  apply simp\n  done\n\nlemma option_case_dom:\n  \"(case f x of None \\<Rightarrow> a | Some v \\<Rightarrow> b v)\n      = (if x \\<in> dom f then b (the (f x)) else a)\"\n  by (auto split: split_if option.split)\n\nlemma contrapos_imp:\n  \"P \\<longrightarrow> Q \\<Longrightarrow> \\<not> Q \\<longrightarrow> \\<not> P\"\n  by clarsimp\n\nlemma eq_mask_less:\n  fixes w :: \"('a::len) word\"\n  assumes eqm: \"w = w && mask n\"\n  and      sz: \"n < len_of TYPE ('a)\"\n  shows \"w < (2::'a word) ^ n\"\n  by (subst eqm, rule and_mask_less' [OF sz])\n\nlemma of_nat_mono_maybe':\n  fixes Y :: \"nat\"\n  assumes xlt: \"X < 2 ^ len_of TYPE ('a :: len)\"\n  assumes ylt: \"Y < 2 ^ len_of TYPE ('a :: len)\"\n  shows   \"(Y < X) = (of_nat Y < (of_nat X :: 'a :: len word))\"\n  apply (subst word_less_nat_alt)\n  apply (subst unat_of_nat)+\n  apply (subst mod_less)\n   apply (rule ylt)\n  apply (subst mod_less)\n   apply (rule xlt)\n  apply simp\n  done\n\n(* FIXME: MOVE *)\nlemma shiftr_mask_eq:\n  fixes x :: \"'a :: len word\"\n  shows \"(x >> n) && mask (size x - n) = x >> n\"\n  apply (rule word_eqI)\n  apply (simp add: word_size nth_shiftr)\n  apply (rule iffI)\n   apply clarsimp\n  apply (clarsimp)\n  apply (drule test_bit_size)\n  apply (simp add: word_size)\n  done\n\n(* FIXME: move *)\nlemma shiftr_mask_eq':\n  fixes x :: \"'a :: len word\"\n  shows \"m = (size x - n) \\<Longrightarrow> (x >> n) && mask m = x >> n\"\n  by (simp add: shiftr_mask_eq)\n\nlemma zipWith_Nil2 :\n  \"zipWith f xs [] = []\"\n  unfolding zipWith_def by simp\n\nlemma zip_upt_Cons:\n  \"a < b \\<Longrightarrow> zip [a ..< b] (x # xs)\n        = (a, x) # zip [Suc a ..< b] xs\"\n  by (simp add: upt_conv_Cons)\n\nlemma map_comp_eq:\n  \"(f \\<circ>\\<^sub>m g) = (case_option None f \\<circ> g)\"\n  apply (rule ext)\n  apply (case_tac \"g x\")\n   apply simp\n  apply simp\n  done\n\nlemma dom_If_Some:\n   \"dom (\\<lambda>x. if x \\<in> S then Some v else f x) = (S \\<union> dom f)\"\n  by (auto split: split_if)\n\nlemma foldl_fun_upd_const:\n  \"foldl (\\<lambda>s x. s(f x := v)) s xs\n    = (\\<lambda>x. if x \\<in> f ` set xs then v else s x)\"\n  apply (induct xs arbitrary: s)\n   apply simp\n  apply (rule ext, simp)\n  done\n\nlemma foldl_id:\n  \"foldl (\\<lambda>s x. s) s xs = s\"\n  apply (induct xs)\n   apply simp\n  apply simp\n  done\n\nlemma SucSucMinus: \"2 \\<le> n \\<Longrightarrow> Suc (Suc (n - 2)) = n\" by arith\n\nlemma ball_to_all:\n  \"(\\<And>x. (x \\<in> A) = (P x)) \\<Longrightarrow> (\\<forall>x \\<in> A. B x) = (\\<forall>x. P x \\<longrightarrow> B x)\"\n  by blast\n\nlemma bang_big: \"n \\<ge> size (x::'a::len0 word) \\<Longrightarrow> (x !! n) = False\"\n  by (simp add: test_bit_bl word_size)\n\nlemma bang_conj_lt:\n  fixes x :: \"'a :: len word\"\n  shows \"(x !! m \\<and> m < len_of TYPE('a)) = x !! m\"\n  apply (cases \"m < len_of TYPE('a)\")\n   apply simp\n  apply (simp add: not_less bang_big  word_size)\n  done\n\nlemma dom_if:\n  \"dom (\\<lambda>a. if a \\<in> addrs then Some (f a) else g a)  = addrs \\<union> dom g\"\n  by (auto simp: dom_def split: split_if)\n\nlemma less_is_non_zero_p1:\n  fixes a :: \"'a :: len word\"\n  shows \"a < k \\<Longrightarrow> a + 1 \\<noteq> 0\"\n  apply (erule contrapos_pn)\n  apply (drule max_word_wrap)\n  apply (simp add: not_less)\n  done\n\nlemma lt_word_bits_lt_pow:\n  \"sz < word_bits \\<Longrightarrow> sz < 2 ^ word_bits\"\n  by (simp add: word_bits_conv)\n\n(* FIXME: shadows an existing thm *)\nlemma of_nat_mono_maybe_le:\n  \"\\<lbrakk>X < 2 ^ len_of TYPE('a); Y < 2 ^ len_of TYPE('a)\\<rbrakk> \\<Longrightarrow>\n   (Y \\<le> X) = ((of_nat Y :: 'a :: len word) \\<le> of_nat X)\"\n  apply (clarsimp simp: le_less)\n  apply (rule disj_cong)\n   apply (rule of_nat_mono_maybe', assumption+)\n  apply (simp add: word_unat.norm_eq_iff [symmetric])\n  done\n\nlemma neg_mask_bang:\n  \"(~~ mask n :: 'a :: len word) !! m = (n \\<le> m \\<and> m < len_of TYPE('a))\"\n  apply (cases \"m < len_of TYPE('a)\")\n   apply (simp add: word_ops_nth_size word_size not_less)\n  apply (simp add: not_less bang_big  word_size)\n  done\n\nlemma mask_AND_NOT_mask:\n  \"(w && ~~ mask n) && mask n = 0\"\nby (rule word_eqI) (clarsimp simp add: word_size neg_mask_bang)\n\nlemma AND_NOT_mask_plus_AND_mask_eq:\n  \"(w && ~~ mask n) + (w && mask n) = w\"\napply (rule word_eqI)\napply (rename_tac m)\napply (simp add: word_size)\napply (cut_tac word_plus_and_or_coroll[of \"w && ~~ mask n\" \"w && mask n\"])\n apply (simp add: word_ao_dist2[symmetric] word_size neg_mask_bang)\napply (rule word_eqI)\napply (rename_tac m)\napply (simp add: word_size neg_mask_bang)\ndone\n\nlemma mask_eqI:\n  fixes x :: \"'a :: len word\"\n  assumes m1: \"x && mask n = y && mask n\"\n  and     m2: \"x && ~~ mask n = y && ~~ mask n\"\n  shows \"x = y\"\nproof (subst bang_eq, rule allI)\n  fix m\n\n  show \"x !! m = y !! m\"\n  proof (cases \"m < n\")\n    case True\n    hence \"x !! m = ((x && mask n) !! m)\"\n      by (simp add: word_size bang_conj_lt)\n    also have \"\\<dots> = ((y && mask n) !! m)\" using m1 by simp\n    also have \"\\<dots> = y !! m\" using True\n      by (simp add: word_size bang_conj_lt)\n    finally show ?thesis .\n  next\n    case False\n    hence \"x !! m = ((x && ~~ mask n) !! m)\"\n      by (simp add: neg_mask_bang bang_conj_lt)\n    also have \"\\<dots> = ((y && ~~ mask n) !! m)\" using m2 by simp\n    also have \"\\<dots> = y !! m\" using False\n      by (simp add: neg_mask_bang bang_conj_lt)\n    finally show ?thesis .\n  qed\nqed\n\nlemma nat_less_power_trans2:\n  fixes n :: nat\n  shows \"\\<lbrakk>n < 2 ^ (m - k); k \\<le> m\\<rbrakk> \\<Longrightarrow> n * 2 ^ k  < 2 ^ m\"\n  by (subst mult.commute, erule (1) nat_less_power_trans)\n\nlemma nat_move_sub_le: \"(a::nat) + b \\<le> c \\<Longrightarrow> a \\<le> c - b\" by arith\n\nlemma neq_0_no_wrap:\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk> x \\<le> x + y; x \\<noteq> 0 \\<rbrakk> \\<Longrightarrow> x + y \\<noteq> 0\"\n  by clarsimp\n\nlemma plus_minus_one_rewrite:\n  \"v + (- 1 :: ('a :: {ring, one, uminus})) \\<equiv> v - 1\"\n  by (simp add: field_simps)\n\nlemmas plus_minus_one_rewrite32 = plus_minus_one_rewrite[where 'a=word32, simplified]\n\nlemma power_minus_is_div:\n  \"b \\<le> a \\<Longrightarrow> (2 :: nat) ^ (a - b) = 2 ^ a div 2 ^ b\"\n  apply (induct a arbitrary: b)\n   apply simp\n  apply (erule le_SucE)\n   apply (clarsimp simp:Suc_diff_le le_iff_add power_add)\n  apply simp\n  done\n\nlemma two_pow_div_gt_le:\n  \"v < 2 ^ n div (2 ^ m :: nat) \\<Longrightarrow> m \\<le> n\"\n  by (clarsimp dest!: less_two_pow_divD)\n\n\n\nlemma unat_less_word_bits:\n  fixes y :: word32\n  shows \"x < unat y \\<Longrightarrow> x < 2 ^ word_bits\"\n  unfolding word_bits_def\n  by (rule order_less_trans [OF _ unat_lt2p])\n\nlemma word_add_power_off:\n  fixes a :: word32\n  assumes ak: \"a < k\"\n  and kw: \"k < 2 ^ (word_bits - m)\"\n  and mw: \"m < word_bits\"\n  and off: \"off < 2 ^ m\"\n  shows \"(a * 2 ^ m) + off < k * 2 ^ m\"\nproof (cases \"m = 0\")\n  case True\n  thus ?thesis using off ak by simp\nnext\n  case False\n\n  from ak have ak1: \"a + 1 \\<le> k\" by (rule inc_le)\n  hence \"(a + 1) * 2 ^ m \\<noteq> 0\"\n    apply -\n    apply (rule word_power_nonzero)\n    apply (erule order_le_less_trans  [OF _ kw])\n    apply (rule mw)\n    apply (rule less_is_non_zero_p1 [OF ak])\n    done\n  hence \"(a * 2 ^ m) + off < ((a + 1) * 2 ^ m)\" using kw mw\n    apply -\n    apply (simp add: distrib_right)\n    apply (rule word_plus_strict_mono_right [OF off])\n    apply (rule is_aligned_no_overflow'')\n    apply (rule is_aligned_mult_triv2)\n    apply assumption\n    done\n  also have \"\\<dots> \\<le> k * 2 ^ m\" using ak1 mw kw False\n    apply -\n    apply (erule word_mult_le_mono1)\n    apply (simp add: p2_gt_0 word_bits_def)\n    apply (simp add: word_bits_len_of word_less_nat_alt word_bits_def)\n    apply (rule nat_less_power_trans2[where m=32, simplified])\n    apply (simp add: word_less_nat_alt)\n    apply simp\n    done\n  finally show ?thesis .\nqed\n\nlemma word_of_nat_less:\n  \"\\<lbrakk> n < unat x \\<rbrakk> \\<Longrightarrow> of_nat n < x\"\n  apply (simp add: word_less_nat_alt)\n  apply (erule order_le_less_trans[rotated])\n  apply (simp add: unat_of_nat)\n  done\n\nlemma word_rsplit_0:\n  \"word_rsplit (0 :: word32) = [0, 0, 0, 0 :: word8]\"\n  apply (simp add: word_rsplit_def bin_rsplit_def Let_def)\n  done\n\nlemma word_of_nat_le:\n  \"n \\<le> unat x \\<Longrightarrow> of_nat n \\<le> x\"\n  apply (simp add: word_le_nat_alt unat_of_nat)\n  apply (erule order_trans[rotated])\n  apply simp\n  done\n\nlemma word_unat_less_le:\n   \"a \\<le> of_nat b \\<Longrightarrow> unat a \\<le> b\"\n   by (metis eq_iff le_cases le_unat_uoi word_of_nat_le)\n\nlemma filter_eq_If:\n  \"distinct xs \\<Longrightarrow> filter (\\<lambda>v. v = x) xs = (if x \\<in> set xs then [x] else [])\"\n  apply (induct xs)\n   apply simp\n  apply (clarsimp split: split_if)\n  done\n\n(*FIXME: isabelle-2012 *)\nlemma (in semigroup_add) foldl_assoc:\nshows \"foldl op+ (x+y) zs = x + (foldl op+ y zs)\"\nby (induct zs arbitrary: y) (simp_all add:add.assoc)\n\nlemma (in monoid_add) foldl_absorb0:\nshows \"x + (foldl op+ 0 zs) = foldl op+ x zs\"\nby (induct zs) (simp_all add:foldl_assoc)\n\nlemma foldl_conv_concat:\n  \"foldl (op @) xs xss = xs @ concat xss\"\nproof (induct xss arbitrary: xs)\n  case Nil show ?case by simp\nnext\n  interpret monoid_add \"op @\" \"[]\" proof qed simp_all\n  case Cons then show ?case by (simp add: foldl_absorb0)\nqed\n\nlemma foldl_concat_concat:\n  \"foldl op @ [] (xs @ ys) = foldl op @ [] xs @ foldl op @ [] ys\"\n  by (simp add: foldl_conv_concat)\n\nlemma foldl_does_nothing:\n  \"\\<lbrakk> \\<And>x. x \\<in> set xs \\<Longrightarrow> f s x = s \\<rbrakk> \\<Longrightarrow> foldl f s xs = s\"\n  by (induct xs, simp_all)\n\nlemma foldl_use_filter:\n  \"\\<lbrakk> \\<And>v x. \\<lbrakk> \\<not> g x; x \\<in> set xs \\<rbrakk> \\<Longrightarrow> f v x = v \\<rbrakk>\n     \\<Longrightarrow>\n    foldl f v xs = foldl f v (filter g xs)\"\n  apply (induct xs arbitrary: v)\n   apply simp\n  apply (simp split: split_if)\n  done\n\nlemma split_upt_on_n:\n  \"n < m \\<Longrightarrow> [0 ..< m] = [0 ..< n] @ [n] @ [Suc n ..< m]\"\n  apply (subst upt_add_eq_append', simp, erule order_less_imp_le)\n  apply (simp add: upt_conv_Cons)\n  done\n\nlemma unat_ucast_10_32 :\n  fixes x :: \"10 word\"\n  shows \"unat (ucast x :: word32) = unat x\"\n  unfolding ucast_def unat_def\n  apply (subst int_word_uint)\n  apply (subst mod_pos_pos_trivial)\n    apply simp\n   apply (rule lt2p_lem)\n   apply simp\n  apply simp\n  done\n\nlemma map_comp_update_lift:\n  assumes fv: \"f v = Some v'\"\n  shows \"(f \\<circ>\\<^sub>m (g(ptr \\<mapsto> v))) = ((f \\<circ>\\<^sub>m g)(ptr \\<mapsto> v'))\"\n  unfolding map_comp_def\n  apply (rule ext)\n  apply (simp add: fv)\n  done\n\nlemma restrict_map_cong:\n  assumes sv: \"S = S'\"\n  and     rl: \"\\<And>p. p \\<in> S' \\<Longrightarrow> mp p = mp' p\"\n  shows   \"mp |` S = mp' |` S'\"\n  apply (simp add: sv)\n  apply (rule ext)\n  apply (case_tac \"x \\<in> S'\")\n   apply (simp add: rl )\n  apply simp\n  done\n\nlemma and_eq_0_is_nth:\n  fixes x :: \"('a :: len) word\"\n  shows \"y = 1 << n \\<Longrightarrow> ((x && y) = 0) = (\\<not> (x !! n))\"\n  apply safe\n   apply (drule_tac u=\"(x && (1 << n))\" and x=n in word_eqD)\n   apply (simp add: nth_w2p)\n   apply (simp add: test_bit_bin)\n  apply (rule word_eqI)\n  apply (simp add: nth_w2p)\n  done\n\nlemmas and_neq_0_is_nth = arg_cong [where f=Not, OF and_eq_0_is_nth, simplified]\n\nlemma ucast_le_ucast_8_32:\n  \"(ucast x \\<le> (ucast y :: word32)) = (x \\<le> (y :: word8))\"\n  by (simp add: word_le_nat_alt unat_ucast_8_32)\n\nlemma mask_Suc_0 : \"mask (Suc 0) = 1\"\n  by (simp add: mask_def)\n\nlemma ucast_ucast_add:\n  fixes x :: \"('a :: len) word\"\n  fixes y :: \"('b :: len) word\"\n  shows\n  \"len_of TYPE('b) \\<ge> len_of TYPE('a) \\<Longrightarrow>\n    ucast (ucast x + y) = x + ucast y\"\n  apply (rule word_unat.Rep_eqD)\n  apply (simp add: unat_ucast unat_word_ariths mod_mod_power\n                   min.absorb2 unat_of_nat)\n  apply (subst mod_add_left_eq)\n  apply (simp add: mod_mod_power min.absorb2)\n  apply (subst mod_add_right_eq)\n  apply simp\n  done\n\nlemma word_shift_zero:\n  \"\\<lbrakk> x << n = 0; x \\<le> 2^m; m + n < len_of TYPE('a)\\<rbrakk> \\<Longrightarrow> (x::'a::len word) = 0\"\n  apply (rule ccontr)\n  apply (drule (2) word_shift_nonzero)\n  apply simp\n  done\n\nlemma neg_mask_mono_le:\n  \"(x :: 'a :: len word) \\<le> y \\<Longrightarrow> x && ~~ mask n \\<le> y && ~~ mask n\"\nproof (rule ccontr, simp add: linorder_not_le, cases \"n < len_of TYPE('a)\")\n  case False\n  show \"y && ~~ mask n < x && ~~ mask n \\<Longrightarrow> False\"\n    using False\n    by (simp add: mask_def linorder_not_less\n                  power_overflow)\nnext\n  case True\n  assume a: \"x \\<le> y\" and b: \"y && ~~ mask n < x && ~~ mask n\"\n  have word_bits:\n    \"n < len_of TYPE('a)\"\n    using True by assumption\n  have \"y \\<le> (y && ~~ mask n) + (y && mask n)\"\n    by (simp add: word_plus_and_or_coroll2 add.commute)\n  also have \"\\<dots> \\<le> (y && ~~ mask n) + 2 ^ n\"\n    apply (rule word_plus_mono_right)\n     apply (rule order_less_imp_le, rule and_mask_less_size)\n     apply (simp add: word_size word_bits)\n    apply (rule is_aligned_no_overflow'',\n           simp_all add: is_aligned_neg_mask word_bits)\n    apply (rule not_greatest_aligned, rule b)\n     apply (simp_all add: is_aligned_neg_mask)\n    done\n  also have \"\\<dots> \\<le> x && ~~ mask n\"\n    using b\n    apply -\n    apply (subst add.commute, rule le_plus)\n     apply (rule aligned_at_least_t2n_diff,\n            simp_all add: is_aligned_neg_mask)\n    apply (rule ccontr, simp add: linorder_not_le)\n    apply (drule aligned_small_is_0[rotated], simp_all add: is_aligned_neg_mask)\n    done\n  also have \"\\<dots> \\<le> x\"\n    by (rule word_and_le2)\n  also have \"x \\<le> y\" by fact\nfinally\n  show \"False\" using b\n    by simp\nqed\n\nlemma isRight_right_map:\n  \"isRight (case_sum Inl (Inr o f) v) = isRight v\"\n  by (simp add: isRight_def split: sum.split)\n\nlemma bool_mask [simp]:\n  fixes x :: word32\n  shows \"(0 < x && 1) = (x && 1 = 1)\"\n  apply (rule iffI)\n   prefer 2\n   apply simp\n  apply (subgoal_tac \"x && mask 1 < 2^1\")\n   prefer 2\n   apply (rule and_mask_less_size)\n   apply (simp add: word_size)\n  apply (simp add: mask_def)\n  apply (drule word_less_cases [where y=2])\n  apply (erule disjE, simp)\n  apply simp\n  done\n\nlemma option_case_over_if:\n  \"case_option P Q (if G then None else Some v)\n        = (if G then P else Q v)\"\n  \"case_option P Q (if G then Some v else None)\n        = (if G then Q v else P)\"\n  by (simp split: split_if)+\n\n\n\nlemma scast_eq_ucast:\n  \"\\<not> msb x \\<Longrightarrow> scast x = ucast x\"\n  by (simp add: scast_def ucast_def sint_eq_uint)\n\n(* MOVE *)\n\nlemma lt1_neq0:\n  fixes x :: \"'a :: len word\"\n  shows \"(1 \\<le> x) = (x \\<noteq> 0)\" by unat_arith\n\nlemma word_plus_one_nonzero:\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk>x \\<le> x + y; y \\<noteq> 0\\<rbrakk> \\<Longrightarrow> x + 1 \\<noteq> 0\"\n  apply (subst lt1_neq0 [symmetric])\n  apply (subst olen_add_eqv [symmetric])\n  apply (erule word_random)\n  apply (simp add: lt1_neq0)\n  done\n\nlemma word_sub_plus_one_nonzero:\n  fixes n :: \"'a :: len word\"\n  shows \"\\<lbrakk>n' \\<le> n; n' \\<noteq> 0\\<rbrakk> \\<Longrightarrow> (n - n') + 1 \\<noteq> 0\"\n  apply (subst lt1_neq0 [symmetric])\n  apply (subst olen_add_eqv [symmetric])\n  apply (rule word_random [where x' = n'])\n   apply simp\n   apply (erule word_sub_le)\n  apply (simp add: lt1_neq0)\n  done\n\nlemma word_le_minus_mono_right:\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk> z \\<le> y; y \\<le> x; z \\<le> x \\<rbrakk> \\<Longrightarrow> x - y \\<le> x - z\"\n  apply (rule word_sub_mono)\n     apply simp\n    apply assumption\n   apply (erule word_sub_le)\n  apply (erule word_sub_le)\n  done\n\nlemma drop_append_miracle:\n  \"n = length xs \\<Longrightarrow> drop n (xs @ ys) = ys\"\n  by simp\n\nlemma foldr_does_nothing_to_xf:\n  \"\\<lbrakk> \\<And>x s. x \\<in> set xs \\<Longrightarrow> xf (f x s) = xf s \\<rbrakk> \\<Longrightarrow> xf (foldr f xs s) = xf s\"\n  by (induct xs, simp_all)\n\nlemma nat_less_mult_monoish: \"\\<lbrakk> a < b; c < (d :: nat) \\<rbrakk> \\<Longrightarrow> (a + 1) * (c + 1) <= b * d\"\n  apply (drule Suc_leI)+\n  apply (drule(1) mult_le_mono)\n  apply simp\n  done\n\nlemma word_0_sle_from_less[unfolded word_size]:\n  \"\\<lbrakk> x < 2 ^ (size x - 1) \\<rbrakk>  \\<Longrightarrow> 0 <=s x\"\n  apply (clarsimp simp: word_sle_msb_le)\n  apply (simp add: word_msb_nth)\n  apply (subst (asm) word_test_bit_def [symmetric])\n  apply (drule less_mask_eq)\n  apply (drule_tac x=\"size x - 1\" in word_eqD)\n  apply (simp add: word_size)\n  done\n\nlemma not_msb_from_less:\n  \"(v :: 'a word) < 2 ^ (len_of TYPE('a :: len) - 1) \\<Longrightarrow> \\<not> msb v\"\n  apply (clarsimp simp add: msb_nth)\n  apply (drule less_mask_eq)\n  apply (drule word_eqD, drule(1) iffD2)\n  apply simp\n  done\n\nlemma distinct_lemma: \"f x \\<noteq> f y \\<Longrightarrow> x \\<noteq> y\" by auto\n\n\nlemma ucast_sub_ucast:\n  fixes x :: \"'a::len word\"\n  assumes \"y \\<le> x\"\n  assumes T: \"len_of TYPE('a) \\<le> len_of TYPE('b)\"\n  shows \"ucast (x - y) = (ucast x - ucast y :: 'b::len word)\"\nproof -\n  from T\n  have P: \"unat x < 2 ^ len_of TYPE('b)\" \"unat y < 2 ^ len_of TYPE('b)\"\n    by (fastforce intro!: less_le_trans[OF unat_lt2p])+\n  thus ?thesis\n    by (simp add: unat_arith_simps unat_ucast split assms[simplified unat_arith_simps])\nqed\n\nlemma word_1_0:\n  \"\\<lbrakk>a + (1::('a::len) word) \\<le> b; a < of_nat ((2::nat) ^ len_of TYPE(32) - 1)\\<rbrakk> \\<Longrightarrow> a < b\"\n  by unat_arith\n\nlemma unat_of_nat_less:\"\\<lbrakk> a < b; unat b = c \\<rbrakk> \\<Longrightarrow> a < of_nat c\"\n  by fastforce\n\nlemma word_le_plus_1: \"\\<lbrakk> (y::('a::len) word) < y + n; a < n \\<rbrakk> \\<Longrightarrow> y + a \\<le> y + a + 1\"\n  by unat_arith\n\nlemma word_le_plus:\"\\<lbrakk>(a::('a::len) word) < a + b; c < b\\<rbrakk> \\<Longrightarrow> a \\<le> a + c\"\nby (metis order_less_imp_le word_random)\n\n(*\n * Basic signed arithemetic properties.\n *)\n\nlemma sint_minus1 [simp]: \"(sint x = -1) = (x = -1)\"\n  by (metis sint_n1 word_sint.Rep_inverse')\n\nlemma sint_0 [simp]: \"(sint x = 0) = (x = 0)\"\n  by (metis sint_0 word_sint.Rep_inverse')\n\n(* It is not always that case that \"sint 1 = 1\", because of 1-bit word sizes.\n * This lemma produces the different cases. *)\nlemma sint_1_cases:\n  \"\\<lbrakk> \\<lbrakk> len_of TYPE ('a::len) = 1; (a::'a word) = 0; sint a = 0 \\<rbrakk> \\<Longrightarrow> P;\n     \\<lbrakk> len_of TYPE ('a) = 1; a = 1; sint (1 :: 'a word) = -1 \\<rbrakk> \\<Longrightarrow> P;\n      \\<lbrakk> len_of TYPE ('a) > 1; sint (1 :: 'a word) = 1 \\<rbrakk> \\<Longrightarrow> P \\<rbrakk>\n                \\<Longrightarrow> P\"\n   apply atomize_elim\n  apply (case_tac \"len_of TYPE ('a) = 1\")\n   apply clarsimp\n   apply (subgoal_tac \"(UNIV :: 'a word set) = {0, 1}\")\n    apply (metis UNIV_I insert_iff singletonE)\n   apply (subst word_unat.univ)\n   apply (clarsimp simp: unats_def image_def)\n   apply (rule set_eqI, rule iffI)\n    apply clarsimp\n    apply (metis One_nat_def less_2_cases of_nat_1 semiring_1_class.of_nat_0)\n   apply clarsimp\n   apply (metis Abs_fnat_hom_0 Suc_1 lessI of_nat_1 zero_less_Suc)\n  apply clarsimp\n  apply (metis One_nat_def arith_is_1 le_def len_gt_0 sint_eq_uint uint_1 word_msb_1)\n  done\n\nlemma sint_int_min:\n  \"sint (- (2 ^ (len_of TYPE('a) - Suc 0)) :: ('a::len) word) = - (2 ^ (len_of TYPE('a) - Suc 0))\"\n  apply (subst word_sint.Abs_inverse' [where r=\"- (2 ^ (len_of TYPE('a) - Suc 0))\"])\n    apply (clarsimp simp: sints_num)\n   apply (clarsimp simp: wi_hom_syms word_of_int_2p)\n  apply clarsimp\n  done\n\nlemma sint_int_max_plus_1:\n  \"sint (2 ^ (len_of TYPE('a) - Suc 0) :: ('a::len) word) = - (2 ^ (len_of TYPE('a) - Suc 0))\"\n  apply (subst word_of_int_2p [symmetric])\n  apply (subst int_word_sint)\n  apply (clarsimp simp: comm_semiring_1_class.normalizing_semiring_rules(27))\n  done\n\nlemma word32_bounds:\n  \"- (2 ^ (size (x :: word32) - 1)) = (-2147483648 :: int)\"\n  \"((2 ^ (size (x :: word32) - 1)) - 1) = (2147483647 :: int)\"\n  \"- (2 ^ (size (y :: 32 signed word) - 1)) = (-2147483648 :: int)\"\n  \"((2 ^ (size (y :: 32 signed word) - 1)) - 1) = (2147483647 :: int)\"\n  by (simp_all add: word_size)\n\n\n\nlemma sbintrunc_If:\n  \"- 3 * (2 ^ n) \\<le> x \\<and> x < 3 * (2 ^ n)\n    \\<Longrightarrow> sbintrunc n x = (if x < - (2 ^ n) then x + 2 * (2 ^ n)\n        else if x \\<ge> 2 ^ n then x - 2 * (2 ^ n) else x)\"\n  apply (simp add: no_sbintr_alt2, safe)\n    apply (simp add: mod_pos_geq mod_pos_pos_trivial)\n   apply (subst mod_add_self1[symmetric], simp)\n   apply (simp add: mod_pos_pos_trivial)\n  apply (simp add: mod_pos_pos_trivial)\n  done\n\nlemma signed_arith_eq_checks_to_ord:\n  \"(sint a + sint b = sint (a + b ))\n    = ((a <=s a + b) = (0 <=s b))\"\n  \"(sint a - sint b = sint (a - b ))\n    = ((0 <=s a - b) = (b <=s a))\"\n  \"(- sint a = sint (- a)) = (0 <=s (- a) = (a <=s 0))\"\n  using sint_range'[where x=a] sint_range'[where x=b]\n  apply (simp_all add: sint_word_ariths\n                word_sle_def word_sless_alt sbintrunc_If)\n  apply arith+\n  done\n\n(* Basic proofs that signed word div/mod operations are\n * truncations of their integer counterparts. *)\n\nlemma signed_div_arith:\n    \"sint ((a::('a::len) word) sdiv b) = sbintrunc (len_of TYPE('a) - 1) (sint a sdiv sint b)\"\n  apply (subst word_sbin.norm_Rep [symmetric])\n  apply (subst bin_sbin_eq_iff' [symmetric])\n   apply simp\n  apply (subst uint_sint [symmetric])\n  apply (clarsimp simp: sdiv_int_def sdiv_word_def)\n  apply (metis word_ubin.eq_norm)\n  done\n\nlemma signed_mod_arith:\n    \"sint ((a::('a::len) word) smod b) = sbintrunc (len_of TYPE('a) - 1) (sint a smod sint b)\"\n  apply (subst word_sbin.norm_Rep [symmetric])\n  apply (subst bin_sbin_eq_iff' [symmetric])\n   apply simp\n  apply (subst uint_sint [symmetric])\n  apply (clarsimp simp: smod_int_def smod_word_def)\n  apply (metis word_ubin.eq_norm)\n  done\n\n(* Signed word arithmetic overflow constraints. *)\n\nlemma signed_arith_ineq_checks_to_eq:\n  \"((- (2 ^ (size a - 1)) \\<le> (sint a + sint b)) \\<and> (sint a + sint b \\<le> (2 ^ (size a - 1) - 1)))\n    = (sint a + sint b = sint (a + b ))\"\n  \"((- (2 ^ (size a - 1)) \\<le> (sint a - sint b)) \\<and> (sint a - sint b \\<le> (2 ^ (size a - 1) - 1)))\n    = (sint a - sint b = sint (a - b))\"\n  \"((- (2 ^ (size a - 1)) \\<le> (- sint a)) \\<and> (- sint a) \\<le> (2 ^ (size a - 1) - 1))\n    = ((- sint a) = sint (- a))\"\n  \"((- (2 ^ (size a - 1)) \\<le> (sint a * sint b)) \\<and> (sint a * sint b \\<le> (2 ^ (size a - 1) - 1)))\n    = (sint a * sint b = sint (a * b))\"\n  \"((- (2 ^ (size a - 1)) \\<le> (sint a sdiv sint b)) \\<and> (sint a sdiv sint b \\<le> (2 ^ (size a - 1) - 1)))\n    = (sint a sdiv sint b = sint (a sdiv b))\"\n  \"((- (2 ^ (size a - 1)) \\<le> (sint a smod sint b)) \\<and> (sint a smod sint b \\<le> (2 ^ (size a - 1) - 1)))\n    = (sint a smod sint b = sint (a smod b))\"\n  by (auto simp: sint_word_ariths word_size signed_div_arith signed_mod_arith\n                    sbintrunc_eq_in_range range_sbintrunc)\n\nlemmas signed_arith_ineq_checks_to_eq_word32\n    = signed_arith_ineq_checks_to_eq[where 'a=32, unfolded word32_bounds]\n      signed_arith_ineq_checks_to_eq[where 'a=\"32 signed\", unfolded word32_bounds]\n\nlemma signed_arith_sint:\n  \"((- (2 ^ (size a - 1)) \\<le> (sint a + sint b)) \\<and> (sint a + sint b \\<le> (2 ^ (size a - 1) - 1)))\n    \\<Longrightarrow> sint (a + b) = (sint a + sint b)\"\n  \"((- (2 ^ (size a - 1)) \\<le> (sint a - sint b)) \\<and> (sint a - sint b \\<le> (2 ^ (size a - 1) - 1)))\n    \\<Longrightarrow> sint (a - b) = (sint a - sint b)\"\n  \"((- (2 ^ (size a - 1)) \\<le> (- sint a)) \\<and> (- sint a) \\<le> (2 ^ (size a - 1) - 1))\n    \\<Longrightarrow> sint (- a) = (- sint a)\"\n  \"((- (2 ^ (size a - 1)) \\<le> (sint a * sint b)) \\<and> (sint a * sint b \\<le> (2 ^ (size a - 1) - 1)))\n    \\<Longrightarrow> sint (a * b) = (sint a * sint b)\"\n  \"((- (2 ^ (size a - 1)) \\<le> (sint a sdiv sint b)) \\<and> (sint a sdiv sint b \\<le> (2 ^ (size a - 1) - 1)))\n    \\<Longrightarrow> sint (a sdiv b) = (sint a sdiv sint b)\"\n  \"((- (2 ^ (size a - 1)) \\<le> (sint a smod sint b)) \\<and> (sint a smod sint b \\<le> (2 ^ (size a - 1) - 1)))\n    \\<Longrightarrow> sint (a smod b) = (sint a smod sint b)\"\n  by (metis signed_arith_ineq_checks_to_eq)+\n\nlemma signed_mult_eq_checks_double_size:\n  assumes mult_le: \"(2 ^ (len_of TYPE ('a) - 1) + 1) ^ 2\n       \\<le> (2 :: int) ^ (len_of TYPE ('b) - 1)\"\n    and le: \"2 ^ (len_of TYPE('a) - 1) \\<le> (2 :: int) ^ (len_of TYPE ('b) - 1)\"\n  shows\n  \"(sint (a :: ('a :: len) word) * sint b = sint (a * b))\n    = (scast a * scast b = (scast (a * b) :: ('b :: len) word))\"\nproof -\n  have P: \"sbintrunc (size a - 1) (sint a * sint b) \\<in> range (sbintrunc (size a - 1))\"\n    by simp\n\n  have abs: \"!! x :: 'a word. abs (sint x) < 2 ^ (size a - 1) + 1\"\n    apply (cut_tac x=x in sint_range')\n    apply (simp add: abs_le_iff word_size)\n    done\n  have abs_ab: \"abs (sint a * sint b) < 2 ^ (len_of TYPE('b) - 1)\"\n    using abs_mult_less[OF abs[where x=a] abs[where x=b]] mult_le\n    by (simp add: abs_mult power2_eq_square word_size)\n  show ?thesis\n    using P[unfolded range_sbintrunc] abs_ab le\n    apply (simp add: sint_word_ariths scast_def)\n    apply (simp add: wi_hom_mult)\n    apply (subst word_sint.Abs_inject, simp_all)\n     apply (simp add: sints_def range_sbintrunc\n                      abs_less_iff)\n    apply clarsimp\n    apply (simp add: sints_def range_sbintrunc word_size)\n    apply (auto elim: order_less_le_trans order_trans[rotated])\n    done\nqed\n\nlemmas signed_mult_eq_checks32_to_64\n    = signed_mult_eq_checks_double_size[where 'a=32 and 'b=64, simplified]\n      signed_mult_eq_checks_double_size[where 'a=\"32 signed\" and 'b=64, simplified]\n\n(* Properties about signed division. *)\n\nlemma int_sdiv_simps [simp]:\n    \"(a :: int) sdiv 1 = a\"\n    \"(a :: int) sdiv 0 = 0\"\n    \"(a :: int) sdiv -1 = -a\"\n  apply (auto simp: sdiv_int_def sgn_if)\n  done\n\nlemma sgn_div_eq_sgn_mult:\n    \"a div b \\<noteq> 0 \\<Longrightarrow> sgn ((a :: int) div b) = sgn (a * b)\"\n  apply (clarsimp simp: sgn_if zero_le_mult_iff neg_imp_zdiv_nonneg_iff not_less)\n  apply (metis less_le mult_le_0_iff neg_imp_zdiv_neg_iff not_less pos_imp_zdiv_neg_iff zdiv_eq_0_iff)\n  done\n\nlemma sgn_sdiv_eq_sgn_mult:\n    \"a sdiv b \\<noteq> 0 \\<Longrightarrow> sgn ((a :: int) sdiv b) = sgn (a * b)\"\n  apply (clarsimp simp: sdiv_int_def sgn_times)\n  apply (subst sgn_div_eq_sgn_mult)\n   apply simp\n  apply (clarsimp simp: sgn_times)\n  apply (metis abs_mult div_0 div_mult_self2_is_id sgn_0_0 sgn_1_pos sgn_times zero_less_abs_iff)\n  done\n\nlemma int_sdiv_same_is_1 [simp]:\n    \"a \\<noteq> 0 \\<Longrightarrow> ((a :: int) sdiv b = a) = (b = 1)\"\n  apply (rule iffI)\n   apply (clarsimp simp: sdiv_int_def)\n   apply (subgoal_tac \"b > 0\")\n    apply (case_tac \"a > 0\")\n     apply (clarsimp simp: sgn_if sign_simps)\n    apply (clarsimp simp: sign_simps not_less)\n    apply (metis int_div_same_is_1 le_neq_trans minus_minus neg_0_le_iff_le neg_equal_0_iff_equal)\n   apply (case_tac \"a > 0\")\n    apply (case_tac \"b = 0\")\n     apply (clarsimp simp: sign_simps)\n    apply (rule classical)\n    apply (clarsimp simp: sign_simps sgn_times not_less)\n    apply (metis le_less neg_0_less_iff_less not_less_iff_gr_or_eq pos_imp_zdiv_neg_iff)\n   apply (rule classical)\n   apply (clarsimp simp: sign_simps sgn_times not_less sgn_if split: if_splits)\n   apply (metis antisym less_le neg_imp_zdiv_nonneg_iff)\n  apply (clarsimp simp: sdiv_int_def sgn_if)\n  done\n\nlemma int_sdiv_negated_is_minus1 [simp]:\n    \"a \\<noteq> 0 \\<Longrightarrow> ((a :: int) sdiv b = - a) = (b = -1)\"\n  apply (clarsimp simp: sdiv_int_def)\n  apply (rule iffI)\n   apply (subgoal_tac \"b < 0\")\n    apply (case_tac \"a > 0\")\n     apply (clarsimp simp: sgn_if sign_simps not_less)\n    apply (case_tac \"sgn (a * b) = -1\")\n     apply (clarsimp simp: not_less sign_simps)\n    apply (clarsimp simp: sign_simps not_less)\n   apply (rule classical)\n   apply (case_tac \"b = 0\")\n    apply (clarsimp simp: sign_simps not_less sgn_times)\n   apply (case_tac \"a > 0\")\n    apply (clarsimp simp: sign_simps not_less sgn_times)\n    apply (metis less_le neg_less_0_iff_less not_less_iff_gr_or_eq pos_imp_zdiv_neg_iff)\n   apply (clarsimp simp: sign_simps not_less sgn_times)\n   apply (metis div_minus_right eq_iff neg_0_le_iff_le neg_imp_zdiv_nonneg_iff not_leE)\n  apply (clarsimp simp: sgn_if)\n  done\n\nlemma sdiv_int_range:\n    \"(a :: int) sdiv b \\<in> { - (abs a) .. (abs a) }\"\n  apply (unfold sdiv_int_def)\n  apply (subgoal_tac \"(abs a) div (abs b) \\<le> (abs a)\")\n   apply (clarsimp simp: sgn_if)\n   apply (metis Divides.transfer_nat_int_function_closures(1) abs_ge_zero\n              abs_less_iff abs_of_nonneg less_asym less_minus_iff not_less)\n  apply (metis abs_eq_0 abs_ge_zero div_by_0 zdiv_le_dividend zero_less_abs_iff)\n  done\n\n\n\nlemma sdiv_int_div_0 [simp]:\n  \"(x :: int) sdiv 0 = 0\"\n  by (clarsimp simp: sdiv_int_def)\n\nlemma sdiv_int_0_div [simp]:\n  \"0 sdiv (x :: int) = 0\"\n  by (clarsimp simp: sdiv_int_def)\n\nlemma word_sdiv_div0 [simp]:\n    \"(a :: ('a::len) word) sdiv 0 = 0\"\n  apply (auto simp: sdiv_word_def sdiv_int_def sgn_if)\n  done\n\nlemma word_sdiv_div_minus1 [simp]:\n    \"(a :: ('a::len) word) sdiv -1 = -a\"\n  apply (auto simp: sdiv_word_def sdiv_int_def sgn_if)\n  apply (metis wi_hom_neg word_sint.Rep_inverse')\n  done\n\nlemma word_sdiv_0 [simp]: \"(x :: ('a::len) word) sdiv 0 = 0\"\n  by (clarsimp simp: sdiv_word_def)\n\nlemma sdiv_word_min:\n    \"- (2 ^ (size a - 1)) \\<le> sint (a :: ('a::len) word) sdiv sint (b :: ('a::len) word)\"\n  apply (clarsimp simp: word_size)\n  apply (cut_tac sint_range' [where x=a])\n  apply (cut_tac sint_range' [where x=b])\n  apply clarsimp\n  apply (insert sdiv_int_range [where a=\"sint a\" and b=\"sint b\"])\n  apply (clarsimp simp: max_def abs_if split: split_if_asm)\n  done\n\nlemma sdiv_word_max:\n    \"(sint (a :: ('a::len) word) sdiv sint (b :: ('a::len) word) < (2 ^ (size a - 1))) =\n          ((a \\<noteq> - (2 ^ (size a - 1)) \\<or> (b \\<noteq> -1)))\"\n    (is \"?lhs = (\\<not> ?a_int_min \\<or> \\<not> ?b_minus1)\")\nproof (rule classical)\n  assume not_thesis: \"\\<not> ?thesis\"\n\n  have not_zero: \"b \\<noteq> 0\"\n    using not_thesis\n    by (clarsimp)\n\n  have result_range: \"sint a sdiv sint b \\<in> (sints (size a)) \\<union> {2 ^ (size a - 1)}\"\n    apply (cut_tac sdiv_int_range [where a=\"sint a\" and b=\"sint b\"])\n    apply (erule rev_subsetD)\n    using sint_range' [where x=a]  sint_range' [where x=b]\n    apply (auto simp: max_def abs_if word_size sints_num)\n    done\n\n  have result_range_overflow: \"(sint a sdiv sint b = 2 ^ (size a - 1)) = (?a_int_min \\<and> ?b_minus1)\"\n    apply (rule iffI [rotated])\n     apply (clarsimp simp: sdiv_int_def sgn_if word_size sint_int_min)\n    apply (rule classical)\n    apply (case_tac \"?a_int_min\")\n     apply (clarsimp simp: word_size sint_int_min)\n     apply (metis diff_0_right\n              int_sdiv_negated_is_minus1 minus_diff_eq minus_int_code(2)\n              power_eq_0_iff sint_minus1 zero_neq_numeral)\n    apply (subgoal_tac \"abs (sint a) < 2 ^ (size a - 1)\")\n     apply (insert sdiv_int_range [where a=\"sint a\" and b=\"sint b\"])[1]\n     apply (clarsimp simp: word_size)\n    apply (insert sdiv_int_range [where a=\"sint a\" and b=\"sint b\"])[1]\n    apply (insert word_sint.Rep [where x=\"a\"])[1]\n    apply (clarsimp simp: minus_le_iff word_size abs_if sints_num split: split_if_asm)\n    apply (metis minus_minus sint_int_min word_sint.Rep_inject)\n    done\n\n  have result_range_simple: \"(sint a sdiv sint b \\<in> (sints (size a))) \\<Longrightarrow> ?thesis\"\n    apply (insert sdiv_int_range [where a=\"sint a\" and b=\"sint b\"])\n    apply (clarsimp simp: word_size sints_num sint_int_min)\n    done\n\n  show ?thesis\n    apply (rule UnE [OF result_range result_range_simple])\n     apply simp\n    apply (clarsimp simp: word_size)\n    using result_range_overflow\n    apply (clarsimp simp: word_size)\n    done\nqed\n\nlemmas sdiv_word_min' = sdiv_word_min [simplified word_size, simplified]\nlemmas sdiv_word_max' = sdiv_word_max [simplified word_size, simplified]\nlemmas sdiv_word32_max = sdiv_word_max [where 'a=32, simplified word_size, simplified]\n    sdiv_word_max [where 'a=\"32 signed\", simplified word_size, simplified]\nlemmas sdiv_word32_min = sdiv_word_min [where 'a=32, simplified word_size, simplified]\n    sdiv_word_min [where 'a=\"32 signed\", simplified word_size, simplified]\n\n(*\n * Signed modulo properties.\n *)\n\nlemma smod_int_alt_def:\n     \"(a::int) smod b = sgn (a) * (abs a mod abs b)\"\n  apply (clarsimp simp: smod_int_def sdiv_int_def)\n  apply (clarsimp simp: zmod_zdiv_equality' abs_sgn sgn_times sgn_if sign_simps)\n  done\n\nlemma smod_int_range:\n  \"b \\<noteq> 0 \\<Longrightarrow> (a::int) smod b \\<in> { - abs b + 1 .. abs b - 1 }\"\n  apply (case_tac  \"b > 0\")\n   apply (insert pos_mod_conj [where a=a and b=b])[1]\n   apply (insert pos_mod_conj [where a=\"-a\" and b=b])[1]\n   apply (clarsimp simp: smod_int_alt_def sign_simps sgn_if\n              abs_if not_less add1_zle_eq [simplified add.commute])\n   apply (metis add_le_cancel_left comm_monoid_add_class.add.right_neutral\n             int_one_le_iff_zero_less less_le_trans mod_minus_right neg_less_0_iff_less\n             neg_mod_conj not_less pos_mod_conj)\n  apply (insert neg_mod_conj [where a=a and b=\"b\"])[1]\n  apply (insert neg_mod_conj [where a=\"-a\" and b=\"b\"])[1]\n  apply (clarsimp simp: smod_int_alt_def sign_simps sgn_if\n            abs_if not_less add1_zle_eq [simplified add.commute])\n  apply (metis neg_0_less_iff_less neg_mod_conj not_le not_less_iff_gr_or_eq order_trans pos_mod_conj)\n  done\n\nlemma smod_int_compares:\n   \"\\<lbrakk> 0 \\<le> a; 0 < b \\<rbrakk> \\<Longrightarrow> (a :: int) smod b < b\"\n   \"\\<lbrakk> 0 \\<le> a; 0 < b \\<rbrakk> \\<Longrightarrow> 0 \\<le> (a :: int) smod b\"\n   \"\\<lbrakk> a \\<le> 0; 0 < b \\<rbrakk> \\<Longrightarrow> -b < (a :: int) smod b\"\n   \"\\<lbrakk> a \\<le> 0; 0 < b \\<rbrakk> \\<Longrightarrow> (a :: int) smod b \\<le> 0\"\n   \"\\<lbrakk> 0 \\<le> a; b < 0 \\<rbrakk> \\<Longrightarrow> (a :: int) smod b < - b\"\n   \"\\<lbrakk> 0 \\<le> a; b < 0 \\<rbrakk> \\<Longrightarrow> 0 \\<le> (a :: int) smod b\"\n   \"\\<lbrakk> a \\<le> 0; b < 0 \\<rbrakk> \\<Longrightarrow> (a :: int) smod b \\<le> 0\"\n   \"\\<lbrakk> a \\<le> 0; b < 0 \\<rbrakk> \\<Longrightarrow> b \\<le> (a :: int) smod b\"\n  apply (insert smod_int_range [where a=a and b=b])\n  apply (auto simp: add1_zle_eq smod_int_alt_def sgn_if)\n  done\n\nlemma smod_int_mod_0 [simp]:\n  \"x smod (0 :: int) = x\"\n  by (clarsimp simp: smod_int_def)\n\nlemma smod_int_0_mod [simp]:\n  \"0 smod (x :: int) = 0\"\n  by (clarsimp simp: smod_int_alt_def)\n\nlemma smod_word_mod_0 [simp]:\n  \"x smod (0 :: ('a::len) word) = x\"\n  by (clarsimp simp: smod_word_def)\n\nlemma smod_word_0_mod [simp]:\n  \"0 smod (x :: ('a::len) word) = 0\"\n  by (clarsimp simp: smod_word_def)\n\nlemma smod_word_max:\n    \"sint (a::'a word) smod sint (b::'a word) < 2 ^ (len_of TYPE('a::len) - Suc 0)\"\n  apply (case_tac \"b = 0\")\n   apply (insert word_sint.Rep [where x=a, simplified sints_num])[1]\n   apply (clarsimp)\n  apply (insert word_sint.Rep [where x=\"b\", simplified sints_num])[1]\n  apply (insert smod_int_range [where a=\"sint a\" and b=\"sint b\"])\n  apply (clarsimp simp: abs_if split: split_if_asm)\n  done\n\nlemma smod_word_min:\n    \"- (2 ^ (len_of TYPE('a::len) - Suc 0)) \\<le> sint (a::'a word) smod sint (b::'a word)\"\n  apply (case_tac \"b = 0\")\n   apply (insert word_sint.Rep [where x=a, simplified sints_num])[1]\n   apply clarsimp\n  apply (insert word_sint.Rep [where x=b, simplified sints_num])[1]\n  apply (insert smod_int_range [where a=\"sint a\" and b=\"sint b\"])\n  apply (clarsimp simp: abs_if add1_zle_eq split: split_if_asm)\n  done\n\nlemma smod_word_alt_def:\n  \"(a :: ('a::len) word) smod b = a - (a sdiv b) * b\"\n  apply (case_tac \"a \\<noteq> - (2 ^ (len_of TYPE('a) - 1)) \\<or> b \\<noteq> -1\")\n   apply (clarsimp simp: smod_word_def sdiv_word_def smod_int_def\n             minus_word.abs_eq [symmetric] times_word.abs_eq [symmetric])\n  apply (clarsimp simp: smod_word_def smod_int_def)\n  done\n\nlemma sint_of_int_eq:\n  \"\\<lbrakk> - (2 ^ (len_of TYPE('a) - 1)) \\<le> x; x < 2 ^ (len_of TYPE('a) - 1) \\<rbrakk> \\<Longrightarrow> sint (of_int x :: ('a::len) word) = x\"\n  apply (clarsimp simp: word_of_int int_word_sint)\n  apply (subst int_mod_eq')\n    apply simp\n   apply (subst (2) power_minus_simp)\n    apply clarsimp\n   apply clarsimp\n  apply clarsimp\n  done\n\nlemmas sint32_of_int_eq = sint_of_int_eq [where 'a=32, simplified]\n\nlemma of_int_sint [simp]:\n    \"of_int (sint a) = a\"\n  apply (insert word_sint.Rep [where x=a])\n  apply (clarsimp simp: word_of_int)\n  done\n\n\nlemma ucast_of_nats [simp]:\n     \"(ucast (of_nat x :: word32) :: sword32) = (of_nat x)\"\n     \"(ucast (of_nat x :: word32) :: sword16) = (of_nat x)\"\n     \"(ucast (of_nat x :: word32) :: sword8) = (of_nat x)\"\n     \"(ucast (of_nat x :: word16) :: sword16) = (of_nat x)\"\n     \"(ucast (of_nat x :: word16) :: sword8) = (of_nat x)\"\n     \"(ucast (of_nat x :: word8) :: sword8) = (of_nat x)\"\n  apply (auto simp: ucast_of_nat is_down)\n  done\n\nlemma nth_w2p_scast [simp]:\n  \"((scast ((2::'a::len signed word) ^ n) :: 'a word) !! m)\n         \\<longleftrightarrow> ((((2::'a::len  word) ^ n) :: 'a word) !! m)\"\n  apply (subst nth_w2p)\n  apply (case_tac \"n \\<ge> len_of TYPE('a)\")\n   apply (subst power_overflow, simp)\n   apply clarsimp\n  apply (metis nth_w2p scast_def bang_conj_lt\n               len_signed nth_word_of_int word_sint.Rep_inverse)\n  done\n\nlemma scast_2_power [simp]: \"scast ((2 :: 'a::len signed word) ^ x) = ((2 :: 'a word) ^ x)\"\n  by (clarsimp simp: word_eq_iff)\n\nlemma scast_bit_test [simp]:\n    \"scast ((1 :: 'a::len signed word) << n) = (1 :: 'a word) << n\"\n  by (clarsimp simp: word_eq_iff)\n\nlemma ucast_nat_def':\n  \"of_nat (unat x) = (ucast :: ('a :: len) word \\<Rightarrow> ('b :: len) signed word) x\"\n  by (simp add: ucast_def word_of_int_nat unat_def)\n\nlemma mod_mod_power_int:\n  fixes k :: int\n  shows \"k mod 2 ^ m mod 2 ^ n = k mod 2 ^ (min m n)\"\n  by (metis bintrunc_bintrunc_min bintrunc_mod2p min.commute)\n\n(* Normalise combinations of scast and ucast. *)\n\nlemma ucast_distrib:\n  fixes M :: \"'a::len word \\<Rightarrow> 'a::len word \\<Rightarrow> 'a::len word\"\n  fixes M' :: \"'b::len word \\<Rightarrow> 'b::len word \\<Rightarrow> 'b::len word\"\n  fixes L :: \"int \\<Rightarrow> int \\<Rightarrow> int\"\n  assumes lift_M: \"\\<And>x y. uint (M x y) = L (uint x) (uint y)  mod 2 ^ len_of TYPE('a)\"\n  assumes lift_M': \"\\<And>x y. uint (M' x y) = L (uint x) (uint y)  mod 2 ^ len_of TYPE('b)\"\n  assumes distrib: \"\\<And>x y. (L (x mod (2 ^ len_of TYPE('b))) (y mod (2 ^ len_of TYPE('b)))) mod (2 ^ len_of TYPE('b))\n                               = (L x y) mod (2 ^ len_of TYPE('b))\"\n  assumes is_down: \"is_down (ucast :: 'a word \\<Rightarrow> 'b word)\"\n  shows \"ucast (M a b) = M' (ucast a) (ucast b)\"\n  apply (clarsimp simp: word_of_int ucast_def)\n  apply (subst lift_M)\n  apply (subst of_int_uint [symmetric], subst lift_M')\n  apply (subst (1 2) int_word_uint)\n  apply (subst word_of_int)\n  apply (subst word.abs_eq_iff)\n  apply (subst (1 2) bintrunc_mod2p)\n  apply (insert is_down)\n  apply (unfold is_down_def)\n  apply (clarsimp simp: target_size source_size)\n  apply (clarsimp simp: mod_mod_power_int min_def)\n  apply (rule distrib [symmetric])\n  done\n\nlemma ucast_down_add:\n    \"is_down (ucast:: 'a word \\<Rightarrow> 'b word) \\<Longrightarrow>  ucast ((a :: 'a::len word) + b) = (ucast a + ucast b :: 'b::len word)\"\n  by (rule ucast_distrib [where L=\"op +\"], (clarsimp simp: uint_word_ariths)+, presburger, simp)\n\nlemma ucast_down_minus:\n    \"is_down (ucast:: 'a word \\<Rightarrow> 'b word) \\<Longrightarrow>  ucast ((a :: 'a::len word) - b) = (ucast a - ucast b :: 'b::len word)\"\n  apply (rule ucast_distrib [where L=\"op -\"], (clarsimp simp: uint_word_ariths)+)\n  apply (metis zdiff_zmod_left zdiff_zmod_right)\n  apply simp\n  done\n\nlemma ucast_down_mult:\n    \"is_down (ucast:: 'a word \\<Rightarrow> 'b word) \\<Longrightarrow>  ucast ((a :: 'a::len word) * b) = (ucast a * ucast b :: 'b::len word)\"\n  apply (rule ucast_distrib [where L=\"op *\"], (clarsimp simp: uint_word_ariths)+)\n  apply (metis mod_mult_eq)\n  apply simp\n  done\n\nlemma scast_distrib:\n  fixes M :: \"'a::len word \\<Rightarrow> 'a::len word \\<Rightarrow> 'a::len word\"\n  fixes M' :: \"'b::len word \\<Rightarrow> 'b::len word \\<Rightarrow> 'b::len word\"\n  fixes L :: \"int \\<Rightarrow> int \\<Rightarrow> int\"\n  assumes lift_M: \"\\<And>x y. uint (M x y) = L (uint x) (uint y)  mod 2 ^ len_of TYPE('a)\"\n  assumes lift_M': \"\\<And>x y. uint (M' x y) = L (uint x) (uint y)  mod 2 ^ len_of TYPE('b)\"\n  assumes distrib: \"\\<And>x y. (L (x mod (2 ^ len_of TYPE('b))) (y mod (2 ^ len_of TYPE('b)))) mod (2 ^ len_of TYPE('b))\n                               = (L x y) mod (2 ^ len_of TYPE('b))\"\n  assumes is_down: \"is_down (scast :: 'a word \\<Rightarrow> 'b word)\"\n  shows \"scast (M a b) = M' (scast a) (scast b)\"\n  apply (subst (1 2 3) down_cast_same [symmetric])\n   apply (insert is_down)\n   apply (clarsimp simp: is_down_def target_size source_size is_down)\n  apply (rule ucast_distrib [where L=L, OF lift_M lift_M' distrib])\n  apply (insert is_down)\n  apply (clarsimp simp: is_down_def target_size source_size is_down)\n  done\n\nlemma scast_down_add:\n    \"is_down (scast:: 'a word \\<Rightarrow> 'b word) \\<Longrightarrow>  scast ((a :: 'a::len word) + b) = (scast a + scast b :: 'b::len word)\"\n  by (rule scast_distrib [where L=\"op +\"], (clarsimp simp: uint_word_ariths)+, presburger, simp)\n\nlemma scast_down_minus:\n    \"is_down (scast:: 'a word \\<Rightarrow> 'b word) \\<Longrightarrow>  scast ((a :: 'a::len word) - b) = (scast a - scast b :: 'b::len word)\"\n  apply (rule scast_distrib [where L=\"op -\"], (clarsimp simp: uint_word_ariths)+)\n  apply (metis zdiff_zmod_left zdiff_zmod_right)\n  apply simp\n  done\n\nlemma scast_down_mult:\n    \"is_down (scast:: 'a word \\<Rightarrow> 'b word) \\<Longrightarrow>  scast ((a :: 'a::len word) * b) = (scast a * scast b :: 'b::len word)\"\n  apply (rule scast_distrib [where L=\"op *\"], (clarsimp simp: uint_word_ariths)+)\n  apply (metis mod_mult_eq)\n  apply simp\n  done\n\n\n\nlemma scast_ucast_3:\n  \"\\<lbrakk> is_down (ucast :: 'a word \\<Rightarrow> 'c word); is_down (ucast :: 'b word \\<Rightarrow> 'c word) \\<rbrakk> \\<Longrightarrow>\n         (scast (ucast (a :: 'a::len word) :: 'b::len word) :: 'c::len word) = ucast a\"\n  by (metis down_cast_same ucast_def ucast_down_wi)\n\nlemma scast_ucast_4:\n  \"\\<lbrakk> is_up (ucast :: 'a word \\<Rightarrow> 'b word); is_down (ucast :: 'b word \\<Rightarrow> 'c word) \\<rbrakk> \\<Longrightarrow>\n         (scast (ucast (a :: 'a::len word) :: 'b::len word) :: 'c::len word) = ucast a\"\n  by (metis down_cast_same ucast_def ucast_down_wi)\n\nlemma scast_scast_b:\n  \"\\<lbrakk> is_up (scast :: 'a word \\<Rightarrow> 'b word) \\<rbrakk> \\<Longrightarrow>\n     (scast (scast (a :: 'a::len word) :: 'b::len word) :: 'c::len word) = scast a\"\n  by (metis scast_def sint_up_scast)\n\nlemma ucast_scast_1:\n  \"\\<lbrakk> is_down (scast :: 'a word \\<Rightarrow> 'b word); is_down (ucast :: 'b word \\<Rightarrow> 'c word) \\<rbrakk> \\<Longrightarrow>\n            (ucast (scast (a :: 'a::len word) :: 'b::len word) :: 'c::len word) = scast a\"\n  by (metis scast_def ucast_down_wi)\n\n\n\nlemma ucast_scast_4:\n  \"\\<lbrakk> is_up (scast :: 'a word \\<Rightarrow> 'b word); is_down (ucast :: 'b word \\<Rightarrow> 'c word) \\<rbrakk> \\<Longrightarrow>\n     (ucast (scast (a :: 'a::len word) :: 'b::len word) :: 'c::len word) = scast a\"\n  by (metis down_cast_same scast_def sint_up_scast)\n\nlemma ucast_ucast_a:\n  \"\\<lbrakk> is_down (ucast :: 'b word \\<Rightarrow> 'c word) \\<rbrakk> \\<Longrightarrow>\n        (ucast (ucast (a :: 'a::len word) :: 'b::len word) :: 'c::len word) = ucast a\"\n  by (metis down_cast_same ucast_def ucast_down_wi)\n\nlemma ucast_ucast_b:\n  \"\\<lbrakk> is_up (ucast :: 'a word \\<Rightarrow> 'b word) \\<rbrakk> \\<Longrightarrow>\n     (ucast (ucast (a :: 'a::len word) :: 'b::len word) :: 'c::len word) = ucast a\"\n  by (metis ucast_up_ucast)\n\nlemma scast_scast_a:\n  \"\\<lbrakk> is_down (scast :: 'b word \\<Rightarrow> 'c word) \\<rbrakk> \\<Longrightarrow>\n            (scast (scast (a :: 'a::len word) :: 'b::len word) :: 'c::len word) = scast a\"\n  apply (clarsimp simp: scast_def)\n  apply (metis down_cast_same is_up_down scast_def ucast_down_wi)\n  done\n\nlemma scast_down_wi [OF refl]:\n  \"uc = scast \\<Longrightarrow> is_down uc \\<Longrightarrow> uc (word_of_int x) = word_of_int x\"\n  by (metis down_cast_same is_up_down ucast_down_wi)\n\nlemmas cast_simps =\n  is_down is_up\n  scast_down_add scast_down_minus scast_down_mult\n  ucast_down_add ucast_down_minus ucast_down_mult\n  scast_ucast_1 scast_ucast_3 scast_ucast_4\n  ucast_scast_1 ucast_scast_3 ucast_scast_4\n  ucast_ucast_a ucast_ucast_b\n  scast_scast_a scast_scast_b\n  ucast_down_bl\n  ucast_down_wi scast_down_wi\n  ucast_of_nat scast_of_nat\n  uint_up_ucast sint_up_scast\n  up_scast_surj up_ucast_surj\n\nlemma smod_mod_positive:\n    \"\\<lbrakk> 0 \\<le> (a :: int); 0 \\<le> b \\<rbrakk> \\<Longrightarrow> a smod b = a mod b\"\n  by (clarsimp simp: smod_int_alt_def zsgn_def)\n\nlemmas signed_shift_guard_simpler_32\n    = power_strict_increasing_iff[where b=\"2 :: nat\" and y=31, simplified]\n\nlemma nat_mult_power_less_eq:\n  \"b > 0 \\<Longrightarrow> (a * b ^ n < (b :: nat) ^ m) = (a < b ^ (m - n))\"\n  using mult_less_cancel2[where m = a and k = \"b ^ n\" and n=\"b ^ (m - n)\"]\n        mult_less_cancel2[where m=\"a * b ^ (n - m)\" and k=\"b ^ m\" and n=1]\n  apply (simp only: power_add[symmetric] nat_minus_add_max)\n  apply (simp only: power_add[symmetric] nat_minus_add_max ac_simps)\n  apply (simp add: max_def split: split_if_asm)\n  done\n\nlemma signed_shift_guard_to_word:\n  \"\\<lbrakk> n < len_of TYPE ('a); n > 0 \\<rbrakk>\n    \\<Longrightarrow> (unat (x :: ('a :: len) word) * 2 ^ y < 2 ^ n)\n    = (x = 0 \\<or> x < (1 << n >> y))\"\n  apply (simp only: nat_mult_power_less_eq)\n  apply (cases \"y \\<le> n\")\n   apply (simp only: shiftl_shiftr1)\n   apply (subst less_mask_eq)\n    apply (simp add: word_less_nat_alt word_size)\n    apply (rule order_less_le_trans[rotated], rule power_increasing[where n=1])\n      apply simp\n     apply simp\n    apply simp\n   apply (simp add: nat_mult_power_less_eq word_less_nat_alt word_size)\n   apply auto[1]\n  apply (simp only: shiftl_shiftr2, simp add: unat_eq_0)\n  done\n\nlemma word32_31_less:\n  \"31 < len_of TYPE (32 signed)\" \"31 > (0 :: nat)\"\n  \"31 < len_of TYPE (32)\" \"31 > (0 :: nat)\"\n  by auto\n\nlemmas signed_shift_guard_to_word_32\n    = signed_shift_guard_to_word[OF word32_31_less(1-2)]\n    signed_shift_guard_to_word[OF word32_31_less(3-4)]\n\nlemma sint_ucast_eq_uint:\n    \"\\<lbrakk> \\<not> is_down (ucast :: ('a::len word \\<Rightarrow> 'b::len word)) \\<rbrakk>\n            \\<Longrightarrow> sint ((ucast :: ('a::len word \\<Rightarrow> 'b::len word)) x) = uint x\"\n  apply (subst sint_eq_uint)\n   apply (clarsimp simp: msb_nth nth_ucast is_down)\n   apply (metis Suc_leI Suc_pred bang_conj_lt len_gt_0)\n  apply (clarsimp simp: uint_up_ucast is_up is_down)\n  done\n\nlemma word_less_nowrapI':\n  \"(x :: 'a :: len0 word) \\<le> z - k \\<Longrightarrow> k \\<le> z \\<Longrightarrow> 0 < k \\<Longrightarrow> x < x + k\"\n  by uint_arith\n\nlemma mask_plus_1:\n  \"mask n + 1 = 2 ^ n\"\n  by (clarsimp simp: mask_def)\n\nlemma unat_inj: \"inj unat\"\n  by (metis eq_iff injI word_le_nat_alt)\n\nlemma unat_ucast_upcast:\n  \"is_up (ucast :: 'b word \\<Rightarrow> 'a word)\n      \\<Longrightarrow> unat (ucast x :: ('a::len) word) = unat (x :: ('b::len) word)\"\n  unfolding ucast_def unat_def\n  apply (subst int_word_uint)\n  apply (subst mod_pos_pos_trivial)\n    apply simp\n   apply (rule lt2p_lem)\n   apply (clarsimp simp: is_up)\n  apply simp\n  done\n\nlemma ucast_mono:\n  \"\\<lbrakk> (x :: 'b :: len word) < y; y < 2 ^ len_of TYPE('a) \\<rbrakk>\n   \\<Longrightarrow> ucast x < ((ucast y) :: ('a :: len) word)\"\n  apply (simp add: ucast_nat_def [symmetric])\n  apply (rule of_nat_mono_maybe)\n  apply (rule unat_less_helper)\n  apply (simp add: Power.of_nat_power)\n  apply (simp add: word_less_nat_alt)\n  done\n\nlemma ucast_mono_le:\n  \"\\<lbrakk>x \\<le> y; y < 2 ^ len_of TYPE('b)\\<rbrakk> \\<Longrightarrow> (ucast (x :: 'a :: len word) :: 'b :: len word) \\<le> ucast y\"\n  apply (simp add: ucast_nat_def [symmetric])\n  apply (subst of_nat_mono_maybe_le[symmetric])\n    apply (rule unat_less_helper)\n    apply (simp add: Power.of_nat_power)\n   apply (rule unat_less_helper)\n   apply (erule le_less_trans)\n   apply (simp add: Power.of_nat_power)\n  apply (simp add: word_le_nat_alt)\n  done\n\nlemma zero_sle_ucast_up:\n  \"\\<not> is_down (ucast :: 'a word \\<Rightarrow> 'b signed word) \\<Longrightarrow>\n          (0 <=s ((ucast (b::('a::len) word)) :: ('b::len) signed word))\"\n  apply (subgoal_tac \"\\<not> msb (ucast b :: 'b signed word)\")\n   apply (clarsimp simp: word_sle_msb_le)\n  apply (clarsimp simp: is_down not_le msb_nth nth_ucast)\n  apply (subst (asm) bang_conj_lt [symmetric])\n  apply clarsimp\n  apply arith\n  done\n\nlemma msb_ucast_eq:\n    \"len_of TYPE('a) = len_of TYPE('b) \\<Longrightarrow>\n         msb (ucast x :: ('a::len) word) = msb (x :: ('b::len) word)\"\n  apply (clarsimp simp: word_msb_alt)\n  apply (subst ucast_down_drop [where n=0])\n   apply (clarsimp simp: source_size_def target_size_def word_size)\n  apply clarsimp\n  done\n\nlemma msb_big:\n     \"msb (a :: ('a::len) word) = (a \\<ge> 2 ^ (len_of TYPE('a)  - Suc 0))\"\n  apply (rule iffI)\n   apply (clarsimp simp: msb_nth)\n   apply (drule bang_is_le)\n   apply simp\n  apply (rule ccontr)\n  apply (subgoal_tac \"a = a && mask (len_of TYPE('a) - Suc 0)\")\n   apply (cut_tac and_mask_less' [where w=a and n=\"len_of TYPE('a) - Suc 0\"])\n    apply (clarsimp simp: word_not_le [symmetric])\n   apply clarsimp\n  apply (rule sym, subst and_mask_eq_iff_shiftr_0)\n  apply (clarsimp simp: msb_shift)\n  done\n\nlemma zero_sle_ucast:\n  \"(0 <=s ((ucast (b::('a::len) word)) :: ('a::len) signed word))\n                = (uint b < 2 ^ (len_of (TYPE('a)) - 1))\"\n  apply (case_tac \"msb b\")\n   apply (clarsimp simp: word_sle_msb_le not_less msb_ucast_eq del: notI)\n   apply (clarsimp simp: msb_big word_le_def uint_2p_alt)\n  apply (clarsimp simp: word_sle_msb_le not_less msb_ucast_eq del: notI)\n  apply (clarsimp simp: msb_big word_le_def uint_2p_alt)\n  done\n\n\n(* to_bool / from_bool. *)\n\ndefinition\n  from_bool :: \"bool \\<Rightarrow> 'a::len word\" where\n  \"from_bool b \\<equiv> case b of True \\<Rightarrow> of_nat 1\n                         | False \\<Rightarrow> of_nat 0\"\n\nlemma from_bool_0:\n  \"(from_bool x = 0) = (\\<not> x)\"\n  by (simp add: from_bool_def split: bool.split)\n\ndefinition\n  to_bool :: \"'a::len word \\<Rightarrow> bool\" where\n  \"to_bool \\<equiv> (op \\<noteq>) 0\"\n\nlemma to_bool_and_1:\n  \"to_bool (x && 1) = (x !! 0)\"\n  apply (simp add: to_bool_def del: word_neq_0_conv)\n  apply (rule iffI)\n   apply (rule classical, erule notE, rule word_eqI)\n   apply clarsimp\n   apply (case_tac n, simp_all)[1]\n  apply (rule notI, drule word_eqD[where x=0])\n  apply simp\n  done\n\nlemma to_bool_from_bool:\n  \"to_bool (from_bool r) = r\"\n  unfolding from_bool_def to_bool_def\n  by (simp split: bool.splits)\n\nlemma from_bool_neq_0:\n  \"(from_bool b \\<noteq> 0) = b\"\n  by (simp add: from_bool_def split: bool.splits)\n\nlemma from_bool_mask_simp:\n  \"((from_bool r) :: word32) && 1 = from_bool r\"\n  unfolding from_bool_def\n  apply (clarsimp split: bool.splits)\n  done\n\nlemma scast_from_bool:\n  \"scast (from_bool P::word32) = (from_bool P::word32)\"\n  by (clarsimp simp: from_bool_def scast_id split: bool.splits)\n\nlemma from_bool_1:\n  \"(from_bool P = 1) = P\"\n  by (simp add: from_bool_def split: bool.splits)\n\nlemma ge_0_from_bool:\n  \"(0 < from_bool P) = P\"\n  by (simp add: from_bool_def split: bool.splits)\n\nlemma limited_and_from_bool:\n  \"limited_and (from_bool b) 1\"\n  by (simp add: from_bool_def limited_and_def split: bool.split)\n\nlemma to_bool_1 [simp]: \"to_bool 1\" by (simp add: to_bool_def)\nlemma to_bool_0 [simp]: \"\\<not>to_bool 0\" by (simp add: to_bool_def)\n\nlemma from_bool_eq_if:\n  \"(from_bool Q = (if P then 1 else 0)) = (P = Q)\"\n  by (simp add: case_bool_If from_bool_def split: split_if)\n\nlemma to_bool_eq_0:\n  \"(\\<not> to_bool x) = (x = 0)\"\n  by (simp add: to_bool_def)\n\nlemma to_bool_neq_0:\n  \"(to_bool x) = (x \\<noteq> 0)\"\n  by (simp add: to_bool_def)\n\nlemma from_bool_all_helper:\n  \"(\\<forall>bool. from_bool bool = val \\<longrightarrow> P bool)\n      = ((\\<exists>bool. from_bool bool = val) \\<longrightarrow> P (val \\<noteq> 0))\"\n  by (auto simp: from_bool_0)\n\nlemma word_rsplit_upt:\n  \"\\<lbrakk> size x = len_of TYPE('a :: len) * n; n \\<noteq> 0 \\<rbrakk>\n    \\<Longrightarrow> word_rsplit x = map (\\<lambda>i. ucast (x >> i * len_of TYPE ('a)) :: 'a word) (rev [0 ..< n])\"\n  apply (subgoal_tac \"length (word_rsplit x :: 'a word list) = n\")\n   apply (rule nth_equalityI, simp)\n   apply (intro allI word_eqI impI)\n   apply (simp add: test_bit_rsplit_alt word_size)\n   apply (simp add: nth_ucast nth_shiftr nth_rev field_simps)\n  apply (simp add: length_word_rsplit_exp_size)\n  apply (metis mult.commute given_quot_alt word_size word_size_gt_0)\n  done\n\nend\n", "meta": {"author": "jcaesar", "repo": "fixed-topos-header-space-analysis", "sha": "2da808ab41e5924d616ad1af15e8f50cb986c803", "save_path": "github-repos/isabelle/jcaesar-fixed-topos-header-space-analysis", "path": "github-repos/isabelle/jcaesar-fixed-topos-header-space-analysis/fixed-topos-header-space-analysis-2da808ab41e5924d616ad1af15e8f50cb986c803/thy/autocorres-0.98/lib/WordLemmaBucket.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.26375474360949813}}
{"text": "theory Typing_Lemmas\n  imports Typing Lemmas\nbegin\n\nno_notation Set.member  (\"(_/ : _)\" [51, 51] 50)\n\nlemma fun_ty_val: \"\\<lbrakk> \\<Gamma> , \\<Delta> \\<turnstile> e : \\<tau>1 \\<rightarrow> \\<tau>2 ; is_value e \\<rbrakk> \\<Longrightarrow> (\\<exists>x e'. e = (\\<lambda>x:\\<tau>1. e')) \\<or> head_ctor e\"\n  by (induction \\<Gamma> \\<Delta> e \"\\<tau>1 \\<rightarrow> \\<tau>2\" rule: Tm.induct) auto\nlemma forall_ty_val: \"\\<lbrakk> \\<Gamma> , \\<Delta> \\<turnstile> e : \\<forall>a:k. \\<sigma> ; is_value e \\<rbrakk> \\<Longrightarrow> (\\<exists>x e'. e = (\\<Lambda> x:k. e')) \\<or> head_ctor e\"\n  by (induction \\<Gamma> \\<Delta> e \"\\<forall>a:k. \\<sigma>\" rule: Tm.induct) auto\n\nlemma context_cons_valid[elim]: \"(\\<Delta>::\\<Delta>) \\<turnstile> bndr # \\<Gamma> \\<Longrightarrow> (\\<Delta> \\<turnstile> \\<Gamma> \\<Longrightarrow> P) \\<Longrightarrow> P\"\n  by (cases rule: Ctx.cases) (auto simp: context_valid(1))\n\n(* inversion rules for abstractions *)\nlemma T_Abs_Inv:\n  assumes a: \"\\<Gamma> , \\<Delta> \\<turnstile> (\\<lambda>x : \\<tau>1 . e) : \\<tau>\" and b: \"atom x \\<sharp> \\<Gamma>\"\n  obtains \\<tau>2 where \"BVar x \\<tau>1 # \\<Gamma> , \\<Delta> \\<turnstile> e : \\<tau>2\" \"\\<tau> = arrow_app \\<tau>1 \\<tau>2\"\nproof (cases rule: Tm.cases[OF a])\n  case (2 x' \\<tau>1' \\<Gamma>' \\<Delta>' e' \\<tau>2)\n  then have swap: \"(x' \\<leftrightarrow> x) \\<bullet> e' = e\" using Abs_rename_body[of x' e' x e] by auto\n  have valid: \"\\<turnstile> \\<Delta>\" using axioms_valid(3)[OF 2(5)] 2(2) by simp\n  show ?thesis\n  proof (cases \"atom x' = atom x\")\n    case True\n    then show ?thesis using 2 swap that by auto\n  next\n    case False\n    then have 1: \"atom x \\<sharp> BVar x' \\<tau>1' # \\<Gamma>'\" using b by (simp add: 2 fresh_Cons)\n    have 3: \"((x' \\<leftrightarrow> x) \\<bullet> (BVar x' \\<tau>1 # \\<Gamma>)) , \\<Delta> \\<turnstile> (x' \\<leftrightarrow> x) \\<bullet> e' : \\<tau>2\" using 2 Tm.eqvt[OF 2(5), of \"(x' \\<leftrightarrow> x)\"] by fastforce\n    have \"((x' \\<leftrightarrow> x) \\<bullet> (BVar x' \\<tau>1) # ((x' \\<leftrightarrow> x) \\<bullet> \\<Gamma>)) = BVar x \\<tau>1 # \\<Gamma>\"\n      by (metis \"1\" \"2\"(1) \"2\"(5) CtxE(2) binder.perm_simps(1) context_valid_tm flip_at_simps(1) flip_fresh_fresh fresh_Cons perm_\\<tau>_vars)\n    then show ?thesis using 1 2 3 swap that by auto\n  qed\nqed simp_all\n\nlemma T_Abs_Inv_2:\n  fixes \\<tau>::\\<tau>\n  assumes a: \"\\<Gamma> , \\<Delta> \\<turnstile> (\\<lambda>x:\\<tau>1. e) : \\<tau>\"\n  obtains x' e' \\<tau>2 where \"BVar x' \\<tau>1  # \\<Gamma> , \\<Delta> \\<turnstile> e' : \\<tau>2\" \"(\\<lambda>x:\\<tau>1. e) = (\\<lambda>x':\\<tau>1. e')\" \"atom x' \\<sharp> (x, e)\" \"\\<tau> = (\\<tau>1 \\<rightarrow> \\<tau>2)\"\nproof (cases rule: Tm.cases[OF a])\n  case (2 x' _ _ _ e' \\<tau>2)\n  then obtain c::var where \"atom c \\<sharp> (x, e, x', e', \\<Gamma>)\" using obtain_fresh by blast\n  then have c: \"atom c \\<sharp> x\" \"atom c \\<sharp> e\" \"atom c \\<sharp> x'\" \"atom c \\<sharp> e'\" \"atom c \\<sharp> \\<Gamma>\" by auto\n  obtain e2 where P: \"(x' \\<leftrightarrow> c) \\<bullet> (\\<lambda> x' : \\<tau>1 . e') = (\\<lambda> c : \\<tau>1 . e2)\" using flip_fresh_fresh by force\n  then have 1: \"(x' \\<leftrightarrow> c) \\<bullet> e' = e2\" by (simp add: Abs1_eq_iff(3))\n  have 3: \"(x' \\<leftrightarrow> c) \\<bullet> \\<Gamma> = \\<Gamma>\" by (metis 2(1,5) CtxE(2) c(5) context_valid_tm flip_def swap_fresh_fresh)\n  have 4: \"((x' \\<leftrightarrow> c) \\<bullet> BVar x' \\<tau>1) = BVar c \\<tau>1\" using P by auto\n  have valid: \"\\<turnstile> \\<Delta>\" using axioms_valid(3)[OF 2(5)] 2(2) by simp\n  have \"(x' \\<leftrightarrow> c) \\<bullet> (BVar x' \\<tau>1 # \\<Gamma> , \\<Delta> \\<turnstile> e' : \\<tau>2)\" using 2 by auto\n  then have \"((x' \\<leftrightarrow> c) \\<bullet> (BVar x' \\<tau>1 # \\<Gamma>)) , \\<Delta> \\<turnstile> (x' \\<leftrightarrow> c) \\<bullet>  e' : \\<tau>2\" using valid by auto\n  then have \"(((x' \\<leftrightarrow> c) \\<bullet> BVar x' \\<tau>1) # ((x' \\<leftrightarrow> c) \\<bullet> \\<Gamma>)) , \\<Delta> \\<turnstile> e2 : \\<tau>2\" using 1 by auto\n  then have x: \"BVar c \\<tau>1 # \\<Gamma> , \\<Delta> \\<turnstile> e2 : \\<tau>2\" using 3 4 by argo\n  have y: \"(\\<lambda> x : \\<tau>1 . e) = (\\<lambda> c : \\<tau>1 . e2)\" by (metis 1 2(3) Abs1_eq_iff(3) c(3,4) flip_commute fresh_at_base(2) term.eq_iff(5))\n  show ?thesis using that[OF x y] 2(3,4) c(1,2) by simp\nqed auto\n\nlemma T_Let_Inv:\n  assumes a: \"\\<Gamma> , \\<Delta> \\<turnstile> Let x \\<tau>1 e1 e2 : \\<tau>\" and b: \"atom x \\<sharp> \\<Gamma>\"\n  shows \"\\<Gamma> , \\<Delta> \\<turnstile> e1 : \\<tau>1 \\<and> BVar x \\<tau>1 # \\<Gamma> , \\<Delta> \\<turnstile> e2 : \\<tau>\"\nproof (cases rule: Tm.cases[OF a])\n  case (7 \\<Gamma>' \\<Delta>' e1' \\<tau>1' x' e2' \\<tau>2')\n  have swap: \"(x' \\<leftrightarrow> x) \\<bullet> e2' = e2\" using Abs_rename_body[of x' e2' x e2] 7(3) by simp\n  show ?thesis\n  proof (cases \"atom x' = atom x\")\n    case True\n    then show ?thesis using 7 swap by auto\n  next\n    case False\n    then have 1: \"atom x \\<sharp> BVar x' \\<tau>1 # \\<Gamma>'\" using b by (simp add: 7 fresh_Cons)\n    have 2: \"((x' \\<leftrightarrow> x) \\<bullet> (BVar x' \\<tau>1#\\<Gamma>)) , \\<Delta> \\<turnstile> (x' \\<leftrightarrow> x) \\<bullet> e2' : \\<tau>\" using Tm.eqvt[OF 7(6), of \"(x' \\<leftrightarrow> x)\"] 7 by auto\n    have 3: \"((x' \\<leftrightarrow> x) \\<bullet> (BVar x' \\<tau>1) # ((x' \\<leftrightarrow> x) \\<bullet> \\<Gamma>)) = BVar x \\<tau>1#\\<Gamma>\"\n      by (metis \"1\" 7(1,6) CtxE(2) binder.perm_simps(1) context_valid_tm flip_at_simps(1) flip_def fresh_Cons perm_\\<tau>_vars swap_fresh_fresh)\n    from 2 3 7 swap show ?thesis by auto\n  qed\nqed simp_all\n\nlemma T_AbsT_Inv:\n  assumes a: \"\\<Gamma> , \\<Delta> \\<turnstile> (\\<Lambda> a : k . e) : \\<tau>\" and b: \"atom a \\<sharp> \\<Gamma>\" \"atom a \\<sharp> \\<tau>\"\n  obtains \\<sigma> where \"BTyVar a k # \\<Gamma> , \\<Delta> \\<turnstile> e : \\<sigma>\" \"\\<tau> = (\\<forall> a:k. \\<sigma>)\"\nproof (cases rule: Tm.cases[OF a])\n  case (4 a' k' \\<Gamma>' \\<Delta>' e' \\<sigma>')\n  then have fresh: \"atom a' \\<sharp> \\<Gamma>\" by (cases rule: Ctx.cases[OF context_valid(2)[OF 4(5)]]) auto\n  have swap: \"(a' \\<leftrightarrow> a) \\<bullet> e' = e\" using Abs_rename_body[of a' e' a e] 4(3) by simp\n  have valid: \"\\<turnstile> \\<Delta>\" using axioms_valid(3)[OF 4(5)] 4(2) by simp\n  show ?thesis\n  proof (cases \"atom a = atom a'\")\n    case True\n    then show ?thesis by (metis 4 Abs1_eq_iff(3) atom_eq_iff term.eq_iff(6) that)\n  next\n    case False\n    then have 1: \"atom a \\<sharp> BTyVar a' k # \\<Gamma>\" using b by (simp add: 4 fresh_Cons)\n    have 2: \"((a' \\<leftrightarrow> a) \\<bullet> (BTyVar a' k # \\<Gamma>)), \\<Delta> \\<turnstile> (a' \\<leftrightarrow> a) \\<bullet> e' : (a' \\<leftrightarrow> a) \\<bullet> \\<sigma>'\" using Tm.eqvt[OF 4(5), of \"(a' \\<leftrightarrow> a)\"] valid 4 by auto\n    have \"((a' \\<leftrightarrow> a) \\<bullet> (BTyVar a' k # \\<Gamma>)) = ((a' \\<leftrightarrow> a) \\<bullet> BTyVar a' k) # \\<Gamma>\" using 1 fresh flip_fresh_fresh b(1) by simp\n    then have \"((a' \\<leftrightarrow> a) \\<bullet> (BTyVar a' k # \\<Gamma>)) = BTyVar a k # \\<Gamma>\" by (simp add: flip_fresh_fresh)\n    then have \"BTyVar a k # \\<Gamma> , \\<Delta> \\<turnstile> e : (a' \\<leftrightarrow> a) \\<bullet> \\<sigma>'\" using 2 swap by argo\n    then show ?thesis by (metis \"4\"(3,4) Abs1_eq_iff(3) False \\<tau>.eq_iff(5) \\<tau>.fresh(5) b(2) empty_iff flip_commute insert_iff list.set(1,2) term.eq_iff(6) that)\n  qed\nqed simp_all\n\nlemma Ty_Forall_Inv:\n  assumes a: \"\\<Gamma> , \\<Delta> \\<turnstile>\\<^sub>t\\<^sub>y (\\<forall>a:k. \\<sigma>) : \\<tau>\" and b: \"atom a \\<sharp> \\<Gamma>\"\n  shows \"BTyVar a k # \\<Gamma> , \\<Delta> \\<turnstile>\\<^sub>t\\<^sub>y \\<sigma> : \\<star> \\<and> \\<tau> = \\<star>\"\nproof (cases rule: Ty.cases[OF a])\n  case (5 a' k' \\<Gamma>' \\<Delta>' \\<sigma>')\n  then have 1: \"(BTyVar a' k # \\<Gamma>) , \\<Delta> \\<turnstile>\\<^sub>t\\<^sub>y \\<sigma>' : \\<star>\" by simp\n  have valid: \"\\<turnstile> \\<Delta>\" by (rule axioms_valid(2)[OF 1])\n  have \"(a' \\<leftrightarrow> a) \\<bullet> \\<sigma>' = \\<sigma>\" using Abs_rename_body[of a' \\<sigma>' a \\<sigma>] 5(3) by auto\n  then have 2: \"((a' \\<leftrightarrow> a) \\<bullet> (BTyVar a' k # \\<Gamma>)) , \\<Delta> \\<turnstile>\\<^sub>t\\<^sub>y \\<sigma> : \\<star>\" using Ty.eqvt[OF 1, of \"(a' \\<leftrightarrow> a)\"] valid by auto\n  have 3: \"((a' \\<leftrightarrow> a) \\<bullet> (BTyVar a' k # \\<Gamma>)) = BTyVar a k # ((a' \\<leftrightarrow> a) \\<bullet> \\<Gamma>)\" using Cons_eqvt flip_fresh_fresh by force\n  have 4: \"(a' \\<leftrightarrow> a) \\<bullet> \\<Gamma> = \\<Gamma>\" by (metis 5(1,5) CtxE(1) b context_valid_ty flip_def swap_fresh_fresh)\n  show ?thesis using 2 3 4 5(4) by argo\nqed simp_all\n\nlemma Ty_Forall_Inv_2:\n  assumes a: \"\\<Gamma> , \\<Delta> \\<turnstile>\\<^sub>t\\<^sub>y \\<forall> a : k . \\<sigma> : k2\"\n  obtains a' \\<sigma>' where \"(\\<forall> a:k. \\<sigma>) = (\\<forall> a':k. \\<sigma>')\" \"BTyVar a' k # \\<Gamma> , \\<Delta> \\<turnstile>\\<^sub>t\\<^sub>y \\<sigma>' : \\<star>\" \"atom a' \\<sharp> (a, \\<sigma>)\" \"k2 = \\<star>\"\nproof (cases rule: Ty.cases[OF a])\n  case (5 a2 _ _ _ \\<sigma>2)\n  then obtain c::tyvar where \"atom c \\<sharp> (a, \\<sigma>, a2, \\<sigma>2, \\<Gamma>)\" using obtain_fresh by blast\n  then have c: \"atom c \\<sharp> a\" \"atom c \\<sharp> \\<sigma>\" \"atom c \\<sharp> a2\" \"atom c \\<sharp> \\<sigma>2\" \"atom c \\<sharp> \\<Gamma>\" by auto\n  obtain \\<sigma>' where P: \"(a2 \\<leftrightarrow> c) \\<bullet> (\\<forall> a2:k. \\<sigma>2) = (\\<forall> c:k. \\<sigma>')\" using flip_fresh_fresh by force\n  then have 1: \"(a2 \\<leftrightarrow> c) \\<bullet> \\<sigma>2 = \\<sigma>'\" by (simp add: Abs1_eq_iff(3))\n  have 2: \"(a2 \\<leftrightarrow> c) \\<bullet> \\<Gamma> = \\<Gamma>\" by (metis 5(1,5) CtxE(1) c(5) context_valid_ty flip_def swap_fresh_fresh)\n  have 3: \"((a2 \\<leftrightarrow> c) \\<bullet> BTyVar a2 k) = BTyVar c k\" using P by auto\n  have valid: \"\\<turnstile> \\<Delta>\" using axioms_valid(2)[OF 5(5)] 5(2) by simp\n  have \"(a2 \\<leftrightarrow> c) \\<bullet> (BTyVar a2 k # \\<Gamma> , \\<Delta> \\<turnstile>\\<^sub>t\\<^sub>y \\<sigma>2 : \\<star>)\" using 5 by auto\n  then have \"((a2 \\<leftrightarrow> c) \\<bullet> (BTyVar a2 k # \\<Gamma>)) , \\<Delta> \\<turnstile>\\<^sub>t\\<^sub>y (a2 \\<leftrightarrow> c) \\<bullet> \\<sigma>2 : \\<star>\" using valid by auto\n  then have \"(((a2 \\<leftrightarrow> c) \\<bullet> BTyVar a2 k) # ((a2 \\<leftrightarrow> c) \\<bullet> \\<Gamma>)) , \\<Delta> \\<turnstile>\\<^sub>t\\<^sub>y \\<sigma>' : \\<star>\" using 1 by auto\n  then have x: \"BTyVar c k # \\<Gamma> , \\<Delta> \\<turnstile>\\<^sub>t\\<^sub>y \\<sigma>' : \\<star>\" using 2 3 by argo\n  have y: \"(a2 \\<leftrightarrow> c) \\<bullet> (\\<forall> a2:k. \\<sigma>2) = (\\<forall> a2:k. \\<sigma>2)\" by (metis \\<tau>.fresh(5) c(4) flip_def insert_iff list.set(2) no_tyvars_in_kinds swap_fresh_fresh)\n  show ?thesis using that[OF _ x _ 5(4)] c(1,2) by (metis 5(3) P \\<tau>.eq_iff(5) fresh_Pair y)\nqed simp_all\n\nlemma axiom_isin_same_kind: \"\\<lbrakk> AxData T k1 \\<in> set (\\<Delta>' @ AxData T k2 # \\<Delta>) ; \\<turnstile> (\\<Delta>' @ AxData T k2 # \\<Delta>) \\<rbrakk> \\<Longrightarrow> k1 = k2\"\nproof (induction \\<Delta>')\n  case Nil\n  then have \"\\<nexists>k. AxData T k \\<in> set \\<Delta>\" by auto\n  then show ?case using Nil.prems(1) by auto\nnext\n  case (Cons a \\<Delta>')\n  then show ?case using axioms_valid(2)\n  proof (cases a rule: axiom.exhaust)\n    case (AxData T' k3)\n    then have \"\\<nexists>k. AxData T' k \\<in> set (\\<Delta>' @ AxData T k2 # \\<Delta>)\" using Cons(3) by fastforce\n    then have \"T' \\<noteq> T\" by auto\n    then show ?thesis using Cons AxData by auto\n  qed fastforce\nqed\n\nlemma axiom_isin_same_type: \"\\<lbrakk> AxCtor D \\<tau>1 \\<in> set (\\<Delta>' @ AxCtor D \\<tau>2 # \\<Delta>) ; \\<turnstile> (\\<Delta>' @ AxCtor D \\<tau>2 # \\<Delta>) \\<rbrakk> \\<Longrightarrow> \\<tau>1 = \\<tau>2\"\nproof (induction \\<Delta>')\n  case Nil\n  then have \"\\<nexists>t. AxCtor D t \\<in> set \\<Delta>\" by auto\n  then show ?case using Nil(1) by auto\nnext\n  case (Cons a \\<Delta>')\n  then show ?case\n  proof (cases a rule: axiom.exhaust)\n    case (AxCtor D' \\<tau>')\n    then have \"\\<nexists>t. AxCtor D' t \\<in> set (\\<Delta>' @ AxCtor D \\<tau>2 # \\<Delta>)\" using Cons(3) by fastforce\n    then have \"D' \\<noteq> D\" by auto\n    then show ?thesis using AxCtor Cons axioms_valid_aux(2) set_ConsD by auto\n  qed auto\nqed\nlemmas axiom_isin_same = axiom_isin_same_kind axiom_isin_same_type\n\nlemma axiom_isin_split: \"\\<lbrakk> b \\<in> set \\<Delta> ; \\<turnstile> \\<Delta> \\<rbrakk> \\<Longrightarrow> \\<exists>\\<Delta>1 \\<Delta>2. \\<Delta> = \\<Delta>1 @ b # \\<Delta>2\"\nproof (induction \\<Delta>)\n  case (Cons a \\<Delta>)\n  then show ?case\n  proof (cases \"a = b\")\n    case True\n    then show ?thesis by blast\n  next\n    case False\n    then show ?thesis by (meson Cons.prems(1) split_list)\n  qed\nqed simp\n\nlemma axioms_split_valid: \"\\<turnstile> \\<Delta>' @ \\<Delta> \\<Longrightarrow> \\<turnstile> \\<Delta>\"\nproof (induction \\<Delta>')\n  case (Cons a \\<Delta>')\n  then show ?case using axioms_valid(2) by (cases a rule: axiom.exhaust) auto\nqed simp\n\nlemma isin_subset:\n  fixes \\<Gamma>::\"\\<Gamma>\"\n  assumes \"\\<Delta> \\<turnstile> \\<Gamma>' @ \\<Gamma>\"\n  shows \"bndr \\<in> \\<Gamma> \\<longrightarrow> bndr \\<in> (\\<Gamma>' @ \\<Gamma>)\"\nproof\n  assume \"bndr \\<in> \\<Gamma>\"\n  then show \"bndr \\<in> (\\<Gamma>' @ \\<Gamma>)\"\n  using assms proof (induction \\<Gamma>' arbitrary: \\<Gamma>)\n    case (Cons b \\<Gamma>2)\n    have 1: \"\\<Delta> \\<turnstile> \\<Gamma>2 @ \\<Gamma>\" using Cons(3) by auto\n    have 2: \"bndr \\<in> (\\<Gamma>2 @ \\<Gamma>)\" by (rule Cons(1)[OF Cons(2) 1])\n    show ?case\n    proof (cases b rule: binder.exhaust)\n      case (BVar x \\<tau>)\n      then have \"atom x \\<sharp> (\\<Gamma>2 @ \\<Gamma>)\" using Cons by auto\n      then show ?thesis using 2 BVar fresh_not_isin_var by (cases bndr rule: binder.exhaust) auto\n    next\n      case (BTyVar a k)\n      then have \"atom a \\<sharp> (\\<Gamma>2 @ \\<Gamma>)\" using Cons by auto\n      then show ?thesis using 2 BTyVar fresh_not_isin_tyvar by (cases bndr rule: binder.exhaust) auto\n    qed\n  qed auto\nqed\n\nlemma isin_superset_tyvar: \"\\<lbrakk> BTyVar a k \\<in> (\\<Gamma>' @ BVar x \\<tau> # \\<Gamma>) ; \\<Delta> \\<turnstile> \\<Gamma>' @ BVar x \\<tau> # \\<Gamma> \\<rbrakk> \\<Longrightarrow> BTyVar a k \\<in> (\\<Gamma>' @ \\<Gamma>)\"\nproof (induction \\<Gamma>')\n  case (Cons bndr \\<Gamma>')\n  then show ?case by (cases bndr rule: binder.exhaust) auto\nqed auto\n\nlemma isin_superset_var: \"\\<lbrakk> BVar x \\<tau> \\<in> (\\<Gamma>' @ BVar y \\<tau>2 # \\<Gamma>) ; \\<Delta> \\<turnstile> \\<Gamma>' @ BVar y \\<tau>2 # \\<Gamma> ; x \\<noteq> y \\<rbrakk> \\<Longrightarrow> BVar x \\<tau> \\<in> (\\<Gamma>' @ \\<Gamma>)\"\nproof (induction \\<Gamma>')\n  case (Cons bndr \\<Gamma>')\n  then show ?case by (cases bndr rule: binder.exhaust) auto\nqed auto\nlemmas isin_superset = isin_superset_tyvar isin_superset_var\n\nlemma isin_same_kind: \"\\<lbrakk> BTyVar a k1 \\<in> (\\<Gamma>' @ BTyVar a k2 # \\<Gamma>) ; \\<Delta> \\<turnstile> \\<Gamma>' @ BTyVar a k2 # \\<Gamma> \\<rbrakk> \\<Longrightarrow> k1 = k2\"\nproof (induction \\<Gamma>')\n  case (Cons bndr \\<Gamma>')\n  then show ?case by (cases rule: Ctx.cases[OF Cons(3)]) (auto split: if_splits simp: fresh_Cons fresh_append fresh_at_base(2))\nqed auto\n\nlemma isin_same_type: \"\\<lbrakk> BVar x \\<tau> \\<in> (\\<Gamma>' @ BVar x \\<tau>2 # \\<Gamma>) ; \\<Delta> \\<turnstile> \\<Gamma>' @ BVar x \\<tau>2 # \\<Gamma> \\<rbrakk> \\<Longrightarrow> \\<tau> = \\<tau>2\"\nproof (induction \\<Gamma>')\n  case (Cons a \\<Gamma>')\n  then show ?case by (cases rule: Ctx.cases[OF Cons(3)]) (auto split: if_splits simp: fresh_Cons fresh_append fresh_at_base)\nqed auto\nlemmas isin_same = isin_same_kind isin_same_type\n\nlemma isin_subst_tyvar: \"\\<lbrakk> BTyVar a k \\<in> (\\<Gamma>' @ BTyVar b k2 # \\<Gamma>) ; \\<Delta> \\<turnstile> \\<Gamma>' @ BTyVar b k2 # \\<Gamma> ; a \\<noteq> b \\<rbrakk> \\<Longrightarrow> BTyVar a k \\<in> (\\<Gamma>'[\\<sigma>/b] @ \\<Gamma>)\"\nproof (induction \\<Gamma>')\n  case (Cons bndr \\<Gamma>')\n  then show ?case\n  proof (cases rule: Ctx.cases[OF Cons(3)])\n    case (2 \\<Gamma>2 c k3)\n    then have \"BTyVar a k = bndr \\<or> BTyVar a k \\<in> (\\<Gamma>' @ BTyVar b k2 # \\<Gamma>)\" by (metis Cons.prems(1) Cons_eq_append_conv isin.simps(5) list.inject)\n    then show ?thesis\n    proof\n      assume a: \"BTyVar a k = bndr\"\n      then show ?thesis using 2 Cons by auto\n    next\n      assume \"BTyVar a k \\<in> (\\<Gamma>' @ BTyVar b k2 # \\<Gamma>)\"\n      then show ?thesis using 2 Cons fresh_not_isin_tyvar by auto\n    qed\n  next\n    case (3 \\<Gamma> \\<tau> x)\n    then show ?thesis using Cons by auto\n  qed simp\nqed simp\n\nlemma context_split_valid: \"(\\<Delta>::\\<Delta>) \\<turnstile> (\\<Gamma>' @ \\<Gamma>) \\<Longrightarrow> \\<Delta> \\<turnstile> \\<Gamma>\"\n  by (induction \\<Gamma>') (auto simp: Ctx_Empty)\n\nlemma isin_split: \"\\<lbrakk> b \\<in> \\<Gamma> ; \\<Delta> \\<turnstile> \\<Gamma> \\<rbrakk> \\<Longrightarrow> \\<exists>\\<Gamma>1 \\<Gamma>2. \\<Gamma> = \\<Gamma>1 @ b # \\<Gamma>2\"\nproof (induction \\<Gamma>)\n  case (Cons bndr \\<Gamma>)\n  then show ?case\n  proof (cases \"bndr = b\")\n    case False\n    then have \"b \\<in> \\<Gamma>\"\n    proof (cases bndr rule: binder.exhaust)\n      case (BVar x \\<tau>)\n      then show ?thesis using False Cons by (cases b rule: binder.exhaust) auto\n    next\n      case (BTyVar a k)\n      then show ?thesis using False Cons by (cases b rule: binder.exhaust) auto\n    qed\n    then show ?thesis by (metis Cons.IH Cons.prems(2) Cons_eq_appendI context_cons_valid)\n  qed blast\nqed auto\n\nlemma axioms_regularity: \"\\<turnstile> \\<Delta>' @ AxCtor D \\<tau> # \\<Delta> \\<Longrightarrow> [] , \\<Delta> \\<turnstile>\\<^sub>t\\<^sub>y \\<tau> : \\<star>\"\n  using Ax_Ctor axioms_split_valid by (induction \\<Delta>) blast+\n\nlemma context_regularity: \"\\<Delta> \\<turnstile> \\<Gamma>' @ BVar x \\<tau> # \\<Gamma> \\<Longrightarrow> \\<Gamma> , \\<Delta> \\<turnstile>\\<^sub>t\\<^sub>y \\<tau> : \\<star>\"\n  using Ctx_Var context_split_valid by (induction \\<Gamma>) blast+\n\nlemma Tm_eqvt_tyvar:\n  assumes \"BTyVar a k # \\<Gamma> , \\<Delta> \\<turnstile> e : \\<tau>\" \"atom c \\<sharp> \\<Gamma>\"\n  shows \"BTyVar c k # \\<Gamma> , \\<Delta> \\<turnstile> (a \\<leftrightarrow> c) \\<bullet> e : (a \\<leftrightarrow> c) \\<bullet> \\<tau>\"\nproof -\n  have \"\\<turnstile> \\<Delta>\" by (rule axioms_valid(3)[OF assms(1)])\n  then have 1: \"(a \\<leftrightarrow> c) \\<bullet> \\<Delta> = \\<Delta>\" by auto\n  have \"\\<Delta> \\<turnstile> BTyVar a k # \\<Gamma>\" by (rule context_valid(2)[OF assms(1)])\n  then have 2: \"(a \\<leftrightarrow> c) \\<bullet> \\<Gamma> = \\<Gamma>\" using assms(2) flip_fresh_fresh by blast\n  have 3: \"(a \\<leftrightarrow> c) \\<bullet> BTyVar a k = BTyVar c k\" using flip_fresh_fresh by force\n\n  have \"(a \\<leftrightarrow> c) \\<bullet> (BTyVar a k # \\<Gamma>) , (a \\<leftrightarrow> c) \\<bullet> \\<Delta> \\<turnstile> (a \\<leftrightarrow> c) \\<bullet> e : (a \\<leftrightarrow> c) \\<bullet> \\<tau>\" by (rule Tm.eqvt[OF assms(1), of \"(a \\<leftrightarrow> c)\"])\n  then show ?thesis using 1 2 3 by auto\nqed\n\nend\n", "meta": {"author": "jvanbruegge", "repo": "isabelle-lambda-calculus", "sha": "41fba58ed18fcb494b6b7abb6c8641a63002a1d5", "save_path": "github-repos/isabelle/jvanbruegge-isabelle-lambda-calculus", "path": "github-repos/isabelle/jvanbruegge-isabelle-lambda-calculus/isabelle-lambda-calculus-41fba58ed18fcb494b6b7abb6c8641a63002a1d5/Typing_Lemmas.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.523420348936324, "lm_q1q2_score": 0.26375474360949813}}
{"text": "theory CFGExit_wf imports CFGExit CFG_wf begin\n\nsubsection \\<open>New well-formedness lemmas using \\<open>(_Exit_)\\<close>\\<close>\n\nlocale CFGExit_wf = CFGExit sourcenode targetnode kind valid_edge Entry \n    get_proc get_return_edges procs Main Exit +\n  CFG_wf sourcenode targetnode kind valid_edge Entry \n    get_proc get_return_edges procs Main Def Use ParamDefs ParamUses\n  for sourcenode :: \"'edge \\<Rightarrow> 'node\" and targetnode :: \"'edge \\<Rightarrow> 'node\"\n  and kind :: \"'edge \\<Rightarrow> ('var,'val,'ret,'pname) edge_kind\" \n  and valid_edge :: \"'edge \\<Rightarrow> bool\"\n  and Entry :: \"'node\" (\"'('_Entry'_')\")  and get_proc :: \"'node \\<Rightarrow> 'pname\"\n  and get_return_edges :: \"'edge \\<Rightarrow> 'edge set\"\n  and procs :: \"('pname \\<times> 'var list \\<times> 'var list) list\" and Main :: \"'pname\"\n  and Exit::\"'node\"  (\"'('_Exit'_')\") \n  and Def :: \"'node \\<Rightarrow> 'var set\" and Use :: \"'node \\<Rightarrow> 'var set\"\n  and ParamDefs :: \"'node \\<Rightarrow> 'var list\" \n  and ParamUses :: \"'node \\<Rightarrow> 'var set list\" +\n  assumes Exit_empty:\"Def (_Exit_) = {} \\<and> Use (_Exit_) = {}\"\n\nbegin\n\nlemma Exit_Use_empty [dest!]: \"V \\<in> Use (_Exit_) \\<Longrightarrow> False\"\nby(simp add:Exit_empty)\n\nlemma Exit_Def_empty [dest!]: \"V \\<in> Def (_Exit_) \\<Longrightarrow> False\"\nby(simp add:Exit_empty)\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/HRB-Slicing/StaticInter/CFGExit_wf.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631698328917, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.26371455255145854}}
{"text": "(*\n * Copyright 2017, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory ArchArraysMemInstance\nimports \"../ArraysMemInstance\"\nbegin\n\n(* Showing arrays are in mem_type requires maximum sizes for objects,\n   and maximum counts for elements *)\nclass array_outer_max_size = mem_type +\n  assumes array_outer_max_size_ax: \"size_of TYPE('a::c_type) < 2 ^ 19\"\n\nclass array_max_count = finite +\n  assumes array_max_count_ax: \"CARD ('a) <= 2 ^ 13\"\n\ninstance array :: (array_outer_max_size, array_max_count) mem_type\napply intro_classes\napply simp\napply (subgoal_tac \"addr_card = 2 ^ (addr_bitsize - 19) * 2 ^ 19\")\n  apply (erule ssubst)\n  apply (rule less_le_trans[where y = \"card (UNIV::'b set) * 2 ^ 19\"])\n    apply (rule mult_less_mono2)\n      apply (rule array_outer_max_size_ax)\n    apply simp\n  apply (rule mult_le_mono1)\n    apply (rule le_trans[where j = \"2 ^ 13\"])\n      apply (rule array_max_count_ax)\n    apply simp\n  apply simp\napply (simp add: addr_card)\ndone\n\nclass array_inner_max_size = array_outer_max_size +\n  assumes array_inner_max_size_ax: \"size_of TYPE('a::c_type) < 2 ^ 6\"\n\ninstance array :: (array_inner_max_size, array_max_count) array_outer_max_size\napply intro_classes\napply simp\n  apply (rule order_less_le_trans)\n   apply (rule mult_le_less_imp_less)\n    apply (rule array_max_count_ax)\n   apply (rule array_inner_max_size_ax)\n  apply simp\n   apply simp\n  apply simp\n  done\n\ninstance word :: (len8) array_outer_max_size\napply intro_classes\napply(simp add: size_of_def)\napply(subgoal_tac \"len_of TYPE('a) \\<le> 128\")\n apply simp\napply(rule len8_width)\ndone\n\ninstance word :: (len8) array_inner_max_size\napply intro_classes\napply(simp add: size_of_def)\napply(subgoal_tac \"len_of TYPE('a) \\<le> 128\")\n apply simp\napply(rule len8_width)\ndone\n\ninstance ptr :: (c_type) array_outer_max_size\napply intro_classes\napply (simp add: size_of_def)\ndone\n\ninstance ptr :: (c_type) array_inner_max_size\napply intro_classes\napply (simp add: size_of_def)\ndone\n\nclass lt12 = finite +\n  assumes lt12_ax: \"CARD ('a) < 2 ^ 12\"\nclass lt11 = lt12 +\n  assumes lt11_ax: \"CARD ('a) < 2 ^ 11\"\nclass lt10 = lt11 +\n  assumes lt10_ax: \"CARD ('a) < 2 ^ 10\"\nclass lt9 = lt10 +\n  assumes lt9_ax: \"CARD ('a) < 2 ^ 9\"\nclass lt8 = lt9 +\n  assumes lt8_ax: \"CARD ('a) < 2 ^ 8\"\nclass lt7 = lt8 +\n  assumes lt7_ax: \"CARD ('a) < 2 ^ 7\"\nclass lt6 = lt7 +\n  assumes lt6_ax: \"CARD ('a) < 2 ^ 6\"\nclass lt5 = lt6 +\n  assumes lt5_ax: \"CARD ('a) < 2 ^ 5\"\nclass lt4 = lt5 +\n  assumes lt4_ax: \"CARD ('a) < 2 ^ 4\"\nclass lt3 = lt4 +\n  assumes lt3_ax: \"CARD ('a) < 2 ^ 3\"\nclass lt2 = lt3 +\n  assumes lt2_ax: \"CARD ('a) < 2 ^ 2\"\nclass lt1 = lt2 +\n  assumes lt1_ax: \"CARD ('a) < 2 ^ 1\"\n\ninstance bit0 :: (lt12) array_max_count\n  using lt12_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt12) array_max_count\n  using lt12_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt11) lt12\n  using lt11_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt11) lt12\n  using lt11_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt10) lt11\n  using lt10_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt10) lt11\n  using lt10_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt9) lt10\n  using lt9_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt9) lt10\n  using lt9_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt8) lt9\n  using lt8_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt8) lt9\n  using lt8_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt7) lt8\n  using lt7_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt7) lt8\n  using lt7_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt6) lt7\n  using lt6_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt6) lt7\n  using lt6_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt5) lt6\n  using lt5_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt5) lt6\n  using lt5_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt4) lt5\n  using lt4_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt4) lt5\n  using lt4_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt3) lt4\n  using lt3_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt3) lt4\n  using lt3_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt2) lt3\n  using lt2_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt2) lt3\n  using lt2_ax[where 'a='a] by intro_classes simp\n\ninstance bit0 :: (lt1) lt2\n  using lt1_ax[where 'a='a] by intro_classes simp\n\ninstance bit1 :: (lt1) lt2\n  using lt1_ax[where 'a='a] by intro_classes simp\n\ninstance num1 :: lt1\n  by (intro_classes, simp_all)\n\n(* don't understand why this also seems to be necessary *)\ninstance num1 :: array_max_count\n  by (intro_classes, simp)\n\n(* introduce hackish handling of 8192 type by making a copy of the type\n   under a constructor, and then manually showing that it is an instance of\n   array_max_count *)\ndatatype array_max_count_ty = array_max_count_ty \"8192\"\n\n(* ML c-parser code also needs to know at which array size to use this type *)\nML \\<open>\n  structure ArchArrayMaxCount = struct\n    val array_max_count = 8192\n  end\n\\<close>\n\nlemma univ_array_max_count_ty:\n  \"(UNIV::array_max_count_ty set) = image array_max_count_ty (UNIV::8192 set)\"\n  apply (simp add: set_eq_iff image_iff)\n  apply (rule_tac allI)\n  apply (rule_tac array_max_count_ty.induct)\n  apply simp\n  done\n\ninstance \"array_max_count_ty\" :: finite\n  apply intro_classes\n  apply (simp add: univ_array_max_count_ty)\n  done\n\nlemma card_array_max_count_ty[simp]: \"CARD(array_max_count_ty) = CARD(8192)\"\n  apply (simp add: univ_array_max_count_ty card_image inj_on_def)\n  done\n\ninstance \"array_max_count_ty\" :: array_max_count\n  by intro_classes simp\n\nend\n", "meta": {"author": "CompSoftVer", "repo": "CSim2", "sha": "b09a4d77ea089168b1805db5204ac151df2b9eff", "save_path": "github-repos/isabelle/CompSoftVer-CSim2", "path": "github-repos/isabelle/CompSoftVer-CSim2/CSim2-b09a4d77ea089168b1805db5204ac151df2b9eff/CParser/tools/c-parser/umm_heap/ARM_HYP/ArchArraysMemInstance.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6076631698328916, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.2637145525514585}}
{"text": "(*<*) \n\n(* Author: Kyndylan Nienhuis *)\n\ntheory CheriInstantiation\n\nimports \n  \"ExecutionStep\"\n  \"ValidState\"\n  \"AddressTranslation\"\n  \"Execute\"\n  \"LoadData\"\n  \"StoreData\"\n  \"RestrictCap\"\n  \"LoadCap\"\n  \"StoreCap\"\n  \"SealCap\"\n  \"UnsealCap\"\n  \"Exception\"\n  \"InvokeCap\"\n  \"MemoryInvariant\"\n  \"CapabilityInvariant\"\n  \"SystemRegisterAccess\"\nbegin\n\n(*>*)\n\ntheorem CheriInstantiation:\n  shows \"CanBeSimulated SemanticsCheriMips\"\nunfolding CanBeSimulated_def\nproof clarify\n  fix s lbl s'\n  assume as: \"(lbl, s') \\<in> SemanticsCheriMips s\"\n  show \"(lbl, s') \\<in> AbstractSemantics s\"\n    unfolding AbstractSemantics_def\n    using AddressTranslationInstantiation[OF as]\n    using ExceptionInstantiation[OF as]\n    using ExecuteInstantiation[OF as]\n    using CapabilityInvariantInstantiation[OF as]\n    using InvokeCapInstantiation[OF as]\n    using LoadCapInstantiation[OF as]\n    using LoadDataInstantiation[OF as]\n    using MemoryInvariantInstantiation[OF as]\n    using RestrictCapInstantiation[OF as]\n    using SealCapInstantiation[OF as]\n    using StoreCapInstantiation[OF as]\n    using StoreLocalCapInstantiation[OF as]\n    using StoreDataInstantiation[OF as]\n    using UnsealCapInstantiation[OF as]\n    using SystemRegisterInstantiation[OF as]\n    using ValidStateInstantiation[OF as]\n    by auto\nqed\n\n(*<*)\nend\n(*>*)", "meta": {"author": "CTSRD-CHERI", "repo": "l3-cheri-mips-proofs", "sha": "239c37ad1587caf261501478bbcd1293b9ecb7b7", "save_path": "github-repos/isabelle/CTSRD-CHERI-l3-cheri-mips-proofs", "path": "github-repos/isabelle/CTSRD-CHERI-l3-cheri-mips-proofs/l3-cheri-mips-proofs-239c37ad1587caf261501478bbcd1293b9ecb7b7/instantiation/CheriInstantiation.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.712232184238947, "lm_q2_score": 0.3702253856469203, "lm_q1q2_score": 0.26368643508001255}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\n(*\n * A theoretical framework for reasoning about non-interference\n * of monadic programs.\n *)\n\ntheory EquivValid\nimports Corres_UL\nbegin\n\nsection\\<open>State equivalence validity\\<close>\n\ntext\\<open>\n\nA generalised information flow property.\n\nOften, we read in the entire state, but then only examine part of it.\nThe following property may be used to split up binds whose first part\ndoes this.\n\n@{term \"I\"} is the state relation that holds invariantly.\n\n@{term \"A\"} (also) holds between initial states.\n\n@{term \"B\"} (also) holds between final states.\n\n@{term \"P\"} holds in the initial state for @{term \"f\"}.\n\n@{term \"P'\"} holds in the initial state for @{term \"f'\"}.\n\n\\<close>\n\ndefinition\n  equiv_valid_2 :: \"('s \\<Rightarrow> 's \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> 's \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> 's \\<Rightarrow> bool) \\<Rightarrow> ('b \\<Rightarrow> 'c \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> bool) \\<Rightarrow> ('s,'b) nondet_monad \\<Rightarrow> ('s,'c) nondet_monad \\<Rightarrow> bool\"\nwhere\n  \"equiv_valid_2 I A B R P P' f f' \\<equiv> \\<forall>s t.\n       P s \\<and> P' t \\<and> I s t \\<and> A s t\n     \\<longrightarrow> (\\<forall>(rva, s') \\<in> fst (f s). \\<forall>(rvb, t') \\<in> fst (f' t).\n          R rva rvb \\<and> I s' t' \\<and> B s' t')\"\n\nlemma equiv_valid_2_bind_general:\n  assumes r2: \"\\<And> rv rv'. R' rv rv' \\<Longrightarrow> equiv_valid_2 D B C R (Q rv) (Q' rv') (g rv) (g' rv')\"\n  assumes r1: \"equiv_valid_2 D A B R' P P' f f'\"\n  assumes hoare: \"\\<lbrace> S \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  assumes hoare': \"\\<lbrace> S' \\<rbrace> f' \\<lbrace> Q' \\<rbrace>\"\n  shows \"equiv_valid_2 D A C R (\\<lambda> s. P s \\<and> S s) (\\<lambda> s. P' s \\<and> S' s) (f >>= g) (f' >>= g')\"\n  using assms\n  unfolding bind_def equiv_valid_2_def valid_def\n  apply fastforce\n  done\n\n(* almost all of the time, the second relation doesn't change *)\nlemma equiv_valid_2_bind:\n  assumes r2: \"\\<And> rv rv'. R' rv rv' \\<Longrightarrow> equiv_valid_2 D A A R (Q rv) (Q' rv') (g rv) (g' rv')\"\n  assumes r1: \"equiv_valid_2 D A A R' P P' f f'\"\n  assumes hoare: \"\\<lbrace> S \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  assumes hoare': \"\\<lbrace> S' \\<rbrace> f' \\<lbrace> Q' \\<rbrace>\"\n  shows \"equiv_valid_2 D A A R (\\<lambda> s. P s \\<and> S s) (\\<lambda> s. P' s \\<and> S' s) (f >>= g) (f' >>= g')\"\n  using assms by (blast intro: equiv_valid_2_bind_general)\n\nlemma equiv_valid_2_guard_imp:\n  assumes reads_res: \"equiv_valid_2 D A B R Q Q' f f'\"\n  assumes guard_imp: \"\\<And> s. P s \\<Longrightarrow> Q s\"\n  assumes guard_imp': \"\\<And> s. P' s \\<Longrightarrow> Q' s\"\n  shows \"equiv_valid_2 D A B R P P' f f'\"\n  using assms\n  by (fastforce simp: equiv_valid_2_def)\n\nlemma equiv_valid_2_bind_pre:\n  assumes r2: \"\\<And> rv rv'. R' rv rv' \\<Longrightarrow> equiv_valid_2 D A A R (Q rv) (Q' rv') (g rv) (g' rv')\"\n  assumes r1: \"equiv_valid_2 D A A R' P P' f f'\"\n  assumes hoare: \"\\<lbrace> S \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  assumes hoare': \"\\<lbrace> S' \\<rbrace> f' \\<lbrace> Q' \\<rbrace>\"\n  assumes guard_imp: \"\\<And> s. T s \\<Longrightarrow> P s \\<and> S s\"\n  assumes guard_imp': \"\\<And> s. T' s \\<Longrightarrow> P' s \\<and> S' s\"\n  shows \"equiv_valid_2 D A A R T T' (f >>= g) (f' >>= g')\"\n  using assms by (blast intro: equiv_valid_2_bind[THEN equiv_valid_2_guard_imp])\n\nlemma return_ev2:\n  assumes rel: \"\\<And> s t. \\<lbrakk>P s; P' t; I s t; A s t\\<rbrakk> \\<Longrightarrow> R a b\"\n  shows \"equiv_valid_2 I A A R P P' (return a) (return b)\"\n  by(auto simp: equiv_valid_2_def return_def rel)\n\nlemma equiv_valid_2_liftE:\n  \"equiv_valid_2 D A B R P P' f f' \\<Longrightarrow>\n   equiv_valid_2 D A B (E \\<oplus> R) P P' (liftE f) (liftE f')\"\n  apply(unfold liftE_def)\n  apply(rule equiv_valid_2_guard_imp)\n  apply(rule_tac Q=\"\\<top>\\<top>\" and Q'=\"\\<top>\\<top>\" and R'=R in equiv_valid_2_bind_general)\n       apply(fastforce intro: return_ev2)\n      apply assumption\n     apply(rule wp_post_taut)+\n   by(simp_all)\n\nlemma equiv_valid_2_liftE_bindE_general:\n  assumes r2: \"\\<And> rv rv'. R' rv rv' \\<Longrightarrow> equiv_valid_2 D B C R (Q rv) (Q' rv') (g rv) (g' rv')\"\n  assumes hoare: \"\\<lbrace> S \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  assumes hoare':  \"\\<lbrace> S' \\<rbrace> f' \\<lbrace> Q' \\<rbrace>\"\n  assumes r1: \"equiv_valid_2 D A B R' P P' f f'\"\n  shows \"equiv_valid_2 D A C R (P and S) (P' and S') (liftE f >>=E g) (liftE f' >>=E g')\"\n  apply(unfold bindE_def)\n  apply(rule equiv_valid_2_guard_imp)\n  apply(rule_tac Q=\"\\<lambda> rv. K (\\<forall> v. rv \\<noteq> Inl v) and (\\<lambda> s. \\<forall> v. rv = Inr v \\<longrightarrow> Q v s)\" and Q'=\"\\<lambda> rv. K (\\<forall> v. rv \\<noteq> Inl v) and (\\<lambda> s. \\<forall> v. rv = Inr v \\<longrightarrow> Q' v s)\" in equiv_valid_2_bind_general)\n       prefer 2\n       apply(rule_tac E=\"dc\" in equiv_valid_2_liftE)\n       apply(rule r1)\n      apply(clarsimp simp: lift_def split: sum.split)\n      apply(insert r2, fastforce simp: equiv_valid_2_def)[1]\n     apply(simp add: liftE_def, wp, fastforce intro!: hoare_strengthen_post[OF hoare])\n    apply(simp add: liftE_def, wp, fastforce intro!: hoare_strengthen_post[OF hoare'])\n   by(auto)\n\nlemma equiv_valid_2_liftE_bindE:\n  assumes r2: \"\\<And> rv rv'. R' rv rv' \\<Longrightarrow> equiv_valid_2 D A A R (Q rv) (Q' rv') (g rv) (g' rv')\"\n  assumes hoare: \"\\<lbrace> S \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  assumes hoare':  \"\\<lbrace> S' \\<rbrace> f' \\<lbrace> Q' \\<rbrace>\"\n  assumes r1: \"equiv_valid_2 D A A R' P P' f f'\"\n  shows \"equiv_valid_2 D A A R (P and S) (P' and S') (liftE f >>=E g) (liftE f' >>=E g')\"\n  using assms by(blast intro: equiv_valid_2_liftE_bindE_general)\n\nlemma equiv_valid_2_rvrel_imp:\n  \"\\<lbrakk>equiv_valid_2 I A A R P P' f f'; \\<And> s t. R s t \\<Longrightarrow> R' s t\\<rbrakk> \\<Longrightarrow>\n   equiv_valid_2 I A A R' P P' f f'\"\n  apply(fastforce simp: equiv_valid_2_def)\n  done\n\nsubsection\\<open>Specialised fixed-state state equivalence validity\\<close>\n\ntext\\<open>\n\nFor resolve_address_bits and rec_del: talk about a fixed initial\nstate. Note we only do this for one of the computations; the other\nstate can be constrained by how it is related to this one by @{term\n\"I\"} and so forth.\n\nAlso captures the typical case where the relation between the return\nvalues is equality and the required preconditions are identical.\n\nwp can cope with this.\n\n\\<close>\n\ndefinition\n  spec_equiv_valid :: \"'s \\<Rightarrow> ('s \\<Rightarrow> 's \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> 's \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> 's \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> bool) \\<Rightarrow> ('s,'b) nondet_monad \\<Rightarrow> bool\"\nwhere\n  \"spec_equiv_valid st I A B P f \\<equiv> equiv_valid_2 I A B (=) (P and ((=) st)) P f f\"\n\nabbreviation spec_equiv_valid_inv where\n  \"spec_equiv_valid_inv st I A P f \\<equiv> spec_equiv_valid st I A A P f\"\n\nsubsection\\<open>Specialised state equivalence validity\\<close>\n\ntext\\<open>\n\nMost of the time we deal with the streamlined version.\n\nwp can cope with this too.\n\n\\<close>\n\ndefinition\n  equiv_valid :: \"('s \\<Rightarrow> 's \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> 's \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> 's \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> bool) \\<Rightarrow> ('s,'b) nondet_monad \\<Rightarrow> bool\"\nwhere\n  \"equiv_valid I A B P f \\<equiv> \\<forall>st. spec_equiv_valid st I A B P f\"\n\nlemma equiv_valid_def2:\n  \"equiv_valid I A B P f = equiv_valid_2 I A B (=) P P f f\"\n  by (simp add: equiv_valid_def spec_equiv_valid_def equiv_valid_2_def)\n\nabbreviation equiv_valid_rv where\n  \"equiv_valid_rv I A B R P f \\<equiv> equiv_valid_2 I A B R P P f f\"\n\n(* this is probably way more general than we need for all but a few special cases *)\nlemma bind_ev_general:\n  assumes reads_res_2: \"\\<And>rv. equiv_valid I B C (Q rv) (g rv)\"\n  assumes reads_res_1: \"equiv_valid I A B P' f\"\n  assumes hoare: \"\\<lbrace> P'' \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  shows \"equiv_valid I A C (\\<lambda>s. P' s \\<and> P'' s) (f >>= g)\"\n  unfolding equiv_valid_def2\n  apply (rule equiv_valid_2_bind_general[where R'=\"(=)\"])\n     apply (auto intro: reads_res_1[unfolded equiv_valid_def2] reads_res_2[unfolded equiv_valid_def2])[2]\n   apply (rule hoare)\n  apply (rule hoare)\n  done\n\nlemma bind_ev:\n  assumes reads_res_2: \"\\<And>rv. equiv_valid I A A (Q rv) (g rv)\"\n  assumes reads_res_1: \"equiv_valid I A A P' f\"\n  assumes hoare: \"\\<lbrace> P'' \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  shows \"equiv_valid I A A (\\<lambda>s. P' s \\<and> P'' s) (f >>= g)\"\n  using assms by (blast intro: bind_ev_general)\n\nlemma equiv_valid_weaken_pre:\n  \"\\<lbrakk> equiv_valid I A' B P f; \\<forall>st t. I st t \\<and> A st t \\<longrightarrow> A' st t \\<rbrakk>\n     \\<Longrightarrow> equiv_valid I A B P f\"\n  by (fastforce simp: equiv_valid_def spec_equiv_valid_def equiv_valid_2_def)\n\nlemma equiv_valid_guard_imp:\n  assumes reads_res: \"equiv_valid I A B Q f\"\n  assumes guard_imp: \"\\<And> s. P s \\<Longrightarrow> Q s\"\n  shows \"equiv_valid I A B P f\"\n  using assms by (fastforce simp: equiv_valid_def2 equiv_valid_2_def)\n\nlemmas bind_ev_pre = bind_ev[THEN equiv_valid_guard_imp]\n\nlemma gen_asm_ev':\n  assumes \"Q \\<Longrightarrow> equiv_valid D A B P f\"\n  shows \"equiv_valid D A B (P and K Q) f\"\n  using assms by (fastforce simp: equiv_valid_def2 equiv_valid_2_def)\n\ndeclare K_def [simp del]\n\nlemmas gen_asm_ev =\n  gen_asm_ev'[where P=\"\\<top>\", simplified]\n  gen_asm_ev'\n  gen_asm_ev'[simplified K_def, where P=\"\\<top>\", simplified]\n  gen_asm_ev'[simplified K_def]\n\ndeclare K_def [simp]\n\ntext \\<open>\n  This is a further streamlined version that we expect to get the most from\n  automating, and for the most part, we shouldn't need to deal with the\n  extra generality of the properties above.\n\\<close>\nabbreviation equiv_valid_inv where\n  \"equiv_valid_inv I A P f \\<equiv> equiv_valid I A A P f\"\n\nabbreviation equiv_valid_rv_inv where\n  \"equiv_valid_rv_inv I A R P f \\<equiv> equiv_valid_rv I A A R P f\"\n\nlemma get_evrv:\n  \"equiv_valid_rv_inv I A (I and A) \\<top> get\"\n  by(auto simp: equiv_valid_2_def get_def)\n\nlemma equiv_valid_rv_bind_general:\n  assumes ev1:\n  \"equiv_valid_rv I A B W P f\"\n  assumes ev2:\n  \"\\<And> rv rv'. W rv rv' \\<Longrightarrow> equiv_valid_2 I B C R (Q rv) (Q rv') (g rv) (g rv')\"\n  assumes hoare:\n  \"\\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  shows \"equiv_valid_rv I A C R P (f >>= g)\"\n  apply(rule equiv_valid_2_guard_imp)\n  apply(rule equiv_valid_2_bind_general[OF ev2])\n       apply(assumption)\n      apply(rule ev1)\n     apply(rule hoare)\n    apply(rule hoare)\n   apply(simp_all)\n  done\n\nlemma equiv_valid_rv_bind:\n  assumes ev1:\n  \"equiv_valid_rv_inv I A W P f\"\n  assumes ev2:\n  \"\\<And> rv rv'. W rv rv' \\<Longrightarrow> equiv_valid_2 I A A R (Q rv) (Q rv') (g rv) (g rv')\"\n  assumes hoare:\n  \"\\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  shows \"equiv_valid_rv_inv I A R P (f >>= g)\"\n  using assms by(blast intro: equiv_valid_rv_bind_general)\n\nlemma modify_ev2:\n  assumes \"\\<And> s t. \\<lbrakk>I s t; A s t; P s; P' t\\<rbrakk> \\<Longrightarrow> R () () \\<and> I (f s) (f' t) \\<and> B (f s) (f' t)\"\n  shows\n  \"equiv_valid_2 I A B R P P' (modify f) (modify f')\"\n  apply(clarsimp simp: equiv_valid_2_def in_monad)\n  using assms by auto\n\nlemma modify_ev:\n  \"equiv_valid I A B\n     (\\<lambda> s. \\<forall> s t. I s t \\<and> A s t \\<longrightarrow> I (f s) (f t) \\<and> B (f s) (f t))\n     (modify f)\"\n  apply(clarsimp simp:equiv_valid_def2)\n  apply(rule modify_ev2)\n  by auto\n\nlemma modify_ev':\n  \"equiv_valid I A B\n     (\\<lambda> s. \\<forall> t. I s t \\<and> A s t \\<longrightarrow> I (f s) (f t) \\<and> B (f s) (f t))\n     (modify f)\"\n  apply(clarsimp simp:equiv_valid_def2)\n  apply(rule modify_ev2)\n  by auto\n\nlemma modify_ev'':\n  assumes \"\\<And> s t. \\<lbrakk>I s t; A s t; P s; P t\\<rbrakk> \\<Longrightarrow> I (f s) (f t) \\<and> B (f s) (f t)\"\n  shows \"equiv_valid I A B P (modify f)\"\n  apply(clarsimp simp:equiv_valid_def2)\n  apply(rule modify_ev2)\n  using assms by auto\n\n\nlemma put_ev2:\n  assumes \"\\<And> s t. \\<lbrakk>I s t; A s t; P s; P' t\\<rbrakk> \\<Longrightarrow> R () () \\<and> I x x' \\<and> B x x'\"\n  shows\n  \"equiv_valid_2 I A B R P P' (put x) (put x')\"\n  apply(clarsimp simp: equiv_valid_2_def in_monad)\n  using assms by auto\n\n\nlemma get_bind_ev2:\n  assumes \"\\<And> rv rv'. \\<lbrakk>I rv rv'; A rv rv'\\<rbrakk> \\<Longrightarrow> equiv_valid_2 I A B R (P and ((=) rv)) (P' and ((=) rv')) (f rv) (f' rv')\"\n  shows \"equiv_valid_2 I A B R P P' (get >>= f) (get >>= f')\"\n  apply(rule equiv_valid_2_guard_imp)\n  apply(rule_tac R'=\"I and A\" in equiv_valid_2_bind_general)\n       apply(rule assms, simp+)\n      apply(rule get_evrv)\n     apply(wp get_sp)+\n   by(auto)\n\n\nlemma return_ev_pre:\n  \"equiv_valid_inv I A P (return x)\"\n  apply (simp add: equiv_valid_def2 return_ev2)\n  done\n\nlemmas return_ev = return_ev_pre[where P=\\<top>]\n\nlemma fail_ev2_l:\n  \"equiv_valid_2 I A B R P P' fail f'\"\n  by(simp add: equiv_valid_2_def fail_def)\n\nlemma fail_ev2_r:\n  \"equiv_valid_2 I A B R P P' f fail\"\n  by(simp add: equiv_valid_2_def fail_def)\n\nlemma fail_ev_pre:\n  \"equiv_valid I A B P fail\"\n  apply (simp add: equiv_valid_def2 fail_ev2_l)\n  done\n\nlemmas fail_ev = fail_ev_pre[where P=\\<top>]\n\nlemma assert_ev2:\n  \"R () () \\<Longrightarrow> equiv_valid_2 I A A R P P' (assert a) (assert b)\"\n  apply(simp add: assert_def fail_ev2_l fail_ev2_r)\n  apply(blast intro: return_ev2)\n  done\n\nlemma liftE_ev:\n  \"equiv_valid I A B P f \\<Longrightarrow> equiv_valid I A B P (liftE f)\"\n  unfolding liftE_def\n  apply (rule bind_ev_general[THEN equiv_valid_guard_imp, OF return_ev _ wp_post_taut])\n  apply fastforce+ (* schematic instantiation *)\n  done\n\nlemma if_ev:\n  assumes \"b \\<Longrightarrow> equiv_valid I A B P f\"\n  assumes \"\\<not> b \\<Longrightarrow> equiv_valid I A B Q g\"\n  shows \"equiv_valid I A B (\\<lambda>s. (b \\<longrightarrow> P s) \\<and> (\\<not>b \\<longrightarrow> Q s)) (if b then f else g)\"\n  apply (clarsimp split: if_split)\n  using assms by blast\n\nlemmas if_ev_pre = equiv_valid_guard_imp[OF if_ev]\n\nlemma assert_ev_pre:\n  \"equiv_valid_inv I A P (assert b)\"\n  apply(simp add: equiv_valid_def2 assert_ev2)\n  done\n\nlemmas assert_ev = assert_ev_pre[where P=\\<top>]\n\nlemma assert_opt_ev:\n  \"equiv_valid_inv I A \\<top> (assert_opt v)\"\n  apply (simp add: assert_opt_def return_ev fail_ev\n            split: option.split)\n  done\n\nlemma assert_opt_ev2:\n  assumes \"\\<And> a a'. \\<lbrakk>v = Some a; v' = Some a'\\<rbrakk> \\<Longrightarrow> R a a'\"\n  shows \"equiv_valid_2 I A A R \\<top> \\<top> (assert_opt v) (assert_opt v')\"\n  apply (simp add: assert_opt_def return_ev fail_ev2_l fail_ev2_r\n            split: option.split)\n  apply(intro allI impI)\n  apply(rule return_ev2)\n  apply(rule assms, assumption+)\n  done\n\nlemma select_f_ev:\n  \"equiv_valid_inv I A (K (det f)) (select_f (f x))\"\n  apply (rule gen_asm_ev)\n  apply (simp add: select_f_def equiv_valid_def2 equiv_valid_2_def det_set_iff)\n  done\n\nlemma gets_evrv:\n  \"equiv_valid_rv_inv I A R (K (\\<forall>s t. I s t \\<and> A s t \\<longrightarrow> R (f s) (f t))) (gets f)\"\n  apply (auto simp: equiv_valid_2_def in_monad)\n  done\n\nlemma gets_evrv':\n  \"equiv_valid_rv_inv I A R (\\<lambda>s. (\\<forall>t. I s t \\<and> A s t \\<longrightarrow> R (f s) (f t))) (gets f)\"\n  apply (auto simp: equiv_valid_2_def in_monad)\n  done\n\nlemma gets_evrv'':\n  \"\\<forall>s t. I s t \\<and> A s t \\<and> P s \\<and> P t \\<longrightarrow> R (f s) (f t) \\<Longrightarrow> equiv_valid_rv_inv I A R P (gets f)\"\n  apply (auto simp: equiv_valid_2_def in_monad)\n  done\n\nlemma equiv_valid_rv_guard_imp:\n  \"\\<lbrakk>equiv_valid_rv I A B R P f; \\<And> s. Q s \\<Longrightarrow> P s\\<rbrakk> \\<Longrightarrow>\n   equiv_valid_rv I A B R Q f\"\n  apply(simp add: equiv_valid_2_def)\n  apply fast\n  done\n\nlemma gets_ev:\n  shows \"equiv_valid_inv I A (\\<lambda> s. \\<forall> s t. I s t \\<and> A s t \\<longrightarrow> f s = f t) (gets f)\"\n  apply (simp add: equiv_valid_def2)\n  apply (auto intro: equiv_valid_rv_guard_imp[OF gets_evrv])\n  done\n\nlemma gets_ev':\n  shows \"equiv_valid_inv I A (\\<lambda> s. \\<forall> t. I s t \\<and> A s t \\<longrightarrow> f s = f t) (gets f)\"\n  apply (simp add: equiv_valid_def2)\n  apply (auto intro: equiv_valid_rv_guard_imp[OF gets_evrv'])\n  done\n\nlemma gets_ev'':\n  \"\\<forall>s t. I s t \\<and> A s t \\<and> P s \\<and> P t \\<longrightarrow> f s = f t \\<Longrightarrow> equiv_valid_inv I A P (gets f)\"\n  apply (simp add: equiv_valid_def2)\n  apply (auto intro: equiv_valid_rv_guard_imp[OF gets_evrv''])\n  done\n\nlemma gets_the_evrv:\n  \"equiv_valid_rv_inv I A R (K (\\<forall>s t. I s t \\<and> A s t \\<longrightarrow> R (the (f s)) (the (f t)))) (gets_the f)\"\n  unfolding gets_the_def\n  apply (rule equiv_valid_rv_bind)\n    apply(rule equiv_valid_rv_guard_imp[OF gets_evrv])\n    apply simp\n   apply(rule assert_opt_ev2)\n   apply simp\n  apply wp\n  done\n\nlemma gets_the_ev:\n  \"equiv_valid_inv I A (K (\\<forall>s t. I s t \\<and> A s t \\<longrightarrow> f s = f t)) (gets_the f)\"\n  unfolding equiv_valid_def2\n  apply(rule equiv_valid_rv_guard_imp[OF gets_the_evrv])\n  by simp\n\nlemma throwError_ev_pre:\n  \"equiv_valid_inv I A P (throwError e)\"\n  by (auto simp: throwError_def return_ev_pre)\n\nlemmas throwError_ev = throwError_ev_pre[where P=\\<top>]\n\nlemma returnOk_ev_pre:\n  \"equiv_valid_inv I A P (returnOk v)\"\n  by (auto simp: returnOk_def return_ev_pre)\n\nlemmas returnOk_ev = returnOk_ev_pre[where P=\\<top>]\n\n(* this seems restrictive, to have the same beginning and ending state relation,\n   however, one suspects that bindE is used usually only in code that doesn't\n   modify the state, so is probably OK.. We'll see *)\nlemma bindE_ev:\n  assumes reads_res_2: \"\\<And> rv. equiv_valid_inv I A (Q rv) (g rv)\"\n  assumes reads_res_1: \"equiv_valid_inv I A P' f\"\n  assumes hoare: \"\\<lbrace> P'' \\<rbrace> f \\<lbrace> Q \\<rbrace>,-\"\n  shows \"equiv_valid_inv I A (\\<lambda>s. P' s \\<and> P'' s) (f >>=E g)\"\n  unfolding bindE_def\n  apply (rule bind_ev)\n    prefer 3\n    apply(rule hoare[unfolded validE_R_def validE_def])\n   apply(simp split: sum.split add: lift_def throwError_ev)\n   apply(blast intro!: reads_res_2)\n  apply(rule reads_res_1)\n  done\n\nlemmas bindE_ev_pre = bindE_ev[THEN equiv_valid_guard_imp]\n\n(* Of course, when we know that progress is always made, we can do better *)\nlemma liftE_bindE_ev_general:\n  assumes r2: \"\\<And> val. equiv_valid I B C (Q val) (g val)\"\n  assumes r1: \"equiv_valid I A B P f\"\n  assumes hoare: \"\\<lbrace> R \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  shows \"equiv_valid I A C (\\<lambda> s. P s \\<and> R s) (liftE f >>=E g)\"\n  apply(simp add: bindE_def)\n  apply(rule_tac Q=\"\\<lambda> rv. K (\\<forall> v. rv \\<noteq> Inl v) and (\\<lambda> s. \\<forall> v. rv = Inr v \\<longrightarrow> Q v s)\" in bind_ev_general)\n    prefer 2\n    apply(rule liftE_ev)\n    apply(rule r1)\n   apply(insert r2, fastforce simp: lift_def split: sum.split simp: equiv_valid_def2 equiv_valid_2_def)[1]\n  apply(insert hoare, fastforce simp: valid_def liftE_def return_def bind_def)\n  done\n\nlemma liftE_bindE_ev:\n  assumes r2: \"\\<And> val. equiv_valid_inv I A (Q val) (g val)\"\n  assumes r1: \"equiv_valid_inv I A P f\"\n  assumes hoare: \"\\<lbrace> R \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  shows \"equiv_valid_inv I A (\\<lambda> s. P s \\<and> R s) (liftE f >>=E g)\"\n  using assms by (blast intro: liftE_bindE_ev_general)\n\nlemmas liftE_bindE_ev_pre = liftE_bindE_ev[THEN equiv_valid_guard_imp]\n\nlemma liftM_ev:\n  assumes reads_res: \"equiv_valid I A B P g\"\n  shows \"equiv_valid I A B P (liftM f g)\"\n  apply (simp add: liftM_def)\n  apply (rule bind_ev_general[THEN equiv_valid_guard_imp, OF return_ev reads_res wp_post_taut])\n  apply simp\n  done\n\nlemma liftME_ev:\n  assumes reads_res: \"equiv_valid_inv I A P g\"\n  shows \"equiv_valid_inv I A P (liftME f g)\"\n  apply(simp add: liftME_def)\n  apply (rule bindE_ev_pre[OF returnOk_ev reads_res])\n  apply (rule hoare_True_E_R)\n  apply fast\n  done\n\nlemma whenE_ev:\n  assumes a: \"b \\<Longrightarrow> equiv_valid_inv I A P m\"\n  shows \"equiv_valid_inv I A (\\<lambda>s. b \\<longrightarrow> P s) (whenE b m)\"\n  unfolding whenE_def by (auto intro: a returnOk_ev_pre)\n\nlemma whenE_throwError_bindE_ev:\n  assumes \"\\<And> rv. \\<not> b \\<Longrightarrow> equiv_valid_inv I A P (g rv)\"\n  shows \"equiv_valid_inv I A P (whenE b (throwError e) >>=E g)\"\n  apply (rule_tac Q=\"\\<lambda> rv. P and (\\<lambda> s. \\<not> b)\" in bindE_ev_pre)\n     apply (rule gen_asm_ev)\n     apply (blast intro: assms)\n    apply (rule whenE_ev)\n    apply (rule throwError_ev)\n   apply (wp whenE_throwError_wp)\n  apply simp\n  done\n\n(* FIXME: trivially generalised *)\nlemma K_bind_ev:\n  \"equiv_valid I A B P f \\<Longrightarrow> equiv_valid I A B P (K_bind f x)\"\n  by simp\n\nsubsection\\<open>wp setup\\<close>\n\nlemmas splits_ev[wp_split] =\n  bind_ev_pre bindE_ev_pre\n  bind_ev bindE_ev\n  if_ev_pre\n  if_ev\n\nlemmas wp_ev[wp] =\n  return_ev_pre\n  return_ev\n  liftE_ev\n  fail_ev_pre\n  fail_ev\n  assert_opt_ev\n  assert_ev\n  gets_ev\n  gets_the_ev\n  returnOk_ev_pre\n  returnOk_ev\n  throwError_ev_pre\n  throwError_ev\n  liftM_ev\n  liftME_ev\n  whenE_ev\n  K_bind_ev\n\nsubsection\\<open>crunch setup\\<close>\n\nlemmas pre_ev =\n  hoare_pre\n  equiv_valid_guard_imp\n\nsubsection\\<open>Tom instantiates wpc\\<close>\n\nlemma wpc_helper_equiv_valid:\n  \"equiv_valid D A B Q f \\<Longrightarrow> wpc_helper (P, P') (Q, Q') (equiv_valid D A B P f)\"\n  using equiv_valid_guard_imp\n  apply (simp add: wpc_helper_def)\n  apply (blast)\n  done\n\nwpc_setup \"\\<lambda>m. equiv_valid D A B Q m\" wpc_helper_equiv_valid\n\nsubsection\\<open>More hoare-like rules\\<close>\n\nlemma mapM_ev_pre:\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A I (m x)\"\n  assumes invariant: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> \\<lbrace> I \\<rbrace> m x \\<lbrace> \\<lambda>_. I \\<rbrace>\"\n  assumes inv_established: \"\\<And> s. P s \\<Longrightarrow> I s\"\n  shows \"equiv_valid_inv D A P (mapM m lst)\"\n  using assms\n  apply(atomize)\n  apply(rule_tac Q=I in equiv_valid_guard_imp)\n  apply(induct lst)\n    apply(simp add: mapM_Nil return_ev_pre)\n   apply(subst mapM_Cons)\n   apply(rule bind_ev_pre[where P''=\"I\"])\n    apply(rule bind_ev[OF return_ev])\n    apply fastforce\n    apply (rule wp_post_taut)\n    apply fastforce+\n  done\n\nlemma mapM_x_ev_pre:\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A I (m x)\"\n  assumes invariant: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> \\<lbrace> I \\<rbrace> m x \\<lbrace> \\<lambda>_. I \\<rbrace>\"\n  assumes inv_established: \"\\<And> s. P s \\<Longrightarrow> I s\"\n  shows \"equiv_valid_inv D A P (mapM_x m lst)\"\n  apply(subst mapM_x_mapM)\n  apply(rule bind_ev_pre[OF return_ev mapM_ev_pre])\n  apply (blast intro: reads_res invariant inv_established wp_post_taut)+\n  done\n\nlemma mapM_ev:\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A I (m x)\"\n  assumes invariant: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> \\<lbrace> I \\<rbrace> m x \\<lbrace> \\<lambda>_. I \\<rbrace>\"\n  shows \"equiv_valid_inv D A I (mapM m lst)\"\n  using assms by (auto intro: mapM_ev_pre)\n\nlemma mapM_x_ev:\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A I (m x)\"\n  assumes invariant: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> \\<lbrace> I \\<rbrace> m x \\<lbrace> \\<lambda>_. I \\<rbrace>\"\n  shows \"equiv_valid_inv D A I (mapM_x m lst)\"\n  using assms by (auto intro: mapM_x_ev_pre)\n\n(* MOVE -- proof clagged from mapM_x_mapM *)\nlemma mapME_x_mapME:\n  \"mapME_x f l = mapME f l >>=E (\\<lambda> y. returnOk ())\"\n  apply (simp add: mapME_x_def sequenceE_x_def mapME_def sequenceE_def)\n  apply (induct l, simp_all add: Let_def bindE_assoc)\n  done\n\nlemma mapME_ev_pre:\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A I (m x)\"\n  assumes invariant: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> \\<lbrace> I \\<rbrace> m x \\<lbrace> \\<lambda>_. I \\<rbrace>,-\"\n  assumes inv_established: \"\\<And> s. P s \\<Longrightarrow> I s\"\n  shows \"equiv_valid_inv D A P (mapME m lst)\"\n  using assms\n  apply(atomize)\n  apply(rule_tac Q=I in equiv_valid_guard_imp)\n  apply(induct lst)\n    apply(simp add: mapME_Nil returnOk_ev_pre)\n   apply(subst mapME_Cons)\n   apply wp\n   apply fastforce\n   apply (rule hoare_True_E_R[where P=\"\\<top>\"])\n   apply fastforce+\n  done\n\nlemma mapME_ev:\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv I A P (m x)\"\n  assumes invariant: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> \\<lbrace> P \\<rbrace> m x \\<lbrace> \\<lambda>_. P \\<rbrace>, -\"\n  shows \"equiv_valid_inv I A P (mapME m lst)\"\n  using assms by (auto intro: mapME_ev_pre)\n\nlemma mapME_x_ev_pre:\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A I (m x)\"\n  assumes invariant: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> \\<lbrace> I \\<rbrace> m x \\<lbrace> \\<lambda>_. I \\<rbrace>,-\"\n  assumes inv_established: \"\\<And> s. P s \\<Longrightarrow> I s\"\n  shows \"equiv_valid_inv D A P (mapME_x m lst)\"\n  unfolding mapME_x_mapME\n  apply (wp assms mapME_ev_pre | simp)+\n  done\n\nlemma mapME_x_ev:\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A I (m x)\"\n  assumes invariant: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> \\<lbrace> I \\<rbrace> m x \\<lbrace> \\<lambda>_. I \\<rbrace>, -\"\n  shows \"equiv_valid_inv D A I (mapME_x m lst)\"\n  using assms by (auto intro: mapME_x_ev_pre)\n\nlemma mapM_ev':\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A (K (P x)) (m x)\"\n  shows \"equiv_valid_inv D A (K (\\<forall>x\\<in>set lst. P x)) (mapM m lst)\"\n  apply(rule mapM_ev)\n  apply(rule equiv_valid_guard_imp[OF reads_res], simp+, wp)\n  done\n\nlemma mapM_x_ev':\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A (K (P x)) (m x)\"\n  shows \"equiv_valid_inv D A (K (\\<forall>x\\<in>set lst. P x)) (mapM_x m lst)\"\n  apply(rule mapM_x_ev)\n  apply(rule equiv_valid_guard_imp[OF reads_res], simp+, wp)\n  done\n\nlemma mapME_ev':\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A (K (P x)) (m x)\"\n  shows \"equiv_valid_inv D A (K (\\<forall>x\\<in>set lst. P x)) (mapME m lst)\"\n  apply(rule mapME_ev)\n  apply(rule equiv_valid_guard_imp[OF reads_res], simp+, wp)\n  done\n\nlemma mapME_x_ev':\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A (K (P x)) (m x)\"\n  shows \"equiv_valid_inv D A (K (\\<forall>x\\<in>set lst. P x)) (mapME_x m lst)\"\n  apply(rule mapME_x_ev)\n  apply(rule equiv_valid_guard_imp[OF reads_res], simp+, wp)\n  done\n\nsubsection\\<open>Rules for the specialised validity\\<close>\n\nlemma use_spec_ev:\n  \"(\\<And>st. spec_equiv_valid st I A B P f) \\<Longrightarrow> equiv_valid I A B P f\"\n  by (simp add: equiv_valid_def)\n\nlemma drop_spec_ev:\n  \"equiv_valid I A B P f \\<Longrightarrow> spec_equiv_valid st I A B P f\"\n  by (simp add: equiv_valid_def)\n\nlemma spec_equiv_valid_guard_imp:\n  assumes reads_res: \"spec_equiv_valid_inv s' I A P' f\"\n  assumes guard_imp: \"\\<And> s. P s \\<Longrightarrow> P' s\"\n  shows \"spec_equiv_valid_inv s' I A P f\"\n  using assms\n  by (fastforce simp: spec_equiv_valid_def equiv_valid_2_def)\n\nlemma bind_spec_ev:\n  assumes reads_res_2: \"\\<And> rv s''. (rv, s'') \\<in> fst (f s') \\<Longrightarrow> spec_equiv_valid_inv s'' I A (Q rv) (g rv)\"\n  assumes reads_res_1: \"spec_equiv_valid_inv s' I A P' f\"\n  assumes hoare: \"\\<lbrace>P''\\<rbrace> f \\<lbrace>Q\\<rbrace>\"\n  shows \"spec_equiv_valid_inv s' I A (\\<lambda>s. P' s \\<and> P'' s) (f >>= g)\"\n  using reads_res_1\n  apply (clarsimp simp: spec_equiv_valid_def equiv_valid_2_def valid_def bind_def split_def)\n  apply (rename_tac t a b aa ba ab bb ac bc)\n  apply (erule_tac x=t in allE)\n  apply clarsimp\n  apply (erule_tac x=\"(a, b)\" in ballE)\n   apply (erule_tac x=\"(ab, bb)\" in ballE)\n    apply clarsimp\n    apply (cut_tac reads_res_2)\n     prefer 2\n     apply assumption\n    apply (clarsimp simp: spec_equiv_valid_def equiv_valid_2_def)\n    apply(erule_tac x=bb in allE)\n    using hoare\n    apply (fastforce simp: valid_def)+\n  done\n\nlemma bindE_spec_ev:\n  assumes reads_res_2: \"\\<And> rv s''. (Inr rv, s'') \\<in> fst (f s') \\<Longrightarrow> spec_equiv_valid_inv s'' I A (Q rv) (g rv)\"\n  assumes reads_res_1: \"spec_equiv_valid_inv s' I A P' f\"\n  assumes hoare: \"\\<lbrace>P''\\<rbrace> f \\<lbrace>Q\\<rbrace>,-\"\n  shows \"spec_equiv_valid_inv s' I A (\\<lambda>s. P' s \\<and> P'' s) (f >>=E g)\"\n  unfolding bindE_def\n  apply (rule bind_spec_ev)\n    prefer 3\n    apply(rule hoare[simplified validE_R_def validE_def])\n   apply(simp split: sum.split add: lift_def)\n   apply(rule conjI)\n    apply(fastforce simp: spec_equiv_valid_def throwError_def return_ev2)\n   apply(fastforce simp: reads_res_2)\n  apply(rule reads_res_1)\n  done\n\nlemma if_spec_ev:\n  \"\\<lbrakk> G \\<Longrightarrow> spec_equiv_valid_inv s' I A P f;\n     \\<not> G \\<Longrightarrow> spec_equiv_valid_inv s' I A P' f'\n   \\<rbrakk>  \\<Longrightarrow> spec_equiv_valid_inv s' I A (\\<lambda>s. (G \\<longrightarrow> P s) \\<and> (\\<not> G \\<longrightarrow> P' s)) (if G then f else f')\"\n  by (cases G, simp+)\n\nlemmas splits_spec_ev[wp_split] =\n  drop_spec_ev\n  spec_equiv_valid_guard_imp[OF bind_spec_ev] spec_equiv_valid_guard_imp[OF bindE_spec_ev]\n  bind_spec_ev bindE_spec_ev\n  spec_equiv_valid_guard_imp[OF if_spec_ev] if_spec_ev\n\n(* Miscellaneous rules. *)\n\nlemma assertE_ev[wp]:\n  \"equiv_valid_inv I A \\<top> (assertE b)\"\n  unfolding assertE_def\n  apply wp\n  by simp\n\nlemma equiv_valid_2_bindE:\n  assumes g: \"\\<And>rv rv'. R' rv rv' \\<Longrightarrow>\n      equiv_valid_2 D A A (E \\<oplus> R) (Q rv) (Q' rv') (g rv) (g' rv')\"\n  assumes h1: \"\\<lbrace>S\\<rbrace> f \\<lbrace>Q\\<rbrace>,-\"\n  assumes h2: \"\\<lbrace>S'\\<rbrace> f' \\<lbrace>Q'\\<rbrace>,-\"\n  assumes f: \"equiv_valid_2 D A A (E \\<oplus> R') P P' f f'\"\n  shows \"equiv_valid_2 D A A (E \\<oplus> R) (P and S) (P' and S') (f >>=E g) (f' >>=E g')\"\n  apply(unfold bindE_def)\n  apply(rule equiv_valid_2_guard_imp)\n    apply(rule_tac R'=\"E \\<oplus> R'\" and Q=\"case_sum \\<top>\\<top> Q\" and Q'=\"case_sum \\<top>\\<top> Q'\" and S=S and S'=S' in equiv_valid_2_bind)\n       apply(clarsimp simp: lift_def split: sum.splits)\n       apply(intro impI conjI allI)\n          apply(simp add: throwError_def)\n          apply(rule return_ev2)\n          apply simp\n         apply(simp)\n        apply(simp)\n       apply(fastforce intro: g)\n      apply(rule f)\n     apply(insert h1, fastforce simp: valid_def validE_R_def validE_def split: sum.splits)[1]\n    apply(insert h2, fastforce simp: valid_def validE_R_def validE_def split: sum.splits)[1]\n   by auto\n\nlemma rel_sum_comb_equals:\n  \"((=) \\<oplus> (=)) = (=)\"\n  apply(rule ext)\n  apply(rule ext)\n  apply(rename_tac a b)\n  apply(case_tac a, auto)\n  done\n\ndefinition spec_equiv_valid_2_inv where\n  \"spec_equiv_valid_2_inv s I A R P P' f f' \\<equiv>\n      equiv_valid_2 I A A R (P and ((=) s)) P' f f'\"\n\nlemma spec_equiv_valid_def2:\n  \"spec_equiv_valid s I A A P f =\n   spec_equiv_valid_2_inv s I A (=) P P f f\"\n  apply(simp add: spec_equiv_valid_def spec_equiv_valid_2_inv_def)\n  done\n\nlemma drop_spec_ev2_inv:\n  \"equiv_valid_2 I A A R P P' f f' \\<Longrightarrow>\n   spec_equiv_valid_2_inv s I A R P P' f f'\"\n  apply(simp add: spec_equiv_valid_2_inv_def)\n  apply(erule equiv_valid_2_guard_imp, auto)\n  done\n\nlemma spec_equiv_valid_2_inv_guard_imp:\n  \"\\<lbrakk>spec_equiv_valid_2_inv s I A R Q Q' f f'; \\<And> s. P s \\<Longrightarrow> Q s; \\<And> s. P' s \\<Longrightarrow> Q' s\\<rbrakk> \\<Longrightarrow>\n    spec_equiv_valid_2_inv s I A R P P' f f'\"\n  by(auto simp: spec_equiv_valid_2_inv_def equiv_valid_2_def)\n\nlemma bind_spec_ev2:\n  assumes reads_res_2: \"\\<And> rv s' rv'. \\<lbrakk>(rv, s') \\<in> fst (f s); R' rv rv'\\<rbrakk> \\<Longrightarrow> spec_equiv_valid_2_inv s' I A R (Q rv) (Q' rv') (g rv) (g' rv')\"\n  assumes reads_res_1: \"spec_equiv_valid_2_inv s I A R' P P' f f'\"\n  assumes hoare: \"\\<lbrace>S\\<rbrace> f \\<lbrace>Q\\<rbrace>\"\n  assumes hoare': \"\\<lbrace>S'\\<rbrace> f' \\<lbrace>Q'\\<rbrace>\"\n  shows \"spec_equiv_valid_2_inv s I A R (P and S) (P' and S') (f >>= g) (f' >>= g')\"\n  using reads_res_1\n  apply (clarsimp simp: spec_equiv_valid_2_inv_def equiv_valid_2_def bind_def split_def)\n  apply (erule_tac x=t in allE)\n  apply clarsimp\n  apply (drule_tac x=\"(a, b)\" in bspec, assumption)\n  apply (drule_tac x=\"(ab, bb)\" in bspec, assumption)\n  apply clarsimp\n  apply (cut_tac rv=\"a\" and s'=\"b\" in reads_res_2)\n    apply assumption\n   apply assumption\n  apply (clarsimp simp: spec_equiv_valid_2_inv_def equiv_valid_2_def)\n  apply(drule_tac x=bb in spec)\n  apply clarsimp\n  using hoare hoare'\n  apply (fastforce simp: valid_def)+\n  done\n\nlemma spec_equiv_valid_2_inv_bindE:\n  assumes g: \"\\<And>rv s' rv'. \\<lbrakk>(Inr rv, s') \\<in> fst (f s); R' rv rv'\\<rbrakk> \\<Longrightarrow>\n      spec_equiv_valid_2_inv s' I A (E \\<oplus> R) (Q rv) (Q' rv') (g rv) (g' rv')\"\n  assumes h1: \"\\<lbrace>S\\<rbrace> f \\<lbrace>Q\\<rbrace>,-\"\n  assumes h2: \"\\<lbrace>S'\\<rbrace> f' \\<lbrace>Q'\\<rbrace>,-\"\n  assumes f: \"spec_equiv_valid_2_inv s I A (E \\<oplus> R') P P' f f'\"\n  shows \"spec_equiv_valid_2_inv s I A (E \\<oplus> R) (P and S) (P' and S') (f >>=E g) (f' >>=E g')\"\n  apply(unfold bindE_def)\n  apply(rule spec_equiv_valid_2_inv_guard_imp)\n    apply(rule_tac R'=\"E \\<oplus> R'\" and Q=\"case_sum \\<top>\\<top> Q\" and Q'=\"case_sum \\<top>\\<top> Q'\" and S=S and S'=S' in bind_spec_ev2)\n       apply(clarsimp simp: lift_def split: sum.splits)\n       apply(intro impI conjI allI)\n          apply(simp add: throwError_def)\n          apply(rule drop_spec_ev2_inv[OF return_ev2])\n          apply simp\n         apply(simp)\n        apply(simp)\n       apply(fastforce intro: g)\n      apply(rule f)\n     apply(insert h1, fastforce simp: valid_def validE_R_def validE_def split: sum.splits)[1]\n    apply(insert h2, fastforce simp: valid_def validE_R_def validE_def split: sum.splits)[1]\n   by auto\n\nlemma trancl_subset_equivalence:\n  \"\\<lbrakk>(a, b) \\<in> r'\\<^sup>+; \\<forall>x. (a, x)\\<in>r'\\<^sup>+ \\<longrightarrow> Q x; \\<forall>x y. Q x \\<longrightarrow> ((y, x) \\<in> r) = ((y, x) \\<in> r')\\<rbrakk> \\<Longrightarrow> (a, b) \\<in> r\\<^sup>+\"\n  apply(induct a b rule: trancl.induct)\n   apply(blast)\n  apply(simp)\n  apply(rule_tac b=b in trancl_into_trancl)\n   apply(simp)\n  apply(erule_tac x=c in allE)\n  apply(subgoal_tac \"(a, c) \\<in> r'\\<^sup>+\")\n   apply(auto)\n   done\n\nlemma equiv_valid_rv_gets_compD:\n  \"equiv_valid_rv_inv I A R P (gets (f \\<circ> g)) \\<Longrightarrow>\n   equiv_valid_rv_inv I A (\\<lambda> rv rv'. R (f rv) (f rv')) P (gets g)\"\n  apply(clarsimp simp: equiv_valid_2_def gets_def bind_def return_def get_def)\n  done\n\n\nlemma liftE_ev2:\n  \"equiv_valid_2 I A B R P P' f f' \\<Longrightarrow>\n   equiv_valid_2 I A B (E \\<oplus> R) P P' (liftE f) (liftE f')\"\n  apply(clarsimp simp: liftE_def equiv_valid_2_def bind_def return_def)\n  apply fastforce\n  done\n\nlemma whenE_spec_ev2_inv:\n  assumes a: \"b \\<Longrightarrow> spec_equiv_valid_2_inv s I A R P P' m m'\"\n  assumes r: \"\\<And> x. R x x\"\n  shows \"spec_equiv_valid_2_inv s I A R P P' (whenE b m) (whenE b m')\"\n  unfolding whenE_def\n  apply (auto intro: a simp: returnOk_def intro!: drop_spec_ev2_inv[OF return_ev2] intro: r)\n  done\n\nlemma whenE_spec_ev:\n  assumes a: \"b \\<Longrightarrow> spec_equiv_valid_inv s I A P m\"\n  shows \"spec_equiv_valid_inv s I A P  (whenE b m) \"\n  unfolding whenE_def\n  apply (auto intro: a simp: returnOk_def intro!: drop_spec_ev[OF return_ev_pre])\n  done\n\n\nlemma spec_equiv_valid_2_inv_by_spec_equiv_valid:\n  \"\\<lbrakk>spec_equiv_valid s I A A P f; P' = P; f' = f;\n    (\\<And> a. R a a)\\<rbrakk> \\<Longrightarrow>\n       spec_equiv_valid_2_inv s I A R P P' f f'\"\n  apply(clarsimp simp: spec_equiv_valid_def spec_equiv_valid_2_inv_def)\n  apply(fastforce simp: equiv_valid_2_def)\n  done\n\nlemma mapM_ev'':\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A (P x) (m x)\"\n  assumes inv: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> \\<lbrace> \\<lambda>s. \\<forall>x\\<in>set lst. P x s \\<rbrace> m x \\<lbrace> \\<lambda>_ s. \\<forall>x\\<in>set lst. P x s \\<rbrace>\"\n  shows \"equiv_valid_inv D A (\\<lambda> s. \\<forall>x\\<in>set lst. P x s) (mapM m lst)\"\n  apply(rule mapM_ev)\n  apply(rule equiv_valid_guard_imp[OF reads_res]; simp)\n  apply(wpsimp wp: inv)\n  done\n\nlemma mapM_x_ev'':\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A (P x) (m x)\"\n  assumes inv: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> \\<lbrace> \\<lambda>s. \\<forall>x\\<in>set lst. P x s \\<rbrace> m x \\<lbrace> \\<lambda>_ s. \\<forall>x\\<in>set lst. P x s \\<rbrace>\"\n  shows \"equiv_valid_inv D A (\\<lambda> s. \\<forall>x\\<in>set lst. P x s) (mapM_x m lst)\"\n  apply(rule mapM_x_ev)\n  apply(rule equiv_valid_guard_imp[OF reads_res]; simp)\n  apply(wpsimp wp: inv)\n  done\n\nlemma catch_ev[wp]:\n  assumes ok:\n    \"equiv_valid I A A P f\"\n  assumes err:\n    \"\\<And> e. equiv_valid I A A (E e) (handler e)\"\n  assumes hoare:\n    \"\\<lbrace> Q \\<rbrace> f -, \\<lbrace> E \\<rbrace>\"\n  shows\n    \"equiv_valid I A A (P and Q) (f <catch> handler)\"\n  apply (simp add: catch_def)\n  apply (wp err ok | wpc | simp)+\n   apply (insert hoare[simplified validE_E_def validE_def])[1]\n   apply (simp split: sum.splits)\n  by simp\n\nlemma equiv_valid_rv_trivial:\n  assumes inv: \"\\<And> P. \\<lbrace> P \\<rbrace> f \\<lbrace> \\<lambda>_. P \\<rbrace>\"\n  shows \"equiv_valid_rv_inv I A \\<top>\\<top> \\<top> f\"\n  by(auto simp: equiv_valid_2_def dest: state_unchanged[OF inv])\n\nlemma equiv_valid_2_trivial:\n  assumes inv: \"\\<And> P. \\<lbrace> P \\<rbrace> f \\<lbrace> \\<lambda>_. P \\<rbrace>\"\n  assumes inv': \"\\<And> P. \\<lbrace> P \\<rbrace> f' \\<lbrace> \\<lambda>_. P \\<rbrace>\"\n  shows \"equiv_valid_2 I A A \\<top>\\<top> \\<top> \\<top> f f'\"\n  by(auto simp: equiv_valid_2_def dest: state_unchanged[OF inv] state_unchanged[OF inv'])\n\nlemma gen_asm_ev2_r:\n  \"\\<lbrakk>P' \\<Longrightarrow> equiv_valid_2 I A B R P Q f f'\\<rbrakk> \\<Longrightarrow>\n   equiv_valid_2 I A B R P  (Q and (K P')) f f'\"\n  apply(fastforce simp: equiv_valid_2_def)\n  done\n\nlemma gen_asm_ev2_l:\n  \"\\<lbrakk>P \\<Longrightarrow> equiv_valid_2 I A B R Q P' f f'\\<rbrakk> \\<Longrightarrow>\n   equiv_valid_2 I A B R (Q and (K P)) P' f f'\"\n  apply(fastforce simp: equiv_valid_2_def)\n  done\n\nlemma gen_asm_ev2_r':\n  \"\\<lbrakk>P' \\<Longrightarrow> equiv_valid_2 I A B R P \\<top> f f'\\<rbrakk> \\<Longrightarrow>\n   equiv_valid_2 I A B R P (\\<lambda>s. P') f f'\"\n  apply(fastforce simp: equiv_valid_2_def)\n  done\n\nlemma gen_asm_ev2_l':\n  \"\\<lbrakk>P \\<Longrightarrow> equiv_valid_2 I A B R \\<top> P' f f'\\<rbrakk> \\<Longrightarrow>\n   equiv_valid_2 I A B R (\\<lambda>s. P) P' f f'\"\n  apply(fastforce simp: equiv_valid_2_def)\n  done\n\nlemma equiv_valid_rv_liftE_bindE:\n  assumes ev1:\n  \"equiv_valid_rv_inv I A W P f\"\n  assumes ev2:\n  \"\\<And> rv rv'. W rv rv' \\<Longrightarrow> equiv_valid_2 I A A R (Q rv) (Q rv') (g rv) (g rv')\"\n  assumes hoare:\n  \"\\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  shows \"equiv_valid_rv_inv I A R P ((liftE f) >>=E g)\"\n  apply(unfold bindE_def)\n  apply(rule_tac Q=\"\\<lambda> rv. K (\\<forall> v. rv \\<noteq> Inl v) and (\\<lambda> s. \\<forall> v. rv = Inr v \\<longrightarrow> Q v s)\" in equiv_valid_rv_bind)\n    apply(rule_tac E=\"dc\" in equiv_valid_2_liftE)\n    apply(rule ev1)\n   apply(clarsimp simp: lift_def split: sum.split)\n   apply(insert ev2, fastforce simp: equiv_valid_2_def)[1]\n  apply(insert hoare, clarsimp simp: valid_def liftE_def bind_def return_def split_def)\n  done\n\nlemma if_evrv:\n  assumes \"b \\<Longrightarrow> equiv_valid_rv_inv I A R P f\"\n  assumes \"\\<not> b \\<Longrightarrow> equiv_valid_rv_inv I A R Q g\"\n  shows \"equiv_valid_rv_inv I A R (\\<lambda>s. (b \\<longrightarrow> P s) \\<and> (\\<not>b \\<longrightarrow> Q s)) (if b then f else g)\"\n  apply (clarsimp split: if_split)\n  using assms by blast\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/lib/EquivValid.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5273165233795672, "lm_q2_score": 0.5, "lm_q1q2_score": 0.2636582616897836}}
{"text": "theory SINVAR_TaintingTrusted_impl\nimports SINVAR_TaintingTrusted \"../TopoS_Interface_impl\"\nbegin\n\n\nsubsubsection \\<open>SecurityInvariant Tainting with Trust List Implementation\\<close>\n\ncode_identifier code_module SINVAR_Tainting_impl => (Scala) SINVAR_Tainting\n\n(*could we use those to make code more efficient?*)\nlemma \"A - B \\<subseteq> C \\<longleftrightarrow> (\\<forall>a\\<in>A. a \\<in> C \\<or> a \\<in> B)\" by blast\nlemma \"\\<not>(A - B \\<subseteq> C) \\<longleftrightarrow> (\\<exists>a \\<in> A. a \\<notin> C \\<and> a \\<notin> B)\" by blast\n\nfun sinvar :: \"'v list_graph \\<Rightarrow> ('v \\<Rightarrow> SINVAR_TaintingTrusted.taints) \\<Rightarrow> bool\" where\n  \"sinvar G nP = (\\<forall> (v1,v2) \\<in> set (edgesL G). taints (nP v1) - untaints (nP v1) \\<subseteq> taints (nP v2))\"\n\n\n(*Test that we have executable code, despite the abstractions*)\nexport_code sinvar checking SML\nvalue[code] \"sinvar \\<lparr> nodesL = [], edgesL =[] \\<rparr> (\\<lambda>_. SINVAR_TaintingTrusted.default_node_properties)\"\nlemma \"sinvar \\<lparr> nodesL = [], edgesL =[] \\<rparr> (\\<lambda>_. SINVAR_TaintingTrusted.default_node_properties)\" by eval\n\n\ndefinition TaintingTrusted_offending_list \n  :: \"'v list_graph \\<Rightarrow> ('v \\<Rightarrow> SINVAR_TaintingTrusted.taints) \\<Rightarrow> ('v \\<times> 'v) list list\" where\n  \"TaintingTrusted_offending_list G nP = (if sinvar G nP then\n    []\n   else \n    [ [e \\<leftarrow> edgesL G. case e of (v1,v2) \\<Rightarrow> \\<not>(taints (nP v1) - untaints (nP v1) \\<subseteq> taints (nP v2))] ])\"\n\n(*TODO: is this code somewhat efficient?*)\nexport_code TaintingTrusted_offending_list checking SML\n\n\ndefinition \"NetModel_node_props P =\n  (\\<lambda> i. (case (node_properties P) i of\n                  Some property \\<Rightarrow> property\n                | None \\<Rightarrow> SINVAR_TaintingTrusted.default_node_properties))\"\n\n\n\ndefinition \"TaintingTrusted_eval G P = (wf_list_graph G \\<and> \n  sinvar G (SecurityInvariant.node_props SINVAR_TaintingTrusted.default_node_properties P))\"\n\n\ninterpretation TaintingTrusted_impl:TopoS_List_Impl\n  where default_node_properties=SINVAR_TaintingTrusted.default_node_properties\n  and sinvar_spec=SINVAR_TaintingTrusted.sinvar\n  and sinvar_impl=sinvar\n  and receiver_violation=SINVAR_TaintingTrusted.receiver_violation\n  and offending_flows_impl=TaintingTrusted_offending_list\n  and node_props_impl=NetModel_node_props\n  and eval_impl=TaintingTrusted_eval\n  apply(unfold TopoS_List_Impl_def)\n  apply(rule conjI)\n   apply(simp add: TopoS_TaintingTrusted)\n   apply(simp add: list_graph_to_graph_def SINVAR_TaintingTrusted.sinvar_def; fail)\n  apply(rule conjI)\n   apply(simp add: list_graph_to_graph_def)\n   apply(simp add: list_graph_to_graph_def SINVAR_TaintingTrusted.sinvar_def Taints_offending_set\n                    SINVAR_TaintingTrusted.Taints_offending_set_def TaintingTrusted_offending_list_def; fail)\n  apply(rule conjI)\n   apply(simp only: NetModel_node_props_def)\n   (*interpretation is in local context*)\n   apply (metis SecurityInvariant.node_props.simps SecurityInvariant.node_props_eq_node_props_formaldef TopoS_TaintingTrusted)\n  apply(simp only: TaintingTrusted_eval_def)\n  apply(simp add: TopoS_eval_impl_proofrule[OF TopoS_TaintingTrusted])\n  apply(simp add: list_graph_to_graph_def SINVAR_TaintingTrusted.sinvar_def; fail)\n done\n\n\n\nsubsubsection \\<open>TaintingTrusted packing\\<close>\n  definition SINVAR_LIB_TaintingTrusted :: \"('v::vertex, SINVAR_TaintingTrusted.taints) TopoS_packed\" where\n    \"SINVAR_LIB_TaintingTrusted \\<equiv> \n    \\<lparr> nm_name = ''TaintingTrusted'', \n      nm_receiver_violation = SINVAR_TaintingTrusted.receiver_violation,\n      nm_default = SINVAR_TaintingTrusted.default_node_properties, \n      nm_sinvar = sinvar,\n      nm_offending_flows = TaintingTrusted_offending_list, \n      nm_node_props = NetModel_node_props,\n      nm_eval = TaintingTrusted_eval\n      \\<rparr>\"\n  interpretation SINVAR_LIB_BLPbasic_interpretation: TopoS_modelLibrary SINVAR_LIB_TaintingTrusted\n      SINVAR_TaintingTrusted.sinvar\n    apply(unfold TopoS_modelLibrary_def SINVAR_LIB_TaintingTrusted_def)\n    apply(rule conjI)\n     apply(simp)\n    apply(simp)\n    by(unfold_locales)\n\nsubsubsection\\<open>Example\\<close>\ncontext\nbegin\n  private definition tainting_example :: \"string list_graph\" where\n  \"tainting_example \\<equiv> \\<lparr> nodesL = [''produce 1'',\n                                  ''produce 2'',\n                                  ''produce 3'',\n                                  ''read 1 2'',\n                                  ''read 3'',\n                                  ''consume 1 2 3'',\n                                  ''consume 3''], \n              edgesL =[(''produce 1'', ''read 1 2''),\n                       (''produce 2'', ''read 1 2''),\n                       (''produce 3'', ''read 3''), \n                       (''read 3'', ''read 1 2''),\n                       (''read 1 2'', ''consume 1 2 3''),\n                       (''read 3'', ''consume 3'')] \\<rparr>\"\n  lemma \"wf_list_graph tainting_example\" by eval\n\n\n  private definition tainting_example_props :: \"string \\<Rightarrow> SINVAR_TaintingTrusted.taints\" where\n    \"tainting_example_props \\<equiv> (\\<lambda> n. SINVAR_TaintingTrusted.default_node_properties)\n                          (''produce 1'' := TaintsUntaints {''1''} {},\n                           ''produce 2'' := TaintsUntaints {''2''} {},\n                           ''produce 3'' := TaintsUntaints {''3''} {},\n                           ''read 1 2'' := TaintsUntaints {''3'',''foo''} {''1'',''2''},\n                           ''read 3'' := TaintsUntaints {''3''} {},\n                           ''consume 1 2 3'' := TaintsUntaints {''foo'',''3''} {},\n                           ''consume 3'' := TaintsUntaints {''3''} {})\"\n\n  value \"tainting_example_props (''consume 1 2 3'')\"\n  value[code] \"TaintingTrusted_offending_list tainting_example tainting_example_props\"\n  private lemma \"sinvar tainting_example tainting_example_props\" by eval\nend\n\n(*TODO: fails. why?*)\nexport_code SINVAR_LIB_TaintingTrusted checking Scala\nexport_code SINVAR_LIB_TaintingTrusted checking SML\n\nhide_const (open) NetModel_node_props TaintingTrusted_offending_list TaintingTrusted_eval\n\nhide_const (open) sinvar\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Network_Security_Policy_Verification/Security_Invariants/SINVAR_TaintingTrusted_impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6654105454764747, "lm_q2_score": 0.3960681662740417, "lm_q1q2_score": 0.2635479345662772}}
{"text": "(*  Title:      Stateful_Protocol_Model.thy\n    Author:     Andreas Viktor Hess, DTU\n    Author:     Sebastian A. Mödersheim, DTU\n    Author:     Achim D. Brucker, University of Exeter\n    Author:     Anders Schlichtkrull, DTU\n    SPDX-License-Identifier: BSD-3-Clause\n*)\n\nsection\\<open>Stateful Protocol Model\\<close>\ntheory Stateful_Protocol_Model\n  imports Stateful_Protocol_Composition_and_Typing.Stateful_Compositionality\n          Transactions Term_Abstraction\nbegin\n\nsubsection \\<open>Locale Setup\\<close>\nlocale stateful_protocol_model =\n  fixes arity\\<^sub>f::\"'fun \\<Rightarrow> nat\"\n    and arity\\<^sub>s::\"'sets \\<Rightarrow> nat\"\n    and public\\<^sub>f::\"'fun \\<Rightarrow> bool\"\n    and Ana\\<^sub>f::\"'fun \\<Rightarrow> ((('fun,'atom::finite,'sets,'lbl) prot_fun, nat) term list \\<times> nat list)\"\n    and \\<Gamma>\\<^sub>f::\"'fun \\<Rightarrow> 'atom option\"\n    and label_witness1::\"'lbl\"\n    and label_witness2::\"'lbl\"\n  assumes Ana\\<^sub>f_assm1: \"\\<forall>f. let (K, M) = Ana\\<^sub>f f in (\\<forall>k \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (set K).\n      is_Fun k \\<longrightarrow> (is_Fu (the_Fun k)) \\<and> length (args k) = arity\\<^sub>f (the_Fu (the_Fun k)))\"\n    and Ana\\<^sub>f_assm2: \"\\<forall>f. let (K, M) = Ana\\<^sub>f f in \\<forall>i \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set K) \\<union> set M. i < arity\\<^sub>f f\"\n    and public\\<^sub>f_assm: \"\\<forall>f. arity\\<^sub>f f > (0::nat) \\<longrightarrow> public\\<^sub>f f\"\n    and \\<Gamma>\\<^sub>f_assm: \"\\<forall>f. arity\\<^sub>f f = (0::nat) \\<longrightarrow> \\<Gamma>\\<^sub>f f \\<noteq> None\"\n    and label_witness_assm: \"label_witness1 \\<noteq> label_witness2\"\nbegin\n\nlemma Ana\\<^sub>f_assm1_alt: \n  assumes \"Ana\\<^sub>f f = (K,M)\" \"k \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (set K)\"\n  shows \"(\\<exists>x. k = Var x) \\<or> (\\<exists>h T. k = Fun (Fu h) T \\<and> length T = arity\\<^sub>f h)\"\nproof (cases k)\n  case (Fun g T)\n  let ?P = \"\\<lambda>k. is_Fun k \\<longrightarrow> is_Fu (the_Fun k) \\<and> length (args k) = arity\\<^sub>f (the_Fu (the_Fun k))\"\n  let ?Q = \"\\<lambda>K M. \\<forall>k \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (set K). ?P k\"\n\n  have \"?Q (fst (Ana\\<^sub>f f)) (snd (Ana\\<^sub>f f))\" using Ana\\<^sub>f_assm1 split_beta[of ?Q \"Ana\\<^sub>f f\"] by meson\n  hence \"?Q K M\" using assms(1) by simp\n  hence \"?P k\" using assms(2) by blast\n  thus ?thesis using Fun by (cases g) auto\nqed simp\n\nlemma Ana\\<^sub>f_assm2_alt:\n  assumes \"Ana\\<^sub>f f = (K,M)\" \"i \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set K) \\<union> set M\"\n  shows \"i < arity\\<^sub>f f\"\nusing Ana\\<^sub>f_assm2 assms by fastforce\n\n\nsubsection \\<open>Definitions\\<close>\nfun arity where\n  \"arity (Fu f) = arity\\<^sub>f f\"\n| \"arity (Set s) = arity\\<^sub>s s\"\n| \"arity (Val _) = 0\"\n| \"arity (Abs _) = 0\"\n| \"arity Pair = 2\"\n| \"arity (Attack _) = 0\"\n| \"arity OccursFact = 2\"\n| \"arity OccursSec = 0\"\n| \"arity (PubConst _ _) = 0\"\n\nfun public where\n  \"public (Fu f) = public\\<^sub>f f\"\n| \"public (Set s) = (arity\\<^sub>s s > 0)\"\n| \"public (Val n) = False\"\n| \"public (Abs _) = False\"\n| \"public Pair = True\"\n| \"public (Attack _) = False\"\n| \"public OccursFact = True\"\n| \"public OccursSec = False\"\n| \"public (PubConst _ _) = True\"\n\nfun Ana where\n  \"Ana (Fun (Fu f) T) = (\n    if arity\\<^sub>f f = length T \\<and> arity\\<^sub>f f > 0\n    then let (K,M) = Ana\\<^sub>f f in (K \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t (!) T, map ((!) T) M)\n    else ([], []))\"\n| \"Ana _ = ([], [])\"\n\ndefinition \\<Gamma>\\<^sub>v where\n  \"\\<Gamma>\\<^sub>v v \\<equiv> (\n    if (\\<forall>t \\<in> subterms (fst v).\n          case t of (TComp f T) \\<Rightarrow> arity f > 0 \\<and> arity f = length T | _ \\<Rightarrow> True)\n    then fst v\n    else TAtom Bottom)\"\n\nfun \\<Gamma> where\n  \"\\<Gamma> (Var v) = \\<Gamma>\\<^sub>v v\"\n| \"\\<Gamma> (Fun f T) = (\n    if arity f = 0\n    then case f of\n      (Fu g) \\<Rightarrow> TAtom (case \\<Gamma>\\<^sub>f g of Some a \\<Rightarrow> Atom a | None \\<Rightarrow> Bottom)\n    | (Val _) \\<Rightarrow> TAtom Value\n    | (Abs _) \\<Rightarrow> TAtom AbsValue\n    | (Set _) \\<Rightarrow> TAtom SetType\n    | (Attack _) \\<Rightarrow> TAtom AttackType\n    | OccursSec \\<Rightarrow> TAtom OccursSecType\n    | (PubConst a _) \\<Rightarrow> TAtom a\n    | _ \\<Rightarrow> TAtom Bottom\n    else TComp f (map \\<Gamma> T))\"\n\nlemma \\<Gamma>_consts_simps[simp]:\n  \"arity\\<^sub>f g = 0 \\<Longrightarrow> \\<Gamma> (Fun (Fu g) []::('fun,'atom,'sets,'lbl) prot_term)\n                    = TAtom (case \\<Gamma>\\<^sub>f g of Some a \\<Rightarrow> Atom a | None \\<Rightarrow> Bottom)\"\n  \"\\<Gamma> (Fun (Val n) []::('fun,'atom,'sets,'lbl) prot_term) = TAtom Value\"\n  \"\\<Gamma> (Fun (Abs b) []::('fun,'atom,'sets,'lbl) prot_term) = TAtom AbsValue\"\n  \"arity\\<^sub>s s = 0 \\<Longrightarrow> \\<Gamma> (Fun (Set s) []::('fun,'atom,'sets,'lbl) prot_term) = TAtom SetType\"\n  \"\\<Gamma> (Fun (Attack x) []::('fun,'atom,'sets,'lbl) prot_term) = TAtom AttackType\"\n  \"\\<Gamma> (Fun OccursSec []::('fun,'atom,'sets,'lbl) prot_term) = TAtom OccursSecType\"\n  \"\\<Gamma> (Fun (PubConst a t) []::('fun,'atom,'sets,'lbl) prot_term) = TAtom a\"\nby simp+\n\nlemma \\<Gamma>_Fu_simps[simp]:\n  \"arity\\<^sub>f f \\<noteq> 0 \\<Longrightarrow> \\<Gamma> (Fun (Fu f) T) = TComp (Fu f) (map \\<Gamma> T)\" (is \"?A1 \\<Longrightarrow> ?A2\")\n  \"arity\\<^sub>f f = 0 \\<Longrightarrow> \\<Gamma>\\<^sub>f f = Some a \\<Longrightarrow> \\<Gamma> (Fun (Fu f) T) = TAtom (Atom a)\" (is \"?B1 \\<Longrightarrow> ?B2 \\<Longrightarrow> ?B3\")\n  \"arity\\<^sub>f f = 0 \\<Longrightarrow> \\<Gamma>\\<^sub>f f = None \\<Longrightarrow> \\<Gamma> (Fun (Fu f) T) = TAtom Bottom\" (is \"?C1 \\<Longrightarrow> ?C2 \\<Longrightarrow> ?C3\")\n  \"\\<Gamma> (Fun (Fu f) T) \\<noteq> TAtom Value\" (is ?D)\n  \"\\<Gamma> (Fun (Fu f) T) \\<noteq> TAtom AttackType\" (is ?E)\n  \"\\<Gamma> (Fun (Fu f) T) \\<noteq> TAtom OccursSecType\" (is ?F)\nproof -\n  show \"?A1 \\<Longrightarrow> ?A2\" by simp\n  show \"?B1 \\<Longrightarrow> ?B2 \\<Longrightarrow> ?B3\" by simp\n  show \"?C1 \\<Longrightarrow> ?C2 \\<Longrightarrow> ?C3\" by simp\n  show ?D by (cases \"\\<Gamma>\\<^sub>f f\") simp_all\n  show ?E by (cases \"\\<Gamma>\\<^sub>f f\") simp_all\n  show ?F by (cases \"\\<Gamma>\\<^sub>f f\") simp_all\nqed\n\nlemma \\<Gamma>_Set_simps[simp]:\n  \"arity\\<^sub>s s \\<noteq> 0 \\<Longrightarrow> \\<Gamma> (Fun (Set s) T) = TComp (Set s) (map \\<Gamma> T)\"\n  \"\\<Gamma> (Fun (Set s) T) = TAtom SetType \\<or> \\<Gamma> (Fun (Set s) T) = TComp (Set s) (map \\<Gamma> T)\"\n  \"\\<Gamma> (Fun (Set s) T) \\<noteq> TAtom Value\"\n  \"\\<Gamma> (Fun (Set s) T) \\<noteq> TAtom (Atom a)\"\n  \"\\<Gamma> (Fun (Set s) T) \\<noteq> TAtom AttackType\"\n  \"\\<Gamma> (Fun (Set s) T) \\<noteq> TAtom OccursSecType\"\n  \"\\<Gamma> (Fun (Set s) T) \\<noteq> TAtom Bottom\"\nby auto\n\n\nsubsection \\<open>Locale Interpretations\\<close>\nlemma Ana_Fu_cases:\n  assumes \"Ana (Fun f T) = (K,M)\"\n    and \"f = Fu g\"\n    and \"Ana\\<^sub>f g = (K',M')\"\n  shows \"(K,M) = (if arity\\<^sub>f g = length T \\<and> arity\\<^sub>f g > 0\n                  then (K' \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t (!) T, map ((!) T) M')\n                  else ([],[]))\" (is ?A)\n    and \"(K,M) = (K' \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t (!) T, map ((!) T) M') \\<or> (K,M) = ([],[])\" (is ?B)\nproof -\n  show ?A using assms by (cases \"arity\\<^sub>f g = length T \\<and> arity\\<^sub>f g > 0\") auto\n  thus ?B by metis\nqed\n\nlemma Ana_Fu_intro:\n  assumes \"arity\\<^sub>f f = length T\" \"arity\\<^sub>f f > 0\"\n    and \"Ana\\<^sub>f f = (K',M')\"\n  shows \"Ana (Fun (Fu f) T) = (K' \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t (!) T, map ((!) T) M')\"\nusing assms by simp\n\nlemma Ana_Fu_elim:\n  assumes \"Ana (Fun f T) = (K,M)\"\n    and \"f = Fu g\"\n    and \"Ana\\<^sub>f g = (K',M')\"\n    and \"(K,M) \\<noteq> ([],[])\"\n  shows \"arity\\<^sub>f g = length T\" (is ?A)\n    and \"(K,M) = (K' \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t (!) T, map ((!) T) M')\" (is ?B)\nproof -\n  show ?A using assms by force\n  moreover have \"arity\\<^sub>f g > 0\" using assms by force\n  ultimately show ?B using assms by auto\nqed\n\nlemma Ana_nonempty_inv:\n  assumes \"Ana t \\<noteq> ([],[])\"\n  shows \"\\<exists>f T. t = Fun (Fu f) T \\<and> arity\\<^sub>f f = length T \\<and> arity\\<^sub>f f > 0 \\<and>\n               (\\<exists>K M. Ana\\<^sub>f f = (K, M) \\<and> Ana t = (K \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t (!) T, map ((!) T) M))\"\nusing assms\nproof (induction t rule: Ana.induct)\n  case (1 f T)\n  hence *: \"arity\\<^sub>f f = length T\" \"0 < arity\\<^sub>f f\"\n           \"Ana (Fun (Fu f) T) = (case Ana\\<^sub>f f of (K, M) \\<Rightarrow> (K \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t (!) T, map ((!) T) M))\"\n    using Ana.simps(1)[of f T] unfolding Let_def by metis+\n\n  obtain K M where **: \"Ana\\<^sub>f f = (K, M)\" by (metis surj_pair)\n  hence \"Ana (Fun (Fu f) T) = (K \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t (!) T, map ((!) T) M)\" using *(3) by simp\n  thus ?case using ** *(1,2) by blast\nqed simp_all\n\nlemma assm1:\n  assumes \"Ana t = (K,M)\"\n  shows \"fv\\<^sub>s\\<^sub>e\\<^sub>t (set K) \\<subseteq> fv t\"\nusing assms\nproof (induction t rule: term.induct)\n  case (Fun f T)\n  have aux: \"fv\\<^sub>s\\<^sub>e\\<^sub>t (set K \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t (!) T) \\<subseteq> fv\\<^sub>s\\<^sub>e\\<^sub>t (set T)\"\n    when K: \"\\<forall>i \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set K). i < length T\"\n    for K::\"(('fun,'atom,'sets,'lbl) prot_fun, nat) term list\"\n  proof\n    fix x assume \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set K \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t (!) T)\"\n    then obtain k where k: \"k \\<in> set K\" \"x \\<in> fv (k \\<cdot> (!) T)\" by moura\n    have \"\\<forall>i \\<in> fv k. i < length T\" using K k(1) by simp\n    thus \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set T)\"\n      by (metis (no_types, lifting) k(2) contra_subsetD fv_set_mono image_subsetI nth_mem\n                                    subst_apply_fv_unfold)\n  qed\n\n  { fix g assume f: \"f = Fu g\" and K: \"K \\<noteq> []\"\n    obtain K' M' where *: \"Ana\\<^sub>f g = (K',M')\" by moura\n    have \"(K, M) \\<noteq> ([], [])\" using K by simp\n    hence \"(K, M) = (K' \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t (!) T, map ((!) T) M')\" \"arity\\<^sub>f g = length T\"\n      using Ana_Fu_cases(1)[OF Fun.prems f *]\n      by presburger+\n    hence ?case using aux[of K'] Ana\\<^sub>f_assm2_alt[OF *] by auto\n  } thus ?case using Fun by (cases f) fastforce+\nqed simp\n\nlemma assm2:\n  assumes \"Ana t = (K,M)\"\n  and \"\\<And>g S'. Fun g S' \\<sqsubseteq> t \\<Longrightarrow> length S' = arity g\"\n  and \"k \\<in> set K\"\n  and \"Fun f T' \\<sqsubseteq> k\"\n  shows \"length T' = arity f\"\nusing assms\nproof (induction t rule: term.induct)\n  case (Fun g T)\n  obtain h where 2: \"g = Fu h\"\n    using Fun.prems(1,3) by (cases g) auto\n  obtain K' M' where 1: \"Ana\\<^sub>f h = (K',M')\" by moura\n  have \"(K,M) \\<noteq> ([],[])\" using Fun.prems(3) by auto\n  hence \"(K,M) = (K' \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t (!) T, map ((!) T) M')\"\n        \"\\<And>i. i \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set K') \\<union> set M' \\<Longrightarrow> i < length T\"\n    using Ana_Fu_cases(1)[OF Fun.prems(1) 2 1] Ana\\<^sub>f_assm2_alt[OF 1]\n    by presburger+\n  hence \"K = K' \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t (!) T\" and 3: \"\\<forall>i\\<in>fv\\<^sub>s\\<^sub>e\\<^sub>t (set K'). i < length T\" by simp_all\n  then obtain k' where k': \"k' \\<in> set K'\" \"k = k' \\<cdot> (!) T\" using Fun.prems(3) by moura\n  hence 4: \"Fun f T' \\<in> subterms (k' \\<cdot> (!) T)\" \"fv k' \\<subseteq> fv\\<^sub>s\\<^sub>e\\<^sub>t (set K')\"\n    using Fun.prems(4) by auto\n  show ?case\n  proof (cases \"\\<exists>i \\<in> fv k'. Fun f T' \\<in> subterms (T ! i)\")\n    case True\n    hence \"Fun f T' \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (set T)\" using k' Fun.prems(4) 3 by auto\n    thus ?thesis using Fun.prems(2) by auto\n  next\n    case False\n    then obtain S where \"Fun f S \\<in> subterms k'\" \"Fun f T' = Fun f S \\<cdot> (!) T\"\n      using k'(2) Fun.prems(4) subterm_subst_not_img_subterm by force\n    thus ?thesis using Ana\\<^sub>f_assm1_alt[OF 1, of \"Fun f S\"] k'(1) by (cases f) auto\n  qed\nqed simp\n\nlemma assm4:\n  assumes \"Ana (Fun f T) = (K, M)\"\n  shows \"set M \\<subseteq> set T\"\nusing assms\nproof (cases f)\n  case (Fu g)\n  obtain K' M' where *: \"Ana\\<^sub>f g = (K',M')\" by moura\n  have \"M = [] \\<or> (arity\\<^sub>f g = length T \\<and> M = map ((!) T) M')\"\n    using Ana_Fu_cases(1)[OF assms Fu *]\n    by (meson prod.inject)\n  thus ?thesis using Ana\\<^sub>f_assm2_alt[OF *] by auto\nqed auto\n\nlemma assm5: \"Ana t = (K,M) \\<Longrightarrow> K \\<noteq> [] \\<or> M \\<noteq> [] \\<Longrightarrow> Ana (t \\<cdot> \\<delta>) = (K \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta>, M \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta>)\"\nproof (induction t rule: term.induct)\n  case (Fun f T) thus ?case\n  proof (cases f)\n    case (Fu g)\n    obtain K' M' where *: \"Ana\\<^sub>f g = (K',M')\" by moura\n    have **: \"K = K' \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t (!) T\" \"M = map ((!) T) M'\"\n             \"arity\\<^sub>f g = length T\" \"\\<forall>i \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set K') \\<union> set M'. i < arity\\<^sub>f g\" \"0 < arity\\<^sub>f g\"\n      using Fun.prems(2) Ana_Fu_cases(1)[OF Fun.prems(1) Fu *] Ana\\<^sub>f_assm2_alt[OF *]\n      by (meson prod.inject)+\n\n    have ***: \"\\<forall>i \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set K'). i < length T\" \"\\<forall>i \\<in> set M'. i < length T\" using **(3,4) by auto\n    \n    have \"K \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta> = K' \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t (!) (map (\\<lambda>t. t \\<cdot> \\<delta>) T)\"\n         \"M \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta> = map ((!) (map (\\<lambda>t. t \\<cdot> \\<delta>) T)) M'\"\n      using subst_idx_map[OF ***(2), of \\<delta>]\n            subst_idx_map'[OF ***(1), of \\<delta>]\n            **(1,2)\n      by fast+\n    thus ?thesis using Fu * **(3,5) by auto\n  qed auto\nqed simp\n\nsublocale intruder_model arity public Ana\napply unfold_locales\nby (metis assm1, metis assm2, rule Ana.simps, metis assm4, metis assm5)\n\nadhoc_overloading INTRUDER_SYNTH intruder_synth\nadhoc_overloading INTRUDER_DEDUCT intruder_deduct\n\nlemma assm6: \"arity c = 0 \\<Longrightarrow> \\<exists>a. \\<forall>X. \\<Gamma> (Fun c X) = TAtom a\" by (cases c) auto\n\nlemma assm7: \"0 < arity f \\<Longrightarrow> \\<Gamma> (Fun f T) = TComp f (map \\<Gamma> T)\" by auto\n\nlemma assm8: \"infinite {c. \\<Gamma> (Fun c []::('fun,'atom,'sets,'lbl) prot_term) = TAtom a \\<and> public c}\"\n  (is \"?P a\")\nproof -\n  let ?T = \"\\<lambda>f. (range f)::('fun,'atom,'sets,'lbl) prot_fun set\"\n  let ?A = \"\\<lambda>f. \\<forall>x::nat \\<in> UNIV. \\<forall>y::nat \\<in> UNIV. (f x = f y) = (x = y)\"\n  let ?B = \"\\<lambda>f. \\<forall>x::nat \\<in> UNIV. f x \\<in> ?T f\"\n  let ?C = \"\\<lambda>f. \\<forall>y::('fun,'atom,'sets,'lbl) prot_fun \\<in> ?T f. \\<exists>x \\<in> UNIV. y = f x\"\n  let ?D = \"\\<lambda>f b. ?T f \\<subseteq> {c. \\<Gamma> (Fun c []::('fun,'atom,'sets,'lbl) prot_term) = TAtom b \\<and> public c}\"\n\n  have sub_lmm: \"?P b\" when \"?A f\" \"?C f\" \"?C f\" \"?D f b\" for b f\n  proof -\n    have \"\\<exists>g::nat \\<Rightarrow> ('fun,'atom,'sets,'lbl) prot_fun. bij_betw g UNIV (?T f)\"\n      using bij_betwI'[of UNIV f \"?T f\"] that(1,2,3) by blast\n    hence \"infinite (?T f)\" by (metis nat_not_finite bij_betw_finite)\n    thus ?thesis using infinite_super[OF that(4)] by blast\n  qed\n\n  show ?thesis\n  proof (cases a)\n    case (Atom b) thus ?thesis using sub_lmm[of \"PubConst (Atom b)\" a] by force\n  next\n    case Value thus ?thesis using sub_lmm[of \"PubConst Value\" a] by force\n  next\n    case SetType thus ?thesis using sub_lmm[of \"PubConst SetType\" a] by fastforce\n  next\n    case AttackType thus ?thesis using sub_lmm[of \"PubConst AttackType\" a] by fastforce\n  next\n    case Bottom thus ?thesis using sub_lmm[of \"PubConst Bottom\" a] by fastforce\n  next\n    case OccursSecType thus ?thesis using sub_lmm[of \"PubConst OccursSecType\" a] by fastforce\n  next\n    case AbsValue thus ?thesis using sub_lmm[of \"PubConst AbsValue\" a] by force\n  qed\nqed\n\nlemma assm9: \"TComp f T \\<sqsubseteq> \\<Gamma> t \\<Longrightarrow> arity f > 0\"\nproof (induction t rule: term.induct)\n  case (Var x)\n  hence \"\\<Gamma> (Var x) \\<noteq> TAtom Bottom\" by force\n  hence \"\\<forall>t \\<in> subterms (fst x). case t of\n            TComp f T \\<Rightarrow> arity f > 0 \\<and> arity f = length T\n          | _ \\<Rightarrow> True\"\n    using Var \\<Gamma>.simps(1)[of x] unfolding \\<Gamma>\\<^sub>v_def by meson\n  thus ?case using Var by (fastforce simp add: \\<Gamma>\\<^sub>v_def)\nnext\n  case (Fun g S)\n  have \"arity g \\<noteq> 0\" using Fun.prems Var_subtermeq assm6 by force\n  thus ?case using Fun by (cases \"TComp f T = TComp g (map \\<Gamma> S)\") auto\nqed\n\nlemma assm10: \"wf\\<^sub>t\\<^sub>r\\<^sub>m (\\<Gamma> (Var x))\"\nunfolding wf\\<^sub>t\\<^sub>r\\<^sub>m_def by (auto simp add: \\<Gamma>\\<^sub>v_def)\n\nlemma assm11: \"arity f > 0 \\<Longrightarrow> public f\" using public\\<^sub>f_assm by (cases f) auto\n\nlemma assm12: \"\\<Gamma> (Var (\\<tau>, n)) = \\<Gamma> (Var (\\<tau>, m))\" by (simp add: \\<Gamma>\\<^sub>v_def)\n\nlemma assm13: \"arity c = 0 \\<Longrightarrow> Ana (Fun c T) = ([],[])\" by (cases c) simp_all\n\nlemma assm14:\n  assumes \"Ana (Fun f T) = (K,M)\"\n  shows \"Ana (Fun f T \\<cdot> \\<delta>) = (K \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta>, M \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta>)\"\nproof -\n  show ?thesis\n  proof (cases \"(K, M) = ([],[])\")\n    case True\n    { fix g assume f: \"f = Fu g\"\n      obtain K' M' where \"Ana\\<^sub>f g = (K',M')\" by moura\n      hence ?thesis using assms f True by auto\n    } thus ?thesis using True assms by (cases f) auto\n  next\n    case False\n    then obtain g where **: \"f = Fu g\" using assms by (cases f) auto\n    obtain K' M' where *: \"Ana\\<^sub>f g = (K',M')\" by moura\n    have ***: \"K = K' \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t (!) T\" \"M = map ((!) T) M'\" \"arity\\<^sub>f g = length T\"\n              \"\\<forall>i \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set K') \\<union> set M'. i < arity\\<^sub>f g\"\n      using Ana_Fu_cases(1)[OF assms ** *] False Ana\\<^sub>f_assm2_alt[OF *]\n      by (meson prod.inject)+\n    have ****: \"\\<forall>i\\<in>fv\\<^sub>s\\<^sub>e\\<^sub>t (set K'). i < length T\" \"\\<forall>i\\<in>set M'. i < length T\" using ***(3,4) by auto\n    have \"K \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta> = K' \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t (!) (map (\\<lambda>t. t \\<cdot> \\<delta>) T)\"\n         \"M \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta> = map ((!) (map (\\<lambda>t. t \\<cdot> \\<delta>) T)) M'\"\n      using subst_idx_map[OF ****(2), of \\<delta>]\n            subst_idx_map'[OF ****(1), of \\<delta>]\n            ***(1,2)\n      by auto\n    thus ?thesis using assms * ** ***(3) by auto\n  qed\nqed\n\nsublocale labeled_stateful_typing' arity public Ana \\<Gamma> Pair label_witness1 label_witness2\n  apply unfold_locales\n  subgoal by (metis assm6)\n  subgoal by (metis assm7)\n  subgoal by (metis assm9)\n  subgoal by (rule assm10)\n  subgoal by (metis assm12)\n  subgoal by (metis assm13)\n  subgoal by (metis assm14)\n  subgoal by (rule label_witness_assm)\n  subgoal by (rule arity.simps(5))\n  subgoal by (metis assm14)\n  subgoal by (metis assm8)\n  subgoal by (metis assm11)\n  done\n\n\nsubsection \\<open>The Protocol Transition System, Defined in Terms of the Reachable Constraints\\<close>\ndefinition transaction_decl_subst where\n  \"transaction_decl_subst (\\<xi>::('fun,'atom,'sets,'lbl) prot_subst) T \\<equiv>\n    subst_domain \\<xi> = fst ` set (transaction_decl T ()) \\<and>\n    (\\<forall>(x,cs) \\<in> set (transaction_decl T ()). \\<exists>c \\<in> cs.\n      \\<xi> x = Fun (Fu c) [] \\<and>\n      arity (Fu c::('fun,'atom,'sets,'lbl) prot_fun) = 0) \\<and>\n    wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<xi>\"\n\ndefinition transaction_fresh_subst where\n  \"transaction_fresh_subst \\<sigma> T \\<A> \\<equiv>\n    subst_domain \\<sigma> = set (transaction_fresh T) \\<and>\n    (\\<forall>t \\<in> subst_range \\<sigma>. \\<exists>c. t = Fun c [] \\<and> \\<not>public c \\<and> arity c = 0) \\<and>\n    (\\<forall>t \\<in> subst_range \\<sigma>. t \\<notin> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)) \\<and>\n    (\\<forall>t \\<in> subst_range \\<sigma>. t \\<notin> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms_transaction T)) \\<and>\n    wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma> \\<and> inj_on \\<sigma> (subst_domain \\<sigma>)\"\n\n(* NB: We need the protocol P as a parameter for this definition---even though we will only apply \\<alpha>\n       to a single transaction T of P---because we have to ensure that \\<alpha>(fv(T)) is disjoint from\n       the bound variables of P and \\<A>. *)\ndefinition transaction_renaming_subst where\n  \"transaction_renaming_subst \\<alpha> P \\<A> \\<equiv>\n    \\<exists>n \\<ge> max_var_set (\\<Union>(vars_transaction ` set P) \\<union> vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>). \\<alpha> = var_rename n\"\n\ndefinition (in intruder_model) constraint_model where\n  \"constraint_model \\<I> \\<A> \\<equiv> \n    constr_sem_stateful \\<I> (unlabel \\<A>) \\<and>\n    interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I> \\<and>\n    wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<I>)\"\n\ndefinition (in typed_model) welltyped_constraint_model where\n  \"welltyped_constraint_model \\<I> \\<A> \\<equiv>  wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I> \\<and> constraint_model \\<I> \\<A>\"\n\ntext \\<open>\n  The set of symbolic constraints reachable in any symbolic run of the protocol \\<open>P\\<close>.\n  \n  \\<open>\\<xi>\\<close> instantiates the \"declared variables\" of transaction \\<open>T\\<close> with ground terms.\n  \\<open>\\<sigma>\\<close> instantiates the fresh variables of transaction \\<open>T\\<close> with fresh terms.\n  \\<open>\\<alpha>\\<close> is a variable-renaming whose range consists of fresh variables.\n\\<close>\ninductive_set reachable_constraints::\n  \"('fun,'atom,'sets,'lbl) prot \\<Rightarrow> ('fun,'atom,'sets,'lbl) prot_constr set\"\n  for P::\"('fun,'atom,'sets,'lbl) prot\"\nwhere\n  init[simp]:\n  \"[] \\<in> reachable_constraints P\"\n| step:\n  \"\\<lbrakk>\\<A> \\<in> reachable_constraints P;\n    T \\<in> set P;\n    transaction_decl_subst \\<xi> T;\n    transaction_fresh_subst \\<sigma> T \\<A>;\n    transaction_renaming_subst \\<alpha> P \\<A>\n   \\<rbrakk> \\<Longrightarrow> \\<A>@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) \\<in> reachable_constraints P\"\n\n\nsubsection \\<open>Minor Lemmata\\<close>\nlemma \\<Gamma>\\<^sub>v_TAtom[simp]: \"\\<Gamma>\\<^sub>v (TAtom a, n) = TAtom a\"\nunfolding \\<Gamma>\\<^sub>v_def by simp\n\nlemma \\<Gamma>\\<^sub>v_TAtom':\n  assumes \"a \\<noteq> Bottom\"\n  shows \"\\<Gamma>\\<^sub>v (\\<tau>, n) = TAtom a \\<longleftrightarrow> \\<tau> = TAtom a\"\nproof\n  assume \"\\<Gamma>\\<^sub>v (\\<tau>, n) = TAtom a\"\n  thus \"\\<tau> = TAtom a\" by (metis (no_types, lifting) assms \\<Gamma>\\<^sub>v_def fst_conv term.inject(1)) \nqed simp\n\nlemma \\<Gamma>\\<^sub>v_TAtom_inv:\n  \"\\<Gamma>\\<^sub>v x = TAtom (Atom a) \\<Longrightarrow> \\<exists>m. x = (TAtom (Atom a), m)\"\n  \"\\<Gamma>\\<^sub>v x = TAtom Value \\<Longrightarrow> \\<exists>m. x = (TAtom Value, m)\"\n  \"\\<Gamma>\\<^sub>v x = TAtom SetType \\<Longrightarrow> \\<exists>m. x = (TAtom SetType, m)\"\n  \"\\<Gamma>\\<^sub>v x = TAtom AttackType \\<Longrightarrow> \\<exists>m. x = (TAtom AttackType, m)\"\n  \"\\<Gamma>\\<^sub>v x = TAtom OccursSecType \\<Longrightarrow> \\<exists>m. x = (TAtom OccursSecType, m)\"\nby (metis \\<Gamma>\\<^sub>v_TAtom' surj_pair prot_atom.distinct(7),\n    metis \\<Gamma>\\<^sub>v_TAtom' surj_pair prot_atom.distinct(18),\n    metis \\<Gamma>\\<^sub>v_TAtom' surj_pair prot_atom.distinct(26),\n    metis \\<Gamma>\\<^sub>v_TAtom' surj_pair prot_atom.distinct(32),\n    metis \\<Gamma>\\<^sub>v_TAtom' surj_pair prot_atom.distinct(38))\n\nlemma \\<Gamma>\\<^sub>v_TAtom'':\n  \"(fst x = TAtom (Atom a)) = (\\<Gamma>\\<^sub>v x = TAtom (Atom a))\" (is \"?A = ?A'\")\n  \"(fst x = TAtom Value) = (\\<Gamma>\\<^sub>v x = TAtom Value)\" (is \"?B = ?B'\")\n  \"(fst x = TAtom SetType) = (\\<Gamma>\\<^sub>v x = TAtom SetType)\" (is \"?C = ?C'\")\n  \"(fst x = TAtom AttackType) = (\\<Gamma>\\<^sub>v x = TAtom AttackType)\" (is \"?D = ?D'\")\n  \"(fst x = TAtom OccursSecType) = (\\<Gamma>\\<^sub>v x = TAtom OccursSecType)\" (is \"?E = ?E'\")\nproof -\n  have 1: \"?A \\<Longrightarrow> ?A'\" \"?B \\<Longrightarrow> ?B'\" \"?C \\<Longrightarrow> ?C'\" \"?D \\<Longrightarrow> ?D'\" \"?E \\<Longrightarrow> ?E'\"\n    by (metis \\<Gamma>\\<^sub>v_TAtom prod.collapse)+\n\n  have 2: \"?A' \\<Longrightarrow> ?A\" \"?B' \\<Longrightarrow> ?B\" \"?C' \\<Longrightarrow> ?C\" \"?D' \\<Longrightarrow> ?D\" \"?E' \\<Longrightarrow> ?E\"\n    using \\<Gamma>\\<^sub>v_TAtom \\<Gamma>\\<^sub>v_TAtom_inv(1) apply fastforce\n    using \\<Gamma>\\<^sub>v_TAtom \\<Gamma>\\<^sub>v_TAtom_inv(2) apply fastforce\n    using \\<Gamma>\\<^sub>v_TAtom \\<Gamma>\\<^sub>v_TAtom_inv(3) apply fastforce\n    using \\<Gamma>\\<^sub>v_TAtom \\<Gamma>\\<^sub>v_TAtom_inv(4) apply fastforce\n    using \\<Gamma>\\<^sub>v_TAtom \\<Gamma>\\<^sub>v_TAtom_inv(5) by fastforce\n\n  show \"?A = ?A'\" \"?B = ?B'\" \"?C = ?C'\" \"?D = ?D'\" \"?E = ?E'\"\n    using 1 2 by metis+\nqed\n\nlemma \\<Gamma>\\<^sub>v_Var_image:\n  \"\\<Gamma>\\<^sub>v ` X = \\<Gamma> ` Var ` X\"\nby force\n\nlemma \\<Gamma>_Fu_const:\n  assumes \"arity\\<^sub>f g = 0\"\n  shows \"\\<exists>a. \\<Gamma> (Fun (Fu g) T) = TAtom (Atom a)\"\nproof -\n  have \"\\<Gamma>\\<^sub>f g \\<noteq> None\" using assms \\<Gamma>\\<^sub>f_assm by blast\n  thus ?thesis using assms by force\nqed\n\nlemma Fun_Value_type_inv:\n  fixes T::\"('fun,'atom,'sets,'lbl) prot_term list\"\n  assumes \"\\<Gamma> (Fun f T) = TAtom Value\"\n  shows \"(\\<exists>n. f = Val n) \\<or> (\\<exists>bs. f = Abs bs) \\<or> (\\<exists>n. f = PubConst Value n)\"\nproof -\n  have *: \"arity f = 0\" by (metis const_type_inv assms) \n  show ?thesis  using assms\n  proof (cases f)\n    case (Fu g)\n    hence \"arity\\<^sub>f g = 0\" using * by simp\n    hence False using Fu \\<Gamma>_Fu_const[of g T] assms by auto\n    thus ?thesis by metis\n  next\n    case (Set s)\n    hence \"arity\\<^sub>s s = 0\" using * by simp\n    hence False using Set assms by auto\n    thus ?thesis by metis\n  qed simp_all\nqed\n\nlemma Ana\\<^sub>f_keys_not_val_terms:\n  assumes \"Ana\\<^sub>f f = (K, T)\"\n    and \"k \\<in> set K\"\n    and \"g \\<in> funs_term k\"\n  shows \"\\<not>is_Val g\"\n    and \"\\<not>is_PubConstValue g\"\n    and \"\\<not>is_Abs g\"\nproof -\n  { assume \"is_Val g\"\n    then obtain n S where *: \"Fun (Val n) S \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (set K)\"\n      using assms(2) funs_term_Fun_subterm[OF assms(3)]\n      by (cases g) auto\n    hence False using Ana\\<^sub>f_assm1_alt[OF assms(1) *] by simp\n  } moreover {\n    assume \"is_PubConstValue g\"\n    then obtain n S where *: \"Fun (PubConst Value n) S \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (set K)\"\n      using assms(2) funs_term_Fun_subterm[OF assms(3)]\n      unfolding is_PubConstValue_def by (cases g) auto\n    hence False using Ana\\<^sub>f_assm1_alt[OF assms(1) *] by simp\n  } moreover {\n    assume \"is_Abs g\"\n    then obtain a S where *: \"Fun (Abs a) S \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (set K)\"\n      using assms(2) funs_term_Fun_subterm[OF assms(3)]\n      by (cases g) auto\n    hence False using Ana\\<^sub>f_assm1_alt[OF assms(1) *] by simp\n  } ultimately show \"\\<not>is_Val g\" \"\\<not>is_PubConstValue g\" \"\\<not>is_Abs g\" by metis+\nqed\n\nlemma Ana\\<^sub>f_keys_not_pairs:\n  assumes \"Ana\\<^sub>f f = (K, T)\"\n    and \"k \\<in> set K\"\n    and \"g \\<in> funs_term k\"\n  shows \"g \\<noteq> Pair\"\nproof\n  assume \"g = Pair\"\n  then obtain S where *: \"Fun Pair S \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (set K)\"\n    using assms(2) funs_term_Fun_subterm[OF assms(3)]\n    by (cases g) auto\n  show False using Ana\\<^sub>f_assm1_alt[OF assms(1) *] by simp\nqed\n\nlemma Ana_Fu_keys_funs_term_subset:\n  fixes K::\"('fun,'atom,'sets,'lbl) prot_term list\"\n  assumes \"Ana (Fun (Fu f) S) = (K, T)\"\n    and \"Ana\\<^sub>f f = (K', T')\"\n  shows \"\\<Union>(funs_term ` set K) \\<subseteq> \\<Union>(funs_term ` set K') \\<union> funs_term (Fun (Fu f) S)\"\nproof -\n  { fix k assume k: \"k \\<in> set K\"\n    then obtain k' where k':\n        \"k' \\<in> set K'\" \"k = k' \\<cdot> (!) S\" \"arity\\<^sub>f f = length S\"\n        \"subterms k' \\<subseteq> subterms\\<^sub>s\\<^sub>e\\<^sub>t (set K')\"\n      using assms Ana_Fu_elim[OF assms(1) _ assms(2)] by fastforce\n\n    have 1: \"funs_term k' \\<subseteq> \\<Union>(funs_term ` set K')\" using k'(1) by auto\n\n    have \"i < length S\" when \"i \\<in> fv k'\" for i\n      using that Ana\\<^sub>f_assm2_alt[OF assms(2), of i] k'(1,3)\n      by auto\n    hence 2: \"funs_term (S ! i) \\<subseteq> funs_term (Fun (Fu f) S)\" when \"i \\<in> fv k'\" for i\n      using that by force\n  \n    have \"funs_term k \\<subseteq> \\<Union>(funs_term ` set K') \\<union> funs_term (Fun (Fu f) S)\"\n      using funs_term_subst[of k' \"(!) S\"] k'(2) 1 2 by fast\n  } thus ?thesis by blast\nqed\n\nlemma Ana_Fu_keys_not_pubval_terms:\n  fixes k::\"('fun,'atom,'sets,'lbl) prot_term\"\n  assumes \"Ana (Fun (Fu f) S) = (K, T)\"\n    and \"Ana\\<^sub>f f = (K', T')\"\n    and \"k \\<in> set K\"\n    and \"\\<forall>g \\<in> funs_term (Fun (Fu f) S). \\<not>is_PubConstValue g\"\n  shows \"\\<forall>g \\<in> funs_term k. \\<not>is_PubConstValue g\"\nusing assms(3,4) Ana\\<^sub>f_keys_not_val_terms(1,2)[OF assms(2)]\n      Ana_Fu_keys_funs_term_subset[OF assms(1,2)]\nby blast\n\nlemma Ana_Fu_keys_not_abs_terms:\n  fixes k::\"('fun,'atom,'sets,'lbl) prot_term\"\n  assumes \"Ana (Fun (Fu f) S) = (K, T)\"\n    and \"Ana\\<^sub>f f = (K', T')\"\n    and \"k \\<in> set K\"\n    and \"\\<forall>g \\<in> funs_term (Fun (Fu f) S). \\<not>is_Abs g\"\n  shows \"\\<forall>g \\<in> funs_term k. \\<not>is_Abs g\"\nusing assms(3,4) Ana\\<^sub>f_keys_not_val_terms(3)[OF assms(2)]\n      Ana_Fu_keys_funs_term_subset[OF assms(1,2)]\nby blast\n\nlemma Ana_Fu_keys_not_pairs:\n  fixes k::\"('fun,'atom,'sets,'lbl) prot_term\"\n  assumes \"Ana (Fun (Fu f) S) = (K, T)\"\n    and \"Ana\\<^sub>f f = (K', T')\"\n    and \"k \\<in> set K\"\n    and \"\\<forall>g \\<in> funs_term (Fun (Fu f) S). g \\<noteq> Pair\"\n  shows \"\\<forall>g \\<in> funs_term k. g \\<noteq> Pair\"\nusing assms(3,4) Ana\\<^sub>f_keys_not_pairs[OF assms(2)]\n      Ana_Fu_keys_funs_term_subset[OF assms(1,2)]\nby blast\n\nlemma Ana_Fu_keys_length_eq:\n  assumes \"length T = length S\"\n  shows \"length (fst (Ana (Fun (Fu f) T))) = length (fst (Ana (Fun (Fu f) S)))\"\nproof (cases \"arity\\<^sub>f f = length T \\<and> arity\\<^sub>f f > 0\")\n  case True thus ?thesis using assms by (cases \"Ana\\<^sub>f f\") auto\nnext\n  case False thus ?thesis using assms by force\nqed\n\nlemma deduct_occurs_in_ik:\n  fixes t::\"('fun,'atom,'sets,'lbl) prot_term\"\n  assumes t: \"M \\<turnstile> occurs t\"\n    and M: \"\\<forall>s \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t M. OccursFact \\<notin> \\<Union>(funs_term ` set (snd (Ana s)))\"\n           \"\\<forall>s \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t M. OccursSec \\<notin> \\<Union>(funs_term ` set (snd (Ana s)))\"\n           \"Fun OccursSec [] \\<notin> M\"\n  shows \"occurs t \\<in> M\"\nusing private_fun_deduct_in_ik''[of M OccursFact \"[Fun OccursSec [], t]\" OccursSec] t M \nby fastforce\n\nlemma constraint_model_prefix:\n  assumes \"constraint_model I (A@B)\"\n  shows \"constraint_model I A\"\nby (metis assms strand_sem_append_stateful unlabel_append constraint_model_def)\n\nlemma welltyped_constraint_model_prefix:\n  assumes \"welltyped_constraint_model I (A@B)\"\n  shows \"welltyped_constraint_model I A\"\nby (metis assms constraint_model_prefix welltyped_constraint_model_def)\n\nlemma welltyped_constraint_model_deduct_append:\n  assumes \"welltyped_constraint_model I A\"\n    and \"ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I \\<turnstile> s \\<cdot> I\"\n  shows \"welltyped_constraint_model I (A@[(l,send\\<langle>[s]\\<rangle>)])\"\nusing assms strand_sem_append_stateful[of \"{}\" \"{}\" \"unlabel A\" _ I]\nunfolding welltyped_constraint_model_def constraint_model_def by simp\n\nlemma welltyped_constraint_model_deduct_split:\n  assumes \"welltyped_constraint_model I (A@[(l,send\\<langle>[s]\\<rangle>)])\"\n  shows \"welltyped_constraint_model I A\"\n    and \"ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I \\<turnstile> s \\<cdot> I\"\nusing assms strand_sem_append_stateful[of \"{}\" \"{}\" \"unlabel A\" _ I]\nunfolding welltyped_constraint_model_def constraint_model_def by simp_all\n\nlemma welltyped_constraint_model_deduct_iff:\n  \"welltyped_constraint_model I (A@[(l,send\\<langle>[s]\\<rangle>)]) \\<longleftrightarrow>\n    welltyped_constraint_model I A \\<and> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I \\<turnstile> s \\<cdot> I\"\nby (metis welltyped_constraint_model_deduct_append welltyped_constraint_model_deduct_split)  \n\nlemma constraint_model_Val_is_Value_term:\n  assumes \"welltyped_constraint_model I A\"\n    and \"t \\<cdot> I = Fun (Val n) []\"\n  shows \"t = Fun (Val n) [] \\<or> (\\<exists>m. t = Var (TAtom Value, m))\"\nproof -\n  have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t I\" using assms(1) unfolding welltyped_constraint_model_def by simp\n  moreover have \"\\<Gamma> (Fun (Val n) []) = TAtom Value\" by auto\n  ultimately have *: \"\\<Gamma> t = TAtom Value\" by (metis (no_types) assms(2) wt_subst_trm'')\n\n  show ?thesis\n  proof (cases t)\n    case (Var x)\n    obtain \\<tau> m where x: \"x = (\\<tau>, m)\" by (metis surj_pair)\n    have \"\\<Gamma>\\<^sub>v x = TAtom Value\" using * Var by auto\n    hence \"\\<tau> = TAtom Value\" using x \\<Gamma>\\<^sub>v_TAtom'[of Value \\<tau> m] by simp\n    thus ?thesis using x Var by metis\n  next\n    case (Fun f T) thus ?thesis using assms(2) by auto\n  qed\nqed\n\nlemma wellformed_transaction_sem_receives:\n  fixes T::\"('fun,'atom,'sets,'lbl) prot_transaction\"\n  assumes T_valid: \"wellformed_transaction T\"\n    and \\<I>: \"strand_sem_stateful IK DB (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))) \\<I>\"\n    and s: \"receive\\<langle>ts\\<rangle> \\<in> set (unlabel (transaction_receive T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n  shows \"\\<forall>t \\<in> set ts. IK \\<turnstile> t \\<cdot> \\<I>\"\nproof -\n  let ?R = \"unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n  let ?S = \"\\<lambda>A. unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n  let ?S' = \"?S (transaction_receive T)\"\n\n  obtain l B s where B:\n      \"(l,send\\<langle>ts\\<rangle>) = dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p ((l,s) \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\"\n      \"prefix ((B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)@[(l,s) \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>]) (transaction_receive T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n    using s dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_steps_iff(2)[of ts \"transaction_receive T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>\"]\n          dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_in_set_prefix_obtain_subst[of \"send\\<langle>ts\\<rangle>\" \"transaction_receive T\" \\<theta>]\n    by blast\n\n  have 1: \"unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t ((B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)@[(l,s) \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>])) = unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))@[send\\<langle>ts\\<rangle>]\"\n    using B(1) unlabel_append dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_subst singleton_lst_proj(4)\n          dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_subst_snoc subst_lsst_append subst_lsst_singleton\n    by (metis (no_types, lifting) subst_apply_labeled_stateful_strand_step.simps)\n\n  have \"strand_sem_stateful IK DB ?S' \\<I>\"\n    using \\<I> strand_sem_append_stateful[of IK DB _ _ \\<I>] transaction_dual_subst_unfold[of T \\<theta>]\n    by fastforce\n  hence \"strand_sem_stateful IK DB (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))@[send\\<langle>ts\\<rangle>]) \\<I>\"\n    using B 1 unfolding prefix_def unlabel_def\n    by (metis dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_def map_append strand_sem_append_stateful) \n  hence t_deduct: \"\\<forall>t \\<in> set ts. IK \\<union> (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<turnstile> t \\<cdot> \\<I>\"\n    using strand_sem_append_stateful[of IK DB \"unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\" \"[send\\<langle>ts\\<rangle>]\" \\<I>]\n    by simp\n\n  have \"\\<forall>s \\<in> set (unlabel (transaction_receive T)). \\<exists>t. s = receive\\<langle>t\\<rangle>\"\n    using T_valid wellformed_transaction_unlabel_cases(1)[OF T_valid] by auto\n  moreover { fix A::\"('fun,'atom,'sets,'lbl) prot_strand\" and \\<theta>\n    assume \"\\<forall>s \\<in> set (unlabel A). \\<exists>t. s = receive\\<langle>t\\<rangle>\"\n    hence \"\\<forall>s \\<in> set (unlabel (A \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)). \\<exists>t. s = receive\\<langle>t\\<rangle>\"\n    proof (induction A)\n      case (Cons a A) thus ?case using subst_lsst_cons[of a A \\<theta>] by (cases a) auto\n    qed simp\n    hence \"\\<forall>s \\<in> set (unlabel (A \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)). \\<exists>t. s = receive\\<langle>t\\<rangle>\"\n      by (simp add: list.pred_set is_Receive_def)\n    hence \"\\<forall>s \\<in> set (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))). \\<exists>t. s = send\\<langle>t\\<rangle>\"\n      by (metis dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_memberD dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_inv(2) unlabel_in unlabel_mem_has_label)\n  }\n  ultimately have \"\\<forall>s \\<in> set ?R. \\<exists>ts. s = send\\<langle>ts\\<rangle>\" by simp\n  hence \"ik\\<^sub>s\\<^sub>s\\<^sub>t ?R = {}\" unfolding unlabel_def ik\\<^sub>s\\<^sub>s\\<^sub>t_def by fast\n  hence \"ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)) = {}\"\n    using B(2) 1 ik\\<^sub>s\\<^sub>s\\<^sub>t_append dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_append\n    by (metis (no_types, lifting) Un_empty map_append prefix_def unlabel_def) \n  thus ?thesis using t_deduct by simp\nqed\n\nlemma wellformed_transaction_sem_pos_checks:\n  assumes T_valid: \"wellformed_transaction T\"\n    and \\<I>: \"strand_sem_stateful IK DB (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))) \\<I>\"\n    and \"\\<langle>ac: t \\<in> u\\<rangle> \\<in> set (unlabel (transaction_checks T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n  shows \"(t \\<cdot> \\<I>, u \\<cdot> \\<I>) \\<in> DB\"\nproof -\n  let ?s = \"\\<langle>ac: t \\<in> u\\<rangle>\"\n  let ?R = \"transaction_receive T@transaction_checks T\"\n  let ?R' = \"unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (?R \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n  let ?S = \"\\<lambda>A. unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n  let ?S' = \"?S (transaction_receive T)@?S (transaction_checks T)\"\n  let ?P = \"\\<lambda>a. is_Receive a \\<or> is_Check_or_Assignment a\"\n  let ?Q = \"\\<lambda>a. is_Send a \\<or> is_Check_or_Assignment a\"\n\n  have s: \"?s \\<in> set (unlabel (?R \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n    using assms(3) subst_lsst_append[of \"transaction_receive T\"]\n          unlabel_append[of \"transaction_receive T\"]\n    by auto\n\n  obtain l B s where B:\n      \"(l,?s) = dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p ((l,s) \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\"\n      \"prefix ((B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)@[(l,s) \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>]) (?R \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n    using s dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_steps_iff(6)[of _ t u]\n          dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_in_set_prefix_obtain_subst[of ?s ?R \\<theta>] \n    by blast\n\n  have 1: \"unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t ((B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)@[(l,s) \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>])) = unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))@[?s]\"\n    using B(1) unlabel_append dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_subst singleton_lst_proj(4)\n          dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_subst_snoc subst_lsst_append subst_lsst_singleton\n    by (metis (no_types, lifting) subst_apply_labeled_stateful_strand_step.simps )\n\n  have \"strand_sem_stateful IK DB ?S' \\<I>\"\n    using \\<I> strand_sem_append_stateful[of IK DB _ _ \\<I>] transaction_dual_subst_unfold[of T \\<theta>]\n    by fastforce\n  hence \"strand_sem_stateful IK DB (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))@[?s]) \\<I>\"\n    using B 1 strand_sem_append_stateful subst_lsst_append\n    unfolding prefix_def unlabel_def dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_def\n    by (metis (no_types) map_append)\n  hence in_db: \"(t \\<cdot> \\<I>, u \\<cdot> \\<I>) \\<in> dbupd\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))) \\<I> DB\"\n    using strand_sem_append_stateful[of IK DB \"unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\" \"[?s]\" \\<I>]\n    by simp\n  \n  have \"\\<forall>a \\<in> set (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))). ?Q a\"\n  proof\n    fix a assume a: \"a \\<in> set (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)))\"\n\n    have \"?P a\" when a: \"a \\<in> set (unlabel ?R)\" for a\n      using a wellformed_transaction_unlabel_cases(1,2)[OF T_valid]\n      unfolding unlabel_def by fastforce\n    hence \"?P a\" when a: \"a \\<in> set (unlabel (?R \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\" for a\n      using a stateful_strand_step_cases_subst(2,11)[of _ \\<theta>] subst_lsst_unlabel[of ?R \\<theta>]\n      unfolding subst_apply_stateful_strand_def by auto\n    hence B_P: \"\\<forall>a \\<in> set (unlabel (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)). ?P a\"\n      using unlabel_mono[OF set_mono_prefix[OF append_prefixD[OF B(2)]]]\n      by blast\n\n    obtain l where \"(l,a) \\<in> set (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n      using a by (meson unlabel_mem_has_label)\n    then obtain b where b: \"(l,b) \\<in> set (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\" \"dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (l,b) = (l,a)\"\n      using dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_memberD by blast\n    hence \"?P b\" using B_P unfolding unlabel_def by fastforce\n    thus \"?Q a\" using dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_inv[OF b(2)] by (cases b) auto\n  qed\n  hence \"\\<forall>a \\<in> set (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))). \\<not>is_Insert a \\<and> \\<not>is_Delete a\" by fastforce\n  thus ?thesis using dbupd\\<^sub>s\\<^sub>s\\<^sub>t_no_upd[of \"unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\" \\<I> DB] in_db by simp\nqed\n\nlemma wellformed_transaction_sem_neg_checks:\n  assumes T_valid: \"wellformed_transaction T\"\n    and \\<I>: \"strand_sem_stateful IK DB (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))) \\<I>\"\n    and \"NegChecks X [] [(t,u)] \\<in> set (unlabel (transaction_checks T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n  shows \"\\<forall>\\<delta>. subst_domain \\<delta> = set X \\<and> ground (subst_range \\<delta>) \\<longrightarrow> (t \\<cdot> \\<delta> \\<cdot> \\<I>, u \\<cdot> \\<delta> \\<cdot> \\<I>) \\<notin> DB\" (is ?A)\n    and \"X = [] \\<Longrightarrow> (t \\<cdot> \\<I>, u \\<cdot> \\<I>) \\<notin> DB\" (is \"?B \\<Longrightarrow> ?B'\")\nproof -\n  let ?s = \"NegChecks X [] [(t,u)]\"\n  let ?R = \"transaction_receive T@transaction_checks T\"\n  let ?R' = \"unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (?R \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n  let ?S = \"\\<lambda>A. unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n  let ?S' = \"?S (transaction_receive T)@?S (transaction_checks T)\"\n  let ?P = \"\\<lambda>a. is_Receive a \\<or> is_Check_or_Assignment a\"\n  let ?Q = \"\\<lambda>a. is_Send a \\<or> is_Check_or_Assignment a\"\n  let ?U = \"\\<lambda>\\<delta>. subst_domain \\<delta> = set X \\<and> ground (subst_range \\<delta>)\"\n\n  have s: \"?s \\<in> set (unlabel (?R \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n    using assms(3) subst_lsst_append[of \"transaction_receive T\"]\n          unlabel_append[of \"transaction_receive T\"]\n    by auto\n\n  obtain l B s where B:\n      \"(l,?s) = dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p ((l,s) \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\"\n      \"prefix ((B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)@[(l,s) \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>]) (?R \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n    using s dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_steps_iff(7)[of X \"[]\" \"[(t,u)]\"]\n          dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_in_set_prefix_obtain_subst[of ?s ?R \\<theta>]\n    by blast\n\n  have 1: \"unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t ((B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)@[(l,s) \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>])) = unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))@[?s]\"\n    using B(1) unlabel_append dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_subst singleton_lst_proj(4)\n          dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_subst_snoc subst_lsst_append subst_lsst_singleton\n    by (metis (no_types, lifting) subst_apply_labeled_stateful_strand_step.simps)\n\n  have \"strand_sem_stateful IK DB ?S' \\<I>\"\n    using \\<I> strand_sem_append_stateful[of IK DB _ _ \\<I>] transaction_dual_subst_unfold[of T \\<theta>]\n    by fastforce\n  hence \"strand_sem_stateful IK DB (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))@[?s]) \\<I>\"\n    using B 1 strand_sem_append_stateful subst_lsst_append\n    unfolding prefix_def unlabel_def dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_def\n    by (metis (no_types) map_append)\n  hence \"negchecks_model \\<I> (dbupd\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))) \\<I> DB) X [] [(t,u)]\"\n    using strand_sem_append_stateful[of IK DB \"unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\" \"[?s]\" \\<I>]\n    by fastforce\n  hence in_db: \"\\<forall>\\<delta>. ?U \\<delta> \\<longrightarrow> (t \\<cdot> \\<delta> \\<cdot> \\<I>, u \\<cdot> \\<delta> \\<cdot> \\<I>) \\<notin> dbupd\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))) \\<I> DB\"\n    unfolding negchecks_model_def\n    by simp\n\n  have \"\\<forall>a \\<in> set (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))). ?Q a\"\n  proof\n    fix a assume a: \"a \\<in> set (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)))\"\n\n    have \"?P a\" when a: \"a \\<in> set (unlabel ?R)\" for a\n      using a wellformed_transaction_unlabel_cases(1,2,3)[OF T_valid]\n      unfolding unlabel_def by fastforce\n    hence \"?P a\" when a: \"a \\<in> set (unlabel (?R \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\" for a\n      using a stateful_strand_step_cases_subst(2,11)[of _ \\<theta>] subst_lsst_unlabel[of ?R \\<theta>]\n      unfolding subst_apply_stateful_strand_def by auto\n    hence B_P: \"\\<forall>a \\<in> set (unlabel (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)). ?P a\"\n      using unlabel_mono[OF set_mono_prefix[OF append_prefixD[OF B(2)]]]\n      by blast\n\n    obtain l where \"(l,a) \\<in> set (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n      using a by (meson unlabel_mem_has_label)\n    then obtain b where b: \"(l,b) \\<in> set (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\" \"dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (l,b) = (l,a)\"\n      using dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_memberD by blast\n    hence \"?P b\" using B_P unfolding unlabel_def by fastforce\n    thus \"?Q a\" using dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_inv[OF b(2)] by (cases b) auto\n  qed\n  hence \"\\<forall>a \\<in> set (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))). \\<not>is_Insert a \\<and> \\<not>is_Delete a\" by fastforce\n  thus ?A using dbupd\\<^sub>s\\<^sub>s\\<^sub>t_no_upd[of \"unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (B \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\" \\<I> DB] in_db by simp\n  moreover have \"\\<delta> = Var\" \"t \\<cdot> \\<delta> = t\"\n    when \"subst_domain \\<delta> = set []\" for t and \\<delta>::\"('fun, 'atom, 'sets, 'lbl) prot_subst\"\n    using that by auto\n  moreover have \"subst_domain Var = set []\" \"range_vars Var = {}\"\n    by simp_all\n  ultimately show \"?B \\<Longrightarrow> ?B'\" unfolding range_vars_alt_def by metis\nqed\n\nlemma dual_transaction_ik_is_transaction_send'':\n  fixes \\<delta> \\<I>::\"('a,'b,'c,'d) prot_subst\"\n  assumes \"wellformed_transaction T\"\n  shows \"(ik\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>))) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<cdot>\\<^sub>\\<alpha>\\<^sub>s\\<^sub>e\\<^sub>t a =\n         (trms\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (transaction_send T)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) \\<cdot>\\<^sub>\\<alpha>\\<^sub>s\\<^sub>e\\<^sub>t a\" (is \"?A = ?B\")\nusing dual_transaction_ik_is_transaction_send[OF assms]\n      subst_lsst_unlabel[of \"dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T)\" \\<delta>]\n      ik\\<^sub>s\\<^sub>s\\<^sub>t_subst[of \"unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T))\" \\<delta>]\n      dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_subst[of \"transaction_strand T\" \\<delta>]\nby (auto simp add: abs_apply_terms_def)\n\nlemma while_prot_terms_fun_mono:\n  \"mono (\\<lambda>M'. M \\<union> \\<Union>(subterms ` M') \\<union> \\<Union>((set \\<circ> fst \\<circ> Ana) ` M'))\"\nunfolding mono_def by fast\n\nlemma while_prot_terms_SMP_overapprox:\n  fixes M::\"('fun,'atom,'sets,'lbl) prot_terms\"\n  assumes N_supset: \"M \\<union> \\<Union>(subterms ` N) \\<union> \\<Union>((set \\<circ> fst \\<circ> Ana) ` N) \\<subseteq> N\"\n    and Value_vars_only: \"\\<forall>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t N. \\<Gamma>\\<^sub>v x = TAtom Value\"\n  shows \"SMP M \\<subseteq> {a \\<cdot> \\<delta> | a \\<delta>. a \\<in> N \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)}\"\nproof -\n  define f where \"f \\<equiv> \\<lambda>M'. M \\<union> \\<Union>(subterms ` M') \\<union> \\<Union>((set \\<circ> fst \\<circ> Ana) ` M')\"\n  define S where \"S \\<equiv> {a \\<cdot> \\<delta> | a \\<delta>. a \\<in> N \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)}\"\n\n  note 0 = Value_vars_only\n  \n  have \"t \\<in> S\" when \"t \\<in> SMP M\" for t\n  using that\n  proof (induction t rule: SMP.induct)\n    case (MP t)\n    hence \"t \\<in> N\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t Var\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range Var)\" using N_supset by auto\n    hence \"t \\<cdot> Var \\<in> S\" unfolding S_def by blast\n    thus ?case by simp\n  next\n    case (Subterm t t')\n    then obtain \\<delta> a where a: \"a \\<cdot> \\<delta> = t\" \"a \\<in> N\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\"\n      by (auto simp add: S_def)\n    hence \"\\<forall>x \\<in> fv a. \\<exists>\\<tau>. \\<Gamma> (Var x) = TAtom \\<tau>\" using 0 by auto\n    hence *: \"\\<forall>x \\<in> fv a. (\\<exists>f. \\<delta> x = Fun f []) \\<or> (\\<exists>y. \\<delta> x = Var y)\"\n      using a(3) TAtom_term_cases[OF wf_trm_subst_rangeD[OF a(4)]]\n      by (metis wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def)\n    obtain b where b: \"b \\<cdot> \\<delta> = t'\" \"b \\<in> subterms a\"\n      using subterms_subst_subterm[OF *, of t'] Subterm.hyps(2) a(1)\n      by fast\n    hence \"b \\<in> N\" using N_supset a(2) by blast\n    thus ?case using a b(1) unfolding S_def by blast\n  next\n    case (Substitution t \\<theta>)\n    then obtain \\<delta> a where a: \"a \\<cdot> \\<delta> = t\" \"a \\<in> N\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\"\n      by (auto simp add: S_def)\n    have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t (\\<delta> \\<circ>\\<^sub>s \\<theta>)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range (\\<delta> \\<circ>\\<^sub>s \\<theta>))\"\n      by (fact wt_subst_compose[OF a(3) Substitution.hyps(2)],\n          fact wf_trms_subst_compose[OF a(4) Substitution.hyps(3)])\n    moreover have \"t \\<cdot> \\<theta> = a \\<cdot> \\<delta> \\<circ>\\<^sub>s \\<theta>\" using a(1) subst_subst_compose[of a \\<delta> \\<theta>] by simp\n    ultimately show ?case using a(2) unfolding S_def by blast\n  next\n    case (Ana t K T k)\n    then obtain \\<delta> a where a: \"a \\<cdot> \\<delta> = t\" \"a \\<in> N\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\"\n      by (auto simp add: S_def)\n    obtain Ka Ta where a': \"Ana a = (Ka,Ta)\" by moura\n    have *: \"K = Ka \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta>\"\n    proof (cases a)\n      case (Var x)\n      then obtain g U where gU: \"t = Fun g U\"\n        using a(1) Ana.hyps(2,3) Ana_var\n        by (cases t) simp_all\n      have \"\\<Gamma> (Var x) = TAtom Value\" using Var a(2) 0 by auto\n      hence \"\\<Gamma> (Fun g U) = TAtom Value\"\n        using a(1,3) Var gU wt_subst_trm''[OF a(3), of a]\n        by argo\n      thus ?thesis using gU Fun_Value_type_inv Ana.hyps(2,3) by fastforce  \n    next\n      case (Fun g U) thus ?thesis using a(1) a' Ana.hyps(2) Ana_subst'[of g U] by simp\n    qed\n    then obtain ka where ka: \"k = ka \\<cdot> \\<delta>\" \"ka \\<in> set Ka\" using Ana.hyps(3) by auto\n    have \"ka \\<in> set ((fst \\<circ> Ana) a)\" using ka(2) a' by simp\n    hence \"ka \\<in> N\" using a(2) N_supset by auto\n    thus ?case using ka a(3,4) unfolding S_def by blast\n  qed\n  thus ?thesis unfolding S_def by blast\nqed\n\n\nsubsection \\<open>Admissible Transactions\\<close>\ndefinition admissible_transaction_checks where\n  \"admissible_transaction_checks T \\<equiv>\n    \\<forall>x \\<in> set (unlabel (transaction_checks T)).\n      (is_InSet x \\<longrightarrow>\n          is_Var (the_elem_term x) \\<and> is_Fun_Set (the_set_term x) \\<and>\n          fst (the_Var (the_elem_term x)) = TAtom Value) \\<and>\n      (is_NegChecks x \\<longrightarrow>\n          bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x = [] \\<and>\n          ((the_eqs x = [] \\<and> length (the_ins x) = 1) \\<or>\n           (the_ins x = [] \\<and> length (the_eqs x) = 1))) \\<and>\n      (is_NegChecks x \\<and> the_eqs x = [] \\<longrightarrow> (let h = hd (the_ins x) in\n          is_Var (fst h) \\<and> is_Fun_Set (snd h) \\<and>\n          fst (the_Var (fst h)) = TAtom Value))\"\n\ndefinition admissible_transaction_updates where\n  \"admissible_transaction_updates T \\<equiv>\n    \\<forall>x \\<in> set (unlabel (transaction_updates T)).\n      is_Update x \\<and> is_Var (the_elem_term x) \\<and> is_Fun_Set (the_set_term x) \\<and>\n      fst (the_Var (the_elem_term x)) = TAtom Value\"\n\ndefinition admissible_transaction_terms where\n  \"admissible_transaction_terms T \\<equiv>\n    wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s' arity (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T)) \\<and>\n    (\\<forall>f \\<in> \\<Union>(funs_term ` trms_transaction T).\n      \\<not>is_Val f \\<and> \\<not>is_Abs f \\<and> \\<not>is_PubConst f \\<and> f \\<noteq> Pair) \\<and>\n    (\\<forall>r \\<in> set (unlabel (transaction_strand T)).\n      (\\<exists>f \\<in> \\<Union>(funs_term ` (trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p r)). is_Attack f) \\<longrightarrow>\n        is_Send r \\<and> length (the_msgs r) = 1 \\<and> is_Fun_Attack (hd (the_msgs r)))\"\n\ndefinition admissible_transaction_occurs_checks where\n  \"admissible_transaction_occurs_checks T \\<equiv> (\n    let occ_in = \\<lambda>x S. occurs (Var x) \\<in> set (the_msgs (hd (unlabel S)));\n        rcvs = transaction_receive T;\n        snds = transaction_send T;\n        frsh = transaction_fresh T;\n        fvs = fv_transaction T\n    in ((\\<exists>x \\<in> fvs - set frsh. fst x = TAtom Value) \\<longrightarrow> (\n          rcvs \\<noteq> [] \\<and> is_Receive (hd (unlabel rcvs)) \\<and>\n          (\\<forall>x \\<in> fvs - set frsh. fst x = TAtom Value \\<longrightarrow> occ_in x rcvs))) \\<and>\n       (frsh \\<noteq> [] \\<longrightarrow> (\n          snds \\<noteq> [] \\<and> is_Send (hd (unlabel snds)) \\<and>\n          (\\<forall>x \\<in> set frsh. occ_in x snds))) \\<and>\n       (\\<forall>t \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t snds.\n          OccursFact \\<in> funs_term t \\<or> OccursSec \\<in> funs_term t \\<longrightarrow>\n            (\\<exists>x \\<in> set (transaction_fresh T). t = occurs (Var x)))\n)\"\n\ndefinition admissible_transaction where\n  \"admissible_transaction T \\<equiv> (\n    wellformed_transaction T \\<and>\n    transaction_decl T () = [] \\<and>\n    list_all (\\<lambda>x. fst x = TAtom Value) (transaction_fresh T) \\<and>\n    (\\<forall>x \\<in> vars_transaction T. is_Var (fst x) \\<and> (the_Var (fst x) = Value)) \\<and>\n    bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T) = {} \\<and>\n    set (transaction_fresh T) \\<subseteq>\n      fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (filter (is_Insert \\<circ> snd) (transaction_updates T)) \\<union> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T) \\<and>\n    (\\<forall>x \\<in> fv_transaction T - set (transaction_fresh T).\n     \\<forall>y \\<in> fv_transaction T - set (transaction_fresh T).\n      x \\<noteq> y \\<longrightarrow> \\<langle>Var x != Var y\\<rangle> \\<in> set (unlabel (transaction_checks T)) \\<or>\n                \\<langle>Var y != Var x\\<rangle> \\<in> set (unlabel (transaction_checks T))) \\<and>\n    fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_updates T) \\<union> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T) - set (transaction_fresh T)\n      \\<subseteq> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T) \\<union> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T) \\<and>\n    (\\<forall>r \\<in> set (unlabel (transaction_checks T)).\n      is_Equality r \\<longrightarrow> fv (the_rhs r) \\<subseteq> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T)) \\<and>\n    fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T) \\<subseteq>\n      fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T) \\<union>\n      fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (filter (\\<lambda>s. is_InSet (snd s) \\<and> the_check (snd s) = Assign) (transaction_checks T)) \\<and>\n    admissible_transaction_checks T \\<and>\n    admissible_transaction_updates T \\<and>\n    admissible_transaction_terms T \\<and>\n    admissible_transaction_occurs_checks T\n)\"\n\nlemma admissible_transactionE:\n  assumes T: \"admissible_transaction T\"\n  shows \"transaction_decl T () = []\" (is ?A)\n    and \"\\<forall>x \\<in> set (transaction_fresh T). \\<Gamma>\\<^sub>v x = TAtom Value\" (is ?B)\n    and \"\\<forall>x \\<in> vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T). \\<Gamma>\\<^sub>v x = TAtom Value\" (is ?C)\n    and \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T) = {}\" (is ?D1)\n    and \"fv_transaction T \\<inter> bvars_transaction T = {}\" (is ?D2)\n    and \"set (transaction_fresh T) \\<subseteq>\n          fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (filter (is_Insert \\<circ> snd) (transaction_updates T)) \\<union> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)\"\n      (is ?E)\n    and \"set (transaction_fresh T) \\<subseteq> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_updates T) \\<union> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)\"\n      (is ?F)\n    and \"\\<forall>x \\<in> fv_transaction T - set (transaction_fresh T).\n         \\<forall>y \\<in> fv_transaction T - set (transaction_fresh T).\n          x \\<noteq> y \\<longrightarrow> \\<langle>Var x != Var y\\<rangle> \\<in> set (unlabel (transaction_checks T)) \\<or>\n                    \\<langle>Var y != Var x\\<rangle> \\<in> set (unlabel (transaction_checks T))\"\n      (is ?G)\n    and \"\\<forall>x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T).\n          x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T) \\<or>\n          (\\<exists>t s. select\\<langle>t,s\\<rangle> \\<in> set (unlabel (transaction_checks T)) \\<and> x \\<in> fv t \\<union> fv s)\"\n      (is ?H)\n    and \"fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_updates T) \\<union> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T) - set (transaction_fresh T) \\<subseteq>\n          fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T) \\<union> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T)\"\n      (is ?I)\n    and \"\\<forall>x \\<in> set (unlabel (transaction_checks T)).\n          is_Equality x \\<longrightarrow> fv (the_rhs x) \\<subseteq> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T)\"\n      (is ?J)\n    and \"set (transaction_fresh T) \\<inter> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T) = {}\" (is ?K1)\n    and \"set (transaction_fresh T) \\<inter> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T) = {}\" (is ?K2)\n    and \"list_all (\\<lambda>x. fst x = Var Value) (transaction_fresh T)\" (is ?K3)\n    and \"\\<forall>x \\<in> vars_transaction T. \\<not>TAtom AttackType \\<sqsubseteq> \\<Gamma>\\<^sub>v x\" (is ?K4)\nproof -\n  show ?A ?D1 ?D2 ?G ?I ?J ?K3\n    using T unfolding admissible_transaction_def\n    by (blast, blast, blast, blast, blast, blast, blast)\n\n  have \"list_all (\\<lambda>x. fst x = Var Value) (transaction_fresh T)\"\n       \"\\<forall>x\\<in>vars_transaction T. is_Var (fst x) \\<and> the_Var (fst x) = Value\"\n    using T unfolding admissible_transaction_def by (blast, blast)\n  thus ?B ?C ?K4 using \\<Gamma>\\<^sub>v_TAtom''(2) unfolding list_all_iff by (blast, force, force)\n\n  show ?E using T unfolding admissible_transaction_def by argo\n  thus ?F unfolding unlabel_def by auto\n\n  show ?K1 ?K2\n    using T unfolding admissible_transaction_def wellformed_transaction_def by (argo, argo)\n\n  let ?selects = \"filter (\\<lambda>s. is_InSet (snd s) \\<and> the_check (snd s) = Assign) (transaction_checks T)\"\n\n  show ?H\n  proof\n    fix x assume \"x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T)\"\n    hence \"x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T) \\<or> x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t ?selects\"\n      using T unfolding admissible_transaction_def by blast\n    thus \"x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T) \\<or>\n          (\\<exists>t s. select\\<langle>t,s\\<rangle> \\<in> set (unlabel (transaction_checks T)) \\<and> x \\<in> fv t \\<union> fv s)\"\n    proof\n      assume \"x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t ?selects\"\n      then obtain r where r: \"x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p r\" \"r \\<in> set (unlabel (transaction_checks T))\"\n                             \"is_InSet r\" \"the_check r = Assign\"\n        unfolding unlabel_def by force\n      thus ?thesis by (cases r) auto\n    qed simp\n  qed\nqed\n\nlemma admissible_transaction_is_wellformed_transaction:\n  assumes \"admissible_transaction T\"\n  shows \"wellformed_transaction T\"\n    and \"admissible_transaction_checks T\"\n    and \"admissible_transaction_updates T\"\n    and \"admissible_transaction_terms T\"\n    and \"admissible_transaction_occurs_checks T\"\nusing assms unfolding admissible_transaction_def by blast+\n\nlemma admissible_transaction_fresh_vars_notin:\n  assumes T: \"admissible_transaction T\"\n    and x: \"x \\<in> set (transaction_fresh T)\"\n  shows \"x \\<notin> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T)\" (is ?A)\n    and \"x \\<notin> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T)\" (is ?B)\n    and \"x \\<notin> vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T)\" (is ?C)\n    and \"x \\<notin> vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T)\" (is ?D)\n    and \"x \\<notin> bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T)\" (is ?E)\n    and \"x \\<notin> bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T)\" (is ?F)\nproof -\n  note T_wf = admissible_transaction_is_wellformed_transaction(1)[OF T]\n\n  have 0:\n      \"set (transaction_fresh T) \\<subseteq> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_updates T) \\<union> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)\"\n      \"set (transaction_fresh T) \\<inter> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T) = {}\"\n      \"set (transaction_fresh T) \\<inter> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T) = {}\"\n      \"fv_transaction T \\<inter> bvars_transaction T = {}\"\n    using admissible_transactionE[OF T] by argo+\n\n  have 1: \"set (transaction_fresh T) \\<inter> bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T) = {}\"\n    using 0(1,4) fv_transaction_unfold[of T] bvars_transaction_unfold[of T] by blast\n\n  have 2:\n      \"vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T) = fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T)\"\n      \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T) = {}\"\n    using bvars_wellformed_transaction_unfold[OF T_wf]\n          vars\\<^sub>s\\<^sub>s\\<^sub>t_is_fv\\<^sub>s\\<^sub>s\\<^sub>t_bvars\\<^sub>s\\<^sub>s\\<^sub>t[of \"unlabel (transaction_receive T)\"]\n    by blast+\n  \n  show ?A ?B ?C ?E ?F using 0 1 2 x by (fast, fast, fast, fast, fast)\n\n  show ?D using 0(3) 1 x vars\\<^sub>s\\<^sub>s\\<^sub>t_is_fv\\<^sub>s\\<^sub>s\\<^sub>t_bvars\\<^sub>s\\<^sub>s\\<^sub>t[of \"unlabel (transaction_checks T)\"] by fast\nqed\n\nlemma admissible_transaction_fv_in_receives_or_selects:\n  assumes T: \"admissible_transaction T\"\n    and x: \"x \\<in> fv_transaction T\" \"x \\<notin> set (transaction_fresh T)\"\n  shows \"x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T) \\<or>\n         (x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T) \\<and>\n          (\\<exists>t s. select\\<langle>t,s\\<rangle> \\<in> set (unlabel (transaction_checks T)) \\<and> x \\<in> fv t \\<union> fv s))\"\nproof -\n  have \"x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T) \\<union> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T) \\<union>\n            fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_updates T) \\<union> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)\"\n    using x(1) fv\\<^sub>s\\<^sub>s\\<^sub>t_append unlabel_append \n    by (metis transaction_strand_def append_assoc)\n  thus ?thesis using x(2) admissible_transactionE(9,10)[OF T] by blast\nqed\n\nlemma admissible_transaction_decl_subst_empty':\n  assumes T: \"transaction_decl T () = []\"\n    and \\<xi>: \"transaction_decl_subst \\<xi> T\"\n  shows \"\\<xi> = Var\"\nproof -\n  have \"subst_domain \\<xi> = {}\"\n    using \\<xi> T unfolding transaction_decl_subst_def by auto\n  thus ?thesis by auto\nqed\n\nlemma admissible_transaction_decl_subst_empty:\n  assumes T: \"admissible_transaction T\"\n    and \\<xi>: \"transaction_decl_subst \\<xi> T\"\n  shows \"\\<xi> = Var\"\nby (rule admissible_transaction_decl_subst_empty'[OF admissible_transactionE(1)[OF T] \\<xi>])\n\nlemma admissible_transaction_no_bvars:\n  assumes \"admissible_transaction T\"\n  shows \"fv_transaction T = vars_transaction T\"\n    and \"bvars_transaction T = {}\"\nusing admissible_transactionE(4)[OF assms]\n      bvars_wellformed_transaction_unfold vars\\<^sub>s\\<^sub>s\\<^sub>t_is_fv\\<^sub>s\\<^sub>s\\<^sub>t_bvars\\<^sub>s\\<^sub>s\\<^sub>t\nby (fast, fast)\n\nlemma admissible_transactions_fv_bvars_disj:\n  assumes \"\\<forall>T \\<in> set P. admissible_transaction T\"\n  shows \"(\\<Union>T \\<in> set P. fv_transaction T) \\<inter> (\\<Union>T \\<in> set P. bvars_transaction T) = {}\"\nusing assms admissible_transaction_no_bvars(2) by fast\n\nlemma admissible_transaction_occurs_fv_types:\n  assumes \"admissible_transaction T\"\n    and \"x \\<in> vars_transaction T\"\n  shows \"\\<exists>a. \\<Gamma> (Var x) = TAtom a \\<and> \\<Gamma> (Var x) \\<noteq> TAtom OccursSecType\"\nproof -\n  have \"is_Var (fst x)\" \"the_Var (fst x) = Value\"\n    using assms unfolding admissible_transaction_def by blast+\n  thus ?thesis using \\<Gamma>\\<^sub>v_TAtom''(2)[of x] by force\nqed\n\nlemma admissible_transaction_Value_vars_are_fv:\n  assumes \"admissible_transaction T\"\n    and \"x \\<in> vars_transaction T\"\n    and \"\\<Gamma>\\<^sub>v x = TAtom Value\"\n  shows \"x \\<in> fv_transaction T\"\nusing assms(2,3) \\<Gamma>\\<^sub>v_TAtom''(2)[of x] vars\\<^sub>s\\<^sub>s\\<^sub>t_is_fv\\<^sub>s\\<^sub>s\\<^sub>t_bvars\\<^sub>s\\<^sub>s\\<^sub>t[of \"unlabel (transaction_strand T)\"]\n      admissible_transactionE(4)[OF assms(1)]\nby fast\n\nlemma transaction_receive_deduct:\n  assumes T_wf: \"wellformed_transaction T\"\n    and \\<I>: \"constraint_model \\<I> (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n    and \\<xi>: \"transaction_decl_subst \\<xi> T\"\n    and \\<sigma>: \"transaction_fresh_subst \\<sigma> T A\"\n    and \\<alpha>: \"transaction_renaming_subst \\<alpha> P A\"\n    and t: \"receive\\<langle>ts\\<rangle> \\<in> set (unlabel (transaction_receive T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n  shows \"\\<forall>t \\<in> set ts. ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> t \\<cdot> \\<I>\"\nproof -\n  define \\<theta> where \"\\<theta> \\<equiv> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n\n  have t': \"send\\<langle>ts\\<rangle> \\<in> set (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)))\"\n    using t dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_steps_iff(2) unfolding \\<theta>_def by blast\n  then obtain T1 T2 where T: \"unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)) = T1@send\\<langle>ts\\<rangle>#T2\"\n    using t' by (meson split_list)\n\n  have \"constr_sem_stateful \\<I> (unlabel A@unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)))\"\n    using \\<I> unlabel_append[of A] unfolding constraint_model_def \\<theta>_def by simp\n  hence \"constr_sem_stateful \\<I> (unlabel A@T1@[send\\<langle>ts\\<rangle>])\"\n    using strand_sem_append_stateful[of \"{}\" \"{}\" \"unlabel A@T1@[send\\<langle>ts\\<rangle>]\" _ \\<I>]\n          transaction_dual_subst_unlabel_unfold[of T \\<theta>] T\n    by (metis append.assoc append_Cons append_Nil)\n  hence \"\\<forall>t \\<in> set ts. ik\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A@T1) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> t \\<cdot> \\<I>\"\n    using strand_sem_append_stateful[of \"{}\" \"{}\" \"unlabel A@T1\" \"[send\\<langle>ts\\<rangle>]\" \\<I>] T\n    by force\n  moreover have \"\\<not>is_Receive x\"\n    when x: \"x \\<in> set (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)))\" for x\n  proof -\n    have *: \"is_Receive a\" when \"a \\<in> set (unlabel (transaction_receive T))\" for a\n      using T_wf Ball_set[of \"unlabel (transaction_receive T)\" is_Receive] that\n      unfolding wellformed_transaction_def\n      by blast\n\n    obtain l where l: \"(l,x) \\<in> set (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n      using x unfolding unlabel_def by fastforce\n    then obtain ly where ly: \"ly \\<in> set (transaction_receive T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\" \"(l,x) = dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p ly\"\n      unfolding dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_def by auto\n\n    obtain j y where j: \"ly = (j,y)\" by (metis surj_pair)\n    hence \"j = l\" using ly(2) by (cases y) auto\n    hence y: \"(l,y) \\<in> set (transaction_receive T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\" \"(l,x) = dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (l,y)\"\n      by (metis j ly(1), metis j ly(2))\n\n    obtain z where z:\n        \"z \\<in> set (unlabel (transaction_receive T))\"\n        \"(l,z) \\<in> set (transaction_receive T)\"\n        \"(l,y) = (l,z) \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>\"\n      using y(1) unfolding subst_apply_labeled_stateful_strand_def unlabel_def by force\n\n    have \"is_Receive y\" using *[OF z(1)] z(3) by (cases z) auto\n    thus \"\\<not>is_Receive x\" using l y by (cases y) auto\n  qed\n  hence \"\\<not>is_Receive x\" when \"x \\<in> set T1\" for x using T that by simp\n  hence \"ik\\<^sub>s\\<^sub>s\\<^sub>t T1 = {}\" unfolding ik\\<^sub>s\\<^sub>s\\<^sub>t_def is_Receive_def by fast\n  hence \"ik\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A@T1) = ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\" using ik\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel A\" T1] by simp\n  ultimately show ?thesis by (simp add: \\<theta>_def)\nqed\n\nlemma transaction_checks_db:\n  assumes T: \"admissible_transaction T\"\n    and \\<I>: \"constraint_model \\<I> (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n    and \\<xi>: \"transaction_decl_subst \\<xi> T\"\n    and \\<sigma>: \"transaction_fresh_subst \\<sigma> T A\"\n    and \\<alpha>: \"transaction_renaming_subst \\<alpha> P A\"\n  shows \"\\<langle>Var (TAtom Value, n) in Fun (Set s) []\\<rangle> \\<in> set (unlabel (transaction_checks T))\n          \\<Longrightarrow> (\\<alpha> (TAtom Value, n) \\<cdot> \\<I>, Fun (Set s) []) \\<in> set (db\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<I>)\"\n      (is \"?A \\<Longrightarrow> ?B\")\n    and \"\\<langle>Var (TAtom Value, n) not in Fun (Set s) []\\<rangle> \\<in> set (unlabel (transaction_checks T))\n          \\<Longrightarrow> (\\<alpha> (TAtom Value, n) \\<cdot> \\<I>, Fun (Set s) []) \\<notin> set (db\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<I>)\"\n      (is \"?C \\<Longrightarrow> ?D\")\nproof -\n  let ?x = \"\\<lambda>n. (TAtom Value, n)\"\n  let ?s = \"Fun (Set s) []\"\n  let ?T = \"transaction_receive T@transaction_checks T\"\n  let ?T' = \"?T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n  let ?S = \"\\<lambda>S. transaction_receive T@S\"\n  let ?S' = \"\\<lambda>S. ?S S \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n\n  note \\<xi>_empty = admissible_transaction_decl_subst_empty[OF T \\<xi>]\n\n  note T_wf = admissible_transaction_is_wellformed_transaction(1)[OF T]\n\n  have \"constr_sem_stateful \\<I> (unlabel (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)))\"\n    using \\<I> unfolding constraint_model_def by simp\n  moreover have\n      \"dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>) =\n       dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (?S (T1@[c]) \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)@\n       dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (T2@transaction_updates T@transaction_send T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)\"\n    when \"transaction_checks T = T1@c#T2\" for T1 T2 c \\<delta>\n    using that dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_append subst_lsst_append\n    unfolding transaction_strand_def\n    by (metis append.assoc append_Cons append_Nil)\n  ultimately have T'_model: \"constr_sem_stateful \\<I> (unlabel (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (?S' (T1@[(l,c)]))))\"\n    when \"transaction_checks T = T1@(l,c)#T2\" for T1 T2 l c\n    using strand_sem_append_stateful[of _ _ _ _ \\<I>]\n    by (simp add: that transaction_strand_def)\n\n  show \"?A \\<Longrightarrow> ?B\"\n  proof -\n    assume a: ?A\n    hence *: \"\\<langle>Var (?x n) in ?s\\<rangle> \\<in> set (unlabel ?T)\"\n      unfolding transaction_strand_def unlabel_def by simp\n    then obtain l T1 T2 where T1: \"transaction_checks T = T1@(l,\\<langle>Var (?x n) in ?s\\<rangle>)#T2\"\n      by (metis a split_list unlabel_mem_has_label)\n\n    have \"?x n \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T)\"\n      using a by force\n    hence \"?x n \\<notin> set (transaction_fresh T)\"\n      using a admissible_transaction_fresh_vars_notin[OF T] by fast\n    hence \"unlabel (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (?S' (T1@[(l,\\<langle>Var (?x n) in ?s\\<rangle>)]))) =\n           unlabel (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (?S' T1))@[\\<langle>\\<alpha> (?x n) in ?s\\<rangle>]\"\n      using T a \\<sigma> dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_append subst_lsst_append unlabel_append \\<xi>_empty\n      by (fastforce simp add: transaction_fresh_subst_def unlabel_def dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_def\n                              subst_apply_labeled_stateful_strand_def)\n    moreover have \"db\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A) = db\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (?S' T1)))\"\n      by (simp add: T1 db\\<^sub>s\\<^sub>s\\<^sub>t_transaction_prefix_eq[OF T_wf] del: unlabel_append)\n    ultimately have \"\\<exists>M. strand_sem_stateful M (set (db\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A) \\<I>)) [\\<langle>\\<alpha> (?x n) in ?s\\<rangle>] \\<I>\"\n      using T'_model[OF T1] db\\<^sub>s\\<^sub>s\\<^sub>t_set_is_dbupd\\<^sub>s\\<^sub>s\\<^sub>t[of _ \\<I>] strand_sem_append_stateful[of _ _ _ _ \\<I>]\n      by (simp add: db\\<^sub>s\\<^sub>s\\<^sub>t_def del: unlabel_append)\n    thus ?B by simp\n  qed\n\n  show \"?C \\<Longrightarrow> ?D\"\n  proof -\n    assume a: ?C\n    hence *: \"\\<langle>Var (?x n) not in ?s\\<rangle> \\<in> set (unlabel ?T)\"\n      unfolding transaction_strand_def unlabel_def by simp\n    then obtain l T1 T2 where T1: \"transaction_checks T = T1@(l,\\<langle>Var (?x n) not in ?s\\<rangle>)#T2\"\n      by (metis a split_list unlabel_mem_has_label)\n\n    have \"?x n \\<in> vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<langle>Var (?x n) not in ?s\\<rangle>\"\n      using vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_cases(9)[of \"[]\" \"Var (?x n)\" ?s] by auto\n    hence \"?x n \\<in> vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T)\"\n      using a unfolding vars\\<^sub>s\\<^sub>s\\<^sub>t_def by force\n    hence \"?x n \\<notin> set (transaction_fresh T)\"\n      using a admissible_transaction_fresh_vars_notin[OF T] by fast\n    hence \"unlabel (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (?S' (T1@[(l,\\<langle>Var (?x n) not in ?s\\<rangle>)]))) =\n           unlabel (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (?S' T1))@[\\<langle>\\<alpha> (?x n) not in ?s\\<rangle>]\"\n      using T a \\<sigma> dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_append subst_lsst_append unlabel_append \\<xi>_empty\n      by (fastforce simp add: transaction_fresh_subst_def unlabel_def dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_def\n                              subst_apply_labeled_stateful_strand_def)\n    moreover have \"db\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A) = db\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (?S' T1)))\"\n      by (simp add: T1 db\\<^sub>s\\<^sub>s\\<^sub>t_transaction_prefix_eq[OF T_wf] del: unlabel_append)\n    ultimately have \"\\<exists>M. strand_sem_stateful M (set (db\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A) \\<I>)) [\\<langle>\\<alpha> (?x n) not in ?s\\<rangle>] \\<I>\"\n      using T'_model[OF T1] db\\<^sub>s\\<^sub>s\\<^sub>t_set_is_dbupd\\<^sub>s\\<^sub>s\\<^sub>t[of _ \\<I>] strand_sem_append_stateful[of _ _ _ _ \\<I>]\n      by (simp add: db\\<^sub>s\\<^sub>s\\<^sub>t_def del: unlabel_append)\n    thus ?D using stateful_strand_sem_NegChecks_no_bvars(1)[of _ _ _ ?s \\<I>] by simp\n  qed\nqed\n\nlemma transaction_selects_db:\n  assumes T: \"admissible_transaction T\"\n    and \\<I>: \"constraint_model \\<I> (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n    and \\<xi>: \"transaction_decl_subst \\<xi> T\"\n    and \\<sigma>: \"transaction_fresh_subst \\<sigma> T A\"\n    and \\<alpha>: \"transaction_renaming_subst \\<alpha> P A\"\n  shows \"select\\<langle>Var (TAtom Value, n), Fun (Set s) []\\<rangle> \\<in> set (unlabel (transaction_checks T))\n          \\<Longrightarrow> (\\<alpha> (TAtom Value, n) \\<cdot> \\<I>, Fun (Set s) []) \\<in> set (db\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<I>)\"\n      (is \"?A \\<Longrightarrow> ?B\")\nproof -\n  let ?x = \"\\<lambda>n. (TAtom Value, n)\"\n  let ?s = \"Fun (Set s) []\"\n  let ?T = \"transaction_receive T@transaction_checks T\"\n  let ?T' = \"?T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n  let ?S = \"\\<lambda>S. transaction_receive T@S\"\n  let ?S' = \"\\<lambda>S. ?S S \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n\n  note \\<xi>_empty = admissible_transaction_decl_subst_empty[OF T \\<xi>]\n\n  note T_wf = admissible_transaction_is_wellformed_transaction(1)[OF T]\n\n  have \"constr_sem_stateful \\<I> (unlabel (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)))\"\n    using \\<I> unfolding constraint_model_def by simp\n  moreover have\n      \"dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>) =\n       dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (?S (T1@[c]) \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)@\n       dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (T2@transaction_updates T@transaction_send T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)\"\n    when \"transaction_checks T = T1@c#T2\" for T1 T2 c \\<delta>\n    using that dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_append subst_lsst_append\n    unfolding transaction_strand_def by (metis append.assoc append_Cons append_Nil)\n  ultimately have T'_model: \"constr_sem_stateful \\<I> (unlabel (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (?S' (T1@[(l,c)]))))\"\n    when \"transaction_checks T = T1@(l,c)#T2\" for T1 T2 l c\n    using strand_sem_append_stateful[of _ _ _ _ \\<I>]\n    by (simp add: that transaction_strand_def)\n\n  show \"?A \\<Longrightarrow> ?B\"\n  proof -\n    assume a: ?A\n    hence *: \"select\\<langle>Var (?x n), ?s\\<rangle> \\<in> set (unlabel ?T)\"\n      unfolding transaction_strand_def unlabel_def by simp\n    then obtain l T1 T2 where T1: \"transaction_checks T = T1@(l,select\\<langle>Var (?x n), ?s\\<rangle>)#T2\"\n      by (metis a split_list unlabel_mem_has_label)\n\n    have \"?x n \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T)\"\n      using a by force\n    hence \"?x n \\<notin> set (transaction_fresh T)\"\n      using a admissible_transaction_fresh_vars_notin[OF T] by fast\n    hence \"unlabel (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (?S' (T1@[(l,select\\<langle>Var (?x n), ?s\\<rangle>)]))) =\n           unlabel (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (?S' T1))@[select\\<langle>\\<alpha> (?x n), ?s\\<rangle>]\"\n      using T a \\<sigma> dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_append subst_lsst_append unlabel_append \\<xi>_empty\n      by (fastforce simp add: transaction_fresh_subst_def unlabel_def dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_def\n                              subst_apply_labeled_stateful_strand_def)\n    moreover have \"db\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A) = db\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (?S' T1)))\"\n      by (simp add: T1 db\\<^sub>s\\<^sub>s\\<^sub>t_transaction_prefix_eq[OF T_wf] del: unlabel_append)\n    ultimately have \"\\<exists>M. strand_sem_stateful M (set (db\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A) \\<I>)) [\\<langle>\\<alpha> (?x n) in ?s\\<rangle>] \\<I>\"\n      using T'_model[OF T1] db\\<^sub>s\\<^sub>s\\<^sub>t_set_is_dbupd\\<^sub>s\\<^sub>s\\<^sub>t[of _ \\<I>] strand_sem_append_stateful[of _ _ _ _ \\<I>]\n      by (simp add: db\\<^sub>s\\<^sub>s\\<^sub>t_def del: unlabel_append)\n    thus ?B by simp\n  qed\nqed\n\nlemma admissible_transaction_terms_no_Value_consts:\n  assumes \"admissible_transaction_terms T\"\n    and \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T))\"\n  shows \"\\<nexists>a T. t = Fun (Val a) T\" (is ?A)\n    and \"\\<nexists>a T. t = Fun (Abs a) T\" (is ?B)\n    and \"\\<nexists>a T. t = Fun (PubConst Value a) T\" (is ?C)\nproof -\n  have \"\\<not>is_Val f\" \"\\<not>is_Abs f\" \"\\<not>is_PubConstValue f\"\n    when \"f \\<in> \\<Union>(funs_term ` (trms_transaction T))\" for f\n    using that assms(1)[unfolded admissible_transaction_terms_def]\n    unfolding is_PubConstValue_def by (blast,blast,blast)\n  moreover have \"f \\<in> \\<Union>(funs_term ` (trms_transaction T))\"\n    when \"f \\<in> funs_term t\" for f\n    using that assms(2) funs_term_subterms_eq(2)[of \"trms_transaction T\"] by blast+\n  ultimately have *: \"\\<not>is_Val f\" \"\\<not>is_Abs f\" \"\\<not>is_PubConstValue f\"\n    when \"f \\<in> funs_term t\" for f\n    using that by presburger+\n\n  show ?A using *(1) by force\n  show ?B using *(2) by force\n  show ?C using *(3) unfolding is_PubConstValue_def by force\nqed\n\nlemma admissible_transactions_no_Value_consts:\n  assumes \"admissible_transaction T\"\n    and \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T))\"\n  shows \"\\<nexists>a T. t = Fun (Val a) T\" (is ?A)\n    and \"\\<nexists>a T. t = Fun (Abs a) T\" (is ?B)\n    and \"\\<nexists>a T. t = Fun (PubConst Value a) T\" (is ?C)\nusing admissible_transaction_terms_no_Value_consts[OF\n        admissible_transaction_is_wellformed_transaction(4)[OF assms(1)] assms(2)]\nby auto\n\nlemma admissible_transactions_no_Value_consts':\n  assumes \"admissible_transaction T\"\n    and \"t \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T)\"\n  shows \"\\<nexists>a T. Fun (Val a) T \\<in> subterms t\"\n    and \"\\<nexists>a T. Fun (Abs a) T \\<in> subterms t\"\nusing admissible_transactions_no_Value_consts[OF assms(1)] assms(2) by fast+\n\nlemma admissible_transactions_no_Value_consts'':\n  assumes \"admissible_transaction T\"\n  shows \"\\<forall>n. PubConst Value n \\<notin> \\<Union>(funs_term ` trms_transaction T)\"\n    and \"\\<forall>n. Abs n \\<notin> \\<Union>(funs_term ` trms_transaction T)\"\nusing assms\nunfolding admissible_transaction_def admissible_transaction_terms_def\nby (meson prot_fun.discI(6), meson prot_fun.discI(4))\n\nlemma admissible_transactions_no_PubConsts:\n  assumes \"admissible_transaction T\"\n    and \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T))\"\n  shows \"\\<nexists>a n T. t = Fun (PubConst a n) T\"\nproof -\n  have \"\\<not>is_PubConst f\"\n    when \"f \\<in> \\<Union>(funs_term ` (trms_transaction T))\" for f\n    using that conjunct1[OF conjunct2[OF admissible_transaction_is_wellformed_transaction(4)[\n            OF assms(1), unfolded admissible_transaction_terms_def]]]\n    by blast\n  moreover have \"f \\<in> \\<Union>(funs_term ` (trms_transaction T))\"\n    when \"f \\<in> funs_term t\" for f\n    using that assms(2) funs_term_subterms_eq(2)[of \"trms_transaction T\"] by blast+\n  ultimately have *: \"\\<not>is_PubConst f\"\n    when \"f \\<in> funs_term t\" for f\n    using that by presburger+\n\n  show ?thesis using * by force\nqed\n\nlemma admissible_transactions_no_PubConsts':\n  assumes \"admissible_transaction T\"\n    and \"t \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T)\"\n  shows \"\\<nexists>a n T. Fun (PubConst a n) T \\<in> subterms t\"\nusing admissible_transactions_no_PubConsts[OF assms(1)] assms(2) by fast+\n\nlemma transaction_inserts_are_Value_vars:\n  assumes T_valid: \"wellformed_transaction T\"\n    and \"admissible_transaction_updates T\"\n    and \"insert\\<langle>t,s\\<rangle> \\<in> set (unlabel (transaction_strand T))\"\n  shows \"\\<exists>n. t = Var (TAtom Value, n)\"\n    and \"\\<exists>u. s = Fun (Set u) []\"\nproof -\n  let ?x = \"insert\\<langle>t,s\\<rangle>\"\n\n  have \"?x \\<in> set (unlabel (transaction_updates T))\"\n    using assms(3) wellformed_transaction_unlabel_cases[OF T_valid, of ?x]    \n    by (auto simp add: transaction_strand_def unlabel_def)\n  hence *: \"is_Var (the_elem_term ?x)\" \"fst (the_Var (the_elem_term ?x)) = TAtom Value\"\n           \"is_Fun (the_set_term ?x)\" \"args (the_set_term ?x) = []\"\n           \"is_Set (the_Fun (the_set_term ?x))\"\n    using assms(2) unfolding admissible_transaction_updates_def is_Fun_Set_def by fastforce+\n  \n  show \"\\<exists>n. t = Var (TAtom Value, n)\" using *(1,2) by (cases t) auto\n  show \"\\<exists>u. s = Fun (Set u) []\" using *(3,4,5) unfolding is_Set_def by (cases s) auto\nqed\n\nlemma transaction_deletes_are_Value_vars:\n  assumes T_valid: \"wellformed_transaction T\"\n    and \"admissible_transaction_updates T\"\n    and \"delete\\<langle>t,s\\<rangle> \\<in> set (unlabel (transaction_strand T))\"\n  shows \"\\<exists>n. t = Var (TAtom Value, n)\"\n    and \"\\<exists>u. s = Fun (Set u) []\"\nproof -\n  let ?x = \"delete\\<langle>t,s\\<rangle>\"\n\n  have \"?x \\<in> set (unlabel (transaction_updates T))\"\n    using assms(3) wellformed_transaction_unlabel_cases[OF T_valid, of ?x]    \n    by (auto simp add: transaction_strand_def unlabel_def)\n  hence *: \"is_Var (the_elem_term ?x)\" \"fst (the_Var (the_elem_term ?x)) = TAtom Value\"\n           \"is_Fun (the_set_term ?x)\" \"args (the_set_term ?x) = []\"\n           \"is_Set (the_Fun (the_set_term ?x))\"\n    using assms(2) unfolding admissible_transaction_updates_def is_Fun_Set_def by fastforce+\n  \n  show \"\\<exists>n. t = Var (TAtom Value, n)\" using *(1,2) by (cases t) auto\n  show \"\\<exists>u. s = Fun (Set u) []\" using *(3,4,5) unfolding is_Set_def by (cases s) auto\nqed\n\nlemma transaction_selects_are_Value_vars:\n  assumes T_valid: \"wellformed_transaction T\"\n    and \"admissible_transaction_checks T\"\n    and \"select\\<langle>t,s\\<rangle> \\<in> set (unlabel (transaction_strand T))\"\n  shows \"\\<exists>n. t = Var (TAtom Value, n) \\<and> (TAtom Value, n) \\<notin> set (transaction_fresh T)\" (is ?A)\n    and \"\\<exists>u. s = Fun (Set u) []\" (is ?B)\nproof -\n  let ?x = \"select\\<langle>t,s\\<rangle>\"\n\n  have *: \"?x \\<in> set (unlabel (transaction_checks T))\"\n    using assms(3) wellformed_transaction_unlabel_cases[OF T_valid, of ?x]    \n    by (auto simp add: transaction_strand_def unlabel_def)\n  \n  have **: \"is_Var (the_elem_term ?x)\" \"fst (the_Var (the_elem_term ?x)) = TAtom Value\"\n           \"is_Fun (the_set_term ?x)\" \"args (the_set_term ?x) = []\"\n           \"is_Set (the_Fun (the_set_term ?x))\"\n    using * assms(2) unfolding admissible_transaction_checks_def is_Fun_Set_def by fastforce+\n\n  have \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p ?x \\<subseteq> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T)\"\n    using * by force\n  hence ***: \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p ?x \\<inter> set (transaction_fresh T) = {}\"\n    using T_valid unfolding wellformed_transaction_def by fast\n\n  show ?A using **(1,2) *** by (cases t) auto\n  show ?B using **(3,4,5) unfolding is_Set_def by (cases s) auto\nqed\n\nlemma transaction_inset_checks_are_Value_vars:\n  assumes T_valid: \"admissible_transaction T\"\n    and t: \"\\<langle>t in s\\<rangle> \\<in> set (unlabel (transaction_strand T))\"\n  shows \"\\<exists>n. t = Var (TAtom Value, n) \\<and> (TAtom Value, n) \\<notin> set (transaction_fresh T)\" (is ?A)\n    and \"\\<exists>u. s = Fun (Set u) []\" (is ?B)\nproof -\n  let ?x = \"\\<langle>t in s\\<rangle>\"\n\n  note T_wf = admissible_transaction_is_wellformed_transaction(1)[OF T_valid]\n  note T_adm_checks = admissible_transaction_is_wellformed_transaction(2)[OF T_valid]\n\n  have *: \"?x \\<in> set (unlabel (transaction_checks T))\"\n    using t wellformed_transaction_unlabel_cases[OF T_wf, of ?x]\n    unfolding transaction_strand_def unlabel_def by fastforce\n  \n  have **: \"is_Var (the_elem_term ?x)\" \"fst (the_Var (the_elem_term ?x)) = TAtom Value\"\n           \"is_Fun (the_set_term ?x)\" \"args (the_set_term ?x) = []\"\n           \"is_Set (the_Fun (the_set_term ?x))\"\n    using * T_adm_checks unfolding admissible_transaction_checks_def is_Fun_Set_def by fastforce+\n\n  have \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p ?x \\<subseteq> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T)\"\n    using * by force\n  hence ***: \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p ?x \\<inter> set (transaction_fresh T) = {}\"\n    using T_wf unfolding wellformed_transaction_def by fast\n\n  show ?A using **(1,2) *** by (cases t) auto\n  show ?B using **(3,4,5) unfolding is_Set_def by (cases s) auto\nqed\n\nlemma transaction_notinset_checks_are_Value_vars:\n  assumes T_adm: \"admissible_transaction T\"\n    and FG: \"\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: G\\<rangle> \\<in> set (unlabel (transaction_strand T))\"\n    and t: \"(t,s) \\<in> set G\"\n  shows \"\\<exists>n. t = Var (TAtom Value, n) \\<and> (TAtom Value, n) \\<notin> set (transaction_fresh T)\" (is ?A)\n    and \"\\<exists>u. s = Fun (Set u) []\" (is ?B)\nproof -\n  let ?x = \"\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: G\\<rangle>\"\n\n  note T_wf = admissible_transaction_is_wellformed_transaction(1)[OF T_adm]\n  note T_adm_checks = admissible_transaction_is_wellformed_transaction(2)[OF T_adm]\n\n  have 0: \"?x \\<in> set (unlabel (transaction_checks T))\"\n    using FG wellformed_transaction_unlabel_cases[OF T_wf, of ?x]    \n    by (auto simp add: transaction_strand_def unlabel_def)\n  hence 1: \"F = [] \\<and> length G = 1\"\n    using T_adm_checks t unfolding admissible_transaction_checks_def by fastforce\n  hence \"hd G = (t,s)\" using t by (cases \"the_ins ?x\") auto\n  hence **: \"is_Var t\" \"fst (the_Var t) = TAtom Value\" \"is_Fun s\" \"args s = []\" \"is_Set (the_Fun s)\"\n    using 1 Set.bspec[OF T_adm_checks[unfolded admissible_transaction_checks_def] 0]\n    unfolding is_Fun_Set_def by auto\n\n  have \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p ?x \\<subseteq> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T)\"\n       \"set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p ?x) \\<subseteq> bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T)\"\n    using 0 by force+\n  moreover have\n      \"set (transaction_fresh T) \\<inter> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T) = {}\"\n      \"set (transaction_fresh T) \\<inter> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T) = {}\"\n    using T_wf unfolding wellformed_transaction_def by fast+\n  ultimately have\n      \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p ?x \\<inter> set (transaction_fresh T) = {}\"\n      \"set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p ?x) \\<inter> set (transaction_fresh T) = {}\"\n    using admissible_transactionE(7)[OF T_adm]\n          wellformed_transaction_wf\\<^sub>s\\<^sub>s\\<^sub>t(2)[OF T_wf]\n          fv_transaction_unfold[of T] bvars_transaction_unfold[of T]\n    by (blast, blast)\n  hence ***: \"fv t \\<inter> set (transaction_fresh T) = {}\"\n    using t by auto\n\n  show ?A using **(1,2) *** by (cases t) auto\n  show ?B using **(3,4,5) unfolding is_Set_def by (cases s) auto\nqed\n\nlemma admissible_transaction_strand_step_cases:\n  assumes T_adm: \"admissible_transaction T\"\n  shows \"r \\<in> set (unlabel (transaction_receive T)) \\<Longrightarrow> \\<exists>t. r = receive\\<langle>t\\<rangle>\"\n        (is \"?A \\<Longrightarrow> ?A'\")\n    and \"r \\<in> set (unlabel (transaction_checks T)) \\<Longrightarrow>\n            (\\<exists>x s. (r = \\<langle>Var x in Fun (Set s) []\\<rangle> \\<or> r = select\\<langle>Var x, Fun (Set s) []\\<rangle> \\<or>\n                   r = \\<langle>Var x not in Fun (Set s) []\\<rangle>) \\<and>\n                   fst x = TAtom Value \\<and> x \\<in> fv_transaction T - set (transaction_fresh T)) \\<or>\n            (\\<exists>s t. r = \\<langle>s == t\\<rangle> \\<or> r = \\<langle>s := t\\<rangle> \\<or> r = \\<langle>s != t\\<rangle>)\"\n        (is \"?B \\<Longrightarrow> ?B'\")\n    and \"r \\<in> set (unlabel (transaction_updates T)) \\<Longrightarrow>\n            \\<exists>x s. (r = insert\\<langle>Var x, Fun (Set s) []\\<rangle> \\<or> r = delete\\<langle>Var x, Fun (Set s) []\\<rangle>) \\<and>\n                  fst x = TAtom Value\"\n        (is \"?C \\<Longrightarrow> ?C'\")\n    and \"r \\<in> set (unlabel (transaction_send T)) \\<Longrightarrow> \\<exists>t. r = send\\<langle>t\\<rangle>\"\n        (is \"?D \\<Longrightarrow> ?D'\")\nproof -\n  note T_wf = admissible_transaction_is_wellformed_transaction(1)[OF T_adm]\n\n  show \"?A \\<Longrightarrow> ?A'\"\n    using T_wf Ball_set[of \"unlabel (transaction_receive T)\" is_Receive]\n    unfolding wellformed_transaction_def is_Receive_def\n    by blast\n\n  show \"?D \\<Longrightarrow> ?D'\"\n    using T_wf Ball_set[of \"unlabel (transaction_send T)\" is_Send]\n    unfolding wellformed_transaction_def is_Send_def\n    by blast\n\n  show \"?B \\<Longrightarrow> ?B'\"\n  proof -\n    assume r: ?B\n    note adm_checks = admissible_transaction_is_wellformed_transaction(1,2)[OF T_adm]\n\n    have fv_r1: \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p r \\<subseteq> fv_transaction T\"\n      using r fv_transaction_unfold[of T] by auto\n  \n    have fv_r2: \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p r \\<inter> set (transaction_fresh T) = {}\"\n      using r T_wf unfolding wellformed_transaction_def by fastforce\n\n    have \"list_all is_Check_or_Assignment (unlabel (transaction_checks T))\"\n      using adm_checks(1) unfolding wellformed_transaction_def by blast\n    hence \"is_InSet r \\<or> is_Equality r \\<or> is_NegChecks r\"\n      using r unfolding list_all_iff by blast\n    thus ?B'\n    proof (elim disjE conjE)\n      assume *: \"is_InSet r\"\n      hence **: \"is_Var (the_elem_term r)\" \"is_Fun (the_set_term r)\"\n                \"is_Set (the_Fun (the_set_term r))\" \"args (the_set_term r) = []\"\n                \"fst (the_Var (the_elem_term r)) = TAtom Value\"\n        using r adm_checks unfolding admissible_transaction_checks_def is_Fun_Set_def\n        by fast+\n      \n      obtain ac rt rs where r': \"r = \\<langle>ac: rt \\<in> rs\\<rangle>\" using * by (cases r) auto\n      obtain x where x: \"rt = Var x\" \"fst x = TAtom Value\" using **(1,5) r' by auto\n      obtain f S where fS: \"rs = Fun f S\" using **(2) r' by auto\n      obtain s where s: \"f = Set s\" using **(3) fS r' by (cases f) auto\n      hence S: \"S = []\" using **(4) fS r' by auto\n  \n      show ?B' using r' x fS s S fv_r1 fv_r2 by (cases ac) simp_all\n    next\n      assume *: \"is_NegChecks r\"\n      hence **: \"bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p r = []\"\n                \"(the_eqs r = [] \\<and> length (the_ins r) = 1) \\<or>\n                 (the_ins r = [] \\<and> length (the_eqs r) = 1)\"\n        using r adm_checks unfolding admissible_transaction_checks_def by fast+\n      show ?B' using **(2)\n      proof (elim disjE conjE)\n        assume ***: \"the_eqs r = []\" \"length (the_ins r) = 1\"\n        then obtain t s where ts: \"the_ins r = [(t,s)]\" by (cases \"the_ins r\") auto\n        hence \"hd (the_ins r) = (t,s)\" by simp\n        hence ****: \"is_Var (fst (t,s))\" \"is_Fun (snd (t,s))\"\n                    \"is_Set (the_Fun (snd (t,s)))\" \"args (snd (t,s)) = []\"\n                    \"fst (the_Var (fst (t,s))) = TAtom Value\"\n          using * ***(1) Set.bspec[OF adm_checks(2)[unfolded admissible_transaction_checks_def] r]\n          unfolding is_Fun_Set_def by simp_all\n        obtain x where x: \"t = Var x\" \"fst x = TAtom Value\" using ts ****(1,5) by (cases t) simp_all\n        obtain f S where fS: \"s = Fun f S\" using ts ****(2) by (cases s) simp_all\n        obtain ss where ss: \"f = Set ss\" using fS ****(3) by (cases f) simp_all\n        have S: \"S = []\" using ts fS ss ****(4) by simp\n        \n        show ?B' using ts x fS ss S *** **(1) * fv_r1 fv_r2 by (cases r) auto\n      next\n        assume ***: \"the_ins r = []\" \"length (the_eqs r) = 1\"\n        then obtain t s where \"the_eqs r = [(t,s)]\" by (cases \"the_eqs r\") auto\n        thus ?B' using *** **(1) * by (cases r) auto\n      qed\n    qed (auto simp add: is_Equality_def the_check_def intro: poscheckvariant.exhaust)\n  qed\n\n  show \"?C \\<Longrightarrow> ?C'\"\n  proof -\n    assume r: ?C\n    note adm_upds = admissible_transaction_is_wellformed_transaction(3)[OF T_adm]\n\n    have *: \"is_Update r\" \"is_Var (the_elem_term r)\" \"is_Fun (the_set_term r)\"\n            \"is_Set (the_Fun (the_set_term r))\" \"args (the_set_term r) = []\"\n            \"fst (the_Var (the_elem_term r)) = TAtom Value\"\n      using r adm_upds unfolding admissible_transaction_updates_def is_Fun_Set_def by fast+\n\n    obtain t s where ts: \"r = insert\\<langle>t,s\\<rangle> \\<or> r = delete\\<langle>t,s\\<rangle>\" using *(1) by (cases r) auto\n    obtain x where x: \"t = Var x\" \"fst x = TAtom Value\" using ts *(2,6) by (cases t) auto\n    obtain f T where fT: \"s = Fun f T\" using ts *(3) by (cases s) auto\n    obtain ss where ss: \"f = Set ss\" using ts fT *(4) by (cases f) fastforce+\n    have T: \"T = []\" using ts fT *(5) ss by (cases T) auto\n\n    show ?C'\n      using ts x fT ss T by blast\n  qed\nqed\n\nlemma protocol_transaction_vars_TAtom_typed:\n  assumes T_adm: \"admissible_transaction T\"\n  shows \"\\<forall>x \\<in> vars_transaction T. \\<Gamma>\\<^sub>v x = TAtom Value \\<or> (\\<exists>a. \\<Gamma>\\<^sub>v x = TAtom (Atom a))\"\n    and \"\\<forall>x \\<in> fv_transaction T. \\<Gamma>\\<^sub>v x = TAtom Value \\<or> (\\<exists>a. \\<Gamma>\\<^sub>v x = TAtom (Atom a))\"\n    and \"\\<forall>x \\<in> set (transaction_fresh T). \\<Gamma>\\<^sub>v x = TAtom Value\"\nproof -\n  note T_wf = admissible_transaction_is_wellformed_transaction(1)[OF T_adm]\n\n  show \"\\<forall>x \\<in> vars_transaction T. \\<Gamma>\\<^sub>v x = TAtom Value \\<or> (\\<exists>a. \\<Gamma>\\<^sub>v x = TAtom (Atom a))\"\n    using admissible_transactionE(3)[OF T_adm] by fast\n  thus \"\\<forall>x \\<in> fv_transaction T. \\<Gamma>\\<^sub>v x = TAtom Value \\<or> (\\<exists>a. \\<Gamma>\\<^sub>v x = TAtom (Atom a))\"\n    using vars\\<^sub>s\\<^sub>s\\<^sub>t_is_fv\\<^sub>s\\<^sub>s\\<^sub>t_bvars\\<^sub>s\\<^sub>s\\<^sub>t by fast\n\n  show \"\\<forall>x \\<in> set (transaction_fresh T). \\<Gamma>\\<^sub>v x = TAtom Value\"\n    using admissible_transactionE(2)[OF T_adm] by argo\nqed\n\nlemma protocol_transactions_no_pubconsts:\n  assumes \"admissible_transaction T\"\n  shows \"Fun (Val n) S \\<notin> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms_transaction T)\"\n    and \"Fun (PubConst Value n) S \\<notin> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms_transaction T)\"\nusing assms admissible_transactions_no_Value_consts(1,3) by (blast, blast)\n\nlemma protocol_transactions_no_abss:\n  assumes \"admissible_transaction T\"\n  shows \"Fun (Abs n) S \\<notin> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms_transaction T)\"\nusing assms admissible_transactions_no_Value_consts(2)\nby fast\n\nlemma admissible_transaction_strand_sem_fv_ineq:\n  assumes T_adm: \"admissible_transaction T\"\n    and \\<I>: \"strand_sem_stateful IK DB (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))) \\<I>\"\n    and x: \"x \\<in> fv_transaction T - set (transaction_fresh T)\"\n    and y: \"y \\<in> fv_transaction T - set (transaction_fresh T)\"\n    and x_not_y: \"x \\<noteq> y\"\n  shows \"\\<theta> x \\<cdot> \\<I> \\<noteq> \\<theta> y \\<cdot> \\<I>\"\nproof -\n  have \"\\<langle>Var x != Var y\\<rangle> \\<in> set (unlabel (transaction_checks T)) \\<or>\n        \\<langle>Var y != Var x\\<rangle> \\<in> set (unlabel (transaction_checks T))\"\n    using x y x_not_y admissible_transactionE(8)[OF T_adm] by auto\n  hence \"\\<langle>Var x != Var y\\<rangle> \\<in> set (unlabel (transaction_strand T)) \\<or>\n         \\<langle>Var y != Var x\\<rangle> \\<in> set (unlabel (transaction_strand T))\"\n    unfolding transaction_strand_def unlabel_def by auto\n  hence \"\\<langle>\\<theta> x != \\<theta> y\\<rangle> \\<in> set (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))) \\<or>\n         \\<langle>\\<theta> y != \\<theta> x\\<rangle> \\<in> set (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)))\"\n    using stateful_strand_step_subst_inI(8)[of _ _ \"unlabel (transaction_strand T)\" \\<theta>]\n          subst_lsst_unlabel[of \"transaction_strand T\" \\<theta>]\n          dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_steps_iff(7)[of \"[]\" _ \"[]\"]\n    by force\n  then obtain B where B:\n      \"prefix (B@[\\<langle>\\<theta> x != \\<theta> y\\<rangle>]) (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))) \\<or>\n       prefix (B@[\\<langle>\\<theta> y != \\<theta> x\\<rangle>]) (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)))\"\n    unfolding prefix_def\n    by (metis (no_types, opaque_lifting) append.assoc append_Cons append_Nil split_list)\n  thus ?thesis\n    using \\<I> strand_sem_append_stateful[of IK DB _ _ \\<I>]\n          stateful_strand_sem_NegChecks_no_bvars(2)\n    unfolding prefix_def\n    by metis \nqed\n\nlemma admissible_transaction_terms_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s:\n  assumes \"admissible_transaction_terms T\"\n  shows \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms_transaction T)\"\nby (rule conjunct1[OF assms[unfolded admissible_transaction_terms_def wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s_code[symmetric]]])\n\nlemma admissible_transactions_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s:\n  assumes \"admissible_transaction T\"\n  shows \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms_transaction T)\" \nproof -\n  have \"admissible_transaction_terms T\" using assms[unfolded admissible_transaction_def] by fast\n  thus ?thesis by (metis admissible_transaction_terms_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s)\nqed\n\nlemma admissible_transaction_no_Ana_Attack:\n  assumes \"admissible_transaction_terms T\"\n    and \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms_transaction T)\"\n  shows \"attack\\<langle>n\\<rangle> \\<notin> set (snd (Ana t))\"\nproof -\n  obtain r where r: \"r \\<in> set (unlabel (transaction_strand T))\" \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p r)\"\n    using assms(2) by force\n\n  obtain K M where t: \"Ana t = (K, M)\"\n    by (metis surj_pair)\n\n  show ?thesis\n  proof\n    assume n: \"attack\\<langle>n\\<rangle> \\<in> set (snd (Ana t))\"\n    hence \"attack\\<langle>n\\<rangle> \\<in> set M\" using t by simp\n    hence n': \"attack\\<langle>n\\<rangle> \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p r)\"\n      using Ana_subterm[OF t] r(2) subterms_subset by fast\n    hence \"\\<exists>f \\<in> \\<Union>(funs_term ` trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p r). is_Attack f\"\n      using funs_term_Fun_subterm' unfolding is_Attack_def by fast\n    hence \"is_Send r\" \"length (the_msgs r) = 1\" \"is_Fun (hd (the_msgs r))\"\n          \"is_Attack (the_Fun (hd (the_msgs r)))\" \"args (hd (the_msgs r)) = []\"\n      using assms(1) r(1) unfolding admissible_transaction_terms_def is_Fun_Attack_def by metis+\n    hence \"t = attack\\<langle>n\\<rangle>\"\n      using n' r(2) unfolding is_Send_def is_Attack_def by (cases \"the_msgs r\") auto\n    thus False using n by fastforce\n  qed\nqed\n\nlemma admissible_transaction_Value_vars:\n  assumes T: \"admissible_transaction T\"\n    and x: \"x \\<in> fv_transaction T\"\n  shows \"\\<Gamma>\\<^sub>v x = TAtom Value\"\nproof -\n  have \"x \\<in> vars_transaction T\"\n    using x vars\\<^sub>s\\<^sub>s\\<^sub>t_is_fv\\<^sub>s\\<^sub>s\\<^sub>t_bvars\\<^sub>s\\<^sub>s\\<^sub>t[of \"unlabel (transaction_strand T)\"]\n    by blast\n  thus \"\\<Gamma>\\<^sub>v x = TAtom Value\"\n    using admissible_transactionE(3)[OF T] by simp\nqed\n\nlemma admissible_transaction_occurs_checksE1:\n  assumes T: \"admissible_transaction_occurs_checks T\"\n    and x: \"x \\<in> fv_transaction T - set (transaction_fresh T)\" \"\\<Gamma>\\<^sub>v x = TAtom Value\"\n  obtains l ts S where\n    \"transaction_receive T = (l,receive\\<langle>ts\\<rangle>)#S\" \"occurs (Var x) \\<in> set ts\"\nproof -\n  let ?rcvs = \"transaction_receive T\"\n  let ?frsh = \"transaction_fresh T\"\n  let ?fvs = \"fv_transaction T\"\n\n  have *: \"?rcvs \\<noteq> []\" \"is_Receive (hd (unlabel ?rcvs))\"\n          \"\\<forall>x \\<in> ?fvs - set ?frsh. \\<Gamma>\\<^sub>v x = TAtom Value \\<longrightarrow>\n            occurs (Var x) \\<in> set (the_msgs (hd (unlabel ?rcvs)))\"\n    using T x unfolding admissible_transaction_occurs_checks_def \\<Gamma>\\<^sub>v_TAtom''(2) by meson+\n\n  obtain r S where S: \"?rcvs = r#S\"\n    using *(1) by (cases ?rcvs) auto\n\n  obtain l ts where r: \"r = (l,receive\\<langle>ts\\<rangle>)\"\n    by (metis *(1,2) S list.map_sel(1) list.sel(1) prod.collapse is_Receive_def unlabel_def) \n\n  have 0: \"occurs (Var x) \\<in> set ts\" using *(3) x S r by fastforce\n\n  show ?thesis using that[unfolded S r, of l ts S] 0 by blast\nqed\n\nlemma admissible_transaction_occurs_checksE2:\n  assumes T: \"admissible_transaction_occurs_checks T\"\n    and x: \"x \\<in> set (transaction_fresh T)\"\n  obtains l ts S where\n    \"transaction_send T = (l,send\\<langle>ts\\<rangle>)#S\" \"occurs (Var x) \\<in> set ts\"\nproof -\n  let ?snds = \"transaction_send T\"\n  let ?frsh = \"transaction_fresh T\"\n  let ?fvs = \"fv_transaction T\"\n  define ts where \"ts \\<equiv> the_msgs (hd (unlabel ?snds))\"\n\n  let ?P = \"\\<forall>x \\<in> set ?frsh. occurs (Var x) \\<in> set ts\"\n\n  have \"?frsh \\<noteq> []\" using x by auto\n  hence *: \"?snds \\<noteq> []\" \"is_Send (hd (unlabel ?snds))\" \"?P\"\n    using T x unfolding admissible_transaction_occurs_checks_def ts_def by meson+\n\n  obtain r S where S: \"?snds = r#S\"\n    using *(1) by (cases ?snds) auto\n\n  obtain l where r: \"r = (l,send\\<langle>ts\\<rangle>)\"\n    by (metis *(1,2) S list.map_sel(1) list.sel(1) prod.collapse unlabel_def ts_def\n              stateful_strand_step.collapse(1)) \n\n  have ts: \"occurs (Var x) \\<in> set ts\"\n    using x *(3) unfolding S by auto\n\n  show ?thesis using that[unfolded S r, of l ts S] ts by blast\nqed\n\nlemma admissible_transaction_occurs_checksE3:\n  assumes T: \"admissible_transaction_occurs_checks T\"\n    and t: \"OccursFact \\<in> funs_term t \\<or> OccursSec \\<in> funs_term t\" \"t \\<in> set ts\"\n    and ts: \"send\\<langle>ts\\<rangle> \\<in> set (unlabel (transaction_send T))\"\n  obtains x where \"t = occurs (Var x)\" \"x \\<in> set (transaction_fresh T)\"\nproof -\n  let ?P = \"\\<lambda>t. \\<exists>x \\<in> set (transaction_fresh T). t = occurs (Var x)\"\n\n  have \"?P t\"\n    when \"t \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)\" \"OccursFact \\<in> funs_term t \\<or> OccursSec \\<in> funs_term t\"\n    for t\n    using assms that unfolding admissible_transaction_occurs_checks_def by metis\n  moreover have \"t \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)\"\n    using t(2) ts unfolding trms\\<^sub>s\\<^sub>s\\<^sub>t_def by fastforce\n  ultimately have \"?P t\" using t(1) by blast\n  thus thesis using that by blast\nqed\n\nlemma admissible_transaction_occurs_checksE4:\n  assumes T: \"admissible_transaction_occurs_checks T\"\n    and ts: \"send\\<langle>ts\\<rangle> \\<in> set (unlabel (transaction_send T))\"\n    and t: \"occurs t \\<in> set ts\"\n  obtains x where \"t = Var x\" \"x \\<in> set (transaction_fresh T)\"\nusing admissible_transaction_occurs_checksE3[OF T _ t ts] by auto\n\nlemma admissible_transaction_occurs_checksE5:\n  assumes T: \"admissible_transaction_occurs_checks T\"\n  shows \"Fun OccursSec [] \\<notin> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)\"\nproof -\n  have \"\\<exists>x \\<in> set (transaction_fresh T). t = occurs (Var x)\"\n    when \"t \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)\" \"OccursFact \\<in> funs_term t \\<or> OccursSec \\<in> funs_term t\"\n    for t\n    using assms that unfolding admissible_transaction_occurs_checks_def by metis\n  thus ?thesis by fastforce\nqed\n\nlemma admissible_transaction_occurs_checksE6:\n  assumes T: \"admissible_transaction_occurs_checks T\"\n    and t: \"t \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)\"\n  shows \"Fun OccursSec [] \\<notin> set (snd (Ana t))\" (is ?A)\n    and \"occurs k \\<notin> set (snd (Ana t))\" (is ?B)\nproof -\n  obtain t' where t': \"t' \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)\" \"t \\<sqsubseteq> t'\" using t by blast\n  have \"?A \\<and> ?B\"\n  proof (rule ccontr)\n    assume *: \"\\<not>(?A \\<and> ?B)\"\n    hence \"OccursSec \\<in> funs_term t' \\<or> OccursFact \\<in> funs_term t'\"\n      by (meson t'(2) Ana_subterm' funs_term_Fun_subterm' term.order.trans) \n    then obtain x where x: \"x \\<in> set (transaction_fresh T)\" \"t' = occurs (Var x)\"\n      using t'(1) T unfolding admissible_transaction_occurs_checks_def by metis\n    have \"t = occurs (Var x) \\<or> t = Var x \\<or> t = Fun OccursSec []\" using x(2) t'(2) by auto\n    thus False using * by fastforce\n  qed\n  thus ?A ?B by simp_all\nqed\n\n\nsubsection \\<open>Lemmata: Renaming, Declaration, and Fresh Substitutions\\<close>\nlemma transaction_decl_subst_empty_inv:\n  assumes \"transaction_decl_subst Var T\"\n  shows \"transaction_decl T () = []\"\nusing assms unfolding transaction_decl_subst_def subst_domain_Var by blast\n\nlemma transaction_decl_subst_domain:\n  fixes \\<xi>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_decl_subst \\<xi> T\"\n  shows \"subst_domain \\<xi> = fst ` set (transaction_decl T ())\"\nusing assms unfolding transaction_decl_subst_def by argo\n\nlemma transaction_decl_subst_grounds_domain:\n  fixes \\<xi>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_decl_subst \\<xi> T\"\n    and \"x \\<in> fst ` set (transaction_decl T ())\"\n  shows \"fv (\\<xi> x) = {}\"\nproof -\n  obtain c where \"\\<xi> x = Fun c []\"\n    using assms unfolding transaction_decl_subst_def by moura\n  thus ?thesis by simp\nqed\n\nlemma transaction_decl_subst_range_vars_empty:\n  fixes \\<xi>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_decl_subst \\<xi> T\"\n  shows \"range_vars \\<xi> = {}\"\nusing assms unfolding transaction_decl_subst_def range_vars_def by auto\n\nlemma transaction_decl_subst_wt:\n  fixes \\<xi>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_decl_subst \\<xi> T\"\n  shows \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<xi>\"\nusing assms unfolding transaction_decl_subst_def by blast\n\nlemma transaction_decl_subst_is_wf_trm:\n  fixes \\<xi>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_decl_subst \\<xi> P\"\n  shows \"wf\\<^sub>t\\<^sub>r\\<^sub>m (\\<xi> v)\"\nproof (cases \"v \\<in> subst_domain \\<xi>\")\n  case True thus ?thesis using assms unfolding transaction_decl_subst_def by fastforce\nqed auto\n\nlemma transaction_decl_subst_range_wf_trms:\n  fixes \\<xi>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_decl_subst \\<xi> P\"\n  shows \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<xi>)\"\nby (metis transaction_decl_subst_is_wf_trm[OF assms] wf_trm_subst_range_iff)\n\nlemma transaction_renaming_subst_is_renaming:\n  fixes \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \\<alpha>: \"transaction_renaming_subst \\<alpha> P A\"\n  shows \"\\<exists>m. \\<forall>\\<tau> n. \\<alpha> (\\<tau>,n) = Var (\\<tau>,n+Suc m)\" (is ?A)\n    and \"\\<exists>y. \\<alpha> x = Var y\" (is ?B)\n    and \"\\<alpha> x \\<noteq> Var x\" (is ?C)\n    and \"subst_domain \\<alpha> = UNIV\" (is ?D)\n    and \"subst_range \\<alpha> \\<subseteq> range Var\" (is ?E)\n    and \"fv (t \\<cdot> \\<alpha>) \\<subseteq> range_vars \\<alpha>\" (is ?F)\nproof -\n  show 0: ?A using \\<alpha> unfolding transaction_renaming_subst_def var_rename_def by force\n  show ?B using \\<alpha> unfolding transaction_renaming_subst_def var_rename_def by blast\n  show ?C using 0 by (cases x) auto\n  show 1: ?D using 0 by fastforce\n  show ?E using 0 by auto\n  show ?F by (induct t) (auto simp add: 1 subst_dom_vars_in_subst subst_fv_imgI)\nqed\n\nlemma transaction_renaming_subst_is_injective:\n  fixes \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_renaming_subst \\<alpha> P A\"\n  shows \"inj \\<alpha>\"\nproof (intro injI)\n  fix x y::\"('fun,'atom,'sets,'lbl) prot_var\"\n  obtain \\<tau>x nx where x: \"x = (\\<tau>x,nx)\" by (metis surj_pair)\n  obtain \\<tau>y ny where y: \"y = (\\<tau>y,ny)\" by (metis surj_pair)\n\n  obtain m where m: \"\\<forall>\\<tau>. \\<forall>n. \\<alpha> (\\<tau>, n) = Var (\\<tau>, n + Suc m)\"\n    using transaction_renaming_subst_is_renaming(1)[OF assms] by blast\n\n  assume \"\\<alpha> x = \\<alpha> y\"\n  hence \"\\<tau>x = \\<tau>y\" \"nx = ny\" using x y m by simp_all\n  thus \"x = y\" using x y by argo\nqed\n\nlemma transaction_renaming_subst_vars_disj:\n  fixes \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_renaming_subst \\<alpha> P A\"\n  shows \"fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<alpha> ` (\\<Union>(vars_transaction ` set P))) \\<inter> (\\<Union>(vars_transaction ` set P)) = {}\" (is ?A)\n    and \"fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<alpha> ` vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A) \\<inter> vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" (is ?B)\n    and \"T \\<in> set P \\<Longrightarrow> vars_transaction T \\<inter> range_vars \\<alpha> = {}\" (is \"T \\<in> set P \\<Longrightarrow> ?C1\")\n    and \"T \\<in> set P \\<Longrightarrow> bvars_transaction T \\<inter> range_vars \\<alpha> = {}\" (is \"T \\<in> set P \\<Longrightarrow> ?C2\")\n    and \"T \\<in> set P \\<Longrightarrow> fv_transaction T \\<inter> range_vars \\<alpha> = {}\" (is \"T \\<in> set P \\<Longrightarrow> ?C3\")\n    and \"vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> range_vars \\<alpha> = {}\" (is ?D1)\n    and \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> range_vars \\<alpha> = {}\" (is ?D2)\n    and \"fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> range_vars \\<alpha> = {}\" (is ?D3)\nproof -\n  define X where \"X \\<equiv> \\<Union>(vars_transaction ` set P) \\<union> vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\"\n\n  have 1: \"finite X\" by (simp add: X_def)\n\n  obtain n where n: \"n \\<ge> max_var_set X\" \"\\<alpha> = var_rename n\"\n    using assms unfolding transaction_renaming_subst_def X_def by moura\n  hence 2: \"\\<forall>x \\<in> X. snd x < Suc n\"\n    using less_Suc_max_var_set[OF _ 1] unfolding var_rename_def by fastforce\n  \n  have 3: \"x \\<notin> fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<alpha> ` X)\" \"fv (\\<alpha> x) \\<inter> X = {}\" \"x \\<notin> range_vars \\<alpha>\" when x: \"x \\<in> X\" for x\n    using 2 x n unfolding var_rename_def by force+\n\n  show ?A ?B using 3(1,2) unfolding X_def by auto\n\n  show ?C1 when T: \"T \\<in> set P\" using T 3(3) unfolding X_def by blast\n  thus ?C2 ?C3 when T: \"T \\<in> set P\"\n    using T by (simp_all add: disjoint_iff_not_equal vars\\<^sub>s\\<^sub>s\\<^sub>t_is_fv\\<^sub>s\\<^sub>s\\<^sub>t_bvars\\<^sub>s\\<^sub>s\\<^sub>t)\n\n  show ?D1 using 3(3) unfolding X_def by auto\n  thus ?D2 ?D3 by (simp_all add: disjoint_iff_not_equal vars\\<^sub>s\\<^sub>s\\<^sub>t_is_fv\\<^sub>s\\<^sub>s\\<^sub>t_bvars\\<^sub>s\\<^sub>s\\<^sub>t)\nqed\n\nlemma transaction_renaming_subst_wt:\n  fixes \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_renaming_subst \\<alpha> P A\"\n  shows \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<alpha>\"\nproof -\n  { fix x::\"('fun,'atom,'sets,'lbl) prot_var\"\n    obtain \\<tau> n where x: \"x = (\\<tau>,n)\" by moura\n    then obtain m where m: \"\\<alpha> x = Var (\\<tau>,m)\"\n      using assms transaction_renaming_subst_is_renaming(1) by moura\n    hence \"\\<Gamma> (\\<alpha> x) = \\<Gamma>\\<^sub>v x\" using x by (simp add: \\<Gamma>\\<^sub>v_def)\n  } thus ?thesis by (simp add: wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def)\nqed\n\nlemma transaction_renaming_subst_is_wf_trm:\n  fixes \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_renaming_subst \\<alpha> P A\"\n  shows \"wf\\<^sub>t\\<^sub>r\\<^sub>m (\\<alpha> v)\"\nproof -\n  obtain \\<tau> n where \"v = (\\<tau>, n)\" by moura\n  then obtain m where \"\\<alpha> v = Var (\\<tau>, n + Suc m)\"\n    using transaction_renaming_subst_is_renaming(1)[OF assms]\n    by moura\n  thus ?thesis by (metis wf_trm_Var)\nqed\n\nlemma transaction_renaming_subst_range_wf_trms:\n  fixes \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_renaming_subst \\<alpha> P A\"\n  shows \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<alpha>)\"\nby (metis transaction_renaming_subst_is_wf_trm[OF assms] wf_trm_subst_range_iff)\n\nlemma transaction_renaming_subst_range_notin_vars:\n  fixes \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_renaming_subst \\<alpha> P \\<A>\"\n  shows \"\\<exists>y. \\<alpha> x = Var y \\<and> y \\<notin> \\<Union>(vars_transaction ` set P) \\<union> vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>\"\nproof -\n  obtain \\<tau> n where x: \"x = (\\<tau>,n)\" by (metis surj_pair)\n\n  define y where \"y \\<equiv> \\<lambda>m. (\\<tau>,n+Suc m)\"\n\n  have \"\\<exists>m \\<ge> max_var_set (\\<Union>(vars_transaction ` set P) \\<union> vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>). \\<alpha> x = Var (y m)\"\n    using assms x by (auto simp add: y_def transaction_renaming_subst_def var_rename_def)\n  moreover have \"finite (\\<Union>(vars_transaction ` set P) \\<union> vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)\" by auto\n  ultimately show ?thesis using x unfolding y_def by force\nqed\n\nlemma transaction_renaming_subst_var_obtain:\n  fixes \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \\<alpha>: \"transaction_renaming_subst \\<alpha> P \\<A>\"\n  shows \"x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<alpha>) \\<Longrightarrow> \\<exists>y. \\<alpha> y = Var x\" (is \"?A1 \\<Longrightarrow> ?B1\")\n    and \"x \\<in> fv (t \\<cdot> \\<alpha>) \\<Longrightarrow> \\<exists>y \\<in> fv t. \\<alpha> y = Var x\" (is \"?A2 \\<Longrightarrow> ?B2\")\nproof -\n  assume x: ?A1\n  obtain y where y: \"y \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t S\" \"x \\<in> fv (\\<alpha> y)\" using fv\\<^sub>s\\<^sub>s\\<^sub>t_subst_obtain_var[OF x] by moura\n  thus ?B1 using transaction_renaming_subst_is_renaming(2)[OF \\<alpha>, of y] by fastforce\nnext\n  assume x: ?A2\n  obtain y where y: \"y \\<in> fv t\" \"x \\<in> fv (\\<alpha> y)\" using fv_subst_obtain_var[OF x] by moura\n  thus ?B2 using transaction_renaming_subst_is_renaming(2)[OF \\<alpha>, of y] by fastforce\nqed\n\nlemma transaction_renaming_subst_set_eq:\n  assumes \"set P1 = set P2\"\n  shows \"transaction_renaming_subst \\<alpha> P1 \\<A> = transaction_renaming_subst \\<alpha> P2 \\<A>\" (is \"?A = ?B\")\nusing assms unfolding transaction_renaming_subst_def by presburger\n\nlemma transaction_fresh_subst_is_wf_trm:\n  fixes \\<sigma>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_fresh_subst \\<sigma> T A\"\n  shows \"wf\\<^sub>t\\<^sub>r\\<^sub>m (\\<sigma> v)\"\nproof (cases \"v \\<in> subst_domain \\<sigma>\")\n  case True\n  then obtain c where \"\\<sigma> v = Fun c []\" \"arity c = 0\"\n    using assms unfolding transaction_fresh_subst_def\n    by moura\n  thus ?thesis by auto\nqed auto\n\nlemma transaction_fresh_subst_wt:\n  fixes \\<sigma>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_fresh_subst \\<sigma> T A\"\n  shows \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma>\"\nusing assms unfolding transaction_fresh_subst_def by blast\n\nlemma transaction_fresh_subst_domain:\n  fixes \\<sigma>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_fresh_subst \\<sigma> T \\<A>\"\n  shows \"subst_domain \\<sigma> = set (transaction_fresh T)\"\nusing assms unfolding transaction_fresh_subst_def by fast\n\nlemma transaction_fresh_subst_range_wf_trms:\n  fixes \\<sigma>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_fresh_subst \\<sigma> T \\<A>\"\n  shows \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<sigma>)\"\nby (metis transaction_fresh_subst_is_wf_trm[OF assms] wf_trm_subst_range_iff)\n\nlemma transaction_fresh_subst_range_fresh:\n  fixes \\<sigma>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_fresh_subst \\<sigma> T \\<A>\"\n  shows \"\\<forall>t \\<in> subst_range \\<sigma>. t \\<notin> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)\"\n    and \"\\<forall>t \\<in> subst_range \\<sigma>. t \\<notin> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T))\"\nusing assms unfolding transaction_fresh_subst_def by meson+\n\nlemma transaction_fresh_subst_sends_to_val:\n  fixes \\<sigma>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \\<sigma>: \"transaction_fresh_subst \\<sigma> T \\<A>\"\n    and y: \"y \\<in> set (transaction_fresh T)\" \"\\<Gamma>\\<^sub>v y = TAtom Value\"\n  obtains n where \"\\<sigma> y = Fun (Val n) []\" \"Fun (Val n) [] \\<in> subst_range \\<sigma>\"\nproof -\n  have \"\\<sigma> y \\<in> subst_range \\<sigma>\" using assms unfolding transaction_fresh_subst_def by simp\n\n  obtain c where c: \"\\<sigma> y = Fun c []\" \"\\<not>public c\" \"arity c = 0\"\n    using \\<sigma> y(1) unfolding transaction_fresh_subst_def by fastforce\n\n  have \"\\<Gamma> (\\<sigma> y) = TAtom Value\"\n    using \\<sigma> y(2) \\<Gamma>\\<^sub>v_TAtom''(2)[of y] wt_subst_trm''[of \\<sigma> \"Var y\"]\n    unfolding transaction_fresh_subst_def by simp\n  then obtain n where \"c = Val n\"\n    using c by (cases c) (auto split: option.splits)\n  thus ?thesis\n    using c that unfolding transaction_fresh_subst_def\n    by fastforce\nqed\n\nlemma transaction_fresh_subst_sends_to_val':\n  fixes \\<sigma> \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_fresh_subst \\<sigma> T \\<A>\"\n    and \"y \\<in> set (transaction_fresh T)\" \"\\<Gamma>\\<^sub>v y = TAtom Value\"\n  obtains n where \"(\\<sigma> \\<circ>\\<^sub>s \\<alpha>) y \\<cdot> \\<I> = Fun (Val n) []\" \"Fun (Val n) [] \\<in> subst_range \\<sigma>\" \nproof -\n  obtain n where \"\\<sigma> y = Fun (Val n) []\" \"Fun (Val n) [] \\<in> subst_range \\<sigma>\"\n    using transaction_fresh_subst_sends_to_val[OF assms] by moura\n  thus ?thesis using that by (fastforce simp add: subst_compose_def)\nqed\n\nlemma transaction_fresh_subst_grounds_domain:\n  fixes \\<sigma>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_fresh_subst \\<sigma> T \\<A>\"\n    and \"y \\<in> set (transaction_fresh T)\"\n  shows \"fv (\\<sigma> y) = {}\"\nproof -\n  obtain c where \"\\<sigma> y = Fun c []\"\n    using assms unfolding transaction_fresh_subst_def by moura\n  thus ?thesis by simp\nqed\n\nlemma transaction_fresh_subst_range_vars_empty:\n  fixes \\<sigma>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_fresh_subst \\<sigma> T \\<A>\"\n  shows \"range_vars \\<sigma> = {}\"\nproof -\n  have \"fv t = {}\" when \"t \\<in> subst_range \\<sigma>\" for t\n    using assms that unfolding transaction_fresh_subst_def by fastforce\n  thus ?thesis unfolding range_vars_def by blast\nqed\n\nlemma transaction_decl_fresh_renaming_substs_range:\n  fixes \\<xi> \\<sigma> \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \\<xi>: \"transaction_decl_subst \\<xi> T\"\n    and \\<sigma>: \"transaction_fresh_subst \\<sigma> T \\<A>\"\n    and \\<alpha>: \"transaction_renaming_subst \\<alpha> P \\<A>\"\n  shows \"x \\<in> fst ` set (transaction_decl T ()) \\<Longrightarrow>\n          \\<exists>c. (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x = Fun c [] \\<and> arity c = 0\"\n    and \"x \\<notin> fst ` set (transaction_decl T ()) \\<Longrightarrow>\n          x \\<in> set (transaction_fresh T) \\<Longrightarrow>\n            \\<exists>c. (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x = Fun c [] \\<and> \\<not>public c \\<and> arity c = 0\"\n    and \"x \\<notin> fst ` set (transaction_decl T ()) \\<Longrightarrow>\n          x \\<in> set (transaction_fresh T) \\<Longrightarrow>\n          fst x = TAtom Value \\<Longrightarrow>\n            \\<exists>n. (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x = Fun (Val n) []\"\n    and \"x \\<notin> fst ` set (transaction_decl T ()) \\<Longrightarrow>\n          x \\<notin> set (transaction_fresh T) \\<Longrightarrow>\n            \\<exists>y. (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x = Var y\"\nproof -\n  assume \"x \\<in> fst ` set (transaction_decl T ())\"\n  then obtain c where c: \"\\<xi> x = Fun c []\" \"arity c = 0\"\n    using \\<xi> unfolding transaction_decl_subst_def by fastforce\n  thus \"\\<exists>c. (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x = Fun c [] \\<and> arity c = 0\"\n    using subst_compose[of \"\\<xi> \\<circ>\\<^sub>s \\<sigma>\" \\<alpha> x] subst_compose[of \\<xi> \\<sigma> x] by simp\nnext\n  assume x: \"x \\<notin> fst ` set (transaction_decl T ())\"\n            \"x \\<in> set (transaction_fresh T)\"\n\n  have *: \"(\\<xi> \\<circ>\\<^sub>s \\<sigma>) x = \\<sigma> x\"\n    using x(1) \\<xi> unfolding transaction_decl_subst_def\n    by (metis (no_types, opaque_lifting) subst_comp_notin_dom_eq)\n  then obtain c where c: \"(\\<xi> \\<circ>\\<^sub>s \\<sigma>) x = Fun c []\" \"\\<not>public c\" \"arity c = 0\"\n    using \\<sigma> x(2) unfolding transaction_fresh_subst_def by fastforce\n  thus \"\\<exists>c. (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x = Fun c [] \\<and> \\<not>public c \\<and> arity c = 0\"\n    using subst_compose[of \"\\<xi> \\<circ>\\<^sub>s \\<sigma>\" \\<alpha> x] subst_compose[of \\<xi> \\<sigma> x] by simp\n\n  assume \"fst x = TAtom Value\"\n  hence \"\\<Gamma> ((\\<xi> \\<circ>\\<^sub>s \\<sigma>) x) = TAtom Value\"\n    using * \\<sigma> \\<Gamma>\\<^sub>v_TAtom''(2)[of x] wt_subst_trm''[of \\<sigma> \"Var x\"]\n    unfolding transaction_fresh_subst_def by simp\n  then obtain n where \"c = Val n\"\n    using c by (cases c) (auto split: option.splits)\n  thus \"\\<exists>n. (\\<xi> \\<circ>\\<^sub>s\\<sigma> \\<circ>\\<^sub>s \\<alpha>) x = Fun (Val n) []\"\n    using c subst_compose[of \"\\<xi> \\<circ>\\<^sub>s \\<sigma>\" \\<alpha> x] subst_compose[of \\<xi> \\<sigma> x] by simp\nnext\n  assume \"x \\<notin> fst ` set (transaction_decl T ())\"\n         \"x \\<notin> set (transaction_fresh T)\"\n  hence \"(\\<xi> \\<circ>\\<^sub>s \\<sigma>) x = Var x\"\n    using \\<xi> \\<sigma>\n    unfolding transaction_decl_subst_def transaction_fresh_subst_def\n    by (metis (no_types, opaque_lifting) subst_comp_notin_dom_eq subst_domI)\n  thus \"\\<exists>y. (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x = Var y\"\n    using transaction_renaming_subst_is_renaming(1)[OF \\<alpha>]\n          subst_compose[of \"\\<xi> \\<circ>\\<^sub>s \\<sigma>\" \\<alpha> x] subst_compose[of \\<xi> \\<sigma> x]\n    by (cases x) force\nqed\n\nlemma transaction_decl_fresh_renaming_substs_range':\n  fixes \\<sigma> \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \\<xi>: \"transaction_decl_subst \\<xi> T\"\n    and \\<sigma>: \"transaction_fresh_subst \\<sigma> T \\<A>\"\n    and \\<alpha>: \"transaction_renaming_subst \\<alpha> P \\<A>\"\n    and t: \"t \\<in> subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n  shows \"(\\<exists>c. t = Fun c [] \\<and> arity c = 0) \\<or> (\\<exists>x. t = Var x)\"\n    and \"\\<xi> = Var \\<Longrightarrow> (\\<exists>c. t = Fun c [] \\<and> \\<not>public c \\<and> arity c = 0) \\<or> (\\<exists>x. t = Var x)\"\n    and \"\\<xi> = Var \\<Longrightarrow> \\<forall>x \\<in> set (transaction_fresh T). \\<Gamma>\\<^sub>v x = TAtom Value \\<Longrightarrow>\n                      (\\<exists>n. t = Fun (Val n) []) \\<or> (\\<exists>x. t = Var x)\"\n    and \"\\<xi> = Var \\<Longrightarrow> is_Fun t \\<Longrightarrow> t \\<in> subst_range \\<sigma>\"\nproof -\n  obtain x where x: \"x \\<in> subst_domain (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\" \"(\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x = t\"\n    using t by auto\n\n  note 0 = x transaction_decl_fresh_renaming_substs_range[OF \\<xi> \\<sigma> \\<alpha>, of x]\n\n  show \"(\\<exists>c. t = Fun c [] \\<and> arity c = 0) \\<or> (\\<exists>x. t = Var x)\"\n    using 0 unfolding \\<Gamma>\\<^sub>v_TAtom'' by auto\n\n  assume 1: \"\\<xi> = Var\"\n\n  note 2 = transaction_decl_subst_empty_inv[OF \\<xi>[unfolded 1]]\n\n  show 3: \"(\\<exists>c. t = Fun c [] \\<and> \\<not>public c \\<and> arity c = 0) \\<or> (\\<exists>x. t = Var x)\"\n    using 0 2 unfolding \\<Gamma>\\<^sub>v_TAtom'' by auto\n\n  show \"(\\<exists>n. t = Fun (Val n) []) \\<or> (\\<exists>x. t = Var x)\"\n    when \"\\<forall>x \\<in> set (transaction_fresh T). \\<Gamma>\\<^sub>v x = TAtom Value\"\n    using 0 2 that unfolding \\<Gamma>\\<^sub>v_TAtom'' by auto\n\n  show \"t \\<in> subst_range \\<sigma>\" when t': \"is_Fun t\"\n  proof -\n    obtain x where x: \"(\\<sigma> \\<circ>\\<^sub>s \\<alpha>) x = t\" using t 1 by auto\n    \n    show ?thesis\n    proof (cases \"x \\<in> subst_domain \\<sigma>\")\n      case True thus ?thesis\n        by (metis subst_dom_vars_in_subst subst_ground_ident_compose(1) subst_imgI x\n                  transaction_fresh_subst_grounds_domain[OF \\<sigma>]\n                  transaction_fresh_subst_domain[OF \\<sigma>]) \n    next\n      case False thus ?thesis\n        by (metis (no_types, lifting) subst_compose_def subst_domI term.disc(1) that\n                  transaction_renaming_subst_is_renaming(5)[OF \\<alpha>] var_renaming_is_Fun_iff x)\n    qed\n  qed\nqed\n\nlemma transaction_decl_fresh_renaming_substs_range'':\n  fixes \\<xi> \\<sigma> \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \\<xi>: \"transaction_decl_subst \\<xi> T\"\n    and \\<sigma>: \"transaction_fresh_subst \\<sigma> T \\<A>\"\n    and \\<alpha>: \"transaction_renaming_subst \\<alpha> P \\<A>\"\n    and y: \"y \\<in> fv ((\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x)\"\n  shows \"\\<xi> x = Var x\"\n    and \"\\<sigma> x = Var x\"\n    and \"\\<alpha> x = Var y\"\n    and \"(\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x = Var y\"\nproof -\n  have \"\\<exists>z. z \\<in> fv (\\<xi> x)\" by (metis y subst_compose_fv')\n  hence \"x \\<notin> subst_domain \\<xi>\"\n    using y transaction_decl_subst_domain[OF \\<xi>]\n          transaction_decl_subst_grounds_domain[OF \\<xi>, of x]\n    by blast\n  thus 0: \"\\<xi> x = Var x\" by blast\n  hence \"y \\<in> fv ((\\<sigma> \\<circ>\\<^sub>s \\<alpha>) x)\" using y by (simp add: subst_compose)\n  hence \"\\<exists>z. z \\<in> fv (\\<sigma> x)\" by (metis subst_compose_fv')\n  hence \"x \\<notin> subst_domain \\<sigma>\"\n    using y transaction_fresh_subst_domain[OF \\<sigma>]\n          transaction_fresh_subst_grounds_domain[OF \\<sigma>, of x]\n    by blast\n  thus 1: \"\\<sigma> x = Var x\" by blast\n  \n  show \"\\<alpha> x = Var y\" \"(\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x = Var y\"\n    using 0 1 y transaction_renaming_subst_is_renaming(2)[OF \\<alpha>, of x]\n    unfolding subst_compose_def by (fastforce,fastforce)\nqed\n\nlemma transaction_decl_fresh_renaming_substs_vars_subset:\n  fixes \\<xi> \\<sigma> \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \\<xi>: \"transaction_decl_subst \\<xi> T\"\n    and \\<sigma>: \"transaction_fresh_subst \\<sigma> T \\<A>\"\n    and \\<alpha>: \"transaction_renaming_subst \\<alpha> P \\<A>\"\n  shows \"\\<Union>(fv_transaction ` set P) \\<subseteq> subst_domain (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\" (is ?A)\n    and \"fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<subseteq> subst_domain (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\" (is ?B)\n    and \"T' \\<in> set P \\<Longrightarrow> fv_transaction T' \\<subseteq> subst_domain (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\" (is \"T' \\<in> set P \\<Longrightarrow> ?C\")\n    and \"T' \\<in> set P \\<Longrightarrow> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T' \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)) \\<subseteq> range_vars (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n      (is \"T' \\<in> set P \\<Longrightarrow> ?D\")\nproof -\n  have *: \"x \\<in> subst_domain (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\" for x\n  proof (cases \"x \\<in> subst_domain \\<xi>\")\n    case True thus ?thesis\n      using transaction_decl_subst_domain[OF \\<xi>] transaction_decl_subst_grounds_domain[OF \\<xi>]\n      by (simp add: subst_domI subst_dom_vars_in_subst subst_ground_ident_compose(1))\n  next\n    case False\n    hence \\<xi>_x_eq: \"(\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x = (\\<sigma> \\<circ>\\<^sub>s \\<alpha>) x\" by (auto simp add: subst_compose)\n\n    show ?thesis\n    proof (cases \"x \\<in> subst_domain \\<sigma>\")\n      case True\n      hence \"x \\<notin> {x. \\<exists>y. \\<sigma> x = Var y \\<and> \\<alpha> y = Var x}\"\n        using transaction_fresh_subst_domain[OF \\<sigma>]\n              transaction_fresh_subst_grounds_domain[OF \\<sigma>, of x]\n        by auto\n      hence \"x \\<in> subst_domain (\\<sigma> \\<circ>\\<^sub>s \\<alpha>)\" using subst_domain_subst_compose[of \\<sigma> \\<alpha>] by blast\n      thus ?thesis using \\<xi>_x_eq subst_dom_vars_in_subst by fastforce \n    next\n      case False\n      hence \"(\\<sigma> \\<circ>\\<^sub>s \\<alpha>) x = \\<alpha> x\" unfolding subst_compose_def by fastforce\n      moreover have \"\\<alpha> x \\<noteq> Var x\"\n        using transaction_renaming_subst_is_renaming(1)[OF \\<alpha>] by (cases x) auto\n      ultimately show ?thesis using \\<xi>_x_eq by fastforce\n    qed\n  qed\n  \n  show ?A ?B using * by blast+\n\n  show ?C when T: \"T' \\<in> set P\" using T * by blast\n  hence \"fv\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (transaction_strand T') \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) \\<subseteq> range_vars (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n    when T: \"T' \\<in> set P\"\n    using T fv\\<^sub>s\\<^sub>s\\<^sub>t_subst_subset_range_vars_if_subset_domain by blast\n  thus ?D when T: \"T' \\<in> set P\" by (metis T unlabel_subst)\nqed\n\nlemma transaction_decl_fresh_renaming_substs_vars_disj:\n  fixes \\<xi> \\<sigma> \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \\<xi>: \"transaction_decl_subst \\<xi> T\"\n    and \\<sigma>: \"transaction_fresh_subst \\<sigma> T \\<A>\"\n    and \\<alpha>: \"transaction_renaming_subst \\<alpha> P \\<A>\"\n  shows \"fv\\<^sub>s\\<^sub>e\\<^sub>t ((\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) ` (\\<Union>(vars_transaction ` set P))) \\<inter> (\\<Union>(vars_transaction ` set P)) = {}\"\n      (is ?A)\n    and \"x \\<in> \\<Union>(vars_transaction ` set P) \\<Longrightarrow> fv ((\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x) \\<inter> (\\<Union>(vars_transaction ` set P)) = {}\"\n      (is \"?B' \\<Longrightarrow> ?B\")\n    and \"T' \\<in> set P \\<Longrightarrow> vars_transaction T' \\<inter> range_vars (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) = {}\" (is \"T' \\<in> set P \\<Longrightarrow> ?C1\")\n    and \"T' \\<in> set P \\<Longrightarrow> bvars_transaction T' \\<inter> range_vars (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) = {}\" (is \"T' \\<in> set P \\<Longrightarrow> ?C2\")\n    and \"T' \\<in> set P \\<Longrightarrow> fv_transaction T' \\<inter> range_vars (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) = {}\" (is \"T' \\<in> set P \\<Longrightarrow> ?C3\")\n    and \"vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<inter> range_vars (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) = {}\" (is ?D1)\n    and \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<inter> range_vars (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) = {}\" (is ?D2)\n    and \"fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<inter> range_vars (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) = {}\" (is ?D3)\nproof -\n  note 0 = transaction_renaming_subst_vars_disj[OF \\<alpha>]\n\n  show ?A\n  proof (cases \"fv\\<^sub>s\\<^sub>e\\<^sub>t ((\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) ` (\\<Union>(vars_transaction ` set P))) = {}\")\n    case False\n    hence \"\\<forall>x \\<in> (\\<Union>(vars_transaction ` set P)). (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x = \\<alpha> x \\<or> fv ((\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x) = {}\"\n      using transaction_decl_fresh_renaming_substs_range''[OF \\<xi> \\<sigma> \\<alpha>] by auto\n    thus ?thesis using 0(1) by force\n  qed blast\n  thus \"?B' \\<Longrightarrow> ?B\" by auto\n\n  have \"range_vars \\<xi> = {}\" \"range_vars \\<sigma> = {}\"\n    using transaction_fresh_subst_grounds_domain[OF \\<sigma>]\n          transaction_decl_subst_grounds_domain[OF \\<xi>]\n    unfolding transaction_fresh_subst_domain[OF \\<sigma>, symmetric]\n              transaction_decl_subst_domain[OF \\<xi>, symmetric]\n    by (fastforce, fastforce)\n  hence 1: \"range_vars (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) \\<subseteq> range_vars \\<alpha>\"\n    using range_vars_subst_compose_subset[of \\<xi> \\<sigma>]\n          range_vars_subst_compose_subset[of \"\\<xi> \\<circ>\\<^sub>s \\<sigma>\" \\<alpha>]\n    by blast\n  \n  show ?C1 ?C2 ?C3 when T: \"T' \\<in> set P\" using T 1 0(3,4,5)[of T'] by blast+\n\n  show ?D1 ?D2 ?D3 using 1 0(6,7,8) by blast+\nqed\n\nlemma transaction_decl_fresh_renaming_substs_trms:\n  fixes \\<xi> \\<sigma> \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \\<xi>: \"transaction_decl_subst \\<xi> T\"\n    and \\<sigma>: \"transaction_fresh_subst \\<sigma> T \\<A>\"\n    and \\<alpha>: \"transaction_renaming_subst \\<alpha> P \\<A>\"\n    and \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t S \\<inter> subst_domain \\<xi> = {}\"\n    and \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t S \\<inter> subst_domain \\<sigma> = {}\"\n    and \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t S \\<inter> subst_domain \\<alpha> = {}\"\n  shows \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))) = subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t S) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\nproof -\n  have 1: \"\\<forall>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t S). (\\<exists>f. (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x = Fun f []) \\<or> (\\<exists>y. (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x = Var y)\"\n    using transaction_decl_fresh_renaming_substs_range'[OF \\<xi> \\<sigma> \\<alpha>] by blast\n\n  have 2: \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t S \\<inter> subst_domain (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) = {}\"\n    using assms(4-6) subst_domain_compose[of \\<xi> \\<sigma>] subst_domain_compose[of \"\\<xi> \\<circ>\\<^sub>s \\<sigma>\" \\<alpha>] by blast\n\n  show ?thesis using subterms_subst_lsst[OF 1 2] by simp\nqed\n\nlemma transaction_decl_fresh_renaming_substs_wt:\n  fixes \\<xi> \\<sigma> \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_decl_subst \\<xi> T\" \"transaction_fresh_subst \\<sigma> T \\<A>\"\n          \"transaction_renaming_subst \\<alpha> P \\<A>\"\n  shows \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\nusing transaction_renaming_subst_wt[OF assms(3)]\n      transaction_fresh_subst_wt[OF assms(2)]\n      transaction_decl_subst_wt[OF assms(1)]\nby (metis wt_subst_compose)\n\nlemma transaction_decl_fresh_renaming_substs_range_wf_trms:\n  fixes \\<xi> \\<sigma> \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \"transaction_decl_subst \\<xi> T\" \"transaction_fresh_subst \\<sigma> T \\<A>\"\n          \"transaction_renaming_subst \\<alpha> P \\<A>\"\n  shows \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\nusing transaction_renaming_subst_range_wf_trms[OF assms(3)]\n      transaction_fresh_subst_range_wf_trms[OF assms(2)]\n      transaction_decl_subst_range_wf_trms[OF assms(1)]\n      wf_trms_subst_compose[of \\<xi> \\<sigma>]\n      wf_trms_subst_compose[of \"\\<xi> \\<circ>\\<^sub>s \\<sigma>\" \\<alpha>]\nby metis\n\nlemma transaction_decl_fresh_renaming_substs_fv:\n  fixes \\<sigma> \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \\<xi>: \"transaction_decl_subst \\<xi> T\"\n    and \\<sigma>: \"transaction_fresh_subst \\<sigma> T A\"\n    and \\<alpha>: \"transaction_renaming_subst \\<alpha> P A\"\n    and x: \"x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n  shows \"\\<exists>y \\<in> fv_transaction T - set (transaction_fresh T). (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) y = Var x\"\nproof -\n  have \"x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (transaction_strand T) \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n    using x fv\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq[of \"transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n          unlabel_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n    by argo\n  then obtain y where \"y \\<in> fv_transaction T\" \"x \\<in> fv ((\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) y)\"\n    by (metis fv\\<^sub>s\\<^sub>s\\<^sub>t_subst_obtain_var)\n  thus ?thesis\n    using transaction_decl_fresh_renaming_substs_range[OF \\<xi> \\<sigma> \\<alpha>, of y]\n    by (cases \"y \\<in> set (transaction_fresh T)\") force+\nqed\n\nlemma transaction_decl_fresh_renaming_substs_range_no_attack_const:\n  fixes \\<xi> \\<sigma> \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes \\<xi>: \"transaction_decl_subst \\<xi> T\"\n    and \\<sigma>: \"transaction_fresh_subst \\<sigma> T A\"\n    and \\<alpha>: \"transaction_renaming_subst \\<alpha> P A\"\n    and T: \"\\<forall>x \\<in> set (transaction_fresh T). \\<Gamma>\\<^sub>v x = TAtom Value \\<or> (\\<exists>a. \\<Gamma>\\<^sub>v x = TAtom (Atom a))\"\n    and t: \"t \\<in> subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n  shows \"\\<nexists>n. t = attack\\<langle>n\\<rangle>\"\nproof -\n  note \\<xi>\\<sigma>\\<alpha>_wt = transaction_decl_fresh_renaming_substs_wt[OF \\<xi> \\<sigma> \\<alpha>]\n\n  obtain x where x: \"(\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x = t\" using t by auto\n\n  have x_type: \"\\<Gamma> (Var x) = \\<Gamma> (Var x \\<cdot> \\<xi>)\" \"\\<Gamma> (Var x) = \\<Gamma> (Var x \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n    using \\<xi> wt_subst_trm''[of \\<xi> \"Var x\"] wt_subst_trm''[OF \\<xi>\\<sigma>\\<alpha>_wt, of \"Var x\"]\n    unfolding transaction_decl_subst_def by (blast, blast)\n\n  show ?thesis\n  proof (cases t)\n    case (Fun f S)\n    hence \"x \\<in> set (transaction_fresh T) \\<or> x \\<in> fst ` set (transaction_decl T ())\"\n      using transaction_decl_fresh_renaming_substs_range[OF \\<xi> \\<sigma> \\<alpha>, of x] x by force\n    thus ?thesis\n    proof\n      assume \"x \\<in> set (transaction_fresh T)\"\n      hence \"\\<Gamma> t = TAtom Value \\<or> (\\<exists>a. \\<Gamma> t = TAtom (Atom a))\"\n        using T x_type(2) x by (metis \\<Gamma>.simps(1) subst_apply_term.simps(1))\n      thus ?thesis by auto\n    next\n      assume \"x \\<in> fst ` set (transaction_decl T ())\"\n      then obtain c where c: \"\\<xi> x = Fun (Fu c) []\" \"arity\\<^sub>f c = 0\"\n        using \\<xi> unfolding transaction_decl_subst_def by auto\n\n      have \"\\<Gamma> t = TAtom Bottom \\<or> (\\<exists>a. \\<Gamma> t = TAtom (Atom a))\"\n        using c(1) \\<Gamma>_consts_simps(1)[OF c(2)] x x_type\n              subst_apply_term.simps(1)[of x \\<xi>] subst_apply_term.simps(1)[of x \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n        by (cases \"\\<Gamma>\\<^sub>f c\") simp_all\n      thus ?thesis by auto\n    qed\n  qed simp\nqed\n\nlemma transaction_decl_fresh_renaming_substs_occurs_fact_send_receive:\n  fixes t::\"('fun,'atom,'sets,'lbl) prot_term\"\n  assumes \\<xi>: \"transaction_decl_subst \\<xi> T\"\n    and \\<sigma>: \"transaction_fresh_subst \\<sigma> T \\<A>\"\n    and \\<alpha>: \"transaction_renaming_subst \\<alpha> P \\<A>\"\n    and T: \"admissible_transaction T\"\n    and t: \"occurs t \\<in> set ts\"\n  shows \"send\\<langle>ts\\<rangle> \\<in> set (unlabel (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\n          \\<Longrightarrow> \\<exists>ts' s. send\\<langle>ts'\\<rangle> \\<in> set (unlabel (transaction_send T)) \\<and>\n                      occurs s \\<in> set ts' \\<and> t = s \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n      (is \"?A \\<Longrightarrow> ?A'\")\n    and \"receive\\<langle>ts\\<rangle> \\<in> set (unlabel (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\n          \\<Longrightarrow> \\<exists>ts' s. receive\\<langle>ts'\\<rangle> \\<in> set (unlabel (transaction_receive T)) \\<and>\n                      occurs s \\<in> set ts' \\<and> t = s \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n      (is \"?B \\<Longrightarrow> ?B'\")\nproof -\n  assume ?A\n  then obtain s ts' where s:\n      \"s \\<in> set ts'\" \"send\\<langle>ts'\\<rangle> \\<in> set (unlabel (transaction_strand T))\" \"occurs t = s \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n    using t stateful_strand_step_mem_substD(1)[\n            of ts \"unlabel (transaction_strand T)\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n          unlabel_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n    by auto\n\n  note \\<xi>_empty = admissible_transaction_decl_subst_empty[OF T \\<xi>]\n\n  have T_decl_notin: \"x \\<notin> fst ` set (transaction_decl T ())\" for x\n    using transaction_decl_subst_empty_inv[OF \\<xi>[unfolded \\<xi>_empty]] by simp\n\n  note 0 = s(3) transaction_decl_fresh_renaming_substs_range[OF \\<xi> \\<sigma> \\<alpha>]\n\n  note T_wf = admissible_transaction_is_wellformed_transaction(1)[OF T]\n  note T_fresh = admissible_transactionE(14)[OF T]\n\n  have \"\\<exists>u. s = occurs u\"\n  proof (cases s)\n    case (Var x) \n    hence \"(\\<exists>c. s \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> = Fun c []) \\<or> (\\<exists>y. s \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> = Var y)\"\n      using 0(2-5)[of x] \\<xi>_empty by (auto simp del: subst_subst_compose)\n    thus ?thesis\n      using 0(1) by simp\n  next\n    case (Fun f T)\n    hence 1: \"f = OccursFact\" \"length T = 2\" \"T ! 0 \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> = Fun OccursSec []\"\n             \"T ! 1 \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> = t\"\n      using 0(1) by auto\n    have \"T ! 0 = Fun OccursSec []\"\n    proof (cases \"T ! 0\")\n      case (Var x) thus ?thesis\n        using 0(2-5)[of x] 1(3) T_fresh T_decl_notin\n        unfolding list_all_iff by (auto simp del: subst_subst_compose)\n    qed (use 1(3) in simp)\n    thus ?thesis using Fun 1 0(1) by (auto simp del: subst_subst_compose)\n  qed\n  then obtain u where u: \"s = occurs u\" by moura\n  hence \"t = u \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\" using s(3) by fastforce\n  thus ?A' using s u wellformed_transaction_strand_unlabel_memberD(8)[OF T_wf] by metis\nnext\n  assume ?B\n  then obtain s ts' where s:\n      \"s \\<in> set ts'\" \"receive\\<langle>ts'\\<rangle> \\<in> set (unlabel (transaction_strand T))\" \"occurs t = s \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n    using t stateful_strand_step_mem_substD(2)[\n            of ts \"unlabel (transaction_strand T)\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n          unlabel_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n    by auto\n\n  note \\<xi>_empty = admissible_transaction_decl_subst_empty[OF T \\<xi>]\n\n  have T_decl_notin: \"x \\<notin> fst ` set (transaction_decl T ())\" for x\n    using transaction_decl_subst_empty_inv[OF \\<xi>[unfolded \\<xi>_empty]] by simp\n\n  note 0 = s(3) transaction_decl_fresh_renaming_substs_range[OF \\<xi> \\<sigma> \\<alpha>]\n\n  note T_wf = admissible_transaction_is_wellformed_transaction(1)[OF T]\n  note T_fresh = admissible_transactionE(14)[OF T]\n\n  have \"\\<exists>u. s = occurs u\"\n  proof (cases s)\n    case (Var x) \n    hence \"(\\<exists>c. s \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> = Fun c []) \\<or> (\\<exists>y. s \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> = Var y)\"\n      using 0(2-5)[of x] \\<xi>_empty by (auto simp del: subst_subst_compose)\n    thus ?thesis\n      using 0(1) by simp\n  next\n    case (Fun f T)\n    hence 1: \"f = OccursFact\" \"length T = 2\" \"T ! 0 \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> = Fun OccursSec []\"\n              \"T ! 1 \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> = t\"\n      using 0(1) by auto\n    have \"T ! 0 = Fun OccursSec []\"\n    proof (cases \"T ! 0\")\n      case (Var x) thus ?thesis\n        using 0(2-5)[of x] 1(3) T_fresh T_decl_notin\n        unfolding list_all_iff by (auto simp del: subst_subst_compose)\n    qed (use 1(3) in simp)\n    thus ?thesis using Fun 1 0(1) by (auto simp del: subst_subst_compose)\n  qed\n  then obtain u where u: \"s = occurs u\" by moura\n  hence \"t = u \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\" using s(3) by fastforce\n  thus ?B' using s u wellformed_transaction_strand_unlabel_memberD(1)[OF T_wf] by metis\nqed\n\nlemma transaction_decl_subst_proj:\n  assumes \"transaction_decl_subst \\<xi> T\"\n  shows \"transaction_decl_subst \\<xi> (transaction_proj n T)\"\nusing assms transaction_proj_decl_eq[of n T]\nunfolding transaction_decl_subst_def by presburger\n\nlemma transaction_fresh_subst_proj:\n  assumes \"transaction_fresh_subst \\<sigma> T A\"\n  shows \"transaction_fresh_subst \\<sigma> (transaction_proj n T) (proj n A)\"\nusing assms transaction_proj_fresh_eq[of n T]\n      contra_subsetD[OF subterms\\<^sub>s\\<^sub>e\\<^sub>t_mono[OF transaction_proj_trms_subset[of n T]]]\n      contra_subsetD[OF subterms\\<^sub>s\\<^sub>e\\<^sub>t_mono[OF trms\\<^sub>s\\<^sub>s\\<^sub>t_proj_subset(1)[of n A]]]\nunfolding transaction_fresh_subst_def by metis\n  \nlemma transaction_renaming_subst_proj:\n  assumes \"transaction_renaming_subst \\<alpha> P A\"\n  shows \"transaction_renaming_subst \\<alpha> (map (transaction_proj n) P) (proj n A)\"\nproof -\n  let ?X = \"\\<lambda>P A. \\<Union>(vars_transaction ` set P) \\<union> vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\"\n  define Y where \"Y \\<equiv> ?X (map (transaction_proj n) P) (proj n A)\"\n  define Z where \"Z \\<equiv> ?X P A\"\n\n  have \"Y \\<subseteq> Z\"\n    using sst_vars_proj_subset(3)[of n A] transaction_proj_vars_subset[of n]\n    unfolding Y_def Z_def by fastforce\n  hence \"insert 0 (snd ` Y) \\<subseteq> insert 0 (snd ` Z)\" by blast\n  moreover have \"finite (insert 0 (snd ` Z))\" \"finite (insert 0 (snd ` Y))\"\n    unfolding Y_def Z_def by auto\n  ultimately have 0: \"max_var_set Y \\<le> max_var_set Z\" using Max_mono by blast\n\n  have \"\\<exists>n\\<ge>max_var_set Z. \\<alpha> = var_rename n\"\n    using assms unfolding transaction_renaming_subst_def Z_def by blast\n  hence \"\\<exists>n\\<ge>max_var_set Y. \\<alpha> = var_rename n\" using 0 le_trans by fast\n  thus ?thesis unfolding transaction_renaming_subst_def Y_def by blast\nqed\n\nlemma transaction_decl_fresh_renaming_substs_wf_sst:\n  fixes \\<xi> \\<sigma> \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  assumes T: \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (fst ` set (transaction_decl T ()) \\<union> set (transaction_fresh T))\n                    (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T)))\"\n    and \\<xi>: \"transaction_decl_subst \\<xi> T\"\n    and \\<sigma>: \"transaction_fresh_subst \\<sigma> T \\<A>\"\n    and \\<alpha>: \"transaction_renaming_subst \\<alpha> P \\<A>\"\n  shows \"wf'\\<^sub>s\\<^sub>s\\<^sub>t {} (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)))\"\nproof -\n  have 0: \"range_vars \\<xi> \\<inter> bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T)) = {}\"\n          \"range_vars \\<sigma> \\<inter> bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T) \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi>) = {}\"\n          \"ground (\\<xi> ` (fst ` set (transaction_decl T ())))\"\n          \"ground (\\<sigma> ` set (transaction_fresh T))\"\n          \"ground (\\<alpha> ` {})\"\n    using transaction_decl_subst_domain[OF \\<xi>]\n          transaction_decl_subst_grounds_domain[OF \\<xi>]\n          transaction_decl_subst_range_vars_empty[OF \\<xi>]\n          transaction_fresh_subst_range_vars_empty[OF \\<sigma>]\n          transaction_fresh_subst_domain[OF \\<sigma>]\n          transaction_fresh_subst_grounds_domain[OF \\<sigma>]\n    by (simp, simp, simp, simp, simp)\n\n  have 1: \"fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<xi> ` set (transaction_fresh T)) \\<subseteq> set (transaction_fresh T)\" (is \"?A \\<subseteq> ?B\")\n  proof\n    fix x assume x: \"x \\<in> ?A\"\n    then obtain y where y: \"y \\<in> set (transaction_fresh T)\" \"x \\<in> fv (\\<xi> y)\" by auto\n    hence \"y \\<notin> subst_domain \\<xi>\"\n      using transaction_decl_subst_domain[OF \\<xi>]\n            transaction_decl_subst_grounds_domain[OF \\<xi>]\n      by fast\n    thus \"x \\<in> ?B\" using x y by auto\n  qed\n\n  let ?X = \"fst ` set (transaction_decl T ()) \\<union> set (transaction_fresh T)\"\n\n  have \"fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<alpha> ` fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<sigma> ` fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<xi> ` ?X))) = {}\" using 0(3-5) 1 by auto\n  hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t {} (((unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T)) \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<xi>) \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<sigma>) \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<alpha>)\"\n    by (metis wf\\<^sub>s\\<^sub>s\\<^sub>t_subst_apply[OF wf\\<^sub>s\\<^sub>s\\<^sub>t_subst_apply[OF wf\\<^sub>s\\<^sub>s\\<^sub>t_subst_apply[OF T]]])\n  thus ?thesis\n    using dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_subst unlabel_subst\n          labeled_stateful_strand_subst_comp[OF 0(1), of \"\\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n          labeled_stateful_strand_subst_comp[OF 0(2), of \\<alpha>]\n          subst_compose_assoc[of \\<xi> \\<sigma> \\<alpha>]\n    by metis\nqed\n\n\nsubsection \\<open>Lemmata: Reachable Constraints\\<close>\nlemma reachable_constraints_as_transaction_lists:\n  fixes f\n  defines \"f \\<equiv> \\<lambda>(T,\\<xi>,\\<sigma>,\\<alpha>). dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n    and \"g \\<equiv> concat \\<circ> map f\"\n  assumes A: \"A \\<in> reachable_constraints P\"\n  obtains Ts where \"A = g Ts\"\n    and \"\\<forall>B. prefix B Ts \\<longrightarrow> g B \\<in> reachable_constraints P\"\n    and \"\\<forall>B T \\<xi> \\<sigma> \\<alpha>. prefix (B@[(T,\\<xi>,\\<sigma>,\\<alpha>)]) Ts \\<longrightarrow>\n                      T \\<in> set P \\<and> transaction_decl_subst \\<xi> T \\<and>\n                      transaction_fresh_subst \\<sigma> T (g B) \\<and> transaction_renaming_subst \\<alpha> P (g B)\"\nproof -\n  let ?P1 = \"\\<lambda>A Ts. A = g Ts\"\n  let ?P2 = \"\\<lambda>Ts. \\<forall>B. prefix B Ts \\<longrightarrow> g B \\<in> reachable_constraints P\"\n  let ?P3 = \"\\<lambda>A Ts. \\<forall>B T \\<xi> \\<sigma> \\<alpha>. prefix (B@[(T,\\<xi>,\\<sigma>,\\<alpha>)]) Ts \\<longrightarrow>\n                      T \\<in> set P \\<and> transaction_decl_subst \\<xi> T \\<and>\n                      transaction_fresh_subst \\<sigma> T (g B) \\<and> transaction_renaming_subst \\<alpha> P (g B)\"\n\n  have \"\\<exists>Ts. ?P1 A Ts \\<and> ?P2 Ts \\<and> ?P3 A Ts\" using A\n  proof (induction A rule: reachable_constraints.induct)\n    case init\n    have \"?P1 [] []\" \"?P2 []\" \"?P3 [] []\" unfolding g_def f_def by simp_all\n    thus ?case by blast\n  next\n    case (step A T \\<xi> \\<sigma> \\<alpha>)\n    let ?A' = \"A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n    obtain Ts where Ts: \"?P1 A Ts\" \"?P2 Ts\" \"?P3 A Ts\" using step.IH by blast\n\n    have 1: \"?P1 ?A' (Ts@[(T,\\<xi>,\\<sigma>,\\<alpha>)])\"\n      using Ts(1) unfolding g_def f_def by simp\n    \n    have 2: \"?P2 (Ts@[(T,\\<xi>,\\<sigma>,\\<alpha>)])\"\n    proof (intro allI impI)\n      fix B assume \"prefix B (Ts@[(T,\\<xi>,\\<sigma>,\\<alpha>)])\"\n      hence \"prefix B Ts \\<or> B = Ts@[(T,\\<xi>,\\<sigma>,\\<alpha>)]\" by fastforce\n      thus \"g B \\<in> reachable_constraints P \"\n        using Ts(1,2) reachable_constraints.step[OF step.hyps]\n        unfolding g_def f_def by auto\n    qed\n\n    have 3: \"?P3 ?A' (Ts@[(T,\\<xi>,\\<sigma>,\\<alpha>)])\"\n      using Ts(1,3) step.hyps(2-5) unfolding g_def f_def by auto \n\n    show ?case using 1 2 3 by blast\n  qed\n  thus thesis using that by blast\nqed\n\nlemma reachable_constraints_transaction_action_obtain:\n  assumes A: \"A \\<in> reachable_constraints P\"\n    and a: \"a \\<in> set A\"\n  obtains T b B \\<alpha> \\<sigma> \\<xi>\n  where \"prefix (B@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)) A\"\n    and \"T \\<in> set P\" \"transaction_decl_subst \\<xi> T\" \"transaction_fresh_subst \\<sigma> T B\"\n        \"transaction_renaming_subst \\<alpha> P B\"\n    and \"b \\<in> set (transaction_strand T)\" \"a = dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p b \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\" \"fst a = fst b\"\nproof -\n  define f where \"f \\<equiv> \\<lambda>(T,\\<xi>,\\<sigma>::('fun,'atom,'sets,'lbl) prot_subst,\\<alpha>).\n                          dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n  define g where \"g \\<equiv> concat \\<circ> map f\"\n\n  obtain Ts where Ts:\n      \"A = g Ts\" \"\\<forall>B. prefix B Ts \\<longrightarrow> g B \\<in> reachable_constraints P\"\n      \"\\<forall>B T \\<xi> \\<sigma> \\<alpha>. prefix (B@[(T,\\<xi>,\\<sigma>,\\<alpha>)]) Ts \\<longrightarrow>\n            T \\<in> set P \\<and> transaction_decl_subst \\<xi> T \\<and>\n            transaction_fresh_subst \\<sigma> T (g B) \\<and> transaction_renaming_subst \\<alpha> P (g B)\"\n    using reachable_constraints_as_transaction_lists[OF A] unfolding g_def f_def by blast\n\n  obtain T \\<alpha> \\<xi> \\<sigma> where T: \"(T,\\<xi>,\\<sigma>,\\<alpha>) \\<in> set Ts\" \"a \\<in> set (f (T,\\<xi>,\\<sigma>,\\<alpha>))\"\n    using Ts(1) a unfolding g_def by auto\n  \n  obtain B where B: \"prefix (B@[(T,\\<xi>,\\<sigma>,\\<alpha>)]) Ts\"\n    using T(1) by (meson prefix_snoc_in_iff) \n\n  obtain b where b:\n      \"b \\<in> set (transaction_strand T)\" \"a = dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p b \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\" \"fst a = fst b\"\n    using T(2) dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n          dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_memberD'[of a \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\" thesis]\n    unfolding f_def by simp\n\n  have 0: \"prefix (g B@f (T, \\<xi>, \\<sigma>, \\<alpha>)) A\"\n    using concat_map_mono_prefix[OF B, of f] unfolding g_def Ts(1) by simp\n\n  have 1: \"T \\<in> set P\" \"transaction_decl_subst \\<xi> T\" \"transaction_fresh_subst \\<sigma> T (g B)\"\n          \"transaction_renaming_subst \\<alpha> P (g B)\"\n    using B Ts(3) by (blast,blast,blast,blast)\n\n  show thesis using 0[unfolded f_def] that[OF _ 1 b] by fast\nqed\n\nlemma reachable_constraints_unlabel_eq:\n  defines \"transaction_unlabel_eq \\<equiv> \\<lambda>T1 T2.\n             transaction_decl T1     =          transaction_decl T2 \\<and>\n             transaction_fresh T1    =          transaction_fresh T2 \\<and>\n    unlabel (transaction_receive T1) = unlabel (transaction_receive T2) \\<and>\n    unlabel (transaction_checks T1)  = unlabel (transaction_checks T2) \\<and>\n    unlabel (transaction_updates T1) = unlabel (transaction_updates T2) \\<and>\n    unlabel (transaction_send T1)    = unlabel (transaction_send T2)\"\n  assumes Peq: \"list_all2 transaction_unlabel_eq P1 P2\"\n  shows \"unlabel ` reachable_constraints P1 = unlabel ` reachable_constraints P2\" (is \"?A = ?B\")\nproof (intro antisym subsetI)\n  have \"transaction_unlabel_eq T2 T1 = transaction_unlabel_eq T1 T2\" for T1 T2\n    unfolding transaction_unlabel_eq_def by argo\n  hence Peq': \"list_all2 transaction_unlabel_eq P2 P1\"\n    using Peq list_all2_sym by metis\n\n  have 0: \"unlabel (transaction_strand T1) = unlabel (transaction_strand T2)\"\n    when \"transaction_unlabel_eq T1 T2\" for T1 T2\n    using that unfolding transaction_unlabel_eq_def transaction_strand_def by force\n\n  have \"vars_transaction T1 = vars_transaction T2\" when \"transaction_unlabel_eq T1 T2\" for T1 T2\n    using 0[OF that] by simp\n  hence \"vars_transaction (P1 ! i) = vars_transaction (P2 ! i)\" when \"i < length P1\" for i\n    using that Peq list_all2_conv_all_nth by blast\n  moreover have \"length P1 = length P2\" using Peq unfolding list_all2_iff by argo\n  ultimately have 1: \"\\<Union>(vars_transaction ` set P1) = \\<Union>(vars_transaction ` set P2)\"\n    using in_set_conv_nth[of _ P1] in_set_conv_nth[of _ P2] by fastforce\n\n  have 2:\n      \"transaction_decl_subst \\<xi> T1 \\<Longrightarrow> transaction_decl_subst \\<xi> T2\" (is \"?A1 \\<Longrightarrow> ?A2\")\n      \"transaction_fresh_subst \\<sigma> T1 \\<A> \\<Longrightarrow> transaction_fresh_subst \\<sigma> T2 \\<B>\" (is \"?B1 \\<Longrightarrow> ?B2\")\n      \"transaction_renaming_subst \\<alpha> P1 \\<A> \\<Longrightarrow> transaction_renaming_subst \\<alpha> P2 \\<B>\" (is \"?C1 \\<Longrightarrow> ?C2\")\n      \"transaction_renaming_subst \\<alpha> P2 \\<A> \\<Longrightarrow> transaction_renaming_subst \\<alpha> P1 \\<B>\" (is \"?D1 \\<Longrightarrow> ?D2\")\n    when \"transaction_unlabel_eq T1 T2\" \"unlabel \\<A> = unlabel \\<B>\"\n    for T1 T2::\"('fun,'atom,'sets,'lbl) prot_transaction\"\n      and \\<A> \\<B>::\"('fun,'atom,'sets,'lbl) prot_strand\"\n      and \\<xi> \\<sigma> \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n  proof -\n    have *: \"transaction_decl T1 = transaction_decl T2\"\n            \"transaction_fresh T1 = transaction_fresh T2\"\n            \"trms_transaction T1 = trms_transaction T2\"\n      using that unfolding transaction_unlabel_eq_def transaction_strand_def by force+\n\n    show \"?A1 \\<Longrightarrow> ?A2\" using *(1) unfolding transaction_decl_subst_def by argo\n    show \"?B1 \\<Longrightarrow> ?B2\" using that(2) *(2,3) unfolding transaction_fresh_subst_def by force\n    show \"?C1 \\<Longrightarrow> ?C2\" using that(2) 1 unfolding transaction_renaming_subst_def by metis\n    show \"?D1 \\<Longrightarrow> ?D2\" using that(2) 1 unfolding transaction_renaming_subst_def by metis\n  qed\n\n  have 3: \"unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T1 \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)) =\n           unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T2 \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n    when \"transaction_unlabel_eq T1 T2\" for T1 T2 \\<theta>\n    using 0[OF that] unlabel_subst[of _ \\<theta>] dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_cong by metis\n\n  have \"\\<exists>\\<B> \\<in> reachable_constraints P2. unlabel \\<A> = unlabel \\<B>\"\n    when \"\\<A> \\<in> reachable_constraints P1\" for \\<A> using that\n  proof (induction \\<A> rule: reachable_constraints.induct)\n    case (step \\<A> T \\<xi> \\<sigma> \\<alpha>)\n    obtain \\<B> where IH: \"\\<B> \\<in> reachable_constraints P2\" \"unlabel \\<A> = unlabel \\<B>\"\n      by (meson step.IH)\n    \n    obtain T' where T': \"T' \\<in> set P2\" \"transaction_unlabel_eq T T'\"\n      using list_all2_in_set_ex[OF Peq step.hyps(2)] by auto\n\n    show ?case\n      using 3[OF T'(2), of \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"] IH(2) reachable_constraints.step[OF IH(1) T'(1)]\n            2[OF T'(2) IH(2)] step.hyps(3-5)\n      by (metis unlabel_append[of \\<A>] unlabel_append[of \\<B>])\n  qed (simp add: unlabel_def)\n  thus \"\\<A> \\<in> ?A \\<Longrightarrow> \\<A> \\<in> ?B\" for \\<A> by fast\n\n  have \"\\<exists>\\<B> \\<in> reachable_constraints P1. unlabel \\<A> = unlabel \\<B>\"\n    when \"\\<A> \\<in> reachable_constraints P2\" for \\<A> using that\n  proof (induction \\<A> rule: reachable_constraints.induct)\n    case (step \\<A> T \\<xi> \\<sigma> \\<alpha>)\n    obtain \\<B> where IH: \"\\<B> \\<in> reachable_constraints P1\" \"unlabel \\<A> = unlabel \\<B>\"\n      by (meson step.IH)\n    \n    obtain T' where T': \"T' \\<in> set P1\" \"transaction_unlabel_eq T T'\"\n      using list_all2_in_set_ex[OF Peq' step.hyps(2)] by auto\n\n    show ?case\n      using 3[OF T'(2), of \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"] IH(2) reachable_constraints.step[OF IH(1) T'(1)]\n            2[OF T'(2) IH(2)] step.hyps(3-5)\n      by (metis unlabel_append[of \\<A>] unlabel_append[of \\<B>])\n  qed (simp add: unlabel_def)\n  thus \"\\<A> \\<in> ?B \\<Longrightarrow> \\<A> \\<in> ?A\" for \\<A> by fast\nqed\n\nlemma reachable_constraints_set_eq:\n  assumes \"set P1 = set P2\"\n  shows \"reachable_constraints P1 = reachable_constraints P2\" (is \"?A = ?B\")\nproof (intro antisym subsetI)\n  note 0 = assms transaction_renaming_subst_set_eq[OF assms]\n  note 1 = reachable_constraints.intros\n\n  show \"\\<A> \\<in> ?A \\<Longrightarrow> \\<A> \\<in> ?B\" for \\<A>\n    by (induct \\<A> rule: reachable_constraints.induct) (auto simp add: 0 intro: 1)\n\n  show \"\\<A> \\<in> ?B \\<Longrightarrow> \\<A> \\<in> ?A\" for \\<A>\n    by (induct \\<A> rule: reachable_constraints.induct) (auto simp add: 0 intro: 1)\nqed\n\nlemma reachable_constraints_set_subst:\n  assumes \"set P1 = set P2\"\n    and \"Q (reachable_constraints P1)\"\n  shows \"Q (reachable_constraints P2)\"\nby (rule subst[of _ _ Q, OF reachable_constraints_set_eq[OF assms(1)] assms(2)])\n\nlemma reachable_constraints_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s:\n  assumes \"\\<forall>T \\<in> set P. wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms_transaction T)\"\n    and \"\\<A> \\<in> reachable_constraints P\"\n  shows \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)\"\nusing assms(2)\nproof (induction \\<A> rule: reachable_constraints.induct)\n  case (step \\<A> T \\<xi> \\<sigma> \\<alpha>)\n  have \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms_transaction T)\"\n    using assms(1) step.hyps(2) by blast\n  hence \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms_transaction T \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n    using transaction_decl_fresh_renaming_substs_range_wf_trms[OF step.hyps(3-5)]\n    by (metis wf_trms_subst)\n  hence \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n    using wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s_trms\\<^sub>s\\<^sub>s\\<^sub>t_subst unlabel_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"] by metis\n  hence \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)))\"\n    using trms\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq by blast\n  thus ?case using step.IH unlabel_append[of \\<A>] trms\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel \\<A>\"] by auto\nqed simp\n\nlemma reachable_constraints_var_types_in_transactions:\n  fixes \\<A>::\"('fun,'atom,'sets,'lbl) prot_constr\"\n  assumes \\<A>: \"\\<A> \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. \\<forall>x \\<in> set (transaction_fresh T).\n              \\<Gamma>\\<^sub>v x = TAtom Value \\<or> (\\<exists>a. \\<Gamma>\\<^sub>v x = TAtom (Atom a))\"\n  shows \"\\<Gamma>\\<^sub>v ` fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<subseteq> (\\<Union>T \\<in> set P. \\<Gamma>\\<^sub>v ` fv_transaction T)\" (is \"?A \\<A>\")\n    and \"\\<Gamma>\\<^sub>v ` bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<subseteq> (\\<Union>T \\<in> set P. \\<Gamma>\\<^sub>v ` bvars_transaction T)\" (is \"?B \\<A>\")\n    and \"\\<Gamma>\\<^sub>v ` vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<subseteq> (\\<Union>T \\<in> set P. \\<Gamma>\\<^sub>v ` vars_transaction T)\" (is \"?C \\<A>\")\nusing \\<A>\nproof (induction \\<A> rule: reachable_constraints.induct)\n  case (step \\<A> T \\<xi> \\<sigma> \\<alpha>)\n  define T' where \"T' \\<equiv> dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n\n  note 2 = transaction_decl_fresh_renaming_substs_wt[OF step.hyps(3-5)]\n\n  have 3: \"\\<forall>t \\<in> subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>). fv t = {} \\<or> (\\<exists>x. t = Var x)\"\n    using transaction_decl_fresh_renaming_substs_range'(1)[OF step.hyps(3-5)]\n    by fastforce\n\n  have \"fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T' = fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n       \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T' = bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n       \"vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T' = vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n    unfolding T'_def\n    by (metis fv\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq,\n        metis bvars\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq,\n        metis vars\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq)\n  hence \"\\<Gamma> ` Var ` fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T' \\<subseteq> \\<Gamma> ` Var ` fv_transaction T\"\n        \"\\<Gamma> ` Var ` bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T' = \\<Gamma> ` Var ` bvars_transaction T\"\n        \"\\<Gamma> ` Var ` vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T' \\<subseteq> \\<Gamma> ` Var ` vars_transaction T\"\n    using wt_subst_lsst_vars_type_subset[OF 2 3, of \"transaction_strand T\"]\n    by argo+\n  hence \"\\<Gamma>\\<^sub>v ` fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T' \\<subseteq> \\<Gamma>\\<^sub>v ` fv_transaction T\"\n        \"\\<Gamma>\\<^sub>v ` bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T' = \\<Gamma>\\<^sub>v ` bvars_transaction T\"\n        \"\\<Gamma>\\<^sub>v ` vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T' \\<subseteq> \\<Gamma>\\<^sub>v ` vars_transaction T\"\n    by (metis \\<Gamma>\\<^sub>v_Var_image)+\n  hence 4: \"\\<Gamma>\\<^sub>v ` fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T' \\<subseteq> (\\<Union>T \\<in> set P. \\<Gamma>\\<^sub>v ` fv_transaction T)\"\n           \"\\<Gamma>\\<^sub>v ` bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T' \\<subseteq> (\\<Union>T \\<in> set P. \\<Gamma>\\<^sub>v ` bvars_transaction T)\"\n           \"\\<Gamma>\\<^sub>v ` vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T' \\<subseteq> (\\<Union>T \\<in> set P. \\<Gamma>\\<^sub>v ` vars_transaction T)\"\n    using step.hyps(2) by fast+\n\n  have 5: \"\\<Gamma>\\<^sub>v ` fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (\\<A> @ T') = (\\<Gamma>\\<^sub>v ` fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>) \\<union> (\\<Gamma>\\<^sub>v ` fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T')\"\n          \"\\<Gamma>\\<^sub>v ` bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (\\<A> @ T') = (\\<Gamma>\\<^sub>v ` bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>) \\<union> (\\<Gamma>\\<^sub>v ` bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T')\"\n          \"\\<Gamma>\\<^sub>v ` vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (\\<A> @ T') = (\\<Gamma>\\<^sub>v ` vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>) \\<union> (\\<Gamma>\\<^sub>v ` vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T')\"\n    using unlabel_append[of \\<A> T']\n          fv\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel \\<A>\" \"unlabel T'\"]\n          bvars\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel \\<A>\" \"unlabel T'\"]\n          vars\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel \\<A>\" \"unlabel T'\"]\n    by auto\n\n  { case 1 thus ?case\n      using step.IH(1) 4(1) 5(1)\n      unfolding T'_def by (simp del: subst_subst_compose fv\\<^sub>s\\<^sub>s\\<^sub>t_def)\n  }\n\n  { case 2 thus ?case\n      using step.IH(2) 4(2) 5(2)\n      unfolding T'_def by (simp del: subst_subst_compose bvars\\<^sub>s\\<^sub>s\\<^sub>t_def)\n  }\n\n  { case 3 thus ?case\n      using step.IH(3) 4(3) 5(3)\n      unfolding T'_def by (simp del: subst_subst_compose)\n  }\nqed simp_all\n\nlemma reachable_constraints_no_bvars:\n  assumes \\<A>: \"\\<A> \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T) = {}\"\n  shows \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> = {}\"\nusing assms proof (induction)\n  case init\n  then show ?case \n    unfolding unlabel_def by auto\nnext\n  case (step \\<A> T \\<xi> \\<sigma> \\<alpha>)\n  then have \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> = {}\"\n    by metis\n  moreover\n  have \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)) = {}\"\n    using step by (metis bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_subst bvars\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq)\n  ultimately \n  show ?case\n    using bvars\\<^sub>s\\<^sub>s\\<^sub>t_append unlabel_append by (metis sup_bot.left_neutral)\nqed\n\nlemma reachable_constraints_fv_bvars_disj:\n  fixes \\<A>::\"('fun,'atom,'sets,'lbl) prot_constr\"\n  assumes \\<A>_reach: \"\\<A> \\<in> reachable_constraints P\"\n    and P: \"\\<forall>S \\<in> set P. admissible_transaction S\"\n  shows \"fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<inter> bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> = {}\"\nproof -\n  let ?X = \"\\<Union>T \\<in> set P. bvars_transaction T\"\n\n  note 0 = admissible_transactions_fv_bvars_disj[OF P]\n\n  have 1: \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<subseteq> ?X\" using \\<A>_reach\n  proof (induction \\<A> rule: reachable_constraints.induct)\n    case (step \\<A> T \\<xi> \\<sigma> \\<alpha>)\n    have \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)) = bvars_transaction T\"\n      using bvars\\<^sub>s\\<^sub>s\\<^sub>t_subst[of \"unlabel (transaction_strand T)\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n            bvars\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq[of \"transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n            dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n            unlabel_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n      by argo\n    hence \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)) \\<subseteq> ?X\"\n      using step.hyps(2)\n      by blast\n    thus ?case\n      using step.IH bvars\\<^sub>s\\<^sub>s\\<^sub>t_append\n      by auto\n  qed (simp add: unlabel_def)\n\n  have 2: \"fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<inter> ?X = {}\" using \\<A>_reach\n  proof (induction \\<A> rule: reachable_constraints.induct)\n    case (step \\<A> T \\<xi> \\<sigma> \\<alpha>)\n    have \"x \\<noteq> y\" when x: \"x \\<in> ?X\" and y: \"y \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\" for x y\n    proof -\n      obtain y' where y': \"y' \\<in> fv_transaction T\" \"y \\<in> fv ((\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) y')\"\n        using y unlabel_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n        by (metis fv\\<^sub>s\\<^sub>s\\<^sub>t_subst_obtain_var)\n\n      have \"y \\<notin> \\<Union>(vars_transaction ` set P)\"\n        using transaction_decl_fresh_renaming_substs_range''[OF step.hyps(3-5) y'(2)]\n              transaction_renaming_subst_range_notin_vars[OF step.hyps(5), of y']\n        by auto\n      thus ?thesis using x vars\\<^sub>s\\<^sub>s\\<^sub>t_is_fv\\<^sub>s\\<^sub>s\\<^sub>t_bvars\\<^sub>s\\<^sub>s\\<^sub>t by fast\n    qed\n    hence \"fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) \\<inter> ?X = {}\"\n      by blast\n    thus ?case\n      using step.IH\n            fv\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq[of \"transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n            dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n            unlabel_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n            fv\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel \\<A>\" \"unlabel (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"]\n            unlabel_append[of \\<A> \"transaction_strand T\"]\n      by force\n  qed (simp add: unlabel_def)\n\n  show ?thesis using 0 1 2 by blast\nqed\n\nlemma reachable_constraints_vars_TAtom_typed:\n  fixes \\<A>::\"('fun,'atom,'sets,'lbl) prot_constr\"\n  assumes \\<A>_reach: \"\\<A> \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and x: \"x \\<in> vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>\"\n  shows \"\\<Gamma>\\<^sub>v x = TAtom Value \\<or> (\\<exists>a. \\<Gamma>\\<^sub>v x = TAtom (Atom a))\"\nproof -\n  have \\<A>_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)\"\n    by (metis reachable_constraints_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s admissible_transactions_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s P \\<A>_reach)\n\n  have T_adm: \"admissible_transaction T\" when \"T \\<in> set P\" for T\n    by (meson that Ball_set P)\n\n  have \"\\<forall>T\\<in>set P. \\<forall>x\\<in>set (transaction_fresh T). \\<Gamma>\\<^sub>v x = TAtom Value\"\n    using protocol_transaction_vars_TAtom_typed(3) P by blast\n  hence *: \"\\<Gamma>\\<^sub>v ` vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<subseteq> (\\<Union>T\\<in>set P. \\<Gamma>\\<^sub>v ` vars_transaction T)\"\n    using reachable_constraints_var_types_in_transactions[of \\<A> P, OF \\<A>_reach] by auto\n\n  have \"\\<Gamma>\\<^sub>v ` vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<subseteq> TAtom ` insert Value (range Atom)\"\n  proof -\n    have \"\\<Gamma>\\<^sub>v x = TAtom Value \\<or> (\\<exists>a. \\<Gamma>\\<^sub>v x = TAtom (Atom a))\"\n      when \"T \\<in> set P\" \"x \\<in> vars_transaction T\" for T x\n      using that protocol_transaction_vars_TAtom_typed(1)[of T] P\n            admissible_transactionE(5)\n      by blast\n    hence \"(\\<Union>T\\<in>set P. \\<Gamma>\\<^sub>v ` vars_transaction T) \\<subseteq> TAtom ` insert Value (range Atom)\"\n      using P by blast\n    thus \"\\<Gamma>\\<^sub>v ` vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<subseteq> TAtom ` insert Value (range Atom)\"\n      using * by auto\n  qed\n  thus ?thesis using x by auto\nqed\n\nlemma reachable_constraints_vars_not_attack_typed:\n  fixes \\<A>::\"('fun,'atom,'sets,'lbl) prot_constr\"\n  assumes \\<A>_reach: \"\\<A> \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. \\<forall>x \\<in> set (transaction_fresh T).\n              \\<Gamma>\\<^sub>v x = TAtom Value \\<or> (\\<exists>a. \\<Gamma>\\<^sub>v x = TAtom (Atom a))\"\n           \"\\<forall>T \\<in> set P. \\<forall>x \\<in> vars_transaction T. \\<not>TAtom AttackType \\<sqsubseteq> \\<Gamma>\\<^sub>v x\"\n    and x: \"x \\<in> vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>\"\n  shows \"\\<not>TAtom AttackType \\<sqsubseteq> \\<Gamma>\\<^sub>v x\"\nusing reachable_constraints_var_types_in_transactions(3)[OF \\<A>_reach P(1)] P(2) x by fastforce\n\nlemma reachable_constraints_Value_vars_are_fv:\n  assumes \\<A>_reach: \"\\<A> \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and x: \"x \\<in> vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>\"\n    and \"\\<Gamma>\\<^sub>v x = TAtom Value\"\n  shows \"x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>\"\nproof -\n  have \"\\<forall>T\\<in>set P. bvars_transaction T = {}\"\n    using P admissible_transactionE(4) by metis\n  hence \\<A>_no_bvars: \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> = {}\"\n    using reachable_constraints_no_bvars[OF \\<A>_reach] by metis\n  thus ?thesis using x vars\\<^sub>s\\<^sub>s\\<^sub>t_is_fv\\<^sub>s\\<^sub>s\\<^sub>t_bvars\\<^sub>s\\<^sub>s\\<^sub>t[of \"unlabel \\<A>\"] by blast\nqed\n\nlemma reachable_constraints_subterms_subst:\n  assumes \\<A>_reach: \"\\<A> \\<in> reachable_constraints P\"\n    and \\<I>: \"welltyped_constraint_model \\<I> \\<A>\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n  shows \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (\\<A> \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<I>)) = (subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\nproof -\n  have \\<A>_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)\"\n    by (metis reachable_constraints_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s admissible_transactions_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s P \\<A>_reach)\n\n  from \\<I> have \\<I>': \"welltyped_constraint_model \\<I> \\<A>\"\n    using welltyped_constraint_model_prefix by auto\n\n  have 1: \"\\<forall>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>). (\\<exists>f. \\<I> x = Fun f []) \\<or> (\\<exists>y. \\<I> x = Var y)\"\n  proof\n    fix x\n    assume xa: \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)\"\n    have \"\\<exists>f T. \\<I> x = Fun f T\"\n      using \\<I> interpretation_grounds[of \\<I> \"Var x\"]\n      unfolding welltyped_constraint_model_def constraint_model_def\n      by (cases \"\\<I> x\") auto\n    then obtain f T where fT_p: \"\\<I> x = Fun f T\"\n      by auto\n    hence \"wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f T)\"\n      using \\<I>\n      unfolding welltyped_constraint_model_def constraint_model_def\n      using wf_trm_subst_rangeD\n      by metis\n    moreover\n    have \"x \\<in> vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>\"\n      using xa var_subterm_trms\\<^sub>s\\<^sub>s\\<^sub>t_is_vars\\<^sub>s\\<^sub>s\\<^sub>t[of x \"unlabel \\<A>\"] vars_iff_subtermeq[of x]\n      by auto\n    hence \"\\<exists>a. \\<Gamma>\\<^sub>v x = TAtom a\"\n      using reachable_constraints_vars_TAtom_typed[OF \\<A>_reach P] by blast\n    hence \"\\<exists>a. \\<Gamma> (Var x) = TAtom a\"\n      by simp\n    hence \"\\<exists>a. \\<Gamma> (Fun f T) = TAtom a\"\n      by (metis (no_types, opaque_lifting) \\<I>' welltyped_constraint_model_def fT_p wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def)\n    ultimately show \"(\\<exists>f. \\<I> x = Fun f []) \\<or> (\\<exists>y. \\<I> x = Var y)\"\n      using TAtom_term_cases fT_p by metis\n  qed\n\n  have \"\\<forall>T\\<in>set P. bvars_transaction T = {}\"\n    using assms admissible_transactionE(4) by metis\n  then have \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> = {}\"\n    using reachable_constraints_no_bvars assms by metis\n  then have 2: \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<inter> subst_domain \\<I> = {}\"\n    by auto\n\n  show ?thesis\n    using subterms_subst_lsst[OF _ 2] 1\n    by simp\nqed\n\nlemma reachable_constraints_val_funs_private':\n  fixes \\<A>::\"('fun,'atom,'sets,'lbl) prot_constr\"\n  assumes \\<A>_reach: \"\\<A> \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction_terms T\"\n           \"\\<forall>T \\<in> set P. transaction_decl T () = []\"\n           \"\\<forall>T \\<in> set P. \\<forall>x \\<in> set (transaction_fresh T). \\<Gamma>\\<^sub>v x = TAtom Value\"\n    and f: \"f \\<in> \\<Union>(funs_term ` trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)\"\n  shows \"\\<not>is_PubConstValue f\"\n    and \"\\<not>is_Abs f\"\nproof -\n  have \"\\<not>is_PubConstValue f \\<and> \\<not>is_Abs f\" using \\<A>_reach f\n  proof (induction \\<A> rule: reachable_constraints.induct)\n    case (step \\<A> T \\<xi> \\<sigma> \\<alpha>)\n    let ?T' = \"unlabel (transaction_strand T) \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n    let ?T'' = \"transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n\n    note \\<xi>_empty =\n      admissible_transaction_decl_subst_empty'[OF bspec[OF P(2) step.hyps(2)] step.hyps(3)]\n\n    have T: \"admissible_transaction_terms T\"\n      using P(1) step.hyps(2) by metis\n\n    have T_fresh: \"\\<forall>x \\<in> set (transaction_fresh T). fst x = TAtom Value\" when \"T \\<in> set P\" for T\n      using P that admissible_transactionE(14) unfolding list_all_iff \\<Gamma>\\<^sub>v_TAtom'' by fast\n\n    show ?thesis using step\n    proof (cases \"f \\<in> \\<Union>(funs_term ` trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)\")\n      case False\n      then obtain t where t: \"t \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t ?T'\" \"f \\<in> funs_term t\"\n        using step.prems trms\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq[of ?T'']\n              trms\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel \\<A>\" \"unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t ?T'')\"]\n              unlabel_append[of \\<A> \"dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t ?T''\"] unlabel_subst[of \"transaction_strand T\"]\n        by fastforce\n      show ?thesis using trms\\<^sub>s\\<^sub>s\\<^sub>t_funs_term_cases[OF t]\n      proof\n        assume \"\\<exists>u \\<in> trms_transaction T. f \\<in> funs_term u\"\n        thus ?thesis\n          using conjunct1[OF conjunct2[OF T[unfolded admissible_transaction_terms_def]]]\n          unfolding is_PubConstValue_def by blast\n      next\n        assume \"\\<exists>x \\<in> fv_transaction T. f \\<in> funs_term ((\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x)\"\n        then obtain x where \"x \\<in> fv_transaction T\" \"f \\<in> funs_term ((\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x)\" by moura\n        thus ?thesis\n          using transaction_decl_fresh_renaming_substs_range'(3)[\n                  OF step.hyps(3-5) _ \\<xi>_empty T_fresh[OF step.hyps(2), unfolded \\<Gamma>\\<^sub>v_TAtom''(2)]]\n          unfolding is_PubConstValue_def\n          by (metis (no_types, lifting) funs_term_Fun_subterm prot_fun.disc(30,48) subst_imgI\n                subtermeq_Var_const(2) term.distinct(1) term.inject(2) term.set_cases(1))\n      qed\n    qed simp\n  qed simp\n  thus \"\\<not>is_PubConstValue f\" \"\\<not>is_Abs f\" by simp_all\nqed\n\nlemma reachable_constraints_val_funs_private:\n  fixes \\<A>::\"('fun,'atom,'sets,'lbl) prot_constr\"\n  assumes \\<A>_reach: \"\\<A> \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and f: \"f \\<in> \\<Union>(funs_term ` trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)\"\n  shows \"\\<not>is_PubConstValue f\"\n    and \"\\<not>is_Abs f\"\nusing P reachable_constraints_val_funs_private'[OF \\<A>_reach _ _ _ f]\n      admissible_transaction_is_wellformed_transaction(4)\n      admissible_transactionE(1,14)\nunfolding list_all_iff \\<Gamma>\\<^sub>v_TAtom''\nby (blast,fast)\n\nlemma reachable_constraints_occurs_fact_ik_case:\n  fixes A::\"('fun,'atom,'sets,'lbl) prot_constr\"\n  assumes \\<A>_reach: \"A \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and occ: \"occurs t \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\"\n  shows \"\\<exists>n. t = Fun (Val n) []\"\nusing \\<A>_reach occ\nproof (induction A rule: reachable_constraints.induct)\n  case (step A T \\<xi> \\<sigma> \\<alpha>)\n  define \\<theta> where \"\\<theta> \\<equiv> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n\n  have T_adm: \"admissible_transaction T\" using P step.hyps(2) by blast\n  hence T: \"wellformed_transaction T\" \"admissible_transaction_occurs_checks T\"\n    using admissible_transaction_is_wellformed_transaction(1,5) by (blast,blast)\n\n  have T_fresh: \"\\<forall>x \\<in> set (transaction_fresh T). fst x = TAtom Value\"\n    using admissible_transactionE(14)[OF T_adm] unfolding list_all_iff by fast\n\n  note \\<xi>_empty = admissible_transaction_decl_subst_empty[OF T_adm step.hyps(3)]\n\n  have \\<xi>_dom_empty: \"z \\<notin> fst ` set (transaction_decl T ())\" for z\n    using transaction_decl_subst_empty_inv[OF step.hyps(3)[unfolded \\<xi>_empty]] by simp\n\n  show ?case\n  proof (cases \"occurs t \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\")\n    case False\n    hence \"occurs t \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n      using step.prems unfolding \\<theta>_def by simp\n    hence \"\\<exists>ts. occurs t \\<in> set ts \\<and>\n                receive\\<langle>ts\\<rangle> \\<in> set (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)))\"\n      unfolding ik\\<^sub>s\\<^sub>s\\<^sub>t_def by force\n    hence \"\\<exists>ts. occurs t \\<in> set ts \\<and>\n                send\\<langle>ts\\<rangle> \\<in> set (unlabel (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n      using dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_steps_iff(1) by blast\n    then obtain ts s where s:\n        \"s \\<in> set ts\" \"send\\<langle>ts\\<rangle> \\<in> set (unlabel (transaction_strand T))\" \"s \\<cdot> \\<theta> = occurs t\"\n      using stateful_strand_step_mem_substD(1)[of _ \"unlabel (transaction_strand T)\" \\<theta>]\n            unlabel_subst[of \"transaction_strand T\" \\<theta>]\n      by force\n\n    note 0 = transaction_decl_fresh_renaming_substs_range[OF step.hyps(3-5)]\n\n    have 1: \"send\\<langle>ts\\<rangle> \\<in> set (unlabel (transaction_send T))\"\n      using s(2) wellformed_transaction_strand_unlabel_memberD(8)[OF T(1)] by blast\n\n    have 2: \"is_Send (send\\<langle>ts\\<rangle>)\"\n      unfolding is_Send_def by simp\n\n    have 3: \"\\<exists>u. s = occurs u\"\n    proof -\n      { fix z\n        have \"(\\<exists>n. \\<theta> z = Fun (Val n) []) \\<or> (\\<exists>y. \\<theta> z = Var y)\"\n          using 0(3,4) T_fresh \\<xi>_dom_empty unfolding \\<theta>_def by blast\n        hence \"\\<nexists>u. \\<theta> z = occurs u\" \"\\<theta> z \\<noteq> Fun OccursSec []\" by auto\n      } note * = this\n\n      obtain u u' where T: \"s = Fun OccursFact [u,u']\"\n        using *(1) s(3) by (cases s) auto\n      thus ?thesis using *(2) s(3) by (cases u) auto\n    qed\n\n    obtain x where x: \"x \\<in> set (transaction_fresh T)\" \"s = occurs (Var x)\"\n      using 3 s(1) admissible_transaction_occurs_checksE4[OF T(2) 1] by metis\n    \n    have \"t = \\<theta> x\"\n      using s(3) x(2) by auto\n    thus ?thesis\n      using 0(3)[OF \\<xi>_dom_empty x(1)] x(1) T_fresh unfolding \\<theta>_def by fast\n  qed (simp add: step.IH)\nqed simp\n\nlemma reachable_constraints_occurs_fact_send_ex:\n  fixes A::\"('fun,'atom,'sets,'lbl) prot_constr\"\n  assumes \\<A>_reach: \"A \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and x: \"\\<Gamma>\\<^sub>v x = TAtom Value\" \"x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\"\n  shows \"\\<exists>ts. occurs (Var x) \\<in> set ts \\<and> send\\<langle>ts\\<rangle> \\<in> set (unlabel A)\"\nusing \\<A>_reach x(2)\nproof (induction A rule: reachable_constraints.induct)\n  case (step A T \\<xi> \\<sigma> \\<alpha>)\n  note \\<xi>_empty = admissible_transaction_decl_subst_empty[OF bspec[OF P step.hyps(2)] step.hyps(3)]\n\n  have T: \"admissible_transaction_occurs_checks T\"\n    using P step.hyps(2) admissible_transaction_is_wellformed_transaction(5) by blast\n  \n  show ?case\n  proof (cases \"x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\")\n    case True\n    show ?thesis\n      using step.IH[OF True] unlabel_append[of A]\n      by auto\n  next\n    case False\n    then obtain y where y:\n        \"y \\<in> fv_transaction T - set (transaction_fresh T)\" \"(\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) y = Var x\"\n      using transaction_decl_fresh_renaming_substs_fv[OF step.hyps(3-5), of x]\n            step.prems(1) fv\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel A\"] unlabel_append[of A]\n      by auto\n    \n    have \"\\<sigma> y = Var y\" using y(1) step.hyps(4) unfolding transaction_fresh_subst_def by auto\n    hence \"\\<alpha> y = Var x\" using y(2) unfolding subst_compose_def \\<xi>_empty by simp\n    hence y_val: \"fst y = TAtom Value\" \"\\<Gamma>\\<^sub>v y = TAtom Value\"\n      using x(1) \\<Gamma>\\<^sub>v_TAtom''[of x] \\<Gamma>\\<^sub>v_TAtom''[of y]\n            wt_subst_trm''[OF transaction_renaming_subst_wt[OF step.hyps(5)], of \"Var y\"]\n      by force+\n\n    obtain ts where ts:\n        \"occurs (Var y) \\<in> set ts\" \"receive\\<langle>ts\\<rangle> \\<in> set (unlabel (transaction_receive T))\"\n      using admissible_transaction_occurs_checksE1[OF T y(1) y_val(2)]\n      by (metis list.set_intros(1) unlabel_Cons(1)) \n    hence \"receive\\<langle>ts\\<rangle> \\<in> set (unlabel (transaction_strand T))\" \n      using transaction_strand_subsets(5) by blast\n    hence *: \"receive\\<langle>ts \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\\<rangle> \\<in> set (unlabel (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n      using unlabel_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n            stateful_strand_step_subst_inI(2)[of _ _ \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"] \n      by force\n\n    have \"occurs (Var y) \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> = occurs (Var x)\"\n      using y(2) by (auto simp del: subst_subst_compose)\n    hence **: \"occurs (Var x) \\<in> set ts \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\" using ts(1) by force\n\n    have \"send\\<langle>ts \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\\<rangle> \\<in> set (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)))\"\n      using * dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_steps_iff(2) by blast\n    thus ?thesis using ** unlabel_append[of A] by force\n  qed\nqed simp\n\nlemma reachable_constraints_db\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_set_args_empty:\n  assumes \\<A>: \"\\<A> \\<in> reachable_constraints P\"\n    and PP: \"list_all wellformed_transaction P\"\n    and admissible_transaction_updates:\n      \"let f = (\\<lambda>T. \\<forall>x \\<in> set (unlabel (transaction_updates T)).\n                      is_Update x \\<and> is_Var (the_elem_term x) \\<and> is_Fun_Set (the_set_term x) \\<and>\n                      fst (the_Var (the_elem_term x)) = TAtom Value)\n      in list_all f P\"\n    and d: \"(t, s) \\<in> set (db\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<I>)\"\n  shows \"\\<exists>ss. s = Fun (Set ss) []\"\n  using \\<A> d\nproof (induction)\n  case (step \\<A> TT \\<xi> \\<sigma> \\<alpha>)\n  let ?TT = \"transaction_strand TT \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n  let ?TTu = \"unlabel ?TT\"\n  let ?TTd = \"dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t ?TT\"\n  let ?TTdu = \"unlabel ?TTd\"\n\n  from step(6) have \"(t, s) \\<in> set (db'\\<^sub>s\\<^sub>s\\<^sub>t ?TTdu \\<I> (db'\\<^sub>s\\<^sub>s\\<^sub>t (unlabel \\<A>) \\<I> []))\"\n    by (metis db\\<^sub>s\\<^sub>s\\<^sub>t_append db\\<^sub>s\\<^sub>s\\<^sub>t_def step.prems unlabel_append)\n  hence \"(t, s) \\<in> set (db'\\<^sub>s\\<^sub>s\\<^sub>t (unlabel \\<A>) \\<I> []) \\<or>\n    (\\<exists>t' s'. insert\\<langle>t',s'\\<rangle> \\<in> set ?TTdu \\<and> t = t' \\<cdot> \\<I> \\<and> s = s' \\<cdot> \\<I>)\"\n    using db\\<^sub>s\\<^sub>s\\<^sub>t_in_cases[of t \"s\" ?TTdu \\<I>] by metis \n  thus ?case\n  proof\n    assume \"\\<exists>t' s'. insert\\<langle>t',s'\\<rangle> \\<in> set ?TTdu \\<and> t = t' \\<cdot> \\<I> \\<and> s = s' \\<cdot> \\<I>\"\n    then obtain t' s' where t's'_p: \"insert\\<langle>t',s'\\<rangle> \\<in> set ?TTdu\" \"t = t' \\<cdot> \\<I>\" \"s = s' \\<cdot> \\<I>\" by metis\n    then obtain lll where \"(lll, insert\\<langle>t',s'\\<rangle>) \\<in> set ?TTd\" by (meson unlabel_mem_has_label)\n    hence \"(lll, insert\\<langle>t',s'\\<rangle>) \\<in> set (transaction_strand TT \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n      using dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_steps_iff(4) by blast\n    hence \"insert\\<langle>t',s'\\<rangle> \\<in> set ?TTu\" by (meson unlabel_in)\n    hence \"insert\\<langle>t',s'\\<rangle> \\<in> set ((unlabel (transaction_strand TT)) \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n      by (simp add: subst_lsst_unlabel)\n    hence \"insert\\<langle>t',s'\\<rangle> \\<in> (\\<lambda>x. x \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) ` set (unlabel (transaction_strand TT))\"\n      unfolding subst_apply_stateful_strand_def by auto\n    then obtain u where\n        \"u \\<in> set (unlabel (transaction_strand TT)) \\<and> u \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> = insert\\<langle>t',s'\\<rangle>\"\n      by auto\n    hence \"\\<exists>t'' s''. insert\\<langle>t'',s''\\<rangle> \\<in> set (unlabel (transaction_strand TT)) \\<and>\n                   t' = t'' \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> \\<and> s' = s'' \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n      by  (cases u) auto\n    then obtain t'' s'' where t''s''_p:\n        \"insert\\<langle>t'',s''\\<rangle> \\<in> set (unlabel (transaction_strand TT)) \\<and>\n          t' = t'' \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> \\<and> s' = s'' \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n      by auto\n    hence \"insert\\<langle>t'',s''\\<rangle> \\<in> set (unlabel (transaction_updates TT))\"\n      using is_Update_in_transaction_updates[of \"insert\\<langle>t'',s''\\<rangle>\" TT]\n      using PP step(2) unfolding list_all_iff by auto\n    moreover have \"\\<forall>x\\<in>set (unlabel (transaction_updates TT)). is_Fun_Set (the_set_term x)\"\n      using step(2) admissible_transaction_updates unfolding is_Fun_Set_def list_all_iff by auto\n    ultimately have \"is_Fun_Set (the_set_term (insert\\<langle>t'',s''\\<rangle>))\" by auto\n    moreover have \"s' = s'' \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\" using t''s''_p by blast\n    ultimately have \"is_Fun_Set (the_set_term (insert\\<langle>t',s'\\<rangle>))\" by (auto simp add: is_Fun_Set_subst)\n    hence \"is_Fun_Set s\" by (simp add: t's'_p(3) is_Fun_Set_subst)\n    thus ?case using is_Fun_Set_exi by auto\n  qed (auto simp add: step db\\<^sub>s\\<^sub>s\\<^sub>t_def)\nqed auto\n\nlemma reachable_constraints_occurs_fact_ik_ground:\n  fixes A::\"('fun,'atom,'sets,'lbl) prot_constr\"\n  assumes \\<A>_reach: \"A \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and t: \"occurs t \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\"\n  shows \"fv (occurs t) = {}\"\nproof -\n  have 0: \"admissible_transaction T\"\n    when \"T \\<in> set P\" for T\n    using P that unfolding list_all_iff by simp\n\n  note 1 = admissible_transaction_is_wellformed_transaction(1,5)[OF 0]\n\n  have 2: \"ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)) =\n           (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A) \\<union> (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>)\"\n    when \"T \\<in> set P\" for T \\<theta> and A::\"('fun,'atom,'sets,'lbl) prot_constr\"\n    using dual_transaction_ik_is_transaction_send'[OF 1(1)[OF that]] by fastforce\n\n  show ?thesis using \\<A>_reach t\n  proof (induction A rule: reachable_constraints.induct)\n    case (step A T \\<xi> \\<sigma> \\<alpha>)\n    note \\<xi>_empty = admissible_transaction_decl_subst_empty[OF 0[OF step.hyps(2)] step.hyps(3)]\n\n    from step show ?case\n    proof (cases \"occurs t \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\")\n      case False\n      hence \"occurs t \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n        using 2[OF step.hyps(2)] step.prems \\<xi>_empty by blast\n      then obtain ts where ts:\n          \"occurs t \\<in> set ts\" \"send\\<langle>ts\\<rangle> \\<in> set (unlabel (transaction_send T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n        using wellformed_transaction_send_receive_subst_trm_cases(2)[OF 1(1)[OF step.hyps(2)]]\n        by blast\n      then obtain ts' s where s:\n          \"occurs s \\<in> set ts'\" \"send\\<langle>ts'\\<rangle> \\<in> set (unlabel (transaction_send T))\" \"t = s \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n        using transaction_decl_fresh_renaming_substs_occurs_fact_send_receive(1)[\n                OF step.hyps(3-5) 0[OF step.hyps(2)] ts(1)]\n              transaction_strand_subst_subsets(8)[of T \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n        by blast\n\n      obtain x where x: \"x \\<in> set (transaction_fresh T)\" \"s = Var x\"\n        using admissible_transaction_occurs_checksE4[OF 1(2)[OF step.hyps(2)] s(2,1)] by metis\n\n      have \"fv t = {}\"\n        using transaction_decl_fresh_renaming_substs_range(2)[OF step.hyps(3-5) _ x(1)]\n              s(3) x(2) transaction_decl_subst_empty_inv[OF step.hyps(3)[unfolded \\<xi>_empty]]\n        by (auto simp del: subst_subst_compose)\n      thus ?thesis by simp\n    qed simp\n  qed simp\nqed\n\nlemma reachable_constraints_occurs_fact_ik_funs_terms:\n  fixes A::\"('fun,'atom,'sets,'lbl) prot_constr\"\n  assumes \\<A>_reach: \"A \\<in> reachable_constraints P\"\n    and \\<I>: \"welltyped_constraint_model I A\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n  shows \"\\<forall>s \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I). OccursFact \\<notin> \\<Union>(funs_term ` set (snd (Ana s)))\" (is \"?A A\")\n    and \"\\<forall>s \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I). OccursSec \\<notin> \\<Union>(funs_term ` set (snd (Ana s)))\" (is \"?B A\")\n    and \"Fun OccursSec [] \\<notin> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I\" (is \"?C A\")\n    and \"\\<forall>x \\<in> vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A. I x \\<noteq> Fun OccursSec []\" (is \"?D A\")\nproof -\n  have T_adm: \"admissible_transaction T\" when \"T \\<in> set P\" for T\n    using P that unfolding list_all_iff by simp\n\n  note T_wf = admissible_transaction_is_wellformed_transaction(1)[OF T_adm]\n\n  note T_occ = admissible_transaction_is_wellformed_transaction(5)[OF T_adm]\n\n  note \\<xi>_empty = admissible_transaction_decl_subst_empty[OF T_adm]\n\n  have \\<I>_wt: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t I\" by (metis \\<I> welltyped_constraint_model_def)\n\n  have \\<I>_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range I)\"\n    by (metis \\<I> welltyped_constraint_model_def constraint_model_def)\n\n  have \\<I>_grounds: \"fv (I x) = {}\" \"\\<exists>f T. I x = Fun f T\" for x\n    using \\<I> interpretation_grounds[of I, of \"Var x\"] empty_fv_exists_fun[of \"I x\"]\n    unfolding welltyped_constraint_model_def constraint_model_def by auto\n\n  have 00: \"fv\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)) \\<subseteq> vars_transaction T\"\n           \"fv\\<^sub>s\\<^sub>e\\<^sub>t (subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T))) = fv\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T))\"\n    for T::\"('fun,'atom,'sets,'lbl) prot_transaction\"\n    using fv_trms\\<^sub>s\\<^sub>s\\<^sub>t_subset(1)[of \"unlabel (transaction_send T)\"] vars_transaction_unfold\n          fv_subterms_set[of \"trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)\"]\n    by blast+\n\n  have 0: \"\\<forall>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)). \\<exists>a. \\<Gamma> (Var x) = TAtom a\"\n          \"\\<forall>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)). \\<Gamma> (Var x) \\<noteq> TAtom OccursSecType\"\n          \"\\<forall>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T))). \\<exists>a. \\<Gamma> (Var x) = TAtom a\"\n          \"\\<forall>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T))). \\<Gamma> (Var x) \\<noteq> TAtom OccursSecType\"\n          \"\\<forall>x \\<in> vars_transaction T. \\<exists>a. \\<Gamma> (Var x) = TAtom a\"\n          \"\\<forall>x \\<in> vars_transaction T. \\<Gamma> (Var x) \\<noteq> TAtom OccursSecType\"\n    when \"T \\<in> set P\" for T\n    using admissible_transaction_occurs_fv_types[OF T_adm[OF that]] 00\n    by blast+\n\n  note T_fresh_type = admissible_transactionE(2)[OF T_adm]\n\n  have 1: \"ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I =\n           (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I) \\<union> (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I)\"\n    when \"T \\<in> set P\" for T \\<theta> and A::\"('fun,'atom,'sets,'lbl) prot_constr\"\n    using dual_transaction_ik_is_transaction_send'[OF T_wf[OF that]]\n    by fastforce\n\n  have 2: \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I) =\n           subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I\"\n    when \"T \\<in> set P\" and \\<theta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\" for T \\<theta>\n    using wt_subst_TAtom_subterms_set_subst[OF wt_subst_compose[OF \\<theta>(1) \\<I>_wt] 0(1)[OF that(1)]]\n          wf_trm_subst_rangeD[OF wf_trms_subst_compose[OF \\<theta>(2) \\<I>_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s]]\n    by auto\n\n  have 3: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n    when \"T \\<in> set P\" \"transaction_decl_subst \\<xi> T\"\n         \"transaction_fresh_subst \\<sigma> T A\" \"transaction_renaming_subst \\<alpha> P A\"\n    for \\<xi> \\<sigma> \\<alpha> and T::\"('fun,'atom,'sets,'lbl) prot_transaction\"\n      and A::\"('fun,'atom,'sets,'lbl) prot_constr\"\n    using protocol_transaction_vars_TAtom_typed(3)[of T] P that(1)\n          transaction_decl_fresh_renaming_substs_wt[OF that(2-4)]\n          transaction_decl_fresh_renaming_substs_range_wf_trms[OF that(2-4)]\n          wf_trms_subst_compose\n    by simp_all\n\n  have 4: \"\\<forall>s \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)).\n              OccursFact \\<notin> \\<Union>(funs_term ` set (snd (Ana s))) \\<and>\n              OccursSec \\<notin> \\<Union>(funs_term ` set (snd (Ana s)))\"\n    when T: \"T \\<in> set P\" for T\n  proof\n    fix t assume t: \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T))\"\n    then obtain ts s where s:\n        \"send\\<langle>ts\\<rangle> \\<in> set (unlabel (transaction_send T))\" \"s \\<in> set ts\" \"t \\<in> subterms s\"\n      using wellformed_transaction_unlabel_cases(4)[OF T_wf[OF T]]\n      by fastforce\n\n    have s_occ: \"\\<exists>x. s = occurs (Var x)\" when \"OccursFact \\<in> funs_term t \\<or> OccursSec \\<in> funs_term t\"\n      using that s(1) subtermeq_imp_funs_term_subset[OF s(3)]\n            admissible_transaction_occurs_checksE3[OF T_occ[OF T] _ s(2)]\n      by blast\n\n    obtain K T' where K: \"Ana t = (K,T')\" by moura\n\n    show \"OccursFact \\<notin> \\<Union>(funs_term ` set (snd (Ana t))) \\<and>\n          OccursSec \\<notin> \\<Union>(funs_term ` set (snd (Ana t)))\"\n    proof (rule ccontr)\n      assume \"\\<not>(OccursFact \\<notin> \\<Union>(funs_term ` set (snd (Ana t))) \\<and>\n                OccursSec \\<notin> \\<Union>(funs_term ` set (snd (Ana t))))\"\n      hence a: \"OccursFact \\<in> \\<Union>(funs_term ` set (snd (Ana t))) \\<or>\n                OccursSec \\<in> \\<Union>(funs_term ` set (snd (Ana t)))\"\n        by simp\n      hence \"OccursFact \\<in> \\<Union>(funs_term ` set T') \\<or> OccursSec \\<in> \\<Union>(funs_term ` set T')\"\n        using K by simp\n      hence \"OccursFact \\<in> funs_term t \\<or> OccursSec \\<in> funs_term t\"\n        using Ana_subterm[OF K] funs_term_subterms_eq(1)[of t] by blast\n      then obtain x where x: \"t \\<in> subterms (occurs (Var x))\"\n        using s(3) s_occ by blast\n      thus False using a by fastforce\n    qed\n  qed\n\n  have 5: \"OccursFact \\<notin> \\<Union>(funs_term ` subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n          \"OccursSec \\<notin> \\<Union>(funs_term ` subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n      when \\<xi>\\<sigma>\\<alpha>: \"transaction_decl_subst \\<xi> T\" \"transaction_fresh_subst \\<sigma> T A\"\n                \"transaction_renaming_subst \\<alpha> P A\"\n      and T: \"T \\<in> set P\"\n    for \\<xi> \\<sigma> \\<alpha> and T::\"('fun,'atom,'sets,'lbl) prot_transaction\"\n      and A::\"('fun,'atom,'sets,'lbl) prot_constr\"\n  proof -\n    have \"OccursFact \\<notin> funs_term t\" \"OccursSec \\<notin> funs_term t\"\n      when \"t \\<in> subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\" for t \n      using transaction_decl_fresh_renaming_substs_range'(3)[\n              OF \\<xi>\\<sigma>\\<alpha> that \\<xi>_empty[OF T \\<xi>\\<sigma>\\<alpha>(1)] T_fresh_type[OF T]]\n      by auto\n    thus \"OccursFact \\<notin> \\<Union>(funs_term ` subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n         \"OccursSec \\<notin> \\<Union>(funs_term ` subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n      by blast+\n  qed\n\n  have 6: \"I x \\<noteq> Fun OccursSec []\" \"\\<nexists>t. I x = occurs t\" \"\\<exists>a. \\<Gamma> (I x) = TAtom a \\<and> a \\<noteq> OccursSecType\"\n    when T: \"T \\<in> set P\"\n      and \\<xi>\\<sigma>\\<alpha>: \"transaction_decl_subst \\<xi> T\" \"transaction_fresh_subst \\<sigma> T A\"\n               \"transaction_renaming_subst \\<alpha> P A\"\n      and x: \"Var x \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n    for x \\<xi> \\<sigma> \\<alpha> and T::\"('fun,'atom,'sets,'lbl) prot_transaction\"\n      and A::\"('fun,'atom,'sets,'lbl) prot_constr\"\n  proof -\n    obtain t where t: \"t \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)\" \"t \\<cdot> (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) = Var x\"\n      using x by moura\n    then obtain y where y: \"t = Var y\" by (cases t) auto\n\n    have \"\\<exists>a. \\<Gamma> t = TAtom a \\<and> a \\<noteq> OccursSecType\"\n      using 0(1,2)[OF T] t(1) y\n      by force\n    thus \"\\<exists>a. \\<Gamma> (I x) = TAtom a \\<and> a \\<noteq> OccursSecType\"\n      using wt_subst_trm''[OF 3(1)[OF T \\<xi>\\<sigma>\\<alpha>]] wt_subst_trm''[OF \\<I>_wt] t(2) \n      by (metis subst_apply_term.simps(1))\n    thus \"I x \\<noteq> Fun OccursSec []\" \"\\<nexists>t. I x = occurs t\"\n      by auto\n  qed\n\n  have 7: \"I x \\<noteq> Fun OccursSec []\" \"\\<nexists>t. I x = occurs t\" \"\\<exists>a. \\<Gamma> (I x) = TAtom a \\<and> a \\<noteq> OccursSecType\"\n    when T: \"T \\<in> set P\"\n      and \\<xi>\\<sigma>\\<alpha>: \"transaction_decl_subst \\<xi> T\" \"transaction_fresh_subst \\<sigma> T A\"\n               \"transaction_renaming_subst \\<alpha> P A\"\n      and x: \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t ((\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) ` vars_transaction T)\"\n    for x \\<xi> \\<sigma> \\<alpha> and T::\"('fun,'atom,'sets,'lbl) prot_transaction\"\n      and A::\"('fun,'atom,'sets,'lbl) prot_constr\"\n  proof -\n    obtain y where y: \"y \\<in> vars_transaction T\" \"x \\<in> fv ((\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) y)\"\n      using x by auto\n    hence y': \"(\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) y = Var x\"\n      using transaction_decl_fresh_renaming_substs_range'(3)[\n              OF \\<xi>\\<sigma>\\<alpha> _ \\<xi>_empty[OF T \\<xi>\\<sigma>\\<alpha>(1)] T_fresh_type[OF T]]\n      by (cases \"(\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) y \\<in> subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\") force+\n\n    have \"\\<exists>a. \\<Gamma> (Var y) = TAtom a \\<and> a \\<noteq> OccursSecType\"\n      using 0(5,6)[OF T] y\n      by force\n    thus \"\\<exists>a. \\<Gamma> (I x) = TAtom a \\<and> a \\<noteq> OccursSecType\"\n      using wt_subst_trm''[OF 3(1)[OF T \\<xi>\\<sigma>\\<alpha>]] wt_subst_trm''[OF \\<I>_wt] y'\n      by (metis subst_apply_term.simps(1))\n    thus \"I x \\<noteq> Fun OccursSec []\" \"\\<nexists>t. I x = occurs t\"\n      by auto\n  qed\n\n  have 8: \"I x \\<noteq> Fun OccursSec []\" \"\\<nexists>t. I x = occurs t\" \"\\<exists>a. \\<Gamma> (I x) = TAtom a \\<and> a \\<noteq> OccursSecType\"\n    when T: \"T \\<in> set P\"\n      and \\<xi>\\<sigma>\\<alpha>: \"transaction_decl_subst \\<xi> T\" \"transaction_fresh_subst \\<sigma> T A\"\n               \"transaction_renaming_subst \\<alpha> P A\"\n      and x: \"Var x \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n    for x \\<xi> \\<sigma> \\<alpha> and T::\"('fun,'atom,'sets,'lbl) prot_transaction\"\n      and A::\"('fun,'atom,'sets,'lbl) prot_constr\"\n  proof -\n    obtain t where t: \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T))\" \"t \\<cdot> (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) = Var x\"\n      using x by moura\n    then obtain y where y: \"t = Var y\" by (cases t) auto\n\n    have \"\\<exists>a. \\<Gamma> t = TAtom a \\<and> a \\<noteq> OccursSecType\"\n      using 0(3,4)[OF T] t(1) y\n      by force\n    thus \"\\<exists>a. \\<Gamma> (I x) = TAtom a \\<and> a \\<noteq> OccursSecType\"\n      using wt_subst_trm''[OF 3(1)[OF T \\<xi>\\<sigma>\\<alpha>]] wt_subst_trm''[OF \\<I>_wt] t(2) \n      by (metis subst_apply_term.simps(1))\n    thus \"I x \\<noteq> Fun OccursSec []\" \"\\<nexists>t. I x = occurs t\"\n      by auto\n  qed\n\n  have s_fv: \"fv s \\<subseteq> fv\\<^sub>s\\<^sub>e\\<^sub>t ((\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) ` vars_transaction T)\"\n    when s: \"s \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n      and T: \"T \\<in> set P\"\n    for s and \\<xi> \\<sigma> \\<alpha>::\"('fun,'atom,'sets,'lbl) prot_subst\"\n      and T::\"('fun,'atom,'sets,'lbl) prot_transaction\"\n  proof\n    fix x assume \"x \\<in> fv s\"\n    hence \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n      using s by auto\n    hence *: \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n      using fv_subterms_set_subst' by fast\n    have **: \"list_all is_Send (unlabel (transaction_send T))\"\n      using T_wf[OF T] unfolding wellformed_transaction_def by blast\n    have \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t ((\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) ` vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T))\"\n    proof -\n      obtain t where t: \"t \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)\" \"x \\<in> fv (t \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n        using * by fastforce\n      hence \"fv t \\<subseteq> vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)\"\n        using fv_trms\\<^sub>s\\<^sub>s\\<^sub>t_subset(1)[of \"unlabel (transaction_send T)\"]\n        by auto\n      thus ?thesis using t(2) subst_apply_fv_subset by fast\n    qed\n    thus \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t ((\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) ` vars_transaction T)\"\n      using vars_transaction_unfold[of T] by fastforce\n  qed\n\n  show \"?A A\" using \\<A>_reach\n  proof (induction A rule: reachable_constraints.induct)\n    case (step A T \\<xi> \\<sigma> \\<alpha>)\n    have *: \"\\<forall>s \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)).\n              OccursFact \\<notin> \\<Union>(funs_term ` set (snd (Ana s)))\"\n      using 4[OF step.hyps(2)] by blast\n\n    have \"\\<forall>s \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I.\n            OccursFact \\<notin> \\<Union>(funs_term ` set (snd (Ana s)))\"\n    proof\n      fix t assume t: \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I\"\n      then obtain s u where su:\n          \"s \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\" \"s \\<cdot> I = t\"\n          \"u \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T))\" \"u \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> = s\"\n        by force\n\n      obtain Ku Tu where KTu: \"Ana u = (Ku,Tu)\" by moura\n      \n      have *: \"OccursFact \\<notin> \\<Union>(funs_term ` set Tu)\"\n              \"OccursFact \\<notin> \\<Union>(funs_term ` subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n              \"OccursFact \\<notin> \\<Union>(funs_term ` \\<Union>(((set \\<circ> snd \\<circ> Ana) ` subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))))\"\n        using transaction_decl_fresh_renaming_substs_range'(3)[\n                OF step.hyps(3-5) _ \\<xi>_empty[OF step.hyps(2,3)] T_fresh_type[OF step.hyps(2)]]\n              4[OF step.hyps(2)] su(3) KTu\n        by (fastforce,fastforce,fastforce)\n\n      have \"OccursFact \\<notin> \\<Union>(funs_term ` set (Tu \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n      proof -\n        { fix f assume f: \"f \\<in> \\<Union>(funs_term ` set (Tu \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n          then obtain tf where tf: \"tf \\<in> set Tu\" \"f \\<in> funs_term (tf \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\" by moura\n          hence \"f \\<in> funs_term tf \\<or> f \\<in> \\<Union>(funs_term ` subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n            using funs_term_subst[of tf \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"] by force\n          hence \"f \\<noteq> OccursFact\" using *(1,2) tf(1) by blast\n        } thus ?thesis by metis\n      qed\n      hence **: \"OccursFact \\<notin> \\<Union>(funs_term ` set (snd (Ana s)))\"\n      proof (cases u)\n        case (Var xu)\n        hence \"s = (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) xu\" using su(4) by (metis subst_apply_term.simps(1))\n        thus ?thesis using *(3) by fastforce\n      qed (use su(4) KTu Ana_subst'[of _ _ Ku Tu \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"] in simp)\n      \n      show \"OccursFact \\<notin> \\<Union>(funs_term ` set (snd (Ana t)))\"\n      proof (cases s)\n        case (Var sx)\n        then obtain a where a: \"\\<Gamma> (I sx) = Var a\"\n          using su(1) 8(3)[OF step.hyps(2-5), of sx] by fast\n        hence \"Ana (I sx) = ([],[])\" by (metis \\<I>_grounds(2) const_type_inv[THEN Ana_const])\n        thus ?thesis using Var su(2) by simp\n      next\n        case (Fun f S)\n        hence snd_Ana_t: \"snd (Ana t) = snd (Ana s) \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t I\"\n          using su(2) Ana_subst'[of f S _ \"snd (Ana s)\" I] by (cases \"Ana s\") simp_all\n\n        { fix g assume \"g \\<in> \\<Union>(funs_term ` set (snd (Ana t)))\"\n          hence \"g \\<in> \\<Union>(funs_term ` set (snd (Ana s))) \\<or>\n                 (\\<exists>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set (snd (Ana s))). g \\<in> funs_term (I x))\"\n            using snd_Ana_t funs_term_subst[of _ I] by auto\n          hence \"g \\<noteq> OccursFact\"\n          proof\n            assume \"\\<exists>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set (snd (Ana s))). g \\<in> funs_term (I x)\"\n            then obtain x where x: \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set (snd (Ana s)))\" \"g \\<in> funs_term (I x)\" by moura\n            have \"x \\<in> fv s\" using x(1) Ana_vars(2)[of s] by (cases \"Ana s\") auto\n            hence \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t ((\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) ` vars_transaction T)\"\n              using s_fv[OF su(1) step.hyps(2)] by blast\n            then obtain a h U where h:\n                \"I x = Fun h U\" \"\\<Gamma> (I x) = Var a\" \"a \\<noteq> OccursSecType\" \"arity h = 0\"\n              using \\<I>_grounds(2) 7(3)[OF step.hyps(2-5)] const_type_inv\n              by metis\n            hence \"h \\<noteq> OccursFact\" by auto\n            moreover have \"U = []\" using h(1,2,4) const_type_inv_wf[of h U a] \\<I>_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s by fastforce\n            ultimately show ?thesis using h(1) x(2) by auto\n          qed (use ** in blast)\n        } thus ?thesis by blast\n      qed\n    qed\n    thus ?case\n      using step.IH step.prems 1[OF step.hyps(2), of A \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n            2[OF step.hyps(2) 3[OF step.hyps(2-5)]]\n      by auto\n  qed simp\n\n  show \"?B A\" using \\<A>_reach\n  proof (induction A rule: reachable_constraints.induct)\n    case (step A T \\<xi> \\<sigma> \\<alpha>)\n    have \"\\<forall>s \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I.\n            OccursSec \\<notin> \\<Union>(funs_term ` set (snd (Ana s)))\"\n    proof\n      fix t assume t: \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I\"\n      then obtain s u where su:\n          \"s \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\" \"s \\<cdot> I = t\"\n          \"u \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T))\" \"u \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> = s\"\n        by force\n\n      obtain Ku Tu where KTu: \"Ana u = (Ku,Tu)\" by moura\n      \n      have *: \"OccursSec \\<notin> \\<Union>(funs_term ` set Tu)\"\n              \"OccursSec \\<notin> \\<Union>(funs_term ` subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n              \"OccursSec \\<notin> \\<Union>(funs_term ` \\<Union>(((set \\<circ> snd \\<circ> Ana) ` subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))))\"\n        using transaction_decl_fresh_renaming_substs_range'(3)[\n                OF step.hyps(3-5) _ \\<xi>_empty[OF step.hyps(2,3)] T_fresh_type[OF step.hyps(2)]] \n              4[OF step.hyps(2)] su(3) KTu\n        by (fastforce,fastforce,fastforce)\n\n      have \"OccursSec \\<notin> \\<Union>(funs_term ` set (Tu \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n      proof -\n        { fix f assume f: \"f \\<in> \\<Union>(funs_term ` set (Tu \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n          then obtain tf where tf: \"tf \\<in> set Tu\" \"f \\<in> funs_term (tf \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\" by moura\n          hence \"f \\<in> funs_term tf \\<or> f \\<in> \\<Union>(funs_term ` subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n            using funs_term_subst[of tf \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"] by force\n          hence \"f \\<noteq> OccursSec\" using *(1,2) tf(1) by blast\n        } thus ?thesis by metis\n      qed\n      hence **: \"OccursSec \\<notin> \\<Union>(funs_term ` set (snd (Ana s)))\"\n      proof (cases u)\n        case (Var xu)\n        hence \"s = (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) xu\" using su(4) by (metis subst_apply_term.simps(1))\n        thus ?thesis using *(3) by fastforce\n      qed (use su(4) KTu Ana_subst'[of _ _ Ku Tu \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"] in simp)\n      \n      show \"OccursSec \\<notin> \\<Union>(funs_term ` set (snd (Ana t)))\"\n      proof (cases s)\n        case (Var sx)\n        then obtain a where a: \"\\<Gamma> (I sx) = Var a\"\n          using su(1) 8(3)[OF step.hyps(2-5), of sx] by fast\n        hence \"Ana (I sx) = ([],[])\" by (metis \\<I>_grounds(2) const_type_inv[THEN Ana_const])\n        thus ?thesis using Var su(2) by simp\n      next\n        case (Fun f S)\n        hence snd_Ana_t: \"snd (Ana t) = snd (Ana s) \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t I\"\n          using su(2) Ana_subst'[of f S _ \"snd (Ana s)\" I] by (cases \"Ana s\") simp_all\n\n        { fix g assume \"g \\<in> \\<Union>(funs_term ` set (snd (Ana t)))\"\n          hence \"g \\<in> \\<Union>(funs_term ` set (snd (Ana s))) \\<or>\n                 (\\<exists>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set (snd (Ana s))). g \\<in> funs_term (I x))\"\n            using snd_Ana_t funs_term_subst[of _ I] by auto\n          hence \"g \\<noteq> OccursSec\"\n          proof\n            assume \"\\<exists>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set (snd (Ana s))). g \\<in> funs_term (I x)\"\n            then obtain x where x: \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set (snd (Ana s)))\" \"g \\<in> funs_term (I x)\" by moura\n            have \"x \\<in> fv s\" using x(1) Ana_vars(2)[of s] by (cases \"Ana s\") auto\n            hence \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t ((\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) ` vars_transaction T)\"\n              using s_fv[OF su(1) step.hyps(2)] by blast\n            then obtain a h U where h:\n                \"I x = Fun h U\" \"\\<Gamma> (I x) = Var a\" \"a \\<noteq> OccursSecType\" \"arity h = 0\"\n              using \\<I>_grounds(2) 7(3)[OF step.hyps(2-5)] const_type_inv\n              by metis\n            hence \"h \\<noteq> OccursSec\" by auto\n            moreover have \"U = []\" using h(1,2,4) const_type_inv_wf[of h U a] \\<I>_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s by fastforce\n            ultimately show ?thesis using h(1) x(2) by auto\n          qed (use ** in blast)\n        } thus ?thesis by blast\n      qed\n    qed\n    thus ?case\n      using step.IH step.prems 1[OF step.hyps(2), of A \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n            2[OF step.hyps(2) 3[OF step.hyps(2-5)]]\n      by auto\n  qed simp\n\n  show \"?C A\" using \\<A>_reach\n  proof (induction A rule: reachable_constraints.induct)\n    case (step A T \\<xi> \\<sigma> \\<alpha>)\n    have *: \"Fun OccursSec [] \\<notin> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)\"\n      using admissible_transaction_occurs_checksE5[OF T_occ[OF step.hyps(2)]] by blast\n\n    have **: \"Fun OccursSec [] \\<notin> subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n      using transaction_decl_fresh_renaming_substs_range'(3)[\n              OF step.hyps(3-5) _ \\<xi>_empty[OF step.hyps(2,3)] T_fresh_type[OF step.hyps(2)]]\n      by auto\n\n    have \"Fun OccursSec [] \\<notin> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I\"\n    proof\n      assume \"Fun OccursSec [] \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I\"\n      then obtain s where \"s \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\" \"s \\<cdot> I = Fun OccursSec []\"\n        by moura\n      moreover have \"Fun OccursSec [] \\<notin> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n      proof\n        assume \"Fun OccursSec [] \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n        then obtain u where \"u \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)\" \"u \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> = Fun OccursSec []\"\n          by moura\n        thus False using * ** by (cases u) (force simp del: subst_subst_compose)+\n      qed\n      ultimately show False using 6[OF step.hyps(2-5)] by (cases s) auto\n    qed\n    thus ?case using step.IH step.prems 1[OF step.hyps(2), of A \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"] by fast\n  qed simp\n\n  show \"?D A\" using \\<A>_reach\n  proof (induction A rule: reachable_constraints.induct)\n    case (step A T \\<xi> \\<sigma> \\<alpha>)\n    { fix x assume x: \"x \\<in> vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n      hence x': \"x \\<in> vars\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (transaction_strand T) \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n        by (metis vars\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq unlabel_subst)\n      hence \"x \\<in> vars_transaction T \\<or> x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t ((\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) ` vars_transaction T)\"\n        using vars\\<^sub>s\\<^sub>s\\<^sub>t_subst_cases[OF x'] by metis\n      moreover have \"I x \\<noteq> Fun OccursSec []\" when \"x \\<in> vars_transaction T\"\n        using that 0(5,6)[OF step.hyps(2)] wt_subst_trm''[OF \\<I>_wt, of \"Var x\"]\n        by fastforce\n      ultimately have \"I x \\<noteq> Fun OccursSec []\"\n        using 7(1)[OF step.hyps(2-5), of x]\n        by blast\n    } thus ?case using step.IH by auto\n  qed simp\nqed\n\nlemma reachable_constraints_occurs_fact_ik_subst_aux:\n  assumes \\<A>_reach: \"A \\<in> reachable_constraints P\"\n    and \\<I>: \"welltyped_constraint_model I A\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and t: \"t \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\" \"t \\<cdot> I = occurs s\"\n  shows \"\\<exists>u. t = occurs u\"\nproof -\n  have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t I\"\n    using \\<I> unfolding welltyped_constraint_model_def constraint_model_def by metis\n  hence 0: \"\\<Gamma> t = \\<Gamma> (occurs s)\"\n    using t(2) wt_subst_trm'' by metis\n\n  have 1: \"\\<Gamma>\\<^sub>v ` fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<subseteq> (\\<Union>T \\<in> set P. \\<Gamma>\\<^sub>v ` fv_transaction T)\"\n          \"\\<forall>T \\<in> set P. \\<forall>x \\<in> fv_transaction T. \\<Gamma>\\<^sub>v x = TAtom Value \\<or> (\\<exists>a. \\<Gamma>\\<^sub>v x = TAtom (Atom a))\"\n    using reachable_constraints_var_types_in_transactions(1)[OF \\<A>_reach]\n          protocol_transaction_vars_TAtom_typed(2,3) P\n    by fast+\n\n  show ?thesis\n  proof (cases t)\n    case (Var x)\n    thus ?thesis\n      using 0 1 t(1) var_subterm_ik\\<^sub>s\\<^sub>s\\<^sub>t_is_fv\\<^sub>s\\<^sub>s\\<^sub>t[of x \"unlabel A\"]\n      by fastforce\n  next\n    case (Fun f T)\n    hence 2: \"f = OccursFact\" \"length T = Suc (Suc 0)\" \"T ! 0 \\<cdot> I = Fun OccursSec []\"\n      using t(2) by auto\n\n    have \"T ! 0 = Fun OccursSec []\"\n    proof (cases \"T ! 0\")\n      case (Var y)\n      hence \"I y = Fun OccursSec []\" using Fun 2(3) by simp\n      moreover have \"Var y \\<in> set T\" using Var 2(2) length_Suc_conv[of T 1] by auto\n      hence \"y \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A)\" using Fun t(1) by force\n      hence \"y \\<in> vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\"\n        using fv_ik_subset_fv_sst'[of \"unlabel A\"] vars\\<^sub>s\\<^sub>s\\<^sub>t_is_fv\\<^sub>s\\<^sub>s\\<^sub>t_bvars\\<^sub>s\\<^sub>s\\<^sub>t[of \"unlabel A\"]\n        by blast\n      ultimately have False\n        using reachable_constraints_occurs_fact_ik_funs_terms(4)[OF \\<A>_reach \\<I> P]\n        by blast\n      thus ?thesis by simp\n    qed (use 2(3) in simp)\n    moreover have \"\\<exists>u u'. T = [u,u']\"\n      using iffD1[OF length_Suc_conv 2(2)] iffD1[OF length_Suc_conv[of _ 0]] length_0_conv by fast\n    ultimately show ?thesis using Fun 2(1,2) by force\n  qed\nqed\n\nlemma reachable_constraints_occurs_fact_ik_subst:\n  assumes \\<A>_reach: \"A \\<in> reachable_constraints P\"\n    and \\<I>: \"welltyped_constraint_model I A\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and t: \"occurs t \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I\"\n  shows \"occurs t \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\"\nproof -\n  have \\<I>_wt: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t I\"\n    using \\<I> unfolding welltyped_constraint_model_def constraint_model_def by metis\n\n  obtain s where s: \"s \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\" \"s \\<cdot> I = occurs t\"\n    using t by auto\n  hence u: \"\\<exists>u. s = occurs u\"\n    using \\<I>_wt reachable_constraints_occurs_fact_ik_subst_aux[OF \\<A>_reach \\<I> P]\n    by blast\n  hence \"fv s = {}\"\n    using reachable_constraints_occurs_fact_ik_ground[OF \\<A>_reach P] s\n    by fast\n  thus ?thesis\n    using s u subst_ground_ident[of s I] \n    by argo\nqed\n\nlemma reachable_constraints_occurs_fact_send_in_ik:\n  assumes \\<A>_reach: \"A \\<in> reachable_constraints P\"\n    and \\<I>: \"welltyped_constraint_model I A\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and x: \"occurs (Var x) \\<in> set ts\" \"send\\<langle>ts\\<rangle> \\<in> set (unlabel A)\"\n  shows \"occurs (I x) \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\"\nusing \\<A>_reach \\<I> x\nproof (induction A rule: reachable_constraints.induct)\n  case (step A T \\<xi> \\<sigma> \\<alpha>)\n  define \\<theta> where \"\\<theta> \\<equiv> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n  define T' where \"T' \\<equiv> dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n\n  have T_adm: \"admissible_transaction T\"\n    using P step.hyps(2) unfolding list_all_iff by blast\n\n  note T_wf = admissible_transaction_is_wellformed_transaction(1)[OF T_adm]\n  note T_adm_occ = admissible_transaction_is_wellformed_transaction(5)[OF T_adm]\n\n  have \\<I>_is_T_model: \"strand_sem_stateful (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I) (set (db\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A I)) (unlabel T') I\"\n    using step.prems unlabel_append[of A T'] db\\<^sub>s\\<^sub>s\\<^sub>t_set_is_dbupd\\<^sub>s\\<^sub>s\\<^sub>t[of \"unlabel A\" I \"[]\"]\n          strand_sem_append_stateful[of \"{}\" \"{}\" \"unlabel A\" \"unlabel T'\" I]\n    by (simp add: T'_def \\<theta>_def welltyped_constraint_model_def constraint_model_def db\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\n  show ?case\n  proof (cases \"send\\<langle>ts\\<rangle> \\<in> set (unlabel A)\")\n    case False\n    hence \"send\\<langle>ts\\<rangle> \\<in> set (unlabel T')\"\n      using step.prems(3) unfolding T'_def \\<theta>_def by simp\n    hence \"receive\\<langle>ts\\<rangle> \\<in> set (unlabel (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n      using dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_steps_iff(2) unfolding T'_def by blast\n    then obtain y ts' where y:\n        \"receive\\<langle>ts'\\<rangle> \\<in> set (unlabel (transaction_receive T))\"\n        \"\\<theta> y = Var x\" \"occurs (Var y) \\<in> set ts'\"\n      using transaction_decl_fresh_renaming_substs_occurs_fact_send_receive(2)[\n              OF step.hyps(3-5) T_adm]\n            subst_to_var_is_var[of _ \\<theta> x] step.prems(2)\n      unfolding \\<theta>_def by (force simp del: subst_subst_compose)\n    hence \"occurs (Var y) \\<cdot> \\<theta> \\<in> set ts' \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\"\n          \"receive\\<langle>ts' \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<theta>\\<rangle> \\<in> set (unlabel (transaction_receive T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n      using subst_lsst_unlabel_member[of \"receive\\<langle>ts'\\<rangle>\" \"transaction_receive T\" \\<theta>]\n      by fastforce+\n    hence \"ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I \\<turnstile> occurs (Var y) \\<cdot> \\<theta> \\<cdot> I\"\n      using wellformed_transaction_sem_receives[\n              OF T_wf, of \"ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I\" \"set (db\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A I)\" \\<theta> I \"ts' \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<theta>\"]\n            \\<I>_is_T_model\n      unfolding T'_def list_all_iff by fastforce\n    hence *: \"ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I \\<turnstile> occurs (\\<theta> y \\<cdot> I)\"\n      by auto\n\n    have \"occurs (\\<theta> y \\<cdot> I) \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\"\n      using deduct_occurs_in_ik[OF *]\n            reachable_constraints_occurs_fact_ik_subst[\n              OF step.hyps(1) welltyped_constraint_model_prefix[OF step.prems(1)] P, of \"\\<theta> y \\<cdot> I\"]\n            reachable_constraints_occurs_fact_ik_funs_terms[\n              OF step.hyps(1) welltyped_constraint_model_prefix[OF step.prems(1)] P]\n      by blast\n    thus ?thesis using y(2) by simp\n  qed (simp add: step.IH[OF welltyped_constraint_model_prefix[OF step.prems(1)]] step.prems(2))\nqed simp\n\nlemma reachable_constraints_occurs_fact_deduct_in_ik:\n  assumes \\<A>_reach: \"A \\<in> reachable_constraints P\"\n    and \\<I>: \"welltyped_constraint_model I A\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and k: \"ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I \\<turnstile> occurs k\"\n  shows \"occurs k \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I\"\n    and \"occurs k \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\"\nusing reachable_constraints_occurs_fact_ik_funs_terms(1-3)[OF \\<A>_reach \\<I> P]\n      reachable_constraints_occurs_fact_ik_subst[OF \\<A>_reach \\<I> P]\n      deduct_occurs_in_ik[OF k]\nby (presburger, presburger)\n\nlemma reachable_contraints_fv_bvars_subset:\n  assumes A: \"A \\<in> reachable_constraints P\"\n  shows \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<subseteq> (\\<Union>T \\<in> set P. bvars_transaction T)\"\nusing assms\nproof (induction A rule: reachable_constraints.induct)\n  case (step \\<A> T \\<xi> \\<sigma> \\<alpha>)\n  let ?T' = \"transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n\n  show ?case\n    using step.IH step.hyps(2)\n          bvars\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq[of ?T']\n          bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n          bvars\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel \\<A>\" \"unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t ?T')\"]\n          unlabel_append[of \\<A> \"dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t ?T'\"]\n    by (metis (no_types, lifting) SUP_upper Un_subset_iff)\nqed simp\n\nlemma reachable_contraints_fv_disj:\n  fixes A::\"('fun,'atom,'sets,'lbl) prot_constr\"\n  assumes A: \"A \\<in> reachable_constraints P\"\n  shows \"fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> (\\<Union>T \\<in> set P. bvars_transaction T) = {}\"\nusing A\nproof (induction A rule: reachable_constraints.induct)\n  case (step \\<A> T \\<xi> \\<sigma> \\<alpha>)\n  define T' where \"T' \\<equiv> transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\" \n  define X where \"X \\<equiv> \\<Union>T \\<in> set P. bvars_transaction T\"\n  have \"fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T' \\<inter> X = {}\"\n    using transaction_decl_fresh_renaming_substs_vars_disj(4)[OF step.hyps(3-5)]\n          transaction_decl_fresh_renaming_substs_vars_subset(4)[OF step.hyps(3-5,2)]\n    unfolding T'_def X_def by blast\n  hence \"fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (\\<A>@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T') \\<inter> X = {}\"\n    using step.IH[unfolded X_def[symmetric]] fv\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq[of T'] by auto\n  thus ?case unfolding T'_def X_def by blast\nqed simp\n\nlemma reachable_contraints_fv_bvars_disj:\n  fixes A::\"('fun,'atom,'sets,'lbl) prot_constr\"\n  assumes P: \"\\<forall>T \\<in> set P. wellformed_transaction T\"\n    and A: \"A \\<in> reachable_constraints P\"\n  shows \"fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\nusing A\nproof (induction A rule: reachable_constraints.induct)\n  case (step \\<A> T \\<xi> \\<sigma> \\<alpha>)\n  define T' where \"T' \\<equiv> dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n\n  note 0 = transaction_decl_fresh_renaming_substs_vars_disj[OF step.hyps(3-5)]\n  note 1 = transaction_decl_fresh_renaming_substs_vars_subset[OF step.hyps(3-5)]\n\n  have 2: \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<inter> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T' = {}\" \n    using 0(7) 1(4)[OF step.hyps(2)] fv\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq\n    unfolding T'_def by (metis (no_types) disjoint_iff_not_equal subset_iff)\n\n  have \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T' \\<subseteq> \\<Union>(bvars_transaction ` set P)\"\n       \"fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<inter> \\<Union>(bvars_transaction ` set P) = {}\"\n    using reachable_contraints_fv_bvars_subset[OF reachable_constraints.step[OF step.hyps]]\n          reachable_contraints_fv_disj[OF reachable_constraints.step[OF step.hyps]]\n    unfolding T'_def by auto\n  hence 3: \"fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<inter> bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T' = {}\" by blast\n  \n  have \"fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) \\<inter> bvars_transaction T = {}\"\n    using 0(4)[OF step.hyps(2)] 1(4)[OF step.hyps(2)] by blast\n  hence 4: \"fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T' \\<inter> bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T' = {}\"\n    by (metis (no_types) T'_def fv\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq bvars\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq\n              unlabel_subst bvars\\<^sub>s\\<^sub>s\\<^sub>t_subst)\n\n  have \"fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (\\<A>@T') \\<inter> bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (\\<A>@T') = {}\"\n    using 2 3 4 step.IH\n    unfolding unlabel_append[of \\<A> T']\n              fv\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel \\<A>\" \"unlabel T'\"]\n              bvars\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel \\<A>\" \"unlabel T'\"]\n    by fast\n  thus ?case unfolding T'_def by blast\nqed simp\n\nlemma reachable_constraints_wf:\n  assumes P:\n      \"\\<forall>T \\<in> set P. wellformed_transaction T\"\n      \"\\<forall>T \\<in> set P. wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s' arity (trms_transaction T)\"\n    and A: \"A \\<in> reachable_constraints P\"\n  shows \"wf\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A)\"\n    and \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A)\"\nproof -\n  let ?X = \"\\<lambda>T. fst ` set (transaction_decl T ()) \\<union> set (transaction_fresh T)\"\n\n  have \"wellformed_transaction T\"\n    when \"T \\<in> set P\" for T\n    using P(1) that by fast+\n  hence 0: \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (?X T) (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T)))\"\n           \"fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T)) \\<inter> bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T)) = {}\"\n           \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms_transaction T)\"\n    when T: \"T \\<in> set P\" for T\n    unfolding admissible_transaction_terms_def\n    by (metis T wellformed_transaction_wf\\<^sub>s\\<^sub>s\\<^sub>t(1),\n        metis T wellformed_transaction_wf\\<^sub>s\\<^sub>s\\<^sub>t(2) fv\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq bvars\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq,\n        metis T wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s_code P(2))\n\n  from A have \"wf\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A) \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A)\"\n  proof (induction A rule: reachable_constraints.induct)\n    case (step A T \\<xi> \\<sigma> \\<alpha>)\n    let ?T' = \"dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n\n    have IH: \"wf'\\<^sub>s\\<^sub>s\\<^sub>t {} (unlabel A)\" \"fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A = {}\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A)\"\n      using step.IH by metis+\n\n    have 1: \"wf'\\<^sub>s\\<^sub>s\\<^sub>t {} (unlabel (A@?T'))\"\n      using transaction_decl_fresh_renaming_substs_wf_sst[OF 0(1)[OF step.hyps(2)] step.hyps(3-5)]\n            wf\\<^sub>s\\<^sub>s\\<^sub>t_vars_mono[of \"{}\"] wf\\<^sub>s\\<^sub>s\\<^sub>t_append[OF IH(1)]\n      by simp\n\n    have 2: \"fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A@?T') \\<inter> bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A@?T') = {}\"\n      using reachable_contraints_fv_bvars_disj[OF P(1)]\n            reachable_constraints.step[OF step.hyps]\n      by blast\n\n    have \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t ?T')\"\n      using trms\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq unlabel_subst\n            wf_trms_subst[\n              OF transaction_decl_fresh_renaming_substs_range_wf_trms[OF step.hyps(3-5)],\n              THEN wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s_trms\\<^sub>s\\<^sub>s\\<^sub>t_subst,\n              OF 0(3)[OF step.hyps(2)]]\n      by metis\n    hence 3: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A@?T'))\"\n      using IH(3) by auto\n\n    show ?case using 1 2 3 by force\n  qed simp\n  thus \"wf\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A)\" by metis+\nqed\n\nlemma reachable_constraints_no_Ana_attack:\n  assumes \\<A>: \"\\<A> \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. wellformed_transaction T\"\n           \"\\<forall>T \\<in> set P. admissible_transaction_terms T\"\n           \"\\<forall>T \\<in> set P. \\<forall>x \\<in> set (transaction_fresh T).\n              \\<Gamma>\\<^sub>v x = TAtom Value \\<or> (\\<exists>a. \\<Gamma>\\<^sub>v x = TAtom (Atom a))\"\n    and t: \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)\"\n  shows \"attack\\<langle>n\\<rangle> \\<notin> set (snd (Ana t))\"\nproof -\n  have T_adm_term: \"admissible_transaction_terms T\" when \"T \\<in> set P\" for T\n    using P that by blast\n\n  have T_wf: \"wellformed_transaction T\" when \"T \\<in> set P\" for T\n    using P that by blast\n\n  have T_fresh: \"\\<forall>x \\<in> set (transaction_fresh T). \\<Gamma>\\<^sub>v x = TAtom Value \\<or> (\\<exists>a. \\<Gamma>\\<^sub>v x = TAtom (Atom a))\"\n    when \"T \\<in> set P\" for T\n    using P(3) that by fast\n\n  show ?thesis\n  using \\<A> t\n  proof (induction \\<A> rule: reachable_constraints.induct)\n    case (step A T \\<xi> \\<sigma> \\<alpha>) thus ?case\n    proof (cases \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A)\")\n      case False\n      hence \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)))\"\n        using step.prems by simp\n      hence \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n        using dual_transaction_ik_is_transaction_send'[OF T_wf[OF step.hyps(2)]]\n        by metis\n      hence \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n        using transaction_decl_fresh_renaming_substs_trms[\n                OF step.hyps(3-5), of \"transaction_send T\"]\n              wellformed_transaction_unlabel_cases(4)[OF T_wf[OF step.hyps(2)]]\n        by fastforce\n      then obtain s where s: \"s \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T))\" \"t = s \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n        by moura\n      hence s': \"attack\\<langle>n\\<rangle> \\<notin> set (snd (Ana s))\"\n        using admissible_transaction_no_Ana_Attack[OF T_adm_term[OF step.hyps(2)]]\n              trms_transaction_unfold[of T]\n        by blast\n\n      note * = transaction_decl_fresh_renaming_substs_range'(1-3)[OF step.hyps(3-5)]\n               transaction_decl_fresh_renaming_substs_range_no_attack_const[\n                 OF step.hyps(3-5) T_fresh[OF step.hyps(2)]]\n\n      show ?thesis\n      proof\n        assume n: \"attack\\<langle>n\\<rangle> \\<in> set (snd (Ana t))\"\n        thus False\n        proof (cases s)\n          case (Var x)\n          hence \"(\\<exists>c. t = Fun c []) \\<or> (\\<exists>y. t = Var y)\"\n            using *(1)[of t] n s(2) by (force simp del: subst_subst_compose)\n          thus ?thesis using n Ana_subterm' by fastforce\n        next\n          case (Fun f S)\n          hence \"attack\\<langle>n\\<rangle> \\<in> set (snd (Ana s)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n            using Ana_subst'[of f S _ \"snd (Ana s)\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"] s(2) s' n\n            by (cases \"Ana s\") auto\n          hence \"attack\\<langle>n\\<rangle> \\<in> set (snd (Ana s)) \\<or> attack\\<langle>n\\<rangle> \\<in> subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n            using const_mem_subst_cases' by fast\n          thus ?thesis using *(4) s' by fast\n        qed\n      qed\n    qed simp\n  qed simp\nqed\n\nlemma reachable_constraints_receive_attack_if_attack:\n  assumes \\<A>: \"\\<A> \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. wellformed_transaction T\"\n           \"\\<forall>T \\<in> set P. admissible_transaction_terms T\"\n           \"\\<forall>T \\<in> set P. \\<forall>x \\<in> set (transaction_fresh T).\n              \\<Gamma>\\<^sub>v x = TAtom Value \\<or> (\\<exists>a. \\<Gamma>\\<^sub>v x = TAtom (Atom a))\"\n           \"\\<forall>T \\<in> set P. \\<forall>x \\<in> vars_transaction T. \\<not>TAtom AttackType \\<sqsubseteq> \\<Gamma>\\<^sub>v x\"\n    and \\<I>: \"welltyped_constraint_model \\<I> \\<A>\"\n    and l: \"ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> attack\\<langle>l\\<rangle>\"\n  shows \"attack\\<langle>l\\<rangle> \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n    and \"receive\\<langle>[attack\\<langle>l\\<rangle>]\\<rangle> \\<in> set (unlabel \\<A>)\"\n    and \"\\<forall>T \\<in> set P. \\<forall>s \\<in> set (transaction_strand T).\n              is_Send (snd s) \\<and> length (the_msgs (snd s)) = 1 \\<and>\n              is_Fun_Attack (hd (the_msgs (snd s)))\n              \\<longrightarrow> the_Attack_label (the_Fun (hd (the_msgs (snd s)))) = fst s\n         \\<Longrightarrow> (l,receive\\<langle>[attack\\<langle>l\\<rangle>]\\<rangle>) \\<in> set \\<A>\" (is \"?Q \\<Longrightarrow> (l,receive\\<langle>[attack\\<langle>l\\<rangle>]\\<rangle>) \\<in> set \\<A>\")\nproof -\n  have \\<I>': \"constr_sem_stateful \\<I> (unlabel \\<A>)\" \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\"\n           \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<I>)\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\"\n    using \\<I> unfolding welltyped_constraint_model_def constraint_model_def by metis+\n\n  have 0: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>)\"\n    when \\<A>: \"\\<A> \\<in> reachable_constraints P\" for \\<A>\n    using reachable_constraints_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s[OF _ \\<A>] admissible_transaction_terms_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s P(2)\n          ik\\<^sub>s\\<^sub>s\\<^sub>t_trms\\<^sub>s\\<^sub>s\\<^sub>t_subset[of \"unlabel \\<A>\"] wf_trms_subst[OF \\<I>'(3)]\n    by fast\n\n  have 1: \"\\<forall>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>). \\<not>TAtom AttackType \\<sqsubseteq> \\<Gamma>\\<^sub>v x\"\n    when \\<A>: \"\\<A> \\<in> reachable_constraints P\" for \\<A>\n    using reachable_constraints_vars_not_attack_typed[OF \\<A> P(3,4)]\n          fv_ik_subset_vars_sst'[of \"unlabel \\<A>\"]\n    by fast\n\n  have 2: \"attack\\<langle>l\\<rangle> \\<notin> set (snd (Ana t)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" when t: \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)\" for t\n  proof\n    assume \"attack\\<langle>l\\<rangle> \\<in> set (snd (Ana t)) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n    then obtain s where s: \"s \\<in> set (snd (Ana t))\" \"s \\<cdot> \\<I> = attack\\<langle>l\\<rangle>\" by moura\n\n    obtain x where x: \"s = Var x\"\n      by (cases s) (use s reachable_constraints_no_Ana_attack[OF \\<A> P(1-3) t] in auto)\n\n    have \"x \\<in> fv t\" using x Ana_subterm'[OF s(1)] vars_iff_subtermeq by force\n    hence \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)\" using t fv_subterms by fastforce\n    hence \"\\<Gamma>\\<^sub>v x \\<noteq> TAtom AttackType\" using 1[OF \\<A>] by fastforce\n    thus False using s(2) x wt_subst_trm''[OF \\<I>'(4), of \"Var x\"] by fastforce\n  qed\n\n  have 3: \"attack\\<langle>l\\<rangle> \\<notin> set (snd (Ana t))\" when t: \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>)\" for t\n  proof\n    assume \"attack\\<langle>l\\<rangle> \\<in> set (snd (Ana t))\"\n    then obtain s where s:\n        \"s \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (\\<I> ` fv\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>))\" \"attack\\<langle>l\\<rangle> \\<in> set (snd (Ana s))\"\n      using Ana_subst_subterms_cases[OF t] 2 by fast\n    then obtain x where x: \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)\" \"s \\<sqsubseteq> \\<I> x\" by moura\n    hence \"\\<I> x \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>)\"\n      using var_is_subterm[of x] subterms_subst_subset'[of \\<I> \"ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>\"]\n      by force\n    hence *: \"wf\\<^sub>t\\<^sub>r\\<^sub>m (\\<I> x)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m s\"\n      using wf_trms_subterms[OF 0[OF \\<A>]] wf_trm_subtermeq[OF _ x(2)]\n      by auto\n\n    show False\n      using term.order_trans[\n              OF subtermeq_imp_subtermtypeeq[OF *(2) Ana_subterm'[OF s(2)]]\n                 subtermeq_imp_subtermtypeeq[OF *(1) x(2)]]\n            1[OF \\<A>] x(1) wt_subst_trm''[OF \\<I>'(4), of \"Var x\"]\n      by force\n  qed\n\n  have 4: \"t = attack\\<langle>n\\<rangle>\"\n    when t: \"t \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> = attack\\<langle>n\\<rangle>\"\n      and hyps: \"transaction_decl_subst \\<xi> T\"\n                \"transaction_fresh_subst \\<sigma> T \\<A>\"\n                \"transaction_renaming_subst \\<alpha> P \\<A>\"\n      and T: \"\\<forall>x \\<in> set (transaction_fresh T). \\<Gamma>\\<^sub>v x = TAtom Value \\<or> (\\<exists>a. \\<Gamma>\\<^sub>v x = TAtom (Atom a))\"\n    for t n\n      and T::\"('fun, 'atom, 'sets, 'lbl) prot_transaction\"\n      and \\<xi> \\<sigma> \\<alpha>::\"('fun, 'atom, 'sets, 'lbl) prot_subst\"\n      and \\<A>::\"('fun, 'atom, 'sets, 'lbl) prot_strand\"\n  proof (cases t)\n    case (Var x)\n    hence \"attack\\<langle>n\\<rangle> \\<in> subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n      by (metis (no_types, lifting) t subst_apply_term.simps(1) subst_imgI term.distinct(1))  \n    thus ?thesis\n      using transaction_decl_fresh_renaming_substs_range_no_attack_const[OF hyps T]\n      by blast\n  qed (use t in simp)\n\n  have 5: \"\\<exists>ts'. ts = ts' \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<theta> \\<and> (l,send\\<langle>ts'\\<rangle>) \\<in> set (transaction_strand T)\"\n    when ts: \"(l,receive\\<langle>ts\\<rangle>) \\<in> set (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n    for l ts \\<theta> and T::\"('fun, 'atom, 'sets, 'lbl) prot_transaction\"\n    using subst_lsst_memD(2)[OF ts[unfolded dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_steps_iff(1)[symmetric]]]\n    by auto\n\n  have 6: \"l' = l\" when \"(l',receive\\<langle>[attack\\<langle>l\\<rangle>]\\<rangle>) \\<in> set \\<A>\" and Q: \"?Q\" for l'\n    using \\<A> that(1)\n  proof (induction \\<A> rule: reachable_constraints.induct)\n    case (step \\<A> T \\<xi> \\<sigma> \\<alpha>) show ?case\n    proof (cases \"(l',receive\\<langle>[attack\\<langle>l\\<rangle>]\\<rangle>) \\<in> set \\<A>\")\n      case False\n      hence *: \"(l',receive\\<langle>[attack\\<langle>l\\<rangle>]\\<rangle>) \\<in> set (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n        using step.prems by simp\n      have \"(l',send\\<langle>[attack\\<langle>l\\<rangle>]\\<rangle>) \\<in> set (transaction_strand T)\"\n        using 4[OF _ step.hyps(3-5)] P(3) step.hyps(2) 5[OF *] by force\n      thus ?thesis using Q step.hyps(2) unfolding is_Fun_Attack_def by fastforce\n    qed (use step.IH in simp)\n  qed simp\n\n  have 7: \"\\<exists>t. ts = [t] \\<and> t = attack\\<langle>l\\<rangle>\"\n    when ts: \"receive\\<langle>ts\\<rangle> \\<in> set (unlabel \\<A>)\" \"attack\\<langle>l\\<rangle> \\<in> set ts \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" for ts\n    using \\<A> ts(1)\n  proof (induction \\<A> rule: reachable_constraints.induct)\n    case (step \\<A> T \\<xi> \\<sigma> \\<alpha>)\n    obtain t where t: \"t \\<in> set ts\" \"attack\\<langle>l\\<rangle> = t \\<cdot> \\<I>\" using ts(2) by blast\n    hence t_in_ik: \"t \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (\\<A> @ dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n      using step.prems(1) in_ik\\<^sub>s\\<^sub>s\\<^sub>t_iff[of t] by blast\n\n    have t_attack_eq: \"t = attack\\<langle>l\\<rangle>\"\n    proof (cases t)\n      case (Var x) \n      hence \"TAtom AttackType \\<notin> subterms (\\<Gamma> t)\"\n        using t_in_ik 1[OF reachable_constraints.step[OF step.hyps]] by fastforce\n      thus ?thesis using t(2) wt_subst_trm''[OF \\<I>'(4), of t] by force\n    qed (use t(2) in simp)\n\n    show ?case\n    proof (cases \"receive\\<langle>ts\\<rangle> \\<in> set (unlabel \\<A>)\")\n      case False\n      then obtain l' where l':\n          \"(l', receive\\<langle>ts\\<rangle>) \\<in> set (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n        using step.prems(1) unfolding unlabel_def by force\n      then obtain ts' where ts':\n          \"ts = ts' \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\" \"(l', send\\<langle>ts'\\<rangle>) \\<in> set (transaction_strand T)\"\n        using 5 by meson\n      then obtain t' where t': \"t' \\<in> set ts'\" \"t' \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> = attack\\<langle>l\\<rangle>\"\n        using t(1) t_attack_eq by force\n\n      note * = t'(1) 4[OF t'(2) step.hyps(3-5)]\n\n      have \"send\\<langle>ts'\\<rangle> \\<in> set (unlabel (transaction_strand T))\"\n        using ts'(2) step.hyps(2) P(2) unfolding unlabel_def by force\n      hence \"length ts' = 1\"\n        using step.hyps(2) P(2,3) * unfolding admissible_transaction_terms_def by fastforce\n      hence \"ts' = [attack\\<langle>l\\<rangle>]\" using * P(3) step.hyps(2) by (cases ts') auto\n      thus ?thesis by (simp add: ts'(1))\n    qed (use step.IH in simp)\n  qed simp\n\n  show \"attack\\<langle>l\\<rangle> \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n    using private_const_deduct[OF _ l] 3 by simp\n  then obtain ts where ts: \"receive\\<langle>ts\\<rangle> \\<in> set (unlabel \\<A>)\" \"attack\\<langle>l\\<rangle> \\<in> set ts \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n    using in_ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_iff[of _ \\<A>] unfolding unlabel_def by force\n  then obtain t where \"ts = [t]\" \"t = attack\\<langle>l\\<rangle>\"\n    using 7 by blast\n  thus \"receive\\<langle>[attack\\<langle>l\\<rangle>]\\<rangle> \\<in> set (unlabel \\<A>)\"\n    using ts(1) by blast\n  hence \"\\<exists>l'. (l', receive\\<langle>[attack\\<langle>l\\<rangle>]\\<rangle>) \\<in> set \\<A>\"\n    unfolding unlabel_def by fastforce\n  thus \"(l,receive\\<langle>[attack\\<langle>l\\<rangle>]\\<rangle>) \\<in> set \\<A>\" when ?Q\n    using that 6 by fast\nqed\n\nlemma reachable_constraints_receive_attack_if_attack':\n  assumes \\<A>: \"\\<A> \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and \\<I>: \"welltyped_constraint_model \\<I> \\<A>\"\n    and n: \"ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> attack\\<langle>n\\<rangle>\"\n  shows \"attack\\<langle>n\\<rangle> \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n    and \"receive\\<langle>[attack\\<langle>n\\<rangle>]\\<rangle> \\<in> set (unlabel \\<A>)\"\nproof -\n  have P': \"\\<forall>T \\<in> set P. wellformed_transaction T\"\n           \"\\<forall>T \\<in> set P. admissible_transaction_terms T\"\n           \"\\<forall>T \\<in> set P. \\<forall>x \\<in> set (transaction_fresh T). \\<Gamma>\\<^sub>v x = TAtom Value\"\n           \"\\<forall>T \\<in> set P. \\<forall>x \\<in> vars_transaction T. \\<not>TAtom AttackType \\<sqsubseteq> \\<Gamma>\\<^sub>v x\"\n    using admissible_transaction_is_wellformed_transaction(1,4)[OF bspec[OF P]]\n          admissible_transactionE(2,15)[OF bspec[OF P]]\n    by (blast, blast, blast, blast)\n\n  show \"attack\\<langle>n\\<rangle> \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" \"receive\\<langle>[attack\\<langle>n\\<rangle>]\\<rangle> \\<in> set (unlabel \\<A>)\"\n    using reachable_constraints_receive_attack_if_attack(1,2)[OF \\<A> P'(1,2) _ P'(4) \\<I> n] P'(3)\n    by (metis, metis)\nqed\n\nlemma constraint_model_Value_term_is_Val:\n  assumes \\<A>_reach: \"A \\<in> reachable_constraints P\"\n    and \\<I>: \"welltyped_constraint_model I A\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and x: \"\\<Gamma>\\<^sub>v x = TAtom Value\" \"x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\"\n  shows \"\\<exists>n. I x = Fun (Val n) []\"\nusing reachable_constraints_occurs_fact_send_ex[OF \\<A>_reach P x]\n      reachable_constraints_occurs_fact_send_in_ik[OF \\<A>_reach \\<I> P]\n      reachable_constraints_occurs_fact_ik_case[OF \\<A>_reach P]\nby fast\n\nlemma constraint_model_Value_term_is_Val':\n  assumes \\<A>_reach: \"A \\<in> reachable_constraints P\"\n    and \\<I>: \"welltyped_constraint_model I A\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and x: \"(TAtom Value, m) \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\"\n  shows \"\\<exists>n. I (TAtom Value, m) = Fun (Val n) []\"\nusing constraint_model_Value_term_is_Val[OF \\<A>_reach \\<I> P _ x] by simp\n\n(* We use this lemma to show that fresh constants first occur in \\<I>(\\<A>) at the point where they were generated *)\nlemma constraint_model_Value_var_in_constr_prefix:\n  assumes \\<A>_reach: \"\\<A> \\<in> reachable_constraints P\"\n    and \\<I>: \"welltyped_constraint_model \\<I> \\<A>\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n  shows \"\\<forall>x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>. \\<Gamma>\\<^sub>v x = TAtom Value \\<longrightarrow> (\\<exists>B. prefix B \\<A> \\<and> x \\<notin> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t B \\<and> \\<I> x \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t B)\"\n    (is \"\\<forall>x \\<in> ?X \\<A>. ?R x \\<longrightarrow> ?Q x \\<A>\")\nusing \\<A>_reach \\<I>\nproof (induction \\<A> rule: reachable_constraints.induct)\n  case (step \\<A> T \\<xi> \\<sigma> \\<alpha>)\n  let ?P = \"\\<lambda>\\<A>. \\<forall>x \\<in> ?X \\<A>. ?R x \\<longrightarrow> ?Q x \\<A>\"\n\n  define T' where \"T' \\<equiv> dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n\n  have IH: \"?P \\<A>\" using step welltyped_constraint_model_prefix by fast\n\n  note \\<xi>_empty = admissible_transaction_decl_subst_empty[OF bspec[OF P step.hyps(2)] step.hyps(3)]\n\n  have T_adm: \"admissible_transaction T\" by (metis P step.hyps(2))\n\n  note T_wf = admissible_transaction_is_wellformed_transaction(1)[OF T_adm]\n\n  have \\<I>_is_T_model: \"strand_sem_stateful (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) (set (db\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<I>)) (unlabel T') \\<I>\"\n    using step.prems unlabel_append[of \\<A> T'] db\\<^sub>s\\<^sub>s\\<^sub>t_set_is_dbupd\\<^sub>s\\<^sub>s\\<^sub>t[of \"unlabel \\<A>\" \\<I> \"[]\"]\n          strand_sem_append_stateful[of \"{}\" \"{}\" \"unlabel \\<A>\" \"unlabel T'\" \\<I>]\n    by (simp add: T'_def welltyped_constraint_model_def constraint_model_def db\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\n  have \\<I>_interp: \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\"\n    and \\<I>_wt: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\"\n    and \\<I>_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<I>)\"\n    by (metis \\<I> welltyped_constraint_model_def constraint_model_def,\n        metis \\<I> welltyped_constraint_model_def,\n        metis \\<I> welltyped_constraint_model_def constraint_model_def)\n\n  have 1: \"?Q x \\<A>\" when x: \"x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T'\" \"\\<Gamma>\\<^sub>v x = TAtom Value\" for x\n  proof -\n    obtain n where n: \"\\<I> x = Fun n []\" \"is_Val n\" \"\\<not>public n\"\n      using constraint_model_Value_term_is_Val[\n              OF reachable_constraints.step[OF step.hyps] step.prems P x(2)]\n            x(1) fv\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel \\<A>\" \"unlabel T'\"] unlabel_append[of \\<A> T']\n      unfolding T'_def by moura\n\n    have \"x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n      using x(1) fv\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq unfolding T'_def by fastforce\n    then obtain y where y: \"y \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T)\" \"x \\<in> fv ((\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) y)\"\n      using fv\\<^sub>s\\<^sub>s\\<^sub>t_subst_obtain_var[of x \"unlabel (transaction_strand T)\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n            unlabel_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n      by auto\n\n    have y_x: \"(\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) y = Var x\" and y_not_fresh: \"y \\<notin> set (transaction_fresh T)\"\n      using y(2) transaction_decl_fresh_renaming_substs_range[OF step.hyps(3-5), of y]\n      by (force, fastforce)\n\n    have \"\\<Gamma> ((\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) y) = TAtom Value\" using x(2) y_x by simp\n    moreover have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n      by (rule transaction_decl_fresh_renaming_substs_wt[OF step.hyps(3-5)])\n    ultimately have y_val: \"\\<Gamma>\\<^sub>v y = TAtom Value\"\n      by (metis wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def \\<Gamma>.simps(1))\n\n    have \"Fun n [] = (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) y \\<cdot> \\<I>\" using n y_x by simp\n    hence y_n: \"Fun n [] = (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> \\<circ>\\<^sub>s \\<I>) y\"\n      by (metis subst_subst_compose[of \"Var y\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\" \\<I>] subst_apply_term.simps(1))\n\n    have \\<A>_ik_\\<I>_vals: \"\\<forall>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>). \\<exists>f. \\<I> x = Fun f []\"\n    proof -\n      have \"\\<exists>a. \\<Gamma> (\\<I> x) = Var a\" when \"x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>\" for x\n        using that reachable_constraints_vars_TAtom_typed[OF step.hyps(1) P, of x]\n              vars\\<^sub>s\\<^sub>s\\<^sub>t_is_fv\\<^sub>s\\<^sub>s\\<^sub>t_bvars\\<^sub>s\\<^sub>s\\<^sub>t[of \"unlabel \\<A>\"] wt_subst_trm''[OF \\<I>_wt, of \"Var x\"]\n        by force\n      hence \"\\<exists>f. \\<I> x = Fun f []\" when \"x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>\" for x\n        using that wf_trm_subst[OF \\<I>_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s, of \"Var x\"] wf_trm_Var[of x] const_type_inv_wf\n              empty_fv_exists_fun[OF interpretation_grounds[OF \\<I>_interp], of \"Var x\"] \n        by (metis subst_apply_term.simps(1)[of x \\<I>])\n      thus ?thesis\n        using fv_ik_subset_fv_sst'[of \"unlabel \\<A>\"] vars\\<^sub>s\\<^sub>s\\<^sub>t_is_fv\\<^sub>s\\<^sub>s\\<^sub>t_bvars\\<^sub>s\\<^sub>s\\<^sub>t[of \"unlabel \\<A>\"]\n        by blast\n    qed\n    hence \\<A>_subterms_subst_cong: \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) = subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n      by (metis ik\\<^sub>s\\<^sub>s\\<^sub>t_subst[of \"unlabel \\<A>\" \\<I>] unlabel_subst[of \\<A> \\<I>] subterms_subst_lsst_ik[of \\<A> \\<I>])\n\n    have x_nin_\\<A>: \"x \\<notin> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>\"\n    proof -\n      have \"x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n        using x(1) fv\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq unfolding T'_def by fast\n      hence \"x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t ((unlabel (transaction_strand T) \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<sigma>) \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<alpha>)\"\n        using transaction_fresh_subst_grounds_domain[OF step.hyps(4)] step.hyps(4)\n              labeled_stateful_strand_subst_comp[of \\<sigma> \"transaction_strand T\" \\<alpha>]\n              unlabel_subst[of \"transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<sigma>\" \\<alpha>]\n              unlabel_subst[of \"transaction_strand T\" \\<sigma>]\n        by (simp add: \\<xi>_empty transaction_fresh_subst_def range_vars_alt_def)\n      then obtain y where \"\\<alpha> y = Var x\"\n        using transaction_renaming_subst_var_obtain(1)[OF step.hyps(5)] by blast\n      thus ?thesis\n        using transaction_renaming_subst_range_notin_vars[OF step.hyps(5), of y]\n              vars\\<^sub>s\\<^sub>s\\<^sub>t_is_fv\\<^sub>s\\<^sub>s\\<^sub>t_bvars\\<^sub>s\\<^sub>s\\<^sub>t[of \"unlabel \\<A>\"]\n        by auto\n    qed\n\n    from admissible_transaction_fv_in_receives_or_selects[OF T_adm y(1) y_not_fresh]\n    have n_cases: \"Fun n [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<or> (\\<exists>z \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>. \\<Gamma>\\<^sub>v z = TAtom Value \\<and> \\<I> z = Fun n [])\"\n    proof\n      assume y_in: \"y \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T)\"\n      then obtain ts where ts:\n          \"receive\\<langle>ts\\<rangle> \\<in> set (unlabel (transaction_receive T))\" \"y \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set ts)\"\n        using admissible_transaction_strand_step_cases(1)[OF T_adm]\n        by force\n      hence ts_deduct: \"list_all (\\<lambda>t. ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> t \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> \\<cdot> \\<I>) ts\"\n        using wellformed_transaction_sem_receives[\n                OF T_wf, of \"ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" \"set (db\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<I>)\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\" \\<I> \"ts \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n              \\<I>_is_T_model\n              subst_lsst_unlabel_member[of \"receive\\<langle>ts\\<rangle>\" \"transaction_receive T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n        unfolding T'_def list_all_iff by force\n\n      obtain ty where ty: \"ty \\<in> set ts\" \"y \\<in> fv ty\" using ts(2) by fastforce\n      \n      have \"Fun n [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<or> (\\<exists>z \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>). \\<Gamma>\\<^sub>v z = TAtom Value \\<and> \\<I> z = Fun n [])\"\n      proof -\n        have \"Fun n [] \\<sqsubseteq> ty \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> \\<cdot> \\<I>\"\n          using imageI[of \"Var y\" \"subterms ty\" \"\\<lambda>x. x \\<cdot> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> \\<circ>\\<^sub>s \\<I>\"]\n                var_is_subterm[OF ty(2)] subterms_subst_subset[of \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha> \\<circ>\\<^sub>s \\<I>\" ty]\n                subst_subst_compose[of ty \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\" \\<I>] y_n\n          by (auto simp del: subst_subst_compose)\n        hence \"Fun n [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n          using ty(1) private_fun_deduct_in_ik[of _ _ n \"[]\"] n(2,3) ts_deduct\n          unfolding is_Val_def is_Abs_def list_all_iff by fast\n        hence \"Fun n [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<or> (\\<exists>z \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>). \\<I> z = Fun n [])\"\n          using const_subterm_subst_cases[of n _ \\<I>] \\<A>_ik_\\<I>_vals by fastforce\n        thus ?thesis\n          using \\<I>_wt n(2) unfolding wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def is_Val_def is_Abs_def by force\n      qed\n      thus ?thesis\n        using fv_ik_subset_fv_sst' ik\\<^sub>s\\<^sub>s\\<^sub>t_trms\\<^sub>s\\<^sub>s\\<^sub>t_subset[of \"unlabel \\<A>\"] \\<A>_subterms_subst_cong\n        by fast\n    next\n      assume y_in: \"y \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T) \\<and>\n                    (\\<exists>t s. select\\<langle>t,s\\<rangle> \\<in> set (unlabel (transaction_checks T)) \\<and> y \\<in> fv t \\<union> fv s)\"\n      then obtain s where s: \"select\\<langle>Var y,Fun (Set s) []\\<rangle> \\<in> set (unlabel (transaction_checks T))\"\n        using admissible_transaction_strand_step_cases(2)[OF T_adm] by force\n      hence \"select\\<langle>(\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) y, Fun (Set s) []\\<rangle> \\<in>\n              set (unlabel (transaction_checks T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n        using subst_lsst_unlabel_member\n        by fastforce\n      hence n_in_db: \"(Fun n [], Fun (Set s) []) \\<in> set (db'\\<^sub>s\\<^sub>s\\<^sub>t (unlabel \\<A>) \\<I> [])\"\n        using wellformed_transaction_sem_pos_checks[\n                OF T_wf, of \"ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" \"set (db\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<I>)\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\" \\<I>\n                               assign \"(\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) y\" \"Fun (Set s) []\"]\n              \\<I>_is_T_model n y_x\n        unfolding T'_def db\\<^sub>s\\<^sub>s\\<^sub>t_def\n        by fastforce\n\n      obtain tn sn where tsn: \"insert\\<langle>tn,sn\\<rangle> \\<in> set (unlabel \\<A>)\" \"Fun n [] = tn \\<cdot> \\<I>\"\n        using db\\<^sub>s\\<^sub>s\\<^sub>t_in_cases[OF n_in_db] by force\n\n      have \"Fun n [] = tn \\<or> (\\<exists>z. \\<Gamma>\\<^sub>v z = TAtom Value \\<and> tn = Var z)\"\n        using \\<I>_wt tsn(2) n(2) unfolding wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def is_Val_def is_Abs_def by (cases tn) auto\n      moreover have \"tn \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)\" \"fv tn \\<subseteq> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>\"\n        using tsn(1) in_subterms_Union by force+\n      ultimately show ?thesis using tsn(2) by auto\n    qed\n\n    from n_cases show ?thesis\n    proof\n      assume \"\\<exists>z \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>. \\<Gamma>\\<^sub>v z = TAtom Value \\<and> \\<I> z = Fun n []\"\n      then obtain B where B: \"prefix B \\<A>\" \"Fun n [] \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t B)\"\n        by (metis IH n(1))\n      thus ?thesis\n        using n x_nin_\\<A> trms\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_prefix_subset(1)[of B]\n        by (metis (no_types, opaque_lifting) self_append_conv subset_iff subterms\\<^sub>s\\<^sub>e\\<^sub>t_mono prefix_def)\n    qed (use n x_nin_\\<A> in fastforce)\n  qed\n\n  have \"?P (\\<A>@T')\"\n  proof (intro ballI impI)\n    fix x assume x: \"x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (\\<A>@T')\" \"\\<Gamma>\\<^sub>v x = TAtom Value\"\n    show \"?Q x (\\<A>@T')\"\n    proof (cases \"x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>\")\n      case False\n      hence \"x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T'\" using x(1) unlabel_append[of \\<A>] fv\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel \\<A>\"] by simp\n      then obtain B where B: \"prefix B \\<A>\" \"x \\<notin> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t B\" \"\\<I> x \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t B)\"\n        using x(2) 1 by moura\n      thus ?thesis using prefix_prefix by fast\n    qed (use x(2) IH prefix_prefix in fast)\n  qed\n  thus ?case unfolding T'_def by blast\nqed simp\n\nlemma constraint_model_Val_const_in_constr_prefix:\n  assumes \\<A>_reach: \"\\<A> \\<in> reachable_constraints P\"\n    and \\<I>: \"welltyped_constraint_model \\<I> \\<A>\"\n    and P: \"\\<forall>T \\<in> set P. wellformed_transaction T\"\n           \"\\<forall>T \\<in> set P. admissible_transaction_terms T\"\n    and n: \"Fun (Val n) [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n  shows \"Fun (Val n) [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>\"\nproof -\n  have *: \"wf\\<^sub>s\\<^sub>s\\<^sub>t (unlabel \\<A>)\"\n          \"constr_sem_stateful \\<I> (unlabel \\<A>)\"\n          \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\"\n          \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<I>)\"\n          \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\"\n    using reachable_constraints_wf(1)[OF P(1) _ \\<A>_reach]\n          admissible_transaction_terms_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s \\<I> P(2) n\n    unfolding welltyped_constraint_model_def constraint_model_def wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s_code by fast+\n\n  show ?thesis\n    using constraint_model_priv_const_in_constr_prefix[OF * _ _ n]\n    by simp\nqed\n\nlemma constraint_model_Val_const_in_constr_prefix':\n  assumes \\<A>_reach: \"\\<A> \\<in> reachable_constraints P\"\n    and \\<I>: \"welltyped_constraint_model \\<I> \\<A>\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and n: \"Fun (Val n) [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n  shows \"Fun (Val n) [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>\"\nusing constraint_model_Val_const_in_constr_prefix[OF \\<A>_reach \\<I> _ _ n]\n      P admissible_transaction_is_wellformed_transaction(1,4)\nby fast\n\nlemma constraint_model_Value_in_constr_prefix_fresh_action':\n  fixes P::\"('fun, 'atom, 'sets, 'lbl) prot_transaction list\"\n  assumes A: \"A \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction_terms T\"\n           \"\\<forall>T \\<in> set P. transaction_decl T () = []\"\n           \"\\<forall>T \\<in> set P. bvars_transaction T = {}\"\n    and n: \"Fun (Val n) [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\"\n  obtains B T \\<xi> \\<sigma> \\<alpha> where \"prefix (B@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)) A\"\n    and \"B \\<in> reachable_constraints P\" \"T \\<in> set P\" \"transaction_decl_subst \\<xi> T\"\n        \"transaction_fresh_subst \\<sigma> T B\" \"transaction_renaming_subst \\<alpha> P B\"\n    and \"Fun (Val n) [] \\<in> subst_range \\<sigma>\"\nproof -\n  define f where \"f \\<equiv>\n    \\<lambda>(T::('fun, 'atom, 'sets, 'lbl) prot_transaction,\n      \\<xi>::('fun, 'atom, 'sets, 'lbl) prot_subst,\n      \\<sigma>::('fun, 'atom, 'sets, 'lbl) prot_subst,\n      \\<alpha>::('fun, 'atom, 'sets, 'lbl) prot_subst).\n        dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n\n  define g where \"g \\<equiv> concat \\<circ> map f\"\n\n  obtain Ts where Ts:\n      \"A = g Ts\" \"\\<forall>B. prefix B Ts \\<longrightarrow> g B \\<in> reachable_constraints P\"\n      \"\\<forall>B T \\<xi> \\<sigma> \\<alpha>. prefix (B@[(T,\\<xi>,\\<sigma>,\\<alpha>)]) Ts \\<longrightarrow>\n                        T \\<in> set P \\<and> transaction_decl_subst \\<xi> T \\<and>\n                        transaction_fresh_subst \\<sigma> T (g B) \\<and> transaction_renaming_subst \\<alpha> P (g B)\"\n    using reachable_constraints_as_transaction_lists[OF A] unfolding g_def f_def by blast\n\n  obtain T \\<xi> \\<sigma> \\<alpha> where T:\n      \"(T, \\<xi>, \\<sigma>, \\<alpha>) \\<in> set Ts\" \"Fun (Val n) [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n    using n trms\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq unlabel_subst\n    unfolding Ts(1) g_def f_def unlabel_def trms\\<^sub>s\\<^sub>s\\<^sub>t_def\n    by fastforce\n  \n  obtain B where B:\n      \"prefix (B@[(T, \\<xi>, \\<sigma>, \\<alpha>)]) Ts\" \"g B \\<in> reachable_constraints P\" \"T \\<in> set P\"\n      \"transaction_decl_subst \\<xi> T\" \"transaction_fresh_subst \\<sigma> T (g B)\"\n      \"transaction_renaming_subst \\<alpha> P (g B)\"\n  proof -\n    obtain B where \"\\<exists>C. B@(T, \\<xi>, \\<sigma>, \\<alpha>)#C = Ts\" by (metis T(1) split_list)\n    thus ?thesis using Ts(2-) that[of B] by auto\n  qed\n\n  note T_adm_terms = bspec[OF P(1) B(3)]\n  note T_decl_empty = bspec[OF P(2) B(3)]\n  note T_no_bvars = bspec[OF P(3) B(3)]\n  note \\<xi>_empty = admissible_transaction_decl_subst_empty'[OF T_decl_empty B(4)]\n\n  have \"trms\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (transaction_strand T) \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) = trms_transaction T \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n    using trms\\<^sub>s\\<^sub>s\\<^sub>t_subst[of _ \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"] T_no_bvars by blast\n  hence \"Fun (Val n) [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t trms_transaction T \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n    by (metis T(2) unlabel_subst)\n  hence \"Fun (Val n) [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n    using admissible_transaction_terms_no_Value_consts(1)[OF T_adm_terms]\n          const_subterms_subst_cases'[of \"Val n\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\" \"trms_transaction T\"]\n    by blast\n  then obtain tn where tn: \"tn \\<in> subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\" \"Fun (Val n) [] \\<sqsubseteq> tn\" \"is_Fun tn\"\n    by fastforce\n\n  have \"Fun (Val n) [] \\<in> subst_range \\<sigma>\"\n    using tn(1-) transaction_decl_fresh_renaming_substs_range'(2,4)[OF B(4-6) tn(1) \\<xi>_empty]\n    by fastforce\n  moreover have \"prefix (g B@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)) A\"\n    using Ts(1) B(1) unfolding g_def f_def prefix_def by fastforce\n  ultimately show thesis using that B(2-) by blast\nqed\n\nlemma constraint_model_Value_in_constr_prefix_fresh_action:\n  fixes P::\"('fun, 'atom, 'sets, 'lbl) prot_transaction list\"\n  assumes A: \"A \\<in> reachable_constraints P\"\n    and P_adm: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and n: \"Fun (Val n) [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\"\n  obtains B T \\<xi> \\<sigma> \\<alpha> where \"prefix (B@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)) A\"\n    and \"B \\<in> reachable_constraints P\" \"T \\<in> set P\" \"transaction_decl_subst \\<xi> T\"\n        \"transaction_fresh_subst \\<sigma> T B\" \"transaction_renaming_subst \\<alpha> P B\"\n    and \"Fun (Val n) [] \\<in> subst_range \\<sigma>\"\nproof -\n  have P: \"\\<forall>T \\<in> set P. admissible_transaction_terms T\"\n          \"\\<forall>T \\<in> set P. transaction_decl T () = []\"\n          \"\\<forall>T \\<in> set P. bvars_transaction T = {}\"\n  using P_adm admissible_transactionE(1) admissible_transaction_no_bvars(2)\n        admissible_transaction_is_wellformed_transaction(4)\n  by (blast,blast,blast)\n\n  show ?thesis using that constraint_model_Value_in_constr_prefix_fresh_action'[OF A P n] by blast\nqed\n\nlemma reachable_constraints_occurs_fact_ik_case':\n  fixes A::\"('fun,'atom,'sets,'lbl) prot_constr\"\n  assumes \\<A>_reach: \"A \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and val: \"Fun (Val n) [] \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\"\n  shows \"occurs (Fun (Val n) []) \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\"\nproof -\n  obtain B T \\<xi> \\<sigma> \\<alpha> where B:\n      \"prefix (B@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)) A\"\n      \"B \\<in> reachable_constraints P\"\n      \"T \\<in> set P\"\n      \"transaction_decl_subst \\<xi> T\"\n      \"transaction_fresh_subst \\<sigma> T B\"\n      \"transaction_renaming_subst \\<alpha> P B\"\n      \"Fun (Val n) [] \\<in> subst_range \\<sigma>\"\n    using constraint_model_Value_in_constr_prefix_fresh_action[OF \\<A>_reach P val]\n    by blast\n\n  define \\<theta> where \"\\<theta> \\<equiv> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n\n  have T_adm: \"admissible_transaction T\" using P B(3) by blast\n  hence T_wf: \"wellformed_transaction T\" \"admissible_transaction_occurs_checks T\"\n    using admissible_transaction_is_wellformed_transaction(1,5) by (blast,blast)\n\n  obtain x where x: \"x \\<in> set (transaction_fresh T)\" \"\\<theta> x = Fun (Val n) []\"\n    using transaction_fresh_subst_domain[OF B(5)] B(7)\n          admissible_transaction_decl_subst_empty[OF T_adm B(4)]\n    by (force simp add: subst_compose \\<theta>_def)\n\n  obtain ts where ts: \"send\\<langle>ts\\<rangle> \\<in> set (unlabel (transaction_send T))\" \"occurs (Var x) \\<in> set ts\"\n    using admissible_transaction_occurs_checksE2[OF T_wf(2) x(1)]\n    by (metis (mono_tags, lifting) list.set_intros(1) unlabel_Cons(1))\n\n  have \"occurs (Var x) \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T)\"\n    using ts by force\n  hence \"occurs (Var x) \\<cdot> \\<theta> \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n    using dual_transaction_ik_is_transaction_send'[OF T_wf(1), of \\<theta>] by fast\n  hence \"occurs (Fun (Val n) []) \\<in> ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\n    using x(2) by simp\n  thus ?thesis\n    using B(1)[unfolded \\<theta>_def[symmetric]]\n          unlabel_append[of B \"dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"]\n          ik\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel B\" \"unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"]\n    unfolding prefix_def by force\nqed\n\nlemma admissible_transaction_occurs_checks_prop:\n  assumes \\<A>_reach: \"\\<A> \\<in> reachable_constraints P\"\n    and \\<I>: \"welltyped_constraint_model \\<I> \\<A>\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and f: \"f \\<in> \\<Union>(funs_term ` (\\<I> ` fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>))\"\n  shows \"\\<not>is_PubConstValue f\"\n    and \"\\<not>is_Abs f\"\nproof -\n  obtain x where x: \"x \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>\" \"f \\<in> funs_term (\\<I> x)\" using f by moura\n  obtain T where T: \"Fun f T \\<sqsubseteq> \\<I> x\" using funs_term_Fun_subterm[OF x(2)] by moura\n\n  have \\<I>_interp: \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\"\n    and \\<I>_wt: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\"\n    and \\<I>_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<I>)\"\n    by (metis \\<I> welltyped_constraint_model_def constraint_model_def,\n        metis \\<I> welltyped_constraint_model_def,\n        metis \\<I> welltyped_constraint_model_def constraint_model_def)\n\n  note 0 = x(1) reachable_constraints_vars_TAtom_typed[OF \\<A>_reach P, of x] \n           vars\\<^sub>s\\<^sub>s\\<^sub>t_is_fv\\<^sub>s\\<^sub>s\\<^sub>t_bvars\\<^sub>s\\<^sub>s\\<^sub>t[of \"unlabel \\<A>\"]\n\n  have 1: \"\\<Gamma> (Var x) = \\<Gamma> (\\<I> x)\" using wt_subst_trm''[OF \\<I>_wt, of \"Var x\"] by simp\n  hence \"\\<exists>a. \\<Gamma> (\\<I> x) = Var a\" using 0 by force\n  hence \"\\<exists>f. \\<I> x = Fun f []\"\n    using x(1) wf_trm_subst[OF \\<I>_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s, of \"Var x\"] wf_trm_Var[of x] const_type_inv_wf\n          empty_fv_exists_fun[OF interpretation_grounds[OF \\<I>_interp], of \"Var x\"] \n    by (metis subst_apply_term.simps(1)[of x \\<I>])\n  hence 2: \"\\<I> x = Fun f []\" using x(2) by force\n\n  have 3: \"\\<Gamma>\\<^sub>v x \\<noteq> TAtom AbsValue\" using 0 by force\n\n  have \"\\<not>is_PubConstValue f \\<and> \\<not>is_Abs f\"\n  proof (cases \"\\<Gamma>\\<^sub>v x = TAtom Value\")\n    case True\n    then obtain B where B: \"prefix B \\<A>\" \"x \\<notin> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t B\" \"\\<I> x \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t B)\"\n      using constraint_model_Value_var_in_constr_prefix[OF \\<A>_reach \\<I> P] x(1)\n      by fast\n  \n    have \"\\<I> x \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)\"\n      using B(1,3) trms\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel B\"] unlabel_append[of B]\n      unfolding prefix_def by auto\n    hence \"f \\<in> \\<Union>(funs_term ` trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)\"\n      using x(2) funs_term_subterms_eq(2)[of \"trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>\"] by blast\n    thus ?thesis\n      using reachable_constraints_val_funs_private[OF \\<A>_reach P]\n      by blast+\n  next\n    case False thus ?thesis using x 1 2 3 unfolding is_PubConstValue_def by (cases f) auto\n  qed\n  thus \"\\<not>is_PubConstValue f\" \"\\<not>is_Abs f\" by metis+\nqed\n\nlemma admissible_transaction_occurs_checks_prop':\n  assumes \\<A>_reach: \"\\<A> \\<in> reachable_constraints P\"\n    and \\<I>: \"welltyped_constraint_model \\<I> \\<A>\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and f: \"f \\<in> \\<Union>(funs_term ` (\\<I> ` fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>))\"\n  shows \"\\<nexists>n. f = PubConst Value n\"\n    and \"\\<nexists>n. f = Abs n\"\nusing admissible_transaction_occurs_checks_prop[OF \\<A>_reach \\<I> P f]\nunfolding is_PubConstValue_def by auto\n\nlemma transaction_var_becomes_Val:\n  assumes \\<A>_reach: \"\\<A>@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) \\<in> reachable_constraints P\"\n    and \\<I>: \"welltyped_constraint_model \\<I> (\\<A>@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n    and \\<xi>: \"transaction_decl_subst \\<xi> T\"\n    and \\<sigma>: \"transaction_fresh_subst \\<sigma> T \\<A>\"\n    and \\<alpha>: \"transaction_renaming_subst \\<alpha> P \\<A>\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and T: \"T \\<in> set P\"\n    and x: \"x \\<in> fv_transaction T\" \"fst x = TAtom Value\"\n  shows \"\\<exists>n. Fun (Val n) [] = (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x \\<cdot> \\<I>\"\nproof -\n  obtain m where m: \"x = (TAtom Value, m)\" by (metis x(2) eq_fst_iff)\n\n  note \\<xi>_empty = admissible_transaction_decl_subst_empty[OF bspec[OF P T] \\<xi>]\n\n  have x_not_bvar: \"x \\<notin> bvars_transaction T\" \"fv ((\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) x) \\<inter> bvars_transaction T = {}\"\n    using x(1) admissible_transactions_fv_bvars_disj[OF P] T\n          transaction_decl_fresh_renaming_substs_vars_disj(2)[OF \\<xi> \\<sigma> \\<alpha>, of x]\n          vars\\<^sub>s\\<^sub>s\\<^sub>t_is_fv\\<^sub>s\\<^sub>s\\<^sub>t_bvars\\<^sub>s\\<^sub>s\\<^sub>t[of \"unlabel (transaction_strand T)\"]\n    by (blast, blast)\n\n  have \\<sigma>x_type: \"\\<Gamma> (\\<sigma> x) = TAtom Value\"\n    using \\<sigma> x \\<Gamma>\\<^sub>v_TAtom''(2)[of x] wt_subst_trm''[of \\<sigma> \"Var x\"]\n    unfolding transaction_fresh_subst_def by simp\n\n  show ?thesis\n  proof (cases \"x \\<in> subst_domain \\<sigma>\")\n    case True\n    then obtain c where c: \"\\<sigma> x = Fun c []\" \"\\<not>public c\" \"arity c = 0\"\n      using \\<sigma> unfolding transaction_fresh_subst_def by fastforce\n    then obtain n where n: \"c = Val n\" using \\<sigma>x_type by (cases c) (auto split: option.splits)\n    show ?thesis using c n subst_compose[of \\<sigma> \\<alpha> x] \\<xi>_empty by simp\n  next\n    case False\n    hence \"\\<sigma> x = Var x\" by auto\n    then obtain n where n: \"(\\<sigma> \\<circ>\\<^sub>s \\<alpha>) x = Var (TAtom Value, n)\"\n      using m transaction_renaming_subst_is_renaming(1)[OF \\<alpha>] subst_compose[of \\<sigma> \\<alpha> x]\n      by force\n    hence \"(TAtom Value, n) \\<in> fv\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n      using x_not_bvar fv\\<^sub>s\\<^sub>s\\<^sub>t_subst_fv_subset[OF x(1), of \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n            unlabel_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"] \\<xi>_empty\n      by force\n    hence \"\\<exists>n'. \\<I> (TAtom Value, n) = Fun (Val n') []\"\n      using constraint_model_Value_term_is_Val'[OF \\<A>_reach \\<I> P, of n] x\n            fv\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq[of \"transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n            fv\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel \\<A>\"] unlabel_append[of \\<A>]\n      by fastforce\n    thus ?thesis using n \\<xi>_empty by simp\n  qed\nqed\n\nlemma reachable_constraints_SMP_subset:\n  assumes \\<A>: \"\\<A> \\<in> reachable_constraints P\"\n  shows \"SMP (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>) \\<subseteq> SMP (\\<Union>T \\<in> set P. trms_transaction T)\" (is \"?A \\<A>\")\n    and \"SMP (pair`setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel \\<A>)) \\<subseteq> SMP (\\<Union>T\\<in>set P. pair`setops_transaction T)\" (is \"?B \\<A>\")\nproof -\n  have \"?A \\<A> \\<and> ?B \\<A>\" using \\<A>\n  proof (induction \\<A> rule: reachable_constraints.induct)\n    case (step A T \\<xi> \\<sigma> \\<alpha>)\n    define T' where \"T' \\<equiv> transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n    define M where \"M \\<equiv> \\<Union>T \\<in> set P. trms_transaction T\"\n    define N where \"N \\<equiv> \\<Union>T \\<in> set P. pair ` setops_transaction T\"\n  \n    let ?P = \"\\<lambda>t. \\<exists>s \\<delta>. s \\<in> M \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> t = s \\<cdot> \\<delta>\"\n    let ?Q = \"\\<lambda>t. \\<exists>s \\<delta>. s \\<in> N \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> t = s \\<cdot> \\<delta>\"\n  \n    have IH: \"SMP (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A) \\<subseteq> SMP M\" \"SMP (pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A)) \\<subseteq> SMP N\"\n      using step.IH by (metis M_def, metis N_def)\n  \n    note \\<xi>\\<sigma>\\<alpha>_wt = transaction_decl_fresh_renaming_substs_wt[OF step.hyps(3-5)]\n    note \\<xi>\\<sigma>\\<alpha>_wf = transaction_decl_fresh_renaming_substs_range_wf_trms[OF step.hyps(3-5)]\n\n    have 0: \"SMP (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T')) = SMP (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A) \\<union> SMP (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T')\"\n            \"SMP (pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T'))) =\n              SMP (pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A)) \\<union> SMP (pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel T'))\"\n      using trms\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq[of T']\n            setops\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq[of T']\n            trms\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel A\" \"unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T')\"]\n            setops\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel A\" \"unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T')\"]\n            unlabel_append[of A \"dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T'\"]\n            image_Un[of pair \"setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A)\" \"setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel T')\"]\n            SMP_union[of \"trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\" \"trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T'\"]\n            SMP_union[of \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A)\" \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel T')\"]\n      by argo+\n  \n    have 1: \"SMP (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T') \\<subseteq> SMP M\"\n    proof (intro SMP_subset_I ballI)\n      fix t show \"t \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T' \\<Longrightarrow> ?P t\"\n        using trms\\<^sub>s\\<^sub>s\\<^sub>t_wt_subst_ex[OF \\<xi>\\<sigma>\\<alpha>_wt \\<xi>\\<sigma>\\<alpha>_wf, of t \"unlabel (transaction_strand T)\"]\n              unlabel_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"] step.hyps(2)\n        unfolding T'_def M_def by auto\n    qed\n  \n    have 2: \"SMP (pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel T')) \\<subseteq> SMP N\"\n    proof (intro SMP_subset_I ballI)\n      fix t show \"t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel T') \\<Longrightarrow> ?Q t\"\n        using setops\\<^sub>s\\<^sub>s\\<^sub>t_wt_subst_ex[OF \\<xi>\\<sigma>\\<alpha>_wt \\<xi>\\<sigma>\\<alpha>_wf, of t \"unlabel (transaction_strand T)\"]\n              unlabel_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"] step.hyps(2)\n        unfolding T'_def N_def by auto\n    qed\n  \n    have \"SMP (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T')) \\<subseteq> SMP M\"\n         \"SMP (pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (A@dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T'))) \\<subseteq> SMP N\"\n      using 0 1 2 IH by blast+\n    thus ?case unfolding T'_def M_def N_def by blast\n  qed (simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n  thus \"?A \\<A>\" \"?B \\<A>\" by metis+\nqed\n\nlemma reachable_constraints_no_Pair_fun':\n  assumes A: \"A \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. \\<forall>x \\<in> set (transaction_fresh T). \\<Gamma>\\<^sub>v x = TAtom Value\"\n           \"\\<forall>T \\<in> set P. transaction_decl T () = []\"\n           \"\\<forall>T \\<in> set P. admissible_transaction_terms T\"\n           \"\\<forall>T \\<in> set P. \\<forall>x \\<in> vars_transaction T. \\<Gamma>\\<^sub>v x = TAtom Value \\<or> (\\<exists>a. \\<Gamma>\\<^sub>v x = \\<langle>a\\<rangle>\\<^sub>\\<tau>\\<^sub>a)\"\n  shows \"Pair \\<notin> \\<Union>(funs_term ` SMP (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A))\"\nusing A\nproof (induction A rule: reachable_constraints.induct)\n  case (step A T \\<xi> \\<sigma> \\<alpha>)\n  define T' where \"T' \\<equiv> dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n\n  note T_fresh_type = bspec[OF P(1) step.hyps(2)]\n\n  note \\<xi>_empty =\n    admissible_transaction_decl_subst_empty'[OF bspec[OF P(2) step.hyps(2)] step.hyps(3)]\n\n  note T_adm_terms = bspec[OF P(3) step.hyps(2)]\n\n  note \\<xi>\\<sigma>\\<alpha>_wt = transaction_decl_fresh_renaming_substs_wt[OF step.hyps(3-5)]\n  note \\<xi>\\<sigma>\\<alpha>_wf = transaction_decl_fresh_renaming_substs_range_wf_trms[OF step.hyps(3-5)]\n\n  have 0: \"SMP (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A@T')) = SMP (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A) \\<union> SMP (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T')\"\n    using SMP_union[of \"trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\" \"trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T'\"]\n          unlabel_append[of A T'] trms\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel A\" \"unlabel T'\"]\n    by simp\n\n  have 1: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T')\"\n    using reachable_constraints_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s[OF _ reachable_constraints.step[OF step.hyps]]\n          admissible_transaction_terms_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s P(3)\n          trms\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel A\"] unlabel_append[of A]\n    unfolding T'_def by force\n\n  have 2: \"Pair \\<notin> \\<Union>(funs_term ` (subst_range (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)))\"\n    using transaction_decl_fresh_renaming_substs_range'(3)[\n            OF step.hyps(3-5) _ \\<xi>_empty T_fresh_type]\n    by force\n\n  have \"Pair \\<notin> \\<Union>(funs_term ` (trms_transaction T))\"\n    using T_adm_terms unfolding admissible_transaction_terms_def by blast\n  hence \"Pair \\<notin> funs_term t\"\n    when t: \"t \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (transaction_strand T) \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\" for t\n    using 2 trms\\<^sub>s\\<^sub>s\\<^sub>t_funs_term_cases[OF t]\n    by force\n  hence 3: \"Pair \\<notin> funs_term t\" when t: \"t \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T'\" for t\n    using t unlabel_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n          trms\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq[of \"transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n    unfolding T'_def by metis\n\n  have \"\\<exists>a. \\<Gamma>\\<^sub>v x = TAtom a\" when \"x \\<in> vars_transaction T\" for x\n    using that protocol_transaction_vars_TAtom_typed(1) bspec[OF P(4) step.hyps(2)]\n    by fast\n  hence \"\\<exists>a. \\<Gamma>\\<^sub>v x = TAtom a\" when \"x \\<in> vars\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (transaction_strand T) \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\" for x\n    using wt_subst_fv\\<^sub>s\\<^sub>e\\<^sub>t_termtype_subterm[OF _ \\<xi>\\<sigma>\\<alpha>_wt \\<xi>\\<sigma>\\<alpha>_wf, of x \"vars_transaction T\"]\n          vars\\<^sub>s\\<^sub>s\\<^sub>t_subst_cases[OF that]\n    by fastforce\n  hence \"\\<exists>a. \\<Gamma>\\<^sub>v x = TAtom a\" when \"x \\<in> vars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T'\" for x\n    using that unlabel_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n          vars\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq[of \"transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n    unfolding T'_def\n    by simp\n  hence \"\\<exists>a. \\<Gamma>\\<^sub>v x = TAtom a\" when \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T')\" for x\n    using that fv_trms\\<^sub>s\\<^sub>s\\<^sub>t_subset(1) by fast\n  hence \"Pair \\<notin> funs_term (\\<Gamma> (Var x))\" when \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T')\" for x\n    using that by fastforce\n  moreover have \"Pair \\<in> funs_term s\"\n    when s: \"Ana s = (K, M)\" \"Pair \\<in> \\<Union>(funs_term ` set K)\"\n    for s::\"('fun,'atom,'sets,'lbl) prot_term\" and K M\n  proof (cases s)\n    case (Fun f S) thus ?thesis using s Ana_Fu_keys_not_pairs[of _ S K M] by (cases f) force+\n  qed (use s in simp)\n  ultimately have \"Pair \\<notin> funs_term t\" when t: \"t \\<in> SMP (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t T')\" for t\n    using t 3 SMP_funs_term[OF t _ _ 1, of Pair] funs_term_type_iff by fastforce\n  thus ?case using 0 step.IH(1) unfolding T'_def by blast\nqed simp\n\nlemma reachable_constraints_no_Pair_fun:\n  assumes A: \"A \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n  shows \"Pair \\<notin> \\<Union>(funs_term ` SMP (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A))\"\nusing reachable_constraints_no_Pair_fun'[OF A]\n      P admissible_transactionE(1,2,3)\n      admissible_transaction_is_wellformed_transaction(4)\nby blast\n\nlemma reachable_constraints_setops_form:\n  assumes A: \"A \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and t: \"t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A)\"\n  shows \"\\<exists>c s. t = pair (c, Fun (Set s) []) \\<and> \\<Gamma> c = TAtom Value\"\nusing A t\nproof (induction A rule: reachable_constraints.induct)\n  case (step A T \\<xi> \\<sigma> \\<alpha>) \n\n  have T_adm: \"admissible_transaction T\" when \"T \\<in> set P\" for T\n    using P that unfolding list_all_iff by simp\n\n  note T_adm' = admissible_transaction_is_wellformed_transaction(2,3)[OF T_adm]\n  note T_wf = admissible_transaction_is_wellformed_transaction(1)[OF T_adm]\n\n  note \\<xi>\\<sigma>\\<alpha>_wt = transaction_decl_fresh_renaming_substs_wt[OF step.hyps(3-5)]\n  note \\<xi>\\<sigma>\\<alpha>_wf = transaction_decl_fresh_renaming_substs_range_wf_trms[OF step.hyps(3-5)]\n  \n  show ?case using step.IH\n  proof (cases \"t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A)\")\n    case False\n    hence \"t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (transaction_strand T) \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n      using step.prems setops\\<^sub>s\\<^sub>s\\<^sub>t_append unlabel_append\n            setops\\<^sub>s\\<^sub>s\\<^sub>t_unlabel_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_eq[of \"transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n            unlabel_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n      by fastforce\n    then obtain t' \\<delta> where t':\n        \"t' \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (transaction_strand T))\"\n        \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\" \"t = t' \\<cdot> \\<delta>\"\n      using setops\\<^sub>s\\<^sub>s\\<^sub>t_wt_subst_ex[OF \\<xi>\\<sigma>\\<alpha>_wt \\<xi>\\<sigma>\\<alpha>_wf] by blast\n    then obtain s s' where s: \"t' = pair (s,s')\"\n      using setops\\<^sub>s\\<^sub>s\\<^sub>t_are_pairs by fastforce\n    moreover have \"InSet ac s s' = InSet Assign s s' \\<or> InSet ac s s' = InSet Check s s'\" for ac\n      by (cases ac) simp_all\n    ultimately have \"\\<exists>n. s = Var (Var Value, n)\" \"\\<exists>u. s' = Fun (Set u) []\"\n      using t'(1) setops\\<^sub>s\\<^sub>s\\<^sub>t_member_iff[of s s' \"unlabel (transaction_strand T)\"]\n            pair_in_pair_image_iff[of s s']\n            transaction_inserts_are_Value_vars[\n              OF T_wf[OF step.hyps(2)] T_adm'(2)[OF step.hyps(2)], of s s']\n            transaction_deletes_are_Value_vars[\n              OF T_wf[OF step.hyps(2)] T_adm'(2)[OF step.hyps(2)], of s s']\n            transaction_selects_are_Value_vars[\n              OF T_wf[OF step.hyps(2)] T_adm'(1)[OF step.hyps(2)], of s s']\n            transaction_inset_checks_are_Value_vars[\n              OF T_adm[OF step.hyps(2)], of s s']\n            transaction_notinset_checks_are_Value_vars[\n              OF T_adm[OF step.hyps(2)], of _ _ _ s s']\n      by metis+\n    then obtain ss n where ss: \"t = pair (\\<delta> (Var Value, n), Fun (Set ss) [])\"\n      using t'(4) s unfolding pair_def by force\n\n    have \"\\<Gamma> (\\<delta> (Var Value, n)) = TAtom Value\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m (\\<delta> (Var Value, n))\"\n      using t'(2) wt_subst_trm''[OF t'(2), of \"Var (Var Value, n)\"] apply simp\n      using t'(3) by (cases \"(Var Value, n) \\<in> subst_domain \\<delta>\") auto\n    thus ?thesis using ss by blast\n  qed simp\nqed (simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma reachable_constraints_setops_type:\n  fixes t::\"('fun,'atom,'sets,'lbl) prot_term\"\n  assumes A: \"A \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n    and t: \"t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A)\"\n  shows \"\\<Gamma> t = TComp Pair [TAtom Value, TAtom SetType]\"\nproof -\n  obtain s c where s: \"t = pair (c, Fun (Set s) [])\" \"\\<Gamma> c = TAtom Value\"\n    using reachable_constraints_setops_form[OF A P t] by moura\n  hence \"(Fun (Set s) []::('fun,'atom,'sets,'lbl) prot_term) \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\"\n    using t setops\\<^sub>s\\<^sub>s\\<^sub>t_member_iff[of c \"Fun (Set s) []\" \"unlabel A\"]\n    by force\n  hence \"wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun (Set s) []::('fun,'atom,'sets,'lbl) prot_term)\"\n    using reachable_constraints_wf(2) P A admissible_transaction_is_wellformed_transaction(1,4)\n    unfolding admissible_transaction_terms_def by blast\n  hence \"arity (Set s) = 0\" unfolding wf\\<^sub>t\\<^sub>r\\<^sub>m_def by simp\n  thus ?thesis using s unfolding pair_def by fastforce\nqed\n\nlemma reachable_constraints_setops_same_type_if_unifiable:\n  assumes A: \"A \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n  shows \"\\<forall>s \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A). \\<forall>t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A).\n          (\\<exists>\\<delta>. Unifier \\<delta> s t) \\<longrightarrow> \\<Gamma> s = \\<Gamma> t\"\n    (is \"?P A\")\nusing reachable_constraints_setops_type[OF A P] by simp\n\nlemma reachable_constraints_setops_unfiable_if_wt_instance_unifiable:\n  assumes A: \"A \\<in> reachable_constraints P\"\n    and P: \"\\<forall>T \\<in> set P. admissible_transaction T\"\n  shows \"\\<forall>s \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A). \\<forall>t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A).\n          (\\<exists>\\<sigma> \\<theta> \\<rho>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma> \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<sigma>) \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>) \\<and>\n                   Unifier \\<rho> (s \\<cdot> \\<sigma>) (t \\<cdot> \\<theta>))\n          \\<longrightarrow> (\\<exists>\\<delta>. Unifier \\<delta> s t)\"\nproof (intro ballI impI)\n  fix s t assume st: \"s \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A)\" \"t \\<in> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel A)\" and\n    \"\\<exists>\\<sigma> \\<theta> \\<rho>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma> \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<sigma>) \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>) \\<and>\n             Unifier \\<rho> (s \\<cdot> \\<sigma>) (t \\<cdot> \\<theta>)\"\n  then obtain \\<sigma> \\<theta> \\<rho> where \\<sigma>:\n      \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma>\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<sigma>)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n      \"Unifier \\<rho> (s \\<cdot> \\<sigma>) (t \\<cdot> \\<theta>)\"\n    by moura\n\n  obtain fs ft cs ct where c:\n      \"s = pair (cs, Fun (Set fs) [])\" \"t = pair (ct, Fun (Set ft) [])\"\n      \"\\<Gamma> cs = TAtom Value\" \"\\<Gamma> ct = TAtom Value\" \n    using reachable_constraints_setops_form[OF A P st(1)]\n          reachable_constraints_setops_form[OF A P st(2)]\n    by moura\n\n  have \"cs \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A)\" \"ct \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A)\"\n    using c(1,2) setops_subterm_trms[OF st(1), of cs] setops_subterm_trms[OF st(2), of ct]\n          Fun_param_is_subterm[of cs \"args s\"] Fun_param_is_subterm[of ct \"args t\"]\n    unfolding pair_def by simp_all\n  moreover have\n      \"\\<forall>T \\<in> set P. wellformed_transaction T\"\n      \"\\<forall>T \\<in> set P. wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s' arity (trms_transaction T)\"\n    using P admissible_transaction_is_wellformed_transaction(1,4)\n    unfolding admissible_transaction_terms_def by fast+\n  ultimately have *: \"wf\\<^sub>t\\<^sub>r\\<^sub>m cs\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m ct\"\n    using reachable_constraints_wf(2)[OF _ _ A] wf_trms_subterms by blast+\n\n  have \"(\\<exists>x. cs = Var x) \\<or> (\\<exists>c d. cs = Fun c [])\"\n    using const_type_inv_wf c(3) *(1) by (cases cs) auto\n  moreover have \"(\\<exists>x. ct = Var x) \\<or> (\\<exists>c d. ct = Fun c [])\"\n    using const_type_inv_wf c(4) *(2) by (cases ct) auto\n  ultimately show \"\\<exists>\\<delta>. Unifier \\<delta> s t\"\n    using reachable_constraints_setops_form[OF A P] reachable_constraints_setops_type[OF A P] st \\<sigma> c\n    unfolding pair_def by auto\nqed\n\nlemma reachable_constraints_tfr:\n  assumes M:\n      \"M \\<equiv> \\<Union>T \\<in> set P. trms_transaction T\"\n      \"has_all_wt_instances_of \\<Gamma> M N\"\n      \"finite N\"\n      \"tfr\\<^sub>s\\<^sub>e\\<^sub>t N\"\n      \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s N\"\n    and P:\n      \"\\<forall>T \\<in> set P. admissible_transaction T\"\n      \"\\<forall>T \\<in> set P. list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (unlabel (transaction_strand T))\"\n    and \\<A>: \"\\<A> \\<in> reachable_constraints P\"\n  shows \"tfr\\<^sub>s\\<^sub>s\\<^sub>t (unlabel \\<A>)\"\nusing \\<A>\nproof (induction \\<A> rule: reachable_constraints.induct)\n  case (step A T \\<xi> \\<sigma> \\<alpha>)\n  define T' where \"T' \\<equiv> dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n\n  have AT'_reach: \"A@T' \\<in> reachable_constraints P\"\n    using reachable_constraints.step[OF step.hyps] unfolding T'_def by metis\n\n  have T_adm: \"admissible_transaction T\" using step.hyps(2) P(1) by blast\n\n  note \\<xi>_empty = admissible_transaction_decl_subst_empty[OF T_adm step.hyps(3)]\n\n  note \\<xi>\\<sigma>\\<alpha>_wt = transaction_decl_fresh_renaming_substs_wt[OF step.hyps(3-5)]\n  note \\<xi>\\<sigma>\\<alpha>_wf = transaction_decl_fresh_renaming_substs_range_wf_trms[OF step.hyps(3-5)]\n\n  have \\<xi>\\<sigma>\\<alpha>_bvars_disj: \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T) \\<inter> range_vars (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) = {}\"\n    using transaction_decl_fresh_renaming_substs_vars_disj(4)[OF step.hyps(3,4,5,2)]\n          \\<xi>_empty\n    by simp\n\n  have wf_trms_M: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s M\"\n    using admissible_transactions_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s P(1)\n    unfolding M(1) by blast\n\n  have \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A@T'))\"\n    using reachable_constraints_SMP_subset(1)[OF AT'_reach]\n          tfr_subset(3)[OF M(4), of \"trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A@T')\"]\n          SMP_SMP_subset[of M N] SMP_I'[OF wf_trms_M M(5,2)]\n    unfolding M(1) by blast\n  moreover have \"\\<forall>p. Ana (pair p) = ([],[])\" unfolding pair_def by auto\n  ultimately have 1: \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A@T') \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (A@T')))\"\n    using tfr_setops_if_tfr_trms[of \"unlabel (A@T')\"]\n          reachable_constraints_no_Pair_fun[OF AT'_reach P(1)]\n          reachable_constraints_setops_same_type_if_unifiable[OF AT'_reach P(1)]\n          reachable_constraints_setops_unfiable_if_wt_instance_unifiable[OF AT'_reach P(1)]\n    by blast\n\n  have \"list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (unlabel (transaction_strand T))\"\n    using step.hyps(2) P(2) tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_is_comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p\n    unfolding comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t_def tfr\\<^sub>s\\<^sub>s\\<^sub>t_def by fastforce\n  hence \"list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (unlabel T')\"\n    using tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_all_wt_subst_apply[OF _ \\<xi>\\<sigma>\\<alpha>_wt \\<xi>\\<sigma>\\<alpha>_wf \\<xi>\\<sigma>\\<alpha>_bvars_disj]\n          dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p[of \"transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n          unlabel_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n    unfolding T'_def by argo\n  hence 2: \"list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (unlabel (A@T'))\"\n    using step.IH unlabel_append\n    unfolding tfr\\<^sub>s\\<^sub>s\\<^sub>t_def by auto\n\n  have \"tfr\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (A@T'))\" using 1 2 by (metis tfr\\<^sub>s\\<^sub>s\\<^sub>t_def)\n  thus ?case by (metis T'_def)\nqed simp\n\nlemma reachable_constraints_tfr':\n  assumes M:\n      \"M \\<equiv> \\<Union>T \\<in> set P. trms_transaction T \\<union> pair' Pair ` setops_transaction T\"\n      \"has_all_wt_instances_of \\<Gamma> M N\"\n      \"finite N\"\n      \"tfr\\<^sub>s\\<^sub>e\\<^sub>t N\"\n      \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s N\"\n    and P:\n      \"\\<forall>T \\<in> set P. wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s' arity (trms_transaction T)\"\n      \"\\<forall>T \\<in> set P. list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (unlabel (transaction_strand T))\"\n    and \\<A>: \"\\<A> \\<in> reachable_constraints P\"\n  shows \"tfr\\<^sub>s\\<^sub>s\\<^sub>t (unlabel \\<A>)\"\nusing \\<A>\nproof (induction \\<A> rule: reachable_constraints.induct)\n  case (step A T \\<xi> \\<sigma> \\<alpha>)\n  define T' where \"T' \\<equiv> dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n\n  have AT'_reach: \"A@T' \\<in> reachable_constraints P\"\n    using reachable_constraints.step[OF step.hyps] unfolding T'_def by metis\n\n  note \\<xi>\\<sigma>\\<alpha>_wt = transaction_decl_fresh_renaming_substs_wt[OF step.hyps(3-5)]\n  note \\<xi>\\<sigma>\\<alpha>_wf = transaction_decl_fresh_renaming_substs_range_wf_trms[OF step.hyps(3-5)]\n\n  have \\<xi>\\<sigma>\\<alpha>_bvars_disj: \"bvars\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T) \\<inter> range_vars (\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>) = {}\"\n    by (rule transaction_decl_fresh_renaming_substs_vars_disj(4)[OF step.hyps(3,4,5,2)])\n\n  have wf_trms_M: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s M\"\n    using P(1) setops\\<^sub>s\\<^sub>s\\<^sub>t_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s(2) unfolding M(1) pair_code wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s_code[symmetric] by fast\n\n  have \"SMP (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A@T')) \\<subseteq> SMP M\" \"SMP (pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (A@T'))) \\<subseteq> SMP M\"\n    using reachable_constraints_SMP_subset[OF AT'_reach]\n          SMP_mono[of \"\\<Union>T \\<in> set P. trms_transaction T\" M]\n          SMP_mono[of \"\\<Union>T \\<in> set P. pair ` setops_transaction T\" M]\n    unfolding M(1) pair_code[symmetric] by blast+\n  hence 1: \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A@T') \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (A@T')))\"\n    using tfr_subset(3)[OF M(4), of \"trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A@T') \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (A@T'))\"]\n          SMP_union[of \"trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A@T')\" \"pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (A@T'))\"]\n          SMP_SMP_subset[of M N] SMP_I'[OF wf_trms_M M(5,2)]\n    by blast\n\n  have \"list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (unlabel (transaction_strand T))\"\n    using step.hyps(2) P(2) tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_is_comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p\n    unfolding comp_tfr\\<^sub>s\\<^sub>s\\<^sub>t_def tfr\\<^sub>s\\<^sub>s\\<^sub>t_def by fastforce\n  hence \"list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (unlabel T')\"\n    using tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_all_wt_subst_apply[OF _ \\<xi>\\<sigma>\\<alpha>_wt \\<xi>\\<sigma>\\<alpha>_wf \\<xi>\\<sigma>\\<alpha>_bvars_disj]\n          dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p[of \"transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n          unlabel_subst[of \"transaction_strand T\" \"\\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"]\n    unfolding T'_def by argo\n  hence 2: \"list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (unlabel (A@T'))\"\n    using step.IH unlabel_append\n    unfolding tfr\\<^sub>s\\<^sub>s\\<^sub>t_def by auto\n\n  have \"tfr\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (A@T'))\" using 1 2 by (metis tfr\\<^sub>s\\<^sub>s\\<^sub>t_def)\n  thus ?case by (metis T'_def)\nqed simp\n\nlemma reachable_constraints_typing_cond\\<^sub>s\\<^sub>s\\<^sub>t:\n  assumes M:\n      \"M \\<equiv> \\<Union>T \\<in> set P. trms_transaction T \\<union> pair' Pair ` setops_transaction T\"\n      \"has_all_wt_instances_of \\<Gamma> M N\"\n      \"finite N\"\n      \"tfr\\<^sub>s\\<^sub>e\\<^sub>t N\"\n      \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s N\"\n    and P:\n      \"\\<forall>T \\<in> set P. wellformed_transaction T\"\n      \"\\<forall>T \\<in> set P. wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s' arity (trms_transaction T)\"\n      \"\\<forall>T \\<in> set P. list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (unlabel (transaction_strand T))\"\n    and \\<A>: \"\\<A> \\<in> reachable_constraints P\"\n  shows \"typing_cond\\<^sub>s\\<^sub>s\\<^sub>t (unlabel \\<A>)\"\nusing reachable_constraints_wf[OF P(1,2) \\<A>] reachable_constraints_tfr'[OF M P(2,3) \\<A>]\nunfolding typing_cond\\<^sub>s\\<^sub>s\\<^sub>t_def by blast\n\ncontext\nbegin\nprivate lemma reachable_constraints_typing_result_aux:\n  assumes 0: \"wf\\<^sub>s\\<^sub>s\\<^sub>t (unlabel \\<A>)\" \"tfr\\<^sub>s\\<^sub>s\\<^sub>t (unlabel \\<A>)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)\"\n  shows \"wf\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (\\<A>@[(l,send\\<langle>[attack\\<langle>n\\<rangle>]\\<rangle>)]))\" \"tfr\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (\\<A>@[(l,send\\<langle>[attack\\<langle>n\\<rangle>]\\<rangle>)]))\"\n        \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (\\<A>@[(l,send\\<langle>[attack\\<langle>n\\<rangle>]\\<rangle>)]))\"\nproof -\n  let ?n = \"[(l,send\\<langle>[attack\\<langle>n\\<rangle>]\\<rangle>)]\"\n  let ?A = \"\\<A>@?n\"\n\n  show \"wf\\<^sub>s\\<^sub>s\\<^sub>t (unlabel ?A)\"\n    using 0(1) wf\\<^sub>s\\<^sub>s\\<^sub>t_append_suffix'[of \"{}\" \"unlabel \\<A>\" \"unlabel ?n\"] unlabel_append[of \\<A> ?n]\n    by simp\n\n  show \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t ?A)\"\n    using 0(3) trms\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel \\<A>\" \"unlabel ?n\"] unlabel_append[of \\<A> ?n]\n    by fastforce\n\n  have \"\\<forall>t \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t ?n \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel ?n). \\<exists>c. t = Fun c []\"\n       \"\\<forall>t \\<in> trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t ?n \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel ?n). Ana t = ([],[])\"\n    by (simp_all add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n  hence \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A> \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel \\<A>) \\<union>\n                (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t ?n \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel ?n)))\"\n    using 0(2) tfr_consts_mono unfolding tfr\\<^sub>s\\<^sub>s\\<^sub>t_def by blast\n  hence \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (\\<A>@?n) \\<union> pair ` setops\\<^sub>s\\<^sub>s\\<^sub>t (unlabel (\\<A>@?n)))\"\n    using unlabel_append[of \\<A> ?n] trms\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel \\<A>\" \"unlabel ?n\"]\n          setops\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"unlabel \\<A>\" \"unlabel ?n\"]\n    by (simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n  thus \"tfr\\<^sub>s\\<^sub>s\\<^sub>t (unlabel ?A)\"\n    using 0(2) unlabel_append[of ?A ?n]\n    unfolding tfr\\<^sub>s\\<^sub>s\\<^sub>t_def by auto\nqed\n\nlemma reachable_constraints_typing_result:\n  fixes P\n  assumes M:\n      \"has_all_wt_instances_of \\<Gamma> (\\<Union>T \\<in> set P. trms_transaction T) N\"\n      \"finite N\"\n      \"tfr\\<^sub>s\\<^sub>e\\<^sub>t N\"\n      \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s N\"\n    and P:\n      \"\\<forall>T \\<in> set P. admissible_transaction T\"\n      \"\\<forall>T \\<in> set P. list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (unlabel (transaction_strand T))\"\n    and A: \"\\<A> \\<in> reachable_constraints P\"\n    and \\<I>: \"constraint_model \\<I> (\\<A>@[(l, send\\<langle>[attack\\<langle>n\\<rangle>]\\<rangle>)])\"\n  shows \"\\<exists>\\<I>\\<^sub>\\<tau>. welltyped_constraint_model \\<I>\\<^sub>\\<tau> (\\<A>@[(l, send\\<langle>[attack\\<langle>n\\<rangle>]\\<rangle>)])\"\nproof -\n  have I:\n      \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<I>)\"\n      \"constr_sem_stateful \\<I> (unlabel (\\<A>@[(l, send\\<langle>[attack\\<langle>n\\<rangle>]\\<rangle>)]))\"\n    using \\<I> unfolding constraint_model_def by metis+\n\n  have \"\\<forall>T \\<in> set P. wellformed_transaction T\"\n       \"\\<forall>T \\<in> set P. admissible_transaction_terms T\"\n    using P(1,2) admissible_transaction_is_wellformed_transaction(1,4) by blast+\n  moreover have \"\\<forall>T \\<in> set P. wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s' arity (trms_transaction T)\"\n    using P(1,2) admissible_transaction_is_wellformed_transaction(4)\n    unfolding admissible_transaction_terms_def by blast\n  ultimately have 0: \"wf\\<^sub>s\\<^sub>s\\<^sub>t (unlabel \\<A>)\" \"tfr\\<^sub>s\\<^sub>s\\<^sub>t (unlabel \\<A>)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)\"\n    using reachable_constraints_tfr[OF _ M P A] reachable_constraints_wf[OF _ _ A] by metis+\n\n  show ?thesis\n    using stateful_typing_result[OF reachable_constraints_typing_result_aux[OF 0] I(1,3)]\n    by (metis welltyped_constraint_model_def constraint_model_def)\nqed\n\nlemma reachable_constraints_typing_result':\n  fixes P\n  assumes M:\n      \"M \\<equiv> \\<Union>T \\<in> set P. trms_transaction T \\<union> pair' Pair ` setops_transaction T\"\n      \"has_all_wt_instances_of \\<Gamma> M N\"\n      \"finite N\"\n      \"tfr\\<^sub>s\\<^sub>e\\<^sub>t N\"\n      \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s N\"\n    and P:\n      \"\\<forall>T \\<in> set P. wellformed_transaction T\"\n      \"\\<forall>T \\<in> set P. wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s' arity (trms_transaction T)\"\n      \"\\<forall>T \\<in> set P. list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (unlabel (transaction_strand T))\"\n    and A: \"\\<A> \\<in> reachable_constraints P\"\n    and \\<I>: \"constraint_model \\<I> (\\<A>@[(l, send\\<langle>[attack\\<langle>n\\<rangle>]\\<rangle>)])\"\n  shows \"\\<exists>\\<I>\\<^sub>\\<tau>. welltyped_constraint_model \\<I>\\<^sub>\\<tau> (\\<A>@[(l, send\\<langle>[attack\\<langle>n\\<rangle>]\\<rangle>)])\"\nproof -\n  have I:\n      \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<I>)\"\n      \"constr_sem_stateful \\<I> (unlabel (\\<A>@[(l, send\\<langle>[attack\\<langle>n\\<rangle>]\\<rangle>)]))\"\n    using \\<I> unfolding constraint_model_def by metis+\n\n  have 0: \"wf\\<^sub>s\\<^sub>s\\<^sub>t (unlabel \\<A>)\" \"tfr\\<^sub>s\\<^sub>s\\<^sub>t (unlabel \\<A>)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>)\"\n    using reachable_constraints_tfr'[OF M P(2-3) A]\n          reachable_constraints_wf[OF P(1,2) A]\n    by metis+\n\n  show ?thesis\n    using stateful_typing_result[OF reachable_constraints_typing_result_aux[OF 0] I(1,3)]\n    by (metis welltyped_constraint_model_def constraint_model_def)\nqed\nend\n\nlemma reachable_constraints_transaction_proj:\n  assumes \"\\<A> \\<in> reachable_constraints P\"\n  shows \"proj n \\<A> \\<in> reachable_constraints (map (transaction_proj n) P)\"\nusing assms\nproof (induction \\<A> rule: reachable_constraints.induct)\n  case (step \\<A> T \\<xi> \\<sigma> \\<alpha>) show ?case\n    using step.hyps(2) reachable_constraints.step[OF\n            step.IH _ transaction_decl_subst_proj[OF step.hyps(3)]\n            transaction_fresh_subst_proj[OF step.hyps(4)]\n            transaction_renaming_subst_proj[OF step.hyps(5)]]\n    by (simp add: proj_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t proj_subst transaction_strand_proj)\nqed (simp add: reachable_constraints.init)\n\ncontext\nbegin\nprivate lemma reachable_constraints_par_comp\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_aux:\n  fixes P\n  defines \"Ts \\<equiv> concat (map transaction_strand P)\"\n  assumes A: \"A \\<in> reachable_constraints P\"\n  shows \"\\<forall>b \\<in> set (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A). \\<exists>a \\<in> set Ts. \\<exists>\\<delta>. b = a \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<delta> \\<and>\n      wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and>\n      (\\<forall>t \\<in> subst_range \\<delta>. (\\<exists>x. t = Var x) \\<or> (\\<exists>c. t = Fun c []))\"\n    (is \"\\<forall>b \\<in> set (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A). \\<exists>a \\<in> set Ts. ?P b a\")\nusing A\nproof (induction A rule: reachable_constraints.induct)\n  case (step \\<A> T \\<xi> \\<sigma> \\<alpha>)\n  define Q where \"Q \\<equiv> ?P\"\n  define \\<theta> where \"\\<theta> \\<equiv> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n\n  let ?R = \"\\<lambda>A Ts. \\<forall>b \\<in> set A. \\<exists>a \\<in> set Ts. Q b a\"\n\n  have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n       \"\\<forall>t \\<in> subst_range \\<theta>. (\\<exists>x. t = Var x) \\<or> (\\<exists>c. t = Fun c [])\"\n    using transaction_decl_fresh_renaming_substs_wt[OF step.hyps(3-5)]\n          transaction_decl_fresh_renaming_substs_range_wf_trms[OF step.hyps(3-5)]\n          transaction_decl_fresh_renaming_substs_range'(1)[OF step.hyps(3-5)]\n    unfolding \\<theta>_def by (metis,metis,fastforce)\n  hence \"?R (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T)) \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>) (transaction_strand T)\"\n    using dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_self_inverse[of \"transaction_strand T\"]\n    by (auto simp add: Q_def subst_apply_labeled_stateful_strand_def)\n  hence \"?R (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))) (transaction_strand T)\"\n    by (metis dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_subst)\n  hence \"?R (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))) Ts\"\n    using step.hyps(2) unfolding Ts_def dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_def by fastforce\n  thus ?case using step.IH unfolding Q_def \\<theta>_def by auto\nqed simp\n\nlemma reachable_constraints_par_comp\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t:\n  fixes P\n  defines \"f \\<equiv> \\<lambda>M. {t \\<cdot> \\<delta> | t \\<delta>. t \\<in> M \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> fv (t \\<cdot> \\<delta>) = {}}\"\n    and \"Ts \\<equiv> concat (map transaction_strand P)\"\n  assumes P_pc: \"comp_par_comp\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t public arity Ana \\<Gamma> Pair Ts M S\"\n    and A: \"A \\<in> reachable_constraints P\"\n  shows \"par_comp\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A ((f S) - {m. intruder_synth {} m})\"\nusing par_comp\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_if_comp_par_comp\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t'[OF P_pc, of \"dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t A\", THEN par_comp\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t]\n      reachable_constraints_par_comp\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_aux[OF A, unfolded Ts_def[symmetric]]\nunfolding f_def dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_self_inverse by fast\nend\n\nlemma reachable_constraints_par_comp_constr:\n  fixes P f S\n  defines \"f \\<equiv> \\<lambda>M. {t \\<cdot> \\<delta> | t \\<delta>. t \\<in> M \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> fv (t \\<cdot> \\<delta>) = {}}\"\n    and \"Ts \\<equiv> concat (map transaction_strand P)\"\n    and \"Sec \\<equiv> f S - {m. intruder_synth {} m}\"\n    and \"M \\<equiv> \\<Union>T \\<in> set P. trms_transaction T \\<union> pair' Pair ` setops_transaction T\"\n  assumes M:\n      \"has_all_wt_instances_of \\<Gamma> M N\"\n      \"finite N\"\n      \"tfr\\<^sub>s\\<^sub>e\\<^sub>t N\"\n      \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s N\"\n    and P:\n      \"\\<forall>T \\<in> set P. wellformed_transaction T\"\n      \"\\<forall>T \\<in> set P. wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s' arity (trms_transaction T)\"\n      \"\\<forall>T \\<in> set P. list_all tfr\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (unlabel (transaction_strand T))\"\n      \"comp_par_comp\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t public arity Ana \\<Gamma> Pair Ts M_fun S\"   \n    and \\<A>: \"\\<A> \\<in> reachable_constraints P\"\n    and \\<I>: \"constraint_model \\<I> \\<A>\"\n  shows \"\\<exists>\\<I>\\<^sub>\\<tau>. welltyped_constraint_model \\<I>\\<^sub>\\<tau> \\<A> \\<and>\n              ((\\<forall>n. welltyped_constraint_model \\<I>\\<^sub>\\<tau> (proj n \\<A>)) \\<or>\n               (\\<exists>\\<A>' l t. prefix \\<A>' \\<A> \\<and> suffix [(l, receive\\<langle>t\\<rangle>)] \\<A>' \\<and> strand_leaks\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>' Sec \\<I>\\<^sub>\\<tau>))\"\nproof -\n  have \\<I>': \"constr_sem_stateful \\<I> (unlabel \\<A>)\" \"interpretation\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\"\n    using \\<I> unfolding constraint_model_def by blast+\n\n  show ?thesis\n    using reachable_constraints_par_comp\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t[OF P(4)[unfolded Ts_def] \\<A>]\n          reachable_constraints_typing_cond\\<^sub>s\\<^sub>s\\<^sub>t[OF M_def M P(1-3) \\<A>]\n          par_comp_constr_stateful[OF _ _ \\<I>', of Sec]\n    unfolding f_def Sec_def welltyped_constraint_model_def constraint_model_def by blast\nqed\n\nlemma reachable_constraints_component_leaks_if_composed_leaks:\n  fixes Sec Q\n  defines \"leaks \\<equiv> \\<lambda>\\<A>. \\<exists>\\<I>\\<^sub>\\<tau> \\<A>'.\n    Q \\<I>\\<^sub>\\<tau> \\<and> prefix \\<A>' \\<A> \\<and> (\\<exists>l' t. suffix [(l', receive\\<langle>t\\<rangle>)] \\<A>') \\<and> strand_leaks\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>' Sec \\<I>\\<^sub>\\<tau>\"\n  assumes Sec: \"\\<forall>s \\<in> Sec. \\<not>{} \\<turnstile>\\<^sub>c s\" \"ground Sec\"\n    and composed_leaks: \"\\<exists>\\<A> \\<in> reachable_constraints Ps. leaks \\<A>\"\n  shows \"\\<exists>l. \\<exists>\\<A> \\<in> reachable_constraints (map (transaction_proj l) Ps). leaks \\<A>\"\nproof -\n  from composed_leaks obtain \\<A> \\<I>\\<^sub>\\<tau> \\<A>' s n where\n      \\<A>: \"\\<A> \\<in> reachable_constraints Ps\" and\n      \\<A>': \"prefix \\<A>' \\<A>\" \"constr_sem_stateful \\<I>\\<^sub>\\<tau> (proj_unl n \\<A>'@[send\\<langle>[s]\\<rangle>])\" and\n      \\<I>\\<^sub>\\<tau>: \"Q \\<I>\\<^sub>\\<tau>\" and\n      s: \"s \\<in> Sec - declassified\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<A>' \\<I>\\<^sub>\\<tau>\"\n    unfolding leaks_def strand_leaks\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_def by fast\n\n  have \"\\<not>{} \\<turnstile>\\<^sub>c s\" \"s \\<cdot> \\<I>\\<^sub>\\<tau> = s\" using s Sec by auto\n  then obtain B k' u where\n      \"constr_sem_stateful \\<I>\\<^sub>\\<tau> (proj_unl n B@[send\\<langle>[s]\\<rangle>])\"\n      \"prefix (proj n B) (proj n \\<A>)\" \"suffix [(k', receive\\<langle>u\\<rangle>)] (proj n B)\"\n      \"s \\<in> Sec - declassified\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (proj n B) \\<I>\\<^sub>\\<tau>\"\n    using constr_sem_stateful_proj_priv_term_prefix_obtain[OF \\<A>' s]\n    unfolding welltyped_constraint_model_def constraint_model_def by metis\n  thus ?thesis\n    using \\<I>\\<^sub>\\<tau> reachable_constraints_transaction_proj[OF \\<A>, of n] proj_idem[of n B]\n    unfolding leaks_def strand_leaks\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_def\n    by metis\nqed\n\nlemma reachable_constraints_preserves_labels:\n  assumes \\<A>: \"\\<A> \\<in> reachable_constraints P\"\n  shows \"\\<forall>a \\<in> set \\<A>. \\<exists>T \\<in> set P. \\<exists>b \\<in> set (transaction_strand T). fst b = fst a\"\n    (is \"\\<forall>a \\<in> set \\<A>. \\<exists>T \\<in> set P. ?P T a\")\nusing \\<A>\nproof (induction \\<A> rule: reachable_constraints.induct)\n  case (step \\<A> T \\<xi> \\<sigma> \\<alpha>)\n  have \"\\<forall>a \\<in> set (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)). ?P T a\"\n  proof\n    fix a assume a: \"a \\<in> set (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>))\"\n    then obtain b where b: \"b \\<in> set (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\" \"a = dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p b\"\n      unfolding dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_def by auto\n    then obtain c where c: \"c \\<in> set (transaction_strand T)\" \"b = c \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n      unfolding subst_apply_labeled_stateful_strand_def by auto\n\n    have \"?P T c\" using c(1) by blast\n    hence \"?P T b\" using c(2) by (simp add: subst_lsstp_fst_eq)\n    thus \"?P T a\" using b(2) dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_fst_eq[of b] by presburger\n  qed\n  thus ?case using step.IH step.hyps(2) by (metis Un_iff set_append)\nqed simp\n\nlemma reachable_constraints_preserves_labels':\n  assumes P: \"\\<forall>T \\<in> set P. \\<forall>a \\<in> set (transaction_strand T). has_LabelN l a \\<or> has_LabelS a\"\n    and \\<A>: \"\\<A> \\<in> reachable_constraints P\"\n  shows \"\\<forall>a \\<in> set \\<A>. has_LabelN l a \\<or> has_LabelS a\"\nusing reachable_constraints_preserves_labels[OF \\<A>] P by fastforce\n\nlemma reachable_constraints_transaction_proj_proj_eq:\n  assumes \\<A>: \"\\<A> \\<in> reachable_constraints (map (transaction_proj l) P)\"\n  shows \"proj l \\<A> = \\<A>\"\n    and \"prefix \\<A>' \\<A> \\<Longrightarrow> proj l \\<A>' = \\<A>'\"\nusing \\<A>\nproof (induction \\<A> rule: reachable_constraints.induct)\n  case (step \\<A> T \\<xi> \\<sigma> \\<alpha>)\n  let ?T = \"dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n  note A = reachable_constraints.step[OF step.hyps]\n\n  have P: \"\\<forall>T \\<in> set (map (transaction_proj l) P).\n            \\<forall>a \\<in> set (transaction_strand T). has_LabelN l a \\<or> has_LabelS a\"\n    using transaction_proj_labels[of l] unfolding list_all_iff by auto\n\n  note * = reachable_constraints_preserves_labels'[OF P A]\n\n  have **: \"\\<forall>a \\<in> set \\<A>'. has_LabelN l a \\<or> has_LabelS a\"\n    when \"\\<forall>a \\<in> set B. has_LabelN l a \\<or> has_LabelS a\" \"prefix \\<A>' B\" for B\n    using that assms unfolding prefix_def by auto\n\n  note *** = proj_ident[unfolded list_all_iff]\n\n  { case 1 thus ?case using *[THEN ***] by blast }\n  { case 2 thus ?case using *[THEN **, THEN ***] by blast }\nqed (simp_all add: reachable_constraints.init)\n\nlemma reachable_constraints_transaction_proj_star_proj:\n  assumes \\<A>: \"\\<A> \\<in> reachable_constraints (map (transaction_proj l) P)\"\n    and k_neq_l: \"k \\<noteq> l\"\n  shows \"proj k \\<A> \\<in> reachable_constraints (map transaction_star_proj P)\"\nusing \\<A>\nproof (induction \\<A> rule: reachable_constraints.induct)\n  case (step \\<A> T \\<xi> \\<sigma> \\<alpha>)\n  have \"map (transaction_proj k) (map (transaction_proj l) P) = map transaction_star_proj P\"\n    using transaction_star_proj_negates_transaction_proj(2)[OF k_neq_l]\n    by fastforce\n  thus ?case\n    using reachable_constraints_transaction_proj[OF reachable_constraints.step[OF step.hyps], of k]\n    by argo\nqed (simp add: reachable_constraints.init)\n\nlemma reachable_constraints_aligned_prefix_ex:\n  fixes P\n  defines \"f \\<equiv> \\<lambda>T.\n    list_all is_Receive (unlabel (transaction_receive T)) \\<and>\n    list_all is_Check_or_Assignment (unlabel (transaction_checks T)) \\<and>\n    list_all is_Update (unlabel (transaction_updates T)) \\<and>\n    list_all is_Send (unlabel (transaction_send T))\"\n  assumes P: \"list_all f P\" \"list_all ((list_all (Not \\<circ> has_LabelS)) \\<circ> tl \\<circ> transaction_send) P\"\n    and s: \"\\<not>{} \\<turnstile>\\<^sub>c s\" \"fv s = {}\"\n    and A: \"A \\<in> reachable_constraints P\" \"prefix B A\"\n    and B: \"\\<exists>l ts. suffix [(l, receive\\<langle>ts\\<rangle>)] B\"\n           \"constr_sem_stateful \\<I> (unlabel B@[send\\<langle>[s]\\<rangle>])\"\n  shows \"\\<exists>C \\<in> reachable_constraints P.\n          prefix C A \\<and> (\\<exists>l ts. suffix [(l, receive\\<langle>ts\\<rangle>)] C) \\<and>\n          declassified\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t B \\<I> = declassified\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t C \\<I> \\<and>\n          constr_sem_stateful \\<I> (unlabel C@[send\\<langle>[s]\\<rangle>])\"\nusing A\nproof (induction A rule: reachable_constraints.induct)\n  case (step A T \\<xi> \\<sigma> \\<alpha>)\n  define \\<theta> where \"\\<theta> \\<equiv> \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>\"\n\n  let ?T = \"dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_strand T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<xi> \\<circ>\\<^sub>s \\<sigma> \\<circ>\\<^sub>s \\<alpha>)\"\n\n  note AT_reach = reachable_constraints.step[OF step.hyps]\n\n  obtain lb tsb B' where B': \"B = B'@[(lb, receive\\<langle>tsb\\<rangle>)]\" using B(1) unfolding suffix_def by blast\n\n  define decl_ik where \"decl_ik \\<equiv> \\<lambda>S::('fun,'atom,'sets,'lbl) prot_strand.\n    \\<Union>{set ts |ts. \\<langle>\\<star>, receive\\<langle>ts\\<rangle>\\<rangle> \\<in> set S} \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\n\n  have decl_ik_append: \"decl_ik (M@N) = decl_ik M \\<union> decl_ik N\" for M N\n    unfolding decl_ik_def by fastforce\n\n  have decl_ik_star: \"decl_ik M = decl_ik (M@N)\" when \"\\<star> \\<notin> fst ` set N\" for M N\n    using that unfolding decl_ik_def\n    by (smt Collect_cong Setcompr_eq_image UnCI UnE fst_conv mem_Collect_eq set_append) \n\n  have decl_decl_ik: \"declassified\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t S \\<I> = {t. decl_ik S \\<turnstile> t}\" for S\n    unfolding declassified\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_alt_def decl_ik_def by blast\n\n  have \"f T\" using P(1) step.hyps(2) by (simp add: list_all_iff)\n  hence \"list_all is_Send (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)))\"\n        \"list_all is_Check_or_Assignment (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)))\"\n        \"list_all is_Update (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_updates T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)))\"\n        \"list_all is_Receive (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)))\"\n    using subst_sst_list_all(2)[of \"unlabel (transaction_receive T)\" \\<theta>]\n          subst_sst_list_all(11)[of \"unlabel (transaction_checks T)\" \\<theta>]\n          subst_sst_list_all(10)[of \"unlabel (transaction_updates T)\" \\<theta>]\n          subst_sst_list_all(1)[of \"unlabel (transaction_send T)\" \\<theta>]\n          dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_list_all(1)[of \"transaction_receive T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>\"]\n          dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_list_all(11)[of \"transaction_checks T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>\"]\n          dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_list_all(10)[of \"transaction_updates T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>\"]\n          dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_list_all(2)[of \"transaction_send T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>\"]\n    unfolding f_def by (metis unlabel_subst[of _ \\<theta>])+\n  hence \"\\<not>list_ex is_Receive (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_receive T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)))\"\n        \"\\<not>list_ex is_Receive (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_checks T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)))\"\n        \"\\<not>list_ex is_Receive (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_updates T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)))\"\n        \"list_all is_Receive (unlabel (dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)))\"\n    unfolding list_ex_iff list_all_iff by blast+\n  then obtain TA TB where T:\n      \"?T = TA@TB\" \"\\<not>list_ex is_Receive (unlabel TA)\" \"list_all is_Receive (unlabel TB)\"\n      \"TB = dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (transaction_send T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n    using transaction_dual_subst_unfold[of T \\<theta>] unfolding \\<theta>_def by fastforce\n\n  have 0: \"prefix B (A@TA@TB)\" using step.prems B' T by argo\n\n  have 1: \"prefix B A\" when \"prefix B (A@TA)\"\n    using that T(2) B' prefix_prefix_inv\n    unfolding list_ex_iff unlabel_def by fastforce\n  \n  have 2: \"\\<star> \\<notin> fst ` set TB2\" when \"TB = TB1@(l,x)#TB2\" for TB1 l x TB2\n  proof -\n    have \"k \\<noteq> \\<star>\" when \"k \\<in> set (map fst (tl (transaction_send T)))\" for k\n      using that P(2) step.hyps(2) unfolding list_all_iff by auto\n    hence \"k \\<noteq> \\<star>\" when \"k \\<in> set (map fst (tl TB))\" for k\n      using that subst_lsst_map_fst_eq[of \"tl (transaction_send T)\" \\<theta>]\n            dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_map_fst_eq[of \"tl (transaction_send T \\<cdot>\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"]\n      unfolding T(4) dual\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t_tl subst_lsst_tl by simp\n    moreover have \"set TB2 \\<subseteq> set (tl TB)\"\n      using that\n      by (metis (no_types, lifting) append_eq_append_conv2 order.eq_iff list.sel(3) self_append_conv\n                set_mono_suffix suffix_appendI suffix_tl tl_append2)\n    ultimately show ?thesis by auto\n  qed\n\n  have 3: \"declassified\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t TB \\<I> = declassified\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (TB1@[(l,x)]) \\<I>\"\n    when \"TB = TB1@(l,x)#TB2\" for TB1 l x TB2\n    using decl_ik_star[OF 2[OF that], of \"TB1@[(l,x)]\"] unfolding that decl_decl_ik by simp\n\n  show ?case\n  proof (cases \"prefix B A\")\n    case False\n    hence 4: \"\\<not>prefix B (A@TA)\" using 1 by blast\n\n    have 5: \"\\<exists>l ts. suffix [(l, receive\\<langle>ts\\<rangle>)] (A@?T)\"\n    proof -\n      have \"(lb, receive\\<langle>tsb\\<rangle>) \\<in> set TB\"\n        using 0 4 prefix_prefix_inv[OF _ suffixI[OF B'], of \"A@TA\" TB] by (metis append_assoc)\n      hence \"receive\\<langle>tsb\\<rangle> \\<in> set (unlabel TB)\"\n        unfolding unlabel_def by force\n      hence \"\\<exists>ts. suffix [receive\\<langle>ts\\<rangle>] (unlabel TB)\"\n        using T(3) unfolding list_all_iff is_Receive_def suffix_def\n        by (metis in_set_conv_decomp list.distinct(1) list.set_cases rev_exhaust)\n      then obtain TB' ts where \"unlabel TB = TB'@[receive\\<langle>ts\\<rangle>]\" unfolding suffix_def by blast\n      then obtain TB'' x where \"TB = TB''@[x]\" \"snd x = receive\\<langle>ts\\<rangle>\"\n        by (smt unlabel_def Nil_is_map_conv map_eq_Cons_D map_eq_append_conv)\n      then obtain l where \"suffix [(l, receive\\<langle>ts\\<rangle>)] TB\"\n        by (metis surj_pair prod.sel(2) suffix_def)\n      thus ?thesis\n        using T(4) transaction_dual_subst_unfold[of T \\<theta>]\n              suffix_append[of \"[(l, receive\\<langle>ts\\<rangle>)]\"]\n        unfolding \\<theta>_def by metis\n    qed\n\n    obtain TB1 where TB:\n        \"B = A@TA@TB1@[(lb, receive\\<langle>tsb\\<rangle>)]\" \"prefix (TB1@[(lb, receive\\<langle>tsb\\<rangle>)]) TB\"\n      using 0 4 B' prefix_snoc_obtain[of B' \"(lb, receive\\<langle>tsb\\<rangle>)\" \"A@TA\" TB thesis]\n      by (metis append_assoc)\n    then obtain TB2 where TB2: \"TB = TB1@(lb, receive\\<langle>tsb\\<rangle>)#TB2\"\n      unfolding prefix_def by fastforce\n    hence TB2': \"list_all is_Receive (unlabel TB2)\"\n      using T(3) unfolding list_all_iff is_Receive_def proj_def unlabel_def by auto\n\n    have 6: \"constr_sem_stateful \\<I> (unlabel B)\" \"ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t B \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> s \\<cdot> \\<I>\"\n      using B(2) strand_sem_append_stateful[of \"{}\" \"{}\" \"unlabel B\" \"[send\\<langle>[s]\\<rangle>]\" \\<I>]\n      by auto\n\n    have \"constr_sem_stateful \\<I> (unlabel (A@TA@TB1@[(lb, receive\\<langle>tsb\\<rangle>)]))\"\n      using 6(1) TB(1) by blast\n    hence \"constr_sem_stateful \\<I> (unlabel (A@?T))\"\n      using T(1) TB2 strand_sem_receive_prepend_stateful[\n              of \"{}\" \"{}\" \"unlabel (A@TA@TB1@[(lb, receive\\<langle>tsb\\<rangle>)])\" \\<I>,\n              OF _ TB2']\n      by auto\n    moreover have \"set (unlabel B) \\<subseteq> set (unlabel (A@?T))\"\n      using step.prems(1) unfolding prefix_def by force\n    hence \"ik\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A@?T) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<turnstile> s \\<cdot> \\<I>\"\n      using ideduct_mono[OF 6(2)] subst_all_mono[of _ _ \\<I>]\n            ik\\<^sub>s\\<^sub>s\\<^sub>t_set_subset[of \"unlabel B\" \"unlabel (A@?T)\"]\n      by meson\n    ultimately have 7: \"constr_sem_stateful \\<I> (unlabel (A@?T)@[send\\<langle>[s]\\<rangle>])\"\n      using strand_sem_append_stateful[of \"{}\" \"{}\" \"unlabel (A@?T)\" \"[send\\<langle>[s]\\<rangle>]\" \\<I>]\n      by auto\n\n    have \"declassified\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t B \\<I> = declassified\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (A@?T) \\<I>\"\n    proof -\n      have \"declassified\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t TB \\<I> = declassified\\<^sub>l\\<^sub>s\\<^sub>s\\<^sub>t (TB1@[(lb, receive\\<langle>tsb\\<rangle>)]) \\<I>\"\n        using 3[of _ lb \"receive\\<langle>tsb\\<rangle>\"] TB(2) unfolding prefix_def by auto\n      hence \"(decl_ik TB \\<turnstile> t) \\<longleftrightarrow> decl_ik (TB1@[(lb,receive\\<langle>tsb\\<rangle>)]) \\<turnstile> t\" for t\n        unfolding TB(1) T(1) decl_decl_ik by blast\n      hence \"(decl_ik (A@TA@TB) \\<turnstile> t) \\<longleftrightarrow> decl_ik (A@TA@TB1@[(lb,receive\\<langle>tsb\\<rangle>)]) \\<turnstile> t\" for t\n        using ideduct_mono_eq[of \"decl_ik TB\" \"decl_ik (TB1@[(lb,receive\\<langle>tsb\\<rangle>)])\" \"decl_ik (A@TA)\"]\n        by (metis decl_ik_append[of \"A@TA\"] Un_commute[of _ \"decl_ik (A@TA)\"] append_assoc)\n      thus ?thesis unfolding TB(1) T(1) decl_decl_ik by blast\n    qed\n    thus ?thesis using step.prems AT_reach B(1) 5 7 by force\n  qed (use step.IH prefix_append in blast)\nqed (use B(1) suffix_def in simp)\n\nend\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Automated_Stateful_Protocol_Verification/Stateful_Protocol_Model.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5312093733737563, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.26352969228783424}}
{"text": "theory RB_Relaxed_mike_v2 imports RCU_Lems \nbegin\n\ndatatype F = B | W | Q | R \ndatatype Pointer = Head | Tail\n\nconsts n :: nat   (*size of buffer, input*)\nconsts N :: nat   (*number of Arr\\<^sub>W entries*)\n\n(*(Wr T u t b \\<sigma>)*)\n(*\nlemma pval_val:\n  assumes \"wfs \\<sigma>\"\n  and \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  and \"u \\<noteq> v\"\n  and \"var w = x\"\n  and \"ts = getTS \\<sigma> w\"\nshows \"\\<not> [x \\<approx>\\<^sub>t u] (write_trans t b w v \\<sigma> ts) \"\n  sorry\n*)\n\n\nlemma pval_val_same:\n  assumes \"wfs \\<sigma>\"\n  and \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  and \"u \\<noteq> v\"\n  and \"var w = x\"\nshows \"\\<not> [x \\<approx>\\<^sub>t u] (Wr x v t b \\<sigma>)\"\n  using assms\n  apply (simp add: p_obs_def visible_writes_def value_def write_trans_def)\n  apply(simp add: rev_app_def update_modView_def update_mods_def update_thrView_def update_wa_def)\n  apply safe  \n  using w_in_writes_on_var apply blast\n  defer  \n  apply (simp add: getVWNC_var)\n   apply (simp add: getVWNC_var)\n  apply(case_tac \"(a, ba)\n       \\<in> writes_on \\<sigma> x\")\n  apply (smt dual_order.strict_trans getTS_w_greater_tst_w getVWNC_in_visible_writes le_neq_trans less_le_not_le mem_Collect_eq visible_writes_def)\nproof -\nfix a :: nat and ba :: rat\n  assume a1: \"(a, ba) \\<in> writes_on (\\<sigma> \\<lparr>thrView := (thrView \\<sigma>) (t := (thrView \\<sigma> t) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))))), modView := (modView \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))) := (thrView \\<sigma> t) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))))), mods := (mods \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))) := \\<lparr>val = v, is_releasing = b\\<rparr>), writes := insert (var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))) (surrey_state.writes \\<sigma>), write_available := (write_available \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> t (var w))) := True)\\<rparr>) (var w)\"\n  assume a2: \"x = var w\"\n  assume a3: \"(a, ba) \\<notin> writes_on \\<sigma> x\"\n  assume a4: \"ba \\<noteq> getTS \\<sigma> (getVWNC \\<sigma> t (var w))\"\n  have f5: \"\\<forall>s n p. var p = n \\<and> p \\<in> surrey_state.writes (s::surrey_state) \\<or> p \\<notin> writes_on s n\"\n    using writes_on_def by force\n  have \"\\<forall>s n p. writes_on (write_available_update p (s::surrey_state)) n = writes_on s n\"\n    by (metis (no_types) surrey_state.select_convs(1) surrey_state.surjective surrey_state.update_convs(5) writes_on_def)\n  then have f6: \"(a, ba) \\<in> writes_on (\\<sigma> \\<lparr>thrView := (thrView \\<sigma>) (t := (thrView \\<sigma> t) (x := (x, getTS \\<sigma> (getVWNC \\<sigma> t x)))), modView := (modView \\<sigma>) ((x, getTS \\<sigma> (getVWNC \\<sigma> t x)) := (thrView \\<sigma> t) (x := (x, getTS \\<sigma> (getVWNC \\<sigma> t x)))), mods := (mods \\<sigma>) ((x, getTS \\<sigma> (getVWNC \\<sigma> t x)) := \\<lparr>val = v, is_releasing = b\\<rparr>), writes := insert (x, getTS \\<sigma> (getVWNC \\<sigma> t x)) (surrey_state.writes \\<sigma>)\\<rparr>) x\"\n    using a2 a1 by blast\n  have f7: \"\\<forall>s f. surrey_state.writes (writes_update f (s::surrey_state)) = f (surrey_state.writes s)\"\n    by auto\n  have f8: \"var (a, ba) = x\"\n    using f6 f5 by meson\n  have \"(a, ba) \\<in> surrey_state.writes \\<sigma>\"\n    using f7 f6 f5 a4 a2 by (metis insert_iff snd_conv)\n  then show False\n    using f8 a3 writes_on_def by force\nqed\n\n\n\nlemma pval_val_other:\n  assumes \"wfs \\<sigma>\"\n  and \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  and \"u \\<noteq> v\"\n  and \"var w = x\"\n  and \"t\\<noteq>s\"\nshows \"\\<not> [x \\<approx>\\<^sub>t u] (Wr x v s b \\<sigma>)\"\n  using assms apply simp\n  apply (simp add: p_obs_def visible_writes_def value_def write_trans_def)\n    apply(simp add: rev_app_def update_modView_def update_mods_def update_thrView_def update_wa_def)\n  apply safe  \n  using w_in_writes_on_var\n  apply (simp add: w_in_writes_on_var getVWNC_var) \n  apply (simp add: getVWNC_var)\n\n  apply(case_tac \"(a, ba)\n       \\<in> writes_on \\<sigma> x\")\n  apply (smt dual_order.strict_trans getTS_w_greater_tst_w getVWNC_in_visible_writes le_neq_trans less_le_not_le mem_Collect_eq visible_writes_def)\nproof -\n  fix a :: nat and ba :: rat\n  assume a1: \"ba \\<noteq> getTS \\<sigma> (getVWNC \\<sigma> s (var w))\"\n  assume a2: \"(a, ba) \\<in> writes_on (\\<sigma> \\<lparr>thrView := (thrView \\<sigma>) (s := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), modView := (modView \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), mods := (mods \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := \\<lparr>val = v, is_releasing = b\\<rparr>), writes := insert (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) (surrey_state.writes \\<sigma>), write_available := (write_available \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := True)\\<rparr>) (var w)\"\n  assume a3: \"(a, ba) \\<notin> writes_on \\<sigma> x\"\n  assume a4: \"x = var w\"\n  have \"(a, ba) \\<in> \\<lbrace>\\<acute>var = var w \\<and> \\<acute>(\\<in>) (surrey_state.writes (\\<sigma> \\<lparr>thrView := (thrView \\<sigma>) (s := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), modView := (modView \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), mods := (mods \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := \\<lparr>val = v, is_releasing = b\\<rparr>), writes := insert (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) (surrey_state.writes \\<sigma>), write_available := (write_available \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := True)\\<rparr>))\\<rbrace>\"\n    using a2 writes_on_def by blast\n  then have f5: \"var (a, ba) = var w \\<and> (a, ba) \\<in> surrey_state.writes (\\<sigma> \\<lparr>thrView := (thrView \\<sigma>) (s := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), modView := (modView \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := (thrView \\<sigma> s) (var w := (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))))), mods := (mods \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := \\<lparr>val = v, is_releasing = b\\<rparr>), writes := insert (var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) (surrey_state.writes \\<sigma>), write_available := (write_available \\<sigma>) ((var w, getTS \\<sigma> (getVWNC \\<sigma> s (var w))) := True)\\<rparr>)\"\n    by blast\n  then have \"(a, ba) \\<notin> surrey_state.writes \\<sigma>\"\n    using a4 a3 writes_on_def by fastforce\n  then show False\n    using f5 a1 by simp\nqed\n\n\n\nlemma pval_val:\n  assumes \"wfs \\<sigma>\"\n  and \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  and \"u \\<noteq> v\"\n  and \"var w = x\"\nshows \"\\<not> [x \\<approx>\\<^sub>t u] (Wr x v t' b \\<sigma>)\"\n  using assms apply (cases \"t=t'\")\n  using pval_val_same apply blast\n  using pval_val_other by blast\n\n\n\n\nlemma pval_val_outside:\n  assumes \"wfs \\<sigma>\"\n  and \"N\\<in> \\<nat>\"\n  and \"\\<forall>j.[x \\<approx>\\<^sub>t j] \\<sigma> \\<longrightarrow> j<N\"\n  and \"\\<forall>k. k<N \\<longrightarrow> [x \\<approx>\\<^sub>t k] \\<sigma>\"\n  and \"u\\<in>\\<nat> \\<and> u<N\"\nshows \"\\<forall>z.(z>N\\<longrightarrow>\\<not>[x \\<approx>\\<^sub>t z] (Wr x u t' b \\<sigma>))\"\n  using assms apply (cases \"t=t'\")\n  apply (metis fst_conv not_less_iff_gr_or_eq pval_val)\n  by (metis fst_conv not_less_iff_gr_or_eq pval_val)\n\n\nlemma pval_val_outside_2:\n  assumes \"wfs \\<sigma>\"\n  and \"N \\<in> \\<nat>\"\n  and \"[x =\\<^sub>t 0] \\<sigma>\"\n  and \"u \\<noteq> 0\"\nshows \"\\<exists>i.(([x =\\<^sub>t i] (Wr x u t b \\<sigma>))\\<or>([x =\\<^sub>t i] (Wr x 0 t' b \\<sigma>)))\" \n  using assms apply (cases \"t=t'\")\n  using OpSem_ProofRules.ext_d_obs_d_obs apply blast\n  using OpSem_ProofRules.ext_d_obs_d_obs by blast\n\n\nlemma pval_val_outside_3:\n  assumes \"wfs \\<sigma>\"\n  and \"N \\<in> \\<nat>\"\n  and \"[x =\\<^sub>t 0] \\<sigma>\"\n  and \"u \\<noteq> 0\"\n shows  \"\\<exists>i.(([x =\\<^sub>t i] (Wr x u t b \\<sigma>)\\<and> i\\<noteq>0)\\<or>(([x =\\<^sub>t i] (Wr x 0 t b \\<sigma>))))\" \n  using OpSem_ProofRules.ext_d_obs_d_obs assms(1) assms(3) by blast\n\nlemma pval_val_outside_4:\n  assumes \"wfs \\<sigma>\"\n  and \"N \\<in> \\<nat>\"\n  and \"[x =\\<^sub>t 0] \\<sigma>\"\n shows  \"\\<exists>i.(([x =\\<^sub>t i] (Wr x 3 t b \\<sigma>)\\<and> i\\<noteq>0)\\<or>(([x =\\<^sub>t i] (Wr x 0 t b \\<sigma>))))\\<longrightarrow>(i+1=1 \\<or> i+1=4)\" \n  using add_cancel_left_left by blast\n\n\n(*\n  assumes \"wfs \\<sigma>\"\n  and \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  and \"u \\<noteq> v\"\n  and \"var w = x\"\nshows \"\\<not> [x \\<approx>\\<^sub>t u] (Wr x v t b \\<sigma>)\"\n\n\nlemma pval_val_all: \n  assumes \"wfs \\<sigma>\"\n  and \"\\<forall>i. i > k \\<longrightarrow> \\<not> [x \\<approx>\\<^sub>t i] \\<sigma>\"\n  and \"k < j\" \n  and \"u \\<le> k\"\n  and \"var w = x\"\nshows \"\\<not> [x \\<approx>\\<^sub>t j] (Wr x v t b \\<sigma>) \"\n  using assms\n  \n  using pval_val sledgehammer\n*)\n\nconsts   \n  H :: L\n  T :: L\n\n\nrecord LB =\n  hW ::  V               (*local copy of W*)\n  tW ::  V               (*local copy of W*)\n  q :: \"(nat \\<times> nat) list\" (*for now assume well synchronised, need to think about weak memory *)\n  tempR :: \"(nat \\<times> nat)\"          (*local copy of word by R*)\n\n  tloc :: V\n  Data:: \"nat  \\<Rightarrow> nat\"     (*returns a word Data_i*)\n  countW :: nat  (* the index of the next element of Data to be written  *)\n  countR :: nat  (* how many words from Data the read has read or reading (i.e., retrieved)  *)\n\n  ownD :: \"nat \\<Rightarrow> F\" (* ownership of data indices *)\n  ownB :: \"nat \\<Rightarrow> F\" (* ownership of bytes in buffer *)\n  (* tries :: nat *)\n  oom :: bool       (*signals W that it was OOM*)\n  \\<sigma> :: surrey_state\n\ndefinition \"global s \\<equiv> wfs s \\<and> H \\<noteq> T\"\n\n\n\n\nlemmas opsemsyntax [simp] =  global_def\nlemmas defs_del [simp del] =  Rd_def Let_def Wr_def Upd_def st_rd_def val_rd_def\n\n(* thread 2 is the writer *)\n(* thread 3 is the reader *)\n\n(* Omit tries *)\n(* Finish queueu + reader *)\n\n(* We need this one to hold at minimum *)\ndefinition \"arrayInv s \\<equiv> \\<forall>i. (i<countR s \\<longrightarrow> ownD s i = R)\\<and> (countR s \\<le> i \\<and> i < countW s \\<longrightarrow> ownD s i = B) \\<and> (countW s \\<le> i \\<and> i < n \\<longrightarrow> ownD s i = W) \"\n\n\ndefinition \"q_entries_bounded s \\<equiv> (\\<forall>i. i < length(q s) \\<longrightarrow> (fst(q s!i)+snd(q s!i)\\<le>N)\\<and>snd(q s!i)>0)\"\ndefinition \"tempR_bounded s \\<equiv> fst (tempR s) + snd (tempR s) \\<le> N\"\ndefinition \"counter_q_rel s \\<equiv> (countW s-countR s=length(q s))\"\ndefinition \"con_assms s  \\<equiv>   0 < N \\<and> 0<n \\<and> (countR s\\<le>countW s) \\<and> (countW s\\<le>n)\n                             \\<and> (\\<forall>i.(i<n)\\<longrightarrow>Data s i\\<le>N \\<and> Data s i>0)\"\n(*new\n(typically)\n\\forall x . P(x) \\<longrightarrow> Q(x)\n\\exists x . P(x) \\<and> Q(x)\n\n[H =\\<^sub>2 i] means thread 2 sees the last write to H and this has value i.\n[H \\<approx>\\<^sub>2 i] means that thread 2 can see the value i.\n*)\ndefinition \"bounded_pointers s \\<equiv> ((\\<forall>i. i > N \\<longrightarrow> \\<not>[H \\<approx>\\<^sub>2 i] (\\<sigma> s)))\\<and>\n                                 ((\\<forall>j. j > N \\<longrightarrow> \\<not>[T \\<approx>\\<^sub>2 j] (\\<sigma> s)))\"\n\ndefinition \"basic_pointer_movement s \\<equiv> 0\\<le>hW s\\<and> hW s\\<le>N \\<and> 0\\<le>tW s\\<and> tW s\\<le>N\"\n\n\n \n\n\ndefinition \"collection s \\<equiv> arrayInv s \\<and> q_entries_bounded s\n                          \\<and>tempR_bounded s \\<and>counter_q_rel s \\<and> con_assms s\n                          \\<and> bounded_pointers s \\<and> basic_pointer_movement s\"\n\n\ndefinition \"init s \\<equiv>\n                     [T =\\<^sub>2 0] (\\<sigma> s) \\<and> [H =\\<^sub>2 0] (\\<sigma> s) \\<and> [T =\\<^sub>3 0] (\\<sigma> s) \\<and> (q s = []) \\<and> (hW s = 0) \\<and> (tW s = 0)\n                        \\<and> (\\<forall>l. (l<n) \\<longrightarrow>  ((Data s l > 0)\\<and>(Data s l \\<le> N)))\n                        \\<and> (\\<forall>i. (i<n) \\<longrightarrow>  ownD s i = W)\n                        \\<and> (\\<forall>i. (i\\<le>N) \\<longrightarrow>  ownB s i = B)\n                        \\<and> (countW s = 0) \\<and> (countR s = 0)\n                        \\<and> (tempR s = (0,0)) \\<and> \\<not> oom s \"\n\ndefinition \"grd1 s \\<equiv> (tW s = hW s) \\<and> (Data s (countW s) \\<le> N) \"\ndefinition \"grd2 s \\<equiv> (tW s > hW s) \\<and> (Data s (countW s) < (tW s - hW s)) \"\ndefinition \"grd3 s \\<equiv> tW s < hW s \"\ndefinition \"grd4 s \\<equiv> Data s (countW s) \\<le> N - hW s \"\ndefinition \"grd5 s \\<equiv> Data s (countW s) < tW s \"\ndefinition \"no_space_for_word s \\<equiv> (grd1 s \\<longrightarrow> \\<not>(Data s (countW s) \\<le> N))\\<and>\n                                  (grd2 s \\<longrightarrow> \\<not>(Data s (countW s) < (tW s - hW s)))\\<and>\n                                  (grd3 s \\<longrightarrow> \\<not>(Data s (countW s) \\<le> N - hW s \\<or> Data s (countW s) < tW s))\"\n\n\n\nlemmas main_invariant_lemmas = collection_def arrayInv_def q_entries_bounded_def \n                                      counter_q_rel_def tempR_bounded_def con_assms_def\n                                      init_def bounded_pointers_def basic_pointer_movement_def\n                                      pval_val_same pval_val_other pval_val\nlemmas guards = grd1_def grd2_def grd3_def grd4_def grd5_def no_space_for_word_def\n\n\nlemma LoadBuffering:\n \"\\<parallel>-   \\<lbrace> global \\<acute>\\<sigma>  \\<and> \\<acute>collection  \\<and> \\<acute>init \\<rbrace>\nCOBEGIN\n\\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection  \\<and> \\<not> \\<acute>oom \\<and> \\<acute>init\\<rbrace>\n  WHILE \\<acute>countW < n \n   INV \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> (\\<exists> i. [H =\\<^sub>2 i]\\<acute>\\<sigma>)\\<rbrace>\n   DO\n    \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> (\\<exists> i. [H =\\<^sub>2 i]\\<acute>\\<sigma>) \\<and> \\<acute>countW < n\\<rbrace> \\<comment> \\<open>A1\\<close>\n      <\\<acute>hW \\<leftarrow>\\<^sub>2 H\\<acute>\\<sigma>> ;;  \n    \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection  \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n\\<rbrace>\n      <\\<acute>tW \\<leftarrow>\\<^sub>2 T\\<acute>\\<sigma>> ;;\n    \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection  \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n\\<rbrace>\n      IF \\<acute>grd1 \\<comment> \\<open>A2\\<close>\n      THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd1 \\<rbrace> \\<comment> \\<open>A3\\<close>\n            \\<langle><T :=\\<^sub>2 0 \\<acute>\\<sigma>>,, <T :=\\<^sub>3 0 \\<acute>\\<sigma>>\\<rangle> ;; \\<comment> \\<open>This might not need to be releasing\\<close>  \n            \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd1 \\<rbrace>\n            \\<langle><H :=\\<^sub>2 (\\<acute>Data \\<acute>countW) \\<acute>\\<sigma>> ,, \\<acute>hW := 0 ,, \\<acute>oom := False ,,\n              (\\<acute>ownB := ( \\<lambda> x. if 0\\<le> x \\<and> x < (\\<acute>Data \\<acute>countW) then W else \\<acute>ownB x ))\\<rangle>\n      ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<not>\\<acute>grd1 \\<rbrace> \n            IF \\<acute>grd2\n            THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd2\\<rbrace> \\<comment> \\<open>A4\\<close>\n                \\<langle><H :=\\<^sub>2 \\<acute>hW + (\\<acute>Data \\<acute>countW) \\<acute>\\<sigma>> ,, \\<acute>oom := False ,,\n                  (\\<acute>ownB := ( \\<lambda> x. if \\<acute>hW \\<le> x \\<and> x < (\\<acute>hW + (\\<acute>Data \\<acute>countW)) then W else \\<acute>ownB x ))\\<rangle>\n            ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<not>\\<acute>grd1 \\<and> \\<not>\\<acute>grd2\\<rbrace>\n                 IF \\<acute>grd3\n                 THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd3 \\<rbrace> \\<comment> \\<open>A5\\<close>\n                      IF \\<acute>grd4\n                      THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd3 \\<and> \\<acute>grd4 \\<rbrace> \\<comment> \\<open>A6\\<close>\n                      \\<langle><H :=\\<^sub>2 \\<acute>hW + (\\<acute>Data \\<acute>countW) \\<acute>\\<sigma>> ,, \\<acute>oom := False ,,\n                         (\\<acute>ownB := ( \\<lambda> x. if \\<acute>hW \\<le> x \\<and> x < (\\<acute>hW + (\\<acute>Data \\<acute>countW)) then W else \\<acute>ownB x ))\\<rangle>\n                      ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd3 \\<and> \\<not>\\<acute>grd4 \\<rbrace>\n                            IF \\<acute>grd5\n                            THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>grd3 \\<and> \\<acute>grd5 \\<rbrace> \\<comment> \\<open>A7\\<close>\n                              \\<langle><H :=\\<^sub>2 (\\<acute>Data \\<acute>countW) \\<acute>\\<sigma>> ,, \\<acute>hW := 0 ,, \\<acute>oom := False ,,\n                                (\\<acute>ownB := ( \\<lambda> x. if ((0 \\<le> x \\<and> x < (\\<acute>Data \\<acute>countW))\\<or> x\\<ge>T)\\<and>x\\<noteq>N then W else \\<acute>ownB x ))\\<rangle>\n                            ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>no_space_for_word\\<rbrace> \\<comment> \\<open>A8\\<close>\n                                \\<langle>\\<acute>oom := True\\<rangle>\n                                  \\<comment> \\<open>OOM\\<close>\n                            FI\n                      FI\n                 ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>countW < n \\<and> \\<acute>no_space_for_word\\<rbrace>\n                      \\<langle>\\<acute>oom := True\\<rangle>\n                      \\<comment> \\<open>OOM\\<close>\n                 FI\n           FI\n     FI;;\n     \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection  \n        \\<and> ((\\<acute>oom=False \\<and> [H =\\<^sub>2 (\\<acute>hW+(\\<acute>Data \\<acute>countW))]\\<acute>\\<sigma> ) \\<comment> \\<open>\\<and> \\<acute>hW  + \\<acute>Data (\\<acute>countW) \\<le> N\\<close> \n             \\<or> (\\<acute>oom=True \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>no_space_for_word)) \\<and> \\<acute>countW < n\\<rbrace>\n     IF \\<acute>oom=True\n     THEN \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> [H =\\<^sub>2 \\<acute>hW]\\<acute>\\<sigma> \\<and> \\<acute>no_space_for_word \\<and> \\<acute>countW < n\\<rbrace> \\<comment> \\<open>OK\\<close>\n          SKIP\n     ELSE \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection  \\<and> \\<acute>countW < n \\<and> [H =\\<^sub>2 (\\<acute>hW+(\\<acute>Data \\<acute>countW))]\\<acute>\\<sigma>\\<rbrace>\n          \\<langle>\\<acute>q := \\<acute>q @ [(\\<acute>hW, (\\<acute>Data \\<acute>countW))],,  \n           \\<acute>ownD := (\\<lambda> x. if x = \\<acute>countW then B else \\<acute>ownD x),, \n           \\<acute>ownB := (\\<lambda> x. if (\\<acute>ownB x = W) then Q else \\<acute>ownB x),,  \n           \\<acute>countW := (\\<acute>countW+1)\\<rangle> \n     FI\n   OD \n    \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>countW = n\\<rbrace>\n\n\\<parallel>\n \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>tempR = (0, 0) \\<rbrace>\n  WHILE \\<acute>countR < n\n  INV \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>tempR=(0,0) \\<rbrace>\n  DO  \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>countR < n \\<and> \\<acute>tempR=(0,0) \\<rbrace>\n      IF \\<acute>countR < \\<acute>countW THEN\n                \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>countR < \\<acute>countW \\<and> \\<acute>tempR=(0,0) \\<rbrace> \\<comment> \\<open>retrieve from Q, dequeue\\<close>\n                \\<langle> \\<acute>tempR  := (fst(hd \\<acute>q),(snd(hd \\<acute>q))) ,,  \n                    \\<acute>ownD := (\\<lambda> x. if x = \\<acute>countR then R else \\<acute>ownD x),, \n                    \\<acute>countR := \\<acute>countR+1,, \n                    ( IF \\<exists>i.(i<(fst(hd \\<acute>q)+snd(hd \\<acute>q)) \\<and> [T =\\<^sub>3 i] \\<acute>\\<sigma>) THEN (\\<acute>ownB := ( \\<lambda> x. if i \\<le> x \\<and> x < (fst(hd \\<acute>q)+(snd(hd \\<acute>q))) then R else \\<acute>ownB x ))\n                      ELSE (\\<acute>ownB := ( \\<lambda> x. if i > x \\<and> x \\<le> (fst(hd \\<acute>q)+(snd(hd \\<acute>q)))\\<or>(x=N) then \\<acute>ownB x else R ))FI),, \n                     \\<acute>q := (tl \\<acute>q) \\<rangle>;;\n                    \\<lbrace> global \\<acute>\\<sigma> \\<and>\\<acute>collection \\<and> \\<acute>countR \\<le> \\<acute>countW  \\<and> \\<acute>tempR\\<noteq>(0,0)\\<rbrace> \\<comment> \\<open>Push T\\<close>\n                    \\<langle><T :=\\<^sub>3 (fst \\<acute>tempR + snd \\<acute>tempR) \\<acute>\\<sigma> > \n                    ,, \\<acute> tempR := (0,0),, \n                   \\<acute>ownB := (\\<lambda> x. if \\<acute>ownB x = R then B else \\<acute>ownD x) \\<rangle>\n      ELSE\n      \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>tempR=(0,0) \\<and> \\<acute>countR < n\\<rbrace>\n      SKIP\n      FI\n  OD\n\\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>countR = n\\<rbrace>\n\n\n\nCOEND\n  \\<lbrace> global \\<acute>\\<sigma> \\<and> \\<acute>collection \\<and> \\<acute>countW = n \\<and> \\<acute>countR = n\\<rbrace>\n  \n\n\"\n  apply (oghoare)\n  apply ((simp add: main_invariant_lemmas Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff; force)+)[4]\n  apply ((simp add: guards main_invariant_lemmas Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)[1]\n  apply (metis OpSem_ProofRules.d_obs_read_value OpSem_ProofRules.ext_d_obs_rd_pres d_obs_implies_p_obs le_less_linear)\n  apply auto[1]\n  apply ((simp add: guards main_invariant_lemmas Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)[1]\n  apply clarsimp\n  apply (meson not_less not_pobs_contradiction)\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  using pval_val apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply auto[3]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply auto[3]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply auto[1]\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis)\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply auto[1]\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply (metis (no_types, lifting) Suc_diff_le d_obs_implies_p_obs fst_eqD le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply auto[1]\n  apply ((simp add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)+)\n  apply clarsimp\n  apply (simp_all add: main_invariant_lemmas guards Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff)\n          (*129*)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred hd_conv_nth length_0_conv length_tl less_numeral_extra(3) nat.inject nth_tl snd_conv zero_less_diff)\n  apply clarify\n  using pval_val apply auto[1]\n  using OpSem_ProofRules.p_obs_contradiction apply blast\n  apply clarify\n  apply linarith\n  apply (metis (no_types, lifting) less_numeral_extra(3) )\n  using pval_val apply auto[1]\n  apply clarify\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply clarify\n  apply (intro conjI impI)\n  apply (metis getVWNC_var leD pval_val)\n  apply (metis OpSem_ProofRules.ext_write_other_pres_d_obs)\n  apply clarify\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply clarify\n  apply (intro conjI impI)\n  apply (metis getVWNC_var leD pval_val)\n  apply (metis OpSem_ProofRules.ext_write_other_pres_d_obs)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply linarith\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply clarify\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply clarify\n  apply blast\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply clarify\n  apply (intro conjI impI)\n  apply (metis getVWNC_var leD pval_val)\n  apply (metis OpSem_ProofRules.ext_write_other_pres_d_obs)\n  apply clarify\n  apply blast\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply (metis getVWNC_var leD pval_val)\n  apply (smt One_nat_def Suc_diff_Suc Suc_mono Suc_pred diff_is_0_eq hd_conv_nth leD length_0_conv length_tl nat_less_le nat.inject nth_tl zero_less_diff)\n  apply clarify\n  apply (meson not_less not_pobs_contradiction)\n  apply (meson not_less not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.write_pres_wfs dual_order.strict_trans fst_eqD leD pval_val_other pval_val_same)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply clarify\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.write_pres_wfs dual_order.strict_trans fst_eqD leD pval_val_other pval_val_same)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply clarify\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.write_pres_wfs dual_order.strict_trans fst_eqD leD pval_val_other pval_val_same)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply clarify\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.write_pres_wfs dual_order.strict_trans fst_eqD leD pval_val_other pval_val_same)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply clarify\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.write_pres_wfs dual_order.strict_trans fst_eqD leD pval_val_other pval_val_same)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply clarify\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (meson le_less_linear not_pobs_contradiction)\n  apply (metis OpSem_ProofRules.write_pres_wfs dual_order.strict_trans fst_eqD leD pval_val_other pval_val_same)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply clarify\n  apply (smt OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD le_less_trans less_diff_conv less_imp_le_nat)\n  apply (metis Nat.le_diff_conv2 OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs add.commute leD)\n  apply (metis OpSem_ProofRules.d_obs_not_p_obs OpSem_ProofRules.ext_d_obs_d_obs OpSem_ProofRules.write_pres_wfs leD)\n  apply (metis Suc_diff_le d_obs_implies_p_obs fst_conv le_less_linear less_antisym nth_append nth_append_length snd_conv)\n  apply (meson le_less_linear not_pobs_contradiction)\n  by simp\n\n\n\n\n\n\n\n\n(*(simp add: Collect_conj_eq[symmetric] Collect_imp_eq[symmetric] Collect_disj_eq[symmetric] Collect_mono_iff )?)*)", "meta": {"author": "MSemenyuk", "repo": "PhD_Isabelle", "sha": "179f5d346a721b15940a271323e3487f4ea51338", "save_path": "github-repos/isabelle/MSemenyuk-PhD_Isabelle", "path": "github-repos/isabelle/MSemenyuk-PhD_Isabelle/PhD_Isabelle-179f5d346a721b15940a271323e3487f4ea51338/Amazon Ring Buffer/RB_Relaxed_mike_v2.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.640635854839898, "lm_q2_score": 0.411110869232168, "lm_q1q2_score": 0.2633723631445235}}
{"text": "theory TTreeImplCardinalitySafe\nimports TTreeImplCardinality TTreeAnalysisSpec CardinalityAnalysisSpec\nbegin\n\nlemma pathsCard_paths_nxt:  \"pathsCard (paths (nxt f x)) \\<sqsubseteq> record_call x\\<cdot>(pathsCard (paths f))\"\n  apply transfer\n  apply (rule pathsCard_below)\n  apply auto\n  apply (erule below_trans[OF _ monofun_cfun_arg[OF paths_Card_above], rotated]) back\n  apply (auto intro: fun_belowI simp add: record_call_simp two_pred_two_add_once)\n  done\n\nlemma pathsCards_none: \"pathsCard (paths t) x = none \\<Longrightarrow> x \\<notin> carrier t\"\n  by transfer (auto dest: pathCards_noneD)\n\nlemma const_on_edom_disj: \"const_on f S empty \\<longleftrightarrow> edom f \\<inter> S = {}\"\n  by (auto simp add: empty_is_bottom edom_def)\n\ncontext TTreeAnalysisCarrier\nbegin\n  lemma carrier_Fstack: \"carrier (Fstack as S) \\<subseteq> fv S\"\n    by (induction S rule: Fstack.induct)\n       (auto simp add: empty_is_bottom[symmetric] carrier_Fexp dest!: subsetD[OF Aexp_edom])\n\n  lemma carrier_FBinds: \"carrier ((FBinds \\<Gamma>\\<cdot>ae) x) \\<subseteq> fv \\<Gamma>\"\n  apply (simp add: Texp.AnalBinds_lookup)\n  apply (auto split: option.split simp add: empty_is_bottom[symmetric] )\n  apply (case_tac \"ae x\")\n  apply (auto simp add: empty_is_bottom[symmetric] carrier_Fexp dest!: subsetD[OF Aexp_edom])\n  by (metis (poly_guards_query) contra_subsetD domA_from_set map_of_fv_subset map_of_SomeD option.sel)\nend\n\ncontext TTreeAnalysisSafe\nbegin\n\n  sublocale CardinalityPrognosisShape prognosis\n  proof\n    fix \\<Gamma> :: heap and ae ae' :: AEnv and u e S as\n    assume \"ae f|` domA \\<Gamma> = ae' f|` domA \\<Gamma>\"\n    from Texp.AnalBinds_cong[OF this]\n    show \"prognosis ae as u (\\<Gamma>, e, S) = prognosis ae' as u (\\<Gamma>, e, S)\" by simp\n  next\n    fix ae as a \\<Gamma> e S\n    show \"const_on (prognosis ae as a (\\<Gamma>, e, S)) (ap S) many\"\n    proof\n      fix x\n      assume \"x \\<in> ap S\"\n      hence \"[x,x] \\<in> paths (Fstack as S)\"\n        by (induction S rule: Fstack.induct)\n           (auto 4 4 intro: subsetD[OF both_contains_arg1] subsetD[OF both_contains_arg2] paths_Cons_nxt)\n      hence \"[x,x] \\<in> paths (Texp e\\<cdot>a \\<otimes>\\<otimes> Fstack as S)\"\n        by (rule subsetD[OF both_contains_arg2])\n      hence \"[x,x] \\<in> paths (substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) (Texp e\\<cdot>a \\<otimes>\\<otimes> Fstack as S))\" \n        by (rule subsetD[OF substitute_contains_arg])\n      hence \"pathCard [x,x] x \\<sqsubseteq> pathsCard (paths (substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) (Texp e\\<cdot>a \\<otimes>\\<otimes> Fstack as S))) x\"\n        by (metis fun_belowD paths_Card_above)\n      also have \"pathCard [x,x] x = many\"  by (auto simp add: pathCard_def)\n      finally\n      show \"prognosis ae as a (\\<Gamma>, e, S) x = many\"\n        by (auto intro: below_antisym)\n    qed\n  next\n    fix \\<Gamma> \\<Delta> :: heap and e :: exp and ae :: AEnv and as u S\n    assume \"map_of \\<Gamma> = map_of \\<Delta>\"\n    hence \"FBinds \\<Gamma> = FBinds \\<Delta>\" and \"thunks \\<Gamma> = thunks \\<Delta>\" by (auto intro!: cfun_eqI  thunks_cong simp add: Texp.AnalBinds_lookup)\n    thus \"prognosis ae as u (\\<Gamma>, e, S) = prognosis ae as u (\\<Delta>, e, S)\"  by simp\n  next\n    fix \\<Gamma> :: heap and e :: exp and ae :: AEnv and as u S x\n    show \"prognosis ae as u (\\<Gamma>, e, S) \\<sqsubseteq> prognosis ae as u (\\<Gamma>, e, Upd x # S)\" by simp\n  next\n  fix \\<Gamma> :: heap and e :: exp and ae :: AEnv and as a S x\n  assume \"ae x = \\<bottom>\"\n\n  hence \"FBinds (delete x \\<Gamma>)\\<cdot>ae = FBinds \\<Gamma>\\<cdot>ae\" by (rule Texp.AnalBinds_delete_bot)\n  moreover\n  hence \"((FBinds \\<Gamma>\\<cdot>ae) x) = \\<bottom>\" by (metis Texp.AnalBinds_delete_lookup)\n  ultimately\n  show \"prognosis ae as a (\\<Gamma>, e, S) \\<sqsubseteq> prognosis ae as a (delete x \\<Gamma>, e, S)\"\n    by (simp add: substitute_T_delete empty_is_bottom)\n  next\n    fix ae as a \\<Gamma> x S\n    have \"once \\<sqsubseteq> (pathCard [x]) x\" by (simp add: two_add_simp)\n    also have \"pathCard [x] \\<sqsubseteq> pathsCard ({[],[x]})\"\n      by (rule paths_Card_above) simp\n    also have \"\\<dots> = pathsCard (paths (single x))\" by simp\n    also have \"single x \\<sqsubseteq> (Texp (Var x)\\<cdot>a)\" by (rule Texp_Var)\n    also have \"\\<dots> \\<sqsubseteq> Texp (Var x)\\<cdot>a \\<otimes>\\<otimes> Fstack as S\" by (rule both_above_arg1)\n    also have \"\\<dots> \\<sqsubseteq> substitute  (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) (Texp (Var x)\\<cdot>a \\<otimes>\\<otimes> Fstack as S)\" by (rule substitute_above_arg)\n    also have \"pathsCard (paths \\<dots>) x = prognosis ae as a (\\<Gamma>, Var x, S) x\" by simp\n    finally\n    show \"once \\<sqsubseteq> prognosis ae as a (\\<Gamma>, Var x, S) x\"\n      by this (rule cont2cont_fun, intro cont2cont)+\n  qed\n\n  sublocale CardinalityPrognosisApp prognosis\n  proof\n    fix ae as a \\<Gamma> e x S\n    have \"Texp e\\<cdot>(inc\\<cdot>a)  \\<otimes>\\<otimes> many_calls x \\<otimes>\\<otimes> Fstack as S = many_calls x  \\<otimes>\\<otimes> (Texp e)\\<cdot>(inc\\<cdot>a) \\<otimes>\\<otimes> Fstack as S\"\n      by (metis both_assoc both_comm)\n    thus \"prognosis ae as (inc\\<cdot>a) (\\<Gamma>, e, Arg x # S) \\<sqsubseteq> prognosis ae as a (\\<Gamma>, App e x, S)\"\n      by simp (intro pathsCard_mono' paths_mono substitute_mono2' both_mono1' Texp_App)\n  qed\n\n  sublocale CardinalityPrognosisLam prognosis\n  proof\n    fix ae as a \\<Gamma> e y x S\n    have \"Texp e[y::=x]\\<cdot>(pred\\<cdot>a) \\<sqsubseteq> many_calls x  \\<otimes>\\<otimes> Texp (Lam [y]. e)\\<cdot>a\"\n      by (rule below_trans[OF Texp_subst both_mono2'[OF Texp_Lam]])\n    moreover have \"Texp (Lam [y]. e)\\<cdot>a \\<otimes>\\<otimes> many_calls x \\<otimes>\\<otimes> Fstack as S = many_calls x  \\<otimes>\\<otimes> Texp (Lam [y]. e)\\<cdot>a \\<otimes>\\<otimes> Fstack as S\"\n      by (metis both_assoc both_comm)\n    ultimately  \n    show \"prognosis ae as (pred\\<cdot>a) (\\<Gamma>, e[y::=x], S) \\<sqsubseteq> prognosis ae as a (\\<Gamma>, Lam [y]. e, Arg x # S)\"\n      by simp (intro pathsCard_mono' paths_mono substitute_mono2' both_mono1')\n  qed\n\n  sublocale CardinalityPrognosisVar prognosis\n  proof\n    fix \\<Gamma> :: heap and e :: exp and x :: var and ae :: AEnv and as u a S\n    assume \"map_of \\<Gamma> x = Some e\"\n    assume \"ae x = up\\<cdot>u\"\n\n    assume \"isVal e\"\n    hence \"x \\<notin> thunks \\<Gamma>\" using \\<open>map_of \\<Gamma> x = Some e\\<close> by (metis thunksE)\n    hence [simp]: \"f_nxt (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) x = FBinds \\<Gamma>\\<cdot>ae\" by (auto simp add: f_nxt_def)\n\n    have \"prognosis ae as u (\\<Gamma>, e, S) = pathsCard (paths (substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) (Texp e\\<cdot>u \\<otimes>\\<otimes> Fstack as S)))\"\n      by simp\n    also have \"\\<dots> = pathsCard (paths (substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) (nxt (single x) x \\<otimes>\\<otimes> Texp e\\<cdot>u  \\<otimes>\\<otimes> Fstack as S)))\"\n      by simp\n    also have \"\\<dots> = pathsCard (paths (substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) ((nxt (single x) x \\<otimes>\\<otimes> Fstack as S) \\<otimes>\\<otimes> Texp e\\<cdot>u )))\"\n      by (metis both_assoc both_comm)\n    also have \"\\<dots> \\<sqsubseteq> pathsCard (paths (substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) (nxt (single x \\<otimes>\\<otimes> Fstack as S) x \\<otimes>\\<otimes> Texp e\\<cdot>u)))\"\n      by (intro pathsCard_mono' paths_mono substitute_mono2' both_mono1'  nxt_both_left) simp\n    also have \"\\<dots> = pathsCard (paths (nxt (substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) (single x \\<otimes>\\<otimes> Fstack as S)) x))\"\n      using \\<open>map_of \\<Gamma> x = Some e\\<close> \\<open>ae x = up\\<cdot>u\\<close> by (simp add: Texp.AnalBinds_lookup)\n    also have \"\\<dots> \\<sqsubseteq> record_call x \\<cdot>(pathsCard (paths (substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) (single x \\<otimes>\\<otimes> Fstack as S))))\"\n      by (rule pathsCard_paths_nxt)\n    also have \"\\<dots> \\<sqsubseteq> record_call x \\<cdot>(pathsCard (paths (substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) ((Texp (Var x)\\<cdot>a) \\<otimes>\\<otimes> Fstack as S))))\"\n      by (intro monofun_cfun_arg pathsCard_mono' paths_mono substitute_mono2' both_mono1' Texp_Var)\n    also have \"\\<dots> = record_call x \\<cdot>(prognosis ae as a (\\<Gamma>, Var x, S))\"\n      by simp\n    finally\n    show \"prognosis ae as u (\\<Gamma>, e, S) \\<sqsubseteq> record_call x\\<cdot>(prognosis ae as a (\\<Gamma>, Var x, S))\" by this simp_all\n  next\n    fix \\<Gamma> :: heap and e :: exp and x :: var and ae :: AEnv and as u a S\n    assume \"map_of \\<Gamma> x = Some e\"\n    assume \"ae x = up\\<cdot>u\"\n    assume \"\\<not> isVal e\"\n    hence \"x \\<in> thunks \\<Gamma>\" using \\<open>map_of \\<Gamma> x = Some e\\<close> by (metis thunksI)\n    hence [simp]: \"f_nxt (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) x = FBinds (delete x \\<Gamma>)\\<cdot>ae\" \n      by (auto simp add: f_nxt_def Texp.AnalBinds_delete_to_fun_upd empty_is_bottom)\n\n    have \"prognosis ae as u (delete x \\<Gamma>, e, Upd x # S) = pathsCard (paths (substitute (FBinds (delete x \\<Gamma>)\\<cdot>ae) (thunks (delete x \\<Gamma>)) (Texp e\\<cdot>u \\<otimes>\\<otimes> Fstack as S)))\"\n      by simp\n    also have \"\\<dots> = pathsCard (paths (substitute (FBinds (delete x \\<Gamma>)\\<cdot>ae) (thunks \\<Gamma>) (Texp e\\<cdot>u \\<otimes>\\<otimes> Fstack as S)))\"\n       by (rule arg_cong[OF substitute_cong_T]) (auto simp add: empty_is_bottom)\n    also have \"\\<dots> = pathsCard (paths (substitute (FBinds (delete x \\<Gamma>)\\<cdot>ae) (thunks \\<Gamma>) (nxt (single x) x \\<otimes>\\<otimes> Texp e\\<cdot>u  \\<otimes>\\<otimes> Fstack as S)))\"\n      by simp\n    also have \"\\<dots> = pathsCard (paths (substitute (FBinds (delete x \\<Gamma>)\\<cdot>ae) (thunks \\<Gamma>) ((nxt (single x) x \\<otimes>\\<otimes> Fstack as S) \\<otimes>\\<otimes> Texp e\\<cdot>u )))\"\n      by (metis both_assoc both_comm)\n    also have \"\\<dots> \\<sqsubseteq> pathsCard (paths (substitute (FBinds (delete x \\<Gamma>)\\<cdot>ae) (thunks \\<Gamma>) (nxt (single x \\<otimes>\\<otimes> Fstack as S) x  \\<otimes>\\<otimes> Texp e\\<cdot>u)))\"\n      by (intro pathsCard_mono' paths_mono substitute_mono2' both_mono1'  nxt_both_left) simp\n    also have \"\\<dots> = pathsCard (paths (nxt (substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) (single x \\<otimes>\\<otimes> Fstack as S)) x))\"\n      using \\<open>map_of \\<Gamma> x = Some e\\<close> \\<open>ae x = up\\<cdot>u\\<close> by (simp add: Texp.AnalBinds_lookup)\n    also have \"\\<dots> \\<sqsubseteq> record_call x \\<cdot>(pathsCard (paths (substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) (single x \\<otimes>\\<otimes> Fstack as S))))\"\n      by (rule pathsCard_paths_nxt)\n    also have \"\\<dots> \\<sqsubseteq> record_call x \\<cdot>(pathsCard (paths (substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) ((Texp (Var x)\\<cdot>a) \\<otimes>\\<otimes> Fstack as S))))\"\n      by (intro monofun_cfun_arg pathsCard_mono' paths_mono substitute_mono2' both_mono1' Texp_Var)\n    also have \"\\<dots> = record_call x \\<cdot>(prognosis ae as a (\\<Gamma>, Var x, S))\"\n      by simp\n    finally\n    show \"prognosis ae as u (delete x \\<Gamma>, e, Upd x # S) \\<sqsubseteq> record_call x\\<cdot>(prognosis ae as a (\\<Gamma>, Var x, S))\" by this simp_all\n  next\n    fix \\<Gamma> :: heap and e :: exp and ae :: AEnv and  x :: var and as S\n    assume \"isVal e\"\n    hence \"repeatable (Texp e\\<cdot>0)\" by (rule Fun_repeatable)\n\n    assume [simp]: \"x \\<notin> domA \\<Gamma>\"\n\n    have [simp]: \"thunks ((x, e) # \\<Gamma>) = thunks \\<Gamma>\" \n      using \\<open>isVal e\\<close>\n      by (auto simp add: thunks_Cons dest: subsetD[OF thunks_domA])\n\n    have \"fup\\<cdot>(Texp e)\\<cdot>(ae x) \\<sqsubseteq> Texp e\\<cdot>0\" by (metis fup2 monofun_cfun_arg up_zero_top)\n    hence \"substitute ((FBinds \\<Gamma>\\<cdot>ae)(x := fup\\<cdot>(Texp e)\\<cdot>(ae x))) (thunks \\<Gamma>) (Texp e\\<cdot>0 \\<otimes>\\<otimes> Fstack as S) \\<sqsubseteq> substitute ((FBinds \\<Gamma>\\<cdot>ae)(x := Texp e\\<cdot>0)) (thunks \\<Gamma>) (Texp e\\<cdot>0 \\<otimes>\\<otimes> Fstack as S)\"\n      by (intro substitute_mono1' fun_upd_mono below_refl monofun_cfun_arg)\n    also have \"\\<dots> = substitute (((FBinds \\<Gamma>\\<cdot>ae)(x := Texp e\\<cdot>0))(x := empty)) (thunks \\<Gamma>) (Texp e\\<cdot>0 \\<otimes>\\<otimes> Fstack as S)\"\n      using \\<open>repeatable (Texp e\\<cdot>0)\\<close> by (rule substitute_remove_anyways, simp)\n    also have \"((FBinds \\<Gamma>\\<cdot>ae)(x := Texp e\\<cdot>0))(x := empty) = FBinds \\<Gamma>\\<cdot>ae\"\n      by (simp add: fun_upd_idem Texp.AnalBinds_not_there empty_is_bottom)\n    finally\n    show \"prognosis ae as 0 ((x, e) # \\<Gamma>, e, S) \\<sqsubseteq> prognosis ae as 0 (\\<Gamma>, e, Upd x # S)\"\n      by (simp, intro pathsCard_mono' paths_mono)\n  qed\n\n  sublocale CardinalityPrognosisIfThenElse prognosis\n  proof\n    fix ae as \\<Gamma> scrut e1 e2 S a\n    have \"Texp scrut\\<cdot>0 \\<otimes>\\<otimes> (Texp e1\\<cdot>a \\<oplus>\\<oplus> Texp e2\\<cdot>a) \\<sqsubseteq> Texp (scrut ? e1 : e2)\\<cdot>a\"\n      by (rule Texp_IfThenElse)\n    hence \"substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) (Texp scrut\\<cdot>0 \\<otimes>\\<otimes> (Texp e1\\<cdot>a \\<oplus>\\<oplus> Texp e2\\<cdot>a) \\<otimes>\\<otimes> Fstack as S) \\<sqsubseteq> substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) (Texp (scrut ? e1 : e2)\\<cdot>a \\<otimes>\\<otimes> Fstack as S)\"\n      by (rule substitute_mono2'[OF both_mono1'])\n    thus \"prognosis ae (a#as) 0 (\\<Gamma>, scrut, Alts e1 e2 # S) \\<sqsubseteq> prognosis ae as a (\\<Gamma>, scrut ? e1 : e2, S)\"\n      by (simp, intro pathsCard_mono' paths_mono)\n  next\n    fix ae as a \\<Gamma> b e1 e2 S\n    have \"Texp (if b then e1 else e2)\\<cdot>a \\<sqsubseteq> Texp e1\\<cdot>a \\<oplus>\\<oplus> Texp e2\\<cdot>a\"\n      by (auto simp add: either_above_arg1 either_above_arg2)\n    hence \"substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) (Texp (if b then e1 else e2)\\<cdot>a \\<otimes>\\<otimes> Fstack as S) \\<sqsubseteq> substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) (Texp (Bool b)\\<cdot>0 \\<otimes>\\<otimes> (Texp e1\\<cdot>a \\<oplus>\\<oplus> Texp e2\\<cdot>a) \\<otimes>\\<otimes> Fstack as S)\"\n      by (rule substitute_mono2'[OF both_mono1'[OF below_trans[OF _ both_above_arg2]]])\n    thus \"prognosis ae as a (\\<Gamma>, if b then e1 else e2, S) \\<sqsubseteq> prognosis ae (a#as) 0 (\\<Gamma>, Bool b, Alts e1 e2 # S)\"\n      by (auto intro!: pathsCard_mono' paths_mono)\n  qed\n\nend\n\ncontext TTreeAnalysisCardinalityHeap\nbegin\n\n  definition cHeap where\n    \"cHeap \\<Gamma> e = (\\<Lambda> a. pathsCard (paths (Theap \\<Gamma> e\\<cdot>a)))\"\n\n  lemma cHeap_simp: \"(cHeap \\<Gamma> e)\\<cdot>a = pathsCard (paths (Theap \\<Gamma> e\\<cdot>a))\"\n    unfolding cHeap_def  by (rule beta_cfun) (intro cont2cont)\n  \n  sublocale CardinalityHeap cHeap.\n \n  sublocale CardinalityHeapSafe cHeap Aheap\n  proof\n    fix x \\<Gamma> e a\n    assume \"x \\<in> thunks \\<Gamma>\"\n    moreover\n    assume \"many \\<sqsubseteq> (cHeap \\<Gamma> e\\<cdot>a) x\"\n    hence \"many \\<sqsubseteq> pathsCard (paths (Theap \\<Gamma> e \\<cdot>a)) x\" unfolding cHeap_def by simp\n    hence \"\\<exists>p\\<in> (paths (Theap \\<Gamma> e\\<cdot>a)). \\<not> (one_call_in_path x p)\" unfolding pathsCard_def\n      by (auto split: if_splits)\n    ultimately\n    show \"(Aheap \\<Gamma> e\\<cdot>a) x = up\\<cdot>0\"\n      by (metis Theap_thunk)\n  next\n    fix \\<Gamma> e a\n    show \"edom (cHeap \\<Gamma> e\\<cdot>a) = edom (Aheap \\<Gamma> e\\<cdot>a)\"\n    by (simp add: cHeap_def Union_paths_carrier carrier_Fheap)\n  qed\n\n  sublocale CardinalityPrognosisEdom prognosis \n  proof\n    fix ae as a \\<Gamma> e S\n    show \"edom (prognosis ae as a (\\<Gamma>, e, S)) \\<subseteq> fv \\<Gamma> \\<union> fv e \\<union> fv S\"\n      apply (simp add: Union_paths_carrier)\n      apply (rule carrier_substitute_below)\n      apply (auto simp add: carrier_Fexp dest: subsetD[OF Aexp_edom] subsetD[OF carrier_Fstack] subsetD[OF ap_fv_subset] subsetD[OF carrier_FBinds])\n      done\n  qed\n  \n  sublocale CardinalityPrognosisLet prognosis cHeap\n  proof\n    fix \\<Delta> \\<Gamma> :: heap and e :: exp and S :: stack and  ae :: AEnv and a :: Arity and as\n    assume \"atom ` domA \\<Delta> \\<sharp>* \\<Gamma>\"\n    assume \"atom ` domA \\<Delta> \\<sharp>* S\"\n    assume \"edom ae \\<subseteq> domA \\<Gamma> \\<union> upds S\"\n\n    have \"domA \\<Delta> \\<inter> edom ae = {}\"\n      using fresh_distinct[OF \\<open>atom ` domA \\<Delta> \\<sharp>* \\<Gamma>\\<close>] fresh_distinct_fv[OF \\<open>atom ` domA \\<Delta> \\<sharp>* S\\<close>] \n            \\<open>edom ae \\<subseteq> domA \\<Gamma> \\<union> upds S\\<close> ups_fv_subset[of S]\n      by auto\n\n    have const_on1:  \"\\<And> x. const_on (FBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (carrier ((FBinds \\<Gamma>\\<cdot>ae) x)) empty\"\n      unfolding const_on_edom_disj using fresh_distinct_fv[OF \\<open>atom ` domA \\<Delta> \\<sharp>* \\<Gamma>\\<close>]\n      by (auto dest!: subsetD[OF carrier_FBinds] subsetD[OF Texp.edom_AnalBinds])\n    have const_on2:  \"const_on (FBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (carrier (Fstack as S)) empty\"\n      unfolding const_on_edom_disj using fresh_distinct_fv[OF \\<open>atom ` domA \\<Delta> \\<sharp>* S\\<close>]\n      by (auto dest!: subsetD[OF carrier_FBinds] subsetD[OF carrier_Fstack] subsetD[OF Texp.edom_AnalBinds] subsetD[OF ap_fv_subset ])\n    have  const_on3: \"const_on (FBinds \\<Gamma>\\<cdot>ae) (- (- domA \\<Delta>)) TTree.empty\"\n      and const_on4: \"const_on (FBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (domA \\<Gamma>) TTree.empty\"\n      unfolding const_on_edom_disj using fresh_distinct[OF \\<open>atom ` domA \\<Delta> \\<sharp>* \\<Gamma>\\<close>]\n      by (auto dest!:  subsetD[OF Texp.edom_AnalBinds])\n\n    have disj1: \"\\<And> x. carrier ((FBinds \\<Gamma>\\<cdot>ae) x) \\<inter> domA \\<Delta> = {}\"\n      using fresh_distinct_fv[OF \\<open>atom ` domA \\<Delta> \\<sharp>* \\<Gamma>\\<close>]\n      by (auto dest: subsetD[OF carrier_FBinds])\n    hence disj1': \"\\<And> x. carrier ((FBinds \\<Gamma>\\<cdot>ae) x) \\<subseteq> - domA \\<Delta>\" by auto\n    have disj2: \"\\<And> x. carrier (Fstack as S) \\<inter> domA \\<Delta> = {}\"\n      using fresh_distinct_fv[OF \\<open>atom ` domA \\<Delta> \\<sharp>* S\\<close>] by (auto dest!: subsetD[OF carrier_Fstack])\n    hence disj2': \"carrier (Fstack as S) \\<subseteq> - domA \\<Delta>\" by auto\n    \n\n    {\n    fix x\n    have \"(FBinds (\\<Delta> @ \\<Gamma>)\\<cdot>(ae \\<squnion> Aheap \\<Delta> e\\<cdot>a)) x = (FBinds \\<Gamma>\\<cdot>ae) x \\<otimes>\\<otimes> (FBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) x\"\n    proof (cases \"x \\<in> domA \\<Delta>\")\n      case True\n      have \"map_of \\<Gamma> x = None\" using True fresh_distinct[OF \\<open>atom ` domA \\<Delta> \\<sharp>* \\<Gamma>\\<close>] by (metis disjoint_iff_not_equal domA_def map_of_eq_None_iff)\n      moreover\n      have \"ae x = \\<bottom>\" using True \\<open>domA \\<Delta> \\<inter> edom ae = {}\\<close> by auto\n      ultimately\n      show ?thesis using True \n          by (auto simp add: Texp.AnalBinds_lookup empty_is_bottom[symmetric] cong: option.case_cong)\n    next\n      case False\n      have \"map_of \\<Delta> x = None\" using False by (metis domA_def map_of_eq_None_iff)\n      moreover\n      have \"(Aheap \\<Delta> e\\<cdot>a) x = \\<bottom>\" using False using edom_Aheap by (metis contra_subsetD edomIff)\n      ultimately\n      show ?thesis using False\n         by (auto simp add: Texp.AnalBinds_lookup empty_is_bottom[symmetric] cong: option.case_cong)\n    qed\n    }\n    note FBinds = ext[OF this]\n    \n    {\n    have \"pathsCard (paths (substitute (FBinds (\\<Delta> @ \\<Gamma>)\\<cdot>(Aheap \\<Delta> e\\<cdot>a \\<squnion> ae)) (thunks (\\<Delta> @ \\<Gamma>)) (Texp e\\<cdot>a \\<otimes>\\<otimes> Fstack as S)))\n      = pathsCard (paths (substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks (\\<Delta> @ \\<Gamma>)) (substitute (FBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a))  (thunks (\\<Delta> @ \\<Gamma>))  (Texp e\\<cdot>a \\<otimes>\\<otimes> Fstack as S))))\"\n       by (simp add: substitute_substitute[OF const_on1] FBinds)\n    also have \"substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks (\\<Delta> @ \\<Gamma>)) = substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>)\"\n      apply (rule substitute_cong_T)\n      using const_on3\n      by (auto dest: subsetD[OF thunks_domA])\n    also have \"substitute (FBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks (\\<Delta> @ \\<Gamma>)) = substitute (FBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>)\"\n      apply (rule substitute_cong_T)\n      using const_on4\n      by (auto dest: subsetD[OF thunks_domA])\n    also have \"substitute (FBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>) (Texp e\\<cdot>a \\<otimes>\\<otimes> Fstack as S) = substitute (FBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>) (Texp e\\<cdot>a) \\<otimes>\\<otimes> Fstack as S\"\n      by (rule substitute_only_empty_both[OF const_on2])\n    also note calculation\n    }\n    note eq_imp_below[OF this]\n    also\n    note env_restr_split[where S = \"domA \\<Delta>\"]\n    also\n    have \"pathsCard (paths (substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) (substitute (FBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>) (Texp e\\<cdot>a) \\<otimes>\\<otimes> Fstack as S))) f|` domA \\<Delta> \n        = pathsCard (paths (ttree_restr (domA \\<Delta>) (substitute (FBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>) (Texp e\\<cdot>a))))\"\n          by (simp add: filter_paths_conv_free_restr ttree_restr_both ttree_rest_substitute[OF disj1]  ttree_restr_is_empty[OF disj2])\n    also\n    have \"ttree_restr (domA \\<Delta>) (substitute (FBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>) (Texp e\\<cdot>a)) \\<sqsubseteq> Theap \\<Delta> e\\<cdot>a\"  by (rule Theap_substitute)\n    also\n    have \"pathsCard (paths (substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) (substitute (FBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>) (Texp e\\<cdot>a) \\<otimes>\\<otimes> Fstack as S))) f|` (- domA \\<Delta>) =\n          pathsCard (paths (substitute (FBinds \\<Gamma>\\<cdot>ae) (thunks \\<Gamma>) (ttree_restr (- domA \\<Delta>) (substitute (FBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a)) (thunks \\<Delta>) (Texp e\\<cdot>a)) \\<otimes>\\<otimes> Fstack as S)))\"\n          by (simp add: filter_paths_conv_free_restr2 ttree_rest_substitute2[OF disj1' const_on3] ttree_restr_both  ttree_restr_noop[OF disj2'])\n    also have \"ttree_restr (- domA \\<Delta>) (substitute (FBinds \\<Delta>\\<cdot>(Aheap \\<Delta> e\\<cdot>a))  (thunks \\<Delta>)  (Texp e\\<cdot>a)) \\<sqsubseteq> Texp (Terms.Let \\<Delta> e)\\<cdot>a\" by (rule Texp_Let)\n    finally\n    show \"prognosis (Aheap \\<Delta> e\\<cdot>a \\<squnion> ae) as a (\\<Delta> @ \\<Gamma>, e, S) \\<sqsubseteq> cHeap \\<Delta> e\\<cdot>a \\<squnion> prognosis ae as a (\\<Gamma>, Terms.Let \\<Delta> e, S)\"\n      by (simp add: cHeap_def del: fun_meet_simp) \n  qed\n\n  sublocale CardinalityPrognosisSafe prognosis cHeap Aheap Aexp ..\nend\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Call_Arity/TTreeImplCardinalitySafe.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.658417500561683, "lm_q2_score": 0.399811640739795, "lm_q1q2_score": 0.2632429811913614}}
{"text": "header {* \\isaheader{Framework Graph Lifting for Noninterference} *}\n\ntheory LiftingIntra \n  imports NonInterferenceIntra \"../Slicing/StaticIntra/CDepInstantiations\" \nbegin\n\ntext {* In this section, we show how a valid CFG from the slicing framework in\n\\cite{Wasserrab:08} can be lifted to fulfil all properties of the \n@{text \"NonInterferenceIntraGraph\"} locale. Basically, we redefine the\nhitherto existing @{text Entry} and @{text Exit} nodes as new\n@{text High} and @{text Low} nodes, and introduce two new nodes\n@{text NewEntry} and @{text NewExit}. Then, we have to lift all functions\nto operate on this new graph. *}\n\nsubsection {* Liftings *}\n\nsubsubsection {* The datatypes *}\n\ndatatype 'node LDCFG_node = Node 'node\n  | NewEntry\n  | NewExit\n\n\ntype_synonym ('edge,'node,'state) LDCFG_edge = \n  \"'node LDCFG_node \\<times> ('state edge_kind) \\<times> 'node LDCFG_node\"\n\n\nsubsubsection {* Lifting @{term valid_edge} *}\n\ninductive lift_valid_edge :: \"('edge \\<Rightarrow> bool) \\<Rightarrow> ('edge \\<Rightarrow> 'node) \\<Rightarrow> ('edge \\<Rightarrow> 'node) \\<Rightarrow>\n  ('edge \\<Rightarrow> 'state edge_kind) \\<Rightarrow> 'node \\<Rightarrow> 'node \\<Rightarrow> ('edge,'node,'state) LDCFG_edge \\<Rightarrow> \n  bool\"\nfor valid_edge::\"'edge \\<Rightarrow> bool\" and src::\"'edge \\<Rightarrow> 'node\" and trg::\"'edge \\<Rightarrow> 'node\" \n  and knd::\"'edge \\<Rightarrow> 'state edge_kind\" and E::'node and X::'node\n\nwhere lve_edge:\n  \"\\<lbrakk>valid_edge a; src a \\<noteq> E \\<or> trg a \\<noteq> X; \n    e = (Node (src a),knd a,Node (trg a))\\<rbrakk>\n  \\<Longrightarrow> lift_valid_edge valid_edge src trg knd E X e\"\n\n  | lve_Entry_edge:\n  \"e = (NewEntry,(\\<lambda>s. True)\\<^sub>\\<surd>,Node E) \n  \\<Longrightarrow> lift_valid_edge valid_edge src trg knd E X e\"\n\n  | lve_Exit_edge:\n  \"e = (Node X,(\\<lambda>s. True)\\<^sub>\\<surd>,NewExit) \n  \\<Longrightarrow> lift_valid_edge valid_edge src trg knd E X e\"\n\n  | lve_Entry_Exit_edge:\n  \"e = (NewEntry,(\\<lambda>s. False)\\<^sub>\\<surd>,NewExit) \n  \\<Longrightarrow> lift_valid_edge valid_edge src trg knd E X e\"\n\n\n\n\n\nsubsubsection {* Lifting @{term Def} and @{term Use} sets *}\n\ninductive_set lift_Def_set :: \"('node \\<Rightarrow> 'var set) \\<Rightarrow> 'node \\<Rightarrow> 'node \\<Rightarrow> \n                       'var set \\<Rightarrow> 'var set \\<Rightarrow> ('node LDCFG_node \\<times> 'var) set\"\nfor Def::\"('node \\<Rightarrow> 'var set)\" and E::'node and X::'node \n  and H::\"'var set\" and L::\"'var set\"\n\nwhere lift_Def_node: \n  \"V \\<in> Def n \\<Longrightarrow> (Node n,V) \\<in> lift_Def_set Def E X H L\"\n\n  | lift_Def_High:\n  \"V \\<in> H \\<Longrightarrow> (Node E,V) \\<in> lift_Def_set Def E X H L\"\n\nabbreviation lift_Def :: \"('node \\<Rightarrow> 'var set) \\<Rightarrow> 'node \\<Rightarrow> 'node \\<Rightarrow> \n                       'var set \\<Rightarrow> 'var set \\<Rightarrow> 'node LDCFG_node \\<Rightarrow> 'var set\"\n  where \"lift_Def Def E X H L n \\<equiv> {V. (n,V) \\<in> lift_Def_set Def E X H L}\"\n\n\ninductive_set lift_Use_set :: \"('node \\<Rightarrow> 'var set) \\<Rightarrow> 'node \\<Rightarrow> 'node \\<Rightarrow> \n                       'var set \\<Rightarrow> 'var set \\<Rightarrow> ('node LDCFG_node \\<times> 'var) set\"\nfor Use::\"'node \\<Rightarrow> 'var set\" and E::'node and X::'node \n  and H::\"'var set\" and L::\"'var set\"\n\nwhere \n  lift_Use_node: \n  \"V \\<in> Use n \\<Longrightarrow> (Node n,V) \\<in> lift_Use_set Use E X H L\"\n\n  | lift_Use_High:\n  \"V \\<in> H \\<Longrightarrow> (Node E,V) \\<in> lift_Use_set Use E X H L\"\n\n  | lift_Use_Low:\n  \"V \\<in> L \\<Longrightarrow> (Node X,V) \\<in> lift_Use_set Use E X H L\"\n\n\nabbreviation lift_Use :: \"('node \\<Rightarrow> 'var set) \\<Rightarrow> 'node \\<Rightarrow> 'node \\<Rightarrow> \n                       'var set \\<Rightarrow> 'var set \\<Rightarrow> 'node LDCFG_node \\<Rightarrow> 'var set\"\n  where \"lift_Use Use E X H L n \\<equiv> {V. (n,V) \\<in> lift_Use_set Use E X H L}\"\n\n\n\nsubsection {* The lifting lemmas *}\n\nsubsubsection {* Lifting the basic locales *}\n\n\nabbreviation src :: \"('edge,'node,'state) LDCFG_edge \\<Rightarrow> 'node LDCFG_node\"\n  where \"src a \\<equiv> fst a\"\n\nabbreviation trg :: \"('edge,'node,'state) LDCFG_edge \\<Rightarrow> 'node LDCFG_node\"\n  where \"trg a \\<equiv> snd(snd a)\"\n\ndefinition knd :: \"('edge,'node,'state) LDCFG_edge \\<Rightarrow> 'state edge_kind\"\n  where \"knd a \\<equiv> fst(snd a)\"\n\n\nlemma lift_CFG:\n  assumes wf:\"CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use\n                         state_val Exit\"\n  shows \"CFG src trg\n    (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewEntry\"\nproof -\n  interpret CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use\n                       state_val Exit\n    by(rule wf)\n  show ?thesis \n  proof\n    fix a assume \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      and \"trg a = NewEntry\"\n    thus False by(fastforce elim:lift_valid_edge.cases)\n  next\n    fix a a' \n    assume \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      and \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a'\"\n      and \"src a = src a'\" and \"trg a = trg a'\"\n    thus \"a = a'\"\n    proof(induct rule:lift_valid_edge.induct)\n      case lve_edge thus ?case by -(erule lift_valid_edge.cases,auto dest:edge_det)\n    qed(auto elim:lift_valid_edge.cases)\n  qed\nqed\n\n\nlemma lift_CFG_wf:\n  assumes wf:\"CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use\n                         state_val Exit\"\n  shows \"CFG_wf src trg knd \n         (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewEntry\n         (lift_Def Def Entry Exit H L) (lift_Use Use Entry Exit H L) state_val\"\nproof -\n  interpret CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use\n                       state_val Exit\n    by(rule wf)\n  interpret CFG:CFG src trg knd\n    \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\" NewEntry\n    by(fastforce intro:lift_CFG wf)\n  show ?thesis\n  proof\n    show \"lift_Def Def Entry Exit H L NewEntry = {} \\<and>\n          lift_Use Use Entry Exit H L NewEntry = {}\"\n      by(fastforce elim:lift_Use_set.cases lift_Def_set.cases)\n  next\n    fix a V s \n    assume \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      and \"V \\<notin> lift_Def Def Entry Exit H L (src a)\" and \"pred (knd a) s\"\n    thus \"state_val (transfer (knd a) s) V = state_val s V\"\n    proof(induct rule:lift_valid_edge.induct)\n      case lve_edge\n      thus ?case by(fastforce intro:CFG_edge_no_Def_equal dest:lift_Def_node[of _ Def]\n        simp:knd_def)\n    qed(auto simp:knd_def)\n  next\n    fix a s s'\n    assume assms:\"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      \"\\<forall>V\\<in>lift_Use Use Entry Exit H L (src a). state_val s V = state_val s' V\"\n      \"pred (knd a) s\" \"pred (knd a) s'\"\n    show \"\\<forall>V\\<in>lift_Def Def Entry Exit H L (src a).\n             state_val (transfer (knd a) s) V = state_val (transfer (knd a) s') V\"\n    proof\n      fix V assume \"V \\<in> lift_Def Def Entry Exit H L (src a)\"\n      with assms\n      show \"state_val (transfer (knd a) s) V = state_val (transfer (knd a) s') V\"\n      proof(induct rule:lift_valid_edge.induct)\n        case (lve_edge a e)\n        show ?case\n        proof (cases \"Node (sourcenode a) = Node Entry\")\n          case True\n          hence \"sourcenode a = Entry\" by simp\n          from Entry_Exit_edge obtain a' where \"valid_edge a'\"\n            and \"sourcenode a' = Entry\" and \"targetnode a' = Exit\"\n            and \"kind a' = (\\<lambda>s. False)\\<^sub>\\<surd>\" by blast\n          have \"\\<exists>Q. kind a = (Q)\\<^sub>\\<surd>\"\n          proof(cases \"targetnode a = Exit\")\n            case True\n            with `valid_edge a` `valid_edge a'` `sourcenode a = Entry`\n              `sourcenode a' = Entry` `targetnode a' = Exit`\n            have \"a = a'\" by(fastforce dest:edge_det)\n            with `kind a' = (\\<lambda>s. False)\\<^sub>\\<surd>` show ?thesis by simp\n          next\n            case False\n            with `valid_edge a` `valid_edge a'` `sourcenode a = Entry`\n              `sourcenode a' = Entry` `targetnode a' = Exit`\n            show ?thesis by(auto dest:deterministic)\n          qed\n          from True `V \\<in> lift_Def Def Entry Exit H L (src e)` Entry_empty\n            `e = (Node (sourcenode a), kind a, Node (targetnode a))`\n          have \"V \\<in> H\" by(fastforce elim:lift_Def_set.cases)\n          from True `e = (Node (sourcenode a), kind a, Node (targetnode a))`\n            `sourcenode a \\<noteq> Entry \\<or> targetnode a \\<noteq> Exit`\n          have \"\\<forall>V\\<in>H. V \\<in> lift_Use Use Entry Exit H L (src e)\"\n            by(fastforce intro:lift_Use_High)\n          with `\\<forall>V\\<in>lift_Use Use Entry Exit H L (src e). \n                            state_val s V = state_val s' V` `V \\<in> H`\n          have \"state_val s V = state_val s' V\" by simp\n          with `e = (Node (sourcenode a), kind a, Node (targetnode a))` \n            `\\<exists>Q. kind a = (Q)\\<^sub>\\<surd>`\n          show ?thesis by(fastforce simp:knd_def)\n        next\n          case False\n          { fix V' assume \"V' \\<in> Use (sourcenode a)\"\n            with `e = (Node (sourcenode a), kind a, Node (targetnode a))`\n            have \"V' \\<in> lift_Use Use Entry Exit H L (src e)\"\n              by(fastforce intro:lift_Use_node)\n          }\n          with `\\<forall>V\\<in>lift_Use Use Entry Exit H L (src e). \n                            state_val s V = state_val s' V`\n          have \"\\<forall>V\\<in>Use (sourcenode a). state_val s V = state_val s' V\"\n            by fastforce\n          from `valid_edge a` this `pred (knd e) s` `pred (knd e) s'`\n            `e = (Node (sourcenode a), kind a, Node (targetnode a))`\n          have \"\\<forall>V \\<in> Def (sourcenode a). state_val (transfer (kind a) s) V =\n            state_val (transfer (kind a) s') V\"\n            by -(erule CFG_edge_transfer_uses_only_Use,auto simp:knd_def)\n          from `V \\<in> lift_Def Def Entry Exit H L (src e)` False\n            `e = (Node (sourcenode a), kind a, Node (targetnode a))`\n          have \"V \\<in> Def (sourcenode a)\" by(fastforce elim:lift_Def_set.cases)\n          with `\\<forall>V \\<in> Def (sourcenode a). state_val (transfer (kind a) s) V =\n            state_val (transfer (kind a) s') V`\n            `e = (Node (sourcenode a), kind a, Node (targetnode a))`\n          show ?thesis by(simp add:knd_def)\n        qed\n      next\n        case (lve_Entry_edge e)\n        from `V \\<in> lift_Def Def Entry Exit H L (src e)` \n          `e = (NewEntry, (\\<lambda>s. True)\\<^sub>\\<surd>, Node Entry)`\n        have False by(fastforce elim:lift_Def_set.cases)\n        thus ?case by simp\n      next\n        case (lve_Exit_edge e)\n        from `V \\<in> lift_Def Def Entry Exit H L (src e)` \n          `e = (Node Exit, (\\<lambda>s. True)\\<^sub>\\<surd>, NewExit)`\n        have False\n          by(fastforce elim:lift_Def_set.cases intro!:Entry_noteq_Exit simp:Exit_empty)\n        thus ?case  by simp\n      qed(simp add:knd_def)\n    qed\n  next\n    fix a s s'\n    assume \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      and \"pred (knd a) s\" \n      and \"\\<forall>V\\<in>lift_Use Use Entry Exit H L (src a). state_val s V = state_val s' V\"\n    thus \"pred (knd a) s'\"\n      by(induct rule:lift_valid_edge.induct,\n         auto elim!:CFG_edge_Uses_pred_equal dest:lift_Use_node simp:knd_def)\n  next\n    fix a a'\n    assume \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      and \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a'\"\n      and \"src a = src a'\" and \"trg a \\<noteq> trg a'\"\n    thus \"\\<exists>Q Q'. knd a = (Q)\\<^sub>\\<surd> \\<and> knd a' = (Q')\\<^sub>\\<surd> \\<and> \n                 (\\<forall>s. (Q s \\<longrightarrow> \\<not> Q' s) \\<and> (Q' s \\<longrightarrow> \\<not> Q s))\"\n    proof(induct rule:lift_valid_edge.induct)\n      case (lve_edge a e)\n      from `lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a'`\n        `valid_edge a` `e = (Node (sourcenode a), kind a, Node (targetnode a))`\n        `src e = src a'` `trg e \\<noteq> trg a'`\n      show ?case\n      proof(induct rule:lift_valid_edge.induct)\n        case lve_edge thus ?case by(auto dest:deterministic simp:knd_def)\n      next\n        case (lve_Exit_edge e')\n        from `e = (Node (sourcenode a), kind a, Node (targetnode a))`\n          `e' = (Node Exit, (\\<lambda>s. True)\\<^sub>\\<surd>, NewExit)` `src e = src e'`\n        have \"sourcenode a = Exit\" by simp\n        with `valid_edge a` have False by(rule Exit_source)\n        thus ?case by simp\n      qed auto\n    qed (fastforce elim:lift_valid_edge.cases simp:knd_def)+\n  qed\nqed\n\n\nlemma lift_CFGExit:\n  assumes wf:\"CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use\n                         state_val Exit\"\n  shows \"CFGExit src trg knd \n         (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) \n         NewEntry NewExit\"\nproof -\n  interpret CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use\n                       state_val Exit\n    by(rule wf)\n  interpret CFG:CFG src trg knd\n    \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\" NewEntry\n    by(fastforce intro:lift_CFG wf)\n  show ?thesis\n  proof\n    fix a assume \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      and \"src a = NewExit\"\n    thus False by(fastforce elim:lift_valid_edge.cases)\n  next\n    from lve_Entry_Exit_edge\n    show \"\\<exists>a. lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a \\<and>\n              src a = NewEntry \\<and> trg a = NewExit \\<and> knd a = (\\<lambda>s. False)\\<^sub>\\<surd>\"\n      by(fastforce simp:knd_def)\n  qed\nqed\n\n\nlemma lift_CFGExit_wf:\n  assumes wf:\"CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use\n                         state_val Exit\"\n  shows \"CFGExit_wf src trg knd \n        (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewEntry\n        (lift_Def Def Entry Exit H L) (lift_Use Use Entry Exit H L) state_val NewExit\"\nproof -\n  interpret CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use\n                       state_val Exit\n    by(rule wf)\n  interpret CFGExit:CFGExit src trg knd\n    \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\" \n    NewEntry NewExit\n    by(fastforce intro:lift_CFGExit wf)\n  interpret CFG_wf:CFG_wf src trg knd\n    \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\" \n    NewEntry \"lift_Def Def Entry Exit H L\" \"lift_Use Use Entry Exit H L\" state_val\n    by(fastforce intro:lift_CFG_wf wf)\n  show ?thesis\n  proof\n    show \"lift_Def Def Entry Exit H L NewExit = {} \\<and>\n          lift_Use Use Entry Exit H L NewExit = {}\"\n      by(fastforce elim:lift_Use_set.cases lift_Def_set.cases)\n  qed\nqed\n\n\n\nsubsubsection {* Lifting @{term wod_backward_slice} *}\n\nlemma lift_wod_backward_slice:\n  fixes valid_edge and sourcenode and targetnode and kind and Entry and Exit\n  and Def and Use and H and L\n  defines lve:\"lve \\<equiv> lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\"\n  and lDef:\"lDef \\<equiv> lift_Def Def Entry Exit H L\" \n  and lUse:\"lUse \\<equiv> lift_Use Use Entry Exit H L\"\n  assumes wf:\"CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use\n                         state_val Exit\"\n  and \"H \\<inter> L = {}\" and \"H \\<union> L = UNIV\"\n  shows \"NonInterferenceIntraGraph src trg knd lve NewEntry lDef lUse state_val \n         (CFG_wf.wod_backward_slice src trg lve lDef lUse)\n         NewExit H L (Node Entry) (Node Exit)\"\nproof -\n  interpret CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use\n                       state_val Exit\n    by(rule wf)\n  interpret CFGExit_wf:\n    CFGExit_wf src trg knd lve NewEntry lDef lUse state_val NewExit\n    by(fastforce intro:lift_CFGExit_wf wf simp:lve lDef lUse)\n  from wf lve have CFG:\"CFG src trg lve NewEntry\"\n    by(fastforce intro:lift_CFG)\n  from wf lve lDef lUse have CFG_wf:\"CFG_wf src trg knd lve NewEntry\n    lDef lUse state_val\"\n    by(fastforce intro:lift_CFG_wf)\n  show ?thesis\n  proof\n    fix n S\n    assume \"n \\<in> CFG_wf.wod_backward_slice src trg lve lDef lUse S\"\n    with CFG_wf show \"CFG.valid_node src trg lve n\"\n      by -(rule CFG_wf.wod_backward_slice_valid_node)\n  next\n    fix n S assume \"CFG.valid_node src trg lve n\" and \"n \\<in> S\"\n    with CFG_wf show \"n \\<in> CFG_wf.wod_backward_slice src trg lve lDef lUse S\"\n      by -(rule CFG_wf.refl)\n  next\n    fix n' S n V\n    assume \"n' \\<in> CFG_wf.wod_backward_slice src trg lve lDef lUse S\"\n      and \"CFG_wf.data_dependence src trg lve lDef lUse n V n'\"\n    with CFG_wf show \"n \\<in> CFG_wf.wod_backward_slice src trg lve lDef lUse S\"\n      by -(rule CFG_wf.dd_closed)\n  next\n    fix n S\n    from CFG_wf \n    have \"(\\<exists>m. (CFG.obs src trg lve n\n        (CFG_wf.wod_backward_slice src trg lve lDef lUse S)) = {m}) \\<or>\n      CFG.obs src trg lve n (CFG_wf.wod_backward_slice src trg lve lDef lUse S) = {}\"\n      by(rule CFG_wf.obs_singleton)\n    thus \"finite \n      (CFG.obs src trg lve n (CFG_wf.wod_backward_slice src trg lve lDef lUse S))\"\n      by fastforce\n  next\n    fix n S\n    from CFG_wf \n    have \"(\\<exists>m. (CFG.obs src trg lve n\n        (CFG_wf.wod_backward_slice src trg lve lDef lUse S)) = {m}) \\<or>\n      CFG.obs src trg lve n (CFG_wf.wod_backward_slice src trg lve lDef lUse S) = {}\"\n      by(rule CFG_wf.obs_singleton)\n    thus \"card (CFG.obs src trg lve n\n                        (CFG_wf.wod_backward_slice src trg lve lDef lUse S)) \\<le> 1\"\n      by fastforce\n  next\n    fix a assume \"lve a\" and \"src a = NewEntry\"\n    with lve show \"trg a = NewExit \\<or> trg a = Node Entry\"\n      by(fastforce elim:lift_valid_edge.cases)\n  next\n    from lve_Entry_edge lve\n    show \"\\<exists>a. lve a \\<and> src a = NewEntry \\<and> trg a = Node Entry \\<and> knd a = (\\<lambda>s. True)\\<^sub>\\<surd>\"\n      by(fastforce simp:knd_def)\n  next\n    fix a assume \"lve a\" and \"trg a = Node Entry\"\n    with lve show \"src a = NewEntry\" by(fastforce elim:lift_valid_edge.cases)\n  next\n    fix a assume \"lve a\" and \"trg a = NewExit\"\n    with lve show \"src a = NewEntry \\<or> src a = Node Exit\"\n      by(fastforce elim:lift_valid_edge.cases)\n  next\n    from lve_Exit_edge lve\n    show \"\\<exists>a. lve a \\<and> src a = Node Exit \\<and> trg a = NewExit \\<and> knd a = (\\<lambda>s. True)\\<^sub>\\<surd>\"\n      by(fastforce simp:knd_def)\n  next\n    fix a assume \"lve a\" and \"src a = Node Exit\"\n    with lve show \"trg a = NewExit\" by(fastforce elim:lift_valid_edge.cases)\n  next\n    from lDef show \"lDef (Node Entry) = H\"\n      by(fastforce elim:lift_Def_set.cases intro:lift_Def_High)\n  next\n    from Entry_noteq_Exit lUse show \"lUse (Node Entry) = H\"\n      by(fastforce elim:lift_Use_set.cases intro:lift_Use_High)\n  next\n    from Entry_noteq_Exit lUse show \"lUse (Node Exit) = L\"\n      by(fastforce elim:lift_Use_set.cases intro:lift_Use_Low)\n  next\n    from `H \\<inter> L = {}` show \"H \\<inter> L = {}\" .\n  next\n    from `H \\<union> L = UNIV` show \"H \\<union> L = UNIV\" .\n  qed\nqed\n\n\nsubsubsection {* Lifting @{text PDG_BS} with @{text standard_control_dependence} *}\n\nlemma lift_Postdomination:\n  assumes wf:\"CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use\n                         state_val Exit\"\n  and pd:\"Postdomination sourcenode targetnode kind valid_edge Entry Exit\"\n  and inner:\"CFGExit.inner_node sourcenode targetnode valid_edge Entry Exit nx\"\n  shows \"Postdomination src trg knd\n  (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewEntry NewExit\"\nproof -\n  interpret Postdomination sourcenode targetnode kind valid_edge Entry Exit\n    by(rule pd)\n  interpret CFGExit_wf:CFGExit_wf src trg knd\n    \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\" NewEntry\n    \"lift_Def Def Entry Exit H L\" \"lift_Use Use Entry Exit H L\" state_val NewExit\n    by(fastforce intro:lift_CFGExit_wf wf)\n  from wf have CFG:\"CFG src trg\n    (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewEntry\"\n    by(rule lift_CFG)\n  show ?thesis\n  proof\n    fix n assume \"CFG.valid_node src trg\n      (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) n\"\n    show \"\\<exists>as. CFG.path src trg\n      (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n      NewEntry as n\"\n    proof(cases n)\n      case NewEntry\n      have \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\n        (NewEntry,(\\<lambda>s. False)\\<^sub>\\<surd>,NewExit)\" by(fastforce intro:lve_Entry_Exit_edge)\n      with NewEntry have \"CFG.path src trg\n        (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n        NewEntry [] n\"\n        by(fastforce intro:CFG.empty_path[OF CFG] simp:CFG.valid_node_def[OF CFG])\n      thus ?thesis by blast\n    next\n      case NewExit\n      have \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\n        (NewEntry,(\\<lambda>s. False)\\<^sub>\\<surd>,NewExit)\" by(fastforce intro:lve_Entry_Exit_edge)\n      with NewExit have \"CFG.path src trg\n        (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n        NewEntry [(NewEntry,(\\<lambda>s. False)\\<^sub>\\<surd>,NewExit)] n\"\n        by(fastforce intro:CFG.Cons_path[OF CFG] CFG.empty_path[OF CFG]\n                     simp:CFG.valid_node_def[OF CFG])\n      thus ?thesis by blast\n    next\n      case (Node m)\n      with Entry_Exit_edge `CFG.valid_node src trg\n        (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) n`\n      have \"valid_node m\" \n        by(auto elim:lift_valid_edge.cases \n                simp:CFG.valid_node_def[OF CFG] valid_node_def)\n      thus ?thesis\n      proof(cases m rule:valid_node_cases)\n        case Entry\n        have \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\n          (NewEntry,(\\<lambda>s. True)\\<^sub>\\<surd>,Node Entry)\" by(fastforce intro:lve_Entry_edge)\n        with Entry Node have \"CFG.path src trg\n          (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n          NewEntry [(NewEntry,(\\<lambda>s. True)\\<^sub>\\<surd>,Node Entry)] n\"\n          by(fastforce intro:CFG.Cons_path[OF CFG] CFG.empty_path[OF CFG]\n                       simp:CFG.valid_node_def[OF CFG])\n        thus ?thesis by blast\n      next\n        case Exit\n        from inner obtain ax where \"valid_edge ax\" and \"inner_node (sourcenode ax)\"\n          and \"targetnode ax = Exit\" by(erule inner_node_Exit_edge)\n        hence \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\n          (Node (sourcenode ax),kind ax,Node Exit)\"\n          by(auto intro:lift_valid_edge.lve_edge simp:inner_node_def)\n        hence path:\"CFG.path src trg\n          (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n          (Node (sourcenode ax)) [(Node (sourcenode ax),kind ax,Node Exit)] \n          (Node Exit)\"\n          by(fastforce intro:CFG.Cons_path[OF CFG] CFG.empty_path[OF CFG]\n                       simp:CFG.valid_node_def[OF CFG])\n        have edge:\"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\n          (NewEntry,(\\<lambda>s. True)\\<^sub>\\<surd>,Node Entry)\" by(fastforce intro:lve_Entry_edge)\n        from `inner_node (sourcenode ax)` have \"valid_node (sourcenode ax)\"\n          by(rule inner_is_valid)\n        then obtain asx where \"Entry -asx\\<rightarrow>* sourcenode ax\"\n          by(fastforce dest:Entry_path)\n        from this `valid_edge ax` have \"\\<exists>es. CFG.path src trg\n          (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n          (Node Entry) es (Node (sourcenode ax))\"\n        proof(induct asx arbitrary:ax rule:rev_induct)\n          case Nil\n          from `Entry -[]\\<rightarrow>* sourcenode ax` have \"sourcenode ax = Entry\" by fastforce\n          hence \"CFG.path src trg\n            (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n            (Node Entry) [] (Node (sourcenode ax))\"\n            apply simp apply(rule CFG.empty_path[OF CFG])\n            by(auto intro:lve_Entry_edge simp:CFG.valid_node_def[OF CFG])\n          thus ?case by blast\n        next\n          case (snoc x xs)\n          note IH = `\\<And>ax. \\<lbrakk>Entry -xs\\<rightarrow>* sourcenode ax; valid_edge ax\\<rbrakk> \\<Longrightarrow>\n            \\<exists>es. CFG.path src trg\n            (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n            (Node Entry) es (Node (sourcenode ax))`\n          from `Entry -xs@[x]\\<rightarrow>* sourcenode ax`\n          have \"Entry -xs\\<rightarrow>* sourcenode x\" and \"valid_edge x\"\n            and \"targetnode x = sourcenode ax\" by(auto elim:path_split_snoc)\n          { assume \"targetnode x = Exit\"\n            with `valid_edge ax` `targetnode x = sourcenode ax`\n            have False by -(rule Exit_source,simp+) }\n          hence \"targetnode x \\<noteq> Exit\" by clarsimp\n          with `valid_edge x` `targetnode x = sourcenode ax`[THEN sym]\n          have \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\n            (Node (sourcenode x),kind x,Node (sourcenode ax))\"\n            by(fastforce intro:lift_valid_edge.lve_edge)\n          hence path:\"CFG.path src trg\n            (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n            (Node (sourcenode x)) [(Node (sourcenode x),kind x,Node (sourcenode ax))] \n            (Node (sourcenode ax))\"\n            by(fastforce intro:CFG.Cons_path[OF CFG] CFG.empty_path[OF CFG]\n                         simp:CFG.valid_node_def[OF CFG])\n          from IH[OF `Entry -xs\\<rightarrow>* sourcenode x` `valid_edge x`] obtain es\n            where \"CFG.path src trg\n            (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n            (Node Entry) es (Node (sourcenode x))\" by blast\n          with path have \"CFG.path src trg\n            (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n            (Node Entry) (es@[(Node (sourcenode x),kind x,Node (sourcenode ax))])\n            (Node (sourcenode ax))\"\n            by -(rule CFG.path_Append[OF CFG])\n          thus ?case by blast\n        qed\n        then obtain es where \"CFG.path src trg\n          (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n          (Node Entry) es (Node (sourcenode ax))\" by blast\n        with path have \"CFG.path src trg\n          (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n          (Node Entry) (es@ [(Node (sourcenode ax),kind ax,Node Exit)]) (Node Exit)\"\n          by -(rule CFG.path_Append[OF CFG])\n        with edge have \"CFG.path src trg\n          (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n          NewEntry ((NewEntry,(\\<lambda>s. True)\\<^sub>\\<surd>,Node Entry)#\n                      (es@ [(Node (sourcenode ax),kind ax,Node Exit)])) (Node Exit)\"\n          by(fastforce intro:CFG.Cons_path[OF CFG])\n        with Node Exit show ?thesis by fastforce\n      next\n        case inner\n        from `valid_node m` obtain as where \"Entry -as\\<rightarrow>* m\"\n          by(fastforce dest:Entry_path)\n        with inner have \"\\<exists>es. CFG.path src trg\n          (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n          (Node Entry) es (Node m)\"\n        proof(induct arbitrary:m rule:rev_induct)\n          case Nil\n          from `Entry -[]\\<rightarrow>* m`\n          have \"m = Entry\" by fastforce\n          with lve_Entry_edge have \"CFG.path src trg\n            (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n            (Node Entry) [] (Node m)\"\n            by(fastforce intro:CFG.empty_path[OF CFG] simp:CFG.valid_node_def[OF CFG])\n          thus ?case by blast\n        next\n          case (snoc x xs)\n          note IH = `\\<And>m. \\<lbrakk>inner_node m; Entry -xs\\<rightarrow>* m\\<rbrakk>\n            \\<Longrightarrow> \\<exists>es. CFG.path src trg\n            (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n            (Node Entry) es (Node m)`\n          from `Entry -xs@[x]\\<rightarrow>* m` have \"Entry -xs\\<rightarrow>* sourcenode x\"\n            and \"valid_edge x\" and \"m = targetnode x\" by(auto elim:path_split_snoc)\n          with `inner_node m`\n          have edge:\"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\n            (Node (sourcenode x),kind x,Node m)\"\n            by(fastforce intro:lve_edge simp:inner_node_def)\n          hence path:\"CFG.path src trg\n            (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n            (Node (sourcenode x)) [(Node (sourcenode x),kind x,Node m)] (Node m)\"\n            by(fastforce intro:CFG.Cons_path[OF CFG] CFG.empty_path[OF CFG]\n                         simp:CFG.valid_node_def[OF CFG])\n          from `valid_edge x` have \"valid_node (sourcenode x)\" by simp\n          thus ?case\n          proof(cases \"sourcenode x\" rule:valid_node_cases)\n            case Entry\n            with edge have \"CFG.path src trg\n              (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n              (Node Entry) [(Node Entry,kind x,Node m)] (Node m)\"\n              apply - apply(rule CFG.Cons_path[OF CFG])\n              apply(rule CFG.empty_path[OF CFG]) \n              by(auto simp:CFG.valid_node_def[OF CFG])\n            thus ?thesis by blast\n          next\n            case Exit\n            with `valid_edge x` have False by(rule Exit_source)\n            thus ?thesis by simp\n          next\n            case inner\n            from IH[OF this `Entry -xs\\<rightarrow>* sourcenode x`] obtain es \n              where \"CFG.path src trg\n              (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n              (Node Entry) es (Node (sourcenode x))\" by blast\n            with path have \"CFG.path src trg\n              (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n              (Node Entry) (es@[(Node (sourcenode x),kind x,Node m)]) (Node m)\"\n              by -(rule CFG.path_Append[OF CFG])\n            thus ?thesis by blast\n          qed\n        qed\n        then obtain es where path:\"CFG.path src trg\n          (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n          (Node Entry) es (Node m)\" by blast\n        have \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\n          (NewEntry,(\\<lambda>s. True)\\<^sub>\\<surd>,Node Entry)\" by(fastforce intro:lve_Entry_edge)\n        from this path Node have \"CFG.path src trg\n          (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n          NewEntry ((NewEntry,(\\<lambda>s. True)\\<^sub>\\<surd>,Node Entry)#es) n\"\n          by(fastforce intro:CFG.Cons_path[OF CFG])\n        thus ?thesis by blast\n      qed\n    qed\n  next\n    fix n assume \"CFG.valid_node src trg\n      (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) n\"\n    show \"\\<exists>as. CFG.path src trg\n      (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n      n as NewExit\"\n    proof(cases n)\n      case NewEntry\n      have \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\n        (NewEntry,(\\<lambda>s. False)\\<^sub>\\<surd>,NewExit)\" by(fastforce intro:lve_Entry_Exit_edge)\n      with NewEntry have \"CFG.path src trg\n        (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n        n [(NewEntry,(\\<lambda>s. False)\\<^sub>\\<surd>,NewExit)] NewExit\"\n        by(fastforce intro:CFG.Cons_path[OF CFG] CFG.empty_path[OF CFG]\n                     simp:CFG.valid_node_def[OF CFG])\n      thus ?thesis by blast\n    next\n      case NewExit\n      have \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\n        (NewEntry,(\\<lambda>s. False)\\<^sub>\\<surd>,NewExit)\" by(fastforce intro:lve_Entry_Exit_edge)\n      with NewExit have \"CFG.path src trg\n        (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n        n [] NewExit\"\n        by(fastforce intro:CFG.empty_path[OF CFG] simp:CFG.valid_node_def[OF CFG])\n      thus ?thesis by blast\n    next\n      case (Node m)\n      with Entry_Exit_edge `CFG.valid_node src trg\n        (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) n`\n      have \"valid_node m\" \n        by(auto elim:lift_valid_edge.cases \n                simp:CFG.valid_node_def[OF CFG] valid_node_def)\n      thus ?thesis\n      proof(cases m rule:valid_node_cases)\n        case Entry\n        from inner obtain ax where \"valid_edge ax\" and \"inner_node (targetnode ax)\"\n          and \"sourcenode ax = Entry\" by(erule inner_node_Entry_edge)\n        hence edge:\"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\n          (Node Entry,kind ax,Node (targetnode ax))\"\n          by(auto intro:lift_valid_edge.lve_edge simp:inner_node_def)\n        have \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\n          (Node Exit,(\\<lambda>s. True)\\<^sub>\\<surd>,NewExit)\" by(fastforce intro:lve_Exit_edge)\n        hence path:\"CFG.path src trg\n          (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n          (Node Exit) [(Node Exit,(\\<lambda>s. True)\\<^sub>\\<surd>,NewExit)] (NewExit)\"\n          by(fastforce intro:CFG.Cons_path[OF CFG] CFG.empty_path[OF CFG]\n                       simp:CFG.valid_node_def[OF CFG])\n        from `inner_node (targetnode ax)` have \"valid_node (targetnode ax)\"\n          by(rule inner_is_valid)\n        then obtain asx where \"targetnode ax -asx\\<rightarrow>* Exit\" by(fastforce dest:Exit_path)\n        from this `valid_edge ax` have \"\\<exists>es. CFG.path src trg\n          (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n          (Node (targetnode ax)) es (Node Exit)\"\n        proof(induct asx arbitrary:ax)\n          case Nil\n          from `targetnode ax -[]\\<rightarrow>* Exit` have \"targetnode ax = Exit\" by fastforce\n          hence \"CFG.path src trg\n            (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n            (Node (targetnode ax)) [] (Node Exit)\"\n            apply simp apply(rule CFG.empty_path[OF CFG])\n            by(auto intro:lve_Exit_edge simp:CFG.valid_node_def[OF CFG])\n          thus ?case by blast\n        next\n          case (Cons x xs)\n          note IH = `\\<And>ax. \\<lbrakk>targetnode ax -xs\\<rightarrow>* Exit; valid_edge ax\\<rbrakk> \\<Longrightarrow>\n            \\<exists>es. CFG.path src trg\n            (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n            (Node (targetnode ax)) es (Node Exit)`\n          from `targetnode ax -x#xs\\<rightarrow>* Exit`\n          have \"targetnode x -xs\\<rightarrow>* Exit\" and \"valid_edge x\"\n            and \"sourcenode x = targetnode ax\" by(auto elim:path_split_Cons)\n          { assume \"sourcenode x = Entry\"\n            with `valid_edge ax` `sourcenode x = targetnode ax`\n            have False by -(rule Entry_target,simp+) }\n          hence \"sourcenode x \\<noteq> Entry\" by clarsimp\n          with `valid_edge x` `sourcenode x = targetnode ax`[THEN sym]\n          have edge:\"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\n            (Node (targetnode ax),kind x,Node (targetnode x))\"\n            by(fastforce intro:lift_valid_edge.lve_edge)\n          from IH[OF `targetnode x -xs\\<rightarrow>* Exit` `valid_edge x`] obtain es\n            where \"CFG.path src trg\n            (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n            (Node (targetnode x)) es (Node Exit)\" by blast\n          with edge have \"CFG.path src trg\n            (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n            (Node (targetnode ax)) \n            ((Node (targetnode ax),kind x,Node (targetnode x))#es) (Node Exit)\"\n            by(fastforce intro:CFG.Cons_path[OF CFG])\n          thus ?case by blast\n        qed\n        then obtain es where \"CFG.path src trg\n          (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n          (Node (targetnode ax)) es (Node Exit)\" by blast\n        with edge have \"CFG.path src trg\n          (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n          (Node Entry) ((Node Entry, kind ax, Node (targetnode ax))#es) (Node Exit)\"\n          by(fastforce intro:CFG.Cons_path[OF CFG])\n        with path have \"CFG.path src trg\n          (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n          (Node Entry) (((Node Entry,kind ax,Node (targetnode ax))#es)@\n                        [(Node Exit, (\\<lambda>s. True)\\<^sub>\\<surd>, NewExit)]) NewExit\"\n          by -(rule CFG.path_Append[OF CFG])\n        with Node Entry show ?thesis by fastforce\n      next\n        case Exit\n        have \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\n          (Node Exit,(\\<lambda>s. True)\\<^sub>\\<surd>,NewExit)\" by(fastforce intro:lve_Exit_edge)\n        with Exit Node have \"CFG.path src trg\n          (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n          n [(Node Exit,(\\<lambda>s. True)\\<^sub>\\<surd>,NewExit)] NewExit\"\n          by(fastforce intro:CFG.Cons_path[OF CFG] CFG.empty_path[OF CFG]\n                       simp:CFG.valid_node_def[OF CFG])\n        thus ?thesis by blast\n      next\n        case inner\n        from `valid_node m` obtain as where \"m -as\\<rightarrow>* Exit\"\n          by(fastforce dest:Exit_path)\n        with inner have \"\\<exists>es. CFG.path src trg\n          (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n          (Node m) es (Node Exit)\"\n        proof(induct as arbitrary:m)\n          case Nil\n          from `m -[]\\<rightarrow>* Exit`\n          have \"m = Exit\" by fastforce\n          with lve_Exit_edge have \"CFG.path src trg\n            (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n            (Node m) [] (Node Exit)\"\n            by(fastforce intro:CFG.empty_path[OF CFG] simp:CFG.valid_node_def[OF CFG])\n          thus ?case by blast\n        next\n          case (Cons x xs)\n          note IH = `\\<And>m. \\<lbrakk>inner_node m; m -xs\\<rightarrow>* Exit\\<rbrakk>\n            \\<Longrightarrow> \\<exists>es. CFG.path src trg\n            (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n            (Node m) es (Node Exit)`\n          from `m -x#xs\\<rightarrow>* Exit` have \"targetnode x -xs\\<rightarrow>* Exit\"\n            and \"valid_edge x\" and \"m = sourcenode x\" by(auto elim:path_split_Cons)\n          with `inner_node m`\n          have edge:\"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\n            (Node m,kind x,Node (targetnode x))\"\n            by(fastforce intro:lve_edge simp:inner_node_def)\n          from `valid_edge x` have \"valid_node (targetnode x)\" by simp\n          thus ?case\n          proof(cases \"targetnode x\" rule:valid_node_cases)\n            case Entry\n            with `valid_edge x` have False by(rule Entry_target)\n            thus ?thesis by simp\n          next\n            case Exit\n            with edge have \"CFG.path src trg\n              (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n              (Node m) [(Node m,kind x,Node Exit)] (Node Exit)\"\n              apply - apply(rule CFG.Cons_path[OF CFG])\n              apply(rule CFG.empty_path[OF CFG]) \n              by(auto simp:CFG.valid_node_def[OF CFG])\n            thus ?thesis by blast\n          next\n            case inner\n            from IH[OF this `targetnode x -xs\\<rightarrow>* Exit`] obtain es \n              where \"CFG.path src trg\n              (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n              (Node (targetnode x)) es (Node Exit)\" by blast\n            with edge have \"CFG.path src trg\n              (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n              (Node m) ((Node m,kind x,Node (targetnode x))#es) (Node Exit)\"\n              by(fastforce intro:CFG.Cons_path[OF CFG])\n            thus ?thesis by blast\n          qed\n        qed\n        then obtain es where path:\"CFG.path src trg\n          (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n          (Node m) es (Node Exit)\" by blast\n        have \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\n          (Node Exit,(\\<lambda>s. True)\\<^sub>\\<surd>,NewExit)\" by(fastforce intro:lve_Exit_edge)\n        hence \"CFG.path src trg\n          (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n          (Node Exit) [(Node Exit,(\\<lambda>s. True)\\<^sub>\\<surd>,NewExit)] NewExit\"\n          by(fastforce intro:CFG.Cons_path[OF CFG] CFG.empty_path[OF CFG]\n                       simp:CFG.valid_node_def[OF CFG])\n        with path Node have \"CFG.path src trg\n          (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n          n (es@[(Node Exit, (\\<lambda>s. True)\\<^sub>\\<surd>, NewExit)]) NewExit\"\n          by(fastforce intro:CFG.path_Append[OF CFG])\n        thus ?thesis by blast\n      qed\n    qed\n  qed\nqed\n\n\nlemma lift_PDG_scd:\n  assumes PDG:\"PDG sourcenode targetnode kind valid_edge Entry Def Use state_val Exit \n  (Postdomination.standard_control_dependence sourcenode targetnode valid_edge Exit)\"\n  and pd:\"Postdomination sourcenode targetnode kind valid_edge Entry Exit\"\n  and inner:\"CFGExit.inner_node sourcenode targetnode valid_edge Entry Exit nx\"\n  shows \"PDG src trg knd \n  (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewEntry\n  (lift_Def Def Entry Exit H L) (lift_Use Use Entry Exit H L) state_val NewExit\n  (Postdomination.standard_control_dependence src trg \n    (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewExit)\"\nproof -\n  interpret PDG sourcenode targetnode kind valid_edge Entry Def Use state_val Exit\n    \"Postdomination.standard_control_dependence sourcenode targetnode \n                                                           valid_edge Exit\"\n    by(rule PDG)\n  have wf:\"CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use\n                            state_val Exit\" by(unfold_locales)\n  from wf pd inner have pd':\"Postdomination src trg knd\n    (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) \n    NewEntry NewExit\"\n    by(rule lift_Postdomination)\n  from wf have CFG:\"CFG src trg\n    (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewEntry\"\n    by(rule lift_CFG)\n  from wf have CFG_wf:\"CFG_wf src trg knd\n    (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewEntry\n    (lift_Def Def Entry Exit H L) (lift_Use Use Entry Exit H L) state_val\"\n    by(rule lift_CFG_wf)\n  from wf have CFGExit:\"CFGExit src trg knd \n    (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) \n    NewEntry NewExit\"\n    by(rule lift_CFGExit)\n  from wf have CFGExit_wf:\"CFGExit_wf src trg knd \n    (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewEntry\n    (lift_Def Def Entry Exit H L) (lift_Use Use Entry Exit H L) state_val NewExit\"\n    by(rule lift_CFGExit_wf)\n  show ?thesis\n  proof\n    fix a assume \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      and \"trg a = NewEntry\"\n    with CFG show False by(rule CFG.Entry_target)\n  next\n    fix a a' \n    assume \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      and \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a'\"\n      and \"src a = src a'\" and \"trg a = trg a'\"\n    with CFG show \"a = a'\" by(rule CFG.edge_det)\n  next\n    from CFG_wf\n    show \"lift_Def Def Entry Exit H L NewEntry = {} \\<and>\n          lift_Use Use Entry Exit H L NewEntry = {}\"\n      by(rule CFG_wf.Entry_empty)\n  next\n    fix a V s \n    assume \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      and \"V \\<notin> lift_Def Def Entry Exit H L (src a)\" and \"pred (knd a) s\"\n    with CFG_wf show \"state_val (transfer (knd a) s) V = state_val s V\"\n      by(rule CFG_wf.CFG_edge_no_Def_equal)\n  next\n    fix a s s'\n    assume assms:\"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      \"\\<forall>V\\<in>lift_Use Use Entry Exit H L (src a). state_val s V = state_val s' V\"\n      \"pred (knd a) s\" \"pred (knd a) s'\"\n    with CFG_wf show \"\\<forall>V\\<in>lift_Def Def Entry Exit H L (src a).\n             state_val (transfer (knd a) s) V = state_val (transfer (knd a) s') V\"\n      by(rule CFG_wf.CFG_edge_transfer_uses_only_Use)\n  next\n    fix a s s'\n    assume \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      and \"pred (knd a) s\" \n      and \"\\<forall>V\\<in>lift_Use Use Entry Exit H L (src a). state_val s V = state_val s' V\"\n    with CFG_wf show \"pred (knd a) s'\" by(rule CFG_wf.CFG_edge_Uses_pred_equal)\n  next\n    fix a a'\n    assume \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      and \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a'\"\n      and \"src a = src a'\" and \"trg a \\<noteq> trg a'\"\n    with CFG_wf show \"\\<exists>Q Q'. knd a = (Q)\\<^sub>\\<surd> \\<and> knd a' = (Q')\\<^sub>\\<surd> \\<and> \n                             (\\<forall>s. (Q s \\<longrightarrow> \\<not> Q' s) \\<and> (Q' s \\<longrightarrow> \\<not> Q s))\"\n      by(rule CFG_wf.deterministic)\n  next\n    fix a assume \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      and \"src a = NewExit\"\n    with CFGExit show False by(rule CFGExit.Exit_source)\n  next\n    from CFGExit\n    show \"\\<exists>a. lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a \\<and>\n              src a = NewEntry \\<and> trg a = NewExit \\<and> knd a = (\\<lambda>s. False)\\<^sub>\\<surd>\"\n      by(rule CFGExit.Entry_Exit_edge)\n  next\n    from CFGExit_wf\n    show \"lift_Def Def Entry Exit H L NewExit = {} \\<and>\n          lift_Use Use Entry Exit H L NewExit = {}\"\n      by(rule CFGExit_wf.Exit_empty)\n  next\n    fix n n'\n    assume scd:\"Postdomination.standard_control_dependence src trg\n      (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewExit n n'\"\n    show \"n' \\<noteq> NewExit\"\n    proof(rule ccontr)\n      assume \"\\<not> n' \\<noteq> NewExit\"\n      hence \"n' = NewExit\" by simp\n      with scd pd' show False \n        by(fastforce intro:Postdomination.Exit_not_standard_control_dependent)\n    qed\n  next\n    fix n n'\n    assume \"Postdomination.standard_control_dependence src trg\n      (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewExit n n'\"\n    thus \"\\<exists>as. CFG.path src trg\n               (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n               n as n' \\<and> as \\<noteq> []\"\n      by(fastforce simp:Postdomination.standard_control_dependence_def[OF pd'])\n  qed\nqed\n\n\n\n\nlemma lift_PDG_standard_backward_slice:\n  fixes valid_edge and sourcenode and targetnode and kind and Entry and Exit\n  and Def and Use and H and L\n  defines lve:\"lve \\<equiv> lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\"\n  and lDef:\"lDef \\<equiv> lift_Def Def Entry Exit H L\" \n  and lUse:\"lUse \\<equiv> lift_Use Use Entry Exit H L\"\n  assumes PDG:\"PDG sourcenode targetnode kind valid_edge Entry Def Use state_val Exit \n  (Postdomination.standard_control_dependence sourcenode targetnode valid_edge Exit)\"\n  and pd:\"Postdomination sourcenode targetnode kind valid_edge Entry Exit\"\n  and inner:\"CFGExit.inner_node sourcenode targetnode valid_edge Entry Exit nx\"\n  and \"H \\<inter> L = {}\" and \"H \\<union> L = UNIV\"\n  shows \"NonInterferenceIntraGraph src trg knd lve NewEntry lDef lUse state_val \n         (PDG.PDG_BS src trg lve lDef lUse\n           (Postdomination.standard_control_dependence src trg lve NewExit))\n         NewExit H L (Node Entry) (Node Exit)\"\nproof -\n  interpret PDG sourcenode targetnode kind valid_edge Entry Def Use state_val Exit\n    \"Postdomination.standard_control_dependence sourcenode targetnode \n                                                           valid_edge Exit\"\n    by(rule PDG)\n  have wf:\"CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use\n                            state_val Exit\" by(unfold_locales)\n  interpret wf':CFGExit_wf src trg knd lve NewEntry lDef lUse state_val NewExit\n    by(fastforce intro:lift_CFGExit_wf wf simp:lve lDef lUse)\n  from PDG pd inner lve lDef lUse have PDG':\"PDG src trg knd \n    lve NewEntry lDef lUse state_val NewExit\n    (Postdomination.standard_control_dependence src trg lve NewExit)\"\n    by(fastforce intro:lift_PDG_scd)\n  from wf pd inner have pd':\"Postdomination src trg knd\n    (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) \n    NewEntry NewExit\"\n    by(rule lift_Postdomination)\n  from wf lve have CFG:\"CFG src trg lve NewEntry\"\n    by(fastforce intro:lift_CFG)\n  from wf lve lDef lUse \n  have CFG_wf:\"CFG_wf src trg knd lve NewEntry lDef lUse state_val\"\n    by(fastforce intro:lift_CFG_wf)\n  from wf lve have CFGExit:\"CFGExit src trg knd lve NewEntry NewExit\"\n    by(fastforce intro:lift_CFGExit)\n  from wf lve lDef lUse \n  have CFGExit_wf:\"CFGExit_wf src trg knd lve NewEntry lDef lUse state_val NewExit\"\n    by(fastforce intro:lift_CFGExit_wf)\n  show ?thesis\n  proof\n    fix n S\n    assume \"n \\<in> PDG.PDG_BS src trg lve lDef lUse\n      (Postdomination.standard_control_dependence src trg lve NewExit) S\"\n    with PDG' show \"CFG.valid_node src trg lve n\"\n      by(rule PDG.PDG_BS_valid_node)\n  next\n    fix n S assume \"CFG.valid_node src trg lve n\" and \"n \\<in> S\"\n    thus \"n \\<in> PDG.PDG_BS src trg lve lDef lUse\n      (Postdomination.standard_control_dependence src trg lve NewExit) S\"\n      by(fastforce intro:PDG.PDG_path_Nil[OF PDG'] simp:PDG.PDG_BS_def[OF PDG'])\n  next\n    fix n' S n V\n    assume \"n' \\<in> PDG.PDG_BS src trg lve lDef lUse\n      (Postdomination.standard_control_dependence src trg lve NewExit) S\"\n      and \"CFG_wf.data_dependence src trg lve lDef lUse n V n'\"\n    thus \"n \\<in> PDG.PDG_BS src trg lve lDef lUse\n      (Postdomination.standard_control_dependence src trg lve NewExit) S\"\n      by(fastforce intro:PDG.PDG_path_Append[OF PDG'] PDG.PDG_path_ddep[OF PDG']\n                        PDG.PDG_ddep_edge[OF PDG'] simp:PDG.PDG_BS_def[OF PDG']\n                  split:split_if_asm)\n  next\n    fix n S\n    interpret PDGx:PDG src trg knd lve NewEntry lDef lUse state_val NewExit\n      \"Postdomination.standard_control_dependence src trg lve NewExit\"\n      by(rule PDG')\n    interpret pdx:Postdomination src trg knd lve NewEntry NewExit\n      by(fastforce intro:pd' simp:lve)\n    have scd:\"StandardControlDependencePDG src trg knd lve NewEntry\n      lDef lUse state_val NewExit\" by(unfold_locales)\n    from StandardControlDependencePDG.obs_singleton[OF scd]\n    have \"(\\<exists>m. CFG.obs src trg lve n\n      (PDG.PDG_BS src trg lve lDef lUse\n        (Postdomination.standard_control_dependence src trg lve NewExit) S) = {m}) \\<or>\n      CFG.obs src trg lve n\n      (PDG.PDG_BS src trg lve lDef lUse\n        (Postdomination.standard_control_dependence src trg lve NewExit) S) = {}\"\n      by(fastforce simp:StandardControlDependencePDG.PDG_BS_s_def[OF scd])\n    thus \"finite (CFG.obs src trg lve n\n        (PDG.PDG_BS src trg lve lDef lUse\n          (Postdomination.standard_control_dependence src trg lve NewExit) S))\"\n      by fastforce\n  next\n    fix n S\n    interpret PDGx:PDG src trg knd lve NewEntry lDef lUse state_val NewExit\n      \"Postdomination.standard_control_dependence src trg lve NewExit\"\n      by(rule PDG')\n    interpret pdx:Postdomination src trg knd lve NewEntry NewExit\n      by(fastforce intro:pd' simp:lve)\n    have scd:\"StandardControlDependencePDG src trg knd lve NewEntry\n      lDef lUse state_val NewExit\" by(unfold_locales)\n    from StandardControlDependencePDG.obs_singleton[OF scd]\n    have \"(\\<exists>m. CFG.obs src trg lve n\n      (PDG.PDG_BS src trg lve lDef lUse\n        (Postdomination.standard_control_dependence src trg lve NewExit) S) = {m}) \\<or>\n      CFG.obs src trg lve n\n      (PDG.PDG_BS src trg lve lDef lUse\n        (Postdomination.standard_control_dependence src trg lve NewExit) S) = {}\"\n      by(fastforce simp:StandardControlDependencePDG.PDG_BS_s_def[OF scd])\n    thus \"card (CFG.obs src trg lve n\n      (PDG.PDG_BS src trg lve lDef lUse\n        (Postdomination.standard_control_dependence src trg lve NewExit) S)) \\<le> 1\"\n      by fastforce\n  next\n    fix a assume \"lve a\" and \"src a = NewEntry\"\n    with lve show \"trg a = NewExit \\<or> trg a = Node Entry\"\n      by(fastforce elim:lift_valid_edge.cases)\n  next\n    from lve_Entry_edge lve\n    show \"\\<exists>a. lve a \\<and> src a = NewEntry \\<and> trg a = Node Entry \\<and> knd a = (\\<lambda>s. True)\\<^sub>\\<surd>\"\n      by(fastforce simp:knd_def)\n  next\n    fix a assume \"lve a\" and \"trg a = Node Entry\"\n    with lve show \"src a = NewEntry\" by(fastforce elim:lift_valid_edge.cases)\n  next\n    fix a assume \"lve a\" and \"trg a = NewExit\"\n    with lve show \"src a = NewEntry \\<or> src a = Node Exit\"\n      by(fastforce elim:lift_valid_edge.cases)\n  next\n    from lve_Exit_edge lve\n    show \"\\<exists>a. lve a \\<and> src a = Node Exit \\<and> trg a = NewExit \\<and> knd a = (\\<lambda>s. True)\\<^sub>\\<surd>\"\n      by(fastforce simp:knd_def)\n  next\n    fix a assume \"lve a\" and \"src a = Node Exit\"\n    with lve show \"trg a = NewExit\" by(fastforce elim:lift_valid_edge.cases)\n  next\n    from lDef show \"lDef (Node Entry) = H\"\n      by(fastforce elim:lift_Def_set.cases intro:lift_Def_High)\n  next\n    from Entry_noteq_Exit lUse show \"lUse (Node Entry) = H\"\n      by(fastforce elim:lift_Use_set.cases intro:lift_Use_High)\n  next\n    from Entry_noteq_Exit lUse show \"lUse (Node Exit) = L\"\n      by(fastforce elim:lift_Use_set.cases intro:lift_Use_Low)\n  next\n    from `H \\<inter> L = {}` show \"H \\<inter> L = {}\" .\n  next\n    from `H \\<union> L = UNIV` show \"H \\<union> L = UNIV\" .\n  qed\nqed\n\n\n\nsubsubsection {* Lifting @{text PDG_BS} with @{text weak_control_dependence} *}\n\nlemma lift_StrongPostdomination:\n  assumes wf:\"CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use\n                         state_val Exit\"\n  and spd:\"StrongPostdomination sourcenode targetnode kind valid_edge Entry Exit\"\n  and inner:\"CFGExit.inner_node sourcenode targetnode valid_edge Entry Exit nx\"\n  shows \"StrongPostdomination src trg knd\n  (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewEntry NewExit\"\nproof -\n  interpret StrongPostdomination sourcenode targetnode kind valid_edge Entry Exit\n    by(rule spd)\n  have pd:\"Postdomination sourcenode targetnode kind valid_edge Entry Exit\"\n    by(unfold_locales)\n  interpret pd':Postdomination src trg knd\n    \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\"\n    NewEntry NewExit\n    by(fastforce intro:wf inner lift_Postdomination pd)\n  interpret CFGExit_wf:CFGExit_wf src trg knd\n    \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\" NewEntry\n    \"lift_Def Def Entry Exit H L\" \"lift_Use Use Entry Exit H L\" state_val NewExit\n    by(fastforce intro:lift_CFGExit_wf wf)\n  from wf have CFG:\"CFG src trg\n    (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewEntry\"\n    by(rule lift_CFG)\n  show ?thesis\n  proof\n    fix n assume \"CFG.valid_node src trg\n      (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) n\"\n    show \"finite\n      {n'. \\<exists>a'. lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a' \\<and>\n                src a' = n \\<and> trg a' = n'}\"\n    proof(cases n)\n      case NewEntry\n      hence \"{n'. \\<exists>a'. lift_valid_edge valid_edge sourcenode targetnode kind \n                     Entry Exit a' \\<and> src a' = n \\<and> trg a' = n'} = {NewExit,Node Entry}\"\n        by(auto elim:lift_valid_edge.cases intro:lift_valid_edge.intros)\n      thus ?thesis by simp\n    next\n      case NewExit\n      hence \"{n'. \\<exists>a'. lift_valid_edge valid_edge sourcenode targetnode kind \n                     Entry Exit a' \\<and> src a' = n \\<and> trg a' = n'} = {}\"\n        by fastforce\n      thus ?thesis by simp\n    next\n      case (Node m)\n      with Entry_Exit_edge `CFG.valid_node src trg\n        (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) n`\n      have \"valid_node m\" \n        by(auto elim:lift_valid_edge.cases \n                simp:CFG.valid_node_def[OF CFG] valid_node_def)\n      hence \"finite {m'. \\<exists>a'. valid_edge a' \\<and> sourcenode a' = m \\<and> targetnode a' = m'}\"\n        by(rule successor_set_finite)\n      have \"{m'. \\<exists>a'. lift_valid_edge valid_edge sourcenode targetnode kind \n                      Entry Exit a' \\<and> src a' = Node m \\<and> trg a' = Node m'} \\<subseteq> \n            {m'. \\<exists>a'. valid_edge a' \\<and> sourcenode a' = m \\<and> targetnode a' = m'}\"\n        by(fastforce elim:lift_valid_edge.cases)\n      with `finite {m'. \\<exists>a'. valid_edge a' \\<and> sourcenode a' = m \\<and> targetnode a' = m'}`\n      have \"finite {m'. \\<exists>a'. lift_valid_edge valid_edge sourcenode targetnode kind \n                             Entry Exit a' \\<and> src a' = Node m \\<and> trg a' = Node m'}\"\n        by -(rule finite_subset)\n      hence \"finite (Node ` {m'. \\<exists>a'. lift_valid_edge valid_edge sourcenode \n        targetnode kind Entry Exit a' \\<and> src a' = Node m \\<and> trg a' = Node m'})\"\n        by fastforce\n      hence fin:\"finite ((Node ` {m'. \\<exists>a'. lift_valid_edge valid_edge sourcenode \n        targetnode kind Entry Exit a' \\<and> src a' = Node m \\<and> trg a' = Node m'}) \\<union>\n        {NewEntry,NewExit})\" by fastforce\n      with Node have \"{n'. \\<exists>a'. lift_valid_edge valid_edge sourcenode targetnode kind \n        Entry Exit a' \\<and> src a' = n \\<and> trg a' = n'} \\<subseteq>\n        (Node ` {m'. \\<exists>a'. lift_valid_edge valid_edge sourcenode \n        targetnode kind Entry Exit a' \\<and> src a' = Node m \\<and> trg a' = Node m'}) \\<union>\n        {NewEntry,NewExit}\" by auto (case_tac x,auto)\n      with fin show ?thesis by -(rule finite_subset)\n    qed\n  qed\nqed\n\n\n\n\n\nlemma lift_PDG_wcd:\n  assumes PDG:\"PDG sourcenode targetnode kind valid_edge Entry Def Use state_val Exit \n  (StrongPostdomination.weak_control_dependence sourcenode targetnode \n  valid_edge Exit)\"\n  and spd:\"StrongPostdomination sourcenode targetnode kind valid_edge Entry Exit\"\n  and inner:\"CFGExit.inner_node sourcenode targetnode valid_edge Entry Exit nx\"\n  shows \"PDG src trg knd \n  (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewEntry\n  (lift_Def Def Entry Exit H L) (lift_Use Use Entry Exit H L) state_val NewExit\n  (StrongPostdomination.weak_control_dependence src trg \n    (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewExit)\"\nproof -\n  interpret PDG sourcenode targetnode kind valid_edge Entry Def Use state_val Exit\n    \"StrongPostdomination.weak_control_dependence sourcenode targetnode \n                                                           valid_edge Exit\"\n    by(rule PDG)\n  have wf:\"CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use\n                            state_val Exit\" by(unfold_locales)\n  from wf spd inner have spd':\"StrongPostdomination src trg knd\n    (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) \n    NewEntry NewExit\"\n    by(rule lift_StrongPostdomination)\n  from wf have CFG:\"CFG src trg\n    (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewEntry\"\n    by(rule lift_CFG)\n  from wf have CFG_wf:\"CFG_wf src trg knd\n    (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewEntry\n    (lift_Def Def Entry Exit H L) (lift_Use Use Entry Exit H L) state_val\"\n    by(rule lift_CFG_wf)\n  from wf have CFGExit:\"CFGExit src trg knd \n    (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) \n    NewEntry NewExit\"\n    by(rule lift_CFGExit)\n  from wf have CFGExit_wf:\"CFGExit_wf src trg knd \n    (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewEntry\n    (lift_Def Def Entry Exit H L) (lift_Use Use Entry Exit H L) state_val NewExit\"\n    by(rule lift_CFGExit_wf)\n  show ?thesis\n  proof\n    fix a assume \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      and \"trg a = NewEntry\"\n    with CFG show False by(rule CFG.Entry_target)\n  next\n    fix a a' \n    assume \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      and \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a'\"\n      and \"src a = src a'\" and \"trg a = trg a'\"\n    with CFG show \"a = a'\" by(rule CFG.edge_det)\n  next\n    from CFG_wf\n    show \"lift_Def Def Entry Exit H L NewEntry = {} \\<and>\n          lift_Use Use Entry Exit H L NewEntry = {}\"\n      by(rule CFG_wf.Entry_empty)\n  next\n    fix a V s \n    assume \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      and \"V \\<notin> lift_Def Def Entry Exit H L (src a)\" and \"pred (knd a) s\"\n    with CFG_wf show \"state_val (transfer (knd a) s) V = state_val s V\"\n      by(rule CFG_wf.CFG_edge_no_Def_equal)\n  next\n    fix a s s'\n    assume assms:\"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      \"\\<forall>V\\<in>lift_Use Use Entry Exit H L (src a). state_val s V = state_val s' V\"\n      \"pred (knd a) s\" \"pred (knd a) s'\"\n    with CFG_wf show \"\\<forall>V\\<in>lift_Def Def Entry Exit H L (src a).\n             state_val (transfer (knd a) s) V = state_val (transfer (knd a) s') V\"\n      by(rule CFG_wf.CFG_edge_transfer_uses_only_Use)\n  next\n    fix a s s'\n    assume \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      and \"pred (knd a) s\" \n      and \"\\<forall>V\\<in>lift_Use Use Entry Exit H L (src a). state_val s V = state_val s' V\"\n    with CFG_wf show \"pred (knd a) s'\" by(rule CFG_wf.CFG_edge_Uses_pred_equal)\n  next\n    fix a a'\n    assume \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      and \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a'\"\n      and \"src a = src a'\" and \"trg a \\<noteq> trg a'\"\n    with CFG_wf show \"\\<exists>Q Q'. knd a = (Q)\\<^sub>\\<surd> \\<and> knd a' = (Q')\\<^sub>\\<surd> \\<and> \n                             (\\<forall>s. (Q s \\<longrightarrow> \\<not> Q' s) \\<and> (Q' s \\<longrightarrow> \\<not> Q s))\"\n      by(rule CFG_wf.deterministic)\n  next\n    fix a assume \"lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a\"\n      and \"src a = NewExit\"\n    with CFGExit show False by(rule CFGExit.Exit_source)\n  next\n    from CFGExit\n    show \"\\<exists>a. lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit a \\<and>\n              src a = NewEntry \\<and> trg a = NewExit \\<and> knd a = (\\<lambda>s. False)\\<^sub>\\<surd>\"\n      by(rule CFGExit.Entry_Exit_edge)\n  next\n    from CFGExit_wf\n    show \"lift_Def Def Entry Exit H L NewExit = {} \\<and>\n          lift_Use Use Entry Exit H L NewExit = {}\"\n      by(rule CFGExit_wf.Exit_empty)\n  next\n    fix n n'\n    assume wcd:\"StrongPostdomination.weak_control_dependence src trg\n      (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewExit n n'\"\n    show \"n' \\<noteq> NewExit\"\n    proof(rule ccontr)\n      assume \"\\<not> n' \\<noteq> NewExit\"\n      hence \"n' = NewExit\" by simp\n      with wcd spd' show False \n        by(fastforce intro:StrongPostdomination.Exit_not_weak_control_dependent)\n    qed\n  next\n    fix n n'\n    assume \"StrongPostdomination.weak_control_dependence src trg\n      (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) NewExit n n'\"\n    thus \"\\<exists>as. CFG.path src trg\n               (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit)\n               n as n' \\<and> as \\<noteq> []\"\n      by(fastforce simp:StrongPostdomination.weak_control_dependence_def[OF spd'])\n  qed\nqed\n\n\n\n\nlemma lift_PDG_weak_backward_slice:\n  fixes valid_edge and sourcenode and targetnode and kind and Entry and Exit\n  and Def and Use and H and L\n  defines lve:\"lve \\<equiv> lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit\"\n  and lDef:\"lDef \\<equiv> lift_Def Def Entry Exit H L\" \n  and lUse:\"lUse \\<equiv> lift_Use Use Entry Exit H L\"\n  assumes PDG:\"PDG sourcenode targetnode kind valid_edge Entry Def Use state_val Exit \n  (StrongPostdomination.weak_control_dependence sourcenode targetnode \n  valid_edge Exit)\"\n  and spd:\"StrongPostdomination sourcenode targetnode kind valid_edge Entry Exit\"\n  and inner:\"CFGExit.inner_node sourcenode targetnode valid_edge Entry Exit nx\"\n  and \"H \\<inter> L = {}\" and \"H \\<union> L = UNIV\"\n  shows \"NonInterferenceIntraGraph src trg knd lve NewEntry lDef lUse state_val \n         (PDG.PDG_BS src trg lve lDef lUse\n           (StrongPostdomination.weak_control_dependence src trg lve NewExit))\n         NewExit H L (Node Entry) (Node Exit)\"\nproof -\n  interpret PDG sourcenode targetnode kind valid_edge Entry Def Use state_val Exit\n    \"StrongPostdomination.weak_control_dependence sourcenode targetnode \n                                                           valid_edge Exit\"\n    by(rule PDG)\n  have wf:\"CFGExit_wf sourcenode targetnode kind valid_edge Entry Def Use\n                            state_val Exit\" by(unfold_locales)\n  interpret wf':CFGExit_wf src trg knd lve NewEntry lDef lUse state_val NewExit\n    by(fastforce intro:lift_CFGExit_wf wf simp:lve lDef lUse)\n  from PDG spd inner lve lDef lUse have PDG':\"PDG src trg knd \n    lve NewEntry lDef lUse state_val NewExit\n    (StrongPostdomination.weak_control_dependence src trg lve NewExit)\"\n    by(fastforce intro:lift_PDG_wcd)\n  from wf spd inner have spd':\"StrongPostdomination src trg knd\n    (lift_valid_edge valid_edge sourcenode targetnode kind Entry Exit) \n    NewEntry NewExit\"\n    by(rule lift_StrongPostdomination)\n  from wf lve have CFG:\"CFG src trg lve NewEntry\"\n    by(fastforce intro:lift_CFG)\n  from wf lve lDef lUse \n  have CFG_wf:\"CFG_wf src trg knd lve NewEntry lDef lUse state_val\"\n    by(fastforce intro:lift_CFG_wf)\n  from wf lve have CFGExit:\"CFGExit src trg knd lve NewEntry NewExit\"\n    by(fastforce intro:lift_CFGExit)\n  from wf lve lDef lUse \n  have CFGExit_wf:\"CFGExit_wf src trg knd lve NewEntry lDef lUse state_val NewExit\"\n    by(fastforce intro:lift_CFGExit_wf)\n  show ?thesis\n  proof\n    fix n S\n    assume \"n \\<in> PDG.PDG_BS src trg lve lDef lUse\n      (StrongPostdomination.weak_control_dependence src trg lve NewExit) S\"\n    with PDG' show \"CFG.valid_node src trg lve n\"\n      by(rule PDG.PDG_BS_valid_node)\n  next\n    fix n S assume \"CFG.valid_node src trg lve n\" and \"n \\<in> S\"\n    thus \"n \\<in> PDG.PDG_BS src trg lve lDef lUse\n      (StrongPostdomination.weak_control_dependence src trg lve NewExit) S\"\n      by(fastforce intro:PDG.PDG_path_Nil[OF PDG'] simp:PDG.PDG_BS_def[OF PDG'])\n  next\n    fix n' S n V\n    assume \"n' \\<in> PDG.PDG_BS src trg lve lDef lUse\n      (StrongPostdomination.weak_control_dependence src trg lve NewExit) S\"\n      and \"CFG_wf.data_dependence src trg lve lDef lUse n V n'\"\n    thus \"n \\<in> PDG.PDG_BS src trg lve lDef lUse\n      (StrongPostdomination.weak_control_dependence src trg lve NewExit) S\"\n      by(fastforce intro:PDG.PDG_path_Append[OF PDG'] PDG.PDG_path_ddep[OF PDG']\n                        PDG.PDG_ddep_edge[OF PDG'] simp:PDG.PDG_BS_def[OF PDG']\n                  split:split_if_asm)\n  next\n    fix n S\n    interpret PDGx:PDG src trg knd lve NewEntry lDef lUse state_val NewExit\n      \"StrongPostdomination.weak_control_dependence src trg lve NewExit\"\n      by(rule PDG')\n    interpret spdx:StrongPostdomination src trg knd lve NewEntry NewExit\n      by(fastforce intro:spd' simp:lve)\n    have wcd:\"WeakControlDependencePDG src trg knd lve NewEntry\n      lDef lUse state_val NewExit\" by(unfold_locales)\n    from WeakControlDependencePDG.obs_singleton[OF wcd]\n    have \"(\\<exists>m. CFG.obs src trg lve n\n      (PDG.PDG_BS src trg lve lDef lUse\n       (StrongPostdomination.weak_control_dependence src trg lve NewExit) S) = {m}) \\<or>\n      CFG.obs src trg lve n\n      (PDG.PDG_BS src trg lve lDef lUse\n        (StrongPostdomination.weak_control_dependence src trg lve NewExit) S) = {}\"\n      by(fastforce simp:WeakControlDependencePDG.PDG_BS_w_def[OF wcd])\n    thus \"finite (CFG.obs src trg lve n\n        (PDG.PDG_BS src trg lve lDef lUse\n          (StrongPostdomination.weak_control_dependence src trg lve NewExit) S))\"\n      by fastforce\n  next\n    fix n S\n    interpret PDGx:PDG src trg knd lve NewEntry lDef lUse state_val NewExit\n      \"StrongPostdomination.weak_control_dependence src trg lve NewExit\"\n      by(rule PDG')\n    interpret spdx:StrongPostdomination src trg knd lve NewEntry NewExit\n      by(fastforce intro:spd' simp:lve)\n    have wcd:\"WeakControlDependencePDG src trg knd lve NewEntry\n      lDef lUse state_val NewExit\" by(unfold_locales)\n    from WeakControlDependencePDG.obs_singleton[OF wcd]\n    have \"(\\<exists>m. CFG.obs src trg lve n\n      (PDG.PDG_BS src trg lve lDef lUse\n       (StrongPostdomination.weak_control_dependence src trg lve NewExit) S) = {m}) \\<or>\n      CFG.obs src trg lve n\n      (PDG.PDG_BS src trg lve lDef lUse\n        (StrongPostdomination.weak_control_dependence src trg lve NewExit) S) = {}\"\n      by(fastforce simp:WeakControlDependencePDG.PDG_BS_w_def[OF wcd])\n    thus \"card (CFG.obs src trg lve n\n      (PDG.PDG_BS src trg lve lDef lUse\n        (StrongPostdomination.weak_control_dependence src trg lve NewExit) S)) \\<le> 1\"\n      by fastforce\n  next\n    fix a assume \"lve a\" and \"src a = NewEntry\"\n    with lve show \"trg a = NewExit \\<or> trg a = Node Entry\"\n      by(fastforce elim:lift_valid_edge.cases)\n  next\n    from lve_Entry_edge lve\n    show \"\\<exists>a. lve a \\<and> src a = NewEntry \\<and> trg a = Node Entry \\<and> knd a = (\\<lambda>s. True)\\<^sub>\\<surd>\"\n      by(fastforce simp:knd_def)\n  next\n    fix a assume \"lve a\" and \"trg a = Node Entry\"\n    with lve show \"src a = NewEntry\" by(fastforce elim:lift_valid_edge.cases)\n  next\n    fix a assume \"lve a\" and \"trg a = NewExit\"\n    with lve show \"src a = NewEntry \\<or> src a = Node Exit\"\n      by(fastforce elim:lift_valid_edge.cases)\n  next\n    from lve_Exit_edge lve\n    show \"\\<exists>a. lve a \\<and> src a = Node Exit \\<and> trg a = NewExit \\<and> knd a = (\\<lambda>s. True)\\<^sub>\\<surd>\"\n      by(fastforce simp:knd_def)\n  next\n    fix a assume \"lve a\" and \"src a = Node Exit\"\n    with lve show \"trg a = NewExit\" by(fastforce elim:lift_valid_edge.cases)\n  next\n    from lDef show \"lDef (Node Entry) = H\"\n      by(fastforce elim:lift_Def_set.cases intro:lift_Def_High)\n  next\n    from Entry_noteq_Exit lUse show \"lUse (Node Entry) = H\"\n      by(fastforce elim:lift_Use_set.cases intro:lift_Use_High)\n  next\n    from Entry_noteq_Exit lUse show \"lUse (Node Exit) = L\"\n      by(fastforce elim:lift_Use_set.cases intro:lift_Use_Low)\n  next\n    from `H \\<inter> L = {}` show \"H \\<inter> L = {}\" .\n  next\n    from `H \\<union> L = UNIV` show \"H \\<union> L = UNIV\" .\n  qed\nqed\n\n\nend\n\n\n\n\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/InformationFlowSlicing/LiftingIntra.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.4882833952958347, "lm_q1q2_score": 0.2631765570048666}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory BCorres_UL\nimports\n  \"Monad_WP/NonDetMonadVCG\"\n  Crunch_Instances_NonDet\nbegin\n\ndefinition s_bcorres_underlying where\n  \"s_bcorres_underlying t f g s \\<equiv> (\\<lambda>(x,y). (x, t y)) ` (fst (f s)) \\<subseteq> (fst (g (t s)))\"\n\ndefinition bcorres_underlying where\n  \"bcorres_underlying t f g \\<equiv> \\<forall>s. s_bcorres_underlying t f g s\"\n\nlemma wpc_helper_bcorres:\n  \"bcorres_underlying t f g \\<Longrightarrow>  wpc_helper (P, P') (Q, Q') (bcorres_underlying t f g)\"\n  by (simp add: wpc_helper_def)\n\nlemma wpc_helper_s_bcorres:\n  \"s_bcorres_underlying t f g s \\<Longrightarrow>  wpc_helper (P, P') (Q, Q') (s_bcorres_underlying t f g s)\"\n  by (simp add: wpc_helper_def)\n\nwpc_setup \"\\<lambda>f. bcorres_underlying t f g\" wpc_helper_bcorres\nwpc_setup \"\\<lambda>f. s_bcorres_underlying t f g s\" wpc_helper_bcorres\n\nlemma s_bcorres_underlying_split[wp_split]:\n  \"(\\<And>r s'. (r,s') \\<in> fst (f s) \\<Longrightarrow>  (s_bcorres_underlying t (g r) (g' r) s')) \\<Longrightarrow>\n   s_bcorres_underlying t f f' s \\<Longrightarrow>\n   s_bcorres_underlying t (f >>= g) (f' >>= g') s\"\n  by (clarsimp simp: s_bcorres_underlying_def bind_def) force\n\nlemma bcorres_underlying_split[wp_split]:\n  \"(\\<And>r. (bcorres_underlying t (g r) (g' r))) \\<Longrightarrow>\n   bcorres_underlying t f f' \\<Longrightarrow>\n   bcorres_underlying t (f >>= g) (f' >>= g')\"\n  by (simp add: bcorres_underlying_def s_bcorres_underlying_split)\n\nlemma get_s_bcorres_underlying[wp]:\n  \"s_bcorres_underlying t (f s) (f' (t s)) s \\<Longrightarrow> s_bcorres_underlying t (get >>= f) (get >>= f') s\"\n  by (simp add: gets_def s_bcorres_underlying_def get_def bind_def return_def)\n\nlemma get_bcorres[wp]:\n  \"(\\<And>x. bcorres_underlying t (f x) (f' (t x))) \\<Longrightarrow> bcorres_underlying t (get >>= f) (get >>= f')\"\n  by (simp add: bcorres_underlying_def get_s_bcorres_underlying)\n\nlemma gets_s_bcorres_underlying[wp]:\n  \"x' (t s) = x s \\<Longrightarrow>  s_bcorres_underlying t (gets x) (gets x') s\"\n  by (simp add: s_bcorres_underlying_def gets_def get_def bind_def return_def)\n\nlemma gets_bcorres_underlying[wp]:\n  \"(\\<And>s. x' (t s) = x s) \\<Longrightarrow> bcorres_underlying t (gets x) (gets x')\"\n  by (simp add: bcorres_underlying_def gets_s_bcorres_underlying)\n\nlemma gets_map_bcorres_underlying[wp]:\n  \"(\\<And>s. f' (t s) p = f s p) \\<Longrightarrow> bcorres_underlying t (gets_map f p) (gets_map f' p)\"\n  by (simp add: gets_map_def bcorres_underlying_def s_bcorres_underlying_def simpler_gets_def\n                bind_def assert_opt_def fail_def return_def\n        split: option.splits)\n\nlemma gets_bcorres_underlying':\n  \"(\\<And>xa. bcorres_underlying t (f (x xa)) (f' (x' (t xa)))) \\<Longrightarrow>\n  bcorres_underlying t (gets x >>= f) (gets x' >>= f')\"\n  by (wpsimp simp: gets_def)\n\nlemma assert_bcorres_underlying[wp]:\n  \"f = f' \\<Longrightarrow> bcorres_underlying t (assert f) (assert f')\"\n  by (simp add: assert_def bcorres_underlying_def return_def s_bcorres_underlying_def fail_def)\n\nlemma return_bcorres[wp]:\n  \"bcorres_underlying t (return x) (return x)\"\n  by (simp add:return_def bcorres_underlying_def s_bcorres_underlying_def)\n\nlemma drop_sbcorres_underlying:\n  \"bcorres_underlying t f g \\<Longrightarrow> s_bcorres_underlying t f g s\"\n  by (simp add: bcorres_underlying_def)\n\nlemma use_sbcorres_underlying:\n  \"(\\<And>s. s_bcorres_underlying t f g s) \\<Longrightarrow> bcorres_underlying t f g\"\n  by (simp add: bcorres_underlying_def)\n\nlemma bcorres_underlying_throwError[wp]:\n  \"bcorres_underlying t (throwError a) (throwError a)\"\n  by (wpsimp simp: throwError_def)\n\nlemma s_bcorres_underlying_splitE[wp_split]:\n  \"(\\<And>r s'. (Inr r,s') \\<in> fst (f s) \\<Longrightarrow> s_bcorres_underlying t (g r) (g' r) s') \\<Longrightarrow>\n   s_bcorres_underlying t f f' s \\<Longrightarrow>\n   s_bcorres_underlying t (f >>=E g) (f' >>=E g') s\"\n  by (wpsimp simp: bindE_def lift_def split: sum.splits | rule conjI drop_sbcorres_underlying)+\n\nlemma get_s_bcorres_underlyingE[wp]:\n  \"s_bcorres_underlying t (f s) (f' (t s)) s \\<Longrightarrow>\n   s_bcorres_underlying t (liftE get >>=E f) (liftE get >>=E f') s\"\n  by (simp add: gets_def s_bcorres_underlying_def get_def bindE_def bind_def return_def liftE_def lift_def)\n\nlemma bcorres_underlying_splitE[wp_split]:\n  \"(\\<And>r. bcorres_underlying t (g r) (g' r)) \\<Longrightarrow>\n   bcorres_underlying t f f' \\<Longrightarrow>\n   bcorres_underlying t (f >>=E g) (f' >>=E g')\"\n  by (simp add: bcorres_underlying_def s_bcorres_underlying_splitE)\n\nlemmas return_s_bcorres_underlying[wp] = drop_sbcorres_underlying[OF return_bcorres]\n\nlemma liftE_s_bcorres_underlying[wp]:\n  \"s_bcorres_underlying t f f' s \\<Longrightarrow> s_bcorres_underlying t (liftE f) (liftE f') s\"\n  by (wpsimp simp: liftE_def)\n\nlemma liftE_bcorres_underlying[wp]:\n  \"bcorres_underlying t f f' \\<Longrightarrow>  bcorres_underlying t (liftE f) (liftE f')\"\n  by (simp add: bcorres_underlying_def liftE_s_bcorres_underlying)\n\nlemma returnOk_bcorres_underlying[wp]:\n  \"bcorres_underlying t (returnOk x) (returnOk x)\"\n  by (wpsimp simp: returnOk_def)\n\nlemma whenE_s_bcorres_underlying[wp]:\n  \"\\<lbrakk> \\<lbrakk>P = P'; P\\<rbrakk> \\<Longrightarrow> s_bcorres_underlying t f f' s; P = P' \\<rbrakk> \\<Longrightarrow>\n   s_bcorres_underlying t (whenE P f) (whenE P' f') s\"\n  by (wpsimp simp: whenE_def|rule drop_sbcorres_underlying)+\n\nlemma select_s_bcorres_underlying[wp]:\n  \"A \\<subseteq> B \\<Longrightarrow> s_bcorres_underlying t (select A) (select B) s\"\n  by (simp add: s_bcorres_underlying_def select_def image_def) blast\n\nlemma fail_s_bcorres_underlying[wp]:\n  \"s_bcorres_underlying t fail fail s\"\n  by (simp add: s_bcorres_underlying_def fail_def)\n\nlemma fail_bcorres_underlying[wp]:\n  \"bcorres_underlying t fail fail\"\n  by (simp add: bcorres_underlying_def fail_s_bcorres_underlying)\n\nlemma assertE_bcorres_underlying[wp]:\n  \"bcorres_underlying t (assertE P) (assertE P)\"\n  by (wpsimp simp: assertE_def returnOk_def|rule conjI)+\n\nlemmas assertE_s_bcorres_underlying[wp] = drop_sbcorres_underlying[OF assertE_bcorres_underlying]\n\nlemma when_s_bcorres_underlying[wp]:\n  \"(P \\<Longrightarrow> s_bcorres_underlying t f f' s) \\<Longrightarrow> s_bcorres_underlying t (when P f) (when P f') s\"\n  by (simp add: return_s_bcorres_underlying when_def)\n\nlemma when_bcorres_underlying[wp]:\n  \"(P \\<Longrightarrow> bcorres_underlying t f f') \\<Longrightarrow> bcorres_underlying t (when P f) (when P f')\"\n  by (simp add: bcorres_underlying_def when_s_bcorres_underlying)\n\nlemma put_bcorres_underlying[wp]:\n  \"t f = f' \\<Longrightarrow> bcorres_underlying t (put f) (put f')\"\n  by (simp add: bcorres_underlying_def s_bcorres_underlying_def put_def)\n\nlemma modify_bcorres_underlying[wp]:\n  \"(\\<And>x. t (f x) = f' (t x)) \\<Longrightarrow> bcorres_underlying t (modify f) (modify f')\"\n  by (wpsimp simp: modify_def)\n\nlemma liftM_bcorres_underlying[wp]:\n  \"bcorres_underlying t m m' \\<Longrightarrow> bcorres_underlying t (liftM f m) (liftM f m')\"\n  by (wpsimp simp: liftM_def)\n\nlemma sequence_x_bcorres_underlying[wp]:\n  \"(\\<And>x. bcorres_underlying t (f x) (f' x)) \\<Longrightarrow>\n   bcorres_underlying t (sequence_x (map f xs)) (sequence_x (map f' xs))\"\n  by (induct xs; wpsimp simp: sequence_x_def)\n\nlemma sequence_bcorres_underlying[wp]:\n  \"(\\<And>x. bcorres_underlying t (f x) (f' x)) \\<Longrightarrow>\n   bcorres_underlying t (sequence (map f xs)) (sequence (map f' xs))\"\n  by (induct xs; wpsimp simp: sequence_def)\n\nlemma mapM_x_bcorres_underlying[wp]:\n  \"(\\<And>x. bcorres_underlying t (f x) (f' x)) \\<Longrightarrow> bcorres_underlying t (mapM_x f xs) (mapM_x f' xs)\"\n  by (wpsimp simp: mapM_x_def)\n\nlemma mapM_bcorres_underlying[wp]:\n  \"(\\<And>x. bcorres_underlying t (f x) (f' x)) \\<Longrightarrow> bcorres_underlying t (mapM f xs) (mapM f' xs)\"\n  by (simp add: mapM_def | wp)+\n\nlemma gets_s_bcorres_underlyingE':\n  \"s_bcorres_underlying t (f (x s)) (f' (x' (t s))) s \\<Longrightarrow>\n   s_bcorres_underlying t (liftE (gets x) >>=E f) (liftE (gets x') >>=E f') s\"\n  by (simp add: gets_def liftE_def lift_def bindE_def) wp\n\nlemma bcorres_underlying_filterM[wp]:\n  \"(\\<And>x. bcorres_underlying t (a x) (a' x)) \\<Longrightarrow> bcorres_underlying t (filterM a b) (filterM a' b)\"\n  by (induct b; wpsimp simp: filterM_def)\n\nlemma option_rec_bcorres_underlying[wp_split]:\n  \"(\\<And>x y. bcorres_underlying t (g x y) (g' x y)) \\<Longrightarrow>\n   (\\<And>x. bcorres_underlying t (f x) (f' x)) \\<Longrightarrow>\n   bcorres_underlying t (rec_option f g a b) (rec_option f' g' a b)\"\n  by (cases a, simp+)\n\nlemma bcorres_underlying_mapME[wp]:\n  \"(\\<And>x. bcorres_underlying t (f x) (f' x)) \\<Longrightarrow> bcorres_underlying t (mapME f r) (mapME f' r)\"\n  by (induct r; wpsimp simp: mapME_def sequenceE_def)\n\nlemma handle2_bcorres_underlying[wp]:\n  \"bcorres_underlying t f f' \\<Longrightarrow>\n   (\\<And>x. bcorres_underlying t (g x) (g' x)) \\<Longrightarrow>\n   bcorres_underlying t (f <handle2> g) (f' <handle2> g')\"\n  by (wpsimp simp: handleE'_def)\n\nlemma liftME_bcorres_underlying[wp]:\n  \"bcorres_underlying t f f' \\<Longrightarrow> bcorres_underlying t (liftME a f) (liftME a f')\"\n  by (wpsimp simp: liftME_def)\n\nlemma zipWithM_x_bcorres[wp]:\n  \"(\\<And>x y. bcorres_underlying t (f x y) (f' x y) ) \\<Longrightarrow>\n   bcorres_underlying t (zipWithM_x f xs ys) (zipWithM_x f' xs ys)\"\n  by (wpsimp simp: zipWithM_x_def zipWith_def split_def)\n\nlemma mapME_x_bcorres_underlying[wp]:\n  \"(\\<And>x. bcorres_underlying t (f x) (f' x)) \\<Longrightarrow> bcorres_underlying t (mapME_x f xs) (mapME_x f' xs)\"\n  by (induct xs; wpsimp simp: mapME_x_def sequenceE_x_def)\n\nlemma liftE_bind_bcorres[wp]:\n  \"bcorres_underlying t (f >>= g) (f' >>= g') \\<Longrightarrow>\n   bcorres_underlying t (liftE f >>=E g) (liftE f' >>=E g')\"\n  by (simp add: gets_def bcorres_underlying_def s_bcorres_underlying_def get_def bind_def return_def\n                split_def liftE_def bindE_def lift_def)\n\nlemma select_f_bcorres[wp]: \"bcorres_underlying t (select_f f) (select_f f)\"\n  by (fastforce simp: select_f_def bcorres_underlying_def s_bcorres_underlying_def)\n\nlemma bcorres_underlying_if[wp]:\n  \"(b \\<Longrightarrow> bcorres_underlying t f f') \\<Longrightarrow>\n   (\\<not>b \\<Longrightarrow> bcorres_underlying t g g') \\<Longrightarrow>\n   bcorres_underlying t (if b then f else g) (if b then f' else g')\"\n  by (case_tac b; simp)\n\nlemma assert_opt_bcorres_underlying[wp]:\n  \"bcorres_underlying t (assert_opt f) (assert_opt f)\"\n  by (wpsimp simp: assert_opt_def)\n\nlemma unlessb_corres_underlying[wp]:\n  \"bcorres_underlying t f f' \\<Longrightarrow> bcorres_underlying t (unless a f) (unless a f')\"\n  by (wpsimp simp: unless_def)\n\nlemma select_bcorres_underlying[wp]:\n  \"A \\<subseteq> B \\<Longrightarrow> bcorres_underlying t (select A) (select B)\"\n  by (fastforce simp: bcorres_underlying_def select_def s_bcorres_underlying_def)\n\nlemma catch_bcorres[wp]:\n  \"bcorres_underlying t f f' \\<Longrightarrow>\n   (\\<And>x. bcorres_underlying t (g x) (g' x)) \\<Longrightarrow>\n   bcorres_underlying t (f <catch> g) (f' <catch> g')\"\n  unfolding catch_def by wpsimp\n\nlemma whenE_bcorres_underlying[wp]:\n  \"\\<lbrakk> \\<lbrakk>P = P'; P\\<rbrakk> \\<Longrightarrow> bcorres_underlying t f f'; P = P' \\<rbrakk> \\<Longrightarrow>\n  bcorres_underlying t (whenE P f) (whenE P' f')\"\n  unfolding whenE_def by wpsimp\n\nlemma unlessE_bcorres[wp]:\n  \"bcorres_underlying t f f' \\<Longrightarrow> bcorres_underlying t (unlessE P f) (unlessE P f')\"\n  by (wpsimp simp: unlessE_def)\n\nlemma alternative_bcorres[wp]:\n  \"\\<lbrakk> bcorres_underlying t f f';  bcorres_underlying t g g' \\<rbrakk> \\<Longrightarrow>\n  bcorres_underlying t (f \\<sqinter> g) (f' \\<sqinter> g')\"\n  by (fastforce simp: alternative_def bcorres_underlying_def s_bcorres_underlying_def)\n\nlemma gets_the_bcorres_underlying[wp]:\n  \"(\\<And>s. f' (t s) = f s) \\<Longrightarrow> bcorres_underlying t (gets_the f) (gets_the f')\"\n  by (wpsimp simp: gets_the_def)\n\nML \\<open>\nstructure CrunchBCorresInstance : CrunchInstance =\nstruct\n  val name = \"bcorres\";\n  type extra = term;\n  val eq_extra = ae_conv;\n  fun parse_extra ctxt extra\n        = case extra of\n             \"\" => error \"bcorres needs truncate function\"\n             | e =>(Syntax.parse_term ctxt \"%_. True\", Syntax.parse_term ctxt e);\n  val has_preconds = false;\n  fun mk_term _ body extra =\n    (Syntax.parse_term @{context} \"bcorres_underlying\") $ extra $ body $ body;\n  fun dest_term (Const (@{const_name \"bcorres_underlying\"}, _) $ extra $ body $ _)\n        = SOME (Term.dummy, body, extra)\n    | dest_term _ = NONE;\n  fun put_precond _ ((v as Const (@{const_name \"bcorres_underlying\"}, _)) $ extra $ body $ body')\n        = v $ extra $ body $ body'\n    | put_precond _ _ = error \"put_precond: not an bcorres term\";\n  val pre_thms = [];\n  val wpc_tactic = WeakestPreCases.wp_cases_tac @{thms wpc_processors};\n  fun wps_tactic _ _ _ = no_tac;\n  val magic = Syntax.parse_term @{context}\n    \"\\<lambda>mapp_lambda_ignore. bcorres_underlying t_free_ignore mapp_lambda_ignore g_free_ignore\";\n  val get_monad_state_type = get_nondet_monad_state_type;\nend;\n\nstructure CrunchBCorres : CRUNCH = Crunch(CrunchBCorresInstance);\n\\<close>\n\nsetup \\<open>\n  add_crunch_instance \"bcorres\" (CrunchBCorres.crunch_x, CrunchBCorres.crunch_ignore_add_del)\n\\<close>\n\nend\n", "meta": {"author": "NICTA", "repo": "l4v", "sha": "3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b", "save_path": "github-repos/isabelle/NICTA-l4v", "path": "github-repos/isabelle/NICTA-l4v/l4v-3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b/lib/BCorres_UL.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.26317655700486653}}
{"text": "chapter \\<open>Semantic Formalization \\& Specification\\<close>\n\nsection \\<open>Core Monadic Language\\<close>\n\ntext \\<open>Notions of procedure and control flow combinator, which enable formalizing\nmost of imperative languages.\\<close>\n\nsection \\<open>Specifications on Fictional \\<phi>-SL\\<close>\n\ntext \\<open>\\begin{remark}[Source \\& Target]\nAs both ToA and view shift constitutes a morphism,\n\\[ \\<open>X \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> Y \\<a>\\<n>\\<d> P\\<close> \\]\n\\[ \\<open>X \\<s>\\<h>\\<i>\\<f>\\<t>\\<s> Y \\<a>\\<n>\\<d> P\\<close> \\]\nwe name the above \\<open>X\\<close> and \\<open>Y\\<close> as \\<^emph>\\<open>source\\<close> and \\<^emph>\\<open>target\\<close> respectively.\nWe also name the \\<open>P\\<close> \\<^emph>\\<open>side fact\\<close> as it is a side effect generated during the transformation.\n\\end{remark}\\<close>\n\ntext \\<open>\n\\begin{remark}[Multi-Term Form (MTF)]\n\\[ \\<open>(x\\<^sub>1 \\<Ztypecolon> T\\<^sub>1) * \\<dots> * (x\\<^sub>n \\<Ztypecolon> T\\<^sub>n) \\<s>\\<u>\\<b>\\<j> a\\<^sub>1 \\<dots> a\\<^sub>m. P\\<close> \\]\nWe call \\<open>x\\<^sub>i \\<Ztypecolon> T\\<^sub>i\\<close> for \\<open>1 \\<le> i \\<le> n\\<close> an \\<^emph>\\<open>item\\<close> in the MTF.\n\\end{remark}\n\n\\begin{remark}[Simple Multi-Term Form]\nWe call a MTF that does not have any existence and conjunction as \\<^emph>\\<open>simple MTF\\<close>.\n\\[ \\<open>(x\\<^sub>1 \\<Ztypecolon> T\\<^sub>1) * \\<dots> * (x\\<^sub>n \\<Ztypecolon> T\\<^sub>n)\\<close> \\]\n\\end{remark}\n\\<close>\n\n\n\nchapter \\<open>Integrated Deduction Environment for Certified Programming\\<close>\n\ntheory Chapter_System\n  imports \"../IDE_CP\"\nbegin\n\ntext \\<open>The major component for programming in \\<phi>-System is\nIntegrated Deduction Environment for Certified Programming (IDE-CP).\nThe environment is an extensible framework targeting on the core monadic language.\nProgramming features like mutable variable or any specific control flow like branches\nare added later to the environment as the framework and the core monadic language is extensible.\nThe chapter focuses on the core designs of the framework, and leaves\npluggable components to the later chapters.\n\n\nThe programming in \\<phi>-System primarily involves 3 (sorts of) Isar commands:\n\\<^item> A sort of declaration commands like @{command proc} that declare program elements and perhaps\n  instantiates a proof context for certifying the element.\n\\<^item> Commands @{command \\<medium_left_bracket>} and @{command \\<medium_right_bracket>} that opens and closes respectively a programming context\n  \\footnote{Here proof context is that in Isabelle, and programming context is invented by IDE-CP.}\n  from a proof context or nestedly from another programming context.\n\\<^item> Command @{command \";;\"} that builds a statement in a programming context.\n\nSo the overall structure of the source code is very nature as demonstrated in the following example,\n\\<close>\n\n(*TODO: give an example*)\n\ntext \\<open>The source code begins with a declaration (@{command proc} here),\nopens and closes programming scope using @{command \\<medium_left_bracket>} and @{command \\<medium_right_bracket>} just like\nthe bracket \\<^verbatim>\\<open>{\\<close> and \\<^verbatim>\\<open>}\\<close> in usual languages like C,\nand separates statements by @{command \";;\"} just like \\<^verbatim>\\<open>;\\<close> in C.\n\n\\begin{remarks}\nIndeed, the statement text is an argument of the command @{command \";;\"}.\nThere is an implicit @{command \";;\"} immediately after @{command \\<medium_left_bracket>}\nso one can write a statement text following @{command \\<medium_left_bracket>} and\nmakes the source more like @{command \";;\"} separates statements or ends a statement\ninstead of the actual fact that @{command \";;\"} leads a statement.\n\\end{remarks}\n\nIDE-CP is based on the theory of Calculus of Programming (CoP).\nWe introduce CoP briefly here and highly recommend readers to its paper~\\cite{CoP}.\nIn CoP, programming is identical to deducing a state sequent.\nOne may view the state sequent a specialized variant of Hoare triple which specifies and\ncertifies the returning state of evaluating the current program segment of the on-going\nconstruction, starting from an input state specified by a fixed pre-condition.\n\nCentering on deduction of the state sequent, IDE-CP is an environment\nequipped with various mechanical assistance including\nautomated reasoning, syntax and interactive interface, programming synthesis, and others.\n\nA feature of the IDE-CP is that the state sequent of the programming is instantly\ndisplayed in the output window of Isabelle.\nOnce can move the cursor onto each statement to inspect the computation state after\nexecuting each statement, which resembles a kind of symbolic execution.\nThe state involves the value of each variable and the state of resources over the abstraction\nlifted by the abstraction relations, i.e., an intuitive and intelligible abstraction enabling\nusers to grasp the value and the state very easily, such as expressions of natural numbers or lists,\ninstead of any complicated representation of the concrete computation model.\n\nBy inserting @{command \";;\"} in a statement to split it into two, one can inspect\nthe computation state after each operation.\nSpecifically and recalling @{command \";;\"} actually leads a statement,\nfor a statement \\<open>C\\<^sub>1 \\<cdots> C\\<^sub>i C\\<^sub>i\\<^sub>+\\<^sub>1 \\<cdots> C\\<^sub>n ;;\\<close> consisting of \\<open>n\\<close> operations, by inserting @{command \";;\"}\nbetween \\<open>C\\<^sub>i\\<close> and \\<open>C\\<^sub>i\\<^sub>+\\<^sub>1\\<close> (and moving the cursor before the inserted @{command \";;\"})\none can inspect the computation state after evaluating operations \\<open>C\\<^sub>1 \\<cdots> C\\<^sub>i\\<close>.\nWe highly recommend users to inspect in this way the change of the state step by step in\nour examples, which is very good for understanding the mechanism of the system.\n\nBefore we dive into more depth of the system, it is good to clarify from the very beginning that\nconstruction in the system actually involves three modes for constructing respectively\n\\<^item> procedures\n\\<^item> view shifts\n\\<^item> transformations of abstraction (\\<phi>-BI implications)\nwhich are both identical in the way of construction and therefore we mainly\ndiscuss using the procedure mode as an exemplar.\nThe differences in detail are presented in later sections \\cref{???} for the construction of\nthe each element.\n\nFor view-shift mode and transformation-of-abstraction mode, the programming or in another word\nthe construction is a forward deduction applying view-shifts or transformations-of-abstraction\nstepwisely from the initial view or the initial abstraction to the destined view or abstraction.\nThe following example demonstrates the such programming approach\\<close>\n\n(*TODO: example*)\n\ntext \\<open>\nAfter such a brief warm-up, now it is the time to start the journey and it begins from\nan overview of the whole mechanism.\n%we shall explore mechanisms of the system first.\n\\<close>\n\nsection \\<open>Overview of the Mechanism\\<close>\n\ntext \\<open>\nMentioned previously, programming in IDE-CP centers on state sequent.\nBecause the hypotheses of the state sequent is managed by the system internally, we only\nconsider its proposition excluding the hypotheses (i.e. \\<open>P\\<close> in \\<open>\\<Gamma> \\<turnstile> P\\<close>) in the manual.\n\nThe proposition of the state sequent is represented in Heredity Harrop Formula (HHF) and\nthe deduction is proceeded in a manner of logic programming\n--- antecedents of the state sequent tells users what are the jobs required to do next in order,\nand premises of each antecedent give us, figuratively speaking,\navailable \\<^emph>\\<open>resources\\<close> to complete the job.\n\nTo illustrate, a job can be either of\n\\<^item> a transformation of abstraction demanded to be reasoned, denoted by \\<open>X \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> Y \\<a>\\<n>\\<d> P\\<close>\n\\<^item> a proof obligation intended to be solved by users, denoted by \\<open>\\<o>\\<b>\\<l>\\<i>\\<g>\\<a>\\<t>\\<i>\\<o>\\<n> P\\<close>\n\\<^item> a parameter expected to be given by users, denoted by \\<open>\\<p>\\<a>\\<r>\\<a>\\<m> ?x\\<close>\n\\<^item> a specification of a sub-procedure waiting for users programming it,\n  denoted by \\<open>\\<p>\\<r>\\<o>\\<c> ?F \\<lbrace> X \\<longmapsto> Y \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E \\<rbrace>\\<close>.\nMore detailed elucidation are given later in \\cref{sec:antecedent-jobs}.\n\n\\begin{remark}\nSometimes, we name an antecedent as \\<^emph>\\<open>antecedent job\\<close> to emphasize it is a job expecting\nresoners or users to do something.\n\\end{remark}\n\n\nReaders who are familiar with Isabelle may remember of another sequent that is also in HHF,\nthe internal representation of a proof state.\n\\[ \\<open>A\\<^sub>1 \\<Longrightarrow> \\<dots> \\<Longrightarrow> A\\<^sub>n \\<Longrightarrow> C\\<close> \\]\nAntecedents \\<open>\\<A> \\<equiv> {A\\<^sub>i}\\<^sub>1\\<^sub>\\<le>\\<^sub>i\\<^sub>\\<le>\\<^sub>n\\<close> are subgoals for proving conclusion \\<open>C\\<close>.\nEach antecedent \\<open>A\\<^sub>i \\<equiv> (\\<And>x\\<^sub>i \\<dots> x\\<^sub>l. P\\<^sub>1 \\<Longrightarrow> \\<dots> \\<Longrightarrow> P\\<^sub>m \\<Longrightarrow> G\\<^sub>i)\\<close> may contains locally fixed variables\n\\<open>{x\\<^sub>k}\\<^sub>1\\<^sub>\\<le>\\<^sub>k\\<^sub>\\<le>\\<^sub>l\\<close> and premises \\<open>{P\\<^sub>j}\\<^sub>1\\<^sub>\\<le>\\<^sub>j\\<^sub>\\<le>\\<^sub>m\\<close> which are available during the proof of the proposition \\<open>G\\<^sub>i\\<close>.\n\nAntecedents \\<open>\\<A>\\<close> in a proof state sequent have the identical interpretation with that in\nstate sequents during programming.\nIndeed, one may even view such proof state sequent as a kind of state sequent in\nproof context, and the difference between them two is just how we name them\n\\footnote{We still need the name of state sequent because there is not the sequent of proof state\nin programming context.}.\n\nDeclaration commands like @{command proc} and others (except those requiring no proof nor programming)\nare indeed specialized proof goal statement like command @{command lemma} and @{command theorem},\nwhich initiates a standard Isabelle proof context having for examples the following proof states\ncorresponding to the three construction mode,\n\\[ \\<open>\\<p>\\<r>\\<o>\\<c> ?F \\<lbrace> X \\<longmapsto> Y \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E \\<rbrace> \\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> ?F \\<lbrace> X \\<longmapsto> Y \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E \\<rbrace>\\<close> \\]\n\\[ \\<open>X \\<s>\\<h>\\<i>\\<f>\\<t>\\<s> Y \\<a>\\<n>\\<d> P \\<Longrightarrow> X \\<s>\\<h>\\<i>\\<f>\\<t>\\<s> Y \\<a>\\<n>\\<d> P\\<close> \\]\n\\[ \\<open>X \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> Y \\<a>\\<n>\\<d> P \\<Longrightarrow> X \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> Y \\<a>\\<n>\\<d> P\\<close> \\]\nwhere the only subgoal is exact the desired conclusion,\nand the subgoal is meantime also an antecedent job\nasking users respectively to program some procedure \\<open>?F\\<close> satisfying the specification,\nto deduce the view shift from \\<open>X\\<close> to \\<open>Y\\<close>,\nand to transform abstraction \\<open>X\\<close> to \\<open>Y\\<close> by forward deduction.\n\nCommand @{command \\<medium_left_bracket>} addresses the above three kinds of antecedent jobs, which opens a programming\ncontext allowing users to program or to deduce the desired construct.\nAnd the programming is deducing a state sequent.\n\nIn the programming, the proposition of a state sequent falls in two sorts of forms:\n\\<^item> \\<^emph>\\<open>ready state\\<close> like \\<^prop>\\<open>\\<c>\\<u>\\<r>\\<r>\\<e>\\<n>\\<t> state [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> P\\<close> representing the previous construction\n  is finished, the computation state is now as specified by \\<open>P\\<close>, and the system is ready for\n  the next construction.\n\\<^item> \\<^emph>\\<open>pending state\\<close> like \\<^prop>\\<open>\\<A> \\<Longrightarrow> \\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> F \\<o>\\<n> state [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> Q \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\\<close>\n  is deduced after applying a procedure \\<^prop>\\<open>\\<A> \\<Longrightarrow> \\<p>\\<r>\\<o>\\<c> F \\<lbrace> P \\<longmapsto> Q \\<rbrace> \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\\<close> on the ready state.\n  It represents the application of \\<open>F\\<close> is pending the finish of antecedent jobs \\<open>\\<A>\\<close>.\n\n\\begin{remark}\nWe reuse the notation of \\<^emph>\\<open>conjunction of aggreagted antecedents\\<close> in \\cite{CoP} where\na family \\<open>\\<A> = {A\\<^sub>i}\\<^sub>1\\<^sub>\\<le>\\<^sub>i\\<^sub>\\<le>\\<^sub>n\\<close> of antecedents in \\<open>\\<A> \\<Longrightarrow> C\\<close> denotes nested implications of the antecedents\nas \\<open>A\\<^sub>1 \\<Longrightarrow> \\<cdots> \\<Longrightarrow> A\\<^sub>n \\<Longrightarrow> C\\<close>.\n\\end{remark}\n\nThose antecedent jobs have various functions, like a transformation of abstraction or\na demanded annotation or even another sub-procedure waiting for programming\n(cf. control flow combinators).\nOnce all the pending jobs \\<open>\\<A>\\<close> are finished, meaning state sequent\n\\<^prop>\\<open>\\<p>\\<e>\\<n>\\<d>\\<i>\\<n>\\<g> F \\<o>\\<n> state [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> Q \\<t>\\<h>\\<r>\\<o>\\<w>\\<s> E\\<close> is deduced, the system accepts the procedure \\<open>F\\<close>\nand deduces the next state sequent in ready form \\<^prop>\\<open>\\<c>\\<u>\\<r>\\<r>\\<e>\\<n>\\<t> state' [R] \\<r>\\<e>\\<s>\\<u>\\<l>\\<t>\\<s> \\<i>\\<n> Q\\<close>.\nThe \\<open>state'\\<close> denotes the resulted state of evaluating procedure \\<open>F\\<close>.\n\nThe programming is then essentially a loop of switching between the ready state and the pending\nstate, where users apply a procedure on a ready state and\nfinishes the antecedent jobs on the pending state.\n\nAt last, @{command \\<medium_right_bracket>} closes the programming context, and obtains the resulted\nspecification theorem for the procedure or the view shift or the transformation.\nThen using the theorem, it solves the antecedent which the corresponding @{command \\<medium_left_bracket>} targets.\n\nThis is the overview of the deductive programming in the logic programming manner.\nNext we will dive into specific usages of each command and and each antecedent jobs.\n\\<close>\n\nsection \\<open>Overall Structure of Programs\\<close>\n\nsubsection \\<open>Declarative Commands\\<close>\n\nsubsubsection \\<open>Procedure\\<close>\n\nsubsubsection \\<open>Transformation of Abstraction (ToA) \\& View Shift\\<close>\n\ntext \\<open>Because their roles are in purely theoretical level serving for proofs and deductions,\ninstead of any specific program element or pragmatic usage,\ntherefore we do not involve a specialized command to declare them.\nWe use standard goal statement commands in Isar directly,\nlike @{command lemma} and @{command theorem}, where the desired transformation or the view shift\nis given in the goal statement directly together with any assumptions as antecedents.\\<close>\n\nlemma example:\n  assumes A: \\<open>x \\<Ztypecolon> T \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> y \\<Ztypecolon> U \\<a>\\<n>\\<d> P\\<close>\n    and   B: \\<open>y \\<Ztypecolon> U \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> z \\<Ztypecolon> Z \\<a>\\<n>\\<d> Q\\<close>\n  shows \\<open>x \\<Ztypecolon> T \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> z \\<Ztypecolon> Z \\<a>\\<n>\\<d> P \\<and> Q\\<close>\n  \\<medium_left_bracket> A B \\<medium_right_bracket>. .\n\ntext \\<open>Recalling the sequent of the Isar proof state\n\\<open>x \\<Ztypecolon> T \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> z \\<Ztypecolon> Z \\<a>\\<n>\\<d> P \\<and> Q \\<Longrightarrow> x \\<Ztypecolon> T \\<i>\\<m>\\<p>\\<l>\\<i>\\<e>\\<s> z \\<Ztypecolon> Z \\<a>\\<n>\\<d> P \\<and> Q\\<close>\nwhere the only sub-goal is also an antecedent, the sub-goal as an antecedent is opened by\n@{command \\<medium_left_bracket>} by which we enter the programming mode where we can deduce the transformation\nforwardly and stepwisely by applying the transformation \\<open>A\\<close> first and then \\<open>B\\<close>.\n\\<close>\n(*Explain \\<medium_right_bracket>. and \\<medium_right_bracket> and the last . after \\<medium_right_bracket>.*)\n\nsubsection \\<open>Commands Opening and Closing Programming Context\\<close>\n\nsubsection \\<open>The Command Writing Statements\\<close>\n\nsection \\<open>Antecedent Jobs for User Input\\<close>\n\ntext \\<open>Antecedent jobs can be classified in two sorts\n\\<^item> programming job for user input\n\\<^item> reasoning job for a specific problem, invoking the related reasoning process\\<close>\n\ntext \\<open>The section introduces the first sort that for user input, and leaves that about\nreasoning to \\cref{sec:reasoning}.\\<close>\n\nsubsection \\<open>Parameter\\<close>\n\nsubsection \\<open>Rule as an Argument\\<close>\n\nsubsection \\<open>Label of Text\\<close>\n\n\n\nsection \\<open>Applying Procedures \\& Other Constructs\\<close>\n\nparagraph \\<open>Procedure\\<close>\n\nparagraph \\<open>View Shift\\<close>\n\nparagraph \\<open>Transformation of Abstraction\\<close>\n\nparagraph \\<open>Meta Operation\\<close>\ntext \\<open>is a bundle of operations \\<close>\n\nsubsubsection \\<open>Extend by User Specified Application Method\\<close>\n\nsection \\<open>Program Synthesis\\<close>\n\nsection \\<open>Reasoning \\label{sec:reasoning}\\<close>\n\n\nsection \\<open>Access Value or Variable\\<close>\n\n(*Notice*)\ntext \\<open>Internal representation of the values and their names are hidden by default during the\n  programming, but you can turn on @{attribute \\<phi>display_value_internal_name} to display them.\\<close>\n\ntext \\<open>By default, remaining values in the previous statement will be removed in the successive\n  statement. You can turn off @{attribute \\<phi>statement_clean_values} to disable this behavior.\\<close>\n\n\n(*Unsorted*)\n\nsubsection \\<open>Options enabling Expert Display\\<close>\n\ntext \\<open>\n\\<^descr> @{attribute \\<phi>display_value_internal_name} enables the display of internal names of values.\n    By turning on this option, values will be displayed as \\<^term>\\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l>[internal] T\\<close>\n    by contrast to the default display \\<^term>\\<open>x \\<Ztypecolon> \\<v>\\<a>\\<l> T\\<close>.\n    This \\<^term>\\<open>internal\\<close> is the internal semantic representation of value.\n\\<^descr> \\<phi>display_brk_frame displays the internal and technical separation items for breaking frame.\n\\<close>\n\nend\n", "meta": {"author": "xqyww123", "repo": "phi-system", "sha": "c8dca186bcc8ac2c9b38d813fc0f0dfec486ebab", "save_path": "github-repos/isabelle/xqyww123-phi-system", "path": "github-repos/isabelle/xqyww123-phi-system/phi-system-c8dca186bcc8ac2c9b38d813fc0f0dfec486ebab/Phi_System/User_Manual/Chapter_System.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5389832058771036, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.263176549773106}}
{"text": "(* Authors: Gerwin Klein and Rafal Kolanski, 2012\n   Maintainers: Gerwin Klein <kleing at cse.unsw.edu.au>\n                Rafal Kolanski <rafal.kolanski at nicta.com.au>\n*)\n\ntheory Sep_Tactics_Test\nimports \"../Sep_Tactics\"\nbegin\n\ntext \\<open>Substitution and forward/backward reasoning\\<close>\n\ntypedecl p\ntypedecl val\ntypedecl heap\n\naxiomatization where heap_sep_algebra: \"OFCLASS(heap, sep_algebra_class)\"\ninstance heap :: sep_algebra by (rule heap_sep_algebra)\n\naxiomatization\n  points_to :: \"p \\<Rightarrow> val \\<Rightarrow> heap \\<Rightarrow> bool\" and\n  val :: \"heap \\<Rightarrow> p \\<Rightarrow> val\"\nwhere\n  points_to: \"(points_to p v ** P) h \\<Longrightarrow> val h p = v\"\n\n\nlemma\n  \"\\<lbrakk> Q2 (val h p); (K ** T ** blub ** P ** points_to p v ** P ** J) h \\<rbrakk>\n   \\<Longrightarrow> Q (val h p) (val h p)\"\n  apply (sep_subst (2) points_to)\n  apply (sep_subst (asm) points_to)\n  apply (sep_subst points_to)\n  oops\n\nlemma\n  \"\\<lbrakk> Q2 (val h p); (K ** T ** blub ** P ** points_to p v ** P ** J) h \\<rbrakk>\n   \\<Longrightarrow> Q (val h p) (val h p)\"\n  apply (sep_drule points_to)\n  apply simp\n  oops\n\nlemma\n  \"\\<lbrakk> Q2 (val h p); (K ** T ** blub ** P ** points_to p v ** P ** J) h \\<rbrakk>\n   \\<Longrightarrow> Q (val h p) (val h p)\"\n  apply (sep_frule points_to)\n  apply simp\n  oops\n\nconsts\n  update :: \"p \\<Rightarrow> val \\<Rightarrow> heap \\<Rightarrow> heap\"\n\nschematic_goal\n  assumes a: \"\\<And>P. (stuff p ** P) H \\<Longrightarrow> (other_stuff p v ** P) (update p v H)\"\n  shows \"(X ** Y ** other_stuff p ?v) (update p v H)\"\n  apply (sep_rule a)\n  oops\n\n\ntext \\<open>Example of low-level rewrites\\<close>\n\nlemma \"\\<lbrakk> unrelated s ; (P ** Q ** R) s \\<rbrakk> \\<Longrightarrow> (A ** B ** Q ** P) s\"\n  apply (tactic \\<open>dresolve_tac @{context} [mk_sep_select_rule @{context} true (3, 1)] 1\\<close>)\n  apply (tactic \\<open>resolve_tac @{context} [mk_sep_select_rule @{context} false (4, 2)] 1\\<close>)\n  (* now sep_conj_impl1 can be used *)\n  apply (erule (1) sep_conj_impl)\n  oops\n\n\ntext \\<open>Conjunct selection\\<close>\n\nlemma \"(A ** B ** Q ** P) s\"\n  apply (sep_select 1)\n  apply (sep_select 3)\n  apply (sep_select 4)\n  oops\n\nlemma \"\\<lbrakk> also unrelated; (A ** B ** Q ** P) s \\<rbrakk> \\<Longrightarrow> unrelated\"\n  apply (sep_select_asm 2)\n  oops\n\n\nsection \\<open>Test cases for \\<open>sep_cancel\\<close>.\\<close>\n\nlemma\n  assumes forward: \"\\<And>s g p v. A g p v s \\<Longrightarrow> AA g p s \"\n  shows \"\\<And>xv yv P s y x s. (A g x yv ** A g y yv ** P) s \\<Longrightarrow> (AA g y ** sep_true) s\"\n  by (sep_cancel add: forward)\n\nlemma\n  assumes forward: \"\\<And>s. generic s \\<Longrightarrow> instance s\"\n  shows \"(A ** generic ** B) s \\<Longrightarrow> (instance ** sep_true) s\"\n  by (sep_cancel add: forward)\n\nlemma \"\\<lbrakk> (A ** B) sa ; (A ** Y) s \\<rbrakk> \\<Longrightarrow> (A ** X) s\"\n  apply (sep_cancel)\n  oops\n\nlemma \"\\<lbrakk> (A ** B) sa ; (A ** Y) s \\<rbrakk> \\<Longrightarrow> (\\<lambda>s. (A ** X) s) s\"\n  apply (sep_cancel)\n  oops\n\nschematic_goal \"\\<lbrakk> (B ** A ** C) s \\<rbrakk> \\<Longrightarrow> (\\<lambda>s. (A ** ?X) s) s\"\n  by (sep_cancel)\n\n(* test backtracking on premises with same state *)\nlemma\n  assumes forward: \"\\<And>s. generic s \\<Longrightarrow> instance s\"\n  shows \"\\<lbrakk> (A ** B) s ; (generic ** Y) s \\<rbrakk> \\<Longrightarrow> (X ** instance) s\"\n  apply (sep_cancel add: forward)\n  oops\n\nlemma\n  assumes forward: \"\\<And>s. generic s \\<Longrightarrow> instance s\"\n  shows \"generic s \\<Longrightarrow> instance s\"\n  by (sep_cancel add: forward)\n\nlemma\n  assumes forward: \"\\<And>s. generic s \\<Longrightarrow> instance s\"\n  assumes forward2: \"\\<And>s. instance s \\<Longrightarrow> instance2 s\"\n  shows \"generic s \\<Longrightarrow> (instance2 ** sep_true) s\"\n  by (sep_cancel_blast add: forward forward2)\n\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Separation_Algebra/ex/Sep_Tactics_Test.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.566018549837479, "lm_q2_score": 0.4649015713733885, "lm_q1q2_score": 0.2631429132459306}}
{"text": "theory flash57Rev imports flashPub\nbegin\nsection{*Main defintions*}\nlemma NI_FAckVsInv57:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvVsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_InvAck_1VsInv57:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1_HomeVsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_InvAck_2VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_GetXVsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak1VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak2VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak3VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX1VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv57:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10VsInv57:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10_homeVsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX11VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_GetVsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_Get ))     (neg ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv1)) )  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv2) )   (Const iInv1))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))     (neg ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2)) )  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak1VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak2VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak3VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put1VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put2VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put3VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_PutVsInv57:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_PutXAcksDoneVsInv57:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_NakVsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Nak_ClearVsInv57:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Nak_HomeVsInv57:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_NakVsInv57:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_Nak_HomeVsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Remote_GetX_PutXVsInv57:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_PutX_HomeVsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Remote_Get_Nak1VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Remote_Get_Nak2VsInv57:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Put1VsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Remote_Get_Put2VsInv57:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutVsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutXVsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_ReplaceVsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_ReplaceHomeVsInv57:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceHomeShrVldVsInv57:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceShrVldVsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_ShWbVsInv57:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_WbVsInv57:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_GetX1VsInv57:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_GetX2VsInv57:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX1VsInv57:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX2VsInv57:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX3VsInv57:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX4VsInv57:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_Get_GetVsInv57:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_Get_PutVsInv57:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_PutXVsInv57:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_ReplaceVsInv57:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_GetVsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_GetXVsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_PutXVsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma PI_Remote_ReplaceVsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma StoreVsInv57:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma StoreHomeVsInv57:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv57  iInv1  iInv2 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash57Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5660185351961015, "lm_q2_score": 0.4649015713733885, "lm_q1q2_score": 0.2631429064391312}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      HoareTotalDef.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection \\<open>Hoare Logic for Total Correctness\\<close>\n\ntheory HoareTotalDef imports HoarePartialDef Termination begin \n\nsubsection \\<open>Validity of Hoare Tuples: \\<open>\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\\<close>\\<close>\n\ndefinition\n  validt :: \"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com,'s assn,'s assn] \\<Rightarrow> bool\"\n                (\"_\\<Turnstile>\\<^sub>t\\<^bsub>'/_\\<^esub>/ _ _ _,_\"  [61,60,1000, 20, 1000,1000] 60)\nwhere\n \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<equiv> \\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<and> (\\<forall>s \\<in> Normal ` P. \\<Gamma>\\<turnstile>c\\<down>s)\"\n\ndefinition\n  cvalidt::\n  \"[('s,'p,'f) body,('s,'p) quadruple set,'f set,\n    's assn,('s,'p,'f) com,'s assn,'s assn] \\<Rightarrow> bool\"\n                (\"_,_\\<Turnstile>\\<^sub>t\\<^bsub>'/_\\<^esub>/ _ _ _,_\"  [61,60, 60,1000, 20, 1000,1000] 60)\nwhere\n \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<equiv> (\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A) \\<longrightarrow> \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n\n\n\nnotation (ASCII)\n  validt  (\"_|=t'/_/ _ _ _,_\"  [61,60,1000, 20, 1000,1000] 60) and\n  cvalidt  (\"_,_|=t'/_ / _ _ _,_\"  [61,60,60,1000, 20, 1000,1000] 60)\n\nsubsection \\<open>Properties of Validity\\<close>\n\nlemma validtI: \n \"\\<lbrakk>\\<And>s t. \\<lbrakk>\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t;s \\<in> P;t \\<notin> Fault ` F\\<rbrakk> \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A;\n   \\<And>s. s \\<in> P \\<Longrightarrow> \\<Gamma>\\<turnstile> c\\<down>(Normal s) \\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (auto simp add: validt_def valid_def)\n\nlemma cvalidtI: \n \"\\<lbrakk>\\<And>s t. \\<lbrakk>\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A;\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t;s \\<in> P; \n          t \\<notin> Fault ` F\\<rbrakk> \n          \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A;\n   \\<And>s. \\<lbrakk>\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A; s\\<in>P\\<rbrakk> \\<Longrightarrow>  \\<Gamma>\\<turnstile>c\\<down>(Normal s)\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (auto simp add: cvalidt_def validt_def valid_def)\n\nlemma cvalidt_postD: \n \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A; \\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A;\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> t;\n   s \\<in> P;t \\<notin> Fault ` F\\<rbrakk> \n  \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  by (simp add: cvalidt_def validt_def valid_def)\n\nlemma cvalidt_termD: \n \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A; \\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A;s \\<in> P\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>\\<turnstile>c\\<down>(Normal s)\"\n  by (simp add: cvalidt_def validt_def valid_def)\n\n\nlemma validt_augment_Faults:\n  assumes valid:\"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes F': \"F \\<subseteq> F'\"\n  shows \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F'\\<^esub> P c Q,A\"\n  using valid F'\n  by (auto intro: valid_augment_Faults simp add: validt_def)\n\nsubsection \\<open>The Hoare Rules: \\<open>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\\<close>\\<close>\n\ninductive \"hoaret\"::\"[('s,'p,'f) body,('s,'p) quadruple set,'f set,\n                        's assn,('s,'p,'f) com,'s assn,'s assn] \n                       => bool\"\n    (\"(3_,_/\\<turnstile>\\<^sub>t\\<^bsub>'/_\\<^esub> (_/ (_)/ _,_))\" [61,60,60,1000,20,1000,1000]60)  \n   for \\<Gamma>::\"('s,'p,'f) body\"\nwhere\n  Skip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> Q Skip Q,A\"\n\n| Basic: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. f s \\<in> Q} (Basic f) Q,A\"\n\n| Spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. (\\<forall>t. (s,t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s,t) \\<in> r)} (Spec r) Q,A\"\n\n| Seq: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 R,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk>\n        \\<Longrightarrow>\n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Seq c\\<^sub>1 c\\<^sub>2 Q,A\"\n  \n| Cond: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> b) c\\<^sub>1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> - b) c\\<^sub>2 Q,A\\<rbrakk>\n         \\<Longrightarrow> \n         \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) Q,A\"\n\n| While: \"\\<lbrakk>wf r; \\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P \\<inter> b) c ({t. (t,\\<sigma>)\\<in>r} \\<inter> P),A\\<rbrakk>\n          \\<Longrightarrow>\n          \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (While b c) (P \\<inter> - b),A\"\n\n| Guard: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\n          \\<Longrightarrow>\n          \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) Guard f g c Q,A\"\n\n| Guarantee: \"\\<lbrakk>f \\<in> F; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\n\n| CallRec: \n  \"\\<lbrakk>(P,p,Q,A) \\<in> Specs;\n    wf r; \n    Specs_wf = (\\<lambda>p \\<sigma>. (\\<lambda>(P,q,Q,A). (P \\<inter> {s. ((s,q),(\\<sigma>,p)) \\<in> r},q,Q,A)) ` Specs);\n    \\<forall>(P,p,Q,A)\\<in> Specs. \n      p \\<in> dom \\<Gamma> \\<and> (\\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<union> Specs_wf p \\<sigma>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P) (the (\\<Gamma> p)) Q,A)\n    \\<rbrakk>\n    \\<Longrightarrow>\n    \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n\n\n| DynCom:  \"\\<forall>s \\<in> P. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (c s) Q,A \n            \\<Longrightarrow> \n            \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (DynCom c) Q,A\"\n\n\n| Throw: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> A Throw Q,A\"\n\n| Catch: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk> \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Catch c\\<^sub>1 c\\<^sub>2 Q,A\"\n\n| Conseq: \"\\<forall>s \\<in> P. \\<exists>P' Q' A'. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A' \\<and> s \\<in> P' \\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A \n           \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n\n\n| Asm: \"(P,p,Q,A) \\<in> \\<Theta> \n        \\<Longrightarrow> \n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n\n| ExFalso: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A; \\<not> \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  \\<comment> \\<open>This is a hack rule that enables us to derive completeness for\n        an arbitrary context \\<open>\\<Theta>\\<close>, from completeness for an empty context.\\<close>\n\n  \ntext \\<open>Does not work, because of rule ExFalso, the context \\<open>\\<Theta>\\<close> is to blame.\n A weaker version with empty context can be derived from soundness \n later on.\\<close>\nlemma hoaret_to_hoarep:\n  assumes hoaret: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P p Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P p Q,A\"\nusing hoaret\nproof (induct)\n  case Skip thus ?case by (rule hoarep.intros)\nnext\n  case Basic thus ?case by (rule hoarep.intros)\nnext\n  case Seq thus ?case by - (rule hoarep.intros)\nnext\n  case Cond thus ?case by - (rule hoarep.intros)\nnext\n  case (While r \\<Theta> F P b c A)\n  hence \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P \\<inter> b) c ({t. (t, \\<sigma>) \\<in> r} \\<inter> P),A\"\n    by iprover\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> b) c P,A\"\n    by (rule HoarePartialDef.conseq) blast\n  then show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P While b c (P \\<inter> - b),A\"\n    by (rule hoarep.While)\nnext\n  case Guard thus ?case by - (rule hoarep.intros)\n(*next\n  case (CallRec A F P Procs Q Z \\<Theta>  p r)\n  hence hyp: \"\\<forall>p\\<in>Procs. \\<forall>\\<tau> Z. \n           \\<Gamma>,\\<Theta> \\<union> (\\<Union>q\\<in>Procs. \\<Union>Z. {(P q Z \\<inter> {s. ((s, q), \\<tau>, p) \\<in> r},\n                      Call q, Q q Z,A q Z)})\\<turnstile>\\<^bsub>/F\\<^esub>\n              ({\\<tau>} \\<inter> P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n    by blast\n  have \"\\<forall>p\\<in>Procs. \\<forall>Z. \n           \\<Gamma>,\\<Theta> \\<union> (\\<Union>q\\<in>Procs. \\<Union>Z. {(P q Z,\n                      Call q, Q q Z,A q Z)})\\<turnstile>\\<^bsub>/F\\<^esub>\n              (P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\" \n  proof (intro ballI allI)\n    fix p Z\n    assume \"p \\<in> Procs\"\n    with hyp\n    have hyp': \"\\<And> \\<tau>. \n           \\<Gamma>,\\<Theta> \\<union> (\\<Union>q\\<in>Procs. \\<Union>Z. {(P q Z \\<inter> {s. ((s, q), \\<tau>, p) \\<in> r},\n                      Call q, Q q Z, A q Z)})\\<turnstile>\\<^bsub>/F\\<^esub>\n              ({\\<tau>} \\<inter> P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n      by blast\n    have \"\\<forall>\\<tau>. \n           \\<Gamma>,\\<Theta> \\<union> (\\<Union>q\\<in>Procs. \\<Union>Z. {(P q Z,\n                      Call q, Q q Z,A q Z)})\\<turnstile>\\<^bsub>/F\\<^esub>\n              ({\\<tau>} \\<inter> P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n      (is \"\\<forall>\\<tau>. \\<Gamma>,?\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\")\n    proof (rule allI, rule WeakenContext [OF hyp'],clarify)\n      fix \\<tau> P' c Q' A'\n      assume \"(P', c, Q', A') \\<in> \\<Theta> \\<union>\n         (\\<Union>q\\<in>Procs.\n             \\<Union>Z. {(P q Z \\<inter> {s. ((s, q), \\<tau>, p) \\<in> r},\n                  Call q, Q q Z,\n                  A q Z)})\" (is \"(P', c, Q', A') \\<in> \\<Theta> \\<union> ?Spec\")\n      then show \"\\<Gamma>,?\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> P' c Q',A'\"\n      proof (cases rule: UnE [consumes 1])\n        assume \"(P',c,Q',A') \\<in> \\<Theta>\" \n        then show ?thesis\n          by (blast intro: HoarePartialDef.Asm)\n      next\n        assume \"(P',c,Q',A') \\<in> ?Spec\" \n        then show ?thesis\n        proof (clarify)\n          fix q Z\n          assume q: \"q \\<in> Procs\"\n          show \"\\<Gamma>,?\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> (P q Z \\<inter> {s. ((s, q), \\<tau>, p) \\<in> r}) \n                         Call  q \n                        (Q q Z),(A q Z)\"\n          proof -\n            from q\n            have \"\\<Gamma>,?\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> (P q Z) Call q (Q q Z),(A q Z)\"\n              by - (rule HoarePartialDef.Asm,blast)\n            thus ?thesis\n              by (rule HoarePartialDef.conseqPre) blast\n          qed\n        qed\n      qed\n    qed\n    then show \"\\<Gamma>,\\<Theta> \\<union> (\\<Union>q\\<in>Procs. \\<Union>Z. {(P q Z, Call q, Q q Z,A q Z)})\n                \\<turnstile>\\<^bsub>/F\\<^esub> (P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n      by (rule HoarePartialDef.conseq) blast\n  qed\n  thus ?case\n    by - (rule hoarep.CallRec)*)\nnext\n  case DynCom thus ?case by (blast intro: hoarep.DynCom)\nnext\n  case Throw thus ?case by - (rule hoarep.Throw)\nnext\n  case Catch thus ?case by - (rule hoarep.Catch)\nnext\n  case Conseq thus ?case by - (rule hoarep.Conseq,blast)\nnext\n  case Asm thus ?case by (rule HoarePartialDef.Asm)\nnext\n  case (ExFalso \\<Theta> F P c Q A)\n  assume \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  hence \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n    oops\n\n\nlemma hoaret_augment_context: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P p Q,A\"\n  shows \"\\<And>\\<Theta>'. \\<Theta> \\<subseteq> \\<Theta>' \\<Longrightarrow> \\<Gamma>,\\<Theta>'\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P p Q,A\"\nusing deriv\nproof (induct)\n  case (CallRec P p Q A Specs r Specs_wf \\<Theta> F \\<Theta>')\n  have aug: \"\\<Theta> \\<subseteq> \\<Theta>'\" by fact\n  then\n  have h: \"\\<And>\\<tau> p. \\<Theta> \\<union> Specs_wf p \\<tau>\n       \\<subseteq> \\<Theta>' \\<union> Specs_wf p \\<tau>\"\n    by blast\n  have \"\\<forall>(P,p,Q,A)\\<in>Specs. p \\<in> dom \\<Gamma> \\<and>\n     (\\<forall>\\<tau>. \\<Gamma>,\\<Theta> \\<union> Specs_wf p \\<tau>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> p)) Q,A \\<and>\n           (\\<forall>x. \\<Theta> \\<union> Specs_wf p \\<tau>\n                 \\<subseteq> x \\<longrightarrow>\n                 \\<Gamma>,x\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> p)) Q,A))\" by fact\n  hence \"\\<forall>(P,p,Q,A)\\<in>Specs. p \\<in> dom \\<Gamma> \\<and> \n         (\\<forall>\\<tau>. \\<Gamma>,\\<Theta>'\\<union> Specs_wf p \\<tau> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> p)) Q,A)\"\n    apply (clarify)\n    apply (rename_tac P p Q A)\n    apply (drule (1) bspec)\n    apply (clarsimp)\n    apply (erule_tac x=\\<tau> in allE)\n    apply clarify\n    apply (erule_tac x=\"\\<Theta>' \\<union> Specs_wf p \\<tau>\" in allE)\n    apply (insert aug)\n    apply auto\n    done\n  with CallRec show ?case by - (rule hoaret.CallRec)\nnext\n  case DynCom thus ?case by (blast intro: hoaret.DynCom)\nnext\n  case (Conseq P \\<Theta> F c Q A \\<Theta>')\n  from Conseq\n  have \"\\<forall>s \\<in> P. (\\<exists>P' Q' A'. (\\<Gamma>,\\<Theta>' \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A') \\<and> s \\<in> P'\\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A)\"\n    by blast\n  with Conseq show ?case by - (rule hoaret.Conseq)\nnext\n  case (ExFalso \\<Theta> F P  c Q A \\<Theta>')\n  have \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" \"\\<not> \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" \"\\<Theta> \\<subseteq> \\<Theta>'\"  by fact+\n  then show ?case\n    by (fastforce intro: hoaret.ExFalso simp add: cvalidt_def)\nqed (blast intro: hoaret.intros)+\n\nsubsection \\<open>Some Derived Rules\\<close>\n\n\nlemma  Conseq': \"\\<forall>s. s \\<in> P \\<longrightarrow> \n            (\\<exists>P' Q' A'. \n              (\\<forall> Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z)) \\<and>\n                    (\\<exists>Z. s \\<in> P' Z \\<and> (Q' Z \\<subseteq> Q) \\<and> (A' Z \\<subseteq> A)))\n           \\<Longrightarrow>\n           \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\napply (rule Conseq)\napply (rule ballI)\napply (erule_tac x=s in allE)\napply (clarify)\napply (rule_tac x=\"P' Z\" in exI)\napply (rule_tac x=\"Q' Z\" in exI)\napply (rule_tac x=\"A' Z\" in exI)\napply blast\ndone\n\nlemma conseq:\"\\<lbrakk>\\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z);\n              \\<forall>s. s \\<in> P \\<longrightarrow> (\\<exists> Z. s\\<in>P' Z \\<and> (Q' Z \\<subseteq> Q)\\<and> (A' Z \\<subseteq> A))\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule Conseq) blast\n\ntheorem conseqPrePost: \n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A' \\<Longrightarrow> P \\<subseteq> P' \\<Longrightarrow>  Q' \\<subseteq> Q \\<Longrightarrow> A' \\<subseteq> A \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule conseq [where ?P'=\"\\<lambda>Z. P'\" and ?Q'=\"\\<lambda>Z. Q'\"]) auto\n\nlemma conseqPre: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q,A \\<Longrightarrow> P \\<subseteq> P' \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nby (rule conseq) auto\n\nlemma conseqPost: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q',A'\\<Longrightarrow> Q' \\<subseteq> Q \\<Longrightarrow> A' \\<subseteq> A \\<Longrightarrow>   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule conseq) auto\n\n\nlemma Spec_wf_conv: \n  \"(\\<lambda>(P, q, Q, A). (P \\<inter> {s. ((s, q), \\<tau>, p) \\<in> r}, q, Q, A)) `\n                (\\<Union>p\\<in>Procs. \\<Union>Z. {(P p Z, p, Q p Z, A p Z)}) = \n        (\\<Union>q\\<in>Procs. \\<Union>Z. {(P q Z \\<inter> {s. ((s, q), \\<tau>, p) \\<in> r}, q, Q q Z, A q Z)})\"\n  by (auto intro!: image_eqI)\n\nlemma CallRec': \n  \"\\<lbrakk>p\\<in>Procs; Procs \\<subseteq> dom \\<Gamma>;\n    wf r; \n   \\<forall>p\\<in>Procs. \\<forall>\\<tau> Z. \n   \\<Gamma>,\\<Theta>\\<union>(\\<Union>q\\<in>Procs. \\<Union>Z. \n    {((P q Z) \\<inter> {s. ((s,q),(\\<tau>,p)) \\<in> r},q,Q q Z,(A q Z))})\n     \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> (P p Z)) (the (\\<Gamma> p)) (Q p Z),(A p Z)\\<rbrakk>\n   \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P p Z) (Call p) (Q p Z),(A p Z)\"\napply (rule CallRec [where Specs=\"\\<Union>p\\<in>Procs. \\<Union>Z. {((P p Z),p,Q p Z,A p Z)}\" and\n         r=r])\napply    blast\napply   assumption\napply  (rule refl)\napply (clarsimp)\napply (rename_tac p')\napply (rule conjI)\napply  blast\napply (intro allI)\napply (rename_tac Z \\<tau>)\napply (drule_tac x=p' in bspec, assumption)\napply (erule_tac x=\\<tau> in allE)\napply (erule_tac x=Z in allE)\napply (fastforce simp add: Spec_wf_conv)\ndone\n\nend\n\n", "meta": {"author": "LVPGroup", "repo": "TimSort", "sha": "16437b6b6e2df9f6d32b2a32be7d0d650d83f980", "save_path": "github-repos/isabelle/LVPGroup-TimSort", "path": "github-repos/isabelle/LVPGroup-TimSort/TimSort-16437b6b6e2df9f6d32b2a32be7d0d650d83f980/Simpl/HoareTotalDef.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.611381973294151, "lm_q2_score": 0.43014734858584286, "lm_q1q2_score": 0.26298433478565963}}
{"text": "theory Final_ML\n  imports Semantics_Final\nbegin\n\nML \\<open>\nval pwriteln = Pretty.writeln\nval pretty_term = Syntax.pretty_term\n\\<close>\n\\<comment> \\<open>temporal logic expression\\<close>\nML \\<open>\nfun tempval ctxt temp v p = \n  let val fun_h1 = nth (v |> Thm.term_of |> Term.strip_comb |> snd) 1\n      val fun_h2 = nth (v |> Thm.term_of |> Term.strip_comb |> snd) 2\n      val ch1 = Thm.cterm_of ctxt fun_h1\n      val ch2 = Thm.cterm_of ctxt fun_h2\n  in\n    case temp of\n      Const (@{const_name \"Before\"}, _) $ event $ n =>\n      let\n        val cevent = Thm.cterm_of @{context} event\n        val cn = Thm.cterm_of @{context} n\n        val before_th = @{thm Before};\n        val args = before_th |> Thm.concl_of |> \n            Term.dest_comb |> snd |> Term.strip_comb |> snd |> hd |> Term.strip_comb |> snd\n        val idp = nth args 2 |> Term.dest_Var\n        val idE = hd args |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n        val idn = hd args |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n        val idh1 = nth (tl args |> hd |> Term.strip_comb |> snd) 1 |> Term.dest_Var\n        val idh2 = nth (tl args |> hd |> Term.strip_comb |> snd) 2 |> Term.dest_Var\n        val th1 = before_th |> Drule.instantiate_normalize ([], [(idE, cevent), (idp, p), \n            (idn, cn), (idh1, ch1), (idh2, ch2)])\n        val th1' = th1 RS @{thm eq_reflection}\n        val rhs = th1' |> Thm.rhs_of\n        val th2 = Simplifier.asm_full_rewrite ctxt rhs;\n        val rhs2 = th2 |> Thm.rhs_of\n        val b1 = (Thm.term_of rhs2 aconv @{term True})\n        val b2 = (Thm.term_of rhs2 aconv @{term False})\n      in\n        (if b1 then true else (if b2 then false \n        else (raise TERM (\"Expression can't be simplified!\", []))))\n        (*Thm.term_of rhs2 aconv @{term True}*)\n      end\n   |  Const (@{const_name \"After\"}, _) $ event $ n =>\n      let\n        val cevent = Thm.cterm_of @{context} event\n        val cn = Thm.cterm_of @{context} n\n        val after_th = @{thm After};\n        val args = after_th |> Thm.concl_of |> \n            Term.dest_comb |> snd |> Term.strip_comb |> snd |> hd |> Term.strip_comb |> snd\n        val idp = nth args 2 |> Term.dest_Var\n        val idE = hd args |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n        val idn = hd args |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n        val idh1 = nth (tl args |> hd |> Term.strip_comb |> snd) 1 |> Term.dest_Var\n        val idh2 = nth (tl args |> hd |> Term.strip_comb |> snd) 2 |> Term.dest_Var\n        val th1 = after_th |> Drule.instantiate_normalize ([], [(idE, cevent), (idp, p), \n            (idn, cn), (idh1, ch1), (idh2, ch2)])\n        val th1' = th1 RS @{thm eq_reflection}\n        val rhs = th1' |> Thm.rhs_of\n        val th2 = Simplifier.asm_full_rewrite ctxt rhs;\n        val rhs2 = th2 |> Thm.rhs_of\n        val b1 = (Thm.term_of rhs2 aconv @{term True})\n        val b2 = (Thm.term_of rhs2 aconv @{term False})\n      in\n        (if b1 then true else (if b2 then false \n        else (raise TERM (\"Expression can't be simplified!\", []))))\n        (*Thm.term_of rhs2 aconv @{term True}*)\n      end\n   |  Const (@{const_name \"At\"}, _) $ event $ n =>\n      let\n        val cevent = Thm.cterm_of @{context} event\n        val cn = Thm.cterm_of @{context} n\n        val at_th = @{thm At};\n        val args = at_th |> Thm.concl_of |> \n            Term.dest_comb |> snd |> Term.strip_comb |> snd |> hd |> Term.strip_comb |> snd\n        val idp = nth args 2 |> Term.dest_Var\n        val idE = hd args |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n        val idn = hd args |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n        val idh1 = nth (tl args |> hd |> Term.strip_comb |> snd) 1 |> Term.dest_Var\n        val idh2 = nth (tl args |> hd |> Term.strip_comb |> snd) 2 |> Term.dest_Var\n        val th1 = at_th |> Drule.instantiate_normalize ([], [(idE, cevent), (idp, p), \n            (idn, cn), (idh1, ch1), (idh2, ch2)])\n        val th1' = th1 RS @{thm eq_reflection}\n        val rhs = th1' |> Thm.rhs_of\n        val th2 = Simplifier.asm_full_rewrite ctxt rhs;\n        val rhs2 = th2 |> Thm.rhs_of\n        val b1 = (Thm.term_of rhs2 aconv @{term True})\n        val b2 = (Thm.term_of rhs2 aconv @{term False})\n      in\n        (if b1 then true else (if b2 then false \n        else (raise TERM (\"Expression can't be simplified!\", []))))\n        (*Thm.term_of rhs2 aconv @{term True}*)\n      end\n   |  Const (@{const_name \"Every\"}, _) $ event $ n =>\n      let\n        val cevent = Thm.cterm_of @{context} event\n        val cn = Thm.cterm_of @{context} n\n        val every_th = @{thm Every};\n        val args = every_th |> Thm.concl_of |> \n            Term.dest_comb |> snd |> Term.strip_comb |> snd |> hd |> Term.strip_comb |> snd\n        val idp = nth args 2 |> Term.dest_Var\n        val idE = hd args |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n        val idn = hd args |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n        val idh1 = nth (tl args |> hd |> Term.strip_comb |> snd) 1 |> Term.dest_Var\n        val idh2 = nth (tl args |> hd |> Term.strip_comb |> snd) 2 |> Term.dest_Var\n        val th1 = every_th |> Drule.instantiate_normalize ([], [(idE, cevent), (idp, p), \n            (idn, cn), (idh1, ch1), (idh2, ch2)])\n        val th1' = th1 RS @{thm eq_reflection}\n        val rhs = th1' |> Thm.rhs_of\n        val th2 = Simplifier.asm_full_rewrite ctxt rhs;\n        val rhs2 = th2 |> Thm.rhs_of\n        val b1 = (Thm.term_of rhs2 aconv @{term True})\n        val b2 = (Thm.term_of rhs2 aconv @{term False})\n      in\n        (if b1 then true else (if b2 then false \n        else (raise TERM (\"Expression can't be simplified!\", []))))\n        (*Thm.term_of rhs2 aconv @{term True}*)\n      end\n   |  _ => raise TERM (\"Not supported\", [temp])\n  end\n\\<close>\n\n\\<comment> \\<open>evaluation for update_vals2\\<close>\nML \\<open>\nfun evaluate_update_vals ctxt a1 a2 v = \n  if a1 aconvc @{cterm \"No_Expr\"} then\n    let\n      val Update_NoExpr_th1 = @{thm Update_NoExpr1}\n      val args = Update_NoExpr_th1 |> Thm.concl_of \n                   |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n      val ida2 = nth args 1 |> Term.dest_Var\n      val idv = nth args 2 |> Term.dest_Var\n    in\n      Update_NoExpr_th1  |> Drule.instantiate_normalize ([], [(ida2, a2), (idv, v)])\n    end\n  else if a2 aconvc @{cterm \"No_Expr\"} then\n    let\n      val Update_NoExpr_th2 = @{thm Update_NoExpr2}\n      val args = Update_NoExpr_th2 |> Thm.concl_of \n                   |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n      val ida1 = nth args 0|> Term.dest_Var\n      val idv = nth args 2 |> Term.dest_Var\n    in\n      Update_NoExpr_th2  |> Drule.instantiate_normalize ([], [(ida1, a1), (idv, v)])\n    end\n  else\n    let\n      val Update_aexp2_th = @{thm Update_exp2}\n      val args = Update_aexp2_th |> Thm.concl_of \n                   |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n      val ida1 = nth args 0 |> Term.dest_Var\n      val ida2 = nth args 1 |> Term.dest_Var\n      val idv = nth args 2 |> Term.dest_Var\n      val th1 = Update_aexp2_th  |> Drule.instantiate_normalize ([], [(ida1, a1), \n              (ida2, a2), (idv, v)])\n      val th2 = asm_full_simplify ctxt th1\n      val a1_1 = th2 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                  |> Term.strip_comb |> snd |> hd |> Term.strip_comb |> snd |> hd |>\n                  Thm.cterm_of ctxt\n      val ida1_1 = th2 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                  |> Term.strip_comb |> snd |> hd |> Term.strip_comb |> snd |> tl |> hd |>\n                  Term.dest_Var\n      val a2_1 = th2 |> Thm.prems_of |> tl |> hd |> Term.dest_comb |> snd \n                  |> Term.strip_comb |> snd |> hd |> Term.strip_comb |> snd |> hd |>\n                  Thm.cterm_of ctxt\n      val ida2_1 = th2 |> Thm.prems_of |> tl |> hd |> Term.dest_comb |> snd \n                  |> Term.strip_comb |> snd |> hd |> Term.strip_comb |> snd |> tl |> hd |>\n                  Term.dest_Var\n      val a1_2 = th2 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                  |> Term.strip_comb |> snd |> tl |> hd \n                  |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n      val ida1_2 = th2 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                  |> Term.strip_comb |> snd |> tl |> hd \n                  |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n      val a2_2 = th2 |> Thm.prems_of |> tl |> hd |> Term.dest_comb |> snd \n                  |> Term.strip_comb |> snd |> tl |> hd \n                  |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n      val ida2_2 = th2 |> Thm.prems_of |> tl |> hd |> Term.dest_comb |> snd \n                  |> Term.strip_comb |> snd |> tl |> hd \n                  |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n      val th3 = th2 |> Drule.instantiate_normalize ([], [(ida1_1, a1_1), (ida1_2, a1_2),\n                  (ida2_1, a2_1), (ida2_2, a2_2)])\n      val th4 = asm_full_simplify ctxt th3\n      val th5 = @{thm refl} RS th4\n      val v2 = th5 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n            |> Term.strip_comb |> snd |> tl |> tl |> hd |> Thm.cterm_of ctxt\n      val th_update = evaluate_update_vals ctxt a1_2 a2_2 v2\n    in\n      th_update RS th5\n    end\n\\<close>\n\n\n\\<comment> \\<open>evaluation for some simple actions\\<close>\nML \\<open>\nfun evaluate_skip env e p s = \n  let\n    val skip_th = @{thm Skip}\n    val args = skip_th |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n    val idenv = nth args 0 |> Term.dest_Var\n    val ide = nth args 2 |> Term.dest_Var\n    val idp = nth args 3 |> Term.dest_Var\n    val ids = nth args 4 |> Term.dest_Var\n  in\n    skip_th |> Drule.instantiate_normalize ([], [(idenv, env), (ide, e),\n        (idp, p), (ids, s)])\n  end\n\\<close>\n\nML \\<open>\nval ctxt = @{context}\nfun evaluate_assign ctxt env x a e p s = \n  let\n    val v = s |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n    val I = s |> Thm.term_of |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n    val assign_th = @{thm Assign}\n    val args = assign_th |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n    val idenv = nth args 0 |> Term.dest_Var\n    val idx = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n    val ida = nth args 1 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n    val ide = nth args 2 |> Term.dest_Var\n    val idp = nth args 3 |> Term.dest_Var\n    val idv = nth args 4 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n    val idI = nth args 4 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n    val th1 = assign_th |> Drule.instantiate_normalize ([], [(idenv, env),(idv, v), (idp, p), \n        (ide, e), (idI, I), (idx, x), (ida, a)])\n    val th2 = [@{thm refl}, @{thm refl}] MRS th1\n  in\n    asm_full_simplify ctxt th2\n  end\n\\<close>\n\nML \\<open>\nfun evaluate_On1 ctxt env temp as1 e p s = \n  let\n    val ON1_th = @{thm On1}\n    val args = ON1_th |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n    val idenv = nth args 0 |> Term.dest_Var\n    val idt = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n    val idas = nth args 1 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n    val ide = nth args 2 |> Term.dest_Var\n    val idp = nth args 3 |> Term.dest_Var\n    val ids = nth args 4 |> Term.dest_Var\n    val x = as1 |> Thm.dest_arg1\n    val a = as1 |> Thm.dest_arg\n    val th_assign = evaluate_assign ctxt env x a e p s\n    val th1 = ON1_th |> Drule.instantiate_normalize ([], [(idenv, env), (idt, temp), \n      (idas, as1), (ide, e), (idp, p), (ids, s)]);\n    val th2 = asm_full_simplify ctxt th1\n  in\n    [th_assign] MRS th2\n  end;\n\nfun evaluate_On2 ctxt env temp as1 e p s = \n  let\n    val ON2_th = @{thm On2}\n    val args = ON2_th |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n    val idenv = nth args 0 |> Term.dest_Var\n    val idt = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n    val idas = nth args 1 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n    val ide = nth args 2 |> Term.dest_Var\n    val idp = nth args 3 |> Term.dest_Var\n    val ids = nth args 4 |> Term.dest_Var\n    val th1 = ON2_th |> Drule.instantiate_normalize ([], [(idenv, env),(idt, temp), (idas, as1), \n         (ide, e), (idp, p),(ids, s)])\n  in\n    asm_full_simplify ctxt th1\n  end\n\nfun evaluate_On3 ctxt env event as1 e p s = \n  let\n    val ON3_th = @{thm On3}\n    val args = ON3_th |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n    val idenv = nth args 0 |> Term.dest_Var\n    val idt = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n    val idas = nth args 1 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n    val ide = nth args 2 |> Term.dest_Var\n    val idp = nth args 3 |> Term.dest_Var\n    val ids = nth args 4 |> Term.dest_Var\n    val x = as1 |> Thm.dest_arg1\n    val a = as1 |> Thm.dest_arg\n    val _ = pwriteln (pretty_term ctxt (Thm.term_of as1))\n    val th_assign = evaluate_assign ctxt env x a e p s\n    val th1 = ON3_th |> Drule.instantiate_normalize ([], [(idenv, env),(idt, event), (idas, as1), \n         (ide, e), (idp, p),(ids, s)])\n    val th2 = asm_full_simplify ctxt th1\n  in\n    th_assign RS th2\n  end\n\nfun evaluate_On4 ctxt env event as1 e p s = \n  let\n    val ON4_th = @{thm On4}\n    val args = ON4_th |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n    val idenv = nth args 0 |> Term.dest_Var\n    val idt = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n    val idas = nth args 1 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n    val ide = nth args 2 |> Term.dest_Var\n    val idp = nth args 3 |> Term.dest_Var\n    val ids = nth args 4 |> Term.dest_Var\n    val th1 = ON4_th |> Drule.instantiate_normalize ([], [(idenv, env),(idt, event), (idas, as1), \n         (ide, e), (idp, p),(ids, s)])\n  in\n    asm_full_simplify ctxt th1\n  end\n\\<close>\n\n\nML \\<open>\nfun evaluate_Print1 ctxt env message e p s = \n  let\n    val v = s |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n    val I = s |> Thm.term_of |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n    val print1_th = @{thm Print1}\n    val args = print1_th |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n    val idenv = nth args 0 |> Term.dest_Var\n    val idmessage = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n    val ide = nth args 2 |> Term.dest_Var\n    val idp = nth args 3 |> Term.dest_Var\n    val idv = nth args 4 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n    val idI = nth args 4 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n    val th1 = print1_th |> Drule.instantiate_normalize ([], [(idenv, env),(idv, v), (idp, p), \n     (idmessage, message), (idI, I), (ide, e)])\n    val th2 = [@{thm refl},@{thm refl}] MRS th1\n  in\n    asm_full_simplify ctxt th2\n  end;\n\nfun evaluate_Print2 ctxt env message e p s = \n  let\n    val v = s |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n    val I = s |> Thm.term_of |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n    val print2_th = @{thm Print2}\n    val args = print2_th |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n    val idenv = nth args 0 |> Term.dest_Var\n    val idmessage = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n    val ide = nth args 2 |> Term.dest_Var\n    val idp = nth args 3 |> Term.dest_Var\n    val idv = nth args 4 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n    val idI = nth args 4 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n    val th1 = print2_th |> Drule.instantiate_normalize ([], [(idenv, env),(idv, v), (idp, p), \n     (idmessage, message), (idI, I), (ide, e)])\n    val th2 = [@{thm refl}, @{thm refl}] MRS th1\n  in\n    asm_full_simplify ctxt th2\n  end\n\\<close>\n\nML \\<open>\nfun evaluate_Send5 ctxt env msg e p s = \nlet\n  val v = s |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n  val I = s |> Thm.term_of |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n  val send5_th = @{thm Send5}\n  val args = send5_th |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n  val idenv = nth args 0 |> Term.dest_Var\n  val idmsg = nth args 1 |> Term.dest_comb |> snd |> Term.dest_Var\n  val ide = nth args 2 |> Term.dest_Var\n  val idp = nth args 3 |> Term.dest_Var\n  val idv = nth args 4 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n  val idI = nth args 4 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n  val th1 = send5_th |> Drule.instantiate_normalize ([], [(idenv, env),(idv, v), (idp, p), \n     (idmsg, msg), (idI, I), (ide, e)])\n  val th2 = @{thm refl} RS th1\nin\n  asm_full_simplify ctxt th2\nend\n\\<close>\n\nML \\<open>\nfun evaluate_al1 env e p s = \n  let\n    val al1_th = @{thm ActionList_Execution1}\n    val args = al1_th |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n    (*val ida = args |> hd |> Term.strip_comb |> snd |> hd |> Term.dest_Var*)\n    val idenv = nth args 0 |> Term.dest_Var\n    val ide = nth args 2 |> Term.dest_Var\n    val idp = nth args 3 |> Term.dest_Var\n    val ids = nth args 4|> Term.dest_Var\n  in\n    al1_th |> Drule.instantiate_normalize ([], [(idenv, env), (ide, e), \n    (idp, p), (ids, s)])\n  end\n\\<close>\n\n\\<comment> \\<open>Enable\\<close>\nML \\<open>\nfun enable_ML ctxt t e s p = \n  let\n    val condition = nth (t |> Thm.term_of |> Term.strip_comb |> snd) 1 \n    val c = nth (t |> Thm.term_of |> Term.strip_comb |> snd) 2 |> (Thm.cterm_of ctxt)\n    val src = nth (t |> Thm.term_of |> Term.strip_comb |> snd) 0 |> Thm.cterm_of ctxt\n    val a1 = nth (t |> Thm.term_of |> Term.strip_comb |> snd) 3 |> Thm.cterm_of ctxt\n    val a2 = nth (t |> Thm.term_of |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n    val trg = nth (t |> Thm.term_of |> Term.strip_comb |> snd) 5 |> Thm.cterm_of ctxt\n  in\n    case condition of\n      Const (@{const_name \"S\"}, _) $_ =>\n      let\n        val enable1_th = @{thm Enable1}\n        val str = nth (t |> Thm.term_of |> Term.strip_comb |> snd) 1 |> Term.dest_comb\n                  |> snd |> (Thm.cterm_of ctxt)\n        val args = enable1_th |> Thm.concl_of |> Term.dest_comb \n                  |> snd |> Term.strip_comb |> snd |> tl |> hd |> Term.strip_comb |> snd;\n        val ide = nth args 0 |> Term.strip_comb |> snd |> tl \n                    |> hd |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n        val idstr = nth args 0 |> Term.strip_comb |> snd |> tl \n                  |> hd |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n        val idc = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n        val ids = nth args 1 |> Term.strip_comb |> snd |> tl |> hd |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n        val idp = nth (nth args 1 |> Term.strip_comb |> snd) 2 |> Term.dest_Var;\n        val th1 = enable1_th |> Drule.instantiate_normalize ([], [(idstr,str),(ids, s), (idp, p), \n                 (ide,e),(idc, c)])\n        val th1' = th1 RS @{thm eq_reflection}\n        val rhs = th1' |> Thm.rhs_of\n        val th2 = Simplifier.asm_full_rewrite ctxt rhs;\n        val rhs2 = th2 |> Thm.rhs_of\n      in\n        Thm.term_of rhs2 aconv @{term True}\n      end\n    | Const (@{const_name \"T1\"}, _) $temp' =>\n      let\n        val enable2_th = @{thm Enable2}\n        val temp = Thm.cterm_of ctxt temp'\n        val args = enable2_th |> Thm.concl_of |> Term.dest_comb \n                  |> snd |> Term.strip_comb |> snd |> tl |> hd |> Term.strip_comb |> snd;\n        val idtemp = nth args 0 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n        val idc = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n        val ids = nth args 1 |> Term.strip_comb |> snd |> tl |> hd |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n        val idp = nth (nth args 1 |> Term.strip_comb |> snd) 2 |> Term.dest_Var;\n        val th1 = enable2_th |> Drule.instantiate_normalize ([], [(idtemp,temp),(ids, s), (idp, p), \n                 (idc, c)])\n        val th1' = th1 RS @{thm eq_reflection}\n        val rhs = th1' |> Thm.rhs_of\n        val th2 = Simplifier.asm_full_rewrite ctxt rhs\n        val rhs2 = th2 |> Thm.rhs_of\n      in\n        Thm.term_of rhs2 aconv @{term True}\n      end\n  | Const (@{const_name \"M\"}, _) $msg' =>\n      let\n        val enable3_th = @{thm Enable3}\n        val msg = Thm.cterm_of ctxt msg'\n        val args = enable3_th |> Thm.concl_of |> Term.dest_comb \n          |> snd |> Term.strip_comb |> snd |> tl |> hd |> Term.strip_comb |> snd\n        val idmsg = nth args 0 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_comb \n          |> snd |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n        val ids = nth args 0 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_comb \n                |> snd |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n        val idc = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n        val idp = nth args 1 |> Term.strip_comb |> snd |> tl |> tl |> hd |> Term.dest_Var\n        val idsrc = nth (nth args 1 |> Term.strip_comb |> snd |> tl |> hd \n            |> Term.dest_comb |> snd |> Term.strip_comb |> snd \n            |> hd |> Term.strip_comb |> snd) 0 |> Term.dest_Var\n        val ida1 = nth (nth args 1 |> Term.strip_comb |> snd |> tl |> hd \n            |> Term.dest_comb |> snd |> Term.strip_comb |> snd \n            |> hd |> Term.strip_comb |> snd) 3 |> Term.dest_Var\n        val ida2 = nth (nth args 1 |> Term.strip_comb |> snd |> tl |> hd \n            |> Term.dest_comb |> snd |> Term.strip_comb |> snd \n            |> hd |> Term.strip_comb |> snd) 4 |> Term.dest_Var\n        val idtrg = nth (nth args 1 |> Term.strip_comb |> snd |> tl |> hd \n            |> Term.dest_comb |> snd |> Term.strip_comb |> snd \n            |> hd |> Term.strip_comb |> snd) 5 |> Term.dest_Var\n        val th1 = enable3_th |> Drule.instantiate_normalize ([], [(idmsg,msg),(ids, s),\n          (idc, c), (idp, p), (idsrc, src), (ida1, a1), (ida2, a2), (idtrg, trg)])\n        val th1' = th1 RS @{thm eq_reflection}\n        val rhs = th1' |> Thm.rhs_of\n        val th2 = Simplifier.asm_full_rewrite ctxt rhs\n        val rhs2 = th2 |> Thm.rhs_of\n      in\n        Thm.term_of rhs2 aconv @{term True}\n      end\n  | _ => raise TERM (\"Not supported\", [condition])\n  end\n\\<close>\n\nML\\<open>\nval ctxt = @{context}\nval t = @{cterm \"Trans (P [''A'']) (M ''a'') \n((V ''x'') [>] (V ''y'')) SKIP SKIP (P [''B''])\"}\nval e = @{cterm \"''E''\"}\nval s = @{cterm \"Status v I \"}\nval p = @{cterm \"[''A'']\"}\nval condition = nth (t |> Thm.term_of |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\nval src = nth (t |> Thm.term_of |> Term.strip_comb |> snd) 0 |> Thm.cterm_of ctxt\nval a1 = nth (t |> Thm.term_of |> Term.strip_comb |> snd) 3 |> Thm.cterm_of ctxt\nval a2 = nth (t |> Thm.term_of |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\nval trg = nth (t |> Thm.term_of |> Term.strip_comb |> snd) 5 |> Thm.cterm_of ctxt;\nval res = enable_ML ctxt t e s p\n\\<close>\n\n\nML \\<open>\nfun evaluate_Fail ctxt env t e p s = \n  let\n    val Fail_th  = @{thm Fail}\n    val args = Fail_th |> Thm.concl_of  |> Term.strip_comb |> snd |> hd \n                   |> Term.strip_comb |> snd \n    val idenv = nth args 0 |> Term.dest_Var\n    val idt = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n    val ide = nth args 2 |> Term.dest_Var\n    val idp = nth args 3 |> Term.dest_Var\n    val ids = nth args 4 |> Term.dest_Var\n    val th1 = Fail_th |> Drule.instantiate_normalize ([], [(idt,t), (idp, p), \n             (idenv, env), (ids, s), (ide, e)])\n    val th2 = asm_full_simplify ctxt th1\n  in\n    @{thm refl} RS th2\n  end\n\\<close>\n\nML \\<open>\nfun evaluate_Termination env e p s = \n  let\n    val Term_th = @{thm Termination}\n    val args = Term_th |> Thm.concl_of  |> Term.strip_comb |> snd |> hd \n                   |> Term.strip_comb |> snd\n    val idenv = nth args 0 |> Term.dest_Var\n    val ide = nth args 2 |> Term.dest_Var\n    val idp = nth args 3 |> Term.dest_Var\n    val ids = nth args 4 |> Term.dest_Var\n  in\n    Term_th |> Drule.instantiate_normalize ([], [(idp, p), \n             (idenv, env), (ids, s), (ide, e)])\n  end\n\\<close>\n\n\n\nML \\<open>\nfun evaluate_No_Composition_Exit env name e s = \n  let\n    val No_Composition_Exit_th = @{thm No_Composition_Exit}\n    val args = No_Composition_Exit_th |> Thm.concl_of |> Term.dest_comb \n               |> snd |> Term.strip_comb |> snd\n    val idenv = nth args 0 |> Term.dest_Var\n    val idname = nth args 2 |> Term.dest_Var\n    val ide = nth args 3 |> Term.dest_Var\n    val ids = nth args 4 |> Term.dest_Var\n  in\n     No_Composition_Exit_th |> Drule.instantiate_normalize ([], [(idenv, env), (idname, name),\n        (ide, e), (ids, s)])\n  end\n\\<close>\n\nML \\<open>\nfun evaluate_No_State_Exit ctxt env e s = \n  let\n    val No_State_Exit_th = @{thm State_Exit2}\n    val args = No_State_Exit_th |> Thm.concl_of |> Term.dest_comb \n               |> snd |> Term.strip_comb |> snd\n    val idenv = nth args 0 |> Term.dest_Var\n    val ide = nth args 2 |> Term.dest_Var\n    val ids = nth args 3 |> Term.dest_Var\n    val th1 = No_State_Exit_th |> Drule.instantiate_normalize ([], [(idenv, env),(ide, e), \n               (ids, s)])\n  in\n    asm_full_simplify ctxt th1\n  end\n\\<close>\n\nML \\<open>\nfun evaluate_State_Exit3 ctxt env ST e s = \n  let\n    val State_Exit3_th = @{thm State_Exit3}\n    val args = State_Exit3_th |> Thm.concl_of |> Term.dest_comb \n               |> snd |> Term.strip_comb |> snd\n    val idenv = nth args 0 |> Term.dest_Var\n    val idST = nth args 1 |> Term.dest_Var\n    val ide = nth args 2 |> Term.dest_Var\n    val ids = nth args 3 |> Term.dest_Var\n    val th1 = State_Exit3_th |> Drule.instantiate_normalize ([], [(idST,ST),(idenv, env), \n               (ide, e), (ids, s)])\n    val th2 = @{thm refl} RS th1\n  in\n    asm_full_simplify ctxt th2\n  end\n\\<close>\n\nML \\<open>\nfun evaluate_No_State_Entry env e p s = \nlet\n  val No_State_Entry_th = @{thm State_Entry2}\n  val args = No_State_Entry_th |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb\n                   |> snd\n  val idenv = nth args 0 |> Term.dest_Var\n  val ide = nth args 2 |> Term.dest_Var\n  val idp = nth args 3 |> Term.dest_Var\n  val ids = nth args 4 |> Term.dest_Var\nin\n  No_State_Entry_th |> Drule.instantiate_normalize ([], [(idenv, env), (ide, e),\n               (ids, s),(idp, p)])\nend\n\\<close>\n\nML \\<open>\nfun evaluate_No_Composition_Entry env name e p s = \nlet\n  val No_Composition_Entry_th = @{thm No_Composition_Entry}\n  val args = No_Composition_Entry_th |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb\n               |> snd\n  val idenv = nth args 0 |> Term.dest_Var\n  val idname = nth args 2 |> Term.dest_Var\n  val ide = nth args 3 |> Term.dest_Var\n  val idp = nth args 4 |> Term.dest_Var\n  val ids = nth args 5 |> Term.dest_Var\nin\n  No_Composition_Entry_th |> Drule.instantiate_normalize ([], [(idname,name),(ide,e)\n            ,(idenv, env),(idp,p),(ids, s)])\nend\n\\<close>\n\n\nML \\<open>\nfun evaluate_No_State_Execution env e is_send s = \n  let\n    val No_State_Execution_th = @{thm No_State_Execution}\n    val args = No_State_Execution_th |> Thm.concl_of |> Term.dest_comb |> snd \n                |> Term.strip_comb |> snd\n    val idenv = nth args 0 |> Term.dest_Var\n    val ide = nth args 2 |> Term.dest_Var\n    val idis_send = nth args 3 |> Term.dest_Var\n    val ids = nth args 4 |> Term.dest_Var\n  in\n    No_State_Execution_th |> Drule.instantiate_normalize ([], [(idenv, env), (ide, e),\n         (ids, s),(idis_send, is_send)])\n  end\n\\<close>\n\nML \\<open>\nfun evaluate_No_Composition_Execution env name e is_send s = \n  let\n    val No_Composition_Execution_th = @{thm No_Composition_Execution}\n    val args = No_Composition_Execution_th |> Thm.concl_of |> Term.dest_comb |> snd \n                |> Term.strip_comb |> snd\n    val idenv = nth args 0 |> Term.dest_Var\n    val idname = nth args 2 |> Term.dest_Var\n    val ide = nth args 3 |> Term.dest_Var\n    val idis_send = nth args 4 |> Term.dest_Var\n    val ids = nth args 5 |> Term.dest_Var\n  in\n    No_Composition_Execution_th |> Drule.instantiate_normalize ([], [(idenv, env), (ide, e),\n      (ids, s),(idname, name),(idis_send, is_send)])\n  end\n\\<close>\n\nML \\<open>\nfun evaluate_Empty_Pathlist_Execution env f e is_send s = \n  let\n    val Empty_Pathlist_Execution_th = @{thm Empty_Pathlist_Execution}\n    val args = Empty_Pathlist_Execution_th |> Thm.concl_of |> Term.dest_comb |> snd \n                    |> Term.strip_comb |> snd\n    val idenv = nth args 0 |> Term.dest_Var\n    val idf = nth args 2 |> Term.dest_Var\n    val ide = nth args 3 |> Term.dest_Var\n    val idis_send = nth args 4 |> Term.dest_Var\n    val ids = nth args 5 |> Term.dest_Var\n  in\n    Empty_Pathlist_Execution_th |> Drule.instantiate_normalize ([], [(idenv, env), (ide, e),\n      (ids, s),(idf, f),(idis_send, is_send)])\n  end\n\\<close>\n\nML \\<open>\nval ctxt = @{context}\nfun evaluate_Inactive_State_Execution ctxt env ST e is_send s = \n  let\n    val v = s |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n    val I = s |> Thm.term_of |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n    val Inactive_State_Execution_th = @{thm Inactive_State_Execution}\n    val args = Inactive_State_Execution_th |> Thm.concl_of |> Term.dest_comb |> snd \n                    |> Term.strip_comb |> snd\n    val idenv = nth args 0 |> Term.dest_Var\n    val idST = nth args 1 |> Term.dest_Var\n    val ide = nth args 2 |> Term.dest_Var\n    val idis_send = nth args 3 |> Term.dest_Var\n    val idv = nth args 4 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n    val idI = nth args 4 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n    val th1 = Inactive_State_Execution_th |> Drule.instantiate_normalize ([], [(idenv, env), \n        (ide, e),(idST,ST),(idv, v),(idI, I),(idis_send, is_send)])\n    val args2 = th1 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                    |> Term.strip_comb |> snd |> tl |> hd\n                    |> Term.strip_comb |> snd\n    val idname = nth args2 0 |> Term.dest_Var\n    val iden_act = nth args2 1 |> Term.dest_Var\n    val iddu_act = nth args2 2 |> Term.dest_Var\n    val idex_act = nth args2 3 |> Term.dest_Var\n    val idtrans_out = nth args2 4 |> Term.dest_Var\n    val idtrans_in = nth args2 5 |> Term.dest_Var\n    val idC = nth args2 6 |> Term.dest_Var\n    val state = th1 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                    |> Term.strip_comb |> snd |> hd |> Term.strip_comb |> snd\n    val name = nth state 0 |> Thm.cterm_of ctxt\n    val en_act = nth state 1 |> Thm.cterm_of ctxt\n    val du_act = nth state 2 |> Thm.cterm_of ctxt\n    val ex_act = nth state 3 |> Thm.cterm_of ctxt\n    val trans_out = nth state 4 |> Thm.cterm_of ctxt\n    val trans_in = nth state 5 |> Thm.cterm_of ctxt\n    val C = nth state 6 |> Thm.cterm_of ctxt\n    val th2 = th1 |> Drule.instantiate_normalize ([], [(idname, name), (iden_act, en_act),\n                   (iddu_act,du_act),(idex_act, ex_act),(idtrans_out, trans_out),\n                   (idtrans_in, trans_in), (idC, C)])\n  in\n    asm_full_simplify ctxt th2\n  end\n\\<close>\n\n\\<comment> \\<open>all execution need to be written together because the action \n\"Send\" need call the Root Execution\\<close>\n\nML \\<open>\nfun evaluate_action ctxt env cmd e p s =\n  case cmd of\n    Const (@{const_name \"SKIP\"}, _) =>\n      evaluate_skip env e p s\n  | Const (@{const_name \"Assign\"}, _) $ x $ a =>\n    let\n      val cx = Thm.cterm_of ctxt x\n      val ca = Thm.cterm_of ctxt a\n    in\n      evaluate_assign ctxt env cx ca e p s |> asm_full_simplify ctxt\n    end\n  | Const (@{const_name \"Seq\"}, _) $ cmd1 $ cmd2 =>\n    let\n      val th1 = evaluate_action ctxt env cmd1 e p s\n      val args = th1 |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n      val b = nth args 6 |> Thm.cterm_of ctxt\n      val s2 = nth args 5 |> Thm.cterm_of ctxt\n    in\n      if b aconvc @{cterm \"True\"} then\n        let\n          val th2 = evaluate_action ctxt env cmd2 e p s2\n        in\n          [th1, th2] MRS @{thm Seq1}\n        end\n      else\n        th1 RS @{thm Seq2}\n    end\n  | Const (@{const_name \"On1\"}, _) $ temp $ as1 =>\n    let\n      val ctemp = Thm.cterm_of ctxt temp\n      val cas1 = Thm.cterm_of ctxt as1\n      val v = s |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n    in\n      (if (tempval ctxt temp v p = true) then \n        let\n          val ON1_th = @{thm On1}\n          val args = ON1_th |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n          val idenv = nth args 0 |> Term.dest_Var\n          val idt = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n          val idas = nth args 1 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n          val ide = nth args 2 |> Term.dest_Var\n          val idp = nth args 3 |> Term.dest_Var\n          val ids = nth args 4 |> Term.dest_Var\n          val th_assign = evaluate_action ctxt env as1 e p s\n          val th1 = ON1_th |> Drule.instantiate_normalize ([], [(idenv, env), (idt, ctemp), \n            (idas, cas1), (ide, e), (idp, p), (ids, s)]);\n          val th2 = asm_full_simplify ctxt th1\n        in\n          [th_assign] MRS th2\n        end\n       else (evaluate_On2 ctxt env ctemp cas1 e p s))\n    end\n  | Const (@{const_name \"On2\"}, _) $ event' $ as1' =>\n    let\n      val event = Thm.cterm_of ctxt event'\n      val as1 = Thm.cterm_of ctxt as1'\n    in\n      if event aconvc e then\n        let\n          val ON3_th = @{thm On3}\n          val args = ON3_th |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n          val idenv = nth args 0 |> Term.dest_Var\n          val idt = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n          val idas = nth args 1 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n          val ide = nth args 2 |> Term.dest_Var\n          val idp = nth args 3 |> Term.dest_Var\n          val ids = nth args 4 |> Term.dest_Var\n          val th_assign = evaluate_action ctxt env as1' e p s\n          val th1 = ON3_th |> Drule.instantiate_normalize ([], [(idenv, env),(idt, event), (idas, as1), \n               (ide, e), (idp, p),(ids, s)])\n          val th2 = asm_full_simplify ctxt th1\n        in\n          th_assign RS th2\n        end\n      else\n        evaluate_On4 ctxt env event as1 e p s\n    end\n  | Const (@{const_name \"Print1\"}, _) $ message =>\n    let\n      val cmessage = Thm.cterm_of ctxt message\n    in\n      evaluate_Print1 ctxt env cmessage e p s\n    end\n  | Const (@{const_name \"Print2\"}, _) $ message =>\n    let\n      val cmessage = Thm.cterm_of ctxt message\n    in\n      evaluate_Print2 ctxt env cmessage e p s\n    end\n\n\\<comment> \\<open>here b0 is a boolean value to tell whether this send action is in transition actions\\<close>\n  | Const (@{const_name \"Send1\"}, _) $ e' $ b0' =>\n    let\n      val e1 = Thm.cterm_of ctxt e'\n      val empty_p = @{cterm \"[]::string list\"}\n      val v = s |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n      val I = s |> Thm.term_of |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n    in\n      if b0' aconv @{term \"False\"} then\n        let\n          val Send1_th = @{thm Send1}\n          val args = Send1_th |> Thm.concl_of |> Term.dest_comb |> snd\n                                 |> Term.strip_comb |> snd\n          val idenv = nth args 0 |> Term.dest_Var\n          val ide1 = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n          val ide = nth args 2 |> Term.dest_Var\n          val idp = nth args 3 |> Term.dest_Var\n          val idv = nth args 4 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n          val idI = nth args 4 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n          val th1 = Send1_th |> Drule.instantiate_normalize ([], [(idenv, env),(ide, e),\n                  (ide1, e1), (idp, p), (idv, v), (idI, I)])\n          val th2 = asm_full_simplify ctxt th1\n          val root = env |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n          val comp_th = evaluate_Composition_Execution ctxt env root empty_p e1 @{cterm \"True\"} s\n          val th3 = comp_th RS th2\n          val I1 = nth (th3 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                       |> Term.strip_comb |> snd) 0 |> Term.dest_comb |> fst |> Thm.cterm_of ctxt\n          val src_p = nth (th3 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                       |> Term.strip_comb |> snd) 0 |> Term.dest_comb |> snd |> Thm.cterm_of ctxt\n          val info_th = Thm.apply I1 src_p \n                                |> Simplifier.rewrite ctxt\n          val info_eq = info_th RS @{thm meta_eq_to_obj_eq}\n          val th4 = info_eq RS th3\n        in\n          asm_full_simplify ctxt th4\n        end\n      else\n        let\n          val Send2_th = @{thm Send2}\n          val args = Send2_th |> Thm.concl_of |> Term.dest_comb |> snd\n                                 |> Term.strip_comb |> snd\n          val idenv = nth args 0 |> Term.dest_Var\n          val ide1 = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n          val ide = nth args 2 |> Term.dest_Var\n          val idp = nth args 3 |> Term.dest_Var\n          val idv = nth args 4 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n          val idI = nth args 4 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n          val th1 = Send2_th |> Drule.instantiate_normalize ([], [(idenv, env),(ide, e),\n                  (ide1, e1), (idp, p), (idv, v), (idI, I)])\n          val th2 = asm_full_simplify ctxt th1\n          val root = env |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n          val comp_th = evaluate_Composition_Execution ctxt env root empty_p e1 @{cterm \"True\"} s\n          val th3 = comp_th RS th2\n          val I1 = nth (th3 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                       |> Term.strip_comb |> snd) 0 |> Term.dest_comb |> fst |> Thm.cterm_of ctxt\n          val src_p = nth (th3 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                       |> Term.strip_comb |> snd) 0 |> Term.dest_comb |> snd |> Thm.cterm_of ctxt\n          val info_th = Thm.apply I1 src_p \n                                |> Simplifier.rewrite ctxt\n          val info_eq = info_th RS @{thm meta_eq_to_obj_eq}\n          val th4 = info_eq RS th3\n          val th5 = @{thm refl} RS th4\n        in\n          asm_full_simplify ctxt th5\n        end\n    end\n  | Const (@{const_name \"Send2\"}, _) $ e' $ b0' $ p1' =>    (*directed send to p1*)\n    let\n      val e1 = Thm.cterm_of ctxt e'\n      val p1 = Thm.cterm_of ctxt p1'\n      val v = s |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n      val I = s |> Thm.term_of |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n    in\n      if b0' aconv @{term \"False\"} then\n        let\n          val Send3_th = @{thm Send3}\n          val args = Send3_th |> Thm.concl_of |> Term.dest_comb |> snd\n                                 |> Term.strip_comb |> snd\n          val idenv = nth args 0 |> Term.dest_Var\n          val ide1 = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n          val idp1 = nth (nth args 1 |> Term.strip_comb |> snd) 2 |> Term.dest_Var\n          val ide = nth args 2 |> Term.dest_Var\n          val idp = nth args 3 |> Term.dest_Var\n          val idv = nth args 4 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n          val idI = nth args 4 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n          val th1 = Send3_th |> Drule.instantiate_normalize ([], [(idenv, env),(ide, e),\n                  (ide1, e1), (idp1, p1), (idp, p), (idv, v), (idI, I)])\n          val th2 = asm_full_simplify ctxt th1\n          val ST = nth (th2 |>Thm.prems_of |> hd |> Term.dest_comb |> snd \n                   |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n          val state_th = evaluate_State_Execution ctxt env ST e1 @{cterm \"True\"} s\n          val th3 = state_th RS th2\n          val I1 = nth (th3 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                       |> Term.strip_comb |> snd) 0 |> Term.dest_comb |> fst |> Thm.cterm_of ctxt\n          val src_p = nth (th3 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                       |> Term.strip_comb |> snd) 0 |> Term.dest_comb |> snd |> Thm.cterm_of ctxt\n          val info_th = Thm.apply I1 src_p \n                                |> Simplifier.rewrite ctxt\n          val info_eq = info_th RS @{thm meta_eq_to_obj_eq}\n          val th4 = info_eq RS th3\n        in\n          asm_full_simplify ctxt th4\n        end\n      else\n        let\n          val Send4_th = @{thm Send4}\n          val args = Send4_th |> Thm.concl_of |> Term.dest_comb |> snd\n                                 |> Term.strip_comb |> snd\n          val idenv = nth args 0 |> Term.dest_Var\n          val ide1 = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n          val idp1 = nth (nth args 1 |> Term.strip_comb |> snd) 2 |> Term.dest_Var\n          val ide = nth args 2 |> Term.dest_Var\n          val idp = nth args 3 |> Term.dest_Var\n          val idv = nth args 4 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n          val idI = nth args 4 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n          val th1 = Send4_th |> Drule.instantiate_normalize ([], [(idenv, env),(ide, e),\n                  (ide1, e1), (idp1, p1), (idp, p), (idv, v), (idI, I)])\n          val th2 = asm_full_simplify ctxt th1\n          val ST = nth (th2 |>Thm.prems_of |> hd |> Term.dest_comb |> snd \n                   |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n          val state_th = evaluate_State_Execution ctxt env ST e1 @{cterm \"True\"} s\n          val th3 = state_th RS th2\n          val I1 = nth (th3 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                       |> Term.strip_comb |> snd) 0 |> Term.dest_comb |> fst |> Thm.cterm_of ctxt\n          val src_p = nth (th3 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                       |> Term.strip_comb |> snd) 0 |> Term.dest_comb |> snd |> Thm.cterm_of ctxt\n          val info_th = Thm.apply I1 src_p \n                                |> Simplifier.rewrite ctxt\n          val info_eq = info_th RS @{thm meta_eq_to_obj_eq}\n          val th4 = info_eq RS th3\n          val th5 = @{thm refl} RS th4\n        in\n          asm_full_simplify ctxt th5\n        end\n    end\n  | Const (@{const_name \"Send3\"}, _) $ msg' =>\n    let\n      val msg = Thm.cterm_of ctxt msg'\n    in\n      evaluate_Send5 ctxt env msg e p s\n    end\n  | Const (@{const_name \"Funapp\"}, _) $ a1' $ f' $ a2' => \n    let\n      val v = s |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n      val I = s |> Thm.term_of |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n      val a1 = Thm.cterm_of ctxt a1'\n      val f = Thm.cterm_of ctxt f'\n      val a2 = Thm.cterm_of ctxt a2'\n      val funapp_th = @{thm Funapp}\n      val args = funapp_th |> Thm.concl_of |> \n                   Term.dest_comb |> snd |> Term.strip_comb |> snd\n      val idenv = nth args 0 |> Term.dest_Var\n      val ida1 = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n      val idf = nth args 1 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n      val ida2 = nth args 1 |> Term.strip_comb |> snd |> tl |> tl |> hd |> Term.dest_Var\n      val ide = nth args 2 |> Term.dest_Var\n      val idp = nth args 3 |> Term.dest_Var\n      val idv = nth args 4 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n      val idI = nth args 4 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n      val th1 = funapp_th |> Drule.instantiate_normalize ([], [(idenv, env),\n                (ide,e),(ida1,a1),(idf,f),(ida2,a2),\n                (idv,v),(idp, p),(idI, I)])\n      val th1_2 = asm_full_simplify ctxt th1\n      val th1_3 = @{thm refl} RS th1_2\n      val th1' = asm_full_simplify ctxt th1_3\n      val args2 = th1' |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                                  |> Term.strip_comb |> snd\n      val tmp_a = nth args2 1 |> Thm.cterm_of ctxt\n      val update_th1 = evaluate_update_vals ctxt a2 tmp_a v\n      val th2 = update_th1 RS th1'\n      val cmd = nth (th2 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                   |> Term.strip_comb |> snd) 1 \n      val s1 = nth (th2 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                   |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n      val act_th = evaluate_action ctxt env cmd e p s1\n      val th3 = act_th RS th2\n      val tmp_a = nth (th3 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                   |> Term.strip_comb |> snd) 0 |> Thm.cterm_of ctxt\n      val v2 = nth (th3 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                   |> Term.strip_comb |> snd) 2 |> Thm.cterm_of ctxt\n      val update_th2 = evaluate_update_vals ctxt tmp_a a1 v2\n    in\n      update_th2 RS th3\n    end\n  | Const (@{const_name \"Grafun\"}, _) $ a1' $ f' $ a2' => \n    let\n      val v = s |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n      val I = s |> Thm.term_of |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n      val a1 = Thm.cterm_of ctxt a1'\n      val f = Thm.cterm_of ctxt f'\n      val a2 = Thm.cterm_of ctxt a2'\n      val grafun_th = @{thm Grafun}\n      val args = grafun_th |> Thm.concl_of |> \n                   Term.dest_comb |> snd |> Term.strip_comb |> snd\n      val idenv = nth args 0 |> Term.dest_Var\n      val ida1 = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n      val idf = nth args 1 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n      val ida2 = nth args 1 |> Term.strip_comb |> snd |> tl |> tl |> hd |> Term.dest_Var\n      val ide = nth args 2 |> Term.dest_Var\n      val idp = nth args 3 |> Term.dest_Var\n      val idv = nth args 4 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n      val idI = nth args 4 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n      val th1 = grafun_th |> Drule.instantiate_normalize ([], [(idenv, env),\n                (ide,e),(ida1,a1),(idf,f),(ida2,a2),\n                (idv,v),(idp, p),(idI, I)])\n      val th1_2 = asm_full_simplify ctxt th1\n      val th1_3 = @{thm refl} RS th1_2\n      val th1' = asm_full_simplify ctxt th1_3\n      val args2 = th1' |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                                  |> Term.strip_comb |> snd\n      val tmp_a = nth args2 1 |> Thm.cterm_of ctxt\n      val update_th1 = evaluate_update_vals ctxt a2 tmp_a v\n      val th2 = update_th1 RS th1'\n      val TL = nth (th2 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                   |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n      val s1 = nth (th2 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                   |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n      val trans_th = evaluate_transition_list ctxt env TL @{cterm \"''''::string\"} p s1\n      val th3 = trans_th RS th2\n      val tmp_a = nth (th3 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                   |> Term.strip_comb |> snd) 0 |> Thm.cterm_of ctxt\n      val v2 = nth (th3 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                   |> Term.strip_comb |> snd) 2 |> Thm.cterm_of ctxt\n      val update_th2 = evaluate_update_vals ctxt tmp_a a1 v2\n    in\n      update_th2 RS th3\n    end\n  | _ => raise TERM (\"Not supported\", [cmd])\nand evaluate_actionlist ctxt env al e p s = \n  if ((Thm.term_of al) aconv @{term \"[]::act list\"})\n  then evaluate_al1 env e p s\n  else\n    let \n      val cmd = al |> Thm.term_of |> Term.strip_comb |> snd |> hd\n      val rest_al =  hd (map (Thm.cterm_of ctxt) \n                    (al |> Thm.term_of |> Term.strip_comb |> snd |> tl))\n      val th1 = evaluate_action ctxt env cmd e p s\n      val args = th1 |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n      val b = nth args 6 |> Thm.cterm_of ctxt\n      val s2 = nth args 5 |> Thm.cterm_of ctxt\n    in\n      if b aconvc @{cterm \"True\"} then\n        let\n          val th2 = evaluate_actionlist ctxt env rest_al e p s2\n        in\n          [th1, th2] MRS @{thm ActionList_Execution2}\n        end\n      else\n        th1 RS @{thm ActionList_Execution3}\n    end\n\nand evaluate_transition ctxt env t e p s = \n  let\n    val v = s |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n    val I = s |> Thm.term_of |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n    val Trans_th = @{thm Trans_Execution1}\n    val args = Trans_th |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n    val idenv = nth args 0 |> Term.dest_Var\n    val idt = nth args 1 |> Term.dest_Var\n    val ide = nth args 2 |> Term.dest_Var\n    val idp = nth args 3 |> Term.dest_Var\n    val idv = nth args 4 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n    val idI = nth args 4 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n    val th1 = Trans_th |> Drule.instantiate_normalize ([], [(idt,t),(idv, v), (idp, p), \n             (ide, e), (idenv, env), (idI, I)])\n    val th2 = asm_full_simplify ctxt th1\n    val args1 = th2 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n            |> Term.dest_comb |> fst\n    val args2 = th2 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n            |> Term.dest_comb |> snd\n    val idv2 = args1 |> Term.dest_comb |> snd |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n    val v2 = args1 |> Term.dest_comb |> snd |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n    val idI2 = args2 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n    val I2 = args2 |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n    val th3' = th2 |> Drule.instantiate_normalize ([], [(idv2,v2),(idI2, I2)])\n    val th3'' = asm_full_simplify ctxt th3'\n    val condition_action = nth (t |> Thm.term_of |> Term.strip_comb |> snd) 3\n    val s2 = nth (th3'' |> Thm.prems_of |> hd |> Term.strip_comb |> snd |> hd |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n    val th3 = evaluate_action ctxt env condition_action e p s2\n    val args = th3 |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n    val b = nth args 6 |> Thm.cterm_of ctxt\n  in\n    if b aconvc @{cterm \"True\"} then\n      [th3,@{thm refl},@{thm refl}] MRS th3''\n    else\n      let\n        val Trans2_th = @{thm Trans_Execution2}\n        val args = Trans2_th |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n        val idenv = nth args 0 |> Term.dest_Var\n        val idt = nth args 1 |> Term.dest_Var\n        val ide = nth args 2 |> Term.dest_Var\n        val idp = nth args 3 |> Term.dest_Var\n        val idv = nth args 4 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n        val idI = nth args 4 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n        val th1 = Trans2_th |> Drule.instantiate_normalize ([], [(idt,t),(idv, v), (idp, p), \n             (ide, e), (idenv, env), (idI, I)])\n        val th2 = asm_full_simplify ctxt th1\n        val args1 = th2 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n            |> Term.dest_comb |> fst\n        val args2 = th2 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                |> Term.dest_comb |> snd\n        val idv2 = args1 |> Term.dest_comb |> snd |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n        val v2 = args1 |> Term.dest_comb |> snd |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n        val idI2 = args2 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n        val I2 = args2 |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n        val th3' = th2 |> Drule.instantiate_normalize ([], [(idv2,v2),(idI2, I2)])\n        val th3'' = asm_full_simplify ctxt th3'\n      in\n        th3 RS th3''\n      end\n  end\n\nand evaluate_transition_list ctxt env TL e p s = \n  if (Thm.term_of TL) aconv @{term \"[]::transition list\"} then   (*Termination*)\n    evaluate_Termination env e p s\n  else\n    let \n      val t = TL |> Thm.term_of |>  Term.strip_comb |> snd |> hd |> (Thm.cterm_of ctxt)\n      val T = TL |> Thm.term_of |>  Term.strip_comb |> snd |> tl |> hd   (*t#T*)\n      val v = s |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n      val I = s |> Thm.term_of |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n    in\n      if enable_ML ctxt t e s p = false then\n        if T aconv @{term \"[]::transition list\"} then     (*Fail*)\n          evaluate_Fail ctxt env t e p s\n        else  (*TLInduction*)\n          let\n            val C_T = Thm.cterm_of ctxt T\n            val TLInduction_th = @{thm TLinduction}\n            val args = TLInduction_th |> Thm.concl_of |> Term.dest_comb \n                       |> snd |> Term.strip_comb |> snd\n            val idenv = nth args 0 |> Term.dest_Var\n            val idt = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n            val idT = nth args 1 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n            val ide = nth args 2 |> Term.dest_Var\n            val idp = nth args 3 |> Term.dest_Var\n            val ids = nth args 4 |> Term.dest_Var\n            val th1 = TLInduction_th |> Drule.instantiate_normalize ([], [(idt,t)\n                ,(idT, C_T),(ids, s), (idp, p), (idenv, env), (ide, e)])\n            val th2 = asm_full_simplify ctxt th1\n            val th3 = @{thm refl} RS th2\n            val s2 = nth (th3 |> Thm.prems_of |> hd |> Term.strip_comb |> snd |> hd\n                      |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n            val th_Induction = evaluate_transition_list ctxt env C_T e p s2\n          in\n            th_Induction RS th3\n          end\n      else\n        let\n          val th_trans = evaluate_transition ctxt env t e p s\n          val args1 = th_trans |> Thm.concl_of |> Term.dest_comb \n                    |> snd |> Term.strip_comb |> snd\n          val b = nth args1 6 |> Thm.cterm_of ctxt\n          val trg = nth args1 8\n        in\n          if b aconvc @{cterm \"False\"} then\n            let\n              val C_T = Thm.cterm_of ctxt T\n              val inactive_th = @{thm SrcInactive}\n              val args = inactive_th |> Thm.concl_of |> Term.dest_comb \n                       |> snd |> Term.strip_comb |> snd\n              val idT = nth args 1 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n              val th1 = inactive_th |> Drule.instantiate_normalize ([], [(idT, C_T)])\n            in\n              th_trans RS th1\n            end\n          else\n            case trg of\n              Const (@{const_name \"P\"}, _) $ _ =>    (*ToState*)\n                let\n                  val ToState_th = @{thm ToState}\n                  val args = ToState_th |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n                  val idenv = nth args 0 |> Term.dest_Var\n                  val idt = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n                  val idT = nth args 1 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n                  val ide = nth args 2 |> Term.dest_Var\n                  val idp = nth args 3 |> Term.dest_Var\n                  val ids = nth args 4 |> Term.dest_Var\n                  val th1 = ToState_th |> Drule.instantiate_normalize ([], [(idt,t),(idenv,env),\n                          (idT,(Thm.cterm_of ctxt T)),(ids, s),(idp, p),(ide, e)])\n                  val th2 = [th_trans, @{thm refl}] MRS th1\n                  val th3 = asm_full_simplify ctxt th2\n                in\n                  @{thm refl} RS th3\n                end \n            | Const (@{const_name \"HJ\"}, _) $ _ =>    (*ToHistoryJucntion*)\n                let\n                  val ToHJ_th = @{thm ToHistoryJunction}\n                  val args = ToHJ_th |> Thm.concl_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n                  val idenv = nth args 0 |> Term.dest_Var\n                  val idt = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n                  val idT = nth args 1 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n                  val ide = nth args 2 |> Term.dest_Var\n                  val idp = nth args 3 |> Term.dest_Var\n                  val idv = nth args 4 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n                  val idI = nth args 4 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n                  val th1 = ToHJ_th |> Drule.instantiate_normalize ([], [(idt,t)\n                ,(idT, (Thm.cterm_of ctxt T)),(idv, v), (idp, p), (idenv, env), (idI, I), (ide, e)])\n                  val th2 = [th_trans, @{thm refl}] MRS th1\n                  val th3 = asm_full_simplify ctxt th2\n                  val th4 = [@{thm refl}] MRS th3\n                  val th5 = asm_full_simplify ctxt th4\n                  val th6 = @{thm refl} RS th5\n                  val th7 = asm_full_simplify ctxt th6\n                  val th8 = @{thm refl} RS th7\n                in\n                  asm_full_simplify ctxt th8\n                end\n            | Const (@{const_name \"J\"}, _) $ str =>\n                let\n                  val s2 = nth args1 5 |> Thm.cterm_of ctxt\n                  val g = nth (env |> Thm.term_of |> Term.strip_comb |> snd) 3 |> Thm.cterm_of ctxt\n                  val TL2 = (Thm.term_of g) $ str |> Thm.cterm_of ctxt \n                      |> Simplifier.rewrite ctxt |> Thm.rhs_of (*TL2 = g(str)*)\n                  val th_trans2 = evaluate_transition_list ctxt env TL2 e p s2\n                  val b2 = nth (th_trans2 |> Thm.concl_of |> Term.dest_comb \n                    |> snd |> Term.strip_comb |> snd) 7 |> Thm.cterm_of ctxt\n                in\n                  if b2 aconvc @{cterm \"False\"} then\n                    let\n                      val C_T = Thm.cterm_of ctxt T\n                      val ToJunc2_th = @{thm ToJunctionInduction2}\n                      val args2 = ToJunc2_th |> Thm.concl_of |> Term.dest_comb \n                              |> snd |> Term.strip_comb |> snd\n                      val idT = nth args2 1 |> Term.strip_comb |> snd \n                                |> tl |> hd |> Term.dest_Var\n                      val th1 = ToJunc2_th |> Drule.instantiate_normalize ([], [(idT, C_T)])\n                      val th2 = th_trans RS th1\n                      val th2' = @{thm refl} RS th2\n                      val th3 = asm_full_simplify ctxt th2'\n                    in\n                      th_trans2 RS th3\n                    end\n                  else\n                    let \n                      val n = nth (th_trans2 |> Thm.concl_of |> Term.dest_comb \n                            |> snd |> Term.strip_comb |> snd) 6 |> Thm.cterm_of ctxt\n                      val s3 = nth (th_trans2 |> Thm.concl_of |> Term.dest_comb \n                            |> snd |> Term.strip_comb |> snd) 5 |> Thm.cterm_of ctxt\n                    in\n                      if n aconvc @{cterm \"-1::int\"} then\n                        let\n                          val ToJunc5_th = @{thm ToJunctionInduction5}\n                          val args2 = ToJunc5_th |> Thm.concl_of |> Term.dest_comb \n                                      |> snd |> Term.strip_comb |> snd\n                          val idT = nth args2 1 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n                          val C_T = T |> Thm.cterm_of ctxt    (*cterm of T*)\n                          val th1 = ToJunc5_th |> Drule.instantiate_normalize ([], [(idT,C_T)])\n                          val th2 = th_trans RS th1\n                          val th2' = @{thm refl} RS th2\n                          val th3 = asm_full_simplify ctxt th2'\n                        in\n                          th_trans2 RS th3\n                        end\n                      else if n aconvc @{cterm \"0::int\"} then\n                        if T aconv @{term \"[]::transition list\"} then   (*ToJunctionInduction3*)\n                          let \n                            val ToJunc4_th = @{thm ToJunctionInduction4}\n                            val th1 = th_trans RS ToJunc4_th\n                            val th2 = @{thm refl} RS th1\n                            val th3 = asm_full_simplify ctxt th2\n                          in\n                            th_trans2 RS th3\n                          end\n                        else    (*ToJunctionInduction3*)\n                          let \n                            val C_T = T |> Thm.cterm_of ctxt    (*cterm of T*)\n                            val th_trans3 = evaluate_transition_list ctxt env C_T e p s3\n                            val ToJunc3_th = @{thm ToJunctionInduction3}\n                            val args2 = ToJunc3_th |> Thm.concl_of |> Term.dest_comb \n                                        |> snd |> Term.strip_comb |> snd\n                            val idT = nth args2 1 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n                            val th1 = ToJunc3_th |> Drule.instantiate_normalize ([], [(idT,C_T)])\n                            val th2 = th_trans RS th1\n                            val th2' = @{thm refl} RS th2\n                            val th3 = asm_full_simplify ctxt th2'\n                          in\n                            [th_trans2, th_trans3] MRS th3\n                          end\n                      else if n aconvc @{cterm \"1::int\"} then    (*ToJunctionInduction1*)\n                        let\n                          val C_T = T |> Thm.cterm_of ctxt    (*cterm of T*)\n                          val ToJunc1_th = @{thm ToJunctionInduction1}\n                          val args2 = ToJunc1_th |> Thm.concl_of |> Term.dest_comb \n                                    |> snd |> Term.strip_comb |> snd\n                          val idT = nth args2 1 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n                          val th1 = ToJunc1_th |> Drule.instantiate_normalize ([], [(idT,C_T)])\n                          val th2 = th_trans RS th1\n                          val th2' = @{thm refl} RS th2\n                          val th3 = asm_full_simplify ctxt th2'\n                          val th4 = th_trans2 RS th3\n                          val th5 = asm_full_simplify ctxt th4\n                        in\n                          @{thm refl} RS th5\n                        end\n                      else\n                        raise CTERM (\"n can't be this value!\", [n]) \n                    end\n                end\n            | _ => raise TERM (\"Transition Target Type Error\", [trg])\n        end\n    end\n\nand evaluate_exit_state ctxt env ST e s = \n  if (Thm.term_of ST) aconv @{term \"No_State\"} then    (*State_Exit2*)\n    evaluate_No_State_Exit ctxt env e s\n  else\n    let\n      val v = s |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n      val I = s |> Thm.term_of |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n      val name = nth (ST |> Thm.term_of |> Term.strip_comb |> snd) 0 |> Thm.cterm_of ctxt\n      val b1 = @{term \"is_active_state\"} $ (Thm.term_of name) $ (Thm.term_of I)\n              |> Thm.cterm_of ctxt |> Simplifier.rewrite ctxt |> Thm.rhs_of\n      val C = nth (ST |> Thm.term_of |> Term.strip_comb |> snd) 6 |> Thm.cterm_of ctxt\n      val exit_action = nth (ST |> Thm.term_of |> Term.strip_comb |> snd) 3\n    in\n      if (Thm.term_of b1) aconv @{term \"False\"} then    (*State_Exit3*)\n        evaluate_State_Exit3 ctxt env ST e s\n      else\n        let\n          val comp_th = evaluate_exit_composition ctxt env C name e s\n          val b2 = nth (comp_th |> Thm.concl_of |> Term.dest_comb \n                       |> snd |> Term.strip_comb |> snd) 6 |> Thm.cterm_of ctxt\n        in\n          if b2 aconvc @{cterm \"False\"} then\n            let\n              val State_Exit4_th = @{thm State_Exit4}\n              val args = State_Exit4_th |> Thm.concl_of |> Term.dest_comb \n                         |> snd |> Term.strip_comb |> snd\n              val idenv = nth args 0 |> Term.dest_Var\n              val idST = nth args 1 |> Term.dest_Var\n              val ide = nth args 2 |> Term.dest_Var\n              val idv = nth args 3 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n              val idI = nth args 3 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n              val th1 = State_Exit4_th |> Drule.instantiate_normalize ([], [(idST,ST),(ide, e), \n                         (idenv, env), (idv, v), (idI, I)])\n              val th2 = @{thm refl} RS th1\n              val th3 = asm_full_simplify ctxt th2\n            in\n              comp_th RS th3\n            end\n          else\n            let\n              val State_Exit1_th = @{thm State_Exit1}\n              val args = State_Exit1_th |> Thm.concl_of |> Term.dest_comb \n                         |> snd |> Term.strip_comb |> snd\n              val idenv = nth args 0 |> Term.dest_Var\n              val idST = nth args 1 |> Term.dest_Var\n              val ide = nth args 2 |> Term.dest_Var\n              val idv = nth args 3 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n              val idI = nth args 3 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n              val th1 = State_Exit1_th |> Drule.instantiate_normalize ([], [(idST,ST),(ide, e), \n                     (idenv, env), (idv, v), (idI, I)])\n              val th2 = @{thm refl} RS th1\n              val th3 = asm_full_simplify ctxt th2\n              val th3' = comp_th RS th3\n              val th3'' = asm_full_simplify ctxt th3'\n              val s2 = nth (th3'' |> Thm.prems_of |> hd |> Term.strip_comb |> snd |> hd\n                      |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n              val action_th = evaluate_action ctxt env exit_action e name s2\n              val b3 = nth (action_th |> Thm.concl_of |> Term.dest_comb \n                       |> snd |> Term.strip_comb |> snd) 6 |> Thm.cterm_of ctxt\n            in\n              if b3 aconvc @{cterm \"False\"} then\n                let\n                  val State_Exit5_th = @{thm State_Exit5}\n                  val args = State_Exit5_th |> Thm.concl_of |> Term.dest_comb \n                             |> snd |> Term.strip_comb |> snd\n                  val idenv = nth args 0 |> Term.dest_Var\n                  val idST = nth args 1 |> Term.dest_Var\n                  val ide = nth args 2 |> Term.dest_Var\n                  val idv = nth args 3 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n                  val idI = nth args 3 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n                  val th1 = State_Exit5_th |> Drule.instantiate_normalize ([], [(idST,ST),(ide, e), \n                         (idenv, env), (idv, v), (idI, I)])\n                  val th2 = @{thm refl} RS th1\n                  val th3 = asm_full_simplify ctxt th2\n                  val th4 = comp_th RS th3\n                in\n                  action_th RS th4\n                end\n              else\n                let\n                  val th4 = action_th RS th3''\n                  val I3 = nth (action_th |> Thm.concl_of |> Term.dest_comb \n                    |> snd |> Term.strip_comb |> snd) 5 \n                    |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n                  val tmp = Thm.apply I3 name |> Simplifier.rewrite ctxt\n                  val Chart_th = tmp RS @{thm meta_eq_to_obj_eq}\n                in\n                  [Chart_th, @{thm refl}] MRS th4\n                end\n            end\n        end\n    end\nand evaluate_exit_composition ctxt env C name e s = \n  case (Thm.term_of C) of\n    Const (@{const_name \"No_Composition\"}, _) =>     (*No_Composition_Exit*)\n      evaluate_No_Composition_Exit env name e s\n  | Const (@{const_name \"Or\"}, _) $ _ $ _ $ _ =>     (*Or_Exit*)\n      let\n        val v = s |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n        val I = s |> Thm.term_of |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n        val Or_Exit1_th = @{thm Or_Exit1}\n        val args = Or_Exit1_th |> Thm.concl_of |> Term.dest_comb |> \n                            snd |> Term.strip_comb |> snd\n        val idenv = nth args 0 |> Term.dest_Var\n        val idC = nth args 1 |> Term.dest_Var\n        val idname = nth args 2 |> Term.dest_Var\n        val ide = nth args 3 |> Term.dest_Var\n        val idv = nth args 4 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n        val idI = nth args 4 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n        val th1 = Or_Exit1_th |> Drule.instantiate_normalize ([], [(idenv, env), (idC, C),\n          (idv, v),(idname,name), (idI, I), (ide, e)])\n        val tmp = Thm.apply I name |> Simplifier.rewrite ctxt\n        val Chart_th = tmp RS @{thm meta_eq_to_obj_eq}\n        val th2 = [@{thm refl}, Chart_th] MRS th1\n        val th3 = asm_full_simplify ctxt th2\n        val ST = nth (th3 |> Thm.prems_of |> hd |> Term.strip_comb |> snd |> hd\n                |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n        val state_th = evaluate_exit_state ctxt env ST e s\n        val b = nth (state_th |> Thm.concl_of |> Term.dest_comb \n                       |> snd |> Term.strip_comb |> snd) 5 |> Thm.cterm_of ctxt\n      in\n        if b aconvc @{cterm \"False\"} then\n        let\n          val Or_Exit2_th = @{thm Or_Exit2}\n          val th1 = Or_Exit2_th |> Drule.instantiate_normalize ([], [(idenv, env), (idC, C),\n          (idv, v),(idname,name), (idI, I), (ide, e)])\n          val tmp = Thm.apply I name |> Simplifier.rewrite ctxt\n          val Chart_th = tmp RS @{thm meta_eq_to_obj_eq}\n          val th2 = [@{thm refl}, Chart_th] MRS th1\n          val th3 = asm_full_simplify ctxt th2\n        in\n          state_th RS th3\n        end\n        else\n          let\n            val th4 = state_th RS th3\n            val th5 = asm_full_simplify ctxt th4\n          in\n            [@{thm refl}, @{thm refl}] MRS th5\n          end\n      end\n  | Const (@{const_name \"And\"}, _) $ sl' $ f' =>     (*And_Exit*)\n    let\n      val sl = Thm.cterm_of ctxt sl'\n      val f = Thm.cterm_of ctxt f'\n      val And_Exit1_th = @{thm And_Exit1}\n      val args = And_Exit1_th |> Thm.concl_of |> Term.dest_comb |> \n                            snd |> Term.strip_comb |> snd\n      val idenv = nth args 0 |> Term.dest_Var\n      val idC = nth args 1 |> Term.dest_Var\n      val idname = nth args 2 |> Term.dest_Var\n      val ide = nth args 3 |> Term.dest_Var\n      val ids = nth args 4 |> Term.dest_Var\n      val th1 = And_Exit1_th |> Drule.instantiate_normalize ([], [(idC, C),\n          (idenv, env), (ids, s), (idname,name), (ide, e)])\n      val th2 = @{thm refl} RS th1\n      val pathlist_th = path_lsit_exit_execution ctxt env sl e f s\n      val b = nth (pathlist_th |> Thm.concl_of |> Term.dest_comb \n                       |> snd |> Term.strip_comb |> snd) 6 |> Thm.cterm_of ctxt\n    in\n      if b aconvc @{cterm \"False\"} then\n      let\n        val And_Exit2_th = @{thm And_Exit2}\n        val th1 = And_Exit2_th |> Drule.instantiate_normalize ([], [(idC, C),\n          (idenv, env), (ids, s), (idname,name), (ide, e)])\n        val th2 = @{thm refl} RS th1\n        val th3 = asm_full_simplify ctxt th2\n      in\n        pathlist_th RS th3\n      end\n      else\n        let\n          val th3 = asm_full_simplify ctxt th2\n        in\n          pathlist_th RS th3\n        end\n    end\n  |_ => raise CTERM (\"Not supported\", [C])\nand path_lsit_exit_execution ctxt env sl e f s = \n    if (Thm.term_of sl) aconv @{term \"[]::string list\"} then\n      let\n        val empty_list_exit_th = @{thm Empty_List_Exit}\n        val args = empty_list_exit_th |> Thm.concl_of |> Term.dest_comb |> snd\n                   |> Term.strip_comb |> snd\n        val idenv = nth args 0 |> Term.dest_Var\n        val ide = nth args 2 |> Term.dest_Var\n        val idf = nth args 3 |> Term.dest_Var\n        val ids = nth args 4 |> Term.dest_Var\n      in\n        empty_list_exit_th |> Drule.instantiate_normalize ([], [(idenv, env), (ide,e), \n                    (idf,f), (ids, s)])\n      end\n    else\n      let\n        val Term_butlast = @{term butlast}\n        val Term_last = @{term last}\n        val sl1 = Term_butlast $ (Thm.term_of sl) |> Thm.cterm_of ctxt |> Simplifier.rewrite ctxt |> Thm.rhs_of\n        val str = Term_last $ (Thm.term_of sl) |> Thm.cterm_of ctxt |> Simplifier.rewrite ctxt |> Thm.rhs_of\n        val path_list_exit1_th = @{thm List_Exit1}\n        val args = path_list_exit1_th |> Thm.concl_of |> Term.dest_comb |> snd\n                   |> Term.strip_comb |> snd\n        val idenv = nth args 0 |> Term.dest_Var\n        val idsl1 = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n        val idstr = nth args 1 |> Term.dest_comb |> snd |> Term.strip_comb \n                    |> snd |> hd |> Term.dest_Var\n        val ide = nth args 2 |> Term.dest_Var\n        val idf = nth args 3 |> Term.dest_Var\n        val ids = nth args 4 |> Term.dest_Var\n        val th1 = path_list_exit1_th |> Drule.instantiate_normalize ([], [(idsl1,sl1),\n                  (idenv, env), (idstr,str),(ide,e),(idf,f),(ids, s)])\n        val th2 = asm_full_simplify ctxt th1\n        \\<comment> \\<open>This is a trick that we can't use f(str) to construct the state\\<close>\n        (*val state = (Thm.term_of f) $ (Thm.term_of str) |> \n                    Term.dest_comb |> fst;*)\n        val state = th2 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                   |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n        val state_th = evaluate_exit_state ctxt env state e s\n        val b = nth (state_th |> Thm.concl_of |> Term.dest_comb \n                       |> snd |> Term.strip_comb |> snd) 5 |> Thm.cterm_of ctxt\n      in\n        if b aconvc @{cterm \"False\"} then\n        let\n          val path_list_exit2_th = @{thm List_Exit2}\n          val th1 = path_list_exit2_th |> Drule.instantiate_normalize ([], [(idsl1,sl1),\n                  (idenv, env), (idstr,str),(ide,e),(idf,f),(ids, s)])\n          val th2 = asm_full_simplify ctxt th1\n        in\n          state_th RS th2\n        end\n        else\n          let\n            val th3 = state_th RS th2\n            val th4 = asm_full_simplify ctxt th3\n            val args2 = th4 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                   |> Term.strip_comb |> snd\n            val s2 = nth args2 4 |> Thm.cterm_of ctxt\n            val sl1_exit_th = path_lsit_exit_execution ctxt env sl1 e f s2\n          in\n            sl1_exit_th RS th4\n          end\n      end\n\nand evaluate_entry_state ctxt env ST e p s = \n  if (Thm.term_of ST) aconv @{term \"No_State\"} then    (*No_State_Entry*)\n    evaluate_No_State_Entry env e p s\n  else\n    let\n      val v = s |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n      val I = s |> Thm.term_of |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n      val name = nth (ST |> Thm.term_of |> Term.strip_comb |> snd) 0 |> (Thm.cterm_of ctxt)\n      val C = nth (ST |> Thm.term_of |> Term.strip_comb |> snd) 6 |> (Thm.cterm_of ctxt)\n      val State_Entry1_th = @{thm State_Entry1}\n      val args = State_Entry1_th |> Thm.concl_of |> Term.dest_comb |> snd\n                  |> Term.strip_comb |> snd\n      val idenv = nth args 0 |> Term.dest_Var\n      val idST = nth args 1 |> Term.dest_Var\n      val ide = nth args 2 |> Term.dest_Var\n      val idp = nth args 3 |> Term.dest_Var\n      val idv = nth args 4 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n      val idI = nth args 4 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n      val th1 = State_Entry1_th |> Drule.instantiate_normalize ([], [(idST,ST),(idv, v), \n                 (idenv, env), (ide, e), (idI, I), (idp, p)])\n      val th2 = [@{thm refl}, @{thm refl}, @{thm refl}] MRS th1\n      val tmp = Thm.apply I name |> Simplifier.rewrite ctxt\n      val Chart_th = tmp RS @{thm meta_eq_to_obj_eq}\n      val th3 = Chart_th RS th2\n      val cterm_butlast = @{cterm butlast}\n      val tmp2 = Thm.apply I (Thm.apply cterm_butlast name) |> Simplifier.rewrite ctxt\n      val Chart_th2 = tmp2 RS @{thm meta_eq_to_obj_eq}\n      val th4 = [Chart_th2, @{thm refl}, @{thm refl}] MRS th3\n      val th4' = asm_full_simplify ctxt th4\n      val entry_action = nth (ST |> Thm.term_of |> Term.strip_comb |> snd) 1\n      val s2 = nth (th4' |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                  |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n      val action_th = evaluate_action ctxt env entry_action e name s2\n      val b1 = nth (action_th |> Thm.concl_of |> Term.dest_comb \n                       |> snd |> Term.strip_comb |> snd) 6 |> Thm.cterm_of ctxt\n    in\n      if b1 aconvc @{cterm \"False\"} then\n      let\n        val State_Entry3_th = @{thm State_Entry3}\n        val th1 = State_Entry3_th |> Drule.instantiate_normalize ([], [(idST,ST),(idv, v), \n                 (idenv, env), (ide, e), (idI, I), (idp, p)])\n        val th2 = [@{thm refl}, @{thm refl}, @{thm refl}] MRS th1\n        val tmp = Thm.apply I name |> Simplifier.rewrite ctxt\n        val Chart_th = tmp RS @{thm meta_eq_to_obj_eq}\n        val th3 = Chart_th RS th2\n        val cterm_butlast = @{cterm butlast}\n        val tmp2 = Thm.apply I (Thm.apply cterm_butlast name) |> Simplifier.rewrite ctxt\n        val Chart_th2 = tmp2 RS @{thm meta_eq_to_obj_eq}\n        val th4 = [Chart_th2, @{thm refl}, @{thm refl}] MRS th3\n        val th4' = asm_full_simplify ctxt th4\n      in\n        action_th RS th4'\n      end\n      else\n        let\n          val th6 = action_th RS th4'\n          val s3 = nth (th6 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                  |> Term.strip_comb |> snd) 5 |> Thm.cterm_of ctxt\n          val new_p = nth (th6 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                  |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n          val Comp_th = evaluate_entry_composition ctxt env C name e new_p s3\n        in\n          Comp_th RS th6\n        end\n    end\nand evaluate_entry_composition ctxt env C name e p s = \ncase (Thm.term_of C) of\n  Const (@{const_name \"No_Composition\"}, _) =>     (*No_Composition_Entry*)\n    evaluate_No_Composition_Entry env name e p s\n| Const (@{const_name \"Or\"}, _) $ TL' $ b' $ _ =>     (*Or_Entry*)\n    let\n      val TL = Thm.cterm_of ctxt TL'\n    in\n      if (Thm.term_of p) aconv @{term \"[]::string list\"} then\n        if b' aconv @{term \"False\"} then\n          let\n            val Or_Entry1_th = @{thm Or_Entry1}      (*Or_Entry1*)\n            val args = Or_Entry1_th |> Thm.concl_of |> Term.dest_comb |> snd\n                        |> Term.strip_comb |> snd\n            val idenv = nth args 0 |> Term.dest_Var\n            val idC = nth args 1 |> Term.dest_Var\n            val idname = nth args 2 |> Term.dest_Var\n            val ide = nth args 3 |> Term.dest_Var\n            val idp = nth args 4 |> Term.dest_Var\n            val ids = nth args 5 |> Term.dest_Var\n            val th1 = Or_Entry1_th |> Drule.instantiate_normalize ([], [(idC,C),(idname,name), \n                       (idenv, env), (ide, e), (idp, p), (ids, s)])\n            val th2 = @{thm refl} RS th1\n            val th3 = asm_full_simplify ctxt th2\n            val name = nth (th3 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                            |> Term.strip_comb |> snd) 3 |> Thm.cterm_of ctxt\n            val trans_th = evaluate_transition_list ctxt env TL e name s\n            val b1 = nth (trans_th |> Thm.concl_of |> Term.dest_comb \n                       |> snd |> Term.strip_comb |> snd) 7 |> Thm.cterm_of ctxt\n          in\n            if b1 aconvc @{cterm \"False\"} then\n            let\n              val Or_Entry2_th = @{thm Or_Entry2}      (*Or_Entry2*)\n              val th1 = Or_Entry2_th |> Drule.instantiate_normalize ([], [(idC,C),(idname,name), \n                       (idenv, env), (ide, e), (idp, p), (ids, s)])\n              val th2 = @{thm refl} RS th1\n              val th3 = asm_full_simplify ctxt th2\n            in\n              trans_th RS th3\n            end\n            else\n            let\n              val th4 = trans_th RS th3\n              val th5 = asm_full_simplify ctxt th4\n              val th6 = @{thm refl} RS th5\n              val action_list = nth (th6 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                          |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n              val s2 = nth (th6 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                          |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n              val actionlist_th = evaluate_actionlist ctxt env action_list e name s2\n              val b2 = nth (actionlist_th |> Thm.concl_of |> Term.dest_comb \n                     |> snd |> Term.strip_comb |> snd) 6 |> Thm.cterm_of ctxt\n            in\n              if b2 aconvc @{cterm \"False\"} then\n              let\n                val Or_Entry3_th = @{thm Or_Entry3}      (*Or_Entry3*)\n                val th1 = Or_Entry3_th |> Drule.instantiate_normalize ([], [(idC,C),(idname,name), \n                       (idenv, env), (ide, e), (idp, p), (ids, s)])\n                val th2 = @{thm refl} RS th1\n                val th3 = asm_full_simplify ctxt th2\n                val th4 = trans_th RS th3\n                val th5 = asm_full_simplify ctxt th4\n                val th6 = @{thm refl} RS th5\n              in\n                actionlist_th RS th6\n              end\n              else\n                let\n                  val th7 = actionlist_th RS th6\n                  val th8 = asm_full_simplify ctxt th7\n                  val ST = nth (th8 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                          |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n                  val s3 = nth (th8 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                          |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n                  val new_p = nth (th8 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                          |> Term.strip_comb |> snd) 3 |> Thm.cterm_of ctxt\n                  val state_th = evaluate_entry_state ctxt env ST e new_p s3\n                in\n                  state_th RS th8\n                end\n              end\n          end\n        else\n          let\n            val v = s |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n            val I = s |> Thm.term_of |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n            val Or_Entry5_th = @{thm Or_Entry5}      (*Or_Entry5*)\n            val args = Or_Entry5_th |> Thm.concl_of |> Term.dest_comb |> snd\n                        |> Term.strip_comb |> snd\n            val idenv = nth args 0 |> Term.dest_Var\n            val idC = nth args 1 |> Term.dest_Var\n            val idname = nth args 2 |> Term.dest_Var\n            val ide = nth args 3 |> Term.dest_Var\n            val idp = nth args 4 |> Term.dest_Var\n            val idv = nth args 5 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n            val idI = nth args 5 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n            val th1 = Or_Entry5_th |> Drule.instantiate_normalize ([], [(idC,C),(idname,name)\n                      ,(idv, v), (idenv, env), (ide, e), (idI, I), (idp, p)])\n            val th2 = @{thm refl} RS th1\n            val th3 = asm_full_simplify ctxt th2\n            val th4 = @{thm refl} RS th3\n            val str2 = nth (th4 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                            |> Term.strip_comb |> snd |> hd |> Term.strip_comb \n                            |> snd) 0|> Thm.cterm_of ctxt\n          in\n            if str2 aconvc @{cterm \"[]::string\"} then    \n              let\n                val Or_Entry9_th = @{thm Or_Entry9}      (*Or_Entry9*)\n                val th1 = Or_Entry9_th |> Drule.instantiate_normalize ([], [(idC,C),(idname,name)\n                      ,(idv, v), (idenv, env), (ide, e), (idI, I), (idp, p)])\n                val th2 = @{thm refl} RS th1\n                val th3 = asm_full_simplify ctxt th2\n                val th3' = @{thm refl} RS th3\n                val th3'' = asm_full_simplify ctxt th3'\n                val trans_th = evaluate_transition_list ctxt env TL e name s\n                val b1 = nth (trans_th |> Thm.concl_of |> Term.dest_comb \n                           |> snd |> Term.strip_comb |> snd) 7 |> Thm.cterm_of ctxt\n              in\n                if b1 aconvc @{cterm \"False\"} then\n                  trans_th RS th3''\n                else\n                  let\n                    val Or_Entry10_th = @{thm Or_Entry10}      (*Or_Entry10*)\n                    val th1 = Or_Entry10_th |> Drule.instantiate_normalize ([], [(idC,C),(idname,name)\n                      ,(idv, v), (idenv, env), (ide, e), (idI, I), (idp, p)])\n                    val th2 = @{thm refl} RS th1\n                    val th3 = asm_full_simplify ctxt th2\n                    val th3' = @{thm refl} RS th3\n                    val th3'' = asm_full_simplify ctxt th3'\n                    val th4 = trans_th RS th3''\n                    val th5 = asm_full_simplify ctxt th4\n                    val th6 = @{thm refl} RS th5\n                    val action_list = nth (th6 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                                |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n                    val s2 = nth (th6 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                                |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n                    val actionlist_th = evaluate_actionlist ctxt env action_list e name s2\n                    val b2 = nth (actionlist_th |> Thm.concl_of |> Term.dest_comb \n                           |> snd |> Term.strip_comb |> snd) 6 |> Thm.cterm_of ctxt\n                  in\n                    if b2 aconvc @{cterm \"False\"} then\n                      actionlist_th RS th6\n                    else\n                      let\n                        val Or_Entry8_th = @{thm Or_Entry8}      (*Or_Entry8*)\n                        val th1 = Or_Entry8_th |> Drule.instantiate_normalize ([], [(idC,C),(idname,name)\n                                ,(idv, v), (idenv, env), (ide, e), (idI, I), (idp, p)])\n                        val th2 = @{thm refl} RS th1\n                        val th3 = asm_full_simplify ctxt th2\n                        val th3' = @{thm refl} RS th3\n                        val th3'' = asm_full_simplify ctxt th3'\n                        val th4 = trans_th RS th3''\n                        val th5 = asm_full_simplify ctxt th4\n                        val th6 = @{thm refl} RS th5\n                        val th8 = actionlist_th RS th6\n                        val th9 = asm_full_simplify ctxt th8\n                        val ST = nth (th9 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                                |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n                        val s3 = nth (th9 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                                |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n                        val new_p = nth (th9 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                                |> Term.strip_comb |> snd) 3 |> Thm.cterm_of ctxt\n                        val state_th = evaluate_entry_state ctxt env ST e new_p s3\n                      in\n                        state_th RS th9\n                      end\n                  end\n              end\n            else\n              let\n                val th5 = asm_full_simplify ctxt th4\n                val ST = nth (th5 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                                    |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n                val state_th = evaluate_entry_state ctxt env ST e p s\n              in\n                state_th RS th5\n              end\n          end\n      else\n        let\n          val Or_Entry7_th = @{thm Or_Entry7}      (*Or_Entry7*)\n          val args = Or_Entry7_th |> Thm.concl_of |> Term.dest_comb |> snd\n                        |> Term.strip_comb |> snd\n          val idenv = nth args 0 |> Term.dest_Var\n          val idC = nth args 1 |> Term.dest_Var\n          val idname = nth args 2 |> Term.dest_Var\n          val ide = nth args 3 |> Term.dest_Var\n          val idp = nth args 4 |> Term.dest_Var\n          val ids = nth args 5 |> Term.dest_Var\n          val th1 = Or_Entry7_th |> Drule.instantiate_normalize ([], [(idC,C),(idname,name), \n                       (idenv, env), (ide, e), (idp, p), (ids, s)])\n          val th2 = @{thm refl} RS th1\n          val th3 = asm_full_simplify ctxt th2\n          val ST = nth (th3 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                                |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n          val state_th = evaluate_entry_state ctxt env ST e p s\n        in\n          state_th RS th3\n        end\n    end\n| Const (@{const_name \"And\"}, _) $ sl' $ f' =>     (*And_Entry*)\n    let\n      val sl = Thm.cterm_of ctxt sl'\n      val f = Thm.cterm_of ctxt f'\n      val And_Entry_th = @{thm And_Entry}\n      val args = And_Entry_th |> Thm.concl_of |> Term.dest_comb |> \n                            snd |> Term.strip_comb |> snd\n      val idenv = nth args 0 |> Term.dest_Var\n      val idC = nth args 1 |> Term.dest_Var\n      val idname = nth args 2 |> Term.dest_Var\n      val ide = nth args 3 |> Term.dest_Var\n      val idp = nth args 4 |> Term.dest_Var\n      val ids = nth args 5 |> Term.dest_Var\n      val th1 = And_Entry_th |> Drule.instantiate_normalize ([], [(idC, C), (idenv, env),\n          (idname,name), (ide, e), (idp, p), (ids, s)])\n      val th2 = @{thm refl} RS th1\n      val th3 = asm_full_simplify ctxt th2\n      val pathlist_th = path_list_entry_execution ctxt env sl f e p s\n    in\n      pathlist_th RS th3\n    end\n|_ => raise CTERM (\"Not supported\", [C])\nand path_list_entry_execution ctxt env sl f e p s = \n    if (Thm.term_of sl) aconv @{term \"[]::string list\"} then\n      let\n        val empty_list_entry_th = @{thm Empty_List_Entry}\n        val args = empty_list_entry_th |> Thm.concl_of |> Term.dest_comb |> snd\n                   |> Term.strip_comb |> snd\n        val idenv = nth args 0 |> Term.dest_Var\n        val idf = nth args 2 |> Term.dest_Var\n        val ide = nth args 3 |> Term.dest_Var\n        val idp = nth args 4 |> Term.dest_Var\n        val ids = nth args 5 |> Term.dest_Var\n      in\n        empty_list_entry_th |> Drule.instantiate_normalize ([], [(ids,s), (ide, e),\n        (idenv, env), (idp, p), (idf,f)])\n      end\n    else\n      let\n        val sl1 = @{term tl} $ (Thm.term_of sl) |> Thm.cterm_of ctxt \n                  |> Simplifier.rewrite ctxt |> Thm.rhs_of\n        val str = @{term hd} $ (Thm.term_of sl) |> Thm.cterm_of ctxt \n                  |> Simplifier.rewrite ctxt |> Thm.rhs_of\n        val hd_p = Thm.apply @{cterm hd} p |> Simplifier.rewrite ctxt |> Thm.rhs_of\n      in\n        if str aconvc hd_p then\n          let\n            val path_list_entry_th2 = @{thm Path_List_Entry2}\n            val args = path_list_entry_th2 |> Thm.concl_of |> Term.dest_comb |> snd\n                   |> Term.strip_comb |> snd\n            val idenv = nth args 0 |> Term.dest_Var\n            val idstr = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n            val idsl1 = nth args 1 |> Term.dest_comb |> snd |> Term.dest_Var\n            val idf = nth args 2 |> Term.dest_Var\n            val ide = nth args 3 |> Term.dest_Var\n            val idp = nth args 4 |> Term.dest_Var\n            val ids = nth args 5 |> Term.dest_Var\n            val th1 = path_list_entry_th2 |> Drule.instantiate_normalize ([], [(idsl1,sl1),\n                      (idenv, env),(idstr,str),(ids,s),(idf,f),(ide,e),(idp,p)])\n            val th2 = asm_full_simplify ctxt th1\n            val ST = nth (th2 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                              |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n            val state_th = evaluate_entry_state ctxt env ST e p s\n            val b = nth (state_th |> Thm.concl_of |> Term.dest_comb \n                       |> snd |> Term.strip_comb |> snd) 6 |> Thm.cterm_of ctxt\n          in\n            if b aconvc @{cterm \"False\"} then\n              state_th RS th2\n            else\n              let\n                val path_list_entry_th1 = @{thm Path_List_Entry1}\n                val th1 = path_list_entry_th1 |> Drule.instantiate_normalize ([], [(idsl1,sl1),\n                      (idenv, env),(idstr,str),(ids,s),(idf,f),(ide,e),(idp,p)])\n                val th2 = asm_full_simplify ctxt th1\n                val th3 = state_th RS th2\n                val th4 = asm_full_simplify ctxt th3\n                val s2 = nth (state_th |> Thm.concl_of |> Term.dest_comb |> snd\n                              |> Term.strip_comb |> snd) 5 |> Thm.cterm_of ctxt\n                val path_list_th = path_list_entry_execution ctxt env sl1 f e p s2\n              in\n                path_list_th RS th4\n              end\n          end\n        else\n          let\n            val empty_p = @{cterm \"[]::string list\"}\n            val path_list_entry_th5 = @{thm Path_List_Entry5}\n            val args = path_list_entry_th5 |> Thm.concl_of |> Term.dest_comb |> snd\n                   |> Term.strip_comb |> snd\n            val idenv = nth args 0 |> Term.dest_Var\n            val idstr = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n            val idsl1 = nth args 1 |> Term.dest_comb |> snd |> Term.dest_Var\n            val idf = nth args 2 |> Term.dest_Var\n            val ide = nth args 3 |> Term.dest_Var\n            val idp = nth args 4 |> Term.dest_Var\n            val ids = nth args 5 |> Term.dest_Var\n            val th1 = path_list_entry_th5 |> Drule.instantiate_normalize ([], [(idsl1,sl1),\n                      (idenv, env),(idstr,str),(ids,s),(idf,f),(ide,e),(idp,p)])\n            val th2 = asm_full_simplify ctxt th1\n            val ST = nth (th2 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                              |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n            val state_th = evaluate_entry_state ctxt env ST e empty_p s\n            val b = nth (state_th |> Thm.concl_of |> Term.dest_comb \n                       |> snd |> Term.strip_comb |> snd) 6 |> Thm.cterm_of ctxt\n          in\n            if b aconvc @{cterm \"False\"} then\n              state_th RS th2\n            else\n              let\n                val path_list_entry_th4 = @{thm Path_List_Entry4}\n                val th1 = path_list_entry_th4 |> Drule.instantiate_normalize ([], [(idsl1,sl1),\n                      (idenv, env),(idstr,str),(ids,s),(idf,f),(ide,e),(idp,p)])\n                val th2 = asm_full_simplify ctxt th1\n                val th3 = state_th RS th2\n                val th4 = asm_full_simplify ctxt th3\n                val s2 = nth (state_th |> Thm.concl_of |> Term.dest_comb |> snd\n                              |> Term.strip_comb |> snd) 5 |> Thm.cterm_of ctxt\n                val path_list_th = path_list_entry_execution ctxt env sl1 f e p s2\n              in\n                path_list_th RS th4\n              end\n          end    \n      end\n\nand evaluate_State_Execution ctxt env ST e is_send s = \nif ST aconvc @{cterm \"No_State\"} then\n  evaluate_No_State_Execution env e is_send s\nelse\n  let\n    val v = s |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n    val I = s |> Thm.term_of |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n    val Outer_Trans_Execution1_th = @{thm Outer_Trans_Execution1}\n    val args = Outer_Trans_Execution1_th |> Thm.concl_of |> Term.dest_comb |> snd \n                    |> Term.strip_comb |> snd\n    val idenv = nth args 0 |> Term.dest_Var\n    val idST = nth args 1 |> Term.dest_Var\n    val ide = nth args 2 |> Term.dest_Var\n    val idis_send = nth args 3 |> Term.dest_Var\n    val idv = nth args 4 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n    val idI = nth args 4 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n    val th1 = Outer_Trans_Execution1_th |> Drule.instantiate_normalize ([], [(idv, v), (ide, e),\n                   (idST,ST),(idenv, env),(idI, I),(idis_send, is_send)])\n    val args3 = nth (th1 |> Thm.prems_of) 2 |> Term.dest_comb |> snd \n                    |> Term.strip_comb |> snd |> tl |> hd\n                    |> Term.strip_comb |> snd\n    val ids = nth args3 0 |> Term.dest_Var\n    val idh1 = nth args3 1 |> Term.dest_Var\n    val idh2 = nth args3 2 |> Term.dest_Var\n    val idh3 = nth args3 3 |> Term.dest_Var\n    val ido1 = nth args3 4 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n    val ido2 =  nth args3 4 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n    val V = nth (th1 |> Thm.prems_of) 2 |> Term.dest_comb |> snd \n                    |> Term.strip_comb |> snd |> hd |> Term.strip_comb |> snd\n    val s = nth V 0 |> Thm.cterm_of ctxt\n    val h1 = nth V 1 |> Thm.cterm_of ctxt\n    val h2 = nth V 2 |> Thm.cterm_of ctxt\n    val h3 = nth V 3 |> Thm.cterm_of ctxt\n    val o1 = nth V 4 |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n    val o2 = nth V 4 |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n    val th2 = @{thm refl} RS th1\n    val th2' = th2 |> Drule.instantiate_normalize ([], [(ids, s), (idh1, h1),\n                    (idh2,h2),(idh3, h3), (ido1, o1),(ido2, o2)])\n    val th3 = asm_full_simplify ctxt th2'\n    val th4 = [@{thm refl}, @{thm refl}, @{thm refl}] MRS th3\n    val trans_out = nth (th4 |>Thm.prems_of |> hd |> Term.dest_comb |> snd \n                        |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n    val s2 = nth (th4 |>Thm.prems_of |> hd |> Term.dest_comb |> snd \n                        |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n    val name = nth (th4 |>Thm.prems_of |> hd |> Term.dest_comb |> snd \n                        |> Term.strip_comb |> snd) 3 |> Thm.cterm_of ctxt\n    val outer_trans_th = evaluate_transition_list ctxt env trans_out e name s2\n    val n1 = nth (outer_trans_th |> Thm.concl_of |> Term.dest_comb |> snd \n                        |> Term.strip_comb |> snd) 6 |> Thm.cterm_of ctxt\n    val b1 = nth (outer_trans_th |> Thm.concl_of |> Term.dest_comb |> snd \n                        |> Term.strip_comb |> snd) 7 |> Thm.cterm_of ctxt\n  in\n    if b1 aconvc @{cterm \"False\"} then\n    let\n      val Outer_Trans_Termination_th = @{thm Outer_Trans_Termination}     (*Outer Transition Termination*)\n      val th1 = Outer_Trans_Termination_th |> Drule.instantiate_normalize ([], [(idv, v), (ide, e),\n                   (idST,ST),(idenv, env),(idI, I),(idis_send, is_send)])\n      val th2 = @{thm refl} RS th1\n      val th2' = th2 |> Drule.instantiate_normalize ([], [(ids, s), (idh1, h1),\n                      (idh2,h2), (idh3, h3), (ido1, o1),(ido2, o2)])\n      val th3 = asm_full_simplify ctxt th2'\n      val th4 = [@{thm refl}, @{thm refl}, @{thm refl}] MRS th3\n    in\n      outer_trans_th RS th4\n    end\n    else if n1 aconvc @{cterm \"1::int\"} then\n    let\n      val th5 = outer_trans_th RS th4\n      val idp0 = th5 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                           |> Term.strip_comb |> snd |> tl |> hd\n                           |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n      val p0 = th5 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                           |> Term.strip_comb |> snd |> hd\n                           |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n      val th6 = th5 |> Drule.instantiate_normalize ([], [(idp0,p0)])\n      val ctrm = th6 |>Thm.prems_of |> hd |> Term.dest_comb |> snd\n            |> Term.strip_comb |> snd  |> hd |> Thm.cterm_of ctxt\n      val th_tmp = (Thm.beta_conversion true ctrm) RS @{thm meta_eq_to_obj_eq}\n      val th7 = th_tmp RS th6\n      val th8 = @{thm refl} RS th7\n      val th9 = asm_full_simplify ctxt th8\n      val C_out = nth (th9 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                            |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n      val name2 = nth (th9 |>Thm.prems_of |> hd |> Term.dest_comb |> snd \n                            |> Term.strip_comb |> snd) 2 |> Thm.cterm_of ctxt\n      val s3 = nth (th9 |>Thm.prems_of |> hd |> Term.dest_comb |> snd \n                            |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n      val comp_exit_th = evaluate_exit_composition ctxt env C_out name2 e s3\n      val b6 = nth (comp_exit_th |> Thm.concl_of |> Term.dest_comb |> snd \n                            |> Term.strip_comb |> snd) 6 |> Thm.cterm_of ctxt\n    in\n      if b6 aconvc @{cterm \"False\"} then\n      let\n        val Outer_Trans_Execution2_th = @{thm Outer_Trans_Execution2}    \n        (* Outer_Trans Terminate in Exit \"Send\" *)\n        val th1 = Outer_Trans_Execution2_th |> Drule.instantiate_normalize ([], [(idv, v), (ide, e),\n                   (idST,ST),(idenv, env),(idI, I),(idis_send, is_send)])\n        val th2 = @{thm refl} RS th1\n        val th2' = th2 |> Drule.instantiate_normalize ([], [(ids, s), (idh1, h1),\n                        (idh2,h2), (idh3, h3), (ido1, o1),(ido2, o2)])\n        val th3 = asm_full_simplify ctxt th2'\n        val th4 = [@{thm refl}, @{thm refl}, @{thm refl}] MRS th3\n        val th5 = outer_trans_th RS th4\n        val th6 = th5 |> Drule.instantiate_normalize ([], [(idp0,p0)])\n        val ctrm = th6 |>Thm.prems_of |> hd |> Term.dest_comb |> snd\n            |> Term.strip_comb |> snd  |> hd |> Thm.cterm_of ctxt\n        val th_tmp = (Thm.beta_conversion true ctrm) RS @{thm meta_eq_to_obj_eq}\n        val th7 = th_tmp RS th6\n        val th8 = @{thm refl} RS th7\n        val th9 = asm_full_simplify ctxt th8\n      in\n        comp_exit_th RS th9\n      end\n      else\n      let\n        val th10 = comp_exit_th RS th9\n        val action_list = nth (th10 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                                 |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n        val name = nth (th10 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                                 |> Term.strip_comb |> snd) 3 |> Thm.cterm_of ctxt\n        val s4 = nth (th10 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                                 |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n        val actionlist_th = evaluate_actionlist ctxt env action_list e name s4\n        val b7 = nth (actionlist_th |> Thm.concl_of |> Term.dest_comb |> snd \n                            |> Term.strip_comb |> snd) 6 |> Thm.cterm_of ctxt\n      in\n        if b7 aconvc @{cterm \"False\"} then\n        let\n           val Outer_Trans_Execution3_th = @{thm Outer_Trans_Execution3}\n            (* Outer_Trans Terminate in Transition action \"Send\" *)\n           val th1 = Outer_Trans_Execution3_th |> Drule.instantiate_normalize ([], [(idv, v), (ide, e),\n                   (idST,ST),(idenv, env),(idI, I),(idis_send, is_send)])\n           val th2 = @{thm refl} RS th1\n           val th2' = th2 |> Drule.instantiate_normalize ([], [(ids, s), (idh1, h1),\n                           (idh2,h2), (idh3, h3), (ido1, o1),(ido2, o2)])\n           val th3 = asm_full_simplify ctxt th2'\n           val th4 = [@{thm refl}, @{thm refl}, @{thm refl}] MRS th3\n           val th5 = outer_trans_th RS th4\n           val th6 = th5 |> Drule.instantiate_normalize ([], [(idp0,p0)])\n           val ctrm = th6 |>Thm.prems_of |> hd |> Term.dest_comb |> snd\n                   |> Term.strip_comb |> snd  |> hd |> Thm.cterm_of ctxt\n           val th_tmp = (Thm.beta_conversion true ctrm) RS @{thm meta_eq_to_obj_eq}\n           val th7 = th_tmp RS th6\n           val th8 = @{thm refl} RS th7\n           val th9 = asm_full_simplify ctxt th8\n           val th10 = comp_exit_th RS th9\n        in\n          actionlist_th RS th10\n        end\n        else\n        let\n          val th11 = actionlist_th RS th10\n          val th13 = [@{thm refl}, @{thm refl}] MRS th11\n          val th14 = asm_full_simplify ctxt th13\n          val C_in = nth (th14 |>Thm.prems_of |> hd |> Term.dest_comb |> snd \n                              |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n          val name3 = nth (th14 |>Thm.prems_of |> hd |> Term.dest_comb |> snd \n                              |> Term.strip_comb |> snd) 2 |> Thm.cterm_of ctxt\n          val s5 = nth (th14 |>Thm.prems_of |> hd |> Term.dest_comb |> snd \n                              |> Term.strip_comb |> snd) 5 |> Thm.cterm_of ctxt\n          val p_in = nth (th14 |>Thm.prems_of |> hd |> Term.dest_comb |> snd \n                              |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n          val comp_entry_th = evaluate_entry_composition ctxt env C_in name3 e p_in s5\n        in\n          comp_entry_th RS th14\n        end\n      end\n    end\n    else\n      let\n        val Fail_Trans_Execution_th = @{thm Fail_Trans_Execution}\n        val args = Fail_Trans_Execution_th |> Thm.concl_of |> Term.dest_comb |> snd \n                        |> Term.strip_comb |> snd\n        val idenv = nth args 0 |> Term.dest_Var\n        val idST = nth args 1 |> Term.dest_Var\n        val ide = nth args 2 |> Term.dest_Var\n        val idis_send = nth args 3 |> Term.dest_Var\n        val idv = nth args 4 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n        val idI = nth args 4 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n        val th1 = Fail_Trans_Execution_th |> Drule.instantiate_normalize ([], [(idv, v), (ide, e),\n                   (idST,ST),(idenv, env),(idI, I),(idis_send, is_send)])\n        val args3 = nth (th1 |> Thm.prems_of) 2 |> Term.dest_comb |> snd \n                    |> Term.strip_comb |> snd |> tl |> hd\n                    |> Term.strip_comb |> snd\n        val ids = nth args3 0 |> Term.dest_Var\n        val idh1 = nth args3 1 |> Term.dest_Var\n        val idh2 = nth args3 2 |> Term.dest_Var\n        val idh3 = nth args3 3 |> Term.dest_Var\n        val ido1 = nth args3 4 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n        val ido2 =  nth args3 4 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n        val V = nth (th1 |> Thm.prems_of) 2 |> Term.dest_comb |> snd \n                        |> Term.strip_comb |> snd |> hd |> Term.strip_comb |> snd\n        val s = nth V 0 |> Thm.cterm_of ctxt\n        val h1 = nth V 1 |> Thm.cterm_of ctxt\n        val h2 = nth V 2 |> Thm.cterm_of ctxt\n        val h3 = nth V 3 |> Thm.cterm_of ctxt\n        val o1 = nth V 4 |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n        val o2 = nth V 4 |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n        val th2 = @{thm refl} RS th1\n        val th2' = th2 |> Drule.instantiate_normalize ([], [(ids, s), (idh1, h1),\n                        (idh2,h2), (idh3, h3), (ido1, o1),(ido2, o2)])\n        val th3 = asm_full_simplify ctxt th2'\n        val th4 = [@{thm refl}, @{thm refl}, @{thm refl}] MRS th3\n        val th5 = outer_trans_th RS th4\n        val th6 = asm_full_simplify ctxt th5\n        val du_act = nth (th6 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                                |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n        val s3 = nth (th6 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                                |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n        val during_action_th = evaluate_action ctxt env (Thm.term_of du_act) e name s3\n        val b2 = nth (during_action_th |> Thm.concl_of |> Term.dest_comb |> snd \n                            |> Term.strip_comb |> snd) 6 |> Thm.cterm_of ctxt\n      in\n        if b2 aconvc @{cterm \"False\"} then\n        let\n          val Inner_Trans_Execution2_th = @{thm Inner_Trans_Execution2}\n          (* Inner_Trans Terminate in During \"Send\" *)\n          val th1 = Inner_Trans_Execution2_th |> Drule.instantiate_normalize ([], [(idv, v), (ide, e),\n                   (idST,ST),(idenv, env),(idI, I),(idis_send, is_send)])\n          val th2 = @{thm refl} RS th1\n          val th2' = th2 |> Drule.instantiate_normalize ([], [(ids, s), (idh1, h1),\n                          (idh2,h2), (idh3, h3), (ido1, o1),(ido2, o2)])\n          val th3 = asm_full_simplify ctxt th2'\n          val th4 = [@{thm refl}, @{thm refl}, @{thm refl}] MRS th3\n          val th5 = outer_trans_th RS th4\n          val th6 = asm_full_simplify ctxt th5\n        in\n          during_action_th RS th6\n        end\n        else\n          let\n            val th8 = during_action_th RS th6\n            val trans_in = nth (th8 |>Thm.prems_of |> hd |> Term.dest_comb |> snd \n                                |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n            val s4 = nth (th8 |>Thm.prems_of |> hd |> Term.dest_comb |> snd \n                                |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n            val inner_trans_th = evaluate_transition_list ctxt env trans_in e name s4\n            val n2 = nth (inner_trans_th |> Thm.concl_of |> Term.dest_comb |> snd \n                            |> Term.strip_comb |> snd) 6 |> Thm.cterm_of ctxt\n            val b3 = nth (inner_trans_th |> Thm.concl_of |> Term.dest_comb |> snd \n                            |> Term.strip_comb |> snd) 7 |> Thm.cterm_of ctxt\n          in\n            if b3 aconvc @{cterm \"False\"} then\n            let\n              val Inner_Trans_Termination_th = @{thm Inner_Trans_Termination}\n              (* Inner_Trans Terminate in Inner Transition *)\n              val th1 = Inner_Trans_Termination_th |> Drule.instantiate_normalize ([], [(idv, v), (ide, e),\n                   (idST,ST),(idenv, env),(idI, I),(idis_send, is_send)])\n              val th2 = @{thm refl} RS th1\n              val th2' = th2 |> Drule.instantiate_normalize ([], [(ids, s), (idh1, h1),\n                              (idh2,h2), (idh3, h3), (ido1, o1),(ido2, o2)])\n              val th3 = asm_full_simplify ctxt th2'\n              val th4 = [@{thm refl}, @{thm refl}, @{thm refl}] MRS th3\n              val th5 = outer_trans_th RS th4\n              val th6 = asm_full_simplify ctxt th5\n              val th8 = during_action_th RS th6\n            in\n              inner_trans_th RS th8\n            end\n            else if n2 aconvc @{cterm \"1::int\"} then\n              let\n                val Inner_Trans_Execution1_th = @{thm Inner_Trans_Execution1}\n                        (* Inner_Trans Terminate Succeed *)\n                val th1 = Inner_Trans_Execution1_th |> Drule.instantiate_normalize ([], [(idv, v), (ide, e),\n                   (idST,ST),(idenv, env),(idI, I),(idis_send, is_send)])\n                val th2 = @{thm refl} RS th1\n                val th2' = th2 |> Drule.instantiate_normalize ([], [(ids, s), (idh1, h1),\n                                (idh2,h2), (idh3, h3), (ido1, o1),(ido2, o2)])\n                val th3 = asm_full_simplify ctxt th2'\n                val th4 = [@{thm refl}, @{thm refl}, @{thm refl}] MRS th3\n                val th5 = outer_trans_th RS th4\n                val th6 = asm_full_simplify ctxt th5\n                val th8 = during_action_th RS th6\n                val th9 = inner_trans_th RS th8\n                val th10 = asm_full_simplify ctxt th9\n                val idp0 = th10 |>Thm.prems_of |> hd |> Term.dest_comb |> snd \n                           |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n                val p0 = th10 |>Thm.prems_of |> hd |> Term.dest_comb |> snd \n                           |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n                val th11 = th10 |> Drule.instantiate_normalize ([], [(idp0,p0)])\n                val ctrm = th11 |>Thm.prems_of |> hd |> Term.dest_comb |> snd\n                    |> Term.strip_comb |> snd  |> hd |> Thm.cterm_of ctxt\n                val th_tmp = (Thm.beta_conversion true ctrm) RS @{thm meta_eq_to_obj_eq}\n                val th12 = th_tmp RS th11\n                val th12' = @{thm refl} RS th12\n                val th12'' = asm_full_simplify ctxt th12'\n                val C = nth (th12'' |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                                 |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n                val ex_ST = nth (th12'' |>Thm.prems_of |> hd |> Term.dest_comb |> snd \n                                 |> Term.strip_comb |> snd) 2 |> Thm.cterm_of ctxt\n                val s5 = nth (th12'' |>Thm.prems_of |> hd |> Term.dest_comb |> snd \n                                 |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n                val comp_exit_th = evaluate_exit_composition ctxt env C ex_ST e s5\n                val b4 = nth (comp_exit_th |> Thm.concl_of |> Term.dest_comb |> snd \n                            |> Term.strip_comb |> snd) 6 |> Thm.cterm_of ctxt\n              in\n                if b4 aconvc @{cterm \"False\"} then\n                let\n                  val Inner_Trans_Execution3_th = @{thm Inner_Trans_Execution3}\n                  (* Inner_Trans Terminate in Exit \"Send\" *)\n                  val th1 = Inner_Trans_Execution3_th |> Drule.instantiate_normalize ([], [(idv, v), (ide, e),\n                   (idST,ST),(idenv, env),(idI, I),(idis_send, is_send)])\n                  val th2 = @{thm refl} RS th1\n                  val th2' = th2 |> Drule.instantiate_normalize ([], [(ids, s), (idh1, h1),\n                                  (idh2,h2), (idh3, h3), (ido1, o1),(ido2, o2)])\n                  val th3 = asm_full_simplify ctxt th2'\n                  val th4 = [@{thm refl}, @{thm refl}, @{thm refl}] MRS th3\n                  val th5 = outer_trans_th RS th4\n                  val th6 = asm_full_simplify ctxt th5\n                  val th8 = during_action_th RS th6\n                  val th9 = inner_trans_th RS th8\n                  val th10 = asm_full_simplify ctxt th9\n                  val th11 = th10 |> Drule.instantiate_normalize ([], [(idp0,p0)])\n                  val ctrm = th11 |>Thm.prems_of |> hd |> Term.dest_comb |> snd\n                      |> Term.strip_comb |> snd  |> hd |> Thm.cterm_of ctxt\n                  val th_tmp = (Thm.beta_conversion true ctrm) RS @{thm meta_eq_to_obj_eq}\n                  val th12 = th_tmp RS th11\n                  val th12' = @{thm refl} RS th12\n                  val th12'' = asm_full_simplify ctxt th12'\n                in\n                  comp_exit_th RS th12''\n                end\n                else\n                let\n                  val th13 = comp_exit_th RS th12''\n                  val action_list = nth (th13 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                                   |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n                  val s6 = nth (th13 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                                   |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n                  val actionlist_th = evaluate_actionlist ctxt env action_list e name s6\n                  val b5 = nth (actionlist_th |> Thm.concl_of |> Term.dest_comb |> snd \n                            |> Term.strip_comb |> snd) 6 |> Thm.cterm_of ctxt\n                in\n                  if b5 aconvc @{cterm \"False\"} then\n                  let\n                    val Inner_Trans_Execution4_th = @{thm Inner_Trans_Execution4}\n                    (* Inner_Trans Terminate in Transition Action \"Send\" *)\n                    val th1 = Inner_Trans_Execution4_th |> Drule.instantiate_normalize ([], [(idv, v), (ide, e),\n                   (idST,ST),(idenv, env),(idI, I),(idis_send, is_send)])\n                    val th2 = @{thm refl} RS th1\n                    val th2' = th2 |> Drule.instantiate_normalize ([], [(ids, s), (idh1, h1),\n                                    (idh2,h2), (idh3, h3), (ido1, o1),(ido2, o2)])\n                    val th3 = asm_full_simplify ctxt th2'\n                    val th4 = [@{thm refl}, @{thm refl}, @{thm refl}] MRS th3\n                    val th5 = outer_trans_th RS th4\n                    val th6 = asm_full_simplify ctxt th5\n                    val th8 = during_action_th RS th6\n                    val th9 = inner_trans_th RS th8\n                    val th10 = asm_full_simplify ctxt th9\n                    val th11 = th10 |> Drule.instantiate_normalize ([], [(idp0,p0)])\n                    val ctrm = th11 |>Thm.prems_of |> hd |> Term.dest_comb |> snd\n                        |> Term.strip_comb |> snd  |> hd |> Thm.cterm_of ctxt\n                    val th_tmp = (Thm.beta_conversion true ctrm) RS @{thm meta_eq_to_obj_eq}\n                    val th12 = th_tmp RS th11\n                    val th12' = @{thm refl} RS th12\n                    val th12'' = asm_full_simplify ctxt th12'\n                    val th13 = comp_exit_th RS th12''\n                  in\n                    actionlist_th RS th13\n                  end\n                  else\n                  let\n                    val th15 = actionlist_th RS th13\n                    val th16 = [@{thm refl}, @{thm refl}] MRS th15\n                    val th17 = asm_full_simplify ctxt th16\n                    val C_in = nth (th17 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                               |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n                    val name2 = nth (th17 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                               |> Term.strip_comb |> snd) 2 |> Thm.cterm_of ctxt\n                    val s7 = nth (th17 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                               |> Term.strip_comb |> snd) 5 |> Thm.cterm_of ctxt\n                    val p_in = nth (th17 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                               |> Term.strip_comb |> snd) 4 |> Thm.cterm_of ctxt\n                    val comp_entry_th = evaluate_entry_composition ctxt env C_in name2 e p_in s7\n                  in\n                    comp_entry_th RS th17\n                  end \n                end\n              end\n            else\n              let\n                val th9 = inner_trans_th RS th8\n                val th10 = asm_full_simplify ctxt th9\n                val C = nth (th10 |>Thm.prems_of |> hd |> Term.dest_comb |> snd \n                                 |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n                val s5 = nth (th10 |>Thm.prems_of |> hd |> Term.dest_comb |> snd \n                                    |> Term.strip_comb |> snd) 5 |> Thm.cterm_of ctxt\n                val comp_exec_th = \n              evaluate_Composition_Execution ctxt env C name e is_send s5\n              in\n                comp_exec_th RS th10\n              end\n          end\n      end\n  end\nand evaluate_Composition_Execution ctxt env C name e is_send s = \nlet\n  val v = s |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n  val I = s |> Thm.term_of |> Term.strip_comb |> snd |> tl |> hd |> Thm.cterm_of ctxt\n  val empty_p = @{cterm \"[]::string list\"}\n  val info = Simplifier.rewrite ctxt (Thm.apply I empty_p) |> Thm.rhs_of\n  val b0 = info |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\nin\n  if (b0 aconvc @{cterm \"False\"}) then\n    let\n      val Start_Execution_th = @{thm Start_Execution}\n      val args = Start_Execution_th |> Thm.concl_of |> Term.dest_comb |> snd \n                      |> Term.strip_comb |> snd\n      val idenv = nth args 0 |> Term.dest_Var\n      val idC = nth args 1 |> Term.dest_Var\n      val idname = nth args 2 |> Term.dest_Var\n      val ide = nth args 3 |> Term.dest_Var\n      val idis_send = nth args 4 |> Term.dest_Var\n      val idv = nth args 5 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n      val idI = nth args 5 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n      val th1 = Start_Execution_th |> Drule.instantiate_normalize ([], [(idv, v), (ide, e),\n               (idC,C), (idname, name),(idI, I),(idenv, env),(idis_send, is_send)])\n      val th3 = asm_full_simplify ctxt th1\n      val th5 = @{thm refl} RS th3\n      val ST = nth (th5 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                              |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n      val empty_p = @{cterm \"[]::string list\"}\n      val state_entry_th = evaluate_entry_state ctxt env ST e empty_p s\n      \n    in\n      state_entry_th RS th5\n    end\n  else\n    case (Thm.term_of C) of\n      Const (@{const_name \"No_Composition\"}, _) =>     (*No_Composition_Execution*)\n        evaluate_No_Composition_Execution env name e is_send s\n    | Const (@{const_name \"Or\"}, _) $ TL' $ b' $ f' =>     (*Or_Execution*)\n      let\n        val TL = Thm.cterm_of ctxt TL'\n        val b = Thm.cterm_of ctxt b'\n        val f = Thm.cterm_of ctxt f'\n        val Or_Execution_th = @{thm Or_Execution}\n        val args = Or_Execution_th |> Thm.concl_of |> Term.dest_comb |> snd \n                        |> Term.strip_comb |> snd\n        val idenv = nth args 0 |> Term.dest_Var\n        val idC = nth args 1 |> Term.dest_Var\n        val idname = nth args 2 |> Term.dest_Var\n        val ide = nth args 3 |> Term.dest_Var\n        val idis_send = nth args 4 |> Term.dest_Var\n        val idv = nth args 5 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n        val idI = nth args 5 |> Term.strip_comb |> snd |> tl |> hd |> Term.dest_Var\n        val th1 = Or_Execution_th |> Drule.instantiate_normalize ([], [(idv, v), (ide, e),\n               (idC,C), (idname, name),(idI, I),(idenv, env),(idis_send, is_send)])\n        val idTL = nth (th1 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                              |> Term.strip_comb |> snd |> tl |> hd |> Term.strip_comb \n                              |> snd) 0 |> Term.dest_Var\n        val idb = nth (th1 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                              |> Term.strip_comb |> snd |> tl |> hd |> Term.strip_comb \n                              |> snd) 1 |> Term.dest_Var\n        val idf = nth (th1 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                              |> Term.strip_comb |> snd |> tl |> hd |> Term.strip_comb \n                              |> snd) 2 |> Term.dest_Var\n        val th2 = th1 |> Drule.instantiate_normalize ([], [(idTL,TL),(idb, b), \n                           (idf, f)])\n        val th3 = asm_full_simplify ctxt th2\n        val th4 = @{thm refl} RS th3\n        val th5 = asm_full_simplify ctxt th4\n        val ST = nth (th5 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                                |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n        val state_execution_th = \n        evaluate_State_Execution ctxt env ST e is_send s\n      in\n        state_execution_th RS th5\n      end\n    | Const (@{const_name \"And\"}, _) $ sl' $ f' =>     (*And_Execution*)\n      let\n        val sl = Thm.cterm_of ctxt sl'\n        val f = Thm.cterm_of ctxt f'\n        val And_Execution_th = @{thm And_Execution}\n        val args = And_Execution_th |> Thm.concl_of |> Term.dest_comb |> snd \n                        |> Term.strip_comb |> snd\n        val idenv = nth args 0 |> Term.dest_Var\n        val idC = nth args 1 |> Term.dest_Var\n        val idname = nth args 2 |> Term.dest_Var\n        val ide = nth args 3 |> Term.dest_Var\n        val idis_send = nth args 4 |> Term.dest_Var\n        val ids = nth args 5 |> Term.dest_Var\n        val th1 = And_Execution_th |> Drule.instantiate_normalize ([], [(ids, s), (ide, e),\n                  (idC,C), (idname, name),(idenv, env),(idis_send, is_send)])\n        val idsl = nth (th1 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                              |> Term.strip_comb |> snd |> tl |> hd |> Term.strip_comb \n                              |> snd) 0 |> Term.dest_Var\n        val idf = nth (th1 |> Thm.prems_of |> hd |> Term.dest_comb |> snd\n                              |> Term.strip_comb |> snd |> tl |> hd |> Term.strip_comb \n                              |> snd) 1 |> Term.dest_Var\n        val th2 = th1 |> Drule.instantiate_normalize ([], [(idsl,sl),(idf, f)])\n        val th3 = asm_full_simplify ctxt th2\n        val path_list_execution_th = \n            evaluate_path_list_execution ctxt env sl f e is_send s\n      in\n        path_list_execution_th RS th3\n      end\n    |_ => raise CTERM (\"Not supported\", [C])\nend\nand evaluate_path_list_execution ctxt env sl f e is_send s = \nif sl aconvc @{cterm \"[]::string list\"} then\n  evaluate_Empty_Pathlist_Execution env f e is_send s\nelse\n  let\n    val sl1 = @{term tl} $ (Thm.term_of sl) |> Thm.cterm_of ctxt \n                  |> Simplifier.rewrite ctxt |> Thm.rhs_of\n    val str = @{term hd} $ (Thm.term_of sl) |> Thm.cterm_of ctxt \n                  |> Simplifier.rewrite ctxt |> Thm.rhs_of\n    val pathlist_execution_th2 = @{thm Pathlist_Execution2}\n    val args = pathlist_execution_th2 |> Thm.concl_of |> Term.dest_comb |> snd\n                   |> Term.strip_comb |> snd\n    val idenv = nth args 0 |> Term.dest_Var\n    val idstr = nth args 1 |> Term.strip_comb |> snd |> hd |> Term.dest_Var\n    val idsl1 = nth args 1 |> Term.dest_comb |> snd |> Term.dest_Var\n    val idf = nth args 2 |> Term.dest_Var\n    val ide = nth args 3 |> Term.dest_Var\n    val idis_send = nth args 4 |> Term.dest_Var\n    val ids = nth args 5 |> Term.dest_Var\n    val th1 = pathlist_execution_th2 |> Drule.instantiate_normalize ([], [(idsl1,sl1),\n              (idstr,str),(ids,s),(idf,f),(ide,e),(idenv,env),(idis_send, is_send)])\n    val th2 = asm_full_simplify ctxt th1\n    val ST = nth (th2 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                            |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n    val state_th = evaluate_State_Execution ctxt env ST e is_send s\n    val b = nth (state_th |> Thm.concl_of |> Term.dest_comb |> snd \n                 |> Term.strip_comb |> snd) 6 |> Thm.cterm_of ctxt\n  in\n    if b aconvc @{cterm \"False\"} then\n      state_th RS th2\n    else\n      let\n        val pathlist_execution_th1 = @{thm Pathlist_Execution1}\n        val th1 = pathlist_execution_th1 |> Drule.instantiate_normalize ([], [(idsl1,sl1),\n              (idstr,str),(ids,s),(idf,f),(ide,e),(idenv,env),(idis_send, is_send)])\n        val th2 = asm_full_simplify ctxt th1\n        val th3 = state_th RS th2\n        val s2 = nth (th3 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                                |> Term.strip_comb |> snd) 5 |> Thm.cterm_of ctxt\n        val path_list_execution_th = \n            evaluate_path_list_execution ctxt env sl1 f e is_send s2\n      in\n        path_list_execution_th RS th3\n      end\n  end\n\\<close>\n\nML \\<open>\nfun evaluate_root_exec_for_times ctxt env e n s = \n  if n aconvc @{cterm \"0::int\"} then\n    let\n      val root_exec_for_times_th1 = @{thm Root_Exec_for_Times1}\n      val args = root_exec_for_times_th1 |> Thm.concl_of \n                  |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n      val idenv = nth args 0 |> Term.dest_Var\n      val ide = nth args 1 |> Term.dest_Var\n      val ids = nth args 3 |> Term.dest_Var\n    in\n      root_exec_for_times_th1 |> Drule.instantiate_normalize ([], [(idenv, env),\n              (ide, e), (ids, s)])\n    end\n  else\n    let\n      val root_exec_for_times_th2 = @{thm Root_Exec_for_Times2}\n      val args = root_exec_for_times_th2 |> Thm.concl_of \n                  |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n      val idenv = nth args 0 |> Term.dest_Var\n      val ide = nth args 1 |> Term.dest_Var\n      val ids = nth args 3 |> Term.dest_Var\n      val idn = nth args 2 |> Term.dest_Var\n      val th1 = root_exec_for_times_th2 |> Drule.instantiate_normalize ([], [(idenv, env),\n              (ide, e), (ids, s), (idn, n)])\n      val th2 = asm_full_simplify ctxt th1\n      val empty_name = @{cterm \"[]::string list\"}\n      val is_send = @{cterm \"False\"}\n      val e' = nth (th2 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                            |> Term.strip_comb |> snd) 3 |> Thm.cterm_of ctxt\n      val root = env |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\n      val t_start = Timing.start ()\n      val comp_th = evaluate_Composition_Execution ctxt env root empty_name e' is_send s\n      val th3 = comp_th RS th2\n      val t_end = Timing.result t_start\n      val _ = writeln (\"Test\" ^ (Timing.message t_end))\n      val s2 = nth (th3 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                            |> Term.strip_comb |> snd) 3 |> Thm.cterm_of ctxt\n      val n2 = nth (th3 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                            |> Term.strip_comb |> snd) 2 |> Thm.cterm_of ctxt\n      val e2 = nth (th3 |> Thm.prems_of |> hd |> Term.dest_comb |> snd \n                            |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\n      val root_exec_th = evaluate_root_exec_for_times ctxt env e2 n2 s2\n    in\n      root_exec_th RS th3\n    end\n\n\\<close>\n\nschematic_goal myconj:\"?x = ?x \\<and> ?y = ?y\"\n  by auto\n\\<comment> \\<open>some tests in ML level\\<close>\nML \\<open>\nval ctxt = @{context}\nval A = @{cterm \"State [''A''] SKIP SKIP SKIP [] [Trans (P [''A'']) (T1 (Before ''E_one'' (N 2))) \n((V ''x'') [>] (V ''y'')) SKIP SKIP (P [''B''])] No_Composition\"}\nval B = @{cterm \"State [''B''] SKIP SKIP SKIP [] [] No_Composition\"}\nval Root = @{cterm \"Or [Trans NONE (S '''') (Bc True) SKIP SKIP (P [''A''])] False\n(\\<lambda>x. (if x = ''A'' then (State [''A''] SKIP SKIP SKIP [] [Trans (P [''A'']) (T1 (Before ''E_one'' (N 2))) \n((V ''x'') [>] (V ''y'')) SKIP SKIP (P [''B''])] No_Composition) else\n(if x = ''B'' then (State [''B''] SKIP SKIP SKIP [] [] No_Composition) else No_State)))\"}\nval env = @{cterm \"Env (Or [Trans NONE (S '''') (Bc True) SKIP SKIP (P [''A''])] False\n(\\<lambda>x. (if x = ''A'' then (State [''A''] SKIP SKIP SKIP [] [Trans (P [''A'']) (T1 (Before ''E_one'' (N 2))) \n((V ''x'') [>] (V ''y'')) (''x'' ::= (N 2)) SKIP (P [''B''])] No_Composition) else\n(if x = ''B'' then (State [''B''] SKIP SKIP SKIP [] [] No_Composition) else No_State))))\n(\\<lambda>name. (SKIP, No_Expr, No_Expr))\n(\\<lambda>name. ((Trans NONE (S []) (Bc True) SKIP SKIP NONE), No_Expr, No_Expr))\n(\\<lambda>x.[]::transition list)\"}\nval root = env |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\nval fe = nth (env |> Thm.term_of |> Term.strip_comb |> snd) 1 |> Thm.cterm_of ctxt\nval ge = nth (env |> Thm.term_of |> Term.strip_comb |> snd) 2 |> Thm.cterm_of ctxt\nval g = nth (env |> Thm.term_of |> Term.strip_comb |> snd) 3 |> Thm.cterm_of ctxt\nval p = @{cterm \"[''A'']\"}\nval e = @{cterm \"''E_one''::string\"}\nval t = @{cterm \"Trans (P [''A'']) (T1 (Before ''E_one'' (N 2))) \n((V ''x'') [>] (V ''y'')) (print1 ''cond_act'') SKIP (P [''B''])\"}\nval T = @{cterm \"[Trans (P [''A'']) (T1 (After ''E_one'' (N 2))) \n((V ''x'') [>] (V ''y'')) (print1 ''cond_act'') SKIP (P [''B''])]\"}\nval Chart = @{cterm \"\\<lambda>x. (if x = [''A''] then (Info True [] []) else\nif x = ([]::string list) then (Info True  ''A'' []) else\n(Info False [] []))\"}\nval s = @{cterm \"Status (Vals (\\<lambda>x. (if x = ''x'' then (1::int) else (0::int)))\n (\\<lambda>p str. 0) (\\<lambda>x. 0) (\\<lambda>x. []) ([], [])) (\\<lambda>x. (if x = [''A''] then (Info True [] []) else\nif x = ([]::string list) then (Info True  ''A'' []) else\n(Info False [] [])))\"}\nval v = s |> Thm.term_of |> Term.strip_comb |> snd |> hd |> Thm.cterm_of ctxt\nval th = evaluate_exit_state ctxt env A e s\n\\<close>\ndefinition fe::fenv where \"\n  fe name = (SKIP, No_Expr, No_Expr)\"\n\n\nML \\<open>\nsignature STATEFLOW_EXECUTION1 = \nsig\n  val stateflow_execution1_tac: Proof.context -> tactic\nend\n\nstructure Stateflow_Execution1 : STATEFLOW_EXECUTION1 = \nstruct\n\nfun stateflow_execution1_tac ctxt state = \n  let\n    val subgoals = state |> Thm.cprop_of |> Drule.strip_imp_prems\n    (*val _ = pwriteln (pretty_term ctxt (Thm.term_of (hd subgoals)))*)\n  in\n    if null subgoals then Seq.empty else\n    let\n      val c_subgoal = hd subgoals\n      val subgoal = Thm.term_of c_subgoal\n      val args = subgoal |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n      val env = nth args 0 |> Thm.cterm_of ctxt\n      val C = nth args 1 |> Thm.cterm_of ctxt\n      val name = nth args 2 |> Thm.cterm_of ctxt\n      val e = nth args 3 |> Thm.cterm_of ctxt\n      val s1 = nth args 5 |> Thm.cterm_of ctxt\n      val th = evaluate_Composition_Execution ctxt env C name e @{cterm \"False\"} s1\n      val args_res = th |> Thm.prop_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n      val _ = pwriteln (pretty_term ctxt (nth args_res 6))\n(*      val _ = pwriteln (pretty_term ctxt (Thm.prop_of th)) *)\n    in\n      Seq.single (th RS state)\n    end\n  end\nend\n\n\\<close>\n\nlemma \"V ''x'' = V ''x''\"\n  by auto\nschematic_goal test:\"?x = ?x \\<and> ?y = ?y\"\n  by auto\n\nmethod_setup stateflow_execution1 \n= \\<open>Scan.succeed (SIMPLE_METHOD o Stateflow_Execution1.stateflow_execution1_tac)\\<close> \n\"Stateflow_Execution1 prover\"\n\n\nML \\<open>\nsignature STATEFLOW_EXECUTION2 = \nsig\n  val stateflow_execution2_tac: Proof.context -> tactic\nend\n\nstructure Stateflow_Execution2 : STATEFLOW_EXECUTION2 = \nstruct\n\nfun stateflow_execution2_tac ctxt state = \n  let\n    val subgoals = state |> Thm.cprop_of |> Drule.strip_imp_prems\n    (*val _ = pwriteln (pretty_term ctxt (Thm.term_of (hd subgoals)))*)\n  in\n    if null subgoals then Seq.empty else\n    let\n      val c_subgoal = hd subgoals\n      val subgoal = Thm.term_of c_subgoal\n      val args = subgoal |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n      val env = nth args 0 |> Thm.cterm_of ctxt\n      val e = nth args 1 |> Thm.cterm_of ctxt\n      val n = nth args 2 |> Thm.cterm_of ctxt\n      val s1 = nth args 3 |> Thm.cterm_of ctxt\n      val th = evaluate_root_exec_for_times ctxt env e n s1\n      val args_res = th |> Thm.prop_of |> Term.dest_comb |> snd |> Term.strip_comb |> snd\n      val _ = pwriteln (pretty_term ctxt (nth args_res 4))\n(*      val _ = pwriteln (pretty_term ctxt (Thm.prop_of th)) *)\n    in\n      Seq.single (th RS state)\n    end\n  end\nend\n\n\\<close>\n\nmethod_setup stateflow_execution2 \n= \\<open>Scan.succeed (SIMPLE_METHOD o Stateflow_Execution2.stateflow_execution2_tac)\\<close> \n\"Stateflow_Execution2 prover\"\n\n\nend ", "meta": {"author": "bzhan", "repo": "mars", "sha": "d10e489a8ddf128a4cbac13291efdece458d732d", "save_path": "github-repos/isabelle/bzhan-mars", "path": "github-repos/isabelle/bzhan-mars/mars-d10e489a8ddf128a4cbac13291efdece458d732d/Semantic_Stateflow/Final_ML.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6113819591324418, "lm_q2_score": 0.4301473485858429, "lm_q1q2_score": 0.262984328694038}}
{"text": "(* \n   Title: Psi-calculi   \n   Based on the AFP entry by Jesper Bengtson (jebe@itu.dk), 2012\n*)\ntheory Weak_Cong_Pres\n  imports Weak_Psi_Congruence Weak_Cong_Sim_Pres Weak_Bisim_Pres\nbegin\n\ncontext env begin\n\nlemma weakPsiCongInputPres:\n  fixes \\<Psi>    :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   xvec :: \"name list\"\n  and   N    :: 'a\n\n  assumes \"\\<And>Tvec. length xvec = length Tvec \\<Longrightarrow>  \\<Psi> \\<rhd> P[xvec::=Tvec] \\<approx> Q[xvec::=Tvec]\"\n\n  shows \"\\<Psi> \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.P \\<doteq> M\\<lparr>\\<lambda>*xvec N\\<rparr>.Q\"\nproof -\n  from assms have \"\\<forall>Tvec. length xvec = length Tvec \\<longrightarrow>  \\<Psi> \\<rhd> P[xvec::=Tvec] \\<approx> Q[xvec::=Tvec]\"\n    by simp\n  thus ?thesis\n  proof(induct rule: weakPsiCongSymI)\n    case(cSym P Q)\n    thus ?case by(auto dest: weakBisimE)\n  next\n    case(cSim P Q)\n    show ?case \n      by(induct rule: weakCongSimI) auto\n  next\n    case(cWeakBisim P Q)\n    thus ?case by(rule_tac weakBisimInputPres) auto\n  qed\nqed\n  \nlemma weakPsiCongOutputPres:\n  fixes \\<Psi>    :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   xvec :: \"name list\"\n  and   N    :: 'a\n\n  assumes \"\\<Psi> \\<rhd> P \\<doteq> Q\"\n\n  shows \"\\<Psi> \\<rhd> M\\<langle>N\\<rangle>.P \\<doteq> M\\<langle>N\\<rangle>.Q\"\nusing assms\nproof(induct rule: weakPsiCongSymI)\n  case(cSym P Q)\n  thus ?case by(rule weakPsiCongSym)\nnext\n  case(cSim P Q)\n  show ?case by(induct rule: weakCongSimI) auto\nnext\n  case(cWeakBisim P Q)\n  thus ?case by(metis weakPsiCongE weakBisimOutputPres)\nqed\n\nlemma weakBisimCasePres:\n  fixes \\<Psi>   :: 'b\n  and   CsP :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n  and   CsQ :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n\n  assumes A: \"\\<And>\\<phi> P. (\\<phi>, P) mem CsP \\<Longrightarrow> \\<exists>Q. (\\<phi>, Q) mem CsQ \\<and> guarded Q \\<and> (\\<forall>\\<Psi>. \\<Psi> \\<rhd> P \\<doteq> Q)\"\n  and     B: \"\\<And>\\<phi> Q. (\\<phi>, Q) mem CsQ \\<Longrightarrow> \\<exists>P. (\\<phi>, P) mem CsP \\<and> guarded P \\<and> (\\<forall>\\<Psi>. \\<Psi> \\<rhd> P \\<doteq> Q)\"\n\n  shows \"\\<Psi> \\<rhd> Cases CsP \\<approx> Cases CsQ\"\nproof -\n  let ?X = \"{(\\<Psi>, Cases CsP, Cases CsQ) | \\<Psi> CsP CsQ. (\\<forall>\\<phi> P. (\\<phi>, P) mem CsP \\<longrightarrow> (\\<exists>Q. (\\<phi>, Q) mem CsQ \\<and> guarded Q \\<and> (\\<forall>\\<Psi>. \\<Psi> \\<rhd> P \\<doteq> Q))) \\<and>\n                                                     (\\<forall>\\<phi> Q. (\\<phi>, Q) mem CsQ \\<longrightarrow> (\\<exists>P. (\\<phi>, P) mem CsP \\<and> guarded P \\<and> (\\<forall>\\<Psi>. \\<Psi> \\<rhd> P \\<doteq> Q)))}\"\n  from assms have \"(\\<Psi>, Cases CsP, Cases CsQ) \\<in> ?X\" by auto\n  thus ?thesis\n  proof(coinduct rule: weakBisimCoinduct)\n    case(cStatImp \\<Psi> CasesP CasesQ)\n    thus ?case\n      apply(auto simp add: weak_stat_imp_def)\n      by(rule_tac x=\"Cases CsQ\" in exI, auto)\n  next\n    case(cSim \\<Psi> CasesP CasesQ)\n    then obtain CsP CsQ where C1: \"\\<And>\\<phi> Q. (\\<phi>, Q) mem CsQ \\<Longrightarrow> \\<exists>P. (\\<phi>, P) mem CsP \\<and> guarded P \\<and> (\\<forall>\\<Psi>. \\<Psi> \\<rhd> P \\<doteq> Q)\"\n                          and A: \"CasesP = Cases CsP\" and B: \"CasesQ = Cases CsQ\"\n      by auto\n    note C1\n    moreover have \"\\<And>\\<Psi> P Q. \\<Psi> \\<rhd> P \\<approx> Q \\<Longrightarrow> \\<Psi> \\<rhd> P \\<leadsto><weakBisim> Q\" by(rule weakBisimE)\n    moreover note weakPsiCongE(1) weakPsiCongE(2)\n    ultimately have \"\\<Psi> \\<rhd> Cases CsP \\<leadsto><weakBisim> Cases CsQ\"\n      by(rule_tac caseWeakSimPres) (assumption | blast)+\n    hence \"\\<Psi> \\<rhd> Cases CsP \\<leadsto><(?X \\<union> weakBisim)> Cases CsQ\"\n      by(rule_tac weakSimMonotonic) auto\n    with A B show ?case by blast\n  next\n    case(cExt \\<Psi> P Q \\<Psi>')\n    thus ?case by auto\n  next\n    case(cSym \\<Psi> P Q)\n    thus ?case by auto (metis weakPsiCongSym)+\n  qed\nqed\n\nlemma weakPsiCongCasePres:\n  fixes \\<Psi>   :: 'b\n  and   CsP :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n  and   CsQ :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n\n  assumes A: \"\\<And>\\<phi> P. (\\<phi>, P) mem CsP \\<Longrightarrow> \\<exists>Q. (\\<phi>, Q) mem CsQ \\<and> guarded Q \\<and> (\\<forall>\\<Psi>. \\<Psi> \\<rhd> P \\<doteq> Q)\"\n  and     B: \"\\<And>\\<phi> Q. (\\<phi>, Q) mem CsQ \\<Longrightarrow> \\<exists>P. (\\<phi>, P) mem CsP \\<and> guarded P \\<and> (\\<forall>\\<Psi>. \\<Psi> \\<rhd> P \\<doteq> Q)\"\n\n  shows \"\\<Psi> \\<rhd> Cases CsP \\<doteq> Cases CsQ\"\nproof -\n  let ?Prop = \"\\<lambda>CsP CsQ. \\<forall>\\<phi> P. (\\<phi>, P) mem CsP \\<longrightarrow> (\\<exists>Q. (\\<phi>, Q) mem CsQ \\<and> guarded Q \\<and> (\\<forall>\\<Psi>. \\<Psi> \\<rhd> P \\<doteq> Q))\"\n  from A B have \"?Prop CsP CsQ \\<and> ?Prop CsQ CsP\" by(metis weakPsiCongSym)\n  thus ?thesis\n  proof(induct rule: weakPsiCongSymI[where C=\"\\<lambda>P. Cases P\"])\n    case(cSym P Q)\n    thus ?case by auto\n  next\n    case(cWeakBisim CsP CsQ)\n    thus ?case\n      by(rule_tac weakBisimCasePres) (metis weakPsiCongSym)+\n  next\n    case(cSim CsP CsQ)\n    thus ?case       \n      apply auto\n      apply(rule_tac weakCongSimCasePres, auto)\n      by(blast dest: weakPsiCongE)\n  qed\nqed\n\nlemma weakPsiCongResPres:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   x :: name\n  \n  assumes \"\\<Psi> \\<rhd> P \\<doteq> Q\"\n  and     \"x \\<sharp> \\<Psi>\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<doteq> \\<lparr>\\<nu>x\\<rparr>Q\"\nusing `\\<Psi> \\<rhd> P \\<doteq> Q`\nproof(induct rule: weakPsiCongSymI)\n  case(cSym P Q)\n  thus ?case by(rule weakPsiCongSym)\nnext\n  case(cWeakBisim P Q)\n  thus ?case using `x \\<sharp> \\<Psi>` by(metis weakPsiCongE weakBisimResPres)\nnext\n  case(cSim P Q)\n  obtain y::name where \"y \\<sharp> \\<Psi>\" and \"y \\<sharp> P\" and \"y \\<sharp> Q\"\n    by(generate_fresh \"name\") auto\n  from `\\<Psi> \\<rhd> P \\<doteq> Q` have \"([(x, y)] \\<bullet> \\<Psi>) \\<rhd> ([(x, y)] \\<bullet> P) \\<doteq> ([(x, y)] \\<bullet> Q)\" by(rule weakPsiCongClosed)\n  hence \"([(x, y)] \\<bullet> \\<Psi>) \\<rhd> ([(x, y)] \\<bullet> P) \\<leadsto>\\<guillemotleft>weakBisim\\<guillemotright> ([(x, y)] \\<bullet> Q)\" by(rule weakPsiCongE)\n  with `x \\<sharp> \\<Psi>` `y \\<sharp> \\<Psi>` have \"\\<Psi>  \\<rhd> ([(x, y)] \\<bullet> P) \\<leadsto>\\<guillemotleft>weakBisim\\<guillemotright> ([(x, y)] \\<bullet> Q)\" by simp\n  moreover have \"eqvt weakBisim\" by simp\n  moreover note `y \\<sharp> \\<Psi>`\n  moreover have \"weakBisim \\<subseteq> weakBisim\" by auto\n  moreover note weakBisimResPres\n  ultimately have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> P) \\<leadsto>\\<guillemotleft>weakBisim\\<guillemotright> \\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> Q)\" by(rule weakCongSimResPres)\n  with `y \\<sharp> P` `y \\<sharp> Q` show ?case by(simp add: alpha_res)\nqed\n\nlemma weakPsiCongResChainPres:\n  fixes \\<Psi>   :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   xvec :: \"name list\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<doteq> Q\"\n  and     \"xvec \\<sharp>* \\<Psi>\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>P \\<doteq> \\<lparr>\\<nu>*xvec\\<rparr>Q\"\nusing assms\nby(induct xvec) (auto intro: weakPsiCongResPres)\n\nlemma weakPsiCongParPres:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   R :: \"('a, 'b, 'c) psi\"\n  \n  assumes \"\\<forall>\\<Psi>. \\<Psi> \\<rhd> P \\<doteq> Q\"\n\n  shows \"\\<Psi> \\<rhd> P \\<parallel> R \\<doteq> Q \\<parallel> R\"\nusing assms\nproof(induct rule: weakPsiCongSymI[where C=\"\\<lambda>P. P \\<parallel> R\"])\n  case(cSym P Q)\n  thus ?case by(blast dest: weakPsiCongSym)\nnext\n  case(cWeakBisim P Q)\n  thus ?case by(metis weakBisimParPres weakPsiCongE)\nnext\n  case(cSim P Q)\n  {\n    fix \\<Psi>\n    from `\\<forall>\\<Psi>. \\<Psi> \\<rhd> P \\<doteq> Q` have \"\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>weakBisim\\<guillemotright> Q\" by(auto dest: weakPsiCongE)\n  }\n  moreover {\n    fix \\<Psi>\n    from `\\<forall>\\<Psi>. \\<Psi> \\<rhd> P \\<doteq> Q` have \"\\<Psi> \\<rhd> P \\<leadsto><weakBisim> Q\" by(auto dest: weakPsiCongE weakBisimE)\n  }\n  moreover {\n    fix \\<Psi>\n    from `\\<forall>\\<Psi>. \\<Psi> \\<rhd> P \\<doteq> Q` have \"\\<Psi> \\<rhd> P \\<approx> Q\" by(auto dest: weakPsiCongE)\n    hence \"\\<Psi> \\<rhd> Q \\<lessapprox><weakBisim> P\" by(metis weakBisimE)\n  }\n  ultimately show ?case using weakBisimEqvt weakBisimEqvt weakBisimE(4)  weakBisimE(3) weakBisimParPresAux weakBisimResChainPres statEqWeakBisim\n    by(rule_tac weakCongSimParPres)\nqed\n\nend\n\nend\n", "meta": {"author": "IlmariReissumies", "repo": "newpsi", "sha": "201517d55b6ed1632a5bff2a585367278b5bc67b", "save_path": "github-repos/isabelle/IlmariReissumies-newpsi", "path": "github-repos/isabelle/IlmariReissumies-newpsi/newpsi-201517d55b6ed1632a5bff2a585367278b5bc67b/Weak_Cong_Pres.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632979641571, "lm_q2_score": 0.4843800842769843, "lm_q1q2_score": 0.2629521700187601}}
{"text": "(*  Title:      HOL/Imperative_HOL/Array.thy\n    Author:     John Matthews, Galois Connections; Alexander Krauss, Lukas Bulwahn & Florian Haftmann, TU Muenchen\n*)\n\nsection \\<open>Monadic arrays\\<close>\n\ntheory Array\nimports Heap_Monad\nbegin\n\nsubsection \\<open>Primitives\\<close>\n\ndefinition present :: \"heap \\<Rightarrow> 'a::heap array \\<Rightarrow> bool\" where\n  \"present h a \\<longleftrightarrow> addr_of_array a < lim h\"\n\ndefinition get :: \"heap \\<Rightarrow> 'a::heap array \\<Rightarrow> 'a list\" where\n  \"get h a = map from_nat (arrays h (TYPEREP('a)) (addr_of_array a))\"\n\ndefinition set :: \"'a::heap array \\<Rightarrow> 'a list \\<Rightarrow> heap \\<Rightarrow> heap\" where\n  \"set a x = arrays_update (\\<lambda>h. h(TYPEREP('a) := ((h(TYPEREP('a))) (addr_of_array a:=map to_nat x))))\"\n\ndefinition alloc :: \"'a list \\<Rightarrow> heap \\<Rightarrow> 'a::heap array \\<times> heap\" where\n  \"alloc xs h = (let\n     l = lim h;\n     r = Array l;\n     h'' = set r xs (h\\<lparr>lim := l + 1\\<rparr>)\n   in (r, h''))\"\n\ndefinition length :: \"heap \\<Rightarrow> 'a::heap array \\<Rightarrow> nat\" where\n  \"length h a = List.length (get h a)\"\n  \ndefinition update :: \"'a::heap array \\<Rightarrow> nat \\<Rightarrow> 'a \\<Rightarrow> heap \\<Rightarrow> heap\" where\n  \"update a i x h = set a ((get h a)[i:=x]) h\"\n\ndefinition noteq :: \"'a::heap array \\<Rightarrow> 'b::heap array \\<Rightarrow> bool\" (infix \"=!!=\" 70) where\n  \"r =!!= s \\<longleftrightarrow> TYPEREP('a) \\<noteq> TYPEREP('b) \\<or> addr_of_array r \\<noteq> addr_of_array s\"\n\n\nsubsection \\<open>Monad operations\\<close>\n\ndefinition new :: \"nat \\<Rightarrow> 'a::heap \\<Rightarrow> 'a array Heap\" where\n  [code del]: \"new n x = Heap_Monad.heap (alloc (replicate n x))\"\n\ndefinition of_list :: \"'a::heap list \\<Rightarrow> 'a array Heap\" where\n  [code del]: \"of_list xs = Heap_Monad.heap (alloc xs)\"\n\ndefinition make :: \"nat \\<Rightarrow> (nat \\<Rightarrow> 'a::heap) \\<Rightarrow> 'a array Heap\" where\n  [code del]: \"make n f = Heap_Monad.heap (alloc (map f [0 ..< n]))\"\n\ndefinition len :: \"'a::heap array \\<Rightarrow> nat Heap\" where\n  [code del]: \"len a = Heap_Monad.tap (\\<lambda>h. length h a)\"\n\ndefinition nth :: \"'a::heap array \\<Rightarrow> nat \\<Rightarrow> 'a Heap\" where\n  [code del]: \"nth a i = Heap_Monad.guard (\\<lambda>h. i < length h a)\n    (\\<lambda>h. (get h a ! i, h))\"\n\ndefinition upd :: \"nat \\<Rightarrow> 'a \\<Rightarrow> 'a::heap array \\<Rightarrow> 'a::heap array Heap\" where\n  [code del]: \"upd i x a = Heap_Monad.guard (\\<lambda>h. i < length h a)\n    (\\<lambda>h. (a, update a i x h))\"\n\ndefinition map_entry :: \"nat \\<Rightarrow> ('a::heap \\<Rightarrow> 'a) \\<Rightarrow> 'a array \\<Rightarrow> 'a array Heap\" where\n  [code del]: \"map_entry i f a = Heap_Monad.guard (\\<lambda>h. i < length h a)\n    (\\<lambda>h. (a, update a i (f (get h a ! i)) h))\"\n\ndefinition swap :: \"nat \\<Rightarrow> 'a \\<Rightarrow> 'a::heap array \\<Rightarrow> 'a Heap\" where\n  [code del]: \"swap i x a = Heap_Monad.guard (\\<lambda>h. i < length h a)\n    (\\<lambda>h. (get h a ! i, update a i x h))\"\n\ndefinition freeze :: \"'a::heap array \\<Rightarrow> 'a list Heap\" where\n  [code del]: \"freeze a = Heap_Monad.tap (\\<lambda>h. get h a)\"\n\n\nsubsection \\<open>Properties\\<close>\n\ntext \\<open>FIXME: Does there exist a \"canonical\" array axiomatisation in\nthe literature?\\<close>\n\ntext \\<open>Primitives\\<close>\n\nlemma noteq_sym: \"a =!!= b \\<Longrightarrow> b =!!= a\"\n  and unequal [simp]: \"a \\<noteq> a' \\<longleftrightarrow> a =!!= a'\"\n  unfolding noteq_def by auto\n\nlemma noteq_irrefl: \"r =!!= r \\<Longrightarrow> False\"\n  unfolding noteq_def by auto\n\nlemma present_alloc_noteq: \"present h a \\<Longrightarrow> a =!!= fst (alloc xs h)\"\n  by (simp add: present_def noteq_def alloc_def Let_def)\n\nlemma get_set_eq [simp]: \"get (set r x h) r = x\"\n  by (simp add: get_def set_def o_def)\n\nlemma get_set_neq [simp]: \"r =!!= s \\<Longrightarrow> get (set s x h) r = get h r\"\n  by (simp add: noteq_def get_def set_def)\n\nlemma set_same [simp]:\n  \"set r x (set r y h) = set r x h\"\n  by (simp add: set_def)\n\nlemma set_set_swap:\n  \"r =!!= r' \\<Longrightarrow> set r x (set r' x' h) = set r' x' (set r x h)\"\n  by (simp add: Let_def fun_eq_iff noteq_def set_def)\n\nlemma get_update_eq [simp]:\n  \"get (update a i v h) a = (get h a) [i := v]\"\n  by (simp add: update_def)\n\nlemma nth_update_neq [simp]:\n  \"a =!!= b \\<Longrightarrow> get (update b j v h) a ! i = get h a ! i\"\n  by (simp add: update_def noteq_def)\n\nlemma get_update_elem_neqIndex [simp]:\n  \"i \\<noteq> j \\<Longrightarrow> get (update a j v h) a ! i = get h a ! i\"\n  by simp\n\nlemma length_update [simp]: \n  \"length (update b i v h) = length h\"\n  by (simp add: update_def length_def set_def get_def fun_eq_iff)\n\nlemma update_swap_neq:\n  \"a =!!= a' \\<Longrightarrow> \n  update a i v (update a' i' v' h) \n  = update a' i' v' (update a i v h)\"\napply (unfold update_def)\napply simp\napply (subst set_set_swap, assumption)\napply (subst get_set_neq)\napply (erule noteq_sym)\napply simp\ndone\n\nlemma update_swap_neqIndex:\n  \"\\<lbrakk> i \\<noteq> i' \\<rbrakk> \\<Longrightarrow> update a i v (update a i' v' h) = update a i' v' (update a i v h)\"\n  by (auto simp add: update_def set_set_swap list_update_swap)\n\nlemma get_alloc:\n  \"get (snd (alloc xs h)) (fst (alloc ys h)) = xs\"\n  by (simp add: Let_def split_def alloc_def)\n\nlemma length_alloc:\n  \"length (snd (alloc (xs :: 'a::heap list) h)) (fst (alloc (ys :: 'a list) h)) = List.length xs\"\n  by (simp add: Array.length_def get_alloc)\n\nlemma set:\n  \"set (fst (alloc ls h))\n     new_ls (snd (alloc ls h))\n       = snd (alloc new_ls h)\"\n  by (simp add: Let_def split_def alloc_def)\n\nlemma present_update [simp]: \n  \"present (update b i v h) = present h\"\n  by (simp add: update_def present_def set_def get_def fun_eq_iff)\n\nlemma present_alloc [simp]:\n  \"present (snd (alloc xs h)) (fst (alloc xs h))\"\n  by (simp add: present_def alloc_def set_def Let_def)\n\nlemma not_present_alloc [simp]:\n  \"\\<not> present h (fst (alloc xs h))\"\n  by (simp add: present_def alloc_def Let_def)\n\n\ntext \\<open>Monad operations\\<close>\n\nlemma execute_new [execute_simps]:\n  \"execute (new n x) h = Some (alloc (replicate n x) h)\"\n  by (simp add: new_def execute_simps)\n\nlemma success_newI [success_intros]:\n  \"success (new n x) h\"\n  by (auto intro: success_intros simp add: new_def)\n\nlemma effect_newI [effect_intros]:\n  assumes \"(a, h') = alloc (replicate n x) h\"\n  shows \"effect (new n x) h h' a\"\n  by (rule effectI) (simp add: assms execute_simps)\n\nlemma effect_newE [effect_elims]:\n  assumes \"effect (new n x) h h' r\"\n  obtains \"r = fst (alloc (replicate n x) h)\" \"h' = snd (alloc (replicate n x) h)\" \n    \"get h' r = replicate n x\" \"present h' r\" \"\\<not> present h r\"\n  using assms by (rule effectE) (simp add: get_alloc execute_simps)\n\nlemma execute_of_list [execute_simps]:\n  \"execute (of_list xs) h = Some (alloc xs h)\"\n  by (simp add: of_list_def execute_simps)\n\nlemma success_of_listI [success_intros]:\n  \"success (of_list xs) h\"\n  by (auto intro: success_intros simp add: of_list_def)\n\nlemma effect_of_listI [effect_intros]:\n  assumes \"(a, h') = alloc xs h\"\n  shows \"effect (of_list xs) h h' a\"\n  by (rule effectI) (simp add: assms execute_simps)\n\nlemma effect_of_listE [effect_elims]:\n  assumes \"effect (of_list xs) h h' r\"\n  obtains \"r = fst (alloc xs h)\" \"h' = snd (alloc xs h)\" \n    \"get h' r = xs\" \"present h' r\" \"\\<not> present h r\"\n  using assms by (rule effectE) (simp add: get_alloc execute_simps)\n\nlemma execute_make [execute_simps]:\n  \"execute (make n f) h = Some (alloc (map f [0 ..< n]) h)\"\n  by (simp add: make_def execute_simps)\n\nlemma success_makeI [success_intros]:\n  \"success (make n f) h\"\n  by (auto intro: success_intros simp add: make_def)\n\nlemma effect_makeI [effect_intros]:\n  assumes \"(a, h') = alloc (map f [0 ..< n]) h\"\n  shows \"effect (make n f) h h' a\"\n  by (rule effectI) (simp add: assms execute_simps)\n\nlemma effect_makeE [effect_elims]:\n  assumes \"effect (make n f) h h' r\"\n  obtains \"r = fst (alloc (map f [0 ..< n]) h)\" \"h' = snd (alloc (map f [0 ..< n]) h)\" \n    \"get h' r = map f [0 ..< n]\" \"present h' r\" \"\\<not> present h r\"\n  using assms by (rule effectE) (simp add: get_alloc execute_simps)\n\nlemma execute_len [execute_simps]:\n  \"execute (len a) h = Some (length h a, h)\"\n  by (simp add: len_def execute_simps)\n\nlemma success_lenI [success_intros]:\n  \"success (len a) h\"\n  by (auto intro: success_intros simp add: len_def)\n\nlemma effect_lengthI [effect_intros]:\n  assumes \"h' = h\" \"r = length h a\"\n  shows \"effect (len a) h h' r\"\n  by (rule effectI) (simp add: assms execute_simps)\n\nlemma effect_lengthE [effect_elims]:\n  assumes \"effect (len a) h h' r\"\n  obtains \"r = length h' a\" \"h' = h\" \n  using assms by (rule effectE) (simp add: execute_simps)\n\nlemma execute_nth [execute_simps]:\n  \"i < length h a \\<Longrightarrow>\n    execute (nth a i) h = Some (get h a ! i, h)\"\n  \"i \\<ge> length h a \\<Longrightarrow> execute (nth a i) h = None\"\n  by (simp_all add: nth_def execute_simps)\n\nlemma success_nthI [success_intros]:\n  \"i < length h a \\<Longrightarrow> success (nth a i) h\"\n  by (auto intro: success_intros simp add: nth_def)\n\nlemma effect_nthI [effect_intros]:\n  assumes \"i < length h a\" \"h' = h\" \"r = get h a ! i\"\n  shows \"effect (nth a i) h h' r\"\n  by (rule effectI) (insert assms, simp add: execute_simps)\n\nlemma effect_nthE [effect_elims]:\n  assumes \"effect (nth a i) h h' r\"\n  obtains \"i < length h a\" \"r = get h a ! i\" \"h' = h\"\n  using assms by (rule effectE) (cases \"i < length h a\", auto simp: execute_simps elim: successE)\n\nlemma execute_upd [execute_simps]:\n  \"i < length h a \\<Longrightarrow>\n    execute (upd i x a) h = Some (a, update a i x h)\"\n  \"i \\<ge> length h a \\<Longrightarrow> execute (upd i x a) h = None\"\n  by (simp_all add: upd_def execute_simps)\n\nlemma success_updI [success_intros]:\n  \"i < length h a \\<Longrightarrow> success (upd i x a) h\"\n  by (auto intro: success_intros simp add: upd_def)\n\nlemma effect_updI [effect_intros]:\n  assumes \"i < length h a\" \"h' = update a i v h\"\n  shows \"effect (upd i v a) h h' a\"\n  by (rule effectI) (insert assms, simp add: execute_simps)\n\nlemma effect_updE [effect_elims]:\n  assumes \"effect (upd i v a) h h' r\"\n  obtains \"r = a\" \"h' = update a i v h\" \"i < length h a\"\n  using assms by (rule effectE) (cases \"i < length h a\", auto simp: execute_simps elim: successE)\n\nlemma execute_map_entry [execute_simps]:\n  \"i < length h a \\<Longrightarrow>\n   execute (map_entry i f a) h =\n      Some (a, update a i (f (get h a ! i)) h)\"\n  \"i \\<ge> length h a \\<Longrightarrow> execute (map_entry i f a) h = None\"\n  by (simp_all add: map_entry_def execute_simps)\n\nlemma success_map_entryI [success_intros]:\n  \"i < length h a \\<Longrightarrow> success (map_entry i f a) h\"\n  by (auto intro: success_intros simp add: map_entry_def)\n\nlemma effect_map_entryI [effect_intros]:\n  assumes \"i < length h a\" \"h' = update a i (f (get h a ! i)) h\" \"r = a\"\n  shows \"effect (map_entry i f a) h h' r\"\n  by (rule effectI) (insert assms, simp add: execute_simps)\n\nlemma effect_map_entryE [effect_elims]:\n  assumes \"effect (map_entry i f a) h h' r\"\n  obtains \"r = a\" \"h' = update a i (f (get h a ! i)) h\" \"i < length h a\"\n  using assms by (rule effectE) (cases \"i < length h a\", auto simp: execute_simps elim: successE)\n\nlemma execute_swap [execute_simps]:\n  \"i < length h a \\<Longrightarrow>\n   execute (swap i x a) h =\n      Some (get h a ! i, update a i x h)\"\n  \"i \\<ge> length h a \\<Longrightarrow> execute (swap i x a) h = None\"\n  by (simp_all add: swap_def execute_simps)\n\nlemma success_swapI [success_intros]:\n  \"i < length h a \\<Longrightarrow> success (swap i x a) h\"\n  by (auto intro: success_intros simp add: swap_def)\n\nlemma effect_swapI [effect_intros]:\n  assumes \"i < length h a\" \"h' = update a i x h\" \"r = get h a ! i\"\n  shows \"effect (swap i x a) h h' r\"\n  by (rule effectI) (insert assms, simp add: execute_simps)\n\nlemma effect_swapE [effect_elims]:\n  assumes \"effect (swap i x a) h h' r\"\n  obtains \"r = get h a ! i\" \"h' = update a i x h\" \"i < length h a\"\n  using assms by (rule effectE) (cases \"i < length h a\", auto simp: execute_simps elim: successE)\n\nlemma execute_freeze [execute_simps]:\n  \"execute (freeze a) h = Some (get h a, h)\"\n  by (simp add: freeze_def execute_simps)\n\nlemma success_freezeI [success_intros]:\n  \"success (freeze a) h\"\n  by (auto intro: success_intros simp add: freeze_def)\n\nlemma effect_freezeI [effect_intros]:\n  assumes \"h' = h\" \"r = get h a\"\n  shows \"effect (freeze a) h h' r\"\n  by (rule effectI) (insert assms, simp add: execute_simps)\n\nlemma effect_freezeE [effect_elims]:\n  assumes \"effect (freeze a) h h' r\"\n  obtains \"h' = h\" \"r = get h a\"\n  using assms by (rule effectE) (simp add: execute_simps)\n\nlemma upd_return:\n  \"upd i x a \\<then> return a = upd i x a\"\n  by (rule Heap_eqI) (simp add: bind_def guard_def upd_def execute_simps)\n\nlemma array_make:\n  \"new n x = make n (\\<lambda>_. x)\"\n  by (rule Heap_eqI) (simp add: map_replicate_trivial execute_simps)\n\nlemma array_of_list_make [code]:\n  \"of_list xs = make (List.length xs) (\\<lambda>n. xs ! n)\"\n  by (rule Heap_eqI) (simp add: map_nth execute_simps)\n\nhide_const (open) present get set alloc length update noteq new of_list make len nth upd map_entry swap freeze\n\n\nsubsection \\<open>Code generator setup\\<close>\n\nsubsubsection \\<open>Logical intermediate layer\\<close>\n\ndefinition new' where\n  [code del]: \"new' = Array.new o nat_of_integer\"\n\n\n\ndefinition make' where\n  [code del]: \"make' i f = Array.make (nat_of_integer i) (f o of_nat)\"\n\nlemma [code]:\n  \"Array.make n f = make' (of_nat n) (f o nat_of_integer)\"\n  by (simp add: make'_def o_def)\n\ndefinition len' where\n  [code del]: \"len' a = Array.len a \\<bind> (\\<lambda>n. return (of_nat n))\"\n\nlemma [code]:\n  \"Array.len a = len' a \\<bind> (\\<lambda>i. return (nat_of_integer i))\"\n  by (simp add: len'_def)\n\ndefinition nth' where\n  [code del]: \"nth' a = Array.nth a o nat_of_integer\"\n\nlemma [code]:\n  \"Array.nth a n = nth' a (of_nat n)\"\n  by (simp add: nth'_def)\n\ndefinition upd' where\n  [code del]: \"upd' a i x = Array.upd (nat_of_integer i) x a \\<then> return ()\"\n\nlemma [code]:\n  \"Array.upd i x a = upd' a (of_nat i) x \\<then> return a\"\n  by (simp add: upd'_def upd_return)\n\nlemma [code]:\n  \"Array.map_entry i f a = do {\n     x \\<leftarrow> Array.nth a i;\n     Array.upd i (f x) a\n   }\"\n  by (rule Heap_eqI) (simp add: bind_def guard_def map_entry_def execute_simps)\n\nlemma [code]:\n  \"Array.swap i x a = do {\n     y \\<leftarrow> Array.nth a i;\n     Array.upd i x a;\n     return y\n   }\"\n  by (rule Heap_eqI) (simp add: bind_def guard_def swap_def execute_simps)\n\nlemma [code]:\n  \"Array.freeze a = do {\n     n \\<leftarrow> Array.len a;\n     Heap_Monad.fold_map (\\<lambda>i. Array.nth a i) [0..<n]\n   }\"\nproof (rule Heap_eqI)\n  fix h\n  have *: \"List.map\n     (\\<lambda>x. fst (the (if x < Array.length h a\n                    then Some (Array.get h a ! x, h) else None)))\n     [0..<Array.length h a] =\n       List.map (List.nth (Array.get h a)) [0..<Array.length h a]\"\n    by simp\n  have \"execute (Heap_Monad.fold_map (Array.nth a) [0..<Array.length h a]) h =\n    Some (Array.get h a, h)\"\n    apply (subst execute_fold_map_unchanged_heap)\n    apply (simp_all add: nth_def guard_def *)\n    apply (simp add: length_def map_nth)\n    done\n  then have \"execute (do {\n      n \\<leftarrow> Array.len a;\n      Heap_Monad.fold_map (Array.nth a) [0..<n]\n    }) h = Some (Array.get h a, h)\"\n    by (auto intro: execute_bind_eq_SomeI simp add: execute_simps)\n  then show \"execute (Array.freeze a) h = execute (do {\n      n \\<leftarrow> Array.len a;\n      Heap_Monad.fold_map (Array.nth a) [0..<n]\n    }) h\" by (simp add: execute_simps)\nqed\n\nhide_const (open) new' make' len' nth' upd'\n\n\ntext \\<open>SML\\<close>\n\ncode_printing type_constructor array \\<rightharpoonup> (SML) \"_/ array\"\ncode_printing constant Array \\<rightharpoonup> (SML) \"raise/ (Fail/ \\\"bare Array\\\")\"\ncode_printing constant Array.new' \\<rightharpoonup> (SML) \"(fn/ ()/ =>/ Array.array/ (IntInf.toInt _,/ (_)))\"\ncode_printing constant Array.of_list \\<rightharpoonup> (SML) \"(fn/ ()/ =>/ Array.fromList/ _)\"\ncode_printing constant Array.make' \\<rightharpoonup> (SML) \"(fn/ ()/ =>/ Array.tabulate/ (IntInf.toInt _,/ _ o IntInf.fromInt))\"\ncode_printing constant Array.len' \\<rightharpoonup> (SML) \"(fn/ ()/ =>/ IntInf.fromInt (Array.length/ _))\"\ncode_printing constant Array.nth' \\<rightharpoonup> (SML) \"(fn/ ()/ =>/ Array.sub/ ((_),/ IntInf.toInt _))\"\ncode_printing constant Array.upd' \\<rightharpoonup> (SML) \"(fn/ ()/ =>/ Array.update/ ((_),/ IntInf.toInt _,/ (_)))\"\ncode_printing constant \"HOL.equal :: 'a array \\<Rightarrow> 'a array \\<Rightarrow> bool\" \\<rightharpoonup> (SML) infixl 6 \"=\"\n\ncode_reserved SML Array\n\n\ntext \\<open>OCaml\\<close>\n\ncode_printing type_constructor array \\<rightharpoonup> (OCaml) \"_/ array\"\ncode_printing constant Array \\<rightharpoonup> (OCaml) \"failwith/ \\\"bare Array\\\"\"\ncode_printing constant Array.new' \\<rightharpoonup> (OCaml) \"(fun/ ()/ ->/ Array.make/ (Z.to'_int/ _)/ _)\"\ncode_printing constant Array.of_list \\<rightharpoonup> (OCaml) \"(fun/ ()/ ->/ Array.of'_list/ _)\"\ncode_printing constant Array.make' \\<rightharpoonup> (OCaml)\n  \"(fun/ ()/ ->/ Array.init/ (Z.to'_int/ _)/ (fun k'_ ->/ _/ (Z.of'_int/ k'_)))\"\ncode_printing constant Array.len' \\<rightharpoonup> (OCaml) \"(fun/ ()/ ->/ Z.of'_int/ (Array.length/ _))\"\ncode_printing constant Array.nth' \\<rightharpoonup> (OCaml) \"(fun/ ()/ ->/ Array.get/ _/ (Z.to'_int/ _))\"\ncode_printing constant Array.upd' \\<rightharpoonup> (OCaml) \"(fun/ ()/ ->/ Array.set/ _/ (Z.to'_int/ _)/ _)\"\ncode_printing constant \"HOL.equal :: 'a array \\<Rightarrow> 'a array \\<Rightarrow> bool\" \\<rightharpoonup> (OCaml) infixl 4 \"=\"\n\ncode_reserved OCaml Array\n\n\ntext \\<open>Haskell\\<close>\n\ncode_printing type_constructor array \\<rightharpoonup> (Haskell) \"Heap.STArray/ Heap.RealWorld/ _\"\ncode_printing constant Array \\<rightharpoonup> (Haskell) \"error/ \\\"bare Array\\\"\"\ncode_printing constant Array.new' \\<rightharpoonup> (Haskell) \"Heap.newArray\"\ncode_printing constant Array.of_list \\<rightharpoonup> (Haskell) \"Heap.newListArray\"\ncode_printing constant Array.make' \\<rightharpoonup> (Haskell) \"Heap.newFunArray\"\ncode_printing constant Array.len' \\<rightharpoonup> (Haskell) \"Heap.lengthArray\"\ncode_printing constant Array.nth' \\<rightharpoonup> (Haskell) \"Heap.readArray\"\ncode_printing constant Array.upd' \\<rightharpoonup> (Haskell) \"Heap.writeArray\"\ncode_printing constant \"HOL.equal :: 'a array \\<Rightarrow> 'a array \\<Rightarrow> bool\" \\<rightharpoonup> (Haskell) infix 4 \"==\"\ncode_printing class_instance array :: HOL.equal \\<rightharpoonup> (Haskell) -\n\n\ntext \\<open>Scala\\<close>\n\ncode_printing type_constructor array \\<rightharpoonup> (Scala) \"!Array.T[_]\"\ncode_printing constant Array \\<rightharpoonup> (Scala) \"!sys.error(\\\"bare Array\\\")\"\ncode_printing constant Array.new' \\<rightharpoonup> (Scala) \"('_: Unit)/ => / Array.alloc((_))((_))\"\ncode_printing constant Array.make' \\<rightharpoonup> (Scala) \"('_: Unit)/ =>/ Array.make((_))((_))\"\ncode_printing constant Array.len' \\<rightharpoonup> (Scala) \"('_: Unit)/ =>/ Array.len((_))\"\ncode_printing constant Array.nth' \\<rightharpoonup> (Scala) \"('_: Unit)/ =>/ Array.nth((_), (_))\"\ncode_printing constant Array.upd' \\<rightharpoonup> (Scala) \"('_: Unit)/ =>/ Array.upd((_), (_), (_))\"\ncode_printing constant Array.freeze \\<rightharpoonup> (Scala) \"('_: Unit)/ =>/ Array.freeze((_))\"\ncode_printing constant \"HOL.equal :: 'a array \\<Rightarrow> 'a array \\<Rightarrow> bool\" \\<rightharpoonup> (Scala) infixl 5 \"==\"\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/Imperative_HOL/Array.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632831725053, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.26295216285397854}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\n(* License: BSD, terms see file ./LICENSE *)\n\ntheory ArrayAssertion\n\nimports\n  \"$L4V_ARCH/ArchArraysMemInstance\"\n  \"StructSupport\"\n\nbegin\n\nlemma array_tag_n_eq:\n  \"(array_tag_n n :: ('a :: c_type['b :: finite]) field_desc typ_desc) =\n  TypDesc (TypAggregate\n    (map (\\<lambda>n. DTPair (adjust_ti (typ_info_t TYPE('a)) (\\<lambda>x. index x n)\n            (\\<lambda>x f. Arrays.update f n x)) (replicate n CHR ''1'')) [0..<n]))\n  (typ_name (typ_uinfo_t TYPE('a)) @ ''_array_'' @ nat_to_bin_string (card (UNIV :: 'b :: finite set)))\"\n  apply (induct n)\n   apply (simp add: typ_info_array array_tag_def eval_nat_numeral array_tag_n.simps empty_typ_info_def)\n   apply (simp add: typ_info_array array_tag_def eval_nat_numeral array_tag_n.simps empty_typ_info_def)\n   apply (simp add: ti_typ_combine_def Let_def)\n   done\n\nlemma typ_info_array':\n  \"typ_info_t TYPE ('a :: c_type['b :: finite]) =\n  TypDesc (TypAggregate\n    (map (\\<lambda>n. DTPair (adjust_ti (typ_info_t TYPE('a)) (\\<lambda>x. index x n)\n            (\\<lambda>x f. Arrays.update f n x)) (replicate n CHR ''1'')) [0..<(card (UNIV :: 'b :: finite set))]))\n  (typ_name (typ_uinfo_t TYPE('a)) @ ''_array_'' @ nat_to_bin_string (card (UNIV :: 'b :: finite set)))\"\n  by (simp add: typ_info_array array_tag_def array_tag_n_eq)\n\ndefinition\n  \"uinfo_array_tag_n_m (v :: 'a itself) n m = TypDesc\n    (TypAggregate (map (\\<lambda>i. DTPair (typ_uinfo_t TYPE('a)) (replicate i CHR ''1'')) [0 ..< n]))\n    (typ_name (typ_uinfo_t TYPE('a :: c_type)) @ ''_array_'' @ nat_to_bin_string m)\"\n\nlemma map_td_list_map:\n  \"map_td_list f = map (map_td_pair f)\"\n  apply (rule ext)\n  apply (induct_tac x, simp_all)\n  done\n\nlemma uinfo_array_tag_n_m_eq:\n  \"n \\<le> CARD('b)\n    \\<Longrightarrow> export_uinfo (array_tag_n n :: (('a :: wf_type)['b :: finite]) field_desc typ_desc)\n        = uinfo_array_tag_n_m TYPE ('a) n (CARD('b))\"\n  apply (clarsimp simp: uinfo_array_tag_n_m_def array_tag_n_eq\n                        map_td_list_map o_def adjust_ti_def map_td_map)\n  apply (simp add: typ_uinfo_t_def export_uinfo_def)\n  apply (rule map_td_extI)\n   apply simp\n  apply (clarsimp simp: field_norm_blah)\n  done\n\nlemma typ_uinfo_array_tag_n_m_eq:\n  \"typ_uinfo_t TYPE (('a :: wf_type)['b :: finite])\n        = uinfo_array_tag_n_m TYPE ('a) (CARD('b)) (CARD('b))\"\n  by (simp add: typ_uinfo_t_def typ_info_array array_tag_def\n                uinfo_array_tag_n_m_eq)\n\ntext {* Alternative to h_t_valid for arrays. This allows reasoning\nabout arrays of variable width. *}\ndefinition\n  h_t_array_valid :: \"heap_typ_desc \\<Rightarrow> ('a :: c_type) ptr \\<Rightarrow> nat \\<Rightarrow> bool\"\nwhere\n  \"h_t_array_valid htd ptr n = valid_footprint htd (ptr_val ptr) (uinfo_array_tag_n_m TYPE ('a) n n)\"\n\ntext {* Assertion that pointer p is within an array that continues\nfor at least n more elements. *}\ndefinition\n  \"array_assertion (p :: ('a :: c_type) ptr) n htd\n    = (\\<exists>q i j. h_t_array_valid htd q j\n        \\<and> p = CTypesDefs.ptr_add q (int i) \\<and> i < j \\<and> i + n \\<le> j)\"\n\nlemma array_assertion_shrink_right:\n  \"array_assertion p n htd \\<Longrightarrow> n' \\<le> n \\<Longrightarrow> array_assertion p n' htd\"\n  by (fastforce simp: array_assertion_def)\n\nlemma array_assertion_shrink_leftD:\n  \"array_assertion p n htd \\<Longrightarrow> j < n \\<Longrightarrow> array_assertion (CTypesDefs.ptr_add p (int j)) (n - j) htd\"\n  apply (clarsimp simp: array_assertion_def)\n  apply (rule exI, rule_tac x=\"i + j\" in exI, rule exI, erule conjI)\n  apply (simp add: CTypesDefs.ptr_add_def field_simps)\n  done\n\nlemma array_assertion_shrink_leftI:\n  \"array_assertion (CTypesDefs.ptr_add p (- (int j))) (n + j) htd\n    \\<Longrightarrow> n \\<noteq> 0 \\<Longrightarrow> array_assertion p n htd\"\n  apply (drule_tac j=j in array_assertion_shrink_leftD, simp)\n  apply (simp add: CTypesDefs.ptr_add_def)\n  done\n\nlemma h_t_array_valid:\n  \"h_t_valid htd gd (p :: (('a :: wf_type)['b :: finite]) ptr)\n    \\<Longrightarrow> h_t_array_valid htd (ptr_coerce p :: 'a ptr) (CARD('b))\"\n  by (clarsimp simp: h_t_valid_def h_t_array_valid_def\n                     typ_uinfo_array_tag_n_m_eq)\n\nlemma array_ptr_valid_array_assertionD:\n  \"h_t_valid htd gd (p :: (('a :: wf_type)['b :: finite]) ptr)\n    \\<Longrightarrow> array_assertion (ptr_coerce p :: 'a ptr) (CARD('b)) htd\"\n  apply (clarsimp simp: array_assertion_def dest!: h_t_array_valid)\n  apply (fastforce intro: exI[where x=0])\n  done\n\nlemma array_ptr_valid_array_assertionI:\n  \"h_t_valid htd gd (q :: (('a :: wf_type)['b :: finite]) ptr)\n    \\<Longrightarrow> q = ptr_coerce p\n    \\<Longrightarrow> n \\<le> CARD('b)\n    \\<Longrightarrow> array_assertion (p :: 'a ptr) n htd\"\n  by (auto dest: array_ptr_valid_array_assertionD\n           simp: array_assertion_shrink_right)\n\ntext {* Derived from array_assertion, an appropriate assertion for performing\na pointer addition, or for dereferencing a pointer addition (the strong case).\n\nIn either case, there must be an array connecting the two ends of the pointer\ntransition, with the caveat that the last address can be just out of the array\nif the pointer is not dereferenced, thus the strong/weak distinction.\n\nIf the pointer doesn't actually move, nothing is learned.\n*}\ndefinition\n  ptr_add_assertion :: \"('a :: c_type) ptr \\<Rightarrow> int \\<Rightarrow> bool \\<Rightarrow> heap_typ_desc \\<Rightarrow> bool\"\nwhere\n  \"ptr_add_assertion ptr offs strong htd \\<equiv> offs = 0\n    \\<or> array_assertion (if offs < 0 then CTypesDefs.ptr_add ptr offs else ptr)\n        (if offs < 0 then nat (- offs) else if strong then Suc (nat offs) else nat offs)\n        htd\"\n\nlemma ptr_add_assertion_positive:\n  \"offs \\<ge> 0 \\<Longrightarrow> ptr_add_assertion ptr offs strong htd\n    = (offs = 0 \\<or> array_assertion ptr (case strong of True \\<Rightarrow> Suc (nat offs)\n        | False \\<Rightarrow> nat offs) htd)\"\n  by (simp add: ptr_add_assertion_def)\n\nlemma ptr_add_assertion_negative:\n  \"offs < 0 \\<Longrightarrow> ptr_add_assertion ptr offs strong htd\n    = array_assertion (CTypesDefs.ptr_add ptr offs) (nat (- offs)) htd\"\n  by (simp add: ptr_add_assertion_def)\n\nlemma ptr_add_assertion_uint[simp]:\n  \"ptr_add_assertion ptr (uint offs) strong htd\n    = (offs = 0 \\<or> array_assertion ptr\n        (case strong of True \\<Rightarrow> Suc (unat offs) | False \\<Rightarrow> unat offs) htd)\"\n  by (simp add: ptr_add_assertion_positive uint_0_iff unat_def\n         split: bool.split)\n\ntext {* Ignore char and void pointers. The C standard specifies that arithmetic on\nchar and void pointers doesn't create any special checks. *}\n\ndefinition\n  ptr_add_assertion' :: \"('a :: c_type) ptr \\<Rightarrow> int \\<Rightarrow> bool \\<Rightarrow> heap_typ_desc \\<Rightarrow> bool\"\nwhere\n  \"ptr_add_assertion' ptr offs strong htd = (typ_uinfo_t TYPE('a) = typ_uinfo_t TYPE(word8)\n    \\<or> typ_uinfo_t TYPE ('a) = typ_uinfo_t TYPE(unit)\n    \\<or> ptr_add_assertion ptr offs strong htd)\"\n\n(* Useful for clearing away these assumptions. *)\nlemma td_diff_from_typ_name:\n  \"typ_name td \\<noteq> typ_name td' \\<Longrightarrow> td \\<noteq> td'\"\n  by clarsimp\n\nlemma typ_name_void:\n  \"typ_name (typ_uinfo_t TYPE(unit)) = ''unit''\"\n by (simp add: typ_uinfo_t_def)\n\nlemmas ptr_add_assertion' = ptr_add_assertion'_def td_diff_from_typ_name typ_name_void\n\ntext {* Mechanism for retyping a range of memory to a non-constant array size. *}\n\ndefinition\n  ptr_arr_retyps :: \"nat \\<Rightarrow> ('a :: c_type) ptr \\<Rightarrow> heap_typ_desc \\<Rightarrow> heap_typ_desc\"\nwhere\n  \"ptr_arr_retyps n p \\<equiv>\n    htd_update_list (ptr_val p)\n        (map (\\<lambda>i. list_map (typ_slice_t (uinfo_array_tag_n_m TYPE('a) n n) i))\n            [0..<n * size_of TYPE('a)])\"\n\nlemma ptr_arr_retyps_to_retyp:\n  \"n = CARD('b :: finite)\n    \\<Longrightarrow> ptr_arr_retyps n (p :: ('c :: wf_type) ptr) = ptr_retyp (ptr_coerce p :: ('c['b]) ptr)\"\n  apply (rule ext)\n  apply (simp add: ptr_arr_retyps_def ptr_retyp_def typ_slices_def\n                   typ_uinfo_array_tag_n_m_eq)\n  done\n\nend\n", "meta": {"author": "z5146542", "repo": "TOR", "sha": "9a82d491288a6d013e0764f68e602a63e48f92cf", "save_path": "github-repos/isabelle/z5146542-TOR", "path": "github-repos/isabelle/z5146542-TOR/TOR-9a82d491288a6d013e0764f68e602a63e48f92cf/checker-verification/autocorres-1.4/c-parser/umm_heap/ArrayAssertion.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5851011542032312, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.26294014911576163}}
{"text": "(*******************************************************************************\n\n  Project: Development of Security Protocols by Refinement\n\n  Module:  Key_establish/m3_kerberos4.thy (Isabelle/HOL 2016-1)\n  ID:      $Id: m3_kerberos4.thy 132890 2016-12-24 10:25:57Z csprenge $\n  Authors  Ivano Somaini, ETH Zurich <somainii@student.ethz.ch>\n           Christoph Sprenger, ETH Zurich <sprenger@inf.ethz.ch>\n\n  Key distribution protocols\n  Third refinement: core Kerberos IV\n\n  Copyright (c) 2009-2016 Ivano Somaini, Christoph Sprenger\n  Licence: LGPL\n\n*******************************************************************************)\n\nsection \\<open>Core Kerberos 4 (L3)\\<close>\n\ntheory m3_kerberos4 imports m2_kerberos \"../Refinement/Message\"\nbegin\n\ntext \\<open>\nWe model the core Kerberos 4 protocol:\n\\[\n\\begin{array}{lll}\n  \\mathrm{M1.} & A \\rightarrow S: & A, B \\\\ \n  \\mathrm{M2.} & S \\rightarrow A: & \\{Kab, B, Ts, Na, \\{Kab, A, Ts\\}_{Kbs} \\}_{Kas} \\\\\n  \\mathrm{M3.} & A \\rightarrow B: & \\{A, Ta\\}_{Kab}, \\{Kab, A, Ts\\}_{Kbs} \\\\\n  \\mathrm{M4.} & B \\rightarrow A: & \\{Ta\\}_{Kab} \\\\\n\\end{array}\n\\]\n\\<close>\n\ntext \\<open>Proof tool configuration. Avoid annoying automatic unfolding of\n\\<open>dom\\<close>.\\<close>\n\ndeclare domIff [simp, iff del]\n\n\n(******************************************************************************)\nsubsection \\<open>Setup\\<close>\n(******************************************************************************)\n\ntext \\<open>Now we can define the initial key knowledge.\\<close>\n\noverloading ltkeySetup' \\<equiv> ltkeySetup begin\ndefinition ltkeySetup_def: \"ltkeySetup' \\<equiv> {(sharK C, A) | C A. A = C \\<or> A = Sv}\"\nend\n\nlemma corrKey_shrK_bad [simp]: \"corrKey = shrK`bad\"\nby (auto simp add: keySetup_def ltkeySetup_def corrKey_def)\n\n\n(******************************************************************************)\nsubsection \\<open>State\\<close>\n(******************************************************************************)\n\ntext \\<open>The secure channels are star-shaped to/from the server.  Therefore,\nwe have only one agent in the relation.\\<close>\n\nrecord m3_state = \"m1_state\" +\n  IK :: \"msg set\"                                \\<comment> \\<open>intruder knowledge\\<close>\n\n\ntext \\<open>Observable state:\n@{term \"runs\"}, @{term \"clk\"}, and @{term \"cache\"}.\\<close>\n\ntype_synonym\n  m3_obs = \"m2_obs\"\n\ndefinition\n  m3_obs :: \"m3_state \\<Rightarrow> m3_obs\" where\n  \"m3_obs s \\<equiv> \\<lparr> runs = runs s, leak = leak s, clk = clk s, cache = cache s \\<rparr>\"\n\ntype_synonym\n  m3_pred = \"m3_state set\"\n\ntype_synonym\n  m3_trans = \"(m3_state \\<times> m3_state) set\"\n\n\n(******************************************************************************)\nsubsection \\<open>Events\\<close>\n(******************************************************************************)\n\ntext \\<open>Protocol events.\\<close>\n\ndefinition     \\<comment> \\<open>by @{term \"A\"}, refines @{term \"m2_step1\"}\\<close>\n  m3_step1 :: \"[rid_t, agent, agent, nonce] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step1 Ra A B Na \\<equiv> {(s, s1).\n    \\<comment> \\<open>guards:\\<close>\n    Ra \\<notin> dom (runs s) \\<and>                  \\<comment> \\<open>\\<open>Ra\\<close> is fresh\\<close>\n    Na = Ra$na \\<and>                         \\<comment> \\<open>generated nonce\\<close>\n\n    \\<comment> \\<open>actions:\\<close>\n    s1 = s\\<lparr>\n      runs := (runs s)(Ra \\<mapsto> (Init, [A, B], [])),\n      IK := insert \\<lbrace>Agent A, Agent B, Nonce Na\\<rbrace> (IK s)   \\<comment> \\<open>send \\<open>M1\\<close>\\<close>\n    \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by @{term \"B\"}, refines @{term \"m2_step2\"}\\<close>\n  m3_step2 :: \"[rid_t, agent, agent] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step2 \\<equiv> m1_step2\"\n\ndefinition     \\<comment> \\<open>by @{text \"Server\"}, refines @{term m2_step3}\\<close>\n  m3_step3 :: \"[rid_t, agent, agent, key, nonce, time] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step3 Rs A B Kab Na Ts \\<equiv> {(s, s1).\n    \\<comment> \\<open>guards:\\<close>\n    Rs \\<notin> dom (runs s) \\<and>                          \\<comment> \\<open>fresh server run\\<close>\n    Kab = sesK (Rs$sk) \\<and>                          \\<comment> \\<open>fresh session key\\<close>\n\n    \\<lbrace>Agent A, Agent B, Nonce Na\\<rbrace> \\<in> IK s \\<and>    \\<comment> \\<open>recv \\<open>M1\\<close>\\<close>\n    Ts = clk s \\<and>                                 \\<comment> \\<open>fresh timestamp\\<close>\n\n    \\<comment> \\<open>actions:\\<close>\n    \\<comment> \\<open>record session key and send \\<open>M2\\<close>\\<close>\n    s1 = s\\<lparr>\n      runs := (runs s)(Rs \\<mapsto> (Serv, [A, B], [aNon Na, aNum Ts])),\n      IK := insert (Crypt (shrK A)                        \\<comment> \\<open>send \\<open>M2\\<close>\\<close>\n                     \\<lbrace>Key Kab, Agent B, Number Ts, Nonce Na,\n                        Crypt (shrK B) \\<lbrace>Key Kab, Agent A, Number Ts\\<rbrace>\\<rbrace>)\n               (IK s)\n    \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by @{term \"A\"}, refines @{term m2_step4}\\<close>\n  m3_step4 :: \"[rid_t, agent, agent, nonce, key, time, time, msg] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step4 Ra A B Na Kab Ts Ta X \\<equiv> {(s, s1).\n\n     \\<comment> \\<open>guards:\\<close>\n     runs s Ra = Some (Init, [A, B], []) \\<and>           \\<comment> \\<open>key not yet recv'd\\<close>\n     Na = Ra$na \\<and>                                    \\<comment> \\<open>generated nonce\\<close>\n\n     Crypt (shrK A)                                  \\<comment> \\<open>recv \\<open>M2\\<close>\\<close>\n       \\<lbrace>Key Kab, Agent B, Number Ts, Nonce Na, X\\<rbrace> \\<in> IK s \\<and>\n\n     \\<comment> \\<open>read current time\\<close>\n     Ta = clk s \\<and>\n\n     \\<comment> \\<open>check freshness of session key\\<close>\n     clk s < Ts + Ls \\<and>\n\n     \\<comment> \\<open>actions:\\<close>\n     \\<comment> \\<open>record session key and send \\<open>M3\\<close>\\<close>\n     s1 = s\\<lparr>\n       runs := (runs s)(Ra \\<mapsto> (Init, [A, B], [aKey Kab, aNum Ts, aNum Ta])),\n       IK := insert \\<lbrace>Crypt Kab \\<lbrace>Agent A, Number Ta\\<rbrace>, X\\<rbrace> (IK s)  \\<comment> \\<open>\\<open>M3\\<close>\\<close>\n     \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by @{term \"B\"}, refines @{term m2_step5}\\<close>\n  m3_step5 :: \"[rid_t, agent, agent, key, time, time] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step5 Rb A B Kab Ts Ta \\<equiv> {(s, s1).\n     \\<comment> \\<open>guards:\\<close>\n     runs s Rb = Some (Resp, [A, B], []) \\<and>             \\<comment> \\<open>key not yet recv'd\\<close>\n\n     \\<lbrace>Crypt Kab \\<lbrace>Agent A, Number Ta\\<rbrace>,                   \\<comment> \\<open>recv \\<open>M3\\<close>\\<close>\n        Crypt (shrK B) \\<lbrace>Key Kab, Agent A, Number Ts\\<rbrace>\\<rbrace> \\<in> IK s \\<and>\n\n     \\<comment> \\<open>ensure freshness of session key\\<close>\n     clk s < Ts + Ls \\<and>\n\n     \\<comment> \\<open>check authenticator's validity and replay; 'replays' with fresh authenticator ok!\\<close>\n     clk s < Ta + La \\<and>\n     (B, Kab, Ta) \\<notin> cache s \\<and>\n\n     \\<comment> \\<open>actions:\\<close>\n     \\<comment> \\<open>record session key\\<close>\n     s1 = s\\<lparr>\n       runs := (runs s)(Rb \\<mapsto> (Resp, [A, B], [aKey Kab, aNum Ts, aNum Ta])),\n       cache := insert (B, Kab, Ta) (cache s),\n       IK := insert (Crypt Kab (Number Ta)) (IK s)               \\<comment> \\<open>send \\<open>M4\\<close>\\<close>\n     \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by @{term \"A\"}, refines @{term m2_step6}\\<close>\n  m3_step6 :: \"[rid_t, agent, agent, nonce, key, time, time] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step6 Ra A B Na Kab Ts Ta \\<equiv> {(s, s').\n     \\<comment> \\<open>guards:\\<close>\n     runs s Ra = Some (Init, [A, B], [aKey Kab, aNum Ts, aNum Ta]) \\<and>  \\<comment> \\<open>knows key\\<close>\n     Na = Ra$na \\<and>                                    \\<comment> \\<open>generated nonce\\<close>\n     clk s < Ts + Ls \\<and>                               \\<comment> \\<open>check session key's recentness\\<close>\n\n     Crypt Kab (Number Ta) \\<in> IK s \\<and>                               \\<comment> \\<open>recv \\<open>M4\\<close>\\<close>\n\n     \\<comment> \\<open>actions:\\<close>\n     s' = s\\<lparr>\n        runs := (runs s)(Ra \\<mapsto> (Init, [A, B], [aKey Kab, aNum Ts, aNum Ta, END]))\n     \\<rparr>\n  }\"\n\ntext \\<open>Clock tick event\\<close>\n\ndefinition   \\<comment> \\<open>refines @{term \"m2_tick\"}\\<close>\n  m3_tick :: \"time \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_tick \\<equiv> m1_tick\"\n\n\ntext \\<open>Purge event: purge cache of expired timestamps\\<close>\n\ndefinition     \\<comment> \\<open>refines @{term \"m2_purge\"}\\<close>\n  m3_purge :: \"agent \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_purge \\<equiv> m1_purge\"\n\n\ntext \\<open>Session key compromise.\\<close>\n\ndefinition     \\<comment> \\<open>refines @{term m2_leak}\\<close>\n  m3_leak :: \"[rid_t, agent, agent, nonce, time] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_leak Rs A B Na Ts \\<equiv> {(s, s1).\n    \\<comment> \\<open>guards:\\<close>\n    runs s Rs = Some (Serv, [A, B], [aNon Na, aNum Ts]) \\<and>\n    (clk s \\<ge> Ts + Ls) \\<and>             \\<comment> \\<open>only compromise 'old' session keys!\\<close>\n\n    \\<comment> \\<open>actions:\\<close>\n    \\<comment> \\<open>record session key as leaked and add it to intruder knowledge\\<close>\n    s1 = s\\<lparr> leak := insert (sesK (Rs$sk), A, B, Na, Ts) (leak s),\n            IK := insert (Key (sesK (Rs$sk))) (IK s) \\<rparr>\n  }\"\n\n\ntext \\<open>Intruder fake event. The following \"Dolev-Yao\" event generates all\nintruder-derivable messages.\\<close>\n\ndefinition     \\<comment> \\<open>refines @{term \"m2_fake\"}\\<close>\n  m3_DY_fake :: \"m3_trans\"\nwhere\n  \"m3_DY_fake \\<equiv> {(s, s1).\n\n     \\<comment> \\<open>actions:\\<close>\n     s1 = s\\<lparr> IK := synth (analz (IK s)) \\<rparr>       \\<comment> \\<open>take DY closure\\<close>\n  }\"\n\n\n(******************************************************************************)\nsubsection \\<open>Transition system\\<close>\n(******************************************************************************)\n\ndefinition\n  m3_init :: \"m3_pred\"\nwhere\n  \"m3_init \\<equiv> { \\<lparr>\n     runs = Map.empty,\n     leak = shrK`bad \\<times> {undefined},\n     clk = 0,\n     cache = {},\n     IK = Key`shrK`bad\n  \\<rparr> }\"\n\ndefinition\n  m3_trans :: \"m3_trans\" where\n  \"m3_trans \\<equiv> (\\<Union>A B Ra Rb Rs Na Kab Ts Ta T X.\n     m3_step1 Ra A B Na \\<union>\n     m3_step2 Rb A B \\<union>\n     m3_step3 Rs A B Kab Na Ts \\<union>\n     m3_step4 Ra A B Na Kab Ts Ta X \\<union>\n     m3_step5 Rb A B Kab Ts Ta \\<union>\n     m3_step6 Ra A B Na Kab Ts Ta \\<union>\n     m3_tick T \\<union>\n     m3_purge A \\<union>\n     m3_leak Rs A B Na Ts \\<union>\n     m3_DY_fake \\<union>\n     Id\n  )\"\n\ndefinition\n  m3 :: \"(m3_state, m3_obs) spec\" where\n  \"m3 \\<equiv> \\<lparr>\n    init = m3_init,\n    trans = m3_trans,\n    obs = m3_obs\n  \\<rparr>\"\n\nlemmas m3_loc_defs =\n  m3_def m3_init_def m3_trans_def m3_obs_def\n  m3_step1_def m3_step2_def m3_step3_def m3_step4_def m3_step5_def\n  m3_step6_def m3_tick_def m3_purge_def m3_leak_def m3_DY_fake_def\n\nlemmas m3_defs = m3_loc_defs m2_defs\n\n\n(******************************************************************************)\nsubsection \\<open>Invariants\\<close>\n(******************************************************************************)\n\ntext \\<open>Specialized injection that we can apply more aggressively.\\<close>\n\nlemmas analz_Inj_IK = analz.Inj [where H=\"IK s\" for s]\nlemmas parts_Inj_IK = parts.Inj [where H=\"IK s\" for s]\n\ndeclare parts_Inj_IK [dest!]\n\ndeclare analz_into_parts [dest]\n\n\nsubsubsection \\<open>inv4: Secrecy of pre-distributed shared keys\\<close>\n(*inv**************************************************************************)\n\ndefinition\n  m3_inv4_lkeysec :: \"m3_pred\"\nwhere\n  \"m3_inv4_lkeysec \\<equiv> {s. \\<forall>C.\n     (Key (shrK C) \\<in> parts (IK s) \\<longrightarrow> C \\<in> bad) \\<and>\n     (C \\<in> bad \\<longrightarrow> Key (shrK C) \\<in> IK s)\n  }\"\n\nlemmas m3_inv4_lkeysecI = m3_inv4_lkeysec_def [THEN setc_def_to_intro, rule_format]\nlemmas m3_inv4_lkeysecE [elim] = m3_inv4_lkeysec_def [THEN setc_def_to_elim, rule_format]\nlemmas m3_inv4_lkeysecD = m3_inv4_lkeysec_def [THEN setc_def_to_dest, rule_format]\n\n\ntext \\<open>Invariance proof.\\<close>\n\nlemma PO_m3_inv4_lkeysec_init [iff]:\n  \"init m3 \\<subseteq> m3_inv4_lkeysec\"\nby (auto simp add: m3_defs intro!: m3_inv4_lkeysecI)\n\nlemma PO_m3_inv4_lkeysec_trans [iff]:\n  \"{m3_inv4_lkeysec} trans m3 {> m3_inv4_lkeysec}\"\nby (auto simp add: PO_hoare_defs m3_defs intro!: m3_inv4_lkeysecI)\n   (auto dest!: Body)\n\nlemma PO_m3_inv4_lkeysec [iff]: \"reach m3 \\<subseteq> m3_inv4_lkeysec\"\nby (rule inv_rule_incr) (fast+)\n\n\ntext \\<open>Useful simplifier lemmas\\<close>\n\nlemma m3_inv4_lkeysec_for_parts [simp]:\n  \"\\<lbrakk> s \\<in> m3_inv4_lkeysec \\<rbrakk> \\<Longrightarrow> Key (shrK C) \\<in> parts (IK s) \\<longleftrightarrow> C \\<in> bad\"\nby auto\n\nlemma m3_inv4_lkeysec_for_analz [simp]:\n  \"\\<lbrakk> s \\<in> m3_inv4_lkeysec \\<rbrakk> \\<Longrightarrow> Key (shrK C) \\<in> analz (IK s) \\<longleftrightarrow> C \\<in> bad\"\nby auto\n\n\nsubsubsection \\<open>inv6: Ticket shape for honestly encrypted M2\\<close>\n(*inv**************************************************************************)\n\ndefinition\n  m3_inv6_ticket :: \"m3_pred\"\nwhere\n  \"m3_inv6_ticket \\<equiv> {s. \\<forall>A B T K N X.\n     A \\<notin> bad \\<longrightarrow>\n     Crypt (shrK A) \\<lbrace>Key K, Agent B, Number T, Nonce N, X\\<rbrace> \\<in> parts (IK s) \\<longrightarrow>\n       X = Crypt (shrK B) \\<lbrace>Key K, Agent A, Number T\\<rbrace> \\<and> K \\<in> range sesK\n  }\"\n\nlemmas m3_inv6_ticketI = m3_inv6_ticket_def [THEN setc_def_to_intro, rule_format]\nlemmas m3_inv6_ticketE [elim] = m3_inv6_ticket_def [THEN setc_def_to_elim, rule_format]\nlemmas m3_inv6_ticketD = m3_inv6_ticket_def [THEN setc_def_to_dest, rule_format, rotated -1]\n\n\ntext \\<open>Invariance proof.\\<close>\n\nlemma PO_m3_inv6_ticket_init [iff]:\n  \"init m3 \\<subseteq> m3_inv6_ticket\"\nby (auto simp add: m3_defs intro!: m3_inv6_ticketI)\n\nlemma PO_m3_inv6_ticket_trans [iff]:\n  \"{m3_inv6_ticket \\<inter> m3_inv4_lkeysec} trans m3 {> m3_inv6_ticket}\"\napply (auto simp add: PO_hoare_defs m3_defs intro!: m3_inv6_ticketI)\napply (auto dest: m3_inv6_ticketD)\n\\<comment> \\<open>2 subgoals\\<close>\napply (drule parts_cut, drule Body, auto dest: m3_inv6_ticketD)+\ndone\n\nlemma PO_m3_inv6_ticket [iff]: \"reach m3 \\<subseteq> m3_inv6_ticket\"\nby (rule inv_rule_incr) (auto del: subsetI)\n\n\nsubsubsection \\<open>inv7: Session keys not used to encrypt other session keys\\<close>\n(*inv**************************************************************************)\n\ntext \\<open>Session keys are not used to encrypt other keys. Proof requires\ngeneralization to sets of session keys.\n\nNOTE: For Kerberos 4, this invariant cannot be inherited from the corresponding\nL2 invariant. The simulation relation is only an implication not an equivalence.\n\\<close>\n\ndefinition\n  m3_inv7a_sesK_compr :: \"m3_pred\"\nwhere\n  \"m3_inv7a_sesK_compr \\<equiv> {s. \\<forall>K KK.\n     KK \\<subseteq> range sesK \\<longrightarrow>\n     (Key K \\<in> analz (Key`KK \\<union> (IK s))) = (K \\<in> KK \\<or> Key K \\<in> analz (IK s))\n  }\"\n\nlemmas m3_inv7a_sesK_comprI = m3_inv7a_sesK_compr_def [THEN setc_def_to_intro, rule_format]\nlemmas m3_inv7a_sesK_comprE = m3_inv7a_sesK_compr_def [THEN setc_def_to_elim, rule_format]\nlemmas m3_inv7a_sesK_comprD = m3_inv7a_sesK_compr_def [THEN setc_def_to_dest, rule_format]\n\ntext \\<open>Additional lemma\\<close>\nlemmas insert_commute_Key = insert_commute [where x=\"Key K\" for K]\n\nlemmas m3_inv7a_sesK_compr_simps =\n  m3_inv7a_sesK_comprD\n  m3_inv7a_sesK_comprD [where KK=\"insert Kab KK\" for Kab KK, simplified]\n  m3_inv7a_sesK_comprD [where KK=\"{Kab}\" for Kab, simplified]\n  insert_commute_Key\n\n\ntext \\<open>Invariance proof.\\<close>\n\nlemma PO_m3_inv7a_sesK_compr_step4:\n  \"{m3_inv7a_sesK_compr \\<inter> m3_inv6_ticket \\<inter> m3_inv4_lkeysec}\n      m3_step4 Ra A B Na Kab Ts Ta X\n   {> m3_inv7a_sesK_compr}\"\nproof -\n  { fix K KK s\n    assume H:\n      \"s \\<in> m3_inv4_lkeysec\" \"s \\<in> m3_inv7a_sesK_compr\" \"s \\<in> m3_inv6_ticket\"\n      \"runs s Ra = Some (Init, [A, B], [])\"\n      \"Na = Ra$na\"\n      \"KK \\<subseteq> range sesK\"\n      \"Crypt (shrK A) \\<lbrace>Key Kab, Agent B, Number Ts, Nonce Na, X\\<rbrace> \\<in> analz (IK s)\"\n    have\n      \"(Key K \\<in> analz (insert X (Key ` KK \\<union> IK s))) =\n          (K \\<in> KK \\<or> Key K \\<in> analz (insert X (IK s)))\"\n    proof (cases \"A \\<in> bad\")\n      case True\n        with H have \"X \\<in> analz (IK s)\" by (auto dest!: Decrypt)\n      moreover\n        with H have \"X \\<in> analz (Key ` KK \\<union> IK s)\"\n        by (auto intro: analz_monotonic)\n      ultimately show ?thesis using H\n        by (auto simp add: m3_inv7a_sesK_compr_simps analz_insert_eq)\n    next\n      case False thus ?thesis using H\n      by (fastforce simp add: m3_inv7a_sesK_compr_simps\n                    dest!: m3_inv6_ticketD [OF analz_into_parts])\n    qed\n  }\n  thus ?thesis\n  by (auto simp add: PO_hoare_defs m3_defs intro!: m3_inv7a_sesK_comprI dest!: analz_Inj_IK)\nqed\n\ntext \\<open>All together now.\\<close>\n\nlemmas PO_m3_inv7a_sesK_compr_trans_lemmas =\n  PO_m3_inv7a_sesK_compr_step4\n\nlemma PO_m3_inv7a_sesK_compr_init [iff]:\n  \"init m3 \\<subseteq> m3_inv7a_sesK_compr\"\nby (auto simp add: m3_defs intro!: m3_inv7a_sesK_comprI)\n\nlemma PO_m3_inv7a_sesK_compr_trans [iff]:\n  \"{m3_inv7a_sesK_compr \\<inter> m3_inv6_ticket \\<inter> m3_inv4_lkeysec}\n     trans m3\n   {> m3_inv7a_sesK_compr}\"\nby (auto simp add: m3_def m3_trans_def intro!: PO_m3_inv7a_sesK_compr_trans_lemmas)\n   (auto simp add: PO_hoare_defs m3_defs m3_inv7a_sesK_compr_simps intro!: m3_inv7a_sesK_comprI)\n\nlemma PO_m3_inv7a_sesK_compr [iff]: \"reach m3 \\<subseteq> m3_inv7a_sesK_compr\"\nby (rule_tac J=\"m3_inv6_ticket \\<inter> m3_inv4_lkeysec\" in inv_rule_incr) (auto)\n\n\nsubsubsection \\<open>inv7b: Session keys not used to encrypt nonces\\<close>\n(*inv**************************************************************************)\n\ntext \\<open>Session keys are not used to encrypt nonces. The proof requires a\ngeneralization to sets of session keys.\\<close>\n\ndefinition\n  m3_inv7b_sesK_compr_non :: \"m3_pred\"\nwhere\n  \"m3_inv7b_sesK_compr_non \\<equiv> {s. \\<forall>N KK.\n     KK \\<subseteq> range sesK \\<longrightarrow> (Nonce N \\<in> analz (Key`KK \\<union> (IK s))) = (Nonce N \\<in> analz (IK s))\n  }\"\n\nlemmas m3_inv7b_sesK_compr_nonI = m3_inv7b_sesK_compr_non_def [THEN setc_def_to_intro, rule_format]\nlemmas m3_inv7b_sesK_compr_nonE = m3_inv7b_sesK_compr_non_def [THEN setc_def_to_elim, rule_format]\nlemmas m3_inv7b_sesK_compr_nonD = m3_inv7b_sesK_compr_non_def [THEN setc_def_to_dest, rule_format]\n\nlemmas m3_inv7b_sesK_compr_non_simps =\n  m3_inv7b_sesK_compr_nonD\n  m3_inv7b_sesK_compr_nonD [where KK=\"insert Kab KK\" for Kab KK, simplified]\n  m3_inv7b_sesK_compr_nonD [where KK=\"{Kab}\" for Kab, simplified]\n  insert_commute_Key\n\n\ntext \\<open>Invariance proof.\\<close>\n\nlemma PO_m3_inv7b_sesK_compr_non_step3:\n  \"{m3_inv7b_sesK_compr_non} m3_step3 Rs A B Kab Na Ts {> m3_inv7b_sesK_compr_non}\"\nby (auto simp add: PO_hoare_defs m3_defs m3_inv7b_sesK_compr_non_simps\n         intro!: m3_inv7b_sesK_compr_nonI dest!: analz_Inj_IK)\n\nlemma PO_m3_inv7b_sesK_compr_non_step4:\n  \"{m3_inv7b_sesK_compr_non \\<inter> m3_inv6_ticket \\<inter> m3_inv4_lkeysec}\n      m3_step4 Ra A B Na Kab Ts Ta X\n   {> m3_inv7b_sesK_compr_non}\"\nproof -\n  { fix N KK s\n    assume H:\n      \"s \\<in> m3_inv4_lkeysec\"\"s \\<in> m3_inv7b_sesK_compr_non\"\n      \"s \\<in> m3_inv6_ticket\"\n      \"runs s Ra = Some (Init, [A, B], [])\"\n      \"Na = Ra$na\"\n      \"KK \\<subseteq> range sesK\"\n      \"Crypt (shrK A) \\<lbrace>Key Kab, Agent B, Number Ts, Nonce Na, X\\<rbrace> \\<in> analz (IK s)\"\n    have\n      \"(Nonce N \\<in> analz (insert X (Key ` KK \\<union> IK s))) =\n          (Nonce N \\<in> analz (insert X (IK s)))\"\n    proof (cases)\n      assume \"A \\<in> bad\" show ?thesis\n      proof -\n        from \\<open>A \\<in> bad\\<close> have \"X \\<in> analz (IK s)\" using H\n        by (auto dest!: Decrypt)\n      moreover\n        hence \"X \\<in> analz (Key ` KK \\<union> IK s)\"\n        by (auto intro: analz_monotonic)\n      ultimately show ?thesis using H\n        by (auto simp add: m3_inv7b_sesK_compr_non_simps analz_insert_eq)\n      qed\n    next\n      assume \"A \\<notin> bad\" thus ?thesis using H\n      by (fastforce simp add: m3_inv7b_sesK_compr_non_simps\n                    dest!: m3_inv6_ticketD [OF analz_into_parts])\n    qed\n  }\n  thus ?thesis\n  by (auto simp add: PO_hoare_defs m3_defs intro!: m3_inv7b_sesK_compr_nonI\n           dest!: analz_Inj_IK)\nqed\n\n\ntext \\<open>All together now.\\<close>\n\nlemmas PO_m3_inv7b_sesK_compr_non_trans_lemmas =\n  PO_m3_inv7b_sesK_compr_non_step3 PO_m3_inv7b_sesK_compr_non_step4\n\nlemma PO_m3_inv7b_sesK_compr_non_init [iff]:\n  \"init m3 \\<subseteq> m3_inv7b_sesK_compr_non\"\nby (auto simp add: m3_defs intro!: m3_inv7b_sesK_compr_nonI)\n\nlemma PO_m3_inv7b_sesK_compr_non_trans [iff]:\n  \"{m3_inv7b_sesK_compr_non \\<inter> m3_inv6_ticket \\<inter> m3_inv4_lkeysec}\n     trans m3\n   {> m3_inv7b_sesK_compr_non}\"\nby (auto simp add: m3_def m3_trans_def intro!: PO_m3_inv7b_sesK_compr_non_trans_lemmas)\n   (auto simp add: PO_hoare_defs m3_defs m3_inv7b_sesK_compr_non_simps\n                   intro!: m3_inv7b_sesK_compr_nonI)\n\nlemma PO_m3_inv7b_sesK_compr_non [iff]: \"reach m3 \\<subseteq> m3_inv7b_sesK_compr_non\"\nby (rule_tac J=\"m3_inv6_ticket \\<inter> m3_inv4_lkeysec\" in inv_rule_incr)\n   (auto)\n\n\n(******************************************************************************)\nsubsection \\<open>Refinement\\<close>\n(******************************************************************************)\n\nsubsubsection \\<open>Message abstraction and simulation relation\\<close>\n(******************************************************************************)\n\ntext \\<open>Abstraction function on sets of messages.\\<close>\n\ninductive_set\n  abs_msg :: \"msg set \\<Rightarrow> chmsg set\"\n  for H :: \"msg set\"\nwhere\n  am_M1:\n    \"\\<lbrace>Agent A, Agent B, Nonce N\\<rbrace> \\<in> H\n  \\<Longrightarrow> Insec A B (Msg [aNon N]) \\<in> abs_msg H\"\n| am_M2a:\n    \"Crypt (shrK C) \\<lbrace>Key K, Agent B, Number T, Nonce N, X\\<rbrace> \\<in> H\n  \\<Longrightarrow> Secure Sv C (Msg [aKey K, aAgt B, aNum T, aNon N]) \\<in> abs_msg H\"\n| am_M2b:\n    \"Crypt (shrK C) \\<lbrace>Key K,  Agent A, Number T\\<rbrace> \\<in> H\n  \\<Longrightarrow> Secure Sv C (Msg [aKey K, aAgt A, aNum T]) \\<in> abs_msg H\"\n| am_M3:\n    \"Crypt K \\<lbrace>Agent A, Number T\\<rbrace> \\<in> H\n  \\<Longrightarrow> dAuth K (Msg [aAgt A, aNum T]) \\<in> abs_msg H\"\n| am_M4:\n    \"Crypt K (Number T) \\<in> H\n  \\<Longrightarrow> dAuth K (Msg [aNum T]) \\<in> abs_msg H\"\n\n\ntext \\<open>R23: The simulation relation. This is a data refinement of\nthe insecure and secure channels of refinement 2.\\<close>\n\ndefinition\n  R23_msgs :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23_msgs \\<equiv> {(s, t). abs_msg (parts (IK t)) \\<subseteq> chan s }\"\n\ndefinition\n  R23_keys :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23_keys \\<equiv> {(s, t). \\<forall>KK K. KK \\<subseteq> range sesK \\<longrightarrow>\n     Key K \\<in> analz (Key`KK \\<union> (IK t)) \\<longrightarrow> aKey K \\<in> extr (aKey`KK \\<union> ik0) (chan s)\n  }\"\n\ndefinition\n  R23_non :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23_non \\<equiv> {(s, t). \\<forall>KK N. KK \\<subseteq> range sesK \\<longrightarrow>\n     Nonce N \\<in> analz (Key`KK \\<union> (IK t)) \\<longrightarrow> aNon N \\<in> extr (aKey`KK \\<union> ik0) (chan s)\n  }\"\n\ndefinition\n  R23_pres :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23_pres \\<equiv> {(s, t). runs s = runs t \\<and> leak s = leak t \\<and> clk s = clk t \\<and> cache s = cache t}\"\n\ndefinition\n  R23 :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23 \\<equiv> R23_msgs \\<inter> R23_keys \\<inter> R23_non \\<inter> R23_pres\"\n\nlemmas R23_defs =\n  R23_def R23_msgs_def R23_keys_def R23_non_def R23_pres_def\n\n\ntext \\<open>The mediator function is the identity here.\\<close>\n\ndefinition\n  med32 :: \"m3_obs \\<Rightarrow> m2_obs\" where\n  \"med32 \\<equiv> id\"\n\n\nlemmas R23_msgsI = R23_msgs_def [THEN rel_def_to_intro, simplified, rule_format]\nlemmas R23_msgsE [elim] = R23_msgs_def [THEN rel_def_to_elim, simplified, rule_format]\nlemmas R23_msgsE' [elim] =\n  R23_msgs_def [THEN rel_def_to_dest, simplified, rule_format, THEN subsetD]\n\nlemmas R23_keysI = R23_keys_def [THEN rel_def_to_intro, simplified, rule_format]\nlemmas R23_keysE [elim] = R23_keys_def [THEN rel_def_to_elim, simplified, rule_format]\nlemmas R23_keysD = R23_keys_def [THEN rel_def_to_dest, simplified, rule_format, rotated 2]\n\nlemmas R23_nonI = R23_non_def [THEN rel_def_to_intro, simplified, rule_format]\nlemmas R23_nonE [elim] = R23_non_def [THEN rel_def_to_elim, simplified, rule_format]\nlemmas R23_nonD = R23_non_def [THEN rel_def_to_dest, simplified, rule_format, rotated 2]\n\nlemmas R23_presI = R23_pres_def [THEN rel_def_to_intro, simplified, rule_format]\nlemmas R23_presE [elim] = R23_pres_def [THEN rel_def_to_elim, simplified, rule_format]\n\nlemmas R23_intros = R23_msgsI R23_keysI R23_nonI R23_presI\n\n\ntext \\<open>Lemmas for various instantiations (keys and nonces).\\<close>\n\nlemmas R23_keys_dests =\n  R23_keysD\n  R23_keysD [where KK=\"{}\", simplified]\n  R23_keysD [where KK=\"{K}\" for K, simplified]\n  R23_keysD [where KK=\"insert K KK\" for K KK, simplified, OF _ _ conjI]\n\nlemmas R23_non_dests =\n  R23_nonD\n  R23_nonD [where KK=\"{}\", simplified]\n  R23_nonD [where KK=\"{K}\" for K, simplified]\n  R23_nonD [where KK=\"insert K KK\" for K KK, simplified, OF _ _ conjI]\n\nlemmas R23_dests = R23_keys_dests R23_non_dests\n\n\nsubsubsection \\<open>General lemmas\\<close>\n(******************************************************************************)\n\ntext \\<open>General facts about @{term \"abs_msg\"}\\<close>\n\ndeclare abs_msg.intros [intro!]\ndeclare abs_msg.cases [elim!]\n\nlemma abs_msg_empty: \"abs_msg {} = {}\"\nby (auto)\n\nlemma abs_msg_Un [simp]:\n  \"abs_msg (G \\<union> H) = abs_msg G \\<union> abs_msg H\"\nby (auto)\n\nlemma abs_msg_mono [elim]:\n  \"\\<lbrakk> m \\<in> abs_msg G; G \\<subseteq> H \\<rbrakk> \\<Longrightarrow> m \\<in> abs_msg H\"\nby (auto)\n\nlemma abs_msg_insert_mono [intro]:\n  \"\\<lbrakk> m \\<in> abs_msg H \\<rbrakk> \\<Longrightarrow> m \\<in> abs_msg (insert m' H)\"\nby (auto)\n\n\ntext \\<open>Facts about @{term \"abs_msg\"} concerning abstraction of fakeable\nmessages. This is crucial for proving the refinement of the intruder event.\\<close>\n\nlemma abs_msg_DY_subset_fakeable:\n  \"\\<lbrakk> (s, t) \\<in> R23_msgs; (s, t) \\<in> R23_keys; (s, t) \\<in> R23_non; t \\<in> m3_inv4_lkeysec \\<rbrakk>\n  \\<Longrightarrow> abs_msg (synth (analz (IK t))) \\<subseteq> fake ik0 (dom (runs s)) (chan s)\"\napply (auto)\n\\<comment> \\<open>9 subgoals, deal with replays first\\<close>\nprefer 2 apply (blast)\nprefer 3 apply (blast)\nprefer 4 apply (blast)\nprefer 5 apply (blast)\n\\<comment> \\<open>remaining 5 subgoals are real fakes\\<close>\napply (intro fake_StatCh fake_DynCh, auto dest: R23_dests)+\ndone\n\n\nsubsubsection \\<open>Refinement proof\\<close>\n(******************************************************************************)\n\ntext \\<open>Pair decomposition. These were set to \\texttt{elim!}, which is too\nagressive here.\\<close>\n\ndeclare MPair_analz [rule del, elim]\ndeclare MPair_parts [rule del, elim]\n\n\ntext \\<open>Protocol events.\\<close>\n\nlemma PO_m3_step1_refines_m2_step1:\n  \"{R23}\n     (m2_step1 Ra A B Na), (m3_step1 Ra A B Na)\n   {> R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n   (auto)\n\nlemma PO_m3_step2_refines_m2_step2:\n  \"{R23}\n     (m2_step2 Rb A B), (m3_step2 Rb A B)\n   {> R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n\nlemma PO_m3_step3_refines_m2_step3:\n  \"{R23 \\<inter> (m2_inv3a_sesK_compr) \\<times> (m3_inv7a_sesK_compr \\<inter> m3_inv4_lkeysec)}\n     (m2_step3 Rs A B Kab Na Ts), (m3_step3 Rs A B Kab Na Ts)\n   {> R23}\"\nproof -\n  { fix s t\n    assume H:\n      \"(s, t) \\<in> R23_msgs\" \"(s, t) \\<in> R23_keys\" \"(s, t) \\<in> R23_non\"\n      \"(s, t) \\<in> R23_pres\"\n      \"s \\<in> m2_inv3a_sesK_compr\"\n      \"t \\<in> m3_inv7a_sesK_compr\" \"t \\<in> m3_inv4_lkeysec\"\n      \"Kab = sesK (Rs$sk)\" \"Rs \\<notin> dom (runs t)\"\n      \"\\<lbrace>Agent A, Agent B, Nonce Na\\<rbrace> \\<in> parts (IK t)\"\n    let ?s'=\n      \"s\\<lparr> runs := runs s(Rs \\<mapsto> (Serv, [A, B], [aNon Na, aNum (clk t)])),\n          chan := insert (Secure Sv A (Msg [aKey Kab, aAgt B, aNum (clk t), aNon Na]))\n                 (insert (Secure Sv B (Msg [aKey Kab, aAgt A, aNum (clk t)])) (chan s)) \\<rparr>\"\n    let ?t'=\n      \"t\\<lparr> runs := runs t(Rs \\<mapsto> (Serv, [A, B], [aNon Na, aNum (clk t)])),\n          IK := insert\n                  (Crypt (shrK A)\n                     \\<lbrace> Key Kab, Agent B, Number (clk t), Nonce Na,\n                       Crypt (shrK B) \\<lbrace> Key Kab, Agent A, Number (clk t) \\<rbrace>\\<rbrace>)\n                  (IK t) \\<rparr>\"\n  \\<comment> \\<open>here we go\\<close>\n    have \"(?s', ?t') \\<in> R23_msgs\" using H\n    by (-) (rule R23_intros, auto)\n  moreover\n    have \"(?s', ?t') \\<in> R23_keys\" using H\n    by (-) (rule R23_intros,\n            auto simp add: m2_inv3a_sesK_compr_simps m3_inv7a_sesK_compr_simps dest: R23_keys_dests)\n  moreover\n    have \"(?s', ?t') \\<in> R23_non\" using H\n    by (-) (rule R23_intros,\n            auto simp add: m2_inv3a_sesK_compr_simps m3_inv7a_sesK_compr_simps dest: R23_non_dests)\n  moreover\n    have \"(?s', ?t') \\<in> R23_pres\" using H\n    by (-) (rule R23_intros, auto)\n  moreover\n    note calculation\n  }\n  thus ?thesis\n  by (auto simp add: PO_rhoare_defs R23_def m3_defs)\nqed\n\nlemma PO_m3_step4_refines_m2_step4:\n  \"{R23 \\<inter> (UNIV)\n        \\<times> (m3_inv7a_sesK_compr \\<inter> m3_inv7b_sesK_compr_non \\<inter> m3_inv6_ticket \\<inter> m3_inv4_lkeysec)}\n     (m2_step4 Ra A B Na Kab Ts Ta), (m3_step4 Ra A B Na Kab Ts Ta X)\n   {> R23}\"\nproof -\n  { fix s t\n    assume H:\n      \"(s, t) \\<in> R23_msgs\" \"(s, t) \\<in> R23_keys\" \"(s, t) \\<in> R23_non\" \"(s, t) \\<in> R23_pres\"\n      \"t \\<in> m3_inv7a_sesK_compr\" \"t \\<in> m3_inv7b_sesK_compr_non\"\n      \"t \\<in> m3_inv6_ticket\" \"t \\<in> m3_inv4_lkeysec\"\n      \"runs t Ra = Some (Init, [A, B], [])\"\n      \"Na = Ra$na\"\n      \"Crypt (shrK A) \\<lbrace>Key Kab, Agent B, Number Ts, Nonce Na, X\\<rbrace> \\<in> analz (IK t)\"\n    let ?s' = \"s\\<lparr> runs := runs s(Ra \\<mapsto> (Init, [A, B], [aKey Kab, aNum Ts, aNum (clk t)])),\n                 chan := insert (dAuth Kab (Msg [aAgt A, aNum (clk t)])) (chan s) \\<rparr>\"\n    and ?t' = \"t\\<lparr> runs := runs t(Ra \\<mapsto> (Init, [A, B], [aKey Kab, aNum Ts, aNum (clk t)])),\n                 IK := insert \\<lbrace> Crypt Kab \\<lbrace>Agent A, Number (clk t)\\<rbrace>, X \\<rbrace> (IK t) \\<rparr>\"\n    from H have\n      \"Secure Sv A (Msg [aKey Kab, aAgt B, aNum Ts, aNon Na]) \\<in> chan s\"\n    by (auto)\n  moreover\n    have \"X \\<in> parts (IK t)\" using H by (auto dest!: Body MPair_parts)\n    hence \"(?s', ?t') \\<in> R23_msgs\" using H by (auto intro!: R23_intros) (auto)\n  moreover\n    have \"(?s', ?t') \\<in> R23_keys\"\n    proof (cases)\n      assume \"A \\<in> bad\"\n      with H have \"X \\<in> analz (IK t)\" by (-) (drule Decrypt, auto)\n      with H show ?thesis\n        by (-) (rule R23_intros, auto dest!: analz_cut intro: analz_monotonic)\n    next\n      assume \"A \\<notin> bad\" show ?thesis\n      proof -\n        note H\n        moreover\n        with \\<open>A \\<notin> bad\\<close>\n        have \"X = Crypt (shrK B) \\<lbrace>Key Kab, Agent A, Number Ts \\<rbrace> \\<and> Kab \\<in> range sesK\"\n          by (auto dest!: m3_inv6_ticketD)\n        moreover\n        { assume H1: \"Key (shrK B) \\<in> analz (IK t)\"\n          have \"aKey Kab \\<in> extr ik0 (chan s)\"\n          proof -\n            note calculation\n            moreover\n            hence \"Secure Sv B (Msg [aKey Kab, aAgt A, aNum Ts]) \\<in> chan s\"\n              by (-) (drule analz_into_parts, drule Body, elim MPair_parts, auto)\n            ultimately\n            show ?thesis using H1 by auto\n          qed\n        }\n        ultimately show ?thesis\n          by (-) (rule R23_intros, auto simp add: m3_inv7a_sesK_compr_simps)\n      qed\n    qed\n  moreover\n    have \"(?s', ?t') \\<in> R23_non\"\n    proof (cases)\n      assume \"A \\<in> bad\"\n      hence \"X \\<in> analz (IK t)\" using H by (-) (drule Decrypt, auto)\n      thus ?thesis using H\n        by (-) (rule R23_intros, auto dest!: analz_cut intro: analz_monotonic)\n    next\n      assume \"A \\<notin> bad\"\n      hence \"X = Crypt (shrK B) \\<lbrace>Key Kab, Agent A, Number Ts \\<rbrace> \\<and> Kab \\<in> range sesK\" using H\n        by (auto dest!: m3_inv6_ticketD)\n      thus ?thesis using H\n        by (-) (rule R23_intros,\n                auto simp add: m3_inv7a_sesK_compr_simps m3_inv7b_sesK_compr_non_simps)\n    qed\n  moreover\n    have \"(?s', ?t') \\<in> R23_pres\" using H\n    by (auto intro!: R23_intros)\n  moreover\n    note calculation\n  }\n  thus ?thesis\n  by (auto simp add: PO_rhoare_defs R23_def m3_defs dest!: analz_Inj_IK)\nqed\n\nlemma PO_m3_step5_refines_m2_step5:\n  \"{R23}\n     (m2_step5 Rb A B Kab Ts Ta), (m3_step5 Rb A B Kab Ts Ta)\n   {> R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n   (auto)\n\nlemma PO_m3_step6_refines_m2_step6:\n  \"{R23}\n     (m2_step6 Ra A B Na Kab Ts Ta), (m3_step6 Ra A B Na Kab Ts Ta)\n   {> R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n\nlemma PO_m3_tick_refines_m2_tick:\n  \"{R23}\n    (m2_tick T), (m3_tick T)\n   {>R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n\nlemma PO_m3_purge_refines_m2_purge:\n  \"{R23}\n     (m2_purge A), (m3_purge A)\n   {>R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n\n\ntext \\<open>Intruder events.\\<close>\n\nlemma PO_m3_leak_refines_m2_leak:\n  \"{R23}\n     (m2_leak Rs A B Na Ts), (m3_leak Rs A B Na Ts)\n   {>R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n   (auto dest: R23_dests)\n\nlemma PO_m3_DY_fake_refines_m2_fake:\n  \"{R23 \\<inter> UNIV \\<times> (m3_inv4_lkeysec)}\n     m2_fake, m3_DY_fake\n   {> R23}\"\napply (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros\n            del: abs_msg.cases)\napply (auto intro: abs_msg_DY_subset_fakeable [THEN subsetD]\n            del: abs_msg.cases)\napply (auto dest: R23_dests)\ndone\n\n\ntext \\<open>All together now...\\<close>\n\nlemmas PO_m3_trans_refines_m2_trans =\n  PO_m3_step1_refines_m2_step1 PO_m3_step2_refines_m2_step2\n  PO_m3_step3_refines_m2_step3 PO_m3_step4_refines_m2_step4\n  PO_m3_step5_refines_m2_step5 PO_m3_step6_refines_m2_step6\n  PO_m3_tick_refines_m2_tick PO_m3_purge_refines_m2_purge\n  PO_m3_leak_refines_m2_leak PO_m3_DY_fake_refines_m2_fake\n\n\nlemma PO_m3_refines_init_m2 [iff]:\n  \"init m3 \\<subseteq> R23``(init m2)\"\nby (auto simp add: R23_def m3_defs intro!: R23_intros)\n\nlemma PO_m3_refines_trans_m2 [iff]:\n  \"{R23 \\<inter> (m2_inv3a_sesK_compr)\n        \\<times> (m3_inv7a_sesK_compr \\<inter> m3_inv7b_sesK_compr_non \\<inter> m3_inv6_ticket \\<inter> m3_inv4_lkeysec)}\n     (trans m2), (trans m3)\n   {> R23}\"\nby (auto simp add: m3_def m3_trans_def m2_def m2_trans_def)\n   (blast intro!: PO_m3_trans_refines_m2_trans)+\n\nlemma PO_m3_observation_consistent [iff]:\n  \"obs_consistent R23 med32 m2 m3\"\nby (auto simp add: obs_consistent_def R23_def med32_def m3_defs)\n\n\ntext \\<open>Refinement result.\\<close>\n\nlemma m3_refines_m2 [iff]:\n  \"refines\n     (R23 \\<inter>\n      (m2_inv3a_sesK_compr) \\<times>\n      (m3_inv7a_sesK_compr \\<inter> m3_inv7b_sesK_compr_non \\<inter> m3_inv6_ticket \\<inter> m3_inv4_lkeysec))\n     med32 m2 m3\"\nby (rule Refinement_using_invariants) (auto)\n\nlemma m3_implements_m2 [iff]:\n  \"implements med32 m2 m3\"\nby (rule refinement_soundness) (auto)\n\n\nsubsection \\<open>Inherited invariants\\<close>\n(******************************************************************************)\n\nsubsubsection \\<open>inv3 (derived): Key secrecy for initiator\\<close>\n(*invh*************************************************************************)\n\ndefinition\n  m3_inv3_ikk_init :: \"m3_state set\"\nwhere\n  \"m3_inv3_ikk_init \\<equiv> {s. \\<forall>A B Ra K Ts nl.\n     runs s Ra = Some (Init, [A, B], aKey K # aNum Ts # nl) \\<longrightarrow> A \\<in> good \\<longrightarrow> B \\<in> good \\<longrightarrow>\n     Key K \\<in> analz (IK s) \\<longrightarrow>\n       (K, A, B, Ra$na, Ts) \\<in> leak s\n  }\"\n\nlemmas m3_inv3_ikk_initI = m3_inv3_ikk_init_def [THEN setc_def_to_intro, rule_format]\nlemmas m3_inv3_ikk_initE [elim] = m3_inv3_ikk_init_def [THEN setc_def_to_elim, rule_format]\nlemmas m3_inv3_ikk_initD = m3_inv3_ikk_init_def [THEN setc_def_to_dest, rule_format, rotated 1]\n\nlemma PO_m3_inv3_ikk_init: \"reach m3 \\<subseteq> m3_inv3_ikk_init\"\nproof (rule INV_from_Refinement_using_invariants [OF m3_refines_m2])\n  show \"Range (R23 \\<inter>\n          m2_inv3a_sesK_compr\n          \\<times> (m3_inv7a_sesK_compr \\<inter> m3_inv7b_sesK_compr_non \\<inter> m3_inv6_ticket \\<inter> m3_inv4_lkeysec)\n        \\<inter> m2_inv6_ikk_init \\<times> UNIV)\n      \\<subseteq> m3_inv3_ikk_init\"\n    by (auto simp add: R23_def R23_pres_def intro!: m3_inv3_ikk_initI)\n       (elim m2_inv6_ikk_initE, auto dest: R23_keys_dests)\nqed auto\n\n\nsubsubsection \\<open>inv4 (derived): Key secrecy for responder\\<close>\n(*invh*************************************************************************)\n\ndefinition\n  m3_inv4_ikk_resp :: \"m3_state set\"\nwhere\n  \"m3_inv4_ikk_resp \\<equiv> {s. \\<forall>A B Rb K Ts nl.\n     runs s Rb = Some (Resp, [A, B], aKey K # aNum Ts # nl) \\<longrightarrow> A \\<in> good \\<longrightarrow> B \\<in> good \\<longrightarrow>\n     Key K \\<in> analz (IK s) \\<longrightarrow>\n       (\\<exists>Na. (K, A, B, Na, Ts) \\<in> leak s)\n  }\"\n\nlemmas m3_inv4_ikk_respI = m3_inv4_ikk_resp_def [THEN setc_def_to_intro, rule_format]\nlemmas m3_inv4_ikk_respE [elim] = m3_inv4_ikk_resp_def [THEN setc_def_to_elim, rule_format]\nlemmas m3_inv4_ikk_respD = m3_inv4_ikk_resp_def [THEN setc_def_to_dest, rule_format, rotated 1]\n\nlemma PO_m3_inv4_ikk_resp: \"reach m3 \\<subseteq> m3_inv4_ikk_resp\"\nproof (rule INV_from_Refinement_using_invariants [OF m3_refines_m2])\n  show \"Range (R23 \\<inter> m2_inv3a_sesK_compr\n                   \\<times> (m3_inv7a_sesK_compr \\<inter> m3_inv7b_sesK_compr_non \\<inter> m3_inv6_ticket \\<inter> m3_inv4_lkeysec)\n                   \\<inter> m2_inv7_ikk_resp \\<times> UNIV)\n      \\<subseteq> m3_inv4_ikk_resp\"\n    by (auto simp add: R23_def R23_pres_def intro!: m3_inv4_ikk_respI)\n       (elim m2_inv7_ikk_respE, auto dest: R23_keys_dests)\nqed auto\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Security_Protocol_Refinement/Key_establish/m3_kerberos4.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5851011542032312, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.26294014911576163}}
{"text": "theory SINVAR_ACLcommunicateWith_impl\nimports SINVAR_ACLcommunicateWith \"../TopoS_Interface_impl\"\nbegin\n\ncode_identifier code_module SINVAR_ACLcommunicateWith_impl => (Scala) SINVAR_ACLcommunicateWith\n\n\nsubsubsection {* List Implementation *}\n\nfun sinvar :: \"'v list_graph \\<Rightarrow> ('v \\<Rightarrow> 'v list) \\<Rightarrow> bool\" where\n  \"sinvar G nP = (\\<forall> v \\<in> set (nodesL G). \\<forall>a \\<in> (set (succ_tran G v)). a \\<in> set (nP v))\"\n\n\ndefinition \"NetModel_node_props (P::('v::vertex, 'v list) TopoS_Params) = \n  (\\<lambda> i. (case (node_properties P) i of Some property \\<Rightarrow> property | None \\<Rightarrow> SINVAR_ACLcommunicateWith.default_node_properties))\"\n\n\ndefinition \"ACLcommunicateWith_offending_list = Generic_offending_list sinvar\"\n\ndefinition \"ACLcommunicateWith_eval G P = (wf_list_graph G \\<and> \n  sinvar G (SecurityInvariant.node_props SINVAR_ACLcommunicateWith.default_node_properties P))\"\n\n\nlemma sinvar_correct: \"wf_list_graph G \\<Longrightarrow> SINVAR_ACLcommunicateWith.sinvar (list_graph_to_graph G) nP = sinvar G nP\"\nby (metis SINVAR_ACLcommunicateWith.sinvar.simps SINVAR_ACLcommunicateWith_impl.sinvar.simps graph.select_convs(1) list_graph_to_graph_def succ_tran_correct)\n\n\ninterpretation SINVAR_ACLcommunicateWith_impl:TopoS_List_Impl \n  where default_node_properties=SINVAR_ACLcommunicateWith.default_node_properties\n  and sinvar_spec=SINVAR_ACLcommunicateWith.sinvar\n  and sinvar_impl=sinvar\n  and receiver_violation=SINVAR_ACLcommunicateWith.receiver_violation\n  and offending_flows_impl=ACLcommunicateWith_offending_list\n  and node_props_impl=NetModel_node_props\n  and eval_impl=ACLcommunicateWith_eval\n apply(unfold TopoS_List_Impl_def)\n apply(rule conjI)\n  apply(rule conjI)\n   apply(simp add: TopoS_ACLcommunicateWith; fail)\n  apply(intro allI impI)\n  apply(fact sinvar_correct)\n apply(rule conjI)\n  apply(unfold ACLcommunicateWith_offending_list_def)\n  apply(intro allI impI)\n  apply(rule Generic_offending_list_correct)\n   apply(assumption)\n  apply(simp only: sinvar_correct; fail)\n apply(rule conjI)\n  apply(intro allI)\n  apply(simp only: NetModel_node_props_def)\n  apply(metis ACLcommunicateWith.node_props.simps ACLcommunicateWith.node_props_eq_node_props_formaldef)\n apply(simp only: ACLcommunicateWith_eval_def)\n apply(intro allI impI)\n apply(rule TopoS_eval_impl_proofrule[OF TopoS_ACLcommunicateWith])\n apply(simp only: sinvar_correct; fail)\ndone\n\n\nsubsubsection {* packing *}\n  definition SINVAR_LIB_ACLcommunicateWith:: \"('v::vertex, 'v list) TopoS_packed\" where\n    \"SINVAR_LIB_ACLcommunicateWith \\<equiv> \n    \\<lparr> nm_name = ''ACLcommunicateWith'', \n      nm_receiver_violation = SINVAR_ACLcommunicateWith.receiver_violation,\n      nm_default = SINVAR_ACLcommunicateWith.default_node_properties, \n      nm_sinvar = sinvar,\n      nm_offending_flows = ACLcommunicateWith_offending_list, \n      nm_node_props = NetModel_node_props,\n      nm_eval = ACLcommunicateWith_eval\n      \\<rparr>\"\n  interpretation SINVAR_LIB_ACLcommunicateWith_interpretation: TopoS_modelLibrary SINVAR_LIB_ACLcommunicateWith\n      SINVAR_ACLcommunicateWith.sinvar\n    apply(unfold TopoS_modelLibrary_def SINVAR_LIB_ACLcommunicateWith_def)\n    apply(rule conjI)\n     apply(simp)\n    apply(simp)\n    by(unfold_locales)\n\n\n\ntext {* Examples*}\ncontext begin\n  text{*\n    1 can access 2 and 3\n    2 can access 3\n  *}\n  private lemma \"sinvar\n            \\<lparr> nodesL = [1::nat, 2, 3],\n              edgesL = [(1,2), (2,3)]\\<rparr>\n            (((\\<lambda>v. SINVAR_ACLcommunicateWith.default_node_properties)\n                    (1 := [2,3]))\n                    (2 := [3]))\" by eval\n\n  text{*\n    Everyone can access everyone, except for 1: 1 must not access 4.\n    The offending flows may be any edge on the path from 1 to 4\n  *}\n  lemma \"ACLcommunicateWith_offending_list \n          \\<lparr> nodesL = [1::nat, 2, 3, 4],\n            edgesL = [(1,2), (2,3), (3, 4)]\\<rparr>\n          (((((\\<lambda>v. SINVAR_ACLcommunicateWith.default_node_properties)\n          (1 := [1,2,3]))\n          (2 := [1,2,3,4]))\n          (3 := [1,2,3,4]))\n          (4 := [1,2,3,4])) =\n       [[(1, 2)], [(2, 3)], [(3, 4)]]\" by eval\n  text{*\n    If we add the additional edge from 1 to 3, then the offending flows are either\n    \\<^item> [(3.4)], because this disconnects 4 from the graph completely\n    \\<^item> any pair of edges which disconnects 1 from 3\n  *}\n  lemma \"ACLcommunicateWith_offending_list \n          \\<lparr> nodesL = [1::nat, 2, 3, 4],\n            edgesL = [(1,2), (1,3), (2,3), (3, 4)]\\<rparr>\n          (((((\\<lambda>v. SINVAR_ACLcommunicateWith.default_node_properties)\n          (1 := [1,2,3]))\n          (2 := [1,2,3,4]))\n          (3 := [1,2,3,4]))\n          (4 := [1,2,3,4])) =\n       [[(1, 2), (1, 3)], [(1, 3), (2, 3)], [(3, 4)]]\" by eval\nend\n\n\nhide_const (open) NetModel_node_props\nhide_const (open) sinvar\n\nend\n", "meta": {"author": "diekmann", "repo": "topoS", "sha": "4303ebd95a501283c02fd513c109e645a48ad080", "save_path": "github-repos/isabelle/diekmann-topoS", "path": "github-repos/isabelle/diekmann-topoS/topoS-4303ebd95a501283c02fd513c109e645a48ad080/thy/Network_Security_Policy_Verification/Security_Invariants/SINVAR_ACLcommunicateWith_impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6893056167854461, "lm_q2_score": 0.38121956625614994, "lm_q1q2_score": 0.2627767882488757}}
{"text": "(*  Title:      HOL/HOLCF/IOA/meta_theory/RefCorrectness.thy\n    Author:     Olaf Müller\n*)\n\nsection {* Correctness of Refinement Mappings in HOLCF/IOA *}\n\ntheory RefCorrectness\nimports RefMappings\nbegin\n\ndefinition\n  corresp_exC :: \"('a,'s2)ioa => ('s1 => 's2) => ('a,'s1)pairs\n                   -> ('s1 => ('a,'s2)pairs)\" where\n  \"corresp_exC A f = (fix$(LAM h ex. (%s. case ex of\n      nil =>  nil\n    | x##xs => (flift1 (%pr. (@cex. move A cex (f s) (fst pr) (f (snd pr)))\n                              @@ ((h$xs) (snd pr)))\n                        $x) )))\"\ndefinition\n  corresp_ex :: \"('a,'s2)ioa => ('s1 => 's2) =>\n                  ('a,'s1)execution => ('a,'s2)execution\" where\n  \"corresp_ex A f ex = (f (fst ex),(corresp_exC A f$(snd ex)) (fst ex))\"\n\ndefinition\n  is_fair_ref_map :: \"('s1 => 's2) => ('a,'s1)ioa => ('a,'s2)ioa => bool\" where\n  \"is_fair_ref_map f C A =\n      (is_ref_map f C A &\n       (! ex : executions(C). fair_ex C ex --> fair_ex A (corresp_ex A f ex)))\"\n\n(* Axioms for fair trace inclusion proof support, not for the correctness proof\n   of refinement mappings!\n   Note: Everything is superseded by LiveIOA.thy! *)\n\naxiomatization where\ncorresp_laststate:\n  \"Finite ex ==> laststate (corresp_ex A f (s,ex)) = f (laststate (s,ex))\"\n\naxiomatization where\ncorresp_Finite:\n  \"Finite (snd (corresp_ex A f (s,ex))) = Finite ex\"\n\naxiomatization where\nFromAtoC:\n  \"fin_often (%x. P (snd x)) (snd (corresp_ex A f (s,ex))) ==> fin_often (%y. P (f (snd y))) ex\"\n\naxiomatization where\nFromCtoA:\n  \"inf_often (%y. P (fst y)) ex ==> inf_often (%x. P (fst x)) (snd (corresp_ex A f (s,ex)))\"\n\n\n(* Proof by case on inf W in ex: If so, ok. If not, only fin W in ex, ie there is\n   an index i from which on no W in ex. But W inf enabled, ie at least once after i\n   W is enabled. As W does not occur after i and W is enabling_persistent, W keeps\n   enabled until infinity, ie. indefinitely *)\naxiomatization where\npersistent:\n  \"[|inf_often (%x. Enabled A W (snd x)) ex; en_persistent A W|]\n   ==> inf_often (%x. fst x :W) ex | fin_often (%x. ~Enabled A W (snd x)) ex\"\n\naxiomatization where\ninfpostcond:\n  \"[| is_exec_frag A (s,ex); inf_often (%x. fst x:W) ex|]\n    ==> inf_often (% x. set_was_enabled A W (snd x)) ex\"\n\n\nsubsection \"corresp_ex\"\n\nlemma corresp_exC_unfold: \"corresp_exC A f  = (LAM ex. (%s. case ex of\n       nil =>  nil\n     | x##xs => (flift1 (%pr. (@cex. move A cex (f s) (fst pr) (f (snd pr)))\n                               @@ ((corresp_exC A f $xs) (snd pr)))\n                         $x) ))\"\napply (rule trans)\napply (rule fix_eq2)\napply (simp only: corresp_exC_def)\napply (rule beta_cfun)\napply (simp add: flift1_def)\ndone\n\nlemma corresp_exC_UU: \"(corresp_exC A f$UU) s=UU\"\napply (subst corresp_exC_unfold)\napply simp\ndone\n\nlemma corresp_exC_nil: \"(corresp_exC A f$nil) s = nil\"\napply (subst corresp_exC_unfold)\napply simp\ndone\n\nlemma corresp_exC_cons: \"(corresp_exC A f$(at>>xs)) s =\n           (@cex. move A cex (f s) (fst at) (f (snd at)))\n           @@ ((corresp_exC A f$xs) (snd at))\"\napply (rule trans)\napply (subst corresp_exC_unfold)\napply (simp add: Consq_def flift1_def)\napply simp\ndone\n\n\ndeclare corresp_exC_UU [simp] corresp_exC_nil [simp] corresp_exC_cons [simp]\n\n\n\nsubsection \"properties of move\"\n\nlemma move_is_move:\n   \"[|is_ref_map f C A; reachable C s; (s,a,t):trans_of C|] ==>\n      move A (@x. move A x (f s) a (f t)) (f s) a (f t)\"\napply (unfold is_ref_map_def)\napply (subgoal_tac \"? ex. move A ex (f s) a (f t) \")\nprefer 2\napply simp\napply (erule exE)\napply (rule someI)\napply assumption\ndone\n\nlemma move_subprop1:\n   \"[|is_ref_map f C A; reachable C s; (s,a,t):trans_of C|] ==>\n     is_exec_frag A (f s,@x. move A x (f s) a (f t))\"\napply (cut_tac move_is_move)\ndefer\napply assumption+\napply (simp add: move_def)\ndone\n\nlemma move_subprop2:\n   \"[|is_ref_map f C A; reachable C s; (s,a,t):trans_of C|] ==>\n     Finite ((@x. move A x (f s) a (f t)))\"\napply (cut_tac move_is_move)\ndefer\napply assumption+\napply (simp add: move_def)\ndone\n\nlemma move_subprop3:\n   \"[|is_ref_map f C A; reachable C s; (s,a,t):trans_of C|] ==>\n     laststate (f s,@x. move A x (f s) a (f t)) = (f t)\"\napply (cut_tac move_is_move)\ndefer\napply assumption+\napply (simp add: move_def)\ndone\n\nlemma move_subprop4:\n   \"[|is_ref_map f C A; reachable C s; (s,a,t):trans_of C|] ==>\n      mk_trace A$((@x. move A x (f s) a (f t))) =\n        (if a:ext A then a>>nil else nil)\"\napply (cut_tac move_is_move)\ndefer\napply assumption+\napply (simp add: move_def)\ndone\n\n\n(* ------------------------------------------------------------------ *)\n(*                   The following lemmata contribute to              *)\n(*                 TRACE INCLUSION Part 1: Traces coincide            *)\n(* ------------------------------------------------------------------ *)\n\nsection \"Lemmata for <==\"\n\n(* --------------------------------------------------- *)\n(*   Lemma 1.1: Distribution of mk_trace and @@        *)\n(* --------------------------------------------------- *)\n\nlemma mk_traceConc: \"mk_trace C$(ex1 @@ ex2)= (mk_trace C$ex1) @@ (mk_trace C$ex2)\"\napply (simp add: mk_trace_def filter_act_def MapConc)\ndone\n\n\n\n(* ------------------------------------------------------\n                 Lemma 1 :Traces coincide\n   ------------------------------------------------------- *)\ndeclare split_if [split del]\n\nlemma lemma_1:\n  \"[|is_ref_map f C A; ext C = ext A|] ==>\n         !s. reachable C s & is_exec_frag C (s,xs) -->\n             mk_trace C$xs = mk_trace A$(snd (corresp_ex A f (s,xs)))\"\napply (unfold corresp_ex_def)\napply (tactic {* pair_induct_tac @{context} \"xs\" [@{thm is_exec_frag_def}] 1 *})\n(* cons case *)\napply (auto simp add: mk_traceConc)\napply (frule reachable.reachable_n)\napply assumption\napply (erule_tac x = \"y\" in allE)\napply (simp add: move_subprop4 split add: split_if)\ndone\n\ndeclare split_if [split]\n\n(* ------------------------------------------------------------------ *)\n(*                   The following lemmata contribute to              *)\n(*              TRACE INCLUSION Part 2: corresp_ex is execution       *)\n(* ------------------------------------------------------------------ *)\n\nsection \"Lemmata for ==>\"\n\n(* -------------------------------------------------- *)\n(*                   Lemma 2.1                        *)\n(* -------------------------------------------------- *)\n\nlemma lemma_2_1 [rule_format (no_asm)]:\n\"Finite xs -->\n (!s .is_exec_frag A (s,xs) & is_exec_frag A (t,ys) &\n      t = laststate (s,xs)\n  --> is_exec_frag A (s,xs @@ ys))\"\n\napply (rule impI)\napply (tactic {* Seq_Finite_induct_tac @{context} 1 *})\n(* main case *)\napply (auto simp add: split_paired_all)\ndone\n\n\n(* ----------------------------------------------------------- *)\n(*               Lemma 2 : corresp_ex is execution             *)\n(* ----------------------------------------------------------- *)\n\n\n\nlemma lemma_2:\n \"[| is_ref_map f C A |] ==>\n  !s. reachable C s & is_exec_frag C (s,xs)\n  --> is_exec_frag A (corresp_ex A f (s,xs))\"\n\napply (unfold corresp_ex_def)\n\napply simp\napply (tactic {* pair_induct_tac @{context} \"xs\" [@{thm is_exec_frag_def}] 1 *})\n(* main case *)\napply auto\napply (rule_tac t = \"f y\" in lemma_2_1)\n\n(* Finite *)\napply (erule move_subprop2)\napply assumption+\napply (rule conjI)\n\n(* is_exec_frag *)\napply (erule move_subprop1)\napply assumption+\napply (rule conjI)\n\n(* Induction hypothesis  *)\n(* reachable_n looping, therefore apply it manually *)\napply (erule_tac x = \"y\" in allE)\napply simp\napply (frule reachable.reachable_n)\napply assumption\napply simp\n(* laststate *)\napply (erule move_subprop3 [symmetric])\napply assumption+\ndone\n\n\nsubsection \"Main Theorem: TRACE - INCLUSION\"\n\nlemma trace_inclusion:\n  \"[| ext C = ext A; is_ref_map f C A |]\n           ==> traces C <= traces A\"\n\n  apply (unfold traces_def)\n\n  apply (simp (no_asm) add: has_trace_def2)\n  apply auto\n\n  (* give execution of abstract automata *)\n  apply (rule_tac x = \"corresp_ex A f ex\" in bexI)\n\n  (* Traces coincide, Lemma 1 *)\n  apply (tactic {* pair_tac @{context} \"ex\" 1 *})\n  apply (erule lemma_1 [THEN spec, THEN mp])\n  apply assumption+\n  apply (simp add: executions_def reachable.reachable_0)\n\n  (* corresp_ex is execution, Lemma 2 *)\n  apply (tactic {* pair_tac @{context} \"ex\" 1 *})\n  apply (simp add: executions_def)\n  (* start state *)\n  apply (rule conjI)\n  apply (simp add: is_ref_map_def corresp_ex_def)\n  (* is-execution-fragment *)\n  apply (erule lemma_2 [THEN spec, THEN mp])\n  apply (simp add: reachable.reachable_0)\n  done\n\n\nsubsection \"Corollary:  FAIR TRACE - INCLUSION\"\n\nlemma fininf: \"(~inf_often P s) = fin_often P s\"\napply (unfold fin_often_def)\napply auto\ndone\n\n\nlemma WF_alt: \"is_wfair A W (s,ex) =\n  (fin_often (%x. ~Enabled A W (snd x)) ex --> inf_often (%x. fst x :W) ex)\"\napply (simp add: is_wfair_def fin_often_def)\napply auto\ndone\n\nlemma WF_persistent: \"[|is_wfair A W (s,ex); inf_often (%x. Enabled A W (snd x)) ex;\n          en_persistent A W|]\n    ==> inf_often (%x. fst x :W) ex\"\napply (drule persistent)\napply assumption\napply (simp add: WF_alt)\napply auto\ndone\n\n\nlemma fair_trace_inclusion: \"!! C A.\n          [| is_ref_map f C A; ext C = ext A;\n          !! ex. [| ex:executions C; fair_ex C ex|] ==> fair_ex A (corresp_ex A f ex) |]\n          ==> fairtraces C <= fairtraces A\"\napply (simp (no_asm) add: fairtraces_def fairexecutions_def)\napply auto\napply (rule_tac x = \"corresp_ex A f ex\" in exI)\napply auto\n\n  (* Traces coincide, Lemma 1 *)\n  apply (tactic {* pair_tac @{context} \"ex\" 1 *})\n  apply (erule lemma_1 [THEN spec, THEN mp])\n  apply assumption+\n  apply (simp add: executions_def reachable.reachable_0)\n\n  (* corresp_ex is execution, Lemma 2 *)\n  apply (tactic {* pair_tac @{context} \"ex\" 1 *})\n  apply (simp add: executions_def)\n  (* start state *)\n  apply (rule conjI)\n  apply (simp add: is_ref_map_def corresp_ex_def)\n  (* is-execution-fragment *)\n  apply (erule lemma_2 [THEN spec, THEN mp])\n  apply (simp add: reachable.reachable_0)\n\ndone\n\nlemma fair_trace_inclusion2: \"!! C A.\n          [| inp(C) = inp(A); out(C)=out(A);\n             is_fair_ref_map f C A |]\n          ==> fair_implements C A\"\napply (simp add: is_fair_ref_map_def fair_implements_def fairtraces_def fairexecutions_def)\napply auto\napply (rule_tac x = \"corresp_ex A f ex\" in exI)\napply auto\n\n  (* Traces coincide, Lemma 1 *)\n  apply (tactic {* pair_tac @{context} \"ex\" 1 *})\n  apply (erule lemma_1 [THEN spec, THEN mp])\n  apply (simp (no_asm) add: externals_def)\n  apply (auto)[1]\n  apply (simp add: executions_def reachable.reachable_0)\n\n  (* corresp_ex is execution, Lemma 2 *)\n  apply (tactic {* pair_tac @{context} \"ex\" 1 *})\n  apply (simp add: executions_def)\n  (* start state *)\n  apply (rule conjI)\n  apply (simp add: is_ref_map_def corresp_ex_def)\n  (* is-execution-fragment *)\n  apply (erule lemma_2 [THEN spec, THEN mp])\n  apply (simp add: reachable.reachable_0)\n\ndone\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/HOLCF/IOA/meta_theory/RefCorrectness.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.600188359260205, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.26277656757891465}}
{"text": "(*\n    Author:   Benedikt Seidl\n    License:  BSD\n*)\n\nsection \\<open>Code export to Standard ML\\<close>\n\ntheory Code_Export\nimports\n  \"LTL_to_DRA/DRA_Instantiation\"\n  LTL.Code_Equations\n  \"HOL-Library.Code_Target_Numeral\"\nbegin\n\nsubsection \\<open>Hashing Sets\\<close>\n\nglobal_interpretation comp_fun_commute \"plus o cube o hashcode :: ('a :: hashable) \\<Rightarrow> hashcode \\<Rightarrow> hashcode\"\n  by unfold_locales (auto simp: cube_def)\n\n\n\nlemma [code]:\n  \"hashcode (abs_ltln\\<^sub>P \\<phi>) = hashcode (min_dnf \\<phi>)\"\n  by simp\n\n\n\nlemma [code]:\n  \"hashcode (abs_ltln\\<^sub>Q \\<phi>) = hashcode (min_dnf (Unf \\<phi>))\"\n  by simp\n\n\nsubsection \\<open>LTL to DRA\\<close>\n\ndeclare ltl_to_dra\\<^sub>P.af_letter\\<^sub>F_lifted_semantics [code]\ndeclare ltl_to_dra\\<^sub>P.af_letter\\<^sub>G_lifted_semantics [code]\ndeclare ltl_to_dra\\<^sub>P.af_letter\\<^sub>\\<nu>_lifted_semantics [code]\n\ndeclare ltl_to_dra\\<^sub>Q.af_letter\\<^sub>F_lifted_semantics [code]\ndeclare ltl_to_dra\\<^sub>Q.af_letter\\<^sub>G_lifted_semantics [code]\ndeclare ltl_to_dra\\<^sub>Q.af_letter\\<^sub>\\<nu>_lifted_semantics [code]\n\ndefinition atoms_ltlc_list_literals :: \"String.literal ltlc \\<Rightarrow> String.literal list\"\nwhere\n  \"atoms_ltlc_list_literals = atoms_ltlc_list\"\n\ndefinition ltlc_to_draei_literals :: \"equiv \\<Rightarrow> String.literal ltlc \\<Rightarrow> (String.literal set, nat) draei\"\nwhere\n  \"ltlc_to_draei_literals = ltlc_to_draei\"\n\ndefinition sort_transitions :: \"(nat \\<times> String.literal set \\<times> nat) list \\<Rightarrow> (nat \\<times> String.literal set \\<times> nat) list\"\nwhere\n  \"sort_transitions = sort_key fst\"\n\nexport_code True_ltlc Iff_ltlc ltlc_to_draei_literals Prop PropUnfold\n  alphabetei initialei transitionei conditionei\n  integer_of_nat atoms_ltlc_list_literals sort_transitions set\n  in SML module_name LTL file_prefix LTL_to_DRA\n\n\n\nsubsection \\<open>LTL to NBA\\<close>\n\n(* TODO *)\n\n\n\nsubsection \\<open>LTL to LDBA\\<close>\n\n(* TODO *)\n\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/LTL_Master_Theorem/Code_Export.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5698526660244838, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.2627116407731443}}
{"text": "theory Wasm_Instantiation imports Wasm_Module_Checker Wasm_Interpreter_Properties begin\n\nfun alloc_Xs :: \"(s \\<Rightarrow> 'a \\<Rightarrow> (s \\<times> i)) \\<Rightarrow> s \\<Rightarrow> 'a list \\<Rightarrow> (s \\<times> i list)\" where\n  \"alloc_Xs f s [] = (s,[])\"\n| \"alloc_Xs f s (m_X#m_Xs) = (let (s'', i_X) = f s m_X in\n                              let (s',i_Xs) = alloc_Xs f s'' m_Xs in\n                              (s',i_X#i_Xs))\"\n\ndefinition alloc_func :: \"s \\<Rightarrow> module_func \\<Rightarrow> inst \\<Rightarrow> (s \\<times> i)\" where\n  \"alloc_func s m_f inst =\n     (case m_f of (i_t, loc_ts, b_es) \\<Rightarrow>\n        (s\\<lparr>s.funcs := (funcs s)@[Func_native inst ((types inst)!i_t) loc_ts b_es]\\<rparr>,length (funcs s)))\"\n\nabbreviation \"alloc_funcs s m_fs i \\<equiv> alloc_Xs (\\<lambda>s m_f. alloc_func s m_f i) s m_fs\"\n\ndefinition alloc_tab :: \"s \\<Rightarrow> tab_t \\<Rightarrow> (s \\<times> i)\" where\n  \"alloc_tab s m_t = (s\\<lparr>s.tabs := (tabs s)@[(replicate (l_min m_t) None, (l_max m_t))]\\<rparr>,length (tabs s))\"\n\nabbreviation \"alloc_tabs \\<equiv> alloc_Xs alloc_tab\"\n\ndefinition alloc_mem :: \"s \\<Rightarrow> mem_t \\<Rightarrow> (s \\<times> i)\" where\n  \"alloc_mem s m_m = (s\\<lparr>s.mems := (mems s)@[mem_mk m_m]\\<rparr>,length (mems s))\"\n\nabbreviation \"alloc_mems \\<equiv> alloc_Xs alloc_mem\"\n\ndefinition alloc_glob :: \"s \\<Rightarrow> (module_glob \\<times> v) \\<Rightarrow> (s \\<times> i)\" where\n  \"alloc_glob s m_g_v = \n    (case m_g_v of (m_g, v) \\<Rightarrow>\n      (s\\<lparr>s.globs := (globs s)@[\\<lparr>g_mut=(tg_mut (module_glob.g_type m_g)), g_val=v\\<rparr>]\\<rparr>,length (globs s)))\"\n\nabbreviation \"alloc_globs s m_gs vs \\<equiv> alloc_Xs alloc_glob s (zip m_gs vs)\"\n\nlemma alloc_func_length:\n  assumes \"alloc_func s m_f i = (s', i_f)\"\n  shows \"length (funcs s) = i_f\"\n        \"length (funcs s') = Suc i_f\"\n        \"\\<exists>farb. (funcs s)@[farb] = (funcs s')\"\n        \"(tabs s) = (tabs s')\"\n        \"(mems s) = (mems s')\"\n        \"(globs s) = (globs s')\"\n  using assms[symmetric]\n  unfolding alloc_func_def\n  by (simp_all split: prod.splits)\n\nlemma alloc_tab_length:\n  assumes \"alloc_tab s m_t = (s', i_t)\"\n  shows \"length (tabs s) = i_t\"\n        \"length (tabs s') = Suc i_t\"\n        \"(funcs s) = (funcs s')\"\n        \"\\<exists>tarb. (tabs s)@[tarb] = (tabs s')\"\n        \"(mems s) = (mems s')\"\n        \"(globs s) = (globs s')\"\n  using assms[symmetric]\n  unfolding alloc_tab_def\n  by (simp_all split: prod.splits)\n\nlemma alloc_mem_length:\n  assumes \"alloc_mem s m_m = (s', i_m)\"\n  shows \"length (mems s) = i_m\"\n        \"length (mems s') = Suc i_m\"\n        \"(funcs s) = (funcs s')\"\n        \"(tabs s) = (tabs s')\"\n        \"\\<exists>marb. (mems s)@[marb] = (mems s')\"\n        \"(globs s) = (globs s')\"\n  using assms[symmetric]\n  unfolding alloc_mem_def\n  by (simp_all split: prod.splits)\n\nlemma alloc_glob_length:\n  assumes \"alloc_glob s (m_g, v) = (s', i_g)\"\n  shows \"length (globs s) = i_g\"\n        \"length (globs s') = Suc i_g\"\n        \"(funcs s) = (funcs s')\"\n        \"(tabs s) = (tabs s')\"\n        \"(mems s) = (mems s')\"\n        \"(globs s)@[\\<lparr>g_mut=(tg_mut (module_glob.g_type m_g)), g_val=v\\<rparr>] = (globs s')\"\n  using assms[symmetric]\n  unfolding alloc_glob_def\n  by (simp_all split: prod.splits)\n\nlemma alloc_funcs_range:\n  assumes \"alloc_funcs s m_fs i = (s', i_fs)\"\n  shows \"i_fs = [length (funcs s) ..< (length (funcs s) + length m_fs)] \\<and>\n         (\\<exists>farb. (funcs s)@farb = (funcs s')) \\<and>\n         (tabs s) = (tabs s') \\<and>\n         (mems s) = (mems s') \\<and>\n         (globs s) = (globs s')\"\n  using assms\nproof (induction m_fs arbitrary: s i_fs)\n  case Nil\n  thus ?case\n    by simp\nnext\n  case (Cons m_f m_fs)\n  obtain s'' i_f' i_fs' where s''_is:\"alloc_func s m_f i = (s'', i_f')\"\n                                     \"alloc_funcs s'' m_fs i = (s', i_fs')\"\n                                     \"i_f' # i_fs' = i_fs\"\n    using Cons(2)\n    by (simp split: prod.splits)\n  thus ?case\n    using Cons(1)[OF s''_is(2)] using alloc_func_length[OF s''_is(1)] upt_rec\n    apply (simp split: prod.splits)\n    apply (metis append_assoc)\n    done\nqed\n\nlemma alloc_tabs_range:\n  assumes \"alloc_tabs s m_ts = (s', i_ts)\"\n  shows \"i_ts = [length (tabs s) ..< (length (tabs s) + length m_ts)] \\<and>\n         (funcs s) = (funcs s') \\<and>\n         (\\<exists>tarb. (tabs s)@tarb = (tabs s')) \\<and>\n         (mems s) = (mems s') \\<and>\n         (globs s) = (globs s')\"\n  using assms\nproof (induction m_ts arbitrary: s i_ts)\n  case Nil\n  thus ?case\n    by simp\nnext\n  case (Cons m_t m_ts)\n  obtain s'' i_t' i_ts' where s''_is:\"alloc_tab s m_t = (s'', i_t')\"\n                                     \"alloc_tabs s'' m_ts = (s', i_ts')\"\n                                     \"i_t' # i_ts' = i_ts\"\n    using Cons(2)\n    by (simp split: prod.splits)\n  thus ?case\n    using Cons(1)[OF s''_is(2)] using alloc_tab_length[OF s''_is(1)] upt_rec\n    apply (simp split: prod.splits)\n    apply (metis append_assoc)\n    done\nqed\n\nlemma alloc_mems_range:\n  assumes \"alloc_mems s m_ms = (s', i_ms)\"\n  shows \"i_ms = [length (mems s) ..< (length (mems s) + length m_ms)] \\<and>\n         (funcs s) = (funcs s') \\<and>\n         (tabs s) = (tabs s') \\<and>\n         (\\<exists>marb. (mems s)@marb = (mems s')) \\<and>\n         (globs s) = (globs s')\"\n  using assms\nproof (induction m_ms arbitrary: s i_ms)\n  case Nil\n  thus ?case\n    by simp\nnext\n  case (Cons m_m m_ms)\n  obtain s'' i_m' i_ms' where s''_is:\"alloc_mem s m_m = (s'', i_m')\"\n                                     \"alloc_mems s'' m_ms = (s', i_ms')\"\n                                     \"i_m' # i_ms' = i_ms\"\n    using Cons(2)\n    by (simp split: prod.splits)\n  thus ?case\n    using Cons(1)[OF s''_is(2)] using alloc_mem_length[OF s''_is(1)] upt_rec\n    apply (simp split: prod.splits)\n    apply (metis append_assoc)\n    done\nqed\n\nlemma alloc_globs_range:\n  assumes \"alloc_globs s m_gs vs = (s', i_gs)\"\n  shows \"i_gs = [length (globs s) ..< (length (globs s) + min (length m_gs) (length vs))] \\<and>\n         (funcs s) = (funcs s') \\<and>\n         (tabs s) = (tabs s') \\<and>\n         (mems s) = (mems s') \\<and>\n         ((globs s)@(map2 (\\<lambda>m_g v. \\<lparr>g_mut=(tg_mut (module_glob.g_type m_g)), g_val=v\\<rparr>) m_gs vs) = (globs s'))\"\n  using assms\nproof (induction m_gs arbitrary: s i_gs vs)\n  case Nil\n  thus ?case\n    by simp\nnext\n  case (Cons m_g m_gs)\n  note outer_Cons = Cons\n  show ?case\n  proof (cases vs)\n    case Nil\n    thus ?thesis\n      using Cons\n      by simp\n  next\n    case (Cons v vs')\n    then obtain s'' i_g' i_gs' where s''_is:\"alloc_glob s (m_g, v) = (s'', i_g')\"\n                                       \"alloc_globs s'' m_gs vs' = (s', i_gs')\"\n                                       \"i_g' # i_gs' = i_gs\"\n      using outer_Cons(2)\n      by (simp split: prod.splits)\n    thus ?thesis\n      using outer_Cons(1)[OF s''_is(2)] using alloc_glob_length[OF s''_is(1)] upt_rec Cons\n      apply (simp)\n      apply (metis (no_types, lifting) append_Cons append_assoc self_append_conv2)\n      done\n  qed\nqed\n\nlemma length_alloc_Xs:\n  assumes \"alloc_Xs f s m_Xs = (s', i_Xs)\"\n  shows \"length i_Xs = length m_Xs\"\n  using assms\nproof (induction m_Xs arbitrary: s i_Xs)\n  case Nil\n  thus ?case\n    by simp\nnext\n  case (Cons m_X m_Xs)\n  thus ?case\n    by (fastforce split: prod.splits)\nqed\n\nlemma alloc_Xs_app:\n  assumes  \"alloc_Xs f s (m_Xs@m_Ys) = (s', i_XYs)\"\n  shows \"\\<exists>s'' i_Xs i_Ys. i_XYs = i_Xs@i_Ys \\<and>\n              alloc_Xs f s m_Xs = (s'', i_Xs) \\<and>\n              alloc_Xs f s'' m_Ys = (s', i_Ys)\"\n  using assms\nproof (induction f s \"(m_Xs@m_Ys)\" arbitrary: m_Xs i_XYs rule: alloc_Xs.induct)\n  case (1 f s)\n  thus ?case\n    by simp\nnext\n  case (2 f s m_X' m_XYs')\n  consider (a) \"m_Xs = []\" \"m_X' # m_XYs' = m_Ys\"\n         | (b) m_Xs' where \"m_X' # m_Xs' = m_Xs\" \"m_XYs' = m_Xs' @ m_Ys\"\n    using Cons_eq_append_conv[of m_X' m_XYs' m_Xs m_Ys]\n          2(2)\n    by blast\n  thus ?case\n  proof cases\n    case a\n    thus ?thesis\n      using 2\n      by fastforce\n  next\n    case b\n    obtain s'' i_XY i_XYs' where s''_is:\n      \"m_Xs = m_X' # m_Xs'\"\n      \"f s m_X' = (s'', i_XY)\"\n      \"alloc_Xs f s'' (m_Xs' @ m_Ys) = (s', i_XYs')\"\n      \"i_XY # i_XYs' = i_XYs\"\n      using 2(3) b(1)[symmetric]\n      by (simp split: prod.splits)\n    thus ?thesis\n      using 2(1)[OF _ _ b(2) s''_is(3), of _ i_XY]\n      by (fastforce split: prod.splits)\n  qed\nqed\n\nlemma alloc_Xs_snoc:\n  assumes  \"alloc_Xs f s (m_Xs@[m_X]) = (s', i_XYs)\"\n  shows \"\\<exists>s'' i_Xs i_X. i_XYs = i_Xs@[i_X] \\<and>\n              alloc_Xs f s m_Xs = (s'', i_Xs) \\<and>\n              f s'' m_X = (s', i_X)\"\n  using alloc_Xs_app[OF assms]\n  apply (simp split: prod.splits)\n  apply (metis prod.exhaust_sel)\n  done\n\ninductive alloc_module :: \"s \\<Rightarrow> m \\<Rightarrow> v_ext list \\<Rightarrow> v list \\<Rightarrow> (s \\<times> inst \\<times> module_export list) \\<Rightarrow> bool\" where\n  \"\\<lbrakk>inst = \\<lparr>types=(m_types m),\n           funcs=(ext_funcs imps)@i_fs,\n           tabs=(ext_tabs imps)@i_ts,\n           mems=(ext_mems imps)@i_ms,\n           globs=(ext_globs imps)@i_gs\\<rparr>;\n    alloc_funcs s (m_funcs m) inst = (s1,i_fs);\n    alloc_tabs s1 (m_tabs m) = (s2,i_ts);\n    alloc_mems s2 (m_mems m) = (s3,i_ms);\n    alloc_globs s3 (m_globs m) gvs = (s',i_gs);\n    exps = map (\\<lambda>m_exp. \\<lparr>E_name=(E_name m_exp), E_desc=(export_get_v_ext inst (E_desc m_exp))\\<rparr>) (m_exports m)\n     \\<rbrakk> \\<Longrightarrow> alloc_module s m imps gvs (s',inst,exps)\"\n\ndefinition interp_alloc_module :: \"s \\<Rightarrow> m \\<Rightarrow> v_ext list \\<Rightarrow> v list \\<Rightarrow> (s \\<times> inst \\<times> module_export list)\" where\n  \"interp_alloc_module s m imps gvs =\n   (let i_fs = [length (funcs s) ..< (length (funcs s) + length (m_funcs m))] in\n    let i_ts = [length (tabs s) ..< (length (tabs s) + length (m_tabs m))] in\n    let i_ms = [length (mems s) ..< (length (mems s) + length (m_mems m))] in\n    let i_gs = [length (globs s) ..< (length (globs s) + min (length (m_globs m)) (length gvs))] in\n    let inst = \\<lparr>types=(m_types m),\n                funcs=(ext_funcs imps)@i_fs,\n                tabs=(ext_tabs imps)@i_ts,\n                mems=(ext_mems imps)@i_ms,\n                globs=(ext_globs imps)@i_gs\\<rparr> in\n    let (s1,_) = alloc_funcs s (m_funcs m) inst in\n    let (s2,_) = alloc_tabs s1 (m_tabs m) in\n    let (s3,_) = alloc_mems s2 (m_mems m) in\n    let (s',_) = alloc_globs s3 (m_globs m) gvs in\n    let exps = map (\\<lambda>m_exp. \\<lparr>E_name=(E_name m_exp), E_desc=(export_get_v_ext inst (E_desc m_exp))\\<rparr>) (m_exports m) in\n    (s', inst, exps))\"\n\nlemma alloc_module_imp_interp_alloc_module:\n  assumes \"alloc_module s m imps gvs (s',inst,exps)\"\n  shows \"(interp_alloc_module s m imps gvs = (s',inst,exps))\"\nproof -\n  obtain s1 s2 s3 i_fs i_ts i_ms i_gs where s'_is:\n    \"inst = \\<lparr>types=(m_types m),\n             funcs=(ext_funcs imps)@i_fs,\n             tabs=(ext_tabs imps)@i_ts,\n             mems=(ext_mems imps)@i_ms,\n             globs=(ext_globs imps)@i_gs\\<rparr>\"\n    \"alloc_funcs s (m_funcs m) inst = (s1,i_fs)\"\n    \"alloc_tabs s1 (m_tabs m) = (s2,i_ts)\"\n    \"alloc_mems s2 (m_mems m) = (s3,i_ms)\"\n    \"alloc_globs s3 (m_globs m) gvs = (s',i_gs)\"\n    \"exps = map (\\<lambda>m_exp. \\<lparr>E_name=(E_name m_exp), E_desc=(export_get_v_ext inst (E_desc m_exp))\\<rparr>) (m_exports m)\"\n    using assms\n    unfolding alloc_module.simps\n    by blast\n  have \"i_fs = [length (funcs s) ..< (length (funcs s) + length (m_funcs m))]\"\n       \"i_ts = [length (tabs s) ..< (length (tabs s) + length (m_tabs m))]\"\n       \"i_ms = [length (mems s) ..< (length (mems s) + length (m_mems m))]\"\n       \"i_gs = [length (globs s) ..< (length (globs s) + min (length (m_globs m)) (length gvs))]\"\n    using alloc_funcs_range[OF s'_is(2)] alloc_tabs_range[OF s'_is(3)]\n          alloc_mems_range[OF s'_is(4)] alloc_globs_range[OF s'_is(5)]\n    by auto\n  thus ?thesis\n    using s'_is\n    unfolding interp_alloc_module_def\n    by (simp add: Let_def split: prod.splits)\nqed\n\nlemma interp_alloc_module_imp_alloc_module:\n  assumes \"(interp_alloc_module s m imps gvs = (s',inst,exps))\"\n  shows \"alloc_module s m imps gvs (s',inst,exps)\"\nproof -\n  obtain i_fs i_ts i_ms i_gs i_fs' i_ts' i_ms' i_gs' s1 s2 s3 where s'_is:\n    \"i_fs = [length (funcs s) ..< (length (funcs s) + length (m_funcs m))]\"\n    \"i_ts = [length (tabs s) ..< (length (tabs s) + length (m_tabs m))]\"\n    \"i_ms = [length (mems s) ..< (length (mems s) + length (m_mems m))]\"\n    \"i_gs = [length (globs s) ..< (length (globs s) + min (length (m_globs m)) (length gvs))]\"\n    \"inst = \\<lparr>types=(m_types m),\n                funcs=(ext_funcs imps)@i_fs,\n                tabs=(ext_tabs imps)@i_ts,\n                mems=(ext_mems imps)@i_ms,\n                globs=(ext_globs imps)@i_gs\\<rparr>\"\n    \"(s1,i_fs') = alloc_funcs s (m_funcs m) inst\"\n    \"(s2,i_ts') = alloc_tabs s1 (m_tabs m)\"\n    \"(s3,i_ms') = alloc_mems s2 (m_mems m)\"\n    \"(s',i_gs') = alloc_globs s3 (m_globs m) gvs\"\n    \"exps = map (\\<lambda>m_exp. \\<lparr>E_name=(E_name m_exp), E_desc=(export_get_v_ext inst (E_desc m_exp))\\<rparr>) (m_exports m)\"\n    using assms\n    unfolding interp_alloc_module_def\n    by (auto simp add: Let_def split: prod.splits)\n  have \"i_fs = i_fs'\"\n       \"i_ts = i_ts'\"\n       \"i_ms = i_ms'\"\n       \"i_gs = i_gs'\"\n    using s'_is(1,2,3,4)\n          alloc_funcs_range[OF s'_is(6)[symmetric]]\n          alloc_tabs_range[OF s'_is(7)[symmetric]]\n          alloc_mems_range[OF s'_is(8)[symmetric]]\n          alloc_globs_range[OF s'_is(9)[symmetric]]\n    by metis+\n  thus ?thesis\n    using alloc_module.intros[OF s'_is(5) _ _ _ _ s'_is(10)]\n    by (metis (no_types, lifting) s'_is(6,7,8,9))\nqed\n\nlemma alloc_module_equiv_interp_alloc_module:\n  \"alloc_module s m imps gvs (s',inst,exps) = (interp_alloc_module s m imps gvs = (s',inst,exps))\"\n  using alloc_module_imp_interp_alloc_module interp_alloc_module_imp_alloc_module\n  by blast\n\ndefinition init_tab :: \"s \\<Rightarrow> inst \\<Rightarrow> nat \\<Rightarrow> module_elem \\<Rightarrow> s\" where\n  \"init_tab s inst e_ind e = (let t_ind = ((inst.tabs inst)!(e_tab e)) in\n                               let (tab_e,max) = (tabs s)!t_ind in\n                               let e_pay = map (\\<lambda>i. Some ((inst.funcs inst)!i)) (e_init e) in\n                               let tab'_e = ((take e_ind tab_e) @ e_pay @ (drop (e_ind + length e_pay) tab_e)) in\n                               s\\<lparr>tabs := (tabs s)[t_ind := (tab'_e,max)]\\<rparr>)\"\n\ndefinition init_tabs :: \"s \\<Rightarrow> inst \\<Rightarrow> nat list \\<Rightarrow> module_elem list \\<Rightarrow> s\" where\n  \"init_tabs s inst e_inds es = foldl (\\<lambda>s' (e_ind,e). init_tab s' inst e_ind e) s (zip e_inds es)\"\n\ndefinition init_mem :: \"s \\<Rightarrow> inst \\<Rightarrow> nat \\<Rightarrow> module_data \\<Rightarrow> s\" where\n  \"init_mem s inst d_ind d = (let m_ind = ((inst.mems inst)!(d_data d)) in\n                               let mem = (mems s)!m_ind in\n                               let mem' = write_bytes mem d_ind (d_init d) in\n                               s\\<lparr>mems := (mems s)[m_ind := mem']\\<rparr>)\"\n\ndefinition init_mems :: \"s \\<Rightarrow> inst \\<Rightarrow> nat list \\<Rightarrow> module_data list \\<Rightarrow> s\" where\n  \"init_mems s inst d_inds ds = foldl (\\<lambda>s' (d_ind,d). init_mem s' inst d_ind d) s (zip d_inds ds)\"\n\ninductive instantiate :: \"s \\<Rightarrow> m \\<Rightarrow> v_ext list \\<Rightarrow> ((s \\<times> inst \\<times> (module_export list)) \\<times> (nat option)) \\<Rightarrow> bool\" where\n  \"\\<lbrakk>module_typing m t_imps t_exps;\n    list_all2 (external_typing s) v_imps t_imps;\n    alloc_module s m v_imps g_inits (s', inst, v_exps);\n    f = \\<lparr> f_locs = [], f_inst = inst \\<rparr>;\n    list_all2 (\\<lambda>g v. reduce_trans (s',f,$*(g_init g)) (s',f,[$C v])) (m_globs m) g_inits;\n    list_all2 (\\<lambda>e c. reduce_trans (s',f,$*(e_off e)) (s',f,[$C ConstInt32 c])) (m_elem m) e_offs;\n    list_all2 (\\<lambda>d c. reduce_trans (s',f,$*(d_off d)) (s',f,[$C ConstInt32 c])) (m_data m) d_offs;\n    list_all2 (\\<lambda>e_off e. ((nat_of_int e_off) + (length (e_init e))) \\<le> length (fst ((tabs s')!((inst.tabs inst)!(e_tab e))))) e_offs (m_elem m);\n    list_all2 (\\<lambda>d_off d. ((nat_of_int d_off) + (length (d_init d))) \\<le> mem_length ((mems s')!((inst.mems inst)!(d_data d)))) d_offs (m_data m);\n    map_option (\\<lambda>i_s. ((inst.funcs inst)!i_s)) (m_start m) = start;\n    init_tabs s' inst (map nat_of_int e_offs) (m_elem m) = s'';\n    init_mems s'' inst (map nat_of_int d_offs) (m_data m) = s_end\n    \\<rbrakk> \\<Longrightarrow> instantiate s m v_imps ((s_end, inst, v_exps), start)\"\n\ndefinition interp_get_v :: \"s \\<Rightarrow> inst \\<Rightarrow> b_e list \\<Rightarrow> v\" where\n  \"interp_get_v s inst b_es = \n     (case run_v 2 0 (s,\\<lparr> f_locs = [], f_inst = inst \\<rparr>,b_es) of\n        (_,RValue [v]) \\<Rightarrow> v)\"\n\ndefinition interp_get_i32 :: \"s \\<Rightarrow> inst \\<Rightarrow> b_e list \\<Rightarrow> i32\" where\n  \"interp_get_i32 s inst b_es = \n     (case interp_get_v s inst b_es of\n        ConstInt32 c \\<Rightarrow> c\n      | _ \\<Rightarrow> 0)\"\n\nfun interp_instantiate :: \"s \\<Rightarrow> m \\<Rightarrow> v_ext list \\<Rightarrow> ((s \\<times> inst \\<times> (module_export list)) \\<times> (nat option)) option\" where\n  \"interp_instantiate s m v_imps =\n     (case (module_type_checker m) of\n        Some (t_imps, t_exps) \\<Rightarrow>\n          if (list_all2 (external_typing s) v_imps t_imps) then\n            let g_inits = \n              map (\\<lambda>g. interp_get_v s \\<lparr>types=[],funcs=[],tabs=[],mems=[],globs=ext_globs v_imps\\<rparr> (g_init g)) (m_globs m) in\n            let (s', inst, v_exps) = interp_alloc_module s m v_imps g_inits in\n            let e_offs = map (\\<lambda>e. interp_get_i32 s' inst (e_off e)) (m_elem m) in\n            let d_offs = map (\\<lambda>d. interp_get_i32 s' inst (d_off d)) (m_data m) in\n            if (list_all2 (\\<lambda>e_off e. ((nat_of_int e_off) + (length (e_init e))) \\<le> length (fst ((tabs s')!((inst.tabs inst)!(e_tab e))))) e_offs (m_elem m) \\<and>\n                list_all2 (\\<lambda>d_off d. ((nat_of_int d_off) + (length (d_init d))) \\<le> mem_length ((mems s')!((inst.mems inst)!(d_data d)))) d_offs (m_data m)) then\n              let start = map_option (\\<lambda>i_s. ((inst.funcs inst)!i_s)) (m_start m) in\n              let s'' = init_tabs s' inst (map nat_of_int e_offs) (m_elem m) in\n              let s_end = init_mems s'' inst (map nat_of_int d_offs) (m_data m) in\n              Some ((s_end, inst, v_exps), start)\n            else None\n          else None\n      | _ \\<Rightarrow> None)\"\n\nlemma const_expr_is:\n  assumes \"const_expr \\<C> b_e\"\n          \"\\<C> \\<turnstile> [b_e] : (ts _> ts')\"\n        shows \"\\<exists>t. (\\<C> \\<turnstile> [b_e] : ([] _> [t])) \\<and> ts' = ts@[t] \\<and> \n         ((\\<exists>v. b_e = (C v) \\<and> typeof v = t) \\<or>\n         (\\<exists>j. b_e = (Get_global j) \\<and> j < length (global \\<C>) \\<and>\n              tg_mut ((global \\<C>)!j) = T_immut \\<and>\n              tg_t ((global \\<C>)!j) = t))\"\n  using assms(2,1)\nproof (induction \"\\<C>\" \"[b_e]\" \"(ts _> ts')\" arbitrary: ts ts' rule: b_e_typing.induct)\n  case (const \\<C> v)\n  thus ?case\n    using b_e_typing.const\n    by blast\nnext\n  case (get_global i \\<C> t)\n  thus ?case\n    using b_e_typing.get_global const_expr.cases\n    by fastforce\nnext\n  case (weakening \\<C> t1s t2s ts)\n  thus ?case\n    by simp\nqed (auto simp add: const_expr.simps)\n\nlemma const_exprs_empty:\n  assumes \"const_exprs \\<C> b_es\"\n          \"\\<C> \\<turnstile> b_es : ([] _> [])\"\n  shows \"b_es = []\"\n  using assms(2,1)\nproof (induction \"([] _> [])\" rule: b_e_typing.induct)\n  case (composition \\<C> es t2s e)\n  thus ?case\n    by (metis (no_types, lifting) Nil_is_append_conv const_expr_is list.pred_inject(2) list_all_append)\nnext\n  case (weakening \\<C> es t1s t2s ts)\n  thus ?case\n    by blast\nqed (auto simp add: const_expr.simps)\n\nlemma const_exprs_is:\n  assumes \"const_exprs \\<C> b_es\"\n          \"\\<C> \\<turnstile> b_es : ([] _> [t])\"\n  shows \"(\\<exists>v. b_es = [C v] \\<and> typeof v = t) \\<or>\n         (\\<exists>j. b_es = [Get_global j] \\<and> j < length (global \\<C>) \\<and>\n              tg_mut ((global \\<C>)!j) = T_immut \\<and>\n              tg_t ((global \\<C>)!j) = t)\"\n  using assms(2,1)\nproof (induction \"\\<C>\" \"b_es\" \"([] _> [t])\" rule: b_e_typing.induct)\n  case (composition \\<C> es t2s e)\n  have 1:\"const_exprs \\<C> es\" \"const_expr \\<C> e\"\n    using composition(5)\n    by simp_all\n  have \"t2s = []\" \"es = []\"\n    using const_expr_is[OF 1(2) composition(3)]  composition(1) const_exprs_empty 1(1)\n    by auto\n  thus ?case\n    using composition\n    by simp\nqed (auto simp add: const_expr.simps)\n\nlemma const_exprs_run_v:\n  assumes \"const_exprs \\<C> b_es\"\n          \"\\<C> \\<turnstile> b_es : ([] _> [t])\"\n          \"global \\<C> = tgs\"\n          \"list_all2 (\\<lambda>ig tg. external_typing s (Ext_glob ig) (Te_glob tg)) igs tgs\"\n          \"inst.globs inst = igs@arb\"\n  shows \"\\<exists>v. typeof v = t \\<and> run_v 2 0 (s, \\<lparr> f_locs=[], f_inst=inst \\<rparr>,b_es) = (s, RValue [v])\"\nproof -\n  consider (1) v where \"b_es = [C v] \\<and> typeof v = t\"\n         | (2) j where \"b_es = [Get_global j]\"\n                       \"j < length (global \\<C>)\"\n                       \"tg_mut (global \\<C> ! j) = T_immut\"\n                       \"tg_t (global \\<C> ! j) = t\"\n    using const_exprs_is[OF assms(1,2)]\n    by blast\n  thus ?thesis\n  proof cases\n    case 1\n    thus ?thesis\n      by (auto simp add: const_list_def is_const_def Suc_1[symmetric])\n  next\n    case 2\n    thus ?thesis\n      using assms\n      unfolding list_all2_conv_all_nth external_typing.simps\n      by (auto simp add: const_list_def is_const_def Suc_1[symmetric] glob_typing_def nth_append sglob_def sglob_ind_def sglob_val_def app_s_f_v_s_get_global_def)\n  qed\nqed\n\nlemma const_exprs_reduce_trans:\n  assumes \"const_exprs \\<C> b_es\"\n          \"\\<C> \\<turnstile> b_es : ([] _> [t])\"\n          \"reduce_trans (s_r,f,$*b_es) (s',f',[$C v])\"\n          \"global \\<C> = tgs\"\n          \"list_all2 (\\<lambda>ig tg. external_typing s (Ext_glob ig) (Te_glob tg)) igs tgs\"\n          \"globs s_r = (globs s)@arbg1\"\n          \"globs s_v = (globs s)@arbg2\"\n          \"inst.globs (f_inst f) = igs@arbi1\"\n          \"inst.globs inst_v = igs@arbi2\"\n  shows \"s_r = s' \\<and> f = f' \\<and> typeof v = t \\<and> run_v 2 0 (s_v,\\<lparr> f_locs=vs_arb, f_inst=inst_v\\<rparr>,b_es) = (s_v, RValue [v])\"\nproof -\n  consider (1) v_r where \"b_es = [C v_r] \\<and> typeof v_r = t\"\n         | (2) j where \"b_es = [Get_global j]\"\n                       \"j < length (global \\<C>)\"\n                       \"tg_mut (global \\<C> ! j) = T_immut\"\n                       \"tg_t (global \\<C> ! j) = t\"\n    using const_exprs_is[OF assms(1,2)]\n    by blast\n  thus ?thesis\n  proof (cases)\n    case 1\n    thus ?thesis\n      using assms(3) reduce_trans_consts\n      apply (simp add: const_list_def is_const_def Suc_1[symmetric])\n      apply (metis (mono_tags, lifting) append_Nil2 case_prod_conv list.inject split_vals_e.simps(1,2) split_vals_e_conv_app)\n      done\n  next\n    case 2\n    have type_is:\"typeof (sglob_val s (f_inst f) j) = t\" \"j < length igs\" \"(igs!j) < length (globs s)\"\n      using assms(4,5,6,8) 2(2,3,4)\n      unfolding list_all2_conv_all_nth external_typing.simps\n      by (simp_all add: glob_typing_def nth_append sglob_def sglob_ind_def sglob_val_def)\n    show ?thesis\n      using assms(3)\n      unfolding reduce_trans_def\n    proof (cases rule: converse_rtranclpE)\n      case base\n      thus ?thesis\n        using 2(1)\n        by auto\n    next\n      case (step y)\n      then obtain s_y f_y es_y where y_is:\"\\<lparr>s_r;f;[$Get_global j]\\<rparr> \\<leadsto> \\<lparr>s_y;f_y;es_y\\<rparr>\" \"y = (s_y, f_y, es_y)\"\n        using 2\n        by fastforce\n      hence s_y_is:\"s_y = s_r \\<and> f_y = f \\<and> es_y = [$C sglob_val s (f_inst f) j]\"\n        using assms(6,8)\n      proof (induction s_r f \"[$Get_global j]\" s_y f_y es_y arbitrary: y rule: reduce.induct)\n        case (basic e' s vs i)\n        thus ?case\n          using lfilled_single\n          apply cases\n          apply auto\n          done\n      next\n        case (get_global s vs i)\n        thus ?case\n          using type_is(2,3)\n          by (simp_all add: sglob_def sglob_ind_def sglob_val_def nth_append)\n      next\n        case (label s vs es i s' vs' es' k lholed les')\n        thus ?case\n          using lfilled_single[OF label(3)]\n          by (metis Lfilled_exact.L0 Lfilled_exact_imp_Lfilled e.distinct(5) lfilled_eq reduce_not_nil)\n      qed auto\n      thus ?thesis\n        using step(2) y_is reduce_trans_consts[of s_y f_y \"[sglob_val s (f_inst f) j]\" s' f' \"[v]\"] 2 type_is\n        apply (simp add: assms nth_append sglob_def sglob_ind_def sglob_val_def reduce_trans_def const_list_def is_const_def Suc_1[symmetric] app_s_f_v_s_get_global_def split: prod.splits)\n        using s_y_is type_is(1)\n        apply blast\n        done\n    qed\n  qed\nqed\n\nlemma ext_globs_ind:\n  assumes \"i<length (ext_globs v_imps)\"\n  shows \"\\<exists>j. j < length v_imps \\<and> Ext_glob ((ext_globs v_imps) ! i) = v_imps!j\"\n  using assms\nproof (induction v_imps arbitrary: i)\ncase Nil\n  thus ?case\n    by (simp add: map_filter_simps(2))\nnext\n  case (Cons v_imp v_imps)\n  consider (1) k where \"v_imp = Ext_glob k\" | (2) \"\\<And>k. v_imp \\<noteq> Ext_glob k\"\n    by blast\n  thus ?case\n  proof (cases)\n    case 1\n    show ?thesis\n    proof (cases i)\n      case 0\n      thus ?thesis\n        using 1\n        by (auto simp add: map_filter_def)\n    next\n      case (Suc i')\n      hence Suc1:\"i' < length (ext_globs (v_imps))\"\n        using 1 Cons(2)\n        by (simp add: map_filter_def)\n      thus ?thesis\n        using Cons(1)[OF Suc1] Suc 1\n        by (auto simp add: map_filter_def)\n    qed\n  next\n    case 2\n    hence a2:\"ext_globs v_imps = ext_globs (v_imp#v_imps)\"\n      apply (cases v_imp)\n      apply (simp_all add: map_filter_def)\n      done\n    hence b2:\"i < length (ext_globs (v_imps))\"\n      using Cons(2)\n      by simp\n    thus ?thesis\n      using Cons(1)[OF b2] a2\n      by auto\n  qed\nqed\n\nlemma alloc_glob_ext_typing:\n  assumes \"alloc_glob s (m_g, v) = (s', i_g)\"\n          \"typeof v = (tg_t (g_type m_g))\"\n  shows \"external_typing s' (Ext_glob i_g) (Te_glob (g_type m_g))\"\n  using assms alloc_glob_length[OF assms(1)]\n  unfolding alloc_glob_def external_typing.simps glob_typing_def\n  apply simp\n  apply (metis global.select_convs(1) global.select_convs(2) nth_append_length)\n  done\n\nlemma alloc_globs_ext_typing:\n  assumes \"alloc_globs s m_gs vs = (s', i_gs)\"\n          \"list_all2 (\\<lambda>v m_g. typeof v = (tg_t (g_type m_g))) vs m_gs\"\n  shows \"list_all2 (\\<lambda>ig tg. external_typing s' (Ext_glob ig) (Te_glob tg)) i_gs (map g_type m_gs)\"\n  using assms(2,1)\nproof (induction arbitrary: s i_gs rule: list_all2_induct)\ncase Nil\n  thus ?case\n    by simp\nnext\n  case (Cons x xs y ys)\n  obtain i_g i_gs' s'' where i_gs_is:\"i_gs = i_g#i_gs'\"\n                                     \"alloc_glob s (y,x) = (s'', i_g)\"\n                                     \"alloc_globs s'' ys xs = (s', i_gs')\"\n    using Cons(4)\n    by (fastforce split: prod.splits)\n  have \"external_typing s' (Ext_glob i_g) (Te_glob (g_type y))\"\n    using alloc_glob_ext_typing[OF i_gs_is(2) Cons(1)] alloc_globs_range[OF i_gs_is(3)] list_all2_lengthD[OF Cons(2)]\n          nth_append[of \"s.globs s''\"]\n    unfolding external_typing.simps\n    apply simp\n    apply (metis length_append trans_less_add1)\n    done\n  thus ?case\n    using alloc_glob_ext_typing[OF i_gs_is(2) Cons(1)] Cons(3)[OF i_gs_is(3)] i_gs_is(1)\n    by (simp split: prod.splits)\nqed\n\nlemma list_all2_external_typing_glob_alloc:\n  assumes \"list_all2 (\\<lambda>i t. external_typing s i t) v_imps t_imps\"\n  shows \"list_all2 (\\<lambda>ig tg. external_typing s (Ext_glob ig) (Te_glob tg)) (ext_globs v_imps) (ext_t_globs t_imps)\"\n  using assms\nproof (induction t_imps rule: list_all2_induct)\n  case Nil\n  thus ?case\n    by (simp add: map_filter_simps(2))\nnext\n  case (Cons x xs y ys)\n  thus ?case\n  proof (cases rule: external_typing.cases)\n    case (4 i gt)\n    thus ?thesis\n      using Cons\n      by (simp add: map_filter_def)\n  qed (fastforce simp add: map_filter_def)+\nqed\n\nlemma alloc_module_ext_arb:\n  assumes \"alloc_module s m imps gvs (s',inst,exps)\"\n  shows \"\\<exists>farbs tarbs marbs garbs.\n           (funcs s)@farbs = funcs s' \\<and>\n           (tabs s)@tarbs = tabs s' \\<and>\n           (mems s)@marbs = mems s' \\<and>\n           (globs s)@garbs = globs s'\"\nproof -\n  obtain s1 s2 s3 i_fs i_ts i_ms i_gs where inst_is:\n    \"inst = \\<lparr>types=(m_types m),\n           funcs=(ext_funcs imps)@i_fs,\n           tabs=(ext_tabs imps)@i_ts,\n           mems=(ext_mems imps)@i_ms,\n           globs=(ext_globs imps)@i_gs\\<rparr>\"\n    \"alloc_funcs s (m_funcs m) inst = (s1,i_fs)\"\n    \"alloc_tabs s1 (m_tabs m) = (s2,i_ts)\"\n    \"alloc_mems s2 (m_mems m) = (s3,i_ms)\"\n    \"alloc_globs s3 (m_globs m) gvs = (s',i_gs)\"\n    \"exps = map (\\<lambda>m_exp. \\<lparr>E_name=(E_name m_exp), E_desc=(export_get_v_ext inst (E_desc m_exp))\\<rparr>) (m_exports m)\"\n    using assms(1)\n    unfolding alloc_module.simps\n    by blast\n  show ?thesis\n    using alloc_funcs_range[OF inst_is(2)]\n          alloc_tabs_range[OF inst_is(3)]\n          alloc_mems_range[OF inst_is(4)]\n          alloc_globs_range[OF inst_is(5)]\n    by fastforce\nqed\n\nlemma alloc_module_external_typing_preserved:\n  assumes \"alloc_module s m imps gvs (s',inst,exps)\"\n          \"external_typing s v_imp t_imp\"\n  shows \"external_typing s' v_imp t_imp\"\n  using assms(2,1)\nproof (cases rule: external_typing.cases)\n  case (1 i tf)\n  thus ?thesis\n    using alloc_module_ext_arb[OF assms(1)]\n    by (metis add.commute external_typing.intros(1) length_append nth_append trans_less_add2)\nnext\n  case (2 i tt)\n  thus ?thesis\n    using alloc_module_ext_arb[OF assms(1)]\n    by (metis external_typing.intros(2) length_append nth_append trans_less_add1)\nnext\n  case (3 i mt)\n  thus ?thesis\n    using alloc_module_ext_arb[OF assms(1)]\n    by (metis external_typing.intros(3) length_append nth_append trans_less_add1)\nnext\n  case (4 i gt)\n  thus ?thesis\n    using alloc_module_ext_arb[OF assms(1)]\n    by (metis external_typing.intros(4) length_append nth_append trans_less_add1)\nqed\n\nlemma g_init_type_interp:\n  assumes \"interp_get_v s inst (g_init m_g) = gv\"\n          \"(module_glob_typing \\<C>) m_g gt\"\n          \"global \\<C> = tgs\"\n          \"list_all2 (\\<lambda>ig tg. external_typing s (Ext_glob ig) (Te_glob tg)) igs tgs\"\n          \"inst.globs inst = igs@arb\"\n  shows \"typeof gv = tg_t (g_type m_g)\"\nproof -\n  have 1:\"const_exprs \\<C> (g_init m_g)\"\n    using assms(2)\n    unfolding module_glob_typing.simps\n    by fastforce\n  have 2:\"\\<C> \\<turnstile> (g_init m_g) : ([] _> [tg_t (g_type m_g)])\"\n    using assms(2)\n    unfolding module_glob_typing.simps\n    by fastforce\n  show ?thesis\n    using const_exprs_run_v[OF 1 2 assms(3,4,5)] assms(1)\n    unfolding interp_get_v_def\n    by (simp split: prod.splits)\nqed\n\nlemma interp_instantiate_imp_instantiate:\n  assumes \"(interp_instantiate s m v_imps = Some ((s_end, inst, v_exps), start))\"\n  shows \"(instantiate s m v_imps ((s_end, inst, v_exps), start))\"\nproof -\n  obtain t_imps t_exps g_inits s' e_offs d_offs s'' inst' where s_end_is:\n    \"module_type_checker m = Some (t_imps, t_exps)\"\n    \"(list_all2 (external_typing s) v_imps t_imps)\"\n    \"g_inits = map (\\<lambda>g. interp_get_v s inst' (g_init g)) (m_globs m)\"\n    \"(s', inst, v_exps) = interp_alloc_module s m v_imps g_inits\"\n    \"e_offs = map (\\<lambda>e. interp_get_i32 s' inst (e_off e)) (m_elem m)\"\n    \"d_offs = map (\\<lambda>d. interp_get_i32 s' inst (d_off d)) (m_data m)\"\n    \"list_all2 (\\<lambda>e_off e. ((nat_of_int e_off) + (length (e_init e))) \\<le> length (fst ((tabs s')!((inst.tabs inst)!(e_tab e))))) e_offs (m_elem m)\"\n    \"list_all2 (\\<lambda>d_off d. ((nat_of_int d_off) + (length (d_init d))) \\<le> mem_length ((mems s')!((inst.mems inst)!(d_data d)))) d_offs (m_data m)\"\n    \"start = map_option (\\<lambda>i_s. ((inst.funcs inst)!i_s)) (m_start m)\"\n    \"s'' = init_tabs s' inst (map nat_of_int e_offs) (m_elem m)\"\n    \"s_end = init_mems s'' inst (map nat_of_int d_offs) (m_data m)\"\n    \"inst' = \\<lparr>types=[],funcs=[],tabs=[],mems=[],globs=ext_globs v_imps\\<rparr>\"\n    using assms\n    by (fastforce simp add: Let_def split: if_splits option.splits prod.splits)\n\n  have 1:\"module_typing m t_imps t_exps\"\n    using s_end_is(1) module_type_checker_imp_module_typing\n    by blast\n  have 2:\"alloc_module s m v_imps g_inits (s', inst, v_exps)\"\n    using s_end_is(4) interp_alloc_module_imp_alloc_module\n    by metis\n\n  obtain fs fts ts ms gs gts els ds i_opt imps exps tfs ifts itts imts igts \\<C> \\<C>' where m_is:\n    \"list_all2 (module_func_typing \\<C>) fs fts\"\n    \"list_all (module_tab_typing) ts\"\n    \"list_all (module_mem_typing) ms\"\n    \"list_all2 (module_glob_typing \\<C>') gs gts\"\n    \"list_all (module_elem_typing \\<C>) els\"\n    \"list_all (module_data_typing \\<C>) ds\"\n    \"pred_option (module_start_typing \\<C>) i_opt\"\n    \"list_all2 (\\<lambda>imp. module_import_typing \\<C> (I_desc imp)) imps t_imps\"\n    \"list_all2 (\\<lambda>exp. module_export_typing \\<C> (E_desc exp)) exps t_exps\"\n    \"ifts = ext_t_funcs t_imps\"\n    \"itts = ext_t_tabs t_imps\"\n    \"imts = ext_t_mems t_imps\"\n    \"igts = ext_t_globs t_imps\"\n    \"\\<C> = \\<lparr>types_t=tfs, func_t=ifts@fts, global=igts@gts, table=itts@ts, memory=imts@ms, local=[], label=[], return=None\\<rparr>\"\n    \"\\<C>' = \\<lparr>types_t=[], func_t=[], global=igts, table=[], memory=[], local=[], label=[], return=None\\<rparr>\"\n    \"m = \\<lparr>m_types = tfs,\n          m_funcs = fs,\n          m_tabs = ts,\n          m_mems = ms,\n          m_globs = gs,\n          m_elem = els,\n          m_data = ds,\n          m_start = i_opt,\n          m_imports = imps,\n          m_exports = exps\\<rparr>\"\n    using 1\n    unfolding module_typing.simps\n    by blast\n\n  obtain s1 s2 s3 i_fs i_ts i_ms i_gs where inst_is:\n    \"inst = \\<lparr>types=(m_types m),\n           funcs=(ext_funcs v_imps)@i_fs,\n           tabs=(ext_tabs v_imps)@i_ts,\n           mems=(ext_mems v_imps)@i_ms,\n           globs=(ext_globs v_imps)@i_gs\\<rparr>\"\n    \"alloc_funcs s (m_funcs m) inst = (s1,i_fs)\"\n    \"alloc_tabs s1 (m_tabs m) = (s2,i_ts)\"\n    \"alloc_mems s2 (m_mems m) = (s3,i_ms)\"\n    \"alloc_globs s3 (m_globs m) g_inits = (s',i_gs)\"\n    \"v_exps = map (\\<lambda>m_exp. \\<lparr>E_name=(E_name m_exp), E_desc=(export_get_v_ext inst (E_desc m_exp))\\<rparr>) (m_exports m)\"\n    using 2\n    unfolding alloc_module.simps\n    by blast\n\n  have 12:\"list_all2 (\\<lambda>ig tg. external_typing s (Ext_glob ig) (Te_glob tg)) (inst.globs inst') (global \\<C>')\"\n    using s_end_is(2,12) m_is(13,15) ext_globs_ind list_all2_external_typing_glob_alloc\n    by simp\n  have 11:\"list_all2 (\\<lambda>ig tg. external_typing s' (Ext_glob ig) (Te_glob tg)) (inst.globs inst) (global \\<C>)\"\n  proof -\n    have \"list_all2 (\\<lambda>ig tg. external_typing s' (Ext_glob ig) (Te_glob tg)) (inst.globs inst') (global \\<C>')\"\n      using alloc_module_external_typing_preserved[OF 2] 12\n      unfolding list_all2_conv_all_nth\n      by fastforce\n    moreover\n    have 111:\"list_all2 (\\<lambda>v m_g. typeof v = tg_t (g_type m_g)) g_inits (m_globs m)\"\n      using s_end_is(3)[symmetric] g_init_type_interp[OF _ _ _ 12, of inst' _ _ \\<C>' _ \"[]\"] m_is(4,16)\n      by (auto simp add: list_all2_conv_all_nth)\n    have \"(gather_m_g_types (m_globs m)) = gts\"\n      using m_is(4,16)\n      unfolding list_all2_conv_all_nth module_glob_typing.simps\n      apply simp\n      apply (metis length_map module_glob.select_convs(1) nth_equalityI nth_map)\n      done\n    hence \"list_all2 (\\<lambda>ig tg. external_typing s' (Ext_glob ig) (Te_glob tg)) i_gs gts\"\n      using alloc_globs_ext_typing[OF inst_is(5) 111]\n      by blast\n    ultimately\n    show ?thesis\n      using list_all2_appendI\n      by (fastforce simp add: m_is(14,15) inst_is(1) s_end_is(12))\n  qed\n\n  have 3:\"list_all2 (\\<lambda>g v. reduce_trans (s',\\<lparr> f_locs=[], f_inst=inst \\<rparr>,$*(g_init g)) (s',\\<lparr> f_locs=[], f_inst=inst \\<rparr>,[$C v])) (m_globs m) g_inits\"\n  proof -\n    { fix i\n      assume local_assms:\"length (m_globs m) = length g_inits\" \"i<length (m_globs m)\"\n      hence l1:\"const_exprs \\<C>' (g_init (m_globs m ! i))\"\n        using m_is(4,16)\n        unfolding list_all2_conv_all_nth module_glob_typing.simps\n        by auto\n      obtain t where l2:\"\\<C>' \\<turnstile> (g_init (m_globs m ! i)) : ([] _> [t])\"\n        using local_assms m_is(4,16)\n        unfolding list_all2_conv_all_nth module_glob_typing.simps\n        by auto\n      obtain v_r where \"run_v 2 0 (s, \\<lparr> f_locs=[], f_inst=inst' \\<rparr>, (g_init (m_globs m ! i))) =  (s, RValue [v_r])\"\n        using const_exprs_run_v[OF l1 l2 _ 12, of inst']\n        by auto\n      hence a_runv:\"run_v 2 0 (s,\\<lparr> f_locs=[], f_inst=inst'\\<rparr>,(g_init ((m_globs m)!i))) = (s,RValue [(g_inits!i)])\"\n        using s_end_is(3) local_assms\n        by (simp add: interp_get_v_def split: v.splits)\n      obtain f_temp where f_temp_is:\n        \"reduce_trans (s, \\<lparr>f_locs = [], f_inst = inst'\\<rparr>, $* g_init (m_globs m ! i)) (s, f_temp, $C* [g_inits ! i])\"\n        using run_v_sound[OF a_runv]\n        by fastforce\n      hence l3:\"reduce_trans (s,\\<lparr> f_locs=[], f_inst=inst' \\<rparr>,$*(g_init ((m_globs m)!i))) (s,\\<lparr> f_locs=[], f_inst=inst' \\<rparr>,[$C (g_inits!i)])\"\n        using reduce_trans_length_locals[OF f_temp_is] reduce_trans_inst_is[OF f_temp_is]\n        apply simp\n        apply (metis (full_types) f.surjective unit.exhaust)\n        done\n      obtain arbg arbi where arbgi:\"(globs s)@arbg = (globs s')\"\n                                   \"inst.globs inst = inst.globs inst' @ arbi\"\n        using alloc_module_ext_arb[OF 2] 2 s_end_is(12)\n        unfolding alloc_module.simps\n        by auto\n      have run_v_is:\"run_v 2 0 (s', \\<lparr> f_locs=[], f_inst=inst \\<rparr>, g_init (m_globs m ! i)) = (s', RValue [g_inits ! i])\"\n        using const_exprs_reduce_trans[OF l1 l2 l3] _ 12 _ arbgi(1)[symmetric] _ arbgi(2)\n        by fastforce\n      obtain f_temp where  \"reduce_trans (s',\\<lparr> f_locs=[], f_inst=inst \\<rparr>,$*(g_init ((m_globs m)!i))) (s',f_temp,[$C (g_inits!i)])\"\n        using run_v_sound[OF run_v_is]\n        by auto\n      hence \"reduce_trans (s',\\<lparr> f_locs=[], f_inst=inst \\<rparr>,$*(g_init ((m_globs m)!i))) (s',\\<lparr> f_locs=[], f_inst=inst \\<rparr>,[$C (g_inits!i)])\"\n        using reduce_trans_length_locals reduce_trans_inst_is\n        by (metis (full_types) f.select_convs(1) f.surjective length_greater_0_conv unit.exhaust)\n    }\n    thus ?thesis\n      using s_end_is(3)\n      unfolding list_all2_conv_all_nth\n      by fastforce\n  qed\n\n  have 4:\"list_all2 (\\<lambda>e c. reduce_trans (s',\\<lparr> f_locs=[], f_inst=inst \\<rparr>,$*(e_off e)) (s',\\<lparr> f_locs=[], f_inst=inst \\<rparr>,[$C ConstInt32 c])) (m_elem m) e_offs\"\n  proof -\n    { fix i\n      assume local_assms:\"length (m_elem m) = length e_offs\" \"i<length (m_elem m)\"\n      hence l1:\"const_exprs \\<C> (e_off (m_elem m ! i))\"\n        by (metis m_is(5,16) list_all_length m.select_convs(6) module_elem.select_convs(2) module_elem_typing.cases)\n      have l2:\"\\<C> \\<turnstile> (e_off (m_elem m ! i)) : ([] _> [T_i32])\"\n        using local_assms\n        by (metis m_is(5,16) list_all_length m.select_convs(6) module_elem.select_convs(2) module_elem_typing.cases)\n      obtain c_r where \"run_v 2 0 (s', \\<lparr> f_locs=[], f_inst=inst \\<rparr>, e_off (m_elem m ! i)) =  (s', RValue [ConstInt32 c_r])\"\n        using const_exprs_run_v[OF l1 l2 _ 11, of inst \"[]\"] typeof_i32\n        by auto\n      hence run_v_is:\"run_v 2 0 (s', \\<lparr> f_locs=[], f_inst=inst \\<rparr>, e_off (m_elem m ! i)) = (s', RValue [ConstInt32 (e_offs ! i)])\"\n        using s_end_is(5) local_assms\n        by (simp add: interp_get_i32_def interp_get_v_def split: v.splits)\n      obtain f_temp where \"reduce_trans (s', \\<lparr> f_locs=[], f_inst=inst \\<rparr>, $* e_off (m_elem m ! i)) (s', f_temp, [$C ConstInt32 (e_offs ! i)])\"\n        using run_v_sound[OF run_v_is]\n        by auto\n      hence \"reduce_trans (s', \\<lparr> f_locs=[], f_inst=inst \\<rparr>, $* e_off (m_elem m ! i)) (s', \\<lparr> f_locs=[], f_inst=inst \\<rparr>, [$C ConstInt32 (e_offs ! i)])\"\n        using reduce_trans_length_locals reduce_trans_inst_is\n        by (metis (full_types) f.select_convs(1) f.surjective length_greater_0_conv old.unit.exhaust)\n    }\n    thus ?thesis\n      using s_end_is(5)\n      unfolding list_all2_conv_all_nth\n      by fastforce\n  qed\n  have 5:\"list_all2 (\\<lambda>d c. reduce_trans (s',\\<lparr> f_locs=[], f_inst=inst \\<rparr>,$*(d_off d)) (s',\\<lparr> f_locs=[], f_inst=inst \\<rparr>,[$C ConstInt32 c])) (m_data m) d_offs\"\n  proof -\n    { fix i\n      assume local_assms:\"length (m_data m) = length d_offs\" \"i<length (m_data m)\"\n      hence l1:\"const_exprs \\<C> (d_off (m_data m ! i))\"\n        by (metis list_all_length m.select_convs(7) m_is(6,16) module_data.select_convs(2) module_data_typing.simps)\n      have l2:\"\\<C> \\<turnstile> (d_off (m_data m ! i)) : ([] _> [T_i32])\"\n        using local_assms\n        by (metis list_all_length m.select_convs(7) m_is(6,16) module_data.select_convs(2) module_data_typing.simps)\n      obtain c_r where \"run_v 2 0 (s', \\<lparr> f_locs=[], f_inst=inst \\<rparr>, d_off (m_data m ! i)) =  (s', RValue [ConstInt32 c_r])\"\n        using const_exprs_run_v[OF l1 l2 _ 11, of inst \"[]\"] typeof_i32\n        by auto\n      hence run_v_is:\"run_v 2 0 (s', \\<lparr> f_locs=[], f_inst=inst \\<rparr>, d_off (m_data m ! i)) = (s', RValue [ConstInt32 (d_offs ! i)])\"\n        using s_end_is(6) local_assms\n        by (simp add: interp_get_i32_def interp_get_v_def split: v.splits)\n      obtain f_temp where \"reduce_trans (s', \\<lparr> f_locs=[], f_inst=inst \\<rparr>, $* d_off (m_data m ! i)) (s', f_temp, [$C ConstInt32 (d_offs ! i)])\"\n        using run_v_sound[OF run_v_is]\n        by auto\n      hence \"reduce_trans (s', \\<lparr> f_locs=[], f_inst=inst \\<rparr>, $* d_off (m_data m ! i)) (s', \\<lparr> f_locs=[], f_inst=inst \\<rparr>, [$C ConstInt32 (d_offs ! i)])\"\n        using reduce_trans_length_locals reduce_trans_inst_is\n        by (metis (full_types) f.select_convs(1) f.surjective length_greater_0_conv old.unit.exhaust)\n    }\n    thus ?thesis\n      using s_end_is(6)\n      unfolding list_all2_conv_all_nth\n      by fastforce\n   qed\n   show ?thesis\n     using instantiate.intros\n           1 s_end_is(2) 2 3 4 5 s_end_is(7,8) s_end_is(9,10,11)[symmetric]\n      by blast\nqed\n\nlemma map_intro_length:\n  assumes \"\\<And>i. i < length ls \\<Longrightarrow> F (ls!i) = fls!i\"\n          \"length ls = length fls\"\n  shows \"map F ls = fls\"\n  using assms\n  by (metis length_map nth_equalityI nth_map)\n\nlemma instantiate_imp_interp_instantiate:\n  assumes \"(instantiate s m v_imps ((s_end, inst, v_exps), start))\"\n  shows \"(interp_instantiate s m v_imps = Some ((s_end, inst, v_exps), start))\"\nproof -\n  obtain fs ts ms gs els ds i_opt imps exps tfs where m_is:\n    \"m = \\<lparr>m_types = tfs,\n          m_funcs = fs,\n          m_tabs = ts,\n          m_mems = ms,\n          m_globs = gs,\n          m_elem = els,\n          m_data = ds,\n          m_start = i_opt,\n          m_imports = imps,\n          m_exports = exps\\<rparr>\"\n    using m.cases\n    by blast\n  obtain inst' where inst'_is:\n    \"inst' = \\<lparr>types=[],funcs=[],tabs=[],mems=[],globs=ext_globs v_imps\\<rparr>\"\n    using inst.cases\n    by blast\n\n  obtain t_imps t_exps g_inits s' e_offs d_offs s'' f where s_end_is:\n    \"module_typing m t_imps t_exps\"\n    \"list_all2 (external_typing s) v_imps t_imps\"\n    \"alloc_module s m v_imps g_inits (s', inst, v_exps)\"\n    \"list_all2 (\\<lambda>g v. reduce_trans (s',f,$*(g_init g)) (s',f,[$C v])) gs g_inits\"\n    \"list_all2 (\\<lambda>e c. reduce_trans (s',f,$*(e_off e)) (s',f,[$C ConstInt32 c])) els e_offs\"\n    \"list_all2 (\\<lambda>d c. reduce_trans (s',f,$*(d_off d)) (s',f,[$C ConstInt32 c])) ds d_offs\"\n    \"list_all2 (\\<lambda>e_off e. ((nat_of_int e_off) + (length (e_init e))) \\<le> length (fst ((tabs s')!((inst.tabs inst)!(e_tab e))))) e_offs els\"\n    \"list_all2 (\\<lambda>d_off d. ((nat_of_int d_off) + (length (d_init d))) \\<le> mem_length ((mems s')!((inst.mems inst)!(d_data d)))) d_offs ds\"\n    \"map_option (\\<lambda>i_s. ((inst.funcs inst)!i_s)) i_opt = start\"\n    \"init_tabs s' inst (map nat_of_int e_offs) els = s''\"\n    \"init_mems s'' inst (map nat_of_int d_offs) ds = s_end\"\n    \"f = \\<lparr> f_locs=[], f_inst=inst \\<rparr>\"\n    using assms m_is\n    unfolding instantiate.simps\n    by fastforce\n\n  obtain fts gts ifts itts imts igts \\<C> \\<C>' where m_is_2:\n    \"list_all2 (module_func_typing \\<C>) fs fts\"\n    \"list_all (module_tab_typing) ts\"\n    \"list_all (module_mem_typing) ms\"\n    \"list_all2 (module_glob_typing \\<C>') gs gts\"\n    \"list_all (module_elem_typing \\<C>) els\"\n    \"list_all (module_data_typing \\<C>) ds\"\n    \"pred_option (module_start_typing \\<C>) i_opt\"\n    \"list_all2 (\\<lambda>imp. module_import_typing \\<C> (I_desc imp)) imps t_imps\"\n    \"list_all2 (\\<lambda>exp. module_export_typing \\<C> (E_desc exp)) exps t_exps\"\n    \"ifts = ext_t_funcs t_imps\"\n    \"itts = ext_t_tabs t_imps\"\n    \"imts = ext_t_mems t_imps\"\n    \"igts = ext_t_globs t_imps\"\n    \"\\<C> = \\<lparr>types_t=tfs, func_t=ifts@fts, global=igts@gts, table=itts@ts, memory=imts@ms, local=[], label=[], return=None\\<rparr>\"\n    \"\\<C>' = \\<lparr>types_t=[], func_t=[], global=igts, table=[], memory=[], local=[], label=[], return=None\\<rparr>\"\n    using s_end_is(1) m_is\n    unfolding module_typing.simps\n    by blast\n\n  obtain s1 s2 s3 i_fs i_ts i_ms i_gs where inst_is:\n    \"inst = \\<lparr>types=(m_types m),\n           funcs=(ext_funcs v_imps)@i_fs,\n           tabs=(ext_tabs v_imps)@i_ts,\n           mems=(ext_mems v_imps)@i_ms,\n           globs=(ext_globs v_imps)@i_gs\\<rparr>\"\n    \"alloc_funcs s fs inst = (s1,i_fs)\"\n    \"alloc_tabs s1 ts = (s2,i_ts)\"\n    \"alloc_mems s2 ms = (s3,i_ms)\"\n    \"alloc_globs s3 gs g_inits = (s',i_gs)\"\n    \"v_exps = map (\\<lambda>m_exp. \\<lparr>E_name=(E_name m_exp), E_desc=(export_get_v_ext inst (E_desc m_exp))\\<rparr>) (m_exports m)\"\n    using s_end_is(3) m_is\n    unfolding alloc_module.simps\n    by fastforce\n\n  have 12:\"list_all2 (\\<lambda>ig tg. external_typing s (Ext_glob ig) (Te_glob tg)) (inst.globs inst') (global \\<C>')\"\n    using ext_globs_ind list_all2_external_typing_glob_alloc\n    by (simp add: inst'_is m_is_2(13,15) s_end_is(2))\n  have 11:\"list_all2 (\\<lambda>ig tg. external_typing s' (Ext_glob ig) (Te_glob tg)) (inst.globs inst) (global \\<C>)\"\n  proof -\n    have \"list_all2 (\\<lambda>ig tg. external_typing s' (Ext_glob ig) (Te_glob tg)) (inst.globs inst') (global \\<C>')\"\n      using alloc_module_external_typing_preserved[OF s_end_is(3)] 12\n      unfolding list_all2_conv_all_nth\n      by fastforce\n    moreover\n    have 111:\"list_all2 (\\<lambda>v m_g. typeof v = tg_t (g_type m_g)) g_inits gs\"\n    proof -\n      { fix i\n        assume local_assms: \"i < length gs\"\n        have l2:\"\\<C>' \\<turnstile> (g_init (gs ! i)) : ([] _> [tg_t (g_type (gs!i))])\"\n                \"const_exprs \\<C>' (g_init (gs ! i))\"\n          using local_assms m_is m_is m_is_2(4,15)\n          unfolding list_all2_conv_all_nth module_glob_typing.simps\n          by auto\n        have l1:\"reduce_trans (s',f,$*(g_init (gs!i))) (s',f,[$C (g_inits!i)])\"\n          using s_end_is(4) local_assms\n          unfolding list_all2_conv_all_nth\n          by blast\n        have \"typeof (g_inits!i) = tg_t (g_type (gs!i))\"\n          using local_assms const_exprs_reduce_trans[OF l2(2,1) l1 _ 12]\n              alloc_module_ext_arb[OF s_end_is(3)] s_end_is(3)\n          unfolding alloc_module.simps s_end_is(12)\n          apply simp\n          apply (metis (mono_tags, lifting) inst'_is inst.select_convs(5))\n          done\n      }\n      thus ?thesis\n        using s_end_is(4)\n        unfolding list_all2_conv_all_nth\n        by metis\n    qed\n    have \"(gather_m_g_types gs) = gts\"\n      using m_is_2(4,15)\n      unfolding list_all2_conv_all_nth module_glob_typing.simps\n      apply simp\n      apply (metis length_map module_glob.select_convs(1) nth_equalityI nth_map)\n      done\n    hence \"list_all2 (\\<lambda>ig tg. external_typing s' (Ext_glob ig) (Te_glob tg)) i_gs gts\"\n      using alloc_globs_ext_typing[OF inst_is(5) 111]\n      by blast\n    ultimately\n    show ?thesis\n      using list_all2_appendI inst'_is\n      by (fastforce simp add: m_is_2(14,15) inst_is(1) s_end_is(11))\n  qed\n\n  have \"(module_type_checker m) = Some (t_imps, t_exps)\"\n    using s_end_is(1) module_typing_equiv_module_type_checker\n    by blast\n  moreover\n  have \"g_inits = map (\\<lambda>g. interp_get_v s inst' (g_init g)) gs\"\n  proof -\n    { fix i\n      assume local_assms: \"i < length gs\"\n      obtain t where l2:\"\\<C>' \\<turnstile> (g_init (gs ! i)) : ([] _> [t])\"\n                        \"const_exprs \\<C>' (g_init (gs ! i))\"\n        using local_assms m_is m_is m_is_2(4,15)\n        unfolding list_all2_conv_all_nth module_glob_typing.simps\n        by auto\n      have l1:\"reduce_trans (s',f,$*(g_init (gs!i))) (s',f,[$C (g_inits!i)])\"\n        using s_end_is(4) local_assms\n        unfolding list_all2_conv_all_nth\n        by blast\n      have \"run_v 2 0 (s,\\<lparr> f_locs=[], f_inst=inst' \\<rparr>,(g_init (gs!i))) = (s,RValue [g_inits!i])\"\n        using const_exprs_reduce_trans[OF l2(2,1) l1 _ 12, of _ s \"[]\" _ inst' \"[]\"]\n              alloc_module_ext_arb[OF s_end_is(3)] s_end_is(3)\n        unfolding alloc_module.simps s_end_is(12)\n        apply (simp split: prod.splits del: run_v.simps)\n        apply (metis (mono_tags, lifting) inst'_is inst.select_convs(5))\n        done\n      hence \"interp_get_v s inst' (g_init (gs!i)) = g_inits!i\"\n        unfolding interp_get_v_def\n        by fastforce\n    }\n    thus ?thesis\n      using map_intro_length[symmetric, of gs \"(\\<lambda>g. interp_get_v s inst' (g_init g))\" g_inits]\n            list_all2_lengthD[OF s_end_is(4)]\n      by fastforce\n  qed\n  moreover\n  have \"interp_alloc_module s m v_imps g_inits = (s', inst, v_exps)\"\n    using s_end_is(3) alloc_module_equiv_interp_alloc_module\n    by blast\n  moreover\n  have \"e_offs = map (\\<lambda>e. interp_get_i32 s' inst (e_off e)) els\"\n  proof -\n    { fix i\n      assume local_assms: \"i < length els\"\n      have l2:\"const_exprs \\<C> (e_off (els ! i))\"\n              \"\\<C> \\<turnstile> e_off (els ! i) : ([] _> [T_i32])\"\n        using m_is_2(5)\n        by (metis list_all_length local_assms module_elem.select_convs(2) module_elem_typing.cases)+\n      have l1:\"reduce_trans (s',f,$*(e_off (els!i))) (s',f,[$C ConstInt32 (e_offs!i)])\"\n        using s_end_is(5) local_assms\n        unfolding list_all2_conv_all_nth\n        by blast\n      have \"run_v 2 0 (s',f,(e_off (els!i))) = (s',RValue [ConstInt32 (e_offs!i)])\"\n        using const_exprs_reduce_trans[OF l2(1,2) l1 _ 11]\n        unfolding s_end_is(12)\n        by fastforce\n      hence \"interp_get_i32 s' inst (e_off (els!i)) = e_offs!i\"\n        unfolding interp_get_i32_def interp_get_v_def s_end_is(12)\n        by fastforce\n    }\n    thus ?thesis\n      using map_intro_length[symmetric, of els \"(\\<lambda>e. interp_get_i32 s' inst (e_off e))\" e_offs]\n            list_all2_lengthD[OF s_end_is(5)]\n      by fastforce\n  qed\n  moreover\n  have \"d_offs = map (\\<lambda>d. interp_get_i32 s' inst (d_off d)) ds\"\n  proof -\n    { fix i\n      assume local_assms: \"i < length ds\"\n      have l2:\"const_exprs \\<C> (d_off (ds ! i))\"\n              \"\\<C> \\<turnstile> d_off (ds ! i) : ([] _> [T_i32])\"\n        using m_is_2(6)\n        by (metis list_all_length local_assms module_data.select_convs(2) module_data_typing.cases)+\n      have l1:\"reduce_trans (s',f,$*(d_off (ds!i))) (s',f,[$C ConstInt32 (d_offs!i)])\"\n        using s_end_is(6) local_assms\n        unfolding list_all2_conv_all_nth\n        by blast\n      have \"run_v 2 0 (s',f,(d_off (ds!i))) = (s',RValue [ConstInt32 (d_offs!i)])\"\n        using const_exprs_reduce_trans[OF l2(1,2) l1 _ 11]\n        unfolding s_end_is(12)\n        by fastforce\n      hence \"interp_get_i32 s' inst (d_off (ds!i)) = d_offs!i\"\n        unfolding interp_get_i32_def interp_get_v_def s_end_is(12)\n        by fastforce\n    }\n    thus ?thesis\n      using map_intro_length[symmetric, of ds \"(\\<lambda>e. interp_get_i32 s' inst (d_off e))\" d_offs]\n            list_all2_lengthD[OF s_end_is(6)]\n      by fastforce\n  qed\n  ultimately\n  show ?thesis\n    using s_end_is(2,7,8,9,10,11) m_is inst'_is\n    by simp\nqed\n\ntheorem instantiate_equiv_interp_instantiate:\n  \"(instantiate s m v_imps ((s_end, inst, v_exps), start)) = (interp_instantiate s m v_imps = Some ((s_end, inst, v_exps), start))\"\n  using instantiate_imp_interp_instantiate interp_instantiate_imp_instantiate\n  by blast\nend", "meta": {"author": "WasmCert", "repo": "WasmCert-Isabelle", "sha": "f61ec8eab5d551347a268e858e83b7ac7da0d8b5", "save_path": "github-repos/isabelle/WasmCert-WasmCert-Isabelle", "path": "github-repos/isabelle/WasmCert-WasmCert-Isabelle/WasmCert-Isabelle-f61ec8eab5d551347a268e858e83b7ac7da0d8b5/WebAssembly/Wasm_Instantiation.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526660244837, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.26271164077314424}}
{"text": "theory flash100Rev imports flashPub\nbegin\nsection{*Main defintions*}\nlemma NI_FAckVsInv100:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv100 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_InvVsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1VsInv100:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1_HomeVsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_2VsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_GetXVsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_Nak1VsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_Nak2VsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_Nak3VsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_PutX1VsInv100:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv100:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv100:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv100:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv100:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv100:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv100:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv100:  \n  (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv100:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_PutX10VsInv100:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_PutX10_homeVsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_PutX11VsInv100:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_Get_GetVsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Nak1VsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Nak2VsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Nak3VsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Put1VsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Put2VsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Put3VsInv100:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''WbMsg_Cmd'') )  ( Const WB_Wb ))    ( eqn ( IVar ( Global ''Dir_local'') )  ( Const true ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma NI_Local_PutVsInv100:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n     have allCases:\"formEval  ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true ))  s  \\<or>formEval   (neg ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true )) )  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume b1:\"formEval ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true ))  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n\n    moreover\n                       {assume b1:\"formEval  (neg ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true )) )  s\"\n\n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''WbMsg_Cmd'') )  ( Const WB_Wb ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Put ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n    }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_PutXAcksDoneVsInv100:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv100 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_NakVsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Nak_ClearVsInv100:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv100 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_Nak_HomeVsInv100:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv100 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_Remote_GetX_NakVsInv100:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_Nak_HomeVsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_PutXVsInv100:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_PutX_HomeVsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Nak1VsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Nak2VsInv100:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Put1VsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Put2VsInv100:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_PutVsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_PutXVsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceVsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceHomeVsInv100:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv100 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_ReplaceHomeShrVldVsInv100:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv100 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_ReplaceShrVldVsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ShWbVsInv100:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv100 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_WbVsInv100:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv100 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_GetX1VsInv100:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv100 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_GetX_GetX2VsInv100:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv100 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_GetX_PutX1VsInv100:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv100 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX2VsInv100:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv100 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX3VsInv100:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv100 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX4VsInv100:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv100 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_Get_GetVsInv100:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv100 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_Get_PutVsInv100:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv100 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n     have allCases:\"formEval  ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true ))  s  \\<or>formEval   (neg ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true )) )  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume b1:\"formEval ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true ))  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n\n    moreover\n                       {assume b1:\"formEval  (neg ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true )) )  s\"\n\n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''WbMsg_Cmd'') )  ( Const WB_Wb ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n    }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Local_PutXVsInv100:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv100 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_ReplaceVsInv100:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv100 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Remote_GetVsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_GetXVsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_PutXVsInv100:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iRule1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Para ''CacheState'' Home) )  ( Const CACHE_S ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma PI_Remote_ReplaceVsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma StoreVsInv100:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv100 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma StoreHomeVsInv100:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv100 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash100Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5698526660244837, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.26271164077314424}}
{"text": "theory IO\n  imports\n    Main\n    \"HOL-Library.Countable\"\n    \"HOL-Library.Monad_Syntax\"\nbegin\n\n(*\n  We don't use HOL-Imperative_HOL Library, because it does implement\n  arrays as a list in a cell. We will follow the same idea about Heap,\n  but implement arrays as sequent cells in a memory.\n*)\n\nclass heap = typerep + countable\n\ninstance unit :: heap ..\ninstance bool :: heap ..\ninstance nat :: heap ..\ninstance int :: heap ..\n\ntype_synonym addr = nat\n\nrecord heap = \n  memory :: \"addr \\<Rightarrow> nat\"\n  lim :: addr\n\ndatatype 'a ref = Ref addr\n\nprimrec addr_of_ref :: \"'a ref \\<Rightarrow> addr\" where\n  \"addr_of_ref (Ref r) = r\"\n\nlemma addr_of_ref_inj [simp]:\n  \"addr_of_ref r = addr_of_ref r' \\<longleftrightarrow> r = r'\"\n  by (cases r, cases r') simp_all\n\nprimrec nat_of_ref :: \"'a ref \\<Rightarrow> nat\" where\n  \"nat_of_ref (Ref r) = r\"\n\ninstance ref :: (type) countable\n  apply (rule countable_classI [of nat_of_ref])\n  apply (metis nat_of_ref.simps ref.exhaust)\n  done\n\ninstance ref :: (type) heap ..\n\ndatatype 'a io = IO \"heap \\<Rightarrow> ('a \\<times> heap)\"\n\nprimrec execute :: \"'a io \\<Rightarrow> heap \\<Rightarrow> ('a \\<times> heap)\" where\n  [code del]: \"execute (IO f) = f\"\n\nlemma io_execute [simp]:\n  \"IO (execute f) = f\"\n  by (cases f, simp)\n\ndefinition tap :: \"(heap \\<Rightarrow> 'a) \\<Rightarrow> 'a io\" where\n  [code del]: \"tap f = IO (\\<lambda>h. (f h, h))\"\n\nlemma execute_tap:\n  \"execute (tap f) h = (f h, h)\"\n  by (simp add: tap_def)\n\ndefinition effect :: \"'a io \\<Rightarrow> heap \\<Rightarrow> heap \\<Rightarrow> 'a \\<Rightarrow> bool\" where\n  \"effect c h h' r = (execute c h = (r,h'))\"\n\nlemma effectI: \"execute c h = (r,h') \\<Longrightarrow> effect c h h' r\"\n  by (simp add: effect_def)\n\nlemma effectE:\n  assumes \"effect c h h' r\"\n  shows \"execute c h = (r,h')\"\n  using assms by (simp add: effect_def)\n\ndefinition return :: \"'a \\<Rightarrow> 'a io\" where\n  [code del]: \"return x = IO (\\<lambda>h. (x,h))\"\n\ndefinition bind :: \"'a io \\<Rightarrow> ('a \\<Rightarrow> 'b io) \\<Rightarrow> 'b io\" where\n  [code del]: \"bind x f = IO (\\<lambda>h. case execute x h of (y,h') \\<Rightarrow> execute (f y) h')\"\n\nadhoc_overloading\n  Monad_Syntax.bind IO.bind\n\n(* IO monad *)\n\nlemma monad_left_id[simp]: \"return a \\<bind> f = f a\"\n  apply (simp add: return_def bind_def)\n  done\n\nlemma monad_right_id[simp]: \"m \\<bind> return = m\"\n  apply (simp add: return_def bind_def comp_def)\n  done\n\nlemma monad_assoc[simp]:\n  fixes m :: \"'a::heap io\"\n  shows \"(m \\<bind> f) \\<bind> g = m \\<bind> (\\<lambda>x. f x \\<bind> g)\"\n  unfolding bind_def comp_def by (auto split: prod.splits)\n\n(* Monadic Combinators *)\n\nfun forMu :: \"'a list \\<Rightarrow> ('a \\<Rightarrow> unit io) \\<Rightarrow> unit io\" where\n  \"forMu [] f = return ()\"\n| \"forMu (x#xs) f = f x \\<bind> (\\<lambda>_. forMu xs f)\"\n\nfun mapM :: \"('a \\<Rightarrow> 'b::heap io) \\<Rightarrow> 'a list \\<Rightarrow> 'b list io\" where\n  \"mapM f [] = return []\"\n| \"mapM f (x#xs) = f x \\<bind> (\\<lambda>r. mapM f xs \\<bind> (\\<lambda>rs. return (r#rs)))\"\n\nfun whenu :: \"bool \\<Rightarrow> unit io \\<Rightarrow> unit io\" where\n  \"whenu cond f = (if cond then f else return ())\"\n\nfun whenM :: \"bool io \\<Rightarrow> unit io \\<Rightarrow> unit io\" where\n  \"whenM cond f = cond \\<bind> (\\<lambda>b. if b then f else return ())\"\n\nlemma execute_bind: \"execute (m \\<bind> k) h = (case (execute m h) of (val,h') \\<Rightarrow> execute (k val) h')\"\n  by (simp add: IO.bind_def)\n\nlemma effect_bind:\n  assumes \"effect (m \\<bind> k) h h' r\"\n  obtains h'' a where \"effect m h h'' a\" \"effect (k a) h'' h' r\"\n  using assms\n  apply (simp add: effect_def execute_bind)\n  by (metis case_prod_beta prod.exhaust_sel)\n\nlemma effect_return_unit [simp]:\n  assumes \"effect (return ()) h h' ()\"\n  shows \"h' = h\"\n  by (metis assms effectE execute.simps return_def snd_conv)\n\nlemma forMu_nil [simp]: \"execute (forMu [] p) h = ((),h)\"\n  by (simp add: return_def)\n\nlemma forMu_app_return:\n  \"execute (forMu (as@bs) program) h = execute (do {\n    _ \\<leftarrow> forMu as program;\n    _ \\<leftarrow> forMu bs program;\n    return ()\n  }) h\"\n  apply (induct as arbitrary: h, simp)\n  apply (simp add: execute_bind)\n  done\n\nlemma forMu_app:\n  \"execute (forMu (as@bs) program) h = execute (do {\n    _ \\<leftarrow> forMu as program;\n    forMu bs program\n  }) h\"\n  apply (induct as arbitrary: h, simp)\n  apply (simp add: execute_bind)\n  done\n\ncode_printing\n  type_constructor io \\<rightharpoonup> (Haskell) \"IO _\"\n  | type_constructor ref \\<rightharpoonup> (Haskell) \"IORef _\"\n  | constant return \\<rightharpoonup> (Haskell) \"return\"\n  | constant bind \\<rightharpoonup> (Haskell) infixl 5 \">>=\"\n\n(* Refs *)\n\ndefinition present :: \"heap \\<Rightarrow> 'a::heap ref \\<Rightarrow> bool\" where\n  \"present h v = (addr_of_ref v < lim h)\"\n\ndefinition set :: \"'a::heap ref \\<Rightarrow> 'a \\<Rightarrow> heap \\<Rightarrow> heap\" where\n  \"set r v h = h \\<lparr> memory := (\\<lambda>i. if i = addr_of_ref r then to_nat v else memory h i) \\<rparr>\"\n\ndefinition alloc :: \"'a \\<Rightarrow> heap \\<Rightarrow> 'a::heap ref \\<times> heap\" where\n  \"alloc v h = (let l = lim h; r = Ref l in (r, set r v (h \\<lparr> lim := lim h + 1 \\<rparr>)))\"\n\ndefinition get :: \"heap \\<Rightarrow> 'a::heap ref \\<Rightarrow> 'a\" where\n  \"get h = from_nat \\<circ> memory h \\<circ> addr_of_ref\"\n\ndefinition ref :: \"'a::heap \\<Rightarrow> 'a ref io\" where\n  \"ref v = IO (alloc v)\"\n\ndefinition lookup :: \"'a::heap ref \\<Rightarrow> 'a io\" (\"!_\" 61) where\n  \"lookup r = tap (\\<lambda>h. get h r)\"\n\ndefinition update :: \"'a ref \\<Rightarrow> 'a::heap \\<Rightarrow> unit io\" (\"_ := _\" 62) where\n  \"update r v = IO (\\<lambda>h. ((), set r v h))\"\n\nlemma get_set_eq [simp]: \"get (set r x h) r = x\"\n  by (simp add: get_def set_def)\n\nlemma heap_eqI:\n  assumes \"\\<And>x. m1 x = m2 x\" and \"l1 = l2\"\n  shows \"\\<lparr> memory = m1, lim = l1 \\<rparr> = \\<lparr> memory = m2, lim = l2 \\<rparr>\"\n  using assms by auto\n\nlemma set_same [simp]: \"set r x (set r y h) = set r x h\"\n  apply (simp add: set_def)\nproof-\n  have \"\\<And>P x y. P x \\<Longrightarrow> (\\<And>y. x \\<noteq> y \\<Longrightarrow> P y) \\<Longrightarrow> (\\<And>z. P z)\"\n    by metis\n  hence \"\\<And>f g. f (addr_of_ref r) = g (addr_of_ref r) \\<Longrightarrow> (\\<And>x. x \\<noteq> addr_of_ref r \\<Longrightarrow> f x = g x) \\<Longrightarrow> (\\<And>z. f z = g z)\"\n    by smt\n  hence \"\\<And>z. (\\<lambda>i. if i = addr_of_ref r then to_nat x else memory (h\\<lparr>memory := \\<lambda>i. if i = addr_of_ref r then to_nat y else memory h i\\<rparr>) i) z = (\\<lambda>i. if i = addr_of_ref r then to_nat x else memory h i) z\"\n    by auto\n  thus \"h\\<lparr>memory := \\<lambda>i. if i = addr_of_ref r then to_nat x else memory (h\\<lparr>memory := \\<lambda>i. if i = addr_of_ref r then to_nat y else memory h i\\<rparr>) i\\<rparr> = h\\<lparr>memory := \\<lambda>i. if i = addr_of_ref r then to_nat x else memory h i\\<rparr>\"\n    by simp\nqed\n\nlemma execute_ref: \"execute (ref v) h = alloc v h\"\n  by (simp add: ref_def)\n\nlemma execute_lookup: \"execute (lookup r) h = (get h r, h)\"\n  by (simp add: lookup_def execute_def tap_def)\n\nlemma execute_update: \"execute (update r v) h = ((), set r v h)\"\n  by (simp add: update_def)\n\ndefinition noteq :: \"'a::heap ref \\<Rightarrow> 'b::heap ref \\<Rightarrow> bool\" (infix \"=!=\" 70) where\n  \"r =!= s \\<longleftrightarrow> addr_of_ref r \\<noteq> addr_of_ref s\"\n\nlemma noteq_sym: \"r =!= s \\<Longrightarrow> s =!= r\"\n  apply (simp add: noteq_def)\n  done\n\nlemma noteq_set_get:\n  assumes \"r =!= s\"\n  shows \"get (set r val h) s = get h s\"\n  apply (auto simp add: noteq_def IO.set_def get_def)\n  using assms apply (simp add: noteq_def)\n  done\n\nlemma effect_forMu_app:\n  assumes \"effect (forMu (as@bs) program) h h' ()\"\n  shows \"effect (do {\n    _ \\<leftarrow> forMu as program;\n    forMu bs program\n  }) h h' ()\"\n  using assms\n  apply (simp add: effect_def)\n  apply (simp add: forMu_app)\n  done\n\nlemma alloc_get: \"alloc v h = (r,h') \\<Longrightarrow> get h' r = v\"\n  apply (simp add: alloc_def get_def)\n  by (metis comp_apply get_def get_set_eq prod.sel(1) snd_conv)\n\nhide_const (open) present get set alloc\n\nend\n", "meta": {"author": "myuon", "repo": "algo", "sha": "691b21ad06f1ac2c41ecd3462c3d5b65110c2b14", "save_path": "github-repos/isabelle/myuon-algo", "path": "github-repos/isabelle/myuon-algo/algo-691b21ad06f1ac2c41ecd3462c3d5b65110c2b14/isabelle/IO.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526514141571, "lm_q2_score": 0.46101677931231594, "lm_q1q2_score": 0.26271163403753856}}
{"text": "theory Class3\nimports Class2\nbegin\n\ntext \\<open>3rd Main Lemma\\<close>\n\nlemma Cut_a_redu_elim:\n  assumes a: \"Cut <a>.M (x).N \\<longrightarrow>\\<^sub>a R\"\n  shows \"(\\<exists>M'. R = Cut <a>.M' (x).N \\<and> M \\<longrightarrow>\\<^sub>a M') \\<or>\n         (\\<exists>N'. R = Cut <a>.M (x).N' \\<and> N \\<longrightarrow>\\<^sub>a N') \\<or>\n         (Cut <a>.M (x).N \\<longrightarrow>\\<^sub>c R) \\<or>\n         (Cut <a>.M (x).N \\<longrightarrow>\\<^sub>l R)\"\nusing a\napply(erule_tac a_redu.cases)\napply(simp_all)\napply(simp_all add: trm.inject)\napply(rule disjI1)\napply(auto simp add: alpha)[1]\napply(rule_tac x=\"[(a,aa)]\\<bullet>M'\" in exI)\napply(perm_simp add: fresh_left calc_atm a_redu.eqvt fresh_a_redu)\napply(rule_tac x=\"[(a,aa)]\\<bullet>M'\" in exI)\napply(perm_simp add: fresh_left calc_atm a_redu.eqvt fresh_a_redu)\napply(rule disjI2)\napply(rule disjI1)\napply(auto simp add: alpha)[1]\napply(rule_tac x=\"[(x,xa)]\\<bullet>N'\" in exI)\napply(perm_simp add: fresh_left calc_atm a_redu.eqvt fresh_a_redu)\napply(rule_tac x=\"[(x,xa)]\\<bullet>N'\" in exI)\napply(perm_simp add: fresh_left calc_atm a_redu.eqvt fresh_a_redu)\ndone\n\nlemma Cut_c_redu_elim:\n  assumes a: \"Cut <a>.M (x).N \\<longrightarrow>\\<^sub>c R\"\n  shows \"(R = M{a:=(x).N} \\<and> \\<not>fic M a) \\<or>\n         (R = N{x:=<a>.M} \\<and> \\<not>fin N x)\"\nusing a\napply(erule_tac c_redu.cases)\napply(simp_all)\napply(simp_all add: trm.inject)\napply(rule disjI1)\napply(auto simp add: alpha)[1]\napply(simp add: subst_rename fresh_atm)\napply(simp add: subst_rename fresh_atm)\napply(drule_tac pi=\"[(a,aa)]\" in fic.eqvt(2))\napply(perm_simp)\napply(simp add: subst_rename fresh_atm fresh_prod)\napply(drule_tac pi=\"[(a,aa)]\" in fic.eqvt(2))\napply(perm_simp)\napply(rule disjI2)\napply(auto simp add: alpha)[1]\napply(simp add: subst_rename fresh_atm)\napply(drule_tac pi=\"[(x,xa)]\" in fin.eqvt(1))\napply(perm_simp)\napply(simp add: subst_rename fresh_atm fresh_prod)\napply(simp add: subst_rename fresh_atm fresh_prod)\napply(drule_tac pi=\"[(x,xa)]\" in fin.eqvt(1))\napply(perm_simp)\ndone\n\nlemma not_fic_crename_aux:\n  assumes a: \"fic M c\" \"c\\<sharp>(a,b)\"\n  shows \"fic (M[a\\<turnstile>c>b]) c\" \nusing a\napply(nominal_induct M avoiding: c a b rule: trm.strong_induct)\napply(auto dest!: fic_elims intro!: fic.intros simp add: fresh_prod fresh_atm rename_fresh abs_fresh)\ndone\n\nlemma not_fic_crename:\n  assumes a: \"\\<not>(fic (M[a\\<turnstile>c>b]) c)\" \"c\\<sharp>(a,b)\"\n  shows \"\\<not>(fic M c)\" \nusing a\napply(auto dest:  not_fic_crename_aux)\ndone\n\nlemma not_fin_crename_aux:\n  assumes a: \"fin M y\"\n  shows \"fin (M[a\\<turnstile>c>b]) y\" \nusing a\napply(nominal_induct M avoiding: a b rule: trm.strong_induct)\napply(auto dest!: fin_elims intro!: fin.intros simp add: fresh_prod fresh_atm rename_fresh abs_fresh)\ndone\n\nlemma not_fin_crename:\n  assumes a: \"\\<not>(fin (M[a\\<turnstile>c>b]) y)\" \n  shows \"\\<not>(fin M y)\" \nusing a\napply(auto dest:  not_fin_crename_aux)\ndone\n\nlemma crename_fresh_interesting1:\n  fixes c::\"coname\"\n  assumes a: \"c\\<sharp>(M[a\\<turnstile>c>b])\" \"c\\<sharp>(a,b)\"\n  shows \"c\\<sharp>M\"\nusing a\napply(nominal_induct M avoiding: c a b rule: trm.strong_induct)\napply(auto split: if_splits simp add: abs_fresh)\ndone\n\nlemma crename_fresh_interesting2:\n  fixes x::\"name\"\n  assumes a: \"x\\<sharp>(M[a\\<turnstile>c>b])\" \n  shows \"x\\<sharp>M\"\nusing a\napply(nominal_induct M avoiding: x a b rule: trm.strong_induct)\napply(auto split: if_splits simp add: abs_fresh abs_supp fin_supp fresh_atm)\ndone\n\n\nlemma fic_crename:\n  assumes a: \"fic (M[a\\<turnstile>c>b]) c\" \"c\\<sharp>(a,b)\"\n  shows \"fic M c\" \nusing a\napply(nominal_induct M avoiding: c a b rule: trm.strong_induct)\napply(auto dest!: fic_elims intro!: fic.intros simp add: fresh_prod fresh_atm rename_fresh abs_fresh\n           split: if_splits)\napply(auto dest: crename_fresh_interesting1 simp add: fresh_prod fresh_atm)\ndone\n\nlemma fin_crename:\n  assumes a: \"fin (M[a\\<turnstile>c>b]) x\"\n  shows \"fin M x\" \nusing a\napply(nominal_induct M avoiding: x a b rule: trm.strong_induct)\napply(auto dest!: fin_elims intro!: fin.intros simp add: fresh_prod fresh_atm rename_fresh abs_fresh\n           split: if_splits)\napply(auto dest: crename_fresh_interesting2 simp add: fresh_prod fresh_atm)\ndone\n\nlemma crename_Cut:\n  assumes a: \"R[a\\<turnstile>c>b] = Cut <c>.M (x).N\" \"c\\<sharp>(a,b,N,R)\" \"x\\<sharp>(M,R)\"\n  shows \"\\<exists>M' N'. R = Cut <c>.M' (x).N' \\<and> M'[a\\<turnstile>c>b] = M \\<and> N'[a\\<turnstile>c>b] = N \\<and> c\\<sharp>N' \\<and> x\\<sharp>M'\"\nusing a\napply(nominal_induct R avoiding: a b c x M N rule: trm.strong_induct)\napply(auto split: if_splits)\napply(simp add: trm.inject)\napply(auto simp add: alpha)\napply(rule_tac x=\"[(name,x)]\\<bullet>trm2\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\napply(rule_tac x=\"[(coname,c)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\napply(auto simp add: fresh_atm)[1]\napply(rule_tac x=\"[(coname,c)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(rule_tac x=\"[(name,x)]\\<bullet>trm2\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\napply(auto simp add: fresh_atm)[1]\napply(drule sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\napply(drule sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma crename_NotR:\n  assumes a: \"R[a\\<turnstile>c>b] = NotR (x).N c\" \"x\\<sharp>R\" \"c\\<sharp>(a,b)\"\n  shows \"\\<exists>N'. (R = NotR (x).N' c) \\<and> N'[a\\<turnstile>c>b] = N\" \nusing a\napply(nominal_induct R avoiding: a b c x N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\napply(rule_tac x=\"[(name,x)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma crename_NotR':\n  assumes a: \"R[a\\<turnstile>c>b] = NotR (x).N c\" \"x\\<sharp>R\" \"c\\<sharp>a\"\n  shows \"(\\<exists>N'. (R = NotR (x).N' c) \\<and> N'[a\\<turnstile>c>b] = N) \\<or> (\\<exists>N'. (R = NotR (x).N' a) \\<and> b=c \\<and> N'[a\\<turnstile>c>b] = N)\"\nusing a\napply(nominal_induct R avoiding: a b c x N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm abs_fresh alpha trm.inject)\napply(rule_tac x=\"[(name,x)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\napply(rule_tac x=\"[(name,x)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma crename_NotR_aux:\n  assumes a: \"R[a\\<turnstile>c>b] = NotR (x).N c\" \n  shows \"(a=c \\<and> a=b) \\<or> (a\\<noteq>c)\" \nusing a\napply(nominal_induct R avoiding: a b c x N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\ndone\n\nlemma crename_NotL:\n  assumes a: \"R[a\\<turnstile>c>b] = NotL <c>.N y\" \"c\\<sharp>(R,a,b)\"\n  shows \"\\<exists>N'. (R = NotL <c>.N' y) \\<and> N'[a\\<turnstile>c>b] = N\" \nusing a\napply(nominal_induct R avoiding: a b c y N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\napply(rule_tac x=\"[(coname,c)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma crename_AndL1:\n  assumes a: \"R[a\\<turnstile>c>b] = AndL1 (x).N y\" \"x\\<sharp>R\"\n  shows \"\\<exists>N'. (R = AndL1 (x).N' y) \\<and> N'[a\\<turnstile>c>b] = N\" \nusing a\napply(nominal_induct R avoiding: a b x y N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\napply(rule_tac x=\"[(name1,x)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma crename_AndL2:\n  assumes a: \"R[a\\<turnstile>c>b] = AndL2 (x).N y\" \"x\\<sharp>R\"\n  shows \"\\<exists>N'. (R = AndL2 (x).N' y) \\<and> N'[a\\<turnstile>c>b] = N\" \nusing a\napply(nominal_induct R avoiding: a b x y N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\napply(rule_tac x=\"[(name1,x)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma crename_AndR_aux:\n  assumes a: \"R[a\\<turnstile>c>b] = AndR <c>.M <d>.N e\" \n  shows \"(a=e \\<and> a=b) \\<or> (a\\<noteq>e)\" \nusing a\napply(nominal_induct R avoiding: a b c d e M N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\ndone\n\nlemma crename_AndR:\n  assumes a: \"R[a\\<turnstile>c>b] = AndR <c>.M <d>.N e\" \"c\\<sharp>(a,b,d,e,N,R)\" \"d\\<sharp>(a,b,c,e,M,R)\" \"e\\<sharp>(a,b)\"\n  shows \"\\<exists>M' N'. R = AndR <c>.M' <d>.N' e \\<and> M'[a\\<turnstile>c>b] = M \\<and> N'[a\\<turnstile>c>b] = N \\<and> c\\<sharp>N' \\<and> d\\<sharp>M'\"\nusing a\napply(nominal_induct R avoiding: a b c d e M N rule: trm.strong_induct)\napply(auto split: if_splits simp add: trm.inject alpha)\napply(simp add: fresh_atm fresh_prod)\napply(rule_tac x=\"[(coname2,d)]\\<bullet>trm2\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(rule_tac x=\"[(coname1,c)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(rule_tac x=\"[(coname1,c)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(rule_tac x=\"[(coname2,d)]\\<bullet>trm2\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(rule_tac x=\"[(coname1,c)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(rule_tac x=\"[(coname1,c)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(rule_tac x=\"[(coname2,d)]\\<bullet>trm2\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\napply(drule_tac s=\"trm2[a\\<turnstile>c>b]\" in  sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma crename_AndR':\n  assumes a: \"R[a\\<turnstile>c>b] = AndR <c>.M <d>.N e\" \"c\\<sharp>(a,b,d,e,N,R)\" \"d\\<sharp>(a,b,c,e,M,R)\" \"e\\<sharp>a\"\n  shows \"(\\<exists>M' N'. R = AndR <c>.M' <d>.N' e \\<and> M'[a\\<turnstile>c>b] = M \\<and> N'[a\\<turnstile>c>b] = N \\<and> c\\<sharp>N' \\<and> d\\<sharp>M') \\<or>\n         (\\<exists>M' N'. R = AndR <c>.M' <d>.N' a \\<and> b=e \\<and> M'[a\\<turnstile>c>b] = M \\<and> N'[a\\<turnstile>c>b] = N \\<and> c\\<sharp>N' \\<and> d\\<sharp>M')\"\nusing a\napply(nominal_induct R avoiding: a b c d e M N rule: trm.strong_induct)\napply(auto split: if_splits simp add: trm.inject alpha)[1]\napply(auto split: if_splits simp add: trm.inject alpha)[1]\napply(auto split: if_splits simp add: trm.inject alpha)[1]\napply(auto split: if_splits simp add: trm.inject alpha)[1]\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm trm.inject alpha)[1]\napply(case_tac \"coname3=a\")\napply(simp)\napply(rule_tac x=\"[(coname1,c)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(rule_tac x=\"[(coname2,d)]\\<bullet>trm2\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm trm.inject alpha split: if_splits)[1]\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\napply(drule_tac s=\"trm2[a\\<turnstile>c>e]\" in  sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\napply(simp)\napply(rule_tac x=\"[(coname1,c)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(rule_tac x=\"[(coname2,d)]\\<bullet>trm2\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm trm.inject alpha split: if_splits)[1]\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\napply(drule_tac s=\"trm2[a\\<turnstile>c>b]\" in  sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\ndone\n\nlemma crename_OrR1_aux:\n  assumes a: \"R[a\\<turnstile>c>b] = OrR1 <c>.M e\" \n  shows \"(a=e \\<and> a=b) \\<or> (a\\<noteq>e)\" \nusing a\napply(nominal_induct R avoiding: a b c e M rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\ndone\n\nlemma crename_OrR1:\n  assumes a: \"R[a\\<turnstile>c>b] = OrR1 <c>.N d\" \"c\\<sharp>(R,a,b)\" \"d\\<sharp>(a,b)\"\n  shows \"\\<exists>N'. (R = OrR1 <c>.N' d) \\<and> N'[a\\<turnstile>c>b] = N\" \nusing a\napply(nominal_induct R avoiding: a b c d N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\napply(rule_tac x=\"[(coname1,c)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma crename_OrR1':\n  assumes a: \"R[a\\<turnstile>c>b] = OrR1 <c>.N d\" \"c\\<sharp>(R,a,b)\" \"d\\<sharp>a\"\n  shows \"(\\<exists>N'. (R = OrR1 <c>.N' d) \\<and> N'[a\\<turnstile>c>b] = N) \\<or>\n         (\\<exists>N'. (R = OrR1 <c>.N' a) \\<and> b=d \\<and> N'[a\\<turnstile>c>b] = N)\" \nusing a\napply(nominal_induct R avoiding: a b c d N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\napply(rule_tac x=\"[(coname1,c)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\napply(rule_tac x=\"[(coname1,c)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma crename_OrR2_aux:\n  assumes a: \"R[a\\<turnstile>c>b] = OrR2 <c>.M e\" \n  shows \"(a=e \\<and> a=b) \\<or> (a\\<noteq>e)\" \nusing a\napply(nominal_induct R avoiding: a b c e M rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\ndone\n\nlemma crename_OrR2:\n  assumes a: \"R[a\\<turnstile>c>b] = OrR2 <c>.N d\" \"c\\<sharp>(R,a,b)\" \"d\\<sharp>(a,b)\"\n  shows \"\\<exists>N'. (R = OrR2 <c>.N' d) \\<and> N'[a\\<turnstile>c>b] = N\" \nusing a\napply(nominal_induct R avoiding: a b c d N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\napply(rule_tac x=\"[(coname1,c)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma crename_OrR2':\n  assumes a: \"R[a\\<turnstile>c>b] = OrR2 <c>.N d\" \"c\\<sharp>(R,a,b)\" \"d\\<sharp>a\"\n  shows \"(\\<exists>N'. (R = OrR2 <c>.N' d) \\<and> N'[a\\<turnstile>c>b] = N) \\<or>\n         (\\<exists>N'. (R = OrR2 <c>.N' a) \\<and> b=d \\<and> N'[a\\<turnstile>c>b] = N)\" \nusing a\napply(nominal_induct R avoiding: a b c d N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\napply(rule_tac x=\"[(coname1,c)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\napply(rule_tac x=\"[(coname1,c)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma crename_OrL:\n  assumes a: \"R[a\\<turnstile>c>b] = OrL (x).M (y).N z\" \"x\\<sharp>(y,z,N,R)\" \"y\\<sharp>(x,z,M,R)\"\n  shows \"\\<exists>M' N'. R = OrL (x).M' (y).N' z \\<and> M'[a\\<turnstile>c>b] = M \\<and> N'[a\\<turnstile>c>b] = N \\<and> x\\<sharp>N' \\<and> y\\<sharp>M'\"\nusing a\napply(nominal_induct R avoiding: a b x y z M N rule: trm.strong_induct)\napply(auto split: if_splits simp add: trm.inject alpha)\napply(rule_tac x=\"[(name2,y)]\\<bullet>trm2\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(rule_tac x=\"[(name1,x)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(rule_tac x=\"[(name1,x)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(rule_tac x=\"[(name2,y)]\\<bullet>trm2\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(drule sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\napply(drule_tac s=\"trm2[a\\<turnstile>c>b]\" in  sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma crename_ImpL:\n  assumes a: \"R[a\\<turnstile>c>b] = ImpL <c>.M (y).N z\" \"c\\<sharp>(a,b,N,R)\" \"y\\<sharp>(z,M,R)\"\n  shows \"\\<exists>M' N'. R = ImpL <c>.M' (y).N' z \\<and> M'[a\\<turnstile>c>b] = M \\<and> N'[a\\<turnstile>c>b] = N \\<and> c\\<sharp>N' \\<and> y\\<sharp>M'\"\nusing a\napply(nominal_induct R avoiding: a b c y z M N rule: trm.strong_induct)\napply(auto split: if_splits simp add: trm.inject alpha)\napply(rule_tac x=\"[(name1,y)]\\<bullet>trm2\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(rule_tac x=\"[(coname,c)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(rule_tac x=\"[(coname,c)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(rule_tac x=\"[(name1,y)]\\<bullet>trm2\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\napply(drule_tac s=\"trm2[a\\<turnstile>c>b]\" in  sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma crename_ImpR_aux:\n  assumes a: \"R[a\\<turnstile>c>b] = ImpR (x).<c>.M e\" \n  shows \"(a=e \\<and> a=b) \\<or> (a\\<noteq>e)\" \nusing a\napply(nominal_induct R avoiding: x a b c e M rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\ndone\n\nlemma crename_ImpR:\n  assumes a: \"R[a\\<turnstile>c>b] = ImpR (x).<c>.N d\" \"c\\<sharp>(R,a,b)\" \"d\\<sharp>(a,b)\" \"x\\<sharp>R\" \n  shows \"\\<exists>N'. (R = ImpR (x).<c>.N' d) \\<and> N'[a\\<turnstile>c>b] = N\" \nusing a\napply(nominal_induct R avoiding: a b x c d N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm abs_perm alpha abs_fresh trm.inject)\napply(rule_tac x=\"[(name,x)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(rule_tac x=\"[(name,x)]\\<bullet>[(coname1, c)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_supp fin_supp abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma crename_ImpR':\n  assumes a: \"R[a\\<turnstile>c>b] = ImpR (x).<c>.N d\" \"c\\<sharp>(R,a,b)\" \"x\\<sharp>R\" \"d\\<sharp>a\"\n  shows \"(\\<exists>N'. (R = ImpR (x).<c>.N' d) \\<and> N'[a\\<turnstile>c>b] = N) \\<or>\n         (\\<exists>N'. (R = ImpR (x).<c>.N' a) \\<and> b=d \\<and> N'[a\\<turnstile>c>b] = N)\" \nusing a\napply(nominal_induct R avoiding: x a b c d N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject abs_perm calc_atm)\napply(rule_tac x=\"[(name,x)]\\<bullet>[(coname1,c)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod abs_supp fin_supp)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\napply(rule_tac x=\"[(name,x)]\\<bullet>[(coname1,c)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod abs_supp fin_supp)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma crename_ax2:\n  assumes a: \"N[a\\<turnstile>c>b] = Ax x c\"\n  shows \"\\<exists>d. N = Ax x d\"\nusing a\napply(nominal_induct N avoiding: a b rule: trm.strong_induct)\napply(auto split: if_splits)\napply(simp add: trm.inject)\ndone\n\nlemma crename_interesting1:\n  assumes a: \"distinct [a,b,c]\"\n  shows \"M[a\\<turnstile>c>c][c\\<turnstile>c>b] = M[c\\<turnstile>c>b][a\\<turnstile>c>b]\"\nusing a\napply(nominal_induct M avoiding: a c b rule: trm.strong_induct)\napply(auto simp add: rename_fresh simp add: trm.inject alpha)\napply(blast)\napply(rotate_tac 12)\napply(drule_tac x=\"a\" in meta_spec)\napply(rotate_tac 15)\napply(drule_tac x=\"c\" in meta_spec)\napply(rotate_tac 15)\napply(drule_tac x=\"b\" in meta_spec)\napply(blast)\napply(blast)\napply(blast)\ndone\n\nlemma crename_interesting2:\n  assumes a: \"a\\<noteq>c\" \"a\\<noteq>d\" \"a\\<noteq>b\" \"c\\<noteq>d\" \"b\\<noteq>c\"\n  shows \"M[a\\<turnstile>c>b][c\\<turnstile>c>d] = M[c\\<turnstile>c>d][a\\<turnstile>c>b]\"\nusing a\napply(nominal_induct M avoiding: a c b d rule: trm.strong_induct)\napply(auto simp add: rename_fresh simp add: trm.inject alpha)\ndone\n\nlemma crename_interesting3:\n  shows \"M[a\\<turnstile>c>c][x\\<turnstile>n>y] = M[x\\<turnstile>n>y][a\\<turnstile>c>c]\"\napply(nominal_induct M avoiding: a c x y rule: trm.strong_induct)\napply(auto simp add: rename_fresh simp add: trm.inject alpha)\ndone\n\nlemma crename_credu:\n  assumes a: \"(M[a\\<turnstile>c>b]) \\<longrightarrow>\\<^sub>c M'\"\n  shows \"\\<exists>M0. M0[a\\<turnstile>c>b]=M' \\<and> M \\<longrightarrow>\\<^sub>c M0\"\nusing a\napply(nominal_induct M\\<equiv>\"M[a\\<turnstile>c>b]\" M' avoiding: M a b rule: c_redu.strong_induct)\napply(drule sym)\napply(drule crename_Cut)\napply(simp)\napply(simp)\napply(auto)\napply(rule_tac x=\"M'{a:=(x).N'}\" in exI)\napply(rule conjI)\napply(simp add: fresh_atm abs_fresh subst_comm fresh_prod)\napply(rule c_redu.intros)\napply(auto dest: not_fic_crename)[1]\napply(simp add: abs_fresh)\napply(simp add: abs_fresh)\napply(drule sym)\napply(drule crename_Cut)\napply(simp)\napply(simp)\napply(auto)\napply(rule_tac x=\"N'{x:=<a>.M'}\" in exI)\napply(rule conjI)\napply(simp add: fresh_atm abs_fresh subst_comm fresh_prod)\napply(rule c_redu.intros)\napply(auto dest: not_fin_crename)[1]\napply(simp add: abs_fresh)\napply(simp add: abs_fresh)\ndone\n\nlemma crename_lredu:\n  assumes a: \"(M[a\\<turnstile>c>b]) \\<longrightarrow>\\<^sub>l M'\"\n  shows \"\\<exists>M0. M0[a\\<turnstile>c>b]=M' \\<and> M \\<longrightarrow>\\<^sub>l M0\"\nusing a\napply(nominal_induct M\\<equiv>\"M[a\\<turnstile>c>b]\" M' avoiding: M a b rule: l_redu.strong_induct)\napply(drule sym)\napply(drule crename_Cut)\napply(simp add: fresh_prod fresh_atm)\napply(simp)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(case_tac \"aa=ba\")\napply(simp add: crename_id)\napply(rule l_redu.intros)\napply(simp)\napply(simp add: fresh_atm)\napply(assumption)\napply(frule crename_ax2)\napply(auto)[1]\napply(case_tac \"d=aa\")\napply(simp add: trm.inject)\napply(rule_tac x=\"M'[a\\<turnstile>c>aa]\" in exI)\napply(rule conjI)\napply(rule crename_interesting1)\napply(simp)\napply(rule l_redu.intros)\napply(simp)\napply(simp add: fresh_atm)\napply(auto dest: fic_crename simp add: fresh_prod fresh_atm)[1]\napply(simp add: trm.inject)\napply(rule_tac x=\"M'[a\\<turnstile>c>b]\" in exI)\napply(rule conjI)\napply(rule crename_interesting2)\napply(simp)\napply(simp)\napply(simp)\napply(simp)\napply(simp)\napply(rule l_redu.intros)\napply(simp)\napply(simp add: fresh_atm)\napply(auto dest: fic_crename simp add: fresh_prod fresh_atm)[1]\napply(drule sym)\napply(drule crename_Cut)\napply(simp add: fresh_prod fresh_atm)\napply(simp add: fresh_prod fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(case_tac \"aa=b\")\napply(simp add: crename_id)\napply(rule l_redu.intros)\napply(simp)\napply(simp add: fresh_atm)\napply(assumption)\napply(frule crename_ax2)\napply(auto)[1]\napply(case_tac \"d=aa\")\napply(simp add: trm.inject)\napply(simp add: trm.inject)\napply(rule_tac x=\"N'[x\\<turnstile>n>y]\" in exI)\napply(rule conjI)\napply(rule sym)\napply(rule crename_interesting3)\napply(rule l_redu.intros)\napply(simp)\napply(simp add: fresh_atm)\napply(auto dest: fin_crename simp add: fresh_prod fresh_atm)[1]\n(* LNot *)\napply(drule sym)\napply(drule crename_Cut)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(drule crename_NotR)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(drule crename_NotL)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(rule_tac x=\"Cut <b>.N'b (x).N'a\" in exI)\napply(simp add: fresh_atm)[1]\napply(rule l_redu.intros)\napply(auto simp add: fresh_prod intro: crename_fresh_interesting2)[1]\napply(auto simp add: fresh_atm fresh_prod intro: crename_fresh_interesting2)[1]\napply(auto simp add: fresh_atm fresh_prod intro: crename_fresh_interesting1)[1]\napply(auto simp add: fresh_atm fresh_prod intro: crename_fresh_interesting1)[1]\napply(simp add: fresh_atm)\napply(simp add: fresh_atm)\n(* LAnd1 *)\napply(auto dest: fin_crename simp add: fresh_prod fresh_atm)[1]\napply(drule sym)\napply(drule crename_Cut)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto)[1]\napply(drule crename_AndR)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(drule crename_AndL1)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(rule_tac x=\"Cut <a1>.M'a (x).N'a\" in exI)\napply(simp add: fresh_atm)[1]\napply(rule l_redu.intros)\napply(auto simp add: fresh_atm abs_fresh fresh_prod intro: crename_fresh_interesting1)[1]\napply(auto simp add: abs_fresh fresh_atm fresh_prod intro: crename_fresh_interesting2)[1]\napply(auto simp add: fresh_atm fresh_prod intro: crename_fresh_interesting1)[1]\napply(auto simp add: fresh_atm fresh_prod intro: crename_fresh_interesting1)[1]\napply(simp add: fresh_atm)\napply(simp add: fresh_atm)\n(* LAnd2 *)\napply(auto dest: fin_crename simp add: fresh_prod fresh_atm)[1]\napply(drule sym)\napply(drule crename_Cut)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto)[1]\napply(drule crename_AndR)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(drule crename_AndL2)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(rule_tac x=\"Cut <a2>.N'b (x).N'a\" in exI)\napply(simp add: fresh_atm)[1]\napply(rule l_redu.intros)\napply(auto simp add: fresh_atm abs_fresh fresh_prod intro: crename_fresh_interesting1)[1]\napply(auto simp add: abs_fresh fresh_atm fresh_prod intro: crename_fresh_interesting2)[1]\napply(auto simp add: fresh_atm fresh_prod intro: crename_fresh_interesting1)[1]\napply(auto simp add: fresh_atm fresh_prod intro: crename_fresh_interesting1)[1]\napply(simp add: fresh_atm)\napply(simp add: fresh_atm)\n(* LOr1 *)\napply(auto dest: fin_crename simp add: fresh_prod fresh_atm)[1]\napply(drule sym)\napply(drule crename_Cut)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto)[1]\napply(drule crename_OrL)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(drule crename_OrR1)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(auto)\napply(rule_tac x=\"Cut <a>.N' (x1).M'a\" in exI)\napply(rule conjI)\napply(simp add: abs_fresh fresh_atm)[1]\napply(rule l_redu.intros)\napply(auto simp add: fresh_atm abs_fresh fresh_prod intro: crename_fresh_interesting1)[1]\napply(auto simp add: abs_fresh fresh_atm fresh_prod intro: crename_fresh_interesting2)[1]\napply(auto simp add: abs_fresh fresh_atm fresh_prod intro: crename_fresh_interesting1)[1]\napply(auto simp add: abs_fresh fresh_atm fresh_prod intro: crename_fresh_interesting1)[1]\napply(simp add: fresh_atm)\napply(simp add: fresh_atm)\n(* LOr2 *)\napply(auto dest: fin_crename simp add: fresh_prod fresh_atm)[1]\napply(drule sym)\napply(drule crename_Cut)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto)[1]\napply(drule crename_OrL)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(drule crename_OrR2)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(auto)\napply(rule_tac x=\"Cut <a>.N' (x2).N'a\" in exI)\napply(rule conjI)\napply(simp add: abs_fresh fresh_atm)[1]\napply(rule l_redu.intros)\napply(auto simp add: fresh_atm abs_fresh fresh_prod intro: crename_fresh_interesting1)[1]\napply(auto simp add: abs_fresh fresh_atm fresh_prod intro: crename_fresh_interesting2)[1]\napply(auto simp add: abs_fresh fresh_atm fresh_prod intro: crename_fresh_interesting1)[1]\napply(auto simp add: abs_fresh fresh_atm fresh_prod intro: crename_fresh_interesting1)[1]\napply(simp add: fresh_atm)\napply(simp add: fresh_atm)\n(* ImpL *)\napply(auto dest: fin_crename simp add: fresh_prod fresh_atm)[1]\napply(drule sym)\napply(drule crename_Cut)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm abs_supp fin_supp)\napply(auto)[1]\napply(drule crename_ImpL)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(drule crename_ImpR)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(rule_tac x=\"Cut <a>.(Cut <c>.M'a (x).N') (y).N'a\" in exI)\napply(rule conjI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(rule l_redu.intros)\napply(auto simp add: fresh_atm abs_fresh abs_supp fin_supp fresh_prod intro: crename_fresh_interesting2)[1]\napply(auto simp add: abs_fresh fresh_atm abs_supp fin_supp fresh_prod intro: crename_fresh_interesting1)[1]\napply(auto simp add: abs_fresh fresh_atm abs_supp fin_supp fresh_prod intro: crename_fresh_interesting2)[1]\napply(auto simp add: abs_fresh fresh_atm abs_supp fin_supp fresh_prod intro: crename_fresh_interesting1)[1]\napply(auto simp add: abs_fresh fresh_atm abs_supp fin_supp fresh_prod intro: crename_fresh_interesting1)[1]\napply(auto simp add: abs_fresh fresh_atm abs_supp fin_supp fresh_prod intro: crename_fresh_interesting1)[1]\ndone\n\nlemma crename_aredu:\n  assumes a: \"(M[a\\<turnstile>c>b]) \\<longrightarrow>\\<^sub>a M'\" \"a\\<noteq>b\"\n  shows \"\\<exists>M0. M0[a\\<turnstile>c>b]=M' \\<and> M \\<longrightarrow>\\<^sub>a M0\"\nusing a\napply(nominal_induct \"M[a\\<turnstile>c>b]\" M' avoiding: M a b rule: a_redu.strong_induct)\napply(drule  crename_lredu)\napply(blast)\napply(drule  crename_credu)\napply(blast)\n(* Cut *)\napply(drule sym)\napply(drule crename_Cut)\napply(simp)\napply(simp)\napply(auto)[1]\napply(drule_tac x=\"M'a\" in meta_spec)\napply(drule_tac x=\"aa\" in meta_spec)\napply(drule_tac x=\"b\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"Cut <a>.M0 (x).N'\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(rule conjI)\napply(rule trans)\napply(rule crename.simps)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(drule crename_fresh_interesting2)\napply(simp add: fresh_a_redu)\napply(simp)\napply(auto)[1]\napply(drule sym)\napply(drule crename_Cut)\napply(simp)\napply(simp)\napply(auto)[1]\napply(drule_tac x=\"N'a\" in meta_spec)\napply(drule_tac x=\"aa\" in meta_spec)\napply(drule_tac x=\"b\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"Cut <a>.M' (x).M0\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(rule conjI)\napply(rule trans)\napply(rule crename.simps)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm fresh_prod)[1]\napply(drule crename_fresh_interesting1)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp add: fresh_a_redu)\napply(simp)\napply(simp)\napply(auto)[1]\n(* NotL *)\napply(drule sym)\napply(drule crename_NotL)\napply(simp)\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"aa\" in meta_spec)\napply(drule_tac x=\"b\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"NotL <a>.M0 x\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\n(* NotR *)\napply(drule sym)\napply(frule crename_NotR_aux)\napply(erule disjE)\napply(auto)[1]\napply(drule crename_NotR')\napply(simp)\napply(simp add: fresh_atm)\napply(erule disjE)\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"aa\" in meta_spec)\napply(drule_tac x=\"b\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"NotR (x).M0 a\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"aa\" in meta_spec)\napply(drule_tac x=\"a\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"NotR (x).M0 aa\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\n(* AndR *)\napply(drule sym)\napply(frule crename_AndR_aux)\napply(erule disjE)\napply(auto)[1]\napply(drule crename_AndR')\napply(simp add: fresh_prod fresh_atm)\napply(simp add: fresh_atm)\napply(simp add: fresh_atm)\napply(erule disjE)\napply(auto)[1]\napply(drule_tac x=\"M'a\" in meta_spec)\napply(drule_tac x=\"aa\" in meta_spec)\napply(drule_tac x=\"ba\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"AndR <a>.M0 <b>.N' c\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(rule trans)\napply(rule crename.simps)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto intro: fresh_a_redu)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(drule_tac x=\"M'a\" in meta_spec)\napply(drule_tac x=\"aa\" in meta_spec)\napply(drule_tac x=\"c\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"AndR <a>.M0 <b>.N' aa\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(rule trans)\napply(rule crename.simps)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto intro: fresh_a_redu)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(drule sym)\napply(frule crename_AndR_aux)\napply(erule disjE)\napply(auto)[1]\napply(drule crename_AndR')\napply(simp add: fresh_prod fresh_atm)\napply(simp add: fresh_atm)\napply(simp add: fresh_atm)\napply(erule disjE)\napply(auto)[1]\napply(drule_tac x=\"N'a\" in meta_spec)\napply(drule_tac x=\"aa\" in meta_spec)\napply(drule_tac x=\"ba\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"AndR <a>.M' <b>.M0 c\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(rule trans)\napply(rule crename.simps)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm fresh_prod)[1]\napply(auto intro: fresh_a_redu)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(drule_tac x=\"N'a\" in meta_spec)\napply(drule_tac x=\"aa\" in meta_spec)\napply(drule_tac x=\"c\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"AndR <a>.M' <b>.M0 aa\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(rule trans)\napply(rule crename.simps)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm fresh_prod)[1]\napply(auto intro: fresh_a_redu)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp)\n(* AndL1 *)\napply(drule sym)\napply(drule crename_AndL1)\napply(simp)\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"a\" in meta_spec)\napply(drule_tac x=\"b\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"AndL1 (x).M0 y\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\n(* AndL2 *)\napply(drule sym)\napply(drule crename_AndL2)\napply(simp)\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"a\" in meta_spec)\napply(drule_tac x=\"b\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"AndL2 (x).M0 y\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\n(* OrL *)\napply(drule sym)\napply(drule crename_OrL)\napply(simp)\napply(auto simp add: fresh_atm fresh_prod)[1]\napply(auto simp add: fresh_atm fresh_prod)[1]\napply(auto)[1]\napply(drule_tac x=\"M'a\" in meta_spec)\napply(drule_tac x=\"a\" in meta_spec)\napply(drule_tac x=\"b\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"OrL (x).M0 (y).N' z\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(rule trans)\napply(rule crename.simps)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm fresh_prod)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto intro: fresh_a_redu)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp)\napply(drule sym)\napply(drule crename_OrL)\napply(simp)\napply(auto simp add: fresh_atm fresh_prod)[1]\napply(auto simp add: fresh_atm fresh_prod)[1]\napply(auto)[1]\napply(drule_tac x=\"N'a\" in meta_spec)\napply(drule_tac x=\"a\" in meta_spec)\napply(drule_tac x=\"b\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"OrL (x).M' (y).M0 z\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(rule trans)\napply(rule crename.simps)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm fresh_prod)[1]\napply(auto intro: fresh_a_redu)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp)\napply(simp)\n(* OrR1 *)\napply(drule sym)\napply(frule crename_OrR1_aux)\napply(erule disjE)\napply(auto)[1]\napply(drule crename_OrR1')\napply(simp)\napply(simp add: fresh_atm)\napply(erule disjE)\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"aa\" in meta_spec)\napply(drule_tac x=\"ba\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"OrR1 <a>.M0 b\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"aa\" in meta_spec)\napply(drule_tac x=\"b\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"OrR1 <a>.M0 aa\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\n(* OrR2 *)\napply(drule sym)\napply(frule crename_OrR2_aux)\napply(erule disjE)\napply(auto)[1]\napply(drule crename_OrR2')\napply(simp)\napply(simp add: fresh_atm)\napply(erule disjE)\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"aa\" in meta_spec)\napply(drule_tac x=\"ba\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"OrR2 <a>.M0 b\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"aa\" in meta_spec)\napply(drule_tac x=\"b\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"OrR2 <a>.M0 aa\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\n(* ImpL *)\napply(drule sym)\napply(drule crename_ImpL)\napply(simp)\napply(simp)\napply(auto)[1]\napply(drule_tac x=\"M'a\" in meta_spec)\napply(drule_tac x=\"aa\" in meta_spec)\napply(drule_tac x=\"b\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"ImpL <a>.M0 (x).N' y\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(rule trans)\napply(rule crename.simps)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm fresh_prod)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto intro: fresh_a_redu)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(drule sym)\napply(drule crename_ImpL)\napply(simp)\napply(simp)\napply(auto)[1]\napply(drule_tac x=\"N'a\" in meta_spec)\napply(drule_tac x=\"aa\" in meta_spec)\napply(drule_tac x=\"b\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"ImpL <a>.M' (x).M0 y\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(rule trans)\napply(rule crename.simps)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm fresh_prod)[1]\napply(auto intro: fresh_a_redu)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp)\n(* ImpR *)\napply(drule sym)\napply(frule crename_ImpR_aux)\napply(erule disjE)\napply(auto)[1]\napply(drule crename_ImpR')\napply(simp)\napply(simp add: fresh_atm)\napply(simp add: fresh_atm)\napply(erule disjE)\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"aa\" in meta_spec)\napply(drule_tac x=\"ba\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"ImpR (x).<a>.M0 b\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"aa\" in meta_spec)\napply(drule_tac x=\"b\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"ImpR (x).<a>.M0 aa\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\ndone\n\nlemma SNa_preserved_renaming1:\n  assumes a: \"SNa M\"\n  shows \"SNa (M[a\\<turnstile>c>b])\"\nusing a\napply(induct rule: SNa_induct)\napply(case_tac \"a=b\")\napply(simp add: crename_id)\napply(rule SNaI)\napply(drule crename_aredu)\napply(blast)+\ndone\n\nlemma nrename_interesting1:\n  assumes a: \"distinct [x,y,z]\"\n  shows \"M[x\\<turnstile>n>z][z\\<turnstile>n>y] = M[z\\<turnstile>n>y][x\\<turnstile>n>y]\"\nusing a\napply(nominal_induct M avoiding: x y z rule: trm.strong_induct)\napply(auto simp add: rename_fresh simp add: trm.inject alpha)\napply(blast)\napply(blast)\napply(rotate_tac 12)\napply(drule_tac x=\"x\" in meta_spec)\napply(rotate_tac 15)\napply(drule_tac x=\"y\" in meta_spec)\napply(rotate_tac 15)\napply(drule_tac x=\"z\" in meta_spec)\napply(blast)\napply(rotate_tac 11)\napply(drule_tac x=\"x\" in meta_spec)\napply(rotate_tac 14)\napply(drule_tac x=\"y\" in meta_spec)\napply(rotate_tac 14)\napply(drule_tac x=\"z\" in meta_spec)\napply(blast)\ndone\n\nlemma nrename_interesting2:\n  assumes a: \"x\\<noteq>z\" \"x\\<noteq>u\" \"x\\<noteq>y\" \"z\\<noteq>u\" \"y\\<noteq>z\"\n  shows \"M[x\\<turnstile>n>y][z\\<turnstile>n>u] = M[z\\<turnstile>n>u][x\\<turnstile>n>y]\"\nusing a\napply(nominal_induct M avoiding: x y z u rule: trm.strong_induct)\napply(auto simp add: rename_fresh simp add: trm.inject alpha)\ndone\n\nlemma not_fic_nrename_aux:\n  assumes a: \"fic M c\" \n  shows \"fic (M[x\\<turnstile>n>y]) c\" \nusing a\napply(nominal_induct M avoiding: c x y rule: trm.strong_induct)\napply(auto dest!: fic_elims intro!: fic.intros simp add: fresh_prod fresh_atm rename_fresh abs_fresh)\ndone\n\nlemma not_fic_nrename:\n  assumes a: \"\\<not>(fic (M[x\\<turnstile>n>y]) c)\" \n  shows \"\\<not>(fic M c)\" \nusing a\napply(auto dest:  not_fic_nrename_aux)\ndone\n\nlemma fin_nrename:\n  assumes a: \"fin M z\" \"z\\<sharp>(x,y)\"\n  shows \"fin (M[x\\<turnstile>n>y]) z\" \nusing a\napply(nominal_induct M avoiding: x y z rule: trm.strong_induct)\napply(auto dest!: fin_elims intro!: fin.intros simp add: fresh_prod fresh_atm rename_fresh abs_fresh\n           split: if_splits)\ndone\n\nlemma nrename_fresh_interesting1:\n  fixes z::\"name\"\n  assumes a: \"z\\<sharp>(M[x\\<turnstile>n>y])\" \"z\\<sharp>(x,y)\"\n  shows \"z\\<sharp>M\"\nusing a\napply(nominal_induct M avoiding: x y z rule: trm.strong_induct)\napply(auto split: if_splits simp add: abs_fresh abs_supp fin_supp)\ndone\n\nlemma nrename_fresh_interesting2:\n  fixes c::\"coname\"\n  assumes a: \"c\\<sharp>(M[x\\<turnstile>n>y])\" \n  shows \"c\\<sharp>M\"\nusing a\napply(nominal_induct M avoiding: x y c rule: trm.strong_induct)\napply(auto split: if_splits simp add: abs_fresh abs_supp fin_supp fresh_atm)\ndone\n\nlemma fin_nrename2:\n  assumes a: \"fin (M[x\\<turnstile>n>y]) z\" \"z\\<sharp>(x,y)\"\n  shows \"fin M z\" \nusing a\napply(nominal_induct M avoiding: x y z rule: trm.strong_induct)\napply(auto dest!: fin_elims intro!: fin.intros simp add: fresh_prod fresh_atm rename_fresh abs_fresh\n           split: if_splits)\napply(auto dest: nrename_fresh_interesting1 simp add: fresh_atm fresh_prod)\ndone\n\nlemma nrename_Cut:\n  assumes a: \"R[x\\<turnstile>n>y] = Cut <c>.M (z).N\" \"c\\<sharp>(N,R)\" \"z\\<sharp>(x,y,M,R)\"\n  shows \"\\<exists>M' N'. R = Cut <c>.M' (z).N' \\<and> M'[x\\<turnstile>n>y] = M \\<and> N'[x\\<turnstile>n>y] = N \\<and> c\\<sharp>N' \\<and> z\\<sharp>M'\"\nusing a\napply(nominal_induct R avoiding: c y x z M N rule: trm.strong_induct)\napply(auto split: if_splits)\napply(simp add: trm.inject)\napply(auto simp add: alpha fresh_atm)\napply(rule_tac x=\"[(coname,c)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(rule_tac x=\"[(name,z)]\\<bullet>trm2\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(rule conjI)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\napply(auto simp add: fresh_atm)[1]\napply(drule sym)\napply(drule sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma nrename_NotR:\n  assumes a: \"R[x\\<turnstile>n>y] = NotR (z).N c\" \"z\\<sharp>(R,x,y)\" \n  shows \"\\<exists>N'. (R = NotR (z).N' c) \\<and> N'[x\\<turnstile>n>y] = N\" \nusing a\napply(nominal_induct R avoiding: x y c z N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\napply(rule_tac x=\"[(name,z)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma nrename_NotL:\n  assumes a: \"R[x\\<turnstile>n>y] = NotL <c>.N z\" \"c\\<sharp>R\" \"z\\<sharp>(x,y)\"\n  shows \"\\<exists>N'. (R = NotL <c>.N' z) \\<and> N'[x\\<turnstile>n>y] = N\" \nusing a\napply(nominal_induct R avoiding: x y c z N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\napply(rule_tac x=\"[(coname,c)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma nrename_NotL':\n  assumes a: \"R[x\\<turnstile>n>y] = NotL <c>.N u\" \"c\\<sharp>R\" \"x\\<noteq>y\" \n  shows \"(\\<exists>N'. (R = NotL <c>.N' u) \\<and> N'[x\\<turnstile>n>y] = N) \\<or> (\\<exists>N'. (R = NotL <c>.N' x) \\<and> y=u \\<and> N'[x\\<turnstile>n>y] = N)\"\nusing a\napply(nominal_induct R avoiding: y u c x N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm abs_fresh alpha trm.inject)\napply(rule_tac x=\"[(coname,c)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\napply(rule_tac x=\"[(coname,c)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma nrename_NotL_aux:\n  assumes a: \"R[x\\<turnstile>n>y] = NotL <c>.N u\" \n  shows \"(x=u \\<and> x=y) \\<or> (x\\<noteq>u)\" \nusing a\napply(nominal_induct R avoiding: y u c x N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\ndone\n\nlemma nrename_AndL1:\n  assumes a: \"R[x\\<turnstile>n>y] = AndL1 (z).N u\" \"z\\<sharp>(R,x,y)\" \"u\\<sharp>(x,y)\"\n  shows \"\\<exists>N'. (R = AndL1 (z).N' u) \\<and> N'[x\\<turnstile>n>y] = N\" \nusing a\napply(nominal_induct R avoiding: z u x y N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\napply(rule_tac x=\"[(name1,z)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma nrename_AndL1':\n  assumes a: \"R[x\\<turnstile>n>y] = AndL1 (v).N u\" \"v\\<sharp>(R,u,x,y)\" \"x\\<noteq>y\" \n  shows \"(\\<exists>N'. (R = AndL1 (v).N' u) \\<and> N'[x\\<turnstile>n>y] = N) \\<or> (\\<exists>N'. (R = AndL1 (v).N' x) \\<and> y=u \\<and> N'[x\\<turnstile>n>y] = N)\"\nusing a\napply(nominal_induct R avoiding: y u v x N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm abs_fresh alpha trm.inject)\napply(rule_tac x=\"[(name1,v)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\napply(rule_tac x=\"[(name1,v)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma nrename_AndL1_aux:\n  assumes a: \"R[x\\<turnstile>n>y] = AndL1 (v).N u\" \n  shows \"(x=u \\<and> x=y) \\<or> (x\\<noteq>u)\" \nusing a\napply(nominal_induct R avoiding: y u v x N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\ndone\n\nlemma nrename_AndL2:\n  assumes a: \"R[x\\<turnstile>n>y] = AndL2 (z).N u\" \"z\\<sharp>(R,x,y)\" \"u\\<sharp>(x,y)\"\n  shows \"\\<exists>N'. (R = AndL2 (z).N' u) \\<and> N'[x\\<turnstile>n>y] = N\" \nusing a\napply(nominal_induct R avoiding: z u x y N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\napply(rule_tac x=\"[(name1,z)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma nrename_AndL2':\n  assumes a: \"R[x\\<turnstile>n>y] = AndL2 (v).N u\" \"v\\<sharp>(R,u,x,y)\" \"x\\<noteq>y\" \n  shows \"(\\<exists>N'. (R = AndL2 (v).N' u) \\<and> N'[x\\<turnstile>n>y] = N) \\<or> (\\<exists>N'. (R = AndL2 (v).N' x) \\<and> y=u \\<and> N'[x\\<turnstile>n>y] = N)\"\nusing a\napply(nominal_induct R avoiding: y u v x N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm abs_fresh alpha trm.inject)\napply(rule_tac x=\"[(name1,v)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\napply(rule_tac x=\"[(name1,v)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma nrename_AndL2_aux:\n  assumes a: \"R[x\\<turnstile>n>y] = AndL2 (v).N u\" \n  shows \"(x=u \\<and> x=y) \\<or> (x\\<noteq>u)\" \nusing a\napply(nominal_induct R avoiding: y u v x N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\ndone\n\nlemma nrename_AndR:\n  assumes a: \"R[x\\<turnstile>n>y] = AndR <c>.M <d>.N e\" \"c\\<sharp>(d,e,N,R)\" \"d\\<sharp>(c,e,M,R)\" \n  shows \"\\<exists>M' N'. R = AndR <c>.M' <d>.N' e \\<and> M'[x\\<turnstile>n>y] = M \\<and> N'[x\\<turnstile>n>y] = N \\<and> c\\<sharp>N' \\<and> d\\<sharp>M'\"\nusing a\napply(nominal_induct R avoiding: x y c d e M N rule: trm.strong_induct)\napply(auto split: if_splits simp add: trm.inject alpha)\napply(simp add: fresh_atm fresh_prod)\napply(rule_tac x=\"[(coname1,c)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(rule_tac x=\"[(coname1,c)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(rule_tac x=\"[(coname2,d)]\\<bullet>trm2\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\napply(drule_tac s=\"trm2[x\\<turnstile>n>y]\" in  sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma nrename_OrR1:\n  assumes a: \"R[x\\<turnstile>n>y] = OrR1 <c>.N d\" \"c\\<sharp>(R,d)\" \n  shows \"\\<exists>N'. (R = OrR1 <c>.N' d) \\<and> N'[x\\<turnstile>n>y] = N\" \nusing a\napply(nominal_induct R avoiding: x y c d N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\napply(rule_tac x=\"[(coname1,c)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma nrename_OrR2:\n  assumes a: \"R[x\\<turnstile>n>y] = OrR2 <c>.N d\" \"c\\<sharp>(R,d)\" \n  shows \"\\<exists>N'. (R = OrR2 <c>.N' d) \\<and> N'[x\\<turnstile>n>y] = N\" \nusing a\napply(nominal_induct R avoiding: x y c d N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\napply(rule_tac x=\"[(coname1,c)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma nrename_OrL:\n  assumes a: \"R[u\\<turnstile>n>v] = OrL (x).M (y).N z\" \"x\\<sharp>(y,z,u,v,N,R)\" \"y\\<sharp>(x,z,u,v,M,R)\" \"z\\<sharp>(u,v)\"\n  shows \"\\<exists>M' N'. R = OrL (x).M' (y).N' z \\<and> M'[u\\<turnstile>n>v] = M \\<and> N'[u\\<turnstile>n>v] = N \\<and> x\\<sharp>N' \\<and> y\\<sharp>M'\"\nusing a\napply(nominal_induct R avoiding: u v x y z M N rule: trm.strong_induct)\napply(auto split: if_splits simp add: trm.inject alpha fresh_prod fresh_atm)\napply(rule_tac x=\"[(name1,x)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(rule_tac x=\"[(name2,y)]\\<bullet>trm2\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(drule sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\napply(drule_tac s=\"trm2[u\\<turnstile>n>v]\" in  sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma nrename_OrL':\n  assumes a: \"R[x\\<turnstile>n>y] = OrL (v).M (w).N u\" \"v\\<sharp>(R,N,u,x,y)\" \"w\\<sharp>(R,M,u,x,y)\" \"x\\<noteq>y\" \n  shows \"(\\<exists>M' N'. (R = OrL (v).M' (w).N' u) \\<and> M'[x\\<turnstile>n>y] = M \\<and> N'[x\\<turnstile>n>y] = N) \\<or> \n         (\\<exists>M' N'. (R = OrL (v).M' (w).N' x) \\<and> y=u \\<and> M'[x\\<turnstile>n>y] = M \\<and> N'[x\\<turnstile>n>y] = N)\"\nusing a\napply(nominal_induct R avoiding: y x u v w M N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm abs_fresh alpha trm.inject)\napply(rule_tac x=\"[(name1,v)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(rule_tac x=\"[(name2,w)]\\<bullet>trm2\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(rule conjI)\napply(drule sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\napply(drule_tac s=\"trm2[x\\<turnstile>n>u]\" in sym)\napply(drule_tac pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\napply(rule_tac x=\"[(name1,v)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(rule_tac x=\"[(name2,w)]\\<bullet>trm2\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(rule conjI)\napply(drule sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\napply(drule_tac s=\"trm2[x\\<turnstile>n>y]\" in sym)\napply(drule_tac pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma nrename_OrL_aux:\n  assumes a: \"R[x\\<turnstile>n>y] = OrL (v).M (w).N u\" \n  shows \"(x=u \\<and> x=y) \\<or> (x\\<noteq>u)\" \nusing a\napply(nominal_induct R avoiding: y x w u v M N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\ndone\n\nlemma nrename_ImpL:\n  assumes a: \"R[x\\<turnstile>n>y] = ImpL <c>.M (u).N z\" \"c\\<sharp>(N,R)\" \"u\\<sharp>(y,x,z,M,R)\" \"z\\<sharp>(x,y)\"\n  shows \"\\<exists>M' N'. R = ImpL <c>.M' (u).N' z \\<and> M'[x\\<turnstile>n>y] = M \\<and> N'[x\\<turnstile>n>y] = N \\<and> c\\<sharp>N' \\<and> u\\<sharp>M'\"\nusing a\napply(nominal_induct R avoiding: u x c y z M N rule: trm.strong_induct)\napply(auto split: if_splits simp add: trm.inject alpha fresh_prod fresh_atm)\napply(rule_tac x=\"[(coname,c)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(rule_tac x=\"[(name1,u)]\\<bullet>trm2\" in exI)\napply(perm_simp)\napply(auto simp add: abs_fresh fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\napply(drule_tac s=\"trm2[x\\<turnstile>n>y]\" in  sym)\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm fresh_prod fresh_atm)\ndone\n\nlemma nrename_ImpL':\n  assumes a: \"R[x\\<turnstile>n>y] = ImpL <c>.M (w).N u\" \"c\\<sharp>(R,N)\" \"w\\<sharp>(R,M,u,x,y)\" \"x\\<noteq>y\" \n  shows \"(\\<exists>M' N'. (R = ImpL <c>.M' (w).N' u) \\<and> M'[x\\<turnstile>n>y] = M \\<and> N'[x\\<turnstile>n>y] = N) \\<or> \n         (\\<exists>M' N'. (R = ImpL <c>.M' (w).N' x) \\<and> y=u \\<and> M'[x\\<turnstile>n>y] = M \\<and> N'[x\\<turnstile>n>y] = N)\"\nusing a\napply(nominal_induct R avoiding: y x u c w M N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm abs_fresh alpha trm.inject)\napply(rule_tac x=\"[(coname,c)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(rule_tac x=\"[(name1,w)]\\<bullet>trm2\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(rule conjI)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\napply(drule_tac s=\"trm2[x\\<turnstile>n>u]\" in sym)\napply(drule_tac pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\napply(rule_tac x=\"[(coname,c)]\\<bullet>trm1\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(rule_tac x=\"[(name1,w)]\\<bullet>trm2\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(rule conjI)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(simp add: eqvts calc_atm)\napply(drule_tac s=\"trm2[x\\<turnstile>n>y]\" in sym)\napply(drule_tac pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma nrename_ImpL_aux:\n  assumes a: \"R[x\\<turnstile>n>y] = ImpL <c>.M (w).N u\" \n  shows \"(x=u \\<and> x=y) \\<or> (x\\<noteq>u)\" \nusing a\napply(nominal_induct R avoiding: y x w u c M N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm alpha abs_fresh trm.inject)\ndone\n\nlemma nrename_ImpR:\n  assumes a: \"R[u\\<turnstile>n>v] = ImpR (x).<c>.N d\" \"c\\<sharp>(R,d)\" \"x\\<sharp>(R,u,v)\" \n  shows \"\\<exists>N'. (R = ImpR (x).<c>.N' d) \\<and> N'[u\\<turnstile>n>v] = N\" \nusing a\napply(nominal_induct R avoiding: u v x c d N rule: trm.strong_induct)\napply(auto split: if_splits simp add: fresh_prod fresh_atm abs_perm alpha abs_fresh trm.inject)\napply(rule_tac x=\"[(name,x)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_fresh fresh_left calc_atm fresh_prod)\napply(rule_tac x=\"[(name,x)]\\<bullet>[(coname1, c)]\\<bullet>trm\" in exI)\napply(perm_simp)\napply(simp add: abs_supp fin_supp abs_fresh fresh_left calc_atm fresh_prod)\napply(drule sym)\napply(drule pt_bij1[OF pt_coname_inst,OF at_coname_inst])\napply(drule pt_bij1[OF pt_name_inst,OF at_name_inst])\napply(simp add: eqvts calc_atm)\ndone\n\nlemma nrename_credu:\n  assumes a: \"(M[x\\<turnstile>n>y]) \\<longrightarrow>\\<^sub>c M'\"\n  shows \"\\<exists>M0. M0[x\\<turnstile>n>y]=M' \\<and> M \\<longrightarrow>\\<^sub>c M0\"\nusing a\napply(nominal_induct M\\<equiv>\"M[x\\<turnstile>n>y]\" M' avoiding: M x y rule: c_redu.strong_induct)\napply(drule sym)\napply(drule nrename_Cut)\napply(simp)\napply(simp)\napply(auto)\napply(rule_tac x=\"M'{a:=(x).N'}\" in exI)\napply(rule conjI)\napply(simp add: fresh_atm abs_fresh subst_comm fresh_prod)\napply(rule c_redu.intros)\napply(auto dest: not_fic_nrename)[1]\napply(simp add: abs_fresh)\napply(simp add: abs_fresh)\napply(drule sym)\napply(drule nrename_Cut)\napply(simp)\napply(simp)\napply(auto)\napply(rule_tac x=\"N'{x:=<a>.M'}\" in exI)\napply(rule conjI)\napply(simp add: fresh_atm abs_fresh subst_comm fresh_prod)\napply(rule c_redu.intros)\napply(auto)\napply(drule_tac x=\"xa\" and y=\"y\" in fin_nrename)\napply(auto simp add: fresh_prod abs_fresh)\ndone\n\nlemma nrename_ax2:\n  assumes a: \"N[x\\<turnstile>n>y] = Ax z c\"\n  shows \"\\<exists>z. N = Ax z c\"\nusing a\napply(nominal_induct N avoiding: x y rule: trm.strong_induct)\napply(auto split: if_splits)\napply(simp add: trm.inject)\ndone\n\nlemma fic_nrename:\n  assumes a: \"fic (M[x\\<turnstile>n>y]) c\" \n  shows \"fic M c\" \nusing a\napply(nominal_induct M avoiding: c x y rule: trm.strong_induct)\napply(auto dest!: fic_elims intro!: fic.intros simp add: fresh_prod fresh_atm rename_fresh abs_fresh\n           split: if_splits)\napply(auto dest: nrename_fresh_interesting2 simp add: fresh_prod fresh_atm)\ndone\n\nlemma nrename_lredu:\n  assumes a: \"(M[x\\<turnstile>n>y]) \\<longrightarrow>\\<^sub>l M'\"\n  shows \"\\<exists>M0. M0[x\\<turnstile>n>y]=M' \\<and> M \\<longrightarrow>\\<^sub>l M0\"\nusing a\napply(nominal_induct M\\<equiv>\"M[x\\<turnstile>n>y]\" M' avoiding: M x y rule: l_redu.strong_induct)\napply(drule sym)\napply(drule nrename_Cut)\napply(simp add: fresh_prod fresh_atm)\napply(simp)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(case_tac \"xa=y\")\napply(simp add: nrename_id)\napply(rule l_redu.intros)\napply(simp)\napply(simp add: fresh_atm)\napply(assumption)\napply(frule nrename_ax2)\napply(auto)[1]\napply(case_tac \"z=xa\")\napply(simp add: trm.inject)\napply(simp)\napply(rule_tac x=\"M'[a\\<turnstile>c>b]\" in exI)\napply(rule conjI)\napply(rule crename_interesting3)\napply(rule l_redu.intros)\napply(simp)\napply(simp add: fresh_atm)\napply(auto dest: fic_nrename simp add: fresh_prod fresh_atm)[1]\napply(drule sym)\napply(drule nrename_Cut)\napply(simp add: fresh_prod fresh_atm)\napply(simp add: fresh_prod fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(case_tac \"xa=ya\")\napply(simp add: nrename_id)\napply(rule l_redu.intros)\napply(simp)\napply(simp add: fresh_atm)\napply(assumption)\napply(frule nrename_ax2)\napply(auto)[1]\napply(case_tac \"z=xa\")\napply(simp add: trm.inject)\napply(rule_tac x=\"N'[x\\<turnstile>n>xa]\" in exI)\napply(rule conjI)\napply(rule nrename_interesting1)\napply(auto)[1]\napply(rule l_redu.intros)\napply(simp)\napply(simp add: fresh_atm)\napply(auto dest: fin_nrename2 simp add: fresh_prod fresh_atm)[1]\napply(simp add: trm.inject)\napply(rule_tac x=\"N'[x\\<turnstile>n>y]\" in exI)\napply(rule conjI)\napply(rule nrename_interesting2)\napply(simp_all)\napply(rule l_redu.intros)\napply(simp)\napply(simp add: fresh_atm)\napply(auto dest: fin_nrename2 simp add: fresh_prod fresh_atm)[1]\n(* LNot *)\napply(drule sym)\napply(drule nrename_Cut)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(drule nrename_NotR)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(drule nrename_NotL)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(rule_tac x=\"Cut <b>.N'b (x).N'a\" in exI)\napply(simp add: fresh_atm)[1]\napply(rule l_redu.intros)\napply(auto simp add: fresh_prod fresh_atm intro: nrename_fresh_interesting1)[1]\napply(auto simp add: fresh_atm fresh_prod intro: nrename_fresh_interesting1)[1]\napply(auto simp add: fresh_atm fresh_prod intro: nrename_fresh_interesting2)[1]\napply(auto simp add: fresh_atm fresh_prod intro: nrename_fresh_interesting2)[1]\napply(simp add: fresh_atm)\napply(simp add: fresh_atm)\n(* LAnd1 *)\napply(auto dest: fin_crename simp add: fresh_prod fresh_atm)[1]\napply(drule sym)\napply(drule nrename_Cut)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto)[1]\napply(drule nrename_AndR)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(drule nrename_AndL1)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(rule_tac x=\"Cut <a1>.M'a (x).N'b\" in exI)\napply(simp add: fresh_atm)[1]\napply(rule l_redu.intros)\napply(auto simp add: fresh_atm abs_fresh fresh_prod intro: nrename_fresh_interesting2)[1]\napply(auto simp add: abs_fresh fresh_atm fresh_prod intro: nrename_fresh_interesting1)[1]\napply(auto simp add: fresh_atm fresh_prod intro: nrename_fresh_interesting1)[1]\napply(auto simp add: fresh_atm fresh_prod intro: nrename_fresh_interesting1)[1]\napply(auto simp add: fresh_atm fresh_prod intro: nrename_fresh_interesting1)[1]\napply(simp add: fresh_atm)\n(* LAnd2 *)\napply(auto dest: fin_crename simp add: fresh_prod fresh_atm)[1]\napply(drule sym)\napply(drule nrename_Cut)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto)[1]\napply(drule nrename_AndR)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(drule nrename_AndL2)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(rule_tac x=\"Cut <a2>.N'a (x).N'b\" in exI)\napply(simp add: fresh_atm)[1]\napply(rule l_redu.intros)\napply(auto simp add: fresh_atm abs_fresh fresh_prod intro: nrename_fresh_interesting2)[1]\napply(auto simp add: abs_fresh fresh_atm fresh_prod intro: nrename_fresh_interesting1)[1]\napply(auto simp add: fresh_atm fresh_prod intro: nrename_fresh_interesting1)[1]\napply(auto simp add: fresh_atm fresh_prod intro: nrename_fresh_interesting1)[1]\napply(auto simp add: fresh_atm fresh_prod intro: nrename_fresh_interesting1)[1]\napply(simp add: fresh_atm)\n(* LOr1 *)\napply(auto dest: fin_crename simp add: fresh_prod fresh_atm)[1]\napply(drule sym)\napply(drule nrename_Cut)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto)[1]\napply(drule nrename_OrL)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(drule nrename_OrR1)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(rule_tac x=\"Cut <a>.N' (x1).M'a\" in exI)\napply(rule conjI)\napply(simp add: abs_fresh fresh_atm)[1]\napply(rule l_redu.intros)\napply(auto simp add: fresh_atm abs_fresh fresh_prod intro: nrename_fresh_interesting2)[1]\napply(auto simp add: abs_fresh fresh_atm fresh_prod intro: nrename_fresh_interesting1)[1]\napply(auto simp add: abs_fresh fresh_atm fresh_prod intro: nrename_fresh_interesting1)[1]\napply(auto simp add: abs_fresh fresh_atm fresh_prod intro: nrename_fresh_interesting1)[1]\napply(simp add: fresh_atm)\napply(simp add: fresh_atm)\n(* LOr2 *)\napply(auto dest: fin_crename simp add: fresh_prod fresh_atm)[1]\napply(drule sym)\napply(drule nrename_Cut)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto)[1]\napply(drule nrename_OrL)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(drule nrename_OrR2)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(rule_tac x=\"Cut <a>.N' (x2).N'a\" in exI)\napply(rule conjI)\napply(simp add: abs_fresh fresh_atm)[1]\napply(rule l_redu.intros)\napply(auto simp add: fresh_atm abs_fresh fresh_prod intro: nrename_fresh_interesting2)[1]\napply(auto simp add: abs_fresh fresh_atm fresh_prod intro: nrename_fresh_interesting1)[1]\napply(auto simp add: abs_fresh fresh_atm fresh_prod intro: nrename_fresh_interesting1)[1]\napply(auto simp add: abs_fresh fresh_atm fresh_prod intro: nrename_fresh_interesting1)[1]\napply(simp add: fresh_atm)\napply(simp add: fresh_atm)\n(* ImpL *)\napply(auto dest: fin_crename simp add: fresh_prod fresh_atm)[1]\napply(drule sym) \napply(drule nrename_Cut)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm abs_supp fin_supp)\napply(auto)[1]\napply(drule nrename_ImpL)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(drule nrename_ImpR)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(simp add: fresh_prod abs_fresh fresh_atm)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)[1]\napply(rule_tac x=\"Cut <a>.(Cut <c>.M'a (x).N') (y).N'a\" in exI)\napply(rule conjI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(rule l_redu.intros)\napply(auto simp add: fresh_atm abs_fresh abs_supp fin_supp fresh_prod intro: nrename_fresh_interesting1)[1]\napply(auto simp add: abs_fresh fresh_atm abs_supp fin_supp fresh_prod intro: nrename_fresh_interesting2)[1]\napply(auto simp add: abs_fresh fresh_atm abs_supp fin_supp fresh_prod intro: nrename_fresh_interesting1)[1]\napply(auto simp add: abs_fresh fresh_atm abs_supp fin_supp fresh_prod intro: nrename_fresh_interesting2)[1]\napply(auto simp add: abs_fresh fresh_atm abs_supp fin_supp fresh_prod intro: nrename_fresh_interesting2)[1]\napply(auto simp add: abs_fresh fresh_atm abs_supp fin_supp fresh_prod intro: nrename_fresh_interesting2)[1]\ndone\n\nlemma nrename_aredu:\n  assumes a: \"(M[x\\<turnstile>n>y]) \\<longrightarrow>\\<^sub>a M'\" \"x\\<noteq>y\"\n  shows \"\\<exists>M0. M0[x\\<turnstile>n>y]=M' \\<and> M \\<longrightarrow>\\<^sub>a M0\"\nusing a\napply(nominal_induct \"M[x\\<turnstile>n>y]\" M' avoiding: M x y rule: a_redu.strong_induct)\napply(drule  nrename_lredu)\napply(blast)\napply(drule  nrename_credu)\napply(blast)\n(* Cut *)\napply(drule sym)\napply(drule nrename_Cut)\napply(simp)\napply(simp)\napply(auto)[1]\napply(drule_tac x=\"M'a\" in meta_spec)\napply(drule_tac x=\"xa\" in meta_spec)\napply(drule_tac x=\"y\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"Cut <a>.M0 (x).N'\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(rule conjI)\napply(rule trans)\napply(rule nrename.simps)\napply(drule nrename_fresh_interesting2)\napply(simp add: fresh_a_redu)\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(drule nrename_fresh_interesting1)\napply(simp add: fresh_prod fresh_atm)\napply(simp add: fresh_a_redu)\napply(simp)\napply(auto)[1]\napply(drule sym)\napply(drule nrename_Cut)\napply(simp)\napply(simp)\napply(auto)[1]\napply(drule_tac x=\"N'a\" in meta_spec)\napply(drule_tac x=\"xa\" in meta_spec)\napply(drule_tac x=\"y\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"Cut <a>.M' (x).M0\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(rule conjI)\napply(rule trans)\napply(rule nrename.simps)\napply(simp add: fresh_a_redu)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm fresh_prod)[1]\napply(simp)\napply(auto)[1]\n(* NotL *)\napply(drule sym)\napply(frule nrename_NotL_aux)\napply(erule disjE)\napply(auto)[1]\napply(drule nrename_NotL')\napply(simp)\napply(simp add: fresh_atm)\napply(erule disjE)\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"xa\" in meta_spec)\napply(drule_tac x=\"y\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"NotL <a>.M0 x\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"xa\" in meta_spec)\napply(drule_tac x=\"x\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"NotL <a>.M0 xa\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\n(* NotR *)\napply(drule sym)\napply(drule nrename_NotR)\napply(simp)\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"xa\" in meta_spec)\napply(drule_tac x=\"y\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"NotR (x).M0 a\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\n(* AndR *)\napply(drule sym)\napply(drule nrename_AndR)\napply(simp)\napply(auto simp add: fresh_atm fresh_prod)[1]\napply(auto simp add: fresh_atm fresh_prod)[1]\napply(auto)[1]\napply(drule_tac x=\"M'a\" in meta_spec)\napply(drule_tac x=\"x\" in meta_spec)\napply(drule_tac x=\"y\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"AndR <a>.M0 <b>.N' c\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(rule trans)\napply(rule nrename.simps)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm fresh_prod)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto intro: fresh_a_redu)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp)\napply(drule sym)\napply(drule nrename_AndR)\napply(simp)\napply(auto simp add: fresh_atm fresh_prod)[1]\napply(auto simp add: fresh_atm fresh_prod)[1]\napply(auto)[1]\napply(drule_tac x=\"N'a\" in meta_spec)\napply(drule_tac x=\"x\" in meta_spec)\napply(drule_tac x=\"y\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"AndR <a>.M' <b>.M0 c\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(rule trans)\napply(rule nrename.simps)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm fresh_prod)[1]\napply(auto intro: fresh_a_redu)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp)\napply(simp)\n(* AndL1 *)\napply(drule sym)\napply(frule nrename_AndL1_aux)\napply(erule disjE)\napply(auto)[1]\napply(drule nrename_AndL1')\napply(simp)\napply(simp add: fresh_atm)\napply(erule disjE)\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"xa\" in meta_spec)\napply(drule_tac x=\"ya\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"AndL1 (x).M0 y\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"xa\" in meta_spec)\napply(drule_tac x=\"y\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"AndL1 (x).M0 xa\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\n(* AndL2 *)\napply(drule sym)\napply(frule nrename_AndL2_aux)\napply(erule disjE)\napply(auto)[1]\napply(drule nrename_AndL2')\napply(simp)\napply(simp add: fresh_atm)\napply(erule disjE)\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"xa\" in meta_spec)\napply(drule_tac x=\"ya\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"AndL2 (x).M0 y\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"xa\" in meta_spec)\napply(drule_tac x=\"y\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"AndL2 (x).M0 xa\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\n(* OrL *)\napply(drule sym)\napply(frule nrename_OrL_aux)\napply(erule disjE)\napply(auto)[1]\napply(drule nrename_OrL')\napply(simp add: fresh_prod fresh_atm)\napply(simp add: fresh_atm)\napply(simp add: fresh_atm)\napply(erule disjE)\napply(auto)[1]\napply(drule_tac x=\"M'a\" in meta_spec)\napply(drule_tac x=\"xa\" in meta_spec)\napply(drule_tac x=\"ya\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"OrL (x).M0 (y).N' z\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(rule trans)\napply(rule nrename.simps)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto intro: fresh_a_redu)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(drule_tac x=\"M'a\" in meta_spec)\napply(drule_tac x=\"xa\" in meta_spec)\napply(drule_tac x=\"z\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"OrL (x).M0 (y).N' xa\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(rule trans)\napply(rule nrename.simps)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto intro: fresh_a_redu)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(drule sym)\napply(frule nrename_OrL_aux)\napply(erule disjE)\napply(auto)[1]\napply(drule nrename_OrL')\napply(simp add: fresh_prod fresh_atm)\napply(simp add: fresh_atm)\napply(simp add: fresh_atm)\napply(erule disjE)\napply(auto)[1]\napply(drule_tac x=\"N'a\" in meta_spec)\napply(drule_tac x=\"xa\" in meta_spec)\napply(drule_tac x=\"ya\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"OrL (x).M' (y).M0 z\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(rule trans)\napply(rule nrename.simps)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm fresh_prod)[1]\napply(auto intro: fresh_a_redu)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(drule_tac x=\"N'a\" in meta_spec)\napply(drule_tac x=\"xa\" in meta_spec)\napply(drule_tac x=\"z\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"OrL (x).M' (y).M0 xa\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(rule trans)\napply(rule nrename.simps)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm fresh_prod)[1]\napply(auto intro: fresh_a_redu)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp)\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\n(* OrR1 *)\napply(drule sym)\napply(drule nrename_OrR1)\napply(simp)\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"x\" in meta_spec)\napply(drule_tac x=\"y\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"OrR1 <a>.M0 b\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\n(* OrR2 *)\napply(drule sym)\napply(drule nrename_OrR2)\napply(simp)\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"x\" in meta_spec)\napply(drule_tac x=\"y\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"OrR2 <a>.M0 b\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\n(* ImpL *)\napply(drule sym)\napply(frule nrename_ImpL_aux)\napply(erule disjE)\napply(auto)[1]\napply(drule nrename_ImpL')\napply(simp add: fresh_prod fresh_atm)\napply(simp add: fresh_atm)\napply(simp add: fresh_atm)\napply(erule disjE)\napply(auto)[1]\napply(drule_tac x=\"M'a\" in meta_spec)\napply(drule_tac x=\"xa\" in meta_spec)\napply(drule_tac x=\"ya\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"ImpL <a>.M0 (x).N' y\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(rule trans)\napply(rule nrename.simps)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto intro: fresh_a_redu)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(drule_tac x=\"M'a\" in meta_spec)\napply(drule_tac x=\"xa\" in meta_spec)\napply(drule_tac x=\"y\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"ImpL <a>.M0 (x).N' xa\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(rule trans)\napply(rule nrename.simps)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto intro: fresh_a_redu)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(drule sym)\napply(frule nrename_ImpL_aux)\napply(erule disjE)\napply(auto)[1]\napply(drule nrename_ImpL')\napply(simp add: fresh_prod fresh_atm)\napply(simp add: fresh_atm)\napply(simp add: fresh_atm)\napply(erule disjE)\napply(auto)[1]\napply(drule_tac x=\"N'a\" in meta_spec)\napply(drule_tac x=\"xa\" in meta_spec)\napply(drule_tac x=\"ya\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"ImpL <a>.M' (x).M0 y\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(rule trans)\napply(rule nrename.simps)\napply(auto intro: fresh_a_redu)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(drule_tac x=\"N'a\" in meta_spec)\napply(drule_tac x=\"xa\" in meta_spec)\napply(drule_tac x=\"y\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"ImpL <a>.M' (x).M0 xa\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\napply(rule trans)\napply(rule nrename.simps)\napply(auto intro: fresh_a_redu)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(simp add: fresh_prod abs_fresh abs_supp fin_supp fresh_atm)[1]\n(* ImpR *)\napply(drule sym)\napply(drule nrename_ImpR)\napply(simp)\napply(simp)\napply(auto)[1]\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"xa\" in meta_spec)\napply(drule_tac x=\"y\" in meta_spec)\napply(auto)[1]\napply(rule_tac x=\"ImpR (x).<a>.M0 b\" in exI)\napply(simp add: abs_fresh abs_supp fin_supp fresh_atm)[1]\napply(auto)[1]\ndone\n\nlemma SNa_preserved_renaming2:\n  assumes a: \"SNa N\"\n  shows \"SNa (N[x\\<turnstile>n>y])\"\nusing a\napply(induct rule: SNa_induct)\napply(case_tac \"x=y\")\napply(simp add: nrename_id)\napply(rule SNaI)\napply(drule nrename_aredu)\napply(blast)+\ndone\n\ntext \\<open>helper-stuff to set up the induction\\<close>\n\nabbreviation\n  SNa_set :: \"trm set\"\nwhere\n  \"SNa_set \\<equiv> {M. SNa M}\"\n\nabbreviation\n  A_Redu_set :: \"(trm\\<times>trm) set\"\nwhere\n \"A_Redu_set \\<equiv> {(N,M)| M N. M \\<longrightarrow>\\<^sub>a N}\"\n\nlemma SNa_elim:\n  assumes a: \"SNa M\"\n  shows \"(\\<forall>M. (\\<forall>N. M \\<longrightarrow>\\<^sub>a N \\<longrightarrow> P N)\\<longrightarrow> P M) \\<longrightarrow> P M\"\nusing a\nby (induct rule: SNa.induct) (blast)\n\nlemma wf_SNa_restricted:\n  shows \"wf (A_Redu_set \\<inter> (UNIV \\<times> SNa_set))\"\napply(unfold wf_def)\napply(intro strip)\napply(case_tac \"SNa x\")\napply(simp (no_asm_use))\napply(drule_tac P=\"P\" in SNa_elim)\napply(erule mp)\napply(blast)\n(* other case *)\napply(drule_tac x=\"x\" in spec)\napply(erule mp)\napply(fast)\ndone\n\ndefinition SNa_Redu :: \"(trm \\<times> trm) set\" where\n  \"SNa_Redu \\<equiv> A_Redu_set \\<inter> (UNIV \\<times> SNa_set)\"\n\nlemma wf_SNa_Redu:\n  shows \"wf SNa_Redu\"\napply(unfold SNa_Redu_def)\napply(rule wf_SNa_restricted)\ndone\n\nlemma wf_measure_triple:\nshows \"wf ((measure size) <*lex*> SNa_Redu <*lex*> SNa_Redu)\"\nby (auto intro: wf_SNa_Redu)\n\nlemma my_wf_induct_triple: \n assumes a: \" wf(r1 <*lex*> r2 <*lex*> r3)\"           \n and     b: \"\\<And>x. \\<lbrakk>\\<And>y. ((fst y,fst (snd y),snd (snd y)),(fst x,fst (snd x), snd (snd x))) \n                                    \\<in> (r1 <*lex*> r2 <*lex*> r3) \\<longrightarrow> P y\\<rbrakk> \\<Longrightarrow> P x\"  \n shows \"P x\"\nusing a\napply(induct x rule: wf_induct_rule)\napply(rule b)\napply(simp)\ndone\n\nlemma my_wf_induct_triple': \n assumes a: \" wf(r1 <*lex*> r2 <*lex*> r3)\"           \n and    b: \"\\<And>x1 x2 x3. \\<lbrakk>\\<And>y1 y2 y3. ((y1,y2,y3),(x1,x2,x3)) \\<in> (r1 <*lex*> r2 <*lex*> r3) \\<longrightarrow> P (y1,y2,y3)\\<rbrakk> \n             \\<Longrightarrow> P (x1,x2,x3)\"  \n shows \"P (x1,x2,x3)\"\napply(rule_tac my_wf_induct_triple[OF a])\napply(case_tac x rule: prod.exhaust)\napply(simp)\napply(rename_tac p a b)\napply(case_tac b)\napply(simp)\napply(rule b)\napply(blast)\ndone\n\nlemma my_wf_induct_triple'': \n assumes a: \" wf(r1 <*lex*> r2 <*lex*> r3)\"           \n and     b: \"\\<And>x1 x2 x3. \\<lbrakk>\\<And>y1 y2 y3. ((y1,y2,y3),(x1,x2,x3)) \\<in> (r1 <*lex*> r2 <*lex*> r3) \\<longrightarrow> P y1 y2 y3\\<rbrakk>\n               \\<Longrightarrow> P x1 x2 x3\"  \n shows \"P x1 x2 x3\"\napply(rule_tac my_wf_induct_triple'[where P=\"\\<lambda>(x1,x2,x3). P x1 x2 x3\", simplified])\napply(rule a)\napply(rule b)\napply(auto)\ndone\n\nlemma excluded_m:\n  assumes a: \"<a>:M \\<in> (\\<parallel><B>\\<parallel>)\" \"(x):N \\<in> (\\<parallel>(B)\\<parallel>)\"\n  shows \"(<a>:M \\<in> BINDINGc B (\\<parallel>(B)\\<parallel>) \\<or> (x):N \\<in> BINDINGn B (\\<parallel><B>\\<parallel>))\n      \\<or>\\<not>(<a>:M \\<in> BINDINGc B (\\<parallel>(B)\\<parallel>) \\<or> (x):N \\<in> BINDINGn B (\\<parallel><B>\\<parallel>))\"\nby (blast)\n\nlemma tricky_subst:\n  assumes a1: \"b\\<sharp>(c,N)\"\n  and     a2: \"z\\<sharp>(x,P)\"\n  and     a3: \"M\\<noteq>Ax z b\"\n  shows \"(Cut <c>.N (z).M){b:=(x).P} = Cut <c>.N (z).(M{b:=(x).P})\"\nusing a1 a2 a3\napply -\napply(generate_fresh \"coname\")\napply(subgoal_tac \"Cut <c>.N (z).M = Cut <ca>.([(ca,c)]\\<bullet>N) (z).M\")\napply(simp)\napply(rule trans)\napply(rule better_Cut_substc)\napply(simp)\napply(simp add: abs_fresh)\napply(simp)\napply(subgoal_tac \"b\\<sharp>([(ca,c)]\\<bullet>N)\")\napply(simp add: forget)\napply(simp add: trm.inject)\napply(simp add: fresh_left calc_atm fresh_prod fresh_atm)\napply(simp add: trm.inject)\napply(rule sym)\napply(simp add: alpha fresh_prod fresh_atm)\ndone\n\ntext \\<open>3rd lemma\\<close>\n\nlemma CUT_SNa_aux:\n  assumes a1: \"<a>:M \\<in> (\\<parallel><B>\\<parallel>)\"\n  and     a2: \"SNa M\"\n  and     a3: \"(x):N \\<in> (\\<parallel>(B)\\<parallel>)\"\n  and     a4: \"SNa N\"\n  shows   \"SNa (Cut <a>.M (x).N)\"\nusing a1 a2 a3 a4\napply(induct B M N arbitrary: a x rule: my_wf_induct_triple''[OF wf_measure_triple])\napply(rule SNaI)\napply(drule Cut_a_redu_elim)\napply(erule disjE)\n(* left-inner reduction *)\napply(erule exE)\napply(erule conjE)+\napply(simp)\napply(drule_tac x=\"x1\" in meta_spec)\napply(drule_tac x=\"M'a\" in meta_spec)\napply(drule_tac x=\"x3\" in meta_spec)\napply(drule conjunct2)\napply(drule mp)\napply(rule conjI)\napply(simp)\napply(rule disjI1)\napply(simp add: SNa_Redu_def)\napply(drule_tac x=\"a\" in spec)\napply(drule mp)\napply(simp add: CANDs_preserved_single)\napply(drule mp)\napply(simp add: a_preserves_SNa)\napply(drule_tac x=\"x\" in spec)\napply(simp)\napply(erule disjE)\n(* right-inner reduction *)\napply(erule exE)\napply(erule conjE)+\napply(simp)\napply(drule_tac x=\"x1\" in meta_spec)\napply(drule_tac x=\"x2\" in meta_spec)\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule conjunct2)\napply(drule mp)\napply(rule conjI)\napply(simp)\napply(rule disjI2)\napply(simp add: SNa_Redu_def)\napply(drule_tac x=\"a\" in spec)\napply(drule mp)\napply(simp add: CANDs_preserved_single)\napply(drule mp)\napply(assumption)\napply(drule_tac x=\"x\" in spec)\napply(drule mp)\napply(simp add: CANDs_preserved_single)\napply(drule mp)\napply(simp add: a_preserves_SNa)\napply(assumption)\napply(erule disjE)\n(******** c-reduction *********)\napply(drule Cut_c_redu_elim)\n(* c-left reduction*)\napply(erule disjE)\napply(erule conjE)\napply(frule_tac B=\"x1\" in fic_CANDS)\napply(simp)\napply(erule disjE)\n(* in AXIOMSc *)\napply(simp add: AXIOMSc_def)\napply(erule exE)+\napply(simp add: ctrm.inject)\napply(simp add: alpha)\napply(erule disjE)\napply(simp)\napply(rule impI)\napply(simp)\napply(subgoal_tac \"fic (Ax y b) b\")(*A*)\napply(simp)\n(*A*)\napply(auto)[1]\napply(simp)\napply(rule impI)\napply(simp)\napply(subgoal_tac \"fic (Ax ([(a,aa)]\\<bullet>y) a) a\")(*B*)\napply(simp)\n(*B*)\napply(auto)[1]\n(* in BINDINGc *)\napply(simp)\napply(drule BINDINGc_elim)\napply(simp)\n(* c-right reduction*)\napply(erule conjE)\napply(frule_tac B=\"x1\" in fin_CANDS)\napply(simp)\napply(erule disjE)\n(* in AXIOMSc *)\napply(simp add: AXIOMSn_def)\napply(erule exE)+\napply(simp add: ntrm.inject)\napply(simp add: alpha)\napply(erule disjE)\napply(simp)\napply(rule impI)\napply(simp)\napply(subgoal_tac \"fin (Ax xa b) xa\")(*A*)\napply(simp)\n(*A*)\napply(auto)[1]\napply(simp)\napply(rule impI)\napply(simp)\napply(subgoal_tac \"fin (Ax x ([(x,xa)]\\<bullet>b)) x\")(*B*)\napply(simp)\n(*B*)\napply(auto)[1]\n(* in BINDINGc *)\napply(simp)\napply(drule BINDINGn_elim)\napply(simp)\n(*********** l-reductions ************)\napply(drule Cut_l_redu_elim)\napply(erule disjE)\n(* ax1 *)\napply(erule exE)\napply(simp)\napply(simp add: SNa_preserved_renaming1)\napply(erule disjE)\n(* ax2 *)\napply(erule exE)\napply(simp add: SNa_preserved_renaming2)\napply(erule disjE)\n(* LNot *)\napply(erule exE)+\napply(auto)[1]\napply(frule_tac excluded_m)\napply(assumption)\napply(erule disjE)\n(* one of them in BINDING *)\napply(erule disjE)\napply(drule fin_elims)\napply(drule fic_elims)\napply(simp)\napply(drule BINDINGc_elim)\napply(drule_tac x=\"x\" in spec)\napply(drule_tac x=\"NotL <b>.N' x\" in spec)\napply(simp)\napply(simp add: better_NotR_substc)\napply(generate_fresh \"coname\")\napply(subgoal_tac \"fresh_fun (\\<lambda>a'. Cut <a'>.NotR (y).M'a a' (x).NotL <b>.N' x) \n                   =  Cut <c>.NotR (y).M'a c (x).NotL <b>.N' x\")\napply(simp)\napply(subgoal_tac \"Cut <c>.NotR (y).M'a c (x).NotL <b>.N' x \\<longrightarrow>\\<^sub>a Cut <b>.N' (y).M'a\")\napply(simp only: a_preserves_SNa)\napply(rule al_redu)\napply(rule better_LNot_intro)\napply(simp)\napply(simp)\napply(fresh_fun_simp (no_asm))\napply(simp)\n(* other case of in BINDING *)\napply(drule fin_elims)\napply(drule fic_elims)\napply(simp)\napply(drule BINDINGn_elim)\napply(drule_tac x=\"a\" in spec)\napply(drule_tac x=\"NotR (y).M'a a\" in spec)\napply(simp)\napply(simp add: better_NotL_substn)\napply(generate_fresh \"name\")\napply(subgoal_tac \"fresh_fun (\\<lambda>x'. Cut <a>.NotR (y).M'a a (x').NotL <b>.N' x') \n                   = Cut <a>.NotR (y).M'a a (c).NotL <b>.N' c\")\napply(simp)\napply(subgoal_tac \"Cut <a>.NotR (y).M'a a (c).NotL <b>.N' c \\<longrightarrow>\\<^sub>a Cut <b>.N' (y).M'a\")\napply(simp only: a_preserves_SNa)\napply(rule al_redu)\napply(rule better_LNot_intro)\napply(simp)\napply(simp)\napply(fresh_fun_simp (no_asm))\napply(simp)\n(* none of them in BINDING *)\napply(simp)\napply(erule conjE)\napply(frule CAND_NotR_elim)\napply(assumption)\napply(erule exE)\napply(frule CAND_NotL_elim)\napply(assumption)\napply(erule exE)\napply(simp only: ty.inject)\napply(drule_tac x=\"B'\" in meta_spec)\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"M'a\" in meta_spec)\napply(erule conjE)+\napply(drule mp)\napply(simp)\napply(drule_tac x=\"b\" in spec)\napply(rotate_tac 13)\napply(drule mp)\napply(assumption)\napply(rotate_tac 13)\napply(drule mp)\napply(simp add: CANDs_imply_SNa)\napply(drule_tac x=\"y\" in spec)\napply(rotate_tac 13)\napply(drule mp)\napply(assumption)\napply(rotate_tac 13)\napply(drule mp)\napply(simp add: CANDs_imply_SNa)\napply(assumption)\n(* LAnd1 case *)\napply(erule disjE)\napply(erule exE)+\napply(auto)[1]\napply(frule_tac excluded_m)\napply(assumption)\napply(erule disjE)\n(* one of them in BINDING *)\napply(erule disjE)\napply(drule fin_elims)\napply(drule fic_elims)\napply(simp)\napply(drule BINDINGc_elim)\napply(drule_tac x=\"x\" in spec)\napply(drule_tac x=\"AndL1 (y).N' x\" in spec)\napply(simp)\napply(simp add: better_AndR_substc)\napply(generate_fresh \"coname\")\napply(subgoal_tac \"fresh_fun (\\<lambda>a'. Cut <a'>.AndR <b>.M1 <c>.M2 a' (x).AndL1 (y).N' x) \n                   = Cut <ca>.AndR <b>.M1 <c>.M2 ca (x).AndL1 (y).N' x\")\napply(simp)\napply(subgoal_tac \"Cut <ca>.AndR <b>.M1 <c>.M2 ca (x).AndL1 (y).N' x \\<longrightarrow>\\<^sub>a Cut <b>.M1 (y).N'\")\napply(auto intro: a_preserves_SNa)[1]\napply(rule al_redu)\napply(rule better_LAnd1_intro)\napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(simp)\napply(fresh_fun_simp (no_asm))\napply(simp)\n(* other case of in BINDING *)\napply(drule fin_elims)\napply(drule fic_elims)\napply(simp)\napply(drule BINDINGn_elim)\napply(drule_tac x=\"a\" in spec)\napply(drule_tac x=\"AndR <b>.M1 <c>.M2 a\" in spec)\napply(simp)\napply(simp add: better_AndL1_substn)\napply(generate_fresh \"name\")\napply(subgoal_tac \"fresh_fun (\\<lambda>z'. Cut <a>.AndR <b>.M1 <c>.M2 a (z').AndL1 (y).N' z') \n                   = Cut <a>.AndR <b>.M1 <c>.M2 a (ca).AndL1 (y).N' ca\")\napply(simp)\napply(subgoal_tac \"Cut <a>.AndR <b>.M1 <c>.M2 a (ca).AndL1 (y).N' ca \\<longrightarrow>\\<^sub>a Cut <b>.M1 (y).N'\")\napply(auto intro: a_preserves_SNa)[1]\napply(rule al_redu)\napply(rule better_LAnd1_intro)\napply(simp add: abs_fresh fresh_prod fresh_atm) \napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(fresh_fun_simp (no_asm))\napply(simp)\n(* none of them in BINDING *)\napply(simp)\napply(erule conjE)\napply(frule CAND_AndR_elim)\napply(assumption)\napply(erule exE)\napply(frule CAND_AndL1_elim)\napply(assumption)\napply(erule exE)+\napply(simp only: ty.inject)\napply(drule_tac x=\"B1\" in meta_spec)\napply(drule_tac x=\"M1\" in meta_spec)\napply(drule_tac x=\"N'\" in meta_spec)\napply(erule conjE)+\napply(drule mp)\napply(simp)\napply(drule_tac x=\"b\" in spec)\napply(rotate_tac 14)\napply(drule mp)\napply(assumption)\napply(rotate_tac 14)\napply(drule mp)\napply(simp add: CANDs_imply_SNa)\napply(drule_tac x=\"y\" in spec)\napply(rotate_tac 15)\napply(drule mp)\napply(assumption)\napply(rotate_tac 15)\napply(drule mp)\napply(simp add: CANDs_imply_SNa)\napply(assumption)\n(* LAnd2 case *)\napply(erule disjE)\napply(erule exE)+\napply(auto)[1]\napply(frule_tac excluded_m)\napply(assumption)\napply(erule disjE)\n(* one of them in BINDING *)\napply(erule disjE)\napply(drule fin_elims)\napply(drule fic_elims)\napply(simp)\napply(drule BINDINGc_elim)\napply(drule_tac x=\"x\" in spec)\napply(drule_tac x=\"AndL2 (y).N' x\" in spec)\napply(simp)\napply(simp add: better_AndR_substc)\napply(generate_fresh \"coname\")\napply(subgoal_tac \"fresh_fun (\\<lambda>a'. Cut <a'>.AndR <b>.M1 <c>.M2 a' (x).AndL2 (y).N' x) \n                   = Cut <ca>.AndR <b>.M1 <c>.M2 ca (x).AndL2 (y).N' x\")\napply(simp)\napply(subgoal_tac \"Cut <ca>.AndR <b>.M1 <c>.M2 ca (x).AndL2 (y).N' x \\<longrightarrow>\\<^sub>a Cut <c>.M2 (y).N'\")\napply(auto intro: a_preserves_SNa)[1]\napply(rule al_redu)\napply(rule better_LAnd2_intro)\napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(simp)\napply(fresh_fun_simp (no_asm))\napply(simp)\n(* other case of in BINDING *)\napply(drule fin_elims)\napply(drule fic_elims)\napply(simp)\napply(drule BINDINGn_elim)\napply(drule_tac x=\"a\" in spec)\napply(drule_tac x=\"AndR <b>.M1 <c>.M2 a\" in spec)\napply(simp)\napply(simp add: better_AndL2_substn)\napply(generate_fresh \"name\")\napply(subgoal_tac \"fresh_fun (\\<lambda>z'. Cut <a>.AndR <b>.M1 <c>.M2 a (z').AndL2 (y).N' z') \n                   = Cut <a>.AndR <b>.M1 <c>.M2 a (ca).AndL2 (y).N' ca\")\napply(simp)\napply(subgoal_tac \"Cut <a>.AndR <b>.M1 <c>.M2 a (ca).AndL2 (y).N' ca \\<longrightarrow>\\<^sub>a Cut <c>.M2 (y).N'\")\napply(auto intro: a_preserves_SNa)[1]\napply(rule al_redu)\napply(rule better_LAnd2_intro)\napply(simp add: abs_fresh fresh_prod fresh_atm) \napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(fresh_fun_simp (no_asm))\napply(simp)\n(* none of them in BINDING *)\napply(simp)\napply(erule conjE)\napply(frule CAND_AndR_elim)\napply(assumption)\napply(erule exE)\napply(frule CAND_AndL2_elim)\napply(assumption)\napply(erule exE)+\napply(simp only: ty.inject)\napply(drule_tac x=\"B2\" in meta_spec)\napply(drule_tac x=\"M2\" in meta_spec)\napply(drule_tac x=\"N'\" in meta_spec)\napply(erule conjE)+\napply(drule mp)\napply(simp)\napply(drule_tac x=\"c\" in spec)\napply(rotate_tac 14)\napply(drule mp)\napply(assumption)\napply(rotate_tac 14)\napply(drule mp)\napply(simp add: CANDs_imply_SNa)\napply(drule_tac x=\"y\" in spec)\napply(rotate_tac 15)\napply(drule mp)\napply(assumption)\napply(rotate_tac 15)\napply(drule mp)\napply(simp add: CANDs_imply_SNa)\napply(assumption)\n(* LOr1 case *)\napply(erule disjE)\napply(erule exE)+\napply(auto)[1]\napply(frule_tac excluded_m)\napply(assumption)\napply(erule disjE)\n(* one of them in BINDING *)\napply(erule disjE)\napply(drule fin_elims)\napply(drule fic_elims)\napply(simp)\napply(drule BINDINGc_elim)\napply(drule_tac x=\"x\" in spec)\napply(drule_tac x=\"OrL (z).M1 (y).M2 x\" in spec)\napply(simp)\napply(simp add: better_OrR1_substc)\napply(generate_fresh \"coname\")\napply(subgoal_tac \"fresh_fun (\\<lambda>a'. Cut <a'>.OrR1 <b>.N' a' (x).OrL (z).M1 (y).M2 x) \n                   = Cut <c>.OrR1 <b>.N' c (x).OrL (z).M1 (y).M2 x\")\napply(simp)\napply(subgoal_tac \"Cut <c>.OrR1 <b>.N' c (x).OrL (z).M1 (y).M2 x \\<longrightarrow>\\<^sub>a Cut <b>.N' (z).M1\")\napply(auto intro: a_preserves_SNa)[1]\napply(rule al_redu)\napply(rule better_LOr1_intro)\napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(simp add: abs_fresh)\napply(fresh_fun_simp (no_asm))\napply(simp)\n(* other case of in BINDING *)\napply(drule fin_elims)\napply(drule fic_elims)\napply(simp)\napply(drule BINDINGn_elim)\napply(drule_tac x=\"a\" in spec)\napply(drule_tac x=\"OrR1 <b>.N' a\" in spec)\napply(simp)\napply(simp add: better_OrL_substn)\napply(generate_fresh \"name\")\napply(subgoal_tac \"fresh_fun (\\<lambda>z'. Cut <a>.OrR1 <b>.N' a (z').OrL (z).M1 (y).M2 z') \n                   = Cut <a>.OrR1 <b>.N' a (c).OrL (z).M1 (y).M2 c\")\napply(simp)\napply(subgoal_tac \"Cut <a>.OrR1 <b>.N' a (c).OrL (z).M1 (y).M2 c \\<longrightarrow>\\<^sub>a Cut <b>.N' (z).M1\")\napply(auto intro: a_preserves_SNa)[1]\napply(rule al_redu)\napply(rule better_LOr1_intro)\napply(simp add: abs_fresh fresh_prod fresh_atm) \napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(fresh_fun_simp (no_asm))\napply(simp)\n(* none of them in BINDING *)\napply(simp)\napply(erule conjE)\napply(frule CAND_OrR1_elim)\napply(assumption)\napply(erule exE)+\napply(frule CAND_OrL_elim)\napply(assumption)\napply(erule exE)+\napply(simp only: ty.inject)\napply(drule_tac x=\"B1\" in meta_spec)\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"M1\" in meta_spec)\napply(erule conjE)+\napply(drule mp)\napply(simp)\napply(drule_tac x=\"b\" in spec)\napply(rotate_tac 15)\napply(drule mp)\napply(assumption)\napply(rotate_tac 15)\napply(drule mp)\napply(simp add: CANDs_imply_SNa)\napply(drule_tac x=\"z\" in spec)\napply(rotate_tac 15)\napply(drule mp)\napply(assumption)\napply(rotate_tac 15)\napply(drule mp)\napply(simp add: CANDs_imply_SNa)\napply(assumption)\n(* LOr2 case *)\napply(erule disjE)\napply(erule exE)+\napply(auto)[1]\napply(frule_tac excluded_m)\napply(assumption)\napply(erule disjE)\n(* one of them in BINDING *)\napply(erule disjE)\napply(drule fin_elims)\napply(drule fic_elims)\napply(simp)\napply(drule BINDINGc_elim)\napply(drule_tac x=\"x\" in spec)\napply(drule_tac x=\"OrL (z).M1 (y).M2 x\" in spec)\napply(simp)\napply(simp add: better_OrR2_substc)\napply(generate_fresh \"coname\")\napply(subgoal_tac \"fresh_fun (\\<lambda>a'. Cut <a'>.OrR2 <b>.N' a' (x).OrL (z).M1 (y).M2 x) \n                   = Cut <c>.OrR2 <b>.N' c (x).OrL (z).M1 (y).M2 x\")\napply(simp)\napply(subgoal_tac \"Cut <c>.OrR2 <b>.N' c (x).OrL (z).M1 (y).M2 x \\<longrightarrow>\\<^sub>a Cut <b>.N' (y).M2\")\napply(auto intro: a_preserves_SNa)[1]\napply(rule al_redu)\napply(rule better_LOr2_intro)\napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(simp add: abs_fresh)\napply(fresh_fun_simp (no_asm))\napply(simp)\n(* other case of in BINDING *)\napply(drule fin_elims)\napply(drule fic_elims)\napply(simp)\napply(drule BINDINGn_elim)\napply(drule_tac x=\"a\" in spec)\napply(drule_tac x=\"OrR2 <b>.N' a\" in spec)\napply(simp)\napply(simp add: better_OrL_substn)\napply(generate_fresh \"name\")\napply(subgoal_tac \"fresh_fun (\\<lambda>z'. Cut <a>.OrR2 <b>.N' a (z').OrL (z).M1 (y).M2 z') \n                   = Cut <a>.OrR2 <b>.N' a (c).OrL (z).M1 (y).M2 c\")\napply(simp)\napply(subgoal_tac \"Cut <a>.OrR2 <b>.N' a (c).OrL (z).M1 (y).M2 c \\<longrightarrow>\\<^sub>a Cut <b>.N' (y).M2\")\napply(auto intro: a_preserves_SNa)[1]\napply(rule al_redu)\napply(rule better_LOr2_intro)\napply(simp add: abs_fresh fresh_prod fresh_atm) \napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(fresh_fun_simp (no_asm))\napply(simp)\n(* none of them in BINDING *)\napply(simp)\napply(erule conjE)\napply(frule CAND_OrR2_elim)\napply(assumption)\napply(erule exE)+\napply(frule CAND_OrL_elim)\napply(assumption)\napply(erule exE)+\napply(simp only: ty.inject)\napply(drule_tac x=\"B2\" in meta_spec)\napply(drule_tac x=\"N'\" in meta_spec)\napply(drule_tac x=\"M2\" in meta_spec)\napply(erule conjE)+\napply(drule mp)\napply(simp)\napply(drule_tac x=\"b\" in spec)\napply(rotate_tac 15)\napply(drule mp)\napply(assumption)\napply(rotate_tac 15)\napply(drule mp)\napply(simp add: CANDs_imply_SNa)\napply(drule_tac x=\"y\" in spec)\napply(rotate_tac 15)\napply(drule mp)\napply(assumption)\napply(rotate_tac 15)\napply(drule mp)\napply(simp add: CANDs_imply_SNa)\napply(assumption)\n(* LImp case *)\napply(erule exE)+\napply(auto)[1]\napply(frule_tac excluded_m)\napply(assumption)\napply(erule disjE)\n(* one of them in BINDING *)\napply(erule disjE)\napply(drule fin_elims)\napply(drule fic_elims)\napply(simp)\napply(drule BINDINGc_elim)\napply(drule_tac x=\"x\" in spec)\napply(drule_tac x=\"ImpL <c>.N1 (y).N2 x\" in spec)\napply(simp)\napply(simp add: better_ImpR_substc)\napply(generate_fresh \"coname\")\napply(subgoal_tac \"fresh_fun (\\<lambda>a'. Cut <a'>.ImpR (z).<b>.M'a a' (x).ImpL <c>.N1 (y).N2 x)\n                   = Cut <ca>.ImpR (z).<b>.M'a ca (x).ImpL <c>.N1 (y).N2 x\")\napply(simp)\napply(subgoal_tac \"Cut <ca>.ImpR (z).<b>.M'a ca (x).ImpL <c>.N1 (y).N2 x \\<longrightarrow>\\<^sub>a \n                                                          Cut <b>.Cut <c>.N1 (z).M'a (y).N2\")\napply(auto intro: a_preserves_SNa)[1]\napply(rule al_redu)\napply(rule better_LImp_intro)\napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(simp add: abs_fresh)\napply(simp)\napply(fresh_fun_simp (no_asm))\napply(simp)\n(* other case of in BINDING *)\napply(drule fin_elims)\napply(drule fic_elims)\napply(simp)\napply(drule BINDINGn_elim)\napply(drule_tac x=\"a\" in spec)\napply(drule_tac x=\"ImpR (z).<b>.M'a a\" in spec)\napply(simp)\napply(simp add: better_ImpL_substn)\napply(generate_fresh \"name\")\napply(subgoal_tac \"fresh_fun (\\<lambda>z'. Cut <a>.ImpR (z).<b>.M'a a (z').ImpL <c>.N1 (y).N2 z')\n                   = Cut <a>.ImpR (z).<b>.M'a a (ca).ImpL <c>.N1 (y).N2 ca\")\napply(simp)\napply(subgoal_tac \"Cut <a>.ImpR (z).<b>.M'a a (ca).ImpL <c>.N1 (y).N2 ca \\<longrightarrow>\\<^sub>a \n                                                          Cut <b>.Cut <c>.N1 (z).M'a (y).N2\")\napply(auto intro: a_preserves_SNa)[1]\napply(rule al_redu)\napply(rule better_LImp_intro)\napply(simp add: abs_fresh fresh_prod fresh_atm) \napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(simp)\napply(fresh_fun_simp (no_asm))\napply(simp add: abs_fresh abs_supp fin_supp)\napply(simp add: abs_fresh abs_supp fin_supp)\napply(simp)\n(* none of them in BINDING *)\napply(erule conjE)\napply(frule CAND_ImpL_elim)\napply(assumption)\napply(erule exE)+\napply(frule CAND_ImpR_elim) (* check here *)\napply(assumption)\napply(erule exE)+\napply(erule conjE)+\napply(simp only: ty.inject)\napply(erule conjE)+\napply(case_tac \"M'a=Ax z b\")\n(* case Ma = Ax z b *)\napply(rule_tac t=\"Cut <b>.(Cut <c>.N1 (z).M'a) (y).N2\" and s=\"Cut <b>.(M'a{z:=<c>.N1}) (y).N2\" in subst)\napply(simp)\napply(drule_tac x=\"c\" in spec)\napply(drule_tac x=\"N1\" in spec)\napply(drule mp)\napply(simp)\napply(drule_tac x=\"B2\" in meta_spec)\napply(drule_tac x=\"M'a{z:=<c>.N1}\" in meta_spec)\napply(drule_tac x=\"N2\" in meta_spec)\napply(drule conjunct1)\napply(drule mp)\napply(simp)\napply(rotate_tac 17)\napply(drule_tac x=\"b\" in spec)\napply(drule mp)\napply(assumption)\napply(drule mp)\napply(simp add: CANDs_imply_SNa)\napply(rotate_tac 17)\napply(drule_tac x=\"y\" in spec)\napply(drule mp)\napply(assumption)\napply(drule mp)\napply(simp add: CANDs_imply_SNa)\napply(assumption)\n(* case Ma \\<noteq> Ax z b *)\napply(subgoal_tac \"<b>:Cut <c>.N1 (z).M'a \\<in> \\<parallel><B2>\\<parallel>\") (* lemma *)\napply(frule_tac meta_spec)\napply(drule_tac x=\"B2\" in meta_spec)\napply(drule_tac x=\"Cut <c>.N1 (z).M'a\" in meta_spec)\napply(drule_tac x=\"N2\" in meta_spec)\napply(erule conjE)+\napply(drule mp)\napply(simp)\napply(rotate_tac 20)\napply(drule_tac x=\"b\" in spec)\napply(rotate_tac 20)\napply(drule mp)\napply(assumption)\napply(rotate_tac 20)\napply(drule mp)\napply(simp add: CANDs_imply_SNa)\napply(rotate_tac 20)\napply(drule_tac x=\"y\" in spec)\napply(rotate_tac 20)\napply(drule mp)\napply(assumption)\napply(rotate_tac 20)\napply(drule mp)\napply(simp add: CANDs_imply_SNa)\napply(assumption)\n(* lemma *)\napply(subgoal_tac \"<b>:Cut <c>.N1 (z).M'a \\<in> BINDINGc B2 (\\<parallel>(B2)\\<parallel>)\") (* second lemma *)\napply(simp add: BINDING_implies_CAND)\n(* second lemma *)\napply(simp (no_asm) add: BINDINGc_def)\napply(rule exI)+\napply(rule conjI)\napply(rule refl)\napply(rule allI)+\napply(rule impI)\napply(generate_fresh \"name\")\napply(rule_tac t=\"Cut <c>.N1 (z).M'a\" and s=\"Cut <c>.N1 (ca).([(ca,z)]\\<bullet>M'a)\" in subst)\napply(simp add: trm.inject alpha fresh_prod fresh_atm)\napply(rule_tac t=\"(Cut <c>.N1 (ca).([(ca,z)]\\<bullet>M'a)){b:=(xa).P}\" \n           and s=\"Cut <c>.N1 (ca).(([(ca,z)]\\<bullet>M'a){b:=(xa).P})\" in subst)\napply(rule sym)\napply(rule tricky_subst)\napply(simp)\napply(simp)\napply(clarify)\napply(drule pt_bij1[OF pt_name_inst, OF at_name_inst])\napply(simp add: calc_atm)\napply(drule_tac x=\"B1\" in meta_spec)\napply(drule_tac x=\"N1\" in meta_spec)\napply(drule_tac x=\"([(ca,z)]\\<bullet>M'a){b:=(xa).P}\" in meta_spec)\napply(drule conjunct1)\napply(drule mp)\napply(simp)\napply(rotate_tac 19)\napply(drule_tac x=\"c\" in spec)\napply(drule mp)\napply(assumption)\napply(drule mp)\napply(simp add: CANDs_imply_SNa)\napply(rotate_tac 19)\napply(drule_tac x=\"ca\" in spec)\napply(subgoal_tac \"(ca):([(ca,z)]\\<bullet>M'a){b:=(xa).P} \\<in> \\<parallel>(B1)\\<parallel>\")(*A*)\napply(drule mp)\napply(assumption)\napply(drule mp)\napply(simp add: CANDs_imply_SNa)\napply(assumption)\n(*A*)\napply(drule_tac x=\"[(ca,z)]\\<bullet>xa\" in spec)\napply(drule_tac x=\"[(ca,z)]\\<bullet>P\" in spec)\napply(rotate_tac 19)\napply(simp add: fresh_prod fresh_left)\napply(drule mp)\napply(rule conjI)\napply(auto simp add: calc_atm)[1]\napply(rule conjI)\napply(auto simp add: calc_atm)[1]\napply(drule_tac pi=\"[(ca,z)]\" and x=\"(xa):P\" in pt_set_bij2[OF pt_name_inst, OF at_name_inst])\napply(simp add: CAND_eqvt_name)\napply(drule_tac pi=\"[(ca,z)]\" and X=\"\\<parallel>(B1)\\<parallel>\" in pt_set_bij2[OF pt_name_inst, OF at_name_inst])\napply(simp add: CAND_eqvt_name csubst_eqvt)\napply(perm_simp)\ndone\n\n\n(* parallel substitution *)\n\n\nlemma CUT_SNa:\n  assumes a1: \"<a>:M \\<in> (\\<parallel><B>\\<parallel>)\"\n  and     a2: \"(x):N \\<in> (\\<parallel>(B)\\<parallel>)\"\n  shows   \"SNa (Cut <a>.M (x).N)\"\nusing a1 a2\napply -\napply(rule CUT_SNa_aux[OF a1])\napply(simp_all add: CANDs_imply_SNa)\ndone \n\n\nfun \n findn :: \"(name\\<times>coname\\<times>trm) list\\<Rightarrow>name\\<Rightarrow>(coname\\<times>trm) option\"\nwhere\n  \"findn [] x = None\"\n| \"findn ((y,c,P)#\\<theta>_n) x = (if y=x then Some (c,P) else findn \\<theta>_n x)\"\n\nlemma findn_eqvt[eqvt]:\n  fixes pi1::\"name prm\"\n  and   pi2::\"coname prm\"\n  shows \"(pi1\\<bullet>findn \\<theta>_n x) = findn (pi1\\<bullet>\\<theta>_n) (pi1\\<bullet>x)\" \n  and   \"(pi2\\<bullet>findn \\<theta>_n x) = findn (pi2\\<bullet>\\<theta>_n) (pi2\\<bullet>x)\"\napply(induct \\<theta>_n)\napply(auto simp add: perm_bij) \ndone\n\nlemma findn_fresh:\n  assumes a: \"x\\<sharp>\\<theta>_n\"\n  shows \"findn \\<theta>_n x = None\"\nusing a\napply(induct \\<theta>_n)\napply(auto simp add: fresh_list_cons fresh_atm fresh_prod)\ndone\n\nfun \n findc :: \"(coname\\<times>name\\<times>trm) list\\<Rightarrow>coname\\<Rightarrow>(name\\<times>trm) option\"\nwhere\n  \"findc [] x = None\"\n| \"findc ((c,y,P)#\\<theta>_c) a = (if a=c then Some (y,P) else findc \\<theta>_c a)\"\n\nlemma findc_eqvt[eqvt]:\n  fixes pi1::\"name prm\"\n  and   pi2::\"coname prm\"\n  shows \"(pi1\\<bullet>findc \\<theta>_c a) = findc (pi1\\<bullet>\\<theta>_c) (pi1\\<bullet>a)\" \n  and   \"(pi2\\<bullet>findc \\<theta>_c a) = findc (pi2\\<bullet>\\<theta>_c) (pi2\\<bullet>a)\"\napply(induct \\<theta>_c)\napply(auto simp add: perm_bij) \ndone\n\nlemma findc_fresh:\n  assumes a: \"a\\<sharp>\\<theta>_c\"\n  shows \"findc \\<theta>_c a = None\"\nusing a\napply(induct \\<theta>_c)\napply(auto simp add: fresh_list_cons fresh_atm fresh_prod)\ndone\n\nabbreviation \n nmaps :: \"(name\\<times>coname\\<times>trm) list \\<Rightarrow> name \\<Rightarrow> (coname\\<times>trm) option \\<Rightarrow> bool\" (\"_ nmaps _ to _\" [55,55,55] 55) \nwhere\n \"\\<theta>_n nmaps x to P \\<equiv> (findn \\<theta>_n x) = P\"\n\nabbreviation \n cmaps :: \"(coname\\<times>name\\<times>trm) list \\<Rightarrow> coname \\<Rightarrow> (name\\<times>trm) option \\<Rightarrow> bool\" (\"_ cmaps _ to _\" [55,55,55] 55) \nwhere\n \"\\<theta>_c cmaps a to P \\<equiv> (findc \\<theta>_c a) = P\"\n\nlemma nmaps_fresh:\n  shows \"\\<theta>_n nmaps x to Some (c,P) \\<Longrightarrow> a\\<sharp>\\<theta>_n \\<Longrightarrow> a\\<sharp>(c,P)\"\napply(induct \\<theta>_n)\napply(auto simp add: fresh_list_cons fresh_prod fresh_atm)\napply(case_tac \"aa=x\")\napply(auto)\napply(case_tac \"aa=x\")\napply(auto)\ndone\n\nlemma cmaps_fresh:\n  shows \"\\<theta>_c cmaps a to Some (y,P) \\<Longrightarrow> x\\<sharp>\\<theta>_c \\<Longrightarrow> x\\<sharp>(y,P)\"\napply(induct \\<theta>_c)\napply(auto simp add: fresh_list_cons fresh_prod fresh_atm)\napply(case_tac \"a=aa\")\napply(auto)\napply(case_tac \"a=aa\")\napply(auto)\ndone\n\nlemma nmaps_false:\n  shows \"\\<theta>_n nmaps x to Some (c,P) \\<Longrightarrow> x\\<sharp>\\<theta>_n \\<Longrightarrow> False\"\napply(induct \\<theta>_n)\napply(auto simp add: fresh_list_cons fresh_prod fresh_atm)\ndone\n\nlemma cmaps_false:\n  shows \"\\<theta>_c cmaps c to Some (x,P) \\<Longrightarrow> c\\<sharp>\\<theta>_c \\<Longrightarrow> False\"\napply(induct \\<theta>_c)\napply(auto simp add: fresh_list_cons fresh_prod fresh_atm)\ndone\n\nfun \n lookupa :: \"name\\<Rightarrow>coname\\<Rightarrow>(coname\\<times>name\\<times>trm) list\\<Rightarrow>trm\"\nwhere\n  \"lookupa x a [] = Ax x a\"\n| \"lookupa x a ((c,y,P)#\\<theta>_c) = (if a=c then Cut <a>.Ax x a (y).P else lookupa x a \\<theta>_c)\"\n\nlemma lookupa_eqvt[eqvt]:\n  fixes pi1::\"name prm\"\n  and   pi2::\"coname prm\"\n  shows \"(pi1\\<bullet>(lookupa x a \\<theta>_c)) = lookupa (pi1\\<bullet>x) (pi1\\<bullet>a) (pi1\\<bullet>\\<theta>_c)\"\n  and   \"(pi2\\<bullet>(lookupa x a \\<theta>_c)) = lookupa (pi2\\<bullet>x) (pi2\\<bullet>a) (pi2\\<bullet>\\<theta>_c)\"\napply -\napply(induct \\<theta>_c)\napply(auto simp add: eqvts)\napply(induct \\<theta>_c)\napply(auto simp add: eqvts)\ndone\n\nlemma lookupa_fire:\n  assumes a: \"\\<theta>_c cmaps a to Some (y,P)\"\n  shows \"(lookupa x a \\<theta>_c) = Cut <a>.Ax x a (y).P\"\nusing a\napply(induct \\<theta>_c arbitrary: x a y P)\napply(auto)\ndone\n\nfun \n lookupb :: \"name\\<Rightarrow>coname\\<Rightarrow>(coname\\<times>name\\<times>trm) list\\<Rightarrow>coname\\<Rightarrow>trm\\<Rightarrow>trm\"\nwhere\n  \"lookupb x a [] c P = Cut <c>.P (x).Ax x a\"\n| \"lookupb x a ((d,y,N)#\\<theta>_c) c P = (if a=d then Cut <c>.P (y).N  else lookupb x a \\<theta>_c c P)\"\n\nlemma lookupb_eqvt[eqvt]:\n  fixes pi1::\"name prm\"\n  and   pi2::\"coname prm\"\n  shows \"(pi1\\<bullet>(lookupb x a \\<theta>_c c P)) = lookupb (pi1\\<bullet>x) (pi1\\<bullet>a) (pi1\\<bullet>\\<theta>_c) (pi1\\<bullet>c) (pi1\\<bullet>P)\"\n  and   \"(pi2\\<bullet>(lookupb x a \\<theta>_c c P)) = lookupb (pi2\\<bullet>x) (pi2\\<bullet>a) (pi2\\<bullet>\\<theta>_c) (pi2\\<bullet>c) (pi2\\<bullet>P)\"\napply -\napply(induct \\<theta>_c)\napply(auto simp add: eqvts)\napply(induct \\<theta>_c)\napply(auto simp add: eqvts)\ndone\n\nfun \n  lookup :: \"name\\<Rightarrow>coname\\<Rightarrow>(name\\<times>coname\\<times>trm) list\\<Rightarrow>(coname\\<times>name\\<times>trm) list\\<Rightarrow>trm\"\nwhere\n  \"lookup x a [] \\<theta>_c = lookupa x a \\<theta>_c\"\n| \"lookup x a ((y,c,P)#\\<theta>_n) \\<theta>_c = (if x=y then (lookupb x a \\<theta>_c c P) else lookup x a \\<theta>_n \\<theta>_c)\"\n\nlemma lookup_eqvt[eqvt]:\n  fixes pi1::\"name prm\"\n  and   pi2::\"coname prm\"\n  shows \"(pi1\\<bullet>(lookup x a \\<theta>_n \\<theta>_c)) = lookup (pi1\\<bullet>x) (pi1\\<bullet>a) (pi1\\<bullet>\\<theta>_n) (pi1\\<bullet>\\<theta>_c)\"\n  and   \"(pi2\\<bullet>(lookup x a \\<theta>_n \\<theta>_c)) = lookup (pi2\\<bullet>x) (pi2\\<bullet>a) (pi2\\<bullet>\\<theta>_n) (pi2\\<bullet>\\<theta>_c)\"\napply -\napply(induct \\<theta>_n)\napply(auto simp add: eqvts)\napply(induct \\<theta>_n)\napply(auto simp add: eqvts)\ndone\n\nfun \n  lookupc :: \"name\\<Rightarrow>coname\\<Rightarrow>(name\\<times>coname\\<times>trm) list\\<Rightarrow>trm\"\nwhere\n  \"lookupc x a [] = Ax x a\"\n| \"lookupc x a ((y,c,P)#\\<theta>_n) = (if x=y then P[c\\<turnstile>c>a] else lookupc x a \\<theta>_n)\"\n\nlemma lookupc_eqvt[eqvt]:\n  fixes pi1::\"name prm\"\n  and   pi2::\"coname prm\"\n  shows \"(pi1\\<bullet>(lookupc x a \\<theta>_n)) = lookupc (pi1\\<bullet>x) (pi1\\<bullet>a) (pi1\\<bullet>\\<theta>_n)\"\n  and   \"(pi2\\<bullet>(lookupc x a \\<theta>_n)) = lookupc (pi2\\<bullet>x) (pi2\\<bullet>a) (pi2\\<bullet>\\<theta>_n)\"\napply -\napply(induct \\<theta>_n)\napply(auto simp add: eqvts)\napply(induct \\<theta>_n)\napply(auto simp add: eqvts)\ndone\n\nfun \n  lookupd :: \"name\\<Rightarrow>coname\\<Rightarrow>(coname\\<times>name\\<times>trm) list\\<Rightarrow>trm\"\nwhere\n  \"lookupd x a [] = Ax x a\"\n| \"lookupd x a ((c,y,P)#\\<theta>_c) = (if a=c then P[y\\<turnstile>n>x] else lookupd x a \\<theta>_c)\"\n\nlemma lookupd_eqvt[eqvt]:\n  fixes pi1::\"name prm\"\n  and   pi2::\"coname prm\"\n  shows \"(pi1\\<bullet>(lookupd x a \\<theta>_n)) = lookupd (pi1\\<bullet>x) (pi1\\<bullet>a) (pi1\\<bullet>\\<theta>_n)\"\n  and   \"(pi2\\<bullet>(lookupd x a \\<theta>_n)) = lookupd (pi2\\<bullet>x) (pi2\\<bullet>a) (pi2\\<bullet>\\<theta>_n)\"\napply -\napply(induct \\<theta>_n)\napply(auto simp add: eqvts)\napply(induct \\<theta>_n)\napply(auto simp add: eqvts)\ndone\n\nlemma lookupa_fresh:\n  assumes a: \"a\\<sharp>\\<theta>_c\"\n  shows \"lookupa y a \\<theta>_c = Ax y a\"\nusing a\napply(induct \\<theta>_c)\napply(auto simp add: fresh_prod fresh_list_cons fresh_atm)\ndone\n\nlemma lookupa_csubst:\n  assumes a: \"a\\<sharp>\\<theta>_c\"\n  shows \"Cut <a>.Ax y a (x).P = (lookupa y a \\<theta>_c){a:=(x).P}\"\nusing a by (simp add: lookupa_fresh)\n\nlemma lookupa_freshness:\n  fixes a::\"coname\"\n  and   x::\"name\"\n  shows \"a\\<sharp>(\\<theta>_c,c) \\<Longrightarrow> a\\<sharp>lookupa y c \\<theta>_c\"\n  and   \"x\\<sharp>(\\<theta>_c,y) \\<Longrightarrow> x\\<sharp>lookupa y c \\<theta>_c\"\napply(induct \\<theta>_c)\napply(auto simp add: fresh_prod fresh_list_cons abs_fresh fresh_atm)\ndone\n\nlemma lookupa_unicity:\n  assumes a: \"lookupa x a \\<theta>_c= Ax y b\" \"b\\<sharp>\\<theta>_c\" \"y\\<sharp>\\<theta>_c\"\n  shows \"x=y \\<and> a=b\"\nusing a\napply(induct \\<theta>_c)\napply(auto simp add: trm.inject fresh_list_cons fresh_prod fresh_atm)\napply(case_tac \"a=aa\")\napply(auto)\napply(case_tac \"a=aa\")\napply(auto)\ndone\n\nlemma lookupb_csubst:\n  assumes a: \"a\\<sharp>(\\<theta>_c,c,N)\"\n  shows \"Cut <c>.N (x).P = (lookupb y a \\<theta>_c c N){a:=(x).P}\"\nusing a\napply(induct \\<theta>_c)\napply(auto simp add: fresh_list_cons fresh_atm fresh_prod)\napply(rule sym)\napply(generate_fresh \"name\")\napply(generate_fresh \"coname\")\napply(subgoal_tac \"Cut <c>.N (y).Ax y a = Cut <caa>.([(caa,c)]\\<bullet>N) (ca).Ax ca a\")\napply(simp)\napply(rule trans)\napply(rule better_Cut_substc)\napply(simp)\napply(simp add: abs_fresh)\napply(simp)\napply(subgoal_tac \"a\\<sharp>([(caa,c)]\\<bullet>N)\")\napply(simp add: forget)\napply(simp add: trm.inject)\napply(simp add: fresh_left calc_atm fresh_prod fresh_atm)\napply(simp add: trm.inject)\napply(rule conjI)\napply(rule sym)\napply(simp add: alpha fresh_prod fresh_atm)\napply(simp add: alpha calc_atm fresh_prod fresh_atm)\ndone\n\nlemma lookupb_freshness:\n  fixes a::\"coname\"\n  and   x::\"name\"\n  shows \"a\\<sharp>(\\<theta>_c,c,b,P) \\<Longrightarrow> a\\<sharp>lookupb y c \\<theta>_c b P\"\n  and   \"x\\<sharp>(\\<theta>_c,y,P) \\<Longrightarrow> x\\<sharp>lookupb y c \\<theta>_c b P\"\napply(induct \\<theta>_c)\napply(auto simp add: fresh_prod fresh_list_cons abs_fresh fresh_atm)\ndone\n\nlemma lookupb_unicity:\n  assumes a: \"lookupb x a \\<theta>_c c P = Ax y b\" \"b\\<sharp>(\\<theta>_c,c,P)\" \"y\\<sharp>\\<theta>_c\"\n  shows \"x=y \\<and> a=b\"\nusing a\napply(induct \\<theta>_c)\napply(auto simp add: fresh_list_cons fresh_prod fresh_atm)\napply(case_tac \"a=aa\")\napply(auto)\napply(case_tac \"a=aa\")\napply(auto)\ndone\n\nlemma lookupb_lookupa:\n  assumes a: \"x\\<sharp>\\<theta>_c\"\n  shows \"lookupb x c \\<theta>_c a P = (lookupa x c \\<theta>_c){x:=<a>.P}\"\nusing a\napply(induct \\<theta>_c)\napply(auto simp add: fresh_list_cons fresh_prod)\napply(generate_fresh \"coname\")\napply(generate_fresh \"name\")\napply(subgoal_tac \"Cut <c>.Ax x c (aa).b = Cut <ca>.Ax x ca (caa).([(caa,aa)]\\<bullet>b)\")\napply(simp)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substn)\napply(simp add: abs_fresh)\napply(simp)\napply(simp)\napply(subgoal_tac \"x\\<sharp>([(caa,aa)]\\<bullet>b)\")\napply(simp add: forget)\napply(simp add: trm.inject)\napply(auto simp add: fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(simp add: trm.inject)\napply(rule conjI)\napply(simp add: alpha calc_atm fresh_atm fresh_prod)\napply(rule sym)\napply(simp add: alpha calc_atm fresh_atm fresh_prod)\ndone\n\nlemma lookup_csubst:\n  assumes a: \"a\\<sharp>(\\<theta>_n,\\<theta>_c)\"\n  shows \"lookup y c \\<theta>_n ((a,x,P)#\\<theta>_c) = (lookup y c \\<theta>_n \\<theta>_c){a:=(x).P}\"\nusing a\napply(induct \\<theta>_n)\napply(auto simp add: fresh_prod fresh_list_cons)\napply(simp add: lookupa_csubst)\napply(simp add: lookupa_freshness forget fresh_atm fresh_prod)\napply(rule lookupb_csubst)\napply(simp)\napply(auto simp add: lookupb_freshness forget fresh_atm fresh_prod)\ndone\n\nlemma lookup_fresh:\n  assumes a: \"x\\<sharp>(\\<theta>_n,\\<theta>_c)\"\n  shows \"lookup x c \\<theta>_n \\<theta>_c = lookupa x c \\<theta>_c\"\nusing a\napply(induct \\<theta>_n)\napply(auto simp add: fresh_prod fresh_list_cons fresh_atm)\ndone\n\nlemma lookup_unicity:\n  assumes a: \"lookup x a \\<theta>_n \\<theta>_c= Ax y b\" \"b\\<sharp>(\\<theta>_c,\\<theta>_n)\" \"y\\<sharp>(\\<theta>_c,\\<theta>_n)\"\n  shows \"x=y \\<and> a=b\"\nusing a\napply(induct \\<theta>_n)\napply(auto simp add: trm.inject fresh_list_cons fresh_prod fresh_atm)\napply(drule lookupa_unicity)\napply(simp)+\napply(drule lookupa_unicity)\napply(simp)+\napply(case_tac \"x=aa\")\napply(auto)\napply(drule lookupb_unicity)\napply(simp add: fresh_atm)\napply(simp)\napply(simp)\napply(case_tac \"x=aa\")\napply(auto)\napply(drule lookupb_unicity)\napply(simp add: fresh_atm)\napply(simp)\napply(simp)\ndone\n\nlemma lookup_freshness:\n  fixes a::\"coname\"\n  and   x::\"name\"\n  shows \"a\\<sharp>(c,\\<theta>_c,\\<theta>_n) \\<Longrightarrow> a\\<sharp>lookup y c \\<theta>_n \\<theta>_c\"\n  and   \"x\\<sharp>(y,\\<theta>_c,\\<theta>_n) \\<Longrightarrow> x\\<sharp>lookup y c \\<theta>_n \\<theta>_c\"   \napply(induct \\<theta>_n)\napply(auto simp add: fresh_prod fresh_list_cons abs_fresh fresh_atm)\napply(simp add: fresh_atm fresh_prod lookupa_freshness)\napply(simp add: fresh_atm fresh_prod lookupa_freshness)\napply(simp add: fresh_atm fresh_prod lookupb_freshness)\napply(simp add: fresh_atm fresh_prod lookupb_freshness)\ndone\n\nlemma lookupc_freshness:\n  fixes a::\"coname\"\n  and   x::\"name\"\n  shows \"a\\<sharp>(\\<theta>_c,c) \\<Longrightarrow> a\\<sharp>lookupc y c \\<theta>_c\"\n  and   \"x\\<sharp>(\\<theta>_c,y) \\<Longrightarrow> x\\<sharp>lookupc y c \\<theta>_c\"\napply(induct \\<theta>_c)\napply(auto simp add: fresh_prod fresh_list_cons abs_fresh fresh_atm)\napply(rule rename_fresh)\napply(simp add: fresh_atm)\napply(rule rename_fresh)\napply(simp add: fresh_atm)\ndone\n\nlemma lookupc_fresh:\n  assumes a: \"y\\<sharp>\\<theta>_n\"\n  shows \"lookupc y a \\<theta>_n = Ax y a\"\nusing a\napply(induct \\<theta>_n)\napply(auto simp add: fresh_prod fresh_list_cons fresh_atm)\ndone\n\nlemma lookupc_nmaps:\n  assumes a: \"\\<theta>_n nmaps x to Some (c,P)\"\n  shows \"lookupc x a \\<theta>_n = P[c\\<turnstile>c>a]\"\nusing a\napply(induct \\<theta>_n)\napply(auto)\ndone \n\nlemma lookupc_unicity:\n  assumes a: \"lookupc y a \\<theta>_n = Ax x b\" \"x\\<sharp>\\<theta>_n\"\n  shows \"y=x\"\nusing a\napply(induct \\<theta>_n)\napply(auto simp add: trm.inject fresh_list_cons fresh_prod)\napply(case_tac \"y=aa\")\napply(auto)\napply(subgoal_tac \"x\\<sharp>(ba[aa\\<turnstile>c>a])\")\napply(simp add: fresh_atm)\napply(rule rename_fresh)\napply(simp)\ndone\n\nlemma lookupd_fresh:\n  assumes a: \"a\\<sharp>\\<theta>_c\"\n  shows \"lookupd y a \\<theta>_c = Ax y a\"\nusing a\napply(induct \\<theta>_c)\napply(auto simp add: fresh_prod fresh_list_cons fresh_atm)\ndone \n\nlemma lookupd_unicity:\n  assumes a: \"lookupd y a \\<theta>_c = Ax y b\" \"b\\<sharp>\\<theta>_c\"\n  shows \"a=b\"\nusing a\napply(induct \\<theta>_c)\napply(auto simp add: trm.inject fresh_list_cons fresh_prod)\napply(case_tac \"a=aa\")\napply(auto)\napply(subgoal_tac \"b\\<sharp>(ba[aa\\<turnstile>n>y])\")\napply(simp add: fresh_atm)\napply(rule rename_fresh)\napply(simp)\ndone\n\nlemma lookupd_freshness:\n  fixes a::\"coname\"\n  and   x::\"name\"\n  shows \"a\\<sharp>(\\<theta>_c,c) \\<Longrightarrow> a\\<sharp>lookupd y c \\<theta>_c\"\n  and   \"x\\<sharp>(\\<theta>_c,y) \\<Longrightarrow> x\\<sharp>lookupd y c \\<theta>_c\"\napply(induct \\<theta>_c)\napply(auto simp add: fresh_prod fresh_list_cons abs_fresh fresh_atm)\napply(rule rename_fresh)\napply(simp add: fresh_atm)\napply(rule rename_fresh)\napply(simp add: fresh_atm)\ndone\n\nlemma lookupd_cmaps:\n  assumes a: \"\\<theta>_c cmaps a to Some (x,P)\"\n  shows \"lookupd y a \\<theta>_c = P[x\\<turnstile>n>y]\"\nusing a\napply(induct \\<theta>_c)\napply(auto)\ndone \n\nnominal_primrec (freshness_context: \"\\<theta>_n::(name\\<times>coname\\<times>trm)\")\n  stn :: \"trm\\<Rightarrow>(name\\<times>coname\\<times>trm) list\\<Rightarrow>trm\" \nwhere\n  \"stn (Ax x a) \\<theta>_n = lookupc x a \\<theta>_n\"\n| \"\\<lbrakk>a\\<sharp>(N,\\<theta>_n);x\\<sharp>(M,\\<theta>_n)\\<rbrakk> \\<Longrightarrow> stn (Cut <a>.M (x).N) \\<theta>_n = (Cut <a>.M (x).N)\" \n| \"x\\<sharp>\\<theta>_n \\<Longrightarrow> stn (NotR (x).M a) \\<theta>_n = (NotR (x).M a)\"\n| \"a\\<sharp>\\<theta>_n \\<Longrightarrow>stn (NotL <a>.M x) \\<theta>_n = (NotL <a>.M x)\"\n| \"\\<lbrakk>a\\<sharp>(N,d,b,\\<theta>_n);b\\<sharp>(M,d,a,\\<theta>_n)\\<rbrakk> \\<Longrightarrow> stn (AndR <a>.M <b>.N d) \\<theta>_n = (AndR <a>.M <b>.N d)\"\n| \"x\\<sharp>(z,\\<theta>_n) \\<Longrightarrow> stn (AndL1 (x).M z) \\<theta>_n = (AndL1 (x).M z)\"\n| \"x\\<sharp>(z,\\<theta>_n) \\<Longrightarrow> stn (AndL2 (x).M z) \\<theta>_n = (AndL2 (x).M z)\"\n| \"a\\<sharp>(b,\\<theta>_n) \\<Longrightarrow> stn (OrR1 <a>.M b) \\<theta>_n = (OrR1 <a>.M b)\"\n| \"a\\<sharp>(b,\\<theta>_n) \\<Longrightarrow> stn (OrR2 <a>.M b) \\<theta>_n = (OrR2 <a>.M b)\"\n| \"\\<lbrakk>x\\<sharp>(N,z,u,\\<theta>_n);u\\<sharp>(M,z,x,\\<theta>_n)\\<rbrakk> \\<Longrightarrow> stn (OrL (x).M (u).N z) \\<theta>_n = (OrL (x).M (u).N z)\"\n| \"\\<lbrakk>a\\<sharp>(b,\\<theta>_n);x\\<sharp>\\<theta>_n\\<rbrakk> \\<Longrightarrow> stn (ImpR (x).<a>.M b) \\<theta>_n = (ImpR (x).<a>.M b)\"\n| \"\\<lbrakk>a\\<sharp>(N,\\<theta>_n);x\\<sharp>(M,z,\\<theta>_n)\\<rbrakk> \\<Longrightarrow> stn (ImpL <a>.M (x).N z) \\<theta>_n = (ImpL <a>.M (x).N z)\"\napply(finite_guess)+\napply(rule TrueI)+\napply(simp add: abs_fresh abs_supp fin_supp)+\napply(fresh_guess)+\ndone\n\nnominal_primrec (freshness_context: \"\\<theta>_c::(coname\\<times>name\\<times>trm)\")\n  stc :: \"trm\\<Rightarrow>(coname\\<times>name\\<times>trm) list\\<Rightarrow>trm\" \nwhere\n  \"stc (Ax x a) \\<theta>_c = lookupd x a \\<theta>_c\"\n| \"\\<lbrakk>a\\<sharp>(N,\\<theta>_c);x\\<sharp>(M,\\<theta>_c)\\<rbrakk> \\<Longrightarrow> stc (Cut <a>.M (x).N) \\<theta>_c = (Cut <a>.M (x).N)\" \n| \"x\\<sharp>\\<theta>_c \\<Longrightarrow> stc (NotR (x).M a) \\<theta>_c = (NotR (x).M a)\"\n| \"a\\<sharp>\\<theta>_c \\<Longrightarrow> stc (NotL <a>.M x) \\<theta>_c = (NotL <a>.M x)\"\n| \"\\<lbrakk>a\\<sharp>(N,d,b,\\<theta>_c);b\\<sharp>(M,d,a,\\<theta>_c)\\<rbrakk> \\<Longrightarrow> stc (AndR <a>.M <b>.N d) \\<theta>_c = (AndR <a>.M <b>.N d)\"\n| \"x\\<sharp>(z,\\<theta>_c) \\<Longrightarrow> stc (AndL1 (x).M z) \\<theta>_c = (AndL1 (x).M z)\"\n| \"x\\<sharp>(z,\\<theta>_c) \\<Longrightarrow> stc (AndL2 (x).M z) \\<theta>_c = (AndL2 (x).M z)\"\n| \"a\\<sharp>(b,\\<theta>_c) \\<Longrightarrow> stc (OrR1 <a>.M b) \\<theta>_c = (OrR1 <a>.M b)\"\n| \"a\\<sharp>(b,\\<theta>_c) \\<Longrightarrow> stc (OrR2 <a>.M b) \\<theta>_c = (OrR2 <a>.M b)\"\n| \"\\<lbrakk>x\\<sharp>(N,z,u,\\<theta>_c);u\\<sharp>(M,z,x,\\<theta>_c)\\<rbrakk> \\<Longrightarrow> stc (OrL (x).M (u).N z) \\<theta>_c = (OrL (x).M (u).N z)\"\n| \"\\<lbrakk>a\\<sharp>(b,\\<theta>_c);x\\<sharp>\\<theta>_c\\<rbrakk> \\<Longrightarrow> stc (ImpR (x).<a>.M b) \\<theta>_c = (ImpR (x).<a>.M b)\"\n| \"\\<lbrakk>a\\<sharp>(N,\\<theta>_c);x\\<sharp>(M,z,\\<theta>_c)\\<rbrakk> \\<Longrightarrow> stc (ImpL <a>.M (x).N z) \\<theta>_c = (ImpL <a>.M (x).N z)\"\napply(finite_guess)+\napply(rule TrueI)+\napply(simp add: abs_fresh abs_supp fin_supp)+\napply(fresh_guess)+\ndone\n\nlemma stn_eqvt[eqvt]:\n  fixes pi1::\"name prm\"\n  and   pi2::\"coname prm\"\n  shows \"(pi1\\<bullet>(stn M \\<theta>_n)) = stn (pi1\\<bullet>M) (pi1\\<bullet>\\<theta>_n)\"\n  and   \"(pi2\\<bullet>(stn M \\<theta>_n)) = stn (pi2\\<bullet>M) (pi2\\<bullet>\\<theta>_n)\"\napply -\napply(nominal_induct M avoiding: \\<theta>_n rule: trm.strong_induct)\napply(auto simp add: eqvts fresh_bij fresh_prod eq_bij fresh_atm)\napply(nominal_induct M avoiding: \\<theta>_n rule: trm.strong_induct)\napply(auto simp add: eqvts fresh_bij fresh_prod eq_bij fresh_atm)\ndone\n\nlemma stc_eqvt[eqvt]:\n  fixes pi1::\"name prm\"\n  and   pi2::\"coname prm\"\n  shows \"(pi1\\<bullet>(stc M \\<theta>_c)) = stc (pi1\\<bullet>M) (pi1\\<bullet>\\<theta>_c)\"\n  and   \"(pi2\\<bullet>(stc M \\<theta>_c)) = stc (pi2\\<bullet>M) (pi2\\<bullet>\\<theta>_c)\"\napply -\napply(nominal_induct M avoiding: \\<theta>_c rule: trm.strong_induct)\napply(auto simp add: eqvts fresh_bij fresh_prod eq_bij fresh_atm)\napply(nominal_induct M avoiding: \\<theta>_c rule: trm.strong_induct)\napply(auto simp add: eqvts fresh_bij fresh_prod eq_bij fresh_atm)\ndone\n\nlemma stn_fresh:\n  fixes a::\"coname\"\n  and   x::\"name\"\n  shows \"a\\<sharp>(\\<theta>_n,M) \\<Longrightarrow> a\\<sharp>stn M \\<theta>_n\"\n  and   \"x\\<sharp>(\\<theta>_n,M) \\<Longrightarrow> x\\<sharp>stn M \\<theta>_n\"\napply(nominal_induct M avoiding: \\<theta>_n a x rule: trm.strong_induct)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)\napply(rule lookupc_freshness)\napply(simp add: fresh_atm)\napply(rule lookupc_freshness)\napply(simp add: fresh_atm)\ndone\n\nlemma stc_fresh:\n  fixes a::\"coname\"\n  and   x::\"name\"\n  shows \"a\\<sharp>(\\<theta>_c,M) \\<Longrightarrow> a\\<sharp>stc M \\<theta>_c\"\n  and   \"x\\<sharp>(\\<theta>_c,M) \\<Longrightarrow> x\\<sharp>stc M \\<theta>_c\"\napply(nominal_induct M avoiding: \\<theta>_c a x rule: trm.strong_induct)\napply(auto simp add: abs_fresh fresh_prod fresh_atm)\napply(rule lookupd_freshness)\napply(simp add: fresh_atm)\napply(rule lookupd_freshness)\napply(simp add: fresh_atm)\ndone\n\nlemma case_option_eqvt1[eqvt_force]:\n  fixes pi1::\"name prm\"\n  and   pi2::\"coname prm\"\n  and   B::\"(name\\<times>trm) option\"\n  and   r::\"trm\"\n  shows \"(pi1\\<bullet>(case B of Some (x,P) \\<Rightarrow> s x P | None \\<Rightarrow> r)) = \n              (case (pi1\\<bullet>B) of Some (x,P) \\<Rightarrow> (pi1\\<bullet>s) x P | None \\<Rightarrow> (pi1\\<bullet>r))\"\n  and   \"(pi2\\<bullet>(case B of Some (x,P) \\<Rightarrow> s x P| None \\<Rightarrow> r)) = \n              (case (pi2\\<bullet>B) of Some (x,P) \\<Rightarrow> (pi2\\<bullet>s) x P | None \\<Rightarrow> (pi2\\<bullet>r))\"\napply(cases \"B\")\napply(auto)\napply(perm_simp)\napply(cases \"B\")\napply(auto)\napply(perm_simp)\ndone\n\nlemma case_option_eqvt2[eqvt_force]:\n  fixes pi1::\"name prm\"\n  and   pi2::\"coname prm\"\n  and   B::\"(coname\\<times>trm) option\"\n  and   r::\"trm\"\n  shows \"(pi1\\<bullet>(case B of Some (x,P) \\<Rightarrow> s x P | None \\<Rightarrow> r)) = \n              (case (pi1\\<bullet>B) of Some (x,P) \\<Rightarrow> (pi1\\<bullet>s) x P | None \\<Rightarrow> (pi1\\<bullet>r))\"\n  and   \"(pi2\\<bullet>(case B of Some (x,P) \\<Rightarrow> s x P| None \\<Rightarrow> r)) = \n              (case (pi2\\<bullet>B) of Some (x,P) \\<Rightarrow> (pi2\\<bullet>s) x P | None \\<Rightarrow> (pi2\\<bullet>r))\"\napply(cases \"B\")\napply(auto)\napply(perm_simp)\napply(cases \"B\")\napply(auto)\napply(perm_simp)\ndone\n\nnominal_primrec (freshness_context: \"(\\<theta>_n::(name\\<times>coname\\<times>trm) list,\\<theta>_c::(coname\\<times>name\\<times>trm) list)\")\n  psubst :: \"(name\\<times>coname\\<times>trm) list\\<Rightarrow>(coname\\<times>name\\<times>trm) list\\<Rightarrow>trm\\<Rightarrow>trm\" (\"_,_<_>\" [100,100,100] 100) \nwhere\n  \"\\<theta>_n,\\<theta>_c<Ax x a> = lookup x a \\<theta>_n \\<theta>_c\" \n| \"\\<lbrakk>a\\<sharp>(N,\\<theta>_n,\\<theta>_c);x\\<sharp>(M,\\<theta>_n,\\<theta>_c)\\<rbrakk> \\<Longrightarrow> \\<theta>_n,\\<theta>_c<Cut <a>.M (x).N> = \n   Cut <a>.(if \\<exists>x. M=Ax x a then stn M \\<theta>_n else \\<theta>_n,\\<theta>_c<M>) \n       (x).(if \\<exists>a. N=Ax x a then stc N \\<theta>_c else \\<theta>_n,\\<theta>_c<N>)\" \n| \"x\\<sharp>(\\<theta>_n,\\<theta>_c) \\<Longrightarrow> \\<theta>_n,\\<theta>_c<NotR (x).M a> = \n  (case (findc \\<theta>_c a) of \n       Some (u,P) \\<Rightarrow> fresh_fun (\\<lambda>a'. Cut <a'>.NotR (x).(\\<theta>_n,\\<theta>_c<M>) a' (u).P) \n     | None \\<Rightarrow> NotR (x).(\\<theta>_n,\\<theta>_c<M>) a)\"\n| \"a\\<sharp>(\\<theta>_n,\\<theta>_c) \\<Longrightarrow> \\<theta>_n,\\<theta>_c<NotL <a>.M x> = \n  (case (findn \\<theta>_n x) of \n       Some (c,P) \\<Rightarrow> fresh_fun (\\<lambda>x'. Cut <c>.P (x').(NotL <a>.(\\<theta>_n,\\<theta>_c<M>) x')) \n     | None \\<Rightarrow> NotL <a>.(\\<theta>_n,\\<theta>_c<M>) x)\"\n| \"\\<lbrakk>a\\<sharp>(N,c,\\<theta>_n,\\<theta>_c);b\\<sharp>(M,c,\\<theta>_n,\\<theta>_c);b\\<noteq>a\\<rbrakk> \\<Longrightarrow> (\\<theta>_n,\\<theta>_c<AndR <a>.M <b>.N c>) = \n  (case (findc \\<theta>_c c) of \n       Some (x,P) \\<Rightarrow> fresh_fun (\\<lambda>a'. Cut <a'>.(AndR <a>.(\\<theta>_n,\\<theta>_c<M>) <b>.(\\<theta>_n,\\<theta>_c<N>) a') (x).P)\n     | None \\<Rightarrow> AndR <a>.(\\<theta>_n,\\<theta>_c<M>) <b>.(\\<theta>_n,\\<theta>_c<N>) c)\"\n| \"x\\<sharp>(z,\\<theta>_n,\\<theta>_c) \\<Longrightarrow> (\\<theta>_n,\\<theta>_c<AndL1 (x).M z>) = \n  (case (findn \\<theta>_n z) of \n       Some (c,P) \\<Rightarrow> fresh_fun (\\<lambda>z'. Cut <c>.P (z').AndL1 (x).(\\<theta>_n,\\<theta>_c<M>) z') \n     | None \\<Rightarrow> AndL1 (x).(\\<theta>_n,\\<theta>_c<M>) z)\"\n| \"x\\<sharp>(z,\\<theta>_n,\\<theta>_c) \\<Longrightarrow> (\\<theta>_n,\\<theta>_c<AndL2 (x).M z>) = \n  (case (findn \\<theta>_n z) of \n       Some (c,P) \\<Rightarrow> fresh_fun (\\<lambda>z'. Cut <c>.P (z').AndL2 (x).(\\<theta>_n,\\<theta>_c<M>) z') \n     | None \\<Rightarrow> AndL2 (x).(\\<theta>_n,\\<theta>_c<M>) z)\"\n| \"\\<lbrakk>x\\<sharp>(N,z,\\<theta>_n,\\<theta>_c);u\\<sharp>(M,z,\\<theta>_n,\\<theta>_c);x\\<noteq>u\\<rbrakk> \\<Longrightarrow> (\\<theta>_n,\\<theta>_c<OrL (x).M (u).N z>) =\n  (case (findn \\<theta>_n z) of  \n       Some (c,P) \\<Rightarrow> fresh_fun (\\<lambda>z'. Cut <c>.P (z').OrL (x).(\\<theta>_n,\\<theta>_c<M>) (u).(\\<theta>_n,\\<theta>_c<N>) z') \n     | None \\<Rightarrow> OrL (x).(\\<theta>_n,\\<theta>_c<M>) (u).(\\<theta>_n,\\<theta>_c<N>) z)\"\n| \"a\\<sharp>(b,\\<theta>_n,\\<theta>_c) \\<Longrightarrow> (\\<theta>_n,\\<theta>_c<OrR1 <a>.M b>) = \n  (case (findc \\<theta>_c b) of\n       Some (x,P) \\<Rightarrow> fresh_fun (\\<lambda>a'. Cut <a'>.OrR1 <a>.(\\<theta>_n,\\<theta>_c<M>) a' (x).P) \n     | None \\<Rightarrow> OrR1 <a>.(\\<theta>_n,\\<theta>_c<M>) b)\"\n| \"a\\<sharp>(b,\\<theta>_n,\\<theta>_c) \\<Longrightarrow> (\\<theta>_n,\\<theta>_c<OrR2 <a>.M b>) = \n  (case (findc \\<theta>_c b) of\n       Some (x,P) \\<Rightarrow> fresh_fun (\\<lambda>a'. Cut <a'>.OrR2 <a>.(\\<theta>_n,\\<theta>_c<M>) a' (x).P) \n     | None \\<Rightarrow> OrR2 <a>.(\\<theta>_n,\\<theta>_c<M>) b)\"\n| \"\\<lbrakk>a\\<sharp>(b,\\<theta>_n,\\<theta>_c); x\\<sharp>(\\<theta>_n,\\<theta>_c)\\<rbrakk> \\<Longrightarrow> (\\<theta>_n,\\<theta>_c<ImpR (x).<a>.M b>) = \n  (case (findc \\<theta>_c b) of\n       Some (z,P) \\<Rightarrow> fresh_fun (\\<lambda>a'. Cut <a'>.ImpR (x).<a>.(\\<theta>_n,\\<theta>_c<M>) a' (z).P)\n     | None \\<Rightarrow> ImpR (x).<a>.(\\<theta>_n,\\<theta>_c<M>) b)\"\n| \"\\<lbrakk>a\\<sharp>(N,\\<theta>_n,\\<theta>_c); x\\<sharp>(z,M,\\<theta>_n,\\<theta>_c)\\<rbrakk> \\<Longrightarrow> (\\<theta>_n,\\<theta>_c<ImpL <a>.M (x).N z>) = \n  (case (findn \\<theta>_n z) of\n       Some (c,P) \\<Rightarrow> fresh_fun (\\<lambda>z'. Cut <c>.P (z').ImpL <a>.(\\<theta>_n,\\<theta>_c<M>) (x).(\\<theta>_n,\\<theta>_c<N>) z') \n     | None \\<Rightarrow> ImpL <a>.(\\<theta>_n,\\<theta>_c<M>) (x).(\\<theta>_n,\\<theta>_c<N>) z)\"\napply(finite_guess)+\napply(rule TrueI)+\napply(simp add: abs_fresh stc_fresh)\napply(simp add: abs_fresh stn_fresh)\napply(case_tac \"findc \\<theta>_c x3\")\napply(simp add: abs_fresh)\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp (no_asm))\napply(drule cmaps_fresh)\napply(auto simp add: fresh_prod)[1]\napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(case_tac \"findn \\<theta>_n x3\")\napply(simp add: abs_fresh)\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp (no_asm))\napply(drule nmaps_fresh)\napply(auto simp add: fresh_prod)[1]\napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(case_tac \"findc \\<theta>_c x5\")\napply(simp add: abs_fresh)\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp (no_asm))\napply(drule cmaps_fresh)\napply(auto simp add: fresh_prod)[1]\napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(case_tac \"findc \\<theta>_c x5\")\napply(simp add: abs_fresh)\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp (no_asm))\napply(drule_tac x=\"x3\" in cmaps_fresh)\napply(auto simp add: fresh_prod)[1]\napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(case_tac \"findn \\<theta>_n x3\")\napply(simp add: abs_fresh)\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp (no_asm))\napply(drule nmaps_fresh)\napply(auto simp add: fresh_prod)[1]\napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(case_tac \"findn \\<theta>_n x3\")\napply(simp add: abs_fresh)\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp (no_asm))\napply(drule nmaps_fresh)\napply(auto simp add: fresh_prod)[1]\napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(case_tac \"findc \\<theta>_c x3\")\napply(simp add: abs_fresh)\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp (no_asm))\napply(drule cmaps_fresh)\napply(auto simp add: fresh_prod)[1]\napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(case_tac \"findc \\<theta>_c x3\")\napply(simp add: abs_fresh)\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp (no_asm))\napply(drule cmaps_fresh)\napply(auto simp add: fresh_prod)[1]\napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(case_tac \"findn \\<theta>_n x5\")\napply(simp add: abs_fresh)\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp (no_asm))\napply(drule nmaps_fresh)\napply(auto simp add: fresh_prod)[1]\napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(case_tac \"findn \\<theta>_n x5\")\napply(simp add: abs_fresh)\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp (no_asm))\napply(drule_tac a=\"x3\" in nmaps_fresh)\napply(auto simp add: fresh_prod)[1]\napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(case_tac \"findc \\<theta>_c x4\")\napply(simp add: abs_fresh abs_supp fin_supp)\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp (no_asm))\napply(drule cmaps_fresh)\napply(auto simp add: fresh_prod)[1]\napply(simp add: abs_fresh fresh_prod fresh_atm abs_supp fin_supp)\napply(case_tac \"findc \\<theta>_c x4\")\napply(simp add: abs_fresh abs_supp fin_supp)\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp (no_asm))\napply(drule_tac x=\"x2\" in cmaps_fresh)\napply(auto simp add: fresh_prod)[1]\napply(simp add: abs_fresh fresh_prod fresh_atm abs_supp fin_supp)\napply(case_tac \"findn \\<theta>_n x5\")\napply(simp add: abs_fresh)\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp (no_asm))\napply(drule nmaps_fresh)\napply(auto simp add: fresh_prod)[1]\napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(case_tac \"findn \\<theta>_n x5\")\napply(simp add: abs_fresh)\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp (no_asm))\napply(drule_tac a=\"x3\" in nmaps_fresh)\napply(auto simp add: fresh_prod)[1]\napply(simp add: abs_fresh fresh_prod fresh_atm)\napply(fresh_guess)+\ndone\n\nlemma case_cong:\n  assumes a: \"B1=B2\" \"x1=x2\" \"y1=y2\"\n  shows \"(case B1 of None \\<Rightarrow> x1 | Some (x,P) \\<Rightarrow> y1 x P) = (case B2 of None \\<Rightarrow> x2 | Some (x,P) \\<Rightarrow> y2 x P)\"\nusing a\napply(auto)\ndone\n\nlemma find_maps:\n  shows \"\\<theta>_c cmaps a to (findc \\<theta>_c a)\"\n  and   \"\\<theta>_n nmaps x to (findn \\<theta>_n x)\"\napply(auto)\ndone\n\nlemma psubst_eqvt[eqvt]:\n  fixes pi1::\"name prm\"\n  and   pi2::\"coname prm\"\n  shows \"pi1\\<bullet>(\\<theta>_n,\\<theta>_c<M>) = (pi1\\<bullet>\\<theta>_n),(pi1\\<bullet>\\<theta>_c)<(pi1\\<bullet>M)>\"\n  and   \"pi2\\<bullet>(\\<theta>_n,\\<theta>_c<M>) = (pi2\\<bullet>\\<theta>_n),(pi2\\<bullet>\\<theta>_c)<(pi2\\<bullet>M)>\"\napply(nominal_induct M avoiding: \\<theta>_n \\<theta>_c rule: trm.strong_induct)\napply(auto simp add: eq_bij fresh_bij eqvts perm_pi_simp)\napply(rule case_cong)\napply(rule find_maps)\napply(simp)\napply(perm_simp add: eqvts)\napply(rule case_cong)\napply(rule find_maps)\napply(simp)\napply(perm_simp add: eqvts)\napply(rule case_cong)\napply(rule find_maps)\napply(simp)\napply(perm_simp add: eqvts)\napply(rule case_cong)\napply(rule find_maps)\napply(simp)\napply(perm_simp add: eqvts)\napply(rule case_cong)\napply(rule find_maps)\napply(simp)\napply(perm_simp add: eqvts)\napply(rule case_cong)\napply(rule find_maps)\napply(simp)\napply(perm_simp add: eqvts)\napply(rule case_cong)\napply(rule find_maps)\napply(simp)\napply(perm_simp add: eqvts)\napply(rule case_cong)\napply(rule find_maps)\napply(simp)\napply(perm_simp add: eqvts)\napply(rule case_cong)\napply(rule find_maps)\napply(simp)\napply(perm_simp add: eqvts)\napply(rule case_cong)\napply(rule find_maps)\napply(simp)\napply(perm_simp add: eqvts)\napply(rule case_cong)\napply(rule find_maps)\napply(simp)\napply(perm_simp add: eqvts)\napply(rule case_cong)\napply(rule find_maps)\napply(simp)\napply(perm_simp add: eqvts)\napply(rule case_cong)\napply(rule find_maps)\napply(simp)\napply(perm_simp add: eqvts)\napply(rule case_cong)\napply(rule find_maps)\napply(simp)\napply(perm_simp add: eqvts)\napply(rule case_cong)\napply(rule find_maps)\napply(simp)\napply(perm_simp add: eqvts)\napply(rule case_cong)\napply(rule find_maps)\napply(simp)\napply(perm_simp add: eqvts)\napply(rule case_cong)\napply(rule find_maps)\napply(simp)\napply(perm_simp add: eqvts)\napply(rule case_cong)\napply(rule find_maps)\napply(simp)\napply(perm_simp add: eqvts)\napply(rule case_cong)\napply(rule find_maps)\napply(simp)\napply(perm_simp add: eqvts)\napply(rule case_cong)\napply(rule find_maps)\napply(simp)\napply(perm_simp add: eqvts)\ndone\n\nlemma ax_psubst:\n  assumes a: \"\\<theta>_n,\\<theta>_c<M> = Ax x a\"\n  and     b: \"a\\<sharp>(\\<theta>_n,\\<theta>_c)\" \"x\\<sharp>(\\<theta>_n,\\<theta>_c)\"\n  shows \"M = Ax x a\"\nusing a b\napply(nominal_induct M avoiding: \\<theta>_n \\<theta>_c rule: trm.strong_induct)\napply(auto)\napply(drule lookup_unicity)\napply(simp)+\napply(case_tac \"findc \\<theta>_c coname\")\napply(simp)\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(simp)\napply(case_tac \"findn \\<theta>_n name\")\napply(simp)\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname3\")\napply(simp)\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(simp)\napply(case_tac \"findn \\<theta>_n name2\")\napply(simp)\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(simp)\napply(case_tac \"findn \\<theta>_n name2\")\napply(simp)\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname2\")\napply(simp)\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname2\")\napply(simp)\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(simp)\napply(case_tac \"findn \\<theta>_n name3\")\napply(simp)\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname2\")\napply(simp)\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(simp)\napply(case_tac \"findn \\<theta>_n name2\")\napply(simp)\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(simp)\ndone\n\nlemma better_Cut_substc1:\n  assumes a: \"a\\<sharp>(P,b)\" \"b\\<sharp>N\" \n  shows \"(Cut <a>.M (x).N){b:=(y).P} = Cut <a>.(M{b:=(y).P}) (x).N\"\nusing a\napply -\napply(generate_fresh \"coname\")\napply(generate_fresh \"name\")\napply(subgoal_tac \"Cut <a>.M (x).N = Cut <c>.([(c,a)]\\<bullet>M) (ca).([(ca,x)]\\<bullet>N)\")\napply(simp)\napply(rule trans)\napply(rule better_Cut_substc)\napply(simp)\napply(simp add: abs_fresh)\napply(auto)[1]\napply(drule pt_bij1[OF pt_name_inst, OF at_name_inst])\napply(simp add: calc_atm fresh_atm)\napply(subgoal_tac\"b\\<sharp>([(ca,x)]\\<bullet>N)\")\napply(simp add: forget)\napply(simp add: trm.inject)\napply(simp add: alpha eqvts calc_atm fresh_prod fresh_atm subst_fresh)[1]\napply(perm_simp)\napply(simp add: fresh_left calc_atm)\napply(simp add: trm.inject)\napply(rule conjI)\napply(rule sym)\napply(simp add: alpha eqvts calc_atm fresh_prod fresh_atm subst_fresh)[1]\napply(rule sym)\napply(simp add: alpha eqvts calc_atm fresh_prod fresh_atm subst_fresh)[1]\ndone\n\nlemma better_Cut_substc2:\n  assumes a: \"x\\<sharp>(y,P)\" \"b\\<sharp>(a,M)\" \"N\\<noteq>Ax x b\"\n  shows \"(Cut <a>.M (x).N){b:=(y).P} = Cut <a>.M (x).(N{b:=(y).P})\"\nusing a\napply -\napply(generate_fresh \"coname\")\napply(generate_fresh \"name\")\napply(subgoal_tac \"Cut <a>.M (x).N = Cut <c>.([(c,a)]\\<bullet>M) (ca).([(ca,x)]\\<bullet>N)\")\napply(simp)\napply(rule trans)\napply(rule better_Cut_substc)\napply(simp)\napply(simp add: abs_fresh)\napply(auto)[1]\napply(drule pt_bij1[OF pt_name_inst, OF at_name_inst])\napply(simp add: calc_atm fresh_atm fresh_prod)\napply(subgoal_tac\"b\\<sharp>([(c,a)]\\<bullet>M)\")\napply(simp add: forget)\napply(simp add: trm.inject)\napply(simp add: alpha eqvts calc_atm fresh_prod fresh_atm subst_fresh)[1]\napply(perm_simp)\napply(auto simp add: fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(simp add: trm.inject)\napply(rule conjI)\napply(rule sym)\napply(simp add: alpha eqvts calc_atm fresh_prod fresh_atm subst_fresh)[1]\napply(rule sym)\napply(simp add: alpha eqvts calc_atm fresh_prod fresh_atm subst_fresh)[1]\ndone\n\nlemma better_Cut_substn1:\n  assumes a: \"y\\<sharp>(x,N)\" \"a\\<sharp>(b,P)\" \"M\\<noteq>Ax y a\"\n  shows \"(Cut <a>.M (x).N){y:=<b>.P} = Cut <a>.(M{y:=<b>.P}) (x).N\"\nusing a\napply -\napply(generate_fresh \"coname\")\napply(generate_fresh \"name\")\napply(subgoal_tac \"Cut <a>.M (x).N = Cut <c>.([(c,a)]\\<bullet>M) (ca).([(ca,x)]\\<bullet>N)\")\napply(simp)\napply(rule trans)\napply(rule better_Cut_substn)\napply(simp add: abs_fresh)\napply(simp add: abs_fresh)\napply(auto)[1]\napply(drule pt_bij1[OF pt_coname_inst, OF at_coname_inst])\napply(simp add: calc_atm fresh_atm fresh_prod)\napply(subgoal_tac\"y\\<sharp>([(ca,x)]\\<bullet>N)\")\napply(simp add: forget)\napply(simp add: trm.inject)\napply(simp add: alpha eqvts calc_atm fresh_prod fresh_atm subst_fresh)[1]\napply(perm_simp)\napply(auto simp add: fresh_left calc_atm fresh_prod fresh_atm)[1]\napply(simp add: trm.inject)\napply(rule conjI)\napply(rule sym)\napply(simp add: alpha eqvts calc_atm fresh_prod fresh_atm subst_fresh)[1]\napply(rule sym)\napply(simp add: alpha eqvts calc_atm fresh_prod fresh_atm subst_fresh)[1]\ndone\n\nlemma better_Cut_substn2:\n  assumes a: \"x\\<sharp>(P,y)\" \"y\\<sharp>M\" \n  shows \"(Cut <a>.M (x).N){y:=<b>.P} = Cut <a>.M (x).(N{y:=<b>.P})\"\nusing a\napply -\napply(generate_fresh \"coname\")\napply(generate_fresh \"name\")\napply(subgoal_tac \"Cut <a>.M (x).N = Cut <c>.([(c,a)]\\<bullet>M) (ca).([(ca,x)]\\<bullet>N)\")\napply(simp)\napply(rule trans)\napply(rule better_Cut_substn)\napply(simp add: abs_fresh)\napply(simp add: abs_fresh)\napply(auto)[1]\napply(drule pt_bij1[OF pt_coname_inst, OF at_coname_inst])\napply(simp add: calc_atm fresh_atm)\napply(subgoal_tac\"y\\<sharp>([(c,a)]\\<bullet>M)\")\napply(simp add: forget)\napply(simp add: trm.inject)\napply(simp add: alpha eqvts calc_atm fresh_prod fresh_atm subst_fresh)[1]\napply(perm_simp)\napply(simp add: fresh_left calc_atm)\napply(simp add: trm.inject)\napply(rule conjI)\napply(rule sym)\napply(simp add: alpha eqvts calc_atm fresh_prod fresh_atm subst_fresh)[1]\napply(rule sym)\napply(simp add: alpha eqvts calc_atm fresh_prod fresh_atm subst_fresh)[1]\ndone\n\nlemma psubst_fresh_name:\n  fixes x::\"name\"\n  assumes a: \"x\\<sharp>\\<theta>_n\" \"x\\<sharp>\\<theta>_c\" \"x\\<sharp>M\"\n  shows \"x\\<sharp>\\<theta>_n,\\<theta>_c<M>\"\nusing a\napply(nominal_induct M avoiding: x \\<theta>_n \\<theta>_c rule: trm.strong_induct)\napply(simp add: lookup_freshness)\napply(auto simp add: abs_fresh)[1]\napply(simp add: lookupc_freshness)\napply(simp add: lookupc_freshness)\napply(simp add: lookupc_freshness)\napply(simp add: lookupd_freshness)\napply(simp add: lookupd_freshness)\napply(simp add: lookupc_freshness)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname\")\napply(auto simp add: abs_fresh)[1]\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(simp add: abs_fresh fresh_prod fresh_atm cmaps_fresh)\napply(simp)\napply(case_tac \"findn \\<theta>_n name\")\napply(auto simp add: abs_fresh)[1]\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(simp add: abs_fresh fresh_prod fresh_atm nmaps_fresh)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname3\")\napply(auto simp add: abs_fresh)[1]\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(simp add: abs_fresh fresh_prod fresh_atm cmaps_fresh)\napply(simp)\napply(case_tac \"findn \\<theta>_n name2\")\napply(auto simp add: abs_fresh)[1]\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(simp add: abs_fresh fresh_prod fresh_atm nmaps_fresh)\napply(simp)\napply(case_tac \"findn \\<theta>_n name2\")\napply(auto simp add: abs_fresh)[1]\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(simp add: abs_fresh fresh_prod fresh_atm nmaps_fresh)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname2\")\napply(auto simp add: abs_fresh)[1]\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(simp add: abs_fresh fresh_prod fresh_atm cmaps_fresh)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname2\")\napply(auto simp add: abs_fresh)[1]\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(simp add: abs_fresh fresh_prod fresh_atm cmaps_fresh)\napply(simp)\napply(case_tac \"findn \\<theta>_n name3\")\napply(auto simp add: abs_fresh)[1]\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(simp add: abs_fresh fresh_prod fresh_atm nmaps_fresh)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname2\")\napply(auto simp add: abs_fresh abs_supp fin_supp)[1]\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(simp add: abs_fresh abs_supp fin_supp fresh_prod fresh_atm cmaps_fresh)\napply(simp)\napply(case_tac \"findn \\<theta>_n name2\")\napply(auto simp add: abs_fresh)[1]\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(simp add: abs_fresh fresh_prod fresh_atm nmaps_fresh)\ndone\n\nlemma psubst_fresh_coname:\n  fixes a::\"coname\"\n  assumes a: \"a\\<sharp>\\<theta>_n\" \"a\\<sharp>\\<theta>_c\" \"a\\<sharp>M\"\n  shows \"a\\<sharp>\\<theta>_n,\\<theta>_c<M>\"\nusing a\napply(nominal_induct M avoiding: a \\<theta>_n \\<theta>_c rule: trm.strong_induct)\napply(simp add: lookup_freshness)\napply(auto simp add: abs_fresh)[1]\napply(simp add: lookupd_freshness)\napply(simp add: lookupd_freshness)\napply(simp add: lookupc_freshness)\napply(simp add: lookupd_freshness)\napply(simp add: lookupc_freshness)\napply(simp add: lookupd_freshness)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname\")\napply(auto simp add: abs_fresh)[1]\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(simp add: abs_fresh fresh_prod fresh_atm cmaps_fresh)\napply(simp)\napply(case_tac \"findn \\<theta>_n name\")\napply(auto simp add: abs_fresh)[1]\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(simp add: abs_fresh fresh_prod fresh_atm nmaps_fresh)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname3\")\napply(auto simp add: abs_fresh)[1]\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(simp add: abs_fresh fresh_prod fresh_atm cmaps_fresh)\napply(simp)\napply(case_tac \"findn \\<theta>_n name2\")\napply(auto simp add: abs_fresh)[1]\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(simp add: abs_fresh fresh_prod fresh_atm nmaps_fresh)\napply(simp)\napply(case_tac \"findn \\<theta>_n name2\")\napply(auto simp add: abs_fresh)[1]\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(simp add: abs_fresh fresh_prod fresh_atm nmaps_fresh)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname2\")\napply(auto simp add: abs_fresh)[1]\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(simp add: abs_fresh fresh_prod fresh_atm cmaps_fresh)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname2\")\napply(auto simp add: abs_fresh)[1]\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(simp add: abs_fresh fresh_prod fresh_atm cmaps_fresh)\napply(simp)\napply(case_tac \"findn \\<theta>_n name3\")\napply(auto simp add: abs_fresh)[1]\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(simp add: abs_fresh fresh_prod fresh_atm nmaps_fresh)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname2\")\napply(auto simp add: abs_fresh abs_supp fin_supp)[1]\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(simp add: abs_fresh abs_supp fin_supp fresh_prod fresh_atm cmaps_fresh)\napply(simp)\napply(case_tac \"findn \\<theta>_n name2\")\napply(auto simp add: abs_fresh)[1]\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(simp add: abs_fresh fresh_prod fresh_atm nmaps_fresh)\ndone\n\nlemma psubst_csubst:\n  assumes a: \"a\\<sharp>(\\<theta>_n,\\<theta>_c)\"\n  shows \"\\<theta>_n,((a,x,P)#\\<theta>_c)<M> = ((\\<theta>_n,\\<theta>_c<M>){a:=(x).P})\"\nusing a\napply(nominal_induct M avoiding: a x \\<theta>_n \\<theta>_c P rule: trm.strong_induct)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(simp add: lookup_csubst)\napply(simp add: fresh_list_cons fresh_prod)\napply(auto)[1]\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substc)\napply(simp)\napply(simp add: abs_fresh fresh_atm)\napply(simp add: lookupd_fresh)\napply(subgoal_tac \"a\\<sharp>lookupc xa coname \\<theta>_n\")\napply(simp add: forget)\napply(simp add: trm.inject)\napply(rule sym)\napply(simp add: alpha nrename_swap fresh_atm)\napply(rule lookupc_freshness)\napply(simp add: fresh_atm)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substc)\napply(simp)\napply(simp add: abs_fresh fresh_atm)\napply(simp)\napply(rule conjI)\napply(rule impI)\napply(simp add: lookupd_unicity)\napply(rule impI)\napply(subgoal_tac \"a\\<sharp>lookupc xa coname \\<theta>_n\")\napply(subgoal_tac \"a\\<sharp>lookupd name aa \\<theta>_c\")\napply(simp add: forget)\napply(rule lookupd_freshness)\napply(simp add: fresh_atm)\napply(rule lookupc_freshness)\napply(simp add: fresh_atm)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substc)\napply(simp)\napply(simp add: abs_fresh fresh_atm)\napply(simp)\napply(rule conjI)\napply(rule impI)\napply(drule ax_psubst)\napply(simp)\napply(simp)\napply(blast)\napply(rule impI)\napply(subgoal_tac \"a\\<sharp>lookupc xa coname \\<theta>_n\")\napply(simp add: forget)\napply(rule lookupc_freshness)\napply(simp add: fresh_atm)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substc)\napply(simp)\napply(simp add: abs_fresh fresh_atm)\napply(simp)\napply(rule conjI)\napply(rule impI)\napply(simp add: trm.inject)\napply(rule sym)\napply(simp add: alpha)\napply(simp add: alpha nrename_swap fresh_atm)\napply(simp add: lookupd_fresh)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substc)\napply(simp)\napply(simp add: abs_fresh fresh_atm)\napply(simp)\napply(rule conjI)\napply(rule impI)\napply(simp add: lookupd_unicity)\napply(rule impI)\napply(subgoal_tac \"a\\<sharp>lookupd name aa \\<theta>_c\")\napply(simp add: forget)\napply(rule lookupd_freshness)\napply(simp add: fresh_atm)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substc)\napply(simp)\napply(simp add: abs_fresh fresh_atm)\napply(simp)\napply(rule impI)\napply(drule ax_psubst)\napply(simp)\napply(simp)\napply(blast)\n(* NotR *)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname\")\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(drule cmaps_false)\napply(assumption)\napply(simp)\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(fresh_fun_simp)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substc1)\napply(simp)\napply(simp add: cmaps_fresh)\napply(auto simp add: fresh_prod fresh_atm)[1]\n(* NotL *)\napply(simp)\napply(case_tac \"findn \\<theta>_n name\")\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(fresh_fun_simp)\napply(drule_tac a=\"a\" in nmaps_fresh)\napply(assumption)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substc2)\napply(simp)\napply(simp)\napply(simp)\napply(simp)\n(* AndR *)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname3\")\napply(simp)\napply(auto simp add: psubst_fresh_coname fresh_list_cons fresh_prod fresh_atm)[1]\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(drule cmaps_false)\napply(assumption)\napply(simp)\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(fresh_fun_simp)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substc1)\napply(simp)\napply(simp add: cmaps_fresh)\napply(auto simp add:  psubst_fresh_coname fresh_prod fresh_atm)[1]\n(* AndL1 *)\napply(simp)\napply(case_tac \"findn \\<theta>_n name2\")\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(fresh_fun_simp)\napply(drule_tac a=\"a\" in nmaps_fresh)\napply(assumption)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substc2)\napply(simp)\napply(simp)\napply(simp)\napply(auto simp add:  psubst_fresh_coname fresh_prod fresh_atm)[1]\n(* AndL2 *)\napply(simp)\napply(case_tac \"findn \\<theta>_n name2\")\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(fresh_fun_simp)\napply(drule_tac a=\"a\" in nmaps_fresh)\napply(assumption)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substc2)\napply(simp)\napply(simp)\napply(simp)\napply(auto simp add:  psubst_fresh_coname fresh_prod fresh_atm)[1]\n(* OrR1 *)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname2\")\napply(simp)\napply(auto simp add: psubst_fresh_coname fresh_list_cons fresh_prod fresh_atm)[1]\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(drule cmaps_false)\napply(assumption)\napply(simp)\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(fresh_fun_simp)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substc1)\napply(simp)\napply(simp add: cmaps_fresh)\napply(auto simp add:  psubst_fresh_coname fresh_prod fresh_atm)[1]\n(* OrR2 *)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname2\")\napply(simp)\napply(auto simp add: psubst_fresh_coname fresh_list_cons fresh_prod fresh_atm)[1]\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(drule cmaps_false)\napply(assumption)\napply(simp)\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(fresh_fun_simp)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substc1)\napply(simp)\napply(simp add: cmaps_fresh)\napply(auto simp add:  psubst_fresh_coname fresh_prod fresh_atm)[1]\n(* OrL *)\napply(simp)\napply(case_tac \"findn \\<theta>_n name3\")\napply(simp)\napply(auto simp add: fresh_list_cons psubst_fresh_name fresh_atm fresh_prod)[1]\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(fresh_fun_simp)\napply(drule_tac a=\"a\" in nmaps_fresh)\napply(assumption)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substc2)\napply(simp)\napply(simp)\napply(simp)\napply(auto simp add:  psubst_fresh_name fresh_prod fresh_atm)[1]\n(* ImpR *)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname2\")\napply(simp)\napply(auto simp add: psubst_fresh_coname fresh_list_cons fresh_prod fresh_atm)[1]\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(drule cmaps_false)\napply(assumption)\napply(simp)\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(fresh_fun_simp)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substc1)\napply(simp)\napply(simp add: cmaps_fresh)\napply(auto simp add:  psubst_fresh_coname fresh_prod fresh_atm)[1]\n(* ImpL *)\napply(simp)\napply(case_tac \"findn \\<theta>_n name2\")\napply(simp)\napply(auto simp add: fresh_list_cons psubst_fresh_coname psubst_fresh_name fresh_atm fresh_prod)[1]\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(fresh_fun_simp)\napply(simp add: abs_fresh subst_fresh)\napply(drule_tac a=\"a\" in nmaps_fresh)\napply(assumption)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substc2)\napply(simp)\napply(simp)\napply(simp)\napply(auto simp add: psubst_fresh_coname psubst_fresh_name fresh_prod fresh_atm)[1]\ndone\n\nlemma psubst_nsubst:\n  assumes a: \"x\\<sharp>(\\<theta>_n,\\<theta>_c)\"\n  shows \"((x,a,P)#\\<theta>_n),\\<theta>_c<M> = ((\\<theta>_n,\\<theta>_c<M>){x:=<a>.P})\"\nusing a\napply(nominal_induct M avoiding: a x \\<theta>_n \\<theta>_c P rule: trm.strong_induct)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(simp add: lookup_fresh)\napply(rule lookupb_lookupa)\napply(simp)\napply(rule sym)\napply(rule forget)\napply(rule lookup_freshness)\napply(simp add: fresh_atm)\napply(auto simp add: lookupc_freshness fresh_list_cons fresh_prod)[1]\napply(simp add: lookupc_fresh)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substn)\napply(simp add: abs_fresh)\napply(simp add: abs_fresh fresh_atm)\napply(simp add: lookupd_fresh)\napply(subgoal_tac \"x\\<sharp>lookupd name aa \\<theta>_c\")\napply(simp add: forget)\napply(simp add: trm.inject)\napply(rule sym)\napply(simp add: alpha crename_swap fresh_atm)\napply(rule lookupd_freshness)\napply(simp add: fresh_atm)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substn)\napply(simp add: abs_fresh) \napply(simp add: abs_fresh fresh_atm)\napply(simp)\napply(rule conjI)\napply(rule impI)\napply(simp add: lookupc_unicity)\napply(rule impI)\napply(subgoal_tac \"x\\<sharp>lookupc xa coname \\<theta>_n\")\napply(subgoal_tac \"x\\<sharp>lookupd name aa \\<theta>_c\")\napply(simp add: forget)\napply(rule lookupd_freshness)\napply(simp add: fresh_atm)\napply(rule lookupc_freshness)\napply(simp add: fresh_atm)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substn)\napply(simp add: abs_fresh)\napply(simp add: abs_fresh fresh_atm)\napply(simp)\napply(rule conjI)\napply(rule impI)\napply(simp add: trm.inject)\napply(rule sym)\napply(simp add: alpha crename_swap fresh_atm)\napply(rule impI)\napply(simp add: lookupc_fresh)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substn)\napply(simp add: abs_fresh)\napply(simp add: abs_fresh fresh_atm)\napply(simp)\napply(rule conjI)\napply(rule impI)\napply(simp add: lookupc_unicity)\napply(rule impI)\napply(subgoal_tac \"x\\<sharp>lookupc xa coname \\<theta>_n\")\napply(simp add: forget)\napply(rule lookupc_freshness)\napply(simp add: fresh_prod fresh_atm)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substn)\napply(simp add: abs_fresh)\napply(simp add: abs_fresh fresh_atm)\napply(simp)\napply(rule conjI)\napply(rule impI)\napply(drule ax_psubst)\napply(simp)\napply(simp)\napply(simp)\napply(blast)\napply(rule impI)\napply(subgoal_tac \"x\\<sharp>lookupd name aa \\<theta>_c\")\napply(simp add: forget)\napply(rule lookupd_freshness)\napply(simp add: fresh_atm)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substn)\napply(simp add: abs_fresh)\napply(simp add: abs_fresh fresh_atm)\napply(simp)\napply(rule impI)\napply(drule ax_psubst)\napply(simp)\napply(simp)\napply(blast)\n(* NotR *)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname\")\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(fresh_fun_simp)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substn1)\napply(simp add: cmaps_fresh)\napply(simp)\napply(simp)\napply(simp)\n(* NotL *)\napply(simp)\napply(case_tac \"findn \\<theta>_n name\")\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(drule nmaps_false)\napply(simp)\napply(simp)\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(fresh_fun_simp)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substn2)\napply(simp)\napply(simp add: nmaps_fresh)\napply(simp add: fresh_prod fresh_atm)\n(* AndR *)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname3\")\napply(simp)\napply(auto simp add: psubst_fresh_coname fresh_list_cons fresh_prod fresh_atm)[1]\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(fresh_fun_simp)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substn1)\napply(simp add: cmaps_fresh)\napply(simp)\napply(simp)\napply(auto simp add:  psubst_fresh_coname fresh_prod fresh_atm)[1]\n(* AndL1 *)\napply(simp)\napply(case_tac \"findn \\<theta>_n name2\")\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(drule nmaps_false)\napply(simp)\napply(simp)\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(fresh_fun_simp)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substn2)\napply(simp)\napply(simp add: nmaps_fresh)\napply(auto simp add:  psubst_fresh_coname fresh_prod fresh_atm)[1]\n(* AndL2 *)\napply(simp)\napply(case_tac \"findn \\<theta>_n name2\")\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(drule nmaps_false)\napply(simp)\napply(simp)\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(fresh_fun_simp)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substn2)\napply(simp)\napply(simp add: nmaps_fresh)\napply(auto simp add:  psubst_fresh_coname fresh_prod fresh_atm)[1]\n(* OrR1 *)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname2\")\napply(simp)\napply(auto simp add: psubst_fresh_coname fresh_list_cons fresh_prod fresh_atm)[1]\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(fresh_fun_simp)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substn1)\napply(simp add: cmaps_fresh)\napply(simp)\napply(simp)\napply(auto simp add:  psubst_fresh_coname fresh_prod fresh_atm)[1]\n(* OrR2 *)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname2\")\napply(simp)\napply(auto simp add: psubst_fresh_coname fresh_list_cons fresh_prod fresh_atm)[1]\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(fresh_fun_simp)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substn1)\napply(simp add: cmaps_fresh)\napply(simp)\napply(simp)\napply(auto simp add:  psubst_fresh_coname fresh_prod fresh_atm)[1]\n(* OrL *)\napply(simp)\napply(case_tac \"findn \\<theta>_n name3\")\napply(simp)\napply(auto simp add: fresh_list_cons psubst_fresh_name fresh_atm fresh_prod)[1]\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(drule nmaps_false)\napply(simp)\napply(simp)\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(fresh_fun_simp)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substn2)\napply(simp)\napply(simp add: nmaps_fresh)\napply(auto simp add:  psubst_fresh_name fresh_prod fresh_atm)[1]\n(* ImpR *)\napply(simp)\napply(case_tac \"findc \\<theta>_c coname2\")\napply(simp)\napply(auto simp add: psubst_fresh_coname fresh_list_cons fresh_prod fresh_atm)[1]\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(fresh_fun_simp)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substn1)\napply(simp add: cmaps_fresh)\napply(simp)\napply(simp)\napply(auto simp add:  psubst_fresh_coname fresh_prod fresh_atm)[1]\n(* ImpL *)\napply(simp)\napply(case_tac \"findn \\<theta>_n name2\")\napply(simp)\napply(auto simp add: fresh_list_cons psubst_fresh_coname psubst_fresh_name fresh_atm fresh_prod)[1]\napply(simp)\napply(auto simp add: fresh_list_cons fresh_prod)[1]\napply(drule nmaps_false)\napply(simp)\napply(simp)\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(fresh_fun_simp)\napply(rule sym)\napply(rule trans)\napply(rule better_Cut_substn2)\napply(simp)\napply(simp add: nmaps_fresh)\napply(auto simp add: psubst_fresh_coname psubst_fresh_name fresh_prod fresh_atm)[1]\ndone\n\ndefinition \n  ncloses :: \"(name\\<times>coname\\<times>trm) list\\<Rightarrow>(name\\<times>ty) list \\<Rightarrow> bool\" (\"_ ncloses _\" [55,55] 55) \nwhere\n  \"\\<theta>_n ncloses \\<Gamma> \\<equiv> \\<forall>x B. ((x,B) \\<in> set \\<Gamma> \\<longrightarrow> (\\<exists>c P. \\<theta>_n nmaps x to Some (c,P) \\<and> <c>:P \\<in> (\\<parallel><B>\\<parallel>)))\"\n  \ndefinition \n  ccloses :: \"(coname\\<times>name\\<times>trm) list\\<Rightarrow>(coname\\<times>ty) list \\<Rightarrow> bool\" (\"_ ccloses _\" [55,55] 55) \nwhere\n  \"\\<theta>_c ccloses \\<Delta> \\<equiv> \\<forall>a B. ((a,B) \\<in> set \\<Delta> \\<longrightarrow> (\\<exists>x P. \\<theta>_c cmaps a to Some (x,P) \\<and> (x):P \\<in> (\\<parallel>(B)\\<parallel>)))\"\n\nlemma ncloses_elim:\n  assumes a: \"(x,B) \\<in> set \\<Gamma>\"\n  and     b: \"\\<theta>_n ncloses \\<Gamma>\"\n  shows \"\\<exists>c P. \\<theta>_n nmaps x to Some (c,P) \\<and> <c>:P \\<in> (\\<parallel><B>\\<parallel>)\"\nusing a b by (auto simp add: ncloses_def)\n\nlemma ccloses_elim:\n  assumes a: \"(a,B) \\<in> set \\<Delta>\"\n  and     b: \"\\<theta>_c ccloses \\<Delta>\"\n  shows \"\\<exists>x P. \\<theta>_c cmaps a to Some (x,P) \\<and> (x):P \\<in> (\\<parallel>(B)\\<parallel>)\"\nusing a b by (auto simp add: ccloses_def)\n\nlemma ncloses_subset:\n  assumes a: \"\\<theta>_n ncloses \\<Gamma>\"\n  and     b: \"set \\<Gamma>' \\<subseteq> set \\<Gamma>\"\n  shows \"\\<theta>_n ncloses \\<Gamma>'\"\nusing a b by (auto  simp add: ncloses_def)\n\nlemma ccloses_subset:\n  assumes a: \"\\<theta>_c ccloses \\<Delta>\"\n  and     b: \"set \\<Delta>' \\<subseteq> set \\<Delta>\"\n  shows \"\\<theta>_c ccloses \\<Delta>'\"\nusing a b by (auto  simp add: ccloses_def)\n\nlemma validc_fresh:\n  fixes a::\"coname\"\n  and   \\<Delta>::\"(coname\\<times>ty) list\"\n  assumes a: \"a\\<sharp>\\<Delta>\"\n  shows \"\\<not>(\\<exists>B. (a,B)\\<in>set \\<Delta>)\"\nusing a\napply(induct \\<Delta>)\napply(auto simp add: fresh_list_cons fresh_prod fresh_atm)\ndone\n\nlemma validn_fresh:\n  fixes x::\"name\"\n  and   \\<Gamma>::\"(name\\<times>ty) list\"\n  assumes a: \"x\\<sharp>\\<Gamma>\"\n  shows \"\\<not>(\\<exists>B. (x,B)\\<in>set \\<Gamma>)\"\nusing a\napply(induct \\<Gamma>)\napply(auto simp add: fresh_list_cons fresh_prod fresh_atm)\ndone\n\nlemma ccloses_extend:\n  assumes a: \"\\<theta>_c ccloses \\<Delta>\" \"a\\<sharp>\\<Delta>\" \"a\\<sharp>\\<theta>_c\" \"(x):P\\<in>\\<parallel>(B)\\<parallel>\"\n  shows \"(a,x,P)#\\<theta>_c ccloses (a,B)#\\<Delta>\"\nusing a\napply(simp add: ccloses_def)\napply(drule validc_fresh)\napply(auto)\ndone\n\nlemma ncloses_extend:\n  assumes a: \"\\<theta>_n ncloses \\<Gamma>\" \"x\\<sharp>\\<Gamma>\" \"x\\<sharp>\\<theta>_n\" \"<a>:P\\<in>\\<parallel><B>\\<parallel>\"\n  shows \"(x,a,P)#\\<theta>_n ncloses (x,B)#\\<Gamma>\"\nusing a\napply(simp add: ncloses_def)\napply(drule validn_fresh)\napply(auto)\ndone\n\n\ntext \\<open>typing relation\\<close>\n\ninductive\n   typing :: \"ctxtn \\<Rightarrow> trm \\<Rightarrow> ctxtc \\<Rightarrow> bool\" (\"_ \\<turnstile> _ \\<turnstile> _\" [100,100,100] 100)\nwhere\n  TAx:    \"\\<lbrakk>validn \\<Gamma>;validc \\<Delta>; (x,B)\\<in>set \\<Gamma>; (a,B)\\<in>set \\<Delta>\\<rbrakk> \\<Longrightarrow> \\<Gamma> \\<turnstile> Ax x a \\<turnstile> \\<Delta>\"\n| TNotR:  \"\\<lbrakk>x\\<sharp>\\<Gamma>; ((x,B)#\\<Gamma>) \\<turnstile> M \\<turnstile> \\<Delta>; set \\<Delta>' = {(a,NOT B)}\\<union>set \\<Delta>; validc \\<Delta>'\\<rbrakk> \n           \\<Longrightarrow> \\<Gamma> \\<turnstile> NotR (x).M a \\<turnstile> \\<Delta>'\"\n| TNotL:  \"\\<lbrakk>a\\<sharp>\\<Delta>; \\<Gamma> \\<turnstile> M \\<turnstile> ((a,B)#\\<Delta>); set \\<Gamma>' = {(x,NOT B)} \\<union> set \\<Gamma>; validn \\<Gamma>'\\<rbrakk>  \n           \\<Longrightarrow> \\<Gamma>' \\<turnstile> NotL <a>.M x \\<turnstile> \\<Delta>\"\n| TAndL1: \"\\<lbrakk>x\\<sharp>(\\<Gamma>,y); ((x,B1)#\\<Gamma>) \\<turnstile> M \\<turnstile> \\<Delta>; set \\<Gamma>' = {(y,B1 AND B2)} \\<union> set \\<Gamma>; validn \\<Gamma>'\\<rbrakk> \n           \\<Longrightarrow> \\<Gamma>' \\<turnstile> AndL1 (x).M y \\<turnstile> \\<Delta>\"\n| TAndL2: \"\\<lbrakk>x\\<sharp>(\\<Gamma>,y); ((x,B2)#\\<Gamma>) \\<turnstile> M \\<turnstile> \\<Delta>; set \\<Gamma>' = {(y,B1 AND B2)} \\<union> set \\<Gamma>; validn \\<Gamma>'\\<rbrakk> \n           \\<Longrightarrow> \\<Gamma>' \\<turnstile> AndL2 (x).M y \\<turnstile> \\<Delta>\"\n| TAndR:  \"\\<lbrakk>a\\<sharp>(\\<Delta>,N,c); b\\<sharp>(\\<Delta>,M,c); a\\<noteq>b; \\<Gamma> \\<turnstile> M \\<turnstile> ((a,B)#\\<Delta>); \\<Gamma> \\<turnstile> N \\<turnstile> ((b,C)#\\<Delta>); \n           set \\<Delta>' = {(c,B AND C)}\\<union>set \\<Delta>; validc \\<Delta>'\\<rbrakk> \n           \\<Longrightarrow> \\<Gamma> \\<turnstile> AndR <a>.M <b>.N c \\<turnstile> \\<Delta>'\"\n| TOrL:   \"\\<lbrakk>x\\<sharp>(\\<Gamma>,N,z); y\\<sharp>(\\<Gamma>,M,z); x\\<noteq>y; ((x,B)#\\<Gamma>) \\<turnstile> M \\<turnstile> \\<Delta>; ((y,C)#\\<Gamma>) \\<turnstile> N \\<turnstile> \\<Delta>;\n           set \\<Gamma>' = {(z,B OR C)} \\<union> set \\<Gamma>; validn \\<Gamma>'\\<rbrakk> \n           \\<Longrightarrow> \\<Gamma>' \\<turnstile> OrL (x).M (y).N z \\<turnstile> \\<Delta>\"\n| TOrR1:  \"\\<lbrakk>a\\<sharp>(\\<Delta>,b); \\<Gamma> \\<turnstile> M \\<turnstile> ((a,B1)#\\<Delta>); set \\<Delta>' = {(b,B1 OR B2)}\\<union>set \\<Delta>; validc \\<Delta>'\\<rbrakk> \n           \\<Longrightarrow> \\<Gamma> \\<turnstile> OrR1 <a>.M b \\<turnstile> \\<Delta>'\"\n| TOrR2:  \"\\<lbrakk>a\\<sharp>(\\<Delta>,b); \\<Gamma> \\<turnstile> M \\<turnstile> ((a,B2)#\\<Delta>); set \\<Delta>' = {(b,B1 OR B2)}\\<union>set \\<Delta>; validc \\<Delta>'\\<rbrakk> \n           \\<Longrightarrow> \\<Gamma> \\<turnstile> OrR2 <a>.M b \\<turnstile> \\<Delta>'\"\n| TImpL:  \"\\<lbrakk>a\\<sharp>(\\<Delta>,N); x\\<sharp>(\\<Gamma>,M,y); \\<Gamma> \\<turnstile> M \\<turnstile> ((a,B)#\\<Delta>); ((x,C)#\\<Gamma>) \\<turnstile> N \\<turnstile> \\<Delta>;\n           set \\<Gamma>' = {(y,B IMP C)} \\<union> set \\<Gamma>; validn \\<Gamma>'\\<rbrakk> \n           \\<Longrightarrow> \\<Gamma>' \\<turnstile> ImpL <a>.M (x).N y \\<turnstile> \\<Delta>\"\n| TImpR:  \"\\<lbrakk>a\\<sharp>(\\<Delta>,b); x\\<sharp>\\<Gamma>; ((x,B)#\\<Gamma>) \\<turnstile> M \\<turnstile> ((a,C)#\\<Delta>); set \\<Delta>' = {(b,B IMP C)}\\<union>set \\<Delta>; validc \\<Delta>'\\<rbrakk> \n           \\<Longrightarrow> \\<Gamma> \\<turnstile> ImpR (x).<a>.M b \\<turnstile> \\<Delta>'\"\n| TCut:   \"\\<lbrakk>a\\<sharp>(\\<Delta>,N); x\\<sharp>(\\<Gamma>,M); \\<Gamma> \\<turnstile> M \\<turnstile> ((a,B)#\\<Delta>); ((x,B)#\\<Gamma>) \\<turnstile> N \\<turnstile> \\<Delta>\\<rbrakk> \n           \\<Longrightarrow> \\<Gamma> \\<turnstile> Cut <a>.M (x).N \\<turnstile> \\<Delta>\"\n\nequivariance typing\n\nlemma fresh_set_member:\n  fixes x::\"name\"\n  and   a::\"coname\"\n  shows \"x\\<sharp>L \\<Longrightarrow> e\\<in>set L \\<Longrightarrow> x\\<sharp>e\"\n  and   \"a\\<sharp>L \\<Longrightarrow> e\\<in>set L \\<Longrightarrow> a\\<sharp>e\"   \nby (induct L) (auto simp add: fresh_list_cons) \n\nlemma fresh_subset:\n  fixes x::\"name\"\n  and   a::\"coname\"\n  shows \"x\\<sharp>L \\<Longrightarrow> set L' \\<subseteq> set L \\<Longrightarrow> x\\<sharp>L'\"\n  and   \"a\\<sharp>L \\<Longrightarrow> set L' \\<subseteq> set L \\<Longrightarrow> a\\<sharp>L'\"   \napply(induct L' arbitrary: L) \napply(auto simp add: fresh_list_cons fresh_list_nil intro: fresh_set_member)\ndone\n\nlemma fresh_subset_ext:\n  fixes x::\"name\"\n  and   a::\"coname\"\n  shows \"x\\<sharp>L \\<Longrightarrow> x\\<sharp>e \\<Longrightarrow> set L' \\<subseteq> set (e#L) \\<Longrightarrow> x\\<sharp>L'\"\n  and   \"a\\<sharp>L \\<Longrightarrow> a\\<sharp>e \\<Longrightarrow> set L' \\<subseteq> set (e#L) \\<Longrightarrow> a\\<sharp>L'\"   \napply(induct L' arbitrary: L) \napply(auto simp add: fresh_list_cons fresh_list_nil intro: fresh_set_member)\ndone\n\nlemma fresh_under_insert:\n  fixes x::\"name\"\n  and   a::\"coname\"\n  and   \\<Gamma>::\"ctxtn\"\n  and   \\<Delta>::\"ctxtc\"\n  shows \"x\\<sharp>\\<Gamma> \\<Longrightarrow> x\\<noteq>y \\<Longrightarrow> set \\<Gamma>' = insert (y,B) (set \\<Gamma>) \\<Longrightarrow> x\\<sharp>\\<Gamma>'\"\n  and   \"a\\<sharp>\\<Delta> \\<Longrightarrow> a\\<noteq>c \\<Longrightarrow> set \\<Delta>' = insert (c,B) (set \\<Delta>) \\<Longrightarrow> a\\<sharp>\\<Delta>'\"   \napply(rule fresh_subset_ext(1))\napply(auto simp add: fresh_prod fresh_atm fresh_ty)\napply(rule fresh_subset_ext(2))\napply(auto simp add: fresh_prod fresh_atm fresh_ty)\ndone\n\nnominal_inductive typing\n  apply (simp_all add: abs_fresh fresh_atm fresh_list_cons fresh_prod fresh_ty fresh_ctxt \n                       fresh_list_append abs_supp fin_supp)\n  apply(auto intro: fresh_under_insert)\n  done\n\nlemma validn_elim:\n  assumes a: \"validn ((x,B)#\\<Gamma>)\"\n  shows \"validn \\<Gamma> \\<and> x\\<sharp>\\<Gamma>\"\nusing a\napply(erule_tac validn.cases)\napply(auto)\ndone\n\nlemma validc_elim:\n  assumes a: \"validc ((a,B)#\\<Delta>)\"\n  shows \"validc \\<Delta> \\<and> a\\<sharp>\\<Delta>\"\nusing a\napply(erule_tac validc.cases)\napply(auto)\ndone\n\nlemma context_fresh:\n  fixes x::\"name\"\n  and   a::\"coname\"\n  shows \"x\\<sharp>\\<Gamma> \\<Longrightarrow> \\<not>(\\<exists>B. (x,B)\\<in>set \\<Gamma>)\"\n  and   \"a\\<sharp>\\<Delta> \\<Longrightarrow> \\<not>(\\<exists>B. (a,B)\\<in>set \\<Delta>)\"\napply -\napply(induct \\<Gamma>)\napply(auto simp add: fresh_list_cons fresh_prod fresh_atm)\napply(induct \\<Delta>)\napply(auto simp add: fresh_list_cons fresh_prod fresh_atm)\ndone\n\nlemma typing_implies_valid:\n  assumes a: \"\\<Gamma> \\<turnstile> M \\<turnstile> \\<Delta>\"\n  shows \"validn \\<Gamma> \\<and> validc \\<Delta>\"\nusing a\napply(nominal_induct rule: typing.strong_induct)\napply(auto dest: validn_elim validc_elim)\ndone\n\nlemma ty_perm:\n  fixes pi1::\"name prm\"\n  and   pi2::\"coname prm\"\n  and   B::\"ty\"\n  shows \"pi1\\<bullet>B=B\" and \"pi2\\<bullet>B=B\"\napply(nominal_induct B rule: ty.strong_induct)\napply(auto simp add: perm_string)\ndone\n\nlemma ctxt_perm:\n  fixes pi1::\"name prm\"\n  and   pi2::\"coname prm\"\n  and   \\<Gamma>::\"ctxtn\"\n  and   \\<Delta>::\"ctxtc\"\n  shows \"pi2\\<bullet>\\<Gamma>=\\<Gamma>\" and \"pi1\\<bullet>\\<Delta>=\\<Delta>\"\napply -\napply(induct \\<Gamma>)\napply(auto simp add: calc_atm ty_perm)\napply(induct \\<Delta>)\napply(auto simp add: calc_atm ty_perm)\ndone\n\nlemma typing_Ax_elim1: \n  assumes a: \"\\<Gamma> \\<turnstile> Ax x a \\<turnstile> ((a,B)#\\<Delta>)\"\n  shows \"(x,B)\\<in>set \\<Gamma>\"\nusing a\napply(erule_tac typing.cases)\napply(simp_all add: trm.inject)\napply(auto)\napply(auto dest: validc_elim context_fresh)\ndone\n\nlemma typing_Ax_elim2: \n  assumes a: \"((x,B)#\\<Gamma>) \\<turnstile> Ax x a \\<turnstile> \\<Delta>\"\n  shows \"(a,B)\\<in>set \\<Delta>\"\nusing a\napply(erule_tac typing.cases)\napply(simp_all add: trm.inject)\napply(auto  dest!: validn_elim context_fresh)\ndone\n\nlemma psubst_Ax_aux: \n  assumes a: \"\\<theta>_c cmaps a to Some (y,N)\"\n  shows \"lookupb x a \\<theta>_c c P = Cut <c>.P (y).N\"\nusing a\napply(induct \\<theta>_c)\napply(auto)\ndone\n\nlemma psubst_Ax:\n  assumes a: \"\\<theta>_n nmaps x to Some (c,P)\"\n  and     b: \"\\<theta>_c cmaps a to Some (y,N)\"\n  shows \"\\<theta>_n,\\<theta>_c<Ax x a> = Cut <c>.P (y).N\"\nusing a b\napply(induct \\<theta>_n)\napply(auto simp add: psubst_Ax_aux)\ndone\n\nlemma psubst_Cut:\n  assumes a: \"\\<forall>x. M\\<noteq>Ax x c\"\n  and     b: \"\\<forall>a. N\\<noteq>Ax x a\"\n  and     c: \"c\\<sharp>(\\<theta>_n,\\<theta>_c,N)\" \"x\\<sharp>(\\<theta>_n,\\<theta>_c,M)\"\n  shows \"\\<theta>_n,\\<theta>_c<Cut <c>.M (x).N> = Cut <c>.(\\<theta>_n,\\<theta>_c<M>) (x).(\\<theta>_n,\\<theta>_c<N>)\"\nusing a b c\napply(simp)\ndone\n\nlemma all_CAND: \n  assumes a: \"\\<Gamma> \\<turnstile> M \\<turnstile> \\<Delta>\"\n  and     b: \"\\<theta>_n ncloses \\<Gamma>\"\n  and     c: \"\\<theta>_c ccloses \\<Delta>\"\n  shows \"SNa (\\<theta>_n,\\<theta>_c<M>)\"\nusing a b c\nproof(nominal_induct avoiding: \\<theta>_n \\<theta>_c rule: typing.strong_induct)\n  case (TAx \\<Gamma> \\<Delta> x B a \\<theta>_n \\<theta>_c)\n  then show ?case\n    apply -\n    apply(drule ncloses_elim)\n    apply(assumption)\n    apply(drule ccloses_elim)\n    apply(assumption)\n    apply(erule exE)+\n    apply(erule conjE)+\n    apply(rule_tac s=\"Cut <c>.P (xa).Pa\" and t=\"\\<theta>_n,\\<theta>_c<Ax x a>\" in subst)\n    apply(rule sym)\n    apply(simp only: psubst_Ax)\n    apply(simp add: CUT_SNa)\n    done\nnext\n  case (TNotR x \\<Gamma> B M \\<Delta> \\<Delta>' a \\<theta>_n \\<theta>_c) \n  then show ?case \n    apply(simp)\n    apply(subgoal_tac \"(a,NOT B) \\<in> set \\<Delta>'\")\n    apply(drule ccloses_elim)\n    apply(assumption)\n    apply(erule exE)+\n    apply(simp)\n    apply(generate_fresh \"coname\")\n    apply(fresh_fun_simp)\n    apply(rule_tac B=\"NOT B\" in CUT_SNa)\n    apply(simp)\n    apply(rule disjI2)\n    apply(rule disjI2)\n    apply(rule_tac x=\"c\" in exI)\n    apply(rule_tac x=\"x\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(simp)\n    apply(rule conjI)\n    apply(rule fic.intros)\n    apply(rule psubst_fresh_coname)\n    apply(simp)\n    apply(simp)\n    apply(simp)\n    apply(rule BINDING_implies_CAND)\n    apply(unfold BINDINGn_def)\n    apply(simp)\n    apply(rule_tac x=\"x\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(simp)\n    apply(rule allI)+\n    apply(rule impI)\n    apply(simp add: psubst_nsubst[symmetric])\n    apply(drule_tac x=\"(x,aa,Pa)#\\<theta>_n\" in meta_spec)\n    apply(drule_tac x=\"\\<theta>_c\" in meta_spec)\n    apply(drule meta_mp)\n    apply(rule ncloses_extend)\n    apply(assumption)\n    apply(assumption)\n    apply(assumption)\n    apply(assumption)\n    apply(drule meta_mp)\n    apply(rule ccloses_subset)\n    apply(assumption)\n    apply(blast)\n    apply(assumption)\n    apply(simp)\n    apply(blast)\n    done\nnext\n  case (TNotL a \\<Delta> \\<Gamma> M B \\<Gamma>' x \\<theta>_n \\<theta>_c)\n  then show ?case\n    apply(simp)\n    apply(subgoal_tac \"(x,NOT B) \\<in> set \\<Gamma>'\")\n    apply(drule ncloses_elim)\n    apply(assumption)\n    apply(erule exE)+\n    apply(simp del: NEGc.simps)\n    apply(generate_fresh \"name\")\n    apply(fresh_fun_simp)\n    apply(rule_tac B=\"NOT B\" in CUT_SNa)\n    apply(simp)\n    apply(rule NEG_intro)\n    apply(simp (no_asm))\n    apply(rule disjI2)\n    apply(rule disjI2)\n    apply(rule_tac x=\"a\" in exI)\n    apply(rule_tac x=\"ca\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(simp del: NEGc.simps)\n    apply(rule conjI)\n    apply(rule fin.intros)\n    apply(rule psubst_fresh_name)\n    apply(simp)\n    apply(simp)\n    apply(simp)\n    apply(rule BINDING_implies_CAND)\n    apply(unfold BINDINGc_def)\n    apply(simp (no_asm))\n    apply(rule_tac x=\"a\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(simp (no_asm))\n    apply(rule allI)+\n    apply(rule impI)\n    apply(simp del: NEGc.simps add: psubst_csubst[symmetric])\n    apply(drule_tac x=\"\\<theta>_n\" in meta_spec)\n    apply(drule_tac x=\"(a,xa,Pa)#\\<theta>_c\" in meta_spec)\n    apply(drule meta_mp)\n    apply(rule ncloses_subset)\n    apply(assumption)\n    apply(blast)\n    apply(drule meta_mp)\n    apply(rule ccloses_extend)\n    apply(assumption)\n    apply(assumption)\n    apply(assumption)\n    apply(assumption)\n    apply(assumption)\n    apply(blast)\n    done\nnext\n  case (TAndL1 x \\<Gamma> y B1 M \\<Delta> \\<Gamma>' B2 \\<theta>_n \\<theta>_c)\n  then show ?case     \n    apply(simp)\n    apply(subgoal_tac \"(y,B1 AND B2) \\<in> set \\<Gamma>'\")\n    apply(drule ncloses_elim)\n    apply(assumption)\n    apply(erule exE)+ \n    apply(simp del: NEGc.simps)\n    apply(generate_fresh \"name\")\n    apply(fresh_fun_simp)\n    apply(rule_tac B=\"B1 AND B2\" in CUT_SNa)\n    apply(simp)\n    apply(rule NEG_intro)\n    apply(simp (no_asm))\n    apply(rule disjI2)\n    apply(rule disjI2)\n    apply(rule disjI1)\n    apply(rule_tac x=\"x\" in exI)\n    apply(rule_tac x=\"ca\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(simp del: NEGc.simps)\n    apply(rule conjI)\n    apply(rule fin.intros)\n    apply(simp del: NEGc.simps add: abs_fresh fresh_prod fresh_atm)\n    apply(rule psubst_fresh_name)\n    apply(simp)\n    apply(simp)\n    apply(simp)\n    apply(rule BINDING_implies_CAND)\n    apply(unfold BINDINGn_def)\n    apply(simp (no_asm))\n    apply(rule_tac x=\"x\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(simp (no_asm))\n    apply(rule allI)+\n    apply(rule impI)\n    apply(simp del: NEGc.simps add: psubst_nsubst[symmetric])\n    apply(drule_tac x=\"(x,a,Pa)#\\<theta>_n\" in meta_spec)\n    apply(drule_tac x=\"\\<theta>_c\" in meta_spec)\n    apply(drule meta_mp)\n    apply(rule ncloses_extend)\n    apply(rule ncloses_subset)\n    apply(assumption)\n    apply(blast)\n    apply(simp)\n    apply(simp)\n    apply(simp)\n    apply(drule meta_mp)\n    apply(assumption)\n    apply(assumption)\n    apply(blast)\n    done\nnext\n  case (TAndL2 x \\<Gamma> y B2 M \\<Delta> \\<Gamma>' B1 \\<theta>_n \\<theta>_c)\n  then show ?case \n    apply(simp)\n    apply(subgoal_tac \"(y,B1 AND B2) \\<in> set \\<Gamma>'\")\n    apply(drule ncloses_elim)\n    apply(assumption)\n    apply(erule exE)+ \n    apply(simp del: NEGc.simps)\n    apply(generate_fresh \"name\")\n    apply(fresh_fun_simp)\n    apply(rule_tac B=\"B1 AND B2\" in CUT_SNa)\n    apply(simp)\n    apply(rule NEG_intro)\n    apply(simp (no_asm))\n    apply(rule disjI2)\n    apply(rule disjI2)\n    apply(rule disjI2)\n    apply(rule_tac x=\"x\" in exI)\n    apply(rule_tac x=\"ca\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(simp del: NEGc.simps)\n    apply(rule conjI)\n    apply(rule fin.intros)\n    apply(simp del: NEGc.simps add: abs_fresh fresh_prod fresh_atm)\n    apply(rule psubst_fresh_name)\n    apply(simp)\n    apply(simp)\n    apply(simp)\n    apply(rule BINDING_implies_CAND)\n    apply(unfold BINDINGn_def)\n    apply(simp (no_asm))\n    apply(rule_tac x=\"x\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(simp (no_asm))\n    apply(rule allI)+\n    apply(rule impI)\n    apply(simp del: NEGc.simps add: psubst_nsubst[symmetric])\n    apply(drule_tac x=\"(x,a,Pa)#\\<theta>_n\" in meta_spec)\n    apply(drule_tac x=\"\\<theta>_c\" in meta_spec)\n    apply(drule meta_mp)\n    apply(rule ncloses_extend)\n    apply(rule ncloses_subset)\n    apply(assumption)\n    apply(blast)\n    apply(simp)\n    apply(simp)\n    apply(simp)\n    apply(drule meta_mp)\n    apply(assumption)\n    apply(assumption)\n    apply(blast)\n    done\nnext\n  case (TAndR a \\<Delta> N c b M \\<Gamma> B C \\<Delta>' \\<theta>_n \\<theta>_c)\n  then show ?case \n    apply(simp)\n    apply(subgoal_tac \"(c,B AND C) \\<in> set \\<Delta>'\")\n    apply(drule ccloses_elim)\n    apply(assumption)\n    apply(erule exE)+\n    apply(simp)\n    apply(generate_fresh \"coname\")\n    apply(fresh_fun_simp)\n    apply(rule_tac B=\"B AND C\" in CUT_SNa)\n    apply(simp)\n    apply(rule disjI2)\n    apply(rule disjI2)\n    apply(rule_tac x=\"ca\" in exI)\n    apply(rule_tac x=\"a\" in exI)\n    apply(rule_tac x=\"b\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<N>\" in exI)\n    apply(simp)\n    apply(rule conjI)\n    apply(rule fic.intros)\n    apply(simp add: abs_fresh fresh_prod fresh_atm)\n    apply(rule psubst_fresh_coname)\n    apply(simp)\n    apply(simp)\n    apply(simp)\n    apply(simp add: abs_fresh fresh_prod fresh_atm)\n    apply(rule psubst_fresh_coname)\n    apply(simp)\n    apply(simp)\n    apply(simp)\n    apply(rule conjI)\n    apply(rule BINDING_implies_CAND)\n    apply(unfold BINDINGc_def)\n    apply(simp)\n    apply(rule_tac x=\"a\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(simp)\n    apply(rule allI)+\n    apply(rule impI)\n    apply(simp add: psubst_csubst[symmetric])\n    apply(drule_tac x=\"\\<theta>_n\" in meta_spec)\n    apply(drule_tac x=\"(a,xa,Pa)#\\<theta>_c\" in meta_spec)\n    apply(drule meta_mp)\n    apply(assumption)\n    apply(drule meta_mp)\n    apply(rule ccloses_extend)\n    apply(rule ccloses_subset)\n    apply(assumption)\n    apply(blast)\n    apply(simp)\n    apply(simp)\n    apply(assumption)\n    apply(assumption)\n    apply(rule BINDING_implies_CAND)\n    apply(unfold BINDINGc_def)\n    apply(simp)\n    apply(rule_tac x=\"b\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<N>\" in exI)\n    apply(simp)\n    apply(rule allI)+\n    apply(rule impI)\n    apply(simp add: psubst_csubst[symmetric])\n    apply(rotate_tac 14)\n    apply(drule_tac x=\"\\<theta>_n\" in meta_spec)\n    apply(drule_tac x=\"(b,xa,Pa)#\\<theta>_c\" in meta_spec)\n    apply(drule meta_mp)\n    apply(assumption)\n    apply(drule meta_mp)\n    apply(rule ccloses_extend)\n    apply(rule ccloses_subset)\n    apply(assumption)\n    apply(blast)\n    apply(simp)\n    apply(simp)\n    apply(assumption)\n    apply(assumption)\n    apply(simp)\n    apply(blast)\n    done\nnext\n  case (TOrL x \\<Gamma> N z y M B \\<Delta> C \\<Gamma>' \\<theta>_n \\<theta>_c)\n  then show ?case \n    apply(simp)\n    apply(subgoal_tac \"(z,B OR C) \\<in> set \\<Gamma>'\")\n    apply(drule ncloses_elim)\n    apply(assumption)\n    apply(erule exE)+\n    apply(simp del: NEGc.simps)\n    apply(generate_fresh \"name\")\n    apply(fresh_fun_simp)\n    apply(rule_tac B=\"B OR C\" in CUT_SNa)\n    apply(simp)\n    apply(rule NEG_intro)\n    apply(simp (no_asm))\n    apply(rule disjI2)\n    apply(rule disjI2)\n    apply(rule_tac x=\"x\" in exI)\n    apply(rule_tac x=\"y\" in exI)\n    apply(rule_tac x=\"ca\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<N>\" in exI)\n    apply(simp del: NEGc.simps)\n    apply(rule conjI)\n    apply(rule fin.intros)\n    apply(simp del: NEGc.simps add: abs_fresh fresh_prod fresh_atm)\n    apply(rule psubst_fresh_name)\n    apply(simp)\n    apply(simp)\n    apply(simp)\n    apply(simp del: NEGc.simps add: abs_fresh fresh_prod fresh_atm)\n    apply(rule psubst_fresh_name)\n    apply(simp)\n    apply(simp)\n    apply(simp)\n    apply(rule conjI)\n    apply(rule BINDING_implies_CAND)\n    apply(unfold BINDINGn_def)\n    apply(simp del: NEGc.simps)\n    apply(rule_tac x=\"x\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(simp del: NEGc.simps)\n    apply(rule allI)+\n    apply(rule impI)\n    apply(simp del: NEGc.simps add: psubst_nsubst[symmetric])\n    apply(drule_tac x=\"(x,a,Pa)#\\<theta>_n\" in meta_spec)\n    apply(drule_tac x=\"\\<theta>_c\" in meta_spec)\n    apply(drule meta_mp)\n    apply(rule ncloses_extend)\n    apply(rule ncloses_subset)\n    apply(assumption)\n    apply(blast)\n    apply(simp)\n    apply(simp)\n    apply(assumption)\n    apply(drule meta_mp)\n    apply(assumption)\n    apply(assumption)\n    apply(rule BINDING_implies_CAND)\n    apply(unfold BINDINGn_def)\n    apply(simp del: NEGc.simps)\n    apply(rule_tac x=\"y\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<N>\" in exI)\n    apply(simp del: NEGc.simps)\n    apply(rule allI)+\n    apply(rule impI)\n    apply(simp del: NEGc.simps add: psubst_nsubst[symmetric])\n    apply(rotate_tac 14)\n    apply(drule_tac x=\"(y,a,Pa)#\\<theta>_n\" in meta_spec)\n    apply(drule_tac x=\"\\<theta>_c\" in meta_spec)\n    apply(drule meta_mp)\n    apply(rule ncloses_extend)\n    apply(rule ncloses_subset)\n    apply(assumption)\n    apply(blast)\n    apply(simp)\n    apply(simp)\n    apply(assumption)\n    apply(drule meta_mp)\n    apply(assumption)\n    apply(assumption)\n    apply(blast)\n    done\nnext\n  case (TOrR1 a \\<Delta> b \\<Gamma> M B1 \\<Delta>' B2 \\<theta>_n \\<theta>_c)\n  then show ?case\n    apply(simp)\n    apply(subgoal_tac \"(b,B1 OR B2) \\<in> set \\<Delta>'\")\n    apply(drule ccloses_elim)\n    apply(assumption)\n    apply(erule exE)+ \n    apply(simp del: NEGc.simps)\n    apply(generate_fresh \"coname\")\n    apply(fresh_fun_simp)\n    apply(rule_tac B=\"B1 OR B2\" in CUT_SNa)\n    apply(simp)\n    apply(rule disjI2)\n    apply(rule disjI2)\n    apply(rule disjI1)\n    apply(rule_tac x=\"a\" in exI)\n    apply(rule_tac x=\"c\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(simp)\n    apply(rule conjI)\n    apply(rule fic.intros)\n    apply(simp del: NEGc.simps add: abs_fresh fresh_prod fresh_atm)\n    apply(rule psubst_fresh_coname)\n    apply(simp)\n    apply(simp)\n    apply(simp)\n    apply(rule BINDING_implies_CAND)\n    apply(unfold BINDINGc_def)\n    apply(simp (no_asm))\n    apply(rule_tac x=\"a\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(simp (no_asm))\n    apply(rule allI)+\n    apply(rule impI)    \n    apply(simp del: NEGc.simps add: psubst_csubst[symmetric])\n    apply(drule_tac x=\"\\<theta>_n\" in meta_spec)\n    apply(drule_tac x=\"(a,xa,Pa)#\\<theta>_c\" in meta_spec)\n    apply(drule meta_mp)\n    apply(assumption)\n    apply(drule meta_mp)\n    apply(rule ccloses_extend)\n    apply(rule ccloses_subset)\n    apply(assumption)\n    apply(blast)\n    apply(simp)\n    apply(simp)\n    apply(simp)\n    apply(assumption)\n    apply(simp)\n    apply(blast)\n    done\nnext\n  case (TOrR2 a \\<Delta> b \\<Gamma> M B2 \\<Delta>' B1 \\<theta>_n \\<theta>_c)\n  then show ?case \n    apply(simp)\n    apply(subgoal_tac \"(b,B1 OR B2) \\<in> set \\<Delta>'\")\n    apply(drule ccloses_elim)\n    apply(assumption)\n    apply(erule exE)+ \n    apply(simp del: NEGc.simps)\n    apply(generate_fresh \"coname\")\n    apply(fresh_fun_simp)\n    apply(rule_tac B=\"B1 OR B2\" in CUT_SNa)\n    apply(simp)\n    apply(rule disjI2)\n    apply(rule disjI2)\n    apply(rule disjI2)\n    apply(rule_tac x=\"a\" in exI)\n    apply(rule_tac x=\"c\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(simp)\n    apply(rule conjI)\n    apply(rule fic.intros)\n    apply(simp del: NEGc.simps add: abs_fresh fresh_prod fresh_atm)\n    apply(rule psubst_fresh_coname)\n    apply(simp)\n    apply(simp)\n    apply(simp)\n    apply(rule BINDING_implies_CAND)\n    apply(unfold BINDINGc_def)\n    apply(simp (no_asm))\n    apply(rule_tac x=\"a\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(simp (no_asm))\n    apply(rule allI)+\n    apply(rule impI)    \n    apply(simp del: NEGc.simps add: psubst_csubst[symmetric])\n    apply(drule_tac x=\"\\<theta>_n\" in meta_spec)\n    apply(drule_tac x=\"(a,xa,Pa)#\\<theta>_c\" in meta_spec)\n    apply(drule meta_mp)\n    apply(assumption)\n    apply(drule meta_mp)\n    apply(rule ccloses_extend)\n    apply(rule ccloses_subset)\n    apply(assumption)\n    apply(blast)\n    apply(simp)\n    apply(simp)\n    apply(simp)\n    apply(assumption)\n    apply(simp)\n    apply(blast)\n    done\nnext\n  case (TImpL a \\<Delta> N x \\<Gamma> M y B C \\<Gamma>' \\<theta>_n \\<theta>_c)\n  then show ?case\n    apply(simp)\n    apply(subgoal_tac \"(y,B IMP C) \\<in> set \\<Gamma>'\")\n    apply(drule ncloses_elim)\n    apply(assumption)\n    apply(erule exE)+\n    apply(simp del: NEGc.simps)\n    apply(generate_fresh \"name\")\n    apply(fresh_fun_simp)\n    apply(rule_tac B=\"B IMP C\" in CUT_SNa)\n    apply(simp)\n    apply(rule NEG_intro)\n    apply(simp (no_asm))\n    apply(rule disjI2)\n    apply(rule disjI2)\n    apply(rule_tac x=\"x\" in exI)\n    apply(rule_tac x=\"a\" in exI)\n    apply(rule_tac x=\"ca\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<N>\" in exI)\n    apply(simp del: NEGc.simps)\n    apply(rule conjI)\n    apply(rule fin.intros)\n    apply(rule psubst_fresh_name)\n    apply(simp)\n    apply(simp)\n    apply(simp)\n    apply(simp del: NEGc.simps add: abs_fresh fresh_prod fresh_atm)\n    apply(rule psubst_fresh_name)\n    apply(simp)\n    apply(simp)\n    apply(simp)\n    apply(rule conjI)\n    apply(rule BINDING_implies_CAND)\n    apply(unfold BINDINGc_def)\n    apply(simp del: NEGc.simps)\n    apply(rule_tac x=\"a\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(simp del: NEGc.simps)\n    apply(rule allI)+\n    apply(rule impI)\n    apply(simp del: NEGc.simps add: psubst_csubst[symmetric])\n    apply(drule_tac x=\"\\<theta>_n\" in meta_spec)\n    apply(drule_tac x=\"(a,xa,Pa)#\\<theta>_c\" in meta_spec)\n    apply(drule meta_mp)\n    apply(rule ncloses_subset)\n    apply(assumption)\n    apply(blast)\n    apply(drule meta_mp)\n    apply(rule ccloses_extend)\n    apply(assumption)\n    apply(simp)\n    apply(simp)\n    apply(assumption)\n    apply(assumption)\n    apply(rule BINDING_implies_CAND)\n    apply(unfold BINDINGn_def)\n    apply(simp del: NEGc.simps)\n    apply(rule_tac x=\"x\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<N>\" in exI)\n    apply(simp del: NEGc.simps)\n    apply(rule allI)+\n    apply(rule impI)\n    apply(simp del: NEGc.simps add: psubst_nsubst[symmetric])\n    apply(rotate_tac 12)\n    apply(drule_tac x=\"(x,aa,Pa)#\\<theta>_n\" in meta_spec)\n    apply(drule_tac x=\"\\<theta>_c\" in meta_spec)\n    apply(drule meta_mp)\n    apply(rule ncloses_extend)\n    apply(rule ncloses_subset)\n    apply(assumption)\n    apply(blast)\n    apply(simp)\n    apply(simp)\n    apply(assumption)\n    apply(drule meta_mp)\n    apply(assumption)\n    apply(assumption)\n    apply(blast)\n    done\nnext\n  case (TImpR a \\<Delta> b x \\<Gamma> B M C \\<Delta>' \\<theta>_n \\<theta>_c)\n  then show ?case\n    apply(simp)\n    apply(subgoal_tac \"(b,B IMP C) \\<in> set \\<Delta>'\")\n    apply(drule ccloses_elim)\n    apply(assumption)\n    apply(erule exE)+\n    apply(simp)\n    apply(generate_fresh \"coname\")\n    apply(fresh_fun_simp)\n    apply(rule_tac B=\"B IMP C\" in CUT_SNa)\n    apply(simp)\n    apply(rule disjI2)\n    apply(rule disjI2)\n    apply(rule_tac x=\"x\" in exI)\n    apply(rule_tac x=\"a\" in exI)\n    apply(rule_tac x=\"c\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(simp)\n    apply(rule conjI)\n    apply(rule fic.intros)\n    apply(simp add: abs_fresh fresh_prod fresh_atm)\n    apply(rule psubst_fresh_coname)\n    apply(simp)\n    apply(simp)\n    apply(simp)\n    apply(rule conjI)\n    apply(rule allI)+\n    apply(rule impI)\n    apply(simp add: psubst_csubst[symmetric])\n    apply(rule BINDING_implies_CAND)\n    apply(unfold BINDINGn_def)\n    apply(simp)\n    apply(rule_tac x=\"x\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,((a,z,Pa)#\\<theta>_c)<M>\" in exI)\n    apply(simp)\n    apply(rule allI)+\n    apply(rule impI)\n    apply(rule_tac t=\"\\<theta>_n,((a,z,Pa)#\\<theta>_c)<M>{x:=<aa>.Pb}\" and \n                   s=\"((x,aa,Pb)#\\<theta>_n),((a,z,Pa)#\\<theta>_c)<M>\" in subst)\n    apply(rule psubst_nsubst)\n    apply(simp add: fresh_prod fresh_atm fresh_list_cons)\n    apply(drule_tac x=\"(x,aa,Pb)#\\<theta>_n\" in meta_spec)\n    apply(drule_tac x=\"(a,z,Pa)#\\<theta>_c\" in meta_spec)\n    apply(drule meta_mp)\n    apply(rule ncloses_extend)\n    apply(assumption)\n    apply(simp)\n    apply(simp)\n    apply(simp)\n    apply(drule meta_mp)\n    apply(rule ccloses_extend)\n    apply(rule ccloses_subset)\n    apply(assumption)\n    apply(blast)\n    apply(auto intro: fresh_subset simp del: NEGc.simps)[1]\n    apply(simp)\n    apply(simp)\n    apply(assumption)\n    apply(rule allI)+\n    apply(rule impI)\n    apply(simp add: psubst_nsubst[symmetric])\n    apply(rule BINDING_implies_CAND)\n    apply(unfold BINDINGc_def)\n    apply(simp)\n    apply(rule_tac x=\"a\" in exI)\n    apply(rule_tac x=\"((x,ca,Q)#\\<theta>_n),\\<theta>_c<M>\" in exI)\n    apply(simp)\n    apply(rule allI)+\n    apply(rule impI)\n    apply(rule_tac t=\"((x,ca,Q)#\\<theta>_n),\\<theta>_c<M>{a:=(xaa).Pa}\" and \n                   s=\"((x,ca,Q)#\\<theta>_n),((a,xaa,Pa)#\\<theta>_c)<M>\" in subst)\n    apply(rule psubst_csubst)\n    apply(simp add: fresh_prod fresh_atm fresh_list_cons)\n    apply(drule_tac x=\"(x,ca,Q)#\\<theta>_n\" in meta_spec)\n    apply(drule_tac x=\"(a,xaa,Pa)#\\<theta>_c\" in meta_spec)\n    apply(drule meta_mp)\n    apply(rule ncloses_extend)\n    apply(assumption)\n    apply(simp)\n    apply(simp)\n    apply(simp)\n    apply(drule meta_mp)\n    apply(rule ccloses_extend)\n    apply(rule ccloses_subset)\n    apply(assumption)\n    apply(blast)\n    apply(auto intro: fresh_subset simp del: NEGc.simps)[1]\n    apply(simp)\n    apply(simp)\n    apply(assumption)\n    apply(simp)\n    apply(blast)\n    done\nnext\n  case (TCut a \\<Delta> N x \\<Gamma> M B \\<theta>_n \\<theta>_c)\n  then show ?case \n    apply -\n    apply(case_tac \"\\<forall>y. M\\<noteq>Ax y a\")\n    apply(case_tac \"\\<forall>c. N\\<noteq>Ax x c\")\n    apply(simp)\n    apply(rule_tac B=\"B\" in CUT_SNa)\n    apply(rule BINDING_implies_CAND)\n    apply(unfold BINDINGc_def)\n    apply(simp)\n    apply(rule_tac x=\"a\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(simp)\n    apply(rule allI)\n    apply(rule allI)\n    apply(rule impI)\n    apply(simp add: psubst_csubst[symmetric]) (*?*)\n    apply(drule_tac x=\"\\<theta>_n\" in meta_spec)\n    apply(drule_tac x=\"(a,xa,P)#\\<theta>_c\" in meta_spec)\n    apply(drule meta_mp)\n    apply(assumption)\n    apply(drule meta_mp)\n    apply(rule ccloses_extend) \n    apply(assumption)\n    apply(assumption)\n    apply(assumption)\n    apply(assumption)\n    apply(assumption)\n    apply(rule BINDING_implies_CAND)\n    apply(unfold BINDINGn_def)\n    apply(simp)\n    apply(rule_tac x=\"x\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<N>\" in exI)\n    apply(simp)\n    apply(rule allI)\n    apply(rule allI)\n    apply(rule impI)\n    apply(simp add: psubst_nsubst[symmetric]) (*?*)\n    apply(rotate_tac 11)\n    apply(drule_tac x=\"(x,aa,P)#\\<theta>_n\" in meta_spec)\n    apply(drule_tac x=\"\\<theta>_c\" in meta_spec)\n    apply(drule meta_mp)\n    apply(rule ncloses_extend)\n    apply(assumption)\n    apply(assumption)\n    apply(assumption)\n    apply(assumption)\n    apply(drule_tac meta_mp)\n    apply(assumption)\n    apply(assumption)\n    (* cases at least one axiom *)\n    apply(simp (no_asm_use))\n    apply(erule exE)\n    apply(simp del: psubst.simps)\n    apply(drule typing_Ax_elim2)\n    apply(auto simp add: trm.inject)[1]\n    apply(rule_tac B=\"B\" in CUT_SNa)\n    (* left term *)\n    apply(rule BINDING_implies_CAND)\n    apply(unfold BINDINGc_def)\n    apply(simp)\n    apply(rule_tac x=\"a\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<M>\" in exI)\n    apply(simp)\n    apply(rule allI)+\n    apply(rule impI)\n    apply(drule_tac x=\"\\<theta>_n\" in meta_spec)\n    apply(drule_tac x=\"(a,xa,P)#\\<theta>_c\" in meta_spec)\n    apply(drule meta_mp)\n    apply(assumption)\n    apply(drule meta_mp)\n    apply(rule ccloses_extend) \n    apply(assumption)\n    apply(assumption)\n    apply(assumption)\n    apply(assumption)\n    apply(simp add: psubst_csubst[symmetric]) (*?*)\n    (* right term -axiom *)\n    apply(drule ccloses_elim)\n    apply(assumption)\n    apply(erule exE)+\n    apply(erule conjE)\n    apply(frule_tac y=\"x\" in lookupd_cmaps)\n    apply(drule cmaps_fresh)\n    apply(assumption)\n    apply(simp)\n    apply(subgoal_tac \"(x):P[xa\\<turnstile>n>x] = (xa):P\")\n    apply(simp)\n    apply(simp add: ntrm.inject)\n    apply(simp add: alpha fresh_prod fresh_atm)\n    apply(rule sym)\n    apply(rule nrename_swap)\n    apply(simp)\n    (* M is axiom *)\n    apply(simp)\n    apply(auto)[1]\n    (* both are axioms *)\n    apply(rule_tac B=\"B\" in CUT_SNa)\n    apply(drule typing_Ax_elim1)\n    apply(drule ncloses_elim)\n    apply(assumption)\n    apply(erule exE)+\n    apply(erule conjE)\n    apply(frule_tac a=\"a\" in lookupc_nmaps)\n    apply(drule_tac a=\"a\" in nmaps_fresh)\n    apply(assumption)\n    apply(simp)\n    apply(subgoal_tac \"<a>:P[c\\<turnstile>c>a] = <c>:P\")\n    apply(simp)\n    apply(simp add: ctrm.inject)\n    apply(simp add: alpha fresh_prod fresh_atm)\n    apply(rule sym)\n    apply(rule crename_swap)\n    apply(simp)\n    apply(drule typing_Ax_elim2)\n    apply(drule ccloses_elim)\n    apply(assumption)\n    apply(erule exE)+\n    apply(erule conjE)\n    apply(frule_tac y=\"x\" in lookupd_cmaps)\n    apply(drule cmaps_fresh)\n    apply(assumption)\n    apply(simp)\n    apply(subgoal_tac \"(x):P[xa\\<turnstile>n>x] = (xa):P\")\n    apply(simp)\n    apply(simp add: ntrm.inject)\n    apply(simp add: alpha fresh_prod fresh_atm)\n    apply(rule sym)\n    apply(rule nrename_swap)\n    apply(simp)\n    (* N is not axioms *)\n    apply(rule_tac B=\"B\" in CUT_SNa)\n    (* left term *)\n    apply(drule typing_Ax_elim1)\n    apply(drule ncloses_elim)\n    apply(assumption)\n    apply(erule exE)+\n    apply(erule conjE)\n    apply(frule_tac a=\"a\" in lookupc_nmaps)\n    apply(drule_tac a=\"a\" in nmaps_fresh)\n    apply(assumption)\n    apply(simp)\n    apply(subgoal_tac \"<a>:P[c\\<turnstile>c>a] = <c>:P\")\n    apply(simp)\n    apply(simp add: ctrm.inject)\n    apply(simp add: alpha fresh_prod fresh_atm)\n    apply(rule sym)\n    apply(rule crename_swap)\n    apply(simp)\n    apply(rule BINDING_implies_CAND)\n    apply(unfold BINDINGn_def)\n    apply(simp)\n    apply(rule_tac x=\"x\" in exI)\n    apply(rule_tac x=\"\\<theta>_n,\\<theta>_c<N>\" in exI)\n    apply(simp)\n    apply(rule allI)\n    apply(rule allI)\n    apply(rule impI)\n    apply(simp add: psubst_nsubst[symmetric]) (*?*)\n    apply(rotate_tac 10)\n    apply(drule_tac x=\"(x,aa,P)#\\<theta>_n\" in meta_spec)\n    apply(drule_tac x=\"\\<theta>_c\" in meta_spec)\n    apply(drule meta_mp)\n    apply(rule ncloses_extend)\n    apply(assumption)\n    apply(assumption)\n    apply(assumption)\n    apply(assumption)\n    apply(drule_tac meta_mp)\n    apply(assumption)\n    apply(assumption)\n    done\nqed\n\nprimrec \"idn\" :: \"(name\\<times>ty) list\\<Rightarrow>coname\\<Rightarrow>(name\\<times>coname\\<times>trm) list\" where\n  \"idn [] a   = []\"\n| \"idn (p#\\<Gamma>) a = ((fst p),a,Ax (fst p) a)#(idn \\<Gamma> a)\"\n\nprimrec \"idc\" :: \"(coname\\<times>ty) list\\<Rightarrow>name\\<Rightarrow>(coname\\<times>name\\<times>trm) list\" where\n  \"idc [] x    = []\"\n| \"idc (p#\\<Delta>) x = ((fst p),x,Ax x (fst p))#(idc \\<Delta> x)\"\n\nlemma idn_eqvt[eqvt]:\n  fixes pi1::\"name prm\"\n  and   pi2::\"coname prm\"\n  shows \"(pi1\\<bullet>(idn \\<Gamma> a)) = idn (pi1\\<bullet>\\<Gamma>) (pi1\\<bullet>a)\"\n  and   \"(pi2\\<bullet>(idn \\<Gamma> a)) = idn (pi2\\<bullet>\\<Gamma>) (pi2\\<bullet>a)\"\napply(induct \\<Gamma>)\napply(auto)\ndone\n\nlemma idc_eqvt[eqvt]:\n  fixes pi1::\"name prm\"\n  and   pi2::\"coname prm\"\n  shows \"(pi1\\<bullet>(idc \\<Delta> x)) = idc (pi1\\<bullet>\\<Delta>) (pi1\\<bullet>x)\"\n  and   \"(pi2\\<bullet>(idc \\<Delta> x)) = idc (pi2\\<bullet>\\<Delta>) (pi2\\<bullet>x)\"\napply(induct \\<Delta>)\napply(auto)\ndone\n\nlemma ccloses_id:\n  shows \"(idc \\<Delta> x) ccloses \\<Delta>\"\napply(induct \\<Delta>)\napply(auto simp add: ccloses_def)\napply(rule Ax_in_CANDs)\napply(rule Ax_in_CANDs)\ndone\n\nlemma ncloses_id:\n  shows \"(idn \\<Gamma> a) ncloses \\<Gamma>\"\napply(induct \\<Gamma>)\napply(auto simp add: ncloses_def)\napply(rule Ax_in_CANDs)\napply(rule Ax_in_CANDs)\ndone\n\nlemma fresh_idn:\n  fixes x::\"name\"\n  and   a::\"coname\"\n  shows \"x\\<sharp>\\<Gamma> \\<Longrightarrow> x\\<sharp>idn \\<Gamma> a\"\n  and   \"a\\<sharp>(\\<Gamma>,b) \\<Longrightarrow> a\\<sharp>idn \\<Gamma> b\"\napply(induct \\<Gamma>)\napply(auto simp add: fresh_list_cons fresh_list_nil fresh_atm fresh_prod)\ndone\n\nlemma fresh_idc:\n  fixes x::\"name\"\n  and   a::\"coname\"\n  shows \"x\\<sharp>(\\<Delta>,y) \\<Longrightarrow> x\\<sharp>idc \\<Delta> y\"\n  and   \"a\\<sharp>\\<Delta>  \\<Longrightarrow> a\\<sharp>idc \\<Delta> y\"\napply(induct \\<Delta>)\napply(auto simp add: fresh_list_cons fresh_list_nil fresh_atm fresh_prod)\ndone\n\nlemma idc_cmaps:\n  assumes a: \"idc \\<Delta> y cmaps b to Some (x,M)\"\n  shows \"M=Ax x b\"\nusing a\napply(induct \\<Delta>)\napply(auto)\napply(case_tac \"b=a\")\napply(auto)\ndone\n\nlemma idn_nmaps:\n  assumes a: \"idn \\<Gamma> a nmaps x to Some (b,M)\"\n  shows \"M=Ax x b\"\nusing a\napply(induct \\<Gamma>)\napply(auto)\napply(case_tac \"aa=x\")\napply(auto)\ndone\n\nlemma lookup1:\n  assumes a: \"x\\<sharp>(idn \\<Gamma> b)\"\n  shows \"lookup x a (idn \\<Gamma> b) \\<theta>_c = lookupa x a \\<theta>_c\"\nusing a\napply(induct \\<Gamma>)\napply(auto simp add: fresh_list_cons fresh_prod fresh_atm)\ndone\n\nlemma lookup2:\n  assumes a: \"\\<not>(x\\<sharp>(idn \\<Gamma> b))\"\n  shows \"lookup x a (idn \\<Gamma> b) \\<theta>_c = lookupb x a \\<theta>_c b (Ax x b)\"\nusing a\napply(induct \\<Gamma>)\napply(auto simp add: fresh_list_cons fresh_prod fresh_atm fresh_list_nil)\ndone\n\nlemma lookup3:\n  assumes a: \"a\\<sharp>(idc \\<Delta> y)\"\n  shows \"lookupa x a (idc \\<Delta> y) = Ax x a\"\nusing a\napply(induct \\<Delta>)\napply(auto simp add: fresh_list_cons fresh_prod fresh_atm)\ndone\n\nlemma lookup4:\n  assumes a: \"\\<not>(a\\<sharp>(idc \\<Delta> y))\"\n  shows \"lookupa x a (idc \\<Delta> y) = Cut <a>.(Ax x a) (y).Ax y a\"\nusing a\napply(induct \\<Delta>)\napply(auto simp add: fresh_list_cons fresh_prod fresh_atm fresh_list_nil)\ndone\n\nlemma lookup5:\n  assumes a: \"a\\<sharp>(idc \\<Delta> y)\"\n  shows \"lookupb x a (idc \\<Delta> y) c P = Cut <c>.P (x).Ax x a\"\nusing a\napply(induct \\<Delta>)\napply(auto simp add: fresh_list_cons fresh_prod fresh_atm fresh_list_nil)\ndone\n\nlemma lookup6:\n  assumes a: \"\\<not>(a\\<sharp>(idc \\<Delta> y))\"\n  shows \"lookupb x a (idc \\<Delta> y) c P = Cut <c>.P (y).Ax y a\"\nusing a\napply(induct \\<Delta>)\napply(auto simp add: fresh_list_cons fresh_prod fresh_atm fresh_list_nil)\ndone\n\nlemma lookup7:\n  shows \"lookupc x a (idn \\<Gamma> b) = Ax x a\"\napply(induct \\<Gamma>)\napply(auto simp add: fresh_list_cons fresh_prod fresh_atm fresh_list_nil)\ndone\n\nlemma lookup8:\n  shows \"lookupd x a (idc \\<Delta> y) = Ax x a\"\napply(induct \\<Delta>)\napply(auto simp add: fresh_list_cons fresh_prod fresh_atm fresh_list_nil)\ndone\n\nlemma id_redu:\n  shows \"(idn \\<Gamma> x),(idc \\<Delta> a)<M> \\<longrightarrow>\\<^sub>a* M\"\napply(nominal_induct M avoiding: \\<Gamma> \\<Delta> x a rule: trm.strong_induct)\napply(auto)\n(* Ax *)\napply(case_tac \"name\\<sharp>(idn \\<Gamma> x)\")\napply(simp add: lookup1)\napply(case_tac \"coname\\<sharp>(idc \\<Delta> a)\")\napply(simp add: lookup3)\napply(simp add: lookup4)\napply(rule a_star_trans)\napply(rule a_starI)\napply(rule al_redu)\napply(rule better_LAxR_intro)\napply(rule fic.intros)\napply(simp)\napply(simp add: lookup2)\napply(case_tac \"coname\\<sharp>(idc \\<Delta> a)\")\napply(simp add: lookup5)\napply(rule a_star_trans)\napply(rule a_starI)\napply(rule al_redu)\napply(rule better_LAxR_intro)\napply(rule fic.intros)\napply(simp)\napply(simp add: lookup6)\napply(rule a_star_trans)\napply(rule a_starI)\napply(rule al_redu)\napply(rule better_LAxR_intro)\napply(rule fic.intros)\napply(simp)\n(* Cut *)\napply(auto simp add: fresh_idn fresh_idc psubst_fresh_name psubst_fresh_coname fresh_atm fresh_prod )[1]\napply(simp add: lookup7 lookup8)\napply(simp add: lookup7 lookup8)\napply(simp add: a_star_Cut)\napply(simp add: lookup7 lookup8)\napply(simp add: a_star_Cut)\napply(simp add: a_star_Cut)\n(* NotR *)\napply(simp add: fresh_idn fresh_idc)\napply(case_tac \"findc (idc \\<Delta> a) coname\")\napply(simp)\napply(simp add: a_star_NotR)\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(drule idc_cmaps)\napply(simp)\napply(subgoal_tac \"c\\<sharp>idn \\<Gamma> x,idc \\<Delta> a<trm>\")\napply(rule a_star_trans)\napply(rule a_starI)\napply(rule al_redu)\napply(rule better_LAxR_intro)\napply(rule fic.intros)\napply(assumption)\napply(simp add: crename_fresh)\napply(simp add: a_star_NotR)\napply(rule psubst_fresh_coname)\napply(rule fresh_idn)\napply(simp)\napply(rule fresh_idc)\napply(simp)\napply(simp)\n(* NotL *)\napply(simp add: fresh_idn fresh_idc)\napply(case_tac \"findn (idn \\<Gamma> x) name\")\napply(simp)\napply(simp add: a_star_NotL)\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(drule idn_nmaps)\napply(simp)\napply(subgoal_tac \"c\\<sharp>idn \\<Gamma> x,idc \\<Delta> a<trm>\")\napply(rule a_star_trans)\napply(rule a_starI)\napply(rule al_redu)\napply(rule better_LAxL_intro)\napply(rule fin.intros)\napply(assumption)\napply(simp add: nrename_fresh)\napply(simp add: a_star_NotL)\napply(rule psubst_fresh_name)\napply(rule fresh_idn)\napply(simp)\napply(rule fresh_idc)\napply(simp)\napply(simp)\n(* AndR *)\napply(simp add: fresh_idn fresh_idc)\napply(case_tac \"findc (idc \\<Delta> a) coname3\")\napply(simp)\napply(simp add: a_star_AndR)\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(drule idc_cmaps)\napply(simp)\napply(subgoal_tac \"c\\<sharp>idn \\<Gamma> x,idc \\<Delta> a<trm1>\")\napply(subgoal_tac \"c\\<sharp>idn \\<Gamma> x,idc \\<Delta> a<trm2>\")\napply(rule a_star_trans)\napply(rule a_starI)\napply(rule al_redu)\napply(rule better_LAxR_intro)\napply(rule fic.intros)\napply(simp add: abs_fresh)\napply(simp add: abs_fresh)\napply(auto simp add: fresh_idn fresh_idc psubst_fresh_name crename_fresh fresh_atm fresh_prod )[1]\napply(rule aux3)\napply(rule crename.simps)\napply(auto simp add: fresh_prod fresh_atm)[1]\napply(rule psubst_fresh_coname)\napply(rule fresh_idn)\napply(simp add: fresh_prod fresh_atm)\napply(rule fresh_idc)\napply(simp)\napply(simp)\napply(auto simp add: fresh_prod fresh_atm)[1]\napply(rule psubst_fresh_coname)\napply(rule fresh_idn)\napply(simp add: fresh_prod fresh_atm)\napply(rule fresh_idc)\napply(simp)\napply(simp)\napply(simp)\napply(simp)\napply(simp add: crename_fresh)\napply(simp add: a_star_AndR)\napply(rule psubst_fresh_coname)\napply(rule fresh_idn)\napply(simp)\napply(rule fresh_idc)\napply(simp)\napply(simp)\napply(rule psubst_fresh_coname)\napply(rule fresh_idn)\napply(simp)\napply(rule fresh_idc)\napply(simp)\napply(simp)\n(* AndL1 *)\napply(simp add: fresh_idn fresh_idc)\napply(case_tac \"findn (idn \\<Gamma> x) name2\")\napply(simp)\napply(simp add: a_star_AndL1)\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(drule idn_nmaps)\napply(simp)\napply(subgoal_tac \"c\\<sharp>idn \\<Gamma> x,idc \\<Delta> a<trm>\")\napply(rule a_star_trans)\napply(rule a_starI)\napply(rule al_redu)\napply(rule better_LAxL_intro)\napply(rule fin.intros)\napply(simp add: abs_fresh)\napply(rule aux3)\napply(rule nrename.simps)\napply(auto simp add: fresh_prod fresh_atm)[1]\napply(simp)\napply(simp add: nrename_fresh)\napply(simp add: a_star_AndL1)\napply(rule psubst_fresh_name)\napply(rule fresh_idn)\napply(simp)\napply(rule fresh_idc)\napply(simp)\napply(simp)\n(* AndL2 *)\napply(simp add: fresh_idn fresh_idc)\napply(case_tac \"findn (idn \\<Gamma> x) name2\")\napply(simp)\napply(simp add: a_star_AndL2)\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(drule idn_nmaps)\napply(simp)\napply(subgoal_tac \"c\\<sharp>idn \\<Gamma> x,idc \\<Delta> a<trm>\")\napply(rule a_star_trans)\napply(rule a_starI)\napply(rule al_redu)\napply(rule better_LAxL_intro)\napply(rule fin.intros)\napply(simp add: abs_fresh)\napply(rule aux3)\napply(rule nrename.simps)\napply(auto simp add: fresh_prod fresh_atm)[1]\napply(simp)\napply(simp add: nrename_fresh)\napply(simp add: a_star_AndL2)\napply(rule psubst_fresh_name)\napply(rule fresh_idn)\napply(simp)\napply(rule fresh_idc)\napply(simp)\napply(simp)\n(* OrR1 *)\napply(simp add: fresh_idn fresh_idc)\napply(case_tac \"findc (idc \\<Delta> a) coname2\")\napply(simp)\napply(simp add: a_star_OrR1)\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(drule idc_cmaps)\napply(simp)\napply(subgoal_tac \"c\\<sharp>idn \\<Gamma> x,idc \\<Delta> a<trm>\")\napply(rule a_star_trans)\napply(rule a_starI)\napply(rule al_redu)\napply(rule better_LAxR_intro)\napply(rule fic.intros)\napply(simp add: abs_fresh)\napply(rule aux3)\napply(rule crename.simps)\napply(auto simp add: fresh_prod fresh_atm)[1]\napply(simp)\napply(simp add: crename_fresh)\napply(simp add: a_star_OrR1)\napply(rule psubst_fresh_coname)\napply(rule fresh_idn)\napply(simp)\napply(rule fresh_idc)\napply(simp)\napply(simp)\n(* OrR2 *)\napply(simp add: fresh_idn fresh_idc)\napply(case_tac \"findc (idc \\<Delta> a) coname2\")\napply(simp)\napply(simp add: a_star_OrR2)\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(drule idc_cmaps)\napply(simp)\napply(subgoal_tac \"c\\<sharp>idn \\<Gamma> x,idc \\<Delta> a<trm>\")\napply(rule a_star_trans)\napply(rule a_starI)\napply(rule al_redu)\napply(rule better_LAxR_intro)\napply(rule fic.intros)\napply(simp add: abs_fresh)\napply(rule aux3)\napply(rule crename.simps)\napply(auto simp add: fresh_prod fresh_atm)[1]\napply(simp)\napply(simp add: crename_fresh)\napply(simp add: a_star_OrR2)\napply(rule psubst_fresh_coname)\napply(rule fresh_idn)\napply(simp)\napply(rule fresh_idc)\napply(simp)\napply(simp)\n(* OrL *)\napply(simp add: fresh_idn fresh_idc)\napply(case_tac \"findn (idn \\<Gamma> x) name3\")\napply(simp)\napply(simp add: a_star_OrL)\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(drule idn_nmaps)\napply(simp)\napply(subgoal_tac \"c\\<sharp>idn \\<Gamma> x,idc \\<Delta> a<trm1>\")\napply(subgoal_tac \"c\\<sharp>idn \\<Gamma> x,idc \\<Delta> a<trm2>\")\napply(rule a_star_trans)\napply(rule a_starI)\napply(rule al_redu)\napply(rule better_LAxL_intro)\napply(rule fin.intros)\napply(simp add: abs_fresh)\napply(simp add: abs_fresh)\napply(rule aux3)\napply(rule nrename.simps)\napply(auto simp add: fresh_prod fresh_atm)[1]\napply(rule psubst_fresh_name)\napply(rule fresh_idn)\napply(simp)\napply(rule fresh_idc)\napply(simp add: fresh_prod fresh_atm)\napply(simp)\napply(auto simp add: fresh_prod fresh_atm)[1]\napply(rule psubst_fresh_name)\napply(rule fresh_idn)\napply(simp)\napply(rule fresh_idc)\napply(simp add: fresh_prod fresh_atm)\napply(simp)\napply(simp)\napply(simp)\napply(simp add: nrename_fresh)\napply(simp add: a_star_OrL)\napply(rule psubst_fresh_name)\napply(rule fresh_idn)\napply(simp)\napply(rule fresh_idc)\napply(simp)\napply(simp)\napply(rule psubst_fresh_name)\napply(rule fresh_idn)\napply(simp)\napply(rule fresh_idc)\napply(simp)\napply(simp)\n(* ImpR *)\napply(simp add: fresh_idn fresh_idc)\napply(case_tac \"findc (idc \\<Delta> a) coname2\")\napply(simp)\napply(simp add: a_star_ImpR)\napply(auto)[1]\napply(generate_fresh \"coname\")\napply(fresh_fun_simp)\napply(drule idc_cmaps)\napply(simp)\napply(subgoal_tac \"c\\<sharp>idn \\<Gamma> x,idc \\<Delta> a<trm>\")\napply(rule a_star_trans)\napply(rule a_starI)\napply(rule al_redu)\napply(rule better_LAxR_intro)\napply(rule fic.intros)\napply(simp add: abs_fresh)\napply(rule aux3)\napply(rule crename.simps)\napply(auto simp add: fresh_prod fresh_atm)[1]\napply(simp)\napply(simp add: crename_fresh)\napply(simp add: a_star_ImpR)\napply(rule psubst_fresh_coname)\napply(rule fresh_idn)\napply(simp)\napply(rule fresh_idc)\napply(simp)\napply(simp)\n(* ImpL *)\napply(simp add: fresh_idn fresh_idc)\napply(case_tac \"findn (idn \\<Gamma> x) name2\")\napply(simp)\napply(simp add: a_star_ImpL)\napply(auto)[1]\napply(generate_fresh \"name\")\napply(fresh_fun_simp)\napply(drule idn_nmaps)\napply(simp)\napply(subgoal_tac \"c\\<sharp>idn \\<Gamma> x,idc \\<Delta> a<trm1>\")\napply(subgoal_tac \"c\\<sharp>idn \\<Gamma> x,idc \\<Delta> a<trm2>\")\napply(rule a_star_trans)\napply(rule a_starI)\napply(rule al_redu)\napply(rule better_LAxL_intro)\napply(rule fin.intros)\napply(simp add: abs_fresh)\napply(simp add: abs_fresh)\napply(rule aux3)\napply(rule nrename.simps)\napply(auto simp add: fresh_prod fresh_atm)[1]\napply(rule psubst_fresh_coname)\napply(rule fresh_idn)\napply(simp add: fresh_atm)\napply(rule fresh_idc)\napply(simp add: fresh_prod fresh_atm)\napply(simp)\napply(auto simp add: fresh_prod fresh_atm)[1]\napply(rule psubst_fresh_name)\napply(rule fresh_idn)\napply(simp)\napply(rule fresh_idc)\napply(simp add: fresh_prod fresh_atm)\napply(simp)\napply(simp)\napply(simp add: nrename_fresh)\napply(simp add: a_star_ImpL)\napply(rule psubst_fresh_name)\napply(rule fresh_idn)\napply(simp)\napply(rule fresh_idc)\napply(simp)\napply(simp)\napply(rule psubst_fresh_name)\napply(rule fresh_idn)\napply(simp)\napply(rule fresh_idc)\napply(simp)\napply(simp)\ndone\n\ntheorem ALL_SNa:\n  assumes a: \"\\<Gamma> \\<turnstile> M \\<turnstile> \\<Delta>\"\n  shows \"SNa M\"\nproof -\n  fix x have \"(idc \\<Delta> x) ccloses \\<Delta>\" by (simp add: ccloses_id)\n  moreover\n  fix a have \"(idn \\<Gamma> a) ncloses \\<Gamma>\" by (simp add: ncloses_id)\n  ultimately have \"SNa ((idn \\<Gamma> a),(idc \\<Delta> x)<M>)\" using a by (simp add: all_CAND)\n  moreover\n  have \"((idn \\<Gamma> a),(idc \\<Delta> x)<M>) \\<longrightarrow>\\<^sub>a* M\" by (simp add: id_redu)\n  ultimately show \"SNa M\" by (simp add: a_star_preserves_SNa)\nqed\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/HOL/Nominal/Examples/Class3.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526514141571, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.26271163403753856}}
{"text": "(*<*)\n(*\n * Knowledge-based programs.\n * (C)opyright 2011, Peter Gammie, peteg42 at gmail.com.\n * License: BSD\n *)\n\ntheory SPRViewNonDetIndInit\nimports\n  SPRView\n  KBPsAuto\n  SPRViewNonDet\nbegin\n(*>*)\n\nsubsubsection{*Perfect Recall in Independently-Initialised Non-deterministic Broadcast Environments*}\n\ntext{*\n\n\\label{sec:kbps-theory-spr-non-deterministic-protocols-ind-init}\n\nIf the private and environment parts of the initial states are\nindependent we can simplify the construction of the previous section\nand consider only sets of states rather than relations. This greatly\nreduces the state space that the algorithm traverses.\n\nWe capture this independence by adding some assumptions to the @{term\n\"FiniteBroadcastEnvironment\"} locale of\nFigure~\\ref{fig:kbps-theory-broadcast-envs}; the result is the @{term\n\"FiniteBroadcastEnvironmentIndependentInit\"} locale shown in\nFigure~\\ref{fig:kbps-theory-broadcast-envs-ind-init}. We ask that the\ninitial states be the Cartesian product of possible private and\nenvironment states; in other words there is nothing for the agents to\nlearn about correlations amongst the initial states. As there are\ninitially no public actions from the previous round, we use the @{term\n\"default\"} class to indicate that there is a fixed but arbitrary\nchoice to be made here.\n\nAgain we introduce common and agent-specific abstraction functions:\n\n\n*}\n\ntext_raw{*\n\\begin{figure}[ht]\n\\begin{isabellebody}%\n*}\nlocale FiniteBroadcastEnvironmentIndependentInit =\n  FiniteBroadcastEnvironment jkbp envInit envAction envTrans envVal envObs\n                             envObsC envActionES envTransES\n    for jkbp :: \"('a::finite, 'p, ('pPubAct::{default,finite} \\<times> 'ps::finite)) JKBP\"\n    and envInit :: \"('a, 'ePubAct :: {default, finite}, 'es :: finite,\n                     'pPubAct, 'ps) BEState list\"\n    and envAction :: \"('a, 'ePubAct, 'es, 'pPubAct, 'ps) BEState\n                   \\<Rightarrow> ('ePubAct \\<times> 'ePrivAct) list\"\n    and envTrans :: \"('ePubAct \\<times> 'ePrivAct)\n                  \\<Rightarrow> ('a \\<Rightarrow> ('pPubAct \\<times> 'ps))\n                  \\<Rightarrow> ('a, 'ePubAct, 'es, 'pPubAct, 'ps) BEState\n                  \\<Rightarrow> ('a, 'ePubAct, 'es, 'pPubAct, 'ps) BEState\"\n    and envVal :: \"('a, 'ePubAct, 'es, 'pPubAct, 'ps) BEState \\<Rightarrow> 'p \\<Rightarrow> bool\"\n    and envObs :: \"'a \\<Rightarrow> ('a, 'ePubAct, 'es, 'pPubAct, 'ps) BEState\n                \\<Rightarrow> ('cobs \\<times> 'ps \\<times> ('ePubAct \\<times> ('a \\<Rightarrow> 'pPubAct)))\"\n    and envObsC :: \"'es \\<Rightarrow> 'cobs\"\n    and envActionES :: \"'es \\<Rightarrow> ('ePubAct \\<times> ('a \\<Rightarrow> 'pPubAct))\n                            \\<Rightarrow> ('ePubAct \\<times> 'ePrivAct) list\"\n    and envTransES :: \"('ePubAct \\<times> 'ePrivAct) \\<Rightarrow> ('a \\<Rightarrow> 'pPubAct)\n                    \\<Rightarrow> 'es \\<Rightarrow> 'es\"\n\n+ fixes agents :: \"'a list\"\n  fixes envInitBits :: \"'es list \\<times> ('a \\<Rightarrow> 'ps list)\"\n  defines envInit_def:\n     \"envInit \\<equiv> [ \\<lparr> es = esf, ps = psf, pubActs = (default, \\<lambda>_. default) \\<rparr>\n                 . psf \\<leftarrow> listToFuns (snd envInitBits) agents\n                 , esf \\<leftarrow> fst envInitBits ]\"\n  assumes agents: \"set agents = UNIV\" \"distinct agents\"\n\ntext_raw{*\n  \\end{isabellebody}%\n  \\caption{Finite broadcast environments with non-deterministic\n  KBPs, where the initial private and environment states are\n  independent.}\n  \\label{fig:kbps-theory-broadcast-envs-ind-init}\n\\end{figure}\n*}\n\ncontext FiniteBroadcastEnvironmentIndependentInit\nbegin\n\ndefinition\n  tObsC_ii_abs :: \"('a, 'ePubAct, 'es, 'pPubAct, 'ps) BEState Trace\n             \\<Rightarrow> ('a, 'ePubAct, 'es, 'pPubAct, 'ps) BEState set\"\nwhere \"tObsC_ii_abs t \\<equiv>\n  { tLast t' |t'. t' \\<in> SPR.jkbpC \\<and> tObsC t' = tObsC t }\"\n\ndefinition\n  agent_ii_abs :: \"'a \\<Rightarrow> ('a, 'ePubAct, 'es, 'pPubAct, 'ps) BEState Trace\n             \\<Rightarrow> ('a, 'ePubAct, 'es, 'pPubAct, 'ps) BEState set\"\nwhere \"agent_ii_abs a t \\<equiv>\n  { tLast t' |t'. t' \\<in> SPR.jkbpC \\<and> spr_jview a t' = spr_jview a t }\"\n(*<*)\n\nlemma tObsC_ii_abs_jview_eq[dest, intro]:\n  \"spr_jview a t' = spr_jview a t\n    \\<Longrightarrow> tObsC_ii_abs t = tObsC_ii_abs t'\"\n  unfolding tObsC_ii_abs_def by (fastforce dest: spr_jview_tObsC)\n\nlemma tObsC_ii_absI[intro]:\n  \"\\<lbrakk> t' \\<in> SPR.jkbpC; tObsC t' = tObsC t; v = tLast t' \\<rbrakk>\n    \\<Longrightarrow> v \\<in> tObsC_ii_abs t\"\n  unfolding tObsC_ii_abs_def by blast\n\nlemma tObsC_ii_abs_conv:\n  \" v \\<in> tObsC_ii_abs t\n    \\<longleftrightarrow> (\\<exists>t'. t' \\<in> SPR.jkbpC \\<and> tObsC t' = tObsC t \\<and> v = tLast t')\"\n  unfolding tObsC_ii_abs_def by blast\n\nlemma agent_ii_absI[elim]:\n  \"\\<lbrakk> t' \\<in> SPR.jkbpC; spr_jview a t' = spr_jview a t; v = tLast t' \\<rbrakk>\n    \\<Longrightarrow> v \\<in> agent_ii_abs a t\"\n  unfolding agent_ii_abs_def by blast\n\nlemma agent_ii_abs_tLastD[simp]:\n  \"v \\<in> agent_ii_abs a t \\<Longrightarrow> envObs a v = envObs a (tLast t)\"\n  unfolding agent_ii_abs_def by auto\n\nlemma agent_ii_abs_inv[dest]:\n  \"v \\<in> agent_ii_abs a t\n    \\<Longrightarrow> \\<exists>t'. t' \\<in> SPR.jkbpC \\<and> spr_jview a t' = spr_jview a t\n           \\<and> v = tLast t'\"\n  unfolding agent_ii_abs_def by blast\n\n(*>*)\ntext{*\n\nThe simulation is similar to the single-agent case\n(\\S\\ref{sec:kbps-spr-single-agent}); for a given canonical trace\n@{term \"t\"} it pairs the set of worlds that any agent considers\npossible with the final state of @{term \"t\"}:\n\n*}\n\ntype_synonym (in -) ('a, 'ePubAct, 'es, 'pPubAct, 'ps) SPRstate =\n  \"('a, 'ePubAct, 'es, 'pPubAct, 'ps) BEState set\n \\<times> ('a, 'ePubAct, 'es, 'pPubAct, 'ps) BEState\"\n\ndefinition\n  spr_ii_sim :: \"('a, 'ePubAct, 'es, 'pPubAct, 'ps) BEState Trace\n           \\<Rightarrow> ('a, 'ePubAct, 'es, 'pPubAct, 'ps) SPRstate\"\nwhere \"spr_ii_sim \\<equiv> \\<lambda>t. (tObsC_ii_abs t, tLast t)\"\n(*<*)\n\nlemma spr_ii_sim_tFirst_tLast:\n  \"\\<lbrakk> spr_ii_sim t = s; t \\<in> SPR.jkbpC \\<rbrakk> \\<Longrightarrow> snd s \\<in> fst s\"\n  unfolding spr_ii_sim_def by auto\n\n(*>*)\ntext{*\n\nThe Kripke structure over simulated traces is also quite similar:\n\n*}\n\ndefinition\n  spr_ii_simRels :: \"'a \\<Rightarrow> ('a, 'ePubAct, 'es, 'pPubAct, 'ps) SPRstate Relation\"\nwhere \"spr_ii_simRels \\<equiv> \\<lambda>a.\n  { (s, s') |s s'. envObs a (snd s) = envObs a (snd s') \\<and> fst s = fst s' }\"\n\ndefinition\n  spr_ii_simVal :: \"('a, 'ePubAct, 'es, 'pPubAct, 'ps) SPRstate \\<Rightarrow> 'p \\<Rightarrow> bool\"\nwhere \"spr_ii_simVal \\<equiv> envVal \\<circ> snd\"\n\nabbreviation\n  \"spr_ii_simMC \\<equiv> mkKripke (spr_ii_sim ` SPR.jkbpC) spr_ii_simRels spr_ii_simVal\"\n(*<*)\n\nlemma spr_ii_simVal_def2[iff]:\n  \"spr_ii_simVal (spr_ii_sim t) = envVal (tLast t)\"\n  unfolding spr_ii_sim_def spr_ii_simVal_def by simp\n\n(* Same as for SPRViewNonDet but different base case. *)\n\nlemma tSplice_jkbpC:\n  assumes tt': \"{t, t'} \\<subseteq> SPR.jkbpC\"\n  assumes tObsC: \"tObsC t = tObsC t'\"\n  shows \"t \\<^bsub>\\<^esub>\\<bowtie>\\<^bsub>a\\<^esub> t' \\<in> SPR.jkbpC\"\nusing tObsC_tLength[OF tObsC] tt' tObsC\nproof(induct rule: trace_induct2)\n  case (tInit s s') thus ?case\n    apply clarsimp\n    unfolding envInit_def sSplice_def\n    apply clarsimp\n    apply (rule_tac x=\"x(a := xa a)\" in bexI)\n    using listToFun_splice[OF agents]\n    apply auto\n    done\nnext\n  case (tStep s s' t t')\n\n  hence tt': \"t \\<^bsub>\\<^esub>\\<bowtie>\\<^bsub>a\\<^esub> t' \\<in> SPR.jkbpC\"\n    and tLen: \"tLength t' = tLength t\"\n    and tObsC: \"tObsC (t \\<leadsto> s) = tObsC (t' \\<leadsto> s')\"\n    by auto\n\n  hence tt'n: \"t \\<^bsub>\\<^esub>\\<bowtie>\\<^bsub>a\\<^esub> t' \\<in> SPR.jkbpCn (tLength t)\"\n    by auto\n\n  from tStep\n  have ts: \"t \\<leadsto> s \\<in> SPR.jkbpCn (Suc (tLength t))\"\n   and t's': \"t' \\<leadsto> s' \\<in> SPR.jkbpCn (Suc (tLength t'))\"\n    apply -\n     apply ((rule SPR.jkbpC_tLength_inv, simp_all)[1])+\n    done\n\n  from ts obtain eact aact\n    where eact: \"eact \\<in> set (envAction (tLast t))\"\n      and aact: \"\\<forall>a. aact a \\<in> set (jAction (SPR.mkM (SPR.jkbpCn (tLength t))) t a)\"\n      and trans: \"envTrans eact aact (tLast t) = s\"\n    apply (auto iff: Let_def)\n    done\n\n  from t's' obtain eact' aact'\n    where eact': \"eact' \\<in> set (envAction (tLast t'))\"\n      and aact': \"\\<forall>a. aact' a \\<in> set (jAction (SPR.mkM (SPR.jkbpCn (tLength t'))) t' a)\"\n      and trans': \"envTrans eact' aact' (tLast t') = s'\"\n    apply (auto iff: Let_def)\n    done\n\n  def aact'' \\<equiv> \"aact (a := aact' a)\"\n\n  from tObsC trans trans'\n  have aact''_fst: \"fst \\<circ> aact'' = fst \\<circ> aact\"\n    unfolding envTrans_def aact''_def\n    apply -\n    apply (rule ext)\n    apply (auto iff: tObsC_tStep)\n    apply (erule o_eq_elim)\n    apply simp\n    done\n\n  from tObsC trans trans'\n  have aact''_snd: \"snd \\<circ> aact'' = (snd \\<circ> aact)(a := ps s' a)\"\n    unfolding envTrans_def aact''_def\n    apply -\n    apply (rule ext)\n    apply auto\n    done\n\n  have \"envTrans eact aact'' (tLast (t \\<^bsub>\\<^esub>\\<bowtie>\\<^bsub>a\\<^esub> t'))\n      = sSplice a (envTrans eact aact (tLast t)) s'\"\n    unfolding envTrans_def sSplice_def\n    using tSplice_es[OF tLen[symmetric]] aact''_fst aact''_snd\n    apply clarsimp\n    done\n\n  moreover\n\n  { fix a'\n    have \"aact'' a' \\<in> set (jAction (SPR.mkM (SPR.jkbpCn (tLength t))) (t \\<^bsub>\\<^esub>\\<bowtie>\\<^bsub>a\\<^esub> t') a')\"\n    proof(cases \"a' = a\")\n      case False\n      with tStep have \"jAction (SPR.mkM (SPR.jkbpCn (tLength t))) (t \\<^bsub>\\<^esub>\\<bowtie>\\<^bsub>a\\<^esub> t') a'\n                     = jAction (SPR.mkM (SPR.jkbpCn (tLength t))) t a'\"\n        apply -\n        apply (rule S5n_jAction_eq)\n         apply simp\n        unfolding SPR.mkM_def\n        using tSplice_spr_jview_not_a tt'\n        apply auto\n        done\n      with False aact show ?thesis\n        unfolding aact''_def by simp\n    next\n      case True\n      with tStep have \"jAction (SPR.mkM (SPR.jkbpCn (tLength t))) (t \\<^bsub>\\<^esub>\\<bowtie>\\<^bsub>a\\<^esub> t') a\n                     = jAction (SPR.mkM (SPR.jkbpCn (tLength t))) t' a\"\n        apply -\n        apply (rule S5n_jAction_eq)\n         apply simp\n        unfolding SPR.mkM_def\n        using tSplice_spr_jview_a tt'\n        apply auto\n        done\n      with True aact' tLen show ?thesis\n        unfolding aact''_def by simp\n    qed }\n\n  moreover\n\n  from tStep have \"envAction (tLast (t \\<^bsub>\\<^esub>\\<bowtie>\\<^bsub>a\\<^esub> t')) = envAction (tLast t)\"\n    using tSplice_envAction by blast\n\n  moreover note eact trans tt'n\n\n  ultimately have \"(t \\<^bsub>\\<^esub>\\<bowtie>\\<^bsub>a\\<^esub> t') \\<leadsto> sSplice a s s' \\<in> SPR.jkbpCn (Suc (tLength t))\"\n    apply (simp add: Let_def del: split_paired_Ex)\n    apply (rule exI[where x=\"eact\"])\n    apply (rule exI[where x=\"aact''\"])\n    apply simp\n    done\n\n  thus ?case\n    apply (simp only: tZip.simps)\n    apply blast\n    done\nqed\n\nlemma spr_ii_sim_r:\n  \"sim_r SPR.MC spr_ii_simMC spr_ii_sim\"\nproof(rule sim_rI)\n  fix a p q'\n  assume pT: \"p \\<in> worlds SPR.MC\"\n     and fpq': \"(spr_ii_sim p, q') \\<in> relations spr_ii_simMC a\"\n  from fpq' obtain vq\n    where q': \"q' = (tObsC_ii_abs p, vq)\"\n      and vq: \"envObs a (tLast p) = envObs a vq\"\n    unfolding mkKripke_def spr_ii_sim_def spr_ii_simRels_def\n    by fastforce\n\n  from fpq' have \"q' \\<in> worlds spr_ii_simMC\" by simp\n  with q' have \"vq \\<in> tObsC_ii_abs p\"\n    using spr_ii_sim_tFirst_tLast[where s=q']\n    apply auto\n    done\n\n  then obtain t\n    where tT: \"t \\<in> SPR.jkbpC\"\n      and tp: \"tObsC t = tObsC p\"\n      and tvq: \"tLast t = vq\"\n    by (auto iff: tObsC_ii_abs_conv)\n\n  def q \\<equiv> \"t \\<^bsub>\\<^esub>\\<bowtie>\\<^bsub>a\\<^esub> p\"\n\n  from tp\n  have \"spr_jview a p = spr_jview a q\"\n    unfolding q_def by (simp add: tSplice_spr_jview_a)\n\n  with pT tT tp\n  have pt: \"(p, q) \\<in> relations SPR.MC a\"\n    unfolding SPR.mkM_def q_def by (simp add: tSplice_jkbpC)\n  from q' vq tp tvq\n  have ftq': \"spr_ii_sim q = q'\"\n    unfolding spr_ii_sim_def q_def\n    using tSplice_tObsC[where a=a and t=t and t'=p]\n    apply clarsimp\n    apply (intro conjI)\n      apply (auto dest: tObsC_tLength)[2]\n    unfolding tObsC_ii_abs_def (* FIXME abstract *)\n    apply auto\n    done\n  from pt ftq'\n  show \"\\<exists>q. (p, q) \\<in> relations SPR.MC a \\<and> spr_ii_sim q = q'\"\n    by blast\nqed\n\n(*>*)\ntext{*\n\nThe proofs that this simulation is adequate are similar to those in\nthe previous section. We elide the details.\n\n*}\n\nlemma spr_ii_sim: \"sim SPR.MC spr_ii_simMC spr_ii_sim\"\n(*<*)\nproof\n  show \"sim_range SPR.MC spr_ii_simMC spr_ii_sim\"\n    by (rule sim_rangeI) (simp_all add: spr_ii_sim_def)\nnext\n  show \"sim_val SPR.MC spr_ii_simMC spr_ii_sim\"\n    by (rule sim_valI) simp\nnext\n  show \"sim_f SPR.MC spr_ii_simMC spr_ii_sim\"\n    unfolding spr_ii_simRels_def spr_ii_sim_def mkKripke_def SPR.mkM_def\n    by (rule sim_fI, auto simp del: split_paired_Ex)\nnext\n  show \"sim_r SPR.MC spr_ii_simMC spr_ii_sim\"\n    by (rule spr_ii_sim_r)\nqed\n(*>*)\n\nend (* context FiniteBroadcastEnvironment *)\n\nsublocale FiniteBroadcastEnvironmentIndependentInit\n        < SPRii!: SimIncrEnvironment jkbp envInit envAction envTrans envVal\n                                       spr_jview envObs spr_jviewInit spr_jviewIncr\n                                       spr_ii_sim spr_ii_simRels spr_ii_simVal\n(*<*)\n  by default (simp add: spr_ii_sim)\n\nend\n(*>*)\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/KBPs/SPRViewNonDetIndInit.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526368038304, "lm_q2_score": 0.46101677931231594, "lm_q1q2_score": 0.2627116273019328}}
{"text": "theory Decision_NCPC\nimports \"../Observation_Setup\" Decision_Value_Setup \"Bounded_Deducibility_Security.Compositional_Reasoning\"\nbegin\n\nsubsection \\<open>Confidentiality protection from non-PC-members\\<close>\n\ntext \\<open>We verify the following property:\n\n\\ \\\\\nA group of users UIDs learn\nnothing about the various updates of a paper's decision\nexcept for the last edited version\nunless/until\na user in UIDs becomes PC member in the paper's conference having no conflict with that paper\nand the conference moves to the decision stage.\n\n\\ \\\\\n\\<close>\n\n(* perhaps this should further strengthened *)\n\nfun T :: \"(state,act,out) trans \\<Rightarrow> bool\" where\n\"T (Trans _ _ ou s') =\n (\\<exists> uid \\<in> UIDs. \\<exists> cid.\n    PID \\<in>\\<in> paperIDs s' cid \\<and> isPC s' cid uid \\<and> pref s' uid PID \\<noteq> Conflict \\<and>\n    phase s' cid \\<ge> disPH\n )\"\n\ndeclare T.simps [simp del]\n\ndefinition B :: \"value list \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"B vl vl1 \\<equiv> vl \\<noteq> [] \\<and> vl1 \\<noteq> [] \\<and> last vl = last vl1\"\n\ninterpretation BD_Security_IO where\nistate = istate and step = step and\n\\<phi> = \\<phi> and f = f and \\<gamma> = \\<gamma> and g = g and T = T and B = B\ndone\n\nlemma reachNT_non_isPC_isChair:\nassumes \"reachNT s\" and \"uid \\<in> UIDs\"\nshows\n\"(PID \\<in>\\<in> paperIDs s cid \\<and> isPC s cid uid \\<and> phase s cid \\<ge> disPH \\<longrightarrow> pref s uid PID = Conflict) \\<and>\n (PID \\<in>\\<in> paperIDs s cid \\<and> isChair s cid uid \\<and> phase s cid \\<ge> disPH \\<longrightarrow> pref s uid PID = Conflict)\"\n  using assms\n  apply induct\n   apply (auto simp: istate_def)[]\n  apply(intro conjI)\n  subgoal for trn apply(cases trn, auto simp: T.simps reachNT_reach)[] .\n  by (metis T.elims(3) isChair_isPC reachNT_reach reach.Step tgtOf_simps)\n\n(* important: *) lemma T_\\<phi>_\\<gamma>:\nassumes 1: \"reachNT s\" and 2: \"step s a = (ou,s')\" \"\\<phi> (Trans s a ou s')\"\nshows \"\\<not> \\<gamma> (Trans s a ou s')\"\nusing reachNT_non_isPC_isChair[OF 1] 2 unfolding T.simps \\<phi>_def2\nby (fastforce simp add: uu_defs)\n\nlemma eqExcPID2_eqExcPID:\n\"eqExcPID2 s s1 \\<Longrightarrow> eqExcPID s s1\"\nunfolding eqExcPID_def eqExcPID2_def eeqExcPID_def eeqExcPID2_def eqExcD2 eqExcD by auto\n\n(* major *) lemma eqExcPID_step_out:\nassumes s's1': \"eqExcPID s s1\"\nand step: \"step s a = (ou,s')\" and step1: \"step s1 a = (ou1,s1')\"\nand sT: \"reachNT s\" and s1: \"reach s1\"\nand PID: \"PID \\<in>\\<in> paperIDs s cid\"\nand ph: \"phase s cid = disPH\"\nand UIDs: \"userOfA a \\<in> UIDs\"\nshows \"ou = ou1\"\nproof-\n  note Inv = reachNT_non_isPC_isChair[OF sT UIDs]\n  note eqs = eqExcPID_imp[OF s's1']\n  note eqs' = eqExcPID_imp1[OF s's1']\n  note s = reachNT_reach[OF sT]\n\n  note simps[simp] = c_defs u_defs uu_defs r_defs l_defs Paper_dest_conv eqExcPID_def eeqExcPID_def eqExcD\n  note * = step step1 eqs eqs' s s1 PID UIDs ph paperIDs_equals[OF s] Inv\n\n  show ?thesis\n  proof (cases a)\n    case (Cact x1)\n    then show ?thesis using * by (cases x1) auto\n  next\n    case (Uact x2)\n    then show ?thesis using * by (cases x2) auto\n  next\n    case (UUact x3)\n    then show ?thesis using * by (cases x3) auto\n  next\n    case (Ract x4)\n    show ?thesis\n    proof (cases x4)\n      case (rMyReview x81 x82 x83 x84)\n      then show ?thesis using * Ract by (auto simp add: getNthReview_def)\n    next\n      case (rReviews x91 x92 x93 x94)\n      then show ?thesis using * Ract by (clarsimp; metis eqExcPID_imp2 s's1')\n    next\n      case (rDecs x101 x102 x103 x104)\n      then show ?thesis using * Ract by (clarsimp; metis)\n    next\n      case (rFinalDec x131 x132 x133 x134)\n      then show ?thesis using * Ract by (clarsimp; metis Suc_n_not_le_n)\n    qed (use * Ract in auto)\n  next\n    case (Lact x5)\n    then show ?thesis using * by (cases x5; auto; presburger)\n  qed\nqed\n\n(* major *) lemma eqExcPID2_step_out:\nassumes ss1: \"eqExcPID2 s s1\"\nand step: \"step s a = (ou,s')\" and step1: \"step s1 a = (ou1,s1')\"\nand sT: \"reachNT s\" and s1: \"reach s1\"\nand PID: \"PID \\<in>\\<in> paperIDs s cid\"\nand ph: \"phase s cid \\<ge> disPH\"\nand UIDs: \"userOfA a \\<in> UIDs\"\nand decs_exit: \"decsPaper (paper s PID) \\<noteq> []\" \"decsPaper (paper s1 PID) \\<noteq> []\"\nshows \"ou = ou1\"\nproof-\n  note Inv = reachNT_non_isPC_isChair[OF sT UIDs]\n  note eqs = eqExcPID2_imp[OF ss1]\n  note eqs' = eqExcPID2_imp1[OF ss1]\n  note s = reachNT_reach[OF sT]\n\n  have \"PID \\<in>\\<in> paperIDs s1 cid\" using PID ss1 unfolding eqExcPID2_def by auto\n  hence decs_exit': \"decsPaper (paper s' PID) \\<noteq> []\" \"decsPaper (paper s1' PID) \\<noteq> []\"\n  using nonempty_decsPaper_persist s s1 PID decs_exit step step1 by metis+\n\n  note simps[simp] = c_defs u_defs uu_defs r_defs l_defs Paper_dest_conv eqExcPID2_def eeqExcPID2_def eqExcD2\n  note * = step step1 eqs eqs' s s1 PID UIDs ph paperIDs_equals[OF s] Inv\n\n  show ?thesis\n  proof (cases a)\n    case (Cact x1)\n    then show ?thesis using * by (cases x1) auto\n  next\n    case (Uact x2)\n    then show ?thesis using * by (cases x2) auto\n  next\n    case (UUact x3)\n    then show ?thesis using * by (cases x3) auto\n  next\n    case (Ract x4)\n    show ?thesis\n    proof (cases x4)\n      case (rMyReview x81 x82 x83 x84)\n      then show ?thesis using * Ract by (auto simp add: getNthReview_def)\n    next\n      case (rReviews x91 x92 x93 x94)\n      then show ?thesis using * Ract by (clarsimp; metis eqExcPID2_imp2 ss1)\n    next\n      case (rDecs x101 x102 x103 x104)\n      then show ?thesis using * Ract by (clarsimp; metis)\n    next\n      case (rFinalDec x131 x132 x133 x134)\n      then show ?thesis using * Ract by (clarsimp; metis decs_exit' list.sel(1) list.simps(5) neq_Nil_conv)\n    qed (use * Ract in auto)\n  next\n    case (Lact x5)\n    then show ?thesis using * by (cases x5; auto; presburger)\n  qed\nqed\n\nlemma eqExcPID_step_eqExcPID2:\nassumes a: \"a = UUact (uuDec cid uid p PID dec)\"\nand ss1: \"eqExcPID s s1\"\nand step: \"step s a = (outOK,s')\" and step1: \"step s1 a = (outOK,s1')\"\nand s: \"reach s\" \"reach s1\" and PID: \"PID \\<in>\\<in> paperIDs s cid\" and ph: \"phase s cid < notifPH\"\nshows \"eqExcPID2 s' s1'\"\nproof-\n  have \"eqExcPID s' s1'\" using assms by (metis eqExcPID_step)\n  moreover have \"hd (decsPaper (paper s' PID)) = hd (decsPaper (paper s1' PID))\"\n    using step step1 unfolding a\n    apply(simp add: uu_defs)\n    by (metis decsPaper.simps fun_upd_same list.sel(1) select_convs(8) surjective update_convs(8))\n  ultimately show ?thesis\n    unfolding eqExcPID_def eqExcPID2_def eeqExcPID_def eeqExcPID2_def eqExcD2 eqExcD by auto\nqed\n\n(* major *) lemma eqExcPID_step_\\<phi>_eqExcPID2:\nassumes ss1: \"eqExcPID s s1\"\nand step: \"step s a = (ou,s')\" and step1: \"step s1 a = (ou1,s1')\"\nand \\<phi>: \"\\<phi> (Trans s a ou s')\"\nand s: \"reach s\" \"reach s1\" and PID: \"PID \\<in>\\<in> paperIDs s cid\" and ph: \"phase s cid \\<le> disPH\"\nshows \"eqExcPID2 s' s1'\"\nproof-\n  obtain cid1 uid p dec where a: \"a = UUact (uuDec cid1 uid p PID dec)\" and ou: \"ou = outOK\"\n  using \\<phi> unfolding \\<phi>_def2 by auto\n  have PID1: \"PID \\<in>\\<in> paperIDs s cid1\" using step unfolding a ou by (auto simp: uu_defs)\n  hence cid1: \"cid1 = cid\" using paperIDs_equals[OF s(1) PID] by auto\n  have \\<phi>1: \"\\<phi> (Trans s1 a ou1 s1')\" using \\<phi> ss1 by (metis eqExcPID_step_\\<phi>_imp step step1)\n  hence ou1: \"ou1 = outOK\" using \\<phi> unfolding \\<phi>_def2 by auto\n  show ?thesis\n  using eqExcPID_step_eqExcPID2[OF a ss1 step[unfolded ou] step1[unfolded ou1] s]\n  PID ph unfolding cid1 by auto\nqed\n\ndefinition \\<Delta>1 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>1 s vl s1 vl1 \\<equiv>\n (\\<forall> cid. PID \\<in>\\<in> paperIDs s cid \\<longrightarrow> phase s cid < disPH) \\<and>\n s = s1 \\<and> B vl vl1\"\n(* \"Critical phase not yet reached: either PID not yet registered\n    or the phase of its conference not yet submission  \" *)\n\ndefinition \\<Delta>2 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>2 s vl s1 vl1 \\<equiv>\n \\<exists> cid uid.\n   PID \\<in>\\<in> paperIDs s cid \\<and> phase s cid = disPH \\<and>\n   isChair s cid uid \\<and> pref s uid PID \\<noteq> Conflict \\<and>\n   eqExcPID s s1 \\<and> B vl vl1\"\n(* \"PID registered to a conference which is in the discussion phase, values not completely flushed,\n    state equality only up to the decision for PID which is a singleton list;\n    assumption that there exists at least a non-conflict chair of the conference\n    (the situation when no such chair exists is covered by \\<Delta>e,\n    since then vl cannot be flushed)\" *)\n\ndefinition \\<Delta>3 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>3 s vl s1 vl1 \\<equiv>\n \\<exists> cid.\n   PID \\<in>\\<in> paperIDs s cid \\<and> phase s cid \\<ge> disPH \\<and>\n   decsPaper (paper s PID) \\<noteq> [] \\<and> decsPaper (paper s1 PID) \\<noteq> [] \\<and> eqExcPID2 s s1 \\<and>\n   vl = [] \\<and> vl1 = []\"\n(* \"During or after discussion, values flushed,\n    state equality a bit tighter: up to the tail of the decision list (so strict equality on the head,\n    which is the only thing a potential author may see);\n    the list of decisions also have to be nonempty in order\n    for eqExcPID2 to be preserved by transitions\" *)\n\ndefinition \\<Delta>e :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>e s vl s1 vl1 \\<equiv>\n vl \\<noteq> [] \\<and>\n ((\\<exists> cid. PID \\<in>\\<in> paperIDs s cid \\<and> phase s cid > disPH)\n  \\<or>\n  (\\<exists> cid. PID \\<in>\\<in> paperIDs s cid \\<and> phase s cid \\<ge> disPH \\<and>\n          \\<not> (\\<exists> uid. isChair s cid uid \\<and> pref s uid PID \\<noteq> Conflict))\n )\"\n\nlemma istate_\\<Delta>1:\nassumes B: \"B vl vl1\"\nshows \"\\<Delta>1 istate vl istate vl1\"\nusing B unfolding \\<Delta>1_def B_def istate_def by auto\n\nlemma unwind_cont_\\<Delta>1: \"unwind_cont \\<Delta>1 {\\<Delta>1,\\<Delta>2,\\<Delta>e}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>1 s vl s1 vl1 \\<or> \\<Delta>2 s vl s1 vl1 \\<or> \\<Delta>e s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \"\\<Delta>1 s vl s1 vl1\"\n  hence rs: \"reach s\" and ss1: \"s1 = s\"\n  and vl: \"vl \\<noteq> []\" and vl1: \"vl1 \\<noteq> []\" and vl_vl1: \"last vl1 = last vl\"\n  and ph_PID: \"\\<And> cid. PID \\<in>\\<in> paperIDs s cid \\<Longrightarrow> phase s cid < disPH\"\n  using reachNT_reach unfolding \\<Delta>1_def B_def by auto\n  note vlvl1 = vl vl1 vl_vl1\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof-\n    have ?react proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\"  let ?trn1 = \"Trans s1 a ou s'\"\n      assume step: \"step s a = (ou, s')\" and T: \"\\<not> T ?trn\" and c: \"consume ?trn vl vl'\"\n      have \\<phi>: \"\\<not> \\<phi> ?trn\"\n      proof (cases a)\n        case (UUact x3)\n        then show ?thesis\n          using step ph_PID\n          by (cases x3; fastforce simp: uu_defs)\n      qed auto\n      hence vl': \"vl' = vl\" using c unfolding consume_def by auto\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n      proof-\n        have ?match proof\n          show \"validTrans ?trn1\" unfolding ss1 using step by simp\n        next\n          show \"consume ?trn1 vl1 vl1\" unfolding consume_def ss1 using \\<phi> by auto\n        next\n          show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n        next\n          assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\" unfolding ss1 by simp\n        next\n          show \"?\\<Delta> s' vl' s' vl1\"\n          proof(cases \"\\<exists> cid. PID \\<in>\\<in> paperIDs s cid\")\n            case False note PID = False\n            have ph_PID': \"\\<And> cid. PID \\<in>\\<in> paperIDs s' cid \\<Longrightarrow> phase s' cid < disPH\" using PID step rs\n            apply(cases a)\n              subgoal for _ x1 apply(cases x1) apply(fastforce simp: c_defs)+ .\n              subgoal for _ x2 apply(cases x2) apply(fastforce simp: u_defs)+ .\n              subgoal for _ x3 apply(cases x3) apply(fastforce simp: uu_defs)+ .\n              by auto\n            hence \"\\<Delta>1 s' vl' s' vl1\" unfolding \\<Delta>1_def B_def vl' using ph_PID' vlvl1 by auto\n            thus ?thesis by auto\n          next\n            case True\n            then obtain CID where PID: \"PID \\<in>\\<in> paperIDs s CID\" by auto\n            hence ph: \"phase s CID < disPH\" using ph_PID by auto\n            have PID': \"PID \\<in>\\<in> paperIDs s' CID\" by (metis PID paperIDs_mono step)\n            show ?thesis\n            proof(cases \"phase s' CID < disPH\")\n              case True note ph' = True\n              hence \"\\<Delta>1 s' vl' s' vl1\" unfolding \\<Delta>1_def B_def vl' using vlvl1 ph' PID'\n                by (auto; metis reach_PairI paperIDs_equals rs step)\n              thus ?thesis by auto\n            next\n              case False note ph' = False\n              hence ph': \"phase s' CID = disPH\" using ph PID step rs\n              apply(cases a)\n                subgoal for x1 apply(cases x1) apply(fastforce simp: c_defs)+ .\n                subgoal for x2 apply(cases x2) apply(fastforce simp: u_defs)+ .\n                subgoal for x3 apply(cases x3) apply(fastforce simp: uu_defs)+ .\n              by auto\n              show ?thesis\n              proof(cases \"\\<exists>uid. isChair s' CID uid \\<and> pref s' uid PID \\<noteq> Conflict\")\n                case True\n                hence \"\\<Delta>2 s' vl' s' vl1\" unfolding \\<Delta>2_def B_def vl' using vlvl1 ph' PID' by auto\n                thus ?thesis by auto\n              next\n                case False\n                hence \"\\<Delta>e s' vl' s' vl1\" unfolding \\<Delta>e_def vl' using vlvl1 ph' PID' by auto\n                thus ?thesis by auto\n              qed\n            qed\n          qed\n        qed\n        thus ?thesis by simp\n      qed\n    qed\n    thus ?thesis using vl by auto\n  qed\nqed\n\nlemma unwind_cont_\\<Delta>2: \"unwind_cont \\<Delta>2 {\\<Delta>2,\\<Delta>3,\\<Delta>e}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>2 s vl s1 vl1 \\<or> \\<Delta>3 s vl s1 vl1 \\<or> \\<Delta>e s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \"\\<Delta>2 s vl s1 vl1\"\n  then obtain CID uid where uid: \"isChair s CID uid\" \"pref s uid PID \\<noteq> Conflict\"\n  and rs: \"reach s\" and ph: \"phase s CID = disPH\" (is \"?ph = _\")\n  and PID: \"PID \\<in>\\<in> paperIDs s CID\" and ss1: \"eqExcPID s s1\"\n  and vl: \"vl \\<noteq> []\" and vl1: \"vl1 \\<noteq> []\" and vl_vl1: \"last vl = last vl1\"\n  using reachNT_reach unfolding \\<Delta>2_def B_def by auto\n  note vlvl1 = vl vl1 vl_vl1\n  from vl vl1 obtain v vl' v1 vl1' where vl: \"vl = v # vl'\" and vl1: \"vl1 = v1 # vl1'\" by (metis list.exhaust)\n  have uid_notin: \"uid \\<notin> UIDs\"\n  using ph uid reachNT_non_isPC_isChair[OF rsT] PID by fastforce\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof(cases \"vl1' = []\")\n    case False note vl1' = False\n    hence vl_vl1': \"last vl = last vl1'\" using vl_vl1 unfolding vl1 by simp\n    have uid1: \"isChair s1 CID uid\" \"pref s1 uid PID \\<noteq> Conflict\" using ss1 uid unfolding eqExcPID_def by auto\n    define a1 where \"a1 \\<equiv> UUact (uuDec CID uid (pass s uid) PID v1)\"\n    obtain s1' ou1 where step1: \"step s1 a1 = (ou1,s1')\" by (metis prod.exhaust)\n    let ?trn1 = \"Trans s1 a1 ou1 s1'\"\n    have s1s1': \"eqExcPID s1 s1'\" using a1_def step1 UUact_uuDec_step_eqExcPID by auto\n    have ss1': \"eqExcPID s s1'\" using eqExcPID_trans[OF ss1 s1s1'] .\n    hence many_s1': \"PID \\<in>\\<in> paperIDs s1' CID\" \"isChair s1' CID uid\"\n    \"pref s1' uid PID \\<noteq> Conflict\" \"phase s1' CID = disPH\"\n    \"pass s1' uid = pass s uid\"\n    using uid PID ph unfolding eqExcPID_def by auto\n    hence more_s1': \"uid \\<in>\\<in> userIDs s1'\" \"CID \\<in>\\<in> confIDs s1'\"\n    by (metis paperIDs_confIDs reach_PairI roles_userIDs rs1 step1 many_s1'(1))+\n    have f: \"f ?trn1 = v1\" unfolding a1_def by simp\n    have rs1': \"reach s1'\" using rs1 step1 by (auto intro: reach_PairI)\n    have ou1: \"ou1 = outOK\"\n    using step1 uid1 ph unfolding a1_def by (auto simp add: uu_defs many_s1' more_s1')\n    have ?iact proof\n      show \"step s1 a1 = (ou1,s1')\" by fact\n    next\n      show \\<phi>: \"\\<phi> ?trn1\" using ou1 unfolding a1_def by simp\n      thus \"consume ?trn1 vl1 vl1'\" using f unfolding consume_def vl1 by simp\n    next\n      show \"\\<not> \\<gamma> ?trn1\" by (simp add: a1_def uid_notin)\n    next\n      have \"\\<Delta>2 s vl s1' vl1'\" unfolding \\<Delta>2_def B_def using ph PID ss1' uid vl_vl1' vl1' vl by auto\n      thus \"?\\<Delta> s vl s1' vl1'\" by simp\n    qed\n    thus ?thesis by auto\n  next\n    case True hence vl1: \"vl1 = [v1]\" unfolding vl1 by simp\n    have ?react proof\n      fix a :: act and ou :: out and s' :: state and vll'\n      let ?trn = \"Trans s a ou s'\"\n      let ?ph' = \"phase s' CID\"\n      assume step: \"step s a = (ou, s')\" and T: \"\\<not> T ?trn\" and c: \"consume ?trn vl vll'\"\n      have PID': \"PID \\<in>\\<in> paperIDs s' CID\" using PID rs by (metis paperIDs_mono step)\n      have uid': \"isChair s' CID uid \\<and> pref s' uid PID \\<noteq> Conflict\"\n      using uid step rs ph PID pref_Conflict_disPH isChair_persistent by auto\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vll' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vll'\" (is \"?match \\<or> ?ignore\")\n      proof(cases \"\\<phi> ?trn\")\n        case False note \\<phi> = False\n        have vll': \"vll' = vl\" using c \\<phi> unfolding consume_def by (cases vl) auto\n        obtain ou1 and s1' where step1: \"step s1 a = (ou1,s1')\" by (metis prod.exhaust)\n        let ?trn1 = \"Trans s1 a ou1 s1'\"\n        have s's1': \"eqExcPID s' s1'\" using eqExcPID_step[OF ss1 step] step1 rs rs1 PID ph by auto\n        have \\<phi>1: \"\\<not> \\<phi> ?trn1\" using \\<phi> unfolding eqExcPID_step_\\<phi>[OF ss1 step step1] .\n        have ?match proof\n          show \"validTrans ?trn1\" using step1 by simp\n        next\n          show \"consume ?trn1 vl1 vl1\" unfolding consume_def using \\<phi>1 by auto\n        next\n          show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n        next\n          assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\"\n          using eqExcPID_step_out[OF ss1 step step1 rsT rs1 PID ph] by simp\n (* note that in this setting eqExcPID_step_out needs the additional phase assumption *)\n        next\n          show \"?\\<Delta> s' vll' s1' vl1\"\n          proof(cases \"?ph' = disPH\")\n            case True\n            hence \"\\<Delta>2 s' vll' s1' vl1\" using PID' s's1' uid' vlvl1 unfolding \\<Delta>2_def B_def vll' by auto\n            thus ?thesis by auto\n          next\n            case False hence \"?ph' > disPH\" using ph rs step by (metis le_less phase_increases)\n            hence \"\\<Delta>e s' vll' s1' vl1\" unfolding \\<Delta>e_def vll' using vlvl1 PID' by auto\n            thus ?thesis by auto\n          qed\n        qed\n        thus ?thesis by simp\n      next\n        case True note \\<phi> = True\n        hence vll': \"vll' = vl'\" using c unfolding vl consume_def by simp\n        obtain cid uid p where a: \"a = UUact (uuDec cid uid p PID v)\" and ou: \"ou = outOK\"\n        using \\<phi> c PID unfolding vl consume_def \\<phi>_def2 vll' by fastforce\n        (* hence cid: \"cid = CID\" using step PID rs by (auto simp add: uu_defs paperIDs_equals) *)\n        hence \\<gamma>: \"\\<not> \\<gamma> ?trn\" using step T rsT by (metis T_\\<phi>_\\<gamma> True)\n        hence f: \"f ?trn = v\" using c \\<phi> unfolding consume_def vl by auto\n        have s's: \"eqExcPID s' s\" using eqExcPID_sym[OF \\<phi>_step_eqExcPID[OF \\<phi> step]] .\n        have s's1: \"eqExcPID s' s1\" using eqExcPID_trans[OF s's ss1] .\n        have ph': \"phase s' CID = disPH\" using s's ph unfolding eqExcPID_def by auto\n        show ?thesis\n        proof(cases \"vl' = []\")\n          case False note vl' = False\n          hence vl'_vl1: \"last vl' = last vl1\" using vl_vl1 unfolding vl by auto\n          have ?ignore proof\n            show \"\\<not> \\<gamma> ?trn\" by fact\n          next\n            show \"?\\<Delta> s' vll' s1 vl1\"\n            proof(cases \"?ph' = disPH\")\n              case True\n              hence \"\\<Delta>2 s' vll' s1 vl1\" using s's1 PID' uid' vl' vl1 vl_vl1 unfolding \\<Delta>2_def B_def vl vll' by auto\n              thus ?thesis by auto\n            next\n              case False hence \"?ph' > disPH\" using ph rs step by (metis le_less phase_increases)\n              hence \"\\<Delta>e s' vll' s1 vl1\" unfolding \\<Delta>e_def vll' using vlvl1 vl' PID' by auto\n              thus ?thesis by auto\n            qed\n          qed\n          thus ?thesis by auto\n        next\n          case True note vl' = True hence vl: \"vl = [v]\" unfolding vl by simp\n(* the transition to \\<Delta>3: \\<phi> holds and both vl and vl1 are singletons: *)\n          hence v1v: \"v1 = v\" using vl_vl1 unfolding vl1 by simp\n          obtain s1' ou1 where step1: \"step s1 a = (ou1,s1')\" by (metis prod.exhaust)\n          let ?trn1 = \"Trans s1 a ou1 s1'\"\n          have \\<phi>1: \"\\<phi> ?trn1\" using eqExcPID_step_\\<phi>_imp[OF ss1 step step1 \\<phi>] .\n          hence ou1: \"ou1 = outOK\" unfolding \\<phi>_def2 by auto\n          have ?match proof\n          show \"validTrans ?trn1\" using step1 by simp\n        next\n          show \"consume ?trn1 vl1 []\" unfolding consume_def using \\<phi>1 by (simp add: a vl1 v1v)\n        next\n          show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n        next\n          assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\"\n          using eqExcPID_step_out[OF ss1 step step1 rsT rs1 PID ph] by simp\n        next\n          have \"\\<Delta>3 s' vll' s1' []\" unfolding vll' vl' \\<Delta>3_def\n          using PID' ph' eqExcPID_step_\\<phi>_eqExcPID2[OF ss1 step step1 \\<phi> rs rs1 PID] ph\n          using step step1 unfolding a by (auto simp: uu_defs ou ou1)\n          thus \"?\\<Delta> s' vll' s1' []\" by simp\n        qed\n        thus ?thesis by simp\n        qed\n      qed\n    qed\n    thus ?thesis using vl by auto\n  qed\nqed\n\nlemma unwind_cont_\\<Delta>3: \"unwind_cont \\<Delta>3 {\\<Delta>3,\\<Delta>e}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>3 s vl s1 vl1 \\<or> \\<Delta>e s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \"\\<Delta>3 s vl s1 vl1\"\n  then obtain CID where rs: \"reach s\" and ph: \"phase s CID \\<ge> disPH\" (is \"?ph \\<ge> _\")\n  and PID: \"PID \\<in>\\<in> paperIDs s CID\"\n  and decs: \"decsPaper (paper s PID) \\<noteq> []\"  \"decsPaper (paper s1 PID) \\<noteq> []\"\n  and ss1: \"eqExcPID2 s s1\" and vl: \"vl = []\" and vl1: \"vl1 = []\"\n  using reachNT_reach unfolding \\<Delta>3_def by auto\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof-\n    have \"?react\"\n    proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\"\n      let ?ph' = \"phase s' CID\"\n      assume step: \"step s a = (ou, s')\" and T: \"\\<not> T ?trn\" and c: \"consume ?trn vl vl'\"\n      have PID': \"PID \\<in>\\<in> paperIDs s' CID\" using PID rs by (metis paperIDs_mono step)\n      have ph': \"phase s' CID \\<ge> disPH\" using ph rs step by (meson dual_order.trans phase_increases)\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n      proof-\n        have \\<phi>: \"\\<not> \\<phi> ?trn\" and vl': \"vl' = []\" using c unfolding consume_def vl by auto\n        obtain ou1 and s1' where step1: \"step s1 a = (ou1,s1')\" by (metis prod.exhaust)\n        let ?trn1 = \"Trans s1 a ou1 s1'\"\n        have s's1': \"eqExcPID2 s' s1'\" using eqExcPID2_step[OF ss1 step step1] .\n        have \\<phi>1: \"\\<not> \\<phi> ?trn1\" using \\<phi> unfolding eqExcPID2_step_\\<phi>[OF ss1 step step1] .\n        have PID1: \"PID \\<in>\\<in> paperIDs s1 CID\" using PID ss1 unfolding eqExcPID2_def by auto\n        have decs': \"decsPaper (paper s' PID) \\<noteq> []\"  \"decsPaper (paper s1' PID) \\<noteq> []\"\n        by (metis PID PID1 decs nonempty_decsPaper_persist rs step rs1 step1)+\n        have ?match proof\n          show \"validTrans ?trn1\" using step1 by simp\n        next\n          show \"consume ?trn1 vl1 vl1\" unfolding consume_def using \\<phi>1 by auto\n        next\n          show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n        next\n          assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\"\n          using eqExcPID2_step_out[OF ss1 step step1 rsT rs1 PID ph _ decs] by simp\n        next\n          have \"\\<Delta>3 s' vl' s1' vl1\" using ph' PID' s's1' unfolding \\<Delta>3_def vl1 vl' by (auto simp: decs')\n          thus \"?\\<Delta> s' vl' s1' vl1\" by simp\n        qed\n        thus ?thesis by simp\n      qed\n    qed\n    thus ?thesis using vl1 by simp\n  qed\nqed\n\n(* Exit arguments: *)\ndefinition K1exit where\n\"K1exit cid s \\<equiv>\n phase s cid \\<ge> disPH \\<and> PID \\<in>\\<in> paperIDs s cid \\<and> \\<not> (\\<exists> uid. isChair s cid uid \\<and> pref s uid PID \\<noteq> Conflict)\"\n\nlemma invarNT_K1exit: \"invarNT (K1exit cid)\"\nunfolding invarNT_def apply (safe dest!: reachNT_reach)\n  subgoal for _ a apply(cases a)\n    subgoal for x1 apply(cases x1)\n      apply (fastforce simp add: c_defs K1exit_def geq_noPH_confIDs)+ .\n    subgoal for x2 apply(cases x2)\n            apply (fastforce simp add: u_defs K1exit_def paperIDs_equals)\n           apply (fastforce simp add: u_defs K1exit_def paperIDs_equals)\n          apply (fastforce simp add: u_defs K1exit_def paperIDs_equals)\n         apply (fastforce simp add: u_defs K1exit_def paperIDs_equals)\n        apply (fastforce simp add: u_defs K1exit_def paperIDs_equals)\n      subgoal for x61 apply(cases \"x61 = cid\")\n         apply (fastforce simp add: u_defs K1exit_def paperIDs_equals)+ .\n      apply (fastforce simp add: u_defs K1exit_def paperIDs_equals) .\n    subgoal for x3 apply(cases x3) apply (fastforce simp add: uu_defs K1exit_def)+ .\n    apply (fastforce simp add: uu_defs K1exit_def)+ .\ndone\n\nlemma noVal_K1exit: \"noVal (K1exit cid) v\"\napply(rule no\\<phi>_noVal)\nunfolding no\\<phi>_def apply safe\n  subgoal for _ a apply(cases a)\n        apply (fastforce simp add: c_defs K1exit_def)\n       apply (fastforce simp add: c_defs K1exit_def)\n    subgoal for x3 apply(cases x3) apply (auto simp add: uu_defs K1exit_def)\n      apply (metis paperIDs_equals reachNT_reach) (* safety used *) .\n    by auto\ndone\n\ndefinition K2exit where\n\"K2exit cid s \\<equiv> PID \\<in>\\<in> paperIDs s cid \\<and> phase s cid > disPH\"\n\nlemma invarNT_K2exit: \"invarNT (K2exit cid)\"\nunfolding invarNT_def apply (safe dest!: reachNT_reach)\n  subgoal for _ a apply(cases a)\n    subgoal for x1 apply(cases x1)\n      apply (fastforce simp add: c_defs K2exit_def geq_noPH_confIDs)+ .\n    subgoal for x2 apply(cases x2)\n      apply (fastforce simp add: u_defs K2exit_def paperIDs_equals)+ .\n    subgoal for x3 apply(cases x3) apply (fastforce simp add: uu_defs K2exit_def)+ .\n    apply (fastforce simp add: uu_defs K2exit_def)+ .\ndone\n\nlemma noVal_K2exit: \"noVal (K2exit cid) v\"\napply(rule no\\<phi>_noVal)\nunfolding no\\<phi>_def apply safe\n  subgoal for _ a apply(cases a)\n        apply (fastforce simp add: c_defs K2exit_def)\n       apply (fastforce simp add: c_defs K2exit_def)\n    subgoal for x3 apply(cases x3) apply (auto simp add: uu_defs K2exit_def)\n      using paperIDs_equals reachNT_reach apply fastforce (* safety used *) .\n  by auto\ndone\n\nlemma unwind_exit_\\<Delta>e: \"unwind_exit \\<Delta>e\"\nproof\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \\<Delta>e: \"\\<Delta>e s vl s1 vl1\"\n  hence vl: \"vl \\<noteq> []\" using reachNT_reach unfolding \\<Delta>e_def by auto\n  then obtain CID where \"K1exit CID s \\<or> K2exit CID s\" using \\<Delta>e unfolding K1exit_def K2exit_def \\<Delta>e_def by auto\n  thus \"vl \\<noteq> [] \\<and> exit s (hd vl)\" apply(simp add: vl)\n  by (metis rsT exitI2 invarNT_K1exit noVal_K1exit invarNT_K2exit noVal_K2exit)\nqed\n\ntheorem secure: secure\napply(rule unwind_decomp3_secure[of \\<Delta>1 \\<Delta>2 \\<Delta>e \\<Delta>3])\nusing\nistate_\\<Delta>1\nunwind_cont_\\<Delta>1 unwind_cont_\\<Delta>2 unwind_cont_\\<Delta>3\nunwind_exit_\\<Delta>e\nby auto\n\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/CoCon/Decision_Confidentiality/Decision_NCPC.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526368038304, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.26271162730193276}}
{"text": "(*******************************************************************************\n\n  Project: Development of Security Protocols by Refinement\n\n  Module:  Key_establish/m3_ds.thy (Isabelle/HOL 2016-1)\n  ID:      $Id: m3_ds.thy 132890 2016-12-24 10:25:57Z csprenge $\n  Authors: Christoph Sprenger, ETH Zurich <sprenger@inf.ethz.ch>\n           Ivano Somaini, ETH Zurich <somainii@student.ethz.ch>\n\n  Key distribution protocols\n  Level 3: Denning-Sacco protocol\n\n  Copyright (c) 2009-2016 Christoph Sprenger, Ivano Somaini\n  Licence: LGPL\n\n*******************************************************************************)\n\nsection \\<open>Denning-Sacco protocol (L3)\\<close>\n\ntheory m3_ds imports m2_ds \"../Refinement/Message\"\nbegin\n\ntext \\<open>\nWe model the Denning-Sacco protocol:\n\\[\n\\begin{array}{lll}\n  \\mathrm{M1.} & A \\rightarrow S: & A, B \\\\ \n  \\mathrm{M2.} & S \\rightarrow A: & \\{Kab, B, Ts, Na, \\{Kab, A, Ts\\}_{Kbs} \\}_{Kas} \\\\\n  \\mathrm{M3.} & A \\rightarrow B: & \\{Kab, A, Ts\\}_{Kbs}\n\\end{array}\n\\]\n\\<close>\n\ntext \\<open>Proof tool configuration. Avoid annoying automatic unfolding of\n\\<open>dom\\<close>.\\<close>\n\ndeclare domIff [simp, iff del]\n\n\n(******************************************************************************)\nsubsection \\<open>Setup\\<close>\n(******************************************************************************)\n\ntext \\<open>Now we can define the initial key knowledge.\\<close>\n\noverloading ltkeySetup' \\<equiv> ltkeySetup begin\ndefinition ltkeySetup_def: \"ltkeySetup' \\<equiv> {(sharK C, A) | C A. A = C \\<or> A = Sv}\"\nend\n\nlemma corrKey_shrK_bad [simp]: \"corrKey = shrK`bad\"\nby (auto simp add: keySetup_def ltkeySetup_def corrKey_def)\n\n\n(******************************************************************************)\nsubsection \\<open>State\\<close>\n(******************************************************************************)\n\ntext \\<open>The secure channels are star-shaped to/from the server.  Therefore,\nwe have only one agent in the relation.\\<close>\n\nrecord m3_state = \"m1_state\" +\n  IK :: \"msg set\"                                \\<comment> \\<open>intruder knowledge\\<close>\n\n\ntext \\<open>Observable state:\n@{term \"runs\"}, @{term \"leak\"}, @{term \"clk\"}, and @{term \"cache\"}.\\<close>\n\ntype_synonym\n  m3_obs = \"m2_obs\"\n\ndefinition\n  m3_obs :: \"m3_state \\<Rightarrow> m3_obs\" where\n  \"m3_obs s \\<equiv> \\<lparr> runs = runs s, leak = leak s, clk = clk s \\<rparr>\"\n\ntype_synonym\n  m3_pred = \"m3_state set\"\n\ntype_synonym\n  m3_trans = \"(m3_state \\<times> m3_state) set\"\n\n\n(******************************************************************************)\nsubsection \\<open>Events\\<close>\n(******************************************************************************)\n\ntext \\<open>Protocol events.\\<close>\n\ndefinition     \\<comment> \\<open>by @{term \"A\"}, refines @{term \"m2_step1\"}\\<close>\n  m3_step1 :: \"[rid_t, agent, agent] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step1 Ra A B \\<equiv> {(s, s1).\n    \\<comment> \\<open>guards:\\<close>\n    Ra \\<notin> dom (runs s) \\<and>                                 \\<comment> \\<open>\\<open>Ra\\<close> is fresh\\<close>\n\n    \\<comment> \\<open>actions:\\<close>\n    s1 = s\\<lparr>\n      runs := (runs s)(Ra \\<mapsto> (Init, [A, B], [])),\n      IK := insert \\<lbrace>Agent A, Agent B\\<rbrace> (IK s)        \\<comment> \\<open>send \\<open>M1\\<close>\\<close>\n    \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by @{term \"B\"}, refines @{term \"m2_step2\"}\\<close>\n  m3_step2 :: \"[rid_t, agent, agent] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step2 \\<equiv> m1_step2\"\n\ndefinition     \\<comment> \\<open>by @{text \"Server\"}, refines @{term m2_step3}\\<close>\n  m3_step3 :: \"[rid_t, agent, agent, key, time] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step3 Rs A B Kab Ts \\<equiv> {(s, s1).\n    \\<comment> \\<open>guards:\\<close>\n    Rs \\<notin> dom (runs s) \\<and>                           \\<comment> \\<open>fresh server run\\<close>\n    Kab = sesK (Rs$sk) \\<and>                          \\<comment> \\<open>fresh session key\\<close>\n\n    \\<lbrace>Agent A, Agent B\\<rbrace> \\<in> IK s \\<and>                   \\<comment> \\<open>recv \\<open>M1\\<close>\\<close>\n    Ts = clk s \\<and>                                  \\<comment> \\<open>fresh timestamp\\<close>\n\n    \\<comment> \\<open>actions:\\<close>\n    \\<comment> \\<open>record session key and send \\<open>M2\\<close>\\<close>\n    s1 = s\\<lparr>\n      runs := (runs s)(Rs \\<mapsto> (Serv, [A, B], [aNum Ts])),\n      IK := insert (Crypt (shrK A)                        \\<comment> \\<open>send \\<open>M2\\<close>\\<close>\n                     \\<lbrace>Key Kab, Agent B, Number Ts,\n                        Crypt (shrK B) \\<lbrace>Key Kab, Agent A, Number Ts\\<rbrace>\\<rbrace>)\n                   (IK s)\n    \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by @{term \"A\"}, refines @{term m2_step4}\\<close>\n  m3_step4 :: \"[rid_t, agent, agent, key, time, msg] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step4 Ra A B Kab Ts X \\<equiv> {(s, s1).\n\n     \\<comment> \\<open>guards:\\<close>\n     runs s Ra = Some (Init, [A, B], []) \\<and>           \\<comment> \\<open>key not yet recv'd\\<close>\n\n     Crypt (shrK A)                                  \\<comment> \\<open>recv \\<open>M2\\<close>\\<close>\n       \\<lbrace>Key Kab, Agent B, Number Ts, X\\<rbrace> \\<in> IK s \\<and>\n\n     \\<comment> \\<open>check freshness of session key\\<close>\n     clk s < Ts + Ls \\<and>\n\n     \\<comment> \\<open>actions:\\<close>\n     \\<comment> \\<open>record session key and send \\<open>M3\\<close>\\<close>\n     s1 = s\\<lparr>\n       runs := (runs s)(Ra \\<mapsto> (Init, [A, B], [aKey Kab, aNum Ts])),\n       IK := insert X (IK s)                         \\<comment> \\<open>send \\<open>M3\\<close>\\<close>\n     \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by @{term \"B\"}, refines @{term m2_step5}\\<close>\n  m3_step5 :: \"[rid_t, agent, agent, key, time] \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_step5 Rb A B Kab Ts \\<equiv> {(s, s1).\n     \\<comment> \\<open>guards:\\<close>\n     runs s Rb = Some (Resp, [A, B], []) \\<and>             \\<comment> \\<open>key not yet recv'd\\<close>\n\n     Crypt (shrK B) \\<lbrace>Key Kab, Agent A, Number Ts\\<rbrace> \\<in> IK s \\<and>    \\<comment> \\<open>recv \\<open>M3\\<close>\\<close>\n\n     \\<comment> \\<open>ensure freshness of session key; replays with fresh authenticator ok!\\<close>\n     clk s < Ts + Ls \\<and>\n\n     \\<comment> \\<open>actions:\\<close>\n     \\<comment> \\<open>record session key\\<close>\n     s1 = s\\<lparr>\n       runs := (runs s)(Rb \\<mapsto> (Resp, [A, B], [aKey Kab, aNum Ts]))\n     \\<rparr>\n  }\"\n\n\ntext \\<open>Clock tick event\\<close>\n\ndefinition   \\<comment> \\<open>refines @{term \"m2_tick\"}\\<close>\n  m3_tick :: \"time \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_tick \\<equiv> m1_tick\"\n\n\ntext \\<open>Session key compromise.\\<close>\n\ndefinition     \\<comment> \\<open>refines @{term m2_leak}\\<close>\n  m3_leak :: \"rid_t \\<Rightarrow> m3_trans\"\nwhere\n  \"m3_leak Rs \\<equiv> {(s, s1).\n    \\<comment> \\<open>guards:\\<close>\n    Rs \\<in> dom (runs s) \\<and>\n    fst (the (runs s Rs)) = Serv \\<and>         \\<comment> \\<open>compromise server run \\<open>Rs\\<close>\\<close>\n\n    \\<comment> \\<open>actions:\\<close>\n    \\<comment> \\<open>record session key as leaked and add it to intruder knowledge\\<close>\n    s1 = s\\<lparr> leak := insert (sesK (Rs$sk)) (leak s),\n            IK := insert (Key (sesK (Rs$sk))) (IK s) \\<rparr>\n  }\"\n\n\ntext \\<open>Intruder fake event. The following \"Dolev-Yao\" event generates all\nintruder-derivable messages.\\<close>\n\ndefinition     \\<comment> \\<open>refines @{term \"m2_fake\"}\\<close>\n  m3_DY_fake :: \"m3_trans\"\nwhere\n  \"m3_DY_fake \\<equiv> {(s, s1).\n\n     \\<comment> \\<open>actions:\\<close>\n     s1 = s\\<lparr> IK := synth (analz (IK s)) \\<rparr>       \\<comment> \\<open>take DY closure\\<close>\n  }\"\n\n\n(******************************************************************************)\nsubsection \\<open>Transition system\\<close>\n(******************************************************************************)\n\ndefinition\n  m3_init :: \"m3_pred\"\nwhere\n  \"m3_init \\<equiv> { \\<lparr>\n     runs = Map.empty,\n     leak = shrK`bad,\n     clk = 0,\n     IK = Key`shrK`bad\n  \\<rparr> }\"\n\ndefinition\n  m3_trans :: \"m3_trans\" where\n  \"m3_trans \\<equiv> (\\<Union>A B Ra Rb Rs Kab Ts T X.\n     m3_step1 Ra A B \\<union>\n     m3_step2 Rb A B \\<union>\n     m3_step3 Rs A B Kab Ts \\<union>\n     m3_step4 Ra A B Kab Ts X \\<union>\n     m3_step5 Rb A B Kab Ts \\<union>\n     m3_tick T \\<union>\n     m3_leak Rs \\<union>\n     m3_DY_fake \\<union>\n     Id\n  )\"\n\ndefinition\n  m3 :: \"(m3_state, m3_obs) spec\" where\n  \"m3 \\<equiv> \\<lparr>\n    init = m3_init,\n    trans = m3_trans,\n    obs = m3_obs\n  \\<rparr>\"\n\nlemmas m3_loc_defs =\n  m3_def m3_init_def m3_trans_def m3_obs_def\n  m3_step1_def m3_step2_def m3_step3_def m3_step4_def m3_step5_def\n  m3_tick_def m3_leak_def m3_DY_fake_def\n\nlemmas m3_defs = m3_loc_defs m2_defs\n\n\n(******************************************************************************)\nsubsection \\<open>Invariants\\<close>\n(******************************************************************************)\n\ntext \\<open>Specialized injection that we can apply more aggressively.\\<close>\n\nlemmas analz_Inj_IK = analz.Inj [where H=\"IK s\" for s]\nlemmas parts_Inj_IK = parts.Inj [where H=\"IK s\" for s]\n\ndeclare parts_Inj_IK [dest!]\n\ndeclare analz_into_parts [dest]\n\n\nsubsubsection \\<open>inv1: Secrecy of pre-distributed shared keys\\<close>\n(******************************************************************************)\n\ndefinition\n  m3_inv1_lkeysec :: \"m3_pred\"\nwhere\n  \"m3_inv1_lkeysec \\<equiv> {s. \\<forall>C.\n     (Key (shrK C) \\<in> parts (IK s) \\<longrightarrow> C \\<in> bad) \\<and>\n     (C \\<in> bad \\<longrightarrow> Key (shrK C) \\<in> IK s)\n  }\"\n\nlemmas m3_inv1_lkeysecI = m3_inv1_lkeysec_def [THEN setc_def_to_intro, rule_format]\nlemmas m3_inv1_lkeysecE [elim] = m3_inv1_lkeysec_def [THEN setc_def_to_elim, rule_format]\nlemmas m3_inv1_lkeysecD = m3_inv1_lkeysec_def [THEN setc_def_to_dest, rule_format]\n\n\ntext \\<open>Invariance proof.\\<close>\n\nlemma PO_m3_inv1_lkeysec_init [iff]:\n  \"init m3 \\<subseteq> m3_inv1_lkeysec\"\nby (auto simp add: m3_defs intro!: m3_inv1_lkeysecI)\n\nlemma PO_m3_inv1_lkeysec_trans [iff]:\n  \"{m3_inv1_lkeysec} trans m3 {> m3_inv1_lkeysec}\"\nby (auto simp add: PO_hoare_defs m3_defs intro!: m3_inv1_lkeysecI)\n   (auto dest!: Body)\n\nlemma PO_m3_inv1_lkeysec [iff]: \"reach m3 \\<subseteq> m3_inv1_lkeysec\"\nby (rule inv_rule_incr) (fast+)\n\n\ntext \\<open>Useful simplifier lemmas\\<close>\n\nlemma m3_inv1_lkeysec_for_parts [simp]:\n  \"\\<lbrakk> s \\<in> m3_inv1_lkeysec \\<rbrakk> \\<Longrightarrow> Key (shrK C) \\<in> parts (IK s) \\<longleftrightarrow> C \\<in> bad\"\nby auto\n\nlemma m3_inv1_lkeysec_for_analz [simp]:\n  \"\\<lbrakk> s \\<in> m3_inv1_lkeysec \\<rbrakk> \\<Longrightarrow> Key (shrK C) \\<in> analz (IK s) \\<longleftrightarrow> C \\<in> bad\"\nby auto\n\n\nsubsubsection \\<open>inv2: Ticket shape for honestly encrypted M2\\<close>\n(******************************************************************************)\n\ndefinition\n  m3_inv2_ticket :: \"m3_pred\"\nwhere\n  \"m3_inv2_ticket \\<equiv> {s. \\<forall>A B T K X.\n     A \\<notin> bad \\<longrightarrow>\n     Crypt (shrK A) \\<lbrace>Key K, Agent B, Number T, X\\<rbrace> \\<in> parts (IK s) \\<longrightarrow>\n       X = Crypt (shrK B) \\<lbrace>Key K, Agent A, Number T\\<rbrace> \\<and> K \\<in> range sesK\n  }\"\n\nlemmas m3_inv2_ticketI = m3_inv2_ticket_def [THEN setc_def_to_intro, rule_format]\nlemmas m3_inv2_ticketE [elim] = m3_inv2_ticket_def [THEN setc_def_to_elim, rule_format]\nlemmas m3_inv2_ticketD = m3_inv2_ticket_def [THEN setc_def_to_dest, rule_format, rotated -1]\n\n\ntext \\<open>Invariance proof.\\<close>\n\nlemma PO_m3_inv2_ticket_init [iff]:\n  \"init m3 \\<subseteq> m3_inv2_ticket\"\nby (auto simp add: m3_defs intro!: m3_inv2_ticketI)\n\nlemma PO_m3_inv2_ticket_trans [iff]:\n  \"{m3_inv2_ticket \\<inter> m3_inv1_lkeysec} trans m3 {> m3_inv2_ticket}\"\napply (auto simp add: PO_hoare_defs m3_defs intro!: m3_inv2_ticketI)\napply (auto dest: m3_inv2_ticketD)\n\\<comment> \\<open>2 subgoals, from step4\\<close>\napply (drule parts_cut, drule Body, auto dest: m3_inv2_ticketD)+\ndone\n\nlemma PO_m3_inv2_ticket [iff]: \"reach m3 \\<subseteq> m3_inv2_ticket\"\nby (rule inv_rule_incr) (auto del: subsetI)\n\n\nsubsubsection \\<open>inv3: Session keys not used to encrypt other session keys\\<close>\n(******************************************************************************)\n\ntext \\<open>Session keys are not used to encrypt other keys. Proof requires\ngeneralization to sets of session keys.\\<close>\n\ndefinition\n  m3_inv3_sesK_compr :: \"m3_pred\"\nwhere\n  \"m3_inv3_sesK_compr \\<equiv> {s. \\<forall>K KK.\n     KK \\<subseteq> range sesK \\<longrightarrow>\n     (Key K \\<in> analz (Key`KK \\<union> (IK s))) = (K \\<in> KK \\<or> Key K \\<in> analz (IK s))\n  }\"\n\nlemmas m3_inv3_sesK_comprI = m3_inv3_sesK_compr_def [THEN setc_def_to_intro, rule_format]\nlemmas m3_inv3_sesK_comprE = m3_inv3_sesK_compr_def [THEN setc_def_to_elim, rule_format]\nlemmas m3_inv3_sesK_comprD = m3_inv3_sesK_compr_def [THEN setc_def_to_dest, rule_format]\n\ntext \\<open>Additional lemma\\<close>\nlemmas insert_commute_Key = insert_commute [where x=\"Key K\" for K]\n\nlemmas m3_inv3_sesK_compr_simps =\n  m3_inv3_sesK_comprD\n  m3_inv3_sesK_comprD [where KK=\"{Kab}\" for Kab, simplified]\n  m3_inv3_sesK_comprD [where KK=\"insert Kab KK\" for Kab KK, simplified]\n  insert_commute_Key    \\<comment> \\<open>to get the keys to the front\\<close>\n\n\ntext \\<open>Invariance proof.\\<close>\n\nlemma PO_m3_inv3_sesK_compr_step4:\n  \"{m3_inv3_sesK_compr \\<inter> m3_inv2_ticket \\<inter> m3_inv1_lkeysec}\n      m3_step4 Ra A B Kab Ts X\n   {> m3_inv3_sesK_compr}\"\nproof -\n  { fix K KK s\n    assume H:\n      \"s \\<in> m3_inv1_lkeysec\" \"s \\<in> m3_inv3_sesK_compr\" \"s \\<in> m3_inv2_ticket\"\n      \"runs s Ra = Some (Init, [A, B], [])\"\n      \"KK \\<subseteq> range sesK\"\n      \"Crypt (shrK A) \\<lbrace>Key Kab, Agent B, Number Ts, X\\<rbrace> \\<in> analz (IK s)\"\n    have\n      \"(Key K \\<in> analz (insert X (Key ` KK \\<union> IK s))) =\n          (K \\<in> KK \\<or> Key K \\<in> analz (insert X (IK s)))\"\n    proof (cases \"A \\<in> bad\")\n      case True show ?thesis\n      proof -\n        note H\n      moreover\n        with \\<open>A \\<in> bad\\<close> have \"X \\<in> analz (IK s)\"\n        by (auto dest!: Decrypt)\n      moreover\n        hence \"X \\<in> analz (Key ` KK \\<union> IK s)\"\n        by (auto intro: analz_mono [THEN [2] rev_subsetD])\n      ultimately\n        show ?thesis\n        by (auto simp add: m3_inv3_sesK_compr_simps analz_insert_eq)\n      qed\n    next\n      case False thus ?thesis using H\n      by (fastforce simp add: m3_inv3_sesK_compr_simps dest!: m3_inv2_ticketD [OF analz_into_parts])\n    qed\n  }\n  thus ?thesis\n  by (auto simp add: PO_hoare_defs m3_defs intro!: m3_inv3_sesK_comprI dest!: analz_Inj_IK)\nqed\n\n\ntext \\<open>All together now.\\<close>\n\nlemmas PO_m3_inv3_sesK_compr_trans_lemmas =\n  PO_m3_inv3_sesK_compr_step4\n\nlemma PO_m3_inv3_sesK_compr_init [iff]:\n  \"init m3 \\<subseteq> m3_inv3_sesK_compr\"\nby (auto simp add: m3_defs intro!: m3_inv3_sesK_comprI)\n\nlemma PO_m3_inv3_sesK_compr_trans [iff]:\n  \"{m3_inv3_sesK_compr \\<inter> m3_inv2_ticket \\<inter> m3_inv1_lkeysec}\n     trans m3\n   {> m3_inv3_sesK_compr}\"\nby (auto simp add: m3_def m3_trans_def intro!: PO_m3_inv3_sesK_compr_trans_lemmas)\n   (auto simp add: PO_hoare_defs m3_defs m3_inv3_sesK_compr_simps intro!: m3_inv3_sesK_comprI)\n\n\n\n\n(******************************************************************************)\nsubsection \\<open>Refinement\\<close>\n(******************************************************************************)\n\nsubsubsection \\<open>Message abstraction and simulation relation\\<close>\n(******************************************************************************)\n\ntext \\<open>Abstraction function on sets of messages.\\<close>\n\ninductive_set\n  abs_msg :: \"msg set \\<Rightarrow> chmsg set\"\n  for H :: \"msg set\"\nwhere\n  am_M1:\n    \"\\<lbrace>Agent A, Agent B\\<rbrace> \\<in> H\n  \\<Longrightarrow> Insec A B (Msg []) \\<in> abs_msg H\"\n| am_M2a:\n    \"Crypt (shrK C) \\<lbrace>Key K, Agent B, Number T, X\\<rbrace> \\<in> H\n  \\<Longrightarrow> Secure Sv C (Msg [aAgt B, aKey K, aNum T]) \\<in> abs_msg H\"\n| am_M2b:\n    \"Crypt (shrK C) \\<lbrace>Key K, Agent A, Number T\\<rbrace> \\<in> H\n  \\<Longrightarrow> Secure Sv C (Msg [aKey K, aAgt A, aNum T]) \\<in> abs_msg H\"\n\n\ntext \\<open>R23: The simulation relation. This is a data refinement of\nthe insecure and secure channels of refinement 2.\\<close>\n\ndefinition\n  R23_msgs :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23_msgs \\<equiv> {(s, t). abs_msg (parts (IK t)) \\<subseteq> chan s }\"\n\ndefinition\n  R23_keys :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23_keys \\<equiv> {(s, t). \\<forall>KK K. KK \\<subseteq> range sesK \\<longrightarrow>\n     Key K \\<in> analz (Key`KK \\<union> (IK t)) \\<longrightarrow> aKey K \\<in> extr (aKey`KK \\<union> ik0) (chan s)\n  }\"\n\ndefinition\n  R23_pres :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23_pres \\<equiv> {(s, t). runs s = runs t \\<and> clk s = clk t \\<and> leak s = leak t}\"\n\ndefinition\n  R23 :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23 \\<equiv> R23_msgs \\<inter> R23_keys \\<inter> R23_pres\"\n\nlemmas R23_defs =\n  R23_def R23_msgs_def R23_keys_def R23_pres_def\n\n\ntext \\<open>The mediator function is the identity here.\\<close>\n\ndefinition\n  med32 :: \"m3_obs \\<Rightarrow> m2_obs\" where\n  \"med32 \\<equiv> id\"\n\n\nlemmas R23_msgsI = R23_msgs_def [THEN rel_def_to_intro, simplified, rule_format]\nlemmas R23_msgsE [elim] = R23_msgs_def [THEN rel_def_to_elim, simplified, rule_format]\n\nlemmas R23_keysI = R23_keys_def [THEN rel_def_to_intro, simplified, rule_format]\nlemmas R23_keysE [elim] = R23_keys_def [THEN rel_def_to_elim, simplified, rule_format]\n\nlemmas R23_presI = R23_pres_def [THEN rel_def_to_intro, simplified, rule_format]\nlemmas R23_presE [elim] = R23_pres_def [THEN rel_def_to_elim, simplified, rule_format]\n\nlemmas R23_intros = R23_msgsI R23_keysI R23_presI\n\n\ntext \\<open>Lemmas for various instantiations (for keys).\\<close>\n\nlemmas R23_keys_dest = R23_keys_def [THEN rel_def_to_dest, simplified, rule_format, rotated 2]\nlemmas R23_keys_dests =\n  R23_keys_dest\n  R23_keys_dest [where KK=\"{}\", simplified]\n  R23_keys_dest [where KK=\"{K'}\" for K', simplified]\n  R23_keys_dest [where KK=\"insert K' KK\" for K' KK, simplified, OF _ _ conjI]\n\n\nsubsubsection \\<open>General lemmas\\<close>\n(******************************************************************************)\n\ntext \\<open>General facts about @{term \"abs_msg\"}\\<close>\n\ndeclare abs_msg.intros [intro!]\ndeclare abs_msg.cases [elim!]\n\nlemma abs_msg_empty: \"abs_msg {} = {}\"\nby (auto)\n\nlemma abs_msg_Un [simp]:\n  \"abs_msg (G \\<union> H) = abs_msg G \\<union> abs_msg H\"\nby (auto)\n\nlemma abs_msg_mono [elim]:\n  \"\\<lbrakk> m \\<in> abs_msg G; G \\<subseteq> H \\<rbrakk> \\<Longrightarrow> m \\<in> abs_msg H\"\nby (auto)\n\nlemma abs_msg_insert_mono [intro]:\n  \"\\<lbrakk> m \\<in> abs_msg H \\<rbrakk> \\<Longrightarrow> m \\<in> abs_msg (insert m' H)\"\nby (auto)\n\n\ntext \\<open>Facts about @{term \"abs_msg\"} concerning abstraction of fakeable\nmessages. This is crucial for proving the refinement of the intruder event.\\<close>\n\nlemma abs_msg_DY_subset_fakeable:\n  \"\\<lbrakk> (s, t) \\<in> R23_msgs; (s, t) \\<in> R23_keys; (s, t) \\<in> R23_non; t \\<in> m3_inv1_lkeysec \\<rbrakk>\n  \\<Longrightarrow> abs_msg (synth (analz (IK t))) \\<subseteq> fake ik0 (dom (runs s)) (chan s)\"\napply (auto)\n\\<comment> \\<open>4 subgoals, deal with replays first\\<close>\napply (blast)\ndefer 1 apply (blast)\n\\<comment> \\<open>remaining 2 subgoals are real fakes\\<close>\napply (rule fake_StatCh, auto dest: R23_keys_dests)+\ndone\n\n\nsubsubsection \\<open>Refinement proof\\<close>\n(******************************************************************************)\n\ntext \\<open>Pair decomposition. These were set to \\texttt{elim!}, which is too\nagressive here.\\<close>\n\ndeclare MPair_analz [rule del, elim]\ndeclare MPair_parts [rule del, elim]\n\n\ntext \\<open>Protocol events.\\<close>\n\nlemma PO_m3_step1_refines_m2_step1:\n  \"{R23}\n     (m2_step1 Ra A B), (m3_step1 Ra A B)\n   {> R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n   (auto)\n\nlemma PO_m3_step2_refines_m2_step2:\n  \"{R23}\n     (m2_step2 Rb A B), (m3_step2 Rb A B)\n   {> R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n   (auto)\n\nlemma PO_m3_step3_refines_m2_step3:\n  \"{R23 \\<inter> (m2_inv3a_sesK_compr) \\<times> (m3_inv3_sesK_compr \\<inter> m3_inv1_lkeysec)}\n     (m2_step3 Rs A B Kab Ts), (m3_step3 Rs A B Kab Ts)\n   {> R23}\"\nproof -\n  { fix s t\n    assume H:\n      \"(s, t) \\<in> R23_msgs\" \"(s, t) \\<in> R23_keys\" \"(s, t) \\<in> R23_pres\"\n      \"s \\<in> m2_inv3a_sesK_compr\" \"t \\<in> m3_inv3_sesK_compr\" \"t \\<in> m3_inv1_lkeysec\"\n      \"Kab = sesK (Rs$sk)\" \"Rs \\<notin> dom (runs t)\"\n      \"\\<lbrace>Agent A, Agent B\\<rbrace> \\<in> parts (IK t)\"\n    let ?s'=\n      \"s\\<lparr> runs := runs s(Rs \\<mapsto> (Serv, [A, B], [aNum (clk t)])),\n          chan := insert (Secure Sv A (Msg [aAgt B, aKey Kab, aNum (clk t)]))\n                 (insert (Secure Sv B (Msg [aKey Kab, aAgt A, aNum (clk t)])) (chan s)) \\<rparr>\"\n    let ?t'=\n      \"t\\<lparr> runs := runs t(Rs \\<mapsto> (Serv, [A, B], [aNum (clk t)])),\n          IK := insert\n                  (Crypt (shrK A)\n                     \\<lbrace> Key Kab, Agent B, Number (clk t),\n                       Crypt (shrK B) \\<lbrace> Key Kab, Agent A, Number (clk t) \\<rbrace>\\<rbrace>)\n                  (IK t) \\<rparr>\"\n    have \"(?s', ?t') \\<in> R23_msgs\" using H\n    by (-) (rule R23_intros, auto)\n  moreover\n    have \"(?s', ?t') \\<in> R23_keys\" using H\n    by (-) (rule R23_intros,\n            auto simp add: m2_inv3a_sesK_compr_simps m3_inv3_sesK_compr_simps dest: R23_keys_dests)\n  moreover\n    have \"(?s', ?t') \\<in> R23_pres\" using H\n    by (-) (rule R23_intros, auto)\n  moreover\n    note calculation\n  }\n  thus ?thesis by (auto simp add: PO_rhoare_defs R23_def m3_defs)\nqed\n\nlemma PO_m3_step4_refines_m2_step4:\n  \"{R23 \\<inter>\n    UNIV \\<times> (m3_inv3_sesK_compr \\<inter> m3_inv2_ticket \\<inter> m3_inv1_lkeysec)}\n     (m2_step4 Ra A B Kab Ts), (m3_step4 Ra A B Kab Ts X)\n   {> R23}\"\nproof -\n  { fix s t\n    assume H:\n      \"(s, t) \\<in> R23_msgs\" \"(s, t) \\<in> R23_keys\" \"(s, t) \\<in> R23_pres\"\n      \"t \\<in> m3_inv3_sesK_compr\" \"t \\<in> m3_inv2_ticket\"  \"t \\<in> m3_inv1_lkeysec\"\n      \"runs t Ra = Some (Init, [A, B], [])\"\n      \"Crypt (shrK A) \\<lbrace>Key Kab, Agent B, Number Ts, X\\<rbrace> \\<in> analz (IK t)\"\n    let ?s' = \"s\\<lparr> runs := runs s(Ra \\<mapsto> (Init, [A, B], [aKey Kab, aNum Ts])) \\<rparr>\"\n    and ?t' = \"t\\<lparr> runs := runs t(Ra \\<mapsto> (Init, [A, B], [aKey Kab, aNum Ts])),\n                 IK := insert X  (IK t) \\<rparr>\"\n    from H have\n      \"Secure Sv A (Msg [aAgt B, aKey Kab, aNum Ts]) \\<in> chan s\"\n      by (auto)\n  moreover\n    have \"X \\<in> parts (IK t)\" using H\n      by (auto dest!: Body MPair_parts)\n    hence \"(?s', ?t') \\<in> R23_msgs\" using H\n      by (auto intro!: R23_intros) (auto)\n  moreover\n    have \"(?s', ?t') \\<in> R23_keys\"\n    proof (cases)\n      assume \"A \\<in> bad\" show ?thesis\n      proof -\n        note H\n      moreover\n        hence \"X \\<in> analz (IK t)\" using \\<open>A \\<in> bad\\<close>\n          by (-) (drule Decrypt, auto)\n      ultimately\n        show ?thesis\n          by (-) (rule R23_intros, auto dest!: analz_cut intro: analz_monotonic)\n      qed\n    next\n      assume \"A \\<notin> bad\" show ?thesis\n      proof -\n        note H\n      moreover\n        with \\<open>A \\<notin> bad\\<close> have\n          \"X = Crypt (shrK B) \\<lbrace>Key Kab, Agent A, Number Ts \\<rbrace> \\<and> Kab \\<in> range sesK\"\n          by (auto dest!: m3_inv2_ticketD)\n      moreover\n        { assume H1: \"Key (shrK B) \\<in> analz (IK t)\"\n          have \"aKey Kab \\<in> extr ik0 (chan s)\"\n          proof -\n            note calculation\n          moreover\n            hence \"Secure Sv B (Msg [aKey Kab, aAgt A, aNum Ts]) \\<in> chan s\"\n              by (-) (drule analz_into_parts, drule Body, elim MPair_parts, auto)\n          ultimately\n            show ?thesis using H1 by auto\n          qed\n        }\n      ultimately show ?thesis\n        by (-) (rule R23_intros, auto simp add: m3_inv3_sesK_compr_simps)\n      qed\n    qed\n  moreover\n    have \"(?s', ?t') \\<in> R23_pres\" using H\n      by (auto intro!: R23_intros)\n  moreover\n    note calculation\n  }\n  thus ?thesis\n    by (auto simp add: PO_rhoare_defs R23_def m3_defs dest!: analz_Inj_IK)\nqed\n\nlemma PO_m3_step5_refines_m2_step5:\n  \"{R23}\n     (m2_step5 Rb A B Kab Ts), (m3_step5 Rb A B Kab Ts)\n   {> R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n   (auto)\n\nlemma PO_m3_tick_refines_m2_tick:\n  \"{R23}\n    (m2_tick T), (m3_tick T)\n   {>R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n   (auto)\n\n\ntext \\<open>Intruder events.\\<close>\n\nlemma PO_m3_leak_refines_m2_leak:\n  \"{R23}\n    (m2_leak Rs), (m3_leak Rs)\n   {>R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros)\n   (auto dest: R23_keys_dests)\n\nlemma PO_m3_DY_fake_refines_m2_fake:\n  \"{R23 \\<inter> UNIV \\<times> (m3_inv1_lkeysec)}\n     m2_fake, m3_DY_fake\n   {> R23}\"\napply (auto simp add: PO_rhoare_defs R23_def m3_defs intro!: R23_intros del: abs_msg.cases)\napply (auto intro: abs_msg_DY_subset_fakeable [THEN subsetD] del: abs_msg.cases\n            dest: R23_keys_dests)\ndone\n\n\ntext \\<open>All together now...\\<close>\n\nlemmas PO_m3_trans_refines_m2_trans =\n  PO_m3_step1_refines_m2_step1 PO_m3_step2_refines_m2_step2\n  PO_m3_step3_refines_m2_step3 PO_m3_step4_refines_m2_step4\n  PO_m3_step5_refines_m2_step5 PO_m3_tick_refines_m2_tick\n  PO_m3_leak_refines_m2_leak PO_m3_DY_fake_refines_m2_fake\n\n\nlemma PO_m3_refines_init_m2 [iff]:\n  \"init m3 \\<subseteq> R23``(init m2)\"\nby (auto simp add: R23_def m3_defs ik0_def intro!: R23_intros)\n\nlemma PO_m3_refines_trans_m2 [iff]:\n  \"{R23 \\<inter>\n    (m2_inv3a_sesK_compr) \\<times> (m3_inv3_sesK_compr \\<inter> m3_inv2_ticket \\<inter> m3_inv1_lkeysec)}\n     (trans m2), (trans m3)\n   {> R23}\"\nby (auto simp add: m3_def m3_trans_def m2_def m2_trans_def)\n   (blast intro!: PO_m3_trans_refines_m2_trans)+\n\nlemma PO_m3_observation_consistent [iff]:\n  \"obs_consistent R23 med32 m2 m3\"\nby (auto simp add: obs_consistent_def R23_def med32_def m3_defs)\n\n\ntext \\<open>Refinement result.\\<close>\n\nlemma m3_refines_m2 [iff]:\n  \"refines\n     (R23 \\<inter> (m2_inv3a_sesK_compr) \\<times> (m3_inv3_sesK_compr \\<inter> m3_inv2_ticket \\<inter> m3_inv1_lkeysec))\n     med32 m2 m3\"\nby (rule Refinement_using_invariants) (auto)\n\nlemma m3_implements_m2 [iff]:\n  \"implements med32 m2 m3\"\nby (rule refinement_soundness) (auto)\n\n\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Security_Protocol_Refinement/Key_establish/m3_ds.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526368038304, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.26271162730193276}}
{"text": "chapter {* Define processes that are linear in execution *}\n\ntheory SimpleSimulation\nimports Main\nbegin\n\nrecord ('a, 'b) data_type =\n  Init :: \"'b \\<Rightarrow> 'a set\"\n  Fin :: \"'a \\<Rightarrow> 'b\"\n  Run :: \"('a \\<times> 'a) set\"\n\ntext {*\nWe follow a simple strategy that allows us to use as much of the NICTA seL4 libraries as\npossible. First, we define linear versions of constructs (e.g. the Hoare triple) in terms\nof the more complex NICTA constructs. Then we prove simple introduction lemmas which allow us\nto reason about linear constructs using lemmas defined over NICTA constructs. \n*}\ndefinition execution where\n\"execution A \\<equiv> \\<lambda>s. Fin A ` (Run A `` Init A s)\"\n\ndefinition hoare_triple where\n\"hoare_triple A P Q \\<equiv> \\<forall>s s'. s \\<in> P \\<longrightarrow> s' \\<in> execution A s \\<longrightarrow> s' \\<in> Q\"\n\ndefinition\n  refines :: \"('c,'b) data_type \\<Rightarrow> ('a,'b) data_type \\<Rightarrow> bool\" (infix \"\\<sqsubseteq>\" 60)\nwhere\n  \"C \\<sqsubseteq> A \\<equiv> \\<forall>s. execution C s \\<subseteq> execution A s\"\n\nlemma hoare_triple_refinement:\n  \"C \\<sqsubseteq> A = (\\<forall>P Q. hoare_triple A P Q \\<longrightarrow> hoare_triple C P Q)\"\n  by (simp add: refines_def hoare_triple_def) blast\n\ndefinition\n  rel_semi :: \"('a \\<times> 'b) set \\<Rightarrow> ('b \\<times> 'c) set \\<Rightarrow> ('a \\<times> 'c) set\" (infixl \";;;\" 65) \nwhere\n  \"A ;;; B \\<equiv> A O B\"\n\ndefinition\n  fw_sim :: \"('a \\<times> 'c) set \\<Rightarrow> ('c,'b) data_type \\<Rightarrow> ('a,'b) data_type \\<Rightarrow> bool\"\nwhere\n  \"fw_sim R C A \\<equiv> (\\<forall>s. Init C s \\<subseteq> R `` Init A s) \\<and> \n                  (R ;;; Run C \\<subseteq> Run A ;;; R) \\<and>\n                  (\\<forall>s s'. (s,s') \\<in> R \\<longrightarrow> Fin C s' = Fin A s)\"\n\ndefinition\n  fw_simulates :: \"('c,'b) data_type \\<Rightarrow> ('a,'b) data_type \\<Rightarrow> bool\" (infixl \"\\<sqsubseteq>\\<^sub>F\" 50)\nwhere\n  \"C \\<sqsubseteq>\\<^sub>F A \\<equiv> \\<exists>R. fw_sim R C A\"\n\nlemma sim_imp_refines:\n  fixes C :: \"('c,'b) data_type\" and A :: \"('a,'b) data_type\"\n  assumes \"C \\<sqsubseteq>\\<^sub>F A\"\n  shows \"C \\<sqsubseteq> A\"\nproof -\n  from assms have \"\\<exists>R. fw_sim R C A\" unfolding fw_simulates_def .\n  then obtain R where \"fw_sim R C A\" ..\n  hence init: \"\\<forall>s. Init C s \\<subseteq> R `` Init A s\"\n    and run:  \"R ;;; Run C \\<subseteq> Run A ;;; R\"\n    and fin:  \"\\<forall>s s'. (s,s') \\<in> R \\<longrightarrow> Fin C s' = Fin A s\"\n      unfolding fw_sim_def by auto\n  have \"\\<forall>s. execution C s \\<subseteq> execution A s\"\n  proof (safe)\n    fix s s'\n    assume \"s' \\<in> execution C s\"\n    hence \"s' \\<in> Fin C ` (Run C `` Init C s)\" unfolding execution_def .\n    hence \"\\<exists>s\\<^sub>C' \\<in> (Run C `` Init C s). s' = Fin C s\\<^sub>C'\" by auto\n    then obtain s\\<^sub>C' where \"s\\<^sub>C' \\<in> (Run C `` Init C s)\" and \"s' = Fin C s\\<^sub>C'\" ..\n    hence \"\\<exists>s\\<^sub>C \\<in> Init C s. (s\\<^sub>C, s\\<^sub>C') \\<in> Run C\" by auto\n    then obtain s\\<^sub>C where \"s\\<^sub>C \\<in> Init C s\" and \"(s\\<^sub>C, s\\<^sub>C') \\<in> Run C\" ..\n    with init have \"s\\<^sub>C \\<in> R `` Init A s\" by auto\n    hence \"\\<exists>s\\<^sub>A \\<in> Init A s. (s\\<^sub>A, s\\<^sub>C) \\<in> R\" by auto\n    then obtain s\\<^sub>A where \"s\\<^sub>A \\<in> Init A s\" and \"(s\\<^sub>A, s\\<^sub>C) \\<in> R\" ..\n    with `(s\\<^sub>C, s\\<^sub>C') \\<in> Run C` have \"(s\\<^sub>A, s\\<^sub>C') \\<in> R ;;; Run C\" unfolding rel_semi_def by auto\n    with run have \"(s\\<^sub>A, s\\<^sub>C') \\<in> Run A ;;; R\" by auto\n    hence \"\\<exists>s\\<^sub>A'. (s\\<^sub>A, s\\<^sub>A') \\<in> Run A \\<and> (s\\<^sub>A', s\\<^sub>C') \\<in> R\" unfolding rel_semi_def by auto\n    then obtain s\\<^sub>A' where \"(s\\<^sub>A, s\\<^sub>A') \\<in> Run A\" and \"(s\\<^sub>A', s\\<^sub>C') \\<in> R\" by auto\n    with fin and `s' = Fin C s\\<^sub>C'` have \"s' = Fin A s\\<^sub>A'\" by auto\n    with `s\\<^sub>A \\<in> Init A s` and `(s\\<^sub>A, s\\<^sub>A') \\<in> Run A` have \"s' \\<in> Fin A ` (Run A `` Init A s)\" by auto\n    thus \"s' \\<in> execution A s\" unfolding execution_def .\n  qed\n  thus \"C \\<sqsubseteq> A\" unfolding refines_def .\nqed\n\ndefinition\n  invariant_holds :: \"('a,'b) data_type \\<Rightarrow> 'a set \\<Rightarrow> bool\" (infix \"\\<Turnstile>\" 60)\nwhere\n  \"invariant_holds A I \\<equiv> (\\<forall>s. Init A s \\<subseteq> I) \\<and> (Run A `` I \\<subseteq> I)\"\n\nlemma invariant_T [iff]: \"D \\<Turnstile> UNIV\"\n  by (simp add: invariant_holds_def)\n\nlemma invariantI:\n  \"\\<lbrakk> \\<forall>s. Init D s \\<subseteq> I; Run D `` I \\<subseteq> I \\<rbrakk> \\<Longrightarrow> D \\<Turnstile> I\"\nby (simp add: invariant_holds_def)\n\nlemma invariant_CollectI [intro?]:\n  assumes init: \"\\<And>s a. s \\<in> Init D a \\<Longrightarrow> I s\"\n  assumes step: \"\\<And>s s'. \\<lbrakk> I s; (s,s') \\<in> Run D \\<rbrakk> \\<Longrightarrow> I s'\"\n  shows \"D \\<Turnstile> Collect I\"\nproof (rule invariantI)\n  show \"\\<forall>a. Init D a \\<subseteq> Collect I\" by (fast intro: init)\nnext\n  show \"Run D `` Collect I \\<subseteq> Collect I\"\n    by (auto simp add: Image_def intro: step)\nqed\n\nlemma invariant_conjI:\n  \"D \\<Turnstile> P \\<Longrightarrow> D \\<Turnstile> Q  \\<Longrightarrow> D \\<Turnstile> P \\<inter> Q\"\n  by (simp add: invariant_holds_def) blast\n\nlemma invariant_conjI2:\n  \"\\<lbrakk> D \\<Turnstile> I; \\<And>s. Init D s \\<subseteq> I \\<Longrightarrow> Init D s \\<subseteq> J; \n    Run D `` (I \\<inter> J) \\<subseteq> J \\<rbrakk> \\<Longrightarrow> D \\<Turnstile> I \\<inter> J\"    \n  by (simp add: invariant_holds_def) blast\n\ndefinition\n  LI :: \"('a,'b) data_type \\<Rightarrow> ('c,'b) data_type \\<Rightarrow> ('a \\<times> 'c) set \\<Rightarrow> ('a \\<times> 'c) set \\<Rightarrow> bool\"\nwhere\n  \"LI A C R I \\<equiv> (\\<forall>s. Init C s \\<subseteq> R `` Init A s) \\<and> \n                ((R \\<inter> I) ;;; Run C \\<subseteq> Run A ;;; R) \\<and>\n                (\\<forall>s s'. (s,s') \\<in> R \\<inter> I \\<longrightarrow> Fin C s' = Fin A s)\"\n(* Arash *)\nlemma LI_fw_sim:\n  fixes C :: \"('c,'b) data_type\" and A :: \"('a,'b) data_type\" and R I\\<^sub>A I\\<^sub>C \n  assumes ia: \"A \\<Turnstile> I\\<^sub>a\" and ic: \"C \\<Turnstile> I\\<^sub>c\" and li: \"LI A C R (I\\<^sub>a \\<times> I\\<^sub>c)\"\n  shows \"fw_sim (R \\<inter> I\\<^sub>a \\<times> I\\<^sub>c) C A\"\napply (simp add:fw_sim_def) \nproof (rule  conjI)\n  show \"\\<forall>s. Init C s \\<subseteq> (R \\<inter> I\\<^sub>a \\<times> I\\<^sub>c) `` Init A s\"\n  proof \n    fix s\n    from li have 0 : \"Init C s \\<subseteq> R `` Init A s\" unfolding LI_def by auto\n    show \"Init C s \\<subseteq> (R \\<inter> I\\<^sub>a \\<times> I\\<^sub>c) `` Init A s\"\n    proof\n      fix c\n      assume \"c \\<in> Init C s\"\n      from this and ic have \"c \\<in> I\\<^sub>c\" unfolding invariant_holds_def by auto\n      from `c \\<in> Init C s` and 0 have \"c \\<in> (R `` Init A s)\" by auto\n      then have \"\\<exists> a. a \\<in> Init A s \\<and> (a,c) \\<in> R\" by auto\n      then obtain a where aCond:\"a \\<in> Init A s \\<and> (a,c) \\<in> R\" by auto\n      then have \"a \\<in> I\\<^sub>a\" using ia unfolding invariant_holds_def by auto\n      then have \"(a,c) \\<in> R \\<inter>(I\\<^sub>a \\<times> I\\<^sub>c)\" using `c \\<in> I\\<^sub>c` and aCond by blast\n      then show \"c \\<in> (R \\<inter> I\\<^sub>a \\<times> I\\<^sub>c) `` Init A s\" using aCond by blast\n    qed\n  qed\nnext\n   show \"R \\<inter> I\\<^sub>a \\<times> I\\<^sub>c ;;; Run C \\<subseteq> Run A ;;; R \\<inter> I\\<^sub>a \\<times> I\\<^sub>c \\<and>\n    (\\<forall>s s'. (s, s') \\<in> R \\<and> s \\<in> I\\<^sub>a \\<and> s' \\<in> I\\<^sub>c \\<longrightarrow> Fin C s' = Fin A s)\"\n    proof(safe)\n      fix a c \n      assume 0:\"(a,c) \\<in>  R \\<inter> I\\<^sub>a \\<times> I\\<^sub>c ;;; Run C\"\n      from ia have iaa: \"(s,s') \\<in> Run A \\<Longrightarrow> s \\<in> I\\<^sub>a  \\<Longrightarrow> s' \\<in> I\\<^sub>a\" \n        by (auto simp: invariant_holds_def)\n      from ic have icc: \"(xx,xx') \\<in> Run C \\<Longrightarrow> xx \\<in> I\\<^sub>c  \\<Longrightarrow> xx' \\<in> I\\<^sub>c\"\n        by (auto simp: invariant_holds_def)\n      from 0 have aIa: \"a \\<in> I\\<^sub>a\" unfolding rel_semi_def by auto\n      from 0 have cIc: \"c \\<in> I\\<^sub>c\" using ic  unfolding rel_semi_def\n      proof -\n        assume \"(a,c) \\<in> (R \\<inter> I\\<^sub>a \\<times> I\\<^sub>c) O Run C\"\n        then have \"\\<exists> cc. (a,cc) \\<in>  R \\<inter> I\\<^sub>a \\<times> I\\<^sub>c \\<and> (cc,c) \\<in> Run C\" using 0  by blast\n        then obtain cc where ccCond:\"(a,cc) \\<in>  R \\<inter> I\\<^sub>a \\<times> I\\<^sub>c \\<and> (cc,c) \\<in> Run C\" by auto\n        then have \"cc \\<in> I\\<^sub>c\" by auto\n        then show \"c \\<in> I\\<^sub>c\" using ccCond ic unfolding invariant_holds_def by auto\n      qed\n      have 1: \"(a,c) \\<in> Run A ;;; R\"\n      proof -\n        from li have \"R \\<inter> I\\<^sub>a \\<times> I\\<^sub>c ;;; Run C \\<subseteq> Run A ;;; R\" unfolding LI_def by auto\n        then show ?thesis using 0 by blast\n      qed\n      from 1 have \"\\<exists> b . (a,b) \\<in> Run A \\<and> (b,c) \\<in> R\" unfolding rel_semi_def by auto\n      then obtain b where bCon: \"(a,b) \\<in> Run A \\<and> (b,c) \\<in> R\" ..\n      from this and aIa and iaa have bIa: \"b \\<in> I\\<^sub>a\" \n        by (meson ImageI ia invariant_holds_def subsetCE) \n      from bCon have \"(b,c) \\<in> R\" by auto\n      from this and cIc and bIa have \"(b,c) \\<in> R \\<inter> (I\\<^sub>a \\<times> I\\<^sub>c)\" by blast\n      from bCon have \"(a,b) \\<in> Run A\" by auto\n      from this and `(b,c) \\<in> R \\<inter> (I\\<^sub>a \\<times> I\\<^sub>c)` have \"(a,c) \\<in> Run A ;;; R \\<inter> (I\\<^sub>a \\<times> I\\<^sub>c)\" \n        by (auto simp: rel_semi_def)\n      from this show \"(a,c) \\<in> Run A ;;; R \\<inter> (I\\<^sub>a \\<times> I\\<^sub>c)\" by auto\n    next\n      fix s s'\n      assume \"(s,s') \\<in> R\" and \"s \\<in> I\\<^sub>a\" and  \"s' \\<in> I\\<^sub>c\"\n      from this and li have \"(s,s') \\<in> R \\<inter> (I\\<^sub>a \\<times> I\\<^sub>c)\" by auto\n      from this and li show  \"Fin C s' = Fin A s\" by (simp add: LI_def)\n   qed\nqed\n\n (* Arash *)     \nlemma weaken_LI:\n  fixes C :: \"('c,'b) data_type\" and A :: \"('a,'b) data_type\" and R I I'\n  assumes LI: \"LI A C R I'\" and weaker: \"I \\<subseteq> I'\"\n  shows \"LI A C R I\"\napply(simp_all add: LI_def)\nproof\n  show \"\\<forall>s. Init C s \\<subseteq> R `` Init A s\" using LI unfolding LI_def by auto\n  next show \" R \\<inter> I ;;; Run C \\<subseteq> Run A ;;; R \\<and>\n    (\\<forall>s s'. (s, s') \\<in> R \\<and> (s, s') \\<in> I \\<longrightarrow> Fin C s' = Fin A s)\"\n  proof (safe)\n    fix a c\n    assume \"(a,c) \\<in> R \\<inter> I ;;; Run C\"\n    then have \"\\<exists> b. (a,b) \\<in> R \\<inter> I \\<and> (b,c) \\<in> Run C\" unfolding rel_semi_def by auto\n    then obtain b where bCond:\"(a,b) \\<in> R \\<inter> I \\<and> (b,c) \\<in> Run C\" by auto\n    then have \"(a,b) \\<in> R \\<inter> I'\" using weaker by auto\n    then have \"(a,c) \\<in> R \\<inter> I' ;;; Run C\" using bCond by (auto simp:rel_semi_def)\n    then show \"(a,c) \\<in> Run A;;; R\" using LI unfolding LI_def by auto\n    next\n    fix s s'\n    assume \"(s,s') \\<in> R\" and \"(s,s') \\<in> I\"\n    then have \"(s,s') \\<in> I'\" using weaker by auto\n    then have \"(s,s') \\<in> R \\<inter> I'\" using `(s,s') \\<in> R` by auto\n    then show \"Fin C s' = Fin A s\" using LI unfolding LI_def by auto\n  qed\nqed \n\nlemma fw_sim_eq_LI: \"fw_sim r C A = LI A C r UNIV\"\nunfolding fw_sim_def LI_def by simp\n\nlemma fw_sim_LI: \"fw_sim r C A \\<Longrightarrow> LI A C r I\"\nby (simp add: fw_sim_eq_LI weaken_LI[where I'=UNIV])\n\nlemma L_invariantI:\n  assumes  \"A \\<Turnstile> I\\<^sub>a\" and \"C \\<Turnstile> I\\<^sub>c\" and \"LI A C r (I\\<^sub>a \\<times> I\\<^sub>c)\"\n  shows \"C \\<sqsubseteq>\\<^sub>F A\"\n  using assms\n  by (simp add: fw_simulates_def, rule_tac x=\"r \\<inter> I\\<^sub>a \\<times> I\\<^sub>c\" in exI,\n      simp add: LI_fw_sim)\n\nlemma refinement_refl[simp]: \"A \\<sqsubseteq> A\"\nunfolding refines_def by auto\n\nlemma refinement_trans [trans]: \"\\<lbrakk>C \\<sqsubseteq> B; B \\<sqsubseteq> A\\<rbrakk> \\<Longrightarrow> C \\<sqsubseteq> A\"\nunfolding refines_def by auto\n\n(* Arash *)\nlemma fw_inv_transport2:\n  fixes A I\\<^sub>a C I\\<^sub>c R\n  assumes \"A \\<Turnstile> I\\<^sub>a\" and  \"C \\<Turnstile> I\\<^sub>c\" and li:\"LI A C R (I\\<^sub>a \\<times> I\\<^sub>c)\"\n  shows \"C \\<Turnstile> {s'. \\<exists>s. (s,s') \\<in> R \\<and> s \\<in> I\\<^sub>a \\<and> s' \\<in> I\\<^sub>c}\"\napply(simp add:invariant_holds_def)\nproof  \n  show \"\\<forall>s. Init C s \\<subseteq> {s'. \\<exists>s. (s, s') \\<in> R \\<and> s \\<in> I\\<^sub>a \\<and> s' \\<in> I\\<^sub>c}\"\n  proof\n    fix s\n    show \"Init C s \\<subseteq> {s'. \\<exists>s. (s, s') \\<in> R \\<and> s \\<in> I\\<^sub>a \\<and> s' \\<in> I\\<^sub>c}\"\n    proof\n      fix x\n      assume \"x \\<in> Init C s\"\n      then have \"x \\<in> R `` Init A s\" using li unfolding LI_def by auto\n      then have \"\\<exists> s' . s' \\<in> Init A s \\<and> (s',x) \\<in> R\" by auto\n      then obtain s' where c1:\"s' \\<in> Init A s \\<and> (s',x) \\<in> R\" by auto\n      then have c2:\"s' \\<in> I\\<^sub>a\" using `A \\<Turnstile> I\\<^sub>a` unfolding invariant_holds_def by auto\n      from `C \\<Turnstile> I\\<^sub>c`` x \\<in> Init C s`  have c3: \"x \\<in> I\\<^sub>c\" unfolding invariant_holds_def by auto\n      then have \"(s', x) \\<in> R \\<and> s' \\<in> I\\<^sub>a \\<and> x \\<in> I\\<^sub>c\" using c1 c2 by auto\n      then show \"x \\<in> {xx . \\<exists>s' . (s',xx) \\<in> R \\<and> s' \\<in> I\\<^sub>a \\<and> xx \\<in> I\\<^sub>c}\" by auto\n    qed\n  qed\nnext\n  let ?X = \"{s'. \\<exists>s. (s, s') \\<in> R \\<and> s \\<in> I\\<^sub>a \\<and> s' \\<in> I\\<^sub>c}\"\n  show \"Run C `` ?X \\<subseteq> ?X\"\n  proof\n  fix b\n    assume \"b \\<in> Run C `` ?X\"\n    then have \"\\<exists> a. a \\<in> ?X \\<and> (a,b) \\<in> Run C\" by auto\n    then obtain a where 0:\"a \\<in> ?X \\<and> (a,b) \\<in> Run C\" by auto\n    then have \"\\<exists> s . (s,a) \\<in> R \\<and> s \\<in> I\\<^sub>a \\<and> a \\<in> I\\<^sub>c\" by auto\n    then obtain s where 1:\"(s,a) \\<in> R \\<and> s \\<in> I\\<^sub>a \\<and> a \\<in> I\\<^sub>c\" by auto\n    then have \"(s,a) \\<in> R \\<inter> (I\\<^sub>a\\<times>I\\<^sub>c)\" by blast\n    then have \"(s,b) \\<in> R \\<inter> (I\\<^sub>a\\<times>I\\<^sub>c) ;;; Run C\" using 0 unfolding rel_semi_def  by blast\n    then have \"(s,b) \\<in> Run A ;;; R\" using li unfolding LI_def by blast\n    then have \"\\<exists> ss. (s,ss) \\<in> Run A \\<and> (ss,b) \\<in> R\" unfolding rel_semi_def  by blast\n    then obtain ss where 2:\"(s,ss) \\<in> Run A \\<and> (ss,b) \\<in> R\" by auto\n    from 1 have \"s \\<in> I\\<^sub>a\" by auto\n    then have \"ss \\<in> I\\<^sub>a\" using 2 `A \\<Turnstile> I\\<^sub>a` unfolding invariant_holds_def by blast\n    from 0 1 `C \\<Turnstile> I\\<^sub>c` have \"b \\<in> I\\<^sub>c\" unfolding invariant_holds_def by blast\n    from 2 `ss \\<in> I\\<^sub>a` `b \\<in> I\\<^sub>c` have \"(ss,b) \\<in> R \\<and> ss \\<in> I\\<^sub>a \\<and> b \\<in> I\\<^sub>c\" by auto\n    then show \"b \\<in> ?X\" by auto\n  qed\nqed\n\nlemma fw_inv_transport:\n  \"\\<lbrakk> A \\<Turnstile> I\\<^sub>a; C \\<Turnstile> I\\<^sub>c; LI A C R (I\\<^sub>a \\<times> I\\<^sub>c) \\<rbrakk> \\<Longrightarrow> C \\<Turnstile> {s'. \\<exists>s. (s,s') \\<in> R \\<and> s \\<in> I\\<^sub>a \\<and> s' \\<in> I\\<^sub>c}\"\nby (simp add: fw_inv_transport2)\n\nlemma fw_sim_refl: \"fw_sim Id A A\"\nunfolding fw_sim_def rel_semi_def by simp\n\nlemma fw_simulates_refl[simp]: \"A \\<sqsubseteq>\\<^sub>F A\"\nunfolding fw_simulates_def by (blast intro: fw_sim_refl)\n\nlemma nondet_app_sub : \"X \\<subseteq> Y \\<Longrightarrow> R `` X \\<subseteq> R `` Y\" by auto\nlemma comp_sub : \" X \\<subseteq> Y \\<Longrightarrow> R O X \\<subseteq> R O Y\" by auto\nlemma comp_sub2 : \"X \\<subseteq> Y \\<Longrightarrow>  X O R \\<subseteq> Y O R\" by auto\nlemma comp_ass : \"R1 O (R2 O R3) = (R1 O R2) O R3\" by auto\nlemma nondet_app_com : \"R1``(R2`` X) = (R2 O R1) `` X\"  by auto\n\n(* Arash *)\nlemma fw_sim_trans2:\n  assumes fwsr1cb:\"fw_sim R1 C B\" and fwsr2ba:\"fw_sim R2 B A\"\n  shows \"fw_sim (R2 O R1) C A\"\nproof -\n  let ?R = \"R2 O R1\"\n  have init:\"\\<forall>s. Init C s \\<subseteq> ?R `` Init A s\"\n  proof\n    fix s\n    have initCB:\"Init C s \\<subseteq> R1 `` Init B s\" using fwsr1cb unfolding fw_sim_def by auto\n    have initBA:\"Init B s \\<subseteq> R2 `` Init A s\" using fwsr2ba unfolding fw_sim_def by auto\n    then have \"R1 `` Init B s \\<subseteq> R1 `` (R2 `` Init A s)\" using nondet_app_sub by auto\n    then have \"Init C s \\<subseteq> R1 `` (R2 `` Init A s)\" using initCB by auto\n    then show \"Init C s \\<subseteq> (R2 O R1) `` Init A s\" using nondet_app_com by force\n  qed\n  have run:\"?R ;;; Run C \\<subseteq> Run A ;;; ?R\"\n  proof -\n    have runCB: \"R1 O Run C \\<subseteq> Run B O R1\" using fwsr1cb unfolding fw_sim_def rel_semi_def by auto\n    have runBA: \"R2 O Run B \\<subseteq> Run A O R2\" using fwsr2ba unfolding fw_sim_def rel_semi_def by auto\n    have 0: \"R2 O R1 O Run C \\<subseteq> R2 O Run B O R1\" using runCB by blast\n    have \"R2 O Run B O R1 \\<subseteq> Run A O R2 O R1\" using runBA by blast\n    then have \"R2 O R1 O Run C \\<subseteq> Run A O R2 O R1\" using 0 by blast\n    then show \"(R2 O R1) ;;; Run C \\<subseteq> Run A ;;; (R2 O R1)\" unfolding rel_semi_def by blast\n  qed\n  have fin:\"(\\<forall>s s'. (s, s') \\<in> ?R \\<longrightarrow> Fin C s' = Fin A s)\"\n  proof (safe)\n    fix s s' x y z\n    show \"(x, y) \\<in> R2 \\<Longrightarrow> (y,z) \\<in> R1 \\<Longrightarrow> Fin C z = Fin A x\"\n    proof -\n      assume xyr2:\"(x, y) \\<in> R2\" and \"(y,z) \\<in> R1\"\n      then have 0:\"Fin C z = Fin B y\" using fwsr1cb unfolding fw_sim_def by auto\n      have \"Fin B y = Fin A x\" using fwsr2ba xyr2 unfolding fw_sim_def by auto\n      then show \"Fin C z = Fin A x\" using 0 by auto\n    qed\n  qed\n  from init run fin show \"fw_sim ?R C A\" using fw_sim_def by blast\nqed\n\nlemma fw_sim_trans: \"\\<lbrakk>fw_sim Q C B; fw_sim R B A\\<rbrakk> \\<Longrightarrow> fw_sim (R O Q) C A\"\nby (simp add:fw_sim_trans2)\n\nlemma fw_simulates_trans: \"\\<lbrakk>C \\<sqsubseteq>\\<^sub>F B; B \\<sqsubseteq>\\<^sub>F A\\<rbrakk> \\<Longrightarrow> C \\<sqsubseteq>\\<^sub>F A\"\nunfolding fw_simulates_def by (blast dest: fw_sim_trans)\n\nend", "meta": {"author": "CriticalTechnologiesInc", "repo": "SableModel", "sha": "a452a2b5e3636b612a4d04cfb6e2ab1c1a132639", "save_path": "github-repos/isabelle/CriticalTechnologiesInc-SableModel", "path": "github-repos/isabelle/CriticalTechnologiesInc-SableModel/SableModel-a452a2b5e3636b612a4d04cfb6e2ab1c1a132639/lib/SimpleSimulation.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.546738151984614, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.262696024503923}}
{"text": "theory ReduceAction\n  imports ReduceProper ReduceWTS\nbegin\n  \n  (* ###### constructive permission definitions.\n      the idea here is that i want to constructively state which permissions are being consumed.\n      the difficult part is that because the \"permissions consumed\" involves \n  *)\n    \ndatatype gen_act =\n  NoResAct\n  | AddResAct string p_type perm_use_env\n  | Add2ResAct string string p_type\n  | ReadResAct\n  | WriteResAct string perm_use_env\n    \nfun red_env :: \"pt_env \\<Rightarrow> gen_act \\<Rightarrow> pt_env\" where\n  \"red_env env NoResAct = env\"\n| \"red_env env (AddResAct x tau r_s) = add_env env (Loc x) tau\"\n| \"red_env env (Add2ResAct x1 x2 tau) = add_env (add_env env (Loc x1) (ChanTy tau SEnd)) (Loc x2) (ChanTy tau REnd)\"\n| \"red_env env ReadResAct = env\"\n| \"red_env env (WriteResAct x r_s) = env\"\n\nfun exp_red_use_env where\n  \"exp_red_use_env r_s NoResAct = r_s\"\n  (* remove resources used to create the value, add the new perm *)\n| \"exp_red_use_env r_s (AddResAct x tau r_s') = add_use_env r_s (Loc x) OwnPerm\"\n| \"exp_red_use_env r_s (Add2ResAct x1 x2 tau) = add_use_env (add_use_env r_s (Loc x1) OwnPerm) (Loc x2) OwnPerm\"\n| \"exp_red_use_env r_s ReadResAct = r_s\"  \n| \"exp_red_use_env r_s (WriteResAct x r_s') = (diff_use_env r_s r_s')\"\n  \nfun end_red_use_env where  \n  \"end_red_use_env r_s (WriteResAct x r_s') = (diff_use_env r_s r_s')\"\n| \"end_red_use_env r_s r_ax = r_s\"\n  \nfun red_nres_map :: \"nres_map \\<Rightarrow> gen_act \\<Rightarrow> nres_map\" where\n  \"red_nres_map rs_map NoResAct = rs_map\"  \n| \"red_nres_map rs_map (AddResAct x tau r_s) = add_env rs_map x r_s\"\n| \"red_nres_map rs_map (Add2ResAct x1 x2 tau) = add_env (add_env rs_map x1 empty_use_env) x2 empty_use_env\"\n| \"red_nres_map rs_map ReadResAct = rs_map\"\n| \"red_nres_map rs_map (WriteResAct x r_s) = add_env rs_map x (comp_use_env (nres_lookup rs_map x) r_s)\"\n  \nfun safe_act where\n  \"safe_act s r_s NoResAct = True\"\n| \"safe_act s r_s (AddResAct x tau r_x) = (s x = None \\<and> leq_use_env r_x r_s)\"\n| \"safe_act s r_s (Add2ResAct x1 x2 tau) = (s x1 = None \\<and> s x2 = None \\<and> x1 \\<noteq> x2)\"\n| \"safe_act s r_s ReadResAct = True\"\n| \"safe_act s r_s (WriteResAct x r_x) = (s x \\<noteq> None \\<and> leq_use_env r_x r_s)\"\n  \nfun corr_act where\n  \"corr_act ax NoResAct = (ax = NoAct)\"\n| \"corr_act ax (AddResAct x tau r_s) = (ax = MakeAct x)\"\n| \"corr_act ax (Add2ResAct x1 x2 tau) = (ax = Mk2Act x1 x2)\"\n| \"corr_act ax ReadResAct = (\\<exists> x. ax = UseAct x)\"\n| \"corr_act ax (WriteResAct x r_s) = (\\<exists> x. ax = UseAct x)\"  \n  \n    \nlemma leq_safe_act: \"\\<lbrakk> safe_act s r_x g_ax; leq_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> safe_act s r_s g_ax\"    \n  apply (case_tac g_ax)\n      apply (auto)\n   apply (rule_tac r_sb=\"r_x\" in trans_leq_use_env)\n    apply (auto)\n  apply (rule_tac r_sb=\"r_x\" in trans_leq_use_env)\n   apply (auto)\n  done  \n  \n  \ndefinition valid_reduct where\n  \"valid_reduct r_exp = (\\<forall> are s1 rs_map env r_f r_s1 e1 tau r_s2 rx ax s2 e2. (\n    r_exp are (s1, e1) ax (s2, e2) \\<and> well_typed env r_s1 e1 tau r_s2 rx \\<and> proper_exp rs_map e1 \\<and>\n    well_typed_state s1 env rs_map \\<and> valid_exp_use_env s1 rs_map r_f \\<and> leq_use_env r_s1 r_f) \\<longrightarrow>\n    (\\<exists> g_ax. well_typed (red_env env g_ax) (exp_red_use_env r_s1 g_ax) e2 tau (end_red_use_env r_s2 g_ax) (end_red_use_env rx g_ax) \\<and>\n      proper_exp (red_nres_map rs_map g_ax) e2 \\<and> well_typed_state s2 (red_env env g_ax) (red_nres_map rs_map g_ax) \\<and>\n      valid_exp_use_env s2 (red_nres_map rs_map g_ax) (exp_red_use_env r_f g_ax) \\<and> safe_act s1 (infl_use_env r_f r_s2) g_ax \\<and> corr_act ax g_ax)\n  )\"  \n  \n  \nlemma red_contain_env: \"\\<lbrakk> safe_act s r_s g_ax; sub_env s env \\<rbrakk> \\<Longrightarrow> contain_env (red_env env g_ax) env\"\n  apply (case_tac g_ax)\n      apply (auto)\n      apply (rule_tac id_contain_env)\n     apply (rule_tac add_contain_env)\n     apply (simp add: sub_env_def)\n     apply (erule_tac x=\"Loc x21\" in allE)\n     apply (auto)\n    apply (rule_tac env_b=\"add_env env (Loc x31) (ChanTy x33 SEnd)\" in trans_contain_env)\n     apply (rule_tac add_contain_env)\n     apply (simp add: add_env_def)\n     apply (case_tac \"env (Loc x32)\")\n      apply (auto)\n     apply (simp add: sub_env_def)\n     apply (erule_tac x=\"Loc x32\" in allE)\n     apply (auto)\n    apply (rule_tac add_contain_env)\n    apply (case_tac \"env (Loc x31)\")\n     apply (auto)\n    apply (simp add: sub_env_def)\n    apply (erule_tac x=\"Loc x31\" in allE)\n    apply (auto)\n   apply (rule_tac id_contain_env)\n  apply (rule_tac id_contain_env)\n  done  \n    \n    (* ##### safe-reduction specific validity lemmas ##### *)\n  \nlemma red_sep_nres_map: \"\\<lbrakk> p_map u = Some r_s; disj_nres_map p_map; sub_nres_map s1 p_map;\n  safe_act s1 r_s g_ax; sub_use_env s1 r_s \\<rbrakk> \\<Longrightarrow> sep_nres_map (exp_red_use_env r_s g_ax) (rem_env p_map u)\"\n  apply (simp add: sep_nres_map_def)\n  apply (auto)\n    (* we dont have to check x = u, since u has been removed from the map *)\n  apply (case_tac \"u = x\")\n   apply (auto)\n   apply (simp add: nres_lookup_def)\n   apply (simp add: rem_env_def)\n   apply (rule_tac empty_strong_disj_use_env2)\n    (* otherwise, the lookup is the same as it was in p_map *)\n  apply (cut_tac rs_map=\"p_map\" and x=\"u\" and y=\"x\" in nres_rem_diff)\n   apply (auto)\n    (* from here we do case analysis on the possible ways that r_s has been modified *)\n    (* if it has not been modified the case is simple *)\n  apply (case_tac \"exp_red_use_env r_s g_ax = r_s\")\n   apply (simp add: disj_nres_map_def)\n   apply (erule_tac x=\"u\" in allE)\n   apply (erule_tac x=\"x\" in allE)\n   apply (auto)\n   apply (simp add: nres_lookup_def)\n    (* make case: if x21 has been added, the rest of r_s is disjoint from p_map x *)\n  apply (case_tac g_ax)\n     apply (auto)\n    apply (rule_tac add_strong_disj_use_env)\n     apply (simp add: disj_nres_map_def)\n     apply (erule_tac x=\"u\" in allE)\n     apply (erule_tac x=\"x\" in allE)\n     apply (auto)\n     apply (simp add: nres_lookup_def)\n    (* now we have to prove that x21 was not in p_map, which should be true since p_map is sub-ordinate to s *)\n    apply (case_tac \"p_map x\")\n     apply (simp add: nres_lookup_def)\n     apply (simp add: empty_use_env_def)\n    apply (simp add: sub_nres_map_def)\n    apply (erule_tac x=\"x\" in allE)\n    apply (simp add: sub_use_env_def)\n    apply (erule_tac x=\"Loc x21\" in allE)\n    apply (auto)\n    (* make 2 case: start by assuming we have p_map x *)\n   apply (case_tac \"p_map x\")\n    apply (simp add: nres_lookup_def)\n    apply (rule_tac empty_strong_disj_use_env2)\n    (* otherwise, prove r_s disjoint from p_map x *)\n   apply (rule_tac add_strong_disj_use_env)\n    apply (rule_tac add_strong_disj_use_env)\n     apply (simp add: disj_nres_map_def)\n     apply (erule_tac x=\"u\" in allE)\n     apply (erule_tac x=\"x\" in allE)\n     apply (auto)\n     apply (simp add: nres_lookup_def)\n    (* after this, prove x31 / x32 do not appear in p_map x *)\n    apply (simp add: sub_nres_map_def)\n    apply (erule_tac x=\"x\" in allE)\n    apply (simp add: sub_use_env_def)\n    apply (erule_tac x=\"Loc x31\" in allE)\n    apply (auto)\n   apply (simp add: sub_nres_map_def)\n   apply (erule_tac x=\"x\" in allE)\n   apply (simp add: sub_use_env_def)\n   apply (erule_tac x=\"Loc x32\" in allE)\n    apply (auto)\n    (* write case: otherwise, x42 was removed from r_s, so disjointness should be simple *)\n  apply (rule_tac r_s=\"r_s\" in strong_disj_leq_use_env1)\n   apply (simp add: disj_nres_map_def)\n   apply (erule_tac x=\"u\" in allE)\n   apply (erule_tac x=\"x\" in allE)\n   apply (auto)\n   apply (simp add: nres_lookup_def)\n  apply (rule_tac self_diff_leq_use_env)\n  done  \n\nlemma red_sep_nres_map2: \"\\<lbrakk> p_map v = Some r_p; p_map u = Some r_s; u \\<noteq> v; disj_nres_map p_map;\n  safe_act s1 r_s g_ax; sep_nres_map r_p rs_map \\<rbrakk> \\<Longrightarrow> sep_nres_map r_p (red_nres_map rs_map g_ax)\"    \n  apply (case_tac g_ax)\n      apply (auto)\n    (* make case *)\n    apply (rule_tac add_sep_nres_map)\n     apply (simp)\n    apply (rule_tac r_s=\"r_s\" in strong_disj_leq_use_env2)\n     apply (simp add: disj_nres_map_def)\n     apply (auto)\n    apply (erule_tac x=\"v\" in allE)\n    apply (erule_tac x=\"u\" in allE)\n    apply (simp add: nres_lookup_def)\n    (* make 2 case *)\n   apply (rule_tac add_sep_nres_map)\n    apply (rule_tac add_sep_nres_map)\n     apply (simp)\n    apply (rule_tac empty_strong_disj_use_env2)\n   apply (rule_tac empty_strong_disj_use_env2)\n    (* write case *)\n  apply (rule_tac add_sep_nres_map)\n   apply (simp)\n  apply (rule_tac strong_disj_comp_use_env1)\n   apply (simp add: sep_nres_map_def)\n  apply (rule_tac r_s=\"r_s\" in strong_disj_leq_use_env2)\n   apply (simp add: disj_nres_map_def)\n   apply (erule_tac x=\"v\" in allE)\n   apply (erule_tac x=\"u\" in allE)\n   apply (simp add: nres_lookup_def)\n  apply (simp)\n  done    \n  \nend", "meta": {"author": "anon-ef", "repo": "perm_lang_ef2", "sha": "0fcb6e4c175193cc7b94f297a8aaa605f502d711", "save_path": "github-repos/isabelle/anon-ef-perm_lang_ef2", "path": "github-repos/isabelle/anon-ef-perm_lang_ef2/perm_lang_ef2-0fcb6e4c175193cc7b94f297a8aaa605f502d711/perm_ref/ReduceAction.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5467381372136563, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.26269601740679277}}
{"text": "(*  Title:      HOL/Auth/n_mutualExOnI_lemma_inv__1_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mutualExOnI Protocol Case Study*} \n\ntheory n_mutualExOnI_lemma_inv__1_on_rules imports n_mutualExOnI_lemma_on_inv__1\nbegin\nsection{*All lemmas on causal relation between inv__1*}\nlemma lemma_inv__1_on_rules:\n  assumes b1: \"r \\<in> rules N\" and b2: \"(\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__1  p__Inv0 p__Inv1)\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have c1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n  apply (cut_tac b1, auto) done\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_TryVsinv__1) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_CritVsinv__1) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_ExitVsinv__1) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_IdleVsinv__1) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "lyj238Gmail", "repo": "newParaVerifier", "sha": "5c2d49bf8e6c46c60efa53c98b0ba5c577d59618", "save_path": "github-repos/isabelle/lyj238Gmail-newParaVerifier", "path": "github-repos/isabelle/lyj238Gmail-newParaVerifier/newParaVerifier-5c2d49bf8e6c46c60efa53c98b0ba5c577d59618/examples/n_mutualExOnI/n_mutualExOnI_lemma_inv__1_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6757646010190476, "lm_q2_score": 0.38861802670584894, "lm_q1q2_score": 0.26261430576568756}}
{"text": "section \\<open>Type System\\<close>\ntheory Type_System\nimports Main Gen_Scheduler_Refine Decide_Locality\nbegin\n  text \\<open>Currently only a very basic type system:\n    Checks that no expression contains overflowing numerals,\n    and that all accessed variables exist.\n\\<close>\n\n  section \\<open>Typing of Programs\\<close>\n\n  type_synonym tenv_valuation = \"ident \\<rightharpoonup> unit\"\n  type_synonym tenv_fs = \"tenv_valuation \\<times> tenv_valuation\"\n\n  definition ty_val :: \"tenv_valuation \\<Rightarrow> valuation \\<Rightarrow> bool\" where\n    \"ty_val \\<Gamma> vars \\<equiv> dom \\<Gamma> = dom vars\"\n\n  abbreviation \"ty_local_state \\<Gamma> ls \\<equiv> ty_val \\<Gamma> (local_state.variables ls)\"\n  abbreviation \"ty_global_state \\<Gamma> gs \\<equiv> ty_val \\<Gamma> (global_state.variables gs)\"\n\n  fun ty_fs :: \"tenv_fs \\<Rightarrow> focused_state \\<Rightarrow> bool\" where\n    \"ty_fs (\\<Gamma>l, \\<Gamma>g) (ls,gs) \\<longleftrightarrow> ty_local_state \\<Gamma>l ls \\<and> ty_global_state \\<Gamma>g gs\"\n\n  declare ty_fs.simps[simp del]  \n\n  fun ty_expr :: \"tenv_fs \\<Rightarrow> exp \\<rightharpoonup> unit\"\n  where\n    \"ty_expr (\\<Gamma>l, \\<Gamma>g) (e_var x) = (if x\\<in>dom \\<Gamma>l \\<or> x\\<in>dom \\<Gamma>g then Some () else None)\"\n  | \"ty_expr (\\<Gamma>l, \\<Gamma>g) (e_localvar x) = (if x\\<in>dom \\<Gamma>l then Some () else None)\"\n  | \"ty_expr (\\<Gamma>l, \\<Gamma>g) (e_globalvar x) = (if x\\<in>dom \\<Gamma>g then Some () else None)\"\n  | \"ty_expr _ (e_const c) = (if min_signed \\<le> c \\<and> c \\<le> max_signed then Some () else None)\"\n  | \"ty_expr (\\<Gamma>l, \\<Gamma>g) (e_bin bop e1 e2) = do {\n      ty_expr (\\<Gamma>l, \\<Gamma>g) e1;\n      ty_expr (\\<Gamma>l, \\<Gamma>g) e2;\n      Some ()\n    }\"\n  | \"ty_expr (\\<Gamma>l, \\<Gamma>g) (e_un uop e) = do {\n      ty_expr (\\<Gamma>l, \\<Gamma>g) e;\n      Some ()\n    }\"\n\n  lemma ty_expr_noerr: \n    notes [simp] = ty_fs.simps\n    shows \"ty_fs \\<Gamma> fs \\<Longrightarrow> eval_exp e fs \\<noteq> None \\<longleftrightarrow> ty_expr \\<Gamma> e \\<noteq> None\"\n    apply (induction e)\n    apply (cases fs, cases \\<Gamma>)\n    apply (auto split: option.splits simp: ty_val_def) []\n    apply (cases fs, cases \\<Gamma>)\n    apply (auto split: option.splits simp: ty_val_def) []\n    apply (cases fs, cases \\<Gamma>)\n    apply (auto split: option.splits simp: ty_val_def) []\n    apply (cases fs, cases \\<Gamma>)\n    apply (auto split: option.splits simp: ty_val_def) []\n    apply (cases fs, cases \\<Gamma>)\n    apply (auto split: option.splits Option.bind_splits simp: ty_val_def) []\n    apply (cases fs, cases \\<Gamma>)\n    apply (auto split: option.splits simp: ty_val_def) []\n    done\n\n  lemma ty_expr_noerr': \n    \"ty_fs \\<Gamma> fs \\<Longrightarrow> ty_expr \\<Gamma> e = Some () \\<longleftrightarrow> (\\<exists>v. eval_exp e fs = Some v)\"\n    using ty_expr_noerr\n    by auto\n\n  type_synonym tenv_cmd = \"tenv_fs \\<times> bool\" \n\n  function ty_cmd :: \"tenv_cmd \\<Rightarrow> cmd \\<Rightarrow> bool\" where\n    \"ty_cmd ((\\<Gamma>l,\\<Gamma>g),loop) (Assign c x e) \\<longleftrightarrow> ty_expr (\\<Gamma>l,\\<Gamma>g) c \\<noteq> None \\<and>\n      (x\\<in>dom \\<Gamma>l | x\\<in>dom \\<Gamma>g) \\<and> ty_expr (\\<Gamma>l,\\<Gamma>g) e \\<noteq> None\"\n  | \"ty_cmd ((\\<Gamma>l,\\<Gamma>g),loop) (Assign_local c x e) \\<longleftrightarrow> ty_expr (\\<Gamma>l,\\<Gamma>g) c \\<noteq> None \\<and>\n      (x\\<in>dom \\<Gamma>l) \\<and> ty_expr (\\<Gamma>l,\\<Gamma>g) e \\<noteq> None\"\n  | \"ty_cmd ((\\<Gamma>l,\\<Gamma>g),loop) (Assign_global c x e) \\<longleftrightarrow> ty_expr (\\<Gamma>l,\\<Gamma>g) c \\<noteq> None \\<and>\n      (x\\<in>dom \\<Gamma>g) \\<and> ty_expr (\\<Gamma>l,\\<Gamma>g) e \\<noteq> None\"\n  | \"ty_cmd ((\\<Gamma>l,\\<Gamma>g),loop) (Test e) \\<longleftrightarrow> ty_expr (\\<Gamma>l,\\<Gamma>g) e \\<noteq> None\"\n  | \"ty_cmd ((\\<Gamma>l,\\<Gamma>g),loop) (Skip) \\<longleftrightarrow> True\"\n  | \"ty_cmd ((\\<Gamma>l,\\<Gamma>g),loop) (Seq c1 c2) \\<longleftrightarrow> ty_cmd ((\\<Gamma>l,\\<Gamma>g),loop) c1 \\<and> ty_cmd ((\\<Gamma>l,\\<Gamma>g),loop) c2\"\n  | \"ty_cmd ((\\<Gamma>l,\\<Gamma>g),loop) (Or c1 c2) \\<longleftrightarrow> ty_cmd ((\\<Gamma>l,\\<Gamma>g),loop) c1 \\<and> ty_cmd ((\\<Gamma>l,\\<Gamma>g),loop) c2\"\n  | \"ty_cmd ((\\<Gamma>l,\\<Gamma>g),loop) (Break) \\<longleftrightarrow> loop\"\n  | \"ty_cmd ((\\<Gamma>l,\\<Gamma>g),loop) (Continue) \\<longleftrightarrow> loop\"\n  | \"ty_cmd ((\\<Gamma>l,\\<Gamma>g),loop) (Iterate c1 c2) \\<longleftrightarrow> ty_cmd ((\\<Gamma>l,\\<Gamma>g),True) c1 \\<and> ty_cmd ((\\<Gamma>l,\\<Gamma>g),True) c2\"\n  | \"ty_cmd ((\\<Gamma>l,\\<Gamma>g),loop) (Invalid) \\<longleftrightarrow> False\"\n  by pat_completeness auto\n  \n  termination\n    apply (relation \"inv_image (reachable_term_order_aux <*mlex*> measure size) snd\")\n    apply (auto simp: mlex_prod_def)\n    done\n    \n  theorem ty_cmd_no_internal: \"ty_cmd (\\<Gamma>,False) c \\<Longrightarrow> cfg c a c' \\<Longrightarrow> isl a\"\n    apply (rotate_tac)\n    apply (induction rule: cfg.induct)\n    apply (cases \\<Gamma>, (auto) [])+\n    done\n\n  lemma ty_cmd_pres_aux: \"ty_cmd ((\\<Gamma>l,\\<Gamma>g),loop) c \\<Longrightarrow> cfg c a c' \\<Longrightarrow> \n    (ty_cmd ((\\<Gamma>l,\\<Gamma>g),loop) c' \\<or> a=Inr AIBreak \\<or> a=Inr AIContinue)\"  \n    apply (rotate_tac)\n    apply (induction arbitrary: loop rule: cfg.induct)\n    apply auto\n    done\n  \n  corollary ty_cmd_pres: \n    \"ty_cmd ((\\<Gamma>l,\\<Gamma>g),False) c \\<Longrightarrow> cfg c a c' \\<Longrightarrow> ty_cmd ((\\<Gamma>l,\\<Gamma>g),False) c'\"\n    apply (frule (1) ty_cmd_pres_aux)\n    apply (frule (1) ty_cmd_no_internal)\n    apply auto\n    done\n\n  definition ty_proc_decl :: \"tenv_valuation \\<Rightarrow> proc_decl \\<Rightarrow> bool\" where\n    \"ty_proc_decl \\<Gamma>g pd \\<equiv> let\n      \\<Gamma>l = (\\<lambda>x. if x \\<in> set (proc_decl.local_vars pd) then Some () else None)\n    in\n      ty_cmd ((\\<Gamma>l,\\<Gamma>g),False) (proc_decl.body pd)\"\n\n  definition ty_program :: \"program \\<Rightarrow> bool\" where\n    \"ty_program prog == let\n      \\<Gamma>g = (\\<lambda>x. if x\\<in>set (program.global_vars prog) then Some () else None)\n    in\n      \\<forall>pd\\<in>set (program.processes prog). ty_proc_decl \\<Gamma>g pd\"\n\n  definition ty_local :: \"cmd \\<Rightarrow> local_state \\<Rightarrow> global_state \\<Rightarrow> bool\" where\n    \"ty_local c ls gs \\<equiv> \\<exists>\\<Gamma>. ty_cmd (\\<Gamma>,False) c \\<and> ty_fs \\<Gamma> (ls,gs)\"\n\n  definition \"cfg' c a c' \\<equiv> cfg c (Inl a) c'\"\n  lemma cfg'_eq: \"ty_cmd (\\<Gamma>,False) c \\<Longrightarrow> cfg c a c' \\<longleftrightarrow> (\\<exists>aa. a=Inl aa \\<and> cfg' c aa c')\"\n    by (cases a) (auto dest: ty_cmd_no_internal[of _ c a c'] simp: cfg'_def)\n\n  lemma cfg_eq: \"ty_cmd (\\<Gamma>,False) c \\<Longrightarrow> cfg' c a c' \\<longleftrightarrow> cfg c (Inl a) c'\" \n    by (auto simp: cfg'_eq)\n\n  section \\<open>Typing of Actions\\<close>  \n  text \\<open>\n    We split the proof that steps from well-typed configurations\n    do not fail and preserve well-typedness in two steps:\n    \n    First, we show that actions from well-types commands are well-typed.\n    Then, we show that well-typed actions do not fail, and preserve \n      well-typedness.\n\\<close>\n\n\n  fun ty_la :: \"tenv_fs \\<Rightarrow> action \\<Rightarrow> bool\" where\n    \"ty_la (\\<Gamma>l,\\<Gamma>g) (AAssign c x e) \\<longleftrightarrow> ty_expr (\\<Gamma>l,\\<Gamma>g) c \\<noteq> None \\<and>\n      (x\\<in>dom \\<Gamma>l \\<or> x\\<in>dom \\<Gamma>g) \\<and> ty_expr (\\<Gamma>l,\\<Gamma>g) e \\<noteq> None\"  \n  | \"ty_la (\\<Gamma>l,\\<Gamma>g) (AAssign_local c x e) \\<longleftrightarrow> ty_expr (\\<Gamma>l,\\<Gamma>g) c \\<noteq> None \\<and>\n      x\\<in>dom \\<Gamma>l \\<and> ty_expr (\\<Gamma>l,\\<Gamma>g) e \\<noteq> None\"\n  | \"ty_la (\\<Gamma>l,\\<Gamma>g) (AAssign_global c x e) \\<longleftrightarrow> ty_expr (\\<Gamma>l,\\<Gamma>g) c \\<noteq> None \\<and>\n      x\\<in>dom \\<Gamma>g \\<and> ty_expr (\\<Gamma>l,\\<Gamma>g) e \\<noteq> None\"\n  | \"ty_la (\\<Gamma>l,\\<Gamma>g) (ATest e) \\<longleftrightarrow> ty_expr (\\<Gamma>l,\\<Gamma>g) e \\<noteq> None\"\n  | \"ty_la (\\<Gamma>l,\\<Gamma>g) (ASkip) \\<longleftrightarrow> True\"\n\n\n  lemma ty_cmd_imp_ty_la_aux:\n    assumes \"ty_cmd (\\<Gamma>,loop) c\"\n    assumes \"cfg c (Inl a) c'\"\n    shows \"ty_la \\<Gamma> a\"\n    using assms (2,1)\n    apply (induction c \"Inl a::action+brk_ctd\" c' arbitrary: loop)\n    apply (case_tac [!] \\<Gamma>)\n    apply auto\n    done\n\n  lemma ty_cmd_imp_ty_la:\n    assumes \"ty_cmd (\\<Gamma>,False) c\"\n    assumes \"cfg' c a c'\"\n    shows \"ty_la \\<Gamma> a\"\n    using assms\n    unfolding cfg_eq[OF assms(1)]\n    by (rule ty_cmd_imp_ty_la_aux)\n\n  lemma ty_en_defined:\n    assumes \"ty_fs \\<Gamma> fs\"\n    assumes \"ty_la \\<Gamma> a\"\n    shows \"la_en fs a \\<noteq> None\"\n    using assms\n    apply (cases \\<Gamma>, cases fs)\n    apply (cases a)\n    apply (auto\n      split: Option.bind_splits \n      dest: ty_expr_noerr)\n    done\n\n  lemma ty_ex_defined:  \n    assumes \"ty_fs \\<Gamma> fs\"\n    assumes \"ty_la \\<Gamma> a\"\n    assumes \"la_en fs a = Some True\"\n    shows \"la_ex fs a \\<noteq> None\"\n    using assms\n    apply (cases \\<Gamma>, cases fs)\n    apply (cases a)\n    apply (auto\n      split: Option.bind_splits \n      dest: ty_expr_noerr, \n      auto simp: ty_val_def ty_fs.simps)\n    apply blast+\n    done\n\n  lemma ty_ex_pres:\n    assumes \"ty_fs \\<Gamma> fs\"\n    assumes \"la_ex fs a = Some fs'\"\n    shows \"ty_fs \\<Gamma> fs'\"\n    using assms\n    apply (cases \\<Gamma>, cases fs)\n    apply (cases a)\n    apply (auto\n      split: Option.bind_splits if_split_asm \n      dest: ty_expr_noerr, \n      auto simp: ty_val_def ty_fs.simps)\n    done\n\n\n  section \\<open>Actions that do not fail\\<close>  \n\n  text \\<open>\n    We define a refinement of the actions, which \n    map failure to not enabled/identity.\n    \n    This allows for simple POR-related proofs, as non-failure can\n    be assumed.\n  \\<close>\n  definition \"la_en' fs a \\<equiv> case la_en fs a of Some b \\<Rightarrow> b | None \\<Rightarrow> False\"\n  definition \"la_ex' fs a \\<equiv> case la_ex fs a of Some fs' \\<Rightarrow> fs' | None \\<Rightarrow> fs\"\n\n  interpretation li': Gen_Scheduler'_linit cfg' la_en' la_ex' \"{init_gc prog}\" global_config.state\n    for prog .\n\n  interpretation li': sched_typing\n    cfg la_en la_ex\n    cfg' la_en' la_ex'\n    ty_local\n    apply unfold_locales\n    unfolding ty_local_def\n    apply (auto \n      simp: cfg'_eq\n      simp: la_en'_def dest: ty_en_defined[OF _ ty_cmd_imp_ty_la]\n      simp: la_ex'_def dest: ty_ex_defined[OF _ ty_cmd_imp_ty_la]\n      dest: ty_ex_pres ty_cmd_pres\n      split: option.splits\n      ) [4]\n\n    apply (clarsimp)\n    apply (intro exI conjI)\n    apply assumption+\n    apply (frule (1) ty_ex_pres)\n    apply (simp add: ty_val_def ty_fs.simps)\n    done\n    \n  locale well_typed_prog =\n    fixes prog\n    assumes well_typed_prog: \"ty_program prog\"\n  begin\n    lemma ty_init[simp, intro!]: \"li'.wf_gglobal (init_gc prog)\"\n      using well_typed_prog\n      apply (auto \n        simp: in_multiset_in_set\n        simp: init_gc_def init_pc_def li'.wf_gglobal_def ty_local_def\n        simp: ty_program_def ty_proc_decl_def\n        dest!: split_list)\n      apply (intro exI conjI)\n      apply assumption\n      apply (auto \n        simp: ty_fs.simps ty_val_def init_valuation_def \n        split: if_split_asm\n        )\n      done\n \n    sublocale li': sched_typing_init\n      cfg la_en la_ex\n      cfg' la_en' la_ex'\n      \"{init_gc prog}\" global_config.state\n      ty_local\n      apply unfold_locales\n      by auto\n\n    lemma \"li'.sa.accept prog = ref_accept prog\"  \n      by (rule li'.accept_eq)\n\n    lemma \"ref_is_run prog r \\<longleftrightarrow> (\\<exists>r'. r=Some o r' \\<and> li'.sa.is_run prog r')\"  \n      by (rule li'.is_run_conv)\n\n  end\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/CAVA_LTL_Modelchecker/SM/Refine/Type_System.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5506073655352404, "lm_q2_score": 0.476579651063676, "lm_q1q2_score": 0.2624082661398748}}
{"text": "section \\<open>Refinement Rule Management\\<close>\ntheory Sepref_Rules\nimports Sepref_Basic Sepref_Constraints\nbegin\n  text \\<open>This theory contains tools for managing the refinement rules used by Sepref\\<close>\n\n  text \\<open>The theories are based on uncurried functions, i.e.,\n    every function has type @{typ \"'a\\<Rightarrow>'b\"}, where @{typ 'a} is the \n    tuple of parameters, or unit if there are none.\n    \\<close>\n\n    \n  definition \"non_dep R \\<equiv> \\<forall>b. R b = R undefined\"\n  lemma non_dep_simp: \"non_dep R \\<Longrightarrow> NO_MATCH undefined x \\<Longrightarrow> R x = R undefined\"\n    by (auto simp: non_dep_def)\n    \n  lemma non_dep_K[simp, intro!]: \"non_dep (\\<lambda>_. c)\"  \n    by (auto simp: non_dep_def)\n    \n  definition \"non_dep2 R \\<equiv> \\<forall>a b. R a b = R undefined undefined\"\n  lemma non_dep2_simp: \n    \"non_dep2 R \\<Longrightarrow> NO_MATCH undefined x \\<Longrightarrow> R x y = R undefined undefined\"\n    \"non_dep2 R \\<Longrightarrow> NO_MATCH undefined y \\<Longrightarrow> R x y = R undefined undefined\"\n    by (auto simp: non_dep2_def)\n    \n  lemma non_dep2_K[simp, intro!]: \"non_dep2 (\\<lambda>_ _. c)\"  \n    by (auto simp: non_dep2_def)\n    \n    \n    \n\n  subsection \\<open>Assertion Interface Binding\\<close>\n  text \\<open>Binding of interface types to refinement assertions\\<close>\n  definition intf_of_assn :: \"('a \\<Rightarrow> _ \\<Rightarrow> assn) \\<Rightarrow> 'b itself \\<Rightarrow> bool\" where\n    [simp]: \"intf_of_assn a b = True\"\n\n  lemma intf_of_assnI: \"intf_of_assn R TYPE('a)\" by simp\n  \n  named_theorems_rev intf_of_assn \\<open>Links between refinement assertions and interface types\\<close>  \n\n  lemma intf_of_assn_fallback: \"intf_of_assn (R :: 'a \\<Rightarrow> _ \\<Rightarrow> assn) TYPE('a)\" by simp\n\n  subsection \\<open>Function Refinement with Precondition\\<close>\n  definition fref :: \"('c \\<Rightarrow> bool) \\<Rightarrow> ('a \\<times> 'c) set \\<Rightarrow> ('c \\<Rightarrow> ('b \\<times> 'd) set)\n           \\<Rightarrow> (('a \\<Rightarrow> 'b) \\<times> ('c \\<Rightarrow> 'd)) set\"\n    (\"[_]\\<^sub>f\\<^sub>d _ \\<rightarrow> _\" [0,60,60] 60)         \n  where \"[P]\\<^sub>f\\<^sub>d R \\<rightarrow> S \\<equiv> {(f,g). \\<forall>x y. P y \\<and> (x,y)\\<in>R \\<longrightarrow> (f x, g y)\\<in>S y}\"\n  \n  abbreviation freft (\"_ \\<rightarrow>\\<^sub>f\\<^sub>d _\" [60,60] 60) where \"R \\<rightarrow>\\<^sub>f\\<^sub>d S \\<equiv> ([\\<lambda>_. True]\\<^sub>f\\<^sub>d R \\<rightarrow> S)\"\n  abbreviation freftnd (\"_ \\<rightarrow>\\<^sub>f _\" [60,60] 60) where \"R \\<rightarrow>\\<^sub>f S \\<equiv> ([\\<lambda>_. True]\\<^sub>f\\<^sub>d R \\<rightarrow> (\\<lambda>_. S))\"\n  abbreviation frefnd (\"[_]\\<^sub>f _ \\<rightarrow> _\" [0,60,60] 60) where \"[P]\\<^sub>f R \\<rightarrow> S \\<equiv> [P]\\<^sub>f\\<^sub>d R \\<rightarrow> (\\<lambda>_. S)\"\n\n  \n  \n  \n\n  lemma fref_cons:  \n    assumes \"(f,g) \\<in> [P]\\<^sub>f\\<^sub>d R \\<rightarrow> S\"\n    assumes \"\\<And>c a. (c,a)\\<in>R' \\<Longrightarrow> Q a \\<Longrightarrow> P a\"\n    assumes \"R' \\<subseteq> R\"\n    assumes \"\\<And>c a. \\<lbrakk>(c,a)\\<in>R'; Q a\\<rbrakk> \\<Longrightarrow> S a \\<subseteq> S' a\"\n    shows \"(f,g) \\<in> [Q]\\<^sub>f\\<^sub>d R' \\<rightarrow> S'\"\n    using assms\n    unfolding fref_def\n    by fastforce\n\n  lemmas fref_cons' = fref_cons[OF _ _ order_refl order_refl]  \n\n  lemma frefI[intro?]: \n    assumes \"\\<And>x y. \\<lbrakk>P y; (x,y)\\<in>R\\<rbrakk> \\<Longrightarrow> (f x, g y)\\<in>S y\"\n    shows \"(f,g)\\<in>fref P R S\"\n    using assms\n    unfolding fref_def\n    by auto\n\n  lemma fref_ncI: \"(f,g)\\<in>R\\<rightarrow>S \\<Longrightarrow> (f,g)\\<in>R\\<rightarrow>\\<^sub>fS\"  \n    apply (rule frefI)\n    apply parametricity\n    done\n\n  lemma frefD: \n    assumes \"(f,g)\\<in>fref P R S\"\n    shows \"\\<lbrakk>P y; (x,y)\\<in>R\\<rbrakk> \\<Longrightarrow> (f x, g y)\\<in>S y\"\n    using assms\n    unfolding fref_def\n    by auto\n\n  lemma fref_ncD: \"(f,g)\\<in>R\\<rightarrow>\\<^sub>fS \\<Longrightarrow> (f,g)\\<in>R\\<rightarrow>S\"  \n    apply (rule fun_relI)\n    apply (drule frefD)\n    apply simp\n    apply assumption+\n    done\n\n\n      \n  definition \"rr_comp S R1 R2 x \\<equiv> if non_dep R1 then R1 undefined O R2 x else (\\<Union>{R1 y | y. (y,x)\\<in>S}) O R2 x\"  \n    \n  lemma rr_comp_K[simp]: \"rr_comp S (\\<lambda>_. R1) R2 = (\\<lambda>x. R1 O R2 x)\"\n    by (auto simp: rr_comp_def fun_eq_iff)\n\n  lemma rr_comp_nondep: \"rr_comp T (\\<lambda>_. A) R = (\\<lambda>x. A O (R x))\"\n    unfolding rr_comp_def\n    by (auto simp: fun_eq_iff)\n    \n      \n  lemma fref_compI: \n    \"fref P R1 R2 O fref Q S1 S2 \\<subseteq>\n      fref (\\<lambda>x. Q x \\<and> (\\<forall>y. (y,x)\\<in>S1 \\<longrightarrow> P y)) (R1 O S1) (rr_comp S1 R2 S2)\"\n    unfolding fref_def rr_comp_def \n    apply (cases \"non_dep R2\"; simp)\n    subgoal by (fastforce simp: non_dep_simp[of R2])\n    subgoal by fastforce\n    done\n    \n  lemma fref_compI':\n    \"\\<lbrakk> (f,g)\\<in>fref P R1 R2; (g,h)\\<in>fref Q S1 S2 \\<rbrakk> \n      \\<Longrightarrow> (f,h) \\<in> fref (\\<lambda>x. Q x \\<and> (\\<forall>y. (y,x)\\<in>S1 \\<longrightarrow> P y)) (R1 O S1) (rr_comp S1 R2 S2)\"\n    using fref_compI[of P R1 R2 Q S1 S2]   \n    by auto\n\n  lemma fref_unit_conv:\n    \"(\\<lambda>_. c, \\<lambda>_. a) \\<in> fref P unit_rel S \\<longleftrightarrow> (P () \\<longrightarrow> (c,a)\\<in>S ())\"   \n    by (auto simp: fref_def)\n\n  lemma fref_uncurry_conv:\n    \"(uncurry c, uncurry a) \\<in> fref P (R1\\<times>\\<^sub>rR2) S \n    \\<longleftrightarrow> (\\<forall>x1 y1 x2 y2. P (y1,y2) \\<longrightarrow> (x1,y1)\\<in>R1 \\<longrightarrow> (x2,y2)\\<in>R2 \\<longrightarrow> (c x1 x2, a y1 y2) \\<in> S (y1,y2))\"\n    by (auto simp: fref_def)\n\n  lemma fref_mono: \"\\<lbrakk> \\<And>x. P' x \\<Longrightarrow> P x; R' \\<subseteq> R; \\<And>x y. P' x \\<Longrightarrow> S x \\<subseteq> S' x \\<rbrakk> \n    \\<Longrightarrow> fref P R S \\<subseteq> fref P' R' S'\"  \n    unfolding fref_def\n    by auto blast\n\n  lemma fref_composeI:\n    assumes FR1: \"(f,g)\\<in>fref P R1 R2\"\n    assumes FR2: \"(g,h)\\<in>fref Q S1 S2\"\n    assumes C1: \"\\<And>x. P' x \\<Longrightarrow> Q x\"\n    assumes C2: \"\\<And>x y. \\<lbrakk>P' x; (y,x)\\<in>S1\\<rbrakk> \\<Longrightarrow> P y\"\n    assumes R1: \"R' \\<subseteq> R1 O S1\"\n    assumes R2: \"\\<And>x. \\<lbrakk> P' x \\<rbrakk> \\<Longrightarrow> rr_comp S1 R2 S2 x \\<subseteq> S' x\"\n    assumes FH: \"f'=f\" \"h'=h\"\n    shows \"(f',h') \\<in> fref P' R' S'\"\n    unfolding FH\n    apply (rule set_mp[OF fref_mono fref_compI'[OF FR1 FR2]])\n    using C1 C2 apply blast\n    using R1 apply blast\n    using R2 apply blast\n    done\n\n  lemma fref_triv: \"A\\<subseteq>Id \\<Longrightarrow> (f,f)\\<in>[P]\\<^sub>f A \\<rightarrow> Id\"\n    by (auto simp: fref_def)\n\n\n  subsection \\<open>Heap-Function Refinement\\<close>\n  text \\<open>\n    The following relates a heap-function with a pure function.\n    It contains a precondition, a refinement assertion for the arguments\n    before and after execution, and a refinement relation for the result.\n    \\<close>\n  (* TODO: We only use this with keep/destroy information, so we could model\n    the parameter relations as such (('a\\<Rightarrow>'ai \\<Rightarrow> assn) \\<times> bool) *)\n  definition hfref \n    :: \"\n      ('a \\<Rightarrow> bool) \n   \\<Rightarrow> (('a \\<Rightarrow> 'ai \\<Rightarrow> assn) \\<times> ('a \\<Rightarrow> 'ai \\<Rightarrow> assn)) \n   \\<Rightarrow> ('a \\<Rightarrow> 'ai \\<Rightarrow> 'b \\<Rightarrow> 'bi \\<Rightarrow> assn) \n   \\<Rightarrow> (('ai \\<Rightarrow> 'bi llM) \\<times> ('a\\<Rightarrow>'b nres)) set\"\n   (\"[_]\\<^sub>a\\<^sub>d _ \\<rightarrow> _\" [0,60,60] 60)\n   where\n    \"[P]\\<^sub>a\\<^sub>d RS \\<rightarrow> T \\<equiv> { (f,g) . \\<forall>c a.  P a \\<longrightarrow> hn_refine (fst RS a c) (f c) (snd RS a c) (T a c) (g a)}\"\n\n  abbreviation hfrefnd (\"[_]\\<^sub>a _ \\<rightarrow> _\" [0,60,60] 60) where \"[P]\\<^sub>a RS \\<rightarrow> T \\<equiv> ([P]\\<^sub>a\\<^sub>d RS \\<rightarrow> (\\<lambda>_ _. T))\"\n  abbreviation hfreft (\"_ \\<rightarrow>\\<^sub>a\\<^sub>d _\" [60,60] 60) where \"RS \\<rightarrow>\\<^sub>a\\<^sub>d T \\<equiv> ([\\<lambda>_. True]\\<^sub>a\\<^sub>d RS \\<rightarrow> T)\"\n  abbreviation hfreftnd (\"_ \\<rightarrow>\\<^sub>a _\" [60,60] 60) where \"RS \\<rightarrow>\\<^sub>a T \\<equiv> [\\<lambda>_. True]\\<^sub>a RS \\<rightarrow> T\"\n\n  lemma hfrefI[intro?]: \n    assumes \"\\<And>c a. P a \\<Longrightarrow> hn_refine (fst RS a c) (f c) (snd RS a c) (T a c) (g a)\"\n    shows \"(f,g)\\<in>hfref P RS T\"\n    using assms unfolding hfref_def by blast\n\n  lemma hfrefD: \n    assumes \"(f,g)\\<in>hfref P RS T\"\n    shows \"\\<And>c a. P a \\<Longrightarrow> hn_refine (fst RS a c) (f c) (snd RS a c) (T a c) (g a)\"\n    using assms unfolding hfref_def by blast\n\n  lemma hfref_to_ASSERT_conv: \n    \"NO_MATCH (\\<lambda>_. True) P \\<Longrightarrow> (a,b)\\<in>[P]\\<^sub>a\\<^sub>d R \\<rightarrow> S \\<longleftrightarrow> (a,\\<lambda>x. doN {ASSERT (P x); b x}) \\<in> R \\<rightarrow>\\<^sub>a\\<^sub>d S\"  \n    unfolding hfref_def\n    apply (clarsimp; safe; clarsimp?)\n    apply (rule hn_refine_nofailI)\n    apply (simp add: refine_pw_simps)\n    subgoal for xc xa\n      apply (drule spec[of _ xc])\n      apply (drule spec[of _ xa])\n      by simp\n    done\n\n  text \\<open>\n    A pair of argument refinement assertions can be created by the \n    input assertion and the information whether the parameter is kept or destroyed\n    by the function.\n    \\<close>  \n  primrec hf_pres \n    :: \"('a \\<Rightarrow> 'b \\<Rightarrow> assn) \\<Rightarrow> bool \\<Rightarrow> ('a \\<Rightarrow> 'b \\<Rightarrow> assn)\\<times>('a \\<Rightarrow> 'b \\<Rightarrow> assn)\"\n    where \n      \"hf_pres R True = (R,R)\" | \"hf_pres R False = (R,invalid_assn R)\"\n\n  abbreviation hfkeep \n    :: \"('a \\<Rightarrow> 'b \\<Rightarrow> assn) \\<Rightarrow> ('a \\<Rightarrow> 'b \\<Rightarrow> assn)\\<times>('a \\<Rightarrow> 'b \\<Rightarrow> assn)\" \n    (\"(_\\<^sup>k)\" [1000] 999)\n    where \"R\\<^sup>k \\<equiv> hf_pres R True\"\n  abbreviation hfdrop \n    :: \"('a \\<Rightarrow> 'b \\<Rightarrow> assn) \\<Rightarrow> ('a \\<Rightarrow> 'b \\<Rightarrow> assn)\\<times>('a \\<Rightarrow> 'b \\<Rightarrow> assn)\" \n    (\"(_\\<^sup>d)\" [1000] 999)\n    where \"R\\<^sup>d \\<equiv> hf_pres R False\"\n\n  abbreviation \"hn_kede R kd \\<equiv> hn_ctxt (snd (hf_pres R kd))\"\n  abbreviation \"hn_keep R \\<equiv> hn_kede R True\"\n  abbreviation \"hn_dest R \\<equiv> hn_kede R False\"\n\n  lemma keep_drop_sels[simp]:  \n    \"fst (R\\<^sup>k) = R\"\n    \"snd (R\\<^sup>k) = R\"\n    \"fst (R\\<^sup>d) = R\"\n    \"snd (R\\<^sup>d) = invalid_assn R\"\n    by auto\n\n  lemma hf_pres_fst[simp]: \"fst (hf_pres R k) = R\" by (cases k) auto\n\n  text \\<open>\n    The following operator combines multiple argument assertion-pairs to\n    argument assertion-pairs for the product. It is required to state\n    argument assertion-pairs for uncurried functions.\n    \\<close>  \n  definition hfprod :: \"\n    (('a \\<Rightarrow> 'b \\<Rightarrow> assn)\\<times>('a \\<Rightarrow> 'b \\<Rightarrow> assn)) \n    \\<Rightarrow> (('c \\<Rightarrow> 'd \\<Rightarrow> assn)\\<times>('c \\<Rightarrow> 'd \\<Rightarrow> assn))\n    \\<Rightarrow> ((('a\\<times>'c) \\<Rightarrow> ('b \\<times> 'd) \\<Rightarrow> assn) \\<times> (('a\\<times>'c) \\<Rightarrow> ('b \\<times> 'd) \\<Rightarrow> assn))\"\n    (infixl \"*\\<^sub>a\" 65)\n    where \"RR *\\<^sub>a SS \\<equiv> (prod_assn (fst RR) (fst SS), prod_assn (snd RR) (snd SS))\"\n\n  lemma hfprod_fst_snd[simp]:\n    \"fst (A *\\<^sub>a B) = prod_assn (fst A) (fst B)\" \n    \"snd (A *\\<^sub>a B) = prod_assn (snd A) (snd B)\" \n    unfolding hfprod_def by auto\n\n\n\n  subsubsection \\<open>Conversion from fref to hfref\\<close>  \n  (* TODO: Variant of import-param! Automate this! *)\n  lemma fref_to_pure_hfref':\n    assumes \"(f,g) \\<in> [P]\\<^sub>f R\\<rightarrow>\\<langle>S\\<rangle>nres_rel\"\n    assumes \"\\<And>x. x\\<in>Domain R \\<inter> R\\<inverse>``Collect P \\<Longrightarrow> f x = RETURN (f' x)\"\n    shows \"(return o f', g) \\<in> [P]\\<^sub>a (pure R)\\<^sup>k\\<rightarrow>pure S\"\n  proof -\n  \n    {\n      fix c a\n      assume A: \"P a\" \"nofail (g a)\" \"(c, a) \\<in> R\"\n      hence \"\\<exists>x. (f' c, x) \\<in> S \\<and> RETURN x \\<le> g a\" \n        using assms\n        by (fastforce simp: fref_def pw_le_iff pw_nres_rel_iff refine_pw_simps)\n        \n      hence \"ENTAILS F ((\\<up>((c, a) \\<in> R) \\<and>* (\\<lambda>s. \\<exists>x. (\\<up>((f' c, x) \\<in> S) \\<and>* \\<up>(RETURN x \\<le> g a)) s)) \\<and>* F)\" \n        for F :: assn \n        using A by vcg\n    } note AUX=this \n    \n    show ?thesis\n      apply (rule hfrefI) apply (rule hn_refineI)\n      unfolding pure_def \n      apply vcg\n      apply (rule AUX)\n      .\n  qed      \n\n\n  subsubsection \\<open>Conversion from hfref to hnr\\<close>  \n  text \\<open>This section contains the lemmas. The ML code is further down. \\<close>\n  lemma hf2hnr:\n    assumes \"(f,g) \\<in> [P]\\<^sub>a\\<^sub>d R \\<rightarrow> S\"\n    shows \"\\<forall>x xi. P x \\<longrightarrow> hn_refine (hn_ctxt (fst R) x xi ** \\<box>) (f$xi) (hn_ctxt (snd R) x xi ** \\<box>) (S x xi) (g$x)\"\n    using assms\n    unfolding hfref_def \n    by (auto simp: hn_ctxt_def)\n\n  (* Products that stem from currying are tagged by a special refinement relation *)  \n  definition [simp]: \"to_hnr_prod \\<equiv> prod_assn\"\n\n  lemma to_hnr_prod_fst_snd:\n    \"fst (A *\\<^sub>a B) = to_hnr_prod (fst A) (fst B)\" \n    \"snd (A *\\<^sub>a B) = to_hnr_prod (snd A) (snd B)\" \n    unfolding hfprod_def by auto\n\n  (* Warning: This lemma is carefully set up to be applicable as an unfold rule,\n    for more than one level of uncurrying*)\n  lemma hnr_uncurry_unfold: \"\n    (\\<forall>x xi. P x \\<longrightarrow> \n      hn_refine \n        (hn_ctxt (to_hnr_prod A B) x xi ** \\<Gamma>) \n        (fi xi) \n        (hn_ctxt (to_hnr_prod A' B') x xi ** \\<Gamma>') \n        (R x xi) \n        (f x))\n\\<longleftrightarrow> (\\<forall>b bi a ai. P (a,b) \\<longrightarrow>\n      hn_refine \n        (hn_ctxt A a ai ** hn_ctxt B b bi ** \\<Gamma>) \n        (fi (ai,bi)) \n        (hn_ctxt A' a ai ** hn_ctxt B' b bi ** \\<Gamma>')\n        (R (a,b) (ai,bi))\n        (f (a,b))\n    )\"\n    by (auto simp: hn_ctxt_def prod_assn_def sep_conj_ac)\n    \n  (*  \n  lemma hnr_intro_dummy:\n    \"\\<forall>x xi. P x \\<longrightarrow> hn_refine (\\<Gamma> x xi) (c xi) (\\<Gamma>' x xi) (R x) (a x) \\<Longrightarrow> \\<forall>x xi. P x \\<longrightarrow> hn_refine (\\<Gamma> x xi ** \\<box>) (c xi) (\\<Gamma>' x xi ** \\<box>) (R x) (a x)\" \n    by simp\n  *)\n\n  lemma hn_ctxt_ctxt_fix_conv: \"hn_ctxt (hn_ctxt R) = hn_ctxt R\"\n    by (simp add: hn_ctxt_def[abs_def])\n\n  lemma uncurry_APP: \"uncurry f$(a,b) = f$a$b\" by auto\n\n  (* TODO: Replace by more general rule. *)  \n  lemma norm_RETURN_o: \n    \"\\<And>f. (RETURN o f)$x = (RETURN$(f$x))\"\n    \"\\<And>f. (RETURN oo f)$x$y = (RETURN$(f$x$y))\"\n    \"\\<And>f. (RETURN ooo f)$x$y$z = (RETURN$(f$x$y$z))\"\n    \"\\<And>f. (\\<lambda>x. RETURN ooo f x)$x$y$z$a = (RETURN$(f$x$y$z$a))\"\n    \"\\<And>f. (\\<lambda>x y. RETURN ooo f x y)$x$y$z$a$b = (RETURN$(f$x$y$z$a$b))\"\n    by auto\n\n  lemma norm_return_o: \n    \"\\<And>f. (return o f)$x = (return$(f$x))\"\n    \"\\<And>f. (return oo f)$x$y = (return$(f$x$y))\"\n    \"\\<And>f. (return ooo f)$x$y$z = (return$(f$x$y$z))\"\n    \"\\<And>f. (\\<lambda>x. return ooo f x)$x$y$z$a = (return$(f$x$y$z$a))\"\n    \"\\<And>f. (\\<lambda>x y. return ooo f x y)$x$y$z$a$b = (return$(f$x$y$z$a$b))\"\n    by auto\n\n  \n  lemma hn_val_unit_conv_emp[simp]: \"hn_val unit_rel x y = \\<box>\"\n    by (auto simp: hn_ctxt_def pure_def sep_algebra_simps)\n\n  subsubsection \\<open>Conversion from hnr to hfref\\<close>  \n  text \\<open>This section contains the lemmas. The ML code is further down. \\<close>\n\n  abbreviation \"id_assn \\<equiv> pure Id\"\n  abbreviation \"unit_assn \\<equiv> id_assn :: unit \\<Rightarrow> _\"\n\n  lemma pure_unit_rel_eq_empty: \"unit_assn x y = \\<box>\"  \n    by (auto simp: pure_def sep_algebra_simps)\n\n  lemma uc_hfprod_sel:\n    \"fst (A *\\<^sub>a B) a c = (case (a,c) of ((a1,a2),(c1,c2)) \\<Rightarrow> fst A a1 c1 ** fst B a2 c2)\" \n    \"snd (A *\\<^sub>a B) a c = (case (a,c) of ((a1,a2),(c1,c2)) \\<Rightarrow> snd A a1 c1 ** snd B a2 c2)\" \n    by auto\n\n  subsubsection \\<open>Conversion from relation to fref\\<close>  \n  text \\<open>This section contains the lemmas. The ML code is further down. \\<close>\n\n  definition \"CURRY R \\<equiv> { (f,g). (uncurry f, uncurry g) \\<in> R }\"\n\n  lemma fref_param1: \"R\\<rightarrow>S = R\\<rightarrow>\\<^sub>fS\"  \n    by (auto simp: fref_def fun_relD)\n\n  lemma fref_nest: \"[P1]\\<^sub>f R1 \\<rightarrow> ([P2]\\<^sub>f R2 \\<rightarrow> S) \n    \\<equiv> CURRY ([(\\<lambda>(a,b). P1 a \\<and> P2 b)]\\<^sub>f (R1\\<times>\\<^sub>rR2) \\<rightarrow> S)\"\n    apply (rule eq_reflection)\n    by (auto simp: fref_def CURRY_def)\n\n  lemma in_CURRY_conv: \"(f,g) \\<in> CURRY R \\<longleftrightarrow> (uncurry f, uncurry g) \\<in> R\"  \n    unfolding CURRY_def by auto\n\n  lemma uncurry0_APP[simp]: \"uncurry0 c $ x = c\" by auto\n\n  lemma fref_param0I: \"(c,a)\\<in>R \\<Longrightarrow> (uncurry0 c, uncurry0 a) \\<in> unit_rel \\<rightarrow>\\<^sub>f R\"\n    by (auto simp: fref_def)\n\n  subsubsection \\<open>Composition\\<close>\n  definition hr_comp :: \"('b \\<Rightarrow> 'c \\<Rightarrow> assn) \\<Rightarrow> ('b \\<times> 'a) set \\<Rightarrow> 'a \\<Rightarrow> 'c \\<Rightarrow> assn\"\n    \\<comment> \\<open>Compose refinement assertion with refinement relation\\<close>\n    where \"hr_comp R1 R2 a c \\<equiv> EXS b. R1 b c ** \\<up>((b,a)\\<in>R2)\"\n\n  definition hrp_comp \n    :: \"('d \\<Rightarrow> 'b \\<Rightarrow> assn) \\<times> ('d \\<Rightarrow> 'c \\<Rightarrow> assn)\n        \\<Rightarrow> ('d \\<times> 'a) set \\<Rightarrow> ('a \\<Rightarrow> 'b \\<Rightarrow> assn) \\<times> ('a \\<Rightarrow> 'c \\<Rightarrow> assn)\"\n    \\<comment> \\<open>Compose argument assertion-pair with refinement relation\\<close>    \n    where \"hrp_comp RR' S \\<equiv> (hr_comp (fst RR') S, hr_comp (snd RR') S) \"\n\n  lemma hr_compI: \"(b,a)\\<in>R2 \\<Longrightarrow> R1 b c \\<turnstile> hr_comp R1 R2 a c\"  \n    unfolding hr_comp_def\n    by (auto simp: sep_algebra_simps entails_def pred_lift_extract_simps)\n\n  lemma hr_comp_Id1[simp]: \"hr_comp (pure Id) R = pure R\"  \n    unfolding hr_comp_def[abs_def] pure_def\n    apply (intro ext)\n    by (auto simp: pred_lift_extract_simps)\n\n  lemma hr_comp_Id2[simp]: \"hr_comp R Id = R\"  \n    unfolding hr_comp_def[abs_def]\n    apply (intro ext)\n    by (auto simp: sep_algebra_simps pred_lift_extract_simps)\n    \n  lemma hr_comp_emp[simp]: \"hr_comp (\\<lambda>a c. \\<box>) R a c = \\<up>(\\<exists>b. (b,a)\\<in>R)\"\n    unfolding hr_comp_def[abs_def]\n    apply (intro ext)\n    by (auto simp: sep_algebra_simps pred_lift_extract_simps)\n\n  lemma hr_comp_prod_conv[simp]:\n    \"hr_comp (prod_assn Ra Rb) (Ra' \\<times>\\<^sub>r Rb') \n    = prod_assn (hr_comp Ra Ra') (hr_comp Rb Rb')\"  \n    unfolding hr_comp_def[abs_def] prod_assn_def[abs_def]\n    apply (intro ext)\n    apply (auto 0 3 simp: sep_algebra_simps pred_lift_extract_simps)\n    done\n\n  lemma hr_comp_pure: \"hr_comp (pure R) S = pure (R O S)\"  \n    apply (intro ext)\n    unfolding hr_comp_def[abs_def] pure_def\n    by (auto simp: sep_algebra_simps pred_lift_extract_simps)\n\n  lemma hr_comp_is_pure[safe_constraint_rules]: \"is_pure A \\<Longrightarrow> is_pure (hr_comp A B)\"\n    by (auto simp: hr_comp_pure is_pure_conv)\n\n  lemma hr_comp_the_pure: \"is_pure A \\<Longrightarrow> the_pure (hr_comp A B) = the_pure A O B\"\n    unfolding is_pure_conv\n    by (clarsimp simp: hr_comp_pure)\n\n  lemma rdomp_hrcomp_conv[simp]: \"rdomp (hr_comp A R) x \\<longleftrightarrow> (\\<exists>y. rdomp A y \\<and> (y,x)\\<in>R)\"\n    by (auto simp: rdomp_def hr_comp_def sep_algebra_simps pred_lift_extract_simps)\n\n  lemma hn_rel_compI: \n    \"\\<lbrakk>nofail a; (b,a)\\<in>\\<langle>R2\\<rangle>nres_rel\\<rbrakk> \\<Longrightarrow> hn_rel R1 b c \\<turnstile> hn_rel (hr_comp R1 R2) a c\"\n    unfolding hr_comp_def hn_rel_def nres_rel_def entails_def\n    apply (auto simp: sep_algebra_simps pred_lift_extract_simps)\n    apply (drule (1) order_trans)\n    apply (auto simp add: ret_le_down_conv)\n    done\n\n  (*  \n  lemma hr_comp_precise[constraint_rules]:\n    assumes [safe_constraint_rules]: \"precise R\"\n    assumes SV: \"single_valued S\"\n    shows \"precise (hr_comp R S)\"\n    apply (rule preciseI)\n    unfolding hr_comp_def\n    apply clarsimp\n    by (metis SV assms(1) preciseD single_valuedD)\n  *)\n\n  lemma hr_comp_assoc: \"hr_comp (hr_comp R S) T = hr_comp R (S O T)\"\n    apply (intro ext)\n    unfolding hr_comp_def\n    by (auto simp: sep_algebra_simps pred_lift_extract_simps)\n\n    \n  lemma hrp_comp_Id1[simp]: \"hrp_comp (hf_pres (pure Id) pp) R = hf_pres (pure R) pp\"\n    unfolding hrp_comp_def apply (cases pp) apply auto\n    by (auto simp: hr_comp_def[abs_def] invalid_assn_def[abs_def] fun_eq_iff sep_algebra_simps pred_lift_extract_simps)\n  \n  lemma hrp_comp_Id2[simp]: \"hrp_comp A Id = A\"\n    unfolding hrp_comp_def by auto\n\n  lemma hnr_comp_aux:\n    assumes \"RETURN x \\<le> m\" \"nofail m'\" \"(m,m')\\<in>\\<langle>R\\<rangle>nres_rel\"\n    obtains x' where \"(x,x')\\<in>R\" \"RETURN x' \\<le> m'\"\n    by (meson assms(1) assms(2) assms(3) inres_def nres_relD pwD2 pw_conc_inres)\n    \n    \n    \n  definition \"hrr_comp R R1 R2 x y a c \\<equiv> \n    if non_dep2 R1 then\n      hr_comp (R1 undefined undefined) (R2 x) a c\n    else\n      EXS b. \\<up>((b,x)\\<in>R) ** hr_comp (R1 b y) (R2 x) a c\"\n  \n  lemma hnr_comp:\n    assumes R: \"\\<And>b1 c1. P b1 \\<Longrightarrow> hn_refine (R1 b1 c1 ** \\<Gamma>) (c c1) (R1p b1 c1 ** \\<Gamma>') (R b1 c1) (b b1)\"\n    assumes S: \"\\<And>a1 b1. \\<lbrakk>Q a1; (b1,a1)\\<in>R1'\\<rbrakk> \\<Longrightarrow> (b b1,a a1)\\<in>\\<langle>R' a1\\<rangle>nres_rel\"\n    assumes PQ: \"\\<And>a1 b1. \\<lbrakk>Q a1; (b1,a1)\\<in>R1'\\<rbrakk> \\<Longrightarrow> P b1\"\n    assumes Q: \"Q a1\"\n    shows \"hn_refine \n      (hr_comp R1 R1' a1 c1 ** \\<Gamma>) \n      (c c1)\n      (hr_comp R1p R1' a1 c1 ** \\<Gamma>') \n      (hrr_comp R1' R R' a1 c1) \n      (a a1)\"\n  proof -\n\n    note [vcg_rules] = R[THEN hn_refineD, of _ c1]\n    \n    have [simp]: \"nofail (b x)\" if  \"nofail (a a1)\" \"(x, a1) \\<in> R1'\" for x\n      using that Q S nres_rel_def pw_ref_iff by fastforce\n    \n      \n    show ?thesis      \n      unfolding hn_refine_alt\n      unfolding hr_comp_def hn_rel_def hrr_comp_def\n      apply (cases \"non_dep2 R\"; simp)\n      subgoal premises prems\n        apply (auto simp: sep_algebra_simps)\n        using PQ[OF Q] \n        supply [simp] = non_dep2_simp[OF prems]\n        apply vcg\n        apply (frule S[OF Q])\n        apply (erule (2) hnr_comp_aux)\n        by vcg_try_solve\n      subgoal  \n        apply (auto simp: sep_algebra_simps)\n        using PQ[OF Q]\n        apply vcg\n        apply (frule S[OF Q])\n        apply (erule (2) hnr_comp_aux)\n        by vcg_try_solve\n        \n      done\n  qed\n  \n\n  lemma hnr_comp1_aux:\n    assumes R: \"\\<And>b1 c1. P b1 \\<Longrightarrow> hn_refine (hn_ctxt R1 b1 c1) (c c1) (hn_ctxt R1p b1 c1) (R b1 c1) (b$b1)\"\n    assumes S: \"\\<And>a1 b1. \\<lbrakk>Q a1; (b1,a1)\\<in>R1'\\<rbrakk> \\<Longrightarrow> (b$b1,a$a1)\\<in>\\<langle>R' a1\\<rangle>nres_rel\"\n    assumes PQ: \"\\<And>a1 b1. \\<lbrakk>Q a1; (b1,a1)\\<in>R1'\\<rbrakk> \\<Longrightarrow> P b1\"\n    assumes Q: \"Q a1\"\n    shows \"hn_refine \n      (hr_comp R1 R1' a1 c1) \n      (c c1)\n      (hr_comp R1p R1' a1 c1) \n      (hrr_comp R1' R R' a1 c1) \n      (a a1)\"\n    using assms hnr_comp[where \\<Gamma>=\\<box> and \\<Gamma>'=\\<box> and a=a and b=b and c=c and P=P and Q=Q]  \n    unfolding hn_ctxt_def\n    by auto\n\n  lemma hfcomp:\n    assumes A: \"(f,g) \\<in> [P]\\<^sub>a\\<^sub>d RR' \\<rightarrow> S\"\n    assumes B: \"(g,h) \\<in> [Q]\\<^sub>f\\<^sub>d T \\<rightarrow> (\\<lambda>x. \\<langle>U x\\<rangle>nres_rel)\"\n    shows \"(f,h) \\<in> [\\<lambda>a. Q a \\<and> (\\<forall>a'. (a',a)\\<in>T \\<longrightarrow> P a')]\\<^sub>a\\<^sub>d \n      hrp_comp RR' T \\<rightarrow> hrr_comp T S U\"\n    using assms  \n    unfolding fref_def hfref_def hrp_comp_def\n    apply clarsimp\n    apply (rule hnr_comp1_aux[of \n        P \"fst RR'\" f \"snd RR'\" S g \"\\<lambda>a. Q a \\<and> (\\<forall>a'. (a',a)\\<in>T \\<longrightarrow> P a')\" T h U])\n    apply (auto simp: hn_ctxt_def)\n    done\n\n  lemma hrr_comp_nondep: \"hrr_comp T (\\<lambda>_ _. A) R = (\\<lambda>x _. hr_comp A (R x))\"\n    unfolding hrr_comp_def\n    by (auto simp: fun_eq_iff)\n    \n  (* TODO: Concept of lifting dependent relation over other relation! Allows us to handle hrr_comp R R1 (\\<lambda>_. Id) *)\n  lemma hrr_comp_Id_R_Id: \"hrr_comp Id R1 (\\<lambda>_. Id) = R1\"\n    by (auto simp: hrr_comp_def fun_eq_iff pred_lift_extract_simps non_dep2_simp[of R1])\n  \n  lemma hrr_comp_id_conv[simp]: \"hrr_comp Id R1 R2 = (\\<lambda>x y. hr_comp (R1 x y) (R2 x))\"\n    unfolding hrr_comp_def\n    by (auto simp: fun_eq_iff pred_lift_extract_simps non_dep2_simp[of R1])\n  \n    \n  lemma hfref_weaken_pre_nofail: \n    assumes \"(f,g) \\<in> [P]\\<^sub>a\\<^sub>d R \\<rightarrow> S\"  \n    shows \"(f,g) \\<in> [\\<lambda>x. nofail (g x) \\<longrightarrow> P x]\\<^sub>a\\<^sub>d R \\<rightarrow> S\"\n    using assms\n    unfolding hfref_def hn_refine_def\n    by auto\n\n  lemma hfref_cons:\n    assumes \"(f,g) \\<in> [P]\\<^sub>a\\<^sub>d R \\<rightarrow> S\"\n    assumes \"\\<And>x. P' x \\<Longrightarrow> P x\"\n    assumes \"\\<And>x y. fst R' x y \\<turnstile> fst R x y\"\n    assumes \"\\<And>x y. snd R x y \\<turnstile> snd R' x y\"\n    assumes \"\\<And>x y a c. P' a \\<Longrightarrow> S a c x y \\<turnstile> S' a c x y\"\n    shows \"(f,g) \\<in> [P']\\<^sub>a\\<^sub>d R' \\<rightarrow> S'\"\n    unfolding hfref_def\n    apply clarsimp\n    apply (rule hn_refine_cons)\n    apply (rule assms(3))\n    defer\n    \n    apply (rule entails_trans[OF assms(4) entails_refl])\n    apply (erule assms(5))\n    apply (frule assms(2))\n    using assms(1)\n    unfolding hfref_def\n    apply auto\n    done\n    \n  (*lemma xfer_hrr_comp:\n    assumes \"\\<And>x y a c. \\<lbrakk> (x,y)\\<in>T \\<rbrakk> \\<Longrightarrow> R x a c \\<turnstile> R' y a c\"  \n    shows \"hrr_comp T R S x a c \\<turnstile> (hr_comp (R' x) S) a c\"\n    using assms unfolding hrr_comp_def\n    apply (cases \"non_dep R\"; simp)\n    subgoal sorry\n    apply (auto simp: sep_algebra_simps pred_lift_extract_simps entails_def hr_comp_def non_dep_simp[of R])\n  *)  \n\n  subsubsection \\<open>Composition Automation\\<close>  \n  text \\<open>This section contains the lemmas. The ML code is further down. \\<close>\n\n  lemma prod_hrp_comp: \n    \"hrp_comp (A *\\<^sub>a B) (C \\<times>\\<^sub>r D) = hrp_comp A C *\\<^sub>a hrp_comp B D\"\n    unfolding hrp_comp_def hfprod_def by simp\n  \n  lemma hrp_comp_keep: \"hrp_comp (A\\<^sup>k) B = (hr_comp A B)\\<^sup>k\"\n    by (auto simp: hrp_comp_def)\n\n  lemma hr_comp_invalid: \"hr_comp (invalid_assn R1) R2 = invalid_assn (hr_comp R1 R2)\"\n    apply (intro ext)\n    unfolding invalid_assn_def hr_comp_def\n    apply (auto simp: sep_algebra_simps pred_lift_extract_simps)\n    apply (auto simp: pure_part_def) (* TODO: too low-level! *)\n    done\n\n  lemma hrp_comp_dest: \"hrp_comp (A\\<^sup>d) B = (hr_comp A B)\\<^sup>d\"\n    by (auto simp: hrp_comp_def hr_comp_invalid)\n\n\n\n  definition \"hrp_imp RR RR' \\<equiv> \n    \\<forall>a b. (fst RR' a b \\<turnstile> fst RR a b) \\<and> (snd RR a b \\<turnstile> snd RR' a b)\"\n\n  lemma hfref_imp: \"hrp_imp RR RR' \\<Longrightarrow> [P]\\<^sub>a RR \\<rightarrow> S \\<subseteq> [P]\\<^sub>a RR' \\<rightarrow> S\"  \n    apply clarsimp\n    apply (erule hfref_cons)\n    apply (simp_all add: hrp_imp_def)\n    done\n    \n  lemma hrp_imp_refl: \"hrp_imp RR RR\"\n    unfolding hrp_imp_def by auto\n\n  lemma hrp_imp_reflI: \"RR = RR' \\<Longrightarrow> hrp_imp RR RR'\"\n    unfolding hrp_imp_def by auto\n\n\n  lemma hrp_comp_cong: \"hrp_imp A A' \\<Longrightarrow> B=B' \\<Longrightarrow> hrp_imp (hrp_comp A B) (hrp_comp A' B')\"\n    by (auto simp: hrp_imp_def hrp_comp_def hr_comp_def entails_def sep_algebra_simps pred_lift_extract_simps)\n    \n  lemma hrp_prod_cong: \"hrp_imp A A' \\<Longrightarrow> hrp_imp B B' \\<Longrightarrow> hrp_imp (A*\\<^sub>aB) (A'*\\<^sub>aB')\"\n    by (auto simp: hrp_imp_def prod_assn_def sep_algebra_simps pred_lift_extract_simps\n      intro: conj_entails_mono\n    )\n\n  lemma hrp_imp_trans: \"hrp_imp A B \\<Longrightarrow> hrp_imp B C \\<Longrightarrow> hrp_imp A C\"  \n    unfolding hrp_imp_def\n    by (fastforce intro: entails_trans)\n\n  lemma fcomp_norm_dflt_init: \"x\\<in>[P]\\<^sub>a R \\<rightarrow> T \\<Longrightarrow> hrp_imp R S \\<Longrightarrow> x\\<in>[P]\\<^sub>a S \\<rightarrow> T\"\n    apply (erule set_rev_mp)\n    by (rule hfref_imp)\n\n  definition \"comp_PRE R P Q S \\<equiv> \\<lambda>x. S x \\<longrightarrow> (P x \\<and> (\\<forall>y. (y,x)\\<in>R \\<longrightarrow> Q x y))\"\n\n  lemma comp_PRE_cong[cong]: \n    assumes \"R\\<equiv>R'\"\n    assumes \"\\<And>x. P x \\<equiv> P' x\"\n    assumes \"\\<And>x. S x \\<equiv> S' x\"\n    assumes \"\\<And>x y. \\<lbrakk>P x; (y,x)\\<in>R; y\\<in>Domain R; S' x \\<rbrakk> \\<Longrightarrow> Q x y \\<equiv> Q' x y\"\n    shows \"comp_PRE R P Q S \\<equiv> comp_PRE R' P' Q' S'\"\n    using assms\n    by (fastforce simp: comp_PRE_def intro!: eq_reflection ext)\n\n  lemma fref_compI_PRE:\n    \"\\<lbrakk> (f,g)\\<in>fref P R1 R2; (g,h)\\<in>fref Q S1 S2 \\<rbrakk> \n      \\<Longrightarrow> (f,h) \\<in> fref (comp_PRE S1 Q (\\<lambda>_. P) (\\<lambda>_. True)) (R1 O S1) (rr_comp S1 R2 S2)\"\n    using fref_compI[of P R1 R2 Q S1 S2]   \n    unfolding comp_PRE_def\n    by auto\n\n  lemma PRE_D1: \"(Q x \\<and> P x) \\<longrightarrow> comp_PRE S1 Q (\\<lambda>x _. P x) S x\"\n    by (auto simp: comp_PRE_def)\n\n  lemma PRE_D2: \"(Q x \\<and> (\\<forall>y. (y,x)\\<in>S1 \\<longrightarrow> S x \\<longrightarrow> P x y)) \\<longrightarrow> comp_PRE S1 Q P S x\"\n    by (auto simp: comp_PRE_def)\n\n  lemma fref_weaken_pre: \n    assumes \"\\<And>x. P x \\<longrightarrow> P' x\"  \n    assumes \"(f,h) \\<in> fref P' R S\"\n    shows \"(f,h) \\<in> fref P R S\"\n    apply (rule set_rev_mp[OF assms(2) fref_mono])\n    using assms(1) by auto\n    \n  lemma fref_PRE_D1:\n    assumes \"(f,h) \\<in> fref (comp_PRE S1 Q (\\<lambda>x _. P x) X) R S\"  \n    shows \"(f,h) \\<in> fref (\\<lambda>x. Q x \\<and> P x) R S\"\n    by (rule fref_weaken_pre[OF PRE_D1 assms])\n\n  lemma fref_PRE_D2:\n    assumes \"(f,h) \\<in> fref (comp_PRE S1 Q P X) R S\"  \n    shows \"(f,h) \\<in> fref (\\<lambda>x. Q x \\<and> (\\<forall>y. (y,x)\\<in>S1 \\<longrightarrow> X x \\<longrightarrow> P x y)) R S\"\n    by (rule fref_weaken_pre[OF PRE_D2 assms])\n\n  lemmas fref_PRE_D = fref_PRE_D1 fref_PRE_D2\n\n  lemma hfref_weaken_pre: \n    assumes \"\\<And>x. P x \\<longrightarrow> P' x\"  \n    assumes \"(f,h) \\<in> hfref P' R S\"\n    shows \"(f,h) \\<in> hfref P R S\"\n    using assms\n    by (auto simp: hfref_def)\n\n  lemma hfref_weaken_pre': \n    assumes \"\\<And>x. \\<lbrakk>P x; rdomp (fst R) x\\<rbrakk> \\<Longrightarrow> P' x\"  \n    assumes \"(f,h) \\<in> hfref P' R S\"\n    shows \"(f,h) \\<in> hfref P R S\"\n    apply (rule hfrefI)\n    apply (rule hn_refine_preI)\n    using assms\n    by (auto simp: hfref_def rdomp_def)\n\n  lemma hfref_weaken_pre_nofail': \n    assumes \"(f,g) \\<in> [P]\\<^sub>a\\<^sub>d R \\<rightarrow> S\"  \n    assumes \"\\<And>x. \\<lbrakk>nofail (g x); Q x\\<rbrakk> \\<Longrightarrow> P x\"\n    shows \"(f,g) \\<in> [Q]\\<^sub>a\\<^sub>d R \\<rightarrow> S\"\n    apply (rule hfref_weaken_pre[OF _ assms(1)[THEN hfref_weaken_pre_nofail]])\n    using assms(2) \n    by blast\n\n  lemma hfref_with_rdomI:\n    assumes \"(c,a)\\<in>[\\<lambda>x. P x \\<and> rdomp (fst A) x]\\<^sub>a\\<^sub>d A \\<rightarrow> R\"\n    shows \"(c,a)\\<in>[P]\\<^sub>a\\<^sub>d A \\<rightarrow> R\"\n    by (metis (no_types, lifting) assms hfref_weaken_pre')\n    \n  lemma hfref_compI_PRE_aux:\n    assumes A: \"(f,g) \\<in> [P]\\<^sub>a\\<^sub>d RR' \\<rightarrow> S\"\n    assumes B: \"(g,h) \\<in> [Q]\\<^sub>f\\<^sub>d T \\<rightarrow> (\\<lambda>x. \\<langle>U x\\<rangle>nres_rel)\"\n    shows \"(f,h) \\<in> [comp_PRE T Q (\\<lambda>_. P) (\\<lambda>_. True)]\\<^sub>a\\<^sub>d \n      hrp_comp RR' T \\<rightarrow> hrr_comp T S U\"\n    apply (rule hfref_weaken_pre[OF _ hfcomp[OF A B]])\n    by (auto simp: comp_PRE_def)\n\n\n  lemma hfref_compI_PRE:\n    assumes A: \"(f,g) \\<in> [P]\\<^sub>a\\<^sub>d RR' \\<rightarrow> S\"\n    assumes B: \"(g,h) \\<in> [Q]\\<^sub>f\\<^sub>d T \\<rightarrow> (\\<lambda>x. \\<langle>U x\\<rangle>nres_rel)\"\n    shows \"(f,h) \\<in> [comp_PRE T Q (\\<lambda>x y. P y) (\\<lambda>x. nofail (h x))]\\<^sub>a\\<^sub>d \n      hrp_comp RR' T \\<rightarrow> hrr_comp T S U\"\n    using hfref_compI_PRE_aux[OF A B, THEN hfref_weaken_pre_nofail]  \n    apply (rule hfref_weaken_pre[rotated])\n    apply (auto simp: comp_PRE_def)\n    done\n\n  lemma hfref_PRE_D1:\n    assumes \"(f,h) \\<in> hfref (comp_PRE S1 Q (\\<lambda>x _. P x) X) R S\"  \n    shows \"(f,h) \\<in> hfref (\\<lambda>x. Q x \\<and> P x) R S\"\n    by (rule hfref_weaken_pre[OF PRE_D1 assms])\n\n  lemma hfref_PRE_D2:\n    assumes \"(f,h) \\<in> hfref (comp_PRE S1 Q P X) R S\"  \n    shows \"(f,h) \\<in> hfref (\\<lambda>x. Q x \\<and> (\\<forall>y. (y,x)\\<in>S1 \\<longrightarrow> X x \\<longrightarrow> P x y)) R S\"\n    by (rule hfref_weaken_pre[OF PRE_D2 assms])\n\n  lemma hfref_PRE_D3:\n    assumes \"(f,h) \\<in> hfref (comp_PRE S1 Q P X) R S\"  \n    shows \"(f,h) \\<in> hfref (comp_PRE S1 Q P X) R S\"\n    using assms .\n\n  lemmas hfref_PRE_D = hfref_PRE_D1 hfref_PRE_D3\n\n  subsection \\<open>Automation\\<close>  \n  text \\<open>Purity configuration for constraint solver\\<close>\n  lemmas [safe_constraint_rules] = pure_pure\n\n  lemma invalid_pure[safe_constraint_rules]: \"is_pure (invalid_assn A)\"\n    unfolding invalid_assn_def is_pure_def by auto\n  \n  text \\<open>Configuration for hfref to hnr conversion\\<close>\n  named_theorems to_hnr_post \\<open>to_hnr converter: Postprocessing unfold rules\\<close>\n\n  lemma uncurry0_add_app_tag: \"uncurry0 (RETURN c) = uncurry0 (RETURN$c)\" by simp\n\n  thm sep_conj_empty[of \"P::ll_assn\" for P]\n  \n  lemmas [to_hnr_post] = norm_RETURN_o norm_return_o\n    uncurry0_add_app_tag uncurry0_apply uncurry0_APP hn_val_unit_conv_emp\n    sep_conj_empty[of \"P::ll_assn\" for P] sep_conj_empty'[of \"P::ll_assn\" for P]\n\n  named_theorems to_hfref_post \\<open>to_hfref converter: Postprocessing unfold rules\\<close> \n  lemma prod_casesK[to_hfref_post]: \"case_prod (\\<lambda>_ _. k) = (\\<lambda>_. k)\" by auto\n  lemma uncurry0_hfref_post[to_hfref_post]: \"hfref (uncurry0 True) R S = hfref (\\<lambda>_. True) R S\" \n    apply (fo_rule arg_cong fun_cong)+ by auto\n\n\n  (* Currently not used, we keep it in here anyway. *)  \n  text \\<open>Configuration for relation normalization after composition\\<close>\n  named_theorems fcomp_norm_unfold \\<open>fcomp-normalizer: Unfold theorems\\<close>\n  named_theorems fcomp_norm_simps \\<open>fcomp-normalizer: Simplification theorems\\<close>\n  named_theorems fcomp_norm_init \"fcomp-normalizer: Initialization rules\"  \n  named_theorems fcomp_norm_trans \"fcomp-normalizer: Transitivity rules\"  \n  named_theorems fcomp_norm_cong \"fcomp-normalizer: Congruence rules\"  \n  named_theorems fcomp_norm_norm \"fcomp-normalizer: Normalization rules\"  \n  named_theorems fcomp_norm_refl \"fcomp-normalizer: Reflexivity rules\"  \n\n  text \\<open>Default Setup\\<close>\n  lemmas [fcomp_norm_unfold] = prod_rel_comp nres_rel_comp Id_O_R R_O_Id\n  lemmas [fcomp_norm_unfold] = hr_comp_Id1 hr_comp_Id2 hrp_comp_Id1 hrp_comp_Id2\n  find_theorems rr_comp\n  lemmas [fcomp_norm_unfold] = hrr_comp_nondep rr_comp_nondep\n  lemmas [fcomp_norm_unfold] = hr_comp_prod_conv\n  lemmas [fcomp_norm_unfold] = prod_hrp_comp hrp_comp_keep hrp_comp_dest hr_comp_pure\n  (*lemmas [fcomp_norm_unfold] = prod_casesK uncurry0_hfref_post*)\n\n  lemma [fcomp_norm_simps]: \"CONSTRAINT is_pure P \\<Longrightarrow> pure (the_pure P) = P\" by simp\n  lemmas [fcomp_norm_simps] = True_implies_equals \n  \n  lemmas [fcomp_norm_init] = fcomp_norm_dflt_init\n  lemmas [fcomp_norm_trans] = hrp_imp_trans\n  lemmas [fcomp_norm_cong] = hrp_comp_cong hrp_prod_cong\n  (*lemmas [fcomp_norm_norm] = hrp_comp_dest*)\n  lemmas [fcomp_norm_refl] = refl hrp_imp_refl\n\n  lemma ensure_fref_nresI: \"(f,g)\\<in>[P]\\<^sub>f\\<^sub>d R\\<rightarrow>S \\<Longrightarrow> (RETURN o f, RETURN o g)\\<in>[P]\\<^sub>f\\<^sub>d R\\<rightarrow>(\\<lambda>x. \\<langle>S x\\<rangle>nres_rel)\" \n    by (auto intro: nres_relI simp: fref_def)\n\n  lemma ensure_fref_nres_unfold:\n    \"\\<And>f. RETURN o (uncurry0 f) = uncurry0 (RETURN f)\" \n    \"\\<And>f. RETURN o (uncurry f) = uncurry (RETURN oo f)\"\n    \"\\<And>f. (RETURN ooo uncurry) f = uncurry (RETURN ooo f)\"\n    by auto\n\n  text \\<open>Composed precondition normalizer\\<close>  \n  named_theorems fcomp_prenorm_simps \\<open>fcomp precondition-normalizer: Simplification theorems\\<close>\n\n  text \\<open>Support for preconditions of the form @{text \"_\\<in>Domain R\"}, \n    where @{text R} is the relation of the next more abstract level.\\<close>\n  declare DomainI[fcomp_prenorm_simps]\n\n  lemma auto_weaken_pre_init_hf: \n    assumes \"\\<And>x. PROTECT P x \\<longrightarrow> P' x\"  \n    assumes \"(f,h) \\<in> hfref P' R S\"\n    shows \"(f,h) \\<in> hfref P R S\"\n    using assms\n    by (auto simp: hfref_def)\n\n  lemma auto_weaken_pre_init_f: \n    assumes \"\\<And>x. PROTECT P x \\<longrightarrow> P' x\"  \n    assumes \"(f,h) \\<in> fref P' R S\"\n    shows \"(f,h) \\<in> fref P R S\"\n    using assms\n    by (auto simp: fref_def)\n\n  lemmas auto_weaken_pre_init = auto_weaken_pre_init_hf auto_weaken_pre_init_f  \n\n  lemma auto_weaken_pre_uncurry_step:\n    assumes \"PROTECT f a \\<equiv> f'\"\n    shows \"PROTECT (\\<lambda>(x,y). f x y) (a,b) \\<equiv> f' b\" \n    using assms\n    by (auto simp: curry_def dest!: meta_eq_to_obj_eq intro!: eq_reflection)\n\n  lemma auto_weaken_pre_uncurry_finish:  \n    \"PROTECT f x \\<equiv> f x\" by (auto)\n\n  lemma auto_weaken_pre_uncurry_start:\n    assumes \"P \\<equiv> P'\"\n    assumes \"P'\\<longrightarrow>Q\"\n    shows \"P\\<longrightarrow>Q\"\n    using assms by (auto)\n\n  \n\n  lemma auto_weaken_pre_to_imp_nf:\n    \"(A\\<longrightarrow>B\\<longrightarrow>C) = (A\\<and>B \\<longrightarrow> C)\"\n    \"((A\\<and>B)\\<and>C) = (A\\<and>B\\<and>C)\"\n    by auto\n\n  lemma auto_weaken_pre_add_dummy_imp:\n    \"P \\<Longrightarrow> True \\<longrightarrow> P\" by simp\n\n\n  text \\<open>Synthesis for hfref statements\\<close>  \n  definition hfsynth_ID_R :: \"('a \\<Rightarrow> _ \\<Rightarrow> assn) \\<Rightarrow> 'a \\<Rightarrow> bool\" where\n    [simp]: \"hfsynth_ID_R _ _ \\<equiv> True\"\n\n  lemma hfsynth_ID_R_D:\n    fixes I :: \"'a itself\"\n    assumes \"hfsynth_ID_R R a\"\n    assumes \"intf_of_assn R I\"\n    shows \"a ::\\<^sub>i I\"\n    by simp\n\n  lemma hfsynth_hnr_from_hfI:\n    assumes \"\\<forall>x xi. P x \\<and> hfsynth_ID_R (fst R) x \\<longrightarrow> hn_refine (hn_ctxt (fst R) x xi ** \\<box>) (f$xi) (hn_ctxt (snd R) x xi ** \\<box>) (S x xi) (g$x)\"\n    shows \"(f,g) \\<in> [P]\\<^sub>a\\<^sub>d R \\<rightarrow> S\"\n    using assms\n    unfolding hfref_def \n    by (auto simp: hn_ctxt_def)\n\n\n  lemma hfsynth_ID_R_uncurry_unfold: \n    \"hfsynth_ID_R (to_hnr_prod R S) (a,b) \\<equiv> hfsynth_ID_R R a \\<and> hfsynth_ID_R S b\" \n    \"hfsynth_ID_R (fst (hf_pres R k)) \\<equiv> hfsynth_ID_R R\"\n    by (auto intro!: eq_reflection)\n\n    \n  ML \\<open>\n\n    signature SEPREF_RULES = sig\n      (* Analysis of relations, both fref and fun_rel *)\n      (* \"R1\\<rightarrow>...\\<rightarrow>Rn\\<rightarrow>_\" / \"[_]\\<^sub>f ((R1\\<times>\\<^sub>rR2)...\\<times>\\<^sub>rRn)\"  \\<mapsto>  \"[R1,...,Rn]\" *)\n      val binder_rels: term -> term list \n      (* \"_\\<rightarrow>...\\<rightarrow>_\\<rightarrow>S\" / \"[_]\\<^sub>f _ \\<rightarrow> S\"  \\<mapsto>  \"S\" *)\n      val body_rel: term -> term \n      (* Map \\<rightarrow>/fref to (precond,args,res). NONE if no/trivial precond. *)\n      val analyze_rel: term -> term option * term list * term \n      (* Make trivial (\"\\<lambda>_. True\") precond *)\n      val mk_triv_precond: term list -> term \n      (* Make \"[P]\\<^sub>f\\<^sub>d ((R1\\<times>\\<^sub>rR2)...\\<times>\\<^sub>rRn) \\<rightarrow> S\". Insert trivial precond if NONE. *)\n      val mk_rel: term option * term list * term -> term \n      (* Map relation to (args,res) *)\n      val strip_rel: term -> term list * term \n\n      (* Make hfprod (op *\\<^sub>a) *)\n      val mk_hfprod : term * term -> term\n      val mk_hfprods : term list -> term\n\n      (* Determine interface type of refinement assertion, using default fallback\n        if necessary. Use named_thms intf_of_assn for configuration. *)\n      val intf_of_assn : Proof.context -> term -> typ\n\n      (*\n        Convert a parametricity theorem in higher-order form to\n        uncurried fref-form. For functions without arguments, \n        a unit-argument is added.\n\n        TODO/FIXME: Currently this only works for higher-order theorems,\n          i.e., theorems of the form (f,g)\\<in>R1\\<rightarrow>\\<dots>\\<rightarrow>Rn. \n          \n          First-order theorems are silently treated as refinement theorems\n          for functions with zero arguments, i.e., a unit-argument is added.\n      *)\n      val to_fref : Proof.context -> thm -> thm\n\n      (* Convert a parametricity or fref theorem to first order form *)\n      val to_foparam : Proof.context -> thm -> thm\n\n      (* Convert schematic hfref goal to hnr-goal *)\n      val prepare_hfref_synth_tac : Proof.context -> tactic'\n\n      (* Convert theorem in hfref-form to hnr-form *)\n      val to_hnr : Proof.context -> thm -> thm\n\n      (* Convert theorem in hnr-form to hfref-form *)\n      val to_hfref: Proof.context -> thm -> thm\n\n      (* Convert theorem to given form, if not yet in this form *)\n      val ensure_fref : Proof.context -> thm -> thm\n      val ensure_fref_nres : Proof.context -> thm -> thm\n      val ensure_hfref : Proof.context -> thm -> thm\n      val ensure_hnr : Proof.context -> thm -> thm\n\n\n      type hnr_analysis = {\n        thm: thm,                     (* Original theorem, may be normalized *)\n        precond: term,                (* Precondition, abstracted over abs-arguments *)\n        prems : term list,            (* Premises not depending on arguments *)\n        ahead: term * bool,           (* Abstract function, has leading RETURN *)\n        chead: term * bool,           (* Concrete function, has leading return *)\n        argrels: (term * bool) list,  (* Argument relations, preserved (keep-flag) *)\n        result_rel: term              (* Result relation *)\n      }\n  \n      val analyze_hnr: Proof.context -> thm -> hnr_analysis\n      val pretty_hnr_analysis: Proof.context -> hnr_analysis -> Pretty.T\n      val mk_hfref_thm: Proof.context -> hnr_analysis -> thm\n  \n  \n\n      (* Simplify precondition of fref/hfref-theorem *)\n      val simplify_precond: Proof.context -> thm -> thm\n\n      (* Normalize hfref-theorem after composition *)\n      val norm_fcomp_rule: Proof.context -> thm -> thm\n\n      (* Replace \"pure ?A\" by \"?A'\" and is_pure constraint, then normalize *)\n      val add_pure_constraints_rule: Proof.context -> thm -> thm\n\n      (* Compose fref/hfref and fref theorem, to produce hfref theorem.\n        The input theorems may also be in ho-param or hnr form, and\n        are converted accordingly.\n      *)\n      val gen_compose : Proof.context -> thm -> thm -> thm\n\n      (* FCOMP-attribute *)\n      val fcomp_attrib: attribute context_parser\n    end\n\n    structure Sepref_Rules: SEPREF_RULES = struct\n\n      local open Refine_Util Relators in\n        fun binder_rels @{mpat \"?F \\<rightarrow> ?G\"} = F::binder_rels G\n          | binder_rels @{mpat \"fref _ ?F _\"} = strip_prodrel_left F\n          | binder_rels _ = []\n    \n        local \n          fun br_aux @{mpat \"_ \\<rightarrow> ?G\"} = br_aux G\n            | br_aux R = R\n        in    \n          fun body_rel @{mpat \"fref _ _ ?G\"} = G\n            | body_rel R = br_aux R\n        end\n    \n        fun strip_rel R = (binder_rels R, body_rel R)   \n    \n        fun analyze_rel @{mpat \"fref (\\<lambda>_. True) ?R ?S\"} = (NONE,strip_prodrel_left R,S)\n          | analyze_rel @{mpat \"fref ?P ?R ?S\"} = (SOME P,strip_prodrel_left R,S)\n          | analyze_rel R = let\n              val (args,res) = strip_rel R\n              val argTuc = \n                   map (fastype_of #> HOLogic.dest_setT #> HOLogic.dest_prodT #> snd) args \n                |> list_prodT_left\n              val res = Term.absdummy argTuc res\n            in\n              (NONE,args,res)\n            end\n    \n        fun mk_triv_precond Rs = absdummy (map rel_absT Rs |> list_prodT_left) @{term True}\n    \n        fun mk_rel (P,Rs,S) = let \n          val R = list_prodrel_left Rs \n    \n          val P = case P of \n              SOME P => P \n            | NONE => mk_triv_precond Rs\n    \n        in \n          @{mk_term \"fref ?P ?R ?S\"} \n        end\n      end\n\n\n      fun mk_hfprod (a, b) = @{mk_term \"?a*\\<^sub>a?b\"}\n  \n      local \n        fun mk_hfprods_rev [] = @{mk_term \"unit_assn\\<^sup>k\"}\n          | mk_hfprods_rev [Rk] = Rk\n          | mk_hfprods_rev (Rkn::Rks) = mk_hfprod (mk_hfprods_rev Rks, Rkn)\n      in\n        val mk_hfprods = mk_hfprods_rev o rev\n      end\n\n\n      fun intf_of_assn ctxt t = let\n        val orig_ctxt = ctxt\n        val (t,ctxt) = yield_singleton (Variable.import_terms false) t ctxt\n\n        val v = TVar ((\"T\",0),Proof_Context.default_sort ctxt (\"T\",0)) |> Logic.mk_type\n        val goal = @{mk_term \"Trueprop (intf_of_assn ?t ?v)\"}\n\n        val i_of_assn_rls = \n          Named_Theorems_Rev.get ctxt @{named_theorems_rev intf_of_assn}\n          @ @{thms intf_of_assn_fallback}\n\n        fun tac ctxt = REPEAT_ALL_NEW (resolve_tac ctxt i_of_assn_rls)\n\n        val thm = Goal.prove ctxt [] [] goal (fn {context,...} => ALLGOALS (tac context))\n        val intf = case Thm.concl_of thm of\n            @{mpat \"Trueprop (intf_of_assn _ (?v AS\\<^sub>p TYPE (_)))\"} => v \n          | _ => raise THM(\"Intf_of_assn: Proved a different theorem?\",~1,[thm])\n\n        val intf = singleton (Variable.export_terms ctxt orig_ctxt) intf\n          |> Logic.dest_type\n\n      in\n        intf\n      end\n\n      datatype rthm_type = \n        RT_HOPARAM    (* (_,_) \\<in> _ \\<rightarrow> \\<dots> \\<rightarrow> _ *)\n      | RT_FREF       (* (_,_) \\<in> [_]\\<^sub>f _ \\<rightarrow> _ *)\n      | RT_HNR        (* hn_refine _ _ _ _ _ *)\n      | RT_HFREF      (* (_,_) \\<in> [_]\\<^sub>a _ \\<rightarrow> _ *)\n      | RT_OTHER\n\n      fun rthm_type thm =\n        case Thm.concl_of thm |> HOLogic.dest_Trueprop of\n          @{mpat \"(_,_) \\<in> fref _ _ _\"} => RT_FREF\n        | @{mpat \"(_,_) \\<in> hfref _ _ _\"} => RT_HFREF\n        | @{mpat \"hn_refine _ _ _ _ _\"} => RT_HNR\n        | @{mpat \"(_,_) \\<in> _\"} => RT_HOPARAM (* TODO: Distinction between ho-param and fo-param *)\n        | _ => RT_OTHER\n\n\n      fun to_fref ctxt thm = let\n        open Conv\n      in  \n        case Thm.concl_of thm |> HOLogic.dest_Trueprop of\n          @{mpat \"(_,_)\\<in>_\\<rightarrow>_\"} =>\n            Local_Defs.unfold0 ctxt @{thms fref_param1} thm\n            |> fconv_rule (repeat_conv (Refine_Util.ftop_conv (K (rewr_conv @{thm fref_nest})) ctxt))\n            |> Local_Defs.unfold0 ctxt @{thms in_CURRY_conv}\n        | @{mpat \"(_,_)\\<in>_\"} => thm RS @{thm fref_param0I}   \n        | _ => raise THM (\"to_fref: Expected theorem of form (_,_)\\<in>_\",~1,[thm])\n      end\n\n      fun to_foparam ctxt thm = let\n        val unf_thms = @{thms \n          split_tupled_all prod_rel_simp uncurry_apply cnv_conj_to_meta Product_Type.split}\n      in\n        case Thm.concl_of thm of\n          @{mpat \"Trueprop ((_,_) \\<in> fref _ _ _)\"} =>\n            (@{thm frefD} OF [thm])\n            |> forall_intr_vars\n            |> Local_Defs.unfold0 ctxt unf_thms\n            |> Variable.gen_all ctxt\n        | @{mpat \"Trueprop ((_,_) \\<in> _)\"} =>\n            Parametricity.fo_rule thm\n        | _ => raise THM(\"Expected parametricity or fref theorem\",~1,[thm])\n      end\n\n      fun to_hnr ctxt thm =\n        (thm RS @{thm hf2hnr})\n        |> Local_Defs.unfold0 ctxt @{thms to_hnr_prod_fst_snd keep_drop_sels} (* Resolve fst and snd over *\\<^sub>a and R\\<^sup>k, R\\<^sup>d *)\n        |> Local_Defs.unfold0 ctxt @{thms hnr_uncurry_unfold} (* Resolve products for uncurried parameters *)\n        |> Local_Defs.unfold0 ctxt @{thms uncurry_apply uncurry_APP sep_conj_empty' split} (* Remove the uncurry modifiers, the emp-dummy, and unfold product cases *)\n        |> Local_Defs.unfold0 ctxt @{thms hn_ctxt_ctxt_fix_conv} (* Remove duplicate hn_ctxt tagging *)\n        |> Local_Defs.unfold0 ctxt @{thms all_to_meta imp_to_meta HOL.True_implies_equals HOL.implies_True_equals Pure.triv_forall_equality cnv_conj_to_meta} (* Convert to meta-level, remove vacuous condition *)\n        |> Local_Defs.unfold0 ctxt (Named_Theorems.get ctxt @{named_theorems to_hnr_post}) (* Post-Processing *)\n        |> Goal.norm_result ctxt\n        |> Conv.fconv_rule Thm.eta_conversion\n\n      (* Convert schematic hfref-goal to hn_refine goal *)  \n      fun prepare_hfref_synth_tac ctxt = let\n        val i_of_assn_rls = \n          Named_Theorems_Rev.get ctxt @{named_theorems_rev intf_of_assn}\n          @ @{thms intf_of_assn_fallback}\n\n        val to_hnr_post_rls = \n          Named_Theorems.get ctxt @{named_theorems to_hnr_post}\n\n        val i_of_assn_tac = (\n          REPEAT' (\n            DETERM o dresolve_tac ctxt @{thms hfsynth_ID_R_D}\n            THEN' DETERM o SOLVED' (REPEAT_ALL_NEW (resolve_tac ctxt i_of_assn_rls))\n          )\n        )\n      in\n        (* Note: To re-use the to_hnr infrastructure, we first work with\n          $-tags on the abstract function, which are finally removed.\n        *)\n        resolve_tac ctxt @{thms hfsynth_hnr_from_hfI} THEN_ELSE' (\n          SELECT_GOAL (\n            unfold_tac ctxt @{thms to_hnr_prod_fst_snd keep_drop_sels hf_pres_fst} (* Distribute fst,snd over product and hf_pres *)\n            THEN unfold_tac ctxt @{thms hnr_uncurry_unfold hfsynth_ID_R_uncurry_unfold} (* Curry parameters *)\n            THEN unfold_tac ctxt @{thms uncurry_apply uncurry_APP sep_conj_empty' split} (* Curry parameters (II) and remove emp assertion *)\n            (*THEN unfold_tac ctxt @{thms hn_ctxt_ctxt_fix_conv} (* Remove duplicate hn_ctxt (Should not be necessary) *)*)\n            THEN unfold_tac ctxt @{thms all_to_meta imp_to_meta HOL.True_implies_equals HOL.implies_True_equals Pure.triv_forall_equality cnv_conj_to_meta} (* Convert precondition to meta-level *)\n            THEN ALLGOALS i_of_assn_tac (* Generate _::\\<^sub>i_ premises*)\n            THEN unfold_tac ctxt to_hnr_post_rls (* Postprocessing *)\n            THEN unfold_tac ctxt @{thms APP_def} (* Get rid of $ - tags *)\n          )\n        ,\n          K all_tac\n        )\n      end\n\n\n      (************************************)  \n      (* Analyze hnr *)\n      structure Termtab2 = Table(\n        type key = term * term \n        val ord = prod_ord Term_Ord.fast_term_ord Term_Ord.fast_term_ord);\n  \n      type hnr_analysis = {\n        thm: thm,                     \n        precond: term,                \n        prems : term list,\n        ahead: term * bool,           \n        chead: term * bool,           \n        argrels: (term * bool) list,  \n        result_rel: term              \n      }\n  \n    \n      fun analyze_hnr (ctxt:Proof.context) thm = let\n    \n        (* Debug information: Stores string*term pairs, which are pretty-printed on error *)\n        val dbg = Unsynchronized.ref []\n        fun add_dbg msg ts = (\n          dbg := (msg,ts) :: !dbg;\n          ()\n        )\n        fun pretty_dbg (msg,ts) = Pretty.block [\n          Pretty.str msg,\n          Pretty.str \":\",\n          Pretty.brk 1,\n          Pretty.list \"[\" \"]\" (map (Syntax.pretty_term ctxt) ts)\n        ]\n        fun pretty_dbgs l = map pretty_dbg l |> Pretty.fbreaks |> Pretty.block\n    \n        fun trace_dbg msg = Pretty.block [Pretty.str msg, Pretty.fbrk, pretty_dbgs (rev (!dbg))] |> Pretty.string_of |> tracing\n    \n        fun fail msg = (trace_dbg msg; raise THM(msg,~1,[thm])) \n        fun assert cond msg = cond orelse fail msg;\n    \n    \n        (* Heads may have a leading return/RETURN.\n          The following code strips off the leading return, unless it has the form\n          \"return x\" for an argument x\n        *)\n        fun check_strip_leading args t f = (* Handle the case RETURN x, where x is an argument *)\n          if Termtab.defined args f then (t,false) else (f,true)\n    \n        fun strip_leading_RETURN args (t as @{mpat \"RETURN$(?f)\"}) = check_strip_leading args t f\n          | strip_leading_RETURN args (t as @{mpat \"RETURN ?f\"}) = check_strip_leading args t f\n          | strip_leading_RETURN _ t = (t,false)\n    \n        fun strip_leading_return args (t as @{mpat \"return$(?f)\"}) = check_strip_leading args t f\n            | strip_leading_return args (t as @{mpat \"return ?f\"}) = check_strip_leading args t f\n            | strip_leading_return _ t = (t,false)\n    \n    \n        (* The following code strips the arguments of the concrete or abstract\n          function. It knows how to handle APP-tags ($), and stops at PR_CONST-tags.\n    \n          Moreover, it only strips actual arguments that occur in the \n          precondition-section of the hn_refine-statement. This ensures\n          that non-arguments, like maxsize, are treated correctly.\n        *)    \n        fun strip_fun _ (t as @{mpat \"PR_CONST _\"}) = (t,[])\n          | strip_fun s (t as @{mpat \"?f$?x\"}) = check_arg s t f x\n          | strip_fun s (t as @{mpat \"?f ?x\"}) = check_arg s t f x\n          | strip_fun _ f = (f,[])\n        and check_arg s t f x = \n            if Termtab.defined s x then\n              strip_fun s f |> apsnd (curry op :: x)\n            else (t,[])  \n    \n        (* Arguments in the pre/postcondition are wrapped into hn_ctxt tags. \n          This function strips them off. *)    \n        fun dest_hn_ctxt @{mpat \"hn_ctxt ?R ?a ?c\"} = ((a,c),R)\n          | dest_hn_ctxt _ = fail \"Invalid hn_ctxt parameter in pre or postcondition\"\n    \n    \n        fun dest_hn_refine @{mpat \"(hn_refine ?G ?c ?G' ?R ?a)\"} = (G,c,G',R,a) \n          | dest_hn_refine _ = fail \"Conclusion is not a hn_refine statement\"\n    \n        (*\n          Strip separation conjunctions. Special case for \"emp\", which is ignored. \n        *)  \n        fun is_emp @{mpat \\<box>} = true | is_emp _ = false\n  \n        val strip_star' = Sepref_Basic.strip_star #> filter (not o is_emp)\n  \n        (* Compare Termtab2s for equality of keys *)  \n        fun pairs_eq pairs1 pairs2 = \n                  Termtab2.forall (Termtab2.defined pairs1 o fst) pairs2\n          andalso Termtab2.forall (Termtab2.defined pairs2 o fst) pairs1\n    \n    \n        fun atomize_prem @{mpat \"Trueprop ?p\"} = p\n          | atomize_prem _ = fail \"Non-atomic premises\"\n    \n        (* Make HOL conjunction list *)  \n        fun mk_conjs [] = @{const True}\n          | mk_conjs [p] = p\n          | mk_conjs (p::ps) = HOLogic.mk_binop @{const_name \"HOL.conj\"} (p,mk_conjs ps)\n    \n    \n        (***********************)      \n        (* Start actual analysis *)\n    \n        val _ = add_dbg \"thm\" [Thm.prop_of thm]\n        val prems = Thm.prems_of thm\n        val concl = Thm.concl_of thm |> HOLogic.dest_Trueprop\n        val (G,c,G',R,a) = dest_hn_refine concl\n    \n        val pre_pairs = G \n          |> strip_star'\n          |> tap (add_dbg \"precondition\")\n          |> map dest_hn_ctxt\n          |> Termtab2.make\n    \n        val post_pairs = G' \n          |> strip_star'\n          |> tap (add_dbg \"postcondition\")\n          |> map dest_hn_ctxt\n          |> Termtab2.make\n    \n        val _ = assert (pairs_eq pre_pairs post_pairs) \n          \"Parameters in precondition do not match postcondition\"\n    \n        val aa_set = pre_pairs |> Termtab2.keys |> map fst |> Termtab.make_set\n        val ca_set = pre_pairs |> Termtab2.keys |> map snd |> Termtab.make_set\n    \n        val (a,leading_RETURN) = strip_leading_RETURN aa_set a\n        val (c,leading_return) = strip_leading_return ca_set c\n    \n        val _ = add_dbg \"stripped abstract term\" [a]\n        val _ = add_dbg \"stripped concrete term\" [c]\n    \n        val (ahead,aargs) = strip_fun aa_set a;\n        val (chead,cargs) = strip_fun ca_set c;\n    \n        val _ = add_dbg \"abstract head\" [ahead]\n        val _ = add_dbg \"abstract args\" aargs\n        val _ = add_dbg \"concrete head\" [chead]\n        val _ = add_dbg \"concrete args\" cargs\n    \n    \n        val _ = assert (length cargs = length aargs) \"Different number of abstract and concrete arguments\";\n    \n        val _ = assert (not (has_duplicates op aconv aargs)) \"Duplicate abstract arguments\"\n        val _ = assert (not (has_duplicates op aconv cargs)) \"Duplicate concrete arguments\"\n    \n        val argpairs = aargs ~~ cargs\n        val ap_set = Termtab2.make_set argpairs\n        val _ = assert (pairs_eq pre_pairs ap_set) \"Arguments from pre/postcondition do not match operation's arguments\"\n    \n        val pre_rels = map (the o (Termtab2.lookup pre_pairs)) argpairs\n        val post_rels = map (the o (Termtab2.lookup post_pairs)) argpairs\n    \n        val _ = add_dbg \"pre-rels\" pre_rels\n        val _ = add_dbg \"post-rels\" post_rels\n\n        fun adjust_hf_pres @{mpat \"snd (?R\\<^sup>k)\"} = R\n          | adjust_hf_pres t = t\n          \n        val post_rels = map adjust_hf_pres post_rels\n    \n        fun is_invalid R @{mpat \"invalid_assn ?R'\"} = R aconv R'\n          | is_invalid _ @{mpat \"snd (_\\<^sup>d)\"} = true\n          | is_invalid _ _ = false\n    \n        fun is_keep (R,R') =\n          if R aconv R' then true\n          else if is_invalid R R' then false\n          else fail \"Mismatch between pre and post relation for argument\"\n    \n        val keep = map is_keep (pre_rels ~~ post_rels)\n    \n        val argrels = pre_rels ~~ keep\n\n        val aa_set = Termtab.make_set aargs\n        val ca_set = Termtab.make_set cargs\n\n        fun is_precond t =\n          (exists_subterm (Termtab.defined ca_set) t andalso fail \"Premise contains concrete argument\")\n          orelse exists_subterm (Termtab.defined aa_set) t\n\n        val (preconds, prems) = split is_precond prems  \n    \n        val precond = \n          map atomize_prem preconds \n          |> mk_conjs\n          |> fold lambda aargs\n    \n        val _ = add_dbg \"precond\" [precond]\n        val _ = add_dbg \"prems\" prems\n    \n      in\n        {\n          thm = thm,\n          precond = precond,\n          prems = prems,\n          ahead = (ahead,leading_RETURN),\n          chead = (chead,leading_return),\n          argrels = argrels,\n          result_rel = R\n        }\n      end  \n    \n      fun pretty_hnr_analysis \n        ctxt \n        ({thm,precond,ahead,chead,argrels,result_rel,...}) \n        : Pretty.T =\n      let  \n        val _ = thm (* Suppress unused warning for thm *)\n\n        fun pretty_argrel (R,k) = Pretty.block [\n          Syntax.pretty_term ctxt R,\n          if k then Pretty.str \"\\<^sup>k\" else Pretty.str \"\\<^sup>d\"\n        ]\n    \n        val pretty_chead = case chead of \n          (t,false) => Syntax.pretty_term ctxt t \n        | (t,true) => Pretty.block [Pretty.str \"return \", Syntax.pretty_term ctxt t]\n\n        val pretty_ahead = case ahead of \n          (t,false) => Syntax.pretty_term ctxt t \n        | (t,true) => Pretty.block [Pretty.str \"RETURN \", Syntax.pretty_term ctxt t]\n\n      in\n        Pretty.fbreaks [\n          (*Display.pretty_thm ctxt thm,*)\n          Pretty.block [ \n            Pretty.enclose \"[\" \"]\" [pretty_chead, pretty_ahead],\n            Pretty.enclose \"[\" \"]\" [Syntax.pretty_term ctxt precond],\n            Pretty.brk 1,\n            Pretty.block (Pretty.separate \" \\<rightarrow>\" (map pretty_argrel argrels @ [Syntax.pretty_term ctxt result_rel]))\n          ]\n        ] |> Pretty.block\n    \n      end\n    \n    \n      fun mk_hfref_thm \n        ctxt \n        ({thm,precond,prems,ahead,chead,argrels,result_rel}) = \n      let\n    \n        fun mk_keep (R,true) = @{mk_term \"?R\\<^sup>k\"}\n          | mk_keep (R,false) = @{mk_term \"?R\\<^sup>d\"}\n    \n        (* TODO: Move, this is of general use! *)  \n        fun mk_uncurry f = @{mk_term \"uncurry ?f\"}  \n      \n        (* Uncurry function for the given number of arguments. \n          For zero arguments, add a unit-parameter.\n        *)\n        fun rpt_uncurry n t =\n          if n=0 then @{mk_term \"uncurry0 ?t\"}\n          else if n=1 then t \n          else funpow (n-1) mk_uncurry t\n      \n        (* Rewrite uncurried lambda's to \\<lambda>(_,_). _ form. Use top-down rewriting\n          to correctly handle nesting to the left. \n    \n          TODO: Combine with abstraction and  uncurry-procedure,\n            and mark the deviation about uncurry as redundant \n            intermediate step to be eliminated.\n        *)  \n        fun rew_uncurry_lambda t = let\n          val rr = map (Logic.dest_equals o Thm.prop_of) @{thms uncurry_def uncurry0_def}\n          val thy = Proof_Context.theory_of ctxt\n        in \n          Pattern.rewrite_term_top thy rr [] t \n        end  \n    \n        (* Shortcuts for simplification tactics *)\n        fun gsimp_only ctxt sec = let\n          val ss = put_simpset HOL_basic_ss ctxt |> sec\n        in asm_full_simp_tac ss end\n    \n        fun simp_only ctxt thms = gsimp_only ctxt (fn ctxt => ctxt addsimps thms)\n    \n    \n        (********************************)\n        (* Build theorem statement *)\n        (* \\<lbrakk>prems\\<rbrakk> \\<Longrightarrow> (chead,ahead) \\<in> [precond] rels \\<rightarrow> R *)\n    \n        (* Uncurry precondition *)\n        val num_args = length argrels\n        val precond = precond\n          |> rpt_uncurry num_args\n          |> rew_uncurry_lambda (* Convert to nicer \\<lambda>((...,_),_) - form*)\n\n        (* Re-attach leading RETURN/return *)\n        fun mk_RETURN (t,r) = if r then \n            let\n              val T = funpow num_args range_type (fastype_of (fst ahead))\n              val tRETURN = Const (@{const_name RETURN}, T --> Type(@{type_name nres},[T]))\n            in\n              Refine_Util.mk_compN num_args tRETURN t\n            end  \n          else t\n    \n        fun mk_return (t,r) = if r then @{mk_term \"return ?t :: _ llM\"}\n            (*let\n              val T = funpow num_args range_type (fastype_of (fst chead))\n              val tRETURN = Const (@{const_name return}, T --> Type(@{type_name llvm_memory},[T]))\n            in\n              Refine_Util.mk_compN num_args tRETURN t\n            end  *)\n          else t\n          \n        (* Hrmpf!: Gone for good from 2015\\<rightarrow>2016. Inserting ctxt-based substitute here. *)  \n        fun certify_inst ctxt (instT, inst) =\n         (map (apsnd (Thm.ctyp_of ctxt)) instT,\n          map (apsnd (Thm.cterm_of ctxt)) inst);\n\n        (*  \n        fun mk_RETURN (t,r) = if r then @{mk_term \"RETURN o ?t\"} else t\n        fun mk_return (t,r) = if r then @{mk_term \"return o ?t\"} else t\n        *)\n    \n        (* Uncurry abstract and concrete function, append leading return *)\n        val ahead = ahead |> mk_RETURN |> rpt_uncurry num_args  \n        val chead = chead |> mk_return |> rpt_uncurry num_args \n    \n        (* Add keep-flags and summarize argument relations to product *)\n        val argrel = map mk_keep argrels |> rev (* TODO: Why this rev? *) |> mk_hfprods\n    \n        (* Produce final result statement *)\n        \n        val _ = @{print} chead\n        val _ = @{print} (fastype_of chead)\n        \n        val result = @{mk_term \"Trueprop ((?chead,?ahead) \\<in> [?precond]\\<^sub>a ?argrel \\<rightarrow> ?result_rel)\"}\n        val result = Logic.list_implies (prems,result)\n    \n        (********************************)\n        (* Prove theorem *)\n    \n        (* Create context and import result statement and original theorem *)\n        val orig_ctxt = ctxt\n        (*val thy = Proof_Context.theory_of ctxt*)\n        val (insts, ctxt) = Variable.import_inst true [result] ctxt\n        val insts' = certify_inst ctxt insts\n        val result = Term_Subst.instantiate insts result\n        val thm = Thm.instantiate insts' thm\n    \n        (* Unfold APP tags. This is required as some APP-tags have also been unfolded by analysis *)\n        val thm = Local_Defs.unfold0 ctxt @{thms APP_def} thm\n    \n        (* Tactic to prove the theorem. \n          A first step uses hfrefI to get a hnr-goal.\n          This is then normalized in several consecutive steps, which \n            get rid of uncurrying. Finally, the original theorem is used for resolution,\n            where the pre- and postcondition, and result relation are connected with \n            a consequence rule, to handle unfolded hn_ctxt-tags, re-ordered relations,\n            and introduced unit-parameters (TODO: \n              Mark artificially introduced unit-parameter specially, it may get confused \n              with intentional unit-parameter, e.g., functional empty_set ()!)\n    \n          *)\n        fun tac ctxt = \n                resolve_tac ctxt @{thms hfrefI}\n          THEN' gsimp_only ctxt (fn c => c \n            addsimps @{thms uncurry_def hn_ctxt_def uncurry0_def\n                            keep_drop_sels uc_hfprod_sel o_apply\n                            APP_def}\n            |> Splitter.add_split @{thm prod.split}\n          ) \n    \n          THEN' TRY o (\n            REPEAT_ALL_NEW (match_tac ctxt @{thms allI impI})\n            THEN' simp_only ctxt @{thms Product_Type.split prod.inject})\n    \n          THEN' TRY o REPEAT_ALL_NEW (ematch_tac ctxt @{thms conjE})\n          THEN' TRY o hyp_subst_tac ctxt\n          THEN' simp_only ctxt @{thms triv_forall_equality}\n          THEN' (\n            resolve_tac ctxt @{thms hn_refine_cons[rotated]} \n            THEN' (resolve_tac ctxt [thm] THEN_ALL_NEW assume_tac ctxt))\n          THEN_ALL_NEW simp_only ctxt \n            @{thms hn_ctxt_def entails_refl pure_unit_rel_eq_empty\n              mult_ac mult_1 mult_1_right keep_drop_sels}  \n    \n        (* Prove theorem *)  \n        val result = Thm.cterm_of ctxt result\n        val rthm = Goal.prove_internal ctxt [] result (fn _ => ALLGOALS (tac ctxt))\n    \n        (* Export statement to original context *)\n        val rthm = singleton (Variable.export ctxt orig_ctxt) rthm\n    \n        (* Post-processing *)\n        val rthm = Local_Defs.unfold0 ctxt (Named_Theorems.get ctxt @{named_theorems to_hfref_post}) rthm\n\n      in\n        rthm\n      end\n  \n      fun to_hfref ctxt = analyze_hnr ctxt #> mk_hfref_thm ctxt\n\n\n\n\n      (***********************************)\n      (* Composition *)\n\n      local\n        fun norm_set_of ctxt = {\n          trans_rules = Named_Theorems.get ctxt @{named_theorems fcomp_norm_trans},\n          cong_rules = Named_Theorems.get ctxt @{named_theorems fcomp_norm_cong},\n          norm_rules = Named_Theorems.get ctxt @{named_theorems fcomp_norm_norm},\n          refl_rules = Named_Theorems.get ctxt @{named_theorems fcomp_norm_refl}\n        }\n    \n        fun init_rules_of ctxt = Named_Theorems.get ctxt @{named_theorems fcomp_norm_init}\n        fun unfold_rules_of ctxt = Named_Theorems.get ctxt @{named_theorems fcomp_norm_unfold}\n        fun simp_rules_of ctxt = Named_Theorems.get ctxt @{named_theorems fcomp_norm_simps}\n\n      in  \n        fun norm_fcomp_rule ctxt = let\n          open PO_Normalizer Refine_Util\n          val norm1 = gen_norm_rule (init_rules_of ctxt) (norm_set_of ctxt) ctxt\n          val norm2 = Local_Defs.unfold0 ctxt (unfold_rules_of ctxt)\n          val norm3 = Conv.fconv_rule (\n            Simplifier.asm_full_rewrite \n              (put_simpset HOL_basic_ss ctxt addsimps simp_rules_of ctxt))\n    \n          val norm = changed_rule (try_rule norm1 o try_rule norm2 o try_rule norm3)\n        in\n          repeat_rule norm\n        end\n      end  \n\n      fun add_pure_constraints_rule ctxt thm = let\n        val orig_ctxt = ctxt\n    \n        val t = Thm.prop_of thm\n    \n        fun \n          cnv (@{mpat (typs) \"pure (mpaq_STRUCT (mpaq_Var ?x _) :: (?'v_c\\<times>?'v_a) set)\"}) = \n          let\n            val T = a --> c --> @{typ assn}\n            val t = Var (x,T)\n            val t = @{mk_term \"(the_pure ?t)\"}\n          in\n            [(x,T,t)]\n          end\n        | cnv (t$u) = union op= (cnv t) (cnv u)\n        | cnv (Abs (_,_,t)) = cnv t  \n        | cnv _ = []\n    \n        val pvars = cnv t\n    \n        val _ = (pvars |> map #1 |> has_duplicates op=) \n          andalso raise TERM (\"Duplicate indexname with different type\",[t]) (* This should not happen *)\n    \n        val substs = map (fn (x,_,t) => (x,t)) pvars\n    \n        val t' = subst_Vars substs t  \n    \n        fun mk_asm (x,T,_) = let\n          val t = Var (x,T)\n          val t = @{mk_term \"Trueprop (CONSTRAINT is_pure ?t)\"}\n        in\n          t\n        end\n    \n        val assms = map mk_asm pvars\n    \n        fun add_prems prems t = let\n          val prems' = Logic.strip_imp_prems t\n          val concl = Logic.strip_imp_concl t\n        in\n          Logic.list_implies (prems@prems', concl)\n        end\n    \n        val t' = add_prems assms t'\n    \n        val (t',ctxt) = yield_singleton (Variable.import_terms true) t' ctxt\n    \n        val thm' = Goal.prove_internal ctxt [] (Thm.cterm_of ctxt t') (fn _ => \n          ALLGOALS (resolve_tac ctxt [thm] THEN_ALL_NEW assume_tac ctxt))\n    \n        val thm' = norm_fcomp_rule ctxt thm'\n\n        val thm' = singleton (Variable.export ctxt orig_ctxt) thm'\n      in\n        thm'\n      end  \n\n\n      val cfg_simp_precond = \n        Attrib.setup_config_bool @{binding fcomp_simp_precond} (K true)\n\n      local\n        fun mk_simp_thm ctxt t = let\n          val st = t\n            |> HOLogic.mk_Trueprop\n            |> Thm.cterm_of ctxt\n            |> Goal.init\n      \n          val ctxt = Context_Position.set_visible false ctxt  \n          val ctxt = ctxt addsimps (\n              refine_pw_simps.get ctxt \n            @ Named_Theorems.get ctxt @{named_theorems fcomp_prenorm_simps}\n            @ @{thms split_tupled_all cnv_conj_to_meta}  \n            )\n          \n          val trace_incomplete_transfer_tac =\n            COND (Thm.prems_of #> exists (strip_all_body #> Logic.strip_imp_concl #> Term.is_open))\n              (print_tac ctxt \"Failed transfer from intermediate level:\") all_tac\n    \n          val tac = \n            ALLGOALS (resolve_tac ctxt @{thms auto_weaken_pre_comp_PRE_I} )\n            THEN ALLGOALS (Simplifier.asm_full_simp_tac ctxt)\n            THEN trace_incomplete_transfer_tac\n            THEN ALLGOALS (TRY o filter_prems_tac ctxt (K false))\n            THEN Local_Defs.unfold0_tac ctxt [Drule.triv_forall_equality]\n      \n          val st' = tac st |> Seq.take 1 |> Seq.list_of\n          val thm = case st' of [st'] => Goal.conclude st' | _ => raise THM(\"Simp_Precond: Simp-Tactic failed\",~1,[st])\n    \n          (* Check generated premises for leftover intermediate stuff *)\n          val _ = exists (Logic.is_all) (Thm.prems_of thm) \n            andalso raise THM(\"Simp_Precond: Transfer from intermediate level failed\",~1,[thm])\n    \n          val thm = \n             thm\n          (*|> map (Simplifier.asm_full_simplify ctxt)*)\n          |> Conv.fconv_rule (Object_Logic.atomize ctxt)\n          |> Local_Defs.unfold0 ctxt @{thms auto_weaken_pre_to_imp_nf}\n    \n          val thm = case Thm.concl_of thm of\n            @{mpat \"Trueprop (_ \\<longrightarrow> _)\"} => thm\n          | @{mpat \"Trueprop _\"} => thm RS @{thm auto_weaken_pre_add_dummy_imp}  \n          | _ => raise THM(\"Simp_Precond: Generated odd theorem, expected form 'P\\<longrightarrow>Q'\",~1,[thm])\n    \n    \n        in\n          thm\n        end\n      in  \n        fun simplify_precond ctxt thm = let\n          val orig_ctxt = ctxt\n          val thm = Refine_Util.OF_fst @{thms auto_weaken_pre_init} [asm_rl,thm]\n          val thm = \n            Local_Defs.unfold0 ctxt @{thms split_tupled_all} thm\n            OF @{thms auto_weaken_pre_uncurry_start}\n      \n          fun rec_uncurry thm =\n            case try (fn () => thm OF @{thms auto_weaken_pre_uncurry_step}) () of\n              NONE => thm OF @{thms auto_weaken_pre_uncurry_finish}\n            | SOME thm => rec_uncurry thm  \n      \n          val thm = rec_uncurry thm  \n            |> Conv.fconv_rule Thm.eta_conversion\n      \n          val t = case Thm.prems_of thm of\n            t::_ => t | _ => raise THM(\"Simp-Precond: Expected at least one premise\",~1,[thm])\n      \n          val (t,ctxt) = yield_singleton (Variable.import_terms false) t ctxt\n          val ((_,t),ctxt) = Variable.focus NONE t ctxt\n          val t = case t of\n            @{mpat \"Trueprop (_ \\<longrightarrow> ?t)\"} => t | _ => raise TERM(\"Simp_Precond: Expected implication\",[t])\n      \n          val simpthm = mk_simp_thm ctxt t  \n            |> singleton (Variable.export ctxt orig_ctxt)\n            \n          val thm = thm OF [simpthm]  \n          val thm = Local_Defs.unfold0 ctxt @{thms prod_casesK} thm\n        in\n          thm\n        end\n\n        fun simplify_precond_if_cfg ctxt =\n          if Config.get ctxt cfg_simp_precond then\n            simplify_precond ctxt\n          else I\n\n      end  \n\n      (* fref O fref *)\n      fun compose_ff ctxt A B = \n          (@{thm fref_compI_PRE} OF [A,B])\n        |> norm_fcomp_rule ctxt\n        |> simplify_precond_if_cfg ctxt\n        |> Conv.fconv_rule Thm.eta_conversion\n\n      (* hfref O fref *)\n      fun compose_hf ctxt A B =\n          (@{thm hfref_compI_PRE} OF [A,B])\n        |> norm_fcomp_rule ctxt\n        |> simplify_precond_if_cfg ctxt\n        |> Conv.fconv_rule Thm.eta_conversion\n        |> add_pure_constraints_rule ctxt\n        |> Conv.fconv_rule Thm.eta_conversion\n\n      fun ensure_fref ctxt thm = case rthm_type thm of\n        RT_HOPARAM => to_fref ctxt thm\n      | RT_FREF => thm\n      | _ => raise THM(\"Expected parametricity or fref theorem\",~1,[thm])\n\n      fun ensure_fref_nres ctxt thm = let\n        val thm = ensure_fref ctxt thm\n      in\n        case Thm.concl_of thm of\n          @{mpat (typs) \"Trueprop (_\\<in>fref _ _ (_::_ \\<Rightarrow> (_ nres\\<times>_)set))\"} => thm\n        | @{mpat \"Trueprop ((_,_)\\<in>fref _ _ _)\"} => \n            (thm RS @{thm ensure_fref_nresI}) |> Local_Defs.unfold0 ctxt @{thms ensure_fref_nres_unfold}\n        | _ => raise THM(\"Expected fref-theorem\",~1,[thm])\n      end\n\n      fun ensure_hfref ctxt thm = case rthm_type thm of\n        RT_HNR => to_hfref ctxt thm\n      | RT_HFREF => thm\n      | _ => raise THM(\"Expected hnr or hfref theorem\",~1,[thm])\n\n      fun ensure_hnr ctxt thm = case rthm_type thm of\n        RT_HNR => thm\n      | RT_HFREF => to_hnr ctxt thm\n      | _ => raise THM(\"Expected hnr or hfref theorem\",~1,[thm])\n\n      fun gen_compose ctxt A B = let\n        val rtA = rthm_type A\n      in\n        if rtA = RT_HOPARAM orelse rtA = RT_FREF then\n          compose_ff ctxt (ensure_fref ctxt A) (ensure_fref ctxt B)\n        else  \n          compose_hf ctxt (ensure_hfref ctxt A) ((ensure_fref_nres ctxt B))\n        \n      end\n\n      val parse_fcomp_flags = Refine_Util.parse_paren_lists \n        (Refine_Util.parse_bool_config \"prenorm\" cfg_simp_precond)\n\n      val fcomp_attrib = parse_fcomp_flags |-- Attrib.thm >> (fn B => Thm.rule_attribute [] (fn context => fn A => \n      let\n        val ctxt = Context.proof_of context\n      in  \n        gen_compose ctxt A B\n      end))\n\n    end\n  \\<close>\n\n  attribute_setup to_fref = \\<open>\n    Scan.succeed (Thm.rule_attribute [] (Sepref_Rules.to_fref o Context.proof_of))\n  \\<close> \"Convert parametricity theorem to uncurried fref-form\" \n\n  attribute_setup to_foparam = \\<open>\n      Scan.succeed (Thm.rule_attribute [] (Sepref_Rules.to_foparam o Context.proof_of))\n  \\<close> \\<open>Convert param or fref rule to first order rule\\<close>\n  (* Overloading existing param_fo - attribute from Parametricity.thy *)\n  attribute_setup param_fo = \\<open>\n      Scan.succeed (Thm.rule_attribute [] (Sepref_Rules.to_foparam o Context.proof_of))\n  \\<close> \\<open>Convert param or fref rule to first order rule\\<close>\n\n  attribute_setup to_hnr = \\<open>\n    Scan.succeed (Thm.rule_attribute [] (Sepref_Rules.to_hnr o Context.proof_of))\n  \\<close> \"Convert hfref-rule to hnr-rule\"\n  \n  attribute_setup to_hfref = \\<open>Scan.succeed (\n      Thm.rule_attribute [] (Context.proof_of #> Sepref_Rules.to_hfref)\n    )\\<close> \\<open>Convert hnr to hfref theorem\\<close>\n\n\n  attribute_setup ensure_fref_nres = \\<open>Scan.succeed (\n      Thm.rule_attribute [] (Context.proof_of #> Sepref_Rules.ensure_fref_nres)\n    )\\<close>\n\n  attribute_setup sepref_dbg_norm_fcomp_rule = \\<open>Scan.succeed (\n      Thm.rule_attribute [] (Context.proof_of #> Sepref_Rules.norm_fcomp_rule)\n    )\\<close>\n\n  attribute_setup sepref_simplify_precond = \\<open>Scan.succeed (\n      Thm.rule_attribute [] (Context.proof_of #> Sepref_Rules.simplify_precond)\n    )\\<close> \\<open>Simplify precondition of fref/hfref-theorem\\<close>\n\n  attribute_setup FCOMP = Sepref_Rules.fcomp_attrib \"Composition of refinement rules\"\n\nend\n", "meta": {"author": "lammich", "repo": "isabelle_llvm", "sha": "6be37a9c3cae74a1134dbef2979e312abb5f7f42", "save_path": "github-repos/isabelle/lammich-isabelle_llvm", "path": "github-repos/isabelle/lammich-isabelle_llvm/isabelle_llvm-6be37a9c3cae74a1134dbef2979e312abb5f7f42/thys/sepref/Sepref_Rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5506073655352404, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.2624082661398747}}
{"text": "theory Incredible_Correctness\nimports\n  Abstract_Rules_To_Incredible\n  Natural_Deduction\nbegin\n\ntext \\<open>\nIn this theory, we prove that if we have a graph that proves a given abstract task (which is\nrepresented as the context @{term Tasked_Proof_Graph}), then we can prove @{term solved}.\n\\<close>\n\ncontext Tasked_Proof_Graph\nbegin\n\ndefinition adjacentTo :: \"'vertex \\<Rightarrow> ('form, 'var) in_port \\<Rightarrow> ('vertex \\<times> ('form, 'var) out_port)\" where\n \"adjacentTo v p = (SOME ps. (ps, (v,p)) \\<in> edges)\"\n\nfun isReg where\n  \"isReg v p = (case p of Hyp h c \\<Rightarrow> False | Reg  c \\<Rightarrow>\n      (case nodeOf v of\n        Conclusion a \\<Rightarrow> False\n      | Assumption a \\<Rightarrow> False\n      | Rule r \\<Rightarrow> True\n      | Helper \\<Rightarrow> True\n      ))\"\n\nfun toNatRule  where\n  \"toNatRule v p = (case p of Hyp h c \\<Rightarrow> Axiom | Reg  c \\<Rightarrow>\n      (case nodeOf v of\n        Conclusion a \\<Rightarrow> Axiom \\<comment> \\<open>a lie\\<close>\n      | Assumption a \\<Rightarrow> Axiom\n      | Rule r \\<Rightarrow> NatRule (r,c)\n      | Helper \\<Rightarrow> Cut\n      ))\"\n\n\ninductive_set global_assms' :: \"'var itself \\<Rightarrow> 'form set\" for i  where\n  \"v |\\<in>| vertices \\<Longrightarrow> nodeOf v = Assumption p \\<Longrightarrow> labelAtOut v (Reg p) \\<in> global_assms' i\"\n\nlemma finite_global_assms': \"finite (global_assms' i)\"\nproof-\n  have \"finite (fset vertices)\" by (rule finite_fset)\n  moreover\n  have \"global_assms' i \\<subseteq> (\\<lambda> v. case nodeOf v of Assumption p \\<Rightarrow>  labelAtOut v (Reg p)) ` fset vertices\"\n    by (force simp add: global_assms'.simps fmember.rep_eq image_iff )\n  ultimately\n  show ?thesis by (rule finite_surj)\nqed\n\ncontext includes fset.lifting\nbegin\n  lift_definition global_assms :: \"'var itself \\<Rightarrow> 'form fset\" is global_assms' by (rule finite_global_assms')\n  lemmas global_assmsI = global_assms'.intros[Transfer.transferred]\n  lemmas global_assms_simps = global_assms'.simps[Transfer.transferred]\nend\n\nfun extra_assms :: \"('vertex \\<times> ('form, 'var) in_port) \\<Rightarrow> 'form fset\" where\n  \"extra_assms (v, p) = (\\<lambda> p. labelAtOut v p) |`| hyps_for (nodeOf v) p\"\n\nfun hyps_along :: \"('vertex, 'form, 'var) edge' list \\<Rightarrow> 'form fset\" where\n  \"hyps_along pth = ffUnion (extra_assms |`| snd |`| fset_from_list pth) |\\<union>| global_assms TYPE('var)\"\n\nlemma hyps_alongE[consumes 1, case_names Hyp Assumption]:\n  assumes \"f |\\<in>| hyps_along pth\"\n  obtains v p h where \"(v,p) \\<in> snd ` set pth\" and \"f = labelAtOut v h \" and \"h |\\<in>| hyps_for (nodeOf v) p\"\n  | v pf  where \"v |\\<in>| vertices\" and \"nodeOf v = Assumption pf\" \"f = labelAtOut v (Reg pf)\"\n  using assms\n  apply (auto simp add: fmember.rep_eq ffUnion.rep_eq  global_assms_simps[unfolded fmember.rep_eq])\n  apply (metis image_iff snd_conv)\n  done\n\ntext \\<open>Here we build the natural deduction tree, by walking the graph.\\<close>\n\nprimcorec tree :: \"'vertex \\<Rightarrow> ('form, 'var) in_port \\<Rightarrow> ('vertex, 'form, 'var) edge' list \\<Rightarrow>  (('form entailment), ('rule \\<times> 'form) NatRule) dtree\" where\n \"root (tree v p pth) =\n    ((hyps_along ((adjacentTo v p,(v,p))#pth) \\<turnstile> labelAtIn v p),\n    (case adjacentTo v p of (v', p') \\<Rightarrow> toNatRule v' p'\n    ))\"\n | \"cont (tree v p pth) =\n    (case adjacentTo v p of (v', p') \\<Rightarrow>\n    (if isReg v' p' then ((\\<lambda> p''. tree v' p'' ((adjacentTo v p,(v,p))#pth)) |`| inPorts (nodeOf v')) else {||}\n    ))\"\n\n\nlemma fst_root_tree[simp]: \"fst (root (tree v p pth)) = (hyps_along ((adjacentTo v p,(v,p))#pth) \\<turnstile> labelAtIn v p)\" by simp\n\nlemma out_port_cases[consumes 1, case_names Assumption Hyp Rule Helper]:\n  assumes \"p |\\<in>| outPorts n\"\n  obtains\n    a where \"n = Assumption a\" and \"p = Reg a\"\n    | r h c where \"n = Rule r\" and \"p = Hyp h c\"\n    | r f where \"n = Rule r\" and \"p = Reg f\"\n    | \"n = Helper\" and \"p = Reg anyP\"\n  using assms by (atomize_elim, cases p; cases n) auto\n\nlemma hyps_for_fimage: \"hyps_for (Rule r) x = (if x |\\<in>| f_antecedent r then (\\<lambda> f. Hyp f x) |`| (a_hyps x) else {||})\"\n  apply (rule fset_eqI)\n  apply (rename_tac p')\n  apply (case_tac p')\n  apply (auto simp add:  split: if_splits out_port.splits)\n  done\n\ntext \\<open>Now we prove that the thus produced tree is well-formed.\\<close>\n\ntheorem wf_tree:\n  assumes \"valid_in_port (v,p)\"\n  assumes \"terminal_path v t pth\"\n  shows \"wf (tree v p pth)\"\nusing assms\nproof (coinduction arbitrary: v p pth)\ncase (wf v p pth)\n  let ?t = \"tree v p pth\"\n  from saturated[OF wf(1)]\n  obtain v' p'\n  where e:\"((v',p'),(v,p)) \\<in> edges\" and [simp]: \"adjacentTo v p = (v',p')\"\n    by (auto simp add: adjacentTo_def, metis (no_types, lifting) eq_fst_iff tfl_some)\n\n  let ?e = \"((v',p'),(v,p))\"\n  let ?pth' = \"?e#pth\"\n  let ?\\<Gamma> = \"hyps_along ?pth'\"\n  let ?l = \"labelAtIn v p\"\n\n  from e valid_edges have \"v' |\\<in>| vertices\" and \"p' |\\<in>| outPorts (nodeOf v')\" by auto\n  hence \"nodeOf v' \\<in> sset nodes\" using valid_nodes by (meson image_eqI notin_fset subsetD)\n\n  from \\<open>?e \\<in> edges\\<close>\n  have s: \"labelAtOut v' p' = labelAtIn v p\"  by (rule solved)\n\n  from \\<open>p' |\\<in>| outPorts (nodeOf v')\\<close>\n  show ?case\n  proof (cases rule: out_port_cases)\n    case (Hyp r h c)\n\n    from Hyp \\<open>p' |\\<in>| outPorts (nodeOf v')\\<close>\n    have \"h |\\<in>| a_hyps c\" and \"c |\\<in>| f_antecedent r\" by auto\n    hence \"hyps (nodeOf v') (Hyp h c) = Some c\" using Hyp by simp\n\n    from well_scoped[OF \\<open> _ \\<in> edges\\<close>[unfolded Hyp] this]\n    have \"(v, p) = (v', c) \\<or> v \\<in> scope (v', c)\".\n    hence \"(v', c) \\<in> insert (v, p) (snd ` set pth)\"\n    proof\n      assume \"(v, p) = (v', c)\"\n      thus ?thesis by simp\n    next\n      assume \"v \\<in> scope (v', c)\"\n      from this terminal_path_end_is_terminal[OF wf(2)] terminal_path_is_path[OF wf(2)]\n      have \"(v', c) \\<in> snd ` set pth\" by (rule scope_find)\n      thus ?thesis by simp\n    qed\n    moreover\n\n\n    from \\<open>hyps (nodeOf v') (Hyp h c) = Some c\\<close>\n    have \"Hyp h c |\\<in>| hyps_for (nodeOf v') c\" by simp\n    hence \"labelAtOut v' (Hyp h c) |\\<in>| extra_assms (v',c)\" by auto\n    ultimately\n\n    have \"labelAtOut v' (Hyp h c) |\\<in>| ?\\<Gamma>\"\n      by (fastforce simp add: fmember.rep_eq ffUnion.rep_eq)\n\n    hence \"labelAtIn v p |\\<in>| ?\\<Gamma>\" by (simp add: s[symmetric] Hyp fmember.rep_eq)\n    thus ?thesis\n      using Hyp\n      apply (auto intro: exI[where x = ?t] simp add: eff.simps simp del: hyps_along.simps)\n      done\n  next\n    case (Assumption f)\n\n    from \\<open>v' |\\<in>| vertices\\<close> \\<open>nodeOf v' = Assumption f\\<close>\n    have \"labelAtOut v' (Reg f) |\\<in>| global_assms TYPE('var)\"\n      by (rule global_assmsI)\n    hence \"labelAtOut v' (Reg f) |\\<in>| ?\\<Gamma>\" by auto\n    hence \"labelAtIn v p |\\<in>| ?\\<Gamma>\" by (simp add: s[symmetric] Assumption fmember.rep_eq)\n    thus ?thesis using Assumption\n      by (auto intro: exI[where x = ?t] simp add: eff.simps)\n  next\n    case (Rule r f)\n    with \\<open>nodeOf v' \\<in> sset nodes\\<close>\n    have \"r \\<in> sset rules\"\n      by (auto simp add: nodes_def stream.set_map)\n\n    from Rule\n    have \"hyps (nodeOf v') p' = None\" by simp\n    with e \\<open>terminal_path v t pth\\<close>\n    have \"terminal_path v' t ?pth'\"..\n\n    from Rule  \\<open>p' |\\<in>| outPorts (nodeOf v')\\<close>\n    have \"f |\\<in>| f_consequent r\" by simp\n    hence \"f \\<in> set (consequent r)\" by (simp add: f_consequent_def)\n    with \\<open>r \\<in> sset rules\\<close>\n    have \"NatRule (r, f) \\<in> sset (smap NatRule n_rules)\"\n      by (auto simp add: stream.set_map n_rules_def no_empty_conclusions)\n    moreover\n\n    {\n    from \\<open>f |\\<in>| f_consequent r\\<close>\n    have \"f \\<in> set (consequent r)\" by (simp add: f_consequent_def)\n    hence \"natEff_Inst (r, f) f (f_antecedent r)\"\n      by (rule natEff_Inst.intros)\n    hence \"eff (NatRule (r, f)) (?\\<Gamma> \\<turnstile> subst (inst v') (freshen (vidx v') f))\n           ((\\<lambda>ant. ((\\<lambda>p. subst (inst v') (freshen (vidx v') p)) |`| a_hyps ant |\\<union>| ?\\<Gamma> \\<turnstile> subst (inst v') (freshen (vidx v') (a_conc ant)))) |`| f_antecedent r)\"\n           (is \"eff _ _ ?ants\")\n    proof (rule eff.intros)\n      fix ant f\n      assume \"ant |\\<in>| f_antecedent r\"\n      from  \\<open>v' |\\<in>| vertices\\<close> \\<open>ant |\\<in>| f_antecedent r\\<close>\n      have \"valid_in_port (v',ant)\" by (simp add: Rule)\n\n      assume \"f |\\<in>| ?\\<Gamma>\"\n      thus \"freshenLC (vidx v') ` a_fresh ant \\<inter> lconsts f = {}\"\n      proof(induct rule: hyps_alongE)\n        case (Hyp v'' p'' h'')\n\n        from Hyp(1) snd_set_path_verties[OF terminal_path_is_path[OF \\<open>terminal_path v' t ?pth'\\<close>]]\n        have \"v'' |\\<in>| vertices\" by (force simp add: fmember.rep_eq)\n\n        from \\<open>terminal_path v' t ?pth'\\<close> Hyp(1)\n        have \"v'' \\<notin> scope (v', ant)\" by (rule hyps_free_path_not_in_scope)\n        with \\<open>valid_in_port (v',ant)\\<close> \\<open>v'' |\\<in>| vertices\\<close>\n        have \"freshenLC (vidx v') ` local_vars (nodeOf v') ant \\<inter> subst_lconsts (inst v'') = {}\"\n         by (rule out_of_scope)\n        moreover\n        from hyps_free_vertices_distinct'[OF \\<open>terminal_path v' t ?pth'\\<close>] Hyp.hyps(1)\n        have \"v'' \\<noteq> v'\" by (metis distinct.simps(2) fst_conv image_eqI list.set_map)\n        hence \"vidx v'' \\<noteq> vidx v'\" using \\<open>v' |\\<in>| vertices\\<close> \\<open>v'' |\\<in>| vertices\\<close> by (meson vidx_inj inj_onD notin_fset)\n        hence \"freshenLC (vidx v') ` a_fresh ant \\<inter> freshenLC (vidx v'') ` lconsts (labelsOut (nodeOf v'') h'') = {}\"by auto\n        moreover\n        have \"lconsts f \\<subseteq> lconsts (freshen (vidx v'') (labelsOut (nodeOf v'') h'')) \\<union> subst_lconsts (inst v'') \" using \\<open>f = _\\<close>\n          by (simp add: labelAtOut_def fv_subst)\n        ultimately\n        show ?thesis\n          by (fastforce simp add:  lconsts_freshen)\n      next\n        case (Assumption v pf)\n        hence \"f = subst (inst v) (freshen (vidx v) pf)\" by (simp add: labelAtOut_def)\n        moreover\n        from Assumption have \"Assumption pf \\<in> sset nodes\" using valid_nodes by (auto simp add: fmember.rep_eq)\n        hence \"pf \\<in> set assumptions\" unfolding nodes_def by (auto simp add: stream.set_map)\n        hence \"closed pf\" by (rule assumptions_closed)\n        ultimately\n        have \"lconsts f = {}\" by (simp add: closed_no_lconsts lconsts_freshen subst_closed freshen_closed)\n        thus ?thesis by simp\n      qed\n    next\n      fix ant\n      assume \"ant |\\<in>| f_antecedent r\"\n      from  \\<open>v' |\\<in>| vertices\\<close> \\<open>ant |\\<in>| f_antecedent r\\<close>\n      have \"valid_in_port (v',ant)\" by (simp add: Rule)\n      moreover\n      note \\<open>v' |\\<in>| vertices\\<close>\n      moreover\n      hence \"v' \\<notin> scope (v', ant)\" by (rule scopes_not_refl)\n      ultimately\n      have \"freshenLC (vidx v') ` local_vars (nodeOf v') ant \\<inter> subst_lconsts (inst v') = {}\"\n        by (rule out_of_scope)\n      thus \"freshenLC (vidx v') ` a_fresh ant \\<inter> subst_lconsts (inst v') = {}\" by simp\n    qed\n    also\n    have \"subst (inst v') (freshen (vidx v') f) = labelAtOut v' p'\" using Rule by (simp add: labelAtOut_def)\n    also\n    note \\<open>labelAtOut v' p' = labelAtIn v p\\<close>\n    also\n    have \"?ants = ((\\<lambda>x. (extra_assms (v',x) |\\<union>| hyps_along ?pth' \\<turnstile> labelAtIn  v' x)) |`| f_antecedent r)\"\n      by (rule fimage_cong[OF refl])\n        (auto simp add: labelAtIn_def labelAtOut_def Rule hyps_for_fimage fmember.rep_eq ffUnion.rep_eq)\n    finally\n    have \"eff (NatRule (r, f))\n        (?\\<Gamma>, labelAtIn v p)\n        ((\\<lambda>x. extra_assms (v',x) |\\<union>| ?\\<Gamma> \\<turnstile> labelAtIn v' x) |`| f_antecedent r)\".\n    }\n    moreover\n\n    { fix x\n      assume \"x |\\<in>| cont ?t\"\n      then obtain a where \"x = tree v' a ?pth'\" and \"a |\\<in>| f_antecedent r\"\n        by (auto simp add: Rule)\n      note this(1)\n      moreover\n\n      from  \\<open>v' |\\<in>| vertices\\<close> \\<open>a |\\<in>| f_antecedent r\\<close>\n      have \"valid_in_port (v',a)\" by (simp add: Rule)\n      moreover\n\n      note \\<open>terminal_path v' t ?pth'\\<close>\n      ultimately\n\n      have \"\\<exists>v p pth. x = tree v p pth \\<and> valid_in_port (v,p) \\<and>  terminal_path v t pth\"\n        by blast\n    }\n    ultimately\n\n    show ?thesis using Rule\n      by (auto intro!: exI[where x = ?t]  simp add: comp_def funion_assoc)\n  next\n    case Helper\n    from Helper\n    have \"hyps (nodeOf v') p' = None\" by simp\n    with e \\<open>terminal_path v t pth\\<close>\n    have \"terminal_path v' t ?pth'\"..\n\n    have \"labelAtIn v' (plain_ant anyP) = labelAtIn v p\"\n      unfolding s[symmetric]\n      using Helper by (simp add: labelAtIn_def labelAtOut_def)\n    moreover\n    { fix x\n      assume \"x |\\<in>| cont ?t\"\n\n      hence \"x = tree v' (plain_ant anyP) ?pth'\"\n        by (auto simp add: Helper)\n      note this(1)\n      moreover\n\n      from  \\<open>v' |\\<in>| vertices\\<close>\n      have \"valid_in_port (v',plain_ant anyP)\" by (simp add: Helper)\n      moreover\n\n      note \\<open>terminal_path v' t ?pth'\\<close>\n      ultimately\n\n      have \"\\<exists>v p pth. x = tree v p pth \\<and> valid_in_port (v,p) \\<and>  terminal_path v t pth\"\n        by blast\n    }\n    ultimately\n\n    show ?thesis using Helper\n      by (auto intro!: exI[where x = ?t]  simp add: comp_def funion_assoc )\n  qed\nqed\n\nlemma global_in_ass: \"global_assms TYPE('var) |\\<subseteq>| ass_forms\"\nproof\n  fix x\n  assume \"x |\\<in>| global_assms TYPE('var)\"\n  then obtain v pf where \"v |\\<in>| vertices\" and \"nodeOf v = Assumption pf\" and \"x = labelAtOut v (Reg pf)\"\n    by (auto simp add: global_assms_simps)\n  from this (1,2) valid_nodes\n  have \"Assumption pf \\<in> sset nodes\" by (auto simp add: fmember.rep_eq)\n  hence \"pf \\<in> set assumptions\" by (auto simp add: nodes_def stream.set_map)\n  hence \"closed pf\" by (rule  assumptions_closed)\n  with \\<open>x = labelAtOut v (Reg pf)\\<close>\n  have \"x = pf\" by (auto simp add: labelAtOut_def lconsts_freshen closed_no_lconsts freshen_closed subst_closed)\n  thus \"x |\\<in>| ass_forms\" using \\<open>pf \\<in> set assumptions\\<close> by (auto simp add: ass_forms_def)\nqed\n\nprimcorec edge_tree :: \"'vertex \\<Rightarrow> ('form, 'var) in_port \\<Rightarrow> ('vertex, 'form, 'var) edge' tree\" where\n \"root (edge_tree v p) = (adjacentTo v p, (v,p))\"\n | \"cont (edge_tree v p) =\n    (case adjacentTo v p of (v', p') \\<Rightarrow>\n    (if isReg v' p' then ((\\<lambda> p. edge_tree  v' p) |`| inPorts (nodeOf v')) else {||}\n    ))\"\n\nlemma tfinite_map_tree: \"tfinite (map_tree f t) \\<longleftrightarrow> tfinite t\"\nproof\n  assume \"tfinite (map_tree f t)\"\n  thus \"tfinite t\"\n    by (induction \"map_tree f t\" arbitrary: t rule: tfinite.induct)\n       (fastforce intro:  tfinite.intros simp add:  tree.map_sel)\nnext\n  assume \"tfinite t\"\n  thus \"tfinite (map_tree f t)\"\n    by (induction t rule: tfinite.induct)\n       (fastforce intro:  tfinite.intros simp add:  tree.map_sel)\nqed\n\n\nlemma finite_tree_edge_tree:\n  \"tfinite (tree v p pth) \\<longleftrightarrow> tfinite (edge_tree v p)\"\nproof-\n  have \"map_tree (\\<lambda> _. ())  (tree v p pth) = map_tree (\\<lambda> _. ()) (edge_tree v p)\"\n   by(coinduction arbitrary: v p pth)\n     (fastforce simp add: tree.map_sel rel_fset_def rel_set_def split: prod.split out_port.split graph_node.split option.split)\n  thus ?thesis by (metis tfinite_map_tree)\nqed\n\ncoinductive forbidden_path :: \"'vertex \\<Rightarrow> ('vertex, 'form, 'var) edge' stream \\<Rightarrow> bool\"   where\n    forbidden_path: \"((v\\<^sub>1,p\\<^sub>1),(v\\<^sub>2,p\\<^sub>2)) \\<in> edges \\<Longrightarrow> hyps (nodeOf v\\<^sub>1) p\\<^sub>1 = None \\<Longrightarrow> forbidden_path v\\<^sub>1 pth \\<Longrightarrow> forbidden_path v\\<^sub>2 (((v\\<^sub>1,p\\<^sub>1),(v\\<^sub>2,p\\<^sub>2))##pth)\"\n\nlemma path_is_forbidden:\n  assumes \"valid_in_port (v,p)\"\n  assumes \"ipath (edge_tree v p) es\"\n  shows \"forbidden_path v es\"\nusing assms\nproof(coinduction arbitrary: v p es)\n  case forbidden_path\n\n  let ?es' = \"stl es\"\n\n  from forbidden_path(2)\n  obtain t' where \"root (edge_tree v p) = shd es\" and \"t' |\\<in>| cont (edge_tree v p)\" and \"ipath t' ?es'\"\n    by rule blast\n\n  from \\<open>root (edge_tree v p) = shd es\\<close>\n  have [simp]: \"shd es = (adjacentTo v p, (v,p))\" by simp\n\n  from saturated[OF \\<open>valid_in_port (v,p)\\<close>]\n  obtain v' p'\n  where e:\"((v',p'),(v,p)) \\<in> edges\" and [simp]: \"adjacentTo v p = (v',p')\"\n    by (auto simp add: adjacentTo_def, metis (no_types, lifting) eq_fst_iff tfl_some)\n  let ?e = \"((v',p'),(v,p))\"\n\n  from e have \"p' |\\<in>| outPorts (nodeOf v')\" using valid_edges by auto\n  thus ?case\n  proof(cases rule: out_port_cases)\n    case Hyp\n    with  \\<open>t' |\\<in>| cont (edge_tree v p)\\<close>\n    have False by auto\n    thus ?thesis..\n  next\n    case Assumption\n    with  \\<open>t' |\\<in>| cont (edge_tree v p)\\<close>\n    have False by auto\n    thus ?thesis..\n  next\n    case (Rule r f)\n    from \\<open>t' |\\<in>| cont (edge_tree v p)\\<close> Rule\n    obtain a where [simp]: \"t' = edge_tree v' a\" and \"a |\\<in>| f_antecedent r\"  by auto\n\n    have \"es = ?e ## ?es'\" by (cases es rule: stream.exhaust_sel) simp\n    moreover\n\n    have \"?e \\<in> edges\" using e by simp\n    moreover\n\n    from \\<open>p' = Reg f\\<close> \\<open>nodeOf v' = Rule r\\<close>\n    have \"hyps (nodeOf v') p' = None\" by simp\n    moreover\n\n    from e valid_edges have \"v' |\\<in>| vertices\"  by auto\n    with \\<open>nodeOf v' = Rule r\\<close> \\<open>a |\\<in>| f_antecedent r\\<close>\n    have \"valid_in_port (v', a)\" by simp\n    moreover\n\n    have \"ipath (edge_tree v' a) ?es'\" using \\<open>ipath t' _\\<close> by simp\n    ultimately\n\n    show ?thesis by metis\n  next\n    case Helper\n    from \\<open>t' |\\<in>| cont (edge_tree v p)\\<close> Helper\n    have [simp]: \"t' = edge_tree v' (plain_ant anyP)\" by simp\n\n    have \"es = ?e ## ?es'\" by (cases es rule: stream.exhaust_sel) simp\n    moreover\n\n    have \"?e \\<in> edges\" using e by simp\n    moreover\n\n    from \\<open>p' = Reg anyP\\<close> \\<open>nodeOf v' = Helper\\<close>\n    have \"hyps (nodeOf v') p' = None\" by simp\n    moreover\n\n    from e valid_edges have \"v' |\\<in>| vertices\"  by auto\n    with \\<open>nodeOf v' = Helper\\<close>\n    have \"valid_in_port (v', plain_ant anyP)\" by simp\n    moreover\n\n    have \"ipath (edge_tree v' (plain_ant anyP)) ?es'\" using \\<open>ipath t' _\\<close> by simp\n    ultimately\n\n    show ?thesis by metis\n  qed\nqed\n\nlemma forbidden_path_prefix_is_path:\n  assumes \"forbidden_path v es\"\n  obtains v' where  \"path v' v (rev (stake n es))\"\n  using assms\n  apply (atomize_elim)\n  apply (induction n arbitrary: v es)\n  apply simp\n  apply (simp add: path_snoc)\n  apply (subst (asm) (2) forbidden_path.simps)\n  apply auto\n  done\n\nlemma forbidden_path_prefix_is_hyp_free:\n  assumes \"forbidden_path v es\"\n  shows \"hyps_free (rev (stake n es))\"\n  using assms\n  apply (induction n arbitrary: v es)\n  apply (simp add: hyps_free_def)\n  apply (subst (asm) (2) forbidden_path.simps)\n  apply (force simp add: hyps_free_def)\n  done\n\n\ntext \\<open>And now we prove that the tree is finite, which requires the above notion of a\n@{term forbidden_path}, i.e.\\@ an infinite path.\\<close>\n\ntheorem finite_tree:\n  assumes \"valid_in_port (v,p)\"\n  assumes \"terminal_vertex v\"\n  shows \"tfinite (tree v p pth)\"\nproof(rule ccontr)\n  let ?n = \"Suc (fcard vertices)\"\n  assume \"\\<not> tfinite (tree v p pth)\"\n  hence \"\\<not> tfinite (edge_tree v p)\" unfolding finite_tree_edge_tree.\n  then obtain es  :: \"('vertex, 'form, 'var) edge' stream\"\n    where \"ipath (edge_tree v p) es\" using Konig by blast\n  with \\<open>valid_in_port (v,p)\\<close>\n  have \"forbidden_path v es\" by (rule path_is_forbidden)\n  from forbidden_path_prefix_is_path[OF this] forbidden_path_prefix_is_hyp_free[OF this]\n  obtain v' where \"path v' v (rev (stake ?n es))\" and \"hyps_free (rev (stake ?n es))\"\n    by blast\n  from this \\<open>terminal_vertex v\\<close>\n  have \"terminal_path  v' v (rev (stake ?n es))\" by (rule terminal_pathI)\n  hence \"length (rev (stake ?n es)) \\<le> fcard vertices\"\n    by (rule hyps_free_limited)\n  thus False by simp\nqed\n\ntext \\<open>The main result of this theory.\\<close>\n\ntheorem solved\nunfolding solved_def\nproof(intro ballI allI conjI impI)\n  fix c\n  assume \"c |\\<in>| conc_forms\"\n  hence \"c \\<in> set conclusions\"  by (auto simp add: conc_forms_def)\n  from this(1) conclusions_present\n  obtain v where \"v |\\<in>| vertices\" and \"nodeOf v = Conclusion c\"\n    by (auto, metis (no_types, lifting) image_iff image_subset_iff notin_fset)\n\n  have \"valid_in_port (v, (plain_ant c))\"\n    using \\<open>v |\\<in>| vertices\\<close> \\<open>nodeOf _ = _ \\<close>  by simp\n\n  have \"terminal_vertex v\" using \\<open>v |\\<in>| vertices\\<close> \\<open>nodeOf v = Conclusion c\\<close> by auto\n\n  let ?t = \"tree v (plain_ant c) []\"\n\n  have \"fst (root ?t) = (global_assms TYPE('var), c)\"\n    using \\<open>c \\<in> set conclusions\\<close> \\<open>nodeOf _ = _\\<close>\n    by (auto simp add: labelAtIn_def conclusions_closed closed_no_lconsts  freshen_def rename_closed subst_closed)\n  moreover\n\n  have \"global_assms TYPE('var) |\\<subseteq>| ass_forms\" by (rule global_in_ass)\n  moreover\n\n  from  \\<open>terminal_vertex v\\<close>\n  have \"terminal_path v v []\" by (rule terminal_path_empty)\n  with \\<open>valid_in_port (v, (plain_ant c))\\<close>\n  have \"wf ?t\" by (rule wf_tree)\n  moreover\n\n  from \\<open>valid_in_port (v, plain_ant c)\\<close> \\<open>terminal_vertex v\\<close>\n  have \"tfinite ?t\" by (rule finite_tree)\n  ultimately\n\n  show \"\\<exists>\\<Gamma> t. fst (root t) = (\\<Gamma> \\<turnstile> c) \\<and> \\<Gamma> |\\<subseteq>| ass_forms \\<and> wf t \\<and> tfinite t\" by blast\nqed\n\nend\n\nend", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Incredible_Proof_Machine/Incredible_Correctness.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5506073655352404, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.2624082661398747}}
{"text": "(*  Title:      JinjaThreads/J/SmallTypeSafe.thy\n    Author:     Tobias Nipkow, Andreas Lochbihler\n*)\n\nheader {* \\isaheader{Type Safety Proof} *}\n\ntheory TypeSafe\nimports\n  Progress\n  DefAssPreservation\nbegin\n\nsubsection{*Basic preservation lemmas*}\n\ntext{* First two easy preservation lemmas. *}\n\ntheorem (in J_conf_read)\n  shows red_preserves_hconf:\n  \"\\<lbrakk> extTA,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>; P,E,hp s \\<turnstile> e : T; hconf (hp s) \\<rbrakk> \\<Longrightarrow> hconf (hp s')\"\n  and reds_preserves_hconf:\n  \"\\<lbrakk> extTA,P,t \\<turnstile> \\<langle>es,s\\<rangle> [-ta\\<rightarrow>] \\<langle>es',s'\\<rangle>; P,E,hp s \\<turnstile> es [:] Ts; hconf (hp s) \\<rbrakk> \\<Longrightarrow> hconf (hp s')\"\nproof (induct arbitrary: T E and Ts E rule: red_reds.inducts)\n  case RedNew thus ?case\n    by(auto intro: hconf_heap_ops_mono)\nnext\n  case RedNewFail thus ?case\n    by(auto intro: hconf_heap_ops_mono)\nnext\n  case RedNewArray thus ?case\n    by(auto intro: hconf_heap_ops_mono)\nnext\n  case RedNewArrayFail thus ?case\n    by(auto intro: hconf_heap_ops_mono)\nnext\n  case (RedAAss h a U n i v U' h' l)\n  from `sint i < int n` `0 <=s i`\n  have \"nat (sint i) < n\" by(metis nat_less_iff sint_0 word_sle_def)\n  thus ?case using RedAAss\n    by(fastforce elim: hconf_heap_write_mono intro: addr_loc_type.intros simp add: conf_def)\nnext\n  case RedFAss thus ?case\n    by(fastforce elim: hconf_heap_write_mono intro: addr_loc_type.intros simp add: conf_def)\nnext\n  case (RedCallExternal s a U M Ts T' D vs ta va h' ta' e' s')\n  hence \"P,hp s \\<turnstile> a\\<bullet>M(vs) : T\"\n    by(fastforce simp add: external_WT'_iff dest: sees_method_fun)\n  with RedCallExternal show ?case by(auto dest: external_call_hconf)\nqed auto\n\ntheorem (in J_heap) red_preserves_lconf:\n  \"\\<lbrakk> extTA,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>; P,E,hp s \\<turnstile> e:T; P,hp s \\<turnstile> lcl s (:\\<le>) E \\<rbrakk> \\<Longrightarrow> P,hp s' \\<turnstile> lcl s' (:\\<le>) E\"\n  and reds_preserves_lconf:\n  \"\\<lbrakk> extTA,P,t \\<turnstile> \\<langle>es,s\\<rangle> [-ta\\<rightarrow>] \\<langle>es',s'\\<rangle>; P,E,hp s \\<turnstile> es[:]Ts; P,hp s \\<turnstile> lcl s (:\\<le>) E \\<rbrakk> \\<Longrightarrow> P,hp s' \\<turnstile> lcl s' (:\\<le>) E\"\nproof(induct arbitrary: T E and Ts E rule:red_reds.inducts)\n  case RedNew thus ?case\n    by(fastforce intro:lconf_hext hext_heap_ops simp del: fun_upd_apply)\nnext\n  case RedNewFail thus ?case\n    by(auto intro:lconf_hext hext_heap_ops simp del: fun_upd_apply)\nnext\n  case RedNewArray thus ?case\n    by(fastforce intro:lconf_hext hext_heap_ops simp del: fun_upd_apply)\nnext\n  case RedNewArrayFail thus ?case\n    by(fastforce intro:lconf_hext hext_heap_ops simp del: fun_upd_apply)\nnext\n  case RedLAss thus ?case \n    by(fastforce elim: lconf_upd simp add: conf_def simp del: fun_upd_apply )\nnext\n  case RedAAss thus ?case\n    by(fastforce intro:lconf_hext hext_heap_ops simp del: fun_upd_apply)\nnext\n  case RedFAss thus ?case\n    by(fastforce intro:lconf_hext hext_heap_ops simp del: fun_upd_apply)\nnext\n  case (BlockRed e h x V vo ta e' h' x' T T' E)\n  note red = `extTA,P,t \\<turnstile> \\<langle>e,(h, x(V := vo))\\<rangle> -ta\\<rightarrow> \\<langle>e',(h', x')\\<rangle>`\n  note IH = `\\<And>T E. \\<lbrakk>P,E,hp (h, x(V := vo)) \\<turnstile> e : T;\n               P,hp (h, x(V := vo)) \\<turnstile> lcl (h, x(V := vo)) (:\\<le>) E\\<rbrakk>\n              \\<Longrightarrow> P,hp (h', x') \\<turnstile> lcl (h', x') (:\\<le>) E`\n  note wt = `P,E,hp (h, x) \\<turnstile> {V:T=vo; e} : T'`\n  note lconf = `P,hp (h, x) \\<turnstile> lcl (h, x) (:\\<le>) E`\n  from lconf_hext[OF lconf[simplified] red_hext_incr[OF red, simplified]]\n  have \"P,h' \\<turnstile> x (:\\<le>) E\" .\n  moreover from wt have \"P,E(V\\<mapsto>T),h \\<turnstile> e : T'\" by(cases vo, auto)\n  moreover from lconf wt have \"P,h \\<turnstile> x(V := vo) (:\\<le>) E(V \\<mapsto> T)\"\n    by(cases vo)(simp add: lconf_def,auto intro: lconf_upd2 simp add: conf_def)\n  ultimately have \"P,h' \\<turnstile> x' (:\\<le>) E(V\\<mapsto>T)\" \n    by(auto intro: IH[simplified])\n  with `P,h' \\<turnstile> x (:\\<le>) E` show ?case\n    by(auto simp add: lconf_def split: split_if_asm)\nnext\n  case (RedCallExternal s a U M Ts T' D vs ta va h' ta' e' s')\n  from `P,t \\<turnstile> \\<langle>a\\<bullet>M(vs),hp s\\<rangle> -ta\\<rightarrow>ext \\<langle>va,h'\\<rangle>` have \"hp s \\<unlhd> h'\" by(rule red_external_hext)\n  with `s' = (h', lcl s)` `P,hp s \\<turnstile> lcl s (:\\<le>) E` show ?case by(auto intro: lconf_hext)\nqed auto\n\ntext{* Combining conformance of heap and local variables: *}\n\ndefinition (in J_heap_conf_base) sconf :: \"env \\<Rightarrow> ('addr, 'heap) Jstate \\<Rightarrow> bool\" (\"_ \\<turnstile> _ \\<surd>\"   [51,51]50)\n  where \"E \\<turnstile> s \\<surd>  \\<equiv>  let (h,l) = s in hconf h \\<and> P,h \\<turnstile> l (:\\<le>) E \\<and> preallocated h\"\n\ncontext J_conf_read begin\n\nlemma red_preserves_sconf:\n  \"\\<lbrakk> extTA,P,t \\<turnstile> \\<langle>e,s\\<rangle> -tas\\<rightarrow> \\<langle>e',s'\\<rangle>; P,E,hp s \\<turnstile> e : T; E \\<turnstile> s \\<surd> \\<rbrakk> \\<Longrightarrow> E \\<turnstile> s' \\<surd>\"\napply(auto dest: red_preserves_hconf red_preserves_lconf simp add:sconf_def)\napply(fastforce dest: red_hext_incr intro: preallocated_hext)\ndone\n\nlemma reds_preserves_sconf:\n  \"\\<lbrakk> extTA,P,t \\<turnstile> \\<langle>es,s\\<rangle> [-ta\\<rightarrow>] \\<langle>es',s'\\<rangle>; P,E,hp s \\<turnstile> es [:] Ts; E \\<turnstile> s \\<surd> \\<rbrakk> \\<Longrightarrow> E \\<turnstile> s' \\<surd>\"\napply(auto dest: reds_preserves_hconf reds_preserves_lconf simp add: sconf_def)\napply(fastforce dest: reds_hext_incr intro: preallocated_hext)\ndone\n\nend\n\nlemma (in J_heap_base) wt_external_call:\n  \"\\<lbrakk> conf_extRet P h va T; P,E,h \\<turnstile> e : T \\<rbrakk> \\<Longrightarrow> \\<exists>T'. P,E,h \\<turnstile> extRet2J e va : T' \\<and> P \\<turnstile> T' \\<le> T\"\nby(cases va)(auto simp add: conf_def)\n\nsubsection \"Subject reduction\"\n\ntheorem (in J_conf_read) assumes wf: \"wf_J_prog P\"\n  shows subject_reduction:\n  \"\\<lbrakk> extTA,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>; E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> e:T; P,hp s \\<turnstile> t \\<surd>t \\<rbrakk>\n  \\<Longrightarrow> \\<exists>T'. P,E,hp s' \\<turnstile> e':T' \\<and> P \\<turnstile> T' \\<le> T\"\n  and subjects_reduction:\n  \"\\<lbrakk> extTA,P,t \\<turnstile> \\<langle>es,s\\<rangle> [-ta\\<rightarrow>] \\<langle>es',s'\\<rangle>; E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> es[:]Ts; P,hp s \\<turnstile> t \\<surd>t \\<rbrakk>\n  \\<Longrightarrow> \\<exists>Ts'. P,E,hp s' \\<turnstile> es'[:]Ts' \\<and> P \\<turnstile> Ts' [\\<le>] Ts\"\nproof (induct arbitrary: T E and Ts E rule:red_reds.inducts)\n  case RedNew\n  thus ?case by(auto dest: allocate_SomeD)\nnext\n  case RedNewFail thus ?case unfolding sconf_def\n    by(fastforce intro:typeof_OutOfMemory preallocated_heap_ops simp add: xcpt_subcls_Throwable[OF _ wf]) \nnext\n  case NewArrayRed\n  thus ?case by fastforce\nnext\n  case RedNewArray\n  thus ?case by(auto dest: allocate_SomeD)\nnext\n  case RedNewArrayNegative thus ?case unfolding sconf_def\n    by(fastforce intro: preallocated_heap_ops simp add: xcpt_subcls_Throwable[OF _ wf]) \nnext\n  case RedNewArrayFail thus ?case unfolding sconf_def\n    by(fastforce intro:typeof_OutOfMemory preallocated_heap_ops simp add: xcpt_subcls_Throwable[OF _ wf])\nnext\n  case (CastRed e s ta e' s' C T E)\n  have esse: \"extTA,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>\" \n    and IH: \"\\<And>T E. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> e : T; P,hp s \\<turnstile> t \\<surd>t\\<rbrakk> \\<Longrightarrow> \\<exists>T'. P,E,hp s' \\<turnstile> e' : T' \\<and> P \\<turnstile> T' \\<le> T\"\n    and hconf: \"E \\<turnstile> s \\<surd>\"\n    and wtc: \"P,E,hp s \\<turnstile> Cast C e : T\" by fact+\n  thus ?case\n  proof(clarsimp)\n    fix T'\n    assume wte: \"P,E,hp s \\<turnstile> e : T'\" \"is_type P T\"\n    from wte and hconf and IH and `P,hp s \\<turnstile> t \\<surd>t` have \"\\<exists>U. P,E,hp s' \\<turnstile> e' : U \\<and> P \\<turnstile> U \\<le> T'\" by simp\n    then obtain U where wtee: \"P,E,hp s' \\<turnstile> e' : U\" and UsTT: \"P \\<turnstile> U \\<le> T'\" by blast\n    from wtee `is_type P T` have \"P,E,hp s' \\<turnstile> Cast T e' : T\" by(rule WTrtCast)\n    thus \"\\<exists>T'. P,E,hp s' \\<turnstile> Cast T e' : T' \\<and> P \\<turnstile> T' \\<le> T\" by blast\n  qed\nnext\n  case RedCast thus ?case\n    by(clarsimp simp add: is_refT_def)\nnext\n  case RedCastFail thus ?case unfolding sconf_def\n    by(fastforce simp add: xcpt_subcls_Throwable[OF _ wf])\nnext\n  case (InstanceOfRed e s ta e' s' U T E)\n  have IH: \"\\<And>T E. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> e : T; P,hp s \\<turnstile> t \\<surd>t\\<rbrakk> \\<Longrightarrow> \\<exists>T'. P,E,hp s' \\<turnstile> e' : T' \\<and> P \\<turnstile> T' \\<le> T\"\n    and hconf: \"E \\<turnstile> s \\<surd>\"\n    and wtc: \"P,E,hp s \\<turnstile> e instanceof U : T\" \n    and tconf: \"P,hp s \\<turnstile> t \\<surd>t\" by fact+\n  from wtc obtain T' where \"P,E,hp s \\<turnstile> e : T'\" by auto\n  from IH[OF hconf this tconf] obtain T'' where \"P,E,hp s' \\<turnstile> e' : T''\" by auto\n  with wtc show ?case by auto\nnext\n  case RedInstanceOf thus ?case\n    by(clarsimp)\nnext\n  case (BinOpRed1 e\\<^sub>1 s ta e\\<^sub>1' s' bop e\\<^sub>2 T E)\n  have red: \"extTA,P,t \\<turnstile> \\<langle>e\\<^sub>1, s\\<rangle> -ta\\<rightarrow> \\<langle>e\\<^sub>1', s'\\<rangle>\"\n   and IH: \"\\<And>T E. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> e\\<^sub>1:T; P,hp s \\<turnstile> t \\<surd>t\\<rbrakk>\n                 \\<Longrightarrow> \\<exists>U. P,E,hp s' \\<turnstile> e\\<^sub>1' : U \\<and> P \\<turnstile> U \\<le> T\"\n   and conf: \"E \\<turnstile> s \\<surd>\" and wt: \"P,E,hp s \\<turnstile> e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2 : T\" \n   and tconf: \"P,hp s \\<turnstile> t \\<surd>t\" by fact+\n  from wt obtain T1 T2 where wt1: \"P,E,hp s \\<turnstile> e\\<^sub>1 : T1\"\n    and wt2: \"P,E,hp s \\<turnstile> e\\<^sub>2 : T2\" and wtbop: \"P \\<turnstile> T1\\<guillemotleft>bop\\<guillemotright>T2 : T\" by auto\n  from IH[OF conf wt1 tconf] obtain T1' where wt1': \"P,E,hp s' \\<turnstile> e\\<^sub>1' : T1'\"\n    and sub: \"P \\<turnstile> T1' \\<le> T1\" by blast\n  from WTrt_binop_widen_mono[OF wtbop sub widen_refl]\n  obtain T' where wtbop': \"P \\<turnstile> T1'\\<guillemotleft>bop\\<guillemotright>T2 : T'\" and sub': \"P \\<turnstile> T' \\<le> T\" by blast\n  from wt1' WTrt_hext_mono[OF wt2 red_hext_incr[OF red]] wtbop'\n  have \"P,E,hp s' \\<turnstile> e\\<^sub>1' \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2 : T'\" by(rule WTrtBinOp)\n  with sub' show ?case by blast\nnext\n  case (BinOpRed2 e\\<^sub>2 s ta e\\<^sub>2' s' v\\<^sub>1 bop T E)\n  have red: \"extTA,P,t \\<turnstile> \\<langle>e\\<^sub>2,s\\<rangle> -ta\\<rightarrow> \\<langle>e\\<^sub>2',s'\\<rangle>\" by fact\n  have IH: \"\\<And>E T. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> e\\<^sub>2:T; P,hp s \\<turnstile> t \\<surd>t\\<rbrakk>\n                 \\<Longrightarrow> \\<exists>U. P,E,hp s' \\<turnstile> e\\<^sub>2' : U \\<and> P \\<turnstile> U \\<le> T\" \n    and tconf: \"P,hp s \\<turnstile> t \\<surd>t\" by fact+\n  have conf: \"E \\<turnstile> s \\<surd>\" and wt: \"P,E,hp s \\<turnstile> (Val v\\<^sub>1) \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2 : T\" by fact+\n  from wt obtain T1 T2 where wt1: \"P,E,hp s \\<turnstile> Val v\\<^sub>1 : T1\"\n    and wt2: \"P,E,hp s \\<turnstile> e\\<^sub>2 : T2\" and wtbop: \"P \\<turnstile> T1\\<guillemotleft>bop\\<guillemotright>T2 : T\" by auto\n  from IH[OF conf wt2 tconf] obtain T2' where wt2': \"P,E,hp s' \\<turnstile> e\\<^sub>2' : T2'\"\n    and sub: \"P \\<turnstile> T2' \\<le> T2\" by blast\n  from WTrt_binop_widen_mono[OF wtbop widen_refl sub]\n  obtain T' where wtbop': \"P \\<turnstile> T1\\<guillemotleft>bop\\<guillemotright>T2' : T'\" and sub': \"P \\<turnstile> T' \\<le> T\" by blast\n  from WTrt_hext_mono[OF wt1 red_hext_incr[OF red]] wt2' wtbop'\n  have \"P,E,hp s' \\<turnstile> Val v\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2' : T'\" by(rule WTrtBinOp)\n  with sub' show ?case by blast\nnext\n  case (RedBinOp bop v1 v2 v s)\n  from `E \\<turnstile> s \\<surd>` have preh: \"preallocated (hp s)\" by(cases s)(simp add: sconf_def)\n  from `P,E,hp s \\<turnstile> Val v1 \\<guillemotleft>bop\\<guillemotright> Val v2 : T` obtain T1 T2\n    where \"typeof\\<^bsub>hp s\\<^esub> v1 = \\<lfloor>T1\\<rfloor>\" \"typeof\\<^bsub>hp s\\<^esub> v2 = \\<lfloor>T2\\<rfloor>\" \"P \\<turnstile> T1\\<guillemotleft>bop\\<guillemotright>T2 : T\" by auto\n  with wf preh have \"P,hp s \\<turnstile> v :\\<le> T\" using `binop bop v1 v2 = \\<lfloor>Inl v\\<rfloor>`\n    by(rule binop_type)\n  thus ?case by(auto simp add: conf_def)\nnext\n  case (RedBinOpFail bop v1 v2 a s)\n  from `E \\<turnstile> s \\<surd>` have preh: \"preallocated (hp s)\" by(cases s)(simp add: sconf_def)\n  from `P,E,hp s \\<turnstile> Val v1 \\<guillemotleft>bop\\<guillemotright> Val v2 : T` obtain T1 T2\n    where \"typeof\\<^bsub>hp s\\<^esub> v1 = \\<lfloor>T1\\<rfloor>\" \"typeof\\<^bsub>hp s\\<^esub> v2 = \\<lfloor>T2\\<rfloor>\" \"P \\<turnstile> T1\\<guillemotleft>bop\\<guillemotright>T2 : T\" by auto\n  with wf preh have \"P,hp s \\<turnstile> Addr a :\\<le> Class Throwable\" using `binop bop v1 v2 = \\<lfloor>Inr a\\<rfloor>`\n    by(rule binop_type)\n  thus ?case by(auto simp add: conf_def)\nnext\n  case RedVar thus ?case by (fastforce simp:sconf_def lconf_def conf_def)\nnext\n  case LAssRed thus ?case by(blast intro:widen_trans)\nnext\n  case RedLAss thus ?case by fastforce\nnext\n  case (AAccRed1 a s ta a' s' i T E)\n  have IH: \"\\<And>E T. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> a : T; P,hp s \\<turnstile> t \\<surd>t\\<rbrakk> \\<Longrightarrow> \\<exists>T'. P,E,hp s' \\<turnstile> a' : T' \\<and> P \\<turnstile> T' \\<le> T\"\n    and assa: \"extTA,P,t \\<turnstile> \\<langle>a,s\\<rangle> -ta\\<rightarrow> \\<langle>a',s'\\<rangle>\"\n    and wt: \"P,E,hp s \\<turnstile> a\\<lfloor>i\\<rceil> : T\"\n    and hconf: \"E \\<turnstile> s \\<surd>\" \n    and tconf: \"P,hp s \\<turnstile> t \\<surd>t\" by fact+\n  from wt have wti: \"P,E,hp s \\<turnstile> i : Integer\" by auto\n  from wti red_hext_incr[OF assa] have wti': \"P,E,hp s' \\<turnstile> i : Integer\" by - (rule WTrt_hext_mono)\n  { assume wta: \"P,E,hp s \\<turnstile> a : T\\<lfloor>\\<rceil>\"\n    from IH[OF hconf wta tconf]\n    obtain U where wta': \"P,E,hp s' \\<turnstile> a' : U\" and UsubT: \"P \\<turnstile> U \\<le> T\\<lfloor>\\<rceil>\" by fastforce\n    with wta' wti' have ?case by(cases U, auto simp add: widen_Array) }\n  moreover\n  { assume wta: \"P,E,hp s \\<turnstile> a : NT\"\n    from IH[OF hconf wta tconf] have \"P,E,hp s' \\<turnstile> a' : NT\" by fastforce\n    from this wti' have ?case\n      by(fastforce intro:WTrtAAccNT) }\n  ultimately show ?case using wt by auto\nnext\n  case (AAccRed2 i s ta i' s' a T E)\n  have IH: \"\\<And>E T. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> i : T; P,hp s \\<turnstile> t \\<surd>t\\<rbrakk> \\<Longrightarrow> \\<exists>T'. P,E,hp s' \\<turnstile> i' : T' \\<and> P \\<turnstile> T' \\<le> T\"\n    and issi: \"extTA,P,t \\<turnstile> \\<langle>i,s\\<rangle> -ta\\<rightarrow> \\<langle>i',s'\\<rangle>\"\n    and wt: \"P,E,hp s \\<turnstile> Val a\\<lfloor>i\\<rceil> : T\"\n    and sconf: \"E \\<turnstile> s \\<surd>\" \n    and tconf: \"P,hp s \\<turnstile> t \\<surd>t\" by fact+\n  from wt have wti: \"P,E,hp s \\<turnstile> i : Integer\" by auto\n  from wti IH sconf tconf have wti': \"P,E,hp s' \\<turnstile> i' : Integer\" by blast\n  from wt show ?case\n  proof (rule WTrt_elim_cases)\n    assume wta: \"P,E,hp s \\<turnstile> Val a : T\\<lfloor>\\<rceil>\"\n    from wta red_hext_incr[OF issi] have wta': \"P,E,hp s' \\<turnstile> Val a : T\\<lfloor>\\<rceil>\" by (rule WTrt_hext_mono)\n    from wta' wti' show ?case by(fastforce)\n  next\n    assume wta: \"P,E,hp s \\<turnstile> Val a : NT\"\n    from wta red_hext_incr[OF issi] have wta': \"P,E,hp s' \\<turnstile> Val a : NT\" by (rule WTrt_hext_mono)\n    from wta' wti' show ?case\n      by(fastforce elim:WTrtAAccNT)\n  qed\nnext\n  case RedAAccNull thus ?case unfolding sconf_def\n    by(fastforce simp add: xcpt_subcls_Throwable[OF _ wf])\nnext\n  case RedAAccBounds thus ?case unfolding sconf_def\n    by(fastforce simp add: xcpt_subcls_Throwable[OF _ wf])\nnext\n  case (RedAAcc h a T n i v l T' E)\n  from `E \\<turnstile> (h, l) \\<surd>` have \"hconf h\" by(clarsimp simp add: sconf_def)\n  from `0 <=s i` `sint i < int n`\n  have \"nat (sint i) < n\" by(metis nat_less_iff sint_0 word_sle_def)\n  with `typeof_addr h a = \\<lfloor>Array_type T n\\<rfloor>` have \"P,h \\<turnstile> a@ACell (nat (sint i)) : T\"\n    by(auto intro: addr_loc_type.intros)\n  from heap_read_conf[OF `heap_read h a (ACell (nat (sint i))) v` this] `hconf h`\n  have \"P,h \\<turnstile> v :\\<le> T\" by simp\n  thus ?case using RedAAcc by(auto simp add: conf_def)\nnext\n  case (AAssRed1 a s ta a' s' i e T E)\n  have IH: \"\\<And>E T. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> a : T; P,hp s \\<turnstile> t \\<surd>t\\<rbrakk> \\<Longrightarrow> \\<exists>T'. P,E,hp s' \\<turnstile> a' : T' \\<and> P \\<turnstile> T' \\<le> T\"\n    and assa: \"extTA,P,t \\<turnstile> \\<langle>a,s\\<rangle> -ta\\<rightarrow> \\<langle>a',s'\\<rangle>\"\n    and wt: \"P,E,hp s \\<turnstile> a\\<lfloor>i\\<rceil> := e : T\"\n    and sconf: \"E \\<turnstile> s \\<surd>\" \n    and tconf: \"P,hp s \\<turnstile> t \\<surd>t\" by fact+\n  from wt have void: \"T = Void\" by blast\n  from wt have wti: \"P,E,hp s \\<turnstile> i : Integer\" by auto\n  from wti red_hext_incr[OF assa] have wti': \"P,E,hp s' \\<turnstile> i : Integer\" by - (rule WTrt_hext_mono)\n  { assume wta: \"P,E,hp s \\<turnstile> a : NT\"\n    from IH[OF sconf wta tconf] have wta': \"P,E,hp s' \\<turnstile> a' : NT\" by fastforce\n    from wt wta obtain V where wte: \"P,E,hp s \\<turnstile> e : V\" by(auto)\n    from wte red_hext_incr[OF assa] have wte': \"P,E,hp s' \\<turnstile> e : V\" by - (rule WTrt_hext_mono)\n    from wta' wti' wte' void have ?case\n      by(fastforce elim: WTrtAAssNT) }\n  moreover\n  { fix U\n    assume wta: \"P,E,hp s \\<turnstile> a : U\\<lfloor>\\<rceil>\"\n    from IH[OF sconf wta tconf]\n    obtain U' where wta': \"P,E,hp s' \\<turnstile> a' : U'\" and UsubT: \"P \\<turnstile> U' \\<le> U\\<lfloor>\\<rceil>\" by fastforce\n    with wta' have ?case\n    proof(cases U')\n      case NT\n      assume UNT: \"U' = NT\"\n      from UNT wt wta obtain V where wte: \"P,E,hp s \\<turnstile> e : V\" by(auto)\n      from wte red_hext_incr[OF assa] have wte': \"P,E,hp s' \\<turnstile> e : V\" by - (rule WTrt_hext_mono)\n      from wta' UNT wti' wte' void show ?thesis\n        by(fastforce elim: WTrtAAssNT)\n    next\n      case (Array A)\n      have UA: \"U' = A\\<lfloor>\\<rceil>\" by fact\n      with UA UsubT wt wta obtain V where wte: \"P,E,hp s \\<turnstile> e : V\" by auto\n      from wte red_hext_incr[OF assa] have wte': \"P,E,hp s' \\<turnstile> e : V\" by - (rule WTrt_hext_mono)\n      with wta' wte' UA wti' void show ?thesis by (fast elim:WTrtAAss)\n    qed(simp_all add: widen_Array) }\n  ultimately show ?case using wt by blast\nnext\n  case (AAssRed2 i s ta i' s' a e T E)\n  have IH: \"\\<And>E T. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> i : T; P,hp s \\<turnstile> t \\<surd>t \\<rbrakk> \\<Longrightarrow> \\<exists>T'. P,E,hp s' \\<turnstile> i' : T' \\<and> P \\<turnstile> T' \\<le> T\" \n    and issi: \"extTA,P,t \\<turnstile> \\<langle>i,s\\<rangle> -ta\\<rightarrow> \\<langle>i',s'\\<rangle>\" \n    and wt: \"P,E,hp s \\<turnstile> Val a\\<lfloor>i\\<rceil> := e : T\" \n    and sconf: \"E \\<turnstile> s \\<surd>\" and tconf: \"P,hp s \\<turnstile> t \\<surd>t\" by fact+\n  from wt have void: \"T = Void\" by blast\n  from wt have wti: \"P,E,hp s \\<turnstile> i : Integer\" by auto\n  from IH[OF sconf wti tconf] have wti': \"P,E,hp s' \\<turnstile> i' : Integer\" by fastforce\n  from wt show ?case\n  proof(rule WTrt_elim_cases)\n    fix U T'\n    assume wta: \"P,E,hp s \\<turnstile> Val a : U\\<lfloor>\\<rceil>\"\n      and wte: \"P,E,hp s \\<turnstile> e : T'\"\n    from wte red_hext_incr[OF issi] have wte': \"P,E,hp s' \\<turnstile> e : T'\" by - (rule WTrt_hext_mono)\n    from wta red_hext_incr[OF issi] have wta': \"P,E,hp s' \\<turnstile> Val a : U\\<lfloor>\\<rceil>\" by - (rule WTrt_hext_mono)\n    from wta' wti' wte' void show ?case by (fastforce elim:WTrtAAss)\n  next\n    fix T'\n    assume wta: \"P,E,hp s \\<turnstile> Val a : NT\"\n      and wte: \"P,E,hp s \\<turnstile> e : T'\"\n    from wte red_hext_incr[OF issi] have wte': \"P,E,hp s' \\<turnstile> e : T'\" by - (rule WTrt_hext_mono)\n    from wta red_hext_incr[OF issi] have wta': \"P,E,hp s' \\<turnstile> Val a : NT\" by - (rule WTrt_hext_mono)\n    from wta' wti' wte' void show ?case by (fastforce elim:WTrtAAss)\n  qed\nnext\n  case (AAssRed3 e s ta e' s' a i T E)\n  have IH: \"\\<And>E T. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> e : T; P,hp s \\<turnstile> t \\<surd>t\\<rbrakk> \\<Longrightarrow> \\<exists>T'. P,E,hp s' \\<turnstile> e' : T' \\<and> P \\<turnstile> T' \\<le> T\" \n    and issi: \"extTA,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>\" \n    and wt: \"P,E,hp s \\<turnstile> Val a\\<lfloor>Val i\\<rceil> := e : T\" \n    and sconf: \"E \\<turnstile> s \\<surd>\" and tconf: \"P,hp s \\<turnstile> t \\<surd>t\" by fact+\n  from wt have void: \"T = Void\" by blast\n  from wt have wti: \"P,E,hp s \\<turnstile> Val i : Integer\" by auto\n  from wti red_hext_incr[OF issi] have wti': \"P,E,hp s' \\<turnstile> Val i : Integer\" by - (rule WTrt_hext_mono)\n  from wt show ?case\n  proof(rule WTrt_elim_cases)\n    fix U T'\n    assume wta: \"P,E,hp s \\<turnstile> Val a : U\\<lfloor>\\<rceil>\"\n      and wte: \"P,E,hp s \\<turnstile> e : T'\"\n    from wta red_hext_incr[OF issi] have wta': \"P,E,hp s' \\<turnstile> Val a : U\\<lfloor>\\<rceil>\" by - (rule WTrt_hext_mono)\n    from IH[OF sconf wte tconf]\n    obtain V where wte': \"P,E,hp s' \\<turnstile> e' : V\" by fastforce\n    from wta' wti' wte' void show ?case by (fastforce elim:WTrtAAss)\n  next\n    fix T'\n    assume wta: \"P,E,hp s \\<turnstile> Val a : NT\"\n      and wte: \"P,E,hp s \\<turnstile> e : T'\"\n    from wta red_hext_incr[OF issi] have wta': \"P,E,hp s' \\<turnstile> Val a : NT\" by - (rule WTrt_hext_mono)\n    from IH[OF sconf wte tconf]\n    obtain V where wte': \"P,E,hp s' \\<turnstile> e' : V\" by fastforce\n    from wta' wti' wte' void show ?case by (fastforce elim:WTrtAAss)\n  qed\nnext\n  case RedAAssNull thus ?case unfolding sconf_def\n    by(fastforce simp add: xcpt_subcls_Throwable[OF _ wf])\nnext\n  case RedAAssBounds thus ?case unfolding sconf_def\n    by(fastforce simp add: xcpt_subcls_Throwable[OF _ wf])\nnext\n  case RedAAssStore thus ?case unfolding sconf_def\n    by(fastforce simp add: xcpt_subcls_Throwable[OF _ wf])\nnext\n  case RedAAss thus ?case\n    by(auto simp del:fun_upd_apply)\nnext\n  case (ALengthRed a s ta a' s' T E)\n  note IH = `\\<And>T'. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> a : T'; P,hp s \\<turnstile> t \\<surd>t\\<rbrakk>\n      \\<Longrightarrow> \\<exists>T''. P,E,hp s' \\<turnstile> a' : T'' \\<and> P \\<turnstile> T'' \\<le> T'`\n  from `P,E,hp s \\<turnstile> a\\<bullet>length : T`\n  show ?case\n  proof(rule WTrt_elim_cases)\n    fix T'\n    assume [simp]: \"T = Integer\"\n      and wta: \"P,E,hp s \\<turnstile> a : T'\\<lfloor>\\<rceil>\"\n    from wta `E \\<turnstile> s \\<surd>` IH `P,hp s \\<turnstile> t \\<surd>t`\n    obtain T'' where wta': \"P,E,hp s' \\<turnstile> a' : T''\" \n      and sub: \"P \\<turnstile> T'' \\<le> T'\\<lfloor>\\<rceil>\" by blast\n    from sub have \"P,E,hp s' \\<turnstile> a'\\<bullet>length : Integer\"\n      unfolding widen_Array\n    proof(rule disjE)\n      assume \"T'' = NT\"\n      with wta' show ?thesis by(auto)\n    next\n      assume \"\\<exists>V. T'' = V\\<lfloor>\\<rceil> \\<and> P \\<turnstile> V \\<le> T'\"\n      then obtain V where \"T'' = V\\<lfloor>\\<rceil>\" \"P \\<turnstile> V \\<le> T'\" by blast\n      with wta' show ?thesis by -(rule WTrtALength, simp)\n    qed\n    thus ?thesis by(simp)\n  next\n    assume \"P,E,hp s \\<turnstile> a : NT\"\n    with `E \\<turnstile> s \\<surd>` IH `P,hp s \\<turnstile> t \\<surd>t`\n    obtain T'' where wta': \"P,E,hp s' \\<turnstile> a' : T''\" \n      and sub: \"P \\<turnstile> T'' \\<le> NT\" by blast\n    from sub have \"T'' = NT\" by auto\n    with wta' show ?thesis by(auto)\n  qed\nnext\n  case (RedALength h a T n l T' E)\n  from `P,E,hp (h, l) \\<turnstile> addr a\\<bullet>length : T'` `typeof_addr h a = \\<lfloor>Array_type T n\\<rfloor>`\n  have [simp]: \"T' = Integer\" by(auto)\n  thus ?case by(auto)\nnext\n  case RedALengthNull thus ?case unfolding sconf_def\n    by(fastforce simp add: xcpt_subcls_Throwable[OF _ wf])\nnext\n  case (FAccRed e s ta e' s' F D T E)\n  have IH: \"\\<And>E T. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> e : T; P,hp s \\<turnstile> t \\<surd>t\\<rbrakk>\n                 \\<Longrightarrow> \\<exists>U. P,E,hp s' \\<turnstile> e' : U \\<and> P \\<turnstile> U \\<le> T\"\n   and conf: \"E \\<turnstile> s \\<surd>\" and wt: \"P,E,hp s \\<turnstile> e\\<bullet>F{D} : T\" \n   and tconf: \"P,hp s \\<turnstile> t \\<surd>t\" by fact+\n  -- \"Now distinguish the two cases how wt can have arisen.\"\n  { fix T' C fm\n    assume wte: \"P,E,hp s \\<turnstile> e : T'\"\n      and icto: \"class_type_of' T' = \\<lfloor>C\\<rfloor>\"\n      and has: \"P \\<turnstile> C has F:T (fm) in D\"\n    from IH[OF conf wte tconf]\n    obtain U where wte': \"P,E,hp s' \\<turnstile> e' : U\" and UsubC: \"P \\<turnstile> U \\<le> T'\" by auto\n    -- \"Now distinguish what @{term U} can be.\"\n    with UsubC have ?case\n    proof(cases \"U = NT\")\n      case True\n      thus ?thesis using wte' by(blast intro:WTrtFAccNT widen_refl) \n    next\n      case False\n      with icto UsubC obtain C' where icto': \"class_type_of' U = \\<lfloor>C'\\<rfloor>\"\n        and C'subC: \"P \\<turnstile> C' \\<preceq>\\<^sup>* C\"\n        by(rule widen_is_class_type_of)\n      from has_field_mono[OF has C'subC] wte' icto'\n      show ?thesis by(auto intro!:WTrtFAcc) \n    qed }\n  moreover\n  { assume \"P,E,hp s \\<turnstile> e : NT\"\n    hence \"P,E,hp s' \\<turnstile> e' : NT\" using IH[OF conf _ tconf] by fastforce\n    hence ?case  by(fastforce intro:WTrtFAccNT widen_refl) }\n  ultimately show ?case using wt by blast\nnext\n  case RedFAcc thus ?case unfolding sconf_def\n    by(fastforce dest: heap_read_conf intro: addr_loc_type.intros simp add: conf_def)\nnext\n  case RedFAccNull thus ?case unfolding sconf_def\n    by(fastforce simp add: xcpt_subcls_Throwable[OF _ wf])\nnext\n  case (FAssRed1 e s ta e' s' F D e\\<^sub>2)\n  have red: \"extTA,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>\"\n   and IH: \"\\<And>E T. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> e : T; P,hp s \\<turnstile> t \\<surd>t\\<rbrakk>\n                 \\<Longrightarrow> \\<exists>U. P,E,hp s' \\<turnstile> e' : U \\<and> P \\<turnstile> U \\<le> T\"\n   and conf: \"E \\<turnstile> s \\<surd>\" and wt: \"P,E,hp s \\<turnstile> e\\<bullet>F{D}:=e\\<^sub>2 : T\"\n   and tconf: \"P,hp s \\<turnstile> t \\<surd>t\" by fact+\n  from wt have void: \"T = Void\" by blast\n  -- \"We distinguish if @{term e} has type @{term NT} or a Class type\"\n  { assume \"P,E,hp s \\<turnstile> e : NT\"\n    hence \"P,E,hp s' \\<turnstile> e' : NT\" using IH[OF conf _ tconf] by fastforce\n    moreover obtain T\\<^sub>2 where \"P,E,hp s \\<turnstile> e\\<^sub>2 : T\\<^sub>2\" using wt by auto\n    from this red_hext_incr[OF red] have  \"P,E,hp s' \\<turnstile> e\\<^sub>2 : T\\<^sub>2\"\n      by(rule WTrt_hext_mono)\n    ultimately have ?case using void by(blast intro!:WTrtFAssNT)\n  }\n  moreover\n  { fix T' C TF T\\<^sub>2 fm\n    assume wt\\<^sub>1: \"P,E,hp s \\<turnstile> e : T'\" and icto: \"class_type_of' T' = \\<lfloor>C\\<rfloor>\" and wt\\<^sub>2: \"P,E,hp s \\<turnstile> e\\<^sub>2 : T\\<^sub>2\"\n      and has: \"P \\<turnstile> C has F:TF (fm) in D\" and sub: \"P \\<turnstile> T\\<^sub>2 \\<le> TF\"\n    obtain U where wt\\<^sub>1': \"P,E,hp s' \\<turnstile> e' : U\" and UsubC: \"P \\<turnstile> U \\<le> T'\"\n      using IH[OF conf wt\\<^sub>1 tconf] by blast\n    have wt\\<^sub>2': \"P,E,hp s' \\<turnstile> e\\<^sub>2 : T\\<^sub>2\"\n      by(rule WTrt_hext_mono[OF wt\\<^sub>2 red_hext_incr[OF red]])\n    -- \"Is @{term U} the null type or a class type?\"\n    have ?case\n    proof(cases \"U = NT\")\n      case True\n      with wt\\<^sub>1' wt\\<^sub>2' void show ?thesis by(blast intro!:WTrtFAssNT)\n    next\n      case False\n      with icto UsubC obtain C' where icto': \"class_type_of' U = \\<lfloor>C'\\<rfloor>\"\n        and \"subclass\": \"P \\<turnstile> C' \\<preceq>\\<^sup>* C\" by(rule widen_is_class_type_of)\n      have \"P \\<turnstile> C' has F:TF (fm) in D\" by(rule has_field_mono[OF has \"subclass\"])\n      with wt\\<^sub>1' show ?thesis using wt\\<^sub>2' sub void icto' by(blast intro:WTrtFAss)\n    qed }\n  ultimately show ?case using wt by blast\nnext\n  case (FAssRed2 e\\<^sub>2 s ta e\\<^sub>2' s' v F D T E)\n  have red: \"extTA,P,t \\<turnstile> \\<langle>e\\<^sub>2,s\\<rangle> -ta\\<rightarrow> \\<langle>e\\<^sub>2',s'\\<rangle>\"\n   and IH: \"\\<And>E T. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> e\\<^sub>2 : T; P,hp s \\<turnstile> t \\<surd>t\\<rbrakk>\n                 \\<Longrightarrow> \\<exists>U. P,E,hp s' \\<turnstile> e\\<^sub>2' : U \\<and> P \\<turnstile> U \\<le> T\"\n   and conf: \"E \\<turnstile> s \\<surd>\" and wt: \"P,E,hp s \\<turnstile> Val v\\<bullet>F{D}:=e\\<^sub>2 : T\" \n   and tconf: \"P,hp s \\<turnstile> t \\<surd>t\" by fact+\n  from wt have [simp]: \"T = Void\" by auto\n  from wt show ?case\n  proof (rule WTrt_elim_cases)\n    fix U C TF T\\<^sub>2 fm\n    assume wt\\<^sub>1: \"P,E,hp s \\<turnstile> Val v : U\"\n      and icto: \"class_type_of' U = \\<lfloor>C\\<rfloor>\"\n      and has: \"P \\<turnstile> C has F:TF (fm) in D\"\n      and wt\\<^sub>2: \"P,E,hp s \\<turnstile> e\\<^sub>2 : T\\<^sub>2\" and TsubTF: \"P \\<turnstile> T\\<^sub>2 \\<le> TF\"\n    have wt\\<^sub>1': \"P,E,hp s' \\<turnstile> Val v : U\"\n      by(rule WTrt_hext_mono[OF wt\\<^sub>1 red_hext_incr[OF red]])\n    obtain T\\<^sub>2' where wt\\<^sub>2': \"P,E,hp s' \\<turnstile> e\\<^sub>2' : T\\<^sub>2'\" and T'subT: \"P \\<turnstile> T\\<^sub>2' \\<le> T\\<^sub>2\"\n      using IH[OF conf wt\\<^sub>2 tconf] by blast\n    have \"P,E,hp s' \\<turnstile> Val v\\<bullet>F{D}:=e\\<^sub>2' : Void\"\n      by(rule WTrtFAss[OF wt\\<^sub>1' icto has wt\\<^sub>2' widen_trans[OF T'subT TsubTF]])\n    thus ?case by auto\n  next\n    fix T\\<^sub>2 assume null: \"P,E,hp s \\<turnstile> Val v : NT\" and wt\\<^sub>2: \"P,E,hp s \\<turnstile> e\\<^sub>2 : T\\<^sub>2\"\n    from null have \"v = Null\" by simp\n    moreover\n    obtain T\\<^sub>2' where \"P,E,hp s' \\<turnstile> e\\<^sub>2' : T\\<^sub>2' \\<and> P \\<turnstile> T\\<^sub>2' \\<le> T\\<^sub>2\"\n      using IH[OF conf wt\\<^sub>2 tconf] by blast\n    ultimately show ?thesis by(fastforce intro:WTrtFAssNT)\n  qed\nnext\n  case RedFAss thus ?case by(auto simp del:fun_upd_apply)\nnext\n  case RedFAssNull thus ?case unfolding sconf_def\n    by(fastforce simp add: xcpt_subcls_Throwable[OF _ wf])\nnext\n  case (CallObj e s ta e' s' M es T E)\n  have red: \"extTA,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>\"\n   and IH: \"\\<And>E T. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> e : T; P,hp s \\<turnstile> t \\<surd>t\\<rbrakk>\n                 \\<Longrightarrow> \\<exists>U. P,E,hp s' \\<turnstile> e' : U \\<and> P \\<turnstile> U \\<le> T\"\n   and conf: \"E \\<turnstile> s \\<surd>\" and wt: \"P,E,hp s \\<turnstile> e\\<bullet>M(es) : T\"\n   and tconf: \"P,hp s \\<turnstile> t \\<surd>t\" by fact+\n  -- \"We distinguish if @{term e} has type @{term NT} or a Class type\"\n  from wt show ?case\n  proof(rule WTrt_elim_cases)\n    fix T' C Ts meth D Us\n    assume wte: \"P,E,hp s \\<turnstile> e : T'\" and icto: \"class_type_of' T' = \\<lfloor>C\\<rfloor>\"\n      and method: \"P \\<turnstile> C sees M:Ts\\<rightarrow>T = meth in D\"\n      and wtes: \"P,E,hp s \\<turnstile> es [:] Us\" and subs: \"P \\<turnstile> Us [\\<le>] Ts\"\n    obtain U where wte': \"P,E,hp s' \\<turnstile> e' : U\" and UsubC: \"P \\<turnstile> U \\<le> T'\"\n      using IH[OF conf wte tconf] by blast\n    show ?thesis\n    proof(cases \"U = NT\")\n      case True\n      moreover have \"P,E,hp s' \\<turnstile> es [:] Us\"\n        by(rule WTrts_hext_mono[OF wtes red_hext_incr[OF red]])\n      ultimately show ?thesis using wte' by(blast intro!:WTrtCallNT)\n    next\n      case False\n      with icto UsubC obtain C'\n        where icto': \"class_type_of' U = \\<lfloor>C'\\<rfloor>\" and \"subclass\": \"P \\<turnstile> C' \\<preceq>\\<^sup>* C\"\n        by(rule widen_is_class_type_of)\n\n      obtain Ts' T' meth' D'\n        where method': \"P \\<turnstile> C' sees M:Ts'\\<rightarrow>T' = meth' in D'\"\n        and subs': \"P \\<turnstile> Ts [\\<le>] Ts'\" and sub': \"P \\<turnstile> T' \\<le> T\"\n        using Call_lemma[OF method \"subclass\" wf] by fast\n      have wtes': \"P,E,hp s' \\<turnstile> es [:] Us\"\n        by(rule WTrts_hext_mono[OF wtes red_hext_incr[OF red]])\n      show ?thesis using wtes' wte' icto' subs method' subs' sub' by(blast intro:widens_trans)\n    qed\n  next\n    fix Ts\n    assume \"P,E,hp s \\<turnstile> e:NT\"\n    hence \"P,E,hp s' \\<turnstile> e' : NT\" using IH[OF conf _ tconf] by fastforce\n    moreover\n    fix Ts assume wtes: \"P,E,hp s \\<turnstile> es [:] Ts\"\n    have \"P,E,hp s' \\<turnstile> es [:] Ts\"\n      by(rule WTrts_hext_mono[OF wtes red_hext_incr[OF red]])\n    ultimately show ?thesis by(blast intro!:WTrtCallNT)\n  qed\nnext\n  case (CallParams es s ta es' s' v M T E)\n  have reds: \"extTA,P,t \\<turnstile> \\<langle>es,s\\<rangle> [-ta\\<rightarrow>] \\<langle>es',s'\\<rangle>\"\n   and IH: \"\\<And>Ts E. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> es [:] Ts; P,hp s \\<turnstile> t \\<surd>t\\<rbrakk>\n           \\<Longrightarrow> \\<exists>Ts'. P,E,hp s' \\<turnstile> es' [:] Ts' \\<and> P \\<turnstile> Ts' [\\<le>] Ts\"\n   and conf: \"E \\<turnstile> s \\<surd>\" and wt: \"P,E,hp s \\<turnstile> Val v\\<bullet>M(es) : T\" \n   and tconf: \"P,hp s \\<turnstile> t \\<surd>t\" by fact+\n  from wt show ?case\n  proof (rule WTrt_elim_cases)\n    fix U C Ts meth D Us\n    assume wte: \"P,E,hp s \\<turnstile> Val v : U\" and icto: \"class_type_of' U = \\<lfloor>C\\<rfloor>\"\n      and \"P \\<turnstile> C sees M:Ts\\<rightarrow>T = meth in D\"\n      and wtes: \"P,E,hp s \\<turnstile> es [:] Us\" and \"P \\<turnstile> Us [\\<le>] Ts\"\n    moreover have \"P,E,hp s' \\<turnstile> Val v : U\"\n      by(rule WTrt_hext_mono[OF wte reds_hext_incr[OF reds]])\n    moreover obtain Us' where \"P,E,hp s' \\<turnstile> es' [:] Us'\" \"P \\<turnstile> Us' [\\<le>] Us\"\n      using IH[OF conf wtes tconf] by blast\n    ultimately show ?thesis by(fastforce intro:WTrtCall widens_trans)\n  next\n    fix Us\n    assume null: \"P,E,hp s \\<turnstile> Val v : NT\" and wtes: \"P,E,hp s \\<turnstile> es [:] Us\"\n    from null have \"v = Null\" by simp\n    moreover\n    obtain Us' where \"P,E,hp s' \\<turnstile> es' [:] Us' \\<and> P \\<turnstile> Us' [\\<le>] Us\"\n      using IH[OF conf wtes tconf] by blast\n    ultimately show ?thesis by(fastforce intro:WTrtCallNT)\n  qed\nnext\n  case (RedCall s a U M Ts T pns body D vs T' E)\n  have hp: \"typeof_addr (hp s) a = \\<lfloor>U\\<rfloor>\"\n    and method: \"P \\<turnstile> class_type_of U sees M: Ts\\<rightarrow>T = \\<lfloor>(pns,body)\\<rfloor> in D\"\n    and wt: \"P,E,hp s \\<turnstile> addr a\\<bullet>M(map Val vs) : T'\" by fact+\n  obtain Ts' where wtes: \"P,E,hp s \\<turnstile> map Val vs [:] Ts'\"\n    and subs: \"P \\<turnstile> Ts' [\\<le>] Ts\" and T'isT: \"T' = T\"\n    using wt method hp wf by(auto 4 3 dest: sees_method_fun)\n  from wtes subs have length_vs: \"length vs = length Ts\"\n    by(auto simp add: WTrts_conv_list_all2 dest!: list_all2_lengthD)\n  have UsubD: \"P \\<turnstile> ty_of_htype U \\<le> Class (class_type_of U)\"\n    by(cases U)(simp_all add: widen_array_object)\n  from sees_wf_mdecl[OF wf method] obtain T''\n    where wtabody: \"P,[this#pns [\\<mapsto>] Class D#Ts] \\<turnstile> body :: T''\"\n    and T''subT: \"P \\<turnstile> T'' \\<le> T\" and length_pns: \"length pns = length Ts\"\n    by(fastforce simp:wf_mdecl_def simp del:map_upds_twist)\n  from wtabody have \"P,empty(this#pns [\\<mapsto>] Class D#Ts),hp s \\<turnstile> body : T''\"\n    by(rule WT_implies_WTrt)\n  hence \"P,E(this#pns [\\<mapsto>] Class D#Ts),hp s \\<turnstile> body : T''\"\n    by(rule WTrt_env_mono) simp\n  hence \"P,E,hp s \\<turnstile> blocks (this#pns) (Class D#Ts) (Addr a#vs) body : T''\"\n    using wtes subs hp sees_method_decl_above[OF method] length_vs length_pns UsubD\n    by(auto simp add:wt_blocks rel_list_all2_Cons2 intro: widen_trans)\n  with T''subT T'isT show ?case by blast\nnext\n  case (RedCallExternal s a U M Ts T' D vs ta va h' ta' e' s')\n  from `P,t \\<turnstile> \\<langle>a\\<bullet>M(vs),hp s\\<rangle> -ta\\<rightarrow>ext \\<langle>va,h'\\<rangle>` have \"hp s \\<unlhd> h'\" by(rule red_external_hext)\n  with `P,E,hp s \\<turnstile> addr a\\<bullet>M(map Val vs) : T`\n  have \"P,E,h' \\<turnstile> addr a\\<bullet>M(map Val vs) : T\" by(rule WTrt_hext_mono)\n  moreover from `typeof_addr (hp s) a = \\<lfloor>U\\<rfloor>` `P \\<turnstile> class_type_of U sees M: Ts\\<rightarrow>T' = Native in D` `P,E,hp s \\<turnstile> addr a\\<bullet>M(map Val vs) : T`\n  have \"P,hp s \\<turnstile> a\\<bullet>M(vs) : T'\"\n    by(fastforce simp add: external_WT'_iff dest: sees_method_fun)\n  ultimately show ?case using RedCallExternal\n    by(auto 4 3 intro: red_external_conf_extRet[OF wf] intro!: wt_external_call simp add: sconf_def dest: sees_method_fun[where C=\"class_type_of U\"])\nnext\n  case RedCallNull thus ?case unfolding sconf_def\n    by(fastforce simp add: xcpt_subcls_Throwable[OF _ wf])\nnext\n  case (BlockRed e h x V vo ta e' h' x' T T' E)\n  note IH = `\\<And>T E. \\<lbrakk>E \\<turnstile> (h, x(V := vo)) \\<surd>; P,E,hp (h, x(V := vo)) \\<turnstile> e : T; P,hp (h, x(V := vo)) \\<turnstile> t \\<surd>t\\<rbrakk>\n             \\<Longrightarrow> \\<exists>T'. P,E,hp (h', x') \\<turnstile> e' : T' \\<and> P \\<turnstile> T' \\<le> T`[simplified]\n  from `P,E,hp (h, x) \\<turnstile> {V:T=vo; e} : T'` have \"P,E(V\\<mapsto>T),h \\<turnstile> e : T'\" by(cases vo, auto)\n  moreover from `E \\<turnstile> (h, x) \\<surd>` `P,E,hp (h, x) \\<turnstile> {V:T=vo; e} : T'`\n  have \"(E(V \\<mapsto> T)) \\<turnstile> (h, x(V := vo)) \\<surd>\"\n    by(cases vo)(simp add: lconf_def sconf_def,auto simp add: sconf_def conf_def intro: lconf_upd2)\n  ultimately obtain T'' where wt': \"P,E(V\\<mapsto>T),h' \\<turnstile> e' : T''\" \"P \\<turnstile> T'' \\<le> T'\" using `P,hp (h, x) \\<turnstile> t \\<surd>t`\n    by(auto dest: IH)\n  { fix v\n    assume vo: \"x' V = \\<lfloor>v\\<rfloor>\"\n    from `(E(V \\<mapsto> T)) \\<turnstile> (h, x(V := vo)) \\<surd>` `extTA,P,t \\<turnstile> \\<langle>e,(h, x(V := vo))\\<rangle> -ta\\<rightarrow> \\<langle>e',(h', x')\\<rangle>` `P,E(V\\<mapsto>T),h \\<turnstile> e : T'`\n    have \"P,h' \\<turnstile> x' (:\\<le>) (E(V \\<mapsto> T))\" by(auto simp add: sconf_def dest: red_preserves_lconf)\n    with vo have \"\\<exists>T'. typeof\\<^bsub>h'\\<^esub> v = \\<lfloor>T'\\<rfloor> \\<and> P \\<turnstile> T' \\<le> T\" by(fastforce simp add: sconf_def lconf_def conf_def)\n    then obtain T' where \"typeof\\<^bsub>h'\\<^esub> v = \\<lfloor>T'\\<rfloor>\" \"P \\<turnstile> T' \\<le> T\" by blast\n    hence ?case using wt' vo by(auto) }\n  moreover\n  { assume \"x' V = None\" with wt' have ?case by(auto) }\n  ultimately show ?case by blast\nnext \n  case RedBlock thus ?case by auto\nnext\n  case (SynchronizedRed1 o' s ta o'' s' e T E)\n  have red: \"extTA,P,t \\<turnstile> \\<langle>o',s\\<rangle> -ta\\<rightarrow> \\<langle>o'',s'\\<rangle>\" by fact\n  have IH: \"\\<And>T E. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> o' : T; P,hp s \\<turnstile> t \\<surd>t\\<rbrakk> \\<Longrightarrow> \\<exists>T'. P,E,hp s' \\<turnstile> o'' : T' \\<and> P \\<turnstile> T' \\<le> T\" by fact\n  have conf: \"E \\<turnstile> s \\<surd>\" by fact\n  have wt: \"P,E,hp s \\<turnstile> sync(o') e : T\" by fact+\n  thus ?case\n  proof(rule WTrt_elim_cases)\n    fix To\n    assume wto: \"P,E,hp s \\<turnstile> o' : To\"\n      and refT: \"is_refT To\" \n      and wte: \"P,E,hp s \\<turnstile> e : T\"\n    from IH[OF conf wto `P,hp s \\<turnstile> t \\<surd>t`] obtain To' where \"P,E,hp s' \\<turnstile> o'' : To'\" and sub: \"P \\<turnstile> To' \\<le> To\" by auto\n    moreover have \"P,E,hp s' \\<turnstile> e : T\"\n      by(rule WTrt_hext_mono[OF wte red_hext_incr[OF red]])\n    moreover have \"is_refT To'\" using refT sub by(auto intro: widen_refT)\n    ultimately show ?thesis by(auto)\n  qed\nnext\n  case SynchronizedNull thus ?case unfolding sconf_def\n    by(fastforce simp add: xcpt_subcls_Throwable[OF _ wf])\nnext\n  case LockSynchronized thus ?case by(auto)\nnext\n  case (SynchronizedRed2 e s ta e' s' a T E)\n  have red: \"extTA,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>\" by fact\n  have IH: \"\\<And>T E. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> e : T; P,hp s \\<turnstile> t \\<surd>t\\<rbrakk> \\<Longrightarrow> \\<exists>T'. P,E,hp s' \\<turnstile> e' : T' \\<and> P \\<turnstile> T' \\<le> T\" by fact\n  have conf: \"E \\<turnstile> s \\<surd>\" by fact\n  have wt: \"P,E,hp s \\<turnstile> insync(a) e : T\" by fact\n  thus ?case\n  proof(rule WTrt_elim_cases)\n    fix Ta\n    assume \"P,E,hp s \\<turnstile> e : T\"\n      and hpa: \"typeof_addr (hp s) a = \\<lfloor>Ta\\<rfloor>\"\n    from `P,E,hp s \\<turnstile> e : T` conf `P,hp s \\<turnstile> t \\<surd>t` obtain T'\n      where \"P,E,hp s' \\<turnstile> e' : T'\" \"P \\<turnstile> T' \\<le> T\" by(blast dest: IH)\n    moreover from red have hext: \"hp s \\<unlhd> hp s'\" by(auto dest: red_hext_incr)\n    with hpa have \"P,E,hp s' \\<turnstile> addr a : ty_of_htype Ta\"\n      by(auto intro: typeof_addr_hext_mono)\n    ultimately show ?thesis by auto\n  qed\nnext\n  case UnlockSynchronized thus ?case by(auto)\nnext\n  case SeqRed thus ?case\n    apply(auto)\n    apply(drule WTrt_hext_mono[OF _ red_hext_incr], assumption)\n    by auto\nnext\n  case (CondRed b s ta b' s' e1 e2 T E)\n  have red: \"extTA,P,t \\<turnstile> \\<langle>b,s\\<rangle> -ta\\<rightarrow> \\<langle>b',s'\\<rangle>\" by fact\n  have IH: \"\\<And>T E. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> b : T; P,hp s \\<turnstile> t \\<surd>t\\<rbrakk> \\<Longrightarrow> \\<exists>T'. P,E,hp s' \\<turnstile> b' : T' \\<and> P \\<turnstile> T' \\<le> T\" by fact\n  have conf: \"E \\<turnstile> s \\<surd>\" by fact\n  have wt: \"P,E,hp s \\<turnstile> if (b) e1 else e2 : T\" by fact\n  thus ?case\n  proof(rule WTrt_elim_cases)\n    fix T1 T2\n    assume wtb: \"P,E,hp s \\<turnstile> b : Boolean\"\n      and wte1: \"P,E,hp s \\<turnstile> e1 : T1\"\n      and wte2: \"P,E,hp s \\<turnstile> e2 : T2\"\n      and lub: \"P \\<turnstile> lub(T1, T2) = T\"\n    from IH[OF conf wtb `P,hp s \\<turnstile> t \\<surd>t`] have \"P,E,hp s' \\<turnstile> b' : Boolean\" by(auto)\n    moreover have \"P,E,hp s' \\<turnstile> e1 : T1\"\n      by(rule WTrt_hext_mono[OF wte1 red_hext_incr[OF red]])\n    moreover have \"P,E,hp s' \\<turnstile> e2 : T2\"\n      by(rule WTrt_hext_mono[OF wte2 red_hext_incr[OF red]])\n    ultimately show ?thesis using lub by auto\n  qed\nnext\n  case (ThrowRed e s ta e' s' T E)\n  have IH: \"\\<And>T E. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> e : T; P,hp s \\<turnstile> t \\<surd>t\\<rbrakk> \\<Longrightarrow> \\<exists>T'. P,E,hp s' \\<turnstile> e' : T' \\<and> P \\<turnstile> T' \\<le> T\" by fact\n  have conf: \"E \\<turnstile> s \\<surd>\" by fact\n  have wt: \"P,E,hp s \\<turnstile> throw e : T\" by fact\n  then obtain T'\n    where wte: \"P,E,hp s \\<turnstile> e : T'\" \n    and nobject: \"P \\<turnstile> T' \\<le> Class Throwable\" by auto\n  from IH[OF conf wte `P,hp s \\<turnstile> t \\<surd>t`] obtain T'' \n    where wte': \"P,E,hp s' \\<turnstile> e' : T''\"\n    and PT'T'': \"P \\<turnstile> T'' \\<le> T'\" by blast\n  from nobject PT'T'' have \"P \\<turnstile> T'' \\<le> Class Throwable\"\n    by(auto simp add: widen_Class)(erule notE, rule rtranclp_trans)\n  hence \"P,E,hp s' \\<turnstile> throw e' : T\" using wte' PT'T''\n    by -(erule WTrtThrow)\n  thus ?case by(auto)\nnext\n  case RedThrowNull thus ?case unfolding sconf_def\n    by(fastforce simp add: xcpt_subcls_Throwable[OF _ wf])\nnext\n  case (TryRed e s ta e' s' C V e2 T E)\n  have red: \"extTA,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>\" by fact\n  have IH: \"\\<And>T E. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> e : T; P,hp s \\<turnstile> t \\<surd>t\\<rbrakk> \\<Longrightarrow> \\<exists>T'. P,E,hp s' \\<turnstile> e' : T' \\<and> P \\<turnstile> T' \\<le> T\" by fact\n  have conf: \"E \\<turnstile> s \\<surd>\" by fact\n  have wt: \"P,E,hp s \\<turnstile> try e catch(C V) e2 : T\" by fact\n  thus ?case\n  proof(rule WTrt_elim_cases)\n    fix T1\n    assume wte: \"P,E,hp s \\<turnstile> e : T1\"\n      and wte2: \"P,E(V \\<mapsto> Class C),hp s \\<turnstile> e2 : T\"\n      and sub: \"P \\<turnstile> T1 \\<le> T\"\n    from IH[OF conf wte `P,hp s \\<turnstile> t \\<surd>t`] obtain T1' where \"P,E,hp s' \\<turnstile> e' : T1'\" and \"P \\<turnstile> T1' \\<le> T1\" by(auto)\n    moreover have \"P,E(V \\<mapsto> Class C),hp s' \\<turnstile> e2 : T\"\n      by(rule WTrt_hext_mono[OF wte2 red_hext_incr[OF red]])\n    ultimately show ?thesis using sub by(auto elim: widen_trans)\n  qed\nnext\n  case RedTryFail thus ?case unfolding sconf_def\n    by(fastforce simp add: xcpt_subcls_Throwable[OF _ wf])\nnext\n  case RedSeq thus ?case by auto\nnext\n  case RedCondT thus ?case by(auto dest: is_lub_upper)\nnext\n  case RedCondF thus ?case by(auto dest: is_lub_upper)\nnext\n  case RedWhile thus ?case by(fastforce) \nnext\n  case RedTry thus ?case by auto\nnext\n  case RedTryCatch thus ?case by(fastforce)\nnext\n  case (ListRed1 e s ta e' s' es Ts E)\n  note IH = `\\<And>T E. \\<lbrakk>E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> e : T; P,hp s \\<turnstile> t \\<surd>t\\<rbrakk> \\<Longrightarrow> \\<exists>T'. P,E,hp s' \\<turnstile> e' : T' \\<and> P \\<turnstile> T' \\<le> T`\n  from `P,E,hp s \\<turnstile> e # es [:] Ts` obtain T Ts' where \"Ts = T # Ts'\" \"P,E,hp s \\<turnstile> e : T\" \"P,E,hp s \\<turnstile> es [:] Ts'\" by auto\n  with IH[of E T] `E \\<turnstile> s \\<surd>` WTrts_hext_mono[OF `P,E,hp s \\<turnstile> es [:] Ts'` red_hext_incr[OF `extTA,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>`]]\n  show ?case using `P,hp s \\<turnstile> t \\<surd>t` by(auto simp add: list_all2_Cons2 intro: widens_refl)\nnext\n  case ListRed2 thus ?case\n    by(fastforce dest: hext_typeof_mono[OF reds_hext_incr])\nqed(fastforce)+\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/JinjaThreads/J/TypeSafe.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5506073507867328, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.26240825911103616}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory GraphLang\n\nimports\n  \"CLib.TypHeapLib\"\n  \"Lib.SplitRule\"\n  \"CommonOps\"\n\nbegin\n\ntext \\<open>Note that machine states here are assumed to be countable and\nare thus represented by naturals.\\<close>\n\ndatatype variable =\n    VarNone\n  | VarWord8 word8\n  | VarWord16 word16\n  | VarWord32 word32\n  | VarWord64 word64\n  | VarMem \"machine_word \\<Rightarrow> word8\"\n  | VarDom \"machine_word set\"\n  | VarGhostState \"ghost_assertions\"\n  | VarHTD \"heap_typ_desc\"\n  | VarMS \"unit \\<times> nat\"\n  | VarBool bool\n\ntext \\<open>States are a mapping from names to the variable type, which is\na union of the available names.\\<close>\n\ndatatype state = State \"string \\<Rightarrow> variable\"\n\ntext \\<open>Accessors for grabbing variables by name and expected type.\\<close>\n\ndefinition\n  \"var_acc nm st = (case st of State f \\<Rightarrow> f nm)\"\n\ndefinition\n  \"var_word8 nm st = (case var_acc nm st of\n    VarWord8 w \\<Rightarrow> w | _ \\<Rightarrow> 0)\"\n\ndefinition\n  \"var_word16 nm st = (case var_acc nm st of\n    VarWord16 w \\<Rightarrow> w | _ \\<Rightarrow> 0)\"\n\ndefinition\n  \"var_word32 nm st = (case var_acc nm st of\n    VarWord32 w \\<Rightarrow> w | _ \\<Rightarrow> 0)\"\n\ndefinition\n  \"var_word64 nm st = (case var_acc nm st of\n    VarWord64 w \\<Rightarrow> w | _ \\<Rightarrow> 0)\"\n\ndefinition\n  \"var_ghoststate nm st = (case var_acc nm st of\n    VarGhostState arr \\<Rightarrow> arr | _ \\<Rightarrow> (\\<lambda>_. 0))\"\n\ndefinition\n  \"var_mem nm st = (case var_acc nm st of\n    VarMem m \\<Rightarrow> m | _ \\<Rightarrow> \\<lambda>_. 0)\"\n\ndefinition\n  \"var_dom nm st = (case var_acc nm st of\n    VarDom d \\<Rightarrow> d | _ \\<Rightarrow> {})\"\n\ndefinition\n  \"var_htd nm st = (case var_acc nm st of\n    VarHTD htd \\<Rightarrow> htd | _ \\<Rightarrow> empty_htd)\"\n\ndefinition\n  \"var_ms nm st = (case var_acc nm st of\n    VarMS ms \\<Rightarrow> ms | _ \\<Rightarrow> ((), 0))\"\n\ndefinition\n  \"var_bool nm st = (case var_acc nm st of\n    VarBool bool \\<Rightarrow> bool | _ \\<Rightarrow> False)\"\n\ntext \\<open>The variable updator.\\<close>\n\ndefinition\n  \"var_upd nm v st = (case st of State f \\<Rightarrow> State (f (nm := v)))\"\n\ndefinition\n  \"default_state = State (\\<lambda>_. VarNone)\"\n\ntext \\<open>The type of nodes.\\<close>\n\ndatatype next_node =\n    NextNode nat | Ret | Err\n\ndatatype node =\n    Basic next_node \"(string \\<times> (state \\<Rightarrow> variable)) list\"\n  | Cond next_node next_node \"state \\<Rightarrow> bool\"\n  | Call next_node string \"(state \\<Rightarrow> variable) list\" \"string list\"\n\ndefinition Skip where\n  \"Skip nn = Cond nn nn (\\<lambda>x. True)\"\n\ntext \\<open>The type for a total graph function, including list of inputs,\n  list of outputs, graph, and entry point.\\<close>\n\ndatatype graph_function\n  = GraphFunction \"string list\" \"string list\" \"nat \\<Rightarrow> node option\" nat\n\nprimrec entry_point where\n  \"entry_point (GraphFunction inputs outputs graph ep) = ep\"\n\nprimrec function_graph where\n  \"function_graph (GraphFunction inputs outputs graph ep) = graph\"\n\nprimrec function_inputs where\n  \"function_inputs (GraphFunction inputs outputs graph ep) = inputs\"\n\nprimrec function_outputs where\n  \"function_outputs (GraphFunction inputs outputs graph ep) = outputs\"\n\ntext \\<open>The definition of execution, including a stack to allow function calls.\\<close>\n\ndefinition\n  save_vals :: \"string list \\<Rightarrow> variable list \\<Rightarrow> state \\<Rightarrow> state\"\nwhere\n \"save_vals vars vals st = fold (\\<lambda>(var, val). var_upd var val) (zip vars vals) st\"\n\ndefinition\n  init_vars :: \"string list \\<Rightarrow> (state \\<Rightarrow> variable) list \\<Rightarrow> state \\<Rightarrow> state\"\nwhere\n  \"init_vars vars accs st = save_vals vars (map (\\<lambda>i. i st) accs) default_state\"\n\ndefinition\n  acc_vars :: \"string list \\<Rightarrow> state \\<Rightarrow> variable list\"\nwhere\n  \"acc_vars vars st = map (\\<lambda>v. var_acc v st) vars\"\n\ndefinition\n  return_vars :: \"string list \\<Rightarrow> string list \\<Rightarrow> state \\<Rightarrow> state \\<Rightarrow> state\"\nwhere\n  \"return_vars inner outer inner_st = save_vals outer (acc_vars inner inner_st)\"\n\ndefinition\n  upd_vars :: \"(string \\<times> (state \\<Rightarrow> variable)) list \\<Rightarrow> state \\<Rightarrow> state\"\nwhere\n  \"upd_vars upds st = save_vals (map fst upds) (map (\\<lambda>(nm, vf). vf st) upds) st\"\n\ntype_synonym stack = \"(next_node \\<times> state \\<times> string) list\"\n\nprimrec\n  upd_stack :: \"next_node \\<Rightarrow> (state \\<Rightarrow> state) \\<Rightarrow> stack \\<Rightarrow> stack\"\nwhere\n    \"upd_stack nn stf (x # xs) = (nn, stf (fst (snd x)), snd (snd x)) # xs\"\n  | \"upd_stack nn stf [] = []\"\n\nprimrec\n  exec_node :: \"(string \\<Rightarrow> graph_function option)\n        \\<Rightarrow> state \\<Rightarrow> node \\<Rightarrow> stack \\<Rightarrow> stack set\"\nwhere\n    \"exec_node Gamma st (Basic cont upds) stack\n        = {upd_stack cont (K (upd_vars upds st)) stack}\"\n  | \"exec_node Gamma st (Cond left right cond) stack\n        = {upd_stack (if cond st then left else right) id stack}\"\n  | \"exec_node Gamma st (Call cont fname inputs outputs) stack\n        = (case Gamma fname of None \\<Rightarrow> {upd_stack Err id stack}\n            | Some (GraphFunction inps outps graph ep)\n                \\<Rightarrow> {(NextNode ep, init_vars inps inputs st, fname)\n                        # stack})\"\n\nprimrec\n  exec_node_return :: \"(string \\<Rightarrow> graph_function option)\n        \\<Rightarrow> state \\<Rightarrow> node \\<Rightarrow> stack \\<Rightarrow> stack set\"\nwhere\n    \"exec_node_return _ _ (Basic _ _) stack = {}\"\n  | \"exec_node_return _ _ (Cond _ _ _) stack = {}\"\n  | \"exec_node_return Gamma st (Call cont fname inputs outputs) stack\n        = (case Gamma fname of None \\<Rightarrow> {}\n            | Some (GraphFunction inps outps graph ep)\n                \\<Rightarrow> {upd_stack cont (return_vars outps outputs st) stack})\"\n\ntext \\<open>The single-step relation on graph states.\\<close>\n\ndefinition\n  exec_graph_step :: \"(string \\<Rightarrow> graph_function option)\n        \\<Rightarrow> (stack \\<times> stack) set\"\nwhere\n    \"exec_graph_step Gamma = {(stack, stack'). case stack of\n            (NextNode nn, st, fname) # _ \\<Rightarrow>\n                (case Gamma fname of None \\<Rightarrow> False\n                    | Some (GraphFunction _ _ graph _) \\<Rightarrow>\n                        (case graph nn of None \\<Rightarrow> stack' = upd_stack Err id stack\n                            | Some node \\<Rightarrow> stack' \\<in> exec_node Gamma st node stack))\n          | (Ret, st, _) # (NextNode nn, _, fname) # _ \\<Rightarrow>\n                (case Gamma fname of None \\<Rightarrow> False\n                    | Some (GraphFunction _ _ graph _) \\<Rightarrow>\n                        (case graph nn of None \\<Rightarrow> stack' = upd_stack Err id (tl stack)\n                            | Some node \\<Rightarrow> stack' \\<in> exec_node_return Gamma st node (tl stack)))\n          | [] \\<Rightarrow> False\n          | [_] \\<Rightarrow> False \\<comment> \\<open>note NextNode case is handled\\<close>\n          | _ \\<Rightarrow> stack' = upd_stack Err id (tl stack)\n      }\"\n\ntext \\<open>Multi-step relations.\\<close>\n\ndefinition exec_graph\nwhere \"exec_graph Gamma = rtrancl (exec_graph_step Gamma)\"\n\ndefinition exec_graph_n\nwhere \"exec_graph_n Gamma n = exec_graph_step Gamma ^^ n\"\n\nlemma relpow_Suc_simp2:\n  \"R ^^ Suc n = R O R ^^ n\"\n  apply safe\n   apply (erule relpow_Suc_E2, blast)\n  apply (blast intro: relpow_Suc_I2)\n  done\n\nlemma exec_graph_n_take_step:\n  \"\\<lbrakk> (stack, stack') \\<in> exec_graph_n GGamma n;\n    \\<lbrakk> n = 0; stack' = stack \\<rbrakk> \\<Longrightarrow> P;\n    \\<And>stack''. \\<lbrakk> n > 0; (stack, stack'') \\<in> exec_graph_step GGamma;\n            (stack'', stack') \\<in> exec_graph_n GGamma (n - 1) \\<rbrakk>\n        \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P\"\n  apply (cases n, simp_all only: exec_graph_n_def relpow_Suc_simp2)\n   apply simp\n  apply clarsimp\n  done\n\nlemma exec_graph_take_step:\n  \"\\<lbrakk> ((NextNode m, gst, fname) # stack, stack') \\<in> exec_graph_n GGamma n;\n            GGamma fname = Some gf; function_graph gf m = Some node \\<rbrakk>\n    \\<Longrightarrow> (n = 0 \\<and> stack' = (NextNode m, gst, fname) # stack)\n    \\<or> (\\<exists>stack''. n \\<ge> 1\n            \\<and> stack'' \\<in> exec_node GGamma gst node\n                    ((NextNode m, gst, fname) # stack)\n            \\<and> (stack'', stack') \\<in> exec_graph_n GGamma (n - 1))\"\n  apply (erule exec_graph_n_take_step)\n   apply simp\n  apply (clarsimp simp: exec_graph_step_def split: graph_function.split_asm)\n  apply blast\n  done\n\ndefinition\n  continuing :: \"stack \\<Rightarrow> bool\"\nwhere\n  \"continuing st = (case st of [] \\<Rightarrow> False\n    | [(NextNode _, _, _)] \\<Rightarrow> True | [_] \\<Rightarrow> False | _ \\<Rightarrow> True)\"\n\nlemma continuing_simps[simp]:\n  \"\\<not> continuing []\"\n  \"continuing [(unn, st, g)] = (unn \\<noteq> Ret \\<and> unn \\<noteq> Err)\"\n  \"continuing ((Ret, st, g) # stk) = (stk \\<noteq> [])\"\n  \"continuing (stf # stf' # stk)\"\n  \"continuing ((NextNode nn, st, g) # stk)\"\n  \"continuing ((Err, st, g) # stk) = (stk \\<noteq> [])\"\n  by (simp_all add: continuing_def split: next_node.split list.split)\n\nlemma consume_Not_eq:\n  \"(\\<not> P) = Q \\<Longrightarrow> P = (\\<not> Q)\"\n  by clarsimp\n\nlemma exec_node_case_helper:\n  \"(stk' \\<in> exec_node Gamma st node stk)\n    = (case node of Basic _ _ \\<Rightarrow> stk' \\<in> id (exec_node Gamma) st node stk\n        | _ \\<Rightarrow> stk' \\<in> id (exec_node Gamma) st node stk)\"\n  \"(stk' \\<in> exec_node_return Gamma st node stk)\n    = (case node of Basic _ _ \\<Rightarrow> stk' \\<in> id (exec_node_return Gamma) st node stk\n        | _ \\<Rightarrow> stk' \\<in> id (exec_node_return Gamma) st node stk)\"\n  by (simp_all split: node.split)\n\nlemmas splits_raw = prod.split list.split option.split\n    next_node.split graph_function.split node.split\nlemmas splits_cooked = splits_raw[where P=Not, THEN consume_Not_eq]\n    option.split[where P=\"\\<lambda>S. x \\<notin> S\", THEN consume_Not_eq]\n    graph_function.split[where P=\"\\<lambda>S. x \\<notin> S\", THEN consume_Not_eq] for x\n\nlemmas all_exec_graph_step_cases = exec_graph_step_def[THEN eqset_imp_iff,\n    simplified, unfolded exec_node_case_helper splits_cooked, simplified,\n    unfolded splits_cooked, simplified]\n\nlemma exec_node_stack_extend:\n  \"continuing stack \\<Longrightarrow>\n    (stack' \\<in> exec_node Gamma st node (stack @ xs))\n        = (\\<exists>stack''. stack' = stack'' @ xs\n                \\<and> stack'' \\<in> exec_node Gamma st node stack)\"\n  apply (cases node, simp_all)\n  apply (simp_all add: continuing_def\n                split: list.split_asm prod.split_asm next_node.split_asm)\n  apply (auto split: option.split graph_function.split)\n  done\n\nlemma exec_node_return_stack_extend:\n  \"continuing stack \\<Longrightarrow>\n    (stack' \\<in> exec_node_return Gamma st node (stack @ xs))\n        = (\\<exists>stack''. stack' = stack'' @ xs\n                \\<and> stack'' \\<in> exec_node_return Gamma st node stack)\"\n  apply (cases node, simp_all)\n  apply (simp_all add: continuing_def\n                split: list.split_asm prod.split_asm next_node.split_asm)\n  apply (auto split: option.split graph_function.split)\n  done\n\nlemma exec_graph_step_stack_extend:\n  \"continuing stack \\<Longrightarrow>\n    ((stack @ xs, stack') \\<in> exec_graph_step Gamma)\n    = (\\<exists>stack''. stack' = stack'' @ xs\n        \\<and> (stack, stack'') \\<in> exec_graph_step Gamma)\"\n  using exec_node_stack_extend[where stack'=stack' and stack=stack\n            and Gamma=Gamma and xs=xs]\n        exec_node_return_stack_extend[where stack'=stack' and stack=\"tl stack\"\n            and Gamma=Gamma and xs=xs]\n  apply (simp add: exec_graph_step_def)\n  apply (cases stack, simp_all)\n  apply clarsimp\n  apply (case_tac a, simp_all)\n    apply (clarsimp split: option.split graph_function.split)\n   apply (clarsimp simp: neq_Nil_conv split: list.split)\n   apply (clarsimp split: next_node.split option.split graph_function.split)\n  apply (clarsimp simp: neq_Nil_conv split: list.split)\n  done\n\nlemma exec_graph_n_stack_extend:\n  \"continuing stack \\<Longrightarrow>\n    ((stack @ xs, stack') \\<in> exec_graph_n Gamma n)\n    = (\\<exists>stack'' n'. (stack, stack'') \\<in> (exec_graph_step Gamma\n                \\<inter> {(st, _). continuing st}) ^^ n'\n        \\<and> ((n' < n \\<and> \\<not> continuing stack''\n                \\<and> (stack'' @ xs, stack') \\<in> exec_graph_n Gamma (n - n'))\n            \\<or> (stack' = stack'' @ xs \\<and> n' = n)))\"\n  unfolding exec_graph_n_def\nproof (induct n arbitrary: stack)\n  case 0\n  show ?case\n    by auto[1]\nnext\n  case (Suc n stack)\n  show ?case\n    apply (simp only: relpow_Suc_simp2)\n    apply (rule iffI)\n     apply (clarsimp simp: exec_graph_step_stack_extend Suc.prems)\n     apply (case_tac \"continuing stack''\")\n      apply (frule Suc.hyps, clarsimp)\n      apply (rule_tac x=\"stack''a\" in exI, rule_tac x=\"Suc n'\" in exI)\n      apply (simp only: relpow_Suc_simp2, clarsimp)\n      apply (blast intro: Suc.prems)\n     apply (rule_tac x=\"stack''\" in exI, rule_tac x=1 in exI)\n     apply (auto simp: Suc.prems)[1]\n    apply (clarsimp)\n    apply (case_tac n', simp_all only: minus_nat.diff_0 relpow_Suc_simp2)\n     apply auto[1]\n    apply clarsimp\n    apply (rule_tac b=\"y @ xs\" in relcompI)\n     apply (simp add: exec_graph_step_stack_extend Suc.prems)\n    apply (case_tac \"nat = 0\")\n     apply auto[1]\n    apply (subst Suc.hyps)\n     apply (case_tac nat, simp_all only: relpow_Suc_simp2, auto)[1]\n    apply auto[1]\n    done\nqed\n\ndefinition\n  \"init_state fname gfun xs =\n    (NextNode (entry_point gfun), save_vals (function_inputs gfun) xs default_state, fname)\"\n\nlemma exec_graph_step_nonempty:\n  \"\\<lbrakk> (stack, stack') \\<in> exec_graph_step Gamma ^^ n; stack \\<noteq> [] \\<rbrakk>\n    \\<Longrightarrow> stack' \\<noteq> []\"\n  by (cases n, auto simp: all_exec_graph_step_cases\n                   split: graph_function.split_asm)\n\nlemma relpow_mono:\n  \"\\<lbrakk> R \\<subseteq> (S :: ('a \\<times> 'a) set) \\<rbrakk> \\<Longrightarrow> R ^^ n \\<subseteq> S ^^ n\"\n  by (induct n, auto)\n\nlemma drop_eq_Cons:\n  \"(drop n xs = x # ys) = (\\<exists>zs. length zs = n \\<and> xs = zs @ x # ys)\"\n  apply (induct n arbitrary: xs)\n   apply simp\n  apply (case_tac xs, auto simp add: length_Suc_conv)\n  done\n\nlemma exec_graph_step_n_Err:\n  \"(((Err, st, graph) # stack, stack') \\<in> exec_graph_n Gamma n)\n    \\<Longrightarrow> stack' = upd_stack Err id (drop n ((Err, st, graph) # stack))\n        \\<and> drop n ((Err, st, graph) # stack) \\<noteq> []\"\nproof (induct n arbitrary: stack')\n  case 0\n  show ?case using 0\n    by (auto simp add: exec_graph_n_def)\nnext\n  case (Suc n)\n  show ?case using Suc.prems\n    apply (clarsimp simp: exec_graph_n_def relcomp_unfold linorder_not_le)\n    apply (drule exec_graph_step_def[THEN eqset_imp_iff, THEN iffD1])\n    apply (case_tac y, simp_all)\n    apply (drule Suc.hyps[rotated, unfolded exec_graph_n_def])\n    apply (simp only: neq_Nil_conv)\n    apply (clarsimp simp: linorder_not_le drop_eq_Cons)\n    apply (clarsimp split: list.split_asm)\n    apply (case_tac zs, simp_all)\n    done\nqed\n\ntext \\<open>Possibly infinite traces.\\<close>\n\ndefinition nat_trace_rel\n  where \"nat_trace_rel cont r = {tr. (\\<forall>n. (tr n = None \\<longrightarrow> tr (Suc n) = None)\n    \\<and> (tr (Suc n) \\<noteq> None \\<longrightarrow> (the (tr n), the (tr (Suc n))) \\<in> r)\n    \\<and> (tr n \\<noteq> None \\<and> cont (the (tr n)) \\<longrightarrow> tr (Suc n) \\<noteq> None))}\"\n\ntype_synonym trace = \"(nat \\<Rightarrow> stack option)\"\n\ndefinition\n  trace_end :: \"(nat \\<Rightarrow> 'a option) \\<Rightarrow> 'a option\"\nwhere\n  \"trace_end tr = (if \\<exists>n. tr n = None then tr (Max (dom tr)) else None)\"\n\nlemma nat_trace_rel_Some_range:\n  \"tr \\<in> nat_trace_rel cont r \\<Longrightarrow> tr n = Some v\n    \\<Longrightarrow> \\<forall>i \\<le> n. \\<exists>v'. tr i = Some v'\"\n  apply (induct n arbitrary: v, simp_all)\n  apply (simp add: nat_trace_rel_def le_Suc_eq)\n  apply (drule_tac x=n in spec, clarsimp)\n  done\n\nlemma trace_None_dom_subset:\n  \"tr n = None \\<Longrightarrow> tr \\<in> nat_trace_rel cont R\n    \\<Longrightarrow> dom tr \\<subseteq> {..< n}\"\n  apply clarsimp\n  apply (drule_tac n=x in nat_trace_rel_Some_range, simp+)\n  apply (drule_tac x=\"n\" in spec)\n  apply simp\n  done\n\nlemma nat_trace_Max_dom_None:\n  \"tr \\<in> nat_trace_rel cont R \\<Longrightarrow> tr n \\<noteq> None \\<Longrightarrow> (tr (Max (dom tr)) \\<noteq> None)\"\n  apply (rule notI)\n  apply (frule(1) trace_None_dom_subset)\n  apply (cases \"dom tr = {}\")\n   apply clarsimp\n  apply (drule Max_in[rotated])\n   apply (simp add: finite_subset)\n  apply clarsimp\n  done\n\nlemma trace_end_NoneD:\n  \"trace_end tr = None \\<Longrightarrow> tr \\<in> nat_trace_rel cont r\n    \\<Longrightarrow> tr = (\\<lambda>_. None) \\<or> (\\<exists>f. tr = Some o f)\"\n  apply (subst disj_commute, rule disjCI)\n  apply (clarsimp simp: fun_eq_iff)\n  apply (simp add: trace_end_def split: if_split_asm)\n   apply (metis nat_trace_Max_dom_None not_None_eq)\n  apply (rule_tac x=\"the o tr\" in exI, simp)\n  done\n\nlemma trace_end_SomeD:\n  \"trace_end tr = Some v \\<Longrightarrow> tr \\<in> nat_trace_rel cont r\n    \\<Longrightarrow> \\<exists>n. tr n = Some v \\<and> tr (Suc n) = None \\<and> \\<not> cont v\"\n  apply (clarsimp simp: trace_end_def split: if_split_asm)\n  apply (rule exI, rule conjI, assumption)\n  apply (case_tac \"tr (Suc (Max (dom tr)))\")\n   apply (simp add: nat_trace_rel_def)\n   apply (metis option.sel option.simps(3))\n  apply (cut_tac x=\"Suc y\" for y in Max_ge[OF finite_subset domI])\n     apply (erule(1) trace_None_dom_subset[rotated])\n    apply simp+\n  done\n\ndefinition\n  exec_trace :: \"(string \\<Rightarrow> graph_function option) \\<Rightarrow> string \\<Rightarrow> trace set\"\nwhere\n  \"exec_trace Gamma fname\n    = {trace. \\<exists>gf. Gamma fname = Some gf\n        \\<and> (\\<exists>st. trace 0 = Some [(NextNode (entry_point gf), st, fname)])\n        \\<and> trace \\<in> nat_trace_rel continuing (exec_graph_step Gamma)}\"\n\nlemma relpow_nat_trace:\n  \"((s, s') \\<in> r ^^ n) = (\\<exists>tr \\<in> nat_trace_rel (\\<lambda>x. False) r. tr 0 = Some s\n    \\<and> tr n = Some s' \\<and> tr (Suc n) = None)\"\n  apply (simp add: relpow_fun_conv, safe)\n   apply (rule_tac x=\"\\<lambda>x. if x < Suc n then Some (f x) else None\" in bexI)\n    apply simp\n   apply (simp add: nat_trace_rel_def)\n  apply (rule_tac x=\"the o tr\" in exI)\n  apply (frule(1) nat_trace_rel_Some_range[where n=n])\n  apply (clarsimp simp: nat_trace_rel_def)\n  done\n\ntext \\<open>Parsing code for the graph language.\\<close>\n\nML \\<open>\n\nstructure ParseGraph = struct\n\nexception PARSEGRAPH of string list\n\nval debug = ref false\n\nfun trace s = if (! debug) then writeln s else ()\n\nfun parse_int str = if String.isPrefix \"-\" str\n  then ~ (parse_int (unprefix \"-\" str))\n  else case read_int (raw_explode str)\n  of (n, []) => n\n    | _ => raise PARSEGRAPH [\"read_int:\", str]\n\nval s = @{term \"s :: state\"}\n\nfun parse_n p (n :: ss) = let\n    val n = parse_int n\n  in funpow_yield n p ss end\n  | parse_n _ [] = raise PARSEGRAPH [\"parse_n: empty\"]\n\nfun mk_binT sz = Word_Lib.mk_wordT sz |> dest_Type |> snd |> hd\n\nval ptr_size_str =\n    case @{typ machine_word} of\n      @{typ word32} => \"32\"\n    | @{typ word64} => \"64\"\n\nfun parse_typ (\"Word\" :: n :: ss) = let\n    val n = parse_int n\n  in (Word_Lib.mk_wordT n, ss) end\n  | parse_typ (\"Bool\" :: ss) = (@{typ bool}, ss)\n  | parse_typ (\"Mem\" :: ss) = (@{typ \"machine_word \\<Rightarrow> word8\"}, ss)\n  | parse_typ (\"Dom\" :: ss) = (@{typ \"machine_word set\"}, ss)\n  | parse_typ (\"HTD\" :: ss) = (@{typ heap_typ_desc}, ss)\n  | parse_typ (\"PMS\" :: ss) = (@{typ nat}, ss)\n  | parse_typ (\"UNIT\" :: ss) = (@{typ unit}, ss)\n  | parse_typ (\"Array\" :: ss) = let\n    val (el_typ, ss) = parse_typ ss\n    val (n, ss) = case ss of (n :: ss) => (parse_int n, ss)\n        | [] => raise PARSEGRAPH [\"parse_typ: array index\"]\n  in (Type (@{type_name array}, [el_typ, mk_binT n]), ss) end\n  | parse_typ (bad as (\"WordArray\" :: \"50\" :: element_size :: ss)) =\n      (if element_size = ptr_size_str\n      then (@{typ \"ghost_assertions\"}, ss)\n      else raise PARSEGRAPH (\"parse_typ: bad ghost assertion codomain\" :: bad))\n  | parse_typ (\"Struct\" :: nm :: ss) = (Type (nm, []), ss)\n  | parse_typ (\"Ptr\" :: ss) = let\n    val (obj_typ, ss) = parse_typ ss\n  in (Type (@{type_name ptr}, [obj_typ]), ss) end\n  | parse_typ ss = raise PARSEGRAPH (\"parse_typ: malformed\" :: ss)\n\nfun parse_lval (\"VarUpdate\" :: nm :: ss) = let\n    val (_, ss) = parse_typ ss (* FIXME: check typ? *)\n  in (nm, ss) end\n  | parse_lval ss = raise PARSEGRAPH (\"parse_lval\" :: ss)\n\nfun parse_var ss = parse_lval (\"VarUpdate\" :: ss)\n\nval opers = Symtab.make [\n      (\"Plus\", @{const_name \"plus\"}),\n      (\"Minus\", @{const_name \"minus\"}),\n      (\"Times\", @{const_name \"times\"}),\n      (\"Modulus\", @{const_name \"modulo_class.modulo\"}),\n      (\"DividedBy\", @{const_name \"divide_class.divide\"}),\n      (\"BWAnd\", @{const_name \"bitAND\"}),\n      (\"BWOr\", @{const_name \"bitOR\"}),\n      (\"BWXOR\", @{const_name \"bitXOR\"}),\n      (\"And\", @{const_name \"conj\"}),\n      (\"Or\", @{const_name \"disj\"}),\n      (\"Implies\", @{const_name \"implies\"}),\n      (\"Equals\", @{const_name \"HOL.eq\"}),\n      (\"Less\", @{const_name \"less\"}),\n      (\"LessEquals\", @{const_name \"less_eq\"}),\n      (\"SignedLess\", @{const_name \"word_sless\"}),\n      (\"SignedLessEquals\", @{const_name \"word_sle\"}),\n      (\"Not\", @{const_name \"Not\"}),\n      (\"BWNot\", @{const_name \"bitNOT\"}),\n      (\"WordCast\", @{const_name \"ucast\"}),\n      (\"WordCastSigned\", @{const_name \"scast\"}),\n      (\"WordArrayAccess\", @{const_name \"fun_app\"}),\n      (\"WordArrayUpdate\", @{const_name \"fun_upd\"}),\n      (\"CountLeadingZeroes\", @{const_name \"bv_clz\"}),\n      (\"CountTrailingZeroes\", @{const_name \"bv_ctz\"}),\n      (\"True\", @{const_name \"True\"}),\n      (\"False\", @{const_name \"False\"}),\n      (\"IfThenElse\", @{const_name \"If\"}),\n      (\"MemAcc\", @{const_name \"mem_acc\"}),\n      (\"MemUpdate\", @{const_name \"mem_upd\"}),\n      (\"MemDom\", @{const_name \"Set.member\"}),\n      (\"ShiftLeft\", @{const_name \"bvshl\"}),\n      (\"ShiftRight\", @{const_name \"bvlshr\"}),\n      (\"SignedShiftRight\", @{const_name \"bvashr\"}),\n      (\"PValid\", @{const_name pvalid}),\n      (\"PArrayValid\", @{const_name parray_valid}),\n      (\"PAlignValid\", @{const_name palign_valid}),\n      (\"PGlobalValid\", @{const_name pglobal_valid}),\n      (\"PWeakValid\", @{const_name pweak_valid}),\n      (\"HTDUpdate\", @{const_name all_htd_updates})\n  ]\n\nfun mk_acc nm typ st = (case typ of\n        @{typ word8} => @{term var_word8}\n      | @{typ word16} => @{term var_word16}\n      | @{typ word32} => @{term var_word32}\n      | @{typ word64} => @{term var_word64}\n      | @{typ \"machine_word \\<Rightarrow> word8\"} => @{term var_mem}\n      | @{typ \"machine_word set\"} => @{term var_dom}\n      | @{typ \"ghost_assertions\"} => @{term var_ghoststate}\n      | @{typ \"heap_typ_desc\"} => @{term var_htd}\n      | @{typ \"nat\"} => @{term var_ms}\n      | @{typ bool} => @{term var_bool}\n      | Type (@{type_name ptr}, [_]) =>\n          (case @{typ \"machine_word\"} of\n            @{typ word32} => @{term var_word32}\n          | @{typ word64} => @{term var_word64})\n      | _ => raise PARSEGRAPH [\"mk_acc\", nm, fst (dest_Type typ)])\n    $ HOLogic.mk_string nm $ st\n\nfun parse_val (\"Num\" :: ss) = let\n    val (n, ss) = case ss of n :: ss => (n, ss)\n        | [] => raise PARSEGRAPH [\"parse_val: parsing num, no numeral\"]\n    val (typ, ss) = parse_typ ss\n    val n = parse_int n\n  in (HOLogic.mk_number typ n, ss) end\n  | parse_val (\"Op\" :: nm :: ss) = let\n    val const = case Symtab.lookup opers nm\n      of SOME c => c\n      | NONE => raise PARSEGRAPH [\"parse_val: unexpected op\", nm]\n    val (typ, ss) = parse_typ ss\n    val (args, ss) = parse_n parse_val ss\n    val oper = Const (const, map fastype_of args ---> typ)\n  in trace (\"parsed oper \" ^ nm ^ \" and args\");\n    (list_comb (oper, args), ss) end\n  | parse_val (\"Var\" :: nm :: ss) = let\n    val (typ, ss) = parse_typ ss\n  in (mk_acc nm typ s, ss) end\n  | parse_val (\"Type\" :: ss) = let\n    val (typ, ss) = parse_typ ss\n  in (Logic.mk_type typ, ss) end\n  | parse_val (\"Symbol\" :: nm :: ss) = let\n    val (_, ss) = parse_typ ss\n  in (TermsTypes.symbol_table $ HOLogic.mk_string nm, ss) end\n  | parse_val ss = raise PARSEGRAPH (\"parse_val: malformed\" :: ss)\n\nval parse_lvals = parse_n parse_lval\n\nval parse_vars = parse_n parse_var\n\nfun mk_var_typ T = (case T of\n        @{typ word8} => @{term VarWord8}\n      | @{typ word16} => @{term VarWord16}\n      | @{typ word32} => @{term VarWord32}\n      | @{typ word64} => @{term VarWord64}\n      | Type (@{type_name word}, [Type (@{type_name signed}, [T2])])\n        => let val uT = Type (@{type_name word}, [T2])\n        in Abs (\"t\", T, mk_var_typ uT $ (Const (@{const_name ucast}, T --> uT) $ Bound 0)) end\n      | @{typ \"machine_word \\<Rightarrow> word8\"} => @{term VarMem}\n      | @{typ \"ghost_assertions\"} => @{term VarGhostState}\n      | @{typ \"machine_word set\"} => @{term VarDom}\n      | @{typ \"heap_typ_desc\"} => @{term VarHTD}\n      | @{typ \"unit \\<times> nat\"} => @{term VarMS}\n      | @{typ bool} => @{term VarBool}\n      | _ => raise TYPE (\"mk_var_typ: unexpected var typ\", [T], []))\n\nfun mk_var_term t = betapply (mk_var_typ (fastype_of t), t)\n\nfun parse_val_acc ss = let\n    val (t, ss) = parse_val ss\n  in (Term.lambda_name (\"s\", s) (mk_var_term t), ss) end\n\nfun parse_cond ss = let\n    val (t, ss) = parse_val ss\n  in (Term.lambda_name (\"s\", s) t, ss) end\n\nval parse_vals = parse_n parse_val_acc\n\nfun mk_NextNode n = @{term NextNode} $ HOLogic.mk_number @{typ nat} n\n\nfun parse_nn \"Err\" = @{term Err}\n  | parse_nn \"Ret\" = @{term Ret}\n  | parse_nn n = mk_NextNode (parse_int n)\n\nfun parse_fun_decl (\"Function\" :: nm :: ss) = let\n    val (xs, ss) = parse_vars ss\n    val (ys, ss) = parse_vars ss\n  in\n    ss = [] orelse raise PARSEGRAPH (\"parse_fun_decl: trailing\" :: ss);\n    (nm, xs, ys)\n  end\n  | parse_fun_decl ss = raise PARSEGRAPH (\"parse_fun_decl: malformed\" :: ss)\n\nfun parse_var_and_val_acc ss = let\n    val (var, ss) = parse_var ss\n    val (v, ss) = parse_val_acc ss\n  in (HOLogic.mk_prod (HOLogic.mk_string var, v), ss) end\n\nval mk_stringlist = map HOLogic.mk_string #> HOLogic.mk_list @{typ string}\n\nfun parse_node (n :: ss) = let\n    val n = parse_int n\n    val (t, ss) = case ss of\n      \"Cond\" :: l :: r :: ss => let\n        val l = parse_nn l\n        val r = parse_nn r\n        val (c, ss) = parse_cond ss\n      in (@{term Cond} $ l $ r $ c, ss) end\n      | \"Basic\" :: c :: ss => let\n        val c = parse_nn c\n        val (upds, ss) = parse_n parse_var_and_val_acc ss\n      in (@{term Basic} $ c $ HOLogic.mk_list\n            @{typ \"string \\<times> (state \\<Rightarrow> variable)\"} upds, ss) end\n      | \"Call\" :: c :: fname :: ss => let\n        val c = parse_nn c\n        val (args, ss) = parse_vals ss\n        val (rets, ss) = parse_vars ss\n      in (@{term Call} $ c $ HOLogic.mk_string fname\n            $ HOLogic.mk_list @{typ \"state \\<Rightarrow> variable\"} args\n            $ mk_stringlist rets, ss) end\n      | _ => raise PARSEGRAPH (\"parse_node: malformed\" :: ss)\n  in\n    ss = [] orelse raise PARSEGRAPH (\"parse_node: trailing\" :: ss);\n    (n, t)\n  end\n  | parse_node [] = raise PARSEGRAPH ([\"parse_node: empty\"])\n\nfun parse_fun ([\"Function\" :: ss]) = let\n    val (nm, xs, ys) = parse_fun_decl (\"Function\" :: ss)\n  in SOME (nm, (xs, ys, NONE)) end\n  | parse_fun ((\"Function\" :: ss) :: sss) = let\n    val (nm, xs, ys) = parse_fun_decl (\"Function\" :: ss)\n    val _ = tracing (\"Parsing \" ^ nm)\n    val (node_sss, sss) = chop_prefix\n        (fn ss => not (is_prefix (op =) [\"EntryPoint\"] ss)) sss\n    val (ep, _) = case sss of (ep :: sss) => (ep, sss)\n        | [] => raise PARSEGRAPH [\n        \"parse_fun: EntryPoint not found\"]\n    val ep = case ep of [_, n] => parse_int n\n        | _ => raise PARSEGRAPH (\n        \"parse_fun: EntryPoint line malformed\" :: ep)\n  in\n    SOME (nm, (xs, ys, SOME (ep, map parse_node node_sss,\n        Abs (\"g\", @{typ \"nat \\<Rightarrow> node option\"}, @{term GraphFunction}\n            $ mk_stringlist xs $ mk_stringlist ys\n            $ Bound 0 $ HOLogic.mk_number @{typ nat} ep))))\n  end\n  | parse_fun [] = raise PARSEGRAPH [\"parse_fun: empty\"]\n  | parse_fun (ss :: _) = (warning (\"parse_fun: ignoring: \"\n    ^ space_implode \" \" ss); NONE)\n\nfun fun_groups gp ((fs as (\"Function\" :: _)) :: sss) =\n    (if null gp then [] else [rev gp]) @ fun_groups [fs] sss\n  | fun_groups gp ([] :: sss) = fun_groups gp sss\n  | fun_groups gp (ss :: sss) = fun_groups (ss :: gp) sss\n  | fun_groups gp [] = [rev gp]\n\nfun filename_relative thy name =\n    Path.append (Resources.master_directory thy) (Path.explode name)\n    |> File.standard_path\n\nfun mkdir_relative thy name =\n    Path.append (Resources.master_directory thy) (Path.explode name)\n    |> Isabelle_System.mkdirs\n\nfun openIn_relative thy = filename_relative thy #> TextIO.openIn\n\nfun get_funs thy file = let\n    val f = openIn_relative thy file\n    fun get () = case TextIO.inputLine f\n      of NONE => []\n      | SOME s => unsuffix \"\\n\" s :: get ()\n    val lines = get ()\n      |> map (Library.space_explode \" \" #> filter (fn s => s <> \"\"))\n      |> filter_out null\n      |> filter_out (fn (s :: _) => String.isPrefix \"#\" s | _ => false)\n  in fun_groups [] lines end\n\ntype funs = (string list * string list * (int * (int * term) list * term) option) Symtab.table\n\nfun funs thy file : funs = get_funs thy file\n  |> map_filter parse_fun\n  |> Symtab.make\n\nfun define_graph s nodes = let\n    val nodes = sort (int_ord o apply2 fst) nodes\n  in StaticFun.define_tree_and_save_thms (Binding.name s)\n    (map (fst #> Int.toString #> prefix (s ^ \"_\")) nodes)\n    (map (apfst (HOLogic.mk_number @{typ nat})) nodes)\n    @{term \"id :: nat => nat\"} []\n  end\n\nfun define_graph_fun (funs : funs) b1 b2 nm ctxt =\n        case (Symtab.lookup funs nm) of\n    SOME (_, _, SOME (_, g, gf))\n    => let\n    val (graph_term, ctxt) = define_graph b1 g ctxt\n    val (_, ctxt) = Local_Theory.define ((b2, NoSyn), ((Thm.def_binding b2, []),\n        betapply (gf, graph_term))) ctxt\n  in ctxt end\n  | _ => error (\"define_graph_fun: \" ^ nm ^ \" not in funs\")\n\nend\n\n\\<close>\n\nend\n", "meta": {"author": "NICTA", "repo": "l4v", "sha": "3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b", "save_path": "github-repos/isabelle/NICTA-l4v", "path": "github-repos/isabelle/NICTA-l4v/l4v-3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b/tools/asmrefine/GraphLang.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5888891307678321, "lm_q2_score": 0.44552953503957277, "lm_q1q2_score": 0.2623675006208504}}
{"text": "\ntheory localesDef imports cache\nbegin\n\nlocale pRule0VsPInv0=\n  fixes paraRule ::\"  rule\"  and paraInv::\"formula \"\n  assumes\n\n  b:\"\n  invHoldForRule' s   (paraInv) (paraRule )  (invariants N) \"  \nbegin\ntheorem  pRule0VsPInv0:\n\n  shows \"invHoldForRule' s   (paraInv) (paraRule  )   (invariants N) \" \n  by(cut_tac a1 b,auto)\nend\n\n\nlocale pRule0VspInv1=\n  fixes paraRule ::\"rule\"  and paraInv::\"nat\\<Rightarrow>formula \"  \n  and iInv1::\"nat\"   and N::\"nat\"\n  assumes  \n  b:\"invHoldForRule' s   (paraInv iInv1) (paraRule)  invariants  \"  \nbegin\ntheorem  pRule10VspInv1:\n   assumes a1:\"iInv1 \\<le> N\"  \n\n\n  shows \"invHoldForRule' s   (paraInv iInv1) (paraRule )   invariants  \" \n  by(cut_tac a1 b,auto)\nend\n\n\n\nlocale pRule0VsPInv2=\n  fixes paraRule ::\"  rule\"  and paraInv::\"nat\\<Rightarrow>nat\\<Rightarrow>formula \"  and iInv1::\"nat\" and iInv2::\"nat\" and N::\"nat\" and  invariants::\"formula set\"\n  assumes  \n\n  b:\" invHoldForRule' s  (paraInv iInv1 iInv2) (paraRule)  invariants  \"  \nbegin\ntheorem  pRule0VsPInv2:\n    assumes  a2:\" iInv1 \\<le> N \" and a3:\"iInv2 \\<le> N \"\n  and a4:\"iInv1 \\<noteq> iInv2\" \n\n\n  shows \"invHoldForRule' s  (paraInv iInv1 iInv2) (paraRule )   invariants \" \n   \n  by(cut_tac a1 b,auto)\nend\n\nlocale pRule0VsPInv3=\n  fixes paraRule ::\"  rule\"  and paraInv::\"nat\\<Rightarrow>nat\\<Rightarrow>nat\\<Rightarrow>formula \"  and iInv1::\"nat\" and iInv2::\"nat\" \n  and iInv3::\"nat\"  and N::\"nat\" and  invariants::\"formula set\"\n  assumes  a2:\" iInv1 \\<le> N \" and a3:\"iInv2 \\<le> N \" and a4:\"iInv3 \\<le> N \"\n  and a5:\"iInv1 \\<noteq> iInv2\" and a6:\"iInv1 \\<noteq> iInv3\" and a7:\"iInv2 \\<noteq> iInv3\" and\n\n  b:\" invHoldForRule' s  (paraInv iInv1 iInv2 iInv3) (paraRule)  invariants  \"  \nbegin\ntheorem  pRule0VsPInv2:\n\n\n  shows \"invHoldForRule' s  (paraInv iInv1 iInv2 iInv3) (paraRule )   invariants \" \n   \n  by(cut_tac  b,auto)\nend\n\n\nlocale pRule1VsPInv0=\n  fixes paraRule ::\"nat \\<Rightarrow>  rule\"  and paraInv::\"formula \"  \n  and iRule1::\"nat\"   and N::\"nat\"  and  invariants::\"formula set\"\n  assumes\n  b:\"\n  invHoldForRule' s   (paraInv) (paraRule iRule1)  invariants \"  \nbegin\ntheorem  pRule1VsPInv0:\n   assumes\n  a1:\"iRule1 \\<le> N \"\n\n  shows \"invHoldForRule' s   (paraInv) (paraRule iRule1 )   invariants \" \n  (is \"?P paraInv  paraRule iRule1    invs\")\n  by(cut_tac a1 b,auto)\nend\n \n\n\nlocale pRule1VspInv1=\n  fixes paraRule ::\"nat \\<Rightarrow> rule\"  and paraInv::\"nat \\<Rightarrow> formula \"  \n  and iRule::\"nat\" and iInv1::\"nat\"  and N::\"nat\"  and  invariants::\"formula set\"\n  assumes \n \n  b:\" iRule = iInv1 \\<longrightarrow> \n  (invHoldForRule' s   (paraInv iInv1) (paraRule iRule)  invariants )\"  and \n  c:\"  iRule \\<noteq> iInv1 \\<longrightarrow> \n  (invHoldForRule' s   (paraInv iInv1) (paraRule iRule)  invariants  )\" \nbegin\ntheorem pRule1VspInv1:\n  assumes\n   a1:\"iRule \\<le> N\"  and a2:\" iInv1 \\<le> N \"\n  shows \"(invHoldForRule' s   (paraInv iInv1) (paraRule iRule)  invariants  )\"\n    (is \"?P paraInv iInv1 paraRule iRule  invariants\")\n  proof -\n   have e2:\"iRule=iInv1  \\<or> iRule \\<noteq> iInv1 \"  by auto\n     \n     \n   moreover\n   {assume e3:\" iRule=iInv1 \"\n            \n     have \"?P paraInv iInv1 paraRule iRule  invariants\"\n       by (metis a1 a2 b e3)\n   }     \n   moreover\n   {assume e3:\"iRule\\<noteq>iInv1 \"\n     have \"?P paraInv iInv1 paraRule iRule  invariants \"\n       by (metis a1 a2 c e3)\n   }\n   ultimately show \"?P paraInv iInv1 paraRule iRule  invariants \"\n     by blast\n qed\nend\n  \n locale pRule1VspInv2=\n  fixes paraRule ::\"nat \\<Rightarrow> rule\"  and paraInv::\"nat \\<Rightarrow> nat\\<Rightarrow>formula \"  \n  and iRule::\"nat\" and iInv1::\"nat\" and iInv2::\"nat\" and N::\"nat\"   and  invariants::\"formula set\"\n  \n  assumes\n  b:\"iRule \\<le> N\\<longrightarrow> iInv1 \\<le> N \\<longrightarrow>iInv2 \\<le> N\\<longrightarrow>iInv1 \\<noteq> iInv2 \\<longrightarrow> iRule = iInv1\\<longrightarrow>\n  invHoldForRule' s   (paraInv iInv1 iInv2) (paraRule iRule)  invariants \"  and \n  c:\"iRule \\<le> N\\<longrightarrow> iInv1 \\<le> N \\<longrightarrow>iInv2 \\<le> N\\<longrightarrow>iInv1 \\<noteq> iInv2 \\<longrightarrow>iRule = iInv2 \\<longrightarrow> \n  invHoldForRule' s   (paraInv iInv1 iInv2) (paraRule iRule) invariants\"  and\n  d:\"iRule \\<le> N\\<longrightarrow> iInv1 \\<le> N \\<longrightarrow>iInv2 \\<le> N\\<longrightarrow>iInv1 \\<noteq> iInv2 \\<longrightarrow>iRule \\<noteq> iInv1 \\<longrightarrow>iRule \\<noteq> iInv2 \\<longrightarrow> \n  invHoldForRule' s   (paraInv iInv1 iInv2) (paraRule iRule)  invariants\"\nbegin\ntheorem  pRule1VspInv2:\n assumes  a1:\"iRule \\<le> N\"  and a2:\" iInv1 \\<le> N \" and a3:\"iInv2 \\<le> N \"and a4:\"iInv1 \\<noteq> iInv2\" \n  \n  shows \"invHoldForRule' s   (paraInv iInv1 iInv2) (paraRule iRule)   invariants \"  (is \"?P paraInv iInv paraRule iRule  invs\")\n  proof -\n   have d2:\"iRule=iInv1 \\<or> iRule=iInv2 \\<or> ((iRule \\<noteq> iInv1) \\<and> (iRule\\<noteq>iInv2))\"  by auto\n   moreover\n   {assume e1:\"iRule=iInv1\"\n     have \"?P paraInv iInv paraRule iRule  invs \"\n       by (metis  a2 a3 a4 b e1)\n              \n           \n   }    \n   \n   moreover\n   {assume e1:\"iRule = iInv2\"            \n     have \"?P paraInv iInv paraRule iRule  invs\"\n       by (metis  a2 a3 a4 c e1)\n   }\n   \n       \n   moreover\n   {assume e1:\"iRule\\<noteq>iInv1 \\<and> iRule\\<noteq>iInv2\"\n     have \"?P paraInv iInv paraRule iRule  invs\"\n       by (metis  a1 a2 a3 a4 d e1)\n            \n   }\n   ultimately show \"?P paraInv iInv paraRule iRule  invs\"\n     by blast\n qed\nend\n\n\nlocale pRule1VspInv3=\n  fixes paraRule ::\"nat \\<Rightarrow> rule\"  and paraInv::\"nat \\<Rightarrow> nat\\<Rightarrow>nat\\<Rightarrow>formula \"  \n  and iRule::\"nat\" and iInv1::\"nat\" and iInv2::\"nat\" and iInv3::\"nat\" and N::\"nat\"   and  invariants::\"formula set\" \n  assumes \n  b:\"iRule = iInv1 \\<longrightarrow> \n  invHoldForRule' s   (paraInv iInv1 iInv2 iInv3) (paraRule iRule)  invariants \"  and \n  c:\" iRule = iInv2 \\<longrightarrow> \n  invHoldForRule' s   (paraInv iInv1 iInv2 iInv3) (paraRule iRule) invariants\"  and\n  d:\"  iRule = iInv3 \\<longrightarrow>\n  invHoldForRule' s   (paraInv iInv1 iInv2 iInv3) (paraRule iRule)  invariants\" and\n  \n  e:\" iRule \\<noteq> iInv1 \\<longrightarrow>iRule \\<noteq> iInv2 \\<longrightarrow> iRule \\<noteq> iInv3 \\<longrightarrow>\n  invHoldForRule' s   (paraInv iInv1 iInv2 iInv3) (paraRule iRule)  invariants\"\nbegin\ntheorem  pRule1VspInv3:\n  assumes a1:\"iRule \\<le> N\"  and a2:\" iInv1 \\<le> N \" and a3:\"iInv2 \\<le> N \" and a4:\"iInv3 \\<le> N \"\n  and a5:\"iInv1 \\<noteq> iInv2\"  and a6:\"iInv1 \\<noteq> iInv3\"   and a7:\"iInv2 \\<noteq> iInv3\"\n  shows \"invHoldForRule' s   (paraInv iInv1 iInv2 iInv3) (paraRule iRule)   invariants \" \n  proof -\n   have d2:\"iRule=iInv1 \\<or> iRule=iInv2 \\<or> iRule=iInv3 \\<or> ((iRule \\<noteq> iInv1) \\<and> (iRule\\<noteq>iInv2) \\<and> iRule \\<noteq> iInv3 )\"  by auto\n   moreover\n   {assume e1:\"iRule=iInv1\"\n     have \"invHoldForRule' s   (paraInv iInv1 iInv2 iInv3) (paraRule iRule)   invariants \" \n       by (cut_tac b e1, auto)\n              \n           \n   }     \n   moreover\n   {assume e1:\"iRule = iInv2\"            \n     have \"invHoldForRule' s   (paraInv iInv1 iInv2 iInv3) (paraRule iRule)   invariants \" \n       by (cut_tac c e1,auto)\n   }\n   \n       \n   moreover\n   {assume e1:\"iRule = iInv3\"\n     have \"invHoldForRule' s   (paraInv iInv1 iInv2 iInv3) (paraRule iRule)   invariants \" \n       by (cut_tac  d  e1,auto)\n            \n   }\n   \n   moreover\n   {assume e1:\"iRule\\<noteq>iInv1 \\<and> iRule\\<noteq>iInv2 \\<and> iRule\\<noteq>iInv3\"\n      have \"invHoldForRule' s   (paraInv iInv1 iInv2 iInv3) (paraRule iRule)   invariants \"\n      by (metis e e1) \n            \n   }\n   ultimately show \"invHoldForRule' s   (paraInv iInv1 iInv2 iInv3) (paraRule iRule)   invariants \"\n     by blast\n qed\nend\n\n\n\nlocale paraRuleInstValidateExLessInvInst=\n  fixes paraRule ::\"nat \\<Rightarrow> rule\"  and paraInv::\"nat \\<Rightarrow> formula \"  \n  and iRule::\"nat\" and iInv1::\"nat\"  and N::\"nat\"\n  assumes  \n  b:\"iRule \\<le> N \\<longrightarrow>iInv1 \\<le> N\\<longrightarrow> iRule = iInv1 \\<longrightarrow> \n  (invHoldForRule' s  (paraInv iInv1) (paraRule iRule)  invariants )\"  and \n  c:\"iRule \\<le> N \\<longrightarrow>iInv1 \\<le> N\\<longrightarrow>  iRule \\<noteq> iInv1 \\<longrightarrow> \n  (invHoldForRule' s  (paraInv iInv1) (paraRule iRule)  invariants  )\" \nbegin\ntheorem paraRuleInstValidateExLessInvInst:\n  assumes a1:\"iRule \\<le> N\"  and a2:\" iInv1 \\<le> N \"\n  shows \"(invHoldForRule' s  (paraInv iInv1) (paraRule iRule)  invariants  )\"\n    (is \"?P paraInv iInv1 paraRule iRule  invariants\")\n  proof -\n   have e2:\"iRule=iInv1  \\<or> iRule \\<noteq> iInv1 \"  by auto\n     \n     \n   moreover\n   {assume e3:\" iRule=iInv1 \"\n            \n     have \"?P paraInv iInv1 paraRule iRule  invariants\"\n       by (metis a1 a2 b e3)\n   }     \n   moreover\n   {assume e3:\"iRule\\<noteq>iInv1 \"\n     have \"?P paraInv iInv1 paraRule iRule  invariants \"\n       by (metis a1 a2 c e3)\n   }\n   ultimately show \"?P paraInv iInv1 paraRule iRule  invariants \"\n     by blast\n qed\nend\n  \n  \nlocale paraRuleInstValidateExTwoLessInvInst=\n  fixes paraRule ::\"nat \\<Rightarrow> rule\"  and paraInv::\"nat \\<Rightarrow> nat\\<Rightarrow>formula \"  \n  and iRule::\"nat\" and iInv1::\"nat\" and iInv2::\"nat\" and N::\"nat\"\n  assumes  \n  b:\"iInv1 \\<noteq> iInv2\\<longrightarrow>iRule \\<le> N \\<longrightarrow>iInv1 \\<le> N\\<longrightarrow>iInv2 \\<le> N\\<longrightarrow>iRule = iInv1 \\<longrightarrow> \n  invHoldForRule' s  (paraInv iInv1 iInv2) (paraRule iRule)  invariants \"  and \n  c:\"iInv1 \\<noteq> iInv2\\<longrightarrow>iRule \\<le> N \\<longrightarrow>iInv1 \\<le> N\\<longrightarrow>iInv2 \\<le> N\\<longrightarrow>iRule = iInv2 \\<longrightarrow> \n  invHoldForRule' s  (paraInv iInv1 iInv2) (paraRule iRule) invariants\"  and\n  d:\"iInv1 \\<noteq> iInv2\\<longrightarrow>iRule \\<le> N \\<longrightarrow>iInv1 \\<le> N\\<longrightarrow>iInv2 \\<le> N\\<longrightarrow>iRule \\<noteq> iInv1 \\<longrightarrow>iRule \\<noteq> iInv2 \\<longrightarrow> \n  invHoldForRule' s  (paraInv iInv1 iInv2) (paraRule iRule)  invariants\"\nbegin\ntheorem paraRuleInstValidateExTwoLessInvInst:\n  assumes a1:\"iRule \\<le> N\"  and a2:\" iInv1 \\<le> N \" and a3:\"iInv2 \\<le> N \"\n  and a4:\"iInv1 \\<noteq> iInv2\"\n  shows \"invHoldForRule' s  (paraInv iInv1 iInv2) (paraRule iRule)   invariants \"  (is \"?P paraInv iInv paraRule iRule  invs\")\n  proof -\n   have d2:\"iRule=iInv1 \\<or> iRule=iInv2 \\<or> ((iRule \\<noteq> iInv1) \\<and> (iRule\\<noteq>iInv2))\"  by auto\n   moreover\n   {assume e1:\"iRule=iInv1\"\n     have \"?P paraInv iInv paraRule iRule  invs \"\n       by (metis  a2 a3 a4 b e1)\n              \n           \n   }     \n   moreover\n   {assume e1:\"iRule = iInv2\"            \n     have \"?P paraInv iInv paraRule iRule  invs\"\n       by (metis  a2 a3 a4 c e1)\n   }\n   \n       \n   moreover\n   {assume e1:\"iRule\\<noteq>iInv1 \\<and> iRule\\<noteq>iInv2\"\n     have \"?P paraInv iInv paraRule iRule  invs\"\n       by (metis  a1 a2 a3 a4 d e1)\n            \n   }\n   ultimately show \"?P paraInv iInv paraRule iRule  invs\"\n     by blast\n qed\nend\n\n\n\nlocale pRule2VsPInv0=\n  fixes paraRule ::\"nat \\<Rightarrow> nat\\<Rightarrow> rule\"  and paraInv::\"formula \"  \n  and iRule1::\"nat\" and iRule2::\"nat\"  and N::\"nat\"\n  assumes\n\n  b:\"\n  invHoldForRule' s   (paraInv) (paraRule iRule1 iRule2)  invariants \"  \nbegin\ntheorem  pRule12sPInv0:\n  assumes a1:\"iRule1 \\<le> N\"  and a2:\"iRule2 \\<le>N\"\n\n  shows \"invHoldForRule' s   (paraInv) (paraRule iRule1 iRule2)   invariants \" \n \n  by(cut_tac a1 a2 b,auto)\nend\n \n\n\nlocale pRule2VspInv1=\n  fixes paraRule ::\"nat \\<Rightarrow>nat\\<Rightarrow> rule\"  and paraInv::\"nat \\<Rightarrow> formula \"  \n  and iRule1::\"nat\" and iRule2::\"nat\" and iInv1::\"nat\"  and N::\"nat\"\n  assumes \n  b:\" iRule1 = iInv1 \\<longrightarrow> \n  (invHoldForRule' s   (paraInv iInv1) (paraRule iRule1  iRule2)  invariants )\"  and \n  c:\"  iRule2= iInv1  \\<longrightarrow>\n  (invHoldForRule' s   (paraInv iInv1) (paraRule iRule1  iRule2)  invariants  )\"   and \n  d:\"  iRule1\\<noteq> iInv1  \\<longrightarrow>iRule2\\<noteq> iInv1 \\<longrightarrow>\n  (invHoldForRule' s   (paraInv iInv1) (paraRule iRule1  iRule2)  invariants  )\"  \nbegin\ntheorem pRule2VspInv1:\n  assumes a1:\"iRule1 \\<le> N\"  and a2:\" iRule2 \\<le> N \" and a3:\" iInv1 \\<le> N \"\n  shows \"(invHoldForRule' s   (paraInv iInv1) (paraRule  iRule1  iRule2)  invariants  )\" \n  proof -\n   have e2:\"iRule1=iInv1  \\<or> iRule2 = iInv1 \\<or> (iRule1\\<noteq> iInv1  \\<and> iRule2\\<noteq> iInv1) \"  by auto\n     \n     \n   moreover\n   {assume e3:\" iRule1=iInv1 \"\n            \n     have \"(invHoldForRule' s   (paraInv iInv1) (paraRule  iRule1  iRule2)  invariants  )\" \n       by (cut_tac b e3,auto )\n   }     \n   moreover\n   {assume e3:\" iRule2=iInv1 \"\n            \n     have \"(invHoldForRule' s   (paraInv iInv1) (paraRule  iRule1  iRule2)  invariants  )\" \n       by (cut_tac c e3,auto )\n   }\n    moreover\n   {assume e3:\" (iRule1\\<noteq> iInv1  \\<and> iRule2\\<noteq> iInv1) \"\n            \n     have \"(invHoldForRule' s   (paraInv iInv1) (paraRule  iRule1  iRule2)  invariants  )\" \n       by (cut_tac d e3,auto )\n   }\n   ultimately show\"(invHoldForRule' s   (paraInv iInv1) (paraRule  iRule1  iRule2)  invariants  )\" \n     by blast\n qed\nend\n  \n\nlocale pRule2VsPInv2=\n  fixes paraRule ::\"nat \\<Rightarrow> nat\\<Rightarrow>rule\"  and paraInv::\"nat \\<Rightarrow> nat\\<Rightarrow>formula \"  \n  and iRule1::\"nat\" and iRule2::\"nat\"  and iInv1::\"nat\" and iInv2::\"nat\" and N::\"nat\" and invariants::\"formula set\"\n  assumes\n  b:\"iRule1 = iInv1 \\<and> iRule2 = iInv2\\<longrightarrow>\n  invHoldForRule' s   (paraInv iInv1 iInv2) (paraRule iRule1 iRule2)  invariants \"  and \n  c:\"iRule1 = iInv1 \\<and> iRule2 \\<noteq> iInv2\\<longrightarrow>\n  invHoldForRule' s   (paraInv iInv1 iInv2) (paraRule iRule1 iRule2)  invariants \"  and\n  d:\"iRule1 = iInv2 \\<longrightarrow>  \n  invHoldForRule' s   (paraInv iInv1 iInv2) (paraRule iRule1 iRule2) invariants\"  and\n  e:\"iRule1 \\<noteq> iInv2 \\<longrightarrow> \n  invHoldForRule' s   (paraInv iInv1 iInv2) (paraRule iRule1 iRule2)  invariants\"   \nbegin\ntheorem  pRule1VspInv2:\n  assumes a1:\"iRule \\<le> N\"  and a2:\" iInv1 \\<le> N \" and a3:\"iInv2 \\<le> N \"\n  and a4:\"iInv1 \\<noteq> iInv2\"\n  shows \"invHoldForRule' s   (paraInv iInv1 iInv2) (paraRule iRule1 iRule2)   invariants \"\n  proof -\n   have d2:\"(iRule1 = iInv1 \\<and> iRule2 = iInv2)\\<and> (iRule1 = iInv1 \\<and> iRule2 \\<noteq> iInv2) \\<or> iRule1=iInv2 \\<or> ( (iRule1\\<noteq>iInv2))\"  by auto\n   moreover\n   {assume e1:\"iRule1=iInv1 \\<and> iRule2 = iInv2\"\n     have \"invHoldForRule' s   (paraInv iInv1 iInv2) (paraRule iRule1 iRule2)   invariants \"\n       by (cut_tac b e1,auto)\n              \n           \n   }     \n   moreover\n   {assume e1:\"iRule1 = iInv1 \\<and> iRule2 \\<noteq> iInv2\"            \n     have \"invHoldForRule' s   (paraInv iInv1 iInv2) (paraRule iRule1 iRule2)   invariants \"\n       by (metis  a2 a3 a4 c e1)\n   }\n   \n       \n   moreover\n   {assume e1: \"iRule1=iInv2 \"\n     have \"invHoldForRule' s   (paraInv iInv1 iInv2) (paraRule iRule1 iRule2)   invariants \"\n       by (metis  d e1)\n            \n   }\n   moreover\n   {assume e1: \"iRule1\\<noteq>iInv2 \"\n     have \"invHoldForRule' s   (paraInv iInv1 iInv2) (paraRule iRule1 iRule2)   invariants \"\n       by (metis e e1)\n            \n   }\n   ultimately show \"invHoldForRule' s   (paraInv iInv1 iInv2) (paraRule iRule1 iRule2)   invariants \"\n     by blast\n qed\nend\n\n\nlocale pRule2VspInv3=\n  fixes paraRule ::\"nat \\<Rightarrow> nat\\<Rightarrow>rule\"  and paraInv::\"nat \\<Rightarrow> nat\\<Rightarrow>nat\\<Rightarrow>formula \"  \n  and iRule1::\"nat\"  and  iRule2::\"nat\"  and iInv1::\"nat\" and iInv2::\"nat\"  and iInv3::\"nat\" and N::\"nat\"\n  and invariants::\"formula set\"\n  assumes \n  b:\"iRule1 = iInv1 \\<longrightarrow> \n  invHoldForRule' s   (paraInv iInv1 iInv2 iInv3) (paraRule iRule1 iRule2)  invariants \"  and \n  c:\" iRule1 = iInv2 \\<longrightarrow> \n  invHoldForRule' s   (paraInv iInv1 iInv2 iInv3) (paraRule iRule1 iRule2 ) invariants\"  and\n  d:\"  iRule1 = iInv3 \\<longrightarrow>\n  invHoldForRule' s   (paraInv iInv1 iInv2 iInv3) (paraRule iRule1 iRule2)  invariants\" and\n  \n  e:\" iRule1 \\<noteq> iInv1 \\<longrightarrow>iRule1 \\<noteq> iInv2 \\<longrightarrow> iRule1 \\<noteq> iInv3 \\<longrightarrow>\n  invHoldForRule' s   (paraInv iInv1 iInv2 iInv3) (paraRule iRule1 iRule2)  invariants\"\nbegin\ntheorem  pRule1VspInv3:\n  assumes a1:\"iRule \\<le> N\"  and a2:\" iInv1 \\<le> N \" and a3:\"iInv2 \\<le> N \" and a4:\"iInv3 \\<le> N \"\n  and a5:\"iInv1 \\<noteq> iInv2\"  and a6:\"iInv1 \\<noteq> iInv3\"   and a7:\"iInv2 \\<noteq> iInv3\"\n  shows \"invHoldForRule' s   (paraInv iInv1 iInv2 iInv3) (paraRule iRule1 iRule2)  invariants \" \n  proof -\n   have d2:\"iRule1=iInv1 \\<or> iRule1=iInv2 \\<or> iRule1=iInv3 \\<or> ((iRule1 \\<noteq> iInv1) \\<and> (iRule1\\<noteq>iInv2) \\<and> iRule1 \\<noteq> iInv3 )\"  by auto\n   moreover\n   {assume e1:\"iRule1=iInv1\"\n     have \"invHoldForRule' s   (paraInv iInv1 iInv2 iInv3) (paraRule iRule1 iRule2)  invariants  \"\n       by (cut_tac b e1, auto)\n              \n           \n   }     \n   moreover\n   {assume e1:\"iRule1 = iInv2\"            \n     have \"invHoldForRule' s   (paraInv iInv1 iInv2 iInv3) (paraRule iRule1 iRule2)  invariants  \"\n       by (cut_tac c e1,auto)\n   }\n   \n       \n   moreover\n   {assume e1:\"iRule1=iInv3\"\n     have \"invHoldForRule' s   (paraInv iInv1 iInv2 iInv3) (paraRule iRule1 iRule2)  invariants  \" \n       by (cut_tac  d  e1,auto)\n            \n   }\n   \n   moreover\n   {assume e1:\"iRule1\\<noteq>iInv1 \\<and> iRule1\\<noteq>iInv2 \\<and> iRule1\\<noteq>iInv3\"\n      have \"invHoldForRule' s   (paraInv iInv1 iInv2 iInv3) (paraRule iRule1 iRule2)  invariants  \" \n       by (cut_tac  e  e1,auto)\n            \n   }\n   ultimately show \"invHoldForRule' s   (paraInv iInv1 iInv2 iInv3) (paraRule iRule1 iRule2)  invariants  \" \n     by blast\n qed\nend\n\n\nlocale iniImplyInv0= \n  fixes paraInv ::\"  formula\" and specOnAVar::\"formula\" and specOnAVars::\"formula list\"\n  assumes a:\" formEval  specOnAVar  s \\<longrightarrow>formEval ( paraInv  ) s\" and\n  b:\"specOnAVar \\<in>set specOnAVars\"\nbegin \ntheorem iniImplyInv: \n  assumes a1:\"ex0P N (  invariant = paraInv  )\" and \n   a2:\"formEval  (andList specOnAVars) s\" \n  shows \"formEval invariant  s \" \nproof - \n  \n \n  have b2:\"formEval  specOnAVar  s\"    \n  by (metis a2 andList1 b)\n \n  \n \n  then show b5:\"formEval (  invariant )   s\" \n \n    apply -    \n    apply(cut_tac a1 a2 a)\n    by (metis (poly_guards_query) a ex0P_def)\n   \n   \nqed \nend     \n  \nlocale iniImplyInv1= \n  fixes paraInv ::\" nat \\<Rightarrow> formula\"  and N::\"nat\" and specOnAVar::\"formula\" and specOnAVars::\"formula list\"\n  assumes a:\"\\<forall>i . i\\<le>N \\<longrightarrow> formEval  specOnAVar  s \\<longrightarrow>formEval ( paraInv i ) s\" and\n  b:\"specOnAVar \\<in>set specOnAVars\"\nbegin \ntheorem iniImplyInv: \n  assumes a1: \" ex1P N (%i.  invariant = paraInv i )\"   \n  and a2:\"formEval  (andList specOnAVars) s\" \n  shows \"formEval invariant  s \" \nproof - \n  from a1 obtain i j where b1:\"i \\<le> N \\<and> invariant =paraInv  i\"  \n    apply - \n    apply(simp add:ex1P_def) \n    apply auto \n    done \n \n  have b2:\"formEval  specOnAVar  s\"    \n  by (metis a2 andList1 b)\n \n  \n \n  then have b5:\"formEval ( paraInv i)   s\" \n \n    apply -    \n    apply(cut_tac a1 b2 a)\n    by (metis b1 local.a)  \n   \n     \n then  show  \"formEval invariant s \"\n by (metis b1)    \n   \nqed \nend   \n  \nlocale iniImplyInv2= \n  fixes paraInv ::\" nat \\<Rightarrow>nat \\<Rightarrow> formula\"  and N::\"nat\" and specOnAVar::\"formula\" and specOnAVars::\"formula list\"\n  assumes a:\"\\<forall>i j. i\\<le>N \\<longrightarrow>  j\\<le>N \\<longrightarrow> formEval  specOnAVar  s \\<longrightarrow>formEval ( paraInv i j) s\" and\n  b:\"specOnAVar \\<in>set specOnAVars\"\nbegin \ntheorem iniImplyInv: \n  assumes a1: \" ex2P N (%i j.  invariant = paraInv i j)\"   \n  and a2:\"formEval  (andList specOnAVars) s\" \n  shows \"formEval invariant  s \" \nproof - \n  from a1 obtain i j where b1:\"i \\<le> N \\<and> j\\<le>N \\<and> invariant =paraInv  i j\"  \n    apply - \n    apply(simp add:ex2P_def) \n    apply auto \n    done \n \n  have b2:\"formEval  specOnAVar  s\"    \n  by (metis a2 andList1 b)\n \n  \n \n  then have b5:\"formEval ( paraInv i j)   s\" \n \n    apply -    \n    apply(cut_tac a1 b2 a)\n    by (metis b1 local.a)  \n   \n     \n then  show  \"formEval invariant s \"\n by (metis b1)    \n   \nqed \nend \n\n\nlocale iniImplyInv3= \n  fixes paraInv ::\" nat \\<Rightarrow>nat \\<Rightarrow> nat\\<Rightarrow>formula\"  and N::\"nat\" and specOnAVar::\"formula\" and specOnAVars::\"formula list\"\n  assumes a:\"\\<forall>i j k. i\\<le>N \\<longrightarrow>  j\\<le>N \\<longrightarrow> k \\<le>N \\<longrightarrow> formEval  specOnAVar  s \\<longrightarrow>formEval ( paraInv i j k) s\" and\n  b:\"specOnAVar \\<in>set specOnAVars\"\nbegin \ntheorem iniImplyInv: \n  assumes a1: \" ex3P N (%i j k.  invariant = paraInv i j k)\"   \n  and a2:\"formEval  (andList specOnAVars) s\" \n  shows \"formEval invariant  s \" \nproof - \n  from a1 obtain i j k where b1:\"i \\<le> N \\<and> j\\<le>N \\<and> k \\<le>N \\<and>  invariant =paraInv  i j k\"  \n    apply - \n    apply(simp add:ex3P_def) \n    apply auto \n    done \n \n  have b2:\"formEval  specOnAVar  s\"    \n  by (metis a2 andList1 b)\n \n  \n \n  then have b5:\"formEval ( paraInv i j k)   s\" \n \n    apply -    \n    apply(cut_tac a1 b2 a)\n    by (metis b1 local.a)  \n   \n     \n then  show  \"formEval invariant s \"\n by (metis b1)    \n   \nqed \nend \n\nend\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/localesDef.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.26224946369766605}}
{"text": "(*  Title:      HOL/Library/Old_SMT.thy\n    Author:     Sascha Boehme, TU Muenchen\n*)\n\nsection \\<open>Old Version of Bindings to Satisfiability Modulo Theories (SMT) solvers\\<close>\n\ntheory Old_SMT\nimports \"../Real\" \"../Word/Word\"\nkeywords \"old_smt_status\" :: diag\nbegin\n\nML_file \"Old_SMT/old_smt_utils.ML\"\nML_file \"Old_SMT/old_smt_failure.ML\"\nML_file \"Old_SMT/old_smt_config.ML\"\n\n\nsubsection \\<open>Triggers for quantifier instantiation\\<close>\n\ntext \\<open>\nSome SMT solvers support patterns as a quantifier instantiation\nheuristics.  Patterns may either be positive terms (tagged by \"pat\")\ntriggering quantifier instantiations -- when the solver finds a\nterm matching a positive pattern, it instantiates the corresponding\nquantifier accordingly -- or negative terms (tagged by \"nopat\")\ninhibiting quantifier instantiations.  A list of patterns\nof the same kind is called a multipattern, and all patterns in a\nmultipattern are considered conjunctively for quantifier instantiation.\nA list of multipatterns is called a trigger, and their multipatterns\nact disjunctively during quantifier instantiation.  Each multipattern\nshould mention at least all quantified variables of the preceding\nquantifier block.\n\\<close>\n\ntypedecl pattern\n\nconsts\n  pat :: \"'a \\<Rightarrow> pattern\"\n  nopat :: \"'a \\<Rightarrow> pattern\"\n\ndefinition trigger :: \"pattern list list \\<Rightarrow> bool \\<Rightarrow> bool\" where \"trigger _ P = P\"\n\n\nsubsection \\<open>Quantifier weights\\<close>\n\ntext \\<open>\nWeight annotations to quantifiers influence the priority of quantifier\ninstantiations.  They should be handled with care for solvers, which support\nthem, because incorrect choices of weights might render a problem unsolvable.\n\\<close>\n\ndefinition weight :: \"int \\<Rightarrow> bool \\<Rightarrow> bool\" where \"weight _ P = P\"\n\ntext \\<open>\nWeights must be non-negative.  The value \\<open>0\\<close> is equivalent to providing\nno weight at all.\n\nWeights should only be used at quantifiers and only inside triggers (if the\nquantifier has triggers).  Valid usages of weights are as follows:\n\n\\begin{itemize}\n\\item\n@{term \"\\<forall>x. trigger [[pat (P x)]] (weight 2 (P x))\"}\n\\item\n@{term \"\\<forall>x. weight 3 (P x)\"}\n\\end{itemize}\n\\<close>\n\n\nsubsection \\<open>Higher-order encoding\\<close>\n\ntext \\<open>\nApplication is made explicit for constants occurring with varying\nnumbers of arguments.  This is achieved by the introduction of the\nfollowing constant.\n\\<close>\n\ndefinition fun_app where \"fun_app f = f\"\n\ntext \\<open>\nSome solvers support a theory of arrays which can be used to encode\nhigher-order functions.  The following set of lemmas specifies the\nproperties of such (extensional) arrays.\n\\<close>\n\nlemmas array_rules = ext fun_upd_apply fun_upd_same fun_upd_other\n  fun_upd_upd fun_app_def\n\n\nsubsection \\<open>First-order logic\\<close>\n\ntext \\<open>\nSome SMT solvers only accept problems in first-order logic, i.e.,\nwhere formulas and terms are syntactically separated. When\ntranslating higher-order into first-order problems, all\nuninterpreted constants (those not built-in in the target solver)\nare treated as function symbols in the first-order sense.  Their\noccurrences as head symbols in atoms (i.e., as predicate symbols) are\nturned into terms by logically equating such atoms with @{term True}.\nFor technical reasons, @{term True} and @{term False} occurring inside\nterms are replaced by the following constants.\n\\<close>\n\ndefinition term_true where \"term_true = True\"\ndefinition term_false where \"term_false = False\"\n\n\nsubsection \\<open>Integer division and modulo for Z3\\<close>\n\ndefinition z3div :: \"int \\<Rightarrow> int \\<Rightarrow> int\" where\n  \"z3div k l = (if 0 \\<le> l then k div l else -(k div (-l)))\"\n\ndefinition z3mod :: \"int \\<Rightarrow> int \\<Rightarrow> int\" where\n  \"z3mod k l = (if 0 \\<le> l then k mod l else k mod (-l))\"\n\n\nsubsection \\<open>Setup\\<close>\n\nML_file \"Old_SMT/old_smt_builtin.ML\"\nML_file \"Old_SMT/old_smt_datatypes.ML\"\nML_file \"Old_SMT/old_smt_normalize.ML\"\nML_file \"Old_SMT/old_smt_translate.ML\"\nML_file \"Old_SMT/old_smt_solver.ML\"\nML_file \"Old_SMT/old_smtlib_interface.ML\"\nML_file \"Old_SMT/old_z3_interface.ML\"\nML_file \"Old_SMT/old_z3_proof_parser.ML\"\nML_file \"Old_SMT/old_z3_proof_tools.ML\"\nML_file \"Old_SMT/old_z3_proof_literals.ML\"\nML_file \"Old_SMT/old_z3_proof_methods.ML\"\nnamed_theorems old_z3_simp \"simplification rules for Z3 proof reconstruction\"\nML_file \"Old_SMT/old_z3_proof_reconstruction.ML\"\nML_file \"Old_SMT/old_z3_model.ML\"\nML_file \"Old_SMT/old_smt_setup_solvers.ML\"\n\nsetup \\<open>\n  Old_SMT_Config.setup #>\n  Old_SMT_Normalize.setup #>\n  Old_SMTLIB_Interface.setup #>\n  Old_Z3_Interface.setup #>\n  Old_SMT_Setup_Solvers.setup\n\\<close>\n\nmethod_setup old_smt = \\<open>\n  Scan.optional Attrib.thms [] >>\n    (fn thms => fn ctxt =>\n      (legacy_feature \"Proof method \\\"old_smt\\\" will be discontinued soon -- use \\\"smt\\\" instead\";\n       METHOD (fn facts => HEADGOAL (Old_SMT_Solver.smt_tac ctxt (thms @ facts)))))\n\\<close> \"apply an SMT solver to the current goal\"\n\n\nsubsection \\<open>Configuration\\<close>\n\ntext \\<open>\nThe current configuration can be printed by the command\n\\<open>old_smt_status\\<close>, which shows the values of most options.\n\\<close>\n\n\n\nsubsection \\<open>General configuration options\\<close>\n\ntext \\<open>\nThe option \\<open>old_smt_solver\\<close> can be used to change the target SMT\nsolver.  The possible values can be obtained from the \\<open>old_smt_status\\<close>\ncommand.\n\nDue to licensing restrictions, Yices and Z3 are not installed/enabled\nby default.  Z3 is free for non-commercial applications and can be enabled\nby setting the \\<open>OLD_Z3_NON_COMMERCIAL\\<close> environment variable to\n\\<open>yes\\<close>.\n\\<close>\n\ndeclare [[ old_smt_solver = z3 ]]\n\ntext \\<open>\nSince SMT solvers are potentially non-terminating, there is a timeout\n(given in seconds) to restrict their runtime.  A value greater than\n120 (seconds) is in most cases not advisable.\n\\<close>\n\ndeclare [[ old_smt_timeout = 20 ]]\n\ntext \\<open>\nSMT solvers apply randomized heuristics.  In case a problem is not\nsolvable by an SMT solver, changing the following option might help.\n\\<close>\n\ndeclare [[ old_smt_random_seed = 1 ]]\n\ntext \\<open>\nIn general, the binding to SMT solvers runs as an oracle, i.e, the SMT\nsolvers are fully trusted without additional checks.  The following\noption can cause the SMT solver to run in proof-producing mode, giving\na checkable certificate.  This is currently only implemented for Z3.\n\\<close>\n\ndeclare [[ old_smt_oracle = false ]]\n\ntext \\<open>\nEach SMT solver provides several commandline options to tweak its\nbehaviour.  They can be passed to the solver by setting the following\noptions.\n\\<close>\n\ndeclare [[ old_cvc3_options = \"\" ]]\ndeclare [[ old_yices_options = \"\" ]]\ndeclare [[ old_z3_options = \"\" ]]\n\ntext \\<open>\nEnable the following option to use built-in support for datatypes and\nrecords.  Currently, this is only implemented for Z3 running in oracle\nmode.\n\\<close>\n\ndeclare [[ old_smt_datatypes = false ]]\n\ntext \\<open>\nThe SMT method provides an inference mechanism to detect simple triggers\nin quantified formulas, which might increase the number of problems\nsolvable by SMT solvers (note: triggers guide quantifier instantiations\nin the SMT solver).  To turn it on, set the following option.\n\\<close>\n\ndeclare [[ old_smt_infer_triggers = false ]]\n\ntext \\<open>\nThe SMT method monomorphizes the given facts, that is, it tries to\ninstantiate all schematic type variables with fixed types occurring\nin the problem.  This is a (possibly nonterminating) fixed-point\nconstruction whose cycles are limited by the following option.\n\\<close>\n\ndeclare [[ monomorph_max_rounds = 5 ]]\n\ntext \\<open>\nIn addition, the number of generated monomorphic instances is limited\nby the following option.\n\\<close>\n\ndeclare [[ monomorph_max_new_instances = 500 ]]\n\n\n\nsubsection \\<open>Certificates\\<close>\n\ntext \\<open>\nBy setting the option \\<open>old_smt_certificates\\<close> to the name of a file,\nall following applications of an SMT solver a cached in that file.\nAny further application of the same SMT solver (using the very same\nconfiguration) re-uses the cached certificate instead of invoking the\nsolver.  An empty string disables caching certificates.\n\nThe filename should be given as an explicit path.  It is good\npractice to use the name of the current theory (with ending\n\\<open>.certs\\<close> instead of \\<open>.thy\\<close>) as the certificates file.\nCertificate files should be used at most once in a certain theory context,\nto avoid race conditions with other concurrent accesses.\n\\<close>\n\ndeclare [[ old_smt_certificates = \"\" ]]\n\ntext \\<open>\nThe option \\<open>old_smt_read_only_certificates\\<close> controls whether only\nstored certificates are should be used or invocation of an SMT solver\nis allowed.  When set to \\<open>true\\<close>, no SMT solver will ever be\ninvoked and only the existing certificates found in the configured\ncache are used;  when set to \\<open>false\\<close> and there is no cached\ncertificate for some proposition, then the configured SMT solver is\ninvoked.\n\\<close>\n\ndeclare [[ old_smt_read_only_certificates = false ]]\n\n\n\nsubsection \\<open>Tracing\\<close>\n\ntext \\<open>\nThe SMT method, when applied, traces important information.  To\nmake it entirely silent, set the following option to \\<open>false\\<close>.\n\\<close>\n\ndeclare [[ old_smt_verbose = true ]]\n\ntext \\<open>\nFor tracing the generated problem file given to the SMT solver as\nwell as the returned result of the solver, the option\n\\<open>old_smt_trace\\<close> should be set to \\<open>true\\<close>.\n\\<close>\n\ndeclare [[ old_smt_trace = false ]]\n\ntext \\<open>\nFrom the set of assumptions given to the SMT solver, those assumptions\nused in the proof are traced when the following option is set to\n@{term true}.  This only works for Z3 when it runs in non-oracle mode\n(see options \\<open>old_smt_solver\\<close> and \\<open>old_smt_oracle\\<close> above).\n\\<close>\n\ndeclare [[ old_smt_trace_used_facts = false ]]\n\n\n\nsubsection \\<open>Schematic rules for Z3 proof reconstruction\\<close>\n\ntext \\<open>\nSeveral prof rules of Z3 are not very well documented.  There are two\nlemma groups which can turn failing Z3 proof reconstruction attempts\ninto succeeding ones: the facts in \\<open>z3_rule\\<close> are tried prior to\nany implemented reconstruction procedure for all uncertain Z3 proof\nrules;  the facts in \\<open>z3_simp\\<close> are only fed to invocations of\nthe simplifier when reconstructing theory-specific proof steps.\n\\<close>\n\nlemmas [old_z3_rule] =\n  refl eq_commute conj_commute disj_commute simp_thms nnf_simps\n  ring_distribs field_simps times_divide_eq_right times_divide_eq_left\n  if_True if_False not_not\n\nlemma [old_z3_rule]:\n  \"(P \\<and> Q) = (\\<not>(\\<not>P \\<or> \\<not>Q))\"\n  \"(P \\<and> Q) = (\\<not>(\\<not>Q \\<or> \\<not>P))\"\n  \"(\\<not>P \\<and> Q) = (\\<not>(P \\<or> \\<not>Q))\"\n  \"(\\<not>P \\<and> Q) = (\\<not>(\\<not>Q \\<or> P))\"\n  \"(P \\<and> \\<not>Q) = (\\<not>(\\<not>P \\<or> Q))\"\n  \"(P \\<and> \\<not>Q) = (\\<not>(Q \\<or> \\<not>P))\"\n  \"(\\<not>P \\<and> \\<not>Q) = (\\<not>(P \\<or> Q))\"\n  \"(\\<not>P \\<and> \\<not>Q) = (\\<not>(Q \\<or> P))\"\n  by auto\n\nlemma [old_z3_rule]:\n  \"(P \\<longrightarrow> Q) = (Q \\<or> \\<not>P)\"\n  \"(\\<not>P \\<longrightarrow> Q) = (P \\<or> Q)\"\n  \"(\\<not>P \\<longrightarrow> Q) = (Q \\<or> P)\"\n  \"(True \\<longrightarrow> P) = P\"\n  \"(P \\<longrightarrow> True) = True\"\n  \"(False \\<longrightarrow> P) = True\"\n  \"(P \\<longrightarrow> P) = True\"\n  by auto\n\nlemma [old_z3_rule]:\n  \"((P = Q) \\<longrightarrow> R) = (R | (Q = (\\<not>P)))\"\n  by auto\n\nlemma [old_z3_rule]:\n  \"(\\<not>True) = False\"\n  \"(\\<not>False) = True\"\n  \"(x = x) = True\"\n  \"(P = True) = P\"\n  \"(True = P) = P\"\n  \"(P = False) = (\\<not>P)\"\n  \"(False = P) = (\\<not>P)\"\n  \"((\\<not>P) = P) = False\"\n  \"(P = (\\<not>P)) = False\"\n  \"((\\<not>P) = (\\<not>Q)) = (P = Q)\"\n  \"\\<not>(P = (\\<not>Q)) = (P = Q)\"\n  \"\\<not>((\\<not>P) = Q) = (P = Q)\"\n  \"(P \\<noteq> Q) = (Q = (\\<not>P))\"\n  \"(P = Q) = ((\\<not>P \\<or> Q) \\<and> (P \\<or> \\<not>Q))\"\n  \"(P \\<noteq> Q) = ((\\<not>P \\<or> \\<not>Q) \\<and> (P \\<or> Q))\"\n  by auto\n\nlemma [old_z3_rule]:\n  \"(if P then P else \\<not>P) = True\"\n  \"(if \\<not>P then \\<not>P else P) = True\"\n  \"(if P then True else False) = P\"\n  \"(if P then False else True) = (\\<not>P)\"\n  \"(if P then Q else True) = ((\\<not>P) \\<or> Q)\"\n  \"(if P then Q else True) = (Q \\<or> (\\<not>P))\"\n  \"(if P then Q else \\<not>Q) = (P = Q)\"\n  \"(if P then Q else \\<not>Q) = (Q = P)\"\n  \"(if P then \\<not>Q else Q) = (P = (\\<not>Q))\"\n  \"(if P then \\<not>Q else Q) = ((\\<not>Q) = P)\"\n  \"(if \\<not>P then x else y) = (if P then y else x)\"\n  \"(if P then (if Q then x else y) else x) = (if P \\<and> (\\<not>Q) then y else x)\"\n  \"(if P then (if Q then x else y) else x) = (if (\\<not>Q) \\<and> P then y else x)\"\n  \"(if P then (if Q then x else y) else y) = (if P \\<and> Q then x else y)\"\n  \"(if P then (if Q then x else y) else y) = (if Q \\<and> P then x else y)\"\n  \"(if P then x else if P then y else z) = (if P then x else z)\"\n  \"(if P then x else if Q then x else y) = (if P \\<or> Q then x else y)\"\n  \"(if P then x else if Q then x else y) = (if Q \\<or> P then x else y)\"\n  \"(if P then x = y else x = z) = (x = (if P then y else z))\"\n  \"(if P then x = y else y = z) = (y = (if P then x else z))\"\n  \"(if P then x = y else z = y) = (y = (if P then x else z))\"\n  by auto\n\nlemma [old_z3_rule]:\n  \"0 + (x::int) = x\"\n  \"x + 0 = x\"\n  \"x + x = 2 * x\"\n  \"0 * x = 0\"\n  \"1 * x = x\"\n  \"x + y = y + x\"\n  by auto\n\nlemma [old_z3_rule]:  (* for def-axiom *)\n  \"P = Q \\<or> P \\<or> Q\"\n  \"P = Q \\<or> \\<not>P \\<or> \\<not>Q\"\n  \"(\\<not>P) = Q \\<or> \\<not>P \\<or> Q\"\n  \"(\\<not>P) = Q \\<or> P \\<or> \\<not>Q\"\n  \"P = (\\<not>Q) \\<or> \\<not>P \\<or> Q\"\n  \"P = (\\<not>Q) \\<or> P \\<or> \\<not>Q\"\n  \"P \\<noteq> Q \\<or> P \\<or> \\<not>Q\"\n  \"P \\<noteq> Q \\<or> \\<not>P \\<or> Q\"\n  \"P \\<noteq> (\\<not>Q) \\<or> P \\<or> Q\"\n  \"(\\<not>P) \\<noteq> Q \\<or> P \\<or> Q\"\n  \"P \\<or> Q \\<or> P \\<noteq> (\\<not>Q)\"\n  \"P \\<or> Q \\<or> (\\<not>P) \\<noteq> Q\"\n  \"P \\<or> \\<not>Q \\<or> P \\<noteq> Q\"\n  \"\\<not>P \\<or> Q \\<or> P \\<noteq> Q\"\n  \"P \\<or> y = (if P then x else y)\"\n  \"P \\<or> (if P then x else y) = y\"\n  \"\\<not>P \\<or> x = (if P then x else y)\"\n  \"\\<not>P \\<or>  (if P then x else y) = x\"\n  \"P \\<or> R \\<or> \\<not>(if P then Q else R)\"\n  \"\\<not>P \\<or> Q \\<or> \\<not>(if P then Q else R)\"\n  \"\\<not>(if P then Q else R) \\<or> \\<not>P \\<or> Q\"\n  \"\\<not>(if P then Q else R) \\<or> P \\<or> R\"\n  \"(if P then Q else R) \\<or> \\<not>P \\<or> \\<not>Q\"\n  \"(if P then Q else R) \\<or> P \\<or> \\<not>R\"\n  \"(if P then \\<not>Q else R) \\<or> \\<not>P \\<or> Q\"\n  \"(if P then Q else \\<not>R) \\<or> P \\<or> R\"\n  by auto\n\nML_file \"Old_SMT/old_smt_real.ML\"\nML_file \"Old_SMT/old_smt_word.ML\"\n\nhide_type (open) pattern\nhide_const fun_app term_true term_false z3div z3mod\nhide_const (open) trigger pat nopat weight\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/HOL/Library/Old_SMT.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736783928749127, "lm_q2_score": 0.45713671682749485, "lm_q1q2_score": 0.26224945703371133}}
{"text": "(*  Title:      HOL/MicroJava/Comp/TranslCompTp.thy\n    Author:     Martin Strecker\n*)\n\ntheory TranslCompTp\nimports Index \"../BV/JVMType\"\nbegin\n\n(**********************************************************************)\n\ndefinition comb :: \"['a \\<Rightarrow> 'b list \\<times> 'c, 'c \\<Rightarrow> 'b list \\<times> 'd, 'a] \\<Rightarrow> 'b list \\<times> 'd\" where \n  \"comb == (\\<lambda> f1 f2 x0. let (xs1, x1) = f1 x0; \n                            (xs2, x2) = f2 x1 \n                        in  (xs1 @ xs2, x2))\"\n\ndefinition comb_nil :: \"'a \\<Rightarrow> 'b list \\<times> 'a\" where\n  \"comb_nil a == ([], a)\"\n\nnotation (xsymbols)\n  comb  (infixr \"\\<box>\" 55)\n\nlemma comb_nil_left [simp]: \"comb_nil \\<box> f = f\"\nby (simp add: comb_def comb_nil_def split_beta)\n\nlemma comb_nil_right [simp]: \"f \\<box> comb_nil = f\"\nby (simp add: comb_def comb_nil_def split_beta)\n\nlemma comb_assoc [simp]: \"(fa \\<box> fb) \\<box> fc = fa \\<box> (fb \\<box> fc)\"\nby (simp add: comb_def split_beta)\n\nlemma comb_inv: \"(xs', x') = (f1 \\<box> f2) x0 \\<Longrightarrow>\n  \\<exists> xs1 x1 xs2 x2. (xs1, x1) = (f1 x0) \\<and> (xs2, x2) = f2 x1 \\<and> xs'= xs1 @ xs2 \\<and> x'=x2\"\napply (case_tac \"f1 x0\")\napply (case_tac \"f2 x1\")\napply (simp add: comb_def split_beta)\ndone\n\n(**********************************************************************)\n\nabbreviation (input)\n  mt_of :: \"method_type \\<times> state_type \\<Rightarrow> method_type\"\n  where \"mt_of == fst\"\n\nabbreviation (input)\n  sttp_of :: \"method_type \\<times> state_type \\<Rightarrow> state_type\"\n  where \"sttp_of == snd\"\n\ndefinition nochangeST :: \"state_type \\<Rightarrow> method_type \\<times> state_type\" where\n  \"nochangeST sttp == ([Some sttp], sttp)\"\n\ndefinition pushST :: \"[ty list, state_type] \\<Rightarrow> method_type \\<times> state_type\" where\n  \"pushST tps == (\\<lambda> (ST, LT). ([Some (ST, LT)], (tps @ ST, LT)))\"\n\ndefinition dupST :: \"state_type \\<Rightarrow> method_type \\<times> state_type\" where\n  \"dupST == (\\<lambda> (ST, LT). ([Some (ST, LT)], (hd ST # ST, LT)))\"\n\ndefinition dup_x1ST :: \"state_type \\<Rightarrow> method_type \\<times> state_type\" where\n  \"dup_x1ST == (\\<lambda> (ST, LT). ([Some (ST, LT)], \n                             (hd ST # hd (tl ST) # hd ST # (tl (tl ST)), LT)))\"\n\ndefinition popST :: \"[nat, state_type] \\<Rightarrow> method_type \\<times> state_type\" where\n  \"popST n == (\\<lambda> (ST, LT). ([Some (ST, LT)], (drop n ST, LT)))\"\n\ndefinition replST :: \"[nat, ty, state_type] \\<Rightarrow> method_type \\<times> state_type\" where\n  \"replST n tp == (\\<lambda> (ST, LT). ([Some (ST, LT)], (tp # (drop n ST), LT)))\"\n\ndefinition storeST :: \"[nat, ty, state_type] \\<Rightarrow> method_type \\<times> state_type\" where\n  \"storeST i tp == (\\<lambda> (ST, LT). ([Some (ST, LT)], (tl ST, LT [i:= OK tp])))\"\n\n\n(* Expressions *)\n\nprimrec compTpExpr :: \"java_mb \\<Rightarrow> java_mb prog \\<Rightarrow> expr \\<Rightarrow>\n    state_type \\<Rightarrow> method_type \\<times> state_type\"\n  and compTpExprs :: \"java_mb \\<Rightarrow> java_mb prog \\<Rightarrow> expr list \\<Rightarrow>\n    state_type \\<Rightarrow> method_type \\<times> state_type\"\nwhere\n  \"compTpExpr jmb G (NewC c) = pushST [Class c]\"\n| \"compTpExpr jmb G (Cast c e) = (compTpExpr jmb G e) \\<box> (replST 1 (Class c))\"\n| \"compTpExpr jmb G (Lit val) = pushST [the (typeof (\\<lambda>v. None) val)]\"\n| \"compTpExpr jmb G (BinOp bo e1 e2) =\n     (compTpExpr jmb G e1) \\<box> (compTpExpr jmb G e2) \\<box> \n     (case bo of \n       Eq => popST 2 \\<box> pushST [PrimT Boolean] \\<box> popST 1 \\<box> pushST [PrimT Boolean]\n     | Add => replST 2 (PrimT Integer))\"\n| \"compTpExpr jmb G (LAcc vn) = (\\<lambda> (ST, LT). \n      pushST [ok_val (LT ! (index jmb vn))] (ST, LT))\"\n| \"compTpExpr jmb G (vn::=e) = \n      (compTpExpr jmb G e) \\<box> dupST \\<box> (popST 1)\"\n| \"compTpExpr jmb G ( {cn}e..fn ) = \n      (compTpExpr jmb G e) \\<box> replST 1 (snd (the (field (G,cn) fn)))\"\n| \"compTpExpr jmb G (FAss cn e1 fn e2 ) = \n      (compTpExpr jmb G e1) \\<box> (compTpExpr jmb G e2) \\<box> dup_x1ST \\<box> (popST 2)\"\n| \"compTpExpr jmb G ({C}a..mn({fpTs}ps)) =\n       (compTpExpr jmb G a) \\<box> (compTpExprs jmb G ps) \\<box> \n       (replST ((length ps) + 1) (method_rT (the (method (G,C) (mn,fpTs)))))\"\n| \"compTpExprs jmb G [] = comb_nil\"\n| \"compTpExprs jmb G (e#es) = (compTpExpr jmb G e) \\<box> (compTpExprs jmb G es)\"\n\n\n(* Statements *)\nprimrec compTpStmt :: \"java_mb \\<Rightarrow> java_mb prog \\<Rightarrow> stmt \\<Rightarrow> \n    state_type \\<Rightarrow> method_type \\<times> state_type\"\nwhere\n  \"compTpStmt jmb G Skip = comb_nil\"\n| \"compTpStmt jmb G (Expr e) =  (compTpExpr jmb G e) \\<box> popST 1\"\n| \"compTpStmt jmb G (c1;; c2) = (compTpStmt jmb G c1) \\<box> (compTpStmt jmb G c2)\"\n| \"compTpStmt jmb G (If(e) c1 Else c2) = \n      (pushST [PrimT Boolean]) \\<box> (compTpExpr jmb G e) \\<box> popST 2 \\<box>\n      (compTpStmt jmb G c1) \\<box> nochangeST \\<box> (compTpStmt jmb G c2)\"\n| \"compTpStmt jmb G (While(e) c) = \n      (pushST [PrimT Boolean]) \\<box> (compTpExpr jmb G e) \\<box> popST 2 \\<box>\n      (compTpStmt jmb G c) \\<box> nochangeST\"\n\ndefinition compTpInit :: \"java_mb \\<Rightarrow> (vname * ty)\n                   \\<Rightarrow> state_type \\<Rightarrow> method_type \\<times> state_type\" where\n  \"compTpInit jmb == (\\<lambda> (vn,ty). (pushST [ty]) \\<box>  (storeST (index jmb vn) ty))\"\n\nprimrec compTpInitLvars :: \"[java_mb, (vname \\<times> ty) list] \\<Rightarrow>\n    state_type \\<Rightarrow> method_type \\<times> state_type\"\nwhere\n  \"compTpInitLvars jmb [] = comb_nil\"\n| \"compTpInitLvars jmb (lv#lvars) = (compTpInit jmb lv) \\<box> (compTpInitLvars jmb lvars)\"\n\ndefinition start_ST :: \"opstack_type\" where\n  \"start_ST == []\"\n\ndefinition start_LT :: \"cname \\<Rightarrow> ty list \\<Rightarrow> nat \\<Rightarrow> locvars_type\" where\n  \"start_LT C pTs n ==  (OK (Class C))#((map OK pTs))@(replicate n Err)\"\n\ndefinition compTpMethod  :: \"[java_mb prog, cname, java_mb mdecl] \\<Rightarrow> method_type\" where\n  \"compTpMethod G C == \\<lambda> ((mn,pTs),rT, jmb). \n                         let (pns,lvars,blk,res) = jmb\n                         in (mt_of\n                            ((compTpInitLvars jmb lvars \\<box> \n                              compTpStmt jmb G blk \\<box> \n                              compTpExpr jmb G res \\<box>\n                              nochangeST)\n                                (start_ST, start_LT C pTs (length lvars))))\"\n\ndefinition compTp :: \"java_mb prog => prog_type\" where\n  \"compTp G C sig == let (D, rT, jmb) = (the (method (G, C) sig))\n                      in compTpMethod G C (sig, rT, jmb)\"\n\n\n\n(**********************************************************************)\n  (* Computing the maximum stack size from the method_type *)\n\ndefinition ssize_sto :: \"(state_type option) \\<Rightarrow> nat\" where\n  \"ssize_sto sto ==  case sto of None \\<Rightarrow> 0 | (Some (ST, LT)) \\<Rightarrow> length ST\"\n\ndefinition max_of_list :: \"nat list \\<Rightarrow> nat\" where\n  \"max_of_list xs == foldr max xs 0\"\n\ndefinition max_ssize :: \"method_type \\<Rightarrow> nat\" where\n  \"max_ssize mt == max_of_list (map ssize_sto mt)\"\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/MicroJava/Comp/TranslCompTp.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6150878696277513, "lm_q2_score": 0.4263215925474903, "lm_q1q2_score": 0.262225240136346}}
{"text": "(*  Title:      JinjaDCI/BV/BVConform.thy\n\n    Author:     Cornelia Pusch, Gerwin Klein, Susannah Mansky\n    Copyright   1999 Technische Universitaet Muenchen, 2019-20 UIUC\n\n    Based on the Jinja theory BV/BVConform.thy by Cornelia Pusch and Gerwin Klein\n\nThe invariant for the type safety proof.\n*)\n\nsection \\<open> BV Type Safety Invariant \\<close>\n\ntheory BVConform\nimports BVSpec \"../JVM/JVMExec\" \"../Common/Conform\"\nbegin\n\nsubsection \\<open> @{text \"correct_state\"} definitions \\<close>\n\ndefinition confT :: \"'c prog \\<Rightarrow> heap \\<Rightarrow> val \\<Rightarrow> ty err \\<Rightarrow> bool\" \n    (\"_,_ \\<turnstile> _ :\\<le>\\<^sub>\\<top> _\" [51,51,51,51] 50)\nwhere\n  \"P,h \\<turnstile> v :\\<le>\\<^sub>\\<top> E \\<equiv> case E of Err \\<Rightarrow> True | OK T \\<Rightarrow> P,h \\<turnstile> v :\\<le> T\"\n\nnotation (ASCII)\n  confT  (\"_,_ |- _ :<=T _\" [51,51,51,51] 50)\n\nabbreviation\n  confTs :: \"'c prog \\<Rightarrow> heap \\<Rightarrow> val list \\<Rightarrow> ty\\<^sub>l \\<Rightarrow> bool\" \n      (\"_,_ \\<turnstile> _ [:\\<le>\\<^sub>\\<top>] _\" [51,51,51,51] 50) where\n  \"P,h \\<turnstile> vs [:\\<le>\\<^sub>\\<top>] Ts \\<equiv> list_all2 (confT P h) vs Ts\"\n\nnotation (ASCII)\n  confTs  (\"_,_ |- _ [:<=T] _\" [51,51,51,51] 50)\n\nfun Called_context :: \"jvm_prog \\<Rightarrow> cname \\<Rightarrow> instr \\<Rightarrow> bool\" where\n\"Called_context P C\\<^sub>0 (New C') = (C\\<^sub>0=C')\" |\n\"Called_context P C\\<^sub>0 (Getstatic C F D) =  ((C\\<^sub>0=D) \\<and> (\\<exists>t. P \\<turnstile> C has F,Static:t in D))\" |\n\"Called_context P C\\<^sub>0 (Putstatic C F D) = ((C\\<^sub>0=D) \\<and> (\\<exists>t. P \\<turnstile> C has F,Static:t in D))\" |\n\"Called_context P C\\<^sub>0 (Invokestatic C M n)\n   = (\\<exists>Ts T m D. (C\\<^sub>0=D) \\<and> P \\<turnstile> C sees M,Static:Ts \\<rightarrow> T = m in D)\" |\n\"Called_context P _ _ = False\"\n\nabbreviation Called_set :: \"instr set\" where\n\"Called_set \\<equiv> {i. \\<exists>C. i = New C} \\<union> {i. \\<exists>C M n. i = Invokestatic C M n}\n                 \\<union> {i. \\<exists>C F D. i = Getstatic C F D} \\<union> {i. \\<exists>C F D. i = Putstatic C F D}\"\n\nlemma Called_context_Called_set:\n \"Called_context P D i \\<Longrightarrow> i \\<in> Called_set\" by(cases i, auto)\n\nfun valid_ics :: \"jvm_prog \\<Rightarrow> heap \\<Rightarrow> sheap \\<Rightarrow> cname \\<times> mname \\<times> pc \\<times> init_call_status \\<Rightarrow> bool\"\n  (\"_,_,_ \\<turnstile>\\<^sub>i _\" [51,51,51,51] 50) where\n\"valid_ics P h sh (C,M,pc,Calling C' Cs)\n = (let ins = instrs_of P C M in Called_context P (last (C'#Cs)) (ins!pc)\n    \\<and> is_class P C')\" |\n\"valid_ics P h sh (C,M,pc,Throwing Cs a)\n =(let ins = instrs_of P C M in \\<exists>C1. Called_context P C1 (ins!pc)\n    \\<and> (\\<exists>obj. h a = Some obj))\" |\n\"valid_ics P h sh (C,M,pc,Called Cs)\n = (let ins = instrs_of P C M\n    in \\<exists>C1 sobj. Called_context P C1 (ins!pc) \\<and> sh C1 = Some sobj)\" |\n\"valid_ics P _ _ _ = True\"\n\ndefinition conf_f  :: \"jvm_prog \\<Rightarrow> heap \\<Rightarrow> sheap \\<Rightarrow> ty\\<^sub>i \\<Rightarrow> bytecode \\<Rightarrow> frame \\<Rightarrow> bool\"\nwhere\n  \"conf_f P h sh \\<equiv> \\<lambda>(ST,LT) is (stk,loc,C,M,pc,ics).\n  P,h \\<turnstile> stk [:\\<le>] ST \\<and> P,h \\<turnstile> loc [:\\<le>\\<^sub>\\<top>] LT \\<and> pc < size is \\<and> P,h,sh \\<turnstile>\\<^sub>i (C,M,pc,ics)\"\n\nlemma conf_f_def2:\n  \"conf_f P h sh (ST,LT) is (stk,loc,C,M,pc,ics) \\<equiv>\n  P,h \\<turnstile> stk [:\\<le>] ST \\<and> P,h \\<turnstile> loc [:\\<le>\\<^sub>\\<top>] LT \\<and> pc < size is \\<and> P,h,sh \\<turnstile>\\<^sub>i (C,M,pc,ics)\"\n  by (simp add: conf_f_def)\n\nprimrec conf_fs :: \"[jvm_prog,heap,sheap,ty\\<^sub>P,cname,mname,nat,ty,frame list] \\<Rightarrow> bool\"\nwhere\n  \"conf_fs P h sh \\<Phi> C\\<^sub>0 M\\<^sub>0 n\\<^sub>0 T\\<^sub>0 [] = True\"\n| \"conf_fs P h sh \\<Phi> C\\<^sub>0 M\\<^sub>0 n\\<^sub>0 T\\<^sub>0 (f#frs) =\n  (let (stk,loc,C,M,pc,ics) = f in\n  (\\<exists>ST LT b Ts T mxs mxl\\<^sub>0 is xt.\n    \\<Phi> C M ! pc = Some (ST,LT) \\<and> \n    (P \\<turnstile> C sees M,b:Ts \\<rightarrow> T = (mxs,mxl\\<^sub>0,is,xt) in C) \\<and>\n    ((\\<exists>D Ts' T' m D'. M\\<^sub>0 \\<noteq> clinit \\<and> ics = No_ics \\<and>\n       is!pc = Invoke M\\<^sub>0 n\\<^sub>0 \\<and> ST!n\\<^sub>0 = Class D \\<and>\n       P \\<turnstile> D sees M\\<^sub>0,NonStatic:Ts' \\<rightarrow> T' = m in D' \\<and> P \\<turnstile> C\\<^sub>0 \\<preceq>\\<^sup>* D' \\<and> P \\<turnstile> T\\<^sub>0 \\<le> T') \\<or>\n     (\\<exists>D Ts' T' m. M\\<^sub>0 \\<noteq> clinit \\<and> ics = No_ics \\<and>\n       is!pc = Invokestatic D M\\<^sub>0 n\\<^sub>0 \\<and>\n       P \\<turnstile> D sees M\\<^sub>0,Static:Ts' \\<rightarrow> T' = m in C\\<^sub>0 \\<and> P \\<turnstile> T\\<^sub>0 \\<le> T') \\<or>\n     (M\\<^sub>0 = clinit \\<and> (\\<exists>Cs. ics = Called Cs))) \\<and>\n    conf_f P h sh (ST, LT) is f \\<and> conf_fs P h sh \\<Phi> C M (size Ts) T frs))\"\n\nfun ics_classes :: \"init_call_status \\<Rightarrow> cname list\" where\n\"ics_classes (Calling C Cs) = Cs\" |\n\"ics_classes (Throwing Cs a) = Cs\" |\n\"ics_classes (Called Cs) = Cs\" |\n\"ics_classes _ = []\"\n\nfun frame_clinit_classes :: \"frame \\<Rightarrow> cname list\" where\n\"frame_clinit_classes (stk,loc,C,M,pc,ics) = (if M=clinit then [C] else []) @ ics_classes ics\"\n\nabbreviation clinit_classes :: \"frame list \\<Rightarrow> cname list\" where\n\"clinit_classes frs \\<equiv> concat (map frame_clinit_classes frs)\"\n\ndefinition distinct_clinit :: \"frame list \\<Rightarrow> bool\" where\n\"distinct_clinit frs \\<equiv> distinct (clinit_classes frs)\"\n\ndefinition conf_clinit :: \"jvm_prog \\<Rightarrow> sheap \\<Rightarrow> frame list \\<Rightarrow> bool\" where\n\"conf_clinit P sh frs\n   \\<equiv> distinct_clinit frs \\<and>\n      (\\<forall>C \\<in> set(clinit_classes frs). is_class P C \\<and> (\\<exists>sfs. sh C = Some(sfs, Processing)))\"\n\n(*************************)\n\ndefinition correct_state :: \"[jvm_prog,ty\\<^sub>P,jvm_state] \\<Rightarrow> bool\"  (\"_,_ \\<turnstile> _ \\<surd>\"  [61,0,0] 61)\nwhere\n  \"correct_state P \\<Phi> \\<equiv> \\<lambda>(xp,h,frs,sh).\n  case xp of\n     None \\<Rightarrow> (case frs of\n             [] \\<Rightarrow> True\n             | (f#fs) \\<Rightarrow> P\\<turnstile> h\\<surd> \\<and> P,h\\<turnstile>\\<^sub>s sh\\<surd> \\<and> conf_clinit P sh frs \\<and>\n             (let (stk,loc,C,M,pc,ics) = f\n              in \\<exists>b Ts T mxs mxl\\<^sub>0 is xt \\<tau>.\n                    (P \\<turnstile> C sees M,b:Ts\\<rightarrow>T = (mxs,mxl\\<^sub>0,is,xt) in C) \\<and>\n                    \\<Phi> C M ! pc = Some \\<tau> \\<and>\n                    conf_f P h sh \\<tau> is f \\<and> conf_fs P h sh \\<Phi> C M (size Ts) T fs))\n  | Some x \\<Rightarrow> frs = []\" \n\nnotation\n  correct_state  (\"_,_ |- _ [ok]\"  [61,0,0] 61)\n\nsubsection \\<open> Values and @{text \"\\<top>\"} \\<close>\n\nlemma confT_Err [iff]: \"P,h \\<turnstile> x :\\<le>\\<^sub>\\<top> Err\" \n  by (simp add: confT_def)\n\nlemma confT_OK [iff]:  \"P,h \\<turnstile> x :\\<le>\\<^sub>\\<top> OK T = (P,h \\<turnstile> x :\\<le> T)\"\n  by (simp add: confT_def)\n\nlemma confT_cases:\n  \"P,h \\<turnstile> x :\\<le>\\<^sub>\\<top> X = (X = Err \\<or> (\\<exists>T. X = OK T \\<and> P,h \\<turnstile> x :\\<le> T))\"\n  by (cases X) auto\n\nlemma confT_hext [intro?, trans]:\n  \"\\<lbrakk> P,h \\<turnstile> x :\\<le>\\<^sub>\\<top> T; h \\<unlhd> h' \\<rbrakk> \\<Longrightarrow> P,h' \\<turnstile> x :\\<le>\\<^sub>\\<top> T\"\n  by (cases T) (blast intro: conf_hext)+\n\nlemma confT_widen [intro?, trans]:\n  \"\\<lbrakk> P,h \\<turnstile> x :\\<le>\\<^sub>\\<top> T; P \\<turnstile> T \\<le>\\<^sub>\\<top> T' \\<rbrakk> \\<Longrightarrow> P,h \\<turnstile> x :\\<le>\\<^sub>\\<top> T'\"\n  by (cases T', auto intro: conf_widen)\n\n\nsubsection \\<open> Stack and Registers \\<close>\n\nlemmas confTs_Cons1 [iff] = list_all2_Cons1 [of \"confT P h\"] for P h\n\nlemma confTs_confT_sup:\nassumes confTs: \"P,h \\<turnstile> loc [:\\<le>\\<^sub>\\<top>] LT\" and n: \"n < size LT\" and\n      LTn: \"LT!n = OK T\" and subtype: \"P \\<turnstile> T \\<le> T'\"\nshows \"P,h \\<turnstile> (loc!n) :\\<le> T'\"\n(*<*)\nproof -\n  have len: \"n < length loc\" using list_all2_lengthD[OF confTs] n\n    by simp\n  show ?thesis\n   using list_all2_nthD[OF confTs len] conf_widen[OF _ subtype] LTn\n    by simp\nqed\n(*>*)\n\nlemma confTs_hext [intro?]:\n  \"P,h \\<turnstile> loc [:\\<le>\\<^sub>\\<top>] LT \\<Longrightarrow> h \\<unlhd> h' \\<Longrightarrow> P,h' \\<turnstile> loc [:\\<le>\\<^sub>\\<top>] LT\"\n  by (fast elim: list_all2_mono confT_hext)    \n\nlemma confTs_widen [intro?, trans]:\n  \"P,h \\<turnstile> loc [:\\<le>\\<^sub>\\<top>] LT \\<Longrightarrow> P \\<turnstile> LT [\\<le>\\<^sub>\\<top>] LT' \\<Longrightarrow> P,h \\<turnstile> loc [:\\<le>\\<^sub>\\<top>] LT'\"\n  by (rule list_all2_trans, rule confT_widen)\n\nlemma confTs_map [iff]:\n  \"\\<And>vs. (P,h \\<turnstile> vs [:\\<le>\\<^sub>\\<top>] map OK Ts) = (P,h \\<turnstile> vs [:\\<le>] Ts)\"\n  by (induct Ts) (auto simp: list_all2_Cons2)\n\nlemma reg_widen_Err [iff]:\n  \"\\<And>LT. (P \\<turnstile> replicate n Err [\\<le>\\<^sub>\\<top>] LT) = (LT = replicate n Err)\"\n  by (induct n) (auto simp: list_all2_Cons1)\n    \n\n\nsubsection \\<open> valid @{text \"init_call_status\"} \\<close>\n\nlemma valid_ics_shupd:\nassumes \"P,h,sh \\<turnstile>\\<^sub>i (C, M, pc, ics)\" and \"distinct (C'#ics_classes ics)\"\nshows \"P,h,sh(C' \\<mapsto> (sfs, i')) \\<turnstile>\\<^sub>i (C, M, pc, ics)\"\nusing assms by(cases ics; clarsimp simp: fun_upd_apply) fastforce\n  \nsubsection \\<open> correct-frame \\<close>\n\nlemma conf_f_Throwing:\nassumes \"conf_f P h sh (ST, LT) is (stk, loc, C, M, pc, Called Cs)\"\n  and \"is_class P C'\" and \"h xcp = Some obj\" and \"sh C' = Some(sfs,Processing)\"\nshows \"conf_f P h sh (ST, LT) is (stk, loc, C, M, pc, Throwing (C' # Cs) xcp)\"\nusing assms by(auto simp: conf_f_def2)\n\nlemma conf_f_shupd:\nassumes \"conf_f P h sh (ST,LT) ins f\"\n and \"i = Processing\n       \\<or> (distinct (C#ics_classes (ics_of f)) \\<and> (curr_method f = clinit \\<longrightarrow> C \\<noteq> curr_class f))\"\nshows \"conf_f P h (sh(C \\<mapsto> (sfs, i))) (ST,LT) ins f\"\nusing assms\n by(cases f, cases \"ics_of f\"; clarsimp simp: conf_f_def2 fun_upd_apply) fastforce+\n\nlemma conf_f_shupd':\nassumes \"conf_f P h sh (ST,LT) ins f\"\n and \"sh C = Some(sfs,i)\"\nshows \"conf_f P h (sh(C \\<mapsto> (sfs', i))) (ST,LT) ins f\"\nusing assms\n by(cases f, cases \"ics_of f\"; clarsimp simp: conf_f_def2 fun_upd_apply) fastforce+\n\nsubsection \\<open> correct-frames \\<close>\n\nlemmas [simp del] = fun_upd_apply\n\nlemma conf_fs_hext:\n  \"\\<And>C M n T\\<^sub>r. \n  \\<lbrakk> conf_fs P h sh \\<Phi> C M n T\\<^sub>r frs; h \\<unlhd> h' \\<rbrakk> \\<Longrightarrow> conf_fs P h' sh \\<Phi> C M n T\\<^sub>r frs\"\n(*<*)\nproof(induct frs)\n  case (Cons fr frs)\n  obtain stk ls C M pc ics where fr: \"fr = (stk, ls, C, M, pc, ics)\" by(cases fr) simp\n  moreover obtain ST LT where \\<Phi>: \"\\<Phi> C M ! pc = \\<lfloor>(ST, LT)\\<rfloor>\" and\n     ST: \"P,h \\<turnstile> stk [:\\<le>] ST\" and LT: \"P,h \\<turnstile> ls [:\\<le>\\<^sub>\\<top>] LT\"\n    using Cons.prems(1) fr by(auto simp: conf_f_def)\n  ultimately show ?case using Cons confs_hext[OF ST Cons(3)] confTs_hext[OF LT Cons(3)]\n    by (fastforce simp: conf_f_def)\nqed simp\n(*>*)\n\n\nlemma conf_fs_shupd:\nassumes \"conf_fs P h sh \\<Phi> C\\<^sub>0 M n T frs\"\n and dist: \"distinct (C#clinit_classes frs)\"\nshows \"conf_fs P h (sh(C \\<mapsto> (sfs, i))) \\<Phi> C\\<^sub>0 M n T frs\"\nusing assms proof(induct frs arbitrary: C\\<^sub>0 C M n T)\n  case (Cons f' frs')\n  then obtain stk' loc' C' M' pc' ics' where f': \"f' = (stk',loc',C',M',pc',ics')\" by(cases f')\n  with assms Cons obtain ST LT b Ts T1 mxs mxl\\<^sub>0 ins xt where\n    ty: \"\\<Phi> C' M' ! pc' = Some (ST,LT)\" and\n    meth: \"P \\<turnstile> C' sees M',b:Ts \\<rightarrow> T1 = (mxs,mxl\\<^sub>0,ins,xt) in C'\" and\n    conf: \"conf_f P h sh (ST, LT) ins f'\" and\n    confs: \"conf_fs P h sh \\<Phi> C' M' (size Ts) T1 frs'\" by clarsimp\n\n  from f' Cons.prems(2) have\n   \"distinct (C#ics_classes (ics_of f')) \\<and> (curr_method f' = clinit \\<longrightarrow> C \\<noteq> curr_class f')\"\n     by fastforce\n  with conf_f_shupd[where C=C, OF conf] have\n    conf': \"conf_f P h (sh(C \\<mapsto> (sfs, i))) (ST, LT) ins f'\" by simp\n\n  from Cons.prems(2) have dist': \"distinct (C # clinit_classes frs')\"\n    by(auto simp: distinct_length_2_or_more)\n  from Cons.hyps[OF confs dist'] have\n    confs': \"conf_fs P h (sh(C \\<mapsto> (sfs, i))) \\<Phi> C' M' (length Ts) T1 frs'\" by simp\n\n  from conf' confs' ty meth f' Cons.prems show ?case by(fastforce dest: sees_method_fun)\nqed(simp)\n\nlemma conf_fs_shupd':\nassumes \"conf_fs P h sh \\<Phi> C\\<^sub>0 M n T frs\"\n and shC: \"sh C = Some(sfs,i)\"\nshows \"conf_fs P h (sh(C \\<mapsto> (sfs', i))) \\<Phi> C\\<^sub>0 M n T frs\"\nusing assms proof(induct frs arbitrary: C\\<^sub>0 C M n T sfs i sfs')\n  case (Cons f' frs')\n  then obtain stk' loc' C' M' pc' ics' where f': \"f' = (stk',loc',C',M',pc',ics')\" by(cases f')\n  with assms Cons obtain ST LT b Ts T1 mxs mxl\\<^sub>0 ins xt where\n    ty: \"\\<Phi> C' M' ! pc' = Some (ST,LT)\" and\n    meth: \"P \\<turnstile> C' sees M',b:Ts \\<rightarrow> T1 = (mxs,mxl\\<^sub>0,ins,xt) in C'\" and\n    conf: \"conf_f P h sh (ST, LT) ins f'\" and\n    confs: \"conf_fs P h sh \\<Phi> C' M' (size Ts) T1 frs'\" and\n    shC': \"sh C = Some(sfs,i)\" by clarsimp\n\n  have conf': \"conf_f P h (sh(C \\<mapsto> (sfs', i))) (ST, LT) ins f'\" by(rule conf_f_shupd'[OF conf shC'])\n\n  from Cons.hyps[OF confs shC'] have\n    confs': \"conf_fs P h (sh(C \\<mapsto> (sfs', i))) \\<Phi> C' M' (length Ts) T1 frs'\" by simp\n\n  from conf' confs' ty meth f' Cons.prems show ?case by(fastforce dest: sees_method_fun)\nqed(simp)\n\nsubsection \\<open> correctness wrt @{term clinit} use \\<close>\n\nlemma conf_clinit_Cons:\nassumes \"conf_clinit P sh (f#frs)\"\nshows \"conf_clinit P sh frs\"\nproof -\n  from assms have dist: \"distinct_clinit (f#frs)\"\n   by(cases \"curr_method f = clinit\", auto simp: conf_clinit_def)\n  then have dist': \"distinct_clinit frs\" by(simp add: distinct_clinit_def)\n\n  with assms show ?thesis by(cases frs; fastforce simp: conf_clinit_def)\nqed\n\nlemma conf_clinit_Cons_Cons:\n \"conf_clinit P sh (f'#f#frs) \\<Longrightarrow> conf_clinit P sh (f'#frs)\"\n by(auto simp: conf_clinit_def distinct_clinit_def)\n\nlemma conf_clinit_diff:\nassumes \"conf_clinit P sh ((stk,loc,C,M,pc,ics)#frs)\"\nshows \"conf_clinit P sh ((stk',loc',C,M,pc',ics)#frs)\"\nusing assms by(cases \"M = clinit\", simp_all add: conf_clinit_def distinct_clinit_def)\n\nlemma conf_clinit_diff':\nassumes \"conf_clinit P sh ((stk,loc,C,M,pc,ics)#frs)\"\nshows \"conf_clinit P sh ((stk',loc',C,M,pc',No_ics)#frs)\"\nusing assms by(cases \"M = clinit\", simp_all add: conf_clinit_def distinct_clinit_def)\n\nlemma conf_clinit_Called_Throwing:\n \"conf_clinit P sh ((stk', loc', C', clinit, pc', ics') # (stk, loc, C, M, pc, Called Cs) # fs)\n  \\<Longrightarrow> conf_clinit P sh ((stk, loc, C, M, pc, Throwing (C' # Cs) xcp) # fs)\"\n by(simp add: conf_clinit_def distinct_clinit_def)\n\nlemma conf_clinit_Throwing:\n \"conf_clinit P sh ((stk, loc, C, M, pc, Throwing (C'#Cs) xcp) # fs)\n  \\<Longrightarrow> conf_clinit P sh ((stk, loc, C, M, pc, Throwing Cs xcp) # fs)\"\n by(simp add: conf_clinit_def distinct_clinit_def)\n\nlemma conf_clinit_Called:\n \"\\<lbrakk> conf_clinit P sh ((stk, loc, C, M, pc, Called (C'#Cs)) # frs);\n    P \\<turnstile> C' sees clinit,Static: [] \\<rightarrow> Void=(mxs',mxl',ins',xt') in C' \\<rbrakk>\n  \\<Longrightarrow> conf_clinit P sh (create_init_frame P C' # (stk, loc, C, M, pc, Called Cs) # frs)\"\n by(simp add: conf_clinit_def distinct_clinit_def)\n\nlemma conf_clinit_Cons_nclinit:\nassumes \"conf_clinit P sh frs\" and nclinit: \"M \\<noteq> clinit\"\nshows \"conf_clinit P sh ((stk, loc, C, M, pc, No_ics) # frs)\"\nproof -\n  from nclinit\n  have \"clinit_classes ((stk, loc, C, M, pc, No_ics) # frs) = clinit_classes frs\" by simp\n  with assms show ?thesis by(simp add: conf_clinit_def distinct_clinit_def)\nqed\n\nlemma conf_clinit_Invoke:\nassumes \"conf_clinit P sh ((stk, loc, C, M, pc, ics) # frs)\" and \"M' \\<noteq> clinit\"\nshows \"conf_clinit P sh ((stk', loc', C', M', pc', No_ics) # (stk, loc, C, M, pc, No_ics) # frs)\"\n using assms conf_clinit_Cons_nclinit conf_clinit_diff' by auto\n\nlemma conf_clinit_nProc_dist:\nassumes \"conf_clinit P sh frs\"\n  and \"\\<forall>sfs. sh C \\<noteq> Some(sfs,Processing)\"\nshows \"distinct (C # clinit_classes frs)\"\nusing assms by(auto simp: conf_clinit_def distinct_clinit_def)\n\n\nlemma conf_clinit_shupd:\nassumes \"conf_clinit P sh frs\"\n and dist: \"distinct (C#clinit_classes frs)\"\nshows \"conf_clinit P (sh(C \\<mapsto> (sfs, i))) frs\"\nusing assms by(simp add: conf_clinit_def fun_upd_apply)\n\nlemma conf_clinit_shupd':\nassumes \"conf_clinit P sh frs\"\n and \"sh C = Some(sfs,i)\"\nshows \"conf_clinit P (sh(C \\<mapsto> (sfs', i))) frs\"\nusing assms by(fastforce simp: conf_clinit_def fun_upd_apply)\n\nlemma conf_clinit_shupd_Called:\nassumes \"conf_clinit P sh ((stk,loc,C,M,pc,Calling C' Cs)#frs)\"\n and dist: \"distinct (C'#clinit_classes ((stk,loc,C,M,pc,Calling C' Cs)#frs))\"\n and cls: \"is_class P C'\"\nshows \"conf_clinit P (sh(C' \\<mapsto> (sfs, Processing))) ((stk,loc,C,M,pc,Called (C'#Cs))#frs)\"\nusing assms by(clarsimp simp: conf_clinit_def fun_upd_apply distinct_clinit_def)\n\nlemma conf_clinit_shupd_Calling:\nassumes \"conf_clinit P sh ((stk,loc,C,M,pc,Calling C' Cs)#frs)\"\n and dist: \"distinct (C'#clinit_classes ((stk,loc,C,M,pc,Calling C' Cs)#frs))\"\n and cls: \"is_class P C'\"\nshows \"conf_clinit P (sh(C' \\<mapsto> (sfs, Processing)))\n         ((stk,loc,C,M,pc,Calling (fst(the(class P C'))) (C'#Cs))#frs)\"\nusing assms by(clarsimp simp: conf_clinit_def fun_upd_apply distinct_clinit_def)\n\nsubsection \\<open> correct state \\<close>\n\nlemma correct_state_Cons:\nassumes cr: \"P,\\<Phi> |- (xp,h,f#frs,sh) [ok]\"\nshows \"P,\\<Phi> |- (xp,h,frs,sh) [ok]\"\nproof -\n  from cr have dist: \"conf_clinit P sh (f#frs)\"\n   by(simp add: correct_state_def)\n  then have \"conf_clinit P sh frs\" by(rule conf_clinit_Cons)\n\n  with cr show ?thesis by(cases frs; fastforce simp: correct_state_def)\nqed\n\nlemma correct_state_shupd:\nassumes cs: \"P,\\<Phi> |- (xp,h,frs,sh) [ok]\" and shC: \"sh C = Some(sfs,i)\"\n and dist: \"distinct (C#clinit_classes frs)\"\nshows \"P,\\<Phi> |- (xp,h,frs,sh(C \\<mapsto> (sfs, i'))) [ok]\"\nusing assms\nproof(cases xp)\n  case None with assms show ?thesis\n  proof(cases frs)\n    case (Cons f' frs')\n    let ?sh = \"sh(C \\<mapsto> (sfs, i'))\"\n\n    obtain stk' loc' C' M' pc' ics' where f': \"f' = (stk',loc',C',M',pc',ics')\" by(cases f')\n    with cs Cons None obtain b Ts T mxs mxl\\<^sub>0 ins xt ST LT where\n         meth: \"P \\<turnstile> C' sees M',b:Ts\\<rightarrow>T = (mxs,mxl\\<^sub>0,ins,xt) in C'\"\n     and ty: \"\\<Phi> C' M' ! pc' = Some (ST,LT)\" and conf: \"conf_f P h sh (ST,LT) ins f'\"\n     and confs: \"conf_fs P h sh \\<Phi> C' M' (size Ts) T frs'\"\n     and confc: \"conf_clinit P sh frs\"\n     and h_ok: \"P\\<turnstile> h\\<surd>\" and sh_ok: \"P,h \\<turnstile>\\<^sub>s sh \\<surd>\"\n    by(auto simp: correct_state_def)\n\n    from Cons dist have dist': \"distinct (C#clinit_classes frs')\"\n     by(auto simp: distinct_length_2_or_more)\n\n    from shconf_upd_obj[OF sh_ok shconfD[OF sh_ok shC]] have sh_ok': \"P,h \\<turnstile>\\<^sub>s ?sh \\<surd>\"\n      by simp\n\n    from conf f' valid_ics_shupd Cons dist have conf': \"conf_f P h ?sh (ST,LT) ins f'\"\n     by(auto simp: conf_f_def2 fun_upd_apply)\n    have confs': \"conf_fs P h ?sh \\<Phi> C' M' (size Ts) T frs'\" by(rule conf_fs_shupd[OF confs dist'])\n\n    have confc': \"conf_clinit P ?sh frs\" by(rule conf_clinit_shupd[OF confc dist])\n\n    with h_ok sh_ok' meth ty conf' confs' f' Cons None show ?thesis\n     by(fastforce simp: correct_state_def)\n  qed(simp add: correct_state_def)\nqed(simp add: correct_state_def)\n\nlemma correct_state_Throwing_ex:\nassumes correct: \"P,\\<Phi> \\<turnstile> (xp,h,(stk,loc,C,M,pc,ics)#frs,sh)\\<surd>\"\nshows \"\\<And>Cs a. ics = Throwing Cs a \\<Longrightarrow> \\<exists>obj. h a = Some obj\"\nusing correct by(clarsimp simp: correct_state_def conf_f_def)\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/JinjaDCI/BV/BVConform.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6150878696277513, "lm_q2_score": 0.4263215925474903, "lm_q1q2_score": 0.262225240136346}}
{"text": "theory Proof_2_3\n  imports Requirements VCTheoryLemmas\nbegin\n\ntheorem proof_2_3: \"VC3 inv2 s0 requestButtonValue\"\n  apply(simp only: VC3_def inv2_def  R2_def extraInv_def)\nproof\n  print_state\n  assume \"((toEnvP s0 \\<and>\n      (\\<forall>s1 s2 s3.\n          substate s1 s2 \\<and>\n          substate s2 s3 \\<and>\n          substate s3 s0 \\<and>\n          toEnvP s1 \\<and>\n          toEnvP s2 \\<and>\n          toEnvP s3 \\<and>\n          toEnvNum s1 s2 = Ctrl \\<and>\n          toEnvNum s2 s3 < T2 \\<and> getVarBool s1 minimalRed \\<noteq> PRESSED \\<and> getVarBool s2 minimalRed = PRESSED \\<longrightarrow>\n          getVarBool s3 minimalRed = PRESSED)) \\<and>\n     toEnvP s0 \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = minimalRed \\<longrightarrow>\n           0 < ltimeEnv s1 Ctrl \\<and> ltimeEnv s1 Ctrl \\<le> MINIMAL_RED_TIME_LIMIT) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = minimalRed \\<longrightarrow>\n           (\\<exists>s2. toEnvP s2 \\<and>\n                 substate s2 s1 \\<and>\n                 toEnvNum s2 s1 = ltimeEnv s1 Ctrl \\<and> getPstate s2 Ctrl = green \\<and> ltimeEnv s2 Ctrl = T2) \\<or>\n           (\\<forall>s2. toEnvP s2 \\<and> substate s2 s1 \\<longrightarrow> getPstate s2 Ctrl = minimalRed)) \\<and>\n     (\\<forall>s1 s2.\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         substate s1 s2 \\<and> substate s2 s0 \\<and> getPstate s2 Ctrl = minimalRed \\<and> toEnvNum s1 s2 < ltimeEnv s2 Ctrl \\<longrightarrow>\n         getPstate s1 Ctrl = minimalRed) \\<and>\n     (\\<forall>s1 s2.\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         substate s1 s2 \\<and>\n         substate s2 s0 \\<and> (\\<forall>s3. toEnvP s3 \\<and> substate s1 s3 \\<and> substate s3 s2 \\<longrightarrow> getPstate s3 Ctrl = minimalRed) \\<longrightarrow>\n         toEnvNum s1 s2 = ltimeEnv s2 Ctrl - ltimeEnv s1 Ctrl) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and>\n           substate s1 s0 \\<and> getPstate s1 Ctrl = redAfterMinimalRed \\<and> getVarBool s1 redAfterMinimalRed = NOT_PRESSED \\<longrightarrow>\n           (\\<exists>s2. toEnvP s2 \\<and>\n                 substate s2 s1 \\<and>\n                 getPstate s2 Ctrl = minimalRed \\<and>\n                 ltimeEnv s2 Ctrl = MINIMAL_RED_TIME_LIMIT \\<and>\n                 getVarBool s2 redAfterMinimalRed = NOT_PRESSED \\<and>\n                 (\\<forall>s3. toEnvP s3 \\<and> substate s2 s3 \\<and> substate s3 s1 \\<and> s2 \\<noteq> s3 \\<longrightarrow>\n                       getPstate s3 Ctrl = redAfterMinimalRed \\<and>\n                       getVarBool s3 redAfterMinimalRed = NOT_PRESSED \\<and> getVarBool s3 Ctrl = NOT_PRESSED))) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = redToGreen \\<longrightarrow>\n           0 < ltimeEnv s1 Ctrl \\<and> ltimeEnv s1 Ctrl \\<le> RED_TO_GREEN_TIME_LIMIT) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = redToGreen \\<longrightarrow>\n           (\\<exists>s2. toEnvP s2 \\<and>\n                 substate s2 s1 \\<and>\n                 toEnvNum s2 s1 = ltimeEnv s1 Ctrl \\<and>\n                 getPstate s2 Ctrl = redAfterMinimalRed \\<and>\n                 (getVarBool s2 redAfterMinimalRed = PRESSED \\<or> getVarBool s2 Ctrl = PRESSED))) \\<and>\n     (\\<forall>s1 s2.\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         substate s1 s2 \\<and> substate s2 s0 \\<and> toEnvNum s1 s2 < ltimeEnv s2 Ctrl \\<and> getPstate s2 Ctrl = redToGreen \\<longrightarrow>\n         getPstate s1 Ctrl = redToGreen) \\<and>\n     (\\<forall>s1 s2.\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         substate s1 s2 \\<and>\n         substate s2 s0 \\<and> (\\<forall>s3. toEnvP s3 \\<and> substate s1 s3 \\<and> substate s3 s2 \\<longrightarrow> getPstate s3 Ctrl = redToGreen) \\<longrightarrow>\n         toEnvNum s1 s2 = ltimeEnv s2 Ctrl - ltimeEnv s1 Ctrl) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = green \\<longrightarrow> 0 < ltimeEnv s1 Ctrl \\<and> ltimeEnv s1 Ctrl \\<le> T2) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = green \\<longrightarrow>\n           (\\<exists>s2. toEnvP s2 \\<and>\n                 substate s2 s1 \\<and>\n                 toEnvNum s2 s1 = ltimeEnv s1 Ctrl \\<and>\n                 getPstate s2 Ctrl = redToGreen \\<and> ltimeEnv s2 Ctrl = RED_TO_GREEN_TIME_LIMIT)) \\<and>\n     (\\<forall>s1 s2.\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         substate s1 s2 \\<and> substate s2 s0 \\<and> getPstate s2 Ctrl = green \\<and> toEnvNum s1 s2 < ltimeEnv s2 Ctrl \\<longrightarrow>\n         getPstate s1 Ctrl = green) \\<and>\n     (\\<forall>s1 s2.\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         substate s1 s2 \\<and>\n         substate s2 s0 \\<and> (\\<forall>s3. toEnvP s3 \\<and> substate s1 s3 \\<and> substate s3 s2 \\<longrightarrow> getPstate s3 Ctrl = green) \\<longrightarrow>\n         toEnvNum s1 s2 = ltimeEnv s2 Ctrl - ltimeEnv s1 Ctrl) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = green \\<longrightarrow> getVarBool s1 minimalRed = PRESSED) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl \\<noteq> green \\<longrightarrow> getVarBool s1 minimalRed = NOT_PRESSED) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<longrightarrow>\n           getPstate s1 Ctrl = minimalRed \\<or>\n           getPstate s1 Ctrl = redAfterMinimalRed \\<or> getPstate s1 Ctrl = redToGreen \\<or> getPstate s1 Ctrl = green) \\<and>\n     (\\<forall>s1 s2.\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         substate s1 s2 \\<and>\n         substate s2 s0 \\<and>\n         toEnvNum s1 s2 < ltimeEnv s2 Ctrl - Ctrl \\<and>\n         getPstate s2 Ctrl = minimalRed \\<and> getVarBool s2 redAfterMinimalRed = NOT_PRESSED \\<longrightarrow>\n         getVarBool s1 Ctrl = NOT_PRESSED) \\<and>\n     (\\<forall>s2. toEnvP s2 \\<and> substate s2 s0 \\<and> getPstate s2 Ctrl = minimalRed \\<and> getVarBool s2 redAfterMinimalRed = PRESSED \\<longrightarrow>\n           (\\<exists>s1. toEnvP s1 \\<and>\n                 substate s1 s2 \\<and> toEnvNum s1 s2 < ltimeEnv s2 Ctrl - Ctrl \\<and> getVarBool s1 Ctrl = PRESSED)) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = redAfterMinimalRed \\<and> getVarBool s1 redAfterMinimalRed \\<longrightarrow>\n           (\\<exists>s2. toEnvP s2 \\<and>\n                 substate s2 s1 \\<and>\n                 toEnvNum s2 s1 = Ctrl \\<and>\n                 getPstate s2 Ctrl = minimalRed \\<and>\n                 ltimeEnv s2 Ctrl = MINIMAL_RED_TIME_LIMIT \\<and>\n                 (getVarBool s2 redAfterMinimalRed \\<or> getVarBool s1 Ctrl = PRESSED))) \\<and>\n     (\\<forall>s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = green \\<longrightarrow>\n           getVarBool s1 redAfterMinimalRed = NOT_PRESSED)) \\<and>\n    env (setVarAny s0 requestButtonValue) requestButtonValue \\<and>\n    getPstate (setVarAny s0 requestButtonValue) Ctrl = minimalRed \\<and>\n    getVarBool (setVarAny s0 requestButtonValue) Ctrl \\<and>\n    \\<not> MINIMAL_RED_TIME_LIMIT\n       \\<le> ltimeEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED) Ctrl\"\n  then obtain reqs0: \"(toEnvP s0 \\<and>\n      (\\<forall>s1 s2 s3.\n          substate s1 s2 \\<and>\n          substate s2 s3 \\<and>\n          substate s3 s0 \\<and>\n          toEnvP s1 \\<and>\n          toEnvP s2 \\<and>\n          toEnvP s3 \\<and>\n          toEnvNum s1 s2 = Ctrl \\<and>\n          toEnvNum s2 s3 < T2 \\<and> getVarBool s1 minimalRed \\<noteq> PRESSED \\<and> getVarBool s2 minimalRed = PRESSED \\<longrightarrow>\n          getVarBool s3 minimalRed = PRESSED))\" \nand ei0: \"toEnvP s0\"\nand ei1: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = minimalRed \\<longrightarrow>\n 0<ltimeEnv s1 Ctrl \\<and>  ltimeEnv s1 Ctrl \\<le> MINIMAL_RED_TIME_LIMIT) \" \nand ei2: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = minimalRed \\<longrightarrow>\n ((\\<exists> s2. toEnvP s2 \\<and> substate s2 s1 \\<and> toEnvNum s2 s1 = ltimeEnv s1 Ctrl  \\<and>\n getPstate s2 Ctrl = green \\<and> ltimeEnv s2 Ctrl = GREEN_TIME_LIMIT) \\<or>\n (\\<forall> s2. toEnvP s2 \\<and> substate s2 s1 \\<longrightarrow> getPstate s2 Ctrl = minimalRed))) \"\nand ei3: \"(\\<forall> s1 s2. toEnvP s1 \\<and> toEnvP s2 \\<and> substate s1 s2 \\<and> substate s2 s0 \\<and> getPstate s2 Ctrl = minimalRed \\<and>\n toEnvNum s1 s2 < ltimeEnv s2 Ctrl \\<longrightarrow> getPstate s1 Ctrl = minimalRed) \"\nand ei4: \"\\<forall> s1 s2. toEnvP s1 \\<and> toEnvP s2 \\<and> substate s1 s2 \\<and> substate s2 s0 \\<and>\n(\\<forall> s3. toEnvP s3 \\<and> substate s1 s3 \\<and> substate s3 s2 \\<longrightarrow> getPstate s3 Ctrl = minimalRed ) \\<longrightarrow>\ntoEnvNum s1 s2 = ltimeEnv s2 Ctrl - ltimeEnv s1 Ctrl\" \nand ei5: \"\\<forall> s1 . toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = redAfterMinimalRed \\<and>\n getVarBool s1 requestButtonPressed = False \\<longrightarrow>\n(\\<exists> s2. toEnvP s2 \\<and> substate s2 s1 \\<and> getPstate s2 Ctrl = minimalRed \\<and> ltimeEnv s2 Ctrl = MINIMAL_RED_TIME_LIMIT \\<and>\ngetVarBool s2 requestButtonPressed = False \\<and> (\\<forall> s3. toEnvP s3 \\<and> substate s2 s3 \\<and> substate s3 s1 \\<and> s2 \\<noteq> s3 \\<longrightarrow>\n getPstate s3 Ctrl = redAfterMinimalRed \\<and> \ngetVarBool s3 requestButtonPressed = False \\<and> getVarBool s3  requestButton = NOT_PRESSED))\"\nand ei6: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = redToGreen \\<longrightarrow>\n0< ltimeEnv s1 Ctrl \\<and> ltimeEnv s1 Ctrl \\<le> RED_TO_GREEN_TIME_LIMIT) \"\nand ei7: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = redToGreen \\<longrightarrow>\n(\\<exists> s2. toEnvP s2  \\<and> substate s2 s1 \\<and>\n toEnvNum s2 s1 = ltimeEnv s1 Ctrl  \\<and> getPstate s2 Ctrl = redAfterMinimalRed \\<and> \n(getVarBool s2 requestButtonPressed = True \\<or> getVarBool s2 requestButton = PRESSED)))\"\nand ei8: \"(\\<forall> s1 s2. toEnvP s1 \\<and> toEnvP s2 \\<and> substate s1 s2 \\<and> substate s2 s0 \\<and> toEnvNum s1 s2 < ltimeEnv s2 Ctrl \\<and>\n getPstate s2 Ctrl = redToGreen \\<longrightarrow> getPstate s1 Ctrl = redToGreen) \"\nand ei9: \"(\\<forall> s1 s2. toEnvP s1 \\<and> toEnvP s2 \\<and> substate s1 s2 \\<and> substate s2 s0 \\<and>\n(\\<forall> s3. toEnvP s3 \\<and> substate s1 s3 \\<and> substate s3 s2 \\<longrightarrow> getPstate s3 Ctrl = redToGreen) \\<longrightarrow>\ntoEnvNum s1 s2 = ltimeEnv s2 Ctrl - ltimeEnv s1 Ctrl) \"\nand ei10: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = green \\<longrightarrow>\n0 < ltimeEnv s1 Ctrl \\<and> ltimeEnv s1 Ctrl \\<le> GREEN_TIME_LIMIT)\"\nand ei11: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = green \\<longrightarrow>\n(\\<exists> s2. toEnvP s2 \\<and> substate s2 s1 \\<and> toEnvNum s2 s1 = ltimeEnv s1 Ctrl \\<and>\ngetPstate s2 Ctrl = redToGreen \\<and> ltimeEnv s2 Ctrl = RED_TO_GREEN_TIME_LIMIT)) \"\nand ei12: \"(\\<forall> s1 s2. toEnvP s1 \\<and> toEnvP s2 \\<and> substate s1 s2 \\<and> substate s2 s0 \\<and> getPstate s2 Ctrl = green \\<and>\ntoEnvNum s1 s2 < ltimeEnv s2 Ctrl \\<longrightarrow> getPstate s1 Ctrl = green)\"\nand ei13: \"(\\<forall> s1 s2. toEnvP s1 \\<and> toEnvP s2 \\<and> substate s1 s2 \\<and> substate s2 s0 \\<and> \n(\\<forall> s3. toEnvP s3 \\<and> substate s1 s3 \\<and> substate s3 s2 \\<longrightarrow> getPstate s3 Ctrl = green) \\<longrightarrow>\ntoEnvNum s1 s2 = ltimeEnv s2 Ctrl - ltimeEnv s1 Ctrl) \"\nand ei14: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = green \\<longrightarrow> getVarBool s1 trafficLight = GREEN) \"\nand ei15: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl \\<noteq> green \\<longrightarrow> getVarBool s1 trafficLight = RED) \"\nand ei16: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<longrightarrow>\n getPstate s1 Ctrl = minimalRed \\<or> getPstate s1 Ctrl = redAfterMinimalRed \\<or>\n getPstate s1 Ctrl = redToGreen \\<or> getPstate s1 Ctrl = green)\"\nand ei17: \"(\\<forall> s1 s2. toEnvP s1 \\<and> toEnvP s2 \\<and> substate s1 s2 \\<and> substate s2 s0 \\<and>\n toEnvNum s1 s2 < ltimeEnv s2 Ctrl - 1 \\<and>  getPstate s2 Ctrl = minimalRed \\<and>\n getVarBool s2 requestButtonPressed = False \\<longrightarrow> getVarBool s1 requestButton = NOT_PRESSED)\"\nand ei18: \"(\\<forall> s2. toEnvP s2  \\<and> substate s2 s0  \\<and>\n getPstate s2 Ctrl = minimalRed \\<and> getVarBool s2 requestButtonPressed = True \\<longrightarrow>\n(\\<exists> s1. toEnvP s1 \\<and> substate s1 s2 \\<and> toEnvNum s1 s2 < ltimeEnv s2 Ctrl - 1 \\<and> getVarBool s1 requestButton = PRESSED))\"\nand ei19: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = redAfterMinimalRed \\<and> getVarBool s1 requestButtonPressed \\<longrightarrow>\n(\\<exists> s2. toEnvP s2 \\<and> substate s2 s1 \\<and> toEnvNum s2 s1 = 1 \\<and> getPstate s2 Ctrl = minimalRed \\<and>\n ltimeEnv s2 Ctrl = MINIMAL_RED_TIME_LIMIT \\<and>\n (getVarBool s2 requestButtonPressed \\<or> getVarBool s1 requestButton = PRESSED)))\"\nand ei20: \"(\\<forall> s1. toEnvP s1 \\<and> substate s1 s0 \\<and> getPstate s1 Ctrl = green \\<longrightarrow> getVarBool s1 requestButtonPressed = False)\"\nand vc: \" env (setVarAny s0 requestButtonValue) requestButtonValue \\<and>\n    getPstate (setVarAny s0 requestButtonValue) Ctrl = minimalRed \\<and>\n    getVarBool (setVarAny s0 requestButtonValue) Ctrl \\<and>\n    \\<not> MINIMAL_RED_TIME_LIMIT\n       \\<le> ltimeEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED) Ctrl\"\n    by fast\n  show \"(toEnvP (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n     (\\<forall>s1 s2 s3.\n         substate s1 s2 \\<and>\n         substate s2 s3 \\<and>\n         substate s3 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         toEnvP s3 \\<and>\n         toEnvNum s1 s2 = Ctrl \\<and>\n         toEnvNum s2 s3 < T2 \\<and> getVarBool s1 minimalRed \\<noteq> PRESSED \\<and> getVarBool s2 minimalRed = PRESSED \\<longrightarrow>\n         getVarBool s3 minimalRed = PRESSED)) \\<and>\n    toEnvP (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n          getPstate s1 Ctrl = minimalRed \\<longrightarrow>\n          0 < ltimeEnv s1 Ctrl \\<and> ltimeEnv s1 Ctrl \\<le> MINIMAL_RED_TIME_LIMIT) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n          getPstate s1 Ctrl = minimalRed \\<longrightarrow>\n          (\\<exists>s2. toEnvP s2 \\<and>\n                substate s2 s1 \\<and>\n                toEnvNum s2 s1 = ltimeEnv s1 Ctrl \\<and> getPstate s2 Ctrl = green \\<and> ltimeEnv s2 Ctrl = T2) \\<or>\n          (\\<forall>s2. toEnvP s2 \\<and> substate s2 s1 \\<longrightarrow> getPstate s2 Ctrl = minimalRed)) \\<and>\n    (\\<forall>s1 s2.\n        toEnvP s1 \\<and>\n        toEnvP s2 \\<and>\n        substate s1 s2 \\<and>\n        substate s2 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n        getPstate s2 Ctrl = minimalRed \\<and> toEnvNum s1 s2 < ltimeEnv s2 Ctrl \\<longrightarrow>\n        getPstate s1 Ctrl = minimalRed) \\<and>\n    (\\<forall>s1 s2.\n        toEnvP s1 \\<and>\n        toEnvP s2 \\<and>\n        substate s1 s2 \\<and>\n        substate s2 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n        (\\<forall>s3. toEnvP s3 \\<and> substate s1 s3 \\<and> substate s3 s2 \\<longrightarrow> getPstate s3 Ctrl = minimalRed) \\<longrightarrow>\n        toEnvNum s1 s2 = ltimeEnv s2 Ctrl - ltimeEnv s1 Ctrl) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n          getPstate s1 Ctrl = redAfterMinimalRed \\<and> getVarBool s1 redAfterMinimalRed = NOT_PRESSED \\<longrightarrow>\n          (\\<exists>s2. toEnvP s2 \\<and>\n                substate s2 s1 \\<and>\n                getPstate s2 Ctrl = minimalRed \\<and>\n                ltimeEnv s2 Ctrl = MINIMAL_RED_TIME_LIMIT \\<and>\n                getVarBool s2 redAfterMinimalRed = NOT_PRESSED \\<and>\n                (\\<forall>s3. toEnvP s3 \\<and> substate s2 s3 \\<and> substate s3 s1 \\<and> s2 \\<noteq> s3 \\<longrightarrow>\n                      getPstate s3 Ctrl = redAfterMinimalRed \\<and>\n                      getVarBool s3 redAfterMinimalRed = NOT_PRESSED \\<and> getVarBool s3 Ctrl = NOT_PRESSED))) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n          getPstate s1 Ctrl = redToGreen \\<longrightarrow>\n          0 < ltimeEnv s1 Ctrl \\<and> ltimeEnv s1 Ctrl \\<le> RED_TO_GREEN_TIME_LIMIT) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n          getPstate s1 Ctrl = redToGreen \\<longrightarrow>\n          (\\<exists>s2. toEnvP s2 \\<and>\n                substate s2 s1 \\<and>\n                toEnvNum s2 s1 = ltimeEnv s1 Ctrl \\<and>\n                getPstate s2 Ctrl = redAfterMinimalRed \\<and>\n                (getVarBool s2 redAfterMinimalRed = PRESSED \\<or> getVarBool s2 Ctrl = PRESSED))) \\<and>\n    (\\<forall>s1 s2.\n        toEnvP s1 \\<and>\n        toEnvP s2 \\<and>\n        substate s1 s2 \\<and>\n        substate s2 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n        toEnvNum s1 s2 < ltimeEnv s2 Ctrl \\<and> getPstate s2 Ctrl = redToGreen \\<longrightarrow>\n        getPstate s1 Ctrl = redToGreen) \\<and>\n    (\\<forall>s1 s2.\n        toEnvP s1 \\<and>\n        toEnvP s2 \\<and>\n        substate s1 s2 \\<and>\n        substate s2 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n        (\\<forall>s3. toEnvP s3 \\<and> substate s1 s3 \\<and> substate s3 s2 \\<longrightarrow> getPstate s3 Ctrl = redToGreen) \\<longrightarrow>\n        toEnvNum s1 s2 = ltimeEnv s2 Ctrl - ltimeEnv s1 Ctrl) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n          getPstate s1 Ctrl = green \\<longrightarrow>\n          0 < ltimeEnv s1 Ctrl \\<and> ltimeEnv s1 Ctrl \\<le> T2) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n          getPstate s1 Ctrl = green \\<longrightarrow>\n          (\\<exists>s2. toEnvP s2 \\<and>\n                substate s2 s1 \\<and>\n                toEnvNum s2 s1 = ltimeEnv s1 Ctrl \\<and>\n                getPstate s2 Ctrl = redToGreen \\<and> ltimeEnv s2 Ctrl = RED_TO_GREEN_TIME_LIMIT)) \\<and>\n    (\\<forall>s1 s2.\n        toEnvP s1 \\<and>\n        toEnvP s2 \\<and>\n        substate s1 s2 \\<and>\n        substate s2 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n        getPstate s2 Ctrl = green \\<and> toEnvNum s1 s2 < ltimeEnv s2 Ctrl \\<longrightarrow>\n        getPstate s1 Ctrl = green) \\<and>\n    (\\<forall>s1 s2.\n        toEnvP s1 \\<and>\n        toEnvP s2 \\<and>\n        substate s1 s2 \\<and>\n        substate s2 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n        (\\<forall>s3. toEnvP s3 \\<and> substate s1 s3 \\<and> substate s3 s2 \\<longrightarrow> getPstate s3 Ctrl = green) \\<longrightarrow>\n        toEnvNum s1 s2 = ltimeEnv s2 Ctrl - ltimeEnv s1 Ctrl) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n          getPstate s1 Ctrl = green \\<longrightarrow>\n          getVarBool s1 minimalRed = PRESSED) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n          getPstate s1 Ctrl \\<noteq> green \\<longrightarrow>\n          getVarBool s1 minimalRed = NOT_PRESSED) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and> substate s1 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<longrightarrow>\n          getPstate s1 Ctrl = minimalRed \\<or>\n          getPstate s1 Ctrl = redAfterMinimalRed \\<or> getPstate s1 Ctrl = redToGreen \\<or> getPstate s1 Ctrl = green) \\<and>\n    (\\<forall>s1 s2.\n        toEnvP s1 \\<and>\n        toEnvP s2 \\<and>\n        substate s1 s2 \\<and>\n        substate s2 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n        toEnvNum s1 s2 < ltimeEnv s2 Ctrl - Ctrl \\<and>\n        getPstate s2 Ctrl = minimalRed \\<and> getVarBool s2 redAfterMinimalRed = NOT_PRESSED \\<longrightarrow>\n        getVarBool s1 Ctrl = NOT_PRESSED) \\<and>\n    (\\<forall>s2. toEnvP s2 \\<and>\n          substate s2 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n          getPstate s2 Ctrl = minimalRed \\<and> getVarBool s2 redAfterMinimalRed = PRESSED \\<longrightarrow>\n          (\\<exists>s1. toEnvP s1 \\<and>\n                substate s1 s2 \\<and> toEnvNum s1 s2 < ltimeEnv s2 Ctrl - Ctrl \\<and> getVarBool s1 Ctrl = PRESSED)) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n          getPstate s1 Ctrl = redAfterMinimalRed \\<and> getVarBool s1 redAfterMinimalRed \\<longrightarrow>\n          (\\<exists>s2. toEnvP s2 \\<and>\n                substate s2 s1 \\<and>\n                toEnvNum s2 s1 = Ctrl \\<and>\n                getPstate s2 Ctrl = minimalRed \\<and>\n                ltimeEnv s2 Ctrl = MINIMAL_RED_TIME_LIMIT \\<and>\n                (getVarBool s2 redAfterMinimalRed \\<or> getVarBool s1 Ctrl = PRESSED))) \\<and>\n    (\\<forall>s1. toEnvP s1 \\<and>\n          substate s1 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n          getPstate s1 Ctrl = green \\<longrightarrow>\n          getVarBool s1 redAfterMinimalRed = NOT_PRESSED)\"\n    apply(rule conjI)\n     apply(rule conjI)\n    apply(simp)\n  proof(rule allI; rule allI; rule allI)\n    fix s1 s2 s3\n    show \"substate s1 s2 \\<and>\n         substate s2 s3 \\<and>\n         substate s3 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         toEnvP s3 \\<and>\n         toEnvNum s1 s2 = Ctrl \\<and>\n         toEnvNum s2 s3 < T2 \\<and> getVarBool s1 minimalRed \\<noteq> PRESSED \\<and> getVarBool s2 minimalRed = PRESSED \\<longrightarrow>\n         getVarBool s3 minimalRed = PRESSED\"\n    proof cases\n      assume 1: \"s3 =  (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED))\"\n      from ei2 ei0 vc substate_refl have \" ((\\<exists> s2. toEnvP s2 \\<and> substate s2 s0\n \\<and> toEnvNum s2 s0 = ltimeEnv s0 Ctrl  \\<and>\n getPstate s2 Ctrl = green \\<and> ltimeEnv s2 Ctrl = GREEN_TIME_LIMIT) \\<or>\n (\\<forall> s2. toEnvP s2 \\<and> substate s2 s0 \\<longrightarrow> getPstate s2 Ctrl = minimalRed))\"\n        by auto\n      thus ?thesis\n      proof\n        assume \"\\<exists>s2. toEnvP s2 \\<and>\n         substate s2 s0 \\<and> toEnvNum s2 s0 = ltimeEnv s0 Ctrl \\<and> getPstate s2 Ctrl = green \\<and> ltimeEnv s2 Ctrl = T2\"\n        then obtain g where 2: \"toEnvP g \\<and>\n         substate g s0 \\<and> toEnvNum g s0 = ltimeEnv s0 Ctrl \\<and> getPstate g Ctrl = green \\<and> ltimeEnv g Ctrl = T2\" ..\n        show ?thesis\n        proof cases\n          assume 4: \"substate s2 g\" \n          from ei11 2 have \"(\\<exists> s2. toEnvP s2 \\<and> substate s2 g \\<and> toEnvNum s2 g = ltimeEnv g Ctrl \\<and>\ngetPstate s2 Ctrl = redToGreen \\<and> ltimeEnv s2 Ctrl = RED_TO_GREEN_TIME_LIMIT)\" by blast\n          then obtain rg where 3: \" toEnvP rg \\<and> substate rg g \\<and> toEnvNum rg g = ltimeEnv g Ctrl \\<and>\ngetPstate rg Ctrl = redToGreen \\<and> ltimeEnv rg Ctrl = RED_TO_GREEN_TIME_LIMIT\" ..\n          show ?thesis\n          proof cases\n            assume 5: \"substate s2 rg\"\n            from ei0 have \"0 < ltimeEnv s0 Ctrl\" by ((cases s0); auto)\n            with 2 3 toEnvNum3[of rg g s0] substate_trans[of rg g s0] have 6: \"toEnvNum rg s0 > T2\"\n              by auto\n            from 2 3 substate_trans have \"substate rg s0\" by blast\n            with 5 6 toEnvNum3[of s2 rg s0] substate_trans[of s2 rg s0] have \"toEnvNum s2 s0 > T2\"\n              by auto\n            with 1 show ?thesis by auto\n          next\n            assume 5: \"\\<not> (substate s2 rg)\"\n            with 3 4 substate_refl substate_total have 6: \"substate rg s2 \\<and> rg \\<noteq> s2\" by auto\n            show ?thesis\n            proof\n              assume 7: \"substate s1 s2 \\<and>\n         substate s2 s3 \\<and>\n         substate s3 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         toEnvP s3 \\<and>\n         toEnvNum s1 s2 = Ctrl \\<and>\n         toEnvNum s2 s3 < T2 \\<and> getVarBool s1 minimalRed \\<noteq> PRESSED \\<and> getVarBool s2 minimalRed = PRESSED\"\n              show \"getVarBool s3 minimalRed = PRESSED\"\n              proof cases\n                assume 8: \"substate s1 rg\"\n               from ei0 have \"0 < ltimeEnv s0 Ctrl\" by ((cases s0); auto)\n            with 2 3 toEnvNum3[of rg g s0] substate_trans[of rg g s0] have 6: \"toEnvNum rg s0 > T2\"\n              by auto\n            from 2 3 substate_trans have \"substate rg s0\" by blast\n            with 8 6 toEnvNum3 have 9: \"toEnvNum s1 s0 > T2\" by auto\n            from 1 7 9 have 10: \"substate s2 s0\" by ((simp split: if_splits); auto)\n            with 7 9 toEnvNum3 have \"toEnvNum s2 s0 \\<ge> T2\" by auto\n            with 1 10 substate_refl toEnvNum3[of s2 s0 s3] have \"toEnvNum s2 s3 > T2\" by auto\n            with 7 show ?thesis by auto\n          next \n            assume 8: \"\\<not> substate s1 rg\"\n            from 4 7 substate_trans have 9: \"substate s1 g\" by blast\n            from 2 4 substate_trans have 10: \"substate s2 s0\" by blast\n            with 1 7 substate_refl substate_asym[of s0 s3]  have \"toEnvNum s2 s0 + 1 < T2\" by ((simp split: if_splits); auto)\n            with 7 10 toEnvNum3 have \"toEnvNum s1 s0 < T2\" by auto\n            with 2 9 toEnvNum3 have \"toEnvNum s1 g < ltimeEnv g Ctrl\" by auto\n            with 2 7 9 ei12 have \"getPstate s1 Ctrl = green\" by blast\n            with ei14 7 show ?thesis using 2 9 substate_trans by blast\n          qed\n        qed\n      qed\n    next\n      assume 4: \"\\<not> substate s2 g\"\n      show ?thesis\n      proof\n        assume 7: \"substate s1 s2 \\<and>\n         substate s2 s3 \\<and>\n         substate s3 (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n         toEnvP s1 \\<and>\n         toEnvP s2 \\<and>\n         toEnvP s3 \\<and>\n         toEnvNum s1 s2 = Ctrl \\<and>\n         toEnvNum s2 s3 < T2 \\<and> getVarBool s1 minimalRed \\<noteq> PRESSED \\<and> getVarBool s2 minimalRed = PRESSED\"\n        have \"getVarBool s2 minimalRed =NOT_PRESSED\"\n        proof cases\n          assume 3: \"s2 =  (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED))\"\n          from vc have \"getPstate s0 Ctrl \\<noteq> green\" by auto\n          with ei0 substate_refl ei15 have \"getVarBool s0 trafficLight = RED\" by blast\n          with 3 show ?thesis by auto\n        next \n          assume 3: \"s2 \\<noteq>  (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED))\"\n          with 1 7 have 5: \"substate s2 s0\" by ((simp split: if_splits); auto)\n          from 4 2 5 substate_total substate_refl have 6: \"substate g s2 \\<and> s2 \\<noteq> g\" by blast\n          with 2 7 gtimeE_inj have 9: \"toEnvNum emptyState g \\<noteq> toEnvNum emptyState s2\" by blast\n           from 5 6 toEnvNum3 have \"toEnvNum s2 s0 \\<le> toEnvNum g s0\" by auto\n          from le_imp_less_or_eq[OF this]\n          show ?thesis\n          proof\n            assume \"toEnvNum s2 s0 < toEnvNum g s0\"\n            with 2 have 8: \"toEnvNum s2 s0 < ltimeEnv s0 Ctrl\" by auto\n            from vc have \"getPstate s0 Ctrl = minimalRed\" by auto\n            with ei3 7 ei0 5 substate_refl 8 have \"getPstate s2 Ctrl = minimalRed\" by blast\n            with 5 7 ei15 show ?thesis by auto\n          next \n            assume \"toEnvNum s2 s0 = toEnvNum g s0\"\n            with 9 have 10: \"toEnvNum emptyState g +toEnvNum g s0 \\<noteq> toEnvNum emptyState s2 +toEnvNum s2 s0\"\n              by auto\n            from emptyState_substate 5 toEnvNum3 have 11: \"toEnvNum emptyState s0 = toEnvNum emptyState s2 + toEnvNum s2 s0\"\n              by auto \n            from emptyState_substate 5 6 substate_trans[of g s2 s0]  toEnvNum3 \n            have  \"toEnvNum emptyState s0 = toEnvNum emptyState g + toEnvNum g s0\"\n              by auto\n            with 10 11 show ?thesis by auto\n          qed\n        qed\n        with 7 show \" getVarBool s3 minimalRed = PRESSED\" by auto\n      qed\n    qed\n  next\n    assume 2: \" \\<forall>s2. toEnvP s2 \\<and> substate s2 s0 \\<longrightarrow> getPstate s2 Ctrl = minimalRed \"\n    show \" \\<forall>s2. toEnvP s2 \\<and> substate s2 s0 \\<longrightarrow> getPstate s2 Ctrl = minimalRed \\<Longrightarrow>\n    substate s1 s2 \\<and>\n    substate s2 s3 \\<and>\n    substate s3\n     (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n    toEnvP s1 \\<and>\n    toEnvP s2 \\<and>\n    toEnvP s3 \\<and>\n    toEnvNum s1 s2 = Ctrl \\<and>\n    toEnvNum s2 s3 < T2 \\<and> getVarBool s1 minimalRed \\<noteq> PRESSED \\<and> getVarBool s2 minimalRed = PRESSED \\<longrightarrow>\n    getVarBool s3 minimalRed = PRESSED\"\n    proof cases\n       assume 3: \"s2 =  (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED))\"\n       from vc have \"getPstate s0 Ctrl \\<noteq> green\" by auto\n          with ei0 substate_refl ei15 have \"getVarBool s0 trafficLight = RED\" by blast\n          with 3 show ?thesis by auto\n        next \n          assume 3: \"s2 \\<noteq>  (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED))\"\n          show ?thesis\n          proof\n            assume 7: \"substate s1 s2 \\<and>\n    substate s2 s3 \\<and>\n    substate s3\n     (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n    toEnvP s1 \\<and>\n    toEnvP s2 \\<and>\n    toEnvP s3 \\<and>\n    toEnvNum s1 s2 = Ctrl \\<and>\n    toEnvNum s2 s3 < T2 \\<and> getVarBool s1 minimalRed \\<noteq> PRESSED \\<and> getVarBool s2 minimalRed = PRESSED\"\n            with 1  3 have \"substate s2 s0\" by ((simp split: if_splits); auto)\n            with 2 7 ei15  show \"  getVarBool s3 minimalRed = PRESSED\" by auto\n          qed\n        qed\n      qed\n    next\n      assume 1: \" s3 \\<noteq>\n   (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED))\"\n      show ?thesis\n      proof\n        print_state\n        assume 7: \"substate s1 s2 \\<and>\n    substate s2 s3 \\<and>\n    substate s3\n    (toEnv (setVarBool (setVarAny s0 requestButtonValue) redAfterMinimalRed PRESSED)) \\<and>\n    toEnvP s1 \\<and>\n    toEnvP s2 \\<and>\n    toEnvP s3 \\<and>\n    toEnvNum s1 s2 = Ctrl \\<and>\n    toEnvNum s2 s3 < T2 \\<and> getVarBool s1 minimalRed \\<noteq> PRESSED \\<and> getVarBool s2 minimalRed = PRESSED\"\n        with 1 have \"substate s3 s0\" by ((simp split: if_splits); auto)\n        with 7 reqs0         show \" getVarBool s3 minimalRed = PRESSED\" by blast\n      qed\n    qed\n  next\n    (*prove extraInv*)\n", "meta": {"author": "ivchernenko", "repo": "post_vcgenerator", "sha": "fadfff131086870a027d6bd1c78b8d5a3baf183b", "save_path": "github-repos/isabelle/ivchernenko-post_vcgenerator", "path": "github-repos/isabelle/ivchernenko-post_vcgenerator/post_vcgenerator-fadfff131086870a027d6bd1c78b8d5a3baf183b/case-studies/trafficLights/Proof_2_3.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.66192288918838, "lm_q2_score": 0.3960681662740417, "lm_q1q2_score": 0.26216658493565737}}
{"text": "(*  Title:      HOL/Auth/n_mutualEx_lemma_inv__3_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n \ntheory n_mutualEx_lemma_inv__3_on_rules imports n_mutualEx_lemma_on_inv__3\nbegin\nsection{*All lemmas on causal relation between inv__3*}\nlemma lemma_inv__3_on_rules:\n  assumes b1: \"r \\<in> rules N\" and b2: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__3  p__Inv3 p__Inv4)\"\n  shows \"invHoldForRule Interp s f r (invariants N)\"\n  proof -\n  have c1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n  apply (cut_tac b1, auto) done\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\"\n      have \"invHoldForRule Interp s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_TryVsinv__3) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\"\n      have \"invHoldForRule Interp s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_CritVsinv__3) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\"\n      have \"invHoldForRule Interp s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_ExitVsinv__3) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n      have \"invHoldForRule Interp s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_IdleVsinv__3) done\n    }\n\n  ultimately show \"invHoldForRule Interp s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "lyj238Gmail", "repo": "gsteProof", "sha": "3070d08e1f31a93be6fde85ab6b65d489c05f99e", "save_path": "github-repos/isabelle/lyj238Gmail-gsteProof", "path": "github-repos/isabelle/lyj238Gmail-gsteProof/gsteProof-3070d08e1f31a93be6fde85ab6b65d489c05f99e/mutualEx/n_mutualEx_lemma_inv__3_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6261241772283034, "lm_q2_score": 0.4186969093556867, "lm_q1q2_score": 0.2621562578783629}}
{"text": "(*  Title:      HOL/HOLCF/IOA/Storage/Impl.thy\n    Author:     Olaf Müller\n*)\n\nsection {* The implementation of a memory *}\n\ntheory Impl\nimports IOA Action\nbegin\n\ndefinition\n  impl_sig :: \"action signature\" where\n  \"impl_sig = (UN l.{Free l} Un {New},\n               UN l.{Loc l},\n               {})\"\n\ndefinition\n  impl_trans :: \"(action, nat  * bool)transition set\" where\n  \"impl_trans =\n    {tr. let s = fst(tr); k = fst s; b = snd s;\n             t = snd(snd(tr)); k' = fst t; b' = snd t\n         in\n         case fst(snd(tr))\n         of\n         New       => k' = k & b'  |\n         Loc l     => b & l= k & k'= (Suc k) & ~b' |\n         Free l    => k'=k & b'=b}\"\n\ndefinition\n  impl_ioa :: \"(action, nat * bool)ioa\" where\n  \"impl_ioa = (impl_sig, {(0,False)}, impl_trans,{},{})\"\n\nlemma in_impl_asig:\n  \"New : actions(impl_sig) &\n    Loc l : actions(impl_sig) &\n    Free l : actions(impl_sig) \"\n  by (simp add: impl_sig_def actions_def asig_projections)\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/HOLCF/IOA/Storage/Impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318479832804, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.2620952280295094}}
{"text": "(*  Title:      JinjaDCI/BV/BVExec.thy\n\n    Author:     Tobias Nipkow, Gerwin Klein, Susannah Mansky\n    Copyright   2000 TUM, 2020 UIUC\n\n    Based on the Jinja theory BV/BVExec.thy by Tobias Nipkow and Gerwin Klein\n*)\n\nsection \\<open> Kildall for the JVM \\label{sec:JVM} \\<close>\n\ntheory BVExec\nimports \"../DFA/Abstract_BV\" TF_JVM\nbegin\n\ndefinition kiljvm :: \"jvm_prog \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> ty \\<Rightarrow> \n             instr list \\<Rightarrow> ex_table \\<Rightarrow> ty\\<^sub>i' err list \\<Rightarrow> ty\\<^sub>i' err list\"\nwhere\n  \"kiljvm P mxs mxl T\\<^sub>r is xt \\<equiv>\n  kildall (JVM_SemiType.le P mxs mxl) (JVM_SemiType.sup P mxs mxl) \n          (exec P mxs T\\<^sub>r xt is)\"\n\ndefinition wt_kildall :: \"jvm_prog \\<Rightarrow> cname \\<Rightarrow> staticb \\<Rightarrow> ty list \\<Rightarrow> ty \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> \n                 instr list \\<Rightarrow> ex_table \\<Rightarrow> bool\"\nwhere\n  \"wt_kildall P C' b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt \\<equiv>\n   0 < size is \\<and> \n   (let first  = Some ([],(case b of Static \\<Rightarrow> [] | NonStatic \\<Rightarrow> [OK (Class C')])\n                            @(map OK Ts)@(replicate mxl\\<^sub>0 Err));\n        start  = (OK first)#(replicate (size is - 1) (OK None));\n        result = kiljvm P mxs\n                   ((case b of Static \\<Rightarrow> 0 | NonStatic \\<Rightarrow> 1)+size Ts+mxl\\<^sub>0)\n                     T\\<^sub>r is xt start\n    in \\<forall>n < size is. result!n \\<noteq> Err)\"\n\ndefinition wf_jvm_prog\\<^sub>k :: \"jvm_prog \\<Rightarrow> bool\"\nwhere\n  \"wf_jvm_prog\\<^sub>k P \\<equiv>\n  wf_prog (\\<lambda>P C' (M,b,Ts,T\\<^sub>r,(mxs,mxl\\<^sub>0,is,xt)). wt_kildall P C' b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt) P\"\n\n\ntheorem (in start_context) is_bcv_kiljvm:\n  \"is_bcv r Err step (size is) A (kiljvm P mxs mxl T\\<^sub>r is xt)\"\n(*<*)\n  apply (insert wf)\n  apply (unfold kiljvm_def)\n  apply (fold r_def f_def step_def_exec)\n  apply (rule is_bcv_kildall)\n       apply simp apply (rule Semilat.intro)\n       apply (fold sl_def2)\n       apply (erule semilat_JVM)\n      apply simp\n      apply blast\n     apply (simp add: JVM_le_unfold)\n    apply (rule exec_pres_type)\n   apply (rule bounded_step)\n  apply (erule step_mono)\n  done\n(*>*)\n\n(* FIXME: move? *)\nlemma subset_replicate [intro?]: \"set (replicate n x) \\<subseteq> {x}\"\n  by (induct n) auto\n\nlemma in_set_replicate:\n  assumes \"x \\<in> set (replicate n y)\"\n  shows \"x = y\"\n(*<*)\nproof -\n  note assms\n  also have \"set (replicate n y) \\<subseteq> {y}\" ..\n  finally show ?thesis by simp\nqed\n(*>*)\n\nlemma (in start_context) start_in_A [intro?]:\n  \"0 < size is \\<Longrightarrow> start \\<in> list (size is) A\"\n  using Ts C\n(*<*)\n  apply (simp add: JVM_states_unfold)\n  apply (cases b; force intro!: listI list_appendI dest!: in_set_replicate)\n  done\n(*>*)\n\n\ntheorem (in start_context) wt_kil_correct:\n  assumes wtk: \"wt_kildall P C b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt\"\n  shows \"\\<exists>\\<tau>s. wt_method P C b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt \\<tau>s\"\n(*<*)\nproof -\n  from wtk obtain res where    \n    result:   \"res = kiljvm P mxs mxl T\\<^sub>r is xt start\" and\n    success:  \"\\<forall>n < size is. res!n \\<noteq> Err\" and\n    instrs:   \"0 < size is\" \n    by (unfold wt_kildall_def) simp\n      \n  have bcv: \"is_bcv r Err step (size is) A (kiljvm P mxs mxl T\\<^sub>r is xt)\"\n    by (rule is_bcv_kiljvm)\n    \n  from instrs have \"start \\<in> list (size is) A\" ..\n  with bcv success result have \n    \"\\<exists>ts\\<in>list (size is) A. start [\\<sqsubseteq>\\<^sub>r] ts \\<and> wt_step r Err step ts\"\n    by (unfold is_bcv_def) blast\n  then obtain \\<tau>s' where\n    in_A: \"\\<tau>s' \\<in> list (size is) A\" and\n    s:    \"start [\\<sqsubseteq>\\<^sub>r] \\<tau>s'\" and\n    w:    \"wt_step r Err step \\<tau>s'\"\n    by blast\n  hence wt_err_step: \"wt_err_step (sup_state_opt P) step \\<tau>s'\"\n    by (simp add: wt_err_step_def JVM_le_Err_conv)\n\n  from in_A have l: \"size \\<tau>s' = size is\" by simp  \n  moreover {\n    from in_A  have \"check_types P mxs mxl \\<tau>s'\" by (simp add: check_types_def)\n    also from w have \"\\<forall>x \\<in> set \\<tau>s'. x \\<noteq> Err\" \n      by (auto simp add: wt_step_def all_set_conv_all_nth)\n    hence [symmetric]: \"map OK (map ok_val \\<tau>s') = \\<tau>s'\" \n      by (auto intro!: map_idI simp add: wt_step_def)\n    finally  have \"check_types P mxs mxl (map OK (map ok_val \\<tau>s'))\" .\n  } \n  moreover {  \n    from s have \"start!0 \\<sqsubseteq>\\<^sub>r \\<tau>s'!0\" by (rule le_listD) simp\n    moreover\n    from instrs w l \n    have \"\\<tau>s'!0 \\<noteq> Err\" by (unfold wt_step_def) simp\n    then obtain \\<tau>s0 where \"\\<tau>s'!0 = OK \\<tau>s0\" by auto\n    ultimately\n    have \"wt_start P C b Ts mxl\\<^sub>0 (map ok_val \\<tau>s')\" using l instrs\n      by (unfold wt_start_def) \n         (cases b; simp add: lesub_def JVM_le_Err_conv Err.le_def)\n  }\n  moreover \n  from in_A have \"set \\<tau>s' \\<subseteq> A\" by simp  \n  with wt_err_step bounded_step\n  have \"wt_app_eff (sup_state_opt P) app eff (map ok_val \\<tau>s')\"\n    by (auto intro: wt_err_imp_wt_app_eff simp add: l)\n  ultimately\n  have \"wt_method P C b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt (map ok_val \\<tau>s')\"\n    using instrs by (simp add: wt_method_def2 check_types_def del: map_map)\n  thus ?thesis by blast\nqed\n(*>*)\n\n\ntheorem (in start_context) wt_kil_complete:\n  assumes wtm: \"wt_method P C b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt \\<tau>s\"\n  shows \"wt_kildall P C b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt\"\n(*<*)\nproof -\n  from wtm obtain\n    instrs:   \"0 < size is\" and\n    length:   \"length \\<tau>s = length is\" and \n    ck_type:  \"check_types P mxs mxl (map OK \\<tau>s)\" and\n    wt_start: \"wt_start P C b Ts mxl\\<^sub>0 \\<tau>s\" and\n    app_eff:  \"wt_app_eff (sup_state_opt P) app eff \\<tau>s\"\n    by (simp add: wt_method_def2 check_types_def)\n\n  from ck_type\n  have in_A: \"set (map OK \\<tau>s) \\<subseteq> A\" \n    by (simp add: check_types_def)  \n  with app_eff in_A bounded_step\n  have \"wt_err_step (sup_state_opt P) (err_step (size \\<tau>s) app eff) (map OK \\<tau>s)\"\n    by - (erule wt_app_eff_imp_wt_err,\n          auto simp add: exec_def length states_def)\n  hence wt_err: \"wt_err_step (sup_state_opt P) step (map OK \\<tau>s)\" \n    by (simp add: length)\n  have is_bcv: \"is_bcv r Err step (size is) A (kiljvm P mxs mxl T\\<^sub>r is xt)\"\n    by (rule is_bcv_kiljvm)\n  moreover from instrs have \"start \\<in> list (size is) A\" ..\n  moreover\n  let ?\\<tau>s = \"map OK \\<tau>s\"  \n  have less_\\<tau>s: \"start [\\<sqsubseteq>\\<^sub>r] ?\\<tau>s\"\n  proof (rule le_listI)\n    from length instrs\n    show \"length start = length (map OK \\<tau>s)\" by simp\n  next\n    fix n\n    from wt_start have \"P \\<turnstile> ok_val (start!0) \\<le>' \\<tau>s!0\" \n      by (cases b; simp add: wt_start_def)\n    moreover from instrs length have \"0 < length \\<tau>s\" by simp\n    ultimately have \"start!0 \\<sqsubseteq>\\<^sub>r ?\\<tau>s!0\" \n      by (simp add: JVM_le_Err_conv lesub_def)\n    moreover {\n      fix n'\n      have \"OK None \\<sqsubseteq>\\<^sub>r ?\\<tau>s!n\"\n        by (auto simp add: JVM_le_Err_conv Err.le_def lesub_def \n                 split: err.splits)\n      hence \"\\<lbrakk>n = Suc n'; n < size start\\<rbrakk> \\<Longrightarrow> start!n \\<sqsubseteq>\\<^sub>r ?\\<tau>s!n\" by simp\n    }\n    ultimately\n    show \"n < size start \\<Longrightarrow> start!n \\<sqsubseteq>\\<^sub>r ?\\<tau>s!n\" by (cases n, blast+)   \n  qed\n  moreover\n  from ck_type length\n  have \"?\\<tau>s \\<in> list (size is) A\"\n    by (auto intro!: listI simp add: check_types_def)\n  moreover\n  from wt_err have \"wt_step r Err step ?\\<tau>s\" \n    by (simp add: wt_err_step_def JVM_le_Err_conv)\n  ultimately\n  have \"\\<forall>p. p < size is \\<longrightarrow> kiljvm P  mxs mxl T\\<^sub>r is xt start ! p \\<noteq> Err\" \n    by (unfold is_bcv_def) blast\n  with instrs \n  show \"wt_kildall P C b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt\" by (unfold wt_kildall_def) simp\nqed\n(*>*)\n\n\ntheorem jvm_kildall_correct:\n  \"wf_jvm_prog\\<^sub>k P = wf_jvm_prog P\"\n(*<*)\nproof \n  let ?\\<Phi> = \"\\<lambda>C M. let (C,b,Ts,T\\<^sub>r,(mxs,mxl\\<^sub>0,is,xt)) = method P C M in \n              SOME \\<tau>s. wt_method P C b Ts T\\<^sub>r mxs mxl\\<^sub>0 is xt \\<tau>s\"\n\n  \\<comment> \\<open>soundness\\<close>\n  assume wt: \"wf_jvm_prog\\<^sub>k P\"\n  hence \"wf_jvm_prog\\<^bsub>?\\<Phi>\\<^esub> P\"\n    apply (unfold wf_jvm_prog_phi_def wf_jvm_prog\\<^sub>k_def)    \n    apply (erule wf_prog_lift)\n    apply (auto dest!: start_context.wt_kil_correct [OF start_context.intro] \n                intro: someI)\n    apply (erule sees_method_is_class)\n    done\n  thus \"wf_jvm_prog P\" by (unfold wf_jvm_prog_def) fast\nnext\n  \\<comment> \\<open>completeness\\<close>\n  assume wt: \"wf_jvm_prog P\"\n  thus \"wf_jvm_prog\\<^sub>k P\"\n    apply (unfold wf_jvm_prog_def wf_jvm_prog_phi_def wf_jvm_prog\\<^sub>k_def)\n    apply (clarify)\n    apply (erule wf_prog_lift)\n    apply (auto intro!: start_context.wt_kil_complete start_context.intro)\n    apply (erule sees_method_is_class)\n    done\nqed\n(*>*)\n\nend\n", "meta": {"author": "susannahej", "repo": "jinja-dci", "sha": "0969fa2c5966204b326395763d7a375e7dc6badf", "save_path": "github-repos/isabelle/susannahej-jinja-dci", "path": "github-repos/isabelle/susannahej-jinja-dci/jinja-dci-0969fa2c5966204b326395763d7a375e7dc6badf/BV/BVExec.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.603931819468636, "lm_q2_score": 0.4339814648038985, "lm_q1q2_score": 0.26209521565468225}}
{"text": "theory IICF_HOL_List\nimports \"../Intf/IICF_List\"\nbegin\n\ncontext \nbegin\n\nprivate lemma id_take_nth_drop_rl:\n  assumes \"i<length l\"\n  assumes \"\\<And>l1 x l2. \\<lbrakk>l=l1@x#l2; i = length l1 \\<rbrakk> \\<Longrightarrow> P (l1@x#l2)\"\n  shows \"P l\" \n  apply (subst id_take_nth_drop[OF assms(1)])\n  apply (rule assms(2))\n  apply (subst id_take_nth_drop[OF assms(1)])\n  apply simp\n  apply (simp add: assms(1))\n  done\n\n\nprivate lemma list_set_entails_aux: \n  shows \"list_assn A l li * A x xi \\<Longrightarrow>\\<^sub>A list_assn A (l[i := x]) (li[i := xi]) * true\"\n  apply (rule entails_preI)\n  apply (clarsimp)\n  apply (cases \"i < length l\"; cases \"i < length li\"; (sep_auto dest!: list_assn_aux_eqlen_simp;fail)?)\n  apply (erule id_take_nth_drop_rl)\n  apply (erule id_take_nth_drop_rl)\n  apply (sep_auto simp add: list_update_append)\n  done\n\nprivate lemma list_set_hd_tl_aux: \n  \"a \\<noteq> [] \\<Longrightarrow> list_assn R a c \\<Longrightarrow>\\<^sub>A R (hd a) (hd c) * true\"\n  \"a \\<noteq> [] \\<Longrightarrow> list_assn R a c \\<Longrightarrow>\\<^sub>A list_assn R (tl a) (tl c) * true\"\n  by (cases c; cases a; sep_auto; fail)+\n\nprivate lemma list_set_last_butlast_aux:\n  \"a \\<noteq> [] \\<Longrightarrow> list_assn R a c \\<Longrightarrow>\\<^sub>A R (last a) (last c) * true\"\n  \"a \\<noteq> [] \\<Longrightarrow> list_assn R a c \\<Longrightarrow>\\<^sub>A list_assn R (butlast a) (butlast c) * true\"\n  by (cases c rule: rev_cases; cases a  rule: rev_cases; sep_auto; fail)+\n\nprivate lemma swap_decomp_simp[simp]: \n  \"swap (l1 @ x # c21' @ xa # l2a) (length l1) (Suc (length l1 + length c21')) = l1@xa#c21'@x#l2a\"\n  \"swap (l1 @ x # c21' @ xa # l2a) (Suc (length l1 + length c21')) (length l1) = l1@xa#c21'@x#l2a\"\n  by (auto simp: swap_def list_update_append nth_append)\n\nprivate lemma list_swap_aux: \"\\<lbrakk>i < length l; j < length l\\<rbrakk> \\<Longrightarrow> list_assn A l li \\<Longrightarrow>\\<^sub>A list_assn A (swap l i j) (swap li i j) * true\"\n  apply (subst list_assn_aux_len; clarsimp)\n  apply (cases \"i=j\"; (sep_auto;fail)?)\n  apply (rule id_take_nth_drop_rl[where l=l and i=i]; simp)\n  apply (rule id_take_nth_drop_rl[where l=l and i=j]; simp)\n  apply (erule list_match_lel_lel; simp)\n  apply (split_list_according li l; sep_auto)\n  apply (split_list_according li l; sep_auto)\n  done\n  \nprivate lemma list_rotate1_aux: \"list_assn A a c \\<Longrightarrow>\\<^sub>A list_assn A (rotate1 a) (rotate1 c) * true\"  \n  by (cases a; cases c; sep_auto)\n\nprivate lemma list_rev_aux: \"list_assn A a c \\<Longrightarrow>\\<^sub>A list_assn A (rev a) (rev c) * true\"\n  apply (subst list_assn_aux_len; clarsimp)\n  apply (induction rule: list_induct2)\n  apply sep_auto\n  apply sep_auto\n  apply (erule ent_frame_fwd, frame_inference)\n  apply sep_auto\n  done\n\nlemma mod_starE: \n  assumes \"h \\<Turnstile> A*B\"\n  obtains h1 h2 where \"h1\\<Turnstile>A\" \"h2\\<Turnstile>B\"\n  using assms by (auto simp: mod_star_conv)\n\nprivate lemma CONSTRAINT_is_pureE:\n  assumes \"CONSTRAINT is_pure A\"\n  obtains R where \"A=pure R\"\n  using assms by (auto simp: is_pure_conv)\n\nprivate method solve_dbg = \n  ( (elim CONSTRAINT_is_pureE; (simp only: list_assn_pure_conv the_pure_pure)?)?;\n    sep_auto \n      simp: pure_def hn_ctxt_def invalid_assn_def list_assn_aux_eqlen_simp \n      intro!: hn_refineI[THEN hn_refine_preI] hfrefI \n      elim!: mod_starE\n      intro: list_set_entails_aux list_set_hd_tl_aux list_set_last_butlast_aux\n             list_swap_aux list_rotate1_aux list_rev_aux\n    ;\n    ((rule entails_preI; sep_auto simp: list_assn_aux_eqlen_simp | (parametricity; simp; fail))?)\n  )\n\nprivate method solve = solve_dbg; fail\n\n(* TODO: Establish sepref_import param mechanism that can handle this! *)\n\nlemma HOL_list_empty_hnr_aux: \"(uncurry0 (return op_list_empty), uncurry0 (RETURN op_list_empty)) \\<in> unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a (list_assn A)\" by solve\nlemma HOL_list_is_empty_hnr[sepref_fr_rules]: \"(return \\<circ> op_list_is_empty, RETURN \\<circ> op_list_is_empty) \\<in> (list_assn A)\\<^sup>k \\<rightarrow>\\<^sub>a bool_assn\" by solve\nlemma HOL_list_prepend_hnr[sepref_fr_rules]: \"(uncurry (return \\<circ>\\<circ> op_list_prepend), uncurry (RETURN \\<circ>\\<circ> op_list_prepend)) \\<in> A\\<^sup>d *\\<^sub>a (list_assn A)\\<^sup>d \\<rightarrow>\\<^sub>a list_assn A\" by solve\nlemma HOL_list_append_hnr[sepref_fr_rules]: \"(uncurry (return \\<circ>\\<circ> op_list_append), uncurry (RETURN \\<circ>\\<circ> op_list_append)) \\<in> (list_assn A)\\<^sup>d *\\<^sub>a A\\<^sup>d \\<rightarrow>\\<^sub>a list_assn A\"  by solve\nlemma HOL_list_concat_hnr[sepref_fr_rules]: \"(uncurry (return \\<circ>\\<circ> op_list_concat), uncurry (RETURN \\<circ>\\<circ> op_list_concat)) \\<in> (list_assn A)\\<^sup>d *\\<^sub>a (list_assn A)\\<^sup>d \\<rightarrow>\\<^sub>a list_assn A\"  by solve\nlemma HOL_list_length_hnr[sepref_fr_rules]: \"(return \\<circ> op_list_length, RETURN \\<circ> op_list_length) \\<in> (list_assn A)\\<^sup>k \\<rightarrow>\\<^sub>a nat_assn\"  by solve\nlemma HOL_list_set_hnr[sepref_fr_rules]: \"(uncurry2 (return \\<circ>\\<circ>\\<circ> op_list_set), uncurry2 (RETURN \\<circ>\\<circ>\\<circ> op_list_set)) \\<in> (list_assn A)\\<^sup>d *\\<^sub>a nat_assn\\<^sup>k *\\<^sub>a A\\<^sup>d \\<rightarrow>\\<^sub>a list_assn A\"  by solve\nlemma HOL_list_hd_hnr[sepref_fr_rules]: \"(return \\<circ> op_list_hd, RETURN \\<circ> op_list_hd) \\<in> [\\<lambda>y. y \\<noteq> []]\\<^sub>a (list_assn R)\\<^sup>d \\<rightarrow> R\"  by solve\nlemma HOL_list_tl_hnr[sepref_fr_rules]: \"(return \\<circ> op_list_tl, RETURN \\<circ> op_list_tl) \\<in> [\\<lambda>y. y \\<noteq> []]\\<^sub>a (list_assn A)\\<^sup>d \\<rightarrow> list_assn A\"  by solve\nlemma HOL_list_last_hnr[sepref_fr_rules]: \"(return \\<circ> op_list_last, RETURN \\<circ> op_list_last) \\<in> [\\<lambda>y. y \\<noteq> []]\\<^sub>a (list_assn R)\\<^sup>d \\<rightarrow> R\"  by solve\n\n\nlemma HOL_list_replicate_hnr[sepref_fr_rules]: \"CONSTRAINT is_pure A \\<Longrightarrow> (uncurry (return \\<circ>\\<circ> op_list_replicate), uncurry (RETURN \\<circ>\\<circ> op_list_replicate)) \\<in> nat_assn\\<^sup>k *\\<^sub>a A\\<^sup>k \\<rightarrow>\\<^sub>a list_assn A\" by solve\nlemma HOL_list_get_hnr[sepref_fr_rules]: \"CONSTRAINT is_pure A \\<Longrightarrow> (uncurry (return \\<circ>\\<circ> op_list_get), uncurry (RETURN \\<circ>\\<circ> op_list_get)) \\<in> [\\<lambda>(a, b). b < length a]\\<^sub>a (list_assn A)\\<^sup>k *\\<^sub>a nat_assn\\<^sup>k \\<rightarrow> A\" by solve\n\n(* TODO: Ad-hoc hack! *)\nprivate lemma bool_by_paramE: \"\\<lbrakk> a; (a,b)\\<in>Id \\<rbrakk> \\<Longrightarrow> b\" by simp\nprivate lemma bool_by_paramE': \"\\<lbrakk> a; (b,a)\\<in>Id \\<rbrakk> \\<Longrightarrow> b\" by simp\n\nlemma HOL_list_contains_hnr[sepref_fr_rules]: \"\\<lbrakk>CONSTRAINT is_pure A; single_valued (the_pure A); single_valued ((the_pure A)\\<inverse>)\\<rbrakk>\n  \\<Longrightarrow> (uncurry (return \\<circ>\\<circ> op_list_contains), uncurry (RETURN \\<circ>\\<circ> op_list_contains)) \\<in> A\\<^sup>k *\\<^sub>a (list_assn A)\\<^sup>k \\<rightarrow>\\<^sub>a bool_assn\" \n  apply solve_dbg\n  apply (erule bool_by_paramE[where a=\"_\\<in>set _\"]) apply parametricity\n  apply (erule bool_by_paramE'[where a=\"_\\<in>set _\"]) apply parametricity\n  done\n \n\nlemmas HOL_list_empty_hnr_mop = HOL_list_empty_hnr_aux[FCOMP mk_mop_rl0_np[OF mop_list_empty_alt]]\nlemmas HOL_list_is_empty_hnr_mop[sepref_fr_rules] = HOL_list_is_empty_hnr[FCOMP mk_mop_rl1_np[OF mop_list_is_empty_alt]]\nlemmas HOL_list_prepend_hnr_mop[sepref_fr_rules] = HOL_list_prepend_hnr[FCOMP mk_mop_rl2_np[OF mop_list_prepend_alt]]\nlemmas HOL_list_append_hnr_mop[sepref_fr_rules] = HOL_list_append_hnr[FCOMP mk_mop_rl2_np[OF mop_list_append_alt]]\nlemmas HOL_list_concat_hnr_mop[sepref_fr_rules] = HOL_list_concat_hnr[FCOMP mk_mop_rl2_np[OF mop_list_concat_alt]]\nlemmas HOL_list_length_hnr_mop[sepref_fr_rules] = HOL_list_length_hnr[FCOMP mk_mop_rl1_np[OF mop_list_length_alt]]\nlemmas HOL_list_set_hnr_mop[sepref_fr_rules] = HOL_list_set_hnr[FCOMP mk_mop_rl3[OF mop_list_set_alt]]\nlemmas HOL_list_hd_hnr_mop[sepref_fr_rules] = HOL_list_hd_hnr[FCOMP mk_mop_rl1[OF mop_list_hd_alt]]\nlemmas HOL_list_tl_hnr_mop[sepref_fr_rules] = HOL_list_tl_hnr[FCOMP mk_mop_rl1[OF mop_list_tl_alt]]\nlemmas HOL_list_last_hnr_mop[sepref_fr_rules] = HOL_list_last_hnr[FCOMP mk_mop_rl1[OF mop_list_last_alt]]\nlemmas HOL_list_butlast_hnr_mop[sepref_fr_rules] = HOL_list_butlast_hnr[FCOMP mk_mop_rl1[OF mop_list_butlast_alt]]\nlemmas HOL_list_swap_hnr_mop[sepref_fr_rules] = HOL_list_swap_hnr[FCOMP mk_mop_rl3[OF mop_list_swap_alt]]\nlemmas HOL_list_rotate1_hnr_mop[sepref_fr_rules] = HOL_list_rotate1_hnr[FCOMP mk_mop_rl1_np[OF mop_list_rotate1_alt]]\nlemmas HOL_list_rev_hnr_mop[sepref_fr_rules] = HOL_list_rev_hnr[FCOMP mk_mop_rl1_np[OF mop_list_rev_alt]]\nlemmas HOL_list_replicate_hnr_mop[sepref_fr_rules] = HOL_list_replicate_hnr[FCOMP mk_mop_rl2_np[OF mop_list_replicate_alt]]\nlemmas HOL_list_get_hnr_mop[sepref_fr_rules] = HOL_list_get_hnr[FCOMP mk_mop_rl2[OF mop_list_get_alt]]\nlemmas HOL_list_contains_hnr_mop[sepref_fr_rules] = HOL_list_contains_hnr[FCOMP mk_mop_rl2_np[OF mop_list_contains_alt]]\n\nlemmas HOL_list_empty_hnr = HOL_list_empty_hnr_aux HOL_list_empty_hnr_mop\n\nend\n\ndefinition [simp]: \"op_HOL_list_empty \\<equiv> op_list_empty\"\ninterpretation HOL_list: list_custom_empty \"list_assn A\" \"return []\" op_HOL_list_empty\n  apply unfold_locales\n  apply (sep_auto intro!: hfrefI hn_refineI)\n  by simp\n\n\nschematic_goal\n  notes [sepref_fr_rules] = HOL_list_empty_hnr\n  shows\n  \"hn_refine (emp) (?c::?'c Heap) ?\\<Gamma>' ?R (do {\n    x \\<leftarrow> RETURN [1,2,3::nat];\n    let x2 = op_list_append x 5;\n    ASSERT (length x = 4);\n    let x = op_list_swap x 1 2;\n    x \\<leftarrow> mop_list_swap x 1 2;\n    RETURN (x@x)\n  })\"  \n    by sepref\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Evaluation/Refine_Imperative_HOL/IICF/Impl/IICF_HOL_List.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5078118642792044, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.2618379106627909}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: GPL-2.0-only\n *)\n\ntheory Sep_Tactic_Examples\nimports\n  \"SepDSpec.Sep_Tactic_Helper\"\n  KHeap_DP\nbegin\n\n\n(* Thesis : Automated Tactics for Seperation Logic *)\n\n(* seperation logic *)\n\n(* after we show that addition and disjointedness on our heap obeys certain laws, we get a seperation algebra *)\n\n(* connectives *)\n\nterm \"P \\<and>* Q\"\n\nterm \"P \\<longrightarrow>* Q\"\n\nlemma frame_rule:\n  \"\\<And>R. \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>_. Q\\<rbrace> \\<Longrightarrow> \\<lbrace>P \\<and>* R\\<rbrace> f \\<lbrace>\\<lambda>_. Q \\<and>* R\\<rbrace>\"\n  oops\n\nlemma\n \"\\<lbrace><dest \\<mapsto>c - \\<and>* src \\<mapsto>c cap \\<and>* R>\\<rbrace>\n    move_cap cap' src dest\n  \\<lbrace>\\<lambda>_. <dest \\<mapsto>c cap'  \\<and>* src \\<mapsto>c NullCap \\<and>* R>\\<rbrace>\"\n  apply (simp add: move_cap_def)\n  apply (wp swap_parents_wp set_cap_wp) (* set_cap doesn't apply *)\nthm set_cap_wp[no_vars]\n   apply (rule hoare_strengthen_post)\n    apply (wp set_cap_wp)\n   apply (clarsimp simp: sep_conj_ac )\noops\n\n\n(* tactics we had pre-thesis *)\n\nlemma \"(A \\<and>* B \\<and>* C \\<and>* D) s  \\<Longrightarrow>  (A \\<and>* B \\<and>* C \\<and>* D) s\"\n  apply (sep_select 4)\n  apply (sep_select_asm 3)\n  apply (sep_select 2)\n  apply (sep_cancel)\n  apply (sep_cancel)\n  apply (sep_cancel)\ndone\n\n(* forward reasoning *)\n\n\nlemma example_drule:\n  \"(ptr \\<mapsto>o obj) s\n  \\<Longrightarrow> (ptr \\<mapsto>S obj \\<and>* ptr \\<mapsto>f obj) s\"\n  by (metis sep_conj_commute sep_map_o_decomp)\n\nlemma sep_drule_example:\n  \"(ptr \\<mapsto>o obj \\<and>* A \\<and>* B ) s\n  \\<Longrightarrow> (A \\<and>* B \\<and>* ptr \\<mapsto>f obj \\<and>* ptr \\<mapsto>S obj) s\"\n  apply (sep_drule  example_drule)\n  apply (sep_solve)\ndone\n\n(* backwards reasoning *)\n\nlemma example_rule:\n  \"(ptr \\<mapsto>f obj \\<and>* ptr \\<mapsto>S obj) s\n  \\<Longrightarrow> (ptr \\<mapsto>o obj) s\"\n  by (metis sep_map_o_decomp)\n\nlemma sep_rule_example: \"(ptr \\<mapsto>f obj \\<and>* A \\<and>* B \\<and>* ptr \\<mapsto>S obj ) s \\<Longrightarrow> (ptr \\<mapsto>o obj \\<and>* A \\<and>* B) s\"\n  apply (sep_rule example_rule)\n  apply (sep_solve)\ndone\n\n\n\n(* the state of proving before new stuff *)\n\nlemma swap_cap_wp_old:\n  \"\\<lbrace><dest \\<mapsto>c cap \\<and>*  src \\<mapsto>c cap' \\<and>* R>\\<rbrace>\n    swap_cap cap' src cap dest\n   \\<lbrace>\\<lambda>_.<dest \\<mapsto>c cap' \\<and>* src \\<mapsto>c cap \\<and>* R>\\<rbrace>\"\n  apply (clarsimp simp add: swap_cap_def)\n  apply (wp swap_parents_wp set_cap_wp)\n  apply (rule hoare_chain)\n    apply (rule set_cap_wp)\n    apply (sep_solve)+\ndone\n\n\nlemma move_cap_wp_old:\n \"\\<lbrace><dest \\<mapsto>c - \\<and>* src \\<mapsto>c cap \\<and>* R>\\<rbrace>\n    move_cap cap' src dest\n  \\<lbrace>\\<lambda>_. <dest \\<mapsto>c cap'  \\<and>* src \\<mapsto>c NullCap \\<and>* R>\\<rbrace>\"\n  including no_pre\n  apply (simp add: move_cap_def)\n  apply (wp swap_parents_wp)\n   apply (rule hoare_strengthen_post)\n    apply (rule set_cap_wp)\n   apply (sep_select 2)\n   apply (sep_solve)\n  apply (rule hoare_chain)\n    apply (rule insert_cap_orphan_wp)\n   apply (sep_solve)\n  apply (sep_solve)\ndone\n\nlemma invoke_cnode_rotate2_wp_old:\n  \"(dest) \\<noteq> (rnd) \\<Longrightarrow>\n  \\<lbrace><dest \\<mapsto>c cap1 \\<and>* src \\<mapsto>c cap2 \\<and>*\n    rnd \\<mapsto>c - \\<and>* R>\\<rbrace>\n     invoke_cnode (RotateCall cap1 cap2 dest src rnd)\n  \\<lbrace>\\<lambda>_. <dest \\<mapsto>c NullCap \\<and>* src \\<mapsto>c cap1 \\<and>*\n    rnd \\<mapsto>c cap2 \\<and>* R>\\<rbrace>\"\n  including no_pre\n  apply (clarsimp simp: invoke_cnode_def)\n  apply (wp)\n   apply (rule hoare_strengthen_post)\n    apply (rule move_cap_wp)\n   apply (sep_solve )\n  apply (rule hoare_chain)\n    apply (rule move_cap_wp)\n   apply (sep_select_asm 2, sep_select_asm 3)\n   apply (sep_solve)\n  apply (sep_solve)\ndone\n\n(* new sep_select/asm *)\n\nlemma \"(A \\<and>* B \\<and>* C \\<and>* D) s  \\<Longrightarrow>  (A \\<and>* B \\<and>* C \\<and>* D) s\"\n  apply (sep_select 4 3 2 1)\n  apply (sep_select_asm 4 3 2 1)\n  apply (sep_select_asm 2 4)\noops\n\n\n(* sep_select_pre/post *)\n\nlemma \"\\<lbrace>A \\<and>* B \\<and>* C \\<and>* D\\<rbrace> f \\<lbrace>\\<lambda>_. A \\<and>* B \\<and>* C \\<and>* D\\<rbrace>\"\n  apply (sep_select_pre 4 1 2 3)\n  apply (sep_select_post 3 4 2 1)\n  apply (sep_select_post 3 4)\noops\n\n(* can be made to work for arbitrary monads *)\n\nlemma \"\\<lbrace>A \\<and>* B \\<and>* C \\<and>* D\\<rbrace> f \\<lbrace>\\<lambda>_. A \\<and>* B \\<and>* C \\<and>* D\\<rbrace>, \\<lbrace>E\\<rbrace>\"\n  apply (sep_select_pre 4 1 2 3)\n  apply (sep_select_post 3 4 2 1)\n  apply (sep_select_post 3 4)\noops\n\nlemma \"\\<lbrace>A \\<and>* B \\<and>* C \\<and>* D\\<rbrace> f \\<lbrace>\\<lambda>_. A \\<and>* B \\<and>* C \\<and>* D\\<rbrace>, -\"\n  apply (sep_select_pre 4 1 2 3)\n  apply (sep_select_post 3 4 2 1)\n  apply (sep_select_post 3 4)\noops\n\nlemma \"(P \\<and>* (P \\<longrightarrow>* Q)) s \\<Longrightarrow> Q s\"\n  apply (sep_mp, assumption )\n  done\n\nlemma \"P s \\<Longrightarrow> (Q \\<longrightarrow>* (P \\<and>* Q)) s\"\n  apply (erule sep_curry[rotated])\n  apply (assumption)\n  done\n\n\n(* wp tactic testing *)\n\n\n(* sep_wand approach *)\n\nmethod_setup debug = \\<open>\n  Attrib.thms >> (fn _ => fn ctxt =>\n   let\n     val wp_pre_tac = SELECT_GOAL (NO_CONTEXT_TACTIC ctxt\n                      (Method_Closure.apply_method ctxt @{method wp_pre} [] [] [] ctxt []))\n   in\n     SIMPLE_METHOD' (CHANGED o wp_pre_tac)\n   end\n)\n\\<close>\n\nlemma move_cap_wp2:\n \"\\<lbrace><dest \\<mapsto>c - \\<and>* src \\<mapsto>c cap \\<and>* R>\\<rbrace>\n    move_cap cap' src dest\n  \\<lbrace>\\<lambda>_. <dest \\<mapsto>c cap'  \\<and>* src \\<mapsto>c NullCap \\<and>* R>\\<rbrace>\"\n  apply (simp add: move_cap_def)\n  apply (sep_wp set_cap_wp swap_parents_wp insert_cap_orphan_wp)+\n  apply (sep_solve)\n  done\n\nlemma swap_cap_wp2:\n  \"\\<lbrace><dest \\<mapsto>c cap \\<and>*  src \\<mapsto>c cap' \\<and>* R>\\<rbrace>\n    swap_cap cap' src cap dest\n   \\<lbrace>\\<lambda>_.<dest \\<mapsto>c cap' \\<and>* src \\<mapsto>c cap \\<and>* R>\\<rbrace>\"\n  apply (clarsimp simp: swap_cap_def)\n  apply (sep_wp swap_parents_wp set_cap_wp)+\n  apply (sep_solve)\n  done\n\nlemma invoke_cnode_rotate2_wp:\n  \"(dest) \\<noteq> (rnd) \\<Longrightarrow>\n  \\<lbrace><dest \\<mapsto>c cap1 \\<and>* src \\<mapsto>c cap2 \\<and>*\n    rnd \\<mapsto>c - \\<and>* R>\\<rbrace>\n     invoke_cnode (RotateCall cap1 cap2 dest src rnd)\n  \\<lbrace>\\<lambda>_. <dest \\<mapsto>c NullCap \\<and>* src \\<mapsto>c cap1 \\<and>*\n    rnd \\<mapsto>c cap2 \\<and>* R>\\<rbrace>\"\n  apply (clarsimp simp: invoke_cnode_def)\n  apply (sep_wp move_cap_wp)+\n  apply (sep_solve)\n  done\n\n\n(* sep_drule/rule *)\n\nlemma sep_rule_example2:\n \"\\<lbrakk>(ptr \\<mapsto>o obj) s; finite (dom (object_slots obj))\\<rbrakk> \\<Longrightarrow>\n   (ptr \\<mapsto>E obj \\<and>* ptr \\<mapsto>f obj \\<and>* (\\<And>* slot\\<in>dom (object_slots obj). (ptr, slot) \\<mapsto>s obj)) s\"\n  apply (subst (asm) sep_map_o_decomp)\n  apply (subst (asm) sep_map_S_decomp, simp+)\n  apply sep_solve\n  done\n\nlemma sep_drule_example2:\n \"\\<lbrakk>(ptr \\<mapsto>f obj \\<and>* (\\<And>* slot\\<in>dom (object_slots obj). (ptr, slot) \\<mapsto>s obj) \\<and>* ptr \\<mapsto>E obj) s;\n   finite (dom (object_slots obj))\\<rbrakk>\n    \\<Longrightarrow>\n  (ptr \\<mapsto>o obj) s\"\n  by (metis sep_map_S_decomp sep_map_o_decomp)\n\n(* sep_curry *)\n\nlemma sep_drule_example_lemma:\n  \"\\<lbrakk>(H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* ptr \\<mapsto>f obj \\<and>* A \\<and>* B \\<and>*\n    (\\<And>* slot\\<in>dom (object_slots obj). (ptr, slot) \\<mapsto>s obj) \\<and>* D \\<and>* G \\<and>* E \\<and>* F \\<and>* ptr \\<mapsto>E obj ) s;\n    finite (dom (object_slots obj))\\<rbrakk>\n  \\<Longrightarrow>\n   (D \\<and>* G \\<and>* E \\<and>* F  \\<and>* ptr \\<mapsto>o obj \\<and>* H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* A \\<and>* B) s\"\n  apply (sep_drule sep_drule_example2)\n   apply assumption\n  apply sep_solve\n  done\n\n\n(* sep_back *)\n\n\nlemma sep_rule_example_lemma:\n \"\\<lbrakk>(H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* ptr \\<mapsto>o obj \\<and>* A \\<and>* B \\<and>* D \\<and>* G \\<and>* E \\<and>* F ) s;\n  finite (dom (object_slots obj))\\<rbrakk> \\<Longrightarrow>\n  (D \\<and>* G \\<and>* E \\<and>* F  \\<and>* ptr \\<mapsto>f obj \\<and>* H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* ptr \\<mapsto>E obj \\<and>*\n   A \\<and>* B \\<and>* (\\<And>* slot\\<in>dom (object_slots obj). (ptr, slot) \\<mapsto>s obj)) s\"\n  apply (sep_rule sep_rule_example2)\n   apply sep_solve\n  apply assumption\n  done\n\n\n(* works even with multiple conjuncts in assumptions and conclusions *)\nlemma sep_rule_double_conjunct_example:\n  \"\\<lbrakk>((obj_id, slot) \\<mapsto>c cap \\<and>* obj_id \\<mapsto>f obj) s;\n    object_slots obj slot = Some cap\\<rbrakk>\n  \\<Longrightarrow> ((obj_id, slot) \\<mapsto>s obj \\<and>* obj_id \\<mapsto>f obj) s\"\n  apply (sep_drule sep_map_s_sep_map_c)\n   apply assumption\n  apply (sep_cancel)+\n  done\n\nlemma sep_rule_double_conjunct_lemma:\n  \"\\<lbrakk>(H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* obj_id \\<mapsto>f obj \\<and>* A \\<and>* B \\<and>* D \\<and>* G \\<and>* E \\<and>* F \\<and>* (obj_id, slot) \\<mapsto>c cap ) s;\n    object_slots obj slot = Some cap\\<rbrakk> \\<Longrightarrow>\n   (D \\<and>* G \\<and>* E \\<and>* F  \\<and>*(obj_id, slot) \\<mapsto>s obj \\<and>* H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* A \\<and>* B \\<and>*  obj_id \\<mapsto>f obj) s\"\n  apply (sep_rule sep_rule_double_conjunct_example)\n   apply sep_solve\n  apply assumption\n  done\n\n(* side-conditions*)\n\n\nlemma sep_drule_side_condition_lemma:\n \"\\<lbrakk>(H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* obj_id \\<mapsto>f obj \\<and>* A \\<and>* B \\<and>* D \\<and>* G \\<and>* E \\<and>* F \\<and>* (obj_id, slot) \\<mapsto>c cap ) s;\n    object_slots obj slot = Some cap\\<rbrakk> \\<Longrightarrow>\n   (D \\<and>* G \\<and>* E \\<and>* F  \\<and>*(obj_id, slot) \\<mapsto>s obj \\<and>* H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* A \\<and>* B \\<and>*  obj_id \\<mapsto>f obj) s\"\n  apply (sep_drule sep_rule_double_conjunct_example, assumption)\n  apply (sep_solve)\n  done\n\nschematic_goal \"(P \\<and>* ?A) s \\<Longrightarrow> (A \\<and>* B \\<and>* P) s\"\n  apply (sep_solve)\n  done\n\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/proof/capDL-api/Sep_Tactic_Examples.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5078118642792044, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.2618379106627909}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory Sep_ImpI\nimports Sep_Provers Sep_Cancel_Set Sep_Tactic_Helpers\nbegin\n\nlemma sep_wand_lens: \"(\\<And>s. T s = Q s) \\<Longrightarrow> ((P \\<longrightarrow>* T) \\<and>* R) s \\<Longrightarrow> ((P \\<longrightarrow>* Q) \\<and>* R) s\"\n  apply (sep_erule_full refl_imp)\n  apply (clarsimp simp: sep_impl_def)\n  done\n\nlemma sep_wand_lens': \"(\\<And>s. T s = Q s) \\<Longrightarrow> ((T \\<longrightarrow>* P) \\<and>* R) s \\<Longrightarrow> ((Q \\<longrightarrow>* P) \\<and>* R) s\" \n  apply (sep_erule_full refl_imp, erule sep_curry[rotated])\n  apply (clarsimp)\n  apply (erule sep_mp)\n  done\n\n(* Removing wands from the conclusions *)\n\nML {* \n\nfun sep_wand_lens ctxt = resolve_tac ctxt[@{thm sep_wand_lens}]\nfun sep_wand_lens' ctxt = resolve_tac ctxt [@{thm sep_wand_lens'}]\n\nfun sep_wand_rule_tac tac ctxt =\n  let\n    val r = rotator' ctxt\n  in \n    tac |> r (sep_wand_lens' ctxt) |> r (sep_wand_lens ctxt) |> r (sep_select ctxt)\n  end\n\nfun sep_wand_rule_tac' thms ctxt =\n  let \n    val r = rotator' ctxt\n  in\n    eresolve_tac ctxt thms |> r (sep_wand_lens ctxt) |> r (sep_select ctxt) |> r (sep_asm_select ctxt)\n  end\n\nfun sep_wand_rule_method thms ctxt = SIMPLE_METHOD' (sep_wand_rule_tac thms ctxt)\nfun sep_wand_rule_method' thms ctxt = SIMPLE_METHOD' (sep_wand_rule_tac' thms ctxt)\n\n*}\n\n\nlemma sep_wand_match:\n  \"(\\<And>s. Q s \\<Longrightarrow> Q' s)  \\<Longrightarrow> (R \\<longrightarrow>* R') s    ==>  (Q \\<and>* R \\<longrightarrow>* Q' \\<and>* R') s\" \n  apply (erule sep_curry[rotated])\n  apply (sep_select_asm 1 3)\n  apply (sep_drule (direct) sep_mp_frame)\n  apply (sep_erule_full refl_imp, clarsimp)\n  done\n\nlemma sep_wand_trivial:    \"(\\<And>s. Q s \\<Longrightarrow> Q' s) \\<Longrightarrow> R' s            ==>   (Q \\<longrightarrow>* Q' \\<and>* R') s\"\n  apply (erule sep_curry[rotated])\n  apply (sep_erule_full refl_imp)\n  apply (clarsimp)\n  done \n\nlemma sep_wand_collapse:  \"(P \\<and>* Q \\<longrightarrow>* R) s \\<Longrightarrow> (P \\<longrightarrow>* Q \\<longrightarrow>* R) s \"\n  apply (erule sep_curry[rotated])+\n  apply (clarsimp simp: sep_conj_assoc)\n  apply (erule sep_mp)\n done\n\nlemma sep_wand_match_less_safe: \n  assumes drule: \" \\<And>s. (Q' \\<and>* R) s \\<Longrightarrow> ((P \\<longrightarrow>* R') \\<and>* Q' \\<and>* R'' ) s \"\n  shows \"(Q' \\<and>* R) s \\<Longrightarrow> (\\<And>s. Q' s \\<Longrightarrow> Q s) \\<Longrightarrow> ((P \\<longrightarrow>* Q \\<and>* R') \\<and>* R'') s\" \n  apply (drule drule)\n  apply (sep_erule_full refl_imp)\n  apply (erule sep_conj_sep_impl)\n  apply (clarsimp simp: sep_conj_assoc)\n  apply (sep_select_asm 1 3)\n  apply (sep_drule (direct) sep_mp_frame, sep_erule_full refl_imp)\n  apply (clarsimp)\n done\n \nML {*\nfun sep_match_trivial_tac ctxt =\n  let\n    fun flip f a b = f b a \n    val sep_cancel = flip (sep_apply_tactic ctxt) (SepCancel_Rules.get ctxt |> rev)\n    fun f x = x |> rotate_prems ~1 |> (fn x => [x]) |> eresolve0_tac |> sep_cancel\n    val sep_thms = map f [@{thm sep_wand_trivial}, @{thm sep_wand_match}]\n  in\n    sep_wand_rule_tac (resolve0_tac [@{thm sep_rule}] THEN' FIRST' sep_thms) ctxt\n  end\n\nfun sep_safe_method ctxt = SIMPLE_METHOD' (sep_match_trivial_tac ctxt)\n*}\n\nmethod_setup sep_safe = {* \n  Scan.succeed (sep_safe_method) \n*}\n\nend\n", "meta": {"author": "pirapira", "repo": "eth-isabelle", "sha": "d0bb02b3e64a2046a7c9670545d21f10bccd7b27", "save_path": "github-repos/isabelle/pirapira-eth-isabelle", "path": "github-repos/isabelle/pirapira-eth-isabelle/eth-isabelle-d0bb02b3e64a2046a7c9670545d21f10bccd7b27/sep_algebra/Sep_ImpI.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5078118642792044, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.2618379106627909}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory NonDetMonadVCG\nimports NonDetMonadLemmas WP WPC\nbegin\n\ndeclare K_def [simp]\n\nsection \"Satisfiability\"\n\ntext {*\n  The dual to validity: an existential instead of a universal\n  quantifier for the post condition. In refinement, it is\n  often sufficient to know that there is one state that\n  satisfies a condition.\n*}\ndefinition\n  exs_valid :: \"('a \\<Rightarrow> bool) \\<Rightarrow> ('a, 'b) nondet_monad \\<Rightarrow>\n                ('b \\<Rightarrow> 'a \\<Rightarrow> bool) \\<Rightarrow> bool\"\n  (\"\\<lbrace>_\\<rbrace> _ \\<exists>\\<lbrace>_\\<rbrace>\")\nwhere\n \"exs_valid P f Q \\<equiv> (\\<forall>s. P s \\<longrightarrow> (\\<exists>(rv, s') \\<in> fst (f s). Q rv s'))\"\n\n\ntext {* The above for the exception monad *}\ndefinition\n  ex_exs_validE :: \"('a \\<Rightarrow> bool) \\<Rightarrow> ('a, 'e + 'b) nondet_monad \\<Rightarrow>\n                    ('b \\<Rightarrow> 'a \\<Rightarrow> bool) \\<Rightarrow> ('e \\<Rightarrow> 'a \\<Rightarrow> bool) \\<Rightarrow> bool\"\n   (\"\\<lbrace>_\\<rbrace> _ \\<exists>\\<lbrace>_\\<rbrace>, \\<lbrace>_\\<rbrace>\")\nwhere\n \"ex_exs_validE P f Q E \\<equiv>\n     exs_valid P f (\\<lambda>rv. case rv of Inl e \\<Rightarrow> E e | Inr v \\<Rightarrow> Q v)\"\n\n\nsection \"Lemmas\"\n\nsubsection {* Determinism *}\n\nlemma det_set_iff:\n  \"det f \\<Longrightarrow> (r \\<in> fst (f s)) = (fst (f s) = {r})\"\n  apply (simp add: det_def)\n  apply (rule iffI)\n  apply (erule_tac x=s in allE)\n  apply auto\n  done\n\nlemma return_det [iff]:\n  \"det (return x)\"\n  by (simp add: det_def return_def)\n\nlemma put_det [iff]:\n  \"det (put s)\"\n  by (simp add: det_def put_def)\n\nlemma get_det [iff]:\n  \"det get\"\n  by (simp add: det_def get_def)\n\nlemma det_gets [iff]:\n  \"det (gets f)\"\n  by (auto simp add: gets_def det_def get_def return_def bind_def)\n\nlemma det_UN:\n  \"det f \\<Longrightarrow> (\\<Union>x \\<in> fst (f s). g x) = (g (THE x. x \\<in> fst (f s)))\"\n  unfolding det_def\n  apply simp\n  apply (drule spec [of _ s])\n  apply clarsimp\n  done\n\nlemma bind_detI [simp, intro!]:\n  \"\\<lbrakk> det f; \\<forall>x. det (g x) \\<rbrakk> \\<Longrightarrow> det (f >>= g)\"\n  apply (simp add: bind_def det_def split_def)\n  apply clarsimp\n  apply (erule_tac x=s in allE)\n  apply clarsimp\n  apply (erule_tac x=\"a\" in allE)\n  apply (erule_tac x=\"b\" in allE)\n  apply clarsimp\n  done\n\nlemma the_run_stateI:\n  \"fst (M s) = {s'} \\<Longrightarrow> the_run_state M s = s'\"\n  by (simp add: the_run_state_def)\n\nlemma the_run_state_det:\n  \"\\<lbrakk> s' \\<in> fst (M s); det M \\<rbrakk> \\<Longrightarrow> the_run_state M s = s'\"\n  by (simp add: the_run_stateI det_set_iff)\n\nsubsection \"Lifting and Alternative Basic Definitions\"\n\nlemma liftE_liftM: \"liftE = liftM Inr\"\n  apply (rule ext)\n  apply (simp add: liftE_def liftM_def)\n  done\n\nlemma liftME_liftM: \"liftME f = liftM (case_sum Inl (Inr \\<circ> f))\"\n  apply (rule ext)\n  apply (simp add: liftME_def liftM_def bindE_def returnOk_def lift_def)\n  apply (rule_tac f=\"bind x\" in arg_cong)\n  apply (rule ext)\n  apply (case_tac xa)\n   apply (simp_all add: lift_def throwError_def)\n  done\n\nlemma liftE_bindE:\n  \"(liftE a) >>=E b = a >>= b\"\n  apply (simp add: liftE_def bindE_def lift_def bind_assoc)\n  done\n\nlemma liftM_id[simp]: \"liftM id = id\"\n  apply (rule ext)\n  apply (simp add: liftM_def)\n  done\n\nlemma liftM_bind:\n  \"(liftM t f >>= g) = (f >>= (\\<lambda>x. g (t x)))\"\n  by (simp add: liftM_def bind_assoc)\n\nlemma gets_bind_ign: \"gets f >>= (\\<lambda>x. m) = m\"\n  apply (rule ext)\n  apply (simp add: bind_def simpler_gets_def)\n  done\n\nlemma get_bind_apply: \"(get >>= f) x = f x x\"\n  by (simp add: get_def bind_def)\n\n\n\nlemma exec_get:\n  \"(get >>= m) s = m s s\"\n  by (simp add: get_def bind_def)\n\nlemma bind_eqI:\n  \"\\<lbrakk> f = f'; \\<And>x. g x = g' x \\<rbrakk> \\<Longrightarrow> f >>= g = f' >>= g'\"\n  apply (rule ext)\n  apply (simp add: bind_def)\n  apply (auto simp: split_def)\n  done\n\nsubsection \"Simplification Rules for Lifted And/Or\"\n\nlemma pred_andE[elim!]: \"\\<lbrakk> (A and B) x; \\<lbrakk> A x; B x \\<rbrakk> \\<Longrightarrow> R \\<rbrakk> \\<Longrightarrow> R\"\n  by(simp add:pred_conj_def)\n\nlemma pred_andI[intro!]: \"\\<lbrakk> A x; B x \\<rbrakk> \\<Longrightarrow> (A and B) x\"\n  by(simp add:pred_conj_def)\n\nlemma pred_conj_app[simp]: \"(P and Q) x = (P x \\<and> Q x)\"\n  by(simp add:pred_conj_def)\n\nlemma bipred_andE[elim!]: \"\\<lbrakk> (A And B) x y; \\<lbrakk> A x y; B x y \\<rbrakk> \\<Longrightarrow> R \\<rbrakk> \\<Longrightarrow> R\"\n  by(simp add:bipred_conj_def)\n\nlemma bipred_andI[intro!]: \"\\<lbrakk> A x y; B x y \\<rbrakk> \\<Longrightarrow> (A And B) x y\"\n  by (simp add:bipred_conj_def)\n\nlemma bipred_conj_app[simp]: \"(P And Q) x = (P x and Q x)\"\n  by(simp add:pred_conj_def bipred_conj_def)\n\nlemma pred_disjE[elim!]: \"\\<lbrakk> (P or Q) x; P x \\<Longrightarrow> R; Q x \\<Longrightarrow> R \\<rbrakk> \\<Longrightarrow> R\"\n  by (fastforce simp: pred_disj_def)\n\nlemma pred_disjI1[intro]: \"P x \\<Longrightarrow> (P or Q) x\"\n  by (simp add: pred_disj_def)\n\nlemma pred_disjI2[intro]: \"Q x \\<Longrightarrow> (P or Q) x\"\n  by (simp add: pred_disj_def)\n\nlemma pred_disj_app[simp]: \"(P or Q) x = (P x \\<or> Q x)\"\n  by auto\n\nlemma bipred_disjI1[intro]: \"P x y \\<Longrightarrow> (P Or Q) x y\"\n  by (simp add: bipred_disj_def)\n\nlemma bipred_disjI2[intro]: \"Q x y \\<Longrightarrow> (P Or Q) x y\"\n  by (simp add: bipred_disj_def)\n\nlemma bipred_disj_app[simp]: \"(P Or Q) x = (P x or Q x)\"\n  by(simp add:pred_disj_def bipred_disj_def)\n\nlemma pred_notnotD[simp]: \"(not not P) = P\"\n  by(simp add:pred_neg_def)\n\nlemma pred_and_true[simp]: \"(P and \\<top>) = P\"\n  by(simp add:pred_conj_def)\n\nlemma pred_and_true_var[simp]: \"(\\<top> and P) = P\"\n  by(simp add:pred_conj_def)\n\nlemma pred_and_false[simp]: \"(P and \\<bottom>) = \\<bottom>\"\n  by(simp add:pred_conj_def)\n\nlemma pred_and_false_var[simp]: \"(\\<bottom> and P) = \\<bottom>\"\n  by(simp add:pred_conj_def)\n\nsubsection \"Hoare Logic Rules\"\n\nlemma validE_def2:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>R\\<rbrace> \\<equiv> \\<forall>s. P s \\<longrightarrow> (\\<forall>(r,s') \\<in> fst (f s). case r of Inr b \\<Rightarrow> Q b s'\n                                                              | Inl a \\<Rightarrow> R a s')\"\n  by (unfold valid_def validE_def)\n\nlemma seq':\n  \"\\<lbrakk> \\<lbrace>A\\<rbrace> f \\<lbrace>B\\<rbrace>;\n     \\<forall>x. P x \\<longrightarrow> \\<lbrace>C\\<rbrace> g x \\<lbrace>D\\<rbrace>;\n     \\<forall>x s. B x s \\<longrightarrow> P x \\<and> C s \\<rbrakk> \\<Longrightarrow>\n   \\<lbrace>A\\<rbrace> do x \\<leftarrow> f; g x od \\<lbrace>D\\<rbrace>\"\n  apply (clarsimp simp: valid_def bind_def)\n  apply fastforce\n  done\n\nlemma seq:\n  assumes f_valid: \"\\<lbrace>A\\<rbrace> f \\<lbrace>B\\<rbrace>\"\n  assumes g_valid: \"\\<And>x. P x \\<Longrightarrow> \\<lbrace>C\\<rbrace> g x \\<lbrace>D\\<rbrace>\"\n  assumes bind:  \"\\<And>x s. B x s \\<Longrightarrow> P x \\<and> C s\"\n  shows \"\\<lbrace>A\\<rbrace> do x \\<leftarrow> f; g x od \\<lbrace>D\\<rbrace>\"\napply (insert f_valid g_valid bind)\napply (blast intro: seq')\ndone\n\nlemma seq_ext':\n  \"\\<lbrakk> \\<lbrace>A\\<rbrace> f \\<lbrace>B\\<rbrace>;\n     \\<forall>x. \\<lbrace>B x\\<rbrace> g x \\<lbrace>C\\<rbrace> \\<rbrakk> \\<Longrightarrow>\n   \\<lbrace>A\\<rbrace> do x \\<leftarrow> f; g x od \\<lbrace>C\\<rbrace>\"\n  by (fastforce simp: valid_def bind_def Let_def split_def)\n\nlemma seq_ext:\n  assumes f_valid: \"\\<lbrace>A\\<rbrace> f \\<lbrace>B\\<rbrace>\"\n  assumes g_valid: \"\\<And>x. \\<lbrace>B x\\<rbrace> g x \\<lbrace>C\\<rbrace>\"\n  shows \"\\<lbrace>A\\<rbrace> do x \\<leftarrow> f; g x od \\<lbrace>C\\<rbrace>\"\n apply(insert f_valid g_valid)\n apply(blast intro: seq_ext')\ndone\n\nlemma seqE':\n  \"\\<lbrakk> \\<lbrace>A\\<rbrace> f \\<lbrace>B\\<rbrace>,\\<lbrace>E\\<rbrace>;\n     \\<forall>x. \\<lbrace>B x\\<rbrace> g x \\<lbrace>C\\<rbrace>,\\<lbrace>E\\<rbrace> \\<rbrakk> \\<Longrightarrow>\n   \\<lbrace>A\\<rbrace> doE x \\<leftarrow> f; g x odE \\<lbrace>C\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  apply(simp add:bindE_def lift_def bind_def Let_def split_def)\n  apply(clarsimp simp:validE_def2)\n  apply (fastforce simp add: throwError_def return_def lift_def\n                  split: sum.splits)\n  done\n\nlemma seqE:\n  assumes f_valid: \"\\<lbrace>A\\<rbrace> f \\<lbrace>B\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  assumes g_valid: \"\\<And>x. \\<lbrace>B x\\<rbrace> g x \\<lbrace>C\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  shows \"\\<lbrace>A\\<rbrace> doE x \\<leftarrow> f; g x odE \\<lbrace>C\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  apply(insert f_valid g_valid)\n  apply(blast intro: seqE')\n  done\n\nlemma hoare_TrueI: \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>_. \\<top>\\<rbrace>\"\n  by (simp add: valid_def)\n\nlemma hoareE_TrueI: \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>_. \\<top>\\<rbrace>, \\<lbrace>\\<lambda>r. \\<top>\\<rbrace>\"\n  by (simp add: validE_def valid_def)\n\nlemma hoare_True_E_R [simp]:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. True\\<rbrace>, -\"\n  by (auto simp add: validE_R_def validE_def valid_def split: sum.splits)\n\nlemma hoare_post_conj [intro!]:\n  \"\\<lbrakk> \\<lbrace> P \\<rbrace> a \\<lbrace> Q \\<rbrace>; \\<lbrace> P \\<rbrace> a \\<lbrace> R \\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace> P \\<rbrace> a \\<lbrace> Q And R \\<rbrace>\"\n  by (fastforce simp: valid_def split_def bipred_conj_def)\n\nlemma hoare_pre_disj [intro!]:\n  \"\\<lbrakk> \\<lbrace> P \\<rbrace> a \\<lbrace> R \\<rbrace>; \\<lbrace> Q \\<rbrace> a \\<lbrace> R \\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace> P or Q \\<rbrace> a \\<lbrace> R \\<rbrace>\"\n  by (simp add:valid_def pred_disj_def)\n\nlemma hoare_conj:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>; \\<lbrace>P'\\<rbrace> f \\<lbrace>Q'\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>P and P'\\<rbrace> f \\<lbrace>Q And Q'\\<rbrace>\"\n  unfolding valid_def by auto\n\nlemma hoare_post_taut: \"\\<lbrace> P \\<rbrace> a \\<lbrace> \\<top>\\<top> \\<rbrace>\"\n  by (simp add:valid_def)\n\nlemma wp_post_taut: \"\\<lbrace>\\<lambda>r. True\\<rbrace> f \\<lbrace>\\<lambda>r s. True\\<rbrace>\"\n  by (rule hoare_post_taut)\n\nlemma wp_post_tautE: \"\\<lbrace>\\<lambda>r. True\\<rbrace> f \\<lbrace>\\<lambda>r s. True\\<rbrace>,\\<lbrace>\\<lambda>f s. True\\<rbrace>\"\nproof -\n  have P: \"\\<And>r. (case r of Inl a \\<Rightarrow> True | _ \\<Rightarrow> True) = True\"\n    by (case_tac r, simp_all)\n  show ?thesis\n    by (simp add: validE_def P wp_post_taut)\nqed\n\nlemma hoare_pre_cont [simp]: \"\\<lbrace> \\<bottom> \\<rbrace> a \\<lbrace> P \\<rbrace>\"\n  by (simp add:valid_def)\n\n\nsubsection {* Strongest Postcondition Rules *}\n\nlemma get_sp:\n  \"\\<lbrace>P\\<rbrace> get \\<lbrace>\\<lambda>a s. s = a \\<and> P s\\<rbrace>\"\n  by(simp add:get_def valid_def)\n\nlemma put_sp:\n  \"\\<lbrace>\\<top>\\<rbrace> put a \\<lbrace>\\<lambda>_ s. s = a\\<rbrace>\"\n  by(simp add:put_def valid_def)\n\nlemma return_sp:\n  \"\\<lbrace>P\\<rbrace> return a \\<lbrace>\\<lambda>b s. b = a \\<and> P s\\<rbrace>\"\n  by(simp add:return_def valid_def)\n\nlemma assert_sp:\n  \"\\<lbrace> P \\<rbrace> assert Q \\<lbrace> \\<lambda>r s. P s \\<and> Q \\<rbrace>\"\n  by (simp add: assert_def fail_def return_def valid_def)\n\nlemma hoare_gets_sp:\n  \"\\<lbrace>P\\<rbrace> gets f \\<lbrace>\\<lambda>rv s. rv = f s \\<and> P s\\<rbrace>\"\n  by (simp add: valid_def simpler_gets_def)\n\nlemma hoare_return_drop_var [iff]: \"\\<lbrace> Q \\<rbrace> return x \\<lbrace> \\<lambda>r. Q \\<rbrace>\"\n  by (simp add:valid_def return_def)\n\nlemma hoare_gets [intro!]: \"\\<lbrakk> \\<And>s. P s \\<Longrightarrow> Q (f s) s \\<rbrakk> \\<Longrightarrow> \\<lbrace> P \\<rbrace> gets f \\<lbrace> Q \\<rbrace>\"\n  by (simp add:valid_def gets_def get_def bind_def return_def)\n\nlemma hoare_modifyE_var [intro!]:\n  \"\\<lbrakk> \\<And>s. P s \\<Longrightarrow> Q (f s) \\<rbrakk> \\<Longrightarrow> \\<lbrace> P \\<rbrace> modify f \\<lbrace> \\<lambda>r s. Q s \\<rbrace>\"\n  by(simp add: valid_def modify_def put_def get_def bind_def)\n\nlemma hoare_if [intro!]:\n  \"\\<lbrakk> P \\<Longrightarrow> \\<lbrace> Q \\<rbrace> a \\<lbrace> R \\<rbrace>; \\<not> P \\<Longrightarrow> \\<lbrace> Q \\<rbrace> b \\<lbrace> R \\<rbrace> \\<rbrakk> \\<Longrightarrow>\n   \\<lbrace> Q \\<rbrace> if P then a else b \\<lbrace> R \\<rbrace>\"\n  by (simp add:valid_def)\n\nlemma hoare_pre_subst: \"\\<lbrakk> A = B; \\<lbrace>A\\<rbrace> a \\<lbrace>C\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>B\\<rbrace> a \\<lbrace>C\\<rbrace>\"\n  by(clarsimp simp:valid_def split_def)\n\nlemma hoare_post_subst: \"\\<lbrakk> B = C; \\<lbrace>A\\<rbrace> a \\<lbrace>B\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>A\\<rbrace> a \\<lbrace>C\\<rbrace>\"\n  by(clarsimp simp:valid_def split_def)\n\nlemma hoare_pre_tautI: \"\\<lbrakk> \\<lbrace>A and P\\<rbrace> a \\<lbrace>B\\<rbrace>; \\<lbrace>A and not P\\<rbrace> a \\<lbrace>B\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>A\\<rbrace> a \\<lbrace>B\\<rbrace>\"\n  by(fastforce simp:valid_def split_def pred_conj_def pred_neg_def)\n\nlemma hoare_pre_imp: \"\\<lbrakk> \\<And>s. P s \\<Longrightarrow> Q s; \\<lbrace>Q\\<rbrace> a \\<lbrace>R\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> a \\<lbrace>R\\<rbrace>\"\n  by (fastforce simp add:valid_def)\n\nlemma hoare_post_imp: \"\\<lbrakk> \\<And>r s. Q r s \\<Longrightarrow> R r s; \\<lbrace>P\\<rbrace> a \\<lbrace>Q\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> a \\<lbrace>R\\<rbrace>\"\n  by(fastforce simp:valid_def split_def)\n\nlemma hoare_post_impErr': \"\\<lbrakk> \\<lbrace>P\\<rbrace> a \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>;\n                           \\<forall>r s. Q r s \\<longrightarrow> R r s;\n                           \\<forall>e s. E e s \\<longrightarrow> F e s \\<rbrakk> \\<Longrightarrow>\n                         \\<lbrace>P\\<rbrace> a \\<lbrace>R\\<rbrace>,\\<lbrace>F\\<rbrace>\"\n apply (simp add: validE_def)\n apply (rule_tac Q=\"\\<lambda>r s. case r of Inl a \\<Rightarrow> E a s | Inr b \\<Rightarrow> Q b s\" in hoare_post_imp)\n  apply (case_tac r)\n   apply simp_all\n done\n\nlemma hoare_post_impErr: \"\\<lbrakk> \\<lbrace>P\\<rbrace> a \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>;\n                          \\<And>r s. Q r s \\<Longrightarrow> R r s;\n                          \\<And>e s. E e s \\<Longrightarrow> F e s \\<rbrakk> \\<Longrightarrow>\n                         \\<lbrace>P\\<rbrace> a \\<lbrace>R\\<rbrace>,\\<lbrace>F\\<rbrace>\"\n apply (blast intro: hoare_post_impErr')\n done\n\nlemma hoare_validE_cases:\n  \"\\<lbrakk> \\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>, \\<lbrace> \\<lambda>_ _. True \\<rbrace>; \\<lbrace> P \\<rbrace> f \\<lbrace> \\<lambda>_ _. True \\<rbrace>, \\<lbrace> R \\<rbrace> \\<rbrakk>\n  \\<Longrightarrow> \\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>, \\<lbrace> R \\<rbrace>\"\n  by (simp add: validE_def valid_def split: sum.splits) blast\n\nlemma hoare_post_imp_dc:\n  \"\\<lbrakk>\\<lbrace>P\\<rbrace> a \\<lbrace>\\<lambda>r. Q\\<rbrace>; \\<And>s. Q s \\<Longrightarrow> R s\\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> a \\<lbrace>\\<lambda>r. R\\<rbrace>,\\<lbrace>\\<lambda>r. R\\<rbrace>\"\n  by (simp add: validE_def valid_def split: sum.splits) blast\n\nlemma hoare_post_imp_dc2:\n  \"\\<lbrakk>\\<lbrace>P\\<rbrace> a \\<lbrace>\\<lambda>r. Q\\<rbrace>; \\<And>s. Q s \\<Longrightarrow> R s\\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> a \\<lbrace>\\<lambda>r. R\\<rbrace>,\\<lbrace>\\<lambda>r s. True\\<rbrace>\"\n  by (simp add: validE_def valid_def split: sum.splits) blast\n\nlemma hoare_post_imp_dc2E:\n  \"\\<lbrakk>\\<lbrace>P\\<rbrace> a \\<lbrace>\\<lambda>r. Q\\<rbrace>; \\<And>s. Q s \\<Longrightarrow> R s\\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> a \\<lbrace>\\<lambda>r s. True\\<rbrace>, \\<lbrace>\\<lambda>r. R\\<rbrace>\"\n  by (simp add: validE_def valid_def split: sum.splits) fast\n\nlemma hoare_post_imp_dc2E_actual:\n  \"\\<lbrakk>\\<lbrace>P\\<rbrace> a \\<lbrace>\\<lambda>r. R\\<rbrace>\\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> a \\<lbrace>\\<lambda>r s. True\\<rbrace>, \\<lbrace>\\<lambda>r. R\\<rbrace>\"\n  by (simp add: validE_def valid_def split: sum.splits) fast\n\nlemma hoare_post_imp_dc2_actual:\n  \"\\<lbrakk>\\<lbrace>P\\<rbrace> a \\<lbrace>\\<lambda>r. R\\<rbrace>\\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> a \\<lbrace>\\<lambda>r. R\\<rbrace>, \\<lbrace>\\<lambda>r s. True\\<rbrace>\"\n  by (simp add: validE_def valid_def split: sum.splits) fast\n\nlemma hoare_post_impE: \"\\<lbrakk> \\<And>r s. Q r s \\<Longrightarrow> R r s; \\<lbrace>P\\<rbrace> a \\<lbrace>Q\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> a \\<lbrace>R\\<rbrace>\"\n  by (fastforce simp:valid_def split_def)\n\nlemma hoare_conjD1:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>rv. Q rv and R rv\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>rv. Q rv\\<rbrace>\"\n  unfolding valid_def by auto\n\nlemma hoare_conjD2:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>rv. Q rv and R rv\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>rv. R rv\\<rbrace>\"\n  unfolding valid_def by auto\n\nlemma hoare_post_disjI1:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>rv. Q rv\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>rv. Q rv or R rv\\<rbrace>\"\n  unfolding valid_def by auto\n\nlemma hoare_post_disjI2:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>rv. R rv\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>rv. Q rv or R rv\\<rbrace>\"\n  unfolding valid_def by auto\n\nlemma hoare_weaken_pre:\n  \"\\<lbrakk>\\<lbrace>Q\\<rbrace> a \\<lbrace>R\\<rbrace>; \\<And>s. P s \\<Longrightarrow> Q s\\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> a \\<lbrace>R\\<rbrace>\"\n  apply (rule hoare_pre_imp)\n   prefer 2\n   apply assumption\n  apply blast\n  done\n\nlemma hoare_strengthen_post:\n  \"\\<lbrakk>\\<lbrace>P\\<rbrace> a \\<lbrace>Q\\<rbrace>; \\<And>r s. Q r s \\<Longrightarrow> R r s\\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> a \\<lbrace>R\\<rbrace>\"\n  apply (rule hoare_post_imp)\n   prefer 2\n   apply assumption\n  apply blast\n  done\n\nlemma use_valid: \"\\<lbrakk>(r, s') \\<in> fst (f s); \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>; P s \\<rbrakk> \\<Longrightarrow> Q r s'\"\n  apply (simp add: valid_def)\n  apply blast\n  done\n\nlemma use_validE_norm: \"\\<lbrakk> (Inr r', s') \\<in> fst (B s); \\<lbrace> P \\<rbrace> B \\<lbrace> Q \\<rbrace>,\\<lbrace> E \\<rbrace>; P s \\<rbrakk> \\<Longrightarrow> Q r' s'\"\n  apply (clarsimp simp: validE_def valid_def)\n  apply force\n  done\n\nlemma use_validE_except: \"\\<lbrakk> (Inl r', s') \\<in> fst (B s); \\<lbrace> P \\<rbrace> B \\<lbrace> Q \\<rbrace>,\\<lbrace> E \\<rbrace>; P s \\<rbrakk> \\<Longrightarrow> E r' s'\"\n  apply (clarsimp simp: validE_def valid_def)\n  apply force\n  done\n\nlemma in_inv_by_hoareD:\n  \"\\<lbrakk> \\<And>P. \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>_. P\\<rbrace>; (x,s') \\<in> fst (f s) \\<rbrakk> \\<Longrightarrow> s' = s\"\n  by (auto simp add: valid_def) blast\n\nsubsection \"Satisfiability\"\n\nlemma exs_hoare_post_imp: \"\\<lbrakk>\\<And>r s. Q r s \\<Longrightarrow> R r s; \\<lbrace>P\\<rbrace> a \\<exists>\\<lbrace>Q\\<rbrace>\\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> a \\<exists>\\<lbrace>R\\<rbrace>\"\n  apply (simp add: exs_valid_def)\n  apply safe\n  apply (erule_tac x=s in allE, simp)\n  apply blast\n  done\n\nlemma use_exs_valid: \"\\<lbrakk>\\<lbrace>P\\<rbrace> f \\<exists>\\<lbrace>Q\\<rbrace>; P s \\<rbrakk> \\<Longrightarrow> \\<exists>(r, s') \\<in> fst (f s). Q r s'\"\n  by (simp add: exs_valid_def)\n\ndefinition \"exs_postcondition P f \\<equiv> (\\<lambda>a b. \\<exists>(rv, s)\\<in> f a b. P rv s)\"\n\nlemma exs_valid_is_triple:\n  \"exs_valid P f Q = triple_judgement P f (exs_postcondition Q (\\<lambda>s f. fst (f s)))\"\n  by (simp add: triple_judgement_def exs_postcondition_def exs_valid_def)\n\nlemmas [wp_trip] = exs_valid_is_triple\n\nlemma exs_valid_weaken_pre [wp_comb]:\n  \"\\<lbrakk> \\<lbrace> P' \\<rbrace> f \\<exists>\\<lbrace> Q \\<rbrace>; \\<And>s. P s \\<Longrightarrow> P' s \\<rbrakk> \\<Longrightarrow> \\<lbrace> P \\<rbrace> f \\<exists>\\<lbrace> Q \\<rbrace>\"\n  apply atomize\n  apply (clarsimp simp: exs_valid_def)\n  done\n\nlemma exs_valid_chain:\n  \"\\<lbrakk> \\<lbrace> P \\<rbrace> f \\<exists>\\<lbrace> Q \\<rbrace>; \\<And>s. R s \\<Longrightarrow> P s; \\<And>r s. Q r s \\<Longrightarrow> S r s \\<rbrakk> \\<Longrightarrow> \\<lbrace> R \\<rbrace> f \\<exists>\\<lbrace> S \\<rbrace>\"\n  apply atomize\n  apply (fastforce simp: exs_valid_def Bex_def)\n  done\n\nlemma exs_valid_assume_pre:\n  \"\\<lbrakk> \\<And>s. P s \\<Longrightarrow> \\<lbrace> P \\<rbrace> f \\<exists>\\<lbrace> Q \\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace> P \\<rbrace> f \\<exists>\\<lbrace> Q \\<rbrace>\"\n  apply (fastforce simp: exs_valid_def)\n  done\n\nlemma exs_valid_bind [wp_split]:\n    \"\\<lbrakk> \\<And>x. \\<lbrace>B x\\<rbrace> g x \\<exists>\\<lbrace>C\\<rbrace>; \\<lbrace>A\\<rbrace> f \\<exists>\\<lbrace>B\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace> A \\<rbrace> f >>= (\\<lambda>x. g x) \\<exists>\\<lbrace> C \\<rbrace>\"\n  apply atomize\n  apply (clarsimp simp: exs_valid_def bind_def')\n  apply blast\n  done\n\nlemma exs_valid_return [wp]:\n    \"\\<lbrace> Q v \\<rbrace> return v \\<exists>\\<lbrace> Q \\<rbrace>\"\n  by (clarsimp simp: exs_valid_def return_def)\n\nlemma exs_valid_select [wp]:\n    \"\\<lbrace> \\<lambda>s. \\<exists>r \\<in> S. Q r s \\<rbrace> select S \\<exists>\\<lbrace> Q \\<rbrace>\"\n  by (clarsimp simp: exs_valid_def select_def)\n\nlemma exs_valid_get [wp]:\n    \"\\<lbrace> \\<lambda>s. Q s s \\<rbrace> get \\<exists>\\<lbrace> Q \\<rbrace>\"\n  by (clarsimp simp: exs_valid_def get_def)\n\nlemma exs_valid_gets [wp]:\n    \"\\<lbrace> \\<lambda>s. Q (f s) s \\<rbrace> gets f \\<exists>\\<lbrace> Q \\<rbrace>\"\n  by (clarsimp simp: gets_def, wp)\n\nlemma exs_valid_put [wp]:\n    \"\\<lbrace> Q v \\<rbrace> put v \\<exists>\\<lbrace> Q \\<rbrace>\"\n  by (clarsimp simp: put_def exs_valid_def)\n\nlemma exs_valid_state_assert [wp]:\n    \"\\<lbrace> \\<lambda>s. Q () s \\<and> G s \\<rbrace> state_assert G \\<exists>\\<lbrace> Q \\<rbrace>\"\n  by (clarsimp simp: state_assert_def exs_valid_def get_def\n           assert_def bind_def' return_def)\n\nlemmas exs_valid_guard = exs_valid_state_assert\n\nlemma exs_valid_fail [wp]:\n    \"\\<lbrace> \\<lambda>_. False \\<rbrace> fail \\<exists>\\<lbrace> Q \\<rbrace>\"\n  by (clarsimp simp: fail_def exs_valid_def)\n\nlemma exs_valid_condition [wp]:\n    \"\\<lbrakk> \\<lbrace> P \\<rbrace> L \\<exists>\\<lbrace> Q \\<rbrace>; \\<lbrace> P' \\<rbrace> R \\<exists>\\<lbrace> Q \\<rbrace> \\<rbrakk> \\<Longrightarrow>\n          \\<lbrace> \\<lambda>s. (C s \\<and> P s) \\<or> (\\<not> C s \\<and> P' s) \\<rbrace> condition C L R \\<exists>\\<lbrace> Q \\<rbrace>\"\n  by (clarsimp simp: condition_def exs_valid_def split: sum.splits)\n\n\nsubsection MISC\n\nlemma hoare_return_simp:\n  \"\\<lbrace>P\\<rbrace> return x \\<lbrace>Q\\<rbrace> = (\\<forall>s. P s \\<longrightarrow> Q x s)\"\n  by (simp add: valid_def return_def)\n\nlemma hoare_gen_asm:\n  \"(P \\<Longrightarrow> \\<lbrace>P'\\<rbrace> f \\<lbrace>Q\\<rbrace>) \\<Longrightarrow> \\<lbrace>P' and K P\\<rbrace> f \\<lbrace>Q\\<rbrace>\"\n  by (fastforce simp add: valid_def)\n\nlemma hoare_when_wp [wp]:\n \"\\<lbrakk> P \\<Longrightarrow> \\<lbrace>Q\\<rbrace> f \\<lbrace>R\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>if P then Q else R ()\\<rbrace> when P f \\<lbrace>R\\<rbrace>\"\n  by (clarsimp simp: when_def valid_def return_def)\n\nlemma hoare_conjI:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>; \\<lbrace>P\\<rbrace> f \\<lbrace>R\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. Q r s \\<and> R r s\\<rbrace>\"\n  unfolding valid_def by blast\n\nlemma hoare_disjI1:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. Q r s \\<or>  R r s \\<rbrace>\"\n  unfolding valid_def by blast\n\nlemma hoare_disjI2:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace> f \\<lbrace>R\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. Q r s \\<or>  R r s \\<rbrace>\"\n  unfolding valid_def by blast\n\nlemma hoare_assume_pre:\n  \"(\\<And>s. P s \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>) \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>\"\n  by (auto simp: valid_def)\n\nlemma hoare_returnOk_sp:\n  \"\\<lbrace>P\\<rbrace> returnOk x \\<lbrace>\\<lambda>r s. r = x \\<and> P s\\<rbrace>, \\<lbrace>Q\\<rbrace>\"\n  by (simp add: valid_def validE_def returnOk_def return_def)\n\nlemma hoare_assume_preE:\n  \"(\\<And>s. P s \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>R\\<rbrace>) \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>R\\<rbrace>\"\n  by (auto simp: valid_def validE_def)\n\nlemma hoare_allI:\n  \"(\\<And>x. \\<lbrace>P\\<rbrace>f\\<lbrace>Q x\\<rbrace>) \\<Longrightarrow> \\<lbrace>P\\<rbrace>f\\<lbrace>\\<lambda>r s. \\<forall>x. Q x r s\\<rbrace>\"\n  by (simp add: valid_def) blast\n\nlemma validE_allI:\n  \"(\\<And>x. \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. Q x r s\\<rbrace>,\\<lbrace>E\\<rbrace>) \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. \\<forall>x. Q x r s\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  by (fastforce simp: valid_def validE_def split: sum.splits)\n\nlemma hoare_exI:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q x\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. \\<exists>x. Q x r s\\<rbrace>\"\n  by (simp add: valid_def) blast\n\nlemma hoare_impI:\n  \"(R \\<Longrightarrow> \\<lbrace>P\\<rbrace>f\\<lbrace>Q\\<rbrace>) \\<Longrightarrow> \\<lbrace>P\\<rbrace>f\\<lbrace>\\<lambda>r s. R \\<longrightarrow> Q r s\\<rbrace>\"\n  by (simp add: valid_def) blast\n\nlemma validE_impI:\n  \" \\<lbrakk>\\<And>E. \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>_ _. True\\<rbrace>,\\<lbrace>E\\<rbrace>; (P' \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>)\\<rbrakk> \\<Longrightarrow>\n         \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. P' \\<longrightarrow> Q r s\\<rbrace>, \\<lbrace>E\\<rbrace>\"\n  by (fastforce simp: validE_def valid_def split: sum.splits)\n\nlemma hoare_case_option_wp:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace> f None \\<lbrace>Q\\<rbrace>;\n     \\<And>x.  \\<lbrace>P' x\\<rbrace> f (Some x) \\<lbrace>Q' x\\<rbrace> \\<rbrakk>\n  \\<Longrightarrow> \\<lbrace>case_option P P' v\\<rbrace> f v \\<lbrace>\\<lambda>rv. case v of None \\<Rightarrow> Q rv | Some x \\<Rightarrow> Q' x rv\\<rbrace>\"\n  by (cases v) auto\n\nsubsection \"Reasoning directly about states\"\n\nlemma in_throwError:\n  \"((v, s') \\<in> fst (throwError e s)) = (v = Inl e \\<and> s' = s)\"\n  by (simp add: throwError_def return_def)\n\nlemma in_returnOk:\n  \"((v', s') \\<in> fst (returnOk v s)) = (v' = Inr v \\<and> s' = s)\"\n  by (simp add: returnOk_def return_def)\n\nlemma in_bind:\n  \"((r,s') \\<in> fst ((do x \\<leftarrow> f; g x od) s)) =\n   (\\<exists>s'' x. (x, s'') \\<in> fst (f s) \\<and> (r, s') \\<in> fst (g x s''))\"\n  apply (simp add: bind_def split_def)\n  apply force\n  done\n\nlemma in_bindE_R:\n  \"((Inr r,s') \\<in> fst ((doE x \\<leftarrow> f; g x odE) s)) =\n  (\\<exists>s'' x. (Inr x, s'') \\<in> fst (f s) \\<and> (Inr r, s') \\<in> fst (g x s''))\"\n  apply (simp add: bindE_def lift_def split_def bind_def)\n  apply (clarsimp simp: throwError_def return_def lift_def split: sum.splits)\n  apply safe\n   apply (case_tac a)\n    apply fastforce\n   apply fastforce\n  apply force\n  done\n\nlemma in_bindE_L:\n  \"((Inl r, s') \\<in> fst ((doE x \\<leftarrow> f; g x odE) s)) \\<Longrightarrow>\n  (\\<exists>s'' x. (Inr x, s'') \\<in> fst (f s) \\<and> (Inl r, s') \\<in> fst (g x s'')) \\<or> ((Inl r, s') \\<in> fst (f s))\"\n  apply (simp add: bindE_def lift_def bind_def)\n  apply safe\n  apply (simp add: return_def throwError_def lift_def split_def split: sum.splits split_if_asm)\n  apply force\n  done\n\nlemma in_liftE:\n  \"((v, s') \\<in> fst (liftE f s)) = (\\<exists>v'. v = Inr v' \\<and> (v', s') \\<in> fst (f s))\"\n  by (force simp add: liftE_def bind_def return_def split_def)\n\nlemma in_whenE:  \"((v, s') \\<in> fst (whenE P f s)) = ((P \\<longrightarrow> (v, s') \\<in> fst (f s)) \\<and>\n                                                   (\\<not>P \\<longrightarrow> v = Inr () \\<and> s' = s))\"\n  by (simp add: whenE_def in_returnOk)\n\nlemma inl_whenE:\n  \"((Inl x, s') \\<in> fst (whenE P f s)) = (P \\<and> (Inl x, s') \\<in> fst (f s))\"\n  by (auto simp add: in_whenE)\n\nlemma in_fail:\n  \"r \\<in> fst (fail s) = False\"\n  by (simp add: fail_def)\n\nlemma in_return:\n  \"(r, s') \\<in> fst (return v s) = (r = v \\<and> s' = s)\"\n  by (simp add: return_def)\n\nlemma in_assert:\n  \"(r, s') \\<in> fst (assert P s) = (P \\<and> s' = s)\"\n  by (simp add: assert_def return_def fail_def)\n\nlemma in_assertE:\n  \"(r, s') \\<in> fst (assertE P s) = (P \\<and> r = Inr () \\<and> s' = s)\"\n  by (simp add: assertE_def returnOk_def return_def fail_def)\n\nlemma in_assert_opt:\n  \"(r, s') \\<in> fst (assert_opt v s) = (v = Some r \\<and> s' = s)\"\n  by (auto simp: assert_opt_def in_fail in_return split: option.splits)\n\nlemma in_get:\n  \"(r, s') \\<in> fst (get s) = (r = s \\<and> s' = s)\"\n  by (simp add: get_def)\n\nlemma in_gets:\n  \"(r, s') \\<in> fst (gets f s) = (r = f s \\<and> s' = s)\"\n  by (simp add: simpler_gets_def)\n\nlemma in_put:\n  \"(r, s') \\<in> fst (put x s) = (s' = x \\<and> r = ())\"\n  by (simp add: put_def)\n\nlemma in_when:\n  \"(v, s') \\<in> fst (when P f s) = ((P \\<longrightarrow> (v, s') \\<in> fst (f s)) \\<and> (\\<not>P \\<longrightarrow> v = () \\<and> s' = s))\"\n  by (simp add: when_def in_return)\n\nlemma in_modify:\n  \"(v, s') \\<in> fst (modify f s) = (s'=f s \\<and> v = ())\"\n  by (simp add: modify_def bind_def get_def put_def)\n\nlemma gets_the_in_monad:\n  \"((v, s') \\<in> fst (gets_the f s)) = (s' = s \\<and> f s = Some v)\"\n  by (auto simp: gets_the_def in_bind in_gets in_assert_opt split: option.split)\n\nlemma in_alternative:\n  \"(r,s') \\<in> fst ((f \\<sqinter> g) s) = ((r,s') \\<in> fst (f s) \\<or> (r,s') \\<in> fst (g s))\"\n  by (simp add: alternative_def)\n\nlemmas in_monad = inl_whenE in_whenE in_liftE in_bind in_bindE_L\n                  in_bindE_R in_returnOk in_throwError in_fail\n                  in_assertE in_assert in_return in_assert_opt\n                  in_get in_gets in_put in_when unlessE_whenE\n                  unless_when in_modify gets_the_in_monad\n                  in_alternative\n\nsubsection \"Non-Failure\"\n\nlemma no_failD:\n  \"\\<lbrakk> no_fail P m; P s \\<rbrakk> \\<Longrightarrow> \\<not>(snd (m s))\"\n  by (simp add: no_fail_def)\n\nlemma non_fail_modify [wp,simp]:\n  \"no_fail \\<top> (modify f)\"\n  by (simp add: no_fail_def modify_def get_def put_def bind_def)\n\nlemma non_fail_gets [simp]:\n  \"no_fail \\<top> (gets f)\"\n  by (simp add: no_fail_def simpler_gets_def)\n\nlemma non_fail_select [simp]:\n  \"no_fail \\<top> (select S)\"\n  by (simp add: no_fail_def select_def)\n\nlemma no_fail_pre:\n  \"\\<lbrakk> no_fail P f; \\<And>s. Q s \\<Longrightarrow> P s\\<rbrakk> \\<Longrightarrow> no_fail Q f\"\n  by (simp add: no_fail_def)\n\nlemma no_fail_alt [wp]:\n  \"\\<lbrakk> no_fail P f; no_fail Q g \\<rbrakk> \\<Longrightarrow> no_fail (P and Q) (f OR g)\"\n  by (simp add: no_fail_def alternative_def)\n\nlemma no_fail_return [simp, wp]:\n  \"no_fail \\<top> (return x)\"\n  by (simp add: return_def no_fail_def)\n\nlemma no_fail_get [simp, wp]:\n  \"no_fail \\<top> get\"\n  by (simp add: get_def no_fail_def)\n\nlemma no_fail_put [simp, wp]:\n  \"no_fail \\<top> (put s)\"\n  by (simp add: put_def no_fail_def)\n\nlemma no_fail_when [wp]:\n  \"(P \\<Longrightarrow> no_fail Q f) \\<Longrightarrow> no_fail (if P then Q else \\<top>) (when P f)\"\n  by (simp add: when_def)\n\nlemma no_fail_unless [wp]:\n  \"(\\<not>P \\<Longrightarrow> no_fail Q f) \\<Longrightarrow> no_fail (if P then \\<top> else Q) (unless P f)\"\n  by (simp add: unless_def when_def)\n\nlemma no_fail_fail [simp, wp]:\n  \"no_fail \\<bottom> fail\"\n  by (simp add: fail_def no_fail_def)\n\nlemmas [wp] = non_fail_gets\n\nlemma no_fail_assert [simp, wp]:\n  \"no_fail (\\<lambda>_. P) (assert P)\"\n  by (simp add: assert_def)\n\nlemma no_fail_assert_opt [simp, wp]:\n  \"no_fail (\\<lambda>_. P \\<noteq> None) (assert_opt P)\"\n  by (simp add: assert_opt_def split: option.splits)\n\nlemma no_fail_case_option [wp]:\n  assumes f: \"no_fail P f\"\n  assumes g: \"\\<And>x. no_fail (Q x) (g x)\"\n  shows \"no_fail (if x = None then P else Q (the x)) (case_option f g x)\"\n  by (clarsimp simp add: f g)\n\nlemma no_fail_if [wp]:\n  \"\\<lbrakk> P \\<Longrightarrow> no_fail Q f; \\<not>P \\<Longrightarrow> no_fail R g \\<rbrakk> \\<Longrightarrow>\n  no_fail (if P then Q else R) (if P then f else g)\"\n  by simp\n\nlemma no_fail_apply [wp]:\n  \"no_fail P (f (g x)) \\<Longrightarrow> no_fail P (f $ g x)\"\n  by simp\n\nlemma no_fail_undefined [simp, wp]:\n  \"no_fail \\<bottom> undefined\"\n  by (simp add: no_fail_def)\n\nlemma no_fail_returnOK [simp, wp]:\n  \"no_fail \\<top> (returnOk x)\"\n  by (simp add: returnOk_def)\n\ntext {* Empty results implies non-failure *}\n\nlemma empty_fail_modify [simp]:\n  \"empty_fail (modify f)\"\n  by (simp add: empty_fail_def simpler_modify_def)\n\nlemma empty_fail_gets [simp]:\n  \"empty_fail (gets f)\"\n  by (simp add: empty_fail_def simpler_gets_def)\n\nlemma empty_failD:\n  \"\\<lbrakk> empty_fail m; fst (m s) = {} \\<rbrakk> \\<Longrightarrow> snd (m s)\"\n  by (simp add: empty_fail_def)\n\nlemma empty_fail_select_f [simp]:\n  assumes ef: \"fst S = {} \\<Longrightarrow> snd S\"\n  shows \"empty_fail (select_f S)\"\n  by (fastforce simp add: empty_fail_def select_f_def intro: ef)\n\nlemma empty_fail_bind [simp]:\n  \"\\<lbrakk> empty_fail a; \\<And>x. empty_fail (b x) \\<rbrakk> \\<Longrightarrow> empty_fail (a >>= b)\"\n  apply (simp add: bind_def empty_fail_def split_def)\n  apply clarsimp\n  apply (case_tac \"fst (a s) = {}\")\n   apply blast\n  apply (clarsimp simp: ex_in_conv [symmetric])\n  done\n\nlemma empty_fail_return [simp]:\n  \"empty_fail (return x)\"\n  by (simp add: empty_fail_def return_def)\n\nlemma empty_fail_mapM [simp]:\n  assumes m: \"\\<And>x. empty_fail (m x)\"\n  shows \"empty_fail (mapM m xs)\"\nproof (induct xs)\n  case Nil\n  thus ?case by (simp add: mapM_def sequence_def)\nnext\n  case Cons\n  have P: \"\\<And>m x xs. mapM m (x # xs) = (do y \\<leftarrow> m x; ys \\<leftarrow> (mapM m xs); return (y # ys) od)\"\n    by (simp add: mapM_def sequence_def Let_def)\n  from Cons\n  show ?case by (simp add: P m)\nqed\n\nlemma empty_fail [simp]:\n  \"empty_fail fail\"\n  by (simp add: fail_def empty_fail_def)\n\nlemma empty_fail_assert_opt [simp]:\n  \"empty_fail (assert_opt x)\"\n  by (simp add: assert_opt_def split: option.splits)\n\nlemma empty_fail_mk_ef:\n  \"empty_fail (mk_ef o m)\"\n  by (simp add: empty_fail_def mk_ef_def)\n\nsubsection \"Failure\"\n\nlemma fail_wp: \"\\<lbrace>\\<lambda>x. True\\<rbrace> fail \\<lbrace>Q\\<rbrace>\"\n  by (simp add: valid_def fail_def)\n\nlemma failE_wp: \"\\<lbrace>\\<lambda>x. True\\<rbrace> fail \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  by (simp add: validE_def fail_wp)\n\nlemma fail_update [iff]:\n  \"fail (f s) = fail s\"\n  by (simp add: fail_def)\n\n\ntext {* We can prove postconditions using hoare triples *}\n\nlemma post_by_hoare: \"\\<lbrakk> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>; P s; (r, s') \\<in> fst (f s) \\<rbrakk> \\<Longrightarrow> Q r s'\"\n  apply (simp add: valid_def)\n  apply blast\n  done\n\ntext {* Weakest Precondition Rules *}\n\nlemma hoare_vcg_prop:\n  \"\\<lbrace>\\<lambda>s. P\\<rbrace> f \\<lbrace>\\<lambda>rv s. P\\<rbrace>\"\n  by (simp add: valid_def)\n\nlemma return_wp:\n  \"\\<lbrace>P x\\<rbrace> return x \\<lbrace>P\\<rbrace>\"\n apply(simp add:valid_def return_def)\ndone\n\nlemma get_wp:\n  \"\\<lbrace>\\<lambda>s. P s s\\<rbrace> get \\<lbrace>P\\<rbrace>\"\n apply(simp add:valid_def split_def get_def)\ndone\n\nlemma gets_wp:\n \"\\<lbrace>\\<lambda>s. P (f s) s\\<rbrace> gets f \\<lbrace>P\\<rbrace>\"\n apply(simp add:valid_def split_def gets_def return_def get_def bind_def)\ndone\n\nlemma modify_wp:\n \"\\<lbrace>\\<lambda>s. P () (f s)\\<rbrace> modify f \\<lbrace>P\\<rbrace>\"\n apply(simp add:valid_def split_def modify_def get_def put_def bind_def)\ndone\n\nlemma put_wp:\n \"\\<lbrace>\\<lambda>s. P () x\\<rbrace> put x \\<lbrace>P\\<rbrace>\"\n apply(simp add:valid_def put_def)\ndone\n\nlemma returnOk_wp:\n  \"\\<lbrace>P x\\<rbrace> returnOk x \\<lbrace>P\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n apply(simp add:validE_def2 returnOk_def return_def)\ndone\n\nlemma throwError_wp:\n  \"\\<lbrace>E e\\<rbrace> throwError e \\<lbrace>P\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n apply(simp add:validE_def2 throwError_def return_def)\ndone\n\nlemma returnOKE_R_wp : \"\\<lbrace>P x\\<rbrace> returnOk x \\<lbrace>P\\<rbrace>, -\"\n  by (simp add: validE_R_def validE_def valid_def\n                returnOk_def return_def)\n\nlemma liftE_wp:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> liftE f \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n apply(clarsimp simp:valid_def validE_def2 liftE_def split_def Let_def bind_def return_def)\ndone\n\nlemma catch_wp:\n  \"\\<lbrakk> \\<And>x. \\<lbrace>E x\\<rbrace> handler x \\<lbrace>Q\\<rbrace>; \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace> \\<rbrakk> \\<Longrightarrow>\n   \\<lbrace>P\\<rbrace> catch f handler \\<lbrace>Q\\<rbrace>\"\n apply (unfold catch_def valid_def validE_def return_def)\n apply (clarsimp simp: bind_def)\n apply (fastforce split: sum.splits)\n done\n\nlemma handleE'_wp:\n  \"\\<lbrakk> \\<And>x. \\<lbrace>F x\\<rbrace> handler x \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>; \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>F\\<rbrace> \\<rbrakk> \\<Longrightarrow>\n   \\<lbrace>P\\<rbrace> f <handle2> handler \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n apply (unfold handleE'_def valid_def validE_def return_def)\n apply (clarsimp simp: bind_def)\n apply (fastforce split: sum.splits)\n done\n\nlemma handleE_wp:\n  assumes x: \"\\<And>x. \\<lbrace>F x\\<rbrace> handler x \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  assumes y: \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>F\\<rbrace>\"\n  shows      \"\\<lbrace>P\\<rbrace> f <handle> handler \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  by (simp add: handleE_def handleE'_wp [OF x y])\n\nlemma hoare_vcg_split_if:\n \"\\<lbrakk> P \\<Longrightarrow> \\<lbrace>Q\\<rbrace> f \\<lbrace>S\\<rbrace>; \\<not>P \\<Longrightarrow> \\<lbrace>R\\<rbrace> g \\<lbrace>S\\<rbrace> \\<rbrakk> \\<Longrightarrow>\n  \\<lbrace>\\<lambda>s. (P \\<longrightarrow> Q s) \\<and> (\\<not>P \\<longrightarrow> R s)\\<rbrace> if P then f else g \\<lbrace>S\\<rbrace>\"\n  by simp\n\nlemma hoare_vcg_split_ifE:\n \"\\<lbrakk> P \\<Longrightarrow> \\<lbrace>Q\\<rbrace> f \\<lbrace>S\\<rbrace>,\\<lbrace>E\\<rbrace>; \\<not>P \\<Longrightarrow> \\<lbrace>R\\<rbrace> g \\<lbrace>S\\<rbrace>,\\<lbrace>E\\<rbrace> \\<rbrakk> \\<Longrightarrow>\n  \\<lbrace>\\<lambda>s. (P \\<longrightarrow> Q s) \\<and> (\\<not>P \\<longrightarrow> R s)\\<rbrace> if P then f else g \\<lbrace>S\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  by simp\n\nlemma hoare_liftM_subst: \"\\<lbrace>P\\<rbrace> liftM f m \\<lbrace>Q\\<rbrace> = \\<lbrace>P\\<rbrace> m \\<lbrace>Q \\<circ> f\\<rbrace>\"\n  apply (simp add: liftM_def bind_def return_def split_def)\n  apply (simp add: valid_def Ball_def)\n  apply (rule_tac f=All in arg_cong)\n  apply (rule ext)\n  apply fastforce\n  done\n\nlemma liftE_validE[simp]: \"\\<lbrace>P\\<rbrace> liftE f \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace> = \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>\"\n  apply (simp add: liftE_liftM validE_def hoare_liftM_subst o_def)\n  done\n\nlemma liftM_wp: \"\\<lbrace>P\\<rbrace> m \\<lbrace>Q \\<circ> f\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> liftM f m \\<lbrace>Q\\<rbrace>\"\n  by (simp add: hoare_liftM_subst)\n\nlemma hoare_liftME_subst: \"\\<lbrace>P\\<rbrace> liftME f m \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace> = \\<lbrace>P\\<rbrace> m \\<lbrace>Q \\<circ> f\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  apply (simp add: validE_def liftME_liftM hoare_liftM_subst o_def)\n  apply (rule_tac f=\"valid P m\" in arg_cong)\n  apply (rule ext)+\n  apply (case_tac x, simp_all)\n  done\n\nlemma liftME_wp: \"\\<lbrace>P\\<rbrace> m \\<lbrace>Q \\<circ> f\\<rbrace>,\\<lbrace>E\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> liftME f m \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  by (simp add: hoare_liftME_subst)\n\n(* FIXME: Move *)\nlemma o_const_simp[simp]: \"(\\<lambda>x. C) \\<circ> f = (\\<lambda>x. C)\"\n  by (simp add: o_def)\n\nlemma hoare_vcg_split_case_option:\n \"\\<lbrakk> \\<And>x. x = None \\<Longrightarrow> \\<lbrace>P x\\<rbrace> f x \\<lbrace>R x\\<rbrace>;\n    \\<And>x y. x = Some y \\<Longrightarrow> \\<lbrace>Q x y\\<rbrace> g x y \\<lbrace>R x\\<rbrace> \\<rbrakk> \\<Longrightarrow>\n  \\<lbrace>\\<lambda>s. (x = None \\<longrightarrow> P x s) \\<and>\n       (\\<forall>y. x = Some y \\<longrightarrow> Q x y s)\\<rbrace>\n  case x of None \\<Rightarrow> f x\n          | Some y \\<Rightarrow> g x y\n  \\<lbrace>R x\\<rbrace>\"\n apply(simp add:valid_def split_def)\n apply(case_tac x, simp_all)\ndone\n\nlemma hoare_vcg_split_case_optionE:\n assumes none_case: \"\\<And>x. x = None \\<Longrightarrow> \\<lbrace>P x\\<rbrace> f x \\<lbrace>R x\\<rbrace>,\\<lbrace>E x\\<rbrace>\"\n assumes some_case: \"\\<And>x y. x = Some y \\<Longrightarrow> \\<lbrace>Q x y\\<rbrace> g x y \\<lbrace>R x\\<rbrace>,\\<lbrace>E x\\<rbrace>\"\n shows \"\\<lbrace>\\<lambda>s. (x = None \\<longrightarrow> P x s) \\<and>\n             (\\<forall>y. x = Some y \\<longrightarrow> Q x y s)\\<rbrace>\n        case x of None \\<Rightarrow> f x\n                | Some y \\<Rightarrow> g x y\n        \\<lbrace>R x\\<rbrace>,\\<lbrace>E x\\<rbrace>\"\n apply(case_tac x, simp_all)\n  apply(rule none_case, simp)\n apply(rule some_case, simp)\ndone\n\nlemma hoare_vcg_split_case_sum:\n \"\\<lbrakk> \\<And>x a. x = Inl a \\<Longrightarrow> \\<lbrace>P x a\\<rbrace> f x a \\<lbrace>R x\\<rbrace>;\n    \\<And>x b. x = Inr b \\<Longrightarrow> \\<lbrace>Q x b\\<rbrace> g x b \\<lbrace>R x\\<rbrace> \\<rbrakk> \\<Longrightarrow>\n  \\<lbrace>\\<lambda>s. (\\<forall>a. x = Inl a \\<longrightarrow> P x a s) \\<and>\n       (\\<forall>b. x = Inr b \\<longrightarrow> Q x b s) \\<rbrace>\n  case x of Inl a \\<Rightarrow> f x a\n          | Inr b \\<Rightarrow> g x b\n  \\<lbrace>R x\\<rbrace>\"\n apply(simp add:valid_def split_def)\n apply(case_tac x, simp_all)\ndone\n\nlemma hoare_vcg_split_case_sumE:\n  assumes left_case: \"\\<And>x a. x = Inl a \\<Longrightarrow> \\<lbrace>P x a\\<rbrace> f x a \\<lbrace>R x\\<rbrace>\"\n  assumes right_case: \"\\<And>x b. x = Inr b \\<Longrightarrow> \\<lbrace>Q x b\\<rbrace> g x b \\<lbrace>R x\\<rbrace>\"\n  shows \"\\<lbrace>\\<lambda>s. (\\<forall>a. x = Inl a \\<longrightarrow> P x a s) \\<and>\n              (\\<forall>b. x = Inr b \\<longrightarrow> Q x b s) \\<rbrace>\n         case x of Inl a \\<Rightarrow> f x a\n                 | Inr b \\<Rightarrow> g x b\n         \\<lbrace>R x\\<rbrace>\"\n apply(case_tac x, simp_all)\n  apply(rule left_case, simp)\n apply(rule right_case, simp)\ndone\n\nlemma hoare_vcg_precond_imp:\n \"\\<lbrakk> \\<lbrace>Q\\<rbrace> f \\<lbrace>R\\<rbrace>; \\<And>s. P s \\<Longrightarrow> Q s \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>R\\<rbrace>\"\n  by (fastforce simp add:valid_def)\n\nlemma hoare_vcg_precond_impE:\n \"\\<lbrakk> \\<lbrace>Q\\<rbrace> f \\<lbrace>R\\<rbrace>,\\<lbrace>E\\<rbrace>; \\<And>s. P s \\<Longrightarrow> Q s \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>R\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  by (fastforce simp add:validE_def2)\n\nlemma hoare_seq_ext:\n  assumes g_valid: \"\\<And>x. \\<lbrace>B x\\<rbrace> g x \\<lbrace>C\\<rbrace>\"\n  assumes f_valid: \"\\<lbrace>A\\<rbrace> f \\<lbrace>B\\<rbrace>\"\n  shows \"\\<lbrace>A\\<rbrace> do x \\<leftarrow> f; g x od \\<lbrace>C\\<rbrace>\"\n apply(insert f_valid g_valid)\n apply(blast intro: seq_ext')\ndone\n\nlemma hoare_vcg_seqE:\n  assumes g_valid: \"\\<And>x. \\<lbrace>B x\\<rbrace> g x \\<lbrace>C\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  assumes f_valid: \"\\<lbrace>A\\<rbrace> f \\<lbrace>B\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  shows \"\\<lbrace>A\\<rbrace> doE x \\<leftarrow> f; g x odE \\<lbrace>C\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n apply(insert f_valid g_valid)\n apply(blast intro: seqE')\ndone\n\nlemma hoare_seq_ext_nobind:\n  \"\\<lbrakk> \\<lbrace>B\\<rbrace> g \\<lbrace>C\\<rbrace>;\n     \\<lbrace>A\\<rbrace> f \\<lbrace>\\<lambda>r s. B s\\<rbrace> \\<rbrakk> \\<Longrightarrow>\n   \\<lbrace>A\\<rbrace> do f; g od \\<lbrace>C\\<rbrace>\"\n  apply (clarsimp simp: valid_def bind_def Let_def split_def)\n  apply fastforce\ndone\n\nlemma hoare_seq_ext_nobindE:\n  \"\\<lbrakk> \\<lbrace>B\\<rbrace> g \\<lbrace>C\\<rbrace>,\\<lbrace>E\\<rbrace>;\n     \\<lbrace>A\\<rbrace> f \\<lbrace>\\<lambda>r s. B s\\<rbrace>,\\<lbrace>E\\<rbrace> \\<rbrakk> \\<Longrightarrow>\n   \\<lbrace>A\\<rbrace> doE f; g odE \\<lbrace>C\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  apply (clarsimp simp:validE_def)\n  apply (simp add:bindE_def Let_def split_def bind_def lift_def)\n  apply (fastforce simp add: valid_def throwError_def return_def lift_def\n                  split: sum.splits)\n  done\n\nlemma hoare_chain:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>;\n    \\<And>s. R s \\<Longrightarrow> P s;\n    \\<And>r s. Q r s \\<Longrightarrow> S r s \\<rbrakk> \\<Longrightarrow>\n   \\<lbrace>R\\<rbrace> f \\<lbrace>S\\<rbrace>\"\n  by(fastforce simp add:valid_def split_def)\n\nlemma validE_weaken:\n  \"\\<lbrakk> \\<lbrace>P'\\<rbrace> A \\<lbrace>Q'\\<rbrace>,\\<lbrace>E'\\<rbrace>; \\<And>s. P s \\<Longrightarrow> P' s; \\<And>r s. Q' r s \\<Longrightarrow> Q r s; \\<And>r s. E' r s \\<Longrightarrow> E r s \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> A \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  by (fastforce simp: validE_def2 split: sum.splits)\n\nlemmas hoare_chainE = validE_weaken\n\nlemma hoare_vcg_handle_elseE:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>;\n     \\<And>e. \\<lbrace>E e\\<rbrace> g e \\<lbrace>R\\<rbrace>,\\<lbrace>F\\<rbrace>;\n     \\<And>x. \\<lbrace>Q x\\<rbrace> h x \\<lbrace>R\\<rbrace>,\\<lbrace>F\\<rbrace> \\<rbrakk> \\<Longrightarrow>\n   \\<lbrace>P\\<rbrace> f <handle> g <else> h \\<lbrace>R\\<rbrace>,\\<lbrace>F\\<rbrace>\"\n  apply (simp add: handle_elseE_def validE_def)\n  apply (rule seq_ext)\n   apply assumption\n  apply (case_tac x, simp_all)\n  done\n\nlemma alternative_valid:\n  assumes x: \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>\"\n  assumes y: \"\\<lbrace>P\\<rbrace> f' \\<lbrace>Q\\<rbrace>\"\n  shows      \"\\<lbrace>P\\<rbrace> f OR f' \\<lbrace>Q\\<rbrace>\"\n  apply (simp add: valid_def alternative_def)\n  apply safe\n   apply (simp add: post_by_hoare [OF x])\n  apply (simp add: post_by_hoare [OF y])\n  done\n\nlemma alternative_wp:\n  assumes x: \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>\"\n  assumes y: \"\\<lbrace>P'\\<rbrace> f' \\<lbrace>Q\\<rbrace>\"\n  shows      \"\\<lbrace>P and P'\\<rbrace> f OR f' \\<lbrace>Q\\<rbrace>\"\n  apply (rule alternative_valid)\n   apply (rule hoare_pre_imp [OF _ x], simp)\n  apply (rule hoare_pre_imp [OF _ y], simp)\n  done\n\nlemma alternativeE_wp:\n  assumes x: \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\" and y: \"\\<lbrace>P'\\<rbrace> f' \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  shows      \"\\<lbrace>P and P'\\<rbrace> f OR f' \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  apply (unfold validE_def)\n  apply (wp add: x y alternative_wp | simp | fold validE_def)+\n  done\n\nlemma alternativeE_R_wp:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,-; \\<lbrace>P'\\<rbrace> f' \\<lbrace>Q\\<rbrace>,- \\<rbrakk> \\<Longrightarrow> \\<lbrace>P and P'\\<rbrace> f OR f' \\<lbrace>Q\\<rbrace>,-\"\n  apply (simp add: validE_R_def)\n  apply (rule alternativeE_wp)\n   apply assumption+\n  done\n\nlemma alternative_R_wp:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace> f -,\\<lbrace>Q\\<rbrace>; \\<lbrace>P'\\<rbrace> g -,\\<lbrace>Q\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>P and P'\\<rbrace> f \\<sqinter> g -, \\<lbrace>Q\\<rbrace>\"\n  by (fastforce simp: alternative_def validE_E_def validE_def valid_def)\n\nlemma select_wp: \"\\<lbrace>\\<lambda>s. \\<forall>x \\<in> S. Q x s\\<rbrace> select S \\<lbrace>Q\\<rbrace>\"\n  by (simp add: select_def valid_def)\n\nlemma select_f_wp:\n  \"\\<lbrace>\\<lambda>s. \\<forall>x\\<in>fst S. Q x s\\<rbrace> select_f S \\<lbrace>Q\\<rbrace>\"\n  by (simp add: select_f_def valid_def)\n\nlemma state_select_wp [wp]: \"\\<lbrace> \\<lambda>s. \\<forall>t. (s, t) \\<in> f \\<longrightarrow> P () t \\<rbrace> state_select f \\<lbrace> P \\<rbrace>\"\n  apply (clarsimp simp: state_select_def)\n  apply (clarsimp simp: valid_def)\n  done\n\nlemma condition_wp [wp]:\n  \"\\<lbrakk> \\<lbrace> Q \\<rbrace> A \\<lbrace> P \\<rbrace>;  \\<lbrace> R \\<rbrace> B \\<lbrace> P \\<rbrace>  \\<rbrakk> \\<Longrightarrow> \\<lbrace> \\<lambda>s. if C s then Q s else R s \\<rbrace> condition C A B \\<lbrace> P \\<rbrace>\"\n  apply (clarsimp simp: condition_def)\n  apply (clarsimp simp: valid_def pred_conj_def pred_neg_def split_def)\n  done\n\nlemma conditionE_wp [wp]:\n  \"\\<lbrakk> \\<lbrace> P \\<rbrace> A \\<lbrace> Q \\<rbrace>,\\<lbrace> R \\<rbrace>; \\<lbrace> P' \\<rbrace> B \\<lbrace> Q \\<rbrace>,\\<lbrace> R \\<rbrace> \\<rbrakk> \\<Longrightarrow>  \\<lbrace> \\<lambda>s. if C s then P s else P' s \\<rbrace> condition C A B \\<lbrace>Q\\<rbrace>,\\<lbrace>R\\<rbrace>\"\n  apply (clarsimp simp: condition_def)\n  apply (clarsimp simp: validE_def valid_def)\n  done\n\nlemma state_assert_wp [wp]: \"\\<lbrace> \\<lambda>s. f s \\<longrightarrow> P () s \\<rbrace> state_assert f \\<lbrace> P \\<rbrace>\"\n  apply (clarsimp simp: state_assert_def get_def\n    assert_def bind_def valid_def return_def fail_def)\n  done\n\ntext {* The weakest precondition handler which works on conjunction *}\n\nlemma hoare_vcg_conj_lift:\n  assumes x: \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>\"\n  assumes y: \"\\<lbrace>P'\\<rbrace> f \\<lbrace>Q'\\<rbrace>\"\n  shows      \"\\<lbrace>\\<lambda>s. P s \\<and> P' s\\<rbrace> f \\<lbrace>\\<lambda>rv s. Q rv s \\<and> Q' rv s\\<rbrace>\"\n  apply (subst bipred_conj_def[symmetric], rule hoare_post_conj)\n   apply (rule hoare_pre_imp [OF _ x], simp)\n  apply (rule hoare_pre_imp [OF _ y], simp)\n  done\n\nlemma hoare_vcg_conj_liftE1:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,-; \\<lbrace>P'\\<rbrace> f \\<lbrace>Q'\\<rbrace>,\\<lbrace>E\\<rbrace> \\<rbrakk> \\<Longrightarrow>\n  \\<lbrace>P and P'\\<rbrace> f \\<lbrace>\\<lambda>r s. Q r s \\<and> Q' r s\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  unfolding valid_def validE_R_def validE_def\n  apply (clarsimp simp: split_def split: sum.splits)\n  apply (erule allE, erule (1) impE)\n  apply (erule allE, erule (1) impE)\n  apply (drule (1) bspec)\n  apply (drule (1) bspec)\n  apply clarsimp\n  done\n\nlemma hoare_vcg_disj_lift:\n  assumes x: \"\\<lbrace>P\\<rbrace>  f \\<lbrace>Q\\<rbrace>\"\n  assumes y: \"\\<lbrace>P'\\<rbrace> f \\<lbrace>Q'\\<rbrace>\"\n  shows      \"\\<lbrace>\\<lambda>s. P s \\<or> P' s\\<rbrace> f \\<lbrace>\\<lambda>rv s. Q rv s \\<or> Q' rv s\\<rbrace>\"\n  apply (simp add: valid_def)\n  apply safe\n   apply (erule(1) post_by_hoare [OF x])\n  apply (erule notE)\n  apply (erule(1) post_by_hoare [OF y])\n  done\n\nlemma hoare_vcg_const_Ball_lift:\n  \"\\<lbrakk> \\<And>x. x \\<in> S \\<Longrightarrow> \\<lbrace>P x\\<rbrace> f \\<lbrace>Q x\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>\\<lambda>s. \\<forall>x\\<in>S. P x s\\<rbrace> f \\<lbrace>\\<lambda>rv s. \\<forall>x\\<in>S. Q x rv s\\<rbrace>\"\n  by (fastforce simp: valid_def)\n\nlemma hoare_vcg_const_Ball_lift_R:\n \"\\<lbrakk> \\<And>x. x \\<in> S \\<Longrightarrow> \\<lbrace>P x\\<rbrace> f \\<lbrace>Q x\\<rbrace>,- \\<rbrakk> \\<Longrightarrow>\n   \\<lbrace>\\<lambda>s. \\<forall>x \\<in> S. P x s\\<rbrace> f \\<lbrace>\\<lambda>rv s. \\<forall>x \\<in> S. Q x rv s\\<rbrace>,-\"\n  apply (simp add: validE_R_def validE_def)\n  apply (rule hoare_strengthen_post)\n   apply (erule hoare_vcg_const_Ball_lift)\n  apply (simp split: sum.splits)\n  done\n\nlemma hoare_vcg_all_lift:\n  \"\\<lbrakk> \\<And>x. \\<lbrace>P x\\<rbrace> f \\<lbrace>Q x\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>\\<lambda>s. \\<forall>x. P x s\\<rbrace> f \\<lbrace>\\<lambda>rv s. \\<forall>x. Q x rv s\\<rbrace>\"\n  by (fastforce simp: valid_def)\n\n(*\n * hoare_vcg_all_lift_R\n *\n * \\<And>x. \\<lbrace>?P x\\<rbrace> ?f \\<lbrace>?Q x\\<rbrace>, -) \\<Longrightarrow> \\<lbrace>\\<lambda>s. \\<forall>x. ?P x s\\<rbrace> ?f \\<lbrace>\\<lambda>rv s. \\<forall>x. ?Q x rv s\\<rbrace>, -\n *)\nlemmas hoare_vcg_all_lift_R = hoare_vcg_const_Ball_lift_R[where S=UNIV, simplified]\n\nlemma hoare_vcg_const_imp_lift:\n  \"\\<lbrakk> P \\<Longrightarrow> \\<lbrace>Q\\<rbrace> m \\<lbrace>R\\<rbrace> \\<rbrakk> \\<Longrightarrow>\n   \\<lbrace>\\<lambda>s. P \\<longrightarrow> Q s\\<rbrace> m \\<lbrace>\\<lambda>rv s. P \\<longrightarrow> R rv s\\<rbrace>\"\n  by (cases P, simp_all add: hoare_vcg_prop)\n\nlemma hoare_vcg_const_imp_lift_R:\n  \"(P \\<Longrightarrow> \\<lbrace>Q\\<rbrace> m \\<lbrace>R\\<rbrace>,-) \\<Longrightarrow> \\<lbrace>\\<lambda>s. P \\<longrightarrow> Q s\\<rbrace> m \\<lbrace>\\<lambda>rv s. P \\<longrightarrow> R rv s\\<rbrace>,-\"\n  by (fastforce simp: validE_R_def validE_def valid_def split_def split: sum.splits)\n\nlemma hoare_weak_lift_imp:\n  \"\\<lbrace>P'\\<rbrace> f \\<lbrace>Q\\<rbrace> \\<Longrightarrow> \\<lbrace>\\<lambda>s. P \\<longrightarrow> P' s\\<rbrace> f \\<lbrace>\\<lambda>rv s. P \\<longrightarrow> Q rv s\\<rbrace>\"\n  by (auto simp add: valid_def split_def)\n\nlemma hoare_vcg_ex_lift:\n  \"\\<lbrakk> \\<And>x. \\<lbrace>P x\\<rbrace> f \\<lbrace>Q x\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>\\<lambda>s. \\<exists>x. P x s\\<rbrace> f \\<lbrace>\\<lambda>rv s. \\<exists>x. Q x rv s\\<rbrace>\"\n  by (clarsimp simp: valid_def, blast)\n\nlemma hoare_vcg_ex_lift_R1:\n  \"(\\<And>x. \\<lbrace>P x\\<rbrace> f \\<lbrace>Q\\<rbrace>, -) \\<Longrightarrow> \\<lbrace>\\<lambda>s. \\<exists>x. P x s\\<rbrace> f \\<lbrace>Q\\<rbrace>, -\"\n  by (fastforce simp: valid_def validE_R_def validE_def split: sum.splits)\n\n(* for instantiations *)\nlemma hoare_triv:    \"\\<lbrace>P\\<rbrace>f\\<lbrace>Q\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace>f\\<lbrace>Q\\<rbrace>\" .\nlemma hoare_trivE:   \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\" .\nlemma hoare_trivE_R: \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,- \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,-\" .\nlemma hoare_trivR_R: \"\\<lbrace>P\\<rbrace> f -,\\<lbrace>E\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f -,\\<lbrace>E\\<rbrace>\" .\n\nlemma hoare_weaken_preE_E:\n  \"\\<lbrakk> \\<lbrace>P'\\<rbrace> f -,\\<lbrace>Q\\<rbrace>; \\<And>s. P s \\<Longrightarrow> P' s \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f -,\\<lbrace>Q\\<rbrace>\"\n  by (fastforce simp add: validE_E_def validE_def valid_def)\n\nlemma hoare_vcg_E_conj:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace> f -,\\<lbrace>E\\<rbrace>; \\<lbrace>P'\\<rbrace> f \\<lbrace>Q'\\<rbrace>,\\<lbrace>E'\\<rbrace> \\<rbrakk>\n    \\<Longrightarrow> \\<lbrace>\\<lambda>s. P s \\<and> P' s\\<rbrace> f \\<lbrace>Q'\\<rbrace>, \\<lbrace>\\<lambda>rv s. E rv s \\<and> E' rv s\\<rbrace>\"\n  apply (unfold validE_def validE_E_def)\n  apply (rule hoare_post_imp [OF _ hoare_vcg_conj_lift], simp_all)\n  apply (case_tac r, simp_all)\n  done\n\nlemma hoare_vcg_E_elim:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace> f -,\\<lbrace>E\\<rbrace>; \\<lbrace>P'\\<rbrace> f \\<lbrace>Q\\<rbrace>,- \\<rbrakk>\n    \\<Longrightarrow> \\<lbrace>\\<lambda>s. P s \\<and> P' s\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  by (rule hoare_post_impErr [OF hoare_vcg_E_conj],\n      (simp add: validE_R_def)+)\n\nlemma hoare_vcg_R_conj:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,-; \\<lbrace>P'\\<rbrace> f \\<lbrace>Q'\\<rbrace>,- \\<rbrakk>\n    \\<Longrightarrow> \\<lbrace>\\<lambda>s. P s \\<and> P' s\\<rbrace> f \\<lbrace>\\<lambda>rv s. Q rv s \\<and> Q' rv s\\<rbrace>,-\"\n  apply (unfold validE_R_def validE_def)\n  apply (rule hoare_post_imp [OF _ hoare_vcg_conj_lift], simp_all)\n  apply (case_tac r, simp_all)\n  done\n\nlemma valid_validE:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>rv. Q\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>rv. Q\\<rbrace>,\\<lbrace>\\<lambda>rv. Q\\<rbrace>\"\n  apply (simp add: validE_def)\n  done\n\nlemma valid_validE2:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>_. Q'\\<rbrace>; \\<And>s. Q' s \\<Longrightarrow> Q s; \\<And>s. Q' s \\<Longrightarrow> E s \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>_. Q\\<rbrace>,\\<lbrace>\\<lambda>_. E\\<rbrace>\"\n  unfolding valid_def validE_def\n  by (clarsimp split: sum.splits) blast\n\nlemma validE_valid: \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>rv. Q\\<rbrace>,\\<lbrace>\\<lambda>rv. Q\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>rv. Q\\<rbrace>\"\n  apply (unfold validE_def)\n  apply (rule hoare_post_imp)\n   defer\n   apply assumption\n  apply (case_tac r, simp_all)\n  done\n\nlemma valid_validE_R:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>rv. Q\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>rv. Q\\<rbrace>,-\"\n  by (simp add: validE_R_def hoare_post_impErr [OF valid_validE])\n\nlemma valid_validE_E:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>rv. Q\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f -,\\<lbrace>\\<lambda>rv. Q\\<rbrace>\"\n  by (simp add: validE_E_def hoare_post_impErr [OF valid_validE])\n\nlemma validE_validE_R: \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>\\<top>\\<top>\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,-\"\n  by (simp add: validE_R_def)\n\nlemma validE_R_validE: \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,- \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>\\<top>\\<top>\\<rbrace>\"\n  by (simp add: validE_R_def)\n\nlemma hoare_post_imp_R: \"\\<lbrakk> \\<lbrace>P\\<rbrace> f \\<lbrace>Q'\\<rbrace>,-; \\<And>r s. Q' r s \\<Longrightarrow> Q r s \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,-\"\n  apply (unfold validE_R_def)\n  apply (rule hoare_post_impErr, simp+)\n  done\n\nlemma hoare_post_comb_imp_conj:\n  \"\\<lbrakk> \\<lbrace>P'\\<rbrace> f \\<lbrace>Q\\<rbrace>; \\<lbrace>P\\<rbrace> f \\<lbrace>Q'\\<rbrace>; \\<And>s. P s \\<Longrightarrow> P' s \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>rv s. Q rv s \\<and> Q' rv s\\<rbrace>\"\n  apply (rule hoare_pre_imp)\n   defer\n   apply (rule hoare_vcg_conj_lift)\n    apply assumption+\n  apply simp\n  done\n\nlemma hoare_vcg_precond_impE_R: \"\\<lbrakk> \\<lbrace>P'\\<rbrace> f \\<lbrace>Q\\<rbrace>,-; \\<And>s. P s \\<Longrightarrow> P' s \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,-\"\n  by (unfold validE_R_def, rule hoare_vcg_precond_impE, simp+)\n\nlemma valid_is_triple:\n  \"valid P f Q = triple_judgement P f (postcondition Q (\\<lambda>s f. fst (f s)))\"\n  by (simp add: triple_judgement_def valid_def postcondition_def)\n\nlemma validE_is_triple:\n  \"validE P f Q E = triple_judgement P f\n    (postconditions (postcondition Q (\\<lambda>s f. {(rv, s'). (Inr rv, s') \\<in> fst (f s)}))\n          (postcondition E (\\<lambda>s f. {(rv, s'). (Inl rv, s') \\<in> fst (f s)})))\"\n  apply (simp add: validE_def triple_judgement_def valid_def postcondition_def\n                   postconditions_def split_def split: sum.split)\n  apply fastforce\n  done\n\nlemma validE_R_is_triple:\n  \"validE_R P f Q = triple_judgement P f\n     (postcondition Q (\\<lambda>s f. {(rv, s'). (Inr rv, s') \\<in> fst (f s)}))\"\n  by (simp add: validE_R_def validE_is_triple postconditions_def postcondition_def)\n\nlemma validE_E_is_triple:\n  \"validE_E P f E = triple_judgement P f\n     (postcondition E (\\<lambda>s f. {(rv, s'). (Inl rv, s') \\<in> fst (f s)}))\"\n  by (simp add: validE_E_def validE_is_triple postconditions_def postcondition_def)\n\nlemmas hoare_wp_combs =\n  hoare_post_comb_imp_conj hoare_vcg_precond_imp hoare_vcg_conj_lift\n\nlemmas hoare_wp_combsE =\n  hoare_vcg_precond_impE\n  hoare_vcg_precond_impE_R\n  validE_validE_R\n  hoare_vcg_R_conj\n  hoare_vcg_E_elim\n  hoare_vcg_E_conj\n\nlemmas hoare_wp_state_combsE =\n  hoare_vcg_precond_impE[OF valid_validE]\n  hoare_vcg_precond_impE_R[OF valid_validE_R]\n  valid_validE_R\n  hoare_vcg_R_conj[OF valid_validE_R]\n  hoare_vcg_E_elim[OF valid_validE_E]\n  hoare_vcg_E_conj[OF valid_validE_E]\n\nlemmas hoare_wp_splits [wp_split] =\n  hoare_seq_ext hoare_vcg_seqE handleE'_wp handleE_wp\n  validE_validE_R [OF hoare_vcg_seqE [OF validE_R_validE]]\n  validE_validE_R [OF handleE'_wp [OF validE_R_validE]]\n  validE_validE_R [OF handleE_wp [OF validE_R_validE]]\n  catch_wp hoare_vcg_split_if hoare_vcg_split_ifE\n  validE_validE_R [OF hoare_vcg_split_ifE [OF validE_R_validE validE_R_validE]]\n  liftM_wp liftME_wp\n  validE_validE_R [OF liftME_wp [OF validE_R_validE]]\n  validE_valid\n\nlemmas [wp_comb] = hoare_wp_state_combsE hoare_wp_combsE  hoare_wp_combs\n\nlemmas [wp] = hoare_vcg_prop\n              return_wp\n              put_wp\n              get_wp\n              gets_wp\n              modify_wp\n              returnOk_wp\n              throwError_wp\n              fail_wp\n              failE_wp\n              liftE_wp\n              select_f_wp\n\nlemmas [wp_trip] = valid_is_triple validE_is_triple validE_E_is_triple validE_R_is_triple\n\ntext {* Simplifications on conjunction *}\n\nlemma hoare_post_eq: \"\\<lbrakk> Q = Q'; \\<lbrace>P\\<rbrace> f \\<lbrace>Q'\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>\"\n  by simp\nlemma hoare_post_eqE1: \"\\<lbrakk> Q = Q'; \\<lbrace>P\\<rbrace> f \\<lbrace>Q'\\<rbrace>,\\<lbrace>E\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  by simp\nlemma hoare_post_eqE2: \"\\<lbrakk> E = E'; \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>E'\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  by simp\nlemma hoare_post_eqE_R: \"\\<lbrakk> Q = Q'; \\<lbrace>P\\<rbrace> f \\<lbrace>Q'\\<rbrace>,- \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,-\"\n  by simp\n\nlemma pred_conj_apply_elim: \"(\\<lambda>r. Q r and Q' r) = (\\<lambda>r s. Q r s \\<and> Q' r s)\"\n  by (simp add: pred_conj_def)\nlemma pred_conj_conj_elim: \"(\\<lambda>r s. (Q r and Q' r) s \\<and> Q'' r s) = (\\<lambda>r s. Q r s \\<and> Q' r s \\<and> Q'' r s)\"\n  by simp\nlemma conj_assoc_apply: \"(\\<lambda>r s. (Q r s \\<and> Q' r s) \\<and> Q'' r s) = (\\<lambda>r s. Q r s \\<and> Q' r s \\<and> Q'' r s)\"\n  by simp\nlemma all_elim: \"(\\<lambda>rv s. \\<forall>x. P rv s) = P\"\n  by simp\nlemma all_conj_elim: \"(\\<lambda>rv s. (\\<forall>x. P rv s) \\<and> Q rv s) = (\\<lambda>rv s. P rv s \\<and> Q rv s)\"\n  by simp\n\nlemmas vcg_rhs_simps = pred_conj_apply_elim pred_conj_conj_elim\n          conj_assoc_apply all_elim all_conj_elim\n\nlemma if_apply_reduct: \"\\<lbrace>P\\<rbrace> If P' (f x) (g x) \\<lbrace>Q\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> If P' f g x \\<lbrace>Q\\<rbrace>\"\n  by (cases P', simp_all)\nlemma if_apply_reductE: \"\\<lbrace>P\\<rbrace> If P' (f x) (g x) \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> If P' f g x \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  by (cases P', simp_all)\nlemma if_apply_reductE_R: \"\\<lbrace>P\\<rbrace> If P' (f x) (g x) \\<lbrace>Q\\<rbrace>,- \\<Longrightarrow> \\<lbrace>P\\<rbrace> If P' f g x \\<lbrace>Q\\<rbrace>,-\"\n  by (cases P', simp_all)\n\nlemmas hoare_wp_simps [wp_split] =\n  vcg_rhs_simps [THEN hoare_post_eq] vcg_rhs_simps [THEN hoare_post_eqE1]\n  vcg_rhs_simps [THEN hoare_post_eqE2] vcg_rhs_simps [THEN hoare_post_eqE_R]\n  if_apply_reduct if_apply_reductE if_apply_reductE_R TrueI\n\nschematic_lemma if_apply_test: \"\\<lbrace>?Q\\<rbrace> (if A then returnOk else K fail) x \\<lbrace>P\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  apply (wp | unfold K_def)+\n  done\n\nlemma hoare_elim_pred_conj:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. Q r s \\<and> Q' r s\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r. Q r and Q' r\\<rbrace>\"\n  by (unfold pred_conj_def)\n\nlemma hoare_elim_pred_conjE1:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. Q r s \\<and> Q' r s\\<rbrace>,\\<lbrace>E\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r. Q r and Q' r\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  by (unfold pred_conj_def)\n\nlemma hoare_elim_pred_conjE2:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>, \\<lbrace>\\<lambda>x s. E x s \\<and> E' x s\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>\\<lambda>x. E x and E' x\\<rbrace>\"\n  by (unfold pred_conj_def)\n\nlemma hoare_elim_pred_conjE_R:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. Q r s \\<and> Q' r s\\<rbrace>,- \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r. Q r and Q' r\\<rbrace>,-\"\n  by (unfold pred_conj_def)\n\nlemmas hoare_wp_pred_conj_elims =\n  hoare_elim_pred_conj hoare_elim_pred_conjE1\n  hoare_elim_pred_conjE2 hoare_elim_pred_conjE_R\n\nlemmas hoare_weaken_preE = hoare_vcg_precond_impE\n\nlemmas hoare_pre =\n  hoare_weaken_pre\n  hoare_weaken_preE\n  hoare_vcg_precond_impE_R\n  hoare_weaken_preE_E\n\ntext {* Miscellaneous lemmas on hoare triples *}\n\nlemma hoare_vcg_mp:\n  assumes a: \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>\"\n  assumes b: \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. Q r s \\<longrightarrow> Q' r s\\<rbrace>\"\n  shows \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q'\\<rbrace>\"\n  using assms\n  by (auto simp: valid_def split_def)\n\n(* note about this precond stuff: rules get a chance to bind directly\n   before any of their combined forms. As a result, these precondition\n   implication rules are only used when needed. *)\n\nlemma hoare_add_post:\n  assumes r: \"\\<lbrace>P'\\<rbrace> f \\<lbrace>Q'\\<rbrace>\"\n  assumes impP: \"\\<And>s. P s \\<Longrightarrow> P' s\"\n  assumes impQ: \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>rv s. Q' rv s \\<longrightarrow> Q rv s\\<rbrace>\"\n  shows \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>\"\n  apply (rule hoare_chain)\n    apply (rule hoare_vcg_conj_lift)\n     apply (rule r)\n    apply (rule impQ)\n   apply simp\n   apply (erule impP)\n  apply simp\n  done\n\nlemma hoare_whenE_wp:\n  \"(P \\<Longrightarrow> \\<lbrace>Q\\<rbrace> f \\<lbrace>R\\<rbrace>, \\<lbrace>E\\<rbrace>) \\<Longrightarrow> \\<lbrace>if P then Q else R ()\\<rbrace> whenE P f \\<lbrace>R\\<rbrace>, \\<lbrace>E\\<rbrace>\"\n  unfolding whenE_def\n  apply clarsimp\n  apply wp\n  done\n\nlemma hoare_gen_asmE:\n  \"(P \\<Longrightarrow> \\<lbrace>P'\\<rbrace> f \\<lbrace>Q\\<rbrace>,-) \\<Longrightarrow> \\<lbrace>P' and K P\\<rbrace> f \\<lbrace>Q\\<rbrace>, -\"\n  by (simp add: validE_R_def validE_def valid_def) blast\n\nlemma hoare_list_case:\n  assumes P1: \"\\<lbrace>P1\\<rbrace> f f1 \\<lbrace>Q\\<rbrace>\"\n  assumes P2: \"\\<And>y ys. xs = y#ys \\<Longrightarrow> \\<lbrace>P2 y ys\\<rbrace> f (f2 y ys) \\<lbrace>Q\\<rbrace>\"\n  shows \"\\<lbrace>case xs of [] \\<Rightarrow> P1 | y#ys \\<Rightarrow> P2 y ys\\<rbrace>\n         f (case xs of [] \\<Rightarrow> f1 | y#ys \\<Rightarrow> f2 y ys)\n         \\<lbrace>Q\\<rbrace>\"\n  apply (cases xs)\n   apply simp\n   apply (rule P1)\n  apply simp\n  apply (rule P2)\n  apply simp\n  done\n\nlemma hoare_unless_wp:\n  \"(\\<not>P \\<Longrightarrow> \\<lbrace>Q\\<rbrace> f \\<lbrace>R\\<rbrace>) \\<Longrightarrow> \\<lbrace>if P then R () else Q\\<rbrace> unless P f \\<lbrace>R\\<rbrace>\"\n  unfolding unless_def by wp auto\n\nlemma hoare_use_eq:\n  assumes x: \"\\<And>P. \\<lbrace>\\<lambda>s. P (f s)\\<rbrace> m \\<lbrace>\\<lambda>rv s. P (f s)\\<rbrace>\"\n  assumes y: \"\\<And>f. \\<lbrace>\\<lambda>s. P f s\\<rbrace> m \\<lbrace>\\<lambda>rv s. Q f s\\<rbrace>\"\n  shows \"\\<lbrace>\\<lambda>s. P (f s) s\\<rbrace> m \\<lbrace>\\<lambda>rv s. Q (f s :: 'c :: type) s \\<rbrace>\"\n  apply (rule_tac Q=\"\\<lambda>rv s. \\<exists>f'. f' = f s \\<and> Q f' s\" in hoare_post_imp)\n   apply simp\n  apply (wp hoare_vcg_ex_lift x y)\n  apply simp\n  done\n\nlemma hoare_return_sp:\n  \"\\<lbrace>P\\<rbrace> return x \\<lbrace>\\<lambda>r. P and K (r = x)\\<rbrace>\"\n  by (simp add: valid_def return_def)\n\nlemma hoare_fail_any [simp]:\n  \"\\<lbrace>P\\<rbrace> fail \\<lbrace>Q\\<rbrace>\" by wp\n\nlemma hoare_failE [simp]: \"\\<lbrace>P\\<rbrace> fail \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\" by  wp\n\nlemma hoare_FalseE [simp]:\n  \"\\<lbrace>\\<lambda>s. False\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  by (simp add: valid_def validE_def)\n\nlemma hoare_K_bind [wp]:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> K_bind f x \\<lbrace>Q\\<rbrace>\"\n  by simp\n\ntext {* Setting up the precondition case splitter. *}\n\nlemma wpc_helper_valid:\n  \"\\<lbrace>Q\\<rbrace> g \\<lbrace>S\\<rbrace> \\<Longrightarrow> wpc_helper (P, P') (Q, Q') \\<lbrace>P\\<rbrace> g \\<lbrace>S\\<rbrace>\"\n  by (clarsimp simp: wpc_helper_def elim!: hoare_pre)\n\nlemma wpc_helper_validE:\n  \"\\<lbrace>Q\\<rbrace> f \\<lbrace>R\\<rbrace>,\\<lbrace>E\\<rbrace> \\<Longrightarrow> wpc_helper (P, P') (Q, Q') \\<lbrace>P\\<rbrace> f \\<lbrace>R\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  by (clarsimp simp: wpc_helper_def elim!: hoare_pre)\n\nlemma wpc_helper_validE_R:\n  \"\\<lbrace>Q\\<rbrace> f \\<lbrace>R\\<rbrace>,- \\<Longrightarrow> wpc_helper (P, P') (Q, Q') \\<lbrace>P\\<rbrace> f \\<lbrace>R\\<rbrace>,-\"\n  by (clarsimp simp: wpc_helper_def elim!: hoare_pre)\n\nlemma wpc_helper_validR_R:\n  \"\\<lbrace>Q\\<rbrace> f -,\\<lbrace>E\\<rbrace> \\<Longrightarrow> wpc_helper (P, P') (Q, Q') \\<lbrace>P\\<rbrace> f -,\\<lbrace>E\\<rbrace>\"\n  by (clarsimp simp: wpc_helper_def elim!: hoare_pre)\n\nlemma wpc_helper_no_fail_final:\n  \"no_fail Q f \\<Longrightarrow> wpc_helper (P, P') (Q, Q') (no_fail P f)\"\n  by (clarsimp simp: wpc_helper_def elim!: no_fail_pre)\n\nlemma wpc_helper_validNF:\n  \"\\<lbrace>Q\\<rbrace> g \\<lbrace>S\\<rbrace>! \\<Longrightarrow> wpc_helper (P, P') (Q, Q') \\<lbrace>P\\<rbrace> g \\<lbrace>S\\<rbrace>!\"\n  apply (clarsimp simp: wpc_helper_def)\n  by (metis hoare_wp_combs(2) no_fail_pre validNF_def)\n\nwpc_setup \"\\<lambda>m. \\<lbrace>P\\<rbrace> m \\<lbrace>Q\\<rbrace>\" wpc_helper_valid\nwpc_setup \"\\<lambda>m. \\<lbrace>P\\<rbrace> m \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\" wpc_helper_validE\nwpc_setup \"\\<lambda>m. \\<lbrace>P\\<rbrace> m \\<lbrace>Q\\<rbrace>,-\" wpc_helper_validE_R\nwpc_setup \"\\<lambda>m. \\<lbrace>P\\<rbrace> m -,\\<lbrace>E\\<rbrace>\" wpc_helper_validR_R\nwpc_setup \"\\<lambda>m. no_fail P m\" wpc_helper_no_fail_final\nwpc_setup \"\\<lambda>m. \\<lbrace>P\\<rbrace> m \\<lbrace>Q\\<rbrace>!\" wpc_helper_validNF\n\n\nlemma in_liftM:\n \"((r, s') \\<in> fst (liftM t f s)) = (\\<exists>r'. (r', s') \\<in> fst (f s) \\<and> r = t r')\"\n  apply (simp add: liftM_def return_def bind_def)\n  apply (simp add: Bex_def)\n  done\n\n(*\n * handy_liftM_lemma\n *\n * ((?r, ?s') \\<in> fst (liftM ?t ?f ?s)) = (\\<exists>r'. (r', ?s') \\<in> fst (?f ?s) \\<and> ?r = ?t r')\n *)\nlemmas handy_liftM_lemma = in_liftM\n\nlemma hoare_fun_app_wp[wp]:\n  \"\\<lbrace>P\\<rbrace> f' x \\<lbrace>Q'\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f' $ x \\<lbrace>Q'\\<rbrace>\"\n  \"\\<lbrace>P\\<rbrace> f x \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f $ x \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  \"\\<lbrace>P\\<rbrace> f x \\<lbrace>Q\\<rbrace>,- \\<Longrightarrow> \\<lbrace>P\\<rbrace> f $ x \\<lbrace>Q\\<rbrace>,-\"\n  \"\\<lbrace>P\\<rbrace> f x -,\\<lbrace>E\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f $ x -,\\<lbrace>E\\<rbrace>\"\n  by simp+\n\nlemma hoare_validE_pred_conj:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace>f\\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>; \\<lbrace>P\\<rbrace>f\\<lbrace>R\\<rbrace>,\\<lbrace>E\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace>f\\<lbrace>Q And R\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  unfolding valid_def validE_def by (simp add: split_def split: sum.splits)\n\nlemma hoare_validE_conj:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace>f\\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>; \\<lbrace>P\\<rbrace>f\\<lbrace>R\\<rbrace>,\\<lbrace>E\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. Q r s \\<and> R r s\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  unfolding valid_def validE_def by (simp add: split_def split: sum.splits)\n\nlemma hoare_valid_validE:\n  \"\\<lbrace>P\\<rbrace>f\\<lbrace>\\<lambda>r. Q\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace>f\\<lbrace>\\<lambda>r. Q\\<rbrace>,\\<lbrace>\\<lambda>r. Q\\<rbrace>\"\n  unfolding valid_def validE_def by (simp add: split_def split: sum.splits)\n\nlemma liftE_validE_E [wp]:\n  \"\\<lbrace>\\<top>\\<rbrace> liftE f -, \\<lbrace>Q\\<rbrace>\"\n  by (clarsimp simp: validE_E_def valid_def)\n\nlemma validE_validE_E [wp_comb]:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<top>\\<top>\\<rbrace>, \\<lbrace>E\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f -, \\<lbrace>E\\<rbrace>\"\n  by (simp add: validE_E_def)\n\nlemma validE_E_validE:\n  \"\\<lbrace>P\\<rbrace> f -, \\<lbrace>E\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<top>\\<top>\\<rbrace>, \\<lbrace>E\\<rbrace>\"\n  by (simp add: validE_E_def)\n\n(*\n * if_validE_E:\n *\n * \\<lbrakk>?P1 \\<Longrightarrow> \\<lbrace>?Q1\\<rbrace> ?f1 -, \\<lbrace>?E\\<rbrace>; \\<not> ?P1 \\<Longrightarrow> \\<lbrace>?R1\\<rbrace> ?g1 -, \\<lbrace>?E\\<rbrace>\\<rbrakk> \\<Longrightarrow> \\<lbrace>\\<lambda>s. (?P1 \\<longrightarrow> ?Q1 s) \\<and> (\\<not> ?P1 \\<longrightarrow> ?R1 s)\\<rbrace> if ?P1 then ?f1 else ?g1 -, \\<lbrace>?E\\<rbrace>\n *)\nlemmas if_validE_E [wp_split] =\n  validE_validE_E [OF hoare_vcg_split_ifE [OF validE_E_validE validE_E_validE]]\n\nlemma returnOk_E [wp]:\n  \"\\<lbrace>\\<top>\\<rbrace> returnOk r -, \\<lbrace>Q\\<rbrace>\"\n  by (simp add: validE_E_def) wp\n\nlemma hoare_drop_imp:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. R r s \\<longrightarrow> Q r s\\<rbrace>\"\n  by (auto simp: valid_def)\n\nlemma hoare_drop_impE:\n  \"\\<lbrakk>\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r. Q\\<rbrace>, \\<lbrace>E\\<rbrace>\\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. R r s \\<longrightarrow> Q s\\<rbrace>, \\<lbrace>E\\<rbrace>\"\n  by (metis (lifting, mono_tags) hoare_post_impErr')\n\nlemma hoare_drop_impE_R:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,- \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. R r s \\<longrightarrow> Q r s\\<rbrace>, -\"\n  by (auto simp: validE_R_def validE_def valid_def split_def split: sum.splits)\n\nlemma hoare_drop_impE_E:\n  \"\\<lbrace>P\\<rbrace> f -,\\<lbrace>Q\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f -,\\<lbrace>\\<lambda>r s. R r s \\<longrightarrow> Q r s\\<rbrace>\"\n  by (auto simp: validE_E_def validE_def valid_def split_def split: sum.splits)\n\nlemmas hoare_drop_imps = hoare_drop_imp hoare_drop_impE_R hoare_drop_impE_E\n\nlemma bind_det_exec:\n  \"fst (a s) = {(r,s')} \\<Longrightarrow> fst ((a >>= b) s) = fst (b r s')\"\n  by (simp add: bind_def)\n\nlemma in_bind_det_exec:\n  \"fst (a s) = {(r,s')} \\<Longrightarrow> (s'' \\<in> fst ((a >>= b) s)) = (s'' \\<in> fst (b r s'))\"\n  by (simp add: bind_def)\n\nlemma exec_put:\n  \"(put s' >>= m) s = m () s'\"\n  by (simp add: bind_def put_def)\n\nlemma bind_execI:\n  \"\\<lbrakk> (r'',s'') \\<in> fst (f s); \\<exists>x \\<in> fst (g r'' s''). P x \\<rbrakk> \\<Longrightarrow>\n  \\<exists>x \\<in> fst ((f >>= g) s). P x\"\n  by (force simp: in_bind split_def bind_def)\n\nlemma True_E_E [wp]: \"\\<lbrace>\\<top>\\<rbrace> f -,\\<lbrace>\\<top>\\<top>\\<rbrace>\"\n  by (auto simp: validE_E_def validE_def valid_def split: sum.splits)\n\n(*\n * \\<lbrakk>\\<And>x. \\<lbrace>?B1 x\\<rbrace> ?g1 x -, \\<lbrace>?E\\<rbrace>; \\<lbrace>?P\\<rbrace> ?f1 \\<lbrace>?B1\\<rbrace>, \\<lbrace>?E\\<rbrace>\\<rbrakk> \\<Longrightarrow> \\<lbrace>?P\\<rbrace> ?f1 >>=E ?g1 -, \\<lbrace>?E\\<rbrace>\n *)\nlemmas [wp_split] =\n  validE_validE_E [OF hoare_vcg_seqE [OF validE_E_validE]]\n\nlemma case_option_wp:\n  assumes x: \"\\<And>x. \\<lbrace>P x\\<rbrace> m x \\<lbrace>Q\\<rbrace>\"\n  assumes y: \"\\<lbrace>P'\\<rbrace> m' \\<lbrace>Q\\<rbrace>\"\n  shows      \"\\<lbrace>\\<lambda>s. (x = None \\<longrightarrow> P' s) \\<and> (x \\<noteq> None \\<longrightarrow> P (the x) s)\\<rbrace>\n                case_option m' m x \\<lbrace>Q\\<rbrace>\"\n  apply (cases x, simp_all)\n   apply (rule y)\n  apply (rule x)\n  done\n\nlemma case_option_wpE:\n  assumes x: \"\\<And>x. \\<lbrace>P x\\<rbrace> m x \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  assumes y: \"\\<lbrace>P'\\<rbrace> m' \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  shows      \"\\<lbrace>\\<lambda>s. (x = None \\<longrightarrow> P' s) \\<and> (x \\<noteq> None \\<longrightarrow> P (the x) s)\\<rbrace>\n                case_option m' m x \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>\"\n  apply (cases x, simp_all)\n   apply (rule y)\n  apply (rule x)\n  done\n\nlemma in_bindE:\n  \"(rv, s') \\<in> fst ((f >>=E (\\<lambda>rv'. g rv')) s) =\n  ((\\<exists>ex. rv = Inl ex \\<and> (Inl ex, s') \\<in> fst (f s)) \\<or>\n  (\\<exists>rv' s''. (rv, s') \\<in> fst (g rv' s'') \\<and> (Inr rv', s'') \\<in> fst (f s)))\"\n  apply (rule iffI)\n   apply (clarsimp simp: bindE_def bind_def)\n   apply (case_tac a)\n    apply (clarsimp simp: lift_def throwError_def return_def)\n   apply (clarsimp simp: lift_def)\n  apply safe\n   apply (clarsimp simp: bindE_def bind_def)\n   apply (erule rev_bexI)\n   apply (simp add: lift_def throwError_def return_def)\n  apply (clarsimp simp: bindE_def bind_def)\n  apply (erule rev_bexI)\n  apply (simp add: lift_def)\n  done\n\n(*\n * \\<lbrace>?P\\<rbrace> ?m1 -, \\<lbrace>?E\\<rbrace> \\<Longrightarrow> \\<lbrace>?P\\<rbrace> liftME ?f1 ?m1 -, \\<lbrace>?E\\<rbrace>\n *)\nlemmas [wp_split] = validE_validE_E [OF liftME_wp, simplified, OF validE_E_validE]\n\nlemma assert_A_True[simp]: \"assert True = return ()\"\n  by (simp add: assert_def)\n\nlemma assert_wp [wp]: \"\\<lbrace>\\<lambda>s. P \\<longrightarrow> Q () s\\<rbrace> assert P \\<lbrace>Q\\<rbrace>\"\n  by (cases P, (simp add: assert_def | wp)+)\n\nlemma list_cases_wp:\n  assumes a: \"\\<lbrace>P_A\\<rbrace> a \\<lbrace>Q\\<rbrace>\"\n  assumes b: \"\\<And>x xs. ts = x#xs \\<Longrightarrow> \\<lbrace>P_B x xs\\<rbrace> b x xs \\<lbrace>Q\\<rbrace>\"\n  shows \"\\<lbrace>case_list P_A P_B ts\\<rbrace> case ts of [] \\<Rightarrow> a | x # xs \\<Rightarrow> b x xs \\<lbrace>Q\\<rbrace>\"\n  by (cases ts, auto simp: a b)\n\n(* FIXME: make wp *)\nlemma whenE_throwError_wp:\n  \"\\<lbrace>\\<lambda>s. \\<not>Q \\<longrightarrow> P s\\<rbrace> whenE Q (throwError e) \\<lbrace>\\<lambda>rv. P\\<rbrace>, -\"\n  apply (simp add: whenE_def split del: split_if)\n  apply (rule hoare_pre)\n   apply wp\n  apply simp\n  done\n\nlemma select_throwError_wp:\n  \"\\<lbrace>\\<lambda>s. \\<forall>x\\<in>S. Q x s\\<rbrace> select S >>= throwError -, \\<lbrace>Q\\<rbrace>\"\n  by (simp add: bind_def throwError_def return_def select_def validE_E_def\n                validE_def valid_def)\n\n\nsection \"validNF Rules\"\n\nsubsection \"Basic validNF theorems\"\n\nlemma validNF [intro?]:\n  \"\\<lbrakk> \\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>; no_fail P f \\<rbrakk> \\<Longrightarrow> \\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>!\"\n  apply (clarsimp simp: validNF_def)\n  done\n\nlemma validNF_valid: \"\\<lbrakk> \\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>! \\<rbrakk> \\<Longrightarrow> \\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  apply (clarsimp simp: validNF_def)\n  done\n\nlemma validNF_no_fail: \"\\<lbrakk> \\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>! \\<rbrakk> \\<Longrightarrow> no_fail P f\"\n  apply (clarsimp simp: validNF_def)\n  done\n\nlemma snd_validNF:\n  \"\\<lbrakk> \\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>!; P s \\<rbrakk> \\<Longrightarrow> \\<not> snd (f s)\"\n  by (clarsimp simp: validNF_def no_fail_def)\n\nlemma use_validNF:\n  \"\\<lbrakk> (r', s') \\<in> fst (f s); \\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>!; P s \\<rbrakk> \\<Longrightarrow> Q r' s'\"\n  by (fastforce simp: validNF_def valid_def)\n\nsubsection \"validNF weakest pre-condition rules\"\n\nlemma validNF_return [wp]:\n  \"\\<lbrace> P x \\<rbrace> return x \\<lbrace> P \\<rbrace>!\"\n  apply rule\n   apply wp\n  apply (clarsimp simp: no_fail_def return_def)\n  done\n\nlemma validNF_get [wp]:\n  \"\\<lbrace> \\<lambda>s. P s s  \\<rbrace> get \\<lbrace> P \\<rbrace>!\"\n  apply rule\n   apply wp\n  apply (clarsimp simp: no_fail_def get_def)\n  done\n\nlemma validNF_put [wp]:\n  \"\\<lbrace> \\<lambda>s. P () x  \\<rbrace> put x \\<lbrace> P \\<rbrace>!\"\n  apply rule\n   apply wp\n  apply (clarsimp simp: no_fail_def put_def)\n  done\n\nlemma validNF_K_bind [wp]:\n  \"\\<lbrace> P \\<rbrace> x \\<lbrace> Q \\<rbrace>! \\<Longrightarrow> \\<lbrace> P \\<rbrace> K_bind x f \\<lbrace> Q \\<rbrace>!\"\n  apply (clarsimp simp: validNF_def)\n  done\n\nlemma validNF_fail [wp]:\n  \"\\<lbrace> \\<lambda>s. False \\<rbrace> fail \\<lbrace> Q \\<rbrace>!\"\n  by (clarsimp simp: validNF_def fail_def no_fail_def)\n\nlemma validNF_prop [wp_unsafe]:\n    \"\\<lbrakk> no_fail (\\<lambda>s. P) f \\<rbrakk> \\<Longrightarrow> \\<lbrace> \\<lambda>s. P \\<rbrace> f \\<lbrace> \\<lambda>rv s. P \\<rbrace>!\"\n  apply rule\n   apply wp\n  apply simp\n  done\n\nlemma validNF_post_conj [intro!]:\n  \"\\<lbrakk> \\<lbrace> P \\<rbrace> a \\<lbrace> Q \\<rbrace>!; \\<lbrace> P \\<rbrace> a \\<lbrace> R \\<rbrace>! \\<rbrakk> \\<Longrightarrow> \\<lbrace> P \\<rbrace> a \\<lbrace> Q And R \\<rbrace>!\"\n  apply (clarsimp simp: validNF_def)\n  done\n\nlemma validNF_pre_disj [intro!]:\n  \"\\<lbrakk> \\<lbrace> P \\<rbrace> a \\<lbrace> R \\<rbrace>!; \\<lbrace> Q \\<rbrace> a \\<lbrace> R \\<rbrace>! \\<rbrakk> \\<Longrightarrow> \\<lbrace> P or Q \\<rbrace> a \\<lbrace> R \\<rbrace>!\"\n  apply rule\n   apply (drule validNF_valid)+\n   apply auto[1]\n  apply (drule validNF_no_fail)+\n  apply (clarsimp simp: no_fail_def)\n  done\n\n(*\n * Setup combination rules for WP, which also requires\n * a \"wp_trip\" rule for validNF.\n *)\n\ndefinition \"validNF_property Q s b \\<equiv> \\<not> snd (b s) \\<and> (\\<forall>(r', s') \\<in> fst (b s). Q r' s')\"\n\nlemma validNF_is_triple [wp_trip]:\n  \"validNF P f Q = triple_judgement P f (validNF_property Q)\"\n  apply (clarsimp simp: validNF_def triple_judgement_def validNF_property_def)\n  apply (clarsimp simp: no_fail_def valid_def)\n  apply auto\n  done\n\nlemma validNF_weaken_pre [wp_comb]:\n  \"\\<lbrakk>\\<lbrace>Q\\<rbrace> a \\<lbrace>R\\<rbrace>!; \\<And>s. P s \\<Longrightarrow> Q s\\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> a \\<lbrace>R\\<rbrace>!\"\n  by (metis hoare_pre_imp no_fail_pre validNF_def)\n\nlemma validNF_post_comb_imp_conj:\n  \"\\<lbrakk> \\<lbrace>P'\\<rbrace> f \\<lbrace>Q\\<rbrace>!; \\<lbrace>P\\<rbrace> f \\<lbrace>Q'\\<rbrace>!; \\<And>s. P s \\<Longrightarrow> P' s \\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>rv s. Q rv s \\<and> Q' rv s\\<rbrace>!\"\n  by (fastforce simp: validNF_def valid_def)\n\nlemma validNF_post_comb_conj_L:\n  \"\\<lbrakk> \\<lbrace>P'\\<rbrace> f \\<lbrace>Q\\<rbrace>!; \\<lbrace>P\\<rbrace> f \\<lbrace>Q'\\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>\\<lambda>s. P s \\<and> P' s \\<rbrace> f \\<lbrace>\\<lambda>rv s. Q rv s \\<and> Q' rv s\\<rbrace>!\"\n  apply (clarsimp simp: validNF_def valid_def no_fail_def)\n  apply force\n  done\n\nlemma validNF_post_comb_conj_R:\n  \"\\<lbrakk> \\<lbrace>P'\\<rbrace> f \\<lbrace>Q\\<rbrace>; \\<lbrace>P\\<rbrace> f \\<lbrace>Q'\\<rbrace>! \\<rbrakk> \\<Longrightarrow> \\<lbrace>\\<lambda>s. P s \\<and> P' s \\<rbrace> f \\<lbrace>\\<lambda>rv s. Q rv s \\<and> Q' rv s\\<rbrace>!\"\n  apply (clarsimp simp: validNF_def valid_def no_fail_def)\n  apply force\n  done\n\nlemma validNF_post_comb_conj:\n  \"\\<lbrakk> \\<lbrace>P'\\<rbrace> f \\<lbrace>Q\\<rbrace>!; \\<lbrace>P\\<rbrace> f \\<lbrace>Q'\\<rbrace>! \\<rbrakk> \\<Longrightarrow> \\<lbrace>\\<lambda>s. P s \\<and> P' s \\<rbrace> f \\<lbrace>\\<lambda>rv s. Q rv s \\<and> Q' rv s\\<rbrace>!\"\n  apply (clarsimp simp: validNF_def valid_def no_fail_def)\n  apply force\n  done\n\nlemma validNF_split_if [wp_split]:\n  \"\\<lbrakk>P \\<Longrightarrow> \\<lbrace>Q\\<rbrace> f \\<lbrace>S\\<rbrace>!; \\<not> P \\<Longrightarrow> \\<lbrace>R\\<rbrace> g \\<lbrace>S\\<rbrace>!\\<rbrakk> \\<Longrightarrow> \\<lbrace>\\<lambda>s. (P \\<longrightarrow> Q s) \\<and> (\\<not> P \\<longrightarrow> R s)\\<rbrace> if P then f else g \\<lbrace>S\\<rbrace>!\"\n  by simp\n\nlemma validNF_vcg_conj_lift:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>!; \\<lbrace>P'\\<rbrace> f \\<lbrace>Q'\\<rbrace>! \\<rbrakk> \\<Longrightarrow>\n      \\<lbrace>\\<lambda>s. P s \\<and> P' s\\<rbrace> f \\<lbrace>\\<lambda>rv s. Q rv s \\<and> Q' rv s\\<rbrace>!\"\n  apply (subst bipred_conj_def[symmetric], rule validNF_post_conj)\n   apply (erule validNF_weaken_pre, fastforce)\n  apply (erule validNF_weaken_pre, fastforce)\n  done\n\nlemma validNF_vcg_disj_lift:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>!; \\<lbrace>P'\\<rbrace> f \\<lbrace>Q'\\<rbrace>! \\<rbrakk> \\<Longrightarrow>\n       \\<lbrace>\\<lambda>s. P s \\<or> P' s\\<rbrace> f \\<lbrace>\\<lambda>rv s. Q rv s \\<or> Q' rv s\\<rbrace>!\"\n  apply (clarsimp simp: validNF_def)\n  apply safe\n   apply (auto intro!: hoare_vcg_disj_lift)[1]\n  apply (clarsimp simp: no_fail_def)\n  done\n\nlemma validNF_vcg_all_lift [wp]:\n  \"\\<lbrakk> \\<And>x. \\<lbrace>P x\\<rbrace> f \\<lbrace>Q x\\<rbrace>! \\<rbrakk> \\<Longrightarrow> \\<lbrace>\\<lambda>s. \\<forall>x. P x s\\<rbrace> f \\<lbrace>\\<lambda>rv s. \\<forall>x. Q x rv s\\<rbrace>!\"\n  apply atomize\n  apply rule\n   apply (clarsimp simp: validNF_def)\n   apply (rule hoare_vcg_all_lift)\n   apply force\n  apply (clarsimp simp: no_fail_def validNF_def)\n  done\n\nlemma validNF_bind [wp_split]:\n  \"\\<lbrakk> \\<And>x. \\<lbrace>B x\\<rbrace> g x \\<lbrace>C\\<rbrace>!; \\<lbrace>A\\<rbrace> f \\<lbrace>B\\<rbrace>! \\<rbrakk> \\<Longrightarrow>\n       \\<lbrace>A\\<rbrace> do x \\<leftarrow> f; g x od \\<lbrace>C\\<rbrace>!\"\n  apply rule\n   apply (metis validNF_valid hoare_seq_ext)\n  apply (clarsimp simp: no_fail_def validNF_def bind_def' valid_def)\n  apply blast\n  done\n\nlemmas validNF_seq_ext = validNF_bind\n\nsubsection \"validNF compound rules\"\n\nlemma validNF_state_assert [wp]:\n  \"\\<lbrace> \\<lambda>s. P () s \\<and> G s  \\<rbrace> state_assert G \\<lbrace> P \\<rbrace>!\"\n  apply rule\n   apply wp\n   apply simp\n  apply (clarsimp simp: no_fail_def state_assert_def\n              bind_def' assert_def return_def get_def)\n  done\n\nlemma validNF_modify [wp]:\n  \"\\<lbrace> \\<lambda>s. P () (f s) \\<rbrace> modify f \\<lbrace> P \\<rbrace>!\"\n  apply (clarsimp simp: modify_def)\n  apply wp\n  done\n\nlemma validNF_gets [wp]:\n  \"\\<lbrace>\\<lambda>s. P (f s) s\\<rbrace> gets f \\<lbrace>P\\<rbrace>!\"\n  apply (clarsimp simp: gets_def)\n  apply wp\n  done\n\nlemma validNF_condition [wp]:\n  \"\\<lbrakk> \\<lbrace> Q \\<rbrace> A \\<lbrace>P\\<rbrace>!; \\<lbrace> R \\<rbrace> B \\<lbrace>P\\<rbrace>!\\<rbrakk> \\<Longrightarrow> \\<lbrace>\\<lambda>s. if C s then Q s else R s\\<rbrace> condition C A B \\<lbrace>P\\<rbrace>!\"\n  apply rule\n   apply (drule validNF_valid)+\n   apply (erule (1) condition_wp)\n  apply (drule validNF_no_fail)+\n  apply (clarsimp simp: no_fail_def condition_def)\n  done\n\nlemma validNF_alt_def:\n  \"validNF P m Q = (\\<forall>s. P s \\<longrightarrow> ((\\<forall>(r', s') \\<in> fst (m s). Q r' s') \\<and> \\<not> snd (m s)))\"\n  by (fastforce simp: validNF_def valid_def no_fail_def)\n\nlemma validNF_assert [wp]:\n    \"\\<lbrace> (\\<lambda>s. P) and (R ()) \\<rbrace> assert P \\<lbrace> R \\<rbrace>!\"\n  apply rule\n   apply (clarsimp simp: valid_def in_return)\n  apply (clarsimp simp: no_fail_def return_def)\n  done\n\nlemma validNF_false_pre:\n  \"\\<lbrace> \\<lambda>_. False \\<rbrace> P \\<lbrace> Q \\<rbrace>!\"\n  apply (clarsimp simp: validNF_def no_fail_def)\n  done\n\nlemma validNF_chain:\n   \"\\<lbrakk>\\<lbrace>P'\\<rbrace> a \\<lbrace>R'\\<rbrace>!; \\<And>s. P s \\<Longrightarrow> P' s; \\<And>r s. R' r s \\<Longrightarrow> R r s\\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> a \\<lbrace>R\\<rbrace>!\"\n  apply (fastforce simp: validNF_def valid_def no_fail_def Ball_def)\n  done\n\nlemma validNF_case_prod [wp]:\n  \"\\<lbrakk> \\<And>x y. validNF (P x y) (B x y) Q \\<rbrakk> \\<Longrightarrow> validNF (case_prod P v) (case_prod (\\<lambda>x y. B x y) v) Q\"\n  by (metis prod.exhaust split_conv)\n\nlemma validE_NF_case_prod [wp]:\n    \"\\<lbrakk> \\<And>a b. \\<lbrace>P a b\\<rbrace> f a b \\<lbrace>Q\\<rbrace>, \\<lbrace>E\\<rbrace>! \\<rbrakk> \\<Longrightarrow>\n          \\<lbrace>case x of (a, b) \\<Rightarrow> P a b\\<rbrace> case x of (a, b) \\<Rightarrow> f a b \\<lbrace>Q\\<rbrace>, \\<lbrace>E\\<rbrace>!\"\n  apply (clarsimp simp: validE_NF_alt_def)\n  apply (erule validNF_case_prod)\n  done\n\nlemma no_fail_is_validNF_True: \"no_fail P s = (\\<lbrace> P \\<rbrace> s \\<lbrace> \\<lambda>_ _. True \\<rbrace>!)\"\n  apply (clarsimp simp: no_fail_def validNF_def valid_def)\n  done\n\nsubsection \"validNF reasoning in the exception monad\"\n\nlemma validE_NF [intro?]:\n  \"\\<lbrakk> \\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>,\\<lbrace> E \\<rbrace>; no_fail P f \\<rbrakk> \\<Longrightarrow> \\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>,\\<lbrace> E \\<rbrace>!\"\n  apply (clarsimp simp: validE_NF_def)\n  done\n\nlemma validE_NF_valid:\n  \"\\<lbrakk> \\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>,\\<lbrace> E \\<rbrace>! \\<rbrakk> \\<Longrightarrow> \\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>,\\<lbrace> E \\<rbrace>\"\n  apply (clarsimp simp: validE_NF_def)\n  done\n\nlemma validE_NF_no_fail:\n  \"\\<lbrakk> \\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>,\\<lbrace> E \\<rbrace>! \\<rbrakk> \\<Longrightarrow> no_fail P f\"\n  apply (clarsimp simp: validE_NF_def)\n  done\n\nlemma validE_NF_weaken_pre [wp_comb]:\n   \"\\<lbrakk>\\<lbrace>Q\\<rbrace> a \\<lbrace>R\\<rbrace>,\\<lbrace>E\\<rbrace>!; \\<And>s. P s \\<Longrightarrow> Q s\\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> a \\<lbrace>R\\<rbrace>,\\<lbrace>E\\<rbrace>!\"\n  apply (clarsimp simp: validE_NF_alt_def)\n  apply (erule validNF_weaken_pre)\n  apply simp\n  done\n\nlemma validE_NF_post_comb_conj_L:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>, \\<lbrace> E \\<rbrace>!; \\<lbrace>P'\\<rbrace> f \\<lbrace>Q'\\<rbrace>, \\<lbrace> \\<lambda>_ _. True \\<rbrace> \\<rbrakk> \\<Longrightarrow> \\<lbrace>\\<lambda>s. P s \\<and> P' s \\<rbrace> f \\<lbrace>\\<lambda>rv s. Q rv s \\<and> Q' rv s\\<rbrace>, \\<lbrace> E \\<rbrace>!\"\n  apply (clarsimp simp: validE_NF_alt_def validE_def validNF_def\n          valid_def no_fail_def split: sum.splits)\n  apply force\n  done\n\nlemma validE_NF_post_comb_conj_R:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>, \\<lbrace> \\<lambda>_ _. True \\<rbrace>; \\<lbrace>P'\\<rbrace> f \\<lbrace>Q'\\<rbrace>, \\<lbrace> E \\<rbrace>! \\<rbrakk> \\<Longrightarrow> \\<lbrace>\\<lambda>s. P s \\<and> P' s \\<rbrace> f \\<lbrace>\\<lambda>rv s. Q rv s \\<and> Q' rv s\\<rbrace>, \\<lbrace> E \\<rbrace>!\"\n  apply (clarsimp simp: validE_NF_alt_def validE_def validNF_def\n          valid_def no_fail_def split: sum.splits)\n  apply force\n  done\n\nlemma validE_NF_post_comb_conj:\n  \"\\<lbrakk> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>, \\<lbrace> E \\<rbrace>!; \\<lbrace>P'\\<rbrace> f \\<lbrace>Q'\\<rbrace>, \\<lbrace> E \\<rbrace>! \\<rbrakk> \\<Longrightarrow> \\<lbrace>\\<lambda>s. P s \\<and> P' s \\<rbrace> f \\<lbrace>\\<lambda>rv s. Q rv s \\<and> Q' rv s\\<rbrace>, \\<lbrace> E \\<rbrace>!\"\n  apply (clarsimp simp: validE_NF_alt_def validE_def validNF_def\n          valid_def no_fail_def split: sum.splits)\n  apply force\n  done\n\nlemma validE_NF_chain:\n   \"\\<lbrakk>\\<lbrace>P'\\<rbrace> a \\<lbrace>R'\\<rbrace>,\\<lbrace>E'\\<rbrace>!;\n    \\<And>s. P s \\<Longrightarrow> P' s;\n    \\<And>r' s'. R' r' s' \\<Longrightarrow> R r' s';\n    \\<And>r'' s''. E' r'' s'' \\<Longrightarrow> E r'' s''\\<rbrakk> \\<Longrightarrow>\n  \\<lbrace>\\<lambda>s. P s \\<rbrace> a \\<lbrace>\\<lambda>r' s'. R r' s'\\<rbrace>,\\<lbrace>\\<lambda>r'' s''. E r'' s''\\<rbrace>!\"\n  apply (fastforce simp: validE_NF_def validE_def2 no_fail_def Ball_def split: sum.splits)\n  done\n\nlemma validE_NF_bind_wp [wp]:\n  \"\\<lbrakk>\\<And>x. \\<lbrace>B x\\<rbrace> g x \\<lbrace>C\\<rbrace>, \\<lbrace>E\\<rbrace>!; \\<lbrace>A\\<rbrace> f \\<lbrace>B\\<rbrace>, \\<lbrace>E\\<rbrace>!\\<rbrakk> \\<Longrightarrow> \\<lbrace>A\\<rbrace> f >>=E (\\<lambda>x. g x) \\<lbrace>C\\<rbrace>, \\<lbrace>E\\<rbrace>!\"\n  apply (unfold validE_NF_alt_def bindE_def)\n  apply (rule validNF_bind [rotated])\n   apply assumption\n  apply (clarsimp simp: lift_def throwError_def split: sum.splits)\n  apply wp\n  apply simp\n  done\n\nlemma validNF_catch [wp]:\n  \"\\<lbrakk>\\<And>x. \\<lbrace>E x\\<rbrace> handler x \\<lbrace>Q\\<rbrace>!; \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>, \\<lbrace>E\\<rbrace>!\\<rbrakk> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f <catch> (\\<lambda>x. handler x) \\<lbrace>Q\\<rbrace>!\"\n  apply (unfold validE_NF_alt_def catch_def)\n  apply (rule validNF_bind [rotated])\n   apply assumption\n  apply (clarsimp simp: lift_def throwError_def split: sum.splits)\n  apply wp\n  done\n\nlemma validNF_throwError [wp]:\n  \"\\<lbrace>E e\\<rbrace> throwError e \\<lbrace>P\\<rbrace>, \\<lbrace>E\\<rbrace>!\"\n  apply (unfold validE_NF_alt_def throwError_def o_def)\n  apply wp\n  apply simp\n  done\n\nlemma validNF_returnOk [wp]:\n  \"\\<lbrace>P e\\<rbrace> returnOk e \\<lbrace>P\\<rbrace>, \\<lbrace>E\\<rbrace>!\"\n  apply (clarsimp simp: validE_NF_alt_def returnOk_def)\n  apply wp\n  apply clarsimp\n  done\n\nlemma validNF_whenE [wp]:\n  \"(P \\<Longrightarrow> \\<lbrace>Q\\<rbrace> f \\<lbrace>R\\<rbrace>, \\<lbrace>E\\<rbrace>!) \\<Longrightarrow> \\<lbrace>if P then Q else R ()\\<rbrace> whenE P f \\<lbrace>R\\<rbrace>, \\<lbrace>E\\<rbrace>!\"\n  unfolding whenE_def\n  apply clarsimp\n  apply wp\n  done\n\nlemma validNF_nobindE [wp]:\n  \"\\<lbrakk> \\<lbrace>B\\<rbrace> g \\<lbrace>C\\<rbrace>,\\<lbrace>E\\<rbrace>!;\n     \\<lbrace>A\\<rbrace> f \\<lbrace>\\<lambda>r s. B s\\<rbrace>,\\<lbrace>E\\<rbrace>! \\<rbrakk> \\<Longrightarrow>\n   \\<lbrace>A\\<rbrace> doE f; g odE \\<lbrace>C\\<rbrace>,\\<lbrace>E\\<rbrace>!\"\n  apply clarsimp\n  apply wp\n  apply auto\n  done\n\n(*\n * Setup triple rules for validE_NF so that we can use the\n * \"wp_comb\" attribute.\n *)\n\ndefinition \"validE_NF_property Q E s b \\<equiv> \\<not> snd (b s)\n       \\<and> (\\<forall>(r', s') \\<in> fst (b s). case r' of Inl x \\<Rightarrow> E x s' | Inr x \\<Rightarrow> Q x s')\"\n\nlemma validE_NF_is_triple [wp_trip]:\n  \"validE_NF P f Q E = triple_judgement P f (validE_NF_property Q E)\"\n  apply (clarsimp simp: validE_NF_def validE_def2 no_fail_def triple_judgement_def\n           validE_NF_property_def split: sum.splits)\n  apply blast\n  done\n\nlemmas [wp_comb] = validE_NF_weaken_pre\n\nlemma validNF_cong:\n   \"\\<lbrakk> \\<And>s. P s = P' s; \\<And>s. P s \\<Longrightarrow> m s = m' s;\n           \\<And>r' s' s. \\<lbrakk> P s; (r', s') \\<in> fst (m s) \\<rbrakk> \\<Longrightarrow> Q r' s' = Q' r' s' \\<rbrakk> \\<Longrightarrow>\n     (\\<lbrace> P \\<rbrace> m \\<lbrace> Q \\<rbrace>!) = (\\<lbrace> P' \\<rbrace> m' \\<lbrace> Q' \\<rbrace>!)\"\n  by (fastforce simp: validNF_alt_def)\n\nlemma validE_NF_liftE [wp]:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>! \\<Longrightarrow> \\<lbrace>P\\<rbrace> liftE f \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>!\"\n  apply (clarsimp simp: validE_NF_alt_def liftE_def)\n  apply wp\n  apply clarsimp\n  done\n\nlemma validE_NF_handleE' [wp]:\n  \"\\<lbrakk> \\<And>x. \\<lbrace>F x\\<rbrace> handler x \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>!; \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>F\\<rbrace>! \\<rbrakk> \\<Longrightarrow>\n   \\<lbrace>P\\<rbrace> f <handle2> (\\<lambda>x. handler x) \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>!\"\n  apply (unfold validE_NF_alt_def handleE'_def)\n  apply (rule validNF_bind [rotated])\n   apply assumption\n  apply (clarsimp split: sum.splits)\n  apply wp\n  apply simp\n  done\n\nlemma validE_NF_handleE [wp]:\n  \"\\<lbrakk> \\<And>x. \\<lbrace>F x\\<rbrace> handler x \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>!; \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,\\<lbrace>F\\<rbrace>! \\<rbrakk> \\<Longrightarrow>\n   \\<lbrace>P\\<rbrace> f <handle> handler \\<lbrace>Q\\<rbrace>,\\<lbrace>E\\<rbrace>!\"\n  apply (unfold handleE_def)\n  apply (metis validE_NF_handleE')\n  done\n\nlemma validE_NF_condition [wp]:\n  \"\\<lbrakk> \\<lbrace> Q \\<rbrace> A \\<lbrace>P\\<rbrace>,\\<lbrace> E \\<rbrace>!; \\<lbrace> R \\<rbrace> B \\<lbrace>P\\<rbrace>,\\<lbrace> E \\<rbrace>!\\<rbrakk>\n      \\<Longrightarrow> \\<lbrace>\\<lambda>s. if C s then Q s else R s\\<rbrace> condition C A B \\<lbrace>P\\<rbrace>,\\<lbrace> E \\<rbrace>!\"\n  apply rule\n   apply (drule validE_NF_valid)+\n   apply (wp, simp, simp)\n  apply (drule validE_NF_no_fail)+\n  apply (clarsimp simp: no_fail_def condition_def)\n  done\n\nend\n", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/lib/wp/NonDetMonadVCG.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5156199157230156, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.26183791066279083}}
{"text": "header {* Code Generation for the Skeleton Algorithm \\label{sec:skel_code}*}\ntheory Gabow_Skeleton_Code\nimports \n  Gabow_Skeleton\n  \"../CAVA_Automata/Digraph_Impl\"\n  \"../CAVA_Automata/CAVA_Base/CAVA_Code_Target\"\nbegin\n\nsection {* Statistics *}\ntext {*\n  In this section, we do the ML setup that gathers statistics about the \n  algorithm's execution.\n*}\n\ncode_printing\n  code_module Gabow_Skeleton_Statistics \\<rightharpoonup> (SML) {*\n    structure Gabow_Skeleton_Statistics = struct\n      val active = Unsynchronized.ref false\n      val num_vis = Unsynchronized.ref 0\n\n      val time = Unsynchronized.ref Time.zeroTime\n\n      fun is_active () = !active\n      fun newnode () = num_vis := !num_vis + 1\n\n      fun start () = (active := true; time := Time.now ())\n      fun stop () = (time := Time.- (Time.now (), !time))\n\n      fun to_string () = let\n        val t = Time.toMilliseconds (!time)\n        val states_per_ms = real (!num_vis) / real t\n        val realStr = Real.fmt (StringCvt.FIX (SOME 2))\n      in\n        \"Required time: \" ^ IntInf.toString (t) ^ \"ms\\n\"\n      ^ \"States per ms: \" ^ realStr states_per_ms ^ \"\\n\"\n      ^ \"# states: \" ^ IntInf.toString (!num_vis) ^ \"\\n\"\n      end\n        \n      val _ = Statistics.register_stat (\"Gabow-Skeleton\",is_active,to_string)\n\n    end\n*}\ncode_reserved SML Gabow_Skeleton_Statistics\n\ncode_printing\n  constant stat_newnode \\<rightharpoonup> (SML) \"Gabow'_Skeleton'_Statistics.newnode\"\n| constant stat_start \\<rightharpoonup> (SML) \"Gabow'_Skeleton'_Statistics.start\"\n| constant stat_stop \\<rightharpoonup> (SML) \"Gabow'_Skeleton'_Statistics.stop\"\n\nsection {* Automatic Refinement Setup *}\nconsts i_node_state :: interface\n\ndefinition \"node_state_rel \\<equiv> {(-1::int,DONE)} \\<union> {(int k,STACK k) | k. True }\"\nlemma node_state_rel_simps[simp]:\n  \"(i,DONE)\\<in>node_state_rel \\<longleftrightarrow> i=-1\"\n  \"(i,STACK n)\\<in>node_state_rel \\<longleftrightarrow> i = int n\"\n  unfolding node_state_rel_def\n  by auto\n\nlemma node_state_rel_sv[simp,intro!,relator_props]:\n  \"single_valued node_state_rel\"\n  unfolding node_state_rel_def\n  by (auto intro: single_valuedI)\n\nlemmas [autoref_rel_intf] = REL_INTFI[of node_state_rel i_node_state]\n\nprimrec is_DONE where\n  \"is_DONE DONE = True\"\n| \"is_DONE (STACK _) = False\"\n\nlemma node_state_rel_refine[autoref_rules]:\n  \"(-1,DONE)\\<in>node_state_rel\"\n  \"(int,STACK)\\<in>nat_rel\\<rightarrow>node_state_rel\"\n  \"(\\<lambda>i. i<0,is_DONE)\\<in>node_state_rel\\<rightarrow>bool_rel\"\n  \"((\\<lambda>f g i. if i\\<ge>0 then f (nat i) else g),case_node_state)\n    \\<in>(nat_rel \\<rightarrow> R) \\<rightarrow> R \\<rightarrow> node_state_rel \\<rightarrow> R\"\n  unfolding node_state_rel_def \n    apply auto [3]\n    apply (fastforce dest: fun_relD)\n    done\n\n\n\n(* TODO: Make changing the Autoref-config simpler, by concentrating\n    everything here *)\nconsts i_node :: interface\n\n(* TODO: Move generic part of this locale to Digraph_impl *)\nlocale fr_graph_impl_loc = fr_graph G\n  for mrel and G_impl and G :: \"('v::hashable,'more) fr_graph_rec_scheme\"\n  +\n  assumes G_refine: \"(G_impl,G)\\<in>\\<langle>mrel,Id\\<rangle>frg_impl_rel_ext\"\nbegin\n  abbreviation \"node_rel \\<equiv> Id :: ('v \\<times> _) set\"\n  lemmas [autoref_rel_intf] = REL_INTFI[of node_rel i_node]\n\n  lemmas [autoref_rules] = G_refine\n\n  lemma locale_this: \"fr_graph_impl_loc mrel G_impl G\"\n    by unfold_locales\n\n  abbreviation \"oGSi_rel \\<equiv> \\<langle>node_rel,node_state_rel\\<rangle>dflt_ahm_rel\"\n\n  abbreviation \"GSi_rel \\<equiv> \n    \\<langle>node_rel\\<rangle>as_rel \n    \\<times>\\<^sub>r \\<langle>nat_rel\\<rangle>as_rel \n    \\<times>\\<^sub>r \\<langle>node_rel,node_state_rel\\<rangle>dflt_ahm_rel\n    \\<times>\\<^sub>r \\<langle>nat_rel \\<times>\\<^sub>r \\<langle>node_rel\\<rangle>list_set_rel\\<rangle>as_rel\"\n\n  lemmas [autoref_op_pat] = GS.S_def GS.B_def GS.I_def GS.P_def\n\nend\n\nsection {* Generating the Code *}\n\ncontext fr_graph_impl_loc\nbegin\n  schematic_lemma push_code_aux: \"(?c,push_impl)\\<in>node_rel \\<rightarrow> GSi_rel \\<rightarrow> GSi_rel\"\n    unfolding push_impl_def_opt[abs_def]\n    using [[autoref_trace_failed_id]]\n    apply (autoref (keep_goal))\n    done\n  concrete_definition (in -) push_code uses fr_graph_impl_loc.push_code_aux\n  lemmas [autoref_rules] = push_code.refine[OF locale_this]\n  \n  schematic_lemma pop_code_aux: \"(?c,pop_impl)\\<in>GSi_rel \\<rightarrow> \\<langle>GSi_rel\\<rangle>nres_rel\"\n    unfolding pop_impl_def_opt[abs_def]\n    unfolding GS.mark_as_done_def\n    using [[autoref_trace_failed_id]]\n    apply (autoref (keep_goal))\n    done\n  concrete_definition (in -) pop_code uses fr_graph_impl_loc.pop_code_aux\n  lemmas [autoref_rules] = pop_code.refine[OF locale_this]\n\n  schematic_lemma S_idx_of_code_aux: \n    notes [autoref_rules] = IdI[of \"undefined::nat\"] (* TODO: hack!*)\n    shows \"(?c,GS.S_idx_of)\\<in>GSi_rel \\<rightarrow> node_rel \\<rightarrow> nat_rel\"\n    unfolding GS.S_idx_of_def[abs_def]\n    using [[autoref_trace_failed_id]]\n    apply (autoref (keep_goal))\n    done\n  concrete_definition (in -) S_idx_of_code \n    uses fr_graph_impl_loc.S_idx_of_code_aux\n  lemmas [autoref_rules] = S_idx_of_code.refine[OF locale_this] \n\n  schematic_lemma idx_of_code_aux:\n    notes [autoref_rules] = IdI[of \"undefined::nat\"] (* TODO: hack!*)\n    shows \"(?c,GS.idx_of_impl)\\<in> GSi_rel \\<rightarrow> node_rel \\<rightarrow> \\<langle>nat_rel\\<rangle>nres_rel\"\n    unfolding \n      GS.idx_of_impl_def[abs_def, unfolded GS.find_seg_impl_def GS.S_idx_of_def,\n        THEN opt_GSdef, unfolded GS_sel_simps, abs_def]\n    using [[autoref_trace_failed_id]]\n    apply (autoref (keep_goal))\n    done\n  concrete_definition (in -) idx_of_code uses fr_graph_impl_loc.idx_of_code_aux\n  lemmas [autoref_rules] = idx_of_code.refine[OF locale_this] \n\n  schematic_lemma collapse_code_aux: \n    \"(?c,collapse_impl)\\<in>node_rel \\<rightarrow> GSi_rel \\<rightarrow> \\<langle>GSi_rel\\<rangle>nres_rel\"\n    unfolding collapse_impl_def_opt[abs_def] \n    using [[autoref_trace_failed_id]]\n    apply (autoref (keep_goal))\n    done\n  concrete_definition (in -) collapse_code \n    uses fr_graph_impl_loc.collapse_code_aux\n  lemmas [autoref_rules] = collapse_code.refine[OF locale_this] \n\n  term select_edge_impl\n  schematic_lemma select_edge_code_aux:\n    \"(?c,select_edge_impl) \n      \\<in> GSi_rel \\<rightarrow> \\<langle>\\<langle>node_rel\\<rangle>option_rel \\<times>\\<^sub>r GSi_rel\\<rangle>nres_rel\"\n    unfolding select_edge_impl_def_opt[abs_def] \n\n    using [[autoref_trace_failed_id]]\n    using [[goals_limit=1]]\n    apply (autoref (keep_goal,trace))\n    done\n  concrete_definition (in -) select_edge_code \n    uses fr_graph_impl_loc.select_edge_code_aux\n  lemmas [autoref_rules] = select_edge_code.refine[OF locale_this] \n\n  context begin interpretation autoref_syn .\n\n    term fr_graph.pop_impl\n    lemma [autoref_op_pat]: \n      \"push_impl \\<equiv> OP push_impl\"\n      \"collapse_impl \\<equiv> OP collapse_impl\"\n      \"select_edge_impl \\<equiv> OP select_edge_impl\"\n      \"pop_impl \\<equiv> OP pop_impl\"\n      by simp_all\n  \n  end\n\n  schematic_lemma skeleton_code_aux:\n    \"(?c,skeleton_impl) \\<in> \\<langle>oGSi_rel\\<rangle>nres_rel\"\n    unfolding skeleton_impl_def[abs_def] initial_impl_def GS_initial_impl_def\n    unfolding path_is_empty_impl_def is_on_stack_impl_def is_done_impl_def \n      is_done_oimpl_def\n    unfolding GS.is_on_stack_impl_def GS.is_done_impl_def\n    using [[autoref_trace_failed_id]]\n\n    apply (autoref (keep_goal,trace))\n    done\n  concrete_definition (in -) skeleton_code \n    uses fr_graph_impl_loc.skeleton_code_aux\n  lemmas [autoref_rules] = skeleton_code.refine[OF locale_this] \n  \n\n  schematic_lemma pop_tr_aux: \"RETURN ?c \\<le> pop_code s\"\n    unfolding pop_code_def by refine_transfer\n  concrete_definition (in -) pop_tr uses fr_graph_impl_loc.pop_tr_aux\n  lemmas [refine_transfer] = pop_tr.refine[OF locale_this]\n\n  schematic_lemma select_edge_tr_aux: \"RETURN ?c \\<le> select_edge_code s\"\n    unfolding select_edge_code_def by refine_transfer\n  concrete_definition (in -) select_edge_tr \n    uses fr_graph_impl_loc.select_edge_tr_aux\n  lemmas [refine_transfer] = select_edge_tr.refine[OF locale_this]\n\n  schematic_lemma idx_of_tr_aux: \"RETURN ?c \\<le> idx_of_code v s\"\n    unfolding idx_of_code_def by refine_transfer\n  concrete_definition (in -) idx_of_tr uses fr_graph_impl_loc.idx_of_tr_aux\n  lemmas [refine_transfer] = idx_of_tr.refine[OF locale_this]\n\n  schematic_lemma collapse_tr_aux: \"RETURN ?c \\<le> collapse_code v s\"\n    unfolding collapse_code_def by refine_transfer\n  concrete_definition (in -) collapse_tr uses fr_graph_impl_loc.collapse_tr_aux\n  lemmas [refine_transfer] = collapse_tr.refine[OF locale_this]\n\n  schematic_lemma skeleton_tr_aux: \"RETURN ?c \\<le> skeleton_code g\"\n    unfolding skeleton_code_def by refine_transfer\n  concrete_definition (in -) skeleton_tr uses fr_graph_impl_loc.skeleton_tr_aux\n  lemmas [refine_transfer] = skeleton_tr.refine[OF locale_this]\n\nend\n\nterm skeleton_tr\n\nexport_code skeleton_tr checking SML\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Gabow_SCC/Gabow_Skeleton_Code.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5078118642792043, "lm_q2_score": 0.5156199157230157, "lm_q1q2_score": 0.26183791066279083}}
{"text": "(* \n   Title: Psi-calculi   \n   Author/Maintainer: Jesper Bengtson (jebe@itu.dk), 2012\n*)\ntheory Tau_Laws_Weak\n  imports Weaken_Bisimulation Weak_Congruence Tau_Sim Tau_Stat_Imp\nbegin\n\ncontext weakTauLaws begin\n\nlemma tauLaw1:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  \n  shows \"\\<Psi> \\<rhd> \\<tau>.(P) \\<approx> P\"\nproof - \n  let ?X = \"{(\\<Psi>, \\<tau>.(P), P) | \\<Psi> P. True}\" let ?Y = \"{(\\<Psi>, P, \\<tau>.(P)) | \\<Psi> P. True}\"\n  have \"(\\<Psi>, \\<tau>.(P), P) \\<in> ?X \\<union> ?Y\" by auto\n  moreover have \"eqvt(?X \\<union> ?Y)\" by(auto simp add: eqvt_def simp add: eqvts)\n  ultimately have \"\\<Psi> \\<rhd> \\<tau>.(P) \\<approx>\\<^sub>w P\"\n  proof(coinduct rule: weakenTransitiveCoinduct)\n    case(cStatImp \\<Psi> P Q)\n    show ?case\n    proof(cases \"(\\<Psi>, P, Q) \\<in> ?X\")\n      case True\n      {\n        fix \\<Psi> P\n        have \"\\<Psi> \\<rhd> P \\<lessapprox>\\<^sub>w<(?X \\<union> ?Y \\<union> weakBisim)> P\" by(auto simp add: weakenStatImp_def intro: weakBisimReflexive)\n        moreover have \"(\\<Psi>, \\<tau>.(P), P) \\<in> ?X \\<union> ?Y \\<union> weakBisim\" by auto\n        ultimately have \"\\<Psi> \\<rhd> \\<tau>.(P) \\<lessapprox>\\<^sub>w<(?X \\<union> ?Y \\<union> weakBisim)> P\"\n          by(rule tauLaw1StatImpLeft)\n      }\n      with \\<open>(\\<Psi>, P, Q) \\<in> ?X\\<close> show ?thesis by auto \n    next\n      case False\n      from \\<open>(\\<Psi>, P, Q) \\<notin> ?X\\<close> \\<open>(\\<Psi>, P, Q) \\<in> ?X \\<union> ?Y\\<close> have \"(\\<Psi>, P, Q) \\<in> ?Y\" by auto\n      {\n        fix \\<Psi> P\n        have \"\\<Psi> \\<rhd> P \\<lessapprox><weakBisim> P\" using weakBisimReflexive\n          by(rule weakBisimE)\n        moreover have \"\\<And>\\<Psi> P Q R. \\<lbrakk>\\<Psi> \\<rhd> P \\<approx> Q; \\<Psi> \\<rhd> Q \\<sim> R\\<rbrakk> \\<Longrightarrow> (\\<Psi>, P, R) \\<in> ?X \\<union> ?Y \\<union> weakBisim\"\n          by(fastforce intro: weakBisimTransitive strongBisimWeakBisim)\n        ultimately have  \"\\<Psi> \\<rhd> P \\<lessapprox><( ?X \\<union> ?Y \\<union> weakBisim)> \\<tau>.(P)\" by(rule tauLaw1StatImpRight)\n        moreover have \"\\<And>\\<Psi> P Q \\<Psi>'. \\<lbrakk>(\\<Psi>, P, Q) \\<in> ?X \\<union> ?Y \\<union> weakBisim; \\<Psi> \\<simeq> \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', P, Q) \\<in> ?X \\<union> ?Y \\<union> weakBisim\"\n          by(auto dest: statEqWeakBisim)\n        ultimately have \"\\<Psi> \\<rhd> P \\<lessapprox>\\<^sub>w<( ?X \\<union> ?Y \\<union> weakBisim)> \\<tau>.(P)\" by(rule weakStatImpWeakenStatImp)\n      }\n      with \\<open>(\\<Psi>, P, Q) \\<in> ?Y\\<close> show ?thesis by auto\n    qed\n  next\n    case(cSim \\<Psi> P Q)\n    let ?Z = \"{(\\<Psi>, P, Q) | \\<Psi> P Q. \\<exists>P' Q'. \\<Psi> \\<rhd> P \\<sim> P' \\<and> (\\<Psi>, P', Q') \\<in> ?X \\<union> ?Y \\<union> weakenBisim \\<and> \\<Psi> \\<rhd> Q' \\<sim> Q}\"\n    have \"eqvt ?Z\" \n      apply auto\n      apply(auto simp add: eqvt_def eqvts)\n      apply(rule_tac x=\"(p \\<bullet> (\\<tau>.(Q')))\" in exI)\n      apply(auto intro: bisimClosed)\n      apply(simp add: eqvts)\n      apply(blast intro: bisimClosed weakBisimClosed)\n      apply(rule_tac x=\"(p \\<bullet> P')\" in exI)\n      apply(auto intro: bisimClosed)\n      apply(rule_tac x=\"\\<tau>.(p \\<bullet> P')\" in exI)\n      apply auto\n      apply(drule_tac p=p and Q=b in bisimClosed)\n      apply(simp add: eqvts)\n      apply(rule_tac x=\"(p \\<bullet> P')\" in exI)\n      apply(auto intro: bisimClosed)\n      apply(rule_tac x=\"p \\<bullet> Q'\" in exI)\n      apply auto\n      by(blast intro: bisimClosed dest: weakBisimClosed)+\n    show ?case\n    proof(cases \"(\\<Psi>, P, Q) \\<in> ?X\")\n      case True\n      {\n        fix P\n        have \"\\<Psi> \\<rhd> P \\<leadsto><?Z> P\" using weakenBisimEqWeakBisim by(blast intro: weakSimReflexive weakBisimReflexive bisimReflexive)\n        moreover note \\<open>eqvt ?Z\\<close>\n        moreover have \"\\<And>\\<Psi> P Q R. \\<lbrakk>\\<Psi> \\<rhd> P \\<sim> Q; (\\<Psi>, Q, R) \\<in> ?Z\\<rbrakk> \\<Longrightarrow> (\\<Psi>, P, R) \\<in> ?Z\"\n          by(blast intro: bisimTransitive)\n        ultimately have \"\\<Psi> \\<rhd> \\<tau>.(P) \\<leadsto><?Z> P\"\n          by(rule tauLaw1SimLeft)\n        moreover have \"\\<And>\\<Psi> P Q \\<Psi>'. \\<lbrakk>(\\<Psi>, P, Q) \\<in> ?Z; \\<Psi> \\<simeq> \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', P, Q) \\<in> ?Z\"\n          by simp (blast intro: statEqWeakBisim statEqBisim)\n        ultimately have \"\\<Psi> \\<rhd> \\<tau>.(P) \\<leadsto>\\<^sub>w<?Z> P\" by(rule weakSimWeakenSim)\n      }\n      with \\<open>(\\<Psi>, P, Q) \\<in> ?X\\<close> show ?thesis by auto\n    next\n      case False\n      from \\<open>(\\<Psi>, P, Q) \\<notin> ?X\\<close> \\<open>(\\<Psi>, P, Q) \\<in> ?X \\<union> ?Y\\<close> have \"(\\<Psi>, P, Q) \\<in> ?Y\" by auto\n      moreover {\n        fix P\n        note \\<open>eqvt ?Z\\<close>  \n        moreover have \"(\\<Psi>, P, P) \\<in> ?Z\" by simp (blast intro: weakBisimReflexive bisimReflexive)\n        moreover have \"\\<And>\\<Psi> P Q R. \\<lbrakk>(\\<Psi>, P, Q) \\<in> ?Z; \\<Psi> \\<rhd> Q \\<sim> R\\<rbrakk> \\<Longrightarrow> (\\<Psi>, P, R) \\<in> ?Z\"\n          by(blast intro: bisimTransitive)\n        ultimately have \"\\<Psi> \\<rhd> P \\<leadsto><?Z> \\<tau>.(P)\" by(rule tauLaw1SimRight)\n        moreover have \"\\<And>\\<Psi> P Q \\<Psi>'. \\<lbrakk>(\\<Psi>, P, Q) \\<in> ?Z; \\<Psi> \\<simeq> \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', P, Q) \\<in> ?Z\"\n          by simp (blast intro: statEqWeakBisim statEqBisim)\n        ultimately have \"\\<Psi> \\<rhd> P \\<leadsto>\\<^sub>w<?Z> \\<tau>.(P)\" by(rule weakSimWeakenSim)\n      }\n      ultimately show ?thesis by auto\n    qed\n  next\n    case(cExt \\<Psi> P Q \\<Psi>')\n    thus ?case by auto\n  next\n    case(cSym \\<Psi> P Q)\n    thus ?case by auto\n  qed\n  thus ?thesis by simp\nqed\n\nlemma tauLaw3:\n  fixes \\<Psi> :: 'b\n  and   \\<alpha> :: \"'a prefix\"\n  and   P :: \"('a, 'b, 'c) psi\"\n\n  shows \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(P)) \\<approx> \\<alpha>\\<cdot>P\"\nproof -\n  let ?X = \"({(\\<Psi>, \\<alpha>\\<cdot>(\\<tau>.(P)), \\<alpha>\\<cdot>P) | \\<Psi> \\<alpha> P. True})\"\n  let ?Y = \"({(\\<Psi>, \\<alpha>\\<cdot>P, \\<alpha>\\<cdot>(\\<tau>.(P))) | \\<Psi> \\<alpha> P. True})\"\n\n  have \"(\\<Psi>, \\<alpha>\\<cdot>(\\<tau>.(P)), \\<alpha>\\<cdot>P) \\<in> ?X \\<union> ?Y\" by blast\n  moreover have \"eqvt(?X \\<union> ?Y)\" by(fastforce simp add: eqvt_def simp add: eqvts)\n  ultimately have \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(P)) \\<approx>\\<^sub>w \\<alpha>\\<cdot>P\"\n  proof(coinduct rule: weakenTransitiveCoinduct)\n    case(cStatImp \\<Psi> P Q)\n    show ?case\n    proof(cases \"(\\<Psi>, P, Q) \\<in> ?X\")\n      case True\n      {\n        fix \\<Psi> \\<alpha> P\n        have \"\\<And>\\<Psi>'. (\\<Psi> \\<otimes> \\<Psi>', \\<alpha>\\<cdot>(\\<tau>.(P)), \\<alpha>\\<cdot>P) \\<in> ?X \\<union> ?Y \\<union> weakenBisim\" by auto\n        hence \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(P)) \\<lessapprox><(?X \\<union> ?Y \\<union> weakenBisim)> \\<alpha>\\<cdot>P\" by(rule tauLaw3StatImpLeft)\n        moreover have \"\\<And>\\<Psi> P Q \\<Psi>'. \\<lbrakk>(\\<Psi>, P, Q) \\<in> ?X \\<union> ?Y \\<union> weakenBisim; \\<Psi> \\<simeq> \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', P, Q) \\<in> ?X \\<union> ?Y \\<union> weakenBisim\"\n          by(fastforce intro: statEqWeakBisim)\n        ultimately have \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(P)) \\<lessapprox>\\<^sub>w<(?X \\<union> ?Y \\<union> weakenBisim)> \\<alpha>\\<cdot>P\" by(rule weakStatImpWeakenStatImp)\n      }\n      with \\<open>(\\<Psi>, P, Q) \\<in> ?X\\<close> show ?thesis by blast\n    next\n      case False\n      {\n        fix \\<Psi> \\<alpha> P\n        have \"\\<And>\\<Psi>'. (\\<Psi> \\<otimes> \\<Psi>', \\<alpha>\\<cdot>P, \\<alpha>\\<cdot>(\\<tau>.(P))) \\<in> ?X \\<union> ?Y \\<union> weakenBisim\" by auto\n        hence \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<lessapprox><(?X \\<union> ?Y \\<union> weakenBisim)> \\<alpha>\\<cdot>(\\<tau>.(P))\" by(rule tauLaw3StatImpRight)\n        moreover have \"\\<And>\\<Psi> P Q \\<Psi>'. \\<lbrakk>(\\<Psi>, P, Q) \\<in> ?X \\<union> ?Y \\<union> weakenBisim; \\<Psi> \\<simeq> \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', P, Q) \\<in> ?X \\<union> ?Y \\<union> weakenBisim\"\n          by(fastforce intro: statEqWeakBisim)\n        ultimately have \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<lessapprox>\\<^sub>w<(?X \\<union> ?Y \\<union> weakenBisim)> \\<alpha>\\<cdot>(\\<tau>.(P))\" by(rule weakStatImpWeakenStatImp)\n      }\n      moreover from \\<open>(\\<Psi>, P, Q) \\<notin> ?X\\<close> \\<open>(\\<Psi>, P, Q) \\<in> ?X \\<union> ?Y\\<close> have \"(\\<Psi>, P, Q) \\<in> ?Y\" by blast\n      ultimately show ?thesis by auto\n    qed\n  next\n    case(cSim \\<Psi> P Q)\n    let ?Z = \"{(\\<Psi>, P, Q) | \\<Psi> P Q. \\<exists>P' Q'. \\<Psi> \\<rhd> P \\<sim> P' \\<and> (\\<Psi>, P', Q') \\<in> ?X \\<union> ?Y \\<union> weakenBisim \\<and> \\<Psi> \\<rhd> Q' \\<sim> Q}\"\n    have \"eqvt ?Z\" \n      apply(clarsimp simp add: eqvt_def)\n      apply(elim disjE)\n      apply(rule_tac x=\"p \\<bullet> P'\" in exI)\n      apply(clarsimp simp add: bisimClosed eqvts)\n      apply(blast intro: bisimClosed eqvts)\n      apply(rule_tac x=\"p \\<bullet> P'\" in exI)\n      apply(clarsimp simp add: bisimClosed eqvts)\n      apply(rule_tac x=\"p \\<bullet> (\\<alpha>\\<cdot>(\\<tau>.(P)))\" in exI)\n      apply(clarsimp simp add: eqvts)\n      apply(rule conjI)\n      apply(rule disjI2)\n      apply(blast intro: bisimClosed eqvts)\n      apply(drule_tac p=p in bisimClosed)\n      apply(drule_tac p=p in bisimClosed)\n      apply(simp add: eqvts)\n      by(blast dest: bisimClosed weakBisimClosed)\n    show ?case\n    proof(cases \"(\\<Psi>, P, Q) \\<in> ?X\")\n      case True\n      note \\<open>(\\<Psi>, P, Q) \\<in> ?X\\<close>\n      moreover {\n        fix \\<Psi> P \\<alpha>\n        note \\<open>eqvt ?Z\\<close>\n        moreover have \"(\\<Psi>, P, P) \\<in> ?Z\" using weakenBisimEqWeakBisim by(blast intro: weakBisimReflexive bisimReflexive)\n        moreover have \"\\<And>xvec Tvec. length xvec = length Tvec \\<Longrightarrow> (\\<Psi>, P[xvec::=Tvec], P[xvec::=Tvec]) \\<in> ?Z\"\n           using weakenBisimEqWeakBisim by(blast intro: weakBisimReflexive bisimReflexive)\n        moreover have \"\\<And>\\<Psi> P Q R S. \\<lbrakk>\\<Psi> \\<rhd> P \\<sim> Q; (\\<Psi>, Q, R) \\<in> ?Z; \\<Psi> \\<rhd> R \\<sim> S\\<rbrakk> \\<Longrightarrow> (\\<Psi>, P, S) \\<in> ?Z\" by(blast intro: bisimTransitive)\n        moreover have \"\\<And>\\<Psi> P Q \\<Psi>'. (\\<Psi>, P, Q) \\<in> ?Z \\<Longrightarrow> (\\<Psi> \\<otimes> \\<Psi>', P, Q) \\<in> ?Z\" by(blast dest: weakenBisimE(3) bisimE(3))\n        ultimately have \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(P)) \\<leadsto><?Z> \\<alpha>\\<cdot>P\" by(rule tauLaw3SimLeft)\n        moreover have \"\\<And>\\<Psi> P Q \\<Psi>'. \\<lbrakk>(\\<Psi>, P, Q) \\<in> ?Z; \\<Psi> \\<simeq> \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', P, Q) \\<in> ?Z\" by simp (blast dest: statEqWeakBisim statEqBisim)\n        ultimately have \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(P)) \\<leadsto>\\<^sub>w<?Z> \\<alpha>\\<cdot>P\" by(rule weakSimWeakenSim)\n      }\n      ultimately show ?thesis by auto\n    next\n      case False\n      from \\<open>(\\<Psi>, P, Q) \\<notin> ?X\\<close> \\<open>(\\<Psi>, P, Q) \\<in> ?X \\<union> ?Y\\<close> have \"(\\<Psi>, P, Q) \\<in> ?Y\" by blast\n      moreover {\n        fix \\<Psi> P \\<alpha>\n        note \\<open>eqvt ?Z\\<close>\n        moreover have \"\\<And>\\<Psi> xvec Tvec. length xvec=length Tvec \\<Longrightarrow> (\\<Psi>, P[xvec::=Tvec], \\<tau>.(P[xvec::=Tvec])) \\<in> ?Z\"\n          by simp (blast intro: weakBisimE(4) bisimReflexive tauLaw1)\n        moreover have \"\\<And>\\<Psi> P Q R S. \\<lbrakk>\\<Psi> \\<rhd> P \\<sim> Q; (\\<Psi>, Q, R) \\<in> ?Z; \\<Psi> \\<rhd> R \\<sim> S\\<rbrakk> \\<Longrightarrow> (\\<Psi>, P, S) \\<in> ?Z\" by(blast intro: bisimTransitive)\n        moreover have \"\\<And>\\<Psi>. (\\<Psi>, P, \\<tau>.(P)) \\<in> ?Z\" by simp (blast intro: weakBisimE(4) bisimReflexive tauLaw1)\n        ultimately have \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<leadsto><?Z> \\<alpha>\\<cdot>(\\<tau>.(P))\" by(rule tauLaw3SimRight)\n        moreover have \"\\<And>\\<Psi> P Q \\<Psi>'. \\<lbrakk>(\\<Psi>, P, Q) \\<in> ?Z; \\<Psi> \\<simeq> \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', P, Q) \\<in> ?Z\" by simp (blast dest: statEqWeakBisim statEqBisim)\n        ultimately have \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>P \\<leadsto>\\<^sub>w<?Z> \\<alpha>\\<cdot>(\\<tau>.(P))\" by(rule weakSimWeakenSim)\n      }\n      ultimately show ?thesis by auto\n    qed\n  next\n    case(cExt \\<Psi> P Q \\<Psi>')\n    thus ?case by auto\n  next\n    case(cSym \\<Psi> P Q)\n    thus ?case by blast \n  qed\n  thus ?thesis by simp\nqed\n  \nlemma tauLaw3PsiCong:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n\n  shows \"\\<Psi> \\<rhd> \\<alpha>\\<cdot>(\\<tau>.(P)) \\<doteq> \\<alpha>\\<cdot>P\"\nproof(induct rule: weakPsiCongI)\n  case cWeakBisim\n  show ?case by(rule tauLaw3)\nnext\n  case cSimLeft\n  have \"\\<Psi> \\<rhd> P \\<approx> P\" by(rule weakBisimReflexive)\n  moreover have \"\\<And>\\<Psi> P Q R S. \\<lbrakk>\\<Psi> \\<rhd> P \\<sim> Q; \\<Psi> \\<rhd> Q \\<approx> R; \\<Psi> \\<rhd> R \\<sim> S\\<rbrakk> \\<Longrightarrow> \\<Psi> \\<rhd> P \\<approx> S\"\n    by(blast intro: weakBisimTransitive strongBisimWeakBisim)\n  ultimately show ?case using weakBisimE(3) by(rule tauLaw3CongSimLeft)\nnext\n  case cSimRight\n  have \"\\<Psi> \\<rhd>  P \\<approx> P\" by(rule weakBisimReflexive)\n  moreover have \"\\<And>\\<Psi> P Q R S. \\<lbrakk>\\<Psi> \\<rhd> P \\<sim> Q; \\<Psi> \\<rhd> Q \\<approx> R; \\<Psi> \\<rhd> R \\<sim> S\\<rbrakk> \\<Longrightarrow> \\<Psi> \\<rhd> P \\<approx> S\"\n    by(blast intro: weakBisimTransitive strongBisimWeakBisim)\n  ultimately show ?case using tauLaw1[THEN weakBisimE(4)]\n    by(rule tauLaw3CongSimRight)\nqed\n  \nlemma tauLaw3Cong:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n\n  shows \"\\<alpha>\\<cdot>(\\<tau>.(P)) \\<doteq>\\<^sub>c \\<alpha>\\<cdot>P\"\nproof(induct rule: weakCongI)\n  case(cWeakPsiCong \\<Psi> \\<sigma>)\n  show ?case\n  proof(nominal_induct \\<alpha> rule: prefix.strong_inducts)\n  next\n    case(pInput M yvec N)\n    obtain p where \"set p \\<subseteq> set yvec \\<times> set(p \\<bullet> yvec)\" and \"(p \\<bullet> yvec) \\<sharp>* N\" and \"(p \\<bullet> yvec) \\<sharp>* P\" and \"(p \\<bullet> yvec) \\<sharp>* \\<sigma>\"\n      by(rule_tac xvec=yvec and c=\"(N, P, \\<sigma>)\" in name_list_avoiding) auto\n    thus ?case using \\<open>wellFormedSubst \\<sigma>\\<close> tauLaw3PsiCong[where \\<alpha>=\"pInput (substTerm.seqSubst M \\<sigma>) (p \\<bullet> yvec) (substTerm.seqSubst (p \\<bullet> N) \\<sigma>)\"]\n      by(simp add: inputChainAlpha' eqvts)\n  next\n    case(pOutput M N)\n    thus ?case using  \\<open>wellFormedSubst \\<sigma>\\<close> tauLaw3PsiCong[where \\<alpha>=\"pOutput (substTerm.seqSubst M \\<sigma>) (substTerm.seqSubst N \\<sigma>)\"]\n      by simp\n  next\n    case pTau\n    thus ?case using  \\<open>wellFormedSubst \\<sigma>\\<close> tauLaw3PsiCong[where \\<alpha>=\"pTau\"]\n      by simp\n  qed\nqed\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Psi_Calculi/Tau_Laws_Weak.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.2617899998530847}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the GNU General Public License version 2. Note that NO WARRANTY is provided.\n * See \"LICENSE_GPLv2.txt\" for details.\n *\n * @TAG(NICTA_GPL)\n *)\n\ntheory Sep_Tactic_Examples\nimports\n  \"../sep-capDL/Sep_Tactic_Helper\"\n  KHeap_DP\nbegin\n\n\n(* Thesis : Automated Tactics for Seperation Logic *)\n\n(* seperation logic *)\n\n(* after we show that addition and disjointedness on our heap obeys certain laws, we get a seperation algebra *)\n\n(* connectives *)\n\nterm \"P \\<and>* Q\"\n\nterm \"P \\<longrightarrow>* Q\"\n\nlemma frame_rule:\n  \"\\<And>R. \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>_. Q\\<rbrace> \\<Longrightarrow> \\<lbrace>P \\<and>* R\\<rbrace> f \\<lbrace>\\<lambda>_. Q \\<and>* R\\<rbrace>\"\n  oops\n\nthm swap_cap_wp[no_vars]\n\nlemma\n \"\\<lbrace><dest \\<mapsto>c - \\<and>* src \\<mapsto>c cap \\<and>* R>\\<rbrace>\n    move_cap cap' src dest\n  \\<lbrace>\\<lambda>_. <dest \\<mapsto>c cap'  \\<and>* src \\<mapsto>c NullCap \\<and>* R>\\<rbrace>\"\n  apply (simp add: move_cap_def)\n  apply (wp swap_parents_wp set_cap_wp) (* set_cap doesn't apply *)\nthm set_cap_wp[no_vars]\n   apply (rule hoare_strengthen_post)\n    apply (wp set_cap_wp)\n   apply (clarsimp simp: sep_conj_ac )\noops\n\n\n(* tactics we had pre-thesis *)\n\nlemma \"(A \\<and>* B \\<and>* C \\<and>* D) s  \\<Longrightarrow>  (A \\<and>* B \\<and>* C \\<and>* D) s\"\n  apply (sep_select 4)\n  apply (sep_select_asm 3)\n  apply (sep_select 2)\n  apply (sep_cancel)\n  apply (sep_cancel)\n  apply (sep_cancel)\ndone\n\n(* forward reasoning *)\n\n\nlemma example_drule:\n  \"(ptr \\<mapsto>o obj) s\n  \\<Longrightarrow> (ptr \\<mapsto>S obj \\<and>* ptr \\<mapsto>f obj) s\"\n  by (metis sep_conj_commute sep_map_o_decomp)\n\nlemma sep_drule_example:\n  \"(ptr \\<mapsto>o obj \\<and>* A \\<and>* B ) s\n  \\<Longrightarrow> (A \\<and>* B \\<and>* ptr \\<mapsto>f obj \\<and>* ptr \\<mapsto>S obj) s\"\n  apply (sep_drule  example_drule)\n  apply (sep_solve)\ndone\n\n(* backwards reasoning *)\n\nlemma example_rule:\n  \"(ptr \\<mapsto>f obj \\<and>* ptr \\<mapsto>S obj) s\n  \\<Longrightarrow> (ptr \\<mapsto>o obj) s\"\n  by (metis sep_map_o_decomp)\n\nlemma sep_rule_example: \"(ptr \\<mapsto>f obj \\<and>* A \\<and>* B \\<and>* ptr \\<mapsto>S obj ) s \\<Longrightarrow> (ptr \\<mapsto>o obj \\<and>* A \\<and>* B) s\"\n  apply (sep_rule example_rule)\n  apply (sep_solve)\ndone\n\n\n\n(* the state of proving before new stuff *)\n\nlemma swap_cap_wp_old:\n  \"\\<lbrace><dest \\<mapsto>c cap \\<and>*  src \\<mapsto>c cap' \\<and>* R>\\<rbrace>\n    swap_cap cap' src cap dest\n   \\<lbrace>\\<lambda>_.<dest \\<mapsto>c cap' \\<and>* src \\<mapsto>c cap \\<and>* R>\\<rbrace>\"\n  apply (clarsimp simp add: swap_cap_def)\n  apply (wp swap_parents_wp set_cap_wp)\n  apply (rule hoare_chain)\n    apply (wp set_cap_wp)\n    apply (sep_solve)+\ndone\n\n\nlemma move_cap_wp_old:\n \"\\<lbrace><dest \\<mapsto>c - \\<and>* src \\<mapsto>c cap \\<and>* R>\\<rbrace>\n    move_cap cap' src dest\n  \\<lbrace>\\<lambda>_. <dest \\<mapsto>c cap'  \\<and>* src \\<mapsto>c NullCap \\<and>* R>\\<rbrace>\"\n  including no_pre\n  apply (simp add: move_cap_def)\n  apply (wp swap_parents_wp)\n   apply (rule hoare_strengthen_post)\n    apply (wp set_cap_wp)\n   apply (sep_select 2)\n   apply (sep_solve)\n  apply (rule hoare_chain)\n    apply (wp insert_cap_orphan_wp)\n   apply (sep_solve)\n  apply (sep_solve)\ndone\n\nlemma invoke_cnode_rotate2_wp_old:\n  \"(dest) \\<noteq> (rnd) \\<Longrightarrow>\n  \\<lbrace><dest \\<mapsto>c cap1 \\<and>* src \\<mapsto>c cap2 \\<and>*\n    rnd \\<mapsto>c - \\<and>* R>\\<rbrace>\n     invoke_cnode (RotateCall cap1 cap2 dest src rnd)\n  \\<lbrace>\\<lambda>_. <dest \\<mapsto>c NullCap \\<and>* src \\<mapsto>c cap1 \\<and>*\n    rnd \\<mapsto>c cap2 \\<and>* R>\\<rbrace>\"\n  including no_pre\n  apply (clarsimp simp: invoke_cnode_def)\n  apply (wp)\n   apply (rule hoare_strengthen_post)\n    apply (rule move_cap_wp)\n   apply (sep_solve )\n  apply (rule hoare_chain)\n    apply (rule move_cap_wp)\n   apply (sep_select_asm 2, sep_select_asm 3)\n   apply (sep_solve)\n  apply (sep_solve)\ndone\n\n(* new sep_select/asm *)\n\nlemma \"(A \\<and>* B \\<and>* C \\<and>* D) s  \\<Longrightarrow>  (A \\<and>* B \\<and>* C \\<and>* D) s\"\n  apply (sep_select 4 3 2 1)\n  apply (sep_select_asm 4 3 2 1)\n  apply (sep_select_asm 2 4)\noops\n\n\n(* sep_select_pre/post *)\n\nlemma \"\\<lbrace>A \\<and>* B \\<and>* C \\<and>* D\\<rbrace> f \\<lbrace>\\<lambda>_. A \\<and>* B \\<and>* C \\<and>* D\\<rbrace>\"\n  apply (sep_select_pre 4 1 2 3)\n  apply (sep_select_post 3 4 2 1)\n  apply (sep_select_post 3 4)\noops\n\n(* can be made to work for arbitrary monads *)\n\nlemma \"\\<lbrace>A \\<and>* B \\<and>* C \\<and>* D\\<rbrace> f \\<lbrace>\\<lambda>_. A \\<and>* B \\<and>* C \\<and>* D\\<rbrace>, \\<lbrace>E\\<rbrace>\"\n  apply (sep_select_pre 4 1 2 3)\n  apply (sep_select_post 3 4 2 1)\n  apply (sep_select_post 3 4)\noops\n\nlemma \"\\<lbrace>A \\<and>* B \\<and>* C \\<and>* D\\<rbrace> f \\<lbrace>\\<lambda>_. A \\<and>* B \\<and>* C \\<and>* D\\<rbrace>, -\"\n  apply (sep_select_pre 4 1 2 3)\n  apply (sep_select_post 3 4 2 1)\n  apply (sep_select_post 3 4)\noops\n\nlemma \"(P \\<and>* (P \\<longrightarrow>* Q)) s \\<Longrightarrow> Q s\"\n  apply (sep_mp, assumption )\n  done\n\nlemma \"P s \\<Longrightarrow> (Q \\<longrightarrow>* (P \\<and>* Q)) s\"\n  apply (erule sep_curry[rotated])\n  apply (assumption)\n  done\n\nthm sep_mp[no_vars] sep_curry[rotated, no_vars]\n\n\n(* wp tactic testing *)\n\n\n(* sep_wand approach *)\n\n\nlemma move_cap_wp2:\n \"\\<lbrace><dest \\<mapsto>c - \\<and>* src \\<mapsto>c cap \\<and>* R>\\<rbrace>\n    move_cap cap' src dest\n  \\<lbrace>\\<lambda>_. <dest \\<mapsto>c cap'  \\<and>* src \\<mapsto>c NullCap \\<and>* R>\\<rbrace>\"\n  apply (simp add: move_cap_def)\n  apply (sep_wp set_cap_wp swap_parents_wp insert_cap_orphan_wp)+\n  apply (sep_solve)\n  done\n\nlemma swap_cap_wp2:\n  \"\\<lbrace><dest \\<mapsto>c cap \\<and>*  src \\<mapsto>c cap' \\<and>* R>\\<rbrace>\n    swap_cap cap' src cap dest\n   \\<lbrace>\\<lambda>_.<dest \\<mapsto>c cap' \\<and>* src \\<mapsto>c cap \\<and>* R>\\<rbrace>\"\n  apply (clarsimp simp: swap_cap_def)\n  apply (sep_wp swap_parents_wp set_cap_wp)+\n  apply (sep_solve)\n  done\n\nlemma invoke_cnode_rotate2_wp:\n  \"(dest) \\<noteq> (rnd) \\<Longrightarrow>\n  \\<lbrace><dest \\<mapsto>c cap1 \\<and>* src \\<mapsto>c cap2 \\<and>*\n    rnd \\<mapsto>c - \\<and>* R>\\<rbrace>\n     invoke_cnode (RotateCall cap1 cap2 dest src rnd)\n  \\<lbrace>\\<lambda>_. <dest \\<mapsto>c NullCap \\<and>* src \\<mapsto>c cap1 \\<and>*\n    rnd \\<mapsto>c cap2 \\<and>* R>\\<rbrace>\"\n  apply (clarsimp simp: invoke_cnode_def)\n  apply (sep_wp move_cap_wp)+\n  apply (sep_solve)\n  done\n\n\n(* sep_drule/rule *)\n\nlemma sep_rule_example2:\n \"\\<lbrakk>(ptr \\<mapsto>o obj) s; finite (dom (object_slots obj))\\<rbrakk> \\<Longrightarrow>\n   (ptr \\<mapsto>E obj \\<and>* ptr \\<mapsto>f obj \\<and>* (\\<And>* slot\\<in>dom (object_slots obj). (ptr, slot) \\<mapsto>s obj)) s\"\n  apply (subst (asm) sep_map_o_decomp)\n  apply (subst (asm) sep_map_S_decomp, simp+)\n  apply sep_solve\n  done\n\nlemma sep_drule_example2:\n \"\\<lbrakk>(ptr \\<mapsto>f obj \\<and>* (\\<And>* slot\\<in>dom (object_slots obj). (ptr, slot) \\<mapsto>s obj) \\<and>* ptr \\<mapsto>E obj) s;\n   finite (dom (object_slots obj))\\<rbrakk>\n    \\<Longrightarrow>\n  (ptr \\<mapsto>o obj) s\"\n  by (metis sep_map_S_decomp sep_map_o_decomp)\n\n(* sep_curry *)\n\nlemma sep_drule_example_lemma:\n  \"\\<lbrakk>(H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* ptr \\<mapsto>f obj \\<and>* A \\<and>* B \\<and>*\n    (\\<And>* slot\\<in>dom (object_slots obj). (ptr, slot) \\<mapsto>s obj) \\<and>* D \\<and>* G \\<and>* E \\<and>* F \\<and>* ptr \\<mapsto>E obj ) s;\n    finite (dom (object_slots obj))\\<rbrakk>\n  \\<Longrightarrow>\n   (D \\<and>* G \\<and>* E \\<and>* F  \\<and>* ptr \\<mapsto>o obj \\<and>* H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* A \\<and>* B) s\"\n  apply (sep_drule sep_drule_example2)\n   apply assumption\n  apply sep_solve\n  done\n\n\n(* sep_back *)\n\n\nlemma sep_rule_example_lemma:\n \"\\<lbrakk>(H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* ptr \\<mapsto>o obj \\<and>* A \\<and>* B \\<and>* D \\<and>* G \\<and>* E \\<and>* F ) s;\n  finite (dom (object_slots obj))\\<rbrakk> \\<Longrightarrow>\n  (D \\<and>* G \\<and>* E \\<and>* F  \\<and>* ptr \\<mapsto>f obj \\<and>* H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* ptr \\<mapsto>E obj \\<and>*\n   A \\<and>* B \\<and>* (\\<And>* slot\\<in>dom (object_slots obj). (ptr, slot) \\<mapsto>s obj)) s\"\n  apply (sep_rule sep_rule_example2)\n   apply sep_solve\n  apply assumption\n  done\n\n\n(* works even with multiple conjuncts in assumptions and conclusions *)\nlemma sep_rule_double_conjunct_example:\n  \"\\<lbrakk>((obj_id, slot) \\<mapsto>c cap \\<and>* obj_id \\<mapsto>f obj) s;\n    object_slots obj slot = Some cap\\<rbrakk>\n  \\<Longrightarrow> ((obj_id, slot) \\<mapsto>s obj \\<and>* obj_id \\<mapsto>f obj) s\"\n  apply (sep_drule sep_map_s_sep_map_c)\n   apply assumption\n  apply (sep_cancel)+\n  done\n\nlemma sep_rule_double_conjunct_lemma:\n  \"\\<lbrakk>(H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* obj_id \\<mapsto>f obj \\<and>* A \\<and>* B \\<and>* D \\<and>* G \\<and>* E \\<and>* F \\<and>* (obj_id, slot) \\<mapsto>c cap ) s;\n    object_slots obj slot = Some cap\\<rbrakk> \\<Longrightarrow>\n   (D \\<and>* G \\<and>* E \\<and>* F  \\<and>*(obj_id, slot) \\<mapsto>s obj \\<and>* H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* A \\<and>* B \\<and>*  obj_id \\<mapsto>f obj) s\"\n  apply (sep_rule sep_rule_double_conjunct_example)\n   apply sep_solve\n  apply assumption\n  done\n\n(* side-conditions*)\n\n\nlemma sep_drule_side_condition_lemma:\n \"\\<lbrakk>(H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* obj_id \\<mapsto>f obj \\<and>* A \\<and>* B \\<and>* D \\<and>* G \\<and>* E \\<and>* F \\<and>* (obj_id, slot) \\<mapsto>c cap ) s;\n    object_slots obj slot = Some cap\\<rbrakk> \\<Longrightarrow>\n   (D \\<and>* G \\<and>* E \\<and>* F  \\<and>*(obj_id, slot) \\<mapsto>s obj \\<and>* H \\<and>* Z \\<and>* J \\<and>* L \\<and>* Y \\<and>* A \\<and>* B \\<and>*  obj_id \\<mapsto>f obj) s\"\n  apply (sep_drule sep_rule_double_conjunct_example, assumption)\n  apply (sep_solve)\n  done\n\nschematic_goal \"(P \\<and>* ?A) s \\<Longrightarrow> (A \\<and>* B \\<and>* P) s\"\n  apply (sep_solve)\n  done\n\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/l4v/proof/capDL-api/Sep_Tactic_Examples.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.519521321952093, "lm_q1q2_score": 0.2617899998530847}}
{"text": "(*  Title:      SSA_CFG_code.thy\n    Author:     Denis Lohner, Sebastian Ullrich\n*)\n\ntheory SSA_CFG_code imports\n  SSA_CFG\n  Mapping_Exts\n  \"~~/src/HOL/Library/Product_Lexorder\"\nbegin\n\ndefinition Union_of :: \"('a \\<Rightarrow> 'b set) \\<Rightarrow> 'a set \\<Rightarrow> 'b set\"\n  where \"Union_of f A \\<equiv> \\<Union>(f ` A)\"\n\nlemma Union_of_alt_def: \"Union_of f A = (\\<Union>x \\<in> A. f x)\"\n  unfolding Union_of_def by simp\n\ntype_synonym ('node, 'val) phis_code = \"('node \\<times> 'val, 'val list) mapping\"\n\ncontext CFG_base begin\n  definition addN :: \"'node \\<Rightarrow> ('var, 'node set) mapping \\<Rightarrow> ('var, 'node set) mapping\"\n    where \"addN n \\<equiv> fold (\\<lambda>v. Mapping.map_default v {} (insert n)) (sorted_list_of_set (uses n))\"\n  definition \"addN' n = fold (\\<lambda>v m. m(v \\<mapsto> case_option {n} (insert n) (m v))) (sorted_list_of_set (uses n))\"\n\n  lemma addN_transfer [transfer_rule]:\n    \"rel_fun op = (rel_fun (pcr_mapping op = op =) (pcr_mapping op = op =)) addN' addN\"\n    unfolding addN_def [abs_def] addN'_def [abs_def]\n      Mapping.map_default_def [abs_def] Mapping.default_def\n  apply (auto simp: mapping.pcr_cr_eq rel_fun_def cr_mapping_def)\n  apply transfer\n  apply (rule fold_cong)\n    apply simp\n   apply simp\n  apply (intro ext)\n  by auto\n\n  definition \"useNodes_of = fold (addN) \\<alpha>n Mapping.empty\"\n  lemmas useNodes_of_code = useNodes_of_def [unfolded addN_def [abs_def]]\n  declare useNodes_of_code [code]\n\n  lemma lookup_useNodes_of':\n    assumes [simp]: \"\\<And>n. finite (uses n)\"\n    shows \"Mapping.lookup (useNodes_of) v =\n    (if (\\<exists>n \\<in> set \\<alpha>n. v \\<in> uses n) then Some {n \\<in> set \\<alpha>n. v \\<in> uses n} else None)\"\n  proof -\n    { fix m n xs v\n      have \"Mapping.lookup (fold (\\<lambda>v. Mapping.map_default (v::'var) {} (insert (n::'node))) xs m) v=\n        (case Mapping.lookup m v of None \\<Rightarrow> (if v \\<in> set xs then Some {n} else None)\n          | Some N \\<Rightarrow> (if v \\<in> set xs then Some (insert n N) else Some N))\"\n      by (induction xs arbitrary: m) (auto simp: Mapping_lookup_map_default split: option.splits)\n    }\n    note addN_conv = this [of n \"sorted_list_of_set (uses n)\" for n, folded addN_def, simplified]\n    { fix xs m v\n      have \"Mapping.lookup (fold (addN) xs m) v = (case Mapping.lookup m v of None \\<Rightarrow> if (\\<exists>n\\<in>set xs. v \\<in> uses n) then Some {n\\<in>set xs. v \\<in> uses n} else None\n        | Some N \\<Rightarrow> Some ({n\\<in>set xs. v \\<in> uses n} \\<union> N))\"\n      by (induction xs arbitrary: m) (auto split: option.splits simp: addN_conv)\n    }\n    note this [of \"\\<alpha>n\" Mapping.empty, simp]\n    show ?thesis unfolding useNodes_of_def\n      by (auto split: option.splits simp: lookup_empty)\n  qed\nend\n\ncontext CFG begin\n  lift_definition useNodes_of' :: \" ('var, 'node set) mapping\"\n  is \"\\<lambda>v. if (\\<exists>n \\<in> set \\<alpha>n. v \\<in> uses n) then Some {n \\<in> set \\<alpha>n. v \\<in> uses n} else None\" .\n\n  lemma useNodes_of': \"useNodes_of' = useNodes_of\"\n  proof-\n    { fix m n xs\n      have \"fold (\\<lambda>v m. m(v::'var \\<mapsto> case m v of None \\<Rightarrow> {n::'node} | Some x \\<Rightarrow> insert n x)) xs m =\n        (\\<lambda>v. case m v of None \\<Rightarrow> (if v \\<in> set xs then Some {n} else None)\n          | Some N \\<Rightarrow> (if v \\<in> set xs then Some (insert n N) else Some N))\"\n      by (induction xs arbitrary: m)(auto split: option.splits)\n    }\n    note addN'_conv = this [of n \"sorted_list_of_set (uses n)\" for n, folded addN'_def, simplified]\n    { fix xs m\n      have \"fold (addN') xs m = (\\<lambda>v. case m v of None \\<Rightarrow> if (\\<exists>n\\<in>set xs. v \\<in> uses n) then Some {n\\<in>set xs. v \\<in> uses n} else None\n        | Some N \\<Rightarrow> Some ({n\\<in>set xs. v \\<in> uses n} \\<union> N))\"\n      by (induction xs arbitrary: m) (auto 4 4 split: option.splits if_splits simp: addN'_conv intro!: ext)\n    }\n    note this [of \"\\<alpha>n\" Map.empty, simp]\n    show \"useNodes_of' = useNodes_of\"\n    unfolding mmap_def useNodes_of_def\n    by (transfer fixing:) auto\n  qed\n\n  declare useNodes_of'.transfer [unfolded useNodes_of', transfer_rule]\n\n  \n\nend\n\ncontext CFG_SSA_base begin\n  definition phis_addN\n  where \"phis_addN n = fold (\\<lambda>v. Mapping.map_default v {} (insert n)) (case_option [] id (phis n))\"\n\n  definition phidefNodes where [code]:\n    \"phidefNodes = fold (\\<lambda>(n,v). Mapping.update v n) (sorted_list_of_set (dom phis)) Mapping.empty\"\n\n  lemma keys_phidefNodes:\n    assumes \"finite (dom phis)\"\n    shows \"Mapping.keys (phidefNodes) = snd ` dom phis\"\n  proof -\n    { fix xs m x\n      have \"fold (\\<lambda>(a,b) m. m(b \\<mapsto> a)) (xs::('node \\<times> 'val) list) m x = (if x \\<in> snd ` set xs then (Some \\<circ> fst) (last [(b,a)\\<leftarrow>xs. a = x]) else m x)\"\n      by (induction xs arbitrary: m) (auto split: if_splits simp: filter_empty_conv intro: rev_image_eqI)\n    }\n    from this [of \"sorted_list_of_set (dom phis)\" Map.empty] assms\n    show ?thesis\n    unfolding phidefNodes_def keys_dom_lookup\n    by (transfer fixing: phis) (auto simp: dom_def intro: rev_image_eqI)\n  qed\n\n  definition phiNodes_of :: \" ('val, ('node \\<times> 'val) set) mapping\"\n  where \"phiNodes_of = fold (phis_addN) (sorted_list_of_set (dom phis)) Mapping.empty\"\n\n  lemma lookup_phiNodes_of:\n  assumes [simp]: \"finite (dom phis)\"\n  shows \"Mapping.lookup (phiNodes_of) v =\n    (if (\\<exists>n \\<in> dom phis. v \\<in> set (the (phis n))) then Some {n \\<in> dom phis. v \\<in> set (the (phis n))} else None)\"\n  proof -\n  {\n    fix m n xs v\n    have \"Mapping.lookup (fold (\\<lambda>v. Mapping.map_default v {} (insert (n::'node \\<times> 'val))) xs (m::('val, ('node \\<times> 'val) set) mapping)) v =\n      (case Mapping.lookup m v of None \\<Rightarrow> (if v \\<in> set xs then Some {n} else None)\n        | Some N \\<Rightarrow> (if v \\<in> set xs then Some (insert n N) else Some N))\"\n    by (induction xs arbitrary: m) (auto simp: Mapping_lookup_map_default split: option.splits)\n  }\n  note phis_addN_conv = this [of n \"case_option [] id (phis n)\" for n, folded phis_addN_def]\n  {\n    fix xs m v\n    have \"Mapping.lookup (fold (phis_addN) xs m) v =\n      (case Mapping.lookup m v of None \\<Rightarrow> if (\\<exists>n \\<in> set xs. v \\<in> set (case_option [] id (phis n))) then Some {n \\<in> set xs. v \\<in> set (case_option [] id (phis n))} else None\n        | Some N \\<Rightarrow> Some ({n \\<in> set xs. v \\<in> set (case_option [] id (phis n))} \\<union> N))\"\n    by (induction xs arbitrary: m) (auto simp: phis_addN_conv split: option.splits if_splits)+\n  }\n  note this [of \"sorted_list_of_set (dom phis)\", simp]\n  show ?thesis\n    unfolding phiNodes_of_def\n  by (force split: option.splits simp: lookup_empty)\n  qed\n\n  lemmas phiNodes_of_code = phiNodes_of_def [unfolded phis_addN_def [abs_def]]\n  declare phiNodes_of_code [code]\n\ninterpretation lifting_syntax .\nlemma phis_transfer [transfer_rule]: \"pcr_mapping op = op = phis (Mapping.Mapping phis)\"\n  by (auto simp: mapping.pcr_cr_eq rel_fun_def cr_mapping_def Mapping.Mapping_inverse)\n\nend\n\ncontext CFG_SSA begin\n  declare lookup_phiNodes_of [OF phis_finite, simp]\n  declare keys_phidefNodes [OF phis_finite, simp]\nend\n\nlocale CFG_SSA_ext_base = CFG_SSA_base \\<alpha>n predecessors Entry \"defs\" \"uses\" phis\n  for \\<alpha>n :: \"'node::linorder list\"\n    and predecessors :: \"'node \\<Rightarrow> 'node list\"\n    and Entry :: \"'node\"\n    and \"defs\" :: \"'node \\<Rightarrow> 'val::linorder set\"\n    and \"uses\" :: \"'node \\<Rightarrow> 'val set\"\n    and phis :: \" ('node, 'val) phis\"\nbegin\n  abbreviation \"cache f \\<equiv> Mapping.tabulate \\<alpha>n f\"\n\n  lemma lookup_cache[simp]: \"n \\<in> set \\<alpha>n \\<Longrightarrow> Mapping.lookup (cache f) n = Some (f n)\"\n  by transfer (auto simp: Map.map_of_map_restrict)\n\n  lemma lookup_cacheD [dest]: \"Mapping.lookup (cache f) x = Some y \\<Longrightarrow> y = f x\"\n  by transfer (auto simp: Map.map_of_map_restrict restrict_map_def split: if_splits)\n\n  lemma lookup_cache_usesD: \"Mapping.lookup (cache uses) n = Some vs \\<Longrightarrow> vs = uses n\"\n  by blast\nend\n\ndefinition[simp]: \"usesOf m n \\<equiv> case_option {} id (Mapping.lookup m n)\"\n\nlocale CFG_SSA_ext = CFG_SSA_ext_base  \\<alpha>n predecessors Entry \"defs\" \"uses\" phis\n  + CFG_SSA \\<alpha>n predecessors Entry \"defs\" \"uses\" phis\n  for \\<alpha>n :: \"'node::linorder list\"\n    and predecessors :: \"'node \\<Rightarrow> 'node list\"\n    and Entry :: \"'node\"\n    and \"defs\" :: \"'node \\<Rightarrow> 'val::linorder set\"\n    and \"uses\" :: \"'node \\<Rightarrow> 'val set\"\n    and phis :: \" ('node, 'val) phis\"\nbegin\n  lemma usesOf_cache[abs_def, simp]: \"usesOf (cache uses) n = uses n\"\n  by (auto simp: uses_in_\\<alpha>n dest: lookup_cache_usesD split: option.split)\nend\n\nlocale CFG_SSA_base_code = CFG_SSA_ext_base \\<alpha>n predecessors Entry \"defs\" \"usesOf uses\" \"Mapping.lookup phis\"\n  for \\<alpha>n :: \"'node::linorder list\"\n    and predecessors :: \"'node \\<Rightarrow> 'node list\"\n    and Entry :: \"'node\"\n    and \"defs\" :: \"'node \\<Rightarrow> 'val::linorder set\"\n    and \"uses\" :: \" ('node, 'val set) mapping\"\n    and phis :: \" ('node, 'val) phis_code\"\nbegin\n  declare phis_transfer [simplified, transfer_rule]\n\n  lemma phiDefs_code [code]:\n  \"phiDefs n = snd ` Set.filter (\\<lambda>(n',v). n' = n) (Mapping.keys phis)\"\n    unfolding phiDefs_def\n    by transfer (auto 4 3 intro: rev_image_eqI simp: Set.filter_def)\n\n  lemmas phiUses_code [code] = phiUses_def [folded Union_of_alt_def]\n  declare allUses_def [code]\n  lemmas allVars_code [code] = allVars_def [folded Union_of_alt_def]\nend\n\nlocale CFG_SSA_code = CFG_SSA_base_code  \\<alpha>n predecessors Entry \"defs\" \"uses\" phis\n  + CFG_SSA_ext \\<alpha>n predecessors Entry \"defs\" \"usesOf uses\" \"Mapping.lookup phis\"\n  for \\<alpha>n :: \"'node::linorder list\"\n    and predecessors :: \"'node \\<Rightarrow> 'node list\"\n    and Entry :: \"'node\"\n    and \"defs\" :: \"'node \\<Rightarrow> 'val::linorder set\"\n    and \"uses\" :: \" ('node, 'val set) mapping\"\n    and phis :: \" ('node, 'val) phis_code\"\n\n\ndefinition \"the_trivial v vs = (case (foldl (\\<lambda>(good,v') w. if w = v then (good,v')\n      else case v' of Some v' \\<Rightarrow> (good \\<and> w = v', Some v')\n        | None \\<Rightarrow> (good, Some w))\n    (True, None) vs)\n  of (False, _) \\<Rightarrow> None | (True,v) \\<Rightarrow> v)\"\n\nlemma the_trivial_Nil [simp]: \"the_trivial x [] = None\"\n  unfolding the_trivial_def by simp\n\nlemma the_trivialI:\n  assumes \"set vs \\<subseteq> {v, v'}\"\n    and \"v' \\<noteq> v\"\n  shows \"the_trivial v vs = (if set vs \\<subseteq> {v} then None else Some v')\"\nproof -\n  { fix vx\n    have \"\\<lbrakk> set vs \\<subseteq> {v, v'}; v' \\<noteq> v; vx \\<in> {None, Some v'} \\<rbrakk>\n    \\<Longrightarrow> (case foldl (\\<lambda>(good, v') w.\n                    if w = v then (good, v')\n                    else case v' of None \\<Rightarrow> (good, Some w) | Some v' \\<Rightarrow> (good \\<and> w = v', Some v'))\n           (True, vx) vs of\n     (True, x) \\<Rightarrow> x | (False, x) \\<Rightarrow> None) = (if set vs \\<subseteq> {v} then vx else Some v')\"\n    by (induction vs arbitrary: vx; case_tac vx; auto)\n  }\n  with assms show ?thesis unfolding the_trivial_def by simp\nqed\n\nlemma the_trivial_conv:\n  shows \"the_trivial v vs = (if \\<exists>v' \\<in> set vs. v' \\<noteq> v \\<and> set vs - {v'} \\<subseteq> {v} then Some (THE v'. v' \\<in> set vs \\<and> v' \\<noteq> v \\<and> set vs - {v'} \\<subseteq> {v}) else None)\"\nproof -\n  { fix b a vs\n    have \"a \\<noteq> v\n       \\<Longrightarrow> foldl (\\<lambda>(good, v') w.\n                     if w = v then (good, v')\n                     else case v' of None \\<Rightarrow> (good, Some w) | Some v' \\<Rightarrow> (good \\<and> w = v', Some v'))\n            (b, Some a) vs =\n           (b \\<and> set vs \\<subseteq> {v, a}, Some a)\"\n     by (induction vs arbitrary: b; clarsimp)\n  }\n  note this[simp]\n  { fix b vx\n    have \"\\<lbrakk> vx \\<in> insert None (Some ` set vs); case_option True (\\<lambda>vx. vx \\<noteq> v) vx \\<rbrakk>\n    \\<Longrightarrow> foldl (\\<lambda>(good, v') w.\n                    if w = v then (good, v')\n                    else case v' of None \\<Rightarrow> (good, Some w) | Some v' \\<Rightarrow> (good \\<and> w = v', Some v'))\n        (b, vx) vs = (b \\<and> (case vx of Some w \\<Rightarrow> set vs \\<subseteq> {v, w} | None \\<Rightarrow> \\<exists>w. set vs \\<subseteq> {v, w}),\n        (case vx of Some w \\<Rightarrow> Some w | None \\<Rightarrow> if (\\<exists>v'\\<in>set vs. v' \\<noteq> v) then Some (hd (filter (\\<lambda>v'. v' \\<noteq> v) vs)) else None))\"\n    by (induction vs arbitrary: b vx; auto)\n  }\n  hence \"the_trivial v vs = (if \\<exists>v' \\<in> set vs. v' \\<noteq> v \\<and> set vs - {v'} \\<subseteq> {v} then Some (hd (filter (\\<lambda>v'. v' \\<noteq> v) vs)) else None)\"\n    unfolding the_trivial_def by (auto split: bool.splits)\n  thus ?thesis\n  apply (auto split: if_splits)\n  apply (rule the_equality [THEN sym])\n   by (thin_tac \"P\" for P, (induction vs; auto))+\nqed\n\nlemma the_trivial_SomeE:\n  assumes \"the_trivial v vs = Some v'\"\n  obtains \"v \\<noteq> v'\" and \"set vs = {v'}\" | \"v \\<noteq> v'\" and \"set vs = {v,v'}\"\nusing assms\napply atomize_elim\napply (subst(asm) the_trivial_conv)\napply (split if_splits; simp)\nby (subgoal_tac \"(THE v'. v' \\<in> set vs \\<and> v' \\<noteq> v \\<and> set vs - {v'} \\<subseteq> {v}) = hd (filter (\\<lambda>v'. v' \\<noteq> v) vs)\")\n  (fastforce simp: set_double_filter_hd set_single_hd set_minus_one)+\n\nlocale CFG_SSA_wf_base_code = CFG_SSA_base_code \\<alpha>n predecessors Entry \"defs\" \"uses\" phis\n  + CFG_SSA_wf_base \\<alpha>n predecessors Entry \"defs\" \"usesOf uses\" \"Mapping.lookup phis\"\n  for \\<alpha>n :: \"'node::linorder list\"\n    and predecessors :: \"'node \\<Rightarrow> 'node list\"\n    and Entry :: \"'node\"\n    and \"defs\" :: \"'node \\<Rightarrow> 'val::linorder set\"\n    and \"uses\" :: \" ('node, 'val set) mapping\"\n    and phis :: \" ('node, 'val) phis_code\"\nbegin\n  definition [code]:\n    \"trivial_code (v::'val) vs = (the_trivial v vs \\<noteq> None)\"\n  definition[code]: \"trivial_phis = Set.filter (\\<lambda>(n,v). trivial_code v (the (Mapping.lookup phis (n,v)))) (Mapping.keys phis)\"\n  definition [code]: \"redundant_code = (trivial_phis \\<noteq> {})\"\nend\n\nlocale CFG_SSA_wf_code = CFG_SSA_code \\<alpha>n predecessors Entry \"defs\" \"uses\" phis\n  + CFG_SSA_wf_base_code \\<alpha>n predecessors Entry \"defs\" \"uses\" phis\n  + CFG_SSA_wf \\<alpha>n predecessors Entry \"defs\" \"usesOf uses\" \"Mapping.lookup phis\"\n  for \\<alpha>n :: \"'node::linorder list\"\n    and predecessors :: \"'node \\<Rightarrow> 'node list\"\n    and Entry :: \"'node\"\n    and \"defs\" :: \"'node \\<Rightarrow> 'val::linorder set\"\n    and \"uses\" :: \" ('node, 'val set) mapping\"\n    and phis :: \" ('node, 'val) phis_code\"\nbegin\n  lemma trivial_code:\n    \"phi v = Some vs \\<Longrightarrow> trivial v = trivial_code v vs\"\n  unfolding trivial_def trivial_code_def\n  apply (auto split: option.splits simp: isTrivialPhi_def)\n    apply (clarsimp simp: the_trivial_conv split: if_splits)\n   apply (clarsimp simp: the_trivial_conv split: if_splits)\n  apply (erule the_trivial_SomeE)\n   apply simp\n   apply (rule phiArg_in_allVars; auto simp: phiArg_def)\n  apply (rename_tac v')\n  apply (rule_tac x=v' in bexI)\n   apply simp\n  apply (rule phiArg_in_allVars; auto simp: phiArg_def)\n  done\n\n  lemma trivial_phis:\n    \"trivial_phis = {(n,v). Mapping.lookup phis (n,v) \\<noteq> None \\<and> trivial v}\"\n  unfolding trivial_phis_def Set.filter_def\n  apply (auto simp add: phi_def keys_dom_lookup)\n   apply (subst trivial_code)\n    apply (auto simp: image_def trivial_in_allVars phis_phi)\n  apply (frule trivial_phi)\n  apply (auto simp add: trivial_code phi_def[symmetric] phis_phi)\n  done\n\n  lemma redundant_code:\n    \"redundant = redundant_code\"\n  unfolding redundant_def redundant_code_def trivial_phis[of]\n  apply (auto simp: image_def trivial_in_allVars)\n  apply (frule trivial_phi)\n  apply (auto simp: phi_def)\n  done\n\n  lemma trivial_code_mapI:\n  \"\\<lbrakk> trivial_code v vs; f ` (set vs - {v}) \\<noteq> {v} ; f v = v \\<rbrakk> \\<Longrightarrow> trivial_code v (map f vs)\"\n  unfolding trivial_code_def the_trivial_conv\n    by (auto split: if_splits)\n\n  lemma trivial_code_map_conv:\n    \"f v = v \\<Longrightarrow> trivial_code v (map f vs) \\<longleftrightarrow> (\\<exists>v'\\<in>set vs. f v' \\<noteq> v \\<and> (f ` set vs) - {f v'} \\<subseteq> {v})\"\n    unfolding trivial_code_def the_trivial_conv\n    by auto\n\nend\n\nlocale CFG_SSA_Transformed_code = ssa: CFG_SSA_wf_code \\<alpha>n predecessors Entry \"defs\" \"uses\" phis\n   +\n   CFG_SSA_Transformed \\<alpha>n predecessors Entry oldDefs oldUses \"defs\" \"usesOf uses\" \"Mapping.lookup phis\" var\nfor\n  \\<alpha>n :: \"'node::linorder list\" and\n  predecessors :: \"'node \\<Rightarrow> 'node list\" and\n  Entry::\"'node\" and\n  oldDefs :: \"'node \\<Rightarrow> 'var::linorder set\" and\n  oldUses :: \"'node \\<Rightarrow> 'var set\" and\n  \"defs\" :: \"'node \\<Rightarrow> 'val::linorder set\" and\n  \"uses\" :: \" ('node, 'val set) mapping\" and\n  phis :: \" ('node, 'val) phis_code\" and\n  var :: \"'val \\<Rightarrow> 'var\"\n+\nassumes dom_uses_in_graph: \"Mapping.keys uses \\<subseteq> set \\<alpha>n\"\n\nend\n", "meta": {"author": "lohner", "repo": "FormalSSA", "sha": "34253ae0ea0db6ef78b644f41ab5e9d0bde6c32e", "save_path": "github-repos/isabelle/lohner-FormalSSA", "path": "github-repos/isabelle/lohner-FormalSSA/FormalSSA-34253ae0ea0db6ef78b644f41ab5e9d0bde6c32e/SSA_CFG_code.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926665999540697, "lm_q2_score": 0.44167300566462553, "lm_q1q2_score": 0.26176483855874816}}
{"text": "(* @TAG(OTHER_LGPL) *)\n\n(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      XVcgEx.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2006-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection \"Examples for Parallel Assignments\"\n\ntheory XVcgEx \nimports \"../XVcg\"\n\nbegin\n\nrecord \"globals\" =\n  \"G_'\"::\"nat\"\n  \"H_'\"::\"nat\"\n\nrecord 'g vars = \"'g state\" +\n  A_' :: nat\n  B_' :: nat\n  C_' :: nat\n  I_' :: nat\n  M_' :: nat\n  N_' :: nat\n  R_' :: nat\n  S_' :: nat\n  Arr_' :: \"nat list\"\n  Abr_':: string\n\nterm \"BASIC\n         \\<acute>A :== x,\n         \\<acute>B :== y        \n      END\"\n\nterm \"BASIC\n         \\<acute>G :== \\<acute>H,\n         \\<acute>H :== \\<acute>G        \n      END\"\n\nterm \"BASIC\n        LET (x,y) = (\\<acute>A,b);\n            z = \\<acute>B\n        IN \\<acute>A :== x,\n           \\<acute>G :== \\<acute>A + y + z\n      END\"\n\n\nlemma \"\\<Gamma>\\<turnstile> \\<lbrace>\\<acute>A = 0\\<rbrace> \n      \\<lbrace>\\<acute>A < 0\\<rbrace> \\<longmapsto> BASIC\n       LET (a,b,c) = foo \\<acute>A\n       IN \n            \\<acute>A :== a,\n            \\<acute>B :== b,\n            \\<acute>C :== c\n      END\n      \\<lbrace>\\<acute>A = x \\<and> \\<acute>B = y \\<and> \\<acute>C = c\\<rbrace>\"\napply vcg\noops\n\nlemma \"\\<Gamma>\\<turnstile> \\<lbrace>\\<acute>A = 0\\<rbrace> \n      \\<lbrace>\\<acute>A < 0\\<rbrace> \\<longmapsto> BASIC\n       LET (a,b,c) = foo \\<acute>A\n       IN \n            \\<acute>A :== a,\n            \\<acute>G :== b + \\<acute>B,\n            \\<acute>H :== c\n      END\n      \\<lbrace>\\<acute>A = x \\<and> \\<acute>G = y \\<and> \\<acute>H = c\\<rbrace>\"\napply vcg\noops\n\ndefinition foo:: \"nat \\<Rightarrow> (nat \\<times> nat \\<times> nat)\"\n  where \"foo n = (n,n+1,n+2)\"\n\nlemma \"\\<Gamma>\\<turnstile> \\<lbrace>\\<acute>A = 0\\<rbrace> \n      \\<lbrace>\\<acute>A < 0\\<rbrace> \\<longmapsto> BASIC\n       LET (a,b,c) = foo \\<acute>A\n       IN \n            \\<acute>A :== a,\n            \\<acute>G :== b + \\<acute>B,\n            \\<acute>H :== c\n      END\n      \\<lbrace>\\<acute>A = x \\<and> \\<acute>G = y \\<and> \\<acute>H = c\\<rbrace>\"\napply (vcg add: foo_def snd_conv fst_conv)\noops\n\nend\n", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/c-parser/Simpl/ex/XVcgEx.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926665855647395, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.2617648322033695}}
{"text": "(*  Title:      Monad_Normalisation_Test.thy\n    Author:     Manuel Eberl, TU München\n    Author:     Andreas Lochbihler, ETH Zurich\n    Author:     Joshua Schneider, ETH Zurich\n*)\n\ntheory Monad_Normalisation_Test\nimports Monad_Normalisation\nbegin\n\nsection \\<open>Tests and examples\\<close>\n\ncontext includes monad_normalisation\nbegin\n\nlemma\n  assumes \"f = id\"\n  shows\n    \"do {x \\<leftarrow> B; z \\<leftarrow> C x; d \\<leftarrow> E z x; a \\<leftarrow> D z x; y \\<leftarrow> A; return_pmf (x,y)} =\n     do {y \\<leftarrow> A; x \\<leftarrow> B; z \\<leftarrow> C x; a \\<leftarrow> D z x; d \\<leftarrow> E z x; return_pmf (f (x,y))}\"\napply (simp)\napply (simp add: assms)\ndone\n\nlemma \"(do {a \\<leftarrow> E; b \\<leftarrow> E; w \\<leftarrow> B b a; z \\<leftarrow> B a b; return_pmf (w,z)}) =\n       (do {a \\<leftarrow> E; b \\<leftarrow> E; z \\<leftarrow> B a b; w \\<leftarrow> B b a; return_pmf (w,z)})\"\nby (simp)\n\nlemma \"(do {a \\<leftarrow> E; b \\<leftarrow> E; w \\<leftarrow> B b a; z \\<leftarrow> B a b; return_pmf (w,z)}) =\n       (do {a \\<leftarrow> E; b \\<leftarrow> E; z \\<leftarrow> B a b; w \\<leftarrow> B b a; return_pmf (w,z)})\"\nby (simp)\n\nlemma \"do {y \\<leftarrow> A; x \\<leftarrow> A; z \\<leftarrow> B x y y; w \\<leftarrow> B x x y; Some (x,y)} =\n       do {x \\<leftarrow> A; y \\<leftarrow> A; z \\<leftarrow> B x x y; w \\<leftarrow> B x y y; Some (x,y)}\"\nby (simp)\n\nlemma \"do {y \\<leftarrow> A; x \\<leftarrow> A; z \\<leftarrow> B x y y; w \\<leftarrow> B x x y; {x,y}} =\n       do {x \\<leftarrow> A; y \\<leftarrow> A; z \\<leftarrow> B x x y; w \\<leftarrow> B x y y; {x,y}}\"\nby (simp)\n\nlemma \"do {y \\<leftarrow> A; x \\<leftarrow> A; z \\<leftarrow> B x y y; w \\<leftarrow> B x x y; return_pmf (x,y)} =\n       do {x \\<leftarrow> A; y \\<leftarrow> A; z \\<leftarrow> B x x y; w \\<leftarrow> B x y y; return_pmf (x,y)}\"\nby (simp)\n\nlemma \"do {x \\<leftarrow> A 0; y \\<leftarrow> A x; w \\<leftarrow> B y y; z \\<leftarrow> B x y; a \\<leftarrow> C; Predicate.single (a,a)} =\n       do {x \\<leftarrow> A 0; y \\<leftarrow> A x; z \\<leftarrow> B x y; w \\<leftarrow> B y y; a \\<leftarrow> C; Predicate.single (a,a)}\"\nby (simp)\n\nlemma \"do {x \\<leftarrow> A 0; y \\<leftarrow> A x; z \\<leftarrow> B x y; w \\<leftarrow> B y y; a \\<leftarrow> C; return_pmf (a,a)} =\n       do {x \\<leftarrow> A 0; y \\<leftarrow> A x; z \\<leftarrow> B y y; w \\<leftarrow> B x y; a \\<leftarrow> C; return_pmf (a,a)}\"\nby (simp)\n\nlemma \"do {x \\<leftarrow> B; z \\<leftarrow> C x; d \\<leftarrow> E z x; a \\<leftarrow> D z x; y \\<leftarrow> A; return_pmf (x,y)} =\n       do {y \\<leftarrow> A; x \\<leftarrow> B; z \\<leftarrow> C x; a \\<leftarrow> D z x; d \\<leftarrow> E z x; return_pmf (x,y)}\"\nby (simp)\n\n\nno_adhoc_overloading Monad_Syntax.bind bind_pmf\n\ncontext\n  fixes \\<A>1 :: \"'a \\<Rightarrow> (('a \\<times> 'a) \\<times> 'b) spmf\"\n  and \\<A>2 :: \"'a \\<times> 'a \\<Rightarrow> 'b \\<Rightarrow> bool spmf\"\n  and sample_uniform :: \"nat \\<Rightarrow> nat spmf\"\n  and order :: \"'a \\<Rightarrow> nat\"\nbegin\n\nlemma \n  \"do {\n      x \\<leftarrow> sample_uniform (order \\<G>);\n      y \\<leftarrow> sample_uniform (order \\<G>);\n      z \\<leftarrow> sample_uniform (order \\<G>);\n      b \\<leftarrow> coin_spmf;\n      ((msg1, msg2), \\<sigma>) \\<leftarrow> \\<A>1 (f x);\n      _ :: unit \\<leftarrow> assert_spmf (valid_plain msg1 \\<and> valid_plain msg2);\n      guess \\<leftarrow> \\<A>2 (f y, xor (f z) (if b then msg1 else msg2)) \\<sigma>;\n      return_spmf (guess \\<longleftrightarrow> b)\n    } = do {\n      x \\<leftarrow> sample_uniform (order \\<G>);\n      y \\<leftarrow> sample_uniform (order \\<G>);\n      ((msg1, msg2), \\<sigma>) \\<leftarrow> \\<A>1 (f x);\n      _ :: unit \\<leftarrow> assert_spmf (valid_plain msg1 \\<and> valid_plain msg2);\n      b \\<leftarrow> coin_spmf;\n      x \\<leftarrow> sample_uniform (order \\<G>);\n      guess \\<leftarrow> \\<A>2 (f y, xor (f x) (if b then msg1 else msg2)) \\<sigma>;\n      return_spmf (guess \\<longleftrightarrow> b)\n    }\"\nby (simp add: split_def)\n\nlemma\n  \"do {\n      x \\<leftarrow> sample_uniform (order \\<G>);\n      xa \\<leftarrow> sample_uniform (order \\<G>);\n      x \\<leftarrow> \\<A>1 (f x);\n      case x of\n      (x, xb) \\<Rightarrow>\n        (case x of\n         (msg1, msg2) \\<Rightarrow>\n           \\<lambda>\\<sigma>. do {\n                a \\<leftarrow> assert_spmf (valid_plain msg1 \\<and> valid_plain msg2);\n                x \\<leftarrow> coin_spmf;\n                xaa \\<leftarrow> map_spmf f (sample_uniform (order \\<G>));\n                guess \\<leftarrow> \\<A>2 (f xa, xaa) \\<sigma>;\n                return_spmf (guess \\<longleftrightarrow> x)\n              })\n         xb\n    } = do {\n      x \\<leftarrow> sample_uniform (order \\<G>);\n      xa \\<leftarrow> sample_uniform (order \\<G>);\n      x \\<leftarrow> \\<A>1 (f x);\n      case x of\n      (x, xb) \\<Rightarrow>\n        (case x of\n         (msg1, msg2) \\<Rightarrow>\n           \\<lambda>\\<sigma>. do {\n                a \\<leftarrow> assert_spmf (valid_plain msg1 \\<and> valid_plain msg2);\n                z \\<leftarrow> map_spmf f (sample_uniform (order \\<G>));\n                guess \\<leftarrow> \\<A>2 (f xa, z) \\<sigma>;\n                map_spmf ((\\<longleftrightarrow>) guess) coin_spmf\n              })\n         xb\n    }\"\nby (simp add: map_spmf_conv_bind_spmf)\n\nlemma elgamal_step3:\n  \"do {\n      x \\<leftarrow> sample_uniform (order \\<G>);\n      y \\<leftarrow> sample_uniform (order \\<G>);\n      b \\<leftarrow> coin_spmf;\n      p \\<leftarrow> \\<A>1 (f x);\n      _ \\<leftarrow> assert_spmf (valid_plain (fst (fst p)) \\<and> valid_plain (snd (fst p)));\n      guess \\<leftarrow>\n        \\<A>2 (f y, xor (f (x * y)) (if b then fst (fst p) else snd (fst p)))\n         (snd p);\n      return_spmf (guess \\<longleftrightarrow> b)\n    }  = do {\n      y \\<leftarrow> sample_uniform (order \\<G>);\n      b \\<leftarrow> coin_spmf;\n      p \\<leftarrow> \\<A>1 (f y);\n      _ \\<leftarrow> assert_spmf (valid_plain (fst (fst p)) \\<and> valid_plain (snd (fst p)));\n      ya \\<leftarrow> sample_uniform (order \\<G>);\n      b' \\<leftarrow> \\<A>2 (f ya,\n                 xor (f (y * ya)) (if b then fst (fst p) else snd (fst p)))\n             (snd p);\n      return_spmf (b' \\<longleftrightarrow> b)\n    }\"\nby (simp)\n\nend\n\ntext \\<open>Distributivity\\<close>\n\nlemma\n  \"do {\n      x \\<leftarrow> A :: nat spmf;\n      a \\<leftarrow> B;\n      b \\<leftarrow> B;\n      if a = b then do {\n        return_spmf x\n      } else do {\n        y \\<leftarrow> C;\n        return_spmf (x + y)\n      }\n   } = do {\n      a \\<leftarrow> B;\n      b \\<leftarrow> B;\n      if b = a then A else do {\n        y \\<leftarrow> C;\n        x \\<leftarrow> A;\n        return_spmf (y + x)\n      }\n   }\"\nby (simp add: add.commute cong: if_cong)\n\nlemma\n  \"do {\n      x \\<leftarrow> A :: nat spmf;\n      p \\<leftarrow> do {\n        a \\<leftarrow> B;\n        b \\<leftarrow> B;\n        return_spmf (a, b)\n      };\n      q \\<leftarrow> coin_spmf;\n      if q then do {\n        return_spmf (x + fst p)\n      } else do {\n        y \\<leftarrow> C;\n        return_spmf (y + snd p)\n      }\n   } = do {\n      q \\<leftarrow> coin_spmf;\n      if q then do {\n        x \\<leftarrow> A;\n        a \\<leftarrow> B;\n        _ \\<leftarrow> B;\n        return_spmf (x + a)\n      } else do {\n        y \\<leftarrow> C;\n        a \\<leftarrow> B;\n        _ \\<leftarrow> B;\n        _ \\<leftarrow> A;\n        return_spmf (y + a)\n      }\n   }\"\nby (simp cong: if_cong)\n\nlemma\n  fixes f :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat + nat\"\n  shows\n  \"do {\n      x \\<leftarrow> (A::nat set);\n      a \\<leftarrow> B;\n      b \\<leftarrow> B;\n      case f a b of\n        Inl c \\<Rightarrow> {x}\n      | Inr c \\<Rightarrow> do {\n          y \\<leftarrow> C x;\n          {(x + y + c)}\n        }\n   } = do {\n      a \\<leftarrow> B;\n      b \\<leftarrow> B;\n      case f b a of\n        Inl c \\<Rightarrow> A\n      | Inr c \\<Rightarrow> do {\n          x \\<leftarrow> A;\n          y \\<leftarrow> C x;\n          {(y + c + x)}\n      }\n   }\"\nby (simp add: add.commute add.left_commute cong: sum.case_cong)\n\n\nsection \\<open>Limits\\<close>\n\ntext \\<open>\n  The following example shows that the combination of monad normalisation and regular ordered\n  rewriting is not necessarily confluent.\n\\<close>\n\nlemma \"do {a \\<leftarrow> A; b \\<leftarrow> A; Some (a \\<and> b, b)} =\n       do {a \\<leftarrow> A; b \\<leftarrow> A; Some (a \\<and> b, a)}\"\napply (simp add: conj_comms)?       \\<comment> \\<open>no progress made\\<close>\napply (rewrite option_bind_commute) \\<comment> \\<open>force a particular binder order\\<close>\napply (simp only: conj_comms)\ndone\n\ntext \\<open>\n  The next example shows that even monad normalisation alone is not confluent because \n  the term ordering prevents the reordering of \\<open>f A\\<close> with \\<open>f B\\<close>.\n  But if we change \\<open>A\\<close> to \\<open>E\\<close>, then the reordering works as expected.\n\\<close>\n\nlemma\n  \"do {a \\<leftarrow> f A; b \\<leftarrow> f B; c \\<leftarrow> D b; d \\<leftarrow> f C; F a c d} = \n   do {b \\<leftarrow> f B; c \\<leftarrow> D b; a \\<leftarrow> f A; d \\<leftarrow> f C; F a c d}\"\n  for f :: \"'b \\<Rightarrow> 'a option\" and D :: \"'a \\<Rightarrow> 'a option\"\n  apply(simp)? \\<comment> \\<open>no progress made\\<close>\n  apply(subst option_bind_commute, subst (2) option_bind_commute, rule refl)\n  done\n\nlemma\n  \"do {a \\<leftarrow> f E; b \\<leftarrow> f B; c \\<leftarrow> D b; d \\<leftarrow> f C; F a c d} = \n   do {b \\<leftarrow> f B; c \\<leftarrow> D b; a \\<leftarrow> f E; d \\<leftarrow> f C; F a c d}\"\n  for f :: \"'b \\<Rightarrow> 'a option\" and D :: \"'a \\<Rightarrow> 'a option\"\n  by simp\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Monad_Normalisation/Monad_Normalisation_Test.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953797290153, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.26175662303632063}}
{"text": "section {*FUNCTION\\_\\_LR\\_PARSER\\_\\_part4*}\ntheory\n  FUNCTION__LR_PARSER__part4\n\nimports\n  FUNCTION__LR_PARSER__part3\n\nbegin\n\nlemma no_shift_shift_conflicts1: \"\n  AF_LR_PARSER_input G F Do S' G' M P k\n  \\<Longrightarrow> y \\<in> cfgSTD_first G' (k - Suc 0) (\\<beta> @ liftB z)\n  \\<Longrightarrow> ya \\<in> cfgSTD_first G' (k - Suc 0) (\\<beta>' @ liftB za)\n  \\<Longrightarrow> \\<lparr>prod_lhs = A, prod_rhs = \\<alpha> @ teB aa # \\<beta>\\<rparr> \\<in> cfg_productions G\n  \\<Longrightarrow> \\<lparr>prod_lhs = Aa, prod_rhs = \\<alpha>' @ teB aa # \\<beta>'\\<rparr> \\<in> cfg_productions G\n  \\<Longrightarrow> \\<lparr>cfg_item_lhs = A, cfg_item_rhs1 = \\<alpha>, cfg_item_rhs2 = teB aa # \\<beta>, cfg_item_look_ahead = z\\<rparr> \\<in> valid_item_set G' k (teB Do # \\<delta>)\n  \\<Longrightarrow> \\<lparr>cfg_item_lhs = Aa, cfg_item_rhs1 = \\<alpha>', cfg_item_rhs2 = teB aa # \\<beta>', cfg_item_look_ahead = za\\<rparr> \\<in> valid_item_set G' k (teB Do # \\<delta>')\n  \\<Longrightarrow> last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>')) = last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>))\n  \\<Longrightarrow> (aa # y) \\<sqsubseteq> (aa # ya)\n  \\<Longrightarrow> y = ya\"\n  apply(simp add: prefix_def)\n  apply(clarsimp)\n  apply(rename_tac c)(*strict*)\n  apply(subgoal_tac \"valid_cfg G'\")\n   apply(rename_tac c)(*strict*)\n   prefer 2\n   apply(rule F_CFG_AUGMENT__makes_CFG)\n   apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n   apply(force)\n  apply(rename_tac c)(*strict*)\n  apply(subgoal_tac \"valid_dfa M\")\n   apply(rename_tac c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"G'\"\n      in Theorem6__27_a)\n     apply(rename_tac c)(*strict*)\n     apply(force)\n    apply(rename_tac c)(*strict*)\n    apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(force)\n   apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n  apply(rename_tac c)(*strict*)\n  apply(subgoal_tac \"some_step_from_every_configuration M\")\n   apply(rename_tac c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"G'\"\n      in F_LR_MACHINE_Complete)\n     apply(rename_tac c)(*strict*)\n     apply(force)\n    apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(force)\n   apply(rename_tac c)(*strict*)\n   apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n  apply(rename_tac c)(*strict*)\n  apply(subgoal_tac \"every_state_in_some_accessible_configuration M\")\n   apply(rename_tac c)(*strict*)\n   prefer 2\n   apply(rule F_LR_MACHINE_all_Connected)\n      apply(rename_tac c)(*strict*)\n      prefer 2\n      apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n      apply(force)\n     apply(rename_tac c)(*strict*)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n   apply(force)\n  apply(rename_tac c)(*strict*)\n  apply(subgoal_tac \"some_step_from_every_configuration M\")\n   apply(rename_tac c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"G'\"\n      in F_LR_MACHINE_Complete)\n     apply(rename_tac c)(*strict*)\n     apply(blast)+\n    apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(force)\n   apply(rename_tac c)(*strict*)\n   apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n  apply(rename_tac c)(*strict*)\n  apply(subgoal_tac \"valid_parser P\")\n   apply(rename_tac c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"G\"\n      in AF_LR_PARSER_valid_parser)\n         apply(rename_tac c)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n        apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n        apply(force)\n       apply(rename_tac c)(*strict*)\n       apply(force)\n      apply(rename_tac c)(*strict*)\n      apply(force)\n     apply(rename_tac c)(*strict*)\n     apply(force)\n    apply(rename_tac c)(*strict*)\n    apply(force)\n   apply(rename_tac c)(*strict*)\n   apply(simp add: AF_LR_PARSER_input_def)\n  apply(rename_tac c)(*strict*)\n  apply(subgoal_tac \"set (teB Do # \\<delta>') \\<subseteq> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')\")\n   apply(rename_tac c)(*strict*)\n   prefer 2\n   apply(rule viable_prefix_in_CFG)\n    apply(rename_tac c)(*strict*)\n    apply(simp add: AF_LR_PARSER_input_def)\n   apply(rename_tac c)(*strict*)\n   apply(rule Fact6_12__1)\n   apply(force)\n  apply(rename_tac c)(*strict*)\n  apply(subgoal_tac \"set (teB Do # \\<delta>) \\<subseteq> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')\")\n   apply(rename_tac c)(*strict*)\n   prefer 2\n   apply(rule viable_prefix_in_CFG)\n    apply(rename_tac c)(*strict*)\n    apply(simp add: AF_LR_PARSER_input_def)\n   apply(rename_tac c)(*strict*)\n   apply(rule Fact6_12__1)\n   apply(force)\n  apply(rename_tac c)(*strict*)\n  apply(subgoal_tac \"\\<lparr>cfg_item_lhs = A, cfg_item_rhs1 = \\<alpha>, cfg_item_rhs2 = teB aa # \\<beta>, cfg_item_look_ahead = z\\<rparr> \\<in> valid_item_set G' k (teB Do # \\<delta>')\")\n   apply(rename_tac c)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"valid_item_set G' k (teB Do # \\<delta>') = (if (teB Do # \\<delta>')=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>')))\")\n    apply(rename_tac c)(*strict*)\n    prefer 2\n    apply(rule F_LR_MACHINE_all_SOUND)\n          apply(rename_tac c)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(rename_tac c)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n         apply(force)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(force)\n      apply(rename_tac c)(*strict*)\n      apply(simp add: AF_LR_PARSER_input_def)\n     apply(rename_tac c)(*strict*)\n     apply(simp add: AF_LR_PARSER_input_def)\n     apply(rename_tac c)(*strict*)\n     prefer 2\n     apply (metis two_elements_construct_domain_setB)\n    apply(rename_tac c)(*strict*)\n    apply (metis two_elements_construct_domain_setA)\n   apply(rename_tac c)(*strict*)\n   apply(subgoal_tac \"valid_item_set G' k (teB Do # \\<delta>) = (if (teB Do # \\<delta>)=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>)))\")\n    apply(rename_tac c)(*strict*)\n    prefer 2\n    apply(rule F_LR_MACHINE_all_SOUND)\n          apply(rename_tac c)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(simp add: AF_LR_PARSER_input_def)\n         apply(force)\n        apply(rename_tac c)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(rename_tac c)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(rename_tac c)(*strict*)\n      apply(simp add: AF_LR_PARSER_input_def)\n     apply(rename_tac c)(*strict*)\n     prefer 2\n     apply (metis two_elements_construct_domain_setB)\n    apply(rename_tac c)(*strict*)\n    apply (metis two_elements_construct_domain_setA)\n   apply(rename_tac c)(*strict*)\n   apply(force)\n  apply(rename_tac c)(*strict*)\n  apply(thin_tac \"last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>')) = last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>))\")\n  apply(rename_tac c)(*strict*)\n  apply(thin_tac \"\\<lparr>cfg_item_lhs = A, cfg_item_rhs1 = \\<alpha>, cfg_item_rhs2 = teB aa # \\<beta>, cfg_item_look_ahead = z\\<rparr> \\<in> valid_item_set G' k (teB Do # \\<delta>)\")\n  apply(rename_tac c)(*strict*)\n  apply(thin_tac \"set (teB Do # \\<delta>) \\<subseteq> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')\")\n  apply(subgoal_tac \"length y \\<le> (k-Suc 0)\")\n   apply(rename_tac c)(*strict*)\n   prefer 2\n   apply(rule cfgSTD_firstk_shorter_than_k)\n   apply(force)\n  apply(rename_tac c)(*strict*)\n  apply(subgoal_tac \"length (y@c) \\<le> (k-Suc 0)\")\n   apply(rename_tac c)(*strict*)\n   prefer 2\n   apply(rule cfgSTD_firstk_shorter_than_k)\n   apply(force)\n  apply(rename_tac c)(*strict*)\n  apply(case_tac \"length y < k - Suc 0\")\n   apply(rename_tac c)(*strict*)\n   prefer 2\n   apply(clarsimp)\n  apply(rename_tac c)(*strict*)\n  apply(subgoal_tac \"suffix y z\")\n   apply(rename_tac c)(*strict*)\n   prefer 2\n   apply(rule cfgSTD_first_suffix_is_shorter)\n     apply(rename_tac c)(*strict*)\n     apply(force)\n    apply(rename_tac c)(*strict*)\n    apply(force)\n   apply(rename_tac c)(*strict*)\n   apply(force)\n  apply(rename_tac c)(*strict*)\n  apply(subgoal_tac \"length z < k - Suc 0\")\n   apply(rename_tac c)(*strict*)\n   prefer 2\n   apply(simp add: suffix_def)\n   apply(clarsimp)\n  apply(rename_tac c)(*strict*)\n  apply(simp add: valid_item_set_def valid_item_set_n_def)\n  apply(clarsimp)\n  apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n  apply(subgoal_tac \"d (Suc 0)= Some (pair (Some \\<lparr>prod_lhs=cfg_initial G',prod_rhs=[teB Do,teA (cfg_initial G),teB Do]\\<rparr>) \\<lparr>cfg_conf=[teB Do,teA (cfg_initial G),teB Do]\\<rparr>)\")\n   apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n   prefer 2\n   apply(rule F_CFG_AUGMENT__FirstStep)\n          apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n        apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n      apply(force)\n     apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n     apply (metis cfgRM_derivations_are_cfg_derivations)\n    apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n    apply(force)\n   apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n   apply(force)\n  apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n  apply(subgoal_tac \"da (Suc 0)= Some (pair (Some \\<lparr>prod_lhs=cfg_initial G',prod_rhs=[teB Do,teA (cfg_initial G),teB Do]\\<rparr>) \\<lparr>cfg_conf=[teB Do,teA (cfg_initial G),teB Do]\\<rparr>)\")\n   apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n   prefer 2\n   apply(rule F_CFG_AUGMENT__FirstStep)\n          apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n        apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n      apply(force)\n     apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n     apply (metis cfgRM_derivations_are_cfg_derivations)\n    apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n    apply(force)\n   apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n   apply(force)\n  apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n  apply(subgoal_tac \"aa \\<noteq> Do\")\n   apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"aa \\<in> cfg_events G\")\n    apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n    apply(subgoal_tac \"Do \\<notin> cfg_events G\")\n     apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n     apply(force)\n    apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n    apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def)\n    apply(clarsimp)\n    apply(subgoal_tac \"F_FRESH (cfg_events G) \\<notin> cfg_events G\")\n     apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n     apply(force)\n    apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n    apply(rule F_FRESH_is_fresh)\n    apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def)\n   apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n   apply(simp add: AF_LR_PARSER_input_def valid_cfg_def)\n   apply(erule conjE)+\n   apply(erule_tac\n      x=\"\\<lparr>prod_lhs = A, prod_rhs = \\<alpha> @ teB aa # \\<beta>\\<rparr>\"\n      and A=\"cfg_productions G\"\n      in ballE)\n    apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n   apply(clarsimp)\n   apply (metis elemInsetB set_mp_prime)\n  apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n  apply(case_tac n)\n   apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c na d da \\<delta> zb \\<delta>'a e1a e2a zaa)(*strict*)\n   apply(case_tac \"\\<delta>\")\n    apply(rename_tac c na d da \\<delta> zb \\<delta>'a e1a e2a zaa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c na d da \\<delta>'a e1a e2a zaa)(*strict*)\n    apply(case_tac \"\\<delta>'a\")\n     apply(rename_tac c na d da \\<delta>'a e1a e2a zaa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c na d da e1a e2a zaa)(*strict*)\n     apply(case_tac \"\\<delta>'\")\n      apply(rename_tac c na d da e1a e2a zaa)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac c na d da e1a e2a zaa a list)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c na d da e1a e2a zaa list)(*strict*)\n     apply(case_tac list)\n      apply(rename_tac c na d da e1a e2a zaa list)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac c na d da e1a e2a zaa list a lista)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac c na d da \\<delta>'a e1a e2a zaa a list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c na d da e1a e2a zaa list)(*strict*)\n    apply(case_tac list)\n     apply(rename_tac c na d da e1a e2a zaa list)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c na d da e1a e2a zaa)(*strict*)\n     apply(case_tac \"\\<alpha>\")\n      apply(rename_tac c na d da e1a e2a zaa)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac c na d da e1a e2a zaa a list)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c na d da e1a e2a zaa list)(*strict*)\n     apply(case_tac list)\n      apply(rename_tac c na d da e1a e2a zaa list)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac c na d da e1a e2a zaa list a lista)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac c na d da e1a e2a zaa list a lista)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c na d da e1a e2a zaa lista)(*strict*)\n    apply(case_tac lista)\n     apply(rename_tac c na d da e1a e2a zaa lista)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c na d da e1a e2a zaa)(*strict*)\n     apply(case_tac \"\\<alpha>\")\n      apply(rename_tac c na d da e1a e2a zaa)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac c na d da e1a e2a zaa a list)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac c na d da e1a e2a zaa lista a list)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac c na d da \\<delta> zb \\<delta>'a e1a e2a zaa a list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac c n na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat)(*strict*)\n  apply(case_tac na)\n   apply(rename_tac c na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a zaa nat)(*strict*)\n   apply(case_tac \"\\<delta>'a\")\n    apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a zaa nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c d da \\<delta> e1 e2 zb nat)(*strict*)\n    apply(case_tac \"\\<delta>\")\n     apply(rename_tac c d da \\<delta> e1 e2 zb nat)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c d da e1 e2 zb nat)(*strict*)\n     apply(case_tac \"\\<delta>'\")\n      apply(rename_tac c d da e1 e2 zb nat)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac c d da e1 e2 zb nat a list)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c d da e1 e2 zb nat list)(*strict*)\n     apply(case_tac list)\n      apply(rename_tac c d da e1 e2 zb nat list)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac c d da e1 e2 zb nat list a lista)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac c d da \\<delta> e1 e2 zb nat a list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c d da e1 e2 zb nat list)(*strict*)\n    apply(case_tac list)\n     apply(rename_tac c d da e1 e2 zb nat list)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c d da e1 e2 zb nat)(*strict*)\n     apply(case_tac \"\\<alpha>'\")\n      apply(rename_tac c d da e1 e2 zb nat)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac c d da e1 e2 zb nat a list)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c d da e1 e2 zb nat list)(*strict*)\n     apply(case_tac list)\n      apply(rename_tac c d da e1 e2 zb nat list)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac c d da e1 e2 zb nat list a lista)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac c d da e1 e2 zb nat list a lista)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c d da e1 e2 zb nat lista)(*strict*)\n    apply(case_tac lista)\n     apply(rename_tac c d da e1 e2 zb nat lista)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c d da e1 e2 zb nat)(*strict*)\n     apply(case_tac \"\\<alpha>'\")\n      apply(rename_tac c d da e1 e2 zb nat)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac c d da e1 e2 zb nat a list)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac c d da e1 e2 zb nat lista a list)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a zaa nat a list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac c na d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat nata)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat nata)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. set w \\<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \\<and> cfg_conf SSc=[teB Do]@w@[teB Do]\" for SSc)\n   apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat nata)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"d\"\n      and i=\"nat\"\n      in F_CFG_AUGMENT__reachableConf_of_certain_form)\n     apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat nata)(*strict*)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat nata)(*strict*)\n    apply(rule cfgSTD.derivation_initialI)\n     apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat nata)(*strict*)\n     apply(rule cfgRM_derivations_are_cfg_derivations)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat nata)(*strict*)\n    apply(simp add: cfg_initial_configurations_def get_configuration_def cfg_configurations_def valid_cfg_def)\n    apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n   apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat nata)(*strict*)\n   apply(force)\n  apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat nata)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. set w \\<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \\<and> cfg_conf SSc=[teB Do]@w@[teB Do]\" for SSc)\n   apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat nata)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"da\"\n      and i=\"nata\"\n      in F_CFG_AUGMENT__reachableConf_of_certain_form)\n     apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat nata)(*strict*)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat nata)(*strict*)\n    apply(rule cfgSTD.derivation_initialI)\n     apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat nata)(*strict*)\n     apply(rule cfgRM_derivations_are_cfg_derivations)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat nata)(*strict*)\n    apply(simp add: cfg_initial_configurations_def get_configuration_def cfg_configurations_def valid_cfg_def)\n    apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n   apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat nata)(*strict*)\n   apply(force)\n  apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat nata)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat nata w wa)(*strict*)\n  apply(case_tac \"\\<delta>\")\n   apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat nata w wa)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac c d da \\<delta> e1 e2 zb \\<delta>'a e1a e2a zaa nat nata w wa a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c d da e1 e2 zb \\<delta>' e1a e2a zaa nat nata w wa list)(*strict*)\n  apply(rename_tac w1)\n  apply(rename_tac c d da e1 e2 zb \\<delta>' e1a e2a zaa nat nata w wa w1)(*strict*)\n  apply(case_tac \"\\<delta>'\")\n   apply(rename_tac c d da e1 e2 zb \\<delta>' e1a e2a zaa nat nata w wa w1)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac c d da e1 e2 zb \\<delta>' e1a e2a zaa nat nata w wa w1 a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c d da e1 e2 zb e1a e2a zaa nat nata w wa w1 list)(*strict*)\n  apply(rename_tac w2)\n  apply(rename_tac c d da e1 e2 zb e1a e2a zaa nat nata w wa w1 w2)(*strict*)\n  apply(case_tac zb)\n   apply(rename_tac c d da e1 e2 zb e1a e2a zaa nat nata w wa w1 w2)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac c d da e1 e2 zb e1a e2a zaa nat nata w wa w1 w2 a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. zb = w' @ [x']\")\n   apply(rename_tac c d da e1 e2 zb e1a e2a zaa nat nata w wa w1 w2 a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac c d da e1 e2 zb e1a e2a zaa nat nata w wa w1 w2 a list)(*strict*)\n  apply(thin_tac \"zb=a#list\")\n  apply(clarsimp)\n  apply(rename_tac c d da e1 e2 e1a e2a zaa nat nata wa w1 w2 w')(*strict*)\n  apply(rename_tac w3)\n  apply(rename_tac c d da e1 e2 e1a e2a zaa nat nata wa w1 w2 w3)(*strict*)\n  apply(case_tac zaa)\n   apply(rename_tac c d da e1 e2 e1a e2a zaa nat nata wa w1 w2 w3)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac c d da e1 e2 e1a e2a zaa nat nata wa w1 w2 w3 a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. zaa = w' @ [x']\")\n   apply(rename_tac c d da e1 e2 e1a e2a zaa nat nata wa w1 w2 w3 a list)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a zaa nat nata wa w1 w2 w3 a list)(*strict*)\n  apply(thin_tac \"zaa=a#list\")\n  apply(clarsimp)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w')(*strict*)\n  apply(rename_tac w4)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4)(*strict*)\n  apply(simp add: suffix_def)\n  apply(clarsimp)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca)(*strict*)\n  apply(case_tac \"k - length w4\")\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca)(*strict*)\n   apply(clarsimp)\n   apply (metis Nat.add_0_right liftB_reflects_length add_Suc diff_is_0_eq' le_refl less_diff_conv add.commute not_less0 take_all_length)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>y. z = y@[Do]\")\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb)(*strict*)\n   prefer 2\n   apply(case_tac \"z\")\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb)(*strict*)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. z = w' @ [x']\")\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb a list)(*strict*)\n   apply(thin_tac \"z=a#list\")\n   apply(clarsimp)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb w' x')(*strict*)\n   apply(rule liftB_terminal_tail_equals)\n   apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb y)(*strict*)\n  apply(subgoal_tac \"w4=liftB y\")\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb y)(*strict*)\n   prefer 2\n   apply(rule liftB_terminal_butlast_equals)\n   apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 w4 ca natb y)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y)(*strict*)\n  apply(thin_tac \"liftB y @ [teB Do] = liftB (y @ [Do])\")\n  apply(case_tac \"k - length w3\")\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y)(*strict*)\n   prefer 2\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc)(*strict*)\n   apply(clarsimp)\n   apply(thin_tac \"ca @ y @ [Do] \\<in> cfgSTD_first G' (k - Suc 0) (\\<beta> @ liftB (y @ [Do]))\")\n   apply(simp add: cfgSTD_first_def)\n   apply(clarsimp)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*)\n   apply(subgoal_tac \"suffix x za\")\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*)\n    prefer 2\n    apply(rule liftB_creates_suffix)\n    apply(subgoal_tac \"\\<exists>d' e. cfgRM.derivation G' d' \\<and> maximum_of_domain d' n \\<and> d' 0 = Some (pair None \\<lparr>cfg_conf=\\<beta>' @ liftB za\\<rparr>) \\<and> d' n = Some (pair e \\<lparr>cfg_conf=liftB x\\<rparr>)\")\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*)\n     prefer 2\n     apply(rule_tac\n      d=\"db\"\n      in cfg_derivation_can_be_translated_to_cfgRM_derivation)\n          apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*)\n         apply(force)\n        apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*)\n        apply(simp add: maximum_of_domain_def)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*)\n       apply(force)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*)\n      apply(force)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*)\n     apply (metis setA_liftB)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n d' e)(*strict*)\n    apply(rule_tac\n      d=\"d'\"\n      and i=\"0\"\n      and j=\"n\"\n      in CFGRM_terminals_stay_at_end)\n         apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n d' e)(*strict*)\n         apply(force)\n        apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n d' e)(*strict*)\n        apply(force)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n d' e)(*strict*)\n       apply (metis setA_liftB)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n d' e)(*strict*)\n      apply(force)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n d' e)(*strict*)\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n d' e)(*strict*)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc x db e1b n)(*strict*)\n   apply(simp add: suffix_def)\n   apply(clarsimp)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n   apply(case_tac \"(k - Suc (length cb))\")\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"set cb \\<subseteq> cfg_events G\")\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n     apply(subgoal_tac \"Do \\<in> set cb\")\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n      apply(subgoal_tac \"Do \\<notin> set cb\")\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n       apply(force)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n      apply(rule_tac\n      B=\"cfg_events G\"\n      in nset_mp)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n       apply(force)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n      apply(simp add: AF_LR_PARSER_input_def two_elements_construct_domain_def)\n      apply(clarsimp)\n      apply(subgoal_tac \"F_FRESH (cfg_events G) \\<notin> cfg_events G\")\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n       apply(force)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n      apply(rule F_FRESH_is_fresh)\n      apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n     apply(rule_tac\n      A=\"set(take (k - Suc 0) cb)\"\n      in set_mp)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n      apply(rule List.set_take_subset)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n     apply(rule_tac\n      t=\"take (k - Suc 0) cb\"\n      and s=\"ca @ y @ Do # c\"\n      in ssubst)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n      apply(force)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n     apply(simp (no_asm))\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n    apply(rule liftB_in_two_elements_construct_domain_to_subset)\n    apply(subgoal_tac \"\\<exists>v. set v \\<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \\<and> (case e1b of None \\<Rightarrow> True|Some e' \\<Rightarrow> e' \\<in> cfg_productions G) \\<and> SSc=\\<lparr>cfg_conf = v @ liftB za\\<rparr>\" for SSc)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n     prefer 2\n     apply(rule_tac\n      n=\"n\"\n      and d=\"db\"\n      in CFG_preserves_partial_belongs)\n          apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n         prefer 2\n         apply(force)\n        apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n        prefer 2\n        apply(force)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n       apply(rule_tac\n      B=\"set (\\<alpha>' @ teB aa # \\<beta>')\"\n      in subset_trans)\n        apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n        apply(force)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n       apply(rule SetxBiElem_check_vs_set_two_elements_construct_domain_check)\n        apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n        apply(rule prod_rhs_in_cfg_events)\n         apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n         apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def)\n        apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n        apply(force)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n       apply(rule prod_rhs_in_nonterms)\n        apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n        apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n       apply(force)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb p)(*strict*)\n      apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def)\n      apply(clarsimp)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n      apply(subgoal_tac \"F_FRESH (cfg_nonterminals G) \\<notin> cfg_nonterminals G\")\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n       apply(force)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n      apply(rule F_FRESH_is_fresh)\n      apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb)(*strict*)\n    apply(erule exE)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb v)(*strict*)\n    apply(erule conjE)+\n    apply(subgoal_tac \"v=liftB cb\")\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb v)(*strict*)\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb v)(*strict*)\n    apply(clarsimp)\n    apply(simp add: liftB_commutes_over_concat)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"prefix (ca @ y @ [Do]) cb \\<or> prefix cb (ca @ y @ [Do])\")\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n    prefer 2\n    apply(rule mutual_prefix_prefix)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n    apply(subgoal_tac \"set cb \\<subseteq> cfg_events G\")\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n     apply(subgoal_tac \"Do \\<in> set cb\")\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n      apply(subgoal_tac \"Do \\<notin> set cb\")\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n       apply(force)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n      apply(rule_tac\n      B=\"cfg_events G\"\n      in nset_mp)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n       apply(force)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n      apply(simp add: AF_LR_PARSER_input_def two_elements_construct_domain_def)\n      apply(clarsimp)\n      apply(subgoal_tac \"F_FRESH (cfg_events G) \\<notin> cfg_events G\")\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n       apply(force)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n      apply(rule F_FRESH_is_fresh)\n      apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n     apply(simp add: prefix_def)\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n    apply(rule liftB_in_two_elements_construct_domain_to_subset)\n    apply(subgoal_tac \"\\<exists>v. set v \\<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \\<and> (case e1b of None \\<Rightarrow> True|Some e' \\<Rightarrow> e' \\<in> cfg_productions G) \\<and> SSc=\\<lparr>cfg_conf = v @ liftB za\\<rparr>\" for SSc)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n     prefer 2\n     apply(rule_tac\n      n=\"n\"\n      and d=\"db\"\n      in CFG_preserves_partial_belongs)\n          apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n         prefer 2\n         apply(force)\n        apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n        prefer 2\n        apply(force)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n       apply(rule_tac\n      B=\"set (\\<alpha>' @ teB aa # \\<beta>')\"\n      in subset_trans)\n        apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n        apply(force)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n       apply(rule SetxBiElem_check_vs_set_two_elements_construct_domain_check)\n        apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n        apply(rule prod_rhs_in_cfg_events)\n         apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n         apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def)\n        apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n        apply(force)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n       apply(rule prod_rhs_in_nonterms)\n        apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n        apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n       apply(force)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd p)(*strict*)\n      apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def)\n      apply(clarsimp)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n      apply(subgoal_tac \"F_FRESH (cfg_nonterminals G) \\<notin> cfg_nonterminals G\")\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n       apply(force)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n      apply(rule F_FRESH_is_fresh)\n      apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n    apply(erule exE)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd v)(*strict*)\n    apply(erule conjE)+\n    apply(subgoal_tac \"v=liftB cb\")\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd v)(*strict*)\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd v)(*strict*)\n    apply(clarsimp)\n    apply(simp add: liftB_commutes_over_concat)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd)(*strict*)\n   apply(simp add: prefix_def)\n   apply(clarsimp)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n   apply(case_tac cc)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n    apply(subgoal_tac \"set cb \\<subseteq> cfg_events G\")\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n     apply(subgoal_tac \"Do \\<in> set cb\")\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n      apply(subgoal_tac \"Do \\<notin> set cb\")\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n       apply(force)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n      apply(rule_tac\n      B=\"cfg_events G\"\n      in nset_mp)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n       apply(force)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n      apply(simp add: AF_LR_PARSER_input_def two_elements_construct_domain_def)\n      apply(clarsimp)\n      apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n natd)(*strict*)\n      apply(subgoal_tac \"F_FRESH (cfg_events G) \\<notin> cfg_events G\")\n       apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n natd)(*strict*)\n       apply(force)\n      apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n natd)(*strict*)\n      apply(rule F_FRESH_is_fresh)\n      apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n    apply(rule liftB_in_two_elements_construct_domain_to_subset)\n    apply(subgoal_tac \"\\<exists>v. set v \\<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \\<and> (case e1b of None \\<Rightarrow> True|Some e' \\<Rightarrow> e' \\<in> cfg_productions G) \\<and> SSc=\\<lparr>cfg_conf = v @ liftB za\\<rparr>\" for SSc)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n     prefer 2\n     apply(rule_tac\n      n=\"n\"\n      and d=\"db\"\n      in CFG_preserves_partial_belongs)\n          apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n         prefer 2\n         apply(force)\n        apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n        prefer 2\n        apply(force)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n       apply(rule_tac\n      B=\"set (\\<alpha>' @ teB aa # \\<beta>')\"\n      in subset_trans)\n        apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n        apply(force)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n       apply(rule SetxBiElem_check_vs_set_two_elements_construct_domain_check)\n        apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n        apply(rule prod_rhs_in_cfg_events)\n         apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n         apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def)\n        apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n        apply(force)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n       apply(rule prod_rhs_in_nonterms)\n        apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n        apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n       apply(force)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc p)(*strict*)\n      apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def)\n      apply(clarsimp)\n      apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n natd)(*strict*)\n      apply(subgoal_tac \"F_FRESH (cfg_nonterminals G) \\<notin> cfg_nonterminals G\")\n       apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n natd)(*strict*)\n       apply(force)\n      apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n natd)(*strict*)\n      apply(rule F_FRESH_is_fresh)\n      apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc)(*strict*)\n    apply(erule exE)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc v)(*strict*)\n    apply(erule conjE)+\n    apply(subgoal_tac \"v=liftB cb\")\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc v)(*strict*)\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc v)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n natd v)(*strict*)\n    apply(simp add: liftB_commutes_over_concat)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. cc = w' @ [x']\")\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd cc a list)(*strict*)\n   apply(thin_tac \"cc=a#list\")\n   apply(clarsimp)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w')(*strict*)\n   apply(subgoal_tac \"take (Suc natd) za = w'@Do#c\")\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w')(*strict*)\n    prefer 2\n    apply(rule sym)\n    apply(rule_tac\n      w=\"cb\"\n      in append_linj)\n    apply(metis concat_asso)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w')(*strict*)\n   apply(clarsimp)\n   apply(case_tac za)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w')(*strict*)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w' a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. za = w' @ [x']\")\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w' a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w' a list)(*strict*)\n   apply(thin_tac \"za=a#list\")\n   apply(clarsimp)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w' w'a x')(*strict*)\n   apply(subgoal_tac \"w3=liftB w'a\")\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w' w'a x')(*strict*)\n    apply(subgoal_tac \"Do=x'\")\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w' w'a x')(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a)(*strict*)\n     apply(case_tac c)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a)(*strict*)\n      apply(force)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a a list)(*strict*)\n     apply(subgoal_tac \"\\<exists>w' x'. c = w' @ [x']\")\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a a list)(*strict*)\n      prefer 2\n      apply(rule NonEmptyListHasTailElem)\n      apply(force)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a a list)(*strict*)\n     apply(thin_tac \"c=a#list\")\n     apply(clarsimp)\n     apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x')(*strict*)\n     apply(subgoal_tac \"teB Do \\<in> set (liftB w'a)\")\n      apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x')(*strict*)\n      apply(subgoal_tac \"teB Do \\<notin> set (liftB w'a)\")\n       apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x')(*strict*)\n       apply(force)\n      apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x')(*strict*)\n      apply(thin_tac \"teB Do \\<in> set (liftB w'a)\")\n      apply(rule_tac\n      B=\"two_elements_construct_domain (cfg_nonterminals G) (cfg_events G)\"\n      in nset_mp)\n       apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x')(*strict*)\n       apply(force)\n      apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x')(*strict*)\n      apply(simp add: two_elements_construct_domain_def AF_LR_PARSER_input_def)\n      apply(subgoal_tac \"F_FRESH (cfg_events G) \\<notin> cfg_events G\")\n       apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x')(*strict*)\n       apply(force)\n      apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x')(*strict*)\n      apply(rule F_FRESH_is_fresh)\n      apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def)\n     apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x')(*strict*)\n     apply(case_tac \"Suc natd - length w'a\")\n      apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x')(*strict*)\n      apply(clarsimp)\n      apply (metis set_liftB_insert take_reflects_mem)\n     apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'a w'b x' nate)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 ca natb y natc db e1b n cb natd w' w'b nate)(*strict*)\n     apply (metis head_in_set set_liftB_insert set_append_contra2)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w' w'a x')(*strict*)\n    apply(rule sym)\n    apply(rule liftB_terminal_tail_equals)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y natc db e1b n cb natd w' w'a x')(*strict*)\n   apply(rule liftB_terminal_butlast_equals)\n   apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y)(*strict*)\n  apply(clarsimp)\n  apply(thin_tac \"ca @ y @ [Do] \\<in> cfgSTD_first G' (k - Suc 0) (\\<beta> @ liftB (y @ [Do]))\")\n  apply(simp add: cfgSTD_first_def)\n  apply(clarsimp)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*)\n  apply(subgoal_tac \"suffix x za\")\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*)\n   prefer 2\n   apply(rule liftB_creates_suffix)\n   apply(subgoal_tac \"\\<exists>d' e. cfgRM.derivation G' d' \\<and> maximum_of_domain d' n \\<and> d' 0 = Some (pair None \\<lparr>cfg_conf=\\<beta>' @ liftB za\\<rparr>) \\<and> d' n = Some (pair e \\<lparr>cfg_conf=liftB x\\<rparr>)\")\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"db\"\n      in cfg_derivation_can_be_translated_to_cfgRM_derivation)\n         apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n        apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*)\n        apply(force)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*)\n       apply(simp add: maximum_of_domain_def)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*)\n      apply(force)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*)\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*)\n    apply (metis setA_liftB)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n d' e)(*strict*)\n   apply(rule_tac\n      d=\"d'\"\n      and i=\"0\"\n      and j=\"n\"\n      in CFGRM_terminals_stay_at_end)\n        apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n d' e)(*strict*)\n        apply(force)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n d' e)(*strict*)\n       apply(force)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n d' e)(*strict*)\n      apply (metis setA_liftB)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n d' e)(*strict*)\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n d' e)(*strict*)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n d' e)(*strict*)\n   apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y x db e1b n)(*strict*)\n  apply(simp add: suffix_def)\n  apply(clarsimp)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n  apply(case_tac \"(k - Suc (length cb))\")\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"set cb \\<subseteq> cfg_events G\")\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n  apply(subgoal_tac \"Do \\<in> set cb\")\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n   apply(subgoal_tac \"Do \\<notin> set cb\")\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n   apply(rule_tac\n    B=\"cfg_events G\"\n    in nset_mp)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n   apply(simp add: AF_LR_PARSER_input_def two_elements_construct_domain_def)\n   apply(clarsimp)\n   apply(subgoal_tac \"F_FRESH (cfg_events G) \\<notin> cfg_events G\")\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n   apply(rule F_FRESH_is_fresh)\n   apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n  apply(rule_tac\n    A=\"set(take (k - Suc 0) cb)\"\n    in set_mp)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n   apply(rule List.set_take_subset)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n  apply(rule_tac\n    t=\"take (k - Suc 0) cb\"\n    and s=\"ca @ y @ Do # c\"\n    in ssubst)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n   apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n  apply(simp (no_asm))\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n  apply(rule liftB_in_two_elements_construct_domain_to_subset)\n  apply(subgoal_tac \"\\<exists>v. set v \\<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \\<and> (case e1b of None \\<Rightarrow> True|Some e' \\<Rightarrow> e' \\<in> cfg_productions G) \\<and> SSc=\\<lparr>cfg_conf = v @ liftB za\\<rparr>\" for SSc)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n  prefer 2\n  apply(rule_tac\n    n=\"n\"\n    and d=\"db\"\n    in CFG_preserves_partial_belongs)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n    apply(rule_tac\n    B=\"set (\\<alpha>' @ teB aa # \\<beta>')\"\n    in subset_trans)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n    apply(rule SetxBiElem_check_vs_set_two_elements_construct_domain_check)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n     apply(rule prod_rhs_in_cfg_events)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n      apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n    apply(rule prod_rhs_in_nonterms)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n     apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb p)(*strict*)\n   apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def)\n   apply(clarsimp)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n   apply(subgoal_tac \"F_FRESH (cfg_nonterminals G) \\<notin> cfg_nonterminals G\")\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n   apply(rule F_FRESH_is_fresh)\n   apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n  apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb)(*strict*)\n  apply(erule exE)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb v)(*strict*)\n  apply(erule conjE)+\n  apply(subgoal_tac \"v=liftB cb\")\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb v)(*strict*)\n  apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb v)(*strict*)\n  apply(clarsimp)\n  apply(simp add: liftB_commutes_over_concat)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"prefix (ca @ y @ [Do]) cb \\<or> prefix cb (ca @ y @ [Do])\")\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n  prefer 2\n  apply(rule mutual_prefix_prefix)\n  apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n  apply(erule disjE)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n  apply(subgoal_tac \"set cb \\<subseteq> cfg_events G\")\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n  apply(subgoal_tac \"Do \\<in> set cb\")\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n   apply(subgoal_tac \"Do \\<notin> set cb\")\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n   apply(rule_tac\n    B=\"cfg_events G\"\n    in nset_mp)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n   apply(simp add: AF_LR_PARSER_input_def two_elements_construct_domain_def)\n   apply(clarsimp)\n   apply(subgoal_tac \"F_FRESH (cfg_events G) \\<notin> cfg_events G\")\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n   apply(rule F_FRESH_is_fresh)\n   apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n  apply(simp add: prefix_def)\n  apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n  apply(rule liftB_in_two_elements_construct_domain_to_subset)\n  apply(subgoal_tac \"\\<exists>v. set v \\<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \\<and> (case e1b of None \\<Rightarrow> True|Some e' \\<Rightarrow> e' \\<in> cfg_productions G) \\<and> SSc=\\<lparr>cfg_conf = v @ liftB za\\<rparr>\" for SSc)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n  prefer 2\n  apply(rule_tac\n    n=\"n\"\n    and d=\"db\"\n    in CFG_preserves_partial_belongs)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n    apply(rule_tac\n    B=\"set (\\<alpha>' @ teB aa # \\<beta>')\"\n    in subset_trans)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n    apply(rule SetxBiElem_check_vs_set_two_elements_construct_domain_check)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n     apply(rule prod_rhs_in_cfg_events)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n      apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n    apply(rule prod_rhs_in_nonterms)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n     apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc p)(*strict*)\n   apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def)\n   apply(clarsimp)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n   apply(subgoal_tac \"F_FRESH (cfg_nonterminals G) \\<notin> cfg_nonterminals G\")\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n   apply(rule F_FRESH_is_fresh)\n   apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n  apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n  apply(erule exE)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc v)(*strict*)\n  apply(erule conjE)+\n  apply(subgoal_tac \"v=liftB cb\")\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc v)(*strict*)\n  apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc v)(*strict*)\n  apply(clarsimp)\n  apply(simp add: liftB_commutes_over_concat)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc)(*strict*)\n  apply(simp add: prefix_def)\n  apply(clarsimp)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n  apply(case_tac cc)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n  apply(subgoal_tac \"set cb \\<subseteq> cfg_events G\")\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n  apply(subgoal_tac \"Do \\<in> set cb\")\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n   apply(subgoal_tac \"Do \\<notin> set cb\")\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n   apply(rule_tac\n    B=\"cfg_events G\"\n    in nset_mp)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n   apply(simp add: AF_LR_PARSER_input_def two_elements_construct_domain_def)\n   apply(clarsimp)\n   apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n natc)(*strict*)\n   apply(subgoal_tac \"F_FRESH (cfg_events G) \\<notin> cfg_events G\")\n    apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n natc)(*strict*)\n    apply(force)\n   apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n natc)(*strict*)\n   apply(rule F_FRESH_is_fresh)\n   apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n  apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n  apply(rule liftB_in_two_elements_construct_domain_to_subset)\n  apply(subgoal_tac \"\\<exists>v. set v \\<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \\<and> (case e1b of None \\<Rightarrow> True|Some e' \\<Rightarrow> e' \\<in> cfg_productions G) \\<and> SSc=\\<lparr>cfg_conf = v @ liftB za\\<rparr>\" for SSc)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n  prefer 2\n  apply(rule_tac\n    n=\"n\"\n    and d=\"db\"\n    in CFG_preserves_partial_belongs)\n       apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n    apply(rule_tac\n    B=\"set (\\<alpha>' @ teB aa # \\<beta>')\"\n    in subset_trans)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n    apply(rule SetxBiElem_check_vs_set_two_elements_construct_domain_check)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n     apply(rule prod_rhs_in_cfg_events)\n      apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n      apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n    apply(rule prod_rhs_in_nonterms)\n     apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n     apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def)\n    apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc p)(*strict*)\n   apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def)\n   apply(clarsimp)\n   apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n natc)(*strict*)\n   apply(subgoal_tac \"F_FRESH (cfg_nonterminals G) \\<notin> cfg_nonterminals G\")\n    apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n natc)(*strict*)\n    apply(force)\n   apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n natc)(*strict*)\n   apply(rule F_FRESH_is_fresh)\n   apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n  apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc)(*strict*)\n  apply(erule exE)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc v)(*strict*)\n  apply(erule conjE)+\n  apply(subgoal_tac \"v=liftB cb\")\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc v)(*strict*)\n  apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc v)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n natc v)(*strict*)\n  apply(simp add: liftB_commutes_over_concat)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. cc = w' @ [x']\")\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc a list)(*strict*)\n  prefer 2\n  apply(rule NonEmptyListHasTailElem)\n  apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc cc a list)(*strict*)\n  apply(thin_tac \"cc=a#list\")\n  apply(clarsimp)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w')(*strict*)\n  apply(subgoal_tac \"take (Suc natc) za = w'@Do#c\")\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w')(*strict*)\n  prefer 2\n  apply(rule sym)\n  apply(rule_tac\n    w=\"cb\"\n    in append_linj)\n  apply(metis concat_asso)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w')(*strict*)\n  apply(clarsimp)\n  apply(case_tac za)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w')(*strict*)\n  apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. za = w' @ [x']\")\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' a list)(*strict*)\n  prefer 2\n  apply(rule NonEmptyListHasTailElem)\n  apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' a list)(*strict*)\n  apply(thin_tac \"za=a#list\")\n  apply(clarsimp)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x')(*strict*)\n  apply(case_tac c)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x')(*strict*)\n  apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' a list)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. c = w' @ [x']\")\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' a list)(*strict*)\n  prefer 2\n  apply(rule NonEmptyListHasTailElem)\n  apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' a list)(*strict*)\n  apply(thin_tac \"c=a#list\")\n  apply(clarsimp)\n  apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*)\n  apply(subgoal_tac \"teB Do \\<in> set (liftB w'a)\")\n  apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*)\n  apply(subgoal_tac \"teB Do \\<notin> set (liftB w'a)\")\n  apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*)\n  apply(force)\n  apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*)\n  apply(thin_tac \"teB Do \\<in> set (liftB w'a)\")\n  apply(rule_tac\n    B=\"set(liftB (w'a @ [x']))\"\n    in nset_mp)\n  apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*)\n  apply (smt set_liftB_commute set_app_subset)\n  apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*)\n  apply(rule_tac\n    B=\"set(take k w3)\"\n    in nset_mp)\n  apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*)\n  apply(force)\n  apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*)\n  apply(rule_tac\n    B=\"set w3\"\n    in nset_mp)\n  apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*)\n  apply(rule List.set_take_subset)\n  apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*)\n  apply(rule_tac\n    B=\"two_elements_construct_domain (cfg_nonterminals G) (cfg_events G)\"\n    in nset_mp)\n  apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*)\n  apply(force)\n  apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*)\n  apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def two_elements_construct_domain_def)\n  apply(clarsimp)\n  apply(subgoal_tac \"F_FRESH (cfg_events G) \\<notin> cfg_events G\")\n  apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*)\n  apply(force)\n  apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*)\n  apply(rule F_FRESH_is_fresh)\n  apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def)\n  apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*)\n  apply(case_tac \"Suc natc - length w'a\")\n  apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a)(*strict*)\n  apply(clarsimp)\n  apply (metis set_liftB_insert take_reflects_mem)\n  apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'a x' w'b x'a natd)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d da e1 e2 e1a e2a nat nata w1 w2 w3 ca natb y db e1b n cb natc w' w'b x'a natd)(*strict*)\n  apply (metis head_in_set set_liftB_insert set_append_contra2)\n  done\n\ntheorem no_shift_shift_conflicts: \"\n  AF_LR_PARSER_input G F Do S' G' M P k\n  \\<Longrightarrow> (parser_marker P) r1 = Some None\n  \\<Longrightarrow> (parser_marker P) r2 = Some None\n  \\<Longrightarrow> r1 \\<in> parser_rules P\n  \\<Longrightarrow> r2 \\<in> parser_rules P\n  \\<Longrightarrow> rule_lpop r2 \\<sqsupseteq> rule_lpop r1 \\<or> rule_lpop r1 \\<sqsupseteq> rule_lpop r2\n  \\<Longrightarrow> rule_rpop r1 \\<sqsubseteq> rule_rpop r2 \\<or> rule_rpop r2 \\<sqsubseteq> rule_rpop r1\n  \\<Longrightarrow> r1 = r2\"\n  apply(case_tac r1)\n  apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n  apply(subgoal_tac \" \\<exists>q\\<delta> y \\<beta> z A \\<alpha> a \\<delta>. y \\<in> (cfgSTD_first G' (k- 1) (\\<beta>@(liftB z))) \\<and> \\<lparr>prod_lhs=A,prod_rhs=\\<alpha>@(teB a)#\\<beta>\\<rparr> \\<in> cfg_productions G \\<and> q\\<delta>=last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do#\\<delta>)) \\<and> \\<lparr>cfg_item_lhs = A,cfg_item_rhs1 = \\<alpha>,cfg_item_rhs2 = (teB a)#\\<beta>,cfg_item_look_ahead = z\\<rparr> \\<in> valid_item_set G' k (teB Do#\\<delta>) \\<and> rule_lpopa=[q\\<delta>] \\<and> rule_rpopa=a#y \\<and> rule_lpush=[q\\<delta>,F_DFA_GOTO M q\\<delta> (teB a)] \\<and> rule_rpush=y\")\n   apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n   prefer 2\n   apply(rule_tac\n      S'=\"S'\"\n      and Do=\"Do\"\n      and G'=\"G'\"\n      and G=\"G\"\n      in X6_3_InformationOnRules_shift2)\n            apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n            apply(simp add: AF_LR_PARSER_input_def)\n           apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n           apply(simp add: AF_LR_PARSER_input_def)\n           apply(force)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n        apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n      apply(force)\n     apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n     apply(force)\n    apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n    apply(simp add: AF_LR_PARSER_input_def)\n   apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n   apply(simp add: AF_LR_PARSER_input_def)\n  apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n  apply(case_tac r2)\n  apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n  apply(subgoal_tac \" \\<exists>q\\<delta> y \\<beta> z A \\<alpha> a \\<delta>. y \\<in> (cfgSTD_first G' (k- 1) (\\<beta>@(liftB z))) \\<and> \\<lparr>prod_lhs=A,prod_rhs=\\<alpha>@(teB a)#\\<beta>\\<rparr> \\<in> cfg_productions G \\<and> q\\<delta>=last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do#\\<delta>)) \\<and> \\<lparr>cfg_item_lhs = A,cfg_item_rhs1 = \\<alpha>,cfg_item_rhs2 = (teB a)#\\<beta>,cfg_item_look_ahead = z\\<rparr> \\<in> valid_item_set G' k (teB Do#\\<delta>) \\<and> rule_lpopaa=[q\\<delta>] \\<and> rule_rpopaa=a#y \\<and> rule_lpusha=[q\\<delta>,F_DFA_GOTO M q\\<delta> (teB a)] \\<and> rule_rpusha=y\")\n   apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n   prefer 2\n   apply(rule_tac\n      S'=\"S'\"\n      and Do=\"Do\"\n      and G'=\"G'\"\n      and G=\"G\"\n      in X6_3_InformationOnRules_shift2)\n            apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n            apply(simp add: AF_LR_PARSER_input_def)\n           apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n           apply(simp add: AF_LR_PARSER_input_def)\n           apply(force)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n        apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n      apply(force)\n     apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n     apply(force)\n    apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n    apply(simp add: AF_LR_PARSER_input_def)\n   apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n   apply(simp add: AF_LR_PARSER_input_def)\n  apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> a Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n  apply(subgoal_tac \"a=aa\")\n   apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> a Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n   prefer 2\n   apply(erule_tac\n      P=\"(a # y) \\<sqsubseteq> (aa # ya)\"\n      in disjE)\n    apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> a Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n    apply(simp add: prefix_def)\n   apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> a Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n   apply(simp add: prefix_def)\n  apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> a Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n  apply(clarsimp)\n  apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n  apply(subgoal_tac \"[last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>'))] = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>))]\")\n   apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n   prefer 2\n   apply(erule_tac\n      P=\"[last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>'))] \\<sqsupseteq> [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>))]\"\n      in disjE)\n    apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n    apply(simp add: suffix_def)\n   apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n   apply(simp add: suffix_def)\n  apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n  apply(clarsimp)\n  apply(thin_tac \"parser_marker P \\<lparr>rule_lpop = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>))], rule_rpop = aa # y, rule_lpush = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>)), F_DFA_GOTO M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>))) (teB aa)], rule_rpush = y\\<rparr> = Some None\")\n  apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n  apply(thin_tac \"parser_marker P \\<lparr>rule_lpop = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>))], rule_rpop = aa # ya, rule_lpush = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>)), F_DFA_GOTO M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>))) (teB aa)], rule_rpush = ya\\<rparr> = Some None\")\n  apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n  apply(thin_tac \"\\<lparr>rule_lpop = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>))], rule_rpop = aa # y, rule_lpush = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>)), F_DFA_GOTO M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>))) (teB aa)], rule_rpush = y\\<rparr> \\<in> parser_rules P\")\n  apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n  apply(thin_tac \"\\<lparr>rule_lpop = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>))], rule_rpop = aa # ya, rule_lpush = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>)), F_DFA_GOTO M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>))) (teB aa)], rule_rpush = ya\\<rparr> \\<in> parser_rules P\")\n  apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n  apply(thin_tac \"[last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>))] \\<sqsupseteq> [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>))]\")\n  apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n  apply(erule disjE)\n   apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n   apply(rule no_shift_shift_conflicts1)\n           apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n           apply(force)\n          apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n          apply(force)\n         apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n         apply(force)\n        apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n        apply(force)\n       apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n       apply(force)\n      apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n      apply(force)\n     apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n     apply(force)\n    apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n    apply(force)\n   apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n   apply(force)\n  apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n  apply(rule sym)\n  apply(rule no_shift_shift_conflicts1)\n          apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n          apply(force)\n         apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n         apply(force)\n        apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n        apply(force)\n       apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n       apply(force)\n      apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n      apply(force)\n     apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n     apply(force)\n    apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n    apply(force)\n   apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n   apply(force)\n  apply(rename_tac y ya \\<beta> \\<beta>' z za A \\<alpha> Aa \\<alpha>' aa \\<delta> \\<delta>')(*strict*)\n  apply(force)\n  done\n\nlemma no_reduce_reduce_conflicts_hlp: \"\n  AF_LR_PARSER_input G F Do S' G' M P k\n  \\<Longrightarrow> valid_cfg G'\n  \\<Longrightarrow> \\<lparr>cfg_item_lhs = A1, cfg_item_rhs1 = w1, cfg_item_rhs2 = [], cfg_item_look_ahead = y1\\<rparr> \\<in> valid_item_set G' k (teB Do # w)\n  \\<Longrightarrow> \\<lparr>cfg_item_lhs = A2, cfg_item_rhs1 = w2, cfg_item_rhs2 = [], cfg_item_look_ahead = y2\\<rparr> \\<in> valid_item_set G' k (teB Do # w)\n  \\<Longrightarrow> prefix y1 y2\n  \\<Longrightarrow> y1 = y2\"\n  apply(simp add: valid_item_set_def valid_item_set_n_def prefix_def)\n  apply(clarsimp)\n  apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d (Suc 0) = Some (pair e c)\")\n   apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc n\"\n      in cfgRM.pre_some_position_is_some_position)\n     apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za)(*strict*)\n     apply(force)\n    apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za)(*strict*)\n    apply(force)\n   apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za)(*strict*)\n   apply(force)\n  apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. da (Suc 0) = Some (pair e c)\")\n   apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc na\"\n      in cfgRM.pre_some_position_is_some_position)\n     apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za)(*strict*)\n     apply(force)\n    apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za)(*strict*)\n    apply(force)\n   apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za)(*strict*)\n   apply(force)\n  apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n  apply(subgoal_tac \"teB Do \\<notin> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G)\")\n   apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n   prefer 2\n   apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def two_elements_construct_domain_def)\n   apply(clarsimp)\n   apply(rule conjI)\n    apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n    apply(force)\n   apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"F_FRESH (cfg_events G) \\<notin> cfg_events G\")\n    apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n    apply(force)\n   apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n   apply(rule F_FRESH_is_fresh)\n   apply(simp add: F_LR_MACHINE_def F_CFG_AUGMENT_def two_elements_construct_domain_def valid_cfg_def)\n  apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. set w \\<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \\<and> cfg_conf ca=[teB Do]@w@[teB Do]\")\n   apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"d\"\n      and i=\"0\"\n      in F_CFG_AUGMENT__reachableConf_of_certain_form)\n     apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n    apply(rule cfgSTD.derivation_initialI)\n     apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n     apply(rule cfgRM_derivations_are_cfg_derivations)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n    apply(simp add: cfg_initial_configurations_def get_configuration_def cfg_configurations_def valid_cfg_def)\n    apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n   apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n   apply(force)\n  apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. set w \\<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \\<and> cfg_conf cb=[teB Do]@w@[teB Do]\")\n   apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"da\"\n      and i=\"0\"\n      in F_CFG_AUGMENT__reachableConf_of_certain_form)\n     apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n    apply(rule cfgSTD.derivation_initialI)\n     apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n     apply(rule cfgRM_derivations_are_cfg_derivations)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n    apply(simp add: cfg_initial_configurations_def get_configuration_def cfg_configurations_def valid_cfg_def)\n    apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n   apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n   apply(force)\n  apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. set w \\<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \\<and> cfg_conf \\<lparr>cfg_conf = \\<delta> @ w1 @ z\\<rparr>=[teB Do]@w@[teB Do]\")\n   apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"d\"\n      and i=\"n\"\n      in F_CFG_AUGMENT__reachableConf_of_certain_form)\n     apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n    apply(rule cfgSTD.derivation_initialI)\n     apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n     apply(rule cfgRM_derivations_are_cfg_derivations)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n    apply(simp add: cfg_initial_configurations_def get_configuration_def cfg_configurations_def valid_cfg_def)\n    apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n   apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n   apply(force)\n  apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. set w \\<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \\<and> cfg_conf \\<lparr>cfg_conf = \\<delta>' @ w2 @ za\\<rparr>=[teB Do]@w@[teB Do]\")\n   apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"da\"\n      and i=\"na\"\n      in F_CFG_AUGMENT__reachableConf_of_certain_form)\n     apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n    apply(rule cfgSTD.derivation_initialI)\n     apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n     apply(rule cfgRM_derivations_are_cfg_derivations)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n    apply(simp add: cfg_initial_configurations_def get_configuration_def cfg_configurations_def valid_cfg_def)\n    apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n   apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n   apply(force)\n  apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb wa waa wb wc)(*strict*)\n  apply(case_tac ca)\n  apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb wa waa wb wc cfg_confa)(*strict*)\n  apply(case_tac cb)\n  apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea ca cb wa waa wb wc cfg_confa cfg_confaa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc)(*strict*)\n  apply(case_tac n)\n   apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac na c d da \\<delta> e2 z \\<delta>' e1a e2a za ea wa wb wc)(*strict*)\n   apply(case_tac \"\\<delta>\")\n    apply(rename_tac na c d da \\<delta> e2 z \\<delta>' e1a e2a za ea wa wb wc)(*strict*)\n    prefer 2\n    apply(rename_tac na c d da \\<delta> e2 z \\<delta>' e1a e2a za ea wa wb wc a list)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac na c d da \\<delta> e2 z \\<delta>' e1a e2a za ea wa wb wc)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac na c d da e2 \\<delta>' e1a e2a za ea wa wb wc)(*strict*)\n   apply(case_tac y1)\n    apply(rename_tac na c d da e2 \\<delta>' e1a e2a za ea wa wb wc)(*strict*)\n    prefer 2\n    apply(rename_tac na c d da e2 \\<delta>' e1a e2a za ea wa wb wc a list)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac na c d da e2 \\<delta>' e1a e2a za ea wa wb wc)(*strict*)\n   apply(clarsimp)\n   apply(case_tac na)\n    apply(rename_tac na c d da e2 \\<delta>' e1a e2a za ea wa wb wc)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c d da e2 \\<delta>' e2a za wb wc)(*strict*)\n    apply(case_tac \"\\<delta>'\")\n     apply(rename_tac c d da e2 \\<delta>' e2a za wb wc)(*strict*)\n     prefer 2\n     apply(rename_tac c d da e2 \\<delta>' e2a za wb wc a list)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac c d da e2 \\<delta>' e2a za wb wc)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c d da e2 e2a wc)(*strict*)\n    apply(case_tac c)\n     apply(rename_tac c d da e2 e2a wc)(*strict*)\n     apply(force)\n    apply(rename_tac c d da e2 e2a wc a list)(*strict*)\n    apply(force)\n   apply(rename_tac na c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat)(*strict*)\n   apply(subgoal_tac \"\\<exists>w. set w \\<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \\<and> cfg_conf \\<lparr>cfg_conf = \\<delta>' @ teA A2 # za\\<rparr>=[teB Do]@w@[teB Do]\")\n    apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"da\"\n      and i=\"nat\"\n      in F_CFG_AUGMENT__reachableConf_of_certain_form)\n      apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat)(*strict*)\n      apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n     apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat)(*strict*)\n     apply(rule cfgSTD.derivation_initialI)\n      apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat)(*strict*)\n      apply(rule cfgRM_derivations_are_cfg_derivations)\n      apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n     apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat)(*strict*)\n     apply(simp add: cfg_initial_configurations_def get_configuration_def cfg_configurations_def valid_cfg_def)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat)(*strict*)\n    apply(force)\n   apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat)(*strict*)\n   apply(subgoal_tac \"\\<exists>w. set w \\<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \\<and> cfg_conf \\<lparr>cfg_conf = teB Do # wc @ [teB Do]\\<rparr>=[teB Do]@w@[teB Do]\")\n    apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"da\"\n      and i=\"Suc nat\"\n      in F_CFG_AUGMENT__reachableConf_of_certain_form)\n      apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat)(*strict*)\n      apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n     apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat)(*strict*)\n     apply(rule cfgSTD.derivation_initialI)\n      apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat)(*strict*)\n      apply(rule cfgRM_derivations_are_cfg_derivations)\n      apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n     apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat)(*strict*)\n     apply(simp add: cfg_initial_configurations_def get_configuration_def cfg_configurations_def valid_cfg_def)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat)(*strict*)\n    apply(force)\n   apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat w)(*strict*)\n   apply(case_tac w2)\n    apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c d da e2 e1a e2a za ea wa wb wc nat w)(*strict*)\n    apply(case_tac za)\n     apply(rename_tac c d da e2 e1a e2a za ea wa wb wc nat w)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac c d da e2 e1a e2a za ea wa wb wc nat w a list)(*strict*)\n    apply(subgoal_tac \"\\<exists>w' x'. za = w' @ [x']\")\n     apply(rename_tac c d da e2 e1a e2a za ea wa wb wc nat w a list)(*strict*)\n     prefer 2\n     apply(rule NonEmptyListHasTailElem)\n     apply(force)\n    apply(rename_tac c d da e2 e1a e2a za ea wa wb wc nat w a list)(*strict*)\n    apply(thin_tac \"za=a#list\")\n    apply(clarsimp)\n   apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat w a list)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. w2 = w' @ [x']\")\n    apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat w a list)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat w a list)(*strict*)\n   apply(thin_tac \"w2=a#list\")\n   apply(clarsimp)\n   apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat w w')(*strict*)\n   apply(case_tac \"\\<delta>'\")\n    apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat w w')(*strict*)\n    apply(clarsimp)\n   apply(rename_tac c d da e2 \\<delta>' e1a e2a za ea wa wb wc nat w w' a list)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d da e2 e1a e2a za ea wa wc nat w w' list)(*strict*)\n   apply(case_tac za)\n    apply(rename_tac c d da e2 e1a e2a za ea wa wc nat w w' list)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac c d da e2 e1a e2a za ea wa wc nat w w' list a lista)(*strict*)\n   apply(subgoal_tac \"\\<exists>w' x'. za = w' @ [x']\")\n    apply(rename_tac c d da e2 e1a e2a za ea wa wc nat w w' list a lista)(*strict*)\n    prefer 2\n    apply(rule NonEmptyListHasTailElem)\n    apply(force)\n   apply(rename_tac c d da e2 e1a e2a za ea wa wc nat w w' list a lista)(*strict*)\n   apply(thin_tac \"za=a#lista\")\n   apply(clarsimp)\n  apply(rename_tac n na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat)(*strict*)\n  apply(case_tac na)\n   apply(rename_tac na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e2a za e wa wb wc nat)(*strict*)\n   apply(case_tac \"\\<delta>'\")\n    apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e2a za e wa wb wc nat)(*strict*)\n    prefer 2\n    apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e2a za e wa wb wc nat a list)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e2a za e wa wb wc nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d da \\<delta> e1 e2 z e2a e w wb wc nat)(*strict*)\n   apply(case_tac c)\n    apply(rename_tac c d da \\<delta> e1 e2 z e2a e w wb wc nat)(*strict*)\n    prefer 2\n    apply(rename_tac c d da \\<delta> e1 e2 z e2a e w wb wc nat a list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d da \\<delta> e1 e2 z e2a e w wb wc nat a list)(*strict*)\n    apply (metis Nil_is_append_conv liftB_reflects_Nil list.simps(3))\n   apply(rename_tac c d da \\<delta> e1 e2 z e2a e w wb wc nat)(*strict*)\n   apply(force)\n  apply(rename_tac na c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. set w \\<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \\<and> cfg_conf \\<lparr>cfg_conf = \\<delta> @ teA A1 # z\\<rparr>=[teB Do]@w@[teB Do]\")\n   apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"d\"\n      and i=\"nat\"\n      in F_CFG_AUGMENT__reachableConf_of_certain_form)\n     apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*)\n    apply(rule cfgSTD.derivation_initialI)\n     apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*)\n     apply(rule cfgRM_derivations_are_cfg_derivations)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*)\n    apply(simp add: cfg_initial_configurations_def get_configuration_def cfg_configurations_def valid_cfg_def)\n    apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n   apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*)\n   apply(force)\n  apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*)\n  apply(subgoal_tac \"\\<exists>w. set w \\<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \\<and> cfg_conf \\<lparr>cfg_conf = \\<delta>' @ teA A2 # za\\<rparr>=[teB Do]@w@[teB Do]\")\n   apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"da\"\n      and i=\"nata\"\n      in F_CFG_AUGMENT__reachableConf_of_certain_form)\n     apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*)\n    apply(rule cfgSTD.derivation_initialI)\n     apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*)\n     apply(rule cfgRM_derivations_are_cfg_derivations)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*)\n    apply(simp add: cfg_initial_configurations_def get_configuration_def cfg_configurations_def valid_cfg_def)\n    apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n   apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*)\n   apply(force)\n  apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat nata)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat nata wd we)(*strict*)\n  apply(case_tac \"\\<delta>\")\n   apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat nata wd we)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac c d da \\<delta> e1 e2 z \\<delta>' e1a e2a za e ea wa waa wb wc nat nata wd we a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c d da e1 e2 z \\<delta>' e1a e2a za e ea w wa wb wc nat nata wd we list)(*strict*)\n  apply(case_tac \"\\<delta>'\")\n   apply(rename_tac c d da e1 e2 z \\<delta>' e1a e2a za e ea w wa wb wc nat nata wd we list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac c d da e1 e2 z \\<delta>' e1a e2a za e ea w wa wb wc nat nata wd we list a lista)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c d da e1 e2 z e1a e2a za e ea w wa wb wc nat nata wd we list lista)(*strict*)\n  apply(case_tac \"z\")\n   apply(rename_tac c d da e1 e2 z e1a e2a za e ea w wa wb wc nat nata wd we list lista)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac c d da e1 e2 z e1a e2a za e ea w wa wb wc nat nata wd we list lista a listb)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. z = w' @ [x']\")\n   apply(rename_tac c d da e1 e2 z e1a e2a za e ea w wa wb wc nat nata wd we list lista a listb)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac c d da e1 e2 z e1a e2a za e ea w wa wb wc nat nata wd we list lista a listb)(*strict*)\n  apply(thin_tac \"z=a#listb\")\n  apply(clarsimp)\n  apply(rename_tac c d da e1 e2 e1a e2a za e ea w wa wc nat nata we list lista w')(*strict*)\n  apply(case_tac \"za\")\n   apply(rename_tac c d da e1 e2 e1a e2a za e ea w wa wc nat nata we list lista w')(*strict*)\n   apply(clarsimp)\n  apply(rename_tac c d da e1 e2 e1a e2a za e ea w wa wc nat nata we list lista w' a listb)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. za = w' @ [x']\")\n   apply(rename_tac c d da e1 e2 e1a e2a za e ea w wa wc nat nata we list lista w' a listb)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a za e ea w wa wc nat nata we list lista w' a listb)(*strict*)\n  apply(thin_tac \"za=a#listb\")\n  apply(clarsimp)\n  apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a)(*strict*)\n  apply(case_tac \"k-length w'\")\n   apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a)(*strict*)\n   apply(clarsimp)\n   apply (metis liftB_reflects_length self_append_conv takeShorter take_all take_all_length take_append take_append_prime)\n  apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb)(*strict*)\n  apply(clarsimp)\n  apply(case_tac y1)\n   apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb a listb)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. y1 = w' @ [x']\")\n   apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb a listb)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb a listb)(*strict*)\n  apply(thin_tac \"y1=a#listb\")\n  apply(clarsimp)\n  apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb w'b x')(*strict*)\n  apply(subgoal_tac \"x'=Do\")\n   apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb w'b x')(*strict*)\n   prefer 2\n   apply(rule_tac\n      v=\"w'\"\n      and w=\"w'b\"\n      in liftB_terminal_tail_equals)\n   apply(blast)\n  apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb w'b x')(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb w'b)(*strict*)\n  apply(subgoal_tac \"w'=liftB w'b\")\n   apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb w'b)(*strict*)\n   prefer 2\n   apply(rule liftB_terminal_butlast_equals)\n   apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w' w'a natb w'b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b)(*strict*)\n  apply(case_tac \"k - length w'a\")\n   apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"teB Do \\<in> set w'a\")\n    apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b)(*strict*)\n    apply(subgoal_tac \"teB Do \\<notin> set w'a\")\n     apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b)(*strict*)\n     apply(force)\n    apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b)(*strict*)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b)(*strict*)\n   apply(rule_tac\n      A=\"set(take k w'a)\"\n      in set_mp)\n    apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b)(*strict*)\n    apply(rule List.set_take_subset)\n   apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b)(*strict*)\n   apply(rule_tac\n      A=\"set(liftB (w'b @ Do # c))\"\n      in set_mp)\n    apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b)(*strict*)\n    apply(force)\n   apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b)(*strict*)\n   apply (metis liftB_BiElem head_in_set not_in_setBI set_append_contra2)\n  apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc)(*strict*)\n  apply(clarsimp)\n  apply(case_tac c)\n   apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc)(*strict*)\n   apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc a listb)(*strict*)\n  apply(subgoal_tac \"\\<exists>w' x'. c = w' @ [x']\")\n   apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc a listb)(*strict*)\n   prefer 2\n   apply(rule NonEmptyListHasTailElem)\n   apply(force)\n  apply(rename_tac c d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc a listb)(*strict*)\n  apply(thin_tac \"c=a#listb\")\n  apply(clarsimp)\n  apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc w' x')(*strict*)\n  apply(subgoal_tac \"x'=Do\")\n   apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc w' x')(*strict*)\n   prefer 2\n   apply(rule_tac\n      v=\"w'a\"\n      and w=\"w'b@Do#w'\"\n      in liftB_terminal_tail_equals)\n   apply(clarsimp)\n  apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc w' x')(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc w')(*strict*)\n  apply(subgoal_tac \"w'a=liftB (w'b@Do#w')\")\n   apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc w')(*strict*)\n   prefer 2\n   apply(rule liftB_terminal_butlast_equals)\n   apply(force)\n  apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista w'a natb w'b natc w')(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista natb w'b natc w')(*strict*)\n  apply(subgoal_tac \"teB Do \\<in> set (liftB (w'b @ Do # w'))\")\n   apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista natb w'b natc w')(*strict*)\n   apply(subgoal_tac \"teB Do \\<notin> set (liftB (w'b @ Do # w'))\")\n    apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista natb w'b natc w')(*strict*)\n    apply(force)\n   apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista natb w'b natc w')(*strict*)\n   apply(force)\n  apply(rename_tac d da e1 e2 e1a e2a e ea w wa nat nata list lista natb w'b natc w')(*strict*)\n  apply (metis liftB_BiElem head_in_set not_in_setBI set_append_contra2)\n  done\n\ntheorem no_reduce_reduce_conflicts: \"\n  AF_LR_PARSER_input G F Do S' G' M P k\n  \\<Longrightarrow> conflict_free G G' k\n  \\<Longrightarrow> (parser_marker P) r1 = Some (Some \\<lparr>prod_lhs = A1, prod_rhs = w1\\<rparr>)\n  \\<Longrightarrow> (parser_marker P) r2 = Some (Some \\<lparr>prod_lhs = A2, prod_rhs = w2\\<rparr>)\n  \\<Longrightarrow> r1 \\<in> parser_rules P\n  \\<Longrightarrow> r2 \\<in> parser_rules P\n  \\<Longrightarrow> rule_lpop r2 \\<sqsupseteq> rule_lpop r1 \\<or> rule_lpop r1 \\<sqsupseteq> rule_lpop r2\n  \\<Longrightarrow> rule_rpop r1 \\<sqsubseteq> rule_rpop r2 \\<or> rule_rpop r2 \\<sqsubseteq> rule_rpop r1\n  \\<Longrightarrow> r1 = r2\"\n  apply(case_tac r1)\n  apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n  apply(subgoal_tac \" rule_rpopa=rule_rpush \\<and> \\<lparr>prod_lhs=A1,prod_rhs=w1\\<rparr> \\<in> (cfg_productions G) \\<and> (\\<exists>q\\<delta>. rule_lpopa=q\\<delta>#F_DFA_GOTO_SEQUENCE M q\\<delta> w1 \\<and> rule_lpush=q\\<delta>#(F_DFA_GOTO_SEQUENCE M q\\<delta> [teA A1]) \\<and> (\\<exists>\\<delta>. \\<lparr>cfg_item_lhs = A1,cfg_item_rhs1 = w1,cfg_item_rhs2 = [],cfg_item_look_ahead = rule_rpopa\\<rparr> \\<in> valid_item_set G' k (teB Do#\\<delta>@w1) \\<and> q\\<delta>=last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do#\\<delta>))))\")\n   apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n   prefer 2\n   apply(rule_tac\n      S'=\"S'\"\n      and Do=\"Do\"\n      and G'=\"G'\"\n      and G=\"G\"\n      in X6_3_InformationOnRules_reduce2)\n            apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n            apply(simp add: AF_LR_PARSER_input_def)\n           apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n           apply(simp add: AF_LR_PARSER_input_def)\n           apply(force)\n          apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(simp add: AF_LR_PARSER_input_def)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n      apply(simp add: AF_LR_PARSER_input_def)\n     apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n     apply(force)\n    apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n    apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n    apply(simp add: AF_LR_PARSER_input_def)\n   apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n   apply(simp add: AF_LR_PARSER_input_def)\n  apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n  apply(case_tac r2)\n  apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n  apply(subgoal_tac \" rule_rpopaa=rule_rpusha \\<and> \\<lparr>prod_lhs=A2,prod_rhs=w2\\<rparr> \\<in> (cfg_productions G) \\<and> (\\<exists>q\\<delta>. rule_lpopaa=q\\<delta>#F_DFA_GOTO_SEQUENCE M q\\<delta> w2 \\<and> rule_lpusha=q\\<delta>#(F_DFA_GOTO_SEQUENCE M q\\<delta> [teA A2]) \\<and> (\\<exists>\\<delta>. \\<lparr>cfg_item_lhs = A2,cfg_item_rhs1 = w2,cfg_item_rhs2 = [],cfg_item_look_ahead = rule_rpopaa\\<rparr> \\<in> valid_item_set G' k (teB Do#\\<delta>@w2) \\<and> q\\<delta>=last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do#\\<delta>))))\")\n   apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n   prefer 2\n   apply(rule_tac\n      S'=\"S'\"\n      and Do=\"Do\"\n      and G'=\"G'\"\n      and G=\"G\"\n      in X6_3_InformationOnRules_reduce2)\n            apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n            apply(simp add: AF_LR_PARSER_input_def)\n           apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n           apply(simp add: AF_LR_PARSER_input_def)\n           apply(force)\n          apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n        apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n      apply(force)\n     apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n     apply(force)\n    apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n    apply(simp add: AF_LR_PARSER_input_def)\n   apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n   apply(simp add: AF_LR_PARSER_input_def)\n  apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n  apply(thin_tac \"parser_marker P r1 = Some (Some \\<lparr>prod_lhs = A1, prod_rhs = w1\\<rparr>)\")\n  apply(thin_tac \"parser_marker P r2 = Some (Some \\<lparr>prod_lhs = A2, prod_rhs = w2\\<rparr>)\")\n  apply(clarsimp)\n  apply(rename_tac rule_rpush rule_rpusha \\<delta> \\<delta>')(*strict*)\n  apply(thin_tac \"\\<lparr>rule_lpop = last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>)) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>))) w1, rule_rpop = rule_rpush, rule_lpush = last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>)) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>))) [teA A1], rule_rpush = rule_rpush\\<rparr> \\<in> parser_rules P\")\n  apply(rename_tac rule_rpush rule_rpusha \\<delta> \\<delta>')(*strict*)\n  apply(thin_tac \"\\<lparr>rule_lpop = last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>')) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>'))) w2, rule_rpop = rule_rpusha, rule_lpush = last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>')) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>'))) [teA A2], rule_rpush = rule_rpusha\\<rparr> \\<in> parser_rules P\")\n  apply(rename_tac rule_rpush rule_rpusha \\<delta> \\<delta>')(*strict*)\n  apply(rename_tac y1 y2 v1 v2)\n  apply(rename_tac y1 y2 v1 v2)(*strict*)\n  apply(subgoal_tac \"valid_cfg G'\")\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   prefer 2\n   apply(rule F_CFG_AUGMENT__makes_CFG)\n   apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n   apply(force)\n  apply(rename_tac y1 y2 v1 v2)(*strict*)\n  apply(subgoal_tac \"valid_dfa M\")\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"G'\"\n      in Theorem6__27_a)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(simp add: AF_LR_PARSER_input_def)\n    apply(force)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n  apply(rename_tac y1 y2 v1 v2)(*strict*)\n  apply(subgoal_tac \"some_step_from_every_configuration M\")\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"G'\"\n      in F_LR_MACHINE_Complete)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(simp add: AF_LR_PARSER_input_def)\n    apply(force)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n  apply(rename_tac y1 y2 v1 v2)(*strict*)\n  apply(subgoal_tac \"every_state_in_some_accessible_configuration M\")\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   prefer 2\n   apply(rule F_LR_MACHINE_all_Connected)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      prefer 2\n      apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n      apply(force)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(force)\n  apply(rename_tac y1 y2 v1 v2)(*strict*)\n  apply(subgoal_tac \"some_step_from_every_configuration M\")\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"G'\"\n      in F_LR_MACHINE_Complete)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(force)\n   apply(simp add: AF_LR_PARSER_input_def)\n  apply(rename_tac y1 y2 v1 v2)(*strict*)\n  apply(subgoal_tac \"valid_parser P\")\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"G\"\n      in AF_LR_PARSER_valid_parser)\n         apply(rename_tac y1 y2 v1 v2)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n        apply(simp add: AF_LR_PARSER_input_def)\n        apply(rename_tac y1 y2 v1 v2)(*strict*)\n        apply(force)\n       apply(rename_tac y1 y2 v1 v2)(*strict*)\n       apply(force)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      apply(force)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(simp add: AF_LR_PARSER_input_def)\n   apply(simp add: AF_LR_PARSER_input_def)\n  apply(rename_tac y1 y2 v1 v2)(*strict*)\n  apply(subgoal_tac \"set (teB Do # v1 @ w1) \\<subseteq> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')\")\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   prefer 2\n   apply(rule viable_prefix_in_CFG)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(simp add: AF_LR_PARSER_input_def)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(rule Fact6_12__1)\n   apply(force)\n  apply(rename_tac y1 y2 v1 v2)(*strict*)\n  apply(subgoal_tac \"set (teB Do # v2 @ w2) \\<subseteq> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')\")\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   prefer 2\n   apply(rule viable_prefix_in_CFG)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(simp add: AF_LR_PARSER_input_def)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(rule Fact6_12__1)\n   apply(force)\n  apply(rename_tac y1 y2 v1 v2)(*strict*)\n  apply(subgoal_tac \"valid_item_set G' k (teB Do # v1 @ w1)=valid_item_set G' k (teB Do # v2 @ w2)\")\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"valid_item_set G' k (teB Do # v1 @ w1) = (if (teB Do # v1 @ w1)=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1 @ w1)))\")\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    prefer 2\n    apply(rule F_LR_MACHINE_all_SOUND)\n          apply(rename_tac y1 y2 v1 v2)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(rename_tac y1 y2 v1 v2)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n         apply(force)\n        apply(rename_tac y1 y2 v1 v2)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(rename_tac y1 y2 v1 v2)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(simp add: AF_LR_PARSER_input_def)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     prefer 2\n     apply (metis two_elements_construct_domain_setB)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply (metis two_elements_construct_domain_setA)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(subgoal_tac \"valid_item_set G' k (teB Do # v2 @ w2) = (if (teB Do # v2 @ w2)=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2 @ w2)))\")\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    prefer 2\n    apply(rule F_LR_MACHINE_all_SOUND)\n          apply(rename_tac y1 y2 v1 v2)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(rename_tac y1 y2 v1 v2)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n         apply(force)\n        apply(rename_tac y1 y2 v1 v2)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(rename_tac y1 y2 v1 v2)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(simp add: AF_LR_PARSER_input_def)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     prefer 2\n     apply (metis two_elements_construct_domain_setB)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply (metis two_elements_construct_domain_setA)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(subgoal_tac \"valid_item_set G' k (teB Do # v1) = (if (teB Do # v1)=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1)))\")\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    prefer 2\n    apply(rule F_LR_MACHINE_all_SOUND)\n          apply(rename_tac y1 y2 v1 v2)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(rename_tac y1 y2 v1 v2)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n         apply(force)\n        apply(rename_tac y1 y2 v1 v2)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(rename_tac y1 y2 v1 v2)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(simp add: AF_LR_PARSER_input_def)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     prefer 2\n     apply (rule two_elements_construct_domain_setB)\n     apply(rule_tac\n      B=\"set (teB Do # v1 @ w1)\"\n      in subset_trans)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      apply(force)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply (rule two_elements_construct_domain_setA)\n    apply(rule_tac\n      B=\"set (teB Do # v1 @ w1)\"\n      in subset_trans)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(force)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(subgoal_tac \"valid_item_set G' k (teB Do # v2) = (if (teB Do # v2)=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2)))\")\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    prefer 2\n    apply(rule F_LR_MACHINE_all_SOUND)\n          apply(rename_tac y1 y2 v1 v2)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(rename_tac y1 y2 v1 v2)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n         apply(force)\n        apply(rename_tac y1 y2 v1 v2)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(rename_tac y1 y2 v1 v2)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(simp add: AF_LR_PARSER_input_def)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     prefer 2\n     apply (rule two_elements_construct_domain_setB)\n     apply(rule_tac\n      B=\"set (teB Do # v2 @ w2)\"\n      in subset_trans)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      apply(force)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply (rule two_elements_construct_domain_setA)\n    apply(rule_tac\n      B=\"set (teB Do # v2 @ w2)\"\n      in subset_trans)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(force)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"length w2 = length (F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))) w2)\")\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    prefer 2\n    apply(rule F_DFA_GOTO_SEQUENCESound_main1)\n         apply(rename_tac y1 y2 v1 v2)(*strict*)\n         apply(force)\n        apply(rename_tac y1 y2 v1 v2)(*strict*)\n        apply(force)\n       apply(rename_tac y1 y2 v1 v2)(*strict*)\n       apply(force)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      prefer 2\n      apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(rule_tac\n      t=\"last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))\"\n      and s=\"valid_item_set G' k (teB Do # v2)\"\n      in ssubst)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(rule LRM_contains_theEqClasses2)\n       apply(rename_tac y1 y2 v1 v2)(*strict*)\n       apply(force)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      apply(simp add: AF_LR_PARSER_input_def)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      apply(force)\n     apply(simp add: AF_LR_PARSER_input_def)\n    apply(force)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(subgoal_tac \"length w1 = length (F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))) w1)\")\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    prefer 2\n    apply(rule F_DFA_GOTO_SEQUENCESound_main1)\n         apply(rename_tac y1 y2 v1 v2)(*strict*)\n         apply(force)\n        apply(rename_tac y1 y2 v1 v2)(*strict*)\n        apply(force)\n       apply(rename_tac y1 y2 v1 v2)(*strict*)\n       apply(force)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      prefer 2\n      apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(rule_tac\n      t=\"last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))\"\n      and s=\"valid_item_set G' k (teB Do # v1)\"\n      in ssubst)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(rule LRM_contains_theEqClasses2)\n       apply(rename_tac y1 y2 v1 v2)(*strict*)\n       apply(force)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      apply(simp add: AF_LR_PARSER_input_def)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      apply(force)\n     apply(simp add: AF_LR_PARSER_input_def)\n    apply(force)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(subgoal_tac \"length (teB Do#v2) = length (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))\")\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    prefer 2\n    apply(rule F_DFA_GOTO_SEQUENCESound_main1)\n         apply(rename_tac y1 y2 v1 v2)(*strict*)\n         apply(force)\n        apply(rename_tac y1 y2 v1 v2)(*strict*)\n        apply(force)\n       apply(rename_tac y1 y2 v1 v2)(*strict*)\n       apply(force)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      prefer 2\n      apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(simp add: valid_dfa_def valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(subgoal_tac \"length (teB Do#v1) = length (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))\")\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    prefer 2\n    apply(rule F_DFA_GOTO_SEQUENCESound_main1)\n         apply(rename_tac y1 y2 v1 v2)(*strict*)\n         apply(force)\n        apply(rename_tac y1 y2 v1 v2)(*strict*)\n        apply(force)\n       apply(rename_tac y1 y2 v1 v2)(*strict*)\n       apply(force)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      prefer 2\n      apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(simp add: valid_dfa_def valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(rule_tac\n      t=\"last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2 @ w2))\"\n      and s=\"last((last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2)) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))) w2))\"\n      in ssubst)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(clarsimp)\n    apply(case_tac w2)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2 a list)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac y1 y2 v1 v2 a list)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2 a list)(*strict*)\n    apply(rule impI)\n    apply(subgoal_tac \"\\<exists>w' x'. w2 = w' @ [x']\")\n     apply(rename_tac y1 y2 v1 v2 a list)(*strict*)\n     prefer 2\n     apply(rule_tac\n      n=\"length list\"\n      in NonEmptyListHasTailElem)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2 a list)(*strict*)\n    apply(thin_tac \"w2=a#list\")\n    apply(clarsimp)\n    apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n    apply(rule_tac\n      t=\"teB Do # v2 @ w' @ [x']\"\n      and s=\"(teB Do # v2) @ (w' @ [x'])\"\n      in ssubst)\n     apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n    apply(rule_tac\n      t=\"F_DFA_GOTO_SEQUENCE M (epda_initial M) ((teB Do # v2) @ (w' @ [x']))\"\n      and s=\"F_DFA_GOTO_SEQUENCE M SSp SSw1 @ (F_DFA_GOTO_SEQUENCE M (last (SSp#(F_DFA_GOTO_SEQUENCE M SSp SSw1))) SSw2)\" for SSp SSw1 SSw2\n      in ssubst)\n     apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n     apply(rule F_DFA_GOTO_SEQUENCE_append_split)\n          apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n          apply(force)\n         apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n         apply(force)\n        apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n        apply(force)\n       apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n       apply(force)\n      apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n      apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def)\n     apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n     apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def)\n    apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n    apply(clarsimp)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(rule_tac\n      t=\"last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1 @ w1))\"\n      and s=\"last((last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1)) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))) w1))\"\n      in ssubst)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(clarsimp)\n    apply(case_tac w1)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2 a list)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac y1 y2 v1 v2 a list)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2 a list)(*strict*)\n    apply(rule impI)\n    apply(subgoal_tac \"\\<exists>w' x'. w1 = w' @ [x']\")\n     apply(rename_tac y1 y2 v1 v2 a list)(*strict*)\n     prefer 2\n     apply(rule_tac\n      n=\"length list\"\n      in NonEmptyListHasTailElem)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2 a list)(*strict*)\n    apply(thin_tac \"w1=a#list\")\n    apply(clarsimp)\n    apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n    apply(rule_tac\n      t=\"teB Do # v1 @ w' @ [x']\"\n      and s=\"(teB Do # v1) @ (w' @ [x'])\"\n      in ssubst)\n     apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n    apply(rule_tac\n      t=\"F_DFA_GOTO_SEQUENCE M (epda_initial M) ((teB Do # v1) @ (w' @ [x']))\"\n      and s=\"F_DFA_GOTO_SEQUENCE M SSp SSw1 @ (F_DFA_GOTO_SEQUENCE M (last (SSp#(F_DFA_GOTO_SEQUENCE M SSp SSw1))) SSw2)\" for SSp SSw1 SSw2\n      in ssubst)\n     apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n     apply(rule F_DFA_GOTO_SEQUENCE_append_split)\n          apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n          apply(force)\n         apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n         apply(force)\n        apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n        apply(force)\n       apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n       apply(force)\n      apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n      apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def)\n     apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n     apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def)\n    apply(rename_tac y1 y2 v1 v2 w' x')(*strict*)\n    apply(clarsimp)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(rule suffix_last_eq)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(force)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(force)\n  apply(rename_tac y1 y2 v1 v2)(*strict*)\n  apply(subgoal_tac \"y1=y2\")\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(simp only: conflict_free_def)\n   apply(erule_tac\n      x=\"(teB Do # v1 @ w1)\"\n      in allE)\n   apply(erule impE)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(force)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(erule conjE)+\n   apply(thin_tac \"\\<forall>I1 I2. I1 \\<in> valid_item_set G' k (teB Do # v1 @ w1) \\<and> I2 \\<in> valid_item_set G' k (teB Do # v1 @ w1) \\<and> item_core I1 \\<in> cfg_productions G \\<and> item_core I2 \\<in> cfg_productions G \\<longrightarrow> \\<not> item_shift_reduce_conflict G' k I1 I2\")\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(erule_tac\n      x=\"\\<lparr>cfg_item_lhs = A1, cfg_item_rhs1 = w1, cfg_item_rhs2 = [], cfg_item_look_ahead = y1\\<rparr>\"\n      in allE)\n   apply(erule_tac\n      x=\"\\<lparr>cfg_item_lhs = A2, cfg_item_rhs1 = w2, cfg_item_rhs2 = [], cfg_item_look_ahead = y2\\<rparr>\"\n      in allE)\n   apply(erule impE)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(simp add: item_core_def)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(simp add: item_reduce_reduce_conflict_def)\n   apply(subgoal_tac \" F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))) w2 = F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))) w2 \\<and> last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2)) = last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))\")\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    prefer 2\n    apply(rule mutual_prefix_equal_suffix)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(subgoal_tac \"valid_item_set G' k (teB Do # v1) = (if (teB Do # v1)=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1)))\")\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     prefer 2\n     apply(rule F_LR_MACHINE_all_SOUND)\n           apply(rename_tac y1 y2 v1 v2)(*strict*)\n           apply(simp add: AF_LR_PARSER_input_def)\n          apply(rename_tac y1 y2 v1 v2)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n          apply(force)\n         apply(rename_tac y1 y2 v1 v2)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n        apply(rename_tac y1 y2 v1 v2)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      prefer 2\n      apply (rule two_elements_construct_domain_setB)\n      apply(rule_tac\n      B=\"set (teB Do # v1 @ w1)\"\n      in subset_trans)\n       apply(rename_tac y1 y2 v1 v2)(*strict*)\n       apply(force)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      apply(force)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply (rule two_elements_construct_domain_setA)\n     apply(rule_tac\n      B=\"set (teB Do # v1 @ w1)\"\n      in subset_trans)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      apply(force)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(subgoal_tac \"valid_item_set G' k (teB Do # v2) = (if (teB Do # v2)=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2)))\")\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     prefer 2\n     apply(rule F_LR_MACHINE_all_SOUND)\n           apply(rename_tac y1 y2 v1 v2)(*strict*)\n           apply(simp add: AF_LR_PARSER_input_def)\n          apply(rename_tac y1 y2 v1 v2)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n          apply(force)\n         apply(rename_tac y1 y2 v1 v2)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n        apply(rename_tac y1 y2 v1 v2)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      prefer 2\n      apply (rule two_elements_construct_domain_setB)\n      apply(rule_tac\n      B=\"set (teB Do # v2 @ w2)\"\n      in subset_trans)\n       apply(rename_tac y1 y2 v1 v2)(*strict*)\n       apply(force)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      apply(force)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply (rule two_elements_construct_domain_setA)\n     apply(rule_tac\n      B=\"set (teB Do # v2 @ w2)\"\n      in subset_trans)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      apply(force)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac y2 v1 v2)(*strict*)\n    apply(subgoal_tac \"length w2 = length (F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))) w2)\")\n     apply(rename_tac y2 v1 v2)(*strict*)\n     prefer 2\n     apply(rule F_DFA_GOTO_SEQUENCESound_main1)\n          apply(rename_tac y2 v1 v2)(*strict*)\n          apply(force)\n         apply(rename_tac y2 v1 v2)(*strict*)\n         apply(force)\n        apply(rename_tac y2 v1 v2)(*strict*)\n        apply(force)\n       apply(rename_tac y2 v1 v2)(*strict*)\n       prefer 2\n       apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def)\n      apply(rename_tac y2 v1 v2)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac y2 v1 v2)(*strict*)\n     apply(rule_tac\n      t=\"last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))\"\n      and s=\"valid_item_set G' k (teB Do # v2)\"\n      in ssubst)\n      apply(rename_tac y2 v1 v2)(*strict*)\n      apply(force)\n     apply(rename_tac y2 v1 v2)(*strict*)\n     apply(rule LRM_contains_theEqClasses2)\n        apply(rename_tac y2 v1 v2)(*strict*)\n        apply(force)\n       apply(simp add: AF_LR_PARSER_input_def)\n       apply(force)\n      apply(rename_tac y2 v1 v2)(*strict*)\n      apply(simp add: AF_LR_PARSER_input_def)\n     apply(rename_tac y2 v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y2 v1 v2)(*strict*)\n    apply(subgoal_tac \"length w2 = length (F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))) w2)\")\n     apply(rename_tac y2 v1 v2)(*strict*)\n     prefer 2\n     apply(rule F_DFA_GOTO_SEQUENCESound_main1)\n          apply(rename_tac y2 v1 v2)(*strict*)\n          apply(force)\n         apply(rename_tac y2 v1 v2)(*strict*)\n         apply(force)\n        apply(rename_tac y2 v1 v2)(*strict*)\n        apply(force)\n       apply(rename_tac y2 v1 v2)(*strict*)\n       prefer 2\n       apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def)\n      apply(rename_tac y2 v1 v2)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac y2 v1 v2)(*strict*)\n     apply(rule_tac\n      t=\"last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))\"\n      and s=\"valid_item_set G' k (teB Do # v1)\"\n      in ssubst)\n      apply(rename_tac y2 v1 v2)(*strict*)\n      apply(force)\n     apply(rename_tac y2 v1 v2)(*strict*)\n     apply(rule LRM_contains_theEqClasses2)\n        apply(rename_tac y2 v1 v2)(*strict*)\n        apply(force)\n       apply(rename_tac y2 v1 v2)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def)\n       apply(rename_tac y2 v1 v2)(*strict*)\n       apply(force)\n      apply(simp add: AF_LR_PARSER_input_def)\n     apply(force)\n    apply(rename_tac y2 v1 v2)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac y1 y2 v1 v2)(*strict*)\n  apply(subgoal_tac \"valid_item_set G' k (teB Do # v1 @ w1) \\<in> epda_states M\")\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   prefer 2\n   apply(rule LRM_contains_theEqClasses2)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      apply(force)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(simp add: AF_LR_PARSER_input_def)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(simp add: AF_LR_PARSER_input_def)\n   apply(force)\n  apply(rename_tac y1 y2 v1 v2)(*strict*)\n  apply(erule_tac\n      P=\"y1 \\<sqsubseteq> y2\"\n      in disjE)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(rule no_reduce_reduce_conflicts_hlp)\n       apply(rename_tac y1 y2 v1 v2)(*strict*)\n       apply(force)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      apply(force)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(force)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(force)\n  apply(rename_tac y1 y2 v1 v2)(*strict*)\n  apply(rule sym)\n  apply(rule no_reduce_reduce_conflicts_hlp)\n      apply(rename_tac y1 y2 v1 v2)(*strict*)\n      apply(force)\n     apply(rename_tac y1 y2 v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y2 v1 v2)(*strict*)\n    apply(force)\n   apply(rename_tac y1 y2 v1 v2)(*strict*)\n   apply(force)\n  apply(rename_tac y1 y2 v1 v2)(*strict*)\n  apply(force)\n  done\n\nlemma translate_cfgSTD_first_with_single: \"\n  AF_LR_PARSER_input G F Do S' G' M P k\n  \\<Longrightarrow> y \\<in> cfgSTD_first G' (k - Suc 0) w\n  \\<Longrightarrow> take k (a # y) \\<in> cfgSTD_first G' k (teB a # w)\"\n  apply(simp add: cfgSTD_first_def)\n  apply(clarsimp)\n  apply(rename_tac x d e1 n)(*strict*)\n  apply(rule inMap)\n  apply(clarsimp)\n  apply(rule_tac\n      x=\"a # x\"\n      in exI)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(rename_tac x d e1 n)(*strict*)\n   prefer 2\n   apply(case_tac k)\n    apply(rename_tac x d e1 n)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac x d e1 n nat)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x d e1 n)(*strict*)\n  apply(rule_tac\n      x=\"derivation_map d (\\<lambda>v. \\<lparr>cfg_conf=(teB a)#(cfg_conf v)\\<rparr>)\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac x d e1 n)(*strict*)\n   apply(rule cfgSTD.derivation_map_preserves_derivation2)\n    apply(rename_tac x d e1 n)(*strict*)\n    apply(force)\n   apply(rename_tac x d e1 n)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x d e1 n aa e b)(*strict*)\n   apply(simp add: cfgSTD_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac x d e1 n aa e b l r)(*strict*)\n   apply(rule_tac\n      x=\"teB a#l\"\n      in exI)\n   apply(rule_tac\n      x=\"r\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac x d e1 n)(*strict*)\n  apply(rule_tac\n      x=\"e1\"\n      in exI)\n  apply(rule_tac\n      x=\"n\"\n      in exI)\n  apply(simp add: derivation_map_def maximum_of_domain_def)\n  done\n\ntheorem no_shift_reduce_conflicts: \"\n  AF_LR_PARSER_input G F Do S' G' M P k\n  \\<Longrightarrow> conflict_free G G' k\n  \\<Longrightarrow> (parser_marker P) r1 = Some None\n  \\<Longrightarrow> (parser_marker P) r2 = Some (Some \\<lparr>prod_lhs = A2, prod_rhs = w2\\<rparr>)\n  \\<Longrightarrow> r1 \\<in> parser_rules P\n  \\<Longrightarrow> r2 \\<in> parser_rules P\n  \\<Longrightarrow> rule_lpop r2 \\<sqsupseteq> rule_lpop r1 \\<or> rule_lpop r1 \\<sqsupseteq> rule_lpop r2\n  \\<Longrightarrow> rule_rpop r1 \\<sqsubseteq> rule_rpop r2 \\<or> rule_rpop r2 \\<sqsubseteq> rule_rpop r1\n  \\<Longrightarrow> r1 = r2\"\n  apply(case_tac r1)\n  apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n  apply(subgoal_tac \" \\<exists>q\\<delta> y \\<beta> z A \\<alpha> a \\<delta>. y \\<in> (cfgSTD_first G' (k- 1) (\\<beta>@(liftB z))) \\<and> \\<lparr>prod_lhs=A,prod_rhs=\\<alpha>@(teB a)#\\<beta>\\<rparr> \\<in> cfg_productions G \\<and> q\\<delta>=last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do#\\<delta>)) \\<and> \\<lparr>cfg_item_lhs = A,cfg_item_rhs1 = \\<alpha>,cfg_item_rhs2 = (teB a)#\\<beta>,cfg_item_look_ahead = z\\<rparr> \\<in> valid_item_set G' k (teB Do#\\<delta>) \\<and> rule_lpopa=[q\\<delta>] \\<and> rule_rpopa=a#y \\<and> rule_lpush=[q\\<delta>,F_DFA_GOTO M q\\<delta> (teB a)] \\<and> rule_rpush=y\")\n   apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n   prefer 2\n   apply(rule_tac\n      S'=\"S'\"\n      and Do=\"Do\"\n      and G'=\"G'\"\n      and G=\"G\"\n      in X6_3_InformationOnRules_shift2)\n            apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n            apply(simp add: AF_LR_PARSER_input_def)\n           apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n           apply(simp add: AF_LR_PARSER_input_def)\n           apply(force)\n          apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n        apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(force)\n     apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n     apply(force)\n    apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n    apply(simp add: AF_LR_PARSER_input_def)\n   apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n   apply(simp add: AF_LR_PARSER_input_def)\n  apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush)(*strict*)\n  apply(case_tac r2)\n  apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n  apply(subgoal_tac \" rule_rpopaa=rule_rpusha \\<and> \\<lparr>prod_lhs=A2,prod_rhs=w2\\<rparr> \\<in> (cfg_productions G) \\<and> (\\<exists>q\\<delta>. rule_lpopaa=q\\<delta>#F_DFA_GOTO_SEQUENCE M q\\<delta> w2 \\<and> rule_lpusha=q\\<delta>#(F_DFA_GOTO_SEQUENCE M q\\<delta> [teA A2]) \\<and> (\\<exists>\\<delta>. \\<lparr>cfg_item_lhs = A2,cfg_item_rhs1 = w2,cfg_item_rhs2 = [],cfg_item_look_ahead = rule_rpopaa\\<rparr> \\<in> valid_item_set G' k (teB Do#\\<delta>@w2) \\<and> q\\<delta>=last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do#\\<delta>))))\")\n   apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n   prefer 2\n   apply(rule_tac\n      S'=\"S'\"\n      and Do=\"Do\"\n      and G'=\"G'\"\n      and G=\"G\"\n      in X6_3_InformationOnRules_reduce2)\n            apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n            apply(simp add: AF_LR_PARSER_input_def)\n           apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n           apply(simp add: AF_LR_PARSER_input_def)\n           apply(force)\n          apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n        apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(force)\n     apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n     apply(force)\n    apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n    apply(simp add: AF_LR_PARSER_input_def)\n   apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n   apply(simp add: AF_LR_PARSER_input_def)\n  apply(rename_tac rule_lpopa rule_rpopa rule_lpush rule_rpush rule_lpopaa rule_rpopaa rule_lpusha rule_rpusha)(*strict*)\n  apply(thin_tac \"parser_marker P r1 = Some None\")\n  apply(thin_tac \"parser_marker P r2 = Some (Some \\<lparr>prod_lhs = A2, prod_rhs = w2\\<rparr>)\")\n  apply(clarsimp)\n  apply(rename_tac rule_rpusha y \\<beta> z A \\<alpha> a \\<delta> \\<delta>')(*strict*)\n  apply(thin_tac \"\\<lparr>rule_lpop = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>))], rule_rpop = a # y, rule_lpush = [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>)), F_DFA_GOTO M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>))) (teB a)], rule_rpush = y\\<rparr> \\<in> parser_rules P\")\n  apply(rename_tac rule_rpusha y \\<beta> z A \\<alpha> a \\<delta> \\<delta>')(*strict*)\n  apply(thin_tac \"\\<lparr>rule_lpop = last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>')) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>'))) w2, rule_rpop = rule_rpusha, rule_lpush = last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>')) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # \\<delta>'))) [teA A2], rule_rpush = rule_rpusha\\<rparr> \\<in> parser_rules P\")\n  apply(rename_tac rule_rpusha y \\<beta> z A \\<alpha> a \\<delta> \\<delta>')(*strict*)\n  apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)\n  apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n  apply(subgoal_tac \"valid_cfg G'\")\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   prefer 2\n   apply(rule F_CFG_AUGMENT__makes_CFG)\n   apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n   apply(force)\n  apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n  apply(subgoal_tac \"valid_dfa M\")\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"G'\"\n      in Theorem6__27_a)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(force)\n   apply(simp add: AF_LR_PARSER_input_def)\n  apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n  apply(subgoal_tac \"some_step_from_every_configuration M\")\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"G'\"\n      in F_LR_MACHINE_Complete)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(force)\n   apply(simp add: AF_LR_PARSER_input_def)\n  apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n  apply(subgoal_tac \"every_state_in_some_accessible_configuration M\")\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   prefer 2\n   apply(rule F_LR_MACHINE_all_Connected)\n      apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n      prefer 2\n      apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n      apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n      apply(force)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(simp add: AF_LR_PARSER_input_def)\n   apply(force)\n  apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n  apply(subgoal_tac \"some_step_from_every_configuration M\")\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"G'\"\n      in F_LR_MACHINE_Complete)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(force)\n   apply(simp add: AF_LR_PARSER_input_def)\n  apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n  apply(subgoal_tac \"valid_parser P\")\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"G\"\n      in AF_LR_PARSER_valid_parser)\n         apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n        apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def)\n        apply(force)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n      apply(force)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply(force)\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   apply(simp add: AF_LR_PARSER_input_def)\n  apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n  apply(subgoal_tac \"set (teB Do # v1) \\<subseteq> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')\")\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   prefer 2\n   apply(rule viable_prefix_in_CFG)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply(simp add: AF_LR_PARSER_input_def)\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   apply(rule Fact6_12__1)\n   apply(force)\n  apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n  apply(subgoal_tac \"set (teB Do # v2 @ w2) \\<subseteq> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')\")\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   prefer 2\n   apply(rule viable_prefix_in_CFG)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply(simp add: AF_LR_PARSER_input_def)\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   apply(rule Fact6_12__1)\n   apply(force)\n  apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n  apply(subgoal_tac \"valid_item_set G' k (teB Do # v1)=valid_item_set G' k (teB Do # v2 @ w2)\")\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"valid_item_set G' k (teB Do # v1) = (if (teB Do # v1)=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1)))\")\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    prefer 2\n    apply(rule F_LR_MACHINE_all_SOUND)\n          apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n         apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n         apply(force)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(simp add: AF_LR_PARSER_input_def)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n     prefer 2\n     apply (metis two_elements_construct_domain_setB)\n    apply(simp add: AF_LR_PARSER_input_def)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply (metis two_elements_construct_domain_setA)\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   apply(subgoal_tac \"valid_item_set G' k (teB Do # v2 @ w2) = (if (teB Do # v2 @ w2)=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2 @ w2)))\")\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    prefer 2\n    apply(rule F_LR_MACHINE_all_SOUND)\n          apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n         apply(force)\n        apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(force)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n     prefer 2\n     apply (metis two_elements_construct_domain_setB)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply (metis two_elements_construct_domain_setA)\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   apply(subgoal_tac \"valid_item_set G' k (teB Do # v2) = (if (teB Do # v2)=[] then (epda_initial M) else last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2)))\")\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    prefer 2\n    apply(rule F_LR_MACHINE_all_SOUND)\n          apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n         apply(force)\n        apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(force)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n     prefer 2\n     apply (rule two_elements_construct_domain_setB)\n     apply(rule_tac\n      B=\"set (teB Do # v2 @ w2)\"\n      in subset_trans)\n      apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n      apply(force)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply (rule two_elements_construct_domain_setA)\n    apply(rule_tac\n      B=\"set (teB Do # v2 @ w2)\"\n      in subset_trans)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply(force)\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"length w2 = length (F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))) w2)\")\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    prefer 2\n    apply(rule F_DFA_GOTO_SEQUENCESound_main1)\n         apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n         apply(force)\n        apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n        apply(force)\n       apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n       apply(force)\n      apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n      prefer 2\n      apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply(rule_tac\n      t=\"last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))\"\n      and s=\"valid_item_set G' k (teB Do # v2)\"\n      in ssubst)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply(rule LRM_contains_theEqClasses2)\n       apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n       apply(force)\n      apply(simp add: AF_LR_PARSER_input_def)\n      apply(force)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n     apply(simp add: AF_LR_PARSER_input_def)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply(force)\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   apply(subgoal_tac \"length (teB Do#v2) = length (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))\")\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    prefer 2\n    apply(rule F_DFA_GOTO_SEQUENCESound_main1)\n         apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n         apply(force)\n        apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n        apply(force)\n       apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n       apply(force)\n      apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n      prefer 2\n      apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply(simp add: valid_dfa_def valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   apply(subgoal_tac \"length (teB Do#v1) = length (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))\")\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    prefer 2\n    apply(rule F_DFA_GOTO_SEQUENCESound_main1)\n         apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n         apply(force)\n        apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n        apply(force)\n       apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n       apply(force)\n      apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n      prefer 2\n      apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply(simp add: valid_dfa_def valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   apply(rule_tac\n      t=\"last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2 @ w2))\"\n      and s=\"last((last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2)) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))) w2))\"\n      in ssubst)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply(clarsimp)\n    apply(case_tac w2)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 aa list)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 aa list)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 aa list)(*strict*)\n    apply(rule impI)\n    apply(subgoal_tac \"\\<exists>w' x'. w2 = w' @ [x']\")\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 aa list)(*strict*)\n     prefer 2\n     apply(rule_tac\n      n=\"length list\"\n      in NonEmptyListHasTailElem)\n     apply(force)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 aa list)(*strict*)\n    apply(thin_tac \"w2=aa#list\")\n    apply(clarsimp)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 w' x')(*strict*)\n    apply(rule_tac\n      t=\"teB Do # v2 @ w' @ [x']\"\n      and s=\"(teB Do # v2) @ (w' @ [x'])\"\n      in ssubst)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 w' x')(*strict*)\n     apply(force)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 w' x')(*strict*)\n    apply(rule_tac\n      t=\"F_DFA_GOTO_SEQUENCE M (epda_initial M) ((teB Do # v2) @ (w' @ [x']))\"\n      and s=\"F_DFA_GOTO_SEQUENCE M SSp SSw1 @ (F_DFA_GOTO_SEQUENCE M (last (SSp#(F_DFA_GOTO_SEQUENCE M SSp SSw1))) SSw2)\" for SSp SSw1 SSw2\n      in ssubst)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 w' x')(*strict*)\n     apply(rule F_DFA_GOTO_SEQUENCE_append_split)\n          apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 w' x')(*strict*)\n          apply(force)\n         apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 w' x')(*strict*)\n         apply(force)\n        apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 w' x')(*strict*)\n        apply(force)\n       apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 w' x')(*strict*)\n       apply(force)\n      apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 w' x')(*strict*)\n      apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 w' x')(*strict*)\n     apply(simp add: AF_LR_PARSER_input_def F_LR_MACHINE_def)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 w' x')(*strict*)\n    apply(clarsimp)\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   apply(rule_tac\n      t=\"last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))\"\n      and s=\"last([last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))])\"\n      in ssubst)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    prefer 2\n    apply(rule sym)\n    apply(rule suffix_last_eq)\n      apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n      apply(force)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n     apply(force)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply(force)\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   apply(force)\n  apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n  apply(simp add: conflict_free_def)\n  apply(erule_tac\n      x=\"(teB Do # v2 @ w2)\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   apply(force)\n  apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n  apply(erule conjE)+\n  apply(thin_tac \"(\\<forall>I1 I2. I1 \\<in> valid_item_set G' k (teB Do # v2 @ w2) \\<and> I2 \\<in> valid_item_set G' k (teB Do # v2 @ w2) \\<and> item_core I1 \\<in> cfg_productions G \\<and> item_core I2 \\<in> cfg_productions G \\<longrightarrow> \\<not> item_reduce_reduce_conflict I1 I2)\")\n  apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n  apply(erule_tac\n      x=\"\\<lparr>cfg_item_lhs = A, cfg_item_rhs1 = \\<alpha>, cfg_item_rhs2 = teB a # \\<beta>, cfg_item_look_ahead = z\\<rparr>\"\n      in allE)\n  apply(erule_tac\n      x=\"\\<lparr>cfg_item_lhs = A2, cfg_item_rhs1 = w2, cfg_item_rhs2 = [], cfg_item_look_ahead = y1\\<rparr>\"\n      in allE)\n  apply(clarsimp)\n  apply(erule impE)\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   apply(simp add: item_core_def)\n  apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n  apply(simp add: item_shift_reduce_conflict_def)\n  defer\n  apply(subgoal_tac \"valid_item_set G' k (teB Do # v2 @ w2) \\<in> epda_states M\")\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   prefer 2\n   apply(rule LRM_contains_theEqClasses2)\n      apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n      apply(force)\n     apply(simp add: AF_LR_PARSER_input_def)\n     apply(force)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply(simp add: AF_LR_PARSER_input_def)\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   apply(force)\n  apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n  apply(subgoal_tac \"y1 \\<in> cfgSTD_first G' k (teB a # \\<beta> @ liftB z)\")\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   apply(force)\n  apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n  apply(subgoal_tac \"take k (a#y) = y1\")\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   apply(clarify)\n   apply(rule translate_cfgSTD_first_with_single)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply(force)\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   apply(force)\n  apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n  apply(case_tac k)\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"valid_item G' 0 \\<lparr>cfg_item_lhs = A2, cfg_item_rhs1 = w2, cfg_item_rhs2 = [], cfg_item_look_ahead = y1\\<rparr>\")\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply(simp add: valid_item_def)\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   apply(rule Fact6_12__2)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n    apply(force)\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2)(*strict*)\n   apply(force)\n  apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n  apply(rule_tac\n      t=\"k\"\n      and s=\"Suc nat\"\n      in ssubst)\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n   apply(force)\n  apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n  apply(rule_tac\n      S'=\"S'\"\n      and Do=\"Do\"\n      and G'=\"G'\"\n      and G=\"G\"\n      in no_shift_reduce_conflicts_hlp)\n              apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n              apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n             apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n             apply(force)\n            apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n            apply(simp add: two_elements_construct_domain_def)\n            apply(rule conjI)\n             apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n             apply(clarsimp)\n            apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n            apply(clarsimp)\n            apply(erule_tac\n      P=\"teB Do \\<in> teA ` cfg_nonterminals G'\"\n      in disjE)\n             apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n             apply(clarsimp)\n            apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n            apply(clarsimp)\n            apply(simp add: AF_LR_PARSER_input_def)\n            apply(clarsimp)\n            apply(subgoal_tac \"F_FRESH (cfg_events G) \\<notin> cfg_events G\")\n             apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n             apply(force)\n            apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n            apply(rule F_FRESH_is_fresh)\n            apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def F_LR_PARSER_def)\n            apply(simp add: F_LR_MACHINE_def F_CFG_AUGMENT_def two_elements_construct_domain_def valid_cfg_def)\n           apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n           apply(simp add: two_elements_construct_domain_def)\n           apply(rule disjI2)\n           apply(clarsimp)\n           apply(rule inMap)\n           apply(clarsimp)\n           apply(simp add: AF_LR_PARSER_input_def valid_cfg_def)\n           apply(clarsimp)\n           apply(erule_tac\n      A=\"cfg_productions G\"\n      and x=\"\\<lparr>prod_lhs = A, prod_rhs = \\<alpha> @ teB a # \\<beta>\\<rparr>\"\n      in ballE)\n            apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n            prefer 2\n            apply(force)\n           apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n           apply(clarsimp)\n           apply(simp add: setBConcat)\n          apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n          apply(force)\n         apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n         apply(force)\n        apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n        prefer 3\n        apply(force)\n       apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n       prefer 3\n       apply(force)\n      apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n      apply(simp add: AF_LR_PARSER_input_def valid_cfg_def)\n      apply(clarsimp)\n      apply(erule_tac\n      x=\"\\<lparr>prod_lhs = A, prod_rhs = \\<alpha> @ teB a # \\<beta>\\<rparr>\"\n      and A=\"cfg_productions G\"\n      in ballE)\n       apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n       prefer 2\n       apply(force)\n      apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n     apply(simp add: AF_LR_PARSER_input_def valid_cfg_def)\n     apply(clarsimp)\n     apply(erule_tac\n      x=\"\\<lparr>prod_lhs = A2, prod_rhs = w2\\<rparr>\"\n      and A=\"cfg_productions G\"\n      in ballE)\n      apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n    apply(force)\n   apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n   apply(simp add: cfgSTD_first_def)\n   apply(clarsimp)\n  apply(rename_tac y1 y \\<beta> z A \\<alpha> a v1 v2 nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac y1 \\<beta> z A \\<alpha> a v1 v2 nat w v)(*strict*)\n  apply(thin_tac \"(last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2)) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))) w2) \\<sqsupseteq> [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))] \\<or> [last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v1))] \\<sqsupseteq> (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2)) # F_DFA_GOTO_SEQUENCE M (last (F_DFA_GOTO_SEQUENCE M (epda_initial M) (teB Do # v2))) w2)\")\n  apply(rename_tac y1 \\<beta> z A \\<alpha> a v1 v2 nat w v)(*strict*)\n  apply(thin_tac \"y1 \\<notin> cfgSTD_first G' (Suc nat) (teB a # \\<beta> @ liftB z)\")\n  apply(thin_tac \"\\<lparr>prod_lhs = A2, prod_rhs = w2\\<rparr> \\<in> cfg_productions G\")\n  apply(thin_tac \"(a # w @ Do # v) \\<sqsubseteq> y1 \\<or> y1 \\<sqsubseteq> (a # w @ Do # v)\")\n  apply(subgoal_tac \" (\\<exists>w. set w \\<subseteq> cfg_events G \\<and> ((cfg_item_look_ahead SSI = w \\<and> length w=Suc nat) \\<or> (cfg_item_look_ahead SSI = w@[Do] \\<and> length w<Suc nat)))\" for SSI)\n   apply(rename_tac y1 \\<beta> z A \\<alpha> a v1 v2 nat w v)(*strict*)\n   prefer 2\n   apply(rule_tac\n      I=\"\\<lparr>cfg_item_lhs = A, cfg_item_rhs1 = \\<alpha>, cfg_item_rhs2 = teB a # \\<beta>, cfg_item_look_ahead = z\\<rparr>\"\n      in lookaheads_are_kprefixes)\n      apply(rename_tac y1 \\<beta> z A \\<alpha> a v1 v2 nat w v)(*strict*)\n      apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n     apply(rename_tac y1 \\<beta> z A \\<alpha> a v1 v2 nat w v)(*strict*)\n     apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n    apply(rename_tac y1 \\<beta> z A \\<alpha> a v1 v2 nat w v)(*strict*)\n    apply(clarsimp)\n    apply(simp add: AF_LR_PARSER_input_def valid_cfg_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"\\<lparr>prod_lhs = A, prod_rhs = \\<alpha> @ teB a # \\<beta>\\<rparr>\"\n      and A=\"cfg_productions G\"\n      in ballE)\n     apply(rename_tac y1 \\<beta> z A \\<alpha> a v1 v2 nat w v)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac y1 \\<beta> z A \\<alpha> a v1 v2 nat w v)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac y1 \\<beta> z A \\<alpha> a v1 v2 nat w v)(*strict*)\n   apply(simp add: AF_LR_PARSER_input_def valid_cfg_def)\n  apply(rename_tac y1 \\<beta> z A \\<alpha> a v1 v2 nat w v)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac y1 \\<beta> z A \\<alpha> a v1 v2 nat w v wa)(*strict*)\n  apply(thin_tac \"\\<lparr>cfg_item_lhs = A, cfg_item_rhs1 = \\<alpha>, cfg_item_rhs2 = teB a # \\<beta>, cfg_item_look_ahead = z\\<rparr> \\<in> valid_item_set G' (Suc nat) (teB Do # v2 @ w2)\")\n  apply(rename_tac y1 \\<beta> z A \\<alpha> a v1 v2 nat w v wa)(*strict*)\n  apply(thin_tac \"\\<lparr>cfg_item_lhs = A2, cfg_item_rhs1 = w2, cfg_item_rhs2 = [], cfg_item_look_ahead = y1\\<rparr> \\<in> valid_item_set G' (Suc nat) (teB Do # v2 @ w2)\")\n  apply(rename_tac y1 \\<beta> z A \\<alpha> a v1 v2 nat w v wa)(*strict*)\n  apply(thin_tac \"valid_dfa M\")\n  apply(thin_tac \"every_state_in_some_accessible_configuration M\")\n  apply(thin_tac \"some_step_from_every_configuration M\")\n  apply(thin_tac \"valid_parser P\")\n  apply(clarsimp)\n  apply(rename_tac \\<beta> z A \\<alpha> a v1 v2 nat w v wa)(*strict*)\n  apply(thin_tac \"valid_item_set G' (Suc nat) (teB Do # v1) = valid_item_set G' (Suc nat) (teB Do # v2 @ w2)\")\n  apply(rename_tac \\<beta> z A \\<alpha> a v1 v2 nat w v wa)(*strict*)\n  apply(thin_tac \"teB Do \\<in> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')\")\n  apply(thin_tac \"set v1 \\<subseteq> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')\")\n  apply(thin_tac \"set v2 \\<subseteq> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')\")\n  apply(thin_tac \"set w2 \\<subseteq> two_elements_construct_domain (cfg_nonterminals G') (cfg_events G')\")\n  apply(simp add: cfgSTD_first_def)\n  apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa x d e1 n)(*strict*)\n  apply(subgoal_tac \"suffix x z\")\n   apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa x d e1 n)(*strict*)\n   apply(simp add: suffix_def)\n   apply(clarsimp)\n   apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c)(*strict*)\n   apply(subgoal_tac \"set c \\<subseteq> cfg_events G\")\n    apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c)(*strict*)\n    apply(subgoal_tac \"strict_prefix w (take nat c) \\<or> prefix (take nat c) w\")\n     apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c)(*strict*)\n     apply(erule_tac\n      P=\"strict_prefix w (take nat c)\"\n      in disjE)\n      apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c)(*strict*)\n      apply(simp add: strict_prefix_def)\n      apply(clarsimp)\n      apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c ca)(*strict*)\n      apply(case_tac ca)\n       apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c ca)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c ca aa list)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c aa list)(*strict*)\n      apply(subgoal_tac \"aa=Do\")\n       apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c aa list)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c list)(*strict*)\n       apply(subgoal_tac \"Do \\<in> cfg_events G\")\n        apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c list)(*strict*)\n        apply(subgoal_tac \"Do \\<notin> cfg_events G\")\n         apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c list)(*strict*)\n         apply(force)\n        apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c list)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def)\n        apply(clarsimp)\n        apply(subgoal_tac \"F_FRESH (cfg_events G) \\<notin> cfg_events G\")\n         apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c list)(*strict*)\n         apply(force)\n        apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c list)(*strict*)\n        apply(rule F_FRESH_is_fresh)\n        apply(simp add: F_LR_MACHINE_def F_CFG_AUGMENT_def two_elements_construct_domain_def valid_cfg_def)\n       apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c list)(*strict*)\n       apply(rule_tac\n      A=\"set c\"\n      in set_mp)\n        apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c list)(*strict*)\n        apply(force)\n       apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c list)(*strict*)\n       apply(rule_tac\n      A=\"set(take nat c)\"\n      in set_mp)\n        apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c list)(*strict*)\n        apply (metis List.set_take_subset)\n       apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c list)(*strict*)\n       apply(rule_tac\n      t=\"take nat c\"\n      and s=\"w@Do#list\"\n      in ssubst)\n        apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c list)(*strict*)\n        apply(force)\n       apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c list)(*strict*)\n       apply(simp (no_asm))\n      apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c aa list)(*strict*)\n      apply(rule_tac\n      t=\"aa\"\n      and s=\"((w @ aa # list) @ take (nat - length c) z)!(length w)\"\n      in ssubst)\n       apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c aa list)(*strict*)\n       apply (metis Cons_eq_appendI append_eq_appendI nth_append_length)\n      apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c aa list)(*strict*)\n      apply(rule_tac\n      t=\"Do\"\n      and s=\"(w @ Do # v)!(length w)\"\n      in ssubst)\n       apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c aa list)(*strict*)\n       apply (metis nth_append_length)\n      apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c aa list)(*strict*)\n      apply(rule_tac\n      t=\"(w @ Do # v)\"\n      and s=\"(w @ aa # list) @ take (nat - length c) z\"\n      in ssubst)\n       apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c aa list)(*strict*)\n       apply(force)\n      apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c aa list)(*strict*)\n      apply(force)\n     apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c)(*strict*)\n     apply(simp add: prefix_def)\n     apply(clarsimp)\n     apply(rename_tac \\<beta> z A \\<alpha> a v2 nat v wa d e1 n c ca)(*strict*)\n     apply(erule disjE)\n      apply(rename_tac \\<beta> z A \\<alpha> a v2 nat v wa d e1 n c ca)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac \\<beta> A \\<alpha> a v2 nat v wa d e1 n c ca)(*strict*)\n      apply(subgoal_tac \"Do \\<in> cfg_events G\")\n       apply(rename_tac \\<beta> A \\<alpha> a v2 nat v wa d e1 n c ca)(*strict*)\n       apply(subgoal_tac \"Do \\<notin> cfg_events G\")\n        apply(rename_tac \\<beta> A \\<alpha> a v2 nat v wa d e1 n c ca)(*strict*)\n        apply(force)\n       apply(rename_tac \\<beta> A \\<alpha> a v2 nat v wa d e1 n c ca)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def)\n       apply(clarsimp)\n       apply(subgoal_tac \"F_FRESH (cfg_events G) \\<notin> cfg_events G\")\n        apply(rename_tac \\<beta> A \\<alpha> a v2 nat v wa d e1 n c ca)(*strict*)\n        apply(force)\n       apply(rename_tac \\<beta> A \\<alpha> a v2 nat v wa d e1 n c ca)(*strict*)\n       apply(rule F_FRESH_is_fresh)\n       apply(simp add: F_LR_MACHINE_def F_CFG_AUGMENT_def two_elements_construct_domain_def valid_cfg_def)\n      apply(rename_tac \\<beta> A \\<alpha> a v2 nat v wa d e1 n c ca)(*strict*)\n      apply(rule_tac\n      A=\"set wa\"\n      in set_mp)\n       apply(rename_tac \\<beta> A \\<alpha> a v2 nat v wa d e1 n c ca)(*strict*)\n       apply(force)\n      apply(rename_tac \\<beta> A \\<alpha> a v2 nat v wa d e1 n c ca)(*strict*)\n      apply(rule_tac\n      A=\"set(take (nat - length c) wa)\"\n      in set_mp)\n       apply(rename_tac \\<beta> A \\<alpha> a v2 nat v wa d e1 n c ca)(*strict*)\n       apply (metis List.set_take_subset)\n      apply(rename_tac \\<beta> A \\<alpha> a v2 nat v wa d e1 n c ca)(*strict*)\n      apply(rule_tac\n      t=\"take (nat - length c) wa\"\n      and s=\"ca@Do#v\"\n      in ssubst)\n       apply(rename_tac \\<beta> A \\<alpha> a v2 nat v wa d e1 n c ca)(*strict*)\n       apply(force)\n      apply(rename_tac \\<beta> A \\<alpha> a v2 nat v wa d e1 n c ca)(*strict*)\n      apply(simp (no_asm))\n     apply(rename_tac \\<beta> z A \\<alpha> a v2 nat v wa d e1 n c ca)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac \\<beta> A \\<alpha> a v2 nat v wa d e1 n c ca)(*strict*)\n     apply(case_tac v)\n      apply(rename_tac \\<beta> A \\<alpha> a v2 nat v wa d e1 n c ca)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca)(*strict*)\n      apply(case_tac \"nat - (length c + length wa)\")\n       apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca)(*strict*)\n       apply(clarsimp)\n       apply(subgoal_tac \"Do \\<in> cfg_events G\")\n        apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca)(*strict*)\n        apply(subgoal_tac \"Do \\<notin> cfg_events G\")\n         apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca)(*strict*)\n         apply(force)\n        apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def)\n        apply(clarsimp)\n        apply(subgoal_tac \"F_FRESH (cfg_events G) \\<notin> cfg_events G\")\n         apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca)(*strict*)\n         apply(force)\n        apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca)(*strict*)\n        apply(rule F_FRESH_is_fresh)\n        apply(simp add: F_LR_MACHINE_def F_CFG_AUGMENT_def two_elements_construct_domain_def valid_cfg_def)\n       apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca)(*strict*)\n       apply(rule_tac\n      A=\"set wa\"\n      in set_mp)\n        apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca)(*strict*)\n        apply(force)\n       apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca)(*strict*)\n       apply(rule_tac\n      A=\"set(take (nat - length c) wa)\"\n      in set_mp)\n        apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca)(*strict*)\n        apply (metis List.set_take_subset)\n       apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca)(*strict*)\n       apply(rule_tac\n      t=\"take (nat - length c) wa\"\n      and s=\"ca@[Do]\"\n      in ssubst)\n        apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca)(*strict*)\n        apply(force)\n       apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca)(*strict*)\n       apply(simp (no_asm))\n      apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca nata)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac \\<beta> A \\<alpha> a v2 nat v wa d e1 n c ca aa list)(*strict*)\n     apply(subgoal_tac \"\\<exists>w' x'. v = w' @ [x']\")\n      apply(rename_tac \\<beta> A \\<alpha> a v2 nat v wa d e1 n c ca aa list)(*strict*)\n      prefer 2\n      apply(rule NonEmptyListHasTailElem)\n      apply(force)\n     apply(rename_tac \\<beta> A \\<alpha> a v2 nat v wa d e1 n c ca aa list)(*strict*)\n     apply(thin_tac \"v=aa#list\")\n     apply(clarsimp)\n     apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*)\n     apply(case_tac \"nat - (length c + length wa)\")\n      apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*)\n      apply(clarsimp)\n      apply(subgoal_tac \"Do \\<in> cfg_events G\")\n       apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*)\n       apply(subgoal_tac \"Do \\<notin> cfg_events G\")\n        apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*)\n        apply(force)\n       apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def)\n       apply(clarsimp)\n       apply(subgoal_tac \"F_FRESH (cfg_events G) \\<notin> cfg_events G\")\n        apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*)\n        apply(force)\n       apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*)\n       apply(rule F_FRESH_is_fresh)\n       apply(simp add: F_LR_MACHINE_def F_CFG_AUGMENT_def two_elements_construct_domain_def valid_cfg_def)\n      apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*)\n      apply(rule_tac\n      A=\"set wa\"\n      in set_mp)\n       apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*)\n       apply(force)\n      apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*)\n      apply(rule_tac\n      A=\"set(take (nat - length c) wa)\"\n      in set_mp)\n       apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*)\n       apply (metis List.set_take_subset)\n      apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*)\n      apply(rule_tac\n      t=\"take (nat - length c) wa\"\n      and s=\"ca @ Do # w' @ [x']\"\n      in ssubst)\n       apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*)\n       apply(force)\n      apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca w' x')(*strict*)\n      apply(simp (no_asm))\n     apply(rename_tac \\<beta> A \\<alpha> a v2 nat wa d e1 n c ca w' x' nata)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac \\<beta> A \\<alpha> a v2 nat d e1 n c ca w' nata)(*strict*)\n     apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def)\n     apply(clarsimp)\n     apply(subgoal_tac \"F_FRESH (cfg_events G) \\<notin> cfg_events G\")\n      apply(rename_tac \\<beta> A \\<alpha> a v2 nat d e1 n c ca w' nata)(*strict*)\n      apply(force)\n     apply(rename_tac \\<beta> A \\<alpha> a v2 nat d e1 n c ca w' nata)(*strict*)\n     apply(rule F_FRESH_is_fresh)\n     apply(simp add: F_LR_MACHINE_def F_CFG_AUGMENT_def two_elements_construct_domain_def valid_cfg_def)\n    apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c)(*strict*)\n    apply(rule mutual_strict_prefix_prefix)\n    apply(force)\n   apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c)(*strict*)\n   prefer 2\n   apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa x d e1 n)(*strict*)\n   apply(rule liftB_creates_suffix)\n   apply(subgoal_tac \"\\<exists>d' e. cfgRM.derivation G' d' \\<and> maximum_of_domain d' n \\<and> d' 0 = Some (pair None \\<lparr>cfg_conf=\\<beta> @ liftB z\\<rparr>) \\<and> d' n = Some (pair e \\<lparr>cfg_conf=liftB x\\<rparr>)\")\n    apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa x d e1 n)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"d\"\n      in cfg_derivation_can_be_translated_to_cfgRM_derivation)\n         apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa x d e1 n)(*strict*)\n         apply(simp add: AF_LR_PARSER_input_def)\n        apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa x d e1 n)(*strict*)\n        apply(force)\n       apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa x d e1 n)(*strict*)\n       apply(simp add: maximum_of_domain_def)\n      apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa x d e1 n)(*strict*)\n      apply(force)\n     apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa x d e1 n)(*strict*)\n     apply(force)\n    apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa x d e1 n)(*strict*)\n    apply (metis setA_liftB)\n   apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa x d e1 n)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa x d e1 n d' e)(*strict*)\n   apply(rule_tac\n      d=\"d'\"\n      and i=\"0\"\n      and j=\"n\"\n      in CFGRM_terminals_stay_at_end)\n        apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa x d e1 n d' e)(*strict*)\n        apply(force)\n       apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa x d e1 n d' e)(*strict*)\n       apply(force)\n      apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa x d e1 n d' e)(*strict*)\n      apply (metis setA_liftB)\n     apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa x d e1 n d' e)(*strict*)\n     apply(force)\n    apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa x d e1 n d' e)(*strict*)\n    apply(force)\n   apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa x d e1 n d' e)(*strict*)\n   apply(force)\n  apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c)(*strict*)\n  apply(subgoal_tac \"\\<exists>v. set v \\<subseteq> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G) \\<and> (case e1 of None \\<Rightarrow> True|Some e' \\<Rightarrow> e' \\<in> cfg_productions G) \\<and> SSc=\\<lparr>cfg_conf = v @ liftB z\\<rparr>\" for SSc)\n   apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      n=\"n\"\n      and d=\"d\"\n      in CFG_preserves_partial_belongs)\n        apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c)(*strict*)\n       prefer 2\n       apply(force)\n      apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c)(*strict*)\n     apply(simp add: AF_LR_PARSER_input_def valid_cfg_def)\n     apply(clarsimp)\n     apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c x)(*strict*)\n     apply(erule_tac\n      x=\"\\<lparr>prod_lhs = A, prod_rhs = \\<alpha> @ teB a # \\<beta>\\<rparr>\"\n      and A=\"cfg_productions G\"\n      in ballE)\n      apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c x)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c x)(*strict*)\n     apply(clarsimp)\n     apply(simp add: setAConcat setBConcat two_elements_construct_domain_def)\n     apply(clarsimp)\n     apply(case_tac x)\n      apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c x aa)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c aa)(*strict*)\n      apply(rule inMap)\n      apply(clarsimp)\n      apply (metis setA_set_not subsetE)\n     apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c x b)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c b)(*strict*)\n     apply (metis inMap2 set_setB set_mp_prime)\n    apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c p)(*strict*)\n    apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def)\n    apply(clarsimp)\n    apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT_def)\n    apply(clarsimp)\n    apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c)(*strict*)\n    apply(subgoal_tac \"F_FRESH (cfg_nonterminals G) \\<notin> cfg_nonterminals G\")\n     apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c)(*strict*)\n     apply(force)\n    apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c)(*strict*)\n    apply(rule F_FRESH_is_fresh)\n    apply(simp add: AF_LR_PARSER_def AF_LR_PARSER_input_def valid_cfg_def)\n   apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c)(*strict*)\n   apply(force)\n  apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c)(*strict*)\n  apply(erule exE)\n  apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c va)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c va x)(*strict*)\n  apply(simp add: liftB_commutes_over_concat take_liftB)\n  apply(clarsimp)\n  apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c x)(*strict*)\n  apply(subgoal_tac \"teB x \\<in> set(liftB c)\")\n   apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c x)(*strict*)\n   prefer 2\n   apply(rule set_liftB_insert)\n   apply(force)\n  apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c x)(*strict*)\n  apply(thin_tac \"x \\<in> set c\")\n  apply(subgoal_tac \"teB x \\<in> two_elements_construct_domain (cfg_nonterminals G) (cfg_events G)\")\n   apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c x)(*strict*)\n   apply(simp add: two_elements_construct_domain_def)\n   apply(erule_tac\n      P=\"teB x \\<in> teA ` cfg_nonterminals G\"\n      in disjE)\n    apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c x)(*strict*)\n    apply(force)\n   apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c x)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac \\<beta> z A \\<alpha> a v2 nat w v wa d e1 n c x)(*strict*)\n  apply(force)\n  done\n\ntheorem Lemma_6_36_ReduceReduce_Conflict_implies_nondeterminism: \"\n  AF_LR_PARSER_input G F Do S' G' M P k\n  \\<Longrightarrow> conflict_free G G' k\n  \\<Longrightarrow> parserS.is_forward_edge_deterministic_accessible P\"\n  apply(subgoal_tac \"valid_cfg G'\")\n   prefer 2\n   apply(rule F_CFG_AUGMENT__makes_CFG)\n   apply(simp add: F_CFG_AUGMENT__input_def AF_LR_PARSER_input_def)\n   apply(force)\n  apply(simp add: parserS.is_forward_edge_deterministic_accessible_def)\n  apply(clarsimp)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(rename_tac r1 r2)\n  apply(rename_tac c c1 c2 r1 r2)(*strict*)\n  apply(subgoal_tac \"r1 \\<in> parser_rules P\")\n   apply(rename_tac c c1 c2 r1 r2)(*strict*)\n   prefer 2\n   apply(simp add: parserS_step_relation_def)\n  apply(rename_tac c c1 c2 r1 r2)(*strict*)\n  apply(subgoal_tac \"r2 \\<in> parser_rules P\")\n   apply(rename_tac c c1 c2 r1 r2)(*strict*)\n   prefer 2\n   apply(simp add: parserS_step_relation_def)\n  apply(rename_tac c c1 c2 r1 r2)(*strict*)\n  apply(subgoal_tac \"(rule_lpop r2 \\<sqsupseteq> rule_lpop r1 \\<or> rule_lpop r1 \\<sqsupseteq> rule_lpop r2) \\<and> (rule_rpop r1 \\<sqsubseteq> rule_rpop r2 \\<or> rule_rpop r2 \\<sqsubseteq> rule_rpop r1)\")\n   apply(rename_tac c c1 c2 r1 r2)(*strict*)\n   prefer 2\n   apply(simp add: parserS_step_relation_def)\n   apply(case_tac c1)\n   apply(rename_tac c c1 c2 r1 r2 parserS_conf_stacka parserS_conf_schedulera)(*strict*)\n   apply(case_tac c2)\n   apply(rename_tac c c1 c2 r1 r2 parserS_conf_stacka parserS_conf_schedulera parserS_conf_stackaa parserS_conf_scheduleraa)(*strict*)\n   apply(case_tac c)\n   apply(rename_tac c c1 c2 r1 r2 parserS_conf_stacka parserS_conf_schedulera parserS_conf_stackaa parserS_conf_scheduleraa parserS_conf_stackb parserS_conf_schedulerb)(*strict*)\n   apply(rule context_conjI)\n    apply(rename_tac c c1 c2 r1 r2 parserS_conf_stacka parserS_conf_schedulera parserS_conf_stackaa parserS_conf_scheduleraa parserS_conf_stackb parserS_conf_schedulerb)(*strict*)\n    prefer 2\n    apply(erule conjE)+\n    apply(erule exE)+\n    apply(rename_tac c c1 c2 r1 r2 parserS_conf_stacka parserS_conf_schedulera parserS_conf_stackaa parserS_conf_scheduleraa parserS_conf_stackb parserS_conf_schedulerb x xa xb xc)(*strict*)\n    apply(rule_tac\n      b=\"xa\"\n      and d=\"xc\"\n      in mutual_prefix_prefix)\n    apply(force)\n   apply(rename_tac c c1 c2 r1 r2 parserS_conf_stacka parserS_conf_schedulera parserS_conf_stackaa parserS_conf_scheduleraa parserS_conf_stackb parserS_conf_schedulerb)(*strict*)\n   apply(erule conjE)+\n   apply(erule exE)+\n   apply(rename_tac c c1 c2 r1 r2 parserS_conf_stacka parserS_conf_schedulera parserS_conf_stackaa parserS_conf_scheduleraa parserS_conf_stackb parserS_conf_schedulerb x xa xb xc)(*strict*)\n   apply(subgoal_tac \"x @ rule_lpop r1 = xb @ rule_lpop r2\")\n    apply(rename_tac c c1 c2 r1 r2 parserS_conf_stacka parserS_conf_schedulera parserS_conf_stackaa parserS_conf_scheduleraa parserS_conf_stackb parserS_conf_schedulerb x xa xb xc)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac c c1 c2 r1 r2 parserS_conf_stacka parserS_conf_schedulera parserS_conf_stackaa parserS_conf_scheduleraa parserS_conf_stackb parserS_conf_schedulerb x xa xb xc)(*strict*)\n   apply(rule_tac\n      a=\"xb\"\n      in mutual_suffix_suffix)\n   apply(rule sym)\n   apply(force)\n  apply(rename_tac c c1 c2 r1 r2)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"(parser_marker P) r1\")\n   apply(rename_tac c c1 c2 r1 r2)(*strict*)\n   apply(subgoal_tac \"parser_marker P r1 \\<noteq> None\")\n    apply(rename_tac c c1 c2 r1 r2)(*strict*)\n    apply(force)\n   apply(rename_tac c c1 c2 r1 r2)(*strict*)\n   apply(rule_tac\n      G=\"G\"\n      in X6_3_InformationOnRules_EffectNotNone)\n          apply(rename_tac c c1 c2 r1 r2)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(simp add: AF_LR_PARSER_input_def)\n         apply(force)\n        apply(rename_tac c c1 c2 r1 r2)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(rename_tac c c1 c2 r1 r2)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(rename_tac c c1 c2 r1 r2)(*strict*)\n      apply(simp add: AF_LR_PARSER_input_def)\n     apply(rename_tac c c1 c2 r1 r2)(*strict*)\n     apply(simp add: AF_LR_PARSER_input_def)\n    apply(rename_tac c c1 c2 r1 r2)(*strict*)\n    apply(simp add: AF_LR_PARSER_input_def)\n   apply(rename_tac c c1 c2 r1 r2)(*strict*)\n   apply(force)\n  apply(rename_tac c c1 c2 r1 r2 a)(*strict*)\n  apply(case_tac \"(parser_marker P) r2\")\n   apply(rename_tac c c1 c2 r1 r2 a)(*strict*)\n   apply(subgoal_tac \"parser_marker P r2 \\<noteq> None\")\n    apply(rename_tac c c1 c2 r1 r2 a)(*strict*)\n    apply(force)\n   apply(rename_tac c c1 c2 r1 r2 a)(*strict*)\n   apply(rule_tac\n      G=\"G\"\n      in X6_3_InformationOnRules_EffectNotNone)\n          apply(rename_tac c c1 c2 r1 r2 a)(*strict*)\n          apply(simp add: AF_LR_PARSER_input_def)\n         apply(simp add: AF_LR_PARSER_input_def)\n         apply(force)\n        apply(rename_tac c c1 c2 r1 r2 a)(*strict*)\n        apply(simp add: AF_LR_PARSER_input_def)\n       apply(rename_tac c c1 c2 r1 r2 a)(*strict*)\n       apply(simp add: AF_LR_PARSER_input_def)\n      apply(rename_tac c c1 c2 r1 r2 a)(*strict*)\n      apply(simp add: AF_LR_PARSER_input_def)\n     apply(rename_tac c c1 c2 r1 r2 a)(*strict*)\n     apply(simp add: AF_LR_PARSER_input_def)\n    apply(rename_tac c c1 c2 r1 r2 a)(*strict*)\n    apply(simp add: AF_LR_PARSER_input_def)\n   apply(rename_tac c c1 c2 r1 r2 a)(*strict*)\n   apply(force)\n  apply(rename_tac c c1 c2 r1 r2 a aa)(*strict*)\n  apply(case_tac a)\n   apply(rename_tac c c1 c2 r1 r2 a aa)(*strict*)\n   apply(case_tac aa)\n    apply(rename_tac c c1 c2 r1 r2 a aa)(*strict*)\n    apply(rule no_shift_shift_conflicts)\n          apply(rename_tac c c1 c2 r1 r2 a aa)(*strict*)\n          apply(force)\n         apply(rename_tac c c1 c2 r1 r2 a aa)(*strict*)\n         apply(force)\n        apply(rename_tac c c1 c2 r1 r2 a aa)(*strict*)\n        apply(force)\n       apply(rename_tac c c1 c2 r1 r2 a aa)(*strict*)\n       apply(force)\n      apply(rename_tac c c1 c2 r1 r2 a aa)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 r1 r2 a aa)(*strict*)\n     apply(force)\n    apply(rename_tac c c1 c2 r1 r2 a aa)(*strict*)\n    apply(force)\n   apply(rename_tac c c1 c2 r1 r2 a aa ab)(*strict*)\n   apply(case_tac ab)\n   apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*)\n   apply(rule no_shift_reduce_conflicts)\n          apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*)\n          apply(force)\n         apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*)\n         apply(force)\n        apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*)\n        apply(force)\n       apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*)\n       apply(force)\n      apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*)\n     apply(force)\n    apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*)\n    apply(force)\n   apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*)\n   apply(force)\n  apply(rename_tac c c1 c2 r1 r2 a aa ab)(*strict*)\n  apply(case_tac aa)\n   apply(rename_tac c c1 c2 r1 r2 a aa ab)(*strict*)\n   apply(rule sym)\n   apply(case_tac ab)\n   apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*)\n   apply(rule no_shift_reduce_conflicts)\n          apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*)\n          apply(force)\n         apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*)\n         apply(force)\n        apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*)\n        apply(force)\n       apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*)\n       apply(force)\n      apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*)\n     apply(force)\n    apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*)\n    apply(force)\n   apply(rename_tac c c1 c2 r1 r2 a aa ab prod_lhs prod_rhs)(*strict*)\n   apply(force)\n  apply(rename_tac c c1 c2 r1 r2 a aa ab ac)(*strict*)\n  apply(case_tac ab)\n  apply(rename_tac c c1 c2 r1 r2 a aa ab ac prod_lhs prod_rhs)(*strict*)\n  apply(case_tac ac)\n  apply(rename_tac c c1 c2 r1 r2 a aa ab ac prod_lhs prod_rhs prod_lhsa prod_rhsa)(*strict*)\n  apply(rule no_reduce_reduce_conflicts)\n         apply(rename_tac c c1 c2 r1 r2 a aa ab ac prod_lhs prod_rhs prod_lhsa prod_rhsa)(*strict*)\n         apply(force)\n        apply(rename_tac c c1 c2 r1 r2 a aa ab ac prod_lhs prod_rhs prod_lhsa prod_rhsa)(*strict*)\n        apply(force)\n       apply(rename_tac c c1 c2 r1 r2 a aa ab ac prod_lhs prod_rhs prod_lhsa prod_rhsa)(*strict*)\n       apply(force)\n      apply(rename_tac c c1 c2 r1 r2 a aa ab ac prod_lhs prod_rhs prod_lhsa prod_rhsa)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 r1 r2 a aa ab ac prod_lhs prod_rhs prod_lhsa prod_rhsa)(*strict*)\n     apply(force)\n    apply(rename_tac c c1 c2 r1 r2 a aa ab ac prod_lhs prod_rhs prod_lhsa prod_rhsa)(*strict*)\n    apply(force)\n   apply(rename_tac c c1 c2 r1 r2 a aa ab ac prod_lhs prod_rhs prod_lhsa prod_rhsa)(*strict*)\n   apply(force)\n  apply(rename_tac c c1 c2 r1 r2 a aa ab ac prod_lhs prod_rhs prod_lhsa prod_rhsa)(*strict*)\n  apply(force)\n  done\n\ntheorem F_LR_PARSER_is_forward_edge_deterministic_accessible: \"\n  AF_LR_PARSER_input G F Do S' G' M P k\n  \\<Longrightarrow> cfgSTD.Nonblockingness_branching G\n  \\<Longrightarrow> cfg_LRk G k\n  \\<Longrightarrow> parserS.is_forward_edge_deterministic_accessible P\"\n  apply(rule Lemma_6_36_ReduceReduce_Conflict_implies_nondeterminism)\n   apply(force)\n  apply(rule cfg_LRk_implies_conflict_free)\n   apply(simp add: AF_LR_PARSER_input_def F_CFG_AUGMENT__input_def)\n  apply(force)\n  done\n\nend\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_12_06_05/FUNCTION__LR_PARSER__part4.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953797290153, "lm_q2_score": 0.4532618480153861, "lm_q1q2_score": 0.26175662303632063}}
{"text": "theory Distributed_WebApp\nimports \"../TopoS_Impl\"\nbegin\n\nsection\\<open>Distributed Web Application Example\\<close>\n\ntext\\<open>\n    The symbolic policy names are of type @{typ string}, e.g. @{term \"''WebFrnt''\"}\n\\<close>\n\ntext\\<open>We start with the empty policy, only the entities are defined.\\<close>\ndefinition policy :: \"string list_graph\" where\n    \"policy \\<equiv> \\<lparr> nodesL = [''WebFrnt'', ''DB'', ''Log'', ''WebApp'', ''INET''],\n                edgesL = [] \\<rparr>\"\n\ntext\\<open>Sanity check\\<close>\nlemma \"wf_list_graph policy\" by eval\n(*proof by eval means we have executable code to show the lemma. No need to show anything by hand*)\n\n\ntext\\<open>Defining the security invariants\\<close>\ndefinition LogSink_m::\"(string SecurityInvariant)\" where\n  \"LogSink_m \\<equiv> new_configured_list_SecurityInvariant SINVAR_LIB_Sink \\<lparr> \n          node_properties = [''Log'' \\<mapsto> Sink]\n          \\<rparr> ''No information must leave the logging server''\"\n\ntext\\<open>\n0 - unclassified\n1 - confidential\n\\<close>\n\\<comment> \\<open>trusted: can access any security level, privacy-level 0: can reveal to anyone. I.e. can declassify\\<close>\ndefinition BLP_m::\"(string SecurityInvariant)\" where\n    \"BLP_m \\<equiv> new_configured_list_SecurityInvariant SINVAR_LIB_BLPtrusted \\<lparr> \n          node_properties = [''DB'' \\<mapsto> \\<lparr> security_level = 1, trusted = False \\<rparr>,\n                             ''Log'' \\<mapsto> \\<lparr> security_level = 1, trusted = False \\<rparr>,\n                             ''WebApp'' \\<mapsto> \\<lparr> security_level = 0, trusted = True \\<rparr> \n                             ]\n          \\<rparr> ''The database and the logging server have confidential information''\"\n\ndefinition Subnet_m::\"(string SecurityInvariant)\" where\n    \"Subnet_m \\<equiv> new_configured_list_SecurityInvariant SINVAR_LIB_SubnetsInGW \\<lparr> \n          node_properties = [''DB'' \\<mapsto> Member,\n                             ''Log'' \\<mapsto> Member,\n                             ''WebApp'' \\<mapsto> Member,\n                             ''WebFrnt'' \\<mapsto> InboundGateway \\<comment> \\<open>DMZ\\<close>\n                             ]\n          \\<rparr> ''internal/DMZ structure''\"\n\n\ndefinition DBACL_m::\"(string SecurityInvariant)\" where\n    \"DBACL_m \\<equiv> new_configured_list_SecurityInvariant SINVAR_LIB_CommunicationPartners \\<lparr> \n          node_properties = [''DB'' \\<mapsto> Master [''WebApp''],\n                             ''WebApp'' \\<mapsto> Care\n                             ]\n          \\<rparr> ''ACL of db''\"\n\ntext\\<open>The list of security invariants\\<close>\ndefinition \"security_invariants = [Subnet_m, BLP_m, LogSink_m, DBACL_m]\"\n\ntext\\<open>All security invariants are fulfilled (obviously, the policy permits no flows).\\<close>\nlemma \"all_security_requirements_fulfilled security_invariants policy\" by eval\n\ntext\\<open>Obviously, no policy rules violate the security invariants.\\<close>\nlemma \"implc_get_offending_flows security_invariants policy = []\" by eval\n\n\ntext\\<open>We generate the maximum security policy.\\<close>\ndefinition \"max_policy = generate_valid_topology security_invariants \\<lparr>nodesL = nodesL policy, edgesL = List.product (nodesL policy) (nodesL policy) \\<rparr>\"\n\n\ntext\\<open>Calculating the maximum policy (executing it).\\<close>\nvalue \"max_policy\"\nlemma \"max_policy = \n   \\<lparr>nodesL = [''WebFrnt'', ''DB'', ''Log'', ''WebApp'', ''INET''],\n    edgesL = [(''WebFrnt'', ''WebFrnt''), (''WebFrnt'', ''Log''), (''WebFrnt'', ''WebApp''), (''WebFrnt'', ''INET''), (''DB'', ''DB''),\n              (''DB'', ''Log''), (''DB'', ''WebApp''), (''Log'', ''Log''), (''WebApp'', ''WebFrnt''), (''WebApp'', ''DB''),\n              (''WebApp'', ''Log''), (''WebApp'', ''WebApp''), (''WebApp'', ''INET''), (''INET'', ''WebFrnt''), (''INET'', ''INET'')]\\<rparr>\"\nby eval (*proof by eval means it can be directly executed*)\n\ntext\\<open>\nVisualizing the maximum policy\n\\<close>\nML\\<open>\nvisualize_graph @{context} @{term \"security_invariants\"} @{term \"max_policy\"};\n\\<close>\n\ntext\\<open>The maximum policy also fulfills all security invariants.\\<close>\nlemma \"all_security_requirements_fulfilled security_invariants max_policy\" by eval\ntext\\<open>This holds in general: @{thm generate_valid_topology_sound}.\\<close>\n\ntext\\<open>fine-tuning generated policy.\\<close>\ndefinition \"my_policy = \\<lparr>nodesL = [''WebFrnt'', ''DB'', ''Log'', ''WebApp'', ''INET''],\n    edgesL = [(''WebFrnt'', ''WebFrnt''), (''WebFrnt'', ''Log''), (''WebFrnt'', ''WebApp''), (''DB'', ''DB''), (''DB'', ''Log''),\n              (''DB'', ''WebApp''), (''Log'', ''Log''), (''WebApp'', ''WebFrnt''), (''WebApp'', ''DB''), (''WebApp'', ''Log''), (''WebApp'', ''WebApp''),\n              (''WebApp'', ''INET''), (''INET'', ''WebFrnt''), (''INET'', ''INET'')]\\<rparr>\"\nlemma \"all_security_requirements_fulfilled security_invariants my_policy\" by eval\nlemma \"set (edgesL my_policy) \\<subset> set (edgesL max_policy)\" by eval\n\ntext\\<open>\nThe diff to the maximum policy.\n\\<close>\nML_val\\<open>\nvisualize_edges @{context} @{term \"edgesL my_policy\"} \n    [(\"edge [dir=\\\"arrow\\\", style=dashed, color=\\\"#3399FF\\\", constraint=false]\", @{term \"[e \\<leftarrow> edgesL max_policy. e \\<notin> set (edgesL my_policy)]\"})] \"\"; \n\\<close>\n\n\n\nsection\\<open>A stateful implementation\\<close>\ndefinition \"stateful_policy = generate_valid_stateful_policy_IFSACS my_policy security_invariants\"\nvalue \"stateful_policy\"\n\ntext\\<open>the stateful compliance criteria\\<close>\n\ntext\\<open>No information flow violations\\<close>\n  lemma \"all_security_requirements_fulfilled (get_IFS security_invariants) (stateful_list_policy_to_list_graph stateful_policy)\" by eval\n  \n  text\\<open>No access control side effects\\<close>\n  lemma \"\\<forall> F \\<in> set (implc_get_offending_flows (get_ACS security_invariants) (stateful_list_policy_to_list_graph stateful_policy)).\n            set F \\<subseteq> set (backlinks (flows_stateL stateful_policy)) - (set (flows_fixL stateful_policy))\" by eval\n\n  text\\<open>In general, the calculated stateful policy complies with the security policy: @{thm generate_valid_stateful_policy_IFSACS_stateful_policy_compliance}\\<close>\n\ntext\\<open>Visualizing the stateful policy.\\<close>\nML_val\\<open>\nvisualize_edges @{context} @{term \"flows_fixL stateful_policy\"} \n    [(\"edge [dir=\\\"arrow\\\", style=dashed, color=\\\"#FF8822\\\", constraint=false]\", @{term \"flows_stateL stateful_policy\"})] \"\"; \n\\<close>\n\n\nsubsection\\<open>Exporting to Network Security Mechanism Configurations\\<close>\n\n\ntext\\<open>Space-separated policy dump\\<close>\nML_val\\<open>\niterate_edges_ML @{context} @{term \"flows_fixL stateful_policy\"}\n  (fn (v1,v2) => writeln (\"\"^v1^\" \"^v2) )\n  (fn _ => () )\n  (fn _ => () );\n\nwriteln \"# stateful answers\";\niterate_edges_ML @{context} @{term \"flows_stateL stateful_policy\"}\n  (fn (v1,v2) => writeln (v2^\" \"^v1) )\n  (fn _ => () )\n  (fn _ => () )\n\\<close>\n\ntext\\<open>firewall -- classical use case\\<close>\nML_val\\<open>\n\n(*header*)\nwriteln (\"echo 1 > /proc/sys/net/ipv4/ip_forward\"^\"\\n\"^\n         \"# flush all rules\"^\"\\n\"^\n         \"iptables -F\"^\"\\n\"^\n         \"#default policy for FORWARD chain:\"^\"\\n\"^\n         \"iptables -P FORWARD DROP\");\n\niterate_edges_ML @{context}  @{term \"flows_fixL stateful_policy\"}\n  (fn (v1,v2) => writeln (\"iptables -A FORWARD -i $\"^v1^\"_iface -s $\"^v1^\"_ipv4 -o $\"^v2^\"_iface -d $\"^v2^\"_ipv4 -j ACCEPT\"^\" # \"^v1^\" -> \"^v2) )\n  (fn _ => () )\n  (fn _ => () );\n\niterate_edges_ML @{context} @{term \"flows_stateL stateful_policy\"}\n  (fn (v1,v2) => writeln (\"iptables -I FORWARD -m state --state ESTABLISHED -i $\"^v2^\"_iface -s $\"^v2^\"_ipv4 -o $\"^v1^\"_iface -d $\"^v1^\"_ipv4 -j ACCEPT # \"^v2^\" -> \"^v1^\" (answer)\") )\n  (fn _ => () )\n  (fn _ => () )\n\\<close>\n\ntext\\<open>firewall -- OpenVPN scenario\\<close>\nML_val\\<open>\n\n(*header*)\nwriteln (\"echo 1 > /proc/sys/net/ipv4/ip_forward\"^\"\\n\"^\n         \"# flush all rules\"^\"\\n\"^\n         \"iptables -F\"^\"\\n\"^\n         \"#default policy for FORWARD chain:\"^\"\\n\"^\n         \"iptables -P FORWARD DROP\");\n\nfun iface (s: string): string =\n  if s = \"INET\" then \"eth0\" else \"tun0\";\n\niterate_edges_ML @{context} @{term \"[(s,r) \\<leftarrow> flows_fixL stateful_policy. s \\<noteq> r]\"}\n  (fn (v1,v2) => writeln (\"iptables -A FORWARD -i \"^iface v1^\" -s $\"^v1^\"_ipv4 -o \"^iface v2^\" -d $\"^v2^\"_ipv4 -j ACCEPT\") )\n  (fn _ => () )\n  (fn _ => () );\n\niterate_edges_ML @{context} @{term \"flows_stateL stateful_policy\"}\n  (fn (v1,v2) => writeln (\"iptables -I FORWARD -m state --state ESTABLISHED -i \"^iface v2^\" -s $\"^v2^\"_ipv4 -o \"^iface v1^\" -d $\"^v1^\"_ipv4 -j ACCEPT\") )\n  (fn _ => () )\n  (fn _ => () )\n\\<close>\n\n\nlemma \"set (flows_stateL stateful_policy) \\<subseteq> set (flows_fixL stateful_policy)\" by eval\n\ndefinition stateful_flows :: \"(string \\<times> string) list\" where\n  \"stateful_flows \\<equiv> [(src, dst) \\<leftarrow> flows_stateL stateful_policy. src \\<noteq> dst]\"\nvalue \"stateful_flows\"\n\ndefinition stateless_flows :: \"(string \\<times> string) list\" where\n  \"stateless_flows \\<equiv> [(src, dst) \\<leftarrow> flows_fixL stateful_policy. src \\<noteq> dst \\<and> (src, dst) \\<notin> set stateful_flows]\"\nvalue \"stateless_flows\"\n\ntext\\<open>OpenFlow Flow table Rules\\<close>\nML_val\\<open>\nfun ARP (src: string) (dst: string): string =\n  \"# ARP Request\\n\"^\n  \"in_port=${port_\"^src^\"} dl_src=${mac_\"^src^\"} dl_dst=ff:ff:ff:ff:ff:ff arp arp_sha=${mac_\"^src^\"} \"^\n  \"arp_spa=${ip4_\"^src^\"} arp_tpa=${ip4_\"^dst^\"} priority=40000 action=mod_dl_dst:${mac_\"^dst^\"},output:${port_\"^dst^\"}\"^\"\\n\"^\n  \"# ARP Reply\\n\"^\n  \"dl_src=${mac_\"^dst^\"} dl_dst=${mac_\"^src^\"} arp arp_sha=${mac_\"^dst^\"} \"^\n  \"arp_spa=${ip4_\"^dst^\"} arp_tpa=${ip4_\"^src^\"} priority=40000 action=output:${port_\"^src^\"}\";\n\nlocal\n  fun IPv4_helper (priority: int) (nw_src_wildcard: bool) (nw_dst_wildcard: bool) (src: string) (dst: string): string =\n    let\n      val nw_src = (if nw_src_wildcard then \"*\" else \"${ip4_\"^src^\"}\");\n      val nw_dst = (if nw_dst_wildcard then \"*\" else \"${ip4_\"^dst^\"}\");\n    in\n      \"in_port=${port_\"^src^\"} dl_src=${mac_\"^src^\"} ip nw_src=\"^nw_src^\" \"^\n      \"nw_dst=\"^nw_dst^\" priority=\"^(Int.toString priority)^\" action=mod_dl_dst:${mac_\"^dst^\"},output:${port_\"^dst^\"}\"\n    end;\nin\n  fun IPv4 (src: string) (dst: string): string =\n    if dst = \"INET\" then\n      IPv4_helper 30000 false true src dst\n    else if src = \"INET\" then\n      IPv4_helper 30000 true false src dst\n    else\n      IPv4_helper 40000 false false src dst\n      ;\nend;\n\niterate_edges_ML @{context} @{term \"stateful_flows\"}\n  (fn (v1,v2) => writeln ((ARP v1 v2) ^ \"\\n\" ^ (ARP v2 v1) ^ \"\\n\" ^ (IPv4 v1 v2) ^ \"\\n\" ^ (IPv4 v2 v1) ^\"\\n\"))\n  (fn _ => () )\n  (fn _ => () );\n\niterate_edges_ML @{context} @{term \"stateless_flows\"}\n  (fn (v1,v2) =>  writeln ((ARP v1 v2) ^ \"\\n\" ^ (IPv4 v1 v2) ^ \"\\n\"))\n  (fn _ => () )\n  (fn _ => () )\n\\<close>\n\n\ntext\\<open>Finally, all the functions demonstrated here can be exported to several programming languages\n     to obtain a stand-alone tool.\\<close>\nexport_code\n  security_invariants\n  policy\n  all_security_requirements_fulfilled\n  implc_get_offending_flows\n  max_policy\n  my_policy\n  generate_valid_stateful_policy_IFSACS\n  stateful_policy\n  stateful_flows\n  stateless_flows\nin Scala\n\n\n\n\n\n\n(*dockermynet4*)\n\n\ndefinition dockermynet4policy :: \"string list_graph\" where\n    \"dockermynet4policy \\<equiv> \\<lparr> nodesL = [''WebFrnt'', ''DB'', ''Log'', ''WebApp'', ''INET''],\n                edgesL = [(''INET'',''INET''),\n                          (''INET'',''WebFrnt''),\n                          (''WebApp'',''INET''),\n                          (''WebApp'',''WebApp''),\n                          (''WebApp'',''DB''),\n                          (''WebApp'',''Log''),\n                          (''WebApp'',''WebFrnt''),\n                          (''DB'',''WebApp''),\n                          (''DB'',''DB''),\n                          (''DB'',''Log''),\n                          (''Log'',''Log''),\n                          (''Log'',''WebFrnt''),\n                          (''WebFrnt'',''WebApp''),\n                          (''WebFrnt'',''Log''),\n                          (''WebFrnt'',''WebFrnt'')] \\<rparr>\"\n\nlemma \"wf_list_graph dockermynet4policy\" by eval\n\nML\\<open>\nvisualize_graph @{context} @{term \"security_invariants\"} @{term \"dockermynet4policy\"};\n\\<close>\n\nML_val\\<open>\nwriteln (\"*filter\"^\"\\n\"^\n         \":INPUT ACCEPT [0:0]\"^\"\\n\"^\n         \":FORWARD DROP [0:0]\"^\"\\n\"^\n         \":OUTPUT ACCEPT [0:0]\"^\"\\n\");\n\nfun mkiface s = if s = \"INET\" then \"INET_iface\" else \"br-b74b417b331f\";\n\niterate_edges_ML @{context}  @{term \"flows_fixL (generate_valid_stateful_policy_IFSACS max_policy security_invariants)\"}\n  (fn (v1,v2) => writeln (\"-A FORWARD -i \"^mkiface v1^\" -s $\"^v1^\"_ipv4 -o \"^mkiface v2^\" -d $\"^v2^\"_ipv4 -j ACCEPT\") )\n  (fn _ => () )\n  (fn _ => () );\n\niterate_edges_ML @{context} @{term \"flows_stateL (generate_valid_stateful_policy_IFSACS max_policy security_invariants)\"}\n  (fn (v1,v2) => writeln (\"-I FORWARD -m state --state ESTABLISHED -i \"^mkiface v2^\" -s $\"^v2^\"_ipv4 -o \"^mkiface v1^\" -d $\"^v1^\"_ipv4 -j ACCEPT\") )\n  (fn _ => () )\n  (fn _ => () );\n\nwriteln (\"COMMIT\"^\"\\n\");\n\\<close>\n\n\nML_val\\<open>\nvisualize_edges @{context} @{term \"flows_fixL (generate_valid_stateful_policy_IFSACS max_policy security_invariants)\"} \n    [(\"edge [dir=\\\"arrow\\\", style=dashed, color=\\\"#FF8822\\\", constraint=false]\", @{term \"flows_stateL (generate_valid_stateful_policy_IFSACS max_policy security_invariants)\"})] \"\"; \n\\<close>\n\n(*dfwfw (docker firewall) rules: https://github.com/irsl/dfwfw*)\n\nML_val\\<open>\nwriteln (\"{\"^\"\\n\"^\n         \"\\\"container_to_container\\\": {\"^\"\\n\"^\n         \"\\\"rules\\\": [\"^\"\\n\"^\n         \"\\n\");\n\nfun mkdfwfwrule filter v1 v2 = \"{\"^\"\\n\"^\n             \"  \\\"network\\\": \\\"mynet\\\",\"^\"\\n\"^\n             \"  \\\"src_container\\\": \\\"Name =~ ^\"^ String.map Char.toLower v1 ^\"-?\\\\\\\\d*$\\\",\"^\"\\n\"^\n             \"  \\\"dst_container\\\": \\\"Name =~ ^\"^ String.map Char.toLower v2 ^\"-?\\\\\\\\d*$\\\",\"^\"\\n\"^\n             \"  \\\"filter\\\": \\\"\"^filter^\"\\\",\"^\"\\n\"^\n             \"  \\\"action\\\": \\\"ACCEPT\\\"\"^\"\\n\"^\n          \"},\";\n\niterate_edges_ML @{context}  @{term \"flows_fixL (generate_valid_stateful_policy_IFSACS max_policy security_invariants)\"}\n  (fn (v1,v2) => writeln (mkdfwfwrule \"\" v1 v2) )\n  (fn _ => () )\n  (fn _ => () );\n\niterate_edges_ML @{context} @{term \"flows_stateL (generate_valid_stateful_policy_IFSACS max_policy security_invariants)\"}\n  (fn (v1,v2) => writeln (mkdfwfwrule \"-m state --state ESTABLISHED\" v2 v1))\n  (fn _ => () )\n  (fn _ => () );\n\nwriteln (\"]}}\"^\"\\n\");\n\\<close>\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Network_Security_Policy_Verification/Examples/Distributed_WebApp.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.577495350642608, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.26175660985256194}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory TailrecPre\nimports\n  \"Word_Lib.WordSetup\"\n  \"Lib.Lib\"\nbegin\n\ndefinition\n  \"tailrec_pre (f1 :: 'a \\<Rightarrow> 'a) guard precondition (x::'a) \\<equiv>\n    (\\<forall>k. (\\<forall>m. m < k \\<longrightarrow> guard ((f1 ^^ m) x)) \\<longrightarrow> precondition ((f1 ^^ k) x)) \\<and>\n    (\\<exists>n. \\<not> guard ((f1 ^^ n) x))\"\n\ndefinition\n  \"short_tailrec_pre (f :: 'a \\<Rightarrow> ('a + 'b) \\<times> bool) \\<equiv>\n     tailrec_pre (theLeft o fst o f) (isLeft o fst o f) (snd o f)\"\n\npartial_function (tailrec)\n  tailrec :: \"('a \\<Rightarrow> 'a) \\<Rightarrow> ('a \\<Rightarrow> 'b) \\<Rightarrow> ('a \\<Rightarrow> bool) \\<Rightarrow> 'a \\<Rightarrow> 'b\"\nwhere\n \"tailrec f1 f2 g x = (if g x then tailrec f1 f2 g (f1 x) else f2 x)\"\n\nlemma tailrec_steps:\n  \"g x \\<Longrightarrow> tailrec f1 f2 g x = tailrec f1 f2 g (f1 x)\"\n  \"\\<not> g x \\<Longrightarrow> tailrec f1 f2 g x = f2 x\"\n  by (simp_all add: tailrec.simps cong: if_weak_cong split del: if_split)\n\ndefinition\n  \"short_tailrec (f :: 'a \\<Rightarrow> ('a + 'b) \\<times> bool) \\<equiv>\n     tailrec (theLeft o fst o f) (theRight o fst o f) (isLeft o fst o f)\"\n\ndefinition\n  \"short_tailrec_pair stp v = (short_tailrec_pre stp v, short_tailrec stp v)\"\n\nlemma tailrec_pre_lemma:\n  \"!f1 g p x. tailrec_pre f1 g p (x::'a) = (p x \\<and> (g x \\<longrightarrow> tailrec_pre f1 g p (f1 x)))\"\n  apply (clarsimp simp add: tailrec_pre_def)\n  apply (rule iffI)\n   apply (rule conjI)\n    apply auto[1]\n   apply clarsimp\n   apply (rule conjI[rotated])\n    apply (case_tac n)\n     apply simp\n    apply (clarsimp simp: funpow_swap1)\n    apply auto[1]\n   apply clarsimp\n   apply (drule_tac x=\"Suc n\" for n in spec, simp add: funpow_swap1)\n   apply (erule mp)\n   apply clarsimp\n   apply (case_tac m, simp_all add: funpow_swap1)[1]\n  apply (case_tac \"g x\")\n   apply clarsimp\n   apply (rule conjI)\n    apply clarsimp\n    apply (case_tac k)\n     apply auto[1]\n    apply (simp_all add: funpow_swap1)[1]\n    apply (erule allE, erule impE)\n     prefer 2\n     apply assumption\n    apply (rule allI)\n    apply (rule impI)\n    apply (drule_tac x=\"Suc m\" in spec, simp_all add: funpow_swap1)\n   apply (rule_tac x=\"Suc n\" in exI)\n   apply (simp add: funpow_swap1)\n  apply (rule conjI)\n   prefer 2\n   apply (rule_tac x=\"0\" in exI)\n   apply auto[1]\n  apply (rule allI)\n  apply (rule impI)\n  apply (case_tac k)\n  apply auto\n  done\n\nlemma tailrec_pre_lemmata:\n  \"g x \\<Longrightarrow> tailrec_pre f1 g p (x::'a) = (p x \\<and> tailrec_pre f1 g p (f1 x))\"\n  \"\\<not> g x \\<Longrightarrow> tailrec_pre f1 g p (x::'a) = p x\"\n  by (metis tailrec_pre_lemma)+\n\ntheorem short_tailrec_thm:\n  \"\\<forall>f x. short_tailrec f x = (if isLeft (fst (f x))\n     then short_tailrec f (theLeft (fst (f x)))\n     else theRight (fst (f x))) \\<and>\n   (short_tailrec_pre f x = (snd (f x)\n     \\<and> (isLeft (fst (f x)) \\<longrightarrow> short_tailrec_pre f (theLeft (fst (f x))))))\"\n  apply (clarsimp simp add: short_tailrec_pre_def short_tailrec_def)\n  apply (simp add: tailrec_pre_lemmata tailrec_steps)\n  done\n\nlemma short_tailrec_pair_single_step:\n  \"\\<forall>v. \\<not> isLeft (fst (f v))\n    \\<Longrightarrow> short_tailrec_pair f = (\\<lambda>v. let (rv, b) = (f v) in (b, theRight rv))\"\n  apply (rule ext)\n  apply (simp add: short_tailrec_pair_def split_def Let_def)\n  apply (simp add: short_tailrec_thm cong: imp_cong[OF _ refl] if_weak_cong)\n  done\n\nlemma eq_true_imp:\n  \"(x ==  Trueprop True) ==> PROP x\"\n  apply auto\n  done\n\nlemma forall_true:\n  \"(!x. True) = True\"\n  apply auto\n  done\n\nlemmas split_thm = split_conv\n\ndefinition\n  line_number :: \"word32 \\<Rightarrow> bool\"\nwhere\n  \"line_number n \\<equiv> True\"\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/asmrefine/TailrecPre.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5583269943353745, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.26173846153682745}}
{"text": "(*\n * Copyright (c) 2020, CleanQ Project - Systems Group, ETH Zurich\n * All rights reserved.\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n *\n * See \"LICENSE\" for details.\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\n\n\nsection \\<open>CleanQ List Model to Ring Buffer Model refinement COMPLEX to SIMPLE\\<close>\n\ntext \\<open>\n  The second refinement is from unbounded lists to bounded buffer rings for transferring\n  ownership between two agents.\n\\<close>\n\ntheory CleanQ_ListRBRefinement\n(*<*) imports\n  \"../Refinements\"\n  CleanQ_ListModel\n  CleanQ_RBModel\n  CleanQ_SetListRefinement (* Only for the pre condition of the lists*)\nbegin\n(*>*)\n\n\n(* ==================================================================================== *)\nsubsection \\<open>RB Pre- and post- conditions\\<close>\n(* ==================================================================================== *)\n\n\ndefinition CleanQ_RB_enq_x_pre :: \"'a set \\<Rightarrow> 'a \\<Rightarrow> ('a CleanQ_RB_State, 'a CleanQ_RB_State) Semantic.xstate set\"\n  where \"CleanQ_RB_enq_x_pre K b =  Semantic.Normal ` {rb. CleanQ_RB_Invariants K rb \\<and> CleanQ_RB_enq_x_possible rb \\<and> b \\<in> rSX rb }\"\n\ndefinition CleanQ_RB_enq_y_pre :: \"'a set \\<Rightarrow> 'a \\<Rightarrow> ('a CleanQ_RB_State, 'a CleanQ_RB_State) Semantic.xstate set\"\n  where \"CleanQ_RB_enq_y_pre K b = Semantic.Normal ` {rb. CleanQ_RB_Invariants K rb \\<and> CleanQ_RB_enq_y_possible rb \\<and> b \\<in> rSY rb}\"\n\ndefinition CleanQ_RB_deq_x_pre :: \"'a set \\<Rightarrow> 'a \\<Rightarrow> ('a CleanQ_RB_State, 'a CleanQ_RB_State) Semantic.xstate set\"        \n  where \"CleanQ_RB_deq_x_pre K buf = Semantic.Normal ` {rb. CleanQ_RB_Invariants K rb \\<and> CleanQ_RB_deq_x_possible rb \\<and>\n                                                        buf = rb_read_tail (rTYX rb)}\"\ndefinition CleanQ_RB_deq_y_pre :: \"'a set \\<Rightarrow> 'a \\<Rightarrow> ('a CleanQ_RB_State, 'a CleanQ_RB_State) Semantic.xstate set\"        \n  where \"CleanQ_RB_deq_y_pre K buf = Semantic.Normal ` {rb. CleanQ_RB_Invariants K rb \\<and> CleanQ_RB_deq_y_possible rb \\<and>\n                                                        buf = rb_read_tail (rTXY rb)}\"\n\n\n(* ------------------------------------------------------------------------------------ *)\nsubsubsection \\<open>Enqueue Refinement\\<close>\n(* ------------------------------------------------------------------------------------ *)\n\nlemma\n  CleanQ_listRBRefinement_enq_x: \n  assumes precond: \"Semantic.xstate.Normal sc \\<in> CleanQ_RB_enq_x_pre K buf\" \n  shows\n  \"((\\<Gamma>a, CleanQ_List_enq_x_pre K buf, Language.Basic (CleanQ_List_enq_x buf)), \n                               (\\<Gamma>c, CleanQ_RB_enq_x_pre K buf, Language.Basic (CleanQ_RB_enq_x buf)))\n                               \\<in> refinement_s (separable_lift CleanQ_RB2List CleanQ_RB2List)\"\n  apply(rule refinement_s_BasicI) (* Problem applying this after unfolding*)\n  unfolding separable_lift_def\nproof -\n   show \"\\<And>sc. Semantic.xstate.Normal sc \\<in> CleanQ_RB_enq_x_pre K buf \\<Longrightarrow> CleanQ_RB2List (CleanQ_RB_enq_x buf sc) = CleanQ_List_enq_x buf (CleanQ_RB2List sc)\" \n     using precond CleanQ_RB_enq_x_equal\n     using CleanQ_RB_enq_x_pre_def by fastforce\n next\n   have core_g2: \"Semantic.xstate.Normal (CleanQ_RB2List sc) \\<in> CleanQ_List_enq_x_pre K buf\" using precond\n   proof -\n     fix b\n     have b_in_sx: \"b \\<in> (rSX sc) \\<Longrightarrow> b \\<in> lSX (CleanQ_RB2List sc)\"\n       by (simp add: CleanQ_RB2List_def)\n     have b_notin_txy: \"b \\<in> (rSX sc) \\<Longrightarrow> b \\<notin> set (lTXY (CleanQ_RB2List sc))\" \n       using precond\n       unfolding CleanQ_RB_enq_x_pre_def CleanQ_RB2List_def\n       using CleanQ_RB_Invariants_def I2_rb_img_def by fastforce\n       \n     have final: \"Semantic.xstate.Normal sc \\<in> CleanQ_RB_enq_x_pre K buf \\<Longrightarrow> Semantic.xstate.Normal (CleanQ_RB2List sc) \\<in> CleanQ_List_enq_x_pre K buf\" \n       using b_in_sx b_notin_txy precond unfolding CleanQ_RB2List_def CleanQ_RB_enq_x_pre_def CleanQ_List_enq_x_pre_def\n       by (smt CleanQ_List_State.select_convs(1) CleanQ_List_State.select_convs(3) CleanQ_RB2List_def \n           CleanQ_RB_Invariants_List_Invariants CleanQ_RB_Invariants_def CollectD CollectI I2_rb_img_def \n           Semantic.xstate.inject(1) Set.set_insert disjoint_insert(1) imageE imageI)\n\n     show ?thesis using final precond\n       by blast\n   qed\n   show \"Semantic.xstate.case_xstate (\\<lambda>sc. Semantic.xstate.Normal (CleanQ_RB2List sc)) (\\<lambda>sc. Abrupt (CleanQ_RB2List sc)) (\\<lambda>fc. Semantic.xstate.Fault (CleanQ_RB2List fc))\n     Semantic.xstate.Stuck ` CleanQ_RB_enq_x_pre K buf \\<subseteq> CleanQ_List_enq_x_pre K buf\"\n     using core_g2 CleanQ_RB_Invariants_List_Invariants unfolding CleanQ_RB_enq_x_pre_def CleanQ_List_enq_x_pre_def\n     by (smt CleanQ_List_State.select_convs(1) CleanQ_List_State.select_convs(3) CleanQ_RB2List_def CleanQ_RB_Invariants_def \n         CollectI I2_rb_img_def Semantic.xstate.simps(16) disjoint_iff_not_equal image_Collect_subsetI image_def image_image)\n    \nqed\n\nlemma\n  CleanQ_listRBRefinement_enq_y: \n  assumes precond: \"Semantic.xstate.Normal sc \\<in> CleanQ_RB_enq_y_pre K buf\" \n  shows\n  \"((\\<Gamma>a, CleanQ_List_enq_y_pre K buf, Language.Basic (CleanQ_List_enq_y buf)), \n                               (\\<Gamma>c, CleanQ_RB_enq_y_pre K buf, Language.Basic (CleanQ_RB_enq_y buf)))\n                               \\<in> refinement_s (separable_lift CleanQ_RB2List CleanQ_RB2List)\"\n  apply(rule refinement_s_BasicI) (* Problem applying this after unfolding*)\n  unfolding separable_lift_def\nproof -\n   show \"\\<And>sc. Semantic.xstate.Normal sc \\<in> CleanQ_RB_enq_y_pre K buf \\<Longrightarrow> CleanQ_RB2List (CleanQ_RB_enq_y buf sc) = CleanQ_List_enq_y buf (CleanQ_RB2List sc)\" \n     using precond CleanQ_RB_enq_y_equal\n     using CleanQ_RB_enq_y_pre_def by fastforce\n next\n   have core_g2: \"Semantic.xstate.Normal (CleanQ_RB2List sc) \\<in> CleanQ_List_enq_y_pre K buf\" using precond\n   proof -\n     fix b\n     have b_in_sx: \"b \\<in> (rSY sc) \\<Longrightarrow> b \\<in> lSY (CleanQ_RB2List sc)\"\n       by (simp add: CleanQ_RB2List_def)\n     have b_notin_tyx: \"b \\<in> (rSY sc) \\<Longrightarrow> b \\<notin> set (lTYX (CleanQ_RB2List sc))\" \n       using precond\n       unfolding CleanQ_RB_enq_y_pre_def CleanQ_RB2List_def\n       using CleanQ_RB_Invariants_def I2_rb_img_def by fastforce\n      \n     have final: \"Semantic.xstate.Normal sc \\<in> CleanQ_RB_enq_y_pre K buf \\<Longrightarrow> Semantic.xstate.Normal (CleanQ_RB2List sc) \\<in> CleanQ_List_enq_y_pre K buf\" \n       using b_in_sx b_notin_tyx precond unfolding CleanQ_RB2List_def CleanQ_RB_enq_y_pre_def CleanQ_List_enq_y_pre_def\n       by (smt CleanQ_List_State.select_convs(2) CleanQ_List_State.select_convs(4) CleanQ_RB2List_def\n           CleanQ_RB_Invariants_List_Invariants CleanQ_RB_Invariants_def CollectD CollectI I2_rb_img_def \n           Semantic.xstate.inject(1) Set.set_insert disjoint_insert(1) imageE imageI)\n\n     show ?thesis using final precond\n       by simp\n   qed\n   show \"Semantic.xstate.case_xstate (\\<lambda>sc. Semantic.xstate.Normal (CleanQ_RB2List sc)) (\\<lambda>sc. Abrupt (CleanQ_RB2List sc)) (\\<lambda>fc. Semantic.xstate.Fault (CleanQ_RB2List fc))\n     Semantic.xstate.Stuck ` CleanQ_RB_enq_y_pre K buf \\<subseteq> CleanQ_List_enq_y_pre K buf\"\n     using core_g2 CleanQ_RB_Invariants_List_Invariants unfolding CleanQ_RB_enq_y_pre_def CleanQ_List_enq_y_pre_def\n     by (smt CleanQ_List_State.select_convs(2) CleanQ_List_State.select_convs(4) CleanQ_RB2List_def \n         CleanQ_RB_Invariants_def CollectD CollectI I2_rb_img_def Semantic.xstate.simps(16) \n         disjoint_iff_not_equal image_iff image_subsetI)\n    \nqed\n\n(* ------------------------------------------------------------------------------------ *)\nsubsubsection \\<open>Dequeue Refinement\\<close>\n(* ------------------------------------------------------------------------------------ *)\n\ntext \\<open>\n  We first show some helper lemmas that connect the two preconditions on the Ring buffer\n  model and the List model.   \n\\<close>\n\nlemma \n  refine_hd_list_tl_ring_tyx:\n  fixes buf sc\n  assumes precond: \"Semantic.xstate.Normal sc \\<in> CleanQ_RB_deq_x_pre K buf\"\n  shows \"buf = the (ring (rTYX sc) (tail (rTYX sc))) \\<Longrightarrow> buf = hd (lTYX (CleanQ_RB2List sc))\"\n  using precond unfolding CleanQ_RB2List_def \n  apply auto\n  by (metis (mono_tags, lifting) CleanQ_RB_Invariants_def CleanQ_RB_deq_x_possible_def CleanQ_RB_deq_x_pre_def \n      CollectD I4_rb_valid_def imageE prod.sel(1) rb_deq_def rb_deq_list_was_head state_simps(1))\n  \n  \n  \n\nlemma \n  refine_hd_list_tl_ring_txy:\n  fixes buf sc\n  assumes precond: \"Semantic.xstate.Normal sc \\<in> CleanQ_RB_deq_y_pre K buf\"\n  shows \"buf = the (ring (rTXY sc) (tail (rTXY sc))) \\<Longrightarrow> buf = hd (lTXY (CleanQ_RB2List sc))\"\n  using precond unfolding CleanQ_RB2List_def CleanQ_RB_deq_y_pre_def\n  apply auto\n  by (metis (no_types) CleanQ_RB_Invariants_def CleanQ_RB_deq_y_possible_def I4_rb_valid_def prod.sel(1) \n      rb_deq_def rb_deq_list_was_head)\n  \nlemma \n  deq_x_rb_pre_implies_list_pre:\n  assumes precond: \"Semantic.xstate.Normal sc \\<in> CleanQ_RB_deq_x_pre K buf\"\n  shows \"CleanQ_RB_Invariants K sc \\<and> buf = the (ring (rTYX sc) (tail (rTYX sc))) \\<and> \\<not> rb_empty (rTYX sc)\n         \\<Longrightarrow> CleanQ_List_Invariants K (CleanQ_RB2List sc) \\<and> buf = hd (lTYX (CleanQ_RB2List sc)) \\<and> lTYX (CleanQ_RB2List sc) \\<noteq> []\"\nproof -\n   have precond_buf: \" buf = hd (lTYX (CleanQ_RB2List sc)) \\<longleftrightarrow> buf = the (ring (rTYX sc) (tail (rTYX sc)))\"\n       using refine_hd_list_tl_ring_tyx precond\n       by (smt CleanQ_RB_deq_x_pre_def CollectD Semantic.xstate.inject(1) imageE rb_read_tail_def)\n        \n   have non_empty: \"CleanQ_RB_deq_x_possible sc \\<Longrightarrow> lTYX (CleanQ_RB2List sc) \\<noteq> []\" \n     using precond unfolding CleanQ_RB_deq_x_possible_def CleanQ_RB2List_def CleanQ_RB_deq_x_pre_def\n     using CleanQ_RB_Invariants_def I4_rb_valid_def rb_deq_not_empty by fastforce\n    \n   show ?thesis  using non_empty precond_buf CleanQ_RB_Invariants_List_Invariants      \n     using precond non_empty refine_hd_list_tl_ring_tyx precond_buf \n     unfolding CleanQ_RB2List_def CleanQ_RB_deq_x_pre_def CleanQ_List_deq_x_pre_def\n     by (smt CollectD imageE rb_read_tail_def state_simps(1))\n qed\n\n\nlemma \n  deq_y_rb_pre_implies_list_pre:\n  assumes precond: \"Semantic.xstate.Normal sc \\<in> CleanQ_RB_deq_y_pre K buf\"\n  shows \"CleanQ_RB_Invariants K sc \\<and> buf = the (ring (rTXY sc) (tail (rTXY sc))) \\<and> \\<not> rb_empty (rTXY sc) \n         \\<Longrightarrow> CleanQ_List_Invariants K (CleanQ_RB2List sc) \\<and> buf = hd (lTXY (CleanQ_RB2List sc)) \\<and> lTXY (CleanQ_RB2List sc) \\<noteq> []\"\nproof -\n   have precond_buf: \" buf = hd (lTXY (CleanQ_RB2List sc)) \\<longleftrightarrow> buf = the (ring (rTXY sc) (tail (rTXY sc)))\"\n     using refine_hd_list_tl_ring_txy precond unfolding CleanQ_RB_deq_y_pre_def\n     by (smt CollectD imageE precond rb_read_tail_def refine_hd_list_tl_ring_txy state_simps(1)) \n     \n   have non_empty: \"CleanQ_RB_deq_y_possible sc \\<Longrightarrow> lTXY (CleanQ_RB2List sc) \\<noteq> []\" \n     using precond unfolding CleanQ_RB_deq_y_possible_def\n     by (smt CleanQ_List_State.select_convs(3) CleanQ_RB2List_def CleanQ_RB_Invariants_def \n         CleanQ_RB_deq_y_pre_def CollectD I4_rb_valid_def image_def rb_deq_not_empty state_simps(1))\n      \n   show ?thesis  using non_empty precond_buf CleanQ_RB_Invariants_List_Invariants      \n     using precond non_empty refine_hd_list_tl_ring_txy precond_buf \n     unfolding CleanQ_RB2List_def CleanQ_RB_deq_y_pre_def CleanQ_List_deq_y_pre_def\n     by (smt CollectD imageE rb_read_tail_def state_simps(1))   \n qed\n\ntext \\<open>\n  Finally the proofs for the Dequeue refinement.\n\\<close>\n\nlemma\n  CleanQ_listRBRefinement_deq_x:   \n  assumes precond: \"Semantic.xstate.Normal sc \\<in> CleanQ_RB_deq_x_pre K buf\" \n  shows\n  \"((\\<Gamma>a, CleanQ_List_deq_x_pre K buf, Language.Basic (CleanQ_List_deq_x)), \n    (\\<Gamma>c, CleanQ_RB_deq_x_pre K buf, Language.Basic (CleanQ_RB_deq_x)))\n                               \\<in> refinement_s (separable_lift CleanQ_RB2List CleanQ_RB2List)\"\n  apply(rule refinement_s_BasicI) (* Problem applying this after unfolding*)\n  unfolding separable_lift_def\nproof auto\n    show \"\\<And>sc. Semantic.xstate.Normal sc \\<in> CleanQ_RB_deq_x_pre K buf \\<Longrightarrow> CleanQ_RB2List (CleanQ_RB_deq_x sc) = CleanQ_List_deq_x (CleanQ_RB2List sc)\" \n    using CleanQ_RB_deq_x_equal\n    by (smt CleanQ_RB_deq_x_pre_def CollectD image_def state_simps(1))\nnext\n   have core: \"\\<And>x. Semantic.xstate.Normal x \\<in> CleanQ_RB_deq_x_pre K buf \\<Longrightarrow> Semantic.xstate.Normal (CleanQ_RB2List x)\n         \\<in> CleanQ_List_deq_x_pre K buf\"\n       using deq_x_rb_pre_implies_list_pre precond CleanQ_RB_Invariants_List_Invariants \n       unfolding CleanQ_RB_deq_x_pre_def CleanQ_List_deq_x_pre_def CleanQ_RB_deq_x_possible_def\n                 rb_can_deq_def rb_read_tail_def\n       by (smt CleanQ_RB_deq_x_pre_def CollectD CollectI imageE image_eqI rb_can_deq_def rb_read_tail_def state_simps(1))\n       \n   show \"\\<And>xa. xa \\<in> CleanQ_RB_deq_x_pre K buf \\<Longrightarrow>\n          (case xa of Semantic.xstate.Normal sc \\<Rightarrow> Semantic.xstate.Normal (CleanQ_RB2List sc) | Abrupt sc \\<Rightarrow> Abrupt (CleanQ_RB2List sc) | Semantic.xstate.Fault fc \\<Rightarrow> Semantic.xstate.Fault (CleanQ_RB2List fc)\n           | Semantic.xstate.Stuck \\<Rightarrow> Semantic.xstate.Stuck)\n          \\<in> CleanQ_List_deq_x_pre K buf\"     \n     unfolding CleanQ_RB_deq_x_pre_def CleanQ_List_deq_x_pre_def\n     apply (auto)\n     using core precond unfolding CleanQ_RB_deq_x_pre_def CleanQ_List_deq_x_pre_def\n     by auto\n qed\n\n\nlemma\n  CleanQ_listRBRefinement_deq_y:   \n  assumes precond: \"Semantic.xstate.Normal sc \\<in> CleanQ_RB_deq_y_pre K buf\" \n  shows\n  \"((\\<Gamma>a, CleanQ_List_deq_y_pre K buf, Language.Basic (CleanQ_List_deq_y)), \n    (\\<Gamma>c, CleanQ_RB_deq_y_pre K buf, Language.Basic (CleanQ_RB_deq_y)))\n                               \\<in> refinement_s (separable_lift CleanQ_RB2List CleanQ_RB2List)\"\n  apply(rule refinement_s_BasicI) (* Problem applying this after unfolding*)\n  unfolding separable_lift_def\nproof auto\n    show \"\\<And>sc. Semantic.xstate.Normal sc \\<in> CleanQ_RB_deq_y_pre K buf \\<Longrightarrow> CleanQ_RB2List (CleanQ_RB_deq_y sc) = CleanQ_List_deq_y (CleanQ_RB2List sc)\" \n    using CleanQ_RB_deq_y_equal\n    by (smt CleanQ_RB_deq_y_pre_def CollectD image_def state_simps(1))\nnext\n   have core: \"\\<And>x. Semantic.xstate.Normal x \\<in> CleanQ_RB_deq_y_pre K buf \\<Longrightarrow> Semantic.xstate.Normal (CleanQ_RB2List x)\n         \\<in> CleanQ_List_deq_y_pre K buf\"\n       using deq_y_rb_pre_implies_list_pre precond CleanQ_RB_Invariants_List_Invariants \n       unfolding CleanQ_RB_deq_y_pre_def CleanQ_List_deq_y_pre_def CleanQ_RB_deq_y_possible_def\n                 rb_can_deq_def rb_read_tail_def\n       by (smt CleanQ_RB_deq_y_pre_def CollectD CollectI imageE image_eqI rb_can_deq_def rb_read_tail_def state_simps(1))   \n\n   show \"\\<And>xa. xa \\<in> CleanQ_RB_deq_y_pre K buf \\<Longrightarrow>\n          (case xa of Semantic.xstate.Normal sc \\<Rightarrow> Semantic.xstate.Normal (CleanQ_RB2List sc) | Abrupt sc \\<Rightarrow> Abrupt (CleanQ_RB2List sc) | Semantic.xstate.Fault fc \\<Rightarrow> Semantic.xstate.Fault (CleanQ_RB2List fc)\n           | Semantic.xstate.Stuck \\<Rightarrow> Semantic.xstate.Stuck)\n          \\<in> CleanQ_List_deq_y_pre K buf\"     \n     unfolding CleanQ_RB_deq_y_pre_def CleanQ_List_deq_x_pre_def\n     apply (auto)\n     using core precond unfolding CleanQ_RB_deq_y_pre_def CleanQ_List_deq_y_pre_def\n     by auto\nqed\n\nend", "meta": {"author": "CleanQ-Project", "repo": "cleanq-proofs", "sha": "5212fcd2aceba0028bd1474e0553578a6091ca63", "save_path": "github-repos/isabelle/CleanQ-Project-cleanq-proofs", "path": "github-repos/isabelle/CleanQ-Project-cleanq-proofs/cleanq-proofs-5212fcd2aceba0028bd1474e0553578a6091ca63/CleanQ/CleanQ_ListRBRefinement.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5583269796369905, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.2617384546463628}}
{"text": "theory ext_BigStepContinuous\n  imports ext_BigStepSimple\nbegin\n\n\nsubsection \\<open>Hoare rules for ODE\\<close>\n\ntext \\<open>Weakest precondition form\\<close>\ntheorem Valid_ode:\n  \"Valid\n    (\\<lambda>(a,s) tr. (\\<not>b s \\<longrightarrow> Q (a,s) tr) \\<and>\n            (\\<forall>d p. 0 < d \\<longrightarrow> ODEsol ode p d \\<longrightarrow> p 0 = s \\<longrightarrow> (\\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p t)) \\<longrightarrow> \\<not>b (p d) \\<longrightarrow>\n                   Q (a,p d) (tr @ [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) ({}, {})])))\n    (Cont ode b)\n    Q\"\n  unfolding Valid_def\n  apply (auto elim!: contE)\n  done\n\nsubsection \\<open>Hoare rules for interrupt\\<close>\n\ntext \\<open>Weakest precondition form\\<close>\ntheorem Valid_interrupt:\n  assumes \"\\<And>i. i < length cs \\<Longrightarrow>\n    case cs ! i of\n      (ch[!]e, p2) \\<Rightarrow>\n        (\\<exists>Q. \\<Turnstile> {Q} p2 {R} \\<and>\n             (P \\<Longrightarrow>\\<^sub>A (\\<lambda>(a,s) tr. Q (a,s) (tr @ [OutBlock ch (e (a,s))]))) \\<and>\n             (P \\<Longrightarrow>\\<^sub>A (\\<lambda>(a,s) tr. \\<forall>d>0. \\<forall>p. ODEsol ode p d \\<longrightarrow> p 0 = s \\<longrightarrow>\n                        (\\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p t)) \\<longrightarrow>\n                        Q (a,p d) (tr @ [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) (rdy_of_echoice cs),\n                                       OutBlock ch (e (a,p d))]))))\n    | (ch[?]var, p2) \\<Rightarrow>\n        (\\<exists>Q. \\<Turnstile> {Q} p2 {R} \\<and>\n             (P \\<Longrightarrow>\\<^sub>A (\\<lambda>(a,s) tr. \\<forall>v. Q (a,s(var := v)) (tr @ [InBlock ch v]))) \\<and>\n             (P \\<Longrightarrow>\\<^sub>A (\\<lambda>(a,s) tr. \\<forall>d>0. \\<forall>p v. ODEsol ode p d \\<longrightarrow> p 0 = s \\<longrightarrow>\n                        (\\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p t)) \\<longrightarrow>\n                        Q (a,(p d)(var := v)) (tr @ [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) (rdy_of_echoice cs),\n                                                   InBlock ch v]))))\"\n    and \"P \\<Longrightarrow>\\<^sub>A (\\<lambda>(a,s) tr. \\<not>b s \\<longrightarrow> R (a,s) tr)\"\n    and \"P \\<Longrightarrow>\\<^sub>A (\\<lambda>(a,s) tr. (\\<forall>d>0. \\<forall>p. ODEsol ode p d \\<longrightarrow> p 0 = s \\<longrightarrow>\n                   (\\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p t)) \\<longrightarrow> \\<not>b (p d) \\<longrightarrow>\n                   R (a,p d) (tr @ [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) (rdy_of_echoice cs)])))\"\n  shows \"\\<Turnstile> {P} Interrupt ode b cs {R}\"\nproof -\n  have a: \"R s2 (tr1 @ OutBlock ch (e s1) # tr2)\"\n    if *: \"P s1 tr1\"\n          \"i < length cs\"\n          \"cs ! i = (ch[!]e, p2)\"\n          \"big_step p2 s1 tr2 s2\" for s1 tr1 s2 i ch e p2 tr2\n  proof -\n    from assms obtain Q where 1:\n      \"\\<Turnstile> {Q} p2 {R}\"\n      \"P \\<Longrightarrow>\\<^sub>A (\\<lambda>(a,s) tr. Q (a,s) (tr @ [OutBlock ch (e (a,s))]))\"\n      using *(2,3) by fastforce\n    have 2: \"Q s1 (tr1 @ [OutBlock ch (e s1)])\"\n      using 1(2) *(1) unfolding entails_def \n      by blast\n    then show ?thesis\n      using *(4) 1(1) unfolding Valid_def by fastforce\n  qed\n  have b: \"R s2 (tr1 @ WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) (rdy_of_echoice cs) # OutBlock ch (e (a,p d)) # tr2)\"\n    if *: \"P (a,p 0) tr1\"\n          \"0 < d\"\n          \"ODEsol ode p d\"\n          \"\\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p t)\"\n          \"i < length cs\"\n          \"cs ! i = (ch[!]e, p2)\"\n          \"big_step p2 (a,p d) tr2 s2\" for a tr1 s2 d p i ch e p2 tr2\n  proof -\n    from assms obtain Q where 1:\n      \"\\<Turnstile> {Q} p2 {R}\"\n      \"P \\<Longrightarrow>\\<^sub>A (\\<lambda>(a,s) tr. \\<forall>d>0. \\<forall>p. ODEsol ode p d \\<longrightarrow> p 0 = s \\<longrightarrow>\n                 (\\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p t)) \\<longrightarrow>\n                 Q (a,p d) (tr @ [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) (rdy_of_echoice cs),\n                                OutBlock ch (e (a,p d))]))\"\n      using *(5,6) by fastforce\n    have \"Q (a,p d) (tr1 @ [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) (rdy_of_echoice cs),\n                          OutBlock ch (e (a,p d))])\"\n      using 1(2) *(1-4) unfolding entails_def by auto\n    then show ?thesis\n      using *(7) 1(1) unfolding Valid_def by fastforce\n  qed\n  have c: \"R s2 (tr1 @ InBlock ch v # tr2)\"\n    if *: \"P (a1,s1) tr1\"\n          \"i < length cs\"\n          \"cs ! i = (ch[?]var, p2)\"\n          \"big_step p2 (a1,s1(var := v)) tr2 s2\" for a1 s1 tr1 s2 i ch var p2 v tr2\n  proof -\n    from assms obtain Q where 1:\n      \"\\<Turnstile> {Q} p2 {R}\"\n      \"P \\<Longrightarrow>\\<^sub>A (\\<lambda>(a,s) tr. \\<forall>v. Q (a,s(var := v)) (tr @ [InBlock ch v]))\"\n      using *(2,3) by fastforce\n    have 2: \"Q (a1,s1(var := v)) (tr1 @ [InBlock ch v])\"\n      using 1(2) *(1) unfolding entails_def by auto\n    then show ?thesis\n      using *(4) 1(1) unfolding Valid_def by fastforce\n  qed\n  have d: \"R s2 (tr1 @ WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) (rdy_of_echoice cs) # InBlock ch v # tr2a)\"\n    if *: \"P (a,p 0) tr1\"\n          \"0 < d\"\n          \"ODEsol ode p d\"\n          \"\\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p t)\"\n          \"i < length cs\"\n          \"cs ! i = (ch[?]var, p2)\"\n          \"big_step p2 (a,(p d)(var := v)) tr2a s2\" for a tr1 s2 d p i ch var p2 v tr2a\n  proof -\n    from assms obtain Q where 1:\n      \"\\<Turnstile> {Q} p2 {R}\"\n      \"P \\<Longrightarrow>\\<^sub>A (\\<lambda>(a,s) tr. \\<forall>d>0. \\<forall>p v. ODEsol ode p d \\<longrightarrow> p 0 = s \\<longrightarrow>\n                 (\\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p t)) \\<longrightarrow>\n                 Q (a,(p d)(var := v)) (tr @ [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) (rdy_of_echoice cs),\n                                            InBlock ch v]))\"\n      using *(5,6) by fastforce\n    have \"Q (a,(p d)(var := v)) (tr1 @ [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) (rdy_of_echoice cs), InBlock ch v])\"\n      using 1(2) *(1-4) unfolding entails_def by auto\n    then show ?thesis\n      using *(7) 1(1) unfolding Valid_def by fastforce\n  qed\n  show ?thesis\n    unfolding Valid_def\n    apply (auto elim!: interruptE)\n    using a b c d assms(2-3) unfolding entails_def by auto\nqed\n\ntext \\<open>Simpler versions with one input/output\\<close>\n\ntheorem Valid_interrupt_In:\n  assumes \"\\<Turnstile> {Q} p {R}\"\n  shows \"\\<Turnstile>\n    {\\<lambda>(a,s) tr. (\\<forall>v. Q (a,s(var := v)) (tr @ [InBlock ch v])) \\<and>\n            (\\<forall>d>0. \\<forall>p v. ODEsol ode p d \\<longrightarrow> p 0 = s \\<longrightarrow>\n                (\\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p t)) \\<longrightarrow>\n                Q (a,(p d)(var := v)) (tr @ [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) ({}, {ch}),\n                                           InBlock ch v])) \\<and>\n            (\\<not>b s \\<longrightarrow> R (a,s) tr) \\<and>\n            (\\<forall>d>0. \\<forall>p. ODEsol ode p d \\<longrightarrow> p 0 = s \\<longrightarrow>\n                (\\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p t)) \\<longrightarrow> \\<not>b (p d) \\<longrightarrow>\n                R (a,p d) (tr @ [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) ({}, {ch})]))}\n      Interrupt ode b [(ch[?]var, p)]\n    {R}\"\n  apply (rule Valid_interrupt)\n  apply auto apply (rule exI[where x=Q])\n  by (auto simp add: assms entails_def)\n\ntheorem Valid_interrupt_Out:\n  assumes \"\\<Turnstile> {Q} p {R}\"\n  shows \"\\<Turnstile>\n    {\\<lambda>(a,s) tr. (Q (a,s) (tr @ [OutBlock ch (e (a,s))])) \\<and>\n            (\\<forall>d>0. \\<forall>p. ODEsol ode p d \\<longrightarrow> p 0 = s \\<longrightarrow>\n                (\\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p t)) \\<longrightarrow>\n                Q (a,p d) (tr @ [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) ({ch}, {}),\n                               OutBlock ch (e (a,p d))])) \\<and>\n            (\\<not>b s \\<longrightarrow> R (a,s) tr) \\<and>\n            (\\<forall>d>0. \\<forall>p. ODEsol ode p d \\<longrightarrow> p 0 = s \\<longrightarrow>\n                (\\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p t)) \\<longrightarrow> \\<not>b (p d) \\<longrightarrow>\n                R (a,p d) (tr @ [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) ({ch}, {})]))}\n      Interrupt ode b [(ch[!]e, p)]\n    {R}\"\n  apply (rule Valid_interrupt)\n  apply auto apply (rule exI[where x=Q])\n  by (auto simp add: assms entails_def)\n\n\nsubsection \\<open>Assertions for ODEs\\<close>\n\ntext \\<open>ODE without interrupt\\<close>\ninductive ode_assn :: \"'a ext_state \\<Rightarrow> ODE \\<Rightarrow> fform \\<Rightarrow> 'a ext_state \\<Rightarrow> 'a tassn\" (\"ODE\\<^sub>t\") where\n  \"\\<not>b s \\<Longrightarrow> ODE\\<^sub>t (a,s) ode b (a,s) []\"\n| \"0 < d \\<Longrightarrow> ODEsol ode p d \\<Longrightarrow> p 0 = s \\<Longrightarrow> (\\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p t)) \\<Longrightarrow> \\<not>b (p d) \\<Longrightarrow>\n     ODE\\<^sub>t (a,s) ode b (a,p d) [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) ({}, {})]\"\nthm ode_assn.induct\nlemmas ode_assn_induct = ode_assn.induct[split_format(complete)]\nlemma ode_assn_ext_con:\n\"ODE\\<^sub>t (a, s) ode b (a', s') tr \\<Longrightarrow> a' = a\"\n  apply(induct rule:ode_assn_induct)\n  by auto\n\ntext \\<open>ODE interrupted by communication\\<close>\ninductive ode_in_assn :: \"'a ext_state \\<Rightarrow> ODE \\<Rightarrow> fform \\<Rightarrow> 'a ext_state \\<Rightarrow> cname \\<Rightarrow> var \\<Rightarrow> rdy_info \\<Rightarrow> 'a tassn\" (\"ODEin\\<^sub>t\") where\n  \"ODEin\\<^sub>t (a,s) ode b (a,s(var := v)) ch var rdy [InBlock ch v]\"\n| \"0 < d \\<Longrightarrow> ODEsol ode p d \\<Longrightarrow> p 0 = s \\<Longrightarrow>\n    \\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p t) \\<Longrightarrow>\n    ODEin\\<^sub>t (a,s) ode b (a,(p d)(var := v)) ch var rdy\n      [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) rdy, InBlock ch v]\"\nlemmas ode_in_assn_induct = ode_in_assn.induct[split_format(complete)]\n\n\n\ninductive ode_out_assn :: \"'a ext_state \\<Rightarrow> ODE \\<Rightarrow> fform \\<Rightarrow> 'a ext_state \\<Rightarrow> cname \\<Rightarrow> 'a ext_exp \\<Rightarrow> rdy_info \\<Rightarrow> 'a tassn\" (\"ODEout\\<^sub>t\") where\n  \"ODEout\\<^sub>t (a,s) ode b (a,s) ch e rdy [OutBlock ch (e (a,s))]\"\n| \"0 < d \\<Longrightarrow> ODEsol ode p d \\<Longrightarrow> p 0 = s \\<Longrightarrow>\n    \\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p t) \\<Longrightarrow>\n    ODEout\\<^sub>t (a,s) ode b (a,p d) ch e rdy\n      [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) rdy, OutBlock ch (e (a,p d))]\"\nlemmas ode_out_assn_induct = ode_out_assn.induct[split_format(complete)]\n\n\ntext \\<open>ODE with interrupt, but reached boundary\\<close>\ninductive ode_rdy_assn :: \"'a ext_state \\<Rightarrow> ODE \\<Rightarrow> fform \\<Rightarrow> 'a ext_state \\<Rightarrow> rdy_info \\<Rightarrow> 'a tassn\" (\"ODErdy\\<^sub>t\") where\n  \"\\<not>b s \\<Longrightarrow> ODErdy\\<^sub>t (a,s) ode b (a,s) rdy []\"\n| \"0 < d \\<Longrightarrow> ODEsol ode p d \\<Longrightarrow> p 0 = s \\<Longrightarrow>\n    \\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p t) \\<Longrightarrow> \\<not>b (p d) \\<Longrightarrow>\n    ODErdy\\<^sub>t (a,s) ode b (a,p d) rdy\n      [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) rdy]\"\n\n\nsubsection \\<open>Simpler rules for ODE\\<close>\n\ntheorem Valid_ode':\n  \"\\<Turnstile> {\\<lambda>(a,s) tr. \\<forall>s'. (ODE\\<^sub>t (a,s) ode b (a,s') @- Q (a,s')) tr}\n       Cont ode b\n      {Q}\"\nproof -\n  have 1: \"Q (a,s) tr\"\n    if \"\\<forall>s'. (ODE\\<^sub>t (a,s) ode b (a,s') @- Q (a,s')) tr\" \"\\<not> b s\" for a s tr\n  proof -\n    have \"(ODE\\<^sub>t (a,s) ode b (a,s) @- Q (a,s)) tr\"\n      using that(1) by auto\n    moreover have \"ODE\\<^sub>t (a,s) ode b (a,s) []\"\n      using that(2) by (auto intro: ode_assn.intros)\n    ultimately show ?thesis\n      by (auto simp add: magic_wand_assn_def)\n  qed\n  have 2: \"Q (a,p d) (tr @ [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) ({}, {})])\"\n    if \"\\<forall>s'. (ODE\\<^sub>t (a,p 0) ode b (a,s') @- Q (a,s')) tr\"\n       \"0 < d\" \"ODEsol ode p d\" \"\\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p t)\" \"\\<not> b (p d)\" for a p d tr\n  proof -\n    have \"(ODE\\<^sub>t (a,p 0) ode b (a,p d) @- Q (a,p d)) tr\"\n      using that(1) by auto\n    moreover have \"ODE\\<^sub>t (a,p 0) ode b (a,p d) [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) ({}, {})]\"\n      apply (rule ode_assn.intros)\n      using that by auto\n    ultimately show ?thesis\n      by (auto simp add: magic_wand_assn_def)\n  qed\n  show ?thesis\n    apply (rule Valid_weaken_pre)\n     prefer 2 apply (rule Valid_ode)\n    unfolding entails_def using 1 2 by auto\nqed\n\ntext \\<open>Strongest postcondition rule for ODE\\<close>\ntheorem Valid_ode_sp:\n  \"\\<Turnstile> {\\<lambda>s t. P s t}\n        Cont ode b\n      {\\<lambda>s t. \\<exists>s'. (P s' @\\<^sub>t ODE\\<^sub>t s' ode b s) t}\"\n  apply (rule Valid_weaken_pre)\n   prefer 2 apply (rule Valid_ode')\n  by (auto simp add: entails_def magic_wand_assn_def join_assn_def)  \n\ntheorem Valid_ode_sp':\n  \"\\<Turnstile> {\\<lambda>(a,s) t. P (a,s) t}\n        Cont ode b\n      {\\<lambda>(a,s) t. \\<exists>s'. (P (a,s') @\\<^sub>t ODE\\<^sub>t (a,s') ode b (a,s)) t}\"\n  apply (rule Valid_weaken_pre)\n   prefer 2 apply (rule Valid_ode')\n  by (auto simp add: entails_def magic_wand_assn_def join_assn_def)  \n\ntext \\<open>Strongest postcondition rule for ODE with fixed initial state\\<close>\ntheorem Valid_ode_sp_st:\n  \"\\<Turnstile> {\\<lambda>s t. s = (a0,s0) \\<and> Q s t}\n        Cont ode b\n      {\\<lambda>s t. (Q (a0,s0) @\\<^sub>t ODE\\<^sub>t (a0,s0) ode b s) t}\"\n  apply (rule Valid_weaken_pre)\n   prefer 2 apply (rule Valid_ode')\n  apply (auto simp add: entails_def)\n  using entails_mp by (auto simp add: entails_tassn_def)\n\ntheorem Valid_ode_sp_st':\n  \"\\<Turnstile> {\\<lambda>(a,s) t. s = s0 \\<and> Q (a,s) t}\n        Cont ode b\n      {\\<lambda>(a,s) t. (Q (a,s0) @\\<^sub>t ODE\\<^sub>t (a,s0) ode b (a,s)) t}\"\n  apply (rule Valid_weaken_pre)\n   prefer 2 apply (rule Valid_ode')\n  apply (auto simp add: entails_def)\n  using entails_mp by (auto simp add: entails_tassn_def)\n\n\ntext \\<open>Auxiliary lemma, converting ODE assertion to Wait assertion\n  when the ODE can be solved exactly.\n\\<close>\ntheorem Valid_ode_unique_solution_aux:\n  assumes\n    \"d > 0\" \"ODEsol ode p d\" \"\\<forall>t. t \\<ge> 0 \\<and> t < d \\<longrightarrow> b (p t)\"\n    \"\\<not> b (p d)\" \"p 0 = st\"\n    \"local_lipschitz {- 1<..} UNIV (\\<lambda>(t::real) v. ODE2Vec ode (vec2state v))\"\n    \"ODE\\<^sub>t (a,st) ode b (a,st') tr\"\n  shows\n    \"st' = p d \\<and> Wait\\<^sub>t d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) ({}, {}) tr\"\nproof -\n  have \"b st\"\n    using assms(1,3,5) by auto\n  have main: \"d2 = d \\<and> p d = p2 d2 \\<and> (\\<lambda>\\<tau>\\<in>{0..d}. EState (a,p \\<tau>)) = (\\<lambda>\\<tau>\\<in>{0..d2}. EState (a,p2 \\<tau>)) \\<and>\n              Wait\\<^sub>t d (\\<lambda>s. EState (a,p s)) ({}, {}) [WaitBlk d2 (\\<lambda>\\<tau>. EState (a,p2 \\<tau>)) ({}, {})]\"\n    if cond: \"0 < d2\"\n       \"ODEsol ode p2 d2\"\n       \"(\\<forall>t. 0 \\<le> t \\<and> t < d2 \\<longrightarrow> b (p2 t))\"\n       \"\\<not> b (p2 d2)\"\n       \"p2 0 = st\" for p2 d2\n  proof -\n    interpret loc:ll_on_open_it \"{-1<..}\"\n      \"\\<lambda>t v. ODE2Vec ode (vec2state v)\" UNIV 0\n      apply standard\n      using assms(6) by auto\n    have s1: \"((\\<lambda>t. state2vec (p t)) solves_ode ((\\<lambda>t v. ODE2Vec ode (vec2state v)))) {0..d} UNIV\"\n      using assms(2) using ODEsol_old[OF assms(2)] unfolding ODEsol_def solves_ode_def by auto\n    have s2: \"(loc.flow 0 (state2vec st)) t = (\\<lambda>t. state2vec (p t)) t\" if \"t \\<in> {0..d}\" for t\n      apply (rule loc.maximal_existence_flow(2)[OF s1])\n      using that by (auto simp add: state2vec_def assms(1,5))\n    have s3: \"((\\<lambda>t. state2vec(p2 t)) solves_ode ((\\<lambda>t v. ODE2Vec ode (vec2state v)))) {0..d2} UNIV\"\n      using cond(2) using ODEsol_old[OF cond(2)] unfolding ODEsol_def solves_ode_def by auto\n    have s4: \"loc.flow 0 (state2vec st) t = state2vec (p2 t)\" if \"t\\<in>{0..d2}\" for t\n      apply (rule loc.maximal_existence_flow(2)[OF s3])\n      using cond(1,5) that by auto\n    have s5: \"d \\<le> d2\"\n    proof (rule ccontr)\n      assume 0: \"\\<not>(d \\<le> d2)\"\n      from 0 have 1: \"(\\<lambda>t. state2vec (p t)) d2 = (\\<lambda>t. state2vec (p2 t)) d2\"\n        using s2[of d2] s4[of d2] cond(1) by auto\n      from 1 have \"p d2 = p2 d2\"\n        by (auto simp add: state2vec_def)\n      show False\n        using \"0\" \\<open>p d2 = p2 d2\\<close> assms(3) that(1) that(4)\n        using less_eq_real_def by auto\n    qed\n    have s6: \"d2 \\<le> d\"\n    proof (rule ccontr)\n      assume 0: \"\\<not>(d2 \\<le> d)\"\n      from 0 have 1: \"(\\<lambda>t. state2vec (p t)) d = (\\<lambda>t. state2vec (p2 t)) d\"\n        using s2[of d] s4[of d] assms(1) by auto\n      from 1 have \"p d = p2 d\"\n        by (auto simp add: state2vec_def)\n      show False\n        using \"0\" \\<open>p d = p2 d\\<close> assms(1) assms(4) that(3) by auto\n    qed\n    have s7: \"d = d2\" using s5 s6 by auto\n    have s8: \"t\\<in>{0..d} \\<Longrightarrow> p2 t = p t\" for t\n      using s2 s4 s7 by (metis vec_state_map1)\n    have s10: \"p d = p2 d\"\n      using s8 by (simp add: assms(1) less_eq_real_def)\n    have s11: \"WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) ({}, {}) = WaitBlk d2 (\\<lambda>\\<tau>. EState (a,p2 \\<tau>)) ({}, {})\"\n      apply (rule WaitBlk_ext_real) using s7 s8 by auto\n    have s12: \"Wait\\<^sub>t d (\\<lambda>s. EState (a,p s)) ({}, {}) [WaitBlk d2 (\\<lambda>\\<tau>. EState (a,p2 \\<tau>)) ({}, {})]\"\n      unfolding s11[symmetric]\n      apply (rule wait_assn.intros)\n      using assms(1) by auto\n    show ?thesis using s7 s8 s10 s12 by auto\n  qed\n  show ?thesis\n    using assms(7) apply (auto simp add: ode_assn.simps)\n    subgoal using \\<open>b st\\<close> by auto\n    subgoal using \\<open>b st\\<close> by auto\n    subgoal for d1 p1\n      using main[of d1 p1] by auto\n    subgoal for d1 p1\n      using main[of d1 p1] by auto\n    done\nqed\n\n\n\ntext \\<open>Strongest postcondition rule for ODE when the ODE can be solved exactly\\<close>\ntheorem Valid_ode_unique_solution_sp:\n  assumes \"\\<And>s. b s \\<Longrightarrow> d s > 0 \\<and> ODEsol ode (p s) (d s) \\<and>\n                (\\<forall>t. t \\<ge> 0 \\<and> t < d s \\<longrightarrow> b (p s t)) \\<and>\n                \\<not>b (p s (d s)) \\<and> p s 0 = s\"\n    and \"local_lipschitz {- 1<..} UNIV (\\<lambda>(t::real) v. ODE2Vec ode (vec2state v))\"\n  shows \"\\<Turnstile>\n    {\\<lambda>(a,s) t. P (a,s) t}\n      Cont ode b\n    {\\<lambda>(a,s) t. \\<exists>s'. if b s' then (\\<up>(s = p s' (d s')) \\<and>\\<^sub>t P (a,s') @\\<^sub>t Wait\\<^sub>t (d s') (\\<lambda>\\<tau>. EState (a,p s' \\<tau>)) ({}, {})) t\n                else (\\<up>(s = s') \\<and>\\<^sub>t P (a,s')) t}\"\nproof -\n  have a: \"s' = p s (d s) \\<and> Wait\\<^sub>t (d s) (\\<lambda>\\<tau>. EState (a,p s \\<tau>)) ({}, {}) tr2\"\n    if \"ODE\\<^sub>t (a,s) ode b (a,s') tr2\" \"b s\" for a s s' tr2\n  proof -\n    have a1: \"d s > 0\" \"ODEsol ode (p s) (d s)\" \"\\<forall>t. 0 \\<le> t \\<and> t < d s \\<longrightarrow> b (p s t)\"\n             \"\\<not>b (p s (d s))\" \"p s 0 = s\"\n      using assms(1) that(2) by auto\n    show ?thesis\n      using Valid_ode_unique_solution_aux[OF a1(1-2) _ a1(4-5) assms(2) that(1)] a1(3)\n      by auto\n  qed\n  have b: \"ODE\\<^sub>t (a,s) ode b (a,s') tr2 \\<Longrightarrow> \\<not>b s \\<Longrightarrow> s = s' \\<and> tr2 = []\" for a s s' tr2\n    apply (induct rule: ode_assn_induct) by auto\n  show ?thesis\n    apply (rule Valid_weaken_pre)\n     prefer 2 apply (rule Valid_ode')\n    apply (auto simp add: entails_def magic_wand_assn_def)\n    subgoal for a s tr1 s' tr2\n      apply (rule exI[where x=s])\n      apply (auto simp add: join_assn_def conj_assn_def pure_assn_def)\n      apply (auto simp add: a)\n      using b apply metis\n      using b by fastforce\n    done\nqed\n\ntext \\<open>Strongest postcondition rule for ODE when the ODE can be solved exactly,\n  for fixed initial state.\n\\<close>\ntheorem Valid_ode_unique_solution_st:\n  assumes\n    \"d > 0\" \"ODEsol ode p d\" \"\\<forall>t. t \\<ge> 0 \\<and> t < d \\<longrightarrow> b (p t)\"\n    \"\\<not> b (p d)\" \"p 0 = st\"\n    \"local_lipschitz {- 1<..} UNIV (\\<lambda>(t::real) v. ODE2Vec ode (vec2state v))\"\n  shows \"\\<Turnstile>\n    {\\<lambda>s tr. s = (a,st) \\<and> Q s tr}\n      Cont ode b\n    {\\<lambda>s tr. s = (a,p d) \\<and> (Q (a,st) @\\<^sub>t Wait\\<^sub>t d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) ({}, {})) tr}\"\nproof -\n  have \"b st\"\n    using assms(1,3,5) by auto\n  have *: \"ODE\\<^sub>t (a,st) ode b (a,s) tr2 \\<Longrightarrow> s = p d \\<and> Wait\\<^sub>t d (\\<lambda>s. EState (a,p s)) ({}, {}) tr2\" for  s tr2\n    using Valid_ode_unique_solution_aux[OF assms(1-6)] by metis\n  show ?thesis\n    apply (rule Valid_strengthen_post)\n     prefer 2 apply (rule Valid_ode_sp_st)\n    apply (auto simp add: \\<open>b st\\<close> entails_def join_assn_def * ode_assn_ext_con)\n    subgoal for a' s' tr1 tr2\n      using * ode_assn_ext_con by metis\n    using * ode_assn_ext_con by metis\nqed\n\ntext \\<open>Case where the initial state does not satisfy domain\\<close>\ntheorem Valid_ode_exit_st:\n  assumes \"\\<not> b st\"\n  shows \"\\<Turnstile>\n    {\\<lambda>s tr. s = (a,st) \\<and> Q tr}\n      Cont ode b\n    {\\<lambda>s tr. s = (a,st) \\<and> Q tr}\"\n  apply (rule Valid_weaken_pre)\n   prefer 2 apply (rule Valid_ode)\n  using assms by (auto simp add: entails_def)\n\nsubsection \\<open>Simpler rules for interrupt\\<close>\n\ntheorem Valid_interrupt':\n  assumes \"\\<And>i. i < length cs \\<Longrightarrow>\n    case cs ! i of\n      (ch[!]e, p2) \\<Rightarrow>\n        (\\<exists>Q. \\<Turnstile> {Q} p2 {R} \\<and>\n             (P \\<Longrightarrow>\\<^sub>A (\\<lambda>(a,s) tr. \\<forall>s'. (ODEout\\<^sub>t (a,s) ode b (a,s') ch e (rdy_of_echoice cs) @- Q (a,s')) tr)))\n    | (ch[?]var, p2) \\<Rightarrow>\n        (\\<exists>Q. \\<Turnstile> {Q} p2 {R} \\<and>\n             (P \\<Longrightarrow>\\<^sub>A (\\<lambda>(a,s) tr. \\<forall>s'. (ODEin\\<^sub>t (a,s) ode b (a,s') ch var (rdy_of_echoice cs) @- Q (a,s')) tr)))\"\n    and \"P \\<Longrightarrow>\\<^sub>A (\\<lambda>(a,s) tr. \\<forall>s'. (ODErdy\\<^sub>t (a,s) ode b (a,s') (rdy_of_echoice cs) @- R (a,s')) tr)\"\n  shows \"\\<Turnstile> {P} Interrupt ode b cs {R}\"\nproof -\n  have 1: \"\\<exists>Q. \\<Turnstile> {Q} p {R} \\<and>\n           (P \\<Longrightarrow>\\<^sub>A (\\<lambda>(a,s) tr. Q (a,s) (tr @ [OutBlock ch (e (a,s))]))) \\<and>\n           (P \\<Longrightarrow>\\<^sub>A\n            (\\<lambda>(a,s) tr.\n                \\<forall>d>0. \\<forall>p. ODEsol ode p d \\<longrightarrow>\n                          p 0 = s \\<longrightarrow>\n                          (\\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p t)) \\<longrightarrow>\n                          Q (a,p d) (tr @ [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) (rdy_of_echoice cs), OutBlock ch (e (a,p d))])))\"\n    if *: \"i < length cs\" \"cs ! i = (ch[!]e, p)\" for i ch e p\n  proof -\n    from assms(1) obtain Q where\n      Q: \"\\<Turnstile> {Q} p {R} \\<and> (P \\<Longrightarrow>\\<^sub>A (\\<lambda>(a,s) tr. \\<forall>s'. (ODEout\\<^sub>t (a,s) ode b (a,s') ch e (rdy_of_echoice cs) @- Q (a,s')) tr))\"\n      using * by fastforce\n    show ?thesis\n      apply (rule exI[where x=Q])\n      using Q ode_out_assn.intros apply (auto simp add: entails_def magic_wand_assn_def)\n       apply (simp add: ode_out_assn.intros(1))\n      apply (simp add: ode_out_assn.intros(2))\n      done\n  qed\n  have 2: \"\\<exists>Q. \\<Turnstile> {Q} p {R} \\<and>\n           (P \\<Longrightarrow>\\<^sub>A (\\<lambda>(a,s) tr. \\<forall>v. Q (a,s(var := v)) (tr @ [InBlock ch v]))) \\<and>\n           (P \\<Longrightarrow>\\<^sub>A\n            (\\<lambda>(a,s) tr.\n                \\<forall>d>0. \\<forall>p. ODEsol ode p d \\<longrightarrow>\n                          p 0 = s \\<longrightarrow>\n                          (\\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p t)) \\<longrightarrow>\n                          (\\<forall>v. Q (a,(p d)(var := v)) (tr @ [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) (rdy_of_echoice cs), InBlock ch v]))))\"\n    if *: \"i < length cs\" \"cs ! i = (ch[?]var, p)\" for i ch var p\n  proof -\n    from assms(1) obtain Q where\n      Q: \"\\<Turnstile> {Q} p {R} \\<and> (P \\<Longrightarrow>\\<^sub>A (\\<lambda>(a,s) tr. \\<forall>s'. (ODEin\\<^sub>t (a,s) ode b (a,s') ch var (rdy_of_echoice cs) @- Q (a,s')) tr))\"\n      using * by fastforce\n    show ?thesis\n      apply (rule exI[where x=Q])\n      using Q ode_in_assn.intros apply (auto simp add: entails_def magic_wand_assn_def)\n       apply (simp add: ode_in_assn.intros(1))\n      apply (simp add: ode_in_assn.intros(2))\n      done\n  qed\n  have 3: \"R (a,s) tr\"\n    if \"\\<forall>s'. (ODErdy\\<^sub>t (a,s) ode b (a,s') (rdy_of_echoice cs) @- R (a,s')) tr\" \"\\<not> b s\" for a s tr\n  proof -\n    have \"(ODErdy\\<^sub>t (a,s) ode b (a,s) (rdy_of_echoice cs) @- R (a,s)) tr\"\n      using that(1) by auto\n    moreover have \"ODErdy\\<^sub>t (a,s) ode b (a,s) (rdy_of_echoice cs) []\"\n      using that(2) by (auto intro: ode_rdy_assn.intros)\n    ultimately show ?thesis\n      by (auto simp add: magic_wand_assn_def)\n  qed\n  have 4: \"R (a,p d) (tr @ [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) (rdy_of_echoice cs)])\"\n    if \"\\<forall>s'. (ODErdy\\<^sub>t (a,p 0) ode b (a,s') (rdy_of_echoice cs) @- R (a,s')) tr\"\n       \"0 < d\" \"ODEsol ode p d\"\n       \"\\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p t)\" \"\\<not> b (p d)\" for a p d tr\n  proof -\n    have \"(ODErdy\\<^sub>t (a,p 0) ode b (a,p d) (rdy_of_echoice cs) @- R (a,p d)) tr\"\n      using that(1) by auto\n    moreover have \"ODErdy\\<^sub>t (a,p 0) ode b (a,p d) (rdy_of_echoice cs) [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) (rdy_of_echoice cs)]\"\n      apply (rule ode_rdy_assn.intros)\n      using that by auto\n    ultimately show ?thesis\n      by (auto simp add: magic_wand_assn_def)\n  qed\n  show ?thesis\n    apply (rule Valid_interrupt)\n    subgoal for i apply (cases \"cs ! i\")\n      subgoal for ch p apply (cases ch)\n        using 1 2 by auto\n      done\n    subgoal apply (rule entails_trans[OF assms(2)])\n      by (auto simp add: entails_def 3)\n    subgoal apply (rule entails_trans[OF assms(2)])\n      by(auto simp add: 4 entails_def)\n    done\nqed\n\ntheorem Valid_interrupt_In':\n  assumes \"\\<Turnstile> {Q} p {R}\"\n  shows \"\\<Turnstile>\n    {\\<lambda>(a,s) tr. (\\<forall>s'. (ODEin\\<^sub>t (a,s) ode b (a,s') ch var ({}, {ch}) @- Q (a,s')) tr) \\<and>\n            (\\<forall>s'. (ODErdy\\<^sub>t (a,s) ode b (a,s') ({}, {ch}) @- R (a,s')) tr)}\n      Interrupt ode b [(ch[?]var, p)]\n    {R}\"\n  apply (rule Valid_interrupt')\n  using assms by (auto simp add: entails_def)\n\n\ntheorem Valid_interrupt_In'':\n  assumes \"\\<Turnstile> {Q} p {R}\"\n  shows \"\\<Turnstile>\n    {\\<lambda>s tr. (\\<forall>s'. (ODEin\\<^sub>t s ode b s' ch var ({}, {ch}) @- Q s') tr) \\<and>\n            (\\<forall>s'. (ODErdy\\<^sub>t s ode b s' ({}, {ch}) @- R s') tr)}\n      Interrupt ode b [(ch[?]var, p)]\n    {R}\"\n  apply (rule Valid_interrupt')\n  using assms by (auto simp add: entails_def)\n\ntheorem Valid_interrupt_Out':\n  assumes \"\\<Turnstile> {Q} p {R}\"\n  shows \"\\<Turnstile>\n    {\\<lambda>(a,s) tr. (\\<forall>s'. (ODEout\\<^sub>t (a,s) ode b (a,s') ch e ({ch}, {}) @- Q (a,s')) tr) \\<and>\n            (\\<forall>s'. (ODErdy\\<^sub>t (a,s) ode b (a,s') ({ch}, {}) @- R (a,s')) tr)}\n      Interrupt ode b [(ch[!]e, p)]\n    {R}\"\n  apply (rule Valid_interrupt')\n  using assms by (auto simp add: entails_def)\n\ntheorem Valid_interrupt_Out'':\n  assumes \"\\<Turnstile> {Q} p {R}\"\n  shows \"\\<Turnstile>\n    {\\<lambda>s tr. (\\<forall>s'. (ODEout\\<^sub>t s ode b s' ch e ({ch}, {}) @- Q s') tr) \\<and>\n            (\\<forall>s'. (ODErdy\\<^sub>t s ode b s' ({ch}, {}) @- R s') tr)}\n      Interrupt ode b [(ch[!]e, p)]\n    {R}\"\n  apply (rule Valid_interrupt')\n  using assms by (auto simp add: entails_def)\n\ntheorem Valid_interrupt_sp:\n  assumes \"\\<And>i. i < length cs \\<Longrightarrow>\n    case cs ! i of\n      (ch[!]e, p2) \\<Rightarrow>\n        \\<Turnstile> {\\<lambda>s tr. (P st @\\<^sub>t ODEout\\<^sub>t st ode b s ch e (rdy_of_echoice cs)) tr} p2 {Q}\n    | (ch[?]var, p2) \\<Rightarrow>\n        \\<Turnstile> {\\<lambda>s tr. (P st @\\<^sub>t ODEin\\<^sub>t st ode b s ch var (rdy_of_echoice cs)) tr} p2 {Q}\"\n  assumes \"(\\<lambda>s tr. (P st @\\<^sub>t (ODErdy\\<^sub>t st ode b s (rdy_of_echoice cs))) tr) \\<Longrightarrow>\\<^sub>A Q\"\n  shows \"\\<Turnstile>\n    {\\<lambda>s tr. s = st \\<and> P s tr}\n      Interrupt ode b cs\n    {Q}\"\n  apply (rule Valid_interrupt')\n  subgoal for i\n    apply (cases \"cs ! i\") apply auto\n    subgoal for comm p2\n      apply (cases comm)\n      subgoal for ch e\n        apply auto\n        apply (rule exI[where x=\"\\<lambda>s tr. (P st @\\<^sub>t ODEout\\<^sub>t st ode b s ch e (rdy_of_echoice cs)) tr\"])\n        using assms(1)[of i]\n        by (auto simp add: entails_def magic_wand_assn_def join_assn_def)\n      subgoal for ch var\n        apply auto\n        apply (rule exI[where x=\"\\<lambda>s tr. (P st @\\<^sub>t ODEin\\<^sub>t st ode b s ch var (rdy_of_echoice cs)) tr\"])\n        using assms(1)[of i]\n        by (auto simp add: entails_def magic_wand_assn_def join_assn_def)\n      done\n    done\n  using assms(2) apply (auto simp add: entails_def magic_wand_assn_def)\n  using join_assn_def by metis\n\n\ntheorem Valid_interrupt_sp':\n  assumes \"\\<And>i. i < length cs \\<Longrightarrow>\n    case cs ! i of\n      (ch[!]e, p2) \\<Rightarrow>\n        \\<Turnstile> {\\<lambda>(a,s) tr. (P (a,st) @\\<^sub>t ODEout\\<^sub>t (a,st) ode b (a,s) ch e (rdy_of_echoice cs)) tr} p2 {Q}\n    | (ch[?]var, p2) \\<Rightarrow>\n        \\<Turnstile> {\\<lambda>(a,s) tr. (P (a,st) @\\<^sub>t ODEin\\<^sub>t (a,st) ode b (a,s) ch var (rdy_of_echoice cs)) tr} p2 {Q}\"\n  assumes \"(\\<lambda>(a,s) tr. (P (a,st) @\\<^sub>t (ODErdy\\<^sub>t (a,st) ode b (a,s) (rdy_of_echoice cs))) tr) \\<Longrightarrow>\\<^sub>A Q\"\n  shows \"\\<Turnstile>\n    {\\<lambda>(a,s) tr. s = st \\<and> P (a,s) tr}\n      Interrupt ode b cs\n    {Q}\"\n  apply (rule Valid_interrupt')\n  subgoal for i\n    apply (cases \"cs ! i\") apply auto\n    subgoal for comm p2\n      apply (cases comm)\n      subgoal for ch e\n        apply auto\n        apply (rule exI[where x=\"\\<lambda>(a,s) tr. (P (a,st) @\\<^sub>t ODEout\\<^sub>t (a,st) ode b (a,s) ch e (rdy_of_echoice cs)) tr\"])\n        using assms(1)[of i]\n        by (auto simp add: entails_def magic_wand_assn_def join_assn_def)\n      subgoal for ch var\n        apply auto\n        apply (rule exI[where x=\"\\<lambda>(a,s)tr. (P (a,st) @\\<^sub>t ODEin\\<^sub>t (a,st) ode b (a,s) ch var (rdy_of_echoice cs)) tr\"])\n        using assms(1)[of i]\n        by (auto simp add: entails_def magic_wand_assn_def join_assn_def)\n      done\n    done\n  using assms(2) apply (auto simp add: entails_def magic_wand_assn_def)\n  using join_assn_def by metis\n\ntheorem Valid_interrupt_In_sp:\n  assumes \"\\<Turnstile> {\\<lambda>s tr. (P st @\\<^sub>t ODEin\\<^sub>t st ode b s ch var ({}, {ch})) tr} p {Q}\"\n  shows \"\\<Turnstile>\n    {\\<lambda>s tr. s = st \\<and> P s tr}\n      Interrupt ode b [(ch[?]var, p)]\n    {\\<lambda>s tr. Q s tr \\<or> (P st @\\<^sub>t (ODErdy\\<^sub>t st ode b s ({}, {ch}))) tr}\"\n  apply (rule Valid_interrupt_sp)\n  using assms by (auto simp add: Valid_def entails_def)\n\ntheorem Valid_interrupt_In_sp':\n  assumes \"\\<Turnstile> {\\<lambda>(a,s) tr. (P (a,st) @\\<^sub>t ODEin\\<^sub>t (a,st) ode b (a,s) ch var ({}, {ch})) tr} p {Q}\"\n  shows \"\\<Turnstile>\n    {\\<lambda>(a,s) tr. s = st \\<and> P (a,s) tr}\n      Interrupt ode b [(ch[?]var, p)]\n    {\\<lambda>(a,s) tr. Q (a,s) tr \\<or> (P (a,st) @\\<^sub>t (ODErdy\\<^sub>t (a,st) ode b (a,s) ({}, {ch}))) tr}\"\n  apply (rule Valid_interrupt_sp')\n  using assms by (auto simp add: Valid_def entails_def)\n\ntheorem Valid_interrupt_Out_sp:\n  assumes \"\\<Turnstile> {\\<lambda>s tr. (P st @\\<^sub>t ODEout\\<^sub>t st ode b s ch e ({ch}, {})) tr} p {Q}\"\n  shows \"\\<Turnstile>\n    {\\<lambda>s tr. s = st \\<and> P s tr}\n      Interrupt ode b [(ch[!]e, p)]\n    {\\<lambda>s tr. Q s tr \\<or> (P st @\\<^sub>t (ODErdy\\<^sub>t st ode b s ({ch}, {}))) tr}\"\n  apply (rule Valid_interrupt_sp)\n  using assms by (auto simp add: Valid_def entails_def)\n\ntheorem Valid_interrupt_Out_sp':\n  assumes \"\\<Turnstile> {\\<lambda>(a,s) tr. (P (a,st) @\\<^sub>t ODEout\\<^sub>t (a,st) ode b (a,s) ch e ({ch}, {})) tr} p {Q}\"\n  shows \"\\<Turnstile>\n    {\\<lambda>(a,s) tr. s = st \\<and> P (a,s) tr}\n      Interrupt ode b [(ch[!]e, p)]\n    {\\<lambda>(a,s) tr. Q (a,s) tr \\<or> (P (a,st) @\\<^sub>t (ODErdy\\<^sub>t (a,st) ode b (a,s) ({ch}, {}))) tr}\"\n  apply (rule Valid_interrupt_sp')\n  using assms by (auto simp add: Valid_def entails_def)\n\nlemma ODErdy_false:\n  \"ODErdy\\<^sub>t st ode b s rdy tr \\<Longrightarrow> b = (\\<lambda>_. True) \\<Longrightarrow> False\"\n  apply (induct rule: ode_rdy_assn.induct) by auto\n\ndefinition supp :: \"state \\<Rightarrow> var set\" where\n  \"supp s = {v. s v \\<noteq> 0}\"\n\nfun ode_supp :: \"ODE \\<Rightarrow> var set\" where\n  \"ode_supp (ODE ode) = {v. ode v \\<noteq> (\\<lambda>_. 0)}\"\n\ntheorem Valid_interrupt_Out_sp2:\n  assumes \"\\<Turnstile> {\\<lambda>(a,s) tr. \\<exists>st'. s = st' \\<and> supp st' \\<subseteq> VS \\<and>\n                (P (a,st) @\\<^sub>t ODEout\\<^sub>t (a,st) (ODE ode) (\\<lambda>_. True) (a,st') ch e ({ch}, {})) tr} p {Q}\"\n    and \"ode_supp (ODE ode) \\<subseteq> VS\"\n    and \"supp st \\<subseteq> VS\"\n  shows \"\\<Turnstile>\n    {\\<lambda>(a,s) tr. s = st \\<and> P (a,s) tr}\n      Interrupt (ODE ode) (\\<lambda>_. True) [(ch[!]e, p)]\n    {Q}\"\n  apply (rule Valid_strengthen_post)\n   prefer 2\n   apply (rule Valid_interrupt_Out_sp')\n   apply (rule Valid_weaken_pre)\n    prefer 2 apply (rule assms)\n  apply (auto simp add: entails_def)\n   apply (auto simp add: Valid_def entails_def join_assn_def)\n  subgoal for a s x tr1 tr2\n    subgoal premises pre\n    proof(rule ccontr)\n      assume cond:\"x \\<notin> VS\"\n    have 1:\"ODEout\\<^sub>t (a,st) (ODE ode) (\\<lambda>_. True) (a,s) ch e ({ch}, {}) tr2 \\<Longrightarrow> tr2 =  [OutBlock ch (e (a,s))] \\<Longrightarrow> st = s\"\n      apply (induct rule: ode_out_assn_induct) by auto\n    have 2:\"ODEout\\<^sub>t (a,st) (ODE ode) (\\<lambda>_. True) (a,s) ch e ({ch}, {}) tr2 \\<Longrightarrow> tr2 =  [OutBlock ch (e (a,s))] \\<Longrightarrow> False\"\n      using 1 pre cond assms(3) unfolding supp_def by auto\n    have 3:\"ODEout\\<^sub>t (a,st) (ODE ode) (\\<lambda>_. True) (a,s) ch e ({ch}, {}) tr2 \\<Longrightarrow> tr2 \\<noteq>  [OutBlock ch (e (a,s))] \\<Longrightarrow>\n\\<exists> p d. (0 < (d::real) \\<and>  ODEsol (ODE ode) p d \\<and> p 0 = st \\<and>\n    s = p d \\<and> tr2 = [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) ({ch}, {}), OutBlock ch (e (a,p d))])\"\n      apply (induct rule: ode_out_assn_induct) by auto\n    have 4:\"ODEout\\<^sub>t (a,st) (ODE ode) (\\<lambda>_. True) (a,s) ch e ({ch}, {}) tr2 \\<Longrightarrow> tr2 \\<noteq>  [OutBlock ch (e (a,s))] \\<Longrightarrow>False\"\n      subgoal premises pre1\n      proof-\n        obtain p and d where condd:\"0 < (d::real)\"\" ODEsol (ODE ode) p d\"\"p 0 = st\"\" s = p d \"\n          using pre1 3 by auto\n        have a1:\"p 0 x = 0\" using pre condd cond assms(3) unfolding supp_def by auto\n        have a2:\"ode x = (\\<lambda>_. 0)\"\n          using assms(2) cond by auto\n        have a3:\"((\\<lambda>t. p t x) has_vderiv_on (\\<lambda>t. 0)) {0 .. d}\"\n          using ODEsol_old[OF condd(2)]\n          using has_vderiv_on_proj[of \"(\\<lambda>t. state2vec (p t))\" \"(\\<lambda>t. ODE2Vec (ODE ode) (p t))\"  \"{0 .. d}\" x]\n          apply auto\n          unfolding state2vec_def apply auto\n          using a2 by auto\n        then have 4:\"p 0 x = p d x\"\n          unfolding has_vderiv_on_def has_vector_derivative_def\n          using mvt_real_eq[of d \"(\\<lambda>t. p t x)\" \"\\<lambda>t. (\\<lambda>x. x *\\<^sub>R 0)\" d] \n          using condd by auto\n        then show ?thesis using a1 cond pre condd unfolding supp_def by auto\n      qed\n      done\n    show False using 2 4 pre by auto\n  qed\n  done\n  using ODErdy_false by blast\n\ninductive wait_in_assn :: \"real \\<Rightarrow> 'a \\<Rightarrow> (real \\<Rightarrow> state) \\<Rightarrow> cname \\<Rightarrow> real \\<Rightarrow> rdy_info \\<Rightarrow> 'a tassn\" (\"WaitIn\\<^sub>t\") where\n  \"WaitIn\\<^sub>t 0 a p ch v rdy [InBlock ch v]\"\n| \"d > 0 \\<Longrightarrow> WaitIn\\<^sub>t d a p ch v rdy [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) rdy, InBlock ch v]\"\n\n\ninductive wait_out_assn :: \"real \\<Rightarrow> 'a \\<Rightarrow> (real \\<Rightarrow> state) \\<Rightarrow> cname \\<Rightarrow> 'a ext_exp \\<Rightarrow> rdy_info \\<Rightarrow> 'a tassn\" (\"WaitOut\\<^sub>t\") where\n  \"WaitOut\\<^sub>t 0 a p ch e rdy [OutBlock ch (e (a,p 0))]\"\n| \"d > 0 \\<Longrightarrow> WaitOut\\<^sub>t d a p ch e rdy [WaitBlk d (\\<lambda>\\<tau>. EState (a,p \\<tau>)) rdy, OutBlock ch (e (a,p d))]\"\n\n\ntheorem Valid_ode_out_unique_solution_aux:\n  assumes\n    \"ODEsolInf ode p\" \"\\<forall>t\\<ge>0. b (p t)\" \"p 0 = st\"\n    \"local_lipschitz {- 1<..} UNIV (\\<lambda>(t::real) v. ODE2Vec ode (vec2state v))\"\n    \"ODEout\\<^sub>t (a,st) ode b (a,st') ch e rdy tr\"\n  shows\n    \"\\<exists>d. st' = p d \\<and> WaitOut\\<^sub>t d a p ch e rdy tr\"\nproof -\n  have main: \"p2 d = p d \\<and> (\\<forall>\\<tau>\\<in>{0..d}. EState (a,p2 \\<tau>) = EState (a,p \\<tau>))\"\n    if cond: \"0 < d\"\n       \"ODEsol ode p2 d\"\n       \"\\<forall>t. 0 \\<le> t \\<and> t < d \\<longrightarrow> b (p2 t)\"\n       \"p2 0 = st\" for d p2\n  proof -\n    interpret loc:ll_on_open_it \"{-1<..}\"\n      \"\\<lambda>t v. ODE2Vec ode (vec2state v)\" UNIV 0\n      apply standard\n      using assms(4) by auto\n    have s1: \"((\\<lambda>t. state2vec (p t)) solves_ode ((\\<lambda>t v. ODE2Vec ode (vec2state v)))) {0..} UNIV\"\n      using assms(1) using ODEsolInf_old[OF assms(1)] unfolding ODEsolInf_def solves_ode_def by auto\n    have s2: \"(loc.flow 0 (state2vec st)) t = (\\<lambda>t. state2vec (p t)) t\" if \"t \\<in> {0..d}\" for t\n      apply (rule loc.maximal_existence_flow(2)[OF s1])\n      using that by (auto simp add: state2vec_def assms(3))\n    have s3: \"((\\<lambda>t. state2vec(p2 t)) solves_ode ((\\<lambda>t v. ODE2Vec ode (vec2state v)))) {0..d} UNIV\"\n      using cond(2) using ODEsol_old[OF cond(2)]unfolding ODEsol_def solves_ode_def by auto\n    have s4: \"loc.flow 0 (state2vec st) t = state2vec (p2 t)\" if \"t\\<in>{0..d}\" for t\n      apply (rule loc.maximal_existence_flow(2)[OF s3])\n      using cond that by auto\n    have s8: \"t\\<in>{0..d} \\<Longrightarrow> p2 t = p t\" for t\n      using s2 s4 by (metis vec_state_map1)\n    have s10: \"p d = p2 d\"\n      using s8 that(1) by auto\n    show ?thesis using s8 s10 by auto\n  qed\n  show ?thesis\n    using assms(5) apply (elim ode_out_assn.cases)\n     apply auto\n     apply (rule exI[where x=0])\n    subgoal for rdy1 rdy2\n      by (auto simp add: assms(3) wait_out_assn.simps)\n    subgoal for d p2 rdy1 rdy2\n      apply (rule exI[where x=d])\n      apply (auto simp add: wait_out_assn.simps)\n      using main[of d p2] apply (auto simp: WaitBlk.simps)\n      done\n    done\nqed\n\n\ntheorem Valid_ode_rdy_unique_solution_aux:\n  assumes\n    \"ODEsolInf ode p\" \"\\<forall>t\\<ge>0. b (p t)\" \"p 0 = st\"\n    \"local_lipschitz {- 1<..} UNIV (\\<lambda>(t::real) v. ODE2Vec ode (vec2state v))\"\n    \"ODErdy\\<^sub>t (a,st) ode b (a,st') rdy tr\"\n  shows\n    \"False\"\nproof -\n  have \"b st\"\n    using assms(2,3) by auto\n  have main: \"False\"\n    if cond: \"0 < d1\"\n       \"ODEsol ode p1 d1\"\n       \"st = p1 0\"\n       \"\\<forall>t. 0 \\<le> t \\<and> t < d1 \\<longrightarrow> b (p1 t)\"\n       \"\\<not> b (p1 d1)\" for d1 p1\n  proof -\n    interpret loc:ll_on_open_it \"{-1<..}\"\n      \"\\<lambda>t v. ODE2Vec ode (vec2state v)\" UNIV 0\n      apply standard\n      using assms(4) by auto\n    have s1: \"((\\<lambda>t. state2vec (p t)) solves_ode ((\\<lambda>t v. ODE2Vec ode (vec2state v)))) {0..} UNIV\"\n      using assms(1) using ODEsolInf_old[OF assms(1)] unfolding ODEsolInf_def solves_ode_def by auto\n    have s2: \"(loc.flow 0 (state2vec st)) t = (\\<lambda>t. state2vec (p t)) t\" if \"t \\<in> {0..d1}\" for t\n      apply (rule loc.maximal_existence_flow(2)[OF s1])\n      using that by (auto simp add: state2vec_def assms(3))\n    have s3: \"((\\<lambda>t. state2vec(p1 t)) solves_ode ((\\<lambda>t v. ODE2Vec ode (vec2state v)))) {0..d1} UNIV\"\n      using cond(2) using ODEsol_old[OF cond(2)] unfolding ODEsol_def solves_ode_def by auto\n    have s4: \"loc.flow 0 (state2vec st) t = state2vec (p1 t)\" if \"t\\<in>{0..d1}\" for t\n      apply (rule loc.maximal_existence_flow(2)[OF s3])\n      using cond that by auto\n    have s8: \"t\\<in>{0..d1} \\<Longrightarrow> p1 t = p t\" for t\n      using s2 s4 by (metis vec_state_map1)\n    have s10: \"p d1 = p1 d1\"\n      using s8 that(1) by auto\n    show ?thesis using assms(2) cond(1,5) s10\n      using less_eq_real_def by auto\n  qed    \n  show ?thesis\n    using assms(5) apply (auto simp add: ode_rdy_assn.simps)\n    subgoal using \\<open>b st\\<close> by auto\n    subgoal for d1 p1\n      using main by auto\n    done\nqed\n\ntheorem Valid_ode_out_unique_solution:\n  assumes\n    \"ODEsolInf ode p\" \"\\<forall>t\\<ge>0. b (p t)\" \"p 0 = st\"\n    \"local_lipschitz {- 1<..} UNIV (\\<lambda>(t::real) v. ODE2Vec ode (vec2state v))\"\n    \"\\<Turnstile> {\\<lambda>(a,s) tr. \\<exists>d. s = p d \\<and> (P (a,st) @\\<^sub>t WaitOut\\<^sub>t d a p ch e ({ch}, {})) tr} p2 {Q}\"\n  shows \"\\<Turnstile>\n    {\\<lambda>(a,s) tr. s = st \\<and> P (a,s) tr}\n      Interrupt ode b [(ch[!]e, p2)]\n    {Q}\"\nproof -\n  have *: \"ODEout\\<^sub>t (a,st) ode b (a,s) ch e ({ch}, {}) tr2 \\<Longrightarrow>\n           \\<exists>d. s = p d \\<and> WaitOut\\<^sub>t d a p ch e ({ch}, {}) tr2\" for a s tr2\n    using Valid_ode_out_unique_solution_aux[OF assms(1-4)] by auto\n  have **: \"ODErdy\\<^sub>t (a,st) ode b (a,s) ({ch}, {}) tr2 \\<Longrightarrow> False\" for a s tr2\n    using Valid_ode_rdy_unique_solution_aux[OF assms(1-4)] by auto\n  show ?thesis\n    apply (rule Valid_strengthen_post)\n     prefer 2 apply (rule Valid_interrupt_Out_sp'[where Q=Q])\n    subgoal\n      apply (auto simp add: Valid_def join_assn_def)\n      apply (drule *)\n      using assms(5) apply (auto simp add: Valid_def join_assn_def join_assoc)\n      by fastforce\n    apply (auto simp add: entails_def join_assn_def)\n    using ** by metis\nqed\n\n\n\nend", "meta": {"author": "AgHHL", "repo": "lics2023", "sha": "e2ea9c15a8c0e1bf658679274ee87f30baf4abc3", "save_path": "github-repos/isabelle/AgHHL-lics2023", "path": "github-repos/isabelle/AgHHL-lics2023/lics2023-e2ea9c15a8c0e1bf658679274ee87f30baf4abc3/case2/ext_BigStepContinuous.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5273165382362517, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.2615984807969706}}
{"text": "(* The value setup for paper confidentiality *)\ntheory Decision_Value_Setup2\nimports Decision_Value_Setup\nbegin\n\nsection\\<open>Preliminaries\\<close>\n\n(* two papers equal everywhere but w.r.t. the tail of the decision: *)\nfun eqExcD2 :: \"paper \\<Rightarrow> paper \\<Rightarrow> bool\" where\n\"eqExcD2 (Paper title abstract ct reviews dis decs )\n         (Paper title1 abstract1 ct1 reviews1 dis1 decs1) =\n (title = title1 \\<and> abstract = abstract1 \\<and> ct = ct1 \\<and> reviews = reviews1 \\<and> dis = dis1 \\<and>\n hd decs = hd decs1)\"\n\nlemma eqExcD2:\n\"eqExcD2 pap pap1 =\n (titlePaper pap = titlePaper pap1 \\<and> abstractPaper pap = abstractPaper pap1 \\<and>\n  contentPaper pap = contentPaper pap1 \\<and>\n  reviewsPaper pap = reviewsPaper pap1 \\<and> disPaper pap = disPaper pap1 \\<and>\n  hd (decsPaper pap) = hd (decsPaper pap1)\n )\"\nby(cases pap, cases pap1, auto)\n\nlemma eqExcD2_eq[simp,intro!]: \"eqExcD2 pap pap\"\nby(cases pap) auto\n\nlemma eqExcD2_sym:\nassumes \"eqExcD2 pap pap1\"\nshows \"eqExcD2 pap1 pap\"\napply(cases pap, cases pap1)\nusing assms by auto\n\nlemma eqExcD2_trans:\nassumes \"eqExcD2 pap pap1\" and \"eqExcD2 pap1 pap2\"\nshows \"eqExcD2 pap pap2\"\napply(cases pap, cases pap1, cases pap2)\nusing assms by auto\n\n(* Auxiliary notion:  *)\ndefinition eeqExcPID2 where\n\"eeqExcPID2 paps paps1 \\<equiv>\n \\<forall> pid. if pid = PID then eqExcD2 (paps pid) (paps1 pid) else paps pid = paps1 pid\"\n\nlemma eeqExcPID2_eeq[simp,intro!]: \"eeqExcPID2 s s\"\nunfolding eeqExcPID2_def by auto\n\nlemma eeqExcPID2_sym:\nassumes \"eeqExcPID2 s s1\" shows \"eeqExcPID2 s1 s\"\nusing assms eqExcD2_sym unfolding eeqExcPID2_def by auto\n\nlemma eeqExcPID2_trans:\nassumes \"eeqExcPID2 s s1\" and \"eeqExcPID2 s1 s2\" shows \"eeqExcPID2 s s2\"\nusing assms eqExcD2_trans unfolding eeqExcPID2_def by simp blast\n\nlemma eeqExcPID2_imp:\n\"eeqExcPID2 paps paps1 \\<Longrightarrow> eqExcD2 (paps PID) (paps1 PID)\"\n\"\\<lbrakk>eeqExcPID2 paps paps1; pid \\<noteq> PID\\<rbrakk> \\<Longrightarrow> paps pid = paps1 pid\"\nunfolding eeqExcPID2_def by auto\n\nlemma eeqExcPID2_cong:\nassumes \"eeqExcPID2 paps paps1\"\nand \"pid = PID \\<Longrightarrow> eqExcD2 uu uu1\"\nand \"pid \\<noteq> PID \\<Longrightarrow> uu = uu1\"\nshows \"eeqExcPID2 (paps (pid := uu)) (paps1(pid := uu1))\"\nusing assms unfolding eeqExcPID2_def by auto\n\nlemma eeqExcPID2_RDD:\n\"eeqExcPID2 paps paps1 \\<Longrightarrow>\n titlePaper (paps PID) = titlePaper (paps1 PID) \\<and>\n abstractPaper (paps PID) = abstractPaper (paps1 PID) \\<and>\n contentPaper (paps PID) = contentPaper (paps1 PID) \\<and>\n reviewsPaper (paps PID) = reviewsPaper (paps1 PID) \\<and>\n disPaper (paps PID) = disPaper (paps1 PID) \\<and>\n hd (decsPaper (paps PID)) = hd (decsPaper (paps PID))\"\nusing eeqExcPID2_def unfolding eqExcD2 by auto\n\n(* The notion of two states being equal everywhere but on the tail of the decision of\n   the paper associated to a given PID *)\ndefinition eqExcPID2 :: \"state \\<Rightarrow> state \\<Rightarrow> bool\" where\n\"eqExcPID2 s s1 \\<equiv>\n confIDs s = confIDs s1 \\<and> conf s = conf s1 \\<and>\n userIDs s = userIDs s1 \\<and> pass s = pass s1 \\<and> user s = user s1 \\<and> roles s = roles s1 \\<and>\n paperIDs s = paperIDs s1\n \\<and>\n eeqExcPID2 (paper s) (paper s1)\n \\<and>\n pref s = pref s1 \\<and>\n voronkov s = voronkov s1 \\<and>\n news s = news s1 \\<and> phase s = phase s1\"\n\nlemma eqExcPID2_eq[simp,intro!]: \"eqExcPID2 s s\"\nunfolding eqExcPID2_def by auto\n\nlemma eqExcPID2_sym:\nassumes \"eqExcPID2 s s1\" shows \"eqExcPID2 s1 s\"\nusing assms eeqExcPID2_sym unfolding eqExcPID2_def by auto\n\nlemma eqExcPID2_trans:\nassumes \"eqExcPID2 s s1\" and \"eqExcPID2 s1 s2\" shows \"eqExcPID2 s s2\"\nusing assms eeqExcPID2_trans unfolding eqExcPID2_def by auto\n\n(* Implications from eqExcPID2, including w.r.t. auxiliary operations: *)\nlemma eqExcPID2_imp:\n\"eqExcPID2 s s1 \\<Longrightarrow>\n confIDs s = confIDs s1 \\<and> conf s = conf s1 \\<and>\n userIDs s = userIDs s1 \\<and> pass s = pass s1 \\<and> user s = user s1 \\<and> roles s = roles s1 \\<and>\n paperIDs s = paperIDs s1\n \\<and>\n eeqExcPID2 (paper s) (paper s1)\n \\<and>\n pref s = pref s1 \\<and>\n voronkov s = voronkov s1 \\<and>\n news s = news s1 \\<and> phase s = phase s1 \\<and>\n\n getAllPaperIDs s = getAllPaperIDs s1 \\<and>\n isRev s cid uid pid = isRev s1 cid uid pid \\<and>\n getReviewIndex s cid uid pid = getReviewIndex s1 cid uid pid \\<and>\n getRevRole s cid uid pid = getRevRole s1 cid uid pid\"\nunfolding eqExcPID2_def getAllPaperIDs_def\nunfolding isRev_def getReviewIndex_def getRevRole_def by auto\n\nlemma eqExcPID2_imp1:\n\"eqExcPID2 s s1 \\<Longrightarrow> eqExcD2 (paper s pid) (paper s1 pid)\"\n\"eqExcPID2 s s1 \\<Longrightarrow> pid \\<noteq> PID \\<or> PID \\<noteq> pid \\<Longrightarrow>\n    paper s pid = paper s1 pid \\<and>\n    getNthReview s pid n = getNthReview s1 pid n\"\nunfolding eqExcPID2_def getNthReview_def eeqExcPID2_def\napply auto\nby (metis eqExcD2_eq)\n\nlemma eqExcPID2_imp2:\nassumes \"eqExcPID2 s s1\" and \"pid \\<noteq> PID \\<or> PID \\<noteq> pid\"\nshows \"getReviewersReviews s cid pid = getReviewersReviews s1 cid pid\"\nproof-\n  have\n  \"(\\<lambda>uID. if isRev s cid uID pid then [(uID, getNthReview s pid (getReviewIndex s cid uID pid))] else []) =\n   (\\<lambda>uID. if isRev s1 cid uID pid then [(uID, getNthReview s1 pid (getReviewIndex s1 cid uID pid))] else [])\"\n  apply(rule ext)\n  using assms by (auto simp: eqExcPID2_imp eqExcPID2_imp1)\n  thus ?thesis unfolding getReviewersReviews_def using assms by (simp add: eqExcPID2_imp)\nqed\n\nlemma eqExcPID2_RDD:\n\"eqExcPID2 s s1 \\<Longrightarrow>\n titlePaper (paper s PID) = titlePaper (paper s1 PID) \\<and>\n abstractPaper (paper s PID) = abstractPaper (paper s1 PID) \\<and>\n contentPaper (paper s PID) = contentPaper (paper s1 PID) \\<and>\n reviewsPaper (paper s PID) = reviewsPaper (paper s1 PID) \\<and>\n disPaper (paper s PID) = disPaper (paper s1 PID)\"\nusing eqExcPID2_imp eeqExcPID2_RDD by auto\n\nlemma eqExcPID2_cong[simp, intro]:\n\"\\<And> uu1 uu2. eqExcPID2 s s1 \\<Longrightarrow> uu1 = uu2 \\<Longrightarrow> eqExcPID2 (s \\<lparr>confIDs := uu1\\<rparr>) (s1 \\<lparr>confIDs := uu2\\<rparr>)\"\n\"\\<And> uu1 uu2. eqExcPID2 s s1 \\<Longrightarrow> uu1 = uu2 \\<Longrightarrow> eqExcPID2 (s \\<lparr>conf := uu1\\<rparr>) (s1 \\<lparr>conf := uu2\\<rparr>)\"\n\n\"\\<And> uu1 uu2. eqExcPID2 s s1 \\<Longrightarrow> uu1 = uu2 \\<Longrightarrow> eqExcPID2 (s \\<lparr>userIDs := uu1\\<rparr>) (s1 \\<lparr>userIDs := uu2\\<rparr>)\"\n\"\\<And> uu1 uu2. eqExcPID2 s s1 \\<Longrightarrow> uu1 = uu2 \\<Longrightarrow> eqExcPID2 (s \\<lparr>pass := uu1\\<rparr>) (s1 \\<lparr>pass := uu2\\<rparr>)\"\n\"\\<And> uu1 uu2. eqExcPID2 s s1 \\<Longrightarrow> uu1 = uu2 \\<Longrightarrow> eqExcPID2 (s \\<lparr>user := uu1\\<rparr>) (s1 \\<lparr>user := uu2\\<rparr>)\"\n\"\\<And> uu1 uu2. eqExcPID2 s s1 \\<Longrightarrow> uu1 = uu2 \\<Longrightarrow> eqExcPID2 (s \\<lparr>roles := uu1\\<rparr>) (s1 \\<lparr>roles := uu2\\<rparr>)\"\n\n\"\\<And> uu1 uu2. eqExcPID2 s s1 \\<Longrightarrow> uu1 = uu2 \\<Longrightarrow> eqExcPID2 (s \\<lparr>paperIDs := uu1\\<rparr>) (s1 \\<lparr>paperIDs := uu2\\<rparr>)\"\n\"\\<And> uu1 uu2. eqExcPID2 s s1 \\<Longrightarrow> eeqExcPID2 uu1 uu2 \\<Longrightarrow> eqExcPID2 (s \\<lparr>paper := uu1\\<rparr>) (s1 \\<lparr>paper := uu2\\<rparr>)\"\n\n\"\\<And> uu1 uu2. eqExcPID2 s s1 \\<Longrightarrow> uu1 = uu2 \\<Longrightarrow> eqExcPID2 (s \\<lparr>pref := uu1\\<rparr>) (s1 \\<lparr>pref := uu2\\<rparr>)\"\n\"\\<And> uu1 uu2. eqExcPID2 s s1 \\<Longrightarrow> uu1 = uu2 \\<Longrightarrow> eqExcPID2 (s \\<lparr>voronkov := uu1\\<rparr>) (s1 \\<lparr>voronkov := uu2\\<rparr>)\"\n\"\\<And> uu1 uu2. eqExcPID2 s s1 \\<Longrightarrow> uu1 = uu2 \\<Longrightarrow> eqExcPID2 (s \\<lparr>news := uu1\\<rparr>) (s1 \\<lparr>news := uu2\\<rparr>)\"\n\"\\<And> uu1 uu2. eqExcPID2 s s1 \\<Longrightarrow> uu1 = uu2 \\<Longrightarrow> eqExcPID2 (s \\<lparr>phase := uu1\\<rparr>) (s1 \\<lparr>phase := uu2\\<rparr>)\"\nunfolding eqExcPID2_def by auto\n\nlemma eqExcPID2_Paper:\nassumes s's1': \"eqExcPID2 s s1\"\nand \"paper s pid = Paper title abstract content reviews dis decs\"\nand \"paper s1 pid = Paper title1 abstract1 content1 reviews1 dis1 decs1\"\nshows \"title = title1 \\<and> abstract = abstract1 \\<and> content = content1 \\<and> reviews = reviews1 \\<and>\n    dis = dis1\"\nusing assms unfolding eqExcPID2_def apply (auto simp: eqExcD2 eeqExcPID2_def)\n  by (metis titlePaper.simps abstractPaper.simps contentPaper.simps reviewsPaper.simps\ndisPaper.simps)+\n\n\nsection\\<open>Value Setup\\<close>\n\n(* These hold for eeqExcPID, but not for eeqExcPID2:\nlemma UUact_uuDec_step_eqExcPID2:\nassumes a: \"a = UUact (uuDec cid uid p PID dec)\"\nand \"step s a = (ou,s')\"\nshows \"eqExcPID2 s s'\"\nusing assms unfolding eqExcPID2_def eeqExcPID2_def by (auto simp: uu_defs)\n\nlemma \\<phi>_step_eqExcPID2:\nassumes \\<phi>: \"\\<phi> (Trans s a ou s')\"\nand s: \"step s a = (ou,s')\"\nshows \"eqExcPID2 s s'\"\nusing \\<phi> UUact_uuDec_step_eqExcPID2[OF _ s] unfolding \\<phi>_def2 by blast\n*)\n\n(* major *) lemma eqExcPID2_step:\nassumes s's1': \"eqExcPID2 s s1\"\nand step: \"step s a = (ou,s')\"\nand step1: \"step s1 a = (ou1,s1')\"\nshows \"eqExcPID2 s' s1'\"\nproof -\n  note eqs = eqExcPID2_imp[OF s's1']\n  note eqs' = eqExcPID2_imp1[OF s's1']\n\n  note simps[simp] = c_defs u_defs uu_defs r_defs l_defs Paper_dest_conv eqExcPID2_def eeqExcPID2_def eqExcD2\n\n  show ?thesis\n    using s's1' step step1 eqs eqs'\n    apply(cases a, simp_all only:)\n      subgoal for x1 apply(cases x1)\n        apply auto[] apply auto[] apply auto[] apply auto[]\n        apply auto[] apply auto[] apply auto[] apply auto[] .\n      subgoal for x2 apply(cases x2)\n        apply auto[] apply auto[] apply auto[] apply auto[]\n        apply auto[] apply auto[] apply auto[] .\n      subgoal for x3 apply(cases x3)\n        apply auto[] apply auto[] apply auto[] apply auto[] .\n      apply auto\n  done\nqed\n\nlemma eqExcPID2_step_\\<phi>_imp:\nassumes s's1': \"eqExcPID2 s s1\"\nand step: \"step s a = (ou,s')\" and step1: \"step s1 a = (ou1,s1')\"\nand \\<phi>: \"\\<phi> (Trans s a ou s')\"\nshows \"\\<phi> (Trans s1 a ou1 s1')\"\nusing assms unfolding \\<phi>_def2 by (auto simp add: uu_defs eqExcPID2_imp)\n\nlemma eqExcPID2_step_\\<phi>:\nassumes s's1': \"eqExcPID2 s s1\"\nand step: \"step s a = (ou,s')\" and step1: \"step s1 a = (ou1,s1')\"\nshows \"\\<phi> (Trans s a ou s') = \\<phi> (Trans s1 a ou1 s1')\"\nby (metis eqExcPID2_step_\\<phi>_imp eqExcPID2_sym assms)\n\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/CoCon/Decision_Confidentiality/Decision_Value_Setup2.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5273165233795672, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.26159847342666115}}
{"text": "section \\<open>Final Instantiation of Algorithms Related to Complementation\\<close>\n\ntheory Complementation_Final\nimports\n  \"Complementation_Implement\"\n  \"Formula\"\n  \"Transition_Systems_and_Automata.NBA_Translate\"\n  \"Transition_Systems_and_Automata.NGBA_Algorithms\"\n  \"HOL-Library.Multiset\"\nbegin\n\n  subsection \\<open>Syntax\\<close>\n\n  (* TODO: this syntax has unnecessarily high inner binding strength, requiring extra parentheses\n    the regular let syntax correctly uses inner binding strength 0: (\"(2_ =/ _)\" 10) *)\n  no_syntax \"_do_let\" :: \"[pttrn, 'a] \\<Rightarrow> do_bind\" (\"(2let _ =/ _)\" [1000, 13] 13)\n  syntax \"_do_let\" :: \"[pttrn, 'a] \\<Rightarrow> do_bind\" (\"(2let _ =/ _)\" 13)\n\n  subsection \\<open>Hashcodes on Complement States\\<close>\n\n  definition \"hci k \\<equiv> uint32_of_nat k * 1103515245 + 12345\"\n  definition \"hc \\<equiv> \\<lambda> (p, q, b). hci p + hci q * 31 + (if b then 1 else 0)\"\n  definition \"list_hash xs \\<equiv> fold ((XOR) \\<circ> hc) xs 0\"\n\n  lemma list_hash_eq:\n    assumes \"distinct xs\" \"distinct ys\" \"set xs = set ys\"\n    shows \"list_hash xs = list_hash ys\"\n  proof -\n    have \"mset (remdups xs) = mset (remdups ys)\" using assms(3)\n      using set_eq_iff_mset_remdups_eq by blast \n    then have \"mset xs = mset ys\" using assms(1, 2) by (simp add: distinct_remdups_id)\n    have \"fold ((XOR) \\<circ> hc) xs = fold ((XOR) \\<circ> hc) ys\"\n      apply (rule fold_multiset_equiv)\n       apply (simp_all add: fun_eq_iff ac_simps)\n      using \\<open>mset xs = mset ys\\<close> .\n    then show ?thesis unfolding list_hash_def by simp\n  qed\n\n  definition state_hash :: \"nat \\<Rightarrow> Complementation_Implement.state \\<Rightarrow> nat\" where\n    \"state_hash n p \\<equiv> nat_of_hashcode (list_hash p) mod n\"\n\n  lemma state_hash_bounded_hashcode[autoref_ga_rules]: \"is_bounded_hashcode state_rel\n    (gen_equals (Gen_Map.gen_ball (foldli \\<circ> list_map_to_list)) (list_map_lookup (=))\n    (prod_eq (=) (\\<longleftrightarrow>))) state_hash\"\n  proof\n    show [param]: \"(gen_equals (Gen_Map.gen_ball (foldli \\<circ> list_map_to_list)) (list_map_lookup (=))\n      (prod_eq (=) (\\<longleftrightarrow>)), (=)) \\<in> state_rel \\<rightarrow> state_rel \\<rightarrow> bool_rel\" by autoref\n    show \"state_hash n xs = state_hash n ys\" if \"xs \\<in> Domain state_rel\" \"ys \\<in> Domain state_rel\"\n      \"gen_equals (Gen_Map.gen_ball (foldli \\<circ> list_map_to_list))\n      (list_map_lookup (=)) (prod_eq (=) (=)) xs ys\" for xs ys n\n    proof -\n      have 1: \"distinct (map fst xs)\" \"distinct (map fst ys)\"\n        using that(1, 2) unfolding list_map_rel_def list_map_invar_def by (auto simp: in_br_conv)\n      have 2: \"distinct xs\" \"distinct ys\" using 1 by (auto intro: distinct_mapI)\n      have 3: \"(xs, map_of xs) \\<in> state_rel\" \"(ys, map_of ys) \\<in> state_rel\"\n        using 1 unfolding list_map_rel_def list_map_invar_def by (auto simp: in_br_conv)\n      have 4: \"(gen_equals (Gen_Map.gen_ball (foldli \\<circ> list_map_to_list)) (list_map_lookup (=))\n        (prod_eq (=) (\\<longleftrightarrow>)) xs ys, map_of xs = map_of ys) \\<in> bool_rel\" using 3 by parametricity\n      have 5: \"map_to_set (map_of xs) = map_to_set (map_of ys)\" using that(3) 4 by simp\n      have 6: \"set xs = set ys\" using map_to_set_map_of 1 5 by blast\n      show \"state_hash n xs = state_hash n ys\" unfolding state_hash_def using list_hash_eq 2 6 by metis\n    qed\n    show \"state_hash n x < n\" if \"1 < n\" for n x using that unfolding state_hash_def by simp\n  qed\n\n  subsection \\<open>Complementation\\<close>\n\n  schematic_goal complement_impl:\n    assumes [simp]: \"finite (NBA.nodes A)\"\n    assumes [autoref_rules]: \"(Ai, A) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    shows \"(?f :: ?'c, op_translate (complement_4 A)) \\<in> ?R\"\n    by (autoref_monadic (plain))\n  concrete_definition complement_impl uses complement_impl\n\n  theorem complement_impl_correct:\n    assumes \"finite (NBA.nodes A)\"\n    assumes \"(Ai, A) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    shows \"NBA.language (nbae_nba (nbaei_nbae (complement_impl Ai))) =\n      streams (nba.alphabet A) - NBA.language A\"\n    using op_translate_language[OF complement_impl.refine[OF assms]]\n    using complement_4_correct[OF assms(1)]\n    by simp\n\n  subsection \\<open>Language Subset\\<close>\n\n  definition [simp]: \"op_language_subset A B \\<equiv> NBA.language A \\<subseteq> NBA.language B\"\n\n  lemmas [autoref_op_pat] = op_language_subset_def[symmetric]\n\n  schematic_goal language_subset_impl:\n    assumes [simp]: \"finite (NBA.nodes B)\"\n    assumes [autoref_rules]: \"(Ai, A) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    assumes [autoref_rules]: \"(Bi, B) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    shows \"(?f :: ?'c, do {\n      let AB' = intersect' A (complement_4 B);\n      ASSERT (finite (NGBA.nodes AB'));\n      RETURN (NGBA.language AB' = {})\n    }) \\<in> ?R\"\n\t\tby (autoref_monadic (plain))\n  concrete_definition language_subset_impl uses language_subset_impl\n  lemma language_subset_impl_refine[autoref_rules]:\n    assumes \"SIDE_PRECOND (finite (NBA.nodes A))\"\n    assumes \"SIDE_PRECOND (finite (NBA.nodes B))\"\n    assumes \"SIDE_PRECOND (nba.alphabet A \\<subseteq> nba.alphabet B)\"\n    assumes \"(Ai, A) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    assumes \"(Bi, B) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    shows \"(language_subset_impl Ai Bi, (OP op_language_subset :::\n      \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel \\<rightarrow> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel \\<rightarrow> bool_rel) $ A $ B) \\<in> bool_rel\"\n  proof -\n    have \"(RETURN (language_subset_impl Ai Bi), do {\n      let AB' = intersect' A (complement_4 B);\n      ASSERT (finite (NGBA.nodes AB'));\n      RETURN (NGBA.language AB' = {})\n    }) \\<in> \\<langle>bool_rel\\<rangle> nres_rel\"\n      using language_subset_impl.refine assms(2, 4, 5) unfolding autoref_tag_defs by this\n    also have \"(do {\n      let AB' = intersect' A (complement_4 B);\n      ASSERT (finite (NGBA.nodes AB'));\n      RETURN (NGBA.language AB' = {})\n    }, RETURN (NBA.language A \\<subseteq> NBA.language B)) \\<in> \\<langle>bool_rel\\<rangle> nres_rel\"\n    proof refine_vcg\n      show \"finite (NGBA.nodes (intersect' A (complement_4 B)))\" using assms(1, 2) by auto\n      have 1: \"NBA.language A \\<subseteq> streams (nba.alphabet B)\"\n        using nba.language_alphabet streams_mono2 assms(3) unfolding autoref_tag_defs by blast\n      have 2: \"NBA.language (complement_4 B) = streams (nba.alphabet B) - NBA.language B\"\n        using complement_4_correct assms(2) by auto\n      show \"(NGBA.language (intersect' A (complement_4 B)) = {},\n        NBA.language A \\<subseteq> NBA.language B) \\<in> bool_rel\" using 1 2 by auto\n    qed\n    finally show ?thesis using RETURN_nres_relD unfolding nres_rel_comp by force\n  qed\n\n  subsection \\<open>Language Equality\\<close>\n\n  definition [simp]: \"op_language_equal A B \\<equiv> NBA.language A = NBA.language B\"\n\n  lemmas [autoref_op_pat] = op_language_equal_def[symmetric]\n\n  schematic_goal language_equal_impl:\n    assumes [simp]: \"finite (NBA.nodes A)\"\n    assumes [simp]: \"finite (NBA.nodes B)\"\n    assumes [simp]: \"nba.alphabet A = nba.alphabet B\"\n    assumes [autoref_rules]: \"(Ai, A) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    assumes [autoref_rules]: \"(Bi, B) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    shows \"(?f :: ?'c, NBA.language A \\<subseteq> NBA.language B \\<and> NBA.language B \\<subseteq> NBA.language A) \\<in> ?R\"\n    by autoref\n  concrete_definition language_equal_impl uses language_equal_impl\n  lemma language_equal_impl_refine[autoref_rules]:\n    assumes \"SIDE_PRECOND (finite (NBA.nodes A))\"\n    assumes \"SIDE_PRECOND (finite (NBA.nodes B))\"\n    assumes \"SIDE_PRECOND (nba.alphabet A = nba.alphabet B)\"\n    assumes \"(Ai, A) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    assumes \"(Bi, B) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    shows \"(language_equal_impl Ai Bi, (OP op_language_equal :::\n      \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel \\<rightarrow> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel \\<rightarrow> bool_rel) $ A $ B) \\<in> bool_rel\"\n    using language_equal_impl.refine[OF assms[unfolded autoref_tag_defs]] by auto\n\n  schematic_goal product_impl:\n    assumes [simp]: \"finite (NBA.nodes B)\"\n    assumes [autoref_rules]: \"(Ai, A) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    assumes [autoref_rules]: \"(Bi, B) \\<in> \\<langle>Id, nat_rel\\<rangle> nbai_nba_rel\"\n    shows \"(?f :: ?'c, do {\n      let AB' = intersect A (complement_4 B);\n      ASSERT (finite (NBA.nodes AB'));\n      op_translate AB'\n    }) \\<in> ?R\"\n\t\tby (autoref_monadic (plain))\n  concrete_definition product_impl uses product_impl\n\n  (* TODO: possible optimizations:\n    - introduce op_map_map operation for maps instead of manually iterating via FOREACH\n    - consolidate various binds and maps in expand_map_get_7 *)\n  export_code\n    Set.empty Set.insert Set.member\n    \"Inf :: 'a set set \\<Rightarrow> 'a set\" \"Sup :: 'a set set \\<Rightarrow> 'a set\" image Pow set\n    nat_of_integer integer_of_nat\n    Variable Negation Conjunction Disjunction satisfies map_formula\n    nbaei alphabetei initialei transitionei acceptingei\n    nbae_nba_impl complement_impl language_equal_impl product_impl\n    in SML module_name Complementation file_prefix Complementation\n\nend", "meta": {"author": "zabihullah331", "repo": "barakzai", "sha": "793257c1d71ec75a299fc6b5843af756ead2afb0", "save_path": "github-repos/isabelle/zabihullah331-barakzai", "path": "github-repos/isabelle/zabihullah331-barakzai/barakzai-793257c1d71ec75a299fc6b5843af756ead2afb0/thys/Buchi_Complementation/Complementation_Final.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.2615984734266611}}
{"text": "(*    Title:              SatSolverVerification/Decide.thy\n      Author:             Filip Maric\n      Maintainer:         Filip Maric <filip at matf.bg.ac.yu>\n*)\n\ntheory Decide\nimports AssertLiteral\nbegin\n\n(******************************************************************************)\n(*          A P P L Y     D E C I D E                                         *)\n(******************************************************************************)   \n\nlemma applyDecideEffect:\nassumes \n  \"\\<not> vars(elements (getM state)) \\<supseteq> Vbl\" and\n  \"InvariantWatchesEl (getF state) (getWatch1 state) (getWatch2 state)\" and \n  \"InvariantWatchListsContainOnlyClausesFromF (getWatchList state) (getF state)\"\nshows \n  \"let literal = selectLiteral state Vbl in \n   let state' = applyDecide state Vbl in \n          var literal \\<notin> vars (elements (getM state)) \\<and> \n          var literal \\<in> Vbl \\<and> \n          getM state' = getM state @ [(literal, True)] \\<and> \n          getF state' = getF state\"\nusing assms\nusing selectLiteral_def[of \"Vbl\" \"state\"]\nunfolding applyDecide_def\nusing assertLiteralEffect[of \"state\" \"selectLiteral state Vbl\" \"True\"]\nby (simp add: Let_def)\n\nlemma InvariantConsistentAfterApplyDecide:\nassumes \n  \"\\<not> vars(elements (getM state)) \\<supseteq> Vbl\" and\n  \"InvariantConsistent (getM state)\" and\n  \"InvariantWatchesEl (getF state) (getWatch1 state) (getWatch2 state)\" and \n  \"InvariantWatchListsContainOnlyClausesFromF (getWatchList state) (getF state)\"\nshows\n  \"let state' = applyDecide state Vbl in\n         InvariantConsistent (getM state')\"\nusing assms\nusing applyDecideEffect[of \"Vbl\" \"state\"]\nusing InvariantConsistentAfterDecide[of \"getM state\" \"selectLiteral state Vbl\" \"getM (applyDecide state Vbl)\"]\nby (simp add: Let_def)\n\n\nlemma InvariantUniqAfterApplyDecide:\nassumes \n  \"\\<not> vars(elements (getM state)) \\<supseteq> Vbl\" and\n  \"InvariantUniq (getM state)\" and\n  \"InvariantWatchesEl (getF state) (getWatch1 state) (getWatch2 state)\" and \n  \"InvariantWatchListsContainOnlyClausesFromF (getWatchList state) (getF state)\"\nshows\n  \"let state' = applyDecide state Vbl in\n         InvariantUniq (getM state')\"\nusing assms\nusing applyDecideEffect[of \"Vbl\" \"state\"]\nusing InvariantUniqAfterDecide[of \"getM state\" \"selectLiteral state Vbl\" \"getM (applyDecide state Vbl)\"]\nby (simp add: Let_def)\n\nlemma InvariantQCharacterizationAfterApplyDecide:\nassumes \n  \"\\<not> vars(elements (getM state)) \\<supseteq> Vbl\" and\n\n  \"InvariantConsistent (getM state)\" and\n  \"InvariantWatchListsContainOnlyClausesFromF (getWatchList state) (getF state)\"\n  \"InvariantWatchListsUniq (getWatchList state)\"\n  \"InvariantWatchListsCharacterization (getWatchList state) (getWatch1 state) (getWatch2 state)\"\n  \"InvariantWatchesEl (getF state) (getWatch1 state) (getWatch2 state)\"\n  \"InvariantWatchesDiffer (getF state) (getWatch1 state) (getWatch2 state)\"\n  \"InvariantWatchCharacterization (getF state) (getWatch1 state) (getWatch2 state) (getM state)\"\n  \"InvariantConflictFlagCharacterization (getConflictFlag state) (getF state) (getM state)\"\n  \"InvariantQCharacterization (getConflictFlag state) (getQ state) (getF state) (getM state)\"\n\n  \"getQ state = []\"\nshows\n  \"let state' = applyDecide state Vbl in\n     InvariantQCharacterization (getConflictFlag state') (getQ state') (getF state') (getM state')\"\nproof-\n  let ?state' = \"applyDecide state Vbl\"\n  let ?literal = \"selectLiteral state Vbl\"\n  have \"getM ?state' = getM state @ [(?literal, True)]\"\n    using assms\n    using applyDecideEffect[of \"Vbl\" \"state\"]\n    by (simp add: Let_def)\n  hence \"InvariantConsistent (getM state @ [(?literal, True)])\"\n    using InvariantConsistentAfterApplyDecide[of \"Vbl\" \"state\"]\n    using assms\n    by (simp add: Let_def)\n  thus ?thesis\n    using assms\n    using InvariantQCharacterizationAfterAssertLiteralNotInQ[of \"state\" \"?literal\" \"True\"]\n    unfolding applyDecide_def\n    by simp\nqed\n\nlemma InvariantEquivalentZLAfterApplyDecide:\nassumes\n  \"InvariantWatchListsContainOnlyClausesFromF (getWatchList state) (getF state)\"\n  \"InvariantWatchesEl (getF state) (getWatch1 state) (getWatch2 state)\"\n  \"InvariantEquivalentZL (getF state) (getM state) F0\"\nshows\n  \"let state' = applyDecide state Vbl in\n     InvariantEquivalentZL (getF state') (getM state') F0\"\nproof-\n  let ?state' = \"applyDecide state Vbl\"\n  let ?l = \"selectLiteral state Vbl\"\n\n  have \"getM ?state' = getM state @ [(?l, True)]\"\n    \"getF ?state' = getF state\"\n    unfolding applyDecide_def\n    using assertLiteralEffect[of \"state\" \"?l\" \"True\"]\n    using assms\n    by (auto simp only: Let_def)\n  have \"prefixToLevel 0 (getM ?state') = prefixToLevel 0 (getM state)\"\n  proof (cases \"currentLevel (getM state) > 0\")\n    case True\n    thus ?thesis\n      using prefixToLevelAppend[of \"0\" \"getM state\" \"[(?l, True)]\"]\n      using \\<open>getM ?state' = getM state @ [(?l, True)]\\<close>\n      by auto\n  next\n    case False\n    hence \"prefixToLevel 0 (getM state @ [(?l, True)]) = \n             getM state @ (prefixToLevel_aux [(?l, True)] 0 (currentLevel (getM state)))\"\n      using prefixToLevelAppend[of \"0\" \"getM state\" \"[(?l, True)]\"]\n      by simp\n    hence \"prefixToLevel 0 (getM state @ [(?l, True)]) = getM state\"\n      by simp\n    thus ?thesis\n      using \\<open>getM ?state' = getM state @ [(?l, True)]\\<close>\n      using currentLevelZeroTrailEqualsItsPrefixToLevelZero[of \"getM state\"]\n      using False\n      by simp\n  qed\n  thus ?thesis\n    using \\<open>InvariantEquivalentZL (getF state) (getM state) F0\\<close>\n    unfolding InvariantEquivalentZL_def\n    using \\<open>getF ?state' = getF state\\<close>\n    by simp\nqed\n\n\nlemma InvariantGetReasonIsReasonAfterApplyDecide:\nassumes\n  \"\\<not> vars (elements (getM state)) \\<supseteq> Vbl\"\n  \"InvariantWatchListsContainOnlyClausesFromF (getWatchList state) (getF state)\"\n  \"InvariantWatchListsCharacterization (getWatchList state) (getWatch1 state) (getWatch2 state)\" and\n  \"InvariantWatchListsUniq (getWatchList state)\"\n  \"InvariantWatchesEl (getF state) (getWatch1 state) (getWatch2 state)\"\n  \"InvariantGetReasonIsReason (getReason state) (getF state) (getM state) (set (getQ state))\"\n  \"getQ state = []\"\nshows\n  \"let state' = applyDecide state Vbl in \n    InvariantGetReasonIsReason (getReason state') (getF state') (getM state') (set (getQ state'))\"\nproof-\n  let ?l = \"selectLiteral state Vbl\"\n  let ?stateM = \"state \\<lparr> getM := getM state @ [(?l, True)] \\<rparr>\"\n  have \"InvariantGetReasonIsReason (getReason ?stateM) (getF ?stateM) (getM ?stateM) (set (getQ ?stateM))\"\n  proof-\n    {\n      fix l::Literal\n      assume *: \"l el (elements (getM ?stateM))\" \"\\<not> l el (decisions (getM ?stateM))\" \"elementLevel l (getM ?stateM) > 0\"\n      have \"\\<exists> reason. getReason ?stateM l = Some reason \\<and>\n        0 \\<le> reason \\<and> reason < length (getF ?stateM) \\<and>\n        isReason (getF ?stateM ! reason) l (elements (getM ?stateM))\"\n      proof (cases \"l el (elements (getM state))\")\n        case True\n        moreover\n        hence \"\\<not> l el (decisions (getM state))\"\n          using *\n          by (simp add: markedElementsAppend)\n        moreover\n        have \"elementLevel l (getM state) > 0\"\n        proof-\n          {\n            assume \"\\<not> ?thesis\"\n            with *\n            have \"l = ?l\"\n              using True\n              using elementLevelAppend[of \"l\" \"getM state\" \"[(?l, True)]\"]\n              by simp\n            hence \"var ?l \\<in> vars (elements (getM state))\"\n              using True\n              using valuationContainsItsLiteralsVariable[of \"l\" \"elements (getM state)\"]\n              by simp\n            hence False\n              using \\<open>\\<not> vars (elements (getM state)) \\<supseteq> Vbl\\<close>\n              using selectLiteral_def[of \"Vbl\" \"state\"]\n              by auto\n          } thus ?thesis\n            by auto\n        qed\n        ultimately\n        obtain reason\n          where \"getReason state l = Some reason \\<and>\n          0 \\<le> reason \\<and> reason < length (getF state) \\<and>\n          isReason (getF state ! reason) l (elements (getM state))\"\n          using \\<open>InvariantGetReasonIsReason (getReason state) (getF state) (getM state) (set (getQ state))\\<close>\n          unfolding InvariantGetReasonIsReason_def\n          by auto\n        thus ?thesis\n          using isReasonAppend[of \"nth (getF ?stateM) reason\" \"l\" \"elements (getM state)\" \"[?l]\"]\n          by auto\n      next\n        case False\n        hence \"l = ?l\"\n          using *\n          by auto\n        hence \"l el (decisions (getM ?stateM))\"\n          using markedElementIsMarkedTrue[of \"l\" \"getM ?stateM\"]\n          by auto\n        with *\n        have False\n          by auto\n        thus ?thesis\n          by simp\n      qed\n    }\n    thus ?thesis\n      using \\<open>getQ state = []\\<close>\n      unfolding InvariantGetReasonIsReason_def\n      by auto\n  qed\n  thus ?thesis\n    using assms\n    using InvariantGetReasonIsReasonAfterNotifyWatches[of \"?stateM\" \"getWatchList ?stateM (opposite ?l)\"\n      \"opposite ?l\" \"getM state\" \"True\" \"{}\" \"[]\"]\n    unfolding applyDecide_def\n    unfolding assertLiteral_def\n    unfolding notifyWatches_def\n    unfolding InvariantWatchListsCharacterization_def\n    unfolding InvariantWatchListsContainOnlyClausesFromF_def\n    unfolding InvariantWatchListsUniq_def\n    using \\<open>getQ state = []\\<close>\n    by (simp add: Let_def)\nqed\n\nlemma InvariantsVarsAfterApplyDecide:\nassumes\n  \"\\<not> vars (elements (getM state)) \\<supseteq> Vbl\"\n  \"InvariantConsistent (getM state)\"\n  \"InvariantUniq (getM state)\"\n  \"InvariantWatchListsContainOnlyClausesFromF (getWatchList state) (getF state)\"\n  \"InvariantWatchListsUniq (getWatchList state)\"\n  \"InvariantWatchListsCharacterization (getWatchList state) (getWatch1 state) (getWatch2 state)\"\n  \"InvariantWatchesEl (getF state) (getWatch1 state) (getWatch2 state)\"\n  \"InvariantWatchesDiffer (getF state) (getWatch1 state) (getWatch2 state)\"\n  \"InvariantWatchCharacterization (getF state) (getWatch1 state) (getWatch2 state) (getM state)\"\n\n  \"InvariantVarsM (getM state) F0 Vbl\"\n  \"InvariantVarsF (getF state) F0 Vbl\"\n  \"getQ state = []\"\nshows\n  \"let state' = applyDecide state Vbl in \n     InvariantVarsM (getM state') F0 Vbl \\<and> \n     InvariantVarsF (getF state') F0 Vbl \\<and> \n     InvariantVarsQ (getQ state') F0 Vbl\"\nproof-\n  let ?state' = \"applyDecide state Vbl\"\n  let ?l = \"selectLiteral state Vbl\"\n\n  have \"InvariantVarsM (getM ?state') F0 Vbl\" \"InvariantVarsF (getF ?state') F0 Vbl\"\n    using assms\n    using applyDecideEffect[of \"Vbl\" \"state\"]\n    using varsAppendValuation[of \"elements (getM state)\" \"[?l]\"]\n    unfolding InvariantVarsM_def\n    by (auto simp add: Let_def)\n  moreover\n  have \"InvariantVarsQ (getQ ?state') F0 Vbl\"\n    using InvariantVarsQAfterAssertLiteral[of \"state\" \"?l\" \"True\" \"F0\" \"Vbl\"]\n    using assms\n    using InvariantConsistentAfterApplyDecide[of \"Vbl\" \"state\"]\n    using InvariantUniqAfterApplyDecide[of \"Vbl\" \"state\"]\n    using assertLiteralEffect[of \"state\" \"?l\" \"True\"]\n    unfolding applyDecide_def\n    unfolding InvariantVarsQ_def\n    by (simp add: Let_def)\n  ultimately\n  show ?thesis\n    by (simp add: Let_def)\nqed\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/SATSolverVerification/Decide.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.2615984734266611}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory PackedTypes\nimports \"../lib/WordSetup\" CProof\nbegin\n\nsection {* Underlying definitions for the class axioms *}\n\ntext {* field_access / field_update is the identity for packed types *}\n\ndefinition\n  \"fa_fu_idem fd n \\<equiv>\n  \\<forall>bs bs' v. length bs = n \\<longrightarrow> length bs' = n \\<longrightarrow> field_access fd (field_update fd bs v) bs' = bs\"\n\n(* Is it better to do this or to use a fold over td?  This seems easier to use *)\nprimrec\n  td_fafu_idem :: \"'a field_desc typ_desc \\<Rightarrow> bool\" and\n  td_fafu_idem_struct :: \"'a field_desc typ_struct \\<Rightarrow> bool\" and\n  td_fafu_idem_list :: \" ('a field_desc typ_desc, char list) dt_pair list \\<Rightarrow> bool\" and\n  td_fafu_idem_pair :: \"('a field_desc typ_desc, char list) dt_pair \\<Rightarrow> bool\"\nwhere\n  fai0: \"td_fafu_idem (TypDesc ts n) = td_fafu_idem_struct ts\"\n\n| fai1: \"td_fafu_idem_struct (TypScalar n algn d) = fa_fu_idem d n\"\n| fai2: \"td_fafu_idem_struct (TypAggregate ts) = td_fafu_idem_list ts\"\n\n| fai3: \"td_fafu_idem_list [] = True\"\n| fai4: \"td_fafu_idem_list (x#xs) = (td_fafu_idem_pair x \\<and> td_fafu_idem_list xs)\"\n\n| fai5: \"td_fafu_idem_pair (DTPair x n) = td_fafu_idem x\"\n\nlemmas td_fafu_idem_simps = fai0 fai1 fai2 fai3 fai4 fai5\n\ntext {* field_access is independent of the underlying bytes *}\n\ndefinition\n  \"fa_heap_indep fd n \\<equiv>\n  \\<forall>bs bs' v. length bs = n \\<longrightarrow> length bs' = n \\<longrightarrow> field_access fd v bs = field_access fd v bs'\"\n\n\nprimrec\n  td_fa_hi :: \"'a field_desc typ_desc \\<Rightarrow> bool\" and\n  td_fa_hi_struct :: \"'a field_desc typ_struct \\<Rightarrow> bool\" and\n  td_fa_hi_list :: \"('a field_desc typ_desc, char list) dt_pair list \\<Rightarrow> bool\" and\n  td_fa_hi_pair :: \"('a field_desc typ_desc, char list) dt_pair \\<Rightarrow> bool\"\nwhere\n  fahi0: \"td_fa_hi (TypDesc ts n) = td_fa_hi_struct ts\"\n\n| fahi1: \"td_fa_hi_struct (TypScalar n algn d) = fa_heap_indep d n\"\n| fahi2: \"td_fa_hi_struct (TypAggregate ts) = td_fa_hi_list ts\"\n\n| fahi3: \"td_fa_hi_list [] = True\"\n| fahi4: \"td_fa_hi_list (x#xs) = (td_fa_hi_pair x \\<and> td_fa_hi_list xs)\"\n\n| fahi5: \"td_fa_hi_pair (DTPair x n) = td_fa_hi x\"\n\nlemmas td_fa_hi_simps = fahi0 fahi1 fahi2 fahi3 fahi4 fahi5\n\nsection {* Lemmas about td_fafu_idem *}\n\nlemma field_lookup_td_fafu_idem:\n  shows \"\\<And>(s :: 'a field_desc typ_desc) f m n. \\<lbrakk> field_lookup t f m = Some (s, n); td_fafu_idem t \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  and   \"\\<And>(s :: 'a field_desc typ_desc) f m n. \\<lbrakk> field_lookup_struct st f m = Some (s, n); td_fafu_idem_struct st \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  and   \"\\<And>(s :: 'a field_desc typ_desc) f m n. \\<lbrakk> field_lookup_list ts f m = Some (s, n); td_fafu_idem_list ts \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  and   \"\\<And>(s :: 'a field_desc typ_desc) f m n. \\<lbrakk> field_lookup_pair p f m = Some (s, n); td_fafu_idem_pair p \\<rbrakk> \\<Longrightarrow> td_fafu_idem s\"\n  by (induct t and st and ts and p) (auto split: split_if_asm option.splits)\n\nlemma field_access_update_same:\n  fixes t :: \"'a :: mem_type field_desc typ_desc\" and st :: \"'a field_desc typ_struct\"\n  shows \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem t; wf_fd t; length bs = size_td t; length bs' = size_td t\\<rbrakk>\n  \\<Longrightarrow> access_ti t (update_ti t bs v) bs' = bs\"\n  and \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem_struct st; wf_fd_struct st; length bs = size_td_struct st; length bs' = size_td_struct st \\<rbrakk>\n  \\<Longrightarrow> access_ti_struct st (update_ti_struct st bs v) bs' = bs\"\n  and \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem_list ts; wf_fd_list ts; length bs = size_td_list ts; length bs' = size_td_list ts\\<rbrakk>\n  \\<Longrightarrow> access_ti_list ts (update_ti_list ts bs v) bs' = bs\"\n  and \"\\<And>(v :: 'a) bs bs'. \\<lbrakk> td_fafu_idem_pair p; wf_fd_pair p; length bs = size_td_pair p; length bs' = size_td_pair p\\<rbrakk>\n  \\<Longrightarrow> access_ti_pair p (update_ti_pair p bs v) bs' = bs\"\nproof (induct t and st and ts and p)\n  case TypScalar thus ?case by (clarsimp simp: fa_fu_idem_def)\nnext\n  case (Cons_typ_desc p' ts' v bs bs')\n  hence \"fu_commutes (update_ti_pair_t p') (update_ti_list_t ts')\" by clarsimp\n  moreover have \"update_ti_pair p' (take (size_td_pair p') bs) = update_ti_pair_t p' (take (size_td_pair p') bs)\"\n    using Cons_typ_desc.prems by (simp add: update_ti_pair_t_def min_ll)\n  moreover have \"update_ti_list ts' (drop (size_td_pair p') bs) = update_ti_list_t ts' (drop (size_td_pair p') bs)\"\n    using Cons_typ_desc.prems by (simp add: update_ti_list_t_def)\n  ultimately have\n    updeq: \"(update_ti_pair p' (take (size_td_pair p') bs) (update_ti_list ts' (drop (size_td_pair p') bs) v))\n    = (update_ti_list ts' (drop (size_td_pair p') bs) (update_ti_pair p' (take (size_td_pair p') bs) v))\"\n    unfolding fu_commutes_def by simp\n\n  show ?case using Cons_typ_desc.prems\n    by (clarsimp simp add: Cons_typ_desc.hyps) (simp add: updeq  Cons_typ_desc.hyps)\nqed simp+\n\nlemma access_ti_pair_dt_fst:\n  \"access_ti_pair p v bs = access_ti (dt_fst p) v bs\"\n  by (cases p, simp)\n\nlemma size_td_pair_dt_fst:\n  \"size_td_pair p = size_td (dt_fst p)\"\n  by (cases p, simp)\n\nlemma wf_fd_pair_dt_fst:\n  \"wf_fd_pair p = wf_fd (dt_fst p)\"\n  by (cases p, simp)\n\nlemma field_lookup_offset2:\n  assumes fl: \"(field_lookup t f (m + n) = Some (s, q))\"\n  shows   \"field_lookup t f m = Some (s, q - n)\"\nproof -\n  from fl have le: \"m + n \\<le> q\"\n    by (rule field_lookup_offset_le)\n\n  hence \"q = (m + n) + (q - (m + n))\"\n    by simp\n\n  hence \"field_lookup t f (m + n) = Some (s, (m + n) + (q - (m + n)))\" using fl by simp\n\n  hence \"field_lookup t f m = Some (s, m + (q - (m + n)))\"\n    by (rule iffD1 [OF field_lookup_offset'(1)])\n\n  thus ?thesis using le by simp\nqed\n\nlemma field_lookup_offset2_list:\n  assumes fl: \"(field_lookup_list ts f (m + n) = Some (s, q))\"\n  shows   \"field_lookup_list ts f m = Some (s, q - n)\"\nproof -\n  from fl have le: \"m + n \\<le> q\"\n    by (rule field_lookup_offset_le)\n\n  hence \"q = (m + n) + (q - (m + n))\"\n    by simp\n\n  hence \"field_lookup_list ts f (m + n) = Some (s, (m + n) + (q - (m + n)))\" using fl by simp\n\n  hence \"field_lookup_list ts f m = Some (s, m + (q - (m + n)))\"\n    by (rule iffD1 [OF field_lookup_offset'(3)])\n\n  thus ?thesis using le by simp\nqed\n\nlemma field_lookup_offset2_pair:\n  assumes fl: \"(field_lookup_pair p f (m + n) = Some (s, q))\"\n  shows   \"field_lookup_pair p f m = Some (s, q - n)\"\nproof -\n  from fl have le: \"m + n \\<le> q\"\n    by (rule field_lookup_offset_le)\n\n  hence \"q = (m + n) + (q - (m + n))\"\n    by simp\n\n  hence \"field_lookup_pair p f (m + n) = Some (s, (m + n) + (q - (m + n)))\" using fl by simp\n\n  hence \"field_lookup_pair p f m = Some (s, m + (q - (m + n)))\"\n    by (rule iffD1 [OF field_lookup_offset'(4)])\n\n  thus ?thesis using le by simp\nqed\n\nlemma field_lookup_offset_size':\n  shows \"field_lookup t f 0 = Some (t',n) \\<Longrightarrow> size_td t' + n \\<le> size_td t\"\n  apply(drule td_set_field_lookupD)\n  apply(erule td_set_offset_size)\ndone\n\nlemma field_access_update_nth_inner:\n  shows \"\\<And>f (s :: 'a :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk> field_lookup t f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd t;\n  length bs = size_td s; length bs' = size_td t \\<rbrakk>\n  \\<Longrightarrow> access_ti t (update_ti s bs v) bs' ! x = bs ! (x - n)\"\n\n  and \"\\<And>f (s :: 'a  :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk>field_lookup_struct st f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd_struct st;\n  length bs = size_td s; length bs' = size_td_struct st \\<rbrakk>\n  \\<Longrightarrow> access_ti_struct st (update_ti s bs v) bs' ! x = bs ! (x - n)\"\n\n  and \"\\<And>f (s :: 'a  :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk>field_lookup_list ts f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd_list ts;\n  length bs = size_td s; length bs' = size_td_list ts\\<rbrakk>\n  \\<Longrightarrow> access_ti_list ts (update_ti s bs v) bs' ! x = bs ! (x - n)\"\n\n  and \"\\<And>f (s :: 'a  :: mem_type field_desc typ_desc) n x v bs bs'.\n  \\<lbrakk>field_lookup_pair p f 0 = Some (s, n); n \\<le> x; x < n + size_td s; td_fafu_idem s; wf_fd s; wf_fd_pair p;\n  length bs = size_td s; length bs' = size_td_pair p\\<rbrakk>\n  \\<Longrightarrow> access_ti_pair p (update_ti s bs v) bs' ! x = bs ! (x - n)\"\nproof (induct t and st and ts and p)\n  case (TypDesc typ_struct ls f s n x v bs bs')\n\n  show ?case\n  proof (cases \"f = []\")\n    case False thus ?thesis using TypDesc by clarsimp\n  next\n    case True\n    thus ?thesis using TypDesc.prems\n      by (simp add: field_access_update_same)\n  qed\nnext\n  case (Cons_typ_desc p' ts' f s n x v bs bs')\n  have nlex: \"n \\<le> x\" and xln: \"x < n + size_td s\"\n    and lbs: \"length bs = size_td s\" and lbs': \"length bs' = size_td_list (p' # ts')\" by fact+\n  from Cons_typ_desc have wf: \"wf_fd (dt_fst p')\" and wfts: \"wf_fd_list ts'\" by (cases p', auto)\n\n  {\n    assume fl: \"field_lookup_list ts' f (size_td (dt_fst p')) = Some (s, n)\"\n\n    hence mlt: \"size_td (dt_fst p') \\<le> n\"\n      by (rule field_lookup_offset_le)\n\n    hence \"size_td (dt_fst p') \\<le> x\"\n      by (rule order_trans) fact\n\n    hence ?case using wf lbs lbs'\n    proof (simp add: nth_append length_fa_ti access_ti_pair_dt_fst size_td_pair_dt_fst)\n      from fl have fl': \"field_lookup_list ts' f 0 = Some (s, n - size_td (dt_fst p'))\"\n\tby (rule field_lookup_offset2_list [where m = 0, simplified])\n\n      show \"access_ti_list ts' (update_ti s bs v) (drop (size_td (dt_fst p')) bs') ! (x - size_td (dt_fst p')) = bs ! (x - n)\"\n\tusing mlt nlex xln lbs lbs' wf wfts `td_fafu_idem s` `wf_fd s`\n\tby (simp add: Cons_typ_desc.hyps(2) [OF fl'] size_td_pair_dt_fst)\n    qed\n  }\n  moreover\n  {\n    note ih = Cons_typ_desc.hyps(1)[simplified access_ti_pair_dt_fst wf_fd_pair_dt_fst]\n\n    assume fl: \"field_lookup_pair p' f 0 = Some (s, n)\"\n\n    hence \"x < size_td (dt_fst p')\"\n      apply -\n      apply (cases p')\n      apply (simp split: split_if_asm)\n      apply (drule field_lookup_offset_size')\n      apply (rule order_less_le_trans [OF xln])\n      apply simp\n      done\n\n    hence ?case using wf lbs lbs' nlex xln wf wfts `td_fafu_idem s` `wf_fd s`\n      by (simp add: nth_append length_fa_ti access_ti_pair_dt_fst size_td_pair_dt_fst ih[OF fl])\n  }\n  ultimately show ?case using `field_lookup_list (p' # ts') f 0 = Some (s, n)` by (simp split: option.splits)\nqed (clarsimp split: split_if_asm)+\n\nsubsection {* td_fa_hi *}\n\n(* \\<lbrakk> size_of TYPE('a::mem_type) \\<le> length h; size_of TYPE('a) \\<le> length h' \\<rbrakk> \\<Longrightarrow> *)\n\nlemma fa_heap_indepD:\n  \"\\<lbrakk> fa_heap_indep fd n; length bs = n; length bs' = n \\<rbrakk> \\<Longrightarrow>\n  field_access fd v bs = field_access fd v bs'\"\n  unfolding fa_heap_indep_def\n  apply (drule spec, drule spec, drule spec)\n  apply (drule (1) mp)\n  apply (erule (1) mp)\n  done\n\n(* The simplifier spins on the IHs here, hence the proofs for each case *)\nlemma td_fa_hi_heap_independence:\n  shows \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi t; length h = size_td t; length h' = size_td t \\<rbrakk>\n  \\<Longrightarrow> access_ti t v h = access_ti t v h'\"\n  and   \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi_struct st; length h = size_td_struct st; length h' = size_td_struct st\\<rbrakk>\n  \\<Longrightarrow> access_ti_struct st v h = access_ti_struct st v h'\"\n  and   \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi_list ts;  length h = size_td_list ts; length h' = size_td_list ts \\<rbrakk>\n  \\<Longrightarrow> access_ti_list ts v h = access_ti_list ts v h'\"\n  and   \"\\<And>(v :: 'a :: mem_type) h h'. \\<lbrakk> td_fa_hi_pair p;  length h = size_td_pair p; length h' = size_td_pair p \\<rbrakk>\n  \\<Longrightarrow> access_ti_pair p v h = access_ti_pair p v h'\"\nproof (induct t and st and ts and p)\n  case TypDesc\n  from TypDesc.prems show ?case\n    by (simp) (erule (2) TypDesc.hyps)\nnext\n  case TypScalar\n  from TypScalar.prems show ?case\n    by simp (erule (2) fa_heap_indepD)\nnext\n  case TypAggregate\n  from TypAggregate.prems show ?case\n    by (simp) (erule (2) TypAggregate.hyps)\nnext\n  case Nil_typ_desc thus ?case by simp\nnext\n  case Cons_typ_desc\n  from Cons_typ_desc.prems show ?case\n    apply simp\n    apply (erule conjE)\n    apply (rule arg_cong2 [where f = \"op @\"])\n    apply (erule Cons_typ_desc.hyps, simp, simp)\n    apply (erule Cons_typ_desc.hyps, simp, simp)\n    done\nnext\n  case DTPair_typ_desc\n  from DTPair_typ_desc.prems show ?case\n    by simp (erule (2) DTPair_typ_desc.hyps)\nqed\n\nsection {* Simp rules for deriving packed props from the type combinators *}\n\nsubsection {* td_fafu_idem *}\n\nlemma td_fafu_idem_final_pad:\n  \"padup (2 ^ align_td t) (size_td t) = 0\n  \\<Longrightarrow> td_fafu_idem (final_pad t) = td_fafu_idem t\"\n  unfolding final_pad_def\n  by (clarsimp simp add: padup_def Let_def)\n\nlemma td_fafu_idem_ti_typ_pad_combine:\n  fixes t :: \"'a :: c_type itself\" and s :: \"'b :: c_type field_desc typ_desc\"\n  assumes pad: \"padup (align_of TYPE('a)) (size_td s) = 0\"\n  shows \"td_fafu_idem (ti_typ_pad_combine t xf xfu nm s) = td_fafu_idem (ti_typ_combine t xf xfu nm s)\"\n  unfolding ti_typ_pad_combine_def using pad\n  by (clarsimp simp: Let_def)\n\nlemma td_fafu_idem_list_append:\n  fixes xs :: \"'a :: c_type field_desc typ_pair list\"\n  shows \"td_fafu_idem_list (xs @ ys) = (td_fafu_idem_list xs \\<and> td_fafu_idem_list ys)\"\n  by (induct xs) simp+\n\nlemma td_fafu_idem_extend_ti:\n  fixes t :: \"'a :: c_type field_desc typ_desc\"\n  assumes as: \"td_fafu_idem s\"\n  and     at: \"td_fafu_idem t\"\n  shows \"td_fafu_idem (extend_ti s t nm)\" using as at\n  apply (cases s)\n  apply (rename_tac typ_struct xs)\n  apply (case_tac typ_struct)\n   apply simp\n  apply (simp add: td_fafu_idem_list_append)\n  done\n\nlemma fd_cons_access_updateD:\n  \"\\<lbrakk> fd_cons_access_update d n; length bs = n; length bs' = n\\<rbrakk> \\<Longrightarrow> field_access d (field_update d bs v) bs' = field_access d (field_update d bs v') bs'\"\n  unfolding fd_cons_access_update_def by clarsimp\n\n(* Beer crime? *)\nlemma fa_fu_idem_update_desc:\n  fixes a :: \"'a field_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and     fd: \"fd_cons_struct (TypScalar n n' a)\"\n  shows   \"fa_fu_idem (update_desc xf xfu a) n = fa_fu_idem a n\"\nproof\n  assume asm: \"fa_fu_idem (update_desc xf xfu a) n\"\n\n  let ?fu = \"\\<lambda>bs. if length bs = n then field_update a bs else id\"\n  let ?a' = \"\\<lparr> field_access = field_access a, field_update = ?fu \\<rparr>\"\n\n  show \"fa_fu_idem a n\"\n    unfolding fa_fu_idem_def\n  proof (intro impI conjI allI)\n    fix bs :: \"byte list\" and bs' :: \"byte list\" and v\n    assume l: \"length bs = n\" and l': \"length bs' = n\"\n\n    hence \"(\\<forall>v. field_access a (field_update a bs (xf v)) bs' = bs)\n      = (\\<forall>v. field_access a (?fu bs (xf v)) bs' = bs)\" by simp\n\n    also have \"\\<dots> = (\\<forall>v. field_access a (field_update a bs v) bs' = bs)\" using fd\n      apply -\n      apply rule\n      apply (rule allI)\n      apply (subst (asm) fd_cons_access_updateD [OF _ l l', where d = ?a', simplified])\n      apply (simp add: fd_cons_struct_def fd_cons_desc_def)\n      apply (fastforce simp: l l')\n      apply (fastforce simp: l l')\n      done\n\n    finally show \"field_access a (field_update a bs v) bs' = bs\" using asm fg l l'\n      by (clarsimp simp add: update_desc_def fa_fu_idem_def fg_cons_def)\n  qed\nnext\n  assume \"fa_fu_idem a n\"\n  thus \"fa_fu_idem (update_desc xf xfu a) n\"\n    unfolding fa_fu_idem_def update_desc_def using fg\n    by (clarsimp simp add: update_desc_def fa_fu_idem_def fg_cons_def)\nqed\n\nlemma td_fafu_idem_map_td_update_desc:\n  assumes fg: \"fg_cons xf xfu\"\n  shows  \"wf_fd t \\<Longrightarrow> td_fafu_idem (map_td (\\<lambda>_ _. update_desc xf xfu) t) = td_fafu_idem t\"\n  and    \"wf_fd_struct st \\<Longrightarrow> td_fafu_idem_struct (map_td_struct (\\<lambda>_ _. update_desc xf xfu) st) = td_fafu_idem_struct st\"\n  and    \"wf_fd_list ts \\<Longrightarrow> td_fafu_idem_list (map_td_list (\\<lambda>_ _. update_desc xf xfu) ts) = td_fafu_idem_list ts\"\n  and    \"wf_fd_pair p \\<Longrightarrow> td_fafu_idem_pair (map_td_pair (\\<lambda>_ _. update_desc xf xfu) p) = td_fafu_idem_pair p\"\n  by (induct t and st and ts and p) (auto elim!: fa_fu_idem_update_desc [OF fg])\n\nlemmas td_fafu_idem_adjust_ti = td_fafu_idem_map_td_update_desc(1)[folded adjust_ti_def]\n\nlemma td_fafu_idem_ti_typ_combine:\n  fixes s :: \"'b :: c_type field_desc typ_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and    tda: \"td_fafu_idem (typ_info_t TYPE('a :: mem_type))\"\n  and    tds: \"td_fafu_idem s\"\n  shows \"td_fafu_idem (ti_typ_combine TYPE('a :: mem_type) xf xfu nm s)\"\n  unfolding ti_typ_combine_def using tda tds\n  apply (clarsimp simp: Let_def)\n  apply (cases s)\n  apply (rename_tac typ_struct xs)\n  apply (case_tac typ_struct)\n   apply simp\n   apply (subst td_fafu_idem_adjust_ti [OF fg wf_fd], assumption)\n  apply (simp add: td_fafu_idem_list_append)\n  apply (subst td_fafu_idem_adjust_ti [OF fg wf_fd], assumption)\n  done\n\nlemma td_fafu_idem_ptr:\n   \"td_fafu_idem (typ_info_t TYPE('a :: c_type ptr))\"\n  apply (clarsimp simp add: fa_fu_idem_def)\n  apply (subst word_rsplit_rcat_size)\n   apply (clarsimp simp add: size_of_def word_size)\n  apply simp\n  done\n\nlemma td_fafu_idem_word:\n   \"td_fafu_idem (typ_info_t TYPE('a :: len8 word))\"\n  apply(clarsimp simp add: fa_fu_idem_def)\n  apply (subst word_rsplit_rcat_size)\n   apply (insert len8_dv8)\n   apply (clarsimp simp add: size_of_def word_size)\n   apply (subst dvd_div_mult_self)\n    apply simp\n   apply simp\n  apply simp\n  done\n\nlemma fg_cons_array [simp]:\n  \"n < card (UNIV :: 'b :: finite set) \\<Longrightarrow> fg_cons (\\<lambda>x. index x n) (\\<lambda>x f. Arrays.update (f :: 'a['b]) n x)\"\n  unfolding fg_cons_def by simp\n\nlemma td_fafu_idem_array_n:\n  \"\\<lbrakk>td_fafu_idem (typ_info_t TYPE('a)); n \\<le> card (UNIV :: 'b set) \\<rbrakk> \\<Longrightarrow> td_fafu_idem (array_tag_n n :: ('a :: mem_type ['b :: finite]) field_desc typ_desc)\"\n  apply (induct n)\n   apply (simp add: array_tag_n.simps empty_typ_info_def)\n  apply (simp add: array_tag_n.simps)\n  apply (rule td_fafu_idem_ti_typ_combine)\n    apply simp\n   apply simp\n  apply simp\n  done\n\nlemma td_fafu_idem_array:\n  \"td_fafu_idem (typ_info_t TYPE('a)) \\<Longrightarrow> td_fafu_idem (typ_info_t TYPE('a :: mem_type ['b :: finite]))\"\n  apply (clarsimp simp add: typ_info_array array_tag_def fa_fu_idem_def)\n  apply (erule td_fafu_idem_array_n)\n  apply simp\n  done\n\nlemma td_fafu_idem_empty_typ_info:\n  \"td_fafu_idem (empty_typ_info t)\"\n  unfolding empty_typ_info_def\n  by simp\n\nsubsection {* td_fa_hi *}\n\n(* These are mostly identical to the above --- surely there is something which implies both? *)\n\nlemma td_fa_hi_final_pad:\n  \"padup (2 ^ align_td t) (size_td t) = 0\n  \\<Longrightarrow> td_fa_hi (final_pad t) = td_fa_hi t\"\n  unfolding final_pad_def\n  by (clarsimp simp add: padup_def Let_def)\n\nlemma td_fa_hi_ti_typ_pad_combine:\n  fixes t :: \"'a :: c_type itself\" and s :: \"'b :: c_type field_desc typ_desc\"\n  assumes pad: \"padup (align_of TYPE('a)) (size_td s) = 0\"\n  shows \"td_fa_hi (ti_typ_pad_combine t xf xfu nm s) = td_fa_hi (ti_typ_combine t xf xfu nm s)\"\n  unfolding ti_typ_pad_combine_def using pad\n  by (clarsimp simp: Let_def)\n\nlemma td_fa_hi_list_append:\n  fixes xs :: \"'a :: c_type field_desc typ_pair list\"\n  shows \"td_fa_hi_list (xs @ ys) = (td_fa_hi_list xs \\<and> td_fa_hi_list ys)\"\n  by (induct xs) simp+\n\nlemma td_fa_hi_extend_ti:\n  fixes t :: \"'a :: c_type field_desc typ_desc\"\n  assumes as: \"td_fa_hi s\"\n  and     at: \"td_fa_hi t\"\n  shows \"td_fa_hi (extend_ti s t nm)\" using as at\n  apply (cases s)\n  apply (rename_tac typ_struct xs)\n  apply (case_tac typ_struct)\n   apply simp\n  apply (simp add: td_fa_hi_list_append)\n  done\n\n(* Beer crime? *)\nlemma fa_heap_indep_update_desc:\n  fixes a :: \"'a field_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and     fd: \"fd_cons_struct (TypScalar n n' a)\"\n  shows   \"fa_heap_indep (update_desc xf xfu a) n = fa_heap_indep a n\"\nproof\n  assume asm: \"fa_heap_indep (update_desc xf xfu a) n\"\n\n  have xf_xfu: \"\\<And>v v'. xf (xfu v v') = v\" using fg\n    unfolding fg_cons_def\n    by simp\n\n  show \"fa_heap_indep a n\"\n    unfolding fa_heap_indep_def\n  proof (intro impI conjI allI)\n    fix bs :: \"byte list\" and bs' :: \"byte list\" and v\n    assume l: \"length bs = n\" and l': \"length bs' = n\"\n    with asm have \"field_access (update_desc xf xfu a) (xfu v undefined) bs =\n      field_access (update_desc xf xfu a) (xfu v undefined) bs'\"\n      by (rule fa_heap_indepD)\n\n    thus \"field_access a v bs = field_access a v bs'\"\n      unfolding update_desc_def\n      by (simp add: xf_xfu)\n  qed\nnext\n  assume asm: \"fa_heap_indep a n\"\n  show \"fa_heap_indep (update_desc xf xfu a) n\"\n    unfolding fa_heap_indep_def update_desc_def\n  proof (simp, intro impI conjI allI)\n    fix bs :: \"byte list\" and bs' :: \"byte list\" and v\n    assume l: \"length bs = n\" and l': \"length bs' = n\"\n\n    with asm show \"field_access a (xf v) bs = field_access a (xf v) bs'\"\n      by (rule fa_heap_indepD)\n  qed\nqed\n\nlemma td_fa_hi_map_td_update_desc:\n  assumes fg: \"fg_cons xf xfu\"\n  shows  \"wf_fd t \\<Longrightarrow> td_fa_hi (map_td (\\<lambda>_ _. update_desc xf xfu) t) = td_fa_hi t\"\n  and    \"wf_fd_struct st \\<Longrightarrow> td_fa_hi_struct (map_td_struct (\\<lambda>_ _. update_desc xf xfu) st) = td_fa_hi_struct st\"\n  and    \"wf_fd_list ts \\<Longrightarrow> td_fa_hi_list (map_td_list (\\<lambda>_ _. update_desc xf xfu) ts) = td_fa_hi_list ts\"\n  and    \"wf_fd_pair p \\<Longrightarrow> td_fa_hi_pair (map_td_pair (\\<lambda>_ _. update_desc xf xfu) p) = td_fa_hi_pair p\"\n  by (induct t and st and ts and p) (auto elim!: fa_heap_indep_update_desc [OF fg])\n\nlemmas td_fa_hi_adjust_ti = td_fa_hi_map_td_update_desc(1)[folded adjust_ti_def]\n\nlemma td_fa_hi_ti_typ_combine:\n  fixes s :: \"'b :: c_type field_desc typ_desc\"\n  assumes fg: \"fg_cons xf xfu\"\n  and    tda: \"td_fa_hi (typ_info_t TYPE('a :: mem_type))\"\n  and    tds: \"td_fa_hi s\"\n  shows \"td_fa_hi (ti_typ_combine TYPE('a :: mem_type) xf xfu nm s)\"\n  unfolding ti_typ_combine_def using tda tds\n  apply (clarsimp simp: Let_def)\n  apply (cases s)\n  apply (rename_tac typ_struct xs)\n  apply (case_tac typ_struct)\n   apply simp\n   apply (subst td_fa_hi_adjust_ti [OF fg wf_fd], assumption)\n  apply (simp add: td_fa_hi_list_append)\n  apply (subst td_fa_hi_adjust_ti [OF fg wf_fd], assumption)\n  done\n\nlemma td_fa_hi_ptr:\n   \"td_fa_hi (typ_info_t TYPE('a :: c_type ptr))\"\n  by (clarsimp simp add: fa_heap_indep_def)\n\nlemma td_fa_hi_word:\n   \"td_fa_hi (typ_info_t TYPE('a :: len8 word))\"\n  by (clarsimp simp add: fa_heap_indep_def)\n\nlemma td_fa_hi_array_n:\n  \"\\<lbrakk>td_fa_hi (typ_info_t TYPE('a)); n \\<le> card (UNIV :: 'b set) \\<rbrakk> \\<Longrightarrow> td_fa_hi (array_tag_n n :: ('a :: mem_type ['b :: finite]) field_desc typ_desc)\"\n  apply (induct n)\n   apply (simp add: array_tag_n.simps empty_typ_info_def)\n  apply (simp add: array_tag_n.simps)\n  apply (rule td_fa_hi_ti_typ_combine)\n    apply simp\n   apply simp\n  apply simp\n  done\n\nlemma td_fa_hi_array:\n  \"td_fa_hi (typ_info_t TYPE('a)) \\<Longrightarrow> td_fa_hi (typ_info_t TYPE('a :: mem_type ['b :: finite]))\"\n  apply (clarsimp simp add: typ_info_array array_tag_def fa_fu_idem_def)\n  apply (erule td_fa_hi_array_n)\n  apply simp\n  done\n\nlemma td_fa_hi_empty_typ_info:\n  \"td_fa_hi (empty_typ_info t)\"\n  unfolding empty_typ_info_def\n  by simp\n\nsection {* The type class and simp sets *}\n\ntext {* Packed types, with no padding, have the defining property that\n        access is invariant under substitution of the underlying heap and\n        access/update is the identity *}\n\nclass packed_type = mem_type +\n  assumes td_fafu_idem: \"td_fafu_idem (typ_info_t TYPE('a::c_type))\"\n  assumes td_fa_hi:     \"td_fa_hi (typ_info_t TYPE('a::c_type))\"\n\nlemmas td_fafu_idem_intro_simps =\n  -- \"Axioms\"\n  td_fafu_idem\n  -- \"Combinators\"\n  td_fafu_idem_final_pad td_fafu_idem_ti_typ_pad_combine td_fafu_idem_ti_typ_combine td_fafu_idem_empty_typ_info\n  -- \"Constructors\"\n  td_fafu_idem_ptr td_fafu_idem_word td_fafu_idem_array\n\nlemmas td_fa_hi_intro_simps =\n  -- \"Axioms\"\n  td_fa_hi\n  -- \"Combinators\"\n  td_fa_hi_final_pad td_fa_hi_ti_typ_pad_combine td_fa_hi_ti_typ_combine td_fa_hi_empty_typ_info\n  -- \"Constructors\"\n  td_fa_hi_ptr td_fa_hi_word td_fa_hi_array\n\nlemma align_td_array':\n  \"align_td (typ_info_t TYPE('a :: c_type['b :: finite])) = align_td (typ_info_t TYPE('a))\"\n  by (simp add: typ_info_array array_tag_def align_td_array_tag)\n\nlemmas packed_type_intro_simps =\n  td_fafu_idem_intro_simps td_fa_hi_intro_simps align_td_array' size_td_simps size_td_array\n\nlemma access_ti_append':\n  \"\\<And>list.\n   access_ti_list (xs @ ys) t list =\n     access_ti_list xs t (take (size_td_list xs) list) @\n     access_ti_list ys t (drop (size_td_list xs) list)\"\nproof(induct xs)\n  case Nil show ?case by simp\nnext\n  case (Cons x xs) thus ?case by (simp add: min_def ac_simps drop_take)\nqed\n\nsection {* Instances *}\n\ntext {* Words (of multiple of 8 size) are packed *}\n\ninstantiation word :: (len8) packed_type\nbegin\ninstance\n apply(intro_classes)\n   apply (rule td_fafu_idem_word)\n  apply (rule td_fa_hi_word)\n  done\nend\n\ntext {* Pointers are always packed *}\n\ninstantiation ptr :: (c_type)packed_type\nbegin\ninstance\n  apply intro_classes\n   apply (simp add: fa_fu_idem_def word_rsplit_rcat_size word_size)\n  apply (simp add: fa_heap_indep_def)\n  done\nend\n\ntext {* Arrays of packed types are in turn packed *}\n\nclass oneMB_packed = packed_type + oneMB_size\n\ninstantiation word :: (len8)oneMB_packed\nbegin\ninstance\n apply(intro_classes)\ndone\nend\n\ninstantiation array :: (oneMB_packed,fourthousand_count) packed_type\nbegin\ninstance\n apply(intro_classes)\n   apply (simp add: td_fafu_idem_intro_simps)\n  apply (simp add: td_fa_hi_intro_simps)\n  done\nend\n\nsection {* Theorems about packed types *}\n\nsubsection {* td_fa_hi *}\n\nlemma heap_independence:\n  \"\\<lbrakk>length h = size_of TYPE('a :: packed_type); length h' = size_of TYPE('a) \\<rbrakk>\n  \\<Longrightarrow> access_ti (typ_info_t TYPE('a)) v h = access_ti (typ_info_t TYPE('a)) v h'\"\n  by (rule td_fa_hi_heap_independence(1)[OF td_fa_hi], simp_all add: size_of_def)\n\ntheorem packed_heap_update_collapse:\n fixes u::\"'a::packed_type\"\n fixes v::\"'a\"\n shows\n  \"heap_update p v (heap_update p u h) = heap_update p v h\"\n apply(simp add:heap_update_def)\n apply(rule ext)\n apply(case_tac \"x \\<in> {ptr_val p..+size_of TYPE('a)}\")\n  apply((subst heap_update_mem_same_point, simp, simp)+)\n  apply(simp add:to_bytes_def)\n  apply(subst heap_independence)\n    apply(simp)\n   prefer 2\n   apply(force)\n  apply(simp)\n apply((subst heap_update_nmem_same, simp)+)\n apply(rule refl)\ndone\n\nlemma packed_heap_update_collapse_hrs:\n  fixes p :: \"'a :: packed_type ptr\"\n  shows \"(hrs_mem_update (heap_update p v) (hrs_mem_update (heap_update p v') hp)) =\n  (hrs_mem_update (heap_update p v) hp)\"\n  unfolding hrs_mem_update_def\n  by (simp add: split_def packed_heap_update_collapse)\n\nsubsection {* td_fafu_idem *}\n\nlemma order_leE:\n  fixes x :: \"'a :: order\"\n  shows \"\\<lbrakk> x \\<le> y; x = y \\<Longrightarrow> P; x < y \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P\"\n  by (auto simp: order_le_less)\n\nlemma of_nat_mono_maybe_le:\n  shows \"\\<lbrakk>X < 2 ^ len_of TYPE('a); Y \\<le> X\\<rbrakk> \\<Longrightarrow> (of_nat Y :: 'a :: len word) \\<le> of_nat X\"\n  apply (erule order_leE)\n   apply simp\n  apply (rule order_less_imp_le)\n  apply (erule (1) of_nat_mono_maybe)\n  done\n\nlemma intvl_le_lower:\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk> x \\<in> {y..+n}; y \\<le> y + of_nat (n - 1); n < 2 ^ len_of TYPE('a) \\<rbrakk> \\<Longrightarrow> y \\<le> x\"\n  apply (drule intvlD)\n  apply (elim conjE exE)\n  apply (erule ssubst)\n  apply (erule word_plus_mono_right2)\n  apply (rule of_nat_mono_maybe_le)\n   apply simp\n  apply simp\n  done\n\nlemma intvl_less_upper:\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk> x \\<in> {y..+n}; y \\<le> y + of_nat (n - 1); n < 2 ^ len_of TYPE('a) \\<rbrakk> \\<Longrightarrow> x \\<le> y + of_nat (n - 1)\"\n  apply (drule intvlD)\n  apply (elim conjE exE)\n  apply (erule ssubst)\n  apply (rule word_plus_mono_right)\n   apply (rule of_nat_mono_maybe_le)\n    apply simp\n   apply simp\n  apply assumption\n  done\n\nlemma packed_type_access_ti:\n  fixes v :: \"'a :: packed_type\"\n  assumes lbs: \"length bs = size_of TYPE('a)\"\n  shows \"access_ti (typ_info_t TYPE('a)) v bs = access_ti\\<^sub>0 (typ_info_t TYPE('a)) v\"\n  unfolding access_ti\\<^sub>0_def using lbs\n  apply -\n  apply (rule heap_independence)\n   apply simp\n  apply (simp add: size_of_def)\n  done\n\nlemma update_ti_update_ti_t:\n  \"length bs = size_td s \\<Longrightarrow> update_ti s bs v = update_ti_t s bs v\"\n  unfolding update_ti_t_def by simp\n\nlemma heap_list_nth:\n  \"m < n \\<Longrightarrow> heap_list hp n p ! m = hp (p + of_nat m)\"\nproof (induct m arbitrary: n p)\n  case (0 n' p')\n\n  thus ?case by (cases n', simp_all)\nnext\n  case (Suc m' n' p')\n\n  show ?case\n  proof (cases n')\n    case 0 thus ?thesis using `Suc m' < n'` by simp\n  next\n    case (Suc n'')\n    hence \"m' < n''\" using `Suc m' < n'` by simp\n    thus ?thesis using Suc\n      by (simp add: Suc.hyps ac_simps)\n  qed\nqed\n\nlemma c_guard_field_lvalue:\n  fixes p :: \"'a :: mem_type ptr\"\n  assumes cg: \"c_guard p\"\n  and     fl: \"field_lookup (typ_info_t TYPE('a)) f 0 = Some (t, n)\"\n  and     eu: \"export_uinfo t = typ_uinfo_t TYPE('b :: mem_type)\"\n  shows   \"c_guard (Ptr &(p\\<rightarrow>f) :: 'b :: mem_type ptr)\"\n  unfolding c_guard_def\nproof (rule conjI)\n  from cg fl eu show \"ptr_aligned (Ptr &(p\\<rightarrow>f) :: 'b ptr)\"\n    by (rule c_guard_ptr_aligned_fl)\nnext\n  from eu have std: \"size_td t = size_of TYPE('b)\" using fl\n    by (simp add: export_size_of)\n\n  from cg have \"c_null_guard p\" unfolding c_guard_def ..\n  thus \"c_null_guard (Ptr &(p\\<rightarrow>f)  :: 'b ptr)\" unfolding c_null_guard_def\n    apply (rule contrapos_nn)\n    apply (rule subsetD [OF field_tag_sub, OF fl])\n    apply (simp add: std)\n    done\nqed\n\n(* Similar in TypHeap, but for w32 *)\nlemma unat_minus':\n  fixes x :: \"'a :: len word\"\n  shows \"x \\<noteq> 0 \\<Longrightarrow> unat (-x) = 2 ^ len_of TYPE('a) - unat x\"\n  apply (simp add: unat_def word_minus_def)\n  apply (simp add: int_word_uint zmod_zminus1_eq_if uint_0_iff)\n  apply (subst nat_diff_distrib)\n    apply simp\n   apply (rule order_less_imp_le [OF uint_lt2p])\n   apply (clarsimp simp: nat_power_eq)\n   done\n\nlemma word_wrap_of_natD:\n  fixes x :: \"'a :: len word\"\n  assumes wraps: \"\\<not> x \\<le> x + of_nat n\"\n  shows   \"\\<exists>k. x + of_nat k = 0 \\<and> k \\<le> n\"\nproof -\n  show ?thesis\n  proof (rule exI [where x = \"unat (- x)\"], intro conjI)\n    show \"x + of_nat (unat (-x)) = 0\"\n      by simp\n  next\n    show \"unat (-x) \\<le> n\"\n    proof (subst unat_minus')\n      from wraps show \"x \\<noteq> 0\"\n\tby (rule contrapos_pn, simp add: not_le)\n    next\n      show \"2 ^ len_of TYPE('a) - unat x \\<le> n\" using wraps\n\tapply (simp add: no_olen_add_nat le_diff_conv not_less)\n\tapply (erule order_trans)\n\tapply (simp add: unat_of_nat)\n\tdone\n    qed\n  qed\nqed\n\nlemma nat_le_Suc_less:\n  \"0 < y \\<Longrightarrow> (x \\<le> y - Suc 0) = (x < y)\"\n  by arith\n\nlemma c_guard_no_wrap:\n  fixes p :: \"'a :: mem_type ptr\"\n  assumes cgrd: \"c_guard p\"\n  shows   \"ptr_val p \\<le> ptr_val p + of_nat (size_of TYPE('a) - 1)\"\n  using cgrd unfolding c_guard_def c_null_guard_def\n  apply -\n  apply (erule conjE)\n  apply (erule contrapos_np)\n  apply (simp add: intvl_def)\n  apply (drule word_wrap_of_natD)\n  apply (erule exE)\n  apply (rule exI)\n  apply (simp add: nat_le_Suc_less)\n  done\n\ntheorem packed_heap_super_field_update:\n  fixes v :: \"'a :: packed_type\" and p :: \"'b :: packed_type ptr\"\n  assumes fl: \"field_lookup (typ_info_t TYPE('b)) f 0 = Some (t, n)\"\n  and   cgrd: \"c_guard p\"\n  and     eu: \"export_uinfo t = typ_uinfo_t TYPE('a)\"\n  shows   \"heap_update (Ptr &(p\\<rightarrow>f)) v hp = heap_update p (update_ti t (to_bytes_p v) (h_val hp p)) hp\"\n  unfolding heap_update_def to_bytes_def\nproof (simp add: packed_type_access_ti, rule ext)\n  fix x\n  let ?LHS = \"heap_update_list &(p\\<rightarrow>f) (to_bytes_p v) hp x\"\n  let ?RHS = \"heap_update_list (ptr_val p) (to_bytes_p (update_ti t (to_bytes_p v) (h_val hp p))) hp x\"\n\n  from cgrd have al: \"ptr_val p \\<le> ptr_val p + of_nat (size_of TYPE('b) - 1)\" by (rule c_guard_no_wrap)\n\n  have szb: \"size_of TYPE('b) < 2 ^ len_of TYPE(32)\"\n    apply (fold card_word)\n    apply (fold addr_card_def)\n    apply (rule max_size)\n    done\n\n  have szt: \"n + size_td t \\<le> size_of TYPE('b)\"\n    unfolding size_of_def\n    by (subst add.commute, rule field_lookup_offset_size [OF fl])\n  moreover have t0: \"0 < size_td t\" using fl wf_size_desc\n    by (rule field_lookup_wf_size_desc_gt)\n  ultimately have szn: \"n < size_of TYPE('b)\" by simp\n  from szt have szt1: \"n + (size_td t - 1) \\<le> size_of TYPE('b)\"\n    by simp\n\n  have b0: \"0 < size_of (TYPE ('b))\" using wf_size_desc\n    unfolding size_of_def\n    by (rule wf_size_desc_gt)\n\n  have uofn: \"unat (of_nat n :: 32 word) = n\" using szn szb\n    by (simp add: unat_simps)\n\n  from eu have std: \"size_td t = size_of TYPE('a)\" using fl\n    by (simp add: export_size_of)\n\n  hence \"?LHS = (if x \\<in> {&(p\\<rightarrow>f)..+size_td t} then (to_bytes_p v) ! unat (x - &(p\\<rightarrow>f)) else hp x)\"\n    by (simp add: heap_update_mem_same_point heap_update_nmem_same)\n  also have \"... = ?RHS\"\n  proof (simp, intro impI conjI)\n    assume xin: \"x \\<in> {&(p\\<rightarrow>f)..+size_td t}\"\n    have \"to_bytes_p v ! unat (x - &(p\\<rightarrow>f)) = to_bytes_p (update_ti t (to_bytes_p v) (h_val hp p)) ! unat (x - ptr_val p)\"\n    proof (simp add: to_bytes_p_def to_bytes_def, subst field_access_update_nth_inner(1)[OF fl, simplified])\n\n      have \"c_guard (Ptr &(p\\<rightarrow>f) :: 'a ptr)\" using cgrd fl eu\n\tby (rule c_guard_field_lvalue)\n      hence pft: \"&(p\\<rightarrow>f) \\<le> &(p\\<rightarrow>f) + of_nat (size_td t - 1)\"\n\tapply -\n\tapply (drule c_guard_no_wrap)\n\tapply (simp add: std)\n\tdone\n\n      have szt': \"size_td t < 2 ^ len_of TYPE(32)\"\n\tapply (subst std)\n\tapply (fold card_word)\n\tapply (fold addr_card_def)\n\tapply (rule max_size)\n\tdone\n\n      have ofn: \"of_nat n \\<le> x - ptr_val p\"\n      proof (rule le_minus')\n\tfrom xin show \"ptr_val p + of_nat n \\<le> x\" using pft szt'\n\t  unfolding field_lvalue_def field_lookup_offset_eq [OF fl]\n\t  by (rule intvl_le_lower)\n      next\n\tfrom szb szn have \"of_nat n \\<le> (of_nat (size_of TYPE('b) - 1) :: 32 word)\"\n\t  apply -\n\t  apply (rule of_nat_mono_maybe_le)\n\t  apply simp_all\n\t  done\n\twith al show \"ptr_val p \\<le> ptr_val p + of_nat n\"\n\t  by (rule word_plus_mono_right2)\n      qed\n\n      thus nlt: \"n \\<le> unat (x - ptr_val p)\"\n\tby (simp add: word_le_nat_alt uofn)\n      have \"x \\<le> ptr_val p + (of_nat n + of_nat (size_td t - 1))\" using xin pft szt' t0\n\tunfolding field_lvalue_def field_lookup_offset_eq [OF fl]\n\tapply -\n\tapply (drule (2) intvl_less_upper)\n\tapply (simp add: add.assoc)\n\tdone\n      moreover have \"x \\<in> {ptr_val p..+size_of TYPE('b)}\" using fl xin\n\tby (rule subsetD [OF field_tag_sub])\n      ultimately have \"x - ptr_val p \\<le> (of_nat n + of_nat (size_td t - 1))\" using al szb\n\tapply -\n\tapply (rule word_diff_ls(4)[where xa=x and x=x for x, simplified])\n     apply (metis (hide_lams, mono_tags) add.commute of_nat_add)\n\tapply (erule (2) intvl_le_lower)\n\tdone\n      moreover have \"unat (of_nat n + of_nat (size_td t - 1) :: 32 word) = n + size_td t - 1\"\n\tusing t0 order_le_less_trans [OF szt1 szb]\n\tapply (subst Abs_fnat_homs(1))\n\tapply (subst unat_of_nat)\n\tapply simp\n\tdone\n      ultimately have \"unat (x - ptr_val p) \\<le> n + size_td t - 1\"\n\tby (simp add: word_le_nat_alt)\n      thus \"unat (x - ptr_val p) < n + size_td t\" using t0\n\tby simp\n\n      show \"td_fafu_idem t\"\n\tby (rule field_lookup_td_fafu_idem(1)[OF fl td_fafu_idem])\n\n      show \"wf_fd t\"\n\tby (rule wf_fd_field_lookupD [OF fl wf_fd])\n\n      show \"length (access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0)) = size_td t\"\n\tusing wf_fd [where 'a = 'a]\n\tby (simp add: length_fa_ti size_of_def std)\n\n      show \"length (replicate (size_of TYPE('b)) 0) = size_td (typ_info_t TYPE('b))\"\n\tby (simp add: size_of_def)\n\n      have \"unat (x - &(p\\<rightarrow>f)) = unat ((x - ptr_val p) - of_nat n)\"\n  \tby (simp add: field_lvalue_def field_lookup_offset_eq [OF fl])\n      also have \"\\<dots> = unat (x - ptr_val p) - n\"\n\tby (simp add: unat_sub [OF ofn] uofn)\n      finally have \"unat (x - &(p\\<rightarrow>f)) = unat (x - ptr_val p) - n\" .\n\n      thus \"access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0) ! unat (x - &(p\\<rightarrow>f)) =\n\taccess_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0) ! (unat (x - ptr_val p) - n)\"\n\tby simp\n    qed\n\n    thus \"to_bytes_p v ! unat (x - &(p\\<rightarrow>f)) = ?RHS\"\n    proof (subst heap_update_mem_same_point, simp_all)\n      show \"x \\<in> {ptr_val p..+size_of TYPE('b)}\" using fl xin\n\tby (rule subsetD [OF field_tag_sub])\n    qed\n  next\n    assume xni: \"x \\<notin> {&(p\\<rightarrow>f)..+size_td t}\"\n    have \"?RHS = (if x \\<in> {ptr_val p..+size_of TYPE('b)}\n          then (to_bytes_p (update_ti t (to_bytes_p v) (h_val hp p))) ! unat (x - ptr_val p) else hp x)\"\n      by (simp add: heap_update_mem_same_point heap_update_nmem_same)\n\n    also\n    {\n      assume xin: \"x \\<in> {ptr_val p..+size_of TYPE('b)}\"\n\n      hence \"access_ti (typ_info_t TYPE('b))\n\t(update_ti_t t (access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0)) (h_val hp p))\n\t(replicate (size_of TYPE('b)) 0) ! unat (x - ptr_val p) = hp x\"\n      proof (subst field_access_update_nth_disjD [OF fl])\n\thave \"x - ptr_val p \\<le> of_nat (size_of TYPE('b) - 1)\"\n\tproof (rule word_diff_ls(4)[where xa=x and x=x for x, simplified])\n      \t  from xin show \"x \\<le> of_nat (size_of TYPE('b) - 1) + ptr_val p\" using al szb\n\t    by (subst add.commute, rule intvl_less_upper)\n\t  show \"ptr_val p \\<le> x\" using xin al szb\n\t    by (rule intvl_le_lower)\n\tqed\n\tthus unx: \"unat (x - ptr_val p) < size_td (typ_info_t TYPE('b))\" using szb b0\n\t  by (simp add: word_le_nat_alt size_of_def unat_of_nat)\n\n\tshow \"unat (x - ptr_val p) < n - 0 \\<or> n - 0 + size_td t \\<le> unat (x - ptr_val p)\" using xin xni\n  \t  unfolding field_lvalue_def field_lookup_offset_eq [OF fl]\n\t  apply -\n\t  apply (erule intvl_cut)\n\t  apply simp\n\t  apply (rule max_size)\n\t  done\n\n\tshow \"wf_fd (typ_info_t TYPE('b))\" by (rule wf_fd)\n\t(* clag *)\n\tshow \"length (access_ti (typ_info_t TYPE('a)) v (replicate (size_of TYPE('a)) 0)) = size_td t\"\n\t  using wf_fd [where 'a = 'a]\n\t  by (simp add: length_fa_ti size_of_def std)\n\n\tshow \"length (replicate (size_of TYPE('b)) 0) = size_td (typ_info_t TYPE('b))\"\n\t  by (simp add: size_of_def)\n\n\thave \"heap_list hp (size_td (typ_info_t TYPE('b))) (ptr_val p) ! unat (x - ptr_val p) = hp x\"\n\t  apply (subst heap_list_nth)\n\t  apply (rule unx)\n\t  apply simp\n\t  done\n\n\tthus \"access_ti (typ_info_t TYPE('b)) (h_val hp p) (replicate (size_of TYPE('b)) 0) ! unat (x - ptr_val p) = hp x\"\n\t  unfolding h_val_def\n\t  by (simp add: from_bytes_def update_ti_t_def size_of_def field_access_update_same(1)[OF td_fafu_idem wf_fd])\n      qed\n     }\n    hence \"\\<dots> = hp x\"\n      by (simp add: to_bytes_p_def to_bytes_def update_ti_update_ti_t length_fa_ti [OF wf_fd] std size_of_def)\n    finally show \"hp x = ?RHS\" by simp\n  qed\n  finally show \"?LHS = ?RHS\" .\nqed\n\nend\n", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/c-parser/PackedTypes.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5312093733737563, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.26145495115824113}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\n(* License: BSD, terms see file ./LICENSE *)\n\n(* Definitions supporting the extremely long CTypes.thy *)\n\ntheory CTypesDefs\nimports\n  \"~~/src/HOL/Library/Prefix_Order\"\n  \"../../lib/SignedWords\"\n  CTypesBase\nbegin\n\nsection \"C types setup\"\n\ntype_synonym field_name = string\ntype_synonym qualified_field_name = \"field_name list\"\n\ntype_synonym typ_name = string\n\n\nsection \"XXX: unsectioned and mostly uncommented, as in original\"\n\n(* XXX FIXME TODO:\n * Figure out sectioning here first and *then* try make CTypes.thy conform\n   to that sectioning.\n * Also, all definitions from CTypes.thy are here. Some might be local-only\n   and thus might need to be put back.\n * Some definitions are closely followed by [simp] lemmas simplifying their\n   most common usage. Perhaps put these in here with the defs?\n *)\n\ntext {* A typ_desc wraps a typ_struct with a typ name.\n        A typ_struct is either a Scalar, with size, alignment and either a\n        field accessor/updator pair (for typ_info) or a 'normalisor'\n        (for typ_uinfo), or an Aggregate, with a list of typ_desc,\n        field name pairs.*}\n\ndatatype 'a typ_desc   = TypDesc \"'a typ_struct\" typ_name\n    and  'a typ_struct = TypScalar nat nat \"'a\" |\n                         TypAggregate \"('a typ_desc,field_name) dt_pair list\"\n\ntype_synonym 'a typ_pair = \"('a typ_desc,field_name) dt_pair\"\n\ntype_synonym typ_uinfo = \"normalisor typ_desc\"\ntype_synonym typ_uinfo_struct = \"normalisor typ_struct\"\ntype_synonym typ_uinfo_pair = \"normalisor typ_pair\"\n\nrecord 'a field_desc =\n  field_access :: \"'a \\<Rightarrow> byte list \\<Rightarrow> byte list\"\n  field_update :: \"byte list \\<Rightarrow> 'a \\<Rightarrow> 'a\"\n\ntype_synonym 'a typ_info = \"'a field_desc typ_desc\"\ntype_synonym 'a typ_info_struct = \"'a field_desc typ_struct\"\ntype_synonym 'a typ_info_pair = \"'a field_desc typ_pair\"\n\ndefinition fu_commutes :: \"('b \\<Rightarrow> 'a \\<Rightarrow> 'a) \\<Rightarrow> ('c \\<Rightarrow> 'a \\<Rightarrow> 'a) \\<Rightarrow> bool\" where\n  \"fu_commutes f g \\<equiv> \\<forall>v bs bs'. f bs (g bs' v) = g bs' (f bs v)\"\n\n\ntext {* size_td returns the sum of the sizes of all Scalar fields\n        comprising a typ_desc i.e. the overall size of the type *}\n\n(* Could express this and many other typ_desc primrecs as tree fold/map\n   combos, but the intuition this way is clearer for anything non-trivial *)\nprimrec\n  size_td :: \"'a typ_desc \\<Rightarrow> nat\" and\n  size_td_struct :: \"'a typ_struct \\<Rightarrow> nat\" and\n  size_td_list :: \"'a typ_pair list \\<Rightarrow> nat\" and\n  size_td_pair :: \"'a typ_pair \\<Rightarrow> nat\"\nwhere\n  tz0: \"size_td (TypDesc st nm) = size_td_struct st\"\n\n| tz1: \"size_td_struct (TypScalar n algn d) = n\"\n| tz2: \"size_td_struct (TypAggregate xs) = size_td_list xs\"\n\n| tz3: \"size_td_list [] = 0\"\n| tz4: \"size_td_list (x#xs) = size_td_pair x + size_td_list xs\"\n\n| tz5: \"size_td_pair (DTPair t n) = size_td t\"\n\n\ntext {* access_ti overlays the byte-wise representation of an object\n        on a given byte list, given the typ_info (i.e. the layout) *}\n\nprimrec\n  access_ti :: \"'a typ_info \\<Rightarrow> ('a \\<Rightarrow> byte list \\<Rightarrow> byte list)\" and\n  access_ti_struct :: \"'a typ_info_struct \\<Rightarrow>\n    ('a \\<Rightarrow> byte list \\<Rightarrow> byte list)\" and\n  access_ti_list :: \"'a typ_info_pair list \\<Rightarrow>\n    ('a \\<Rightarrow> byte list \\<Rightarrow> byte list)\" and\n  access_ti_pair :: \"'a typ_info_pair \\<Rightarrow> ('a \\<Rightarrow> byte list \\<Rightarrow> byte list)\"\nwhere\n  fa0: \"access_ti (TypDesc st nm) = access_ti_struct st\"\n\n| fa1: \"access_ti_struct (TypScalar n algn d) = field_access d\"\n| fa2: \"access_ti_struct (TypAggregate xs) = access_ti_list xs\"\n\n| fa3: \"access_ti_list [] = (\\<lambda>v bs. [])\"\n| fa4: \"access_ti_list (x#xs) =\n         (\\<lambda>v bs. access_ti_pair x v (take (size_td_pair x) bs) @\n                 access_ti_list xs v (drop (size_td_pair x) bs))\"\n\n| fa5: \"access_ti_pair (DTPair t nm) = access_ti t\"\n\ntext {* access_ti\\<^sub>0 overlays the representation of an object on a\n        list of zero bytes *}\n\ndefinition access_ti\\<^sub>0 :: \"'a typ_info \\<Rightarrow> ('a \\<Rightarrow> byte list)\" where\n  \"access_ti\\<^sub>0 t \\<equiv> \\<lambda>v. access_ti t v (replicate (size_td t) 0)\"\n\ntext {* update_ti updates an object, given a list of bytes (the\n        representation of the new value), and the typ_info *}\n\nprimrec\n  update_ti :: \"'a typ_info \\<Rightarrow> (byte list \\<Rightarrow> 'a \\<Rightarrow> 'a)\" and\n  update_ti_struct :: \"'a typ_info_struct \\<Rightarrow> (byte list \\<Rightarrow> 'a \\<Rightarrow> 'a)\" and\n  update_ti_list :: \"'a typ_info_pair list \\<Rightarrow> (byte list \\<Rightarrow> 'a \\<Rightarrow> 'a)\" and\n  update_ti_pair :: \"'a typ_info_pair \\<Rightarrow> (byte list \\<Rightarrow> 'a \\<Rightarrow> 'a)\"\nwhere\n  fu0: \"update_ti (TypDesc st nm) = update_ti_struct st\"\n\n| fu1: \"update_ti_struct (TypScalar n algn d) = field_update d\"\n| fu2: \"update_ti_struct (TypAggregate xs) = update_ti_list xs\"\n\n| fu3: \"update_ti_list [] = (\\<lambda>bs. id)\"\n| fu4: \"update_ti_list (x#xs) = (\\<lambda>bs v.\n         update_ti_pair x (take (size_td_pair x) bs)\n             (update_ti_list xs (drop (size_td_pair x) bs) v))\"\n\n| fu5: \"update_ti_pair (DTPair t nm) = update_ti t\"\n\n\ntext {* update_ti_t updates an object only if the length of the\n        supplied representation equals the object size *}\n\ndefinition update_ti_t :: \"'a typ_info \\<Rightarrow> (byte list \\<Rightarrow> 'a \\<Rightarrow> 'a)\" where\n  \"update_ti_t t \\<equiv> \\<lambda>bs. if length bs = size_td t then\n      update_ti t bs else id\"\n\ndefinition update_ti_struct_t :: \"'a typ_info_struct \\<Rightarrow> (byte list \\<Rightarrow> 'a \\<Rightarrow> 'a)\" where\n  \"update_ti_struct_t t \\<equiv> \\<lambda>bs. if length bs = size_td_struct t then\n      update_ti_struct t bs else id\"\n\ndefinition update_ti_list_t :: \"'a typ_info_pair list  \\<Rightarrow> (byte list \\<Rightarrow> 'a \\<Rightarrow> 'a)\" where\n  \"update_ti_list_t t \\<equiv> \\<lambda>bs. if length bs = size_td_list t then\n      update_ti_list t bs else id\"\n\ndefinition update_ti_pair_t :: \"'a typ_info_pair \\<Rightarrow> (byte list \\<Rightarrow> 'a \\<Rightarrow> 'a)\" where\n  \"update_ti_pair_t t \\<equiv> \\<lambda>bs. if length bs = size_td_pair t then\n      update_ti_pair t bs else id\"\n\n\ntext {* field_desc generates the access/update pair for a field,\n        given the field's type_desc *}\n\ndefinition field_desc :: \"'a typ_info \\<Rightarrow> 'a field_desc\" where\n  \"field_desc t \\<equiv> \\<lparr> field_access = access_ti t,\n      field_update = update_ti_t t \\<rparr>\"\n\ndeclare field_desc_def [simp add]\n\ndefinition field_desc_struct :: \"'a typ_info_struct \\<Rightarrow> 'a field_desc\" where\n  \"field_desc_struct t \\<equiv> \\<lparr> field_access = access_ti_struct t,\n      field_update = update_ti_struct_t t \\<rparr>\"\n\ndeclare field_desc_struct_def [simp add]\n\ndefinition field_desc_list :: \"'a typ_info_pair list \\<Rightarrow> 'a field_desc\"\nwhere\n  \"field_desc_list t \\<equiv> \\<lparr> field_access = access_ti_list t,\n      field_update = update_ti_list_t t \\<rparr>\"\n\ndeclare field_desc_list_def [simp add]\n\ndefinition field_desc_pair :: \"'a typ_info_pair \\<Rightarrow> 'a field_desc\"\nwhere\n  \"field_desc_pair t \\<equiv> \\<lparr> field_access = access_ti_pair t,\n      field_update = update_ti_pair_t t \\<rparr>\"\n\ndeclare field_desc_pair_def [simp add]\n\n\nprimrec\n  map_td :: \"(nat \\<Rightarrow> nat \\<Rightarrow> 'a \\<Rightarrow> 'b) \\<Rightarrow> 'a typ_desc \\<Rightarrow> 'b typ_desc\" and\n  map_td_struct :: \"(nat \\<Rightarrow> nat \\<Rightarrow> 'a \\<Rightarrow> 'b) \\<Rightarrow> 'a typ_struct  \\<Rightarrow> 'b typ_struct\" and\n  map_td_list :: \"(nat \\<Rightarrow> nat \\<Rightarrow> 'a \\<Rightarrow> 'b) \\<Rightarrow> 'a typ_pair list \\<Rightarrow>\n    'b typ_pair list\" and\n  map_td_pair :: \"(nat \\<Rightarrow> nat \\<Rightarrow> 'a  \\<Rightarrow> 'b) \\<Rightarrow> 'a typ_pair \\<Rightarrow> 'b typ_pair\"\nwhere\n  mat0: \"map_td f (TypDesc st nm) = TypDesc (map_td_struct f st) nm\"\n\n| mat1: \"map_td_struct f (TypScalar n algn d) = TypScalar n algn (f n algn d)\"\n| mat2: \"map_td_struct f (TypAggregate xs) = TypAggregate (map_td_list f xs)\"\n\n| mat3: \"map_td_list f [] = []\"\n| mat4: \"map_td_list f (x#xs) = map_td_pair f x # map_td_list f xs\"\n\n| mat5: \"map_td_pair f (DTPair t n) = DTPair (map_td f t) n\"\n\ndefinition field_norm :: \"nat \\<Rightarrow> nat \\<Rightarrow> 'a field_desc \\<Rightarrow> (byte list \\<Rightarrow> byte list)\"\nwhere\n  \"field_norm \\<equiv> \\<lambda>n algn d bs.\n      if length bs = n then\n          field_access d (field_update d bs undefined) (replicate n 0) else\n          []\"\n\ndefinition export_uinfo :: \"'a typ_info \\<Rightarrow> typ_uinfo\" where\n  \"export_uinfo t \\<equiv> map_td field_norm t\"\n\n\nprimrec\n  wf_desc :: \"'a typ_desc \\<Rightarrow> bool\" and\n  wf_desc_struct :: \"'a typ_struct \\<Rightarrow> bool\" and\n  wf_desc_list :: \"'a typ_pair list \\<Rightarrow> bool\" and\n  wf_desc_pair :: \"'a typ_pair \\<Rightarrow> bool\"\nwhere\n  wfd0: \"wf_desc (TypDesc ts n) = wf_desc_struct ts\"\n\n| wfd1: \"wf_desc_struct (TypScalar n algn d) = True\"\n| wfd2: \"wf_desc_struct (TypAggregate ts) = wf_desc_list ts\"\n\n| wfd3: \"wf_desc_list [] = True\"\n| wfd4: \"wf_desc_list (x#xs) = (wf_desc_pair x \\<and> \\<not> dt_snd x \\<in> dt_snd ` set xs \\<and>\n          wf_desc_list xs)\"\n\n| wfd5: \"wf_desc_pair (DTPair x n) = wf_desc x\"\n\n\nprimrec\n  wf_size_desc :: \"'a typ_desc \\<Rightarrow> bool\" and\n  wf_size_desc_struct :: \"'a typ_struct \\<Rightarrow> bool\" and\n  wf_size_desc_list :: \"'a typ_pair list \\<Rightarrow> bool\" and\n  wf_size_desc_pair :: \"'a typ_pair \\<Rightarrow> bool\"\nwhere\n  wfsd0: \"wf_size_desc (TypDesc ts n) = wf_size_desc_struct ts\"\n\n| wfsd1: \"wf_size_desc_struct (TypScalar n algn d) = (0 < n)\"\n| wfsd2: \"wf_size_desc_struct (TypAggregate ts) =\n           (ts \\<noteq> [] \\<and> wf_size_desc_list ts)\"\n\n| wfsd3: \"wf_size_desc_list [] = True\"\n| wfsd4: \"wf_size_desc_list (x#xs) =\n           (wf_size_desc_pair x \\<and> wf_size_desc_list xs)\"\n\n| wfsd5: \"wf_size_desc_pair (DTPair x n) = wf_size_desc x\"\n\n\nprimrec\n  typ_struct :: \"'a typ_desc \\<Rightarrow> 'a typ_struct\"\nwhere\n  \"typ_struct (TypDesc st sz) = st\"\n\nprimrec\n  typ_name :: \"'a typ_desc \\<Rightarrow> typ_name\"\nwhere\n  \"typ_name (TypDesc st nm) = nm\"\n\nprimrec\n  norm_tu :: \"typ_uinfo \\<Rightarrow> normalisor\" and\n  norm_tu_struct :: \"typ_uinfo_struct \\<Rightarrow> normalisor\" and\n  norm_tu_list :: \"typ_uinfo_pair list \\<Rightarrow> normalisor\" and\n  norm_tu_pair :: \"typ_uinfo_pair \\<Rightarrow> normalisor\"\nwhere\n  tn0: \"norm_tu (TypDesc st nm) = norm_tu_struct st\"\n\n| tn1: \"norm_tu_struct (TypScalar n aln f) = f\"\n| tn2: \"norm_tu_struct (TypAggregate xs) = norm_tu_list xs\"\n\n| tn3: \"norm_tu_list [] = (\\<lambda>bs. [])\"\n| tn4: \"norm_tu_list (x#xs) = (\\<lambda>bs.\n         norm_tu_pair x (take (size_td_pair x) bs) @\n         norm_tu_list xs (drop (size_td_pair x) bs))\"\n\n| tn5: \"norm_tu_pair (DTPair t n) = norm_tu t\"\n\nclass c_type\n\ninstance c_type \\<subseteq> type ..\n\nconsts\n  typ_info_t :: \"'a::c_type itself \\<Rightarrow> 'a typ_info\"\n  typ_name_itself :: \"'a::c_type itself \\<Rightarrow> typ_name\"\n\ndefinition typ_uinfo_t :: \"'a::c_type itself \\<Rightarrow> typ_uinfo\" where\n  \"typ_uinfo_t t \\<equiv> export_uinfo (typ_info_t TYPE('a))\"\n\ndefinition to_bytes :: \"'a::c_type \\<Rightarrow> byte list \\<Rightarrow> byte list\" where\n  \"to_bytes v \\<equiv> access_ti (typ_info_t TYPE('a)) v\"\n\n\n(* from_bytes is now total - all partial C types 'a need to be instantiated\n   as c_types using 'a option and the parser needs to do some work\n   extracting the value and generating guards for non-None when these are\n   used. Luckily for us in our work we never use them. *)\ndefinition from_bytes :: \"byte list \\<Rightarrow> 'a::c_type\" where\n  \"from_bytes bs \\<equiv>\n      field_update (field_desc (typ_info_t TYPE('a))) bs undefined\"\n\n\ntype_synonym 'a flr = \"('a typ_desc \\<times> nat) option\"\n\nprimrec\n  field_lookup :: \"'a typ_desc \\<Rightarrow> qualified_field_name \\<Rightarrow> nat \\<Rightarrow> 'a flr\" and\n  field_lookup_struct :: \"'a typ_struct \\<Rightarrow> qualified_field_name \\<Rightarrow> nat \\<Rightarrow>\n    'a flr\" and\n  field_lookup_list :: \"'a typ_pair list \\<Rightarrow> qualified_field_name \\<Rightarrow> nat \\<Rightarrow>\n    'a flr\" and\n  field_lookup_pair :: \"'a typ_pair \\<Rightarrow> qualified_field_name \\<Rightarrow> nat \\<Rightarrow> 'a flr\"\nwhere\n  fl0: \"field_lookup (TypDesc st nm) f m =\n         (if f=[] then Some (TypDesc st nm,m) else field_lookup_struct st f m)\"\n\n| fl1: \"field_lookup_struct (TypScalar n algn d) f m = None\"\n| fl2: \"field_lookup_struct (TypAggregate xs) f m = field_lookup_list xs f m\"\n\n| fl3: \"field_lookup_list [] f m = None\"\n| fl4: \"field_lookup_list (x#xs) f m = (\n         case field_lookup_pair x f m of\n           None \\<Rightarrow> field_lookup_list xs f (m + size_td (dt_fst x)) |\n           Some y \\<Rightarrow> Some y)\"\n\n| fl5: \"field_lookup_pair (DTPair t nm) f m =\n         (if nm=hd f \\<and> f \\<noteq> [] then field_lookup t (tl f) m else None)\"\n\n\ndefinition map_td_flr :: \"(nat \\<Rightarrow> nat \\<Rightarrow> 'a \\<Rightarrow> 'b) \\<Rightarrow>\n  ('a typ_desc \\<times> nat) option \\<Rightarrow> 'b flr\"\nwhere\n  \"map_td_flr f \\<equiv> case_option None (\\<lambda>(s,n). Some (map_td f s,n))\"\n\n\ndefinition\n  import_flr :: \"(nat \\<Rightarrow> nat \\<Rightarrow> 'b \\<Rightarrow> 'a) \\<Rightarrow> 'a flr \\<Rightarrow> ('b typ_desc \\<times> nat) option \\<Rightarrow> bool\"\nwhere\n  \"import_flr f s k \\<equiv> case_option (k=None)\n      (\\<lambda>(s,m). case_option False (\\<lambda>(t,n). n=m \\<and> map_td f t=s) k )\n      s\"\n\ndefinition\n  field_offset_untyped :: \"'a typ_desc \\<Rightarrow> qualified_field_name \\<Rightarrow> nat\"\nwhere\n  \"field_offset_untyped t n \\<equiv> snd (the (field_lookup t n 0))\"\n\ndefinition\n  field_offset :: \"'a::c_type itself \\<Rightarrow> qualified_field_name \\<Rightarrow> nat\"\nwhere\n  \"field_offset t n \\<equiv> field_offset_untyped (typ_uinfo_t TYPE('a)) n\"\n\ndefinition\n  field_ti :: \"'a::c_type itself \\<Rightarrow> qualified_field_name \\<rightharpoonup> 'a typ_info\"\nwhere\n  \"field_ti t n \\<equiv> case_option None (Some \\<circ> fst)\n      (field_lookup (typ_info_t TYPE('a)) n 0)\"\n\n\ndefinition\n  field_size :: \"'a::c_type itself \\<Rightarrow> qualified_field_name \\<Rightarrow> nat\"\nwhere\n  \"field_size t n \\<equiv> size_td (the (field_ti t n))\"\n\ndefinition\n  field_lvalue :: \"'a::c_type ptr \\<Rightarrow> qualified_field_name \\<Rightarrow> addr\" (\"&'(_\\<rightarrow>_')\")\nwhere\n  \"&(p\\<rightarrow>f) \\<equiv> ptr_val (p::'a ptr) + of_nat (field_offset TYPE('a) f)\"\n\ndefinition\n  size_of :: \"'a::c_type itself \\<Rightarrow> nat\" where\n  \"size_of t \\<equiv> size_td (typ_info_t TYPE('a))\"\n\ndefinition\n  norm_bytes :: \"'a::c_type itself \\<Rightarrow> normalisor\" where\n  \"norm_bytes t \\<equiv> norm_tu (export_uinfo (typ_info_t t))\"\n\ndefinition to_bytes_p :: \"'a::c_type \\<Rightarrow> byte list\" where\n  \"to_bytes_p v \\<equiv> to_bytes v (replicate (size_of TYPE('a)) 0)\"\n\nprimrec\n  align_td :: \"'a typ_desc \\<Rightarrow> nat\" and\n  align_td_struct :: \"'a typ_struct \\<Rightarrow> nat\" and\n  align_td_list :: \"'a typ_pair list \\<Rightarrow> nat\" and\n  align_td_pair :: \"'a typ_pair \\<Rightarrow> nat\"\nwhere\n  al0:  \"align_td (TypDesc st nm) = align_td_struct st\"\n\n| al1:  \"align_td_struct (TypScalar n algn d) = algn\"\n| al2:  \"align_td_struct (TypAggregate xs) = align_td_list xs\"\n\n| al3:  \"align_td_list [] = 0\"\n| al4:  \"align_td_list (x#xs) = max (align_td_pair x) (align_td_list xs)\"\n\n| al5:  \"align_td_pair (DTPair t n) = align_td t\"\n\n\ndefinition align_of :: \"'a::c_type itself \\<Rightarrow> nat\" where\n  \"align_of t \\<equiv> 2^(align_td (typ_info_t TYPE('a)))\"\n\ndefinition\n  ptr_add :: \"('a::c_type) ptr \\<Rightarrow> int \\<Rightarrow> 'a ptr\" (infixl \"+\\<^sub>p\" 65)\nwhere\n  \"ptr_add (a :: ('a::c_type) ptr) w \\<equiv>\n     Ptr (ptr_val a + of_int w * of_nat (size_of (TYPE('a))))\"\n\nlemma ptr_add_def':\n  \"ptr_add (Ptr p :: ('a::c_type) ptr) n\n      = (Ptr (p + of_int n * of_nat (size_of TYPE('a))))\"\n  by (cases p, auto simp: ptr_add_def scast_id)\n\ndefinition\n  ptr_sub :: \"('a::c_type) ptr \\<Rightarrow> ('a::c_type) ptr \\<Rightarrow> 32 signed word\" (infixl \"-\\<^sub>p\" 65)\nwhere\n  \"ptr_sub (a :: ('a::c_type) ptr) p \\<equiv>\n     ucast (ptr_val a - ptr_val p) div of_nat (size_of (TYPE('a)))\"\n\ndefinition ptr_aligned :: \"'a::c_type ptr \\<Rightarrow> bool\" where\n  \"ptr_aligned p \\<equiv> align_of TYPE('a) dvd unat (ptr_val (p::'a ptr))\"\n\nprimrec\n  td_set :: \"'a typ_desc \\<Rightarrow> nat \\<Rightarrow> ('a typ_desc \\<times> nat) set\" and\n  td_set_struct :: \"'a typ_struct \\<Rightarrow> nat \\<Rightarrow> ('a typ_desc \\<times> nat) set\" and\n  td_set_list :: \"'a typ_pair list \\<Rightarrow> nat \\<Rightarrow> ('a typ_desc \\<times> nat) set\" and\n  td_set_pair :: \"'a typ_pair \\<Rightarrow> nat \\<Rightarrow> ('a typ_desc \\<times> nat) set\"\nwhere\n  ts0:  \"td_set (TypDesc st nm) m = {(TypDesc st nm,m)} \\<union> td_set_struct st m\"\n\n| ts1:  \"td_set_struct (TypScalar n algn d) m = {}\"\n| ts2:  \"td_set_struct (TypAggregate xs) m = td_set_list xs m\"\n\n| ts3:  \"td_set_list [] m = {}\"\n| ts4:  \"td_set_list (x#xs) m = td_set_pair x m \\<union> td_set_list xs (m + size_td (dt_fst x))\"\n\n| ts5:  \"td_set_pair (DTPair t nm) m = td_set t m\"\n\n\ninstantiation typ_desc :: (type) ord\nbegin\n\ndefinition\n  typ_tag_le_def:  \"s \\<le> (t::'a typ_desc) \\<equiv> (\\<exists>n. (s,n) \\<in> td_set t 0)\"\ndefinition\n  typ_tag_lt_def: \"s < (t::'a typ_desc) \\<equiv> s \\<le> t \\<and> s \\<noteq> t\"\ninstance ..\n\nend\n\n\ndefinition\n  fd_cons_double_update :: \"'a field_desc \\<Rightarrow> bool\"\nwhere\n  \"fd_cons_double_update d \\<equiv>\n      (\\<forall>v bs bs'. length bs = length bs' \\<longrightarrow> field_update d bs (field_update d bs' v) = field_update d bs v)\"\n\ndefinition\n  fd_cons_update_access :: \"'a field_desc \\<Rightarrow> nat \\<Rightarrow> bool\"\nwhere\n  \"fd_cons_update_access d n \\<equiv>\n      (\\<forall>v bs. length bs = n \\<longrightarrow> field_update d (field_access d v bs) v = v)\"\n\ndefinition\n  norm_desc  :: \"'a field_desc \\<Rightarrow> nat \\<Rightarrow> (byte list \\<Rightarrow> byte list)\"\nwhere\n  \"norm_desc d n \\<equiv> \\<lambda>bs. field_access d (field_update d bs undefined) (replicate n 0)\"\n\ndefinition\n  fd_cons_length :: \"'a field_desc \\<Rightarrow> nat \\<Rightarrow> bool\"\nwhere\n  \"fd_cons_length d n \\<equiv> \\<forall>v bs. length bs = n \\<longrightarrow> length (field_access d v bs) = n\"\n\ndefinition\n  fd_cons_access_update :: \"'a field_desc \\<Rightarrow> nat \\<Rightarrow> bool\"\nwhere\n  \"fd_cons_access_update d n \\<equiv> \\<forall>bs bs' v v'. length bs = n \\<longrightarrow>\n      length bs' = n \\<longrightarrow>\n      field_access d (field_update d bs v) bs' = field_access d (field_update d bs v') bs'\"\n\n\ndefinition\n  fd_cons_update_normalise :: \"'a field_desc \\<Rightarrow> nat \\<Rightarrow> bool\"\nwhere\n  \"fd_cons_update_normalise d n  \\<equiv>\n      (\\<forall>v bs. length bs=n \\<longrightarrow> field_update d (norm_desc d n bs) v = field_update d bs v)\"\n\n\ndefinition\n  fd_cons_desc :: \"'a field_desc \\<Rightarrow> nat \\<Rightarrow> bool\"\nwhere\n  \"fd_cons_desc d n \\<equiv> fd_cons_double_update d \\<and>\n      fd_cons_update_access d n \\<and>\n      fd_cons_access_update d n \\<and>\n      fd_cons_length d n\"\n\ndefinition\n  fd_cons :: \"'a typ_info \\<Rightarrow> bool\"\nwhere\n  \"fd_cons t \\<equiv> fd_cons_desc (field_desc t) (size_td t)\"\n\ndefinition\n  fd_cons_struct :: \"'a typ_info_struct \\<Rightarrow> bool\"\nwhere\n  \"fd_cons_struct t \\<equiv> fd_cons_desc (field_desc_struct t) (size_td_struct t)\"\n\ndefinition\n  fd_cons_list :: \"'a typ_info_pair list \\<Rightarrow> bool\"\nwhere\n  \"fd_cons_list t \\<equiv> fd_cons_desc (field_desc_list t) (size_td_list t)\"\n\ndefinition\n  fd_cons_pair :: \"'a typ_info_pair \\<Rightarrow> bool\"\nwhere\n  \"fd_cons_pair t \\<equiv> fd_cons_desc (field_desc_pair t) (size_td_pair t)\"\n\n\ndefinition\n  fa_fu_ind :: \"'a field_desc \\<Rightarrow> 'a field_desc \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow>bool\"\nwhere\n  \"fa_fu_ind d d' n n' \\<equiv> \\<forall>v bs bs'. length bs = n \\<longrightarrow> length bs' = n' \\<longrightarrow>\n      field_access d (field_update d' bs v) bs' = field_access d v bs'\"\n\ndefinition\n  wf_fdp :: \"('a typ_info \\<times> qualified_field_name) set \\<Rightarrow> bool\"\nwhere\n  \"wf_fdp t \\<equiv> \\<forall>x m. (x,m) \\<in> t \\<longrightarrow> (fd_cons x \\<and> (\\<forall>y n. (y,n) \\<in> t \\<and> \\<not> m \\<le> n \\<and> \\<not> n \\<le> m\n      \\<longrightarrow> fu_commutes (field_update (field_desc x)) (field_update (field_desc y)) \\<and>\n          fa_fu_ind (field_desc x) (field_desc y) (size_td y) (size_td x)))\"\n\nlemma wf_fdp_list:\n  \"wf_fdp (xs \\<union> ys) \\<Longrightarrow> wf_fdp xs \\<and> wf_fdp ys\"\n  by (auto simp: wf_fdp_def)\n\n\nprimrec\n  wf_fd :: \"'a typ_info \\<Rightarrow> bool\" and\n  wf_fd_struct :: \"'a typ_info_struct \\<Rightarrow> bool\" and\n  wf_fd_list :: \"'a typ_info_pair list \\<Rightarrow> bool\" and\n  wf_fd_pair :: \"'a typ_info_pair \\<Rightarrow> bool\"\nwhere\n  wffd0:  \"wf_fd (TypDesc ts n) = (wf_fd_struct ts)\"\n\n| wffd1:  \"wf_fd_struct (TypScalar n algn d) = fd_cons_struct (TypScalar n algn d)\"\n| wffd2:  \"wf_fd_struct (TypAggregate ts) = wf_fd_list ts\"\n\n| wffd3:  \"wf_fd_list [] = True\"\n| wffd4:  \"wf_fd_list (x#xs) = (wf_fd_pair x \\<and> wf_fd_list xs \\<and>\n      fu_commutes (update_ti_pair_t x) (update_ti_list_t xs) \\<and>\n      fa_fu_ind (field_desc_pair x) (field_desc_list xs) (size_td_list xs) (size_td_pair x)\\<and>\n      fa_fu_ind (field_desc_list xs) (field_desc_pair x) (size_td_pair x) (size_td_list xs))\"\n\n| wffd5:  \"wf_fd_pair (DTPair x n) = wf_fd x\"\n\n\ndefinition\n  tf_set :: \"'a typ_info \\<Rightarrow> ('a typ_info \\<times> qualified_field_name) set\"\nwhere\n  \"tf_set td \\<equiv> {(s,f) | s f. \\<exists>n. field_lookup td f 0 = Some (s,n)}\"\n\ndefinition\n  tf_set_struct :: \"'a typ_info_struct \\<Rightarrow> ('a typ_info \\<times> qualified_field_name) set\"\nwhere\n  \"tf_set_struct td \\<equiv> {(s,f) | s f. \\<exists>n. field_lookup_struct td f 0 = Some (s,n)}\"\n\ndefinition\n  tf_set_list :: \"'a typ_info_pair list \\<Rightarrow> ('a typ_info \\<times> qualified_field_name) set\"\nwhere\n  \"tf_set_list td \\<equiv> {(s,f) | s f. \\<exists>n. field_lookup_list td f 0 = Some (s,n)}\"\n\ndefinition\n  tf_set_pair :: \"'a typ_info_pair \\<Rightarrow> ('a typ_info \\<times> qualified_field_name) set\"\nwhere\n  \"tf_set_pair td \\<equiv> {(s,f) | s f. \\<exists>n. field_lookup_pair td f 0 = Some (s,n)}\"\n\n\nrecord 'a leaf_desc =\n  lf_fd :: \"'a field_desc\"\n  lf_sz :: nat\n  lf_fn :: qualified_field_name\n\nprimrec\n  lf_set :: \"'a typ_info \\<Rightarrow> qualified_field_name \\<Rightarrow> 'a leaf_desc set\" and\n  lf_set_struct :: \"'a typ_info_struct \\<Rightarrow> qualified_field_name \\<Rightarrow> 'a leaf_desc set\" and\n  lf_set_list :: \"'a typ_info_pair list \\<Rightarrow> qualified_field_name \\<Rightarrow> 'a leaf_desc set\" and\n  lf_set_pair :: \"'a typ_info_pair \\<Rightarrow> qualified_field_name \\<Rightarrow> 'a leaf_desc set\"\nwhere\n  fds0:  \"lf_set (TypDesc st nm) fn = lf_set_struct st fn\"\n\n| fds1:  \"lf_set_struct (TypScalar n algn d) fn = {(\\<lparr> lf_fd = d, lf_sz = n, lf_fn = fn \\<rparr>)}\"\n| fds2:  \"lf_set_struct (TypAggregate xs) fn = lf_set_list xs fn\"\n\n| fds3:  \"lf_set_list [] fn = {}\"\n| fds4:  \"lf_set_list (x#xs) fn = lf_set_pair x fn \\<union> lf_set_list xs fn\"\n\n| fds5:  \"lf_set_pair (DTPair t n) fn = lf_set t (fn@[n])\"\n\n\ndefinition\n  wf_lf :: \"'a leaf_desc set \\<Rightarrow> bool\"\nwhere\n  \"wf_lf D \\<equiv> \\<forall>x. x \\<in> D \\<longrightarrow> (fd_cons_desc (lf_fd x) (lf_sz x) \\<and> (\\<forall>y. y \\<in> D \\<longrightarrow> lf_fn y \\<noteq> lf_fn x\n      \\<longrightarrow> fu_commutes (field_update (lf_fd x)) (field_update (lf_fd y)) \\<and>\n          fa_fu_ind (lf_fd x) (lf_fd y) (lf_sz y) (lf_sz x)))\"\n\ndefinition\n  ti_ind :: \"'a leaf_desc set \\<Rightarrow> 'a leaf_desc set \\<Rightarrow> bool\"\nwhere\n  \"ti_ind X Y \\<equiv> \\<forall>x y. x \\<in> X \\<and> y \\<in> Y \\<longrightarrow> (\n      fu_commutes (field_update (lf_fd x)) (field_update (lf_fd y)) \\<and>\n          fa_fu_ind (lf_fd x) (lf_fd y) (lf_sz y) (lf_sz x) \\<and>\n          fa_fu_ind (lf_fd y) (lf_fd x) (lf_sz x) (lf_sz y))\"\n\n\ndefinition\n  t2d :: \"('a typ_info \\<times> qualified_field_name) \\<Rightarrow> 'a leaf_desc\"\nwhere\n  \"t2d x \\<equiv> \\<lparr> lf_fd = field_desc (fst x), lf_sz = size_td (fst x), lf_fn = snd x\\<rparr>\"\n\n\ndefinition\n  fd_consistent :: \"'a typ_info \\<Rightarrow> bool\"\nwhere\n  \"fd_consistent t \\<equiv> \\<forall>f s n. field_lookup t f 0 = Some (s,n)\n      \\<longrightarrow> fd_cons s\"\n\nclass wf_type = c_type +\n  assumes wf_desc [simp]: \"wf_desc (typ_info_t TYPE('a::c_type))\"\n  assumes wf_size_desc [simp]: \"wf_size_desc (typ_info_t TYPE('a::c_type))\"\n  assumes wf_lf [simp]: \"wf_lf (lf_set (typ_info_t TYPE('a::c_type)) [])\"\n\ndefinition\n  super_update_bs :: \"byte list \\<Rightarrow> byte list \\<Rightarrow> nat \\<Rightarrow> byte list\"\nwhere\n  \"super_update_bs v bs n \\<equiv> take n bs @ v @\n      drop (n + length v) bs\"\n\ndefinition\n  disj_fn :: \"qualified_field_name \\<Rightarrow> qualified_field_name \\<Rightarrow> bool\"\nwhere\n  \"disj_fn s t \\<equiv> \\<not> s \\<le> t \\<and> \\<not> t \\<le> s\"\n\ndefinition\n  fs_path :: \"qualified_field_name list \\<Rightarrow> qualified_field_name set\"\nwhere\n  \"fs_path xs \\<equiv> {x. \\<exists>k. k \\<in> set xs \\<and> x \\<le> k} \\<union> {x. \\<exists>k. k \\<in> set xs \\<and> k \\<le> x}\"\n\ndefinition\n  field_names :: \"'a typ_desc \\<Rightarrow> qualified_field_name set\"\nwhere\n  \"field_names t \\<equiv> {f. field_lookup t f 0 \\<noteq> None}\"\n\ndefinition\n  align_field :: \"'a typ_desc \\<Rightarrow> bool\"\nwhere\n  \"align_field ti \\<equiv> \\<forall>f s n. field_lookup ti f 0 = Some (s,n) \\<longrightarrow>\n      2^(align_td s) dvd n\"\n\nclass mem_type_sans_size = wf_type +\n  assumes upd:\n     \"length bs = size_of TYPE('a) \\<longrightarrow>\n      update_ti_t (typ_info_t TYPE('a::c_type)) bs v\n          = update_ti_t (typ_info_t TYPE('a)) bs w\"\n  assumes align_size_of: \"align_of (TYPE('a::c_type)) dvd size_of TYPE('a)\"\n  assumes align_field: \"align_field (typ_info_t TYPE('a::c_type))\"\n\n\nclass mem_type = mem_type_sans_size +\n  assumes max_size: \"size_of (TYPE('a::c_type)) < addr_card\"\n\n\nprimrec\n  aggregate :: \"'a typ_desc \\<Rightarrow> bool\" and\n  aggregate_struct :: \"'a typ_struct \\<Rightarrow> bool\"\nwhere\n  \"aggregate (TypDesc st tn) = aggregate_struct st\"\n\n| \"aggregate_struct (TypScalar n algn d) = False\"\n| \"aggregate_struct (TypAggregate ts) = True\"\n\nclass simple_mem_type = mem_type +\n  assumes simple_tag: \"\\<not> aggregate (typ_info_t TYPE('a::c_type))\"\n\ndefinition\n  field_of :: \"addr \\<Rightarrow> 'a typ_desc \\<Rightarrow> 'a typ_desc \\<Rightarrow> bool\"\nwhere\n  \"field_of q s t \\<equiv> (s,unat q) \\<in> td_set t 0\"\n\ndefinition\n  field_of_t :: \"'a::c_type ptr \\<Rightarrow> 'b::c_type ptr \\<Rightarrow> bool\"\nwhere\n  \"field_of_t p q \\<equiv> field_of (ptr_val p - ptr_val q) (typ_uinfo_t TYPE('a))\n      (typ_uinfo_t TYPE('b))\"\n\ndefinition\n  h_val :: \"heap_mem \\<Rightarrow> 'a::c_type ptr \\<Rightarrow> 'a\"\nwhere\n  \"h_val h \\<equiv> \\<lambda>p. from_bytes (heap_list h (size_of TYPE ('a))\n      (ptr_val (p::'a ptr)))\"\n\nprimrec\n  heap_update_list :: \"addr \\<Rightarrow> byte list \\<Rightarrow> heap_mem \\<Rightarrow> heap_mem\"\nwhere\n  heap_update_list_base: \"heap_update_list p [] h = h\"\n| heap_update_list_rec:\n  \"heap_update_list p (x#xs) h = heap_update_list (p + 1) xs (h(p:= x))\"\n\ntype_synonym 'a typ_heap_g = \"'a ptr \\<Rightarrow> 'a\"\n\n(* FIXME: now redundant with h_val *)\ndefinition\n  lift :: \"heap_mem \\<Rightarrow> 'a::c_type typ_heap_g\"\nwhere\n  \"lift h \\<equiv> h_val h\"\n\ndefinition\n  heap_update :: \"'a::c_type ptr \\<Rightarrow> 'a \\<Rightarrow> heap_mem \\<Rightarrow> heap_mem\"\nwhere\n  \"heap_update p v h \\<equiv> heap_update_list (ptr_val p) (to_bytes v (heap_list h (size_of TYPE('a)) (ptr_val p))) h\"\n\nfun\n  fold_td' :: \"(typ_name \\<Rightarrow> ('a \\<times> field_name) list \\<Rightarrow> 'a) \\<times> 'a typ_desc \\<Rightarrow> 'a\"\nwhere\nfot0: \"fold_td' (f,TypDesc st nm) = (case st of\n           TypScalar n algn d \\<Rightarrow> d |\n           TypAggregate ts \\<Rightarrow> f nm (map (\\<lambda>x. case x of DTPair t n \\<Rightarrow> (fold_td' (f,t),n)) ts))\"\n\n\ndefinition\n  fold_td :: \"(typ_name \\<Rightarrow> ('a \\<times> field_name) list \\<Rightarrow> 'a) \\<Rightarrow> 'a typ_desc \\<Rightarrow> 'a\"\nwhere\n  \"fold_td \\<equiv> \\<lambda>f t. fold_td' (f,t)\"\n\ndeclare fold_td_def [simp add]\n\ndefinition\n  fold_td_struct :: \"typ_name \\<Rightarrow> (typ_name \\<Rightarrow> ('a \\<times> field_name) list \\<Rightarrow> 'a) \\<Rightarrow> 'a typ_struct \\<Rightarrow> 'a\"\nwhere\n  \"fold_td_struct tn f st \\<equiv> (case st of\n           TypScalar n algn d \\<Rightarrow> d |\n           TypAggregate ts \\<Rightarrow> f tn (map (\\<lambda>x. case x of DTPair t n \\<Rightarrow> (fold_td' (f,t),n)) ts))\"\n\ndeclare fold_td_struct_def [simp add]\n\ndefinition\n  fold_td_list :: \"typ_name \\<Rightarrow> (typ_name \\<Rightarrow> ('a \\<times> field_name) list \\<Rightarrow> 'a) \\<Rightarrow> 'a typ_pair list \\<Rightarrow> 'a\"\nwhere\n  \"fold_td_list tn f ts \\<equiv> f tn (map (\\<lambda>x. case x of DTPair t n \\<Rightarrow> (fold_td' (f,t),n)) ts)\"\n\ndeclare fold_td_list_def [simp add]\n\ndefinition\n  fold_td_pair :: \"(typ_name \\<Rightarrow> ('a \\<times> field_name) list \\<Rightarrow> 'a) \\<Rightarrow> 'a typ_pair \\<Rightarrow> 'a\"\nwhere\n  \"fold_td_pair f x \\<equiv> (case x of DTPair t n \\<Rightarrow> fold_td' (f,t))\"\n\ndeclare fold_td_pair_def [simp add]\n\nfun\n  map_td' :: \"(nat \\<Rightarrow> nat \\<Rightarrow> 'a \\<Rightarrow> 'b) \\<times> 'a typ_desc \\<Rightarrow> 'b typ_desc\"\nwhere\n  \"map_td' (f,TypDesc st nm) = (TypDesc (case st of\n           TypScalar n algn d \\<Rightarrow> TypScalar n algn (f n algn d) |\n           TypAggregate ts \\<Rightarrow> TypAggregate (map (\\<lambda>x. case x of DTPair t n \\<Rightarrow> DTPair (map_td' (f,t)) n) ts)) nm)\"\n\ndefinition\n  tnSum :: \"typ_name \\<Rightarrow> (nat \\<times> field_name) list \\<Rightarrow> nat\"\nwhere\n  \"tnSum \\<equiv> \\<lambda>tn ts. foldr (op + o fst) ts 0\"\n\ndefinition\n  tnMax :: \"typ_name \\<Rightarrow> (nat \\<times> field_name) list \\<Rightarrow> nat\"\nwhere\n  \"tnMax \\<equiv> \\<lambda>tn ts. foldr (\\<lambda>x y. max (fst x) y) ts 0\"\n\ndefinition\n  wfd :: \"typ_name \\<Rightarrow> (bool \\<times> field_name) list \\<Rightarrow> bool\"\nwhere\n  \"wfd \\<equiv> \\<lambda>tn ts. distinct (map snd ts) \\<and> foldr (op \\<and>) (map fst ts) True\"\n\ndefinition\n  wfsd :: \"typ_name \\<Rightarrow> (bool \\<times> field_name) list \\<Rightarrow> bool\"\nwhere\n  \"wfsd \\<equiv> \\<lambda>tn ts. ts \\<noteq> [] \\<and> foldr (op \\<and>) (map fst ts) True\"\n\nend\n", "meta": {"author": "crizkallah", "repo": "checker-verification", "sha": "cd5101e57ef70dcdd1680db2de2f08521605bd7c", "save_path": "github-repos/isabelle/crizkallah-checker-verification", "path": "github-repos/isabelle/crizkallah-checker-verification/checker-verification-cd5101e57ef70dcdd1680db2de2f08521605bd7c/autocorres-1.0/c-parser/umm_heap/CTypesDefs.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6187804337438501, "lm_q2_score": 0.42250463481418826, "lm_q1q2_score": 0.26143760118911036}}
{"text": "theory Analyze_SQRL_Shorewall\nimports \n  Iptables_Semantics.Parser\nbegin\n\n\nsection\\<open>Example: SQRL Shorewall\\<close>\n\n\nparse_iptables_save SQRL_fw=\"iptables-saveakachan\"\n\n\nthm SQRL_fw_def\nthm SQRL_fw_FORWARD_default_policy_def\n\nvalue[code] \"map (\\<lambda>(c,rs). (c, map (quote_rewrite \\<circ> common_primitive_rule_toString) rs)) SQRL_fw\"\n\nlemma \"Semantics_Goto.terminal_chain (the ((map_of_string_ipv4 SQRL_fw) ''smurflog''))\" by eval\nlemma \"Semantics_Goto.terminal_chain (the ((map_of_string_ipv4 SQRL_fw) ''logflags''))\" by eval\nlemma \"Semantics_Goto.terminal_chain (the ((map_of_string_ipv4 SQRL_fw) ''reject''))\" by eval\n\n(*12.942s*)\nvalue[code] \"Semantics_Goto.rewrite_Goto SQRL_fw\"\n\ndefinition \"unfolded = unfold_ruleset_FORWARD SQRL_fw_FORWARD_default_policy (map_of_string_ipv4 (Semantics_Goto.rewrite_Goto SQRL_fw))\"\n\n(*\n(*2174.839s elapsed time, 3308.410s cpu time, 161.539s GC time*)\nvalue[code] \"unfolded\"*)\n(*0.561s*)\nvalue[code] \"let x = unfolded in ()\" (*pretty printing is slow, not the unfolding! ML forces evaluation of unfolded!*)\n(*39.149s*)\nvalue[code] \"map (quote_rewrite \\<circ> common_primitive_rule_toString) (unfolded)\"\n(*2.871s*)\nlemma \"length unfolded = 2649\" by eval\n\n\n(*17.554s*)\nvalue[code] \"map (quote_rewrite \\<circ> common_primitive_rule_toString) (upper_closure unfolded)\"\nlemma \"length (upper_closure unfolded) = 1986\" by eval\n\n\nvalue[code] \"upper_closure (packet_assume_new unfolded)\"\n\n(*28.550s*)\nlemma \"length (lower_closure unfolded) = 5715\" by eval\n\nlemma \"check_simple_fw_preconditions (upper_closure unfolded) = False\" by eval\nlemma \"\\<forall>m \\<in> get_match`set (upper_closure (packet_assume_new unfolded)). normalized_nnf_match m\" by eval\n\nlemma \"\\<forall>m \\<in> get_match`set (optimize_matches abstract_for_simple_firewall (upper_closure (packet_assume_new unfolded))). normalized_nnf_match m\" by eval\n\nlemma \"check_simple_fw_preconditions (upper_closure (optimize_matches abstract_for_simple_firewall (upper_closure (packet_assume_new unfolded))))\" by eval\nlemma \"length (to_simple_firewall (upper_closure (optimize_matches abstract_for_simple_firewall (upper_closure (packet_assume_new unfolded))))) = 1389\" by eval\n(*22.240s*)\nvalue[code] \"map simple_rule_ipv4_toString (to_simple_firewall (upper_closure (optimize_matches abstract_for_simple_firewall (upper_closure (packet_assume_new unfolded)))))\"\n\n(*25.480s*)\nvalue[code] \"map ipv4addr_wordinterval_toString (getParts (to_simple_firewall (upper_closure (optimize_matches abstract_for_simple_firewall (upper_closure (packet_assume_new unfolded))))))\"\n\n(*43.702s*)\nlemma \"length (to_simple_firewall (lower_closure (optimize_matches abstract_for_simple_firewall (lower_closure (packet_assume_new unfolded))))) = 5120\" by eval\n\n(*71.518s*)\nvalue[code] \"length (remdups_rev (to_simple_firewall (lower_closure (optimize_matches abstract_for_simple_firewall (lower_closure (packet_assume_new unfolded))))))\" (*not smaller*)\n\nvalue[code] \"map ipv4addr_wordinterval_toString (getParts (to_simple_firewall (lower_closure (optimize_matches abstract_for_simple_firewall (lower_closure (packet_assume_new unfolded))))))\"\n\nlemma \"simple_fw_valid (to_simple_firewall (lower_closure (optimize_matches abstract_for_simple_firewall (lower_closure (packet_assume_new unfolded)))))\" by eval\nlemma \"simple_fw_valid (to_simple_firewall (upper_closure (optimize_matches abstract_for_simple_firewall (lower_closure (packet_assume_new unfolded)))))\" by eval\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Iptables_Semantics/Examples/SQRL_Shorewall/Analyze_SQRL_Shorewall.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982315512488, "lm_q2_score": 0.4035668537353746, "lm_q1q2_score": 0.26142989416247714}}
{"text": "(*\n * Copyright 2016, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the GNU General Public License version 2. Note that NO WARRANTY is provided.\n * See \"LICENSE_GPLv2.txt\" for details.\n *\n * @TAG(NICTA_GPL)\n *)\n\ntheory Cogent\nimports Util\nbegin\n\n\nsection {* Utility lemmas, probably should be in a separate theory *}\n\nlemma map_snd_app [simp]: \nshows \"map (snd \\<circ> (\\<lambda> (a , b). (a , f b))) l  =  map (f \\<circ> snd) l\" \nby (induct l, auto)\n\nlemma map_snd_ignore [simp]: \nshows \"map (snd \\<circ> (\\<lambda> (a , b). (f a , b))) l  =  map (snd) l\" \nby (induct l, auto)\n\nlemma map_fst_app [simp]:\nshows \"map (fst \\<circ> (\\<lambda> (a , b). (f a , b))) l =  map (f \\<circ> fst) l\" \nby (induct l, auto)\n\nlemma map_fst_ignore [simp]:\nshows \"map (fst \\<circ> (\\<lambda> (a , b). (a , f b))) l = map fst l\" \nby (induct l, auto)\n\nlemma map_fst_update:\nassumes \"ts ! f = (t, x)\"\nand     \"f < length ts\"\nshows \"map fst (ts[f := (t,x')]) = map fst ts\"\nproof -\nfrom assms have  \"map fst ts ! f = t\" by (clarsimp)\nthen show ?thesis by (auto simp add: map_update)\nqed\n\nlemma map_zip [simp]:\nshows \"map (\\<lambda> (a , b). (f a, g b)) (zip as bs) = zip (map f as) (map g bs)\"\nby (induct as arbitrary:bs, simp, case_tac bs, simp_all)\n\nlemma distinct_fst:\nassumes \"distinct (map fst ls)\"\nand     \"(a, b) \\<in> set ls\"\nand     \"(a, b') \\<in> set ls\"\nshows   \"b = b'\"\nusing assms\n  apply (clarsimp simp: set_conv_nth distinct_conv_nth)\n  apply (drule_tac x = i in spec, simp)\n  apply (drule_tac x = ia in spec, simp)\n  apply (case_tac \"ls ! i\")\n  apply (case_tac \"ls ! ia\")\n  apply (auto)\ndone\n\nlemma map_filter_fst:\nshows \"map (\\<lambda>(c, t). (c, f t)) [x\\<leftarrow>ts . P (fst x)]\n     = [x \\<leftarrow> map (\\<lambda>(c,t). (c, f t)) ts. P (fst x)]\"\nproof -\nhave \"(\\<lambda>x. P (fst x)) \\<circ> (\\<lambda>(c, t). (c, f t)) = (\\<lambda>x. P (fst x))\"\n  by (rule ext, case_tac x, simp)\nthen show ?thesis by (simp add: filter_map)\nqed\n\nlemma set_subset_map:\nassumes \"set a \\<subseteq> set b\"\nshows   \"set (map f a) \\<subseteq> set (map f b)\"\nusing assms by auto\n\n\nlemma prod_in_set:\nassumes \"(a, b) \\<in> set l\"\nshows   \"a \\<in> set (map fst l)\"\nand     \"b \\<in> set (map snd l)\"\nusing assms by (force intro: imageI)+ \n\nlemma filter_fst_ignore:\nshows \"filter (\\<lambda> x. P (fst x)) (map (\\<lambda>(a,b). (a, f b)) ls) \n     = map (\\<lambda>(a,b). (a, f b)) (filter (\\<lambda> x. P (fst x)) ls)\"\nby (induct_tac ls, auto)\n\nsection {* Terms and Types of Cogent *}\n\ntype_synonym name = string\n\ntype_synonym index = nat\n\ntype_synonym field = nat\n\ndatatype num_type = U8 | U16 | U32 | U64 \n\ndatatype prim_type = Num num_type | Bool | String\n\ndatatype sigil = ReadOnly | Writable | Unboxed\n\n\ndatatype prim_op \n  = Plus num_type \n  | Minus num_type \n  | Times num_type \n  | Divide num_type \n  | Mod num_type\n  | Not | And | Or\n  | Gt num_type\n  | Lt num_type \n  | Le num_type \n  | Ge num_type \n  | Eq prim_type \n  | NEq prim_type\n  | BitAnd num_type \n  | BitOr num_type \n  | BitXor num_type \n  | LShift num_type\n  | RShift num_type\n  | Complement num_type\n\n\ndatatype type = TVar index\n              | TVarBang index\n              | TCon name \"type list\" sigil\n              | TFun type type \n              | TPrim prim_type\n              | TSum \"(name \\<times> type) list\"\n              | TProduct \"type\" \"type\"\n              | TRecord \"(type \\<times> bool) list\" sigil\n              | TUnit\n\ndatatype lit = LBool bool\n             | LU8 \"8 word\"\n             | LU16 \"16 word\"\n             | LU32 \"32 word\"\n             | LU64 \"64 word\"\n             (* etc *)\n\nfun cast_to :: \"num_type \\<Rightarrow> lit \\<Rightarrow> lit option\" where\n  \"cast_to U8  (LU8  x) = Some (LU8 x)\"\n| \"cast_to U16 (LU8  x) = Some (LU16 (ucast x))\"\n| \"cast_to U16 (LU16 x) = Some (LU16 x)\"\n| \"cast_to U32 (LU8  x) = Some (LU32 (ucast x))\"\n| \"cast_to U32 (LU16 x) = Some (LU32 (ucast x))\"\n| \"cast_to U32 (LU32 x) = Some (LU32 x)\"\n| \"cast_to U64 (LU8  x) = Some (LU64 (ucast x))\"\n| \"cast_to U64 (LU16 x) = Some (LU64 (ucast x))\"\n| \"cast_to U64 (LU32 x) = Some (LU64 (ucast x))\"\n| \"cast_to U64 (LU64 x) = Some (LU64 x)\"\n\ndatatype 'f expr = Var index\n                 | AFun 'f  \"type list\"\n                 | Fun \"'f expr\" \"type list\"\n                 | Prim prim_op \"'f expr list\"\n                 | App \"'f expr\" \"'f expr\"\n                 | Con \"(name \\<times> type) list\" name \"'f expr\" (* promotes \"inlined\" *)\n                 | Promote \"(name \\<times> type) list\" \"'f expr\"\n                 | Struct \"type list\" \"'f expr list\"\n                 | Member \"'f expr\" field \n                 | Unit\n                 | Lit lit\n                 | Cast num_type \"'f expr\"\n                 | Tuple \"'f expr\" \"'f expr\"\n                 | Put \"'f expr\" field \"'f expr\"\n                 | Let \"'f expr\" \"'f expr\"\n                 | LetBang \"index set\" \"'f expr\" \"'f expr\"\n                 | Case \"'f expr\" name \"'f expr\" \"'f expr\"\n                 | Esac \"'f expr\"\n                 | If \"'f expr\" \"'f expr\" \"'f expr\"\n                 | Take \"'f expr\" field \"'f expr\"\n                 | Split \"'f expr\" \"'f expr\"\n\ndatatype kind_comp = D | S | E\n\ntype_synonym kind = \"kind_comp set\"\n\ntype_synonym poly_type = \"kind list \\<times> type \\<times> type\"\n\ntype_synonym 'v env  = \"'v list\"\n\ntype_synonym 'a substitution = \"'a list\"\n\nsection {* Kinding rules *}\n\nprimrec sigil_kind :: \"sigil \\<Rightarrow> kind\" where \n  \"sigil_kind ReadOnly  = {D,S}\"\n| \"sigil_kind Writable  = {E}\"\n| \"sigil_kind Unboxed   = {D,S,E}\"\n\n\n\ninductive kinding        :: \"kind env \\<Rightarrow> type               \\<Rightarrow> kind \\<Rightarrow> bool\" (\"_ \\<turnstile>  _ :\\<kappa>  _\" [30,0,20] 60) \n      and kinding_all    :: \"kind env \\<Rightarrow> type list          \\<Rightarrow> kind \\<Rightarrow> bool\" (\"_ \\<turnstile>* _ :\\<kappa>  _\" [30,0,20] 60) \n      and kinding_record :: \"kind env \\<Rightarrow> (type \\<times> bool) list \\<Rightarrow> kind \\<Rightarrow> bool\" (\"_ \\<turnstile>* _ :\\<kappa>r _\" [30,0,20] 60) where\n\n   kind_tvar    : \"\\<lbrakk> k \\<subseteq> (K ! i) ; i < length K \\<rbrakk> \\<Longrightarrow> K \\<turnstile> TVar i :\\<kappa> k\"\n|  kind_tvarb   : \"\\<lbrakk> k \\<subseteq> {D, S} ; i < length K \\<rbrakk> \\<Longrightarrow> K \\<turnstile> TVarBang i :\\<kappa> k\"\n|  kind_tcon    : \"\\<lbrakk> K \\<turnstile>* ts :\\<kappa> k ; k \\<subseteq> sigil_kind s \\<rbrakk> \\<Longrightarrow> K \\<turnstile> TCon n ts s :\\<kappa> k\"\n|  kind_tfun    : \"\\<lbrakk> K \\<turnstile> a :\\<kappa> ka ; K \\<turnstile> b :\\<kappa> kb \\<rbrakk> \\<Longrightarrow> K \\<turnstile> TFun a b :\\<kappa> k\"\n|  kind_tprim   : \"K \\<turnstile> TPrim p :\\<kappa> k\"\n|  kind_tsum    : \"\\<lbrakk> distinct (map fst ts); K \\<turnstile>* map snd ts :\\<kappa> k \\<rbrakk> \\<Longrightarrow> K \\<turnstile> TSum ts :\\<kappa> k\"\n|  kind_tprod   : \"\\<lbrakk> K \\<turnstile> t :\\<kappa> k; K \\<turnstile> u :\\<kappa> k \\<rbrakk>  \\<Longrightarrow> K \\<turnstile> TProduct t u :\\<kappa> k\"\n|  kind_trec    : \"\\<lbrakk> K \\<turnstile>* ts :\\<kappa>r k ; k \\<subseteq> sigil_kind s \\<rbrakk> \\<Longrightarrow> K \\<turnstile> TRecord ts s :\\<kappa> k\"\n|  kind_tunit   : \"K \\<turnstile> TUnit :\\<kappa> k\"\n\n|  kind_all_empty : \"K \\<turnstile>* [] :\\<kappa> k\"\n|  kind_all_cons  : \"\\<lbrakk> K \\<turnstile> x :\\<kappa> k ; K \\<turnstile>* xs :\\<kappa> k \\<rbrakk> \\<Longrightarrow> K \\<turnstile>* (x # xs) :\\<kappa> k\"\n\n|  kind_record_empty : \"K \\<turnstile>* [] :\\<kappa>r k\"\n|  kind_record_cons1 : \"\\<lbrakk> K \\<turnstile> x :\\<kappa> k  ; K \\<turnstile>* xs :\\<kappa>r k \\<rbrakk> \\<Longrightarrow> K \\<turnstile>* ((x,False) # xs) :\\<kappa>r k\"\n|  kind_record_cons2 : \"\\<lbrakk> K \\<turnstile> x :\\<kappa> k' ; K \\<turnstile>* xs :\\<kappa>r k \\<rbrakk> \\<Longrightarrow> K \\<turnstile>* ((x,True)  # xs) :\\<kappa>r k\"\n\ninductive_cases kind_tvarE         [elim] : \"K \\<turnstile> TVar i :\\<kappa> k\"\ninductive_cases kind_tvarbE        [elim] : \"K \\<turnstile> TVarBang i :\\<kappa> k\"\ninductive_cases kind_tconE         [elim] : \"K \\<turnstile> TCon n ts s :\\<kappa> k\"\ninductive_cases kind_tfunE         [elim] : \"K \\<turnstile> TFun a b :\\<kappa> k\"\ninductive_cases kind_tsumE         [elim] : \"K \\<turnstile> TSum ts :\\<kappa> k\"\ninductive_cases kind_tprodE        [elim] : \"K \\<turnstile> TProduct t u :\\<kappa> k\"\ninductive_cases kind_trecE         [elim] : \"K \\<turnstile> TRecord ts s :\\<kappa> k\"\ninductive_cases kind_all_emptyE    [elim] : \"K \\<turnstile>* [] :\\<kappa> k\"\ninductive_cases kind_all_consE     [elim] : \"K \\<turnstile>* (x # xs) :\\<kappa> k\"\ninductive_cases kind_record_emptyE [elim] : \"K \\<turnstile>* [] :\\<kappa>r k\"\ninductive_cases kind_record_consE  [elim] : \"K \\<turnstile>* (x # xs) :\\<kappa>r k\"\ninductive_cases kind_record_cons1E [elim] : \"K \\<turnstile>* ((x,False) # xs) :\\<kappa>r k\"\ninductive_cases kind_record_cons2E [elim] : \"K \\<turnstile>* ((x,True)  # xs) :\\<kappa>r k\"\n\n\ndefinition type_wellformed :: \"kind env \\<Rightarrow> type \\<Rightarrow> bool\" (\"_ \\<turnstile> _ wellformed\" [30,20] 60) where\n  \"K \\<turnstile> \\<tau> wellformed \\<equiv> \\<exists>k. K \\<turnstile> \\<tau> :\\<kappa> k\"  \n\ndeclare type_wellformed_def [simp]\n\n\ndefinition type_wellformed_all :: \"kind env \\<Rightarrow> type list \\<Rightarrow> bool\" (\"_ \\<turnstile>* _ wellformed\"[30,20]60) where\n  \"K \\<turnstile>* \\<tau>s wellformed \\<equiv> \\<exists>k. K \\<turnstile>* \\<tau>s :\\<kappa> k\"  \n\ndeclare type_wellformed_all_def [simp]\n\ndefinition proc_ctx_wellformed :: \"('f \\<Rightarrow> poly_type) \\<Rightarrow> bool\" where\n  \"proc_ctx_wellformed \\<Xi> = (\\<forall> f. let (K, \\<tau>i, \\<tau>o) = \\<Xi> f in K \\<turnstile> TFun \\<tau>i \\<tau>o wellformed )\"\n\nsection {* Observation and type instantiation *}\n\nprimrec bang_sigil :: \"sigil \\<Rightarrow> sigil\" where \n  \"bang_sigil (ReadOnly)   = ReadOnly\"\n| \"bang_sigil (Writable)   = ReadOnly\"\n| \"bang_sigil (Unboxed)    = Unboxed\"\n\nfun bang :: \"type \\<Rightarrow> type\" where \n  \"bang (TVar i)       = TVarBang i\"\n| \"bang (TVarBang i)   = TVarBang i\"\n| \"bang (TCon n ts s)  = TCon n (map bang ts) (bang_sigil s)\"\n| \"bang (TFun a b)     = TFun a b\"\n| \"bang (TPrim p)      = TPrim p\"\n| \"bang (TSum ps)      = TSum (map (\\<lambda> (c, t). (c, bang t)) ps)\"\n| \"bang (TProduct t u) = TProduct (bang t) (bang u)\"\n| \"bang (TRecord ts s) = TRecord (map (\\<lambda> (t, b). (bang t, b)) ts) (bang_sigil s)\"\n| \"bang (TUnit)        = TUnit\"\n\n\nfun instantiate :: \"type substitution \\<Rightarrow> type \\<Rightarrow> type\" where \n  \"instantiate \\<delta> (TVar i)       = (if i < length \\<delta> then \\<delta> ! i else TVar i)\"\n| \"instantiate \\<delta> (TVarBang i)   = (if i < length \\<delta> then bang (\\<delta> ! i) else TVarBang i)\"\n| \"instantiate \\<delta> (TCon n ts s)  = TCon n (map (instantiate \\<delta>) ts) s\"\n| \"instantiate \\<delta> (TFun a b)     = TFun (instantiate \\<delta> a) (instantiate \\<delta> b)\"\n| \"instantiate \\<delta> (TPrim p)      = TPrim p\"\n| \"instantiate \\<delta> (TSum ps)      = TSum (map (\\<lambda> (c, t). (c, instantiate \\<delta> t)) ps)\"\n| \"instantiate \\<delta> (TProduct t u) = TProduct (instantiate \\<delta> t) (instantiate \\<delta> u)\"\n| \"instantiate \\<delta> (TRecord ts s) = TRecord (map (\\<lambda> (t, b). (instantiate \\<delta> t, b)) ts) s\"\n| \"instantiate \\<delta> (TUnit)        = TUnit\"\n\nfun specialise :: \"type substitution \\<Rightarrow> 'f expr \\<Rightarrow> 'f expr\" where \n  \"specialise \\<delta> (Var i)           = Var i\"\n| \"specialise \\<delta> (Fun f ts)        = Fun f (map (instantiate \\<delta>) ts)\"\n| \"specialise \\<delta> (AFun f ts)       = AFun f (map (instantiate \\<delta>) ts)\"\n| \"specialise \\<delta> (Prim p es)       = Prim p (map (specialise \\<delta>) es)\"\n| \"specialise \\<delta> (App a b)         = App (specialise \\<delta> a) (specialise \\<delta> b)\"\n| \"specialise \\<delta> (Con as t e)      = Con (map (\\<lambda> (c,t). (c, instantiate \\<delta> t)) as) t (specialise \\<delta> e)\" \n| \"specialise \\<delta> (Promote as e)    = Promote (map (\\<lambda> (c,t). (c, instantiate \\<delta> t)) as) (specialise \\<delta> e)\"\n| \"specialise \\<delta> (Struct ts vs)    = Struct (map (instantiate \\<delta>) ts) (map (specialise \\<delta>) vs)\"\n| \"specialise \\<delta> (Member v f)      = Member (specialise \\<delta> v) f\"\n| \"specialise \\<delta> (Unit)            = Unit\"\n| \"specialise \\<delta> (Cast t e)        = Cast t (specialise \\<delta> e)\"\n| \"specialise \\<delta> (Lit v)           = Lit v\"\n| \"specialise \\<delta> (Tuple a b)       = Tuple (specialise \\<delta> a) (specialise \\<delta> b)\"\n| \"specialise \\<delta> (Put e f e')      = Put (specialise \\<delta> e) f (specialise \\<delta> e')\"\n| \"specialise \\<delta> (Let e e')        = Let (specialise \\<delta> e) (specialise \\<delta> e')\"\n| \"specialise \\<delta> (LetBang vs e e') = LetBang vs (specialise \\<delta> e) (specialise \\<delta> e')\"\n| \"specialise \\<delta> (Case e t a b)    = Case (specialise \\<delta> e) t (specialise \\<delta> a) (specialise \\<delta> b)\"\n| \"specialise \\<delta> (Esac e)          = Esac (specialise \\<delta> e)\"\n| \"specialise \\<delta> (If c t e)        = If (specialise \\<delta> c) (specialise \\<delta> t) (specialise \\<delta> e)\"\n| \"specialise \\<delta> (Take e f e')     = Take (specialise \\<delta> e) f (specialise \\<delta> e')\"\n| \"specialise \\<delta> (Split v va)      = Split (specialise \\<delta> v) (specialise \\<delta> va)\"\n\n\nsection {* Contexts *}\n \ntype_synonym ctx = \"type option env\"\n\ndefinition empty :: \"nat \\<Rightarrow> ctx\" where \n  \"empty \\<equiv> (\\<lambda> x. replicate x None)\"\n\ndefinition singleton :: \"nat \\<Rightarrow> index \\<Rightarrow> type \\<Rightarrow> ctx\" where \n  \"singleton n i t \\<equiv> (empty n)[i := Some t]\"\n\ndeclare singleton_def [simp]\ndefinition instantiate_ctx :: \"type substitution \\<Rightarrow> ctx \\<Rightarrow> ctx\" where\n  \"instantiate_ctx \\<delta> \\<Gamma> \\<equiv> map (map_option (instantiate \\<delta>)) \\<Gamma>\"\n\ninductive split_comp :: \"kind env \\<Rightarrow> type option \\<Rightarrow> type option \\<Rightarrow> type option \\<Rightarrow> bool\"\n          (\"_ \\<turnstile> _ \\<leadsto> _ \\<parallel> _\" [30,0,0,20] 60) where\n  none  : \"K \\<turnstile> None \\<leadsto> None \\<parallel> None\"\n| left  : \"\\<lbrakk> K \\<turnstile> t :\\<kappa> k         \\<rbrakk> \\<Longrightarrow> K \\<turnstile> Some t \\<leadsto> Some t \\<parallel> None\"\n| right : \"\\<lbrakk> K \\<turnstile> t :\\<kappa> k         \\<rbrakk> \\<Longrightarrow> K \\<turnstile> Some t \\<leadsto> None   \\<parallel> (Some t)\"\n| share : \"\\<lbrakk> K \\<turnstile> t :\\<kappa> k ; S \\<in> k \\<rbrakk> \\<Longrightarrow> K \\<turnstile> Some t \\<leadsto> Some t \\<parallel> Some t\" \n\ninductive split :: \"kind env \\<Rightarrow> ctx \\<Rightarrow> ctx \\<Rightarrow> ctx \\<Rightarrow> bool\" (\"_ \\<turnstile> _ \\<leadsto> _ | _\" [30,0,0,20] 60) where\n  split_empty : \"K \\<turnstile> [] \\<leadsto> [] | []\"\n| split_cons  : \"\\<lbrakk> K \\<turnstile> x \\<leadsto> a \\<parallel> b ; K \\<turnstile> xs \\<leadsto> as | bs \\<rbrakk> \\<Longrightarrow> K \\<turnstile> (x # xs) \\<leadsto> (a # as) | (b # bs)\"\n\ndefinition pred :: \"nat \\<Rightarrow> nat\" where\n  \"pred n \\<equiv> (case n of Suc n' \\<Rightarrow> n')\"\n\ninductive split_bang :: \"kind env \\<Rightarrow> index set \\<Rightarrow> ctx \\<Rightarrow> ctx \\<Rightarrow> ctx \\<Rightarrow> bool\" where \n  split_bang_empty : \"split_bang K is [] [] []\"\n| split_bang_cons  : \"\\<lbrakk> 0 \\<notin> is \n                      ; K \\<turnstile> x \\<leadsto> a \\<parallel> b\n                      ; split_bang K (pred ` is) xs as bs\n                      \\<rbrakk>  \\<Longrightarrow> split_bang K is (x # xs) (a # as) (b # bs) \"\n| split_bang_bang  : \"\\<lbrakk> 0 \\<in> is \n                      ; is' = Set.remove (0 :: index) is\n                      ; split_bang K (pred ` is') xs as bs\n                      \\<rbrakk>  \\<Longrightarrow> split_bang K is (Some x # xs) (Some (bang x) # as) (Some x # bs)\"\n\n\ninductive weakening_comp :: \"kind env \\<Rightarrow> type option \\<Rightarrow> type option \\<Rightarrow> bool\" where\n  none : \"weakening_comp K None None\"\n| keep : \"\\<lbrakk> K \\<turnstile> t :\\<kappa> k \\<rbrakk>         \\<Longrightarrow> weakening_comp K (Some t) (Some t)\"\n| drop : \"\\<lbrakk> K \\<turnstile> t :\\<kappa> k ; D \\<in> k \\<rbrakk> \\<Longrightarrow> weakening_comp K (Some t) None\"\n\ndefinition weakening :: \"kind env \\<Rightarrow> ctx \\<Rightarrow> ctx \\<Rightarrow> bool\" (\"_ \\<turnstile> _ \\<leadsto>w _\" [30,0,20] 60) where \n  \"weakening \\<equiv> (\\<lambda>K. list_all2 (weakening_comp K))\"\n\ndefinition is_consumed :: \"kind env \\<Rightarrow> ctx \\<Rightarrow> bool\" (\"_ \\<turnstile> _ consumed\" [30,20] 60 ) where  \n  \"K \\<turnstile> \\<Gamma> consumed \\<equiv> K \\<turnstile> \\<Gamma> \\<leadsto>w empty (length \\<Gamma>)\" \n\ndeclare is_consumed_def [simp]\n\nsection {* Built-in types *}\n\nprimrec prim_op_type :: \"prim_op \\<Rightarrow> prim_type list \\<times> prim_type\" where \n  \"prim_op_type (Plus t)   = ([Num t, Num t], Num t)\"\n| \"prim_op_type (Times t)  = ([Num t, Num t], Num t)\"\n| \"prim_op_type (Minus t)  = ([Num t, Num t], Num t)\"\n| \"prim_op_type (Divide t) = ([Num t, Num t], Num t)\"\n| \"prim_op_type (Mod t)    = ([Num t, Num t], Num t)\"\n| \"prim_op_type (BitAnd t) = ([Num t, Num t], Num t)\"\n| \"prim_op_type (BitOr t)  = ([Num t, Num t], Num t)\"\n| \"prim_op_type (BitXor t) = ([Num t, Num t], Num t)\"\n| \"prim_op_type (LShift t) = ([Num t, Num t], Num t)\"\n| \"prim_op_type (RShift t) = ([Num t, Num t], Num t)\"\n| \"prim_op_type (Complement t) = ([Num t], Num t)\"\n| \"prim_op_type (Gt t)     = ([Num t, Num t], Bool )\"\n| \"prim_op_type (Lt t)     = ([Num t, Num t], Bool )\"\n| \"prim_op_type (Le t)     = ([Num t, Num t], Bool )\"\n| \"prim_op_type (Ge t)     = ([Num t, Num t], Bool )\"\n| \"prim_op_type (Eq t)     = ([t    , t    ], Bool )\"\n| \"prim_op_type (NEq t)    = ([t    , t    ], Bool )\"\n| \"prim_op_type (And)      = ([Bool , Bool ], Bool )\"\n| \"prim_op_type (Or)       = ([Bool , Bool ], Bool )\"\n| \"prim_op_type (Not)      = ([Bool],         Bool )\"\n\nprimrec lit_type :: \"lit \\<Rightarrow> prim_type\" where \n  \"lit_type (LBool _) = Bool\" \n| \"lit_type (LU8  _)  = Num U8\" \n| \"lit_type (LU16 _)  = Num U16\" \n| \"lit_type (LU32 _)  = Num U32\" \n| \"lit_type (LU64 _)  = Num U64\"\n\nfun upcast_valid :: \"num_type \\<Rightarrow> num_type \\<Rightarrow> bool\" where\n  \"upcast_valid U8  U8  = True\"\n| \"upcast_valid U8  U16 = True\"\n| \"upcast_valid U8  U32 = True\"\n| \"upcast_valid U8  U64 = True\"\n| \"upcast_valid U16 U16 = True\"\n| \"upcast_valid U16 U32 = True\"\n| \"upcast_valid U16 U64 = True\"\n| \"upcast_valid U32 U32 = True\"\n| \"upcast_valid U32 U64 = True\"\n| \"upcast_valid U64 U64 = True\"\n| \"upcast_valid _   _   = False\"\n\nprimrec prim_lbool where\n  \"prim_lbool (LBool b) = b\"\n| \"prim_lbool (LU8 w) = False\"\n| \"prim_lbool (LU16 w) = False\"\n| \"prim_lbool (LU32 w) = False\"\n| \"prim_lbool (LU64 w) = False\"\n\ndefinition prim_word_op\n  where prim_word_op_def[simp]:\n  \"prim_word_op f8 f16 f32 f64 xs = (case (take 2 xs) of\n      [LU8 x, LU8 y] \\<Rightarrow> LU8 (f8 x y)\n    | [LU16 x, LU16 y] \\<Rightarrow> LU16 (f16 x y)\n    | [LU32 x, LU32 y] \\<Rightarrow> LU32 (f32 x y)\n    | [LU64 x, LU64 y] \\<Rightarrow> LU64 (f64 x y)\n    | _ \\<Rightarrow> LBool False)\"\n\ndefinition prim_word_comp\n  where prim_word_comp_def[simp]:\n  \"prim_word_comp f8 f16 f32 f64 xs = (case (take 2 xs) of\n      [LU8 x, LU8 y] \\<Rightarrow> LBool (f8 x y)\n    | [LU16 x, LU16 y] \\<Rightarrow> LBool (f16 x y)\n    | [LU32 x, LU32 y] \\<Rightarrow> LBool (f32 x y)\n    | [LU64 x, LU64 y] \\<Rightarrow> LBool (f64 x y)\n    | _ \\<Rightarrow> LBool False)\"\n\nprimrec eval_prim_op :: \"prim_op \\<Rightarrow> lit list \\<Rightarrow> lit\"\nwhere\n    \"eval_prim_op Not xs = LBool (\\<not> prim_lbool (hd xs))\"\n  | \"eval_prim_op And xs = LBool (prim_lbool (hd xs) \\<and> prim_lbool (xs ! 1))\"\n  | \"eval_prim_op Or xs = LBool (prim_lbool (hd xs) \\<or> prim_lbool (xs ! 1))\"\n  | \"eval_prim_op (Eq _) xs = LBool (hd xs = xs ! 1)\"\n  | \"eval_prim_op (NEq _) xs = LBool (hd xs \\<noteq> xs ! 1)\"\n  | \"eval_prim_op (Plus _) xs = prim_word_op (op +) (op +) (op +) (op +) xs\"\n  | \"eval_prim_op (Minus _) xs = prim_word_op (op -) (op -) (op -) (op -) xs\"\n  | \"eval_prim_op (Times _) xs = prim_word_op (op *) (op *) (op *) (op *) xs\"\n  | \"eval_prim_op (Divide _) xs = prim_word_op checked_div checked_div checked_div checked_div  xs\"\n  | \"eval_prim_op (Mod _) xs = prim_word_op checked_mod checked_mod checked_mod checked_mod xs\"\n  | \"eval_prim_op (Gt _) xs = prim_word_comp greater greater greater greater xs\"\n  | \"eval_prim_op (Lt _) xs = prim_word_comp less less less less xs\"\n  | \"eval_prim_op (Le _) xs = prim_word_comp less_eq less_eq less_eq less_eq xs\"\n  | \"eval_prim_op (Ge _) xs = prim_word_comp greater_eq greater_eq greater_eq greater_eq xs\"\n  | \"eval_prim_op (BitAnd _) xs = prim_word_op bitAND bitAND bitAND bitAND xs\"\n  | \"eval_prim_op (BitOr _) xs = prim_word_op bitOR bitOR bitOR bitOR xs\"\n  | \"eval_prim_op (BitXor _) xs = prim_word_op bitXOR bitXOR bitXOR bitXOR xs\"\n  | \"eval_prim_op (LShift _) xs = prim_word_op (checked_shift shiftl) (checked_shift shiftl)\n        (checked_shift shiftl) (checked_shift shiftl) xs\"\n  | \"eval_prim_op (RShift _) xs = prim_word_op (checked_shift shiftr) (checked_shift shiftr)\n        (checked_shift shiftr) (checked_shift shiftr) xs\"\n  | \"eval_prim_op (Complement _) xs = prim_word_op (\\<lambda>x y. bitNOT x) (\\<lambda>x y. bitNOT x)\n        (\\<lambda>x y. bitNOT x) (\\<lambda>x y. bitNOT x) [hd xs, hd xs]\"\n\nlemma eval_prim_op_lit_type:\n  \"prim_op_type pop = (\\<tau>s, \\<tau>) \\<Longrightarrow> map lit_type xs = \\<tau>s\n    \\<Longrightarrow> lit_type (eval_prim_op pop xs) = \\<tau>\"\n  by (cases pop, auto split: lit.split)\n\nsection {* Typing rules *}\n\ninductive typing :: \"('f \\<Rightarrow> poly_type) \\<Rightarrow> kind env \\<Rightarrow> ctx \\<Rightarrow> 'f expr \\<Rightarrow> type \\<Rightarrow> bool\" \n          (\"_, _, _ \\<turnstile> _ : _\" [30,0,0,0,20] 60)\n      and typing_all :: \"('f \\<Rightarrow> poly_type) \\<Rightarrow> kind env \\<Rightarrow> ctx \\<Rightarrow> 'f expr list \\<Rightarrow> type list \\<Rightarrow> bool\"\n          (\"_, _, _ \\<turnstile>* _ : _\" [30,0,0,0,20] 60) where\n\n  typing_var    : \"\\<lbrakk> K \\<turnstile> \\<Gamma> \\<leadsto>w singleton (length \\<Gamma>) i t \n                   ; i < length \\<Gamma>\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> Var i : t\"\n\n| typing_afun   : \"\\<lbrakk> \\<Xi> f = (K', t, u)\n                   ; list_all2 (kinding K) ts K' \n                   ; K' \\<turnstile> TFun t u wellformed\n                   ; K \\<turnstile> \\<Gamma> consumed\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> AFun f ts : instantiate ts (TFun t u)\"\n\n| typing_fun    : \"\\<lbrakk> \\<Xi>, K', [Some t] \\<turnstile> f : u \n                   ; K \\<turnstile> \\<Gamma> consumed\n                   ; K' \\<turnstile> t wellformed\n                   ; list_all2 (kinding K) ts K'\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> Fun f ts : instantiate ts (TFun t u)\"\n\n| typing_app    : \"\\<lbrakk> K \\<turnstile> \\<Gamma> \\<leadsto> \\<Gamma>1 | \\<Gamma>2\n                   ; \\<Xi>, K, \\<Gamma>1 \\<turnstile> a : TFun x y\n                   ; \\<Xi>, K, \\<Gamma>2 \\<turnstile> b : x \n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> App a b : y\"\n\n| typing_con    : \"\\<lbrakk> \\<Xi>, K, \\<Gamma> \\<turnstile> x : t; (tag,t) \\<in> set ts \n                   ; K \\<turnstile>* (map snd ts) wellformed\n                   ; distinct (map fst ts)\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> Con ts tag x : TSum ts\"\n\n| typing_prom   : \"\\<lbrakk> \\<Xi>, K, \\<Gamma> \\<turnstile> x : TSum ts\n                   ; set ts \\<subseteq> set ts' \n                   ; K \\<turnstile>* (map snd ts') wellformed\n                   ; distinct (map fst ts')\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> Promote ts' x : TSum ts'\"\n\n| typing_cast   : \"\\<lbrakk> \\<Xi>, K, \\<Gamma> \\<turnstile> e : TPrim (Num \\<tau>)\n                   ; upcast_valid \\<tau> \\<tau>' \n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> Cast \\<tau>' e : TPrim (Num \\<tau>')\"\n\n| typing_tuple  : \"\\<lbrakk> K \\<turnstile> \\<Gamma> \\<leadsto> \\<Gamma>1 | \\<Gamma>2\n                   ; \\<Xi>, K, \\<Gamma>1 \\<turnstile> t : T \n                   ; \\<Xi>, K, \\<Gamma>2 \\<turnstile> u : U\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> Tuple t u : TProduct T U\"\n\n| typing_split  : \"\\<lbrakk> K \\<turnstile> \\<Gamma> \\<leadsto> \\<Gamma>1 | \\<Gamma>2\n                   ; \\<Xi>, K, \\<Gamma>1 \\<turnstile> x : TProduct t u\n                   ; \\<Xi>, K, (Some t)#(Some u)#\\<Gamma>2 \\<turnstile> y : t'\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> Split x y : t'\" \n\n| typing_let    : \"\\<lbrakk> K \\<turnstile> \\<Gamma> \\<leadsto> \\<Gamma>1 | \\<Gamma>2 \n                   ; \\<Xi>, K, \\<Gamma>1 \\<turnstile> x : t\n                   ; \\<Xi>, K, (Some t # \\<Gamma>2) \\<turnstile> y : u\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> Let x y : u\"\n\n| typing_letb   : \"\\<lbrakk> split_bang K is \\<Gamma> \\<Gamma>1 \\<Gamma>2\n                   ; \\<Xi>, K, \\<Gamma>1 \\<turnstile> x : t\n                   ; \\<Xi>, K, (Some t # \\<Gamma>2) \\<turnstile> y : u\n                   ; K \\<turnstile> t :\\<kappa> k\n                   ; E \\<in> k\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> LetBang is x y : u\"\n\n| typing_case   : \"\\<lbrakk> K \\<turnstile> \\<Gamma> \\<leadsto> \\<Gamma>1 | \\<Gamma>2\n                   ; \\<Xi>, K, \\<Gamma>1 \\<turnstile> x : TSum ts\n                   ; (tag, t) \\<in> set ts\n                   ; \\<Xi>, K, (Some t # \\<Gamma>2) \\<turnstile> a : u\n                   ; \\<Xi>, K, (Some (TSum (filter (\\<lambda> x. fst x \\<noteq> tag) ts)) # \\<Gamma>2) \\<turnstile> b : u\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> Case x tag a b : u\" \n\n| typing_esac   : \"\\<lbrakk> \\<Xi>, K, \\<Gamma> \\<turnstile> x : TSum [(tag,t)]\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> Esac x : t\"\n\n| typing_if     : \"\\<lbrakk> K \\<turnstile> \\<Gamma> \\<leadsto> \\<Gamma>1 | \\<Gamma>2\n                   ; \\<Xi>, K, \\<Gamma>1 \\<turnstile> x : TPrim Bool\n                   ; \\<Xi>, K, \\<Gamma>2 \\<turnstile> a : t\n                   ; \\<Xi>, K, \\<Gamma>2 \\<turnstile> b : t\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> If x a b : t\"\n\n| typing_prim   : \"\\<lbrakk> \\<Xi>, K, \\<Gamma> \\<turnstile>* args : map TPrim ts \n                   ; prim_op_type oper = (ts,t)\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> Prim oper args : TPrim t\"\n\n| typing_lit    : \"\\<lbrakk> K \\<turnstile> \\<Gamma> consumed\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> Lit l : TPrim (lit_type l)\" \n\n| typing_unit   : \"\\<lbrakk> K \\<turnstile> \\<Gamma> consumed\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> Unit : TUnit\"\n\n| typing_struct : \"\\<lbrakk> \\<Xi>, K, \\<Gamma> \\<turnstile>* es : ts\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> Struct ts es : TRecord (zip ts (replicate (length ts) False)) Unboxed\"\n\n| typing_member : \"\\<lbrakk> \\<Xi>, K, \\<Gamma> \\<turnstile> e : TRecord ts s\n                   ; K \\<turnstile> TRecord ts s :\\<kappa> k\n                   ; S \\<in> k\n                   ; f < length ts\n                   ; ts ! f = (t, False)\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> Member e f : t\"\n\n| typing_take   : \"\\<lbrakk> K \\<turnstile> \\<Gamma> \\<leadsto> \\<Gamma>1 | \\<Gamma>2 \n                   ; \\<Xi>, K, \\<Gamma>1 \\<turnstile> e : TRecord ts s\n                   ; s \\<noteq> ReadOnly\n                   ; f < length ts\n                   ; ts ! f = (t, False)\n                   ; K \\<turnstile> t :\\<kappa> k\n                   ; S \\<in> k \\<or> taken\n                   ; \\<Xi>, K, (Some t # Some (TRecord (ts [f := (t,taken)]) s) # \\<Gamma>2) \\<turnstile> e' : u\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> Take e f e' : u\"\n\n| typing_put    : \"\\<lbrakk> K \\<turnstile> \\<Gamma> \\<leadsto> \\<Gamma>1 | \\<Gamma>2\n                   ; \\<Xi>, K, \\<Gamma>1 \\<turnstile> e : TRecord ts s\n                   ; s \\<noteq> ReadOnly\n                   ; f < length ts\n                   ; ts ! f = (t, taken)\n                   ; K \\<turnstile> t :\\<kappa> k\n                   ; D \\<in> k \\<or> taken\n                   ; \\<Xi>, K, \\<Gamma>2 \\<turnstile> e' : t\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile> Put e f e' : TRecord (ts [f := (t,False)]) s\"\n\n| typing_all_empty : \"\\<Xi>, K, empty n \\<turnstile>* [] : []\"\n\n| typing_all_cons  : \"\\<lbrakk> K \\<turnstile> \\<Gamma> \\<leadsto> \\<Gamma>1 | \\<Gamma>2\n                      ; \\<Xi>, K, \\<Gamma>1 \\<turnstile>  e  : t\n                      ; \\<Xi>, K, \\<Gamma>2 \\<turnstile>* es : ts\n                      \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> \\<turnstile>* (e # es) : (t # ts)\"\n\ninductive_cases typing_num     [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> e : TPrim (Num \\<tau>)\"\ninductive_cases typing_bool    [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> e : TPrim Bool\"\ninductive_cases typing_varE    [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> Var i : \\<tau>\"\ninductive_cases typing_appE    [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> App x y : \\<tau>\"\ninductive_cases typing_litE    [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> Lit l : \\<tau>\"\ninductive_cases typing_funE    [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> Fun f ts : \\<tau>\"\ninductive_cases typing_afunE   [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> AFun f ts : \\<tau>\"\ninductive_cases typing_ifE     [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> If c t e : \\<tau>\"\ninductive_cases typing_conE    [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> Con ts t e : \\<tau>\"\ninductive_cases typing_unitE   [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> Unit : \\<tau>\"\ninductive_cases typing_promE   [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> Promote ts e : \\<tau>\"\ninductive_cases typing_primE   [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> Prim p es : \\<tau>\"\ninductive_cases typing_memberE [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> Member e f : \\<tau>\"\ninductive_cases typing_tupleE  [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> Tuple a b : \\<tau>\"\ninductive_cases typing_caseE   [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> Case x t m n : \\<tau>\"\ninductive_cases typing_esacE   [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> Esac e : \\<tau>\"\ninductive_cases typing_castE   [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> Cast t e : \\<tau>\"\ninductive_cases typing_letE    [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> Let a b : \\<tau>\"\ninductive_cases typing_structE [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> Struct ts es : \\<tau>\"\ninductive_cases typing_letbE   [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> LetBang vs a b : \\<tau>\"\ninductive_cases typing_takeE   [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> Take x f e : \\<tau>\"\ninductive_cases typing_putE    [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> Put x f e : \\<tau>\"\ninductive_cases typing_splitE  [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile> Split x e : \\<tau>\"\ninductive_cases typing_all_emptyE [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile>* []       : \\<tau>s\"\ninductive_cases typing_all_consE  [elim]: \"\\<Xi>, K, \\<Gamma> \\<turnstile>* (x # xs) : \\<tau>s\"\n\nsection {* Syntax structural judgements *}\n\nsubsection {* A-normal form *}\n\ninductive atom ::\"'f expr \\<Rightarrow> bool\" where \n  \"atom (Var x)\"\n| \"atom (Fun f ts)\"\n| \"atom (AFun f ts)\"\n| \"atom (Prim p (map Var is))\"\n| \"atom (Con ts n (Var x))\"\n| \"atom (Promote ts (Var x))\"\n| \"atom (Struct ts (map Var is))\"\n| \"atom (Cast t (Var x))\"\n| \"atom (Member (Var x) f)\"\n| \"atom Unit\"\n| \"atom (Lit l)\"\n| \"atom (Tuple (Var x) (Var y))\"\n| \"atom (Esac (Var x))\"\n| \"atom (App (Var a) (Var b))\"\n| \"atom (App (Fun f ts) (Var b))\"\n| \"atom (App (AFun f ts) (Var b))\"\n| \"atom (Put (Var x) f (Var y))\"\n\ninductive a_normal :: \"'f expr \\<Rightarrow> bool\" where \n  \"\\<lbrakk> atom x \\<rbrakk> \\<Longrightarrow> a_normal x\"\n| \"\\<lbrakk> atom x ; a_normal y \\<rbrakk> \\<Longrightarrow> a_normal (Let x y)\"\n| \"\\<lbrakk> a_normal x ; a_normal y \\<rbrakk> \\<Longrightarrow> a_normal (LetBang is x y)\"\n| \"\\<lbrakk> a_normal m ; a_normal n \\<rbrakk> \\<Longrightarrow> a_normal (Case (Var x) t m n)\"\n| \"\\<lbrakk> a_normal t ; a_normal e \\<rbrakk> \\<Longrightarrow> a_normal (If (Var x) t e)\"\n| \"\\<lbrakk> a_normal y \\<rbrakk> \\<Longrightarrow> a_normal (Split (Var x) y)\"\n| \"\\<lbrakk> a_normal y \\<rbrakk> \\<Longrightarrow> a_normal (Take (Var x) f y)\"\n\ninductive_cases a_normal_E:  \"a_normal x\"\ninductive_cases a_normal_LetE:  \"a_normal (Let x y)\"\ninductive_cases a_normal_LetBangE: \"a_normal (LetBang is x y)\"\ninductive_cases a_normal_CaseE: \"a_normal (Case x t m n)\"\ninductive_cases a_normal_IfE: \"a_normal (If x t e)\"\ninductive_cases a_normal_Split: \"a_normal (Split x y)\"\ninductive_cases a_normal_TakeE:  \"a_normal (Take x f e)\"\n\nsection {* Representation Types (for use in C-refinement) *}\n\n\ndatatype repr = RPtr repr\n              | RCon name \"repr list\"\n              | RFun\n              | RPrim prim_type\n              | RSum \"(name \\<times> repr) list\"\n              | RProduct \"repr\" \"repr\"\n              | RRecord \"repr list\"\n              | RUnit\n\nfun type_repr :: \"type \\<Rightarrow> repr\" where\n  \"type_repr (TFun t t')          = RFun\"\n| \"type_repr (TPrim t)            = RPrim t\"\n| \"type_repr (TSum ts)            = RSum (map (\\<lambda>(a,b).(a, type_repr b)) ts)\"\n| \"type_repr (TProduct a b)       = RProduct (type_repr a) (type_repr b)\"\n| \"type_repr (TCon n ts Unboxed)  = RCon n (map type_repr ts)\"\n| \"type_repr (TCon n ts _)        = RPtr (RCon n (map type_repr ts))\"\n| \"type_repr (TRecord ts Unboxed) = RRecord (map (\\<lambda>a. type_repr (fst a)) ts)\"  \n| \"type_repr (TRecord ts _)       = RPtr (RRecord (map (\\<lambda>a. type_repr (fst a)) ts))\"\n| \"type_repr (TUnit)              = RUnit\"\n\nsection {* Kinding lemmas *}\n\nlemma supersumption:\nfixes k' :: kind\nassumes k_is_superset : \"k' \\<subseteq> k\"\nshows \"K \\<turnstile>  t  :\\<kappa> k  \\<Longrightarrow> K \\<turnstile>  t  :\\<kappa> k'\" \nand   \"K \\<turnstile>* ts :\\<kappa> k  \\<Longrightarrow> K \\<turnstile>* ts :\\<kappa> k'\"\nand   \"K \\<turnstile>* fs :\\<kappa>r k \\<Longrightarrow> K \\<turnstile>* fs :\\<kappa>r k'\"\nusing k_is_superset proof (induct rule: kinding_kinding_all_kinding_record.inducts)\nqed (auto intro: subset_trans kinding_kinding_all_kinding_record.intros)\n\n\nlemma kind_top:\nshows \"k \\<subseteq> {D, S, E}\"\nby (force intro: kind_comp.exhaust)\n\nlemma kinding_all_nth:\nfixes n :: nat\nassumes \"K \\<turnstile>* ts :\\<kappa> k\" \nand     \"n < length ts\"\nshows   \"K \\<turnstile> (ts ! n) :\\<kappa> k\"\nusing assms proof (induct ts arbitrary: n)\n     case Nil  then show ?case by auto\nnext case Cons then show ?case by (case_tac n, auto)\nqed\n\nlemma kinding_all_set:\nshows \"(K \\<turnstile>* ts :\\<kappa> k) = (\\<forall> t \\<in> set ts. K \\<turnstile> t :\\<kappa> k)\"\nproof (rule iffI)\n     assume \"K \\<turnstile>* ts :\\<kappa> k\"\nthen show   \"\\<forall> t \\<in> set ts. K \\<turnstile> t :\\<kappa> k\"\n     by (rule kinding_kinding_all_kinding_record.inducts, simp+)\n\nnext assume \"\\<forall> t \\<in> set ts. K \\<turnstile> t :\\<kappa> k\"\nthen show   \"K \\<turnstile>* ts :\\<kappa> k\" \n     by (induct ts, auto intro: kinding_kinding_all_kinding_record.intros)\nqed\n\nlemma kinding_all_subset:\nassumes \"K \\<turnstile>* ts :\\<kappa> k\"\nand     \"set us \\<subseteq> set ts\"\nshows   \"K \\<turnstile>* us :\\<kappa> k\"\nusing assms by (auto simp add: kinding_all_set)\n\nlemma kinding_record_wellformed:\nassumes \"K \\<turnstile>* ts :\\<kappa>r k\"\nand     \"(a,b) \\<in> set ts\" \nshows   \"K \\<turnstile> a wellformed\"\nusing assms proof (induct ts)\n     case Nil  then show ?case by (simp add:   set_conv_nth)\nnext case Cons then show ?case by (auto split: prod.split\n                                        elim:  kinding_record.cases)\nqed\n\nlemma kinding_record_wellformed_nth:\nassumes \"K \\<turnstile>* ts :\\<kappa>r k\"\nand     \"ts ! n = (a,b)\"\nand     \"n < length ts\" \nshows   \"K \\<turnstile> a wellformed\"\nusing assms(1)\n  and assms(2) [THEN sym] \n  and assms(3) by (force intro: kinding_record_wellformed [simplified]\n                         simp:  set_conv_nth)\n\n\nlemma kinding_all_record:\nassumes \"K \\<turnstile>* ts :\\<kappa> k\"\nshows   \"K \\<turnstile>* zip ts (replicate (length ts) False) :\\<kappa>r k\"\nusing assms proof (induct ts)\nqed (force intro: kinding_kinding_all_kinding_record.intros)+\n\n\nlemma kinding_all_record':\nassumes \"K \\<turnstile>* map fst ts :\\<kappa> k\"\nshows   \"K \\<turnstile>* ts :\\<kappa>r k\"\nusing assms proof (induct ts)\n     case Nil         then show ?case by (force intro: kinding_kinding_all_kinding_record.intros)\nnext case (Cons a ts) then show ?case apply (clarsimp)\n                                      apply (case_tac a)\n                                      apply (case_tac b)\n                                      apply (auto intro: kinding_kinding_all_kinding_record.intros)\n                                      done\nqed\n\nlemma kinding_record_update:\nassumes \"K \\<turnstile>* ts :\\<kappa>r k\"\nand     \"ts ! n = (a, b)\"\nand     \"K \\<turnstile> a :\\<kappa> k'\"\nshows   \"K \\<turnstile>* (ts[ n := (a, False)]) :\\<kappa>r (k \\<inter> k')\"\nusing assms proof (induct ts arbitrary: n)\n     case Nil then show ?case by (force intro: kinding_kinding_all_kinding_record.intros)\nnext case Cons\n  note A = this\n  show ?case proof (cases n)\n         case 0   with A show ?thesis by (force elim!:  kind_record_consE\n                                                intro!: kinding_kinding_all_kinding_record.intros \n                                                intro:  supersumption)\n    next case Suc with A show ?thesis by (force elim!:  kind_record_consE\n                                                intro!: kinding_kinding_all_kinding_record.intros \n                                                intro:  supersumption)\n  qed\nqed\n\nlemma sigil_kind_writable:\nassumes \"s \\<noteq> ReadOnly\"\nand     \"k \\<subseteq> sigil_kind Writable\"\nshows   \"k \\<subseteq> sigil_kind s\"\nproof (cases s)\nqed (simp_all add: assms(1) assms(2)[simplified] kind_top)\n\nsection {* Bang lemmas *}\n\nlemma bang_sigil_idempotent:\nshows \"bang_sigil (bang_sigil s) = bang_sigil s\"\nby (cases s, simp+)\n\nlemma bang_idempotent:\nshows \"bang (bang \\<tau>) = bang \\<tau>\"\nby (force intro: bang.induct [where P = \"\\<lambda> \\<tau> . bang (bang \\<tau>) = bang \\<tau>\"]\n          simp:  bang_sigil_idempotent)\n\nlemma bang_sigil_kind: \nshows \"{D , S} \\<subseteq> sigil_kind (bang_sigil s)\" \nby (case_tac s,auto)\n\nlemma bang_kind:\nshows \"K \\<turnstile>  t  :\\<kappa>  k \\<Longrightarrow> K \\<turnstile>  bang t                       :\\<kappa>  {D, S}\"\nand   \"K \\<turnstile>* ts :\\<kappa>  k \\<Longrightarrow> K \\<turnstile>* map bang ts                  :\\<kappa>  {D, S}\"\nand   \"K \\<turnstile>* fs :\\<kappa>r k \\<Longrightarrow> K \\<turnstile>* map (\\<lambda>(a,b). (bang a, b)) fs :\\<kappa>r {D, S}\"\nby ( induct rule: kinding_kinding_all_kinding_record.inducts\n   , auto intro:  kinding_kinding_all_kinding_record.intros\n          intro!: bang_sigil_kind)\n\nsection {* Instantiation *}\n\nlemma instantiate_bang [simp]:\nshows \"instantiate \\<delta> (bang \\<tau>) = bang (instantiate \\<delta> \\<tau>)\"\nby (force intro: bang.induct [where P = \"\\<lambda> \\<tau>. instantiate \\<delta> (bang \\<tau>) = bang (instantiate \\<delta> \\<tau>)\"] \n          simp:  bang_idempotent)\n\nlemma instantiate_instantiate [simp]:\nassumes \"list_all2 (kinding K') \\<delta>' K\"\nand     \"length K' = length \\<delta>\"\nshows   \"K \\<turnstile> x wellformed \\<Longrightarrow> instantiate \\<delta> (instantiate \\<delta>' x) = instantiate (map (instantiate \\<delta>) \\<delta>') x\"\nusing assms proof (induct x arbitrary: \\<delta>' rule: instantiate.induct)\n\nnext case 3 then show ?case by (force simp: set_conv_nth \n                                      dest: kinding_all_nth)\nnext case 8 then show ?case by (fastforce dest: kinding_record_wellformed) \nnext case 6 note IH   = this(1)\n            and  REST = this(2-)\n            from REST show ?case apply (clarsimp elim!: kind_tsumE)   \n                                 apply (rule IH, simp,simp)\n                                 apply (bestsimp simp:  set_conv_nth \n                                                 dest!: prod_in_set(2) \n                                                 dest:  kinding_all_nth [ where ts = \"map snd ts\" for ts\n                                                                        , simplified])+\n                                 done (*TODO automate properly*)\nqed (force dest: list_all2_lengthD)+\n                        \nlemma instantiate_tprim [simp]:\nshows \"instantiate \\<delta> \\<circ> TPrim = TPrim\"\nby (rule ext, simp)\n\n\nlemma instantiate_nothing:\nshows \"instantiate [] e = e\"\nby (induct e) (auto simp: prod_set_defs intro: map_idI)\n\nlemma instantiate_nothing_id[simp]:\nshows \"instantiate [] = id\"\nby (rule ext, simp add: instantiate_nothing)\n\nlemma instantiate_ctx_nothing:\nshows \"instantiate_ctx [] e = e\"\nunfolding instantiate_ctx_def\nby (induct e, auto simp: map_option.id [simplified id_def])\n\nlemma instantiate_ctx_nothing_id[simp]:\nshows \"instantiate_ctx [] = id\"\nby (rule ext, simp add: instantiate_ctx_nothing)\n\nlemma specialise_nothing:\nshows \"specialise [] e = e\"\nby (induct e) (auto simp: prod_set_defs intro: map_idI)\n\nlemma specialise_nothing_id[simp]:\nshows \"specialise [] = id\"\nby (rule ext, simp add: specialise_nothing)\n\n\n\nlemmas typing_struct_instantiate = typing_struct [where ts = \"map (instantiate \\<delta>) ts\" for ts, simplified]\n\nsubsection {* substitutivity *}\n\nlemma substitutivity:\nfixes \\<delta>    :: \"type substitution\"\nand   K K' :: \"kind env\"\nassumes well_kinded: \"list_all2 (kinding K') \\<delta> K\"\nshows \"K \\<turnstile> t :\\<kappa> k    \\<Longrightarrow> K' \\<turnstile>  instantiate \\<delta> t                       :\\<kappa>  k\"\nand   \"K \\<turnstile>* ts :\\<kappa> k  \\<Longrightarrow> K' \\<turnstile>* map (instantiate \\<delta>) ts                :\\<kappa>  k\"\nand   \"K \\<turnstile>* fs :\\<kappa>r k \\<Longrightarrow> K' \\<turnstile>* map (\\<lambda>(a,b). (instantiate \\<delta> a, b)) fs :\\<kappa>r k\"\nusing well_kinded proof (induct rule: kinding_kinding_all_kinding_record.inducts)\n     case (kind_tvar k K i)\n       assume \"list_all2 (kinding K') \\<delta> K\"\n       and    \"i < length K\"\n       and    \"k \\<subseteq> K ! i\" \n       moreover   then have \"i < length \\<delta>\" by (auto dest: list_all2_lengthD)\n       ultimately also have \"K' \\<turnstile> (\\<delta> ! i) :\\<kappa> (K ! i)\" by (auto intro: list_all2_nthD)\n       ultimately show ?case by (auto intro: supersumption)\nnext case (kind_tvarb k i K)\n       assume \"list_all2 (kinding K') \\<delta> K\"\n       and    \"i < length K\"\n       and    \"k \\<subseteq> {D, S}\"\n       moreover   then have \"i < length \\<delta>\" by (auto dest: list_all2_lengthD)\n       ultimately also have \"K' \\<turnstile> (\\<delta> ! i) :\\<kappa> (K ! i)\" by (auto intro: list_all2_nthD)\n       ultimately show ?case by (auto intro: supersumption bang_kind)\nqed (auto intro: kinding_kinding_all_kinding_record.intros)\n\nlemma list_all2_substitutivity:\nfixes \\<delta>    :: \"type substitution\"\nand   K K' :: \"kind env\"\nassumes well_kinded: \"list_all2 (kinding K') \\<delta> K\"\nshows \"list_all2 (kinding K) ts ks \\<Longrightarrow> list_all2 (kinding K') (map (instantiate \\<delta>) ts) ks\"\nby ( induct rule: list_all2_induct\n   , auto dest: substitutivity [OF well_kinded])\n\nsubsection {* Instantiation of contexts *}\n\nlemma instantiate_ctx_weaken:\nassumes \"K \\<turnstile> \\<Gamma> \\<leadsto>w \\<Gamma>'\"\nand     \"list_all2 (kinding K') \\<delta> K\"\nshows   \"K' \\<turnstile> instantiate_ctx \\<delta> \\<Gamma> \\<leadsto>w instantiate_ctx \\<delta> \\<Gamma>'\"\nusing assms(1) [simplified weakening_def] and assms(2) proof (induct rule: list_all2_induct)\n     case Nil  then show ?case by (simp add: instantiate_ctx_def weakening_def) \nnext case Cons then show ?case by (fastforce intro: weakening_comp.intros \n                                             elim:  weakening_comp.cases\n                                             simp:  instantiate_ctx_def \n                                                    weakening_def \n                                             dest:  substitutivity)\nqed\n\n\nlemma instantiate_ctx_empty [simplified, simp]:\nshows \"instantiate_ctx \\<delta> (empty l) = empty l\"\nby (induct l, simp_all add: empty_def\n                            instantiate_ctx_def)\n\n\n\nlemma instantiate_ctx_singleton [simplified, simp]:\nshows \"instantiate_ctx \\<delta> (singleton l i \\<tau>) = singleton l i (instantiate \\<delta> \\<tau>)\"\nby (induct l arbitrary: i, simp_all add:   instantiate_ctx_def \n                                           empty_def \n                                    split: nat.split)\n\nlemma instantiate_ctx_length [simp]:\nshows \"length (instantiate_ctx \\<delta> \\<Gamma>) = length \\<Gamma>\"\nby (simp add: instantiate_ctx_def)\n\nlemma instantiate_ctx_consumed [simplified]:\nassumes \"K \\<turnstile> \\<Gamma> consumed\"\nand     \"list_all2 (kinding K') \\<delta> K\"\nshows   \"K' \\<turnstile> instantiate_ctx \\<delta> \\<Gamma> consumed\"\nusing assms by (auto intro: instantiate_ctx_weaken [where \\<Gamma>' = \"empty (length \\<Gamma>)\", simplified])\n\nlemma map_option_instantiate_split_comp:\nassumes \"K \\<turnstile> c \\<leadsto> c1 \\<parallel> c2\"\nand     \"list_all2 (kinding K') \\<delta> K\"\nshows   \"K' \\<turnstile> map_option (instantiate \\<delta>) c \\<leadsto> map_option (instantiate \\<delta>) c1 \\<parallel> map_option (instantiate \\<delta>) c2\"\nusing assms(1) by ( rule split_comp.cases\n                  , auto elim: split_comp.cases \n                         intro: substitutivity(1) assms(2) split_comp.intros)\n\nlemma instantiate_ctx_split:\nassumes \"K \\<turnstile> \\<Gamma> \\<leadsto> \\<Gamma>1 | \\<Gamma>2\"\nand     \"list_all2 (kinding K') \\<delta> K\"\nshows   \"K' \\<turnstile> instantiate_ctx \\<delta> \\<Gamma> \\<leadsto> instantiate_ctx \\<delta> \\<Gamma>1 | instantiate_ctx \\<delta> \\<Gamma>2\"\nusing assms proof (induct rule: split.induct)\ncase split_empty then show ?case by (auto simp:  instantiate_ctx_def\n                                          intro: split.intros)\ncase split_cons  then show ?case by (auto simp:  instantiate_ctx_def\n                                          intro: split.intros\n                                                 map_option_instantiate_split_comp)\nqed\n\n\nlemma instantiate_ctx_split_bang:\nassumes \"split_bang K is \\<Gamma> \\<Gamma>1 \\<Gamma>2\"\nand     \"list_all2 (kinding K') \\<delta> K\"\nshows   \"split_bang K' is (instantiate_ctx \\<delta> \\<Gamma>) (instantiate_ctx \\<delta> \\<Gamma>1) (instantiate_ctx \\<delta> \\<Gamma>2)\"\nusing assms proof (induct rule: split_bang.induct)\n     case split_bang_empty then show ?case by (auto simp:  instantiate_ctx_def\n                                                    intro: split_bang.intros)\nnext case split_bang_cons  then show ?case by (auto simp:  instantiate_ctx_def\n                                                    intro: split_bang.intros\n                                                           map_option_instantiate_split_comp)\nnext case split_bang_bang  then show ?case by (auto simp: instantiate_ctx_def \n                                                    intro: split_bang.intros)\nqed\n\n\nlemma instantiate_ctx_cons [simp]:\nshows   \"instantiate_ctx \\<delta> (Some x # \\<Gamma>) = Some (instantiate \\<delta> x) # instantiate_ctx \\<delta> \\<Gamma>\"\nby (simp add: instantiate_ctx_def)\n\n\n\nsection {* Lemmas about contexts, splitting and weakening *}\n\nlemma empty_length: \nshows \"length (empty n) = n\"\nby (induct n, simp_all add: empty_def)\n\nlemma weakening_length:\nshows \"K \\<turnstile> \\<Gamma> \\<leadsto>w \\<Gamma>' \\<Longrightarrow> length \\<Gamma> = length \\<Gamma>'\"\nby (auto simp: weakening_def dest:list_all2_lengthD)\n\nlemma weakening_preservation:\nassumes weak: \"K \\<turnstile> \\<Gamma> \\<leadsto>w \\<Gamma>'\"\nand     idx:  \"\\<Gamma>' ! x = Some t\"\nshows   \"\\<Gamma>  ! x = Some t\"\nusing weak[simplified weakening_def]\n  and weakening_length[OF weak] \n  and idx\n  proof (induct arbitrary: x rule: list_all2_induct)\n     case Nil                then show ?case by auto\nnext case (Cons x xs y ys a) then show ?case by (case_tac a, auto elim: weakening_comp.cases)\nqed           \n\nlemma weakening_nth:\nassumes weak: \"K \\<turnstile> \\<Gamma> \\<leadsto>w \\<Gamma>'\"\nand           \"i < length \\<Gamma>\"\nshows         \"weakening_comp K (\\<Gamma>!i) (\\<Gamma>'!i)\"\nusing assms by (auto simp add: weakening_def dest: list_all2_nthD)\n\n\nlemma typing_to_kinding :\nshows \"\\<Xi>, K, \\<Gamma> \\<turnstile>  e  : t  \\<Longrightarrow> K \\<turnstile>  t  wellformed\" \nand   \"\\<Xi>, K, \\<Gamma> \\<turnstile>* es : ts \\<Longrightarrow> K \\<turnstile>* ts wellformed\"\nproof (induct rule: typing_typing_all.inducts)\n     case typing_var    then show ?case by (fastforce dest: weakening_preservation weakening_nth\n                                                      simp: empty_length \n                                                      elim: weakening_comp.cases)\nnext case typing_fun    then show ?case by (fastforce intro: kinding_kinding_all_kinding_record.intros \n                                                             substitutivity)\nnext case typing_afun   then show ?case by (fastforce intro: kinding_kinding_all_kinding_record.intros \n                                                             substitutivity)\nnext case typing_esac   then show ?case by (fastforce)\nnext case typing_member then show ?case by (fastforce intro: kinding_record_wellformed_nth)\nnext case typing_struct then show ?case by ( clarsimp\n                                           , intro exI kind_trec kinding_all_record\n                                           , simp_all add: kind_top )\nnext case typing_take   then show ?case by (simp)  \nnext case typing_put    then show ?case by (fastforce intro: kinding_kinding_all_kinding_record.intros\n                                                             kinding_record_update)\nqed (auto intro: supersumption kinding_kinding_all_kinding_record.intros)\n\nlemma upcast_valid_cast_to :\nassumes \"upcast_valid \\<tau> \\<tau>'\"\n    and \"lit_type l = Num \\<tau>\"\nobtains x where \"cast_to \\<tau>' l = Some x\"\n            and \"lit_type x = Num \\<tau>'\"\nusing assms by (cases l, auto elim: upcast_valid.elims)\n\nlemma bang_type_repr [simp]:\nshows \"[] \\<turnstile> t :\\<kappa> k \\<Longrightarrow> (type_repr (bang t) = type_repr t)\"\nand   \"[] \\<turnstile>* ts :\\<kappa> k \\<Longrightarrow> (map (type_repr \\<circ> bang) ts) = map (type_repr) ts \"\nand   \"[] \\<turnstile>* fs :\\<kappa>r k \\<Longrightarrow> (map (type_repr \\<circ>  bang \\<circ> fst) fs) = map (type_repr  \\<circ> fst) fs\"\nby ( induct \"[] :: kind list\"  t k\n           and \"[] :: kind list\" ts k\n           and \"[] :: kind list\" fs k\n     rule: kinding_kinding_all_kinding_record.inducts\n   , auto, (case_tac s,auto)+)\n\n\nsubsection {* Specialisation *}\n\n\nlemma specialisation:\nassumes well_kinded: \"list_all2 (kinding K') \\<delta> K\"\nshows \"\\<Xi> , K , \\<Gamma> \\<turnstile>  e  : \\<tau>  \\<Longrightarrow> \\<Xi> , K' , instantiate_ctx \\<delta> \\<Gamma> \\<turnstile> specialise \\<delta> e : instantiate \\<delta> \\<tau> \"\nand   \"\\<Xi> , K , \\<Gamma> \\<turnstile>* es : \\<tau>s \\<Longrightarrow> \\<Xi> , K' , instantiate_ctx \\<delta> \\<Gamma> \\<turnstile>* map (specialise \\<delta>) es : map (instantiate \\<delta>) \\<tau>s\"\nusing assms proof (induct rule: typing_typing_all.inducts)\nnext case typing_case   then show ?case by (force intro:  typing_typing_all.intros instantiate_ctx_split \n                                                  simp:   set_conv_nth \n                                                          filter_fst_ignore [where P =\"\\<lambda>f. f \\<noteq> c\" for c]\n                                                  split:  prod.split)\nnext case (typing_afun \\<Xi> f ks t u K ts ks)\nthen also have \"instantiate \\<delta> (instantiate ts t) = instantiate (map (instantiate \\<delta>) ts) t\"\n          and  \"instantiate \\<delta> (instantiate ts u) = instantiate (map (instantiate \\<delta>) ts) u\"\n          by (force dest: list_all2_lengthD intro: instantiate_instantiate)+\nultimately show ?case by (auto intro!: list_all2_substitutivity\n                                       typing_typing_all.typing_afun [simplified] \n                                       instantiate_ctx_consumed)\nnext case (typing_fun \\<Xi> K t f u \\<Gamma> ks ts)\nthen also have \"instantiate \\<delta> (instantiate ts t) = instantiate (map (instantiate \\<delta>) ts) t\"\n          and  \"instantiate \\<delta> (instantiate ts u) = instantiate (map (instantiate \\<delta>) ts) u\"\n          by (force dest: list_all2_lengthD intro: instantiate_instantiate dest!: typing_to_kinding)+\nultimately show ?case by (auto intro!: list_all2_substitutivity\n                                       typing_typing_all.typing_fun [simplified] \n                                       instantiate_ctx_consumed)\nqed (force intro!: typing_struct_instantiate\n                   typing_typing_all.intros\n           dest:   substitutivity\n                   instantiate_ctx_split\n                   instantiate_ctx_split_bang\n                   instantiate_ctx_weaken\n                   instantiate_ctx_consumed\n           simp:   instantiate_ctx_def [where \\<Gamma> = \"[]\", simplified]\n                   map_update)+\n\n\n\nfun expr_size :: \"'f expr \\<Rightarrow> nat\" where\n  \"expr_size (Let a b) = Suc ((expr_size a) + (expr_size b))\"\n| \"expr_size (LetBang vs a b) = Suc ((expr_size a) + (expr_size b))\"\n| \"expr_size (Fun f ts) = Suc (expr_size f)\"\n| \"expr_size (Unit) = 0\"\n| \"expr_size (Member x f) = Suc (expr_size x)\"\n| \"expr_size (Cast t x) = Suc (expr_size x)\"\n| \"expr_size (Con c x ts) = Suc (expr_size ts)\"\n| \"expr_size (App a b) = Suc ((expr_size a) + (expr_size b))\"\n| \"expr_size (Prim p as) = Suc (listsum (map expr_size as))\"\n| \"expr_size (Var v) = 0\"\n| \"expr_size (AFun v va) = 0\"\n| \"expr_size (Promote v va) = Suc (expr_size va)\"\n| \"expr_size (Struct v va) = Suc (listsum ( map expr_size va))\"\n| \"expr_size (Lit v) = 0\"\n| \"expr_size (Tuple v va) = Suc ((expr_size v) + (expr_size va))\"\n| \"expr_size (Put v va vb) = Suc ((expr_size v) + (expr_size vb))\"\n| \"expr_size (Esac x) = Suc (expr_size x)\"\n| \"expr_size (If x a b) = Suc ((expr_size x) + (expr_size a) + (expr_size b))\"\n| \"expr_size (Split x y) = Suc ((expr_size x) + (expr_size y))\"\n| \"expr_size (Case x v a b) = Suc ((expr_size x) + (expr_size a) + (expr_size b))\"\n| \"expr_size (Take x f y) = Suc ((expr_size x) + (expr_size y))\"\n\nlemma specialise_size [simp]:\n  shows \"expr_size (specialise \\<tau>s x) = expr_size x\"\nproof -\nhave \"\\<forall> as . (\\<forall> x. x \\<in> set as \\<longrightarrow> expr_size (specialise \\<tau>s x) = expr_size x) \\<longrightarrow>\n  listsum (map (expr_size \\<circ> specialise \\<tau>s) as) = listsum (map expr_size as)\"\nby (rule allI, induct_tac as, simp+)\nthen show ?thesis by (induct x rule: expr_size.induct, auto)\nqed\n\nend\n", "meta": {"author": "crizkallah", "repo": "cogent", "sha": "cb16e8169d4389e32dc4aecf4eb9f57173264006", "save_path": "github-repos/isabelle/crizkallah-cogent", "path": "github-repos/isabelle/crizkallah-cogent/cogent-cb16e8169d4389e32dc4aecf4eb9f57173264006/cogent/isa/Cogent.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982043529715, "lm_q2_score": 0.4035668537353746, "lm_q1q2_score": 0.26142988318615396}}
{"text": "header {* \\isaheader{Basic Parametricity Reasoning} *}\ntheory Param_Tool\nimports \"Relators\"\nbegin\n\n  subsection {* Auxiliary Lemmas *}\n  lemma tag_both: \"\\<lbrakk> (Let x f,Let x' f')\\<in>R \\<rbrakk> \\<Longrightarrow> (f x,f' x')\\<in>R\" by simp\n  lemma tag_rhs: \"\\<lbrakk> (c,Let x f)\\<in>R \\<rbrakk> \\<Longrightarrow> (c,f x)\\<in>R\" by simp\n  lemma tag_lhs: \"\\<lbrakk> (Let x f,a)\\<in>R \\<rbrakk> \\<Longrightarrow> (f x,a)\\<in>R\" by simp\n\n  lemma tagged_fun_relD_both: \n    \"\\<lbrakk> (f,f')\\<in>A\\<rightarrow>B; (x,x')\\<in>A \\<rbrakk> \\<Longrightarrow> (Let x f,Let x' f')\\<in>B\"\n    and tagged_fun_relD_rhs: \"\\<lbrakk> (f,f')\\<in>A\\<rightarrow>B; (x,x')\\<in>A \\<rbrakk> \\<Longrightarrow> (f x,Let x' f')\\<in>B\"\n    and tagged_fun_relD_lhs: \"\\<lbrakk> (f,f')\\<in>A\\<rightarrow>B; (x,x')\\<in>A \\<rbrakk> \\<Longrightarrow> (Let x f,f' x')\\<in>B\"\n    and tagged_fun_relD_none: \"\\<lbrakk> (f,f')\\<in>A\\<rightarrow>B; (x,x')\\<in>A \\<rbrakk> \\<Longrightarrow> (f x,f' x')\\<in>B\"\n    by (simp_all add: fun_relD)\n\n\n  subsection {* ML-Setup*}\n\n  ML {*\n    signature PARAMETRICITY = sig\n      type param_ruleT = {\n        lhs: term,\n        rhs: term,\n        R: term,\n        rhs_head: term,\n        arity: int\n      }\n    \n      val dest_param_term: term -> param_ruleT\n      val dest_param_rule: thm -> param_ruleT\n      val dest_param_goal: int -> thm -> param_ruleT\n\n      val safe_fun_relD_tac: Proof.context -> tactic'\n\n      val adjust_arity: int -> thm -> thm\n      val adjust_arity_tac: int -> Proof.context -> tactic'\n      val unlambda_tac: tactic'\n      val prepare_tac: Proof.context -> tactic'\n\n      val fo_rule: thm -> thm\n\n      (*** Basic tactics ***)\n      val param_rule_tac: Proof.context -> thm -> tactic'\n      val param_rules_tac: Proof.context -> thm list -> tactic'\n      val asm_param_tac: Proof.context -> tactic'\n\n\n      (*** Nets of parametricity rules ***)\n      type param_net\n      val net_empty: param_net\n      val net_add: thm -> param_net -> param_net\n      val net_del: thm -> param_net -> param_net\n      val net_add_int: thm -> param_net -> param_net\n      val net_del_int: thm -> param_net -> param_net\n      val net_tac: param_net -> Proof.context -> tactic'\n    \n      (*** Default parametricity rules ***)\n      val add_dflt: thm -> Context.generic -> Context.generic\n      val add_dflt_attr: attribute\n      val del_dflt: thm -> Context.generic -> Context.generic\n      val del_dflt_attr: attribute\n      val get_dflt: Proof.context -> param_net\n\n      (** Configuration **)\n      val cfg_use_asm: bool Config.T\n      val cfg_single_step: bool Config.T\n\n      (** Setup **)\n      val setup: theory -> theory\n    end\n\n    structure Parametricity : PARAMETRICITY = struct\n      type param_ruleT = {\n        lhs: term,\n        rhs: term,\n        R: term,\n        rhs_head: term,\n        arity: int\n      }\n\n      fun dest_param_term t = \n        case \n          strip_all_body t |> Logic.strip_imp_concl |> HOLogic.dest_Trueprop\n        of \n          @{mpat \"(?lhs,?rhs):?R\"} => let \n            val (rhs_head,arity) = \n              case strip_comb rhs of\n                (c as Const _,l) => (c,length l)\n              | (c as Free _,l) => (c,length l)\n              | (c as Abs _,l) => (c,length l)\n              | _ => raise TERM (\"dest_param_term: Head\",[t])\n          in \n            { lhs = lhs, rhs = rhs, R=R, rhs_head = rhs_head, arity = arity }\n          end\n        | t => raise TERM (\"dest_param_term: Expected (_,_):_\",[t])\n\n      val dest_param_rule = dest_param_term o prop_of\n      fun dest_param_goal i st = \n        if i > nprems_of st then\n          raise THM (\"dest_param_goal\",i,[st])\n        else\n          dest_param_term (Logic.concl_of_goal (prop_of st) i)\n\n\n      fun safe_fun_relD_tac ctxt = let\n        fun t a b = fo_resolve_tac [a] ctxt THEN' rtac b\n      in\n        DETERM o (\n          t @{thm tag_both} @{thm tagged_fun_relD_both} ORELSE'\n          t @{thm tag_rhs} @{thm tagged_fun_relD_rhs} ORELSE'\n          t @{thm tag_lhs} @{thm tagged_fun_relD_lhs} ORELSE'\n          rtac @{thm tagged_fun_relD_none}\n        )\n      end\n\n      fun adjust_arity i thm = \n        if i = 0 then thm \n        else if i<0 then funpow (~i) (fn thm => thm RS @{thm fun_relI}) thm\n        else funpow i (fn thm => thm RS @{thm fun_relD}) thm\n\n      fun NTIMES k tac = \n        if k <= 0 then K all_tac \n        else tac THEN' NTIMES (k-1) tac\n\n      fun adjust_arity_tac n ctxt i st = \n        (if n = 0 then K all_tac\n        else if n>0 then NTIMES n (DETERM o rtac @{thm fun_relI})\n        else NTIMES (~n) (safe_fun_relD_tac ctxt)) i st\n\n      fun unlambda_tac i st = \n        case try (dest_param_goal i) st of\n          NONE => Seq.empty\n        | SOME g => let\n            val n = Term.strip_abs (#rhs_head g) |> #1 |> length\n          in NTIMES n (rtac @{thm fun_relI}) i st end\n\n      fun prepare_tac ctxt = \n        Subgoal.FOCUS (K (PRIMITIVE (Drule.eta_contraction_rule))) ctxt\n        THEN' unlambda_tac\n\n\n      fun could_param_rl rl i st = \n        if i > nprems_of st then NONE\n        else (\n          case (try (dest_param_goal i) st, try dest_param_term rl) of\n            (SOME g, SOME r) =>\n              if Term.could_unify (#rhs_head g, #rhs_head r) then\n                SOME (#arity r - #arity g)\n              else NONE\n          | _ => NONE\n        )\n\n      fun param_rule_tac_aux ctxt rl i st = \n        case could_param_rl (prop_of rl) i st of\n          SOME adj => (adjust_arity_tac adj ctxt THEN' rtac rl) i st\n        | _ => Seq.empty\n\n      fun param_rule_tac ctxt rl = \n        prepare_tac ctxt THEN' param_rule_tac_aux ctxt rl\n\n      fun param_rules_tac ctxt rls = \n        prepare_tac ctxt THEN' FIRST' (map (param_rule_tac_aux ctxt) rls)\n\n      fun asm_param_tac_aux ctxt i st = \n        if i > nprems_of st then Seq.empty\n        else let\n          val prems = Logic.prems_of_goal (prop_of st) i |> tag_list 1\n          \n          fun tac (n,t) i st = case could_param_rl t i st of\n            SOME adj => (adjust_arity_tac adj ctxt THEN' rprem_tac n ctxt) i st\n          | NONE => Seq.empty\n        in\n          FIRST' (map tac prems) i st\n        end\n\n      fun asm_param_tac ctxt = prepare_tac ctxt THEN' asm_param_tac_aux ctxt\n    \n      type param_net = (param_ruleT * thm) Item_Net.T\n\n      local\n        val param_get_key = single o #rhs_head o #1\n      in \n        val net_empty = Item_Net.init (Thm.eq_thm o pairself #2) param_get_key\n      end\n\n      fun wrap_pr_op f thm = case try (`dest_param_rule) thm of\n        NONE => \n          let \n            val msg = \"Ignoring invalid parametricity theorem: \"\n              ^ Display.string_of_thm_without_context thm\n            val _ = warning msg\n          in I end\n      | SOME p => f p\n    \n      val net_add_int = wrap_pr_op Item_Net.update \n      val net_del_int = wrap_pr_op Item_Net.remove\n\n      val net_add = Item_Net.update o `dest_param_rule\n      val net_del = Item_Net.remove o `dest_param_rule\n\n      fun net_tac_aux net ctxt i st = \n        if i > nprems_of st then \n          Seq.empty \n        else\n          let\n            val g = dest_param_goal i st\n            val rls = Item_Net.retrieve net (#rhs_head g)\n        \n            fun tac (r,thm) = \n              adjust_arity_tac (#arity r - #arity g) ctxt \n              THEN' DETERM o rtac thm\n        \n          in \n            FIRST' (map tac rls) i st\n          end\n\n      fun net_tac net ctxt = prepare_tac ctxt THEN' net_tac_aux net ctxt\n\n      structure dflt_rules = Generic_Data (\n        type T = param_net\n        val empty = net_empty\n        val extend = I\n        val merge = Item_Net.merge\n      )\n        \n      fun add_dflt thm = dflt_rules.map (net_add_int thm)\n      fun del_dflt thm = dflt_rules.map (net_del_int thm)\n      val add_dflt_attr = Thm.declaration_attribute add_dflt\n      val del_dflt_attr = Thm.declaration_attribute del_dflt\n\n      val get_dflt = dflt_rules.get o Context.Proof\n\n      val cfg_use_asm = \n        Attrib.setup_config_bool @{binding param_use_asm} (K true)\n      val cfg_single_step = \n        Attrib.setup_config_bool @{binding param_single_step} (K false)\n\n      local\n        open Refine_Util\n\n        val param_modifiers =\n          [Args.add -- Args.colon >> K (Method.modifier add_dflt_attr @{here}),\n           Args.del -- Args.colon >> K (Method.modifier del_dflt_attr @{here}),\n           Args.$$$ \"only\" -- Args.colon >>\n            K {init = Context.proof_map (dflt_rules.map (K net_empty)),\n                attribute = add_dflt_attr, pos = @{here}}]\n\n        val param_flags = \n           parse_bool_config \"use_asm\" cfg_use_asm\n        || parse_bool_config \"single_step\" cfg_single_step\n\n      in\n          \n        val parametricity_method = \n          parse_paren_lists param_flags |-- Method.sections param_modifiers >> \n          (fn _ => fn ctxt => \n            let\n              val net2 = get_dflt ctxt\n              val asm_tac = \n                if Config.get ctxt cfg_use_asm then \n                  asm_param_tac ctxt\n                else K no_tac\n   \n              val RPT = \n                if Config.get ctxt cfg_single_step then I\n                else REPEAT_ALL_NEW_FWD\n  \n            in\n              SIMPLE_METHOD' (\n                RPT (\n                  (atac \n                    ORELSE' net_tac net2 ctxt\n                    ORELSE' asm_tac)\n                ) \n              )\n            end\n          )\n      end\n\n      fun fo_rule thm = case concl_of thm of\n            @{mpat \"Trueprop ((_,_)\\<in>_\\<rightarrow>_)\"} => fo_rule (thm RS @{thm fun_relD})\n          | _ => thm \n          \n      val param_fo_attr = Scan.succeed (Thm.rule_attribute (K fo_rule))\n\n      val setup = I\n        #> Attrib.setup @{binding param} \n            (Attrib.add_del add_dflt_attr del_dflt_attr)\n            \"declaration of parametricity theorem\"\n        #> Global_Theory.add_thms_dynamic (@{binding param}, \n             map #2 o Item_Net.content o dflt_rules.get)\n        #> Method.setup @{binding parametricity} parametricity_method \n             \"Parametricity solver\"\n        #> Attrib.setup @{binding param_fo} param_fo_attr \n             \"Parametricity: Rule in first-order form\"\n\n    end\n    *}\n\n  setup Parametricity.setup\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Automatic_Refinement/Parametricity/Param_Tool.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6076631840431539, "lm_q2_score": 0.4301473485858429, "lm_q1q2_score": 0.26138470744939374}}
{"text": "theory TopoS_Interface_impl\nimports \"Lib/FiniteGraph\" \"Lib/FiniteListGraph\" TopoS_Interface TopoS_Helper\nbegin\n\nsection{*Executable Implementation with Lists*}\n  text {*Correspondence List Implementation and set Specification*}\n  \n  subsection{*Abstraction from list implementation to set specification*}\n  text{*Nomenclature: @{text \"_spec\"} is the specification, @{text \"_impl\"} the corresponding implementation.*}\n\n  text{*@{text \"_spec\"} and @{text \"_impl\"} only need to comply for @{const wf_graph}s. \n   We will always require the stricter @{const wf_list_graph}, which implies @{const wf_graph}.\n  *}\n  lemma \"wf_list_graph G \\<Longrightarrow> wf_graph (list_graph_to_graph G)\"\n    by %invisible (metis wf_list_graph_def wf_list_graph_iff_wf_graph)\n\n  locale TopoS_List_Impl = \n    fixes default_node_properties :: \"'a\" (\"\\<bottom>\") \n    and sinvar_spec::\"('v::vertex) graph \\<Rightarrow> ('v::vertex \\<Rightarrow> 'a) \\<Rightarrow> bool\"\n    and sinvar_impl::\"('v::vertex) list_graph \\<Rightarrow> ('v::vertex \\<Rightarrow> 'a) \\<Rightarrow> bool\"\n    and receiver_violation :: \"bool\"\n    and offending_flows_impl::\"('v::vertex) list_graph \\<Rightarrow> ('v \\<Rightarrow> 'a) \\<Rightarrow> ('v \\<times> 'v) list list\"\n    and node_props_impl::\"('v::vertex, 'a) TopoS_Params \\<Rightarrow> ('v \\<Rightarrow> 'a)\"\n    and eval_impl::\"('v::vertex) list_graph \\<Rightarrow> ('v, 'a) TopoS_Params \\<Rightarrow> bool\"\n    assumes\n      spec: \"SecurityInvariant sinvar_spec default_node_properties receiver_violation\" --\"specification is valid\"\n    and\n      sinvar_spec_impl: \"wf_list_graph G \\<Longrightarrow> \n        (sinvar_spec (list_graph_to_graph G) nP) = (sinvar_impl G nP)\"\n    and\n      offending_flows_spec_impl: \"wf_list_graph G \\<Longrightarrow> \n      (SecurityInvariant_withOffendingFlows.set_offending_flows sinvar_spec (list_graph_to_graph G) nP) = \n      set`set (offending_flows_impl G nP)\"\n    and \n      node_props_spec_impl: \n     \"SecurityInvariant.node_props_formaldef default_node_properties P = node_props_impl P\"\n    and\n      eval_spec_impl:\n     \"(distinct (nodesL G) \\<and> distinct (edgesL G) \\<and> \n     SecurityInvariant.eval sinvar_spec default_node_properties (list_graph_to_graph G) P ) = \n     (eval_impl G P)\"\n\n  subsection {* Security Invariants Packed*}\n\n  text {* We pack all necessary functions and properties of a security invariant in a struct-like data structure.*}\n  record ('v::vertex, 'a) TopoS_packed =\n    nm_name :: \"string\"\n    nm_receiver_violation :: \"bool\"\n    nm_default :: \"'a\"\n    nm_sinvar::\"('v::vertex) list_graph \\<Rightarrow> ('v \\<Rightarrow> 'a) \\<Rightarrow> bool\"\n    nm_offending_flows::\"('v::vertex) list_graph \\<Rightarrow> ('v \\<Rightarrow> 'a) \\<Rightarrow> ('v \\<times> 'v) list list\"\n    nm_node_props::\"('v::vertex, 'a) TopoS_Params \\<Rightarrow> ('v \\<Rightarrow> 'a)\" \n    nm_eval::\"('v::vertex) list_graph \\<Rightarrow> ('v, 'a)TopoS_Params \\<Rightarrow> bool\"\n    \n\n\n   text{*The packed list implementation must comply with the formal definition. *}\n   locale TopoS_modelLibrary =\n    fixes m :: \"('v::vertex, 'a) TopoS_packed\" -- \"concrete model implementation\"\n    and sinvar_spec::\"('v::vertex) graph \\<Rightarrow> ('v::vertex \\<Rightarrow> 'a) \\<Rightarrow> bool\" --\"specification\"\n    assumes\n       name_not_empty: \"length (nm_name m) > 0\"\n     and\n       impl_spec: \"TopoS_List_Impl \n        (nm_default m)\n        sinvar_spec\n        (nm_sinvar m)\n        (nm_receiver_violation m)\n        (nm_offending_flows m)\n        (nm_node_props m)\n        (nm_eval m)\"\n\n\n\n  subsection{*Helpful Lemmata*}\n\n  text{*show that @{term \"sinvar\"} complies*}\n  lemma TopoS_eval_impl_proofrule: \n    assumes inst: \"SecurityInvariant sinvar_spec default_node_properties receiver_violation\"\n    assumes ev: \"\\<And>nP. wf_list_graph G \\<Longrightarrow> sinvar_spec (list_graph_to_graph G) nP = sinvar_impl G nP\"\n    shows \"\n      (distinct (nodesL G) \\<and> distinct (edgesL G) \\<and> \n       SecurityInvariant.eval sinvar_spec default_node_properties (list_graph_to_graph G) P) =\n      (wf_list_graph G \\<and> sinvar_impl G (SecurityInvariant.node_props default_node_properties P))\"\n  proof (cases \"wf_list_graph G\")\n    case True\n    hence \"sinvar_spec (list_graph_to_graph G) (SecurityInvariant.node_props default_node_properties P) =\n       sinvar_impl G (SecurityInvariant.node_props default_node_properties P)\"\n      using ev by blast\n\n    with inst show ?thesis\n      unfolding wf_list_graph_def \n      by (simp add: wf_list_graph_iff_wf_graph SecurityInvariant.eval_def)\n  next\n    case False\n    hence \"(distinct (nodesL G) \\<and> distinct (edgesL G) \\<and> wf_list_graph_axioms G) = False\"\n      unfolding wf_list_graph_def by blast\n    with False show ?thesis\n      unfolding SecurityInvariant.eval_def[OF inst]\n      by (fastforce simp: wf_list_graph_iff_wf_graph)\n  qed\n\n\nsubsection {*Helper lemmata*}\n\n  text{* Provide @{term sinvar} function and get back a function that computes the list of offending flows\n  \n  Exponential time!\n  *}\n  definition Generic_offending_list:: \"('v list_graph \\<Rightarrow> ('v \\<Rightarrow> 'a) \\<Rightarrow> bool )\\<Rightarrow> 'v list_graph \\<Rightarrow> ('v \\<Rightarrow> 'a) \\<Rightarrow> ('v \\<times> 'v) list list\" where\n    \"Generic_offending_list sinvar G nP = [f \\<leftarrow> (sublists (edgesL G)). \n    (\\<not> sinvar G nP \\<and> sinvar (FiniteListGraph.delete_edges G f) nP) \\<and> \n      (\\<forall>(e1, e2)\\<in>set f. \\<not> sinvar (add_edge e1 e2 (FiniteListGraph.delete_edges G f)) nP)]\"\n  \n  \n  text{*proof rule: if @{term sinvar} complies, @{const Generic_offending_list} complies *}\n  lemma Generic_offending_list_correct: \n    assumes valid: \"wf_list_graph G\"\n    assumes spec_impl: \"\\<And>G nP. wf_list_graph G \\<Longrightarrow> sinvar_spec (list_graph_to_graph G) nP = sinvar_impl G nP\"\n    shows \"SecurityInvariant_withOffendingFlows.set_offending_flows sinvar_spec (list_graph_to_graph G) nP = \n      set`set( Generic_offending_list sinvar_impl G nP )\"\n  proof -\n    have \"\\<And> P G. set ` {x \\<in> set (sublists (edgesL G)). P G (set x)} = {x \\<in> set ` set (sublists (edgesL G)). P G (x)}\"\n      by fastforce\n    hence subset_sublists_filter: \"\\<And> G P. {f. f \\<subseteq> edges (list_graph_to_graph G) \\<and> P G f} \n    = set ` set [f\\<leftarrow>sublists (edgesL G) . P G (set f)]\"\n      unfolding list_graph_to_graph_def\n      by (auto simp: sublists_powset)\n\n    from valid delete_edges_wf have \"\\<forall>f. wf_list_graph(FiniteListGraph.delete_edges G f)\" by fast\n    with spec_impl[symmetric] FiniteListGraph.delete_edges_correct[of \"G\"] have impl_spec_delete:\n      \"\\<forall>f. sinvar_impl (FiniteListGraph.delete_edges G f) nP = \n          sinvar_spec (FiniteGraph.delete_edges (list_graph_to_graph G) (set f)) nP\" by simp\n\n    from spec_impl[OF valid, symmetric] have impl_spec_not:\n      \"(\\<not> sinvar_impl G nP) = (\\<not> sinvar_spec (list_graph_to_graph G) nP)\" by auto\n\n    from spec_impl[symmetric, OF FiniteListGraph.add_edge_wf[OF FiniteListGraph.delete_edges_wf[OF valid]]] have impl_spec_allE:\n    \"\\<forall> e1 e2 E. sinvar_impl (FiniteListGraph.add_edge e1 e2 (FiniteListGraph.delete_edges G E)) nP =\n    sinvar_spec (list_graph_to_graph (FiniteListGraph.add_edge e1 e2 (FiniteListGraph.delete_edges G E))) nP\" by simp\n\n    have list_graph: \"\\<And> e1 e2 G f. (list_graph_to_graph (FiniteListGraph.add_edge e1 e2 (FiniteListGraph.delete_edges G f))) = \n      (FiniteGraph.add_edge e1 e2 (FiniteGraph.delete_edges (list_graph_to_graph G) (set f)))\"\n    by(simp add: FiniteListGraph.add_edge_correct FiniteListGraph.delete_edges_correct)\n    \n    show ?thesis \n      unfolding SecurityInvariant_withOffendingFlows.set_offending_flows_def \n      SecurityInvariant_withOffendingFlows.is_offending_flows_min_set_def \n      SecurityInvariant_withOffendingFlows.is_offending_flows_def\n      Generic_offending_list_def\n        apply(subst impl_spec_delete)\n        apply(subst impl_spec_not)\n        apply(subst impl_spec_allE)\n        apply(subst list_graph)\n        apply(rule subset_sublists_filter)\n        done\n  qed\n\n  lemma all_edges_list_I: \"P (list_graph_to_graph G) = Pl G \\<Longrightarrow> \n    (\\<forall>(e1, e2)\\<in> (edges (list_graph_to_graph G)). P (list_graph_to_graph G) e1 e2) = (\\<forall>(e1, e2)\\<in>set (edgesL G). Pl G e1 e2)\"\n  unfolding list_graph_to_graph_def\n  by simp\n\n  lemma all_nodes_list_I: \"P (list_graph_to_graph G) = Pl G \\<Longrightarrow> \n    (\\<forall>n \\<in> (nodes (list_graph_to_graph G)). P (list_graph_to_graph G) n) = (\\<forall> n \\<in>set (nodesL G). Pl G n)\"\n  unfolding list_graph_to_graph_def\n  by simp\n\n\n\n\n\n\n  fun minimalize_offending_overapprox :: \"('v list_graph \\<Rightarrow> bool) \\<Rightarrow> \n    ('v \\<times> 'v) list \\<Rightarrow> ('v \\<times> 'v) list \\<Rightarrow> 'v list_graph \\<Rightarrow> ('v \\<times> 'v) list\" where\n  \"minimalize_offending_overapprox _ [] keep _ = keep\" |\n  \"minimalize_offending_overapprox m (f#fs) keep G = (if m (delete_edges G (fs@keep)) then\n      minimalize_offending_overapprox m fs keep G\n    else\n      minimalize_offending_overapprox m fs (f#keep) G\n    )\"\n\n  thm minimalize_offending_overapprox_boundnP (*is usage of this one better?*)\n  lemma minimalize_offending_overapprox_spec_impl:\n    assumes valid: \"wf_list_graph (G::'v::vertex list_graph)\"\n        and spec_impl: \"\\<And>G nP::('v \\<Rightarrow> 'a). wf_list_graph G \\<Longrightarrow> sinvar_spec (list_graph_to_graph G) nP = sinvar_impl G nP\"\n    shows \"minimalize_offending_overapprox (\\<lambda>G. sinvar_impl G nP) fs keeps G =\n       TopoS_withOffendingFlows.minimalize_offending_overapprox (\\<lambda>G. sinvar_spec G nP) fs keeps (list_graph_to_graph G)\"\n    apply(subst minimalize_offending_overapprox_boundnP)\n    using valid spec_impl apply(induction fs arbitrary: keeps)\n     apply(simp add: SecurityInvariant_withOffendingFlows.minimalize_offending_overapprox.simps; fail)\n    apply(simp add: SecurityInvariant_withOffendingFlows.minimalize_offending_overapprox.simps)\n    apply (metis FiniteListGraph.delete_edges_wf delete_edges_list_set list_graph_correct(5))\n    done\n\n  text{*With @{const minimalize_offending_overapprox}, we can get one offending flow*}\n  lemma minimalize_offending_overapprox_gives_some_offending_flow:\n    assumes wf: \"wf_list_graph G\"\n        and NetModelLib: \"TopoS_modelLibrary m sinvar_spec\"\n        and violation: \"\\<not> (nm_sinvar m) G nP\"\n    shows \"set (minimalize_offending_overapprox (\\<lambda>G. (nm_sinvar m) G nP) (edgesL G) [] G) \\<in>\n            SecurityInvariant_withOffendingFlows.set_offending_flows sinvar_spec (list_graph_to_graph G) nP\"\n    proof -\n      from wf have wfG: \"wf_graph (list_graph_to_graph G)\"\n        by (simp add: wf_list_graph_def wf_list_graph_iff_wf_graph)\n      from wf have dist_edges: \"distinct (edgesL G)\" by (simp add: wf_list_graph_def)\n\n      let ?spec_algo=\"TopoS_withOffendingFlows.minimalize_offending_overapprox\n                          (\\<lambda>G. sinvar_spec G nP) (edgesL G) [] (list_graph_to_graph G)\"\n\n      note spec=TopoS_List_Impl.spec[OF TopoS_modelLibrary.impl_spec[OF NetModelLib]]\n\n      from spec have spec_prelim: \"SecurityInvariant_preliminaries sinvar_spec\"\n        by(simp add: SecurityInvariant_def)\n      from spec_prelim SecurityInvariant_preliminaries.sinvar_monoI have mono:\n        \"SecurityInvariant_withOffendingFlows.sinvar_mono sinvar_spec\" by blast\n        \n      from spec_prelim have empty_edges: \"sinvar_spec \\<lparr>nodes = set (nodesL G), edges = {}\\<rparr> nP\"\n      using SecurityInvariant_preliminaries.defined_offending \n        SecurityInvariant_withOffendingFlows.sinvar_mono_imp_sinvar_mono \n        SecurityInvariant_withOffendingFlows.valid_empty_edges_iff_exists_offending_flows  \n        mono empty_subsetI graph.simps(1) \n        list_graph_to_graph_def local.wf wf_list_graph_def wf_list_graph_iff_wf_graph\n        by (metis)\n\n      (*TODO: tune*)\n      have spec_impl: \"wf_list_graph G \\<Longrightarrow> sinvar_spec (list_graph_to_graph G) nP = (nm_sinvar m) G nP\" for G nP\n        using NetModelLib TopoS_List_Impl.sinvar_spec_impl TopoS_modelLibrary.impl_spec by fastforce\n      \n      from minimalize_offending_overapprox_spec_impl[OF wf] spec_impl have alog_spec:\n        \"minimalize_offending_overapprox (\\<lambda>G. (nm_sinvar m) G nP) fs keeps G =\n         TopoS_withOffendingFlows.minimalize_offending_overapprox (\\<lambda>G. sinvar_spec G nP) fs keeps (list_graph_to_graph G)\"\n         for fs keeps by blast\n\n      (*TODO: tune*)\n      from spec_impl violation have\n        \"SecurityInvariant_withOffendingFlows.is_offending_flows sinvar_spec (set (edgesL G)) (list_graph_to_graph G) nP\"\n        apply(simp add: SecurityInvariant_withOffendingFlows.is_offending_flows_def)\n        apply(intro conjI)\n         apply (simp add: local.wf; fail)\n        apply(simp add: FiniteGraph.delete_edges_simp2 list_graph_to_graph_def)\n        apply(simp add: empty_edges)\n        done\n      hence goal: \"SecurityInvariant_withOffendingFlows.is_offending_flows_min_set sinvar_spec\n        (set ?spec_algo) (list_graph_to_graph G) nP\"\n      apply(subst minimalize_offending_overapprox_boundnP) (*we do this subst pretty often. is this the right abstraction here?*)\n      apply(rule SecurityInvariant_withOffendingFlows.is_offending_flows_min_set_minimalize_offending_overapprox[OF\n              mono wfG _ _ dist_edges])\n       apply(simp add: list_graph_to_graph_def)+\n      done\n\n      from SecurityInvariant_withOffendingFlows.minimalize_offending_overapprox_subseteq_input[of\n        \"sinvar_spec\" \"(edgesL G)\" \"[]\"] have subset_edges:\n        \"set ?spec_algo \\<subseteq> edges (list_graph_to_graph G)\" \n        apply(subst minimalize_offending_overapprox_boundnP)\n        by(simp add: list_graph_to_graph_def)\n\n      from goal show ?thesis\n        by(simp add: SecurityInvariant_withOffendingFlows.set_offending_flows_def alog_spec subset_edges)\n    qed\n\n\n\n\n\n\n(*TODO: this should be a header of TopoS_Libary. The header should be printed BEFORE the imports are processed. *)\nsection{*Security Invariant Library*}\n(*The SINVAR_* theory files all use the \"subsection\" command. Here is the top-section.*)\n\nend\n", "meta": {"author": "diekmann", "repo": "topoS", "sha": "4303ebd95a501283c02fd513c109e645a48ad080", "save_path": "github-repos/isabelle/diekmann-topoS", "path": "github-repos/isabelle/diekmann-topoS/topoS-4303ebd95a501283c02fd513c109e645a48ad080/thy/Network_Security_Policy_Verification/TopoS_Interface_impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297746213017459, "lm_q2_score": 0.4148988457967688, "lm_q1q2_score": 0.26129276349019154}}
{"text": "theory Extra2\n  imports ExtraInv VCTheoryLemmas\nbegin\n\nabbreviation s where \"s s0 userAtTop_value userAtBottom_value directionSwitch_value alarmButton_value stuck_value \\<equiv>\n(toEnv\n             (setPstate (setVarAny s0 userAtTop_value userAtBottom_value directionSwitch_value alarmButton_value stuck_value) ERROR\n               Ctrl'emergency))\"\n\ntheorem extra2: \"VC2 extraInv env s0 userAtTop_value userAtBottom_value directionSwitch_value alarmButton_value stuck_value\"\n  apply(simp only: VC2_def extraInv_def)\n  apply(rule impI)\n  apply(rule conjI)\n   apply simp\n  subgoal\n    apply((drule conjE[of _ _ ?thesis])+)\n                        defer\n                        apply assumption+\n    subgoal premises prems\n      apply(rule conjI)\n      using prems(1-4) prems(5) apply simp\n      apply(rule conjI)\n      using prems(1-4) prems(6) apply simp\n      apply(rule conjI)\n      using prems(1-4) prems(7) apply simp\n apply(rule conjI)\n      using prems(1-4) prems(8) apply simp\n apply(rule conjI)\n      using prems(1-4) prems(9) apply simp\n apply(rule conjI)\n      using prems(1-4) prems(10) apply simp\n apply(rule conjI)\n      using prems(1-4) prems(11) apply simp\n apply(rule conjI)\n      using prems(1-4) prems(12) apply simp\n apply(rule conjI)\n      using prems(1-4) prems(13) apply simp\n apply(rule conjI)\n      using prems(1-4) prems(14) apply simp\n apply(rule conjI)\n      using prems(1-4) prems(15) apply simp\n apply(rule conjI)\n      using prems(1-4) prems(16) apply simp\n      apply(rule conjI)\n       apply(rule allI)\n      subgoal for s1\n        apply(cases \"s1 = s s0 userAtTop_value userAtBottom_value directionSwitch_value alarmButton_value stuck_value\")\n         apply(rule impI)\n         apply(rule exI[of _ s0])\n         apply(rule exI[of _ \"s s0 userAtTop_value userAtBottom_value directionSwitch_value alarmButton_value stuck_value\"])\n        using prems(1-4) substate_refl toEnvNum_id apply -\n         apply(((rule conjI),simp)+)\n        using substate_trans substate_antisym\n         apply (metis le_numeral_extra(4) not_one_le_zero)\n        using prems(17) by simp\n apply(rule conjI)\n      using prems(1-4) prems(18) apply simp\n apply(rule conjI)\n      using prems(1-4) prems(19) apply simp\n apply(rule conjI)\n      using prems(1-4) prems(20) apply simp\n      using prems(1-4) prems(21) by simp\n    done\n  done\n\nend     \n      ", "meta": {"author": "ivchernenko", "repo": "post_vcgenerator", "sha": "fadfff131086870a027d6bd1c78b8d5a3baf183b", "save_path": "github-repos/isabelle/ivchernenko-post_vcgenerator", "path": "github-repos/isabelle/ivchernenko-post_vcgenerator/post_vcgenerator-fadfff131086870a027d6bd1c78b8d5a3baf183b/case-studies/escalator/Extra2.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5813030906443133, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.26123332732715493}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the GNU General Public License version 2. Note that NO WARRANTY is provided.\n * See \"LICENSE_GPLv2.txt\" for details.\n *\n * @TAG(NICTA_GPL)\n *)\n\ntheory CreateIRQCaps_SI\nimports\n  \"../proof/capDL-api/IRQ_DP\"\n  ObjectInitialised_SI\n  RootTask_SI\n  SysInit_SI\nbegin\n\n(*****************\n * Helper lemmas *\n *****************)\n\n\n\nlemma si_cnode_caps:\n  \"si_cnode_cap = si_cspace_cap\"\n  by (simp add: si_cnode_cap_def si_cspace_cap_def)\n\nlemma hoare_grab_exs2:\n  \"(\\<And>x. P x \\<Longrightarrow> \\<lbrace>P' x\\<rbrace> f \\<lbrace>Q\\<rbrace>) \\<Longrightarrow> \\<lbrace>\\<lambda>s. \\<exists>x. P x \\<and> P' x s\\<rbrace> f \\<lbrace>Q\\<rbrace>\"\n  by (fastforce simp: valid_def)\n\nlemma sep_map_irq_sep_irq_node:\n  \"(irq \\<mapsto>irq k_irq_table irq \\<and>* R) s\n  \\<Longrightarrow> sep_irq_node s irq = Some (k_irq_table irq)\"\n  by (fastforce simp: sep_map_irq_def sep_conj_def\n                      sep_disj_sep_state_def sep_state_disj_def\n                      plus_sep_state_def sep_state_add_def\n                      map_disj_def map_add_Some_iff)\n\n(*********************************************************************************\n * A new definition of si_irq_nodes that states that the mapping is injective. *\n *********************************************************************************)\n\nlemma sep_map_o_distinct:\n  \"(obj_id \\<mapsto>o obj \\<and>* obj_id' \\<mapsto>o obj') s \\<Longrightarrow> obj_id \\<noteq> obj_id'\"\n  by (fastforce simp: sep_map_o_def sep_map_general_def sep_conj_def object_to_sep_state_def\n                      sep_disj_sep_state_def sep_state_disj_def\n                      map_disj_def dom_def disjoint_iff_not_equal)\n\nlemma sep_any_map_o_false_eq:\n  \"(obj_id \\<mapsto>o - \\<and>* obj_id \\<mapsto>o -) = sep_false\"\n  by (fastforce simp: sep_any_def sep_map_o_def sep_map_general_def sep_conj_def\n                      object_to_sep_state_def sep_disj_sep_state_def sep_state_disj_def\n                      map_disj_def dom_def disjoint_iff_not_equal)\n\nlemma sep_any_map_o_false:\n  \"(obj_id \\<mapsto>o - \\<and>* obj_id \\<mapsto>o -) s \\<Longrightarrow> False\"\n  by (simp add: sep_any_map_o_false_eq)\n\nlemma sep_map_o_false:\n  \"(obj_id \\<mapsto>o obj \\<and>* obj_id \\<mapsto>o obj') s \\<Longrightarrow> False\"\n  by (metis sep_map_o_distinct)\n\nlemma sep_map_o_any_distinct_list:\n  \"((f x) \\<mapsto>o - \\<and>* \\<And>* map (\\<lambda>x. (f x) \\<mapsto>o -) xs) s\n  \\<Longrightarrow> x \\<notin> set xs\"\n  apply clarsimp\n  apply (subst (asm) sep_list_conj_map_remove1, assumption)\n  apply (sep_drule sep_any_map_o_false)\n  apply clarsimp\n  done\n\nlemma sep_any_map_o_inj_on:\n  \"(\\<And>* map (\\<lambda>x. (f x) \\<mapsto>o -) xs) s\n  \\<Longrightarrow> inj_on f (set xs)\"\n  apply (induct xs arbitrary: s)\n   apply clarsimp\n  apply clarsimp\n  apply (rule conjI)\n   apply (clarsimp simp: sep_conj_def)\n  apply clarsimp\n  apply (frule sep_map_o_any_distinct_list)\n  apply simp\n  done\n\nlemma sep_any_map_o_inj_on_set:\n  \"\\<lbrakk>(\\<And>* x \\<in> A. (f x) \\<mapsto>o -) s; finite A\\<rbrakk>\n  \\<Longrightarrow> inj_on f A\"\n  apply (drule sep_map_set_conj_sep_list_conj [where P=\"\\<lambda>x. (f x) \\<mapsto>o -\"])\n  apply clarsimp\n  apply (erule sep_any_map_o_inj_on)\n  done\n\nlemma sep_map_o_inj_on_set:\n  \"\\<lbrakk>(\\<And>* x \\<in> A. (f x) \\<mapsto>o obj) s; finite A\\<rbrakk>\n  \\<Longrightarrow> inj_on f A\"\n  apply (rule sep_any_map_o_inj_on_set [rotated, where s=s], assumption)\n  apply (erule sep_map_set_conj_impl)\n   apply (fastforce simp: sep_any_def)\n  apply simp\n  done\n\nlemma sep_conj_existL:\n  \"(P \\<and>* Q) s \\<Longrightarrow> \\<exists>s. P s\"\n  by (auto simp: sep_conj_def)\n\nlemma sep_conj_existR:\n  \"(P \\<and>* Q) s \\<Longrightarrow> \\<exists>s. Q s\"\n  by (auto simp: sep_conj_def)\n\nlemma si_irq_nodes_def2:\n  \"si_irq_nodes spec =\n     (\\<lambda>s. \\<exists>k_irq_table. inj_on k_irq_table (used_irqs spec) \\<and>\n                        (\\<And>* irq\\<in>used_irqs spec. irq \\<mapsto>irq k_irq_table irq \\<and>*\n                                                 k_irq_table irq \\<mapsto>o IRQNode empty_irq_node) s)\"\n  apply (rule ext)\n  apply (clarsimp simp: si_irq_nodes_def)\n  apply (rule iffI)\n   apply clarsimp\n   apply (rule_tac x=k_irq_table in exI, simp)\n   apply (subst (asm) sep.prod.distrib)\n   apply (drule sep_conj_existR, clarsimp)\n    apply (erule sep_map_o_inj_on_set) (* Why doesn't sep_rule work? *)\n   apply simp\n  apply blast\n  done\n\n\n\n(*******************************************\n * The actual proofs about create_irq_caps *\n *******************************************)\n\nlemma well_formed_default_irq_node_empty:\n  \"\\<lbrakk>well_formed spec; irq \\<in> used_irqs spec\\<rbrakk>\n    \\<Longrightarrow> object_at (\\<lambda>obj. object_default_state obj = IRQNode empty_irq_node) (cdl_irq_node spec irq) spec\"\n  apply (frule (1) well_formed_used_irqs_have_irq_node, clarsimp)\n  apply (frule (1) well_formed_irq_is_irq_node)\n  apply (frule (1) well_formed_size_irq_node)\n  apply (clarsimp simp: object_at_def empty_irq_node_def object_default_state_def2\n                        is_irq_node_def object_size_bits_def\n                 split: cdl_object.splits)\n  done\n\nlemma create_irq_cap_sep:\n  \"\\<lbrace>\\<guillemotleft>(si_cnode_id, unat free_cptr) \\<mapsto>c NullCap \\<and>*\n      irq \\<mapsto>irq kernel_irq_id \\<and>*\n      kernel_irq_id \\<mapsto>o (IRQNode empty_irq_node) \\<and>*\n      si_objects \\<and>* R\\<guillemotright> and\n    K(well_formed spec \\<and>\n      irq \\<in> used_irqs spec \\<and>\n      t' (cdl_irq_node spec irq) = Some kernel_irq_id \\<and>\n      irq_caps irq = Some free_cptr \\<and>\n      free_cptr < 2 ^ si_cnode_size)\\<rbrace>\n   create_irq_cap spec (irq, free_cptr)\n   \\<lbrace>\\<lambda>_.\n    \\<guillemotleft>irq_empty spec t' irq \\<and>*\n     si_irq_cap_at irq_caps spec irq \\<and>*\n     si_objects \\<and>*\n     R\\<guillemotright>\\<rbrace>\"\n  apply (rule hoare_gen_asm, clarsimp)\n  apply (frule (1) well_formed_used_irqs_have_irq_node, clarsimp)\n  apply (frule (1) well_formed_default_irq_node_empty, clarsimp simp: object_at_def)\n  apply (clarsimp simp: create_irq_cap_def si_objects_def si_cnode_caps\n                        irq_empty_def irq_initialised_general_def\n                        si_irq_cap_at_def sep_conj_assoc)\n  apply (wp add: hoare_drop_imp sep_wp: seL4_IRQHandler_IRQControl_Get, simp)\n  apply (rule conjI)\n   apply sep_solve\n  apply (simp add: offset_slot_si_cnode_size' guard_equal_si_cspace_cap word_bits_def)\n  done\n\nlemma create_irq_caps_sep_helper:\n  \"\\<lbrace>\\<guillemotleft>((\\<And>* cptr \\<in> set (take (card (used_irqs spec)) free_cptrs).\n           ((si_cnode_id, unat cptr) \\<mapsto>c NullCap)) \\<and>*\n      si_caps_at t orig_caps spec dev {obj_id. real_object_at obj_id spec} \\<and>*\n      si_objects \\<and>* si_irq_nodes spec \\<and>* R)  and\n   K (well_formed spec \\<and>\n      list_all (\\<lambda>n. n < 2 ^ si_cnode_size) free_cptrs \\<and>\n      distinct free_cptrs \\<and>\n      card (used_irqs spec) \\<le> length free_cptrs)\\<guillemotright> \\<rbrace>\n  create_irq_caps spec free_cptrs\n   \\<lbrace>\\<lambda>rv s. \\<exists>(t'::32 word \\<Rightarrow> 32 word option).\n    \\<guillemotleft>(irqs_empty spec t' (used_irqs spec) \\<and>*\n      si_irq_caps_at (fst rv) spec (used_irqs spec) \\<and>*\n      si_caps_at t orig_caps spec dev {obj_id. real_object_at obj_id spec} \\<and>*\n      si_objects \\<and>* R)\n    and K ((map_of (zip (used_irq_list spec) free_cptrs), drop (card (used_irqs spec)) free_cptrs) = rv \\<and>\n    inj_on t' (used_irq_nodes spec) \\<and>\n    dom t' = used_irq_nodes spec)\\<guillemotright> s\\<rbrace>\"\n  including no_pre\n  apply clarsimp\n  apply (rule hoare_gen_asm_conj)\n  apply (clarsimp simp: create_irq_caps_def si_irq_nodes_def2 sep_conj_exists)\n  apply wp\n  apply simp\n  apply (rule hoare_grab_exs2)\n  apply (rule_tac x=\"(\\<lambda>obj_id. Some ((k_irq_table \\<circ> inv (cdl_irq_node spec)) obj_id))\n                     |` used_irq_nodes spec\" in hoare_exI)\n\n  apply (rule_tac P1 = \"\\<lambda>(irq,free_cptr). (si_cnode_id, unat free_cptr) \\<mapsto>c NullCap \\<and>*\n                                           irq \\<mapsto>irq k_irq_table irq \\<and>*\n                                           k_irq_table irq \\<mapsto>o IRQNode empty_irq_node\" and\n                  Q1 = \"\\<lambda>(irq,free_cptr). irq_empty spec ((\\<lambda>obj_id. Some ((k_irq_table \\<circ> inv (cdl_irq_node spec)) obj_id))\n                                                           |` used_irq_nodes spec) irq \\<and>*\n                                          si_irq_cap_at (map_of (zip (used_irq_list spec) free_cptrs)) spec irq\" and\n                  I1 = \"si_objects\" and\n                  R1 = \"si_caps_at t orig_caps spec dev {obj_id. real_object_at obj_id spec} \\<and>*\n                        R\" in hoare_chain [OF mapM_x_set_sep])\n     apply (metis distinct_zipI2)\n    apply (clarsimp split:prod.splits)\n    apply (clarsimp simp: sep_conj_assoc)\n    apply (wp sep_wp: create_irq_cap_sep, simp+)\n    apply (rule conjI)\n     apply (clarsimp simp: sep_conj_assoc sep_conj_exists)\n     apply sep_solve\n    apply (frule well_formed_inj_cdl_irq_node)\n    apply (frule set_zip_leftD)\n    apply (frule in_set_zip2)\n    apply (simp add: map_of_zip_tuple_in list_all_iff unat_less_2_si_cnode_size\n                     restrict_map_def used_irq_nodes_def)\n\n   apply (subst sep_list_conj_sep_map_set_conj [symmetric], erule distinct_zipI2)\n   apply (subst (asm) sep_list_conj_sep_map_set_conj [symmetric, where xs = \"used_irq_list spec\", simplified])\n   apply (subst split_beta')\n   apply (subst sep_list_conj_map_add)\n   apply (subst zip_take_length [symmetric])\n   apply (subst split_beta' [symmetric])+\n   apply (subst map_zip_snd', simp)\n\n   apply (subst (asm) (3) append_take_drop_id [where n=\"card (used_irqs spec)\" and xs=free_cptrs, symmetric])\n   apply (subst map_zip_fst', simp)\n   apply (subst sep_list_conj_sep_map_set_conj, fastforce simp: used_irq_list_def)\n   apply (simp add: comp_def)\n   apply sep_solve\n\n  apply simp\n  apply (subst (asm) sep_list_conj_sep_map_set_conj [symmetric], erule distinct_zipI2)\n  apply (subst (asm) map_zip_fst', simp)\n  apply (subst (asm) sep_list_conj_map_add)\n  apply (subst (asm) sep_list_conj_sep_map_set_conj,\n         metis used_irq_list_def distinct_sorted_list_of_set)\n  apply (subst (asm) sep_list_conj_sep_map_set_conj,\n         metis used_irq_list_def distinct_sorted_list_of_set)\n  apply (clarsimp simp: irqs_empty_def si_irq_caps_at_def)\n  apply (rule conjI)\n   apply sep_solve\n  apply (frule well_formed_inj_cdl_irq_node)\n  apply (fastforce simp: inj_on_def used_irq_nodes_def)\n  done\n\n\n\n\n\n(*****************************************************************************\n * The above lemma has an injection on just the IRQs.                        *\n * We take the above proof, and join it with the result of CreateObjects     *\n * to produce an injection on all objects.                                   *\n *                                                                           *\n * The sum of the two injections \"t_irqs\" and \"t_real\" is injective because: *\n *  - Each individual relation is injective                                  *\n *  - The domains are separate                                               *\n *  - The ranges are separate                                                *\n *                                                                           *\n * The first two are easily true.                                            *\n * The last one is hard and only true because we have                        *\n     obj_id \\<mapsto>o Untyped \\<and>* obj_id \\<mapsto> IRQ, and so the obj_ids are distinct.   *\n *****************************************************************************)\n\nlemma irq_empty_cong:\n  \"t (cdl_irq_node spec irq) = t' (cdl_irq_node spec irq)\n  \\<Longrightarrow> irq_empty spec t irq = irq_empty spec t' irq\"\n  by (clarsimp simp: irq_empty_def irq_initialised_general_def)\n\nlemma object_empty_cong:\n  \"t obj_id = t' obj_id\n  \\<Longrightarrow> object_empty spec t obj_id = object_empty spec t' obj_id\"\n  by (clarsimp simp: object_empty_def object_initialised_general_def)\n\nlemma si_cap_at_cong:\n  \"t obj_id = t' obj_id\n  \\<Longrightarrow> si_cap_at  t si_caps spec dev obj_id = si_cap_at  t' si_caps spec dev obj_id\"\n  by (clarsimp simp: si_cap_at_def)\n\nlemma irq_empty_map_add:\n  \"\\<lbrakk>dom t' = cdl_irq_node spec ` irqs\\<rbrakk>\n  \\<Longrightarrow> irqs_empty spec t' irqs = irqs_empty spec (t++t') irqs\"\n  apply (clarsimp simp: irqs_empty_def)\n  apply (rule sep.prod.cong, simp)\n  apply (subst irq_empty_cong [where t'=\"t++t'\" and t=t'], simp_all)\n  by (metis imageI map_add_eval_right)\n\nlemma object_empty_map_add:\n  \"\\<lbrakk>dom t = obj_ids; map_disj t t'\\<rbrakk>\n  \\<Longrightarrow> objects_empty spec t obj_ids = objects_empty spec (t++t') obj_ids\"\n  apply (clarsimp simp: objects_empty_def)\n  apply (rule sep.prod.cong, simp)\n  apply (subst object_empty_cong [where t'=\"t++t'\" and t=t], simp_all)\n  by (metis map_add_eval_left)\n\nlemma si_caps_at_map_add:\n  \"\\<lbrakk>dom t = obj_ids; map_disj t t'\\<rbrakk>\n  \\<Longrightarrow> si_caps_at t si_caps spec dev obj_ids = si_caps_at (t++t') si_caps spec dev obj_ids\"\n  apply (clarsimp simp: si_caps_at_def)\n  apply (rule sep.prod.cong, simp)\n  apply (subst si_cap_at_cong [where t'=\"t++t'\" and t=t], simp_all)\n  by (metis map_add_eval_left)\n\n\nlemma inj_on_map_add:\n  \"\\<lbrakk>inj_on m (dom m); inj_on m' (dom m');\n    dom m \\<inter> dom m' = {}; ran m \\<inter> ran m' = {}; A = dom m \\<union> dom m'\\<rbrakk>\n  \\<Longrightarrow> inj_on (m ++ m') A\"\n  apply (rule inj_onI)\n  apply clarsimp\n  apply (elim disjE)\n     apply (metis inj_on_eq_iff inter_empty_not_both map_add_eval_left')\n    apply (metis dom_ran map_add_comm map_add_eval_right orthD1)\n   apply (metis dom_ran map_add_comm map_add_eval_right orthD1)\n  apply (metis inj_on_def map_add_eval_right)\n  done\n\nlemma inter_emptyI:\n  \"\\<lbrakk>\\<And>x. x \\<in> A \\<and> x \\<in> B \\<Longrightarrow> False\\<rbrakk>  \\<Longrightarrow> A \\<inter> B = {}\"\n  by auto\n\nlemma ran_inter_emptyI:\n  \"\\<lbrakk>\\<And>x a b. f a = Some x \\<and> g b = Some x \\<Longrightarrow> False\\<rbrakk> \\<Longrightarrow> ran f \\<inter> ran g = {}\"\n  apply (rule inter_emptyI)\n  apply (auto simp: ran_def)\n  done\n\nlemma irq_empty_objects_empty_ran_distinct:\n  \"\\<lbrakk>\\<guillemotleft>irqs_empty spec t_irq (used_irqs spec) \\<and>*\n    objects_empty spec t_real {obj_id. real_object_at obj_id spec} \\<and>* R\\<guillemotright> s;\n    well_formed spec;\n    inj_on t_irq (cdl_irq_node spec ` used_irqs spec); dom t_irq = cdl_irq_node spec ` used_irqs spec;\n    inj_on t_real {obj_id. real_object_at obj_id spec}; dom t_real = {obj_id. real_object_at obj_id spec}\\<rbrakk>\n  \\<Longrightarrow> ran t_real \\<inter> ran t_irq = {}\"\n  apply (frule well_formed_inj_cdl_irq_node)\n  apply (clarsimp simp: irqs_empty_def irq_empty_def irq_initialised_general_def\n                        objects_empty_def object_empty_def object_initialised_general_def)\n  apply (rule ran_inter_emptyI)\n  apply clarsimp\n  apply (frule domI [where m=t_real])\n  apply (frule domI [where m=t_irq])\n  apply clarsimp\n  apply (rename_tac irq_obj_id obj_id irq)\n  apply (subst (asm) sep.prod.remove, simp, assumption)\n  apply (subst (asm) sep.prod.remove, simp, fast)\n  apply (clarsimp simp: sep_conj_exists sep_conj_assoc)\n  apply (sep_drule sep_map_o_false, simp)\n  done\n\n\nlemma si_objects_extra_caps'_split:\n  \"\\<lbrakk>well_formed spec; distinct free_cptrs';\n   free_cptrs = drop (card {obj_id. real_object_at obj_id spec}) free_cptrs'\\<rbrakk> \\<Longrightarrow>\n   si_objects_extra_caps' {obj_id. real_object_at obj_id spec} free_cptrs' untyped_cptrs\n    =\n  ((\\<And>* cptr \\<in> set (take (card (used_irqs spec)) free_cptrs). (si_cnode_id, unat cptr) \\<mapsto>c NullCap) \\<and>*\n   si_objects_extra_caps' (dom (cdl_objects spec)) free_cptrs' untyped_cptrs)\"\n  apply (frule well_formed_objects_card [symmetric])\n  apply (subst (asm) add.commute)\n  apply (clarsimp simp: si_objects_extra_caps'_def sep_conj_exists sep_conj_assoc)\n  apply (subst take_drop_append [where a=\"card {obj_id. real_object_at obj_id spec}\"\n                                   and b=\"card (used_irqs spec)\"])\n  apply clarsimp\n  apply (subst sep.prod.union_disjoint, (simp add: distinct_take_drop_append)+)\n  apply (clarsimp simp: sep_conj_ac)\n  done\n\n\nlemma create_irq_caps_sep:\n  \"\\<lbrace>\\<lambda>s. \\<exists>t_real.\n    \\<guillemotleft>(objects_empty spec t_real {obj_id. real_object_at obj_id spec} \\<and>*\n      si_caps_at t_real orig_caps spec dev {obj_id. real_object_at obj_id spec} \\<and>*\n      si_objects \\<and>*\n      si_objects_extra_caps' {obj_id. real_object_at obj_id spec} free_cptrs_orig untyped_cptrs \\<and>*\n      si_irq_nodes spec \\<and>* R)  and\n   K (well_formed spec \\<and>\n      distinct free_cptrs_orig \\<and>\n      list_all (\\<lambda>n. n < 2 ^ si_cnode_size) free_cptrs \\<and>\n      card (used_irqs spec) \\<le> length free_cptrs \\<and>\n      inj_on t_real {obj_id. real_object_at obj_id spec} \\<and>\n      dom t_real = {obj_id. real_object_at obj_id spec} \\<and>\n      dom orig_caps = {obj_id. real_object_at obj_id spec} \\<and>\n      free_cptrs = drop (card {obj_id. real_object_at obj_id spec}) free_cptrs_orig)\\<guillemotright> s\\<rbrace>\n  create_irq_caps spec free_cptrs\n   \\<lbrace>\\<lambda>rv s. \\<exists>(t::32 word \\<Rightarrow> 32 word option).\n    \\<guillemotleft>(objects_empty spec t {obj_id. real_object_at obj_id spec} \\<and>*\n      irqs_empty spec t (used_irqs spec) \\<and>*\n      si_caps_at t orig_caps spec dev {obj_id. real_object_at obj_id spec} \\<and>*\n      si_irq_caps_at (fst rv) spec (used_irqs spec) \\<and>*\n      si_objects \\<and>*\n      si_objects_extra_caps' (dom (cdl_objects spec)) free_cptrs_orig untyped_cptrs \\<and>*\n      R) and\n    K ((map_of (zip (used_irq_list spec) free_cptrs), drop (card (used_irqs spec)) free_cptrs) = rv \\<and>\n       inj_on t (dom (cdl_objects spec)) \\<and> dom t = dom (cdl_objects spec))\\<guillemotright> s\\<rbrace>\"\n  apply (rule hoare_ex_pre)\n  apply (rule hoare_gen_lifted_asm)\n  apply (elim conjE)\n  apply (subst si_objects_extra_caps'_split, assumption+)\n  apply (rule hoare_chain [OF create_irq_caps_sep_helper, where orig_caps1=orig_caps])\n   apply (rule pred_andI)\n    apply sep_solve\n   apply clarsimp\n  apply clarsimp\n  apply (rule_tac x=\"t_real ++ t'\" in exI)\n  apply clarsimp\n  apply (frule well_formed_objects_real_or_irq)\n  apply (frule well_formed_objects_only_real_or_irq)\n  apply (clarsimp simp: used_irq_nodes_def)\n  apply (subgoal_tac \"map_disj t_real t'\")\n   apply (rule conjI)\n    apply (subst object_empty_map_add [symmetric], assumption+)\n    apply (subst irq_empty_map_add [symmetric],simp add: used_irq_nodes_def)\n    apply (subst si_caps_at_map_add [symmetric], assumption+)\n    apply (clarsimp simp: si_objects_extra_caps'_def sep_conj_exists sep_conj_assoc)\n    apply (rule_tac x=untyped_caps in exI)\n    apply (rule_tac x=all_available_ids in exI)\n    apply sep_solve\n   apply (rule conjI)\n    apply (rule inj_on_map_add, simp+)\n     apply (rule irq_empty_objects_empty_ran_distinct, sep_solve, simp+)\n   apply (metis sup_commute)\n  apply (clarsimp simp: map_disjI)\n  done\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/l4v/sys-init/CreateIRQCaps_SI.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331319177488, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.26113244080387116}}
{"text": "theory WTLemma\n  imports GenSubEnv WellTypedExp PermEnvMisc NormEnv \nbegin\n    \n    (* \n      ####################################\n        P2. general well-typed lemmas\n      ####################################\n    *)\n\nlemma well_typed_perm_leq: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx \\<rbrakk> \\<Longrightarrow> leq_use_env r_s2 r_s1\"\n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n        apply (auto)\n      apply (rule_tac r_sb=\"diff_use_env r_s1 (comp_use_env (ereq_use_env x1a tau_x) r_ex)\" in trans_leq_use_env)\n       apply (rule_tac self_diff_leq_use_env)\n      apply (simp)\n     apply (rule_tac r_sb=\"diff_use_env r_s3 r_ex\" in trans_leq_use_env)\n      apply (rule_tac diff_leq_use_env)\n      apply (rule_tac r_sb=\"r_s2a\" in trans_leq_use_env)\n       apply (auto)\n    apply (rule_tac r_sb=\"r_s2a\" in trans_leq_use_env)\n     apply (auto)\n   apply (rule_tac r_sb=\"diff_use_env r_s1 r_ex\" in trans_leq_use_env)\n    apply (rule_tac self_diff_leq_use_env)\n   apply (simp)\n  apply (rule_tac r_sb=\"r_s2a\" in trans_leq_use_env)\n   apply (auto)\n  apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n   apply (auto)\n  apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n   apply (rule_tac self_diff_leq_use_env)\n  apply (simp)\n  done\n\nlemma well_typed_perm_leqx: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx \\<rbrakk> \\<Longrightarrow> leq_use_env rx r_s2\"    \n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n       apply (auto)\n    (* if case *)\n  apply (rule_tac dist_comp_leq_use_env)\n   apply (auto)\n  done\n\nlemma well_typed_spec_perm_leq: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx \\<rbrakk> \\<Longrightarrow> leq_perm (r_s2 x) (r_s1 x)\"\n  apply (cut_tac ?r_s2.0=\"r_s2\" and ?r_s1.0=\"r_s1\" in well_typed_perm_leq)\n   apply (auto)\n  apply (simp add: leq_use_env_def)\n  done       \n  \n    (* \n      ####################################\n        P3. well-typed free var lemmas\n      ####################################\n    *)\n    \nlemma well_typed_fv_env_use: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; x \\<in> free_vars e \\<rbrakk> \\<Longrightarrow> env x \\<noteq> None\"\n  (*apply (simp add: env_gen_use_def)*)\n  apply (induction e arbitrary: env tau r_s1 r_s2 rx)\n       apply (auto)\n  apply (case_tac \"\\<exists> y. add_env env x1a t1 x = Some y\")\n   apply (simp add: add_env_def)\n   apply (auto)\n  done\n    \nlemma well_typed_rv_env_use: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; x \\<in> ref_vars e \\<rbrakk> \\<Longrightarrow> env x \\<noteq> None\"\n  (*apply (simp add: env_gen_use_def)*)\n  apply (induction e arbitrary: env tau r_s1 r_s2 rx)\n        apply (auto)\n   apply (case_tac \"x = x1a\")\n    apply (auto)\n   apply (case_tac x2a)\n     apply (auto)\n   apply (simp add: deref_name_def)\n  apply (case_tac \"x = x1a\")\n   apply (auto)\n  apply (case_tac \"\\<exists> y. add_env env x1a t1 x = Some y\")\n   apply (simp add: add_env_def)\n   apply (auto)\n  done    \n    \nlemma well_typed_no_npv_use: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; r_s1 x = NoPerm \\<rbrakk> \\<Longrightarrow> x \\<notin> non_prim_vars env e\"\n  apply (induction e arbitrary: env r_s1 tau r_s2 rx)\n       apply (auto)\n    (* const + op case *)\n        apply (simp add: non_prim_vars_def)\n       apply (simp add: non_prim_vars_def)\n    (* var case. *)\n      apply (cut_tac r_x=\"ereq_use_env x1a tau_x\" and r_s=\"r_s1\" in leq_use_none)\n        apply (auto)\n      apply (case_tac \"x \\<noteq> x1a\")\n       apply (simp add: non_prim_vars_def)\n      apply (cut_tac x=\"x\" and tau=\"tau_x\" in ereq_use_none)\n       apply (auto)\n      apply (simp add: non_prim_vars_def)\n      apply (simp add: non_prim_entry_def)\n    (* pair case 1 *)\n     apply (case_tac \"x \\<notin> free_vars (PairExp e1 e2)\")\n      apply (simp add: non_prim_vars_def)\n     apply (auto)\n      apply (simp add: non_prim_vars_def)\n    (* pair case 2 *)\n     apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" and x=\"x\" in leq_use_none)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n     apply (simp add: non_prim_vars_def)\n    (* if case 1 *)\n    apply (case_tac \"x \\<notin> free_vars (IfExp e1 e2 e3)\")\n     apply (simp add: non_prim_vars_def)\n    apply (auto)\n      apply (case_tac \"x \\<notin> non_prim_vars env e1\")\n      apply (simp add: non_prim_vars_def)\n      apply (auto)\n    (* if case 2 *)\n     apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" and x=\"x\" in leq_use_none)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n     apply (case_tac \"x \\<notin> non_prim_vars env e2\")\n      apply (simp add: non_prim_vars_def)\n     apply (auto)\n    (* if case 3 *)\n     apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" and x=\"x\" in leq_use_none)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n    apply (case_tac \"x \\<notin> non_prim_vars env e3\")\n     apply (simp add: non_prim_vars_def)\n    apply (auto)\n    (* lambda case *)\n    apply (case_tac \"x \\<noteq> x1a\")\n     apply (auto)\n    apply (cut_tac r_x=\"rxa\" and r_s=\"r_s1\" and x=\"x\" in leq_use_none)\n      apply (auto)\n    apply (cut_tac r_s=\"rxa\" and y=\"x1a\" and r=\"r\" and x=\"x\" in add_use_none_rev)\n      apply (auto)\n    apply (case_tac \"x \\<notin> non_prim_vars (add_env env x1a t1) e\")\n     apply (simp add: non_prim_vars_def)\n    apply (case_tac \"\\<not> non_prim_entry (add_env env x1a t1) x\")\n      apply (simp add: non_prim_entry_def)\n      apply (simp add: add_env_def)\n      apply (auto)\n   apply (simp add: non_prim_vars_def)\n    (* app case 1 *)\n  apply (case_tac \"x \\<notin> free_vars (AppExp e1 e2)\")\n   apply (simp add: non_prim_vars_def)\n  apply (auto)\n   apply (case_tac \"x \\<notin> non_prim_vars env e1\")\n    apply (simp add: non_prim_vars_def)\n   apply (auto)\n    (* app case 2 *)\n  apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" and x=\"x\" in leq_use_none)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n  apply (case_tac \"x \\<notin> non_prim_vars env e2\")\n   apply (simp add: non_prim_vars_def)\n  apply (auto)\n  done\n  \n \n    \n(*\nlemma well_typed_no_fv_use: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; r_s1 x = NoPerm \\<rbrakk> \\<Longrightarrow> x \\<notin> free_vars e\"\n  apply (induction e arbitrary: env r_s1 tau r_s2 rx)\n       apply (auto)\n    (* var case *)\n        apply (cut_tac r_x=\"req_use_env x tau\" and r_s=\"r_s1\" in leq_use_none)\n          apply (auto)\n        apply (cut_tac x=\"x\" in req_use_none)\n        apply (auto)\n    (* if case 1 *)\n       apply (metis)\n    (* if case 2 *)\n      apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" and x=\"x\" in leq_use_none)\n        apply (rule_tac well_typed_perm_leq)\n        apply (auto)\n      apply (metis)\n    (* if case 3 *)\n     apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" and x=\"x\" in leq_use_none)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n     apply (metis)\n    (* lambda case *)\n    apply (case_tac \"x \\<noteq> x1a\")\n     apply (auto)\n    apply (cut_tac r_x=\"rxa\" and r_s=\"r_s1\" and x=\"x\" in leq_use_none)\n      apply (auto)\n    apply (cut_tac r_s=\"rxa\" and y=\"x1a\" and r=\"r\" and x=\"x\" in  add_use_none_rev)\n      apply (auto)\n    apply (metis)\n    (* app case 1 *)\n   apply (metis)\n    (* app case 2 *)\n  apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" and x=\"x\" in leq_use_none)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n  apply (metis)\n  done    *)\n \nlemma well_typed_aff_fv_own: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; x \\<in> free_vars e; env x = Some t; req_type t = Aff \\<rbrakk> \\<Longrightarrow> r_s1 x = OwnPerm\"    \n  apply (induction e arbitrary: env r_s1 tau r_s2 rx)\n       apply (auto)\n    (* var case *)\n       apply (case_tac \"ereq_use_env x t x \\<noteq> OwnPerm\")\n        apply (simp add: ereq_use_env_def)\n        apply (simp add: end_req_perm_def)\n        apply (simp add: one_use_env_def)\n       apply (cut_tac r_x=\"ereq_use_env x t\" and r_s=\"r_s1\" and x=\"x\" in leq_use_own)\n         apply (auto)\n    (* pair case 2 *)\n      apply (rule_tac r_x=\"r_s2a\" in leq_use_own)\n       apply (auto)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n    (* if case 2 *)\n     apply (rule_tac r_x=\"r_s2a\" in leq_use_own)\n      apply (auto)\n     apply (rule_tac e=\"e1\" in well_typed_perm_leq)\n     apply (auto)\n    (* if case 3 *)\n    apply (rule_tac r_x=\"r_s2a\" in leq_use_own)\n     apply (auto)\n    apply (rule_tac e=\"e1\" in well_typed_perm_leq)\n    apply (auto)\n    (* lambda case *)\n   apply (rule_tac r_x=\"rxa\" in leq_use_own)\n    apply (auto)\n   apply (case_tac \"\\<not> add_use_env rxa x1a r x = OwnPerm\")\n    apply (auto)\n    apply (case_tac \"\\<not> add_env env x1a t1 x = Some t\")\n     apply (simp add: add_env_def)\n    apply (auto)\n   apply (simp add: add_use_env_def)\n    (* app case *)\n  apply (rule_tac r_x = \"r_s2a\" in leq_use_own)\n   apply (auto)\n  apply (rule_tac e=\"e1\" in well_typed_perm_leq)\n  apply (auto)\n  done    \n    \n  (*\nlemma well_typed_fv_start_use: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; x \\<in> free_vars e; env x = Some t; aff_fun_ty t \\<rbrakk> \\<Longrightarrow> r_s1 x = OwnPerm\"    \n  apply (induction e arbitrary: env r_s1 tau r_s2 rx)\n       apply (auto)\n    (* var case *)\n      apply (case_tac \"req_use_env x t x \\<noteq> OwnPerm\")\n       apply (simp add: req_use_env_def)\n       apply (simp add: start_req_perm_def)\n       apply (simp add: one_use_env_def)\n      apply (cut_tac r_x=\"req_use_env x t\" and r_s=\"r_s1\" and x=\"x\" in leq_use_own)\n        apply (auto)\n    (* if case 2 *)\n     apply (rule_tac r_x=\"r_s2a\" in leq_use_own)\n      apply (auto)\n     apply (rule_tac e=\"e1\" in well_typed_perm_leq)\n     apply (auto)\n    (* if case 3 *)\n    apply (rule_tac r_x=\"r_s2a\" in leq_use_own)\n     apply (auto)\n    apply (rule_tac e=\"e1\" in well_typed_perm_leq)\n    apply (auto)\n    (* lambda case *)\n   apply (rule_tac r_x=\"rxa\" in leq_use_own)\n    apply (auto)\n   apply (case_tac \"\\<not> add_use_env rxa x1a r x = OwnPerm\")\n    apply (auto)\n    apply (case_tac \"\\<not> add_env env x1a t1 x = Some t\")\n     apply (simp add: add_env_def)\n    apply (auto)\n   apply (simp add: add_use_env_def)\n    (* app case*)\n  apply (rule_tac r_x = \"r_s2a\" in leq_use_own)\n   apply (auto)\n  apply (rule_tac e=\"e1\" in well_typed_perm_leq)\n  apply (auto)\n  done*)\n  \n    (* \n      ####################################\n        P4. well-typed manipulation for type environments\n      ####################################\n    *)\n\nlemma well_typed_add_vars: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; x \\<notin> free_vars e; x \\<notin> ref_vars e \\<rbrakk> \\<Longrightarrow> well_typed (add_env env x t) r_s1 e tau r_s2 rx\"       \n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n        apply (auto)\n    (* var case *)\n       apply (simp add: add_env_def)\n       apply (simp add: deref_name_def)\n       apply (case_tac x2a)\n        apply (auto)\n       apply (simp add: add_env_def)\n       apply (auto)\n    (* pair case *)\n      apply (rule_tac x=\"r_s2a\" in exI)\n      apply (rule_tac x=\"r_s3\" in exI)\n      apply (rule_tac x=\"rx1\" in exI)\n      apply (auto)\n      apply (rule_tac x=\"rx2\" in exI)\n      apply (auto)\n    (* if case *)\n     apply (rule_tac x=\"rx'\" in exI)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)    \n    (* lambda case 1 *)\n    apply (rule_tac x=\"rxa\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"r_end\" in exI)\n    apply (rule_tac x=\"r_s'\" in exI)\n    apply (case_tac \"x = x1a\")\n     apply (cut_tac env=\"env\" and x=\"x\" and t=\"t\" and t'=\"t1\" in double_add_env)\n     apply (auto)\n    apply (cut_tac env=\"env\" and x=\"x1a\" and y=\"x\" and t=\"t\" and t'=\"t1\" in almost_comm_add_env)\n     apply (auto)\n    (* lambda case 2 *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_end\" in exI)\n   apply (rule_tac x=\"r_s'\" in exI)\n   apply (cut_tac env=\"env\" and x=\"x\" and t=\"t\" and t'=\"t1\" in double_add_env)\n   apply (auto)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  done    \n\nlemma well_typed_rem_vars: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; x \\<notin> free_vars e; x \\<notin> ref_vars e \\<rbrakk> \\<Longrightarrow> well_typed (rem_env env x) r_s1 e tau r_s2 rx\"    \n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n        apply (auto)\n    (* var case *)\n        apply (simp add: rem_env_def)\n        apply (simp add: deref_name_def)\n        apply (case_tac x2a)\n         apply (auto)\n       apply (simp add: rem_env_def)\n       apply (auto)\n    (* pair case *)\n      apply (rule_tac x=\"r_s2a\" in exI)\n      apply (rule_tac x=\"r_s3\" in exI)\n      apply (rule_tac x=\"rx1\" in exI)\n      apply (auto)\n      apply (rule_tac x=\"rx2\" in exI)\n      apply (auto)\n    (* if case *)\n     apply (rule_tac x=\"rx'\" in exI)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n    (* lambda case 1 *)\n    apply (rule_tac x=\"rxa\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"r_end\" in exI)\n    apply (rule_tac x=\"r_s'\" in exI)\n    apply (case_tac \"x = x1a\")\n     apply (cut_tac env=\"env\" and x=\"x\" and t=\"t1\" in partial_add_rem_env)\n    apply (auto)\n    apply (cut_tac env=\"env\" and x=\"x\" and y=\"x1a\" and t=\"t1\" in almost_comm_add_rem_env)\n     apply (auto)\n    (* lambda case 2 *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_end\" in exI)\n   apply (rule_tac x=\"r_s'\" in exI)\n   apply (cut_tac env=\"env\" and x=\"x\" and t=\"t1\" in partial_add_rem_env)\n   apply (auto)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  done   \n\nlemma well_typed_add_vars_rev: \"\\<lbrakk> well_typed (add_env env x t) r_s1 e tau r_s2 rx; x \\<notin> free_vars e; x \\<notin> ref_vars e \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau r_s2 rx\"\n  apply (cut_tac env=\"add_env env x t\" and ?r_s1.0=\"r_s1\" and e=\"e\" and tau=\"tau\" and ?r_s2.0=\"r_s2\" and rx=\"rx\" and x=\"x\" in well_typed_rem_vars)\n    apply (auto)\n  apply (case_tac \"env x = None\")\n   apply (auto)\n   apply (cut_tac env=\"env\" and x=\"x\" and t=\"t\" in cancel_rem_add_env)\n    apply (auto)\n  apply (rule_tac t=\"well_typed env r_s1 e tau r_s2 rx\" and s=\"well_typed (add_env (rem_env env x) x y) r_s1 e tau r_s2 rx\" in subst)\n   apply (cut_tac env=\"env\" and x=\"x\" and y=\"y\" in cancel_add_rem_env)\n    apply (auto)\n  apply (rule_tac well_typed_add_vars)\n   apply (cut_tac env=\"env\" and x=\"x\" and y=\"t\" in partial_rem_add_env)\n   apply (auto)\n  done\n\nlemma well_typed_contain_env: \"\\<lbrakk> contain_env env env'; well_typed env' r_s1 e tau r_s2 rx \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau r_s2 rx\"    \n  apply (induct e arbitrary: env env' r_s1 tau r_s2 rx)\n        apply (auto)\n    (* var case *)\n       apply (simp add: contain_env_def)\n       apply (erule_tac x=\"deref_name x1a x2a\" in allE)\n       apply (auto)\n      apply (simp add: contain_env_def)\n      apply (erule_tac x=\"x1a\" in allE)\n      apply (auto)\n    (* pair case *)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (rule_tac x=\"r_s3\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"r_s2a\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"rx1\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"rx2\" in exI)\n    apply (auto)\n    (* lam case *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_end\" in exI)\n   apply (rule_tac x=\"r_s'\" in exI)\n   apply (cut_tac r_s=\"env\" and r_x=\"env'\" and x=\"x1a\" and t=\"t1\" in dist_add_contain_env)\n    apply (auto)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  done\n    \n    (* \n      ####################################\n        P5. well-typed manipulation for start permissions\n      ####################################\n    *)    \n    \nlemma well_typed_comp_start_perm: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx \\<rbrakk> \\<Longrightarrow> well_typed env (comp_use_env r_s1 r_ex) e tau r_s2 rx\"\n  apply (induction e arbitrary: env r_s1 tau r_s2 rx)\n        apply (auto)\n    (* const, op, var case 1 *)\n         apply (rule_tac comp_leq_use_env1)\n         apply (simp)\n        apply (rule_tac comp_leq_use_env1)\n        apply (simp)\n       apply (rule_tac comp_leq_use_env1)\n       apply (simp)\n    (* var case 2 *)\n      apply (rule_tac x=\"r_exa\" in exI)\n      apply (auto)\n       apply (rule_tac r_sb=\"diff_use_env r_s1 (comp_use_env (ereq_use_env x1a tau_x) r_exa)\" in trans_leq_use_env)\n        apply (rule_tac dist_diff_leq_use_env)\n        apply (rule_tac self_comp_leq_use_env1)\n       apply (auto)\n      apply (rule_tac comp_leq_use_env1)\n      apply (simp)\n    (* pair case *)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (rule_tac x=\"r_s3\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"r_exa\" in exI)\n     apply (auto)\n     apply (rule_tac comp_leq_use_env1)\n     apply (simp)\n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"r_s2a\" in exI)\n    apply (auto)\n    (* lambda case *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n    apply (rule_tac r_sb=\"r_s1\" in trans_leq_use_env)\n     apply (rule_tac comp_leq_use_env1)\n     apply (rule_tac id_leq_use_env)\n    apply (simp)\n   apply (rule_tac x=\"r_exa\" in exI)\n   apply (auto)\n    apply (rule_tac r_sb=\"diff_use_env r_s1 r_exa\" in trans_leq_use_env)\n     apply (rule_tac dist_diff_leq_use_env)\n     apply (rule_tac self_comp_leq_use_env1)\n    apply (simp)\n   apply (rule_tac comp_leq_use_env1)\n   apply (simp)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"r_exa\" in exI)\n  apply (auto)\n  apply (rule_tac comp_leq_use_env1)\n  apply (simp)\n  done\n  \nlemma well_typed_comp_start_perm2: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx \\<rbrakk> \\<Longrightarrow> well_typed env (comp_use_env r_ex r_s1) e tau r_s2 rx\"\n  apply (cut_tac r_s=\"r_ex\" and r_x=\"r_s1\" in comm_comp_use_env)\n  apply (auto)\n  apply (rule_tac well_typed_comp_start_perm)\n  apply (auto)\n  done    \n    \nlemma well_typed_incr_start_perm: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; leq_use_env r_s1 r_c \\<rbrakk> \\<Longrightarrow> well_typed env r_c e tau r_s2 rx\"\n  apply (cut_tac r_s=\"r_c\" and r_x=\"r_s1\" in cancel_comp_use_env2)\n   apply (auto)\n  apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s1\" and r_ex=\"r_c\" and e=\"e\" and tau=\"tau\" and ?r_s2.0=\"r_s2\" and rx=\"rx\" in well_typed_comp_start_perm2)\n   apply (auto)\n  done\n    \n    (* \n      ####################################\n        P6. well-typed manipulation for sweeping changes\n      ####################################\n    *)        \n    \n    (* - diff perm lemmas *)\n    \nlemma wtdp_start_perm_req: \"\\<lbrakk> y \\<notin> own_env_vars r_x; leq_use_env (req_use_env y tau) r_s1 \\<rbrakk>\n       \\<Longrightarrow> leq_use_env (req_use_env y tau) (diff_use_env r_s1 r_x)\"        \n  apply (rule_tac r_s=\"r_s1\" in req_leq_use_env)\n   apply (simp)\n  apply (cut_tac r_s=\"r_s1\" and x=\"y\" and r_x=\"r_x\" in diff_use_eq)\n   apply (auto)\n  apply (simp add: own_env_vars_def)\n  done\n    \nlemma lhs_ddl_use_env: \"\\<lbrakk> disj_use_env r_s r_x \\<rbrakk> \\<Longrightarrow> leq_use_env (diff_use_env r_s (diff_use_env r_ex r_x)) (diff_use_env r_s r_ex)\"    \n  apply (simp add: leq_use_env_def)\n  apply (simp add: diff_use_env_def)\n  apply (simp add: minus_use_env_def)\n  apply (simp add: neg_use_env_def)\n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n   apply (case_tac \"r_ex x\")\n     apply (auto)\n    apply (case_tac \"r_x x\")\n      apply (auto)\n   apply (case_tac \"r_x x\")\n     apply (auto)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n   apply (case_tac \"r_ex x\")\n     apply (auto)\n  apply (case_tac \"r_ex x\")\n    apply (auto)\n  done\n\nlemma weak_diff_req_use_env: \"weak_use_env (diff_use_env (req_use_env x tau) (req_use_env x tau))\"\n  apply (simp add: diff_use_env_def)\n  apply (simp add: minus_use_env_def)\n  apply (simp add: neg_use_env_def)\n  apply (simp add: weak_use_env_def)\n  apply (auto)\n  apply (case_tac \"req_use_env x tau xa\")\n    apply (auto)\n  done\n  \nlemma wtdp_disj_req_use_env2: \"\\<lbrakk> r_x x \\<noteq> OwnPerm \\<rbrakk> \\<Longrightarrow> disj_use_env r_x (diff_use_env (req_use_env x tau) (req_use_env x tau))\"\n  apply (cut_tac x=\"x\" and tau=\"tau\" in weak_diff_req_use_env)\n  apply (simp add: disj_use_env_def)\n  apply (auto)\n   apply (simp add: mini_disj_use_env_def)\n   apply (auto)\n   apply (rule_tac r_s=\"req_use_env x tau\" in leq_use_none)\n    apply (rule_tac self_diff_leq_use_env)\n   apply (rule_tac req_use_none_alt)\n   apply (auto)\n  apply (simp add: mini_disj_use_env_def)\n  apply (auto)\n  apply (simp add: weak_use_env_def)\n  done\n    \nlemma wtdp_end_req: \"\\<lbrakk> non_prim_vars env e \\<inter> own_env_vars r_x = {}; x \\<in> free_vars e; env x = Some tau;\n  r_x x = OwnPerm \\<rbrakk> \\<Longrightarrow> end_req_perm tau = NoPerm\" \n  apply (case_tac \"x \\<in> non_prim_vars env e\")\n   apply (simp add: own_env_vars_def)\n   apply (auto)\n  apply (case_tac \"req_type tau \\<noteq> Prim\")\n   apply (simp add: non_prim_vars_def)\n   apply (simp add: non_prim_entry_def)\n  apply (simp add: end_req_perm_def)\n  done\n    \nlemma well_typed_diff_perms: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; non_prim_vars env e \\<inter> own_env_vars r_x = {} \\<rbrakk> \\<Longrightarrow>\n  well_typed env (diff_use_env r_s1 r_x) e tau (diff_use_env r_s2 r_x) (diff_use_env rx r_x)\"\n  apply (induction e arbitrary: env r_s1 tau r_s2 rx r_x)\n       apply (auto)\n    (* const case *)\n          apply (rule_tac dist_diff_leq_use_env)\n          apply (simp)\n         apply (rule_tac dist_diff_leq_use_env)\n         apply (simp)\n    (* op case *)\n        apply (rule_tac dist_diff_leq_use_env)\n        apply (simp)\n       apply (rule_tac dist_diff_leq_use_env)\n       apply (simp)\n    (* var case p1. manipulation to show that x1a exists in r_s2 *)\n      apply (rule_tac mini_disj_diff_leq_use_env2)\n       apply (simp)\n      apply (simp add: ereq_use_env_def)\n      apply (simp add: mini_disj_use_env_def)\n      apply (simp add: one_use_env_def)\n      apply (auto)\n      apply (rule_tac env=\"env\" and e=\"VarExp x1a x2a\" and r_x=\"r_x\" and x=\"x1a\" in wtdp_end_req)\n         apply (auto)\n    (* var case p2 *)\n     apply (rule_tac x=\"diff_use_env r_ex r_x\" in exI)\n     apply (auto)\n        apply (rule_tac rhs_fold_dcl_use_env)\n        apply (rule_tac rhs_flip_use_env)\n        apply (rule_tac rhs_pull_comp_use_env)\n        apply (cut_tac r_ex=\"r_ex\" and r_x=\"r_x\" in sum_comp_diff_use_env)\n        apply (auto)\n        apply (rule_tac rhs_unroll_dcl_use_env)\n        apply (rule_tac rhs_unroll_dcl_use_env)\n        apply (rule_tac dist_diff_leq_use_env)\n        apply (rule_tac rhs_fold_dcl_use_env)\n        apply (simp)\n       apply (rule_tac dist_diff_leq_use_env)\n       apply (simp)\n      apply (rule_tac dist_diff_leq_use_env)\n      apply (simp)\n    (* - use disjointess of r_x from (req x tau) to remove - r_x *)\n     apply (rule_tac disj_diff_leq_use_env)\n      apply (simp add: ereq_use_env_def)\n      apply (simp add: disj_use_env_def)\n      apply (auto)\n       apply (rule_tac one_mini_disj_use_env1)\n       apply (auto)\n       apply (rule_tac env=\"env\" and e=\"VarExp x1a x2a\" and r_x=\"r_x\" and x=\"x1a\" in wtdp_end_req)\n          apply (auto)\n      apply (rule_tac one_mini_disj_use_env2)\n      apply (auto)\n      apply (simp add: comp_use_env_def)\n      apply (simp add: one_use_env_def)\n    (* - through a slightly more involved process we can also remove it from the left *)\n     apply (rule_tac lhs_unroll_dcl_use_env)\n     apply (rule_tac r_sb=\"diff_use_env (diff_use_env (ereq_use_env x1a tau_x) (ereq_use_env x1a tau_x)) r_ex\" in trans_leq_use_env)\n      apply (rule_tac lhs_fold_dcl_use_env)\n      apply (simp)\n     apply (rule_tac lhs_ddl_use_env)\n     apply (rule_tac comm_disj_use_env)\n     apply (simp add: ereq_use_env_def)\n     apply (simp add: disj_use_env_def)\n     apply (auto)\n      apply (rule_tac one_mini_disj_use_env1)\n      apply (auto)\n      apply (rule_tac env=\"env\" and e=\"VarExp x1a x2a\" and r_x=\"r_x\" and x=\"x1a\" in wtdp_end_req)\n         apply (auto)\n     apply (rule_tac one_mini_disj_use_env2)\n     apply (auto)\n      apply (simp add: one_use_env_def)\n    (* pair case *)\n     apply (rule_tac x=\"diff_use_env r_s2a r_x\" in exI)\n     apply (rule_tac x=\"diff_use_env r_s3 r_x\" in exI)\n     apply (rule_tac x=\"diff_use_env rx1 r_x\" in exI)\n     apply (auto)\n      apply (case_tac \"\\<not> non_prim_vars env e1 \\<inter> own_env_vars r_x = {}\")\n       apply (simp add: non_prim_vars_def)\n       apply (auto)\n     apply (rule_tac x=\"diff_use_env rx2 r_x\" in exI)\n     apply (auto)\n           apply (case_tac \"\\<not> non_prim_vars env e2 \\<inter> own_env_vars r_x = {}\")\n            apply (simp add: non_prim_vars_def)\n            apply (auto)\n          (*apply (rule_tac aff_diff_use_env)\n          apply (simp)*)\n          apply (rule_tac t=\"lift_use_env (diff_use_env rx1 r_x) r\" and s=\"diff_use_env (lift_use_env rx1 r) r_x\" in subst)\n           apply (rule_tac lift_diff_use_env)\n          apply (rule_tac dist_diff_leq_use_env)\n          apply (simp)\n         apply (rule_tac t=\"lift_use_env (diff_use_env rx2 r_x) r\" and s=\"diff_use_env (lift_use_env rx2 r) r_x\" in subst)\n          apply (rule_tac lift_diff_use_env)\n         apply (rule_tac dist_diff_leq_use_env)\n         apply (simp)\n      apply (rule_tac r_s=\"lift_use_env rx1 r\" in disj_leq_use_env1)\n       apply (rule_tac r_s=\"lift_use_env rx2 r\" in disj_leq_use_env2)\n        apply (simp)\n       apply (rule_tac dist_lift_leq_use_env)\n       apply (rule_tac self_diff_leq_use_env)\n      apply (rule_tac dist_lift_leq_use_env)\n      apply (rule_tac self_diff_leq_use_env)\n     apply (rule_tac x=\"diff_use_env r_ex r_x\" in exI)\n     apply (auto)\n        apply (rule_tac t=\"diff_use_env (diff_use_env r_s3 r_x) (diff_use_env r_ex r_x)\" and s=\"diff_use_env (diff_use_env r_s3 r_ex) r_x\" in subst)\n         apply (rule_tac dist_sq_diff_use_env)\n        apply (rule_tac dist_diff_leq_use_env)\n        apply (simp)\n       apply (rule_tac dist_diff_leq_use_env)\n       apply (simp)\n      apply (rule_tac dist_diff_leq_use_env)\n      apply (simp)\n     apply (case_tac \"req_type (PairTy t1 t2 r) = Prim\")\n      apply (simp add: pair_req_def)\n      apply (auto)\n      apply (rule_tac leq_empty_use_env)     \n     apply (simp add: pair_req_def)\n     apply (rule_tac t=\"lift_use_env (diff_use_env rx1 r_x) r\" and s=\"diff_use_env (lift_use_env rx1 r) r_x\" in subst)\n      apply (rule_tac lift_diff_use_env)\n     apply (rule_tac t=\"lift_use_env (diff_use_env rx2 r_x) r\" and s=\"diff_use_env (lift_use_env rx2 r) r_x\" in subst)\n      apply (rule_tac lift_diff_use_env)\n     apply (simp add: dist_diff_comp_use_env)\n     apply (rule_tac t=\"diff_use_env (diff_use_env (comp_use_env (lift_use_env rx1 r) (lift_use_env rx2 r)) r_x)\n        (diff_use_env r_ex r_x)\" and s=\"diff_use_env (diff_use_env (comp_use_env (lift_use_env rx1 r) (lift_use_env rx2 r)) r_ex) r_x\" in subst)\n      apply (rule_tac dist_sq_diff_use_env)\n     apply (rule_tac dist_diff_leq_use_env)\n     apply (simp)\n    (* if case *)\n    apply (rule_tac x=\"diff_use_env rx' r_x\" in exI)\n    apply (rule_tac x=\"diff_use_env r_s2a r_x\" in exI)\n    apply (auto)\n     apply (case_tac \"\\<not> non_prim_vars env e1 \\<inter> own_env_vars r_x = {}\")\n      apply (simp add: non_prim_vars_def)\n      apply (auto)\n    apply (rule_tac x=\"diff_use_env rx1 r_x\" in exI)\n    apply (auto)\n     apply (case_tac \"\\<not> non_prim_vars env e2 \\<inter> own_env_vars r_x = {}\")\n      apply (simp add: non_prim_vars_def)\n      apply (auto)\n    apply (rule_tac x=\"diff_use_env rx2 r_x\" in exI)\n    apply (auto)\n     apply (case_tac \"\\<not> non_prim_vars env e3 \\<inter> own_env_vars r_x = {}\")\n      apply (simp add: non_prim_vars_def)\n      apply (auto)\n    apply (simp add: diff_use_env_def)\n    apply (rule_tac dist_minus_comp_use_env)\n    (* lambda case *)\n   apply (rule_tac x=\"diff_use_env rxa r_x\" in exI)\n   apply (auto)\n      apply (rule_tac x=\"diff_use_env r_end (rem_use_env r_x x1a)\" in exI)\n      apply (rule_tac x=\"diff_use_env r_s' (rem_use_env r_x x1a)\" in exI)\n      apply (cut_tac r_s=\"rxa\" and x=\"x1a\" and r=\"r\" and r_x=\"r_x\" in diff_add_rem_use_env)\n      apply (auto)\n      apply (case_tac \"\\<not> non_prim_vars (add_env env x1a t1) e \\<inter> own_env_vars (rem_use_env r_x x1a) = {}\")\n       apply (auto)\n      apply (simp add: rem_use_env_def)\n      apply (simp add: own_env_vars_def)\n      apply (case_tac \"x = x1a\")\n       apply (auto)\n      apply (simp add: non_prim_vars_def)\n      apply (simp add: non_prim_entry_def)\n      apply (simp add: add_env_def)\n      apply (auto)\n     apply (rule_tac aff_diff_use_env)\n     apply (simp)\n    apply (rule_tac dist_diff_leq_use_env)\n    apply (simp)\n   apply (rule_tac x=\"diff_use_env r_ex r_x\" in exI)\n   apply (auto)\n    (* - proving bounds *)\n      apply (rule_tac t=\"diff_use_env (diff_use_env r_s1 r_x) (diff_use_env r_ex r_x)\" and s=\"diff_use_env (diff_use_env r_s1 r_ex) r_x\" in subst)\n       apply (cut_tac r_s=\"r_s1\" and r_x=\"r_ex\" and r_ex=\"r_x\" in dist_sq_diff_use_env)\n       apply (auto)\n      apply (rule_tac dist_diff_leq_use_env)\n      apply (simp)\n     apply (rule_tac dist_diff_leq_use_env)\n     apply (simp)\n    apply (rule_tac dist_diff_leq_use_env)\n    apply (simp)\n   apply (rule_tac t=\"diff_use_env (diff_use_env rxa r_x) (diff_use_env r_ex r_x)\" and s=\"diff_use_env (diff_use_env rxa r_ex) r_x\" in subst)\n    apply (cut_tac r_s=\"rxa\" and r_x=\"r_ex\" and r_ex=\"r_x\" in dist_sq_diff_use_env)\n    apply (auto)\n   apply (rule_tac dist_diff_leq_use_env)\n   apply (simp)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"diff_use_env r_s2a r_x\" in exI)\n  apply (rule_tac x=\"diff_use_env rx1 r_x\" in exI)\n  apply (auto)\n   apply (case_tac \"\\<not> non_prim_vars env e1 \\<inter> own_env_vars r_x = {}\")\n    apply (simp add: non_prim_vars_def)\n    apply (auto)\n  apply (rule_tac x=\"diff_use_env rx2 r_x\" in exI)\n  apply (rule_tac x=\"diff_use_env r_s3 r_x\" in exI)\n  apply (auto)\n   apply (case_tac \"\\<not> non_prim_vars env e2 \\<inter> own_env_vars r_x = {}\")\n    apply (simp add: non_prim_vars_def)\n    apply (auto)\n    (* - reusable substitutions *)\n  apply (case_tac \"\\<not> lift_use_env (diff_use_env rx2 r_x) r = diff_use_env (lift_use_env rx2 r) r_x\")\n   apply (cut_tac r_s=\"rx2\" and r=\"r\" and r_x=\"r_x\" in lift_diff_use_env)\n   apply (simp)\n    (* - last instantiation *)\n  apply (rule_tac x=\"diff_use_env r_ex r_x\" in exI)\n  apply (auto)\n    (* - prove the bound for r_s2 *)\n        apply (rule_tac rhs_fold_dcl_use_env)\n        apply (rule_tac rhs_flip_use_env)\n        apply (rule_tac rhs_unroll_dcl_use_env)\n        apply (rule_tac rhs_diff_leq_use_env)\n        apply (rule_tac r_sb=\"diff_use_env (diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)) r_x\" in trans_leq_use_env)\n         apply (rule_tac lhs_fold_dcl_use_env)\n         apply (rule_tac lhs_flip_use_env)\n         apply (rule_tac lhs_unroll_dcl_use_env)\n         apply (rule_tac unroll_dcl_use_env)\n         apply (rule_tac dist_diff_leq_use_env_gen)\n          apply (rule_tac dist_diff_leq_use_env_gen)\n           apply (rule_tac self_diff_leq_use_env)\n          apply (rule_tac dist_comp_leq_use_env)\n           apply (rule_tac comp_leq_use_env1)\n           apply (rule_tac self_diff_leq_use_env)\n          apply (rule_tac comp_leq_use_env2)\n          apply (rule_tac self_diff_leq_use_env)\n         apply (rule_tac self_diff_leq_use_env)\n        apply (rule_tac dist_diff_leq_use_env)\n        apply (simp)\n    (* - prove lift safety *)\n    (* - prove rx1 + rx2 is subtractable *)\n      apply (rule_tac r_sb=\"diff_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_x\" in trans_leq_use_env)\n       apply (rule_tac dist_diff_leq_use_env)\n       apply (simp)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (rule_tac dist_diff_leq_use_env)\n       apply (rule_tac self_comp_leq_use_env1)\n      apply (rule_tac dist_diff_leq_use_env)\n      apply (rule_tac self_comp_leq_use_env2)\n    (* - prove disjointedness *)\n     apply (rule_tac r_s=\"rx1\" in disj_leq_use_env1)\n      apply (rule_tac r_s=\"lift_use_env rx2 r\" in disj_leq_use_env2)\n       apply (simp)\n      apply (rule_tac self_diff_leq_use_env)\n     apply (rule_tac self_diff_leq_use_env)\n    apply (rule_tac dist_diff_leq_use_env)\n    apply (simp)\n    (* - prove r_ex bound *)\n   apply (rule_tac dist_diff_leq_use_env)\n   apply (simp)\n    (* - prove the bound for rx *)\n  apply (simp add: app_req_def)\n  apply (auto)\n   apply (rule_tac leq_empty_use_env)\n  apply (rule_tac t=\"comp_use_env (diff_use_env rx1 r_x) (diff_use_env rx2 r_x)\" and s=\"diff_use_env (comp_use_env rx1 rx2) r_x\" in subst)\n   apply (simp add: diff_use_env_def)\n   apply (rule_tac dist_minus_comp_use_env) \n  apply (rule_tac t=\"comp_use_env (diff_use_env rx1 r_x) (diff_use_env (lift_use_env rx2 r) r_x)\" and\n      s=\"diff_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_x\" in subst)\n   apply (simp add: diff_use_env_def)\n   apply (rule_tac dist_minus_comp_use_env)\n  apply (rule_tac t=\"comp_use_env (diff_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_x) (diff_use_env r_ex r_x)\" and\n      s=\"diff_use_env (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex) r_x\" in subst)\n   apply (simp add: diff_use_env_def)\n   apply (rule_tac dist_minus_comp_use_env)\n  apply (rule_tac t=\"diff_use_env (diff_use_env (comp_use_env rx1 rx2) r_x) (diff_use_env (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex) r_x)\" and\n      s=\"diff_use_env (diff_use_env (comp_use_env rx1 rx2) (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)) r_x\" in subst)\n   apply (rule_tac dist_sq_diff_use_env)\n  apply (rule_tac dist_diff_leq_use_env)\n  apply (simp)\n  done \n\nlemma well_typed_rem_perms: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; x \\<notin> non_prim_vars env e \\<rbrakk> \\<Longrightarrow>\n  well_typed env (rem_use_env r_s1 x) e tau (rem_use_env r_s2 x) (rem_use_env rx x)\"  \n  apply (cut_tac r_s=\"r_s1\" and x=\"x\" in diff_rem_use_env)\n  apply (cut_tac r_s=\"r_s2\" and x=\"x\" in diff_rem_use_env)\n  apply (cut_tac r_s=\"rx\" and x=\"x\" in diff_rem_use_env)\n  apply (auto)\n  apply (rule_tac well_typed_diff_perms)\n   apply (auto)\n  apply (simp add: one_use_env_def)\n  apply (simp add: own_env_vars_def)\n  apply (case_tac \"x = xa\")\n   apply (auto)\n  done\n\nlemma well_typed_add_perms_rev: \"\\<lbrakk> well_typed env (add_use_env r_s1 x r) e tau (add_use_env r_s2 x r') (add_use_env rx x r3);\n  r_s1 x = NoPerm; r_s2 x = NoPerm; rx x = NoPerm; x \\<notin> non_prim_vars env e \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau r_s2 rx\"\n  apply (cut_tac r_s=\"r_s1\" and x=\"x\" and r=\"r\" in cancel_rem_add_use_env)\n   apply (auto)\n  apply (cut_tac r_s=\"r_s2\" and x=\"x\" and r=\"r'\" in cancel_rem_add_use_env)\n   apply (auto)\n  apply (cut_tac r_s=\"rx\" and x=\"x\" and r=\"r3\" in cancel_rem_add_use_env)\n   apply (auto)\n  apply (cut_tac env=\"env\" and ?r_s1.0=\"add_use_env r_s1 x r\" and e=\"e\" and tau=\"tau\" and ?r_s2.0=\"add_use_env r_s2 x r'\" and rx=\"add_use_env rx x r3\" and x=\"x\" in well_typed_rem_perms)\n    apply (auto)\n  done\n    \n    (* \n      ####################################\n        P7. well-typed manipulation for permission changes\n      ####################################\n    *)    \n\nlemma well_typed_comp_perms_gen: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; mini_disj_use_env r_s1 r_ex \\<rbrakk> \\<Longrightarrow>\n  well_typed env (comp_use_env r_s1 r_ex) e tau (comp_use_env r_s2 r_ex) rx\"\n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n       apply (auto)\n    (* const case *)\n           apply (rule_tac dist_comp_leq_use_env)\n            apply (rule_tac comp_leq_use_env1)\n            apply (simp)\n           apply (rule_tac comp_leq_use_env2)\n           apply (rule_tac id_leq_use_env)\n          apply (rule_tac comp_leq_use_env1)\n          apply (simp)\n    (* op case *)\n         apply (rule_tac dist_comp_leq_use_env)\n          apply (rule_tac comp_leq_use_env1)\n          apply (simp)\n         apply (rule_tac comp_leq_use_env2)\n         apply (rule_tac id_leq_use_env)\n        apply (rule_tac comp_leq_use_env1)\n        apply (simp)\n    (* var case *)\n       apply (rule_tac comp_leq_use_env1)\n       apply (simp)\n      apply (rule_tac x=\"r_exa\" in exI)\n      apply (auto)\n    (* - first half of end permission bounds check *)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (rule_tac r_sb=\"diff_use_env r_s1 (comp_use_env (ereq_use_env x1a tau_x) r_exa)\" in trans_leq_use_env)\n          apply (rule_tac dist_diff_leq_use_env)\n          apply (rule_tac self_comp_leq_use_env1)\n         apply (simp)\n    (* - second half of end permission bounds check *)\n        apply (rule_tac rhs_dist_dcl_use_env)\n        apply (rule_tac comp_leq_use_env2)\n        apply (rule_tac mini_disj_diff_leq_use_env)\n         apply (rule_tac id_leq_use_env)\n        apply (rule_tac r_s=\"r_s1\" in mini_disj_leq_use_env1)\n         apply (simp)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (auto)\n    (* - various bounds checks *)\n       apply (rule_tac comp_leq_use_env1)\n       apply (simp)\n      apply (rule_tac comp_leq_use_env1)\n      apply (simp)\n    (* pair case *)\n     apply (rule_tac x=\"comp_use_env r_s2a r_ex\" in exI)\n     apply (rule_tac x=\"comp_use_env r_s3 r_ex\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n        apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" and r_ex=\"r_ex\" in mini_disj_leq_use_env1)\n          apply (simp)\n         apply (rule_tac well_typed_perm_leq)\n         apply (auto)\n       apply (rule_tac comp_leq_use_env1)\n       apply (simp)\n      apply (rule_tac comp_leq_use_env1)\n      apply (simp)\n     apply (rule_tac x=\"r_exa\" in exI)\n     apply (auto)\n       apply (rule_tac rhs_dist_dcl_use_env)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac comp_leq_use_env1)\n        apply (simp)\n       apply (rule_tac comp_leq_use_env2)\n       apply (rule_tac mini_disj_diff_leq_use_env)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac r_s=\"r_s1\" in mini_disj_leq_use_env1)\n        apply (simp_all)\n      apply (rule_tac comp_leq_use_env1)\n      apply (simp)\n     apply (rule_tac comp_leq_use_env1)\n     apply (simp)\n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"comp_use_env r_s2a r_ex\" in exI)\n    apply (auto)\n    apply (cut_tac r_s=\"r_s1\" and r_x=\"r_s2a\" and r_ex=\"r_ex\" in mini_disj_leq_use_env1)\n      apply (simp)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n    apply (rule_tac x=\"rx1\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"rx2\" in exI)\n    apply (auto)\n    (* lambda case *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n    apply (rule_tac comp_leq_use_env1)\n    apply (simp)\n   apply (rule_tac x=\"r_exa\" in exI)\n   apply (auto)\n     apply (rule_tac rhs_dist_dcl_use_env)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac comp_leq_use_env1)\n      apply (simp)\n     apply (rule_tac comp_leq_use_env2)\n     apply (rule_tac mini_disj_diff_leq_use_env)\n      apply (rule_tac id_leq_use_env)\n     apply (rule_tac r_s=\"r_s1\" in mini_disj_leq_use_env1)\n      apply (auto)\n    apply (rule_tac comp_leq_use_env1)\n    apply (simp)\n   apply (rule_tac comp_leq_use_env1)\n   apply (simp)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"comp_use_env r_s2a r_ex\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"comp_use_env r_s3 r_ex\" in exI)\n  apply (auto)\n   apply (cut_tac r_s=\"r_s1\" and r_x=\"r_s2a\" and r_ex=\"r_ex\" in mini_disj_leq_use_env1)\n     apply (simp)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n  apply (cut_tac r_sa=\"r_s1\" and r_sb=\"r_s2a\" and r_sc=\"r_s3\" in trans_leq_use_env)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n   apply (rule_tac well_typed_perm_leq)\n   apply (auto)\n  apply (rule_tac x=\"r_exa\" in exI)\n  apply (auto)\n    (* - first half of end permissions bounds check *)\n     apply (rule_tac rhs_dist_dcl_use_env)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac comp_leq_use_env1)\n      apply (simp)\n    (* - second half of end permissions bounds check *)\n     apply (rule_tac comp_leq_use_env2)\n     apply (rule_tac mini_disj_diff_leq_use_env)\n      apply (rule_tac id_leq_use_env)\n     apply (rule_tac r_s=\"r_s1\" in mini_disj_leq_use_env1)\n      apply (simp)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n       apply (auto)\n    (* - final bounds checks *)\n    apply (rule_tac comp_leq_use_env1)\n    apply (simp)\n   apply (rule_tac comp_leq_use_env1)\n   apply (simp)\n  apply (rule_tac comp_leq_use_env1)\n  apply (simp)\n  done    \n \nlemma well_typed_comp_perms: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; disj_use_env r_s1 r_ex \\<rbrakk> \\<Longrightarrow>\n  well_typed env (comp_use_env r_s1 r_ex) e tau (comp_use_env r_s2 r_ex) rx\"\n  apply (rule_tac well_typed_comp_perms_gen)\n   apply (simp)\n  apply (simp add: disj_use_env_def)\n  done\n    \n    (*\nlemma well_typed_comp_perms: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; disj_use_env r_s1 r_ex \\<rbrakk> \\<Longrightarrow>\n  well_typed env (comp_use_env r_s1 r_ex) e tau (comp_use_env r_s2 r_ex) rx\"\n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n       apply (auto)\n    (* const case *)\n          apply (rule_tac dist_comp_leq_use_env)\n           apply (rule_tac comp_leq_use_env1)\n           apply (simp)\n          apply (rule_tac comp_leq_use_env2)\n          apply (rule_tac id_leq_use_env)\n         apply (rule_tac comp_leq_use_env1)\n         apply (simp)\n    (* op case *)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (rule_tac comp_leq_use_env1)\n         apply (simp)\n        apply (rule_tac comp_leq_use_env2)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac comp_leq_use_env1)\n       apply (simp)\n    (* var case *)\n      apply (rule_tac comp_leq_use_env1)\n      apply (simp)\n     apply (rule_tac x=\"r_exa\" in exI)\n     apply (auto)\n    (* - first half of end permission bounds check *)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac r_sb=\"diff_use_env r_s1 (comp_use_env (req_use_env x1a tau) r_exa)\" in trans_leq_use_env)\n         apply (rule_tac dist_diff_leq_use_env)\n         apply (rule_tac self_comp_leq_use_env1)\n        apply (simp)\n    (* - second half of end permission bounds check *)\n       apply (rule_tac disj_diff_leq_use_env)\n        apply (rule_tac r_s=\"r_s1\" in disj_leq_use_env1)\n         apply (simp)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (auto)\n    (* - various bounds checks *)\n       apply (rule_tac self_comp_leq_use_env2)\n      apply (rule_tac comp_leq_use_env1)\n      apply (simp)\n     apply (rule_tac comp_leq_use_env1)\n     apply (simp)\n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"comp_use_env r_s2a r_ex\" in exI)\n    apply (auto)\n    apply (cut_tac r_s=\"r_s1\" and r_x=\"r_s2a\" and r_ex=\"r_ex\" in disj_leq_use_env1)\n      apply (simp)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n    apply (rule_tac x=\"rx1\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"rx2\" in exI)\n    apply (auto)\n    (* lambda case *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n    apply (rule_tac comp_leq_use_env1)\n    apply (simp)\n   apply (rule_tac x=\"r_exa\" in exI)\n   apply (auto)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (rule_tac r_sb=\"diff_use_env r_s1 r_exa\" in trans_leq_use_env)\n      apply (rule_tac dist_diff_leq_use_env)\n      apply (rule_tac self_comp_leq_use_env1)\n     apply (simp)\n    apply (rule_tac disj_diff_leq_use_env)\n     apply (rule_tac r_s=\"r_s1\" in disj_leq_use_env1)\n       apply (auto)\n     apply (rule_tac self_comp_leq_use_env2)\n    apply (rule_tac comp_leq_use_env1)\n    apply (simp)\n   apply (rule_tac comp_leq_use_env1)\n   apply (simp)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"comp_use_env r_s2a r_ex\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"comp_use_env r_s3 r_ex\" in exI)\n  apply (auto)\n   apply (cut_tac r_s=\"r_s1\" and r_x=\"r_s2a\" and r_ex=\"r_ex\" in disj_leq_use_env1)\n     apply (simp)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n  apply (cut_tac r_sa=\"r_s1\" and r_sb=\"r_s2a\" and r_sc=\"r_s3\" in trans_leq_use_env)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n   apply (rule_tac well_typed_perm_leq)\n   apply (auto)\n  apply (rule_tac x=\"r_exa\" in exI)\n  apply (auto)\n    (* - first half of end permissions bounds check *)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_exa)\" in trans_leq_use_env)\n       apply (rule_tac dist_diff_leq_use_env)\n       apply (rule_tac self_comp_leq_use_env1)\n      apply (simp)\n    (* - second half of end permissions bounds check *)\n     apply (rule_tac disj_diff_leq_use_env)\n      apply (rule_tac r_s=\"r_s1\" in disj_leq_use_env1)\n       apply (simp)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n        apply (auto)\n    (* - final bounds checks *)\n     apply (rule_tac self_comp_leq_use_env2)\n    apply (rule_tac comp_leq_use_env1)\n    apply (simp)\n   apply (rule_tac comp_leq_use_env1)\n   apply (simp)\n  apply (rule_tac comp_leq_use_env1)\n  apply (simp)\n  done*)\n\nlemma well_typed_comp_perms2: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; disj_use_env r_s1 r_ex \\<rbrakk> \\<Longrightarrow>\n  well_typed env (comp_use_env r_ex r_s1) e tau (comp_use_env r_ex r_s2) rx\"    \n  apply (cut_tac r_s=\"r_ex\" and r_x=\"r_s1\" in comm_comp_use_env)  \n  apply (cut_tac r_s=\"r_ex\" and r_x=\"r_s2\" in comm_comp_use_env)\n  apply (auto)\n  apply (rule_tac well_typed_comp_perms)\n   apply (auto)\n  done           \n    \nlemma well_typed_add_perms: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; x \\<notin> non_prim_vars env e; r = OwnPerm; rx x = NoPerm \\<rbrakk> \\<Longrightarrow>\n  well_typed env (add_use_env r_s1 x r) e tau (add_use_env r_s2 x r) rx\"\n  apply (cut_tac r_s=\"r_s1\" and x=\"x\" and r=\"r\" in partial_add_rem_use_env)\n  apply (cut_tac r_s=\"r_s2\" and x=\"x\" and r=\"r\" in partial_add_rem_use_env)\n  apply (cut_tac r_s=\"rx\" and x=\"x\" in ignore_rem_use_env)\n   apply (simp)\n  apply (cut_tac r_s=\"rem_use_env r_s1 x\" and x=\"x\" and r=\"r\" in add_comp_use_env)\n   apply (auto)\n  apply (cut_tac r_s=\"rem_use_env r_s2 x\" and x=\"x\" and r=\"r\" in add_comp_use_env)\n    apply (auto)\n  apply (rule_tac well_typed_comp_perms)\n   apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s1\" and e=\"e\" and tau=\"tau\" and ?r_s2.0=\"r_s2\" and rx=\"rx\" and x=\"x\" in well_typed_rem_perms)\n     apply (auto)\n  apply (rule_tac disj_one_use_env)\n  apply (simp add: rem_use_env_def)\n  done    \n        \n   (*\nlemma well_typed_add_perms: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; x \\<notin> free_vars e; r = OwnPerm; rx x = NoPerm \\<rbrakk> \\<Longrightarrow>\n  well_typed env (add_use_env r_s1 x r) e tau (add_use_env r_s2 x r) rx\"\n  apply (cut_tac r_s=\"r_s1\" and x=\"x\" and r=\"r\" in partial_add_rem_use_env)\n  apply (cut_tac r_s=\"r_s2\" and x=\"x\" and r=\"r\" in partial_add_rem_use_env)\n  apply (cut_tac r_s=\"rx\" and x=\"x\" in ignore_rem_use_env)\n   apply (simp)\n  apply (cut_tac r_s=\"rem_use_env r_s1 x\" and x=\"x\" and r=\"r\" in add_comp_use_env)\n   apply (auto)\n  apply (cut_tac r_s=\"rem_use_env r_s2 x\" and x=\"x\" and r=\"r\" in add_comp_use_env)\n    apply (auto)\n  apply (rule_tac well_typed_comp_perms)\n   apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s1\" and e=\"e\" and tau=\"tau\" and ?r_s2.0=\"r_s2\" and rx=\"rx\" and x=\"x\" in well_typed_rem_perms)\n     apply (auto)\n  apply (rule_tac disj_one_use_env)\n  apply (simp add: rem_use_env_def)\n  done    *)\n  \nlemma well_typed_incr_simul_perm: \"\\<lbrakk> leq_use_env r_s r_c; well_typed env r_s e tau r_s rx \\<rbrakk> \\<Longrightarrow> well_typed env r_c e tau r_c rx\"\n  apply (rule_tac t=\"r_c\" and s=\"comp_use_env r_s (diff_use_env r_c r_s)\" in subst)\n   apply (rule_tac msum_diff_comp_use_env)\n   apply (simp)\n  apply (rule_tac well_typed_comp_perms_gen)\n   apply (simp)\n  apply (rule_tac mini_disj_diff_use_env)\n  done    \n    \nlemma well_typed_lift_perms: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx \\<rbrakk> \\<Longrightarrow> well_typed env (lift_use_env r_s1 r) e tau (lift_use_env r_s2 r) rx\"\n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)  \n        apply (auto)\n    (* const + op cases *)\n           apply (rule_tac dist_lift_leq_use_env)\n           apply (simp)\n          apply (rule_tac lift_leq_use_env)\n          apply (simp)\n         apply (rule_tac dist_lift_leq_use_env)\n         apply (simp)\n        apply (rule_tac lift_leq_use_env)\n        apply (simp)\n    (* var cases *)\n       apply (rule_tac lift_leq_use_env)\n       apply (simp)\n      apply (rule_tac x=\"r_ex\" in exI)\n      apply (auto)\n        apply (cut_tac r_s=\"r_s1\" and r_x=\"comp_use_env (ereq_use_env x1a tau_x) r_ex\" and r=\"r\" in lift_diff_use_env)\n        apply (auto)\n        apply (rule_tac dist_lift_leq_use_env)\n        apply (simp)\n       apply (rule_tac lift_leq_use_env)\n       apply (simp)\n      apply (rule_tac lift_leq_use_env)\n      apply (simp)\n    (* pair case *)\n     apply (rule_tac x=\"lift_use_env r_s2a r\" in exI)\n     apply (rule_tac x=\"lift_use_env r_s3 r\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n       apply (rule_tac lift_leq_use_env)\n       apply (simp)\n      apply (rule_tac lift_leq_use_env)\n      apply (simp)\n     apply (rule_tac x=\"r_ex\" in exI)\n     apply (auto)\n       apply (cut_tac r_s=\"r_s3\" and r_x=\"r_ex\" and r=\"r\" in lift_diff_use_env)\n       apply (simp)\n       apply (rule_tac dist_lift_leq_use_env)\n       apply (simp)\n      apply (rule_tac lift_leq_use_env)\n      apply (simp)\n     apply (rule_tac lift_leq_use_env)\n     apply (simp)\n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"lift_use_env r_s2a r\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"rx1\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"rx2\" in exI)\n    apply (auto)\n    (* lam case *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n    apply (rule_tac lift_leq_use_env)\n    apply (simp)\n   apply (rule_tac x=\"r_ex\" in exI)\n   apply (auto)\n     apply (cut_tac r_s=\"r_s1\" and r_x=\"r_ex\" and r=\"r\" in lift_diff_use_env)\n     apply (auto)\n     apply (rule_tac dist_lift_leq_use_env)\n     apply (simp)\n    apply (rule_tac lift_leq_use_env)\n    apply (simp)\n   apply (rule_tac lift_leq_use_env)\n   apply (simp)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"ra\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"lift_use_env r_s2a r\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"lift_use_env r_s3 r\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"r_ex\" in exI)\n  apply (auto)\n     apply (cut_tac r_s=\"r_s3\" and r_x=\"comp_use_env (comp_use_env rx1 (lift_use_env rx2 ra)) r_ex\" and r=\"r\" in lift_diff_use_env)\n     apply (auto)\n     apply (rule_tac dist_lift_leq_use_env)\n     apply (simp)\n    apply (rule_tac lift_leq_use_env)\n    apply (simp)\n   apply (rule_tac lift_leq_use_env)\n   apply (simp)\n  apply (rule_tac lift_leq_use_env)\n  apply (simp)\n  done    \n    \n    (* \n      ####################################\n        P8. well-typed manipulation for end permissions\n      ####################################\n    *)    \n    \nlemma wtdep_diff_use_env: \"\\<lbrakk> leq_use_env r_x (diff_use_env r_s r_xa) \\<rbrakk> \\<Longrightarrow> diff_use_env r_x r_ex = diff_use_env r_x (comp_use_env (diff_use_env r_ex r_xa) r_xa)\"    \n  apply (case_tac \"\\<forall> x. diff_use_env r_x r_ex x = diff_use_env r_x (comp_use_env (diff_use_env r_ex r_xa) r_xa) x\")\n   apply (auto)\n  apply (simp add: diff_use_env_def)\n  apply (simp add: minus_use_env_def)\n  apply (simp add: neg_use_env_def)\n  apply (simp add: leq_use_env_def)\n  apply (simp add: comp_use_env_def)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n   apply (case_tac \"r_s x\")\n     apply (auto)\n    apply (case_tac \"r_xa x\")\n      apply (auto)\n     apply (case_tac \"r_ex x\")\n       apply (auto)\n    apply (case_tac \"r_ex x\")\n      apply (auto)\n   apply (case_tac \"r_xa x\")\n     apply (auto)\n    apply (case_tac \"r_ex x\")\n      apply (auto)\n   apply (case_tac \"r_ex x\")\n     apply (auto)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n   apply (case_tac \"r_xa x\")\n     apply (auto)\n  apply (case_tac \"r_xa x\")\n    apply (auto)\n   apply (case_tac \"r_ex x\")\n     apply (auto)\n  apply (case_tac \"r_ex x\")\n    apply (auto)\n  done\n\nlemma wtdep_strong_use_vars: \"\\<lbrakk> well_typed env (diff_use_env r_s1 r_x) e tau r_s2 rx; strong_use_env r_x \\<rbrakk> \\<Longrightarrow> non_prim_vars env e \\<inter> own_env_vars r_x = {}\"    \n  apply (auto)\n  apply (case_tac \"r_x x \\<noteq> NoPerm\")\n   apply (case_tac \"r_x x\")\n     apply (auto)\n    apply (simp add: strong_use_env_def)\n   apply (cut_tac r_s=\"r_s1\" and r_ex=\"r_x\" and x=\"x\" in diff_use_none_ex)\n    apply (auto)\n   apply (cut_tac x=\"x\" and e=\"e\" and env=\"env\" and ?r_s1.0=\"diff_use_env r_s1 r_x\" in well_typed_no_npv_use)\n     apply (auto)\n  apply (simp add: own_env_vars_def)\n  done\n  \n    \nlemma well_typed_break: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau (norm_use_env r_s1 r_s2) rx\"    \n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n        apply (auto)\n    (* const case *)\n          apply (rule_tac self_norm_leq_use_env)\n         apply (rule_tac rhs_norm_leq_use_env)\n          apply (auto)\n    (* op case *)\n        apply (rule_tac self_norm_leq_use_env)\n       apply (rule_tac rhs_norm_leq_use_env)\n        apply (auto)\n    (* var case *)\n      apply (rule_tac x=\"r_ex\" in exI)\n      apply (auto)\n       apply (rule_tac diff_norm_leq_use_env)\n       apply (simp)\n      apply (rule_tac rhs_norm_leq_use_env)\n       apply (simp)\n      apply (rule_tac r_sb=\"diff_use_env r_s1 (comp_use_env (ereq_use_env x1a tau_x) r_ex)\" in trans_leq_use_env)\n       apply (rule_tac self_diff_leq_use_env)\n      apply (auto)\n    (* pair case *)\n     apply (cut_tac r_sc=\"r_s3\" and r_sb=\"r_s2a\" and r_sa=\"r_s1\" in trans_leq_use_env)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n     apply (rule_tac x=\"norm_use_env r_s1 r_s2a\" in exI)\n     apply (rule_tac x=\"norm_use_env r_s1 r_s3\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n        apply (rule_tac t=\"norm_use_env r_s1 r_s3\" and s=\"norm_use_env (norm_use_env r_s1 r_s2a) r_s3\" in subst)\n         apply (rule_tac sub_norm_use_env)\n         apply (rule_tac well_typed_perm_leq)\n         apply (auto)\n        apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s2a\" and r_c=\"norm_use_env r_s1 r_s2a\" and e=\"e2\" and ?r_s2.0=\"r_s3\" and rx=\"rx2\" in well_typed_incr_start_perm)\n          apply (auto)\n        apply (rule_tac rhs_self_norm_leq_use_env)\n        apply (rule_tac well_typed_perm_leq)\n        apply (auto)\n       apply (rule_tac rhs_norm_leq_use_env)\n        apply (auto)\n      apply (rule_tac rhs_norm_leq_use_env)\n       apply (auto)\n     apply (rule_tac x=\"r_ex\" in exI)\n     apply (auto)\n      apply (rule_tac spec_norm_leq_use_env)\n      apply (simp)\n     apply (rule_tac rhs_norm_leq_use_env)\n      apply (simp)\n     apply (rule_tac r_sb=\"diff_use_env r_s3 r_ex\" in trans_leq_use_env)\n      apply (rule_tac diff_leq_use_env)\n     apply (auto)\n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"norm_use_env r_s1 r_s2a\" in exI)\n    apply (auto)\n    (* - common substitution *)\n    apply (cut_tac ?r_s1.0=\"r_s2a\" and ?r_s2.0=\"r_s2\" in well_typed_perm_leq)\n     apply (auto)\n    apply (rule_tac t=\"norm_use_env r_s1 r_s2\" and s=\"norm_use_env (norm_use_env r_s1 r_s2a) r_s2\" in subst)\n     apply (rule_tac sub_norm_use_env)\n     apply (simp)\n    (* - rx1 *)\n    apply (rule_tac x=\"rx1\" in exI)\n    apply (auto)\n     apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s2a\" and r_c=\"norm_use_env r_s1 r_s2a\" and e=\"e2\" and ?r_s2.0=\"r_s2\" and rx=\"rx1\" in well_typed_incr_start_perm)\n       apply (auto)\n     apply (rule_tac rhs_self_norm_leq_use_env)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n    (* - rx2 *)\n    apply (rule_tac x=\"rx2\" in exI)\n    apply (auto)\n    apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s2a\" and r_c=\"norm_use_env r_s1 r_s2a\" and e=\"e3\" and ?r_s2.0=\"r_s2\" and rx=\"rx2\" in well_typed_incr_start_perm)\n      apply (auto)\n    apply (rule_tac rhs_self_norm_leq_use_env)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n    (* lam case *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_ex\" in exI)\n   apply (auto)\n    apply (rule_tac diff_norm_leq_use_env)\n    apply (simp)\n   apply (rule_tac rhs_norm_leq_use_env)\n    apply (auto)\n   apply (rule_tac r_sb=\"diff_use_env r_s1 r_ex\" in trans_leq_use_env)\n    apply (rule_tac self_diff_leq_use_env)\n   apply (auto)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"norm_use_env r_s1 r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"norm_use_env r_s1 r_s3\" in exI)\n  apply (cut_tac ?r_s1.0=\"r_s2a\" and ?r_s2.0=\"r_s3\" in well_typed_perm_leq)\n   apply (auto)\n   apply (rule_tac t=\"norm_use_env r_s1 r_s3\" and s=\"norm_use_env (norm_use_env r_s1 r_s2a) r_s3\" in subst)\n    apply (rule_tac sub_norm_use_env)\n    apply (simp)\n   apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s2a\" and r_c=\"norm_use_env r_s1 r_s2a\" and e=\"e2\" and ?r_s2.0=\"r_s3\" and rx=\"rx2\" in well_typed_incr_start_perm)\n     apply (auto)\n   apply (rule_tac rhs_self_norm_leq_use_env)\n   apply (rule_tac well_typed_perm_leq)\n   apply (auto)\n  apply (cut_tac r_sc=\"r_s3\" and r_sb=\"r_s2a\" and r_sa=\"r_s1\" in trans_leq_use_env)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n  apply (rule_tac x=\"r_ex\" in exI)\n  apply (auto)\n    apply (rule_tac spec_norm_leq_use_env)\n    apply (simp)\n   apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n    apply (rule_tac rhs_self_norm_leq_use_env)\n    apply (auto)\n  apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n   apply (rule_tac rhs_self_norm_leq_use_env)\n   apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n    apply (auto)\n  apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n   apply (rule_tac self_diff_leq_use_env)\n  apply (simp)\n  done\n    \n    (* when we perform substitution, we need to be able to stop \"requiring\" permissions. the\n    intuition behind this lemma is that we no longer need a permission if we simply remove it from\n    the list of permissions in the environment. *)    \n\nlemma well_typed_diff_end_perm: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; leq_use_env r_ex r_s1 \\<rbrakk> \\<Longrightarrow>\n  well_typed env r_s1 e tau (diff_use_env r_s2 r_ex) (diff_use_env rx r_ex)\"\n  apply (induct e arbitrary: env r_s1 tau r_s2 rx r_ex)\n        apply (auto)\n    (* const case + op case are trivial since they never require permissions *)\n          apply (rule_tac diff_leq_use_env)\n          apply (simp)\n         apply (rule_tac dist_diff_leq_use_env)\n         apply (simp)\n        apply (rule_tac diff_leq_use_env)\n        apply (simp)\n       apply (rule_tac dist_diff_leq_use_env)\n       apply (simp)\n    (* var case *)\n      apply (rule_tac x=\"comp_use_env r_exa r_ex\" in exI)\n      apply (auto)\n         apply (rule_tac rhs_unroll_dcl_use_env)\n         apply (rule_tac rhs_unroll_dcl_use_env)\n         apply (rule_tac dist_diff_leq_use_env)\n         apply (rule_tac rhs_fold_dcl_use_env)\n         apply (simp)\n        apply (rule_tac dist_diff_leq_use_env)\n        apply (simp)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (auto)\n      apply (rule_tac lhs_unroll_dcl_use_env)\n      apply (rule_tac lhs_unroll_dcl_use_env)\n      apply (rule_tac dist_diff_leq_use_env)\n      apply (rule_tac lhs_fold_dcl_use_env)\n      apply (simp)\n    (* pair case *)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (rule_tac x=\"r_s3\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"comp_use_env r_exa r_ex\" in exI)\n     apply (auto)\n        apply (rule_tac rhs_unroll_dcl_use_env)\n        apply (rule_tac dist_diff_leq_use_env)\n        apply (simp)\n       apply (rule_tac dist_diff_leq_use_env)\n       apply (simp)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (simp_all)\n     apply (case_tac \"req_type (PairTy t1 t2 r) = Prim\")\n      apply (simp add: pair_req_def)\n      apply (rule_tac leq_empty_use_env)\n     apply (simp add: pair_req_def)\n     apply (rule_tac lhs_unroll_dcl_use_env)\n     apply (rule_tac dist_diff_leq_use_env)\n     apply (simp)\n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s1\" and e=\"e1\" and ?r_s2.0=\"r_s2a\" in well_typed_break)\n     apply (auto)\n    apply (cut_tac r_x=\"r_s2a\" and r_s=\"r_s1\" in ex_norm_use_env)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n    (* - setup r_s2 \\<le> r_s1 - r_exa *)\n    apply (cut_tac r_sc=\"r_s2\" and r_sb=\"r_s2a\" and r_sa=\"norm_use_env r_s1 r_s2a\" in trans_leq_use_env)\n      apply (rule_tac rhs_self_norm_leq_use_env)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n    (* - prelim for both inductions *)\n    apply (case_tac \"diff_use_env r_s2 (comp_use_env (diff_use_env r_ex r_exa) r_exa) \\<noteq> diff_use_env (diff_use_env r_s2 (diff_use_env r_ex r_exa)) r_exa\")\n     apply (cut_tac r_s=\"r_s2\" and r_x=\"diff_use_env r_ex r_exa\" and r_ex=\"r_exa\" in diff_comp_use_env)\n     apply (auto)\n    apply (cut_tac r_sc=\"diff_use_env r_ex r_exa\" and r_sb=\"r_ex\" and r_sa=\"r_s1\" in trans_leq_use_env)\n      apply (simp)\n     apply (rule_tac self_diff_leq_use_env)\n    (* - first induction *)\n    apply (rule_tac x=\"diff_use_env r_s1 r_exa\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"diff_use_env rx1 r_ex\" in exI)\n    apply (auto)\n    apply (cut_tac r_x=\"r_s2\" and r_s=\"r_s1\" and r_xa=\"r_exa\" and r_ex=\"r_ex\" in wtdep_diff_use_env)\n     apply (auto)\n    apply (cut_tac r_x=\"rx1\" and r_s=\"r_s1\" and r_xa=\"r_exa\" and r_ex=\"r_ex\" in wtdep_diff_use_env)\n      apply (auto)\n      apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n       apply (simp)\n      apply (rule_tac well_typed_perm_leqx)\n      apply (auto)\n     apply (rule_tac t=\"diff_use_env rx1 (comp_use_env (diff_use_env r_ex r_exa) r_exa)\" and s=\"diff_use_env (diff_use_env rx1 (diff_use_env r_ex r_exa)) r_exa\" in subst)\n      apply (rule_tac diff_comp_use_env)\n     apply (rule_tac well_typed_diff_perms)\n      apply (auto)\n      apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s2a\" and r_c=\"r_s1\" and e=\"e2\" and tau=\"tau\" and ?r_s2.0=\"r_s2\" and rx=\"rx1\" in well_typed_incr_start_perm)\n        apply (auto)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n    (* - lemma to prove non-prim x is not in e2 *)\n     apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s1\" and tau=\"tau\" and ?r_s2.0=\"r_s2\" and rx=\"rx1\" and e=\"e2\" and r_x=\"r_exa\" in wtdep_strong_use_vars)\n       apply (rule_tac ?r_s1.0=\"r_s2a\" in well_typed_incr_start_perm)\n        apply (auto)\n     apply (rule_tac r_sb=\"norm_use_env r_s1 r_s2a\" in trans_leq_use_env)\n      apply (simp)\n      apply (rule_tac id_leq_use_env)\n     apply (rule_tac rhs_self_norm_leq_use_env)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n    (* - second induction *)\n    apply (rule_tac x=\"diff_use_env rx2 r_ex\" in exI)\n    apply (auto)\n     apply (cut_tac r_x=\"r_s2\" and r_s=\"r_s1\" and r_xa=\"r_exa\" and r_ex=\"r_ex\" in wtdep_diff_use_env)\n      apply (auto)\n     apply (cut_tac r_x=\"rx2\" and r_s=\"r_s1\" and r_xa=\"r_exa\" and r_ex=\"r_ex\" in wtdep_diff_use_env)\n      apply (auto)\n      apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n       apply (simp)\n      apply (rule_tac well_typed_perm_leqx)\n      apply (auto)\n     apply (rule_tac t=\"diff_use_env rx2 (comp_use_env (diff_use_env r_ex r_exa) r_exa)\" and s=\"diff_use_env (diff_use_env rx2 (diff_use_env r_ex r_exa)) r_exa\" in subst)\n      apply (rule_tac diff_comp_use_env)\n     apply (rule_tac well_typed_diff_perms)\n      apply (auto)\n      apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s2a\" and r_c=\"r_s1\" and e=\"e3\" and tau=\"tau\" and ?r_s2.0=\"r_s2\" and rx=\"rx2\" in well_typed_incr_start_perm)\n        apply (auto)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n    (* - lemma to prove non-prim x is not in e3 *)\n     apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s1\" and tau=\"tau\" and ?r_s2.0=\"r_s2\" and rx=\"rx2\" and e=\"e3\" and r_x=\"r_exa\" in wtdep_strong_use_vars)\n       apply (rule_tac ?r_s1.0=\"r_s2a\" in well_typed_incr_start_perm)\n        apply (auto)\n     apply (rule_tac r_sb=\"norm_use_env r_s1 r_s2a\" in trans_leq_use_env)\n      apply (simp)\n      apply (rule_tac id_leq_use_env)\n     apply (rule_tac rhs_self_norm_leq_use_env)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n    (* - final equality *)\n    apply (simp add: diff_use_env_def)\n    apply (rule_tac dist_minus_comp_use_env)\n    (* the lambda case allows us to select any r_s2 + rx as long as they match. *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"comp_use_env r_exa r_ex\" in exI)\n   apply (auto)\n      apply (rule_tac r_sb=\"diff_use_env (diff_use_env r_s1 r_exa) r_ex\" in trans_leq_use_env)\n       apply (rule_tac diff_comp_leq_use_env1)\n      apply (rule_tac dist_diff_leq_use_env)\n      apply (simp)\n     apply (rule_tac dist_diff_leq_use_env)\n     apply (simp)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (simp_all)\n   apply (rule_tac lhs_unroll_dcl_use_env)\n   apply (rule_tac dist_diff_leq_use_env)\n   apply (simp)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"comp_use_env r_exa r_ex\" in exI)\n  apply (auto)\n     apply (rule_tac rhs_unroll_dcl_use_env)\n     apply (rule_tac rhs_unroll_dcl_use_env)\n     apply (rule_tac dist_diff_leq_use_env)\n     apply (rule_tac rhs_fold_dcl_use_env)\n     apply (simp)\n    apply (rule_tac dist_diff_leq_use_env)\n    apply (simp)\n   apply (rule_tac dist_comp_leq_use_env)\n    apply (simp_all)\n  apply (simp add: app_req_def)\n  apply (auto)\n   apply (rule_tac leq_empty_use_env)\n  apply (rule_tac lhs_unroll_dcl_use_env)\n  apply (rule_tac lhs_unroll_dcl_use_env)\n  apply (rule_tac dist_diff_leq_use_env)\n  apply (rule_tac lhs_fold_dcl_use_env)\n  apply (simp)\n  done\n\nlemma well_typed_rem_end_perm: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; r_s1 x = OwnPerm \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau (rem_use_env r_s2 x) (rem_use_env rx x)\"  \n  apply (cut_tac r_s=\"r_s2\" and x=\"x\" in diff_rem_use_env)\n  apply (cut_tac r_s=\"rx\" and x=\"x\" in diff_rem_use_env)\n  apply (auto)\n  apply (rule_tac well_typed_diff_end_perm)\n   apply (auto)\n  apply (simp add: leq_use_env_def)\n  apply (simp add: one_use_env_def)\n  done \n    \nlemma well_typed_decr_end_perm: \"\\<lbrakk> well_typed env r_s1 e tau r_c rx; leq_use_env r_s2 r_c; leq_use_env rx r_s2 \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau r_s2 rx\"    \n  apply (induction e arbitrary: env r_s1 tau rx)\n        apply (auto)\n        apply (rule_tac r_sb=\"r_c\" in trans_leq_use_env)\n         apply (auto)\n       apply (rule_tac r_sb=\"r_c\" in trans_leq_use_env)\n        apply (auto)\n      apply (rule_tac x=\"r_ex\" in exI)\n      apply (auto)\n      apply (rule_tac r_sb=\"r_c\" in trans_leq_use_env)\n       apply (auto)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (rule_tac x=\"r_s3\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"r_ex\" in exI)\n     apply (auto)\n     apply (rule_tac r_sb=\"r_c\" in trans_leq_use_env)\n      apply (simp_all)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"r_s2a\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"rx1\" in exI)\n    apply (auto)\n     apply (cut_tac r_sa=\"r_s2\" and r_sb=\"comp_use_env rx1 rx2\" and r_sc=\"rx1\" in trans_leq_use_env)\n       apply (auto)\n     apply (rule_tac comp_leq_use_env1)\n     apply (rule_tac id_leq_use_env)\n    apply (rule_tac x=\"rx2\" in exI)\n    apply (auto)\n    apply (cut_tac r_sa=\"r_s2\" and r_sb=\"comp_use_env rx1 rx2\" and r_sc=\"rx2\" in trans_leq_use_env)\n      apply (auto)\n    apply (rule_tac comp_leq_use_env2)\n    apply (rule_tac id_leq_use_env)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_ex\" in exI)\n   apply (auto)\n   apply (rule_tac r_sb=\"r_c\" in trans_leq_use_env)\n    apply (auto)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"r_ex\" in exI)\n  apply (auto)\n  apply (rule_tac r_sb=\"r_c\" in trans_leq_use_env)\n   apply (auto)\n  done\n  \nlemma well_typed_diff_decr_end_perm: \"\\<lbrakk> well_typed env r_s1 e tau (diff_use_env r_s2 r_ex) (diff_use_env rx r_ex');\n    leq_use_env r_ex' r_ex; leq_use_env r_ex r_s1 \\<rbrakk> \\<Longrightarrow>    \n    well_typed env r_s1 e tau (diff_use_env r_s2 r_ex) (diff_use_env rx r_ex)\"\n  apply (case_tac \"well_typed env r_s1 e tau (diff_use_env r_s2 r_ex) (diff_use_env rx r_ex) =\n    well_typed env r_s1 e tau (diff_use_env (diff_use_env r_s2 r_ex) r_ex) (diff_use_env (diff_use_env rx r_ex') r_ex)\")\n   apply (simp)\n   apply (rule_tac well_typed_diff_end_perm)\n    apply (auto)\n  apply (cut_tac r_s=\"r_s2\" and r_x=\"r_ex\" in double_diff_use_env)\n  apply (cut_tac r_s=\"rx\" and r_x=\"r_ex'\" and r_c=\"r_ex\" in cancel_diff_use_env)\n   apply (auto)\n  done    \n\nlemma well_typed_diff_decr_end_perm_gen: \"\\<lbrakk> well_typed env r_s1 e tau (diff_use_env r_s2 r_exb) (diff_use_env rx r_exb);\n  leq_use_env r_exb r_exa; leq_use_env r_exa r_s1 \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau (diff_use_env r_s2 r_exa) (diff_use_env rx r_exa)\"    \n  apply (cut_tac r_s=\"r_s2\" and r_x=\"r_exb\" and r_c=\"r_exa\" in cancel_diff_use_env)\n   apply (auto)\n  apply (cut_tac r_s=\"rx\" and r_x=\"r_exb\" and r_c=\"r_exa\" in cancel_diff_use_env)\n   apply (auto)\n  apply (rule_tac well_typed_diff_end_perm)\n   apply (auto)\n  done    \n    \n    (* \n      ####################################\n        P9. well-typed manipulation for requirements\n      ####################################\n    *)\n\nlemma well_typed_comp_req1: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; leq_use_env r_ex r_s2 \\<rbrakk> \\<Longrightarrow>\n  well_typed env r_s1 e tau r_s2 (comp_use_env r_ex rx)\"\n  apply (induct e arbitrary: env r_s1 tau r_s2 rx r_ex)\n        apply (auto)\n    (* const + op case *)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (auto)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (auto)\n    (* var cases *)\n      apply (rule_tac x=\"r_exa\" in exI)\n      apply (auto)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (auto)\n      apply (rule_tac comp_leq_use_env2)\n      apply (simp)\n    (* pair case *)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (rule_tac x=\"r_s3\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"r_exa\" in exI)\n     apply (auto)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (simp_all)\n     apply (rule_tac comp_leq_use_env2)\n     apply (simp)\n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"r_s2a\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"comp_use_env r_ex rx1\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"rx2\" in exI)\n    apply (auto)\n    apply (rule_tac assoc_comp_use_env)\n    (* lambda case *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_exa\" in exI)\n   apply (auto)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (auto)\n   apply (rule_tac comp_leq_use_env2)\n   apply (simp)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"r_exa\" in exI)\n  apply (auto)\n   apply (rule_tac dist_comp_leq_use_env)\n    apply (auto)\n  apply (rule_tac comp_leq_use_env2)\n  apply (simp)\n  done\n    \nlemma well_typed_comp_req2: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; leq_use_env r_ex r_s2 \\<rbrakk> \\<Longrightarrow>\n  well_typed env r_s1 e tau r_s2 (comp_use_env rx r_ex)\"\n  apply (cut_tac r_s=\"rx\" and r_x=\"r_ex\" in comm_comp_use_env)\n  apply (auto)\n  apply (rule_tac well_typed_comp_req1)\n   apply (auto)\n  done\n\nlemma well_typed_incr_req: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; leq_use_env rx rc; leq_use_env rc r_s2 \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau r_s2 rc\"    \n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n        apply (auto)\n    (* var case *)\n      apply (rule_tac x=\"r_ex\" in exI)\n      apply (auto)\n      apply (rule_tac r_sb=\"rx\" in trans_leq_use_env)\n       apply (auto)\n    (* pair case *)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (rule_tac x=\"r_s3\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"r_ex\" in exI)\n     apply (auto)\n     apply (rule_tac r_sb=\"rx\" in trans_leq_use_env)\n      apply (auto)\n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"r_s2a\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"rc\" in exI)\n    apply (auto)\n     apply (cut_tac r_sc=\"rx1\" and r_sb=\"comp_use_env rx1 rx2\" and r_sa=\"rc\" in trans_leq_use_env)\n       apply (simp)\n      apply (rule_tac self_comp_leq_use_env1)\n     apply (simp)\n    apply (rule_tac x=\"rc\" in exI)\n    apply (auto)\n     apply (cut_tac r_sc=\"rx2\" and r_sb=\"comp_use_env rx1 rx2\" and r_sa=\"rc\" in trans_leq_use_env)\n       apply (simp)\n      apply (rule_tac self_comp_leq_use_env2)\n     apply (simp)\n    apply (case_tac \"\\<forall> x. rc x = comp_use_env rc rc x\")\n     apply (auto)\n    apply (simp add: comp_use_env_def)\n    apply (case_tac \"rc x\")\n      apply (auto)\n    (* lam case *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_ex\" in exI)\n   apply (auto)\n   apply (rule_tac r_sb=\"rx\" in trans_leq_use_env)\n    apply (auto)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"r_ex\" in exI)\n  apply (auto)\n  apply (rule_tac r_sb=\"rx\" in trans_leq_use_env)\n   apply (auto)\n  done    \n\nlemma well_typed_simul_end_perm: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; leq_use_env r_c r_s2;\n  leq_use_env rc r_c; leq_use_env rx rc \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau r_c rc\"\n  apply (rule_tac rx=\"rx\" in well_typed_incr_req)\n    apply (rule_tac r_c=\"r_s2\" in well_typed_decr_end_perm)\n      apply (auto)\n  apply (rule_tac r_sb=\"rc\" in trans_leq_use_env)\n   apply (auto)\n  done    \n    (*\nlemma well_typed_add_perms2: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; x \\<notin> non_prim_vars env e \\<rbrakk> \\<Longrightarrow>\n  well_typed env (add_use_env r_s1 x r) e tau (add_use_env r_s2 x r) rx\"\n  apply (rule_tac rx=\"rem_use_env rx x\" in well_typed_incr_req)\n    apply (cut_tac r_s=\"r_s1\" and x=\"x\" and r=\"r\" in partial_add_rem_use_env)\n    apply (cut_tac r_s=\"r_s2\" and x=\"x\" and r=\"r\" in partial_add_rem_use_env)\n    apply (cut_tac r_s=\"rem_use_env r_s1 x\" and x=\"x\" and r=\"r\" in add_comp_use_env)\n     apply (auto)\n     apply (simp add: rem_use_env_def)\n    apply (cut_tac r_s=\"rem_use_env r_s2 x\" and x=\"x\" and r=\"r\" in add_comp_use_env)\n     apply (auto)\n     apply (simp add: rem_use_env_def)\n    apply (rule_tac well_typed_comp_perms)\n     apply (rule_tac well_typed_rem_perms)\n      apply (auto)\n    apply (simp add: disj_use_env_def)\n    apply (simp add: one_use_env_def)\n    apply (simp add: rem_use_env_def)\n   apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s1\" and e=\"e\" and tau=\"tau\" and ?r_s2.0=\"r_s2\" and rx=\"rx\" and x=\"x\" in well_typed_rem_perms)\n     apply (auto)\n  done   *)     \n    \nlemma well_typed_add_permsx: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; x \\<notin> non_prim_vars env e \\<rbrakk> \\<Longrightarrow>\n  well_typed env (add_use_env r_s1 x r) e tau (add_use_env r_s2 x r) (add_use_env rx x r)\"  \n  apply (cut_tac r_s=\"r_s1\" and x=\"x\" and r=\"r\" in partial_add_rem_use_env)\n  apply (cut_tac r_s=\"r_s2\" and x=\"x\" and r=\"r\" in partial_add_rem_use_env)  \n  apply (cut_tac r_s=\"rx\" and x=\"x\" and r=\"r\" in partial_add_rem_use_env)  \n  apply (simp)\n  apply (cut_tac r_s=\"rem_use_env r_s1 x\" and x=\"x\" and r=\"r\" in add_comp_use_env)\n   apply (auto)\n   apply (simp add: rem_use_env_def)\n  apply (cut_tac r_s=\"rem_use_env r_s2 x\" and x=\"x\" and r=\"r\" in add_comp_use_env)\n   apply (auto)\n   apply (simp add: rem_use_env_def)\n  apply (cut_tac r_s=\"rem_use_env rx x\" and x=\"x\" and r=\"r\" in add_comp_use_env)\n   apply (auto)\n   apply (simp add: rem_use_env_def)\n  apply (rule_tac well_typed_comp_req2)\n   apply (rule_tac well_typed_comp_perms)\n    apply (rule_tac well_typed_rem_perms)\n     apply (auto)\n   apply (simp add: disj_use_env_def)\n   apply (simp add: mini_disj_use_env_def)\n   apply (simp add: one_use_env_def)\n   apply (simp add: rem_use_env_def)\n  apply (rule_tac self_comp_leq_use_env2)\n  done\n    \n    (* \n      ####################################\n        P10. well-typed manipulation involving lifts\n      ####################################\n    *)     \n\nlemma well_typed_lift_req: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; leq_use_env (lift_use_env rx r) r_s2 \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 e tau r_s2 (lift_use_env rx r)\"    \n  apply (induct e arbitrary: env r_s1 tau r_s2 rx)\n        apply (auto)\n    (* var case *)\n      apply (rule_tac x=\"r_ex\" in exI)\n      apply (auto)\n      apply (rule_tac lift_leq_use_env)\n      apply (simp)\n    (* pair case *)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (rule_tac x=\"r_s3\" in exI)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"r_ex\" in exI)\n     apply (auto)\n     apply (rule_tac lift_leq_use_env)\n     apply (simp)\n    (* if case *)\n    apply (rule_tac x=\"rx'\" in exI)\n    apply (rule_tac x=\"r_s2a\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"lift_use_env rx1 r\" in exI)\n    apply (auto)\n     apply (cut_tac r_sc=\"lift_use_env rx1 r\" and r_sb=\"lift_use_env (comp_use_env rx1 rx2) r\" and r_sa=\"r_s2\" in trans_leq_use_env)\n       apply (simp)\n      apply (rule_tac dist_lift_leq_use_env)\n      apply (rule_tac self_comp_leq_use_env1)\n     apply (auto)\n    apply (rule_tac x=\"lift_use_env rx2 r\" in exI)\n    apply (auto)\n     apply (cut_tac r_sc=\"lift_use_env rx2 r\" and r_sb=\"lift_use_env (comp_use_env rx1 rx2) r\" and r_sa=\"r_s2\" in trans_leq_use_env)\n       apply (simp)\n      apply (rule_tac dist_lift_leq_use_env)\n      apply (rule_tac self_comp_leq_use_env2)\n     apply (auto)\n    apply (rule_tac lift_comp_use_env)\n    (* lam case *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_ex\" in exI)\n   apply (auto)\n   apply (rule_tac lift_leq_use_env)\n   apply (simp)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"ra\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"r_ex\" in exI)\n  apply (auto)\n  apply (rule_tac lift_leq_use_env)\n  apply (auto)\n  done    \n  \nlemma well_typed_lift_all_perms: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx \\<rbrakk> \\<Longrightarrow> well_typed env (lift_use_env r_s1 r) e tau (lift_use_env r_s2 r) (lift_use_env rx r)\"\n  apply (rule_tac well_typed_lift_req)\n   apply (rule_tac well_typed_lift_perms)\n   apply (simp)\n  apply (rule_tac dist_lift_leq_use_env)\n  apply (rule_tac well_typed_perm_leqx)\n  apply (auto)\n  done        \n    \nend", "meta": {"author": "dcco", "repo": "perm_lang_ax1", "sha": "5742edc2c5db417002ed6b8acd159c522b3e6e38", "save_path": "github-repos/isabelle/dcco-perm_lang_ax1", "path": "github-repos/isabelle/dcco-perm_lang_ax1/perm_lang_ax1-5742edc2c5db417002ed6b8acd159c522b3e6e38/perm_unsafe_lift/WTLemma.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331319177487, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.2611324408038711}}
{"text": "section \\<open>Adversary Rule\\<close>\n\ntheory Adversary_Rule\n  imports Helping_Lemmas\nbegin\n\nlocale adversary_rule =\n  fixes s :: \"nat \\<Rightarrow> context\" \n  fixes s' :: \"nat \\<Rightarrow> context\"\n  fixes R :: predicate\n  fixes aux :: var\n  fixes Rv defines \"Rv \\<equiv> deidx12 (fvp R)\"\nbegin\n\ndefinition \"subst C = substitute C s\"\ndefinition \"subst' C = substitute C s'\"\n\nlemma finite_Rv: \"finite Rv\"\n  unfolding Rv_def deidx12_def apply simp\n  unfolding vimage_def[symmetric] \n  by (meson finite_fvp finite_vimageI idx_inj injI)+\n\nabbreviation \"qrhlC V C \\<equiv> qRHL (R \\<sqinter> Eq V) (subst C) (subst' C) (R \\<sqinter> Eq V)\"\n\nlemma context_induct[\n    params     i and p and           e C1 C2 and   e C and   x C and                      q C and                     C1 C2, \n    case_names Hole program[program] IfTE[IH1 IH2] While[IH] LocalC[IH program classical] LocalQ[IH program quantum] Seq[IH1 IH2]]:\n  fixes P :: \"context \\<Rightarrow> bool\"\n    and \"context\" :: \"context\"\n  assumes \"\\<And>i. P (Hole i)\"\n    and \"\\<And>p. program p \\<Longrightarrow> P p\"\n    and \"\\<And>e C1 C2. P C1 \\<Longrightarrow> P C2 \\<Longrightarrow> P (IfTE e C1 C2)\"\n    and \"\\<And>e C. P C \\<Longrightarrow> P (While e C)\"\n    and \"\\<And>x C. P C \\<Longrightarrow> \\<not> program C \\<Longrightarrow> is_classical x \\<Longrightarrow> P (Local x C)\"\n    and \"\\<And>q C. P C \\<Longrightarrow> \\<not> program C \\<Longrightarrow> is_quantum q \\<Longrightarrow> P (Local q C)\"\n    and \"\\<And>C1 C2. P C1 \\<Longrightarrow> P C2 \\<Longrightarrow> P (Seq C1 C2)\"\n  shows \"P context\"\n  apply (rule context.induct)\n  using assms apply (auto intro!: program.intros)\n  by (meson program.intros(9))\n\nlemma adversary_rule0:\n  fixes V :: \"var set\"\n  fixes Vmid :: \"var set\"\n  assumes inf_aux: \"infinite_var aux\" \n  assumes quant_aux: \"is_quantum aux\"\n  assumes aux_R: \"aux \\<notin> Rv\"\n  assumes aux_si: \"\\<And>i. i \\<in> holes C \\<Longrightarrow> aux \\<notin> fv (s i)\"\n  assumes aux_s'i: \"\\<And>i. i \\<in> holes C \\<Longrightarrow> aux \\<notin> fv (s' i)\"\n  assumes finite_Vmid: \"finite Vmid\"\n  assumes qrhl_s: \"\\<And>i. i\\<in>holes C \\<Longrightarrow> qRHL (R \\<sqinter> Eq Vmid) (s i) (s' i) (R \\<sqinter> Eq Vmid)\"\n  assumes aux_Vmid: \"aux \\<in> Vmid\"\n  assumes Vmid_V: \"Vmid \\<supseteq> V \\<union> inner C\"\n  assumes Vmid_R: \"Vmid \\<inter> Rv \\<subseteq> V \\<union> covered C\"\n  assumes Vmid_s: \"\\<And>i. i\\<in>holes C \\<Longrightarrow> Vmid \\<inter> (fv (s i) \\<union> fv (s' i)) \\<subseteq> classical' (overwr (s i) \\<inter> overwr (s' i)) \\<union> covered C \\<union> V\"\n  assumes fv_V: \"fv C \\<subseteq> V\"\n  assumes R_inner: \"Rv \\<inter> inner C = {}\"\n  assumes R_written: \"Rv \\<inter> written C = {}\"\n  shows \"qrhlC V C\"\n  using aux_si aux_s'i finite_Vmid qrhl_s aux_Vmid Vmid_V Vmid_R Vmid_s fv_V R_inner R_written apply atomize\nproof (induction C arbitrary: V Vmid rule:context_induct)\n  case (program p)\n\n  from program.prems\n  have R_written: \"Rv \\<inter> written p = {}\"\n    by simp\n\n  from \\<open>fv p \\<subseteq> V\\<close>\n  have \"qRHL (Eq V) p p (Eq V)\"\n    by (rule equal_rule)\n  then have \"qRHL (R \\<sqinter> Eq V) p p (R \\<sqinter> Eq V)\"\n    unfolding inf.commute[of R]\n    apply (rule frame_rule[rotated -1])\n    using R_written \\<open>program p\\<close>\n    by (auto simp add: Rv_def deidx12_def idx12_def is_classical'_def)\n  then show ?case \n    by (simp add: program.program subst_def subst'_def substitute_program)\nnext\n  case (Seq C1 C2)\n  have subst: \"subst (Seq C1 C2) = Seq (subst C1) (subst C2)\"\n    unfolding subst_def by simp\n  have subst': \"subst' (Seq C1 C2) = Seq (subst' C1) (subst' C2)\"\n    unfolding subst'_def by simp\n\n  have \"qrhlC V C1\"\n    apply (rule Seq.IH1)\n    using Seq.prems by (auto simp: idx12_def)\n  moreover have \"qrhlC V C2\"\n    apply (rule Seq.IH2)\n    using Seq.prems by (auto simp: idx12_def)\n  ultimately show ?case\n    unfolding subst subst'\n    by (rule seq)\nnext\n  case (IfTE e C1 C2)\n  have subst: \"subst (IfTE e C1 C2) = IfTE e (subst C1) (subst C2)\"\n    unfolding subst_def by simp\n  have subst': \"subst' (IfTE e C1 C2) = IfTE e (subst' C1) (subst' C2)\"\n    unfolding subst'_def by simp\n\n  from IfTE.prems\n  have \"CVar ` fve e \\<subseteq> V\"\n    by auto\n  then have Eq_e: \"Eq V \\<le> Eq (CVar ` fve e)\"\n    apply (subst asm_rl[of \"V = (CVar ` fve e) \\<union> (V - CVar ` fve e)\"], blast)\n    apply (subst Eq_split)\n    by (auto simp: is_classical'_def)\n\n  have \"qrhlC V C1\"\n    apply (rule IfTE.IH1)\n    using IfTE.prems by (auto simp: idx12_def)   \n  moreover have \"qrhlC V C2\"\n    apply (rule IfTE.IH2)\n    using IfTE.prems by (auto simp: idx12_def)\n  ultimately show ?case\n    unfolding subst subst'\n    apply (rule joint_if_rule[rotated -2])\n    using Eq_e by (simp_all add: inf.coboundedI2)\nnext\n  case (While e C)\n  have subst: \"subst (While e C) = While e (subst C)\"\n    unfolding subst_def by simp\n  have subst': \"subst' (While e C) = While e (subst' C)\"\n    unfolding subst'_def by simp\n\n  from While.prems\n  have \"CVar ` fve e \\<subseteq> V\"\n    by simp\n  then have Eq_e: \"Eq V \\<le> Eq (CVar ` fve e)\"\n    apply (subst asm_rl[of \"V = (CVar ` fve e) \\<union> (V - CVar ` fve e)\"], blast)\n    apply (subst Eq_split)\n    by (auto simp: is_classical'_def)\n\n  have \"qrhlC V C\"\n    apply (rule While.IH)\n    using While.prems apply simp\n    using While.prems apply (auto simp: idx12_def)[1]\n    using While.prems by auto\n  then show ?case\n    unfolding subst subst'\n    apply (rule joint_while_rule[rotated 1])\n    using Eq_e by (simp_all add: inf.coboundedI2)\nnext\n  case (LocalC x C)\n  have subst: \"subst (Local x C) = Local x (subst C)\"\n    unfolding subst_def by simp\n  have subst': \"subst' (Local x C) = Local x (subst' C)\"\n    unfolding subst'_def by simp\n\n  from LocalC.classical\n  obtain x' where x': \"x = CVar x'\"\n    using is_classical.cases by blast\n\n  from LocalC.program\n  have inner: \"inner (Local x C) = {x} \\<union> inner C\"\n    by simp\n  moreover \n  from LocalC.prems\n  have R_inner: \"Rv \\<inter> inner (Local x C) = {}\"\n    by simp\n  ultimately have xR: \" x \\<notin> Rv\"\n    by auto\n\n  have [simp]: \"CVar (idxc b x') = idx b x\" for b\n    unfolding x' by simp\n\n  have \"qrhlC (insert x V) C\"\n    apply (rule LocalC.IH[where V=\"insert x V\"])\n    using LocalC.prems inner by (auto simp: idx12_def)\n  then have \"qrhlC (V-{x}) (Local x C)\"\n    unfolding subst subst'\n    apply (rule_tac joint_local0_rule[rotated -1])\n    using xR by (auto simp: Rv_def deidx12_def)\n  then have \"qRHL (R \\<sqinter> Eq (V-{x}) \\<sqinter> Eq (V\\<inter>{x}))\n             (subst (Local x C)) (subst' (Local x C))\n             (R \\<sqinter> Eq (V-{x}) \\<sqinter> Eq (V\\<inter>{x}))\"\n    apply (rule frame_rule[rotated -1])\n    by (auto simp: is_classical'_def subst subst' idx12_def intro!: program.intros)\n  then show ?case\n    unfolding inf.assoc \n    unfolding inf.commute[of \"Eq (V-{x})\"]\n    apply (subst (asm) Eq_split[symmetric], simp add: is_classical'_def LocalC.classical)\n    apply (subst (asm) Eq_split[symmetric], simp add: is_classical'_def LocalC.classical)\n    by (simp add: Un_Diff_Int Un_commute)\nnext\n  case (LocalQ q C)\n\n  from LocalQ.program\n  have [simp]: \"inner (Local q C) = insert q (inner C)\"\n    by simp\n\n  from LocalQ.prems\n  have [simp]: \"finite V\"\n    using rev_finite_subset by blast\n\n  have cofin: \"\\<exists>x. compatible q x \\<and> P x\" if \"finite {x. \\<not> P x}\" for P :: \"var \\<Rightarrow> bool\" and q\n  proof -\n    have \"{x. compatible q x \\<and> P x} = Collect (compatible q) - {x. \\<not> P x}\"\n      by auto\n    also have \"infinite (Collect (compatible q) - {x. \\<not> P x})\"\n      using that apply (rule Diff_infinite_finite)\n      by (simp add: compatible_inexhaust)\n    finally have \"{x. compatible q x \\<and> P x} \\<noteq> {}\"\n      by force\n    then show ?thesis\n      by auto\n  qed\n\n  have [simp]: \"finite {r. \\<exists>i\\<in>holes C. r \\<in> fv (s i)}\"\n    apply (subst Collect_bex_eq)\n    apply (rule finite_Union)\n    by auto\n\n  obtain r :: var where [simp]: \\<open>compatible q r\\<close>\n    and \"r \\<notin> fv (subst C)\"\n    and \"r \\<notin> fv (subst' C)\"\n    and \"r \\<notin> Rv\"\n    and \"r \\<noteq> q\"\n    and \"r \\<notin> V\"\n    and [simp]: \"\\<And>i. i\\<in>holes C \\<Longrightarrow> r \\<notin> fv (s i)\"\n    and [simp]: \"\\<And>i. i\\<in>holes C \\<Longrightarrow> r \\<notin> fv (s' i)\"\n    apply atomize_elim\n    apply (rule cofin)\n    by (auto intro!: finite_Rv finite_vimageI[unfolded vimage_def, unfolded inj_on_def, rule_format])\n  from \\<open>compatible q r\\<close> have [simp]: \\<open>is_quantum r\\<close>\n    using LocalQ.quantum compatible_is_classical by blast\n\n  from LocalQ.quantum \\<open>is_quantum r\\<close>\n  obtain q' r' :: qvar where q': \"q = QVar q'\" and r': \"r = QVar r'\"\n    by (metis (full_types) is_classical_CVar var.exhaust)\n  with \\<open>compatible q r\\<close> have [simp]: \\<open>compatible (QVar q') (QVar r')\\<close>\n    by simp\n\n  define V' where\n    \"V' = (if q\\<in>V then insert r V - {q} else V)\"\n\n  have \"q \\<notin> V'\"\n    unfolding V'_def by auto\n\n  from LocalQ.prems\n  have qR: \"q \\<notin> Rv\"\n    by simp\n\n  have subst: \"subst (Local q C) = Local q (subst C)\"\n    unfolding subst_def by simp\n  have subst': \"subst' (Local q C) = Local q (subst' C)\"\n    unfolding subst'_def by simp\n\n  from LocalQ.prems\n  have qrhl_s: \"qRHL (R \\<sqinter> Eq Vmid) (s i) (s' i) (R \\<sqinter> Eq Vmid)\" if \"i\\<in>holes C\" for i\n    using that by simp\n\n  from LocalQ.prems\n  have aux_si: \"\\<And>i. i \\<in> holes C \\<Longrightarrow> aux \\<notin> fv (s i)\" \n    and aux_s'i: \"\\<And>i. i \\<in> holes C \\<Longrightarrow> aux \\<notin> fv (s' i)\"\n    by auto\n\n  have qrhl_sr: \"qRHL (R \\<sqinter> Eq (insert r Vmid)) (s i) (s' i) (R \\<sqinter> Eq (insert r Vmid))\" \n    if \"i\\<in>holes C\" for i\n    apply (subst asm_rl[of \"insert r Vmid = (Vmid-{aux}) \\<union> {aux,r}\"], \n               (auto simp add: \\<open>aux \\<in> Vmid\\<close>)[1])+\n    apply (rule varchange[where Q=\"{aux}\" and q=aux, rotated -1])\n          apply (subst asm_rl[of \"Vmid - {aux} \\<union> {aux} = Vmid\"], (auto simp add: \\<open>aux \\<in> Vmid\\<close>)[1])+\n          using that apply (rule qrhl_s)\n    using quant_aux \\<open>is_quantum r\\<close> inf_aux aux_R aux_si aux_s'i that\n    by (auto simp add: is_quantum'_def Rv_def deidx12_def)\n\n  have \"qrhlC (insert q V') C\"\n  proof (rule LocalQ.IH[where Vmid = \"insert r Vmid\"])\n    show \"finite (insert r Vmid)\"\n      using LocalQ.prems by simp\n    show \"aux \\<in> insert r Vmid\"\n      using LocalQ.prems by simp\n    show \"insert q V' \\<union> inner C \\<subseteq> insert r Vmid\"\n      using LocalQ.prems V'_def by auto\n    show \"insert r Vmid \\<inter> Rv \\<subseteq> insert q V' \\<union> covered C\"\n      using LocalQ.prems \\<open>r \\<notin> Rv\\<close>\n      by (auto simp: idx12_diff V'_def)\n    show \"\\<forall>i. i\\<in>holes C \\<longrightarrow> insert r Vmid \\<inter> (fv (s i) \\<union> fv (s' i))\n        \\<subseteq> classical' (overwr (s i) \\<inter> overwr (s' i)) \\<union> covered C \\<union> insert q V'\"\n      using LocalQ.prems unfolding V'_def by auto\n    show \"fv C \\<subseteq> insert q V'\"\n      using LocalQ.prems V'_def by auto\n    show \"Rv \\<inter> inner C = {}\"\n      using LocalQ.prems by auto\n    from LocalQ.prems\n    have R_written: \"Rv \\<inter> written (Local q C) = {}\"\n      by simp\n    then show \"Rv \\<inter> written C = {}\"\n      using qR by auto\n  qed (auto simp add: qrhl_sr aux_si aux_s'i)\n\n  then have qrhl_V': \"qrhlC V' (Local q C)\"\n    unfolding subst subst'\n    apply (rule joint_local0_rule[rotated -1])\n    using qR \\<open>q \\<notin> V'\\<close> \\<open>q \\<notin> V'\\<close> by (auto simp: Rv_def deidx12_def)\n\n  have [simp]: \"QVar q' \\<notin> fv (subst' (Local (QVar q') C))\"\n    using subst' by (simp add: q')\n  have [simp]: \"QVar r' \\<notin> fv (subst' (Local (QVar q') C))\"\n    using \\<open>r \\<notin> fv (subst' C)\\<close> subst' by (simp add: r' q')\n  have [simp]: \"QVar q' \\<notin> fv (subst (Local (QVar q') C))\"\n    using subst by (simp add: q')\n  have [simp]: \"QVar r' \\<notin> fv (subst (Local (QVar q') C))\"\n    using \\<open>r \\<notin> fv (subst C)\\<close> subst by (simp add: r' q')\n  have idx_r_R[simp]: \"idx b r \\<notin> fvp R\" for b\n    apply (cases b)\n    using \\<open>r \\<notin> Rv\\<close> by (simp_all add: r' deidx12_def Rv_def)\n  have idx_q_R[simp]: \"idx b q \\<notin> fvp R\" for b\n    apply (cases b)\n    using qR by (simp_all add: Rv_def deidx12_def)\n\n  have swap_V': \"transpose (QVar q') (QVar r') ` V' = V\"\n    unfolding V'_def\n    using \\<open>r \\<noteq> q\\<close> \\<open>r \\<notin> V\\<close>\n    by (auto simp: transpose_def q'[symmetric] r'[symmetric])\n\n  have \"R \\<sqinter> Eq V\n        = substp_bij (transpose (idx True q) (idx True r) o\n                   (transpose (idx False q) (idx False r))) (R \\<sqinter> Eq V')\"\n    apply (subst substp_bij_inter)\n      apply (auto intro!: valid_var_subst_comp compatible_idx simp: bij_swap_iff)[2]\n    apply (subst substp_bij_id)\n       apply (auto intro!: valid_var_subst_comp compatible_idx simp: bij_swap_iff)[3]\n     apply (metis idx_q_R idx_r_R transpose_apply_other)\n    using substp_bij_Eq  q' r' apply auto\n    by (metis \\<open>compatible q r\\<close> \\<open>r \\<noteq> q\\<close> swap_V')\n  also have \\<open>\\<dots> = substp (transpose (idx True q) (idx True r)) (substp (transpose (idx False q) (idx False r)) (R \\<sqinter> Eq V'))\\<close>\n    apply (subst substp_bij_comp[symmetric])\n        apply auto[4]\n    apply (subst substp_substp_bij[where \\<tau>=\\<open>transpose (idx True q) (idx True r)\\<close>])\n       apply auto[3]\n    apply (subst substp_substp_bij[where \\<tau>=\\<open>transpose (idx False q) (idx False r)\\<close>])\n    by auto\n\n  also have \"qRHL \\<dots> (subst (Local q C)) (subst' (Local q C)) \\<dots>\"\n    unfolding q' r'\n    apply (rule rename_qrhl1)\n      apply auto[3]\n    apply (rule rename_qrhl2)\n      apply auto[3]\n    using q' qrhl_V' by blast\n\n  finally show \"qrhlC V (Local q C)\"\n    by simp\nnext\n  case (Hole i)\n\n  define X Y Q C where \"X = {x\\<in>Vmid-V. is_classical x \\<and> x \\<in> overwr (s i) \\<and> x \\<in> overwr (s' i)}\" \n    and \"Y = {x\\<in>Vmid-V. is_classical x \\<and> \\<not> (x \\<in> overwr (s i) \\<and> x \\<in> overwr (s' i))}\"\n    and \"Q = {x\\<in>Vmid-V. is_quantum x}\" and [simp]: \"C = Hole i\"\n  \n  have quant_Q[simp]: \"is_quantum' Q\"\n    unfolding is_quantum'_def Q_def by simp\n  have class_Y[simp]: \"is_classical' Y\"\n    using Y_def is_classical'_def by blast\n\n  from \\<open>aux \\<in> Vmid\\<close> quant_aux\n  have [simp]: \"aux \\<in> V \\<union> Q\"\n    by (simp add: Q_def)\n\n  from Hole.prems\n  have Vmid_s: \"Vmid \\<inter> (fv (s i) \\<union> fv (s' i)) \\<subseteq> classical' (overwr (s i) \\<inter> overwr (s' i)) \\<union> covered C \\<union> V\"\n    and Vmid_R: \"Vmid \\<inter> Rv \\<subseteq> V \\<union> covered C\"\n    and Vmid_V: \"V \\<union> inner C \\<subseteq> Vmid\"\n    and qrhl_s: \"qRHL (R \\<sqinter> Eq Vmid) (s i) (s' i) (R \\<sqinter> Eq Vmid)\"\n    by simp_all\n\n  from Vmid_s\n  have sQ: \"fv (s i) \\<inter> Q = {}\" and s'Q: \"fv (s' i) \\<inter> Q = {}\"\n    by (auto simp add: Q_def classical'_def)\n\n  from \\<open>finite Vmid\\<close>\n  have \"finite X\"\n    unfolding X_def by simp\n\n  have class_X: \"is_classical' X\"\n    unfolding X_def is_classical'_def by simp\n\n  from Vmid_s\n  have X_overwr_si: \"X \\<subseteq> overwr (s i)\" and X_overwr_si': \"X \\<subseteq> overwr (s' i)\"\n    using overwr_fv[of \"s i\"] overwr_fv[of \"s' i\"] unfolding X_def classical'_def by auto\n\n  then obtain Xlist where Xlist: \"X = CVar ` set Xlist\"\n    using class_X \\<open>finite X\\<close>\n    by (metis finite_list is_classical'_def finite_subset_image imageI is_classical.simps subsetI)\n  have Vmid_XYQ: \"Vmid = V \\<union> X \\<union> Y \\<union> Q\"\n    unfolding X_def Y_def Q_def using Vmid_V by blast\n  have \"X \\<inter> V = {}\" and \"X \\<inter> Y = {}\" and \"X \\<inter> Q = {}\"\n    unfolding X_def Y_def Q_def\n    by auto\n  moreover \n  from \\<open>X \\<inter> V = {}\\<close>\n  have \"idx12 X \\<inter> idx12 V = {}\"\n    unfolding idx12_def by auto\n  then have \"idx12 X \\<inter> fvp R = {}\"\n    using Vmid_R unfolding Rv_def deidx12_def idx12_def Vmid_XYQ idx12_union by auto\n  ultimately have 1: \"idx12 X \\<inter> fvp (R \\<sqinter> Eq (V \\<union> Y \\<union> Q)) = {}\"\n    apply (rule_tac fvp_inter_empty)\n    by (auto simp add: idx12_def)\n\n  have \"Y \\<inter> V = {}\" and \"Y \\<inter> Q = {}\"\n    unfolding Y_def Q_def by auto\n  moreover \n  from \\<open>Y \\<inter> V = {}\\<close>\n  have \"idx12 Y \\<inter> idx12 V = {}\"\n    unfolding idx12_def by auto\n  then have \"idx12 Y \\<inter> fvp R = {}\"\n    using Vmid_R unfolding Rv_def idx12_def deidx12_def Vmid_XYQ idx12_union by auto\n  ultimately have 2: \"idx12 Y \\<inter> fvp (R \\<sqinter> Eq (V \\<union> Q)) = {}\"\n    apply (rule_tac fvp_inter_empty)\n    by (auto simp add: idx12_def)\n  have siY: \"fv (s i) \\<inter> Y = {}\" and s'iY: \"fv (s' i) \\<inter> Y = {}\"\n    using Vmid_s unfolding Y_def classical'_def by auto\n\n  have \"R \\<sqinter> Eq (V \\<union> Q) \\<sqinter> Eq Y = R \\<sqinter> Eq (V \\<union> Y \\<union> Q)\"\n    apply (subst asm_rl[of \"V \\<union> Y \\<union> Q = Y \\<union> (V \\<union> Q)\"], blast)\n    apply (subst Eq_split[where X=Y], simp)\n    by (simp add: inf_commute inf_left_commute)\n  also have \"qRHL (R \\<sqinter> Eq (V \\<union> Y \\<union> Q)) (Assign Xlist some_constant) (Assign Xlist some_constant) (R \\<sqinter> Eq Vmid)\"\n    apply (subst asm_rl[of \"R \\<sqinter> Eq Vmid = Eq (CVar ` set Xlist) \\<sqinter> (R \\<sqinter> Eq (V \\<union> Y \\<union> Q))\"])\n     apply (metis Eq_split Vmid_XYQ Xlist class_X inf_left_commute sup_commute sup_left_commute)\n    apply (subst asm_rl[of \"(R \\<sqinter> Eq (V \\<union> Y \\<union> Q)) = top \\<sqinter> (R \\<sqinter> Eq (V \\<union> Y \\<union> Q))\"], simp)\n    apply (rule frame_rule)\n    using 1 apply (auto simp: idx12_def Xlist[symmetric] intro!: program.intros) [2]\n    by (rule assign_Eq)\n  also from qrhl_s have \"qrhlC Vmid C\"\n    unfolding subst_def subst'_def by auto\n  also have \"Assign Xlist some_constant; subst C =d= subst C\"\n    apply (rule denot_eq_init)\n    unfolding subst_def apply auto using X_overwr_si Xlist by blast\n  also have \"Assign Xlist some_constant; subst' C =d= subst' C\"\n    apply (rule denot_eq_init)\n    unfolding subst'_def apply auto using X_overwr_si' Xlist by blast\n  also have \"R \\<sqinter> Eq Vmid \\<le> R \\<sqinter> Eq (V \\<union> Q)\"\n    apply (rule inf_mono, simp)\n    apply (rule weaken_Eq)\n    using class_X Vmid_XYQ is_classical'_def Q_def\n    by blast+\n  finally have \"qRHL (R \\<sqinter> Eq (V \\<union> Q) \\<sqinter> Eq Y) (subst C) (subst' C) (R \\<sqinter> Eq (V \\<union> Q))\"\n    by auto\n\n  then have qrhl_VQ: \"qrhlC (V \\<union> Q) C\"\n    apply (rule drop_Eq[rotated -1]) \n    using 2 siY s'iY by (auto simp: subst_def subst'_def)\n\n  from Hole.prems\n  have aux_si: \"aux \\<notin> fv (s i)\"\n    and aux_s'i: \"aux \\<notin> fv (s' i)\"\n    by auto\n\n  have \"qrhlC ((V - {aux}) \\<union> (V \\<inter> {aux})) (Hole i)\"\n    apply (rule varchange[where Q=\"insert aux Q\" and q=aux])\n    using inf_aux quant_aux quant_Q aux_R\n      aux_si aux_s'i sQ s'Q\n          apply (auto simp: is_quantum'_def idx12_def subst_def subst'_def Rv_def deidx12_def)[6]\n    using qrhl_VQ \\<open>aux \\<in> V \\<union> Q\\<close>\n    by (metis C_def Un_insert_right insert_Diff_single insert_absorb sup_commute)\n\n  then show ?case\n    by (simp add: Un_Diff_Int)\nqed\n\nlemma adversary_rule:\n  fixes Vin :: \"var set\"\n  fixes Vout :: \"var set\"\n  fixes Vmid :: \"var set\"\n  assumes inf_aux: \"infinite_var aux\" \n  assumes quant_aux: \"is_quantum aux\"\n  assumes aux_R: \"aux \\<notin> Rv\"\n  assumes finite_Vmid: \"finite Vmid\"\n  assumes finite_Vin: \"finite Vin\"\n  assumes aux_si: \"\\<And>i. i \\<in> holes C \\<Longrightarrow> aux \\<notin> fv (s i)\"\n  assumes aux_s'i: \"\\<And>i. i \\<in> holes C \\<Longrightarrow> aux \\<notin> fv (s' i)\"\n  assumes qrhl_s: \"\\<And>i. i \\<in> holes C \\<Longrightarrow> qRHL (R \\<sqinter> Eq Vmid) (s i) (s' i) (R \\<sqinter> Eq Vmid)\"\n  assumes aux_Vmid: \"aux \\<in> Vmid\"\n  assumes inner_Vmid: \"inner C \\<subseteq> Vmid\"\n  assumes Vout_Vmid: \"Vout \\<subseteq> Vmid\"\n  assumes Vout_overwr_Vin: \"Vout - overwr C \\<subseteq> Vin\"\n  assumes Vout_Vin_R: \"(Vout - Vin) \\<inter> Rv = {}\"\n  assumes Vin_Vout_overwr: \"quantum' Vin \\<subseteq> Vout \\<union> overwr C\"\n  assumes Vin_Vout_R: \"quantum' (Vin - Vout) \\<inter> Rv = {}\"\n  assumes Vmid_R_Vin_covered: \"Vmid \\<inter> Rv \\<subseteq> Vin \\<union> covered C\"\n  assumes Vmid_R_Vout_covered: \"quantum' (Vmid \\<inter> Rv) \\<subseteq> Vout \\<union> covered C\"\n  assumes Vmid_s_Vin_covered: \"\\<And>i. i \\<in> holes C \\<Longrightarrow> Vmid \\<inter> (fv (s i) \\<union> fv (s' i)) \\<subseteq> Vin \\<union> covered C \\<union> classical' (overwr (s i) \\<inter> overwr (s' i))\"\n  assumes Vmid_s_Vout_covered: \"\\<And>i. i \\<in> holes C \\<Longrightarrow> quantum' Vmid \\<inter> (fv (s i) \\<union> fv (s' i)) \\<subseteq> Vout \\<union> covered C\"\n  assumes C_Vmid: \"fv C \\<subseteq> Vmid\"\n  assumes C_Vin_overwr: \"fv C \\<subseteq> Vin \\<union> overwr C\"\n  assumes C_Vin_R: \"fv C \\<inter> Rv \\<subseteq> Vin\"\n  assumes C_Vout: \"quantum' (fv C) \\<subseteq> Vout\"\n  assumes R_inner: \"Rv \\<inter> inner C = {}\"\n  assumes R_written: \"Rv \\<inter> written C = {}\"\n\n  shows \"qRHL (R \\<sqinter> Eq Vin) (subst C) (subst' C) (R \\<sqinter> Eq Vout)\"\nproof -\n  define V where \n    \"V = Vmid \\<inter> (overwr C \\<union> Vin) \\<inter> (Vin \\<union> - Rv) \\<inter> (Vout \\<union> range CVar)\"\n\n  have [simp]: \"finite V\"\n    unfolding V_def\n    using finite_Vmid by blast\n\n  have Vmid_V: \"V \\<union> inner C \\<subseteq> Vmid\"\n    unfolding V_def using inner_Vmid by auto\n  have Vmid_R: \"Vmid \\<inter> Rv \\<subseteq> V \\<union> covered C\"\n    unfolding V_def\n    using Vmid_R_Vin_covered Vmid_R_Vout_covered\n    unfolding quantum'_def is_classical.simps\n    by auto\n  have Vmid_s: \"Vmid \\<inter> (fv (s i) \\<union> fv (s' i))\n         \\<subseteq> classical' (overwr (s i) \\<inter> overwr (s' i)) \\<union> covered C \\<union> V\" if \"i\\<in>holes C\" for i\n    unfolding V_def Un_Int_distrib\n    apply (rule Int_greatest)+\n       apply blast\n      using Vmid_s_Vin_covered that apply blast\n     using Vmid_s_Vin_covered that apply fastforce\n    using Vmid_s_Vout_covered that by (auto simp: quantum'_def is_classical.simps)\n  have fv_V: \"fv C \\<subseteq> V\"\n    using C_Vmid C_Vin_overwr C_Vin_R C_Vout\n    unfolding V_def Rv_def quantum'_def is_classical.simps by auto\n  have V_Vin_overwr: \"V - Vin \\<subseteq> overwr C\"\n    unfolding V_def by auto\n  have Vin_V_overwr: \"quantum' (Vin - V) \\<subseteq> overwr C\"\n    using Vout_Vmid Vin_Vout_overwr\n    unfolding V_def quantum'_def\n    by auto\n  have V_Vin_R: \"idx12 (V - Vin) \\<inter> fvp R = {}\"\n    unfolding V_def idx12_def deidx12_def Rv_def by auto\n  have \"quantum' (Vin - V) \\<inter> deidx12 (fvp R) = {}\"\n    using Vin_Vout_R Diff_disjoint Vout_Vmid \n    unfolding V_def quantum'_def Rv_def\n    by auto\n  then have Vin_V_R: \"idx12 (quantum' (Vin - V)) \\<inter> fvp R = {}\"\n    unfolding deidx12_def idx12_def by auto\n  have Vout_V: \"Vout \\<subseteq> V\"\n    using Vout_Vmid Vout_overwr_Vin Vout_Vin_R \n    unfolding deidx12_def V_def Rv_def\n    by auto\n  have Vout_V_class: \"is_classical' (V - Vout)\"\n    unfolding V_def is_classical'_def by auto\n\n  from inf_aux quant_aux aux_R aux_si aux_s'i  finite_Vmid qrhl_s aux_Vmid Vmid_V Vmid_R Vmid_s fv_V R_inner R_written\n  have \\<open>qrhlC V C\\<close>\n    by (rule adversary_rule0[where Vmid=Vmid])\n\n  then have \\<open>qRHL (R \\<sqinter> Eq Vin) (subst C) (subst' C) (R \\<sqinter> Eq V)\\<close>\n    apply (rule change_Eq_precondition[rotated -1])\n    using V_Vin_overwr overwr_subst subst'_def subst_def apply auto[1]\n    using Vin_V_overwr overwr_subst subst'_def subst_def apply auto[1] \n    using \\<open>finite V\\<close> \\<open>finite Vin\\<close> V_Vin_R Vin_V_R by simp_all\n  also have \"R \\<sqinter> Eq V \\<le> R \\<sqinter> Eq Vout\"\n    apply (rule inf_mono, simp)\n    apply (subst asm_rl[of \"V = (V-Vout) \\<union> Vout\"])\n    using Vout_V apply auto[1]\n    apply (subst Eq_split)\n    using Vout_V_class by auto\n  finally show ?thesis\n    by auto \n\nqed\n\nend\n\nend\n", "meta": {"author": "dominique-unruh", "repo": "qrhl-local-variables-isabelle", "sha": "372d8b88b62628a1088931392e71d82302178512", "save_path": "github-repos/isabelle/dominique-unruh-qrhl-local-variables-isabelle", "path": "github-repos/isabelle/dominique-unruh-qrhl-local-variables-isabelle/qrhl-local-variables-isabelle-372d8b88b62628a1088931392e71d82302178512/Adversary_Rule.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.4843800842769843, "lm_q1q2_score": 0.2610727378605809}}
{"text": "(* Author: Florian Haftmann, TU Muenchen *)\n\nsection \\<open>Reflecting Pure types into HOL\\<close>\n\ntheory Typerep\nimports String\nbegin\n\ndatatype typerep = Typerep String.literal \"typerep list\"\n\nclass typerep =\n  fixes typerep :: \"'a itself \\<Rightarrow> typerep\"\nbegin\n\ndefinition typerep_of :: \"'a \\<Rightarrow> typerep\" where\n  [simp]: \"typerep_of x = typerep TYPE('a)\"\n\nend\n\nsyntax\n  \"_TYPEREP\" :: \"type => logic\"  (\"(1TYPEREP/(1'(_')))\")\n\nparse_translation \\<open>\n  let\n    fun typerep_tr (*\"_TYPEREP\"*) [ty] =\n          Syntax.const \\<^const_syntax>\\<open>typerep\\<close> $\n            (Syntax.const \\<^syntax_const>\\<open>_constrain\\<close> $ Syntax.const \\<^const_syntax>\\<open>Pure.type\\<close> $\n              (Syntax.const \\<^type_syntax>\\<open>itself\\<close> $ ty))\n      | typerep_tr (*\"_TYPEREP\"*) ts = raise TERM (\"typerep_tr\", ts);\n  in [(\\<^syntax_const>\\<open>_TYPEREP\\<close>, K typerep_tr)] end\n\\<close>\n\ntyped_print_translation \\<open>\n  let\n    fun typerep_tr' ctxt (*\"typerep\"*)\n            (Type (\\<^type_name>\\<open>fun\\<close>, [Type (\\<^type_name>\\<open>itself\\<close>, [T]), _]))\n            (Const (\\<^const_syntax>\\<open>Pure.type\\<close>, _) :: ts) =\n          Term.list_comb\n            (Syntax.const \\<^syntax_const>\\<open>_TYPEREP\\<close> $ Syntax_Phases.term_of_typ ctxt T, ts)\n      | typerep_tr' _ T ts = raise Match;\n  in [(\\<^const_syntax>\\<open>typerep\\<close>, typerep_tr')] end\n\\<close>\n\nsetup \\<open>\nlet\n\nfun add_typerep tyco thy =\n  let\n    val sorts = replicate (Sign.arity_number thy tyco) \\<^sort>\\<open>typerep\\<close>;\n    val vs = Name.invent_names Name.context \"'a\" sorts;\n    val ty = Type (tyco, map TFree vs);\n    val lhs = Const (\\<^const_name>\\<open>typerep\\<close>, Term.itselfT ty --> \\<^typ>\\<open>typerep\\<close>)\n      $ Free (\"T\", Term.itselfT ty);\n    val rhs = \\<^term>\\<open>Typerep\\<close> $ HOLogic.mk_literal tyco\n      $ HOLogic.mk_list \\<^typ>\\<open>typerep\\<close> (map (HOLogic.mk_typerep o TFree) vs);\n    val eq = HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs));\n  in\n    thy\n    |> Class.instantiation ([tyco], vs, \\<^sort>\\<open>typerep\\<close>)\n    |> `(fn lthy => Syntax.check_term lthy eq)\n    |-> (fn eq => Specification.definition NONE [] [] (Binding.empty_atts, eq))\n    |> snd\n    |> Class.prove_instantiation_exit (fn ctxt => Class.intro_classes_tac ctxt [])\n  end;\n\nfun ensure_typerep tyco thy =\n  if not (Sorts.has_instance (Sign.classes_of thy) tyco \\<^sort>\\<open>typerep\\<close>)\n    andalso Sorts.has_instance (Sign.classes_of thy) tyco \\<^sort>\\<open>type\\<close>\n  then add_typerep tyco thy else thy;\n\nin\n\nadd_typerep \\<^type_name>\\<open>fun\\<close>\n#> Typedef.interpretation (Local_Theory.background_theory o ensure_typerep)\n#> Code.type_interpretation ensure_typerep\n\nend\n\\<close>\n\n\n\nlemma [code nbe]:\n  \"HOL.equal (x :: typerep) x \\<longleftrightarrow> True\"\n  by (fact equal_refl)\n\ncode_printing\n  type_constructor typerep \\<rightharpoonup> (Eval) \"Term.typ\"\n| constant Typerep \\<rightharpoonup> (Eval) \"Term.Type/ (_, _)\"\n\ncode_reserved Eval Term\n\nhide_const (open) typerep Typerep\n\nend\n", "meta": {"author": "landonf", "repo": "isabelle-legacy", "sha": "e40f3ca7e9a42bb91e57fd15f969388e6e83f692", "save_path": "github-repos/isabelle/landonf-isabelle-legacy", "path": "github-repos/isabelle/landonf-isabelle-legacy/isabelle-legacy-e40f3ca7e9a42bb91e57fd15f969388e6e83f692/src/HOL/Typerep.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.538983220687684, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.26107273786058083}}
{"text": "theory User_Execution\n                  \nimports Context_Switch\n        \n\nbegin               \n\n\n\ndefinition\n  ptable_lift_user :: \"vaddr  \\<Rightarrow> p_state  \\<Rightarrow> paddr \\<Rightarrow> bool\"    (\"(_/ \\<hookrightarrow>\\<^sub>_/ \\<^sub>u\\<^sub>s\\<^sub>e\\<^sub>r / _)\")\nwhere\n  \"ptable_lift_user va s p \\<equiv> (ptable_lift_m (heap s) (root s) User va  = Some p)\"\n\n\n\ndefinition                   \n  user_safe :: \"p_state \\<Rightarrow> vaddr set\"\nwhere\n  \"user_safe s = {va. \\<exists>p. va \\<hookrightarrow>\\<^sub>s  \\<^sub>u\\<^sub>s\\<^sub>e\\<^sub>r  p } \"\n\n\n\n\nlemma mmu_layout_no_phy:\n  \"\\<lbrakk> mmu_layout s; mode s = User;  ptable_lift_m (heap s) (root s) (mode s) (Addr vp) = Some p \\<rbrakk> \n           \\<Longrightarrow> p \\<notin> kernel_phy_mem\"\n  by (clarsimp simp: mmu_layout_def user_mappings_def dest!: root_map_rootsD)\n\nlemma phy_mem_data_area:\n  \"\\<lbrakk> mmu_layout s; p \\<notin> kernel_phy_mem \\<rbrakk> \n           \\<Longrightarrow> p \\<notin> kernel_data_area s\"\n  apply (clarsimp simp: mmu_layout_def )\n  by blast\n  \n \n\nlemma user_safe_assignment:\n  \"\\<Turnstile> \\<lbrace> \\<lambda>s. mmu_layout s \\<and> mode s = User \\<and> \\<I>\\<C> s = {} \\<and>\n           aval lval s = Some vp \\<and> aval rval s = Some v \\<and> \n         ptable_lift_m (heap s) (root s) (mode s) (Addr vp) = Some p \\<rbrace>\n                  lval ::= rval\n           \\<lbrace>\\<lambda>s. mmu_layout s \\<and> mode s = User \\<and> \\<I>\\<C> s = {} \\<and> heap s p = Some v\\<rbrace>\"\n  apply vcgm\n  apply (rule conjI)\n   apply (clarsimp simp: \\<I>\\<C>_def)\n  apply (frule_tac vp = vp and p = p in  mmu_layout_no_phy , clarsimp , clarsimp)\n  apply (frule_tac  p = p in phy_mem_data_area, simp)\n  apply (clarsimp simp: mmu_layout_global_heap_upd)\n  apply (frule_tac mmu_layout_global_set_subset, simp)\n  apply (simp add: mmu_layout_ptable_comp mmu_layout_upd)\n  apply (simp add: \\<I>\\<C>_def)\n  done\n\n  \nend\n", "meta": {"author": "SEL4PROJ", "repo": "tlb", "sha": "88bb017dd96c3830baed93ba62e45b45050d1417", "save_path": "github-repos/isabelle/SEL4PROJ-tlb", "path": "github-repos/isabelle/SEL4PROJ-tlb/tlb-88bb017dd96c3830baed93ba62e45b45050d1417/Logic/User_Execution.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.640635854839898, "lm_q2_score": 0.4073334000459302, "lm_q1q2_score": 0.26095238094326667}}
{"text": "section \\<open>Secure composition: Encrypt then MAC\\<close>\n\ntheory Secure_Channel imports\n  One_Time_Pad\n  Message_Authentication_Code\nbegin\n\ncontext begin\ninterpretation INSEC: insec_channel .\n\ninterpretation MAC: macode \"rnd \\<eta>\" \"mac \\<eta>\" for \\<eta> . \ninterpretation AUTH: auth_channel . \n\ninterpretation CIPHER: cipher \"key \\<eta>\" \"enc \\<eta>\" \"dec \\<eta>\" for \\<eta> . \ninterpretation SEC: sec_channel .\n\nlemma plossless_enc [plossless_intro]:\n  \"plossless_converter (\\<I>_uniform (nlists UNIV \\<eta>) UNIV) (\\<I>_uniform UNIV (nlists UNIV \\<eta>) \\<oplus>\\<^sub>\\<I> \\<I>_uniform (nlists UNIV \\<eta>) UNIV) (CIPHER.enc \\<eta>)\"\n  unfolding CIPHER.enc_def\n  by(rule plossless_converter_of_callee) (auto simp add: stateless_callee_def enc_def in_nlists_UNIV)\n\nlemma plossless_dec [plossless_intro]:\n  \"plossless_converter (\\<I>_uniform UNIV (insert None (Some ` nlists UNIV \\<eta>))) (\\<I>_uniform UNIV (nlists UNIV \\<eta>) \\<oplus>\\<^sub>\\<I> \\<I>_uniform UNIV (insert None (Some ` nlists UNIV \\<eta>))) (CIPHER.dec \\<eta>)\"\n  unfolding CIPHER.dec_def\n  by(rule plossless_converter_of_callee) (auto simp add: stateless_callee_def dec_def in_nlists_UNIV split: option.split)\n\nlemma callee_invariant_on_key_oracle:\n  \"callee_invariant_on\n     (CIPHER.KEY.key_oracle \\<eta> \\<oplus>\\<^sub>O CIPHER.KEY.key_oracle \\<eta>)\n     (\\<lambda>x. case x of None \\<Rightarrow> True | Some x' \\<Rightarrow> length x' = \\<eta>)\n     (\\<I>_uniform UNIV (nlists UNIV \\<eta>) \\<oplus>\\<^sub>\\<I> \\<I>_full)\"\nproof(unfold_locales, goal_cases)\n  case (1 s x y s')\n  then show ?case by(cases x; clarsimp split: option.splits; simp add: key_def in_nlists_UNIV)\nnext\n  case (2 s)\n  then show ?case by(clarsimp intro!: WT_calleeI split: option.split_asm)(simp_all add: in_nlists_UNIV key_def)\nqed\n\ninterpretation key: callee_invariant_on\n  \"CIPHER.KEY.key_oracle \\<eta> \\<oplus>\\<^sub>O CIPHER.KEY.key_oracle \\<eta>\"\n  \"\\<lambda>x. case x of None \\<Rightarrow> True | Some x' \\<Rightarrow> length x' = \\<eta>\"\n  \"\\<I>_uniform UNIV (nlists UNIV \\<eta>) \\<oplus>\\<^sub>\\<I> \\<I>_full\" for \\<eta>\n  by(rule callee_invariant_on_key_oracle)\n\nlemma WT_enc [WT_intro]: \"\\<I>_uniform (nlists UNIV \\<eta>) UNIV,\n  \\<I>_uniform UNIV (nlists UNIV \\<eta>) \\<oplus>\\<^sub>\\<I> \\<I>_uniform (vld \\<eta>) UNIV \\<turnstile>\\<^sub>C CIPHER.enc \\<eta> \\<surd>\"\n  unfolding CIPHER.enc_def\n  by (rule WT_converter_of_callee) (simp_all add: stateless_callee_def vld_def enc_def in_nlists_UNIV)\n\nlemma WT_dec [WT_intro]: \"\\<I>_uniform UNIV (insert None (Some ` nlists UNIV \\<eta>)),\n    \\<I>_uniform UNIV (nlists UNIV \\<eta>) \\<oplus>\\<^sub>\\<I> \\<I>_uniform UNIV (insert None (Some ` vld \\<eta>)) \\<turnstile>\\<^sub>C\n    CIPHER.dec \\<eta> \\<surd>\"\n  unfolding CIPHER.dec_def\n  by(rule WT_converter_of_callee)(auto simp add: stateless_callee_def dec_def vld_def in_nlists_UNIV)\n\nlemma bound_enc [interaction_bound]: \"interaction_any_bounded_converter (CIPHER.enc \\<eta>) (enat 2)\"\n  unfolding CIPHER.enc_def\n  by (rule interaction_any_bounded_converter_of_callee) \n    (auto simp add: stateless_callee_def map_gpv_id_bind_gpv zero_enat_def one_enat_def)\n\nlemma bound_dec [interaction_bound]: \"interaction_any_bounded_converter (CIPHER.dec \\<eta>) (enat 2)\"\n  unfolding CIPHER.dec_def\n  by (rule interaction_any_bounded_converter_of_callee)\n    (auto simp add: stateless_callee_def map_gpv_id_bind_gpv zero_enat_def one_enat_def split: sum.split option.split)\n\ntheorem mac_otp:\n  defines \"\\<I>_real \\<equiv> \\<lambda>\\<eta>. \\<I>_uniform {x. valid_mac_query \\<eta> x} UNIV\"\n    and \"\\<I>_ideal \\<equiv> \\<lambda>_. \\<I>_full\"\n    and \"\\<I>_common \\<equiv> \\<lambda>\\<eta>. \\<I>_uniform (vld \\<eta>) UNIV \\<oplus>\\<^sub>\\<I> \\<I>_full\"\n  shows\n    \"constructive_security\n      (\\<lambda>\\<eta>. 1\\<^sub>C |\\<^sub>= (CIPHER.enc \\<eta> |\\<^sub>= CIPHER.dec \\<eta>) \\<odot> parallel_wiring \\<rhd>\n            parallel_resource1_wiring \\<rhd>\n            CIPHER.KEY.res \\<eta> \\<parallel>\n            (1\\<^sub>C |\\<^sub>= MAC.enm \\<eta> |\\<^sub>= MAC.dem \\<eta> \\<rhd>\n             1\\<^sub>C |\\<^sub>= parallel_wiring \\<rhd>\n             parallel_resource1_wiring \\<rhd> MAC.RO.res \\<eta> \\<parallel> INSEC.res))\n      (\\<lambda>_. SEC.res)\n      (\\<lambda>\\<eta>. CNV Message_Authentication_Code.sim (Inl None) \\<odot> CNV One_Time_Pad.sim None)\n      (\\<lambda>\\<eta>. \\<I>_uniform (Set.Collect (valid_mac_query \\<eta>)) (insert None (Some ` (nlists UNIV \\<eta> \\<times> nlists UNIV \\<eta>))))\n      (\\<lambda>\\<eta>. \\<I>_uniform UNIV {None, Some \\<eta>})\n      (\\<lambda>\\<eta>. \\<I>_uniform (nlists UNIV \\<eta>) UNIV \\<oplus>\\<^sub>\\<I> \\<I>_uniform UNIV (insert None (Some ` nlists UNIV \\<eta>)))\n      (\\<lambda>_. enat q) True (\\<lambda>\\<eta>. (id, map_option length) \\<circ>\\<^sub>w (insec_query_of, map_option snd))\"\nproof(rule composability[OF one_time_pad[THEN constructive_security2.constructive_security, unfolded CIPHER.res_alt_def comp_converter_parallel2 comp_converter_id_left]\n  secure_mac[unfolded MAC.res_def, \n        THEN constructive_security.parallel_resource1,\n        THEN constructive_security.lifting],\n      where ?\\<I>_res2=\"\\<lambda>\\<eta>. \\<I>_uniform UNIV (nlists UNIV \\<eta>) \\<oplus>\\<^sub>\\<I> \\<I>_uniform UNIV (nlists UNIV \\<eta>)\" and ?bound_conv1=\"\\<lambda>_. 2\" and ?q3 = \"2 * q\" and bound_sim = \"\\<lambda>_. \\<infinity>\",\nsimplified]\n    , goal_cases)\n  case (1 \\<eta>)\n  have [simp]: \"\\<I>_uniform UNIV (nlists UNIV \\<eta>) \\<turnstile>c CIPHER.KEY.key_oracle \\<eta> s \\<surd>\"\n    if \"pred_option (\\<lambda>x. length x = \\<eta>) s\" for s \\<eta>\n    apply(rule WT_calleeI)\n    subgoal for call using that by(cases s; cases call; clarsimp; auto simp add: key_def in_nlists_UNIV)\n    done\n  have *: \"callee_invariant_on (CIPHER.KEY.key_oracle \\<eta> \\<oplus>\\<^sub>O CIPHER.KEY.key_oracle \\<eta>) (pred_option (\\<lambda>x. length x = \\<eta>))\n     (\\<I>_uniform UNIV (nlists UNIV \\<eta>) \\<oplus>\\<^sub>\\<I> \\<I>_uniform UNIV (nlists UNIV \\<eta>))\" for \\<eta>\n    apply(unfold_locales)\n    subgoal for s x y s' by(cases s; cases x; clarsimp; auto simp add: key_def in_nlists_UNIV)\n    subgoal for s by auto\n    done\n  then show ?case unfolding CIPHER.KEY.res_def\n    by(rule callee_invariant_on.WT_resource_of_oracle) simp\n\n  case (2 \\<eta>)\n  show ?case \n    unfolding CIPHER.KEY.res_def\n    apply(rule callee_invariant_on.lossless_resource_of_oracle[OF *])\n    subgoal for s x by(cases s; cases x)(auto split: plus_oracle_split; simp add: key_def)+\n    subgoal by simp\n    done\n\n  case (3 \\<eta>)\n  show ?case by(rule WT_intro)+\n\n  case (4 \\<eta>)\n  show ?case by interaction_bound_converter code_simp\n\n  case (5 \\<eta>)\n  show ?case by (simp add: mult_2_right)\n\n  case (6 \\<eta>)\n  show ?case unfolding vld_def by(rule plossless_intro WT_intro[unfolded vld_def])+\nqed\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Constructive_Cryptography/Examples/Secure_Channel/Secure_Channel.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6406358411176238, "lm_q2_score": 0.40733340004593027, "lm_q1q2_score": 0.2609523753537261}}
{"text": "(*<*)\ntheory Everything\nimports DenotationalEquivalences Correctness CorrectnessUpd \"Correctness-Counterexample\" \"~~/src/HOL/Library/LaTeXsugar\" \nbegin\n\nnotation (latex output) DenotationalUpd.ESem (\"\\<lbrakk>_\\<rbrakk>\\<^bsup>u\\<^esup>\\<^bsub>_\\<^esub>\"  [60,60] 60)\nnotation (latex output) \"Denotational-PropsUpd.HSem_syn\" (\"\\<lbrace>_\\<rbrace>\\<^bsup>u\\<^esup>_\"  [60,60] 60)\n\ntranslations\n  \"xs\" <= \"CONST set xs\"\ntranslations\n  \"xs\" <= \"CONST asToHeap xs\"\ntranslations\n  \"a\" <= \"CONST atom a\"\n\nlemma Terms:\n  \"\\<exists> x assn e'. (e = (Lam [x]. e') \\<or> (e = Var x) \\<or> (e = App e' x) \\<or> (e = Let assn e'))\"\n  by (metis Terms.exp_assn.exhaust(1))\nlemma expressions_grammar:\n\"(\\<forall> var. y = Var var \\<longrightarrow> P) \\<longrightarrow>\n(\\<forall> exp var. y = App exp var \\<longrightarrow> P) \\<longrightarrow>\n(\\<forall> assn exp. y = Terms.Let assn exp \\<longrightarrow> P) \\<longrightarrow> (\\<forall> var exp. y = Lam [var]. exp \\<longrightarrow> P) \\<longrightarrow> P\"\n  by (metis exp_assn.exhaust(1)) \n\nabbreviation (Grammar output)\n  \"grammar_imp\"\nwhere\n  \"grammar_imp \\<equiv> op \\<longrightarrow>\"\n\nsyntax (Grammar output)\n  \"_grapats\" :: \"term \\<Rightarrow> term \\<Rightarrow> term\" (\"_ | _\")\n  \"_grafirst\" :: \"term \\<Rightarrow> term \\<Rightarrow> term\" (\"_ ::= _\")\n  \"_grarest\" :: \"term \\<Rightarrow> term \\<Rightarrow> term\"\n  \"_firsteq\" :: \"term \\<Rightarrow> term \\<Rightarrow> term\"\n  \"_resteq\" :: \"term \\<Rightarrow> term \\<Rightarrow> term\"\n\ntranslations\n  \"_grapats (_firsteq all) (_grarest (CONST grammar_imp rest1 rest2))\" <= \"CONST grammar_imp all (CONST grammar_imp rest1 rest2)\"\n  \"_grapats (_resteq all) (_grarest (CONST grammar_imp rest1 rest2))\" <= \"_grarest (CONST grammar_imp all (CONST grammar_imp rest1 rest2))\"\n  \"_resteq all\" <= \"_grarest (CONST grammar_imp all rest)\"\n  \"_resteq all\" <= \"_resteq (CONST grammar_imp all rest)\"\n  \"_firsteq all\" <= \"_firsteq (CONST grammar_imp all rest)\"\n  \"_firsteq imp\" <= \"_firsteq (ALL x. imp)\"\n  \"_resteq imp\" <= \"_resteq (ALL x. imp)\"\n  \"_grafirst x t\" <= \"_firsteq (x = t)\"\n  \"t\" <= \"_resteq (x = t)\"\n\n(*\nthm expressions_grammar[no_vars]\nthm (Grammar) expressions_grammar[no_vars]\nthm (latex) expressions_grammar[no_vars]\nthm (latex Grammar) expressions_grammar[no_vars]\n*)\n\ndeclare [[names_short]]\n\n(*>*)\nsubsection {* Main definitions and theorems *}\n\ntext {*\nFor your convenience, the main definitions and theorems of the present work are assembled in this section. The following \nformulas are mechanically pretty-printed versions of the statements as defined resp.\\ proven in Isabelle.\nFree variables are all-quantified. Some type conversion functions (like @{term_type set}) are omitted.\nThe relations @{text \\<sharp>} and @{text \"\\<sharp>*\"} come from the Nominal package and express freshness of the\nvariables on the left with regard to the expressions on the right.\n\n\\input{map.tex}\n*}\n\nsubsubsection {* Expressions *}\n\ntext {*\nThe type @{typ var} of variables is abstract and provided by the Nominal package. All we know about\nit is that it is countably infinite.\nExpressions of type @{typ exp} are given by the following grammar:\n\\begin{alignatstar}{2}\n@{term e} \\Coloneqq {}& @{term \"Lam [x]. e\"} &\\quad& \\text{lambda abstraction}\\\\\n\\mid {} & @{term \"App e x\"} && \\text{application}\\\\\n\\mid {} & @{term \"Var x\"} && \\text{variable} \\\\\n\\mid {} & @{term \"Let as e\"} && \\text{recursive let}\n\\end{alignatstar}\nIn the introduction we pretty-print expressions to match the notation in \\cite{launchbury} and omit\nthe constructor names @{term Var}, @{term App}, @{text Lam} and @{term Let}. In the actual theories, these are visible.\nThese expressions are, due to the machinery of the Nominal package, actually alpha-equivalency classes, so @{thm alpha_test[no_vars]} holds provably. This differs from Launchbury's original definition, which expects distinctly-named expressions and performs explicit alpha-renaming in the semantics.\n\nThe type @{type heap} is an abbreviation for @{typ \"(var \\<times> exp) list\"}. These are \\emph{not} alpha-equivalency classes, i.e.\\ we manage the bindings in heaps explicitly.\n*}\n\nsubsubsection {* The natural semantics *}\n\ntext_raw {*\n\\newlength{\\rulelen}\n\\setlength{\\rulelen}{\\linewidth}\n\\newlength{\\rulenamelen}\n\\settowidth{\\rulenamelen}{~{\\sc Application}}\n\\addtolength{\\rulelen}{-\\rulenamelen}\n*}\n\ntext {*\nLaunchbury's original semantics, extended with some technical overhead related to name binding,\nis defined as follows:\\\\\n%\\begin{center}\n\\parbox[t]{\\rulelen}{\\centering@{thm[mode=Axiom] Launchbury.reds.Lambda[no_vars]}}~{\\sc Lambda}\\\\[2ex]\n\\parbox[t]{\\rulelen}{\\centering@{thm[mode=Rule] Launchbury.reds.Application[no_vars]}}~{\\sc Application}\\\\[2ex]\n\\parbox[t]{\\rulelen}{\\centering@{thm[mode=Rule] Launchbury.reds.Variable[no_vars]}}~{\\sc Variable}\\\\[2ex]\n\\parbox[t]{\\rulelen}{\\centering@{thm[mode=Rule] Launchbury.reds.Let[no_vars]}}~{\\sc Let}\n%\\end{center}\n*}\n\nsubsubsection {* The stacked semantics *}\n\ntext {*\nThis is our modified semantics that allows the correctness theorem to go through without generalisation:\\\\\n\\parbox[t]{\\rulelen}{\\centering@{thm[mode=Axiom] LaunchburyStacked.reds.Lambda[no_vars]}}~{\\sc Lambda}\\\\[2ex]\n\\parbox[t]{\\rulelen}{\\centering@{thm[mode=Rule] LaunchburyStacked.reds.Application[no_vars]}}~{\\sc Application}\\\\[2ex]\n\\parbox[t]{\\rulelen}{\\centering@{thm[mode=Rule] LaunchburyStacked.reds.Variable[no_vars]}}~{\\sc Variable}\\\\[2ex]\n\\parbox[t]{\\rulelen}{\\centering@{thm[mode=Rule] LaunchburyStacked.reds.Let[no_vars]}}~{\\sc Let}\n*}\nsubsubsection {* The denotational semantics *}\n\ntext {*\nThe value domain of the denotational semantics is the initial solution to\n\\[\nD = [D \\to D]_\\bot\n\\]\nas introduced in \\cite{abramsky}. The type @{typ Value}, together with the bottom value @{term_type \"\\<bottom>::Value\"}, the\ninjection @{term_type \"Fn\"} and the projection @{term \"DUMMY \\<down>Fn DUMMY\"}@{text \"::\"}@{typeof \"Fn_project\"},\nis constructed as a pointed chain-complete partial order from this equation by the HOLCF package.\nThe type of semantic environments, @{typ Env}, is an abbreviation for @{typ \"var f\\<rightharpoonup> Value\"}.\n\nThe semantics of an expression @{term_type \"e :: exp\"} in an environment @{term \"\\<rho>\"}@{text \"::\"}@{typ Env} is \nwritten \\mbox{@{term_type \"Denotational.ESem e \\<rho>\"}} and defined by the following equations:\n\\begin{alignstar}\n@{thm (lhs) Denotational.ESem.simps(1)[no_vars]} & = @{thm (rhs) Denotational.ESem.simps(1)[no_vars]} && \\text{if } @{thm (prem 1) Denotational.ESem.simps(1)[no_vars]} \\\\\n@{thm (lhs) Denotational.ESem.simps(2)[no_vars]} & = @{thm (rhs) Denotational.ESem.simps(2)[no_vars]} \\\\\n@{thm (lhs) Denotational.ESem.simps(3)[no_vars]} & = @{thm (rhs) Denotational.ESem.simps(3)[no_vars]} \\\\\n@{thm (lhs) Denotational.ESem.simps(4)[no_vars]} & = @{thm (rhs) Denotational.ESem.simps(4)[no_vars]} && \\text{if } @{thm (prem 1) Denotational.ESem.simps(4)[no_vars]}.\n\\end{alignstar}\n*}\n\ntext {*\nWe study two alternatives for the semantics @{term \"Denotational.HSem \\<Gamma> \\<rho>\"}@{text \"::\"}@{typ Env} of a\nheap @{term \"\\<Gamma> :: heap\"}@{text \"::\"}@{typ heap}\nin an environment @{term \"\\<rho>\"}@{text \"::\"}@{typ Env}. As this is used in denotations of a Let expression,\nwe have also two expression semantics. Their defining equations are, besides the choice of heap semantics, identical.\n\nThe first involves a least upper bound ($\\sqcup$) and is defined by the recursive equation\n\\[ @{thm (concl) Denotational.HSem_eq[no_vars]}, \\]\nwhere the set in the index position indicates the expansion of the map to the given domain and\n@{term \"heapToEnv:: heap \\<Rightarrow> (exp \\<Rightarrow> Value) \\<Rightarrow> Env\"}@{text \"::\"}@{typ \"heap \\<Rightarrow> (exp \\<Rightarrow> Value) \\<Rightarrow> Env\"}\nmaps the given expression semantics over the heap, producing a semantic environment.\n\nThe other, here shown with a superscript @{text \"u\"}, uses the right-sided update operator @{text \"f++\"}\nand is defined by the recursive equation\n\\[ @{thm \"Denotational-PropsUpd.HSem_eq\"[no_vars]}. \\]\n\nThe semantics of the heap in the empty environment @{term \"fempty\"} is abbreviated as @{abbrev \"HSem_fempty \\<Gamma>\"}.\n\nIt is worth noting that the two semantics agree on expressions, i.e. @{thm HSem_join_update(1)[no_vars] },\nbut obviously not on heaps that bind variables that also occur in the environment.\n*}\n\nsubsubsection {* Equivalences *}\ntext {*\nThe stacked semantics is equivalent to the original semantics in the following sense:\n\\begin{itemize}\n\\item If @{thm[mode=IfThen] (prem 1) forget_stack_nice[no_vars] } is derivable in the stacked semantics,\nand @{term L} is chosen such that @{thm[mode=IfThen] (prem 2) forget_stack_nice[no_vars]} holds, then\n @{thm[mode=IfThen] (concl) forget_stack_nice[no_vars]} is derivable in the original semantics.\n\\item If @{thm[mode=IfThen] (prem 1) add_stack[no_vars]} is derivable in the original semantics and\n@{term \"x\"} and @{term \"\\<Gamma>'\"} are chosen such that @{thm[mode=IfThen] (prem 2) add_stack[no_vars]} and\n@{thm[mode=IfThen] (prem 3) add_stack[no_vars]} holds, then  @{thm[mode=IfThen] (concl) add_stack[no_vars]}\nis derivable in the stacked semantics.\n\\end{itemize}\n*}\n\nsubsubsection {* Correctness *}\ntext {* The statement of correctness for the stacked semantics reads:\nIf @{thm [mode=IfThen] (prem 1) CorrectnessStacked.correctness[no_vars]} and, as a side condition,\n@{thm [mode=IfThen] (prem 2) CorrectnessStacked.correctness[no_vars]} holds, then @{thm [mode=IfThen] (concl) CorrectnessStacked.correctness(1)[no_vars]}. *}\n\ntext {* By the stated equivalency, we obtain the correctness of the original semantics:\nIf \\mbox{@{thm [mode=IfThen] (prem 1) Correctness.correctness(1)[no_vars]}} and, as a side condition,\n@{thm [mode=IfThen] (prem 2) Correctness.correctness(1)[no_vars]} holds, then @{thm [mode=IfThen] (concl) Correctness.correctness(1)[no_vars]} and \n @{thm [mode=IfThen] (concl) Correctness.correctness(2)[no_vars]} *}\n\ntext {* The generalization introduced by Launchbury is true if the update-based semantics is chosen:\nIf @{thm [mode=IfThen] (prem 1) CorrectnessUpd.correctness(1)[no_vars]} and, as a side condition,\n@{thm [mode=IfThen] (prem 2) CorrectnessUpd.correctness(1)[no_vars]} and\n\\mbox{@{thm [mode=IfThen] (prem 3) CorrectnessUpd.correctness(1)[no_vars]}} hold,\nthen @{thm [mode=IfThen] (concl) CorrectnessUpd.correctness(1)[no_vars]} and  @{thm [mode=IfThen] (concl) CorrectnessUpd.correctness(2)[no_vars]}. *}\n\n\n(*<*)\n\nend\n(*>*)\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Launchbury/Everything.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.2608342326594719}}
{"text": "(*  Title:      Native_Cast.thy\n    Author:     Andreas Lochbihler, ETH Zurich\n*)\n\nchapter \\<open>Conversions between unsigned words and between char\\<close>\n\ntheory Native_Cast\n  imports\n  Uint8\n  Uint16\n  Uint32\n  Uint64\nbegin\n\ntext \\<open>Auxiliary stuff\\<close>\n\nlemma integer_of_char_char_of_integer [simp]:\n  \"integer_of_char (char_of_integer x) = x mod 256\"\n  by (simp add: integer_of_char_def char_of_integer_def)\n\nlemma char_of_integer_integer_of_char [simp]:\n  \"char_of_integer (integer_of_char x) = x\"\n  by (simp add: integer_of_char_def char_of_integer_def)\n\nlemma int_lt_numeral [simp]: \"int x < numeral n \\<longleftrightarrow> x < numeral n\"\nby (metis nat_numeral zless_nat_eq_int_zless)\n\nlemma int_of_integer_ge_0: \"0 \\<le> int_of_integer x \\<longleftrightarrow> 0 \\<le> x\"\nincluding integer.lifting by transfer simp\n\nlemma integer_of_char_ge_0 [simp]: \"0 \\<le> integer_of_char x\"\n  including integer.lifting unfolding integer_of_char_def\n  by transfer (simp add: of_char_def)\n\n\nsection \\<open>Conversion between native words\\<close>\n\nlift_definition uint8_of_uint16 :: \"uint16 \\<Rightarrow> uint8\" is ucast .\nlift_definition uint8_of_uint32 :: \"uint32 \\<Rightarrow> uint8\" is ucast .\nlift_definition uint8_of_uint64 :: \"uint64 \\<Rightarrow> uint8\" is ucast .\n\nlift_definition uint16_of_uint8 :: \"uint8 \\<Rightarrow> uint16\" is ucast .\nlift_definition uint16_of_uint32 :: \"uint32 \\<Rightarrow> uint16\" is ucast .\nlift_definition uint16_of_uint64 :: \"uint64 \\<Rightarrow> uint16\" is ucast .\n\nlift_definition uint32_of_uint8 :: \"uint8 \\<Rightarrow> uint32\" is ucast .\nlift_definition uint32_of_uint16 :: \"uint16 \\<Rightarrow> uint32\" is ucast .\nlift_definition uint32_of_uint64 :: \"uint64 \\<Rightarrow> uint32\" is ucast .\n\nlift_definition uint64_of_uint8 :: \"uint8 \\<Rightarrow> uint64\" is ucast .\nlift_definition uint64_of_uint16 :: \"uint16 \\<Rightarrow> uint64\" is ucast .\nlift_definition uint64_of_uint32 :: \"uint32 \\<Rightarrow> uint64\" is ucast .\n\ndefinition mask where \"mask = (0xFFFFFFFF :: integer)\"\n\ncode_printing\n  constant uint8_of_uint16 \\<rightharpoonup>\n  (SML_word) \"Word8.fromLarge (Word16.toLarge _)\" and\n  (Haskell) \"(Prelude.fromIntegral _ :: Uint8.Word8)\" and\n  (Scala) \"_.toByte\"\n| constant uint8_of_uint32 \\<rightharpoonup>\n  (SML) \"Word8.fromLarge (Word32.toLarge _)\" and\n  (Haskell) \"(Prelude.fromIntegral _ :: Uint8.Word8)\" and\n  (Scala) \"_.toByte\"\n| constant uint8_of_uint64 \\<rightharpoonup>\n  (SML) \"Word8.fromLarge (Uint64.toLarge _)\" and\n  (Haskell) \"(Prelude.fromIntegral _ :: Uint8.Word8)\" and\n  (Scala) \"_.toByte\"\n| constant uint16_of_uint8 \\<rightharpoonup>\n  (SML_word) \"Word16.fromLarge (Word8.toLarge _)\" and\n  (Haskell) \"(Prelude.fromIntegral _ :: Uint16.Word16)\" and\n  (Scala) \"((_).toInt & 0xFF).toChar\"\n| constant uint16_of_uint32 \\<rightharpoonup>\n  (SML_word) \"Word16.fromLarge (Word32.toLarge _)\" and\n  (Haskell) \"(Prelude.fromIntegral _ :: Uint16.Word16)\" and\n  (Scala) \"_.toChar\"\n| constant uint16_of_uint64 \\<rightharpoonup>\n  (SML_word) \"Word16.fromLarge (Uint64.toLarge _)\" and\n  (Haskell) \"(Prelude.fromIntegral _ :: Uint16.Word16)\" and\n  (Scala) \"_.toChar\"\n| constant uint32_of_uint8 \\<rightharpoonup>\n  (SML) \"Word32.fromLarge (Word8.toLarge _)\" and\n  (Haskell) \"(Prelude.fromIntegral _ :: Uint32.Word32)\" and\n  (Scala) \"((_).toInt & 0xFF)\"\n| constant uint32_of_uint16 \\<rightharpoonup>\n  (SML_word) \"Word32.fromLarge (Word16.toLarge _)\" and\n  (Haskell) \"(Prelude.fromIntegral _ :: Uint32.Word32)\" and\n  (Scala) \"(_).toInt\"\n| constant uint32_of_uint64 \\<rightharpoonup>\n  (SML_word) \"Word32.fromLarge (Uint64.toLarge _)\" and\n  (Haskell) \"(Prelude.fromIntegral _ :: Uint32.Word32)\" and\n  (Scala) \"(_).toInt\" and\n  (OCaml) \"Int64.to'_int32\"\n| constant uint64_of_uint8 \\<rightharpoonup>\n  (SML_word) \"Word64.fromLarge (Word8.toLarge _)\" and\n  (Haskell) \"(Prelude.fromIntegral _ :: Uint64.Word64)\" and\n  (Scala) \"((_).toLong & 0xFF)\"\n| constant uint64_of_uint16 \\<rightharpoonup>\n  (SML_word) \"Word64.fromLarge (Word16.toLarge _)\" and\n  (Haskell) \"(Prelude.fromIntegral _ :: Uint64.Word64)\" and\n  (Scala) \"_.toLong\"\n| constant uint64_of_uint32 \\<rightharpoonup>\n  (SML_word) \"Word64.fromLarge (Word32.toLarge _)\" and\n  (Haskell) \"(Prelude.fromIntegral _ :: Uint64.Word64)\" and\n  (Scala) \"((_).toLong & 0xFFFFFFFFL)\" and\n  (OCaml) \"Int64.logand (Int64.of'_int32 _) (Int64.of'_string \\\"4294967295\\\")\"\n\ntext \\<open>\n  Use @{const Abs_uint8'} etc. instead of @{const Rep_uint8} in code equations\n  for conversion functions to avoid exceptions during code generation when the\n  target language provides only some of the uint types.\n\\<close>\n\nlemma uint8_of_uint16_code [code]:\n  \"uint8_of_uint16 x = Abs_uint8' (ucast (Rep_uint16' x))\"\nby transfer simp\n\nlemma uint8_of_uint32_code [code]:\n  \"uint8_of_uint32 x = Abs_uint8' (ucast (Rep_uint32' x))\"\nby transfer simp\n\nlemma uint8_of_uint64_code [code]:\n  \"uint8_of_uint64 x = Abs_uint8' (ucast (Rep_uint64' x))\"\nby transfer simp\n\nlemma uint16_of_uint8_code [code]:\n  \"uint16_of_uint8 x = Abs_uint16' (ucast (Rep_uint8' x))\"\nby transfer simp\n\nlemma uint16_of_uint32_code [code]:\n  \"uint16_of_uint32 x = Abs_uint16' (ucast (Rep_uint32' x))\"\nby transfer simp\n\nlemma uint16_of_uint64_code [code]:\n  \"uint16_of_uint64 x = Abs_uint16' (ucast (Rep_uint64' x))\"\nby transfer simp\n\nlemma uint32_of_uint8_code [code]:\n  \"uint32_of_uint8 x = Abs_uint32' (ucast (Rep_uint8' x))\"\nby transfer simp\n\nlemma uint32_of_uint16_code [code]:\n  \"uint32_of_uint16 x = Abs_uint32' (ucast (Rep_uint16' x))\"\nby transfer simp\n\nlemma uint32_of_uint64_code [code]:\n  \"uint32_of_uint64 x = Abs_uint32' (ucast (Rep_uint64' x))\"\nby transfer simp\n\nlemma uint64_of_uint8_code [code]:\n  \"uint64_of_uint8 x = Abs_uint64' (ucast (Rep_uint8' x))\"\nby transfer simp\n\nlemma uint64_of_uint16_code [code]:\n  \"uint64_of_uint16 x = Abs_uint64' (ucast (Rep_uint16' x))\"\nby transfer simp\n\nlemma uint64_of_uint32_code [code]:\n  \"uint64_of_uint32 x = Abs_uint64' (ucast (Rep_uint32' x))\"\nby transfer simp\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Evaluation/Native_Word/Native_Cast.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5851011686727231, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.26067985162986895}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory Memset\nimports \"AutoCorres.AutoCorres\"\nbegin\n\nexternal_file \"memset.c\"\ninstall_C_file \"memset.c\"\n\nautocorres [\n  heap_abs_syntax,\n  no_heap_abs=memset,\n  no_signed_word_abs=memset,\n  unsigned_word_abs=memset] \"memset.c\"\n\nlemma c_guard_word8_ptr [simp]:\n     \"c_guard (x :: word8 ptr) = (x \\<noteq> NULL)\"\n  apply (clarsimp simp: c_guard_def ptr_aligned_def c_null_guard_def)\n  apply (metis Ptr_ptr_val first_in_intvl intvl_Suc not_less_eq ptr_val.ptr_val_def)\n  done\n\nlemma to_bytes_word8 [simp]: \"to_bytes (a :: word8) x = [a]\"\n  by (clarsimp simp: to_bytes_def typ_info_word word_rsplit_same)\n\nlemma heap_update_list_id [simp]:\n    \"heap_update_list x [] = (\\<lambda>x. x)\"\n  apply (rule ext)\n  apply simp\n  done\n\nlemma heap_update_heap_update_list:\n   \"\\<lbrakk> ptr_val p = q + (of_nat (length l)); Suc (length l) < addr_card \\<rbrakk> \\<Longrightarrow>\n      heap_update (p :: word8 ptr) v (heap_update_list q l s) = (heap_update_list q (l @ [v]) s)\"\n  apply (rule ext)\n  apply (clarsimp simp: heap_update_def unat_of_nat\n    addr_card word_bits_def fun_upd_def)\n  apply (subst heap_update_list_value, clarsimp simp: addr_card)\n  apply safe\n   apply (subst if_P)\n    apply (fastforce intro: intvlI)\n   apply (clarsimp simp: unat_of_nat word_bits_def)\n  apply (subst (1 2)  heap_update_list_value,\n    simp add: addr_card,\n    simp add: addr_card)\n  apply (case_tac \"x \\<in> {q..+length l}\")\n   apply (subst if_P, simp)\n   apply (subst if_P)\n    apply clarsimp\n    apply (metis (full_types) intvlD intvlI less_SucI)\n   apply (subst nth_append, clarsimp)\n   apply (metis (hide_lams, no_types) add_diff_cancel2 intvlD le_unat_uoi less_or_eq_imp_le not_le)\n  apply clarsimp\n  apply (metis intvlD intvlI less_antisym)\n  done\n\nlemma (in memset) memset:\n  \"\\<forall>s\\<^sub>0. \\<lbrace> \\<lambda>s. s = s\\<^sub>0 \\<and> n < addr_card \\<and> 0 \\<notin> {ptr_val p ..+ n} \\<rbrace>\n      memset' p c n\n      \\<lbrace> \\<lambda>rv s. s = t_hrs_'_update (hrs_mem_update (\n          heap_update_list (ptr_val p) (replicate n (scast c)))) s\\<^sub>0 \\<rbrace>!\"\nproof -\n  {\n     fix s0\n     have \"\\<lbrace> \\<lambda>s. s = s0 \\<and> n < addr_card \\<and> 0 \\<notin> {ptr_val p ..+ n} \\<rbrace>\n                memset' p c n\n          \\<lbrace> \\<lambda>rv s. s = t_hrs_'_update (hrs_mem_update\n              (heap_update_list (ptr_val p) (replicate n (scast c)))) s0 \\<rbrace>!\"\n      apply (rule validNF_assume_pre)\n      apply (unfold memset'_def)\n      apply (subst whileLoop_add_inv [where M=\"\\<lambda>((d', n'), _). n'\"\n                and I=\"\\<lambda>(d', n') s.\n                   n' \\<le> n \\<and>\n                   (n' \\<le> n \\<longrightarrow> d' = ptr_coerce p +\\<^sub>p int (n - n')) \\<and>\n                   (n' \\<le> n \\<longrightarrow> s = t_hrs_'_update\n                  (hrs_mem_update (heap_update_list (ptr_val p) (replicate (n - n') (scast c)))) s0)\"])\n      apply wp\n        apply (clarsimp simp:)\n        apply (intro conjI impI)\n           apply arith\n          apply (clarsimp simp: ptr_add_def)\n         apply (rule globals.fold_congs, simp, simp)\n         apply (clarsimp simp: hrs_mem_update_def)\n         apply (subst heap_update_heap_update_list)\n           apply (clarsimp simp: ptr_add_def)\n          apply (clarsimp)\n          apply arith\n         apply (metis diff_Suc_diff_eq2 diff_diff_left minus_nat.diff_0 replicate_Suc_append)\n        apply (clarsimp simp: ptr_add_def)\n        apply (metis (hide_lams, no_types) add_less_cancel_right add.left_neutral intvl_inter_le le0 le_add_diff_inverse of_nat_diff semiring_1_class.of_nat_0)\n       apply clarsimp\n      apply (clarsimp simp: hrs_mem_update_def)\n      done\n  }\n\n  thus ?thesis\n    by simp\nqed\n\nlemma word_rsplit_sword_0 [simplified, simp]:\n  \"word_rsplit (0 :: addr_bitsize signed word) = replicate (size_of TYPE(addr)) (0 :: word8)\"\n  apply (simp add: word_rsplit_def bin_rsplit_def Let_def)\n  done\n\nlemma word_rsplit_word_0 [simplified, simp]:\n  \"word_rsplit (0 :: addr_bitsize word) = replicate (size_of TYPE(addr)) (0 :: word8)\"\n  apply (simp add: word_rsplit_def bin_rsplit_def Let_def)\n  done\n\nlemma heap_update_zero_node [simplified]:\n  \"heap_update_list p (replicate (size_of TYPE(node_C)) 0) = heap_update (Ptr p) (node_C NULL 0)\"\n  apply (rule ext)\n  apply (clarsimp simp: heap_update_def to_bytes_def)\n  apply (subst packed_type_access_ti, simp)\n  apply (clarsimp simp: access_ti\\<^sub>0_def)\n  apply (clarsimp simp: to_bytes_def to_bytes_p_def node_C_tag_def node_C_typ_tag)\n  apply (subst final_pad_def)\n  apply (clarsimp simp: typ_info_word size_td_lt_ti_typ_pad_combine Let_def padup_def)\n  apply (clarsimp simp: ti_typ_pad_combine_def)\n  apply (clarsimp simp: ti_typ_combine_def empty_typ_info_def typ_info_ptr typ_info_word)\n  done\n\nlemma (in memset) is_valid_node_C_non_NULL [simp]:\n  \"is_valid_node_C (lift_global_heap s) p \\<Longrightarrow> 0 \\<notin> {ptr_val p ..+ size_of TYPE(node_C)}\"\n  by (auto simp: lift_global_heap_def c_guard_def c_null_guard_def dest: simple_lift_c_guard)\n\nlemma (in memset) zero_node:\n  \"\\<forall>s\\<^sub>0. \\<lbrace> \\<lambda>s. is_valid_node_C s p \\<and> s = s\\<^sub>0\\<rbrace> zero_node' p \\<lbrace> \\<lambda>rv s. s = s\\<^sub>0[p := (node_C NULL 0) ] \\<rbrace>! \"\n  including nf_no_pre\n  apply (clarsimp simp: zero_node'_def)\n  apply (wp add: memset [THEN validNF_make_schematic_post, simplified])\n  apply (fastforce dest: simple_lift_c_guard is_valid_node_C_non_NULL\n                   simp: addr_card lift_global_heap_def heap_update_zero_node\n                         memset.update_node_def typ_simple_heap_simps fun_upd_def)\n  done\n\nend\n", "meta": {"author": "amblafont", "repo": "AutoCorres", "sha": "a8e96bff9fb22d633ff473401947ca84235d3b73", "save_path": "github-repos/isabelle/amblafont-AutoCorres", "path": "github-repos/isabelle/amblafont-AutoCorres/AutoCorres-a8e96bff9fb22d633ff473401947ca84235d3b73/autocorres/tests/examples/Memset.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.585101139733739, "lm_q2_score": 0.44552953503957266, "lm_q1q2_score": 0.26067983873669676}}
{"text": "(*  Title:      JinjaThreads/Execute/Round_Robin.thy\n    Author:     Andreas Lochbihler\n*)\n\nsection \\<open>Round robin scheduler\\<close>\n\ntheory Round_Robin\nimports\n  Scheduler\nbegin\n\ntext \\<open>\n  A concrete scheduler must pick one possible reduction step from the small-step semantics for invidivual threads.\n  Currently, this is only possible if there is only one such by using @{term Predicate.the}.\n\\<close>\n\nsubsection \\<open>Concrete schedulers\\<close>\n\nsubsection \\<open>Round-robin schedulers\\<close>\n\ntype_synonym 'queue round_robin = \"'queue \\<times> nat\"\n  \\<comment> \\<open>Waiting queue of threads and remaining number of steps of the first thread until it has to return resources\\<close>\n\nprimrec enqueue_new_thread :: \"'t list \\<Rightarrow> ('t,'x,'m) new_thread_action \\<Rightarrow> 't list\"\nwhere \n  \"enqueue_new_thread queue (NewThread t x m) = queue @ [t]\"\n| \"enqueue_new_thread queue (ThreadExists t b) = queue\"\n\ndefinition enqueue_new_threads :: \"'t list \\<Rightarrow> ('t,'x,'m) new_thread_action list \\<Rightarrow> 't list\"\nwhere\n  \"enqueue_new_threads = foldl enqueue_new_thread\"\n\nprimrec round_robin_update_state :: \"nat \\<Rightarrow> 't list round_robin \\<Rightarrow> 't \\<Rightarrow> ('l,'t,'x,'m,'w,'o) thread_action \\<Rightarrow> 't list round_robin\"\nwhere \n  \"round_robin_update_state n0 (queue, n) t ta =\n   (let queue' = enqueue_new_threads queue \\<lbrace>ta\\<rbrace>\\<^bsub>t\\<^esub>\n    in if n = 0 \\<or> Yield \\<in> set \\<lbrace>ta\\<rbrace>\\<^bsub>c\\<^esub> then (rotate1 queue', n0) else (queue', n - 1))\"\n\ncontext multithreaded_base begin\n\nabbreviation round_robin_step :: \"nat \\<Rightarrow> 't list round_robin \\<Rightarrow> ('l,'t,'x,'m,'w) state \\<Rightarrow> 't \\<Rightarrow> ('t \\<times> (('l,'t,'x,'m,'w,'o) thread_action \\<times> 'x \\<times> 'm) option \\<times> 't list round_robin) option\"\nwhere\n  \"round_robin_step n0 \\<sigma> s t \\<equiv> step_thread (round_robin_update_state n0 \\<sigma> t) s t\"\n\npartial_function (option) round_robin_reschedule :: \"'t \\<Rightarrow> \n    't list \\<Rightarrow> nat \\<Rightarrow> ('l,'t,'x,'m,'w) state \\<Rightarrow> ('t \\<times> (('l,'t,'x,'m,'w,'o) thread_action \\<times> 'x \\<times> 'm) option \\<times> 't list round_robin) option\"\nwhere\n  \"round_robin_reschedule t0 queue n0 s =\n   (let\n      t = hd queue;\n      queue' = tl queue\n    in\n      if t = t0 then\n        None\n      else\n        case round_robin_step n0 (t # queue', n0) s t of\n          None \\<Rightarrow> round_robin_reschedule t0 (queue' @ [t]) n0 s\n        | \\<lfloor>ttaxm\\<sigma>\\<rfloor> \\<Rightarrow> \\<lfloor>ttaxm\\<sigma>\\<rfloor>)\"\n\nfun round_robin :: \"nat \\<Rightarrow> 't list round_robin \\<Rightarrow> ('l,'t,'x,'m,'w) state \\<Rightarrow> ('t \\<times> (('l,'t,'x,'m,'w,'o) thread_action \\<times> 'x \\<times> 'm) option \\<times> 't list round_robin) option\"\nwhere \n  \"round_robin n0 ([], n) s = None\"\n| \"round_robin n0 (t # queue, n) s =\n   (case round_robin_step n0 (t # queue, n) s t of\n      \\<lfloor>ttaxm\\<sigma>\\<rfloor> \\<Rightarrow> \\<lfloor>ttaxm\\<sigma>\\<rfloor>\n    | None \\<Rightarrow> round_robin_reschedule t (queue @ [t]) n0 s)\"\n\nend\n\nprimrec round_robin_invar :: \"'t list round_robin \\<Rightarrow> 't set \\<Rightarrow> bool\"\nwhere \"round_robin_invar (queue, n) T \\<longleftrightarrow> set queue = T \\<and> distinct queue\"\n\nlemma set_enqueue_new_thread: \n  \"set (enqueue_new_thread queue nta) = set queue \\<union> {t. \\<exists>x m. nta = NewThread t x m}\"\nby(cases nta) auto\n\nlemma set_enqueue_new_threads: \n  \"set (enqueue_new_threads queue ntas) = set queue \\<union> {t. \\<exists>x m. NewThread t x m \\<in> set ntas}\"\napply(induct ntas arbitrary: queue)\napply(auto simp add: enqueue_new_threads_def set_enqueue_new_thread)\ndone\n\nlemma enqueue_new_thread_eq_Nil [simp]:\n  \"enqueue_new_thread queue nta = [] \\<longleftrightarrow> queue = [] \\<and> (\\<exists>t b. nta = ThreadExists t b)\"\nby(cases nta) simp_all\n\nlemma enqueue_new_threads_eq_Nil [simp]:\n  \"enqueue_new_threads queue ntas = [] \\<longleftrightarrow> queue = [] \\<and> set ntas \\<subseteq> {ThreadExists t b|t b. True}\"\napply(induct ntas arbitrary: queue)\napply(auto simp add: enqueue_new_threads_def)\ndone\n\nlemma distinct_enqueue_new_threads:\n  fixes ts :: \"('l,'t,'x) thread_info\"\n  and ntas :: \"('t,'x,'m) new_thread_action list\"\n  assumes \"thread_oks ts ntas\" \"set queue = dom ts\" \"distinct queue\"\n  shows \"distinct (enqueue_new_threads queue ntas)\"\nusing assms\nproof(induct ntas arbitrary: ts queue)\n  case Nil thus ?case by(simp add: enqueue_new_threads_def)\nnext\n  case (Cons nt ntas)\n  from \\<open>thread_oks ts (nt # ntas)\\<close>\n  have \"thread_ok ts nt\" and \"thread_oks (redT_updT ts nt) ntas\" by simp_all\n  from \\<open>thread_ok ts nt\\<close> \\<open>set queue = dom ts\\<close> \\<open>distinct queue\\<close>\n  have \"set (enqueue_new_thread queue nt) = dom (redT_updT ts nt) \\<and> distinct (enqueue_new_thread queue nt)\"\n    by(cases nt)(auto)\n  with \\<open>thread_oks (redT_updT ts nt) ntas\\<close>\n  have \"distinct (enqueue_new_threads (enqueue_new_thread queue nt) ntas)\"\n    by(blast intro: Cons.hyps)\n  thus ?case by(simp add: enqueue_new_threads_def)\nqed\n\nlemma round_robin_reschedule_induct [consumes 1, case_names head rotate]:\n  assumes major: \"t0 \\<in> set queue\"\n  and head: \"\\<And>queue. P (t0 # queue)\"\n  and rotate: \"\\<And>queue t. \\<lbrakk> t \\<noteq> t0; t0 \\<in> set queue; P (queue @ [t]) \\<rbrakk> \\<Longrightarrow> P (t # queue)\"\n  shows \"P queue\"\nusing major\nproof(induct n\\<equiv>\"length (takeWhile (\\<lambda>x. x\\<noteq>t0) queue)\" arbitrary: queue)\n  case 0\n  then obtain queue' where \"queue = t0 # queue'\"\n    by(cases queue)(auto split: if_split_asm)\n  thus ?case by(simp add: head)\nnext\n  case (Suc n)\n  then obtain t queue' where [simp]: \"queue = t # queue'\"\n    and t: \"t \\<noteq> t0\" and n: \"n = length (takeWhile (\\<lambda>x. x \\<noteq> t0) queue')\"\n    and t0: \"t0 \\<in> set queue'\"\n    by(cases queue)(auto split: if_split_asm)\n  from n t0 have \"n = length (takeWhile (\\<lambda>x. x \\<noteq> t0) (queue' @ [t]))\" by(simp)\n  moreover from t0 have \"t0 \\<in> set (queue' @ [t])\" by simp\n  ultimately have \"P (queue' @ [t])\" by(rule Suc.hyps)\n  with t t0 show ?case by(simp add: rotate)\nqed\n\ncontext multithreaded_base begin\n\ndeclare actions_ok_iff [simp del]\ndeclare actions_ok.cases [rule del]\n\nlemma round_robin_step_invar_None:\n  \"\\<lbrakk> round_robin_step n0 \\<sigma> s t' = \\<lfloor>(t, None, \\<sigma>')\\<rfloor>; round_robin_invar \\<sigma> (dom (thr s)) \\<rbrakk>\n  \\<Longrightarrow> round_robin_invar \\<sigma>' (dom (thr s))\"\nby(cases \\<sigma>)(auto dest: step_thread_Some_NoneD simp add: set_enqueue_new_threads distinct_enqueue_new_threads)\n\nlemma round_robin_step_invar_Some:\n  \"\\<lbrakk> deterministic I; round_robin_step n0 \\<sigma> s t' = \\<lfloor>(t, \\<lfloor>(ta, x', m')\\<rfloor>, \\<sigma>')\\<rfloor>; round_robin_invar \\<sigma> (dom (thr s)); s \\<in> I \\<rbrakk>\n  \\<Longrightarrow> round_robin_invar \\<sigma>' (dom (thr s) \\<union> {t. \\<exists>x m. NewThread t x m \\<in> set \\<lbrace>ta\\<rbrace>\\<^bsub>t\\<^esub>})\"\napply(cases \\<sigma>)\napply clarsimp\napply(frule (1) step_thread_Some_SomeD)\napply(auto split: if_split_asm simp add: split_beta set_enqueue_new_threads deterministic_THE)\napply(auto simp add: actions_ok_iff distinct_enqueue_new_threads)\ndone\n\nlemma round_robin_reschedule_Cons:\n  \"round_robin_reschedule t0 (t0 # queue) n0 s = None\"\n  \"t \\<noteq> t0 \\<Longrightarrow> round_robin_reschedule t0 (t # queue) n0 s =\n   (case round_robin_step n0 (t # queue, n0) s t of\n      None \\<Rightarrow> round_robin_reschedule t0 (queue @ [t]) n0 s\n    | Some ttaxm\\<sigma> \\<Rightarrow> Some ttaxm\\<sigma>)\"\nby(simp_all add: round_robin_reschedule.simps)\n\nlemma round_robin_reschedule_NoneD:\n  assumes rrr: \"round_robin_reschedule t0 queue n0 s = None\"\n  and t0: \"t0 \\<in> set queue\"\n  shows \"set (takeWhile (\\<lambda>t'. t' \\<noteq> t0) queue) \\<inter> active_threads s = {}\"\nusing t0 rrr\nproof(induct queue rule: round_robin_reschedule_induct)\n  case (head queue)\n  thus ?case by simp\nnext\n  case (rotate queue t)\n  from \\<open>round_robin_reschedule t0 (t # queue) n0 s = None\\<close> \\<open>t \\<noteq> t0\\<close>\n  have \"round_robin_step n0 (t # queue, n0) s t = None\" \n    and \"round_robin_reschedule t0 (queue @ [t]) n0 s = None\"\n    by(simp_all add: round_robin_reschedule_Cons)\n  from this(1) have \"t \\<notin> active_threads s\" by(rule step_thread_NoneD)\n  moreover from \\<open>round_robin_reschedule t0 (queue @ [t]) n0 s = None\\<close> \n  have \"set (takeWhile (\\<lambda>t'. t' \\<noteq> t0) (queue @ [t])) \\<inter> active_threads s = {}\"\n    by(rule rotate.hyps)\n  moreover have \"takeWhile (\\<lambda>t'. t' \\<noteq> t0) (queue @ [t]) = takeWhile (\\<lambda>t'. t' \\<noteq> t0) queue\"\n    using \\<open>t0 \\<in> set queue\\<close> by simp\n  ultimately show ?case using \\<open>t \\<noteq> t0\\<close> by simp\nqed\n\nlemma round_robin_reschedule_Some_NoneD:\n  assumes rrr: \"round_robin_reschedule t0 queue n0 s = \\<lfloor>(t, None, \\<sigma>')\\<rfloor>\"\n  and t0: \"t0 \\<in> set queue\"\n  shows \"\\<exists>x ln n. thr s t = \\<lfloor>(x, ln)\\<rfloor> \\<and> ln $ n > 0 \\<and> \\<not> waiting (wset s t) \\<and> may_acquire_all (locks s) t ln\"\nusing t0 rrr\nproof(induct queue rule: round_robin_reschedule_induct)\n  case head thus ?case by(simp add: round_robin_reschedule_Cons)\nnext\n  case (rotate queue t')\n  show ?case\n  proof(cases \"round_robin_step n0 (t' # queue, n0) s t'\")\n    case None\n    with \\<open>round_robin_reschedule t0 (t' # queue) n0 s = \\<lfloor>(t, None, \\<sigma>')\\<rfloor>\\<close> \\<open>t' \\<noteq> t0\\<close>\n    have \"round_robin_reschedule t0 (queue @ [t']) n0 s = \\<lfloor>(t, None, \\<sigma>')\\<rfloor>\"\n      by(simp add: round_robin_reschedule_Cons)\n    thus ?thesis by(rule rotate.hyps)\n  next\n    case (Some a)\n    with \\<open>round_robin_reschedule t0 (t' # queue) n0 s = \\<lfloor>(t, None, \\<sigma>')\\<rfloor>\\<close> \\<open>t' \\<noteq> t0\\<close>\n    have \"round_robin_step n0 (t' # queue, n0) s t' = \\<lfloor>(t, None, \\<sigma>')\\<rfloor>\"\n      by(simp add: round_robin_reschedule_Cons)\n    thus ?thesis by(blast dest: step_thread_Some_NoneD)\n  qed\nqed\n\nlemma round_robin_reschedule_Some_SomeD:\n  assumes \"deterministic I\"\n  and rrr: \"round_robin_reschedule t0 queue n0 s = \\<lfloor>(t, \\<lfloor>(ta, x', m')\\<rfloor>, \\<sigma>')\\<rfloor>\"\n  and t0: \"t0 \\<in> set queue\"\n  and I: \"s \\<in> I\"\n  shows \"\\<exists>x. thr s t = \\<lfloor>(x, no_wait_locks)\\<rfloor> \\<and> t \\<turnstile> \\<langle>x, shr s\\<rangle> -ta\\<rightarrow> \\<langle>x', m'\\<rangle> \\<and> actions_ok s t ta\"\nusing t0 rrr\nproof(induct queue rule: round_robin_reschedule_induct)\n  case head thus ?case by(simp add: round_robin_reschedule_Cons)\nnext\n  case (rotate queue t')\n  show ?case\n  proof(cases \"round_robin_step n0 (t' # queue, n0) s t'\")\n    case None\n    with \\<open>round_robin_reschedule t0 (t' # queue) n0 s = \\<lfloor>(t, \\<lfloor>(ta, x', m')\\<rfloor>, \\<sigma>')\\<rfloor>\\<close> \\<open>t' \\<noteq> t0\\<close>\n    have \"round_robin_reschedule t0 (queue @ [t']) n0 s = \\<lfloor>(t, \\<lfloor>(ta, x', m')\\<rfloor>, \\<sigma>')\\<rfloor>\"\n      by(simp add: round_robin_reschedule_Cons)\n    thus ?thesis by(rule rotate.hyps)\n  next\n    case (Some a)\n    with \\<open>round_robin_reschedule t0 (t' # queue) n0 s = \\<lfloor>(t, \\<lfloor>(ta, x', m')\\<rfloor>, \\<sigma>')\\<rfloor>\\<close> \\<open>t' \\<noteq> t0\\<close>\n    have \"round_robin_step n0 (t' # queue, n0) s t' = \\<lfloor>(t, \\<lfloor>(ta, x', m')\\<rfloor>, \\<sigma>')\\<rfloor>\"\n      by(simp add: round_robin_reschedule_Cons)\n    thus ?thesis using I by(blast dest: step_thread_Some_SomeD[OF \\<open>deterministic I\\<close>])\n  qed\nqed\n\nlemma round_robin_reschedule_invar_None:\n  assumes rrr: \"round_robin_reschedule t0 queue n0 s = \\<lfloor>(t, None, \\<sigma>')\\<rfloor>\"\n  and invar: \"round_robin_invar (queue, n0) (dom (thr s))\"\n  and t0: \"t0 \\<in> set queue\"\n  shows \"round_robin_invar \\<sigma>' (dom (thr s))\"\nusing t0 rrr invar\nproof(induct queue rule: round_robin_reschedule_induct)\n  case head thus ?case by(simp add: round_robin_reschedule_Cons)\nnext\n  case (rotate queue t')\n  show ?case\n  proof(cases \"round_robin_step n0 (t' # queue, n0) s t'\")\n    case None\n    with \\<open>round_robin_reschedule t0 (t' # queue) n0 s = \\<lfloor>(t, None, \\<sigma>')\\<rfloor>\\<close> \\<open>t' \\<noteq> t0\\<close>\n    have \"round_robin_reschedule t0 (queue @ [t']) n0 s = \\<lfloor>(t, None, \\<sigma>')\\<rfloor>\"\n      by(simp add: round_robin_reschedule_Cons)\n    moreover from \\<open>round_robin_invar (t' # queue, n0) (dom (thr s))\\<close>\n    have \"round_robin_invar (queue @ [t'], n0) (dom (thr s))\" by simp\n    ultimately show ?thesis by(rule rotate.hyps)\n  next\n    case (Some a)\n    with \\<open>round_robin_reschedule t0 (t' # queue) n0 s = \\<lfloor>(t, None, \\<sigma>')\\<rfloor>\\<close> \\<open>t' \\<noteq> t0\\<close>\n    have \"round_robin_step n0 (t' # queue, n0) s t' = \\<lfloor>(t, None, \\<sigma>')\\<rfloor>\"\n      by(simp add: round_robin_reschedule_Cons)\n    thus ?thesis using \\<open>round_robin_invar (t' # queue, n0) (dom (thr s))\\<close>\n      by(rule round_robin_step_invar_None)\n  qed\nqed\n\nlemma round_robin_reschedule_invar_Some:\n  assumes \"deterministic I\"\n  and rrr: \"round_robin_reschedule t0 queue n0 s = \\<lfloor>(t, \\<lfloor>(ta, x', m')\\<rfloor>, \\<sigma>')\\<rfloor>\"\n  and invar: \"round_robin_invar (queue, n0) (dom (thr s))\"\n  and t0: \"t0 \\<in> set queue\"\n  and \"s \\<in> I\"\n  shows \"round_robin_invar \\<sigma>' (dom (thr s) \\<union> {t. \\<exists>x m. NewThread t x m \\<in> set \\<lbrace>ta\\<rbrace>\\<^bsub>t\\<^esub>})\"\nusing t0 rrr invar\nproof(induct queue rule: round_robin_reschedule_induct)\n  case head thus ?case by(simp add: round_robin_reschedule_Cons)\nnext\n  case (rotate queue t')\n  show ?case\n  proof(cases \"round_robin_step n0 (t' # queue, n0) s t'\")\n    case None\n    with \\<open>round_robin_reschedule t0 (t' # queue) n0 s = \\<lfloor>(t, \\<lfloor>(ta, x', m')\\<rfloor>, \\<sigma>')\\<rfloor>\\<close> \\<open>t' \\<noteq> t0\\<close>\n    have \"round_robin_reschedule t0 (queue @ [t']) n0 s = \\<lfloor>(t, \\<lfloor>(ta, x', m')\\<rfloor>, \\<sigma>')\\<rfloor>\"\n      by(simp add: round_robin_reschedule_Cons)\n    moreover from \\<open>round_robin_invar (t' # queue, n0) (dom (thr s))\\<close>\n    have \"round_robin_invar (queue @ [t'], n0) (dom (thr s))\" by simp\n    ultimately show ?thesis by(rule rotate.hyps)\n  next\n    case (Some a)\n    with \\<open>round_robin_reschedule t0 (t' # queue) n0 s = \\<lfloor>(t, \\<lfloor>(ta, x', m')\\<rfloor>, \\<sigma>')\\<rfloor>\\<close> \\<open>t' \\<noteq> t0\\<close>\n    have \"round_robin_step n0 (t' # queue, n0) s t' = \\<lfloor>(t, \\<lfloor>(ta, x', m')\\<rfloor>, \\<sigma>')\\<rfloor>\"\n      by(simp add: round_robin_reschedule_Cons)\n    thus ?thesis using \\<open>round_robin_invar (t' # queue, n0) (dom (thr s))\\<close> \\<open>s \\<in> I\\<close>\n      by(rule round_robin_step_invar_Some[OF \\<open>deterministic I\\<close>])\n  qed\nqed\n\nlemma round_robin_NoneD: \n  assumes rr: \"round_robin n0 \\<sigma> s = None\"\n  and invar: \"round_robin_invar \\<sigma> (dom (thr s))\"\n  shows \"active_threads s = {}\"\nproof -\n  obtain queue n where \\<sigma>: \"\\<sigma> = (queue, n)\" by(cases \\<sigma>)\n  show ?thesis\n  proof(cases queue)\n    case Nil\n    thus ?thesis using invar \\<sigma> by(fastforce elim: active_threads.cases)\n  next\n    case (Cons t queue')\n    with rr \\<sigma> have \"round_robin_step n0 (t # queue', n) s t = None\"\n      and \"round_robin_reschedule t (queue' @ [t]) n0 s = None\" by simp_all\n    from \\<open>round_robin_step n0 (t # queue', n) s t = None\\<close>\n    have \"t \\<notin> active_threads s\" by(rule step_thread_NoneD)\n    moreover from \\<open>round_robin_reschedule t (queue' @ [t]) n0 s = None\\<close>\n    have \"set (takeWhile (\\<lambda>x. x \\<noteq> t) (queue' @ [t])) \\<inter> active_threads s = {}\"\n      by(rule round_robin_reschedule_NoneD) simp\n    moreover from invar \\<sigma> Cons\n    have \"takeWhile (\\<lambda>x. x \\<noteq> t) (queue' @ [t]) = queue'\"\n      by(subst takeWhile_append2) auto\n    moreover from invar have \"active_threads s \\<subseteq> set queue\"\n      using \\<sigma> by(auto elim: active_threads.cases)\n    ultimately show ?thesis using Cons by auto\n  qed\nqed\n\nlemma round_robin_Some_NoneD:\n  assumes rr: \"round_robin n0 \\<sigma> s = \\<lfloor>(t, None, \\<sigma>')\\<rfloor>\"\n  shows \"\\<exists>x ln n. thr s t = \\<lfloor>(x, ln)\\<rfloor> \\<and> ln $ n > 0 \\<and> \\<not> waiting (wset s t) \\<and> may_acquire_all (locks s) t ln\"\nproof -\n  obtain queue n where \\<sigma>: \"\\<sigma> = (queue, n)\" by(cases \\<sigma>)\n  with rr have \"queue \\<noteq> []\" by clarsimp\n  then obtain t' queue' where queue: \"queue = t' # queue'\"\n    by(auto simp add: neq_Nil_conv)\n  show ?thesis\n  proof(cases \"round_robin_step n0 (t' # queue', n) s t'\")\n    case (Some a)\n    with rr queue \\<sigma> have \"round_robin_step n0 (t' # queue', n) s t' = \\<lfloor>(t, None, \\<sigma>')\\<rfloor>\" by simp\n    thus ?thesis by(blast dest: step_thread_Some_NoneD)\n  next\n    case None\n    with rr queue \\<sigma> have \"round_robin_reschedule t' (queue' @ [t']) n0 s = \\<lfloor>(t, None, \\<sigma>')\\<rfloor>\" by simp\n    thus ?thesis by(rule round_robin_reschedule_Some_NoneD)simp\n  qed\nqed\n\nlemma round_robin_Some_SomeD:\n  assumes \"deterministic I\"\n  and rr: \"round_robin n0 \\<sigma> s = \\<lfloor>(t, \\<lfloor>(ta, x', m')\\<rfloor>, \\<sigma>')\\<rfloor>\"\n  and \"s \\<in> I\"\n  shows \"\\<exists>x. thr s t = \\<lfloor>(x, no_wait_locks)\\<rfloor> \\<and> t \\<turnstile> \\<langle>x, shr s\\<rangle> -ta\\<rightarrow> \\<langle>x', m'\\<rangle> \\<and> actions_ok s t ta\"\nproof -\n  obtain queue n where \\<sigma>: \"\\<sigma> = (queue, n)\" by(cases \\<sigma>)\n  with rr have \"queue \\<noteq> []\" by clarsimp\n  then obtain t' queue' where queue: \"queue = t' # queue'\"\n    by(auto simp add: neq_Nil_conv)\n  show ?thesis\n  proof(cases \"round_robin_step n0 (t' # queue', n) s t'\")\n    case (Some a)\n    with rr queue \\<sigma> have \"round_robin_step n0 (t' # queue', n) s t' = \\<lfloor>(t, \\<lfloor>(ta, x', m')\\<rfloor>, \\<sigma>')\\<rfloor>\" by simp\n    thus ?thesis using \\<open>s \\<in> I\\<close> by(blast dest: step_thread_Some_SomeD[OF \\<open>deterministic I\\<close>])\n  next\n    case None\n    with rr queue \\<sigma> have \"round_robin_reschedule t' (queue' @ [t']) n0 s = \\<lfloor>(t, \\<lfloor>(ta, x', m')\\<rfloor>, \\<sigma>')\\<rfloor>\" by simp\n    thus ?thesis by(rule round_robin_reschedule_Some_SomeD[OF \\<open>deterministic I\\<close>])(simp_all add: \\<open>s \\<in> I\\<close>)\n  qed\nqed\n\nlemma round_robin_invar_None:\n  assumes rr: \"round_robin n0 \\<sigma> s = \\<lfloor>(t, None, \\<sigma>')\\<rfloor>\"\n  and invar: \"round_robin_invar \\<sigma> (dom (thr s))\"\n  shows \"round_robin_invar \\<sigma>' (dom (thr s))\"\nproof -\n  obtain queue n where \\<sigma>: \"\\<sigma> = (queue, n)\" by(cases \\<sigma>)\n  with rr have \"queue \\<noteq> []\" by clarsimp\n  then obtain t' queue' where queue: \"queue = t' # queue'\"\n    by(auto simp add: neq_Nil_conv)\n  show ?thesis\n  proof(cases \"round_robin_step n0 (t' # queue', n) s t'\")\n    case (Some a)\n    with rr queue \\<sigma> have \"round_robin_step n0 (t' # queue', n) s t' = \\<lfloor>(t, None, \\<sigma>')\\<rfloor>\" by simp\n    thus ?thesis using invar unfolding \\<sigma> queue by(rule round_robin_step_invar_None)\n  next\n    case None\n    with rr queue \\<sigma> have \"round_robin_reschedule t' (queue' @ [t']) n0 s = \\<lfloor>(t, None, \\<sigma>')\\<rfloor>\" by simp\n    moreover from invar queue \\<sigma> have \"round_robin_invar (queue' @ [t'], n0) (dom (thr s))\" by simp\n    ultimately show ?thesis by(rule round_robin_reschedule_invar_None) simp\n  qed\nqed\n\nlemma round_robin_invar_Some:\n  assumes \"deterministic I\"\n  and rr: \"round_robin n0 \\<sigma> s = \\<lfloor>(t, \\<lfloor>(ta, x', m')\\<rfloor>, \\<sigma>')\\<rfloor>\"\n  and invar: \"round_robin_invar \\<sigma> (dom (thr s))\" \"s \\<in> I\"\n  shows \"round_robin_invar \\<sigma>' (dom (thr s) \\<union> {t. \\<exists>x m. NewThread t x m \\<in> set \\<lbrace>ta\\<rbrace>\\<^bsub>t\\<^esub>})\"\nproof -\n  obtain queue n where \\<sigma>: \"\\<sigma> = (queue, n)\" by(cases \\<sigma>)\n  with rr have \"queue \\<noteq> []\" by clarsimp\n  then obtain t' queue' where queue: \"queue = t' # queue'\"\n    by(auto simp add: neq_Nil_conv)\n  show ?thesis\n  proof(cases \"round_robin_step n0 (t' # queue', n) s t'\")\n    case (Some a)\n    with rr queue \\<sigma> have \"round_robin_step n0 (t' # queue', n) s t' = \\<lfloor>(t, \\<lfloor>(ta, x', m')\\<rfloor>, \\<sigma>')\\<rfloor>\" by simp\n    thus ?thesis using invar unfolding \\<sigma> queue by(rule round_robin_step_invar_Some[OF \\<open>deterministic I\\<close>])\n  next\n    case None\n    with rr queue \\<sigma> have \"round_robin_reschedule t' (queue' @ [t']) n0 s = \\<lfloor>(t, \\<lfloor>(ta, x', m')\\<rfloor>, \\<sigma>')\\<rfloor>\" by simp\n    moreover from invar queue \\<sigma>\n    have \"round_robin_invar (queue' @ [t'], n0) (dom (thr s))\" by simp\n    ultimately show ?thesis by(rule round_robin_reschedule_invar_Some[OF \\<open>deterministic I\\<close>])(simp_all add: \\<open>s \\<in> I\\<close>)\n  qed\nqed\n\nend\n\nlocale round_robin_base =\n  scheduler_base_aux\n    final r convert_RA\n    thr_\\<alpha> thr_invar thr_lookup thr_update\n    ws_\\<alpha> ws_invar ws_lookup\n    is_\\<alpha> is_invar is_memb is_ins is_delete\n  for final :: \"'x \\<Rightarrow> bool\"\n  and r :: \"'t \\<Rightarrow> ('x \\<times> 'm) \\<Rightarrow> (('l,'t,'x,'m,'w,'o) thread_action \\<times> 'x \\<times> 'm) Predicate.pred\"\n  and convert_RA :: \"'l released_locks \\<Rightarrow> 'o list\"\n  and \"output\" :: \"'queue round_robin \\<Rightarrow> 't \\<Rightarrow> ('l,'t,'x,'m,'w,'o) thread_action \\<Rightarrow> 'q option\"\n  and thr_\\<alpha> :: \"'m_t \\<Rightarrow> ('l,'t,'x) thread_info\"\n  and thr_invar :: \"'m_t \\<Rightarrow> bool\"\n  and thr_lookup :: \"'t \\<Rightarrow> 'm_t \\<rightharpoonup> ('x \\<times> 'l released_locks)\"\n  and thr_update :: \"'t \\<Rightarrow> 'x \\<times> 'l released_locks \\<Rightarrow> 'm_t \\<Rightarrow> 'm_t\"\n  and ws_\\<alpha> :: \"'m_w \\<Rightarrow> ('w,'t) wait_sets\"\n  and ws_invar :: \"'m_w \\<Rightarrow> bool\"\n  and ws_lookup :: \"'t \\<Rightarrow> 'm_w \\<rightharpoonup> 'w wait_set_status\"\n  and ws_update :: \"'t \\<Rightarrow> 'w wait_set_status \\<Rightarrow> 'm_w \\<Rightarrow> 'm_w\"\n  and ws_delete :: \"'t \\<Rightarrow> 'm_w \\<Rightarrow> 'm_w\"\n  and ws_iterate :: \"'m_w \\<Rightarrow> ('t \\<times> 'w wait_set_status, 'm_w) set_iterator\"\n  and ws_sel :: \"'m_w \\<Rightarrow> ('t \\<times> 'w wait_set_status \\<Rightarrow> bool) \\<rightharpoonup> ('t \\<times> 'w wait_set_status)\"\n  and is_\\<alpha> :: \"'s_i \\<Rightarrow> 't interrupts\"\n  and is_invar :: \"'s_i \\<Rightarrow> bool\"\n  and is_memb :: \"'t \\<Rightarrow> 's_i \\<Rightarrow> bool\"\n  and is_ins :: \"'t \\<Rightarrow> 's_i \\<Rightarrow> 's_i\"\n  and is_delete :: \"'t \\<Rightarrow> 's_i \\<Rightarrow> 's_i\"\n  +\n  fixes queue_\\<alpha> :: \"'queue \\<Rightarrow> 't list\"\n  and queue_invar :: \"'queue \\<Rightarrow> bool\"\n  and queue_empty :: \"unit \\<Rightarrow> 'queue\"\n  and queue_isEmpty :: \"'queue \\<Rightarrow> bool\"\n  and queue_enqueue :: \"'t \\<Rightarrow> 'queue \\<Rightarrow> 'queue\"\n  and queue_dequeue :: \"'queue \\<Rightarrow> 't \\<times> 'queue\"\n  and queue_push :: \"'t \\<Rightarrow> 'queue \\<Rightarrow> 'queue\"\nbegin\n\ndefinition queue_rotate1 :: \"'queue \\<Rightarrow> 'queue\"\nwhere \"queue_rotate1 = case_prod queue_enqueue \\<circ> queue_dequeue\"\n\nprimrec enqueue_new_thread :: \"'queue \\<Rightarrow> ('t,'x,'m) new_thread_action \\<Rightarrow> 'queue\"\nwhere \n  \"enqueue_new_thread ts (NewThread t x m) = queue_enqueue t ts\"\n| \"enqueue_new_thread ts (ThreadExists t b) = ts\"\n\ndefinition enqueue_new_threads :: \"'queue \\<Rightarrow> ('t,'x,'m) new_thread_action list \\<Rightarrow> 'queue\"\nwhere\n  \"enqueue_new_threads = foldl enqueue_new_thread\"\n\nprimrec round_robin_update_state :: \"nat \\<Rightarrow> 'queue round_robin \\<Rightarrow> 't \\<Rightarrow> ('l,'t,'x,'m,'w,'o) thread_action \\<Rightarrow> 'queue round_robin\"\nwhere \n  \"round_robin_update_state n0 (queue, n) t ta =\n   (let queue' = enqueue_new_threads queue \\<lbrace>ta\\<rbrace>\\<^bsub>t\\<^esub>\n    in if n = 0 \\<or> Yield \\<in> set \\<lbrace>ta\\<rbrace>\\<^bsub>c\\<^esub> then (queue_rotate1 queue', n0) else (queue', n - 1))\"\n\nabbreviation round_robin_step ::\n  \"nat \\<Rightarrow> 'queue round_robin \\<Rightarrow> ('l,'t,'m,'m_t,'m_w,'s_i) state_refine \\<Rightarrow> 't \n  \\<Rightarrow> ('t \\<times> (('l,'t,'x,'m,'w,'o) thread_action \\<times> 'x \\<times> 'm) option \\<times> 'queue round_robin) option\"\nwhere\n  \"round_robin_step n0 \\<sigma> s t \\<equiv> step_thread (round_robin_update_state n0 \\<sigma> t) s t\"\n\npartial_function (option) round_robin_reschedule ::\n  \"'t \\<Rightarrow> 'queue \\<Rightarrow> nat \\<Rightarrow> ('l,'t,'m,'m_t,'m_w,'s_i) state_refine \n  \\<Rightarrow> ('t \\<times> (('l,'t,'x,'m,'w,'o) thread_action \\<times> 'x \\<times> 'm) option \\<times> 'queue round_robin) option\"\nwhere\n  \"round_robin_reschedule t0 queue n0 s =\n   (let\n      (t, queue') = queue_dequeue queue\n    in\n      if t = t0 then\n        None \n      else\n        case round_robin_step n0 (queue_push t queue', n0) s t of\n          None \\<Rightarrow> round_robin_reschedule t0 (queue_enqueue t queue') n0 s\n        | \\<lfloor>ttaxm\\<sigma>\\<rfloor> \\<Rightarrow> \\<lfloor>ttaxm\\<sigma>\\<rfloor>)\"\n\nprimrec round_robin :: \"nat \\<Rightarrow> ('l,'t,'x,'m,'w,'o,'m_t,'m_w,'s_i,'queue round_robin) scheduler\"\nwhere \n  \"round_robin n0 (queue, n) s = \n   (if queue_isEmpty queue then None\n    else\n      let\n        (t, queue') = queue_dequeue queue\n      in\n        (case round_robin_step n0 (queue_push t queue', n) s t of\n           \\<lfloor>ttaxm\\<sigma>\\<rfloor> \\<Rightarrow> \\<lfloor>ttaxm\\<sigma>\\<rfloor>\n         | None \\<Rightarrow> round_robin_reschedule t (queue_enqueue t queue') n0 s))\"\n\nprimrec round_robin_invar :: \"'queue round_robin \\<Rightarrow> 't set \\<Rightarrow> bool\"\nwhere \"round_robin_invar (queue, n) T \\<longleftrightarrow> queue_invar queue \\<and> Round_Robin.round_robin_invar (queue_\\<alpha> queue, n) T\"\n\ndefinition round_robin_\\<alpha> :: \"'queue round_robin \\<Rightarrow> 't list round_robin\"\nwhere \"round_robin_\\<alpha> = apfst queue_\\<alpha>\"\n\ndefinition round_robin_start :: \"nat \\<Rightarrow> 't \\<Rightarrow> 'queue round_robin\"\nwhere \"round_robin_start n0 t = (queue_enqueue t (queue_empty ()), n0)\"\n\nlemma round_robin_invar_correct:\n  \"round_robin_invar \\<sigma> T \\<Longrightarrow> Round_Robin.round_robin_invar (round_robin_\\<alpha> \\<sigma>) T\"\nby(cases \\<sigma>)(simp add: round_robin_\\<alpha>_def)\n\nend\n\nlocale round_robin =\n  round_robin_base\n    final r convert_RA \"output\"\n    thr_\\<alpha> thr_invar thr_lookup thr_update\n    ws_\\<alpha> ws_invar ws_lookup ws_update ws_delete ws_iterate ws_sel\n    is_\\<alpha> is_invar is_memb is_ins is_delete\n    queue_\\<alpha> queue_invar queue_empty queue_isEmpty queue_enqueue queue_dequeue queue_push\n  +\n  scheduler_aux\n    final r convert_RA\n    thr_\\<alpha> thr_invar thr_lookup thr_update\n    ws_\\<alpha> ws_invar ws_lookup\n    is_\\<alpha> is_invar is_memb is_ins is_delete\n  +\n  ws: map_update ws_\\<alpha> ws_invar ws_update +\n  ws: map_delete ws_\\<alpha> ws_invar ws_delete +\n  ws: map_iteratei ws_\\<alpha> ws_invar ws_iterate +\n  ws: map_sel' ws_\\<alpha> ws_invar ws_sel +\n  queue: list queue_\\<alpha> queue_invar +\n  queue: list_empty queue_\\<alpha> queue_invar queue_empty +\n  queue: list_isEmpty queue_\\<alpha> queue_invar queue_isEmpty +\n  queue: list_enqueue queue_\\<alpha> queue_invar queue_enqueue +\n  queue: list_dequeue queue_\\<alpha> queue_invar queue_dequeue +\n  queue: list_push queue_\\<alpha> queue_invar queue_push\n  for final :: \"'x \\<Rightarrow> bool\"\n  and r :: \"'t \\<Rightarrow> ('x \\<times> 'm) \\<Rightarrow> (('l,'t,'x,'m,'w,'o) thread_action \\<times> 'x \\<times> 'm) Predicate.pred\"\n  and convert_RA :: \"'l released_locks \\<Rightarrow> 'o list\"\n  and \"output\" :: \"'queue round_robin \\<Rightarrow> 't \\<Rightarrow> ('l,'t,'x,'m,'w,'o) thread_action \\<Rightarrow> 'q option\"\n  and thr_\\<alpha> :: \"'m_t \\<Rightarrow> ('l,'t,'x) thread_info\"\n  and thr_invar :: \"'m_t \\<Rightarrow> bool\"\n  and thr_lookup :: \"'t \\<Rightarrow> 'm_t \\<rightharpoonup> ('x \\<times> 'l released_locks)\"\n  and thr_update :: \"'t \\<Rightarrow> 'x \\<times> 'l released_locks \\<Rightarrow> 'm_t \\<Rightarrow> 'm_t\"\n  and ws_\\<alpha> :: \"'m_w \\<Rightarrow> ('w,'t) wait_sets\"\n  and ws_invar :: \"'m_w \\<Rightarrow> bool\"\n  and ws_lookup :: \"'t \\<Rightarrow> 'm_w \\<rightharpoonup> 'w wait_set_status\"\n  and ws_update :: \"'t \\<Rightarrow> 'w wait_set_status \\<Rightarrow> 'm_w \\<Rightarrow> 'm_w\"\n  and ws_delete :: \"'t \\<Rightarrow> 'm_w \\<Rightarrow> 'm_w\"\n  and ws_iterate :: \"'m_w \\<Rightarrow> ('t \\<times> 'w wait_set_status, 'm_w) set_iterator\"\n  and ws_sel :: \"'m_w \\<Rightarrow> ('t \\<times> 'w wait_set_status \\<Rightarrow> bool) \\<rightharpoonup> ('t \\<times> 'w wait_set_status)\"\n  and is_\\<alpha> :: \"'s_i \\<Rightarrow> 't interrupts\"\n  and is_invar :: \"'s_i \\<Rightarrow> bool\"\n  and is_memb :: \"'t \\<Rightarrow> 's_i \\<Rightarrow> bool\"\n  and is_ins :: \"'t \\<Rightarrow> 's_i \\<Rightarrow> 's_i\"\n  and is_delete :: \"'t \\<Rightarrow> 's_i \\<Rightarrow> 's_i\"\n  and queue_\\<alpha> :: \"'queue \\<Rightarrow> 't list\"\n  and queue_invar :: \"'queue \\<Rightarrow> bool\"\n  and queue_empty :: \"unit \\<Rightarrow> 'queue\"\n  and queue_isEmpty :: \"'queue \\<Rightarrow> bool\"\n  and queue_enqueue :: \"'t \\<Rightarrow> 'queue \\<Rightarrow> 'queue\"\n  and queue_dequeue :: \"'queue \\<Rightarrow> 't \\<times> 'queue\"\n  and queue_push :: \"'t \\<Rightarrow> 'queue \\<Rightarrow> 'queue\"\nbegin\n\nlemma queue_rotate1_correct:\n  assumes \"queue_invar queue\" \"queue_\\<alpha> queue \\<noteq> []\"\n  shows \"queue_\\<alpha> (queue_rotate1 queue) = rotate1 (queue_\\<alpha> queue)\"\n  and \"queue_invar (queue_rotate1 queue)\"\nusing assms\napply(auto simp add: queue_rotate1_def split_beta queue.dequeue_correct queue.enqueue_correct)\nby(cases \"queue_\\<alpha> queue\") simp_all\n\nlemma enqueue_thread_correct:\n  assumes \"queue_invar queue\"\n  shows \"queue_\\<alpha> (enqueue_new_thread queue nta) = Round_Robin.enqueue_new_thread (queue_\\<alpha> queue) nta\"\n  and \"queue_invar (enqueue_new_thread queue nta)\"\nusing assms\nby(case_tac [!] nta)(simp_all add: queue.enqueue_correct)\n\nlemma enqueue_threads_correct:\n  assumes \"queue_invar queue\"\n  shows \"queue_\\<alpha> (enqueue_new_threads queue ntas) = Round_Robin.enqueue_new_threads (queue_\\<alpha> queue) ntas\"\n  and \"queue_invar (enqueue_new_threads queue ntas)\"\nusing assms\napply(induct ntas arbitrary: queue)\napply(simp_all add: enqueue_new_threads_def Round_Robin.enqueue_new_threads_def enqueue_thread_correct)\ndone\n\nlemma round_robin_update_thread_correct:\n  assumes \"round_robin_invar \\<sigma> T\" \"t' \\<in> T\"\n  shows \"round_robin_\\<alpha> (round_robin_update_state n0 \\<sigma> t ta) = Round_Robin.round_robin_update_state n0 (round_robin_\\<alpha> \\<sigma>) t ta\"\nusing assms\napply(cases \\<sigma>)\napply(auto simp add: round_robin_\\<alpha>_def queue_rotate1_correct enqueue_threads_correct del: conjI)\napply(subst (1 2) queue_rotate1_correct)\napply(auto simp add: enqueue_threads_correct)\ndone\n\nlemma round_robin_step_correct:\n  assumes det: \"\\<alpha>.deterministic I\"\n  and invar: \"round_robin_invar \\<sigma> (dom (thr_\\<alpha> (thr s)))\" \"state_invar s\" \"state_\\<alpha> s \\<in> I\"\n  shows\n  \"map_option (apsnd (apsnd round_robin_\\<alpha>)) (round_robin_step n0 \\<sigma> s t) = \n   \\<alpha>.round_robin_step n0 (round_robin_\\<alpha> \\<sigma>) (state_\\<alpha> s) t\" (is ?thesis1)\n  and \"case_option True (\\<lambda>(t, taxm, \\<sigma>). round_robin_invar \\<sigma> (case taxm of None \\<Rightarrow> dom (thr_\\<alpha> (thr s)) | Some (ta, x', m') \\<Rightarrow> dom (thr_\\<alpha> (thr s)) \\<union> {t. \\<exists>x m. NewThread t x m \\<in> set \\<lbrace>ta\\<rbrace>\\<^bsub>t\\<^esub>})) (round_robin_step n0 \\<sigma> s t)\"\n  (is ?thesis2)\nproof -\n  have \"?thesis1 \\<and> ?thesis2\"\n  proof(cases \"dom (thr_\\<alpha> (thr s)) = {}\")\n    case True\n    thus ?thesis using invar\n      apply(cases \\<sigma>)\n      apply(auto dest: step_thread_Some_NoneD[OF det] step_thread_Some_SomeD[OF det])\n      apply(fastforce simp add: \\<alpha>.step_thread_eq_None_conv elim: \\<alpha>.active_threads.cases intro: sym)\n      done\n  next\n    case False\n    then obtain t' where t': \"t' \\<in> dom (thr_\\<alpha> (thr s))\" by blast\n    hence ?thesis1\n      using step_thread_correct(1)[of I round_robin_invar \\<sigma> s round_robin_\\<alpha> \"round_robin_update_state n0 \\<sigma> t\" t, OF det invar]\n      unfolding o_def using invar\n      by(subst (asm) round_robin_update_thread_correct) auto\n    moreover\n    { fix ta :: \"('l, 't, 'x, 'm, 'w, 'o) thread_action\"\n      assume \"FWThread.thread_oks (thr_\\<alpha> (thr s)) \\<lbrace>ta\\<rbrace>\\<^bsub>t\\<^esub>\"\n      moreover from t' invar have \"queue_\\<alpha> (fst \\<sigma>) \\<noteq> []\" by(cases \\<sigma>) auto\n      ultimately have \"round_robin_invar (round_robin_update_state n0 \\<sigma> t ta) (dom (thr_\\<alpha> (thr s)) \\<union> {t. \\<exists>x m. NewThread t x m \\<in> set \\<lbrace>ta\\<rbrace>\\<^bsub>t\\<^esub>})\"\n        using invar t' by(cases \\<sigma>)(auto simp add: queue_rotate1_correct enqueue_threads_correct set_enqueue_new_threads iff del: domIff intro: distinct_enqueue_new_threads) }\n    from step_thread_correct(2)[OF det, of round_robin_invar \\<sigma> s \"round_robin_update_state n0 \\<sigma> t\" t, OF invar this]\n    have ?thesis2 using t' invar by simp\n    ultimately show ?thesis by blast\n  qed\n  thus ?thesis1 ?thesis2 by blast+\nqed\n\nlemma round_robin_reschedule_correct:\n  assumes det: \"\\<alpha>.deterministic I\"\n  and invar: \"round_robin_invar (queue, n) (dom (thr_\\<alpha> (thr s)))\" \"state_invar s\" \"state_\\<alpha> s \\<in> I\"\n  and t0: \"t0 \\<in> set (queue_\\<alpha> queue)\"\n  shows \"map_option (apsnd (apsnd round_robin_\\<alpha>)) (round_robin_reschedule t0 queue n0 s) =\n     \\<alpha>.round_robin_reschedule t0 (queue_\\<alpha> queue) n0 (state_\\<alpha> s)\"\n  and \"case_option True (\\<lambda>(t, taxm, \\<sigma>). round_robin_invar \\<sigma> (case taxm of None \\<Rightarrow> dom (thr_\\<alpha> (thr s)) | Some (ta, x', m') \\<Rightarrow> dom (thr_\\<alpha> (thr s)) \\<union> {t. \\<exists>x m. NewThread t x m \\<in> set \\<lbrace>ta\\<rbrace>\\<^bsub>t\\<^esub>})) (round_robin_reschedule t0 queue n0 s)\"\nusing t0 invar\nproof(induct \"queue_\\<alpha> queue\" arbitrary: queue n rule: round_robin_reschedule_induct)\n  case head\n  { case 1 thus ?case using head[symmetric]\n      by(subst round_robin_reschedule.simps)(subst \\<alpha>.round_robin_reschedule.simps, clarsimp simp add: split_beta queue.dequeue_correct) \n  next\n    case 2 thus ?case using head[symmetric]\n      by(subst round_robin_reschedule.simps)(clarsimp simp add: split_beta queue.dequeue_correct) }\nnext\n  case (rotate \\<alpha>queue' t)\n  obtain t' queue' where queue': \"queue_dequeue queue = (t', queue')\" by(cases \"queue_dequeue queue\")\n  note [simp] = \\<open>t # \\<alpha>queue' = queue_\\<alpha> queue\\<close>[symmetric]\n  { case 1\n    with queue' have [simp]: \"t' = t\" \"\\<alpha>queue' = queue_\\<alpha> queue'\" \"queue_invar queue'\" by(auto elim: queue.removelE)\n    from 1 queue' have invar': \"round_robin_invar (queue_push t queue', n0) (dom (thr_\\<alpha> (thr s)))\"\n      by(auto simp add: queue.push_correct)\n    show ?case\n    proof(cases \"round_robin_step n0 (queue_push t queue', n0) s t\")\n      case Some thus ?thesis\n        using queue' \\<open>t \\<noteq> t0\\<close> round_robin_step_correct[OF det invar' \\<open>state_invar s\\<close>, of n0 t] invar' \\<open>state_\\<alpha> s \\<in> I\\<close>\n        by(subst round_robin_reschedule.simps)(subst \\<alpha>.round_robin_reschedule.simps, auto simp add: round_robin_\\<alpha>_def queue.push_correct)\n    next\n      case None\n      hence \\<alpha>None: \"\\<alpha>.round_robin_step n0 (queue_\\<alpha> (queue_push t queue'), n0) (state_\\<alpha> s) t = None\"\n        using round_robin_step_correct[OF det invar' \\<open>state_invar s\\<close>, of n0 t] invar' \\<open>state_\\<alpha> s \\<in> I\\<close>\n        by(auto simp add: queue.push_correct round_robin_\\<alpha>_def)\n      have \"\\<alpha>queue' @ [t] = queue_\\<alpha> (queue_enqueue t queue')\" by(simp add: queue.enqueue_correct)\n      moreover from invar'\n      have \"round_robin_invar (queue_enqueue t queue', n0) (dom (thr_\\<alpha> (thr s)))\"\n        by(auto simp add: queue.enqueue_correct queue.push_correct)\n      ultimately \n      have \"map_option (apsnd (apsnd round_robin_\\<alpha>)) (round_robin_reschedule t0 (queue_enqueue t queue') n0 s) =\n            \\<alpha>.round_robin_reschedule t0 (queue_\\<alpha> (queue_enqueue t queue')) n0 (state_\\<alpha> s)\"\n        using \\<open>state_invar s\\<close> \\<open>state_\\<alpha> s \\<in> I\\<close> by(rule rotate.hyps)\n      thus ?thesis using None \\<alpha>None \\<open>t \\<noteq> t0\\<close> invar' queue'\n        by(subst round_robin_reschedule.simps)(subst \\<alpha>.round_robin_reschedule.simps, auto simp add: queue.enqueue_correct queue.push_correct)\n    qed\n  next\n    case 2\n    with queue' have [simp]: \"t' = t\" \"\\<alpha>queue' = queue_\\<alpha> queue'\" \"queue_invar queue'\" by(auto elim: queue.removelE)\n    from 2 queue' have invar': \"round_robin_invar (queue_push t queue', n0) (dom (thr_\\<alpha> (thr s)))\"\n      by(auto simp add: queue.push_correct)\n    show ?case\n    proof(cases \"round_robin_step n0 (queue_push t queue', n0) s t\")\n      case Some thus ?thesis\n        using queue' \\<open>t \\<noteq> t0\\<close> round_robin_step_correct[OF det invar' \\<open>state_invar s\\<close>, of n0 t] invar' \\<open>state_\\<alpha> s \\<in> I\\<close>\n        by(subst round_robin_reschedule.simps)(auto simp add: round_robin_\\<alpha>_def queue.push_correct)\n    next\n      case None\n      have \"\\<alpha>queue' @ [t] = queue_\\<alpha> (queue_enqueue t queue')\" by(simp add: queue.enqueue_correct)\n      moreover from invar'\n      have \"round_robin_invar (queue_enqueue t queue', n0) (dom (thr_\\<alpha> (thr s)))\"\n        by(auto simp add: queue.enqueue_correct queue.push_correct)\n      ultimately \n      have \"case_option True (\\<lambda>(t, taxm, \\<sigma>). round_robin_invar \\<sigma> (case_option (dom (thr_\\<alpha> (thr s))) (\\<lambda>(ta, x', m'). dom (thr_\\<alpha> (thr s)) \\<union> {t. \\<exists>x m. NewThread t x m \\<in> set \\<lbrace>ta\\<rbrace>\\<^bsub>t\\<^esub>}) taxm)) (round_robin_reschedule t0 (queue_enqueue t queue') n0 s)\"\n        using \\<open>state_invar s\\<close> \\<open>state_\\<alpha> s \\<in> I\\<close> by(rule rotate.hyps)\n      thus ?thesis using None \\<open>t \\<noteq> t0\\<close> invar' queue'\n        by(subst round_robin_reschedule.simps)(auto simp add: queue.enqueue_correct queue.push_correct)\n    qed\n  }\nqed\n\nlemma round_robin_correct:\n  assumes det: \"\\<alpha>.deterministic I\"\n  and invar: \"round_robin_invar \\<sigma> (dom (thr_\\<alpha> (thr s)))\" \"state_invar s\" \"state_\\<alpha> s \\<in> I\"\n  shows \"map_option (apsnd (apsnd round_robin_\\<alpha>)) (round_robin n0 \\<sigma> s) =\n         \\<alpha>.round_robin n0 (round_robin_\\<alpha> \\<sigma>) (state_\\<alpha> s)\"\n    (is ?thesis1)\n  and \"case_option True (\\<lambda>(t, taxm, \\<sigma>). round_robin_invar \\<sigma> (case taxm of None \\<Rightarrow> dom (thr_\\<alpha> (thr s)) | Some (ta, x', m') \\<Rightarrow> dom (thr_\\<alpha> (thr s)) \\<union> {t. \\<exists>x m. NewThread t x m \\<in> set \\<lbrace>ta\\<rbrace>\\<^bsub>t\\<^esub>})) (round_robin n0 \\<sigma> s)\"\n    (is ?thesis2)\nproof -\n  obtain queue n where \\<sigma>: \"\\<sigma> = (queue, n)\" by(cases \\<sigma>)\n  have \"?thesis1 \\<and> ?thesis2\"\n  proof(cases \"queue_\\<alpha> queue\")\n    case Nil thus ?thesis using invar \\<sigma>\n      by(auto simp add: split_beta queue.isEmpty_correct round_robin_\\<alpha>_def)\n  next\n    case (Cons t \\<alpha>queue')\n    with invar \\<sigma> obtain queue'\n      where [simp]: \"queue_dequeue queue = (t, queue')\" \"\\<alpha>queue' = queue_\\<alpha> queue'\" \"queue_invar queue'\"\n      by(auto elim: queue.removelE)\n    from invar \\<sigma> Cons have invar': \"round_robin_invar (queue_push t queue', n) (dom (thr_\\<alpha> (thr s)))\"\n      by(auto simp add: queue.push_correct)\n    from invar \\<sigma> Cons have invar'': \"round_robin_invar (queue_enqueue t queue', n0) (dom (thr_\\<alpha> (thr s)))\"\n      by(auto simp add: queue.enqueue_correct)\n    show ?thesis\n    proof(cases \"round_robin_step n0 (queue_push t queue', n) s t\")\n      case Some\n      with \\<sigma> Cons invar show ?thesis\n        using round_robin_step_correct[OF det invar' \\<open>state_invar s\\<close>, of n0 t]\n        by(auto simp add: queue.isEmpty_correct queue.push_correct round_robin_\\<alpha>_def)\n    next\n      case None\n      from invar \\<sigma> Cons have \"t \\<in> set (queue_\\<alpha> (queue_enqueue t queue'))\"\n        by(auto simp add: queue.enqueue_correct)      \n      from round_robin_reschedule_correct[OF det invar'' \\<open>state_invar s\\<close>, OF \\<open>state_\\<alpha> s \\<in> I\\<close> this, of n0] None \\<sigma> Cons invar\n        round_robin_step_correct[OF det invar' \\<open>state_invar s\\<close>, of n0 t]\n      show ?thesis by(auto simp add: queue.isEmpty_correct queue.push_correct round_robin_\\<alpha>_def queue.enqueue_correct)\n    qed\n  qed\n  thus ?thesis1 ?thesis2 by simp_all\nqed\n\nlemma round_robin_scheduler_spec:\n  assumes det: \"\\<alpha>.deterministic I\"\n  shows \"scheduler_spec final r (round_robin n0) round_robin_invar thr_\\<alpha> thr_invar ws_\\<alpha> ws_invar is_\\<alpha> is_invar I\"\nproof\n  fix \\<sigma> s\n  assume rr: \"round_robin n0 \\<sigma> s = None\"\n    and invar: \"round_robin_invar \\<sigma> (dom (thr_\\<alpha> (thr s)))\" \"state_invar s\" \"state_\\<alpha> s \\<in> I\"\n  from round_robin_correct[OF det, OF invar, of n0] rr\n  have \"\\<alpha>.round_robin n0 (round_robin_\\<alpha> \\<sigma>) (state_\\<alpha> s) = None\" by simp\n  moreover from invar have \"Round_Robin.round_robin_invar (round_robin_\\<alpha> \\<sigma>) (dom (thr (state_\\<alpha> s)))\"\n    by(simp add: round_robin_invar_correct)\n  ultimately show \"\\<alpha>.active_threads (state_\\<alpha> s) = {}\" by(rule \\<alpha>.round_robin_NoneD)\nnext\n  fix \\<sigma> s t \\<sigma>'\n  assume rr: \"round_robin n0 \\<sigma> s = \\<lfloor>(t, None, \\<sigma>')\\<rfloor>\"\n    and invar: \"round_robin_invar \\<sigma> (dom (thr_\\<alpha> (thr s)))\" \"state_invar s\" \"state_\\<alpha> s \\<in> I\"\n  from round_robin_correct[OF det, OF invar, of n0] rr\n  have rr': \"\\<alpha>.round_robin n0 (round_robin_\\<alpha> \\<sigma>) (state_\\<alpha> s) = \\<lfloor>(t, None, round_robin_\\<alpha> \\<sigma>')\\<rfloor>\" by simp\n  then show \"\\<exists>x ln n. thr_\\<alpha> (thr s) t = \\<lfloor>(x, ln)\\<rfloor> \\<and> 0 < ln $ n \\<and> \\<not> waiting (ws_\\<alpha> (wset s) t) \\<and> may_acquire_all (locks s) t ln\"\n    by(rule \\<alpha>.round_robin_Some_NoneD[where s=\"state_\\<alpha> s\", unfolded state_\\<alpha>_conv])\nnext\n  fix \\<sigma> s t ta x' m' \\<sigma>'\n  assume rr: \"round_robin n0 \\<sigma> s = \\<lfloor>(t, \\<lfloor>(ta, x', m')\\<rfloor>, \\<sigma>')\\<rfloor>\"\n    and invar: \"round_robin_invar \\<sigma> (dom (thr_\\<alpha> (thr s)))\" \"state_invar s\" \"state_\\<alpha> s \\<in> I\"\n  from round_robin_correct[OF det, OF invar, of n0] rr\n  have rr': \"\\<alpha>.round_robin n0 (round_robin_\\<alpha> \\<sigma>) (state_\\<alpha> s) = \\<lfloor>(t, \\<lfloor>(ta, x', m')\\<rfloor>, round_robin_\\<alpha> \\<sigma>')\\<rfloor>\" by simp\n  thus \"\\<exists>x. thr_\\<alpha> (thr s) t = \\<lfloor>(x, no_wait_locks)\\<rfloor> \\<and> Predicate.eval (r t (x, shr s)) (ta, x', m') \\<and> \\<alpha>.actions_ok (state_\\<alpha> s) t ta\"\n    using \\<open>state_\\<alpha> s \\<in> I\\<close> by(rule \\<alpha>.round_robin_Some_SomeD[OF det, where s=\"state_\\<alpha> s\", unfolded state_\\<alpha>_conv])\nnext\n  fix \\<sigma> s t \\<sigma>'\n  assume rr: \"round_robin n0 \\<sigma> s = \\<lfloor>(t, None, \\<sigma>')\\<rfloor>\"\n    and invar: \"round_robin_invar \\<sigma> (dom (thr_\\<alpha> (thr s)))\" \"state_invar s\" \"state_\\<alpha> s \\<in> I\"\n  from round_robin_correct[OF det, OF invar, of n0] rr\n  show \"round_robin_invar \\<sigma>' (dom (thr_\\<alpha> (thr s)))\" by simp\nnext\n  fix \\<sigma> s t ta x' m' \\<sigma>'\n  assume rr: \"round_robin n0 \\<sigma> s = \\<lfloor>(t, \\<lfloor>(ta, x', m')\\<rfloor>, \\<sigma>')\\<rfloor>\"\n    and invar: \"round_robin_invar \\<sigma> (dom (thr_\\<alpha> (thr s)))\" \"state_invar s\" \"state_\\<alpha> s \\<in> I\"\n  from round_robin_correct[OF det, OF invar, of n0] rr\n  show \"round_robin_invar \\<sigma>' (dom (thr_\\<alpha> (thr s)) \\<union> {t. \\<exists>x m. NewThread t x m \\<in> set \\<lbrace>ta\\<rbrace>\\<^bsub>t\\<^esub>})\" by simp\nqed\n\nlemma round_robin_start_invar:\n  \"round_robin_invar (round_robin_start n0 t0) {t0}\"\nby(simp add: round_robin_start_def queue.empty_correct queue.enqueue_correct)\n\nend\n\nsublocale round_robin_base <\n  scheduler_base\n    final r convert_RA\n    \"round_robin n0\" \"output\" \"pick_wakeup_via_sel (\\<lambda>s P. ws_sel s (\\<lambda>(k,v). P k v))\" round_robin_invar\n    thr_\\<alpha> thr_invar thr_lookup thr_update\n    ws_\\<alpha> ws_invar ws_lookup ws_update ws_delete ws_iterate\n    is_\\<alpha> is_invar is_memb is_ins is_delete\n  for n0 .\n\nsublocale round_robin <\n  pick_wakeup_spec\n    final r convert_RA\n    \"pick_wakeup_via_sel (\\<lambda>s P. ws_sel s (\\<lambda>(k,v). P k v))\" round_robin_invar\n    thr_\\<alpha> thr_invar\n    ws_\\<alpha> ws_invar\n    is_\\<alpha> is_invar\nby(rule pick_wakeup_spec_via_sel)(unfold_locales)\n\ncontext round_robin begin\n\nlemma round_robin_scheduler:\n  assumes det: \"\\<alpha>.deterministic I\"\n  shows \n  \"scheduler\n     final r convert_RA\n     (round_robin n0) (pick_wakeup_via_sel (\\<lambda>s P. ws_sel s (\\<lambda>(k,v). P k v))) round_robin_invar \n     thr_\\<alpha> thr_invar thr_lookup thr_update \n     ws_\\<alpha> ws_invar ws_lookup ws_update ws_delete ws_iterate\n     is_\\<alpha> is_invar is_memb is_ins is_delete\n     I\"\nproof -\n  interpret scheduler_spec\n      final r convert_RA\n      \"round_robin n0\" round_robin_invar\n      thr_\\<alpha> thr_invar\n      ws_\\<alpha> ws_invar\n      is_\\<alpha> is_invar\n      I\n    using det by(rule round_robin_scheduler_spec)\n\n  show ?thesis by(unfold_locales)(rule \\<alpha>.deterministic_invariant3p[OF det])\nqed\n\nend\n\nlemmas [code] =\n  round_robin_base.queue_rotate1_def\n  round_robin_base.enqueue_new_thread.simps\n  round_robin_base.enqueue_new_threads_def\n  round_robin_base.round_robin_update_state.simps\n  round_robin_base.round_robin_reschedule.simps\n  round_robin_base.round_robin.simps\n  round_robin_base.round_robin_start_def\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/JinjaThreads/Execute/Round_Robin.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6224593312018546, "lm_q2_score": 0.4186969093556867, "lm_q1q2_score": 0.2606217981738243}}
{"text": "(*<*)\n(*:maxLineLen=78:*)\ntheory RecursiveVDM\nimports VDMToolkit\nbegin\n(*>*)\n\n(*****************************************************************************)\nsection \\<open>Introduction\\label{sec:Intro}\\<close>\ntext \\<open>This paper describes a translation strategy for a variety of recursive\ndefinitions from VDM to Isabelle/HOL. The strategy takes into account the\ndifferences in how termination and well-foundedness are represented in both\nformalisms.\n\nBeyond overcoming technical practicalities, which we discuss, a major\nobjective is to create translation strategy templates. These templates must\ncover a wide variety of VDM recursive definitions, as well as having their\nproof obligations being highly automated. The result is an extension to the\nVDM to Isabelle/HOL translation strategy and implementation as a plugin to\nVDMJ~@{cite Battle09} and extension to VDM-VSCode @{cite AdvancedVSCodePaper}.\n\nIsabelle uses literate programming, where formal specification, proofs and\ndocumentation are all within the same environment. We omit proof scripts\nbelow; the full VDM and Isabelle sources and proofs can be found at the VDM\ntoolkit repository at\n\\<^verbatim>\\<open>./plugins/vdm2isa/src/main/resources/RecursiveVDM.*\\<close>\\<^footnote>\\<open>in~\\<^url>\\<open>https://github.com/leouk/VDM_Toolkit\\<close>\\<close>.\n\nIn the next section, we present background on VDM and Isabelle recursion and\nmeasure relations. Section~\\ref{sec:VDMTypes} briefly discusses VDM basic\ntypes translation and their consequence for recursion. Next,\nSection~\\ref{sec:Recursion} describes how both VDM and Isabelle recursive\ndefinitions work and how they differ. Our translation strategy is then\npresented in Section~\\ref{sec:Strategy} for basic types, sets, maps, and\ncomplex recursive patterns. Finally, we conclude in\nSection~\\ref{sec:Conclusion}. \\<close>\n\n(******************************************************************************)\nsection \\<open>Background\\label{sec:Background}\\<close> \n\ntext \\<open>Our VDM to Isabelle/HOL translator caters for a wide range of the VDM-SL\nAST. It copes with all kinds of expressions, a variety of patterns, almost all\ntypes, imports and exports, functions and specifications, traces, and some of\nstate and operations @{cite NimFull and AdvancedVSCodePaper}. Although not\nall VDM patterns are allowed, the translator copes with most, and\nwhere it does not, there is a corresponding equivalent.\n\nOne particular area we want to extend translation is over recursively defined\nfunctions. VDM requires the user to define a measure function to justify why\nrecursion terminates. It then generates proof obligations to ensure\ntotality and termination.\n\nFinally, our translation strategy follows the size-change termination (SCT)\nproof strategy described in @{cite SCT_POPL and SCNP_POPL}. In particular, its\nSCP (polynomial) and SCNP (non-polynomial) subclasses of recursive definitions\nwithin the SCT, which permits efficient termination checking. Effectively, if\nevery infinite computation would give rise to an infinitely decreasing value\nsequence (according to the size-change principle), then no infinite\ncomputation is possible. Termination problems in this class have a global\nranking function of a certain form, which can be found using SAT solving,\nhence increasing automation.\\<close>\n(*\\<^bold>\\<open>ANYTHING ELSE? Related work?\\<close>*)\n\n(*****************************************************************************)\nsection \\<open>VDM basic types in Isabelle\\label{sec:VDMTypes}\\<close>\n\ntext \\<open>Isabelle represents natural numbers (\\<^typ>\\<open>\\<nat>\\<close>) as a (data) type with\ntwo constructors (\\<^term>\\<open>0::\\<nat>\\<close> and \\<^term>\\<open>Suc n\\<close>), where all numbers are\nprojections over such constructions (\\<^emph>\\<open>e.g.\\<close>~@{lemma \\<open>2 = (Suc (Suc 0))\\<close> by\nsimp}). Isabelle integers (\\<^typ>\\<open>\\<int>\\<close>) are defined as a quotient type\ninvolving two natural numbers. Isabelle quotient types are injections into a\nconstructively defined type. As with integers, other Isabelle numeric types\n(\\<^emph>\\<open>e.g.,\\<close>~rationals \\<^typ>\\<open>\\<rat>\\<close>, reals \\<^typ>\\<open>\\<real>\\<close>, \\<^emph>\\<open>etc\\<close>.) are defined in\nterms of some involved natural number construction. Type conversions (or\ncoercions) are then defined to allow users to jump between type spaces.\nNevertheless, Isabelle has no implicit type widening rule for \\<^typ>\\<open>\\<nat>\\<close>;\ninstead, it takes conventions like @{lemma[show_types] \\<open>(0 - x::\\<nat>) = 0\\<close> by\nsimp}. For expressions involving a mixutre of \\<^typ>\\<open>\\<int>\\<close> and \\<^typ>\\<open>\\<nat>\\<close> typed\nterms, explicit user-defined type coercions might be needed\n(\\<^emph>\\<open>e.g.,\\<close>~@{lemma[show_types] \\<open>(2::\\<nat>) - (3::\\<int>) = -1\\<close> by simp}).\n \nVDM expressions with basic-typed (\\<^bold>\\<open>nat\\<close>, \\<^bold>\\<open>int\\<close>) variables have specific\ntype widening rules. For example, even if both variables are \\<^bold>\\<open>nat\\<close>, the\nresult might be \\<^bold>\\<open>int\\<close>. (\\<^emph>\\<open>e.g.,\\<close>~in VDM, \\<^verbatim>\\<open>0 - x:nat = -x:int\\<close>). Therefore,\nour translation strategy considers VDM \\<^bold>\\<open>nat\\<close> as the Isabelle type\n\\<^typ>\\<open>VDMNat\\<close>, which is just a type synonym for \\<^typ>\\<open>\\<int>\\<close>. This simplifies\nthe translation process to Isabelle, such that no type coercions are\nnecessary to encode all VDM type widenning rules. On the other hand, this\ndesign decision on type widening means encoding of recursive functions over\n\\<^bold>\\<open>nat\\<close> to have to follow the scheme for \\<^typ>\\<open>\\<int>\\<close>, given VDM's \\<^bold>\\<open>nat\\<close> is \nrepresented as Isabelle's \\<^typ>\\<open>\\<int>\\<close>.\n\n  Despite this design decision over basic types and their consequences,\n  recursion over VDM \\<^bold>\\<open>int\\<close>, sets or maps will still be involved. That is\n  because these types are not constructively defined in Isabelle.\\<close>\n\n(*****************************************************************************)\nsection \\<open>Recursion in VDM and in Isabelle\\label{sec:Recursion}\\<close>\n\ntext \\<open>An important aspect of every recursive definition is an argument that\njustifies its termination. Otherwise, the recursion might go into an infinite\nloop. In VDM, this is defined using a recursive measure:~it has the same input\ntype signature as the recursive definition, and returns a \\<^bold>\\<open>nat\\<close>, which\n\\<^bold>\\<open>must\\<close> monotonically decrease at each recursive call, eventually reaching\nzero. This is how termination of recursive definitions are justified in VDM. A\nsimple example of a VDM recursive definition is one for calculating the\nfactorial of a given natural number\n%\n\\begin{vdmsl}[frame=none,basicstyle=\\ttfamily\\scriptsize]\n   fact: nat -> nat \n   fact(n) == if n = 0 then 1 else n * fact(n - 1)   measure n;   \n\\end{vdmsl} \n%\n%   -- For the measure below, VDMJ produces a measure function as: \n%   -- measure_fact: nat -> nat\n%   -- measure_fact(n) == n\n\\noindent The VDM  \\<^verbatim>\\<open>fact\\<close>-function recursive measure uses the given  \\<^verbatim>\\<open>n\\<close> input itself as its\nresult. This works because the only recursive call is made with a decreasing\nvalue of \\<^verbatim>\\<open>n\\<close>, until it reaches the base case \\<^verbatim>\\<open>0\\<close> and terminates. VDMJ generates three\nproof obligations for the definition above. They are trivial to discharge in\nIsabelle given the measure definition expanded is just \n@{lemma \\<open>(\\<forall> n::\\<nat> . \\<not> n = 0 \\<longrightarrow> n - 1 \\<ge> 0)\\<close> by simp} and \n@{lemma \\<open>(\\<forall> n::\\<nat> . \\<not> n = 0 \\<longrightarrow> n > n - 1)\\<close> by simp}.\n%\n\\begin{vdmsl}[frame=none,basicstyle=\\ttfamily\\scriptsize]\n  Proof Obligation 1: (Unproved) fact; measure_fact: total function obligation \n  (forall n:nat & is_(measure_fact(n), nat))\n  \n  Proof Obligation 2: (Unproved) fact: subtype obligation \n  (forall n:nat & (not (n = 0) => (n - 1) >= 0))\n  \n  Proof Obligation 3: (Unproved) fact: recursive function obligation \n  (forall n:nat & (not (n=0) => measure_fact(n) > measure_fact((n-1))))\n\\end{vdmsl} \n%\n%Remove?\nMoreover, even though measures over recursive type structures are impossible\nto define in VDM, they are easily described in Isabelle. For example, it is\nnot possible to write a measure in VDM over a recursive record defining a\nlinked list, such as \\<^verbatim>\\<open>R :: v: nat n: R\\<close>. This is automatically generated for\nour representation of VDM records in Isabelle as a datatype. Other complex\nrecursive patterns are hard/impossible to represent in VDM (see\nSection~\\ref{subsec:Complex}).\n  \nIn Isabelle, recursive definitions can be provided through primitive recursion\nover inputs that are constructively defined, or more general function\ndefinitions that produce proof obligations. The former insists on definition\nfor each type constructor and only provides simplification rules; whereas the\nlatter allows for more sophisticated input patterns and provides\nsimplification, elimination and induction rules, as well as partial function\nconsiderations. For the purposes of this paper, we only consider function\ndefinitions. Readers can find more about these differences in~@{cite\nIsaFunctionPackage}.\n\nIsabelle's recursive functions require a proof obligation that its parameters\nrepresent a constructive and compatible pattern, and that recursive calls\nterminate. Constructive patterns covers all constructors in the data type\nbeing used in the recursion inputs (\\<^emph>\\<open>i.e.,\\<close>~one equation for each of the\nconstructors of \\<^typ>\\<open>\\<nat>\\<close>, hence one involving \\<^term>\\<open>0::\\<nat>\\<close> and another\ninvolving \\<^term>\\<open>Suc n\\<close>). Compatible patterns cover the multiple ways\npatterns can be constructed will boil down to the pattern completeness cases\n(\\<^emph>\\<open>e.g.,\\<close>~\\<^term>\\<open>n + 2::\\<nat>\\<close> being simply multiple calls over defined\nconstructors like \\<^term>\\<open>Suc (Suc n)\\<close>). This is important to ensure that\nrecursion is well structured (\\<^emph>\\<open>i.e.,\\<close>~recursive calls will not get stuck\nbecause some constructs are not available). For example, if you miss the\n\\<^term>\\<open>0::\\<nat>\\<close> case, eventually the \\<^term>\\<open>Suc n\\<close> case will reach zero and\nfail, as no patterns for zero exist. The proof obligation for termination\nestablishes that the recursion is well-founded. This has to be proved whenever\nproperties of the defined function are meant to be total.\n\nIsabelle's function definitions can be given with either \\<^term>\\<open>fun\\<close> or\n\\<^term>\\<open>function\\<close> syntax. The former attempts to automatically prove the\npattern constructive and compatible proofs and finds a measure for the\ntermination proof obligation. The latter requires the user to do these proofs\nmanually by providing a measure relation. It is better suited for cases where\n\\<^term>\\<open>fun\\<close> declarations fail, which usually involve complex or ill-defined\nrecursion.\n\nThe termination relation must be well-founded, which means have a well-ordered\ninduction principle over a partially ordered relation defined as\\<^footnote>\\<open>Details on \nwell-ordered induction are in Isabelle's \\<^verbatim>\\<open>Wellfounded.thy\\<close> theory.\\<close> \n@{thm[display,show_types] wf_def} A version of the factorial definition that\nIsabelle discovers all three termination and well-formedness proofs is given as\\<close>\n(* find_theorems name:wellorder print_locale! wellorder *)\nfun fact' :: \\<open>\\<nat> \\<Rightarrow> \\<nat>\\<close> where \\<open>fact' n = (if n = 0 then 1 else n * (fact' (n - 1)))\\<close> \n\ntext \\<open>This definition is quite similar in VDM. Nevertheless, VDM basic types\nwidening rules necessitate we translate them to \\<^typ>\\<open>VDMNat\\<close>. The same\nversion of \\<^term>\\<open>fact\\<close> defined for \\<^typ>\\<open>\\<int>\\<close> will fail with the error that\n``\\<^emph>\\<open>Could not find lexicographic termination order\\<close>''. That is, Isabelle\nmanages to discharge the pattern proofs, but not the termination one. This is\nbecause the user must provide a projection relation from the \\<^typ>\\<open>\\<int>\\<close>\nquotient type back into the constructive type \\<^typ>\\<open>\\<nat>\\<close>.\n\nEven if we could avoid this translation technicality, the same problem would\noccur for recursion over non-constructive types, such as sets or maps. They\nrequire recursion over finite sets, which are defined inductively. The only\neasy recursive translations are those involving lists, given lists in Isabelle\nare defined constructively and VDM sequences map directly.\n\nTherefore, defining recursive functions over non-constructive types entail\ncompatibility and completeness proofs. They also lead to partial function\ndefinitions, given Isabelle cannot tell whether termination is immediately\nobvious. In VDM, however, recursive functions on sets (as well as map domains)\nare common, hence the need for extending our translation strategy.\\<close>\n\n(******************************************************************************)\nsection \\<open>VDM recursion translation strategy\\label{sec:Strategy}\\<close>\n\ntext \\<open>We want to identify a translation strategy that will cater for \nissues described above not only for basic types, but also for sets, sequences,\nmaps, as well as mutual recursion.\n\nThe VDM-SL AST tags all recursive functions, even those without an explicit\nmeasure. All such functions will be translated using Isabelle's \\<^term>\\<open>fun\\<close>\nsyntax, which will attempt to discover proofs for compatibility and\ntermination. For our setup of the \\<^verbatim>\\<open>fact\\<close> example, where Isabelle discovers the\ntermination proof.\\<close>\n\n(*<*)\ndefinition pre_fact'' :: \\<open>VDMNat \\<Rightarrow> \\<bool>\\<close> where [simp]:\\<open>pre_fact'' n \\<equiv> inv_VDMNat n\\<close>\nfun fact'' :: \\<open>VDMNat \\<Rightarrow> VDMNat\\<close> where \n\\<open>fact'' n = (if pre_fact'' n then (if n = 0 then 1 else n * (fact'' (n - 1))) else undefined)\\<close>\n(*>*)\n\ntext \\<open> If that had failed, the user could define a VDM \\<^verbatim>\\<open>@IsaMeasure\\<close>\nannotation. VDM annotations are comments that will be processed according to\nspecific implementations @{cite VDMJAnnotations and AdvancedVSCodePaper}. If\nthe user does not provide an \\<^verbatim>\\<open>@IsaMeasure\\<close> annotation and \\<^term>\\<open>fun\\<close>\nfails, then it is up to the user to figure out the necessary proof setup.\n\nThe \\<^verbatim>\\<open>@IsaMeasure\\<close> annotation defines a well-founded measure relation that\nwill participate in the setup for Isabelle termination proof. For example, for\nthe \\<^verbatim>\\<open>fact\\<close> example, the user would have to write an annotation before the VDM\nmeasure.\n\\begin{vdmsl}[frame=none,basicstyle=\\ttfamily\\scriptsize]\n  --@IsaMeasure( { (n -1, n) | n : nat & n <> 0 } )\n\\end{vdmsl}\n\\noindent This measure relation corresponds to the relationship between the\nrecursive call (\\<^verbatim>\\<open>fact(n-1)\\<close>) and its defining equation (\\<^verbatim>\\<open>fact(n)\\<close>), where\nthe filtering condition determines which values of \\<^verbatim>\\<open>n\\<close> the relation should \nrefer to. More interesting measure relations are defined in\nSection~\\ref{subsec:Complex}.\n\nDuring translation, the \\<^verbatim>\\<open>vdm2isa\\<close> plugin will typecheck the \\<^verbatim>\\<open>@IsaMeasure\\<close> annotation\n(\\<^emph>\\<open>i.e.,\\<close>~it is a type correct relation over the function signature). Next, it\nwill translate the annotation and some automation lemmas as a series of\nIsabelle definitions to be used during the proof of termination of translated\nVDM recursive functions. If no annotation is provided, following similar\nprinciples from Isabelle, then the plugin will try to automatically infer what\nthe measure relation should be based on the structure of the recursive\nfunction definition. If this fails, then the user is informed. Still, even\nif measure-relation synthesis succeeds, the user still has to appropriately\nuse it during Isabelle's termination proof.\n\nIn what follows, we will detail the translation strategy for each relevant VDM\ntype. For details of the overall translation strategy, see examples in the\ndistribution\\<^footnote>\\<open>\\<^url>\\<open>https://github.com/leouk/VDM_Toolkit\\<close>\\<close> and~@{cite NimFull}.\nThe translation strategy imposes various implicit VDM checks as explicit predicates. \nFor example, VDM sets are always finite, and type invariants over set, sequence\nand map elements must hold for every element.\\<close>\n\n(*----------------------------------------------------------------------------*)\nsubsection \\<open>Recursion over VDM basic types (\\<^bold>\\<open>nat\\<close>, \\<^bold>\\<open>int\\<close>)\\label{subsec:VDMNat}\\<close>\n\ntext \\<open>Following the general translation strategy~@{cite NimFull}, we first\nencode the implicit precondition, which insists that\nthe given parameter \\<^term>\\<open>n\\<close> is a \\<^typ>\\<open>VDMNat\\<close>, alongside a list of\ndefining constants that are useful for proof strategy synthesis.\\<close>\n(* COMMENT: make pre_XXX a simplification rule for fun declarations! *)\n\ndefinition pre_fact :: \\<open>VDMNat \\<Rightarrow> \\<bool>\\<close> where \\<open>pre_fact n \\<equiv> inv_VDMNat n\\<close>\nlemmas pre_fact_defs = pre_fact_def  \n\ntext \\<open>Next, we define factorial recursively. When the precondition fails, we\nreturn \\<^term>\\<open>undefined\\<close>, which is a term that cannot be reasoned with in\nIsabelle The \\<^term>\\<open>domintros\\<close> tag tells Isabelle to generate domain\npredicates, in case this function is not total. Domain predicates are\nimportant to our strategy because every VDM function will be undefined, when\napplied outside its precondition. It also generates domain-predicate sensitive\nproof rules listed below.\\<close>\nfunction (domintros) fact :: \\<open>VDMNat \\<Rightarrow> VDMNat\\<close> where\n\\<open>fact n = (if pre_fact n then (if n = 0 then 1 else n * (fact (n - 1))) else undefined)\\<close>\n\ntext \\<open>The proof obligations for pattern compatibility and completeness are\ndischarged with the usual Isabelle proof strategy for simple recursive\npatterns with the @{method pat_completeness} method. In the general case\ndiscussed in Section~\\ref{subsec:Complex}, the user might have goals to\ndischarge. Isabelle proves various theorems abou case analysis and\n(partial) rules for elimination, induction and simplification.\\<close>\n  by (pat_completeness, auto) \\<^marker>\\<open>tag invisible\\<close>\n  \ntext \\<open>Partial rules require the domain predicate @{term fact_dom} as an assumption.\nIt represents a well-founded relation that ensures termination. That is, if\nthe user does not want (or knows how) to prove termination, such domain\npredicates will follow every application of definitions,\nhence documenting the requirement that such well-founded relation is still\nmissing.\n\nIf/when the termination proof is discharged, these p-rules can be simplified\ninto total rules that do not depend on a domain predicate, given a\nwell-founded relation has been provided. Domain predicates will complicate\nuser proofs, and also make proof strategy synthesis harder to automate.\n\nTermination proof is discharged by establishing a well-founded relation\nassociated with the function recursive call(s) with respect to its\ndeclaration. The \\<^verbatim>\\<open>@IsaMeasure\\<close> annotation is translated as an\nIsabelle abbreviation. The filter that the function\nprecondition holds:~this is important to ensure the termination proof never\nreaches the \\<^term>\\<open>undefined\\<close> case. The other filter comes from the negated\ntest from the if-statement. More complex definitions will have more\ninvolved filters. We use abbreviation instead of definition to avoid needing\nto expand the defined term in proofs.\\<close>\n\nabbreviation fact_wf :: \\<open>(VDMNat \\<times> VDMNat) set\\<close> where\n  \\<open>fact_wf \\<equiv> { (n - 1, n) | n . pre_fact n \\<and> n \\<noteq> 0 }\\<close>\n\ntext \\<open>Given \\<^verbatim>\\<open>fact\\<close> definition is simple (non-mutual, single call-site, easy\nmeasure relation choice) recursion, its setup is easy to\nestablish well-foundedness. For recursions of this nature, we can piggyback on\nIsabelle machinery to prove well foundedness by using terms\n@{term gen_VDMNat_term} and @{term int_ge_less_than}.\n\nThe first term is defined in terms of the second, which is a subset of our\nwell-founded relation \\<^term>\\<open>fact_wf\\<close>. Isabelle has proofs about the \nwell foundedness of \\<^term>\\<open>int_ge_less_than\\<close>. Thus, making the proof our\nterm being well-founded trivial for @{command sledgehammer}. \nAs part of the translation strategy, we define\n(and attempt to discover the proof of) the following lemma. This follows\nthe strategy described in~@{cite KrausSCNP}.\\<close>\nlemma l_fact_term_wf: \\<open>wf (gen_VDMNat_term fact_wf)\\<close>\n  by (simp add: wf_int_ge_less_than wf_Int1) \\<^marker>\\<open>tag invisible\\<close>\n\ntext \\<open>Finally, we prove termination using the previously proved lemma using\nthe @{method relation}. This simplifies the goal into well-foundedness of\ntermination relation and that the precondition implies it, both of which are\neasily proved with simplification in this case.\\<close>\ntermination \\<^marker>\\<open>tag invisible\\<close>\n  apply (relation \\<open>(gen_VDMNat_term fact_wf)\\<close>) \\<^marker>\\<open>tag invisible\\<close>\ntext \\<open>This transforms the abstract domain predicate into two new subgoals as\n@{subgoals[display]}\\<close>\n  using l_fact_term_wf apply presburger \\<^marker>\\<open>tag invisible\\<close>\n  by (simp add: pre_fact_defs int_ge_less_than_def) \\<^marker>\\<open>tag invisible\\<close>\n\ntext \\<open>For this example, subgoals are proved with @{command\nsledgehammer}. In general, the user will have to either find the proof, or\ndeal with domain predicates involving the recursive call. After the\ntermination proof is discharged, Isabelle provides versions of rules for\nelimination, induction and simplification that are total and do not depend on\nthe domain predicates. \n\nTo make sure our choice does not lead to the empty relation, we ensure that\nthe termination relation is in fact the same as the well founded\npredicate by proving the next goal. This is something users might want to do,\nbut is not part of the translation strategy. In case the measure relation is\nempty, the recursive call simplification rules will not be useful anyhow.\\<close>\n\nlemma l_fact_term_valid: \\<open>(gen_VDMNat_term fact_wf) = fact_wf\\<close>\n  apply (simp ) \\<^marker>\\<open>tag invisible\\<close>\n  apply (intro equalityI subsetI)\\<^marker>\\<open>tag invisible\\<close>\n   apply (simp_all add: pre_fact_defs int_ge_less_than_def case_prod_beta)\\<^marker>\\<open>tag invisible\\<close>\n  by auto\\<^marker>\\<open>tag invisible\\<close>\n\n(*---------------------------------------------------------------------------*)\nsubsection \\<open>Recursion over VDM sets\\label{subsec:VDMSet}\\<close>\n\ntext \\<open>Next, we extend the translation strategy for VDM sets.\nFor this, we use a function that sums the elements of a set.\n%\n\\begin{vdmsl}[frame=none,basicstyle=\\ttfamily\\scriptsize]\n  sumset: set of nat -> nat \n  sumset(s) == if s = {} then 0 else let e in set s in sumset(s - {e}) + e\n  --@IsaMeasure({(x - { let e in set x in e }, x) | x : set of nat & x <> {}}) \n  --@Witness(sumset({ 1 }))\n  measure card s;\n\\end{vdmsl}\n%\n\\noindent Most common VDM-recursion over sets consume the\nset by picking an arbitrary set element and then continue the recursion without\nthe element picked, until the set is empty. The VDM measure states that the\nrecursion is based on the cardinality of the input parameter. VDM measures are\nnot suitable for Isabelle proofs, given Isabelle requires a relation;~hence,\nVDM measures are mostly ignored. They might still be useful during\nproofs as potential witnesses to existentially-quantified goals.\n\nThe implicit VDM checks are defined as the precondition, which\nensures that the given set only contains natural numbers and is finite, as\ndefined by \\<^term>\\<open>inv_VDMSet'\\<close>.\\<close>\n\ndefinition pre_sumset :: \\<open>VDMNat VDMSet \\<Rightarrow> \\<bool>\\<close> where\n  \\<open>pre_sumset s \\<equiv> inv_VDMSet' inv_VDMNat s\\<close>\nlemmas pre_sumset_defs = pre_sumset_def inv_VDMSet'_defs \n\ntext \\<open>We define the VDM recursive function in Isabelle next. It checks whether\nthe given set satisfies the function precondition, returning \\<^term>\\<open>undefined\\<close>\nif not. Each case is encoded pretty much 1-1 from VDM after that. The\ntranslation strategy for VDM \\<^verbatim>\\<open>let-in-set\\<close> patterns uses Isabelle's Hilbert's\nchoice operator (\\<^term>\\<open>\\<some> x . x \\<in> s\\<close>). Note this naturally extends to VDM's\n\\<^verbatim>\\<open>let-be-st\\<close> patterns as well.\\<close>\nfunction (domintros) sumset :: \\<open>VDMNat VDMSet \\<Rightarrow> VDMNat\\<close> where \n  \\<open>sumset s = (if pre_sumset s then \n                       (if s = {} then 0 else let e = (\\<some> x . x \\<in> s) in sumset (s - {e}) + e) \n                    else undefined)\\<close>\n  by (pat_completeness, auto) \\<^marker>\\<open>tag invisible\\<close>\n\ntext \\<open>The pattern completeness and compatibility goals are trivial.\nThe measure relation defined with  \\<^verbatim>\\<open>@IsaMeasure\\<close> is next.\nIt is defined as the smaller set after picking \\<^term>\\<open>e\\<close> and the set used \nat the entry call, leading to the pairs \\<^term>\\<open>(s - {(\\<some> e . e \\<in> s)}, s)\\<close>. \nFinally, we ensure all the relation elements satisfy the function precondition\nand that the if-test is negated. \\<close>\nabbreviation sumset_wf_rel :: \\<open>(VDMNat VDMSet \\<times> VDMNat VDMSet) set\\<close> where\n  \\<open>sumset_wf_rel \\<equiv> { (s - {(\\<some> e . e \\<in> s)}, s)| s . pre_sumset s \\<and> s \\<noteq> {}}\\<close>\n\ntext \\<open>Given this is a simple recursion, again we can piggyback on Isabelle \nmachinery by using the terms @{term gen_set_term} and @{term finite_psubset}.\nThey establishes that a relation where the first element is strictly smaller\nset than the second in the relation pair is well-founded. This makes\nthe proof of well-foundedness easy for @{command sledgehammer}.\\<close>\n\nlemma l_sumset_rel_wf: \\<open>wf (gen_set_term sumset_wf_rel)\\<close>\n  using l_gen_set_term_wf \\<^marker>\\<open>tag invisible\\<close>\n  by blast \\<^marker>\\<open>tag invisible\\<close>\n\ntext \\<open>Next, we tackle the termination proof, with the same setup with @{method\nrelation} again.\\<close>\ntermination\\<^marker>\\<open>tag invisible\\<close>\n  apply (relation \\<open>(gen_set_term sumset_wf_rel)\\<close>)\\<^marker>\\<open>tag invisible\\<close>\n  using l_sumset_rel_wf \\<^marker>\\<open>tag invisible\\<close> \n  apply force\\<^marker>\\<open>tag invisible\\<close>\n  text \\<open>Unfortunately, using @{command sledgehammer} fails to discharge the\n  second subgoal @{subgoals[display]}\\<close>\n  oops\\<^marker>\\<open>tag invisible\\<close>\n\ntext \\<open>Fortunately, for most simple situations, this is easy to decompose in\ngeneral. The translation strategy takes the \\<^verbatim>\\<open>@IsaMeasure\\<close> expression and\ndecomposes its parts, such that the filtering predicates are assumptions, and\nthe element in the relation belongs to the well-founded measure chosen. This \nis defined in the next lemma, which require some manual intervention until \nIsabelle's @{command sledgehammer} can finish the proof.\\<close>\nlemma l_pre_sumset_sumset_wf_rel: \n   \\<open>pre_sumset s \\<Longrightarrow> s \\<noteq> {} \\<Longrightarrow> (s - {(\\<some> x. x \\<in> s)}, s) \\<in> (gen_set_term sumset_wf_rel)\\<close>\n  unfolding gen_set_term_def \\<^marker>\\<open>tag invisible\\<close>\n  apply (simp add: pre_sumset_defs)\\<^marker>\\<open>tag invisible\\<close>\n  by (metis Diff_subset member_remove psubsetI remove_def some_in_eq)\\<^marker>\\<open>tag invisible\\<close>\n\ntext \\<open>The intuition behind this lemma is that elements in the measure\nrelation satisfy well-foundedness under the function precondition and the\nfiltering case (\\<^term>\\<open>s \\<noteq> {}\\<close>) where the recursive call is made. That is,\nthe precondition and filtering condition help establish the terminating\nrelation. For this particular proof, the only aspect needed from the\nprecondition is that the set is finite.\nWith this, we try the termination proof and @{command\nsledgehammer} find proofs for all subgoals.\\<close>\ntermination\\<^marker>\\<open>tag invisible\\<close>\n  apply (relation \\<open>(gen_set_term sumset_wf_rel)\\<close>)\\<^marker>\\<open>tag invisible\\<close>\n  using l_sumset_rel_wf apply force\\<^marker>\\<open>tag invisible\\<close>\n  using l_pre_sumset_sumset_wf_rel by presburger\\<^marker>\\<open>tag invisible\\<close>\n(*<*)\nlemma l_pre_fact_wf_rel': \\<open>pre_fact n \\<Longrightarrow> n \\<noteq> 0 \\<Longrightarrow> (n - 1, n) \\<in> gen_VDMNat_term fact_wf\\<close>\n  unfolding gen_VDMNat_term_def gen_VDMInt_term_def\n  using l_fact_term_valid by force\n(*>*)\n\ntext \\<open>Note we omit such lemma over termination and precondition for the\n\\<^typ>\\<open>VDMNat\\<close> case in Section~\\ref{subsec:VDMNat}. The translation strategy\ndoes define it following the same recipe, where @{command sledgehammer} \nfind the proof once more.\\<close>\nlemma l_pre_fact_wf_rel: \n  \\<open>\\<lbrakk>pre_fact n; n \\<noteq> 0\\<rbrakk> \\<Longrightarrow> (n - 1, n) \\<in> gen_VDMNat_term fact_wf\\<close>\n  unfolding gen_VDMNat_term_def gen_VDMInt_term_def \\<^marker>\\<open>tag invisible\\<close>\n  using l_less_than_VDMNat_subset_int_ge_less_than pre_fact_def \\<^marker>\\<open>tag invisible\\<close>\n  by auto \\<^marker>\\<open>tag invisible\\<close>\n\n(*<*)\nlemma l_sumset_wf_rel_valid: \\<open>gen_set_term sumset_wf_rel = sumset_wf_rel\\<close>\n  apply (intro equalityI subsetI, simp) \\<^marker>\\<open>tag invisible\\<close>\n  using l_pre_sumset_sumset_wf_rel by blast \\<^marker>\\<open>tag invisible\\<close>\n(*>*)\n\ntext \\<open>Finally, even though this was not necessary for this proof, we encourage\nusers to always provide a witness for the top recursive call. This is done by\nusing the \\<^verbatim>\\<open>@Witness\\<close> annotation~@{cite AdvancedVSCodePaper}:~it provides a \nconcrete example for the function input parameters. This witness is useful \nfor existentially quantified predicates of involved termination \nproofs (see Section~\\ref{subsec:Complex}).\\<close>\n\n(*---------------------------------------------------------------------------*)\nsubsection \\<open>Recursion over VDM maps\\label{subsec:VDMMap}\\<close>\n\ntext \\<open>Recursive functions over maps are a special case of sets, given\nmap recursion usually iterates over the map's domain. For example, the\nfunction that sums the elements of the map's range is defined as\n%\n\\begin{vdmsl}[frame=none,basicstyle=\\ttfamily\\scriptsize]\n  sum_elems: map nat to nat -> nat\n  sum_elems(m) == \n    if m = {|->} then 0 else let d in set dom m in m(d) + sum_elems({d}<-:m)\n  --@IsaMeasure({({d} <-: m, m) | m : map nat to nat, d: nat & \n                      m <> {} and d in set dom m})\n  --@Witness( sum_elems({ 1 |-> 1 }) )\n  measure card dom m;\n\\end{vdmsl}\n%\n\\noindent As with sets, it iterates over the map by picking a domain element,\nperforming the necessary computation, and then recursing on the map filtered by\nremoving the chosen element, until the map is empty and the function\nterminates. The measure relation follows the same\npattern:~recursive call site related with defining site, where both the\nif-test and the \\<^verbatim>\\<open>let-in-set\\<close> choice is part of the filtering predicate.\n\nFollowing the general translation strategy for maps~@{cite NimFull}, we define\nthe function precondition using \\<^term>\\<open>inv_Map\\<close>. It insists that both the map\ndomain and range are finite, and that all domain and range elements satisfy\ntheir corresponding type invariant. Note that, if the recursion was defined\nover sets other than the domain and range, then Isabelle requires a proof that\nsuch set is finite. Given both domain and range sets are finite,\nthis should be easy, if needed.\\<close>\n\ndefinition pre_sum_elems :: \\<open>(VDMNat \\<rightharpoonup> VDMNat) \\<Rightarrow> \\<bool>\\<close> where\n  \\<open>pre_sum_elems m \\<equiv> inv_VDMMap inv_VDMNat inv_VDMNat m\\<close>\nlemmas pre_sum_elems_defs = pre_sum_elems_def inv_VDMMap_defs  \n\ntext \\<open>VDM maps in Isabelle (\\<^typ>\\<open>(VDMNat \\<rightharpoonup> VDMNat)\\<close>) are defined as a HOL\nfunction which maps to an optional result. That is, if the element is in the\ndomain, then the map results in a non {\\texttt{\\<^bold>\\<open>nil\\<close>}} value; whereas, if the\nelement does not belong to the domain, then the map results in a {\\texttt{\\<^bold>\\<open>nil\\<close>}}\nvalue. This makes all maps total, where values outside the domain\nmap to {\\texttt{\\<^bold>\\<open>nil\\<close>}}. The Isabelle translation and compatibility proof\nfollows patterns used before.\\<close>\nfunction (domintros) sum_elems :: \\<open>(VDMNat \\<rightharpoonup> VDMNat) \\<Rightarrow> VDMNat\\<close> where\n  \\<open>sum_elems m = \n    (if pre_sum_elems m then\n         if m = Map.empty then 0 else\n             let d = (\\<some> e . e \\<in> dom m) in the(m d) + (sum_elems ({d} -\\<triangleleft> m))\n     else undefined)\\<close>\n  by (pat_completeness, auto) \\<^marker>\\<open>tag invisible\\<close>\n\ntext \\<open>Similarly, the well-founded relation is translated\nnext, where the precondition is included as part of the relation's\nfilter. The \\<^term>\\<open>{d}-\\<triangleleft>m\\<close> corresponds to the VDM domain anti-filtering operator\n\\<^verbatim>\\<open>{d}<-:m\\<close>.\\<close>\nabbreviation \n  sum_elems_wf :: \\<open>((VDMNat \\<rightharpoonup> VDMNat) \\<times> (VDMNat \\<rightharpoonup> VDMNat)) VDMSet\\<close> \n  where \\<open>sum_elems_wf \\<equiv> \n  { (({d} -\\<triangleleft> m), m) | m d . pre_sum_elems m \\<and> m \\<noteq> Map.empty \\<and> d \\<in> dom m }\\<close>\n\ntext \\<open>For the well-founded lemma over the recursive measure relation, there is\nno available Isabelle help, and projecting the domain element of the maps\nwithin the relation is awkward. Thus, we have to prove the well-founded lemma \nand this will not be automatic in general. This is one difference in terms of\ntranslation of VDM recursive functions over sets and maps.\n\nFortunately, the proof strategy for such situations is somewhat known:~it\nfollows a similar strategy to the proof of well foundedness of the\n\\<^term>\\<open>finite_psubset\\<close>. It uses the provided VDM measure expression to extract \nthe right projection of interest, then follows the proof for\n \\<^term>\\<open>finite_psubset\\<close>, where @{command sledgehammer} can \nfind the final steps.\n\nThe precondition subgoal and the termination proof follow the same\npatterns as before. Their proof was discovered with @{command\nsledgehammer}, yet this will not be the case in general.\\<close>\nlemma l_sum_elems_wf: \\<open>wf sum_elems_wf\\<close>\n  apply (rule wf_measure[of \\<open>\\<lambda> m . card (dom m)\\<close>, THEN wf_subset]) \\<^marker>\\<open>tag invisible\\<close>\n  apply (simp add: measure_def inv_image_def less_than_def less_eq)\\<^marker>\\<open>tag invisible\\<close>\n  apply (rule subsetI, simp add: case_prod_beta)\\<^marker>\\<open>tag invisible\\<close>\n  apply (elim exE conjE)\\<^marker>\\<open>tag invisible\\<close>\n  by (simp add: l_VDMMap_filtering_card pre_sum_elems_defs)\\<^marker>\\<open>tag invisible\\<close>\n\nlemma l_pre_sum_elems_sum_elems_wf: \n  \\<open>\\<lbrakk>pre_sum_elems m; m \\<noteq> Map.empty\\<rbrakk> \\<Longrightarrow> \n   ({(\\<some> e. e \\<in> dom m)} -\\<triangleleft> m, m) \\<in> sum_elems_wf\\<close>\n  apply (simp add: pre_sum_elems_defs) \\<^marker>\\<open>tag invisible\\<close>\n  by (metis domIff empty_iff some_in_eq) \\<^marker>\\<open>tag invisible\\<close>\n\ntermination  \\<^marker>\\<open>tag invisible\\<close>\n  apply (relation sum_elems_wf)\\<^marker>\\<open>tag invisible\\<close>\n(*  apply (rule \\<open>termination\\<close>[OF l_sum_elems_wf])\\<^marker>\\<open>tag invisible\\<close> *)\n  apply (simp add: l_sum_elems_wf)\\<^marker>\\<open>tag invisible\\<close>\n  using l_pre_sum_elems_sum_elems_wf by presburger\\<^marker>\\<open>tag invisible\\<close>\n\nlemma l_sum_elems_wf_valid: \\<open>sum_elems_wf \\<noteq> {}\\<close>\n  apply safe \\<^marker>\\<open>tag invisible\\<close>\n  apply (erule equalityE)\\<^marker>\\<open>tag invisible\\<close>\n  apply (simp add: subset_eq)\\<^marker>\\<open>tag invisible\\<close>\n  apply (erule_tac x=\\<open>[1 \\<mapsto> 1]\\<close> in allE)\\<^marker>\\<open>tag invisible\\<close>\n  by (simp add: pre_sum_elems_defs) \\<^marker>\\<open>tag invisible\\<close>\n\ntext \\<open>Finally, we also prove that the well founded termination relation\nis not empty, as we did for sets and \\<^bold>\\<open>nat\\<close>\nrecursion. Note that here the \\<^verbatim>\\<open>@Witness\\<close> annotation is useful in discharging\nthe actual value to use as the witness demonstrating the relation is not\nempty.\\<close>\n\n(*---------------------------------------------------------------------------*)\nsubsection \\<open>VDM recursion involving complex measures\\label{subsec:Complex}\\<close>\n\ntext \\<open>The class of recursive examples shown so far have covered a wide range of\nsituations, and have a good level of automation. Nevertheless, the same\nstrategy can also be applied for more complex recursive definitions. The cost\nfor the VDM user is the need of involved \\<^verbatim>\\<open>@IsaMeasure\\<close> definitions and\nthe highly likely need for extra user-defined lemmas. These lemmas can be\ndefined in VDM itself using the \\<^verbatim>\\<open>@Lemma\\<close> annotation.\nTo illustrate this, we define in VDM the (in)famous Ackermann\nfunction\\<^footnote>\\<open>\\<^url>\\<open>https://en.wikipedia.org/wiki/Ackermann_function\\<close>\\<close>, which is a\nstaple example of complex recursion.\n%\n\\begin{vdmsl}[frame=none,basicstyle=\\ttfamily\\scriptsize]\n    ack: nat * nat -> nat \n    ack(m,n) == if m = 0 then n+1\n           else if n = 0 then ack(m-1, 1)\n           else               ack(m-1, ack(m, (n-1)))\n    --@IsaMeasure( pair_less_VDMNat )\n    --@Witness( ack(2, 1) )\n    measure is not yet specified;\n\\end{vdmsl}\n%\n\\noindent Note that the VDM measure is not defined, and that the\n\\<^verbatim>\\<open>@IsaMeasure\\<close> uses a construct from Isabelle called \\<^term>\\<open>pair_less\\<close>. It\nis part of Isabelle's machinery of concrete orders for SCNP problems @{cite\nKrausSCNP}. It considers recursions over multiple parameters, where some might\nincrease the number of calls (\\<^emph>\\<open>e.g.\\<close>~size-change). We are not aware of a\nmechanism to define such measures in VDM.\n\nWe instantiate \\<^term>\\<open>pair_less\\<close> to \\<^typ>\\<open>VDMNat\\<close> as the\nlexicographic product over the transitive closure of a totally ordered\nrelation between inputs\\<^footnote>\\<open>Details of this definition are in the\n\\<^verbatim>\\<open>VDMToolkit.thy\\<close> within the distribution.\\<close>.\nIf VDM measures were over relations, then the Ackermann measure could be defined\nin VDM, assuming a standard definition of transitive closure\\<^footnote>\\<open>The\n\\<^verbatim>\\<open>Relations.vdmsl\\<close> provides such definition in the VDM toolkit distribution.\\<close>.\n%\n\\begin{vdmsl}[frame=none,basicstyle=\\ttfamily\\scriptsize]\npair_less_VDMNat: () -> set of ((nat*nat) * (nat*nat))\npair_less_VDMNat() == lex_prod[nat, nat](less_than_VDMNat(), less_than_VDMNat());\n\nless_than_VDMNat: () -> set of (nat*nat)\nless_than_VDMNat() == trans_closure[nat]({ mk_(z', z) | z', z : nat & z' < z });\n\nlex_prod[@A,@B]: set of (@A*@A) * set of (@B*@B) -> set of ((@A*@B) * (@A*@B))\nlex_prod(ra,rb) == { mk_(mk_(a, b), mk_(a', b')) | a, a': @A, b, b': @B & \n                      mk_(a,a') in set ra or a = a' and mk_(b, b') in set rb };\n\\end{vdmsl}\n%\nThat represents the lexicographic product of possibilities that are ordered in \nits parameters. Translation then outputs:\\<close>\n\ndefinition pre_ack :: \\<open>VDMNat \\<Rightarrow> VDMNat \\<Rightarrow> \\<bool>\\<close> where\n  \\<open>pre_ack m n \\<equiv> inv_VDMNat m \\<and> inv_VDMNat n\\<close>\nlemmas pre_ack_defs = pre_ack_def \n\nfunction (domintros) ack :: \\<open>VDMNat \\<Rightarrow> VDMNat \\<Rightarrow> VDMNat\\<close> where\n  \\<open>ack m n = (if pre_ack m n then\n                       if m = 0 then n+1\n                  else if n = 0 then ack (m-1) 1\n                  else               ack (m-1) (ack m (n-1))\n                  else               undefined)\\<close>\n  by (pat_completeness, auto) \\<^marker>\\<open>tag invisible\\<close>\n\nabbreviation ack_wf :: \\<open>((VDMNat \\<times> VDMNat) \\<times> (VDMNat \\<times> VDMNat)) VDMSet\\<close> \n  where \\<open>ack_wf \\<equiv> pair_less_VDMNat\\<close>\n\ntermination \\<^marker>\\<open>tag invisible\\<close>\n  apply (relation ack_wf)\\<^marker>\\<open>tag invisible\\<close>\n  using wf_pair_less_VDMNat \\<^marker>\\<open>tag invisible\\<close> apply blast \\<^marker>\\<open>tag invisible\\<close>\n    apply (simp add: l_pair_less_VDMNat_I1 pre_ack_def) \\<^marker>\\<open>tag invisible\\<close>\n   apply (simp add:  pre_ack_def) \\<^marker>\\<open>tag invisible\\<close>\n  by (simp add: pair_less_VDMNat_def pre_ack_def) \\<^marker>\\<open>tag invisible\\<close>\n\ntext \\<open>Compatibility and termination proofs are similar, despite the more \ncomplex measure, because of available Isabelle automation. We also show that \nthis version of Ackermann with \\<^typ>\\<open>VDMNat\\<close> is equivalent to the usual Isabelle \ndefinition using \\<^typ>\\<open>\\<nat>\\<close>. We omit details here, but have proved that they are \nequivalent by induction.\\<close>\n(*<*)\nfun ack' :: \\<open>\\<nat> \\<Rightarrow> \\<nat> \\<Rightarrow> \\<nat>\\<close> where\n  \\<open>ack' 0 n             = Suc n\\<close>\n| \\<open>ack' (Suc m) 0       = ack' m 1\\<close>\n| \\<open>ack' (Suc m) (Suc n) = ack' m (ack' (Suc m) n)\\<close>\n\nfun ack'' :: \\<open>\\<nat> \\<Rightarrow> \\<nat> \\<Rightarrow> \\<nat>\\<close> where\n  \\<open>ack'' m n = (if m = 0 then Suc n else if n = 0 then \n                  ack'' (m - 1) 1 else ack'' (m-1) (ack'' m (n -1)))\\<close>\nlemma l_ack''_1[simp]: \\<open>ack'' 0 n = Suc n\\<close> by simp\nlemma l_ack''_2[simp]: \\<open>ack'' (Suc m) 0 = ack'' m 1\\<close> by simp\nlemma l_ack''_3[simp]: \\<open>ack'' (Suc m) (Suc n) = ack'' m (ack'' (Suc m) n)\\<close> by simp\n\nfunction ack''' :: \\<open>\\<nat> \\<Rightarrow> \\<nat> \\<Rightarrow> \\<nat>\\<close> where\n  \\<open>ack''' 0 n             = Suc n\\<close>\n| \\<open>ack''' (Suc m) 0       = ack''' m 1\\<close>\n| \\<open>ack''' (Suc m) (Suc n) = ack''' m (ack''' (Suc m) n)\\<close>\n  by (pat_completeness, auto) \ntermination \n  text \\<open>Through the sledgehammer version, I unpicked the various bits and\n  pieces needed.\\<close>\n(*\n  using \\<open>termination\\<close> lessI pair_lessI1 pair_less_iff1 wf_pair_less by presburger\n*)\n  thm lessI pair_lessI1 pair_less_def pair_less_iff1 wf_pair_less\n  apply (relation pair_less)\n     apply (simp)\n  using lessI pair_lessI1 apply presburger\n  using lessI pair_less_iff1 apply presburger\n  using lessI pair_lessI1 by presburger\n(*>*)\n\ntheorem ack_correct: \\<open>ack' m n = ack m n\\<close>\n  apply (induction \\<open>m\\<close> \\<open>n\\<close> rule: ack'.induct) by (simp add: pre_ack_defs)+\n\ntext \\<open>In general, each complex recursive function will require such a setup.\nFortunately, Isabelle has a number of options available. Yet, in general, the\nmore complex the recursion, the more users will have to provide further\nautomation.\\<close>\n\n(*---------------------------------------------------------------------------*)\nsubsection \\<open>Harder examples\\label{subsec:Hard}\\<close>\n\n(*<*)\n\ntext \\<open>Other examples from @{cite SCT_POPL}. Example 3 is Ackermann, example 4\nis permutation. Example 5 are yet to be finished.\\<close>\n\nfun sct1_rev :: \\<open>'a list \\<Rightarrow> 'a list\\<close>\nand sct1_r1  :: \\<open>'a list \\<Rightarrow> 'a list \\<Rightarrow> 'a list\\<close> \nwhere\n  \\<open>sct1_rev ls = sct1_r1 ls []\\<close>\n| \\<open>sct1_r1 ls a = (if ls = [] then a else sct1_r1 (tl ls) ((hd ls)#a))\\<close>\n\nfun sct2_f :: \\<open>'a list \\<Rightarrow> 'a list \\<Rightarrow> 'a list\\<close>\nand sct2_g :: \\<open>'a list \\<Rightarrow> 'a list \\<Rightarrow> 'a list \\<Rightarrow> 'a list\\<close>\n  where\n  \\<open>sct2_f i x   = (if i = [] then x else (sct2_g (tl i) x i))\\<close>\n| \\<open>sct2_g a b c = sct2_f a (b @ c)\\<close>\n\nfunction sct5_f :: \\<open>'a list \\<Rightarrow> 'a list \\<Rightarrow> 'a list\\<close> where\n  \\<open>sct5_f x y = (if y = [] then x else if x = [] then sct5_f y (tl y) else sct5_f y (tl x))\\<close>\n  by (pat_completeness, auto)\n\nabbreviation sct5_f_wf_rel :: \\<open>(('a list \\<times> 'a list) \\<times> 'a list \\<times> 'a list) set\\<close> where\n  \\<open>sct5_f_wf_rel \\<equiv>\n   { ((y, tl y), (x, y)) | x y . y \\<noteq> [] \\<and> x = [] } \\<union> \n   { ((y, tl x), (x, y)) | x y . y \\<noteq> [] \\<and> x \\<noteq> [] }\\<close>\n\nlemma l_sct5__wf_rel_VDM_measure: \n  \\<open>sct5_f_wf_rel \\<subseteq> measure (\\<lambda> (x,y) . if y = [] then 0 else if x = [] then length y else length x + length y)\\<close>\n  apply (intro subsetI, case_tac x, case_tac a)\n    apply (simp add: case_prod_beta)\n  apply (elim disjE conjE, simp)  \n  nitpick\n  oops\n\n(*lemma l_sct5_f_wf: \\<open>wf sct5_f_wf_rel\\<close> \n  using l_sct5__wf_rel_VDM_measure \n  by (rule wf_subset [OF wf_measure])\n\ntermination\n  apply (relation sct5_f_wf_rel)\n  using l_sct5_f_wf apply blast\n  by simp+*)\n\nfun sct6_f :: \\<open>'a list \\<Rightarrow> 'a list \\<Rightarrow> 'a list\\<close> \nand sct6_g :: \\<open>'a list \\<Rightarrow> 'a list \\<Rightarrow> 'a list\\<close>\nwhere\n  \\<open>sct6_f a b = (if b = [] then sct6_g a [] else sct6_f ((hd b)#a) (tl b))\\<close>\n| \\<open>sct6_g c d = (if c = [] then d else sct6_g (tl c) ((hd c)#d))\\<close>\n\n(*>*)\n\ntext \\<open>We can handle all examples from~@{cite SCT_POPL}. We show here some that\nrequire an elaborate setup. For example, the permutation function shows\npermuting decreasing parameters with an involved measure. The precondition was\nrequired for finishing the termination proof and shows an example why proofs\nover \\<^typ>\\<open>\\<int>\\<close> can be harder. This illustrated how Isabelle (failed) proofs \nhelped to improve the VDM specification. \n%\n\\begin{vdmsl}[frame=none,basicstyle=\\ttfamily\\scriptsize]\n    perm: int * int * int -> int \n    perm(m,n,r) == if 0 < r then perm(m, r-1, n) \n              else if 0 < n then perm(r, n-1, m) else m\n    --@IsaMeasure({mk_(mk_(m, r-1, n), mk_(m,n,r)) | ... & 0 < r} union \n    --            {mk_(mk_(r, n-1, m), mk_(m,n,r)) | ... & not 0 < r and 0 < n})\n    pre ((0 < r or 0 < n) => m+n+r > 0)   measure maxs({m+n+r, 0});      \n\n    tak: int * int * int -> int\n    tak(x,y,z) == if x <= y then y  \n                  else           tak(tak(x-1,y,z), tak(y-1,z,x), tak(z-1,x,y))\n    measure is not yet specified;\n\\end{vdmsl}\\<close>\n\ndefinition pre_perm :: \\<open>VDMInt \\<Rightarrow> VDMInt \\<Rightarrow> VDMInt \\<Rightarrow> \\<bool>\\<close> where\n  \\<open>pre_perm m n r \\<equiv> ((0 < r \\<or> 0 < n) \\<longrightarrow> m+n+r > 0)\\<close>\nlemmas pre_perm_defs = pre_perm_def inv_VDMInt_def inv_True_def\n\nlemma l_pre_perm_trivial[simp]: \\<open>(pre_perm m n r) = ((0 < r \\<or> 0 < n) \\<longrightarrow> m+n+r > 0)\\<close> \\<^marker>\\<open>tag invisible\\<close>\n  unfolding pre_perm_def inv_VDMInt_def \\<^marker>\\<open>tag invisible\\<close>\n  by simp \\<^marker>\\<open>tag invisible\\<close>\n\nfunction (domintros) perm :: \\<open>VDMInt \\<Rightarrow> VDMInt \\<Rightarrow> VDMInt \\<Rightarrow> VDMInt\\<close> where\n  \\<open>perm m n r = (if pre_perm m n r then\n                                if 0 < r then perm m (r-1) n \n                           else if 0 < n then perm r (n-1) m else m\n                        else undefined)\\<close>\n  by (pat_completeness, auto) \\<^marker>\\<open>tag invisible\\<close>\n\n(*perm_wf_rel :: \\<open>((VDMInt \\<times> VDMInt \\<times> VDMInt) \\<times> (VDMInt \\<times> VDMInt \\<times> VDMInt)) VDMSet\\<close>\n  where*)\ndefinition \\<open>perm_wf_rel \\<equiv> \n   { ((m, r-1, n), (m, n, r)) | m r n . pre_perm m n r \\<and> 0 < r } \\<union> \n   { ((r, n-1, m), (m, n, r)) | m r n . pre_perm m n r \\<and> \\<not> 0 < r \\<and> 0 < n }\\<close>\n\ntext \\<open>Its measure relation contains elements for each recursive call, filtered\nfor the corresponding if-then case. The proof of well-foundedness of such\nmeasure relations involving multiple recursive calls require further proof\nengineering, which is stated in the next lemma.\\<close>\n\nlemma l_perm_wf_rel_VDM_measure: \n  \\<open>perm_wf_rel \\<subseteq> measure (\\<lambda> (m, r, n) . nat (max 0 (m+r+n)))\\<close>\nproof - \\<^marker>\\<open>tag invisible\\<close>\n   show ?thesis\n  apply (intro subsetI, case_tac x)\n    apply (simp add: perm_wf_rel_def case_prod_beta max_def)\n    apply (elim disjE conjE, simp) \n     apply (intro impI conjI, simp_all)\n    done\nqed\n\nlemma l_perm_wf_rel: \\<open>wf perm_wf_rel\\<close>\nproof - \\<^marker>\\<open>tag invisible\\<close>\n  from l_perm_wf_rel_VDM_measure show ?thesis\n  by (rule wf_subset [OF wf_measure])\nqed\n\ntext \\<open>The Isabelle \\<^term>\\<open>measure\\<close> definition projects the less-than ordered\ninverse image\\<^footnote>\\<open>That is, @{thm measure_def}. Inverse image is defined as @{thm\ninv_image_def}.\\<close> of a given function as the recursive measure relation. Here\nthe VDM-defined measure is given as such measure function projection. This\nhighlights to the VDM user the relationship (and differences) between VDM and\nIsabelle recursive measures.\n\nThe setup works here if the @{term pre_perm} specifically curbs negative\nsums of parameters. This was not immediately obvious. With the added\nprecondition the termination proof is discovered with @{command sledgehammer}.\\<close>\ntermination \\<^marker>\\<open>tag invisible\\<close>\n  apply (relation \\<open>perm_wf_rel\\<close>) \\<^marker>\\<open>tag invisible\\<close>\n    apply (simp add: l_perm_wf_rel) \\<^marker>\\<open>tag invisible\\<close>\n  by (simp_all add: perm_wf_rel_def)  \\<^marker>\\<open>tag invisible\\<close>\n\ntext \\<open>Finally, Takeuchi's\nfunction\\<^footnote>\\<open>\\<^url>\\<open>https://isabelle.in.tum.de/library/HOL/HOL-Examples/Functions.html\\<close>\\<close>,\nwhich contains both permutation and inner recursion is defined next, where the\nimportant part is the SCNP setup using multi-sets @{cite KrausSCNP}. That is\nneeded because ordered lexicographic products are not strong enough to capture\nthis type of recursion. It has not implicit precondition. The translation\nstrategy works for these definitions, yet stands little chance of finding\nproofs automatically.\\<close>\nfunction (domintros) tak :: \\<open>VDMInt \\<Rightarrow> VDMInt \\<Rightarrow> VDMInt \\<Rightarrow> VDMInt\\<close> where\n  \\<open>tak x y z = (if x \\<le> y then y else tak (tak (x-1) y z) (tak (y-1) z x) (tak (z-1) x y))\\<close>\n  by auto \\<^marker>\\<open>tag invisible\\<close>\n\ntext \\<open>Next is an example of how one has to keep domain predicates as \nassumptions prior to termination proofs.\\<close>\nlemma tak_pcorrect:\n  \\<open>tak_dom (x, y, z) \\<Longrightarrow> tak x y z = (if x \\<le> y then y else if y \\<le> z then z else x)\\<close>\n  thm tak.pinduct tak.psimps \\<^marker>\\<open>tag invisible\\<close>\n  apply (induction x y z rule: tak.pinduct) \\<^marker>\\<open>tag invisible\\<close>\n  by (simp add: tak.psimps) \\<^marker>\\<open>tag invisible\\<close>\n\ntext \\<open>Each case (including the non-recursive call) is represented in the SCNP\nsetup, and then their measure-lexicographic\\<^footnote>\\<open>The measure-lexicographic product\n\\<^term>\\<open>f <*mlex*> R\\<close> is represented as the inverse image of the lexicographic product @{thm\nmlex_prod_def}.\\<close> composition is used as the measure relation for the\ntermination proof.\\<close>\ndefinition tak_m1 where \\<open>tak_m1 = (\\<lambda>(x,y,z). if x \\<le> y then 0 else 1)\\<close>\ndefinition tak_m2 where \\<open>tak_m2 = (\\<lambda>(x,y,z). nat (Max {x, y, z} - Min {x, y, z}))\\<close>\ndefinition tak_m3 where \\<open>tak_m3 = (\\<lambda>(x,y,z). nat (x - Min {x, y, z}))\\<close>\n\n(*<*)\nlemma \\<open>(((x1,y1,z1),(x2,y2,z2)) \\<in> tak_m3 <*mlex*> {}) \\<longleftrightarrow> (nat (x1 - Min {x1, y1, z1}) < nat (x2 - Min {x2, y2, z2}))\\<close>\n  apply (simp add: mlex_iff)\n  unfolding tak_m3_def\n  (*apply (simp only: case_prod_beta fst_conv snd_conv) *)\n  by simp\n\nlemma \\<open>((x1,y1,z1),(x2,y2,z2)) \\<in> (tak_m2 <*mlex*> (tak_m3 <*mlex*> {}))\\<close>\n  apply (simp add: mlex_iff)\n  unfolding tak_m3_def tak_m2_def\n  apply (simp only: case_prod_beta fst_conv snd_conv, clarify)\n  oops\n\nlemma l_call1: \n  \\<open>x > y \\<Longrightarrow> ((x-1,y,z),(x,y,z)) \\<in> tak_m1 <*mlex*> (tak_m2 <*mlex*> (tak_m3 <*mlex*> {}))\\<close> \n  apply (simp add: mlex_iff)  \\<^marker>\\<open>tag invisible\\<close>\n  unfolding tak_m3_def tak_m2_def tak_m1_def \\<^marker>\\<open>tag invisible\\<close>\n  apply (simp add: case_prod_beta)\\<^marker>\\<open>tag invisible\\<close>\n  unfolding min_def max_def\\<^marker>\\<open>tag invisible\\<close>\n  by (simp_all split:if_splits)\\<^marker>\\<open>tag invisible\\<close>\n\nlemma l_call2:\n  \\<open>x > y \\<Longrightarrow> ((y-1,z,x),(x,y,z)) \\<in> tak_m1 <*mlex*> (tak_m2 <*mlex*> (tak_m3 <*mlex*> {}))\\<close>\n  apply (simp add: mlex_iff)\n  unfolding tak_m3_def tak_m2_def tak_m1_def\n  by (simp add: case_prod_beta)\n  \nlemma l_call3:\n  \\<open>x > y \\<Longrightarrow> ((z-1,x,y),(x,y,z)) \\<in> tak_m1 <*mlex*> (tak_m2 <*mlex*> (tak_m3 <*mlex*> {}))\\<close>\n  apply (simp add: mlex_iff)\n  unfolding tak_m3_def tak_m2_def tak_m1_def\n  by (simp add: case_prod_beta)\n  \nlemma l_call4:\n  \\<open>x >y \\<Longrightarrow>  tak_dom (z - 1, x, y) \\<Longrightarrow>\n       tak_dom (y - 1, z, x) \\<Longrightarrow>\n       tak_dom (x - 1, y, z) \\<Longrightarrow>\n       ((tak (x - 1) y z, tak (y - 1) z x, tak (z - 1) x y), x, y, z)\n       \\<in> tak_m1 <*mlex*> tak_m2 <*mlex*> tak_m3 <*mlex*> {}\\<close>\n  apply (simp add: mlex_iff)\n  apply (simp add: tak_pcorrect)\n  unfolding tak_m3_def tak_m2_def tak_m1_def \n  by (simp add: case_prod_beta)\n(*>*)\n\ntext \\<open>The termination proof uses the measure relation @{term \\<open>tak_m1 <*mlex*>\ntak_m2 <*mlex*> tak_m3 <*mlex*> {}\\<close>}. It requires user-defined lemmas for each\nof the four cases.\\<close>\ntermination \\<^marker>\\<open>tag invisible\\<close>\n  apply (relation \\<open>tak_m1 <*mlex*> tak_m2 <*mlex*> tak_m3 <*mlex*> {}\\<close>) \\<^marker>\\<open>tag invisible\\<close>\n      apply (simp add: wf_mlex) \\<^marker>\\<open>tag invisible\\<close>\n     apply (simp add: l_call1)\\<^marker>\\<open>tag invisible\\<close>\n     apply (simp add: l_call2)\\<^marker>\\<open>tag invisible\\<close>\n     apply (simp add: l_call3)\\<^marker>\\<open>tag invisible\\<close>\n  by (simp add: l_call4)\\<^marker>\\<open>tag invisible\\<close>\n\ntext \\<open>With the total version of induction and simplification rules are\navailable. Then, it is possible to prove its rather simpler equivalence.\\<close>\n\ntheorem tak_correct: \\<open>tak x y z = (if x \\<le> y then y else if y \\<le> z then z else x)\\<close>\n  by (induction x y z rule: tak.induct) auto\n\n(*---------------------------------------------------------------------------*)\nsubsection \\<open>Mutual recursion\\label{subsec:MutualRec}\\<close>\n\ntext \\<open>Finally, we handle mutual recursion. VDM has few bounds on mutually\nrecursive definitions. We reuse the VDM type checker cyclic-measure discovery\nalgorithm in order to deduce related recursive calls. Note this is not\ncomplete and may fail to discover involved recursive calls, such as those\nunder some lambda-term result, for example. If that recursive call graph\ndiscovery fails, then users have to annotate at least one of the mutually\nrecursive definitions with an \\<^verbatim>\\<open>@IsaMutualRec\\<close> annotation listing all expected\nfunction names involved.\n\nMutually recursive definitions proof obligations refer to each others\nmeasure functions. Isabelle requires all related functions to be given in a\nsingle definition, where Isabelle's sum (or union) types are used in the proof\nsetup. Where needed, termination proof setup will be involved and with limited \nautomation. Here is a simple example and its translation, which works with\n \\<^term>\\<open>fun\\<close> syntax, hence has no further proof obligation needs. Note that in \nthis case using \\<^term>\\<open>fun\\<close> syntax, we declare implicit preconditions as \nsimplification rules.\n%\n\\begin{vdmsl}[frame=none,basicstyle=\\ttfamily\\scriptsize]\n    --@IsaMutualRec({odd})\n    even: nat -> bool\n    even(n) == if n = 0 then true else odd(n-1) measure n;\n    \n    --@IsaMutualRec({even})\n    --@TheoremAttribte pre_even_def = {termination_simp}\n    odd: nat -> bool\n    odd(n) == if n = 0 then false else even(n-1) measure n;\n\\end{vdmsl}\n\\<close>\ndefinition pre_even :: \\<open>VDMNat \\<Rightarrow> \\<bool>\\<close> where [termination_simp]: \\<open>pre_even n \\<equiv> inv_VDMNat n\\<close> \ndefinition pre_odd  :: \\<open>VDMNat \\<Rightarrow> \\<bool>\\<close> where [termination_simp]: \\<open>pre_odd n \\<equiv> inv_VDMNat n\\<close> \nfun (domintros) even :: \\<open>VDMNat \\<Rightarrow> \\<bool>\\<close> and odd  :: \\<open>VDMNat \\<Rightarrow> \\<bool>\\<close> where \n  \\<open>even n = (if pre_even n then (if n = 0 then True else odd (n-1)) else undefined)\\<close>\n| \\<open>odd  n = (if pre_odd n then (if n = 0 then False else even (n-1)) else undefined)\\<close>\n\n(******************************************************************************)\nsection \\<open>Discussion and conclusion\\label{sec:Conclusion}\\<close>\n\ntext \\<open>This paper has presented a translation strategy from VDM to Isabelle for\nrecursive functions over basic types, sets and maps, as well as mutual\nrecursion. We present how the strategy works for complex recursion.\n\nThe complex recursion examples hint at possible VDM recursive measure\nextensions to use a combination of measure relations and functions. The full\nVDM and Isabelle sources and proofs can be found at the VDM toolkit repository\nat \\<^verbatim>\\<open>RecursiveVDM*.thy\\<close>\\<^footnote>\\<open>\\<^url>\\<open>https://github.com/leouk/VDM_Toolkit\\<close>\\<close>.\n\n\\<^bold>\\<open>Future work.\\<close>~We are implementing the translation strategy in the\n\\<^verbatim>\\<open>vdm2isa\\<close> plugin, which should be available soon.\n\n\\<^bold>\\<open>Acknowledgements.\\<close>~We appreciated discussions with Stephan Merz on pointers\nfor complex well-founded recursion proofs in Isabelle, and with Nick Battle on\nlimits for VDM recursive measures. Peter Gorm Larsen would also like to\nacknowledge the Poul Due Jensen Foundation for funding the project Digital\nTwins for Cyber-Physical Systems (DiT4CPS).\\<close>\n\n(*<*)\nlemma l_sumset_rel_wf': \\<open>wf sumset_wf_rel\\<close>\n  apply (rule wf_measure[of \\<open>\\<lambda> s . card s\\<close>, THEN wf_subset])\\<^marker>\\<open>tag invisible\\<close>\n  apply (simp add: measure_def inv_image_def less_than_def less_eq)\\<^marker>\\<open>tag invisible\\<close>\n  apply (rule subsetI, simp add: case_prod_beta)\\<^marker>\\<open>tag invisible\\<close>\n  apply (elim exE conjE)\\<^marker>\\<open>tag invisible\\<close>\n  by (metis card_Diff1_less_iff fst_conv inv_VDMMap_defs(2) inv_VDMMap_defs(3) \n        pre_sumset_defs(1) snd_conv some_in_eq)\\<^marker>\\<open>tag invisible\\<close>\n(*>*)\n\n(*<*)\nend\n(*>*)\n", "meta": {"author": "leouk", "repo": "VDM_Toolkit", "sha": "791013909961d45949fcd96d937ae18f0174c7ec", "save_path": "github-repos/isabelle/leouk-VDM_Toolkit", "path": "github-repos/isabelle/leouk-VDM_Toolkit/VDM_Toolkit-791013909961d45949fcd96d937ae18f0174c7ec/plugins/vdm2isa/pub/recursion/RecursiveVDM.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5467381667555713, "lm_q2_score": 0.476579651063676, "lm_q1q2_score": 0.2605642847355641}}
{"text": "theory MainHC\nimports Main\nbegin\n\n-- \"we need full proof object support to use translate_thm later on\"\nML {* proofs := 2 *}\n\ntype_synonym 'a partial = \"'a option\"\n\n(* negation of is_none *)\nprimrec defOp :: \"'a partial => bool\"\nwhere\n\"defOp None = False\" |\n\"defOp (Some x) = True\"\n\ndefinition makeTotal :: \"'a partial => 'a\"\nwhere \"makeTotal == the\"\n\ndefinition makePartial :: \"'a => 'a partial\"\nwhere \"makePartial == Some\"\n\n(* undefined is predefined *)\ndefinition undefinedOp :: \"'a partial\"\nwhere \"undefinedOp == None\"\n\n(* backward compatibility only *)\ndefinition noneOp :: \"'a partial\"\nwhere \"noneOp == undefinedOp\"\n\ndefinition restrictOp :: \"'a partial => bool => 'a partial\"\nwhere \"restrictOp a b == if b then a else undefinedOp\"\n\n(* utilities *)\ndefinition flip :: \"('a => 'b => 'c) => 'b => 'a => 'c\"\nwhere \"flip f a b == f b a\"\n\ndefinition uncurryOp :: \"('a => 'b => 'c) => 'a * 'b => 'c\"\nwhere \"uncurryOp f p == f (fst p) (snd p)\"\n\ndefinition curryOp :: \"('a * 'b => 'c) => 'a => 'b => 'c\"\nwhere \"curryOp f a b == f (a, b)\"\n\n(* map on pairs *)\ndefinition mapFst :: \"('a => 'b) => 'a * 'c => 'b * 'c\"\nwhere \"mapFst f p == (f (fst p), snd p)\"\n\ndefinition mapSnd :: \"('b => 'c) => 'a * 'b => 'a * 'c\"\nwhere \"mapSnd f p == (fst p, f (snd p))\"\n\n(* predefined HasCASL functions *)\ndefinition ifImplOp :: \"bool * bool => bool\"\nwhere \"ifImplOp p == snd p --> fst p\"\n\ndefinition existEqualOp :: \"'a partial => 'a partial => bool\"\n  (\"(_ =e=/ _)\" [50, 51] 50)\nwhere \"existEqualOp a b == defOp a & defOp b & makeTotal a = makeTotal b\"\n\ndefinition exEqualOp :: \"'a partial * 'a partial => bool\"\nwhere \"exEqualOp == uncurryOp existEqualOp\"\n\ndefinition strongEqualOp :: \"'a partial => 'a partial => bool\"\n  (\"(_ =s=/ _)\" [50, 51] 50)\nwhere \"strongEqualOp a b == a = b\"\n\ndefinition whenElseOp :: \"('a partial * bool) * 'a partial => 'a partial\"\nwhere \"whenElseOp t == case t of\n    (p, e) => if snd p then fst p else e\"\n\n(*resOp :: \"'a partial * 'b partial => 'a\"\n\"resOp p == makeTotal (restrictOp (fst p) (defOp (snd p)))\"*)\n\ndefinition resOp :: \"'a partial * 'b partial => 'a partial\"\nwhere  \"resOp p == restrictOp (fst p) (defOp (snd p))\"\n\n\n(* conversions *)\ndefinition lift2partial :: \"('a => 'b partial) => 'a partial => 'b partial\"\nwhere \"lift2partial f s == restrictOp (f (makeTotal s)) (defOp s)\"\n\ndefinition mapPartial :: \"('a => 'b) => 'a partial => 'b partial\"\nwhere \"mapPartial f s == restrictOp (makePartial (f (makeTotal s))) (defOp s)\"\n\ndefinition unpackPartial :: \"(('a => 'b) => 'c => 'd partial)\n            => ('a => 'b) partial => 'c => 'd partial\"\nwhere \"unpackPartial c s a == lift2partial (flip c a) s\"\n\ndefinition unpackBool :: \"(('a => 'b) => 'c => bool)\n            => ('a => 'b) partial => 'c => bool\"\nwhere \"unpackBool c s a == defOp s & c (makeTotal s) a\"\n\ndefinition unpack2partial :: \"(('a => 'b) => 'c => 'd)\n            => ('a => 'b) partial => 'c => 'd partial\"\nwhere \"unpack2partial c s a == mapPartial (flip c a) s\"\n\ndefinition unpack2bool :: \"(('a => 'b) => 'c => 'd)\n            => ('a => 'b) partial => 'c => bool\"\nwhere \"unpack2bool c s a == defOp s\"\n\ndefinition bool2partial :: \"bool => unit partial\"\nwhere \"bool2partial b == restrictOp (makePartial ()) b\"\n\ndefinition liftUnit2unit :: \"('a => 'b) => bool => bool\"\nwhere \"liftUnit2unit f b == b\"\n\ndefinition liftUnit2bool :: \"(unit => bool) => bool => bool\"\nwhere \"liftUnit2bool f b == b & f ()\"\n\ndefinition liftUnit2partial :: \"(unit => 'a partial) => bool => 'a partial\"\nwhere \"liftUnit2partial f b == restrictOp (f ()) b\"\n\ndefinition liftUnit :: \"(unit => 'a) => bool => 'a partial\"\nwhere \"liftUnit f b ==restrictOp (makePartial (f ())) b\"\n\ndefinition lift2unit :: \"('b => 'c) => ('a partial => bool)\"\nwhere \"lift2unit f == defOp\"\n\ndefinition lift2bool :: \"('a => bool) => 'a partial => bool\"\nwhere \"lift2bool f s == defOp s & f (makeTotal s)\"\n\n(* old stuff *)\nprimrec app :: \"('a => 'b option) option => 'a option => 'b option\"\nwhere\n  \"app None a = None\" |\n  \"app (Some f) x = (case x of\n                            None => None\n                          | Some x' => f x')\"\n\nprimrec apt :: \"('a => 'b) option => 'a option => 'b option\"\nwhere\n  \"apt None a = None\" |\n  \"apt (Some f) x = (case x of\n                            None => None\n                          | Some x' => Some (f x'))\"\n\nprimrec pApp :: \"('a => bool) option => 'a option => bool\"\nwhere\n  \"pApp None a = False\" |\n  \"pApp (Some f) x = (case x of\n                             None => False\n                           | Some y => f y)\"\n\nprimrec pair :: \"'a option => 'b option => ('a * 'b) option\"\nwhere\n  \"pair None a = None\" |\n  \"pair (Some x) z = (case z of\n                             None => None\n                           | Some y => Some (x,y))\"\n\nlemma some_inj : \"Some x = Some y ==> x = y\"\napply (auto)\ndone\n\n(* Monad law added by Lutz Schroeder *)\n\nlemma partial_monad_unit1[simp]: \"lift2partial f (makePartial a) = f a\"\napply (simp add: lift2partial_def makePartial_def restrictOp_def makeTotal_def)\ndone\n\nlemma partial_monad_unit2[simp]: \"lift2partial makePartial m = m\"\napply (auto simp add: lift2partial_def makePartial_def restrictOp_def makeTotal_def undefinedOp_def)\napply (case_tac \"m\")\napply (auto)\napply (case_tac \"m\")\napply (auto)\ndone\n\nlemma partial_monad_assoc[simp]:\n  \"lift2partial g (lift2partial f m) =\n  lift2partial (%x. lift2partial g (f x)) m\"\napply (simp add: lift2partial_def makePartial_def restrictOp_def makeTotal_def undefinedOp_def)\ndone\n\nlemma strictness_closure:\n  \"defOp (lift2partial f a) = (defOp (lift2partial f a) & defOp a)\"\napply (simp add: lift2partial_def makePartial_def restrictOp_def makeTotal_def undefinedOp_def)\ndone\n\n(*\n   Identities added by Ewaryst Schulz\n*)\n(*\nlemma defOp_implies_makePartial:\n\"defOp(x :: 'a partial) ==> (EX (y :: 'a). x = makePartial y)\"\n-- \"for isabelle 2009\"\n  by (rule Option.option.exhaust [of x], simp, simp add: exI makePartial_def)\n-- \"for isabelle 2008\"\n by (rule Datatype.option.exhaust [of x], simp, simp add: exI makePartial_def)\n-- \"for both versions:\"\n  sorry\n*)\n\naxiomatization\nwhere\ndefOp_implies_makePartial:\n\"defOp(x :: 'a partial) ==> (EX (y :: 'a). x = makePartial y)\"\n\n\n-- \"need this to expand a term for application of lemmas\"\nlemma partial_identity: \"!!x. makeTotal(makePartial(x)) = x\"\n  by (simp add: makeTotal_def makePartial_def)\n\naxiomatization\npreDefOp :: \"'a partial => bool\"\nwhere\npreDefOp_atom[simp]: \"preDefOp a = defOp a\"\nand\npreDefOp_lift[simp]:\n\"preDefOp (lift2partial f a) = (defOp (lift2partial f a) & preDefOp a)\"\n\n\nend\n", "meta": {"author": "spechub", "repo": "Hets-lib", "sha": "7bed416952e7000e2fa37f0b6071b5291b299b77", "save_path": "github-repos/isabelle/spechub-Hets-lib", "path": "github-repos/isabelle/spechub-Hets-lib/Hets-lib-7bed416952e7000e2fa37f0b6071b5291b299b77/Isabelle/MainHC.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.2605642776960263}}
{"text": "(*  Title:      HOL/Library/Phantom_Type.thy\n    Author:     Andreas Lochbihler\n*)\n\nsection \\<open>A generic phantom type\\<close>\n\ntheory Phantom_Type\nimports Main\nbegin\n\ndatatype ('a, 'b) phantom = phantom (of_phantom: 'b)\n\nlemma type_definition_phantom': \"type_definition of_phantom phantom UNIV\"\nby(unfold_locales) simp_all\n\nlemma phantom_comp_of_phantom [simp]: \"phantom \\<circ> of_phantom = id\"\n  and of_phantom_comp_phantom [simp]: \"of_phantom \\<circ> phantom = id\"\nby(simp_all add: o_def id_def)\n\nsyntax \"_Phantom\" :: \"type \\<Rightarrow> logic\" (\"(1Phantom/(1'(_')))\")\ntranslations\n  \"Phantom('t)\" => \"CONST phantom :: _ \\<Rightarrow> ('t, _) phantom\"\n\ntyped_print_translation \\<open>\n  let\n    fun phantom_tr' ctxt (Type (\\<^type_name>\\<open>fun\\<close>, [_, Type (\\<^type_name>\\<open>phantom\\<close>, [T, _])])) ts =\n          list_comb\n            (Syntax.const \\<^syntax_const>\\<open>_Phantom\\<close> $ Syntax_Phases.term_of_typ ctxt T, ts)\n      | phantom_tr' _ _ _ = raise Match;\n  in [(\\<^const_syntax>\\<open>phantom\\<close>, phantom_tr')] end\n\\<close>\n\nlemma of_phantom_inject [simp]:\n  \"of_phantom x = of_phantom y \\<longleftrightarrow> x = y\"\nby(cases x y rule: phantom.exhaust[case_product phantom.exhaust]) simp\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/Library/Phantom_Type.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.2605642776960263}}
{"text": "section {*L\\_ATS\\_Language*}\ntheory\n  L_ATS_Language\n\nimports\n  L_ATS_Language0\n\nbegin\n\nlocale ATS_Language =\n  ATS_Language0\n  \"TSstructure :: 'TSstructure \\<Rightarrow> bool\"\n  \"configurations :: 'TSstructure \\<Rightarrow> 'conf set\"\n  \"initial_configurations :: 'TSstructure \\<Rightarrow> 'conf set\"\n  \"step_labels :: 'TSstructure \\<Rightarrow> 'label set\"\n  \"step_relation :: 'TSstructure \\<Rightarrow> 'conf \\<Rightarrow> 'label \\<Rightarrow> 'conf \\<Rightarrow> bool\"\n  \"effects :: 'TSstructure \\<Rightarrow> 'event set\"\n  \"marking_condition :: 'TSstructure \\<Rightarrow> ('label,'conf)derivation \\<Rightarrow> bool\"\n  \"marked_effect :: 'TSstructure \\<Rightarrow> ('label,'conf)derivation \\<Rightarrow> 'event set\"\n  \"unmarked_effect :: 'TSstructure \\<Rightarrow> ('label,'conf)derivation \\<Rightarrow> 'event set\"\n  for\n    TSstructure configurations initial_configurations step_labels step_relation effects marking_condition marked_effect unmarked_effect\n    +\n\nassumes AX_effect_inclusion1: \"\n  TSstructure G\n  \\<Longrightarrow> derivation_initial G d\n  \\<Longrightarrow> marking_condition G d\n  \\<Longrightarrow> marked_effect G d \\<subseteq> unmarked_effect G d\"\n\nassumes AX_effect_inclusion2: \"\n  TSstructure G\n  \\<Longrightarrow> unmarked_language G \\<subseteq> effects G\"\n\nassumes AX_marking_condition_implies_existence_of_effect: \"\n  TSstructure G\n  \\<Longrightarrow> derivation_initial G d\n  \\<Longrightarrow> marking_condition G d\n  \\<Longrightarrow> marked_effect G d \\<noteq> {}\"\n\nassumes AX_unmarked_effect_persists: \"\n  TSstructure G\n  \\<Longrightarrow> derivation_initial G d\n  \\<Longrightarrow> unmarked_effect G (derivation_take d n) \\<subseteq> unmarked_effect G d\"\n\ncontext ATS_Language\nbegin\n\nlemma lang_inclusion: \"\n  TSstructure M\n  \\<Longrightarrow> marked_language M \\<subseteq> unmarked_language M\"\n  apply(simp add: marked_language_def unmarked_language_def)\n  apply(clarsimp)\n  apply(rename_tac x d)(*strict*)\n  apply(rule_tac\n      x=\"d\"\n      in exI)\n  apply(clarsimp)\n  apply(rule_tac\n      A=\"marked_effect M d\"\n      in set_mp)\n   apply(rename_tac x d)(*strict*)\n   apply(rule AX_effect_inclusion1)\n     apply(rename_tac x d)(*strict*)\n     apply(auto)\n  done\n\nlemma Nonblockingness_branching_implies_non_empty_lang: \"\n  TSstructure G\n  \\<Longrightarrow> Nonblockingness_branching G\n  \\<Longrightarrow> marked_language G = {}\n  \\<Longrightarrow> c \\<in> initial_configurations G\n  \\<Longrightarrow> Q\"\n  apply(simp add: Nonblockingness_branching_def)\n  apply(erule_tac\n      x=\"der1 c\"\n      in allE)\n  apply(subgoal_tac \"derivation_initial G (der1 c) \\<and> maximum_of_domain (der1 c) 0\")\n   apply(clarsimp)\n   prefer 2\n   apply(simp add: derivation_initial_def)\n   apply(rule conjI)\n    apply(rule der1_is_derivation)\n   apply(simp add: maximum_of_domain_def der1_def)\n  apply(erule_tac\n      x=\"0\"\n      in allE)\n  apply(erule impE)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac dc x)(*strict*)\n  apply(simp add: marked_language_def)\n  apply(subgoal_tac \"derivation_initial G (derivation_append (der1 c) dc 0)\")\n   apply(rename_tac dc x)(*strict*)\n   prefer 2\n   apply(rule derivation_append_preserves_derivation_initial)\n     apply(rename_tac dc x)(*strict*)\n     apply(force)\n    apply(rename_tac dc x)(*strict*)\n    apply(force)\n   apply(rename_tac dc x)(*strict*)\n   apply(rule derivation_append_preserves_derivation)\n     apply(rename_tac dc x)(*strict*)\n     apply(simp add: derivation_initial_def)\n    apply(rename_tac dc x)(*strict*)\n    apply(force)\n   apply(rename_tac dc x)(*strict*)\n   apply(simp add: der1_def)\n   apply(case_tac \"dc 0\")\n    apply(rename_tac dc x)(*strict*)\n    apply(clarsimp)\n    apply(simp add: derivation_def derivation_append_fit_def)\n   apply(rename_tac dc x a)(*strict*)\n   apply(simp add: derivation_def derivation_append_fit_def)\n   apply(case_tac a)\n   apply(rename_tac dc x a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac dc x option b)(*strict*)\n   apply(case_tac option)\n    apply(rename_tac dc x option b)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac dc x option b a)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac dc x)(*strict*)\n  apply(subgoal_tac \"marked_effect G (derivation_append (der1 c) dc 0) \\<noteq> {}\")\n   apply(rename_tac dc x)(*strict*)\n   prefer 2\n   apply(rule AX_marking_condition_implies_existence_of_effect)\n     apply(rename_tac dc x)(*strict*)\n     apply(force)\n    apply(rename_tac dc x)(*strict*)\n    apply(force)\n   apply(rename_tac dc x)(*strict*)\n   apply(force)\n  apply(rename_tac dc x)(*strict*)\n  apply(subgoal_tac \"\\<exists>x. x \\<in> marked_effect G (derivation_append (der1 c) dc 0)\")\n   apply(rename_tac dc x)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac dc x)(*strict*)\n  apply(thin_tac \"marked_effect G (derivation_append (der1 c) dc 0)\\<noteq>{}\")\n  apply(clarsimp)\n  apply(rename_tac dc x xa)(*strict*)\n  apply(erule_tac\n      x=\"xa\"\n      in allE)\n  apply(erule_tac\n      x=\"derivation_append (der1 c) dc 0\"\n      in allE)\n  apply(clarsimp)\n  apply(simp add: derivation_initial_def)\n  done\n\nend\n\nend\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_06_01/L_ATS_Language.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526660244837, "lm_q2_score": 0.45713671682749485, "lm_q1q2_score": 0.2605005768218274}}
{"text": "(*  Title:      HOL/Auth/n_mesi_on_inis.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mesi Protocol Case Study*} \n\ntheory n_mesi_on_inis imports n_mesi_on_ini\nbegin\nlemma on_inis:\n  assumes b1: \"f \\<in> (invariants N)\" and b2: \"ini \\<in> {andList (allInitSpecs N)}\" and b3: \"formEval ini s\"\n  shows \"formEval f s\"\n  proof -\n  have c1: \"(\\<exists> p__Inv0 p__Inv2. p__Inv0\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv0~=p__Inv2\\<and>f=inv__1  p__Inv0 p__Inv2)\\<or>\n    (\\<exists> p__Inv0 p__Inv2. p__Inv0\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv0~=p__Inv2\\<and>f=inv__2  p__Inv0 p__Inv2)\\<or>\n    (\\<exists> p__Inv0 p__Inv2. p__Inv0\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv0~=p__Inv2\\<and>f=inv__3  p__Inv0 p__Inv2)\"\n  apply (cut_tac b1, simp) done\n    moreover {\n      assume d1: \"(\\<exists> p__Inv0 p__Inv2. p__Inv0\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv0~=p__Inv2\\<and>f=inv__1  p__Inv0 p__Inv2)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__1)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> p__Inv0 p__Inv2. p__Inv0\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv0~=p__Inv2\\<and>f=inv__2  p__Inv0 p__Inv2)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__2)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> p__Inv0 p__Inv2. p__Inv0\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv0~=p__Inv2\\<and>f=inv__3  p__Inv0 p__Inv2)\"\n      have \"formEval f s\"\n      apply (rule iniImply_inv__3)\n      apply (cut_tac d1, assumption)\n      apply (cut_tac b2 b3, blast) done\n    }\n\n  ultimately show \"formEval f s\"\n  by satx\nqed\n\nend\n", "meta": {"author": "paraVerifier", "repo": "paraVerifier", "sha": "5de62b433a160bf8d714e0a5085a38b9dd8899f0", "save_path": "github-repos/isabelle/paraVerifier-paraVerifier", "path": "github-repos/isabelle/paraVerifier-paraVerifier/paraVerifier-5de62b433a160bf8d714e0a5085a38b9dd8899f0/proof_scripts/mesi/n_mesi_on_inis.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526514141571, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.2605005701429106}}
{"text": "section \\<open>Definition of the CFG\\<close>\n\ntheory PCFG imports ProcState begin\n\ndefinition Main :: \"pname\"\n  where \"Main = ''Main''\"\n\ndatatype label = Label nat | Entry | Exit\n\nsubsection\\<open>The CFG for every procedure\\<close>\n\nsubsubsection \\<open>Definition of \\<open>\\<oplus>\\<close>\\<close>\n\nfun label_incr :: \"label \\<Rightarrow> nat \\<Rightarrow> label\" (\"_ \\<oplus> _\" 60)\nwhere \"(Label l) \\<oplus> i = Label (l + i)\"\n  | \"Entry \\<oplus> i       = Entry\"\n  | \"Exit \\<oplus> i        = Exit\"\n\n\nlemma Exit_label_incr [dest]: \"Exit = n \\<oplus> i \\<Longrightarrow> n = Exit\"\n  by(cases n,auto)\n\nlemma label_incr_Exit [dest]: \"n \\<oplus> i = Exit \\<Longrightarrow> n = Exit\"\n  by(cases n,auto)\n\nlemma Entry_label_incr [dest]: \"Entry = n \\<oplus> i \\<Longrightarrow> n = Entry\"\n  by(cases n,auto)\n\nlemma label_incr_Entry [dest]: \"n \\<oplus> i = Entry \\<Longrightarrow> n = Entry\"\n  by(cases n,auto)\n\nlemma label_incr_inj:\n  \"n \\<oplus> c = n' \\<oplus> c \\<Longrightarrow> n = n'\"\nby(cases n)(cases n',auto)+\n\nlemma label_incr_simp:\"n \\<oplus> i = m \\<oplus> (i + j) \\<Longrightarrow> n = m \\<oplus> j\"\nby(cases n,auto,cases m,auto)\n\n\n\nlemma label_incr_start_Node_smaller:\n  \"Label l = n \\<oplus> i \\<Longrightarrow> n = Label (l - i)\"\nby(cases n,auto)\n\nlemma label_incr_start_Node_smaller_rev:\n  \"n \\<oplus> i = Label l \\<Longrightarrow> n = Label (l - i)\"\nby(cases n,auto)\n\n\nlemma label_incr_ge:\"Label l = n \\<oplus> i \\<Longrightarrow> l \\<ge> i\"\nby(cases n) auto\n\nlemma label_incr_0 [dest]:\n  \"\\<lbrakk>Label 0 = n \\<oplus> i; i > 0\\<rbrakk> \\<Longrightarrow> False\" \nby(cases n) auto\n\nlemma label_incr_0_rev [dest]:\n  \"\\<lbrakk>n \\<oplus> i = Label 0; i > 0\\<rbrakk> \\<Longrightarrow> False\" \nby(cases n) auto\n\nsubsubsection \\<open>The edges of the procedure CFG\\<close>\n\ntext \\<open>Control flow information in this language is the node, to which we return\n  after the calles procedure is finished.\\<close>\n\ndatatype p_edge_kind = \n  IEdge \"(vname,val,pname \\<times> label,pname) edge_kind\"\n| CEdge \"pname \\<times> expr list \\<times> vname list\"\n\n\ntype_synonym p_edge = \"(label \\<times> p_edge_kind \\<times> label)\"\n\ninductive Proc_CFG :: \"cmd \\<Rightarrow> label \\<Rightarrow> p_edge_kind \\<Rightarrow> label \\<Rightarrow> bool\"\n(\"_ \\<turnstile> _ -_\\<rightarrow>\\<^sub>p _\")\nwhere\n\n  Proc_CFG_Entry_Exit:\n  \"prog \\<turnstile> Entry -IEdge (\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow>\\<^sub>p Exit\"\n\n| Proc_CFG_Entry:\n  \"prog \\<turnstile> Entry -IEdge (\\<lambda>s. True)\\<^sub>\\<surd>\\<rightarrow>\\<^sub>p Label 0\"\n\n| Proc_CFG_Skip: \n  \"Skip \\<turnstile> Label 0 -IEdge \\<Up>id\\<rightarrow>\\<^sub>p Exit\"\n\n| Proc_CFG_LAss: \n  \"V:=e \\<turnstile> Label 0 -IEdge \\<Up>(\\<lambda>cf. update cf V e)\\<rightarrow>\\<^sub>p Label 1\"\n\n| Proc_CFG_LAssSkip:\n  \"V:=e \\<turnstile> Label 1 -IEdge \\<Up>id\\<rightarrow>\\<^sub>p Exit\"\n\n| Proc_CFG_SeqFirst:\n  \"\\<lbrakk>c\\<^sub>1 \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'; n' \\<noteq> Exit\\<rbrakk> \\<Longrightarrow> c\\<^sub>1;;c\\<^sub>2 \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'\"\n\n| Proc_CFG_SeqConnect: \n  \"\\<lbrakk>c\\<^sub>1 \\<turnstile> n -et\\<rightarrow>\\<^sub>p Exit; n \\<noteq> Entry\\<rbrakk> \\<Longrightarrow> c\\<^sub>1;;c\\<^sub>2 \\<turnstile> n -et\\<rightarrow>\\<^sub>p Label #:c\\<^sub>1\"\n\n| Proc_CFG_SeqSecond: \n  \"\\<lbrakk>c\\<^sub>2 \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'; n \\<noteq> Entry\\<rbrakk> \\<Longrightarrow> c\\<^sub>1;;c\\<^sub>2 \\<turnstile> n \\<oplus> #:c\\<^sub>1 -et\\<rightarrow>\\<^sub>p n' \\<oplus> #:c\\<^sub>1\"\n\n| Proc_CFG_CondTrue:\n    \"if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> Label 0 \n  -IEdge (\\<lambda>cf. state_check cf b (Some true))\\<^sub>\\<surd>\\<rightarrow>\\<^sub>p Label 1\"\n\n| Proc_CFG_CondFalse:\n    \"if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> Label 0 -IEdge (\\<lambda>cf. state_check cf b (Some false))\\<^sub>\\<surd>\\<rightarrow>\\<^sub>p \n                        Label (#:c\\<^sub>1 + 1)\"\n\n| Proc_CFG_CondThen:\n  \"\\<lbrakk>c\\<^sub>1 \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'; n \\<noteq> Entry\\<rbrakk> \\<Longrightarrow> if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> n \\<oplus> 1 -et\\<rightarrow>\\<^sub>p n' \\<oplus> 1\"\n\n| Proc_CFG_CondElse:\n  \"\\<lbrakk>c\\<^sub>2 \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'; n \\<noteq> Entry\\<rbrakk> \n  \\<Longrightarrow> if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> n \\<oplus> (#:c\\<^sub>1 + 1) -et\\<rightarrow>\\<^sub>p n' \\<oplus> (#:c\\<^sub>1 + 1)\"\n\n| Proc_CFG_WhileTrue:\n    \"while (b) c' \\<turnstile> Label 0 -IEdge (\\<lambda>cf. state_check cf b (Some true))\\<^sub>\\<surd>\\<rightarrow>\\<^sub>p Label 2\"\n\n| Proc_CFG_WhileFalse:\n    \"while (b) c' \\<turnstile> Label 0 -IEdge (\\<lambda>cf. state_check cf b (Some false))\\<^sub>\\<surd>\\<rightarrow>\\<^sub>p Label 1\"\n\n| Proc_CFG_WhileFalseSkip:\n  \"while (b) c' \\<turnstile> Label 1 -IEdge \\<Up>id\\<rightarrow>\\<^sub>p Exit\"\n\n| Proc_CFG_WhileBody:\n  \"\\<lbrakk>c' \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'; n \\<noteq> Entry; n' \\<noteq> Exit\\<rbrakk> \n  \\<Longrightarrow> while (b) c' \\<turnstile> n \\<oplus> 2 -et\\<rightarrow>\\<^sub>p n' \\<oplus> 2\"\n\n| Proc_CFG_WhileBodyExit:\n  \"\\<lbrakk>c' \\<turnstile> n -et\\<rightarrow>\\<^sub>p Exit; n \\<noteq> Entry\\<rbrakk> \\<Longrightarrow> while (b) c' \\<turnstile> n \\<oplus> 2 -et\\<rightarrow>\\<^sub>p Label 0\"\n\n| Proc_CFG_Call:\n  \"Call p es rets \\<turnstile> Label 0 -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p Label 1\"\n\n| Proc_CFG_CallSkip:\n  \"Call p es rets \\<turnstile> Label 1 -IEdge \\<Up>id\\<rightarrow>\\<^sub>p Exit\"\n\n\nsubsubsection\\<open>Some lemmas about the procedure CFG\\<close>\n\nlemma Proc_CFG_Exit_no_sourcenode [dest]:\n  \"prog \\<turnstile> Exit -et\\<rightarrow>\\<^sub>p n' \\<Longrightarrow> False\"\nby(induct prog n\\<equiv>\"Exit\" et n' rule:Proc_CFG.induct,auto)\n\n\nlemma Proc_CFG_Entry_no_targetnode [dest]:\n  \"prog \\<turnstile> n -et\\<rightarrow>\\<^sub>p Entry \\<Longrightarrow> False\"\nby(induct prog n et n'\\<equiv>\"Entry\" rule:Proc_CFG.induct,auto)\n\n\nlemma Proc_CFG_IEdge_intra_kind:\n  \"prog \\<turnstile> n -IEdge et\\<rightarrow>\\<^sub>p n' \\<Longrightarrow> intra_kind et\"\nby(induct prog n x\\<equiv>\"IEdge et\" n' rule:Proc_CFG.induct,auto simp:intra_kind_def)\n\n\nlemma [dest]:\"prog \\<turnstile> n -IEdge (Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs)\\<rightarrow>\\<^sub>p n' \\<Longrightarrow> False\"\nby(fastforce dest:Proc_CFG_IEdge_intra_kind simp:intra_kind_def)\n\nlemma [dest]:\"prog \\<turnstile> n -IEdge (Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f)\\<rightarrow>\\<^sub>p n' \\<Longrightarrow> False\"\nby(fastforce dest:Proc_CFG_IEdge_intra_kind simp:intra_kind_def)\n\n\nlemma Proc_CFG_sourcelabel_less_num_nodes:\n  \"prog \\<turnstile> Label l -et\\<rightarrow>\\<^sub>p n' \\<Longrightarrow> l < #:prog\"\nproof(induct prog \"Label l\" et n' arbitrary:l rule:Proc_CFG.induct)\n  case (Proc_CFG_SeqFirst c\\<^sub>1 et n' c\\<^sub>2 l)\n  thus ?case by simp\nnext\n  case (Proc_CFG_SeqConnect c\\<^sub>1 et c\\<^sub>2 l)\n  thus ?case by simp\nnext\n  case (Proc_CFG_SeqSecond c\\<^sub>2 n et n' c\\<^sub>1 l) \n  note n = \\<open>n \\<oplus> #:c\\<^sub>1 = Label l\\<close> \n  note IH = \\<open>\\<And>l. n = Label l \\<Longrightarrow> l < #:c\\<^sub>2\\<close>\n  from n obtain l' where l':\"n = Label l'\" by(cases n) auto\n  from IH[OF this] have \"l' < #:c\\<^sub>2\" .\n  with n l' show ?case by simp\nnext\n  case (Proc_CFG_CondThen c\\<^sub>1 n et n' b c\\<^sub>2 l) \n  note n = \\<open>n \\<oplus> 1 = Label l\\<close>\n  note IH = \\<open>\\<And>l. n = Label l \\<Longrightarrow> l < #:c\\<^sub>1\\<close>\n  from n obtain l' where l':\"n = Label l'\" by(cases n) auto\n  from IH[OF this] have \"l' < #:c\\<^sub>1\" .\n  with n l' show ?case by simp\nnext\n  case (Proc_CFG_CondElse c\\<^sub>2 n et n' b c\\<^sub>1 l)\n  note n = \\<open>n \\<oplus> (#:c\\<^sub>1 + 1) = Label l\\<close>\n  note IH = \\<open>\\<And>l. n = Label l \\<Longrightarrow> l < #:c\\<^sub>2\\<close>\n  from n obtain l' where l':\"n = Label l'\" by(cases n) auto\n  from IH[OF this] have \"l' < #:c\\<^sub>2\" .\n  with n l' show ?case by simp\nnext\n  case (Proc_CFG_WhileBody c' n et n' b l)\n  note n = \\<open>n \\<oplus> 2 = Label l\\<close> \n  note IH = \\<open>\\<And>l. n = Label l \\<Longrightarrow> l < #:c'\\<close>\n  from n obtain l' where l':\"n = Label l'\" by(cases n) auto\n  from IH[OF this] have \"l' < #:c'\" .\n  with n l' show ?case by simp\nnext\n  case (Proc_CFG_WhileBodyExit c' n et b l)\n  note n = \\<open>n \\<oplus> 2 = Label l\\<close> \n  note IH = \\<open>\\<And>l. n = Label l \\<Longrightarrow> l < #:c'\\<close>\n  from n obtain l' where l':\"n = Label l'\" by(cases n) auto\n  from IH[OF this] have \"l' < #:c'\" .\n  with n l' show ?case by simp\nqed (auto simp:num_inner_nodes_gr_0)\n\n\nlemma Proc_CFG_targetlabel_less_num_nodes:\n  \"prog \\<turnstile> n -et\\<rightarrow>\\<^sub>p Label l \\<Longrightarrow> l < #:prog\"\nproof(induct prog n et \"Label l\" arbitrary:l rule:Proc_CFG.induct)\n  case (Proc_CFG_SeqFirst c\\<^sub>1 n et c\\<^sub>2 l)\n thus ?case by simp\nnext\n  case (Proc_CFG_SeqSecond c\\<^sub>2 n et n' c\\<^sub>1 l)\n  note n' = \\<open>n' \\<oplus> #:c\\<^sub>1 = Label l\\<close> \n  note IH = \\<open>\\<And>l. n' = Label l \\<Longrightarrow> l < #:c\\<^sub>2\\<close>\n  from n' obtain l' where l':\"n' = Label l'\" by(cases n') auto\n  from IH[OF this] have \"l' < #:c\\<^sub>2\" .\n  with n' l' show ?case by simp\nnext\n  case (Proc_CFG_CondThen c\\<^sub>1 n et n' b c\\<^sub>2 l)\n  note n' = \\<open>n' \\<oplus> 1 = Label l\\<close> \n  note IH = \\<open>\\<And>l. n' = Label l \\<Longrightarrow> l < #:c\\<^sub>1\\<close>\n  from n' obtain l' where l':\"n' = Label l'\" by(cases n') auto\n  from IH[OF this] have \"l' < #:c\\<^sub>1\" .\n  with n' l' show ?case by simp\nnext\n  case (Proc_CFG_CondElse c\\<^sub>2 n et n' b c\\<^sub>1 l)\n  note n' = \\<open>n' \\<oplus> (#:c\\<^sub>1 + 1) = Label l\\<close> \n  note IH = \\<open>\\<And>l. n' = Label l \\<Longrightarrow> l < #:c\\<^sub>2\\<close>\n  from n' obtain l' where l':\"n' = Label l'\" by(cases n') auto\n  from IH[OF this] have \"l' < #:c\\<^sub>2\" .\n  with n' l' show ?case by simp\nnext\n  case (Proc_CFG_WhileBody c' n et n' b l)\n  note n' = \\<open>n' \\<oplus> 2 = Label l\\<close> \nnote IH = \\<open>\\<And>l. n' = Label l \\<Longrightarrow> l < #:c'\\<close>\n  from n' obtain l' where l':\"n' = Label l'\" by(cases n') auto\n  from IH[OF this] have \"l' < #:c'\" .\n  with n' l' show ?case by simp\nqed (auto simp:num_inner_nodes_gr_0)\n\n\nlemma Proc_CFG_EntryD:\n  \"prog \\<turnstile> Entry -et\\<rightarrow>\\<^sub>p n' \n  \\<Longrightarrow> (n' = Exit \\<and> et = IEdge(\\<lambda>s. False)\\<^sub>\\<surd>) \\<or> (n' = Label 0 \\<and> et = IEdge (\\<lambda>s. True)\\<^sub>\\<surd>)\"\nby(induct prog n\\<equiv>\"Entry\" et n' rule:Proc_CFG.induct,auto)\n\n\n\n\n\ntext \\<open>Lots of lemmas for call edges \\<open>\\<dots>\\<close>\\<close>\n\nlemma Proc_CFG_Call_Labels:\n  \"prog \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n' \\<Longrightarrow> \\<exists>l. n = Label l \\<and> n' = Label (Suc l)\"\nby(induct prog n et\\<equiv>\"CEdge (p,es,rets)\" n' rule:Proc_CFG.induct,auto)\n\n\nlemma Proc_CFG_Call_target_0:\n  \"prog \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p Label 0 \\<Longrightarrow> n = Entry\"\nby(induct prog n et\\<equiv>\"CEdge (p,es,rets)\" n'\\<equiv>\"Label 0\" rule:Proc_CFG.induct)\n  (auto dest:Proc_CFG_Call_Labels)\n\n\nlemma Proc_CFG_Call_Intra_edge_not_same_source:\n  \"\\<lbrakk>prog \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'; prog \\<turnstile> n -IEdge et\\<rightarrow>\\<^sub>p n''\\<rbrakk> \\<Longrightarrow> False\"\nproof(induct prog n \"CEdge (p,es,rets)\" n' arbitrary:n'' rule:Proc_CFG.induct)\n  case (Proc_CFG_SeqFirst c\\<^sub>1 n n' c\\<^sub>2)\n  note IH = \\<open>\\<And>n''. c\\<^sub>1 \\<turnstile> n -IEdge et\\<rightarrow>\\<^sub>p n'' \\<Longrightarrow> False\\<close>\n  from \\<open>c\\<^sub>1;;c\\<^sub>2 \\<turnstile> n -IEdge et\\<rightarrow>\\<^sub>p n''\\<close> \\<open>c\\<^sub>1 \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n'\\<close> \n    \\<open>n' \\<noteq> Exit\\<close>\n  obtain nx where \"c\\<^sub>1 \\<turnstile> n -IEdge et\\<rightarrow>\\<^sub>p nx\"\n    apply - apply(erule Proc_CFG.cases)\n    apply(auto intro:Proc_CFG_Entry_Exit Proc_CFG_Entry)\n    by(case_tac n)(auto dest:Proc_CFG_sourcelabel_less_num_nodes)\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_SeqConnect c\\<^sub>1 n c\\<^sub>2)\n  from \\<open>c\\<^sub>1 \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p Exit\\<close>\n  show ?case by(fastforce dest:Proc_CFG_Call_Labels)\nnext\n  case (Proc_CFG_SeqSecond c\\<^sub>2 n n' c\\<^sub>1)\n  note IH = \\<open>\\<And>n''. c\\<^sub>2 \\<turnstile> n -IEdge et\\<rightarrow>\\<^sub>p n'' \\<Longrightarrow> False\\<close>\n  from \\<open>c\\<^sub>1;;c\\<^sub>2 \\<turnstile> n \\<oplus> #:c\\<^sub>1 -IEdge et\\<rightarrow>\\<^sub>p n''\\<close> \\<open>c\\<^sub>2 \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n'\\<close> \n    \\<open>n \\<noteq> Entry\\<close>\n  obtain nx where \"c\\<^sub>2 \\<turnstile> n -IEdge et\\<rightarrow>\\<^sub>p nx\"\n    apply - apply(erule Proc_CFG.cases,auto)\n      apply(cases n) apply(auto dest:Proc_CFG_sourcelabel_less_num_nodes)\n     apply(cases n) apply(auto dest:Proc_CFG_sourcelabel_less_num_nodes)\n    by(cases n,auto,case_tac n,auto)\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_CondThen c\\<^sub>1 n n' b c\\<^sub>2)\n  note IH = \\<open>\\<And>n''. c\\<^sub>1 \\<turnstile> n -IEdge et\\<rightarrow>\\<^sub>p n'' \\<Longrightarrow> False\\<close>\n  from \\<open>if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> n \\<oplus> 1 -IEdge et\\<rightarrow>\\<^sub>p n''\\<close> \\<open>c\\<^sub>1 \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n'\\<close>\n    \\<open>n \\<noteq> Entry\\<close>\n  obtain nx where \"c\\<^sub>1 \\<turnstile> n -IEdge et\\<rightarrow>\\<^sub>p nx\"\n    apply - apply(erule Proc_CFG.cases,auto)\n     apply(cases n) apply auto apply(case_tac n) apply auto\n    apply(cases n) apply auto\n    by(case_tac n)(auto dest:Proc_CFG_sourcelabel_less_num_nodes)\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_CondElse c\\<^sub>2 n n' b c\\<^sub>1)\n  note IH = \\<open>\\<And>n''. c\\<^sub>2 \\<turnstile> n -IEdge et\\<rightarrow>\\<^sub>p n'' \\<Longrightarrow> False\\<close>\n  from \\<open>if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> n \\<oplus> #:c\\<^sub>1 + 1 -IEdge et\\<rightarrow>\\<^sub>p n''\\<close> \\<open>c\\<^sub>2 \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n'\\<close>\n    \\<open>n \\<noteq> Entry\\<close>\n  obtain nx where \"c\\<^sub>2 \\<turnstile> n -IEdge et\\<rightarrow>\\<^sub>p nx\"\n    apply - apply(erule Proc_CFG.cases,auto)\n     apply(cases n) apply auto\n     apply(case_tac n) apply(auto dest:Proc_CFG_sourcelabel_less_num_nodes)\n    by(cases n,auto,case_tac n,auto)\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_WhileBody c' n n' b)\n  note IH = \\<open>\\<And>n''. c' \\<turnstile> n -IEdge et\\<rightarrow>\\<^sub>p n'' \\<Longrightarrow> False\\<close>\n  from \\<open>while (b) c' \\<turnstile> n \\<oplus> 2 -IEdge et\\<rightarrow>\\<^sub>p n''\\<close> \\<open>c' \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n'\\<close>\n    \\<open>n \\<noteq> Entry\\<close> \\<open>n' \\<noteq> Exit\\<close>\n  obtain nx where \"c' \\<turnstile> n -IEdge et\\<rightarrow>\\<^sub>p nx\"\n    apply - apply(erule Proc_CFG.cases,auto)\n      apply(drule label_incr_ge[OF sym]) apply simp\n     apply(cases n) apply auto apply(case_tac n) apply auto\n    by(cases n,auto,case_tac n,auto)\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_WhileBodyExit c' n b)\n  from \\<open>c' \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p Exit\\<close>\n  show ?case by(fastforce dest:Proc_CFG_Call_Labels)\nnext\n  case Proc_CFG_Call\n  from \\<open>Call p es rets \\<turnstile> Label 0 -IEdge et\\<rightarrow>\\<^sub>p n''\\<close>\n  show ?case by(fastforce elim:Proc_CFG.cases)\nqed\n\n\nlemma Proc_CFG_Call_Intra_edge_not_same_target:\n  \"\\<lbrakk>prog \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'; prog \\<turnstile> n'' -IEdge et\\<rightarrow>\\<^sub>p n'\\<rbrakk> \\<Longrightarrow> False\"\nproof(induct prog n \"CEdge (p,es,rets)\" n' arbitrary:n'' rule:Proc_CFG.induct)\n  case (Proc_CFG_SeqFirst c\\<^sub>1 n n' c\\<^sub>2)\n  note IH = \\<open>\\<And>n''. c\\<^sub>1 \\<turnstile> n'' -IEdge et\\<rightarrow>\\<^sub>p n' \\<Longrightarrow> False\\<close>\n  from \\<open>c\\<^sub>1;;c\\<^sub>2 \\<turnstile> n'' -IEdge et\\<rightarrow>\\<^sub>p n'\\<close> \\<open>c\\<^sub>1 \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n'\\<close> \n    \\<open>n' \\<noteq> Exit\\<close>\n  have \"c\\<^sub>1 \\<turnstile> n'' -IEdge et\\<rightarrow>\\<^sub>p n'\"\n    apply - apply(erule Proc_CFG.cases)\n    apply(auto intro:Proc_CFG_Entry dest:Proc_CFG_targetlabel_less_num_nodes) \n    by(case_tac n')(auto dest:Proc_CFG_targetlabel_less_num_nodes)\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_SeqConnect c\\<^sub>1 n c\\<^sub>2)\n  from \\<open>c\\<^sub>1 \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p Exit\\<close>\n  show ?case by(fastforce dest:Proc_CFG_Call_Labels)\nnext\n  case (Proc_CFG_SeqSecond c\\<^sub>2 n n' c\\<^sub>1)\n  note IH = \\<open>\\<And>n''. c\\<^sub>2 \\<turnstile> n'' -IEdge et\\<rightarrow>\\<^sub>p n' \\<Longrightarrow> False\\<close>\n  from \\<open>c\\<^sub>1;;c\\<^sub>2 \\<turnstile> n'' -IEdge et\\<rightarrow>\\<^sub>p n' \\<oplus> #:c\\<^sub>1\\<close> \\<open>c\\<^sub>2 \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n'\\<close> \n    \\<open>n \\<noteq> Entry\\<close>\n  obtain nx where \"c\\<^sub>2 \\<turnstile> nx -IEdge et\\<rightarrow>\\<^sub>p n'\"\n    apply - apply(erule Proc_CFG.cases,auto)\n       apply(fastforce intro:Proc_CFG_Entry_Exit)\n      apply(cases n') apply(auto dest:Proc_CFG_targetlabel_less_num_nodes)\n     apply(cases n') apply(auto dest:Proc_CFG_Call_target_0)\n    apply(cases n') apply(auto dest:Proc_CFG_Call_Labels)\n    by(case_tac n') auto\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_CondThen c\\<^sub>1 n n' b c\\<^sub>2)\n  note IH = \\<open>\\<And>n''. c\\<^sub>1 \\<turnstile> n'' -IEdge et\\<rightarrow>\\<^sub>p n' \\<Longrightarrow> False\\<close>\n  from \\<open>if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> n'' -IEdge et\\<rightarrow>\\<^sub>p n' \\<oplus> 1\\<close> \\<open>c\\<^sub>1 \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n'\\<close>\n    \\<open>n \\<noteq> Entry\\<close>\n  obtain nx where \"c\\<^sub>1 \\<turnstile> nx -IEdge et\\<rightarrow>\\<^sub>p n'\"\n    apply - apply(erule Proc_CFG.cases,auto)\n        apply(cases n') apply(auto intro:Proc_CFG_Entry_Exit)\n       apply(cases n') apply(auto dest:Proc_CFG_Call_target_0)\n      apply(cases n') apply(auto dest:Proc_CFG_targetlabel_less_num_nodes)\n     apply(cases n') apply auto apply(case_tac n') apply auto\n    apply(cases n') apply auto\n    apply(case_tac n') apply(auto dest:Proc_CFG_targetlabel_less_num_nodes)\n    by(case_tac n')(auto dest:Proc_CFG_Call_Labels)\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_CondElse c\\<^sub>2 n n' b c\\<^sub>1)\n  note IH = \\<open>\\<And>n''. c\\<^sub>2 \\<turnstile> n'' -IEdge et\\<rightarrow>\\<^sub>p n' \\<Longrightarrow> False\\<close>\n  from \\<open>if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> n'' -IEdge et\\<rightarrow>\\<^sub>p n' \\<oplus> #:c\\<^sub>1 + 1\\<close> \\<open>c\\<^sub>2 \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n'\\<close>\n    \\<open>n \\<noteq> Entry\\<close>\n  obtain nx where \"c\\<^sub>2 \\<turnstile> nx -IEdge et\\<rightarrow>\\<^sub>p n'\"\n    apply - apply(erule Proc_CFG.cases,auto)\n        apply(cases n') apply(auto intro:Proc_CFG_Entry_Exit)\n       apply(cases n') apply(auto dest:Proc_CFG_Call_target_0)\n      apply(cases n') apply(auto dest:Proc_CFG_Call_target_0)\n     apply(cases n') apply auto\n      apply(case_tac n') apply(auto dest:Proc_CFG_targetlabel_less_num_nodes)\n     apply(case_tac n') apply(auto dest:Proc_CFG_Call_Labels)\n    by(cases n',auto,case_tac n',auto)\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_WhileBody c' n n' b)\n  note IH = \\<open>\\<And>n''. c' \\<turnstile> n'' -IEdge et\\<rightarrow>\\<^sub>p n' \\<Longrightarrow> False\\<close>\n  from \\<open>while (b) c' \\<turnstile> n'' -IEdge et\\<rightarrow>\\<^sub>p n' \\<oplus> 2\\<close> \\<open>c' \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p n'\\<close>\n    \\<open>n \\<noteq> Entry\\<close> \\<open>n' \\<noteq> Exit\\<close>\n  obtain nx where \"c' \\<turnstile> nx -IEdge et\\<rightarrow>\\<^sub>p n'\"\n    apply - apply(erule Proc_CFG.cases,auto)\n      apply(cases n') apply(auto dest:Proc_CFG_Call_target_0)\n     apply(cases n') apply auto\n    by(cases n',auto,case_tac n',auto)\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_WhileBodyExit c' n b)\n  from \\<open>c' \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p Exit\\<close>\n  show ?case by(fastforce dest:Proc_CFG_Call_Labels)\nnext\n  case Proc_CFG_Call\n  from \\<open>Call p es rets \\<turnstile> n'' -IEdge et\\<rightarrow>\\<^sub>p Label 1\\<close>\n  show ?case by(fastforce elim:Proc_CFG.cases)\nqed\n\n\nlemma Proc_CFG_Call_nodes_eq:\n  \"\\<lbrakk>prog \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'; prog \\<turnstile> n -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n''\\<rbrakk>\n  \\<Longrightarrow> n' = n'' \\<and> p = p' \\<and> es = es' \\<and> rets = rets'\"\nproof(induct prog n \"CEdge (p,es,rets)\" n' arbitrary:n'' rule:Proc_CFG.induct)\n  case (Proc_CFG_SeqFirst c\\<^sub>1 n n' c\\<^sub>2)\n  note IH = \\<open>\\<And>n''. c\\<^sub>1 \\<turnstile> n -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n''\n    \\<Longrightarrow> n' = n'' \\<and> p = p' \\<and> es = es' \\<and> rets = rets'\\<close>\n  from \\<open>c\\<^sub>1;; c\\<^sub>2 \\<turnstile> n -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n''\\<close> \\<open>c\\<^sub>1 \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'\\<close>\n  have \"c\\<^sub>1 \\<turnstile> n -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n''\"\n    apply - apply(erule Proc_CFG.cases,auto)\n     apply(fastforce dest:Proc_CFG_Call_Labels)\n    by(case_tac n,(fastforce dest:Proc_CFG_sourcelabel_less_num_nodes)+)\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_SeqConnect c\\<^sub>1 n c\\<^sub>2)\n  from \\<open>c\\<^sub>1 \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p Exit\\<close> have False\n    by(fastforce dest:Proc_CFG_Call_Labels)\n  thus ?case by simp\nnext\n  case (Proc_CFG_SeqSecond c\\<^sub>2 n n' c\\<^sub>1)\n  note IH = \\<open>\\<And>n''. c\\<^sub>2 \\<turnstile> n -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n''\n    \\<Longrightarrow> n' = n'' \\<and> p = p' \\<and> es = es' \\<and> rets = rets'\\<close>\n  from \\<open>c\\<^sub>1;;c\\<^sub>2 \\<turnstile> n \\<oplus> #:c\\<^sub>1 -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n''\\<close> \\<open>n \\<noteq> Entry\\<close>\n  obtain nx where edge:\"c\\<^sub>2 \\<turnstile> n -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p nx\" and nx:\"nx \\<oplus> #:c\\<^sub>1 = n''\"\n    apply - apply(erule Proc_CFG.cases,auto)\n    by(cases n,auto dest:Proc_CFG_sourcelabel_less_num_nodes label_incr_inj)+\n  from edge have \"n' = nx \\<and> p = p' \\<and> es = es' \\<and> rets = rets'\" by (rule IH)\n  with nx show ?case by auto\nnext\n  case (Proc_CFG_CondThen c\\<^sub>1 n n' b c\\<^sub>2)\n  note IH = \\<open>\\<And>n''. c\\<^sub>1 \\<turnstile> n -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n''\n    \\<Longrightarrow> n' = n'' \\<and> p = p' \\<and> es = es' \\<and> rets = rets'\\<close>\n  from \\<open>if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> n \\<oplus> 1 -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n''\\<close>\n  obtain nx where \"c\\<^sub>1 \\<turnstile> n -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p nx \\<and> nx \\<oplus> 1 = n''\"\n  proof(rule Proc_CFG.cases)\n    fix c\\<^sub>2' nx etx nx' bx c\\<^sub>1'\n    assume \"if (b) c\\<^sub>1 else c\\<^sub>2 = if (bx) c\\<^sub>1' else c\\<^sub>2'\"\n      and \"n \\<oplus> 1 = nx \\<oplus> #:c\\<^sub>1' + 1\" and \"nx \\<noteq> Entry\"\n    with \\<open>c\\<^sub>1 \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'\\<close> obtain l where \"n = Label l\" and \"l \\<ge> #:c\\<^sub>1\"\n      by(cases n,auto,cases nx,auto)\n    with \\<open>c\\<^sub>1 \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'\\<close> have False\n      by(fastforce dest:Proc_CFG_sourcelabel_less_num_nodes)\n    thus ?thesis by simp\n  qed (auto dest:label_incr_inj)\n  then obtain nx where edge:\"c\\<^sub>1 \\<turnstile> n -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p nx\" \n    and nx:\"nx \\<oplus> 1 = n''\" by blast\n  from IH[OF edge] nx show ?case by simp\nnext\n  case (Proc_CFG_CondElse c\\<^sub>2 n n' b c\\<^sub>1)\n  note IH = \\<open>\\<And>n''. c\\<^sub>2 \\<turnstile> n -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n''\n    \\<Longrightarrow> n' = n'' \\<and> p = p' \\<and> es = es' \\<and> rets = rets'\\<close>\n  from \\<open>if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> n \\<oplus> #:c\\<^sub>1 + 1 -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n''\\<close>\n  obtain nx where \"c\\<^sub>2 \\<turnstile> n -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p nx \\<and> nx \\<oplus> #:c\\<^sub>1 + 1 = n''\"\n  proof(rule Proc_CFG.cases)\n    fix c\\<^sub>1' nx etx nx' bx c\\<^sub>2'\n    assume ifs:\"if (b) c\\<^sub>1 else c\\<^sub>2 = if (bx) c\\<^sub>1' else c\\<^sub>2'\"\n      and \"n \\<oplus> #:c\\<^sub>1 + 1 = nx \\<oplus> 1\" and \"nx \\<noteq> Entry\"\n      and edge:\"c\\<^sub>1' \\<turnstile> nx -etx\\<rightarrow>\\<^sub>p nx'\"\n    then obtain l where \"nx = Label l\" and \"l \\<ge> #:c\\<^sub>1\"\n      by(cases n,auto,cases nx,auto)\n    with edge ifs have False\n      by(fastforce dest:Proc_CFG_sourcelabel_less_num_nodes)\n    thus ?thesis by simp\n  qed (auto dest:label_incr_inj)\n  then obtain nx where edge:\"c\\<^sub>2 \\<turnstile> n -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p nx\"\n    and nx:\"nx \\<oplus> #:c\\<^sub>1 + 1 = n''\"\n    by blast\n  from IH[OF edge] nx show ?case by simp\nnext\n  case (Proc_CFG_WhileBody c' n n' b)\n  note IH = \\<open>\\<And>n''. c' \\<turnstile> n -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n''\n    \\<Longrightarrow> n' = n'' \\<and> p = p' \\<and> es = es' \\<and> rets = rets'\\<close>\n  from \\<open>while (b) c' \\<turnstile> n \\<oplus> 2 -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n''\\<close>\n  obtain nx where \"c' \\<turnstile> n -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p nx \\<and> nx \\<oplus> 2 = n''\"\n    by(rule Proc_CFG.cases,auto dest:label_incr_inj Proc_CFG_Call_Labels)\n  then obtain nx where edge:\"c' \\<turnstile> n -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p nx\" \n    and nx:\"nx \\<oplus> 2 = n''\" by blast\n  from IH[OF edge] nx show ?case by simp\nnext\n  case (Proc_CFG_WhileBodyExit c' n b)\n  from \\<open>c' \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p Exit\\<close> have False\n    by(fastforce dest:Proc_CFG_Call_Labels)\n  thus ?case by simp\nnext\n  case Proc_CFG_Call\n  from \\<open>Call p es rets \\<turnstile> Label 0 -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n''\\<close>\n  have \"p = p' \\<and> es = es' \\<and> rets = rets' \\<and> n'' = Label 1\"\n    by(auto elim:Proc_CFG.cases)\n  then show ?case by simp\nqed\n\n\nlemma Proc_CFG_Call_nodes_eq':\n  \"\\<lbrakk>prog \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'; prog \\<turnstile> n'' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n'\\<rbrakk>\n  \\<Longrightarrow> n = n'' \\<and> p = p' \\<and> es = es' \\<and> rets = rets'\"\nproof(induct prog n \"CEdge (p,es,rets)\" n' arbitrary:n'' rule:Proc_CFG.induct)\n  case (Proc_CFG_SeqFirst c\\<^sub>1 n n' c\\<^sub>2)\n  note IH = \\<open>\\<And>n''. c\\<^sub>1 \\<turnstile> n'' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n'\n    \\<Longrightarrow> n = n'' \\<and> p = p' \\<and> es = es' \\<and> rets = rets'\\<close>\n  from \\<open>c\\<^sub>1;;c\\<^sub>2 \\<turnstile> n'' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n'\\<close> \\<open>c\\<^sub>1 \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'\\<close>\n  have \"c\\<^sub>1 \\<turnstile> n'' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n'\"\n    apply - apply(erule Proc_CFG.cases,auto)\n     apply(fastforce dest:Proc_CFG_Call_Labels)\n    by(case_tac n',auto dest:Proc_CFG_targetlabel_less_num_nodes Proc_CFG_Call_Labels)\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_SeqConnect c\\<^sub>1 n c\\<^sub>2)\n  from \\<open>c\\<^sub>1 \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p Exit\\<close> have False\n    by(fastforce dest:Proc_CFG_Call_Labels)\n  thus ?case by simp\nnext\n  case (Proc_CFG_SeqSecond c\\<^sub>2 n n' c\\<^sub>1)\n  note IH = \\<open>\\<And>n''. c\\<^sub>2 \\<turnstile> n'' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n'\n    \\<Longrightarrow> n = n'' \\<and> p = p' \\<and> es = es' \\<and> rets = rets'\\<close>\n  from \\<open>c\\<^sub>1;;c\\<^sub>2 \\<turnstile> n'' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n' \\<oplus> #:c\\<^sub>1\\<close>\n  obtain nx where edge:\"c\\<^sub>2 \\<turnstile> nx -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n'\" and nx:\"nx \\<oplus> #:c\\<^sub>1 = n''\"\n    apply - apply(erule Proc_CFG.cases,auto)\n    by(cases n',\n       auto dest:Proc_CFG_targetlabel_less_num_nodes Proc_CFG_Call_Labels \n                 label_incr_inj)\n  from edge have \"n = nx \\<and> p = p' \\<and> es = es' \\<and> rets = rets'\" by (rule IH)\n  with nx show ?case by auto\nnext\n  case (Proc_CFG_CondThen c\\<^sub>1 n n' b c\\<^sub>2)\n  note IH = \\<open>\\<And>n''. c\\<^sub>1 \\<turnstile> n'' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n'\n    \\<Longrightarrow> n = n'' \\<and> p = p' \\<and> es = es' \\<and> rets = rets'\\<close>\n  from \\<open>if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> n'' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n' \\<oplus> 1\\<close>\n  obtain nx where \"c\\<^sub>1 \\<turnstile> nx -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n' \\<and> nx \\<oplus> 1 = n''\"\n  proof(cases)\n    case (Proc_CFG_CondElse nx nx')\n    from \\<open>n' \\<oplus> 1 = nx' \\<oplus> #:c\\<^sub>1 + 1\\<close>\n      \\<open>c\\<^sub>1 \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'\\<close>\n    obtain l where \"n' = Label l\" and \"l \\<ge> #:c\\<^sub>1\"\n      by(cases n', auto dest:Proc_CFG_Call_Labels,cases nx',auto)\n    with \\<open>c\\<^sub>1 \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'\\<close> have False\n      by(fastforce dest:Proc_CFG_targetlabel_less_num_nodes)\n    thus ?thesis by simp\n  qed (auto dest:label_incr_inj)\n  then obtain nx where edge:\"c\\<^sub>1 \\<turnstile> nx -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n'\" \n    and nx:\"nx \\<oplus> 1 = n''\"\n    by blast\n  from IH[OF edge] nx show ?case by simp\nnext\n  case (Proc_CFG_CondElse c\\<^sub>2 n n' b c\\<^sub>1)\n  note IH = \\<open>\\<And>n''. c\\<^sub>2 \\<turnstile> n'' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n'\n    \\<Longrightarrow> n = n'' \\<and> p = p' \\<and> es = es' \\<and> rets = rets'\\<close>\n  from \\<open>if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> n'' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n' \\<oplus> #:c\\<^sub>1 + 1\\<close>\n  obtain nx where \"c\\<^sub>2 \\<turnstile> nx -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n' \\<and> nx \\<oplus> #:c\\<^sub>1 + 1 = n''\"\n  proof(cases)\n    case (Proc_CFG_CondThen nx nx')\n    from \\<open>n' \\<oplus> #:c\\<^sub>1 + 1 = nx' \\<oplus> 1\\<close>\n      \\<open>c\\<^sub>1 \\<turnstile> nx -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p nx'\\<close>\n    obtain l where \"nx' = Label l\" and \"l \\<ge> #:c\\<^sub>1\"\n      by(cases n',auto,cases nx',auto dest:Proc_CFG_Call_Labels)\n    with \\<open>c\\<^sub>1 \\<turnstile> nx -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p nx'\\<close>\n    have False by(fastforce dest:Proc_CFG_targetlabel_less_num_nodes)\n    thus ?thesis by simp\n  qed (auto dest:label_incr_inj)\n  then obtain nx where edge:\"c\\<^sub>2 \\<turnstile> nx -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n'\" \n    and nx:\"nx \\<oplus> #:c\\<^sub>1 + 1 = n''\"\n    by blast\n  from IH[OF edge] nx show ?case by simp\nnext\n  case (Proc_CFG_WhileBody c' n n' b)\n  note IH = \\<open>\\<And>n''. c' \\<turnstile> n'' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n'\n    \\<Longrightarrow> n = n'' \\<and> p = p' \\<and> es = es' \\<and> rets = rets'\\<close>\n  from \\<open>while (b) c' \\<turnstile> n'' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n' \\<oplus> 2\\<close>\n  obtain nx where edge:\"c' \\<turnstile> nx -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n'\" and nx:\"nx \\<oplus> 2 = n''\"\n    by(rule Proc_CFG.cases,auto dest:label_incr_inj)\n  from IH[OF edge] nx show ?case by simp\nnext\n  case (Proc_CFG_WhileBodyExit c' n b)\n  from \\<open>c' \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p Exit\\<close>\n  have False by(fastforce dest:Proc_CFG_Call_Labels)\n  thus ?case by simp\nnext\n  case Proc_CFG_Call\n  from \\<open>Call p es rets \\<turnstile> n'' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p Label 1\\<close>\n  have \"p = p' \\<and> es = es' \\<and> rets = rets' \\<and> n'' = Label 0\"\n    by(auto elim:Proc_CFG.cases)\n  then show ?case by simp\nqed\n\n\nlemma Proc_CFG_Call_targetnode_no_Call_sourcenode:\n  \"\\<lbrakk>prog \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'; prog \\<turnstile> n' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n''\\<rbrakk> \n  \\<Longrightarrow> False\"\nproof(induct prog n \"CEdge (p,es,rets)\" n' arbitrary:n'' rule:Proc_CFG.induct)\n  case (Proc_CFG_SeqFirst c\\<^sub>1 n n' c\\<^sub>2)\n  note IH = \\<open>\\<And>n''. c\\<^sub>1 \\<turnstile> n' -CEdge (p', es', rets')\\<rightarrow>\\<^sub>p n'' \\<Longrightarrow> False\\<close>\n  from \\<open>c\\<^sub>1;; c\\<^sub>2 \\<turnstile> n' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n''\\<close> \\<open>c\\<^sub>1 \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'\\<close>\n  have \"c\\<^sub>1 \\<turnstile> n' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n''\"\n    apply - apply(erule Proc_CFG.cases,auto)\n     apply(fastforce dest:Proc_CFG_Call_Labels)\n    by(case_tac n)(auto dest:Proc_CFG_targetlabel_less_num_nodes)\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_SeqConnect c\\<^sub>1 n c\\<^sub>2)\n  from \\<open>c\\<^sub>1 \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p Exit\\<close> have False\n    by(fastforce dest:Proc_CFG_Call_Labels)\n  thus ?case by simp\nnext\n  case (Proc_CFG_SeqSecond c\\<^sub>2 n n' c\\<^sub>1)\n  note IH = \\<open>\\<And>n''. c\\<^sub>2 \\<turnstile> n' -CEdge (p', es', rets')\\<rightarrow>\\<^sub>p n'' \\<Longrightarrow> False\\<close>\n  from \\<open>c\\<^sub>1;; c\\<^sub>2 \\<turnstile> n' \\<oplus> #:c\\<^sub>1 -CEdge (p', es', rets')\\<rightarrow>\\<^sub>p n''\\<close> \\<open>c\\<^sub>2 \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'\\<close>\n  obtain nx where \"c\\<^sub>2 \\<turnstile> n' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p nx\"\n    apply - apply(erule Proc_CFG.cases,auto)\n      apply(cases n') apply(auto dest:Proc_CFG_sourcelabel_less_num_nodes)\n     apply(fastforce dest:Proc_CFG_Call_Labels)\n    by(cases n',auto,case_tac n,auto)\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_CondThen c\\<^sub>1 n n' b c\\<^sub>2)\n  note IH = \\<open>\\<And>n''. c\\<^sub>1 \\<turnstile> n' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n'' \\<Longrightarrow> False\\<close>\n  from \\<open>if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> n' \\<oplus> 1 -CEdge (p', es', rets')\\<rightarrow>\\<^sub>p n''\\<close> \\<open>c\\<^sub>1 \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'\\<close>\n  obtain nx where \"c\\<^sub>1 \\<turnstile> n' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p nx\"\n    apply - apply(erule Proc_CFG.cases,auto)\n     apply(cases n') apply auto apply(case_tac n) apply auto\n    apply(cases n') apply auto\n    by(case_tac n)(auto dest:Proc_CFG_targetlabel_less_num_nodes)\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_CondElse c\\<^sub>2 n n' b c\\<^sub>1)\n  note IH = \\<open>\\<And>n''. c\\<^sub>2 \\<turnstile> n' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n'' \\<Longrightarrow> False\\<close>\n  from \\<open>if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> n' \\<oplus> #:c\\<^sub>1 + 1 -CEdge (p', es', rets')\\<rightarrow>\\<^sub>p n''\\<close> \n    \\<open>c\\<^sub>2 \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'\\<close>\n  obtain nx where \"c\\<^sub>2 \\<turnstile> n' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p nx\"\n    apply - apply(erule Proc_CFG.cases,auto)\n     apply(cases n') apply auto\n     apply(case_tac n) apply(auto dest:Proc_CFG_sourcelabel_less_num_nodes)\n    by(cases n',auto,case_tac n,auto)\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_WhileBody c' n n' b)\n  note IH = \\<open>\\<And>n''. c' \\<turnstile> n' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n'' \\<Longrightarrow> False\\<close>\n  from \\<open>while (b) c' \\<turnstile> n' \\<oplus> 2 -CEdge (p', es', rets')\\<rightarrow>\\<^sub>p n''\\<close> \\<open>c' \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'\\<close>\n  obtain nx where \"c' \\<turnstile> n' -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p nx\"\n    apply - apply(erule Proc_CFG.cases,auto)\n    by(cases n',auto,case_tac n,auto)+\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_WhileBodyExit c' n b)\n  from \\<open>c' \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p Exit\\<close> \n  show ?case by(fastforce dest:Proc_CFG_Call_Labels)\nnext\n  case Proc_CFG_Call\n  from \\<open>Call p es rets \\<turnstile> Label 1 -CEdge (p', es', rets')\\<rightarrow>\\<^sub>p n''\\<close>\n  show ?case by(fastforce elim:Proc_CFG.cases)\nqed\n\n\nlemma Proc_CFG_Call_follows_id_edge:\n  \"\\<lbrakk>prog \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'; prog \\<turnstile> n' -IEdge et\\<rightarrow>\\<^sub>p n''\\<rbrakk> \\<Longrightarrow> et = \\<Up>id\"\nproof(induct prog n \"CEdge (p,es,rets)\" n' arbitrary:n'' rule:Proc_CFG.induct)\n  case (Proc_CFG_SeqFirst c\\<^sub>1 n n' c\\<^sub>2)\n  note IH = \\<open>\\<And>n''. c\\<^sub>1 \\<turnstile> n' -IEdge et\\<rightarrow>\\<^sub>p n'' \\<Longrightarrow> et = \\<Up>id\\<close>\n  from \\<open>c\\<^sub>1;;c\\<^sub>2 \\<turnstile> n' -IEdge et\\<rightarrow>\\<^sub>p n''\\<close> \\<open>c\\<^sub>1 \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'\\<close> \\<open>n' \\<noteq> Exit\\<close>\n  obtain nx where \"c\\<^sub>1 \\<turnstile> n' -IEdge et\\<rightarrow>\\<^sub>p nx\"\n    apply - apply(erule Proc_CFG.cases,auto)\n    by(case_tac n)(auto dest:Proc_CFG_targetlabel_less_num_nodes)\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_SeqConnect c\\<^sub>1 n c\\<^sub>2)\n  from \\<open>c\\<^sub>1 \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p Exit\\<close>\n  show ?case by(fastforce dest:Proc_CFG_Call_Labels)\nnext\n  case (Proc_CFG_SeqSecond c\\<^sub>2 n n' c\\<^sub>1)\n  note IH = \\<open>\\<And>n''. c\\<^sub>2 \\<turnstile> n' -IEdge et\\<rightarrow>\\<^sub>p n'' \\<Longrightarrow> et = \\<Up>id\\<close>\n  from \\<open>c\\<^sub>1;;c\\<^sub>2 \\<turnstile> n' \\<oplus> #:c\\<^sub>1 -IEdge et\\<rightarrow>\\<^sub>p n''\\<close> \\<open>c\\<^sub>2 \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'\\<close>\n  obtain nx where \"c\\<^sub>2 \\<turnstile> n' -IEdge et\\<rightarrow>\\<^sub>p nx\"\n    apply - apply(erule Proc_CFG.cases,auto)\n      apply(cases n') apply(auto dest:Proc_CFG_sourcelabel_less_num_nodes)\n     apply(cases n') apply(auto dest:Proc_CFG_sourcelabel_less_num_nodes)\n    by(cases n',auto,case_tac n,auto)\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_CondThen c\\<^sub>1 n n' b c\\<^sub>2)\n  note IH = \\<open>\\<And>n''. c\\<^sub>1 \\<turnstile> n' -IEdge et\\<rightarrow>\\<^sub>p n'' \\<Longrightarrow> et = \\<Up>id\\<close>\n  from \\<open>if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> n' \\<oplus> 1 -IEdge et\\<rightarrow>\\<^sub>p n''\\<close> \\<open>c\\<^sub>1 \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'\\<close>\n    \\<open>n \\<noteq> Entry\\<close>\n  obtain nx where \"c\\<^sub>1 \\<turnstile> n' -IEdge et\\<rightarrow>\\<^sub>p nx\"\n    apply - apply(erule Proc_CFG.cases,auto)\n     apply(cases n') apply auto apply(case_tac n) apply auto\n    apply(cases n') apply auto\n    by(case_tac n)(auto dest:Proc_CFG_targetlabel_less_num_nodes)\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_CondElse c\\<^sub>2 n n' b c\\<^sub>1)\n  note IH = \\<open>\\<And>n''. c\\<^sub>2 \\<turnstile> n' -IEdge et\\<rightarrow>\\<^sub>p n'' \\<Longrightarrow> et = \\<Up>id\\<close>\n  from \\<open>if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> n' \\<oplus> #:c\\<^sub>1 + 1 -IEdge et\\<rightarrow>\\<^sub>p n''\\<close> \\<open>c\\<^sub>2 \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'\\<close>\n  obtain nx where \"c\\<^sub>2 \\<turnstile> n' -IEdge et\\<rightarrow>\\<^sub>p nx\"\n    apply - apply(erule Proc_CFG.cases,auto)\n     apply(cases n') apply auto\n     apply(case_tac n) apply(auto dest:Proc_CFG_sourcelabel_less_num_nodes)\n    by(cases n',auto,case_tac n,auto)\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_WhileBody c' n n' b)\n  note IH = \\<open>\\<And>n''. c' \\<turnstile> n' -IEdge et\\<rightarrow>\\<^sub>p n'' \\<Longrightarrow> et = \\<Up>id\\<close>\n  from \\<open>while (b) c' \\<turnstile> n' \\<oplus> 2 -IEdge et\\<rightarrow>\\<^sub>p n''\\<close> \\<open>c' \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'\\<close>\n  obtain nx where \"c' \\<turnstile> n' -IEdge et\\<rightarrow>\\<^sub>p nx\"\n    apply - apply(erule Proc_CFG.cases,auto)\n      apply(cases n') apply auto\n     apply(cases n') apply auto apply(case_tac n) apply auto\n    by(cases n',auto,case_tac n,auto)\n  then show ?case by (rule IH)\nnext\n  case (Proc_CFG_WhileBodyExit c' n et' b)\n  from \\<open>c' \\<turnstile> n -CEdge (p, es, rets)\\<rightarrow>\\<^sub>p Exit\\<close> \n  show ?case by(fastforce dest:Proc_CFG_Call_Labels)\nnext\n  case Proc_CFG_Call\n  from \\<open>Call p es rets \\<turnstile> Label 1 -IEdge et\\<rightarrow>\\<^sub>p n''\\<close> show ?case\n    by(fastforce elim:Proc_CFG.cases)\nqed\n\n\nlemma Proc_CFG_edge_det:\n  \"\\<lbrakk>prog \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'; prog \\<turnstile> n -et'\\<rightarrow>\\<^sub>p n'\\<rbrakk> \\<Longrightarrow> et = et'\"\nproof(induct rule:Proc_CFG.induct)\n  case Proc_CFG_Entry_Exit thus ?case by(fastforce dest:Proc_CFG_EntryD)\nnext\n  case Proc_CFG_Entry thus ?case by(fastforce dest:Proc_CFG_EntryD)\nnext\n  case Proc_CFG_Skip thus ?case by(fastforce elim:Proc_CFG.cases)\nnext\n  case Proc_CFG_LAss thus ?case by(fastforce elim:Proc_CFG.cases)\nnext\n  case Proc_CFG_LAssSkip thus ?case by(fastforce elim:Proc_CFG.cases)\nnext\n  case (Proc_CFG_SeqFirst c\\<^sub>1 n et n' c\\<^sub>2)\n  note edge = \\<open>c\\<^sub>1 \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'\\<close> \n  note IH = \\<open>c\\<^sub>1 \\<turnstile> n -et'\\<rightarrow>\\<^sub>p n' \\<Longrightarrow> et = et'\\<close>\n  from edge \\<open>n' \\<noteq> Exit\\<close> obtain l where l:\"n' = Label l\" by (cases n') auto\n  with edge have \"l < #:c\\<^sub>1\" by(fastforce intro:Proc_CFG_targetlabel_less_num_nodes)\n  with \\<open>c\\<^sub>1;;c\\<^sub>2 \\<turnstile> n -et'\\<rightarrow>\\<^sub>p n'\\<close> l have \"c\\<^sub>1 \\<turnstile> n -et'\\<rightarrow>\\<^sub>p n'\"\n    by(fastforce elim:Proc_CFG.cases intro:Proc_CFG.intros dest:label_incr_ge)\n  from IH[OF this] show ?case .\nnext\n  case (Proc_CFG_SeqConnect c\\<^sub>1 n et c\\<^sub>2)\n  note edge = \\<open>c\\<^sub>1 \\<turnstile> n -et\\<rightarrow>\\<^sub>p Exit\\<close>\n  note IH = \\<open>c\\<^sub>1 \\<turnstile> n -et'\\<rightarrow>\\<^sub>p Exit \\<Longrightarrow> et = et'\\<close>\n  from edge \\<open>n \\<noteq> Entry\\<close> obtain l where l:\"n = Label l\" by (cases n) auto\n  with edge have \"l < #:c\\<^sub>1\" by(fastforce intro: Proc_CFG_sourcelabel_less_num_nodes)\n  with \\<open>c\\<^sub>1;;c\\<^sub>2 \\<turnstile> n -et'\\<rightarrow>\\<^sub>p Label #:c\\<^sub>1\\<close> l have \"c\\<^sub>1 \\<turnstile> n -et'\\<rightarrow>\\<^sub>p Exit\"\n    by(fastforce elim:Proc_CFG.cases \n                dest:Proc_CFG_targetlabel_less_num_nodes label_incr_ge)\n  from IH[OF this] show ?case .\nnext\n  case (Proc_CFG_SeqSecond c\\<^sub>2 n et n' c\\<^sub>1)\n  note edge = \\<open>c\\<^sub>2 \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'\\<close> \n  note IH = \\<open>c\\<^sub>2 \\<turnstile> n -et'\\<rightarrow>\\<^sub>p n' \\<Longrightarrow> et = et'\\<close>\n  from edge \\<open>n \\<noteq> Entry\\<close> obtain l where l:\"n = Label l\" by (cases n) auto\n  with edge have \"l < #:c\\<^sub>2\" by(fastforce intro:Proc_CFG_sourcelabel_less_num_nodes)\n  with \\<open>c\\<^sub>1;;c\\<^sub>2 \\<turnstile> n \\<oplus> #:c\\<^sub>1 -et'\\<rightarrow>\\<^sub>p n' \\<oplus> #:c\\<^sub>1\\<close> l have \"c\\<^sub>2 \\<turnstile> n -et'\\<rightarrow>\\<^sub>p n'\"\n    by -(erule Proc_CFG.cases,\n    (fastforce dest:Proc_CFG_sourcelabel_less_num_nodes label_incr_ge\n              dest!:label_incr_inj)+)\n  from IH[OF this] show ?case .\nnext\n  case Proc_CFG_CondTrue thus ?case by(fastforce elim:Proc_CFG.cases)\nnext\n  case Proc_CFG_CondFalse thus ?case by(fastforce elim:Proc_CFG.cases)\nnext\n  case (Proc_CFG_CondThen c\\<^sub>1 n et n' b c\\<^sub>2)\n  note edge = \\<open>c\\<^sub>1 \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'\\<close>\n  note IH = \\<open>c\\<^sub>1 \\<turnstile> n -et'\\<rightarrow>\\<^sub>p n' \\<Longrightarrow> et = et'\\<close>\n  from edge \\<open>n \\<noteq> Entry\\<close> obtain l where l:\"n = Label l\" by (cases n) auto\n  with edge have \"l < #:c\\<^sub>1\" by(fastforce intro:Proc_CFG_sourcelabel_less_num_nodes)\n  with \\<open>if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> n \\<oplus> 1 -et'\\<rightarrow>\\<^sub>p n' \\<oplus> 1\\<close> l have \"c\\<^sub>1 \\<turnstile> n -et'\\<rightarrow>\\<^sub>p n'\"\n    by -(erule Proc_CFG.cases,(fastforce dest:label_incr_ge label_incr_inj)+)\n  from IH[OF this] show ?case .\nnext\n  case (Proc_CFG_CondElse c\\<^sub>2 n et n' b c\\<^sub>1)\n  note edge = \\<open>c\\<^sub>2 \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'\\<close>\n  note IH = \\<open>c\\<^sub>2 \\<turnstile> n -et'\\<rightarrow>\\<^sub>p n' \\<Longrightarrow> et = et'\\<close>\n  from edge \\<open>n \\<noteq> Entry\\<close> obtain l where l:\"n = Label l\" by (cases n) auto\n  with edge have \"l < #:c\\<^sub>2\" by(fastforce intro:Proc_CFG_sourcelabel_less_num_nodes)\n  with \\<open>if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> n \\<oplus> (#:c\\<^sub>1 + 1) -et'\\<rightarrow>\\<^sub>p n' \\<oplus> (#:c\\<^sub>1 + 1)\\<close> l \n  have \"c\\<^sub>2 \\<turnstile> n -et'\\<rightarrow>\\<^sub>p n'\"\n    by -(erule Proc_CFG.cases,(fastforce dest:Proc_CFG_sourcelabel_less_num_nodes \n                             label_incr_inj label_incr_ge label_incr_simp_rev)+)\n  from IH[OF this] show ?case .\nnext\n  case Proc_CFG_WhileTrue thus ?case by(fastforce elim:Proc_CFG.cases)\nnext\n  case Proc_CFG_WhileFalse thus ?case by(fastforce elim:Proc_CFG.cases)\nnext\n  case Proc_CFG_WhileFalseSkip thus ?case by(fastforce elim:Proc_CFG.cases)\nnext\n  case (Proc_CFG_WhileBody c' n et n' b)\n  note edge = \\<open>c' \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'\\<close>\n  note IH = \\<open>c' \\<turnstile> n -et'\\<rightarrow>\\<^sub>p n' \\<Longrightarrow> et = et'\\<close>\n  from edge \\<open>n \\<noteq> Entry\\<close> obtain l where l:\"n = Label l\" by (cases n) auto\n  with edge have less:\"l < #:c'\" \n    by(fastforce intro:Proc_CFG_sourcelabel_less_num_nodes)\n  from edge \\<open>n' \\<noteq> Exit\\<close> obtain l' where l':\"n' = Label l'\" by (cases n') auto\n  with edge have \"l' < #:c'\" by(fastforce intro:Proc_CFG_targetlabel_less_num_nodes)\n  with \\<open>while (b) c' \\<turnstile> n \\<oplus> 2 -et'\\<rightarrow>\\<^sub>p n' \\<oplus> 2\\<close> l less l' have \"c' \\<turnstile> n -et'\\<rightarrow>\\<^sub>p n'\"\n    by(fastforce elim:Proc_CFG.cases dest:label_incr_start_Node_smaller)\n  from IH[OF this] show ?case .\nnext\n  case (Proc_CFG_WhileBodyExit c' n et b)\n  note edge = \\<open>c' \\<turnstile> n -et\\<rightarrow>\\<^sub>p Exit\\<close>\n  note IH = \\<open>c' \\<turnstile> n -et'\\<rightarrow>\\<^sub>p Exit \\<Longrightarrow> et = et'\\<close>\n  from edge \\<open>n \\<noteq> Entry\\<close> obtain l where l:\"n = Label l\" by (cases n) auto\n  with edge have \"l < #:c'\" by(fastforce intro:Proc_CFG_sourcelabel_less_num_nodes)\n  with \\<open>while (b) c' \\<turnstile> n \\<oplus> 2 -et'\\<rightarrow>\\<^sub>p Label 0\\<close> l have \"c' \\<turnstile> n -et'\\<rightarrow>\\<^sub>p Exit\"\n    by -(erule Proc_CFG.cases,auto dest:label_incr_start_Node_smaller)\n  from IH[OF this] show ?case .\nnext\n  case Proc_CFG_Call thus ?case by(fastforce elim:Proc_CFG.cases)\nnext\n  case Proc_CFG_CallSkip thus ?case by(fastforce elim:Proc_CFG.cases)\nqed\n\n\nlemma WCFG_deterministic:\n  \"\\<lbrakk>prog \\<turnstile> n\\<^sub>1 -et\\<^sub>1\\<rightarrow>\\<^sub>p n\\<^sub>1'; prog \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'; n\\<^sub>1 = n\\<^sub>2; n\\<^sub>1' \\<noteq> n\\<^sub>2'\\<rbrakk>\n  \\<Longrightarrow> \\<exists>Q Q'. et\\<^sub>1 = IEdge (Q)\\<^sub>\\<surd> \\<and> et\\<^sub>2 = IEdge (Q')\\<^sub>\\<surd> \\<and> \n            (\\<forall>s. (Q s \\<longrightarrow> \\<not> Q' s) \\<and> (Q' s \\<longrightarrow> \\<not> Q s))\"\nproof(induct arbitrary:n\\<^sub>2 n\\<^sub>2' rule:Proc_CFG.induct)\n  case (Proc_CFG_Entry_Exit prog)\n  from \\<open>prog \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'\\<close> \\<open>Entry = n\\<^sub>2\\<close> \\<open>Exit \\<noteq> n\\<^sub>2'\\<close>\n  have \"et\\<^sub>2 = IEdge (\\<lambda>s. True)\\<^sub>\\<surd>\" by(fastforce dest:Proc_CFG_EntryD)\n  thus ?case by simp\nnext\n  case (Proc_CFG_Entry prog)\n  from \\<open>prog \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'\\<close> \\<open>Entry = n\\<^sub>2\\<close> \\<open>Label 0 \\<noteq> n\\<^sub>2'\\<close>\n  have \"et\\<^sub>2 = IEdge (\\<lambda>s. False)\\<^sub>\\<surd>\" by(fastforce dest:Proc_CFG_EntryD)\n  thus ?case by simp\nnext\n  case Proc_CFG_Skip\n  from \\<open>Skip \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'\\<close> \\<open>Label 0 = n\\<^sub>2\\<close> \\<open>Exit \\<noteq> n\\<^sub>2'\\<close>\n  have False by(fastforce elim:Proc_CFG.cases)\n  thus ?case by simp\nnext\n  case (Proc_CFG_LAss V e)\n  from \\<open>V:=e \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'\\<close> \\<open>Label 0 = n\\<^sub>2\\<close> \\<open>Label 1 \\<noteq> n\\<^sub>2'\\<close>\n  have False by -(erule Proc_CFG.cases,auto)\n  thus ?case by simp\nnext\n  case (Proc_CFG_LAssSkip V e)\n  from \\<open>V:=e \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'\\<close> \\<open>Label 1 = n\\<^sub>2\\<close> \\<open>Exit \\<noteq> n\\<^sub>2'\\<close>\n  have False by -(erule Proc_CFG.cases,auto)\n  thus ?case by simp\nnext\n  case (Proc_CFG_SeqFirst c\\<^sub>1 n et n' c\\<^sub>2)\n  note IH = \\<open>\\<And>n\\<^sub>2 n\\<^sub>2'. \\<lbrakk>c\\<^sub>1 \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'; n = n\\<^sub>2; n' \\<noteq> n\\<^sub>2'\\<rbrakk>\n  \\<Longrightarrow> \\<exists>Q Q'. et = IEdge (Q)\\<^sub>\\<surd> \\<and> et\\<^sub>2 = IEdge (Q')\\<^sub>\\<surd> \\<and> \n            (\\<forall>s. (Q s \\<longrightarrow> \\<not> Q' s) \\<and> (Q' s \\<longrightarrow> \\<not> Q s))\\<close>\n  from \\<open>c\\<^sub>1;;c\\<^sub>2 \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'\\<close> \\<open>c\\<^sub>1 \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'\\<close> \\<open>n = n\\<^sub>2\\<close> \\<open>n' \\<noteq> n\\<^sub>2'\\<close>\n  have \"c\\<^sub>1 \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2' \\<or> (c\\<^sub>1 \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p Exit \\<and> n\\<^sub>2' = Label #:c\\<^sub>1)\"\n    apply hypsubst_thin apply(erule Proc_CFG.cases)\n    apply(auto intro:Proc_CFG.intros)\n    by(case_tac n,auto dest:Proc_CFG_sourcelabel_less_num_nodes)+\n  thus ?case\n  proof\n    assume \"c\\<^sub>1 \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'\"\n    from IH[OF this \\<open>n = n\\<^sub>2\\<close> \\<open>n' \\<noteq> n\\<^sub>2'\\<close>] show ?case .\n  next\n    assume \"c\\<^sub>1 \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p Exit \\<and> n\\<^sub>2' = Label #:c\\<^sub>1\"\n    hence edge:\"c\\<^sub>1 \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p Exit\" and n2':\"n\\<^sub>2' = Label #:c\\<^sub>1\" by simp_all\n    from IH[OF edge \\<open>n = n\\<^sub>2\\<close> \\<open>n' \\<noteq> Exit\\<close>] show ?case .\n  qed\nnext\n  case (Proc_CFG_SeqConnect c\\<^sub>1 n et c\\<^sub>2)\n  note IH = \\<open>\\<And>n\\<^sub>2 n\\<^sub>2'. \\<lbrakk>c\\<^sub>1 \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'; n = n\\<^sub>2; Exit \\<noteq> n\\<^sub>2'\\<rbrakk>\n  \\<Longrightarrow> \\<exists>Q Q'. et = IEdge (Q)\\<^sub>\\<surd> \\<and> et\\<^sub>2 = IEdge (Q')\\<^sub>\\<surd> \\<and> \n            (\\<forall>s. (Q s \\<longrightarrow> \\<not> Q' s) \\<and> (Q' s \\<longrightarrow> \\<not> Q s))\\<close>\n  from \\<open>c\\<^sub>1;;c\\<^sub>2 \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'\\<close> \\<open>c\\<^sub>1 \\<turnstile> n -et\\<rightarrow>\\<^sub>p Exit\\<close> \\<open>n = n\\<^sub>2\\<close> \\<open>n \\<noteq> Entry\\<close>\n    \\<open>Label #:c\\<^sub>1 \\<noteq> n\\<^sub>2'\\<close> have \"c\\<^sub>1 \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2' \\<and> Exit \\<noteq> n\\<^sub>2'\"\n    apply hypsubst_thin apply(erule Proc_CFG.cases)\n    apply(auto intro:Proc_CFG.intros)\n    by(case_tac n,auto dest:Proc_CFG_sourcelabel_less_num_nodes)+\n  from IH[OF this[THEN conjunct1] \\<open>n = n\\<^sub>2\\<close> this[THEN conjunct2]]\n  show ?case .\nnext\n  case (Proc_CFG_SeqSecond c\\<^sub>2 n et n' c\\<^sub>1)\n  note IH = \\<open>\\<And>n\\<^sub>2 n\\<^sub>2'. \\<lbrakk>c\\<^sub>2 \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'; n = n\\<^sub>2; n' \\<noteq> n\\<^sub>2'\\<rbrakk>\n  \\<Longrightarrow> \\<exists>Q Q'. et = IEdge (Q)\\<^sub>\\<surd> \\<and> et\\<^sub>2 = IEdge (Q')\\<^sub>\\<surd> \\<and> \n            (\\<forall>s. (Q s \\<longrightarrow> \\<not> Q' s) \\<and> (Q' s \\<longrightarrow> \\<not> Q s))\\<close>\n  from \\<open>c\\<^sub>1;;c\\<^sub>2 \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'\\<close> \\<open>c\\<^sub>2 \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'\\<close> \\<open>n \\<oplus> #:c\\<^sub>1 = n\\<^sub>2\\<close>\n    \\<open>n' \\<oplus> #:c\\<^sub>1 \\<noteq> n\\<^sub>2'\\<close> \\<open>n \\<noteq> Entry\\<close>\n  obtain nx where \"c\\<^sub>2 \\<turnstile> n -et\\<^sub>2\\<rightarrow>\\<^sub>p nx \\<and> nx \\<oplus> #:c\\<^sub>1 = n\\<^sub>2'\"\n    apply - apply(erule Proc_CFG.cases)\n    apply(auto intro:Proc_CFG.intros)\n      apply(cases n,auto dest:Proc_CFG_sourcelabel_less_num_nodes)\n     apply(cases n,auto dest:Proc_CFG_sourcelabel_less_num_nodes)\n    by(fastforce dest:label_incr_inj)\n  with \\<open>n' \\<oplus> #:c\\<^sub>1 \\<noteq> n\\<^sub>2'\\<close> have edge:\"c\\<^sub>2 \\<turnstile> n -et\\<^sub>2\\<rightarrow>\\<^sub>p nx\" and neq:\"n' \\<noteq> nx\"\n    by auto\n  from IH[OF edge _ neq] show ?case by simp\nnext\n  case (Proc_CFG_CondTrue b c\\<^sub>1 c\\<^sub>2)\n  from \\<open>if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'\\<close> \\<open>Label 0 = n\\<^sub>2\\<close> \\<open>Label 1 \\<noteq> n\\<^sub>2'\\<close>\n  show ?case by -(erule Proc_CFG.cases,auto)\nnext\n  case (Proc_CFG_CondFalse b c\\<^sub>1 c\\<^sub>2)\n  from \\<open>if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'\\<close> \\<open>Label 0 = n\\<^sub>2\\<close> \\<open>Label (#:c\\<^sub>1 + 1) \\<noteq> n\\<^sub>2'\\<close>\n  show ?case by -(erule Proc_CFG.cases,auto)\nnext\n  case (Proc_CFG_CondThen c\\<^sub>1 n et n' b c\\<^sub>2)\n  note IH = \\<open>\\<And>n\\<^sub>2 n\\<^sub>2'. \\<lbrakk>c\\<^sub>1 \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'; n = n\\<^sub>2; n' \\<noteq> n\\<^sub>2'\\<rbrakk>\n    \\<Longrightarrow> \\<exists>Q Q'. et = IEdge (Q)\\<^sub>\\<surd> \\<and> et\\<^sub>2 = IEdge (Q')\\<^sub>\\<surd> \\<and> \n              (\\<forall>s. (Q s \\<longrightarrow> \\<not> Q' s) \\<and> (Q' s \\<longrightarrow> \\<not> Q s))\\<close>\n  from \\<open>if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'\\<close> \\<open>c\\<^sub>1 \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'\\<close> \\<open>n \\<noteq> Entry\\<close> \n    \\<open>n \\<oplus> 1 = n\\<^sub>2\\<close> \\<open>n' \\<oplus> 1 \\<noteq> n\\<^sub>2'\\<close>\n  obtain nx where \"c\\<^sub>1 \\<turnstile> n -et\\<^sub>2\\<rightarrow>\\<^sub>p nx \\<and> n' \\<noteq> nx\"\n    apply - apply(erule Proc_CFG.cases)\n    apply(auto intro:Proc_CFG.intros simp del:One_nat_def)\n     apply(drule label_incr_inj) apply(auto simp del:One_nat_def)\n    apply(drule label_incr_simp_rev[OF sym])\n    by(case_tac na,auto dest:Proc_CFG_sourcelabel_less_num_nodes)\n  from IH[OF this[THEN conjunct1] _ this[THEN conjunct2]] show ?case by simp\nnext\n  case (Proc_CFG_CondElse c\\<^sub>2 n et n' b c\\<^sub>1)\n  note IH = \\<open>\\<And>n\\<^sub>2 n\\<^sub>2'. \\<lbrakk>c\\<^sub>2 \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'; n = n\\<^sub>2; n' \\<noteq> n\\<^sub>2'\\<rbrakk>\n    \\<Longrightarrow> \\<exists>Q Q'. et = IEdge (Q)\\<^sub>\\<surd> \\<and> et\\<^sub>2 = IEdge (Q')\\<^sub>\\<surd> \\<and> \n              (\\<forall>s. (Q s \\<longrightarrow> \\<not> Q' s) \\<and> (Q' s \\<longrightarrow> \\<not> Q s))\\<close>\n  from \\<open>if (b) c\\<^sub>1 else c\\<^sub>2 \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'\\<close> \\<open>c\\<^sub>2 \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'\\<close> \\<open>n \\<noteq> Entry\\<close> \n    \\<open>n \\<oplus> #:c\\<^sub>1 + 1 = n\\<^sub>2\\<close> \\<open>n' \\<oplus> #:c\\<^sub>1 + 1 \\<noteq> n\\<^sub>2'\\<close>\n  obtain nx where \"c\\<^sub>2 \\<turnstile> n -et\\<^sub>2\\<rightarrow>\\<^sub>p nx \\<and> n' \\<noteq> nx\"\n    apply - apply(erule Proc_CFG.cases)\n    apply(auto intro:Proc_CFG.intros simp del:One_nat_def)\n     apply(drule label_incr_simp_rev)\n     apply(case_tac na,auto,cases n,auto dest:Proc_CFG_sourcelabel_less_num_nodes)\n    by(fastforce dest:label_incr_inj)\n  from IH[OF this[THEN conjunct1] _ this[THEN conjunct2]] show ?case by simp\nnext\n  case (Proc_CFG_WhileTrue b c')\n  from \\<open>while (b) c' \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'\\<close> \\<open>Label 0 = n\\<^sub>2\\<close> \\<open>Label 2 \\<noteq> n\\<^sub>2'\\<close>\n  show ?case by -(erule Proc_CFG.cases,auto)\nnext\n  case (Proc_CFG_WhileFalse b c')\n  from \\<open>while (b) c' \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'\\<close> \\<open>Label 0 = n\\<^sub>2\\<close> \\<open>Label 1 \\<noteq> n\\<^sub>2'\\<close>\n  show ?case by -(erule Proc_CFG.cases,auto)\nnext\n  case (Proc_CFG_WhileFalseSkip b c')\n  from \\<open>while (b) c' \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'\\<close> \\<open>Label 1 = n\\<^sub>2\\<close> \\<open>Exit \\<noteq> n\\<^sub>2'\\<close>\n  show ?case by -(erule Proc_CFG.cases,auto dest:label_incr_ge)\nnext\n  case (Proc_CFG_WhileBody c' n et n' b)\n  note IH = \\<open>\\<And>n\\<^sub>2 n\\<^sub>2'. \\<lbrakk>c' \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'; n = n\\<^sub>2; n' \\<noteq> n\\<^sub>2'\\<rbrakk>\n    \\<Longrightarrow> \\<exists>Q Q'. et = IEdge (Q)\\<^sub>\\<surd> \\<and> et\\<^sub>2 = IEdge (Q')\\<^sub>\\<surd> \\<and> \n              (\\<forall>s. (Q s \\<longrightarrow> \\<not> Q' s) \\<and> (Q' s \\<longrightarrow> \\<not> Q s))\\<close>\n  from \\<open>while (b) c' \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'\\<close> \\<open>c' \\<turnstile> n -et\\<rightarrow>\\<^sub>p n'\\<close> \\<open>n \\<noteq> Entry\\<close>\n    \\<open>n' \\<noteq> Exit\\<close> \\<open>n \\<oplus> 2 = n\\<^sub>2\\<close> \\<open>n' \\<oplus> 2 \\<noteq> n\\<^sub>2'\\<close>\n  obtain nx where \"c' \\<turnstile> n -et\\<^sub>2\\<rightarrow>\\<^sub>p nx \\<and> n' \\<noteq> nx\"\n    apply - apply(erule Proc_CFG.cases)\n    apply(auto intro:Proc_CFG.intros)\n      apply(fastforce dest:label_incr_ge[OF sym])\n     apply(fastforce dest:label_incr_inj)\n    by(fastforce dest:label_incr_inj)\n  from IH[OF this[THEN conjunct1] _ this[THEN conjunct2]] show ?case by simp\nnext\n  case (Proc_CFG_WhileBodyExit c' n et b)\n  note IH = \\<open>\\<And>n\\<^sub>2 n\\<^sub>2'. \\<lbrakk>c' \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'; n = n\\<^sub>2; Exit \\<noteq> n\\<^sub>2'\\<rbrakk>\n    \\<Longrightarrow> \\<exists>Q Q'. et = IEdge (Q)\\<^sub>\\<surd> \\<and> et\\<^sub>2 = IEdge (Q')\\<^sub>\\<surd> \\<and> \n              (\\<forall>s. (Q s \\<longrightarrow> \\<not> Q' s) \\<and> (Q' s \\<longrightarrow> \\<not> Q s))\\<close>\n  from \\<open>while (b) c' \\<turnstile> n\\<^sub>2 -et\\<^sub>2\\<rightarrow>\\<^sub>p n\\<^sub>2'\\<close> \\<open>c' \\<turnstile> n -et\\<rightarrow>\\<^sub>p Exit\\<close> \\<open>n \\<noteq> Entry\\<close>\n    \\<open>n \\<oplus> 2 = n\\<^sub>2\\<close> \\<open>Label 0 \\<noteq> n\\<^sub>2'\\<close>\n  obtain nx where \"c' \\<turnstile> n -et\\<^sub>2\\<rightarrow>\\<^sub>p nx \\<and> Exit \\<noteq> nx\"\n    apply - apply(erule Proc_CFG.cases)\n    apply(auto intro:Proc_CFG.intros)\n     apply(fastforce dest:label_incr_ge[OF sym])\n    by(fastforce dest:label_incr_inj)\n  from IH[OF this[THEN conjunct1] _ this[THEN conjunct2]] show ?case by simp\nnext\n  case Proc_CFG_Call thus ?case by -(erule Proc_CFG.cases,auto)\nnext\n  case Proc_CFG_CallSkip thus ?case by -(erule Proc_CFG.cases,auto)\nqed\n\n\nsubsection \\<open>And now: the interprocedural CFG\\<close>\n\nsubsubsection \\<open>Statements containing calls\\<close>\n\ntext \\<open>A procedure is a tuple composed of its name, its input and output variables\n  and its method body\\<close>\n\ntype_synonym proc = \"(pname \\<times> vname list \\<times> vname list \\<times> cmd)\"\ntype_synonym procs = \"proc list\"\n\n\ntext \\<open>\\<open>containsCall\\<close> guarantees that a call to procedure p is in\n  a certain statement.\\<close>\n\ndeclare conj_cong[fundef_cong]\n\nfunction containsCall :: \n  \"procs \\<Rightarrow> cmd \\<Rightarrow> pname list \\<Rightarrow> pname \\<Rightarrow> bool\"\nwhere \"containsCall procs Skip ps p \\<longleftrightarrow> False\"\n  | \"containsCall procs (V:=e) ps p \\<longleftrightarrow> False\"\n  | \"containsCall procs (c\\<^sub>1;;c\\<^sub>2) ps p \\<longleftrightarrow> \n       containsCall procs c\\<^sub>1 ps p \\<or> containsCall procs c\\<^sub>2 ps p\"\n  | \"containsCall procs (if (b) c\\<^sub>1 else c\\<^sub>2) ps p \\<longleftrightarrow> \n       containsCall procs c\\<^sub>1 ps p \\<or> containsCall procs c\\<^sub>2 ps p\"\n  | \"containsCall procs (while (b) c) ps p \\<longleftrightarrow> \n       containsCall procs c ps p\"\n  | \"containsCall procs (Call q es' rets') ps p \\<longleftrightarrow> p = q \\<and> ps = [] \\<or> \n       (\\<exists>ins outs c ps'. ps = q#ps' \\<and> (q,ins,outs,c) \\<in> set procs \\<and>\n                     containsCall procs c ps' p)\"\nby pat_completeness auto\ntermination containsCall\nby(relation \"measures [\\<lambda>(procs,c,ps,p). length ps, \n  \\<lambda>(procs,c,ps,p). size c]\") auto\n\n\nlemmas containsCall_induct[case_names Skip LAss Seq Cond While Call] = \n  containsCall.induct\n\n\nlemma containsCallcases: \n  \"containsCall procs prog ps p\n  \\<Longrightarrow> ps = [] \\<and> containsCall procs prog ps p \\<or> \n  (\\<exists>q ins outs c ps'. ps = ps'@[q] \\<and> (q,ins,outs,c) \\<in> set procs \\<and>\n  containsCall procs c [] p \\<and> containsCall procs prog ps' q)\"\nproof(induct procs prog ps p rule:containsCall_induct)\n  case (Call procs q es' rets' ps p)\n  note IH = \\<open>\\<And>x y z ps'. \\<lbrakk>ps = q#ps'; (q,x,y,z) \\<in> set procs;\n    containsCall procs z ps' p\\<rbrakk>\n    \\<Longrightarrow> ps' = [] \\<and> containsCall procs z ps' p \\<or> \n    (\\<exists>qx ins outs c psx. ps' = psx@[qx] \\<and> (qx,ins,outs,c) \\<in> set procs \\<and>\n    containsCall procs c [] p \\<and> \n    containsCall procs z psx qx)\\<close>\n  from \\<open>containsCall procs (Call q es' rets') ps p\\<close>\n  have \"p = q \\<and> ps = [] \\<or> \n    (\\<exists>ins outs c ps'. ps = q#ps' \\<and> (q,ins,outs,c) \\<in> set procs \\<and>\n                  containsCall procs c ps' p)\" by simp\n  thus ?case\n  proof\n    assume assms:\"p = q \\<and> ps = []\"\n    hence \"containsCall procs (Call q es' rets') ps p\" by simp\n    with assms show ?thesis by simp\n  next\n    assume \"\\<exists>ins outs c ps'. ps = q#ps' \\<and> (q,ins,outs,c) \\<in> set procs \\<and>\n      containsCall procs c ps' p\"\n    then obtain ins outs c ps' where \"ps = q#ps'\" and \"(q,ins,outs,c) \\<in> set procs\"\n      and \"containsCall procs c ps' p\" by blast\n    from IH[OF this] have \"ps' = [] \\<and> containsCall procs c ps' p \\<or>\n      (\\<exists>qx insx outsx cx psx. \n         ps' = psx @ [qx] \\<and> (qx,insx,outsx,cx) \\<in> set procs \\<and>\n         containsCall procs cx [] p \\<and> containsCall procs c psx qx)\" .\n    thus ?thesis\n    proof\n      assume assms:\"ps' = [] \\<and> containsCall procs c ps' p\"\n      have \"containsCall procs (Call q es' rets') [] q\" by simp\n      with assms \\<open>ps = q#ps'\\<close> \\<open>(q,ins,outs,c) \\<in> set procs\\<close> show ?thesis by fastforce\n    next\n      assume \"\\<exists>qx insx outsx cx psx. \n        ps' = psx@[qx] \\<and> (qx,insx,outsx,cx) \\<in> set procs \\<and>\n        containsCall procs cx [] p \\<and> containsCall procs c psx qx\"\n      then obtain qx insx outsx cx psx\n        where \"ps' = psx@[qx]\" and \"(qx,insx,outsx,cx) \\<in> set procs\"\n        and \"containsCall procs cx [] p\"\n        and \"containsCall procs c psx qx\" by blast\n      from \\<open>(q,ins,outs,c) \\<in> set procs\\<close> \\<open>containsCall procs c psx qx\\<close>\n      have \"containsCall procs (Call q es' rets') (q#psx) qx\" by fastforce\n      with \\<open>ps' = psx@[qx]\\<close> \\<open>ps = q#ps'\\<close> \\<open>(qx,insx,outsx,cx) \\<in> set procs\\<close>\n        \\<open>containsCall procs cx [] p\\<close> show ?thesis by fastforce\n    qed\n  qed\nqed auto\n\n\n\nlemma containsCallE:\n  \"\\<lbrakk>containsCall procs prog ps p; \n    \\<lbrakk>ps = []; containsCall procs prog ps p\\<rbrakk> \\<Longrightarrow> P procs prog ps p;\n    \\<And>q ins outs c es' rets' ps'. \\<lbrakk>ps = ps'@[q]; (q,ins,outs,c) \\<in> set procs; \n      containsCall procs c [] p; containsCall procs prog ps' q\\<rbrakk> \n     \\<Longrightarrow> P procs prog ps p\\<rbrakk> \\<Longrightarrow> P procs prog ps p\"\n  by(auto dest:containsCallcases)\n\n\nlemma containsCall_in_proc: \n  \"\\<lbrakk>containsCall procs prog qs q; (q,ins,outs,c) \\<in> set procs; \n  containsCall procs c [] p\\<rbrakk>\n  \\<Longrightarrow> containsCall procs prog (qs@[q]) p\"\nproof(induct procs prog qs q rule:containsCall_induct)\n  case (Call procs qx esx retsx ps p')\n  note IH = \\<open>\\<And>x y z psx. \\<lbrakk>ps = qx#psx; (qx,x,y,z) \\<in> set procs;\n    containsCall procs z psx p'; (p',ins,outs,c) \\<in> set procs; \n    containsCall procs c [] p\\<rbrakk> \\<Longrightarrow> containsCall procs z (psx@[p']) p\\<close>\n  from \\<open>containsCall procs (Call qx esx retsx) ps p'\\<close>\n  have \"p' = qx \\<and> ps = [] \\<or>\n    (\\<exists>insx outsx cx psx. ps = qx#psx \\<and> (qx,insx,outsx,cx) \\<in> set procs \\<and>\n    containsCall procs cx psx p')\" by simp\n  thus ?case\n  proof\n    assume assms:\"p' = qx \\<and> ps = []\"\n    with \\<open>(p', ins, outs, c) \\<in> set procs\\<close> \\<open>containsCall procs c [] p\\<close>\n    have \"containsCall procs (Call qx esx retsx) [p'] p\" by fastforce\n    with assms show ?thesis by simp\n  next\n    assume \"\\<exists>insx outsx cx psx. ps = qx#psx \\<and> (qx,insx,outsx,cx) \\<in> set procs \\<and>\n      containsCall procs cx psx p'\"\n    then obtain insx outsx cx psx where \"ps = qx#psx\" \n      and \"(qx,insx,outsx,cx) \\<in> set procs\"\n      and \"containsCall procs cx psx p'\" by blast\n    from IH[OF this \\<open>(p', ins, outs, c) \\<in> set procs\\<close> \n      \\<open>containsCall procs c [] p\\<close>] \n    have \"containsCall procs cx (psx @ [p']) p\" .\n    with \\<open>ps = qx#psx\\<close> \\<open>(qx,insx,outsx,cx) \\<in> set procs\\<close>\n    show ?thesis by fastforce\n  qed\nqed auto\n    \n\nlemma containsCall_indirection:\n  \"\\<lbrakk>containsCall procs prog qs q; containsCall procs c ps p;\n  (q,ins,outs,c) \\<in> set procs\\<rbrakk>\n  \\<Longrightarrow> containsCall procs prog (qs@q#ps) p\"\nproof(induct procs prog qs q rule:containsCall_induct)\n  case (Call procs px esx retsx ps' p')\n  note IH = \\<open>\\<And>x y z psx. \\<lbrakk>ps' = px # psx; (px, x, y, z) \\<in> set procs;\n    containsCall procs z psx p'; containsCall procs c ps p;\n    (p', ins, outs, c) \\<in> set procs\\<rbrakk>\n    \\<Longrightarrow> containsCall procs z (psx @ p' # ps) p\\<close>\n  from \\<open>containsCall procs (Call px esx retsx) ps' p'\\<close>\n  have \"p' = px \\<and> ps' = [] \\<or>\n    (\\<exists>insx outsx cx psx. ps' = px#psx \\<and> (px,insx,outsx,cx) \\<in> set procs \\<and>\n    containsCall procs cx psx p')\" by simp\n  thus ?case\n  proof\n    assume \"p' = px \\<and> ps' = []\"\n    with \\<open>containsCall procs c ps p\\<close> \\<open>(p', ins, outs, c) \\<in> set procs\\<close>\n    show ?thesis by fastforce\n  next\n    assume \"\\<exists>insx outsx cx psx. ps' = px#psx \\<and> (px,insx,outsx,cx) \\<in> set procs \\<and>\n      containsCall procs cx psx p'\"\n    then obtain insx outsx cx psx where \"ps' = px#psx\" \n      and \"(px,insx,outsx,cx) \\<in> set procs\"\n      and \"containsCall procs cx psx p'\" by blast\n    from IH[OF this \\<open>containsCall procs c ps p\\<close>\n      \\<open>(p', ins, outs, c) \\<in> set procs\\<close>] \n    have \"containsCall procs cx (psx @ p' # ps) p\" .\n    with \\<open>ps' = px#psx\\<close> \\<open>(px,insx,outsx,cx) \\<in> set procs\\<close>\n    show ?thesis by fastforce\n  qed\nqed auto\n\n\nlemma Proc_CFG_Call_containsCall:\n  \"prog \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n' \\<Longrightarrow> containsCall procs prog [] p\"\nby(induct prog n et\\<equiv>\"CEdge (p,es,rets)\" n' rule:Proc_CFG.induct,auto)\n\n\nlemma containsCall_empty_Proc_CFG_Call_edge: \n  assumes \"containsCall procs prog [] p\"\n  obtains l es rets l' where \"prog \\<turnstile> Label l -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p Label l'\"\nproof(atomize_elim)\n  from \\<open>containsCall procs prog [] p\\<close>\n  show \"\\<exists>l es rets l'. prog \\<turnstile> Label l -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p Label l'\"\n  proof(induct procs prog ps\\<equiv>\"[]::pname list\" p rule:containsCall_induct)\n    case Seq thus ?case\n      by auto(fastforce dest:Proc_CFG_SeqFirst,fastforce dest:Proc_CFG_SeqSecond)\n  next\n    case Cond thus ?case\n      by auto(fastforce dest:Proc_CFG_CondThen,fastforce dest:Proc_CFG_CondElse)\n  next\n    case While thus ?case by(fastforce dest:Proc_CFG_WhileBody)\n  next\n    case Call thus ?case by(fastforce intro:Proc_CFG_Call)\n  qed auto\nqed\n\n\nsubsubsection\\<open>The edges of the combined CFG\\<close>\n\ntype_synonym node = \"(pname \\<times> label)\"\ntype_synonym edge = \"(node \\<times> (vname,val,node,pname) edge_kind \\<times> node)\"\n\nfun get_proc :: \"node \\<Rightarrow> pname\"\n  where \"get_proc (p,l) = p\"\n\n\ninductive PCFG :: \n  \"cmd \\<Rightarrow> procs \\<Rightarrow> node \\<Rightarrow> (vname,val,node,pname) edge_kind \\<Rightarrow> node \\<Rightarrow> bool\" \n(\"_,_ \\<turnstile> _ -_\\<rightarrow> _\" [51,51,0,0,0] 81)\nfor prog::cmd and procs::procs\nwhere\n\n  Main:\n  \"prog \\<turnstile> n -IEdge et\\<rightarrow>\\<^sub>p n' \\<Longrightarrow> prog,procs \\<turnstile> (Main,n) -et\\<rightarrow> (Main,n')\"\n\n| Proc:\n  \"\\<lbrakk>(p,ins,outs,c) \\<in> set procs; c \\<turnstile> n -IEdge et\\<rightarrow>\\<^sub>p n'; \n    containsCall procs prog ps p\\<rbrakk> \n  \\<Longrightarrow> prog,procs \\<turnstile> (p,n) -et\\<rightarrow> (p,n')\"\n\n\n| MainCall:\n  \"\\<lbrakk>prog \\<turnstile> Label l -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'; (p,ins,outs,c) \\<in> set procs\\<rbrakk>\n  \\<Longrightarrow> prog,procs \\<turnstile> (Main,Label l) \n                  -(\\<lambda>s. True):(Main,n')\\<hookrightarrow>\\<^bsub>p\\<^esub>map (\\<lambda>e cf. interpret e cf) es\\<rightarrow> (p,Entry)\"\n\n| ProcCall:\n  \"\\<lbrakk>(p,ins,outs,c) \\<in> set procs; c \\<turnstile> Label l -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p Label l';\n    (p',ins',outs',c') \\<in> set procs; containsCall procs prog ps p\\<rbrakk>\n  \\<Longrightarrow> prog,procs \\<turnstile> (p,Label l) \n               -(\\<lambda>s. True):(p,Label l')\\<hookrightarrow>\\<^bsub>p'\\<^esub>map (\\<lambda>e cf. interpret e cf) es'\\<rightarrow> (p',Entry)\"\n\n| MainReturn:\n  \"\\<lbrakk>prog \\<turnstile> Label l -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p Label l'; (p,ins,outs,c) \\<in> set procs\\<rbrakk>\n  \\<Longrightarrow> prog,procs \\<turnstile> (p,Exit) -(\\<lambda>cf. snd cf = (Main,Label l'))\\<hookleftarrow>\\<^bsub>p\\<^esub>\n       (\\<lambda>cf cf'. cf'(rets [:=] map cf outs))\\<rightarrow> (Main,Label l')\"\n\n| ProcReturn:\n  \"\\<lbrakk>(p,ins,outs,c) \\<in> set procs; c \\<turnstile> Label l -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p Label l'; \n   (p',ins',outs',c') \\<in> set procs; containsCall procs prog ps p\\<rbrakk>\n  \\<Longrightarrow> prog,procs \\<turnstile> (p',Exit) -(\\<lambda>cf. snd cf = (p,Label l'))\\<hookleftarrow>\\<^bsub>p'\\<^esub>\n       (\\<lambda>cf cf'. cf'(rets' [:=] map cf outs'))\\<rightarrow> (p,Label l')\"\n\n| MainCallReturn:\n  \"prog \\<turnstile> n -CEdge (p,es,rets)\\<rightarrow>\\<^sub>p n'\n  \\<Longrightarrow> prog,procs \\<turnstile> (Main,n) -(\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow> (Main,n')\"\n\n| ProcCallReturn:\n  \"\\<lbrakk>(p,ins,outs,c) \\<in> set procs; c \\<turnstile> n -CEdge (p',es',rets')\\<rightarrow>\\<^sub>p n'; \n    containsCall procs prog ps p\\<rbrakk> \n  \\<Longrightarrow> prog,procs \\<turnstile> (p,n) -(\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow> (p,n')\"\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/HRB-Slicing/Proc/PCFG.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6513548646660543, "lm_q2_score": 0.399811640739795, "lm_q1q2_score": 0.2604192571459823}}
{"text": "(*******************************************************************************\n\n  Project: Development of Security Protocols by Refinement\n\n  Module:   Key_establish/m1_keydist_iirn.thy (Isabelle/HOL 2016-1)\n  ID:       $Id: m1_keydist_iirn.thy 133854 2017-03-20 17:53:50Z csprenge $\n  Author:   Christoph Sprenger, ETH Zurich <sprenger@inf.ethz.ch>\n\n  Key distribution protocols\n  Level 1, 1st refinement: Abstract server-based key transport protocol with \n  initiator and responder roles. Provides injective server authentication to \n  the initiator and non-injective server authenticaiton to the responder.\n\n  Copyright (c) 2009-2016 Christoph Sprenger\n  Licence: LGPL\n\n*******************************************************************************)\n\nsection \\<open>Abstract (i/n)-authenticated key transport (L1)\\<close>\n\ntheory m1_keydist_iirn imports m1_keydist \"../Refinement/a0i_agree\"\nbegin\n\ntext \\<open>We add authentication for the initiator and responder to the basic\nserver-based key transport protocol: \n\\begin{enumerate}\n\\item the initiator injectively agrees with the server on the key and some\nadditional data\n\\item the responder non-injectively agrees with the server on the key and \nsome additional data.\n\\end{enumerate}\nThe \"additional data\" is a parameter of this model.\\<close>\n\ndeclare option.split [split]\n(* declare option.split_asm [split] *)\n\nconsts\n  na :: \"nat\"\n\n(******************************************************************************)\nsubsection \\<open>State\\<close>\n(******************************************************************************)\n\ntext \\<open>The state type remains the same, but in this model we will record\nnonces and timestamps in the run frame.\\<close>\n\ntype_synonym m1a_state = \"m1x_state\"\ntype_synonym m1a_obs = \"m1x_obs\"\n\ntype_synonym 'x m1a_pred = \"'x m1x_pred\"\ntype_synonym 'x m1a_trans = \"'x m1x_trans\"\n\n\ntext \\<open>We need some parameters regarding the list of freshness values\nstored by the server. These   should be defined in further refinements.\\<close>\n\nconsts \n  is_len :: \"nat\"   \\<comment> \\<open>num of agreeing list elements for initiator-server\\<close>  \n  rs_len :: \"nat\"   \\<comment> \\<open>num of agreeing list elements for responder-server\\<close>\n\n\n(******************************************************************************)\nsubsection \\<open>Events\\<close>\n(******************************************************************************)\n\ndefinition         \\<comment> \\<open>by @{term \"A\"}, refines @{term \"m1x_step1\"}\\<close>\n  m1a_step1 :: \"[rid_t, agent, agent, nonce] \\<Rightarrow> 'x m1r_trans\"\nwhere\n  \"m1a_step1 Ra A B Na \\<equiv> {(s, s1).\n    \\<comment> \\<open>guards:\\<close>\n    Ra \\<notin> dom (runs s) \\<and>                \\<comment> \\<open>\\<open>Ra\\<close> is fresh\\<close>\n    Na = Ra$na \\<and>                       \\<comment> \\<open>NEW: generate a nonce\\<close>\n\n    \\<comment> \\<open>actions:\\<close>\n    \\<comment> \\<open>create initiator thread\\<close>\n    s1 = s\\<lparr> runs := (runs s)(Ra \\<mapsto> (Init, [A, B], [])) \\<rparr>\n  }\"\n\ndefinition       \\<comment> \\<open>by @{term \"B\"}, refines @{term \"m1x_step2\"}\\<close>\n  m1a_step2 :: \"[rid_t, agent, agent] \\<Rightarrow> 'x m1r_trans\"\nwhere\n  \"m1a_step2 \\<equiv> m1x_step2\"\n\ndefinition       \\<comment> \\<open>by @{term \"Server\"}, refines @{term m1x_step3}\\<close>\n  m1a_step3 :: \"[rid_t, agent, agent, key, nonce, atom list] \\<Rightarrow> 'x m1r_trans\"\nwhere\n  \"m1a_step3 Rs A B Kab Na al \\<equiv> {(s, s1).\n     \\<comment> \\<open>guards:\\<close>\n     Rs \\<notin> dom (runs s) \\<and>                 \\<comment> \\<open>fresh run id\\<close>\n     Kab = sesK (Rs$sk) \\<and>                \\<comment> \\<open>generate session key\\<close>\n\n     \\<comment> \\<open>actions:\\<close>\n     s1 = s\\<lparr> runs := (runs s)(Rs \\<mapsto> (Serv, [A, B], aNon Na # al)) \\<rparr>\n  }\"\n\ndefinition         \\<comment> \\<open>by @{text \"A\"}, refines @{term m1x_step4}\\<close>\n  m1a_step4 :: \"[rid_t, agent, agent, nonce, key, atom list] \\<Rightarrow> 'x m1a_trans\"\nwhere\n  \"m1a_step4 Ra A B Na Kab nla \\<equiv> {(s, s').\n     \\<comment> \\<open>guards:\\<close>\n     runs s Ra = Some (Init, [A, B], []) \\<and>\n     (Kab \\<notin> leak s \\<longrightarrow> (Kab, A) \\<in> azC (runs s)) \\<and>  \\<comment> \\<open>authorization guard\\<close>\n     Na = Ra$na \\<and>                                   \\<comment> \\<open>fix parameter\\<close>\n\n     \\<comment> \\<open>new guard for agreement with server on \\<open>(Kab, B, Na, isl)\\<close>,\\<close>\n     \\<comment> \\<open>where \\<open>isl = take is_len nla\\<close>; injectiveness by including \\<open>Na\\<close>\\<close>\n     (A \\<notin> bad \\<longrightarrow> (\\<exists>Rs. Kab = sesK (Rs$sk) \\<and>\n        runs s Rs = Some (Serv, [A, B], aNon Na # take is_len nla))) \\<and>\n\n     \\<comment> \\<open>actions:\\<close>\n     s' = s\\<lparr> runs := (runs s)(Ra \\<mapsto> (Init, [A, B], aKey Kab # nla)) \\<rparr>\n  }\" \n\ndefinition         \\<comment> \\<open>by @{term \"B\"}, refines @{term m1x_step5}\\<close>\n  m1a_step5 :: \"[rid_t, agent, agent, key, atom list] \\<Rightarrow> 'x m1a_trans\"\nwhere\n  \"m1a_step5 Rb A B Kab nlb \\<equiv> {(s, s1). \n     \\<comment> \\<open>guards:\\<close>\n     runs s Rb = Some (Resp, [A, B], []) \\<and> \n     (Kab \\<notin> leak s \\<longrightarrow> (Kab, B) \\<in> azC (runs s)) \\<and>         \\<comment> \\<open>authorization guard\\<close>\n\n     \\<comment> \\<open>guard for showing agreement with server on \\<open>(Kab, A, rsl)\\<close>,\\<close>\n     \\<comment> \\<open>where \\<open>rsl = take rs_len nlb\\<close>; this agreement is non-injective\\<close>\n\n     (B \\<notin> bad \\<longrightarrow> (\\<exists>Rs Na. Kab = sesK (Rs$sk) \\<and>\n        runs s Rs = Some (Serv, [A, B], aNon Na # take rs_len nlb))) \\<and>\n\n     \\<comment> \\<open>actions:\\<close>\n     s1 = s\\<lparr> runs := (runs s)(Rb \\<mapsto> (Resp, [A, B], aKey Kab # nlb)) \\<rparr>\n  }\"\n\ndefinition     \\<comment> \\<open>by attacker, refines @{term m1x_leak}\\<close>\n  m1a_leak :: \"rid_t \\<Rightarrow> 'x m1x_trans\"\nwhere\n  \"m1a_leak = m1x_leak\" \n\n\n(******************************************************************************)\nsubsection \\<open>Specification\\<close>\n(******************************************************************************)\n\ndefinition\n  m1a_init :: \"m1a_state set\"\nwhere\n  \"m1a_init \\<equiv> m1x_init\" \n\ndefinition \n  m1a_trans :: \"'x m1a_trans\" where\n  \"m1a_trans \\<equiv> (\\<Union>A B Ra Rb Rs Na Kab nls nla nlb.\n     m1a_step1 Ra A B Na \\<union>\n     m1a_step2 Rb A B \\<union>\n     m1a_step3 Rs A B Kab Na nls \\<union>\n     m1a_step4 Ra A B Na Kab nla \\<union>\n     m1a_step5 Rb A B Kab nlb \\<union>\n     m1a_leak Rs \\<union>\n     Id\n  )\"\n\ndefinition \n  m1a :: \"(m1a_state, m1a_obs) spec\" where\n  \"m1a \\<equiv> \\<lparr>\n     init = m1a_init,\n     trans = m1a_trans,\n     obs = id\n  \\<rparr>\" \n\nlemma init_m1a: \"init m1a = m1a_init\"\nby (simp add: m1a_def)\n\nlemma trans_m1a: \"trans m1a = m1a_trans\"\nby (simp add: m1a_def)\n\nlemma obs_m1a [simp]: \"obs m1a = id\"\nby (simp add: m1a_def)\n\nlemmas m1a_loc_defs = \n  m1a_def m1a_init_def m1a_trans_def\n  m1a_step1_def m1a_step2_def m1a_step3_def m1a_step4_def m1a_step5_def \n  m1a_leak_def \n\nlemmas m1a_defs = m1a_loc_defs m1x_defs\n\n\n(******************************************************************************)\nsubsection \\<open>Invariants\\<close>\n(******************************************************************************)\n\nsubsubsection \\<open>inv0: Finite domain\\<close>\n(*inv**************************************************************************)\n\ntext \\<open>There are only finitely many runs. This is needed to establish\nthe responder/initiator agreement.\\<close>\n\ndefinition \n  m1a_inv0_fin :: \"'x m1r_pred\"\nwhere\n  \"m1a_inv0_fin \\<equiv> {s. finite (dom (runs s))}\"\n\nlemmas m1a_inv0_finI = m1a_inv0_fin_def [THEN setc_def_to_intro, rule_format]\nlemmas m1a_inv0_finE [elim] = m1a_inv0_fin_def [THEN setc_def_to_elim, rule_format]\nlemmas m1a_inv0_finD = m1a_inv0_fin_def [THEN setc_def_to_dest, rule_format]\n\ntext \\<open>Invariance proof.\\<close>\n\nlemma PO_m1a_inv0_fin_init [iff]:\n  \"init m1a \\<subseteq> m1a_inv0_fin\"\nby (auto simp add: m1a_defs intro!: m1a_inv0_finI)\n\n\n\nlemma PO_m1a_inv0_fin [iff]: \"reach m1a \\<subseteq> m1a_inv0_fin\"\nby (rule inv_rule_incr, auto del: subsetI)\n\n\n(******************************************************************************)\nsubsection \\<open>Refinement of \\<open>m1x\\<close>\\<close>\n(******************************************************************************)\n\nsubsubsection \\<open>Simulation relation\\<close>\n(******************************************************************************)\n\ntext \\<open>Define run abstraction.\\<close>\n\nfun \n  rm1x1a :: \"role_t \\<Rightarrow> atom list \\<Rightarrow> atom list\"\nwhere\n  \"rm1x1a Init = take 1\"         \\<comment> \\<open>take \\<open>Kab\\<close> from \\<open>Kab # nla\\<close>\\<close>\n| \"rm1x1a Resp = take 1\"         \\<comment> \\<open>take \\<open>Kab\\<close> from \\<open>Kab # nlb\\<close>\\<close>\n| \"rm1x1a Serv = take 0\"         \\<comment> \\<open>drop all from \\<open>[Na]\\<close>\\<close>\n\nabbreviation \n  runs1x1a :: \"runs_t \\<Rightarrow> runs_t\" where \n  \"runs1x1a \\<equiv> map_runs rm1x1a\"\n\ntext \\<open>med1x1: The mediator function maps a concrete observation to an \nabstract one.\\<close>\n\ndefinition\n  med1x1a :: \"m1a_obs \\<Rightarrow> m1x_obs\" where\n  \"med1x1a t \\<equiv> \\<lparr> runs = runs1x1a (runs t), leak = leak t \\<rparr>\"\n\ntext \\<open>R1x1a: The simulation relation is defined in terms of the mediator\nfunction.\\<close>\n\ndefinition\n  R1x1a :: \"(m1x_state \\<times> m1a_state) set\" where\n  \"R1x1a \\<equiv> {(s, t). s = med1x1a t}\"\n\nlemmas R1x1a_defs = \n  R1x1a_def med1x1a_def \n\n\nsubsubsection \\<open>Refinement proof\\<close>\n(******************************************************************************)\n\nlemma PO_m1a_step1_refines_m1x_step1:\n  \"{R1x1a} \n     (m1x_step1 Ra A B), (m1a_step1 Ra A B Na) \n   {> R1x1a}\"\nby (auto simp add: PO_rhoare_defs R1x1a_defs m1a_defs)\n\nlemma PO_m1a_step2_refines_m1x_step2:\n  \"{R1x1a} \n     (m1x_step2 Rb A B), (m1a_step2 Rb A B) \n   {> R1x1a}\"\nby (auto simp add: PO_rhoare_defs R1x1a_defs m1a_defs)\n\nlemma PO_m1a_step3_refines_m1x_step3:\n  \"{R1x1a} \n     (m1x_step3 Rs A B Kab), (m1a_step3 Rs A B Kab Na nls)\n   {> R1x1a}\"\nby (auto simp add: PO_rhoare_defs R1x1a_defs m1a_defs)\n\nlemma PO_m1a_step4_refines_m1x_step4:\n  \"{R1x1a} \n     (m1x_step4 Ra A B Kab), (m1a_step4 Ra A B Na Kab nla) \n   {> R1x1a}\"\nby (auto simp add: PO_rhoare_defs R1x1a_defs m1a_defs map_runs_def)\n\nlemma PO_m1a_step5_refines_m1x_step5:\n  \"{R1x1a} \n     (m1x_step5 A B Rb Kab), (m1a_step5 A B Rb Kab nlb) \n   {> R1x1a}\"\nby (auto simp add: PO_rhoare_defs R1x1a_defs m1a_defs map_runs_def)\n\nlemma PO_m1a_leak_refines_m1x_leak:\n  \"{R1x1a} \n     (m1x_leak Rs), (m1a_leak Rs) \n   {> R1x1a}\"\nby (auto simp add: PO_rhoare_defs R1x1a_defs m1a_defs map_runs_def)\n\n\ntext \\<open>All together now...\\<close>\n\nlemmas PO_m1a_trans_refines_m1x_trans = \n  PO_m1a_step1_refines_m1x_step1 PO_m1a_step2_refines_m1x_step2\n  PO_m1a_step3_refines_m1x_step3 PO_m1a_step4_refines_m1x_step4\n  PO_m1a_step5_refines_m1x_step5 PO_m1a_leak_refines_m1x_leak\n\n\nlemma PO_m1a_refines_init_m1x [iff]:\n  \"init m1a \\<subseteq>  R1x1a``(init m1x)\"\nby (auto simp add: R1x1a_defs m1a_defs)\n\nlemma PO_m1a_refines_trans_m1x [iff]:\n  \"{R1x1a} \n     (trans m1x), (trans m1a) \n   {> R1x1a}\"\napply (auto simp add: m1a_def m1a_trans_def m1x_def m1x_trans_def\n            intro!: PO_m1a_trans_refines_m1x_trans)\napply (force intro!: PO_m1a_trans_refines_m1x_trans)+\ndone\n\ntext \\<open>Observation consistency.\\<close>\n\nlemma obs_consistent_med1x1a [iff]: \n  \"obs_consistent R1x1a med1x1a m1x m1a\"\nby (auto simp add: obs_consistent_def R1x1a_def m1a_defs)\n\n\ntext \\<open>Refinement result.\\<close>\n\nlemma PO_m1a_refines_m1x [iff]: \n  \"refines R1x1a med1x1a m1x m1a\"\nby (rule Refinement_basic) (auto del: subsetI)\n\nlemma  m1a_implements_m1x [iff]: \"implements med1x1a m1x m1a\"\nby (rule refinement_soundness) (fast)\n\ntext \\<open>By transitivity:\\<close>\n\nlemma m1a_implements_s0g [iff]: \"implements (med01x o med1x1a) s0g m1a\"\nby (rule implements_trans, auto)\n\n\nsubsubsection \\<open>inv (inherited): Secrecy\\<close>\n(*invh*************************************************************************)\n\ntext \\<open>Secrecy preserved from \\<open>m1x\\<close>.\\<close>\n\nlemma knC_runs1x1a [simp]: \"knC (runs1x1a runz) = knC runz\"\napply (auto simp add: map_runs_def elim!: knC.cases, auto)\n\\<comment> \\<open>5 subgoals\\<close>\napply (rename_tac b, case_tac b, auto)\napply (rename_tac b, case_tac b, auto)\napply (rule knC_init, auto simp add: map_runs_def)\napply (rule knC_resp, auto simp add: map_runs_def)\napply (rule knC_serv, auto simp add: map_runs_def)\ndone\n\nlemma PO_m1a_obs_secrecy [iff]: \"oreach m1a \\<subseteq> m1x_secrecy\"\napply (rule_tac Q=m1x_secrecy in external_invariant_translation)\napply (auto del: subsetI)\napply (auto simp add: med1x1a_def m1x_secrecy_def)\ndone\n\nlemma PO_m1a_secrecy [iff]: \"reach m1a \\<subseteq> m1x_secrecy\"\nby (rule external_to_internal_invariant) (auto del: subsetI)\n\n\n(******************************************************************************)\nsubsection \\<open>Refinement of \\<open>a0i\\<close> for initiator/server\\<close>\n(******************************************************************************)\n\ntext \\<open>For the initiator, we get an injective agreement with the server on \nthe session key, the responder name, the initiator's nonce and the list of \nfreshness values @{term \"isl\"}.\\<close>\n\n\nsubsubsection \\<open>Simulation relation\\<close>\n(******************************************************************************)\n\ntext \\<open>We define two auxiliary functions to reconstruct the signals of the\ninitial model from completed initiator and server runs.\\<close>\n\ntype_synonym \n  issig = \"key \\<times> agent \\<times> nonce \\<times> atom list\"\n\nfun\n  is_runs2sigs :: \"runs_t \\<Rightarrow> issig signal \\<Rightarrow> nat\"\nwhere\n  \"is_runs2sigs runz (Running [A, Sv] (Kab, B, Na, nl)) = \n     (if \\<exists>Rs. Kab = sesK (Rs$sk) \\<and> \n         runz Rs = Some (Serv, [A, B], aNon Na # nl) \n      then 1 else 0)\"\n\n| \"is_runs2sigs runz (Commit [A, Sv] (Kab, B, Na, nl)) = \n     (if \\<exists>Ra nla. Na = Ra$na \\<and> \n         runz Ra = Some (Init, [A, B], aKey Kab # nla) \\<and> \n         take is_len nla = nl\n      then 1 else 0)\"\n\n| \"is_runs2sigs runz _ = 0\"\n\n\ntext \\<open>Simulation relation and mediator function. We map completed initiator \nand responder runs to commit and running signals, respectively.\\<close>\n\ndefinition \n  med_a0m1a_is :: \"m1a_obs \\<Rightarrow> issig a0i_obs\" where\n  \"med_a0m1a_is o1 \\<equiv> \\<lparr> signals = is_runs2sigs (runs o1), corrupted = {} \\<rparr>\"\n\ndefinition\n  R_a0m1a_is :: \"(issig a0i_state \\<times> m1a_state) set\" where\n  \"R_a0m1a_is \\<equiv> {(s, t). signals s = is_runs2sigs (runs t) \\<and> corrupted s = {} }\"\n\nlemmas R_a0m1a_is_defs = R_a0m1a_is_def med_a0m1a_is_def \n\n\nsubsubsection \\<open>Lemmas about the auxiliary functions\\<close>\n(******************************************************************************)\n\nlemma is_runs2sigs_empty [simp]: \n  \"runz = Map.empty \\<Longrightarrow> is_runs2sigs runz = (\\<lambda>s. 0)\"\nby (rule ext, erule rev_mp) \n   (rule is_runs2sigs.induct, auto)\n\n\ntext \\<open>Update lemmas\\<close>\n\nlemma is_runs2sigs_upd_init_none [simp]:\n  \"\\<lbrakk> Ra \\<notin> dom runz \\<rbrakk>\n  \\<Longrightarrow> is_runs2sigs (runz(Ra \\<mapsto> (Init, [A, B], []))) = is_runs2sigs runz\"\nby (rule ext, erule rev_mp) \n   (rule is_runs2sigs.induct, auto dest: dom_lemmas)\n\nlemma is_runs2sigs_upd_resp_none [simp]:\n  \"\\<lbrakk> Rb \\<notin> dom runz \\<rbrakk>\n  \\<Longrightarrow> is_runs2sigs (runz(Rb \\<mapsto> (Resp, [A, B], []))) = is_runs2sigs runz\"\nby (rule ext, erule rev_mp) \n   (rule is_runs2sigs.induct, auto dest: dom_lemmas)\n\nlemma is_runs2sigs_upd_serv [simp]:\n  \"\\<lbrakk> Rs \\<notin> dom runz \\<rbrakk>\n  \\<Longrightarrow> is_runs2sigs (runz(Rs \\<mapsto> (Serv, [A, B], aNon Na # ils))) = \n     (is_runs2sigs runz)(Running [A, Sv] (sesK (Rs$sk), B, Na, ils) := 1)\"\napply (rule ext, (erule rev_mp)+) \napply (rule is_runs2sigs.induct)\napply (safe, simp_all)+\napply (fastforce simp add: domIff)+\ndone\n\nlemma is_runs2sigs_upd_init_some [simp]:\n  \"\\<lbrakk> runz Ra = Some (Init, [A, B], []); ils = take is_len nla \\<rbrakk>\n  \\<Longrightarrow> is_runs2sigs (runz(Ra \\<mapsto> (Init, [A, B], aKey Kab # nla))) =\n     (is_runs2sigs runz)(Commit [A, Sv] (Kab, B, Ra$na, ils) := 1)\"\napply (rule ext, (erule rev_mp)+)\napply (rule is_runs2sigs.induct)\napply (safe, simp_all)+ \napply (fastforce)+\ndone\n\nlemma is_runs2sigs_upd_resp_some [simp]:\n  \"\\<lbrakk> runz Rb = Some (Resp, [A, B], []) \\<rbrakk>\n  \\<Longrightarrow> is_runs2sigs (runz(Rb \\<mapsto> (Resp, [A, B], aKey Kab # nlb))) =\n     is_runs2sigs runz\" \napply (rule ext, erule rev_mp)\napply (rule is_runs2sigs.induct, auto)  \ndone\n\n\nsubsubsection \\<open>Refinement proof\\<close>\n(******************************************************************************)\n\nlemma PO_m1a_step1_refines_a0_is_skip:\n  \"{R_a0m1a_is} \n     Id, (m1a_step1 Ra A B Na) \n   {> R_a0m1a_is}\"\nby (auto simp add: PO_rhoare_defs R_a0m1a_is_defs m1a_defs)\n\nlemma PO_m1a_step2_refines_a0_is_skip:\n  \"{R_a0m1a_is} \n     Id, (m1a_step2 Rb A B) \n   {> R_a0m1a_is}\"\nby (auto simp add: PO_rhoare_defs R_a0m1a_is_defs m1a_defs)\n\nlemma PO_m1a_step3_refines_a0_is_running:\n  \"{R_a0m1a_is} \n     (a0i_running [A, Sv] (Kab, B, Na, nls)), \n     (m1a_step3 Rs A B Kab Na nls) \n   {> R_a0m1a_is}\"\nby (auto simp add: PO_rhoare_defs R_a0m1a_is_defs a0i_defs m1a_defs \n         dest: dom_lemmas)\n\nlemma PO_m1a_step4_refines_a0_is_commit:\n  \"{R_a0m1a_is \\<inter> UNIV \\<times> m1a_inv0_fin} \n     (a0i_commit [A, Sv] (Kab, B, Na, take is_len nla)), \n     (m1a_step4 Ra A B Na Kab nla) \n   {> R_a0m1a_is}\"\nby (auto simp add: PO_rhoare_defs R_a0m1a_is_defs a0i_defs m1a_defs)\n\nlemma PO_m1a_step5_refines_a0_is_skip:\n  \"{R_a0m1a_is} \n     Id, (m1a_step5 A B Rb Kab nlb) \n   {> R_a0m1a_is}\"\nby (auto simp add: PO_rhoare_defs R_a0m1a_is_defs m1a_defs)\n\nlemma PO_m1a_leak_refines_a0_is_skip:\n  \"{R_a0m1a_is} \n     Id, (m1a_leak Rs) \n   {> R_a0m1a_is}\"\nby (auto simp add: PO_rhoare_defs R_a0m1a_is_defs m1a_defs)\n\ntext \\<open>All together now...\\<close>\n\nlemmas PO_m1a_trans_refines_a0_is_trans = \n  PO_m1a_step1_refines_a0_is_skip PO_m1a_step2_refines_a0_is_skip\n  PO_m1a_step3_refines_a0_is_running PO_m1a_step4_refines_a0_is_commit\n  PO_m1a_step5_refines_a0_is_skip PO_m1a_leak_refines_a0_is_skip\n  \n\nlemma PO_m1a_refines_init_a0_is [iff]:\n  \"init m1a \\<subseteq>  R_a0m1a_is``(init a0i)\"\nby (auto simp add: R_a0m1a_is_defs a0i_defs m1a_defs)\n\nlemma PO_m1a_refines_trans_a0_is [iff]:\n  \"{R_a0m1a_is \\<inter> a0i_inv1_iagree \\<times> m1a_inv0_fin} \n     (trans a0i), (trans m1a) \n   {> R_a0m1a_is}\"\nby (force simp add: m1a_def m1a_trans_def a0i_def a0i_trans_def\n          intro!: PO_m1a_trans_refines_a0_is_trans)\n\nlemma obs_consistent_med_a0m1a_is [iff]: \n  \"obs_consistent R_a0m1a_is med_a0m1a_is a0i m1a\"\nby (auto simp add: obs_consistent_def R_a0m1a_is_def med_a0m1a_is_def \n                   a0i_def m1a_def)\n\ntext \\<open>Refinement result.\\<close>\n\nlemma PO_m1a_refines_a0_is [iff]: \n  \"refines (R_a0m1a_is \\<inter> a0i_inv1_iagree \\<times> m1a_inv0_fin) med_a0m1a_is a0i m1a\"\nby (rule Refinement_using_invariants) \n   (auto del: subsetI)\n\nlemma  m1a_implements_a0_is: \"implements med_a0m1a_is a0i m1a\"\nby (rule refinement_soundness) (fast)\n\n\nsubsubsection \\<open>inv2i (inherited): Initiator and server\\<close>\n(*invh*************************************************************************)\n\ntext \\<open>This is a translation of the agreement property to Level 1. It\nfollows from the refinement and is needed to prove inv1.\\<close>\n\ndefinition \n  m1a_inv2i_serv :: \"'x m1x_state_scheme set\"\nwhere\n  \"m1a_inv2i_serv \\<equiv> {s. \\<forall>A B Ra Kab nla.\n     A \\<notin> bad \\<longrightarrow>\n     runs s Ra = Some (Init, [A, B], aKey Kab # nla) \\<longrightarrow>\n       (\\<exists>Rs. Kab = sesK (Rs$sk) \\<and> \n         runs s Rs = Some (Serv, [A, B], aNon (Ra$na) # take is_len nla))\n  }\"\n\nlemmas m1a_inv2i_servI = \n  m1a_inv2i_serv_def [THEN setc_def_to_intro, rule_format]\nlemmas m1a_inv2i_servE =     (* DO NOT declare elim: leads to slow proofs! *)\n  m1a_inv2i_serv_def [THEN setc_def_to_elim, rule_format]\nlemmas m1a_inv2i_servD =     (* DO NOT declare dest: leads to slow proofs! *)\n  m1a_inv2i_serv_def [THEN setc_def_to_dest, rule_format, rotated -1]\n\n\ntext \\<open>Invariance proof, see below after init/serv authentication proof.\\<close>\n\nlemma PO_m1a_inv2i_serv [iff]:\n  \"reach m1a \\<subseteq> m1a_inv2i_serv\"\napply (rule INV_from_Refinement_basic [OF PO_m1a_refines_a0_is])\napply (auto simp add: R_a0m1a_is_def a0i_inv1_iagree_def \n            intro!: m1a_inv2i_servI)\napply (drule_tac x=\"[A, Sv]\" in spec, force)\ndone\n\n\nsubsubsection \\<open>inv1: Key freshness for initiator\\<close>\n(*inv**************************************************************************)\n\ntext \\<open>The initiator obtains key freshness from the injective agreement\nwith the server AND the fact that there is only one server run with a \ngiven key.\\<close>\n\ndefinition \n  m1a_inv1_ifresh :: \"'x m1a_pred\"\nwhere\n  \"m1a_inv1_ifresh \\<equiv> {s. \\<forall>A A' B B' Ra Ra' Kab nl nl'.\n     runs s Ra  = Some (Init, [A,  B],  aKey Kab # nl) \\<longrightarrow>\n     runs s Ra' = Some (Init, [A', B'], aKey Kab # nl') \\<longrightarrow>\n     A \\<notin> bad \\<longrightarrow> B \\<notin> bad \\<longrightarrow> Kab \\<notin> leak s \\<longrightarrow>\n       Ra = Ra'\n  }\"\n\nlemmas m1a_inv1_ifreshI = m1a_inv1_ifresh_def [THEN setc_def_to_intro, rule_format]\nlemmas m1a_inv1_ifreshE [elim] = m1a_inv1_ifresh_def [THEN setc_def_to_elim, rule_format]\nlemmas m1a_inv1_ifreshD = m1a_inv1_ifresh_def [THEN setc_def_to_dest, rule_format, rotated 1]\n\n\ntext \\<open>Invariance proof\\<close>\n\nlemma PO_m1a_inv1_ifresh_init [iff]:\n  \"init m1a \\<subseteq> m1a_inv1_ifresh\"\nby (auto simp add: m1a_defs intro!: m1a_inv1_ifreshI)\n\n\nlemma PO_m1a_inv1_ifresh_step4:\n  \"{m1a_inv1_ifresh \\<inter> m1a_inv2i_serv \\<inter> m1x_secrecy} \n      m1a_step4 Ra A B Na Kab nla\n   {> m1a_inv1_ifresh}\"\nproof (auto simp add: PO_hoare_defs m1a_defs intro!: m1a_inv1_ifreshI,  (* UGLY *)\n       auto dest: m1a_inv1_ifreshD, auto dest: m1a_inv2i_servD)\n  fix Rs Ra' A' B' nl' s \n  assume H: \n    \"(sesK (Rs $ sk), A) \\<in> azC (runs s)\" \"sesK (Rs $ sk) \\<notin> leak s\" \n    \"A \\<notin> bad\" \"B \\<notin> bad\" \"Ra' \\<noteq> Ra\"\n    \"runs s Ra = Some (Init, [A, B], [])\" \n    \"runs s Rs = Some (Serv, [A, B], aNon (Ra $ na) # take is_len nla)\" \n    \"runs s Ra' = Some (Init, [A', B'], aKey (sesK (Rs $ sk)) # nl')\"\n    \"s \\<in> m1x_secrecy\" \"s \\<in> m1a_inv2i_serv\" \n  thus False\n  proof (cases \"A' \\<in> bad\")\n    case True \n    from H have \"(sesK (Rs$sk), A') \\<in> azC (runs s)\" by (elim m1x_secrecyE, auto) \n    with H True show ?thesis by (elim azC.cases) (auto dest: m1a_inv2i_servD) \n  next \n    case False thus ?thesis using H by (auto dest: m1a_inv2i_servD)\n  qed\nnext\n  fix A' B' Ra' nl s\n  assume \n    \"(Kab, A) \\<in> azC (runs s)\" \"Kab \\<notin> leak s\" \n    \"A' \\<notin> bad\"  \"B' \\<notin> bad\" \"A \\<in> bad\" \"Ra' \\<noteq> Ra\"\n    \"runs s Ra' = Some (Init, [A', B'], aKey Kab # nl)\"\n    \"runs s Ra = Some (Init, [A, B], [])\"\n    \"s \\<in> m1a_inv2i_serv\" \n  thus False \n  by (elim azC.cases, auto dest: m1a_inv2i_servD)\nqed \n\nlemma PO_m1a_inv1_ifresh_trans [iff]:\n  \"{m1a_inv1_ifresh \\<inter> m1a_inv2i_serv \\<inter> m1x_secrecy} trans m1a {> m1a_inv1_ifresh}\"\nproof (simp add: m1a_def m1a_trans_def, safe)\n  fix Ra A B Kab Ts nla\n  show\n    \"{m1a_inv1_ifresh \\<inter> m1a_inv2i_serv \\<inter> m1x_secrecy} \n        m1a_step4 Ra A B Kab Ts nla\n     {> m1a_inv1_ifresh}\"\n  by (rule PO_m1a_inv1_ifresh_step4)\nqed (auto simp add: PO_hoare_defs m1a_defs intro!: m1a_inv1_ifreshI)\n\nlemma PO_m1a_inv1_ifresh [iff]: \"reach m1a \\<subseteq> m1a_inv1_ifresh\"\nby (rule_tac J=\" m1a_inv2i_serv \\<inter> m1x_secrecy\" in inv_rule_incr) \n   (auto simp add: Int_assoc del: subsetI)\n\n\n(******************************************************************************)\nsubsection \\<open>Refinement of \\<open>a0n\\<close> for responder/server\\<close>\n(******************************************************************************)\n\ntext \\<open>For the responder, we get a non-injective agreement with the server on \nthe session key, the initiator's name, and additional data.\\<close>\n\n\nsubsubsection \\<open>Simulation relation\\<close>\n(******************************************************************************)\n\ntext \\<open>We define two auxiliary functions to reconstruct the signals of the\ninitial model from completed responder and server runs.\\<close>\n\ntype_synonym\n  rssig = \"key \\<times> agent \\<times> atom list\"\n\nabbreviation\n  rs_commit :: \"[runs_t, agent, agent, key, atom list] \\<Rightarrow> rid_t set\" \nwhere\n  \"rs_commit runz A B Kab rsl \\<equiv> {Rb. \\<exists>nlb. \n     runz Rb = Some (Resp, [A, B], aKey Kab # nlb) \\<and> take rs_len nlb = rsl \n  }\"\n\nfun\n  rs_runs2sigs :: \"runs_t \\<Rightarrow> rssig signal \\<Rightarrow> nat\"\nwhere\n  \"rs_runs2sigs runz (Running [B, Sv] (Kab, A, rsl)) = \n     (if (\\<exists>Rs Na. Kab = sesK (Rs$sk) \\<and> \n           runz Rs = Some (Serv, [A, B], aNon Na # rsl)) \n      then 1 else 0)\"\n\n| \"rs_runs2sigs runz (Commit [B, Sv] (Kab, A, rsl)) = \n     card (rs_commit runz A B Kab rsl)\"\n\n| \"rs_runs2sigs runz _ = 0\"\n\n\ntext \\<open>Simulation relation and mediator function. We map completed initiator \nand responder runs to commit and running signals, respectively.\\<close>\n\ndefinition \n  med_a0m1a_rs :: \"m1a_obs \\<Rightarrow> rssig a0n_obs\" where\n  \"med_a0m1a_rs o1 \\<equiv> \\<lparr> signals = rs_runs2sigs (runs o1), corrupted = {} \\<rparr>\"\n\ndefinition\n  R_a0m1a_rs :: \"(rssig a0n_state \\<times> m1a_state) set\" where\n  \"R_a0m1a_rs \\<equiv> {(s, t). signals s = rs_runs2sigs (runs t) \\<and> corrupted s = {} }\"\n\nlemmas R_a0m1a_rs_defs = R_a0m1a_rs_def med_a0m1a_rs_def \n\n\nsubsubsection \\<open>Lemmas about the auxiliary functions\\<close>\n(******************************************************************************)\n\ntext \\<open>Other lemmas\\<close>\n\nlemma rs_runs2sigs_empty [simp]: \n  \"runz = Map.empty \\<Longrightarrow> rs_runs2sigs runz = (\\<lambda>s. 0)\"\nby (rule ext, erule rev_mp) \n   (rule rs_runs2sigs.induct, auto)\n\nlemma rs_commit_finite [simp, intro]:\n  \"finite (dom runz) \\<Longrightarrow> finite (rs_commit runz A B Kab nls)\"\nby (auto intro: finite_subset dest: dom_lemmas)\n\n\ntext \\<open>Update lemmas\\<close>\n\nlemma rs_runs2sigs_upd_init_none [simp]:\n  \"\\<lbrakk> Ra \\<notin> dom runz \\<rbrakk>\n  \\<Longrightarrow> rs_runs2sigs (runz(Ra \\<mapsto> (Init, [A, B], []))) = rs_runs2sigs runz\"\nby (rule ext, erule rev_mp) \n   (rule rs_runs2sigs.induct, auto dest: dom_lemmas)\n\nlemma rs_runs2sigs_upd_resp_none [simp]:\n  \"\\<lbrakk> Rb \\<notin> dom runz \\<rbrakk>\n  \\<Longrightarrow> rs_runs2sigs (runz(Rb \\<mapsto> (Resp, [A, B], []))) = rs_runs2sigs runz\"\nby (rule ext, erule rev_mp) \n   (rule rs_runs2sigs.induct, auto dest: dom_lemmas)\n\nlemma rs_runs2sigs_upd_serv [simp]:\n  \"\\<lbrakk> Rs \\<notin> dom runz \\<rbrakk>\n  \\<Longrightarrow> rs_runs2sigs (runz(Rs \\<mapsto> (Serv, [A, B], aNon Na # nls))) = \n     (rs_runs2sigs runz)(Running [B, Sv] (sesK (Rs$sk), A, nls) := 1)\"\nby (rule ext, erule rev_mp) \n   (rule rs_runs2sigs.induct, auto dest: dom_lemmas)\n\nlemma rs_runs2sigs_upd_init_some [simp]:\n  \"\\<lbrakk> runz Ra = Some (Init, [A, B], []) \\<rbrakk>\n  \\<Longrightarrow> rs_runs2sigs (runz(Ra \\<mapsto> (Init, [A, B], aKey Kab # nl))) =\n     rs_runs2sigs runz\" \nby (rule ext, erule rev_mp)\n   (rule rs_runs2sigs.induct, auto dest: dom_lemmas)  \n\nlemma rs_runs2sigs_upd_resp_some [simp]:\n  \"\\<lbrakk> runz Rb = Some (Resp, [A, B], []); finite (dom runz);\n     rsl = take rs_len nlb \\<rbrakk>\n \\<Longrightarrow> rs_runs2sigs (runz(Rb \\<mapsto> (Resp, [A, B], aKey Kab # nlb))) =\n   (rs_runs2sigs runz)(\n      Commit [B, Sv] (Kab, A, rsl) := Suc (card (rs_commit runz A B Kab rsl)))\"\napply (rule ext, (erule rev_mp)+) \napply (rule rs_runs2sigs.induct, auto dest: dom_lemmas)\n\\<comment> \\<open>1 subgoal\\<close>\napply (rule_tac s=\"card (insert Rb (rs_commit runz A B Kab (take rs_len nlb)))\" \n       in trans, fast, auto)\ndone\n\n\nsubsubsection \\<open>Refinement proof\\<close>\n(******************************************************************************)\n\nlemma PO_m1a_step1_refines_a0_rs_skip:\n  \"{R_a0m1a_rs} \n     Id, (m1a_step1 Ra A B Na) \n   {> R_a0m1a_rs}\"\nby (auto simp add: PO_rhoare_defs R_a0m1a_rs_defs m1a_defs)\n\nlemma PO_m1a_step2_refines_a0_rs_skip:\n  \"{R_a0m1a_rs} \n     Id, (m1a_step2 Rb A B) \n   {> R_a0m1a_rs}\"\nby (auto simp add: PO_rhoare_defs R_a0m1a_rs_defs m1a_defs)\n\nlemma PO_m1a_step3_refines_a0_rs_running:\n  \"{R_a0m1a_rs} \n     (a0n_running [B, Sv] (Kab, A, nls)), \n     (m1a_step3 Rs A B Kab Na nls) \n   {> R_a0m1a_rs}\"\nby (auto simp add: PO_rhoare_defs R_a0m1a_rs_defs a0i_defs m1a_defs\n         dest: dom_lemmas)\n\nlemma PO_m1a_step4_refines_a0_rs_skip:\n  \"{R_a0m1a_rs} \n     Id, (m1a_step4 Ra A B Na Kab nla) \n   {> R_a0m1a_rs}\"\nby (auto simp add: PO_rhoare_defs R_a0m1a_rs_defs a0i_defs m1a_defs)\n\nlemma PO_m1a_step5_refines_a0_rs_commit:\n  \"{R_a0m1a_rs \\<inter> UNIV \\<times> m1a_inv0_fin} \n     (a0n_commit [B, Sv] (Kab, A, take rs_len nlb)), \n     (m1a_step5 Rb A B Kab nlb) \n   {> R_a0m1a_rs}\"\nby (auto simp add: PO_rhoare_defs R_a0m1a_rs_defs a0i_defs m1a_defs)\n\nlemma PO_m1a_leak_refines_a0_rs_skip:\n  \"{R_a0m1a_rs} \n     Id, (m1a_leak Rs) \n   {> R_a0m1a_rs}\"\nby (auto simp add: PO_rhoare_defs R_a0m1a_rs_defs a0i_defs m1a_defs)\n\n\ntext \\<open>All together now...\\<close>\n\nlemmas PO_m1a_trans_refines_a0_rs_trans = \n  PO_m1a_step1_refines_a0_rs_skip PO_m1a_step2_refines_a0_rs_skip\n  PO_m1a_step3_refines_a0_rs_running PO_m1a_step4_refines_a0_rs_skip\n  PO_m1a_step5_refines_a0_rs_commit PO_m1a_leak_refines_a0_rs_skip\n\n\nlemma PO_m1a_refines_init_ra0n [iff]:\n  \"init m1a \\<subseteq>  R_a0m1a_rs``(init a0n)\"\nby (auto simp add: R_a0m1a_rs_defs a0n_defs m1a_defs)\n\nlemma PO_m1a_refines_trans_ra0n [iff]:\n  \"{R_a0m1a_rs \\<inter> a0n_inv1_niagree \\<times> m1a_inv0_fin} \n     (trans a0n), (trans m1a) \n   {> R_a0m1a_rs}\"\nby (force simp add: m1a_def m1a_trans_def a0n_def a0n_trans_def\n          intro!: PO_m1a_trans_refines_a0_rs_trans)\n\nlemma obs_consistent_med_a0m1a_rs [iff]: \n  \"obs_consistent \n     (R_a0m1a_rs \\<inter> a0n_inv1_niagree \\<times> m1a_inv0_fin) \n     med_a0m1a_rs a0n m1a\"\nby (auto simp add: obs_consistent_def R_a0m1a_rs_def med_a0m1a_rs_def \n                   a0n_def m1a_def)\n\n\ntext \\<open>Refinement result.\\<close>\n\nlemma PO_m1a_refines_a0_rs [iff]: \n  \"refines (R_a0m1a_rs \\<inter> a0n_inv1_niagree \\<times> m1a_inv0_fin) med_a0m1a_rs a0n m1a\"\nby (rule Refinement_using_invariants) (auto)\n\nlemma m1a_implements_ra0n: \"implements med_a0m1a_rs a0n m1a\"\nby (rule refinement_soundness) (fast)\n\n\nsubsubsection \\<open>inv2r (inherited): Responder and server\\<close>\n(*invh*************************************************************************)\n\ntext \\<open>This is a translation of the agreement property to Level 1. It\nfollows from the refinement and not needed here but later.\\<close>\n\ndefinition \n  m1a_inv2r_serv :: \"'x m1x_state_scheme set\"\nwhere\n  \"m1a_inv2r_serv \\<equiv> {s. \\<forall>A B Rb Kab nlb.\n     B \\<notin> bad \\<longrightarrow> \n     runs s Rb = Some (Resp, [A, B], aKey Kab # nlb) \\<longrightarrow>\n       (\\<exists>Rs Na. Kab = sesK (Rs$sk) \\<and>\n        runs s Rs = Some (Serv, [A, B], aNon Na # take rs_len nlb))\n  }\"\n\nlemmas m1a_inv2r_servI = \n  m1a_inv2r_serv_def [THEN setc_def_to_intro, rule_format]\nlemmas m1a_inv2r_servE [elim] = \n  m1a_inv2r_serv_def [THEN setc_def_to_elim, rule_format]\nlemmas m1a_inv2r_servD = \n  m1a_inv2r_serv_def [THEN setc_def_to_dest, rule_format, rotated -1]\n\n\ntext \\<open>Invariance proof\\<close>\n\nlemma PO_m1a_inv2r_serv [iff]:\n  \"reach m1a \\<subseteq> m1a_inv2r_serv\"\napply (rule INV_from_Refinement_basic [OF PO_m1a_refines_a0_rs])\napply (auto simp add: R_a0m1a_rs_def a0n_inv1_niagree_def intro!: m1a_inv2r_servI)\napply (rename_tac x A B Rb Kab nlb a, drule_tac x=\"[B, Sv]\" in spec, clarsimp)\napply (rename_tac x A B Rb Kab nlb a, drule_tac x=\"Kab\" in spec, force)\ndone\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Security_Protocol_Refinement/Key_establish/m1_keydist_iirn.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5506073802837478, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.26026301076539066}}
{"text": "(*******************************************************************************\n\n  Project: Development of Security Protocols by Refinement\n\n  Module:  Auth_simple/m3_sig.thy (Isabelle/HOL 2016-1)\n  ID:      $Id: m3_sig.thy 133852 2017-03-20 15:59:33Z csprenge $\n  Author:  Christoph Sprenger, ETH Zurich <sprenger@inf.ethz.ch>\n\n  One-Way authentication protocols\n  Refinement 3: protocol using signatures\n\n  Copyright (c) 2009-2016 Christoph Sprenger\n  Licence: LGPL\n\n*******************************************************************************)\n\nsection \\<open>Refinement 3a: Signature-based Dolev-Yao Protocol (Variant A)\\<close>\n\ntheory m3_sig imports m2_auth_chan \"../Refinement/Message\"\nbegin\n\ntext \\<open>We implement the channel protocol of the previous refinement with\nsignatures and add a full-fledged Dolev-Yao adversary.  In this variant, the\nadversary is realized using Paulson's closure operators for message derivation\n(as opposed to a collection of one-step derivation events a la Strand spaces).\n\\<close>\n\ntext \\<open>Proof tool configuration. Avoid annoying automatic unfolding of\n\\<open>dom\\<close> (again).\\<close>\n\ndeclare domIff [simp, iff del]\ndeclare analz_into_parts [dest]\n\n\n(******************************************************************************)\nsubsection \\<open>State\\<close>\n(******************************************************************************)\n\ntext \\<open>We extend the state of @{term m1} with insecure and authentic\nchannels between each pair of agents.\\<close>\n\nrecord m3_state = m1_state +\n  IK :: \"msg set\"                             \\<comment> \\<open>intruder knowledge\\<close>\n\ntype_synonym\n  m3_obs = m1_state\n\ndefinition\n  m3_obs :: \"m3_state \\<Rightarrow> m3_obs\" where\n  \"m3_obs s \\<equiv> \\<lparr>\n     runs = runs s\n  \\<rparr>\"\n\n\n(******************************************************************************)\nsubsection \\<open>Events\\<close>\n(******************************************************************************)\n\ndefinition\n  m3_step1 :: \"[rid_t, agent, agent, nonce] \\<Rightarrow> (m3_state \\<times> m3_state) set\"\nwhere\n  \"m3_step1 Ra A B Na \\<equiv> {(s, s1).\n\n     \\<comment> \\<open>guards\\<close>\n     Ra \\<notin> dom (runs s) \\<and>\n     Na = Ra$0 \\<and>\n\n     \\<comment> \\<open>actions\\<close>\n     s1 = s\\<lparr>\n       runs := (runs s)(Ra \\<mapsto> (Init, [A, B], [])),\n       IK := insert \\<lbrace>Agent A, Agent B, Nonce Na\\<rbrace> (IK s)    \\<comment> \\<open>send msg 1\\<close>\n     \\<rparr>\n  }\"\n\ndefinition\n  m3_step2 :: \"[rid_t, agent, agent, nonce, nonce] \\<Rightarrow> (m3_state \\<times> m3_state) set\"\nwhere\n  \"m3_step2 Rb A B Na Nb \\<equiv> {(s, s1).\n\n     \\<comment> \\<open>guards\\<close>\n     Rb \\<notin> dom (runs s) \\<and>\n     Nb = Rb$0 \\<and>\n\n     \\<lbrace>Agent A, Agent B, Nonce Na\\<rbrace> \\<in> IK s \\<and>            \\<comment> \\<open>receive msg 1\\<close>\n\n     \\<comment> \\<open>actions\\<close>\n     s1 = s\\<lparr>\n       runs := (runs s)(Rb \\<mapsto> (Resp, [A, B], [aNon Na])),\n                                                        \\<comment> \\<open>send msg 2\\<close>\n       IK := insert (Crypt (priK B) \\<lbrace>Nonce Nb, Nonce Na, Agent A\\<rbrace>) (IK s)\n     \\<rparr>\n  }\"\n\ndefinition\n  m3_step3 :: \"[rid_t, agent, agent, nonce, nonce] \\<Rightarrow> (m3_state \\<times> m3_state) set\"\nwhere\n  \"m3_step3 Ra A B Na Nb \\<equiv> {(s, s1).\n\n     \\<comment> \\<open>guards\\<close>\n     runs s Ra = Some (Init, [A, B], []) \\<and>\n     Na = Ra$0 \\<and>\n\n     Crypt (priK B) \\<lbrace>Nonce Nb, Nonce Na, Agent A\\<rbrace> \\<in> IK s \\<and> \\<comment> \\<open>recv msg 2\\<close>\n\n     \\<comment> \\<open>actions\\<close>\n     s1 = s\\<lparr>\n       runs := (runs s)(Ra \\<mapsto> (Init, [A, B], [aNon Nb]))\n     \\<rparr>\n  }\"\n\n\ntext \\<open>The intruder messages are now generated by a full-fledged Dolev-Yao\nintruder.\\<close>\n\ndefinition\n  m3_DY_fake :: \"(m3_state \\<times> m3_state) set\"\nwhere\n  \"m3_DY_fake \\<equiv> {(s, s1).\n\n     \\<comment> \\<open>actions:\\<close>\n     s1 = s\\<lparr>\n       IK := synth (analz (IK s))\n     \\<rparr>\n  }\"\n\n\ntext \\<open>Transition system.\\<close>\n\ndefinition\n  m3_init :: \"m3_state set\"\nwhere\n  \"m3_init \\<equiv> { \\<lparr>\n     runs = Map.empty,\n     IK = (Key`priK`bad) \\<union> (Key`range pubK) \\<union> (Key`shrK`bad)\n  \\<rparr> }\"\n\ndefinition\n  m3_trans :: \"(m3_state \\<times> m3_state) set\" where\n  \"m3_trans \\<equiv> (\\<Union> A B Ra Rb Na Nb.\n     m3_step1 Ra A B Na    \\<union>\n     m3_step2 Rb A B Na Nb \\<union>\n     m3_step3 Ra A B Na Nb \\<union>\n     m3_DY_fake         \\<union>\n     Id\n  )\"\n\ndefinition\n  m3 :: \"(m3_state, m3_obs) spec\" where\n  \"m3 \\<equiv> \\<lparr>\n    init = m3_init,\n    trans = m3_trans,\n    obs = m3_obs\n  \\<rparr>\"\n\nlemmas m3_defs =\n  m3_def m3_init_def m3_trans_def m3_obs_def\n  m3_step1_def m3_step2_def m3_step3_def\n  m3_DY_fake_def\n\n\n(******************************************************************************)\nsubsection \\<open>Invariants\\<close>\n(******************************************************************************)\n\ntext \\<open>Specialize injectiveness of parts to enable aggressive application.\\<close>\n\nlemmas parts_Inj_IK = parts.Inj [where H=\"IK s\" for s]\nlemmas analz_Inj_IK = analz.Inj [where H=\"IK s\" for s]\n\n\ntext \\<open>The following invariants do not depend on the protocol messages.\nWe want to keep this compilation refinement from channel protocols to\nfull-fledged Dolev-Yao protocols as generic as possible.\\<close>\n\n\nsubsubsection \\<open>inv1: Long-term key secrecy\\<close>\n(******************************************************************************)\n\ntext \\<open>Private signing keys are secret, that is, the intruder only knows\nprivate keys of corrupted agents.\n\nThe invariant uses the weaker @{term parts} operator instead of the perhaps\nmore intuitive @{term analz} in its premise.  This strengthens the invariant\nand potentially simplifies its proof.\n\\<close>\n\ndefinition\n  m3_inv1_lkeysec :: \"m3_state set\" where\n  \"m3_inv1_lkeysec \\<equiv> {s. \\<forall> A.\n     Key (priK A) \\<in> analz (IK s) \\<longrightarrow> A \\<in> bad\n  }\"\n\nlemmas m3_inv1_lkeysecI =\n  m3_inv1_lkeysec_def [THEN setc_def_to_intro, rule_format]\nlemmas m3_inv1_lkeysecE [elim] =\n  m3_inv1_lkeysec_def [THEN setc_def_to_elim, rule_format]\nlemmas m3_inv1_lkeysecD =\n  m3_inv1_lkeysec_def [THEN setc_def_to_dest, rule_format, rotated 1]\n\n\nlemma PO_m3_inv1_lkeysec_init [iff]:\n  \"init m3 \\<subseteq> m3_inv1_lkeysec\"\nby (auto simp add: PO_hoare_def m3_defs intro!: m3_inv1_lkeysecI)\n\nlemma PO_m3_inv1_lkeysec_trans [iff]:\n  \"{m3_inv1_lkeysec} trans m3 {> m3_inv1_lkeysec}\"\nby (auto simp add: PO_hoare_def m3_defs intro!: m3_inv1_lkeysecI)\n\nlemma PO_m3_inv1_lkeysec [iff]: \"reach m3 \\<subseteq> m3_inv1_lkeysec\"\nby (rule inv_rule_basic) (auto)\n\n\nsubsubsection \\<open>inv2: Intruder knows long-term keys of bad guys\\<close>\n(******************************************************************************)\n\ndefinition\n  m3_inv2_badkeys :: \"m3_state set\"\nwhere\n  \"m3_inv2_badkeys \\<equiv> {s. \\<forall>C.\n     C \\<in> bad \\<longrightarrow> Key (priK C) \\<in> analz (IK s)\n  }\"\n\nlemmas m3_inv2_badkeysI =\n  m3_inv2_badkeys_def [THEN setc_def_to_intro, rule_format]\nlemmas m3_inv2_badkeysE [elim] =\n  m3_inv2_badkeys_def [THEN setc_def_to_elim, rule_format]\nlemmas m3_inv2_badkeysD [dest] =\n  m3_inv2_badkeys_def [THEN setc_def_to_dest, rule_format, rotated 1]\n\n\ntext \\<open>Invariance proof.\\<close>\n\nlemma PO_m3_inv2_badkeys_init [iff]:\n  \"init m3 \\<subseteq> m3_inv2_badkeys\"\nby (auto simp add: m3_defs m3_inv2_badkeys_def)\n\nlemma PO_m3_inv2_badkeys_trans [iff]:\n  \"{m3_inv2_badkeys} trans m3 {> m3_inv2_badkeys}\"\nby (auto simp add: PO_hoare_defs m3_defs intro!: m3_inv2_badkeysI)\n\nlemma PO_m3_inv2_badkeys [iff]: \"reach m3 \\<subseteq> m3_inv2_badkeys\"\nby (rule inv_rule_basic) (auto)\n\n\nsubsubsection \\<open>inv3: Intruder knows all public keys (NOT USED)\\<close>\n(******************************************************************************)\n\ntext \\<open>This invariant is only needed with equality in \\<open>R23_msgs\\<close>.\\<close>\n\ndefinition\n  m3_inv3_pubkeys :: \"m3_state set\"\nwhere\n  \"m3_inv3_pubkeys \\<equiv> {s. \\<forall>C.\n     Key (pubK C) \\<in> analz (IK s)\n  }\"\n\nlemmas m3_inv3_pubkeysI =\n  m3_inv3_pubkeys_def [THEN setc_def_to_intro, rule_format]\nlemmas m3_inv3_pubkeysE [elim] =\n  m3_inv3_pubkeys_def [THEN setc_def_to_elim, rule_format]\nlemmas m3_inv3_pubkeysD [dest] =\n  m3_inv3_pubkeys_def [THEN setc_def_to_dest, rule_format, rotated 1]\n\n\ntext \\<open>Invariance proof.\\<close>\n\nlemma PO_m3_inv3_pubkeys_init [iff]:\n  \"init m3 \\<subseteq> m3_inv3_pubkeys\"\nby (auto simp add: m3_defs m3_inv3_pubkeys_def)\n\nlemma PO_m3_inv3_pubkeys_trans [iff]:\n  \"{m3_inv3_pubkeys} trans m3 {> m3_inv3_pubkeys}\"\nby (auto simp add: PO_hoare_defs m3_defs intro!: m3_inv3_pubkeysI)\n\nlemma PO_m3_inv3_pubkeys [iff]: \"reach m3 \\<subseteq> m3_inv3_pubkeys\"\nby (rule inv_rule_basic) (auto)\n\n\n(******************************************************************************)\nsubsection \\<open>Refinement\\<close>\n(******************************************************************************)\n\ntext \\<open>Automatic tool tuning. Tame too-agressive pair decomposition, which is\ndeclared as a safe elim rule ([elim!]).\\<close>\n\nlemmas MPair_parts [rule del, elim]\nlemmas MPair_analz [rule del, elim]\n\n\nsubsubsection \\<open>Simulation relation\\<close>\n(******************************************************************************)\n\nabbreviation\n  nonces :: \"msg set \\<Rightarrow> nonce set\"\nwhere\n  \"nonces H \\<equiv> {N. Nonce N \\<in> analz H}\"\n\nabbreviation\n  ink :: \"chmsg set \\<Rightarrow> nonce set\"\nwhere\n  \"ink H \\<equiv> {N. aNon N \\<in> extr ik0 H}\"\n\n\ntext \\<open>Abstraction function on sets of messages.\\<close>\n\ninductive_set\n  abs_msg :: \"msg set \\<Rightarrow> chmsg set\"\n  for H :: \"msg set\"\nwhere\n  am_M1:\n    \"\\<lbrace>Agent A, Agent B, Nonce Na\\<rbrace> \\<in> H\n  \\<Longrightarrow> Insec A B (Msg [aNon Na]) \\<in> abs_msg H\"\n\n| am_M2:\n    \"Crypt (priK B) \\<lbrace>Nonce Nb, Nonce Na, Agent A\\<rbrace> \\<in> H\n  \\<Longrightarrow> Auth B A (Msg [aNon Nb, aNon Na]) \\<in> abs_msg H\"\n\n\ntext \\<open>The simulation relation is canonical. It states that the protocol\nmessages in the intruder knowledge refine the abstract messages appearing in\nthe channels @{term Insec} and @{term Auth}.\\<close>\n\ndefinition\n  R23_msgs :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23_msgs \\<equiv> {(s, t). abs_msg (parts (IK t)) \\<subseteq> chan s}\"   \\<comment> \\<open>with \\<open>parts\\<close>!\\<close>\n\ndefinition\n  R23_ink :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23_ink \\<equiv> {(s, t). nonces (IK t) \\<subseteq> ink (chan s)}\"\n\ndefinition\n  R23_preserved :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23_preserved \\<equiv> {(s, t). runs s = runs t}\"\n\ndefinition\n  R23 :: \"(m2_state \\<times> m3_state) set\" where\n  \"R23 \\<equiv> R23_msgs \\<inter> R23_ink \\<inter> R23_preserved\"\n\nlemmas R23_defs = R23_def R23_msgs_def R23_ink_def R23_preserved_def\n\n\ntext \\<open>Mediator function: nothing new.\\<close>\n\ndefinition\n  med32 :: \"m3_obs \\<Rightarrow> m2_obs\" where\n  \"med32 \\<equiv> id\"\n\n\nlemmas R23_msgsI =\n  R23_msgs_def [THEN rel_def_to_intro, simplified, rule_format]\nlemmas R23_msgsE [elim] =\n  R23_msgs_def [THEN rel_def_to_elim, simplified, rule_format]\nlemmas R23_msgsE' [elim] =\n  R23_msgs_def [THEN rel_def_to_dest, simplified, rule_format, THEN subsetD]\n\nlemmas R23_inkI =\n  R23_ink_def [THEN rel_def_to_intro, simplified, rule_format]\nlemmas R23_inkE [elim] =\n  R23_ink_def [THEN rel_def_to_elim, simplified, rule_format]\n\nlemmas R23_preservedI =\n  R23_preserved_def [THEN rel_def_to_intro, simplified, rule_format]\nlemmas R23_preservedE [elim] =\n  R23_preserved_def [THEN rel_def_to_elim, simplified, rule_format]\n\nlemmas R23_intros = R23_msgsI R23_inkI R23_preservedI\n\n\nsubsubsection \\<open>Facts about the abstraction function\\<close>\n(******************************************************************************)\n\ndeclare abs_msg.intros [intro!]\ndeclare abs_msg.cases [elim!]\n\nlemma abs_msg_empty: \"abs_msg {} = {}\"\nby (auto)\n\nlemma abs_msg_Un [simp]:\n  \"abs_msg (G \\<union> H) = abs_msg G \\<union> abs_msg H\"\nby (auto)\n\nlemma abs_msg_mono [elim]:\n  \"\\<lbrakk> m \\<in> abs_msg G; G \\<subseteq> H \\<rbrakk> \\<Longrightarrow> m \\<in> abs_msg H\"\nby (auto)\n\nlemma abs_msg_insert_mono [intro]:\n  \"\\<lbrakk> m \\<in> abs_msg H \\<rbrakk> \\<Longrightarrow> m \\<in> abs_msg (insert m' H)\"\nby (auto)\n\n\ntext \\<open>Abstraction of concretely fakeable message yields abstractly fakeable\nmessages. This is the key lemma for the refinement of the intruder.\\<close>\n\nlemma abs_msg_DY_subset_fakeable:\n  \"\\<lbrakk> (s, t) \\<in> R23_msgs; (s, t) \\<in> R23_ink; t \\<in> m3_inv1_lkeysec \\<rbrakk>\n  \\<Longrightarrow> abs_msg (synth (analz (IK t))) \\<subseteq> fake ik0 (dom (runs s)) (chan s)\"\napply (auto)\n  apply (rule fake_intros, auto)\n  apply (rule fake_Inj, auto)\n  apply (rule fake_intros, auto)\ndone\n\nlemma absmsg_parts_subset_fakeable:\n  \"\\<lbrakk> (s, t) \\<in> R23_msgs \\<rbrakk>\n  \\<Longrightarrow> abs_msg (parts (IK t)) \\<subseteq> fake ik0 (-dom (runs s)) (chan s)\"\nby (rule_tac B=\"chan s\" in subset_trans) (auto)\n\ndeclare abs_msg_DY_subset_fakeable [simp, intro!]\ndeclare absmsg_parts_subset_fakeable [simp, intro!]\n\n\n\nsubsubsection \\<open>Refinement proof\\<close>\n(******************************************************************************)\n\nlemma PO_m3_step1_refines_m2_step1:\n  \"{R23}\n     (m2_step1 Ra A B Na), (m3_step1 Ra A B Na)\n   {> R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m2_defs m3_defs intro!: R23_intros)\n   (auto)\n\nlemma PO_m3_step2_refines_m2_step2:\n  \"{R23 \\<^cancel>\\<open>\\<inter> UNIV \\<times> m3_inv3_pubkeys\\<close>}\n     (m2_step2 Rb A B Na Nb), (m3_step2 Rb A B Na Nb)\n   {> R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m2_defs m3_defs intro!: R23_intros)\n   (auto)\n\nlemma PO_m3_step3_refines_m2_step3:\n  \"{R23}\n     (m2_step3 Ra A B Na Nb), (m3_step3 Ra A B Na Nb)\n   {> R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m2_defs m3_defs intro!: R23_intros)\n   (auto)\n\n\ntext \\<open>The Dolev-Yao fake event refines the abstract fake event.\\<close>\n\nlemma PO_m3_DY_fake_refines_m2_fake:\n  \"{R23 \\<inter> UNIV \\<times> (m3_inv1_lkeysec \\<inter> m3_inv2_badkeys)}\n     m2_fake, m3_DY_fake\n   {> R23}\"\nby (auto simp add: PO_rhoare_defs R23_def m2_defs m3_defs)\n   (rule R23_intros, auto)+\n\n\ntext \\<open>All together now...\\<close>\n\nlemmas PO_m3_trans_refines_m2_trans =\n  PO_m3_step1_refines_m2_step1 PO_m3_step2_refines_m2_step2\n  PO_m3_step3_refines_m2_step3 PO_m3_DY_fake_refines_m2_fake\n\nlemma PO_m3_refines_init_m2 [iff]:\n  \"init m3 \\<subseteq> R23``(init m2)\"\nby (auto simp add: R23_defs m2_defs m3_defs)\n\nlemma PO_m3_refines_trans_m2 [iff]:\n  \"{R23 \\<inter> UNIV \\<times> (m3_inv2_badkeys \\<inter> m3_inv1_lkeysec)}\n     (trans m2), (trans m3)\n   {> R23}\"\napply (auto simp add: m3_def m3_trans_def m2_def m2_trans_def)\napply (blast intro!: PO_m3_trans_refines_m2_trans)+\ndone\n\nlemma PO_obs_consistent [iff]:\n  \"obs_consistent R23 med32 m2 m3\"\nby (auto simp add: obs_consistent_def R23_def med32_def m2_defs m3_defs)\n\nlemma PO_m3_refines_m2:\n  \"refines\n     (R23 \\<inter> UNIV \\<times> (m3_inv2_badkeys \\<inter> m3_inv1_lkeysec))\n     med32 m2 m3\"\nby (rule Refinement_using_invariants) (auto)\n\n\nend\n\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Security_Protocol_Refinement/Auth_simple/m3_sig.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5506073802837478, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.26026301076539066}}
{"text": "(*\n * @TAG(OTHER_LGPL)\n *)\n\n(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      HoareTotalDef.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nheader {* Hoare Logic for Total Correctness *}\n\ntheory HoareTotalDef imports HoarePartialDef Termination begin \n\nsubsection {* Validity of Hoare Tuples: @{text  \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"} *}\n\ndefinition\n  validt :: \"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com,'s assn,'s assn] \\<Rightarrow> bool\"\n                (\"_\\<Turnstile>\\<^sub>t\\<^bsub>'/_\\<^esub>/ _ _ _,_\"  [61,60,1000, 20, 1000,1000] 60)\nwhere\n \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<equiv> \\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<and> (\\<forall>s \\<in> Normal ` P. \\<Gamma>\\<turnstile>c\\<down>s)\"\n\ndefinition\n  cvalidt::\n  \"[('s,'p,'f) body,('s,'p) quadruple set,'f set,\n    's assn,('s,'p,'f) com,'s assn,'s assn] \\<Rightarrow> bool\"\n                (\"_,_\\<Turnstile>\\<^sub>t\\<^bsub>'/_\\<^esub>/ _ _ _,_\"  [61,60, 60,1000, 20, 1000,1000] 60)\nwhere\n \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<equiv> (\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A) \\<longrightarrow> \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n\n\n\nnotation (ascii)\n  validt  (\"_|=t'/_/ _ _ _,_\"  [61,60,1000, 20, 1000,1000] 60) and\n  cvalidt  (\"_,_|=t'/_ / _ _ _,_\"  [61,60,60,1000, 20, 1000,1000] 60)\n\nsubsection {* Properties of Validity *}\n\nlemma validtI: \n \"\\<lbrakk>\\<And>s t. \\<lbrakk>\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t;s \\<in> P;t \\<notin> Fault ` F\\<rbrakk> \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A;\n   \\<And>s. s \\<in> P \\<Longrightarrow> \\<Gamma>\\<turnstile> c\\<down>(Normal s) \\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (auto simp add: validt_def valid_def)\n\nlemma cvalidtI: \n \"\\<lbrakk>\\<And>s t. \\<lbrakk>\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A;\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t;s \\<in> P; \n          t \\<notin> Fault ` F\\<rbrakk> \n          \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A;\n   \\<And>s. \\<lbrakk>\\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A; s\\<in>P\\<rbrakk> \\<Longrightarrow>  \\<Gamma>\\<turnstile>c\\<down>(Normal s)\\<rbrakk>\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (auto simp add: cvalidt_def validt_def valid_def)\n\nlemma cvalidt_postD: \n \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A; \\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A;\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> t;\n   s \\<in> P;t \\<notin> Fault ` F\\<rbrakk> \n  \\<Longrightarrow> t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  by (simp add: cvalidt_def validt_def valid_def)\n\nlemma cvalidt_termD: \n \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A; \\<forall>(P,p,Q,A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A;s \\<in> P\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>\\<turnstile>c\\<down>(Normal s)\"\n  by (simp add: cvalidt_def validt_def valid_def)\n\n\nlemma validt_augment_Faults:\n  assumes valid:\"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes F': \"F \\<subseteq> F'\"\n  shows \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F'\\<^esub> P c Q,A\"\n  using valid F'\n  by (auto intro: valid_augment_Faults simp add: validt_def)\n\nsubsection {* The Hoare Rules: @{text \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" } *}\n\ninductive \"hoaret\"::\"[('s,'p,'f) body,('s,'p) quadruple set,'f set,\n                        's assn,('s,'p,'f) com,'s assn,'s assn] \n                       => bool\"\n    (\"(3_,_/\\<turnstile>\\<^sub>t\\<^bsub>'/_\\<^esub> (_/ (_)/ _,_))\" [61,60,60,1000,20,1000,1000]60)  \n   for \\<Gamma>::\"('s,'p,'f) body\"\nwhere\n  Skip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> Q Skip Q,A\"\n\n| Basic: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. f s \\<in> Q} (Basic f) Q,A\"\n\n| Spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. (\\<forall>t. (s,t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s,t) \\<in> r)} (Spec r) Q,A\"\n\n| Seq: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 R,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk>\n        \\<Longrightarrow>\n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Seq c\\<^sub>1 c\\<^sub>2 Q,A\"\n  \n| Cond: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> b) c\\<^sub>1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> - b) c\\<^sub>2 Q,A\\<rbrakk>\n         \\<Longrightarrow> \n         \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) Q,A\"\n\n| While: \"\\<lbrakk>wf r; \\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P \\<inter> b) c ({t. (t,\\<sigma>)\\<in>r} \\<inter> P),A\\<rbrakk>\n          \\<Longrightarrow>\n          \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (While b c) (P \\<inter> - b),A\"\n\n| Guard: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\n          \\<Longrightarrow>\n          \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) Guard f g c Q,A\"\n\n| Guarantee: \"\\<lbrakk>f \\<in> F; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\n\n| CallRec: \n  \"\\<lbrakk>(P,p,Q,A) \\<in> Specs;\n    wf r; \n    Specs_wf = (\\<lambda>p \\<sigma>. (\\<lambda>(P,q,Q,A). (P \\<inter> {s. ((s,q),(\\<sigma>,p)) \\<in> r},q,Q,A)) ` Specs);\n    \\<forall>(P,p,Q,A)\\<in> Specs. \n      p \\<in> dom \\<Gamma> \\<and> (\\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<union> Specs_wf p \\<sigma>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P) (the (\\<Gamma> p)) Q,A)\n    \\<rbrakk>\n    \\<Longrightarrow>\n    \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n\n\n| DynCom:  \"\\<forall>s \\<in> P. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (c s) Q,A \n            \\<Longrightarrow> \n            \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (DynCom c) Q,A\"\n\n\n| Throw: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> A Throw Q,A\"\n\n| Catch: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk> \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Catch c\\<^sub>1 c\\<^sub>2 Q,A\"\n\n| Conseq: \"\\<forall>s \\<in> P. \\<exists>P' Q' A'. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A' \\<and> s \\<in> P' \\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A \n           \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n\n\n| Asm: \"(P,p,Q,A) \\<in> \\<Theta> \n        \\<Longrightarrow> \n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n\n| ExFalso: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A; \\<not> \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  -- {* This is a hack rule that enables us to derive completeness for\n        an arbitrary context @{text \"\\<Theta>\"}, from completeness for an empty context.*}\n\n  \ntext {* Does not work, because of rule ExFalso, the context @{text \\<Theta>} is to blame.\n A weaker version with empty context can be derived from soundness \n later on. *}\nlemma hoaret_to_hoarep:\n  assumes hoaret: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P p Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P p Q,A\"\nusing hoaret\nproof (induct)\n  case Skip thus ?case by (rule hoarep.intros)\nnext\n  case Basic thus ?case by (rule hoarep.intros)\nnext\n  case Seq thus ?case by - (rule hoarep.intros)\nnext\n  case Cond thus ?case by - (rule hoarep.intros)\nnext\n  case (While r \\<Theta> F P b c A)\n  hence \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P \\<inter> b) c ({t. (t, \\<sigma>) \\<in> r} \\<inter> P),A\"\n    by iprover\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> b) c P,A\"\n    by (rule HoarePartialDef.conseq) blast\n  then show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P While b c (P \\<inter> - b),A\"\n    by (rule hoarep.While)\nnext\n  case Guard thus ?case by - (rule hoarep.intros)\n(*next\n  case (CallRec A F P Procs Q Z \\<Theta>  p r)\n  hence hyp: \"\\<forall>p\\<in>Procs. \\<forall>\\<tau> Z. \n           \\<Gamma>,\\<Theta> \\<union> (\\<Union>q\\<in>Procs. \\<Union>Z. {(P q Z \\<inter> {s. ((s, q), \\<tau>, p) \\<in> r},\n                      Call q, Q q Z,A q Z)})\\<turnstile>\\<^bsub>/F\\<^esub>\n              ({\\<tau>} \\<inter> P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n    by blast\n  have \"\\<forall>p\\<in>Procs. \\<forall>Z. \n           \\<Gamma>,\\<Theta> \\<union> (\\<Union>q\\<in>Procs. \\<Union>Z. {(P q Z,\n                      Call q, Q q Z,A q Z)})\\<turnstile>\\<^bsub>/F\\<^esub>\n              (P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\" \n  proof (intro ballI allI)\n    fix p Z\n    assume \"p \\<in> Procs\"\n    with hyp\n    have hyp': \"\\<And> \\<tau>. \n           \\<Gamma>,\\<Theta> \\<union> (\\<Union>q\\<in>Procs. \\<Union>Z. {(P q Z \\<inter> {s. ((s, q), \\<tau>, p) \\<in> r},\n                      Call q, Q q Z, A q Z)})\\<turnstile>\\<^bsub>/F\\<^esub>\n              ({\\<tau>} \\<inter> P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n      by blast\n    have \"\\<forall>\\<tau>. \n           \\<Gamma>,\\<Theta> \\<union> (\\<Union>q\\<in>Procs. \\<Union>Z. {(P q Z,\n                      Call q, Q q Z,A q Z)})\\<turnstile>\\<^bsub>/F\\<^esub>\n              ({\\<tau>} \\<inter> P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n      (is \"\\<forall>\\<tau>. \\<Gamma>,?\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\")\n    proof (rule allI, rule WeakenContext [OF hyp'],clarify)\n      fix \\<tau> P' c Q' A'\n      assume \"(P', c, Q', A') \\<in> \\<Theta> \\<union>\n         (\\<Union>q\\<in>Procs.\n             \\<Union>Z. {(P q Z \\<inter> {s. ((s, q), \\<tau>, p) \\<in> r},\n                  Call q, Q q Z,\n                  A q Z)})\" (is \"(P', c, Q', A') \\<in> \\<Theta> \\<union> ?Spec\")\n      then show \"\\<Gamma>,?\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> P' c Q',A'\"\n      proof (cases rule: UnE [consumes 1])\n        assume \"(P',c,Q',A') \\<in> \\<Theta>\" \n        then show ?thesis\n          by (blast intro: HoarePartialDef.Asm)\n      next\n        assume \"(P',c,Q',A') \\<in> ?Spec\" \n        then show ?thesis\n        proof (clarify)\n          fix q Z\n          assume q: \"q \\<in> Procs\"\n          show \"\\<Gamma>,?\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> (P q Z \\<inter> {s. ((s, q), \\<tau>, p) \\<in> r}) \n                         Call  q \n                        (Q q Z),(A q Z)\"\n          proof -\n            from q\n            have \"\\<Gamma>,?\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> (P q Z) Call q (Q q Z),(A q Z)\"\n              by - (rule HoarePartialDef.Asm,blast)\n            thus ?thesis\n              by (rule HoarePartialDef.conseqPre) blast\n          qed\n        qed\n      qed\n    qed\n    then show \"\\<Gamma>,\\<Theta> \\<union> (\\<Union>q\\<in>Procs. \\<Union>Z. {(P q Z, Call q, Q q Z,A q Z)})\n                \\<turnstile>\\<^bsub>/F\\<^esub> (P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n      by (rule HoarePartialDef.conseq) blast\n  qed\n  thus ?case\n    by - (rule hoarep.CallRec)*)\nnext\n  case DynCom thus ?case by (blast intro: hoarep.DynCom)\nnext\n  case Throw thus ?case by - (rule hoarep.Throw)\nnext\n  case Catch thus ?case by - (rule hoarep.Catch)\nnext\n  case Conseq thus ?case by - (rule hoarep.Conseq,blast)\nnext\n  case Asm thus ?case by (rule HoarePartialDef.Asm)\nnext\n  case (ExFalso \\<Theta> F P c Q A)\n  assume \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  hence \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n    oops\n\n\nlemma hoaret_augment_context: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P p Q,A\"\n  shows \"\\<And>\\<Theta>'. \\<Theta> \\<subseteq> \\<Theta>' \\<Longrightarrow> \\<Gamma>,\\<Theta>'\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P p Q,A\"\nusing deriv\nproof (induct)\n  case (CallRec P p Q A Specs r Specs_wf \\<Theta> F \\<Theta>')\n  have aug: \"\\<Theta> \\<subseteq> \\<Theta>'\" by fact\n  then\n  have h: \"\\<And>\\<tau> p. \\<Theta> \\<union> Specs_wf p \\<tau>\n       \\<subseteq> \\<Theta>' \\<union> Specs_wf p \\<tau>\"\n    by blast\n  have \"\\<forall>(P,p,Q,A)\\<in>Specs. p \\<in> dom \\<Gamma> \\<and>\n     (\\<forall>\\<tau>. \\<Gamma>,\\<Theta> \\<union> Specs_wf p \\<tau>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> p)) Q,A \\<and>\n           (\\<forall>x. \\<Theta> \\<union> Specs_wf p \\<tau>\n                 \\<subseteq> x \\<longrightarrow>\n                 \\<Gamma>,x\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> p)) Q,A))\" by fact\n  hence \"\\<forall>(P,p,Q,A)\\<in>Specs. p \\<in> dom \\<Gamma> \\<and> \n         (\\<forall>\\<tau>. \\<Gamma>,\\<Theta>'\\<union> Specs_wf p \\<tau> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> p)) Q,A)\"\n    apply (clarify)\n    apply (rename_tac P p Q A)\n    apply (drule (1) bspec)\n    apply (clarsimp)\n    apply (erule_tac x=\\<tau> in allE)\n    apply clarify\n    apply (erule_tac x=\"\\<Theta>' \\<union> Specs_wf p \\<tau>\" in allE)\n    apply (insert aug)\n    apply auto\n    done\n  with CallRec show ?case by - (rule hoaret.CallRec)\nnext\n  case DynCom thus ?case by (blast intro: hoaret.DynCom)\nnext\n  case (Conseq P \\<Theta> F c Q A \\<Theta>')\n  from Conseq\n  have \"\\<forall>s \\<in> P. (\\<exists>P' Q' A'. (\\<Gamma>,\\<Theta>' \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A') \\<and> s \\<in> P'\\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A)\"\n    by blast\n  with Conseq show ?case by - (rule hoaret.Conseq)\nnext\n  case (ExFalso \\<Theta> F P  c Q A \\<Theta>')\n  have \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" \"\\<not> \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" \"\\<Theta> \\<subseteq> \\<Theta>'\"  by fact+\n  then show ?case\n    by (fastforce intro: hoaret.ExFalso simp add: cvalidt_def)\nqed (blast intro: hoaret.intros)+\n\nsubsection {* Some Derived Rules *}\n\n\nlemma  Conseq': \"\\<forall>s. s \\<in> P \\<longrightarrow> \n            (\\<exists>P' Q' A'. \n              (\\<forall> Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z)) \\<and>\n                    (\\<exists>Z. s \\<in> P' Z \\<and> (Q' Z \\<subseteq> Q) \\<and> (A' Z \\<subseteq> A)))\n           \\<Longrightarrow>\n           \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\napply (rule Conseq)\napply (rule ballI)\napply (erule_tac x=s in allE)\napply (clarify)\napply (rule_tac x=\"P' Z\" in exI)\napply (rule_tac x=\"Q' Z\" in exI)\napply (rule_tac x=\"A' Z\" in exI)\napply blast\ndone\n\nlemma conseq:\"\\<lbrakk>\\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z);\n              \\<forall>s. s \\<in> P \\<longrightarrow> (\\<exists> Z. s\\<in>P' Z \\<and> (Q' Z \\<subseteq> Q)\\<and> (A' Z \\<subseteq> A))\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule Conseq) blast\n\ntheorem conseqPrePost: \n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A' \\<Longrightarrow> P \\<subseteq> P' \\<Longrightarrow>  Q' \\<subseteq> Q \\<Longrightarrow> A' \\<subseteq> A \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule conseq [where ?P'=\"\\<lambda>Z. P'\" and ?Q'=\"\\<lambda>Z. Q'\"]) auto\n\nlemma conseqPre: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q,A \\<Longrightarrow> P \\<subseteq> P' \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nby (rule conseq) auto\n\nlemma conseqPost: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q',A'\\<Longrightarrow> Q' \\<subseteq> Q \\<Longrightarrow> A' \\<subseteq> A \\<Longrightarrow>   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule conseq) auto\n\n\nlemma Spec_wf_conv: \n  \"(\\<lambda>(P, q, Q, A). (P \\<inter> {s. ((s, q), \\<tau>, p) \\<in> r}, q, Q, A)) `\n                (\\<Union>p\\<in>Procs. \\<Union>Z. {(P p Z, p, Q p Z, A p Z)}) = \n        (\\<Union>q\\<in>Procs. \\<Union>Z. {(P q Z \\<inter> {s. ((s, q), \\<tau>, p) \\<in> r}, q, Q q Z, A q Z)})\"\napply (rule)\napply  fastforce\napply (fastforce simp add: image_def)\ndone\n\nlemma CallRec': \n  \"\\<lbrakk>p\\<in>Procs; Procs \\<subseteq> dom \\<Gamma>;\n    wf r; \n   \\<forall>p\\<in>Procs. \\<forall>\\<tau> Z. \n   \\<Gamma>,\\<Theta>\\<union>(\\<Union>q\\<in>Procs. \\<Union>Z. \n    {((P q Z) \\<inter> {s. ((s,q),(\\<tau>,p)) \\<in> r},q,Q q Z,(A q Z))})\n     \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> (P p Z)) (the (\\<Gamma> p)) (Q p Z),(A p Z)\\<rbrakk>\n   \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P p Z) (Call p) (Q p Z),(A p Z)\"\napply (rule CallRec [where Specs=\"\\<Union>p\\<in>Procs. \\<Union>Z. {((P p Z),p,Q p Z,A p Z)}\" and\n         r=r])\napply    blast\napply   assumption\napply  (rule refl)\napply (clarsimp)\napply (rename_tac p')\napply (rule conjI)\napply  blast\napply (intro allI)\napply (rename_tac Z \\<tau>)\napply (drule_tac x=p' in bspec, assumption)\napply (erule_tac x=\\<tau> in allE)\napply (erule_tac x=Z in allE)\napply (fastforce simp add: Spec_wf_conv)\ndone\n\nend\n\n", "meta": {"author": "crizkallah", "repo": "checker-verification", "sha": "cd5101e57ef70dcdd1680db2de2f08521605bd7c", "save_path": "github-repos/isabelle/crizkallah-checker-verification", "path": "github-repos/isabelle/crizkallah-checker-verification/checker-verification-cd5101e57ef70dcdd1680db2de2f08521605bd7c/autocorres-1.0/c-parser/hoare-package/HoareTotalDef.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5506073655352404, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.2602630037940149}}
{"text": "theory BinarySearch\n  imports\n    BinarySearchAsm\nbegin\n\nsublocale WordArray \\<subseteq> Generated_cogent_shallow _ upd.wa_abs_repr val.wa_abs_typing_v upd.wa_abs_typing_u wa_abs_upd_val\n  by (unfold_locales)\n\ncontext WordArray begin\n\nthm corres_shallow_C_binarySearch_concrete\n\nsection \"record simps\"\n\nfun t0_unmake\n  where\n\"t0_unmake x = (T0.p1\\<^sub>f x, T0.p2\\<^sub>f x, T0.p3\\<^sub>f x)\" \n\nfun t0_make\n  where\n\"t0_make (a, b, c) = T0.make a b c\"\n\nfun t1_make\n  where\n\"t1_make (a, b) = T1.make a b\"\n\nfun t1_unmake\n  where\n\"t1_unmake x = (T1.p1\\<^sub>f x, T1.p2\\<^sub>f x)\"\n\nlemma t0_make_simps:\n  \"T0.p1\\<^sub>f (t0_make x) = (\\<lambda>(a,b,c). a) x\"\n  \"T0.p2\\<^sub>f (t0_make x) = (\\<lambda>(a,b,c). b) x\"\n  \"T0.p3\\<^sub>f (t0_make x) = (\\<lambda>(a,b,c). c) x\"\n  apply (clarsimp split: prod.splits simp: valRel_records)+\n  done\n\nlemma t1_make_simps:\n  \"T1.p1\\<^sub>f (t1_make x) = (\\<lambda>(a,b). a) x\"\n  \"T1.p2\\<^sub>f (t1_make x) = (\\<lambda>(a,b). b) x\"\n  apply (clarsimp split: prod.splits simp: valRel_records)+\n  done\n\nsection \"word simps\"\n\nlemma unat_ucast_of_nat:\n  \"x \\<le> unat (max_word :: 32 word) \\<Longrightarrow> unat (UCAST(32 \\<rightarrow> 64) (of_nat (x))) = x\"\n  apply (clarsimp simp: max_word_def ucast_of_nat_small )\n  apply (subst le_unat_uoi[where z = \"4294967295\"]; simp)\n  done\n\nlemma unatSuc_comm:\n  \"(1 :: ('a :: len8) word) + n \\<noteq> 0 \\<Longrightarrow> unat (n + 1) = Suc (unat n)\"\n  apply (drule unatSuc)\n  apply (simp add: add.commute)\n  done\n\nsection \"midpoint lemmas\"\n\nlemma midpoint_alt:\n  \"a < b \\<Longrightarrow> (a ::nat) + (b - a) div 2 = (a + b) div 2\"\n  apply (induct a)\n   apply simp\n  apply simp\n  done\n\nlemma midpoint_bounds_upper:\n  \"\\<lbrakk>a < b; b \\<le> d\\<rbrakk> \\<Longrightarrow> (a ::nat) + (b - a) div 2 < d\"\n  apply (induct a)\n   apply simp\n  apply simp\n  done\n\nsection \"search_stop simps\"\n\ndefinition search_stop0\n  where\n\"search_stop0 = (\\<lambda>ds\\<^sub>0. \\<not> T0.p2\\<^sub>f (StepParam.acc\\<^sub>f ds\\<^sub>0) \\<le> T0.p1\\<^sub>f (StepParam.acc\\<^sub>f ds\\<^sub>0) \\<longrightarrow> p3\\<^sub>f (StepParam.acc\\<^sub>f ds\\<^sub>0))\"\n\nlemma search_stop0_simp:\n  \"Generated_Shallow_Desugar.searchStop = search_stop0\"\n  unfolding Generated_Shallow_Desugar.searchStop_def search_stop0_def\n  apply (clarsimp simp: Let_def take\\<^sub>c\\<^sub>o\\<^sub>g\\<^sub>e\\<^sub>n\\<^sub>t_def valRel_records swa_get_def split: if_splits)\n  done\n\ndefinition search_stop1\n  where\n\"search_stop1 = (\\<lambda>a b. \\<not> T0.p2\\<^sub>f a \\<le> T0.p1\\<^sub>f a \\<longrightarrow> p3\\<^sub>f a)\"\n\nlemma search_stop1_simp:\n  \"(\\<lambda>a b. search_stop0 \\<lparr>StepParam.acc\\<^sub>f = a, obsv\\<^sub>f = b\\<rparr>) = search_stop1\"\n  unfolding search_stop0_def search_stop1_def\n  apply (clarsimp simp: Let_def take\\<^sub>c\\<^sub>o\\<^sub>g\\<^sub>e\\<^sub>n\\<^sub>t_def valRel_records swa_get_def split: if_splits)\n  done\n\ndefinition search_stop2\n  where\n\"search_stop2 = (\\<lambda>(a, b, c) (d, e). \\<not> b \\<le> a \\<longrightarrow> c)\"\n\nlemma search_stop2_simp:\n  \"(\\<lambda>a b. search_stop1 (t0_make a) (t1_make b)) = search_stop2\"\n  unfolding search_stop1_def search_stop2_def\n  apply (clarsimp simp: fun_eq_iff valRel_records split: prod.splits)\n  done\n\nsection \"search_next simps\"\n\nlemma searchNext_simps:\n  \"(\\<lambda>a (b, c). t0_unmake (Generated_Shallow_Desugar.searchNext \\<lparr>StepParam.acc\\<^sub>f = t0_make a, obsv\\<^sub>f = \\<lparr>T1.p1\\<^sub>f = SWA b, p2\\<^sub>f = c\\<rparr>\\<rparr>))\n    = (\\<lambda>(a0, a1, a2) (b, c). t0_unmake (Generated_Shallow_Desugar.searchNext \\<lparr>StepParam.acc\\<^sub>f = t0_make (a0, a1, a2), obsv\\<^sub>f = \\<lparr>T1.p1\\<^sub>f = SWA b, p2\\<^sub>f = c\\<rparr>\\<rparr>))\"\n  unfolding Generated_Shallow_Desugar.searchNext_def swa_get_def\n  apply (clarsimp simp: Let_def take\\<^sub>c\\<^sub>o\\<^sub>g\\<^sub>e\\<^sub>n\\<^sub>t_def valRel_records checked_div_def  t1_make_simps t0_make_simps fun_eq_iff\n                  split: if_splits)\n  done\n\ndefinition search_next0\n  where\n\"search_next0 = (\\<lambda>(a0, a1, a2) (b, c).\n    (if (if unat (a0 + (a1 - a0) div 2) < length b then b ! unat (a0 + (a1 - a0) div 2) else 0) < c\n      then (a0 + (a1 - a0) div 2 + 1, a1, a2)\n     else if c < (if unat (a0 + (a1 - a0) div 2) < length b then b ! unat (a0 + (a1 - a0) div 2) else 0)\n      then (a0, a0 + (a1 - a0) div 2, a2)\n     else (a0 + (a1 - a0) div 2, a1, True)))\"\nlemma search_next_simp:\n  \"(\\<lambda>(a0, a1, a2) (b, c). t0_unmake (Generated_Shallow_Desugar.searchNext \\<lparr>StepParam.acc\\<^sub>f = t0_make (a0, a1, a2), obsv\\<^sub>f = \\<lparr>T1.p1\\<^sub>f = SWA b, p2\\<^sub>f = c\\<rparr>\\<rparr>))\n    = search_next0\"\n  unfolding Generated_Shallow_Desugar.searchNext_def swa_get_def search_next0_def\n  apply (clarsimp simp: Let_def take\\<^sub>c\\<^sub>o\\<^sub>g\\<^sub>e\\<^sub>n\\<^sub>t_def valRel_records checked_div_def  t1_make_simps t0_make_simps fun_eq_iff\n                  split: if_splits)\n  done\n\ndefinition search_next1\n  where\n\"search_next1 = (\\<lambda>(a0, a1, a2) (b, c).\n    (if (if ((a0 + a1) div 2) < length b then b ! ((a0 + a1) div 2) else 0) < c\n      then ((a0 + a1) div 2 + 1, a1, a2)\n     else if c < (if ((a0 + a1) div 2) < length b then b ! ((a0 + a1) div 2) else 0)\n      then (a0, (a0 + a1 ) div 2, a2)\n     else ((a0 + a1) div 2, a1, True)))\"\n\nlemma search_next1_simp:\n  \"\\<lbrakk>length xs \\<le> unat (max_word :: 32 word); a0 < a1; unat a0 < length xs; unat a1 \\<le> length xs\\<rbrakk> \\<Longrightarrow> \n    (\\<lambda>(a0, a1, b). (unat a0, unat a1, b)) ((search_next0 ((a0) :: 32 word, a1, a2) (xs, (v :: ('a :: len8) word))))\n      = search_next1 (unat a0, unat a1, a2) (xs, v)\"\n  apply (subgoal_tac \"unat (a0 + (a1 - a0) div 2) = ((unat a0) + (unat a1)) div 2\")\n  unfolding search_next0_def search_next1_def\n   apply (clarsimp split: prod.splits)\n   apply (rule conjI; clarsimp)\n    apply (subst unatSuc_comm)\n     apply (subst add.commute)\n     apply (rule_tac k = max_word in less_is_non_zero_p1)\n     apply (subst word_less_nat_alt)\n     apply simp\n    apply simp\n   apply (subst unatSuc_comm)\n    apply (subst add.commute)\n    apply (rule_tac k = max_word in less_is_non_zero_p1)\n    apply (subst word_less_nat_alt)\n    apply simp\n   apply simp\n  apply (subst unat_add_lem')\n   apply (simp add: unat_div unat_sub)+\n   apply (simp add: unat_div unat_sub midpoint_bounds_upper max_word_def)\n  apply (simp add: unat_div unat_sub)\n  apply (subst midpoint_alt; simp add: word_less_nat_alt)\n  done\n \ndefinition search_stop3\n  where\n\"search_stop3 = (\\<lambda>a (b, c). search_stop2 a (SWA b, c))\"\n\ndefinition search_stop4\n  where\n\"search_stop4 = (\\<lambda>(a0, a1, a2) (b, c). (\\<not> (a1 :: nat) \\<le> a0 \\<longrightarrow> a2))\"\n\nlemma search_next1_simp2:\n  \"\\<lbrakk>length xs \\<le> unat (max_word :: 32 word); a0 < a1; unat a0 < length xs; unat a1 \\<le> length xs;\n    search_next0 ((a0) :: 32 word, a1, a2) (xs, (v :: ('a :: len8) word)) = (l, h, b)\\<rbrakk>\n      \\<Longrightarrow> search_next1 (unat a0, unat a1, a2) (xs, v) = (unat l, unat h, b)\"\n apply (subgoal_tac \"unat (a0 + (a1 - a0) div 2) = ((unat a0) + (unat a1)) div 2\")\n  unfolding search_next0_def search_next1_def\n   apply (clarsimp split: prod.splits)\n   apply (rule conjI; clarsimp)+\n    apply (subst unatSuc_comm)\n     apply (subst add.commute)\n     apply (rule_tac k = max_word in less_is_non_zero_p1)\n     apply (subst word_less_nat_alt)\n     apply simp\n     apply simp\n    apply (rule conjI; clarsimp)+\n    apply (subst unatSuc_comm)\n     apply (subst add.commute)\n     apply (rule_tac k = max_word in less_is_non_zero_p1)\n     apply (subst word_less_nat_alt)\n     apply simp\n    apply simp\n   apply (rule conjI; clarsimp)+\n   apply (subst unatSuc_comm)\n    apply (subst add.commute)\n    apply (rule_tac k = max_word in less_is_non_zero_p1)\n    apply (subst word_less_nat_alt)\n    apply simp\n   apply simp\n  apply (subst unat_add_lem')\n   apply (simp add: unat_div unat_sub)+\n   apply (simp add: unat_div unat_sub midpoint_bounds_upper max_word_def)\n  apply (simp add: unat_div unat_sub)\n  apply (subst midpoint_alt; simp add: word_less_nat_alt)\n  done\n\nsection \"repeat simps\"\n\nlemma repeatatm_simps:\n  \"repeatatm n f1 f2 \\<lparr>T0.p1\\<^sub>f = a, p2\\<^sub>f = b, p3\\<^sub>f = c\\<rparr> \\<lparr>T1.p1\\<^sub>f = d, p2\\<^sub>f = e\\<rparr> \n    = t0_make (repeatatm n (\\<lambda>a b. f1 (t0_make a) (t1_make b)) (\\<lambda>a b. t0_unmake (f2 (t0_make a) (t1_make b))) (a,b,c) (d,e))\"\n  apply (induct n arbitrary: a b c)\n   apply (simp add: repeatatm.simps valRel_records)\n  apply (clarsimp simp: repeatatm.simps valRel_records)\n  apply (erule_tac x = \"T0.p1\\<^sub>f (f2 \\<lparr>T0.p1\\<^sub>f = a, p2\\<^sub>f = b, p3\\<^sub>f = c\\<rparr> \\<lparr>T1.p1\\<^sub>f = d, p2\\<^sub>f = e\\<rparr>)\" in meta_allE)\n  apply (erule_tac x = \"T0.p2\\<^sub>f (f2 \\<lparr>T0.p1\\<^sub>f = a, p2\\<^sub>f = b, p3\\<^sub>f = c\\<rparr> \\<lparr>T1.p1\\<^sub>f = d, p2\\<^sub>f = e\\<rparr>)\" in meta_allE)\n  apply (erule_tac x = \"T0.p3\\<^sub>f (f2 \\<lparr>T0.p1\\<^sub>f = a, p2\\<^sub>f = b, p3\\<^sub>f = c\\<rparr> \\<lparr>T1.p1\\<^sub>f = d, p2\\<^sub>f = e\\<rparr>)\" in meta_allE)\n  by (metis (mono_tags, lifting) T0.surjective old.unit.exhaust)\n\n\nlemma repeatatm_simps2:\n  \"repeatatm n f g (a, b, c) (SWA xs, v) \n    = repeatatm n (\\<lambda>a (b, c). f a (list_to_swa b, c)) (\\<lambda>a (b, c). g a (list_to_swa b, c)) (a, b, c) (xs, v)\"\n  apply (induct n arbitrary: a b c)\n   apply (simp add: repeatatm.simps)\n  apply (clarsimp simp: repeatatm.simps)\n  by (metis WordArray.t0_make.cases)\n\n\nlemma repeatatm_nat_simp:\n  \"\\<lbrakk>repeatatm n search_stop3 search_next0 ((i :: 32 word), j, b) (xs, (v :: ('a :: len8) word)) = (l, h, b');\n    unat i < length xs; unat j \\<le> length xs; length xs \\<le> unat (max_word :: 32 word)\\<rbrakk>\n    \\<Longrightarrow> repeatatm n search_stop4 search_next1 (unat i, unat j, b) (xs, v) = (unat l, unat h, b')\"\n  apply (induct n arbitrary: i j b)\n   apply (simp add: repeatatm.simps)\n  apply (simp add: repeatatm.simps)\n  apply (rule conjI; clarsimp)\n   apply (rotate_tac 1; subst (asm) search_stop3_def)\n   apply (clarsimp simp: search_stop2_def search_stop4_def not_le word_less_nat_alt)\n   apply (rotate_tac 1; subst (asm) search_stop3_def)\n  apply (clarsimp simp: search_stop2_def not_le word_less_nat_alt)\n  apply (subst (asm) search_stop4_def)\n  apply simp\n  apply (subgoal_tac \"\\<exists>x y z. search_next0 (i, j, False) (xs, v) = (x, y, z) \\<and>  unat y \\<le> length xs\")\n   apply (elim exE conjE)\n   apply simp\n   apply (drule search_next1_simp2[rotated -1]; simp?)\n    apply (clarsimp simp: word_less_nat_alt not_le)\n   apply (case_tac \"unat x < length xs\"; clarsimp?)\n   apply (case_tac n; clarsimp simp: repeatatm.simps)\n   apply (rule conjI; clarsimp)\n    apply (subst (asm) search_stop3_def)\n    apply (clarsimp simp: search_stop2_def search_stop4_def not_le word_less_nat_alt)\n   apply (subst (asm) search_stop3_def)\n   apply (clarsimp simp: search_stop2_def not_le word_less_nat_alt)\n   apply (rotate_tac -1; subst (asm) search_stop4_def)\n   apply simp\n  apply (subst search_next0_def)\n  apply clarsimp\n  done\n\nsection \"binary search nat lemmas\"\n\nlemma binary_search_range_shrink:\n  \"\\<lbrakk>repeatatm n search_stop4 search_next1 (i, j, b) (xs, v) = (l, h, b'); \n    i < j; j \\<le> length xs\\<rbrakk>\n    \\<Longrightarrow> i \\<le> l \\<and> h \\<le> j\"\n  apply (induct n arbitrary: i j b)\n   apply (clarsimp simp: repeatatm.simps)\n  apply (clarsimp simp: repeatatm.simps)\n  apply (rotate_tac 1; subst (asm) search_stop4_def; clarsimp split: if_splits)\n  apply (rotate_tac -1; subst (asm) search_next1_def; subst (asm) search_next1_def)\n  apply (subst (asm) search_next1_def[symmetric])\n  apply (clarsimp split: if_splits)\n    apply (case_tac \"Suc ((i + j) div 2) < j\"; clarsimp)\n     apply (elim meta_allE, erule meta_impE, assumption; simp?)\n     apply clarsimp\n     apply (rule_tac b = \"Suc ((i + j) div 2)\" in  order.trans; simp?)\n    apply (case_tac n; clarsimp simp: repeatatm.simps search_stop4_def split: if_splits)\n   apply (elim meta_allE, erule meta_impE, assumption; simp?)\n   apply (case_tac \"i < (i + j) div 2\"; clarsimp)\n    apply (rule_tac b = \"(i + j) div 2\" in  order.trans; simp?)\n   apply (case_tac n; clarsimp simp: repeatatm.simps search_stop4_def split: if_splits)\n    apply (case_tac n; clarsimp simp: repeatatm.simps search_stop4_def split: if_splits)\n   apply arith\n  apply arith\n  done\n\nlemma binary_search_correct_range:\n  \"\\<lbrakk>repeatatm n search_stop4 search_next1 (i, j, False) (xs, v) = (l, h, b'); \n    i < j; j \\<le> length xs; sorted xs\\<rbrakk>\n    \\<Longrightarrow> (b' \\<longrightarrow> xs ! l = v \\<and> l < length xs) \\<and> (\\<not>b' \\<longrightarrow>\n        (l < h \\<longrightarrow> (\\<forall>k. (i \\<le> k \\<and> k < l \\<longrightarrow> xs ! k < v) \\<and> (h \\<le> k \\<and> k < j \\<longrightarrow> xs ! k > v))) \\<and> \n        (\\<not> l < h \\<longrightarrow> (\\<forall>k. i \\<le>k \\<and> k < j \\<longrightarrow> xs ! k \\<noteq> v)))\"\n  apply (induct n arbitrary: i j)\n   apply (clarsimp simp: repeatatm.simps)\n   apply (rule conjI; clarsimp)\n  apply (clarsimp simp: repeatatm.simps)\n  apply (rotate_tac -4; subst (asm) search_stop4_def; clarsimp split: if_splits)\n  apply (subst (asm) search_next1_def; subst (asm) search_next1_def)\n  apply (subst (asm) search_next1_def[symmetric])\n  apply (clarsimp split: if_splits)\n    apply (case_tac \"Suc ((i + j) div 2) < j\")\n     apply (elim meta_allE, erule meta_impE, assumption; simp?)\n     apply clarsimp\n     apply (rule conjI; clarsimp)\n      apply (erule_tac x = k in allE; clarsimp)\n      apply (drule binary_search_range_shrink; simp?)\n      apply (clarsimp simp: not_le)\n      apply (rule_tac y = \"xs ! ((i + j) div 2)\" in le_less_trans; simp?)\n      apply (rule sorted_nth_mono; simp?)\n      apply (erule_tac x = k in allE; clarsimp)\n      apply (drule binary_search_range_shrink; simp?)\n      apply (clarsimp simp: not_le not_less)\n     apply (drule_tac i = k and j = \"((i + j) div 2)\" in sorted_nth_mono; simp?)\n    apply (case_tac n; clarsimp simp: repeatatm.simps search_stop4_def split: if_splits)\n     apply (clarsimp simp: not_le not_less)\n     apply (drule_tac i = k and j = \"((i + h) div 2)\" in sorted_nth_mono; simp?)\n    apply (drule_tac i = k and j = \"((i + h) div 2)\" in sorted_nth_mono; simp?)\n   apply (elim meta_allE, erule meta_impE, assumption; simp?)\n  apply (clarsimp simp: not_le not_less)\n   apply (case_tac \"i < (i + j) div 2\"; clarsimp)\n    apply (rule conjI; clarsimp)\n     apply (drule binary_search_range_shrink; simp?)\n     apply clarsimp\n     apply (erule_tac x = k in allE; clarsimp)\n     apply (drule_tac i = \"((i + j) div 2)\" and j = k in sorted_nth_mono; simp?)\n    apply (drule binary_search_range_shrink; simp?)\n    apply clarsimp\n    apply (erule_tac x = k in allE; clarsimp)\n    apply (drule_tac i = \"((i + j) div 2)\" and j = k in sorted_nth_mono; simp?)\n   apply (case_tac n; clarsimp simp: repeatatm.simps search_stop4_def split: if_splits)\n    apply (drule_tac i = \"((l + j) div 2)\" and j = k in sorted_nth_mono; simp?)\n   apply (drule_tac i = \"((l + j) div 2)\" and j = k in sorted_nth_mono; simp?)\n  apply (case_tac n; clarsimp simp: repeatatm.simps search_stop4_def split: if_splits)\n  done\n\nlemma binary_search_completes:\n  \"\\<lbrakk>repeatatm n search_stop4 search_next1 (i, j, False) (xs, v) = (l, h, b'); \n    i < j; j \\<le> length xs; n \\<ge> j - i\\<rbrakk>\n    \\<Longrightarrow> b' \\<or> l \\<ge> h\"\n  apply (induct n arbitrary: i j)\n   apply (clarsimp simp: repeatatm.simps)\n  apply (clarsimp simp: repeatatm.simps)\n  apply (rotate_tac 1; subst (asm) search_stop4_def; clarsimp split: if_splits)\n  apply (subst (asm) search_next1_def; subst (asm) search_next1_def)\n  apply (subst (asm) search_next1_def[symmetric])\n  apply (clarsimp split: if_splits)\n   apply (case_tac \"Suc ((i + j) div 2) < j\")\n     apply (elim meta_allE, erule meta_impE, assumption; simp?)\n       apply (case_tac n; clarsimp simp: repeatatm.simps search_stop4_def split: if_splits)\n      apply simp\n     apply (case_tac \"i < (i + j) div 2\")\n      apply (elim meta_allE, erule meta_impE, assumption; simp?)\n     apply (case_tac n; clarsimp simp: repeatatm.simps search_stop4_def split: if_splits)\n    apply (case_tac n; clarsimp simp: repeatatm.simps search_stop4_def split: if_splits)\n   apply simp\n  apply simp\n  done\n\ntext \"This provides a tighter bound for time complexity analysis\"\n\nlemma binary_search_completes_tight:\n  \"\\<lbrakk>repeatatm n search_stop4 search_next1 (i, j, False) (xs, v) = (l, h, b'); \n    i < j; j \\<le> length xs; 2 ^ n >  j - i\\<rbrakk>\n    \\<Longrightarrow> b' \\<or> l \\<ge> h\"\n apply (induct n arbitrary: i j)\n   apply (clarsimp simp: repeatatm.simps)\n apply (clarsimp simp: repeatatm.simps)\n  apply (rotate_tac 1; subst (asm) search_stop4_def; clarsimp split: if_splits)\n  apply (subst (asm) search_next1_def; subst (asm) search_next1_def)\n  apply (subst (asm) search_next1_def[symmetric])\n  apply (clarsimp split: if_splits)\n       apply (case_tac \"Suc ((i + j) div 2) < j\")\n        apply (elim meta_allE, erule meta_impE, assumption; simp?)\n       apply (case_tac n; clarsimp simp: repeatatm.simps search_stop4_def split: if_splits)\n      apply simp\n     apply (case_tac \"i < (i + j) div 2\")\n      apply (elim meta_allE, erule meta_impE, assumption; simp?)\n     apply (case_tac n; clarsimp simp: repeatatm.simps search_stop4_def split: if_splits)\n    apply (case_tac n; clarsimp simp: repeatatm.simps search_stop4_def split: if_splits)\n   apply simp\n  apply simp\n  done\n\nsection \"binary search functional correctness theorem\"\n\ntheorem binary_search_correct:\n  \"\\<lbrakk>sorted xs; i = unat (Generated_Shallow_Desugar.binarySearch \\<lparr>T1.p1\\<^sub>f = SWA xs, p2\\<^sub>f = v\\<rparr>);\n    length xs \\<le> unat (max_word :: 32 word)\\<rbrakk> \\<Longrightarrow> \n   (i < length xs \\<longrightarrow> xs ! i = v) \\<and> \n   (\\<not> i < length xs \\<longrightarrow> v \\<notin> set xs)\"\n  unfolding Generated_Shallow_Desugar.binarySearch_def swa_length_def repeat'_def swa_get_def     \n  apply (clarsimp simp: Let_def take\\<^sub>c\\<^sub>o\\<^sub>g\\<^sub>e\\<^sub>n\\<^sub>t_def valRel_records unat_ucast_of_nat\n                        search_stop0_simp search_stop1_simp repeatatm_simps \n                        search_stop2_simp t0_make_simps checked_div_def\n                        t1_make_simps repeatatm_simps2 le_unat_uoi[where z = \"max_word :: 32 word\"]\n                 split:  prod.splits;\n         subst (asm) t0_unmake.simps[symmetric]; subst (asm) searchNext_simps; subst (asm) search_next_simp)\n  apply (subst (asm) search_stop3_def[symmetric])\n  apply (case_tac xs, clarsimp)\n  apply (drule repeatatm_nat_simp, simp)\n    apply (subst le_unat_uoi[where z = \"max_word :: 32 word\"]; simp)\n   apply simp\n  apply (frule binary_search_completes)\n     apply (subst le_unat_uoi[where z = \"max_word :: 32 word\"]; simp)+\n  apply (drule binary_search_correct_range)\n     apply (subst le_unat_uoi[where z = \"max_word :: 32 word\"]; simp)+\n   apply simp\n  apply (thin_tac \"xs = _ \")\n  apply clarsimp\n  apply (subst (asm) le_unat_uoi[where z = \"max_word :: 32 word\"], simp)\n  apply (simp add: set_conv_nth)\n  apply clarsimp\n  apply (rename_tac k)\n  apply (erule_tac x = k in allE; clarsimp)\n  done\n\ndefinition\n  array :: \"(lifted_globals \\<times> WordArray_u32_C ptr) \\<Rightarrow>\n              (WordArray_u32_C \\<times>\n              abstyp \\<times>\n              vabstyp \\<times>\n              vabstyp \\<times>\n              32 word WordArray)\"\nwhere\n  \"array sp = \n    (let (s, p) = sp;\n         w = heap s p;\n         l = (SCAST(32 signed \\<rightarrow> 32))(len_C w);\n         arr = values_C w;\n         xs = (map (\\<lambda>i. heap_w32 s (arr +\\<^sub>p int i)) [0..<(unat l)]);\n         vxs = (map (\\<lambda>i. VPrim (LU32 i)) xs);\n         rp = RCon ''WordArray'' [RPrim (Num U32)]\n    in (w,\n        UWA (TPrim (Num U32)) l (ptr_val arr),\n        VWA (TPrim (Num U32)) vxs,\n        VWA (TPrim (Num U32)) vxs,\n        SWA xs))\"\n\nabbreviation  \"arr\\<^sub>c \\<equiv> prod.fst \\<circ> array\"\nabbreviation  \"arr\\<^sub>u \\<equiv> prod.fst \\<circ> prod.snd \\<circ> array\"\nabbreviation  \"arr\\<^sub>m \\<equiv> prod.fst \\<circ> prod.snd \\<circ> prod.snd \\<circ> array\"\nabbreviation  \"arr\\<^sub>p \\<equiv> prod.fst \\<circ> prod.snd \\<circ> prod.snd \\<circ> prod.snd \\<circ> array\"\nabbreviation  \"arr\\<^sub>s \\<equiv> prod.snd \\<circ> prod.snd \\<circ> prod.snd \\<circ> prod.snd \\<circ> array\"\nabbreviation  \"arrlist \\<equiv> swa_to_list \\<circ> arr\\<^sub>s\"\nabbreviation  \"arrptrs s p \\<equiv> map (\\<lambda>i. ptr_val (values_C (arr\\<^sub>c (s, p)) +\\<^sub>p int i))[0..<unat((SCAST(32 signed \\<rightarrow> 32))(len_C (arr\\<^sub>c (s, p))))]\"\n\n\ndefinition\n  inputs :: \"(lifted_globals \\<times> t8_C) \\<Rightarrow>\n                ((funtyp, atyp, ptrtyp) uval \\<times>\n                (funtyp, vabstyp) vval \\<times>\n                (funtyp, vabstyp) vval \\<times>\n                (32 word WordArray, 32 word) T1)\"\nwhere\n  \"inputs sx = \n    (let (s, x) = sx;\n         p = t8_C.p1_C x;\n         v = t8_C.p2_C x;\n             rp = RCon ''WordArray'' [RPrim (Num U32)]\n    in (URecord [(UPtr (ptr_val p) rp, RPtr rp), (UPrim (LU32 v), RPrim (Num U32))] None,\n        VRecord [VAbstract (arr\\<^sub>m (s, p)), VPrim (LU32 v)],\n        VRecord [VAbstract (arr\\<^sub>p (s, p)), VPrim (LU32 v)],\n        \\<lparr>T1.p1\\<^sub>f = arr\\<^sub>s (s, p), p2\\<^sub>f = v\\<rparr>))\"\n\ndefinition\n  valid_array :: \"lifted_globals \\<Rightarrow>  WordArray_u32_C ptr \\<Rightarrow> bool\"\nwhere\n  \"valid_array s p = \n    (let w = heap s p;\n         l = (SCAST(32 signed \\<rightarrow> 32))(len_C w);\n         arr = values_C w\n     in is_valid s p \\<and> \n        size_of (TYPE(32 word)) * unat l \\<le> unat (max_word :: 32 word) \\<and>\n        (\\<forall>i < l. is_valid_w32 s (arr +\\<^sub>p uint i)) \\<and>\n         (\\<forall>i < l. ptr_val p \\<noteq> ptr_val (arr +\\<^sub>p uint i)))\"\n\ndefinition\n  same_array :: \"lifted_globals \\<Rightarrow> lifted_globals \\<Rightarrow> WordArray_u32_C ptr \\<Rightarrow> bool\"\nwhere\n  \"same_array s s' p = \n    (let w = heap s p;\n         l = (SCAST(32 signed \\<rightarrow> 32))(len_C w);\n         w' = heap s' p;\n         arr = values_C w\n     in valid_array s p \\<and>\n        valid_array s' p \\<and>\n        w = w' \\<and>\n        (\\<forall>i < l. heap_w32 s (arr +\\<^sub>p uint i) = heap_w32 s' (arr +\\<^sub>p uint i)))\"\n\nlemma \n  \"unat ((of_nat (size_of (TYPE(32 word)))) :: ptrtyp) = size_of (TYPE(32 word))\"\n  apply simp\n  done\n\nabbreviation  \"uv\\<^sub>m \\<equiv> prod.fst \\<circ> inputs\"\n\nabbreviation  \"vv\\<^sub>m \\<equiv> prod.fst \\<circ> prod.snd \\<circ> inputs\"\n\nabbreviation  \"vv\\<^sub>p \\<equiv> prod.fst \\<circ> prod.snd \\<circ> prod.snd \\<circ> inputs\"\n\nabbreviation  \"vv\\<^sub>s \\<equiv> prod.snd \\<circ> prod.snd \\<circ> prod.snd \\<circ> inputs\"\n\nlemma inputs_uv_matches:\n  \"\\<lbrakk>valid_array s p; \\<sigma> (ptr_val p) = option.Some (UAbstract (arr\\<^sub>u (s, p)));\n    \\<forall>p \\<in> set (arrptrs s p). \\<sigma> p = option.Some (UPrim (LU32 (heap_w32 s (PTR(32 word)p))))\\<rbrakk> \\<Longrightarrow>\n   u_v_matches \\<Xi> \\<sigma> [uv\\<^sub>m (s, t8_C p v)] [vv\\<^sub>m (s, t8_C p v)]\n      [Some (fst (snd (snd (snd Generated_TypeProof.binarySearch_type))))]\n      (insert (ptr_val p) (set (arrptrs s p))) {}\"\n  apply (clarsimp simp: inputs_def\n                        array_def\n                        Let_def\n                        Generated_TypeProof.binarySearch_type_def\n                        Generated_TypeProof.abbreviated_type_defs)\n  apply (intro u_v_matches_some[where r' = \"{}\" and w' = \"{}\", simplified]\n               u_v_matches_empty[where \\<tau>s = \"[]\", simplified]\n               u_v_struct\n               u_v_r_cons1[where r' = \"{}\" and w' = \"{}\", simplified]\n               u_v_p_abs_ro[where a = \"arr\\<^sub>u (s, p)\" and ts = \"[TPrim (Num U32)]\", simplified]\n               u_v_prim'\n               u_v_r_empty; (simp add: array_def Let_def u_v_matches.intros(1))?)\n  apply (clarsimp simp: wa_abs_upd_val_def)\n  apply (rule conjI)\n   apply (clarsimp simp: upd.wa_abs_typing_u_def valid_array_def Let_def)\n   apply (rule conjI)\n    apply (rule equalityI; clarsimp simp: word_less_nat_alt array_def Let_def)\n     apply (intro exI conjI; simp?)\n     apply (subst le_unat_uoi[OF order.strict_implies_order]; simp?)\n    apply (rule image_eqI; simp?)\n   apply clarsimp\n   apply (erule_tac x = \"unat i\" in ballE; simp?)\n    apply (rule l0.upd.u_t_prim'; simp?)\n   apply (clarsimp simp: word_less_nat_alt)\n  apply (rule conjI)\n   apply (clarsimp simp: val.wa_abs_typing_v_def valid_array_def Let_def)\n   apply (rule l0.val.v_t_prim'; simp?)\n  apply clarsimp\n  apply (erule_tac x = \"unat i\" in ballE; simp?)\n   apply (subst nth_map)\n    apply (simp add: word_less_nat_alt)\n   apply simp\n   apply (rule l0.u_v_prim'; simp?)\n   apply (simp add: word_less_nat_alt)\n   apply (rename_tac i)\n   apply (subgoal_tac \"(PTR(32 word) (ptr_val (values_C (heap s p)) + 4 * i)) = (values_C (heap s p) +\\<^sub>p int (unat i))\")\n    apply simp\n   apply (cut_tac p = \"values_C (heap s p)\" and x = \"of_nat x\" in upd.ptr_val_add[where ?'a = \"32 word\"])\n   apply (subst ptr_val_inj[symmetric])\n   apply simp\n  apply (simp add: word_less_nat_alt)\n  done\n\nlemma inputs_staterel_valrel:\n  \"\\<lbrakk>valid_array s p\\<rbrakk> \\<Longrightarrow>\n   \\<exists>\\<sigma>. (\\<sigma>, s) \\<in> upd.state_rel \\<and>\n      \\<sigma> (ptr_val p) = option.Some (UAbstract (arr\\<^sub>u (s, p))) \\<and>\n      (\\<forall>p \\<in> set (arrptrs s p). \\<sigma> p = option.Some (UPrim (LU32 (heap_w32 s (PTR(32 word)p))))) \\<and>\n      val_rel_shallow_C rename (vv\\<^sub>s (s, (t8_C p v))) (t8_C p v) (vv\\<^sub>p (s, (t8_C p v))) (uv\\<^sub>m (s, (t8_C p v))) \\<xi>p1 \\<sigma> \\<Xi>\"\n  apply (clarsimp simp: val_rel_shallow_C_def\n                        valRel_records inputs_def\n                        Let_def\n                        upd.val_rel_simp\n                        valRel_WordArrayWord\n                        ucast_id)\n  apply (rule_tac x = \"(\\<lambda>l. if l = ptr_val p then option.Some (UAbstract (arr\\<^sub>u (s, p))) \n                            else if l \\<in> set (arrptrs s p)\n                              then option.Some (UPrim (LU32 (heap_w32 s (PTR(32 word)l))))\n                            else None)\" in exI)\n  apply (rule conjI)\n   apply (clarsimp simp: upd.state_rel_def upd.heap_rel_def)\n   apply (rule conjI;\n          clarsimp simp: upd.heap_rel_ptr_meta\n                         upd.heap_rel_meta_def\n                         array_def\n                         Let_def\n                         upd.type_rel_simp\n                         upd.wa_abs_repr_def\n                         valid_array_def\n                         upd.val_rel_simp)\n   apply (rename_tac i)\n   apply (erule_tac x = \"of_nat i\" in allE)\n   apply (clarsimp simp: word_less_nat_alt)\n   apply (cut_tac y = i and z = \"(SCAST(32 signed \\<rightarrow> 32) (len_C (heap s p)))\" in le_unat_uoi; simp?)\n   apply (subgoal_tac \"x = values_C (heap s p) +\\<^sub>p uint (of_nat i)\")\n    apply clarsimp\n    apply assumption\n   apply (cut_tac p = \"values_C (heap s p)\" and x = \"of_nat i\" in upd.ptr_val_add[where ?'a = \"32 word\"])\n   apply (simp add: ptr_add_def )\n   apply (subst ptr_val_inj[symmetric])\n   apply simp\n  apply (rule conjI; clarsimp simp: array_def Let_def)\n  apply (rule conjI)\n   apply (clarsimp simp: valid_array_def Let_def)\n   apply (rename_tac i)\n   apply (erule_tac x = \"of_nat i\" in allE)+\n   apply (cut_tac y = i and z = \"(SCAST(32 signed \\<rightarrow> 32) (len_C (heap s p)))\" in le_unat_uoi; simp?)\n   apply (clarsimp simp: word_less_nat_alt)\n  apply (frule_tac v  = v and \\<sigma> = \"(\\<lambda>l. if l = ptr_val p then option.Some (UAbstract (arr\\<^sub>u (s, p))) \n                            else if l \\<in> set (arrptrs s p)\n                              then option.Some (UPrim (LU32 (heap_w32 s (PTR(32 word)l))))\n                            else None)\" in inputs_uv_matches; simp?)\n   apply (clarsimp simp: valid_array_def Let_def)\n   apply (rename_tac j)\n   apply (erule_tac x = \"of_nat j\" in allE)+\n   apply (clarsimp simp: word_less_nat_alt)\n   apply (cut_tac y = j and z = \"(SCAST(32 signed \\<rightarrow> 32) (len_C (heap s p)))\" in le_unat_uoi; simp?)\n    apply (clarsimp simp: array_def Let_def u_v_matches.intros(1))+\n  (*apply (rule_tac x = \"fst (snd Generated_TypeProof.binarySearch_type)\" in exI)*)\n  apply (drule_tac i = 0 in  u_v_matches_proj_single'; simp?)\n  apply clarsimp\n  apply (clarsimp simp: inputs_def array_def Let_def)\n  apply (intro exI conjI; assumption)\n  done\n\nlemma inputs_rename_monoval:\n  \"vv\\<^sub>m sx = val.rename_val rename (val.monoval (vv\\<^sub>p sx))\"\n  apply (clarsimp simp: rename_def inputs_def Let_def array_def split: prod.splits)\n  done\n\nlemma inputs_val_matches:\n  \"val.matches \\<Xi> [vv\\<^sub>m (s, t8_C p v)] \n      [Some (fst (snd (snd (snd Generated_TypeProof.binarySearch_type))))]\"\n  apply (clarsimp simp: val.matches_def\n                        inputs_def\n                        Let_def\n                        array_def\n                        Generated_TypeProof.binarySearch_type_def\n                        Generated_TypeProof.abbreviated_type_defs)\n  apply (intro val.v_t_record val.v_t_r_cons1 val.v_t_r_empty val.v_t_prim' val.v_t_abstract; simp?)\n  apply (clarsimp simp: val.wa_abs_typing_v_def)\n  apply (rule l0.val.v_t_prim'; simp?)\n  done\n\nlemma WordArray_u32_C_eq_simps:\n  \"x = y \\<longleftrightarrow> len_C x = len_C y \\<and> values_C x = values_C y\"\n  apply (rule iffI)\n   apply clarsimp\n  apply clarsimp\n  by (metis WordArray_u32_C_idupdates(1))\n\ncorollary binary_search_C_correct:\n  \"\\<lbrakk>sorted (arrlist (s, p));\n    cc = upd.binarySearch' (t8_C p v);\n    valid_array s p\\<rbrakk> \\<Longrightarrow>\n   \\<not> prod.snd (cc s) \\<and> \n   (\\<forall>r s'. (r, s') \\<in> prod.fst (cc s) \\<longrightarrow>\n      same_array s s' p \\<and>\n      (unat r < length (arrlist (s, p)) \\<longrightarrow> (arrlist (s, p)) ! unat r = v) \\<and> \n      (\\<not> unat r < length (arrlist (s, p)) \\<longrightarrow> v \\<notin> set (arrlist (s, p))))\"\n  apply (frule_tac v = v in inputs_staterel_valrel; clarsimp)\n  apply (frule_tac s = s in \n      corres_shallow_C_binarySearch_concrete[rotated 1,\n             OF _ inputs_val_matches[where s = s and p = p and v = v]];\n      (simp add: inputs_rename_monoval[simplified])?)\n  apply (clarsimp simp: corres_shallow_C_def proc_ctx_wellformed_\\<Xi> \\<xi>_1_\\<xi>m1_matchesuv_\\<Xi> upd.\\<xi>_1_matchesu_\\<Xi>)\n  apply (erule impE)\n   apply (subst inputs_rename_monoval[simplified, symmetric])\n   apply (frule_tac \\<sigma> = \\<sigma> and v = v in inputs_uv_matches; simp?)\n   apply (intro exI; assumption)\n  apply clarsimp\n  apply (erule_tac x = r in allE)\n  apply (erule_tac x = s' in allE)\n  apply clarsimp\n  apply (rule conjI)\n   apply (thin_tac \"_ \\<in> upd.state_rel\")\n   apply (frule_tac v = v in inputs_uv_matches; simp?)\n   apply (drule u_v_matches_to_matches_ptrs)\n\n   apply (drule (1) upd.preservation(1)[where  \\<tau>s = \"[]\" and K = \"[]\", simplified, \n          OF subst_wellformed_nothing proc_ctx_wellformed_\\<Xi>  _ \n             upd.\\<xi>_1_matchesu_\\<Xi> _ binarySearch_typecorrect', simplified, rotated 1])\n   apply (clarsimp simp: Generated_TypeProof.binarySearch_type_def)\n   apply (frule upd.tprim_no_pointers(1))\n   apply (drule upd.tprim_no_pointers(2))\n   apply clarsimp\n   apply (drule upd.frame_empty)\n   apply (clarsimp simp: valid_array_def same_array_def)\n   apply (clarsimp simp: Let_def upd.state_rel_def upd.heap_rel_def upd.heap_rel_ptr_meta)\n   apply (erule_tac x = p in allE)\n   apply (clarsimp simp: upd.heap_rel_meta_def array_def Let_def type_rel_simps upd.wa_abs_repr_def val_rel_simps)\n   apply (rule conjI)\n    apply clarsimp\n    apply (rename_tac i)\n    apply (erule_tac x = \"unat i\" in ballE; simp?)\n     apply (subgoal_tac \"(PTR(32 word) (ptr_val (values_C (heap s p)) + 4 * i)) = (values_C (heap s p) +\\<^sub>p uint i)\")\n      apply simp\n      apply (erule_tac x = \"values_C (heap s' p) +\\<^sub>p uint i\" in allE)\n      apply (clarsimp simp: upd.heap_rel_meta_def array_def Let_def type_rel_simps upd.wa_abs_repr_def val_rel_simps)\n     apply (simp add: ptr_add_def)\n    apply (clarsimp simp: word_less_nat_alt)\n   apply (rule conjI)\n    apply (clarsimp simp:  WordArray_u32_C_eq_simps)\n   apply clarsimp\n   apply (rename_tac i)\n    apply (erule_tac x = \"unat i\" in ballE; simp?)\n     apply (subgoal_tac \"(PTR(32 word) (ptr_val (values_C (heap s p)) + 4 * i)) = (values_C (heap s p) +\\<^sub>p uint i)\")\n      apply simp\n      apply (erule_tac x = \"values_C (heap s' p) +\\<^sub>p uint i\" in allE)\n      apply (clarsimp simp: upd.heap_rel_meta_def array_def Let_def type_rel_simps upd.wa_abs_repr_def val_rel_simps)\n     apply (simp add: ptr_add_def)\n    apply (clarsimp simp: word_less_nat_alt)\n  apply (rotate_tac -1; subst (asm) val_rel_shallow_C_def)\n  apply (clarsimp simp: val_rel_simps valRel_records)\n  apply (erule u_v_uvprimE)\n  apply (drule_tac i = \"unat r\" and v = v  in binary_search_correct; simp?)\n   apply (clarsimp simp: inputs_def array_def Let_def unat_le_helper)+\n  done\n                                                                                               \nend (* of context *)\nend", "meta": {"author": "zilinc", "repo": "popl23-artefact", "sha": "1fe1490d2d34f93dc01ada940c160477db3b9b72", "save_path": "github-repos/isabelle/zilinc-popl23-artefact", "path": "github-repos/isabelle/zilinc-popl23-artefact/popl23-artefact-1fe1490d2d34f93dc01ada940c160477db3b9b72/arrays/loops/BinarySearch.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5506073655352404, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.2602630037940149}}
{"text": "section \\<open>Safety Properties\\<close>\n\ntext \\<open>This section describes the invariants that hold in the system, shows that the implementation\npreserves the invariants, and shows that the invariants imply the required safety properties.\\<close>\n\ntheory Zen\n  imports Implementation OneSlot\nbegin\n\nsubsection \\<open>Invariants on messages\\<close>\n\ntext \\<open>Firstly, a set of invariants that hold on the set of messages that\nhave ever been sent, without considering the state of any individual\nnode.\\<close>\n\nfun nat_inductive_def :: \"'a \\<Rightarrow> (nat \\<Rightarrow> 'a \\<Rightarrow> 'a) \\<Rightarrow> nat \\<Rightarrow> 'a\"\n  where\n    \"nat_inductive_def zeroCase sucCase 0 = zeroCase\"\n  | \"nat_inductive_def zeroCase sucCase (Suc i) = sucCase i (nat_inductive_def zeroCase sucCase i)\"\n\nlocale zenMessages =\n  fixes messages :: \"RoutedMessage set\"\n  fixes isMessageFromTo :: \"Node \\<Rightarrow> Message \\<Rightarrow> Destination \\<Rightarrow> bool\" (\"(_) \\<midarrow>\\<langle> _ \\<rangle>\\<rightarrow> (_)\" [1000,55,1000])\n  defines \"s \\<midarrow>\\<langle> m \\<rangle>\\<rightarrow> d \\<equiv> \\<lparr> sender = s, destination = d, payload = m \\<rparr> \\<in> messages\"\n  fixes isMessageFrom :: \"Node \\<Rightarrow> Message \\<Rightarrow> bool\" (\"(_) \\<midarrow>\\<langle> _ \\<rangle>\\<leadsto>\" [1000,55])\n  defines \"s \\<midarrow>\\<langle> m \\<rangle>\\<leadsto> \\<equiv> \\<exists> d. s \\<midarrow>\\<langle> m \\<rangle>\\<rightarrow> d\"\n  fixes isMessageTo :: \"Message \\<Rightarrow> Destination \\<Rightarrow> bool\" (\"\\<langle> _ \\<rangle>\\<rightarrow> (_)\" [55,1000])\n  defines \"\\<langle> m \\<rangle>\\<rightarrow> d \\<equiv> \\<exists> s. s \\<midarrow>\\<langle> m \\<rangle>\\<rightarrow> d\"\n  fixes isMessage :: \"Message \\<Rightarrow> bool\" (\"\\<langle> _ \\<rangle>\\<leadsto>\" [55])\n  defines \"\\<langle> m \\<rangle>\\<leadsto> \\<equiv> \\<exists> s. s \\<midarrow>\\<langle> m \\<rangle>\\<leadsto>\"\n    (* value proposed in a slot & a term *)\n  fixes v :: \"Slot \\<Rightarrow> Term \\<Rightarrow> Value\"\n  defines \"v i t \\<equiv> THE x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\"\n    (* whether a slot is committed *)\n  fixes isCommitted :: \"Slot \\<Rightarrow> bool\"\n  defines \"isCommitted i \\<equiv> \\<exists> t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto>\"\n    (* whether all preceding slots are committed *)\n  fixes committedTo :: \"Slot \\<Rightarrow> bool\" (\"committed\\<^sub><\")\n  defines \"committed\\<^sub>< i \\<equiv> \\<forall> j < i. isCommitted j\"\n    (* the committed value in a slot *)\n  fixes v\\<^sub>c :: \"Slot \\<Rightarrow> Value\"\n  defines \"v\\<^sub>c i \\<equiv> v i (SOME t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto>)\"\n    (* the configuration of a slot *)\n  fixes V :: \"Slot \\<Rightarrow> Node set\"\n  defines \"V \\<equiv> nat_inductive_def V\\<^sub>0 (\\<lambda>i Vi. if isReconfiguration (v\\<^sub>c i) then getConf (v\\<^sub>c i) else Vi)\"\n    (* predicate to say whether an applicable Vote has been sent *)\n  fixes promised :: \"Slot \\<Rightarrow> Node \\<Rightarrow> Node \\<Rightarrow> Term \\<Rightarrow> bool\"\n  defines \"promised i s dn t \\<equiv> \\<exists> i' \\<le> i. \\<exists> a. s \\<midarrow>\\<langle> Vote i' t a \\<rangle>\\<rightarrow> (OneNode dn)\"\n    (* set of previously-accepted terms *)\n  fixes prevAccepted :: \"Slot \\<Rightarrow> Term \\<Rightarrow> Node set \\<Rightarrow> Term set\"\n  defines \"prevAccepted i t senders\n      \\<equiv> {t'. \\<exists> s \\<in> senders. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> }\"\n  fixes lastCommittedClusterStateBefore :: \"Slot \\<Rightarrow> ClusterState\"\n  defines \"lastCommittedClusterStateBefore \\<equiv> nat_inductive_def CS\\<^sub>0\n      (\\<lambda>i CSi. case v\\<^sub>c i of ClusterStateDiff diff \\<Rightarrow> diff CSi | _ \\<Rightarrow> CSi)\"\n\n(* ASSUMPTIONS *)\nassumes Vote_future:\n  \"\\<And>i i' s t t' a.\n        \\<lbrakk> s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto>; i < i'; t' < t \\<rbrakk>\n            \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i' t' \\<rangle>\\<leadsto>\"\nassumes Vote_None:\n  \"\\<And>i s t t'.\n        \\<lbrakk> s \\<midarrow>\\<langle> Vote i t NO_TERM \\<rangle>\\<leadsto>; t' < t \\<rbrakk>\n            \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\"\nassumes Vote_Some_lt:\n  \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto>\n      \\<Longrightarrow> t' < t\"\nassumes Vote_Some_PublishResponse:\n  \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto>\n      \\<Longrightarrow> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\"\nassumes Vote_Some_max:\n  \"\\<And>i s t t' t''. \\<lbrakk> s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto>; t' < t''; t'' < t \\<rbrakk>\n      \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t'' \\<rangle>\\<leadsto>\"\nassumes Vote_not_broadcast:\n  \"\\<And>i t a d. \\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> d \\<noteq> Broadcast\"\nassumes Vote_unique_destination:\n  \"\\<And>i s t a a' d d'. \\<lbrakk> s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d; s \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<rightarrow> d' \\<rbrakk>\n      \\<Longrightarrow> d = d'\"\nassumes PublishRequest_committedTo:\n  \"\\<And>i t x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> committedTo i\"\nassumes PublishRequest_quorum:\n  \"\\<And>i s t x. s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\n      \\<Longrightarrow> \\<exists> q \\<in> majorities (V i). (\\<forall> n \\<in> q. promised i n s t) \\<and>\n            (prevAccepted i t q = {}\n                \\<or> (\\<exists> t'. v i t = v i t' \\<and> maxTerm (prevAccepted i t q) \\<le> t'\n                                        \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto> \\<and> t' < t))\"\nassumes PublishRequest_function:\n  \"\\<And>i t x x'. \\<lbrakk> \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>; \\<langle> PublishRequest i t x' \\<rangle>\\<leadsto> \\<rbrakk>\n       \\<Longrightarrow> x = x'\"\nassumes finite_messages:\n  \"finite messages\"\nassumes PublishResponse_PublishRequest:\n  \"\\<And>i s t. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists> x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\"\nassumes ApplyCommit_quorum:\n  \"\\<And>i t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto>\n                        \\<Longrightarrow> \\<exists> q \\<in> majorities (V i). \\<forall> s \\<in> q. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\"\nassumes CatchUpResponse_committedTo:\n  \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\"\nassumes CatchUpResponse_V:\n  \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> V i = conf\"\nassumes CatchUpResponse_lastCommittedClusterStateBefore:\n  \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> lastCommittedClusterStateBefore i = cs\"\n\ndefinition (in zenMessages) votedFor :: \"Node \\<Rightarrow> Node \\<Rightarrow> Term \\<Rightarrow> bool\"\n  where \"votedFor n\\<^sub>1 n\\<^sub>2 t \\<equiv> \\<exists> i. promised i n\\<^sub>1 n\\<^sub>2 t\"\n\nlemma (in zenMessages) votedFor_unique:\n  assumes \"votedFor n n\\<^sub>1 t\"\n  assumes \"votedFor n n\\<^sub>2 t\"\n  shows \"n\\<^sub>1 = n\\<^sub>2\"\n  using assms unfolding votedFor_def by (meson Destination.inject Vote_unique_destination promised_def)\n\nlemma (in zenMessages) V_simps[simp]:\n  \"V 0 = V\\<^sub>0\"\n  \"V (Suc i) = (if isReconfiguration (v\\<^sub>c i) then getConf (v\\<^sub>c i) else V i)\"\n  unfolding V_def by simp_all\n\nlemma (in zenMessages) lastCommittedClusterStateBefore_simps[simp]:\n  \"lastCommittedClusterStateBefore 0 = CS\\<^sub>0\"\n  \"lastCommittedClusterStateBefore (Suc i) = (case v\\<^sub>c i of ClusterStateDiff diff \\<Rightarrow> diff | _ \\<Rightarrow> id) (lastCommittedClusterStateBefore i)\"\n  unfolding lastCommittedClusterStateBefore_def by (simp, cases \"v\\<^sub>c i\", auto)\n\ndeclare [[goals_limit = 40]]\n\nsubsubsection \\<open>Utility lemmas\\<close>\n\ntext \\<open>Some results that are useful later:\\<close>\n\nlemma (in zenMessages) V_finite: \"finite (V i)\"\n  by (induct i, simp_all add: finite_V\\<^sub>0 getConf_finite)\n\nlemma (in zenMessages) V_intersects: \"majorities (V i) \\<frown> majorities (V i)\"\n  using V_finite majorities_intersect by simp\n\nlemma (in zenMessages) ApplyCommit_PublishResponse:\n  assumes \"\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>\"\n  obtains s where \"s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\"\n  by (meson ApplyCommit_quorum majorities_member assms)\n\nlemma (in zenMessages) ApplyCommit_PublishRequest:\n  assumes \"\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>\"\n  shows \"\\<langle> PublishRequest i t (v i t) \\<rangle>\\<leadsto>\"\n  by (metis ApplyCommit_PublishResponse PublishResponse_PublishRequest assms the_equality v_def PublishRequest_function)\n\nlemma (in zenMessages) PublishRequest_Vote:\n  assumes \"s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\"\n  obtains i' n a where \"i' \\<le> i\" \"n \\<midarrow>\\<langle> Vote i' t a \\<rangle>\\<rightarrow> (OneNode s)\"\n  by (meson PublishRequest_quorum majorities_member assms isMessage_def promised_def)\n\nlemma (in zenMessages) finite_prevAccepted: \"finite (prevAccepted i t ns)\"\nproof -\n  fix t\\<^sub>0\n  define f :: \"RoutedMessage \\<Rightarrow> Term\" where \"f \\<equiv> \\<lambda> m. case payload m of Vote _ _ (SomeTerm t') \\<Rightarrow> t' | _ \\<Rightarrow> t\\<^sub>0\"\n  have \"prevAccepted i t ns \\<subseteq> f ` messages\"\n    apply (simp add: prevAccepted_def f_def isMessageFrom_def isMessageFromTo_def, intro subsetI)\n    using image_iff by fastforce\n  with finite_messages show ?thesis using finite_surj by auto\nqed\n\nlemma (in zenMessages) promised_long_def: \"\\<exists>d. promised i s d t\n     \\<equiv> (s \\<midarrow>\\<langle> Vote i t NO_TERM \\<rangle>\\<leadsto>\n           \\<or> (\\<exists>i'<i. \\<exists>a. s \\<midarrow>\\<langle> Vote i' t a \\<rangle>\\<leadsto>))\n           \\<or> (\\<exists>t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto>)\"\n  (is \"?LHS == ?RHS\")\nproof -\n  have \"?LHS = ?RHS\"\n    apply (intro iffI)\n    apply (metis TermOption.exhaust isMessageFrom_def nat_less_le promised_def)\n    by (metis Destination.exhaust Vote_not_broadcast isMessageFrom_def isMessageTo_def nat_less_le not_le promised_def)\n  thus \"?LHS == ?RHS\" by simp\nqed\n\nlemma (in zenMessages) Vote_value_function:\n  assumes \"s \\<midarrow>\\<langle> Vote i t a\\<^sub>1 \\<rangle>\\<leadsto>\" and \"s \\<midarrow>\\<langle> Vote i t a\\<^sub>2 \\<rangle>\\<leadsto>\"\n  shows \"a\\<^sub>1 = a\\<^sub>2\"\nproof (cases a\\<^sub>1)\n  case NO_TERM\n  with assms show ?thesis\n    by (metis TermOption.exhaust Vote_None Vote_Some_PublishResponse Vote_Some_lt)\nnext\n  case (SomeTerm t\\<^sub>1)\n  with assms obtain t\\<^sub>2 where a\\<^sub>2: \"a\\<^sub>2 = SomeTerm t\\<^sub>2\"\n    using Vote_None Vote_Some_PublishResponse Vote_Some_lt TermOption.exhaust by metis\n\n  from SomeTerm a\\<^sub>2 assms show ?thesis\n    by (metis Vote_Some_PublishResponse Vote_Some_lt less_linear Vote_Some_max)\nqed\n\nlemma (in zenMessages) shows finite_messages_insert: \"finite (insert m messages)\"\n  using finite_messages by auto\n\nlemma (in zenMessages) isCommitted_committedTo:\n  assumes \"isCommitted i\"\n  shows \"committed\\<^sub>< i\"\n  using ApplyCommit_PublishRequest PublishRequest_committedTo assms isCommitted_def by blast\n\nlemma (in zenMessages) isCommitted_committedTo_Suc:\n  assumes \"isCommitted i\"\n  shows \"committed\\<^sub>< (Suc i)\"\n  using assms committedTo_def isCommitted_committedTo less_antisym by blast\n\nlemma (in zenMessages) promised_unique:\n  assumes \"promised i s d t\" and \"promised i' s d' t\"\n  shows \"d = d'\"\n  by (meson Destination.inject Vote_unique_destination assms promised_def)\n\nlemma (in zenMessages) PublishResponse_PublishRequest_v:\n  assumes \"\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\"\n  shows \"\\<langle> PublishRequest i t (v i t) \\<rangle>\\<leadsto>\"\nproof -\n  from assms obtain s where \"s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\" unfolding isMessage_def by blast\n  with PublishResponse_PublishRequest\n  obtain x where x: \"\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\" by blast\n  have \"v i t = x\" unfolding v_def using x by (intro the_equality PublishRequest_function)\n  with x show ?thesis by simp\nqed\n\nlemma (in zenMessages) Vote_PublishRequest_v:\n  assumes \"\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto>\"\n  shows \"\\<langle> PublishRequest i t' (v i t') \\<rangle>\\<leadsto>\"\n  using assms Vote_Some_PublishResponse PublishResponse_PublishRequest_v\n  unfolding isMessage_def by metis\n\nsubsubsection \\<open>Relationship to @{term oneSlot}\\<close>\n\ntext \\<open>This shows that each slot @{term i} in Zen satisfies the assumptions of the @{term\noneSlot} model above.\\<close>\n\nlemma (in zenMessages) zen_is_oneSlot:\n  fixes i\n  shows \"oneSlot (majorities (V i)) (v i)\n    (\\<lambda> s t. s \\<midarrow>\\<langle> Vote i t NO_TERM \\<rangle>\\<leadsto>\n        \\<or> (\\<exists> i' < i. \\<exists> a. s \\<midarrow>\\<langle> Vote i' t a \\<rangle>\\<leadsto>))\n    (\\<lambda> s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto>)\n    (\\<lambda> t. \\<exists> x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>)\n    (\\<lambda> s t. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>)\n    (\\<lambda> t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto>)\"\nproof (unfold_locales, fold prevAccepted_def promised_long_def)\n  from V_intersects show \"majorities (V i) \\<frown> majorities (V i)\".\nnext\n  fix s t t'\n  assume \"t' < t\" \"s \\<midarrow>\\<langle> Vote i t NO_TERM \\<rangle>\\<leadsto> \\<or> (\\<exists>i'<i. \\<exists>a. s \\<midarrow>\\<langle> Vote i' t a \\<rangle>\\<leadsto>)\"\n  thus \"\\<not> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\"\n    using Vote_None Vote_future by auto\nnext\n  fix s t t'\n  assume j: \"s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto>\"\n  from j show \"t' < t\" using Vote_Some_lt by blast\n  from j show \"s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\" using Vote_Some_PublishResponse by blast\n\n  fix t'' assume \"t' < t''\" \"t'' < t\"\n  with j show \"\\<not> s \\<midarrow>\\<langle> PublishResponse i t'' \\<rangle>\\<leadsto>\" using Vote_Some_max by blast\nnext\n  fix t\n  assume \"\\<exists>x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\"\n  then obtain x s where \"s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\" by (auto simp add: isMessage_def)\n  from PublishRequest_quorum [OF this] PublishResponse_PublishRequest\n  show \"\\<exists>q \\<in> majorities (V i). (\\<forall>n\\<in>q. \\<exists>d. promised i n d t) \\<and> (prevAccepted i t q = {} \\<or> (\\<exists>t'. v i t = v i t' \\<and> maxTerm (prevAccepted i t q) \\<le> t' \\<and> (\\<exists>x. \\<langle> PublishRequest i t' x \\<rangle>\\<leadsto>) \\<and> t' < t))\"\n    unfolding isMessageFrom_def by (meson PublishResponse_PublishRequest_v)\nnext\n  fix s t assume \"s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\"\n  thus \"\\<exists>x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\"\n    by (simp add: PublishResponse_PublishRequest)\nnext\n  fix t assume \"\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>\"\n  thus \"\\<exists>q \\<in> majorities (V i). \\<forall>s\\<in>q. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\"\n    by (simp add: ApplyCommit_quorum)\nnext\n  fix t\\<^sub>0\n  define f :: \"RoutedMessage \\<Rightarrow> Term\"\n    where \"f \\<equiv> \\<lambda> m. case payload m of PublishRequest i t x \\<Rightarrow> t | _ \\<Rightarrow> t\\<^sub>0\"\n\n  have \"{t. \\<exists>x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>} \\<subseteq> f ` messages\"\n    apply (unfold isMessage_def isMessageFrom_def isMessageFromTo_def)\n    using f_def image_iff by fastforce\n\n  moreover have \"finite (f ` messages)\"\n    by (simp add: finite_messages)\n\n  ultimately show \"finite {t. \\<exists>x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>}\"\n    using finite_subset by blast\nqed\n\ntext \\<open>From this it follows that all committed values are equal.\\<close>\n\ntheorem (in zenMessages) consistent:\n  assumes \"\\<langle> ApplyCommit  i t\\<^sub>1 \\<rangle>\\<leadsto>\"\n  assumes \"\\<langle> ApplyCommit  i t\\<^sub>2 \\<rangle>\\<leadsto>\"\n  assumes \"\\<langle> PublishRequest i t\\<^sub>1 v\\<^sub>1 \\<rangle>\\<leadsto>\"\n  assumes \"\\<langle> PublishRequest i t\\<^sub>2 v\\<^sub>2 \\<rangle>\\<leadsto>\"\n  shows \"v\\<^sub>1 = v\\<^sub>2\"\nproof -\n  from oneSlot.consistent [OF zen_is_oneSlot] assms\n  have \"v i t\\<^sub>1 = v i t\\<^sub>2\" by blast\n  moreover have \"v\\<^sub>1 = v i t\\<^sub>1\" using ApplyCommit_PublishRequest assms PublishRequest_function by blast\n  moreover have \"v\\<^sub>2 = v i t\\<^sub>2\" using ApplyCommit_PublishRequest assms PublishRequest_function by blast\n  ultimately show ?thesis by simp\nqed\n\nlemma (in zenMessages) ApplyCommit_v\\<^sub>c:\n  assumes \"\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>\"\n  shows \"v\\<^sub>c i = v i t\"\nproof (unfold v\\<^sub>c_def, intro someI2 [where Q = \"\\<lambda>t'. v i t' = v i t\"])\n  from assms show \"\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>\" .\n  fix t' assume \"\\<langle> ApplyCommit i t' \\<rangle>\\<leadsto>\"\n  thus \"v i t' = v i t\" by (intro oneSlot.consistent [OF zen_is_oneSlot] assms)\nqed\n\nlemma (in zenMessages) ApplyCommit_PublishRequest_v\\<^sub>c:\n  assumes \"\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>\"\n  shows \"\\<langle> PublishRequest i t (v\\<^sub>c i) \\<rangle>\\<leadsto>\"\n  unfolding ApplyCommit_v\\<^sub>c [OF assms]\n  using ApplyCommit_PublishRequest assms .\n\nsubsection \\<open>Invariants on node states\\<close>\n\ntext \\<open>A set of invariants which relate the states of the individual nodes to the set of messages sent.\\<close>\n\nlocale zen = zenMessages +\n  fixes nodeState :: \"Node \\<Rightarrow> NodeData\"\n  assumes currentNode_nodeState: \"\\<And>n. currentNode (nodeState n) = n\"\n  assumes committedTo_firstUncommittedSlot:\n    \"\\<And>n. committed\\<^sub>< (firstUncommittedSlot (nodeState n))\"\n  assumes currentVotingNodes_firstUncommittedSlot:\n    \"\\<And>n. currentVotingNodes (nodeState n) = V (firstUncommittedSlot (nodeState n))\"\n  assumes firstUncommittedSlot_PublishRequest:\n    \"\\<And>i n t x. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\"\n  assumes firstUncommittedSlot_PublishResponse:\n    \"\\<And>i n t. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\"\n  assumes lastAcceptedTerm_None: \"\\<And>n t. lastAcceptedTerm (nodeState n) = NO_TERM\n    \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\"\n  assumes lastAcceptedTerm_Some_sent: \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t\n    \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\"\n  assumes lastAcceptedTerm_Some_max: \"\\<And>n t t'. lastAcceptedTerm (nodeState n) = SomeTerm t\n    \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t' \\<rangle>\\<leadsto>\n    \\<Longrightarrow> t' \\<le> t\"\n  assumes lastAcceptedTerm_Some_currentTerm: \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t\n    \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\"\n  assumes lastAcceptedTerm_Some_value: \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t\n    \\<Longrightarrow> \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t (lastAcceptedValue (nodeState n)) \\<rangle>\\<leadsto>\"\n  assumes Vote_currentTerm:\n    \"\\<And>n i t a. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\"\n  assumes Vote_slot_function:\n    \"\\<And>n i i' t a a'. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> n \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<leadsto> \\<Longrightarrow> i = i'\"\n  assumes PublishRequest_currentTerm:\n    \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto>\n        \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\"\n  assumes PublishRequest_publishPermitted_currentTerm:\n    \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto>\n        \\<Longrightarrow> publishPermitted (nodeState n)\n        \\<Longrightarrow> t < currentTerm (nodeState n)\"\n  assumes joinVotes:\n    \"\\<And> n n'. n' \\<in> joinVotes (nodeState n)\n      \\<Longrightarrow> promised (firstUncommittedSlot (nodeState n)) n' n (currentTerm (nodeState n))\"\n  assumes electionWon_isQuorum:\n    \"\\<And>n. electionWon (nodeState n) \\<Longrightarrow> isQuorum (nodeState n) (joinVotes (nodeState n))\"\n  assumes joinVotes_max: \"\\<And>n n' a'.\n    \\<lbrakk> \\<not> (\\<exists> x. \\<langle> PublishRequest (firstUncommittedSlot (nodeState n))\n                               (currentTerm (nodeState n)) x \\<rangle>\\<leadsto>);\n      n' \\<in> joinVotes (nodeState n);\n      n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot (nodeState n))\n                                (currentTerm (nodeState n))\n                                a' \\<rangle>\\<rightarrow> (OneNode n) \\<rbrakk>\n    \\<Longrightarrow> a' \\<le> lastAcceptedTerm (nodeState n)\"\n  assumes publishVotes: \"\\<And>n n'. n' \\<in> publishVotes (nodeState n)\n    \\<Longrightarrow> n' \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n))\n                              (currentTerm (nodeState n)) \\<rangle>\\<leadsto>\"\n  assumes currentClusterState_lastCommittedClusterStateBefore:\n    \"\\<And>n. currentClusterState (nodeState n)\n              = lastCommittedClusterStateBefore (firstUncommittedSlot (nodeState n))\"\n\nlemma (in zen) joinVotes_votedFor:\n  assumes \"n' \\<in> joinVotes (nodeState n)\"\n  shows \"votedFor n' n (currentTerm (nodeState n))\"\n  using joinVotes assms unfolding votedFor_def by auto\n\nlocale zenStep = zen +\n  fixes messages' :: \"RoutedMessage set\"\n  fixes nodeState' :: \"Node \\<Rightarrow> NodeData\"\n  fixes n\\<^sub>0 :: Node\n\nassumes messages_subset: \"messages \\<subseteq> messages'\"\nfixes nd :: NodeData\ndefines \"nd \\<equiv> nodeState n\\<^sub>0\"\nfixes nd' :: NodeData\ndefines \"nd' \\<equiv> nodeState' n\\<^sub>0\"\nassumes nodeState_unchanged: \"\\<And>n. n \\<noteq> n\\<^sub>0 \\<Longrightarrow> nodeState' n = nodeState n\"\n  (* updated definitions from zenMessages *)\nfixes isMessageFromTo' :: \"Node \\<Rightarrow> Message \\<Rightarrow> Destination \\<Rightarrow> bool\" (\"(_) \\<midarrow>\\<langle> _ \\<rangle>\\<rightarrow>' (_)\" [1000,55,1000])\ndefines \"s \\<midarrow>\\<langle> m \\<rangle>\\<rightarrow>' d \\<equiv> \\<lparr> sender = s, destination = d, payload = m \\<rparr> \\<in> messages'\"\nfixes isMessageFrom' :: \"Node \\<Rightarrow> Message \\<Rightarrow> bool\" (\"(_) \\<midarrow>\\<langle> _ \\<rangle>\\<leadsto>'\" [1000,55])\ndefines \"s \\<midarrow>\\<langle> m \\<rangle>\\<leadsto>' \\<equiv> \\<exists> d. s \\<midarrow>\\<langle> m \\<rangle>\\<rightarrow>' d\"\nfixes isMessageTo' :: \"Message \\<Rightarrow> Destination \\<Rightarrow> bool\" (\"\\<langle> _ \\<rangle>\\<rightarrow>' (_)\" [55,1000])\ndefines \"\\<langle> m \\<rangle>\\<rightarrow>' d \\<equiv> \\<exists> s. s \\<midarrow>\\<langle> m \\<rangle>\\<rightarrow>' d\"\nfixes isMessage' :: \"Message \\<Rightarrow> bool\" (\"\\<langle> _ \\<rangle>\\<leadsto>'\" [55])\ndefines \"\\<langle> m \\<rangle>\\<leadsto>' \\<equiv> \\<exists> s. s \\<midarrow>\\<langle> m \\<rangle>\\<leadsto>'\"\n  (* value proposed in a slot & a term *)\nfixes v' :: \"nat \\<Rightarrow> Term \\<Rightarrow> Value\"\ndefines \"v' i t \\<equiv> THE x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>'\"\n  (* whether a slot is committed *)\nfixes isCommitted' :: \"nat \\<Rightarrow> bool\"\ndefines \"isCommitted' i \\<equiv> \\<exists> t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto>'\"\n  (* whether all preceding slots are committed *)\nfixes committedTo' :: \"nat \\<Rightarrow> bool\" (\"committed\\<^sub><'\")\ndefines \"committed\\<^sub><' i \\<equiv> \\<forall> j < i. isCommitted' j\"\n  (* the committed value in a slot *)\nfixes v\\<^sub>c' :: \"nat \\<Rightarrow> Value\"\ndefines \"v\\<^sub>c' i \\<equiv> v' i (SOME t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto>')\"\n  (* the configuration of a slot *)\nfixes V' :: \"Slot \\<Rightarrow> Node set\"\ndefines \"V' \\<equiv> nat_inductive_def V\\<^sub>0 (\\<lambda>i Vi. if isReconfiguration (v\\<^sub>c' i) then getConf (v\\<^sub>c' i) else Vi)\"\n  (* predicate to say whether an applicable Vote has been sent *)\nfixes promised' :: \"nat \\<Rightarrow> Node \\<Rightarrow> Node \\<Rightarrow> Term \\<Rightarrow> bool\"\ndefines \"promised' i s dn t \\<equiv> \\<exists> i' \\<le> i. \\<exists> a. s \\<midarrow>\\<langle> Vote i' t a \\<rangle>\\<rightarrow>' (OneNode dn)\"\n  (* set of previously-accepted terms *)\nfixes prevAccepted' :: \"nat \\<Rightarrow> Term \\<Rightarrow> Node set \\<Rightarrow> Term set\"\ndefines \"prevAccepted' i t senders\n      \\<equiv> {t'. \\<exists> s \\<in> senders. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto>' }\"\nfixes lastCommittedClusterStateBefore' :: \"nat \\<Rightarrow> ClusterState\"\ndefines \"lastCommittedClusterStateBefore' \\<equiv> nat_inductive_def CS\\<^sub>0\n      (\\<lambda>i CSi. case v\\<^sub>c' i of ClusterStateDiff diff \\<Rightarrow> diff CSi | _ \\<Rightarrow> CSi)\"\nfixes sendTo :: \"Destination \\<Rightarrow> (NodeData * Message option) \\<Rightarrow> RoutedMessage set\"\ndefines \"sendTo d result \\<equiv> case snd result of\n    None \\<Rightarrow> messages | Some m \\<Rightarrow> insert \\<lparr> sender = n\\<^sub>0, destination = d, payload = m \\<rparr> messages\"\n\nlemma (in zenStep) nodeState'_def: \"nodeState' n \\<equiv> if n = n\\<^sub>0 then nd' else nodeState n\"\n  using nodeState_unchanged nd'_def by presburger\n\nlemma (in zenStep) V'_simps[simp]:\n  \"V' 0 = V\\<^sub>0\"\n  \"V' (Suc i) = (if isReconfiguration (v\\<^sub>c' i) then getConf (v\\<^sub>c' i) else V' i)\"\n  unfolding V'_def by simp_all\n\nlemma (in zenStep) lastCommittedClusterStateBefore'_simps[simp]:\n  \"lastCommittedClusterStateBefore' 0 = CS\\<^sub>0\"\n  \"lastCommittedClusterStateBefore' (Suc i) = (case v\\<^sub>c' i of ClusterStateDiff diff \\<Rightarrow> diff | _ \\<Rightarrow> id) (lastCommittedClusterStateBefore' i)\"\n  unfolding lastCommittedClusterStateBefore'_def by (simp, cases \"v\\<^sub>c' i\", auto)\n\nlemma (in zenStep) sendTo_simps[simp]:\n  \"sendTo d (nd'', None) = messages\"\n  \"sendTo d (nd'', Some m) = insert \\<lparr> sender = n\\<^sub>0, destination = d, payload = m \\<rparr> messages\"\n  by (auto simp add: sendTo_def)\n\nlemma currentTerm_ensureCurrentTerm[simp]: \"currentTerm nd \\<le> t \\<Longrightarrow> currentTerm (ensureCurrentTerm t nd) = t\"\n  by (auto simp add: ensureCurrentTerm_def)\n\nlemma (in zenStep)\n  assumes \"\\<And>i i' s t t' a. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto>' \\<Longrightarrow> i < i' \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i' t' \\<rangle>\\<leadsto>'\"\n  assumes \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t NO_TERM \\<rangle>\\<leadsto>' \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>'\"\n  assumes \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto>' \\<Longrightarrow> t' < t\"\n  assumes \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto>' \\<Longrightarrow> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>'\"\n  assumes \"\\<And>i s t t' t''. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto>' \\<Longrightarrow> t' < t'' \\<Longrightarrow> t'' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t'' \\<rangle>\\<leadsto>'\"\n  assumes \"\\<And>i t a d. \\<langle> Vote i t a \\<rangle>\\<rightarrow>' d \\<Longrightarrow> d \\<noteq> Broadcast\"\n  assumes \"\\<And>i' i s t a a' d d'. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow>' d \\<Longrightarrow> s \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<rightarrow>' d' \\<Longrightarrow> d = d'\"\n  assumes \"\\<And>i t x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>' \\<Longrightarrow> committed\\<^sub><' i\"\n  assumes \"\\<And>i s t x. s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>' \\<Longrightarrow> \\<exists>q\\<in>majorities (V' i). (\\<forall>n\\<in>q. promised' i n s t) \\<and> (prevAccepted' i t q = {} \\<or> (\\<exists>t'. v' i t = v' i t' \\<and> maxTerm (prevAccepted' i t q) \\<le> t' \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto>' \\<and> t' < t))\"\n  assumes \"\\<And>i t x x'. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>' \\<Longrightarrow> \\<langle> PublishRequest i t x' \\<rangle>\\<leadsto>' \\<Longrightarrow> x = x'\"\n  assumes \"finite messages'\"\n  assumes \"\\<And>i s t. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>' \\<Longrightarrow> \\<exists>x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>'\"\n  assumes \"\\<And>i t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto>' \\<Longrightarrow> \\<exists>q\\<in>majorities (V' i). \\<forall>s\\<in>q. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>'\"\n  assumes \"\\<And>n. currentNode (nodeState' n) = n\"\n  assumes \"\\<And>n. committed\\<^sub><' (firstUncommittedSlot (nodeState' n))\"\n  assumes \"\\<And>n. currentVotingNodes (nodeState' n) = V' (firstUncommittedSlot (nodeState' n))\"\n  assumes \"\\<And>i n t x. firstUncommittedSlot (nodeState' n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>'\"\n  assumes \"\\<And>i n t. firstUncommittedSlot (nodeState' n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>'\"\n  assumes \"\\<And>n t. lastAcceptedTerm (nodeState' n) = NO_TERM \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState' n)) t \\<rangle>\\<leadsto>'\"\n  assumes \"\\<And>n t. lastAcceptedTerm (nodeState' n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState' n)) t \\<rangle>\\<leadsto>'\"\n  assumes \"\\<And>n t t'. lastAcceptedTerm (nodeState' n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState' n)) t' \\<rangle>\\<leadsto>' \\<Longrightarrow> t' \\<le> t\"\n  assumes \"\\<And>n t. lastAcceptedTerm (nodeState' n) = SomeTerm t \\<Longrightarrow> \\<langle> PublishRequest (firstUncommittedSlot (nodeState' n)) t (lastAcceptedValue (nodeState' n)) \\<rangle>\\<leadsto>'\"\n  assumes \"\\<And>n t. lastAcceptedTerm (nodeState' n) = SomeTerm t \\<Longrightarrow> t \\<le> currentTerm (nodeState' n)\"\n  assumes \"\\<And>n i t a. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto>' \\<Longrightarrow> t \\<le> currentTerm (nodeState' n)\"\n  assumes \"\\<And>n i i' t a a'. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto>' \\<Longrightarrow> n \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<leadsto>' \\<Longrightarrow> i = i'\"\n  assumes \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState' n)) t x \\<rangle>\\<leadsto>' \\<Longrightarrow> t \\<le> currentTerm (nodeState' n)\"\n  assumes \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState' n)) t x \\<rangle>\\<leadsto>' \\<Longrightarrow> publishPermitted (nodeState' n) \\<Longrightarrow> t < currentTerm (nodeState' n)\"\n  assumes \"\\<And>n n'. n' \\<in> joinVotes (nodeState' n) \\<Longrightarrow> promised' (firstUncommittedSlot (nodeState' n)) n' n (currentTerm (nodeState' n))\"\n  assumes \"\\<And>n. electionWon (nodeState' n) \\<Longrightarrow> isQuorum (nodeState' n) (joinVotes (nodeState' n))\"\n  assumes \"\\<And>n n' a'. \\<not> (\\<exists>x. \\<langle> PublishRequest (firstUncommittedSlot (nodeState' n)) (currentTerm (nodeState' n)) x \\<rangle>\\<leadsto>') \\<Longrightarrow> n' \\<in> joinVotes (nodeState' n) \\<Longrightarrow> n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot (nodeState' n)) (currentTerm (nodeState' n)) a' \\<rangle>\\<rightarrow>' (OneNode n) \\<Longrightarrow> a' \\<le> lastAcceptedTerm (nodeState' n)\"\n  assumes \"\\<And>n n'. n' \\<in> publishVotes (nodeState' n) \\<Longrightarrow> n' \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState' n)) (currentTerm (nodeState' n)) \\<rangle>\\<leadsto>'\"\n  assumes \"\\<And>n. currentClusterState (nodeState' n) = lastCommittedClusterStateBefore' (firstUncommittedSlot (nodeState' n))\"\n  assumes \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>' \\<Longrightarrow> committed\\<^sub><' i\"\n  assumes \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>' \\<Longrightarrow> V' i = conf\"\n  assumes \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>' \\<Longrightarrow> lastCommittedClusterStateBefore' i = cs\"\n  shows zenI: \"zen messages' nodeState'\"\n  apply (unfold_locales)\n                      apply (fold isMessageFromTo'_def)\n                      apply (fold isMessageTo'_def)\n                      apply (fold isMessageFrom'_def)\n                      apply (fold isMessage'_def)\n                      apply (fold v'_def)\n                      apply (fold isCommitted'_def)\n                      apply (fold committedTo'_def)\n                      apply (fold v\\<^sub>c'_def)\n                      apply (fold V'_def)\n                      apply (fold promised'_def)\n                      apply (fold prevAccepted'_def)\n                      apply (fold lastCommittedClusterStateBefore'_def)\n  using assms proof - qed\n\nlemma (in zenStep)\n  assumes \"zen messages' nodeState'\" \"messages' \\<subseteq> messages''\" \"\\<And>n. n \\<noteq> n\\<^sub>0 \\<Longrightarrow> nodeState' n = nodeState'' n\"\n  shows zenStepI1: \"zenStep messages' nodeState' messages'' nodeState'' n\\<^sub>0\"\nproof (intro_locales)\n  from `zen messages' nodeState'`\n  show \"zenMessages messages'\" \"zen_axioms messages' nodeState'\"\n    unfolding zen_def by simp_all\n\n  from assms\n  show \"zenStep_axioms messages' nodeState' messages'' nodeState'' n\\<^sub>0\"\n    by (intro zenStep_axioms.intro, auto)\nqed\n\nlemma (in zenStep)\n  assumes \"messages \\<subseteq> messages''\" \"\\<And>n. n \\<noteq> n\\<^sub>0 \\<Longrightarrow> nodeState n = nodeState'' n\"\n  shows zenStepI2: \"zenStep messages nodeState messages'' nodeState'' n\\<^sub>0\"\nproof (intro_locales)\n  from assms\n  show \"zenStep_axioms messages nodeState messages'' nodeState'' n\\<^sub>0\"\n    by (intro zenStep_axioms.intro, auto)\nqed\n\nlemma (in zenStep) Broadcast_to_OneNode:\n  fixes x\n  assumes nodeState': \"nodeState' = nodeState\"\n  assumes sent: \"n\\<^sub>0 \\<midarrow>\\<langle> m \\<rangle>\\<rightarrow> Broadcast\"\n  assumes messages': \"messages' = sendTo (OneNode d) (nd'', Some m)\"\n  shows \"zen messages' nodeState'\"\nproof -\n  have messages': \"messages' = insert \\<lparr>sender = n\\<^sub>0, destination = OneNode d, payload = m \\<rparr> messages\"\n    by (simp add: messages')\n\n  from Vote_not_broadcast sent have not_Vote: \"\\<And>i t a. m \\<noteq> Vote i t a\"\n    unfolding isMessageTo_def by blast\n\n  from sent not_Vote have message_simps:\n    \"\\<And>s m'. (s \\<midarrow>\\<langle> m' \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> m' \\<rangle>\\<leadsto>)\"\n    \"\\<And>m'. (\\<langle> m' \\<rangle>\\<leadsto>') = (\\<langle> m' \\<rangle>\\<leadsto>)\"\n    \"\\<And>s d i t a. (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t a. (\\<langle> Vote i t a \\<rangle>\\<rightarrow>' d) = (\\<langle> Vote i t a \\<rangle>\\<rightarrow> d)\"\n    by (auto simp add: isMessageFromTo'_def isMessageTo'_def isMessage'_def isMessageFrom'_def,\n        auto simp add: isMessageFromTo_def isMessageTo_def isMessage_def isMessageFrom_def messages')\n\n  have property_simps[simp]:\n    \"\\<And>n. currentNode (nodeState' n) = currentNode (nodeState n)\"\n    \"\\<And>n. firstUncommittedSlot (nodeState' n) = firstUncommittedSlot (nodeState n)\"\n    \"\\<And>n. currentVotingNodes (nodeState' n) = currentVotingNodes (nodeState n)\"\n    \"\\<And>n q. isQuorum (nodeState' n) q = isQuorum (nodeState n) q\"\n    \"\\<And>n. currentTerm (nodeState' n) = currentTerm (nodeState n)\"\n    \"\\<And>n. publishPermitted (nodeState' n) = publishPermitted (nodeState n)\"\n    \"\\<And>n. joinVotes (nodeState' n) = joinVotes (nodeState n)\"\n    \"\\<And>n. electionWon (nodeState' n) = electionWon (nodeState n)\"\n    \"\\<And>n. publishVotes (nodeState' n) = publishVotes (nodeState n)\"\n    \"\\<And>n. currentClusterState (nodeState' n) = currentClusterState (nodeState n)\"\n    \"\\<And>n. lastAcceptedTerm (nodeState' n) = lastAcceptedTerm (nodeState n)\"\n    \"\\<And>n. lastAcceptedValue (nodeState' n) = lastAcceptedValue (nodeState n)\"\n    by (unfold nodeState', auto)\n\n  have v_eq[simp]: \"v' = v\" by (intro ext, auto simp add: v'_def v_def message_simps)\n  have v\\<^sub>c_eq[simp]: \"v\\<^sub>c' = v\\<^sub>c\" by (intro ext, auto simp add: v\\<^sub>c'_def v\\<^sub>c_def message_simps)\n  have isCommitted_eq[simp]: \"isCommitted' = isCommitted\" by (intro ext, auto simp add: isCommitted'_def isCommitted_def message_simps)\n  have committedTo_eq[simp]: \"committed\\<^sub><' = committed\\<^sub><\" by (intro ext, auto simp add: committedTo'_def committedTo_def)\n  have V_eq[simp]: \"V' = V\" using v\\<^sub>c_eq V'_def V_def by blast\n  have lastCommittedClusterStateBefore_eq[simp]: \"lastCommittedClusterStateBefore' = lastCommittedClusterStateBefore\"\n    unfolding lastCommittedClusterStateBefore_def lastCommittedClusterStateBefore'_def v\\<^sub>c_eq ..\n  have promised_eq[simp]: \"promised' = promised\" by (intro ext, auto simp add: promised'_def promised_def message_simps)\n  have prevAccepted_eq[simp]: \"prevAccepted' = prevAccepted\" by (intro ext, auto simp add: prevAccepted'_def prevAccepted_def message_simps)\n\n  show ?thesis\n    apply (intro zenI)\n                        apply (unfold message_simps committedTo_eq V_eq v_eq\n        lastCommittedClusterStateBefore_eq property_simps promised_eq prevAccepted_eq)\n  proof -\n    from finite_messages show \"finite messages'\" by (simp add: messages')\n    from Vote_future show \"\\<And>i i' s t t' a. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> i < i' \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i' t' \\<rangle>\\<leadsto>\".\n    from Vote_None show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t NO_TERM \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_lt show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t\".\n    from Vote_Some_PublishResponse show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_max show \"\\<And>i s t t' t''. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t'' \\<Longrightarrow> t'' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t'' \\<rangle>\\<leadsto>\".\n    from Vote_not_broadcast show \"\\<And>i t a d. \\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> d \\<noteq> Broadcast\".\n    from Vote_unique_destination show \"\\<And>i' i s t a a' d d'. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> s \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<rightarrow> d' \\<Longrightarrow> d = d'\".\n    from currentNode_nodeState show \"\\<And>n. currentNode (nodeState n) = n\" .\n    from committedTo_firstUncommittedSlot show \"\\<And>n. committed\\<^sub>< (firstUncommittedSlot (nodeState n))\" .\n    from firstUncommittedSlot_PublishResponse show \"\\<And>n i t. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\" .\n    from lastAcceptedTerm_None show \"\\<And>n i t. lastAcceptedTerm (nodeState n) = NO_TERM \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_sent show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_max show \"\\<And>n t t'. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t' \\<rangle>\\<leadsto> \\<Longrightarrow> t' \\<le> t\".\n    from Vote_currentTerm show \"\\<And>n i t a. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from Vote_slot_function show \"\\<And>n i i' t a a'. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> n \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<leadsto> \\<Longrightarrow> i = i'\".\n    from electionWon_isQuorum show \"\\<And>n. electionWon (nodeState n) \\<Longrightarrow> isQuorum (nodeState n) (joinVotes (nodeState n))\".\n    from joinVotes_max show \" \\<And>n n' a'. \\<not> (\\<exists>x. \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) x \\<rangle>\\<leadsto>) \\<Longrightarrow> n' \\<in> joinVotes (nodeState n) \\<Longrightarrow> n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) a' \\<rangle>\\<rightarrow> (OneNode n) \\<Longrightarrow> a' \\<le> lastAcceptedTerm (nodeState n)\".\n    from publishVotes show \"\\<And>n n'. n' \\<in> publishVotes (nodeState n) \\<Longrightarrow> n' \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) \\<rangle>\\<leadsto>\".\n    from currentClusterState_lastCommittedClusterStateBefore show \"\\<And>n. currentClusterState (nodeState n) = lastCommittedClusterStateBefore (firstUncommittedSlot (nodeState n))\".\n    from joinVotes show \"\\<And>n n'. n' \\<in> joinVotes (nodeState n) \\<Longrightarrow> promised (firstUncommittedSlot (nodeState n)) n' n (currentTerm (nodeState n))\".\n    from PublishRequest_committedTo show \"\\<And>i t x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from PublishRequest_quorum show \"\\<And>i s t x. s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). (\\<forall>n\\<in>q. promised i n s t) \\<and> (prevAccepted i t q = {} \\<or> (\\<exists>t'. v i t = v i t' \\<and> maxTerm (prevAccepted i t q) \\<le> t' \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto> \\<and> t' < t))\".\n    from PublishRequest_function show \"\\<And>i t x x'. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<langle> PublishRequest i t x' \\<rangle>\\<leadsto> \\<Longrightarrow> x = x'\".\n    from PublishResponse_PublishRequest show \"\\<And>i s t. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from ApplyCommit_quorum show \"\\<And>i t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). \\<forall>s\\<in>q. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\".\n    from currentVotingNodes_firstUncommittedSlot show \"\\<And>n. currentVotingNodes (nodeState n) = V (firstUncommittedSlot (nodeState n))\".\n    from firstUncommittedSlot_PublishRequest show \"\\<And>i n t x. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_value show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t (lastAcceptedValue (nodeState n)) \\<rangle>\\<leadsto>\".\n    from PublishRequest_currentTerm show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from PublishRequest_publishPermitted_currentTerm show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> publishPermitted (nodeState n) \\<Longrightarrow> t < currentTerm (nodeState n)\".\n    from CatchUpResponse_committedTo show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from CatchUpResponse_V show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> V i = conf\".\n    from CatchUpResponse_lastCommittedClusterStateBefore show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> lastCommittedClusterStateBefore i = cs\".\n    from lastAcceptedTerm_Some_currentTerm show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n  qed\nqed\n\nlemma (in zenStep) send_spontaneous_message:\n  assumes messages': \"messages' = sendTo d\\<^sub>0 (nd, Some m)\"\n  assumes spontaneous: \"case m of StartJoin _ \\<Rightarrow> True | ClientValue _ \\<Rightarrow> True | Reboot \\<Rightarrow> True | CatchUpRequest \\<Rightarrow> True | _ \\<Rightarrow> False\"\n  assumes nodeState': \"nodeState' = nodeState\"\n  shows \"zen messages' nodeState'\"\nproof -\n  have messages': \"messages' = insert \\<lparr>sender = n\\<^sub>0, destination = d\\<^sub>0, payload = m \\<rparr> messages\"\n    by (simp add: messages')\n\n  from spontaneous\n  have message_simps[simp]:\n    \"\\<And>s d i t a. (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s d i t. (s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s d i t x. (s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s d i t. (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t a. (\\<langle> Vote i t a \\<rangle>\\<rightarrow>' d) = (\\<langle> Vote i t a \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t. (\\<langle> PublishResponse i t \\<rangle>\\<rightarrow>' d) = (\\<langle> PublishResponse i t \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t x. (\\<langle> PublishRequest i t x \\<rangle>\\<rightarrow>' d) = (\\<langle> PublishRequest i t x \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t. (\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow>' d) = (\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s i t a. (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto>)\"\n    \"\\<And>s i t. (s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>)\"\n    \"\\<And>s i t x. (s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>)\"\n    \"\\<And>s i t. (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>)\"\n    \"\\<And>d i t a. (\\<langle> Vote i t a \\<rangle>\\<leadsto>') = (\\<langle> Vote i t a \\<rangle>\\<leadsto>)\"\n    \"\\<And>d i t. (\\<langle> PublishResponse i t \\<rangle>\\<leadsto>') = (\\<langle> PublishResponse i t \\<rangle>\\<leadsto>)\"\n    \"\\<And>d i t x. (\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>') = (\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>)\"\n    \"\\<And>d i t. (\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>') = (\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>)\"\n    \"\\<And>s d i conf cs. (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i conf cs. (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow>' d) = (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s i conf cs. (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>)\"\n    \"\\<And>d i conf cs. (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>') = (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>)\"\n    by (auto simp add: isMessageFromTo'_def isMessageTo'_def isMessage'_def isMessageFrom'_def,\n        auto simp add: isMessageFromTo_def isMessageTo_def isMessage_def isMessageFrom_def messages')\n\n  have property_simps[simp]:\n    \"\\<And>n. currentNode (nodeState' n) = currentNode (nodeState n)\"\n    \"\\<And>n. firstUncommittedSlot (nodeState' n) = firstUncommittedSlot (nodeState n)\"\n    \"\\<And>n. currentVotingNodes (nodeState' n) = currentVotingNodes (nodeState n)\"\n    \"\\<And>n q. isQuorum (nodeState' n) q = isQuorum (nodeState n) q\"\n    \"\\<And>n. currentTerm (nodeState' n) = currentTerm (nodeState n)\"\n    \"\\<And>n. publishPermitted (nodeState' n) = publishPermitted (nodeState n)\"\n    \"\\<And>n. joinVotes (nodeState' n) = joinVotes (nodeState n)\"\n    \"\\<And>n. electionWon (nodeState' n) = electionWon (nodeState n)\"\n    \"\\<And>n. publishVotes (nodeState' n) = publishVotes (nodeState n)\"\n    \"\\<And>n. currentClusterState (nodeState' n) = currentClusterState (nodeState n)\"\n    \"\\<And>n. lastAcceptedTerm (nodeState' n) = lastAcceptedTerm (nodeState n)\"\n    \"\\<And>n. lastAcceptedValue (nodeState' n) = lastAcceptedValue (nodeState n)\"\n    by (unfold nodeState', auto)\n\n  have v_eq[simp]: \"v' = v\" by (intro ext, auto simp add: v'_def v_def)\n  have v\\<^sub>c_eq[simp]: \"v\\<^sub>c' = v\\<^sub>c\" by (intro ext, auto simp add: v\\<^sub>c'_def v\\<^sub>c_def)\n  have isCommitted_eq[simp]: \"isCommitted' = isCommitted\" by (intro ext, auto simp add: isCommitted'_def isCommitted_def)\n  have committedTo_eq[simp]: \"committed\\<^sub><' = committed\\<^sub><\" by (intro ext, auto simp add: committedTo'_def committedTo_def)\n  have V_eq[simp]: \"V' = V\" using v\\<^sub>c_eq V'_def V_def by blast\n  have lastCommittedClusterStateBefore_eq[simp]: \"lastCommittedClusterStateBefore' = lastCommittedClusterStateBefore\"\n    unfolding lastCommittedClusterStateBefore_def lastCommittedClusterStateBefore'_def v\\<^sub>c_eq ..\n  have promised_eq[simp]: \"promised' = promised\" by (intro ext, auto simp add: promised'_def promised_def)\n  have prevAccepted_eq[simp]: \"prevAccepted' = prevAccepted\" by (intro ext, auto simp add: prevAccepted'_def prevAccepted_def)\n\n  show ?thesis\n    apply (intro zenI)\n                        apply (unfold message_simps committedTo_eq V_eq v_eq\n        lastCommittedClusterStateBefore_eq property_simps promised_eq prevAccepted_eq)\n  proof -\n    from finite_messages show \"finite messages'\" by (simp add: messages')\n    from Vote_future show \"\\<And>i i' s t t' a. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> i < i' \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i' t' \\<rangle>\\<leadsto>\".\n    from Vote_None show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t NO_TERM \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_lt show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t\".\n    from Vote_Some_PublishResponse show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_max show \"\\<And>i s t t' t''. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t'' \\<Longrightarrow> t'' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t'' \\<rangle>\\<leadsto>\".\n    from Vote_not_broadcast show \"\\<And>i t a d. \\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> d \\<noteq> Broadcast\".\n    from Vote_unique_destination show \"\\<And>i' i s t a a' d d'. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> s \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<rightarrow> d' \\<Longrightarrow> d = d'\".\n    from currentNode_nodeState show \"\\<And>n. currentNode (nodeState n) = n\" .\n    from committedTo_firstUncommittedSlot show \"\\<And>n. committed\\<^sub>< (firstUncommittedSlot (nodeState n))\" .\n    from firstUncommittedSlot_PublishResponse show \"\\<And>n i t. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\" .\n    from lastAcceptedTerm_None show \"\\<And>n i t. lastAcceptedTerm (nodeState n) = NO_TERM \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_sent show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_max show \"\\<And>n t t'. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t' \\<rangle>\\<leadsto> \\<Longrightarrow> t' \\<le> t\".\n    from Vote_currentTerm show \"\\<And>n i t a. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from Vote_slot_function show \"\\<And>n i i' t a a'. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> n \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<leadsto> \\<Longrightarrow> i = i'\".\n    from electionWon_isQuorum show \"\\<And>n. electionWon (nodeState n) \\<Longrightarrow> isQuorum (nodeState n) (joinVotes (nodeState n))\".\n    from joinVotes_max show \" \\<And>n n' a'. \\<not> (\\<exists>x. \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) x \\<rangle>\\<leadsto>) \\<Longrightarrow> n' \\<in> joinVotes (nodeState n) \\<Longrightarrow> n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) a' \\<rangle>\\<rightarrow> (OneNode n) \\<Longrightarrow> a' \\<le> lastAcceptedTerm (nodeState n)\".\n    from publishVotes show \"\\<And>n n'. n' \\<in> publishVotes (nodeState n) \\<Longrightarrow> n' \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) \\<rangle>\\<leadsto>\".\n    from currentClusterState_lastCommittedClusterStateBefore show \"\\<And>n. currentClusterState (nodeState n) = lastCommittedClusterStateBefore (firstUncommittedSlot (nodeState n))\".\n    from joinVotes show \"\\<And>n n'. n' \\<in> joinVotes (nodeState n) \\<Longrightarrow> promised (firstUncommittedSlot (nodeState n)) n' n (currentTerm (nodeState n))\".\n    from PublishRequest_committedTo show \"\\<And>i t x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from PublishRequest_quorum show \"\\<And>i s t x. s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). (\\<forall>n\\<in>q. promised i n s t) \\<and> (prevAccepted i t q = {} \\<or> (\\<exists>t'. v i t = v i t' \\<and> maxTerm (prevAccepted i t q) \\<le> t' \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto> \\<and> t' < t))\".\n    from PublishRequest_function show \"\\<And>i t x x'. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<langle> PublishRequest i t x' \\<rangle>\\<leadsto> \\<Longrightarrow> x = x'\".\n    from PublishResponse_PublishRequest show \"\\<And>i s t. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from ApplyCommit_quorum show \"\\<And>i t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). \\<forall>s\\<in>q. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\".\n    from currentVotingNodes_firstUncommittedSlot show \"\\<And>n. currentVotingNodes (nodeState n) = V (firstUncommittedSlot (nodeState n))\".\n    from firstUncommittedSlot_PublishRequest show \"\\<And>i n t x. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_value show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t (lastAcceptedValue (nodeState n)) \\<rangle>\\<leadsto>\".\n    from PublishRequest_currentTerm show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from PublishRequest_publishPermitted_currentTerm show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> publishPermitted (nodeState n) \\<Longrightarrow> t < currentTerm (nodeState n)\".\n    from CatchUpResponse_committedTo show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from CatchUpResponse_V show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> V i = conf\".\n    from CatchUpResponse_lastCommittedClusterStateBefore show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> lastCommittedClusterStateBefore i = cs\".\n    from lastAcceptedTerm_Some_currentTerm show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n  qed\nqed\n\nlemma (in zenStep) send_StartJoin:\n  assumes messages': \"messages' = sendTo d\\<^sub>0 (nd, Some (StartJoin t\\<^sub>0))\"\n  assumes nodeState': \"nodeState' = nodeState\"\n  shows \"zen messages' nodeState'\"\n  using assms by (intro send_spontaneous_message, auto)\n\nlemma (in zenStep) send_ClientValue:\n  assumes messages': \"messages' = sendTo d\\<^sub>0 (nd, Some (ClientValue x\\<^sub>0))\"\n  assumes nodeState': \"nodeState' = nodeState\"\n  shows \"zen messages' nodeState'\"\n  using assms by (intro send_spontaneous_message, auto)\n\nlemma (in zenStep) send_CatchUpRequest:\n  assumes messages': \"messages' = sendTo d\\<^sub>0 (nd, Some CatchUpRequest)\"\n  assumes nodeState': \"nodeState' = nodeState\"\n  shows \"zen messages' nodeState'\"\n  using assms by (intro send_spontaneous_message, auto)\n\nlemma (in zenStep) send_Reboot:\n  assumes messages': \"messages' = sendTo d\\<^sub>0 (nd, Some Reboot)\"\n  assumes nodeState': \"nodeState' = nodeState\"\n  shows \"zen messages' nodeState'\"\n  using assms by (intro send_spontaneous_message, auto)\n\nlemma (in zenStep) ensureCurrentTerm_invariants:\n  assumes nd': \"nd' = ensureCurrentTerm t nd\"\n  assumes messages': \"messages' = messages\"\n  shows \"zen messages' nodeState'\"\nproof (cases \"t \\<le> currentTerm nd\")\n  case True\n  hence \"nodeState' = nodeState\"\n    by (intro ext, unfold nodeState'_def, auto simp add: nd' ensureCurrentTerm_def nd_def)\n  with zen_axioms messages' show ?thesis by simp\nnext\n  case False hence t: \"currentTerm nd < t\" by simp\n\n  have message_simps[simp]:\n    \"\\<And>s p d. (s \\<midarrow>\\<langle> p \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> p \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>p d. (\\<langle> p \\<rangle>\\<rightarrow>' d) = (\\<langle> p \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s p. (s \\<midarrow>\\<langle> p \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> p \\<rangle>\\<leadsto>)\"\n    \"\\<And>p. (\\<langle> p \\<rangle>\\<leadsto>') = (\\<langle> p \\<rangle>\\<leadsto>)\"\n    by (unfold isMessageFromTo'_def isMessageTo'_def isMessageFrom'_def isMessage'_def,\n        auto simp add: messages' isMessageFromTo_def isMessageTo_def isMessageFrom_def isMessage_def)\n\n  have property_simps[simp]:\n    \"\\<And>n. currentNode (nodeState' n) = currentNode (nodeState n)\"\n    \"\\<And>n. firstUncommittedSlot (nodeState' n) = firstUncommittedSlot (nodeState n)\"\n    \"\\<And>n. currentClusterState (nodeState' n) = currentClusterState (nodeState n)\"\n    \"\\<And>n. currentVotingNodes (nodeState' n) = currentVotingNodes (nodeState n)\"\n    \"\\<And>n q. isQuorum (nodeState' n) q = isQuorum (nodeState n) q\"\n    \"\\<And>n. lastAcceptedTerm (nodeState' n) = lastAcceptedTerm (nodeState n)\"\n    \"\\<And>n. lastAcceptedValue (nodeState' n) = lastAcceptedValue (nodeState n)\"\n    \"currentTerm (nodeState' n\\<^sub>0) = t\"\n    \"electionWon (nodeState' n\\<^sub>0) = False\"\n    \"joinVotes (nodeState' n\\<^sub>0) = {}\"\n    \"publishPermitted (nodeState' n\\<^sub>0) = True\"\n    \"publishVotes (nodeState' n\\<^sub>0) = {}\"\n    using t\n    by (unfold nodeState'_def, auto simp add: nd_def isQuorum_def nd' ensureCurrentTerm_def\n        lastAcceptedTerm_def lastAcceptedValue_def)\n\n  have currentTerm_increases: \"\\<And>n. currentTerm (nodeState n) \\<le> currentTerm (nodeState' n)\"\n    using nd_def nodeState'_def property_simps t by auto\n\n  have v_eq[simp]: \"v' = v\" by (intro ext, auto simp add: v'_def v_def)\n  have v\\<^sub>c_eq[simp]: \"v\\<^sub>c' = v\\<^sub>c\" by (intro ext, auto simp add: v\\<^sub>c'_def v\\<^sub>c_def)\n  have isCommitted_eq[simp]: \"isCommitted' = isCommitted\" by (intro ext, auto simp add: isCommitted'_def isCommitted_def)\n  have committedTo_eq[simp]: \"committed\\<^sub><' = committed\\<^sub><\" by (intro ext, auto simp add: committedTo'_def committedTo_def)\n  have V_eq[simp]: \"V' = V\" using v\\<^sub>c_eq V'_def V_def by blast\n  have lastCommittedClusterStateBefore_eq[simp]: \"lastCommittedClusterStateBefore' = lastCommittedClusterStateBefore\"\n    unfolding lastCommittedClusterStateBefore_def lastCommittedClusterStateBefore'_def v\\<^sub>c_eq ..\n  have promised_eq: \"\\<And>i n n' t. promised' i n n' t = promised i n n' t\" by (simp add: promised_def promised'_def)\n  have prevAccepted_eq: \"\\<And>i t q. prevAccepted' i t q  = prevAccepted i t q\" by (simp add: prevAccepted_def prevAccepted'_def)\n\n  show ?thesis\n    apply (intro zenI)\n                        apply (unfold message_simps committedTo_eq V_eq v_eq\n        lastCommittedClusterStateBefore_eq property_simps promised_eq prevAccepted_eq)\n  proof -\n    from finite_messages show \"finite messages'\" by (simp add: messages')\n    from Vote_future show \"\\<And>i i' s t t' a. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> i < i' \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i' t' \\<rangle>\\<leadsto>\".\n    from Vote_None show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t NO_TERM \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_lt show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t\".\n    from Vote_Some_PublishResponse show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_max show \"\\<And>i s t t' t''. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t'' \\<Longrightarrow> t'' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t'' \\<rangle>\\<leadsto>\".\n    from Vote_not_broadcast show \"\\<And>i t a d. \\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> d \\<noteq> Broadcast\".\n    from Vote_unique_destination show \"\\<And>i' i s t a a' d d'. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> s \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<rightarrow> d' \\<Longrightarrow> d = d'\".\n    from currentNode_nodeState show \"\\<And>n. currentNode (nodeState n) = n\" .\n    from committedTo_firstUncommittedSlot show \"\\<And>n. committed\\<^sub>< (firstUncommittedSlot (nodeState n))\" .\n    from firstUncommittedSlot_PublishResponse show \"\\<And>n i t. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\" .\n    from lastAcceptedTerm_None show \"\\<And>n i t. lastAcceptedTerm (nodeState n) = NO_TERM \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_sent show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_max show \"\\<And>n t t'. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t' \\<rangle>\\<leadsto> \\<Longrightarrow> t' \\<le> t\".\n    from Vote_slot_function show \"\\<And>n i i' t a a'. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> n \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<leadsto> \\<Longrightarrow> i = i'\".\n    from currentClusterState_lastCommittedClusterStateBefore show \"\\<And>n. currentClusterState (nodeState n) = lastCommittedClusterStateBefore (firstUncommittedSlot (nodeState n))\".\n    from PublishRequest_committedTo show \"\\<And>i t x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from PublishRequest_function show \"\\<And>i t x x'. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<langle> PublishRequest i t x' \\<rangle>\\<leadsto> \\<Longrightarrow> x = x'\".\n    from PublishResponse_PublishRequest show \"\\<And>i s t. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from ApplyCommit_quorum show \"\\<And>i t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). \\<forall>s\\<in>q. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\".\n    from currentVotingNodes_firstUncommittedSlot show \"\\<And>n. currentVotingNodes (nodeState n) = V (firstUncommittedSlot (nodeState n))\".\n    from firstUncommittedSlot_PublishRequest show \"\\<And>i n t x. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_value show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t (lastAcceptedValue (nodeState n)) \\<rangle>\\<leadsto>\".\n    from PublishRequest_quorum show \"\\<And>i s t x. s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). (\\<forall>n\\<in>q. promised i n s t) \\<and> (prevAccepted i t q = {} \\<or> (\\<exists>t'. v i t = v i t' \\<and> maxTerm (prevAccepted i t q) \\<le> t' \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto> \\<and> t' < t))\".\n    from CatchUpResponse_committedTo show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from CatchUpResponse_V show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> V i = conf\".\n    from CatchUpResponse_lastCommittedClusterStateBefore show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> lastCommittedClusterStateBefore i = cs\".\n\n    from Vote_currentTerm currentTerm_increases\n    show \"\\<And>n i t a. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState' n)\"\n      using dual_order.trans by blast\n\n    from PublishRequest_publishPermitted_currentTerm currentTerm_increases property_simps\n    show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> publishPermitted (nodeState' n) \\<Longrightarrow> t < currentTerm (nodeState' n)\"\n      by (metis False PublishRequest_currentTerm dual_order.trans leI nd_def nodeState_unchanged)\n\n    from joinVotes\n    show \"\\<And>n n'. n' \\<in> joinVotes (nodeState' n) \\<Longrightarrow> promised (firstUncommittedSlot (nodeState n)) n' n (currentTerm (nodeState' n))\"\n      unfolding nodeState'_def by (auto simp add: nd'_def)\n\n    from PublishRequest_currentTerm currentTerm_increases\n    show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState' n)\"\n      using dual_order.trans by blast\n\n    from publishVotes\n    show \"\\<And>n n'. n' \\<in> publishVotes (nodeState' n) \\<Longrightarrow> n' \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState' n)) \\<rangle>\\<leadsto>\"\n      unfolding nodeState'_def by (auto simp add: nd'_def)\n\n    from electionWon_isQuorum show \"\\<And>n. electionWon (nodeState' n) \\<Longrightarrow> isQuorum (nodeState n) (joinVotes (nodeState' n))\"\n      unfolding nodeState'_def by (auto simp add: nd'_def)\n\n    from lastAcceptedTerm_Some_currentTerm currentTerm_increases\n    show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> t \\<le> currentTerm (nodeState' n)\"\n      using dual_order.trans by blast\n\n    show \"\\<And>n n' a'. \\<not> (\\<exists>x. \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState' n)) x \\<rangle>\\<leadsto>) \\<Longrightarrow> n' \\<in> joinVotes (nodeState' n) \\<Longrightarrow> n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState' n)) a' \\<rangle>\\<rightarrow> (OneNode n) \\<Longrightarrow> a' \\<le> lastAcceptedTerm (nodeState n)\"\n      by (metis ex_in_conv joinVotes_max nodeState_unchanged property_simps(10))\n  qed\nqed\n\nlemma (in zenStep) sendVote_invariants:\n  assumes messages': \"messages' = sendTo (OneNode d\\<^sub>0) (nd'',\n    Some (Vote (firstUncommittedSlot nd) (currentTerm nd) (lastAcceptedTerm nd)))\"\n  assumes nd': \"nd' = nd\"\n  assumes not_sent: \"\\<And>i a. \\<not> n\\<^sub>0 \\<midarrow>\\<langle> Vote i (currentTerm nd) a \\<rangle>\\<leadsto>\"\n  assumes not_accepted: \"\\<And>t'. lastAcceptedTerm nd = SomeTerm t' \\<Longrightarrow> t' < currentTerm nd\"\n  shows \"zen messages' nodeState'\"\nproof -\n  have messages': \"messages' = insert \\<lparr>sender = n\\<^sub>0, destination = OneNode d\\<^sub>0,\n                       payload = Vote (firstUncommittedSlot nd) (currentTerm nd) (lastAcceptedTerm nd)\\<rparr> messages\"\n    by (simp add: messages')\n\n  have nodeState'[simp]: \"nodeState' = nodeState\"\n    by (intro ext, auto simp add: nodeState'_def nd' nd_def)\n\n  have message_simps[simp]:\n    \"\\<And>s d i t. (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s d i t x. (s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s d i t. (s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t. (\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow>' d) = (\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t x. (\\<langle> PublishRequest i t x \\<rangle>\\<rightarrow>' d) = (\\<langle> PublishRequest i t x \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t. (\\<langle> PublishResponse i t \\<rangle>\\<rightarrow>' d) = (\\<langle> PublishResponse i t \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s i t. (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>)\"\n    \"\\<And>s i t x. (s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>)\"\n    \"\\<And>s i t. (s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>)\"\n    \"\\<And>i t. (\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>') = (\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>)\"\n    \"\\<And>i t x. (\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>') = (\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>)\"\n    \"\\<And>i t. (\\<langle> PublishResponse i t \\<rangle>\\<leadsto>') = (\\<langle> PublishResponse i t \\<rangle>\\<leadsto>)\"\n    \"\\<And>s d i conf cs. (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i conf cs. (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow>' d) = (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s i conf cs. (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>)\"\n    \"\\<And>d i conf cs. (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>') = (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>)\"\n    by (unfold isMessageFromTo'_def isMessageTo'_def isMessageFrom'_def isMessage'_def,\n        auto simp add: messages' isMessageFromTo_def isMessageTo_def isMessageFrom_def isMessage_def)\n\n  have Vote':\n    \"\\<And>s d i t' a. (s \\<midarrow>\\<langle> Vote i t' a \\<rangle>\\<rightarrow>' d) =\n    ((s \\<midarrow>\\<langle> Vote i t' a \\<rangle>\\<rightarrow> d)\n      \\<or> (s, i, t', a, d) = (n\\<^sub>0, firstUncommittedSlot nd, currentTerm nd, lastAcceptedTerm nd, OneNode d\\<^sub>0))\"\n    \"\\<And>d i t' a. (\\<langle> Vote i t' a \\<rangle>\\<rightarrow>' d) =\n    ((\\<langle> Vote i t' a \\<rangle>\\<rightarrow> d)\n      \\<or> (i, t', a, d) = (firstUncommittedSlot nd, currentTerm nd, lastAcceptedTerm nd, OneNode d\\<^sub>0))\"\n    \"\\<And>s i t' a. (s \\<midarrow>\\<langle> Vote i t' a \\<rangle>\\<leadsto>') =\n    ((s \\<midarrow>\\<langle> Vote i t' a \\<rangle>\\<leadsto>)\n      \\<or> (s, i, t', a) = (n\\<^sub>0, firstUncommittedSlot nd, currentTerm nd, lastAcceptedTerm nd))\"\n    \"\\<And>i t' a. (\\<langle> Vote i t' a \\<rangle>\\<leadsto>') =\n    ((\\<langle> Vote i t' a \\<rangle>\\<leadsto>)\n      \\<or> (i, t', a) = (firstUncommittedSlot nd, currentTerm nd, lastAcceptedTerm nd))\"\n    by (unfold isMessageFromTo'_def isMessageFromTo_def isMessageTo'_def isMessageTo_def\n        isMessageFrom'_def isMessageFrom_def isMessage'_def isMessage_def, auto simp add: messages')\n\n  have v_eq[simp]: \"v' = v\" by (intro ext, auto simp add: v'_def v_def)\n  have v\\<^sub>c_eq[simp]: \"v\\<^sub>c' = v\\<^sub>c\" by (intro ext, auto simp add: v\\<^sub>c'_def v\\<^sub>c_def)\n  have isCommitted_eq[simp]: \"isCommitted' = isCommitted\" by (intro ext, auto simp add: isCommitted'_def isCommitted_def)\n  have committedTo_eq[simp]: \"committed\\<^sub><' = committed\\<^sub><\" by (intro ext, auto simp add: committedTo'_def committedTo_def)\n  have V_eq[simp]: \"V' = V\" using v\\<^sub>c_eq V'_def V_def by blast\n  have lastCommittedClusterStateBefore_eq[simp]: \"lastCommittedClusterStateBefore' = lastCommittedClusterStateBefore\"\n    unfolding lastCommittedClusterStateBefore_def lastCommittedClusterStateBefore'_def v\\<^sub>c_eq ..\n\n  have promised_eq: \"\\<And>i s dn t. promised' i s dn t = (promised i s dn t \\<or> (firstUncommittedSlot nd \\<le> i \\<and> s = n\\<^sub>0 \\<and> dn = d\\<^sub>0 \\<and> t = currentTerm nd))\"\n    unfolding promised'_def promised_def Vote' by auto\n\n  have prevAccepted_eq: \"\\<And>i t q. prevAccepted' i t q = prevAccepted i t q \\<union> {t'. n\\<^sub>0 \\<in> q \\<and> i = firstUncommittedSlot nd \\<and> t = currentTerm nd \\<and> lastAcceptedTerm nd = SomeTerm t'}\"\n    unfolding prevAccepted_def prevAccepted'_def Vote' by auto\n\n  have property_simps[simp]:\n    \"\\<And>n. currentNode (nodeState' n) = currentNode (nodeState n)\"\n    \"\\<And>n. firstUncommittedSlot (nodeState' n) = firstUncommittedSlot (nodeState n)\"\n    \"\\<And>n. currentVotingNodes (nodeState' n) = currentVotingNodes (nodeState n)\"\n    \"\\<And>n q. isQuorum (nodeState' n) q = isQuorum (nodeState n) q\"\n    \"\\<And>n. lastAcceptedTerm (nodeState' n) = lastAcceptedTerm (nodeState n)\"\n    \"\\<And>n. lastAcceptedValue (nodeState' n) = lastAcceptedValue (nodeState n)\"\n    \"\\<And>n. currentTerm (nodeState' n) = currentTerm (nodeState n)\"\n    \"\\<And>n. publishPermitted (nodeState' n) = publishPermitted (nodeState n)\"\n    \"\\<And>n. publishVotes (nodeState' n) = publishVotes (nodeState n)\"\n    \"\\<And>n. currentClusterState (nodeState' n) = currentClusterState (nodeState n)\"\n    \"\\<And>n. electionWon (nodeState' n) = electionWon (nodeState n)\"\n    \"\\<And>n. joinVotes (nodeState' n) = joinVotes (nodeState n)\"\n    by (unfold nodeState'_def, auto simp add: nd_def isQuorum_def nd' addElectionVote_def Let_def)\n\n  show \"zen messages' nodeState'\"\n    apply (intro zenI)\n                        apply (unfold message_simps property_simps committedTo_eq V_eq lastCommittedClusterStateBefore_eq v_eq)\n  proof -\n    from finite_messages show \"finite messages'\" by (simp add: messages')\n    from currentNode_nodeState show \"\\<And>n. currentNode (nodeState n) = n\" .\n    from committedTo_firstUncommittedSlot show \"\\<And>n. committed\\<^sub>< (firstUncommittedSlot (nodeState n))\" .\n    from firstUncommittedSlot_PublishResponse show \"\\<And>n i t. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\" .\n    from lastAcceptedTerm_None show \"\\<And>n i t. lastAcceptedTerm (nodeState n) = NO_TERM \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_sent show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_max show \"\\<And>n t t'. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t' \\<rangle>\\<leadsto> \\<Longrightarrow> t' \\<le> t\".\n    from electionWon_isQuorum show \"\\<And>n. electionWon (nodeState n) \\<Longrightarrow> isQuorum (nodeState n) (joinVotes (nodeState n))\".\n    from publishVotes show \"\\<And>n n'. n' \\<in> publishVotes (nodeState n) \\<Longrightarrow> n' \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) \\<rangle>\\<leadsto>\".\n    from currentClusterState_lastCommittedClusterStateBefore show \"\\<And>n. currentClusterState (nodeState n) = lastCommittedClusterStateBefore (firstUncommittedSlot (nodeState n))\".\n    from PublishRequest_committedTo show \"\\<And>i t x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from PublishRequest_function show \"\\<And>i t x x'. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<langle> PublishRequest i t x' \\<rangle>\\<leadsto> \\<Longrightarrow> x = x'\".\n    from PublishResponse_PublishRequest show \"\\<And>i s t. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from ApplyCommit_quorum show \"\\<And>i t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). \\<forall>s\\<in>q. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\".\n    from currentVotingNodes_firstUncommittedSlot show \"\\<And>n. currentVotingNodes (nodeState n) = V (firstUncommittedSlot (nodeState n))\".\n    from firstUncommittedSlot_PublishRequest show \"\\<And>i n t x. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_value show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t (lastAcceptedValue (nodeState n)) \\<rangle>\\<leadsto>\".\n    from PublishRequest_currentTerm show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from PublishRequest_publishPermitted_currentTerm show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> publishPermitted (nodeState n) \\<Longrightarrow> t < currentTerm (nodeState n)\".\n    from CatchUpResponse_committedTo show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from CatchUpResponse_V show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> V i = conf\".\n    from CatchUpResponse_lastCommittedClusterStateBefore show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> lastCommittedClusterStateBefore i = cs\".\n    from lastAcceptedTerm_Some_currentTerm show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n\n    from Vote_currentTerm show \"\\<And>n i t a. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto>' \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\"\n      unfolding Vote' by (auto simp add: nd_def)\n\n    from joinVotes show \"\\<And>n n'. n' \\<in> joinVotes (nodeState n) \\<Longrightarrow> promised' (firstUncommittedSlot (nodeState n)) n' n (currentTerm (nodeState n))\"\n      unfolding promised_eq by simp\n\n    from Vote_future firstUncommittedSlot_PublishResponse\n    show \"\\<And>i i' s t t' a. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto>' \\<Longrightarrow> i < i' \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i' t' \\<rangle>\\<leadsto>\"\n      unfolding Vote' nd_def by auto\n\n    from Vote_None show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t NO_TERM \\<rangle>\\<leadsto>' \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\"\n      unfolding Vote' using Vote_future lastAcceptedTerm_None nd' nd'_def by auto\n\n    from Vote_Some_lt show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto>' \\<Longrightarrow> t' < t\"\n      unfolding Vote' using not_accepted lastAcceptedTerm_def\n      by (smt fst_conv TermOption.distinct(1) snd_conv)\n\n    from Vote_Some_PublishResponse show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto>' \\<Longrightarrow> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\"\n      unfolding Vote' using lastAcceptedTerm_Some_sent nd' nd'_def nd_def\n      by (smt Pair_inject TermOption.distinct(1))\n\n    from Vote_Some_max show \"\\<And>i s t t' t''. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto>' \\<Longrightarrow> t' < t'' \\<Longrightarrow> t'' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t'' \\<rangle>\\<leadsto>\"\n      unfolding Vote' nd_def\n      by (smt Pair_inject TermOption.distinct(1) \\<open>\\<And>t' t na. \\<lbrakk>lastAcceptedTerm (nodeState na) = SomeTerm t; na \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState na)) t' \\<rangle>\\<leadsto>\\<rbrakk> \\<Longrightarrow> t' \\<le> t\\<close> leD)\n\n    from Vote_not_broadcast show \"\\<And>i t a d. \\<langle> Vote i t a \\<rangle>\\<rightarrow>' d \\<Longrightarrow> d \\<noteq> Broadcast\"\n      unfolding Vote' by blast\n\n    from Vote_unique_destination show \"\\<And>i' i s t a a' d d'. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow>' d \\<Longrightarrow> s \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<rightarrow>' d' \\<Longrightarrow> d = d'\"\n      unfolding Vote'  using isMessageFrom_def not_sent by auto\n\n    from Vote_slot_function show \"\\<And>n i i' t a a'. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto>' \\<Longrightarrow> n \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<leadsto>' \\<Longrightarrow> i = i'\"\n      unfolding Vote'\n      by (metis Vote'(3) Message.inject(2) RoutedMessage.ext_inject insert_iff isMessageFrom'_def isMessageFromTo'_def isMessageFromTo_def isMessageFrom_def messages' not_sent)\n\n    from joinVotes_max show \"\\<And>n n' a'. \\<not> (\\<exists>x. \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) x \\<rangle>\\<leadsto>) \\<Longrightarrow> n' \\<in> joinVotes (nodeState n) \\<Longrightarrow> n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) a' \\<rangle>\\<rightarrow>' (OneNode n) \\<Longrightarrow> a' \\<le> lastAcceptedTerm (nodeState n)\"\n      unfolding Vote'\n      by (smt Vote'(1) Message.inject(2) RoutedMessage.ext_inject insert_iff isMessageFromTo'_def isMessageFrom_def joinVotes messages' not_sent promised_def zen.Vote_slot_function zenMessages.Vote_value_function zenMessages_axioms zen_axioms)\n\n    fix i s t x\n    assume \"s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\"\n    from PublishRequest_quorum [OF this]\n    obtain q where q_majority: \"q \\<in> majorities (V i)\" \n      and q_promised: \"\\<And>n. n \\<in> q \\<Longrightarrow> promised i n s t\"\n      and q_value: \"prevAccepted i t q = {} \\<or> (\\<exists>t'. v i t = v i t' \\<and> maxTerm (prevAccepted i t q) \\<le> t' \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto> \\<and> t' < t)\" by blast\n\n    from not_sent q_promised\n    have no_new_terms: \"{t'. n\\<^sub>0 \\<in> q \\<and> i = firstUncommittedSlot nd \\<and> t = currentTerm nd \\<and> lastAcceptedTerm nd = SomeTerm t'} = {}\"\n      unfolding isMessageFrom_def promised_def by blast\n    hence prevAccepted_eq: \"prevAccepted' i t q = prevAccepted i t q\"\n      unfolding prevAccepted_eq by auto\n\n    show \"\\<exists>q\\<in>majorities (V i). (\\<forall>n\\<in>q. promised' i n s t) \\<and> (prevAccepted' i t q = {} \\<or> (\\<exists>t'. v i t = v i t' \\<and> maxTerm (prevAccepted' i t q) \\<le> t' \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto> \\<and> t' < t))\"\n    proof (intro bexI conjI)\n      from q_majority show \"q \\<in> majorities (V i)\" .\n      from q_promised show \"\\<forall>n\\<in>q. promised' i n s t\" unfolding promised_eq by simp\n\n      from q_value show \"prevAccepted' i t q = {} \\<or> (\\<exists>t'. v i t = v i t' \\<and> maxTerm (prevAccepted' i t q) \\<le> t' \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto> \\<and> t' < t)\"\n        unfolding prevAccepted_eq by simp\n    qed\n  qed\nqed\n\nlemma (in zenStep) handleStartJoin_invariants:\n  fixes t\n  defines \"result \\<equiv> handleStartJoin t nd\"\n  assumes nd': \"nd' = fst result\"\n  assumes sent: \"s \\<midarrow>\\<langle> StartJoin t \\<rangle>\\<leadsto>\"\n  assumes messages': \"messages' = sendTo (OneNode s) result\"\n  shows \"zen messages' nodeState'\"\nproof (cases \"currentTerm nd < t\")\n  case False\n  hence result: \"result = (nd, None)\" by (simp add: result_def handleStartJoin_def)\n  have \"messages' = messages\" by (auto simp add: messages' result)\n  moreover\n  have \"nodeState' = nodeState\" by (intro ext, unfold nodeState'_def, simp add: nd' result nd_def)\n  moreover note zen_axioms\n  ultimately show ?thesis by simp\nnext\n  case True\n  hence new_term: \"currentTerm nd < t\" by simp\n\n  have result: \"result = (ensureCurrentTerm t nd, Some (Vote (firstUncommittedSlot nd) t (lastAcceptedTerm nd)))\"\n    by (simp add: result_def handleStartJoin_def True)\n\n  have nd': \"nd' = ensureCurrentTerm t nd\" by (simp add: nd' result)\n\n  have zen1: \"zen messages nodeState'\"\n  proof (intro zenStep.ensureCurrentTerm_invariants)\n    show \"messages = messages\" ..\n    from nd' show \"nodeState' n\\<^sub>0 = ensureCurrentTerm t (nodeState n\\<^sub>0)\" by (simp add: nd'_def nd_def)\n    show \"zenStep messages nodeState messages nodeState' n\\<^sub>0\"\n      by (intro_locales, intro zenStep_axioms.intro nodeState_unchanged, simp_all)\n  qed\n\n  with nodeState_unchanged messages_subset\n  have zenStep1: \"zenStep messages nodeState' messages' nodeState' n\\<^sub>0\"\n    by (intro_locales, simp add: zen_def, intro zenStep_axioms.intro, auto)\n\n  have nodeState': \"nodeState' = (\\<lambda> n. if n = n\\<^sub>0 then nd' else nodeState' n)\"\n    by (auto simp add: nodeState'_def)\n\n  have nd'_eq: \"nodeState' n\\<^sub>0 = nd'\"\n    by (simp add: nodeState'_def)\n\n  from True\n  have currentTerm_nd': \"currentTerm nd' = t\" by (auto simp add: nd')\n\n  have [simp]: \"firstUncommittedSlot nd' = firstUncommittedSlot nd\"\n    \"lastAcceptedTerm nd' = lastAcceptedTerm nd\"\n    by (auto simp add: nd' ensureCurrentTerm_def lastAcceptedTerm_def\n        lastAcceptedValue_def)\n\n  show \"zen messages' nodeState'\"\n  proof (intro zenStep.sendVote_invariants [OF zenStep1], unfold nd'_eq currentTerm_nd', simp_all add: messages' result)\n    show \"\\<And>i a. \\<forall>d. \\<lparr>sender = n\\<^sub>0, destination = d, payload = Vote i t a\\<rparr> \\<notin> messages\"\n      using nd_def new_term zen.Vote_currentTerm zen_axioms by fastforce\n    show \"\\<And>t'. lastAcceptedTerm nd = SomeTerm t' \\<Longrightarrow> t' < t\" using True lastAcceptedTerm_Some_currentTerm unfolding nd_def by fastforce\n  qed\nqed\n\nlemma (in zenStep) addElectionVote_invariants:\n  assumes nd': \"nd' = addElectionVote s i a nd\"\n  assumes messages': \"messages' = messages\"\n  assumes sent: \"s \\<midarrow>\\<langle> Vote i (currentTerm nd) a \\<rangle>\\<rightarrow> (OneNode n\\<^sub>0)\"\n  assumes precondition:\n    \"i < firstUncommittedSlot nd \\<or> (i = firstUncommittedSlot nd \\<and> a \\<le> lastAcceptedTerm nd)\"\n  shows \"zen messages' nodeState'\"\nproof -\n  from precondition have slot: \"i \\<le> firstUncommittedSlot nd\" by auto\n\n  have message_simps[simp]:\n    \"\\<And>s p d. (s \\<midarrow>\\<langle> p \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> p \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>p d. (\\<langle> p \\<rangle>\\<rightarrow>' d) = (\\<langle> p \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s p. (s \\<midarrow>\\<langle> p \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> p \\<rangle>\\<leadsto>)\"\n    \"\\<And>p. (\\<langle> p \\<rangle>\\<leadsto>') = (\\<langle> p \\<rangle>\\<leadsto>)\"\n    by (unfold isMessageFromTo'_def isMessageTo'_def isMessageFrom'_def isMessage'_def,\n        auto simp add: messages' isMessageFromTo_def isMessageTo_def isMessageFrom_def isMessage_def)\n\n  have property_simps[simp]:\n    \"\\<And>n. currentNode (nodeState' n) = currentNode (nodeState n)\"\n    \"\\<And>n. firstUncommittedSlot (nodeState' n) = firstUncommittedSlot (nodeState n)\"\n    \"\\<And>n. currentVotingNodes (nodeState' n) = currentVotingNodes (nodeState n)\"\n    \"\\<And>n q. isQuorum (nodeState' n) q = isQuorum (nodeState n) q\"\n    \"\\<And>n. lastAcceptedTerm (nodeState' n) = lastAcceptedTerm (nodeState n)\"\n    \"\\<And>n. lastAcceptedValue (nodeState' n) = lastAcceptedValue (nodeState n)\"\n    \"\\<And>n. currentTerm (nodeState' n) = currentTerm (nodeState n)\"\n    \"\\<And>n. publishPermitted (nodeState' n) = publishPermitted (nodeState n)\"\n    \"\\<And>n. publishVotes (nodeState' n) = publishVotes (nodeState n)\"\n    \"\\<And>n. currentClusterState (nodeState' n) = currentClusterState (nodeState n)\"\n    by (unfold nodeState'_def, auto simp add: nd_def isQuorum_def nd' addElectionVote_def Let_def\n        lastAcceptedValue_def lastAcceptedTerm_def)\n\n  have updated_properties:\n    \"\\<And>n. joinVotes (nodeState' n) = joinVotes (nodeState n) \\<union> (if n = n\\<^sub>0 then {s} else {})\"\n    \"\\<And>n. electionWon (nodeState' n) = (if n = n\\<^sub>0 then isQuorum nd (insert s (joinVotes nd)) else electionWon (nodeState n))\"\n    unfolding nodeState'_def by (auto simp add: nd' addElectionVote_def Let_def nd_def)\n\n  have v_eq[simp]: \"v' = v\" by (intro ext, auto simp add: v'_def v_def)\n  have v\\<^sub>c_eq[simp]: \"v\\<^sub>c' = v\\<^sub>c\" by (intro ext, auto simp add: v\\<^sub>c'_def v\\<^sub>c_def)\n  have isCommitted_eq[simp]: \"isCommitted' = isCommitted\" by (intro ext, auto simp add: isCommitted'_def isCommitted_def)\n  have committedTo_eq[simp]: \"committed\\<^sub><' = committed\\<^sub><\" by (intro ext, auto simp add: committedTo'_def committedTo_def)\n  have V_eq[simp]: \"V' = V\" using v\\<^sub>c_eq V'_def V_def by blast\n  have promised_eq[simp]: \"promised' = promised\" by (intro ext, auto simp add: promised'_def promised_def)\n  have prevAccepted_eq[simp]: \"prevAccepted' = prevAccepted\" by (intro ext, auto simp add: prevAccepted'_def prevAccepted_def)\n  have lastCommittedClusterStateBefore_eq[simp]: \"lastCommittedClusterStateBefore' = lastCommittedClusterStateBefore\"\n    unfolding lastCommittedClusterStateBefore_def lastCommittedClusterStateBefore'_def v\\<^sub>c_eq ..\n\n  show \"zen messages' nodeState'\"\n    apply (intro zenI)\n                        apply (unfold message_simps property_simps committedTo_eq v_eq V_eq promised_eq lastCommittedClusterStateBefore_eq prevAccepted_eq)\n  proof -\n    from finite_messages show \"finite messages'\" by (simp add: messages')\n    from Vote_future show \"\\<And>i i' s t t' a. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> i < i' \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i' t' \\<rangle>\\<leadsto>\".\n    from Vote_None show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t NO_TERM \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_lt show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t\".\n    from Vote_Some_PublishResponse show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_max show \"\\<And>i s t t' t''. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t'' \\<Longrightarrow> t'' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t'' \\<rangle>\\<leadsto>\".\n    from Vote_not_broadcast show \"\\<And>i t a d. \\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> d \\<noteq> Broadcast\".\n    from Vote_unique_destination show \"\\<And>i' i s t a a' d d'. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> s \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<rightarrow> d' \\<Longrightarrow> d = d'\".\n    from currentNode_nodeState show \"\\<And>n. currentNode (nodeState n) = n\" .\n    from committedTo_firstUncommittedSlot show \"\\<And>n. committed\\<^sub>< (firstUncommittedSlot (nodeState n))\" .\n    from firstUncommittedSlot_PublishResponse show \"\\<And>n i t. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\" .\n    from lastAcceptedTerm_None show \"\\<And>n i t. lastAcceptedTerm (nodeState n) = NO_TERM \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_sent show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_max show \"\\<And>n t t'. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t' \\<rangle>\\<leadsto> \\<Longrightarrow> t' \\<le> t\".\n    from Vote_currentTerm show \"\\<And>n i t a. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from Vote_slot_function show \"\\<And>n i i' t a a'. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> n \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<leadsto> \\<Longrightarrow> i = i'\".\n    from publishVotes show \"\\<And>n n'. n' \\<in> publishVotes (nodeState n) \\<Longrightarrow> n' \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) \\<rangle>\\<leadsto>\".\n    from currentClusterState_lastCommittedClusterStateBefore show \"\\<And>n. currentClusterState (nodeState n) = lastCommittedClusterStateBefore (firstUncommittedSlot (nodeState n))\".\n    from PublishRequest_committedTo show \"\\<And>i t x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from PublishRequest_function show \"\\<And>i t x x'. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<langle> PublishRequest i t x' \\<rangle>\\<leadsto> \\<Longrightarrow> x = x'\".\n    from PublishResponse_PublishRequest show \"\\<And>i s t. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from ApplyCommit_quorum show \"\\<And>i t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). \\<forall>s\\<in>q. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\".\n    from currentVotingNodes_firstUncommittedSlot show \"\\<And>n. currentVotingNodes (nodeState n) = V (firstUncommittedSlot (nodeState n))\".\n    from firstUncommittedSlot_PublishRequest show \"\\<And>i n t x. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_value show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t (lastAcceptedValue (nodeState n)) \\<rangle>\\<leadsto>\".\n    from PublishRequest_currentTerm show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from PublishRequest_publishPermitted_currentTerm show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> publishPermitted (nodeState n) \\<Longrightarrow> t < currentTerm (nodeState n)\".\n    from PublishRequest_quorum show \"\\<And>i s t x. s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). (\\<forall>n\\<in>q. promised i n s t) \\<and> (prevAccepted i t q = {} \\<or> (\\<exists>t'. v i t = v i t' \\<and> maxTerm (prevAccepted i t q) \\<le> t' \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto> \\<and> t' < t))\".\n    from CatchUpResponse_committedTo show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from CatchUpResponse_V show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> V i = conf\".\n    from CatchUpResponse_lastCommittedClusterStateBefore show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> lastCommittedClusterStateBefore i = cs\".\n    from lastAcceptedTerm_Some_currentTerm show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n\n    from electionWon_isQuorum show \"\\<And>n. electionWon (nodeState' n) \\<Longrightarrow> isQuorum (nodeState n) (joinVotes (nodeState' n))\"\n      unfolding updated_properties by (auto simp add: nd_def)\n\n    fix n\n\n    from joinVotes nd_def precondition sent\n    show \"\\<And>n'. n' \\<in> joinVotes (nodeState' n) \\<Longrightarrow> promised (firstUncommittedSlot (nodeState n)) n' n (currentTerm (nodeState n))\"\n      using precondition sent unfolding updated_properties nd_def apply (cases \"n = n\\<^sub>0\", simp_all)\n      using nd_def promised_def slot by blast\n\n    fix n' a'\n    assume fresh_request: \"\\<not> (\\<exists>x. \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) x \\<rangle>\\<leadsto>)\"\n      and n'_joinVotes: \"n' \\<in> joinVotes (nodeState' n)\"\n      and n'_vote: \"n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) a' \\<rangle>\\<rightarrow> (OneNode n)\"\n\n    show \"a' \\<le> lastAcceptedTerm (nodeState n)\"\n    proof (cases \"n = n\\<^sub>0\")\n      case False\n      with fresh_request n'_joinVotes n'_vote joinVotes_max\n      show ?thesis by (simp add: updated_properties)\n    next\n      case n_eq: True\n\n      show ?thesis\n      proof (cases \"n' = s\")\n        case n'_eq: True\n        have i: \"i = firstUncommittedSlot nd\"\n        proof (intro Vote_slot_function)\n          from n'_vote show \"n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot nd) (currentTerm nd) a' \\<rangle>\\<leadsto>\"\n            unfolding isMessageFrom_def nd_def n_eq by auto\n          from sent show \"n' \\<midarrow>\\<langle> Vote i (currentTerm nd) a \\<rangle>\\<leadsto>\"\n            unfolding isMessageFrom_def nd_def n'_eq by auto\n        qed\n\n        have a: \"a = a'\"\n        proof (intro Vote_value_function)\n          from n'_vote show \"n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot nd) (currentTerm nd) a' \\<rangle>\\<leadsto>\"\n            unfolding isMessageFrom_def nd_def n_eq by auto\n          from sent show \"n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot nd) (currentTerm nd) a \\<rangle>\\<leadsto>\"\n            unfolding isMessageFrom_def nd_def n'_eq i by auto\n        qed\n\n        from precondition show ?thesis by (auto simp add: i a n_eq nd_def)\n      next\n        case False with n'_joinVotes have n'_joinVotes: \"n' \\<in> joinVotes nd\" by (simp add: nd_def n_eq updated_properties)\n        with fresh_request n'_vote joinVotes_max show ?thesis unfolding nd_def n_eq by auto\n      qed\n    qed\n  qed\nqed\n\nlemma (in zenStep) publishValue_invariants:\n  fixes x\n  defines \"result \\<equiv> publishValue x nd\"\n  assumes nd': \"nd' = fst result\"\n  assumes messages': \"messages' = sendTo Broadcast result\"\n  assumes x: \"lastAcceptedTerm nd \\<noteq> NO_TERM \\<Longrightarrow> x = lastAcceptedValue nd\"\n  shows \"zen messages' nodeState'\"\nproof (cases \"electionWon nd \\<and> publishPermitted nd\")\n  case False\n  hence result: \"result = (nd, None)\" by (simp add: result_def publishValue_def)\n  have \"messages' = messages\" by (auto simp add: messages' result)\n  moreover\n  have \"nodeState' = nodeState\" by (intro ext, unfold nodeState'_def, simp add: nd' result nd_def)\n  moreover note zen_axioms\n  ultimately show ?thesis by simp\nnext\n  case won: True\n  hence result: \"result = (nd \\<lparr> publishPermitted := False \\<rparr>,\n                           Some (PublishRequest (firstUncommittedSlot nd) (currentTerm nd) x))\"\n    by (simp add: result_def publishValue_def)\n\n  have messages': \"messages' = insert \\<lparr>sender = n\\<^sub>0, destination = Broadcast, payload = PublishRequest (firstUncommittedSlot nd) (currentTerm nd) x\\<rparr> messages\"\n    by (simp add: messages' result)\n\n  have message_simps:\n    \"\\<And>s d i t a. (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s d i t. (s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s d i t. (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t a. (\\<langle> Vote i t a \\<rangle>\\<rightarrow>' d) = (\\<langle> Vote i t a \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t. (\\<langle> PublishResponse i t \\<rangle>\\<rightarrow>' d) = (\\<langle> PublishResponse i t \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t. (\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow>' d) = (\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s i t a. (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto>)\"\n    \"\\<And>s i t. (s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>)\"\n    \"\\<And>s i t. (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>)\"\n    \"\\<And>d i t a. (\\<langle> Vote i t a \\<rangle>\\<leadsto>') = (\\<langle> Vote i t a \\<rangle>\\<leadsto>)\"\n    \"\\<And>d i t. (\\<langle> PublishResponse i t \\<rangle>\\<leadsto>') = (\\<langle> PublishResponse i t \\<rangle>\\<leadsto>)\"\n    \"\\<And>d i t. (\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>') = (\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>)\"\n    \"\\<And>s d i conf cs. (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i conf cs. (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow>' d) = (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s i conf cs. (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>)\"\n    \"\\<And>d i conf cs. (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>') = (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>)\"\n    by (auto simp add: isMessageFromTo'_def isMessageTo'_def isMessage'_def isMessageFrom'_def,\n        auto simp add: isMessageFromTo_def isMessageTo_def isMessage_def isMessageFrom_def messages')\n\n  have PublishRequest': \"\\<And>s d i t x'. (s \\<midarrow>\\<langle> PublishRequest i t x' \\<rangle>\\<rightarrow>' d) = ((s \\<midarrow>\\<langle> PublishRequest i t x' \\<rangle>\\<rightarrow> d)\n          \\<or> (s, d, i, t, x') = (n\\<^sub>0, Broadcast, firstUncommittedSlot nd, currentTerm nd, x))\"\n    \"\\<And>s i t x'. (s \\<midarrow>\\<langle> PublishRequest i t x' \\<rangle>\\<leadsto>') = ((s \\<midarrow>\\<langle> PublishRequest i t x' \\<rangle>\\<leadsto>)\n          \\<or> (s, i, t, x') = (n\\<^sub>0, firstUncommittedSlot nd, currentTerm nd, x))\"\n    \"\\<And>d i t x'. (\\<langle> PublishRequest i t x' \\<rangle>\\<rightarrow>' d) = ((\\<langle> PublishRequest i t x' \\<rangle>\\<rightarrow> d)\n          \\<or> (d, i, t, x') = (Broadcast, firstUncommittedSlot nd, currentTerm nd, x))\"\n    \"\\<And>i t x'. (\\<langle> PublishRequest i t x' \\<rangle>\\<leadsto>') = ((\\<langle> PublishRequest i t x' \\<rangle>\\<leadsto>)\n          \\<or> (i, t, x') = (firstUncommittedSlot nd, currentTerm nd, x))\"\n    by (auto simp add: isMessageFromTo'_def isMessageFrom'_def isMessageTo'_def isMessage'_def,\n        auto simp add: messages' isMessageFromTo_def isMessageFrom_def isMessageTo_def isMessage_def)\n\n  have fresh_request: \"\\<And>x. \\<not> \\<langle> PublishRequest (firstUncommittedSlot nd) (currentTerm nd) x \\<rangle>\\<leadsto>\"\n  proof (intro notI)\n    fix x'\n    assume \"\\<langle> PublishRequest (firstUncommittedSlot nd) (currentTerm nd) x' \\<rangle>\\<leadsto>\"\n    with won obtain s d where\n      s: \"s \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot nd) (currentTerm nd) x' \\<rangle>\\<rightarrow> d\"\n      by (auto simp add: isMessage_def isMessageFrom_def)\n\n    with PublishRequest_quorum [where s = s and i = \"firstUncommittedSlot nd\" and t = \"currentTerm nd\" and x = x']\n    obtain q where q: \"q \\<in> majorities (V (firstUncommittedSlot nd))\" and promised: \"\\<And>n. n \\<in> q \\<Longrightarrow> promised (firstUncommittedSlot nd) n s (currentTerm nd)\"\n      by (auto simp add: isMessageFrom_def, blast)\n\n    from won have \"isQuorum nd (joinVotes nd)\"\n      by (unfold nd_def, intro electionWon_isQuorum, simp)\n    with currentVotingNodes_firstUncommittedSlot [of n\\<^sub>0]\n    have \"joinVotes nd \\<in> majorities (V (firstUncommittedSlot nd))\" using nd_def isQuorum_def by auto\n\n    from q this V_intersects have \"q \\<inter> joinVotes nd \\<noteq> {}\"\n      by (auto simp add: intersects_def)\n    then obtain n where n: \"n \\<in> q\" \"n \\<in> joinVotes nd\" by auto\n\n    from promised [OF `n \\<in> q`]\n    obtain i' a' where \"n \\<midarrow>\\<langle> Vote i' (currentTerm nd) a' \\<rangle>\\<rightarrow> (OneNode s)\"\n      by (auto simp add: promised_def)\n\n    moreover from joinVotes n\n    obtain i'' a'' where \"n \\<midarrow>\\<langle> Vote i'' (currentTerm nd) a'' \\<rangle>\\<rightarrow> (OneNode n\\<^sub>0)\"\n      by (auto simp add: nd_def promised_def, blast)\n\n    ultimately have \"OneNode s = OneNode n\\<^sub>0\"\n      by (intro Vote_unique_destination)\n\n    with s have \"n\\<^sub>0 \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot nd) (currentTerm nd) x' \\<rangle>\\<leadsto>\"\n      by (auto simp add: isMessageFrom_def)\n\n    hence \"currentTerm nd < currentTerm (nodeState n\\<^sub>0)\"\n    proof (intro PublishRequest_publishPermitted_currentTerm, fold nd_def)\n      from won show \"publishPermitted nd\" by (simp add: nd_def)\n    qed\n    thus False by (simp add: nd_def)\n  qed\n\n  have v_eq: \"\\<And>i t x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> v' i t = v i t\"\n  proof -\n    fix i t x'\n\n    assume \"\\<langle> PublishRequest i t x' \\<rangle>\\<leadsto>\"\n    with fresh_request have ne: \"(i, t) \\<noteq> (firstUncommittedSlot nd, currentTerm nd)\" by auto\n\n    have sent_eq: \"\\<And>x''. \\<langle> PublishRequest i t x'' \\<rangle>\\<leadsto>' = \\<langle> PublishRequest i t x'' \\<rangle>\\<leadsto>\"\n    proof (intro iffI)\n      fix x''\n      show \"\\<langle> PublishRequest i t x'' \\<rangle>\\<leadsto> \\<Longrightarrow> \\<langle> PublishRequest i t x'' \\<rangle>\\<leadsto>'\" by (simp add: PublishRequest')\n      assume \"\\<langle> PublishRequest i t x'' \\<rangle>\\<leadsto>'\" with ne show \"\\<langle> PublishRequest i t x'' \\<rangle>\\<leadsto>\"\n        by (unfold PublishRequest', auto)\n    qed\n\n    show \"v' i t = v i t\"\n      by (unfold v'_def v_def sent_eq, simp)\n  qed\n\n  have isCommitted_eq: \"isCommitted' = isCommitted\"\n    by (intro ext, simp add: isCommitted_def isCommitted'_def message_simps)\n\n  have committedTo_eq: \"committed\\<^sub><' = committed\\<^sub><\"\n    by (intro ext, simp add: committedTo_def committedTo'_def isCommitted_eq)\n\n  have v\\<^sub>c_eq: \"\\<And>i. isCommitted i \\<Longrightarrow> v\\<^sub>c' i = v\\<^sub>c i\"\n  proof -\n    fix i assume i: \"isCommitted i\"\n    define t where \"t \\<equiv> SOME t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto>\"\n    have t: \"\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>\"\n    proof -\n      from i obtain t where t: \"\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>\" by (auto simp add: isCommitted_def)\n      thus ?thesis by (unfold t_def, intro someI)\n    qed\n    hence v_eq: \"v' i t = v i t\" by (intro v_eq [OF ApplyCommit_PublishRequest])\n\n    have \"v\\<^sub>c' i = v' i t\" by (simp add: v\\<^sub>c'_def t_def message_simps)\n    also note v_eq\n    also have \"v i t = v\\<^sub>c i\" by (simp add: v\\<^sub>c_def t_def)\n    finally show \"?thesis i\" by simp\n  qed\n\n  have V_eq: \"\\<And>i. committed\\<^sub>< i \\<Longrightarrow> V' i = V i\"\n  proof -\n    fix i assume i: \"committed\\<^sub>< i\"\n    thus \"?thesis i\"\n    proof (induct i)\n      case (Suc i')\n      hence prems: \"committed\\<^sub>< i'\" \"isCommitted i'\" unfolding committedTo_def by auto\n      thus ?case using Suc v\\<^sub>c_eq by simp\n    qed simp\n  qed\n\n  have lastCommittedClusterStateBefore_eq: \"\\<And>i. committed\\<^sub>< i \\<Longrightarrow> lastCommittedClusterStateBefore' i = lastCommittedClusterStateBefore i\"\n  proof -\n    fix i assume \"committed\\<^sub>< i\"\n    thus \"?thesis i\"\n    proof (induct i)\n      case (Suc i')\n      hence prems: \"committed\\<^sub>< i'\" \"isCommitted i'\" unfolding committedTo_def by auto\n      thus ?case using Suc v\\<^sub>c_eq by (cases \"v\\<^sub>c i'\", simp_all)\n    qed simp\n  qed\n\n  have promised_eq: \"\\<And>i n n' t. promised' i n n' t = promised i n n' t\"\n    by (simp add: promised_def promised'_def message_simps)\n\n  have prevAccepted_eq: \"\\<And>i t q. prevAccepted' i t q  = prevAccepted i t q\"\n    by (simp add: prevAccepted_def prevAccepted'_def message_simps)\n\n  from committedTo_firstUncommittedSlot V_eq\n  have V_slot_eq: \"\\<And>n. V' (firstUncommittedSlot (nodeState n)) = V (firstUncommittedSlot (nodeState n))\" by blast\n\n  have lastCommittedClusterStateBefore_slot_eq: \"\\<And>n. lastCommittedClusterStateBefore' (firstUncommittedSlot (nodeState n)) = lastCommittedClusterStateBefore (firstUncommittedSlot (nodeState n))\"\n    by (intro lastCommittedClusterStateBefore_eq committedTo_firstUncommittedSlot)\n\n  have v_prevAccepted_eq: \"\\<And>i t q. prevAccepted i t q \\<noteq> {} \\<Longrightarrow> v' i (maxTerm (prevAccepted i t q)) = v i (maxTerm (prevAccepted i t q))\"\n  proof -\n    fix i t q\n    assume nonempty: \"prevAccepted i t q \\<noteq> {}\"\n    have \"maxTerm (prevAccepted i t q) \\<in> prevAccepted i t q\"\n      by (intro maxTerm_mem finite_prevAccepted nonempty)\n    hence \"\\<langle> Vote i t (SomeTerm (maxTerm (prevAccepted i t q))) \\<rangle>\\<leadsto>\"\n      by (auto simp add: prevAccepted_def isMessage_def)\n    hence \"\\<langle> PublishResponse i (maxTerm (prevAccepted i t q)) \\<rangle>\\<leadsto>\"\n      using Vote_Some_PublishResponse unfolding isMessage_def by blast\n    then obtain x' where \"\\<langle> PublishRequest i (maxTerm (prevAccepted i t q)) x' \\<rangle>\\<leadsto>\"\n      using PublishResponse_PublishRequest unfolding isMessage_def by blast\n    thus \"?thesis i t q\" by (intro v_eq)\n  qed\n\n  have nd': \"nd' = nd \\<lparr> publishPermitted := False \\<rparr>\" by (simp add: nd' result)\n\n  have property_simps[simp]:\n    \"\\<And>n. currentNode (nodeState' n) = currentNode (nodeState n)\"\n    \"\\<And>n. firstUncommittedSlot (nodeState' n) = firstUncommittedSlot (nodeState n)\"\n    \"\\<And>n. currentVotingNodes (nodeState' n) = currentVotingNodes (nodeState n)\"\n    \"\\<And>n q. isQuorum (nodeState' n) q = isQuorum (nodeState n) q\"\n    \"\\<And>n. lastAcceptedValue (nodeState' n) = lastAcceptedValue (nodeState n)\"\n    \"\\<And>n. lastAcceptedTerm (nodeState' n) = lastAcceptedTerm (nodeState n)\"\n    \"\\<And>n. currentTerm (nodeState' n) = currentTerm (nodeState n)\"\n    \"\\<And>n. publishVotes (nodeState' n) = publishVotes (nodeState n)\"\n    \"\\<And>n. currentClusterState (nodeState' n) = currentClusterState (nodeState n)\"\n    \"\\<And>n. electionWon (nodeState' n) = electionWon (nodeState n)\"\n    \"\\<And>n. joinVotes (nodeState' n) = joinVotes (nodeState n)\"\n    by (unfold nodeState'_def, auto simp add: nd_def isQuorum_def nd' addElectionVote_def Let_def\n        lastAcceptedTerm_def lastAcceptedValue_def)\n\n  show ?thesis\n    apply (intro zenI)\n                        apply (unfold message_simps committedTo_eq V_slot_eq\n        lastCommittedClusterStateBefore_slot_eq property_simps promised_eq prevAccepted_eq)\n  proof -\n    from Vote_future show \"\\<And>i i' s t t' a. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> i < i' \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i' t' \\<rangle>\\<leadsto>\".\n    from Vote_None show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t NO_TERM \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_lt show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t\".\n    from Vote_Some_PublishResponse show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_max show \"\\<And>i s t t' t''. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t'' \\<Longrightarrow> t'' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t'' \\<rangle>\\<leadsto>\".\n    from Vote_not_broadcast show \"\\<And>i t a d. \\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> d \\<noteq> Broadcast\".\n    from Vote_unique_destination show \"\\<And>i' i s t a a' d d'. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> s \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<rightarrow> d' \\<Longrightarrow> d = d'\".\n    from currentNode_nodeState show \"\\<And>n. currentNode (nodeState n) = n\" .\n    from committedTo_firstUncommittedSlot show \"\\<And>n. committed\\<^sub>< (firstUncommittedSlot (nodeState n))\" .\n    from firstUncommittedSlot_PublishResponse show \"\\<And>n i t. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\" .\n    from lastAcceptedTerm_None show \"\\<And>n i t. lastAcceptedTerm (nodeState n) = NO_TERM \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_sent show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_max show \"\\<And>n t t'. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t' \\<rangle>\\<leadsto> \\<Longrightarrow> t' \\<le> t\".\n    from Vote_currentTerm show \"\\<And>n i t a. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from Vote_slot_function show \"\\<And>n i i' t a a'. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> n \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<leadsto> \\<Longrightarrow> i = i'\".\n    from electionWon_isQuorum show \"\\<And>n. electionWon (nodeState n) \\<Longrightarrow> isQuorum (nodeState n) (joinVotes (nodeState n))\".\n    from publishVotes show \"\\<And>n n'. n' \\<in> publishVotes (nodeState n) \\<Longrightarrow> n' \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) \\<rangle>\\<leadsto>\".\n    from currentClusterState_lastCommittedClusterStateBefore show \"\\<And>n. currentClusterState (nodeState n) = lastCommittedClusterStateBefore (firstUncommittedSlot (nodeState n))\".\n    from joinVotes show \"\\<And>n n'. n' \\<in> joinVotes (nodeState n) \\<Longrightarrow> promised (firstUncommittedSlot (nodeState n)) n' n (currentTerm (nodeState n))\".\n    from currentVotingNodes_firstUncommittedSlot show \"\\<And>n. currentVotingNodes (nodeState n) = V (firstUncommittedSlot (nodeState n))\".\n    from lastAcceptedTerm_Some_currentTerm show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n\n    {\n      fix i conf cs assume a: \"\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>\"\n      with CatchUpResponse_committedTo show \"committed\\<^sub>< i\" .\n      with a V_eq lastCommittedClusterStateBefore_eq CatchUpResponse_V CatchUpResponse_lastCommittedClusterStateBefore\n      show \"V' i = conf\" \"lastCommittedClusterStateBefore' i = cs\" by auto\n    }\n\n    from lastAcceptedTerm_Some_value  PublishRequest'\n    show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t (lastAcceptedValue (nodeState n)) \\<rangle>\\<leadsto>'\"\n      by (meson isMessage'_def isMessageFrom'_def isMessageFrom_def isMessage_def)\n\n    from PublishRequest_currentTerm\n    show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto>' \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\"\n      using PublishRequest' isMessageFrom'_def isMessageFrom_def nd_def by fastforce\n\n    from fresh_request PublishRequest_function\n    show \"\\<And>i t x x'. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>' \\<Longrightarrow> \\<langle> PublishRequest i t x' \\<rangle>\\<leadsto>' \\<Longrightarrow> x = x'\"\n      unfolding PublishRequest' by auto\n\n    from messages' finite_messages show \"finite messages'\" by simp\n\n    from PublishResponse_PublishRequest show \"\\<And>i s t. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>'\"\n      unfolding PublishRequest' by blast\n\n    from ApplyCommit_quorum V_eq isCommitted_committedTo\n    show \"\\<And>i t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V' i). \\<forall>s\\<in>q. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\"\n      unfolding isCommitted_def by fastforce\n\n    fix n\n\n    from firstUncommittedSlot_PublishRequest\n    show \"\\<And>i t x. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>'\"\n      by (cases \"n = n\\<^sub>0\", unfold nodeState'_def PublishRequest' isMessageFrom'_def isMessageFrom_def, auto simp add: nd' nd_def)\n\n    from PublishRequest_publishPermitted_currentTerm\n    show \"\\<And>t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto>' \\<Longrightarrow> publishPermitted (nodeState' n) \\<Longrightarrow> t < currentTerm (nodeState n)\"\n      unfolding isMessageFrom'_def PublishRequest'\n      by (cases \"n = n\\<^sub>0\", auto simp add: nodeState'_def nd' isMessageFrom_def)\n\n    show PublishRequest_committedTo': \"\\<And>i t x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>' \\<Longrightarrow> committed\\<^sub>< i\"\n      using PublishRequest_committedTo committedTo_firstUncommittedSlot\n      by (auto simp add: committedTo_def PublishRequest' nd_def)\n\n    from joinVotes_max\n    show \"\\<And>n' a'. \\<not> (\\<exists>x. \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) x \\<rangle>\\<leadsto>') \\<Longrightarrow> n' \\<in> joinVotes (nodeState n) \\<Longrightarrow> n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) a' \\<rangle>\\<rightarrow> (OneNode n) \\<Longrightarrow> a' \\<le> lastAcceptedTerm (nodeState n)\"\n      by (cases \"n = n\\<^sub>0\", auto simp add: nodeState'_def nd' PublishRequest')\n\n    {\n      fix i s t x'\n      assume \"s \\<midarrow>\\<langle> PublishRequest i t x' \\<rangle>\\<leadsto>'\"\n      thus \"\\<exists>q\\<in>majorities (V' i). (\\<forall>n\\<in>q. promised i n s t) \\<and> (prevAccepted i t q = {} \\<or> (\\<exists>t'. v' i t = v' i t' \\<and> maxTerm (prevAccepted i t q) \\<le> t' \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto> \\<and> t' < t))\"\n        unfolding PublishRequest'\n      proof (elim disjE)\n        assume sent: \"s \\<midarrow>\\<langle> PublishRequest i t x' \\<rangle>\\<leadsto>\"\n        from sent have [simp]: \"V' i = V i\" by (intro V_eq PublishRequest_committedTo, auto simp add: isMessage_def)\n        from sent have [simp]: \"v' i t = v i t\" by (intro v_eq, auto simp add: isMessage_def)\n\n        from PublishRequest_quorum [OF sent]\n        obtain q where q_quorum: \"q \\<in> majorities (V i)\"\n          and q_promised: \"\\<And>n. n \\<in> q \\<Longrightarrow> promised i n s t\"\n          and q_value: \"prevAccepted i t q = {} \\<or> (\\<exists>t'. v i t = v i t' \\<and> maxTerm (prevAccepted i t q) \\<le> t' \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto> \\<and> t' < t)\"\n          by blast\n\n        show ?thesis\n        proof (cases \"prevAccepted i t q = {}\")\n          case True with q_quorum q_promised show ?thesis by auto\n        next\n          case False\n          with q_value obtain t' where t': \"v i t = v i t'\" \"maxTerm (prevAccepted i t q) \\<le> t'\" \"\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\" \"t' < t\" by blast\n\n          show ?thesis\n          proof (intro bexI conjI disjI2 exI ballI)\n            from q_promised show \"\\<And>n. n \\<in> q \\<Longrightarrow> promised i n s t\" .\n            from t' show \"maxTerm (prevAccepted i t q) \\<le> t'\" \"\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\" \"t' < t\" by simp_all\n            from q_quorum show \"q \\<in> majorities (V' i)\" by simp\n\n            have \"v' i t = v i t\" by simp\n            also have \"... = v i t'\" using t' by simp\n            also have \"... = v' i t'\" unfolding v_def v'_def PublishRequest' using t'\n              by (metis PublishResponse_PublishRequest_v fresh_request fst_conv snd_conv)\n            finally show \"v' i t = v' i t'\" .\n          qed\n        qed\n      next\n        assume \"(s, i, t, x') = (n\\<^sub>0, firstUncommittedSlot nd, currentTerm nd, x)\"\n        hence [simp]: \"s = n\\<^sub>0\" \"i = firstUncommittedSlot nd\" \"t = currentTerm nd\" \"x' = x\" by simp_all\n\n        have Vi: \"V' i = V i\"\n          using committedTo_firstUncommittedSlot by (intro V_eq, simp add: nd_def)\n        define q where \"q \\<equiv> joinVotes nd\"\n\n        show ?thesis\n        proof (intro bexI conjI ballI)\n          from won have \"isQuorum nd q\" unfolding nd_def q_def by (intro electionWon_isQuorum, simp)\n          with currentVotingNodes_firstUncommittedSlot Vi show \"q \\<in> majorities (V' i)\" by (auto simp add: nd_def isQuorum_def)\n          fix n assume \"n \\<in> q\"\n          with joinVotes show \"promised i n s t\" by (simp add: nd_def q_def)\n        next\n          show \"prevAccepted i t q = {} \\<or> (\\<exists>t'. v' i t = v' i t' \\<and> maxTerm (prevAccepted i t q) \\<le> t' \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto> \\<and> t' < t)\"\n          proof (cases \"prevAccepted i t q = {}\")\n            case True thus ?thesis by simp\n          next\n            case False\n            then obtain t' n' where n'_vote: \"n' \\<in> q\" and n'_sent: \"n' \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto>\"\n              unfolding prevAccepted_def by auto\n\n            from n'_sent n'_vote\n            have n'_sent: \"n' \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<rightarrow> (OneNode n\\<^sub>0)\" unfolding isMessageFrom_def q_def nd_def\n              using \\<open>t = currentTerm nd\\<close> isMessageFromTo_def nd_def zen.joinVotes zenMessages.Vote_unique_destination zenMessages_axioms zen_axioms by blast\n\n            have t'_latis: \"SomeTerm t' \\<le> lastAcceptedTerm nd\"\n              unfolding nd_def\n            proof (intro joinVotes_max)\n              from fresh_request\n              show \"\\<not> (\\<exists>x. \\<langle> PublishRequest (firstUncommittedSlot (nodeState n\\<^sub>0)) (currentTerm (nodeState n\\<^sub>0)) x \\<rangle>\\<leadsto>)\"\n                unfolding nd_def by auto\n\n              from n'_vote show \"n' \\<in> joinVotes (nodeState n\\<^sub>0)\" by (simp add: q_def nd_def)\n\n              from n'_sent\n              show \"n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot (nodeState n\\<^sub>0)) (currentTerm (nodeState n\\<^sub>0)) (SomeTerm t') \\<rangle>\\<rightarrow> (OneNode n\\<^sub>0)\"\n                by (simp add: nd_def)\n            qed\n\n            then obtain t'' where t'': \"lastAcceptedTerm nd = SomeTerm t''\"\n              by (cases \"lastAcceptedTerm nd\", auto)\n\n            show ?thesis\n            proof (intro disjI2 exI conjI)\n              from t''\n              have slots: \"firstUncommittedSlot nd = firstUncommittedSlot nd\"\n                by (cases \"firstUncommittedSlot nd = firstUncommittedSlot nd\", simp_all add: lastAcceptedTerm_def)\n              \n              from t'' have lat: \"lastAcceptedTerm nd = SomeTerm t''\"\n                by (cases \"firstUncommittedSlot nd = firstUncommittedSlot nd\", simp_all add: lastAcceptedTerm_def)\n              \n              from lastAcceptedTerm_Some_sent lat slots\n              show accepted: \"\\<langle> PublishResponse i t'' \\<rangle>\\<leadsto>\" by (auto simp add: nd_def isMessage_def)\n              \n              from fresh_request\n              have \"\\<And>x'. \\<langle> PublishRequest i t x' \\<rangle>\\<leadsto>' \\<Longrightarrow> x' = x\" unfolding PublishRequest' by simp\n              hence \"v' i t = x\" unfolding v'_def using \\<open>s \\<midarrow>\\<langle> PublishRequest i t x' \\<rangle>\\<leadsto>'\\<close> isMessage'_def by blast\n              \n              also from x have \"x = lastAcceptedValue nd\" by (simp add: t'')\n              \n              also have \"... = v i t''\"\n              proof (intro PublishRequest_function)\n                from accepted PublishResponse_PublishRequest_v show \"\\<langle> PublishRequest i t'' (v i t'') \\<rangle>\\<leadsto>\" by simp\n              \n                from lat lastAcceptedTerm_Some_value slots\n                show \"\\<langle> PublishRequest i t'' (lastAcceptedValue nd) \\<rangle>\\<leadsto>\"\n                  by (simp add: nd_def)\n              qed\n              \n              also have \"... = v' i t''\"\n              proof (intro sym [OF v_eq])\n                from accepted PublishResponse_PublishRequest_v show \"\\<langle> PublishRequest i t'' (v i t'') \\<rangle>\\<leadsto>\" by simp\n              qed\n              \n              finally show \"v' i t = v' i t''\" .\n              \n              show \"maxTerm (prevAccepted i t q) \\<le> t''\"\n              proof (intro maxTerm_le False finite_prevAccepted)\n                fix t''' assume \"t''' \\<in> prevAccepted i t q\"\n                thus \"t''' \\<le> t''\" unfolding prevAccepted_def apply auto\n                  by (metis \\<open>\\<And>t s i' ia d' d a' a. \\<lbrakk>s \\<midarrow>\\<langle> Vote ia t a \\<rangle>\\<rightarrow> d; s \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<rightarrow> d'\\<rbrakk> \\<Longrightarrow> d = d'\\<close> fresh_request isMessageFrom_def joinVotes joinVotes_max le_SomeTerm nd_def promised_def q_def t'')\n              qed\n              \n              have \"t'' \\<le> t\" using \\<open>t = currentTerm nd\\<close> lastAcceptedTerm_Some_currentTerm lat nd_def by blast\n              moreover have \"t'' \\<noteq> t\" apply (intro notI) using accepted fresh_request\n                using lastAcceptedTerm_Some_value lat nd_def slots by auto\n              ultimately show \"t'' < t\" by simp\n            qed\n          qed\n        qed\n      qed\n    }\n  qed\nqed\n\nlemma (in zenStep) handleVote_invariants:\n  fixes s i t a\n  defines \"result \\<equiv> handleVote s i t a nd\"\n  assumes nd': \"nd' = fst result\"\n  assumes messages': \"messages' = sendTo Broadcast result\"\n  assumes sent: \"s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> (OneNode n\\<^sub>0)\"\n  shows \"zen messages' nodeState'\"\nproof (cases \"t = currentTerm nd\n             \\<and> (i < firstUncommittedSlot nd\n                \\<or> (i = firstUncommittedSlot nd\n                    \\<and> (a \\<le> lastAcceptedTerm nd)))\")\n  case False\n  have [simp]: \"result = (nd, None)\" unfolding result_def handleVote_def by (simp add: False Let_def)\n  have [simp]: \"messages' = messages\" by (simp add: messages')\n  have [simp]: \"nodeState' = nodeState\" unfolding nodeState'_def by (intro ext, simp add: nd' nd_def)\n  from zen_axioms show ?thesis by simp\nnext\n  case True\n  hence True': \"i \\<le> firstUncommittedSlot nd\"\n    \"t = currentTerm nd\"\n    \"i < firstUncommittedSlot nd \\<or> (i = firstUncommittedSlot nd \\<and> a \\<le> lastAcceptedTerm nd)\"\n    by auto\n\n  define nd1 where \"nd1 \\<equiv> addElectionVote s i a nd\"\n  define nodeState1 where \"\\<And>n. nodeState1 n \\<equiv> if n = n\\<^sub>0 then nd1 else nodeState n\"\n\n  have zenStep1: \"zenStep messages nodeState messages nodeState1 n\\<^sub>0\"\n    by (intro zenStepI2, auto simp add: nodeState1_def)\n\n  have zenStep2: \"zenStep messages nodeState1 messages' nodeState' n\\<^sub>0\"\n  proof (intro zenStep.zenStepI1 [OF zenStep1] zenStep.addElectionVote_invariants [OF zenStep1] refl messages_subset,\n      fold nd_def isMessageFromTo_def)\n    show \"nodeState1 n\\<^sub>0 = addElectionVote s i a nd\" by (simp add: nodeState1_def nd1_def)\n    from True' sent show \"s \\<midarrow>\\<langle> Vote i (currentTerm nd) a \\<rangle>\\<rightarrow> (OneNode n\\<^sub>0)\" by simp\n    from True' show \"i < firstUncommittedSlot nd \\<or> (i = firstUncommittedSlot nd \\<and> a \\<le> lastAcceptedTerm nd)\" by simp\n    show \"\\<And>n. n \\<noteq> n\\<^sub>0 \\<Longrightarrow> nodeState1 n = nodeState' n\" unfolding nodeState1_def nodeState'_def by simp\n  qed\n\n  note zenStep.publishValue_invariants\n  have latis_eq: \"lastAcceptedTerm nd1 = lastAcceptedTerm nd\"\n    by (simp add: nd1_def addElectionVote_def Let_def)\n\n  show ?thesis\n  proof (cases \"lastAcceptedTerm nd1\")\n    case (SomeTerm t')\n    with True' latis_eq\n    have handleVote_eq: \"handleVote s i t a nd = publishValue (lastAcceptedValue nd1) nd1\"\n      unfolding handleVote_def nd1_def by (simp add: addElectionVote_def Let_def)\n\n    show ?thesis\n    proof (intro zenStep.publishValue_invariants [OF zenStep2])\n      show \"nodeState' n\\<^sub>0 = fst (publishValue (lastAcceptedValue nd1) (nodeState1 n\\<^sub>0))\"\n        by (simp add: nodeState1_def nd1_def nodeState'_def nd' result_def handleVote_eq)\n\n      show \"messages' = (case snd (publishValue (lastAcceptedValue nd1) (nodeState1 n\\<^sub>0)) of None \\<Rightarrow> messages | Some m \\<Rightarrow> insert \\<lparr>sender = n\\<^sub>0, destination = Broadcast, payload = m\\<rparr> messages)\"\n        by (cases \"publishValue (lastAcceptedValue nd1) nd1\", cases \"snd (publishValue (lastAcceptedValue nd1) nd1)\",\n            simp_all add: nodeState1_def messages' result_def handleVote_eq)\n\n      show \"lastAcceptedValue nd1 = lastAcceptedValue (nodeState1 n\\<^sub>0)\" by (simp add: nodeState1_def)\n    qed\n\n  next\n    case NO_TERM\n    with True' latis_eq\n    have handleVote_eq: \"handleVote s i t a nd = (nd1, None)\" unfolding handleVote_def nd1_def by simp\n    have [simp]: \"messages' = messages\" by (simp add: messages' result_def handleVote_eq)\n    have [simp]: \"nodeState' = nodeState1\" by (intro ext, simp add: nodeState'_def nodeState1_def nd' result_def handleVote_eq)\n    from zenStep2 show ?thesis by (simp add: zenStep_def)\n  qed\nqed\n\nlemma (in zenStep) handleClientValue_invariants:\n  fixes x\n  defines \"result \\<equiv> handleClientValue x nd\"\n  assumes nd': \"nd' = fst result\"\n  assumes messages': \"messages' = sendTo Broadcast result\"\n  shows \"zen messages' nodeState'\"\nproof (cases \"lastAcceptedTerm nd\")\n  case (SomeTerm t')\n  hence \"handleClientValue x nd = (nd, None)\" by (auto simp add: handleClientValue_def)\n  hence [simp]: \"result = (nd, None)\" by (simp add: result_def)\n  have [simp]: \"messages' = messages\" by (simp add: messages')\n  have [simp]: \"nodeState' = nodeState\" unfolding nodeState'_def by (intro ext, simp add: nd' nd_def)\n  from zen_axioms show ?thesis by simp\nnext\n  case NO_TERM\n  hence handleClientValue_eq[simp]: \"handleClientValue x nd = publishValue x nd\"\n    by (auto simp add: handleClientValue_def)\n\n  have result: \"result = publishValue x nd\"\n    unfolding result_def by simp\n\n  show ?thesis\n  proof (intro publishValue_invariants)\n    show \"nd' = fst (publishValue x nd)\" by (simp add: result nd')\n    show \"messages' = sendTo Broadcast (publishValue x nd)\" by (simp_all add: messages' result)\n    from NO_TERM show \"lastAcceptedTerm nd \\<noteq> NO_TERM \\<Longrightarrow> x = lastAcceptedValue nd\"\n      by simp\n  qed\nqed\n\nlemma (in zenStep) handlePublishRequest_invariants:\n  fixes i t x\n  defines \"result \\<equiv> handlePublishRequest i t x nd\"\n  assumes nd': \"nd' = fst result\"\n  assumes messages': \"messages' = sendTo (OneNode s) result\"\n  assumes sent: \"s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\"\n  shows \"zen messages' nodeState'\"\nproof (cases \"i = firstUncommittedSlot nd \\<and> t = currentTerm nd\")\n  case False\n  hence [simp]: \"result = (nd, None)\"\n    by (simp add: result_def handlePublishRequest_def)\n\n  have [simp]: \"messages' = messages\"\n    by (simp add: messages')\n\n  have [simp]: \"nodeState' = nodeState\"\n    unfolding nodeState'_def\n    by (intro ext, simp add: nd' nd_def)\n\n  from zen_axioms show ?thesis by simp\n\nnext\n  case precondition: True\n\n  hence result: \"result = (nd\\<lparr>lastAcceptedData := Some \\<lparr> tvTerm = t, tvValue = x\\<rparr> \\<rparr>,\n      Some (PublishResponse i t))\"\n    by (auto simp add: result_def handlePublishRequest_def)\n\n  have messages': \"messages' = insert \\<lparr> sender = n\\<^sub>0, destination = OneNode s, payload = PublishResponse i t \\<rparr> messages\"\n    by (simp add: messages' result)\n\n  have message_simps[simp]:\n    \"\\<And>s d i t. (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s d i t x. (s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s d i t a. (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t. (\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow>' d) = (\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t x. (\\<langle> PublishRequest i t x \\<rangle>\\<rightarrow>' d) = (\\<langle> PublishRequest i t x \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t a. (\\<langle> Vote i t a \\<rangle>\\<rightarrow>' d) = (\\<langle> Vote i t a \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s i t. (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>)\"\n    \"\\<And>s i t x. (s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>)\"\n    \"\\<And>s i t a. (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto>)\"\n    \"\\<And>i t. (\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>') = (\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>)\"\n    \"\\<And>i t x. (\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>') = (\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>)\"\n    \"\\<And>i t a. (\\<langle> Vote i t a \\<rangle>\\<leadsto>') = (\\<langle> Vote i t a \\<rangle>\\<leadsto>)\"\n    \"\\<And>s d i conf cs. (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i conf cs. (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow>' d) = (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s i conf cs. (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>)\"\n    \"\\<And>d i conf cs. (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>') = (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>)\"\n    by (unfold isMessageFromTo'_def isMessageTo'_def isMessageFrom'_def isMessage'_def,\n        auto simp add: messages' isMessageFromTo_def isMessageTo_def isMessageFrom_def isMessage_def)\n\n  have property_simps[simp]:\n    \"\\<And>n. currentNode (nodeState' n) = currentNode (nodeState n)\"\n    \"\\<And>n. firstUncommittedSlot (nodeState' n) = firstUncommittedSlot (nodeState n)\"\n    \"\\<And>n. currentVotingNodes (nodeState' n) = currentVotingNodes (nodeState n)\"\n    \"\\<And>n q. isQuorum (nodeState' n) q = isQuorum (nodeState n) q\"\n    \"\\<And>n. currentTerm (nodeState' n) = currentTerm (nodeState n)\"\n    \"\\<And>n. publishPermitted (nodeState' n) = publishPermitted (nodeState n)\"\n    \"\\<And>n. joinVotes (nodeState' n) = joinVotes (nodeState n)\"\n    \"\\<And>n. electionWon (nodeState' n) = electionWon (nodeState n)\"\n    \"\\<And>n. publishVotes (nodeState' n) = publishVotes (nodeState n)\"\n    \"\\<And>n. currentClusterState (nodeState' n) = currentClusterState (nodeState n)\"\n    \"lastAcceptedTerm nd' = SomeTerm t\"\n    \"lastAcceptedValue nd' = x\"\n    using precondition\n    by (unfold nodeState'_def, auto simp add: result nd' nd_def isQuorum_def\n        lastAcceptedTerm_def lastAcceptedValue_def)\n\n  have updated_properties:\n    \"\\<And>n. lastAcceptedTerm (nodeState' n) = (if n = n\\<^sub>0 then SomeTerm t else lastAcceptedTerm (nodeState n))\"\n    \"\\<And>n. lastAcceptedValue (nodeState' n) = (if n = n\\<^sub>0 then x else lastAcceptedValue (nodeState n))\"\n    by (unfold nodeState'_def, auto simp add: result nd' nd_def\n        lastAcceptedTerm_def lastAcceptedValue_def)\n\n  have PublishResponse': \"\\<And>s' d i t'. (s' \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<rightarrow>' d) =\n    ((s' \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<rightarrow> d) \\<or> (s', i, t', d) = (n\\<^sub>0, firstUncommittedSlot nd, t, OneNode s))\"\n    \"\\<And>d i t'. (\\<langle> PublishResponse i t' \\<rangle>\\<rightarrow>' d) =\n    ((\\<langle> PublishResponse i t' \\<rangle>\\<rightarrow> d) \\<or> (i, t', d) = (firstUncommittedSlot nd, t, OneNode s))\"\n    \"\\<And>s' i t'. (s' \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>') =\n    ((s' \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>) \\<or> (s', i, t') = (n\\<^sub>0, firstUncommittedSlot nd, t))\"\n    \"\\<And>i t'. (\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>') =\n    ((\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>) \\<or> (i, t') = (firstUncommittedSlot nd, t))\"\n    unfolding isMessageFromTo_def isMessageFromTo'_def isMessageFrom_def isMessageFrom'_def isMessageTo_def isMessageTo'_def isMessage_def isMessage'_def\n    by (auto simp add: messages' precondition)\n\n  have v_eq[simp]: \"v' = v\" by (intro ext, auto simp add: v'_def v_def)\n  have v\\<^sub>c_eq[simp]: \"v\\<^sub>c' = v\\<^sub>c\" by (intro ext, auto simp add: v\\<^sub>c'_def v\\<^sub>c_def)\n  have isCommitted_eq[simp]: \"isCommitted' = isCommitted\" by (intro ext, auto simp add: isCommitted'_def isCommitted_def)\n  have committedTo_eq[simp]: \"committed\\<^sub><' = committed\\<^sub><\" by (intro ext, auto simp add: committedTo'_def committedTo_def)\n  have V_eq[simp]: \"V' = V\" using v\\<^sub>c_eq V'_def V_def by blast\n  have lastCommittedClusterStateBefore_eq[simp]: \"lastCommittedClusterStateBefore' = lastCommittedClusterStateBefore\"\n    unfolding lastCommittedClusterStateBefore_def lastCommittedClusterStateBefore'_def v\\<^sub>c_eq ..\n  have promised_eq[simp]: \"promised' = promised\" by (intro ext, auto simp add: promised'_def promised_def)\n  have prevAccepted_eq[simp]: \"prevAccepted' = prevAccepted\" by (intro ext, auto simp add: prevAccepted'_def prevAccepted_def)\n\n  show ?thesis\n    apply (intro zenI)\n                        apply (unfold message_simps committedTo_eq V_eq v_eq\n        lastCommittedClusterStateBefore_eq property_simps promised_eq prevAccepted_eq)\n  proof -\n    from finite_messages show \"finite messages'\" by (simp add: messages')\n    from Vote_Some_lt show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t\".\n    from Vote_not_broadcast show \"\\<And>i t a d. \\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> d \\<noteq> Broadcast\".\n    from Vote_unique_destination show \"\\<And>i' i s t a a' d d'. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> s \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<rightarrow> d' \\<Longrightarrow> d = d'\".\n    from currentNode_nodeState show \"\\<And>n. currentNode (nodeState n) = n\" .\n    from committedTo_firstUncommittedSlot show \"\\<And>n. committed\\<^sub>< (firstUncommittedSlot (nodeState n))\" .\n    from Vote_currentTerm show \"\\<And>n i t a. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from Vote_slot_function show \"\\<And>n i i' t a a'. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> n \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<leadsto> \\<Longrightarrow> i = i'\".\n    from electionWon_isQuorum show \"\\<And>n. electionWon (nodeState n) \\<Longrightarrow> isQuorum (nodeState n) (joinVotes (nodeState n))\".\n    from currentClusterState_lastCommittedClusterStateBefore show \"\\<And>n. currentClusterState (nodeState n) = lastCommittedClusterStateBefore (firstUncommittedSlot (nodeState n))\".\n    from joinVotes show \"\\<And>n n'. n' \\<in> joinVotes (nodeState n) \\<Longrightarrow> promised (firstUncommittedSlot (nodeState n)) n' n (currentTerm (nodeState n))\".\n    from PublishRequest_committedTo show \"\\<And>i t x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from PublishRequest_function show \"\\<And>i t x x'. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<langle> PublishRequest i t x' \\<rangle>\\<leadsto> \\<Longrightarrow> x = x'\".\n    from currentVotingNodes_firstUncommittedSlot show \"\\<And>n. currentVotingNodes (nodeState n) = V (firstUncommittedSlot (nodeState n))\".\n    from firstUncommittedSlot_PublishRequest show \"\\<And>i n t x. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from PublishRequest_currentTerm show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from PublishRequest_publishPermitted_currentTerm show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> publishPermitted (nodeState n) \\<Longrightarrow> t < currentTerm (nodeState n)\".\n    from CatchUpResponse_committedTo show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from CatchUpResponse_V show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> V i = conf\".\n    from CatchUpResponse_lastCommittedClusterStateBefore show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> lastCommittedClusterStateBefore i = cs\".\n\n    from Vote_future show \"\\<And>i i' s t t' a. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> i < i' \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i' t' \\<rangle>\\<leadsto>'\"\n      using precondition unfolding PublishResponse' nd_def by (metis Vote_currentTerm Pair_inject leD)\n\n    from Vote_None show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t NO_TERM \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>'\"\n      using precondition unfolding PublishResponse' nd_def by (metis Vote_currentTerm Pair_inject leD)\n\n    from Vote_Some_PublishResponse show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>'\"\n      using precondition unfolding PublishResponse' nd_def by metis\n\n    from Vote_Some_max show \"\\<And>i s t t' t''. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t'' \\<Longrightarrow> t'' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t'' \\<rangle>\\<leadsto>'\"\n      using precondition unfolding PublishResponse' nd_def using Vote_currentTerm by fastforce\n\n    from PublishRequest_quorum show \"\\<And>i s t x. s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). (\\<forall>n\\<in>q. promised i n s t) \\<and> (prevAccepted i t q = {} \\<or> (\\<exists>t'. v i t = v i t' \\<and> maxTerm (prevAccepted i t q) \\<le> t' \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto>' \\<and> t' < t))\" \n      unfolding PublishResponse' by meson\n\n    fix n\n\n    from firstUncommittedSlot_PublishResponse show \"\\<And>i t. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>'\" \n      using precondition property_simps unfolding PublishResponse' nd_def by (cases \"n = n\\<^sub>0\", auto)\n\n    from lastAcceptedTerm_None show \"\\<And>i t. lastAcceptedTerm (nodeState' n) = NO_TERM \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>'\"\n      using precondition property_simps updated_properties unfolding PublishResponse' nd_def by (cases \"n = n\\<^sub>0\", auto)\n\n    from lastAcceptedTerm_Some_sent show \"\\<And>n t. lastAcceptedTerm (nodeState' n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>'\"\n      using precondition property_simps unfolding PublishResponse' nd_def\n      by (metis nd'_def nodeState_unchanged TermOption.inject)\n\n    from lastAcceptedTerm_Some_max show \"\\<And>t t'. lastAcceptedTerm (nodeState' n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t' \\<rangle>\\<leadsto>' \\<Longrightarrow> t' \\<le> t\"\n      using precondition property_simps updated_properties unfolding PublishResponse' nd_def apply (cases \"n = n\\<^sub>0\", auto)\n      by (meson TermOption.exhaust lastAcceptedTerm_None lastAcceptedTerm_Some_currentTerm le_trans)\n    \n    from joinVotes_max show \"\\<And>n n' a'. \\<not> (\\<exists>x. \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) x \\<rangle>\\<leadsto>) \\<Longrightarrow> n' \\<in> joinVotes (nodeState n) \\<Longrightarrow> n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) a' \\<rangle>\\<rightarrow> (OneNode n) \\<Longrightarrow> a' \\<le> lastAcceptedTerm (nodeState' n)\"\n      using precondition property_simps unfolding PublishResponse' nd_def\n      by (metis isMessage_def nodeState_unchanged sent)\n\n    from publishVotes show \"\\<And>n n'. n' \\<in> publishVotes (nodeState n) \\<Longrightarrow> n' \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) \\<rangle>\\<leadsto>'\"\n      using precondition property_simps unfolding PublishResponse' nd_def\n      by blast\n\n    from PublishResponse_PublishRequest show \"\\<And>i s t. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>' \\<Longrightarrow> \\<exists>x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\"\n      using precondition property_simps unfolding PublishResponse' nd_def\n      using isMessage_def sent by auto\n\n    from ApplyCommit_quorum show \"\\<And>i t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). \\<forall>s\\<in>q. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>'\"\n      using precondition property_simps unfolding PublishResponse' nd_def\n      by meson\n\n    from lastAcceptedTerm_Some_value show \"\\<And>n t. lastAcceptedTerm (nodeState' n) = SomeTerm t \\<Longrightarrow> \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t (lastAcceptedValue (nodeState' n)) \\<rangle>\\<leadsto>\"\n      using precondition property_simps unfolding PublishResponse' nd_def\n      by (metis isMessage_def nd'_def nodeState_unchanged TermOption.inject sent)\n\n    from lastAcceptedTerm_Some_currentTerm show \"\\<And>n t. lastAcceptedTerm (nodeState' n) = SomeTerm t \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\"\n      using precondition property_simps unfolding PublishResponse' nd_def\n      by (metis eq_imp_le TermOption.inject updated_properties(1))\n  qed\nqed\n\nlemma (in zenStep) addPublishVote_invariants:\n  assumes nd': \"nd' = nd \\<lparr> publishVotes := insert s (publishVotes nd) \\<rparr>\"\n  assumes messages': \"messages' = messages\"\n  assumes sent: \"s \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot nd) (currentTerm nd) \\<rangle>\\<leadsto>\"\n  shows \"zen messages' nodeState'\"\nproof -\n  have message_simps[simp]:\n    \"\\<And>s p d. (s \\<midarrow>\\<langle> p \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> p \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>p d. (\\<langle> p \\<rangle>\\<rightarrow>' d) = (\\<langle> p \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s p. (s \\<midarrow>\\<langle> p \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> p \\<rangle>\\<leadsto>)\"\n    \"\\<And>p. (\\<langle> p \\<rangle>\\<leadsto>') = (\\<langle> p \\<rangle>\\<leadsto>)\"\n    by (unfold isMessageFromTo'_def isMessageTo'_def isMessageFrom'_def isMessage'_def,\n        auto simp add: messages' isMessageFromTo_def isMessageTo_def isMessageFrom_def isMessage_def)\n\n  have property_simps[simp]:\n    \"\\<And>n. currentNode (nodeState' n) = currentNode (nodeState n)\"\n    \"\\<And>n. firstUncommittedSlot (nodeState' n) = firstUncommittedSlot (nodeState n)\"\n    \"\\<And>n. currentVotingNodes (nodeState' n) = currentVotingNodes (nodeState n)\"\n    \"\\<And>n q. isQuorum (nodeState' n) q = isQuorum (nodeState n) q\"\n    \"\\<And>n. lastAcceptedTerm (nodeState' n) = lastAcceptedTerm (nodeState n)\"\n    \"\\<And>n. lastAcceptedValue (nodeState' n) = lastAcceptedValue (nodeState n)\"\n    \"\\<And>n. currentTerm (nodeState' n) = currentTerm (nodeState n)\"\n    \"\\<And>n. publishPermitted (nodeState' n) = publishPermitted (nodeState n)\"\n    \"\\<And>n. joinVotes (nodeState' n) = joinVotes (nodeState n)\"\n    \"\\<And>n. electionWon (nodeState' n) = electionWon (nodeState n)\"\n    \"\\<And>n. currentClusterState (nodeState' n) = currentClusterState (nodeState n)\"\n    by (unfold nodeState'_def, auto simp add: nd_def isQuorum_def nd' addElectionVote_def Let_def\n        lastAcceptedTerm_def lastAcceptedValue_def)\n\n  have updated_properties[simp]:\n    \"\\<And>n. publishVotes (nodeState' n) = publishVotes (nodeState n) \\<union> (if n = n\\<^sub>0 then {s} else {})\"\n    by (unfold nodeState'_def, auto simp add: nd' nd_def isQuorum_def)\n\n  have v_eq[simp]: \"v' = v\" by (intro ext, auto simp add: v'_def v_def)\n  have v\\<^sub>c_eq[simp]: \"v\\<^sub>c' = v\\<^sub>c\" by (intro ext, auto simp add: v\\<^sub>c'_def v\\<^sub>c_def)\n  have isCommitted_eq[simp]: \"isCommitted' = isCommitted\" by (intro ext, auto simp add: isCommitted'_def isCommitted_def)\n  have committedTo_eq[simp]: \"committed\\<^sub><' = committed\\<^sub><\" by (intro ext, auto simp add: committedTo'_def committedTo_def)\n  have V_eq[simp]: \"V' = V\" using v\\<^sub>c_eq V'_def V_def by blast\n  have promised_eq[simp]: \"promised' = promised\" by (intro ext, auto simp add: promised'_def promised_def)\n  have lastCommittedClusterStateBefore_eq[simp]: \"lastCommittedClusterStateBefore' = lastCommittedClusterStateBefore\"\n    unfolding lastCommittedClusterStateBefore_def lastCommittedClusterStateBefore'_def v\\<^sub>c_eq ..\n  have prevAccepted_eq[simp]: \"prevAccepted' = prevAccepted\" by (intro ext, auto simp add: prevAccepted'_def prevAccepted_def)\n\n  show ?thesis\n    apply (intro zenI)\n                        apply (unfold message_simps committedTo_eq V_eq v_eq\n        lastCommittedClusterStateBefore_eq property_simps promised_eq prevAccepted_eq)\n  proof -\n    from finite_messages show \"finite messages'\" by (simp add: messages')\n    from Vote_future show \"\\<And>i i' s t t' a. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> i < i' \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i' t' \\<rangle>\\<leadsto>\".\n    from Vote_None show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t NO_TERM \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_lt show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t\".\n    from Vote_Some_PublishResponse show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_max show \"\\<And>i s t t' t''. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t'' \\<Longrightarrow> t'' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t'' \\<rangle>\\<leadsto>\".\n    from Vote_not_broadcast show \"\\<And>i t a d. \\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> d \\<noteq> Broadcast\".\n    from Vote_unique_destination show \"\\<And>i' i s t a a' d d'. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> s \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<rightarrow> d' \\<Longrightarrow> d = d'\".\n    from currentNode_nodeState show \"\\<And>n. currentNode (nodeState n) = n\" .\n    from committedTo_firstUncommittedSlot show \"\\<And>n. committed\\<^sub>< (firstUncommittedSlot (nodeState n))\" .\n    from firstUncommittedSlot_PublishResponse show \"\\<And>n i t. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\" .\n    from lastAcceptedTerm_None show \"\\<And>n i t. lastAcceptedTerm (nodeState n) = NO_TERM \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_sent show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_max show \"\\<And>n t t'. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t' \\<rangle>\\<leadsto> \\<Longrightarrow> t' \\<le> t\".\n    from Vote_currentTerm show \"\\<And>n i t a. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from Vote_slot_function show \"\\<And>n i i' t a a'. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> n \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<leadsto> \\<Longrightarrow> i = i'\".\n    from electionWon_isQuorum show \"\\<And>n. electionWon (nodeState n) \\<Longrightarrow> isQuorum (nodeState n) (joinVotes (nodeState n))\".\n    from joinVotes_max show \"\\<And>n n' a'. \\<not> (\\<exists>x. \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) x \\<rangle>\\<leadsto>) \\<Longrightarrow> n' \\<in> joinVotes (nodeState n) \\<Longrightarrow> n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) a' \\<rangle>\\<rightarrow> (OneNode n) \\<Longrightarrow> a' \\<le> lastAcceptedTerm (nodeState n)\".\n    from currentClusterState_lastCommittedClusterStateBefore show \"\\<And>n. currentClusterState (nodeState n) = lastCommittedClusterStateBefore (firstUncommittedSlot (nodeState n))\".\n    from joinVotes show \"\\<And>n n'. n' \\<in> joinVotes (nodeState n) \\<Longrightarrow> promised (firstUncommittedSlot (nodeState n)) n' n (currentTerm (nodeState n))\".\n    from PublishRequest_committedTo show \"\\<And>i t x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from PublishRequest_quorum show \"\\<And>i s t x. s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). (\\<forall>n\\<in>q. promised i n s t) \\<and> (prevAccepted i t q = {} \\<or> (\\<exists>t'. v i t = v i t' \\<and> maxTerm (prevAccepted i t q) \\<le> t' \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto> \\<and> t' < t))\".\n    from PublishRequest_function show \"\\<And>i t x x'. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<langle> PublishRequest i t x' \\<rangle>\\<leadsto> \\<Longrightarrow> x = x'\".\n    from PublishResponse_PublishRequest show \"\\<And>i s t. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from ApplyCommit_quorum show \"\\<And>i t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). \\<forall>s\\<in>q. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\".\n    from currentVotingNodes_firstUncommittedSlot show \"\\<And>n. currentVotingNodes (nodeState n) = V (firstUncommittedSlot (nodeState n))\".\n    from firstUncommittedSlot_PublishRequest show \"\\<And>i n t x. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_value show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t (lastAcceptedValue (nodeState n)) \\<rangle>\\<leadsto>\".\n    from PublishRequest_currentTerm show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from PublishRequest_publishPermitted_currentTerm show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> publishPermitted (nodeState n) \\<Longrightarrow> t < currentTerm (nodeState n)\".\n    from CatchUpResponse_committedTo show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from CatchUpResponse_V show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> V i = conf\".\n    from CatchUpResponse_lastCommittedClusterStateBefore show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> lastCommittedClusterStateBefore i = cs\".\n    from lastAcceptedTerm_Some_currentTerm show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n\n    from publishVotes show \"\\<And>n n'. n' \\<in> publishVotes (nodeState' n) \\<Longrightarrow> n' \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) \\<rangle>\\<leadsto>\"\n      unfolding updated_properties using sent apply auto by (metis empty_iff nd_def singleton_iff)\n  qed\nqed\n\nlemma (in zenStep) commitIfQuorate_invariants:\n  fixes s i t\n  defines \"result \\<equiv> commitIfQuorate nd\"\n  assumes nd': \"nd' = fst result\"\n  assumes messages': \"messages' = sendTo Broadcast result\"\n  shows \"zen messages' nodeState'\"\nproof (cases \"isQuorum nd (publishVotes nd)\")\n  case False\n  hence [simp]: \"result = (nd, None)\"\n    by (simp add: result_def commitIfQuorate_def)\n\n  have [simp]: \"messages' = messages\"\n    by (simp add: messages')\n\n  have [simp]: \"nodeState' = nodeState\"\n    unfolding nodeState'_def\n    by (intro ext, simp add: nd' nd_def)\n\n  from zen_axioms show ?thesis by simp\n\nnext\n  case isQuorum: True\n  hence result: \"result = (nd, Some (ApplyCommit (firstUncommittedSlot nd) (currentTerm nd)))\"\n    by (simp add: result_def commitIfQuorate_def)\n\n  have nodeState': \"nodeState' = nodeState\"\n    unfolding nodeState'_def\n    by (intro ext, simp add: nd' nd_def result)\n\n  have messages': \"messages' = insert \\<lparr> sender = n\\<^sub>0, destination = Broadcast, payload = ApplyCommit (firstUncommittedSlot nd) (currentTerm nd) \\<rparr> messages\"\n    by (simp add: messages' result)\n\n  have message_simps[simp]:\n    \"\\<And>s d i t. (s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s d i t x. (s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s d i t a. (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t. (\\<langle> PublishResponse i t \\<rangle>\\<rightarrow>' d) = (\\<langle> PublishResponse i t \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t x. (\\<langle> PublishRequest i t x \\<rangle>\\<rightarrow>' d) = (\\<langle> PublishRequest i t x \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t a. (\\<langle> Vote i t a \\<rangle>\\<rightarrow>' d) = (\\<langle> Vote i t a \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s i t. (s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>)\"\n    \"\\<And>s i t x. (s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>)\"\n    \"\\<And>s i t a. (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto>)\"\n    \"\\<And>i t. (\\<langle> PublishResponse i t \\<rangle>\\<leadsto>') = (\\<langle> PublishResponse i t \\<rangle>\\<leadsto>)\"\n    \"\\<And>i t x. (\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>') = (\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>)\"\n    \"\\<And>i t a. (\\<langle> Vote i t a \\<rangle>\\<leadsto>') = (\\<langle> Vote i t a \\<rangle>\\<leadsto>)\"\n    \"\\<And>s d i conf cs. (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i conf cs. (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow>' d) = (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s i conf cs. (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>)\"\n    \"\\<And>d i conf cs. (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>') = (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>)\"\n    by (unfold isMessageFromTo'_def isMessageTo'_def isMessageFrom'_def isMessage'_def,\n        auto simp add: messages' isMessageFromTo_def isMessageTo_def isMessageFrom_def isMessage_def)\n\n  have ApplyCommit': \"\\<And>s d i t. (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow>' d) = ((s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow> d)\n      \\<or> (s, i, t, d) = (n\\<^sub>0, firstUncommittedSlot nd, currentTerm nd, Broadcast))\"\n    \"\\<And>s i t. (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>') = ((s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>)\n      \\<or> (s, i, t) = (n\\<^sub>0, firstUncommittedSlot nd, currentTerm nd))\"\n    \"\\<And>d i t. (\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow>' d) = ((\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow> d)\n      \\<or> (i, t, d) = (firstUncommittedSlot nd, currentTerm nd, Broadcast))\"\n    \"\\<And>i t. (\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>') = ((\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>)\n      \\<or> (i, t) = (firstUncommittedSlot nd, currentTerm nd))\"\n    unfolding isMessageFromTo_def isMessageFromTo'_def isMessageFrom_def isMessageFrom'_def isMessageTo_def isMessageTo'_def isMessage_def isMessage'_def\n    by (auto simp add: messages')\n\n  from committedTo_firstUncommittedSlot\n  have committedTo_current: \"committed\\<^sub>< (firstUncommittedSlot nd)\"\n    by (simp add: nd_def)\n\n  have isCommitted_eq: \"\\<And>i. isCommitted' i = (isCommitted i \\<or> i = firstUncommittedSlot nd)\"\n    using isCommitted'_def isCommitted_def by (auto simp add: ApplyCommit')\n\n  have committedTo_eq: \"\\<And>i. committed\\<^sub><' i = ((committed\\<^sub>< i) \\<or> (i = Suc (firstUncommittedSlot nd)))\"\n  proof -\n    fix i\n    show \"?thesis i\"\n    proof (cases \"isCommitted (firstUncommittedSlot nd)\")\n      case True with isCommitted_eq have 1: \"isCommitted' = isCommitted\" by (intro ext, auto)\n      from True isCommitted_committedTo_Suc have 2: \"committed\\<^sub>< (Suc (firstUncommittedSlot nd))\" by simp\n      from 1 2 show ?thesis by (simp add: committedTo'_def committedTo_def, blast)\n    next\n      case False\n      with committedTo_current isCommitted_committedTo\n      have isCommitted_lt[simp]: \"\\<And>j. isCommitted j = (j < firstUncommittedSlot nd)\"\n        using committedTo_def nat_neq_iff by blast\n      have isCommitted'_le[simp]: \"\\<And>j. isCommitted' j = (j \\<le> firstUncommittedSlot nd)\"\n        by (auto simp add: isCommitted_eq)\n      show ?thesis\n        by (simp add: committedTo'_def committedTo_def, auto, presburger)\n    qed\n  qed\n\n  have v_eq[simp]: \"v' = v\" by (intro ext, auto simp add: v'_def v_def)\n\n  note oneSlot.consistent [OF oneSlot.commit [OF zen_is_oneSlot]]\n\n  have v\\<^sub>c_eq: \"\\<And>i. isCommitted i \\<Longrightarrow> v\\<^sub>c' i = v\\<^sub>c i\"\n  proof -\n    fix i assume \"isCommitted i\" then obtain t where t: \"\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>\" unfolding isCommitted_def by blast\n    show \"?thesis i\"\n    proof (cases \"i = firstUncommittedSlot nd\")\n      case False thus ?thesis unfolding v\\<^sub>c_def v\\<^sub>c'_def v_eq ApplyCommit' by simp\n    next\n      case i: True\n      show \"v\\<^sub>c' i = v\\<^sub>c i\"\n        unfolding v\\<^sub>c_def v\\<^sub>c'_def v_eq\n      proof (intro oneSlot.consistent [OF oneSlot.commit [OF zen_is_oneSlot]])\n        from isQuorum show \"publishVotes nd \\<in> majorities (V i)\" unfolding nd_def i isQuorum_def using currentVotingNodes_firstUncommittedSlot by simp\n        from publishVotes show \"\\<And>n. n \\<in> publishVotes nd \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse i (currentTerm nd) \\<rangle>\\<leadsto>\" unfolding nd_def i .\n        from t have \"\\<langle> ApplyCommit i (SOME t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto>) \\<rangle>\\<leadsto>\" by (intro someI)\n        thus \"\\<langle> ApplyCommit i (SOME t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto>) \\<rangle>\\<leadsto> \\<or> (SOME t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto>) = currentTerm nd\" by simp\n        show \"\\<langle> ApplyCommit i (SOME t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto>') \\<rangle>\\<leadsto> \\<or> (SOME t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto>') = currentTerm nd\"\n        proof (rule someI2)\n          from t show \"\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>'\"\n            \"\\<And>x. \\<langle> ApplyCommit i x \\<rangle>\\<leadsto>' \\<Longrightarrow> \\<langle> ApplyCommit i x \\<rangle>\\<leadsto> \\<or> x = currentTerm nd\"\n            by (simp_all add: ApplyCommit' i)\n        qed\n      qed\n    qed\n  qed\n\n  have V_eq: \"\\<And>i. committed\\<^sub>< i \\<Longrightarrow> V' i = V i\"\n  proof -\n    fix i assume i: \"committed\\<^sub>< i\"\n    thus \"?thesis i\"\n    proof (induct i)\n      case (Suc i')\n      hence prems: \"committed\\<^sub>< i'\" \"isCommitted i'\" unfolding committedTo_def by auto\n      thus ?case using Suc v\\<^sub>c_eq by simp\n    qed simp\n  qed\n  hence V_era_eq: \"\\<And>n. V' (firstUncommittedSlot (nodeState n)) = V (firstUncommittedSlot (nodeState n))\"\n    using committedTo_firstUncommittedSlot by blast\n\n  have lastCommittedClusterStateBefore_eq: \"\\<And>i. committed\\<^sub>< i \\<Longrightarrow> lastCommittedClusterStateBefore' i = lastCommittedClusterStateBefore i\"\n  proof -\n    fix i assume \"committed\\<^sub>< i\"\n    thus \"?thesis i\"\n    proof (induct i)\n      case (Suc i')\n      hence prems: \"committed\\<^sub>< i'\" \"isCommitted i'\" unfolding committedTo_def by auto\n      thus ?case using Suc v\\<^sub>c_eq by (cases \"v\\<^sub>c i'\", simp_all)\n    qed simp\n  qed\n  hence lastCommittedClusterStateBefore_slot_eq:\n    \"\\<And>n. lastCommittedClusterStateBefore' (firstUncommittedSlot (nodeState n))\n        = lastCommittedClusterStateBefore (firstUncommittedSlot (nodeState n))\"\n    using committedTo_firstUncommittedSlot by blast\n\n  have promised_eq[simp]: \"promised' = promised\" by (intro ext, auto simp add: promised'_def promised_def)\n  have prevAccepted_eq[simp]: \"prevAccepted' = prevAccepted\" by (intro ext, auto simp add: prevAccepted'_def prevAccepted_def)\n\n  show ?thesis\n    apply (intro zenI)\n                        apply (unfold nodeState' message_simps V_era_eq lastCommittedClusterStateBefore_slot_eq promised_eq prevAccepted_eq v_eq)\n  proof -\n    from finite_messages show \"finite messages'\" by (simp add: messages')\n    from Vote_future show \"\\<And>i i' s t t' a. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> i < i' \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i' t' \\<rangle>\\<leadsto>\".\n    from Vote_None show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t NO_TERM \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_lt show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t\".\n    from Vote_Some_PublishResponse show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_max show \"\\<And>i s t t' t''. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t'' \\<Longrightarrow> t'' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t'' \\<rangle>\\<leadsto>\".\n    from Vote_not_broadcast show \"\\<And>i t a d. \\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> d \\<noteq> Broadcast\".\n    from Vote_unique_destination show \"\\<And>i' i s t a a' d d'. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> s \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<rightarrow> d' \\<Longrightarrow> d = d'\".\n    from currentNode_nodeState show \"\\<And>n. currentNode (nodeState n) = n\" .\n    from firstUncommittedSlot_PublishResponse show \"\\<And>n i t. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\" .\n    from lastAcceptedTerm_None show \"\\<And>n i t. lastAcceptedTerm (nodeState n) = NO_TERM \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_sent show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_max show \"\\<And>n t t'. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t' \\<rangle>\\<leadsto> \\<Longrightarrow> t' \\<le> t\".\n    from Vote_currentTerm show \"\\<And>n i t a. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from Vote_slot_function show \"\\<And>n i i' t a a'. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> n \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<leadsto> \\<Longrightarrow> i = i'\".\n    from electionWon_isQuorum show \"\\<And>n. electionWon (nodeState n) \\<Longrightarrow> isQuorum (nodeState n) (joinVotes (nodeState n))\".\n    from joinVotes_max show \"\\<And>n n' a'. \\<not> (\\<exists>x. \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) x \\<rangle>\\<leadsto>) \\<Longrightarrow> n' \\<in> joinVotes (nodeState n) \\<Longrightarrow> n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) a' \\<rangle>\\<rightarrow> (OneNode n) \\<Longrightarrow> a' \\<le> lastAcceptedTerm (nodeState n)\".\n    from publishVotes show \"\\<And>n n'. n' \\<in> publishVotes (nodeState n) \\<Longrightarrow> n' \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) \\<rangle>\\<leadsto>\".\n    from currentClusterState_lastCommittedClusterStateBefore show \"\\<And>n. currentClusterState (nodeState n) = lastCommittedClusterStateBefore (firstUncommittedSlot (nodeState n))\".\n    from joinVotes show \"\\<And>n n'. n' \\<in> joinVotes (nodeState n) \\<Longrightarrow> promised (firstUncommittedSlot (nodeState n)) n' n (currentTerm (nodeState n))\".\n    from PublishRequest_function show \"\\<And>i t x x'. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<langle> PublishRequest i t x' \\<rangle>\\<leadsto> \\<Longrightarrow> x = x'\".\n    from PublishResponse_PublishRequest show \"\\<And>i s t. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from currentVotingNodes_firstUncommittedSlot show \"\\<And>n. currentVotingNodes (nodeState n) = V (firstUncommittedSlot (nodeState n))\".\n    from firstUncommittedSlot_PublishRequest show \"\\<And>i n t x. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_value show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t (lastAcceptedValue (nodeState n)) \\<rangle>\\<leadsto>\".\n    from PublishRequest_currentTerm show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from PublishRequest_publishPermitted_currentTerm show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> publishPermitted (nodeState n) \\<Longrightarrow> t < currentTerm (nodeState n)\".\n    from lastAcceptedTerm_Some_currentTerm show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n\n    {\n      fix i conf cs assume a: \"\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>\"\n      with CatchUpResponse_committedTo have committedTo: \"committed\\<^sub>< i\" .\n      thus \"committed\\<^sub><' i\" unfolding committedTo_eq by simp\n      from a committedTo V_eq lastCommittedClusterStateBefore_eq CatchUpResponse_V CatchUpResponse_lastCommittedClusterStateBefore\n      show \"V' i = conf\" \"lastCommittedClusterStateBefore' i = cs\" by auto\n    }\n\n    from committedTo_firstUncommittedSlot\n    show \"\\<And>n. committed\\<^sub><' (firstUncommittedSlot (nodeState n))\"\n      unfolding committedTo_eq by simp\n\n    from PublishRequest_committedTo\n    show \"\\<And>i t x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub><' i\"\n      unfolding committedTo_eq by simp\n\n    from PublishRequest_quorum\n    show \"\\<And>i s t x. s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V' i). (\\<forall>n\\<in>q. promised i n s t) \\<and> (prevAccepted i t q = {} \\<or> (\\<exists>t'. v i t = v i t' \\<and> maxTerm (prevAccepted i t q) \\<le> t' \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto> \\<and> t' < t))\"\n      using V_eq PublishRequest_committedTo isMessage_def by metis\n\n    from ApplyCommit_quorum\n    show \"\\<And>i t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto>' \\<Longrightarrow> \\<exists>q\\<in>majorities (V' i). \\<forall>s\\<in>q. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\"\n      using V_eq committedTo_firstUncommittedSlot unfolding ApplyCommit' committedTo_def isCommitted_def\n      by (metis ApplyCommit_PublishRequest_v\\<^sub>c PublishRequest_committedTo V_eq isQuorum currentVotingNodes_firstUncommittedSlot nd_def prod.inject publishVotes isQuorum_def)\n  qed\nqed\n\nlemma (in zenStep) handlePublishResponse_invariants:\n  fixes s i t\n  defines \"result \\<equiv> handlePublishResponse s i t nd\"\n  assumes nd': \"nd' = fst result\"\n  assumes messages': \"messages' = sendTo Broadcast result\"\n  assumes sent: \"s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\"\n  shows \"zen messages' nodeState'\"\nproof (cases \"i = firstUncommittedSlot nd \\<and> t = currentTerm nd\")\n  case False\n  hence [simp]: \"result = (nd, None)\"\n    by (auto simp add: result_def handlePublishResponse_def Let_def)\n\n  have [simp]: \"messages' = messages\"\n    by (simp add: messages')\n\n  have [simp]: \"nodeState' = nodeState\"\n    unfolding nodeState'_def\n    by (intro ext, simp add: nd' nd_def)\n\n  from zen_axioms show ?thesis by simp\n\nnext\n  case True\n  hence i: \"i = firstUncommittedSlot nd\"\n    and t: \"t = currentTerm nd\"\n    by simp_all\n\n  define nd1 where \"nd1 \\<equiv> nd \\<lparr>publishVotes := insert s (publishVotes nd)\\<rparr>\"\n  define nodeState1 where \"nodeState1 \\<equiv> \\<lambda>n. if n = n\\<^sub>0 then nd1 else nodeState n\"\n\n  have result: \"result = commitIfQuorate nd1\"\n    by (simp add: result_def handlePublishResponse_def i t nd1_def)\n\n  have zenStep1: \"zenStep messages nodeState messages nodeState1 n\\<^sub>0\"\n    by (intro zenStepI2, auto simp add: nodeState1_def)\n\n  have zenStep2: \"zenStep messages nodeState1 messages' nodeState' n\\<^sub>0\"\n  proof (intro zenStep.zenStepI1 [OF zenStep1] zenStep.addPublishVote_invariants [OF zenStep1] refl messages_subset,\n      fold isMessageFromTo_def isMessageFrom_def nd_def)\n    show \"nodeState1 n\\<^sub>0 = nd\\<lparr>publishVotes := insert s (publishVotes nd)\\<rparr>\"\n      by (simp add: nodeState1_def nd1_def)\n    from sent show \"s \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot nd) (currentTerm nd) \\<rangle>\\<leadsto>\" by (simp add: True)\n    show \"\\<And>n. n \\<noteq> n\\<^sub>0 \\<Longrightarrow> nodeState1 n = nodeState' n\" unfolding nodeState1_def nodeState'_def by simp\n  qed\n\n  show ?thesis\n  proof (intro zenStep.commitIfQuorate_invariants [OF zenStep2])\n    show \"nodeState' n\\<^sub>0 = fst (commitIfQuorate (nodeState1 n\\<^sub>0))\"\n      by (simp add: nodeState'_def nd' result nodeState1_def)\n    show \"messages' = (case snd (commitIfQuorate (nodeState1 n\\<^sub>0)) of None \\<Rightarrow> messages | Some m \\<Rightarrow> insert \\<lparr>sender = n\\<^sub>0, destination = Broadcast, payload = m\\<rparr> messages)\"\n      by (cases \"commitIfQuorate (nodeState1 n\\<^sub>0)\", cases \"snd (commitIfQuorate (nodeState1 n\\<^sub>0))\",\n          simp_all add: nodeState1_def messages' result_def handlePublishResponse_def i t nd1_def)\n  qed\nqed\n\nlemma (in zenStep) handleApplyCommit_invariants:\n  assumes nd': \"nd' = handleApplyCommit i t nd\"\n  assumes messages'[simp]: \"messages' = messages\"\n  assumes sent: \"\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>\"\n  shows \"zen messages' nodeState'\"\nproof (cases \"i = firstUncommittedSlot nd \\<and> lastAcceptedTerm nd = SomeTerm t\")\n  case False\n  hence nd'[simp]: \"nd' = nd\"\n    by (auto simp add: nd' handleApplyCommit_def)\n\n  have nodeState'[simp]: \"nodeState' = nodeState\" unfolding nodeState'_def by (intro ext, simp add: nd_def)\n\n  from zen_axioms show ?thesis unfolding nodeState' by simp\n\nnext\n  case True\n  hence i: \"i = firstUncommittedSlot nd\"\n    and t: \"lastAcceptedTerm nd = SomeTerm t\" by simp_all\n\n  have message_simps[simp]:\n    \"\\<And>s p d. (s \\<midarrow>\\<langle> p \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> p \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>p d. (\\<langle> p \\<rangle>\\<rightarrow>' d) = (\\<langle> p \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s p. (s \\<midarrow>\\<langle> p \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> p \\<rangle>\\<leadsto>)\"\n    \"\\<And>p. (\\<langle> p \\<rangle>\\<leadsto>') = (\\<langle> p \\<rangle>\\<leadsto>)\"\n    by (unfold isMessageFromTo'_def isMessageTo'_def isMessageFrom'_def isMessage'_def,\n        auto simp add: isMessageFromTo_def isMessageTo_def isMessageFrom_def isMessage_def)\n\n  have v_eq[simp]: \"v' = v\" by (intro ext, auto simp add: v'_def v_def)\n  have v\\<^sub>c_eq[simp]: \"v\\<^sub>c' = v\\<^sub>c\" by (intro ext, auto simp add: v\\<^sub>c'_def v\\<^sub>c_def)\n  have isCommitted_eq[simp]: \"isCommitted' = isCommitted\" by (intro ext, auto simp add: isCommitted'_def isCommitted_def)\n  have committedTo_eq[simp]: \"committed\\<^sub><' = committed\\<^sub><\" by (intro ext, auto simp add: committedTo'_def committedTo_def)\n  have V_eq[simp]: \"V' = V\" using v\\<^sub>c_eq V'_def V_def by blast\n  have promised_eq[simp]: \"promised' = promised\" by (intro ext, auto simp add: promised'_def promised_def)\n  have lastCommittedClusterStateBefore_eq[simp]: \"lastCommittedClusterStateBefore' = lastCommittedClusterStateBefore\"\n    unfolding lastCommittedClusterStateBefore_def lastCommittedClusterStateBefore'_def v\\<^sub>c_eq ..\n  have prevAccepted_eq[simp]: \"prevAccepted' = prevAccepted\" by (intro ext, auto simp add: prevAccepted'_def prevAccepted_def)\n\n  from sent t\n  have lastAcceptedValue_eq: \"v\\<^sub>c i = lastAcceptedValue nd\"\n    unfolding i nd_def using lastAcceptedTerm_Some_value [of n\\<^sub>0 t]\n    by (intro PublishRequest_function [OF ApplyCommit_PublishRequest_v\\<^sub>c])\n\n  show ?thesis\n  proof (cases \"isReconfiguration (v\\<^sub>c i)\")\n    case False\n\n    have \"\\<And>n. currentNode (nodeState' n) = currentNode (nodeState n)\n      \\<and> currentTerm (nodeState' n) = currentTerm (nodeState n)\n      \\<and> currentVotingNodes (nodeState' n) = currentVotingNodes (nodeState n)\n      \\<and> joinVotes (nodeState' n) = joinVotes (nodeState n)\n      \\<and> electionWon (nodeState' n) = electionWon (nodeState n)\n      \\<and> isQuorum (nodeState' n) = isQuorum (nodeState n)\"\n    proof (cases \"lastAcceptedValue nd\")\n      case NoOp thus \"\\<And>n. ?thesis n\"\n        unfolding nodeState'_def nd' handleApplyCommit_def i t applyAcceptedValue_def isQuorum_def nd_def\n        by simp\n    next\n      case ClusterStateDiff thus \"\\<And>n. ?thesis n\"\n        unfolding nodeState'_def nd' handleApplyCommit_def i t applyAcceptedValue_def isQuorum_def nd_def\n        by simp\n    next\n      case Reconfigure with False lastAcceptedValue_eq show \"\\<And>n. ?thesis n\" by simp\n    qed\n    hence property_simps[simp]:\n      \"\\<And>n. currentNode (nodeState' n) = currentNode (nodeState n)\"\n      \"\\<And>n. currentTerm (nodeState' n) = currentTerm (nodeState n)\"\n      \"\\<And>n. currentVotingNodes (nodeState' n) = currentVotingNodes (nodeState n)\"\n      \"\\<And>n. joinVotes (nodeState' n) = joinVotes (nodeState n)\"\n      \"\\<And>n. electionWon (nodeState' n) = electionWon (nodeState n)\"\n      \"\\<And>n. isQuorum (nodeState' n) = isQuorum (nodeState n)\"\n      by simp_all\n\n    have \"\\<And>n. firstUncommittedSlot (nodeState' n) = (if n = n\\<^sub>0 then Suc (firstUncommittedSlot (nodeState n)) else firstUncommittedSlot (nodeState n))\n     \\<and> publishPermitted (nodeState' n) = (publishPermitted (nodeState n) \\<or> n = n\\<^sub>0)\n     \\<and> publishVotes (nodeState' n) = (if n = n\\<^sub>0 then {} else publishVotes (nodeState n))\n     \\<and> lastAcceptedTerm (nodeState' n) = (if n = n\\<^sub>0 then NO_TERM else lastAcceptedTerm (nodeState n))\"\n    proof (cases \"lastAcceptedValue nd\")\n      case NoOp\n      with i t show \"\\<And>n. ?thesis n\"\n        by (unfold nodeState'_def, auto simp add: lastAcceptedValue_eq nd_def nd' applyAcceptedValue_def isQuorum_def handleApplyCommit_def lastAcceptedTerm_def)\n    next\n      case ClusterStateDiff\n      with i t show \"\\<And>n. ?thesis n\"\n        by (unfold nodeState'_def, auto simp add: lastAcceptedValue_eq nd_def nd' applyAcceptedValue_def isQuorum_def handleApplyCommit_def lastAcceptedTerm_def)\n    next\n      case Reconfigure with False lastAcceptedValue_eq show \"\\<And>n. ?thesis n\" by simp\n    qed\n    hence updated_properties:\n      \"\\<And>n. firstUncommittedSlot (nodeState' n) = (if n = n\\<^sub>0 then Suc (firstUncommittedSlot (nodeState n)) else firstUncommittedSlot (nodeState n)) \"\n      \"\\<And>n. publishPermitted (nodeState' n) = (publishPermitted (nodeState n) \\<or> n = n\\<^sub>0)\"\n      \"\\<And>n. publishVotes (nodeState' n) = (if n = n\\<^sub>0 then {} else publishVotes (nodeState n))\"\n      \"\\<And>n. lastAcceptedTerm (nodeState' n) = (if n = n\\<^sub>0 then NO_TERM else lastAcceptedTerm (nodeState n))\"\n      by simp_all\n\n    show ?thesis\n      apply (intro zenI)\n                          apply (unfold messages' message_simps committedTo_eq V_eq v_eq\n          lastCommittedClusterStateBefore_eq property_simps promised_eq prevAccepted_eq)\n    proof -\n      from finite_messages show \"finite messages\" .\n      from Vote_future show \"\\<And>i i' s t t' a. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> i < i' \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i' t' \\<rangle>\\<leadsto>\".\n      from Vote_None show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t NO_TERM \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n      from Vote_Some_lt show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t\".\n      from Vote_Some_PublishResponse show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n      from Vote_Some_max show \"\\<And>i s t t' t''. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t'' \\<Longrightarrow> t'' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t'' \\<rangle>\\<leadsto>\".\n      from Vote_not_broadcast show \"\\<And>i t a d. \\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> d \\<noteq> Broadcast\".\n      from Vote_unique_destination show \"\\<And>i' i s t a a' d d'. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> s \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<rightarrow> d' \\<Longrightarrow> d = d'\".\n      from currentNode_nodeState show \"\\<And>n. currentNode (nodeState n) = n\" .\n      from Vote_currentTerm show \"\\<And>n i t a. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n      from Vote_slot_function show \"\\<And>n i i' t a a'. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> n \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<leadsto> \\<Longrightarrow> i = i'\".\n      from electionWon_isQuorum show \"\\<And>n. electionWon (nodeState n) \\<Longrightarrow> isQuorum (nodeState n) (joinVotes (nodeState n))\".\n      from PublishRequest_committedTo show \"\\<And>i t x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n      from PublishRequest_quorum show \"\\<And>i s t x. s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). (\\<forall>n\\<in>q. promised i n s t) \\<and> (prevAccepted i t q = {} \\<or> (\\<exists>t'. v i t = v i t' \\<and> maxTerm (prevAccepted i t q) \\<le> t' \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto> \\<and> t' < t))\".\n      from PublishRequest_function show \"\\<And>i t x x'. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<langle> PublishRequest i t x' \\<rangle>\\<leadsto> \\<Longrightarrow> x = x'\".\n      from PublishResponse_PublishRequest show \"\\<And>i s t. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n      from ApplyCommit_quorum show \"\\<And>i t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). \\<forall>s\\<in>q. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\".\n      from CatchUpResponse_committedTo show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n      from CatchUpResponse_V show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> V i = conf\".\n      from CatchUpResponse_lastCommittedClusterStateBefore show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> lastCommittedClusterStateBefore i = cs\".\n\n      fix n\n\n      from firstUncommittedSlot_PublishResponse show \"\\<And>i t. firstUncommittedSlot (nodeState' n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\" \n        using updated_properties by (cases \"n = n\\<^sub>0\", auto)\n\n      from lastAcceptedTerm_None show \"\\<And>i t. lastAcceptedTerm (nodeState' n) = NO_TERM \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState' n)) t \\<rangle>\\<leadsto>\"\n        using updated_properties firstUncommittedSlot_PublishResponse by (cases \"n = n\\<^sub>0\", auto)\n\n      from lastAcceptedTerm_Some_sent show \"\\<And>t. lastAcceptedTerm (nodeState' n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState' n)) t \\<rangle>\\<leadsto>\"\n        using updated_properties by (cases \"n = n\\<^sub>0\", auto)\n\n      from lastAcceptedTerm_Some_max show \"\\<And>t t'. lastAcceptedTerm (nodeState' n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState' n)) t' \\<rangle>\\<leadsto> \\<Longrightarrow> t' \\<le> t\"\n        using updated_properties by (cases \"n = n\\<^sub>0\", auto)\n\n      from lastAcceptedTerm_Some_value show \"\\<And>t. lastAcceptedTerm (nodeState' n) = SomeTerm t \\<Longrightarrow> \\<langle> PublishRequest (firstUncommittedSlot (nodeState' n)) t (lastAcceptedValue (nodeState' n)) \\<rangle>\\<leadsto>\"\n        using updated_properties by (cases \"n = n\\<^sub>0\", auto, simp add: nodeState'_def)\n\n      from lastAcceptedTerm_Some_currentTerm show \"\\<And>t. lastAcceptedTerm (nodeState' n) = SomeTerm t \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\"\n        using updated_properties by (cases \"n = n\\<^sub>0\", auto)\n\n      from committedTo_firstUncommittedSlot show \"committed\\<^sub>< (firstUncommittedSlot (nodeState' n))\"\n        unfolding updated_properties committedTo_def apply (cases \"n = n\\<^sub>0\", auto)\n        using i isCommitted_def less_antisym nd_def sent by blast\n\n      from joinVotes_max show \"\\<And>n' a'. \\<not> (\\<exists>x. \\<langle> PublishRequest (firstUncommittedSlot (nodeState' n)) (currentTerm (nodeState n)) x \\<rangle>\\<leadsto>) \\<Longrightarrow> n' \\<in> joinVotes (nodeState n) \\<Longrightarrow> n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot (nodeState' n)) (currentTerm (nodeState n)) a' \\<rangle>\\<rightarrow> (OneNode n) \\<Longrightarrow> a' \\<le> lastAcceptedTerm (nodeState' n)\"\n        unfolding updated_properties apply (cases \"n = n\\<^sub>0\", auto)\n        using isMessageFromTo_def zen.Vote_slot_function zen.joinVotes zen_axioms by fastforce\n\n      from publishVotes show \"\\<And>n'. n' \\<in> publishVotes (nodeState' n) \\<Longrightarrow> n' \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState' n)) (currentTerm (nodeState n)) \\<rangle>\\<leadsto>\"\n        unfolding updated_properties apply (cases \"n = n\\<^sub>0\", auto) done\n\n      from joinVotes show \"\\<And>n'. n' \\<in> joinVotes (nodeState n) \\<Longrightarrow> promised (firstUncommittedSlot (nodeState' n)) n' n (currentTerm (nodeState n))\"\n        unfolding updated_properties apply (cases \"n = n\\<^sub>0\", auto)\n        by (meson le_SucI promised_def)\n\n      from currentVotingNodes_firstUncommittedSlot show \"\\<And>n. currentVotingNodes (nodeState n) = V (firstUncommittedSlot (nodeState' n))\"\n        unfolding updated_properties using False i nd_def by (cases \"n = n\\<^sub>0\", auto)\n\n      from firstUncommittedSlot_PublishRequest show \"\\<And>i t x. firstUncommittedSlot (nodeState' n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\"\n        unfolding updated_properties apply (cases \"n = n\\<^sub>0\", auto) done\n\n      from PublishRequest_currentTerm show \"\\<And>t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState' n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\"\n        unfolding updated_properties apply (cases \"n = n\\<^sub>0\", auto simp add: firstUncommittedSlot_PublishRequest) done\n\n      from PublishRequest_publishPermitted_currentTerm show \"\\<And>t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState' n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> publishPermitted (nodeState' n) \\<Longrightarrow> t < currentTerm (nodeState n)\"\n        unfolding updated_properties apply (cases \"n = n\\<^sub>0\", auto simp add: firstUncommittedSlot_PublishRequest) done\n\n      from currentClusterState_lastCommittedClusterStateBefore\n      show \"currentClusterState (nodeState' n) = lastCommittedClusterStateBefore (firstUncommittedSlot (nodeState' n))\"\n      proof (cases \"n = n\\<^sub>0\")\n        case False with currentClusterState_lastCommittedClusterStateBefore\n        show ?thesis unfolding nodeState'_def by auto\n      next\n        case True\n        show ?thesis\n        proof (cases \"v\\<^sub>c i\")\n          case NoOp\n          with currentClusterState_lastCommittedClusterStateBefore True lastAcceptedValue_eq i t\n          show ?thesis\n            unfolding nodeState'_def\n            by (simp add: nd' nd_def applyAcceptedValue_def handleApplyCommit_def)\n        next\n          case Reconfigure with False show ?thesis by simp\n        next\n          case (ClusterStateDiff diff)\n          with lastAcceptedValue_eq have \"lastAcceptedValue nd = ClusterStateDiff diff\" by simp\n          with ClusterStateDiff True i t currentClusterState_lastCommittedClusterStateBefore\n          show ?thesis\n            unfolding nodeState'_def\n            by (simp add: nd' nd_def applyAcceptedValue_def handleApplyCommit_def)\n        qed\n      qed\n    qed\n\n  next\n    case True\n    then obtain newConfig where Reconfigure: \"v\\<^sub>c i = Reconfigure newConfig\" by (cases \"v\\<^sub>c i\", auto)\n    with lastAcceptedValue_eq have lastAcceptedValue_eq: \"lastAcceptedValue nd = Reconfigure newConfig\" by simp\n\n    hence property_simps[simp]:\n      \"\\<And>n. currentNode (nodeState' n) = currentNode (nodeState n)\"\n      \"\\<And>n. currentTerm (nodeState' n) = currentTerm (nodeState n)\"\n      \"\\<And>n. currentClusterState (nodeState' n) = currentClusterState (nodeState n)\"\n      \"\\<And>n. joinVotes (nodeState' n) = joinVotes (nodeState n)\"\n      unfolding nodeState'_def by (auto simp add: nd' handleApplyCommit_def applyAcceptedValue_def nd_def\n          lastAcceptedTerm_def firstUncommittedSlot_def lastAcceptedValue_def)\n\n    have updated_properties:\n      \"\\<And>n. firstUncommittedSlot (nodeState' n) = (if n = n\\<^sub>0 then Suc (firstUncommittedSlot (nodeState n)) else firstUncommittedSlot (nodeState n)) \"\n      \"\\<And>n. publishPermitted (nodeState' n) = (publishPermitted (nodeState n) \\<or> n = n\\<^sub>0)\"\n      \"\\<And>n. publishVotes (nodeState' n) = (if n = n\\<^sub>0 then {} else publishVotes (nodeState n))\"\n      \"\\<And>n. currentVotingNodes (nodeState' n) = (if n = n\\<^sub>0 then set newConfig else currentVotingNodes (nodeState n))\"\n      \"\\<And>n. electionWon (nodeState' n) = (if n = n\\<^sub>0 then joinVotes nd \\<in> majorities (set newConfig) else electionWon (nodeState n))\"\n      \"\\<And>n. isQuorum (nodeState' n) = (if n = n\\<^sub>0 then (\\<lambda>q. q \\<in> majorities (set newConfig)) else isQuorum (nodeState n))\"\n      \"\\<And>n. currentVotingNodes (nodeState' n) = (if n = n\\<^sub>0 then set newConfig else currentVotingNodes (nodeState n))\"\n      \"\\<And>n. lastAcceptedTerm (nodeState' n) = (if n = n\\<^sub>0 then NO_TERM else lastAcceptedTerm (nodeState n))\"\n      \"\\<And>n. n \\<noteq> n\\<^sub>0 \\<Longrightarrow> lastAcceptedValue (nodeState' n) = lastAcceptedValue (nodeState n)\"\n      unfolding nodeState'_def using i t lastAcceptedValue_eq\n      by (auto simp add: nd' handleApplyCommit_def applyAcceptedValue_def nd_def isQuorum_def lastAcceptedTerm_def)\n\n    show ?thesis\n      apply (intro zenI)\n                          apply (unfold messages' message_simps committedTo_eq V_eq v_eq\n          lastCommittedClusterStateBefore_eq property_simps promised_eq prevAccepted_eq)\n    proof -\n      from finite_messages show \"finite messages\" .\n      from Vote_future show \"\\<And>i i' s t t' a. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> i < i' \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i' t' \\<rangle>\\<leadsto>\".\n      from Vote_None show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t NO_TERM \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n      from Vote_Some_lt show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t\".\n      from Vote_Some_PublishResponse show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n      from Vote_Some_max show \"\\<And>i s t t' t''. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t'' \\<Longrightarrow> t'' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t'' \\<rangle>\\<leadsto>\".\n      from Vote_not_broadcast show \"\\<And>i t a d. \\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> d \\<noteq> Broadcast\".\n      from Vote_unique_destination show \"\\<And>i' i s t a a' d d'. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> s \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<rightarrow> d' \\<Longrightarrow> d = d'\".\n      from currentNode_nodeState show \"\\<And>n. currentNode (nodeState n) = n\" .\n      from Vote_currentTerm show \"\\<And>n i t a. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n      from Vote_slot_function show \"\\<And>n i i' t a a'. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> n \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<leadsto> \\<Longrightarrow> i = i'\".\n      from PublishRequest_committedTo show \"\\<And>i t x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n      from PublishRequest_quorum show \"\\<And>i s t x. s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). (\\<forall>n\\<in>q. promised i n s t) \\<and> (prevAccepted i t q = {} \\<or> (\\<exists>t'. v i t = v i t' \\<and> maxTerm (prevAccepted i t q) \\<le> t' \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto> \\<and> t' < t))\".\n      from PublishRequest_function show \"\\<And>i t x x'. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<langle> PublishRequest i t x' \\<rangle>\\<leadsto> \\<Longrightarrow> x = x'\".\n      from PublishResponse_PublishRequest show \"\\<And>i s t. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n      from ApplyCommit_quorum show \"\\<And>i t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). \\<forall>s\\<in>q. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\".\n      from CatchUpResponse_committedTo show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n      from CatchUpResponse_V show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> V i = conf\".\n      from CatchUpResponse_lastCommittedClusterStateBefore show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> lastCommittedClusterStateBefore i = cs\".\n\n      fix n\n\n      from firstUncommittedSlot_PublishResponse show \"\\<And>i t. firstUncommittedSlot (nodeState' n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\"\n        using updated_properties by (cases \"n = n\\<^sub>0\", auto)\n\n      from lastAcceptedTerm_None show \"\\<And>i t. lastAcceptedTerm (nodeState' n) = NO_TERM \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState' n)) t \\<rangle>\\<leadsto>\"\n        using updated_properties firstUncommittedSlot_PublishResponse by (cases \"n = n\\<^sub>0\", auto)\n\n      from lastAcceptedTerm_Some_sent show \"\\<And>t. lastAcceptedTerm (nodeState' n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState' n)) t \\<rangle>\\<leadsto>\"\n        using updated_properties by (cases \"n = n\\<^sub>0\", auto)\n\n      from lastAcceptedTerm_Some_max show \"\\<And>t t'. lastAcceptedTerm (nodeState' n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState' n)) t' \\<rangle>\\<leadsto> \\<Longrightarrow> t' \\<le> t\"\n        using updated_properties by (cases \"n = n\\<^sub>0\", auto)\n\n      from lastAcceptedTerm_Some_value show \"\\<And>t. lastAcceptedTerm (nodeState' n) = SomeTerm t \\<Longrightarrow> \\<langle> PublishRequest (firstUncommittedSlot (nodeState' n)) t (lastAcceptedValue (nodeState' n)) \\<rangle>\\<leadsto>\"\n        using updated_properties by (cases \"n = n\\<^sub>0\", auto)\n\n      from committedTo_firstUncommittedSlot show \"committed\\<^sub>< (firstUncommittedSlot (nodeState' n))\"\n        unfolding updated_properties committedTo_def apply (cases \"n = n\\<^sub>0\", auto)\n        using i isCommitted_def less_antisym nd_def sent by blast\n\n      from electionWon_isQuorum show \"\\<And>n. electionWon (nodeState' n) \\<Longrightarrow> isQuorum (nodeState' n) (joinVotes (nodeState n))\"\n        unfolding updated_properties apply (cases \"n = n\\<^sub>0\", auto simp add: nd_def) done\n\n      from joinVotes_max show \"\\<And>n' a'. \\<not> (\\<exists>x. \\<langle> PublishRequest (firstUncommittedSlot (nodeState' n)) (currentTerm (nodeState n)) x \\<rangle>\\<leadsto>) \\<Longrightarrow> n' \\<in> joinVotes (nodeState n) \\<Longrightarrow> n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot (nodeState' n)) (currentTerm (nodeState n)) a' \\<rangle>\\<rightarrow> (OneNode n) \\<Longrightarrow> a' \\<le> lastAcceptedTerm (nodeState' n)\"\n        unfolding updated_properties apply (cases \"n = n\\<^sub>0\", auto)\n        using isMessageFromTo_def zen.Vote_slot_function zen.joinVotes zen_axioms by fastforce\n\n      from publishVotes show \"\\<And>n'. n' \\<in> publishVotes (nodeState' n) \\<Longrightarrow> n' \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState' n)) (currentTerm (nodeState n)) \\<rangle>\\<leadsto>\"\n        unfolding updated_properties apply (cases \"n = n\\<^sub>0\", auto) done\n\n      from joinVotes show \"\\<And>n'. n' \\<in> joinVotes (nodeState n) \\<Longrightarrow> promised (firstUncommittedSlot (nodeState' n)) n' n (currentTerm (nodeState n))\"\n        unfolding updated_properties apply (cases \"n = n\\<^sub>0\", auto)\n        by (meson le_SucI promised_def)\n\n      from firstUncommittedSlot_PublishRequest show \"\\<And>i t x. firstUncommittedSlot (nodeState' n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\"\n        unfolding updated_properties apply (cases \"n = n\\<^sub>0\", auto) done\n\n      from PublishRequest_currentTerm show \"\\<And>t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState' n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\"\n        unfolding updated_properties apply (cases \"n = n\\<^sub>0\", auto simp add: firstUncommittedSlot_PublishRequest) done\n\n      from PublishRequest_publishPermitted_currentTerm show \"\\<And>t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState' n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> publishPermitted (nodeState' n) \\<Longrightarrow> t < currentTerm (nodeState n)\"\n        unfolding updated_properties apply (cases \"n = n\\<^sub>0\", auto simp add: firstUncommittedSlot_PublishRequest) done\n\n      from currentClusterState_lastCommittedClusterStateBefore Reconfigure i nd_def\n      show \"currentClusterState (nodeState n) = lastCommittedClusterStateBefore (firstUncommittedSlot (nodeState' n))\"\n        unfolding updated_properties committedTo_def by (cases \"n = n\\<^sub>0\", auto)\n\n      from currentVotingNodes_firstUncommittedSlot show \"\\<And>n. currentVotingNodes (nodeState' n) = V (firstUncommittedSlot (nodeState' n))\"\n        unfolding updated_properties committedTo_def using Reconfigure i nd_def by (cases \"n = n\\<^sub>0\", auto)\n\n      from lastAcceptedTerm_Some_currentTerm show \"\\<And>t. lastAcceptedTerm (nodeState' n) = SomeTerm t \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\"\n        unfolding updated_properties apply (cases \"n = n\\<^sub>0\", auto) done\n    qed\n  qed\nqed\n\nlemma (in zenStep) handleCatchUpRequest_invariants:\n  fixes s i t\n  defines \"result \\<equiv> handleCatchUpRequest nd\"\n  assumes nd': \"nd' = fst result\"\n  assumes messages': \"messages' = sendTo d\\<^sub>0 result\"\n  shows \"zen messages' nodeState'\"\nproof -\n\n  have result: \"result = (nd, Some (CatchUpResponse (firstUncommittedSlot nd) (currentVotingNodes nd) (currentClusterState nd)))\"\n    by (simp add: result_def handleCatchUpRequest_def)\n\n  have nd'[simp]: \"nd' = nd\" by (simp add: nd' result)\n  have nodeState'[simp]: \"nodeState' = nodeState\" by (intro ext, simp add: nodeState'_def result nd_def)\n\n  have messages': \"messages' = insert \\<lparr> sender = n\\<^sub>0, destination = d\\<^sub>0, payload = CatchUpResponse (firstUncommittedSlot nd) (currentVotingNodes nd) (currentClusterState nd) \\<rparr> messages\"\n    by (simp add: messages' result)\n\n  have message_simps[simp]:\n    \"\\<And>s d i t. (s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s d i t. (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s d i t x. (s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s d i t a. (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t. (\\<langle> PublishResponse i t \\<rangle>\\<rightarrow>' d) = (\\<langle> PublishResponse i t \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t. (\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow>' d) = (\\<langle> ApplyCommit i t \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t x. (\\<langle> PublishRequest i t x \\<rangle>\\<rightarrow>' d) = (\\<langle> PublishRequest i t x \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>d i t a. (\\<langle> Vote i t a \\<rangle>\\<rightarrow>' d) = (\\<langle> Vote i t a \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s i t. (s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>)\"\n    \"\\<And>s i t. (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>)\"\n    \"\\<And>s i t x. (s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>)\"\n    \"\\<And>s i t a. (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto>)\"\n    \"\\<And>i t. (\\<langle> PublishResponse i t \\<rangle>\\<leadsto>') = (\\<langle> PublishResponse i t \\<rangle>\\<leadsto>)\"\n    \"\\<And>i t. (\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>') = (\\<langle> ApplyCommit i t \\<rangle>\\<leadsto>)\"\n    \"\\<And>i t x. (\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>') = (\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>)\"\n    \"\\<And>i t a. (\\<langle> Vote i t a \\<rangle>\\<leadsto>') = (\\<langle> Vote i t a \\<rangle>\\<leadsto>)\"\n    by (unfold isMessageFromTo'_def isMessageTo'_def isMessageFrom'_def isMessage'_def,\n        auto simp add: messages' isMessageFromTo_def isMessageTo_def isMessageFrom_def isMessage_def)\n\n  have CatchUpResponse':\n    \"\\<And>s d i conf cs. (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow> d\n      \\<or> (s, i, conf, cs, d) = (n\\<^sub>0, firstUncommittedSlot nd, currentVotingNodes nd, currentClusterState nd, d\\<^sub>0))\"\n    \"\\<And>d i conf cs. (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow>' d) = (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<rightarrow> d\n      \\<or> (i, conf, cs, d) = (firstUncommittedSlot nd, currentVotingNodes nd, currentClusterState nd, d\\<^sub>0))\"\n    \"\\<And>s i conf cs. (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>\n      \\<or> (s, i, conf, cs) = (n\\<^sub>0, firstUncommittedSlot nd, currentVotingNodes nd, currentClusterState nd))\"\n    \"\\<And>i conf cs. (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>') = (\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>\n      \\<or> (i, conf, cs) = (firstUncommittedSlot nd, currentVotingNodes nd, currentClusterState nd))\"\n    unfolding isMessageFromTo_def isMessageFromTo'_def isMessageFrom_def isMessageFrom'_def isMessageTo_def isMessageTo'_def isMessage_def isMessage'_def\n    by (auto simp add: messages')\n\n  have v_eq[simp]: \"v' = v\" by (intro ext, auto simp add: v'_def v_def)\n  have v\\<^sub>c_eq[simp]: \"v\\<^sub>c' = v\\<^sub>c\" by (intro ext, auto simp add: v\\<^sub>c'_def v\\<^sub>c_def)\n  have isCommitted_eq[simp]: \"isCommitted' = isCommitted\" by (intro ext, auto simp add: isCommitted'_def isCommitted_def)\n  have committedTo_eq[simp]: \"committed\\<^sub><' = committed\\<^sub><\" by (intro ext, auto simp add: committedTo'_def committedTo_def)\n  have V_eq[simp]: \"V' = V\" using v\\<^sub>c_eq V'_def V_def by blast\n  have promised_eq[simp]: \"promised' = promised\" by (intro ext, auto simp add: promised'_def promised_def)\n  have lastCommittedClusterStateBefore_eq[simp]: \"lastCommittedClusterStateBefore' = lastCommittedClusterStateBefore\"\n    unfolding lastCommittedClusterStateBefore_def lastCommittedClusterStateBefore'_def v\\<^sub>c_eq ..\n  have prevAccepted_eq[simp]: \"prevAccepted' = prevAccepted\" by (intro ext, auto simp add: prevAccepted'_def prevAccepted_def)\n\n  show ?thesis\n    apply (intro zenI)\n                        apply (unfold message_simps committedTo_eq V_eq v_eq\n        lastCommittedClusterStateBefore_eq promised_eq prevAccepted_eq nodeState')\n  proof -\n    from finite_messages show \"finite messages'\" by (simp add: messages')\n    from Vote_future show \"\\<And>i i' s t t' a. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> i < i' \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i' t' \\<rangle>\\<leadsto>\".\n    from Vote_None show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t NO_TERM \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_lt show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t\".\n    from Vote_Some_PublishResponse show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_max show \"\\<And>i s t t' t''. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t'' \\<Longrightarrow> t'' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t'' \\<rangle>\\<leadsto>\".\n    from Vote_not_broadcast show \"\\<And>i t a d. \\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> d \\<noteq> Broadcast\".\n    from Vote_unique_destination show \"\\<And>i' i s t a a' d d'. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> s \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<rightarrow> d' \\<Longrightarrow> d = d'\".\n    from currentNode_nodeState show \"\\<And>n. currentNode (nodeState n) = n\" .\n    from committedTo_firstUncommittedSlot show \"\\<And>n. committed\\<^sub>< (firstUncommittedSlot (nodeState n))\" .\n    from firstUncommittedSlot_PublishResponse show \"\\<And>n i t. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\" .\n    from lastAcceptedTerm_None show \"\\<And>n i t. lastAcceptedTerm (nodeState n) = NO_TERM \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_sent show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_max show \"\\<And>n t t'. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t' \\<rangle>\\<leadsto> \\<Longrightarrow> t' \\<le> t\".\n    from Vote_currentTerm show \"\\<And>n i t a. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from Vote_slot_function show \"\\<And>n i i' t a a'. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> n \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<leadsto> \\<Longrightarrow> i = i'\".\n    from electionWon_isQuorum show \"\\<And>n. electionWon (nodeState n) \\<Longrightarrow> isQuorum (nodeState n) (joinVotes (nodeState n))\".\n    from joinVotes_max show \"\\<And>n n' a'. \\<not> (\\<exists>x. \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) x \\<rangle>\\<leadsto>) \\<Longrightarrow> n' \\<in> joinVotes (nodeState n) \\<Longrightarrow> n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) a' \\<rangle>\\<rightarrow> (OneNode n) \\<Longrightarrow> a' \\<le> lastAcceptedTerm (nodeState n)\".\n    from publishVotes show \"\\<And>n n'. n' \\<in> publishVotes (nodeState n) \\<Longrightarrow> n' \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) \\<rangle>\\<leadsto>\".\n    from currentClusterState_lastCommittedClusterStateBefore show \"\\<And>n. currentClusterState (nodeState n) = lastCommittedClusterStateBefore (firstUncommittedSlot (nodeState n))\".\n    from joinVotes show \"\\<And>n n'. n' \\<in> joinVotes (nodeState n) \\<Longrightarrow> promised (firstUncommittedSlot (nodeState n)) n' n (currentTerm (nodeState n))\".\n    from PublishRequest_committedTo show \"\\<And>i t x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from PublishRequest_quorum show \"\\<And>i s t x. s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). (\\<forall>n\\<in>q. promised i n s t) \\<and> (prevAccepted i t q = {} \\<or> (\\<exists>t'. v i t = v i t' \\<and> maxTerm (prevAccepted i t q) \\<le> t' \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto> \\<and> t' < t))\".\n    from PublishRequest_function show \"\\<And>i t x x'. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<langle> PublishRequest i t x' \\<rangle>\\<leadsto> \\<Longrightarrow> x = x'\".\n    from PublishResponse_PublishRequest show \"\\<And>i s t. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from ApplyCommit_quorum show \"\\<And>i t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). \\<forall>s\\<in>q. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\".\n    from currentVotingNodes_firstUncommittedSlot show \"\\<And>n. currentVotingNodes (nodeState n) = V (firstUncommittedSlot (nodeState n))\".\n    from firstUncommittedSlot_PublishRequest show \"\\<And>i n t x. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_value show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t (lastAcceptedValue (nodeState n)) \\<rangle>\\<leadsto>\".\n    from PublishRequest_currentTerm show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from PublishRequest_publishPermitted_currentTerm show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> publishPermitted (nodeState n) \\<Longrightarrow> t < currentTerm (nodeState n)\".\n    from lastAcceptedTerm_Some_currentTerm show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n\n    from CatchUpResponse_committedTo committedTo_firstUncommittedSlot\n    show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>' \\<Longrightarrow> committed\\<^sub>< i\"\n      unfolding CatchUpResponse' nd_def by blast\n\n    from CatchUpResponse_V currentVotingNodes_firstUncommittedSlot\n    show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>' \\<Longrightarrow> V i = conf\"\n      unfolding CatchUpResponse' nd_def isQuorum_def by auto\n\n    from CatchUpResponse_lastCommittedClusterStateBefore currentClusterState_lastCommittedClusterStateBefore\n    show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>' \\<Longrightarrow> lastCommittedClusterStateBefore i = cs\"\n      unfolding CatchUpResponse' nd_def by auto\n  qed\nqed\n\n\nlemma (in zenStep) handleCatchUpResponse_invariants:\n  assumes nd': \"nd' = handleCatchUpResponse i conf cs nd\"\n  assumes messages'[simp]: \"messages' = messages\"\n  assumes sent: \"\\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto>\"\n  shows \"zen messages' nodeState'\"\nproof (cases \"firstUncommittedSlot nd < i\")\n  case False\n  hence nd'[simp]: \"nd' = nd\"\n    by (auto simp add: nd' handleCatchUpResponse_def)\n\n  have nodeState'[simp]: \"nodeState' = nodeState\" unfolding nodeState'_def by (intro ext, simp add: nd_def)\n\n  from zen_axioms show ?thesis unfolding nodeState' by simp\n\nnext\n  case True\n\n  hence nd': \"nd' = nd \\<lparr> firstUncommittedSlot := i\n                , publishPermitted := True\n                , publishVotes := {}\n                , currentVotingNodes := conf\n                , currentClusterState := cs\n                , joinVotes := {}\n                , electionWon := False\n                , lastAcceptedData := None \\<rparr>\"\n    by (simp add: nd', simp add: handleCatchUpResponse_def)\n\n  have message_simps[simp]:\n    \"\\<And>s p d. (s \\<midarrow>\\<langle> p \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> p \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>p d. (\\<langle> p \\<rangle>\\<rightarrow>' d) = (\\<langle> p \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s p. (s \\<midarrow>\\<langle> p \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> p \\<rangle>\\<leadsto>)\"\n    \"\\<And>p. (\\<langle> p \\<rangle>\\<leadsto>') = (\\<langle> p \\<rangle>\\<leadsto>)\"\n    by (unfold isMessageFromTo'_def isMessageTo'_def isMessageFrom'_def isMessage'_def,\n        auto simp add: isMessageFromTo_def isMessageTo_def isMessageFrom_def isMessage_def)\n\n  have v_eq[simp]: \"v' = v\" by (intro ext, auto simp add: v'_def v_def)\n  have v\\<^sub>c_eq[simp]: \"v\\<^sub>c' = v\\<^sub>c\" by (intro ext, auto simp add: v\\<^sub>c'_def v\\<^sub>c_def)\n  have isCommitted_eq[simp]: \"isCommitted' = isCommitted\" by (intro ext, auto simp add: isCommitted'_def isCommitted_def)\n  have committedTo_eq[simp]: \"committed\\<^sub><' = committed\\<^sub><\" by (intro ext, auto simp add: committedTo'_def committedTo_def)\n  have V_eq[simp]: \"V' = V\" using v\\<^sub>c_eq V'_def V_def by blast\n  have promised_eq[simp]: \"promised' = promised\" by (intro ext, auto simp add: promised'_def promised_def)\n  have lastCommittedClusterStateBefore_eq[simp]: \"lastCommittedClusterStateBefore' = lastCommittedClusterStateBefore\"\n    unfolding lastCommittedClusterStateBefore_def lastCommittedClusterStateBefore'_def v\\<^sub>c_eq ..\n  have prevAccepted_eq[simp]: \"prevAccepted' = prevAccepted\" by (intro ext, auto simp add: prevAccepted'_def prevAccepted_def)\n\n  have property_simps[simp]:\n    \"\\<And>n. currentNode (nodeState' n) = currentNode (nodeState n)\"\n    \"\\<And>n. currentTerm (nodeState' n) = currentTerm (nodeState n)\"\n    unfolding nodeState'_def by (auto simp add: nd' nd_def lastAcceptedTerm_def firstUncommittedSlot_def lastAcceptedValue_def)\n\n  have updated_properties:\n    \"\\<And>n. firstUncommittedSlot (nodeState' n) = (if n = n\\<^sub>0 then i else firstUncommittedSlot (nodeState n)) \"\n    \"\\<And>n. publishPermitted (nodeState' n) = (publishPermitted (nodeState n) \\<or> n = n\\<^sub>0)\"\n    \"\\<And>n. publishVotes (nodeState' n) = (if n = n\\<^sub>0 then {} else publishVotes (nodeState n))\"\n    \"\\<And>n. currentVotingNodes (nodeState' n) = (if n = n\\<^sub>0 then conf else currentVotingNodes (nodeState n))\"\n    \"\\<And>n. joinVotes (nodeState' n) = (if n = n\\<^sub>0 then {} else joinVotes (nodeState n))\"\n    \"\\<And>n. electionWon (nodeState' n) = (electionWon (nodeState n) \\<and> n \\<noteq> n\\<^sub>0)\"\n    \"\\<And>n. currentVotingNodes (nodeState' n) = (if n = n\\<^sub>0 then conf else currentVotingNodes (nodeState n))\"\n    \"\\<And>n. isQuorum (nodeState' n) = (if n = n\\<^sub>0 then (\\<lambda>q. q \\<in> majorities conf) else isQuorum (nodeState n))\"\n    \"\\<And>n. currentClusterState (nodeState' n) = (if n = n\\<^sub>0 then cs else currentClusterState (nodeState n))\"\n    unfolding nodeState'_def\n    by (auto simp add: nd' nd_def isQuorum_def)\n\n  have \"\\<And>n. lastAcceptedTerm (nodeState' n) = (if n = n\\<^sub>0 then NO_TERM else lastAcceptedTerm (nodeState n))\"\n    using True unfolding lastAcceptedTerm_def updated_properties property_simps nd_def\n    using not_le by (simp add: nodeState'_def nd')\n  note updated_properties = updated_properties this\n\n  show ?thesis\n    apply (intro zenI)\n                        apply (unfold messages' message_simps committedTo_eq V_eq v_eq\n        lastCommittedClusterStateBefore_eq property_simps promised_eq prevAccepted_eq)\n  proof -\n    from finite_messages show \"finite messages\" .\n    from Vote_future show \"\\<And>i i' s t t' a. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> i < i' \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i' t' \\<rangle>\\<leadsto>\".\n    from Vote_None show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t NO_TERM \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_lt show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t\".\n    from Vote_Some_PublishResponse show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_max show \"\\<And>i s t t' t''. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t'' \\<Longrightarrow> t'' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t'' \\<rangle>\\<leadsto>\".\n    from Vote_not_broadcast show \"\\<And>i t a d. \\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> d \\<noteq> Broadcast\".\n    from Vote_unique_destination show \"\\<And>i' i s t a a' d d'. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> s \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<rightarrow> d' \\<Longrightarrow> d = d'\".\n    from currentNode_nodeState show \"\\<And>n. currentNode (nodeState n) = n\" .\n    from Vote_currentTerm show \"\\<And>n i t a. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from Vote_slot_function show \"\\<And>n i i' t a a'. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> n \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<leadsto> \\<Longrightarrow> i = i'\".\n    from PublishRequest_committedTo show \"\\<And>i t x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from PublishRequest_quorum show \"\\<And>i s t x. s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). (\\<forall>n\\<in>q. promised i n s t) \\<and> (prevAccepted i t q = {} \\<or> (\\<exists>t'. v i t = v i t' \\<and> maxTerm (prevAccepted i t q) \\<le> t' \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto> \\<and> t' < t))\".\n    from PublishRequest_function show \"\\<And>i t x x'. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<langle> PublishRequest i t x' \\<rangle>\\<leadsto> \\<Longrightarrow> x = x'\".\n    from PublishResponse_PublishRequest show \"\\<And>i s t. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from ApplyCommit_quorum show \"\\<And>i t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). \\<forall>s\\<in>q. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\".\n    from CatchUpResponse_committedTo show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from CatchUpResponse_V show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> V i = conf\".\n    from CatchUpResponse_lastCommittedClusterStateBefore show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> lastCommittedClusterStateBefore i = cs\".\n\n    from committedTo_firstUncommittedSlot show \"\\<And>n. committed\\<^sub>< (firstUncommittedSlot (nodeState' n))\"\n      unfolding updated_properties apply auto\n      using CatchUpResponse_committedTo sent by blast\n\n    from electionWon_isQuorum show \"\\<And>n. electionWon (nodeState' n) \\<Longrightarrow> isQuorum (nodeState' n) (joinVotes (nodeState' n))\"\n      unfolding updated_properties apply auto done\n\n    from joinVotes_max show \"\\<And>n n' a'. \\<not> (\\<exists>x. \\<langle> PublishRequest (firstUncommittedSlot (nodeState' n)) (currentTerm (nodeState n)) x \\<rangle>\\<leadsto>) \\<Longrightarrow> n' \\<in> joinVotes (nodeState' n) \\<Longrightarrow> n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot (nodeState' n)) (currentTerm (nodeState n)) a' \\<rangle>\\<rightarrow> (OneNode n) \\<Longrightarrow> a' \\<le> lastAcceptedTerm (nodeState' n)\"\n      unfolding updated_properties apply auto done\n\n    from publishVotes show \"\\<And>n n'. n' \\<in> publishVotes (nodeState' n) \\<Longrightarrow> n' \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState' n)) (currentTerm (nodeState n)) \\<rangle>\\<leadsto>\"\n      unfolding updated_properties apply auto done\n\n    from joinVotes show \"\\<And>n n'. n' \\<in> joinVotes (nodeState' n) \\<Longrightarrow> promised (firstUncommittedSlot (nodeState' n)) n' n (currentTerm (nodeState n))\"\n      unfolding updated_properties apply auto done\n\n    fix n\n\n    from firstUncommittedSlot_PublishRequest show \"\\<And>i t x. firstUncommittedSlot (nodeState' n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\"\n      unfolding updated_properties using True nd_def by (cases \"n = n\\<^sub>0\", auto)\n\n    from PublishRequest_currentTerm show \"\\<And>t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState' n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\"\n      unfolding updated_properties apply (cases \"n = n\\<^sub>0\", auto)\n      using True firstUncommittedSlot_PublishRequest nd_def by blast\n\n    from PublishRequest_publishPermitted_currentTerm show \"\\<And>t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState' n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> publishPermitted (nodeState' n) \\<Longrightarrow> t < currentTerm (nodeState n)\"\n      unfolding updated_properties apply (cases \"n = n\\<^sub>0\", auto)\n      using True firstUncommittedSlot_PublishRequest nd_def by blast\n\n    from currentClusterState_lastCommittedClusterStateBefore show \"currentClusterState (nodeState' n) = lastCommittedClusterStateBefore (firstUncommittedSlot (nodeState' n))\"\n      unfolding updated_properties apply (cases \"n = n\\<^sub>0\", auto)\n      using CatchUpResponse_lastCommittedClusterStateBefore sent by blast\n\n    from currentVotingNodes_firstUncommittedSlot show \"\\<And>n. currentVotingNodes (nodeState' n) = V (firstUncommittedSlot (nodeState' n))\"\n      unfolding updated_properties using CatchUpResponse_V sent by (cases \"n = n\\<^sub>0\", auto)\n\n    from firstUncommittedSlot_PublishResponse show \"\\<And>i t. firstUncommittedSlot (nodeState' n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\" \n      unfolding updated_properties apply (cases \"n = n\\<^sub>0\", auto)\n      using True dual_order.strict_trans nd_def by blast\n\n    from lastAcceptedTerm_None show \"\\<And>i t. lastAcceptedTerm (nodeState' n) = NO_TERM \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState' n)) t \\<rangle>\\<leadsto>\"\n      unfolding updated_properties apply (cases \"n = n\\<^sub>0\", auto)\n      using True firstUncommittedSlot_PublishResponse nd_def by blast\n\n    from lastAcceptedTerm_Some_sent show \"\\<And>t. lastAcceptedTerm (nodeState' n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState' n)) t \\<rangle>\\<leadsto>\"\n      unfolding updated_properties by (cases \"n = n\\<^sub>0\", auto)\n\n    from lastAcceptedTerm_Some_max show \"\\<And>t t'. lastAcceptedTerm (nodeState' n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState' n)) t' \\<rangle>\\<leadsto> \\<Longrightarrow> t' \\<le> t\" \n      unfolding updated_properties by (cases \"n = n\\<^sub>0\", auto)\n\n    from lastAcceptedTerm_Some_value show \"\\<And>t. lastAcceptedTerm (nodeState' n) = SomeTerm t \\<Longrightarrow> \\<langle> PublishRequest (firstUncommittedSlot (nodeState' n)) t (lastAcceptedValue (nodeState' n)) \\<rangle>\\<leadsto>\" \n      unfolding updated_properties lastAcceptedValue_def by (cases \"n = n\\<^sub>0\", auto simp add: nodeState'_def)\n\n    from lastAcceptedTerm_Some_currentTerm show \"\\<And>t. lastAcceptedTerm (nodeState' n) = SomeTerm t \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\" \n      unfolding updated_properties by (cases \"n = n\\<^sub>0\", auto)\n  qed\nqed\n\nlemma (in zenStep) handleDiscardJoinVotes_invariants:\n  assumes nd': \"nd' = handleDiscardJoinVotes nd\"\n  assumes messages': \"messages' = messages\"\n  shows \"zen messages' nodeState'\"\nproof -\n  have message_simps[simp]:\n    \"\\<And>s p d. (s \\<midarrow>\\<langle> p \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> p \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>p d. (\\<langle> p \\<rangle>\\<rightarrow>' d) = (\\<langle> p \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s p. (s \\<midarrow>\\<langle> p \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> p \\<rangle>\\<leadsto>)\"\n    \"\\<And>p. (\\<langle> p \\<rangle>\\<leadsto>') = (\\<langle> p \\<rangle>\\<leadsto>)\"\n    by (unfold isMessageFromTo'_def isMessageTo'_def isMessageFrom'_def isMessage'_def,\n        auto simp add: messages' isMessageFromTo_def isMessageTo_def isMessageFrom_def isMessage_def)\n\n  have property_simps[simp]:\n    \"\\<And>n. currentNode (nodeState' n) = currentNode (nodeState n)\"\n    \"\\<And>n. firstUncommittedSlot (nodeState' n) = firstUncommittedSlot (nodeState n)\"\n    \"\\<And>n. currentVotingNodes (nodeState' n) = currentVotingNodes (nodeState n)\"\n    \"\\<And>n q. isQuorum (nodeState' n) q = isQuorum (nodeState n) q\"\n    \"\\<And>n. lastAcceptedTerm (nodeState' n) = lastAcceptedTerm (nodeState n)\"\n    \"\\<And>n. lastAcceptedValue (nodeState' n) = lastAcceptedValue (nodeState n)\"\n    \"\\<And>n. currentTerm (nodeState' n) = currentTerm (nodeState n)\"\n    \"\\<And>n. currentClusterState (nodeState' n) = currentClusterState (nodeState n)\"\n    \"\\<And>n. publishPermitted (nodeState' n) = publishPermitted (nodeState n)\"\n    \"\\<And>n. publishVotes (nodeState' n) = publishVotes (nodeState n)\"\n    by (unfold nodeState'_def, auto simp add: nd_def isQuorum_def nd' handleDiscardJoinVotes_def Let_def\n        lastAcceptedValue_def lastAcceptedTerm_def)\n\n  have updated_properties:\n    \"\\<And>n. joinVotes (nodeState' n) = (if n = n\\<^sub>0 then {} else joinVotes (nodeState n))\"\n    \"\\<And>n. electionWon (nodeState' n) = (electionWon (nodeState n) \\<and> n \\<noteq> n\\<^sub>0)\"\n    by (unfold nodeState'_def, auto simp add: nd' nd_def handleDiscardJoinVotes_def)\n\n  have v_eq[simp]: \"v' = v\" by (intro ext, auto simp add: v'_def v_def)\n  have v\\<^sub>c_eq[simp]: \"v\\<^sub>c' = v\\<^sub>c\" by (intro ext, auto simp add: v\\<^sub>c'_def v\\<^sub>c_def)\n  have isCommitted_eq[simp]: \"isCommitted' = isCommitted\" by (intro ext, auto simp add: isCommitted'_def isCommitted_def)\n  have committedTo_eq[simp]: \"committed\\<^sub><' = committed\\<^sub><\" by (intro ext, auto simp add: committedTo'_def committedTo_def)\n  have V_eq[simp]: \"V' = V\" using v\\<^sub>c_eq V'_def V_def by blast\n  have promised_eq[simp]: \"promised' = promised\" by (intro ext, auto simp add: promised'_def promised_def)\n  have lastCommittedClusterStateBefore_eq[simp]: \"lastCommittedClusterStateBefore' = lastCommittedClusterStateBefore\"\n    unfolding lastCommittedClusterStateBefore_def lastCommittedClusterStateBefore'_def v\\<^sub>c_eq ..\n  have prevAccepted_eq[simp]: \"prevAccepted' = prevAccepted\" by (intro ext, auto simp add: prevAccepted'_def prevAccepted_def)\n\n  show ?thesis\n    apply (intro zenI)\n                        apply (unfold message_simps committedTo_eq V_eq v_eq\n        lastCommittedClusterStateBefore_eq property_simps promised_eq prevAccepted_eq)\n  proof -\n    from finite_messages show \"finite messages'\" by (simp add: messages')\n    from Vote_future show \"\\<And>i i' s t t' a. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> i < i' \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i' t' \\<rangle>\\<leadsto>\".\n    from Vote_None show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t NO_TERM \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_lt show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t\".\n    from Vote_Some_PublishResponse show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_max show \"\\<And>i s t t' t''. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t'' \\<Longrightarrow> t'' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t'' \\<rangle>\\<leadsto>\".\n    from Vote_not_broadcast show \"\\<And>i t a d. \\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> d \\<noteq> Broadcast\".\n    from Vote_unique_destination show \"\\<And>i' i s t a a' d d'. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> s \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<rightarrow> d' \\<Longrightarrow> d = d'\".\n    from currentNode_nodeState show \"\\<And>n. currentNode (nodeState n) = n\" .\n    from committedTo_firstUncommittedSlot show \"\\<And>n. committed\\<^sub>< (firstUncommittedSlot (nodeState n))\" .\n    from firstUncommittedSlot_PublishResponse show \"\\<And>n i t. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\" .\n    from lastAcceptedTerm_None show \"\\<And>n i t. lastAcceptedTerm (nodeState n) = NO_TERM \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_sent show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\" .\n    from lastAcceptedTerm_Some_max show \"\\<And>n t t'. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t' \\<rangle>\\<leadsto> \\<Longrightarrow> t' \\<le> t\" .\n    from lastAcceptedTerm_Some_value show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t (lastAcceptedValue (nodeState n)) \\<rangle>\\<leadsto>\" .\n    from Vote_currentTerm show \"\\<And>n i t a. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from Vote_slot_function show \"\\<And>n i i' t a a'. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> n \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<leadsto> \\<Longrightarrow> i = i'\".\n    from currentClusterState_lastCommittedClusterStateBefore show \"\\<And>n. currentClusterState (nodeState n) = lastCommittedClusterStateBefore (firstUncommittedSlot (nodeState n))\".\n    from PublishRequest_committedTo show \"\\<And>i t x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from PublishRequest_quorum show \"\\<And>i s t x. s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). (\\<forall>n\\<in>q. promised i n s t) \\<and> (prevAccepted i t q = {} \\<or> (\\<exists>t'. v i t = v i t' \\<and> maxTerm (prevAccepted i t q) \\<le> t' \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto> \\<and> t' < t))\".\n    from PublishRequest_function show \"\\<And>i t x x'. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<langle> PublishRequest i t x' \\<rangle>\\<leadsto> \\<Longrightarrow> x = x'\".\n    from PublishResponse_PublishRequest show \"\\<And>i s t. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from ApplyCommit_quorum show \"\\<And>i t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). \\<forall>s\\<in>q. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\".\n    from currentVotingNodes_firstUncommittedSlot show \"\\<And>n. currentVotingNodes (nodeState n) = V (firstUncommittedSlot (nodeState n))\".\n    from firstUncommittedSlot_PublishRequest show \"\\<And>i n t x. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from PublishRequest_currentTerm show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from CatchUpResponse_committedTo show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from CatchUpResponse_V show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> V i = conf\".\n    from CatchUpResponse_lastCommittedClusterStateBefore show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> lastCommittedClusterStateBefore i = cs\".\n    from lastAcceptedTerm_Some_currentTerm show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from PublishRequest_publishPermitted_currentTerm show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> publishPermitted (nodeState n) \\<Longrightarrow> t < currentTerm (nodeState n)\".\n    from publishVotes show \"\\<And>n n'. n' \\<in> publishVotes (nodeState n) \\<Longrightarrow> n' \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) \\<rangle>\\<leadsto>\".\n\n    from electionWon_isQuorum show \"\\<And>n. electionWon (nodeState' n) \\<Longrightarrow> isQuorum (nodeState n) (joinVotes (nodeState' n))\"\n      unfolding updated_properties by simp\n\n    fix n\n\n    from joinVotes show \"\\<And>n'. n' \\<in> joinVotes (nodeState' n) \\<Longrightarrow> promised (firstUncommittedSlot (nodeState n)) n' n (currentTerm (nodeState n))\"\n      unfolding updated_properties by (cases \"n = n\\<^sub>0\", simp_all)\n    from joinVotes_max show \"\\<And>n' a'. \\<not> (\\<exists>x. \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) x \\<rangle>\\<leadsto>) \\<Longrightarrow> n' \\<in> joinVotes (nodeState' n) \\<Longrightarrow> n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) a' \\<rangle>\\<rightarrow> (OneNode n) \\<Longrightarrow> a' \\<le> lastAcceptedTerm (nodeState n)\"\n      unfolding updated_properties by (cases \"n = n\\<^sub>0\", simp_all)\n  qed\nqed\n\nlemma (in zenStep) handleReboot_invariants:\n  assumes nd': \"nd' = handleReboot nd\"\n  assumes messages': \"messages' = messages\"\n  shows \"zen messages' nodeState'\"\nproof -\n  have message_simps[simp]:\n    \"\\<And>s p d. (s \\<midarrow>\\<langle> p \\<rangle>\\<rightarrow>' d) = (s \\<midarrow>\\<langle> p \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>p d. (\\<langle> p \\<rangle>\\<rightarrow>' d) = (\\<langle> p \\<rangle>\\<rightarrow> d)\"\n    \"\\<And>s p. (s \\<midarrow>\\<langle> p \\<rangle>\\<leadsto>') = (s \\<midarrow>\\<langle> p \\<rangle>\\<leadsto>)\"\n    \"\\<And>p. (\\<langle> p \\<rangle>\\<leadsto>') = (\\<langle> p \\<rangle>\\<leadsto>)\"\n    by (unfold isMessageFromTo'_def isMessageTo'_def isMessageFrom'_def isMessage'_def,\n        auto simp add: messages' isMessageFromTo_def isMessageTo_def isMessageFrom_def isMessage_def)\n\n  have property_simps[simp]:\n    \"\\<And>n. currentNode (nodeState' n) = currentNode (nodeState n)\"\n    \"\\<And>n. firstUncommittedSlot (nodeState' n) = firstUncommittedSlot (nodeState n)\"\n    \"\\<And>n. currentVotingNodes (nodeState' n) = currentVotingNodes (nodeState n)\"\n    \"\\<And>n q. isQuorum (nodeState' n) q = isQuorum (nodeState n) q\"\n    \"\\<And>n. lastAcceptedTerm (nodeState' n) = lastAcceptedTerm (nodeState n)\"\n    \"\\<And>n. lastAcceptedValue (nodeState' n) = lastAcceptedValue (nodeState n)\"\n    \"\\<And>n. currentTerm (nodeState' n) = currentTerm (nodeState n)\"\n    \"\\<And>n. currentClusterState (nodeState' n) = currentClusterState (nodeState n)\"\n    by (unfold nodeState'_def, auto simp add: nd_def isQuorum_def nd' handleReboot_def Let_def\n        lastAcceptedValue_def lastAcceptedTerm_def)\n\n  have updated_properties:\n    \"\\<And>n. publishPermitted (nodeState' n) = (publishPermitted (nodeState n) \\<and> n \\<noteq> n\\<^sub>0)\"\n    \"\\<And>n. joinVotes (nodeState' n) = (if n = n\\<^sub>0 then {} else joinVotes (nodeState n))\"\n    \"\\<And>n. electionWon (nodeState' n) = (electionWon (nodeState n) \\<and> n \\<noteq> n\\<^sub>0)\"\n    \"\\<And>n. publishVotes (nodeState' n) = (if n = n\\<^sub>0 then {} else publishVotes (nodeState n))\"\n    by (unfold nodeState'_def, auto simp add: nd' nd_def handleReboot_def)\n\n  have v_eq[simp]: \"v' = v\" by (intro ext, auto simp add: v'_def v_def)\n  have v\\<^sub>c_eq[simp]: \"v\\<^sub>c' = v\\<^sub>c\" by (intro ext, auto simp add: v\\<^sub>c'_def v\\<^sub>c_def)\n  have isCommitted_eq[simp]: \"isCommitted' = isCommitted\" by (intro ext, auto simp add: isCommitted'_def isCommitted_def)\n  have committedTo_eq[simp]: \"committed\\<^sub><' = committed\\<^sub><\" by (intro ext, auto simp add: committedTo'_def committedTo_def)\n  have V_eq[simp]: \"V' = V\" using v\\<^sub>c_eq V'_def V_def by blast\n  have promised_eq[simp]: \"promised' = promised\" by (intro ext, auto simp add: promised'_def promised_def)\n  have lastCommittedClusterStateBefore_eq[simp]: \"lastCommittedClusterStateBefore' = lastCommittedClusterStateBefore\"\n    unfolding lastCommittedClusterStateBefore_def lastCommittedClusterStateBefore'_def v\\<^sub>c_eq ..\n  have prevAccepted_eq[simp]: \"prevAccepted' = prevAccepted\" by (intro ext, auto simp add: prevAccepted'_def prevAccepted_def)\n\n  show ?thesis\n    apply (intro zenI)\n                        apply (unfold message_simps committedTo_eq V_eq v_eq\n        lastCommittedClusterStateBefore_eq property_simps promised_eq prevAccepted_eq)\n  proof -\n    from finite_messages show \"finite messages'\" by (simp add: messages')\n    from Vote_future show \"\\<And>i i' s t t' a. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> i < i' \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i' t' \\<rangle>\\<leadsto>\".\n    from Vote_None show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t NO_TERM \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_lt show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t\".\n    from Vote_Some_PublishResponse show \"\\<And>i s t t'. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> s \\<midarrow>\\<langle> PublishResponse i t' \\<rangle>\\<leadsto>\".\n    from Vote_Some_max show \"\\<And>i s t t' t''. s \\<midarrow>\\<langle> Vote i t (SomeTerm t') \\<rangle>\\<leadsto> \\<Longrightarrow> t' < t'' \\<Longrightarrow> t'' < t \\<Longrightarrow> \\<not> s \\<midarrow>\\<langle> PublishResponse i t'' \\<rangle>\\<leadsto>\".\n    from Vote_not_broadcast show \"\\<And>i t a d. \\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> d \\<noteq> Broadcast\".\n    from Vote_unique_destination show \"\\<And>i' i s t a a' d d'. s \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> d \\<Longrightarrow> s \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<rightarrow> d' \\<Longrightarrow> d = d'\".\n    from currentNode_nodeState show \"\\<And>n. currentNode (nodeState n) = n\" .\n    from committedTo_firstUncommittedSlot show \"\\<And>n. committed\\<^sub>< (firstUncommittedSlot (nodeState n))\" .\n    from firstUncommittedSlot_PublishResponse show \"\\<And>n i t. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\" .\n    from lastAcceptedTerm_None show \"\\<And>n i t. lastAcceptedTerm (nodeState n) = NO_TERM \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\".\n    from lastAcceptedTerm_Some_sent show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t \\<rangle>\\<leadsto>\" .\n    from lastAcceptedTerm_Some_max show \"\\<And>n t t'. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> n \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) t' \\<rangle>\\<leadsto> \\<Longrightarrow> t' \\<le> t\" .\n    from lastAcceptedTerm_Some_value show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t (lastAcceptedValue (nodeState n)) \\<rangle>\\<leadsto>\" .\n    from Vote_currentTerm show \"\\<And>n i t a. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from Vote_slot_function show \"\\<And>n i i' t a a'. n \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<leadsto> \\<Longrightarrow> n \\<midarrow>\\<langle> Vote i' t a' \\<rangle>\\<leadsto> \\<Longrightarrow> i = i'\".\n    from currentClusterState_lastCommittedClusterStateBefore show \"\\<And>n. currentClusterState (nodeState n) = lastCommittedClusterStateBefore (firstUncommittedSlot (nodeState n))\".\n    from PublishRequest_committedTo show \"\\<And>i t x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from PublishRequest_quorum show \"\\<And>i s t x. s \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). (\\<forall>n\\<in>q. promised i n s t) \\<and> (prevAccepted i t q = {} \\<or> (\\<exists>t'. v i t = v i t' \\<and> maxTerm (prevAccepted i t q) \\<le> t' \\<and> \\<langle> PublishResponse i t' \\<rangle>\\<leadsto> \\<and> t' < t))\".\n    from PublishRequest_function show \"\\<And>i t x x'. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto> \\<Longrightarrow> \\<langle> PublishRequest i t x' \\<rangle>\\<leadsto> \\<Longrightarrow> x = x'\".\n    from PublishResponse_PublishRequest show \"\\<And>i s t. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>x. \\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from ApplyCommit_quorum show \"\\<And>i t. \\<langle> ApplyCommit i t \\<rangle>\\<leadsto> \\<Longrightarrow> \\<exists>q\\<in>majorities (V i). \\<forall>s\\<in>q. s \\<midarrow>\\<langle> PublishResponse i t \\<rangle>\\<leadsto>\".\n    from currentVotingNodes_firstUncommittedSlot show \"\\<And>n. currentVotingNodes (nodeState n) = V (firstUncommittedSlot (nodeState n))\".\n    from firstUncommittedSlot_PublishRequest show \"\\<And>i n t x. firstUncommittedSlot (nodeState n) < i \\<Longrightarrow> \\<not> n \\<midarrow>\\<langle> PublishRequest i t x \\<rangle>\\<leadsto>\".\n    from PublishRequest_currentTerm show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n    from CatchUpResponse_committedTo show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> committed\\<^sub>< i\".\n    from CatchUpResponse_V show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> V i = conf\".\n    from CatchUpResponse_lastCommittedClusterStateBefore show \"\\<And>i conf cs. \\<langle> CatchUpResponse i conf cs \\<rangle>\\<leadsto> \\<Longrightarrow> lastCommittedClusterStateBefore i = cs\".\n    from lastAcceptedTerm_Some_currentTerm show \"\\<And>n t. lastAcceptedTerm (nodeState n) = SomeTerm t \\<Longrightarrow> t \\<le> currentTerm (nodeState n)\".\n\n    from electionWon_isQuorum show \"\\<And>n. electionWon (nodeState' n) \\<Longrightarrow> isQuorum (nodeState n) (joinVotes (nodeState' n))\"\n      unfolding updated_properties by simp\n    from PublishRequest_publishPermitted_currentTerm show \"\\<And>n t x. n \\<midarrow>\\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) t x \\<rangle>\\<leadsto> \\<Longrightarrow> publishPermitted (nodeState' n) \\<Longrightarrow> t < currentTerm (nodeState n)\"\n      unfolding updated_properties by simp\n\n    fix n\n\n    from joinVotes show \"\\<And>n'. n' \\<in> joinVotes (nodeState' n) \\<Longrightarrow> promised (firstUncommittedSlot (nodeState n)) n' n (currentTerm (nodeState n))\"\n      unfolding updated_properties by (cases \"n = n\\<^sub>0\", simp_all)\n    from publishVotes show \"\\<And>n'. n' \\<in> publishVotes (nodeState' n) \\<Longrightarrow> n' \\<midarrow>\\<langle> PublishResponse (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) \\<rangle>\\<leadsto>\"\n      unfolding updated_properties by (cases \"n = n\\<^sub>0\", simp_all)\n    from joinVotes_max show \"\\<And>n' a'. \\<not> (\\<exists>x. \\<langle> PublishRequest (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) x \\<rangle>\\<leadsto>) \\<Longrightarrow> n' \\<in> joinVotes (nodeState' n) \\<Longrightarrow> n' \\<midarrow>\\<langle> Vote (firstUncommittedSlot (nodeState n)) (currentTerm (nodeState n)) a' \\<rangle>\\<rightarrow> (OneNode n) \\<Longrightarrow> a' \\<le> lastAcceptedTerm (nodeState n)\"\n      unfolding updated_properties by (cases \"n = n\\<^sub>0\", simp_all)\n  qed\nqed\n\nfun insertOption :: \"RoutedMessage option \\<Rightarrow> RoutedMessage set \\<Rightarrow> RoutedMessage set\"\n  where\n    \"insertOption None = id\"\n  | \"insertOption (Some m) = insert m\"\n\nlemma currentNode_ensureCurrentTerm[simp]: \"currentNode (ensureCurrentTerm t nd) = currentNode nd\"\n  by (auto simp add: ensureCurrentTerm_def)\n\nlemma currentNode_publishValue[simp]: \"currentNode (fst (publishValue x nd)) = currentNode nd\"\n  by (auto simp add: publishValue_def)\n\nlemma currentNode_addElectionVote[simp]: \"currentNode (addElectionVote s i a nd) = currentNode nd\"\n  by (auto simp add: addElectionVote_def Let_def)\n\nlemma currentNode_handleVote[simp]: \"currentNode (fst (handleVote s i t a nd)) = currentNode nd\"\n  by (auto simp add: handleVote_def Let_def)\n\ntext \\<open>\\pagebreak\\<close>\n\nlemma initial_state_satisfies_invariants:\n  shows \"zen {} initialNodeState\"\n  by (unfold_locales, simp_all add: initialNodeState_def isQuorum_def\n      lastAcceptedTerm_def lastAcceptedValue_def)\n\nlemma (in zen) invariants_preserved_by_ProcessMessage:\n  fixes n\\<^sub>0\n  assumes \"m \\<in> messages\"\n  defines \"nd \\<equiv> nodeState n\\<^sub>0\"\n  defines \"result \\<equiv> ProcessMessage nd m\"\n  defines \"nodeState' \\<equiv> \\<lambda>n. if n = n\\<^sub>0 then (fst result) else nodeState n\"\n  defines \"messages' \\<equiv> insertOption (snd result) messages\"\n  shows \"zen messages' nodeState'\"\nproof -\n  {\n    assume r: \"result = (nd, None)\"\n    from r have \"nodeState' = nodeState\"\n      by (auto simp add: nodeState'_def nd_def)\n    moreover from r have \"messages' = messages\" by (simp add: messages'_def)\n    ultimately have \"zen messages' nodeState'\"\n      using zen_axioms by blast\n  }\n  note noop = this\n\n  from `m \\<in> messages`\n  have m: \"(sender m) \\<midarrow>\\<langle> payload m \\<rangle>\\<rightarrow> (destination m)\"\n    by (cases m, auto simp add: isMessageFromTo_def)\n\n  have currentNode[simp]: \"currentNode nd = n\\<^sub>0\" \"\\<And>n. currentNode (nodeState n) = n\"\n    by (simp_all add: nd_def currentNode_nodeState)\n\n  have zenStep: \"zenStep messages nodeState messages' nodeState' n\\<^sub>0\"\n  proof (intro_locales, intro zenStep_axioms.intro)\n    show \"messages \\<subseteq> messages'\"\n      by (cases \"snd result\", auto simp add: messages'_def)\n  qed (simp add: nodeState'_def)\n\n  have [simp]: \"nodeState n\\<^sub>0 = nd\" by (simp add: nd_def)\n\n  define broadcast' :: \"(NodeData * Message option) \\<Rightarrow> (NodeData * RoutedMessage option)\" where\n    \"\\<And>p. broadcast' p \\<equiv> case p of\n            (nd, Some m') \\<Rightarrow> (nd, Some \\<lparr>sender = currentNode nd,\n                                   destination = Broadcast,\n                                   payload = m' \\<rparr>)\n            | (nd, None) \\<Rightarrow> (nd, None)\"\n\n  define respond' :: \"(NodeData * Message option) \\<Rightarrow> (NodeData * RoutedMessage option)\" where\n    \"\\<And>p. respond' p \\<equiv> case p of\n            (nd, Some m') \\<Rightarrow> (nd, Some \\<lparr>sender = currentNode nd,\n                                   destination = OneNode (sender m),\n                                   payload = m' \\<rparr>)\n            | (nd, None) \\<Rightarrow> (nd, None)\"\n\n  have fst_broadcast[simp]: \"\\<And>p. fst (broadcast' p) = fst p\"\n    unfolding broadcast'_def by (simp add: case_prod_unfold option.case_eq_if)\n\n  have fst_respond[simp]: \"\\<And>p. fst (respond' p) = fst p\"\n    unfolding respond'_def by (simp add: case_prod_unfold option.case_eq_if)\n\n  show ?thesis\n  proof (cases \"destination m = Broadcast \\<or> destination m = OneNode (currentNode nd)\")\n    case False\n    hence \"result = (nd, None)\"\n      unfolding result_def ProcessMessage_def Let_def by simp\n    thus ?thesis by (intro noop)\n  next\n    case dest_ok: True\n    have dest_True: \"destination m \\<in> {Broadcast, OneNode (currentNode nd)} = True\"\n      using dest_ok by simp\n    show ?thesis\n    proof (cases \"payload m\")\n      case (StartJoin t)\n\n      have result: \"result = respond' (handleStartJoin t nd)\"\n        unfolding result_def respond'_def ProcessMessage_def dest_True StartJoin by auto\n\n      have currentNode_eq: \"currentNode (nodeState' n\\<^sub>0) = currentNode (nodeState n\\<^sub>0)\"\n        unfolding nodeState'_def result by (auto simp add: handleStartJoin_def)\n\n      show ?thesis\n      proof (intro zenStep.handleStartJoin_invariants [OF zenStep])\n        show \"nodeState' n\\<^sub>0 = fst (handleStartJoin t (nodeState n\\<^sub>0))\"\n          by (simp add: result nodeState'_def)\n\n        from currentNode_eq\n        show \"messages' = (case snd (handleStartJoin t (nodeState n\\<^sub>0)) of None \\<Rightarrow> messages | Some m' \\<Rightarrow> insert \\<lparr>sender = n\\<^sub>0, destination = OneNode (sender m), payload = m'\\<rparr> messages)\"\n          unfolding messages'_def result respond'_def nodeState'_def by (cases \"handleStartJoin t nd\", cases \"snd (handleStartJoin t nd)\", auto)\n\n        from m show \"\\<exists>d. \\<lparr>sender = sender m, destination = d, payload = StartJoin t\\<rparr> \\<in> messages\"\n          by (auto simp add: isMessageFromTo_def StartJoin)\n      qed\n    next\n      case (Vote i t a)\n\n      from Vote_not_broadcast m Vote dest_ok\n      have dest_m: \"destination m = OneNode n\\<^sub>0\"\n        apply (cases \"destination m\")\n        using isMessageTo_def apply fastforce\n        by auto\n\n      from Vote_not_broadcast m Vote dest_ok\n      have m: \"(sender m) \\<midarrow>\\<langle> Vote i t a \\<rangle>\\<rightarrow> (OneNode n\\<^sub>0)\"\n        apply (cases \"destination m\")\n        using isMessageTo_def apply fastforce\n        by auto\n\n      have result: \"result = broadcast' (handleVote (sender m) i t a nd)\"\n        unfolding result_def ProcessMessage_def Vote dest_True broadcast'_def by simp\n\n      have currentNode_eq: \"currentNode (nodeState' n\\<^sub>0) = currentNode (nodeState n\\<^sub>0)\"\n        unfolding nodeState'_def result by simp\n\n      show ?thesis\n      proof (intro zenStep.handleVote_invariants [OF zenStep])\n        show \"nodeState' n\\<^sub>0 = fst (handleVote (sender m) i t a (nodeState n\\<^sub>0))\"\n          by (simp add: result nodeState'_def)\n\n        from currentNode_eq\n        show \"messages' = (case snd (handleVote (sender m) i t a (nodeState n\\<^sub>0)) of None \\<Rightarrow> messages | Some m \\<Rightarrow> insert \\<lparr>sender = n\\<^sub>0, destination = Broadcast, payload = m\\<rparr> messages)\"\n          unfolding messages'_def result broadcast'_def nodeState'_def by (cases \"handleVote (sender m) i t a nd\", cases \"snd (handleVote (sender m) i t a nd)\", auto)\n\n        from m\n        show \"\\<lparr>sender = sender m, destination = OneNode n\\<^sub>0, payload = Vote i t a\\<rparr> \\<in> messages\"\n          by (auto simp add: Vote isMessageFromTo_def)\n      qed\n\n    next\n      case (ClientValue x)\n\n      have result: \"result = broadcast' (handleClientValue x nd)\"\n        unfolding result_def ProcessMessage_def ClientValue dest_True broadcast'_def by simp\n\n      have currentNode_eq: \"currentNode (nodeState' n\\<^sub>0) = currentNode (nodeState n\\<^sub>0)\"\n        unfolding nodeState'_def result by (simp add: handleClientValue_def)\n\n      show ?thesis\n      proof (intro zenStep.handleClientValue_invariants [OF zenStep])\n        show \"nodeState' n\\<^sub>0 = fst (handleClientValue x (nodeState n\\<^sub>0))\"\n          by (simp add: result nodeState'_def)\n\n        from currentNode_eq\n        show \"messages' = (case snd (handleClientValue x (nodeState n\\<^sub>0)) of None \\<Rightarrow> messages | Some m \\<Rightarrow> insert \\<lparr>sender = n\\<^sub>0, destination = Broadcast, payload = m\\<rparr> messages)\"\n          unfolding messages'_def result broadcast'_def nodeState'_def by (cases \"handleClientValue x (nodeState n\\<^sub>0)\", cases \"snd (handleClientValue x (nodeState n\\<^sub>0))\", auto)\n      qed\n\n    next\n      case (PublishRequest i t x)\n\n      have result: \"result = respond' (handlePublishRequest i t x nd)\"\n        unfolding result_def ProcessMessage_def PublishRequest dest_True by (simp add: respond'_def)\n\n      have currentNode_eq: \"currentNode (nodeState' n\\<^sub>0) = currentNode (nodeState n\\<^sub>0)\"\n        unfolding nodeState'_def result by (simp add: handlePublishRequest_def)\n\n      show ?thesis\n      proof (intro zenStep.handlePublishRequest_invariants [OF zenStep])\n        show \"nodeState' n\\<^sub>0 = fst (handlePublishRequest i t x (nodeState n\\<^sub>0))\"\n          by (simp add: nodeState'_def result)\n\n        from currentNode_eq\n        show \"messages' = (case snd (handlePublishRequest i t x (nodeState n\\<^sub>0)) of None \\<Rightarrow> messages | Some m' \\<Rightarrow> insert \\<lparr>sender = n\\<^sub>0, destination = OneNode (sender m), payload = m'\\<rparr> messages)\"\n          unfolding messages'_def result respond'_def nodeState'_def by (cases \"handlePublishRequest i t x (nodeState n\\<^sub>0)\", cases \"snd (handlePublishRequest i t x (nodeState n\\<^sub>0))\", auto)\n\n        from m\n        show \"\\<exists>d. \\<lparr>sender = sender m, destination = d, payload = PublishRequest i t x\\<rparr> \\<in> messages\"\n          by (auto simp add: PublishRequest isMessageFromTo_def)\n      qed\n\n    next\n      case (PublishResponse i t)\n\n      have result: \"result = broadcast' (handlePublishResponse (sender m) i t nd)\"\n        unfolding result_def ProcessMessage_def PublishResponse dest_True by (simp add: broadcast'_def)\n\n      show ?thesis\n      proof (intro zenStep.handlePublishResponse_invariants [OF zenStep])\n        show \"nodeState' n\\<^sub>0 = fst (handlePublishResponse (sender m) i t (nodeState n\\<^sub>0))\"\n          by (simp add: result nodeState'_def)\n\n        show \"messages' = (case snd (handlePublishResponse (sender m) i t (nodeState n\\<^sub>0)) of None \\<Rightarrow> messages | Some m \\<Rightarrow> insert \\<lparr>sender = n\\<^sub>0, destination = Broadcast, payload = m\\<rparr> messages)\"\n          by (simp_all add: messages'_def result broadcast'_def handlePublishResponse_def commitIfQuorate_def)\n\n        from m\n        show \"\\<exists>d. \\<lparr>sender = sender m, destination = d, payload = PublishResponse i t\\<rparr> \\<in> messages\"\n          by (auto simp add: PublishResponse isMessageFromTo_def)\n      qed\n\n    next\n      case (ApplyCommit i t)\n\n      have result: \"result = (handleApplyCommit i t nd, None)\"\n        unfolding result_def ProcessMessage_def ApplyCommit dest_True by simp\n\n      have currentNode_eq: \"currentNode (nodeState' n\\<^sub>0) = currentNode (nodeState n\\<^sub>0)\"\n        unfolding nodeState'_def result by (cases \"lastAcceptedValue nd\", simp_all add: handleApplyCommit_def applyAcceptedValue_def)\n\n      show ?thesis\n      proof (intro zenStep.handleApplyCommit_invariants [OF zenStep])\n        show \"nodeState' n\\<^sub>0 = handleApplyCommit i t (nodeState n\\<^sub>0)\"\n          by (simp add: result nodeState'_def)\n        show \"messages' = messages\"\n          by (simp add: result messages'_def)\n        from m show \"\\<exists>s d. \\<lparr>sender = s, destination = d, payload = ApplyCommit i t\\<rparr> \\<in> messages\"\n          by (auto simp add: ApplyCommit isMessageFromTo_def)\n      qed\n\n    next\n      case Reboot\n\n      have result: \"result = (handleReboot nd, None)\"\n        unfolding result_def ProcessMessage_def Reboot dest_True by simp\n\n      show ?thesis\n      proof (intro zenStep.handleReboot_invariants [OF zenStep])\n        show \"nodeState' n\\<^sub>0 = handleReboot (nodeState n\\<^sub>0)\"\n          by (simp add: nodeState'_def result)\n\n        show \"messages' = messages\"\n          by (simp add: result messages'_def)\n      qed\n\n    next\n      case DiscardJoinVotes\n\n      have result: \"result = (handleDiscardJoinVotes nd, None)\"\n        unfolding result_def ProcessMessage_def DiscardJoinVotes dest_True by simp\n\n      show ?thesis\n      proof (intro zenStep.handleDiscardJoinVotes_invariants [OF zenStep])\n        show \"nodeState' n\\<^sub>0 = handleDiscardJoinVotes (nodeState n\\<^sub>0)\"\n          by (simp add: nodeState'_def result)\n\n        show \"messages' = messages\"\n          by (simp add: result messages'_def)\n      qed\n\n    next\n      case CatchUpRequest\n\n      have result: \"result = respond' (handleCatchUpRequest nd)\"\n        unfolding result_def ProcessMessage_def CatchUpRequest dest_True by (simp add: respond'_def)\n\n      have currentNode_eq: \"currentNode (nodeState' n\\<^sub>0) = currentNode (nodeState n\\<^sub>0)\"\n        unfolding nodeState'_def result by (cases \"lastAcceptedValue nd\", simp_all add: handleCatchUpRequest_def)\n\n      show ?thesis\n      proof (intro zenStep.handleCatchUpRequest_invariants [OF zenStep])\n        show \"nodeState' n\\<^sub>0 = fst (handleCatchUpRequest (nodeState n\\<^sub>0))\"\n          by (simp add: nodeState'_def result)\n\n        show \"messages' = (case snd (handleCatchUpRequest (nodeState n\\<^sub>0)) of None \\<Rightarrow> messages | Some m' \\<Rightarrow> insert \\<lparr>sender = n\\<^sub>0, destination = OneNode (sender m), payload = m'\\<rparr> messages)\"\n          by (simp_all add: messages'_def result respond'_def handleCatchUpRequest_def)\n      qed\n\n    next\n      case (CatchUpResponse i conf cs)\n\n      have result: \"result = (handleCatchUpResponse i conf cs nd, None)\"\n        unfolding result_def ProcessMessage_def CatchUpResponse dest_True by simp\n\n      show ?thesis\n      proof (intro zenStep.handleCatchUpResponse_invariants [OF zenStep])\n        show \"nodeState' n\\<^sub>0 = handleCatchUpResponse i conf cs (nodeState n\\<^sub>0)\"\n          by (simp add: nodeState'_def result)\n\n        show \"messages' = messages\"\n          by (simp add: result messages'_def)\n\n        from m show \"\\<exists>s d. \\<lparr>sender = s, destination = d, payload = CatchUpResponse i conf cs\\<rparr> \\<in> messages\"\n          unfolding CatchUpResponse isMessageFromTo_def by auto\n      qed\n    qed\n  qed\nqed\n\ntheorem (in zen) invariants_imply_consistent_states:\n  assumes\n    \"firstUncommittedSlot (nodeState n\\<^sub>1) = firstUncommittedSlot (nodeState n\\<^sub>2)\"\n  shows\n    \"currentClusterState (nodeState n\\<^sub>1) = currentClusterState (nodeState n\\<^sub>2)\"\nproof -\n  have \"currentClusterState (nodeState n\\<^sub>1) = lastCommittedClusterStateBefore (firstUncommittedSlot (nodeState n\\<^sub>1))\"\n    using currentClusterState_lastCommittedClusterStateBefore .\n  also have \"... = lastCommittedClusterStateBefore (firstUncommittedSlot (nodeState n\\<^sub>2))\" using assms by simp\n  also have \"... = currentClusterState (nodeState n\\<^sub>2)\"\n    using currentClusterState_lastCommittedClusterStateBefore ..\n  finally show ?thesis .\nqed\n\nend\n", "meta": {"author": "elastic", "repo": "elasticsearch-formal-models", "sha": "ca30663506a7e18de9d23fabbc70a369903d7c98", "save_path": "github-repos/isabelle/elastic-elasticsearch-formal-models", "path": "github-repos/isabelle/elastic-elasticsearch-formal-models/elasticsearch-formal-models-ca30663506a7e18de9d23fabbc70a369903d7c98/cluster/isabelle/Zen.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5888891451980403, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.26009643876289057}}
{"text": "(*******************************************************************************\n\n  Project: Refining Authenticated Key Agreement with Strong Adversaries\n\n  Module:  Implem.thy (Isabelle/HOL 2016-1)\n  ID:      $Id: Implem.thy 132885 2016-12-23 18:41:32Z csprenge $\n  Author:  Joseph Lallemand, INRIA Nancy <joseph.lallemand@loria.fr>\n           Christoph Sprenger, ETH Zurich <sprenger@inf.ethz.ch>\n  \n  Parametric channel message implementation\n  - definition of 'valid' implementations\n  - assumptions for channel implementations (formulated as locales)\n\n  Copyright (c) 2015-2016 Joseph Lallemand and Christoph Sprenger\n  Licence: LGPL\n\n*******************************************************************************)\n\nsection \\<open>Assumptions for Channel Message Implementation\\<close>\n\ntext \\<open>We define a series of locales capturing our assumptions on channel message \nimplementations.\\<close>\n\ntheory Implem\nimports Channels Payloads\nbegin\n\nsubsection \\<open>First step: basic implementation locale\\<close>\n(**************************************************************************************************)\n\ntext \\<open>This locale has no assumptions, it only fixes an implementation function and \ndefines some useful abbreviations (impl*, impl*Set) and \\<open>valid\\<close>.\n\\<close>\n\nlocale basic_implem =\n  fixes implem :: \"chan \\<Rightarrow> msg\"\nbegin\n\nabbreviation \"implInsec A B M \\<equiv> implem (Insec A B M)\"\nabbreviation \"implConfid A B M \\<equiv> implem (Confid A B M)\"\nabbreviation \"implAuth A B M \\<equiv> implem (Auth A B M)\"\nabbreviation \"implSecure A B M \\<equiv> implem (Secure A B M)\"\n\nabbreviation implInsecSet :: \"msg set \\<Rightarrow> msg set\"\nwhere \"implInsecSet G \\<equiv> {implInsec A B M | A B M. M \\<in> G}\"\n\nabbreviation implConfidSet :: \"(agent * agent) set \\<Rightarrow> msg set \\<Rightarrow> msg set\"\nwhere \"implConfidSet Ag G \\<equiv> {implConfid A B M | A B M.  (A, B) \\<in> Ag \\<and> M \\<in> G}\"\n\nabbreviation implAuthSet :: \"msg set \\<Rightarrow> msg set\"\nwhere \"implAuthSet G \\<equiv> {implAuth A B M | A B M. M \\<in> G}\"\n\nabbreviation implSecureSet :: \"(agent * agent) set \\<Rightarrow> msg set \\<Rightarrow> msg set\"\nwhere \"implSecureSet Ag G \\<equiv> {implSecure A B M | A B M. (A, B) \\<in> Ag \\<and> M \\<in> G}\"\n\ndefinition\n  valid :: \"msg set\"\nwhere\n  \"valid \\<equiv> {implem (Chan x A B M) | x A B M. M \\<in> payload}\"\n\nlemma validI:\n  \"M \\<in> payload \\<Longrightarrow> implem (Chan x A B M) \\<in> valid\"\nby (auto simp add: valid_def)\n\nlemma validE:\n  \"X \\<in> valid \\<Longrightarrow> (\\<And> x A B M. X = implem (Chan x A B M) \\<Longrightarrow> M \\<in> payload \\<Longrightarrow> P) \\<Longrightarrow> P\"\nby (auto simp add: valid_def)\n\nlemma valid_cases:\nfixes X P\nassumes \"X \\<in> valid\"\n        \"(\\<And>A B M. X = implInsec A B M \\<Longrightarrow> M \\<in> payload \\<Longrightarrow> P)\"\n        \"(\\<And>A B M. X = implConfid A B M \\<Longrightarrow> M \\<in> payload \\<Longrightarrow> P)\"\n        \"(\\<And>A B M. X = implAuth A B M \\<Longrightarrow> M \\<in> payload \\<Longrightarrow> P)\"\n        \"(\\<And>A B M. X = implSecure A B M \\<Longrightarrow> M \\<in> payload \\<Longrightarrow> P)\"\nshows \"P\"\nproof -\n  from assms have \"(\\<And> x A B M. X = implem (Chan x A B M) \\<Longrightarrow> M \\<in> payload \\<Longrightarrow> P) \\<Longrightarrow> P\"\n  by (auto elim: validE)\n  moreover from assms have \"\\<And> x A B M. X = implem (Chan x A B M) \\<Longrightarrow> M \\<in> payload \\<Longrightarrow> P\"\n    proof -\n      fix x A B M\n      assume \"X = implem (Chan x A B M)\" \"M \\<in> payload\"\n      with assms show \"P\" by (cases x, auto)\n    qed\n  ultimately show ?thesis .\nqed\n\nend\n\nsubsection \\<open>Second step: basic and analyze assumptions\\<close>\n(**************************************************************************************************)\n\ntext \\<open>This locale contains most of the assumptions on implem, i.e.:\n\\begin{itemize}\n\\item \\<open>impl_inj\\<close>: injectivity\n\\item \\<open>parts_impl_inj\\<close>: injectivity through parts\n\\item \\<open>Enc_parts_valid_impl\\<close>: if Enc X Y appears in parts of an implem, then it is \n  in parts of the payload, or the key is either long term or payload\n\\item \\<open>impl_composed\\<close>: the implementations are composed (not nonces, agents, tags etc.)\n\\item \\<open>analz_Un_implXXXSet\\<close>: move the impl*Set out of the analz (only keep the payloads)\n\\item \\<open>impl_Impl\\<close>: implementations contain implementation material\n\\item \\<open>LtK_parts_impl\\<close>: no exposed long term keys in the implementations \n  (i.e., they are only used as keys, or under hashes)\n\\end{itemize}\n\\<close>\n\nlocale semivalid_implem = basic_implem +\n\\<comment> \\<open>injectivity\\<close>\nassumes impl_inj:\n  \"implem (Chan x A B M) = implem (Chan x' A' B' M') \n   \\<longleftrightarrow> x = x' \\<and> A = A' \\<and> B = B' \\<and> M = M'\"\n\\<comment> \\<open>implementations and parts\\<close>\nand parts_impl_inj:\n  \"M' \\<in> payload \\<Longrightarrow>\n   implem (Chan x A B M) \\<in> parts {implem (Chan x' A' B' M')} \\<Longrightarrow> \n   x = x' \\<and> A = A' \\<and> B = B' \\<and> M = M'\"\nand Enc_keys_clean_valid: \"I \\<subseteq> valid \\<Longrightarrow> Enc_keys_clean I\"\nand impl_composed: \"composed (implem Z)\"\nand impl_Impl: \"implem (Chan x A B M) \\<notin> payload\"\n\\<comment> \\<open>no ltk in the parts of an implementation\\<close>\nand LtK_parts_impl: \"X \\<in> valid \\<Longrightarrow> LtK K \\<notin> parts {X}\"\n\n\\<comment> \\<open>analyze assumptions:\\<close>\nand analz_Un_implInsecSet:\n  \"\\<lbrakk> G \\<subseteq> payload; Enc_keys_clean H \\<rbrakk> \n \\<Longrightarrow> analz (implInsecSet G \\<union> H) \\<subseteq> synth (analz (G \\<union> H)) \\<union> -payload\"\nand analz_Un_implConfidSet:\n  \"\\<lbrakk> G \\<subseteq> payload; Enc_keys_clean H \\<rbrakk> \n \\<Longrightarrow> analz (implConfidSet Ag G \\<union> H) \\<subseteq> synth (analz (G \\<union> H)) \\<union> -payload\"\nand analz_Un_implConfidSet_2:\n  \"\\<lbrakk> G \\<subseteq> payload; Enc_keys_clean H; Ag \\<inter> broken (parts H \\<inter> range LtK) = {} \\<rbrakk>\n \\<Longrightarrow> analz (implConfidSet Ag G \\<union> H) \\<subseteq> synth (analz H) \\<union> -payload\"\nand analz_Un_implAuthSet:\n  \"\\<lbrakk> G \\<subseteq> payload; Enc_keys_clean H \\<rbrakk>\n \\<Longrightarrow> analz (implAuthSet G \\<union> H) \\<subseteq> synth (analz (G \\<union> H)) \\<union> -payload\"\nand analz_Un_implSecureSet:\n  \"\\<lbrakk> G \\<subseteq> payload; Enc_keys_clean H \\<rbrakk>\n \\<Longrightarrow> analz (implSecureSet Ag G \\<union> H) \\<subseteq> synth (analz (G \\<union> H)) \\<union> -payload\"\nand analz_Un_implSecureSet_2:\n  \"\\<lbrakk> G \\<subseteq> payload; Enc_keys_clean H; Ag \\<inter> broken (parts H \\<inter> range LtK) = {} \\<rbrakk>\n \\<Longrightarrow> analz (implSecureSet Ag G \\<union> H) \\<subseteq> synth (analz H) \\<union> -payload\"\n\nbegin\n\\<comment> \\<open>declare some attributes and abbreviations for the hypotheses\\<close>\n\\<comment> \\<open>and prove some simple consequences of the hypotheses\\<close>\ndeclare impl_inj [simp]\n\nlemmas parts_implE [elim] = parts_impl_inj [rotated 1]\n\ndeclare impl_composed [simp, intro]\n\nlemma composed_arg_cong: \"X = Y \\<Longrightarrow> composed X \\<longleftrightarrow> composed Y\"\nby (rule arg_cong)\n\nlemma implem_Tags_aux: \"implem (Chan x A B M) \\<notin> Tags\" by (cases x, auto dest: composed_arg_cong)\nlemma implem_Tags [simp]: \"implem x \\<notin> Tags\" by (cases x, auto simp add: implem_Tags_aux)\nlemma implem_LtK_aux: \"implem (Chan x A B M) \\<noteq> LtK K\" by (cases x, auto dest: composed_arg_cong)\nlemma implem_LtK [simp]: \"implem x \\<noteq> LtK K\" by (cases x, auto simp add: implem_LtK_aux)\nlemma implem_LtK2 [simp]: \"implem x \\<notin> range LtK\" by (cases x, auto simp add: implem_LtK_aux)\n\ndeclare impl_Impl [simp]\n\nlemma LtK_parts_impl_insert:\n  \"LtK K \\<in> parts (insert (implem (Chan x A B M)) S) \\<Longrightarrow> M \\<in> payload \\<Longrightarrow> LtK K \\<in> parts S\"\napply (simp add: parts_insert [of _ S], clarify)\napply (auto dest: validI LtK_parts_impl)\ndone\n\n\ndeclare LtK_parts_impl_insert [dest]\ndeclare Enc_keys_clean_valid [simp, intro]\n\nlemma valid_composed [simp,dest]: \"M \\<in> valid \\<Longrightarrow> composed M\"\nby (auto elim: validE)\n\n\\<comment> \\<open>lemmas: valid/payload are mutually exclusive\\<close>\nlemma valid_payload [dest]: \"\\<lbrakk> X \\<in> valid; X \\<in> payload \\<rbrakk> \\<Longrightarrow> P\"\nby (auto elim!: validE)\n    \n\\<comment> \\<open>valid/LtK are mutually exclusive\\<close>\nlemma valid_isLtKey [dest]: \"\\<lbrakk> X \\<in> valid; X \\<in> range LtK \\<rbrakk> \\<Longrightarrow> P\"\nby (auto)\n\nlemma analz_valid:\n  \"H \\<subseteq> payload \\<union> valid \\<union> range LtK \\<union> Tags \\<Longrightarrow>\n   implem (Chan x A B M) \\<in> analz H \\<Longrightarrow>\n   implem (Chan x A B M) \\<in> H\"\napply (drule analz_into_parts, \n       drule parts_monotone [of _ H \"payload \\<union> H \\<inter> valid \\<union> range LtK \\<union> Tags\"], auto)\napply (drule parts_singleton, auto elim!:validE dest: parts_impl_inj)\ndone\n\nlemma parts_valid_LtKeys_disjoint:\n  \"I \\<subseteq> valid \\<Longrightarrow> parts I \\<inter> range LtK = {}\"\napply (safe, drule parts_singleton, clarsimp)\napply (auto dest: subsetD LtK_parts_impl)\ndone\n\nlemma analz_LtKeys:\n  \"H \\<subseteq> payload \\<union> valid \\<union> range LtK \\<union> Tags \\<Longrightarrow>\n   analz H \\<inter> range LtK \\<subseteq> H\"\napply auto\napply (drule analz_into_parts, drule parts_monotone [of _ H \"payload \\<union> valid \\<union> H \\<inter> range LtK \\<union> Tags\"], auto)\napply (drule parts_singleton, auto elim!:validE dest: parts_impl_inj)\ndone\n\nend\n\n\nsubsection \\<open>Third step: \\<open>valid_implem\\<close>\\<close>\n(**************************************************************************************************)\n\ntext \\<open>This extends @{locale \"semivalid_implem\"} with four new assumptions, which under certain \n  conditions give information on $A$, $B$, $M$ when @{term \"implXXX A B M \\<in> synth (analz Z)\"}.\n  These assumptions are separated because interpretations are more easily proved, if the \n  conclusions that follow from the @{locale \"semivalid_implem\"} assumptions are already \n  available.\n\\<close>\n\nlocale valid_implem = semivalid_implem +\n\n\\<comment> \\<open>Synthesize assumptions: conditions on payloads $M$ implied by derivable\\<close>\n\\<comment> \\<open>channel messages with payload $M$.\\<close>\nassumes implInsec_synth_analz:\n  \"H \\<subseteq> payload \\<union> valid \\<union> range LtK \\<union> Tags \\<Longrightarrow>\n   implInsec A B M \\<in> synth (analz H) \\<Longrightarrow>\n   implInsec A B M \\<in> H \\<or> M \\<in> synth (analz H)\"\nand implConfid_synth_analz:\n  \"H \\<subseteq> payload \\<union> valid \\<union> range LtK \\<union> Tags \\<Longrightarrow>\n   implConfid A B M \\<in> synth (analz H) \\<Longrightarrow>\n   implConfid A B M \\<in> H \\<or> M \\<in> synth (analz H)\"\nand implAuth_synth_analz:\n  \"H \\<subseteq> payload \\<union> valid \\<union> range LtK \\<union> Tags \\<Longrightarrow>\n   implAuth A B M \\<in> synth (analz H) \\<Longrightarrow>\n   implAuth A B M \\<in> H \\<or> (M \\<in> synth (analz H) \\<and> (A, B) \\<in> broken H)\"\nand implSecure_synth_analz:\n  \"H \\<subseteq> payload \\<union> valid \\<union> range LtK \\<union> Tags \\<Longrightarrow>\n   implSecure A B M \\<in> synth (analz H) \\<Longrightarrow>\n   implSecure A B M \\<in> H \\<or> (M \\<in> synth (analz H) \\<and> (A, B) \\<in> broken H)\"\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Key_Agreement_Strong_Adversaries/Implem.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.44167300566462564, "lm_q1q2_score": 0.2600964323894571}}
{"text": "theory flash95Rev imports flashPub\nbegin\nsection{*Main defintions*}\nlemma NI_FAckVsInv95:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv95 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_InvVsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1VsInv95:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1_HomeVsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_2VsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_GetXVsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_Nak1VsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_Nak2VsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_Nak3VsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_PutX1VsInv95:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv95:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv95:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv95:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv95:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv95:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv95:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv95:  \n  (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv95:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv95:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' Home) )  ( Const CACHE_S ))    ( eqn ( IVar ( Global ''Dir_local'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX10VsInv95:  \n  (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' Home) )  ( Const CACHE_S ))    ( eqn ( IVar ( Global ''Dir_local'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX10_homeVsInv95:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1 , simp)\n\n        apply(rule_tac x=\" (neg ( eqn ( IVar ( Para ''Dir_ShrSet'' Home) )  ( Const true )) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX11VsInv95:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_Get_GetVsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Nak1VsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Nak2VsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Nak3VsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Put1VsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Put2VsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Put3VsInv95:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_PutVsInv95:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n     have allCases:\"formEval  ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true ))  s  \\<or>formEval   (neg ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true )) )  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume b1:\"formEval ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true ))  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n\n    moreover\n                       {assume b1:\"formEval  (neg ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true )) )  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_PutXAcksDoneVsInv95:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv95 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_NakVsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Nak_ClearVsInv95:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv95 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_Nak_HomeVsInv95:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv95 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_Remote_GetX_NakVsInv95:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_Nak_HomeVsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_PutXVsInv95:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_PutX_HomeVsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Nak1VsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Nak2VsInv95:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Put1VsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Put2VsInv95:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_PutVsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_PutXVsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceVsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceHomeVsInv95:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv95 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_ReplaceHomeShrVldVsInv95:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv95 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_ReplaceShrVldVsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ShWbVsInv95:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv95 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_WbVsInv95:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv95 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_GetX1VsInv95:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv95 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_GetX_GetX2VsInv95:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv95 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_GetX_PutX1VsInv95:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv95 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX2VsInv95:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv95 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX3VsInv95:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv95 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX4VsInv95:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv95 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_Get_GetVsInv95:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv95 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_Get_PutVsInv95:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv95 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n     have allCases:\"formEval  ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true ))  s  \\<or>formEval   (neg ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true )) )  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume b1:\"formEval ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true ))  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n\n    moreover\n                       {assume b1:\"formEval  (neg ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true )) )  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Local_PutXVsInv95:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv95 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_ReplaceVsInv95:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv95 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Remote_GetVsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_GetXVsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_PutXVsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_ReplaceVsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma StoreVsInv95:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv95 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma StoreHomeVsInv95:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv95 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash95Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5736784074525098, "lm_q2_score": 0.4532618480153862, "lm_q1q2_score": 0.26002653512844826}}
{"text": "subsection \"Termination-Sensitive Systems\"\n\ntheory Sec_TypingT imports Sec_Type_Expr\nbegin\n\nsubsubsection \"A Syntax Directed System\"\n\ninductive sec_type :: \"nat \\<Rightarrow> com \\<Rightarrow> bool\" (\"(_/ \\<turnstile> _)\" [0,0] 50) where\nSkip:\n  \"l \\<turnstile> SKIP\"  |\nAssign:\n  \"\\<lbrakk> sec x \\<ge> sec a;  sec x \\<ge> l \\<rbrakk> \\<Longrightarrow> l \\<turnstile> x ::= a\"  |\nSeq:\n  \"l \\<turnstile> c\\<^sub>1 \\<Longrightarrow> l \\<turnstile> c\\<^sub>2 \\<Longrightarrow> l \\<turnstile> c\\<^sub>1;;c\\<^sub>2\"  |\nIf:\n  \"\\<lbrakk> max (sec b) l \\<turnstile> c\\<^sub>1;  max (sec b) l \\<turnstile> c\\<^sub>2 \\<rbrakk>\n   \\<Longrightarrow> l \\<turnstile> IF b THEN c\\<^sub>1 ELSE c\\<^sub>2\"  |\nWhile:\n  \"sec b = 0 \\<Longrightarrow> 0 \\<turnstile> c \\<Longrightarrow> 0 \\<turnstile> WHILE b DO c\"\n\ncode_pred (expected_modes: i => i => bool) sec_type .\n\ninductive_cases [elim!]:\n  \"l \\<turnstile> x ::= a\"  \"l \\<turnstile> c\\<^sub>1;;c\\<^sub>2\"  \"l \\<turnstile> IF b THEN c\\<^sub>1 ELSE c\\<^sub>2\"  \"l \\<turnstile> WHILE b DO c\"\n\n\nlemma anti_mono: \"l \\<turnstile> c \\<Longrightarrow> l' \\<le> l \\<Longrightarrow> l' \\<turnstile> c\"\napply(induction arbitrary: l' rule: sec_type.induct)\napply (metis sec_type.intros(1))\napply (metis le_trans sec_type.intros(2))\napply (metis sec_type.intros(3))\napply (metis If le_refl sup_mono sup_nat_def)\nby (metis While le_0_eq)\n\n\nlemma confinement: \"(c,s) \\<Rightarrow> t \\<Longrightarrow> l \\<turnstile> c \\<Longrightarrow> s = t (< l)\"\nproof(induction rule: big_step_induct)\n  case Skip thus ?case by simp\nnext\n  case Assign thus ?case by auto\nnext\n  case Seq thus ?case by auto\nnext\n  case (IfTrue b s c1)\n  hence \"max (sec b) l \\<turnstile> c1\" by auto\n  hence \"l \\<turnstile> c1\" by (metis max.cobounded2 anti_mono)\n  thus ?case using IfTrue.IH by metis\nnext\n  case (IfFalse b s c2)\n  hence \"max (sec b) l \\<turnstile> c2\" by auto\n  hence \"l \\<turnstile> c2\" by (metis max.cobounded2 anti_mono)\n  thus ?case using IfFalse.IH by metis\nnext\n  case WhileFalse thus ?case by auto\nnext\n  case (WhileTrue b s1 c)\n  hence \"l \\<turnstile> c\" by auto\n  thus ?case using WhileTrue by metis\nqed\n\nlemma termi_if_non0: \"l \\<turnstile> c \\<Longrightarrow> l \\<noteq> 0 \\<Longrightarrow> \\<exists> t. (c,s) \\<Rightarrow> t\"\napply(induction arbitrary: s rule: sec_type.induct)\napply (metis big_step.Skip)\napply (metis big_step.Assign)\napply (metis big_step.Seq)\napply (metis IfFalse IfTrue le0 le_antisym max.cobounded2)\napply simp\ndone\n\ntheorem noninterference: \"(c,s) \\<Rightarrow> s' \\<Longrightarrow> 0 \\<turnstile> c \\<Longrightarrow>  s = t (\\<le> l)\n  \\<Longrightarrow> \\<exists> t'. (c,t) \\<Rightarrow> t' \\<and> s' = t' (\\<le> l)\"\nproof(induction arbitrary: t rule: big_step_induct)\n  case Skip thus ?case by auto\nnext\n  case (Assign x a s)\n  have \"sec x >= sec a\" using \\<open>0 \\<turnstile> x ::= a\\<close> by auto\n  have \"(x ::= a,t) \\<Rightarrow> t(x := aval a t)\" by auto\n  moreover\n  have \"s(x := aval a s) = t(x := aval a t) (\\<le> l)\"\n  proof auto\n    assume \"sec x \\<le> l\"\n    with \\<open>sec x \\<ge> sec a\\<close> have \"sec a \\<le> l\" by arith\n    thus \"aval a s = aval a t\"\n      by (rule aval_eq_if_eq_le[OF \\<open>s = t (\\<le> l)\\<close>])\n  next\n    fix y assume \"y \\<noteq> x\" \"sec y \\<le> l\"\n    thus \"s y = t y\" using \\<open>s = t (\\<le> l)\\<close> by simp\n  qed\n  ultimately show ?case by blast\nnext\n  case Seq thus ?case by blast\nnext\n  case (IfTrue b s c1 s' c2)\n  have \"sec b \\<turnstile> c1\" \"sec b \\<turnstile> c2\" using \\<open>0 \\<turnstile> IF b THEN c1 ELSE c2\\<close> by auto\n  obtain t' where t': \"(c1, t) \\<Rightarrow> t'\" \"s' = t' (\\<le> l)\"\n    using IfTrue.IH[OF anti_mono[OF \\<open>sec b \\<turnstile> c1\\<close>] \\<open>s = t (\\<le> l)\\<close>] by blast\n  show ?case\n  proof cases\n    assume \"sec b \\<le> l\"\n    hence \"s = t (\\<le> sec b)\" using \\<open>s = t (\\<le> l)\\<close> by auto\n    hence \"bval b t\" using \\<open>bval b s\\<close> by(simp add: bval_eq_if_eq_le)\n    thus ?thesis by (metis t' big_step.IfTrue)\n  next\n    assume \"\\<not> sec b \\<le> l\"\n    hence 0: \"sec b \\<noteq> 0\" by arith\n    have 1: \"sec b \\<turnstile> IF b THEN c1 ELSE c2\"\n      by(rule sec_type.intros)(simp_all add: \\<open>sec b \\<turnstile> c1\\<close> \\<open>sec b \\<turnstile> c2\\<close>)\n    from confinement[OF big_step.IfTrue[OF IfTrue(1,2)] 1] \\<open>\\<not> sec b \\<le> l\\<close>\n    have \"s = s' (\\<le> l)\" by auto\n    moreover\n    from termi_if_non0[OF 1 0, of t] obtain t' where\n      t': \"(IF b THEN c1 ELSE c2,t) \\<Rightarrow> t'\" ..\n    moreover\n    from confinement[OF t' 1] \\<open>\\<not> sec b \\<le> l\\<close>\n    have \"t = t' (\\<le> l)\" by auto\n    ultimately\n    show ?case using \\<open>s = t (\\<le> l)\\<close> by auto\n  qed\nnext\n  case (IfFalse b s c2 s' c1)\n  have \"sec b \\<turnstile> c1\" \"sec b \\<turnstile> c2\" using \\<open>0 \\<turnstile> IF b THEN c1 ELSE c2\\<close> by auto\n  obtain t' where t': \"(c2, t) \\<Rightarrow> t'\" \"s' = t' (\\<le> l)\"\n    using IfFalse.IH[OF anti_mono[OF \\<open>sec b \\<turnstile> c2\\<close>] \\<open>s = t (\\<le> l)\\<close>] by blast\n  show ?case\n  proof cases\n    assume \"sec b \\<le> l\"\n    hence \"s = t (\\<le> sec b)\" using \\<open>s = t (\\<le> l)\\<close> by auto\n    hence \"\\<not> bval b t\" using \\<open>\\<not> bval b s\\<close> by(simp add: bval_eq_if_eq_le)\n    thus ?thesis by (metis t' big_step.IfFalse)\n  next\n    assume \"\\<not> sec b \\<le> l\"\n    hence 0: \"sec b \\<noteq> 0\" by arith\n    have 1: \"sec b \\<turnstile> IF b THEN c1 ELSE c2\"\n      by(rule sec_type.intros)(simp_all add: \\<open>sec b \\<turnstile> c1\\<close> \\<open>sec b \\<turnstile> c2\\<close>)\n    from confinement[OF big_step.IfFalse[OF IfFalse(1,2)] 1] \\<open>\\<not> sec b \\<le> l\\<close>\n    have \"s = s' (\\<le> l)\" by auto\n    moreover\n    from termi_if_non0[OF 1 0, of t] obtain t' where\n      t': \"(IF b THEN c1 ELSE c2,t) \\<Rightarrow> t'\" ..\n    moreover\n    from confinement[OF t' 1] \\<open>\\<not> sec b \\<le> l\\<close>\n    have \"t = t' (\\<le> l)\" by auto\n    ultimately\n    show ?case using \\<open>s = t (\\<le> l)\\<close> by auto\n  qed\nnext\n  case (WhileFalse b s c)\n  hence [simp]: \"sec b = 0\" by auto\n  have \"s = t (\\<le> sec b)\" using \\<open>s = t (\\<le> l)\\<close> by auto\n  hence \"\\<not> bval b t\" using \\<open>\\<not> bval b s\\<close> by (metis bval_eq_if_eq_le le_refl)\n  with WhileFalse.prems(2) show ?case by auto\nnext\n  case (WhileTrue b s c s'' s')\n  let ?w = \"WHILE b DO c\"\n  from \\<open>0 \\<turnstile> ?w\\<close> have [simp]: \"sec b = 0\" by auto\n  have \"0 \\<turnstile> c\" using \\<open>0 \\<turnstile> WHILE b DO c\\<close> by auto\n  from WhileTrue.IH(1)[OF this \\<open>s = t (\\<le> l)\\<close>]\n  obtain t'' where \"(c,t) \\<Rightarrow> t''\" and \"s'' = t'' (\\<le>l)\" by blast\n  from WhileTrue.IH(2)[OF \\<open>0 \\<turnstile> ?w\\<close> this(2)]\n  obtain t' where \"(?w,t'') \\<Rightarrow> t'\" and \"s' = t' (\\<le>l)\" by blast\n  from \\<open>bval b s\\<close> have \"bval b t\"\n    using bval_eq_if_eq_le[OF \\<open>s = t (\\<le>l)\\<close>] by auto\n  show ?case\n    using big_step.WhileTrue[OF \\<open>bval b t\\<close> \\<open>(c,t) \\<Rightarrow> t''\\<close> \\<open>(?w,t'') \\<Rightarrow> t'\\<close>]\n    by (metis \\<open>s' = t' (\\<le> l)\\<close>)\nqed\n\nsubsubsection \"The Standard System\"\n\ntext\\<open>The predicate \\<^prop>\\<open>l \\<turnstile> c\\<close> is nicely intuitive and executable. The\nstandard formulation, however, is slightly different, replacing the maximum\ncomputation by an antimonotonicity rule. We introduce the standard system now\nand show the equivalence with our formulation.\\<close>\n\ninductive sec_type' :: \"nat \\<Rightarrow> com \\<Rightarrow> bool\" (\"(_/ \\<turnstile>'' _)\" [0,0] 50) where\nSkip':\n  \"l \\<turnstile>' SKIP\"  |\nAssign':\n  \"\\<lbrakk> sec x \\<ge> sec a;  sec x \\<ge> l \\<rbrakk> \\<Longrightarrow> l \\<turnstile>' x ::= a\"  |\nSeq':\n  \"l \\<turnstile>' c\\<^sub>1 \\<Longrightarrow> l \\<turnstile>' c\\<^sub>2 \\<Longrightarrow> l \\<turnstile>' c\\<^sub>1;;c\\<^sub>2\"  |\nIf':\n  \"\\<lbrakk> sec b \\<le> l;  l \\<turnstile>' c\\<^sub>1;  l \\<turnstile>' c\\<^sub>2 \\<rbrakk> \\<Longrightarrow> l \\<turnstile>' IF b THEN c\\<^sub>1 ELSE c\\<^sub>2\"  |\nWhile':\n  \"\\<lbrakk> sec b = 0;  0 \\<turnstile>' c \\<rbrakk> \\<Longrightarrow> 0 \\<turnstile>' WHILE b DO c\"  |\nanti_mono':\n  \"\\<lbrakk> l \\<turnstile>' c;  l' \\<le> l \\<rbrakk> \\<Longrightarrow> l' \\<turnstile>' c\"\n\nlemma sec_type_sec_type': \n  \"l \\<turnstile> c \\<Longrightarrow> l \\<turnstile>' c\"\napply(induction rule: sec_type.induct)\napply (metis Skip')\napply (metis Assign')\napply (metis Seq')\napply (metis max.commute max.absorb_iff2 nat_le_linear If' anti_mono')\nby (metis While')\n\n\nlemma sec_type'_sec_type:\n  \"l \\<turnstile>' c \\<Longrightarrow> l \\<turnstile> c\"\napply(induction rule: sec_type'.induct)\napply (metis Skip)\napply (metis Assign)\napply (metis Seq)\napply (metis max.absorb2 If)\napply (metis While)\nby (metis anti_mono)\n\ncorollary sec_type_eq: \"l \\<turnstile> c \\<longleftrightarrow> l \\<turnstile>' c\"\nby (metis sec_type'_sec_type sec_type_sec_type')\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/IMP/Sec_TypingT.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736784074525098, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.26002653512844826}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      AlternativeSmallStep.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2006-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection  {* Alternative Small Step Semantics *}\n\ntheory AlternativeSmallStep imports HoareTotalDef\nbegin\n\n\ntext {* \nThis is the small-step semantics, which is described and used in my PhD-thesis \\cite{Schirmer-PhD}. \nIt decomposes the statement into a list of statements and finally executes the head.\nSo the redex is always the head of the list. The equivalence between termination\n(based on the big-step semantics) and the absence of infinite computations in\nthis small-step semantics follows the same lines of reasoning as for\nthe new small-step semantics. However, it is technically more involved since\nthe configurations are more complicated. Thats why I switched to the new small-step\nsemantics in the \"main trunk\". I keep this alternative version and the important\nproofs in this theory, so that one can compare both approaches.\n*}\n\n\nsubsection {*Small-Step Computation: @{text \"\\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow> (cs', css', s')\"}*}\n\ntype_synonym ('s,'p,'f) continuation = \"('s,'p,'f) com list \\<times> ('s,'p,'f) com list\"\n \ntype_synonym ('s,'p,'f) config =\n  \"('s,'p,'f)com list \\<times> ('s,'p,'f)continuation list \\<times> ('s,'f) xstate\"\n\n\n\ninductive \"step\"::\"[('s,'p,'f) body,('s,'p,'f) config,('s,'p,'f) config] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile> (_ \\<rightarrow>/ _)\" [81,81,81] 100)\n  for \\<Gamma>::\"('s,'p,'f) body\"\nwhere\n  Skip: \"\\<Gamma>\\<turnstile>(Skip#cs,css,Normal s) \\<rightarrow> (cs,css,Normal s)\"\n| Guard: \"s\\<in>g \\<Longrightarrow> \\<Gamma>\\<turnstile>(Guard f g c#cs,css,Normal s) \\<rightarrow> (c#cs,css,Normal s)\"\n  \n| GuardFault: \"s\\<notin>g \\<Longrightarrow> \\<Gamma>\\<turnstile>(Guard f g c#cs,css,Normal s) \\<rightarrow> (cs,css,Fault f)\"\n\n| FaultProp: \"\\<Gamma>\\<turnstile>(c#cs,css,Fault f) \\<rightarrow> (cs,css,Fault f)\" \n| FaultPropBlock: \"\\<Gamma>\\<turnstile>([],(nrms,abrs)#css,Fault f) \\<rightarrow> (nrms,css,Fault f)\"\n  (* FaultPropBlock: \"\\<Gamma>\\<turnstile>([],cs#css,Fault) \\<rightarrow> ([],css,Fault)\"*)\n    \n| AbruptProp:  \"\\<Gamma>\\<turnstile>(c#cs,css,Abrupt s) \\<rightarrow> (cs,css,Abrupt s)\"\n \n| ExitBlockNormal: \n    \"\\<Gamma>\\<turnstile>([],(nrms,abrs)#css,Normal s) \\<rightarrow> (nrms,css,Normal s)\"\n| ExitBlockAbrupt: \n    \"\\<Gamma>\\<turnstile>([],(nrms,abrs)#css,Abrupt s) \\<rightarrow> (abrs,css,Normal s)\"\n\n| Basic: \"\\<Gamma>\\<turnstile>(Basic f#cs,css,Normal s) \\<rightarrow> (cs,css,Normal (f s))\"\n\n| Spec: \"(s,t) \\<in> r \\<Longrightarrow> \\<Gamma>\\<turnstile>(Spec r#cs,css,Normal s) \\<rightarrow> (cs,css,Normal t)\"\n| SpecStuck: \"\\<forall>t. (s,t) \\<notin> r \\<Longrightarrow> \\<Gamma>\\<turnstile>(Spec r#cs,css,Normal s) \\<rightarrow> (cs,css,Stuck)\"\n\n| Seq: \"\\<Gamma>\\<turnstile>(Seq c\\<^sub>1 c\\<^sub>2#cs,css,Normal s) \\<rightarrow> (c\\<^sub>1#c\\<^sub>2#cs,css,Normal s)\"\n\n| CondTrue:  \"s\\<in>b \\<Longrightarrow> \\<Gamma>\\<turnstile>(Cond b c\\<^sub>1 c\\<^sub>2#cs,css,Normal s) \\<rightarrow> (c\\<^sub>1#cs,css,Normal s)\"\n| CondFalse: \"s\\<notin>b \\<Longrightarrow> \\<Gamma>\\<turnstile>(Cond b c\\<^sub>1 c\\<^sub>2#cs,css,Normal s) \\<rightarrow> (c\\<^sub>2#cs,css,Normal s)\"\n\n| WhileTrue: \"\\<lbrakk>s\\<in>b\\<rbrakk> \n              \\<Longrightarrow> \n   \\<Gamma>\\<turnstile>(While b c#cs,css,Normal s) \\<rightarrow> (c#While b c#cs,css,Normal s)\"\n| WhileFalse: \"\\<lbrakk>s\\<notin>b\\<rbrakk> \n               \\<Longrightarrow> \n               \\<Gamma>\\<turnstile>(While b c#cs,css,Normal s) \\<rightarrow> (cs,css,Normal s)\"\n\n| Call: \"\\<Gamma> p=Some bdy \\<Longrightarrow>\n         \\<Gamma>\\<turnstile>(Call p#cs,css,Normal s) \\<rightarrow> ([bdy],(cs,Throw#cs)#css,Normal s)\"\n\n| CallUndefined: \"\\<Gamma> p=None \\<Longrightarrow>\n         \\<Gamma>\\<turnstile>(Call p#cs,css,Normal s) \\<rightarrow> (cs,css,Stuck)\"\n\n| StuckProp: \"\\<Gamma>\\<turnstile>(c#cs,css,Stuck) \\<rightarrow> (cs,css,Stuck)\" \n| StuckPropBlock: \"\\<Gamma>\\<turnstile>([],(nrms,abrs)#css,Stuck) \\<rightarrow> (nrms,css,Stuck)\"\n\n| DynCom: \"\\<Gamma>\\<turnstile>(DynCom c#cs,css,Normal s) \\<rightarrow> (c s#cs,css,Normal s)\"\n\n| Throw: \"\\<Gamma>\\<turnstile>(Throw#cs,css,Normal s) \\<rightarrow> (cs,css,Abrupt s)\"\n| Catch: \"\\<Gamma>\\<turnstile>(Catch c\\<^sub>1 c\\<^sub>2#cs,css,Normal s) \\<rightarrow> ([c\\<^sub>1],(cs,c\\<^sub>2#cs)#css,Normal s)\"\n\nlemmas step_induct = step.induct [of _ \"(c,css,s)\" \"(c',css',s')\", split_format (complete), \ncase_names\nSkip Guard GuardFault FaultProp FaultPropBlock AbruptProp ExitBlockNormal ExitBlockAbrupt\nBasic Spec SpecStuck Seq CondTrue CondFalse WhileTrue WhileFalse Call CallUndefined\nStuckProp StuckPropBlock DynCom Throw Catch, induct set]\n\ninductive_cases step_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>(c#cs,css,Fault f) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>([],css,Fault f) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(c#cs,css,Stuck) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>([],css,Stuck) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(c#cs,css,Abrupt s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>([],css,Abrupt s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>([],css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Skip#cs,css,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Guard f g c#cs,css,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Basic f#cs,css,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Spec r#cs,css,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Seq c1 c2#cs,css,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Cond b c1 c2#cs,css,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(While b c#cs,css,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Call p#cs,css,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(DynCom c#cs,css,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Throw#cs,css,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Catch c1 c2#cs,css,s) \\<rightarrow> u\"\n\ninductive_cases step_Normal_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>(c#cs,css,Fault f) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>([],css,Fault f) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(c#cs,css,Stuck) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>([],css,Stuck) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>([],(nrms,abrs)#css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>([],(nrms,abrs)#css,Abrupt s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Skip#cs,css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Guard f g c#cs,css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Basic f#cs,css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Spec r#cs,css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Seq c1 c2#cs,css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Cond b c1 c2#cs,css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(While b c#cs,css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Call p#cs,css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(DynCom c#cs,css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Throw#cs,css,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>(Catch c1 c2#cs,css,Normal s) \\<rightarrow> u\"\n\nabbreviation\n \"step_rtrancl\" :: \"[('s,'p,'f) body,('s,'p,'f) config,('s,'p,'f) config] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile> (_ \\<rightarrow>\\<^sup>*/ _)\" [81,81,81] 100)\n  where\n  \"\\<Gamma>\\<turnstile>cs0 \\<rightarrow>\\<^sup>* cs1     == (step \\<Gamma>)\\<^sup>*\\<^sup>* cs0 cs1\"\n\nabbreviation\n\n \"step_trancl\" :: \"[('s,'p,'f) body,('s,'p,'f) config,('s,'p,'f) config] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile> (_ \\<rightarrow>\\<^sup>+/ _)\" [81,81,81] 100)\n  where\n  \"\\<Gamma>\\<turnstile>cs0 \\<rightarrow>\\<^sup>+ cs1     == (step \\<Gamma>)\\<^sup>+\\<^sup>+ cs0 cs1\"\n\n\nsubsubsection {* Structural Properties of Small Step Computations *}\n\nlemma Fault_app_steps: \"\\<Gamma>\\<turnstile>(cs@xs,css,Fault f) \\<rightarrow>\\<^sup>* (xs,css,Fault f)\"\nproof (induct cs)\n  case Nil thus ?case by simp\nnext\n  case (Cons c cs)\n  have \"\\<Gamma>\\<turnstile>(c#cs@xs, css, Fault f) \\<rightarrow>\\<^sup>* (xs, css, Fault f)\"\n  proof -\n    have \"\\<Gamma>\\<turnstile>(c#cs@xs, css, Fault f) \\<rightarrow> (cs@xs, css, Fault f)\"\n      by (rule step.FaultProp)\n    also \n    have \"\\<Gamma>\\<turnstile>(cs@xs, css, Fault f) \\<rightarrow>\\<^sup>* (xs, css, Fault f)\"\n      by (rule Cons.hyps)\n    finally show ?thesis .\n  qed\n  thus ?case\n    by simp\nqed\n\nlemma Stuck_app_steps: \"\\<Gamma>\\<turnstile>(cs@xs,css,Stuck) \\<rightarrow>\\<^sup>* (xs,css,Stuck)\"\nproof (induct cs)\n  case Nil thus ?case by simp\nnext\n  case (Cons c cs)\n  have \"\\<Gamma>\\<turnstile>(c#cs@xs, css, Stuck) \\<rightarrow>\\<^sup>* (xs, css, Stuck)\"\n  proof -\n    have \"\\<Gamma>\\<turnstile>(c#cs@xs, css, Stuck) \\<rightarrow> (cs@xs, css, Stuck)\"\n      by (rule step.StuckProp)\n    also \n    have \"\\<Gamma>\\<turnstile>(cs@xs, css, Stuck) \\<rightarrow>\\<^sup>* (xs, css, Stuck)\"\n      by (rule Cons.hyps)\n    finally show ?thesis .\n  qed\n  thus ?case\n    by simp\nqed\n\ntext {* We can only append commands inside a block, if execution does not\n        enter or exit a block.\n      *}\nlemma app_step:  \n  assumes step: \"\\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow> (cs',css',t)\"\n  shows \"css=css' \\<Longrightarrow> \\<Gamma>\\<turnstile>(cs@xs,css,s) \\<rightarrow> (cs'@xs,css',t)\"\nusing step\napply induct\napply (simp_all del: fun_upd_apply,(blast intro: step.intros)+)\ndone\n\ntext {* We can append whole blocks, without interfering with the actual\n        block. Outer blocks do not influence execution of\n        inner blocks. *}\nlemma app_css_step:  \n  assumes step: \"\\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow> (cs',css',t)\"\n  shows \"\\<Gamma>\\<turnstile>(cs,css@xs,s) \\<rightarrow> (cs',css'@xs,t)\"\nusing step\napply induct\napply (simp_all del: fun_upd_apply,(blast intro: step.intros)+)\ndone\n\nML {*\n  ML_Thms.bind_thm (\"trancl_induct3\", Split_Rule.split_rule @{context}\n    (Rule_Insts.read_instantiate @{context}\n      [(((\"a\", 0), Position.none), \"(ax, ay, az)\"),\n       (((\"b\", 0), Position.none), \"(bx, by, bz)\")] []\n      @{thm tranclp_induct}));\n*}\n\nlemma app_css_steps:  \n  assumes step: \"\\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow>\\<^sup>+ (cs',css',t)\"\n  shows \"\\<Gamma>\\<turnstile>(cs,css@xs,s) \\<rightarrow>\\<^sup>+ (cs',css'@xs,t)\"\napply(rule trancl_induct3 [OF step])\n apply (rule app_css_step [THEN tranclp.r_into_trancl [of \"step \\<Gamma>\"]],assumption)\napply(blast intro:app_css_step tranclp_trans)\ndone\n\nlemma step_Cons':  \n  assumes step: \"\\<Gamma>\\<turnstile>(ccs,css,s) \\<rightarrow> (cs',css',t)\"\n  shows\n  \"\\<And>c cs. ccs=c#cs \\<Longrightarrow> \\<exists>css''. css'=css''@css \\<and>\n      (if css''=[] then \\<exists>p. cs'=p@cs\n       else (\\<exists>pnorm pabr. css''=[(pnorm@cs,pabr@cs)]))\"\nusing step\nby induct force+\n\nlemma step_Cons:  \n  assumes step: \"\\<Gamma>\\<turnstile>(c#cs,css,s) \\<rightarrow> (cs',css',t)\"\n  shows \"\\<exists>pcss. css'=pcss@css \\<and>\n         (if pcss=[] then \\<exists>ps. cs'=ps@cs\n          else (\\<exists>pcs_normal pcs_abrupt. pcss=[(pcs_normal@cs,pcs_abrupt@cs)]))\"\nusing step_Cons' [OF step]\nby blast  \n\n\nlemma step_Nil':  \n  assumes step: \"\\<Gamma>\\<turnstile>(cs,asscss,s) \\<rightarrow> (cs',css',t)\"\n  shows\n  \"\\<And>ass. \\<lbrakk>cs=[]; asscss=ass@css; ass\\<noteq>Nil\\<rbrakk> \\<Longrightarrow> \n          css'=tl ass@css \\<and>\n          (case s of \n             Abrupt s' \\<Rightarrow> cs'=snd (hd ass) \\<and> t=Normal s'\n           |  _ \\<Rightarrow> cs'=fst (hd ass) \\<and> t=s)\"\nusing step\nby (induct) (fastforce simp add: neq_Nil_conv)+\n\nlemma step_Nil:  \n  assumes step: \"\\<Gamma>\\<turnstile>([],ass@css,s) \\<rightarrow> (cs',css',t)\"\n  assumes ass_not_Nil: \"ass\\<noteq>[]\"\n  shows \"css'=tl ass@css \\<and>\n          (case s of \n             Abrupt s' \\<Rightarrow> cs'=snd (hd ass) \\<and> t=Normal s'\n           |  _ \\<Rightarrow> cs'=fst (hd ass) \\<and> t=s)\"\n  using step_Nil' [OF step _ _ ass_not_Nil]\n  by simp\n\nlemma step_Nil'':  \n  assumes step: \"\\<Gamma>\\<turnstile>([],(pcs_normal,pcs_abrupt)#pcss@css,s) \\<rightarrow> (cs',pcss@css,t)\"\n  shows \"(case s of \n             Abrupt s' \\<Rightarrow> cs'=pcs_abrupt \\<and> t=Normal s'\n           |  _ \\<Rightarrow> cs'=pcs_normal \\<and> t=s)\"\n  using step_Nil' [OF step, where ass =\"(pcs_normal,pcs_abrupt)#pcss\" and css=\"css\"]\n  by (auto split: xstate.splits)\n\nlemma drop_suffix_css_step':\nassumes step: \"\\<Gamma>\\<turnstile>(cs,cssxs,s) \\<rightarrow> (cs',css'xs,t)\"\nshows \"\\<And>css css' xs. \\<lbrakk>cssxs = css@xs; css'xs=css'@xs\\<rbrakk> \n     \\<Longrightarrow> \\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow> (cs',css',t)\"\nusing step\napply induct\napply (fastforce intro: step.intros)+\ndone\n\nlemma drop_suffix_css_step:\nassumes step: \"\\<Gamma>\\<turnstile>(cs,pcss@css,s) \\<rightarrow> (cs',pcss'@css,t)\"\nshows \"\\<Gamma>\\<turnstile>(cs,pcss,s) \\<rightarrow> (cs',pcss',t)\"\nusing step by (blast intro: drop_suffix_css_step')\n\nlemma drop_suffix_hd_css_step': \n  assumes step: \"\\<Gamma>\\<turnstile> (pcs,css,s) \\<rightarrow> (cs',css'css,t)\"\n  shows \"\\<And>p ps cs pnorm pabr. \\<lbrakk>pcs=p#ps@cs; css'css=(pnorm@cs,pabr@cs)#css\\<rbrakk> \n         \\<Longrightarrow> \\<Gamma>\\<turnstile> (p#ps,css,s) \\<rightarrow> (cs',(pnorm,pabr)#css,t)\"\nusing step\nby induct (force intro: step.intros)+\n\nlemma drop_suffix_hd_css_step'': \n  assumes step: \"\\<Gamma>\\<turnstile> (p#ps@cs,css,s) \\<rightarrow> (cs',(pnorm@cs,pabr@cs)#css,t)\"\n  shows  \"\\<Gamma>\\<turnstile> (p#ps,css,s) \\<rightarrow> (cs',(pnorm,pabr)#css,t)\"\nusing drop_suffix_hd_css_step' [OF step]\nby auto\n\nlemma drop_suffix_hd_css_step: \n  assumes step: \"\\<Gamma>\\<turnstile> (p#ps@cs,css,s) \\<rightarrow> (cs',[(pnorm@ps@cs,pabr@ps@cs)]@css,t)\"\n  shows  \"\\<Gamma>\\<turnstile> (p#ps,css,s) \\<rightarrow> (cs',[(pnorm@ps,pabr@ps)]@css,t)\"\nproof -\n  from step drop_suffix_hd_css_step'' [of _ p ps cs css s cs' \"pnorm@ps\" \"pabr@ps\" t]\n  show ?thesis\n    by auto\nqed\n\nlemma drop_suffix':  \n  assumes step: \"\\<Gamma>\\<turnstile>(csxs,css,s) \\<rightarrow> (cs'xs,css',t)\"\n  shows \"\\<And>xs cs cs'. \\<lbrakk>css=css'; csxs=cs@xs; cs'xs = cs'@xs; cs\\<noteq>[] \\<rbrakk> \n         \\<Longrightarrow> \\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow> (cs',css,t)\"\nusing step\napply induct\napply (fastforce intro: step.intros simp add: neq_Nil_conv)+\ndone\n\nlemma drop_suffix: \n  assumes step: \"\\<Gamma>\\<turnstile>(c#cs@xs,css,s) \\<rightarrow> (cs'@xs,css,t)\" \n  shows \"\\<Gamma>\\<turnstile>(c#cs,css,s) \\<rightarrow> (cs',css,t)\"\n  by(rule drop_suffix' [OF step _ _ _]) auto\n\nlemma drop_suffix_same_css_step: \n  assumes step: \"\\<Gamma>\\<turnstile>(cs@xs,css,s) \\<rightarrow> (cs'@xs,css,t)\" \n  assumes not_Nil: \"cs\\<noteq>[]\"\n  shows \"\\<Gamma>\\<turnstile>(cs,xss,s) \\<rightarrow> (cs',xss,t)\"\nproof-\n  from drop_suffix' [OF step _ _ _ not_Nil]\n  have \"\\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow> (cs',css,t)\"\n    by auto\n  with drop_suffix_css_step [of _ cs \"[]\" css s cs' \"[]\" t]\n  have \"\\<Gamma>\\<turnstile> (cs, [], s) \\<rightarrow> (cs', [], t)\"\n    by auto\n  from app_css_step [OF this]\n  show ?thesis\n    by auto\nqed\n \nlemma Cons_change_css_step:\n  assumes step: \"\\<Gamma>\\<turnstile> (cs,css,s) \\<rightarrow> (cs',css'@css,t)\"\n  shows \"\\<Gamma>\\<turnstile> (cs,xss,s) \\<rightarrow> (cs',css'@xss,t)\"\nproof -\n  from step\n    drop_suffix_css_step [where cs=cs and pcss=\"[]\" and css=css and s=s\n                             and cs'=cs' and pcss'=css' and t=t]\n  have \"\\<Gamma>\\<turnstile> (cs, [], s) \\<rightarrow> (cs', css', t)\"\n    by auto\n  from app_css_step [where xs=xss, OF this]\n  show ?thesis\n    by auto\nqed\n\nlemma Nil_change_css_step:\n  assumes step: \"\\<Gamma>\\<turnstile>([],ass@css,s) \\<rightarrow> (cs',ass'@css,t)\"\n  assumes ass_not_Nil: \"ass\\<noteq>[]\"\n  shows \"\\<Gamma>\\<turnstile>([],ass@xss,s) \\<rightarrow> (cs',ass'@xss,t)\"\nproof -\n  from step drop_suffix_css_step [of _ \"[]\" ass css s cs' ass' t]\n  have \"\\<Gamma>\\<turnstile> ([], ass, s) \\<rightarrow> (cs', ass', t)\"\n    by auto\n  from app_css_step [where xs=xss, OF this]\n  show ?thesis\n    by auto\nqed\n\nsubsubsection {* Equivalence between Big and Small-Step Semantics *}\n    \nlemma exec_impl_steps:\n  assumes exec: \"\\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t\"\n  shows \"\\<And>cs css. \\<Gamma>\\<turnstile>(c#cs,css,s) \\<rightarrow>\\<^sup>* (cs,css,t)\"\nusing exec\nproof (induct)\n  case Skip thus ?case by (blast intro: step.Skip)\nnext\n  case Guard thus ?case by (blast intro: step.Guard rtranclp_trans)\nnext\n  case GuardFault thus ?case by (blast intro: step.GuardFault)\nnext\n  case FaultProp thus ?case by (blast intro: step.FaultProp)\nnext\n  case Basic thus ?case by (blast intro: step.Basic)\nnext\n  case Spec thus ?case by (blast intro: step.Spec)\nnext\n  case SpecStuck thus ?case by (blast intro: step.SpecStuck)\nnext\n  case Seq thus ?case by (blast intro: step.Seq rtranclp_trans)\nnext\n  case CondTrue thus ?case by (blast intro: step.CondTrue rtranclp_trans)\nnext\n  case CondFalse thus ?case by (blast intro: step.CondFalse rtranclp_trans)\nnext\n  case WhileTrue thus ?case by (blast intro: step.WhileTrue rtranclp_trans)\nnext\n  case WhileFalse thus ?case by (blast intro: step.WhileFalse)\nnext\n  case (Call p bdy s s' cs css)\n  have bdy: \"\\<Gamma> p = Some bdy\" by fact\n  have steps_body: \"\\<Gamma>\\<turnstile>([bdy],(cs,Throw#cs)#css,Normal s) \\<rightarrow>\\<^sup>* \n                       ([],(cs,Throw#cs)#css, s')\" by fact\n  show ?case\n  proof (cases s')\n    case (Normal s'')\n    note steps_body\n    also from Normal have \"\\<Gamma>\\<turnstile>([],(cs,Throw#cs)#css, s') \\<rightarrow> (cs,css,s')\"\n      by (auto intro: step.intros)\n    finally show ?thesis\n      using bdy\n      by (blast intro: step.Call rtranclp_trans)\n  next\n    case (Abrupt s'')\n    with steps_body \n    have \"\\<Gamma>\\<turnstile>([bdy],(cs,Throw#cs)#css,Normal s) \\<rightarrow>\\<^sup>* \n             ([],(cs,Throw#cs)#css, Abrupt s'')\" by simp\n    also have \"\\<Gamma>\\<turnstile>([],(cs,Throw#cs)#css, Abrupt s'') \\<rightarrow> (Throw#cs,css,Normal s'')\"\n      by (rule ExitBlockAbrupt)\n    also have \"\\<Gamma>\\<turnstile>(Throw#cs,css,Normal s'') \\<rightarrow> (cs,css,Abrupt s'')\"\n      by (rule Throw)\n    finally show ?thesis\n      using bdy Abrupt\n      by (auto intro: step.Call rtranclp_trans)\n  next\n    case Fault\n    note steps_body\n    also from Fault have \"\\<Gamma>\\<turnstile>([],(cs,Throw#cs)#css, s') \\<rightarrow> (cs,css,s')\"\n      by (auto intro: step.intros)\n    finally show ?thesis\n      using bdy\n      by (blast intro: step.Call rtranclp_trans)\n  next\n    case Stuck\n    note steps_body\n    also from Stuck have \"\\<Gamma>\\<turnstile>([],(cs,Throw#cs)#css, s') \\<rightarrow> (cs,css,s')\"\n      by (auto intro: step.intros)\n    finally show ?thesis\n      using bdy\n      by (blast intro: step.Call rtranclp_trans)\n  qed\nnext\n  case (CallUndefined p s cs css)\n  have undef: \"\\<Gamma> p = None\" by fact\n  hence \"\\<Gamma>\\<turnstile>(Call p # cs, css, Normal s) \\<rightarrow> (cs, css, Stuck)\"\n    by (rule step.CallUndefined)\n  thus ?case ..\nnext\n  case StuckProp thus ?case by (blast intro: step.StuckProp rtrancl_trans)\nnext\n  case DynCom thus ?case by (blast intro: step.DynCom rtranclp_trans)\nnext\n   case Throw thus ?case by (blast intro: step.Throw)\nnext\n  case AbruptProp thus ?case by (blast intro: step.AbruptProp)\nnext\n  case (CatchMatch c\\<^sub>1 s s' c\\<^sub>2 s'' cs css) \n  have steps_c1: \"\\<Gamma>\\<turnstile>([c\\<^sub>1],(cs,c\\<^sub>2#cs)#css,Normal s) \\<rightarrow>\\<^sup>* \n                    ([],(cs,c\\<^sub>2#cs)#css,Abrupt s')\" by fact\n  also\n  have \"\\<Gamma>\\<turnstile>([],(cs,c\\<^sub>2#cs)#css,Abrupt s') \\<rightarrow> (c\\<^sub>2#cs,css,Normal s')\"\n    by (rule ExitBlockAbrupt)\n  also \n  have steps_c2: \"\\<Gamma>\\<turnstile>(c\\<^sub>2#cs,css,Normal s') \\<rightarrow>\\<^sup>* (cs,css,s'')\"  by fact\n  finally\n  show \"\\<Gamma>\\<turnstile>(Catch c\\<^sub>1 c\\<^sub>2 # cs, css, Normal s) \\<rightarrow>\\<^sup>* (cs, css, s'')\"\n    by (blast intro: step.Catch rtranclp_trans)\nnext\n  case (CatchMiss c\\<^sub>1 s s' c\\<^sub>2 cs css) \n  assume notAbr: \"\\<not> isAbr s'\"\n  have steps_c1: \"\\<Gamma>\\<turnstile>([c\\<^sub>1],(cs,c\\<^sub>2#cs)#css,Normal s) \\<rightarrow>\\<^sup>* ([],(cs,c\\<^sub>2#cs)#css,s')\" by fact\n  show \"\\<Gamma>\\<turnstile>(Catch c\\<^sub>1 c\\<^sub>2 # cs, css, Normal s) \\<rightarrow>\\<^sup>* (cs, css, s')\"\n  proof (cases s')\n    case (Normal w)\n    with steps_c1\n    have \"\\<Gamma>\\<turnstile>([c\\<^sub>1],(cs,c\\<^sub>2#cs)#css,Normal s) \\<rightarrow>\\<^sup>* ([],(cs,c\\<^sub>2#cs)#css,Normal w)\"\n      by simp\n    also\n    have \"\\<Gamma>\\<turnstile>([],(cs,c\\<^sub>2#cs)#css,Normal w) \\<rightarrow> (cs,css,Normal w)\"\n      by (rule ExitBlockNormal)\n    finally show ?thesis using Normal\n      by (auto intro: step.Catch rtranclp_trans)\n  next\n    case Abrupt with notAbr show ?thesis by simp\n  next\n    case (Fault f)\n    with steps_c1\n    have \"\\<Gamma>\\<turnstile>([c\\<^sub>1],(cs,c\\<^sub>2#cs)#css,Normal s) \\<rightarrow>\\<^sup>* ([],(cs,c\\<^sub>2#cs)#css,Fault f)\"\n      by simp\n    also\n    have \"\\<Gamma>\\<turnstile>([],(cs,c\\<^sub>2#cs)#css,Fault f) \\<rightarrow> (cs,css,Fault f)\"\n      by (rule FaultPropBlock)\n    finally show ?thesis using Fault\n      by (auto intro: step.Catch rtranclp_trans)\n  next\n    case Stuck\n    with steps_c1\n    have \"\\<Gamma>\\<turnstile>([c\\<^sub>1],(cs,c\\<^sub>2#cs)#css,Normal s) \\<rightarrow>\\<^sup>* ([],(cs,c\\<^sub>2#cs)#css,Stuck)\"\n      by simp\n    also\n    have \"\\<Gamma>\\<turnstile>([],(cs,c\\<^sub>2#cs)#css,Stuck) \\<rightarrow> (cs,css,Stuck)\"\n      by (rule StuckPropBlock)\n    finally show ?thesis using Stuck\n      by (auto intro: step.Catch rtranclp_trans)\n  qed\nqed\n\n\ninductive \"execs\"::\"[('s,'p,'f) body,('s,'p,'f) com list,\n                      ('s,'p,'f) continuation list,\n                      ('s,'f) xstate,('s,'f) xstate] \\<Rightarrow> bool\"\n                   (\"_\\<turnstile> \\<langle>_,_,_\\<rangle> \\<Rightarrow> _\" [50,50,50,50,50] 50)\n  for \\<Gamma>:: \"('s,'p,'f) body\"\nwhere\n  Nil: \"\\<Gamma>\\<turnstile>\\<langle>[],[],s\\<rangle> \\<Rightarrow> s\"\n\n| ExitBlockNormal: \"\\<Gamma>\\<turnstile>\\<langle>nrms,css,Normal s\\<rangle> \\<Rightarrow> t\n                    \\<Longrightarrow>\n                    \\<Gamma>\\<turnstile>\\<langle>[],(nrms,abrs)#css,Normal s\\<rangle> \\<Rightarrow> t\"\n\n| ExitBlockAbrupt: \"\\<Gamma>\\<turnstile>\\<langle>abrs,css,Normal s\\<rangle> \\<Rightarrow> t\n                    \\<Longrightarrow>\n                    \\<Gamma>\\<turnstile>\\<langle>[],(nrms,abrs)#css,Abrupt s\\<rangle> \\<Rightarrow> t\"\n\n| ExitBlockFault: \"\\<Gamma>\\<turnstile>\\<langle>nrms,css,Fault f\\<rangle> \\<Rightarrow> t\n                    \\<Longrightarrow>\n                    \\<Gamma>\\<turnstile>\\<langle>[],(nrms,abrs)#css,Fault f\\<rangle> \\<Rightarrow> t\"\n\n| ExitBlockStuck: \"\\<Gamma>\\<turnstile>\\<langle>nrms,css,Stuck\\<rangle> \\<Rightarrow> t\n                    \\<Longrightarrow>\n                    \\<Gamma>\\<turnstile>\\<langle>[],(nrms,abrs)#css,Stuck\\<rangle> \\<Rightarrow> t\"\n\n| Cons: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t; \\<Gamma>\\<turnstile>\\<langle>cs,css,t\\<rangle> \\<Rightarrow> u\\<rbrakk> \n         \\<Longrightarrow> \n         \\<Gamma>\\<turnstile>\\<langle>c#cs,css,s\\<rangle> \\<Rightarrow> u\"\n\n\ninductive_cases execs_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>\\<langle>[],css,s\\<rangle> \\<Rightarrow> t\"\n \"\\<Gamma>\\<turnstile>\\<langle>c#cs,css,s\\<rangle> \\<Rightarrow> t\"\n\nML {*\n  ML_Thms.bind_thm (\"converse_rtrancl_induct3\", Split_Rule.split_rule @{context}\n    (Rule_Insts.read_instantiate @{context}\n      [(((\"a\", 0), Position.none), \"(cs, css, s)\"),\n       (((\"b\", 0), Position.none), \"(cs', css', t)\")] []\n      @{thm converse_rtranclp_induct}));\n*}\n\nlemma execs_Fault_end: \n  assumes execs: \"\\<Gamma>\\<turnstile>\\<langle>cs,css,s\\<rangle> \\<Rightarrow> t\" shows \"s=Fault f\\<Longrightarrow> t=Fault f\"\n  using execs\n  by (induct) (auto dest: Fault_end)\n\nlemma execs_Stuck_end: \n  assumes execs: \"\\<Gamma>\\<turnstile>\\<langle>cs,css,s\\<rangle> \\<Rightarrow> t\" shows \"s=Stuck \\<Longrightarrow> t=Stuck\"\n  using execs\n  by (induct) (auto dest: Stuck_end)\n\n\ntheorem steps_impl_execs: \n  assumes steps: \"\\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow>\\<^sup>* ([],[],t)\" \n  shows \"\\<Gamma>\\<turnstile>\\<langle>cs,css,s\\<rangle> \\<Rightarrow> t\"\nusing steps\nproof (induct rule: converse_rtrancl_induct3 [consumes 1])\n  show \"\\<Gamma>\\<turnstile>\\<langle>[],[],t\\<rangle> \\<Rightarrow> t\" by (rule execs.Nil)\nnext\n  fix cs css s cs' css' w\n  assume step: \"\\<Gamma>\\<turnstile>(cs,css, s) \\<rightarrow> (cs',css', w)\" \n  assume execs: \"\\<Gamma>\\<turnstile>\\<langle>cs',css',w\\<rangle> \\<Rightarrow> t\"\n  from step \n  show \"\\<Gamma>\\<turnstile>\\<langle>cs,css,s\\<rangle> \\<Rightarrow> t\"\n  proof (cases)\n    case (Catch c1 c2 cs s)\n    with execs obtain t' where\n      exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> t'\" and\n      execs_rest: \"\\<Gamma>\\<turnstile>\\<langle>[],(cs, c2 # cs) # css,t'\\<rangle> \\<Rightarrow> t\"\n      by (clarsimp elim!: execs_elim_cases)\n    have  \"\\<Gamma>\\<turnstile>\\<langle>Catch c1 c2 # cs,css,Normal s\\<rangle> \\<Rightarrow> t\"\n    proof (cases t')\n      case (Normal t'')\n      with exec_c1 have \"\\<Gamma>\\<turnstile>\\<langle>Catch c1 c2,Normal s\\<rangle> \\<Rightarrow> t'\"\n        by (auto intro: exec.CatchMiss)\n      moreover\n      from execs_rest Normal have \"\\<Gamma>\\<turnstile>\\<langle>cs,css,t'\\<rangle> \\<Rightarrow> t\"\n        by (cases) auto\n      ultimately show ?thesis\n        by (rule execs.Cons)\n    next\n      case (Abrupt t'')\n      from execs_rest Abrupt have \"\\<Gamma>\\<turnstile>\\<langle>c2#cs,css,Normal t''\\<rangle> \\<Rightarrow> t\"\n        by (cases) auto\n      then obtain v where\n          exec_c2: \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal t''\\<rangle> \\<Rightarrow> v\" and\n          rest: \"\\<Gamma>\\<turnstile>\\<langle>cs,css,v\\<rangle> \\<Rightarrow> t\"\n        by cases\n      from exec_c1 Abrupt exec_c2\n      have \"\\<Gamma>\\<turnstile>\\<langle>Catch c1 c2,Normal s\\<rangle> \\<Rightarrow> v\"\n        by  - (rule exec.CatchMatch, auto)\n      from this rest\n      show ?thesis\n        by (rule execs.Cons)\n    next\n      case (Fault f)\n      with exec_c1 have \"\\<Gamma>\\<turnstile>\\<langle>Catch c1 c2,Normal s\\<rangle> \\<Rightarrow> Fault f\"\n        by (auto intro: exec.intros)\n      moreover from execs_rest Fault have \"\\<Gamma>\\<turnstile>\\<langle>cs,css,Fault f\\<rangle> \\<Rightarrow> t\"\n        by (cases) auto\n      ultimately show ?thesis\n        by (rule execs.Cons)\n    next\n      case Stuck\n      with exec_c1 have \"\\<Gamma>\\<turnstile>\\<langle>Catch c1 c2,Normal s\\<rangle> \\<Rightarrow> Stuck\"\n        by (auto intro: exec.intros)\n      moreover from execs_rest Stuck have \"\\<Gamma>\\<turnstile>\\<langle>cs,css,Stuck\\<rangle> \\<Rightarrow> t\"\n        by (cases) auto\n      ultimately show ?thesis\n        by (rule execs.Cons)\n    qed\n    with Catch show ?thesis by simp\n  next\n    case (Call p bdy cs s)\n    have bdy: \"\\<Gamma> p = Some bdy\" by fact\n    from Call execs obtain t' where\n      exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal s\\<rangle> \\<Rightarrow> t'\" and\n      execs_rest: \n            \"\\<Gamma>\\<turnstile>\\<langle>[],(cs,Throw#cs)#css ,t'\\<rangle> \\<Rightarrow> t\"\n       by (clarsimp elim!: execs_elim_cases)\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call p # cs,css,Normal s\\<rangle> \\<Rightarrow> t\"\n    proof (cases t')\n      case (Normal t'')\n      with exec_body bdy\n      have \"\\<Gamma>\\<turnstile>\\<langle>Call p ,Normal s\\<rangle> \\<Rightarrow> Normal t''\" \n        by (auto intro: exec.intros)\n      moreover\n      from execs_rest Normal\n      have \"\\<Gamma>\\<turnstile>\\<langle>cs,css ,Normal t''\\<rangle> \\<Rightarrow> t\" \n        by cases auto\n      ultimately show ?thesis by (rule execs.Cons)\n    next\n      case (Abrupt t'')\n      with exec_body bdy\n      have \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow> Abrupt t''\"\n        by (auto intro: exec.intros)\n      moreover\n      from execs_rest Abrupt have \n        \"\\<Gamma>\\<turnstile>\\<langle>Throw # cs,css,Normal t''\\<rangle> \\<Rightarrow> t\"\n        by (cases) auto\n      then obtain v where \n        \"\\<Gamma>\\<turnstile>\\<langle>Throw,Normal t''\\<rangle> \\<Rightarrow> v\" and \n        rest: \"\\<Gamma>\\<turnstile>\\<langle>cs,css,v\\<rangle> \\<Rightarrow> t\"\n        by (clarsimp elim!: execs_elim_cases)\n      moreover from this have \"v=Abrupt t''\"\n        by (auto elim: exec_Normal_elim_cases)\n      ultimately \n      show ?thesis by (auto intro: execs.Cons)\n    next\n      case (Fault f)\n      with exec_body bdy have \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow> Fault f\"\n        by (auto intro: exec.intros)\n      moreover from execs_rest Fault have \"\\<Gamma>\\<turnstile>\\<langle>cs,css,Fault f\\<rangle> \\<Rightarrow> t\"\n        by (cases) (auto elim: execs_elim_cases dest: Fault_end)\n      ultimately \n      show ?thesis by (rule execs.Cons)\n    next\n      case Stuck\n      with exec_body bdy have \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow> Stuck\"\n        by (auto intro: exec.intros)\n      moreover from execs_rest Stuck have \"\\<Gamma>\\<turnstile>\\<langle>cs,css,Stuck\\<rangle> \\<Rightarrow> t\"\n        by (cases) (auto elim: execs_elim_cases dest: Stuck_end)\n      ultimately \n      show ?thesis by (rule execs.Cons)\n    qed \n    with Call show ?thesis by simp\n  qed (insert execs,\n      (blast intro:execs.intros exec.intros elim!: execs_elim_cases)+)\nqed\n\ntheorem steps_impl_exec: \n  assumes steps: \"\\<Gamma>\\<turnstile>([c],[],s) \\<rightarrow>\\<^sup>* ([],[],t)\" \n  shows \"\\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t\"\nusing steps_impl_execs [OF steps]\nby (blast elim: execs_elim_cases)\n\ncorollary steps_eq_exec: \"\\<Gamma>\\<turnstile>([c],[],s) \\<rightarrow>\\<^sup>* ([],[],t) = \\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t\"\n  by (blast intro: steps_impl_exec exec_impl_steps)\n\n\nsubsection {* Infinite Computations: @{text \"inf \\<Gamma> cs css s\"}*}\n\ndefinition inf :: \n \"[('s,'p,'f) body,('s,'p,'f) com list,('s,'p,'f) continuation list,('s,'f) xstate]\n  \\<Rightarrow> bool\"\nwhere \"inf \\<Gamma> cs css s = (\\<exists>f. f 0 = (cs,css,s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f(Suc i)))\"\n\nlemma not_infI: \"\\<lbrakk>\\<And>f. \\<lbrakk>f 0 = (cs,css,s); \\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\\<rbrakk> \\<Longrightarrow> False\\<rbrakk>  \n                \\<Longrightarrow> \\<not>inf \\<Gamma> cs css s\"\n  by (auto simp add: inf_def)\n\nsubsection {* Equivalence of Termination and Absence of Infinite Computations *}\n\n\ninductive \"terminatess\":: \"[('s,'p,'f) body,('s,'p,'f) com list,\n                            ('s,'p,'f) continuation list,('s,'f) xstate] \\<Rightarrow> bool\" \n                (\"_\\<turnstile>_,_ \\<Down> _\" [60,20,60] 89)\n  for  \\<Gamma>::\"('s,'p,'f) body\"\nwhere\n   Nil: \"\\<Gamma>\\<turnstile>[],[]\\<Down>s\"\n\n|  ExitBlockNormal: \"\\<Gamma>\\<turnstile>nrms,css\\<Down>Normal s\n                     \\<Longrightarrow> \n                     \\<Gamma>\\<turnstile>[],(nrms,abrs)#css\\<Down>Normal s\"\n\n|  ExitBlockAbrupt: \"\\<Gamma>\\<turnstile>abrs,css\\<Down>Normal s\n                     \\<Longrightarrow> \n                     \\<Gamma>\\<turnstile>[],(nrms,abrs)#css\\<Down>Abrupt s\"\n\n|  ExitBlockFault: \"\\<Gamma>\\<turnstile>nrms,css\\<Down>Fault f\n                    \\<Longrightarrow> \n                    \\<Gamma>\\<turnstile>[],(nrms,abrs)#css\\<Down>Fault f\"\n\n|  ExitBlockStuck: \"\\<Gamma>\\<turnstile>nrms,css\\<Down>Stuck\n                    \\<Longrightarrow> \n                    \\<Gamma>\\<turnstile>[],(nrms,abrs)#css\\<Down>Stuck\"\n\n\n|  Cons: \"\\<lbrakk>\\<Gamma>\\<turnstile>c\\<down>s; (\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t \\<longrightarrow> \\<Gamma>\\<turnstile>cs,css\\<Down>t)\\<rbrakk>\n          \\<Longrightarrow> \n          \\<Gamma>\\<turnstile>c#cs,css\\<Down>s\"\n \ninductive_cases terminatess_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>[],css\\<Down>t\"\n \"\\<Gamma>\\<turnstile>c#cs,css\\<Down>t\"\n\nlemma terminatess_Fault: \"\\<And>cs. \\<Gamma>\\<turnstile>cs,css\\<Down>Fault f\"\nproof (induct css)\n  case Nil\n  show \"\\<Gamma>\\<turnstile>cs,[]\\<Down>Fault f\"\n  proof (induct cs)\n    case Nil show \"\\<Gamma>\\<turnstile>[],[]\\<Down>Fault f\" by (rule terminatess.Nil)\n  next\n    case (Cons c cs)\n    thus ?case\n      by (auto intro: terminatess.intros terminates.intros dest: Fault_end)\n  qed\nnext\n  case (Cons d css)\n  have hyp: \"\\<And>cs. \\<Gamma>\\<turnstile>cs,css\\<Down>Fault f\" by fact\n  obtain nrms abrs where d: \"d=(nrms,abrs)\"  by (cases d) auto\n  have \"\\<Gamma>\\<turnstile>cs,(nrms,abrs)#css\\<Down>Fault f\"\n  proof (induct cs)\n    case Nil\n    show \"\\<Gamma>\\<turnstile>[],(nrms, abrs) # css\\<Down>Fault f\"\n      by (rule terminatess.ExitBlockFault) (rule hyp)\n  next\n    case (Cons c cs)\n    have hyp1: \"\\<Gamma>\\<turnstile>cs,(nrms, abrs) # css\\<Down>Fault f\" by fact\n    show \"\\<Gamma>\\<turnstile>c#cs,(nrms, abrs)#css\\<Down>Fault f\"\n      by (auto intro: hyp1 terminatess.Cons terminates.intros dest: Fault_end)\n  qed\n  with d show ?case by simp\nqed\n\nlemma terminatess_Stuck: \"\\<And>cs. \\<Gamma>\\<turnstile>cs,css\\<Down>Stuck\"\nproof (induct css)\n  case Nil\n  show \"\\<Gamma>\\<turnstile>cs,[]\\<Down>Stuck\"\n  proof (induct cs)\n    case Nil show \"\\<Gamma>\\<turnstile>[],[]\\<Down>Stuck\" by (rule terminatess.Nil)\n  next\n    case (Cons c cs)\n    thus ?case\n      by (auto intro: terminatess.intros terminates.intros dest: Stuck_end)\n  qed\nnext\n  case (Cons d css)\n  have hyp: \"\\<And>cs. \\<Gamma>\\<turnstile>cs,css\\<Down>Stuck\" by fact\n  obtain nrms abrs where d: \"d=(nrms,abrs)\" by (cases d) auto\n  have \"\\<Gamma>\\<turnstile>cs,(nrms,abrs)#css\\<Down>Stuck\"\n  proof (induct cs)\n    case Nil\n    show \"\\<Gamma>\\<turnstile>[],(nrms, abrs) # css\\<Down>Stuck\"\n      by (rule terminatess.ExitBlockStuck) (rule hyp)\n  next\n    case (Cons c cs)\n    have hyp1: \"\\<Gamma>\\<turnstile>cs,(nrms, abrs) # css\\<Down>Stuck\" by fact\n    show \"\\<Gamma>\\<turnstile>c#cs,(nrms, abrs)#css\\<Down>Stuck\"\n      by (auto intro: hyp1 terminatess.Cons terminates.intros dest: Stuck_end)\n  qed\n  with d show ?case by simp\nqed\n\n\nlemma Basic_terminates: \"\\<Gamma>\\<turnstile>Basic f \\<down> t\"\n  by (cases t) (auto intro: terminates.intros)\n\nlemma step_preserves_terminations: \n  assumes step: \"\\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow> (cs',css',t)\" \n  shows \"\\<Gamma>\\<turnstile>cs,css\\<Down>s \\<Longrightarrow> \\<Gamma>\\<turnstile>cs',css'\\<Down>t\"\nusing step\nproof (induct)\n  case Skip thus ?case\n    by (auto elim: terminates_Normal_elim_cases terminatess_elim_cases\n             intro: exec.intros)\nnext\n  case Guard thus ?case \n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n             intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case GuardFault thus ?case\n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case FaultProp show ?case by (rule terminatess_Fault)\nnext\n  case FaultPropBlock show ?case by (rule terminatess_Fault)\nnext\n  case AbruptProp thus ?case\n    by (blast elim: terminatess_elim_cases \n              intro: terminatess.intros)\nnext\n  case ExitBlockNormal thus ?case\n    by (blast elim: terminatess_elim_cases\n              intro: terminatess.intros )\nnext\n  case ExitBlockAbrupt thus ?case\n    by (blast elim: terminatess_elim_cases\n              intro: terminatess.intros )\nnext\n  case Basic thus ?case \n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case Spec thus ?case \n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case SpecStuck thus ?case \n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case Seq thus ?case \n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case CondTrue thus ?case \n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case CondFalse thus ?case \n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case WhileTrue thus ?case\n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case WhileFalse thus ?case\n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case (Call p bdy cs css s)\n  have bdy: \"\\<Gamma> p = Some bdy\" by fact\n  from Call obtain \n    term_body: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal s\" and\n    term_rest: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow> t \\<longrightarrow> \\<Gamma>\\<turnstile>cs,css\\<Down>t\"\n    by (fastforce elim!: terminatess_elim_cases terminates_Normal_elim_cases)\n  show \"\\<Gamma>\\<turnstile>[bdy],(cs,Throw # cs)#css\\<Down>Normal s\"\n  proof (rule terminatess.Cons [OF term_body],clarsimp)\n    fix t\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal s\\<rangle> \\<Rightarrow> t\"\n    show \"\\<Gamma>\\<turnstile>[],(cs,Throw # cs) # css\\<Down>t\"\n    proof (cases t)\n      case (Normal t')\n      with exec_body bdy\n      have \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow> Normal t'\"\n        by (auto intro: exec.intros)\n      with term_rest have \"\\<Gamma>\\<turnstile>cs,css\\<Down>Normal t'\"\n        by iprover\n      with Normal show ?thesis\n        by (auto intro: terminatess.intros terminates.intros\n                 elim: exec_Normal_elim_cases)\n    next\n      case (Abrupt t')\n      with exec_body bdy\n      have \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow> Abrupt t'\"\n        by (auto intro: exec.intros)\n      with term_rest have \"\\<Gamma>\\<turnstile>cs,css\\<Down>Abrupt t'\"\n        by iprover\n      with Abrupt show ?thesis\n        by (fastforce intro: terminatess.intros terminates.intros\n                     elim: exec_Normal_elim_cases)\n    next\n      case Fault\n      thus ?thesis\n        by (iprover intro: terminatess_Fault)\n    next\n      case Stuck\n      thus ?thesis\n        by (iprover intro: terminatess_Stuck)\n    qed\n  qed\nnext\n  case CallUndefined thus ?case\n    by (iprover intro: terminatess_Stuck)\nnext\n  case StuckProp show ?case by (rule terminatess_Stuck)\nnext\n  case StuckPropBlock show ?case by (rule terminatess_Stuck)\nnext\n  case DynCom thus ?case\n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case Throw thus ?case\n    by (blast elim: terminatess_elim_cases terminates_Normal_elim_cases\n              intro: terminatess.intros terminates.intros exec.intros)\nnext\n  case (Catch c1 c2 cs css s) \n  then obtain \n    term_c1: \"\\<Gamma>\\<turnstile>c1 \\<down> Normal s\" and\n    term_c2: \"\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> Abrupt s' \\<longrightarrow> \\<Gamma>\\<turnstile>c2 \\<down> Normal s'\"and\n    term_rest: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>Catch c1 c2,Normal s\\<rangle> \\<Rightarrow> t \\<longrightarrow> \\<Gamma>\\<turnstile>cs,css\\<Down>t\"\n    by (clarsimp elim!: terminatess_elim_cases terminates_Normal_elim_cases)\n  show \"\\<Gamma>\\<turnstile>[c1],(cs, c2 # cs) # css\\<Down>Normal s\"\n  proof (rule terminatess.Cons [OF term_c1],clarsimp)\n    fix t\n    assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> t\" \n    show \"\\<Gamma>\\<turnstile>[],(cs, c2 # cs) # css\\<Down>t\"\n    proof (cases t)\n      case (Normal t')\n      with exec_c1 have \"\\<Gamma>\\<turnstile>\\<langle>Catch c1 c2,Normal s\\<rangle> \\<Rightarrow> t\" \n        by (auto intro: exec.intros)\n      with term_rest have \"\\<Gamma>\\<turnstile>cs,css\\<Down>t\"\n        by iprover\n      with Normal show ?thesis\n        by (iprover intro: terminatess.intros)\n    next\n      case (Abrupt t')\n      with exec_c1 term_c2 have \"\\<Gamma>\\<turnstile>c2 \\<down> Normal t'\"\n        by auto\n      moreover\n      {\n        fix w\n        assume exec_c2: \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal t'\\<rangle> \\<Rightarrow> w\" \n        have \"\\<Gamma>\\<turnstile>cs,css\\<Down>w\" \n        proof -\n          from exec_c1 Abrupt exec_c2\n          have \"\\<Gamma>\\<turnstile>\\<langle>Catch c1 c2,Normal s\\<rangle> \\<Rightarrow> w\"\n            by (auto intro: exec.intros)\n          with term_rest show ?thesis by simp\n        qed\n      }\n      ultimately\n      show ?thesis using Abrupt\n        by (auto intro: terminatess.intros)\n    next\n      case Fault thus ?thesis\n        by (iprover intro: terminatess_Fault)\n    next\n      case Stuck thus ?thesis\n        by (iprover intro: terminatess_Stuck)\n    qed\n  qed\nqed\n\n\nML {*\n  ML_Thms.bind_thm (\"rtrancl_induct3\", Split_Rule.split_rule @{context}\n    (Rule_Insts.read_instantiate @{context}\n      [(((\"a\", 0), Position.none), \"(ax, ay, az)\"),\n       (((\"b\", 0), Position.none), \"(bx, by, bz)\")] []\n      @{thm rtranclp_induct}));\n*}\n\nlemma steps_preserves_terminations: \n  assumes steps: \"\\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow>\\<^sup>* (cs',css',t)\" \n  shows \"\\<Gamma>\\<turnstile>cs,css\\<Down>s \\<Longrightarrow> \\<Gamma>\\<turnstile>cs',css'\\<Down>t\"\nusing steps\nproof (induct rule: rtrancl_induct3 [consumes 1])\n  assume  \"\\<Gamma>\\<turnstile>cs,css\\<Down>s\" then show \"\\<Gamma>\\<turnstile>cs,css\\<Down>s\". \nnext\n  fix cs'' css'' w cs' css' t\n  assume \"\\<Gamma>\\<turnstile>(cs'',css'', w) \\<rightarrow> (cs',css', t)\" \"\\<Gamma>\\<turnstile>cs,css\\<Down>s \\<Longrightarrow> \\<Gamma>\\<turnstile>cs'',css''\\<Down>w\"\n         \"\\<Gamma>\\<turnstile>cs,css\\<Down>s\"\n  then show \"\\<Gamma>\\<turnstile>cs',css'\\<Down>t\"\n    by (blast dest: step_preserves_terminations)\nqed\n\ntheorem steps_preserves_termination: \n  assumes steps: \"\\<Gamma>\\<turnstile>([c],[],s) \\<rightarrow>\\<^sup>* (c'#cs',css',t)\" \n  assumes term_c: \"\\<Gamma>\\<turnstile>c\\<down>s\" \n  shows \"\\<Gamma>\\<turnstile>c'\\<down>t\"\nproof -\n  from term_c have \"\\<Gamma>\\<turnstile>[c],[]\\<Down>s\"\n    by (auto intro: terminatess.intros)\n  from steps this\n  have \"\\<Gamma>\\<turnstile>c'#cs',css'\\<Down>t\"\n    by (rule steps_preserves_terminations)\n  thus \"\\<Gamma>\\<turnstile>c'\\<down>t\"\n    by (auto elim: terminatess_elim_cases)\nqed\n\n\n\n\n\nlemma renumber':\n  assumes f: \"\\<forall>i. (a,f i) \\<in> r\\<^sup>* \\<and> (f i,f(Suc i)) \\<in> r\" \n  assumes a_b: \"(a,b) \\<in> r\\<^sup>*\" \n  shows \"b = f 0 \\<Longrightarrow> (\\<exists>f. f 0 = a \\<and> (\\<forall>i. (f i, f(Suc i)) \\<in> r))\"\nusing a_b\nproof (induct rule: converse_rtrancl_induct [consumes 1])\n  assume \"b = f 0\"\n  with f show \"\\<exists>f. f 0 = b \\<and> (\\<forall>i. (f i, f (Suc i)) \\<in> r)\"\n    by blast\nnext\n  fix a z\n  assume a_z: \"(a, z) \\<in> r\" and \"(z, b) \\<in> r\\<^sup>*\" \n  assume \"b = f 0 \\<Longrightarrow> \\<exists>f. f 0 = z \\<and> (\\<forall>i. (f i, f (Suc i)) \\<in> r)\"\n         \"b = f 0\"\n  then obtain f where f0: \"f 0 = z\" and seq: \"\\<forall>i. (f i, f (Suc i)) \\<in> r\"\n    by iprover\n  {\n    fix i have \"((\\<lambda>i. case i of 0 \\<Rightarrow> a | Suc i \\<Rightarrow> f i) i, f i) \\<in> r\"\n      using seq a_z f0\n      by (cases i) auto\n  }\n  then\n  show \"\\<exists>f. f 0 = a \\<and> (\\<forall>i. (f i, f (Suc i)) \\<in> r)\"\n    by - (rule exI [where x=\"\\<lambda>i. case i of 0 \\<Rightarrow> a | Suc i \\<Rightarrow> f i\"],simp)\nqed\n\nlemma renumber:\n \"\\<forall>i. (a,f i) \\<in> r\\<^sup>* \\<and> (f i,f(Suc i)) \\<in> r \n \\<Longrightarrow> \\<exists>f. f 0 = a \\<and> (\\<forall>i. (f i, f(Suc i)) \\<in> r)\"\n  by(blast dest:renumber')\n\nlemma not_inf_Fault': \n  assumes enum_step: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n  shows \"\\<And>k cs. f k = (cs,css,Fault m) \\<Longrightarrow> False\"\nproof (induct css)\n  case Nil\n  have f_k: \"f k = (cs,[],Fault m)\" by fact\n  have \"\\<And>k. f k = (cs,[],Fault m) \\<Longrightarrow> False\"\n  proof (induct cs)\n    case Nil \n    have \"f k = ([], [], Fault m)\" by fact\n    moreover\n    from enum_step have \"\\<Gamma>\\<turnstile>f k \\<rightarrow> f (Suc k)\"..\n    ultimately show \"False\"\n      by (fastforce elim: step_elim_cases)\n  next\n    case (Cons c cs)\n    have fk: \"f k = (c # cs, [], Fault m)\" by fact\n    from enum_step have \"\\<Gamma>\\<turnstile>f k \\<rightarrow> f (Suc k)\"..\n    with fk have \"f (Suc k) = (cs,[],Fault m)\"\n      by (fastforce elim: step_elim_cases)\n    with enum_step Cons.hyps\n    show False\n      by blast\n  qed\n  from this f_k show False by blast\nnext\n  case (Cons ds css)\n  then obtain nrms abrs where ds: \"ds=(nrms,abrs)\" by (cases ds) auto\n  have hyp: \"\\<And>k cs. f k = (cs,css,Fault m) \\<Longrightarrow> False\" by fact\n  have \"\\<And>k. f k = (cs,(nrms,abrs)#css,Fault m) \\<Longrightarrow> False\"\n  proof (induct cs)\n    case Nil\n    have fk: \"f k = ([], (nrms, abrs) # css, Fault m)\" by fact\n    from enum_step have \"\\<Gamma>\\<turnstile>f k \\<rightarrow> f (Suc k)\"..\n    with fk have \"f (Suc k) = (nrms,css,Fault m)\"\n      by (fastforce elim: step_elim_cases)\n    thus ?case\n      by (rule hyp)\n  next\n    case (Cons c cs)\n    have fk: \"f k = (c#cs, (nrms, abrs) # css, Fault m)\" by fact\n    have hyp1: \"\\<And>k. f k = (cs, (nrms, abrs) # css, Fault m) \\<Longrightarrow> False\" by fact\n    from enum_step have \"\\<Gamma>\\<turnstile>f k \\<rightarrow> f (Suc k)\"..\n    with fk have \"f (Suc k) = (cs,(nrms,abrs)#css,Fault m)\"\n      by (fastforce elim: step_elim_cases)\n    thus ?case\n      by (rule hyp1)\n  qed\n  with ds Cons.prems show False by auto\nqed\n\nlemma not_inf_Fault:\n  \"\\<not> inf \\<Gamma> cs css (Fault m)\"\napply (rule not_infI)\napply (rule_tac f=f in not_inf_Fault' )\nby auto\n\nlemma not_inf_Stuck': \n  assumes enum_step: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n  shows \"\\<And>k cs. f k = (cs,css,Stuck) \\<Longrightarrow> False\"\nproof (induct css)\n  case Nil\n  have f_k: \"f k = (cs,[],Stuck)\" by fact\n  have \"\\<And>k. f k = (cs,[],Stuck) \\<Longrightarrow> False\"\n  proof (induct cs)\n    case Nil \n    have \"f k = ([], [], Stuck)\" by fact\n    moreover\n    from enum_step have \"\\<Gamma>\\<turnstile>f k \\<rightarrow> f (Suc k)\"..\n    ultimately show \"False\"\n      by (fastforce elim: step_elim_cases)\n  next\n    case (Cons c cs)\n    have fk: \"f k = (c # cs, [], Stuck)\" by fact\n    from enum_step have \"\\<Gamma>\\<turnstile>f k \\<rightarrow> f (Suc k)\"..\n    with fk have \"f (Suc k) = (cs,[],Stuck)\"\n      by (fastforce elim: step_elim_cases)\n    with enum_step Cons.hyps\n    show False\n      by blast\n  qed\n  from this f_k show False .\nnext\n  case (Cons ds css)\n  then obtain nrms abrs where ds: \"ds=(nrms,abrs)\" by (cases ds) auto\n  have hyp: \"\\<And>k cs. f k = (cs,css,Stuck) \\<Longrightarrow> False\" by fact\n  have \"\\<And>k. f k = (cs,(nrms,abrs)#css,Stuck) \\<Longrightarrow> False\"\n  proof (induct cs)\n    case Nil\n    have fk: \"f k = ([], (nrms, abrs) # css, Stuck)\" by fact\n    from enum_step have \"\\<Gamma>\\<turnstile>f k \\<rightarrow> f (Suc k)\"..\n    with fk have \"f (Suc k) = (nrms,css,Stuck)\"\n      by (fastforce elim: step_elim_cases)\n    thus ?case\n      by (rule hyp)\n  next\n    case (Cons c cs)\n    have fk: \"f k = (c#cs, (nrms, abrs) # css, Stuck)\" by fact\n    have hyp1: \"\\<And>k. f k = (cs, (nrms, abrs) # css, Stuck) \\<Longrightarrow> False\" by fact\n    from enum_step have \"\\<Gamma>\\<turnstile>f k \\<rightarrow> f (Suc k)\"..\n    with fk have \"f (Suc k) = (cs,(nrms,abrs)#css,Stuck)\"\n      by (fastforce elim: step_elim_cases)\n    thus ?case\n      by (rule hyp1)\n  qed\n  with ds Cons.prems show False by auto\nqed\n\nlemma not_inf_Stuck:\n  \"\\<not> inf \\<Gamma> cs css Stuck\"\napply (rule not_infI)\napply (rule_tac f=f in not_inf_Stuck')\nby auto\n\nlemma last_butlast_app: \nassumes butlast: \"butlast as = xs @ butlast bs\"\nassumes not_Nil: \"bs \\<noteq> []\" \"as \\<noteq> []\"\nassumes last: \"fst (last as) = fst (last bs)\" \"snd (last as) = snd (last bs)\"\nshows \"as = xs @ bs\"\nproof -\n  from last have \"last as = last bs\"\n    by (cases \"last as\",cases \"last bs\") simp\n  moreover\n  from not_Nil have \"as = butlast as @ [last as]\" \"bs = butlast bs @ [last bs]\"\n    by auto\n  ultimately show ?thesis\n    using butlast\n    by simp\nqed\n\n\nlemma last_butlast_tl:\nassumes butlast: \"butlast bs = x # butlast as\" \nassumes not_Nil: \"bs \\<noteq> []\" \"as \\<noteq> []\" \nassumes last: \"fst (last as) = fst (last bs)\" \"snd (last as) = snd (last bs)\"\nshows \"as = tl bs\"\nproof -\n  from last have \"last as = last bs\"\n    by (cases \"last as\",cases \"last bs\") simp\n  moreover\n  from not_Nil have \"as = butlast as @ [last as]\" \"bs = butlast bs @ [last bs]\"\n    by auto\n  ultimately show ?thesis\n    using butlast\n    by simp\nqed\n\nlocale inf =\nfixes CS:: \"('s,'p,'f) config \\<Rightarrow> ('s, 'p,'f) com list\"\n  and CSS:: \"('s,'p,'f) config \\<Rightarrow> ('s, 'p,'f) continuation list\"  \n  and S:: \"('s,'p,'f) config \\<Rightarrow> ('s,'f) xstate\"  \n  defines CS_def : \"CS \\<equiv> fst\"\n  defines CSS_def : \"CSS \\<equiv> \\<lambda>c. fst (snd c)\"\n  defines S_def: \"S \\<equiv> \\<lambda>c. snd (snd c)\"\n\nlemma (in inf) steps_hd_drop_suffix:\nassumes f_0: \"f 0 = (c#cs,css,s)\"\nassumes f_step: \"\\<forall>i. \\<Gamma>\\<turnstile> f(i) \\<rightarrow> f(Suc i)\"  \nassumes not_finished: \"\\<forall>i < k. \\<not> (CS (f i) = cs \\<and> CSS (f i) = css)\"\nassumes simul: \"\\<forall>i\\<le>k.\n        (if pcss i = [] then CSS (f i)=css \\<and> CS (f i)=pcs i@cs \n                 else CS (f i)=pcs i \\<and> \n                      CSS (f i)= butlast (pcss i)@\n                              [(fst (last (pcss i))@cs,(snd (last (pcss i)))@cs)]@\n                              css)\"\ndefines \"p\\<equiv>\\<lambda>i. (pcs i, pcss i, S (f i))\"\nshows \"\\<forall>i<k. \\<Gamma>\\<turnstile> p i \\<rightarrow> p (Suc i)\"\nusing not_finished simul\nproof (induct k)\n  case 0\n  thus ?case by simp\nnext\n  case (Suc k)\n  have simul: \"\\<forall>i\\<le>Suc k.\n        (if pcss i = [] then CSS (f i)=css \\<and> CS (f i)=pcs i@cs \n                 else CS (f i)=pcs i \\<and> \n                      CSS (f i)= butlast (pcss i)@\n                              [(fst (last (pcss i))@cs,(snd (last (pcss i)))@cs)]@\n                              css)\" by fact\n  have not_finished': \"\\<forall>i < Suc k. \\<not> (CS (f i) = cs \\<and> CSS (f i) = css)\" by fact\n  with simul \n  have not_finished: \"\\<forall>i<Suc k. \\<not> (pcs i = [] \\<and> pcss i = [])\"\n    by (auto simp add: CS_def CSS_def S_def split: split_if_asm)\n  show ?case\n  proof (clarify)\n    fix i\n    assume i_le_Suc_k: \"i < Suc k\"\n    show \"\\<Gamma>\\<turnstile> p i \\<rightarrow> p (Suc i)\"\n    proof (cases \"i < k\")\n      case True\n      with not_finished' simul Suc.hyps\n      show ?thesis\n        by auto\n    next\n      case False\n      with i_le_Suc_k\n      have eq_i_k: \"i=k\"\n        by simp\n      show \"\\<Gamma>\\<turnstile>p i \\<rightarrow> p (Suc i)\"\n      proof -\n        obtain cs' css' t' where \n          f_Suc_i: \"f (Suc i) = (cs', css', t')\"\n          by (cases \"f (Suc i)\")\n        obtain cs'' css'' t'' where \n          f_i: \"f i = (cs'',css'',t'')\"\n          by (cases \"f i\")\n        from not_finished eq_i_k \n        have pcs_pcss_not_Nil: \"\\<not> (pcs i = [] \\<and> pcss i = [])\"\n          by auto\n        from simul [rule_format, of i] i_le_Suc_k f_i\n        have pcs_pcss_i:\n          \"if pcss i = [] then css''=css \\<and> cs''=pcs i@cs \n           else cs''=pcs i \\<and> \n           css''= butlast (pcss i)@\n                       [(fst (last (pcss i))@cs,(snd (last (pcss i)))@cs)]@\n                       css\"\n          by (simp add: CS_def CSS_def S_def cong: if_cong)\n        from simul [rule_format, of \"Suc i\"] i_le_Suc_k f_Suc_i \n        have pcs_pcss_Suc_i: \n        \"if pcss (Suc i) = [] then css' = css \\<and> cs' = pcs (Suc i) @ cs\n         else cs' = pcs (Suc i) \\<and>\n              css' = butlast (pcss (Suc i)) @\n               [(fst (last (pcss (Suc i))) @ cs, snd (last (pcss (Suc i))) @ cs)] @ \n               css\"\n          by (simp add: CS_def CSS_def S_def cong: if_cong)\n        show ?thesis\n        proof (cases \"pcss i = []\")\n          case True\n          note pcss_Nil = this\n          with pcs_pcss_i pcs_pcss_not_Nil obtain p ps where\n            pcs_i: \"pcs i = p#ps\" and\n            css'': \"css''=css\" and \n            cs'': \"cs''=(p#ps)@cs\"\n            by (auto simp add: neq_Nil_conv)\n          with f_i have \"f i = (p#(ps@cs),css,t'')\"\n            by simp\n          with f_Suc_i f_step [rule_format, of i]\n          have step_css: \"\\<Gamma>\\<turnstile> (p#(ps@cs),css,t'') \\<rightarrow> (cs',css',t')\"\n            by simp\n          from step_Cons' [OF this, of p \"ps@cs\"]\n          obtain css''' where\n            css''': \"css' = css''' @ css\" \n            \"if css''' = [] then \\<exists>p. cs' = p @ ps @ cs\n            else (\\<exists>pnorm pabr. css'''=[(pnorm @ ps @ cs,pabr @ ps @ cs)])\"\n            by auto\n          show ?thesis\n          proof (cases \"css''' = []\")\n            case True\n            with css'''\n            obtain p' where \n              css': \"css' = css\" and\n              cs': \"cs' = p' @ ps @ cs\"\n              by auto\n                (*from cs' css' f_Suc_i f_i [rule_format, of \"Suc k\"]\n                have p_ps_not_Nil: \"p'@ps \\<noteq> Nil\"\n                by auto*)\n            from css' cs' step_css \n            have step: \"\\<Gamma>\\<turnstile> (p#(ps@cs),css,t'') \\<rightarrow> (p'@ps@cs,css,t')\"\n              by simp\n            hence \"\\<Gamma>\\<turnstile> ((p#ps)@cs,css,t'') \\<rightarrow> ((p'@ps)@cs,css,t')\"\n              by simp\n            from drop_suffix_css_step' [OF drop_suffix_same_css_step [OF this], \n              where xs=\"css\" and css=\"[]\" and css'=\"[]\"]\n            have  \"\\<Gamma>\\<turnstile> (p#ps,[],t'') \\<rightarrow> (p'@ps,[],t')\"\n              by simp \n            moreover \n            from css' cs' pcs_pcss_Suc_i\n            obtain \"pcs (Suc i) = p'@ps\" and \"pcss (Suc i) = []\"\n              by (simp split: split_if_asm)\n            ultimately show ?thesis\n              using pcs_i pcss_Nil f_i f_Suc_i\n              by (simp add: CS_def CSS_def S_def p_def)\n          next\n            case False\n            with css'''\n            obtain pnorm pabr where \n              css': \"css'=css'''@css\"\n              \"css'''=[(pnorm @ ps @ cs,pabr @ ps @ cs)]\"\n              by auto\n            with css''' step_css \n            have \"\\<Gamma>\\<turnstile> (p#ps@cs,css,t'') \\<rightarrow> (cs',[(pnorm@ps@cs,pabr@ps@cs)]@css,t')\"\n              by simp\n            then \n            have \"\\<Gamma>\\<turnstile>(p#ps, css, t'') \\<rightarrow> (cs', [(pnorm@ps, pabr@ps)] @ css, t')\" \n              by (rule drop_suffix_hd_css_step)\n            from drop_suffix_css_step' [OF this,\n              where css=\"[]\" and xs=\"css\" and css'=\"[(pnorm@ps, pabr@ps)]\"]\n            have \"\\<Gamma>\\<turnstile> (p#ps,[],t'') \\<rightarrow> (cs',[(pnorm@ps, pabr@ps)],t')\"\n              by simp\n            moreover\n            from css' pcs_pcss_Suc_i\n            obtain \"pcs (Suc i) = cs'\" \"pcss (Suc i) = [(pnorm@ps, pabr@ps)]\"\n              apply (cases \"pcss (Suc i)\")\n              apply (auto split: split_if_asm)\n              done\n            ultimately show ?thesis\n              using pcs_i pcss_Nil f_i f_Suc_i   \n              by (simp add: p_def CS_def CSS_def S_def)\n          qed\n        next\n          case False\n          note pcss_i_not_Nil = this\n          with pcs_pcss_i obtain\n            cs'': \"cs''=pcs i\" and  \n            css'': \"css''= butlast (pcss i)@\n                            [(fst (last (pcss i))@cs,(snd (last (pcss i)))@cs)]@\n                            css\"\n            by auto\n          from f_Suc_i f_i f_step [rule_format, of i]\n          have step_i_full: \"\\<Gamma>\\<turnstile> (cs'',css'',t'') \\<rightarrow> (cs',css',t')\"\n            by simp\n          show ?thesis\n          proof (cases cs'')\n            case (Cons c' cs)\n            with step_Cons' [OF step_i_full]\n            obtain css''' where css': \"css' = css'''@css''\"\n              by auto\n            with step_i_full \n            have \"\\<Gamma>\\<turnstile> (cs'',css'',t'') \\<rightarrow> (cs',css'''@css'',t')\"\n              by simp\n            from Cons_change_css_step [OF this, where xss=\"pcss i\"] Cons cs''\n            have \"\\<Gamma>\\<turnstile> (pcs i, pcss i,t'') \\<rightarrow> (cs',css'''@pcss i,t')\"\n              by simp\n            moreover\n            from cs'' css'' css' False pcs_pcss_Suc_i\n            obtain \"pcs (Suc i) = cs'\" \"pcss (Suc i) = css'''@pcss i\"\n              apply (auto  split: split_if_asm)\n              apply (drule (4) last_butlast_app)\n              by simp\n            ultimately show ?thesis\n              using f_i f_Suc_i\n              by (simp add: p_def CS_def CSS_def S_def)\n          next\n            case Nil\n            note cs''_Nil = this\n            show ?thesis\n            proof (cases \"butlast (pcss i)\")\n              case (Cons bpcs bpcss)\n              with cs''_Nil step_i_full css''\n              have \"\\<Gamma>\\<turnstile> ([],[hd css'']@tl css'',t'') \\<rightarrow> (cs',css',t')\"\n                by simp\n              moreover\n              from step_Nil [OF this]\n              have css': \"css'=tl css''\"\n                by simp\n              ultimately have \n                step_i_full: \"\\<Gamma>\\<turnstile> ([],[hd css'']@tl css'',t'') \\<rightarrow> (cs',tl css'',t')\"\n                by simp\n              from css'' Cons pcss_i_not_Nil\n              have \"hd css'' = hd (pcss i)\"\n                by (auto simp add: neq_Nil_conv split: split_if_asm)\n              with cs'' cs''_Nil\n                Nil_change_css_step [where ass=\"[hd css'']\" and\n                css=\"tl css''\" and ass'=\"[]\" and \n                xss=\"tl (pcss i)\", simplified, OF step_i_full [simplified]]\n              have \"\\<Gamma>\\<turnstile> (pcs i,[hd (pcss i)]@tl (pcss i),t'') \\<rightarrow> (cs',tl (pcss i),t')\"\n                by simp\n              with pcss_i_not_Nil \n              have \"\\<Gamma>\\<turnstile> (pcs i,pcss i,t'') \\<rightarrow> (cs',tl (pcss i),t')\"\n                by simp\n              moreover\n              from css' css'' cs''_Nil Cons pcss_i_not_Nil pcs_pcss_Suc_i\n              obtain \"pcs (Suc i) = cs'\" \"pcss (Suc i) = tl (pcss i)\" \n                apply (clarsimp  split: split_if_asm)\n                apply (drule (4) last_butlast_tl)\n                by simp\n              ultimately show ?thesis\n                using f_i f_Suc_i\n                by (simp add: p_def CS_def CSS_def S_def)\n            next\n              case Nil\n              with css'' pcss_i_not_Nil\n              obtain pnorm pabr\n                where css'': \"css''= [(pnorm@cs,pabr@cs)]@css\" and\n                pcss_i: \"pcss i = [(pnorm,pabr)]\"\n                by (force simp add: neq_Nil_conv split: split_if_asm)\n              with cs''_Nil step_i_full\n              have \"\\<Gamma>\\<turnstile>([],[(pnorm@cs,pabr@cs)]@css,t'') \\<rightarrow> (cs',css',t')\"\n                by simp\n              from step_Nil [OF this]\n              obtain \n                css': \"css'=css\" and\n                cs': \"(case t'' of\n                         Abrupt s' \\<Rightarrow> cs' = pabr @ cs \\<and> t' = Normal s'\n                       | _ \\<Rightarrow> cs' = pnorm @ cs \\<and> t' = t'')\"\n                by (simp cong: xstate.case_cong)\n              let \"?pcs_Suc_i \" = \"(case t'' of Abrupt s' \\<Rightarrow> pabr | _ \\<Rightarrow> pnorm)\"\n              from cs'\n              have \"\\<Gamma>\\<turnstile>([],[(pnorm,pabr)],t'') \\<rightarrow> (?pcs_Suc_i,[],t')\"\n                by (auto intro: step.intros split: xstate.splits)\n              moreover\n              from css'' css' cs' pcss_i pcs_pcss_Suc_i\n              obtain \"pcs (Suc i) = ?pcs_Suc_i\" \"pcss (Suc i) = []\"\n                by (simp split: split_if_asm xstate.splits)\n              ultimately\n              show ?thesis\n                using pcss_i cs'' cs''_Nil f_i f_Suc_i\n                by (simp add: p_def CS_def CSS_def S_def)\n            qed\n          qed\n        qed\n      qed\n    qed\n  qed\nqed\n\nlemma k_steps_to_rtrancl: \n  assumes steps: \"\\<forall>i<k. \\<Gamma>\\<turnstile> p i \\<rightarrow> p (Suc i)\"\n  shows \"\\<Gamma>\\<turnstile>p 0\\<rightarrow>\\<^sup>* p k\"\nusing steps\nproof (induct k)\n  case 0 thus ?case by auto\nnext\n  case (Suc k)\n  have \"\\<forall>i<Suc k. \\<Gamma>\\<turnstile> p i \\<rightarrow> p (Suc i)\" by fact\n  then obtain\n  step_le_k: \"\\<forall>i<k. \\<Gamma>\\<turnstile> p i \\<rightarrow> p (Suc i)\" and step_k: \"\\<Gamma>\\<turnstile> p k \\<rightarrow> p (Suc k)\"\n    by auto\n  from Suc.hyps [OF step_le_k]\n  have \"\\<Gamma>\\<turnstile> p 0 \\<rightarrow>\\<^sup>* p k\".\n  also note step_k\n  finally show ?case .\nqed\n\n    \n\nlemma (in inf) steps_hd_drop_suffix_finite:\nassumes f_0: \"f 0 = (c#cs,css,s)\"\nassumes f_step: \"\\<forall>i. \\<Gamma>\\<turnstile> f(i) \\<rightarrow> f(Suc i)\"  \nassumes not_finished: \"\\<forall>i < k. \\<not> (CS (f i) = cs \\<and> CSS (f i) = css)\"\nassumes simul: \"\\<forall>i\\<le>k.\n        (if pcss i = [] then CSS (f i)=css \\<and> CS (f i)=pcs i@cs \n                 else CS (f i)=pcs i \\<and> \n                      CSS (f i)= butlast (pcss i)@\n                              [(fst (last (pcss i))@cs,(snd (last (pcss i)))@cs)]@\n                              css)\"\nshows \"\\<Gamma>\\<turnstile>([c],[],s) \\<rightarrow>\\<^sup>* (pcs k, pcss k, S (f k))\"\nproof -\n  from steps_hd_drop_suffix [OF f_0 f_step not_finished simul]\n  have \"\\<forall>i<k. \\<Gamma>\\<turnstile> (pcs i, pcss i, S (f i)) \\<rightarrow> \n                  (pcs (Suc i), pcss (Suc i), S (f (Suc i)))\".\n  from k_steps_to_rtrancl [OF this]\n  have \"\\<Gamma>\\<turnstile> (pcs 0, pcss 0, S (f 0)) \\<rightarrow>\\<^sup>* (pcs k, pcss k, S (f k))\".\n  moreover from f_0 simul [rule_format, of 0]\n  have \"(pcs 0, pcss 0, S (f 0)) = ([c],[],s)\"\n    by (auto split: split_if_asm simp add: CS_def CSS_def S_def)\n  ultimately show ?thesis by simp\nqed\n\nlemma (in inf) steps_hd_drop_suffix_infinite:\nassumes f_0: \"f 0 = (c#cs,css,s)\"\nassumes f_step: \"\\<forall>i. \\<Gamma>\\<turnstile> f(i) \\<rightarrow> f(Suc i)\"  \nassumes not_finished: \"\\<forall>i. \\<not> (CS (f i) = cs \\<and> CSS (f i) = css)\"\n(*assumes not_finished: \"\\<forall>i. \\<not> (pcs i = [] \\<and> pcss i = [])\"*)\nassumes simul: \"\\<forall>i.\n        (if pcss i = [] then CSS (f i)=css \\<and> CS (f i)=pcs i@cs \n                 else CS (f i)=pcs i \\<and> \n                      CSS (f i)= butlast (pcss i)@\n                              [(fst (last (pcss i))@cs,(snd (last (pcss i)))@cs)]@\n                              css)\"\ndefines \"p\\<equiv>\\<lambda>i. (pcs i, pcss i, S (f i))\"\nshows \"\\<Gamma>\\<turnstile> p i \\<rightarrow> p (Suc i)\"\nproof -\n  from steps_hd_drop_suffix [OF f_0 f_step, of \"Suc i\" pcss pcs] not_finished simul\n  show ?thesis\n    by (auto simp add: p_def)\nqed\n\nlemma (in inf) steps_hd_progress:\nassumes f_0: \"f 0 = (c#cs,css,s)\"\nassumes f_step: \"\\<forall>i. \\<Gamma>\\<turnstile> f(i) \\<rightarrow> f(Suc i)\"\nassumes c_unfinished: \"\\<forall>i < k. \\<not> (CS (f i) = cs \\<and> CSS (f i) = css)\"\nshows \"\\<forall>i \\<le> k. (\\<exists>pcs pcss. \n          (if pcss = [] then CSS (f i)=css \\<and> CS (f i)=pcs@cs \n           else CS (f i)=pcs  \\<and> \n                CSS (f i)= butlast pcss@\n                           [(fst (last pcss)@cs,(snd (last pcss))@cs)]@\n                           css))\"\nusing c_unfinished \nproof (induct k)\n  case 0\n  with f_0 show ?case\n    by (simp add: CSS_def CS_def)\nnext\n  case (Suc k)\n  have c_unfinished: \"\\<forall>i<Suc k. \\<not> (CS (f i) = cs \\<and> CSS (f i) = css)\" by fact\n  hence c_unfinished': \"\\<forall>i< k. \\<not> (CS (f i) = cs \\<and> CSS (f i) = css)\" by simp\n  show ?case\n  proof (clarify)\n    fix i\n    assume i_le_Suc_k: \"i \\<le> Suc k\"\n    show \"\\<exists>pcs pcss. \n          (if pcss = [] then CSS (f i)=css \\<and> CS (f i)=pcs@cs \n           else CS (f i)=pcs  \\<and> \n                CSS (f i)= butlast pcss@\n                           [(fst (last pcss)@cs,(snd (last pcss))@cs)]@\n                           css)\"\n    proof (cases \"i < Suc k\")\n      case True\n      with Suc.hyps [OF c_unfinished', rule_format, of i] c_unfinished\n      show ?thesis\n        by auto\n    next\n      case False\n      with i_le_Suc_k have eq_i_Suc_k: \"i=Suc k\"\n        by auto\n      obtain cs' css' t' where \n        f_Suc_k: \"f (Suc k) = (cs', css', t')\"\n        by (cases \"f (Suc k)\")\n      obtain cs'' css'' t'' where \n        f_k: \"f k = (cs'',css'',t'')\"\n        by (cases \"f k\")\n      with Suc.hyps [OF c_unfinished',rule_format, of k] \n      obtain pcs pcss where  \n        pcs_pcss_k: \n        \"if pcss = [] then css'' = css \\<and> cs'' = pcs @ cs\n         else cs'' = pcs \\<and>\n              css'' = butlast pcss @ \n                           [(fst (last pcss) @ cs, snd (last pcss) @ cs)] @ \n                           css\"\n        by (auto simp add: CSS_def CS_def cong: if_cong)\n      from c_unfinished [rule_format, of k] f_k pcs_pcss_k\n      have pcs_pcss_empty: \"\\<not> (pcs = [] \\<and> pcss = [])\" \n        by (auto simp add: CS_def CSS_def S_def split: split_if_asm)\n      show ?thesis\n      proof (cases \"pcss = []\")\n        case True\n        note pcss_Nil = this\n        with pcs_pcss_k pcs_pcss_empty obtain p ps where\n          pcs_i: \"pcs = p#ps\" and\n          css'': \"css''=css\" and \n          cs'': \"cs''=(p#ps)@cs\"\n          by (cases \"pcs\") auto\n        with f_k have \"f k = (p#(ps@cs),css,t'')\"\n          by simp \n        with f_Suc_k f_step [rule_format, of k]\n        have step_css: \"\\<Gamma>\\<turnstile> (p#(ps@cs),css,t'') \\<rightarrow> (cs',css',t')\"\n          by simp\n        from step_Cons' [OF this, of p \"ps@cs\"]\n        obtain css''' where\n          css''': \"css' = css''' @ css\" \n          \"if css''' = [] then \\<exists>p. cs' = p @ ps @ cs\n          else (\\<exists>pnorm pabr. css'''=[(pnorm @ ps @ cs,pabr @ ps @ cs)])\"\n          by auto\n        show ?thesis\n        proof (cases \"css''' = []\")\n          case True\n          with css'''\n          obtain p' where \n            css': \"css' = css\" and\n            cs': \"cs' = p' @ ps @ cs\"\n            by auto\n          from css' cs' f_Suc_k\n          show ?thesis\n            apply (rule_tac x=\"p'@ps\" in exI) \n            apply (rule_tac x=\"[]\" in exI)\n            apply (simp add: CSS_def CS_def eq_i_Suc_k)\n            done\n        next\n          case False\n          with css'''\n          obtain pnorm pabr where \n            css': \"css'=css'''@css\"\n            \"css'''=[(pnorm @ ps @ cs,pabr @ ps @ cs)]\"\n            by auto\n          with f_Suc_k eq_i_Suc_k\n          show ?thesis\n            apply (rule_tac x=\"cs'\" in exI)\n            apply (rule_tac x=\"[(pnorm@ps, pabr@ps)]\" in exI) \n            by (simp add: CSS_def CS_def)\n        qed\n      next\n        case False\n        note pcss_k_not_Nil = this\n        with pcs_pcss_k obtain\n          cs'': \"cs''=pcs\" and  \n          css'': \"css''= butlast pcss@\n                           [(fst (last pcss)@cs,(snd (last pcss))@cs)]@\n                           css\"\n          by auto\n        from f_Suc_k f_k f_step [rule_format, of k]\n        have step_i_full: \"\\<Gamma>\\<turnstile> (cs'',css'',t'') \\<rightarrow> (cs',css',t')\"\n          by simp \n        show ?thesis\n        proof (cases cs'')\n          case (Cons c' cs)\n          with step_Cons' [OF step_i_full]\n          obtain css''' where css': \"css' = css'''@css''\"\n            by auto\n          with cs'' css'' f_Suc_k eq_i_Suc_k pcss_k_not_Nil\n          show ?thesis\n            apply (rule_tac x=\"cs'\" in exI)\n            apply (rule_tac x=\"css'''@pcss\" in exI)\n            by (clarsimp simp add: CSS_def CS_def butlast_append)\n        next\n          case Nil\n          note cs''_Nil = this\n          show ?thesis\n          proof (cases \"butlast pcss\")\n            case (Cons bpcs bpcss)\n            with cs''_Nil step_i_full css''\n            have \"\\<Gamma>\\<turnstile> ([],[hd css'']@tl css'',t'') \\<rightarrow> (cs',css',t')\"\n              by simp\n            moreover\n            from step_Nil [OF this]\n            obtain css': \"css'=tl css''\" and\n                   cs': \"cs' = (case t'' of Abrupt s' \\<Rightarrow> snd (hd css'') \n                                 | _ \\<Rightarrow> fst (hd css''))\"\n              by (auto split: xstate.splits)\n            from css'' Cons pcss_k_not_Nil\n            have \"hd css'' = hd pcss\"\n              by (auto simp add: neq_Nil_conv split: split_if_asm)\n            with css' cs' css'' cs''_Nil Cons pcss_k_not_Nil f_Suc_k eq_i_Suc_k  \n            show ?thesis\n              apply (rule_tac x=\"cs'\" in exI)\n              apply (rule_tac x=\"tl pcss\" in exI)\n              apply (clarsimp split: xstate.splits \n                       simp add: CS_def CSS_def neq_Nil_conv split: split_if_asm)\n              done\n          next\n            case Nil\n            with css'' pcss_k_not_Nil\n            obtain pnorm pabr\n              where css'': \"css''= [(pnorm@cs,pabr@cs)]@css\" and\n              pcss_k: \"pcss = [(pnorm,pabr)]\"\n              by (force simp add: neq_Nil_conv split: split_if_asm)\n            with cs''_Nil step_i_full\n            have \"\\<Gamma>\\<turnstile>([],[(pnorm@cs,pabr@cs)]@css,t'') \\<rightarrow> (cs',css',t')\"\n              by simp\n            from step_Nil [OF this]\n            obtain \n              css': \"css'=css\" and\n              cs': \"(case t'' of\n              Abrupt s' \\<Rightarrow> cs' = pabr @ cs \\<and> t' = Normal s'\n              | _ \\<Rightarrow> cs' = pnorm @ cs \\<and> t' = t'')\"\n              by (simp cong: xstate.case_cong)\n            let \"?pcs_Suc_k \" = \"(case t'' of Abrupt s' \\<Rightarrow> pabr | _ \\<Rightarrow> pnorm)\"\n            from css'' css' cs' pcss_k f_Suc_k eq_i_Suc_k\n            show ?thesis\n              apply (rule_tac x=\"?pcs_Suc_k\" in exI)\n              apply (rule_tac x=\"[]\" in exI)\n              apply (simp split: xstate.splits add: CS_def CSS_def)\n              done\n          qed\n        qed\n      qed\n    qed\n  qed\nqed\n  \nlemma (in inf) inf_progress:\nassumes f_0: \"f 0 = (c#cs,css,s)\"\nassumes f_step: \"\\<forall>i. \\<Gamma>\\<turnstile> f(i) \\<rightarrow> f(Suc i)\"\nassumes unfinished: \"\\<forall>i. \\<not> ((CS (f i) = cs) \\<and> (CSS (f i) = css))\"\nshows \"\\<exists>pcs pcss. \n          (if pcss = [] then CSS (f i)=css \\<and> CS (f i)=pcs@cs \n           else CS (f i)=pcs  \\<and> \n                CSS (f i)= butlast pcss@\n                           [(fst (last pcss)@cs,(snd (last pcss))@cs)]@\n                           css)\"\nproof -\n  from steps_hd_progress [OF f_0 f_step, of \"i\"] unfinished\n  show ?thesis\n    by auto\nqed\n\nlemma skolemize1: \"\\<forall>x. P x \\<longrightarrow> (\\<exists>y. Q x y) \\<Longrightarrow> \\<exists>f.\\<forall>x. P x \\<longrightarrow> Q x (f x)\"\n  by (rule choice) blast\n\nlemma skolemize2: \"\\<forall>x. P x \\<longrightarrow> (\\<exists>y z. Q x y z) \\<Longrightarrow> \\<exists>f g.\\<forall>x. P x \\<longrightarrow> Q x (f x) (g x)\"\napply (drule skolemize1)\napply (erule exE)\napply (drule skolemize1)\napply fast\ndone\n\nlemma skolemize2': \"\\<forall>x.\\<exists>y z. P x y z \\<Longrightarrow> \\<exists>f g.\\<forall>x. P x (f x) (g x)\"\napply (drule choice)\napply (erule exE)\napply (drule choice)\napply fast\ndone\n\ntheorem (in inf) inf_cases:\n  fixes c::\"('s,'p,'f) com\"\n  assumes inf: \"inf \\<Gamma> (c#cs) css s\" \n  shows \"inf \\<Gamma> [c] [] s \\<or> (\\<exists>t. \\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t \\<and> inf \\<Gamma> cs css t)\"\nproof -\n  from inf obtain f where\n    f_0: \"f 0 = (c#cs,css,s)\" and\n    f_step: \"(\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i))\"\n    by (auto simp add: inf_def)\n  show ?thesis\n  proof (cases \"\\<exists>i. CS (f i) = cs \\<and> CSS (f i) = css\")\n    case True\n    def k\\<equiv>\"(LEAST i. CS (f i) = cs \\<and> CSS (f i) = css)\"\n    from True\n    obtain CS_f_k: \"CS (f k) = cs\" and CSS_f_k: \"CSS (f k) = css\" \n      apply -\n      apply (erule exE)\n      apply (drule LeastI)\n      apply (simp add: k_def)\n      done\n    have less_k_prop: \"\\<forall>i<k. \\<not> (CS (f i) = cs \\<and> CSS (f i) = css)\"\n      apply (intro allI impI)\n      apply (unfold k_def)\n      apply (drule not_less_Least)\n      apply simp\n      done\n    have \"\\<Gamma>\\<turnstile>([c], [], s) \\<rightarrow>\\<^sup>* ([],[],S (f k))\"\n    proof -\n      have \"\\<forall>i\\<le>k. \\<exists>pcs pcss. \n        (if pcss = [] then CSS (f i)=css \\<and> CS (f i)=pcs@cs \n           else CS (f i)=pcs  \\<and> \n                CSS (f i)= butlast pcss@\n                           [(fst (last pcss)@cs,(snd (last pcss))@cs)]@\n                           css)\"\n        by (rule steps_hd_progress \n        [OF f_0 f_step, where k=k, OF less_k_prop])\n      from skolemize2 [OF this] obtain pcs pcss where\n        pcs_pcss: \n            \"\\<forall>i\\<le>k. \n               (if pcss i = [] then CSS (f i)=css \\<and> CS (f i)=pcs i@cs \n                else CS (f i)=pcs i \\<and> \n                     CSS (f i)= butlast (pcss i)@\n                           [(fst (last (pcss i))@cs,(snd (last (pcss i)))@cs)]@\n                           css)\"\n        by iprover\n      from pcs_pcss [rule_format, of k] CS_f_k CSS_f_k \n      have finished: \"pcs k = []\" \"pcss k = []\"\n        by (auto simp add: CS_def CSS_def S_def split: split_if_asm)\n      from pcs_pcss\n      have simul: \"\\<forall>i\\<le>k. (if pcss i = [] then CSS (f i)=css \\<and> CS (f i)=pcs i@cs \n                   else CS (f i)=pcs i \\<and> \n                     CSS (f i)= butlast (pcss i)@\n                           [(fst (last (pcss i))@cs,(snd (last (pcss i)))@cs)]@\n                            css)\"\n        by auto\n      from steps_hd_drop_suffix_finite [OF f_0 f_step less_k_prop simul] finished\n      show ?thesis\n        by simp\n    qed\n    hence \"\\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> S (f k)\"\n      by (rule steps_impl_exec)\n    moreover\n    from CS_f_k CSS_f_k f_step\n    have \"inf \\<Gamma> cs css (S (f k))\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (i + k)\" in exI)\n      apply simp\n      apply (auto simp add: CS_def CSS_def S_def)\n      done\n    ultimately\n    have \"(\\<exists>t. \\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t \\<and> inf \\<Gamma> cs css t)\"\n      by blast\n    thus ?thesis\n      by simp\n  next\n    case False\n    hence unfinished: \"\\<forall>i. \\<not> ((CS (f i) = cs) \\<and> (CSS (f i) = css))\"\n      by simp\n    from inf_progress [OF f_0 f_step this]\n    have \"\\<forall>i. \\<exists>pcs pcss. \n          (if pcss = [] then CSS (f i)=css \\<and> CS (f i)=pcs@cs \n           else CS (f i)=pcs  \\<and> \n                CSS (f i)= butlast pcss@\n                           [(fst (last pcss)@cs,(snd (last pcss))@cs)]@\n                           css)\"\n      by auto\n    from skolemize2' [OF this] obtain pcs pcss where \n      pcs_pcss: \"\\<forall>i. \n          (if pcss i = [] then CSS (f i)=css \\<and> CS (f i)=pcs i@cs \n           else CS (f i)=pcs i  \\<and> \n                CSS (f i)= butlast (pcss i)@\n                           [(fst (last (pcss i))@cs,(snd (last (pcss i)))@cs)]@\n                           css)\"\n      by iprover\n    def \"g\" \\<equiv> \"\\<lambda>i. (pcs i, pcss i, S (f i))\"\n    from pcs_pcss [rule_format, of 0] f_0\n    have \"g 0 = ([c],[],s)\"\n      by (auto split: split_if_asm simp add: CS_def CSS_def S_def g_def)\n    moreover\n    from steps_hd_drop_suffix_infinite [OF f_0 f_step unfinished pcs_pcss]\n    have \"\\<forall>i. \\<Gamma>\\<turnstile>g i \\<rightarrow> g (Suc i)\"\n      by (simp add: g_def)\n    ultimately\n    have \"inf \\<Gamma> [c] [] s\"\n      by (auto simp add: inf_def)\n    thus ?thesis\n      by simp\n  qed\nqed\n\nlemma infE [consumes 1]:\n  assumes inf: \"inf \\<Gamma> (c#cs) css s\" \n  assumes cases: \"inf \\<Gamma> [c] [] s \\<Longrightarrow> P\"\n                 \"\\<And>t. \\<lbrakk>\\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t; inf \\<Gamma> cs css t\\<rbrakk> \\<Longrightarrow> P\"\n  shows P\nusing inf cases\napply -\napply (drule inf.inf_cases)\napply auto\ndone\n\nlemma inf_Seq: \n  \"inf \\<Gamma> (Seq c1 c2#cs) css (Normal s) = inf \\<Gamma> (c1#c2#cs) css (Normal s)\" \nproof \n  assume \"inf \\<Gamma> (Seq c1 c2 # cs) css (Normal s)\"\n  then obtain f where \n    f_0: \"f 0 = (Seq c1 c2#cs,css,Normal s)\" and\n    f_step: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    by (auto simp add: inf_def)\n  from f_step [rule_format, of 0] f_0\n  have \"f 1 = (c1#c2#cs,css,Normal s)\"\n    by (auto elim: step_Normal_elim_cases)\n  with f_step show \"inf \\<Gamma> (c1#c2#cs) css (Normal s)\"\n    apply (simp add: inf_def)\n    apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n    apply simp\n    done\nnext\n  assume \"inf \\<Gamma> (c1 # c2 # cs) css (Normal s)\"\n  then obtain f where \n    f_0: \"f 0 = (c1# c2#cs,css,Normal s)\" and\n    f_step: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    by (auto simp add: inf_def)\n  def g\\<equiv>\"\\<lambda>i. case i of 0 \\<Rightarrow> (Seq c1 c2#cs,css,Normal s) | Suc j \\<Rightarrow> f j\" \n  with f_0 have\n    \"\\<Gamma>\\<turnstile>g 0 \\<rightarrow> g (Suc 0)\"\n    by (auto intro: step.intros)\n  moreover\n  from f_step have \"\\<forall>i. i\\<noteq>0 \\<longrightarrow> \\<Gamma>\\<turnstile>g i \\<rightarrow> g (Suc i)\"\n    by (auto simp add: g_def split: nat.splits)\n  ultimately\n  show \"inf \\<Gamma> (Seq c1 c2 # cs) css (Normal s)\"\n    apply (simp add: inf_def)\n    apply (rule_tac x=g in exI)\n    apply (simp add: g_def split: nat.splits)\n    done\nqed\n \nlemma inf_WhileTrue: \n  assumes b: \"s \\<in> b\"\n  shows \"inf \\<Gamma> (While b c#cs) css (Normal s) = \n          inf \\<Gamma> (c#While b c#cs) css (Normal s)\" \nproof\n  assume \"inf \\<Gamma> (While b c # cs) css (Normal s)\"\n  then obtain f where \n    f_0: \"f 0 = (While b c#cs,css,Normal s)\" and\n    f_step: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    by (auto simp add: inf_def)\n  from b f_step [rule_format, of 0] f_0\n  have \"f 1 = (c#While b c#cs,css,Normal s)\"\n    by (auto elim: step_Normal_elim_cases)\n  with f_step show \"inf \\<Gamma> (c # While b c # cs) css (Normal s)\"\n    apply (simp add: inf_def)\n    apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n    apply simp\n    done\nnext\n  assume \"inf \\<Gamma> (c # While b c # cs) css (Normal s)\"\n  then obtain f where \n    f_0: \"f 0 = (c # While b c #cs,css,Normal s)\" and\n    f_step: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    by (auto simp add: inf_def)\n  def h\\<equiv>\"\\<lambda>i. case i of 0 \\<Rightarrow> (While b c#cs,css,Normal s) | Suc j \\<Rightarrow> f j\" \n  with b f_0 have\n    \"\\<Gamma>\\<turnstile>h 0 \\<rightarrow> h (Suc 0)\"\n    by (auto intro: step.intros)\n  moreover\n  from f_step have \"\\<forall>i. i\\<noteq>0 \\<longrightarrow> \\<Gamma>\\<turnstile>h i \\<rightarrow> h (Suc i)\"\n    by (auto simp add: h_def split: nat.splits)\n  ultimately\n  show \"inf \\<Gamma> (While b c # cs) css (Normal s)\"\n    apply (simp add: inf_def)\n    apply (rule_tac x=h in exI)\n    apply (simp add: h_def split: nat.splits)\n    done\nqed\n\nlemma inf_Catch:\n\"inf \\<Gamma> (Catch c1 c2#cs) css (Normal s) = inf \\<Gamma> [c1] ((cs,c2#cs)#css) (Normal s)\"\nproof\n  assume \"inf \\<Gamma> (Catch c1 c2#cs) css (Normal s)\"\n  then obtain f where \n    f_0: \"f 0 = (Catch c1 c2#cs,css,Normal s)\" and\n    f_step: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    by (auto simp add: inf_def)\n  from f_step [rule_format, of 0] f_0\n  have \"f 1 = ([c1],(cs,c2#cs)#css,Normal s)\"\n    by (auto elim: step_Normal_elim_cases)\n  with f_step show \"inf \\<Gamma> [c1] ((cs,c2#cs)#css) (Normal s)\"\n    apply (simp add: inf_def)\n    apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n    apply simp\n    done\nnext\n  assume \"inf \\<Gamma> [c1] ((cs,c2#cs)#css) (Normal s)\"\n  then obtain f where \n    f_0: \"f 0 = ([c1],(cs,c2#cs)#css,Normal s)\" and\n    f_step: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    by (auto simp add: inf_def)\n  def h\\<equiv>\"\\<lambda>i. case i of 0 \\<Rightarrow> (Catch c1 c2#cs,css,Normal s) | Suc j \\<Rightarrow> f j\" \n  with f_0 have\n    \"\\<Gamma>\\<turnstile>h 0 \\<rightarrow> h (Suc 0)\"\n    by (auto intro: step.intros)\n  moreover\n  from f_step have \"\\<forall>i. i\\<noteq>0 \\<longrightarrow> \\<Gamma>\\<turnstile>h i \\<rightarrow> h (Suc i)\"\n    by (auto simp add: h_def split: nat.splits)\n  ultimately\n  show \"inf \\<Gamma> (Catch c1 c2 # cs) css (Normal s)\"\n    apply (simp add: inf_def)\n    apply (rule_tac x=h in exI)\n    apply (simp add: h_def split: nat.splits)\n    done\nqed\n\ntheorem terminates_impl_not_inf: \n  assumes termi: \"\\<Gamma>\\<turnstile>c \\<down> s\"\n  shows \"\\<not>inf \\<Gamma> [c] [] s\"\nusing termi\nproof induct\n  case (Skip s) thus ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([Skip], [], Normal s)\" \n    from f_step [of 0] f_0\n    have \"f (Suc 0) = ([],[],Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step [of 1]\n    show False\n      by (auto elim: step_elim_cases)\n  qed\nnext\n  case (Basic g s) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([Basic g], [], Normal s)\" \n    from f_step [of 0] f_0\n    have \"f (Suc 0) = ([],[],Normal (g s))\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step [of 1]\n    show False\n      by (auto elim: step_elim_cases)\n  qed\nnext\n  case (Spec r s) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([Spec r], [], Normal s)\" \n    with f_step [of 0]\n    have \"\\<Gamma>\\<turnstile>([Spec r], [], Normal s) \\<rightarrow> f (Suc 0)\"\n      by simp\n    then show False\n    proof (cases)\n      fix t\n      assume \"(s, t) \\<in> r\" \"f (Suc 0) = ([], [], Normal t)\"\n      with f_step [of 1]\n      show False\n        by (auto elim: step_elim_cases)\n    next\n      assume \"\\<forall>t. (s, t) \\<notin> r\" \"f (Suc 0) = ([], [], Stuck)\"\n      with f_step [of 1]\n      show False\n        by (auto elim: step_elim_cases)\n    qed\n  qed\nnext\n  case (Guard s g c m)\n  have g: \"s \\<in> g\" by fact\n  have hyp: \"\\<not> inf \\<Gamma> [c] [] (Normal s)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([Guard m g c], [], Normal s)\" \n    from g f_step [of 0] f_0\n    have \"f (Suc 0) = ([c],[],Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step\n    have \"inf \\<Gamma> [c] [] (Normal s)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with hyp show False ..\n  qed\nnext\n  case (GuardFault s g m c)\n  have g: \"s \\<notin> g\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([Guard m g c], [], Normal s)\" \n    from g f_step [of 0] f_0\n    have \"f (Suc 0) = ([],[],Fault m)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step [of 1]\n    show False\n      by (auto elim: step_elim_cases)\n  qed\nnext\n  case (Fault c m)\n  thus ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([c], [], Fault m)\" \n    from f_step [of 0] f_0\n    have \"f (Suc 0) = ([],[],Fault m)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step [of 1]\n    show False\n      by (auto elim: step_elim_cases)\n  qed\nnext\n  case (Seq c1 s c2)\n  have hyp_c1: \"\\<not> inf \\<Gamma> [c1] [] (Normal s)\" by fact\n  have hyp_c2: \"\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> s' \\<longrightarrow> \\<Gamma>\\<turnstile>c2 \\<down> s' \\<and> \\<not> inf \\<Gamma> [c2] [] s'\" by fact\n  have \"\\<not> inf \\<Gamma> ([c1,c2]) [] (Normal s)\"\n  proof \n    assume \"inf \\<Gamma> [c1, c2] [] (Normal s)\"\n    then show False\n    proof (cases rule: infE)\n      assume \"inf \\<Gamma> [c1] [] (Normal s)\"\n      with hyp_c1 show ?thesis by simp\n    next\n      fix t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> t\" \"inf \\<Gamma> [c2] [] t\"\n      with hyp_c2 show ?thesis by simp\n    qed\n  qed\n  thus ?case\n    by (simp add: inf_Seq)\nnext\n  case (CondTrue s b c1 c2)\n  have b: \"s \\<in> b\" by fact\n  have hyp_c1: \"\\<not> inf \\<Gamma> [c1] [] (Normal s)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([Cond b c1 c2], [], Normal s)\" \n    from b f_step [of 0] f_0\n    have \"f 1 = ([c1],[],Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step\n    have \"inf \\<Gamma> [c1] [] (Normal s)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with hyp_c1 show False by simp\n  qed\nnext\n  case (CondFalse s b c2 c1)\n  have b: \"s \\<notin> b\" by fact\n  have hyp_c2: \"\\<not> inf \\<Gamma> [c2] [] (Normal s)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([Cond b c1 c2], [], Normal s)\" \n    from b f_step [of 0] f_0\n    have \"f 1 = ([c2],[],Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step\n    have \"inf \\<Gamma> [c2] [] (Normal s)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with hyp_c2 show False by simp\n  qed\nnext\n  case (WhileTrue s b c)\n  have b: \"s \\<in> b\" by fact\n  have hyp_c: \"\\<not> inf \\<Gamma> [c] [] (Normal s)\" by fact\n  have hyp_w: \"\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> s' \\<longrightarrow> \n                      \\<Gamma>\\<turnstile>While b c \\<down> s' \\<and> \\<not> inf \\<Gamma> [While b c] [] s'\" by fact\n  have \"\\<not> inf \\<Gamma> [c,While b c] [] (Normal s)\"\n  proof \n    assume \"inf \\<Gamma> [c,While b c] [] (Normal s)\"\n    from this hyp_c hyp_w show False\n      by (cases rule: infE) auto\n  qed\n  with b show ?case\n    by (simp add: inf_WhileTrue)\nnext\n  case (WhileFalse s b c)\n  have b: \"s \\<notin> b\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([While b c], [], Normal s)\" \n    from b f_step [of 0] f_0\n    have \"f (Suc 0) = ([],[],Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step [of 1]\n    show False\n      by (auto elim: step_elim_cases)\n  qed\nnext\n  case (Call p bdy s)\n  have bdy: \"\\<Gamma> p = Some bdy\" by fact\n  have hyp: \"\\<not> inf \\<Gamma> [bdy] [] (Normal s)\" by fact\n  have not_inf_bdy:\n    \"\\<not> inf \\<Gamma> [bdy] [([],[Throw])] (Normal s)\"\n  proof \n    assume \"inf \\<Gamma> [bdy] [([],[Throw])] (Normal s)\"\n    then show False\n    proof (rule infE)\n      assume \"inf \\<Gamma> [bdy] [] (Normal s)\"\n      with hyp show False by simp\n    next\n      fix t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal s\\<rangle> \\<Rightarrow> t\"\n      assume inf: \"inf \\<Gamma> [] [([], [Throw])] t\"\n      then obtain f where\n        f_0: \"f 0 = ([],[([], [Throw])],t)\" and\n        f_step: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n        by (auto simp add: inf_def)\n      show False\n      proof (cases t)\n        case (Normal t')\n        with f_0 f_step [rule_format, of 0]\n        have \"f (Suc 0) = ([],[],(Normal t'))\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step [rule_format, of \"Suc 0\"]\n        show False\n          by (auto elim: step.cases)\n      next        \n        case (Abrupt t')\n        with f_0 f_step [rule_format, of 0]\n        have \"f (Suc 0) = ([Throw],[],(Normal t'))\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step [rule_format, of \"Suc 0\"]\n        have \"f (Suc (Suc 0)) = ([],[],(Abrupt t'))\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step [rule_format, of \"Suc(Suc 0)\"]\n        show False\n          by (auto elim: step.cases)\n      next\n        case (Fault m)\n        with f_0 f_step [rule_format, of 0]\n        have \"f (Suc 0) = ([],[],Fault m)\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step [rule_format, of 1]\n        have \"f (Suc (Suc 0)) = ([],[],Fault m)\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step [rule_format, of \"Suc (Suc 0)\"]\n        show False\n          by (auto elim: step.cases)\n      next\n        case Stuck\n        with f_0 f_step [rule_format, of 0]\n        have \"f (Suc 0) = ([],[],Stuck)\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step [rule_format, of 1]\n        have \"f (Suc (Suc 0)) = ([],[],Stuck)\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step [rule_format, of \"Suc (Suc 0)\"]\n        show False\n          by (auto elim: step.cases)\n      qed\n    qed\n  qed   \n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([Call p], [], Normal s)\" \n    from bdy f_step [of 0] f_0\n    have \"f (Suc 0) = \n              ([bdy],[([],[Throw])],Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step\n    have \"inf \\<Gamma> [bdy] [([],[Throw])] (Normal s)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with not_inf_bdy\n    show False by simp\n  qed\nnext\n  case (CallUndefined p s)\n  have undef: \"\\<Gamma> p = None\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([Call p], [], Normal s)\" \n    from undef f_step [of 0] f_0\n    have \"f (Suc 0) = ([],[],Stuck)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step [rule_format, of \"Suc 0\"]\n    show False\n      by (auto elim: step_elim_cases)\n  qed\nnext\n  case (Stuck c)\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([c], [], Stuck)\" \n    from f_step [of 0] f_0\n    have \"f (Suc 0) = ([],[],Stuck)\"\n      by (auto elim: step_elim_cases)\n    with f_step [rule_format, of \"Suc 0\"]\n    show False\n      by (auto elim: step_elim_cases)\n  qed\nnext\n  case (DynCom c s)\n  have hyp: \"\\<not> inf \\<Gamma> [(c s)] [] (Normal s)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([DynCom c], [], Normal s)\" \n    from f_step [of 0] f_0\n    have \"f (Suc 0) = ([(c s)], [], Normal s)\"\n      by (auto elim: step_elim_cases)\n    with f_step have \"inf \\<Gamma> [(c s)] [] (Normal s)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with hyp\n    show False by simp\n  qed\nnext\n  case (Throw s) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([Throw], [], Normal s)\" \n    from f_step [of 0] f_0\n    have \"f (Suc 0) = ([],[],Abrupt s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step [of 1]\n    show False\n      by (auto elim: step_elim_cases)\n  qed\nnext\n  case (Abrupt c s)\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = ([c], [], Abrupt s)\" \n    from f_step [of 0] f_0\n    have \"f (Suc 0) = ([],[],Abrupt s)\"\n      by (auto elim: step_elim_cases)\n    with f_step [rule_format, of \"Suc 0\"]\n    show False\n      by (auto elim: step_elim_cases)\n  qed\nnext\n  case (Catch c1 s c2)\n  have hyp_c1: \"\\<not> inf \\<Gamma> [c1] [] (Normal s)\" by fact\n  have hyp_c2: \"\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> Abrupt s' \\<longrightarrow>\n                   \\<Gamma>\\<turnstile>c2 \\<down> Normal s' \\<and> \\<not> inf \\<Gamma> [c2] [] (Normal s')\" by fact\n  have \"\\<not> inf \\<Gamma> [c1] [([],[c2])] (Normal s)\"\n  proof \n    assume \"inf \\<Gamma> [c1] [([],[c2])] (Normal s)\"\n    then show False\n    proof (rule infE) \n      assume \"inf \\<Gamma> [c1] [] (Normal s)\"\n      with hyp_c1 show False by simp\n    next\n      fix t\n      assume eval: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> t\" \n      assume inf: \"inf \\<Gamma> [] [([], [c2])] t\"\n      then obtain f where\n        f_0: \"f 0 = ([],[([], [c2] )],t)\" and\n        f_step: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n        by (auto simp add: inf_def)\n      show False\n      proof (cases t)\n        case (Normal t')\n        with f_0 f_step [rule_format, of 0]\n        have \"f (Suc 0) = ([],[],Normal t')\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step [rule_format, of 1]\n        show False\n          by (auto elim: step_elim_cases)\n      next\n        case (Abrupt t')\n        with f_0 f_step [rule_format, of 0]\n        have \"f (Suc 0) = ([c2],[],Normal t')\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step eval Abrupt\n        have \"inf \\<Gamma> [c2] [] (Normal t')\"\n          apply (simp add: inf_def)\n          apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n          by simp\n        with eval hyp_c2 Abrupt show False by simp\n      next\n        case (Fault m)\n        with f_0 f_step [rule_format, of 0]\n        have \"f (Suc 0) = ([],[],Fault m)\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step [rule_format, of 1]\n        show False\n          by (auto elim: step_elim_cases)\n      next\n        case Stuck\n        with f_0 f_step [rule_format, of 0]\n        have \"f (Suc 0) = ([],[],Stuck)\"\n          by (auto elim: step_Normal_elim_cases)\n        with f_step [rule_format, of 1]\n        show False\n          by (auto elim: step_elim_cases)\n      qed\n    qed\n  qed\n  thus ?case\n    by (simp add: inf_Catch)\nqed\n\nlemma terminatess_impl_not_inf:\n assumes termi: \"\\<Gamma>\\<turnstile>cs,css\\<Down>s\" \n  shows \"\\<not>inf \\<Gamma> cs css s\"\nusing termi\nproof (induct)\n  case (Nil s)\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    hence \"\\<Gamma>\\<turnstile>f 0 \\<rightarrow> f (Suc 0)\" \n      by simp\n    moreover\n    assume \"f 0 = ([], [], s)\"\n    ultimately show False\n      by (fastforce elim: step.cases)\n  qed\nnext\n  case (ExitBlockNormal nrms css s abrs)\n  have hyp: \"\\<not> inf \\<Gamma> nrms css (Normal s)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f0: \"f 0 = ([], (nrms, abrs) # css, Normal s)\"\n    with f_step [of 0] have \"f (Suc 0) = (nrms,css,Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step have \"inf \\<Gamma> nrms css (Normal s)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp   \n    with hyp show False ..\n  qed\nnext\n  case (ExitBlockAbrupt abrs css s nrms)\n  have hyp: \"\\<not> inf \\<Gamma> abrs css (Normal s)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f0: \"f 0 = ([], (nrms, abrs) # css, Abrupt s)\"\n    with f_step [of 0] have \"f (Suc 0) = (abrs,css,Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step have \"inf \\<Gamma> abrs css (Normal s)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp   \n    with hyp show False ..\n  qed\nnext\n  case (ExitBlockFault nrms css f abrs)\n  show ?case\n    by (rule not_inf_Fault)\nnext\n  case (ExitBlockStuck nrms css abrs)\n  show ?case\n    by (rule not_inf_Stuck)\nnext\n  case (Cons c s cs css)\n  have termi_c: \"\\<Gamma>\\<turnstile>c \\<down> s\" by fact\n  have hyp: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t \\<longrightarrow> \\<Gamma>\\<turnstile>cs,css\\<Down>t \\<and> \\<not> inf \\<Gamma> cs css t\"  by fact\n  show \"\\<not> inf \\<Gamma> (c # cs) css s\"\n  proof \n    assume \"inf \\<Gamma> (c # cs) css s\"\n    thus False\n    proof (rule infE)\n      assume \"inf \\<Gamma> [c] [] s\"\n      with terminates_impl_not_inf [OF termi_c]\n      show False ..\n    next\n      fix t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t\" \"inf \\<Gamma> cs css t\"\n      with hyp show False by simp\n    qed\n  qed\nqed\n\nlemma lem:\n  \"\\<forall>y. r\\<^sup>+\\<^sup>+ a y \\<longrightarrow> P a \\<longrightarrow> P y \n   \\<Longrightarrow> ((b,a) \\<in> {(y,x). P x \\<and> r x y}\\<^sup>+) = ((b,a) \\<in> {(y,x). P x \\<and> r\\<^sup>+\\<^sup>+ x y})\"\napply(rule iffI)\n apply clarify\n apply(erule trancl_induct)\n  apply blast\n apply(blast intro:tranclp_trans)\napply clarify\napply(erule tranclp_induct)\n apply blast\napply(blast intro:trancl_trans)\ndone\n\ncorollary terminatess_impl_no_inf_chain:\n assumes terminatess: \"\\<Gamma>\\<turnstile>cs,css\\<Down>s\"\n shows \"\\<not>(\\<exists>f. f 0 = (cs,css,s) \\<and> (\\<forall>i::nat. \\<Gamma>\\<turnstile>f i \\<rightarrow>\\<^sup>+ f(Suc i)))\"\nproof -\n  have \"wf({(y,x). \\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow> y}\\<^sup>+)\"\n  proof (rule wf_trancl)\n    show \"wf {(y, x). \\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow> y}\"\n    proof (simp only: wf_iff_no_infinite_down_chain,clarify,simp)\n      fix f\n      assume \"\\<forall>i. \\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* f i \\<and> \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n      hence \"\\<exists>f. f 0 = (cs, css, s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i))\"\n        by (rule renumber [to_pred])\n      moreover from terminatess\n      have \"\\<not> (\\<exists>f. f 0 = (cs, css, s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)))\"\n        by (rule terminatess_impl_not_inf [unfolded inf_def])\n      ultimately show False\n        by simp\n    qed\n  qed\n  hence \"\\<not> (\\<exists>f. \\<forall>i. (f (Suc i), f i)\n                 \\<in> {(y, x). \\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow> y}\\<^sup>+)\"\n    by (simp add: wf_iff_no_infinite_down_chain)\n  thus ?thesis\n  proof (rule contrapos_nn)\n    assume \"\\<exists>f. f 0 = (cs, css, s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow>\\<^sup>+ f (Suc i))\"\n    then obtain f where\n      f0: \"f 0 = (cs, css, s)\" and\n      seq: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow>\\<^sup>+ f (Suc i)\"\n      by iprover\n    show \n      \"\\<exists>f. \\<forall>i. (f (Suc i), f i) \\<in> {(y, x). \\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow> y}\\<^sup>+\"\n    proof (rule exI [where x=f],rule allI)\n      fix i\n      show \"(f (Suc i), f i) \\<in> {(y, x). \\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow> y}\\<^sup>+\"\n      proof -   \n        {\n          fix i have \"\\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow>\\<^sup>* f i\"\n          proof (induct i)\n            case 0 show \"\\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* f 0\"\n              by (simp add: f0)\n          next\n            case (Suc n)\n            have \"\\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* f n\"  by fact\n            with seq show \"\\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* f (Suc n)\"\n              by (blast intro: tranclp_into_rtranclp rtranclp_trans)\n          qed\n        }\n        hence \"\\<Gamma>\\<turnstile>(cs,css,s) \\<rightarrow>\\<^sup>* f i\"\n          by iprover\n        with seq have\n          \"(f (Suc i), f i) \\<in> {(y, x). \\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow>\\<^sup>+ y}\"\n          by clarsimp\n        moreover \n        have \"\\<forall>y. \\<Gamma>\\<turnstile>f i \\<rightarrow>\\<^sup>+ y\\<longrightarrow>\\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* f i\\<longrightarrow>\\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* y\"\n          by (blast intro: tranclp_into_rtranclp rtranclp_trans)\n        ultimately \n        show ?thesis \n          by (subst lem)\n      qed\n    qed\n  qed\nqed\n\ncorollary terminates_impl_no_inf_chain:\n \"\\<Gamma>\\<turnstile>c\\<down>s \\<Longrightarrow> \\<not>(\\<exists>f. f 0 = ([c],[],s) \\<and> (\\<forall>i::nat. \\<Gamma>\\<turnstile>f i \\<rightarrow>\\<^sup>+ f(Suc i)))\"\n  by (rule terminatess_impl_no_inf_chain) (iprover intro: terminatess.intros)\n\n\ndefinition\n termi_call_steps :: \"('s,'p,'f) body \\<Rightarrow> (('s \\<times> 'p) \\<times> ('s \\<times> 'p))set\"\nwhere\n\"termi_call_steps \\<Gamma> =\n {((t,q),(s,p)). \\<Gamma>\\<turnstile>the (\\<Gamma> p)\\<down>Normal s \\<and> \n       (\\<exists>css. \\<Gamma>\\<turnstile>([the (\\<Gamma> p)],[],Normal s) \\<rightarrow>\\<^sup>+ ([the (\\<Gamma> q)],css,Normal t))}\"\n\ntext {* Sequencing computations, or more exactly continuation stacks *}\nprimrec seq:: \"(nat \\<Rightarrow> 'a list) \\<Rightarrow> nat \\<Rightarrow> 'a list\"\nwhere\n\"seq css 0 = []\" |\n\"seq css (Suc i) = css i@seq css i\"\n\n\ntheorem wf_termi_call_steps: \"wf (termi_call_steps \\<Gamma>)\"\nproof (simp only: termi_call_steps_def wf_iff_no_infinite_down_chain,\n       clarify,simp)\n  fix S\n  assume inf:\n     \"\\<forall>i. (\\<lambda>(t,q) (s,p). \\<Gamma>\\<turnstile>(the (\\<Gamma> p)) \\<down> Normal s \\<and>\n                 (\\<exists>css. \\<Gamma>\\<turnstile>([the (\\<Gamma> p)],[],Normal s) \\<rightarrow>\\<^sup>+ ([the (\\<Gamma> q)],css,Normal t)))\n           (S (Suc i)) (S i)\"\n  obtain s p where \"s = (\\<lambda>i. fst (S i))\" and \"p = (\\<lambda>i. snd (S i))\" \n    by auto\n  with inf\n  have inf':\n     \"\\<forall>i. \\<Gamma>\\<turnstile>(the (\\<Gamma> (p i))) \\<down> Normal (s i) \\<and>\n                 (\\<exists>css. \\<Gamma>\\<turnstile>([the (\\<Gamma> (p i))],[],Normal (s i)) \\<rightarrow>\\<^sup>+ \n                           ([the (\\<Gamma> (p (Suc i)))],css,Normal (s (Suc i))))\"\n    apply -\n    apply (rule allI)\n    apply (erule_tac x=i in allE)\n    apply auto\n    done\n  show False\n  proof -\n    from inf' -- {* Skolemization of css with axiom of choice *}\n    have \"\\<exists>css. \\<forall>i. \\<Gamma>\\<turnstile>(the (\\<Gamma> (p i))) \\<down> Normal (s i) \\<and>\n                 \\<Gamma>\\<turnstile>([the (\\<Gamma> (p i))],[],Normal (s i)) \\<rightarrow>\\<^sup>+ \n                           ([the (\\<Gamma> (p (Suc i)))],css i,Normal (s (Suc i)))\"\n      apply -\n      apply (rule choice)\n      by blast\n    then obtain css where\n      termi_css: \"\\<forall>i. \\<Gamma>\\<turnstile>(the (\\<Gamma> (p i))) \\<down> Normal (s i)\" and\n      step_css: \"\\<forall>i. \\<Gamma>\\<turnstile>([the (\\<Gamma> (p i))],[],Normal (s i)) \\<rightarrow>\\<^sup>+ \n                         ([the (\\<Gamma> (p (Suc i)))],css i,Normal (s (Suc i)))\"\n      by blast\n    def f == \"\\<lambda>i. ([the (\\<Gamma> (p i))], seq css i,Normal (s i)::('a,'c) xstate)\"\n    have \"f 0 = ([the (\\<Gamma> (p 0))],[],Normal (s 0))\"\n      by (simp add: f_def)\n    moreover\n    have \"\\<forall>i. \\<Gamma>\\<turnstile> (f i) \\<rightarrow>\\<^sup>+ (f (i+1))\"\n    proof \n      fix i\n      from step_css [rule_format, of i]\n      have \"\\<Gamma>\\<turnstile>([the (\\<Gamma> (p i))], [], Normal (s i)) \\<rightarrow>\\<^sup>+ \n              ([the (\\<Gamma> (p (Suc i)))], css i, Normal (s (Suc i)))\".\n      from app_css_steps [OF this,simplified]\n      have \"\\<Gamma>\\<turnstile>([the (\\<Gamma> (p i))], seq css i, Normal (s i)) \\<rightarrow>\\<^sup>+ \n              ([the (\\<Gamma> (p (Suc i)))], css i@seq css i, Normal (s (Suc i)))\".\n      thus \"\\<Gamma>\\<turnstile> (f i) \\<rightarrow>\\<^sup>+ (f (i+1))\"\n        by (simp add: f_def)\n    qed\n    moreover from termi_css [rule_format, of 0]\n    have \"\\<not> (\\<exists>f. (f 0 = ([the (\\<Gamma> (p 0))],[],Normal (s 0)) \\<and> \n                 (\\<forall>i. \\<Gamma>\\<turnstile>(f i) \\<rightarrow>\\<^sup>+ f(Suc i))))\"\n      by (rule terminates_impl_no_inf_chain)\n    ultimately show False\n      by auto\n  qed\nqed\n\ntext {* An alternative proof using Hilbert-choice instead of axiom of choice.*}\ntheorem \"wf (termi_call_steps \\<Gamma>)\"\nproof (simp only: termi_call_steps_def wf_iff_no_infinite_down_chain,\n       clarify,simp)\n  fix S\n  assume inf:\n     \"\\<forall>i. (\\<lambda>(t,q) (s,p). \\<Gamma>\\<turnstile>(the (\\<Gamma> p)) \\<down> Normal s \\<and>\n                 (\\<exists>css. \\<Gamma>\\<turnstile>([the (\\<Gamma> p)],[],Normal s) \\<rightarrow>\\<^sup>+ ([the (\\<Gamma> q)],css,Normal t)))\n           (S (Suc i)) (S i)\"\n  obtain s p where \"s = (\\<lambda>i. fst (S i))\" and \"p = (\\<lambda>i. snd (S i))\" \n    by auto\n  with inf\n  have inf':\n     \"\\<forall>i. \\<Gamma>\\<turnstile>(the (\\<Gamma> (p i))) \\<down> Normal (s i) \\<and>\n                 (\\<exists>css. \\<Gamma>\\<turnstile>([the (\\<Gamma> (p i))],[],Normal (s i)) \\<rightarrow>\\<^sup>+ \n                           ([the (\\<Gamma> (p (Suc i)))],css,Normal (s (Suc i))))\"\n    apply -\n    apply (rule allI)\n    apply (erule_tac x=i in allE)\n    apply auto\n    done\n  show \"False\"\n  proof -\n    def CSS \\<equiv> \"\\<lambda>i. (SOME css.  \n                      \\<Gamma>\\<turnstile>([the (\\<Gamma> (p i))],[], Normal (s i)) \\<rightarrow>\\<^sup>+\n                      ([the (\\<Gamma> (p (i+1)))],css,Normal (s (i+1))))\"\n    def f == \"\\<lambda>i. ([the (\\<Gamma> (p i))], seq CSS i,Normal (s i)::('a,'c) xstate)\"\n    have \"f 0 = ([the (\\<Gamma> (p 0))],[],Normal (s 0))\"\n      by (simp add: f_def)\n    moreover\n    have \"\\<forall>i. \\<Gamma>\\<turnstile> (f i) \\<rightarrow>\\<^sup>+ (f (i+1))\"\n    proof \n      fix i\n      from inf' [rule_format, of i] obtain css where\n         css: \"\\<Gamma>\\<turnstile>([the (\\<Gamma> (p i))],[],Normal (s i)) \\<rightarrow>\\<^sup>+ \n                ([the (\\<Gamma> (p (i+1)))],css,Normal (s (i+1)))\"\n        by fastforce\n      hence \"\\<Gamma>\\<turnstile>([the (\\<Gamma> (p i))], seq CSS i, Normal (s i)) \\<rightarrow>\\<^sup>+ \n                  ([the (\\<Gamma> (p (i+1)))], CSS i @ seq CSS i, Normal (s (i+1)))\"\n        apply -\n        apply (unfold CSS_def)\n        apply (rule someI2 \n              [where P=\"\\<lambda>css. \n                    \\<Gamma>\\<turnstile>([the (\\<Gamma> (p i))],[],Normal (s i))\\<rightarrow>\\<^sup>+\n                         ([the (\\<Gamma> (p (i+1)))],css, Normal (s (i+1)))\"])\n        apply (rule css)\n        apply (fastforce dest: app_css_steps)\n        done\n      thus \"\\<Gamma>\\<turnstile> (f i) \\<rightarrow>\\<^sup>+ (f (i+1))\"\n        by (simp add: f_def)\n    qed\n    moreover from inf' [rule_format, of 0]\n    have \"\\<Gamma>\\<turnstile>the (\\<Gamma> (p 0)) \\<down> Normal (s 0)\" \n      by iprover\n    then have \"\\<not> (\\<exists>f. (f 0 = ([the (\\<Gamma> (p 0))],[],Normal (s 0)) \\<and> \n                 (\\<forall>i. \\<Gamma>\\<turnstile>(f i) \\<rightarrow>\\<^sup>+ f(Suc i))))\"\n      by (rule terminates_impl_no_inf_chain)\n    ultimately show False\n      by auto\n  qed\nqed\n\nlemma not_inf_implies_wf: assumes not_inf: \"\\<not> inf \\<Gamma> cs css s\"\n  shows \"wf {(c2,c1). \\<Gamma> \\<turnstile> (cs,css,s) \\<rightarrow>\\<^sup>* c1 \\<and> \\<Gamma> \\<turnstile> c1 \\<rightarrow> c2}\"\nproof (simp only: wf_iff_no_infinite_down_chain,clarify, simp)\n  fix f\n  assume \"\\<forall>i. \\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* f i \\<and> \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n  hence \"\\<exists>f. f 0 = (cs, css, s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i))\"\n    by (rule renumber [to_pred])\n  moreover from not_inf\n  have \"\\<not> (\\<exists>f. f 0 = (cs, css, s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)))\"\n    by (unfold inf_def)\n  ultimately show False\n    by simp\nqed\n\nlemma wf_implies_termi_reach:\nassumes wf: \"wf {(c2,c1). \\<Gamma> \\<turnstile> (cs,css,s) \\<rightarrow>\\<^sup>* c1 \\<and> \\<Gamma> \\<turnstile> c1 \\<rightarrow> c2}\"\nshows \"\\<And>cs1 css1 s1. \\<lbrakk>\\<Gamma> \\<turnstile> (cs,css,s) \\<rightarrow>\\<^sup>* c1;  c1=(cs1,css1,s1)\\<rbrakk>\\<Longrightarrow> \\<Gamma>\\<turnstile>cs1,css1\\<Down>s1\"\nusing wf \nproof (induct c1, simp)\n  fix cs1 css1 s1\n  assume reach: \"\\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* (cs1, css1, s1)\"\n  assume hyp_raw: \"\\<And>y cs2 css2 s2. \\<lbrakk>\\<Gamma> \\<turnstile> (cs1,css1,s1) \\<rightarrow> (cs2,css2,s2);\n                 \\<Gamma> \\<turnstile> (cs,css,s) \\<rightarrow>\\<^sup>* (cs2,css2,s2); y=(cs2,css2,s2)\\<rbrakk> \\<Longrightarrow> \n                 \\<Gamma>\\<turnstile>cs2,css2\\<Down>s2\"\n  have hyp: \"\\<And>cs2 css2 s2. \\<lbrakk>\\<Gamma> \\<turnstile> (cs1,css1,s1) \\<rightarrow> (cs2,css2,s2)\\<rbrakk> \\<Longrightarrow> \n                 \\<Gamma>\\<turnstile>cs2,css2\\<Down>s2\"\n    apply -\n    apply (rule hyp_raw)\n    apply   assumption\n    using reach \n    apply  simp\n    apply (rule refl)\n    done\n  show \"\\<Gamma>\\<turnstile>cs1,css1\\<Down>s1\"\n  proof (cases s1)\n    case (Normal s1')\n    show ?thesis\n    proof (cases cs1)\n      case Nil\n      note cs1_Nil = this\n      show ?thesis\n      proof (cases css1)\n        case Nil\n        with cs1_Nil show ?thesis\n          by (auto intro: terminatess.intros)\n      next\n        case (Cons nrms_abrs css1')\n        then obtain nrms abrs where nrms_abrs: \"nrms_abrs=(nrms,abrs)\"\n          by (cases \"nrms_abrs\")\n        have \"\\<Gamma> \\<turnstile> ([],(nrms,abrs)#css1',Normal s1') \\<rightarrow> (nrms,css1',Normal s1')\"\n          by (rule step.intros)\n        from hyp [simplified cs1_Nil Cons nrms_abrs Normal, OF this]\n        have \"\\<Gamma>\\<turnstile>nrms,css1'\\<Down>Normal s1'\".\n        from ExitBlockNormal [OF this] cs1_Nil Cons nrms_abrs Normal\n        show ?thesis\n          by auto\n      qed\n    next\n      case (Cons c1 cs1')\n      have \"\\<Gamma>\\<turnstile>c1#cs1',css1\\<Down>Normal s1'\"\n      proof (cases c1)\n        case Skip\n        have \"\\<Gamma> \\<turnstile> (Skip#cs1',css1,Normal s1') \\<rightarrow> (cs1',css1,Normal s1')\"\n          by (rule step.intros)\n        from hyp [simplified Cons Skip Normal, OF this]\n        have \"\\<Gamma>\\<turnstile>cs1',css1\\<Down>Normal s1'\".\n        with Normal Skip show ?thesis\n          by (auto intro: terminatess.intros terminates.intros \n                  elim: exec_Normal_elim_cases)\n      next\n        case (Basic f)\n        have \"\\<Gamma> \\<turnstile> (Basic f#cs1',css1,Normal s1') \\<rightarrow> (cs1',css1,Normal (f s1'))\"\n          by (rule step.intros)\n        from hyp [simplified Cons Basic Normal, OF this]\n        have \"\\<Gamma>\\<turnstile>cs1',css1\\<Down>Normal (f s1')\".\n        with Normal Basic show ?thesis\n          by (auto intro: terminatess.intros terminates.intros \n                  elim: exec_Normal_elim_cases)\n      next\n        case (Spec r)\n        with Normal show ?thesis\n          apply simp\n          apply (rule terminatess.Cons)\n          apply  (fastforce intro: terminates.intros)\n          apply (clarify)\n          apply (erule exec_Normal_elim_cases)\n          apply  clarsimp\n          apply  (rule hyp)\n          apply  (fastforce intro: step.intros simp add: Cons Spec Normal )\n          apply (fastforce intro: terminatess_Stuck)\n          done\n      next\n        case (Seq c\\<^sub>1 c\\<^sub>2)\n        have \"\\<Gamma> \\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2#cs1',css1,Normal s1') \\<rightarrow> (c\\<^sub>1#c\\<^sub>2#cs1',css1,Normal s1')\"\n          by (rule step.intros)\n        from hyp [simplified Cons Seq Normal, OF this]\n        have \"\\<Gamma>\\<turnstile>c\\<^sub>1 # c\\<^sub>2 # cs1',css1\\<Down>Normal s1'\".\n        with Normal Seq show ?thesis\n          by (fastforce intro: terminatess.intros terminates.intros\n                   elim: terminatess_elim_cases exec_Normal_elim_cases)\n      next\n        case (Cond b c\\<^sub>1 c\\<^sub>2)\n        show ?thesis\n        proof (cases \"s1' \\<in> b\")\n          case True\n          hence \"\\<Gamma>\\<turnstile>(Cond b c\\<^sub>1 c\\<^sub>2#cs1',css1,Normal s1') \\<rightarrow> (c\\<^sub>1#cs1',css1,Normal s1')\"\n            by (rule step.intros)\n          from hyp [simplified Cons Cond Normal, OF this]\n          have \"\\<Gamma>\\<turnstile>c\\<^sub>1 # cs1',css1\\<Down>Normal s1'\".\n          with Normal Cond True show ?thesis\n            by (fastforce intro: terminatess.intros terminates.intros\n              elim: terminatess_elim_cases exec_Normal_elim_cases)\n        next\n          case False\n          hence \"\\<Gamma>\\<turnstile>(Cond b c\\<^sub>1 c\\<^sub>2#cs1',css1,Normal s1') \\<rightarrow> (c\\<^sub>2#cs1',css1,Normal s1')\"\n            by (rule step.intros)\n          from hyp [simplified Cons Cond Normal, OF this]\n          have \"\\<Gamma>\\<turnstile>c\\<^sub>2 # cs1',css1\\<Down>Normal s1'\".\n          with Normal Cond False show ?thesis\n            by (fastforce intro: terminatess.intros terminates.intros\n              elim: terminatess_elim_cases exec_Normal_elim_cases)\n        qed\n      next\n        case (While b c')\n        show ?thesis\n        proof (cases \"s1' \\<in> b\")\n          case True\n          then have \"\\<Gamma>\\<turnstile>(While b c' # cs1', css1, Normal s1') \\<rightarrow> \n                       (c' # While b c' # cs1', css1, Normal s1')\"\n            by (rule step.intros)\n          from hyp [simplified Cons While Normal, OF this]\n          have \"\\<Gamma>\\<turnstile>c' # While b c' # cs1',css1\\<Down>Normal s1'\".\n          with Cons While True Normal\n          show ?thesis\n            by (fastforce intro: terminatess.intros terminates.intros exec.intros \n                    elim: terminatess_elim_cases exec_Normal_elim_cases)\n        next\n          case False\n          then \n          have \"\\<Gamma>\\<turnstile>(While b c' # cs1', css1, Normal s1') \\<rightarrow> (cs1', css1, Normal s1')\"\n            by (rule step.intros)\n          from hyp [simplified Cons While Normal, OF this]\n          have \"\\<Gamma>\\<turnstile>cs1',css1\\<Down>Normal s1'\".\n          with Cons While False Normal\n          show ?thesis\n            by (fastforce intro: terminatess.intros terminates.intros exec.intros \n                    elim: terminatess_elim_cases exec_Normal_elim_cases)\n        qed\n      next\n        case (Call p)\n        show ?thesis\n        proof (cases \"\\<Gamma> p\")\n          case None\n          with Call Normal show ?thesis\n            by (fastforce intro: terminatess.intros terminates.intros terminatess_Stuck\n                 elim: exec_Normal_elim_cases)\n        next\n          case (Some bdy)\n          then\n          have \"\\<Gamma> \\<turnstile> (Call p#cs1',css1,Normal s1') \\<rightarrow> \n                    ([bdy],(cs1',Throw#cs1')#css1,Normal s1')\"\n            by (rule step.intros)\n          from hyp [simplified Cons Call Normal Some, OF this]\n          have \"\\<Gamma>\\<turnstile>[bdy],(cs1', Throw # cs1') # css1\\<Down>Normal s1'\".\n          with Some Call Normal show ?thesis\n            apply simp\n            apply (rule terminatess.intros)\n            apply (blast elim: terminatess_elim_cases intro: terminates.intros)\n            apply clarify\n            apply (erule terminatess_elim_cases)\n            apply (erule exec_Normal_elim_cases)\n            prefer 2\n            apply  simp\n            apply (erule_tac x=t in allE)\n            apply (case_tac t)\n            apply (auto intro: terminatess_Stuck terminatess_Fault exec.intros \n                    elim: terminatess_elim_cases exec_Normal_elim_cases)\n            done\n        qed\n      next\n        case (DynCom c')\n        have \"\\<Gamma> \\<turnstile> (DynCom c'#cs1',css1,Normal s1') \\<rightarrow> (c' s1'#cs1',css1,Normal s1')\"\n          by (rule step.intros)\n        from hyp [simplified Cons DynCom Normal, OF this]\n        have \"\\<Gamma>\\<turnstile>c' s1'#cs1',css1\\<Down>Normal s1'\".\n        with Normal DynCom show ?thesis\n          by (fastforce intro: terminatess.intros terminates.intros exec.intros \n                    elim: terminatess_elim_cases exec_Normal_elim_cases)\n      next\n        case (Guard f g c')\n        show ?thesis\n        proof (cases \"s1' \\<in> g\")\n          case True\n          then have \"\\<Gamma> \\<turnstile> (Guard f g c'#cs1',css1,Normal s1') \\<rightarrow> (c'#cs1',css1,Normal s1')\"\n            by (rule step.intros)\n          from hyp [simplified Cons Guard Normal, OF this]\n          have \"\\<Gamma>\\<turnstile>c'#cs1',css1\\<Down>Normal s1'\".\n          with Normal Guard True show ?thesis\n            by (fastforce intro: terminatess.intros terminates.intros exec.intros \n                    elim: terminatess_elim_cases exec_Normal_elim_cases)\n        next\n          case False\n          with Guard Normal show ?thesis\n            by (fastforce intro: terminatess.intros terminatess_Fault \n                                terminates.intros  \n                 elim:  exec_Normal_elim_cases)\n        qed\n      next\n        case Throw\n        have \"\\<Gamma> \\<turnstile> (Throw#cs1',css1,Normal s1') \\<rightarrow> (cs1',css1,Abrupt s1')\"\n          by (rule step.intros)\n        from hyp [simplified Cons Throw Normal, OF this]\n        have \"\\<Gamma>\\<turnstile>cs1',css1\\<Down>Abrupt s1'\".\n        with Normal Throw show ?thesis\n          by (auto intro: terminatess.intros terminates.intros \n                  elim: exec_Normal_elim_cases)\n      next\n        case (Catch c\\<^sub>1 c\\<^sub>2)\n        have \"\\<Gamma> \\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2#cs1',css1,Normal s1') \\<rightarrow> \n                  ([c\\<^sub>1], (cs1',c\\<^sub>2#cs1')# css1,Normal s1')\"\n          by (rule step.intros)\n        from hyp [simplified Cons Catch Normal, OF this]\n        have \"\\<Gamma>\\<turnstile>[c\\<^sub>1],(cs1', c\\<^sub>2 # cs1') # css1\\<Down>Normal s1'\".\n        with Normal Catch show ?thesis\n          by (fastforce intro: terminatess.intros terminates.intros exec.intros \n                    elim: terminatess_elim_cases exec_Normal_elim_cases)\n      qed       \n      with Cons Normal show ?thesis\n        by simp\n    qed\n  next\n    case (Abrupt s1')\n    show ?thesis\n    proof (cases cs1)\n      case Nil\n      note cs1_Nil = this\n      show ?thesis\n      proof (cases css1)\n        case Nil\n        with cs1_Nil show ?thesis by (auto intro: terminatess.intros)\n      next\n        case (Cons nrms_abrs css1')\n        then obtain nrms abrs where nrms_abrs: \"nrms_abrs=(nrms,abrs)\"\n          by (cases \"nrms_abrs\")\n        have \"\\<Gamma> \\<turnstile> ([],(nrms,abrs)#css1',Abrupt s1') \\<rightarrow> (abrs,css1',Normal s1')\"\n          by (rule step.intros)\n        from hyp [simplified cs1_Nil Cons nrms_abrs Abrupt, OF this]\n        have \"\\<Gamma>\\<turnstile>abrs,css1'\\<Down>Normal s1'\".\n        from ExitBlockAbrupt [OF this] cs1_Nil Cons nrms_abrs Abrupt\n        show ?thesis\n          by auto\n      qed\n    next\n      case (Cons c1 cs1')\n      have \"\\<Gamma>\\<turnstile>c1#cs1',css1\\<Down>Abrupt s1'\"\n      proof -\n        have \"\\<Gamma> \\<turnstile> (c1#cs1',css1,Abrupt s1') \\<rightarrow> (cs1',css1,Abrupt s1')\"\n          by (rule step.intros)\n        from hyp [simplified Cons Abrupt, OF this]\n        have \"\\<Gamma>\\<turnstile>cs1',css1\\<Down>Abrupt s1'\".\n        with Cons Abrupt\n        show ?thesis\n          by (fastforce intro: terminatess.intros terminates.intros exec.intros \n                    elim: terminatess_elim_cases exec_Normal_elim_cases)\n      qed\n      with Cons Abrupt show ?thesis by simp\n    qed\n  next\n    case (Fault f)\n    thus ?thesis by (auto intro: terminatess_Fault)\n  next\n    case Stuck\n    thus ?thesis by (auto intro: terminatess_Stuck)\n  qed\nqed\n\nlemma not_inf_impl_terminatess:\n  assumes not_inf: \"\\<not> inf \\<Gamma> cs css s\"\n  shows \"\\<Gamma>\\<turnstile>cs,css\\<Down>s\"\nproof -\n  from not_inf_implies_wf [OF not_inf]\n  have wf: \"wf {(c2, c1). \\<Gamma>\\<turnstile>(cs, css, s) \\<rightarrow>\\<^sup>* c1 \\<and> \\<Gamma>\\<turnstile>c1 \\<rightarrow> c2}\".\n  show ?thesis\n    by (rule wf_implies_termi_reach [OF wf]) auto\nqed\n\nlemma not_inf_impl_terminates:\n  assumes not_inf: \"\\<not> inf \\<Gamma> [c] [] s\"\n  shows \"\\<Gamma>\\<turnstile>c\\<down>s\"\nproof -\n  from not_inf_impl_terminatess [OF not_inf]\n  have \"\\<Gamma>\\<turnstile>[c],[]\\<Down>s\".\n  thus ?thesis\n    by (auto elim: terminatess_elim_cases)\nqed\n\ntheorem terminatess_iff_not_inf: \n  \"\\<Gamma>\\<turnstile>cs,css\\<Down>s = (\\<not> inf \\<Gamma> cs css s)\"\n  apply rule\n  apply  (erule terminatess_impl_not_inf)\n  apply (erule not_inf_impl_terminatess)\n  done\n\ncorollary terminates_iff_not_inf: \n  \"\\<Gamma>\\<turnstile>c\\<down>s = (\\<not> inf \\<Gamma> [c] [] s)\"\n  apply (rule)\n  apply  (erule terminates_impl_not_inf)\n  apply (erule not_inf_impl_terminates)\n  done\n\nsubsection {* Completeness of Total Correctness Hoare Logic*}\n\nlemma ConseqMGT: \n  assumes modif: \"\\<forall>Z::'a. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z::'a assn) c (Q' Z),(A' Z)\"\n  assumes impl: \"\\<And>s. s \\<in> P \\<Longrightarrow> s \\<in> P' s \\<and> (\\<forall>t. t \\<in> Q' s \\<longrightarrow> t \\<in> Q) \\<and> \n                                            (\\<forall>t. t \\<in> A' s \\<longrightarrow> t \\<in> A)\"\n  shows \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nusing impl \nby - (rule conseq [OF modif],blast)\n\nlemma conseq_extract_state_indep_prop: \n  assumes state_indep_prop:\"\\<forall>s \\<in> P. R\" \n  assumes to_show: \"R \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule Conseq)\n  apply (clarify)\n  apply (rule_tac x=\"P\" in exI)\n  apply (rule_tac x=\"Q\" in exI)\n  apply (rule_tac x=\"A\" in exI)\n  using state_indep_prop to_show\n  by blast\n\n\n\n\ntext {* To prove a procedure implementation correct it suffices to assume\n       only the procedure specifications of procedures that actually\n       occur during evaluation of the body.  \n    *}\nlemma Call_lemma:\n assumes \n Call: \"\\<forall>q \\<in> dom \\<Gamma>. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> \n                 {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call q\\<down>Normal s \\<and> ((s,q),(\\<sigma>,p)) \\<in> termi_call_steps \\<Gamma>}\n                 (Call q)\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n shows \"\\<And>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>  \n              ({\\<sigma>} \\<inter> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>  \n                                 \\<Gamma>\\<turnstile>the (\\<Gamma> p)\\<down>Normal s}) \n                 the (\\<Gamma> p) \n              {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (rule conseqPre)\napply (rule Call_lemma')\napply (rule Call)\napply blast\ndone\n\nlemma Call_lemma_switch_Call_body:\n assumes \n call: \"\\<forall>q \\<in> dom \\<Gamma>. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> \n                 {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call q\\<down>Normal s \\<and> ((s,q),(\\<sigma>,p)) \\<in> termi_call_steps \\<Gamma>}\n                 (Call q)\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n assumes p_defined: \"p \\<in> dom \\<Gamma>\"\n shows \"\\<And>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>  \n              ({\\<sigma>} \\<inter> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>  \n                                 \\<Gamma>\\<turnstile>Call p\\<down>Normal s}) \n                 the (\\<Gamma> p) \n              {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (simp only: exec_Call_body' [OF p_defined] noFaultStuck_Call_body' [OF p_defined] terminates_Normal_Call_body [OF p_defined])\napply (rule conseqPre)\napply (rule Call_lemma')\napply (rule call)\napply blast\ndone\n\n\nlemma MGT_Call:\n\"\\<forall>p \\<in> dom \\<Gamma>. \\<forall>Z. \n  \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n             \\<Gamma>\\<turnstile>(Call p)\\<down>Normal s}\n           (Call p)\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (intro ballI allI)\napply (rule CallRec' [where Procs=\"dom \\<Gamma>\" and\n    P=\"\\<lambda>p Z. {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call p\\<down>Normal s}\" and\n    Q=\"\\<lambda>p Z. {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t}\" and\n    A=\"\\<lambda>p Z. {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" and\n    r=\"termi_call_steps \\<Gamma>\"\n    ]) \napply    simp\napply   simp\napply  (rule wf_termi_call_steps)\napply (intro ballI allI)\napply simp\napply (rule Call_lemma_switch_Call_body [rule_format, simplified])\napply  (rule hoaret.Asm)\napply  fastforce\napply assumption\ndone\n\n\nlemma CollInt_iff: \"{s. P s} \\<inter> {s. Q s} = {s. P s \\<and> Q s}\"\n  by auto\n\nlemma image_Un_conv: \"f ` (\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. {x p Z}) =  (\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. {f (x p Z)})\"\n  by (auto iff: not_None_eq)\n\n\ntext {* Another proof of @{text MGT_Call}, maybe a little more readable *}\nlemma \n\"\\<forall>p \\<in> dom \\<Gamma>. \\<forall>Z. \n  \\<Gamma>,{} \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n             \\<Gamma>\\<turnstile>(Call p)\\<down>Normal s}\n           (Call p)\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\nproof -\n  {\n    fix p Z \\<sigma>\n    assume defined: \"p \\<in> dom \\<Gamma>\"\n    def Specs == \"(\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. \n            {({s. s=Z \\<and> \n              \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n              \\<Gamma>\\<turnstile>Call p\\<down>Normal s},\n             p,\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})})\"\n    def Specs_wf == \"(\\<lambda>p \\<sigma>. (\\<lambda>(P,q,Q,A). \n                       (P \\<inter> {s. ((s,q),\\<sigma>,p) \\<in> termi_call_steps \\<Gamma>}, q, Q, A)) ` Specs)\"\n    have \"\\<Gamma>,Specs_wf p \\<sigma>\n            \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>({\\<sigma>} \\<inter>\n                 {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                  \\<Gamma>\\<turnstile>the (\\<Gamma> p)\\<down>Normal s}) \n                (the (\\<Gamma> p))\n               {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      apply (rule Call_lemma [rule_format])\n      apply (rule hoaret.Asm)\n      apply (clarsimp simp add: Specs_wf_def Specs_def image_Un_conv)\n      apply (rule_tac x=q in bexI)\n      apply (rule_tac x=Z in exI)\n      apply (clarsimp simp add: CollInt_iff)\n      apply auto\n      done\n    hence \"\\<Gamma>,Specs_wf p \\<sigma>\n            \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>({\\<sigma>} \\<inter>\n                 {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                  \\<Gamma>\\<turnstile>Call p\\<down>Normal s}) \n                (the (\\<Gamma> p))\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      by (simp only: exec_Call_body' [OF defined] \n                   noFaultStuck_Call_body' [OF defined] \n                  terminates_Normal_Call_body [OF defined])\n  } note bdy=this\n  show ?thesis\n    apply (intro ballI allI)\n    apply (rule hoaret.CallRec [where Specs=\"(\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. \n            {({s. s=Z \\<and> \n              \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n              \\<Gamma>\\<turnstile>Call p\\<down>Normal s},\n             p,\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})})\", \n             OF _ wf_termi_call_steps [of \\<Gamma>] refl])\n    apply fastforce\n    apply clarify\n    apply (rule conjI)\n    apply  fastforce\n    apply (rule allI)\n    apply (simp (no_asm_use) only : Un_empty_left)\n    apply (rule bdy)\n    apply auto\n    done\nqed\n\nend", "meta": {"author": "CompSoftVer", "repo": "CSim2", "sha": "b09a4d77ea089168b1805db5204ac151df2b9eff", "save_path": "github-repos/isabelle/CompSoftVer-CSim2", "path": "github-repos/isabelle/CompSoftVer-CSim2/CSim2-b09a4d77ea089168b1805db5204ac151df2b9eff/ConCSimpl/AlternativeSmallStep.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.2600265351284482}}
{"text": "theory Simple_Network_Language\n  imports Main\n    Networks.State_Networks\n    Uppaal_Networks.UPPAAL_State_Networks_Impl\n    FinFun.FinFun\nbegin\n\nparagraph \\<open>Tagging\\<close>\n\ndefinition TAG (\"_ \\<bar> _\" [8, 8] 9) where\n  \"TAG t x = x\"\n\ndefinition\n  \"TAG' t x = TAG t x\"\n\nlemmas TAG = TAG'_def[symmetric]\n\nlemmas add_tag = TAG_def[symmetric]\n\nlemma rm_TAG:\n  assumes \"TAG t x\" \"TAG t x = TAG' t x\"\n  shows True\n  by auto\n\nmethod tags uses del keep =\n  (unfold keep)?,\n  ((drule rm_TAG, rule del)+)?,\n  (unfold keep[symmetric])?\n\ndatatype 'a tag = ANY 'a | TRANS 'a | SEL 'a | SEND 'a | RECV 'a\n\nlemma\n  assumes \"TAG 1 False\" \"TAG (TRANS STR ''remove'') (x > 0)\"\n  shows False\n  using assms\n  apply -\n  apply (tags del: TAG[of \"TRANS t\" for t] TAG[of 1] keep: TAG[of 1])\n  unfolding TAG_def .\n\n\nsection \\<open>Simple networks of automata with broadcast channels and committed locations\\<close>\n\nno_notation top_assn (\"true\")\n\ndatatype ('a, 'b) bexp =\n  true |\n  not \"('a, 'b) bexp\" |\n  \"and\" \"('a, 'b) bexp\" \"('a, 'b) bexp\" |\n  or \"('a, 'b) bexp\" \"('a, 'b) bexp\" |\n  imply \"('a, 'b) bexp\" \"('a, 'b) bexp\" | \\<comment> \\<open>Boolean connectives\\<close>\n  eq \"('a, 'b) exp\" \"('a, 'b) exp\" |\n  le \"('a, 'b) exp\" \"('a, 'b) exp\" |\n  lt \"('a, 'b) exp\" \"('a, 'b) exp\" |\n  ge \"('a, 'b) exp\" \"('a, 'b) exp\" |\n  gt \"('a, 'b) exp\" \"('a, 'b) exp\"\nand ('a, 'b) exp =\n  const 'b | var 'a | if_then_else \"('a, 'b) bexp\" \"('a, 'b) exp\" \"('a, 'b) exp\" |\n  binop \"'b \\<Rightarrow> 'b \\<Rightarrow> 'b\" \"('a, 'b) exp\" \"('a, 'b) exp\" | unop \"'b \\<Rightarrow> 'b\" \"('a, 'b) exp\"\n\ninductive check_bexp :: \"('a \\<rightharpoonup> 'b) \\<Rightarrow> ('a, 'b :: linorder) bexp \\<Rightarrow> bool \\<Rightarrow> bool\" and is_val\n  where\n  \"check_bexp s true True\" |\n  \"check_bexp s (not e) (\\<not> b)\" if \"check_bexp s e b\" |\n  \"check_bexp s (and e1 e2) (a \\<and> b)\" if \"check_bexp s e1 a\" \"check_bexp s e2 b\" |\n  \"check_bexp s (or e1 e2) (a \\<or> b)\" if \"check_bexp s e1 a\" \"check_bexp s e2 b\" |\n  \"check_bexp s (imply e1 e2) (a \\<longrightarrow> b)\" if \"check_bexp s e1 a\" \"check_bexp s e2 b\" |\n  \"check_bexp s (eq a b) (x = v)\" if \"is_val s a v\" \"is_val s b x\" |\n  \"check_bexp s (le a b) (v \\<le> x)\" if \"is_val s a v\" \"is_val s b x\" |\n  \"check_bexp s (lt a b) (v < x)\" if \"is_val s a v\" \"is_val s b x\" |\n  \"check_bexp s (ge a b) (v \\<ge> x)\" if \"is_val s a v\" \"is_val s b x\" |\n  \"check_bexp s (gt a b) (v > x)\" if \"is_val s a v\" \"is_val s b x\" |\n  \"is_val s (const c) c\" |\n  \"is_val s (var x)   v\" if \"s x = Some v\" |\n  \"is_val s (if_then_else b e1 e2) (if bv then v1 else v2)\"\n  if \"is_val s e1 v1\" \"is_val s e2 v2\" \"check_bexp s b bv\" |\n  \"is_val s (binop f e1 e2) (f v1 v2)\" if \"is_val s e1 v1\" \"is_val s e2 v2\" |\n  \"is_val s (unop f e) (f v)\" if \"is_val s e v\"\n\ntype_synonym\n  ('c, 't, 's) invassn = \"'s \\<Rightarrow> ('c, 't) cconstraint\"\n\ntype_synonym\n  ('a, 'b) upd = \"('a * ('a, 'b) exp) list\"\n\ntype_synonym\n  ('a, 's, 'c, 't, 'x, 'v) transition =\n  \"'s \\<times> ('x, 'v) bexp \\<times> ('c, 't) cconstraint \\<times> 'a \\<times> ('x, 'v) upd \\<times> 'c list \\<times> 's\"\n\ntype_synonym\n  ('a, 's, 'c, 't, 'x, 'v) sta =\n  \"'s set \\<times> 's set \\<times> ('a, 's, 'c, 't, 'x, 'v) transition set \\<times> ('c, 't, 's) invassn\"\n\ntype_synonym\n  ('a, 's, 'c, 't, 'x, 'v) nta = \"'a set \\<times> ('a act, 's, 'c, 't, 'x, 'v) sta list \\<times> ('x \\<rightharpoonup> 'v * 'v)\"\n\ncontext begin\n\nqualified definition conv_t where \"conv_t \\<equiv> \\<lambda> (l,b,g,a,f,r,l'). (l,b,conv_cc g,a,f,r,l')\"\n\nqualified definition conv_A where \"conv_A \\<equiv> \\<lambda> (C, U, T, I). (C, U, conv_t ` T, conv_cc o I)\"\n\ndefinition conv where\n  \"conv \\<equiv> \\<lambda>(broadcast, automata, bounds). (broadcast, map conv_A automata, bounds)\"\n\nend\n\ndatatype 'b label = Del | Internal 'b | Bin 'b | Broad 'b\n\ndefinition bounded where\n  \"bounded bounds s \\<equiv> dom s = dom bounds \\<and>\n    (\\<forall>x \\<in> dom s. fst (the (bounds x)) \\<le> the (s x) \\<and> the (s x) \\<le> snd (the (bounds x)))\"\n\ndefinition is_upd where\n  \"is_upd s upds s' \\<equiv> \\<exists>xs. list_all2 (\\<lambda> (l1, r1) (l2, r2). l1 = l2 \\<and> is_val s r1 r2) upds xs\n    \\<and> s' = fold (\\<lambda> (l, r) s. s(l := Some r)) xs s\"\n\ninductive is_upds where\n  \"is_upds s [] s\" |\n  \"is_upds s (x # xs) s''\" if \"is_upd s x s'\" \"is_upds s' xs s''\"\n\ndefinition committed :: \"('a, 's, 'c, 't, 'x, 'v) sta \\<Rightarrow> 's set\" where\n  \"committed A \\<equiv> fst A\"\n\ndefinition urgent :: \"('a, 's, 'c, 't, 'x, 'v) sta \\<Rightarrow> 's set\" where\n  \"urgent A \\<equiv> fst (snd A)\"\n\ndefinition trans :: \"('a, 's, 'c, 't, 'x, 'v) sta \\<Rightarrow> ('a, 's, 'c, 't, 'x, 'v) transition set\"\n  where\n  \"trans A \\<equiv> fst (snd (snd A))\"\n\ndefinition inv :: \"('a, 's, 'c, 't, 'x, 'v) sta \\<Rightarrow> ('c, 't, 's) invassn\" where\n  \"inv A \\<equiv> snd (snd (snd A))\"\n\nno_notation step_sn (\"_ \\<turnstile> \\<langle>_, _, _\\<rangle> \\<rightarrow>\\<^bsub>_\\<^esub> \\<langle>_, _, _\\<rangle>\" [61,61,61,61,61] 61)\nno_notation steps_sn (\"_ \\<turnstile> \\<langle>_, _, _\\<rangle> \\<rightarrow>* \\<langle>_, _, _\\<rangle>\" [61, 61, 61,61,61] 61)\n\ninductive step_u ::\n  \"('a, 's, 'c, 't :: time, 'x, 'v :: linorder) nta \\<Rightarrow> 's list \\<Rightarrow> ('x \\<rightharpoonup> 'v) \\<Rightarrow> ('c, 't) cval\n  \\<Rightarrow> 'a label \\<Rightarrow> 's list \\<Rightarrow> ('x \\<rightharpoonup> 'v) \\<Rightarrow> ('c, 't) cval \\<Rightarrow> bool\"\n(\"_ \\<turnstile> \\<langle>_, _, _\\<rangle> \\<rightarrow>\\<^bsub>_\\<^esub> \\<langle>_, _, _\\<rangle>\" [61,61,61,61,61] 61)\nwhere\n  step_t:\n    \"\\<lbrakk>\n      ''target invariant'' \\<bar> \\<forall>p < length N. u \\<oplus> d \\<turnstile> inv (N ! p) (L ! p);\n      ''nonnegative''      \\<bar> d \\<ge> 0;\n      ''urgent''           \\<bar> (\\<exists>p < length N. L ! p \\<in> urgent (N ! p)) \\<longrightarrow> d = 0;\n      ''bounded''          \\<bar> bounded B s\n     \\<rbrakk>\n    \\<Longrightarrow> (broadcast, N, B) \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>Del\\<^esub> \\<langle>L, s, u \\<oplus> d\\<rangle>\" |\n  step_int:\n    \"\\<lbrakk>\n      TRANS ''silent'' \\<bar> (l, b, g, Sil a, f, r, l') \\<in> trans (N ! p);\n      ''committed'' \\<bar> l \\<in> committed (N ! p) \\<or> (\\<forall>p < length N. L ! p \\<notin> committed (N ! p));\n      ''bexp''      \\<bar> check_bexp s b True;\n      ''guard''     \\<bar> u \\<turnstile> g;\n      ''target invariant'' \\<bar> \\<forall>p < length N. u' \\<turnstile> inv (N ! p) (L' ! p);\n      ''loc''           \\<bar> L!p = l;\n      ''range''         \\<bar> p < length L;\n      ''new loc''       \\<bar> L' = L[p := l'];\n      ''new valuation'' \\<bar> u' = [r\\<rightarrow>0]u;\n      ''is_upd''        \\<bar> is_upd s f s';\n      ''bounded''       \\<bar> bounded B s'\n    \\<rbrakk>\n    \\<Longrightarrow> (broadcast, N, B) \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>Internal a\\<^esub> \\<langle>L', s', u'\\<rangle>\" |\n  step_bin:\n    \"\\<lbrakk>\n      ''not broadcast'' \\<bar> (a \\<notin> broadcast);\n      TRANS ''in''  \\<bar> (l1, b1, g1, In a,  f1, r1, l1') \\<in> trans (N ! p);\n      TRANS ''out'' \\<bar> (l2, b2, g2, Out a, f2, r2, l2') \\<in> trans (N ! q);\n      ''committed'' \\<bar>\n        l1 \\<in> committed (N ! p) \\<or> l2 \\<in> committed (N ! q) \\<or> (\\<forall>p < length N. L ! p \\<notin> committed (N ! p));\n      ''bexp'' \\<bar> check_bexp s b1 True; ''bexp'' \\<bar> check_bexp s b2 True;\n      ''guard'' \\<bar> u \\<turnstile> g1; ''guard'' \\<bar> u \\<turnstile> g2;\n      ''target invariant'' \\<bar> \\<forall>p < length N. u' \\<turnstile> inv (N ! p) (L' ! p);\n      RECV ''loc'' \\<bar> L!p = l1; SEND ''loc'' \\<bar> L!q = l2;\n      RECV ''range'' \\<bar> p < length L; SEND ''range'' \\<bar> q < length L;\n      ''different'' \\<bar> p \\<noteq> q;\n      ''new loc''       \\<bar> L' = L[p := l1', q := l2'];\n      ''new valuation'' \\<bar> u' = [r1@r2\\<rightarrow>0]u;\n      ''upd'' \\<bar> is_upd s f1 s'; ''upd'' \\<bar> is_upd s' f2 s'';\n      ''bounded'' \\<bar> bounded B s''\n    \\<rbrakk>\n    \\<Longrightarrow> (broadcast, N, B) \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>Bin a\\<^esub> \\<langle>L', s'', u'\\<rangle>\" |\n  step_broad:\n    \"\\<lbrakk>\n      ''broadcast'' \\<bar> a \\<in> broadcast;\n      TRANS ''out'' \\<bar> (l, b, g, Out a, f, r, l') \\<in> trans (N ! p);\n      TRANS ''in''  \\<bar> (\\<forall>p \\<in> set ps. (L ! p, bs p, gs p, In a, fs p, rs p, ls' p) \\<in> trans (N ! p));\n      ''committed'' \\<bar> (l \\<in> committed (N ! p) \\<or> (\\<exists>p \\<in> set ps. L ! p \\<in> committed (N ! p))\n      \\<or> (\\<forall>p < length N. L ! p \\<notin> committed (N ! p)));\n      ''bexp''    \\<bar> check_bexp s b True;\n      ''bexp''    \\<bar> \\<forall>p \\<in> set ps. check_bexp s (bs p) True;\n      ''guard''   \\<bar> u \\<turnstile> g;\n      ''guard''   \\<bar> \\<forall>p \\<in> set ps. u \\<turnstile> gs p;\n      ''maximal'' \\<bar> \\<forall>q < length N. q \\<notin> set ps \\<and> p \\<noteq> q\n        \\<longrightarrow> (\\<forall>b g f r l'. (L!q, b, g, In a, f, r, l') \\<in> trans (N ! q)\n        \\<longrightarrow> \\<not> check_bexp s b True \\<or> \\<not> u \\<turnstile> g);\n      ''target invariant'' \\<bar> \\<forall>p < length N. u' \\<turnstile> inv (N ! p) (L' ! p);\n      SEND ''loc''       \\<bar> L!p = l;\n      SEND ''range''     \\<bar> p < length L;\n      SEL ''range''      \\<bar> set ps \\<subseteq> {0..<length N};\n      SEL ''not sender'' \\<bar> p \\<notin> set ps;\n      SEL ''distinct''   \\<bar> distinct ps;\n      SEL ''sorted''     \\<bar> sorted ps;\n      ''new loc'' \\<bar> L' = (fold (\\<lambda>p L . L[p := ls' p]) ps L)[p := l'];\n      ''new valuation'' \\<bar> u' = [r@concat (map rs ps)\\<rightarrow>0]u;\n      ''upd''     \\<bar> is_upd s f s';\n      ''upds''    \\<bar> is_upds s' (map fs ps) s'';\n      ''bounded'' \\<bar> bounded B s''\n    \\<rbrakk>\n    \\<Longrightarrow> (broadcast, N, B) \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>Broad a\\<^esub> \\<langle>L', s'', u'\\<rangle>\"\nlemmas [intro?] = step_u.intros[unfolded TAG_def]\n\ntext \\<open>Comments:\n\\<^item> Should there be an error transition + state if states run of bounds or updates are undefined?\nThen one could run a reachability check for the error state.\n\\<^item> Should the state be total?\n\\<^item> Note that intermediate states are allowed to run out of bounds\n\\<close>\n\ndefinition steps_u ::\n  \"('a, 's, 'c, 't :: time, 'x, 'v :: linorder) nta \\<Rightarrow> 's list \\<Rightarrow> ('x \\<rightharpoonup> 'v) \\<Rightarrow> ('c, 't) cval\n  \\<Rightarrow> 's list \\<Rightarrow> ('x \\<rightharpoonup> 'v) \\<Rightarrow> ('c, 't) cval \\<Rightarrow> bool\"\n(\"_ \\<turnstile> \\<langle>_, _, _\\<rangle> \\<rightarrow>* \\<langle>_, _, _\\<rangle>\" [61,61,61,61,61] 61)\nwhere\n  \"A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>* \\<langle>L', s', u'\\<rangle> \\<equiv>\n    (\\<lambda> (L, s, u) (L', s', u'). \\<exists>a. A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>a\\<^esub> \\<langle>L', s', u'\\<rangle>)\\<^sup>*\\<^sup>* (L, s, u) (L', s', u')\"\n\nparagraph \\<open>Misc\\<close>\n\nlemma clock_val_concat_iff:\n  \\<open>u \\<turnstile> concat gs \\<longleftrightarrow> (\\<forall>g \\<in> set gs. u \\<turnstile> g)\\<close>\n  by (auto intro: guard_concat concat_guard)\n\nlemma clock_val_append_iff:\n  \\<open>u \\<turnstile> g1 @ g2 \\<longleftrightarrow> u \\<turnstile> g1 \\<and> u \\<turnstile> g2\\<close>\nproof -\n  have \"u \\<turnstile> g1 @ g2 \\<longleftrightarrow> u \\<turnstile> concat [g1, g2]\"\n    by simp\n  also have \"... \\<longleftrightarrow> u \\<turnstile> g1 \\<and> u \\<turnstile> g2\"\n    unfolding clock_val_concat_iff by simp\n  finally show ?thesis .\nqed\n\n\nsubsection \\<open>Product construction\\<close>\n\nlocale Prod_TA_Defs =\n  fixes A :: \"('a, 's, 'c, 't, 'x, 'v :: linorder) nta\"\nbegin\n\ndefinition\n  \"broadcast = fst A\"\n\ndefinition\n  \"N i = fst (snd A) ! i\"\n\ndefinition\n  \"bounds = snd (snd A)\"\n\ndefinition \\<comment>\\<open>Number of processes\\<close>\n  \"n_ps = length (fst (snd A))\"\n\ndefinition states  :: \"'s list set\" where\n  \"states \\<equiv> {L. length L = n_ps \\<and>\n    (\\<forall> i. i < n_ps --> L ! i \\<in> (\\<Union> (l, e, g, a, r, u, l') \\<in> (trans (N i)). {l, l'}))}\"\n\ndefinition\n  \"prod_inv \\<equiv> \\<lambda>(L, s). if L \\<in> states then concat (map (\\<lambda>i. inv (N i) (L ! i)) [0..<n_ps]) else []\"\n\ndefinition\n  \"trans_int =\n    {((L, s), g, Internal a, r, (L', s')) | L s l b g f p a r l' L' s'.\n      (l, b, g, Sil a, f, r, l') \\<in> trans (N p) \\<and>\n      (l \\<in> committed (N p) \\<or> (\\<forall>p < n_ps. L ! p \\<notin> committed (N p))) \\<and>\n      L!p = l \\<and> p < length L \\<and> L' = L[p := l'] \\<and> is_upd s f s' \\<and> check_bexp s b True \\<and>\n      L \\<in> states \\<and> bounded bounds s \\<and> bounded bounds s'\n    }\"\n\ndefinition\n  \"trans_bin =\n    {((L, s), g1 @ g2, Bin a, r1 @ r2, (L', s'')) |\n      L s L' s' s'' a p q l1 b1 g1 f1 r1 l1' l2 b2 g2 f2 r2 l2'.\n      a \\<notin> broadcast \\<and>\n      (l1, b1, g1, In a,  f1, r1, l1') \\<in> trans (N p) \\<and>\n      (l2, b2, g2, Out a, f2, r2, l2') \\<in> trans (N q) \\<and>\n      (l1 \\<in> committed (N p) \\<or> l2 \\<in> committed (N q) \\<or> (\\<forall>p < n_ps. L ! p \\<notin> committed (N p))) \\<and>\n      L!p = l1 \\<and> L!q = l2 \\<and> p < length L \\<and> q < length L \\<and> p \\<noteq> q \\<and>\n      check_bexp s b1 True \\<and> check_bexp s b2 True \\<and>\n      L' = L[p := l1', q := l2'] \\<and> is_upd s f1 s' \\<and> is_upd s' f2 s'' \\<and>\n      L \\<in> states \\<and> bounded bounds s \\<and> bounded bounds s''\n    }\"\n\ndefinition\n  \"trans_broad =\n    {((L, s), g @ concat (map gs ps), Broad a, r @ concat (map rs ps), (L', s'')) |\n    L s L' s' s'' a p l b g f r l' bs gs fs rs ls' ps.\n      a \\<in> broadcast  \\<and>\n      (l, b, g, Out a, f, r, l') \\<in> trans (N p) \\<and>\n      (\\<forall>p \\<in> set ps. (L ! p, bs p, gs p, In a, fs p, rs p, ls' p) \\<in> trans (N p)) \\<and>\n      (l \\<in> committed (N p) \\<or> (\\<exists>p \\<in> set ps. L ! p \\<in> committed (N p))\n      \\<or> (\\<forall>p < n_ps. L ! p \\<notin> committed (N p))) \\<and>\n      (\\<forall>q < n_ps. q \\<notin> set ps \\<and> p \\<noteq> q \\<longrightarrow>\n        \\<not> (\\<exists>b g f r l'. (L!q, b, g, In a, f, r, l') \\<in> trans (N q) \\<and> check_bexp s b True)) \\<and>\n      L!p = l \\<and>\n      p < length L \\<and> set ps \\<subseteq> {0..<n_ps} \\<and> p \\<notin> set ps \\<and> distinct ps \\<and> sorted ps \\<and>\n      check_bexp s b True \\<and> (\\<forall>p \\<in> set ps. check_bexp s (bs p) True) \\<and>\n      L' = (fold (\\<lambda>p L . L[p := ls' p]) ps L)[p := l'] \\<and>\n      is_upd s f s' \\<and> is_upds s' (map fs ps) s'' \\<and>\n      L \\<in> states \\<and> bounded bounds s \\<and> bounded bounds s''\n    }\"\n\ndefinition\n  \"trans_prod = trans_int \\<union> trans_bin \\<union> trans_broad\"\n\ndefinition\n  \"prod_ta = (trans_prod, prod_inv :: ('s list \\<times> ('x \\<Rightarrow> 'v option) \\<Rightarrow> _))\"\n\nlemma inv_of_prod[simp]:\n  \"inv_of prod_ta = prod_inv\"\n  unfolding prod_ta_def inv_of_def by simp\n\nlemma trans_of_prod[simp]:\n  \"trans_of prod_ta = trans_prod\"\n  unfolding prod_ta_def trans_of_def by simp\n\nlemma A_split:\n  \\<open>A = (broadcast, map N [0..<n_ps], bounds)\\<close>\n  unfolding broadcast_def N_def bounds_def n_ps_def by (cases A) (simp add: List.map_nth)\n\nlemma map_N_n_ps_simp:\n  \"map N [0..<n_ps] ! p = N p\"\n  unfolding N_def n_ps_def List.map_nth ..\n\nlemma N_split_simp[simp]:\n  assumes \"A = (broadcast', N', B)\"\n  shows \"N' ! i = N i\"\n  unfolding N_def unfolding assms by simp\n\nlemma state_preservation_updI:\n  assumes \"l' \\<in> (\\<Union> (l, b, g, a, r, u, l') \\<in> trans (N p). {l, l'})\" \"L \\<in> states\"\n  shows \"L[p := l'] \\<in> states\"\n  using assms unfolding states_def by (fastforce simp: nth_list_update')\n\nlemma state_preservation_fold_updI:\n  assumes \"\\<forall>p \\<in> set ps. ls' p \\<in> (\\<Union> (l, b, g, a, r, u, l') \\<in> trans (N p). {l, l'})\" \"L \\<in> states\"\n  shows \"fold (\\<lambda>p L. L[p := ls' p]) ps L \\<in> states\"\n  using assms by (induction ps arbitrary: L) (auto intro: state_preservation_updI)\n\nlemma state_set_states:\n  \"Simulation_Graphs_TA.state_set prod_ta \\<subseteq> {(l, s). l \\<in> states}\"\n  unfolding prod_ta_def state_set_def\n  unfolding trans_of_def trans_prod_def\n  unfolding trans_int_def trans_bin_def trans_broad_def\n  by auto (auto intro: state_preservation_updI state_preservation_fold_updI)\n\nlemma trans_prod_bounded_inv:\n  \\<open>bounded bounds s'\\<close> if \\<open>((L, s), g, a, r, (L', s')) \\<in> trans_prod\\<close>\n  using that unfolding bounds_def trans_prod_def trans_int_def trans_bin_def trans_broad_def\n  by (auto simp: bounds_def)\n\nlemma trans_prod_states_inv:\n  \\<open>L' \\<in> states\\<close> if \\<open>((L, s), g, a, r, (L', s')) \\<in> trans_prod\\<close> \\<open>L \\<in> states\\<close>\n  using that\n  unfolding bounds_def trans_prod_def trans_int_def trans_bin_def trans_broad_def\n  apply clarsimp\n  apply safe\n         apply (force intro!: state_preservation_updI)\n        apply (force intro!: state_preservation_updI)\n       apply (force intro!: state_preservation_updI)\n      apply (force intro!: state_preservation_updI)\n     apply (force intro!: state_preservation_updI)\n    apply (fastforce intro!: state_preservation_updI state_preservation_fold_updI)\n  subgoal\n    apply (rule state_preservation_updI)\n    apply force\n    apply (force intro!: state_preservation_fold_updI)\n    done\n  apply (fastforce intro!: state_preservation_updI state_preservation_fold_updI)\n  done\n\nend (* Prod TA Defs *)\n\n\nlocale Prod_TA_sem =\n  Prod_TA_Defs A for A :: \"('a, 's, 'c, 't :: time, 'x, 'v :: linorder) nta\"\nbegin\n\nlemma prod_invI[intro]:\n  \\<open>u \\<turnstile> prod_inv (L, s)\\<close> if \\<open>\\<forall>p<n_ps. u \\<turnstile> Simple_Network_Language.inv (N p) (L ! p)\\<close>\n  using that unfolding prod_inv_def by (auto intro!: guard_concat)\n\nlemma prod_invD[dest]:\n  \\<open>\\<forall>p<n_ps. u \\<turnstile> Simple_Network_Language.inv (N p) (L ! p)\\<close> if \\<open>u \\<turnstile> prod_inv (L, s)\\<close> \\<open>L \\<in> states\\<close>\n  using that unfolding prod_inv_def by (auto elim: concat_guard)\n\nlemma delay_sound:\n  assumes \"prod_ta \\<turnstile> \\<langle>(L, s), u\\<rangle> \\<rightarrow>\\<^bsup>d\\<^esup> \\<langle>(L', s'), u'\\<rangle>\" \"L \\<in> states\" \"bounded bounds s\"\n          \"\\<forall>N \\<in> set (fst (snd A)). urgent N = {}\"\n        shows \"A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>Del\\<^esub> \\<langle>L', s', u'\\<rangle>\"\nproof -\n  from assms(4) have \"l \\<notin> urgent (N p)\" if \"p < n_ps\" for p l\n    using that unfolding N_def n_ps_def by auto\n  then show ?thesis\n    by (subst A_split) (use assms in \\<open>cases, auto intro!: step_t simp: TAG_def\\<close>)\nqed\n\nlemma action_sound:\n  \"A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>a\\<^esub> \\<langle>L', s', u'\\<rangle>\" if \"prod_ta \\<turnstile> \\<langle>(L, s), u\\<rangle> \\<rightarrow>\\<^bsub>a\\<^esub> \\<langle>(L', s'), u'\\<rangle>\"\n  using that\nproof cases\n  case prems: (1 g r)\n  note [simp add] = map_N_n_ps_simp clock_val_append_iff clock_val_concat_iff\n  from \\<open>prod_ta \\<turnstile> (L, s) \\<longrightarrow>\\<^bsup>g,a,r\\<^esup> (L', s')\\<close>[THEN state_setI2] have \"L' \\<in> states\"\n    using state_set_states that by fast\n  from \\<open>prod_ta \\<turnstile> (L, s) \\<longrightarrow>\\<^bsup>g,a,r\\<^esup> (L', s')\\<close> show ?thesis\n    unfolding trans_of_prod trans_prod_def\n  proof safe\n    assume \"((L, s), g, a, r, L', s') \\<in> trans_int\"\n    then show \"A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>a\\<^esub> \\<langle>L', s', u'\\<rangle>\"\n      unfolding trans_int_def\n      apply clarsimp\n      using prems \\<open>L' \\<in> _\\<close>\n      by (subst A_split) (intro step_int; simp add: TAG_def; elim prod_invD; assumption)\n  next\n    assume \"((L, s), g, a, r, L', s') \\<in> trans_bin\"\n    then show \"A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>a\\<^esub> \\<langle>L', s', u'\\<rangle>\"\n      unfolding trans_bin_def\n      using prems \\<open>L' \\<in> _\\<close>\n      apply clarsimp\n      apply (subst A_split, standard)\n                     apply (assumption | simp; elim prod_invD; assumption)+\n      done\n  next\n    assume \"((L, s), g, a, r, L', s') \\<in> trans_broad\"\n    then show \"A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>a\\<^esub> \\<langle>L', s', u'\\<rangle>\"\n      using prems \\<open>L' \\<in> _\\<close>\n      unfolding trans_broad_def inv_of_prod\n      apply clarsimp\n      apply (subst A_split)\n      apply standard\n                          apply (assumption | simp; elim prod_invD; assumption | fastforce)+\n      done\n  qed\nqed\n\nlemma bounded_inv:\n  \\<open>bounded bounds s'\\<close> if \\<open>A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>a\\<^esub> \\<langle>L', s', u'\\<rangle>\\<close>\n  using that unfolding bounds_def by cases (simp add: TAG_def)+\n\nlemma states_inv:\n  \\<open>L' \\<in> states\\<close> if \\<open>A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>a\\<^esub> \\<langle>L', s', u'\\<rangle>\\<close> \\<open>L \\<in> states\\<close>\n  using that unfolding bounds_def\nproof cases\n  case (step_t N d B broadcast)\n  with \\<open>L \\<in> states\\<close> show ?thesis\n    by simp\nnext\n  case prems[unfolded TAG_def]: (step_int l b g a f r l' N' p B broadcast)\n  from \\<open>A = _\\<close> prems(3) have \"l' \\<in> (\\<Union> (l, b, g, a, r, u, l') \\<in> trans (N p). {l, l'})\"\n    by force\n  with \\<open>L \\<in> states\\<close> show ?thesis\n    unfolding \\<open>L' = _\\<close> by (intro state_preservation_updI)\nnext\n  case prems[unfolded TAG_def]:\n    (step_bin broadcast a l1 b1 g1 f1 r1 l1' N' p l2 b2 g2 f2 r2 l2' q s' B)\n  from \\<open>A = _\\<close> prems(4, 5) have\n    \"l1' \\<in> (\\<Union> (l, b, g, a, r, u, l') \\<in> trans (N p). {l, l'})\"\n    \"l2' \\<in> (\\<Union> (l, b, g, a, r, u, l') \\<in> trans (N q). {l, l'})\"\n    by force+\n  with \\<open>L \\<in> states\\<close> show ?thesis\n    unfolding \\<open>L' = _\\<close> by (intro state_preservation_updI)\nnext\n  case prems[unfolded TAG_def]: (step_broad a broadcast l b g f r l' N' p ps bs gs fs rs ls' s' B)\n  from \\<open>A = _\\<close> prems(4, 5) have\n    \"l' \\<in> (\\<Union> (l, b, g, a, r, u, l') \\<in> trans (N p). {l, l'})\"\n    \"\\<forall> q \\<in> set ps. ls' q \\<in> (\\<Union> (l, b, g, a, r, u, l') \\<in> trans (N q). {l, l'})\"\n    by force+\n  with \\<open>L \\<in> states\\<close> show ?thesis\n    unfolding \\<open>L' = _\\<close> by (intro state_preservation_updI state_preservation_fold_updI)\nqed\n\nend (* Prod TA Defs on a time domain *)\n\n\nlocale Prod_TA =\n  Prod_TA_sem A for A :: \"('a, 's, 'c, 't :: time, 'x, 'v :: linorder) nta\" +\n  assumes broadcast_receivers_unguarded:\n    \"\\<forall>p < n_ps. \\<forall>l b g a f r l'. (l, b, g, In a, f, r, l') \\<in> trans (N p) \\<and> a \\<in> broadcast \\<longrightarrow> g = []\"\nbegin\n\nlemma action_complete:\n  \"prod_ta \\<turnstile> \\<langle>(L, s), u\\<rangle> \\<rightarrow>\\<^bsub>a\\<^esub> \\<langle>(L', s'), u'\\<rangle>\"\n  if \"A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>a\\<^esub> \\<langle>L', s', u'\\<rangle>\" \"a \\<noteq> Del\" \"L \\<in> states\" \"bounded bounds s\"\nusing that(1) proof cases\n  case (step_t N d B broadcast)\n  then show ?thesis\n    using that(2) by auto\nnext\n  case prems[unfolded TAG_def]: (step_int l b g a' f r l' N' p B broadcast')\n  have [simp]:\n    \"B = bounds\" \"broadcast' = broadcast\" \"length N' = n_ps\"\n    unfolding bounds_def broadcast_def n_ps_def unfolding prems(1) by simp+\n  have [simp]:\n    \"N' ! i = N i\" for i\n    unfolding N_def unfolding prems(1) by simp\n  have \"prod_ta \\<turnstile> (L, s) \\<longrightarrow>\\<^bsup>g,Internal a',r\\<^esup> (L', s')\"\n  proof -\n    from prems \\<open>L \\<in> states\\<close> \\<open>bounded _ s\\<close> have \"((L, s),g,Internal a',r,(L', s')) \\<in> trans_int\"\n      unfolding trans_int_def\n      by simp (rule exI conjI HOL.refl | assumption | (simp; fail))+\n    then show ?thesis\n      unfolding prod_ta_def trans_of_def trans_prod_def by simp\n  qed\n  moreover have \"u \\<turnstile> g\"\n    by (rule prems)\n  moreover have \"u' \\<turnstile> inv_of prod_ta (L', s')\"\n    using prems(7) by auto\n  moreover have \"u' = [r\\<rightarrow>0]u\"\n    by (rule prems)\n  ultimately show ?thesis\n    unfolding \\<open>a = _\\<close> ..\nnext\n  case prems[unfolded TAG_def]:\n    (step_bin a' broadcast' l1 b1 g1 f1 r1 l1' N' p l2 b2 g2 f2 r2 l2' q s'' B)\n  have [simp]:\n    \"B = bounds\" \"broadcast' = broadcast\" \"length N' = n_ps\"\n    unfolding bounds_def broadcast_def n_ps_def unfolding prems(1) by simp+\n  have [simp]:\n    \"N' ! i = N i\" for i\n    unfolding N_def unfolding prems(1) by simp\n  have \"prod_ta \\<turnstile> (L, s) \\<longrightarrow>\\<^bsup>g1 @ g2,Bin a',r1 @ r2\\<^esup> (L', s')\"\n  proof -\n    from prems \\<open>L \\<in> states\\<close> \\<open>bounded bounds s\\<close> have\n      \"((L, s),g1 @ g2,Bin a',r1 @ r2,(L', s')) \\<in> trans_bin\"\n      unfolding trans_bin_def\n      using [[simproc add: ex_reorder4]]\n      by simp (rule exI conjI HOL.refl | assumption | fast)+\n    then show ?thesis\n      unfolding prod_ta_def trans_of_def trans_prod_def by simp\n  qed\n  moreover have \"u \\<turnstile> g1 @ g2\"\n    using \\<open>u \\<turnstile> g1\\<close> \\<open>u \\<turnstile> g2\\<close> by (rule guard_append)\n  moreover have \"u' \\<turnstile> inv_of prod_ta (L', s')\"\n    using prems by auto\n  moreover have \"u' = [r1@r2\\<rightarrow>0]u\"\n    by (rule prems)\n  ultimately show ?thesis\n    unfolding \\<open>a = _\\<close> ..\nnext\n  case prems[unfolded TAG_def]: (step_broad a' broadcast' l b g f r l' N' p ps bs gs fs rs ls' s'' B)\n  have [simp]:\n    \"B = bounds\" \"broadcast' = broadcast\" \"length N' = n_ps\"\n    unfolding bounds_def broadcast_def n_ps_def unfolding prems(1) by simp+\n  have [simp]:\n    \"N' ! i = N i\" for i\n    unfolding N_def unfolding prems(1) by simp\n  let ?r = \"r @ concat (map rs ps)\" and ?g = \"g @ concat (map gs ps)\"\n  have \"prod_ta \\<turnstile> (L, s) \\<longrightarrow>\\<^bsup>?g,Broad a',?r\\<^esup> (L', s')\"\n  proof -\n    have *: \"\\<not> u \\<turnstile> g \\<longleftrightarrow> False\" if\n      \"p < n_ps\" \"(l, b, g, In a', f, r, l') \\<in> Simple_Network_Language.trans (N p)\"\n      \"a' \\<in> broadcast\"\n      for l b g a' f r l' p\n    proof -\n      from that broadcast_receivers_unguarded have \\<open>g = []\\<close>\n        by blast\n      then show ?thesis\n        by auto\n    qed\n    from prems \\<open>L \\<in> states\\<close> \\<open>bounded bounds s\\<close> have \"((L, s),?g,Broad a',?r,(L', s')) \\<in> trans_broad\"\n      unfolding trans_broad_def\n      by clarsimp\n         (intro exI conjI HOL.refl; (rule HOL.refl | assumption | fastforce simp: *))\n   then show ?thesis\n      unfolding prod_ta_def trans_of_def trans_prod_def by simp\n  qed\n  moreover have \"u \\<turnstile> ?g\"\n    using prems by (auto intro!: guard_append guard_concat)\n  moreover have \"u' \\<turnstile> inv_of prod_ta (L', s')\"\n    using prems by auto\n  moreover have \"u' = [?r\\<rightarrow>0]u\"\n    by (rule prems)\n  ultimately show ?thesis\n    unfolding \\<open>a = _\\<close> ..\nqed\n\nlemma delay_complete:\n  assumes \"A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>Del\\<^esub> \\<langle>L', s', u'\\<rangle>\"\n  obtains d where \"prod_ta \\<turnstile> \\<langle>(L, s), u\\<rangle> \\<rightarrow>\\<^bsup>d\\<^esup> \\<langle>(L', s'), u'\\<rangle>\"\n  using assms\nproof cases\n  case prems: (step_t N' d B broadcast)\n  have [simp]:\n    \"length N' = n_ps\"\n    unfolding n_ps_def unfolding prems(1) by simp+\n  have [simp]:\n    \"N' ! i = N i\" for i\n    unfolding N_def unfolding prems(1) by simp\n  from prems show ?thesis\n  by (intro that[of d]; unfold \\<open>u' = _\\<close> \\<open>L' = L\\<close> \\<open>s' = s\\<close> TAG_def)\n     (rule step_t.intros; (unfold inv_of_prod; rule prod_invI)?; simp)\nqed\n\nlemma step_iff:\n  \"(\\<exists> a. A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>a\\<^esub> \\<langle>L', s', u'\\<rangle>) \\<longleftrightarrow> prod_ta \\<turnstile> \\<langle>(L, s), u\\<rangle> \\<rightarrow> \\<langle>(L', s'), u'\\<rangle>\"\n  if \"bounded bounds s\" \"L \\<in> states\" \"\\<forall>N \\<in> set (fst (snd A)). urgent N = {}\"\n  using that(1,2)\n  apply (auto intro: action_sound delay_sound[OF _ _ _ that(3)])\n  subgoal for a\n    by (cases a; blast dest: action_complete elim: delay_complete)\n  done\n\nend (* Prod TA *)\n\nend (* Theory *)", "meta": {"author": "wimmers", "repo": "munta", "sha": "62cb1a4a4dbcfcf62c365e90faba15b0012d5a12", "save_path": "github-repos/isabelle/wimmers-munta", "path": "github-repos/isabelle/wimmers-munta/munta-62cb1a4a4dbcfcf62c365e90faba15b0012d5a12/Simple_Networks/Simple_Network_Language.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.2600265351284482}}
{"text": "(*\n * Copyright 2016, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the GNU General Public License version 2. Note that NO WARRANTY is provided.\n * See \"LICENSE_GPLv2.txt\" for details.\n *\n * @TAG(NICTA_GPL)\n *)\n\ntheory PleSle\nimports\n  \"BilbyFsConsts.BilbyFs_Shallow_Desugar_Tuples\"\n  \"../adt/WordArrayT\"\n  \"../adt/ArrayT\"\n  \"../adt/BufferT\"\n  \"HOL-Eisbach.Eisbach\"\nbegin\n\ntext{* axioms and lemmas that are *not* specific to 32 word. -> should be refactored.*}\naxiomatization\nwhere\n u32_to_u8_is_ucast:\n  \"u32_to_u8 = ucast\"\nand\n u64_to_u8_is_ucast:\n  \"u64_to_u8 = ucast\"\nand\n u64_to_u32_is_ucast:\n  \"u64_to_u32 = ucast\"\nand\n u16_to_u8_is_ucast:\n  \"u16_to_u8 = ucast\"\n  \nlemmas less_to_le = order_class.order.strict_implies_order\n\nlemma test_bit_out_of_bounds:\n  \"\\<lbrakk>n \\<ge> 8\\<rbrakk> \\<Longrightarrow> ((w :: 8 word) !! n) = False\"\n  by (auto dest!: test_bit_size simp:word_size)\n  \nlemma mod_range_eq:\n  \"\\<lbrakk>n \\<ge> (a::nat)*8; (n::nat) < (a+1)*8\\<rbrakk> \\<Longrightarrow> n mod 8 = n - (a*8)\"\n  by (simp add: div_nat_eqI modulo_nat_def mult.commute)\n  \nlemma range_le:\n  \"\\<lbrakk>(n :: nat) \\<ge> (a::nat)*8; n < (a+1)*8\\<rbrakk> \\<Longrightarrow>\n      n - (a*8) < 8\"\n  by simp\n  \nlemma div_range_le:\n  \"\\<lbrakk>n < (a*8)\\<rbrakk> \\<Longrightarrow> (n :: nat) div 8 < a\"\n  by auto\n\nlemma take_decomp:\n  \"length l \\<ge> n \\<Longrightarrow> n > 0 \\<Longrightarrow> (take n l) = ((hd l) # (take (n - 1) (tl l)))\"\n  by (induct l) (simp add: take_Cons split: nat.split)+\n  \nlemma take_drop_decomp:\n  \"k < length l \\<Longrightarrow> length (drop k l) \\<ge> n \\<Longrightarrow> n > 0 \n    \\<Longrightarrow> take n (drop k l) = (l ! k) # take (n - 1) (drop (k + 1) l)\"\n  by (simp add: take_decomp hd_drop_conv_nth drop_Suc[symmetric] drop_tl[symmetric])\n\nlemma elem_take_n:\n \"i<n \\<Longrightarrow> (take n xs ! i) = xs ! i\"\n by simp\n  \nlemma take_n_eq_simp:\n \"take len ys = take len xs \\<Longrightarrow>\n  idx < len \\<Longrightarrow>\n    ys !idx = xs !idx\"\nby (metis elem_take_n)\n\n lemma take_n_and_len'_eq_simp:\n \"take len ys = take len xs \\<Longrightarrow>\n  idx < len' \\<Longrightarrow>\n  len' \\<le> len \\<Longrightarrow>\n    ys !idx = xs !idx\"\nby (erule take_n_eq_simp) simp\n\nlemma drop_n_then_nth_eq:\n assumes \"n + i \\<le> length xs\"\n assumes \"n + i \\<le> length ys\"\n assumes \"ys ! (n + i) = xs ! (n + i)\"\n shows \"drop n ys ! (0 + i) = drop n xs ! (0 + i)\"\n using assms by auto\n \n lemma drop_n_then_nth_eq_wo_0:\n assumes \"n + i \\<le> length xs\"\n assumes \"n + i \\<le> length ys\"\n assumes \"ys ! (n + i) = xs ! (n + i)\"\n shows \"drop n ys ! i = drop n xs ! i\"\n using assms by auto\n\nlemma plus_no_overflow_unat_lift: \n  \"(a::'a::len word )  < a + b \\<Longrightarrow>  unat (a+b) = unat a + unat b\"\n  by unat_arith\n\n\nmethod handle_wa_mod for offs :: \"U32\" =\n(rule wordarray_modify_ret[where index=offs, simplified Let_def],\n  simp_all add: wordarray_make ArrA.defs ElemAO.defs  ElemA.defs\n   setu8_def[unfolded tuple_simps sanitizers], unat_arith)\n\nlemma take_list_update:\n  \"i < length xs\n    \\<Longrightarrow> take n (xs[i := x]) = (if i < n then (take n xs)[i := x] else take n xs)\"\n  by (induct xs arbitrary: n i, simp_all add: take_Cons split: nat.split)\n\nlemma drop_list_update:\n  \"i < length xs\n    \\<Longrightarrow> drop n (xs[i := x]) = (if i < n then drop n xs else (drop n xs)[i - n := x])\"\n  by (induct xs arbitrary: n i, simp_all add: drop_Cons split: nat.split)\n\ndefinition ple16 :: \"8 word list \\<Rightarrow> 32 word \\<Rightarrow> 16 word\"\nwhere\n  \"ple16 data offs \\<equiv> word_rcat (rev (take 2 (drop (unat offs) data)))\"\n  \ndefinition sle16 :: \"U16 \\<Rightarrow> U8 list\"\nwhere\n  \"sle16 \\<equiv> rev \\<circ> word_rsplit\"\n  \nlemma deserialise_le16_ret:\nassumes valid_offs:\n  \"unat offs + 1 < length (\\<alpha>wa $ data\\<^sub>f buf)\"\nassumes no_ovf:\n  \"offs < offs + 2\"\nshows\n  \"deserialise_le16 (buf, offs) = (ple16 (\\<alpha>wa $ data\\<^sub>f buf) offs)\"\nusing valid_offs\n  apply (subgoal_tac \"(\\<forall>i\\<in>{0..1}. unat (offs+i) < length (\\<alpha>wa (data\\<^sub>f buf)))\")\n   prefer 2\n   apply unat_arith\n  apply (clarsimp simp: wordarray_get_ret[where arr=\"data\\<^sub>f buf\"] ple16_def \n                        deserialise_le16_def)\n  apply (subgoal_tac \"(unat (offs + 1) > 0)\")\n   prefer 2\n   apply (drule_tac x=1 in bspec, simp)\n   using no_ovf apply unat_arith\n   apply auto[1]\n  apply (subst take_drop_decomp, (simp+))+\n  apply (subst unatSuc[symmetric], (simp add: unat_gt_0[symmetric] add.commute[where b=offs]))+\n  apply (rule trans, rule word_rcat_rsplit[symmetric])\n  apply (rule arg_cong[where f=word_rcat])\n  apply (subst word_rsplit_upt[where n=2], simp add: word_size)\n   apply simp\n  apply (simp add: upt_rec shiftr_over_or_dist shiftl_shiftr1 shiftl_shiftr2 word_size)\n  apply (safe intro!: word_eqI, simp_all add: word_size word_ops_nth_size nth_ucast\n        nth_shiftr nth_shiftl add.commute[where b=offs] test_bit_out_of_bounds)\n  done\n\nlemma serial_le16_helper:\n \"unat offs + 2 < length (\\<alpha>wa (data\\<^sub>f buf)) \\<Longrightarrow>\n   [u16_to_u8 v, u16_to_u8 (v >> 8)]\n = sle16 v\"\n  apply (clarsimp simp: u16_to_u8_is_ucast sle16_def)\n  apply (subst word_rsplit_upt[where n=2])\n    apply ((simp add: word_size upt_rec)+)[2]\n   apply (simp add: upt_rec)\n  done\n  \nlemma serialise_le16_ret:\n  assumes no_overflow: \"offs < offs + 2\"\n  and valid_offs:\n   \"unat offs + 2 < length (\\<alpha>wa (data\\<^sub>f buf))\"\nshows\n  \"(serialise_le16 (buf, offs, v)) =\n   buf \\<lparr>data\\<^sub>f:=WordArrayT.make (buf_sub_slice buf offs (offs+2) (sle16 v))\\<rparr>\"\nproof -\n  have unat_plus:\n    \"\\<And>n. n \\<le> 2 \\<longrightarrow> unat (offs + n) = unat offs + unat n\"\n    using no_overflow valid_offs\n    by clarsimp unat_arith\n  show ?thesis\n  using valid_offs\n  apply (simp add: serialise_le16_def[unfolded sanitizers] serialise_u8_def[unfolded sanitizers] Let_def)\n  apply (handle_wa_mod \"offs\")\n  apply (handle_wa_mod \"offs+1\")\n    apply (simp add: serial_le16_helper[OF valid_offs, where v=v,symmetric])\n  apply (rule arg_cong[where f=\"\\<lambda>v. Buffer.data\\<^sub>f_update v buf\"])\n  apply (rule ext)\n  apply (rule arg_cong[where f=\"WordArrayT.make\"])\n  \n  apply (simp add: buf_sub_slice_def)\n  apply (rule trans, rule_tac n=\"unat offs\" in append_take_drop_id[symmetric],\n    rule arg_cong2[where f=append])\n   apply (simp add: unat_plus order_le_less_trans[OF _ valid_offs] take_list_update)\n  apply (simp add: unat_plus)\n    apply (cut_tac valid_offs, simp)\n   apply (simp add: max_absorb1)\n   apply clarsimp\n   apply (simp add: list_eq_iff_nth_eq)\n   apply (rule conjI)\n    using valid_offs\n    apply (simp add: nth_Cons split: nat.split)\n  using valid_offs\n  apply (clarsimp simp only:)\n  apply (subst nth_list_update, unat_arith) +\n  apply clarsimp\n  apply (rule arg_cong[where f=\"nth (\\<alpha>wa (data\\<^sub>f buf))\"])\n   apply simp\n done\nqed\n\n\nlemma ple16_take:\n assumes offs:\"offs < offs+2\"\n assumes ntake:\"unat (offs + 2) \\<le> ntake\"\n shows   \"ple16 (take ntake ys) offs = ple16 ys offs\"\n apply (simp add: ple16_def)\n apply (rule arg_cong[where f=\"word_rcat\"])\n apply (rule arg_cong[where f=\"rev\"])\n  apply (subst list_eq_iff_nth_eq)\n  using offs ntake less_to_le[OF offs, simplified unat_plus_simple]\n  apply fastforce\n done\n \nlemma ple16_append:\n  assumes no_overflow: \"offs < offs + 2\" \n  assumes len_ys: \"unat (offs + 2) \\<le> length ys\"\n  shows   \"ple16 (ys@zs) offs = ple16 ys offs\"\n  using plus_no_overflow_unat_lift[OF no_overflow]  len_ys\n  by (simp add: ple16_def)\n  \nlemma ple16_append_Cons:\n  assumes no_overflow: \"offs < offs + 2\"\n  assumes len_ys: \"unat (offs + 2) \\<le> length (v#ys)\"\n  shows   \"ple16 (v#ys@zs) offs = ple16 (v#ys) offs\"\nproof -\n  have unat_nth_simp_Cons: \"\\<And> n xs ys . \n    unat n < Suc (length xs) \\<Longrightarrow> (v#xs@ys)!(unat n) = (v#xs)!(unat n)\"\n  by (case_tac \"0 < unat n\") (fastforce simp: nth_append) +\n  show ?thesis\n  apply(subgoal_tac \"unat offs < Suc (length ys)\")\n   apply(rule ple16_append[where ys = \"v#ys\" and zs = \"zs\" and offs=\"offs\", \n       simplified List.append.append_Cons])\n    using no_overflow apply clarsimp\n   using len_ys apply clarsimp\n  using assms by unat_arith\nqed\n\ndefinition ple64 :: \"8 word list \\<Rightarrow> 32 word \\<Rightarrow> 64 word\"\nwhere\n  \"ple64 data offs \\<equiv> word_rcat (rev (take 8 (drop (unat offs) data)))\"\n\ndefinition ple32 :: \"8 word list \\<Rightarrow> 32 word \\<Rightarrow> 32 word\"\nwhere\n  \"ple32 data offs \\<equiv> word_rcat (rev (take 4 (drop (unat offs) data)))\"\n\ndefinition sle32 :: \"U32 \\<Rightarrow> U8 list\"\nwhere\n  \"sle32 \\<equiv> rev \\<circ> word_rsplit\"\n\nlemma deserialise_le32_ret:\nassumes valid_offs:\n  \"unat offs + 3 < length (\\<alpha>wa $ data\\<^sub>f buf)\"\nassumes no_ovf:\n  \"offs < offs + 3\"\nshows\n  \"deserialise_le32 (buf, offs) = (ple32 (\\<alpha>wa $ data\\<^sub>f buf) offs)\"\nusing valid_offs\n  apply (subgoal_tac \"(\\<forall>i\\<in>{0..3}. unat (offs+i) < length (\\<alpha>wa (data\\<^sub>f buf)))\")\n   prefer 2\n   apply unat_arith\n  apply (clarsimp simp: wordarray_get_ret[where arr=\"data\\<^sub>f buf\"] ple32_def \n                        deserialise_le32_def)\n  apply (subgoal_tac \"\\<forall>j\\<in>{1..3}. (unat (offs + j) > 0)\")\n   prefer 2\n   apply clarsimp\n   apply (drule_tac x=j in bspec, simp)\n   using no_ovf apply unat_arith\n   apply auto[1]\n  apply (subst take_drop_decomp, (simp+))+\n  apply (subst unatSuc[symmetric], (simp add: unat_gt_0[symmetric] add.commute[where b=offs]))+\n  apply simp\n  apply (rule trans, rule word_rcat_rsplit[symmetric])\n  apply (rule arg_cong[where f=word_rcat])\n  apply (subst word_rsplit_upt[where n=4], simp add: word_size)\n   apply simp\n  apply (simp add: upt_rec shiftr_over_or_dist shiftl_shiftr1 shiftl_shiftr2 word_size)\n  apply (safe intro!: word_eqI, simp_all add: word_size word_ops_nth_size nth_ucast\n        nth_shiftr nth_shiftl add.commute[where b=offs] test_bit_out_of_bounds)\n  done\n\n\nlemma serial_le32_helper:\n \"unat offs + 4 < length (\\<alpha>wa (data\\<^sub>f buf)) \\<Longrightarrow>\n   [u32_to_u8 v, u32_to_u8 (v >> 8), u32_to_u8 (v >> 16), u32_to_u8 (v >> 24)]\n = sle32 v\"\n  apply (clarsimp simp: u32_to_u8_is_ucast sle32_def)\n  apply (subst word_rsplit_upt[where n=4])\n    apply ((simp add: word_size upt_rec)+)[2]\n   apply (simp add: upt_rec)\n  done\n  \nlemma serialise_le32_ret:\n  assumes no_overflow: \"offs < offs + 4\"\n  and valid_offs:\n   \"unat offs + 4 < length (\\<alpha>wa (data\\<^sub>f buf))\"\n  notes  wa_modify_ret = wordarray_modify_ret[rotated - 1, simplified Let_def]\nshows\n  \"(serialise_le32 (buf, offs, v)) =\n  buf\\<lparr>data\\<^sub>f:=WordArrayT.make (buf_sub_slice buf offs (offs+4) (sle32 v))\\<rparr>\"\nproof -\n  have unat_plus:\n    \"\\<And>n. n \\<le> 4 \\<longrightarrow> unat (offs + n) = unat offs + unat n\"\n    using no_overflow valid_offs\n    by unat_arith auto\n  show ?thesis\n  using valid_offs\n  apply (simp add: serialise_le32_def[unfolded sanitizers] serialise_u8_def[unfolded sanitizers] Let_def)\n  apply (handle_wa_mod \"offs\")\n  apply (handle_wa_mod \"offs+1\")\n  apply (handle_wa_mod \"offs+2\")\n  apply (handle_wa_mod \"offs+3\")\n  apply (simp add: serial_le32_helper[OF valid_offs, where v=v,symmetric])\n  apply (rule arg_cong[where f=\"\\<lambda>v. Buffer.data\\<^sub>f_update v buf\"])\n  apply (rule ext)\n  apply (rule arg_cong[where f=\"WordArrayT.make\"])\n  \n  apply (simp add: buf_sub_slice_def)\n  apply (rule trans, rule_tac n=\"unat offs\" in append_take_drop_id[symmetric],\n    rule arg_cong2[where f=append])\n   apply (simp add: unat_plus order_le_less_trans[OF _ valid_offs] take_list_update)\n  apply (simp add: unat_plus)\n    apply (cut_tac valid_offs, simp)\n   apply (simp add: max_absorb1)\n   apply (simp add: list_eq_iff_nth_eq)\n   apply (rule conjI)\n    using valid_offs\n    apply (simp add: nth_Cons split: nat.split)\n  using valid_offs\n  apply (clarsimp simp only:)\n  apply (subst nth_list_update, unat_arith) +\n  apply force\n done\nqed\n\nlemma ple32_take:\n assumes offs:\"offs < offs+4\"\n assumes ntake:\"unat (offs + 4) \\<le> ntake\"\n shows   \"ple32 (take ntake ys) offs = ple32 ys offs\"\n  apply (simp add: ple32_def)\n  apply (rule arg_cong[where f=\"word_rcat\"])\n  apply (rule arg_cong[where f=\"rev\"])\n  apply (subst list_eq_iff_nth_eq)\n  using offs ntake less_to_le[OF offs, simplified unat_plus_simple]\n  apply fastforce\n done\n \nlemma plus4_offs_ntake:\n  fixes offs ::U32\n  assumes \"unat (offs + 4) \\<le> ntake\"\n  assumes offs_overflow: \" (offs) <  ((offs+4))\"\n  assumes \"n \\<in> {0,1,2,3}\"\n  shows \"unat (offs+n) < ntake\"\n  using assms apply (clarsimp)\n  apply (erule disjE, unat_arith, fastforce?)+\n  apply simp\n  apply unat_arith\n done\n \nlemma ple32_append:\n  assumes no_overflow: \"offs < offs+4\" \n  assumes len_ys: \"unat (offs + 4) \\<le> length ys\"\n  shows   \"ple32 (ys@zs) offs = ple32 ys offs\"\n  using plus_no_overflow_unat_lift[OF no_overflow]  len_ys\n  by (simp add: ple32_def)\n  \nlemma ple32_append_Cons:\n  assumes no_overflow: \"offs < offs+4\"\n  assumes len_ys: \"unat (offs + 4) \\<le> length (v#ys)\"\n  shows   \"ple32 (v#ys@zs) offs = ple32 (v#ys) offs\"\nproof -\n  have unat_nth_simp_Cons: \"\\<And> n xs ys . \n    unat n < Suc (length xs) \\<Longrightarrow> (v#xs@ys)!(unat n) = (v#xs)!(unat n)\"\n  by (case_tac \"0 < unat n\") (fastforce simp: nth_append) +\n  show ?thesis\n  apply(subgoal_tac \"unat offs < Suc (length ys)\")\n   apply(rule ple32_append[where ys = \"v#ys\" and zs = \"zs\" and offs=\"offs\", simplified List.append.append_Cons])\n    using no_overflow apply clarsimp\n   using len_ys apply clarsimp\n  using assms by unat_arith\nqed\n\n  \ndefinition sle64 :: \"U64 \\<Rightarrow> U8 list\"\nwhere\n  \"sle64 \\<equiv> rev \\<circ> word_rsplit\"\n\nlemma deserialise_le64_ret:\nassumes valid_offs:\n  \"unat offs + 8 \\<le> length (\\<alpha>wa $ data\\<^sub>f buf)\"\nassumes no_ovf:\n  \"offs \\<le> offs + 8\"\nshows\n  \"deserialise_le64 (buf, offs) = (ple64 (\\<alpha>wa $ data\\<^sub>f buf) offs)\"\nusing valid_offs\n  apply (subgoal_tac \"(\\<forall>i\\<in>{0..7}. unat (offs+i) < length (\\<alpha>wa (data\\<^sub>f buf)))\")\n   prefer 2\n   apply unat_arith\n  apply (clarsimp simp: wordarray_get_ret[where arr=\"data\\<^sub>f buf\"] ple64_def \n                        deserialise_le64_def)\n  apply (subgoal_tac \"\\<forall>j\\<in>{1..7}. (unat (offs + j) > 0)\")\n   prefer 2\n   apply clarsimp\n   apply (drule_tac x=j in bspec, simp)\n   using no_ovf apply unat_arith\n   apply auto[1]\n  apply (subst take_drop_decomp, (simp+))+\n  apply (subst unatSuc[symmetric], (simp add: unat_gt_0[symmetric] add.commute[where b=offs])[1])+\n  apply simp\n  apply (rule trans, rule word_rcat_rsplit[symmetric])\n  apply (rule arg_cong[where f=word_rcat])\n  apply (subst word_rsplit_upt[where n=8], simp add: word_size)\n   apply simp\n  apply (simp add: upt_rec shiftr_over_or_dist shiftl_shiftr1 shiftl_shiftr2 word_size)\n  apply (safe intro!: word_eqI, simp_all add: word_size word_ops_nth_size nth_ucast\n        nth_shiftr nth_shiftl add.commute[where b=offs] test_bit_out_of_bounds)\n  done\n\nlemma serial_le64_helper:\n \"unat offs + 8 < length (\\<alpha>wa (data\\<^sub>f buf)) \\<Longrightarrow>\n   [u64_to_u8 v, u64_to_u8 (v >> 8), u64_to_u8 (v >> 16), u64_to_u8 (v >> 24),\n    u64_to_u8 (v >> 32),  u64_to_u8 (v >> 40), u64_to_u8 (v >> 48), u64_to_u8 (v >> 56)]\n = sle64 v\"\n  apply (clarsimp simp: u64_to_u8_is_ucast sle64_def)\n  apply (subst word_rsplit_upt[where n=8])\n    apply ((simp add: word_size upt_rec)+)[2]\n   apply (simp add: upt_rec)\n  done\n\nlemma serialise_le64_ret:\n  assumes no_overflow: \"offs < offs + 8\"\n  and valid_offs:\n   \"unat offs + 8 < length (\\<alpha>wa (data\\<^sub>f buf))\"\nshows\n  \"(serialise_le64 (buf, offs, v)) =\n  buf\\<lparr>data\\<^sub>f:=WordArrayT.make (buf_sub_slice buf offs (offs+8) (sle64 v))\\<rparr>\"\nproof -\n  have unat_plus:\n    \"\\<And>n. n \\<le> 8 \\<longrightarrow> unat (offs + n) = unat offs + unat n\"\n    using no_overflow valid_offs\n    by unat_arith auto\n  show ?thesis\n\n  apply (simp add: serialise_le64_def[unfolded sanitizers] serialise_u8_def[unfolded sanitizers] Let_def)\n  using valid_offs apply -\n  apply (handle_wa_mod \"offs\")\n  apply (handle_wa_mod \"offs+1\")\n  apply (handle_wa_mod \"offs+2\")\n  apply (handle_wa_mod \"offs+3\")\n  apply (handle_wa_mod \"offs+4\")\n  apply (handle_wa_mod \"offs+5\")\n  apply (handle_wa_mod \"offs+6\")\n  apply (handle_wa_mod \"offs+7\")\n          apply (simp add: serial_le64_helper[OF valid_offs, where v=v,symmetric])\n\n  apply (rule arg_cong[where f=\"\\<lambda>v. Buffer.data\\<^sub>f_update v buf\"])\n  apply (rule ext)\n  apply (rule arg_cong[where f=\"WordArrayT.make\"])\n  \n  apply (simp add: buf_sub_slice_def)\n  apply (rule trans, rule_tac n=\"unat offs\" in append_take_drop_id[symmetric],\n    rule arg_cong2[where f=append])\n   apply (simp add: unat_plus order_le_less_trans[OF _ valid_offs] take_list_update)\n  apply (simp add: unat_plus)\n    apply (cut_tac valid_offs, simp)\n   apply (simp add: max_absorb1)\n   apply (simp add: list_eq_iff_nth_eq)\n   apply (rule conjI)\n    using valid_offs\n    apply (simp add: nth_Cons split: nat.split)\n  using valid_offs\n  apply (clarsimp simp only:)\n  apply (subst nth_list_update, unat_arith) +\n  apply force\n done\nqed\n\nlemma ple64_take:\n assumes offs:\"offs < offs+8\"\n assumes ntake:\"unat (offs + 8) \\<le> ntake\"\n shows   \"ple64 (take ntake ys) offs = ple64 ys offs\"\n  apply (simp add: ple64_def)\n  apply (rule arg_cong[where f=\"word_rcat\"])\n  apply (rule arg_cong[where f=\"rev\"])\n  apply (subst list_eq_iff_nth_eq)\n  using offs ntake less_to_le[OF offs, simplified unat_plus_simple]\n  apply fastforce\n done\n \nlemma ple64_append:\n  assumes no_overflow: \"offs < offs + 8\" \n  assumes len_ys: \"unat (offs + 8) \\<le> length ys\"\n  shows   \"ple64 (ys@zs) offs = ple64 ys offs\"\n  using plus_no_overflow_unat_lift[OF no_overflow]  len_ys\n  by (simp add: ple64_def)\n  \nlemma ple64_append_Cons:\n  assumes no_overflow: \"offs < offs + 8\"\n  assumes len_ys: \"unat (offs + 8) \\<le> length (v#ys)\"\n  shows   \"ple64 (v#ys@zs) offs = ple64 (v#ys) offs\"\nproof -\n  have unat_nth_simp_Cons: \"\\<And> n xs ys . \n    unat n < Suc (length xs) \\<Longrightarrow> (v#xs@ys)!(unat n) = (v#xs)!(unat n)\"\n  by (case_tac \"0 < unat n\") (fastforce simp: nth_append) +\n  show ?thesis\n  apply(subgoal_tac \"unat offs < Suc (length ys)\")\n   apply(rule ple64_append[where ys = \"v#ys\" and zs = \"zs\" and offs=\"offs\", simplified List.append.append_Cons])\n    using no_overflow apply clarsimp\n   using len_ys apply clarsimp\n  using assms by unat_arith\nqed\n\nend\n", "meta": {"author": "au-ts", "repo": "cogent", "sha": "a1464313bbd1bbfaa5c4e58ab14f669c6d2436a2", "save_path": "github-repos/isabelle/au-ts-cogent", "path": "github-repos/isabelle/au-ts-cogent/cogent-a1464313bbd1bbfaa5c4e58ab14f669c6d2436a2/impl/fs/bilby/proof/spec/PleSle.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.4532618480153861, "lm_q1q2_score": 0.26002653512844814}}
{"text": "(*  \n    Author:      Salomon Sickert\n    License:     BSD\n*)\n\nsection \\<open>LTL Translation Layer\\<close>\n\ntheory LTL_Compat\n  imports Main LTL.LTL \"../LTL_FGXU\"\nbegin\n\n\\<comment> \\<open>The following infrastructure translates the generic @{datatype ltln} datatype to special structure used in this project\\<close>\n\nabbreviation LTLRelease :: \"'a ltl \\<Rightarrow> 'a ltl \\<Rightarrow> 'a ltl\" (\"_ R _\" [87,87] 86)\nwhere\n  \"\\<phi> R \\<psi> \\<equiv> (G \\<psi>) or (\\<psi> U (\\<phi> and \\<psi>))\"\n\nabbreviation LTLWeakUntil :: \"'a ltl \\<Rightarrow> 'a ltl \\<Rightarrow> 'a ltl\" (\"_ W _\" [87,87] 86)\nwhere\n  \"\\<phi> W \\<psi> \\<equiv> (\\<phi> U \\<psi>) or (G \\<phi>)\"\n\nabbreviation LTLStrongRelease :: \"'a ltl \\<Rightarrow> 'a ltl \\<Rightarrow> 'a ltl\" (\"_ M _\" [87,87] 86)\nwhere\n  \"\\<phi> M \\<psi> \\<equiv> \\<psi> U (\\<phi> and \\<psi>)\"\n\nfun ltln_to_ltl :: \"'a ltln \\<Rightarrow> 'a ltl\"\nwhere\n  \"ltln_to_ltl true\\<^sub>n = true\"\n| \"ltln_to_ltl false\\<^sub>n = false\"\n| \"ltln_to_ltl prop\\<^sub>n(q) = p(q)\"\n| \"ltln_to_ltl nprop\\<^sub>n(q) = np(q)\"\n| \"ltln_to_ltl (\\<phi> and\\<^sub>n \\<psi>) = ltln_to_ltl \\<phi> and ltln_to_ltl \\<psi>\"\n| \"ltln_to_ltl (\\<phi> or\\<^sub>n \\<psi>) = ltln_to_ltl \\<phi> or ltln_to_ltl \\<psi>\"\n| \"ltln_to_ltl (\\<phi> U\\<^sub>n \\<psi>) = (if \\<phi> = true\\<^sub>n then F (ltln_to_ltl \\<psi>) else (ltln_to_ltl \\<phi>) U (ltln_to_ltl \\<psi>))\"\n| \"ltln_to_ltl (\\<phi> R\\<^sub>n \\<psi>) = (if \\<phi> = false\\<^sub>n then G (ltln_to_ltl \\<psi>) else (ltln_to_ltl \\<phi>) R (ltln_to_ltl \\<psi>))\"\n| \"ltln_to_ltl (\\<phi> W\\<^sub>n \\<psi>) = (if \\<psi> = false\\<^sub>n then G (ltln_to_ltl \\<phi>) else (ltln_to_ltl \\<phi>) W (ltln_to_ltl \\<psi>))\"\n| \"ltln_to_ltl (\\<phi> M\\<^sub>n \\<psi>) = (if \\<psi> = true\\<^sub>n then F (ltln_to_ltl \\<phi>) else (ltln_to_ltl \\<phi>) M (ltln_to_ltl \\<psi>))\"\n| \"ltln_to_ltl (X\\<^sub>n \\<phi>) = X (ltln_to_ltl \\<phi>)\"\n\nlemma ltln_to_ltl_semantics:\n  \"w \\<Turnstile> ltln_to_ltl \\<phi> \\<longleftrightarrow> w \\<Turnstile>\\<^sub>n \\<phi>\"\n  by (induction \\<phi> arbitrary: w)\n     (simp_all del: semantics_ltln.simps(9-11), unfold ltln_Release_alterdef ltln_weak_strong(1) ltl_StrongRelease_Until_con, insert nat_less_le, auto)\n\nlemma ltln_to_ltl_atoms:\n  \"vars (ltln_to_ltl \\<phi>) = atoms_ltln \\<phi>\"\n  by (induction \\<phi>) auto\n\nfun atoms_list :: \"'a ltln \\<Rightarrow>'a list\"\nwhere \n  \"atoms_list (\\<phi> and\\<^sub>n \\<psi>) = List.union (atoms_list \\<phi>) (atoms_list \\<psi>)\"\n| \"atoms_list (\\<phi> or\\<^sub>n \\<psi>) = List.union (atoms_list \\<phi>) (atoms_list \\<psi>)\"\n| \"atoms_list (\\<phi> U\\<^sub>n \\<psi>) = List.union (atoms_list \\<phi>) (atoms_list \\<psi>)\"\n| \"atoms_list (\\<phi> R\\<^sub>n \\<psi>) = List.union (atoms_list \\<phi>) (atoms_list \\<psi>)\"\n| \"atoms_list (\\<phi> W\\<^sub>n \\<psi>) = List.union (atoms_list \\<phi>) (atoms_list \\<psi>)\"\n| \"atoms_list (\\<phi> M\\<^sub>n \\<psi>) = List.union (atoms_list \\<phi>) (atoms_list \\<psi>)\"\n| \"atoms_list (X\\<^sub>n \\<phi>) = atoms_list \\<phi>\"\n| \"atoms_list (prop\\<^sub>n(a)) = [a]\"\n| \"atoms_list (nprop\\<^sub>n(a)) = [a]\"\n| \"atoms_list _ = []\"\n\nlemma atoms_list_correct:\n  \"set (atoms_list \\<phi>) = atoms_ltln \\<phi>\"\n  by (induction \\<phi>) auto\n\nlemma atoms_list_distinct:\n  \"distinct (atoms_list \\<phi>)\"\n  by (induction \\<phi>) auto\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/LTL_to_DRA/Impl/LTL_Compat.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736783928749127, "lm_q2_score": 0.4532618480153861, "lm_q1q2_score": 0.2600265285209796}}
{"text": "(*  Title:      HOL/Auth/ZhouGollmann.thy\n    Author:     Giampaolo Bella and L C Paulson, Cambridge Univ Computer Lab\n    Copyright   2003  University of Cambridge\n\nThe protocol of\n  Jianying Zhou and Dieter Gollmann,\n  A Fair Non-Repudiation Protocol,\n  Security and Privacy 1996 (Oakland)\n  55-61\n*)\n\ntheory ZhouGollmann imports Public begin\n\nabbreviation\n  TTP :: agent where \"TTP == Server\"\n\nabbreviation f_sub :: nat where \"f_sub == 5\"\nabbreviation f_nro :: nat where \"f_nro == 2\"\nabbreviation f_nrr :: nat where \"f_nrr == 3\"\nabbreviation f_con :: nat where \"f_con == 4\"\n\n\ndefinition broken :: \"agent set\" where    \n    --{*the compromised honest agents; TTP is included as it's not allowed to\n        use the protocol*}\n   \"broken == bad - {Spy}\"\n\ndeclare broken_def [simp]\n\ninductive_set zg :: \"event list set\"\n  where\n\n  Nil:  \"[] \\<in> zg\"\n\n| Fake: \"[| evsf \\<in> zg;  X \\<in> synth (analz (spies evsf)) |]\n         ==> Says Spy B X  # evsf \\<in> zg\"\n\n| Reception:  \"[| evsr \\<in> zg; Says A B X \\<in> set evsr |] ==> Gets B X # evsr \\<in> zg\"\n\n  (*L is fresh for honest agents.\n    We don't require K to be fresh because we don't bother to prove secrecy!\n    We just assume that the protocol's objective is to deliver K fairly,\n    rather than to keep M secret.*)\n| ZG1: \"[| evs1 \\<in> zg;  Nonce L \\<notin> used evs1; C = Crypt K (Number m);\n           K \\<in> symKeys;\n           NRO = Crypt (priK A) {|Number f_nro, Agent B, Nonce L, C|}|]\n       ==> Says A B {|Number f_nro, Agent B, Nonce L, C, NRO|} # evs1 \\<in> zg\"\n\n  (*B must check that NRO is A's signature to learn the sender's name*)\n| ZG2: \"[| evs2 \\<in> zg;\n           Gets B {|Number f_nro, Agent B, Nonce L, C, NRO|} \\<in> set evs2;\n           NRO = Crypt (priK A) {|Number f_nro, Agent B, Nonce L, C|};\n           NRR = Crypt (priK B) {|Number f_nrr, Agent A, Nonce L, C|}|]\n       ==> Says B A {|Number f_nrr, Agent A, Nonce L, NRR|} # evs2  \\<in>  zg\"\n\n  (*A must check that NRR is B's signature to learn the sender's name;\n    without spy, the matching label would be enough*)\n| ZG3: \"[| evs3 \\<in> zg; C = Crypt K M; K \\<in> symKeys;\n           Says A B {|Number f_nro, Agent B, Nonce L, C, NRO|} \\<in> set evs3;\n           Gets A {|Number f_nrr, Agent A, Nonce L, NRR|} \\<in> set evs3;\n           NRR = Crypt (priK B) {|Number f_nrr, Agent A, Nonce L, C|};\n           sub_K = Crypt (priK A) {|Number f_sub, Agent B, Nonce L, Key K|}|]\n       ==> Says A TTP {|Number f_sub, Agent B, Nonce L, Key K, sub_K|}\n             # evs3 \\<in> zg\"\n\n (*TTP checks that sub_K is A's signature to learn who issued K, then\n   gives credentials to A and B.  The Notes event models the availability of\n   the credentials, but the act of fetching them is not modelled.  We also\n   give con_K to the Spy. This makes the threat model more dangerous, while \n   also allowing lemma @{text Crypt_used_imp_spies} to omit the condition\n   @{term \"K \\<noteq> priK TTP\"}. *)\n| ZG4: \"[| evs4 \\<in> zg; K \\<in> symKeys;\n           Gets TTP {|Number f_sub, Agent B, Nonce L, Key K, sub_K|}\n             \\<in> set evs4;\n           sub_K = Crypt (priK A) {|Number f_sub, Agent B, Nonce L, Key K|};\n           con_K = Crypt (priK TTP) {|Number f_con, Agent A, Agent B,\n                                      Nonce L, Key K|}|]\n       ==> Says TTP Spy con_K\n           #\n           Notes TTP {|Number f_con, Agent A, Agent B, Nonce L, Key K, con_K|}\n           # evs4 \\<in> zg\"\n\n\ndeclare Says_imp_knows_Spy [THEN analz.Inj, dest]\ndeclare Fake_parts_insert_in_Un  [dest]\ndeclare analz_into_parts [dest]\n\ndeclare symKey_neq_priEK [simp]\ndeclare symKey_neq_priEK [THEN not_sym, simp]\n\n\ntext{*A \"possibility property\": there are traces that reach the end*}\nlemma \"[|A \\<noteq> B; TTP \\<noteq> A; TTP \\<noteq> B; K \\<in> symKeys|] ==>\n     \\<exists>L. \\<exists>evs \\<in> zg.\n           Notes TTP {|Number f_con, Agent A, Agent B, Nonce L, Key K,\n               Crypt (priK TTP) {|Number f_con, Agent A, Agent B, Nonce L, Key K|} |}\n               \\<in> set evs\"\napply (intro exI bexI)\napply (rule_tac [2] zg.Nil\n                    [THEN zg.ZG1, THEN zg.Reception [of _ A B],\n                     THEN zg.ZG2, THEN zg.Reception [of _ B A],\n                     THEN zg.ZG3, THEN zg.Reception [of _ A TTP], \n                     THEN zg.ZG4])\napply (basic_possibility, auto)\ndone\n\nsubsection {*Basic Lemmas*}\n\nlemma Gets_imp_Says:\n     \"[| Gets B X \\<in> set evs; evs \\<in> zg |] ==> \\<exists>A. Says A B X \\<in> set evs\"\napply (erule rev_mp)\napply (erule zg.induct, auto)\ndone\n\nlemma Gets_imp_knows_Spy:\n     \"[| Gets B X \\<in> set evs; evs \\<in> zg |]  ==> X \\<in> spies evs\"\nby (blast dest!: Gets_imp_Says Says_imp_knows_Spy)\n\n\ntext{*Lets us replace proofs about @{term \"used evs\"} by simpler proofs \nabout @{term \"parts (spies evs)\"}.*}\nlemma Crypt_used_imp_spies:\n     \"[| Crypt K X \\<in> used evs; evs \\<in> zg |]\n      ==> Crypt K X \\<in> parts (spies evs)\"\napply (erule rev_mp)\napply (erule zg.induct)\napply (simp_all add: parts_insert_knows_A) \ndone\n\nlemma Notes_TTP_imp_Gets:\n     \"[|Notes TTP {|Number f_con, Agent A, Agent B, Nonce L, Key K, con_K |}\n           \\<in> set evs;\n        sub_K = Crypt (priK A) {|Number f_sub, Agent B, Nonce L, Key K|};\n        evs \\<in> zg|]\n    ==> Gets TTP {|Number f_sub, Agent B, Nonce L, Key K, sub_K|} \\<in> set evs\"\napply (erule rev_mp)\napply (erule zg.induct, auto)\ndone\n\ntext{*For reasoning about C, which is encrypted in message ZG2*}\nlemma ZG2_msg_in_parts_spies:\n     \"[|Gets B {|F, B', L, C, X|} \\<in> set evs; evs \\<in> zg|]\n      ==> C \\<in> parts (spies evs)\"\nby (blast dest: Gets_imp_Says)\n\n(*classical regularity lemma on priK*)\nlemma Spy_see_priK [simp]:\n     \"evs \\<in> zg ==> (Key (priK A) \\<in> parts (spies evs)) = (A \\<in> bad)\"\napply (erule zg.induct)\napply (frule_tac [5] ZG2_msg_in_parts_spies, auto)\ndone\n\ntext{*So that blast can use it too*}\ndeclare  Spy_see_priK [THEN [2] rev_iffD1, dest!]\n\nlemma Spy_analz_priK [simp]:\n     \"evs \\<in> zg ==> (Key (priK A) \\<in> analz (spies evs)) = (A \\<in> bad)\"\nby auto \n\n\nsubsection{*About NRO: Validity for @{term B}*}\n\ntext{*Below we prove that if @{term NRO} exists then @{term A} definitely\nsent it, provided @{term A} is not broken.*}\n\ntext{*Strong conclusion for a good agent*}\nlemma NRO_validity_good:\n     \"[|NRO = Crypt (priK A) {|Number f_nro, Agent B, Nonce L, C|};\n        NRO \\<in> parts (spies evs);\n        A \\<notin> bad;  evs \\<in> zg |]\n     ==> Says A B {|Number f_nro, Agent B, Nonce L, C, NRO|} \\<in> set evs\"\napply clarify\napply (erule rev_mp)\napply (erule zg.induct)\napply (frule_tac [5] ZG2_msg_in_parts_spies, auto)  \ndone\n\nlemma NRO_sender:\n     \"[|Says A' B {|n, b, l, C, Crypt (priK A) X|} \\<in> set evs; evs \\<in> zg|]\n    ==> A' \\<in> {A,Spy}\"\napply (erule rev_mp)  \napply (erule zg.induct, simp_all)\ndone\n\ntext{*Holds also for @{term \"A = Spy\"}!*}\ntheorem NRO_validity:\n     \"[|Gets B {|Number f_nro, Agent B, Nonce L, C, NRO|} \\<in> set evs;\n        NRO = Crypt (priK A) {|Number f_nro, Agent B, Nonce L, C|};\n        A \\<notin> broken;  evs \\<in> zg |]\n     ==> Says A B {|Number f_nro, Agent B, Nonce L, C, NRO|} \\<in> set evs\"\napply (drule Gets_imp_Says, assumption) \napply clarify \napply (frule NRO_sender, auto)\ntxt{*We are left with the case where the sender is @{term Spy} and not\n  equal to @{term A}, because @{term \"A \\<notin> bad\"}. \n  Thus theorem @{text NRO_validity_good} applies.*}\napply (blast dest: NRO_validity_good [OF refl])\ndone\n\n\nsubsection{*About NRR: Validity for @{term A}*}\n\ntext{*Below we prove that if @{term NRR} exists then @{term B} definitely\nsent it, provided @{term B} is not broken.*}\n\ntext{*Strong conclusion for a good agent*}\nlemma NRR_validity_good:\n     \"[|NRR = Crypt (priK B) {|Number f_nrr, Agent A, Nonce L, C|};\n        NRR \\<in> parts (spies evs);\n        B \\<notin> bad;  evs \\<in> zg |]\n     ==> Says B A {|Number f_nrr, Agent A, Nonce L, NRR|} \\<in> set evs\"\napply clarify\napply (erule rev_mp)\napply (erule zg.induct) \napply (frule_tac [5] ZG2_msg_in_parts_spies, auto)  \ndone\n\nlemma NRR_sender:\n     \"[|Says B' A {|n, a, l, Crypt (priK B) X|} \\<in> set evs; evs \\<in> zg|]\n    ==> B' \\<in> {B,Spy}\"\napply (erule rev_mp)  \napply (erule zg.induct, simp_all)\ndone\n\ntext{*Holds also for @{term \"B = Spy\"}!*}\ntheorem NRR_validity:\n     \"[|Says B' A {|Number f_nrr, Agent A, Nonce L, NRR|} \\<in> set evs;\n        NRR = Crypt (priK B) {|Number f_nrr, Agent A, Nonce L, C|};\n        B \\<notin> broken; evs \\<in> zg|]\n    ==> Says B A {|Number f_nrr, Agent A, Nonce L, NRR|} \\<in> set evs\"\napply clarify \napply (frule NRR_sender, auto)\ntxt{*We are left with the case where @{term \"B' = Spy\"} and  @{term \"B' \\<noteq> B\"},\n  i.e. @{term \"B \\<notin> bad\"}, when we can apply @{text NRR_validity_good}.*}\n apply (blast dest: NRR_validity_good [OF refl])\ndone\n\n\nsubsection{*Proofs About @{term sub_K}*}\n\ntext{*Below we prove that if @{term sub_K} exists then @{term A} definitely\nsent it, provided @{term A} is not broken.  *}\n\ntext{*Strong conclusion for a good agent*}\nlemma sub_K_validity_good:\n     \"[|sub_K = Crypt (priK A) {|Number f_sub, Agent B, Nonce L, Key K|};\n        sub_K \\<in> parts (spies evs);\n        A \\<notin> bad;  evs \\<in> zg |]\n     ==> Says A TTP {|Number f_sub, Agent B, Nonce L, Key K, sub_K|} \\<in> set evs\"\napply clarify\napply (erule rev_mp)\napply (erule zg.induct)\napply (frule_tac [5] ZG2_msg_in_parts_spies, simp_all)\ntxt{*Fake*} \napply (blast dest!: Fake_parts_sing_imp_Un)\ndone\n\nlemma sub_K_sender:\n     \"[|Says A' TTP {|n, b, l, k, Crypt (priK A) X|} \\<in> set evs;  evs \\<in> zg|]\n    ==> A' \\<in> {A,Spy}\"\napply (erule rev_mp)  \napply (erule zg.induct, simp_all)\ndone\n\ntext{*Holds also for @{term \"A = Spy\"}!*}\ntheorem sub_K_validity:\n     \"[|Gets TTP {|Number f_sub, Agent B, Nonce L, Key K, sub_K|} \\<in> set evs;\n        sub_K = Crypt (priK A) {|Number f_sub, Agent B, Nonce L, Key K|};\n        A \\<notin> broken;  evs \\<in> zg |]\n     ==> Says A TTP {|Number f_sub, Agent B, Nonce L, Key K, sub_K|} \\<in> set evs\"\napply (drule Gets_imp_Says, assumption) \napply clarify \napply (frule sub_K_sender, auto)\ntxt{*We are left with the case where the sender is @{term Spy} and not\n  equal to @{term A}, because @{term \"A \\<notin> bad\"}. \n  Thus theorem @{text sub_K_validity_good} applies.*}\napply (blast dest: sub_K_validity_good [OF refl])\ndone\n\n\n\nsubsection{*Proofs About @{term con_K}*}\n\ntext{*Below we prove that if @{term con_K} exists, then @{term TTP} has it,\nand therefore @{term A} and @{term B}) can get it too.  Moreover, we know\nthat @{term A} sent @{term sub_K}*}\n\nlemma con_K_validity:\n     \"[|con_K \\<in> used evs;\n        con_K = Crypt (priK TTP)\n                  {|Number f_con, Agent A, Agent B, Nonce L, Key K|};\n        evs \\<in> zg |]\n    ==> Notes TTP {|Number f_con, Agent A, Agent B, Nonce L, Key K, con_K|}\n          \\<in> set evs\"\napply clarify\napply (erule rev_mp)\napply (erule zg.induct)\napply (frule_tac [5] ZG2_msg_in_parts_spies, simp_all)\ntxt{*Fake*}\napply (blast dest!: Fake_parts_sing_imp_Un)\ntxt{*ZG2*} \napply (blast dest: parts_cut)\ndone\n\ntext{*If @{term TTP} holds @{term con_K} then @{term A} sent\n @{term sub_K}.  We assume that @{term A} is not broken.  Importantly, nothing\n  needs to be assumed about the form of @{term con_K}!*}\nlemma Notes_TTP_imp_Says_A:\n     \"[|Notes TTP {|Number f_con, Agent A, Agent B, Nonce L, Key K, con_K|}\n           \\<in> set evs;\n        sub_K = Crypt (priK A) {|Number f_sub, Agent B, Nonce L, Key K|};\n        A \\<notin> broken; evs \\<in> zg|]\n     ==> Says A TTP {|Number f_sub, Agent B, Nonce L, Key K, sub_K|} \\<in> set evs\"\napply clarify\napply (erule rev_mp)\napply (erule zg.induct)\napply (frule_tac [5] ZG2_msg_in_parts_spies, simp_all)\ntxt{*ZG4*}\napply clarify \napply (rule sub_K_validity, auto) \ndone\n\ntext{*If @{term con_K} exists, then @{term A} sent @{term sub_K}.  We again\n   assume that @{term A} is not broken. *}\ntheorem B_sub_K_validity:\n     \"[|con_K \\<in> used evs;\n        con_K = Crypt (priK TTP) {|Number f_con, Agent A, Agent B,\n                                   Nonce L, Key K|};\n        sub_K = Crypt (priK A) {|Number f_sub, Agent B, Nonce L, Key K|};\n        A \\<notin> broken; evs \\<in> zg|]\n     ==> Says A TTP {|Number f_sub, Agent B, Nonce L, Key K, sub_K|} \\<in> set evs\"\nby (blast dest: con_K_validity Notes_TTP_imp_Says_A)\n\n\nsubsection{*Proving fairness*}\n\ntext{*Cannot prove that, if @{term B} has NRO, then  @{term A} has her NRR.\nIt would appear that @{term B} has a small advantage, though it is\nuseless to win disputes: @{term B} needs to present @{term con_K} as well.*}\n\ntext{*Strange: unicity of the label protects @{term A}?*}\nlemma A_unicity: \n     \"[|NRO = Crypt (priK A) {|Number f_nro, Agent B, Nonce L, Crypt K M|};\n        NRO \\<in> parts (spies evs);\n        Says A B {|Number f_nro, Agent B, Nonce L, Crypt K M', NRO'|}\n          \\<in> set evs;\n        A \\<notin> bad; evs \\<in> zg |]\n     ==> M'=M\"\napply clarify\napply (erule rev_mp)\napply (erule rev_mp)\napply (erule zg.induct)\napply (frule_tac [5] ZG2_msg_in_parts_spies, auto) \ntxt{*ZG1: freshness*}\napply (blast dest: parts.Body) \ndone\n\n\ntext{*Fairness lemma: if @{term sub_K} exists, then @{term A} holds \nNRR.  Relies on unicity of labels.*}\nlemma sub_K_implies_NRR:\n     \"[| NRO = Crypt (priK A) {|Number f_nro, Agent B, Nonce L, Crypt K M|};\n         NRR = Crypt (priK B) {|Number f_nrr, Agent A, Nonce L, Crypt K M|};\n         sub_K \\<in> parts (spies evs);\n         NRO \\<in> parts (spies evs);\n         sub_K = Crypt (priK A) {|Number f_sub, Agent B, Nonce L, Key K|};\n         A \\<notin> bad;  evs \\<in> zg |]\n     ==> Gets A {|Number f_nrr, Agent A, Nonce L, NRR|} \\<in> set evs\"\napply clarify\napply hypsubst_thin\napply (erule rev_mp)\napply (erule rev_mp)\napply (erule zg.induct)\napply (frule_tac [5] ZG2_msg_in_parts_spies, simp_all)\ntxt{*Fake*}\napply blast \ntxt{*ZG1: freshness*}\napply (blast dest: parts.Body) \ntxt{*ZG3*} \napply (blast dest: A_unicity [OF refl]) \ndone\n\n\nlemma Crypt_used_imp_L_used:\n     \"[| Crypt (priK TTP) {|F, A, B, L, K|} \\<in> used evs; evs \\<in> zg |]\n      ==> L \\<in> used evs\"\napply (erule rev_mp)\napply (erule zg.induct, auto)\ntxt{*Fake*}\napply (blast dest!: Fake_parts_sing_imp_Un)\ntxt{*ZG2: freshness*}\napply (blast dest: parts.Body) \ndone\n\n\ntext{*Fairness for @{term A}: if @{term con_K} and @{term NRO} exist, \nthen @{term A} holds NRR.  @{term A} must be uncompromised, but there is no\nassumption about @{term B}.*}\ntheorem A_fairness_NRO:\n     \"[|con_K \\<in> used evs;\n        NRO \\<in> parts (spies evs);\n        con_K = Crypt (priK TTP)\n                      {|Number f_con, Agent A, Agent B, Nonce L, Key K|};\n        NRO = Crypt (priK A) {|Number f_nro, Agent B, Nonce L, Crypt K M|};\n        NRR = Crypt (priK B) {|Number f_nrr, Agent A, Nonce L, Crypt K M|};\n        A \\<notin> bad;  evs \\<in> zg |]\n    ==> Gets A {|Number f_nrr, Agent A, Nonce L, NRR|} \\<in> set evs\"\napply clarify\napply (erule rev_mp)\napply (erule rev_mp)\napply (erule zg.induct)\napply (frule_tac [5] ZG2_msg_in_parts_spies, simp_all)\n   txt{*Fake*}\n   apply (simp add: parts_insert_knows_A) \n   apply (blast dest: Fake_parts_sing_imp_Un) \n  txt{*ZG1*}\n  apply (blast dest: Crypt_used_imp_L_used) \n txt{*ZG2*}\n apply (blast dest: parts_cut)\ntxt{*ZG4*} \napply (blast intro: sub_K_implies_NRR [OF refl] \n             dest: Gets_imp_knows_Spy [THEN parts.Inj])\ndone\n\ntext{*Fairness for @{term B}: NRR exists at all, then @{term B} holds NRO.\n@{term B} must be uncompromised, but there is no assumption about @{term\nA}. *}\ntheorem B_fairness_NRR:\n     \"[|NRR \\<in> used evs;\n        NRR = Crypt (priK B) {|Number f_nrr, Agent A, Nonce L, C|};\n        NRO = Crypt (priK A) {|Number f_nro, Agent B, Nonce L, C|};\n        B \\<notin> bad; evs \\<in> zg |]\n    ==> Gets B {|Number f_nro, Agent B, Nonce L, C, NRO|} \\<in> set evs\"\napply clarify\napply (erule rev_mp)\napply (erule zg.induct)\napply (frule_tac [5] ZG2_msg_in_parts_spies, simp_all)\ntxt{*Fake*}\napply (blast dest!: Fake_parts_sing_imp_Un)\ntxt{*ZG2*}\napply (blast dest: parts_cut)\ndone\n\n\ntext{*If @{term con_K} exists at all, then @{term B} can get it, by @{text\ncon_K_validity}.  Cannot conclude that also NRO is available to @{term B},\nbecause if @{term A} were unfair, @{term A} could build message 3 without\nbuilding message 1, which contains NRO. *}\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/Auth/ZhouGollmann.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5544704796847396, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.259930563617163}}
{"text": "theory TheoremD5\nimports TheoremD4\nbegin\n\ncontext LocalLexing begin\n\n\n\nlemma \\<pi>_no_tokens: \"\\<pi> k {} I =  limit (\\<lambda> I. Complete k (Predict k I)) I\"\n  by (simp add: \\<pi>_def Scan_empty)\n\nlemma bin_elem: \"x \\<in> bin I k \\<Longrightarrow> x \\<in> I\"\n  by (auto simp add: bin_def)\n\nlemma Gen_implies_pvalid: \"x \\<in> Gen P \\<Longrightarrow> \\<exists> p \\<in> P. pvalid p x\"\n  by (auto simp add: Gen_def)\n\nlemma wellformed_init_item[simp]: \"r \\<in> \\<RR> \\<Longrightarrow> k \\<le> length Doc \\<Longrightarrow> wellformed_item (init_item r k)\"\n  by (simp add: init_item_def wellformed_item_def)\n\nlemma init_item_origin[simp]: \"item_origin (init_item r k) = k\"\n  by (auto simp add: item_origin_def init_item_def)\n\nlemma init_item_end[simp]: \"item_end (init_item r k) = k\"\n  by (auto simp add: item_end_def init_item_def)\n\nlemma init_item_nonterminal[simp]: \"item_nonterminal (init_item r k) = fst r\"\n  by (auto simp add: init_item_def item_nonterminal_def)\n\nlemma init_item_\\<alpha>[simp]: \"item_\\<alpha> (init_item r k) = []\"\n  by (auto simp add: init_item_def item_\\<alpha>_def)\n\nlemma Predict_elem_in_Gen:\n  assumes I_in_Gen_P: \"I \\<subseteq> Gen P\"\n  assumes k: \"k \\<le> length Doc\"\n  assumes x_in_Predict: \"x \\<in> Predict k I\"\n  shows \"x \\<in> Gen P\"\nproof -\n  have \"x \\<in> I \\<or> (\\<exists> r y. r \\<in> \\<RR> \\<and> x = init_item r k \\<and> y \\<in> bin I k \\<and> next_symbol y = Some(fst r))\"\n    using x_in_Predict by (auto simp add: Predict_def)\n  then show ?thesis\n  proof (induct rule: disjCases2)\n    case 1 thus ?case using I_in_Gen_P by blast\n  next\n    case 2 \n    then obtain r y where ry: \"r \\<in> \\<RR> \\<and> x = init_item r k \\<and> y \\<in> bin I k \\<and> \n      next_symbol y = Some (fst r)\" by blast\n    then have \"\\<exists> p \\<in> P. pvalid p y\"\n      using Gen_implies_pvalid I_in_Gen_P bin_elem subsetCE by blast \n    then obtain p where p: \"p \\<in> P \\<and> pvalid p y\" by blast\n    have wellformed_p: \"wellformed_tokens p\" using p by (auto simp add: pvalid_def)\n    have wellformed_x: \"wellformed_item x\"\n      by (simp add: ry k)\n    from ry have \"item_end y = k\" by (auto simp add: bin_def)\n    with p have charslength_p[simplified]: \"charslength p = k\" by (auto simp add: pvalid_def)\n    have item_end_x: \"item_end x = k\" by (simp add: ry)\n    have pvalid_x: \"pvalid p x\"\n      apply (auto simp add: pvalid_def)\n      apply (simp add: wellformed_p)\n      apply (simp add: wellformed_x)\n      apply (rule_tac x=\"length p\" in exI)\n      apply (auto simp add: charslength_p ry)\n      by (metis append_Cons next_symbol_starts_item_\\<beta> p pvalid_def \n        pvalid_is_derivation_terminals_item_\\<beta> ry)\n    then show ?case using Gen_def mem_Collect_eq p by blast\n qed\nqed\n\nlemma Predict_subset_Gen:\n  assumes \"I \\<subseteq> Gen P\"\n  assumes \"k \\<le> length Doc\"\n  shows \"Predict k I \\<subseteq> Gen P\"\nusing Predict_elem_in_Gen assms by blast\n\nlemma nth_superfluous_append[simp]: \"i < length a \\<Longrightarrow> (a@b)!i = a!i\"\nby (simp add: nth_append)\n\nlemma tokens_nth_in_\\<Z>: \n  \"p \\<in> \\<PP> \\<Longrightarrow> \\<forall> i. i < length p \\<longrightarrow> (\\<exists> u. p ! i \\<in> \\<Z> (charslength (take i p)) u)\"\nproof (induct rule: \\<PP>_induct)\n  case Base thus ?case by simp\nnext\n  case (Induct p k u)\n  then have \"p \\<in> limit (Append (\\<Z> k (Suc u)) k) (\\<P> k u)\" by simp\n  then show ?case\n  proof (induct rule: limit_induct)\n    case (Init p) thus ?case using Induct by auto\n  next\n    case (Iterate p Y)\n    from Iterate(2) have \"p \\<in> Y \\<or> (\\<exists> q t. p = q@[t] \\<and> q \\<in> by_length k Y \\<and> t \\<in> \\<Z> k (Suc u) \\<and> \n      admissible (q @ [t]))\"\n      by (auto simp add: Append_def)\n    then show ?case\n    proof (induct rule: disjCases2)\n      case 1 thus ?case using Iterate(1) by auto\n    next\n      case 2 \n      then obtain q t where \n        qt: \"p = q @ [t] \\<and> q \\<in> by_length k Y \\<and> t \\<in> \\<Z> k (Suc u) \\<and> admissible (q @ [t])\" by blast\n      then have q_in_Y: \"q \\<in> Y\" by auto\n      with qt have k: \"k = charslength q\" by auto\n      with qt have t: \"t \\<in> \\<Z> k (Suc u)\" by auto\n      show ?case\n      proof(auto simp add: qt)\n        fix i\n        assume i: \"i < Suc (length q)\"\n        then have \"i < length q \\<or> i = length q\" by arith\n        then show \"\\<exists>u. (q @ [t]) ! i \\<in> \\<Z> (length (chars (take i q))) u\"\n        proof (induct rule: disjCases2)\n          case 1\n            from Iterate(1)[OF q_in_Y]\n            show ?case by (simp add: 1)\n        next\n          case 2\n            show ?case \n              apply (auto simp add: 2)\n              apply (rule_tac x=\"Suc u\" in exI)\n              using k t by auto \n        qed\n      qed\n    qed\n  qed\nqed\n\nlemma path_append_token:\n  assumes p: \"p \\<in> \\<P> k u\"\n  assumes t: \"t \\<in> \\<Z> k (Suc u)\"\n  assumes pt: \"admissible (p@[t])\"\n  assumes k: \"charslength p = k\"\n  shows \"p@[t] \\<in> \\<P> k (Suc u)\"\napply (simp only: \\<P>.simps)\napply (rule_tac n=\"Suc 0\" in limit_elem)\nusing p t pt k apply (auto simp only: Append_def funpower.simps)\nby fastforce\n\ndefinition indexlt_rel :: \"((nat \\<times> nat) \\<times> (nat \\<times> nat)) set\" where\n  \"indexlt_rel = less_than <*lex*> less_than\"\n\ndefinition indexlt :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"indexlt k' u' k u = (((k', u'), (k, u)) \\<in> indexlt_rel)\"\n\nlemma indexlt_simp: \"indexlt k' u' k u = (k' < k \\<or> (k' = k \\<and> u' < u))\"\n  by (auto simp add: indexlt_def indexlt_rel_def)\n\nlemma wf_indexlt_rel: \"wf indexlt_rel\"\n  using indexlt_rel_def pair_less_def by auto\n\nlemma \\<P>_induct[consumes 1, case_names Induct]:\n  assumes \"p \\<in> \\<P> k u\"\n  assumes induct: \"\\<And> p k u . (\\<And> p' k' u'. p' \\<in> \\<P> k' u' \\<Longrightarrow> indexlt k' u' k u \\<Longrightarrow> P p' k' u') \n                     \\<Longrightarrow> p \\<in> \\<P> k u \\<Longrightarrow> P p k u\"\n  shows \"P p k u\"\nproof -\n  let ?R = \"indexlt_rel <*lex*> {}\"\n  have wf_R: \"wf ?R\" by (auto simp add: wf_indexlt_rel)\n  let ?P = \"\\<lambda> a. snd a \\<in> \\<P> (fst (fst a)) (snd (fst a)) \\<longrightarrow> P (snd a) (fst (fst a)) (snd (fst a))\"\n  have \"p \\<in> \\<P> k u \\<longrightarrow> P p k u\"\n    apply (rule wf_induct[OF wf_R, where P = ?P and a = \"((k, u), p)\", simplified])\n    apply (auto simp add: indexlt_def[symmetric])\n    apply (rule_tac p=ba and k=a and u=b in induct)\n    by auto\n  thus ?thesis using assms by auto \nqed\n\nlemma nonempty_path_indices: \n  assumes p: \"p \\<in> \\<P> k u\"\n  assumes nonempty: \"p \\<noteq> []\"\n  shows \"k > 0 \\<or> u > 0\"\nproof (cases \"u = 0\")\n  case True\n  note u = True\n  have \"k > 0\"\n  proof (cases \"k = 0\")\n    case True\n    with p u have \"p = []\" by simp\n    with nonempty have \"False\" by auto\n    then show ?thesis by auto\n  next\n    case False\n    then show ?thesis by arith\n  qed\n  then show ?thesis by blast\nnext\n  case False\n  then show ?thesis by arith\nqed\n\nlemma base_paths:\n  assumes p: \"p \\<in> \\<P> k 0\"\n  assumes k: \"k > 0\"\n  shows \"\\<exists> u. p \\<in> \\<P> (k - 1) u\"\nproof -\n  from k have \"\\<exists> i. k = Suc i\" by arith\n  then obtain i where i: \"k = Suc i\" by blast\n  from p show ?thesis\n    by (auto simp add: i natUnion_def)\nqed\n\nlemma indexlt_trans: \"indexlt k'' u'' k' u' \\<Longrightarrow> indexlt k' u' k u \\<Longrightarrow> indexlt k'' u'' k u\"\nusing dual_order.strict_trans indexlt_simp by auto\n\ndefinition is_continuation :: \"nat \\<Rightarrow> nat \\<Rightarrow> tokens \\<Rightarrow> tokens \\<Rightarrow> bool\" where\n  \"is_continuation k u q ts = (q \\<in> \\<P> k u \\<and> charslength q = k \\<and> admissible (q@ts) \\<and> \n     (\\<forall> t \\<in> set ts. t \\<in> \\<Z> k (Suc u)) \\<and> (\\<forall> t \\<in> set (butlast ts). chars_of_token t = []))\"\n\nlemma limit_Append_path_nonelem_split: \"p \\<in> limit (Append T k) (\\<P> k u) \\<Longrightarrow> p \\<notin> \\<P> k u \\<Longrightarrow>\n  \\<exists> q ts. p = q@ts \\<and> q \\<in> \\<P> k u \\<and> charslength q = k \\<and> admissible (q@ts) \\<and> (\\<forall> t \\<in> set ts. t \\<in> T) \\<and> \n    (\\<forall> t \\<in> set (butlast ts). chars_of_token t = [])\"\nproof (induct rule: limit_induct)\n  case (Init p) thus ?case by auto\nnext\n  case (Iterate p Y)\n  show ?case\n  proof (cases \"p \\<in> Y\")\n    case True\n    from Iterate(1)[OF True Iterate(3)] show ?thesis by blast\n  next\n    case False\n    with Append_def Iterate(2) \n    have \"\\<exists> q t. p = q@[t] \\<and> q \\<in> by_length k Y \\<and> t \\<in> T \\<and> admissible (q @ [t])\" by auto\n    then obtain q t where qt: \"p = q@[t] \\<and> q \\<in> by_length k Y \\<and> t \\<in> T \\<and> admissible (q @ [t])\" \n      by blast\n    from qt have qlen: \"charslength q = k\" by auto\n    have \"q \\<in> \\<P> k u \\<or> q \\<notin> \\<P> k u\" by blast\n    then show ?thesis\n    proof(induct rule: disjCases2)\n      case 1\n      show ?case\n        apply (rule_tac x=q in exI)\n        apply (rule_tac x=\"[t]\" in exI)\n        using qlen by (simp add: qt 1)\n    next\n      case 2\n      have q_in_Y: \"q \\<in> Y\" using qt by auto\n      from Iterate(1)[OF q_in_Y 2] \n      obtain q' ts where \n        q'ts: \"q = q' @ ts \\<and> q' \\<in> \\<P> k u \\<and> charslength q' = k \\<and> (\\<forall>t\\<in>set ts. t \\<in> T) \\<and>\n               (\\<forall>t\\<in>set(butlast ts). chars_of_token t = [])\"\n        by blast\n      with qlen have \"charslength ts = 0\" by auto\n      hence empty: \"\\<forall> t \\<in> set(ts). chars_of_token t = []\" \n        apply (induct ts)\n        by auto\n      show ?case\n        apply (rule_tac x=q' in exI)\n        apply (rule_tac x=\"ts@[t]\" in exI)\n        using qt q'ts empty by auto\n    qed\n  qed\nqed\n\nlemma limit_Append_path_nonelem_split': \n  \"p \\<in> limit (Append (\\<Z> k (Suc u)) k) (\\<P> k u) \\<Longrightarrow> p \\<notin> \\<P> k u \\<Longrightarrow>\n   \\<exists> q ts. p = q@ts \\<and> is_continuation k u q ts\"\napply (simp only: is_continuation_def)\napply (rule_tac limit_Append_path_nonelem_split)\nby auto\n\nlemma final_step_of_path: \"p \\<in> \\<P> k u \\<Longrightarrow> p \\<noteq> [] \\<Longrightarrow> (\\<exists> q ts k' u'. p = q@ts \\<and> indexlt k' u' k u \n  \\<and> is_continuation k' u' q ts)\"\nproof (induct rule: \\<P>_induct)\n  case (Induct p k u)\n  from Induct(2) Induct(3) have ku_0: \"k > 0 \\<or> u > 0\"\n    using nonempty_path_indices by blast\n  show ?case  \n  proof (cases \"u = 0\")\n    case True\n    with ku_0 have k_0: \"k > 0\" by arith\n    with True Induct(2) base_paths have \"\\<exists> u'. p \\<in> \\<P> (k - 1) u'\" by auto\n    then obtain u' where u': \"p \\<in> \\<P> (k - 1) u'\" by blast\n    have indexlt: \"indexlt (k - 1) u' k u\" by (simp add: indexlt_simp k_0)\n    from Induct(1)[OF u' indexlt Induct(3)] show ?thesis\n      using indexlt indexlt_trans by blast\n  next\n    case False \n    then have \"\\<exists> u'. u = Suc u'\" by arith\n    then obtain u' where u': \"u = Suc u'\" by blast\n    with Induct(2) have p_limit: \"p \\<in> limit (Append (\\<Z> k (Suc u')) k) (\\<P> k u')\"\n      using \\<P>.simps(2) by blast\n    from u' have indexlt: \"indexlt k u' k u\" by (simp add: indexlt_simp)\n    have \"p \\<in> \\<P> k u' \\<or> p \\<notin> \\<P> k u'\" by blast\n    then show ?thesis\n    proof (induct rule: disjCases2)\n      case 1\n      from Induct(1)[OF 1 indexlt Induct(3)] show ?case\n        using indexlt indexlt_trans by blast\n    next\n      case 2\n      from limit_Append_path_nonelem_split'[OF p_limit 2]\n      show ?case using indexlt u' by auto\n    qed\n  qed\nqed      \n\n\n\nlemma empty_in_\\<L>\\<^sub>P[simp]: \"[] \\<in> \\<L>\\<^sub>P\"\n  apply (simp add: \\<L>\\<^sub>P_def is_derivation_def)\n  apply (rule_tac x=\"[\\<SS>]\" in exI)\n  by simp \n     \n\n\nlemma \\<PP>_are_admissible: \"p \\<in> \\<PP> \\<Longrightarrow> admissible p\"\nproof (induct rule: \\<PP>_induct)\n  case Base thus ?case by simp\nnext\n  case (Induct p k u)\n  from Induct(2)[simplified] show ?case\n  proof (induct rule: limit_induct)\n    case (Init p) from Induct(1)[OF Init] show ?case .\n  next\n    case (Iterate p Y) \n    have \"\\<Y> (\\<Z> k u) (\\<P> k u) k \\<subseteq> \\<X> k\" by (metis \\<Z>.simps(2) \\<Z>_subset_\\<X>)\n    then have 1: \"Append (\\<Y> (\\<Z> k u) (\\<P> k u) k) k Y \\<subseteq> Append (\\<X> k) k Y\"\n      by (rule Append_mono, simp) \n    have 2: \"p \\<in> Append (\\<X> k) k Y \\<Longrightarrow> admissible p\"\n      apply (auto simp add: Append_def)\n      by (simp add: Iterate)\n    show ?case \n      apply (rule 2)\n      using \"1\" Iterate(2) by blast\n  qed  \nqed\n\nlemma prefix_of_empty_is_empty: \"is_prefix q [] \\<Longrightarrow> q = []\"\nby (metis  is_prefix_cons neq_Nil_conv)\n\nlemma subset_\\<P> :\n  assumes leq: \"k' < k \\<or> (k' = k \\<and> u' \\<le> u)\"\n  shows \"\\<P> k' u' \\<subseteq> \\<P> k u\"\nproof -\n  from leq show ?thesis\n  proof (induct rule: disjCases2)\n    case 1\n    have s1: \"\\<P> k' u' \\<subseteq> \\<Q> k'\" by (rule_tac subset_\\<P>\\<Q>k) \n    have s2: \"\\<Q> k' \\<subseteq> \\<Q> (k - 1)\" \n      apply (rule_tac subset_\\<Q>)\n      using 1 by arith\n    from subset_\\<Q>\\<P>Suc[where k=\"k - 1\"] 1 have s3: \"\\<Q> (k - 1) \\<subseteq> \\<P> k 0\"\n      by simp\n    have s4: \"\\<P> k 0 \\<subseteq> \\<P> k u\" by (rule_tac subset_\\<P>k, simp)\n    from s1 s2 s3 s4 subset_trans show ?case by blast\n  next\n    case 2 thus ?case by (simp add : subset_\\<P>k)\n  qed\nqed  \n\nlemma empty_path_is_elem[simp]: \"[] \\<in> \\<P> k u\"\nproof -\n  have \"[] \\<in> \\<P> 0 0\" by simp\n  then show \"[] \\<in> \\<P> k u\" by (metis le0 not_gr0 subsetCE subset_\\<P>) \nqed\n\nlemma is_prefix_of_append:\n  assumes \"is_prefix p (a@b)\"\n  shows \"is_prefix p a \\<or> (\\<exists> b'. b' \\<noteq> [] \\<and> is_prefix b' b \\<and> p = a@b')\"\napply (auto simp add: is_prefix_def) \nby (metis append_Nil2 append_eq_append_conv2 assms is_prefix_cancel is_prefix_def)\n\nlemma prefix_is_continuation: \"is_continuation k u p ts \\<Longrightarrow> is_prefix ts' ts \\<Longrightarrow> \n  is_continuation k u p ts'\"\napply (auto simp add: is_continuation_def is_prefix_def)\napply (metis \\<L>\\<^sub>P_split admissible_def append_assoc terminals_append)\nusing in_set_butlast_appendI by fastforce \n\nlemma charslength_0: \"(\\<forall> t \\<in> set ts. chars_of_token t = []) = (charslength ts = 0)\"\nby (induct ts, auto)\n    \nlemma is_continuation_in_\\<P>: \"is_continuation k u p ts \\<Longrightarrow> p@ts \\<in> \\<P> k (Suc u)\"\nproof(induct ts rule: rev_induct)\n  case Nil thus ?case \n    apply (auto simp add: is_continuation_def)\n    using subset_\\<P>Suc by fastforce\nnext\n  case (snoc t ts)\n  from snoc(2) have \"is_continuation k u p ts\"\n    by (metis append_Nil2 is_prefix_cancel is_prefix_empty prefix_is_continuation)\n  note induct = snoc(1)[OF this]\n  then have pts: \"p@ts \\<in> limit (Append (\\<Z> k (Suc u)) k) (\\<P> k u)\" by simp\n  note is_cont = snoc(2)\n  then have admissible: \"admissible (p@ts@[t])\" by (simp add: is_continuation_def)\n  from is_cont have t: \"t \\<in> \\<Z> k (Suc u)\" by (simp add: is_continuation_def)\n  from is_cont have \"\\<forall> t \\<in> set ts. chars_of_token t = []\" by (simp add: is_continuation_def)\n  then have charslength_ts: \"charslength ts = 0\" by (simp only: charslength_0)\n  from is_cont have plen: \"charslength p = k\" by (simp add: is_continuation_def)\n  show ?case\n    apply (simp only: \\<P>.simps)\n    apply (rule_tac limit_step_pointwise[OF pts])\n    apply (simp add: pointwise_Append)\n    apply (auto simp add: Append_def)\n    apply (rule_tac x=\"fst t\" in exI)\n    apply (rule_tac x=\"snd t\" in exI)\n    apply (auto simp add: admissible)\n    using charslength_ts apply simp\n    using plen apply simp\n    using t by simp\nqed    \n\nlemma indexlt_subset_\\<P>: \"indexlt k' u' k u \\<Longrightarrow> \\<P> k' (Suc u') \\<subseteq> \\<P> k u\"\napply (rule_tac subset_\\<P>)\napply (simp add: indexlt_simp)\napply arith\ndone\n\nlemma prefixes_are_paths: \"p \\<in> \\<P> k u \\<Longrightarrow> is_prefix x p \\<Longrightarrow> x \\<in> \\<P> k u\"\nproof (induct arbitrary: x rule: \\<P>_induct)\n  case (Induct p k u)\n  show ?case\n  proof (cases \"p = []\")\n    case True\n    then have \"x = []\"\n      using Induct.prems prefix_of_empty_is_empty by blast \n    then show \"x \\<in> \\<P> k u\" by simp\n  next\n    case False\n    from final_step_of_path[OF Induct(2) False]\n    obtain q ts k' u' where step: \"p = q@ts \\<and> indexlt k' u' k u \\<and> is_continuation k' u' q ts\"\n      by blast\n    have subset: \"\\<P> k' u' \\<subseteq> \\<P> k u\"\n      by (metis indexlt_simp less_or_eq_imp_le step subset_\\<P>)\n    have \"is_prefix x q \\<or> (\\<exists> ts'. ts' \\<noteq> [] \\<and> is_prefix ts' ts \\<and> x = q@ts')\"\n      apply (rule_tac is_prefix_of_append)\n      using Induct(3) step by auto\n    then show ?thesis\n    proof (induct rule: disjCases2)\n      case 1\n        have x: \"x \\<in> \\<P> k' u'\"\n        using 1 Induct step by (auto simp add: is_continuation_def)\n        then show \"x \\<in> \\<P> k u\" using subset subsetCE by blast\n    next\n      case 2\n      then obtain ts' where ts': \"is_prefix ts' ts \\<and> x = q@ts'\" by blast\n      have \"is_continuation k' u' q ts'\" using step prefix_is_continuation ts' by blast \n      with ts' have \"x \\<in> \\<P> k' (Suc u')\"\n        apply (simp only: ts')\n        apply (rule_tac is_continuation_in_\\<P>)\n        by simp\n      with subset show \"x \\<in> \\<P> k u\" using indexlt_subset_\\<P> step by blast\n    qed\n  qed\nqed  \n\nlemma empty_or_last_of_suffix:\n  assumes \"q = q' @ [t]\"\n  assumes \"q = p @ ts\"\n  shows \"ts = [] \\<or> (\\<exists> ts'. q' = p @ ts' \\<and> ts'@[t] = ts)\"\nby (metis assms(1) assms(2) butlast_append last_appendR snoc_eq_iff_butlast)\n\nlemma is_prefix_butlast: \"is_prefix q (butlast p) \\<Longrightarrow> is_prefix q p\"\nby (metis butlast_conv_take is_prefix_append is_prefix_def is_prefix_take)\n        \nlemma last_step_of_path:\n  \"q \\<in> \\<P> k u \\<Longrightarrow> q = q'@[t] \\<Longrightarrow>\n   \\<exists> k' u'. indexlt k' u' k u \\<and> q \\<in> \\<P> k' (Suc u') \\<and> charslength q' = k' \\<and> t \\<in> \\<Z> k' (Suc u')\"\nproof (induct arbitrary: q' t rule: \\<P>_induct)\n  case (Induct q k u)\n    have \"\\<exists> p ts k' u'. q = p@ts \\<and> indexlt k' u' k u \\<and> is_continuation k' u' p ts\"\n      apply (rule_tac final_step_of_path)\n      apply (simp add: Induct(2))\n      apply (simp add: Induct(3))\n      done\n    then obtain p ts k' u' where pts: \"q = p@ts \\<and> indexlt k' u' k u \\<and> is_continuation k' u' p ts\"\n      by blast\n    then have indexlt: \"indexlt k' u' k u\" by auto\n    from pts have \"ts = [] \\<or> (\\<exists> ts'. q' = p @ ts' \\<and> ts'@[t] = ts)\"\n      by (metis empty_or_last_of_suffix Induct(3))\n    then show ?case\n    proof (induct rule: disjCases2)\n      case 1\n        with pts have q: \"q \\<in> \\<P> k' u'\" by (auto simp add: is_continuation_def)\n        from Induct(1)[OF this indexlt Induct(3)] show ?case\n          using indexlt indexlt_trans by blast\n    next\n      case 2\n        then obtain ts' where ts': \"q' = p @ ts' \\<and> ts'@[t] = ts\" by blast\n        then have \"is_prefix ts' ts\" using is_prefix_def by blast \n        then have \"is_continuation k' u' p ts'\" by (metis prefix_is_continuation pts)\n        have \"charslength ts' = 0\" using charslength_0 is_continuation_def pts ts' by auto \n        then have q'len: \"charslength q' = k'\" using is_continuation_def pts ts' by auto \n        have \"t \\<in> set ts\" using ts' by auto\n        with pts have t_in_\\<Z>: \"t \\<in> \\<Z> k' (Suc u')\" using is_continuation_def by blast \n        have q_dom: \"q \\<in> \\<P> k' (Suc u')\" using pts is_continuation_in_\\<P> by blast\n        show ?case  \n          apply (rule_tac x=k' in exI)\n          apply (rule_tac x=u' in exI)\n          by (simp only: indexlt q'len t_in_\\<Z> q_dom)\n    qed\nqed\n      \nlemma charslength_of_butlast_0: \"p \\<in> \\<P> k 0 \\<Longrightarrow> p = q@[t] \\<Longrightarrow> charslength q < k\"\nusing last_step_of_path LocalLexing_axioms indexlt_simp by blast\n\nlemma charslength_of_butlast: \"p \\<in> \\<P> k u \\<Longrightarrow> p = q@[t] \\<Longrightarrow> charslength q \\<le> k\"\nby (metis indexlt_simp last_step_of_path eq_imp_le less_imp_le_nat)\n\nlemma last_token_of_path:\n  assumes \"q \\<in> \\<P> k u\"\n  assumes \"q = q'@[t]\"\n  assumes \"charslength q' = k\"\n  shows \"t \\<in> \\<Z> k u\"\nproof -\n  from assms have \"\\<exists> k' u'. indexlt k' u' k u \\<and> q \\<in> \\<P> k' (Suc u') \\<and> charslength q' = k' \\<and> \n    t \\<in> \\<Z> k' (Suc u')\" using last_step_of_path by blast\n  then obtain k' u' where th: \"indexlt k' u' k u \\<and> q \\<in> \\<P> k' (Suc u') \\<and> charslength q' = k' \\<and> \n    t \\<in> \\<Z> k' (Suc u')\" by blast\n  with assms(3) have k': \"k' = k\" by blast\n  with th have \"t \\<in> \\<Z> k' (Suc u') \\<and> u' < u\" using indexlt_simp by auto\n  then show ?thesis\n    by (metis (no_types, hide_lams) \\<Z>_subset_Suc k' linorder_neqE_nat not_less_eq \n      subsetCE subset_fSuc_strict)\nqed\n\nlemma final_step_of_path': \"p \\<in> \\<P> k u \\<Longrightarrow> p \\<notin> \\<P> k (u - 1) \\<Longrightarrow> \n  \\<exists> q ts. u > 0 \\<and> p = q@ts \\<and> is_continuation k (u - 1) q ts\"\nby (metis Suc_diff_1 \\<P>.simps(2) diff_0_eq_0 limit_Append_path_nonelem_split' not_gr0)\n\nlemma is_continuation_continue:\n  assumes \"is_continuation k u q ts\"\n  assumes \"charslength ts = 0\"\n  assumes \"t \\<in> \\<Z> k (Suc u)\"\n  assumes \"admissible (q @ ts @ [t])\"\n  shows \"is_continuation k u q (ts@[t])\"\nproof -\n  from assms show ?thesis\n    by (simp add: is_continuation_def charslength_0)\nqed\n\n(* In an older version of local lexing, compatibility was an assumption we had to make, \n   but now it is a theorem *)\n\ntheorem compatibility_def:\n  assumes p_in_dom: \"p \\<in> \\<P> k u\"\n  assumes q_in_dom: \"q \\<in> \\<P> k u\"\n  assumes p_charslength: \"charslength p = k\"\n  assumes q_split: \"q = q'@[t]\"\n  assumes q'len: \"charslength q' = k\"\n  assumes admissible: \"admissible (p @ [t])\" \n  shows \"p @ [t] \\<in> \\<P> k u\"\nproof - \n  have u: \"u > 0\"\n  proof (cases \"u = 0\")\n    case True\n      then have \"charslength q' < k\" \n        using charslength_of_butlast_0 q_in_dom q_split by blast       \n      with q'len have \"False\" by arith\n      then show ?thesis by blast\n  next\n    case False\n      then show ?thesis by arith\n  qed\n  have t_dom: \"t \\<in> \\<Z> k u\" using last_token_of_path q'len q_in_dom q_split by blast  \n  have \"p \\<in> \\<P> k (u - 1) \\<or> p \\<notin> \\<P> k (u - 1)\" by blast\n  then show ?thesis\n  proof (induct rule: disjCases2)\n    case 1\n      with t_dom p_charslength admissible u have \"is_continuation k (u - 1) p [t]\"\n        by (auto simp add: is_continuation_def)\n      with u show \"p@[t] \\<in> \\<P> k u\"\n        by (metis One_nat_def Suc_pred is_continuation_in_\\<P>)\n  next\n    case 2\n      from final_step_of_path'[OF p_in_dom 2] \n      obtain p' ts where p': \"p = p' @ ts \\<and> is_continuation k (u - 1) p' ts\"\n        by blast\n      from p' p_charslength is_continuation_def have charslength_ts: \"charslength ts = 0\"\n        by auto\n      from u have u': \"Suc (u - 1) = u\" by arith\n      have \"is_continuation k (u - 1) p' (ts@[t])\"\n        apply (rule_tac is_continuation_continue)\n        using p' apply blast\n        using charslength_ts apply blast\n        apply (simp only: u' t_dom)\n        using admissible p' apply auto\n        done\n      from is_continuation_in_\\<P>[OF this] show ?case by (simp only: p' u', simp)\n  qed\nqed    \n\nlemma is_prefix_admissible:\n  assumes \"is_prefix a b\"\n  assumes \"admissible b\"\n  shows \"admissible a\"\nproof -\n  from assms show ?thesis\n    by (auto simp add: is_prefix_def admissible_def \\<L>\\<^sub>P_def)\nqed  \n\nlemma butlast_split: \"n < length q \\<Longrightarrow> butlast q = (take n q)@(drop n (butlast q))\"\nby (metis append_take_drop_id take_butlast)\n\nlemma in_\\<P>_charslength:\n  assumes p_dom: \"p \\<in> \\<P> k u\"\n  shows \"\\<exists> v. p \\<in> \\<P> (charslength p) v\"\nproof (cases \"charslength p \\<ge> k\")\n  case True\n    show ?thesis\n      apply (rule_tac x=u in exI)\n      by (metis True le_neq_implies_less p_dom subsetCE subset_\\<P>)\nnext\n  case False\n    then have charslength: \"charslength p < k\" by arith\n    have \"p = [] \\<or> p \\<noteq> []\" by blast\n    thus ?thesis\n    proof (induct rule: disjCases2)\n      case 1 thus ?case by simp\n    next\n      case 2\n        from final_step_of_path[OF p_dom 2] obtain q ts k' u' where\n          step: \"p = q @ ts \\<and> indexlt k' u' k u \\<and> is_continuation k' u' q ts\" by blast\n        from step have k': \"charslength q = k'\" using is_continuation_def by blast  \n        from step have \"charslength q \\<le> charslength p\"  by simp       \n        with k' have k': \"k' \\<le> charslength p\" by simp\n        from step have \"p \\<in> \\<P> k' (Suc u')\" using is_continuation_in_\\<P> by blast \n        with k' have \"p \\<in> \\<P> (charslength p) (Suc u')\"\n          by (metis le_neq_implies_less subsetCE subset_\\<P>) \n        then show ?case by blast\n    qed\nqed\n\ntheorem general_compatibility:\n  \"p \\<in> \\<P> k u \\<Longrightarrow> q \\<in> \\<P> k u \\<Longrightarrow> charslength p = charslength (take n q) \n    \\<Longrightarrow> charslength p \\<le> k \\<Longrightarrow> admissible (p @ (drop n q)) \\<Longrightarrow> p @ (drop n q) \\<in> \\<P> k u\"\nproof (induct \"length q - n\" arbitrary: p q n k u)\n  case 0\n    from 0 have \"0 = length q - n\" by auto\n    then have n: \"n \\<ge> length q\" by arith\n    then have \"drop n q = []\" by auto\n    then show ?case by (simp add: \"0.prems\"(1)) \nnext\n  case (Suc l)\n    have \"n \\<ge> length q \\<or> n < length q\" by arith\n    then show ?case\n    proof (induct rule: disjCases2)\n      case 1\n        then have \"drop n q = []\" by auto\n        then show ?case by (simp add: Suc.prems(1))\n    next\n      case 2\n        then have \"length q > 0\" by auto\n        then have q_nonempty: \"q \\<noteq> []\" by auto\n        let ?q' = \"butlast q\"\n        from q_nonempty Suc(2) have h1: \"l = length ?q' - n\" by auto\n        have h2: \"?q' \\<in> \\<P> k u\"\n          by (metis Suc.prems(2) butlast_conv_take is_prefix_take prefixes_are_paths)\n        have h3: \"charslength p = charslength (take n ?q')\"\n          using \"2.hyps\" Suc.prems(3) take_butlast by force\n        have \"is_prefix (p @ drop n ?q') (p @ drop n q)\"\n          by (simp add: butlast_conv_take drop_take)\n        note h4 = is_prefix_admissible[OF this Suc.prems(5)] \n        note induct = Suc(1)[OF h1 Suc(3) h2 h3 Suc.prems(4) h4] \n        let ?p' = \"p @ (drop n (butlast q))\"\n        from induct have \"?p' \\<in> \\<P> k u\" .\n        let ?i = \"charslength ?p'\"\n        have charslength_i[symmetric]: \"charslength ?q' = ?i\"\n          using Suc.prems(3) apply simp\n          apply (subst butlast_split[OF 2])\n          by simp\n        have q_split: \"q = ?q'@[last q]\" by (simp add: q_nonempty)\n        with Suc.prems(2) charslength_of_butlast have charslength_q': \"charslength ?q' \\<le> k\" \n          by blast \n        from q_nonempty have p'last: \"?p'@[last q] = p@(drop n q)\"\n          by (metis \"2.hyps\" append_assoc drop_eq_Nil drop_keep_last not_le q_split)\n        have \"?i \\<le> k\" by (simp only: charslength_i charslength_q')\n        then have \"?i = k \\<or> ?i < k\" by auto\n        then show ?case\n        proof (induct rule: disjCases2)\n          case 1\n            have charslength_q': \"charslength ?q' = k\" using charslength_i[symmetric] 1 by blast\n            from compatibility_def[OF induct Suc.prems(2) 1 q_split charslength_q']\n            show ?case by (simp only: p'last Suc.prems(5))\n        next\n          case 2\n            from in_\\<P>_charslength[OF induct]\n            obtain v1 where v1: \"?p' \\<in> \\<P> ?i v1\" by blast \n            from last_step_of_path[OF Suc.prems(2) q_split] \n            have \"\\<exists> u. q \\<in> \\<P> ?i u\" by (metis charslength_i)\n            then obtain v2 where v2: \"q \\<in> \\<P> ?i v2\" by blast\n            let ?v = \"max v1 v2\"\n            have \"v1 \\<le> ?v\" by auto\n            with v1 have dom1: \"?p' \\<in> \\<P> ?i ?v\" by (metis (no_types, hide_lams) subsetCE subset_\\<P>k) \n            have \"v2 \\<le> ?v\" by auto\n            with v2 have dom2: \"q \\<in> \\<P> ?i ?v\" by (metis (no_types, hide_lams) subsetCE subset_\\<P>k) \n            from compatibility_def[OF dom1 dom2 _ q_split] \n            have \"p @ drop n q \\<in> \\<P> ?i ?v\"\n              by (simp only: p'last charslength_i[symmetric] Suc.prems(5))\n            then show \"p @ drop n q \\<in> \\<P> k u\" by (meson \"2.hyps\" subsetCE subset_\\<P>) \n        qed                                                          \n    qed        \nqed\n\nlemma wellformed_item_derives:\n  assumes wellformed: \"wellformed_item x\"\n  shows \"derives [item_nonterminal x] (item_rhs x)\"\nproof -\n  from wellformed have \"(item_nonterminal x, item_rhs x) \\<in> \\<RR>\"\n    by (simp add: item_nonterminal_def item_rhs_def wellformed_item_def)\n  then show ?thesis\n    by (metis append_Nil2 derives1_def derives1_implies_derives is_sentence_concat \n        rule_\\<alpha>_type self_append_conv2)\nqed      \n\nlemma wellformed_complete_item_\\<beta>:\n  assumes wellformed: \"wellformed_item x\"\n  assumes complete: \"is_complete x\" \n  shows \"item_\\<beta> x = []\"\nusing complete is_complete_def item_\\<beta>_def by auto\n\nlemma wellformed_complete_item_derives:\n  assumes wellformed: \"wellformed_item x\"\n  assumes complete: \"is_complete x\" \n  shows \"derives [item_nonterminal x] (item_\\<alpha> x)\"\nusing complete is_complete_def item_\\<alpha>_def wellformed wellformed_item_derives by auto \n\nlemma is_derivation_implies_admissible:\n  \"is_derivation (terminals p @ \\<delta>) \\<Longrightarrow> is_word (terminals p) \\<Longrightarrow> admissible p\"\nusing \\<L>\\<^sub>P_def admissible_def by blast\n\nlemma item_rhs_of_inc_item[simp]: \"item_rhs (inc_item x k) = item_rhs x\"\n  by (auto simp add: inc_item_def item_rhs_def)\n\nlemma item_rule_of_inc_item[simp]: \"item_rule (inc_item x k) = item_rule x\"\n  by (simp add: inc_item_def)\n\nlemma item_origin_of_inc_item[simp]: \"item_origin (inc_item x k) = item_origin x\"\n  by (simp add: inc_item_def)\n\nlemma item_end_of_inc_item[simp]: \"item_end (inc_item x k) = k\"\n  by (simp add: inc_item_def)\n\nlemma item_dot_of_inc_item[simp]: \"item_dot (inc_item x k) = (item_dot x) + 1\"\n  by (simp add: inc_item_def)\n\nlemma item_nonterminal_of_inc_item[simp]: \"item_nonterminal (inc_item x k) = item_nonterminal x\"\n  by (simp add: inc_item_def item_nonterminal_def)\n\nlemma wellformed_inc_item:\n  assumes wellformed: \"wellformed_item x\"\n  assumes next_symbol: \"next_symbol x = Some s\"\n  assumes k_upper_bound: \"k \\<le> length Doc\"\n  assumes k_lower_bound: \"k \\<ge> item_end x\"\n  shows \"wellformed_item (inc_item x k)\"\nproof -\n  have k_lower_bound': \"k \\<ge> item_origin x\"\n    using k_lower_bound wellformed wellformed_item_def by auto  \n  show ?thesis\n    apply (auto simp add: wellformed_item_def k_upper_bound k_lower_bound')\n    using wellformed wellformed_item_def apply blast\n    using is_complete_def next_symbol next_symbol_not_complete not_less_eq_eq by blast\nqed    \n\nlemma item_\\<alpha>_of_inc_item:\n  assumes wellformed: \"wellformed_item x\"\n  assumes next_symbol: \"next_symbol x = Some s\"\n  shows \"item_\\<alpha> (inc_item x k) = item_\\<alpha> x @ [s]\"\nby (metis (mono_tags, lifting) item_dot_of_inc_item item_rhs_of_inc_item \n  One_nat_def add.right_neutral add_Suc_right is_complete_def item_\\<alpha>_def item_\\<beta>_def \n  le_neq_implies_less list.sel(1) next_symbol next_symbol_not_complete next_symbol_starts_item_\\<beta> \n  take_hd_drop wellformed wellformed_item_def)\n\nlemma derives1_pad: \n  assumes derives1: \"derives1 \\<alpha> \\<beta>\"\n  assumes u: \"is_sentence u\"\n  assumes v: \"is_sentence v\"\n  shows \"derives1 (u@\\<alpha>@v) (u@\\<beta>@v)\"\nproof -\n  from derives1 have \n   \"\\<exists>x y N \\<delta>. \\<alpha> = x @ [N] @ y \\<and> \\<beta> = x @ \\<delta> @ y \\<and> is_sentence x \\<and> is_sentence y \\<and> (N, \\<delta>) \\<in> \\<RR>\"\n   by (auto simp add: derives1_def)\n  then obtain x y N \\<delta> where \n   1: \"\\<alpha> = x @ [N] @ y \\<and> \\<beta> = x @ \\<delta> @ y \\<and> is_sentence x \\<and> is_sentence y \\<and> (N, \\<delta>) \\<in> \\<RR>\" by blast\n  show ?thesis\n    apply (simp only: derives1_def)\n    apply (rule_tac x=\"u@x\" in exI)\n    apply (rule_tac x=\"y@v\" in exI)\n    apply (rule_tac x=N in exI)\n    apply (rule_tac x=\\<delta> in exI)\n    using 1 u v is_sentence_concat by auto\nqed\n\nlemma derives_pad:\n  \"derives \\<alpha> \\<beta> \\<Longrightarrow> is_sentence u \\<Longrightarrow> is_sentence v \\<Longrightarrow> derives (u@\\<alpha>@v) (u@\\<beta>@v)\"\nproof (induct rule: derives_induct)\n  case Base thus ?case by simp\nnext\n  case (Step y z) \n    from Step have 1: \"derives (u@\\<alpha>@v) (u@y@v)\" by auto\n    from Step have 2: \"derives1 y z\" by auto\n    then have \"derives1 (u@y@v) (u@z@v)\" by (simp add: Step.prems derives1_pad)    \n    then show ?case\n      using \"1\" derives1_implies_derives derives_trans by blast\nqed  \n\nlemma derives1_is_sentence: \"derives1 \\<alpha> \\<beta> \\<Longrightarrow> is_sentence \\<alpha> \\<and> is_sentence \\<beta>\"\nusing Derives1_sentence1 Derives1_sentence2 derives1_implies_Derives1 by blast\n\nlemma derives_is_sentence: \"derives \\<alpha> \\<beta> \\<Longrightarrow> (\\<alpha> = \\<beta>) \\<or> (is_sentence \\<alpha> \\<and> is_sentence \\<beta>)\"\nproof (induct rule: derives_induct)\n  case Base thus ?case by simp\nnext\n  case (Step y z) \n    show ?case using Step.hyps(2) Step.hyps(3) derives1_is_sentence by blast\nqed\n\nlemma derives_append: \n  assumes au: \"derives a u\"\n  assumes bv: \"derives b v\"\n  assumes is_sentence_a: \"is_sentence a\"\n  assumes is_sentence_b: \"is_sentence b\"\n  shows \"derives (a@b) (u@v)\"\nproof -\n  from au have \"a = u \\<or> (is_sentence a \\<and> is_sentence u)\"\n    using derives_is_sentence by blast\n  then have au_sentences: \"is_sentence a \\<and> is_sentence u\" using is_sentence_a by blast \n  from bv have \"b = v \\<or> (is_sentence b \\<and> is_sentence v)\"\n    using derives_is_sentence by blast\n  then have bv_sentences: \"is_sentence b \\<and> is_sentence v\" using is_sentence_b by blast \n  have 1: \"derives (a@b) (u@b)\"\n    apply (rule_tac derives_pad[OF au, where u=\"[]\", simplified])\n    using is_sentence_b by auto\n  have 2: \"derives (u@b) (u@v)\"\n    apply (rule_tac derives_pad[OF bv, where v=\"[]\", simplified])\n    apply (simp add: au_sentences)\n    done\n  from 1 2 derives_trans show ?thesis by blast\nqed  \n\nlemma is_sentence_item_\\<alpha>: \"wellformed_item x \\<Longrightarrow> is_sentence (item_\\<alpha> x)\"\n  by (metis is_sentence_take item_\\<alpha>_def item_rhs_def prod.collapse rule_\\<alpha>_type wellformed_item_def)\n\nlemma is_nonterminal_item_nonterminal:  \"wellformed_item x \\<Longrightarrow> is_nonterminal (item_nonterminal x)\"\n  by (metis item_nonterminal_def prod.collapse rule_nonterminal_type wellformed_item_def)\n  \nlemma Complete_elem_in_Gen:\n  assumes I_in_Gen: \"I \\<subseteq> Gen (\\<P> k u)\"\n  assumes k: \"k \\<le> length Doc\"\n  assumes x_in_Complete: \"x \\<in> Complete k I\"\n  shows \"x \\<in> Gen (\\<P> k u)\"\nproof -\n  let ?P = \"\\<P> k u\"\n  from x_in_Complete have \"x \\<in> I \\<or> (\\<exists> x1 x2. x = inc_item x1 k \\<and> \n     x1 \\<in> bin I (item_origin x2) \\<and> x2 \\<in> bin I k \\<and> is_complete x2 \\<and> \n     next_symbol x1 = Some (item_nonterminal x2))\"\n     by (auto simp add: Complete_def)\n  then show ?thesis\n  proof (induct rule: disjCases2)\n    case 1 thus ?case using I_in_Gen subsetCE by blast \n  next\n    case 2 \n    then obtain x1 x2 where x12: \"x = inc_item x1 k \\<and> \n      x1 \\<in> bin I (item_origin x2) \\<and> x2 \\<in> bin I k \\<and> is_complete x2 \\<and> \n      next_symbol x1 = Some (item_nonterminal x2)\" by blast\n    from x12 have \"\\<exists> p1 p2. p1 \\<in> ?P \\<and> pvalid p1 x1 \\<and> p2 \\<in> ?P \\<and> pvalid p2 x2\"\n      by (meson Gen_implies_pvalid I_in_Gen bin_elem subsetCE)\n    then obtain p1 p2 where p1: \"p1 \\<in> ?P \\<and> pvalid p1 x1\" and p2: \"p2 \\<in> ?P \\<and> pvalid p2 x2\"\n      by blast\n    from p1 obtain w \\<delta> where p1valid:\n      \"wellformed_tokens p1 \\<and>\n       wellformed_item x1 \\<and>\n       w \\<le> length p1 \\<and>\n       charslength p1 = item_end x1 \\<and>\n       charslength (take w p1) = item_origin x1 \\<and>\n       is_derivation (terminals (take w p1) @ [item_nonterminal x1] @ \\<delta>) \\<and>\n       derives (item_\\<alpha> x1) (terminals (drop w p1))\"\n       using pvalid_def by blast\n    from p2 obtain y \\<gamma> where p2valid:\n      \"wellformed_tokens p2 \\<and>\n       wellformed_item x2 \\<and>\n       y \\<le> length p2 \\<and>\n       charslength p2 = item_end x2 \\<and>\n       charslength (take y p2) = item_origin x2 \\<and>\n       is_derivation (terminals (take y p2) @ [item_nonterminal x2] @ \\<gamma>) \\<and>\n       derives (item_\\<alpha> x2) (terminals (drop y p2))\"\n       using pvalid_def by blast\n    let ?r = \"p1 @ (drop y p2)\"\n    have charslength_p1_eq: \"charslength p1 = item_end x1\" by (simp only: p1valid)\n    from x12 have item_end_x1: \"item_end x1 = item_origin x2\" \n      using bin_def mem_Collect_eq by blast\n    have item_end_x2: \"item_end x2 = k\" using bin_def x12 by blast \n    then have charslength_p1_leq: \"charslength p1 \\<le> k\"\n      using charslength_p1_eq item_end_x1 p2valid wellformed_item_def by auto \n    have \"\\<exists>\\<delta>'. item_\\<beta> x1 = [item_nonterminal x2] @ \\<delta>'\"\n      by (simp add: next_symbol_starts_item_\\<beta> p1valid x12)  \n    then obtain \\<delta>' where \\<delta>': \"item_\\<beta> x1 = [item_nonterminal x2] @ \\<delta>'\" by blast\n    have \"is_derivation ((terminals (take w p1))@(item_rhs x1)@\\<delta>)\"\n      using is_derivation_derives p1valid wellformed_item_derives by blast\n    then have \"is_derivation ((terminals (take w p1))@(item_\\<alpha> x1 @ item_\\<beta> x1)@\\<delta>)\"\n       by (simp add: item_rhs_split)\n    then have \"is_derivation ((terminals (take w p1))@((terminals (drop w p1)) @ item_\\<beta> x1)@\\<delta>)\"\n      using is_derivation_derives p1valid by auto\n    then have \"is_derivation ((terminals p1)@(item_\\<beta> x1)@\\<delta>)\"\n      by (metis append_assoc append_take_drop_id terminals_append)\n    then have \"is_derivation ((terminals p1)@([item_nonterminal x2] @ \\<delta>')@\\<delta>)\"\n      using is_derivation_derives \\<delta>' by auto\n    then have \"is_derivation ((terminals p1)@(terminals (drop y p2)) @ \\<delta>' @\\<delta>)\"\n      using is_complete_def is_derivation_derives is_derivation_step item_\\<alpha>_def \n        item_nonterminal_def item_rhs_def p2valid wellformed_item_def x12 by auto\n    then have \"is_derivation (terminals (p1 @ (drop y p2)) @ (\\<delta>' @ \\<delta>))\" by simp\n    then have admissible_r: \"admissible (p1 @ (drop y p2))\"\n      apply (rule_tac is_derivation_implies_admissible)\n      apply auto\n      apply (rule is_word_terminals)\n      apply (simp add: p1valid)\n      using p2valid using is_word_terminals_drop terminals_drop by auto \n    have r_in_dom: \"?r \\<in> \\<P> k u\"\n      apply (rule_tac general_compatibility)\n      apply (simp add: p1)\n      apply (simp add: p2)\n      apply (simp only: p2valid charslength_p1_eq item_end_x1)\n      apply (simp only: charslength_p1_leq)\n      by (simp add: admissible_r)\n    have wellformed_r: \"wellformed_tokens ?r\" \n      using admissible_r admissible_wellformed_tokens by blast \n    have wellformed_x: \"wellformed_item x\"\n      apply (simp add: x12)\n      apply (rule_tac wellformed_inc_item)\n      apply (simp add: p1valid)\n      apply (simp add: x12)\n      apply (simp add: k)\n      using charslength_p1_eq charslength_p1_leq by auto\n    have charslength_p1_as_p2: \"charslength p1 = charslength (take y p2)\"\n      using charslength_p1_eq item_end_x1 p2valid by linarith     \n    then have charslength_r: \"charslength ?r = item_end x\"\n      apply (simp add: x12)\n      apply (subst length_append[symmetric])\n      apply (subst chars_append[symmetric])\n      apply (subst append_take_drop_id)\n      using item_end_x2 p2valid by auto\n    have item_\\<alpha>_x: \"item_\\<alpha> x = item_\\<alpha> x1 @ [item_nonterminal x2]\"\n      using x12 p1valid by (simp add: item_\\<alpha>_of_inc_item)\n    from p2valid have derives_item_nonterminal_x2:\n      \"derives [item_nonterminal x2] (terminals (drop y p2))\"\n      using derives_trans wellformed_complete_item_derives x12 by blast\n    have \"pvalid ?r x\"\n      apply (auto simp only: pvalid_def)\n      apply (rule_tac x=w in exI)\n      apply (rule_tac x=\\<delta> in exI)\n      apply (auto simp only:)\n      apply (simp add: wellformed_r)\n      apply (simp add: wellformed_x)\n      using p1valid apply simp\n      apply (simp only: charslength_r)\n      using x12 p1valid apply simp\n      using x12 p1valid apply simp\n      apply (simp add:  item_\\<alpha>_x)\n      apply (rule_tac derives_append)\n      using p1valid apply simp\n      using derives_item_nonterminal_x2 p1valid apply auto[1]\n      using is_sentence_item_\\<alpha> p1valid apply blast\n      using is_derivation_is_sentence is_sentence_concat p2valid by blast\n    with r_in_dom show ?case using Gen_def mem_Collect_eq by blast\n  qed\nqed\n\nlemma Complete_subset_Gen:\n  assumes I_in_Gen_P: \"I \\<subseteq> Gen (\\<P> k u)\"\n  assumes k: \"k \\<le> length Doc\"\n  shows \"Complete k I \\<subseteq> Gen (\\<P> k u)\"\nusing Complete_elem_in_Gen I_in_Gen_P k by blast\n\nlemma \\<P>_are_admissible: \"p \\<in> \\<P> k u \\<Longrightarrow> admissible p\"\napply (rule_tac \\<PP>_are_admissible)\nusing \\<PP>_covers_\\<P> subsetCE by blast\n\nlemma is_continuation_base:\n  assumes p_dom: \"p \\<in> \\<P> k u\"\n  assumes charslength_p: \"charslength p = k\"\n  shows \"is_continuation k u p []\"\napply (auto simp add: is_continuation_def)\napply (simp add: p_dom)\nusing charslength_p apply simp\nusing \\<P>_are_admissible p_dom by blast\n\nlemma is_continuation_empty_chars: \n  \"is_continuation k u q ts \\<Longrightarrow> charslength (q@ts) = k \\<Longrightarrow> chars ts = []\"\nby (simp add: is_continuation_def)\n\nlemma \\<Z>_subset: \"u \\<le> v \\<Longrightarrow> \\<Z> k u \\<subseteq> \\<Z> k v\"\nusing \\<Z>_subset_Suc subset_fSuc by blast\n\nlemma is_continuation_increase_u:\n  assumes cont: \"is_continuation k u q ts\"\n  assumes uv: \"u \\<le> v\"\n  shows \"is_continuation k v q ts\"\nproof -\n  have \"q \\<in> \\<P> k u\" using cont is_continuation_def by blast\n  with uv have q_dom: \"q \\<in> \\<P> k v\" by (meson subsetCE subset_\\<P>k) \n  from uv have \\<Z>: \"\\<And> t. t \\<in> \\<Z> k (Suc u) \\<Longrightarrow> t \\<in> \\<Z> k (Suc v)\"\n    using \\<Z>_subset le_neq_implies_less less_imp_le_nat not_less_eq subsetCE by blast  \n  show ?thesis\n    apply (auto simp only: is_continuation_def)\n    apply (simp add: q_dom)\n    using cont is_continuation_def apply simp\n    using cont is_continuation_def apply simp\n    using cont is_continuation_def \\<Z> apply simp\n    using cont is_continuation_def apply (simp only:)\n    done\nqed\n\nlemma pvalid_next_symbol_derivable:\n  assumes pvalid: \"pvalid p x\" \n  assumes next_symbol: \"next_symbol x = Some s\"\n  shows \"\\<exists> \\<delta>. is_derivation((terminals p)@[s]@\\<delta>)\"\nproof -\n  from pvalid pvalid_def have wellformed_x: \"wellformed_item x\" by auto\n  from next_symbol_starts_item_\\<beta>[OF wellformed_x next_symbol]\n  obtain \\<omega> where \\<omega>: \"item_\\<beta> x = [s] @ \\<omega>\" by auto\n  from pvalid have \"\\<exists> \\<gamma>. is_derivation((terminals p)@(item_\\<beta> x)@\\<gamma>)\"\n    using pvalid_is_derivation_terminals_item_\\<beta> by blast\n  then obtain \\<gamma> where \"is_derivation((terminals p)@(item_\\<beta> x)@\\<gamma>)\" by blast\n  with \\<omega> have \"is_derivation((terminals p)@[s]@\\<omega>@\\<gamma>)\" by auto\n  then show ?thesis by blast\nqed\n\nlemma pvalid_admissible: \n  assumes pvalid: \"pvalid p x\" \n  shows \"admissible p\"\nproof -\n  have \"\\<exists> \\<delta>. is_derivation((terminals p)@(item_\\<beta> x)@\\<delta>)\"\n    by (simp add: pvalid pvalid_is_derivation_terminals_item_\\<beta>)\n  then obtain \\<delta> where \\<delta>: \"is_derivation((terminals p)@(item_\\<beta> x)@\\<delta>)\" by blast\n  have is_word: \"is_word (terminals p)\"\n    using pvalid_def is_word_terminals pvalid by blast \n  show ?thesis using \\<delta> is_derivation_implies_admissible is_word by blast\nqed \n\nlemma pvalid_next_terminal_admissible:\n  assumes pvalid: \"pvalid p x\" \n  assumes next_symbol: \"next_symbol x = Some t\"\n  assumes terminal: \"is_terminal t\"\n  shows \"admissible (p@[(t, c)])\"\nproof -\n  have \"is_word (terminals p)\"\n    using is_word_terminals pvalid pvalid_def by blast\n  then show ?thesis\n    using is_derivation_implies_admissible next_symbol pvalid pvalid_next_symbol_derivable \n      terminal by fastforce\nqed\n\nlemma \\<X>_wellformed: \"t \\<in> \\<X> k \\<Longrightarrow> wellformed_token t\"\n  by (simp add: \\<X>_are_terminals wellformed_token_def)\n\nlemma \\<Z>_wellformed: \"t \\<in> \\<Z> k u \\<Longrightarrow> wellformed_token t\"\n  using \\<X>_wellformed \\<Z>_subset_\\<X> by blast\n \nlemma Scan_elem_in_Gen:\n  assumes I_in_Gen: \"I \\<subseteq> Gen (\\<P> k u)\"\n  assumes k: \"k \\<le> length Doc\"\n  assumes T: \"T \\<subseteq> \\<Z> k u\"\n  assumes x_in_Scan: \"x \\<in> Scan T k I\"\n  shows \"x \\<in> Gen (\\<P> k u)\"\nproof -\n  have \"u = 0 \\<Longrightarrow> x \\<in> I\" \n  proof -\n    assume \"u = 0\"\n    then have \"\\<Z> k u = {}\" by simp\n    then have \"T = {}\" using T by blast\n    then have \"Scan T k I = I\" by (simp add: Scan_empty)\n    then show \"x \\<in> I\" using x_in_Scan by simp\n  qed\n  then have \"x \\<in> I \\<or> (u > 0 \\<and> (\\<exists> y t c. x = inc_item y (k + length c) \\<and> y \\<in> bin I k \\<and> \n    (t, c) \\<in> T \\<and> next_symbol y = Some t))\" using x_in_Scan Scan_def by auto\n  then show ?thesis\n  proof (induct rule: disjCases2)\n    case 1 thus ?case using I_in_Gen by blast\n  next\n    case 2 \n    then obtain y t c where x_is_scan: \"x = inc_item y (k + length c) \\<and> y \\<in> bin I k \\<and> \n       (t, c) \\<in> T \\<and> next_symbol y = Some t\" by blast\n    have u_gt_0: \"0 < u\" using 2 by blast\n    have \"\\<exists> p \\<in> \\<P> k u. pvalid p y\" using Gen_implies_pvalid I_in_Gen bin_elem x_is_scan by blast \n    then obtain p where p: \"p \\<in> \\<P> k u \\<and> pvalid p y\" by blast\n    have p_dom: \"p \\<in> \\<P> k u\" using p by blast\n    from p pvalid_def x_is_scan have charslength_p: \"charslength p = k\"\n      using bin_def mem_Collect_eq by auto \n    obtain tok where tok: \"tok = (t, c)\" using x_is_scan by blast\n    have tok_dom: \"tok \\<in> \\<Z> k u\" using tok x_is_scan T by blast\n    have \"p = [] \\<or> p \\<noteq> []\" by blast\n    then have \"\\<exists> q ts u'. p = q@ts \\<and> u' < u \\<and> charslength ts = 0 \\<and> is_continuation k u' q ts\"\n    proof (induct rule: disjCases2)\n      case 1 thus ?case\n        apply (rule_tac x=p in exI)\n        apply (rule_tac x=\"[]\" in exI)\n        apply (rule_tac x=\"0\" in exI)\n        apply (simp add: 2 is_continuation_def)\n        using charslength_p by simp\n    next\n      case 2\n      from final_step_of_path[OF p_dom 2] obtain q ts k' u'\n        where final_step: \"p = q @ ts \\<and> indexlt k' u' k u \\<and> is_continuation k' u' q ts\" by blast\n      then have \"k' \\<le> k\" using indexlt_simp by auto \n      then have \"k' < k \\<or> k' = k\" by arith\n      then show ?case\n      proof (induct rule: disjCases2)\n        case 1 \n        have \"p \\<in> \\<P> k' (Suc u')\" using final_step is_continuation_in_\\<P> by blast \n        then have p_dom: \"p \\<in> \\<P> k 0\" by (meson 1 subsetCE subset_\\<P>) \n        with charslength_p have \"is_continuation k 0 p []\" using is_continuation_base by blast \n        then show ?case\n          apply (rule_tac x=p in exI)\n          apply (rule_tac x=\"[]\" in exI)\n          apply (rule_tac x=\"0\" in exI)\n          apply (simp add: u_gt_0)\n          done\n      next\n        case 2\n        with final_step indexlt_simp have \"u' < u\" by auto\n        then show ?case\n          apply (rule_tac x=q in exI)\n          apply (rule_tac x=ts in exI)\n          apply (rule_tac x=u' in exI)\n          using final_step 2 apply auto\n          using charslength_p is_continuation_empty_chars by blast\n      qed\n    qed\n    then obtain q ts u' where \n      p_split: \"p = q@ts \\<and> u' < u \\<and> charslength ts = 0 \\<and> is_continuation k u' q ts\" by blast\n    then have \"\\<exists> u''. u' \\<le> u'' \\<and> Suc u'' = u\" by (auto, arith)\n    then obtain u'' where u'': \" u' \\<le> u'' \\<and> Suc u'' = u\" by blast\n    with p_split have cont_u'': \"is_continuation k u'' q ts\" \n      using is_continuation_increase_u by blast \n    have admissible: \"admissible (p@[tok])\"\n      apply (simp add: tok)\n      apply (rule_tac pvalid_next_terminal_admissible[where x=y])\n      apply (simp add: p)\n      apply (simp add: x_is_scan)\n      using \\<Z>_wellformed tok tok_dom wellformed_token_def by auto \n    have \"is_continuation k u'' q (ts@[tok])\"\n      apply (rule is_continuation_continue)\n      apply (simp add: cont_u'')\n      using p_split apply simp\n      using u'' tok_dom apply simp\n      using admissible p_split by auto\n    with p_split u'' have ptok_dom: \"p@[tok] \\<in> \\<P> k u\" \n      using append_assoc is_continuation_in_\\<P> by auto \n    from p obtain i \\<gamma> where valid:\n      \"wellformed_tokens p \\<and>\n       wellformed_item y \\<and>\n       i \\<le> length p \\<and>\n       charslength p = item_end y \\<and>\n       charslength (take i p) = item_origin y \\<and>\n       is_derivation (terminals (take i p) @ [item_nonterminal y] @ \\<gamma>) \\<and>\n       derives (item_\\<alpha> y) (terminals (drop i p))\" using pvalid_def by blast \n    have clen_ptok: \"k + length c = charslength (p@[tok])\"\n      using charslength_p tok by simp\n    from ptok_dom have ptok_doc_tokens: \"doc_tokens (p@[tok])\"\n      using \\<PP>_are_doc_tokens \\<PP>_covers_\\<P> rev_subsetD by blast\n    have wellformed_x: \"wellformed_item x\"\n      apply (simp add: x_is_scan)\n      apply (rule_tac wellformed_inc_item)\n      apply (simp add: valid)\n      apply (simp add: x_is_scan)\n      apply (simp only: clen_ptok) \n      using ptok_doc_tokens charslength.simps doc_tokens_length apply presburger \n      apply (simp only: clen_ptok)\n      using valid by auto\n    have \"pvalid (p@[tok]) x\"\n      apply (auto simp only: pvalid_def)\n      apply (rule_tac x=i in exI)\n      apply (rule_tac x=\\<gamma> in exI)\n      apply (auto simp only:)\n      using ptok_dom admissible admissible_wellformed_tokens apply blast \n      apply (simp add: wellformed_x)\n      using valid apply simp\n      apply (simp add: x_is_scan clen_ptok)\n      using valid apply (simp add: x_is_scan)\n      using valid apply (simp add: x_is_scan)\n      using valid apply (simp add: x_is_scan)\n      apply (subst item_\\<alpha>_of_inc_item)\n      using valid apply simp\n      using x_is_scan apply simp\n      apply (rule_tac derives_append)\n      apply simp\n      apply (simp add: tok)\n      using is_sentence_item_\\<alpha> apply blast\n      by (meson pvalid_next_symbol_derivable LocalLexing_axioms is_derivation_is_sentence \n          is_sentence_concat p x_is_scan)\n    with ptok_dom show ?thesis\n      using Gen_def mem_Collect_eq by blast\n  qed\nqed\n\nlemma Scan_subset_Gen:\n  assumes I_in_Gen: \"I \\<subseteq> Gen (\\<P> k u)\"\n  assumes k: \"k \\<le> length Doc\"\n  assumes T: \"T \\<subseteq> \\<Z> k u\"\n  shows \"Scan T k I \\<subseteq> Gen (\\<P> k u)\"\nusing I_in_Gen Scan_elem_in_Gen T k by blast\n\ntheorem thmD5:\n  assumes I: \"I \\<subseteq> Gen (\\<P> k u)\"\n  assumes k: \"k \\<le> length Doc\"\n  assumes T: \"T \\<subseteq> \\<Z> k u\"\n  shows \"\\<pi> k T I \\<subseteq> Gen (\\<P> k u)\"\napply (simp add: \\<pi>_def)\napply (rule_tac limit_upperbound)\nusing I k T Predict_subset_Gen Complete_subset_Gen Scan_subset_Gen apply metis\nby (simp add: I)\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/LocalLexing/TheoremD5.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.25993055671454346}}
{"text": "theory LaunchburyAbstractTransformation\nimports Launchbury\nbegin\n\n\nlocale reds_rel = \n  fixes rel :: \"(heap \\<times> exp) \\<Rightarrow> var list \\<Rightarrow> (heap \\<times> exp) \\<Rightarrow>  bool\" (\"_ \\<triangleright>\\<^bsub>_\\<^esub> _\" [50,50,50] 50 )\n\nlocale reds_rel_fresh = reds_rel +\n  assumes fresh_rel1[simp]: \"(\\<Gamma>, e) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', e') \\<Longrightarrow> a \\<sharp> \\<Gamma> \\<Longrightarrow> a \\<sharp> \\<Gamma>'\"\n  assumes fresh_rel2[simp]: \"(\\<Gamma>, e) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', e') \\<Longrightarrow> a \\<sharp> e \\<Longrightarrow> a \\<sharp> e'\"\n\nlocale rel_lambda_cong = reds_rel + \n  assumes rel_lambda_cong: \"(\\<Gamma>, Lam [x]. e) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', lam) \\<Longrightarrow> (\\<And>e'. lam = Lam [x]. e' \\<Longrightarrow> thesis) \\<Longrightarrow> thesis\"\n\nlocale rel_lambda_case = rel_lambda_cong\nbegin\nlemma lambda_case:\n  fixes \\<Gamma> x e L \\<Gamma>' e'\n  assumes \"(\\<Gamma>, Lam [x]. e) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', e')\"\n  shows \"\\<exists>\\<Delta>' z'. (\\<Gamma>, Lam [x]. e) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Delta>', z') \\<and> \\<Gamma>' : e' \\<Down>\\<^bsub>L\\<^esub> \\<Delta>' : z'\"\nproof-\n  note assms\n  moreover\n  then obtain e'' where \"e' = Lam [x]. e''\" by (rule rel_lambda_cong)\n  moreover\n  have \"\\<Gamma>' : Lam [x]. e'' \\<Down>\\<^bsub>L\\<^esub> \\<Gamma>' : Lam [x]. e''\"..\n  ultimately show ?thesis by auto\nqed\nend\n\nlocale rel_app_cong = reds_rel + \n  assumes rel_app_cong: \"(\\<Gamma>, App e x) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', e') \\<Longrightarrow> (\\<And>e''. e' = App e'' x \\<Longrightarrow> thesis) \\<Longrightarrow> thesis\"\n\nlocale rel_app_case = reds_rel_fresh + rel_lambda_cong + rel_app_cong +\n  assumes rel_app_apply: \"(\\<Gamma>, App e x) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', App e'' x) \\<Longrightarrow> (\\<Gamma>, e) \\<triangleright>\\<^bsub>x # L\\<^esub> (\\<Gamma>', e'')\"\n  assumes rel_lam_subst: \"(\\<Gamma>, Lam [y]. body) \\<triangleright>\\<^bsub>x # L\\<^esub> (\\<Gamma>', Lam [y]. body') \\<Longrightarrow> (\\<Gamma>, body[y::=x]) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', body'[y::=x])\"\nbegin\nlemma app_case:\n  fixes y \\<Gamma> e x L \\<Delta> \\<Theta> z body\n  assumes \"atom y \\<sharp> \\<Gamma>\"\n  assumes \"atom y \\<sharp> e\"\n  assumes \"atom y \\<sharp> x\"\n  assumes \"atom y \\<sharp> L\"\n  assumes \"atom y \\<sharp> \\<Delta>\"\n  assumes \"atom y \\<sharp> \\<Theta>\"\n  assumes \"atom y \\<sharp> z\"\n  assumes \"\\<Gamma> : e \\<Down>\\<^bsub>x # L\\<^esub> \\<Delta> : Lam [y]. body\"\n  assumes \"\\<And> \\<Gamma>' e'. (\\<Gamma>, e) \\<triangleright>\\<^bsub>x # L\\<^esub> (\\<Gamma>', e') \\<Longrightarrow> \\<exists>\\<Delta>'' z'. (\\<Delta>, Lam [y]. body) \\<triangleright>\\<^bsub>x # L\\<^esub> (\\<Delta>'', z') \\<and> \\<Gamma>' : e' \\<Down>\\<^bsub>x # L\\<^esub> \\<Delta>'' : z'\"\n  assumes \"\\<Delta> : body[y::=x] \\<Down>\\<^bsub>L\\<^esub> \\<Theta> : z\"\n  assumes \"\\<And> \\<Gamma>' e'. (\\<Delta>, body[y::=x]) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', e') \\<Longrightarrow> \\<exists>\\<Delta>' z'. (\\<Theta>, z) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Delta>', z') \\<and> \\<Gamma>' : e' \\<Down>\\<^bsub>L\\<^esub> \\<Delta>' : z'\"\n  assumes \"(\\<Gamma>, App e x) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', e')\"\n  shows \"\\<exists>\\<Delta>' z'. (\\<Theta>, z) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Delta>', z') \\<and> \\<Gamma>' : e' \\<Down>\\<^bsub>L\\<^esub> \\<Delta>' : z'\"\nproof-\n  from `(\\<Gamma>, App e x) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', e')`\n  obtain e'' where \"e' = App e'' x\" by (rule rel_app_cong)\n  from `(\\<Gamma>, App e x) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', e')`[unfolded this]\n  have \"(\\<Gamma>, e) \\<triangleright>\\<^bsub>x # L\\<^esub> (\\<Gamma>', e'')\" by (rule rel_app_apply)\n  from assms(9)[OF this]\n  obtain \\<Delta>' lam\n  where \"(\\<Delta>, Lam [y]. body) \\<triangleright>\\<^bsub>x # L\\<^esub> (\\<Delta>', lam)\" and reds1: \"\\<Gamma>' : e'' \\<Down>\\<^bsub>x # L\\<^esub> \\<Delta>' : lam\" by blast\n  from this(1)\n  obtain body' where \"lam = Lam [y]. body'\" by (rule rel_lambda_cong)\n\n  from `(\\<Delta>, Lam [y]. body) \\<triangleright>\\<^bsub>x # L\\<^esub> (\\<Delta>', lam)`[unfolded `lam = _`]\n  have \"(\\<Delta>, body[y::=x]) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Delta>', body'[y::=x])\" by (rule rel_lam_subst)\n  from assms(11)[OF this]\n  obtain \\<Theta>' z'\n  where \"(\\<Theta>, z) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Theta>', z')\" and reds2: \"\\<Delta>' : body'[y::=x] \\<Down>\\<^bsub>L\\<^esub> \\<Theta>' : z'\" by blast\n\n  have \"atom y \\<sharp> (\\<Gamma>', e'', x, L, \\<Delta>', \\<Theta>', z')\"\n    using assms(1-7) `(\\<Gamma>, e) \\<triangleright>\\<^bsub>x # L\\<^esub> (\\<Gamma>', e'')` `(\\<Delta>, Lam [y]. body) \\<triangleright>\\<^bsub>x # L\\<^esub> (\\<Delta>', lam)` `(\\<Theta>, z) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Theta>', z')`\n    by (auto simp add: fresh_Pair)\n    \n  hence \"\\<Gamma>' :  App e'' x \\<Down>\\<^bsub>L\\<^esub> \\<Theta>' : z'\"\n    by (rule reds.Application[OF _ reds1[unfolded `lam = _`] reds2])\n  with `(\\<Theta>, z) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Theta>', z')` `e' = _`\n  show ?thesis by blast\nqed\nend\n\nlocale rel_var_cong = reds_rel + \n  assumes rel_var_cong: \"(\\<Gamma>, Var x) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', e') \\<Longrightarrow> e' = Var x\"\n\nlocale rel_var_case = rel_var_cong +\n  assumes rel_lookup: \"(\\<Gamma>, Var x) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', Var x) \\<Longrightarrow> map_of \\<Gamma> x = Some e \\<Longrightarrow> (\\<And>e'. map_of \\<Gamma>' x = Some e' \\<Longrightarrow> (delete x \\<Gamma>, e) \\<triangleright>\\<^bsub>x # L\\<^esub> (delete x \\<Gamma>', e') \\<Longrightarrow> thesis) \\<Longrightarrow>  thesis\"\n  assumes rel_add_binding: \" x \\<notin> domA \\<Delta> \\<Longrightarrow> (\\<Delta>, z) \\<triangleright>\\<^bsub>x # L\\<^esub> (\\<Delta>'', z') \\<Longrightarrow> ((x, z) # \\<Delta>, z) \\<triangleright>\\<^bsub>L\\<^esub> ((x, z') # \\<Delta>'', z')\"\nbegin\nlemma var_case:\n  fixes \\<Gamma> x e L \\<Delta> z \\<Gamma>' var\n  assumes \"map_of \\<Gamma> x = Some e\"\n  assumes \"delete x \\<Gamma> : e \\<Down>\\<^bsub>x # L\\<^esub> \\<Delta> : z\"\n  assumes \"\\<And> \\<Gamma>' e'. (delete x \\<Gamma>, e) \\<triangleright>\\<^bsub>x # L\\<^esub> (\\<Gamma>', e') \\<Longrightarrow> \\<exists>\\<Delta>'' z'. (\\<Delta>, z) \\<triangleright>\\<^bsub>x # L\\<^esub> (\\<Delta>'', z') \\<and> \\<Gamma>' : e' \\<Down>\\<^bsub>x # L\\<^esub> \\<Delta>'' : z'\"\n  assumes \"(\\<Gamma>, Var x) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', var)\"\n  shows \"\\<exists>\\<Delta>'' z'. ((x, z) # \\<Delta>, z) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Delta>'', z') \\<and> \\<Gamma>' : var \\<Down>\\<^bsub>L\\<^esub> \\<Delta>'' : z'\"\n  proof-\n    from `(\\<Gamma>, Var x) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', var)`\n    have \"var = Var x\" by (rule rel_var_cong)\n  \n    from `(\\<Gamma>, Var x) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', var)`[unfolded `var = _`]\n        and `map_of \\<Gamma> x = Some e`\n    obtain e' where \"map_of \\<Gamma>' x = Some e'\" and  \"(delete x \\<Gamma>, e) \\<triangleright>\\<^bsub>x # L\\<^esub> (delete x \\<Gamma>', e')\" by (rule rel_lookup)\n    from assms(3)[OF this(2)]\n    obtain \\<Delta>'' z'\n    where \"(\\<Delta>, z) \\<triangleright>\\<^bsub>x # L\\<^esub> (\\<Delta>'', z')\" and \"delete x \\<Gamma>' : e' \\<Down>\\<^bsub>x # L\\<^esub> \\<Delta>'' : z'\" by blast\n\n    have \"x \\<notin> domA \\<Delta>\" by (rule reds_avoids_live[OF assms(2)]) simp_all\n    with `(\\<Delta>, z) \\<triangleright>\\<^bsub>x # L\\<^esub> (\\<Delta>'', z')`\n    have \"((x,z)#\\<Delta>, z) \\<triangleright>\\<^bsub>L\\<^esub> ((x,z')#\\<Delta>'', z')\" by (rule rel_add_binding[rotated])\n    moreover\n    from  `map_of \\<Gamma>' x = Some e'` and `delete x \\<Gamma>' : e' \\<Down>\\<^bsub>x # L\\<^esub> \\<Delta>'' : z'`\n    have \"\\<Gamma>' : (Var x) \\<Down>\\<^bsub>L\\<^esub> (x,z')#\\<Delta>'' : z'\"..\n    ultimately\n    show ?thesis unfolding `var = _` by auto\n  qed\nend\n\nlocale rel_let_cong = reds_rel +\n  fixes \\<Gamma> as body\n  assumes rel_let_cong: \"(\\<Gamma>, Let as body) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', let') \\<Longrightarrow> (\\<And>as' body'. let' = Let as' body' \\<Longrightarrow> map fst as = map fst as' \\<Longrightarrow> thesis) \\<Longrightarrow> thesis\"\n\nlocale rel_let_case = rel_let_cong + reds_rel_fresh + \n  assumes rel_let:\n    \"(\\<Gamma>, Let as body) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', Let as' body') \\<Longrightarrow>\n     map fst as = map fst as' \\<Longrightarrow>\n     atom ` domA as \\<sharp>* \\<Gamma> \\<Longrightarrow>  \n     atom ` domA as \\<sharp>* L \\<Longrightarrow>  \n     (as @ \\<Gamma>, body) \\<triangleright>\\<^bsub>L\\<^esub> (as' @ \\<Gamma>', body')\"\n  (*  assumes rel_heap_subset: \" (\\<Gamma>, e) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', e'') \\<Longrightarrow> domA as' \\<subseteq> domA as\" *)\nbegin\nlemma let_case:\n  fixes L \\<Delta> z \\<Gamma>' let'\n  assumes \"atom ` domA as \\<sharp>* \\<Gamma>\"\n  assumes \"atom ` domA as \\<sharp>* L\"\n  assumes \"as @ \\<Gamma> : body \\<Down>\\<^bsub>L\\<^esub> \\<Delta> : z\"\n  assumes \"\\<And> \\<Gamma>' e' . (as @ \\<Gamma>, body) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', e') \\<Longrightarrow> \\<exists>\\<Delta>'' z'. (\\<Delta>, z) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Delta>'', z') \\<and> \\<Gamma>' : e' \\<Down>\\<^bsub>L\\<^esub> \\<Delta>'' : z'\"\n  assumes \"(\\<Gamma>, Let as body) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', let')\"\n  shows \"\\<exists>\\<Delta>'' z'. (\\<Delta>, z) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Delta>'', z') \\<and> \\<Gamma>' : let' \\<Down>\\<^bsub>L\\<^esub> \\<Delta>'' : z'\"\nproof-\n  from `(\\<Gamma>, Let as body) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', let')`\n  obtain as' body' where \"let' = Let as' body'\" and \"map fst as = map fst as'\"   by (rule rel_let_cong)\n\n  from `(\\<Gamma>, Let as body) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', let')`[unfolded `let' = _`] `map _ _ = _` assms(1,2)\n  have \"(as@\\<Gamma>, body) \\<triangleright>\\<^bsub>L\\<^esub> (as'@\\<Gamma>', body')\" by (rule rel_let)\n  from assms(4)[OF this]\n  obtain \\<Delta>' z' where \"(\\<Delta>, z) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Delta>', z')\" and \"as' @ \\<Gamma>' : body' \\<Down>\\<^bsub>L\\<^esub> \\<Delta>' : z'\" by blast\n\n  (* from `(\\<Gamma>, Let as body) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', let')`[unfolded `let' = _`] *)\n  have \"domA as' \\<subseteq> domA as\" using `map fst as = map fst as'` unfolding domA_def by (metis list.set_map order_refl)\n  hence \"atom ` domA as' \\<sharp>* (\\<Gamma>', L)\"\n    using assms(1-2) `(\\<Gamma>, Let as body) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Gamma>', let')`\n    by (auto simp add: fresh_Pair fresh_star_def)\n\n  from this `as' @ \\<Gamma>' : body' \\<Down>\\<^bsub>L\\<^esub> \\<Delta>' : z'`\n  have \"\\<Gamma>' : Let as' body' \\<Down>\\<^bsub>L\\<^esub> \\<Delta>' : z'\"\n    by (rule reds.Let)\n  with `(\\<Delta>, z) \\<triangleright>\\<^bsub>L\\<^esub> (\\<Delta>', z')`\n  show ?thesis unfolding `let' = _` by auto\nqed\nend\n\n\nend\n", "meta": {"author": "nomeata", "repo": "isa-launchbury", "sha": "2caa8d7d588e218aef1c49f2f327597af06d116e", "save_path": "github-repos/isabelle/nomeata-isa-launchbury", "path": "github-repos/isabelle/nomeata-isa-launchbury/isa-launchbury-2caa8d7d588e218aef1c49f2f327597af06d116e/Scratchpad/LaunchburyAbstractTransformation.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.2599305567145434}}
{"text": "theory R_L_Spark_User\nimports\n  R_L_Spark_Specification\n  R_L_Spark_Declaration\n  Global_User\nbegin\n\nlemma goal2'1:\n  assumes \"0 <= j''\"\n  assumes \"j'' <= 79\"\n  shows\n  \"(block_permutation___default_arr''\n    (0 := 0, 1 := 1, 2 := 2, 3 := 3, 4 := 4, 5 := 5, 6 := 6, 7 := 7,\n     8 := 8, 9 := 9, 10 := 10, 11 := 11, 12 := 12, 13 := 13, 14 := 14,\n     15 := 15, 16 := 7, 17 := 4, 18 := 13, 19 := 1, 20 := 10, 21 := 6,\n     22 := 15, 23 := 3, 24 := 12, 25 := 0, 26 := 9, 27 := 5, 28 := 2,\n     29 := 14, 30 := 11, 31 := 8, 32 := 3, 33 := 10, 34 := 14, 35 := 4,\n     36 := 9, 37 := 15, 38 := 8, 39 := 1, 40 := 2, 41 := 7, 42 := 0,\n     43 := 6, 44 := 13, 45 := 11, 46 := 5, 47 := 12, 48 := 1, 49 := 9,\n     50 := 11, 51 := 10, 52 := 0, 53 := 8, 54 := 12, 55 := 4, 56 := 13,\n     57 := 3, 58 := 7, 59 := 15, 60 := 14, 61 := 5, 62 := 6, 63 := 2,\n     64 := 4, 65 := 0, 66 := 5, 67 := 9, 68 := 7, 69 := 12, 70 := 2,\n     71 := 10, 72 := 14, 73 := 1, 74 := 3, 75 := 8, 76 := 11, 77 := 6,\n     78 := 15, 79 := 13))\n    j'' =\n   R_L_Spark_Specification.r_l' j''\"\nproof -\n  note nth_list_to_fun_eff_eq\n  moreover have \"0 <= nat j''\" by simp\n  moreover from `j'' <= 79` have \"nat j'' < length r_list\"\n    unfolding r_list_def by simp\n  ultimately have conversion:\n    \"int (r_list ! nat j'') =\n      list_to_fun_eff\n        r_list 0 block_permutation___default_arr'' (int (nat j''))\" .\n  show ?thesis\n    unfolding r_def conversion\n    unfolding r_list_def\n    using `0 <= j''` `j'' <= 79`\n    by simp\nqed\n\nlemma goal2'2:\n  assumes \"0 <= j''\"\n  assumes \"j'' <= 79\"\n  shows \"0 \\<le> (block_permutation___default_arr''\n   (0 := 0, 1 := 1, 2 := 2, 3 := 3, 4 := 4, 5 := 5, 6 := 6, 7 := 7,\n    8 := 8, 9 := 9, 10 := 10, 11 := 11, 12 := 12, 13 := 13, 14 := 14,\n    15 := 15, 16 := 7, 17 := 4, 18 := 13, 19 := 1, 20 := 10, 21 := 6,\n    22 := 15, 23 := 3, 24 := 12, 25 := 0, 26 := 9, 27 := 5, 28 := 2,\n    29 := 14, 30 := 11, 31 := 8, 32 := 3, 33 := 10, 34 := 14, 35 := 4,\n    36 := 9, 37 := 15, 38 := 8, 39 := 1, 40 := 2, 41 := 7, 42 := 0,\n    43 := 6, 44 := 13, 45 := 11, 46 := 5, 47 := 12, 48 := 1, 49 := 9,\n    50 := 11, 51 := 10, 52 := 0, 53 := 8, 54 := 12, 55 := 4, 56 := 13,\n    57 := 3, 58 := 7, 59 := 15, 60 := 14, 61 := 5, 62 := 6, 63 := 2,\n    64 := 4, 65 := 0, 66 := 5, 67 := 9, 68 := 7, 69 := 12, 70 := 2,\n    71 := 10, 72 := 14, 73 := 1, 74 := 3, 75 := 8, 76 := 11, 77 := 6,\n    78 := 15, 79 := 13))\n   j''\"\n  unfolding goal2'1[OF assms]\nby simp\n\nlemma goal2'3:\n  assumes \"0 <= j''\"\n  assumes \"j'' <= 79\"\n  shows\n   \"(block_permutation___default_arr''\n     (0 := 0, 1 := 1, 2 := 2, 3 := 3, 4 := 4, 5 := 5, 6 := 6, 7 := 7,\n      8 := 8, 9 := 9, 10 := 10, 11 := 11, 12 := 12, 13 := 13, 14 := 14,\n      15 := 15, 16 := 7, 17 := 4, 18 := 13, 19 := 1, 20 := 10, 21 := 6,\n      22 := 15, 23 := 3, 24 := 12, 25 := 0, 26 := 9, 27 := 5, 28 := 2,\n      29 := 14, 30 := 11, 31 := 8, 32 := 3, 33 := 10, 34 := 14, 35 := 4,\n      36 := 9, 37 := 15, 38 := 8, 39 := 1, 40 := 2, 41 := 7, 42 := 0,\n      43 := 6, 44 := 13, 45 := 11, 46 := 5, 47 := 12, 48 := 1, 49 := 9,\n      50 := 11, 51 := 10, 52 := 0, 53 := 8, 54 := 12, 55 := 4, 56 := 13,\n      57 := 3, 58 := 7, 59 := 15, 60 := 14, 61 := 5, 62 := 6, 63 := 2,\n      64 := 4, 65 := 0, 66 := 5, 67 := 9, 68 := 7, 69 := 12, 70 := 2,\n      71 := 10, 72 := 14, 73 := 1, 74 := 3, 75 := 8, 76 := 11, 77 := 6,\n      78 := 15, 79 := 13))\n     j''\n    \\<le> 15\"\nproof -\n  have \"r_list ! nat j'' \\<le> foldl max 0 r_list\"\n    by (insert assms, rule list_max) (simp_all add: r_list_def)\n  thus ?thesis unfolding goal2'1[OF assms] r_def\n    by (rule list_max_int) (simp_all add: assms r_list_def)\nqed\n\nlemmas userlemmas = goal2'1 goal2'2 goal2'3\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/RIPEMD-160-SPARK/R_L_Spark_User.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6150878555160665, "lm_q2_score": 0.4225046348141882, "lm_q1q2_score": 0.2598774697734578}}
{"text": "chapter\\<open>Main Theorems\\<close>\n\ntheory Hygge_Theory\nimports\n  Corecursive_Prop\n\nbegin\ntext \\<open>\n  Using the properties we have shown about the interpretation of configurations \n  and the stepwise unfolding of the denotational semantics, we can now prove \n  several important results about the construction of runs from a specification.\n\\<close>\nsection \\<open>Initial configuration\\<close>\n\ntext \\<open>\n  The denotational semantics of a specification @{term \\<open>\\<Psi>\\<close>} is the interpretation \n  at the first instant of a configuration which has @{term \\<open>\\<Psi>\\<close>} as its present.\n  This means that we can start to build a run that satisfies a specification by \n  starting from this configuration.\n\\<close>\n\n\nsection \\<open>Soundness\\<close>\ntext \\<open>\n  The interpretation of a configuration @{term \\<open>\\<S>\\<^sub>2\\<close>} that is a refinement of a\n  configuration @{term \\<open>\\<S>\\<^sub>1\\<close>} is contained in the interpretation of @{term \\<open>\\<S>\\<^sub>1\\<close>}.\n  This means that by making successive choices in building the instants of a run,\n  we preserve the soundness of the constructed run with regard to the original \n  specification.\n\\<close>\nlemma sound_reduction:\n  assumes \\<open>(\\<Gamma>\\<^sub>1, n\\<^sub>1 \\<turnstile> \\<Psi>\\<^sub>1 \\<triangleright> \\<Phi>\\<^sub>1)  \\<hookrightarrow>  (\\<Gamma>\\<^sub>2, n\\<^sub>2 \\<turnstile> \\<Psi>\\<^sub>2 \\<triangleright> \\<Phi>\\<^sub>2)\\<close>\n  shows \\<open>\\<lbrakk>\\<lbrakk> \\<Gamma>\\<^sub>1 \\<rbrakk>\\<rbrakk>\\<^sub>p\\<^sub>r\\<^sub>i\\<^sub>m \\<inter> \\<lbrakk>\\<lbrakk> \\<Psi>\\<^sub>1 \\<rbrakk>\\<rbrakk>\\<^sub>T\\<^sub>E\\<^sub>S\\<^sub>L\\<^bsup>\\<ge> n\\<^sub>1\\<^esup> \\<inter> \\<lbrakk>\\<lbrakk> \\<Phi>\\<^sub>1 \\<rbrakk>\\<rbrakk>\\<^sub>T\\<^sub>E\\<^sub>S\\<^sub>L\\<^bsup>\\<ge> Suc n\\<^sub>1\\<^esup>\n          \\<supseteq>  \\<lbrakk>\\<lbrakk> \\<Gamma>\\<^sub>2 \\<rbrakk>\\<rbrakk>\\<^sub>p\\<^sub>r\\<^sub>i\\<^sub>m \\<inter> \\<lbrakk>\\<lbrakk> \\<Psi>\\<^sub>2 \\<rbrakk>\\<rbrakk>\\<^sub>T\\<^sub>E\\<^sub>S\\<^sub>L\\<^bsup>\\<ge> n\\<^sub>2\\<^esup> \\<inter> \\<lbrakk>\\<lbrakk> \\<Phi>\\<^sub>2 \\<rbrakk>\\<rbrakk>\\<^sub>T\\<^sub>E\\<^sub>S\\<^sub>L\\<^bsup>\\<ge> Suc n\\<^sub>2\\<^esup>\\<close> (is ?P)\nproof -\n  from assms consider\n    (a) \\<open>(\\<Gamma>\\<^sub>1, n\\<^sub>1 \\<turnstile> \\<Psi>\\<^sub>1 \\<triangleright> \\<Phi>\\<^sub>1)  \\<hookrightarrow>\\<^sub>i  (\\<Gamma>\\<^sub>2, n\\<^sub>2 \\<turnstile> \\<Psi>\\<^sub>2 \\<triangleright> \\<Phi>\\<^sub>2)\\<close>\n  | (b) \\<open>(\\<Gamma>\\<^sub>1, n\\<^sub>1 \\<turnstile> \\<Psi>\\<^sub>1 \\<triangleright> \\<Phi>\\<^sub>1)  \\<hookrightarrow>\\<^sub>e  (\\<Gamma>\\<^sub>2, n\\<^sub>2 \\<turnstile> \\<Psi>\\<^sub>2 \\<triangleright> \\<Phi>\\<^sub>2)\\<close>\n    using operational_semantics_step.simps by blast\n  thus ?thesis\n  proof (cases)\n    case a\n      thus ?thesis by (simp add: operational_semantics_intro.simps)\n  next\n    case b thus ?thesis\n    proof (rule operational_semantics_elim.cases)\n      fix  \\<Gamma> n K\\<^sub>1 \\<tau> K\\<^sub>2 \\<Psi> \\<Phi>\n      assume \\<open>(\\<Gamma>\\<^sub>1, n\\<^sub>1 \\<turnstile> \\<Psi>\\<^sub>1 \\<triangleright> \\<Phi>\\<^sub>1) = (\\<Gamma>, n \\<turnstile> (K\\<^sub>1 sporadic \\<tau> on K\\<^sub>2) # \\<Psi> \\<triangleright> \\<Phi>)\\<close>\n      and \\<open>(\\<Gamma>\\<^sub>2, n\\<^sub>2 \\<turnstile> \\<Psi>\\<^sub>2 \\<triangleright> \\<Phi>\\<^sub>2) = (\\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 sporadic \\<tau> on K\\<^sub>2) # \\<Phi>))\\<close>\n      thus ?P using HeronConf_interp_stepwise_sporadicon_cases\n                    HeronConf_interpretation.simps by blast\n    next\n      fix  \\<Gamma> n K\\<^sub>1 \\<tau> K\\<^sub>2 \\<Psi> \\<Phi>\n      assume \\<open>(\\<Gamma>\\<^sub>1, n\\<^sub>1 \\<turnstile> \\<Psi>\\<^sub>1 \\<triangleright> \\<Phi>\\<^sub>1) = (\\<Gamma>, n \\<turnstile> (K\\<^sub>1 sporadic \\<tau> on K\\<^sub>2) # \\<Psi> \\<triangleright> \\<Phi>)\\<close>\n      and \\<open>(\\<Gamma>\\<^sub>2, n\\<^sub>2 \\<turnstile> \\<Psi>\\<^sub>2 \\<triangleright> \\<Phi>\\<^sub>2) = (((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<Down> n @ \\<tau>) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi>)\\<close>\n      thus ?P using HeronConf_interp_stepwise_sporadicon_cases\n                    HeronConf_interpretation.simps by blast\n    next\n      fix \\<Gamma> n K\\<^sub>1 K\\<^sub>2 R \\<Psi> \\<Phi>\n      assume \\<open>(\\<Gamma>\\<^sub>1, n\\<^sub>1 \\<turnstile> \\<Psi>\\<^sub>1 \\<triangleright> \\<Phi>\\<^sub>1) = (\\<Gamma>, n \\<turnstile> (time-relation \\<lfloor>K\\<^sub>1, K\\<^sub>2\\<rfloor> \\<in> R) # \\<Psi> \\<triangleright> \\<Phi>)\\<close>\n      and \\<open>(\\<Gamma>\\<^sub>2, n\\<^sub>2 \\<turnstile> \\<Psi>\\<^sub>2 \\<triangleright> \\<Phi>\\<^sub>2) = (((\\<lfloor>\\<tau>\\<^sub>v\\<^sub>a\\<^sub>r (K\\<^sub>1, n), \\<tau>\\<^sub>v\\<^sub>a\\<^sub>r (K\\<^sub>2, n)\\<rfloor> \\<in> R) # \\<Gamma>), n\n                                      \\<turnstile> \\<Psi> \\<triangleright> ((time-relation \\<lfloor>K\\<^sub>1, K\\<^sub>2\\<rfloor> \\<in> R) # \\<Phi>))\\<close>\n      thus ?P using HeronConf_interp_stepwise_tagrel_cases\n                    HeronConf_interpretation.simps by blast\n    next\n      fix \\<Gamma> n K\\<^sub>1 K\\<^sub>2 \\<Psi> \\<Phi>\n      assume \\<open>(\\<Gamma>\\<^sub>1, n\\<^sub>1 \\<turnstile> \\<Psi>\\<^sub>1 \\<triangleright> \\<Phi>\\<^sub>1) = (\\<Gamma>, n \\<turnstile> (K\\<^sub>1 implies K\\<^sub>2) # \\<Psi> \\<triangleright> \\<Phi>)\\<close>\n      and \\<open>(\\<Gamma>\\<^sub>2, n\\<^sub>2 \\<turnstile> \\<Psi>\\<^sub>2 \\<triangleright> \\<Phi>\\<^sub>2) = (((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies K\\<^sub>2) # \\<Phi>))\\<close>\n      thus ?P using HeronConf_interp_stepwise_implies_cases\n                    HeronConf_interpretation.simps by blast\n    next\n      fix \\<Gamma> n K\\<^sub>1 K\\<^sub>2 \\<Psi> \\<Phi>\n      assume \\<open>(\\<Gamma>\\<^sub>1, n\\<^sub>1 \\<turnstile> \\<Psi>\\<^sub>1 \\<triangleright> \\<Phi>\\<^sub>1) = (\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 implies K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\\<close>\n      and \\<open>(\\<Gamma>\\<^sub>2, n\\<^sub>2 \\<turnstile> \\<Psi>\\<^sub>2 \\<triangleright> \\<Phi>\\<^sub>2) = (((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<Up> n) # \\<Gamma>), n\n                                   \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies K\\<^sub>2) # \\<Phi>))\\<close>\n      thus ?P using HeronConf_interp_stepwise_implies_cases\n                    HeronConf_interpretation.simps by blast\n    next\n      fix \\<Gamma> n K\\<^sub>1 K\\<^sub>2 \\<Psi> \\<Phi>\n      assume \\<open>(\\<Gamma>\\<^sub>1, n\\<^sub>1 \\<turnstile> \\<Psi>\\<^sub>1 \\<triangleright> \\<Phi>\\<^sub>1) = (\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\\<close>\n      and \\<open>(\\<Gamma>\\<^sub>2, n\\<^sub>2 \\<turnstile> \\<Psi>\\<^sub>2 \\<triangleright> \\<Phi>\\<^sub>2) = (((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Phi>))\\<close>\n      thus ?P using HeronConf_interp_stepwise_implies_not_cases\n                    HeronConf_interpretation.simps by blast\n    next\n      fix \\<Gamma> n K\\<^sub>1 K\\<^sub>2 \\<Psi> \\<Phi>\n      assume \\<open>(\\<Gamma>\\<^sub>1, n\\<^sub>1 \\<turnstile> \\<Psi>\\<^sub>1 \\<triangleright> \\<Phi>\\<^sub>1) = (\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\\<close>\n      and \\<open>(\\<Gamma>\\<^sub>2, n\\<^sub>2 \\<turnstile> \\<Psi>\\<^sub>2 \\<triangleright> \\<Phi>\\<^sub>2) = (((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<not>\\<Up> n) # \\<Gamma>), n\n                                   \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Phi>))\\<close>\n      thus ?P using HeronConf_interp_stepwise_implies_not_cases\n                    HeronConf_interpretation.simps by blast\n    next\n      fix \\<Gamma> n K\\<^sub>1 \\<delta>\\<tau> K\\<^sub>2 K\\<^sub>3 \\<Psi> \\<Phi>\n      assume \\<open>(\\<Gamma>\\<^sub>1, n\\<^sub>1 \\<turnstile> \\<Psi>\\<^sub>1 \\<triangleright> \\<Phi>\\<^sub>1) =\n                (\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Psi>) \\<triangleright> \\<Phi>)\\<close>\n      and \\<open>(\\<Gamma>\\<^sub>2, n\\<^sub>2 \\<turnstile> \\<Psi>\\<^sub>2 \\<triangleright> \\<Phi>\\<^sub>2) =\n            (((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Phi>))\\<close>\n      thus ?P using HeronConf_interp_stepwise_timedelayed_cases\n                    HeronConf_interpretation.simps by blast\n    next\n      fix \\<Gamma> n K\\<^sub>1 \\<delta>\\<tau> K\\<^sub>2 K\\<^sub>3 \\<Psi> \\<Phi>\n      assume \\<open>(\\<Gamma>\\<^sub>1, n\\<^sub>1 \\<turnstile> \\<Psi>\\<^sub>1 \\<triangleright> \\<Phi>\\<^sub>1) =\n               (\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Psi>) \\<triangleright> \\<Phi>)\\<close>\n      and \\<open>(\\<Gamma>\\<^sub>2, n\\<^sub>2 \\<turnstile> \\<Psi>\\<^sub>2 \\<triangleright> \\<Phi>\\<^sub>2)\n            = (((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 @ n \\<oplus> \\<delta>\\<tau> \\<Rightarrow> K\\<^sub>3) # \\<Gamma>), n\n                \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Phi>))\\<close>\n      thus ?P using HeronConf_interp_stepwise_timedelayed_cases\n                    HeronConf_interpretation.simps by blast\n    next\n      fix \\<Gamma> n K\\<^sub>1 K\\<^sub>2 \\<Psi> \\<Phi>\n      assume \\<open>(\\<Gamma>\\<^sub>1, n\\<^sub>1 \\<turnstile> \\<Psi>\\<^sub>1 \\<triangleright> \\<Phi>\\<^sub>1) = (\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 weakly precedes K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\\<close>\n      and \\<open>(\\<Gamma>\\<^sub>2, n\\<^sub>2 \\<turnstile> \\<Psi>\\<^sub>2 \\<triangleright> \\<Phi>\\<^sub>2) = (((\\<lceil>#\\<^sup>\\<le> K\\<^sub>2 n, #\\<^sup>\\<le> K\\<^sub>1 n\\<rceil> \\<in> (\\<lambda>(x, y). x \\<le> y)) # \\<Gamma>), n\n                                  \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 weakly precedes K\\<^sub>2) # \\<Phi>))\\<close>\n      thus ?P using HeronConf_interp_stepwise_weakly_precedes_cases\n                    HeronConf_interpretation.simps by blast\n    next\n      fix \\<Gamma> n K\\<^sub>1 K\\<^sub>2 \\<Psi> \\<Phi>\n      assume \\<open>(\\<Gamma>\\<^sub>1, n\\<^sub>1 \\<turnstile> \\<Psi>\\<^sub>1 \\<triangleright> \\<Phi>\\<^sub>1) = (\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 strictly precedes K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\\<close>\n      and \\<open>(\\<Gamma>\\<^sub>2, n\\<^sub>2 \\<turnstile> \\<Psi>\\<^sub>2 \\<triangleright> \\<Phi>\\<^sub>2) = (((\\<lceil>#\\<^sup>\\<le> K\\<^sub>2 n, #\\<^sup>< K\\<^sub>1 n\\<rceil> \\<in> (\\<lambda>(x, y). x \\<le> y)) # \\<Gamma>), n\n                                  \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 strictly precedes K\\<^sub>2) # \\<Phi>))\\<close>\n      thus ?P using HeronConf_interp_stepwise_strictly_precedes_cases\n                    HeronConf_interpretation.simps by blast\n    next\n      fix \\<Gamma> n K\\<^sub>1 K\\<^sub>2 \\<Psi> \\<Phi>\n      assume \\<open>(\\<Gamma>\\<^sub>1, n\\<^sub>1 \\<turnstile> \\<Psi>\\<^sub>1 \\<triangleright> \\<Phi>\\<^sub>1) = (\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 kills K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\\<close>\n      and \\<open>(\\<Gamma>\\<^sub>2, n\\<^sub>2 \\<turnstile> \\<Psi>\\<^sub>2 \\<triangleright> \\<Phi>\\<^sub>2) = (((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 kills K\\<^sub>2) # \\<Phi>))\\<close>\n      thus ?P using HeronConf_interp_stepwise_kills_cases\n                    HeronConf_interpretation.simps by blast\n    next\n      fix \\<Gamma> n K\\<^sub>1 K\\<^sub>2 \\<Psi> \\<Phi>\n      assume \\<open>(\\<Gamma>\\<^sub>1, n\\<^sub>1 \\<turnstile> \\<Psi>\\<^sub>1 \\<triangleright> \\<Phi>\\<^sub>1) = (\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 kills K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\\<close>\n      and \\<open>(\\<Gamma>\\<^sub>2, n\\<^sub>2 \\<turnstile> \\<Psi>\\<^sub>2 \\<triangleright> \\<Phi>\\<^sub>2) =\n            (((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<not>\\<Up> \\<ge> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 kills K\\<^sub>2) # \\<Phi>))\\<close>\n      thus ?P using HeronConf_interp_stepwise_kills_cases\n                    HeronConf_interpretation.simps by blast\n    qed\n  qed\nqed\n\ninductive_cases step_elim:\\<open>\\<S>\\<^sub>1 \\<hookrightarrow> \\<S>\\<^sub>2\\<close>\n\nlemma sound_reduction':\n  assumes \\<open>\\<S>\\<^sub>1 \\<hookrightarrow> \\<S>\\<^sub>2\\<close>\n  shows \\<open>\\<lbrakk> \\<S>\\<^sub>1 \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g \\<supseteq> \\<lbrakk> \\<S>\\<^sub>2 \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\nproof -\n  have \\<open>\\<forall>s\\<^sub>1 s\\<^sub>2. (\\<lbrakk> s\\<^sub>2 \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g \\<subseteq> \\<lbrakk> s\\<^sub>1 \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g) \\<or> \\<not>(s\\<^sub>1 \\<hookrightarrow> s\\<^sub>2)\\<close>\n    using sound_reduction by fastforce\n  thus ?thesis using assms by blast\nqed\n\nlemma sound_reduction_generalized:\n  assumes \\<open>\\<S>\\<^sub>1 \\<hookrightarrow>\\<^bsup>k\\<^esup> \\<S>\\<^sub>2\\<close>\n    shows \\<open>\\<lbrakk> \\<S>\\<^sub>1 \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g \\<supseteq> \\<lbrakk> \\<S>\\<^sub>2 \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\nproof -\n  from assms show ?thesis\n  proof (induction k arbitrary: \\<S>\\<^sub>2)\n    case 0\n      hence *: \\<open>\\<S>\\<^sub>1 \\<hookrightarrow>\\<^bsup>0\\<^esup> \\<S>\\<^sub>2 \\<Longrightarrow> \\<S>\\<^sub>1 = \\<S>\\<^sub>2\\<close> by auto\n      moreover have \\<open>\\<S>\\<^sub>1 = \\<S>\\<^sub>2\\<close> using * \"0.prems\" by linarith\n      ultimately show ?case by auto\n  next\n    case (Suc k)\n      thus ?case\n      proof -\n        fix k :: nat\n        assume ff: \\<open>\\<S>\\<^sub>1 \\<hookrightarrow>\\<^bsup>Suc k\\<^esup> \\<S>\\<^sub>2\\<close>\n        assume hi: \\<open>\\<And>\\<S>\\<^sub>2. \\<S>\\<^sub>1 \\<hookrightarrow>\\<^bsup>k\\<^esup> \\<S>\\<^sub>2 \\<Longrightarrow> \\<lbrakk> \\<S>\\<^sub>2 \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g \\<subseteq> \\<lbrakk> \\<S>\\<^sub>1 \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        obtain \\<S>\\<^sub>n where red_decomp: \\<open>(\\<S>\\<^sub>1 \\<hookrightarrow>\\<^bsup>k\\<^esup> \\<S>\\<^sub>n) \\<and> (\\<S>\\<^sub>n \\<hookrightarrow> \\<S>\\<^sub>2)\\<close> using ff by auto\n        hence \\<open>\\<lbrakk> \\<S>\\<^sub>1 \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g \\<supseteq> \\<lbrakk> \\<S>\\<^sub>n \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close> using hi by simp\n        also have \\<open>\\<lbrakk> \\<S>\\<^sub>n \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g \\<supseteq> \\<lbrakk> \\<S>\\<^sub>2 \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close> by (simp add: red_decomp sound_reduction')\n        ultimately show \\<open>\\<lbrakk> \\<S>\\<^sub>1 \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g \\<supseteq> \\<lbrakk> \\<S>\\<^sub>2 \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close> by simp\n      qed\n  qed\nqed\n\ntext \\<open>\n  From the initial configuration, a configuration @{term \\<open>\\<S>\\<close>} obtained after any \n  number @{term \\<open>k\\<close>} of reduction steps denotes runs from the \n  initial specification @{term \\<open>\\<Psi>\\<close>}.\n\\<close>\ntheorem soundness:\n  assumes \\<open>([], 0 \\<turnstile> \\<Psi> \\<triangleright> []) \\<hookrightarrow>\\<^bsup>k\\<^esup> \\<S>\\<close>\n    shows \\<open>\\<lbrakk>\\<lbrakk> \\<Psi> \\<rbrakk>\\<rbrakk>\\<^sub>T\\<^sub>E\\<^sub>S\\<^sub>L \\<supseteq> \\<lbrakk> \\<S> \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n  using assms sound_reduction_generalized solve_start by blast\n\nsection \\<open>Completeness\\<close>\n\ntext \\<open>\n  We will now show that any run that satisfies a specification can be derived\n  from the initial configuration, at any number of steps.\n\n  We start by proving that any run that is denoted by a configuration @{term \\<open>\\<S>\\<close>}\n  is necessarily denoted by at least one of the configurations that can be reached\n  from @{term \\<open>\\<S>\\<close>}.\n\\<close>\nlemma complete_direct_successors:\n  shows \\<open>\\<lbrakk> \\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi> \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g \\<subseteq> (\\<Union>X\\<in>\\<C>\\<^sub>n\\<^sub>e\\<^sub>x\\<^sub>t (\\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi>). \\<lbrakk> X \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g)\\<close>\n  proof (induct \\<Psi>)\n    case Nil\n    show ?case\n      using HeronConf_interp_stepwise_instant_cases operational_semantics_step.simps\n            operational_semantics_intro.instant_i\n      by fastforce\n  next\n    case (Cons \\<psi> \\<Psi>)  thus ?case\n      proof (cases \\<psi>)\n        case (SporadicOn K1 \\<tau> K2) thus ?thesis \n          using HeronConf_interp_stepwise_sporadicon_cases\n                                      [of \\<open>\\<Gamma>\\<close> \\<open>n\\<close> \\<open>K1\\<close> \\<open>\\<tau>\\<close> \\<open>K2\\<close> \\<open>\\<Psi>\\<close> \\<open>\\<Phi>\\<close>]\n                Cnext_solve_sporadicon[of \\<open>\\<Gamma>\\<close> \\<open>n\\<close> \\<open>\\<Psi>\\<close> \\<open>K1\\<close> \\<open>\\<tau>\\<close> \\<open>K2\\<close> \\<open>\\<Phi>\\<close>] by blast\n      next\n        case (TagRelation K\\<^sub>1 K\\<^sub>2 R) thus ?thesis\n          using HeronConf_interp_stepwise_tagrel_cases\n                                  [of \\<open>\\<Gamma>\\<close> \\<open>n\\<close> \\<open>K\\<^sub>1\\<close> \\<open>K\\<^sub>2\\<close> \\<open>R\\<close> \\<open>\\<Psi>\\<close> \\<open>\\<Phi>\\<close>]\n                Cnext_solve_tagrel[of \\<open>K\\<^sub>1\\<close> \\<open>n\\<close> \\<open>K\\<^sub>2\\<close> \\<open>R\\<close> \\<open>\\<Gamma>\\<close> \\<open>\\<Psi>\\<close> \\<open>\\<Phi>\\<close>] by blast\n      next\n        case (Implies K1 K2) thus ?thesis\n          using HeronConf_interp_stepwise_implies_cases\n                                   [of \\<open>\\<Gamma>\\<close> \\<open>n\\<close> \\<open>K1\\<close> \\<open>K2\\<close> \\<open>\\<Psi>\\<close> \\<open>\\<Phi>\\<close>]\n                Cnext_solve_implies[of \\<open>K1\\<close> \\<open>n\\<close> \\<open>\\<Gamma>\\<close> \\<open>\\<Psi>\\<close> \\<open>K2\\<close> \\<open>\\<Phi>\\<close>] by blast\n      next\n        case (ImpliesNot K1 K2) thus ?thesis\n          using HeronConf_interp_stepwise_implies_not_cases\n                                       [of \\<open>\\<Gamma>\\<close> \\<open>n\\<close> \\<open>K1\\<close> \\<open>K2\\<close> \\<open>\\<Psi>\\<close> \\<open>\\<Phi>\\<close>]\n                Cnext_solve_implies_not[of \\<open>K1\\<close> \\<open>n\\<close> \\<open>\\<Gamma>\\<close> \\<open>\\<Psi>\\<close> \\<open>K2\\<close> \\<open>\\<Phi>\\<close>] by blast\n      next\n        case (TimeDelayedBy Kmast \\<tau> Kmeas Kslave) thus ?thesis\n          using HeronConf_interp_stepwise_timedelayed_cases\n                          [of \\<open>\\<Gamma>\\<close> \\<open>n\\<close> \\<open>Kmast\\<close> \\<open>\\<tau>\\<close> \\<open>Kmeas\\<close> \\<open>Kslave\\<close> \\<open>\\<Psi>\\<close> \\<open>\\<Phi>\\<close>]\n                Cnext_solve_timedelayed\n                          [of \\<open>Kmast\\<close> \\<open>n\\<close> \\<open>\\<Gamma>\\<close> \\<open>\\<Psi>\\<close> \\<open>\\<tau>\\<close> \\<open>Kmeas\\<close> \\<open>Kslave\\<close> \\<open>\\<Phi>\\<close>] by blast\n      next\n        case (WeaklyPrecedes K1 K2) thus ?thesis\n          using HeronConf_interp_stepwise_weakly_precedes_cases\n                                           [of \\<open>\\<Gamma>\\<close> \\<open>n\\<close> \\<open>K1\\<close> \\<open>K2\\<close> \\<open>\\<Psi>\\<close> \\<open>\\<Phi>\\<close>]\n                Cnext_solve_weakly_precedes[of \\<open>K2\\<close> \\<open>n\\<close> \\<open>K1\\<close> \\<open>\\<Gamma>\\<close> \\<open>\\<Psi>\\<close>  \\<open>\\<Phi>\\<close>]\n          by blast\n      next\n        case (StrictlyPrecedes K1 K2)  thus ?thesis\n          using HeronConf_interp_stepwise_strictly_precedes_cases\n                                             [of \\<open>\\<Gamma>\\<close> \\<open>n\\<close> \\<open>K1\\<close> \\<open>K2\\<close> \\<open>\\<Psi>\\<close> \\<open>\\<Phi>\\<close>]\n                Cnext_solve_strictly_precedes[of \\<open>K2\\<close> \\<open>n\\<close> \\<open>K1\\<close> \\<open>\\<Gamma>\\<close> \\<open>\\<Psi>\\<close>  \\<open>\\<Phi>\\<close>]\n          by blast\n      next\n        case (Kills K1 K2) thus ?thesis\n          using HeronConf_interp_stepwise_kills_cases[of \\<open>\\<Gamma>\\<close> \\<open>n\\<close> \\<open>K1\\<close> \\<open>K2\\<close> \\<open>\\<Psi>\\<close> \\<open>\\<Phi>\\<close>]\n                Cnext_solve_kills[of \\<open>K1\\<close> \\<open>n\\<close> \\<open>\\<Gamma>\\<close> \\<open>\\<Psi>\\<close> \\<open>K2\\<close> \\<open>\\<Phi>\\<close>] by blast\n      qed\n  qed\n\nlemma complete_direct_successors':\n  shows \\<open>\\<lbrakk> \\<S> \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g \\<subseteq> (\\<Union>X\\<in>\\<C>\\<^sub>n\\<^sub>e\\<^sub>x\\<^sub>t \\<S>. \\<lbrakk> X \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g)\\<close>\nproof -\n  from HeronConf_interpretation.cases obtain \\<Gamma> n \\<Psi> \\<Phi>\n    where \\<open>\\<S> = (\\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi>)\\<close> by blast\n  with complete_direct_successors[of \\<open>\\<Gamma>\\<close> \\<open>n\\<close> \\<open>\\<Psi>\\<close> \\<open>\\<Phi>\\<close>] show ?thesis by simp\nqed\n\ntext \\<open>\n  Therefore, if a run belongs to a configuration, it necessarily belongs to a\n  configuration derived from it.\n\\<close>\nlemma branch_existence:\n  assumes \\<open>\\<rho> \\<in> \\<lbrakk> \\<S>\\<^sub>1 \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n  shows \\<open>\\<exists>\\<S>\\<^sub>2. (\\<S>\\<^sub>1 \\<hookrightarrow> \\<S>\\<^sub>2) \\<and> (\\<rho> \\<in> \\<lbrakk> \\<S>\\<^sub>2 \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g)\\<close>\nproof -\n  from assms complete_direct_successors' have \\<open>\\<rho> \\<in> (\\<Union>X\\<in>\\<C>\\<^sub>n\\<^sub>e\\<^sub>x\\<^sub>t \\<S>\\<^sub>1. \\<lbrakk> X \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g)\\<close> by blast\n  hence \\<open>\\<exists>s\\<in>\\<C>\\<^sub>n\\<^sub>e\\<^sub>x\\<^sub>t \\<S>\\<^sub>1. \\<rho> \\<in> \\<lbrakk> s \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close> by simp\n  thus ?thesis by blast\nqed\n\nlemma branch_existence':\n  assumes \\<open>\\<rho> \\<in> \\<lbrakk> \\<S>\\<^sub>1 \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n  shows \\<open>\\<exists>\\<S>\\<^sub>2. (\\<S>\\<^sub>1 \\<hookrightarrow>\\<^bsup>k\\<^esup> \\<S>\\<^sub>2) \\<and> (\\<rho> \\<in> \\<lbrakk> \\<S>\\<^sub>2 \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g)\\<close>\nproof (induct k)\n  case 0\n    thus ?case by (simp add: assms)\nnext\n  case (Suc k)\n    thus ?case\n      using branch_existence relpowp_Suc_I[of \\<open>k\\<close> \\<open>operational_semantics_step\\<close>]\n    by blast\nqed\n\ntext\\<open>\n  Any run that belongs to the original specification @{term \\<open>\\<Psi>\\<close>} has a corresponding \n  configuration @{term \\<open>\\<S>\\<close>} at any number @{term \\<open>k\\<close>} of reduction steps\n  from the initial configuration. Therefore, any run that satisfies a specification\n  can be derived from the initial configuration at any level of reduction.\n\\<close>\ntheorem completeness:\n  assumes \\<open>\\<rho> \\<in> \\<lbrakk>\\<lbrakk> \\<Psi> \\<rbrakk>\\<rbrakk>\\<^sub>T\\<^sub>E\\<^sub>S\\<^sub>L\\<close>\n  shows \\<open>\\<exists>\\<S>. (([], 0 \\<turnstile> \\<Psi> \\<triangleright> [])  \\<hookrightarrow>\\<^bsup>k\\<^esup>  \\<S>)\n           \\<and> \\<rho> \\<in> \\<lbrakk> \\<S> \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n  using assms branch_existence' solve_start by blast\n\nsection \\<open>Progress\\<close>\n\ntext \\<open>\n  Reduction steps do not guarantee that the construction of a run progresses in the\n  sequence of instants. We need to show that it is always possible to reach the next \n  instant, and therefore any future instant, through a number of steps.\n\\<close>\nlemma instant_index_increase:\n  assumes \\<open>\\<rho> \\<in> \\<lbrakk> \\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi> \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n  shows   \\<open>\\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k. ((\\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi>)  \\<hookrightarrow>\\<^bsup>k\\<^esup>  (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                         \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\nproof (insert assms, induct \\<Psi> arbitrary: \\<Gamma> \\<Phi>)\n  case (Nil \\<Gamma> \\<Phi>)\n    then show ?case\n    proof -\n      have \\<open>(\\<Gamma>, n \\<turnstile> [] \\<triangleright> \\<Phi>) \\<hookrightarrow>\\<^bsup>1\\<^esup> (\\<Gamma>, Suc n \\<turnstile> \\<Phi> \\<triangleright> [])\\<close>\n        using instant_i intro_part by fastforce\n      moreover have \\<open>\\<lbrakk> \\<Gamma>, n \\<turnstile> [] \\<triangleright> \\<Phi> \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g = \\<lbrakk> \\<Gamma>, Suc n \\<turnstile> \\<Phi> \\<triangleright> [] \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        by auto\n      moreover have \\<open>\\<rho> \\<in> \\<lbrakk> \\<Gamma>, Suc n \\<turnstile> \\<Phi> \\<triangleright> [] \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        using assms Nil.prems calculation(2) by blast\n      ultimately show ?thesis by blast\n    qed\nnext\n  case (Cons \\<psi> \\<Psi>)\n    then show ?case\n    proof (induct \\<psi>)\n      case (SporadicOn K\\<^sub>1 \\<tau> K\\<^sub>2)\n        have branches: \\<open>\\<lbrakk> \\<Gamma>, n \\<turnstile> ((K\\<^sub>1 sporadic \\<tau> on K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi> \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n                      = \\<lbrakk> \\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 sporadic \\<tau> on K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n                      \\<union> \\<lbrakk> ((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<Down> n @ \\<tau>) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi> \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n          using HeronConf_interp_stepwise_sporadicon_cases by simp\n        have br1: \\<open>\\<rho> \\<in> \\<lbrakk> \\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 sporadic \\<tau> on K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n                    \\<Longrightarrow> \\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k.\n                      ((\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 sporadic \\<tau> on K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n                          \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                      \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        proof -\n          assume h1: \\<open>\\<rho> \\<in> \\<lbrakk> \\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 sporadic \\<tau> on K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n          hence \\<open>\\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k. ((\\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 sporadic \\<tau> on K\\<^sub>2) # \\<Phi>))\n                                      \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                                 \\<and> (\\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g)\\<close>\n            using h1 SporadicOn.prems by simp\n          from this obtain \\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k where\n              fp:\\<open>((\\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 sporadic \\<tau> on K\\<^sub>2) # \\<Phi>))\n                    \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close> by blast\n          have\n            \\<open>(\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 sporadic \\<tau> on K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n              \\<hookrightarrow> (\\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 sporadic \\<tau> on K\\<^sub>2) # \\<Phi>))\\<close>\n            by (simp add: elims_part sporadic_on_e1)\n          with fp relpowp_Suc_I2 have\n            \\<open>((\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 sporadic \\<tau> on K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n              \\<hookrightarrow>\\<^bsup>Suc k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\\<close> by auto\n          thus ?thesis using fp by blast\n        qed\n        have br2: \\<open>\\<rho> \\<in> \\<lbrakk> ((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<Down> n @ \\<tau>) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi> \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n                  \\<Longrightarrow> \\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k. ((\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 sporadic \\<tau> on K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n                                        \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                            \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        proof -\n          assume h2: \\<open>\\<rho> \\<in> \\<lbrakk> ((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<Down> n @ \\<tau>) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi> \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n          hence \\<open>\\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k. ((((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<Down> n @ \\<tau>) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi>)\n                                    \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                             \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n            using h2 SporadicOn.prems by simp\n\n            from this obtain \\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k\n            where fp:\\<open>((((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<Down> n @ \\<tau>) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi>)\n                            \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\\<close>\n              and rc:\\<open>\\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close> by blast\n            have pc:\\<open>(\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 sporadic \\<tau> on K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n              \\<hookrightarrow> (((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<Down> n @ \\<tau>) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi>)\\<close>\n            by (simp add: elims_part sporadic_on_e2)\n            hence \\<open>(\\<Gamma>, n \\<turnstile> (K\\<^sub>1 sporadic \\<tau> on K\\<^sub>2) # \\<Psi> \\<triangleright> \\<Phi>)\n                    \\<hookrightarrow>\\<^bsup>Suc k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\\<close>\n                using fp relpowp_Suc_I2 by auto\n            with rc show ?thesis by blast\n        qed\n        from branches SporadicOn.prems(2) have\n          \\<open>\\<rho> \\<in> \\<lbrakk> \\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 sporadic \\<tau> on K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n             \\<union> \\<lbrakk> ((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<Down> n @ \\<tau>) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi> \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n          by simp\n        with br1 br2 show ?case by blast\n  next\n    case (TagRelation K\\<^sub>1 K\\<^sub>2 R)\n      have branches: \\<open>\\<lbrakk> \\<Gamma>, n \\<turnstile> ((time-relation \\<lfloor>K\\<^sub>1, K\\<^sub>2\\<rfloor> \\<in> R) # \\<Psi>) \\<triangleright> \\<Phi> \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n          = \\<lbrakk> ((\\<lfloor>\\<tau>\\<^sub>v\\<^sub>a\\<^sub>r(K\\<^sub>1, n), \\<tau>\\<^sub>v\\<^sub>a\\<^sub>r(K\\<^sub>2, n)\\<rfloor> \\<in> R) # \\<Gamma>), n\n              \\<turnstile> \\<Psi> \\<triangleright> ((time-relation \\<lfloor>K\\<^sub>1, K\\<^sub>2\\<rfloor> \\<in> R) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        using HeronConf_interp_stepwise_tagrel_cases by simp\n      thus ?case\n      proof -\n        have \\<open>\\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k.\n            ((((\\<lfloor>\\<tau>\\<^sub>v\\<^sub>a\\<^sub>r(K\\<^sub>1, n), \\<tau>\\<^sub>v\\<^sub>a\\<^sub>r(K\\<^sub>2, n)\\<rfloor> \\<in> R) # \\<Gamma>), n\n                \\<turnstile> \\<Psi> \\<triangleright> ((time-relation \\<lfloor>K\\<^sub>1, K\\<^sub>2\\<rfloor> \\<in> R) # \\<Phi>))\n              \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)) \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n          using TagRelation.prems by simp\n\n        from this obtain \\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k\n          where fp:\\<open>((((\\<lfloor>\\<tau>\\<^sub>v\\<^sub>a\\<^sub>r(K\\<^sub>1, n), \\<tau>\\<^sub>v\\<^sub>a\\<^sub>r(K\\<^sub>2, n)\\<rfloor> \\<in> R) # \\<Gamma>), n\n                        \\<turnstile> \\<Psi> \\<triangleright> ((time-relation \\<lfloor>K\\<^sub>1, K\\<^sub>2\\<rfloor> \\<in> R) # \\<Phi>))\n                    \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\\<close>\n            and rc:\\<open>\\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close> by blast\n        have pc:\\<open>(\\<Gamma>, n \\<turnstile> ((time-relation \\<lfloor>K\\<^sub>1, K\\<^sub>2\\<rfloor> \\<in> R) # \\<Psi>) \\<triangleright> \\<Phi>)\n            \\<hookrightarrow> (((\\<lfloor>\\<tau>\\<^sub>v\\<^sub>a\\<^sub>r (K\\<^sub>1, n), \\<tau>\\<^sub>v\\<^sub>a\\<^sub>r (K\\<^sub>2, n)\\<rfloor> \\<in> R) # \\<Gamma>), n\n                  \\<turnstile> \\<Psi> \\<triangleright> ((time-relation \\<lfloor>K\\<^sub>1, K\\<^sub>2\\<rfloor> \\<in> R) # \\<Phi>))\\<close>\n          by (simp add: elims_part tagrel_e)\n        hence \\<open>(\\<Gamma>, n \\<turnstile> (time-relation \\<lfloor>K\\<^sub>1, K\\<^sub>2\\<rfloor> \\<in> R) # \\<Psi> \\<triangleright> \\<Phi>)\n                \\<hookrightarrow>\\<^bsup>Suc k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\\<close>\n          using fp relpowp_Suc_I2 by auto\n        with rc show ?thesis by blast\n      qed\n  next\n    case (Implies K\\<^sub>1 K\\<^sub>2)\n      have branches: \\<open>\\<lbrakk> \\<Gamma>, n \\<turnstile> ((K\\<^sub>1 implies K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi> \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n          = \\<lbrakk> ((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n          \\<union> \\<lbrakk> ((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        using HeronConf_interp_stepwise_implies_cases by simp\n      moreover have br1: \\<open>\\<rho> \\<in> \\<lbrakk> ((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n                \\<Longrightarrow> \\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k. ((\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 implies K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n                                    \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                  \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n      proof -\n        assume h1: \\<open>\\<rho> \\<in> \\<lbrakk> ((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        then have \\<open>\\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k.\n                    ((((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies K\\<^sub>2) # \\<Phi>))\n                        \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                  \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n          using h1 Implies.prems by simp\n        from this obtain \\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k where\n          fp:\\<open>((((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies K\\<^sub>2) # \\<Phi>))\n            \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\\<close>\n          and rc:\\<open>\\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close> by blast\n        have pc:\\<open>(\\<Gamma>, n \\<turnstile> (K\\<^sub>1 implies K\\<^sub>2) # \\<Psi> \\<triangleright> \\<Phi>)\n                  \\<hookrightarrow> (((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies K\\<^sub>2) # \\<Phi>))\\<close>\n          by (simp add: elims_part implies_e1)\n        hence \\<open>(\\<Gamma>, n \\<turnstile> (K\\<^sub>1 implies K\\<^sub>2) # \\<Psi> \\<triangleright> \\<Phi>) \\<hookrightarrow>\\<^bsup>Suc k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\\<close>\n          using fp relpowp_Suc_I2 by auto\n        with rc show ?thesis by blast\n      qed\n      moreover have br2: \\<open>\\<rho> \\<in> \\<lbrakk> ((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<Up> n) # \\<Gamma>), n\n                                \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n                            \\<Longrightarrow> \\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k. ((\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 implies K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n                                              \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                                  \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n      proof -\n        assume h2: \\<open>\\<rho> \\<in> \\<lbrakk> ((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<Up> n) # \\<Gamma>), n\n                          \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        then have \\<open>\\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k. (\n                        (((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies K\\<^sub>2) # \\<Phi>))\n                          \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\n                    ) \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n          using h2 Implies.prems by simp\n        from this obtain \\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k where\n            fp:\\<open>(((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies K\\<^sub>2) # \\<Phi>))\n                \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\\<close>\n        and rc:\\<open>\\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close> by blast\n        have \\<open>(\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 implies K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n              \\<hookrightarrow> (((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies K\\<^sub>2) # \\<Phi>))\\<close>\n          by (simp add: elims_part implies_e2)\n        hence \\<open>(\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 implies K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>) \\<hookrightarrow>\\<^bsup>Suc k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\\<close>\n          using fp relpowp_Suc_I2 by auto\n        with rc show ?thesis by blast\n      qed\n      ultimately show ?case using Implies.prems(2) by blast\n  next\n    case (ImpliesNot K\\<^sub>1 K\\<^sub>2)\n      have branches: \\<open>\\<lbrakk> \\<Gamma>, n \\<turnstile> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi> \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n          = \\<lbrakk> ((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n          \\<union> \\<lbrakk> ((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        using HeronConf_interp_stepwise_implies_not_cases by simp\n      moreover have br1: \\<open>\\<rho> \\<in> \\<lbrakk> ((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n\n                            \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n                \\<Longrightarrow> \\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k. ((\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n                                    \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                  \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n      proof -\n        assume h1: \\<open>\\<rho> \\<in> \\<lbrakk> ((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        then have \\<open>\\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k.\n                    ((((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Phi>))\n                      \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                  \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n          using h1 ImpliesNot.prems by simp\n        from this obtain \\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k where\n          fp:\\<open>((((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Phi>))\n                \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\\<close>\n          and rc:\\<open>\\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close> by blast\n        have pc:\\<open>(\\<Gamma>, n \\<turnstile> (K\\<^sub>1 implies not K\\<^sub>2) # \\<Psi> \\<triangleright> \\<Phi>)\n                  \\<hookrightarrow> (((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Phi>))\\<close>\n          by (simp add: elims_part implies_not_e1)\n        hence \\<open>(\\<Gamma>, n \\<turnstile> (K\\<^sub>1 implies not K\\<^sub>2) # \\<Psi> \\<triangleright> \\<Phi>) \\<hookrightarrow>\\<^bsup>Suc k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\\<close>\n          using fp relpowp_Suc_I2 by auto\n        with rc show ?thesis by blast\n      qed\n      moreover have br2: \\<open>\\<rho> \\<in> \\<lbrakk> ((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<not>\\<Up> n) # \\<Gamma>), n\n                            \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n                            \\<Longrightarrow> \\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k. ((\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n                                              \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                                  \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n      proof -\n        assume h2: \\<open>\\<rho> \\<in> \\<lbrakk> ((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<not>\\<Up> n) # \\<Gamma>), n\n                          \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        then have \\<open>\\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k. (\n                     (((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<not>\\<Up> n) # \\<Gamma>), n\n                       \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Phi>)) \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\n                    ) \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n          using h2 ImpliesNot.prems by simp\n        from this obtain \\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k where\n            fp:\\<open>(((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Phi>))\n                \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\\<close>\n        and rc:\\<open>\\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close> by blast\n        have \\<open>(\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n              \\<hookrightarrow> (((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Phi>))\\<close>\n          by (simp add: elims_part implies_not_e2)\n        hence \\<open>(\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 implies not K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n                \\<hookrightarrow>\\<^bsup>Suc k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\\<close>\n          using fp relpowp_Suc_I2 by auto\n        with rc show ?thesis by blast\n      qed\n      ultimately show ?case  using ImpliesNot.prems(2) by blast\n  next\n    case (TimeDelayedBy K\\<^sub>1 \\<delta>\\<tau> K\\<^sub>2 K\\<^sub>3)\n      have branches:\n        \\<open>\\<lbrakk> \\<Gamma>, n \\<turnstile> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Psi>) \\<triangleright> \\<Phi> \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n          = \\<lbrakk> ((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n\n              \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n          \\<union> \\<lbrakk> ((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 @ n \\<oplus> \\<delta>\\<tau> \\<Rightarrow> K\\<^sub>3) # \\<Gamma>), n\n              \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        using HeronConf_interp_stepwise_timedelayed_cases by simp\n      moreover have br1:\n        \\<open>\\<rho> \\<in> \\<lbrakk> ((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n\n              \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n          \\<Longrightarrow> \\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k.\n            ((\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Psi>) \\<triangleright> \\<Phi>)\n                \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n            \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n      proof -\n        assume h1: \\<open>\\<rho> \\<in> \\<lbrakk> ((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n\n                         \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        then have \\<open>\\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k.\n          ((((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Phi>))\n            \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n          \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n          using h1 TimeDelayedBy.prems by simp\n        from this obtain \\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k\n          where fp:\\<open>(((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n\n                      \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Phi>))\n                    \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\\<close>\n            and rc:\\<open>\\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close> by blast\n        have \\<open>(\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Psi>) \\<triangleright> \\<Phi>)\n              \\<hookrightarrow> (((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n\n                    \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Phi>))\\<close>\n          by (simp add: elims_part timedelayed_e1)\n        hence \\<open>(\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Psi>) \\<triangleright> \\<Phi>)\n                \\<hookrightarrow>\\<^bsup>Suc k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\\<close>\n          using fp relpowp_Suc_I2 by auto\n        with rc show ?thesis by blast\n      qed\n      moreover have br2:\n        \\<open>\\<rho> \\<in> \\<lbrakk> ((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 @ n \\<oplus> \\<delta>\\<tau> \\<Rightarrow> K\\<^sub>3) # \\<Gamma>), n\n              \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n          \\<Longrightarrow> \\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k.\n              ((\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Psi>) \\<triangleright> \\<Phi>)\n                \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n              \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n      proof -\n        assume h2: \\<open>\\<rho> \\<in> \\<lbrakk> ((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 @ n \\<oplus> \\<delta>\\<tau> \\<Rightarrow> K\\<^sub>3) # \\<Gamma>), n\n                    \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        then have \\<open>\\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k. ((((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 @ n \\<oplus> \\<delta>\\<tau> \\<Rightarrow> K\\<^sub>3) # \\<Gamma>), n\n                                 \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Phi>))\n                                 \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                                \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n          using h2 TimeDelayedBy.prems by simp\n        from this obtain \\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k\n          where fp:\\<open>(((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 @ n \\<oplus> \\<delta>\\<tau> \\<Rightarrow> K\\<^sub>3) # \\<Gamma>), n\n                         \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Phi>))\n                       \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\\<close>\n            and rc:\\<open>\\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close> by blast\n        have \\<open>(\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Psi>) \\<triangleright> \\<Phi>)\n              \\<hookrightarrow> (((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 @ n \\<oplus> \\<delta>\\<tau> \\<Rightarrow> K\\<^sub>3) # \\<Gamma>), n\n                  \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Phi>))\\<close>\n          by (simp add: elims_part timedelayed_e2)\n        with fp relpowp_Suc_I2 have\n          \\<open>(\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 time-delayed by \\<delta>\\<tau> on K\\<^sub>2 implies K\\<^sub>3) # \\<Psi>) \\<triangleright> \\<Phi>)\n            \\<hookrightarrow>\\<^bsup>Suc k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\\<close>\n          by auto\n        with rc show ?thesis by blast\n      qed\n      ultimately show ?case using TimeDelayedBy.prems(2) by blast\n  next\n    case (WeaklyPrecedes K\\<^sub>1 K\\<^sub>2)\n      have \\<open>\\<lbrakk> \\<Gamma>, n \\<turnstile> ((K\\<^sub>1 weakly precedes K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi> \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g =\n        \\<lbrakk> ((\\<lceil>#\\<^sup>\\<le> K\\<^sub>2 n, #\\<^sup>\\<le> K\\<^sub>1 n\\<rceil> \\<in> (\\<lambda>(x, y). x \\<le> y)) # \\<Gamma>), n\n            \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 weakly precedes K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        using HeronConf_interp_stepwise_weakly_precedes_cases by simp\n      moreover have \\<open>\\<rho> \\<in> \\<lbrakk> ((\\<lceil>#\\<^sup>\\<le> K\\<^sub>2 n, #\\<^sup>\\<le> K\\<^sub>1 n\\<rceil> \\<in> (\\<lambda>(x, y). x \\<le> y)) # \\<Gamma>), n\n                            \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 weakly precedes K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n            \\<Longrightarrow> (\\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k. ((\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 weakly precedes K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n                                  \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                \\<and> (\\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g))\\<close>\n      proof -\n        assume \\<open>\\<rho> \\<in> \\<lbrakk> ((\\<lceil>#\\<^sup>\\<le> K\\<^sub>2 n, #\\<^sup>\\<le> K\\<^sub>1 n\\<rceil> \\<in> (\\<lambda>(x, y). x \\<le> y)) # \\<Gamma>), n\n                        \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 weakly precedes K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        hence \\<open>\\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k. ((((\\<lceil>#\\<^sup>\\<le> K\\<^sub>2 n, #\\<^sup>\\<le> K\\<^sub>1 n\\<rceil> \\<in> (\\<lambda>(x, y). x \\<le> y)) # \\<Gamma>), n\n                                  \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 weakly precedes K\\<^sub>2) # \\<Phi>))\n                             \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                          \\<and> (\\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g)\\<close>\n          using  WeaklyPrecedes.prems by simp\n        from this obtain \\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k\n          where fp:\\<open>(((\\<lceil>#\\<^sup>\\<le> K\\<^sub>2 n, #\\<^sup>\\<le> K\\<^sub>1 n\\<rceil> \\<in> (\\<lambda>(x, y). x \\<le> y)) # \\<Gamma>), n\n                                  \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 weakly precedes K\\<^sub>2) # \\<Phi>))\n                             \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\\<close>\n            and rc:\\<open>\\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close> by blast\n        have \\<open>(\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 weakly precedes K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n                \\<hookrightarrow> (((\\<lceil>#\\<^sup>\\<le> K\\<^sub>2 n, #\\<^sup>\\<le> K\\<^sub>1 n\\<rceil> \\<in> (\\<lambda>(x, y). x \\<le> y)) # \\<Gamma>), n\n              \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 weakly precedes K\\<^sub>2) # \\<Phi>))\\<close>\n          by (simp add: elims_part weakly_precedes_e)\n        with fp relpowp_Suc_I2 have \\<open>(\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 weakly precedes K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n                                      \\<hookrightarrow>\\<^bsup>Suc k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\\<close>\n          by auto\n        with rc show ?thesis by blast\n      qed\n      ultimately show ?case using WeaklyPrecedes.prems(2) by blast\n  next\n    case (StrictlyPrecedes K\\<^sub>1 K\\<^sub>2)\n      have \\<open>\\<lbrakk> \\<Gamma>, n \\<turnstile> ((K\\<^sub>1 strictly precedes K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi> \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g =\n        \\<lbrakk> ((\\<lceil>#\\<^sup>\\<le> K\\<^sub>2 n, #\\<^sup>< K\\<^sub>1 n\\<rceil> \\<in> (\\<lambda>(x, y). x \\<le> y)) # \\<Gamma>), n\n          \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 strictly precedes K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        using HeronConf_interp_stepwise_strictly_precedes_cases by simp\n      moreover have \\<open>\\<rho> \\<in> \\<lbrakk> ((\\<lceil>#\\<^sup>\\<le> K\\<^sub>2 n, #\\<^sup>< K\\<^sub>1 n\\<rceil> \\<in> (\\<lambda>(x, y). x \\<le> y)) # \\<Gamma>), n\n                            \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 strictly precedes K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n            \\<Longrightarrow> (\\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k. ((\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 strictly precedes K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n                                  \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                \\<and> (\\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g))\\<close>\n      proof -\n        assume \\<open>\\<rho> \\<in> \\<lbrakk> ((\\<lceil>#\\<^sup>\\<le> K\\<^sub>2 n, #\\<^sup>< K\\<^sub>1 n\\<rceil> \\<in> (\\<lambda>(x, y). x \\<le> y)) # \\<Gamma>), n\n                        \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 strictly precedes K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        hence \\<open>\\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k. ((((\\<lceil>#\\<^sup>\\<le> K\\<^sub>2 n, #\\<^sup>< K\\<^sub>1 n\\<rceil> \\<in> (\\<lambda>(x, y). x \\<le> y)) # \\<Gamma>), n\n                                  \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 strictly precedes K\\<^sub>2) # \\<Phi>))\n                             \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                            \\<and> (\\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g)\\<close>\n          using  StrictlyPrecedes.prems by simp\n        from this obtain \\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k\n          where fp:\\<open>(((\\<lceil>#\\<^sup>\\<le> K\\<^sub>2 n, #\\<^sup>< K\\<^sub>1 n\\<rceil> \\<in> (\\<lambda>(x, y). x \\<le> y)) # \\<Gamma>), n\n                                  \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 strictly precedes K\\<^sub>2) # \\<Phi>))\n                             \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\\<close>\n            and rc:\\<open>\\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close> by blast\n        have \\<open>(\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 strictly precedes K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n                \\<hookrightarrow> (((\\<lceil>#\\<^sup>\\<le> K\\<^sub>2 n, #\\<^sup>< K\\<^sub>1 n\\<rceil> \\<in> (\\<lambda>(x, y). x \\<le> y)) # \\<Gamma>), n\n              \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 strictly precedes K\\<^sub>2) # \\<Phi>))\\<close>\n          by (simp add: elims_part strictly_precedes_e)\n        with fp relpowp_Suc_I2 have \\<open>(\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 strictly precedes K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n                                      \\<hookrightarrow>\\<^bsup>Suc k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\\<close>\n          by auto\n        with rc show ?thesis by blast\n      qed\n      ultimately show ?case using StrictlyPrecedes.prems(2) by blast\n  next\n    case (Kills K\\<^sub>1 K\\<^sub>2)\n      have branches: \\<open>\\<lbrakk> \\<Gamma>, n \\<turnstile> ((K\\<^sub>1 kills K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi> \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n          = \\<lbrakk> ((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 kills K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n          \\<union> \\<lbrakk> ((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<not>\\<Up> \\<ge> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 kills K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        using HeronConf_interp_stepwise_kills_cases by simp\n      moreover have br1: \\<open>\\<rho> \\<in> \\<lbrakk> ((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 kills K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n                \\<Longrightarrow> \\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k. ((\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 kills K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n                                    \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                  \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n      proof -\n        assume h1: \\<open>\\<rho> \\<in> \\<lbrakk> ((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 kills K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        then have \\<open>\\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k.\n                    ((((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 kills K\\<^sub>2) # \\<Phi>))\n                    \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                  \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n          using h1 Kills.prems by simp\n        from this obtain \\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k where\n          fp:\\<open>((((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 kills K\\<^sub>2) # \\<Phi>))\n                \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\\<close>\n          and rc:\\<open>\\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close> by blast\n        have pc:\\<open>(\\<Gamma>, n \\<turnstile> (K\\<^sub>1 kills K\\<^sub>2) # \\<Psi> \\<triangleright> \\<Phi>)\n                  \\<hookrightarrow> (((K\\<^sub>1 \\<not>\\<Up> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 kills K\\<^sub>2) # \\<Phi>))\\<close>\n          by (simp add: elims_part kills_e1)\n        hence \\<open>(\\<Gamma>, n \\<turnstile> (K\\<^sub>1 kills K\\<^sub>2) # \\<Psi> \\<triangleright> \\<Phi>) \\<hookrightarrow>\\<^bsup>Suc k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\\<close>\n          using fp relpowp_Suc_I2 by auto\n        with rc show ?thesis by blast\n      qed\n      moreover have br2:\n        \\<open>\\<rho> \\<in> \\<lbrakk> ((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<not>\\<Up> \\<ge> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 kills K\\<^sub>2) # \\<Phi>) \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\n          \\<Longrightarrow> \\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k. ((\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 kills K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n                                \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                          \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n      proof -\n        assume h2: \\<open>\\<rho> \\<in> \\<lbrakk>((K\\<^sub>1 \\<Up> n)#(K\\<^sub>2 \\<not>\\<Up> \\<ge> n)#\\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 kills K\\<^sub>2)#\\<Phi>)\\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n        then have \\<open>\\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k. (\n                    (((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<not>\\<Up> \\<ge> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 kills K\\<^sub>2) # \\<Phi>))\n                      \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\n                    ) \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n          using h2 Kills.prems by simp\n        from this obtain \\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k where\n            fp:\\<open>(((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<not>\\<Up> \\<ge> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 kills K\\<^sub>2) # \\<Phi>))\n                \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\\<close>\n        and rc:\\<open>\\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close> by blast\n        have \\<open>(\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 kills K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>)\n              \\<hookrightarrow> (((K\\<^sub>1 \\<Up> n) # (K\\<^sub>2 \\<not>\\<Up> \\<ge> n) # \\<Gamma>), n \\<turnstile> \\<Psi> \\<triangleright> ((K\\<^sub>1 kills K\\<^sub>2) # \\<Phi>))\\<close>\n          by (simp add: elims_part kills_e2)\n        hence \\<open>(\\<Gamma>, n \\<turnstile> ((K\\<^sub>1 kills K\\<^sub>2) # \\<Psi>) \\<triangleright> \\<Phi>) \\<hookrightarrow>\\<^bsup>Suc k\\<^esup> (\\<Gamma>\\<^sub>k, Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\\<close>\n          using fp relpowp_Suc_I2 by auto\n        with rc show ?thesis by blast\n      qed\n      ultimately show ?case using Kills.prems(2) by blast\n  qed\nqed\n\nlemma instant_index_increase_generalized:\n  assumes \\<open>n < n\\<^sub>k\\<close>\n  assumes \\<open>\\<rho> \\<in> \\<lbrakk> \\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi> \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n  shows   \\<open>\\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k. ((\\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi>) \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, n\\<^sub>k \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                         \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, n\\<^sub>k \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\nproof -\n  obtain \\<delta>k where diff: \\<open>n\\<^sub>k = \\<delta>k + Suc n\\<close>\n    using add.commute assms(1) less_iff_Suc_add by auto\n  show ?thesis\n    proof (subst diff, subst diff, insert assms(2), induct \\<delta>k)\n      case 0  thus ?case\n        using instant_index_increase assms(2) by simp\n    next\n      case (Suc \\<delta>k)\n        have f0: \\<open>\\<rho> \\<in> \\<lbrakk> \\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi> \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g \\<Longrightarrow> \\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k.\n                  ((\\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi>) \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, \\<delta>k + Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, \\<delta>k + Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n          using Suc.hyps by blast\n        obtain \\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k\n          where cont: \\<open>((\\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi>) \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, \\<delta>k + Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                      \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, \\<delta>k + Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n          using f0 assms(1) Suc.prems by blast\n        then have fcontinue: \\<open>\\<exists>\\<Gamma>\\<^sub>k' \\<Psi>\\<^sub>k' \\<Phi>\\<^sub>k' k'. ((\\<Gamma>\\<^sub>k, \\<delta>k + Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\n                                       \\<hookrightarrow>\\<^bsup>k'\\<^esup> (\\<Gamma>\\<^sub>k', Suc (\\<delta>k + Suc n) \\<turnstile> \\<Psi>\\<^sub>k' \\<triangleright> \\<Phi>\\<^sub>k'))\n                                   \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k', Suc (\\<delta>k + Suc n) \\<turnstile> \\<Psi>\\<^sub>k' \\<triangleright> \\<Phi>\\<^sub>k' \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n          using f0 cont instant_index_increase by blast\n        obtain \\<Gamma>\\<^sub>k' \\<Psi>\\<^sub>k' \\<Phi>\\<^sub>k' k'\n          where cont2: \\<open>((\\<Gamma>\\<^sub>k, \\<delta>k + Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k)\n                        \\<hookrightarrow>\\<^bsup>k'\\<^esup> (\\<Gamma>\\<^sub>k', Suc (\\<delta>k + Suc n) \\<turnstile> \\<Psi>\\<^sub>k' \\<triangleright> \\<Phi>\\<^sub>k'))\n                      \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k', Suc (\\<delta>k + Suc n) \\<turnstile> \\<Psi>\\<^sub>k' \\<triangleright> \\<Phi>\\<^sub>k' \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n          using Suc.prems using fcontinue cont by blast\n        have trans: \\<open>(\\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi>) \\<hookrightarrow>\\<^bsup>k + k'\\<^esup> (\\<Gamma>\\<^sub>k', Suc (\\<delta>k + Suc n) \\<turnstile> \\<Psi>\\<^sub>k' \\<triangleright> \\<Phi>\\<^sub>k')\\<close>\n          using operational_semantics_trans_generalized cont cont2 by blast\n        moreover have suc_assoc: \\<open>Suc \\<delta>k + Suc n = Suc (\\<delta>k + Suc n)\\<close> by arith\n        ultimately show ?case\n          proof (subst suc_assoc)\n            show \\<open>\\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k.\n                   ((\\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi>) \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, Suc (\\<delta>k + Suc n) \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                  \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, Suc \\<delta>k + Suc n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n            using cont2 local.trans by auto\n          qed\n    qed\nqed\n\ntext\\<open>\n  Any run that belongs to a specification @{term \\<open>\\<Psi>\\<close>} has a corresponding \n  configuration that develops it up to the @{term \\<open>n\\<close>}\\textsuperscript{th} instant.\n\\<close>\ntheorem progress:\n  assumes \\<open>\\<rho> \\<in> \\<lbrakk>\\<lbrakk> \\<Psi> \\<rbrakk>\\<rbrakk>\\<^sub>T\\<^sub>E\\<^sub>S\\<^sub>L\\<close>\n    shows \\<open>\\<exists>k \\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k. (([], 0 \\<turnstile> \\<Psi> \\<triangleright> [])  \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                         \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, n \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\nproof -\n  have 1:\\<open>\\<exists>\\<Gamma>\\<^sub>k \\<Psi>\\<^sub>k \\<Phi>\\<^sub>k k. (([], 0 \\<turnstile> \\<Psi> \\<triangleright> []) \\<hookrightarrow>\\<^bsup>k\\<^esup> (\\<Gamma>\\<^sub>k, 0 \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k))\n                      \\<and> \\<rho> \\<in> \\<lbrakk> \\<Gamma>\\<^sub>k, 0 \\<turnstile> \\<Psi>\\<^sub>k \\<triangleright> \\<Phi>\\<^sub>k \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\n    using assms relpowp_0_I solve_start by fastforce\n  show ?thesis\n  proof (cases \\<open>n = 0\\<close>)\n    case True\n      thus ?thesis using assms relpowp_0_I solve_start by fastforce\n  next\n    case False hence pos:\\<open>n > 0\\<close> by simp\n      from assms solve_start have \\<open>\\<rho> \\<in> \\<lbrakk> [], 0 \\<turnstile> \\<Psi> \\<triangleright> [] \\<rbrakk>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g \\<close> by blast\n      from instant_index_increase_generalized[OF pos this] show ?thesis by blast\n  qed\nqed\n\nsection \\<open>Local termination\\<close>\ntext \\<open>\n  Here, we prove that the computation of an instant in a run always terminates.\n  Since this computation terminates when the list of constraints for the present\n  instant becomes empty, we introduce a measure for this formula.\n\\<close>\nprimrec measure_interpretation :: \\<open>'\\<tau>::linordered_field TESL_formula \\<Rightarrow> nat\\<close> (\\<open>\\<mu>\\<close>)\nwhere\n  \\<open>\\<mu> [] = (0::nat)\\<close>\n| \\<open>\\<mu> (\\<phi> # \\<Phi>) = (case \\<phi> of\n                      _ sporadic _ on _ \\<Rightarrow> 1 + \\<mu> \\<Phi>\n                    | _                 \\<Rightarrow> 2 + \\<mu> \\<Phi>)\\<close>\n\nfun measure_interpretation_config :: \\<open>'\\<tau>::linordered_field config \\<Rightarrow> nat\\<close> (\\<open>\\<mu>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>)\nwhere\n  \\<open>\\<mu>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g (\\<Gamma>, n \\<turnstile> \\<Psi> \\<triangleright> \\<Phi>) = \\<mu> \\<Psi>\\<close>\n\ntext \\<open>\n  We then show that the elimination rules make this measure decrease.\n\\<close>\nlemma elimation_rules_strictly_decreasing:\n  assumes \\<open>(\\<Gamma>\\<^sub>1, n\\<^sub>1 \\<turnstile> \\<Psi>\\<^sub>1 \\<triangleright> \\<Phi>\\<^sub>1)  \\<hookrightarrow>\\<^sub>e  (\\<Gamma>\\<^sub>2, n\\<^sub>2 \\<turnstile> \\<Psi>\\<^sub>2 \\<triangleright> \\<Phi>\\<^sub>2)\\<close>\n    shows \\<open>\\<mu> \\<Psi>\\<^sub>1 > \\<mu> \\<Psi>\\<^sub>2\\<close>\nusing assms by (auto elim: operational_semantics_elim.cases)\n\nlemma elimation_rules_strictly_decreasing_meas:\n  assumes \\<open>(\\<Gamma>\\<^sub>1, n\\<^sub>1 \\<turnstile> \\<Psi>\\<^sub>1 \\<triangleright> \\<Phi>\\<^sub>1)  \\<hookrightarrow>\\<^sub>e  (\\<Gamma>\\<^sub>2, n\\<^sub>2 \\<turnstile> \\<Psi>\\<^sub>2 \\<triangleright> \\<Phi>\\<^sub>2)\\<close>\n    shows \\<open>(\\<Psi>\\<^sub>2, \\<Psi>\\<^sub>1) \\<in> measure \\<mu>\\<close>\nusing assms by (auto elim: operational_semantics_elim.cases)\n\nlemma elimation_rules_strictly_decreasing_meas':\n  assumes \\<open>\\<S>\\<^sub>1  \\<hookrightarrow>\\<^sub>e  \\<S>\\<^sub>2\\<close>\n  shows \\<open>(\\<S>\\<^sub>2, \\<S>\\<^sub>1) \\<in> measure \\<mu>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g\\<close>\nproof -\n  from assms obtain \\<Gamma>\\<^sub>1 n\\<^sub>1 \\<Psi>\\<^sub>1 \\<Phi>\\<^sub>1 where p1:\\<open>\\<S>\\<^sub>1 = (\\<Gamma>\\<^sub>1, n\\<^sub>1 \\<turnstile> \\<Psi>\\<^sub>1 \\<triangleright> \\<Phi>\\<^sub>1)\\<close>\n    using measure_interpretation_config.cases by blast\n  from assms obtain \\<Gamma>\\<^sub>2 n\\<^sub>2 \\<Psi>\\<^sub>2 \\<Phi>\\<^sub>2 where p2:\\<open>\\<S>\\<^sub>2 = (\\<Gamma>\\<^sub>2, n\\<^sub>2 \\<turnstile> \\<Psi>\\<^sub>2 \\<triangleright> \\<Phi>\\<^sub>2)\\<close>\n    using measure_interpretation_config.cases by blast\n  from elimation_rules_strictly_decreasing_meas assms p1 p2\n    have \\<open>(\\<Psi>\\<^sub>2, \\<Psi>\\<^sub>1) \\<in> measure \\<mu>\\<close> by blast\n  hence \\<open>\\<mu> \\<Psi>\\<^sub>2 < \\<mu> \\<Psi>\\<^sub>1\\<close> by simp\n  hence \\<open>\\<mu>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g (\\<Gamma>\\<^sub>2, n\\<^sub>2 \\<turnstile> \\<Psi>\\<^sub>2 \\<triangleright> \\<Phi>\\<^sub>2) < \\<mu>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g (\\<Gamma>\\<^sub>1, n\\<^sub>1 \\<turnstile> \\<Psi>\\<^sub>1 \\<triangleright> \\<Phi>\\<^sub>1)\\<close> by simp\n  with p1 p2 show ?thesis by simp\nqed\n\ntext \\<open>\n  Therefore, the relation made up of elimination rules is well-founded and the\n  computation of an instant terminates.\n\\<close>\ntheorem instant_computation_termination:\n  \\<open>wfP (\\<lambda>(\\<S>\\<^sub>1::'a::linordered_field config) \\<S>\\<^sub>2. (\\<S>\\<^sub>1  \\<hookrightarrow>\\<^sub>e\\<^sup>\\<leftarrow>  \\<S>\\<^sub>2))\\<close>\nproof (simp add: wfP_def)\n  show \\<open>wf {((\\<S>\\<^sub>1::'a::linordered_field config), \\<S>\\<^sub>2). \\<S>\\<^sub>1 \\<hookrightarrow>\\<^sub>e\\<^sup>\\<leftarrow> \\<S>\\<^sub>2}\\<close>\n  proof (rule wf_subset)\n    have \\<open>measure \\<mu>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g = {(\\<S>\\<^sub>2, (\\<S>\\<^sub>1::'a::linordered_field config)).\n                               \\<mu>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g \\<S>\\<^sub>2 < \\<mu>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g \\<S>\\<^sub>1}\\<close>\n      by (simp add: inv_image_def less_eq measure_def)\n    thus \\<open>{((\\<S>\\<^sub>1::'a::linordered_field config), \\<S>\\<^sub>2). \\<S>\\<^sub>1 \\<hookrightarrow>\\<^sub>e\\<^sup>\\<leftarrow> \\<S>\\<^sub>2} \\<subseteq> (measure \\<mu>\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>f\\<^sub>i\\<^sub>g)\\<close>\n      using elimation_rules_strictly_decreasing_meas'\n            operational_semantics_elim_inv_def by blast\n  next\n    show \\<open>wf (measure measure_interpretation_config)\\<close> by simp\n  qed\nqed\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/TESL_Language/Hygge_Theory.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5078118642792044, "lm_q2_score": 0.5117166047041654, "lm_q1q2_score": 0.25985576301744695}}
{"text": "(*\n * Copyright 2016, Data61, CSIRO\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(DATA61_BSD)\n *)\n\nsection \\<open>The COMPLX Syntax\\<close>\n\ntheory Language\nimports Main\nbegin\n\nsubsection \\<open>The Core Language\\<close>\n\ntext \\<open>We use a shallow embedding of boolean expressions as well as assertions\nas sets of states. \n\\<close>\n\ntype_synonym 's bexp = \"'s set\"\ntype_synonym 's assn = \"'s set\"\n\ndatatype ('s, 'p, 'f) com =\n    Skip\n  | Basic \"'s \\<Rightarrow> 's\"\n  | Spec \"('s \\<times> 's) set\"\n  | Seq \"('s ,'p, 'f) com\" \"('s,'p, 'f) com\"    \n  | Cond \"'s bexp\" \"('s,'p,'f) com\"  \"('s,'p,'f) com\"\n  | While \"'s bexp\" \"('s,'p,'f) com\"\n  | Call \"'p\"\n  | DynCom \"'s \\<Rightarrow> ('s,'p,'f) com\" \n  | Guard \"'f\" \"'s bexp\" \"('s,'p,'f) com\" \n  | Throw\n  | Catch \"('s,'p,'f) com\" \"('s,'p,'f) com\"\n  | Parallel \"('s, 'p, 'f) com list\"\n  | Await \"'s bexp\" \"('s,'p,'f) com\"\n\n\nsubsection \\<open>Derived Language Constructs\\<close>\n\ntext \\<open>We inherit the remainder of derived language constructs from SIMPL\\<close>\n\ndefinition\n  raise:: \"('s \\<Rightarrow> 's) \\<Rightarrow> ('s,'p,'f) com\" where\n  \"raise f = Seq (Basic f) Throw\"\n\ndefinition\n  condCatch:: \"('s,'p,'f) com \\<Rightarrow> 's bexp \\<Rightarrow> ('s,'p,'f) com \\<Rightarrow> ('s,'p,'f) com\" where\n  \"condCatch c\\<^sub>1 b c\\<^sub>2 = Catch c\\<^sub>1 (Cond b c\\<^sub>2 Throw)\"\n\ndefinition\n  bind:: \"('s \\<Rightarrow> 'v) \\<Rightarrow> ('v \\<Rightarrow> ('s,'p,'f) com) \\<Rightarrow> ('s,'p,'f) com\" where\n  \"bind e c = DynCom (\\<lambda>s. c (e s))\"\n\ndefinition\n  bseq:: \"('s,'p,'f) com \\<Rightarrow> ('s,'p,'f) com \\<Rightarrow> ('s,'p,'f) com\" where\n  \"bseq = Seq\"\n \ndefinition\n  block:: \"['s\\<Rightarrow>'s ,('s,'p,'f) com,'s\\<Rightarrow>'s\\<Rightarrow>'s,'s\\<Rightarrow>'s\\<Rightarrow>('s,'p,'f) com]\\<Rightarrow>('s,'p,'f) com\"\nwhere\n  \"block init bdy restore return =\n    DynCom (\\<lambda>s. (Seq (Catch (Seq (Basic init) bdy) (Seq (Basic (restore s)) Throw)) \n                            (DynCom (\\<lambda>t. Seq (Basic (restore s)) (return s t))))\n                        )\" \n\ndefinition\n  call:: \"('s\\<Rightarrow>'s) \\<Rightarrow> 'p \\<Rightarrow> ('s \\<Rightarrow> 's \\<Rightarrow> 's)\\<Rightarrow>('s\\<Rightarrow>'s\\<Rightarrow>('s,'p,'f) com)\\<Rightarrow>('s,'p,'f)com\" where\n  \"call init p restore return = block init (Call p) restore return\"\n\ndefinition\n  dynCall:: \"('s\\<Rightarrow>'s) \\<Rightarrow> ('s \\<Rightarrow> 'p) \\<Rightarrow> ('s \\<Rightarrow> 's \\<Rightarrow> 's) \\<Rightarrow>\n             ('s \\<Rightarrow> 's \\<Rightarrow> ('s,'p,'f) com) \\<Rightarrow> ('s,'p,'f) com\" where\n  \"dynCall init p restore return = DynCom (\\<lambda>s. call init (p s) restore return)\"\n\ndefinition\n  fcall:: \"('s\\<Rightarrow>'s) \\<Rightarrow> 'p \\<Rightarrow> ('s \\<Rightarrow> 's \\<Rightarrow> 's)\\<Rightarrow>('s \\<Rightarrow> 'v) \\<Rightarrow> ('v\\<Rightarrow>('s,'p,'f) com)\n            \\<Rightarrow>('s,'p,'f) com\" where\n  \"fcall init p restore result return = call init p restore (\\<lambda>s t. return (result t))\"\n\ndefinition\n  lem:: \"'x \\<Rightarrow> ('s,'p,'f)com \\<Rightarrow>('s,'p,'f)com\" where\n  \"lem x c = c\"\n\nprimrec switch:: \"('s \\<Rightarrow> 'v) \\<Rightarrow> ('v set \\<times> ('s,'p,'f) com) list \\<Rightarrow> ('s,'p,'f) com\" \nwhere\n\"switch v [] = Skip\" |\n\"switch v (Vc#vs) = Cond {s. v s \\<in> fst Vc} (snd Vc) (switch v vs)\"\n\ndefinition guaranteeStrip:: \"'f \\<Rightarrow> 's set \\<Rightarrow> ('s,'p,'f) com \\<Rightarrow> ('s,'p,'f) com\"\n  where \"guaranteeStrip f g c = Guard f g c\"\n\ndefinition guaranteeStripPair:: \"'f \\<Rightarrow> 's set \\<Rightarrow> ('f \\<times> 's set)\"\n  where \"guaranteeStripPair f g = (f,g)\"\n\nprimrec guards:: \"('f \\<times> 's set ) list \\<Rightarrow> ('s,'p,'f) com \\<Rightarrow> ('s,'p,'f) com\"\nwhere\n\"guards [] c = c\" |\n\"guards (g#gs) c = Guard (fst g) (snd g) (guards gs c)\"\n\ndefinition\n  while::  \"('f \\<times> 's set) list \\<Rightarrow> 's bexp \\<Rightarrow> ('s,'p,'f) com \\<Rightarrow> ('s, 'p, 'f) com\"\nwhere\n  \"while gs b c = guards gs (While b (Seq c (guards gs Skip)))\"\n\ndefinition\n  whileAnno:: \n  \"'s bexp \\<Rightarrow> 's assn \\<Rightarrow> ('s \\<times> 's) assn \\<Rightarrow> ('s,'p,'f) com \\<Rightarrow> ('s,'p,'f) com\" where\n  \"whileAnno b I V c = While b c\"\n\ndefinition\n  whileAnnoG:: \n  \"('f \\<times> 's set) list \\<Rightarrow> 's bexp \\<Rightarrow> 's assn \\<Rightarrow> ('s \\<times> 's) assn \\<Rightarrow> \n     ('s,'p,'f) com \\<Rightarrow> ('s,'p,'f) com\" where\n  \"whileAnnoG gs b I V c = while gs b c\"\n \ndefinition\n  specAnno::  \"('a \\<Rightarrow> 's assn) \\<Rightarrow> ('a \\<Rightarrow> ('s,'p,'f) com) \\<Rightarrow> \n                         ('a \\<Rightarrow> 's assn) \\<Rightarrow> ('a \\<Rightarrow> 's assn) \\<Rightarrow> ('s,'p,'f) com\"\n  where \"specAnno P c Q A = (c undefined)\"\n\ndefinition\n  whileAnnoFix:: \n  \"'s bexp \\<Rightarrow> ('a \\<Rightarrow> 's assn) \\<Rightarrow> ('a \\<Rightarrow> ('s \\<times> 's) assn) \\<Rightarrow> ('a \\<Rightarrow> ('s,'p,'f) com) \\<Rightarrow> \n     ('s,'p,'f) com\" where\n  \"whileAnnoFix b I V c = While b (c undefined)\"\n\ndefinition\n  whileAnnoGFix:: \n  \"('f \\<times> 's set) list \\<Rightarrow> 's bexp \\<Rightarrow> ('a \\<Rightarrow> 's assn) \\<Rightarrow> ('a \\<Rightarrow> ('s \\<times> 's) assn) \\<Rightarrow> \n     ('a \\<Rightarrow> ('s,'p,'f) com) \\<Rightarrow> ('s,'p,'f) com\" where\n  \"whileAnnoGFix gs b I V c = while gs b (c undefined)\"\n\ndefinition if_rel::\"('s \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> 's) \\<Rightarrow> ('s \\<Rightarrow> 's) \\<Rightarrow> ('s \\<Rightarrow> 's) \\<Rightarrow> ('s \\<times> 's) set\" \n  where \"if_rel b f g h = {(s,t). if b s then t = f s else t = g s \\<or> t = h s}\"\n\nlemma fst_guaranteeStripPair: \"fst (guaranteeStripPair f g) = f\"\n  by (simp add: guaranteeStripPair_def)\n\nlemma snd_guaranteeStripPair: \"snd (guaranteeStripPair f g) = g\"\n  by (simp add: guaranteeStripPair_def)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Complx/Language.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5156199157230157, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.25982405718051205}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory LemmaBucket_C\nimports\n  Basics.CLib\n  TypHeapLib\nbegin\n\nlemma Ptr_not_null_pointer_not_zero: \"(Ptr p \\<noteq> NULL)=(p\\<noteq>0)\"\n by simp\n\nlemma hrs_mem_f: \"f (hrs_mem s) = hrs_mem (hrs_mem_update f s)\"\n  apply (cases s)\n  apply (clarsimp simp: hrs_mem_def hrs_mem_update_def)\n  done\n\nlemma hrs_mem_heap_update:\n  \"heap_update p v (hrs_mem s) = hrs_mem (hrs_mem_update (heap_update p v) s)\"\n  by (rule hrs_mem_f)\n\nlemma addr_card_wb:\n  \"addr_card = 2 ^ word_bits\"\n  by (simp add: addr_card_def card_word word_bits_conv)\n\nlemma surj_Ptr [simp]:\n  \"surj Ptr\"\n  by (rule surjI [where f = ptr_val], simp)\n\nlemma inj_Ptr [simp]:\n  \"inj Ptr\"\n  apply (rule injI)\n  apply simp\n  done\n\nlemma bij_Ptr :\n  \"bij Ptr\"\n  by (simp add: bijI)\n\nlemma exec_Guard:\n  \"(G \\<turnstile> \\<langle>Guard Err S c, Normal s\\<rangle> \\<Rightarrow> s')\n       = (if s \\<in> S then G \\<turnstile> \\<langle>c, Normal s\\<rangle> \\<Rightarrow> s'\n                else s' = Fault Err)\"\n  using exec.intros by (auto split: if_split elim!: exec_elim_cases)\n\nlemma to_bytes_word8:\n  \"to_bytes (v :: word8) xs = [v]\"\n  by (simp add: to_bytes_def typ_info_word word_rsplit_same)\n\nlemma byte_ptr_guarded:\"ptr_val (x::8 word ptr) \\<noteq> 0 \\<Longrightarrow> c_guard x\"\n  unfolding c_guard_def c_null_guard_def ptr_aligned_def\n  by (clarsimp simp: intvl_Suc simp del: word_neq_0_conv)\n\nlemma heap_update_list_append:\n  fixes v :: word8\n  shows \"heap_update_list s (xs @ ys) hp =\n  heap_update_list (s + of_nat (length xs)) ys (heap_update_list s xs hp)\"\nproof (induct xs arbitrary: ys rule: rev_induct)\n  case Nil\n  show ?case by simp\nnext\n  case (snoc v' vs')\n  show ?case\n    apply (simp add: snoc.hyps field_simps)\n    apply (rule arg_cong [where f = \"heap_update_list (1 + (s + of_nat (length vs'))) ys\"])\n    apply (rule ext)\n    apply simp\n    done\nqed\n\nlemma intvl_aligned_bottom_eq:\n  fixes p :: \"'a::len word\"\n  assumes al1: \"is_aligned x n\"\n  and     al2: \"is_aligned p bits\"\n  and      nb: \"\\<not> n < bits\"\n  and     off: \"off \\<le> 2 ^ bits\" \"off \\<noteq> 0\"\n  shows  \"(x \\<in> {p ..+ off}) = (x = p)\"\nproof (rule iffI)\n  assume \"x = p\"\n  thus \"x \\<in> {p ..+ off}\" using off\n    by (simp add: intvl_self)\nnext\n  assume x_in_intvl: \"x \\<in> {p ..+ off}\"\n\n  show \"x = p\"\n  proof cases\n    assume wb: \"bits < len_of TYPE('a)\"\n\n    from x_in_intvl obtain kp where xp: \"x = p + of_nat kp\" and kp: \"kp < off\"\n      by (clarsimp dest!: intvlD)\n\n    hence \"is_aligned (p + of_nat kp) n\" using al1 by simp\n    hence \"2 ^ n dvd unat (p + of_nat kp)\" unfolding is_aligned_def .\n    hence \"2 ^ n dvd unat p + kp\" using kp off wb\n      apply -\n      apply (subst (asm) iffD1 [OF unat_plus_simple])\n       apply (rule is_aligned_no_wrap' [OF al2])\n       apply (rule of_nat_power)\n        apply simp_all[2]\n      apply (subst (asm) unat_of_nat)\n      apply (subst (asm) mod_less)\n       apply (erule order_less_le_trans)\n       apply (erule order_trans)\n       apply simp\n      apply simp\n      done\n\n  moreover from al2 obtain q2 where pbits: \"p = 2 ^ bits * of_nat q2\"\n                                and q2: \"q2 < 2 ^ (len_of TYPE('a) - bits)\"\n    by (rule is_alignedE)\n\n  moreover from nb obtain kn where nbits: \"n = bits + kn\"\n    by (clarsimp simp: linorder_not_less le_iff_add)\n\n  ultimately have \"2 ^ bits dvd 2 ^ bits * q2 + kp\"\n    apply (simp add: power_add)\n    apply (simp add: unat_mult_power_lem [OF q2])\n    apply (erule dvd_mult_left)\n    done\n\n  hence \"2 ^ bits dvd kp\"\n    by (simp add: dvd_add_right_iff)\n  with kp have \"kp = 0\"\n    apply -\n    apply (erule contrapos_pp)\n    apply (simp add: linorder_not_less)\n    apply (drule (1) dvd_imp_le)\n    apply (erule order_trans [OF off(1)])\n    done\n\n  thus ?thesis using xp by simp\n  next\n    assume wb: \"\\<not> bits < len_of TYPE('a)\"\n    with assms\n    show ?thesis by (simp add: is_aligned_mask mask_def power_overflow)\n  qed\nqed\n\nlemma intvl_mem_weaken: \"x \\<in> {p..+a - n} \\<Longrightarrow> x \\<in> {p..+a}\"\n  apply (drule intvlD)\n  apply clarsimp\n  apply (rule intvlI)\n  apply simp\n  done\n\n\nlemma upto_intvl_eq:\n  fixes x :: \"'a::len word\"\n  assumes al: \"is_aligned x n\"\n  shows \"{x..+2 ^ n} = {x .. x + 2 ^ n - 1}\"\nproof cases\n  assume \"n < len_of TYPE('a)\"\n  with assms show ?thesis\n  unfolding intvl_def\n  apply simp\n  apply rule\n   apply clarsimp\n   apply (subgoal_tac \"of_nat k < (2 :: 'a word) ^ n\")\n    apply (intro conjI)\n     apply (erule (1) is_aligned_no_wrap')\n    apply (subst p_assoc_help)\n    apply (rule word_plus_mono_right)\n     apply (simp add: word_less_sub_1)\n    apply (simp add: field_simps is_aligned_no_overflow)\n   apply (simp add: of_nat_power)\n  apply clarsimp\n  apply (rule_tac x = \"unat (xa - x)\" in exI)\n  apply clarsimp\n  apply (rule unat_less_power, assumption)\n  apply (subst word_less_sub_le [symmetric])\n   apply assumption\n  apply (rule word_diff_ls'(4))\n   apply (simp add: field_simps)\n  apply assumption\n  done\nnext\n  assume \"\\<not> n < len_of TYPE('a)\"\n  with assms show ?thesis\n    apply (simp add: is_aligned_mask mask_def power_overflow intvl_def)\n    apply (rule set_eqI)\n    apply clarsimp\n    apply (rename_tac w)\n    apply (case_tac w rule: word_nat_cases)\n    apply (rename_tac m)\n    apply (rule_tac x=m in exI)\n    apply simp\n    apply (erule order_less_le_trans)\n    apply simp\n    done\nqed\n\nlemma upto_intvl_eq':\n  fixes x :: \"'a :: len word\"\n  shows \"\\<lbrakk> x \\<le> x + (of_nat b - 1); b \\<noteq> 0; b \\<le> 2 ^ len_of TYPE('a)\\<rbrakk> \\<Longrightarrow> {x..+b} = {x .. x + of_nat b - 1}\"\n  unfolding intvl_def\n  apply rule\n   apply clarsimp\n   apply (subgoal_tac \"of_nat k \\<le> (of_nat (b - 1) :: 'a word)\")\n    apply (intro conjI)\n     apply (erule word_random)\n     apply simp\n    apply (subst field_simps [symmetric], rule word_plus_mono_right)\n     apply simp\n    apply assumption\n   apply (rule of_nat_mono_maybe_le; simp)\n  apply clarsimp\n  apply (rule_tac x = \"unat (xa - x)\" in exI)\n  apply simp\n  apply (simp add: unat_sub)\n  apply (rule nat_diff_less)\n   apply (subst (asm) word_le_nat_alt, erule order_le_less_trans)\n   apply (subst add_diff_eq[symmetric], subst unat_plus_if')\n   apply (simp add: no_olen_add_nat le_eq_less_or_eq)\n   apply (metis gt0_iff_gem1 unat_less_helper unat_ucast_less_no_overflow unsigned_0 unsigned_less)\n  apply (simp add: word_le_nat_alt)\n  done\n\nlemma intvl_aligned_top:\n  fixes x :: \"'a::len word\"\n  assumes al1: \"is_aligned x n\"\n  and     al2: \"is_aligned p bits\"\n  and      nb: \"n \\<le> bits\"\n  and    offn: \"off < 2 ^ n\"\n  and      wb: \"bits < len_of TYPE('a)\"\n  shows  \"(x \\<in> {p ..+ 2 ^ bits - off}) = (x \\<in> {p ..+ 2 ^ bits})\"\nproof (rule iffI)\n  assume \"x \\<in> {p..+2 ^ bits - off}\"\n  thus \"x \\<in> {p..+2 ^ bits}\" by (rule intvl_mem_weaken)\nnext\n  assume asm: \"x \\<in> {p..+2 ^ bits}\"\n\n  show \"x \\<in> {p..+2 ^ bits - off}\"\n  proof (cases \"n = 0\")\n    case True\n    with offn asm show ?thesis by simp\n  next\n    case False\n\n    from asm have \"x \\<in> {p .. p + 2 ^ bits - 1}\"\n      by (simp add: upto_intvl_eq [OF al2])\n    then obtain q where xp: \"x = p + of_nat (q * 2 ^ n)\" and qb: \"q < 2 ^ (bits - n)\" using False nb\n      by (fastforce dest!: is_aligned_diff[OF al1 al2 wb,simplified field_simps])\n\n    have \"q * 2 ^ n < 2 ^ bits - off\"\n    proof -\n      show ?thesis using offn qb nb\n        apply (simp add: less_diff_conv)\n        apply (erule (1) nat_add_offset_less)\n        apply arith\n        done\n    qed\n\n    with xp show ?thesis\n      apply -\n      apply (erule ssubst)\n      apply (erule intvlI)\n      done\n  qed\nqed\n\nlemma heap_update_list_update:\n  fixes v :: word8\n  shows \"x \\<noteq> y \\<Longrightarrow> heap_update_list s xs (hp(y := v)) x = heap_update_list s xs hp x\"\n  apply (induct xs rule: rev_induct)\n   apply simp\n  apply (simp add: heap_update_list_append cong: if_cong)\n  done\n\n(* FIXME: generalise *)\nlemma heap_update_list_append2:\n  \"length xs + length ys < 2 ^ word_bits \\<Longrightarrow>\n    heap_update_list s (xs @ ys) hp\n      = heap_update_list s xs (heap_update_list (s + of_nat (length xs)) ys hp)\"\nproof (induct xs arbitrary: hp s)\n  case Nil\n  show ?case by simp\nnext\n  case (Cons v' vs')\n\n  have \"(1 :: addr) + of_nat (length vs') = of_nat (length (v' # vs'))\"\n    by simp\n  also have \"\\<dots> \\<noteq> 0\" using Cons.prems\n    apply -\n    apply (rule of_nat_neq_0)\n    apply simp\n    apply (simp add: word_bits_conv)\n    done\n  finally have neq0: \"(1 :: addr) + of_nat (length vs') \\<noteq> 0\" .\n\n  have \"(1 :: addr) + of_nat (length vs') = of_nat (length (v' # vs'))\"\n    by simp\n  also have \"unat \\<dots> + length ys < 2 ^ word_bits\" using Cons.prems\n    apply (subst unat_of_nat)\n    apply (simp add: word_bits_conv)\n    done\n  finally have lt: \"unat ((1 :: addr) + of_nat (length vs')) + length ys < 2 ^ word_bits\" .\n\n  from Cons.prems have \"length vs' + length ys < 2 ^ word_bits\" by simp\n  thus ?case\n    apply simp\n    apply (subst Cons.hyps, assumption)\n    apply (rule arg_cong [where f = \"heap_update_list (s + 1) vs'\"])\n    apply (rule ext)\n    apply (case_tac \"x = s\")\n     apply simp\n     apply (subst heap_update_nmem_same)\n     apply (subst add.assoc)\n     apply (rule intvl_nowrap[OF neq0 order_less_imp_le\n                                      [OF lt[unfolded word_bits_def]]])\n    apply simp\n    apply (clarsimp simp: heap_update_list_update field_simps)\n   done\nqed\n\nlemma heap_update_word8:\n  \"heap_update p (v :: word8) hp = hp(ptr_val p := v)\"\n  unfolding heap_update_def by (simp add: to_bytes_word8)\n\nlemma index_foldr_update2:\n  \"\\<lbrakk> n \\<le> i; i < CARD('b::finite) \\<rbrakk> \\<Longrightarrow> index (foldr (\\<lambda>n arr. Arrays.update arr n m) [0..<n] (x :: ('a,'b) array)) i = index x i\"\n  apply (induct n arbitrary: x)\n   apply simp\n  apply simp\n  done\n\nlemma index_foldr_update:\n  \"\\<lbrakk> i < n; n \\<le> CARD('b::finite) \\<rbrakk> \\<Longrightarrow> index (foldr (\\<lambda>n arr. Arrays.update arr n m) [0..<n]  (x :: ('a,'b) array)) i = m\"\n  apply (induct n arbitrary: x)\n   apply simp\n  apply simp\n  apply (erule less_SucE)\n   apply simp\n  apply simp\n  apply (subst index_foldr_update2)\n    apply simp\n   apply simp\n  apply simp\n  done\n\nlemma intvl_disjoint1:\n  fixes a :: \"'a :: len word\"\n  assumes abc: \"a + of_nat b \\<le> c\"\n  and     alb: \"a \\<le> a + of_nat b\"\n  and     cld: \"c \\<le> c + of_nat d\"\n  and     blt: \"b < 2 ^ len_of TYPE('a)\"\n  and     dlt: \"d < 2 ^ len_of TYPE('a)\"\n  shows   \"{a..+b} \\<inter> {c..+d} = {}\"\nproof (unfold disjoint_iff_not_equal, intro ballI notI)\n  fix x y\n  assume x: \"x \\<in> {a..+b}\" and y: \"y \\<in> {c..+d}\" and xy: \"x = y\"\n\n  from x obtain kx where \"x = a + of_nat kx\" and kx: \"kx < b\"\n    by (clarsimp dest!: intvlD)\n\n  moreover from y obtain ky where \"y = c + of_nat ky\" and ky: \"ky < d\"\n    by (clarsimp dest!: intvlD)\n\n  ultimately have ac: \"a + of_nat kx = c + of_nat ky\" using xy by simp\n\n  have \"of_nat kx < (of_nat b :: 'a word)\" using blt kx\n    by (rule of_nat_mono_maybe)\n  hence \"a + of_nat kx < a + of_nat b\" using alb\n    by (rule word_plus_strict_mono_right)\n\n  also have \"\\<dots> \\<le> c\" by (rule abc)\n  also have \"\\<dots> \\<le> c + of_nat ky\" using cld dlt ky\n    by (meson less_imp_le of_nat_mono_maybe word_random)\n  finally show False using ac by simp\nqed\n\nlemma intvl_disjoint2:\n  fixes a :: \"'a :: len word\"\n  assumes abc: \"a + of_nat b \\<le> c\"\n  and     alb: \"a \\<le> a + of_nat b\"\n  and     cld: \"c \\<le> c + of_nat d\"\n  and     blt: \"b < 2 ^ len_of TYPE('a)\"\n  and     dlt: \"d < 2 ^ len_of TYPE('a)\"\n  shows   \"{c..+d} \\<inter> {a..+b} = {}\"\n  using abc alb cld blt dlt\n  by (subst Int_commute, rule intvl_disjoint1)\n\n\nlemma intvl_off_disj:\n  fixes x :: addr\n  assumes ylt: \"y \\<le> off\"\n  and    zoff: \"z + off < 2 ^ word_bits\"\n  shows   \"{x ..+ y} \\<inter> {x + of_nat off ..+ z} = {}\"\n  using ylt zoff\n  apply (cases \"off = 0\")\n   apply simp\n  apply (rule contrapos_pp [OF TrueI])\n  apply (drule intvl_inter)\n  apply (erule disjE)\n   apply (cut_tac intvl_nowrap [where x = x and y = \"of_nat off :: addr\" and z = z])\n     apply simp\n    apply (rule of_nat_neq_0)\n     apply simp\n    apply (unfold word_bits_len_of)\n    apply simp\n   apply (simp add: unat_of_nat word_bits_conv)\n  apply (drule intvlD)\n  apply clarsimp\n  apply (drule (1) order_less_le_trans)\n  apply (drule unat_cong)\n  apply (simp add: unat_of_nat word_bits_conv)\n  done\n\n\nlemma list_map_comono:\n  assumes  s: \"list_map m \\<subseteq>\\<^sub>m list_map n\"\n  shows    \"m \\<le> n\"\n  using s\nproof (induct m arbitrary: n rule: rev_induct)\n  case Nil thus ?case unfolding list_map_def by simp\nnext\n  case (snoc x xs)\n\n  note [[syntax_ambiguity_warning=false]]\n  from snoc.prems have\n    sm: \"[length xs \\<mapsto> x] ++ list_map xs \\<subseteq>\\<^sub>m list_map n\"\n    unfolding list_map_def by simp\n\n  hence xsn: \"xs \\<le> n\"\n    by (rule snoc.hyps [OF map_add_le_mapE])\n\n  have \"list_map n (length xs) = Some x\" using sm\n    by (simp add: map_le_def list_map_def merge_dom2 set_zip)\n\n  hence \"length xs < length n\" and \"x = n ! length xs\"\n    by (auto simp add: list_map_eq split: if_split_asm)\n\n  thus \"xs @ [x] \\<le> n\" using xsn\n    by (simp add: append_one_prefix less_eq_list_def)\nqed\n\nlemma typ_slice_t_self:\n  \"td \\<in> fst ` set (typ_slice_t td m)\"\n  by (fact ladder_set_self)\n\nlemma drop_heap_list_le2:\n  \"heap_list h n (x + of_nat k)\n      = drop k (heap_list h (n + k) x)\"\n  by (simp add: drop_heap_list_le)\n\nlemma index_fold_update:\n  \"\\<lbrakk> distinct xs; set xs \\<subseteq> {..< card (UNIV :: 'b set)}; n < card (UNIV :: 'b set) \\<rbrakk> \\<Longrightarrow>\n   index (foldr (\\<lambda>n (arr :: 'a['b :: finite]). Arrays.update arr n (f n (index arr n))) xs v) n\n     = (if n \\<in> set xs then f n (index v n) else index v n)\"\n  apply (induct xs)\n   apply simp\n  apply (rename_tac x xs)\n  apply (case_tac \"x = n\"; simp)\n  done\n\nlemma heap_update_list_id:\n  \"heap_list hp n ptr = xs \\<Longrightarrow> heap_update_list ptr xs hp = hp\"\n  apply (induct xs arbitrary: ptr n)\n   apply simp\n  apply simp\n  apply (case_tac n, simp_all)\n  apply (clarsimp simp add: fun_upd_idem)\n  done\n\nlemma size_td_list_map2: \"\\<And>f adjs. \\<lbrakk> \\<And>a. size_td_pair (f a) = size_td_pair a \\<rbrakk>\n                           \\<Longrightarrow> size_td_list (map f adjs) = size_td_list adjs\"\n  by (induct_tac adjs, simp_all)\n\nlemma hrs_mem_update_cong:\n  \"\\<lbrakk> \\<And>x. f x = f' x \\<rbrakk> \\<Longrightarrow> hrs_mem_update f = hrs_mem_update f'\"\n  by (simp add: hrs_mem_update_def)\n\nlemma Guard_no_cong:\n  \"\\<lbrakk> A=A'; c=c' \\<rbrakk> \\<Longrightarrow> Guard A P c = Guard A' P c'\"\n  by simp\n\nlemma heap_update_list_concat_fold:\n  assumes \"ptr' = ptr + of_nat (length ys)\"\n  shows \"heap_update_list ptr' xs (heap_update_list ptr ys s)\n    = heap_update_list ptr (ys @ xs) s\"\n  unfolding assms\n  apply (induct ys arbitrary: ptr s)\n   apply simp\n  apply simp\n  apply (elim meta_allE)\n  apply (erule trans[rotated])\n  apply (simp add: field_simps)\n  done\n\nlemma heap_update_list_concat_fold_hrs_mem:\n  \"ptr' = ptr + of_nat (length ys) \\<Longrightarrow>\n   hrs_mem_update (heap_update_list ptr' xs)\n        (hrs_mem_update (heap_update_list ptr ys) s)\n    = hrs_mem_update (heap_update_list ptr (ys @ xs)) s\"\n  by (simp add: hrs_mem_update_def split_def\n                heap_update_list_concat_fold)\n\nlemmas heap_update_list_concat_unfold\n    = heap_update_list_concat_fold[OF refl, symmetric]\n\nlemma coerce_heap_update_to_heap_updates:\n  assumes n: \"n = chunk * m\" and len: \"length xs = n\"\n  shows \"heap_update_list x xs\n      = (\\<lambda>s. foldl (\\<lambda>s n. heap_update_list (x + (of_nat n * of_nat chunk))\n                                      (take chunk (drop (n * chunk) xs)) s)\n                     s [0 ..< m])\"\n  using len[simplified n]\n  apply (induct m arbitrary: x xs)\n   apply (rule ext, simp)\n  apply (rule ext)\n  apply (simp only: upt_conv_Cons map_Suc_upt[symmetric])\n  apply (subgoal_tac \"\\<exists>ys zs. length ys = chunk \\<and> xs = ys @ zs\")\n   apply (clarsimp simp: heap_update_list_concat_unfold foldl_map\n                         field_simps)\n  apply (rule_tac x=\"take chunk xs\" in exI)\n  apply (rule_tac x=\"drop chunk xs\" in exI)\n  apply simp\n  done\n\nlemma update_ti_list_array':\n  \"\\<lbrakk> update_ti_list_t (map f [0 ..< n]) xs v = y;\n     \\<forall>n. size_td_pair (f n) = v3; length xs = v3 * n;\n     \\<forall>m xs v'. length xs = v3 \\<and> m < n \\<longrightarrow>\n       update_ti_pair_t (f m) xs v' = Arrays.update v' m (update_ti_t (g m) xs (index v' m)) \\<rbrakk>\n    \\<Longrightarrow> y = foldr (\\<lambda>n arr. Arrays.update arr n (update_ti_t (g n) (take v3 (drop (v3 * n) xs)) (index arr n))) [0 ..< n] v\"\n  apply (subgoal_tac \"\\<forall>ys. size_td_list (map f ys) = v3 * length ys\")\n   prefer 2\n   apply (rule allI, induct_tac ys, simp+)\n  apply (induct n arbitrary: xs y v)\n   apply simp\n  apply (simp add: access_ti_append)\n  apply (elim meta_allE, drule(1) meta_mp)\n  apply simp\n  apply (rule foldr_cong, (rule refl)+)\n  apply (simp add: take_drop)\n  apply (subst min.absorb1)\n   apply (fold mult_Suc_right, rule mult_le_mono2)\n   apply simp\n  apply simp\n  done\n\nlemma update_ti_list_array:\n  \"\\<lbrakk> update_ti_list_t (map f [0 ..< n]) xs v = (y :: 'a['b :: finite]);\n     \\<forall>n. size_td_pair (f n) = v3; length xs = v3 * n;\n     \\<forall>m xs v'. length xs = v3 \\<and> m < n \\<longrightarrow>\n       update_ti_pair_t (f m) xs v' = Arrays.update v' m (update_ti_t (g m) xs (index v' m));\n      n \\<le> card (UNIV :: 'b set) \\<rbrakk>\n    \\<Longrightarrow> \\<forall>m < n. update_ti_t (g m) (take v3 (drop (v3 * m) xs)) (index v m) = index y m\"\n  apply (subst update_ti_list_array'[where y=y], assumption+)\n  apply clarsimp\n  apply (subst index_fold_update)\n     apply clarsimp+\n  done\n\nlemma access_in_array:\n  fixes y :: \"('a :: c_type)['b :: finite]\"\n  assumes assms: \"h_val hp x = y\"\n                 \"n < card (UNIV :: 'b set)\"\n     and subst: \"\\<forall>xs v. length xs = size_of TYPE('a)\n                     \\<longrightarrow> update_ti_t (typ_info_t TYPE('a)) xs v = f xs\"\n  shows \"h_val hp\n           (Ptr (ptr_val x + of_nat (n * size_of TYPE('a)))) = index y n\"\n  using assms\n  apply (simp add: h_val_def drop_heap_list_le2 del: of_nat_mult)\n  apply (subst take_heap_list_le[symmetric, where n=\"card (UNIV :: 'b set) * size_of TYPE ('a)\"])\n   apply (fold mult_Suc, rule mult_le_mono1)\n   apply simp\n  apply (simp add: from_bytes_def typ_info_array')\n  apply (drule update_ti_list_array, simp+)\n     apply (simp add: size_of_def)\n    apply (clarsimp simp: update_ti_s_adjust_ti)\n    apply (rule refl)\n   apply simp\n  apply (drule spec, drule(1) mp)\n  apply (simp add: size_of_def ac_simps drop_take)\n  apply (subgoal_tac \"length v = size_of TYPE('a)\" for v)\n   apply (subst subst, assumption)\n   apply (subst(asm) subst, assumption)\n   apply simp\n  apply (simp add: size_of_def min.absorb_iff2[symmetric])\n  apply (subst le_diff_conv2)\n   apply simp\n  apply (fold mult_Suc, rule mult_le_mono1)\n  apply simp\n  done\n\nlemma access_ti_list_array:\n  \"\\<lbrakk> \\<forall>n. size_td_pair (f n) = v3; length xs = v3 * n;\n     \\<forall>m. m < n \\<and> v3 \\<le> length (drop (v3 * m) xs)\n        \\<longrightarrow> access_ti_pair (f m) (FCP g) (take v3 (drop (v3 * m) xs)) = (h m)\n          \\<rbrakk> \\<Longrightarrow>\n   access_ti_list (map f [0 ..< n]) (FCP g) xs\n     = foldl (@) [] (map h [0 ..< n])\"\n  apply (subgoal_tac \"\\<forall>ys. size_td_list (map f ys) = v3 * length ys\")\n   prefer 2\n   apply (rule allI, induct_tac ys, simp+)\n  apply (induct n arbitrary: xs)\n   apply simp\n  apply (simp add: access_ti_append)\n  apply (erule_tac x=\"take (v3 * n) xs\" in meta_allE)\n  apply simp\n  apply (frule spec, drule mp, rule conjI, rule lessI)\n   apply simp\n  apply simp\n  apply (erule meta_mp)\n  apply (auto simp add: drop_take)\n  done\n\ndefinition\n  array_ptr_index :: \"(('a :: c_type)['b :: finite]) ptr \\<Rightarrow> bool \\<Rightarrow> nat \\<Rightarrow> 'a ptr\"\nwhere\n  \"array_ptr_index p coerce n = CTypesDefs.ptr_add (ptr_coerce p)\n    (if coerce \\<and> n \\<ge> CARD ('b) then 0 else of_nat n)\"\n\nlemmas array_ptr_index_simps\n    = array_ptr_index_def[where coerce=False, simplified]\n        array_ptr_index_def[where coerce=True, simplified]\n\nlemma heap_update_Array:\n  \"heap_update (p ::('a::packed_type['b::finite]) ptr) arr\n     = (\\<lambda>s. foldl (\\<lambda>s n. heap_update (array_ptr_index p False n)\n                                     (Arrays.index arr n) s) s [0 ..< card (UNIV :: 'b set)])\"\n  apply (rule ext, simp add: heap_update_def)\n  apply (subst coerce_heap_update_to_heap_updates\n                 [OF _ refl, where chunk=\"size_of TYPE('a)\" and m=\"card (UNIV :: 'b set)\"])\n   apply simp\n  apply (rule foldl_cong[OF refl refl])\n  apply (simp add: array_ptr_index_def CTypesDefs.ptr_add_def)\n  apply (rule_tac f=\"\\<lambda>xs. heap_update_list p xs s\" for p s in arg_cong)\n  apply (simp add: to_bytes_def size_of_def\n                   packed_type_access_ti)\n  apply (simp add: typ_info_array')\n  apply (subst fcp_eta[symmetric], subst access_ti_list_array)\n     apply simp\n    apply simp\n   apply (simp add: packed_type_access_ti size_of_def)\n   apply fastforce\n  apply (rule take_drop_foldl_concat)\n   apply (simp add: size_of_def)\n  apply simp\n  done\n\nlemma from_bytes_Array_element:\n  fixes p :: \"('a::mem_type['b::finite]) ptr\"\n  assumes less: \"of_nat n < card (UNIV :: 'b set)\"\n  assumes len: \"length bs = size_of TYPE('a) * CARD('b)\"\n  shows\n  \"index (from_bytes bs :: 'a['b]) n\n      = from_bytes (take (size_of TYPE('a)) (drop (n * size_of TYPE('a)) bs))\"\n  using less\n  apply (simp add: from_bytes_def size_of_def typ_info_array')\n  apply (subst update_ti_list_array'[OF refl])\n     apply simp\n    apply (simp add: len size_of_def)\n   apply (clarsimp simp: update_ti_s_adjust_ti)\n   apply (rule refl)\n  apply (simp add: split_upt_on_n[OF less])\n  apply (rule trans, rule foldr_does_nothing_to_xf[where xf=\"\\<lambda>s. index s n\"])\n   apply simp+\n  apply (subst foldr_does_nothing_to_xf[where xf=\"\\<lambda>s. index s n\"])\n   apply simp\n  apply (simp add: mult.commute)\n  apply (frule Suc_leI)\n  apply (drule_tac k=\"size_of TYPE('a)\" in mult_le_mono2)\n  apply (rule upd_rf)\n  apply (simp add: size_of_def len mult.commute)\n  done\n\nlemma heap_access_Array_element':\n  fixes p :: \"('a::mem_type['b::finite]) ptr\"\n  assumes less: \"of_nat n < card (UNIV :: 'b set)\"\n  shows\n  \"index (h_val hp p) n\n      = h_val hp (array_ptr_index p False n)\"\n  using less\n  apply (simp add: array_ptr_index_def CTypesDefs.ptr_add_def h_val_def)\n  apply (simp add: from_bytes_Array_element)\n  apply (simp add: drop_heap_list_le take_heap_list_le)\n  apply (subst take_heap_list_le)\n   apply (simp add: le_diff_conv2)\n   apply (drule Suc_leI)\n   apply (drule_tac k=\"size_of TYPE('a)\" in mult_le_mono2)\n   apply (simp add: mult.commute)\n  apply simp\n  done\n\nlemmas heap_access_Array_element\n    = heap_access_Array_element'[simplified array_ptr_index_simps]\n\nlemma heap_update_id:\n  \"h_val hp ptr = (v :: 'a :: packed_type)\n      \\<Longrightarrow> heap_update ptr v hp = hp\"\n  apply (simp add: h_val_def heap_update_def)\n  apply (rule heap_update_list_id[where n=\"size_of TYPE('a)\"])\n  apply clarsimp\n  apply (simp add: from_bytes_def to_bytes_def update_ti_t_def\n                   size_of_def field_access_update_same\n                   td_fafu_idem)\n  done\n\nlemma fold_cong':\n  \"a = b \\<Longrightarrow> xs = ys \\<Longrightarrow> (\\<And>x. x \\<in> set xs =simp=> f x = g x)\n    \\<Longrightarrow> fold f xs a = fold g ys b\"\n  unfolding simp_implies_def\n  by (metis fold_cong)\n\nlemma intvl_empty2:\n  \"({p ..+ n} = {}) = (n = 0)\"\n  by (auto simp add: intvl_def)\n\nlemma heap_update_list_commute:\n  \"{p ..+ length xs} \\<inter> {q ..+ length ys} = {}\n      \\<Longrightarrow> heap_update_list p xs (heap_update_list q ys hp)\n        = heap_update_list q ys (heap_update_list p xs hp)\"\n  apply (cases \"length xs < addr_card\")\n   apply (cases \"length ys < addr_card\")\n    apply (rule ext, simp add: heap_update_list_value)\n    apply blast\n   apply (simp_all add: addr_card intvl_overflow intvl_empty2)\n  done\n\nlemma heap_update_commute:\n  \"\\<lbrakk> {ptr_val p ..+ size_of TYPE('a)} \\<inter> {ptr_val q ..+ size_of TYPE('b)} = {};\n       wf_fd (typ_info_t TYPE('a)); wf_fd (typ_info_t TYPE('b)) \\<rbrakk>\n        \\<Longrightarrow> heap_update p v (heap_update q (u :: 'b :: c_type) h)\n              = heap_update q u (heap_update p (v :: 'a :: c_type) h)\"\n  apply (simp add: heap_update_def)\n  apply (simp add: heap_update_list_commute heap_list_update_disjoint_same\n                   to_bytes_def length_fa_ti size_of_def Int_commute)\n  done\n\nlemma heap_update_Array_update:\n  assumes n: \"n < CARD('b :: finite)\"\n  assumes size: \"CARD('b) * size_of TYPE('a :: packed_type) < 2 ^ addr_bitsize\"\n  shows \"heap_update p (Arrays.update (arr :: 'a['b]) n v) hp\n       = heap_update (array_ptr_index p False n) v (heap_update p arr hp)\"\nproof -\n\n  have P: \"\\<And>x k. \\<lbrakk> x < CARD('b); k < size_of TYPE('a) \\<rbrakk>\n         \\<Longrightarrow> unat (of_nat x * of_nat (size_of TYPE('a)) + (of_nat k :: addr))\n                 = x * size_of TYPE('a) + k\"\n    using size\n    apply (case_tac \"size_of TYPE('a)\", simp_all)\n    apply (case_tac \"CARD('b)\", simp_all)\n    apply (subst unat_add_lem[THEN iffD1])\n     apply (simp add: unat_word_ariths unat_of_nat less_Suc_eq_le)\n     apply (subgoal_tac \"Suc x * size_of TYPE('a) < 2 ^ addr_bitsize\", simp_all)\n     apply (erule order_le_less_trans[rotated], simp add: add_mono)\n    apply (subst unat_mult_lem[THEN iffD1])\n     apply (simp add: unat_of_nat unat_add_lem[THEN iffD1])\n     apply (rule order_less_le_trans, erule order_le_less_trans[rotated],\n            rule add_mono, simp+)\n      apply (simp add: less_Suc_eq_le trans_le_add2)\n     apply simp\n    apply (simp add: unat_of_nat unat_add_lem[THEN iffD1])\n    done\n\n  let ?key_upd = \"heap_update (array_ptr_index p False n) v\"\n  note commute = fold_commute_apply[where h=\"?key_upd\"\n      and xs=\"[Suc n ..< CARD('b)]\", where g=f' and f=f' for f']\n\n  show ?thesis using n\n    apply (simp add: heap_update_Array split_upt_on_n[OF n]\n                     foldl_conv_fold)\n    apply (subst commute)\n     apply (simp_all add: packed_heap_update_collapse\n                    cong: fold_cong')\n    apply (rule ext, simp)\n    apply (rule heap_update_commute, simp_all add: ptr_add_def)\n    apply (simp add: array_ptr_index_def CTypesDefs.ptr_add_def intvl_def Suc_le_eq)\n    apply (rule set_eqI, clarsimp)\n    apply (drule word_unat.Rep_inject[THEN iffD2])\n    apply (clarsimp simp: P nat_eq_add_iff1)\n    apply (case_tac x, simp_all add: less_Suc_eq_le Suc_diff_le)\n    done\nqed\n\nlemma heap_update_id_Array:\n  fixes arr :: \"('a :: packed_type)['b :: finite]\"\n  shows \"arr = h_val hp p\n    \\<Longrightarrow> heap_update p arr hp = hp\"\n  apply (simp add: heap_update_Array)\n  apply (rule foldl_does_nothing[where s=hp])\n  apply (simp add: heap_access_Array_element' heap_update_id)\n  done\n\nlemma heap_update_Array_element'':\n  fixes p' :: \"(('a :: packed_type)['b::finite]) ptr\"\n  fixes p :: \"('a :: packed_type) ptr\"\n  fixes hp w\n  assumes p: \"p = array_ptr_index p' False n\"\n  assumes n: \"n < CARD('b)\"\n  assumes size: \"CARD('b) * size_of TYPE('a) < 2 ^ addr_bitsize\"\n  shows \"heap_update p' (Arrays.update (h_val hp p') n w) hp\n       = heap_update p w hp\"\n  apply (subst heap_update_Array_update[OF n size])\n  apply (simp add: heap_update_id_Array p)\n  done\n\nlemmas heap_update_Array_element'\n    = heap_update_Array_element''[simplified array_ptr_index_simps]\n\nlemma array_count_size:\n  \"CARD('b :: array_max_count) * size_of TYPE('a :: array_outer_max_size) < 2 ^ addr_bitsize\"\n  using array_outer_max_size_ax[where 'a='a] array_max_count_ax[where 'a='b]\n  apply (clarsimp dest!: nat_le_Suc_less_imp)\n  apply (drule(1) mult_mono, simp+)\n  done\n\nlemmas heap_update_Array_element\n    = heap_update_Array_element'[OF refl _ array_count_size]\n\nlemma typ_slice_list_cut:\n  \"\\<lbrakk> (\\<forall>x \\<in> set xs. size_td (dt_fst x) = m); m \\<noteq> 0; n < (length xs * m) \\<rbrakk>\n    \\<Longrightarrow> typ_slice_list xs n =\n      typ_slice_pair (xs ! (n div m)) (n mod m)\"\n  apply (induct xs arbitrary: n, simp_all)\n  apply (intro conjI impI)\n   apply simp\n  apply (subgoal_tac \"\\<exists>n'. n = n' + m\")\n   apply (clarsimp simp add: div_add1_eq)\n  apply (rule_tac x=\"n - m\" in exI)\n  apply simp\n  done\n\nlemma typ_slice_t_array:\n  \"\\<lbrakk> n < CARD('b); y < size_of TYPE('a) \\<rbrakk>\n   \\<Longrightarrow> typ_slice_t (export_uinfo (typ_info_t TYPE('a))) y \\<le>\n   typ_slice_t (export_uinfo (array_tag TYPE('a['b :: finite])))\n              (y + size_of TYPE('a :: mem_type) * n)\"\n  apply (simp add: array_tag_def array_tag_n_eq\n               split del: if_split)\n  apply (rule disjI2)\n  apply (subgoal_tac \"y + (size_of TYPE('a) * n) < CARD('b) * size_of TYPE('a)\")\n   apply (simp add: typ_slice_list_cut[where m=\"size_of TYPE('a)\"]\n                    map_td_list_map o_def size_of_def\n                    sz_nzero[unfolded size_of_def])\n   apply (simp add: export_uinfo_def[symmetric])\n  apply (rule_tac y=\"Suc n * size_of TYPE('a)\" in order_less_le_trans)\n   apply (simp add: size_of_def)\n  apply (simp only: size_of_def mult_le_mono1)\n  done\n\nlemma h_t_valid_Array_element':\n  \"\\<lbrakk> htd \\<Turnstile>\\<^sub>t (p :: (('a :: mem_type)['b :: finite]) ptr); coerce \\<or> n < CARD('b) \\<rbrakk>\n    \\<Longrightarrow> htd \\<Turnstile>\\<^sub>t array_ptr_index p coerce n\"\n  apply (clarsimp simp only: h_t_valid_def valid_footprint_def Let_def\n                             c_guard_def c_null_guard_def)\n  apply (subgoal_tac \"\\<exists>offs. array_ptr_index p coerce n = ptr_add (ptr_coerce p) (of_nat offs)\n        \\<and> offs < CARD ('b)\")\n   apply (clarsimp simp: size_td_array size_of_def typ_uinfo_t_def\n                         typ_info_array array_tag_def)\n   apply (intro conjI)\n     apply (clarsimp simp: CTypesDefs.ptr_add_def\n                           field_simps)\n     apply (drule_tac x=\"offs * size_of TYPE('a) + y\" in spec)\n     apply (drule mp)\n      apply (rule_tac y=\"Suc offs * size_of TYPE('a)\" in order_less_le_trans)\n       apply (simp add: size_of_def)\n      apply (simp only: size_of_def mult_le_mono1)\n     apply (clarsimp simp: field_simps)\n     apply (erule map_le_trans[rotated])\n     apply (rule list_map_mono)\n     apply (subst mult.commute, rule typ_slice_t_array[unfolded array_tag_def])\n      apply assumption\n     apply (simp add: size_of_def)\n    apply (simp add: ptr_aligned_def align_of_def align_td_array\n                     array_ptr_index_def\n                     CTypesDefs.ptr_add_def unat_word_ariths unat_of_nat)\n    using align_size_of[where 'a='a] align[where 'a='a]\n    apply (simp add: align_of_def size_of_def addr_card_def card_word)\n    apply (simp add: dvd_mod)\n   apply (thin_tac \"\\<forall>x. P x\" for P)\n   apply (clarsimp simp: intvl_def simp del: word_neq_0_conv)\n   apply (drule_tac x=\"offs * size_of TYPE('a) + k\" in spec)\n   apply (drule mp)\n    apply (simp add: array_ptr_index_def CTypesDefs.ptr_add_def field_simps)\n   apply (erule notE)\n   apply (rule_tac y=\"Suc offs * size_of TYPE('a)\" in order_less_le_trans)\n    apply (simp add: size_of_def)\n   apply (simp only: size_of_def mult_le_mono1)\n  apply (auto simp add: array_ptr_index_def intro: exI[where x=0])\n  done\n\nlemma h_t_valid_Array_element:\n  \"\\<lbrakk> htd \\<Turnstile>\\<^sub>t (p :: (('a :: mem_type)['b :: finite]) ptr); 0 \\<le> n; n < int CARD('b) \\<rbrakk>\n    \\<Longrightarrow> htd \\<Turnstile>\\<^sub>t ((ptr_coerce p :: 'a ptr) +\\<^sub>p n)\"\n  apply (drule_tac n=\"nat n\" and coerce=False in h_t_valid_Array_element')\n   apply simp\n  apply (simp add: array_ptr_index_def)\n  done\n\nlemma ptr_safe_Array_element:\n  \"\\<lbrakk> ptr_safe (p :: (('a :: mem_type)['b :: finite]) ptr) htd; coerce \\<or> n < CARD('b) \\<rbrakk>\n    \\<Longrightarrow> ptr_safe (array_ptr_index p coerce n) htd\"\n  apply (simp add: ptr_safe_def)\n  apply (erule order_trans[rotated])\n  apply (subgoal_tac \"\\<exists>offs. array_ptr_index p coerce n = ptr_add (ptr_coerce p) (of_nat offs)\n        \\<and> offs < CARD ('b)\")\n   prefer 2\n   apply (auto simp: array_ptr_index_def intro: exI[where x=0])[1]\n  apply (clarsimp simp: s_footprint_def s_footprint_untyped_def\n                        CTypesDefs.ptr_add_def\n                        size_td_array size_of_def)\n  apply (rule_tac x=\"offs * size_of TYPE('a) + x\" in exI)\n  apply (simp add: size_of_def)\n  apply (rule conjI)\n   apply (rule_tac y=\"Suc offs * size_of TYPE('a)\" in order_less_le_trans)\n    apply (simp add: size_of_def)\n   apply (simp only: size_of_def)\n   apply (rule mult_le_mono1)\n   apply simp\n  apply (thin_tac \"coerce \\<or> P\" for P)\n  apply (elim disjE exE conjE, simp_all add: typ_uinfo_t_def)\n  apply (erule order_less_le_trans)\n  apply (rule prefix_length_le)\n  apply (rule order_trans, erule typ_slice_t_array)\n   apply (simp add: size_of_def)\n  apply (simp add: size_of_def field_simps typ_info_array)\n  done\n\nlemma from_bytes_eq:\n  \"from_bytes [x] = x\"\n  by (clarsimp simp:from_bytes_def update_ti_t_def typ_info_word word_rcat_def)\n\nlemma bytes_disjoint:\"(x::('a::c_type) ptr) \\<noteq> y \\<Longrightarrow> {ptr_val x + a ..+ 1} \\<inter> {ptr_val y + a ..+ 1} = {}\"\n  by (clarsimp simp:intvl_def)\n\nlemma byte_ptrs_disjoint:\"(x::('a::c_type) ptr) \\<noteq> y \\<Longrightarrow> \\<forall>i < of_nat (size_of TYPE('a)). ptr_val x + i \\<noteq> ptr_val y + i\"\n  by force\n\nlemma le_step:\"\\<lbrakk>(x::('a::len) word) < y + 1; x \\<noteq> y\\<rbrakk> \\<Longrightarrow> x < y\"\n  by (metis less_x_plus_1 max_word_max order_less_le)\n\nlemma ptr_add_disjoint:\n  \"\\<lbrakk> ptr_val y \\<notin> {ptr_val x ..+ size_of TYPE('a)};\n     ptr_val (x::('a::c_type) ptr) < ptr_val (y::('b::c_type) ptr);\n     a < of_nat (size_of TYPE('a)) \\<rbrakk> \\<Longrightarrow>\n   ptr_val x + a < ptr_val y\"\n  apply (erule swap)\n  apply (rule intvl_inter_le [where k=0 and ka=\"unat (ptr_val y - ptr_val x)\"])\n    apply clarsimp\n   apply (metis (mono_tags) add_diff_cancel2 add_diff_inverse diff_add_cancel\n              trans_less_add1 unat_less_helper word_le_less_eq word_less_add_right\n              word_of_nat_less word_unat.Rep_inverse)\n  apply simp\n  done\n\nlemma ptr_add_disjoint2:\n  \"\\<lbrakk> ptr_val x \\<notin> {ptr_val y ..+ size_of TYPE('a)};\n     ptr_val (y::('b::c_type) ptr) < ptr_val (x::('a::c_type) ptr);\n     a < of_nat (size_of TYPE('a)) \\<rbrakk> \\<Longrightarrow>\n   ptr_val y + a < ptr_val x\"\n  apply (erule swap)\n  apply (rule intvl_inter_le[where k=0 and ka=\"unat (ptr_val x - ptr_val y)\"])\n    apply clarsimp\n   apply (metis (no_types) add.commute less_imp_le less_le_trans not_le unat_less_helper\n                word_diff_ls'(4))\n  apply simp\n  done\n\nlemma ptr_aligned_is_aligned:\"\\<lbrakk>ptr_aligned (x::('a::c_type) ptr); align_of TYPE('a) = 2 ^ n\\<rbrakk> \\<Longrightarrow> is_aligned (ptr_val x) n\"\n  by (clarsimp simp: ptr_aligned_def is_aligned_def)\n\nlemma intvl_no_overflow:\n  assumes no_overflow: \"unat a + b < 2 ^ len_of TYPE('a::len)\"\n  shows \"(x \\<in> {(a :: 'a word) ..+ b}) = (a \\<le> x \\<and> x < (a + of_nat b))\"\nproof -\n  obtain \"sk\" :: \"'a word \\<Rightarrow> 'a word \\<Rightarrow> nat \\<Rightarrow> nat\"\n      where f1: \"\\<And>x y z. x \\<notin> {y..+z} \\<or> x = y + of_nat (sk x y z) \\<and> sk x y z < z\"\n    using [[metis_new_skolem]] by (metis intvlD)\n\n  have f2: \"\\<And>x. a + x < a + of_nat b \\<or> \\<not> x < of_nat b\"\n    using no_overflow\n    by (metis PackedTypes.of_nat_mono_maybe_le add_lessD1 le_add1\n            add.commute olen_add_eqv unat_of_nat_eq word_arith_nat_add\n            word_plus_strict_mono_right)\n\n  have f3: \"\\<forall>x y. y \\<notin> {x..+b} \\<or> of_nat (sk y x b) < (of_nat b :: 'a word)\"\n    using no_overflow f1\n    by (metis add_lessD1 add.commute of_nat_mono_maybe)\n\n  have \"x < a + of_nat b \\<or> \\<not> of_nat (sk x a b) < (of_nat b :: 'a word) \\<or> ?thesis\"\n    using f1 f2 by metis\n\n  hence \"x < a + of_nat b \\<or> ?thesis\"\n    using f3 by metis\n\n  thus \"?thesis\"\n    apply (rule disjE)\n     apply (rule iffI)\n      apply (clarsimp simp: intvl_def)\n      apply (clarsimp simp: unat_sub_if_size word_le_nat_alt word_less_nat_alt)\n      apply (cut_tac no_overflow)\n      apply (subgoal_tac \"k + (b + unat a) < 2 ^ len_of (TYPE('a)) + b\")\n       apply (subgoal_tac \"k + unat a < 2 ^ len_of (TYPE('a))\")\n        apply (metis add_lessD1 le_def less_not_refl2 add.commute unat_eq_of_nat word_arith_nat_add)\n       apply clarsimp\n      apply clarsimp\n     apply (clarsimp simp: intvl_def)\n     apply (rule exI [where x=\"unat (x  - a)\"])\n     apply (clarsimp simp: unat_sub_if_size word_le_nat_alt word_less_nat_alt)\n     apply (cut_tac no_overflow)\n     apply (metis diff_le_self le_add_diff_inverse le_diff_conv le_eq_less_or_eq le_unat_uoi add.commute nat_neq_iff unat_of_nat_eq word_arith_nat_add)\n    apply simp\n    done\nqed\n\n(* arg_cong specified for FCP because it does not apply as is. *)\nlemma FCP_arg_cong:\"f = g \\<Longrightarrow> FCP f = FCP g\"\n  by simp\n\nlemma h_val_id:\n    \"h_val (hrs_mem (hrs_mem_update (heap_update x y) s)) x = (y::'a::mem_type)\"\n  apply (subst hrs_mem_update)\n  apply (rule h_val_heap_update)\n  done\n\nlemma heap_update_id2:\n    \"hrs_mem_update (heap_update p ((h_val (hrs_mem s) p)::'a::packed_type)) s = s\"\n  apply (clarsimp simp:hrs_mem_update_def case_prod_beta)\n  apply (subst heap_update_id)\n   apply (simp add:hrs_mem_def)+\n  done\n\nlemma intvlI_unat:\"unat b < unat c \\<Longrightarrow> a + b \\<in> {a ..+ unat c}\"\n  by (metis intvlI word_unat.Rep_inverse)\n\nlemma neq_imp_bytes_disjoint:\n  \"\\<lbrakk> c_guard (x::'a::c_type ptr); c_guard y; unat j < align_of TYPE('a);\n        unat i < align_of TYPE('a); x \\<noteq> y; 2 ^ n = align_of TYPE('a); n < 32\\<rbrakk> \\<Longrightarrow>\n    ptr_val x + j \\<noteq> ptr_val y + i\"\n  apply (rule ccontr)\n  apply (subgoal_tac \"is_aligned (ptr_val x) n\")\n   apply (subgoal_tac \"is_aligned (ptr_val y) n\")\n    apply (subgoal_tac \"(ptr_val x + j && ~~ mask n) = (ptr_val y + i && ~~ mask n)\")\n     apply (subst (asm) neg_mask_add_aligned, simp, simp add: word_less_nat_alt)\n     apply (subst (asm) neg_mask_add_aligned, simp, simp add: word_less_nat_alt)\n     apply clarsimp\n    apply simp\n   apply (clarsimp simp: c_guard_def ptr_aligned_def is_aligned_def)\n  apply (clarsimp simp: c_guard_def ptr_aligned_def is_aligned_def)\n  done\n\nlemma heap_update_list_base':\"heap_update_list p [] = id\"\n  by (rule ext, simp)\n\nlemma hrs_mem_update_id3: \"hrs_mem_update id = id\"\n  unfolding hrs_mem_update_def by simp\n\nabbreviation\n  ptr_span :: \"'a::mem_type ptr \\<Rightarrow> addr set\" where\n  \"ptr_span p \\<equiv> {ptr_val p ..+ size_of TYPE('a)}\"\n\nabbreviation (input)\n  cptr_type :: \"('a :: c_type) ptr \\<Rightarrow> 'a itself\"\nwhere\n  \"cptr_type p \\<equiv> TYPE('a)\"\n\nlemma ptr_retyp_valid_footprint_disjoint2:\n  \"\\<lbrakk>valid_footprint (ptr_retyp (q::'b::mem_type ptr) d) p s; {p..+size_td s} \\<inter> {ptr_val q..+size_of TYPE('b)} = {} \\<rbrakk>\n     \\<Longrightarrow> valid_footprint d p s\"\n  apply(clarsimp simp: valid_footprint_def Let_def)\n  apply (drule spec, drule (1) mp)\n  apply(subgoal_tac \"p + of_nat y \\<in> {p..+size_td s}\")\n  apply (subst (asm) ptr_retyp_d)\n    apply clarsimp\n    apply fast\n   apply (clarsimp simp add: ptr_retyp_d_eq_fst split: if_split_asm)\n   apply fast\n  apply (erule intvlI)\n  done\n\nlemma ptr_retyp_disjoint2:\n  \"\\<lbrakk>ptr_retyp (p::'a::mem_type ptr) d,g \\<Turnstile>\\<^sub>t q;\n    {ptr_val p..+size_of TYPE('a)} \\<inter> {ptr_val q..+size_of TYPE('b)} = {} \\<rbrakk>\n  \\<Longrightarrow> d,g \\<Turnstile>\\<^sub>t (q::'b::mem_type ptr)\"\n  apply(clarsimp simp: h_t_valid_def)\n  apply(erule ptr_retyp_valid_footprint_disjoint2)\n  apply(simp add: size_of_def)\n  apply fast\n  done\n\nlemma ptr_retyp_disjoint_iff:\n  \"{ptr_val p..+size_of TYPE('a)} \\<inter> {ptr_val q..+size_of TYPE('b)} = {}\n  \\<Longrightarrow> ptr_retyp (p::'a::mem_type ptr) d,g \\<Turnstile>\\<^sub>t q = d,g \\<Turnstile>\\<^sub>t (q::'b::mem_type ptr)\"\n  apply rule\n   apply (erule (1) ptr_retyp_disjoint2)\n  apply (erule (1) ptr_retyp_disjoint)\n  done\n\nlemma h_t_valid_ptr_retyp_eq:\n  \"\\<not> cptr_type p <\\<^sub>\\<tau> cptr_type p' \\<Longrightarrow> h_t_valid (ptr_retyp p td) g p'\n    = (if ptr_span p \\<inter> ptr_span p' = {} then h_t_valid td g p'\n        else field_of_t p' p \\<and> g p')\"\n  apply (clarsimp simp: ptr_retyp_disjoint_iff split: if_split)\n  apply (cases \"g p'\")\n   apply (rule iffI)\n    apply (rule ccontr, drule h_t_valid_neq_disjoint, rule ptr_retyp_h_t_valid, simp+)\n    apply (simp add: Int_commute)\n   apply (clarsimp simp: field_of_t_def field_of_def)\n   apply (drule sub_h_t_valid[where p=p, rotated], rule ptr_retyp_h_t_valid, simp, simp)\n   apply (erule(1) h_t_valid_guard_subst)\n  apply (simp add: h_t_valid_def)\n  done\n\nlemma field_lookup_list_Some_again:\n  \"dt_snd (xs ! i) = f\n    \\<Longrightarrow> i < length xs\n    \\<Longrightarrow> f \\<notin> dt_snd ` set ((take i xs))\n    \\<Longrightarrow> field_lookup_list xs [f] n\n        = Some (dt_fst (xs ! i), n + sum_list (map (size_td o dt_fst) (take i xs)))\"\n  apply (induct xs arbitrary: i n, simp_all)\n  apply (case_tac x1, simp)\n  apply (case_tac i, auto split: if_split)\n  done\n\nlemma field_lookup_array:\n  \"n < CARD('b) \\<Longrightarrow> field_lookup (typ_info_t TYPE(('a :: c_type)['b :: finite]))\n    [replicate n (CHR ''1'')] i = Some (adjust_ti (typ_info_t TYPE('a))\n        (\\<lambda>x. x.[n]) (\\<lambda>x f. Arrays.update f n x), i + n * size_of TYPE ('a))\"\n  apply (simp add: typ_info_array array_tag_def array_tag_n_eq)\n  apply (subst field_lookup_list_Some_again[where i=n],\n    auto simp add: take_map o_def sum_list_triv size_of_def)\n  done\n\nlemma field_of_t_refl:\n  \"field_of_t p p' = (p = p')\"\n  apply (safe, simp_all add: field_of_t_def)\n  apply (simp add: field_of_def)\n  apply (drule td_set_size_lte)\n  apply (simp add: unat_eq_0)\n  done\n\nlemma ptr_retyp_same_cleared_region:\n  fixes p :: \"'a :: mem_type ptr\" and p' :: \"'a :: mem_type ptr\"\n  assumes  ht: \"ptr_retyp p td, g \\<Turnstile>\\<^sub>t p'\"\n  shows \"p = p' \\<or> {ptr_val p..+ size_of TYPE('a)} \\<inter> {ptr_val p' ..+ size_of TYPE('a)} = {}\"\n  using ht\n  by (simp add: h_t_valid_ptr_retyp_eq[where p=p and p'=p'] field_of_t_refl\n         split: if_split_asm)\n\nlemma h_t_valid_ptr_retyp_inside_eq:\n  fixes p :: \"'a :: mem_type ptr\" and p' :: \"'a :: mem_type ptr\"\n  assumes inside: \"ptr_val p' \\<in> {ptr_val p ..+ size_of TYPE('a)}\"\n  and         ht: \"ptr_retyp p td, g \\<Turnstile>\\<^sub>t p'\"\n  shows   \"p = p'\"\n  using ptr_retyp_same_cleared_region[OF ht] inside mem_type_self[where p=p']\n  by blast\n\nlemma typ_slice_t_self_nth:\n  \"\\<exists>n < length (typ_slice_t td m). \\<exists>b. typ_slice_t td m ! n = (td, b)\"\n  using typ_slice_t_self [where td = td and m = m]\n  by (fastforce simp add: in_set_conv_nth)\n\nlemma ptr_retyp_other_cleared_region:\n  fixes p :: \"'a :: mem_type ptr\" and p' :: \"'b :: mem_type ptr\"\n  assumes  ht: \"ptr_retyp p td, g \\<Turnstile>\\<^sub>t p'\"\n  and   tdisj: \"typ_uinfo_t TYPE('a) \\<bottom>\\<^sub>t typ_uinfo_t TYPE('b :: mem_type)\"\n  and   clear: \"\\<forall>x \\<in> {ptr_val p ..+ size_of TYPE('a)}. \\<forall>n b. snd (td x) n \\<noteq> Some (typ_uinfo_t TYPE('b), b)\"\n  shows \"{ptr_val p'..+ size_of TYPE('b)} \\<inter> {ptr_val p ..+ size_of TYPE('a)} = {}\"\nproof (rule classical)\n  assume asm: \"{ptr_val p'..+ size_of TYPE('b)} \\<inter> {ptr_val p ..+ size_of TYPE('a)} \\<noteq> {}\"\n  then obtain mv where mvp: \"mv \\<in> {ptr_val p..+size_of TYPE('a)}\"\n    and mvp': \"mv \\<in> {ptr_val p'..+size_of TYPE('b)}\"\n      by blast\n\n  then obtain k' where mv: \"mv = ptr_val p' + of_nat k'\" and klt: \"k' < size_td (typ_info_t TYPE('b))\"\n    by (clarsimp dest!: intvlD simp: size_of_def)\n\n  let ?mv = \"ptr_val p' + of_nat k'\"\n\n  obtain n b where nl: \"n < length (typ_slice_t (typ_uinfo_t TYPE('b)) k')\"\n    and tseq: \"typ_slice_t (typ_uinfo_t TYPE('b)) k' ! n = (typ_uinfo_t TYPE('b), b)\"\n    using typ_slice_t_self_nth [where td = \"typ_uinfo_t TYPE('b)\" and m = k']\n    by clarsimp\n\n  with ht have \"snd (ptr_retyp p td ?mv) n = Some (typ_uinfo_t TYPE('b), b)\"\n    unfolding h_t_valid_def\n    apply -\n    apply (clarsimp simp: valid_footprint_def Let_def)\n    apply (drule spec, drule mp [OF _ klt])\n    apply (clarsimp simp: map_le_def)\n    apply (drule bspec)\n    apply simp\n    apply simp\n    done\n\n  moreover {\n    assume \"snd (ptr_retyp p empty_htd ?mv) n = Some (typ_uinfo_t TYPE('b), b)\"\n    hence \"(typ_uinfo_t TYPE('b)) \\<in> fst ` set (typ_slice_t (typ_uinfo_t TYPE('a))\n                                                 (unat (ptr_val p' + of_nat k' - ptr_val p)))\"\n      using asm mv mvp\n      apply -\n      apply (rule_tac x = \"(typ_uinfo_t TYPE('b), b)\" in image_eqI)\n       apply simp\n      apply (fastforce simp add: ptr_retyp_footprint list_map_eq in_set_conv_nth split: if_split_asm)\n      done\n\n    with typ_slice_set have \"(typ_uinfo_t TYPE('b)) \\<in> fst ` td_set (typ_uinfo_t TYPE('a)) 0\"\n      by (rule subsetD)\n\n    hence False using tdisj by (clarsimp simp: tag_disj_def typ_tag_le_def)\n  } ultimately show ?thesis using mvp mvp' mv unfolding h_t_valid_def valid_footprint_def\n    apply -\n    apply (subst (asm) ptr_retyp_d_eq_snd)\n    apply (auto simp add: map_add_Some_iff clear)\n    done\nqed\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/c-parser/LemmaBucket_C.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.603931819468636, "lm_q2_score": 0.43014734858584286, "lm_q1q2_score": 0.2597796708710577}}
{"text": "section {*LR1\\_Property\\_Satisfaction\\_\\_compute\\_latest\\_production*}\ntheory\n  LR1_Property_Satisfaction__compute_latest_production\n\nimports\n  PRJ_12_04_06_06_12__ENTRY\n\nbegin\n\ndeclare [[ hypsubst_thin = false ]]\ndatatype DT_revert_position =\n  elim \"nat\"\n  | gen \"nat\" \"nat\"\ndeclare [[ hypsubst_thin = true ]]\n\ndefinition Pident_line :: \"\n  ('q, 's, 't) PSplitItem\n  \\<Rightarrow> bool\"\n  where\n    \"Pident_line S \\<equiv>\n  PSplitItem_prods S = []\n  \\<and> PSplitItem_elim S = []\"\n\ndefinition Pident_lines :: \"\n  ('q, 's, 't) PSplit\n  \\<Rightarrow> nat set\"\n  where\n    \"Pident_lines S \\<equiv>\n  {n. n < length S \\<and> Pident_line (S ! n)}\"\n\ndefinition first_empty_rhs :: \"\n  (('q, 's) DT_l2_l3_nonterminals, 't) cfg_step_label list\n  \\<Rightarrow> (('q, 's) DT_l2_l3_nonterminals, 't) cfg_step_label\"\n  where\n    \"first_empty_rhs w \\<equiv>\n  THE p.\n      \\<exists>i.\n        w ! i = p\n        \\<and> prod_rhs p = []\n        \\<and> (\\<forall>j < i. prod_rhs (w ! j) \\<noteq> [])\"\n\ndefinition get_prod_at_DT_revert_position :: \"\n  ('q, 's, 't) PSplit\n  \\<Rightarrow> DT_revert_position\n  \\<Rightarrow> (('q, 's) DT_l2_l3_nonterminals, 't) cfg_step_label\"\n  where\n    \"get_prod_at_DT_revert_position S rp \\<equiv>\n  case rp of\n  elim n \\<Rightarrow> first_empty_rhs (hd (PSplitItem_elim_prods (S ! n)))\n  | gen n m \\<Rightarrow> hd (filterB [PSplitItem_prods (S ! n) ! m])\"\n\ndefinition valid_DT_revert_position :: \"\n  ('q, 's, 't) PSplit\n  \\<Rightarrow> DT_revert_position\n  \\<Rightarrow> bool\"\n  where\n    \"valid_DT_revert_position S rp \\<equiv>\n  case rp of\n  elim n \\<Rightarrow>\n    n < length S\n    \\<and> PSplitItem_elim (S ! n) \\<noteq> []\n  | gen n m \\<Rightarrow>\n    n < length S\n    \\<and> m < length (PSplitItem_prods (S ! n))\n    \\<and> setA [PSplitItem_prods (S ! n) ! m] = {}\"\n\ndefinition before_ident_line :: \"\n  ('q, 's, 't) PSplit\n  \\<Rightarrow> nat\n  \\<Rightarrow> bool\"\n  where\n    \"before_ident_line S n \\<equiv>\n  \\<forall>i < n. \\<not> Pident_line (S ! i)\"\n\ndefinition get_line :: \"\n  DT_revert_position\n  \\<Rightarrow> nat\"\n  where\n    \"get_line rp \\<equiv>\n  case rp of\n  elim n \\<Rightarrow> n\n  | gen n m \\<Rightarrow> n\"\n\ndefinition is_DT_revert_position :: \"\n  ('q, 's, 't) PSplit\n  \\<Rightarrow> DT_revert_position\n  \\<Rightarrow> bool\"\n  where\n    \"is_DT_revert_position S rp \\<equiv>\n  valid_DT_revert_position S rp\n  \\<and> before_ident_line S (get_line rp)\n  \\<and> (case rp of\n    elim n \\<Rightarrow> True\n    | gen n m \\<Rightarrow> (\n        let\n          prod = get_prod_at_DT_revert_position S rp\n        in\n          (prod_rhs prod = [] \\<and> Suc m < length (PSplitItem_prods (S ! n)))\n          \\<or> (Suc n \\<in> Pident_lines S \\<and> Suc m = length (PSplitItem_prods (S ! n)))))\"\n\ndefinition get_pos :: \"\n  DT_revert_position\n  \\<Rightarrow> nat\"\n  where\n    \"get_pos rp \\<equiv>\n  case rp of\n  elim n \\<Rightarrow> 0\n  | gen n m \\<Rightarrow> Suc m\"\n\ndefinition leq :: \"\n  DT_revert_position\n  \\<Rightarrow> DT_revert_position\n  \\<Rightarrow> bool\"\n  where\n    \"leq rp1 rp2 \\<equiv>\n  get_line rp1 < get_line rp2\n  \\<or> (get_line rp1 = get_line rp2\n     \\<and> get_pos rp1 \\<le> get_pos rp2)\"\n\ndefinition get_DT_revert_position :: \"\n  ('q, 's, 't) PSplit\n  \\<Rightarrow> DT_revert_position option\"\n  where\n    \"get_DT_revert_position S \\<equiv>\n  if \\<exists>rp. is_DT_revert_position S rp\n  then Some (THE rp.\n                is_DT_revert_position S rp\n                \\<and> (\\<forall>rp'. is_DT_revert_position S rp' \\<longrightarrow> leq rp rp'))\n  else None\"\n\ndefinition get_revert_prod :: \"\n  ('q, 's, 't) PSplit\n  \\<Rightarrow> (('q, 's) DT_l2_l3_nonterminals, 't) cfg_step_label option\"\n  where\n    \"get_revert_prod S \\<equiv>\n  case get_DT_revert_position S of\n  None \\<Rightarrow> None\n  | Some rp \\<Rightarrow> Some (get_prod_at_DT_revert_position S rp)\"\n\nlemma get_DT_revert_position_eq: \"\n  is_DT_revert_position S rp\n  \\<Longrightarrow> (THE rp. is_DT_revert_position S rp \\<and> (\\<forall>rp'. is_DT_revert_position S rp' \\<longrightarrow> leq rp rp')) = p\n  \\<Longrightarrow> get_DT_revert_position S = Some p\"\n  apply(simp add: get_DT_revert_position_def)\n  apply(force)\n  done\n\nlemma leq_leq_eq: \"\n  leq x y\n  \\<Longrightarrow> leq y x\n  \\<Longrightarrow> x=y\"\n  apply(simp add: leq_def)\n  apply(case_tac x)\n   apply(rename_tac nat)(*strict*)\n   apply(case_tac y)\n    apply(rename_tac nat nata)(*strict*)\n    apply(simp add: leq_def get_line_def get_pos_def)\n    apply(clarsimp)\n   apply(rename_tac nat nat1 nat2)(*strict*)\n   apply(simp add: leq_def get_line_def get_pos_def)\n  apply(rename_tac nat1 nat2)(*strict*)\n  apply(case_tac y)\n   apply(rename_tac nat1 nat2 nat)(*strict*)\n   apply(simp add: leq_def get_line_def get_pos_def)\n  apply(rename_tac nat1 nat2 nat1a nat2a)(*strict*)\n  apply(clarsimp)\n  apply(simp add: leq_def get_line_def get_pos_def)\n  apply(force)\n  done\n\nlemma THE_get_DT_revert_position_eq: \"\n  is_DT_revert_position S rp\n  \\<Longrightarrow> (\\<forall>rp'. is_DT_revert_position S rp' \\<longrightarrow> leq rp rp')\n  \\<Longrightarrow> (THE rp. is_DT_revert_position S rp \\<and> (\\<forall>rp'. is_DT_revert_position S rp' \\<longrightarrow> leq rp rp')) = rp\"\n  apply(rule the_equality)\n   apply(force)\n  apply(rename_tac rpa)(*strict*)\n  apply(clarsimp)\n  apply(rule leq_leq_eq)\n   apply(rename_tac rpa)(*strict*)\n   apply(force)\n  apply(rename_tac rpa)(*strict*)\n  apply(force)\n  done\n\nlemma get_DT_revert_position_eq2: \"\n  is_DT_revert_position S rp\n  \\<Longrightarrow> (is_DT_revert_position S rp \\<Longrightarrow> (\\<forall>rp'. is_DT_revert_position S rp' \\<longrightarrow> leq rp rp'))\n  \\<Longrightarrow> get_DT_revert_position S = Some rp\"\n  apply(rule get_DT_revert_position_eq)\n   apply(force)\n  apply(rule THE_get_DT_revert_position_eq)\n   apply(force)\n  apply(force)\n  done\n\nlemma leq_gen_elim: \"\n  m<n\n  \\<Longrightarrow> leq (gen m x) (elim n)\"\n  apply(simp add: leq_def get_line_def get_pos_def)\n  done\n\nlemma first_empty_rhs_with_left_degen_front: \"\n  valid_cfg G\n  \\<Longrightarrow> cfgLM.trans_der G d c \\<pi> c'\n  \\<Longrightarrow> left_degen G d\n  \\<Longrightarrow> first_empty_rhs\n           (\\<pi> @ \\<lparr>prod_lhs = A, prod_rhs = []\\<rparr> # w) = \\<lparr>prod_lhs = A, prod_rhs = []\\<rparr>\"\n  apply(simp add: first_empty_rhs_def)\n  apply(rule the_equality)\n   apply(rule_tac\n      x=\"length \\<pi>\"\n      in exI)\n   apply(clarsimp)\n   apply(rename_tac j)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac j)(*strict*)\n    prefer 2\n    apply(rule_tac\n      G=\"G\"\n      and d=\"d\"\n      and i=\"j\"\n      and kleene_starT=\"False\"\n      and END=\"False\"\n      in cfgLM.trans_der_step_detail)\n      apply(rename_tac j)(*strict*)\n      apply(force)\n     apply(rename_tac j)(*strict*)\n     apply(force)\n    apply(rename_tac j)(*strict*)\n    apply(force)\n   apply(rename_tac j)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac j e ci ci')(*strict*)\n   apply(simp add: cfgLM_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac j e ci ci' l r)(*strict*)\n   apply(simp add: left_degen_def)\n   apply(simp add: sat_refined_def)\n   apply(erule_tac\n      x=\"j\"\n      in allE)\n   apply(clarsimp)\n   apply(rename_tac j e ci ci' l r wa Aa waa)(*strict*)\n   apply (metis list.simps(2) nth_append_1)\n  apply(rename_tac p)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(case_tac \"i=length \\<pi>\")\n   apply(rename_tac i)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(case_tac \"i>length \\<pi>\")\n   apply(rename_tac i)(*strict*)\n   apply(force)\n  apply(rename_tac i)(*strict*)\n  apply(subgoal_tac \"i<length \\<pi>\")\n   apply(rename_tac i)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac i)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"False\")\n   apply(rename_tac i)(*strict*)\n   apply(force)\n  apply(rename_tac i)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac i)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"G\"\n      and d=\"d\"\n      and i=\"i\"\n      and kleene_starT=\"False\"\n      and END=\"False\"\n      in cfgLM.trans_der_step_detail)\n     apply(rename_tac i)(*strict*)\n     apply(force)\n    apply(rename_tac i)(*strict*)\n    apply(force)\n   apply(rename_tac i)(*strict*)\n   apply(force)\n  apply(rename_tac i)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i e ci ci')(*strict*)\n  apply(simp add: cfgLM_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac i e ci ci' l r)(*strict*)\n  apply(simp add: left_degen_def)\n  apply(simp add: sat_refined_def)\n  apply(thin_tac \"\\<forall>j<i. prod_rhs ((\\<pi> @ \\<lparr>prod_lhs = A, prod_rhs = []\\<rparr> # w) ! j) \\<noteq> []\")\n  apply(erule_tac\n      x=\"i\"\n      in allE)\n  apply(clarsimp)\n  apply(rename_tac i e ci ci' l r wa Aa waa)(*strict*)\n  apply (metis list.simps(2) nth_append_1)\n  done\n\nlemma leq_elim_elim: \"\n  n\\<le>m\n  \\<Longrightarrow> leq (elim n) (elim m)\"\n  apply(simp add: leq_def get_line_def get_pos_def)\n  apply(force)\n  done\n\nlemma leq_elim_gen: \"\n  n\\<le>m\n  \\<Longrightarrow> leq (elim n) (gen m x)\"\n  apply(simp add: leq_def get_line_def get_pos_def)\n  apply(force)\n  done\n\nlemma get_revert_prod_sound_rhs_empty: \"\n       F2LR1inputx G G'\n  \\<Longrightarrow> split_TSstructure G\n  \\<Longrightarrow> EValidSplit G (S1 @ SL # S2 # Sb)\n  \\<Longrightarrow> EValidSplit G (S1 @ Xstep_mergeL (Xstep_elem SL \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = r\\<rparr> # Xstep_gen (filterA (tl r)) (ESplitItem_to SL @ ESplitItem_ignore SL)) (Some S2) @ Sb)\n  \\<Longrightarrow> EValidSplitExt (S1 @ SL # S2 # Sb)\n  \\<Longrightarrow> EValidSplitExt (S1 @ Xstep_mergeL (Xstep_elem SL \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = r\\<rparr> # Xstep_gen (filterA (tl r)) (ESplitItem_to SL @ ESplitItem_ignore SL)) (Some S2) @ Sb)\n  \\<Longrightarrow> Esplit_signature (Xstep_mergeL (Xstep_elem SL \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = r\\<rparr> # Xstep_gen (filterA (tl r)) (ESplitItem_to SL @ ESplitItem_ignore SL)) (Some S2)) = r @ [teB b]\n  \\<Longrightarrow> setA (Esplit_signature Sb) = {}\n  \\<Longrightarrow> \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = r\\<rparr> \\<in> cfg_productions G\n  \\<Longrightarrow> ESplitItem_elem SL = Some (teA (cons_l3   q1 X q2))\n  \\<Longrightarrow> length (Esplit_signature S1) = length S1\n  \\<Longrightarrow> ESplitItem_elem S2 = Some (teB b)\n  \\<Longrightarrow> length (nat_seq 0 (length S1)) = Suc (length S1)\n  \\<Longrightarrow> nat_seq 0 (length S1) ! length S1 = length S1\n  \\<Longrightarrow> r = []\n  \\<Longrightarrow> get_revert_prod (restrict G' G \n          (S1 @ Xstep_mergeL (Xstep_elem SL \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = r\\<rparr> # Xstep_gen (filterA (tl r)) (ESplitItem_to SL @ ESplitItem_ignore SL)) (Some S2) @ Sb) (Suc (length S1 + length r))) \n  = Some \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = r\\<rparr>\"\n  apply(simp add: Xstep_gen_def)\n  apply(simp add: Xstep_mergeL_def Xstep_elem_def nth_opt_def)\n  apply(case_tac SL)\n  apply(rename_tac ESplitItem_elim ESplitItem_from ESplitItem_ignore ESplitItem_elim_prods ESplitItem_prodsa ESplitItem_elema ESplitItem_to)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ESplitItem_elim ESplitItem_from ESplitItem_ignore ESplitItem_elim_prods ESplitItem_prods ESplitItem_to)(*strict*)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(simp add: Xstep_merge1_def)\n  apply(rule conjI)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(clarsimp)\n   apply(simp add: Xstep_merge1_toWasNotEliminated_def)\n   apply(simp add: get_revert_prod_def)\n   apply(subgoal_tac \"get_DT_revert_position (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb) (Suc (length S1))) = Some (gen (length S1) (length \\<pi>))\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(simp add: get_prod_at_DT_revert_position_def)\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"restrict_newprods G' G (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr>]) (length S1) ! length \\<pi>\"\n      and s=\"teB \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr>\"\n      in ssubst)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(simp add: restrict_newprods_def restrict_newprodsX_def)\n    apply(rule_tac\n      t=\"(map SSf SSw)!SSn\" for SSf SSw SSn\n      in ssubst)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(rule nth_map)\n     apply(rule_tac\n      t=\"length (nat_seq 0 n)\" for n\n      in ssubst)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(rule nat_seq_length_prime)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"liftB (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2) ! length \\<pi>\"\n      in ssubst)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(rule liftB_nth)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"nat_seq 0 SSX ! SSY\" for SSX SSY\n      in ssubst)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(rule nat_seq_nth_compute)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(simp add: restrict_newprodsXX_def)\n    apply(subgoal_tac \"derives G (\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2) = []\")\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(simp add: strict_prefix_def option_to_list_def)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(rule_tac\n      G=\"G\"\n      in derive_empty_if_first_prod_has_empty_rhs)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(simp add: split_TSstructure_def)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(subgoal_tac \"EValidSplit_ValidItem G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb)\")\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n      prefer 2\n      apply(simp add: EValidSplit_def)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(simp add: EValidSplit_ValidItem_def EValidSplitItem_def EValidSplitItem_belongs_def)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(force)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(rule_tac\n      rp=\"gen (length S1) (length \\<pi>)\"\n      in get_DT_revert_position_eq2)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(simp add: is_DT_revert_position_def)\n    apply(rule_tac\n      t=\"before_ident_line (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb) (Suc (length S1))) (get_line (gen (length S1) (length \\<pi>)))\"\n      and s=\"True\"\n      in ssubst)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(simp add: before_ident_line_def get_line_def)\n     apply(clarsimp)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(subgoal_tac \"EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      prefer 2\n      apply(simp add: EValidSplitExt_def)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(simp add: EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal_def)\n     apply(erule_tac\n      x=\"length S1\"\n      in allE)\n     apply(clarsimp)\n     apply(erule_tac\n      x=\"i\"\n      in allE)\n     apply(clarsimp)\n     apply(subgoal_tac \"\\<not> Pident_line (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb) (Suc (length S1)) ! i)\")\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(simp add: Eident_lines_def Eident_line_def Pident_line_def)\n     apply(clarsimp)\n     apply(subgoal_tac \"nat_seq 0 (length S1) ! i = SSX\" for SSX)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      prefer 2\n      apply(rule nat_seq_nth_compute)\n       apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n       apply(force)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(simp add: Pident_line_def)\n     apply(subgoal_tac \"length(restrict_newprods G' G (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr>]) i) = length(ESplitItem_prods ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! i))\")\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      apply(clarsimp)\n      apply(subgoal_tac \"length(ESplitItem_elim ((S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr>]) ! i)) = length(ESplitItem_elim ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! i))\")\n       apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n       apply(force)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      apply(rule_tac\n      t=\"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr>]) ! i\"\n      in ssubst)\n       apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n       apply(rule nth_append_1)\n       apply(force)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      apply(rule_tac\n      t=\"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! i\"\n      in ssubst)\n       apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n       apply(rule nth_append_1)\n       apply(force)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(rule_tac\n      t=\"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! i\"\n      in ssubst)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      apply(rule nth_append_1)\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(rule restrict_newprods_preserves_length)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"(map SSf SSw)!SSn\" for SSf SSw SSn\n      in ssubst)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(rule nth_map)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(subgoal_tac \"length (restrict_newprods G' G (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr>]) (length S1)) = length(\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2)\")\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(clarsimp)\n     apply(simp add: valid_DT_revert_position_def)\n     apply(simp add: get_prod_at_DT_revert_position_def)\n     apply(rule_tac\n      t=\"(map SSf SSw)!SSn\" for SSf SSw SSn\n      in ssubst)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(rule nth_map)\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(case_tac \"foldl (@) [] (ESplitItem_elim_prods S2) = [] \\<and> ESplitItem_prods S2 = []\")\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(clarsimp)\n      apply(subgoal_tac \"EValidSplit_ValidItem G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb)\")\n       apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n       prefer 2\n       apply(simp add: EValidSplit_def)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(simp add: EValidSplit_ValidItem_def EValidSplitItem_def EValidSplitItem_gen_def)\n      apply(clarsimp)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to d)(*strict*)\n      apply(subgoal_tac \"X\" for X)\n       apply(rename_tac el fr ig el\\<pi> \\<pi> to d)(*strict*)\n       prefer 2\n       apply(rule_tac\n      G=\"G\"\n      and d=\"d\"\n      and i=\"length \\<pi>\"\n      and kleene_starT=\"False\"\n      and END=\"True\"\n      in cfgLM.trans_der_step_detail)\n         apply(rename_tac el fr ig el\\<pi> \\<pi> to d)(*strict*)\n         apply(simp add: split_TSstructure_def)\n        apply(rename_tac el fr ig el\\<pi> \\<pi> to d)(*strict*)\n        apply(force)\n       apply(rename_tac el fr ig el\\<pi> \\<pi> to d)(*strict*)\n       apply(force)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to d)(*strict*)\n      apply(simp add: cfgLM_step_relation_def)\n      apply(clarsimp)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to d e ci l r)(*strict*)\n      apply(case_tac ci)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to d e ci l r cfg_confa)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to d e l r)(*strict*)\n      apply(simp add: option_to_list_def)\n      apply(case_tac fr)\n       apply(rename_tac el fr ig el\\<pi> \\<pi> to d e l r)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e l r)(*strict*)\n       apply(subgoal_tac \"SSrenPI=[] \\<and> SSc2=\\<lparr>cfg_conf=[]\\<rparr>\" for SSrenPI SSc2)\n        apply(rename_tac el ig el\\<pi> \\<pi> to d e l r)(*strict*)\n        prefer 2\n        apply(rule_tac cfgLM_trans_der_from_empty)\n        apply(force)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e l r)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to d e l r a)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac el ig el\\<pi> \\<pi> to d e l r a)(*strict*)\n      apply(subgoal_tac \"(\\<forall>d c \\<pi> c'. cfgLM.trans_der G d c \\<pi> c' \\<longrightarrow> (\\<exists>w1 w2. cfg_conf c = liftB w1 @ liftA w2) \\<longrightarrow> (\\<exists>w1 w2. cfg_conf c' = liftB w1 @ liftA w2))\")\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e l r a)(*strict*)\n       prefer 2\n       apply(simp add: split_TSstructure_def CFGtermLeft_def)\n      apply(rename_tac el ig el\\<pi> \\<pi> to d e l r a)(*strict*)\n      apply(erule_tac\n      x=\"d\"\n      in allE)\n      apply(erule_tac\n      x=\"\\<lparr>cfg_conf = [teA a]\\<rparr>\"\n      in allE)\n      apply(erule_tac\n      x=\"\\<pi>\"\n      in allE)\n      apply(erule_tac\n      x=\"\\<lparr>cfg_conf = l @ teA (cons_l3   q1 X q2) # r\\<rparr>\"\n      in allE)\n      apply(clarsimp)\n      apply(erule impE)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e l r a)(*strict*)\n       apply(simp add: cfgLM.trans_der_def)\n       apply(rule_tac\n      m=\"Suc 0\"\n      and v=\"[Some SSx]\" for SSx\n      in get_labels_drop_tail)\n        apply(rename_tac el ig el\\<pi> \\<pi> to d e l r a)(*strict*)\n        apply(force)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e l r a)(*strict*)\n       apply(force)\n      apply(rename_tac el ig el\\<pi> \\<pi> to d e l r a)(*strict*)\n      apply(erule impE)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e l r a)(*strict*)\n       apply(rule_tac\n      x=\"[]\"\n      in exI)\n       apply(clarsimp)\n       apply(rule_tac\n      x=\"[SSX]\" for SSX\n      in exI)\n       apply(force)\n      apply(rename_tac el ig el\\<pi> \\<pi> to d e l r a)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac el ig el\\<pi> \\<pi> to d e l r a w1 w2)(*strict*)\n      apply(case_tac l)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e l r a w1 w2)(*strict*)\n       prefer 2\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e l r a w1 w2 aa list)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e r a w1 w2 list)(*strict*)\n       apply(case_tac w1)\n        apply(rename_tac el ig el\\<pi> \\<pi> to d e r a w1 w2 list)(*strict*)\n        apply(clarsimp)\n        apply(rename_tac el ig el\\<pi> \\<pi> to d e r a w2 list)(*strict*)\n        apply(case_tac w2)\n         apply(rename_tac el ig el\\<pi> \\<pi> to d e r a w2 list)(*strict*)\n         apply(clarsimp)\n        apply(rename_tac el ig el\\<pi> \\<pi> to d e r a w2 list aa lista)(*strict*)\n        apply(clarsimp)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e r a w1 w2 list aa lista)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e r a w2 list lista)(*strict*)\n       apply(case_tac list)\n        apply(rename_tac el ig el\\<pi> \\<pi> to d e r a w2 list lista)(*strict*)\n        prefer 2\n        apply(rename_tac el ig el\\<pi> \\<pi> to d e r a w2 list lista aa listb)(*strict*)\n        apply(clarsimp)\n        apply(rename_tac el ig el\\<pi> \\<pi> to d e r a w2 lista aa listb)(*strict*)\n        apply(case_tac \"ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (case ESplitItem_from S2 of None \\<Rightarrow> [] | Some A \\<Rightarrow> [A])) to\")\n         apply(rename_tac el ig el\\<pi> \\<pi> to d e r a w2 lista aa listb)(*strict*)\n         apply(clarsimp)\n        apply(rename_tac el ig el\\<pi> \\<pi> to d e r a w2 lista aa listb ab list)(*strict*)\n        apply(clarsimp)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e r a w2 list lista)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e a w2 lista)(*strict*)\n       apply(case_tac lista)\n        apply(rename_tac el ig el\\<pi> \\<pi> to d e a w2 lista)(*strict*)\n        prefer 2\n        apply(rename_tac el ig el\\<pi> \\<pi> to d e a w2 lista aa list)(*strict*)\n        apply(clarsimp)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e a w2 lista)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e a w2)(*strict*)\n       apply(case_tac w2)\n        apply(rename_tac el ig el\\<pi> \\<pi> to d e a w2)(*strict*)\n        apply(force)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e a w2 aa list)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e a list)(*strict*)\n       apply(subgoal_tac \"ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (case ESplitItem_from S2 of None \\<Rightarrow> [] | Some A \\<Rightarrow> [A])) to = list\")\n        apply(rename_tac el ig el\\<pi> \\<pi> to d e a list)(*strict*)\n        prefer 2\n        apply(rule liftA_inj)\n        apply(force)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e a list)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e a)(*strict*)\n       apply(erule_tac\n      x=\"length \\<pi>\"\n      in allE)\n       apply(clarsimp)\n       apply(simp add: get_configuration_def)\n      apply(rename_tac el ig el\\<pi> \\<pi> to d e l r a w1 w2)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac el ig el\\<pi> \\<pi> to d e a w1 w2)(*strict*)\n      apply(case_tac w1)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e a w1 w2)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e a w2)(*strict*)\n       apply(case_tac w2)\n        apply(rename_tac el ig el\\<pi> \\<pi> to d e a w2)(*strict*)\n        apply(clarsimp)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e a w2 aa list)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e a list)(*strict*)\n       apply(case_tac list)\n        apply(rename_tac el ig el\\<pi> \\<pi> to d e a list)(*strict*)\n        apply(clarsimp)\n       apply(rename_tac el ig el\\<pi> \\<pi> to d e a list aa lista)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac el ig el\\<pi> \\<pi> to d e a w1 w2 aa list)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(clarsimp)\n     apply(simp add: restrict_newprods_def)\n     apply(rule_tac\n      t=\"liftB (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2) ! length \\<pi>\"\n      in ssubst)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(rule liftB_nth)\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(clarsimp)\n     apply(simp add: restrict_newprodsX_def)\n     apply(rule_tac\n      t=\"nat_seq 0 SSX ! SSY\" for SSX SSY\n      in ssubst)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(rule nat_seq_nth_compute)\n       apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n       apply(force)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(clarsimp)\n     apply(simp add: restrict_newprodsXX_def)\n     apply(subgoal_tac \"derives G (\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2) = []\")\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(simp add: strict_prefix_def option_to_list_def)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(rule_tac\n      G=\"G\"\n      in derive_empty_if_first_prod_has_empty_rhs)\n       apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n       apply(simp add: split_TSstructure_def)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(subgoal_tac \"EValidSplit_ValidItem G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb)\")\n       apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n       prefer 2\n       apply(simp add: EValidSplit_def)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(simp add: EValidSplit_ValidItem_def EValidSplitItem_def EValidSplitItem_belongs_def)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(simp add: restrict_newprods_def)\n    apply(simp add: restrict_newprodsX_def)\n    apply(rule_tac\n      t=\"length(nat_seq SSx SSy)\" for SSx SSy\n      in ssubst)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(rule nat_seq_length_prime)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"length (liftB (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2))\"\n      in ssubst)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(rule liftB_length)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(force)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to rp')(*strict*)\n   apply(simp add: is_DT_revert_position_def)\n   apply(clarsimp)\n   apply(thin_tac \"prod_rhs (get_prod_at_DT_revert_position (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb) (Suc (length S1))) (gen (length S1) (length \\<pi>))) = [] \\<and> Suc (length \\<pi>) < length (PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb) (Suc (length S1)) ! length S1)) \\<or> Suc (length S1) \\<in> Pident_lines (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb) (Suc (length S1))) \\<and> Suc (length \\<pi>) = length (PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb) (Suc (length S1)) ! length S1))\")\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to rp')(*strict*)\n   apply(case_tac rp')\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to rp' nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(simp add: valid_DT_revert_position_def)\n    apply(clarsimp)\n    apply(thin_tac \"length \\<pi> < length (PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb) (Suc (length S1)) ! length S1))\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(thin_tac \" (case PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb) (Suc (length S1)) ! length S1) ! length \\<pi> of teA a \\<Rightarrow> {a} | teB b \\<Rightarrow> {}) = {}\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(rule leq_gen_elim)\n    apply(subgoal_tac \"length (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb) (Suc (length S1))) = Suc(length S1)\")\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     prefer 2\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"PSplitItem_elim (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb) (Suc (length S1)) ! nat) = []\")\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"nat_seq 0 (length S1) ! nat\"\n      in ssubst)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(rule nat_seq_nth_compute)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(clarsimp)\n    apply(thin_tac \"EValidSplitExt (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb)\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(simp add: EValidSplitExt_def EValidSplitExt_no_elim_before_nonterminal_def)\n    apply(erule conjE)+\n    apply(erule_tac\n      x=\"length S1\"\n      in allE)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"nat\"\n      in allE)\n    apply(clarsimp)\n    apply(case_tac \"nat < length S1\")\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(rule_tac\n      t=\"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr>]) ! nat\"\n      and s=\"S1!nat\"\n      in ssubst)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n      apply(rule nth_append_1)\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(rule_tac\n      t=\"S1!nat\"\n      and s=\"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! nat\"\n      in subst)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n      apply(rule nth_append_1)\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(rule_tac\n      t=\"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr>]) ! nat\"\n      and s=\"[\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr>]!SSX\" for SSX\n      in ssubst)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(rule nth_append_2_prime)\n       apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n       apply(force)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"nat=length S1\")\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to rp' nat1 nat2)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(simp add: valid_DT_revert_position_def)\n   apply(clarsimp)\n   apply(case_tac \"PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb) (Suc (length S1)) ! nat1) ! nat2\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 a)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"length (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb) (Suc (length S1))) = Suc(length S1)\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    prefer 2\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(subgoal_tac \"nat_seq 0 (length S1) ! nat1 = SSX\" for SSX)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    prefer 2\n    apply(rule nat_seq_nth_compute)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(force)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(clarsimp)\n   apply(thin_tac \"length (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb) (Suc (length S1))) = Suc (length S1)\")\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(simp add: leq_def get_pos_def get_line_def)\n   apply(case_tac \"length S1 = nat1 \\<and> length \\<pi> \\<le> nat2\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(force)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(subgoal_tac \"False\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(force)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(subgoal_tac \"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb) ! nat1 = (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr>]) ! nat1\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    prefer 2\n    apply(rule_tac\n      ?x1.0=\"Sb\"\n      and ?x2.0=\"[]\"\n      in nth_eq_ignore_append)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(force)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"length (PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb) (Suc (length S1)) ! nat1)) = length (ESplitItem_prods ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb) ! nat1))\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    prefer 2\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(clarsimp)\n    apply(simp add: restrict_newprods_def restrict_newprodsX_def)\n    apply(clarsimp)\n    apply(rule conjI)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(clarsimp)\n     apply(rule_tac\n      t=\"length (nat_seq 0 (length (ESplitItem_prods ((S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr>]) ! nat1)) - Suc 0))\"\n      in ssubst)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n      apply(rule nat_seq_length_prime)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(clarsimp)\n    apply(rule liftB_length)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(clarsimp)\n    apply(simp add: get_prod_at_DT_revert_position_def)\n    apply(thin_tac \"EValidSplitExt (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb)\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(subgoal_tac \"EValidSplitExt_no_pop_in_prods_before_nonterminal (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     prefer 2\n     apply(simp add: EValidSplitExt_def)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(simp add: EValidSplitExt_no_pop_in_prods_before_nonterminal_def)\n    apply(erule_tac\n      x=\"length S1\"\n      in allE)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"nat1\"\n      in allE)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"nat2\"\n      in allE)\n    apply(erule_tac\n      P=\"nat2 < length (ESplitItem_prods ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! nat1))\"\n      in impE)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     prefer 2\n     apply(subgoal_tac \"(ESplitItem_prods ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! nat1) ! nat2)= ba\")\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(rule_tac\n      t=\"S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb\"\n      and s=\"S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # (S2 # Sb)\"\n      in ssubst)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(rule_tac\n      el=\"el\"\n      and fr=\"fr\"\n      and ig=\"ig\"\n      and el\\<pi>=\"el\\<pi>\"\n      and to=\"ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\"\n      and G=\"G\"\n      and G'=\"G'\"\n      and ?S1.0=\"Sb\"\n      in nonabstracted_productions_are_unmodified)\n        apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n        apply(force)\n       apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n       apply(force)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(case_tac \"nat1=length S1\")\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! nat1\"\n      and s=\"S1!nat1\"\n      in ssubst)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(rule nth_append_1)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(rule_tac\n      t=\"S1!nat1\"\n      and s=\"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr>]) ! nat1\"\n      in subst)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(rule nth_append_1)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"nat1=length S1\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"nat1<length S1\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    prefer 2\n    apply(simp add: EValidSplitExt_def)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(simp add: EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal_def)\n   apply(erule_tac\n      x=\"length S1\"\n      in allE)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"Suc nat1\"\n      in allE)\n   apply(case_tac \"Suc nat1 < length S1\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    prefer 2\n    apply(clarsimp)\n    apply(simp add: Pident_line_def Pident_lines_def)\n    apply(clarsimp)\n    apply(case_tac \"Suc nat1=length S1\")\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(force)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(clarsimp)\n   apply(simp add: Eident_line_def Eident_lines_def Pident_line_def Pident_lines_def)\n   apply(clarsimp)\n   apply(subgoal_tac \"length(ESplitItem_prods ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! Suc nat1)) = length(PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb) (Suc (length S1)) ! Suc nat1))\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"length(ESplitItem_elim ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! Suc nat1)) = length(PSplitItem_elim (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr> # Sb) (Suc (length S1)) ! Suc nat1))\")\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"nat_seq 0 (length S1) ! Suc nat1\"\n      in ssubst)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(rule nat_seq_nth_compute)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(clarsimp)\n    apply(rule_tac\n      f=\"\\<lambda>X. length(ESplitItem_elim X)\"\n      in arg_cong)\n    apply(rule nth_eq_ignore_append)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(force)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n   apply(clarsimp)\n   apply(rule_tac\n      t=\"nat_seq 0 (length S1) ! Suc nat1\"\n      in ssubst)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(rule nat_seq_nth_compute)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(force)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(clarsimp)\n   apply(simp add: restrict_newprods_def)\n   apply(subgoal_tac \"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! Suc nat1 = (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (ESplitItem_elim_prods S2) @ ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2 @ drop (length (ESplitItem_elim S2) + length (option_to_list (ESplitItem_from S2))) to\\<rparr>]) ! Suc nat1\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(clarsimp)\n     apply(simp add: restrict_newprodsX_def)\n     apply(clarsimp)\n     apply(rule_tac\n      t=\"length(nat_seq SSx SSy)\" for SSx SSy\n      in ssubst)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n      apply(rule nat_seq_length_prime)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(clarsimp)\n    apply(rule sym)\n    apply(rule liftB_length)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(rule nth_eq_ignore_append)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(force)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(clarsimp)\n  apply(simp add: Xstep_merge1_toWasEliminated_def)\n  apply(simp add: get_revert_prod_def)\n  apply(subgoal_tac \"get_DT_revert_position (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr> # Sb) (Suc (length S1))) = Some (elim (length S1))\")\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(clarsimp)\n   apply(simp add: get_prod_at_DT_revert_position_def)\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n   apply(clarsimp)\n   apply(subgoal_tac \"el\\<pi>=[]\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac el fr ig \\<pi> to)(*strict*)\n    apply(subgoal_tac \"EValidSplit_ValidItem G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = [], ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n     apply(rename_tac el fr ig \\<pi> to)(*strict*)\n     prefer 2\n     apply(simp add: EValidSplit_def)\n    apply(rename_tac el fr ig \\<pi> to)(*strict*)\n    apply(simp add: EValidSplit_ValidItem_def EValidSplitItem_def EValidSplitItem_gen_def)\n    apply(clarsimp)\n    apply(rename_tac el fr ig \\<pi> to d da)(*strict*)\n    apply(rule_tac\n      d=\"d\"\n      in first_empty_rhs_with_left_degen_front)\n      apply(rename_tac el fr ig \\<pi> to d da)(*strict*)\n      apply(simp add: split_TSstructure_def)\n      apply(force)\n     apply(rename_tac el fr ig \\<pi> to d da)(*strict*)\n     apply(force)\n    apply(rename_tac el fr ig \\<pi> to d da)(*strict*)\n    apply(force)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(subgoal_tac \"EValidSplitExt_no_elim_before_nonterminal (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n    prefer 2\n    apply(simp add: EValidSplitExt_def )\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(simp add: EValidSplitExt_no_elim_before_nonterminal_def)\n   apply(erule_tac\n      x=\"(length S1)\"\n      in allE)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"(length S1)\"\n      in allE)\n   apply(clarsimp)\n   apply(rename_tac fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(subgoal_tac \"length (el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2)) = length(option_to_list fr @ drop (length to) (ESplitItem_elim S2))\")\n    apply(rename_tac fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"EValidSplit_producing G (S1 @ \\<lparr>ESplitItem_elim = [], ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n     apply(rename_tac fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(simp add: EValidSplit_def)\n    apply(rename_tac fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(simp add: EValidSplit_producing_def)\n    apply(erule_tac\n      x=\"\\<lparr>ESplitItem_elim = [], ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr>\"\n      in ballE)\n     apply(rename_tac fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply (metis append_Cons eq_Nil_appendI in_set_butlast list.simps(3))\n    apply(rename_tac fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac ig el\\<pi> \\<pi> to y)(*strict*)\n    apply(simp add: option_to_list_def)\n    apply(simp add: EValidSplit_def EValidSplit_ValidItem_def EValidSplitItem_def EValidSplitItem_elim_def)\n   apply(rename_tac fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(simp add: EValidSplit_def EValidSplit_ValidItem_def EValidSplitItem_def EValidSplitItem_elim_def)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(rule get_DT_revert_position_eq2)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(simp add: is_DT_revert_position_def valid_DT_revert_position_def)\n   apply(rule_tac\n      t=\"before_ident_line (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr> # Sb) (Suc (length S1))) (get_line (elim (length S1)))\"\n      and s=\"True\"\n      in ssubst)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(simp add: before_ident_line_def get_line_def)\n    apply(clarsimp)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n    apply(subgoal_tac \"EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     prefer 2\n     apply(simp add: EValidSplitExt_def)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n    apply(simp add: EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal_def)\n    apply(erule_tac\n      x=\"length S1\"\n      in allE)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"i\"\n      in allE)\n    apply(clarsimp)\n    apply(subgoal_tac \"\\<not> Pident_line (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr> # Sb) (Suc (length S1)) ! i)\")\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(simp add: Eident_lines_def Eident_line_def Pident_line_def)\n    apply(clarsimp)\n    apply(subgoal_tac \"nat_seq 0 (length S1) ! i = SSX\" for SSX)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     prefer 2\n     apply(rule nat_seq_nth_compute)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n    apply(simp add: Pident_line_def)\n    apply(subgoal_tac \"length(restrict_newprods G' G (S1 @ [\\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr>]) i) = length(ESplitItem_prods ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! i))\")\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"length(ESplitItem_elim ((S1 @ [\\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr>]) ! i)) = length(ESplitItem_elim ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! i))\")\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(rule_tac\n      t=\" ((S1 @ [\\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr>]) ! i)\"\n      in ssubst)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      apply(rule nth_append_1)\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(rule_tac\n      t=\"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! i\"\n      in ssubst)\n      apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      apply(rule nth_append_1)\n      apply(force)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n    apply(rule_tac\n      t=\"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! i\"\n      in ssubst)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(rule nth_append_1)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to i)(*strict*)\n    apply(rule restrict_newprods_preserves_length)\n    apply(force)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n   apply(clarsimp)\n   apply(rename_tac fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(subgoal_tac \"EValidSplit_producing G (S1 @ \\<lparr>ESplitItem_elim = [], ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n    apply(rename_tac fr ig el\\<pi> \\<pi> to)(*strict*)\n    prefer 2\n    apply(simp add: EValidSplit_def)\n   apply(rename_tac fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(simp add: EValidSplit_producing_def)\n   apply(erule_tac\n      x=\"\\<lparr>ESplitItem_elim = [], ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr>\"\n      in ballE)\n    apply(rename_tac fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(simp add: option_to_list_def)\n    apply(clarsimp)\n   apply(rename_tac fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply (metis Cons_eq_appendI append_Nil in_set_butlast list.simps(2))\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to rp')(*strict*)\n  apply(case_tac rp')\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to rp' nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n   apply(rule leq_elim_elim)\n   apply(case_tac \"nat<length S1\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"EValidSplitExt_no_elim_before_nonterminal (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    prefer 2\n    apply(simp add: EValidSplitExt_def )\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n   apply(simp add: EValidSplitExt_no_elim_before_nonterminal_def)\n   apply(erule_tac\n      x=\"(length S1)\"\n      in allE)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"nat\"\n      in allE)\n   apply(clarsimp)\n   apply(simp add: is_DT_revert_position_def valid_DT_revert_position_def)\n   apply(clarsimp)\n   apply(subgoal_tac \"nat_seq 0 (length S1) ! nat = SSX\" for SSX)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    prefer 2\n    apply(rule nat_seq_nth_compute)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(force)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n   apply(subgoal_tac \"length(PSplitItem_elim (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr> # Sb) (Suc (length S1)) ! nat)) = length(ESplitItem_elim ((S1 @ \\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr> # Sb) ! nat))\")\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    prefer 2\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"(S1 @ [\\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr>]) ! nat\"\n      in ssubst)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n   apply(rule nth_append_1)\n   apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n  apply(rule_tac\n    t=\"(S1 @ \\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr> # Sb) ! nat\"\n    in ssubst)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n   apply(rule nth_append_1)\n   apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n  apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n  apply(subgoal_tac \"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! nat = SSX\" for SSX)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n  prefer 2\n  apply(rule nth_append_1)\n  apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"(S1 @ \\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr> # Sb) ! nat = SSX\" for SSX)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n  prefer 2\n  apply(rule nth_append_1)\n  apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to rp' nat1 nat2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n  apply(rule leq_elim_gen)\n  apply(case_tac \"nat1<length S1\")\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n  prefer 2\n  apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n  apply(clarsimp)\n  apply(simp add: is_DT_revert_position_def)\n  apply(clarsimp)\n  apply(erule disjE)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"EValidSplitExt_no_pop_in_prods_before_nonterminal (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n  prefer 2\n  apply(simp add: EValidSplitExt_def)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n  apply(simp add: EValidSplitExt_no_pop_in_prods_before_nonterminal_def)\n  apply(erule_tac\n    x=\"length S1\"\n    in allE)\n  apply(clarsimp)\n  apply(erule_tac\n    x=\"nat1\"\n    in allE)\n  apply(clarsimp)\n  apply(erule_tac\n    x=\"nat2\"\n    in allE)\n  apply(erule impE)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n  apply(rule_tac\n    t=\"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! nat1\"\n    in ssubst)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(rule nth_append_1)\n   apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n  apply(rule_tac\n    t=\"length (ESplitItem_prods (S1 ! nat1))\"\n    and s=\"length (PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr> # Sb) (Suc (length S1)) ! nat1))\"\n    in ssubst)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n   apply(clarsimp)\n   apply(subgoal_tac \"nat_seq 0 (length S1) ! nat1 = SSX\" for SSX)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    prefer 2\n    apply(rule nat_seq_nth_compute)\n     apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n     apply(force)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(force)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(clarsimp)\n   apply(simp add: restrict_newprods_def restrict_newprodsX_def)\n   apply(rule_tac\n    t=\"(S1 @ [\\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr>]) ! nat1\"\n    in ssubst)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(rule nth_append_1)\n    apply(force)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(subgoal_tac \"length (nat_seq 0 (length (ESplitItem_prods (S1 ! nat1)) - Suc 0)) = SSX\" for SSX)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    prefer 2\n    apply(rule nat_seq_length_prime)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(clarsimp)\n   apply(rule sym)\n   apply(rule liftB_length)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n  apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n  apply(simp add: get_prod_at_DT_revert_position_def valid_DT_revert_position_def)\n  apply(clarsimp)\n  apply(case_tac \"PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr> # Sb) (Suc (length S1)) ! nat1) ! nat2\")\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"ESplitItem_prods ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! nat1) ! nat2 = ba\")\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(rule_tac\n    t=\"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! nat1\"\n    in ssubst)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(rule nth_append_1)\n  apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(rule_tac\n    k=\"Suc 0\"\n    in nonabstracted_productions_are_unmodified2)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(rule_tac\n    t=\"length (ESplitItem_prods (S1 ! nat1))\"\n    and s=\"length (PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr> # Sb) (Suc (length S1)) ! nat1))\"\n    in ssubst)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(subgoal_tac \"nat_seq 0 (length S1) ! nat1 = SSX\" for SSX)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   prefer 2\n   apply(rule nat_seq_nth_compute)\n    apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(force)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(clarsimp)\n  apply(simp add: restrict_newprods_def restrict_newprodsX_def)\n  apply(rule_tac\n    t=\"(S1 @ [\\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr>]) ! nat1\"\n    in ssubst)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(rule nth_append_1)\n   apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(subgoal_tac \"length (nat_seq 0 (length (ESplitItem_prods (S1 ! nat1)) - Suc 0)) = SSX\" for SSX)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   prefer 2\n   apply(rule nat_seq_length_prime)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(clarsimp)\n  apply(rule sym)\n  apply(rule liftB_length)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n  apply(clarsimp)\n  apply(simp add: get_prod_at_DT_revert_position_def valid_DT_revert_position_def)\n  apply(clarsimp)\n  apply(case_tac \"PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr> # Sb) (Suc (length S1)) ! nat1) ! nat2\")\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(clarsimp)\n  apply(thin_tac \"PSplitItem_elim (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr> # Sb) (Suc (length S1)) ! length S1) \\<noteq> []\")\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(thin_tac \"length S1 < length (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr> # Sb) (Suc (length S1)))\")\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(subgoal_tac \"EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  prefer 2\n  apply(simp add: EValidSplitExt_def)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(simp add: EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal_def)\n  apply(erule_tac\n    x=\"length S1\"\n    in allE)\n  apply(clarsimp)\n  apply(case_tac \"Suc nat1 < length S1\")\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  prefer 2\n  apply(subgoal_tac \"Suc nat1=length S1\")\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  prefer 2\n  apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(clarsimp)\n  apply(simp add: Pident_lines_def Pident_line_def)\n  apply(clarsimp)\n  apply(subgoal_tac \"PSplitItem_elim (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr> # Sb) (Suc (length S1)) ! length S1) = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2)\")\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  prefer 2\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(subgoal_tac \"EValidSplit_producing G (S1 @ \\<lparr>ESplitItem_elim = [], ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n  apply(rename_tac fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  prefer 2\n  apply(simp add: EValidSplit_def)\n  apply(rename_tac fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(simp add: EValidSplit_producing_def)\n  apply(erule_tac\n    x=\"\\<lparr>ESplitItem_elim = [], ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr>\"\n    in ballE)\n  apply(rename_tac fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  prefer 2\n  apply (metis append_Cons eq_Nil_appendI in_set_butlast list.simps(3))\n  apply(rename_tac fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac ig el\\<pi> \\<pi> to nat1 nat2 ba y)(*strict*)\n  apply(simp add: option_to_list_def)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(clarsimp)\n  apply(erule_tac\n    x=\"Suc nat1\"\n    in allE)\n  apply(clarsimp)\n  apply(subgoal_tac \"Suc nat1 \\<notin> Pident_lines (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr> # Sb) (Suc (length S1)))\")\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(simp (no_asm) add: Pident_lines_def Pident_line_def Eident_lines_def Eident_line_def)\n  apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n  apply(clarsimp)\n  apply(subgoal_tac \"nat_seq 0 (length S1) ! Suc nat1 = SSX\" for SSX)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  prefer 2\n  apply(rule nat_seq_nth_compute)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"(S1 @ [\\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr>]) ! Suc nat1 = SSX\" for SSX)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  prefer 2\n  apply(rule nth_append_1)\n  apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(clarsimp)\n  apply(simp add: Eident_lines_def Eident_line_def)\n  apply(subgoal_tac \"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! Suc nat1 = SSX\" for SSX)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  prefer 2\n  apply(rule nth_append_1)\n  apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"length(restrict_newprods G' G (S1 @ [\\<lparr>ESplitItem_elim = el @ option_to_list fr @ drop (length to) (ESplitItem_elim S2), ESplitItem_from = ESplitItem_from S2, ESplitItem_ignore = ESplitItem_ignore S2, ESplitItem_elim_prods = el\\<pi> @ (\\<pi> @ \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = []\\<rparr> # foldl (@) [] (take (length to) (ESplitItem_elim_prods S2))) # drop (length to) (ESplitItem_elim_prods S2), ESplitItem_prods = ESplitItem_prods S2, ESplitItem_elem = Some (teB b), ESplitItem_to = ESplitItem_to S2\\<rparr>]) (Suc nat1)) = length (ESplitItem_prods (S1 ! Suc nat1))\")\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(force)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n  apply(rule restrict_newprods_preserves_length)\n  apply(force)\n  done\n\nlemma leq_gen_gen: \"\n  n\\<le>m \\<and> x\\<le>y\n  \\<Longrightarrow> leq (gen n x) (gen m y)\"\n  apply(simp add: leq_def get_line_def get_pos_def)\n  apply(force)\n  done\n\nlemma get_revert_prod_sound_rhs_read: \"\n       F2LR1inputx G G'\n  \\<Longrightarrow> split_TSstructure G\n  \\<Longrightarrow> EValidSplit G (S1 @ SL # S2 # Sb)\n  \\<Longrightarrow> EValidSplit G (S1 @ Xstep_mergeL (Xstep_elem SL \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA B]\\<rparr> # Xstep_gen [B] (ESplitItem_to SL @ ESplitItem_ignore SL)) (Some S2) @ Sb)\n  \\<Longrightarrow> EValidSplitExt (S1 @ SL # S2 # Sb)\n  \\<Longrightarrow> EValidSplitExt (S1 @ Xstep_mergeL (Xstep_elem SL \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA B]\\<rparr> # Xstep_gen [B] (ESplitItem_to SL @ ESplitItem_ignore SL)) (Some S2) @ Sb)\n  \\<Longrightarrow> Esplit_signature (Xstep_mergeL (Xstep_elem SL \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA B]\\<rparr> # Xstep_gen [B] (ESplitItem_to SL @ ESplitItem_ignore SL)) (Some S2)) = [teB ba, teA B, teB b]\n  \\<Longrightarrow> setA (Esplit_signature Sb) = {}\n  \\<Longrightarrow> \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA B]\\<rparr> \\<in> cfg_productions G\n  \\<Longrightarrow> ESplitItem_elem SL = Some (teA (cons_l3   q1 X q2))\n  \\<Longrightarrow> length (Esplit_signature S1) = length S1\n  \\<Longrightarrow> ESplitItem_elem S2 = Some (teB b)\n  \\<Longrightarrow> length (nat_seq 0 (length S1)) = Suc (length S1)\n  \\<Longrightarrow> nat_seq 0 (length S1) ! length S1 = length S1\n  \\<Longrightarrow> get_revert_prod (restrict G' G (S1 @ Xstep_mergeL (Xstep_elem SL \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA B]\\<rparr> # Xstep_gen [B] (ESplitItem_to SL @ ESplitItem_ignore SL)) (Some S2) @ Sb) (Suc (Suc (Suc (length S1))))) = Some \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA B]\\<rparr>\"\n  apply(case_tac B)\n   apply(rename_tac q bb)(*strict*)\n   apply(subgoal_tac \"LR1ProdForm G\")\n    apply(rename_tac q bb)(*strict*)\n    apply(simp add: LR1ProdForm_def)\n    apply(erule_tac\n      x=\"\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l2   q bb)]\\<rparr>\"\n      in ballE)\n     apply(rename_tac q bb)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac q bb)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac q bb)(*strict*)\n   apply(simp add: split_TSstructure_def F2LR1inputx_def)\n   apply(rule sub_of_F_SDPDA_TO_CFG_STD__implies_LR1ProdForm)\n   apply(force)\n  apply(rename_tac q1a bb q2a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac q1' X' q2')\n  apply(rename_tac q1' X' q2')(*strict*)\n  apply(subgoal_tac \"nat_seq 0 0 = [0]\")\n   apply(rename_tac q1' X' q2')(*strict*)\n   prefer 2\n   apply (metis natUptTo_n_n)\n  apply(rename_tac q1' X' q2')(*strict*)\n  apply(simp add: Xstep_gen_def)\n  apply(simp add: Xstep_mergeL_def Xstep_elem_def nth_opt_def)\n  apply(case_tac SL)\n  apply(rename_tac q1' X' q2' ESplitItem_elim ESplitItem_from ESplitItem_ignorea ESplitItem_elim_prods ESplitItem_prodsa ESplitItem_elema ESplitItem_toa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac q1' X' q2' ESplitItem_elim ESplitItem_from ESplitItem_ignore ESplitItem_elim_prods ESplitItem_prods ESplitItem_to)(*strict*)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(simp add: Esplit_signature_def)\n  apply(simp add: option_to_list_def)\n  apply(simp add: get_revert_prod_def)\n  apply(subgoal_tac \"get_DT_revert_position (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = (cons_l3 q1' X' q2') # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1))))) = Some (gen (length S1) (length \\<pi>))\")\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n   prefer 2\n   apply(rule get_DT_revert_position_eq2)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(simp add: is_DT_revert_position_def)\n    apply(simp add: valid_DT_revert_position_def)\n    apply(rule_tac\n      t=\"before_ident_line (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1))))) (get_line (gen (length S1) (length \\<pi>)))\"\n      and s=\"True\"\n      in ssubst)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(simp (no_asm) add: Pident_lines_def Pident_line_def restrict_def restrict_map_def restrict_len_def before_ident_line_def)\n     apply(clarsimp)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(simp add: Pident_line_def get_line_def)\n     apply(subgoal_tac \"length(nat_seq 0 (Suc (Suc (length S1)))) = SSX\" for SSX)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      prefer 2\n      apply(rule nat_seq_length_prime)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"nat_seq 0 (Suc (Suc (length S1))) ! i = SSX\" for SSX)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      prefer 2\n      apply(rule nat_seq_nth_compute)\n       apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n       apply(force)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! i = SSX\" for SSX)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      prefer 2\n      apply(rule nth_append_1)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(clarsimp)\n     apply(thin_tac \"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! i = S1 ! i\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(subgoal_tac \"EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      prefer 2\n      apply(simp add: EValidSplitExt_def)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(simp add: EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal_def)\n     apply(erule_tac\n      x=\"length S1\"\n      in allE)\n     apply(clarsimp)\n     apply(erule_tac\n      x=\"i\"\n      in allE)\n     apply(clarsimp)\n     apply(simp add: Eident_lines_def Eident_line_def)\n     apply(subgoal_tac \"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! i = SSX\" for SSX)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      prefer 2\n      apply(rule nth_append_1)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \" length(restrict_newprods G' G (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) i) = SSX\" for SSX)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      prefer 2\n      apply(rule restrict_newprods_preserves_length)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(subgoal_tac \"nat_seq 0 (Suc (Suc (length S1))) ! length S1 = SSX\" for SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule nat_seq_nth_compute)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"length(nat_seq 0 (Suc (Suc (length S1)))) = SSX\" for SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule nat_seq_length_prime)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule_tac\n      ?S2.0=\"[\\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]\"\n      and G=\"G\"\n      and G'=\"G'\"\n      and ?S1.0=\"S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = (cons_l3 q1' X' q2') # to\\<rparr>]\"\n      and n=\"length S1\"\n      in restrict_newprods_preserves_length)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(simp (no_asm) add: Pident_lines_def Pident_line_def)\n    apply(clarsimp)\n    apply(subgoal_tac \"nat_seq 0 (Suc (Suc (length S1))) ! Suc (length S1) = SSX\" for SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule nat_seq_nth_compute)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"length(nat_seq 0 (Suc (Suc (length S1)))) = SSX\" for SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule nat_seq_length_prime)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = (cons_l3 q1' X' q2') # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1) = ([\\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>,S2])!SSX\" for SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule nth_append_2_prime)\n       apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n       apply(force)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule_tac\n      ?S2.0=\"[S2]\"\n      and G=\"G\"\n      and G'=\"G'\"\n      and ?S1.0=\"S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = (cons_l3 q1' X' q2') # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>]\"\n      and n=\"Suc(length S1)\"\n      in restrict_newprods_preserves_length)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = (cons_l3 q1' X' q2') # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>]) ! Suc (length S1) = [SSy]!SSX\" for SSy SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule nth_append_2_prime)\n       apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n       apply(force)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(case_tac \"restrict_newprods G' G (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = (cons_l3 q1' X' q2') # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) (length S1) ! length \\<pi>\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n     prefer 2\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    apply(clarsimp)\n    apply(thin_tac \"restrict_newprods G' G (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = (cons_l3 q1' X' q2') # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) (Suc (length S1)) = []\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    apply(simp add: restrict_newprods_def)\n    apply(case_tac \"restrict_newignore (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = (cons_l3 q1' X' q2') # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) (length S1) = []\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n     prefer 2\n     apply(clarsimp)\n     apply (metis Nat.lessI setA_liftB liftB_length Suc_length nth_setA)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    apply(clarsimp)\n    apply(simp add: restrict_newprodsX_def)\n    apply(case_tac \"restrict_newprodsXX G (nat_seq 0 (length \\<pi>) ! length \\<pi>) (\\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>]) (Some (teB ba)) (restrict_newto (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = (cons_l3 q1' X' q2') # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) (length S1))\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(subgoal_tac \"nat_seq 0 (length \\<pi>) ! length \\<pi> = SSX\" for SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule nat_seq_nth_compute)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(simp add: restrict_newprodsXX_def)\n    apply(subgoal_tac \"derives G [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>] = SSX\" for SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule derives_single)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(simp add: split_TSstructure_def)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(simp add: option_to_list_def restrict_newto_def restrict_newignore_def new_post_sig_def)\n    apply(subgoal_tac \"length (drop_and_crop (cons_l3 q1' X' q2' # to @ ig) (length (restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)))) = SSX\" for SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule drop_and_crop_length)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(thin_tac \"length (drop_and_crop (cons_l3 q1' X' q2' # to @ ig) (length (restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)))) = Suc (length to + length ig) - length (restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1))\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(subgoal_tac \"Suc (length to + length ig) \\<le> Suc (length to)+ length (restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1))\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(thin_tac \"Suc (length to + length ig) - length (restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)) \\<le> Suc (length to)\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1) = SSX\" for SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule restrict_toberemovedX_equals_restrict_toberemoved)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule_tac\n      S=\"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2])\"\n      and i=\"Suc(length S1)\"\n      in ignore_toberemoved_suffix)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(simp add: suffix_def)\n    apply(clarsimp)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n    apply(case_tac c)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n     prefer 2\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c a list)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n     apply(simp add: drop_and_crop_def cropTol3l2_def butn_def)\n     apply(case_tac \"Suc (length to + length ig) \\<le> length (restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1))\")\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n      apply(clarsimp)\n      apply(subgoal_tac \"length(to @ ig) =length(a # list @ restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1))\")\n       apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n       apply(thin_tac \"to @ ig = a # list @ restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)\")\n       apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"Suc (length to + length ig) - length (restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)) = Suc (length(a#list))\")\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n      prefer 2\n      apply(rule_tac\n      t=\"length to+length ig\"\n      and s=\"length(to@ig)\"\n      in ssubst)\n       apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n       apply(force)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n      apply(rule_tac\n      t=\"Suc (length (to @ ig))\"\n      and s=\"Suc(length(a # list @ restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)))\"\n      in ssubst)\n       apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n       apply(force)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n      apply(simp (no_asm))\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n     apply(clarsimp)\n     apply(case_tac \"to = [] \\<and> (Suc (length list) \\<le> length to \\<or> ig = [])\")\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n     apply(clarsimp)\n     apply(simp add: strict_prefix_def)\n     apply(case_tac \"butlast (take (Suc (length list)) to) @ [cropTol3l2_single (last (take (Suc (length list)) to))]\")\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list aa lista)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(thin_tac \"to @ ig = restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(thin_tac \"\\<not> strict_prefix [teB ba, teA (cons_l3   q1' X' q2')] (teB ba # liftA (drop_and_crop (cons_l3 q1' X' q2' # to @ ig) (length to + length ig)))\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(subgoal_tac \"restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1) = SSX\" for SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule restrict_toberemovedX_equals_restrict_toberemoved)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"suffix SSX (restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1))\" for SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule_tac\n      k=\"Suc(Suc (length S1))\"\n      in ESplitItem_ignore_restrict_toberemoved_suffix)\n       apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n       apply(force)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(simp add: suffix_def)\n    apply(clarsimp)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n    apply(rule_tac\n      c=\"c\"\n      in entirely_ignored_can_not_happend_to_early)\n            apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n            apply(force)\n           apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n           apply(force)\n          apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n          apply(thin_tac \"EValidSplit G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n          apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n          apply(force)\n         apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n         apply(force)\n        apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n        apply(force)\n       apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n       apply(force)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n    apply(rule_tac\n      t=\"S2\"\n      and s=\"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (Suc (length S1))\"\n      in subst)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n    apply(rule_tac\n      t=\"S2\"\n      and s=\"[S2]!0\"\n      in ssubst)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n     prefer 2\n     apply(rule nth_append_2_prime)\n       apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n       apply(force)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n    apply(force)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to rp')(*strict*)\n   apply(case_tac \"rp'\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to rp' nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(rule leq_gen_elim)\n    apply(case_tac \"nat \\<le> length S1\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"EValidSplitExt_no_elim_before_nonterminal (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     prefer 2\n     apply(simp add: EValidSplitExt_def)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(simp add: EValidSplitExt_no_elim_before_nonterminal_def)\n    apply(erule_tac\n      x=\"length S1\"\n      in allE)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"nat\"\n      in allE)\n    apply(clarsimp)\n    apply(subgoal_tac \"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! nat = (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr>])!nat\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     prefer 2\n     apply(rule sym)\n     apply(rule nth_append_2_prime_prime_X)\n       apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n       apply(force)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(clarsimp)\n    apply(case_tac \"nat = length S1\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac q1' X' q2' fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(simp add: is_DT_revert_position_def valid_DT_revert_position_def)\n     apply(clarsimp)\n     apply(subgoal_tac \"PSplitItem_elim (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = [], ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))) ! length S1) = ESplitItem_elim ((S1 @ \\<lparr>ESplitItem_elim = [], ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) ! length S1)\")\n      apply(rename_tac q1' X' q2' fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(subgoal_tac \"length(nat_seq 0 (Suc (Suc (length S1)))) = SSX\" for SSX)\n      apply(rename_tac q1' X' q2' fr ig el\\<pi> \\<pi> to)(*strict*)\n      prefer 2\n      apply(rule nat_seq_length_prime)\n     apply(rename_tac q1' X' q2' fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"nat_seq 0 (Suc (Suc (length S1))) ! length S1 = SSX\" for SSX)\n      apply(rename_tac q1' X' q2' fr ig el\\<pi> \\<pi> to)(*strict*)\n      prefer 2\n      apply(rule nat_seq_nth_compute)\n       apply(rename_tac q1' X' q2' fr ig el\\<pi> \\<pi> to)(*strict*)\n       apply(force)\n      apply(rename_tac q1' X' q2' fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(subgoal_tac \"nat < length S1\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(clarsimp)\n    apply(simp add: is_DT_revert_position_def valid_DT_revert_position_def)\n    apply(subgoal_tac \"PSplitItem_elim (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))) ! nat) = ESplitItem_elim ((S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr>]) ! nat)\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(subgoal_tac \"length(nat_seq 0 (Suc (Suc (length S1)))) = SSX\" for SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     prefer 2\n     apply(rule nat_seq_length_prime)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"nat_seq 0 (Suc (Suc (length S1))) ! nat = SSX\" for SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     prefer 2\n     apply(rule nat_seq_nth_compute)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! nat\"\n      in ssubst)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(rule nth_append_1)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(rule_tac\n      t=\"S1!nat\"\n      and s=\"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr>]) ! nat\"\n      in subst)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(rule nth_append_1)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(force)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to rp' nat1 nat2)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(subgoal_tac \"length(nat_seq 0 (Suc (Suc (length S1)))) = SSX\" for SSX)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    prefer 2\n    apply(rule nat_seq_length_prime)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(rule leq_gen_gen)\n   apply(subgoal_tac \"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) ! Suc (length S1) = SSX\" for SSX)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    prefer 2\n    apply(rule nth_append_2)\n    apply(force)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(clarsimp)\n   apply(rule context_conjI)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(rule ccontr)\n    apply(subgoal_tac \"nat1<length S1\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"nat_seq 0 (Suc (Suc (length S1))) ! nat1 = SSX\" for SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n     prefer 2\n     apply(rule nat_seq_nth_compute)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(subgoal_tac \"nat_seq 0 (Suc (Suc (length S1))) ! Suc nat1 = SSX\" for SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n     prefer 2\n     apply(rule nat_seq_nth_compute)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(subgoal_tac \"length (ESplitItem_prods (S1 ! nat1)) = length (PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))) ! nat1))\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n     prefer 2\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(clarsimp)\n     apply(rule sym)\n     apply(rule restrict_newprods_preserves_length)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(clarsimp)\n    apply(thin_tac \"is_DT_revert_position (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1))))) (gen (length S1) (length \\<pi>))\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(simp add: is_DT_revert_position_def valid_DT_revert_position_def)\n    apply(clarsimp)\n    apply(case_tac \"PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))) ! nat1) ! nat2\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 a)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! nat1 = S1!nat1\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n     prefer 2\n     apply(rule nth_append_1)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n     apply(clarsimp)\n     apply(simp add: get_prod_at_DT_revert_position_def)\n     apply(subgoal_tac \"X\" for X)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n      prefer 2\n      apply(rule_tac\n      G=\"G\"\n      and G'=\"G'\"\n      and k=\"Suc(Suc(Suc 0))\"\n      and ba=\"bb\"\n      and n=\"nat1\"\n      and m=\"nat2\"\n      and ?S1.0=\"S1\"\n      in nonabstracted_productions_are_unmodified2)\n        apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n        apply(force)\n       apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n       apply(force)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n     apply(thin_tac \"EValidSplitExt (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb)\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n     apply(simp add: EValidSplitExt_def EValidSplitExt_no_pop_in_prods_before_nonterminal_def)\n     apply(clarsimp)\n     apply(erule_tac\n      x=\"length S1\"\n      in allE)\n     apply(clarsimp)\n     apply(erule_tac\n      x=\"nat1\"\n      in allE)\n     apply(clarsimp)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n    apply(clarsimp)\n    apply(thin_tac \"EValidSplitExt (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n    apply(simp add: EValidSplitExt_def EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"Suc(length S1)\"\n      in allE)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"Suc nat1\"\n      in allE)\n    apply(case_tac \"Suc nat1<Suc (length S1)\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"Suc nat1 \\<notin> Pident_lines (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))))\")\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def Pident_lines_def Pident_line_def)\n     apply(clarsimp)\n     apply(simp add: Eident_lines_def Eident_line_def)\n     apply(subgoal_tac \"length(ESplitItem_prods ((S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>]) ! Suc nat1)) = SSX\" for SSX)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n      prefer 2\n      apply(rule sym)\n      apply(rule_tac\n      G=\"G\"\n      and G'=\"G'\"\n      and ?S2.0=\" \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # [S2]\"\n      in restrict_newprods_preserves_length)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n     apply(clarsimp)\n     apply(erule impE)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n      apply(rule_tac\n      t=\"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) ! Suc nat1\"\n      and s=\"((S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>]) ! Suc nat1)\"\n      in subst)\n       apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n       apply(rule nth_append_2_prime_prime_X)\n         apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n         apply(force)\n        apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n        apply(force)\n       apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n       apply(force)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n     apply(subgoal_tac \"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) ! Suc nat1 = (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc nat1\")\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n     apply(rule sym)\n     apply(rule nth_append_2_prime_prime_X)\n       apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n       apply(force)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n    apply(force)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(thin_tac \"is_DT_revert_position (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1))))) (gen (length S1) (length \\<pi>))\")\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(case_tac \"length S1<nat1\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(clarsimp)\n    apply(simp add: is_DT_revert_position_def valid_DT_revert_position_def)\n    apply(clarsimp)\n    apply(subgoal_tac \"length (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1))))) = (Suc (Suc (Suc (length S1))))\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n     prefer 2\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(clarsimp)\n    apply(thin_tac \"length (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1))))) = Suc (Suc (Suc (length S1)))\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(case_tac \"PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))) ! nat1) ! nat2\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 a)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n    apply(clarsimp)\n    apply(case_tac \"Suc(length S1)=nat1\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n     apply(subgoal_tac \"length (PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (length (nat_seq 0 (length S1))))) ! length (nat_seq 0 (length S1)))) = 0\")\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(clarsimp)\n     apply(rule_tac\n      t=\"length (nat_seq 0 (length S1))\"\n      in ssubst)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n      apply(rule nat_seq_length_prime)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n     apply(simp (no_asm))\n     apply(rule_tac\n      t=\"min (length S1) (Suc (Suc (Suc (length S1))))\"\n      and s=\"length S1\"\n      in ssubst)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n     apply(subgoal_tac \"nat_seq 0 (Suc(Suc(length S1))) ! Suc(length S1) = SSX\" for SSX)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n      prefer 2\n      apply(rule nat_seq_nth_compute)\n       apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n       apply(force)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n     apply(clarsimp)\n     apply(rule_tac\n      t=\"length (nat_seq 0 (length S1))\"\n      in ssubst)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n      apply(rule nat_seq_length_prime)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n     apply(simp (no_asm))\n     apply(subgoal_tac \"SSX = length (ESplitItem_prods ((S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2])! (Suc (length S1))))\" for SSX)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n      prefer 2\n      apply(rule_tac\n      ?S2.0=\"[]\"\n      in restrict_newprods_preserves_length)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n     apply(subgoal_tac \"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1) = SSX\" for SSX)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n      prefer 2\n      apply(rule nth_append_2)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n     apply(thin_tac \"Suc (length S1) = length (nat_seq 0 (length S1))\")\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n    apply(subgoal_tac \"Suc(length S1) < nat1\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n    apply(clarsimp)\n    apply(case_tac \"nat1=Suc(Suc(length S1))\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2 bb)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n    apply(simp add: get_line_def before_ident_line_def)\n    apply(erule_tac\n      x=\"Suc (length S1)\"\n      in allE)\n    apply(clarsimp)\n    apply(subgoal_tac \"nat_seq 0 (Suc (Suc (length S1))) ! Suc (length S1) = SSX\" for SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n     prefer 2\n     apply(rule nat_seq_nth_compute)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"Pident_line (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))) ! Suc (length S1))\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n    apply(thin_tac \"\\<not> Pident_line (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))) ! Suc (length S1))\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n    apply(simp add: Pident_line_def)\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(clarsimp)\n    apply(subgoal_tac \"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)=SSX\" for SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n     prefer 2\n     apply(rule nth_append_2)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"length(restrict_newprods G' G ((S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2])@[]) (Suc (length S1))) = SSX\" for SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n     prefer 2\n     apply(rule_tac\n      ?S2.0=\"[]\"\n      in restrict_newprods_preserves_length)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n    apply(force)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(thin_tac \"length (foldl (@) [] (map (option_to_list \\<circ> ESplitItem_elem) S1)) = length S1\")\n   apply(subgoal_tac \"length S1=nat1\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n   apply(simp add: is_DT_revert_position_def)\n   apply(clarsimp)\n   apply(case_tac \"nat2 < length \\<pi>\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n    apply(clarsimp)\n    apply(thin_tac \"Suc nat2 < length (PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))) ! length S1))\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n    apply(thin_tac \"before_ident_line (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1))))) (get_line (gen (length S1) nat2))\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n    apply(simp add: valid_DT_revert_position_def)\n    apply(clarsimp)\n    apply(case_tac \"PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))) ! length S1) ! nat2\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 a)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n    apply(clarsimp)\n    apply(thin_tac \"length S1 < length (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))))\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n    apply(thin_tac \"nat2 < length (PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))) ! length S1))\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n    apply(subgoal_tac \"EValidSplitExt_no_pop_in_prods_before_nonterminal (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb)\")\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n     prefer 2\n     apply(simp add: EValidSplitExt_def)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n    apply(simp add: EValidSplitExt_no_pop_in_prods_before_nonterminal_def)\n    apply(erule_tac\n      x=\"Suc(length S1)\"\n      in allE)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"(length S1)\"\n      in allE)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"nat2\"\n      in allE)\n    apply(clarsimp)\n    apply(subgoal_tac \"(\\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>]) ! nat2 = SSX\" for SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n     prefer 2\n     apply(rule nth_append_1)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n     prefer 2\n     apply(rule_tac\n      ?S1.0=\"S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>]\"\n      and k=\"(Suc (Suc 0))\"\n      in nonabstracted_productions_are_unmodified2)\n       apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n       apply(force)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n    apply(subgoal_tac \"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>]) ! length S1 = SSX\" for SSX)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n     prefer 2\n     apply(rule nth_append_2)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2 bb)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n    apply(simp add: get_prod_at_DT_revert_position_def)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"length (PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))) ! length S1)) = length(\\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>])\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n    apply(force)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n   apply(clarsimp)\n   apply(rule_tac\n      t=\"nat_seq 0 (Suc (Suc (length S1))) ! length S1\"\n      in ssubst)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n    apply(rule nat_seq_nth_compute)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n    apply(force)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n    prefer 2\n    apply(rule_tac\n      ?S1.0=\"S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>]\"\n      and ?S2.0=\"[\\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]\"\n      and n=\"length S1\"\n      in restrict_newprods_preserves_length)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n    apply(force)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n   apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(clarsimp)\n  apply(simp add: get_prod_at_DT_revert_position_def)\n  apply(case_tac \"PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))) ! length S1) ! length \\<pi>\")\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"False\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    apply(force)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n   apply(subgoal_tac \"PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))) ! length S1) ! length \\<pi> \\<noteq> teA a\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    apply(force)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n   apply(thin_tac \"PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))) ! length S1) ! length \\<pi> = teA a\")\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n   apply(clarsimp)\n   apply(subgoal_tac \"length(nat_seq 0 (Suc (Suc (length S1)))) = SSX\" for SSX)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    prefer 2\n    apply(rule nat_seq_length_prime)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"nat_seq 0 (Suc (Suc (length S1))) ! length S1 = SSX\" for SSX)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    prefer 2\n    apply(rule nat_seq_nth_compute)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    apply(force)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n   apply(clarsimp)\n   apply(simp add: restrict_newprods_def)\n   apply(case_tac \"restrict_newignore (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) (length S1) = []\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    prefer 2\n    apply(clarsimp)\n    apply (metis Nat.lessI setA_liftB liftB_length Suc_length nth_setA)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n   apply(clarsimp)\n   apply(simp add: restrict_newprodsX_def)\n   apply(subgoal_tac \"length (nat_seq 0 (length \\<pi>)) = SSX\" for SSX)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    prefer 2\n    apply(rule nat_seq_length_prime)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"restrict_newprodsXX G (nat_seq 0 (length \\<pi>) ! length \\<pi>) (\\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>]) (Some (teB ba)) (restrict_newto (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) (length S1))\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(subgoal_tac \"nat_seq 0 (length \\<pi>) ! length \\<pi> = SSX\" for SSX)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  prefer 2\n  apply(rule nat_seq_nth_compute)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(clarsimp)\n  apply(simp add: restrict_newprodsXX_def)\n  apply(subgoal_tac \"derives G [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>] = SSX\" for SSX)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  prefer 2\n  apply(rule derives_single)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(simp add: split_TSstructure_def)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(clarsimp)\n  apply(thin_tac \"derives G [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>] = [teB ba, teA (cons_l3   q1' X' q2')]\")\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(simp add: option_to_list_def restrict_newto_def restrict_newignore_def new_post_sig_def)\n  apply(subgoal_tac \"length (drop_and_crop (cons_l3 q1' X' q2' # to @ ig) (length (restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)))) = SSX\" for SSX)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  prefer 2\n  apply(rule drop_and_crop_length)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(clarsimp)\n  apply(thin_tac \"length (drop_and_crop (cons_l3 q1' X' q2' # to @ ig) (length (restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)))) = Suc (length to + length ig) - length (restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1))\")\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(subgoal_tac \"Suc (length to + length ig) \\<le> Suc (length to)+ length (restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1))\")\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  prefer 2\n  apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(thin_tac \"Suc (length to + length ig) - length (restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)) \\<le> Suc (length to)\")\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1) = SSX\" for SSX)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  prefer 2\n  apply(rule restrict_toberemovedX_equals_restrict_toberemoved)\n  apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  prefer 2\n  apply(rule_tac\n    S=\"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2])\"\n    and i=\"Suc(length S1)\"\n    in ignore_toberemoved_suffix)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(simp add: suffix_def)\n  apply(clarsimp)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  apply(subgoal_tac \"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1) = SSX\" for SSX)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  prefer 2\n  apply(rule nth_append_2)\n  apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  apply(clarsimp)\n  apply(case_tac c)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  prefer 2\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n  apply(simp add: drop_and_crop_def cropTol3l2_def butn_def)\n  apply(case_tac \"Suc (length to + length ig) \\<le> length (restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1))\")\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"length(to @ ig) =length(a # list @ restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1))\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n    apply(thin_tac \"to @ ig = a # list @ restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)\")\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n   apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"Suc (length to + length ig) - length (restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)) = Suc (length(a#list))\")\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n   prefer 2\n   apply(rule_tac\n    t=\"length to+length ig\"\n    and s=\"length(to@ig)\"\n    in ssubst)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n    apply(force)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n   apply(rule_tac\n    t=\"Suc (length (to @ ig))\"\n    and s=\"Suc(length(a # list @ restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)))\"\n    in ssubst)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n    apply(force)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n   apply(simp (no_asm))\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"to = [] \\<and> (Suc (length list) \\<le> length to \\<or> ig = [])\")\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n  apply(clarsimp)\n  apply(simp add: strict_prefix_def)\n  apply(case_tac \"butlast (take (Suc (length list)) to) @ [cropTol3l2_single (last (take (Suc (length list)) to))]\")\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n   apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to a list aa lista)(*strict*)\n  apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(thin_tac \"to @ ig = restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)\")\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(thin_tac \"\\<not> strict_prefix [teB ba, teA (cons_l3   q1' X' q2')] (teB ba # liftA (drop_and_crop (cons_l3 q1' X' q2' # to @ ig) (length to + length ig)))\")\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(subgoal_tac \"restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1) = SSX\" for SSX)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  prefer 2\n  apply(rule restrict_toberemovedX_equals_restrict_toberemoved)\n  apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"suffix SSX (restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1))\" for SSX)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  prefer 2\n  apply(rule_tac\n    k=\"Suc(Suc (length S1))\"\n    in ESplitItem_ignore_restrict_toberemoved_suffix)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(force)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(simp add: suffix_def)\n  apply(clarsimp)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  apply(rule_tac\n    c=\"c\"\n    in entirely_ignored_can_not_happend_to_early)\n         apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n         apply(force)\n        apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n        apply(force)\n       apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n       apply(thin_tac \"EValidSplit G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n       apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n       apply(force)\n      apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n      apply(force)\n     apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n     apply(force)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n    apply(force)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n   apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  apply(rule_tac\n    t=\"S2\"\n    and s=\"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) ! Suc (Suc (length S1))\"\n    in subst)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  prefer 2\n  apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  apply(rule_tac\n    t=\"S2\"\n    and s=\"[S2]!0\"\n    in ssubst)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  prefer 2\n  apply(rule nth_append_2_prime)\n    apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n    apply(force)\n   apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n   apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))) ! length S1) ! length \\<pi> = teB (\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>)\")\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  apply(simp add: get_DT_revert_position_def)\n  apply(case_tac \"\\<exists>rp. is_DT_revert_position (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1))))) rp\")\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  prefer 2\n  apply(clarsimp)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb rp)(*strict*)\n  apply(thin_tac \"(THE rp. is_DT_revert_position (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1))))) rp \\<and> (\\<forall>rp'. is_DT_revert_position (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1))))) rp' \\<longrightarrow> leq rp rp')) = gen (length S1) (length \\<pi>)\")\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb rp)(*strict*)\n  apply(thin_tac \"is_DT_revert_position (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1))))) rp\")\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb rp)(*strict*)\n  apply(simp add: restrict_def restrict_map_def restrict_len_def)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  apply(subgoal_tac \"length(nat_seq 0 (Suc (Suc (length S1)))) = SSX\" for SSX)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  prefer 2\n  apply(rule nat_seq_length_prime)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"nat_seq 0 (Suc (Suc (length S1))) ! length S1 = SSX\" for SSX)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  prefer 2\n  apply(rule nat_seq_nth_compute)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  apply(clarsimp)\n  apply(simp add: restrict_newprods_def)\n  apply(case_tac \"restrict_newignore (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) (length S1) = []\")\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  prefer 2\n  apply(clarsimp)\n  apply (metis Nat.lessI liftB_nth2 Suc_length nth_append_length)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  apply(clarsimp)\n  apply(simp add: restrict_newprodsX_def)\n  apply(subgoal_tac \"length(nat_seq 0 (length \\<pi>)) = SSX\" for SSX)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  prefer 2\n  apply(rule nat_seq_length_prime)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"nat_seq 0 (length \\<pi>) ! (length \\<pi>) = SSX\" for SSX)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  prefer 2\n  apply(rule nat_seq_nth_compute)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  apply(force)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"restrict_newprodsXX G (length \\<pi>) (\\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>]) (Some (teB ba)) (restrict_newto (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teB ba, teA (cons_l3   q1' X' q2')]\\<rparr>], ESplitItem_elem = Some (teB ba), ESplitItem_to = cons_l3 q1' X' q2' # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q1' X' q2'), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = []\\<rparr>, S2]) (length S1))\")\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac q1' X' q2' el fr ig el\\<pi> \\<pi> to bb)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma get_revert_prod_sound_rhs_push: \"\nF2LR1inputx G G'\n  \\<Longrightarrow> split_TSstructure G\n  \\<Longrightarrow> EValidSplit G (S1 @ SL # S2 # Sb)\n  \\<Longrightarrow> EValidSplit G (S1 @ Xstep_mergeL (Xstep_elem SL \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA B, teA C]\\<rparr> # Xstep_gen [C] (ESplitItem_to SL @ ESplitItem_ignore SL)) (Some S2) @ Sb)\n  \\<Longrightarrow> EValidSplitExt (S1 @ SL # S2 # Sb)\n  \\<Longrightarrow> EValidSplitExt (S1 @ Xstep_mergeL (Xstep_elem SL \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA B, teA C]\\<rparr> # Xstep_gen [C] (ESplitItem_to SL @ ESplitItem_ignore SL)) (Some S2) @ Sb)\n  \\<Longrightarrow> Esplit_signature (Xstep_mergeL (Xstep_elem SL \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA B, teA C]\\<rparr> # Xstep_gen [C] (ESplitItem_to SL @ ESplitItem_ignore SL)) (Some S2)) = [teA B, teA C, teB b]\n  \\<Longrightarrow> setA (Esplit_signature Sb) = {}\n  \\<Longrightarrow> \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA B, teA C]\\<rparr> \\<in> cfg_productions G\n  \\<Longrightarrow> ESplitItem_elem SL = Some (teA (cons_l3   q1 X q2))\n  \\<Longrightarrow> length (Esplit_signature S1) = length S1\n  \\<Longrightarrow> ESplitItem_elem S2 = Some (teB b)\n  \\<Longrightarrow> length (nat_seq 0 (length S1)) = Suc (length S1)\n  \\<Longrightarrow> nat_seq 0 (length S1) ! length S1 = length S1\n  \\<Longrightarrow> get_revert_prod (restrict G' G (S1 @ Xstep_mergeL (Xstep_elem SL \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA B, teA C]\\<rparr> # Xstep_gen [C] (ESplitItem_to SL @ ESplitItem_ignore SL)) (Some S2) @ Sb) (Suc (Suc (Suc (length S1))))) = Some \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA B, teA C]\\<rparr>\"\n  apply(subgoal_tac \"LR1ProdForm G\")\n   prefer 2\n   apply(rule sub_of_F_SDPDA_TO_CFG_STD__implies_LR1ProdForm)\n   apply(simp add: split_TSstructure_def F2LR1inputx_def)\n   apply(force)\n  apply(simp add: LR1ProdForm_def)\n  apply(erule_tac\n      x=\"\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA B, teA C]\\<rparr>\"\n      in ballE)\n   prefer 2\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac q2a q3 A2)(*strict*)\n  apply(rename_tac q1' q2' X')\n  apply(rename_tac q1' q2' X')(*strict*)\n  apply(subgoal_tac \"nat_seq 0 0 = [0]\")\n   apply(rename_tac q1' q2' X')(*strict*)\n   prefer 2\n   apply (metis natUptTo_n_n)\n  apply(rename_tac q1' q2' X')(*strict*)\n  apply(simp add: Xstep_gen_def)\n  apply(simp add: Xstep_mergeL_def Xstep_elem_def nth_opt_def)\n  apply(case_tac SL)\n  apply(rename_tac q1' q2' X' ESplitItem_elim ESplitItem_from ESplitItem_ignorea ESplitItem_elim_prods ESplitItem_prodsa ESplitItem_elema ESplitItem_toa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac q1' q2' X' ESplitItem_elim ESplitItem_from ESplitItem_ignore ESplitItem_elim_prods ESplitItem_prods ESplitItem_to)(*strict*)\n  apply(rename_tac el fr ig el\\<pi> \\<pi> to)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(simp add: Esplit_signature_def)\n  apply(simp add: option_to_list_def)\n  apply(simp add: get_revert_prod_def)\n  apply(subgoal_tac \"get_DT_revert_position (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1))))) = Some (gen (length S1) (length \\<pi>))\")\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n   prefer 2\n   apply(rule get_DT_revert_position_eq2)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(simp add: is_DT_revert_position_def)\n    apply(simp add: valid_DT_revert_position_def)\n    apply(rule_tac\n      t=\"before_ident_line (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1))))) (get_line (gen (length S1) (length \\<pi>)))\"\n      and s=\"True\"\n      in ssubst)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(simp (no_asm) add: Pident_lines_def Pident_line_def restrict_def restrict_map_def restrict_len_def before_ident_line_def)\n     apply(clarsimp)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(simp add: Pident_line_def get_line_def)\n     apply(subgoal_tac \"length(nat_seq 0 (Suc (Suc (length S1)))) = SSX\" for SSX)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      prefer 2\n      apply(rule nat_seq_length_prime)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"nat_seq 0 (Suc (Suc (length S1))) ! i = SSX\" for SSX)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      prefer 2\n      apply(rule nat_seq_nth_compute)\n       apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n       apply(force)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! i = SSX\" for SSX)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      prefer 2\n      apply(rule nth_append_1)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(clarsimp)\n     apply(thin_tac \"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! i = S1 ! i\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(subgoal_tac \"EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      prefer 2\n      apply(simp add: EValidSplitExt_def)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(simp add: EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal_def)\n     apply(erule_tac\n      x=\"length S1\"\n      in allE)\n     apply(clarsimp)\n     apply(erule_tac\n      x=\"i\"\n      in allE)\n     apply(clarsimp)\n     apply(simp add: Eident_lines_def Eident_line_def)\n     apply(subgoal_tac \"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! i = SSX\" for SSX)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      prefer 2\n      apply(rule nth_append_1)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \" length(restrict_newprods G' G (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) i) = SSX\" for SSX)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n      prefer 2\n      apply(rule restrict_newprods_preserves_length)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to i)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(subgoal_tac \"nat_seq 0 (Suc (Suc (length S1))) ! length S1 = SSX\" for SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule nat_seq_nth_compute)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"length(nat_seq 0 (Suc (Suc (length S1)))) = SSX\" for SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule nat_seq_length_prime)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule_tac\n      ?S2.0=\"[\\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]\"\n      and G=\"G\"\n      and G'=\"G'\"\n      and ?S1.0=\"S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>]\"\n      and n=\"length S1\"\n      in restrict_newprods_preserves_length)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(simp (no_asm) add: Pident_lines_def Pident_line_def)\n    apply(clarsimp)\n    apply(subgoal_tac \"nat_seq 0 (Suc (Suc (length S1))) ! Suc (length S1) = SSX\" for SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule nat_seq_nth_compute)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"length(nat_seq 0 (Suc (Suc (length S1)))) = SSX\" for SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule nat_seq_length_prime)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1) = SSX\" for SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule nth_append_2)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule_tac\n      ?S2.0=\"[S2]\"\n      and G=\"G\"\n      and G'=\"G'\"\n      and ?S1.0=\"S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>]\"\n      and n=\"Suc(length S1)\"\n      in restrict_newprods_preserves_length)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>]) ! Suc (length S1) = [SSy]!SSX\" for SSy SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule nth_append_2_prime)\n       apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n       apply(force)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(case_tac \"restrict_newprods G' G (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) (length S1) ! length \\<pi>\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n     prefer 2\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    apply(clarsimp)\n    apply(thin_tac \"restrict_newprods G' G (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) (Suc (length S1)) = []\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    apply(simp add: restrict_newprods_def)\n    apply(case_tac \"restrict_newignore (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) (length S1) = []\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n     prefer 2\n     apply(clarsimp)\n     apply (metis Nat.lessI setA_liftB liftB_length Suc_length nth_setA)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    apply(clarsimp)\n    apply(simp add: restrict_newprodsX_def)\n    apply(case_tac \"restrict_newprodsXX G (nat_seq 0 (length \\<pi>) ! length \\<pi>) (\\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>]) (Some (teA (cons_l3   q1' X' q2'))) (restrict_newto (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) (length S1))\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(subgoal_tac \"nat_seq 0 (length \\<pi>) ! length \\<pi> = SSX\" for SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule nat_seq_nth_compute)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(simp add: restrict_newprodsXX_def)\n    apply(subgoal_tac \"derives G [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>] = SSX\" for SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule derives_single)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(simp add: split_TSstructure_def)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(simp add: option_to_list_def restrict_newto_def restrict_newignore_def new_post_sig_def)\n    apply(subgoal_tac \"length (drop_and_crop (cons_l3 q2' X q2 # to @ ig) (length (restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)))) = SSX\" for SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule drop_and_crop_length)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(thin_tac \"length (drop_and_crop (cons_l3 q2' X q2 # to @ ig) (length (restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)))) = Suc (length to + length ig) - length (restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1))\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(subgoal_tac \"Suc (length to + length ig) \\<le> Suc (length to)+ length (restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1))\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(thin_tac \"Suc (length to + length ig) - length (restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)) \\<le> Suc (length to)\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1) = SSX\" for SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule restrict_toberemovedX_equals_restrict_toberemoved)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule_tac\n      S=\"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2])\"\n      and i=\"Suc(length S1)\"\n      in ignore_toberemoved_suffix)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(simp add: suffix_def)\n    apply(clarsimp)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n    apply(case_tac c)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n     prefer 2\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c a list)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n     apply(simp add: drop_and_crop_def cropTol3l2_def butn_def)\n     apply(case_tac \"Suc (length to + length ig) \\<le> length (restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1))\")\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n      apply(clarsimp)\n      apply(subgoal_tac \"length(to @ ig) =length(a # list @ restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1))\")\n       apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n       apply(thin_tac \"to @ ig = a # list @ restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)\")\n       apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"Suc (length to + length ig) - length (restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)) = Suc (length(a#list))\")\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n      prefer 2\n      apply(rule_tac\n      t=\"length to+length ig\"\n      and s=\"length(to@ig)\"\n      in ssubst)\n       apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n       apply(force)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n      apply(rule_tac\n      t=\"Suc (length (to @ ig))\"\n      and s=\"Suc(length(a # list @ restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)))\"\n      in ssubst)\n       apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n       apply(force)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n      apply(simp (no_asm))\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n     apply(clarsimp)\n     apply(case_tac \"to = [] \\<and> (Suc (length list) \\<le> length to \\<or> ig = [])\")\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n     apply(clarsimp)\n     apply(simp add: strict_prefix_def)\n     apply(case_tac \"butlast (take (Suc (length list)) to) @ [cropTol3l2_single (last (take (Suc (length list)) to))]\")\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list aa lista)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(thin_tac \"to @ ig = restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(thin_tac \"\\<not> strict_prefix [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)] (teA (cons_l3   q1' X' q2') # liftA (drop_and_crop (cons_l3 q2' X q2 # to @ ig) (length to + length ig)))\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(subgoal_tac \"restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1) = SSX\" for SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule restrict_toberemovedX_equals_restrict_toberemoved)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"suffix SSX (restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1))\" for SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     prefer 2\n     apply(rule_tac\n      k=\"Suc(Suc (length S1))\"\n      in ESplitItem_ignore_restrict_toberemoved_suffix)\n       apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n       apply(force)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(simp add: suffix_def)\n    apply(clarsimp)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n    apply(rule_tac\n      c=\"c\"\n      in entirely_ignored_can_not_happend_to_early)\n            apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n            apply(force)\n           apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n           apply(force)\n          apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n          apply(thin_tac \"EValidSplit G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n          apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n          apply(force)\n         apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n         apply(force)\n        apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n        apply(force)\n       apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n       apply(force)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n    apply(rule_tac\n      t=\"S2\"\n      and s=\"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (Suc (length S1))\"\n      in subst)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n    apply(rule_tac\n      t=\"S2\"\n      and s=\"[S2]!0\"\n      in ssubst)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n     prefer 2\n     apply(rule nth_append_2_prime)\n       apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n       apply(force)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n    apply(force)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to rp')(*strict*)\n   apply(case_tac \"rp'\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to rp' nat)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(rule leq_gen_elim)\n    apply(case_tac \"nat \\<le> length S1\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"EValidSplitExt_no_elim_before_nonterminal (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     prefer 2\n     apply(simp add: EValidSplitExt_def)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(simp add: EValidSplitExt_no_elim_before_nonterminal_def)\n    apply(erule_tac\n      x=\"length S1\"\n      in allE)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"nat\"\n      in allE)\n    apply(clarsimp)\n    apply(subgoal_tac \"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! nat = (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr>])!nat\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     prefer 2\n     apply(rule sym)\n     apply(rule nth_append_2_prime_prime_X)\n       apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n       apply(force)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(clarsimp)\n    apply(case_tac \"nat = length S1\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac q1' q2' X' fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(simp add: is_DT_revert_position_def valid_DT_revert_position_def)\n     apply(clarsimp)\n     apply(subgoal_tac \"PSplitItem_elim (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = [], ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))) ! length S1) = ESplitItem_elim ((S1 @ \\<lparr>ESplitItem_elim = [], ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb) ! length S1)\")\n      apply(rename_tac q1' q2' X' fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(subgoal_tac \"length(nat_seq 0 (Suc (Suc (length S1)))) = SSX\" for SSX)\n      apply(rename_tac q1' q2' X' fr ig el\\<pi> \\<pi> to)(*strict*)\n      prefer 2\n      apply(rule nat_seq_length_prime)\n     apply(rename_tac q1' q2' X' fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"nat_seq 0 (Suc (Suc (length S1))) ! length S1 = SSX\" for SSX)\n      apply(rename_tac q1' q2' X' fr ig el\\<pi> \\<pi> to)(*strict*)\n      prefer 2\n      apply(rule nat_seq_nth_compute)\n       apply(rename_tac q1' q2' X' fr ig el\\<pi> \\<pi> to)(*strict*)\n       apply(force)\n      apply(rename_tac q1' q2' X' fr ig el\\<pi> \\<pi> to)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(subgoal_tac \"nat < length S1\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(clarsimp)\n    apply(simp add: is_DT_revert_position_def valid_DT_revert_position_def)\n    apply(subgoal_tac \"PSplitItem_elim (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))) ! nat) = ESplitItem_elim ((S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr>]) ! nat)\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(subgoal_tac \"length(nat_seq 0 (Suc (Suc (length S1)))) = SSX\" for SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     prefer 2\n     apply(rule nat_seq_length_prime)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"nat_seq 0 (Suc (Suc (length S1))) ! nat = SSX\" for SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     prefer 2\n     apply(rule nat_seq_nth_compute)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! nat\"\n      in ssubst)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(rule nth_append_1)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(rule_tac\n      t=\"S1!nat\"\n      and s=\"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr>]) ! nat\"\n      in subst)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n     apply(rule nth_append_1)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat)(*strict*)\n    apply(force)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to rp' nat1 nat2)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(subgoal_tac \"length(nat_seq 0 (Suc (Suc (length S1)))) = SSX\" for SSX)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    prefer 2\n    apply(rule nat_seq_length_prime)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(rule leq_gen_gen)\n   apply(subgoal_tac \"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb) ! Suc (length S1) = SSX\" for SSX)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    prefer 2\n    apply(rule nth_append_2)\n    apply(force)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(clarsimp)\n   apply(rule context_conjI)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(rule ccontr)\n    apply(subgoal_tac \"nat1<length S1\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"nat_seq 0 (Suc (Suc (length S1))) ! nat1 = SSX\" for SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n     prefer 2\n     apply(rule nat_seq_nth_compute)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(subgoal_tac \"nat_seq 0 (Suc (Suc (length S1))) ! Suc nat1 = SSX\" for SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n     prefer 2\n     apply(rule nat_seq_nth_compute)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(subgoal_tac \"length (ESplitItem_prods (S1 ! nat1)) = length (PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))) ! nat1))\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n     prefer 2\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(clarsimp)\n     apply(rule sym)\n     apply(rule restrict_newprods_preserves_length)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(clarsimp)\n    apply(thin_tac \"is_DT_revert_position (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1))))) (gen (length S1) (length \\<pi>))\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(simp add: is_DT_revert_position_def valid_DT_revert_position_def)\n    apply(clarsimp)\n    apply(case_tac \"PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))) ! nat1) ! nat2\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 a)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb) ! nat1 = S1!nat1\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     prefer 2\n     apply(rule nth_append_1)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(clarsimp)\n     apply(simp add: get_prod_at_DT_revert_position_def)\n     apply(subgoal_tac \"X\" for X)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n      prefer 2\n      apply(rule_tac\n      G=\"G\"\n      and G'=\"G'\"\n      and k=\"Suc(Suc(Suc 0))\"\n      and ba=\"ba\"\n      and n=\"nat1\"\n      and m=\"nat2\"\n      and ?S1.0=\"S1\"\n      in nonabstracted_productions_are_unmodified2)\n        apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n        apply(force)\n       apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n       apply(force)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n     apply(thin_tac \"EValidSplitExt (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb)\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n     apply(simp add: EValidSplitExt_def EValidSplitExt_no_pop_in_prods_before_nonterminal_def)\n     apply(clarsimp)\n     apply(erule_tac\n      x=\"length S1\"\n      in allE)\n     apply(clarsimp)\n     apply(erule_tac\n      x=\"nat1\"\n      in allE)\n     apply(clarsimp)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(clarsimp)\n    apply(thin_tac \"EValidSplitExt (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(simp add: EValidSplitExt_def EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"Suc(length S1)\"\n      in allE)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"Suc nat1\"\n      in allE)\n    apply(case_tac \"Suc nat1<Suc (length S1)\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(clarsimp)\n     apply(subgoal_tac \"Suc nat1 \\<notin> Pident_lines (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))))\")\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def Pident_lines_def Pident_line_def)\n     apply(clarsimp)\n     apply(simp add: Eident_lines_def Eident_line_def)\n     apply(subgoal_tac \"length(ESplitItem_prods ((S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>]) ! Suc nat1)) = SSX\" for SSX)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n      prefer 2\n      apply(rule sym)\n      apply(rule_tac\n      G=\"G\"\n      and G'=\"G'\"\n      and ?S2.0=\" \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # [S2]\"\n      in restrict_newprods_preserves_length)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(clarsimp)\n     apply(erule impE)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n      apply(rule_tac\n      t=\"((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb)) ! Suc nat1\"\n      and s=\"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>])!(Suc nat1)\"\n      in subst)\n       apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n       apply(rule nth_append_2_prime_prime_X)\n         apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n         apply(force)\n        apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n        apply(force)\n       apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n       apply(force)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(subgoal_tac \"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb) ! Suc nat1 = (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2#[]) ! Suc nat1\")\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(rule sym)\n     apply(rule nth_append_2_prime_prime_X)\n       apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n       apply(force)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(force)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(thin_tac \"is_DT_revert_position (restrict G' G ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb)) (Suc (Suc (Suc (length S1))))) (gen (length S1) (length \\<pi>))\")\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(case_tac \"length S1<nat1\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(clarsimp)\n    apply(simp add: is_DT_revert_position_def valid_DT_revert_position_def)\n    apply(clarsimp)\n    apply(subgoal_tac \"length (restrict G' G ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb)) (Suc (Suc (Suc (length S1))))) = (Suc (Suc (Suc (length S1))))\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n     prefer 2\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(clarsimp)\n    apply(thin_tac \"length (restrict G' G ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb)) (Suc (Suc (Suc (length S1))))) = Suc (Suc (Suc (length S1)))\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    apply(case_tac \"PSplitItem_prods (restrict G' G ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb)) (Suc (Suc (Suc (length S1)))) ! nat1) ! nat2\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 a)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(clarsimp)\n    apply(case_tac \"Suc(length S1)=nat1\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n     apply(subgoal_tac \"length (PSplitItem_prods (restrict G' G ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb)) (Suc (Suc (length (nat_seq 0 (length S1))))) ! length (nat_seq 0 (length S1)))) = 0\")\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n     apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n     apply(clarsimp)\n     apply(rule_tac\n      t=\"length (nat_seq 0 (length S1))\"\n      in ssubst)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n      apply(rule nat_seq_length_prime)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n     apply(simp (no_asm))\n     apply(rule_tac\n      t=\"min (length S1) (Suc (Suc (Suc (length S1))))\"\n      and s=\"length S1\"\n      in ssubst)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n     apply(subgoal_tac \"nat_seq 0 (Suc(Suc(length S1))) ! Suc(length S1) = SSX\" for SSX)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n      prefer 2\n      apply(rule nat_seq_nth_compute)\n       apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n       apply(force)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n     apply(clarsimp)\n     apply(rule_tac\n      t=\"length (nat_seq 0 (length S1))\"\n      in ssubst)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n      apply(rule nat_seq_length_prime)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n     apply(simp (no_asm))\n     apply(subgoal_tac \"SSX = length (ESplitItem_prods (((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # []))! (Suc (length S1))))\" for SSX)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n      prefer 2\n      apply(rule_tac\n      ?S2.0=\"[]\"\n      in restrict_newprods_preserves_length)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n     apply(subgoal_tac \"((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # [])) ! Suc (length S1) = SSX\" for SSX)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n      prefer 2\n      apply(rule nth_append_2)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n     apply(thin_tac \"Suc (length S1) = length (nat_seq 0 (length S1))\")\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(subgoal_tac \"Suc(length S1) < nat1\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(clarsimp)\n    apply(case_tac \"nat1=Suc(Suc(length S1))\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2 ba)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n    apply(simp add: get_line_def before_ident_line_def)\n    apply(erule_tac\n      x=\"Suc (length S1)\"\n      in allE)\n    apply(clarsimp)\n    apply(subgoal_tac \"nat_seq 0 (Suc (Suc (length S1))) ! Suc (length S1) = SSX\" for SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n     prefer 2\n     apply(rule nat_seq_nth_compute)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"Pident_line (restrict G' G ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb)) (Suc (Suc (Suc (length S1)))) ! Suc (length S1))\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n    apply(thin_tac \"\\<not> Pident_line (restrict G' G ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb)) (Suc (Suc (Suc (length S1)))) ! Suc (length S1))\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n    apply(simp add: Pident_line_def)\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(clarsimp)\n    apply(subgoal_tac \"((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # [])) ! Suc (length S1)=SSX\" for SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n     prefer 2\n     apply(rule nth_append_2)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"length(restrict_newprods G' G (((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # []))@[]) (Suc (length S1))) = SSX\" for SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n     prefer 2\n     apply(rule_tac\n      ?S2.0=\"[]\"\n      in restrict_newprods_preserves_length)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n    apply(force)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(thin_tac \"length (foldl (@) [] (map (option_to_list \\<circ> ESplitItem_elem) S1)) = length S1\")\n   apply(subgoal_tac \"length S1=nat1\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat1 nat2)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n   apply(simp add: is_DT_revert_position_def)\n   apply(clarsimp)\n   apply(case_tac \"nat2 < length \\<pi>\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n    apply(clarsimp)\n    apply(thin_tac \"Suc nat2 < length (PSplitItem_prods (restrict G' G ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb)) (Suc (Suc (Suc (length S1)))) ! length S1))\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n    apply(thin_tac \"before_ident_line (restrict G' G ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb)) (Suc (Suc (Suc (length S1))))) (get_line (gen (length S1) nat2))\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n    apply(simp add: valid_DT_revert_position_def)\n    apply(clarsimp)\n    apply(case_tac \"PSplitItem_prods (restrict G' G ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb)) (Suc (Suc (Suc (length S1)))) ! length S1) ! nat2\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 a)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n    apply(clarsimp)\n    apply(thin_tac \"length S1 < length (restrict G' G ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb)) (Suc (Suc (Suc (length S1)))))\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n    apply(thin_tac \"nat2 < length (PSplitItem_prods (restrict G' G ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb)) (Suc (Suc (Suc (length S1)))) ! length S1))\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n    apply(subgoal_tac \"EValidSplitExt_no_pop_in_prods_before_nonterminal ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb))\")\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n     prefer 2\n     apply(simp add: EValidSplitExt_def)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n    apply(simp add: EValidSplitExt_no_pop_in_prods_before_nonterminal_def)\n    apply(erule_tac\n      x=\"Suc(length S1)\"\n      in allE)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"(length S1)\"\n      in allE)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"nat2\"\n      in allE)\n    apply(clarsimp)\n    apply(subgoal_tac \"(\\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>]) ! nat2 = SSX\" for SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n     prefer 2\n     apply(rule nth_append_1)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n    apply(clarsimp)\n    apply(subgoal_tac \"X\" for X)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n     prefer 2\n     apply(rule_tac\n      ?S1.0=\"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # [])\"\n      and k=\"(Suc (Suc 0))\"\n      in nonabstracted_productions_are_unmodified2)\n       apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n       apply(force)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n    apply(subgoal_tac \"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # []) ! length S1 = SSX\" for SSX)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n     prefer 2\n     apply(rule nth_append_2)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2 ba)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n    apply(simp add: get_prod_at_DT_revert_position_def)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"length (PSplitItem_prods (restrict G' G ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb)) (Suc (Suc (Suc (length S1)))) ! length S1)) = length(\\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>])\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n    apply(force)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n   apply(clarsimp)\n   apply(rule_tac\n      t=\"nat_seq 0 (Suc (Suc (length S1))) ! length S1\"\n      in ssubst)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n    apply(rule nat_seq_nth_compute)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n    apply(force)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n    prefer 2\n    apply(rule_tac\n      ?S1.0=\"(S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # [])\"\n      and n=\"length S1\"\n      in restrict_newprods_preserves_length)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n    apply(force)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to nat2)(*strict*)\n   apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(clarsimp)\n  apply(simp add: get_prod_at_DT_revert_position_def)\n  apply(case_tac \"PSplitItem_prods (restrict G' G ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb)) (Suc (Suc (Suc (length S1)))) ! length S1) ! length \\<pi>\")\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"False\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    apply(force)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n   apply(subgoal_tac \"PSplitItem_prods (restrict G' G ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb)) (Suc (Suc (Suc (length S1)))) ! length S1) ! length \\<pi> \\<noteq> teA a\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    apply(force)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n   apply(thin_tac \"PSplitItem_prods (restrict G' G ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb)) (Suc (Suc (Suc (length S1)))) ! length S1) ! length \\<pi> = teA a\")\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n   apply(clarsimp)\n   apply(subgoal_tac \"length(nat_seq 0 (Suc (Suc (length S1)))) = SSX\" for SSX)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    prefer 2\n    apply(rule nat_seq_length_prime)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"nat_seq 0 (Suc (Suc (length S1))) ! length S1 = SSX\" for SSX)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    prefer 2\n    apply(rule nat_seq_nth_compute)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    apply(force)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n   apply(clarsimp)\n   apply(simp add: restrict_newprods_def)\n   apply(case_tac \"restrict_newignore ((S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # [])) (length S1) = []\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    prefer 2\n    apply(clarsimp)\n    apply (metis Nat.lessI setA_liftB liftB_length Suc_length nth_setA)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n   apply(clarsimp)\n   apply(simp add: restrict_newprodsX_def)\n   apply(subgoal_tac \"length (nat_seq 0 (length \\<pi>)) = SSX\" for SSX)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    prefer 2\n    apply(rule nat_seq_length_prime)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"restrict_newprodsXX G (nat_seq 0 (length \\<pi>) ! length \\<pi>) (\\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>]) (Some (teA (cons_l3   q1' X' q2'))) (restrict_newto (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) (length S1))\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(subgoal_tac \"nat_seq 0 (length \\<pi>) ! length \\<pi> = SSX\" for SSX)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    prefer 2\n    apply(rule nat_seq_nth_compute)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(clarsimp)\n  apply(simp add: restrict_newprodsXX_def)\n  apply(subgoal_tac \"derives G [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>] = SSX\" for SSX)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  prefer 2\n  apply(rule derives_single)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(simp add: split_TSstructure_def)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(clarsimp)\n  apply(thin_tac \"derives G [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>] = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\")\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(simp add: option_to_list_def restrict_newto_def restrict_newignore_def new_post_sig_def)\n  apply(subgoal_tac \"length (drop_and_crop (cons_l3 q2' X q2 # to @ ig) (length (restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)))) = SSX\" for SSX)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  prefer 2\n  apply(rule drop_and_crop_length)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(clarsimp)\n  apply(thin_tac \"length (drop_and_crop (cons_l3 q2' X q2 # to @ ig) (length (restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)))) = Suc (length to + length ig) - length (restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1))\")\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(subgoal_tac \"Suc (length to + length ig) \\<le> Suc (length to)+ length (restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1))\")\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  prefer 2\n  apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(thin_tac \"Suc (length to + length ig) - length (restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)) \\<le> Suc (length to)\")\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1) = SSX\" for SSX)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  prefer 2\n  apply(rule restrict_toberemovedX_equals_restrict_toberemoved)\n  apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  prefer 2\n  apply(rule_tac\n    S=\"S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]\"\n    and i=\"Suc(length S1)\"\n    in ignore_toberemoved_suffix)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(simp add: suffix_def)\n  apply(clarsimp)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  apply(subgoal_tac \"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1) = SSX\" for SSX)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  prefer 2\n  apply(rule nth_append_2)\n  apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  apply(clarsimp)\n  apply(case_tac c)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  prefer 2\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n  apply(simp add: drop_and_crop_def cropTol3l2_def butn_def)\n  apply(case_tac \"Suc (length to + length ig) \\<le> length (restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1))\")\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"length(to @ ig) =length(a # list @ restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1))\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n    apply(thin_tac \"to @ ig = a # list @ restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)\")\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n   apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"Suc (length to + length ig) - length (restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)) = Suc (length(a#list))\")\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n   prefer 2\n   apply(rule_tac\n    t=\"length to+length ig\"\n    and s=\"length(to@ig)\"\n    in ssubst)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n    apply(force)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n   apply(rule_tac\n    t=\"Suc (length (to @ ig))\"\n    and s=\"Suc(length(a # list @ restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)))\"\n    in ssubst)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n    apply(force)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n   apply(simp (no_asm))\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"to = [] \\<and> (Suc (length list) \\<le> length to \\<or> ig = [])\")\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n  apply(clarsimp)\n  apply(simp add: strict_prefix_def)\n  apply(case_tac \"butlast (take (Suc (length list)) to) @ [cropTol3l2_single (last (take (Suc (length list)) to))]\")\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list)(*strict*)\n   apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to a list aa lista)(*strict*)\n  apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(thin_tac \"to @ ig = restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1)\")\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(thin_tac \"\\<not> strict_prefix [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)] (teA (cons_l3   q1' X' q2') # liftA (drop_and_crop (cons_l3 q2' X q2 # to @ ig) (length to + length ig)))\")\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(subgoal_tac \"restrict_toberemovedX (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1) = SSX\" for SSX)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  prefer 2\n  apply(rule restrict_toberemovedX_equals_restrict_toberemoved)\n  apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"suffix SSX (restrict_toberemoved (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (length S1))\" for SSX)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  prefer 2\n  apply(rule_tac\n    k=\"Suc(Suc (length S1))\"\n    in ESplitItem_ignore_restrict_toberemoved_suffix)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n    apply(force)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n   apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to)(*strict*)\n  apply(simp add: suffix_def)\n  apply(clarsimp)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  apply(rule_tac\n    c=\"c\"\n    in entirely_ignored_can_not_happend_to_early)\n         apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n         apply(force)\n        apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n        apply(force)\n       apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n       apply(thin_tac \"EValidSplit G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi>, ESplitItem_elem = Some (teA (cons_l3   q1 X q2)), ESplitItem_to = to\\<rparr> # S2 # Sb)\")\n       apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n       apply(force)\n      apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n      apply(force)\n     apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n     apply(force)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n    apply(force)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n   apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  apply(rule_tac\n    t=\"S2\"\n    and s=\"(S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) ! Suc (Suc (length S1))\"\n    in subst)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  prefer 2\n  apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  apply(rule_tac\n    t=\"S2\"\n    and s=\"[S2]!0\"\n    in ssubst)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  prefer 2\n  apply(rule nth_append_2_prime)\n    apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n    apply(force)\n   apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n   apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to c)(*strict*)\n  apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"PSplitItem_prods (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1)))) ! length S1) ! length \\<pi> = teB (\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>)\")\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n  apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n  apply(thin_tac \"get_DT_revert_position (restrict G' G (S1 @ \\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr> # \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr> # S2 # Sb) (Suc (Suc (Suc (length S1))))) = Some (gen (length S1) (length \\<pi>))\")\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n  apply(simp add: restrict_def restrict_map_def restrict_len_def)\n  apply(subgoal_tac \"length(nat_seq 0 (Suc (Suc (length S1)))) = SSX\" for SSX)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n  prefer 2\n  apply(rule nat_seq_length_prime)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"nat_seq 0 (Suc (Suc (length S1))) ! length S1 = SSX\" for SSX)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n  prefer 2\n  apply(rule nat_seq_nth_compute)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n  apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n  apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n  apply(clarsimp)\n  apply(simp add: restrict_newprods_def)\n  apply(case_tac \"restrict_newignore (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) (length S1) = []\")\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n  prefer 2\n  apply(clarsimp)\n  apply (metis Nat.lessI liftB_nth2 Suc_length nth_append_length)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n  apply(clarsimp)\n  apply(simp add: restrict_newprodsX_def)\n  apply(subgoal_tac \"length(nat_seq 0 (length \\<pi>)) = SSX\" for SSX)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n  prefer 2\n  apply(rule nat_seq_length_prime)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"nat_seq 0 (length \\<pi>) ! (length \\<pi>) = SSX\" for SSX)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n  prefer 2\n  apply(rule nat_seq_nth_compute)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n  apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n  apply(force)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"restrict_newprodsXX G (length \\<pi>) (\\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>]) (Some (teA (cons_l3   q1' X' q2'))) (restrict_newto (S1 @ [\\<lparr>ESplitItem_elim = el, ESplitItem_from = fr, ESplitItem_ignore = ig, ESplitItem_elim_prods = el\\<pi>, ESplitItem_prods = \\<pi> @ [\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = [teA (cons_l3   q1' X' q2'), teA (cons_l3   q2' X q2)]\\<rparr>], ESplitItem_elem = Some (teA (cons_l3   q1' X' q2')), ESplitItem_to = cons_l3 q2' X q2 # to\\<rparr>, \\<lparr>ESplitItem_elim = [], ESplitItem_from = Some (cons_l3 q2' X q2), ESplitItem_ignore = to @ ig, ESplitItem_elim_prods = [], ESplitItem_prods = [], ESplitItem_elem = Some (teA (cons_l3   q2' X q2)), ESplitItem_to = []\\<rparr>, S2]) (length S1))\")\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac q1' q2' X' el fr ig el\\<pi> \\<pi> to ba)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma get_revert_prod_sound: \"\n  F2LR1inputx G G'\n  \\<Longrightarrow> split_TSstructure G\n  \\<Longrightarrow> EValidSplit G S\n  \\<Longrightarrow> EValidSplit G (Sa @ Sb)\n  \\<Longrightarrow> EValidSplitExt S\n  \\<Longrightarrow> EValidSplitExt (Sa @ Sb)\n  \\<Longrightarrow> A=(cons_l3 q1 X q2)\n  \\<Longrightarrow> Esplit_signature S = xl @ teA A # teB b # x\n  \\<Longrightarrow> Esplit_signature Sa = xl @ r @ [teB b]\n  \\<Longrightarrow> Esplit_signature Sb = x\n  \\<Longrightarrow> length Sa = length (Esplit_signature Sa)\n  \\<Longrightarrow> Esplit_step_relation G S \\<lparr>prod_lhs = A, prod_rhs = r\\<rparr> (Sa @ Sb)\n  \\<Longrightarrow> setA x = {}\n  \\<Longrightarrow> get_revert_prod (restrict G' G (Sa @ Sb) (length Sa)) = Some \\<lparr>prod_lhs = A, prod_rhs = r\\<rparr>\"\n  apply(simp add: Esplit_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac S1 SL S2)(*strict*)\n  apply(simp add: Esplit_signature_append setAConcat)\n  apply(subgoal_tac \"Esplit_signature [SL] = [teA (cons_l3   q1 X q2)]\")\n   apply(rename_tac S1 SL S2)(*strict*)\n   prefer 2\n   apply(simp add: Esplit_signature_def option_to_list_def)\n  apply(rename_tac S1 SL S2)(*strict*)\n  apply(subgoal_tac \"Esplit_signature (SL # S2) = Esplit_signature [SL] @ Esplit_signature S2\")\n   apply(rename_tac S1 SL S2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      t=\"SL#S2\"\n      and s=\"[SL]@S2\"\n      in ssubst)\n    apply(rename_tac S1 SL S2)(*strict*)\n    apply(force)\n   apply(rename_tac S1 SL S2)(*strict*)\n   apply(simp (no_asm) only: Esplit_signature_append)\n  apply(rename_tac S1 SL S2)(*strict*)\n  apply(clarsimp)\n  apply(thin_tac \"Esplit_signature (SL # S2) = teA (cons_l3   q1 X q2) # Esplit_signature S2\")\n  apply(subgoal_tac \"Esplit_signature S2 = teB b # Esplit_signature Sb\")\n   apply(rename_tac S1 SL S2)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"strict_prefix (Esplit_signature S1) xl \\<or> SSX\" for SSX)\n    apply(rename_tac S1 SL S2)(*strict*)\n    prefer 2\n    apply(rule mutual_strict_prefix_strict_prefix)\n    apply(force)\n   apply(rename_tac S1 SL S2)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac S1 SL S2)(*strict*)\n    apply(subgoal_tac \"False\")\n     apply(rename_tac S1 SL S2)(*strict*)\n     apply(force)\n    apply(rename_tac S1 SL S2)(*strict*)\n    apply(simp add: strict_prefix_def)\n    apply(clarsimp)\n    apply(rename_tac S1 SL S2 c)(*strict*)\n    apply(case_tac c)\n     apply(rename_tac S1 SL S2 c)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac S1 SL S2 c a list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac S1 SL S2 list)(*strict*)\n    apply(simp add: Esplit_signature_append setAConcat)\n   apply(rename_tac S1 SL S2)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac S1 SL S2)(*strict*)\n    apply(subgoal_tac \"False\")\n     apply(rename_tac S1 SL S2)(*strict*)\n     apply(force)\n    apply(rename_tac S1 SL S2)(*strict*)\n    apply(simp add: strict_prefix_def)\n    apply(clarsimp)\n    apply(rename_tac S1 SL S2 c)(*strict*)\n    apply(case_tac c)\n     apply(rename_tac S1 SL S2 c)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac S1 SL S2 c a list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac S1 SL S2 a list)(*strict*)\n    apply(subgoal_tac \" list @ teA (cons_l3   q1 X q2) # Esplit_signature S2 = teB b # Esplit_signature Sb\")\n     apply(rename_tac S1 SL S2 a list)(*strict*)\n     apply(case_tac list)\n      apply(rename_tac S1 SL S2 a list)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac S1 SL S2 a list aa lista)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac S1 SL S2 a lista)(*strict*)\n     apply (metis elemInsetA emptyE)\n    apply(rename_tac S1 SL S2 a list)(*strict*)\n    apply(rule_tac\n      a=\"xl@[a]\"\n      and b=\"xl@[teA (cons_l3   q1 X q2)]\"\n      in append_linj_length)\n     apply(rename_tac S1 SL S2 a list)(*strict*)\n     apply(force)\n    apply(rename_tac S1 SL S2 a list)(*strict*)\n    apply(rule_tac\n      t=\"(xl @ [teA (cons_l3   q1 X q2)]) @ teB b # Esplit_signature Sb\"\n      and s=\"Esplit_signature S1 @ teA (cons_l3   q1 X q2) # Esplit_signature S2\"\n      in ssubst)\n     apply(rename_tac S1 SL S2 a list)(*strict*)\n     apply(force)\n    apply(rename_tac S1 SL S2 a list)(*strict*)\n    apply(rule_tac\n      t=\"Esplit_signature S1\"\n      and s=\"xl @ a # list\"\n      in ssubst)\n     apply(rename_tac S1 SL S2 a list)(*strict*)\n     apply(force)\n    apply(rename_tac S1 SL S2 a list)(*strict*)\n    apply(simp (no_asm))\n   apply(rename_tac S1 SL S2)(*strict*)\n   apply(force)\n  apply(rename_tac S1 SL S2)(*strict*)\n  apply(subgoal_tac \"Esplit_signature S1 = xl\")\n   apply(rename_tac S1 SL S2)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac S1 SL S2)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"S2\")\n   apply(rename_tac S1 SL S2)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac S1 SL)(*strict*)\n   apply(simp add: Esplit_signature_def)\n  apply(rename_tac S1 SL S2 a list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac S1 SL a list)(*strict*)\n  apply(rename_tac S2 S2L)\n  apply(rename_tac S1 SL S2 S2L)(*strict*)\n  apply(simp add: nth_opt_def)\n  apply(subgoal_tac \"Esplit_signature [S2] = [teB b]\")\n   apply(rename_tac S1 SL S2 S2L)(*strict*)\n   prefer 2\n   apply(simp add: Esplit_signature_def)\n   apply(case_tac \"ESplitItem_elem S2\")\n    apply(rename_tac S1 SL S2 S2L)(*strict*)\n    apply(clarsimp)\n    apply(simp add: option_to_list_def)\n    apply(rule_tac\n      xs=\"S2L\"\n      in rev_cases)\n     apply(rename_tac S1 SL S2 S2L)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac S1 SL S2 S2L ys y)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac S1 SL S2 ys y)(*strict*)\n    apply(subgoal_tac \"(\\<forall>x\\<in> set (butlast (S1 @ SL # S2 # ys @ [y])). (\\<exists>y. ESplitItem_from x = Some y) \\<and> (\\<exists>y. ESplitItem_elem x = Some y))\")\n     apply(rename_tac S1 SL S2 ys y)(*strict*)\n     prefer 2\n     apply(simp add: EValidSplit_def EValidSplit_producing_def)\n    apply(rename_tac S1 SL S2 ys y)(*strict*)\n    apply(erule_tac\n      x=\"S2\"\n      in ballE)\n     apply(rename_tac S1 SL S2 ys y)(*strict*)\n     apply(force)\n    apply(rename_tac S1 SL S2 ys y)(*strict*)\n    apply(subgoal_tac \"(butlast (S1 @ SL # S2 # ys @ [y]))=SSX\" for SSX)\n     apply(rename_tac S1 SL S2 ys y)(*strict*)\n     prefer 2\n     apply(rule butlast_direct)\n     apply(force)\n    apply(rename_tac S1 SL S2 ys y)(*strict*)\n    apply(force)\n   apply(rename_tac S1 SL S2 S2L a)(*strict*)\n   apply(subgoal_tac \"foldl (@) (option_to_list (ESplitItem_elem S2)) (map (option_to_list \\<circ> ESplitItem_elem) S2L) = SSX\" for SSX)\n    apply(rename_tac S1 SL S2 S2L a)(*strict*)\n    prefer 2\n    apply(rule foldl_first)\n   apply(rename_tac S1 SL S2 S2L a)(*strict*)\n   apply(clarsimp)\n   apply(simp add: option_to_list_def)\n  apply(rename_tac S1 SL S2 S2L)(*strict*)\n  apply(subgoal_tac \"Esplit_signature (S2#S2L) = Esplit_signature [S2] @ Esplit_signature S2L\")\n   apply(rename_tac S1 SL S2 S2L)(*strict*)\n   prefer 2\n   apply(rule_tac\n      t=\"S2#S2L\"\n      and s=\"[S2]@S2L\"\n      in ssubst)\n    apply(rename_tac S1 SL S2 S2L)(*strict*)\n    apply(force)\n   apply(rename_tac S1 SL S2 S2L)(*strict*)\n   apply(simp (no_asm) only: Esplit_signature_append)\n  apply(rename_tac S1 SL S2 S2L)(*strict*)\n  apply(clarsimp)\n  apply(thin_tac \"Esplit_signature (S2 # S2L) = teB b # Esplit_signature Sb\")\n  apply(subgoal_tac \"length (Esplit_signature S1) = length S1\")\n   apply(rename_tac S1 SL S2 S2L)(*strict*)\n   prefer 2\n   apply (metis EValidSplit_Esplit_signature_length list.simps(3))\n  apply(rename_tac S1 SL S2 S2L)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"length(Xstep_mergeL (Xstep_elem SL \\<lparr>prod_lhs = (cons_l3 q1 X q2), prod_rhs = r\\<rparr> # Xstep_gen (filterA (tl r)) (ESplitItem_to SL @ ESplitItem_ignore SL)) (Some S2)) = Suc(length r)\")\n   apply(rename_tac S1 SL S2 S2L)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"length(Xstep_gen (filterA (tl r)) (ESplitItem_to SL @ ESplitItem_ignore SL)) = length r - Suc 0\")\n    apply(rename_tac S1 SL S2 S2L)(*strict*)\n    prefer 2\n    apply(rule Xstep_gen_length)\n     apply(rename_tac S1 SL S2 S2L)(*strict*)\n     apply(simp add: split_TSstructure_def)\n     apply(force)\n    apply(rename_tac S1 SL S2 S2L)(*strict*)\n    apply(force)\n   apply(rename_tac S1 SL S2 S2L)(*strict*)\n   apply(simp (no_asm) add: Xstep_mergeL_def)\n   apply(rule conjI)\n    apply(rename_tac S1 SL S2 S2L)(*strict*)\n    apply(clarsimp)\n    apply(case_tac \"ESplitItem_elem (Xstep_elem SL \\<lparr>prod_lhs = (cons_l3 q1 X q2), prod_rhs = r\\<rparr>)\")\n     apply(rename_tac S1 SL S2 S2L)(*strict*)\n     prefer 2\n     apply(rename_tac S1 SL S2 S2L a)(*strict*)\n     apply(clarsimp)\n     apply(case_tac r)\n      apply(rename_tac S1 SL S2 S2L a)(*strict*)\n      apply(clarsimp)\n      apply(simp add: Xstep_elem_def nth_opt_def)\n     apply(rename_tac S1 SL S2 S2L a aa list)(*strict*)\n     apply(clarsimp)\n     apply(simp add: Xstep_elem_def nth_opt_def)\n     apply(clarsimp)\n     apply(rename_tac S1 SL S2 S2L a list)(*strict*)\n     apply(simp add: Xstep_gen_def)\n     apply(case_tac \"filterA list = []\")\n      apply(rename_tac S1 SL S2 S2L a list)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac S1 SL S2 S2L a list)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac S1 SL S2 S2L)(*strict*)\n    apply(clarsimp)\n    apply(simp add: Xstep_elem_def nth_opt_def)\n    apply(case_tac r)\n     apply(rename_tac S1 SL S2 S2L)(*strict*)\n     apply(force)\n    apply(rename_tac S1 SL S2 S2L a list)(*strict*)\n    apply(force)\n   apply(rename_tac S1 SL S2 S2L)(*strict*)\n   apply(clarsimp)\n   apply(case_tac r)\n    apply(rename_tac S1 SL S2 S2L)(*strict*)\n    apply(force)\n   apply(rename_tac S1 SL S2 S2L a list)(*strict*)\n   apply(clarsimp)\n   apply(case_tac list)\n    apply(rename_tac S1 SL S2 S2L a list)(*strict*)\n    apply(force)\n   apply(rename_tac S1 SL S2 S2L a list aa lista)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac S1 SL S2 S2L a aa lista)(*strict*)\n   apply(simp add: split_TSstructure_def LR1ProdFormSimp_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = a # aa # lista\\<rparr>\"\n      in ballE)\n    apply(rename_tac S1 SL S2 S2L a aa lista)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac S1 SL S2 S2L a aa lista)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac S1 SL S2 S2L a aa lista ba A B)(*strict*)\n   apply(subgoal_tac \"nat_seq 0 0 = [0]\")\n    apply(rename_tac S1 SL S2 S2L a aa lista ba A B)(*strict*)\n    prefer 2\n    apply (metis natUptTo_n_n)\n   apply(rename_tac S1 SL S2 S2L a aa lista ba A B)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac S1 SL S2 S2L a aa lista ba A B)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac S1 SL S2 S2L ba B)(*strict*)\n    apply(simp add: Xstep_gen_def)\n   apply(rename_tac S1 SL S2 S2L a aa lista ba A B)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac S1 SL S2 S2L B C)(*strict*)\n   apply(simp add: Xstep_gen_def)\n  apply(rename_tac S1 SL S2 S2L)(*strict*)\n  apply(subgoal_tac \"Sa = S1 @ Xstep_mergeL (Xstep_elem SL \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = r\\<rparr> # Xstep_gen (filterA (tl r)) (ESplitItem_to SL @ ESplitItem_ignore SL)) (Some S2)\")\n   apply(rename_tac S1 SL S2 S2L)(*strict*)\n   prefer 2\n   apply(rule length_append_equal)\n    apply(rename_tac S1 SL S2 S2L)(*strict*)\n    apply(force)\n   apply(rename_tac S1 SL S2 S2L)(*strict*)\n   apply(force)\n  apply(rename_tac S1 SL S2 S2L)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac S1 SL S2)(*strict*)\n  apply(simp add: Esplit_signature_append setAConcat)\n  apply(thin_tac \"Esplit_signature [SL] = [teA (cons_l3   q1 X q2)]\")\n  apply(thin_tac \"length (Xstep_mergeL (Xstep_elem SL \\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = r\\<rparr> # Xstep_gen (filterA (tl r)) (ESplitItem_to SL @ ESplitItem_ignore SL)) (Some S2)) = Suc (length r)\")\n  apply(rename_tac S1 SL S2)(*strict*)\n  apply(subgoal_tac \"ESplitItem_elem S2 = Some (teB b)\")\n   apply(rename_tac S1 SL S2)(*strict*)\n   prefer 2\n   apply(simp add: Esplit_signature_def option_to_list_def)\n   apply(case_tac \"ESplitItem_elem S2\")\n    apply(rename_tac S1 SL S2)(*strict*)\n    apply(force)\n   apply(rename_tac S1 SL S2 a)(*strict*)\n   apply(force)\n  apply(rename_tac S1 SL S2)(*strict*)\n  apply(thin_tac \"Esplit_signature [S2] = [teB b]\")\n  apply(rename_tac S1 SL S2)(*strict*)\n  apply(subgoal_tac \"LR1ProdFormSimp G\")\n   apply(rename_tac S1 SL S2)(*strict*)\n   prefer 2\n   apply(simp add: split_TSstructure_def)\n  apply(rename_tac S1 SL S2)(*strict*)\n  apply(simp add: LR1ProdFormSimp_def)\n  apply(erule_tac\n      x=\"\\<lparr>prod_lhs = cons_l3 q1 X q2, prod_rhs = r\\<rparr>\"\n      in ballE)\n   apply(rename_tac S1 SL S2)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac S1 SL S2)(*strict*)\n  apply(subgoal_tac \"length(nat_seq 0 (length S1))=SSX\" for SSX)\n   apply(rename_tac S1 SL S2)(*strict*)\n   prefer 2\n   apply(rule nat_seq_length_prime)\n  apply(rename_tac S1 SL S2)(*strict*)\n  apply(subgoal_tac \"nat_seq 0 (length S1) ! (length S1) = SSX\" for SSX)\n   apply(rename_tac S1 SL S2)(*strict*)\n   prefer 2\n   apply(rule nat_seq_nth_compute)\n    apply(rename_tac S1 SL S2)(*strict*)\n    apply(force)\n   apply(rename_tac S1 SL S2)(*strict*)\n   apply(force)\n  apply(rename_tac S1 SL S2)(*strict*)\n  apply(clarsimp)\n  apply(erule disjE)\n   apply(rename_tac S1 SL S2)(*strict*)\n   apply(rule get_revert_prod_sound_rhs_empty)\n                 apply(rename_tac S1 SL S2)(*strict*)\n                 apply(force)\n                apply(rename_tac S1 SL S2)(*strict*)\n                apply(force)\n               apply(rename_tac S1 SL S2)(*strict*)\n               apply(force)\n              apply(rename_tac S1 SL S2)(*strict*)\n              apply(force)\n             apply(rename_tac S1 SL S2)(*strict*)\n             apply(force)\n            apply(rename_tac S1 SL S2)(*strict*)\n            apply(force)\n           apply(rename_tac S1 SL S2)(*strict*)\n           apply(force)\n          apply(rename_tac S1 SL S2)(*strict*)\n          apply(force)\n         apply(rename_tac S1 SL S2)(*strict*)\n         apply(force)\n        apply(rename_tac S1 SL S2)(*strict*)\n        apply(force)\n       apply(rename_tac S1 SL S2)(*strict*)\n       apply(force)\n      apply(rename_tac S1 SL S2)(*strict*)\n      apply(force)\n     apply(rename_tac S1 SL S2)(*strict*)\n     apply(force)\n    apply(rename_tac S1 SL S2)(*strict*)\n    apply(force)\n   apply(rename_tac S1 SL S2)(*strict*)\n   apply(force)\n  apply(rename_tac S1 SL S2)(*strict*)\n  apply(erule exE)+\n  apply(rename_tac S1 SL S2 ba A B)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac S1 SL S2 ba A B)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac S1 SL S2 ba B)(*strict*)\n   apply(rule get_revert_prod_sound_rhs_read)\n                apply(rename_tac S1 SL S2 ba B)(*strict*)\n                apply(force)\n               apply(rename_tac S1 SL S2 ba B)(*strict*)\n               apply(force)\n              apply(rename_tac S1 SL S2 ba B)(*strict*)\n              apply(force)\n             apply(rename_tac S1 SL S2 ba B)(*strict*)\n             apply(force)\n            apply(rename_tac S1 SL S2 ba B)(*strict*)\n            apply(force)\n           apply(rename_tac S1 SL S2 ba B)(*strict*)\n           apply(force)\n          apply(rename_tac S1 SL S2 ba B)(*strict*)\n          apply(force)\n         apply(rename_tac S1 SL S2 ba B)(*strict*)\n         apply(force)\n        apply(rename_tac S1 SL S2 ba B)(*strict*)\n        apply(force)\n       apply(rename_tac S1 SL S2 ba B)(*strict*)\n       apply(force)\n      apply(rename_tac S1 SL S2 ba B)(*strict*)\n      apply(force)\n     apply(rename_tac S1 SL S2 ba B)(*strict*)\n     apply(force)\n    apply(rename_tac S1 SL S2 ba B)(*strict*)\n    apply(force)\n   apply(rename_tac S1 SL S2 ba B)(*strict*)\n   apply(force)\n  apply(rename_tac S1 SL S2 ba A B)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac S1 SL S2 ba A B)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac S1 SL S2 B)(*strict*)\n   apply(subgoal_tac \"LR1ProdForm G\")\n    apply(rename_tac S1 SL S2 B)(*strict*)\n    prefer 2\n    apply(simp add: Esplit_TSstructure_def F2LR1input_def F2LR1inputx_def)\n    apply(clarsimp)\n    apply(rule sub_of_F_SDPDA_TO_CFG_STD__implies_LR1ProdForm)\n    apply(force)\n   apply(rename_tac S1 SL S2 B)(*strict*)\n   apply(simp add: LR1ProdForm_def)\n   apply(force)\n  apply(rename_tac S1 SL S2 ba A B)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac S1 SL S2 B C)(*strict*)\n  apply(rule get_revert_prod_sound_rhs_push)\n               apply(rename_tac S1 SL S2 B C)(*strict*)\n               apply(force)+\n  done\n\nlemma LR1_property_part2_equal_productions2: \"\n  F2LR1inputx G G'\n  \\<Longrightarrow> split_TSstructure G\n  \\<Longrightarrow> EValidSplit G S1\n  \\<Longrightarrow> EValidSplit G (S1a @ S1b)\n  \\<Longrightarrow> EValidSplitExt S1\n  \\<Longrightarrow> EValidSplitExt (S1a @ S1b)\n  \\<Longrightarrow> A1=(cons_l3 q11 X1 q12)\n  \\<Longrightarrow> A2=(cons_l3 q21 X2 q22)\n  \\<Longrightarrow> Esplit_signature S1 = xl1 @ teA A1 # teB b # Esplit_signature S1b\n  \\<Longrightarrow> Esplit_signature S1a = xl1 @ r1 @ [teB b]\n  \\<Longrightarrow> length S1a = length (Esplit_signature S1a)\n  \\<Longrightarrow> Esplit_step_relation G S1 \\<lparr>prod_lhs = A1, prod_rhs = r1\\<rparr> (S1a @ S1b)\n  \\<Longrightarrow> EValidSplit G S2\n  \\<Longrightarrow> EValidSplit G (S2a @ S2b)\n  \\<Longrightarrow> EValidSplitExt S2\n  \\<Longrightarrow> EValidSplitExt (S2a @ S2b)\n  \\<Longrightarrow> Esplit_signature S2 = xl2 @ teA A2 # teB b # Esplit_signature S2b\n  \\<Longrightarrow> Esplit_signature S2a = xl2 @ r2 @ [teB b]\n  \\<Longrightarrow> length S2a = length (Esplit_signature S2a)\n  \\<Longrightarrow> Esplit_step_relation G S2 \\<lparr>prod_lhs = A2, prod_rhs = r2\\<rparr> (S2a @ S2b)\n  \\<Longrightarrow> restrict G' G (S1a @ S1b) (length S1a) = restrict G' G (S2a @ S2b) (length S2a)\n  \\<Longrightarrow> setA (Esplit_signature S1b) = {}\n  \\<Longrightarrow> setA (Esplit_signature S2b) = {}\n  \\<Longrightarrow> \\<lparr>prod_lhs = A1, prod_rhs = r1\\<rparr> = \\<lparr>prod_lhs = A2, prod_rhs = r2\\<rparr>\"\n  apply(subgoal_tac \"get_revert_prod (restrict G' G (S1a @ S1b) (length S1a)) = Some \\<lparr>prod_lhs = A1, prod_rhs = r1\\<rparr>\")\n   apply(subgoal_tac \"get_revert_prod (restrict G' G (S2a @ S2b) (length S2a)) = Some \\<lparr>prod_lhs = A2, prod_rhs = r2\\<rparr>\")\n    apply(subgoal_tac \"get_revert_prod (restrict G' G (S1a @ S1b) (length S1a)) = get_revert_prod (restrict G' G (S2a @ S2b) (length S2a))\")\n     apply(force)\n    apply(force)\n   apply(rule get_revert_prod_sound)\n               apply(force)\n              apply(force)\n             prefer 4\n             apply(force)\n            prefer 4\n            apply(force)\n           prefer 4\n           apply(force)\n          apply(force)\n         apply(force)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(rule get_revert_prod_sound)\n              apply(force)\n             apply(force)\n            prefer 2\n            apply(force)\n           prefer 3\n           apply(force)\n          prefer 3\n          apply(force)\n         prefer 3\n         apply(force)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(force)\n  done\n\nlemma LR1_property_part2_equal_productions: \"\n  F2LR1inputx G G'\n  \\<Longrightarrow> split_TSstructure G\n  \\<Longrightarrow> EValidSplit G S1\n  \\<Longrightarrow> EValidSplit G (S1a @ S1b)\n  \\<Longrightarrow> EValidSplitExt S1\n  \\<Longrightarrow> EValidSplitExt (S1a @ S1b)\n  \\<Longrightarrow> A1=(cons_l3 q11 X1 q12)\n  \\<Longrightarrow> A2=(cons_l3 q21 X2 q22)\n  \\<Longrightarrow> Esplit_signature S1 = xl1 @ teA A1 # teB b # Esplit_signature S1b\n  \\<Longrightarrow> Esplit_signature (S1a @ S1b) = xl1 @ r1 @ teB b # Esplit_signature S1b\n  \\<Longrightarrow> Esplit_signature S1a = xl1 @ r1 @ [teB b]\n  \\<Longrightarrow> length S1a = Suc (length xl1 + length r1)\n  \\<Longrightarrow> Esplit_step_relation G S1 \\<lparr>prod_lhs = A1, prod_rhs = r1\\<rparr> (S1a @ S1b)\n  \\<Longrightarrow> EValidSplit G S2\n  \\<Longrightarrow> EValidSplit G (S2a @ S2b)\n  \\<Longrightarrow> EValidSplitExt S2\n  \\<Longrightarrow> EValidSplitExt (S2a @ S2b)\n  \\<Longrightarrow> Esplit_signature S2 = xl2 @ teA A2 # teB b # Esplit_signature S2b\n  \\<Longrightarrow> Esplit_signature (S2a @ S2b) = xl2 @ r2 @ teB b # Esplit_signature S2b\n  \\<Longrightarrow> Esplit_signature S2a = xl2 @ r2 @ [teB b]\n  \\<Longrightarrow> length S2a = Suc (length xl2 + length r2)\n  \\<Longrightarrow> Esplit_step_relation G S2 \\<lparr>prod_lhs = A2, prod_rhs = r2\\<rparr> (S2a @ S2b)\n  \\<Longrightarrow> xl1 @ r1 = xl2 @ r2\n  \\<Longrightarrow> restrict G' G (S1a @ S1b) (Suc (length xl1 + length r1)) = restrict G' G (S2a @ S2b) (Suc (length xl2 + length r2))\n  \\<Longrightarrow> setA (Esplit_signature S1b) = {}\n  \\<Longrightarrow> setA (Esplit_signature S2b) = {}\n  \\<Longrightarrow> A1 = A2 \\<and> r1 = r2\"\n  apply(subgoal_tac \"Esplit_signature (S2a @ S2b) = SSX\" for SSX)\n   prefer 2\n   apply(rule Esplit_signature_append)\n  apply(subgoal_tac \"Esplit_signature (S1a @ S1b) = SSX\" for SSX)\n   prefer 2\n   apply(rule Esplit_signature_append)\n  apply(thin_tac \"Esplit_signature (S2a @ S2b) = xl2 @ r2 @ teB b # Esplit_signature S2b\")\n  apply(thin_tac \"Esplit_signature (S1a @ S1b) = xl1 @ r1 @ teB b # Esplit_signature S1b\")\n  apply(subgoal_tac \"\\<lparr>prod_lhs = A1, prod_rhs = r1\\<rparr> = \\<lparr>prod_lhs = A2, prod_rhs = r2\\<rparr>\")\n   apply(force)\n  apply(rule_tac\n      S1a=\"S1a\"\n      and S2a=\"S2a\"\n      and ?S1.0=\"S1\"\n      and ?S1b.0=\"S1b\"\n      and ?S2b.0=\"S2b\"\n      and ?S2.0=\"S2\"\n      in LR1_property_part2_equal_productions2)\n                      apply(force)+\n  done\n\ntheorem LR1_property_part2: \"\n  F2LR1inputx G G'\n  \\<Longrightarrow> split_TSstructure G\n  \\<Longrightarrow> cfgRM.derivation_initial G d1\n  \\<Longrightarrow> d1 n1 = Some (pair e1 \\<lparr>cfg_conf=xl1@teA A1#teB b#x1\\<rparr>)\n  \\<Longrightarrow> d1 (Suc n1) = Some (pair (Some \\<lparr>prod_lhs = A1, prod_rhs = r1\\<rparr>) \\<lparr>cfg_conf=xl1@r1@teB b#x1\\<rparr>)\n  \\<Longrightarrow> cfgRM.derivation_initial G d2\n  \\<Longrightarrow> d2 n2 = Some (pair e2 \\<lparr>cfg_conf=xl2@teA A2#teB b#x2\\<rparr>)\n  \\<Longrightarrow> d2 (Suc n2) = Some (pair (Some \\<lparr>prod_lhs = A2, prod_rhs = r2\\<rparr>) \\<lparr>cfg_conf=xl2@r2@teB b#x2\\<rparr>)\n  \\<Longrightarrow> xl1@r1=xl2@r2\n  \\<Longrightarrow> \\<lparr>prod_lhs = A1, prod_rhs = r1\\<rparr> = \\<lparr>prod_lhs = A2, prod_rhs = r2\\<rparr>\"\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac\n      ?d1.0=\"d1\"\n      and n=\"n1\"\n      in cfgRM_derivation_to_Esplit_derivation)\n     apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac d2a S)(*strict*)\n  apply(rename_tac d1x S1)\n  apply(rename_tac d1x S1)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1x S1)(*strict*)\n   prefer 2\n   apply(rule_tac\n      ?d1.0=\"d2\"\n      and n=\"n2\"\n      in cfgRM_derivation_to_Esplit_derivation)\n     apply(rename_tac d1x S1)(*strict*)\n     apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n     apply(force)\n    apply(rename_tac d1x S1)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1)(*strict*)\n   apply(force)\n  apply(rename_tac d1x S1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1x S1 d2a S)(*strict*)\n  apply(rename_tac d2x S2)\n  apply(rename_tac d1x S1 d2x S2)(*strict*)\n  apply(subgoal_tac \"EValidSplit G S1\")\n   apply(rename_tac d1x S1 d2x S2)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"S1 \\<in> SSC\" for SSC)\n    apply(rename_tac d1x S1 d2x S2)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"d1x\"\n      in Esplit.belongs_configurations)\n     apply(rename_tac d1x S1 d2x S2)(*strict*)\n     apply(rule Esplit.derivation_initial_belongs)\n      apply(rename_tac d1x S1 d2x S2)(*strict*)\n      apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2)(*strict*)\n   apply(simp add: Esplit_configurations_def)\n  apply(rename_tac d1x S1 d2x S2)(*strict*)\n  apply(subgoal_tac \"EValidSplit G S2\")\n   apply(rename_tac d1x S1 d2x S2)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"S2 \\<in> SSC\" for SSC)\n    apply(rename_tac d1x S1 d2x S2)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"d2x\"\n      in Esplit.belongs_configurations)\n     apply(rename_tac d1x S1 d2x S2)(*strict*)\n     apply(rule Esplit.derivation_initial_belongs)\n      apply(rename_tac d1x S1 d2x S2)(*strict*)\n      apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2)(*strict*)\n   apply(simp add: Esplit_configurations_def)\n  apply(rename_tac d1x S1 d2x S2)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1x S1 d2x S2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      S=\"S1\"\n      and e=\"\\<lparr>prod_lhs = A1, prod_rhs = r1\\<rparr>\"\n      and w=\"xl1 @ teA A1 # teB b # x1\"\n      and w'=\"xl1 @ r1 @ teB b # x1\"\n      in ESplit_cfgRM_step_can_be_simulated)\n      apply(rename_tac d1x S1 d2x S2)(*strict*)\n      apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d1x S1 d2x S2)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"d1\"\n      and n=\"n1\"\n      and m=\"Suc n1\"\n      in cfgRM.step_detail_before_some_position)\n      apply(rename_tac d1x S1 d2x S2)(*strict*)\n      apply(rule cfgRM.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d1x S1 d2x S2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1x S1 d2x S2 S')(*strict*)\n  apply(rename_tac S1x)\n  apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n   prefer 2\n   apply(rule_tac\n      S=\"S2\"\n      and e=\"\\<lparr>prod_lhs = A2, prod_rhs = r2\\<rparr>\"\n      and w=\"xl2 @ teA A2 # teB b # x2\"\n      and w'=\"xl2 @ r2 @ teB b # x2\"\n      in ESplit_cfgRM_step_can_be_simulated)\n      apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n      apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"d2\"\n      and n=\"n2\"\n      and m=\"Suc n2\"\n      in cfgRM.step_detail_before_some_position)\n      apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n      apply(rule cfgRM.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1x S1 d2x S2 S1x S')(*strict*)\n  apply(rename_tac S2x)\n  apply(rename_tac d1x S1 d2x S2 S1x S2x)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1x S1 d2x S2 S1x S2x)(*strict*)\n   prefer 2\n   apply(rule_tac\n      S=\"S1x\"\n      and b=\"b\"\n      and x=\"x1\"\n      and v=\"xl1 @ r1\"\n      in EValidSplit_take_prefix)\n      apply(rename_tac d1x S1 d2x S2 S1x S2x)(*strict*)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1x S2x)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1x S2x)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1x S2x)(*strict*)\n   apply(force)\n  apply(rename_tac d1x S1 d2x S2 S1x S2x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1x S1 d2x S2 S2x S1a S2a)(*strict*)\n  apply(rename_tac S1a S1b)\n  apply(rename_tac d1x S1 d2x S2 S2x S1a S1b)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1x S1 d2x S2 S2x S1a S1b)(*strict*)\n   prefer 2\n   apply(rule_tac\n      S=\"S2x\"\n      and b=\"b\"\n      and x=\"x2\"\n      and v=\"xl2 @ r2\"\n      in EValidSplit_take_prefix)\n      apply(rename_tac d1x S1 d2x S2 S2x S1a S1b)(*strict*)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S2x S1a S1b)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S2x S1a S1b)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S2x S1a S1b)(*strict*)\n   apply(force)\n  apply(rename_tac d1x S1 d2x S2 S2x S1a S1b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S1c S2a)(*strict*)\n  apply(rename_tac S2a S2b)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n   prefer 2\n   apply(rule_tac\n      ?S1.0=\"S1a\"\n      and S1'=\"S1b\"\n      and ?S2.0=\"S2a\"\n      and S2'=\"S2b\"\n      and ?d1.0=\"d1\"\n      and ?d2.0=\"d2\"\n      and ?n1.0=\"Suc n1\"\n      and ?n2.0=\"Suc n2\"\n      and v=\"xl1 @ r1\"\n      and b=\"b\"\n      and ?x1.0=\"Esplit_signature S1b\"\n      in equal_split_prefix)\n                  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n                  apply(force)\n                 apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n                 apply(force)\n                apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n                apply(force)\n               apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n               apply(force)\n              apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n              apply(force)\n             apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n             apply(rule_tac\n      t=\"xl1@r1\"\n      and s=\"xl2@r2\"\n      in ssubst)\n              apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n              apply(force)\n             apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n             apply(force)\n            apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n            apply(force)\n           apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n           apply(force)\n          apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n          apply(force)\n         apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n         apply(force)\n        apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n        apply(force)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n   apply(force)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n  apply(subgoal_tac \"setA (Esplit_signature S1b) = {}\")\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"d1\"\n      and n=\"n1\"\n      and m=\"Suc n1\"\n      in cfgRM.step_detail_before_some_position)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n      apply(rule cfgRM.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n   apply(clarsimp)\n   apply(simp add: cfgRM_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l r)(*strict*)\n   apply(subgoal_tac \"\\<exists>l'. liftB l' = r\")\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l r)(*strict*)\n    prefer 2\n    apply(rule_tac\n      x=\"filterB r\"\n      in exI)\n    apply (rule liftBDeConv2)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l r)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l')(*strict*)\n   apply(subgoal_tac \"strict_prefix xl1 l \\<or> SSX\" for SSX)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l')(*strict*)\n    prefer 2\n    apply(rule mutual_strict_prefix_strict_prefix)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l')(*strict*)\n   apply(erule disjE)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l')(*strict*)\n    apply(simp add: strict_prefix_def)\n    apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' c)(*strict*)\n    apply(rule_tac\n      xs=\"c\"\n      in rev_cases)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' c)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' c ys y)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' ys y)(*strict*)\n    apply(case_tac ys)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' ys y)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' ys y a list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list)(*strict*)\n    apply(subgoal_tac \"LR1ProdFormSimp G\")\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list)(*strict*)\n     prefer 2\n     apply(simp add: split_TSstructure_def)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list)(*strict*)\n    apply(simp add: LR1ProdFormSimp_def)\n    apply(erule_tac\n      x=\"\\<lparr>prod_lhs = A1, prod_rhs = r1\\<rparr>\"\n      in ballE)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' list)(*strict*)\n     apply(case_tac list)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' list)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' list a lista)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list ba A B)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list ba A B)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list ba A B)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list ba A B)(*strict*)\n     apply(clarify)\n     apply(subgoal_tac \"A1=B\")\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list ba A B)(*strict*)\n      prefer 2\n      apply(rule sym)\n      apply (metis Cons_eq_appendI append_Nil DT_two_elements.inject(1) unequal_by_first_char)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list ba A B)(*strict*)\n     apply(clarify)\n     apply(thin_tac \"[teA A1] @ list @ [y, teA A1] = teA A1 # list @ [y, teA A1]\")\n     apply(clarsimp)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list)(*strict*)\n     apply(subgoal_tac \"CFG_no_self_loop G\")\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list)(*strict*)\n      prefer 2\n      apply(simp add: split_TSstructure_def)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list)(*strict*)\n     apply(simp add: CFG_no_self_loop_def)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list ba A B)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' list)(*strict*)\n    apply(case_tac list)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' list)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' list a lista)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l')(*strict*)\n   apply(erule disjE)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l')(*strict*)\n    apply(simp add: strict_prefix_def)\n    apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l' c)(*strict*)\n    apply(rule_tac\n      xs=\"c\"\n      in rev_cases)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l' c)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l' c ys y)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l' ys y)(*strict*)\n    apply(case_tac ys)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l' ys y)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l')(*strict*)\n     apply(case_tac l')\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l')(*strict*)\n      apply(clarsimp)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l' a list)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l' ys y a list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l' y list)(*strict*)\n    apply (metis ConsApp setA_liftB setA_decompose setA_setmp_concat_2 all_not_in_conv append_Nil elemInsetA emptyE empty_subsetI)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l')(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l')(*strict*)\n   apply(case_tac l')\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l')(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' a list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n  apply(subgoal_tac \"setA (Esplit_signature S2b) = {}\")\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"d2\"\n      and n=\"n2\"\n      and m=\"Suc n2\"\n      in cfgRM.step_detail_before_some_position)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n      apply(rule cfgRM.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n   apply(clarsimp)\n   apply(simp add: cfgRM_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l r)(*strict*)\n   apply(subgoal_tac \"\\<exists>l'. liftB l' = r\")\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l r)(*strict*)\n    prefer 2\n    apply(rule_tac\n      x=\"filterB r\"\n      in exI)\n    apply (rule liftBDeConv2)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l r)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l')(*strict*)\n   apply(subgoal_tac \"strict_prefix xl2 l \\<or> SSX\" for SSX)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l')(*strict*)\n    prefer 2\n    apply(rule mutual_strict_prefix_strict_prefix)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l')(*strict*)\n   apply(erule disjE)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l')(*strict*)\n    apply(simp add: strict_prefix_def)\n    apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' c)(*strict*)\n    apply(rule_tac\n      xs=\"c\"\n      in rev_cases)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' c)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' c ys y)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' ys y)(*strict*)\n    apply(case_tac ys)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' ys y)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' ys y a list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list)(*strict*)\n    apply(subgoal_tac \"LR1ProdFormSimp G\")\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list)(*strict*)\n     prefer 2\n     apply(simp add: split_TSstructure_def)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list)(*strict*)\n    apply(simp add: LR1ProdFormSimp_def)\n    apply(erule_tac\n      x=\"\\<lparr>prod_lhs = A2, prod_rhs = r2\\<rparr>\"\n      in ballE)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' list)(*strict*)\n     apply(case_tac list)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' list)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' list a lista)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list ba A B)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list ba A B)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list ba A B)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list ba A B)(*strict*)\n     apply(clarify)\n     apply(subgoal_tac \"A2=B\")\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list ba A B)(*strict*)\n      prefer 2\n      apply(rule sym)\n      apply (metis Cons_eq_appendI append_Nil DT_two_elements.inject(1) unequal_by_first_char)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list ba A B)(*strict*)\n     apply(clarify)\n     apply(thin_tac \"[teA A2] @ list @ [y, teA A2] = teA A2 # list @ [y, teA A2]\")\n     apply(clarsimp)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list)(*strict*)\n     apply(subgoal_tac \"CFG_no_self_loop G\")\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list)(*strict*)\n      prefer 2\n      apply(simp add: split_TSstructure_def)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list)(*strict*)\n     apply(simp add: CFG_no_self_loop_def)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' y list ba A B)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' list)(*strict*)\n    apply(case_tac list)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' list)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' list a lista)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l')(*strict*)\n   apply(erule disjE)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l')(*strict*)\n    apply(simp add: strict_prefix_def)\n    apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l' c)(*strict*)\n    apply(rule_tac\n      xs=\"c\"\n      in rev_cases)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l' c)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l' c ys y)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l' ys y)(*strict*)\n    apply(case_tac ys)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l' ys y)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l')(*strict*)\n     apply(case_tac l')\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l')(*strict*)\n      apply(clarsimp)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l' a list)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l' ys y a list)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l' y list)(*strict*)\n    apply (metis ConsApp setA_liftB setA_decompose setA_setmp_concat_2 all_not_in_conv append_Nil elemInsetA emptyE empty_subsetI)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l l')(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l')(*strict*)\n   apply(case_tac l')\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l')(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b l' a list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n  apply(case_tac A1)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n   apply(subgoal_tac \"False\")\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"d1\"\n      and n=\"n1\"\n      and \\<pi>=\"map the (get_labels d1 n1)\"\n      in cfgRM_reachable_only_l3_nonterminals)\n        apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n        apply(force)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n      apply(simp add: cfgRM.trans_der_def cfgRM.derivation_initial_def)\n      apply(rule conjI)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n       apply(rule cfgRM.derivation_initial_belongs)\n        apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n        apply(simp add: split_TSstructure_def)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n       apply(simp add: cfgRM.trans_der_def cfgRM.derivation_initial_def)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n      apply(rule_tac\n      t=\"length (get_labels d1 n1)\"\n      and s=\"n1\"\n      in ssubst)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n       apply (metis get_labels_length)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n      apply(rule conjI)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n       apply(rule_tac\n      G=\"G\"\n      in cfgRM.get_labels_the_Some_on_defined_positions)\n        apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n        apply(force)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n      apply(rule conjI)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n       apply(case_tac \"d1 0\")\n        apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n        apply(clarsimp)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba a)(*strict*)\n       apply(clarsimp)\n       apply(case_tac a)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba a option baa)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba baa)(*strict*)\n       apply(simp add: cfg_initial_configurations_def)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n     apply(clarsimp)\n     apply(rule_tac\n      t=\"length (get_labels d1 n1)\"\n      and s=\"n1\"\n      in ssubst)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n      apply (metis get_labels_length)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n   apply(rule_tac\n      xs=\"teB b # Esplit_signature S1b\"\n      in rev_cases)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba ys y)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"butlast (xl1 @ teA (cons_l2   q ba) # ys @ [y]) = SSX\" for SSX)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba ys y)(*strict*)\n    prefer 2\n    apply(rule butlast_direct)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba ys y)(*strict*)\n   apply(clarsimp)\n   apply(simp add: filterA_distrib_append filterA_liftB)\n   apply (metis only_l3_nonterminals_drop only_l3_nonterminals_l2_at_front)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2)(*strict*)\n  apply(case_tac A2)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n   apply(subgoal_tac \"False\")\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"d2\"\n      and n=\"n2\"\n      and \\<pi>=\"map the (get_labels d2 n2)\"\n      in cfgRM_reachable_only_l3_nonterminals)\n        apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n        apply(force)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n      apply(simp add: cfgRM.trans_der_def cfgRM.derivation_initial_def)\n      apply(rule conjI)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n       apply(rule cfgRM.derivation_initial_belongs)\n        apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n        apply(simp add: split_TSstructure_def)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n       apply(simp add: cfgRM.trans_der_def cfgRM.derivation_initial_def)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n      apply(rule_tac\n      t=\"length (get_labels d2 n2)\"\n      and s=\"n2\"\n      in ssubst)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n       apply (metis get_labels_length)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n      apply(rule conjI)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n       apply(rule_tac\n      G=\"G\"\n      in cfgRM.get_labels_the_Some_on_defined_positions)\n        apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n        apply(force)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n      apply(rule conjI)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n       apply(case_tac \"d2 0\")\n        apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n        apply(clarsimp)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa a)(*strict*)\n       apply(clarsimp)\n       apply(case_tac a)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa a option bb)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa bb)(*strict*)\n       apply(simp add: cfg_initial_configurations_def)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n     apply(clarsimp)\n     apply(rule_tac\n      t=\"length (get_labels d2 n2)\"\n      and s=\"n2\"\n      in ssubst)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n      apply (metis get_labels_length)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n   apply(rule_tac\n      xs=\"teB b # Esplit_signature S2b\"\n      in rev_cases)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa ys y)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"butlast (xl2 @ teA (cons_l2   q baa) # ys @ [y]) = SSX\" for SSX)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa ys y)(*strict*)\n    prefer 2\n    apply(rule butlast_direct)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q baa ys y)(*strict*)\n   apply(clarsimp)\n   apply(simp add: filterA_distrib_append filterA_liftB)\n   apply (metis only_l3_nonterminals_drop only_l3_nonterminals_l2_at_front)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 q1a baa q2a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac q11 A1 q12 q21 A2 q22)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n  apply(subgoal_tac \"EValidSplitExt S1\")\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n   apply(subgoal_tac \"EValidSplitExt S2\")\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n    apply(subgoal_tac \"EValidSplitExt (S1a@S1b)\")\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n     apply(subgoal_tac \"EValidSplitExt (S2a@S2b)\")\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n      apply(thin_tac \"Esplit.derivation_initial G d1x\")\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n      apply(thin_tac \"Esplit.derivation_initial G d2x\")\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n      apply(thin_tac \"get_labels d2x n2 = get_labels d2 n2\")\n      apply(thin_tac \"get_labels d1x n1 = get_labels d1 n1\")\n      apply(thin_tac \"d1x n1 = Some (pair e1 S1)\")\n      apply(thin_tac \"d2x n2 = Some (pair e2 S2)\")\n      apply(thin_tac \"cfgRM.derivation_initial G d1\")\n      apply(thin_tac \"d1 n1 = SSX\" for SSX)\n      apply(thin_tac \"d1 (Suc n1) = SSX\" for SSX)\n      apply(thin_tac \"cfgRM.derivation_initial G d2\")\n      apply(thin_tac \"d2 n2 = SSX\" for SSX)\n      apply(thin_tac \"d2 (Suc n2) = SSX\" for SSX)\n      apply(clarsimp)\n      apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n      apply(subgoal_tac \"X\" for X)\n       apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n       prefer 2\n       apply(rule_tac\n      ?A1.0=\"cons_l3 q11 A1 q12\"\n      and ?A2.0=\"cons_l3 q21 A2 q22\"\n      and S2a=\"S2a\"\n      and S1a=\"S1a\"\n      and ?S1.0=\"S1\"\n      and ?S2.0=\"S2\"\n      in LR1_property_part2_equal_productions)\n                      apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n                      apply(force)\n                      apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n                      apply(force)\n                      apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n                      apply(force)\n                      apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n                      apply(force)\n                      apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n                      apply(force)\n                      apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n                      apply(force)\n                      apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n                      apply(force)\n                      apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n                      apply(force)\n                      apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n                      apply(force)\n                      apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n                      apply(force)\n                      apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n                      apply(force)\n                     apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n                     apply(rule_tac\n      t=\"length xl1 + length r1\"\n      and s=\"length (xl1@r1)\"\n      in ssubst)\n                      apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n                      apply(simp (no_asm))\n                     apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n                     apply(force)\n                    apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n                    apply(force)\n                   apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n                   apply(force)\n                  apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n                  apply(force)\n                 apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n                 apply(force)\n                apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n                apply(force)\n               apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n               apply(force)\n              apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n              apply(force)\n             apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n             apply(force)\n            apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n            apply(rule_tac\n      t=\"length xl2 + length r2\"\n      and s=\"length (xl2@r2)\"\n      in ssubst)\n             apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n             apply(simp (no_asm))\n            apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n            apply(force)\n           apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n           apply(force)\n          apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n          apply(force)\n         apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n         apply(rule_tac\n      t=\"Suc (length xl1 + length r1)\"\n      and s=\"Suc (length xl2 + length r2)\"\n      in ssubst)\n          apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n          prefer 2\n          apply(force)\n         apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n         apply (metis length_append)\n        apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n        apply(force)\n       apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n       apply(force)\n      apply(rename_tac S1 S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n     apply(rule_tac\n      G=\"G\"\n      and G'=\"G'\"\n      and d=\"derivation_append d2x (der2 S2 \\<lparr>prod_lhs = cons_l3 q21 A2 q22, prod_rhs = r2\\<rparr> (S2a @ S2b)) n2\"\n      and n=\"Suc n2\"\n      in Esplit_derivation_enforces_EValidSplitExt)\n         apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n         apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n         apply(force)\n        apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n        apply(force)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n      apply(rule Esplit.derivation_append_preserves_derivation_initial)\n        apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n        apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n        apply(force)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n      apply(rule Esplit.derivation_append_preserves_derivation)\n        apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n        apply(rule Esplit.derivation_initial_is_derivation)\n        apply(force)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n       apply(rule Esplit.der2_is_derivation)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n      apply(clarsimp)\n      apply(simp add: der2_def)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n     apply(simp add: derivation_append_def der2_def)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n    apply(rule_tac\n      G=\"G\"\n      and G'=\"G'\"\n      and d=\"derivation_append d1x (der2 S1 \\<lparr>prod_lhs = cons_l3 q11 A1 q12, prod_rhs = r1\\<rparr> (S1a @ S1b)) n1\"\n      and n=\"Suc n1\"\n      in Esplit_derivation_enforces_EValidSplitExt)\n        apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n        apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n        apply(force)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n     apply(rule Esplit.derivation_append_preserves_derivation_initial)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n       apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n     apply(rule Esplit.derivation_append_preserves_derivation)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n       apply(rule Esplit.derivation_initial_is_derivation)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n      apply(rule Esplit.der2_is_derivation)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n     apply(clarsimp)\n     apply(simp add: der2_def)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n    apply(simp add: derivation_append_def der2_def)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n   apply(rule_tac\n      G=\"G\"\n      and G'=\"G'\"\n      and d=\"d2x\"\n      and n=\"n2\"\n      in Esplit_derivation_enforces_EValidSplitExt)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n       apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n   apply(force)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n  apply(rule_tac\n      G=\"G\"\n      and G'=\"G'\"\n      and d=\"d1x\"\n      and n=\"n1\"\n      in Esplit_derivation_enforces_EValidSplitExt)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n      apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n   apply(force)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q11 A1 q12 q21 A2 q22)(*strict*)\n  apply(force)\n  done\n\nlemma no_pre_DT_revert_position: \"\n  F2LR1inputx G G'\n  \\<Longrightarrow> split_TSstructure G\n  \\<Longrightarrow> EValidSplit G S\n  \\<Longrightarrow> EValidSplitExt S\n  \\<Longrightarrow> Esplit_signature S = w @ v @ teA A # liftB \\<alpha>\n  \\<Longrightarrow> is_DT_revert_position (restrict G' G S (length w)) rp\n  \\<Longrightarrow> w \\<noteq> []\n  \\<Longrightarrow> Q\"\n  apply(subgoal_tac \"get_line rp \\<le> length w\")\n   prefer 2\n   apply(simp add: is_DT_revert_position_def valid_DT_revert_position_def restrict_def restrict_map_def restrict_len_def)\n   apply(clarsimp)\n   apply(subgoal_tac \"length (nat_seq 0 (min (length S) (length w) - Suc 0))=SSX\" for SSX)\n    prefer 2\n    apply(rule nat_seq_length_prime)\n   apply(case_tac rp)\n    apply(rename_tac nat)(*strict*)\n    apply(clarsimp)\n    apply(simp add: get_line_def)\n   apply(rename_tac nat1 nat2)(*strict*)\n   apply(clarsimp)\n   apply(simp add: get_line_def)\n  apply(subgoal_tac \"\\<exists>Sw Sv SA S\\<alpha>. S = Sw @ Sv @ SA # S\\<alpha> \\<and> Esplit_signature Sw = w \\<and> length Sw = length (Esplit_signature Sw) \\<and> Esplit_signature Sv = v \\<and> length Sv = length (Esplit_signature Sv) \\<and> Esplit_signature [SA] = [teA A] \\<and> Esplit_signature S\\<alpha> = liftB \\<alpha> \")\n   prefer 2\n   apply(rule no_pre_DT_revert_position_hlp2)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac Sw Sv SA S\\<alpha>)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac Sw Sv SA S\\<alpha>)(*strict*)\n   prefer 2\n   apply(rule_tac\n      S=\"Sw@Sv\"\n      in EValidSplit_Esplit_signature_length)\n   apply(force)\n  apply(rename_tac Sw Sv SA S\\<alpha>)(*strict*)\n  apply(clarsimp)\n  apply(case_tac rp)\n   apply(rename_tac Sw Sv SA S\\<alpha> nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i)\n   apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n   apply(subgoal_tac \"(Sw@Sv @ SA # S\\<alpha>) ! length (Sw@Sv) = (SA#S\\<alpha>)!SSX\" for SSX)\n    apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n    prefer 2\n    apply(rule nth_append_2_prime)\n      apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n      apply(force)\n     apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n     apply(force)\n    apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n    apply(force)\n   apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n   apply(simp add: is_DT_revert_position_def)\n   apply(simp add: valid_DT_revert_position_def)\n   apply(clarsimp)\n   apply(simp add: EValidSplitExt_def EValidSplitExt_no_elim_before_nonterminal_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"length (Sw@Sv)\"\n      in allE)\n   apply(erule impE)\n    apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n    apply(force)\n   apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n   apply(erule impE)\n    apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n    apply(clarsimp)\n    apply(simp add: Esplit_signature_def option_to_list_def)\n    apply(case_tac \"ESplitItem_elem SA\")\n     apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac Sw Sv SA S\\<alpha> i a)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n   apply(simp add: get_line_def)\n   apply(erule_tac\n      x=\"i\"\n      in allE)\n   apply (simp add: Esplit_signature_append)\n   apply(subgoal_tac \"length (nat_seq 0 (length (Esplit_signature Sw) - Suc 0)) = SSX\" for SSX)\n    apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n    prefer 2\n    apply(rule nat_seq_length_prime)\n   apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n   apply(subgoal_tac \"(nat_seq 0 (length (Esplit_signature Sw) - Suc 0) ! i) = SSX\" for SSX)\n    apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n    prefer 2\n    apply(rule nat_seq_nth_compute)\n     apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n     apply(force)\n    apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n    apply(simp add: restrict_def restrict_map_def restrict_len_def)\n   apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n   apply(subgoal_tac \"length(PSplitItem_elim (restrict G' G (Sw @ Sv @ SA # S\\<alpha>) (length (Esplit_signature Sw)) ! i)) = length(ESplitItem_elim ((Sw @ Sv @ SA # S\\<alpha>) ! i)) \")\n    apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n    apply(force)\n   apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n   apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n   apply(clarsimp)\n   apply(rule_tac\n      t=\"(map SSf SSw)!SSn\" for SSf SSw SSn\n      in ssubst)\n    apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n    apply(rule nth_map)\n    apply(simp add: restrict_def restrict_map_def restrict_len_def)\n   apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"(Sw @ Sv @ SA # S\\<alpha>) ! i = Sw!i\")\n    apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n    prefer 2\n    apply(rule nth_append_1)\n    apply(simp add: restrict_def restrict_map_def restrict_len_def)\n   apply(rename_tac Sw Sv SA S\\<alpha> i)(*strict*)\n   apply(force)\n  apply(rename_tac Sw Sv SA S\\<alpha> nat1 nat2)(*strict*)\n  apply(simp add: get_line_def)\n  apply(rename_tac i1 i2)\n  apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n  apply(simp add: is_DT_revert_position_def)\n  apply(simp add: valid_DT_revert_position_def)\n  apply(clarsimp)\n  apply(subgoal_tac \"length (nat_seq 0 (length (Esplit_signature Sw) - Suc 0)) = SSX\" for SSX)\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n   prefer 2\n   apply(rule nat_seq_length_prime)\n  apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n  apply(subgoal_tac \"(Sw @ Sv @ SA # S\\<alpha>) ! i1 = Sw!i1\")\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n   prefer 2\n   apply(rule nth_append_1)\n   apply(simp add: restrict_def restrict_map_def restrict_len_def)\n  apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n  apply(case_tac \"PSplitItem_prods (restrict G' G (Sw @ Sv @ SA # S\\<alpha>) (length (Esplit_signature Sw)) ! i1) ! i2\")\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 a)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n  apply(clarsimp)\n  apply(erule disjE)\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"get_prod_at_DT_revert_position (restrict G' G (Sw @ Sv @ SA # S\\<alpha>) (length (Esplit_signature Sw))) (gen i1 i2) = b\")\n    apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n    apply(simp add: EValidSplitExt_def EValidSplitExt_no_pop_in_prods_before_nonterminal_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"length (Sw@Sv)\"\n      in allE)\n    apply(clarsimp)\n    apply(erule impE)\n     apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n     apply(rule_tac\n      t=\"(Sw @ Sv @ SA # S\\<alpha>) ! length (Esplit_signature (Sw @ Sv))\"\n      and s=\"(SA#S\\<alpha>)!X\" for X\n      in ssubst)\n      apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n      apply(rule nth_append_2_prime)\n        apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n        apply(force)\n       apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n       apply(force)\n      apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n     apply(clarsimp)\n     apply(simp add: Esplit_signature_def option_to_list_def)\n     apply(case_tac \"ESplitItem_elem SA\")\n      apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 a)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n    apply(erule_tac\n      x=\"i1\"\n      in allE)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"i2\"\n      in allE)\n    apply(subgoal_tac \" length (ESplitItem_prods ((Sw @ Sv @ SA # S\\<alpha>) ! i1)) = length (PSplitItem_prods (restrict G' G (Sw @ Sv @ SA # S\\<alpha>) (length (Esplit_signature Sw)) ! i1))\")\n     apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n     apply(subgoal_tac \"(i1 + (length Sw - i1 - Suc 0) + Suc 0) = length (Esplit_signature Sw)\")\n      apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n      apply(subgoal_tac \"ESplitItem_prods (Sw ! i1) ! i2 = SSX\" for SSX)\n       apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n       prefer 2\n       apply(rule_tac\n      k=\"length Sw - i1 - Suc 0\"\n      and G=\"G\"\n      and S1'=\"Sv@SA#S\\<alpha>\"\n      and G'=\"G'\"\n      in nonabstracted_productions_are_unmodified3)\n         apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n         apply(force)\n        apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n        apply(force)\n       apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n       apply(force)\n      apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n      apply(force)\n     apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n     apply(clarsimp)\n     apply(simp add: restrict_def restrict_map_def restrict_len_def)\n    apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n    apply(simp (no_asm) add: restrict_def restrict_map_def restrict_len_def)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"(map SSf SSw)!SSn\" for SSf SSw SSn\n      in ssubst)\n     apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n     apply(rule nth_map)\n     apply(rule_tac\n      t=\"length (nat_seq 0 (length (Esplit_signature Sw) - Suc 0))\"\n      in ssubst)\n      apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n      apply(rule nat_seq_length_prime)\n     apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n     apply(simp add: restrict_def restrict_map_def restrict_len_def)\n    apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n    apply(clarsimp)\n    apply(rule_tac\n      t=\"nat_seq 0 (length (Esplit_signature Sw) - Suc 0) ! i1\"\n      in ssubst)\n     apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n     apply(rule nat_seq_nth_compute)\n      apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n      apply(force)\n     apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n     apply(simp add: restrict_def restrict_map_def restrict_len_def)\n    apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n    apply(clarsimp)\n    apply(simp add: restrict_newprods_def)\n    apply(rule conjI)\n     apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n     apply(clarsimp)\n     apply(simp add: restrict_newprodsX_def)\n     apply(clarsimp)\n     apply(rule_tac\n      t=\"length (nat_seq 0 (length (ESplitItem_prods (Sw ! i1)) - Suc 0))\"\n      in ssubst)\n      apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n      apply(rule nat_seq_length_prime)\n     apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n     apply(force)\n    apply(rename_tac Sw Sv SA S\\<alpha> i1 i2)(*strict*)\n    apply(clarsimp)\n    apply (metis liftB_length)\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n   apply(simp add: get_prod_at_DT_revert_position_def)\n  apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n  apply(clarsimp)\n  apply(simp add: EValidSplitExt_def EValidSplitExt_ident_line_is_always_at_the_latest_nonterminal_def)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"length (Esplit_signature Sw) + length (Esplit_signature Sv)\"\n      in allE)\n  apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n  apply(clarsimp)\n  apply(erule impE)\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n   apply(rule_tac\n      t=\"(Sw @ Sv @ SA # S\\<alpha>) ! length (Esplit_signature (Sw @ Sv))\"\n      and s=\"(SA#S\\<alpha>)!X\" for X\n      in ssubst)\n    apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n    apply(rule nth_append_2_prime)\n      apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n      apply(force)\n     apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n     apply(force)\n    apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n   apply(clarsimp)\n   apply(simp add: Esplit_signature_def option_to_list_def)\n   apply(case_tac \"ESplitItem_elem SA\")\n    apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b a)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n  apply(case_tac \"Suc i1 = length (Sw@Sv)\")\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n   apply(clarsimp)\n   apply(simp add: Pident_line_def Pident_lines_def)\n   apply(clarsimp)\n   apply(simp add: restrict_def restrict_map_def restrict_len_def)\n  apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n  apply(erule_tac\n      x=\"Suc i1\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n   apply (simp add: Esplit_signature_append)\n   apply(simp add: restrict_def restrict_map_def restrict_len_def)\n  apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n  apply(simp add: Eident_line_def Eident_lines_def Pident_line_def Pident_lines_def)\n  apply(clarsimp)\n  apply(simp add: restrict_def restrict_map_def restrict_len_def)\n  apply(subgoal_tac \"nat_seq 0 (length (Esplit_signature Sw) - Suc 0) ! Suc i1 = SSX\" for SSX)\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n   prefer 2\n   apply(rule nat_seq_nth_compute)\n    apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n    apply(force)\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n   apply(force)\n  apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"(Sw @ Sv @ SA # S\\<alpha>) ! Suc i1 = Sw!Suc i1\")\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n   prefer 2\n   apply(rule nth_append_1)\n   apply(force)\n  apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"length (restrict_newprods G' G Sw (Suc i1)) = length (ESplitItem_prods (Sw ! Suc i1))\")\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n   apply(force)\n  apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n  apply(simp add: restrict_newprods_def)\n  apply(subgoal_tac \"length(nat_seq 0 (length (ESplitItem_prods (Sw ! Suc i1)) - Suc 0)) = SSX\" for SSX)\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n   prefer 2\n   apply(rule nat_seq_length_prime)\n  apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n  apply(case_tac \"restrict_newignore Sw (nat_seq 0 (length (Esplit_signature Sw) - Suc 0) ! i1) = []\")\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"restrict_newignore Sw (Suc i1) = []\")\n    apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n    apply(clarsimp)\n    apply(simp add: restrict_newprodsX_def)\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"length(liftB (ESplitItem_prods (Sw ! Suc i1))) = SSX\" for SSX)\n    apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n    prefer 2\n    apply(rule liftB_length)\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n   apply(case_tac \"ESplitItem_prods (Sw ! Suc i1)\")\n    apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b a list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"restrict_newignore Sw (Suc i1) = []\")\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n   apply(clarsimp)\n   apply(simp add: restrict_newprodsX_def)\n  apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"length(liftB (ESplitItem_prods (Sw ! Suc i1))) = SSX\" for SSX)\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n   prefer 2\n   apply(rule liftB_length)\n  apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n  apply(case_tac \"ESplitItem_prods (Sw ! Suc i1)\")\n   apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac Sw Sv SA S\\<alpha> i1 i2 b a list)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma F_SDPDA_TO_CFG_STD__enforces_cfg_LRk_3: \"\n  F2LR1inputx G' G\n  \\<Longrightarrow> split_TSstructure G'\n  \\<Longrightarrow> cfgRM.derivation_initial G' d1\n  \\<Longrightarrow> d1 n1 = Some (pair e1 \\<lparr>cfg_conf = \\<beta>1 @ teA A1 # teB b # liftB \\<alpha>3\\<rparr>)\n  \\<Longrightarrow> d1 (Suc n1) = Some (pair (Some \\<lparr>prod_lhs = A1, prod_rhs = \\<beta>2\\<rparr>) \\<lparr>cfg_conf = \\<beta>1 @ \\<beta>2 @ teB b # liftB \\<alpha>3\\<rparr>)\n  \\<Longrightarrow> cfgRM.derivation_initial G' d2\n  \\<Longrightarrow> d2 n2 = Some (pair e2 \\<lparr>cfg_conf = \\<beta>1 @ \\<beta>2 @ teB b # liftB \\<alpha>1 @ teA A2 # liftB \\<alpha>2\\<rparr>)\n  \\<Longrightarrow> d2 (Suc n2) = Some (pair (Some \\<lparr>prod_lhs = A2, prod_rhs = []\\<rparr>) \\<lparr>cfg_conf = \\<beta>1 @ \\<beta>2 @ teB b # liftB \\<alpha>1 @ liftB \\<alpha>2\\<rparr>)\n  \\<Longrightarrow> \\<lparr>prod_lhs = A1, prod_rhs = \\<beta>2\\<rparr> \\<in> cfg_productions G'\n  \\<Longrightarrow> \\<lparr>prod_lhs = A2, prod_rhs = []\\<rparr> \\<in> cfg_productions G'\n  \\<Longrightarrow> False\"\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac\n      ?d1.0=\"d1\"\n      and n=\"n1\"\n      in cfgRM_derivation_to_Esplit_derivation)\n     apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac d2a S)(*strict*)\n  apply(rename_tac d1x S1)\n  apply(rename_tac d1x S1)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1x S1)(*strict*)\n   prefer 2\n   apply(rule_tac\n      ?d1.0=\"d2\"\n      and n=\"n2\"\n      in cfgRM_derivation_to_Esplit_derivation)\n     apply(rename_tac d1x S1)(*strict*)\n     apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n     apply(force)\n    apply(rename_tac d1x S1)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1)(*strict*)\n   apply(force)\n  apply(rename_tac d1x S1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1x S1 d2a S)(*strict*)\n  apply(rename_tac d2x S2)\n  apply(rename_tac d1x S1 d2x S2)(*strict*)\n  apply(subgoal_tac \"EValidSplit G' S1\")\n   apply(rename_tac d1x S1 d2x S2)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"S1 \\<in> SSC\" for SSC)\n    apply(rename_tac d1x S1 d2x S2)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"d1x\"\n      in Esplit.belongs_configurations)\n     apply(rename_tac d1x S1 d2x S2)(*strict*)\n     apply(rule Esplit.derivation_initial_belongs)\n      apply(rename_tac d1x S1 d2x S2)(*strict*)\n      apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2)(*strict*)\n   apply(simp add: Esplit_configurations_def)\n  apply(rename_tac d1x S1 d2x S2)(*strict*)\n  apply(subgoal_tac \"EValidSplit G' S2\")\n   apply(rename_tac d1x S1 d2x S2)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"S2 \\<in> SSC\" for SSC)\n    apply(rename_tac d1x S1 d2x S2)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"d2x\"\n      in Esplit.belongs_configurations)\n     apply(rename_tac d1x S1 d2x S2)(*strict*)\n     apply(rule Esplit.derivation_initial_belongs)\n      apply(rename_tac d1x S1 d2x S2)(*strict*)\n      apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2)(*strict*)\n   apply(simp add: Esplit_configurations_def)\n  apply(rename_tac d1x S1 d2x S2)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1x S1 d2x S2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      S=\"S1\"\n      and e=\"\\<lparr>prod_lhs = A1, prod_rhs = \\<beta>2\\<rparr>\"\n      and w=\"\\<beta>1 @ teA A1 # teB b # liftB \\<alpha>3\"\n      and w'=\"\\<beta>1 @ \\<beta>2 @ teB b # liftB \\<alpha>3\"\n      in ESplit_cfgRM_step_can_be_simulated)\n      apply(rename_tac d1x S1 d2x S2)(*strict*)\n      apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d1x S1 d2x S2)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"d1\"\n      and n=\"n1\"\n      and m=\"Suc n1\"\n      in cfgRM.step_detail_before_some_position)\n      apply(rename_tac d1x S1 d2x S2)(*strict*)\n      apply(rule cfgRM.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d1x S1 d2x S2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1x S1 d2x S2 S')(*strict*)\n  apply(rename_tac S1x)\n  apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n   prefer 2\n   apply(rule_tac\n      S=\"S2\"\n      and e=\"\\<lparr>prod_lhs = A2, prod_rhs = []\\<rparr>\"\n      and w=\"\\<beta>1 @ \\<beta>2 @ teB b # liftB \\<alpha>1 @ teA A2 # liftB \\<alpha>2\"\n      and w'=\"\\<beta>1 @ \\<beta>2 @ teB b # liftB \\<alpha>1 @ liftB \\<alpha>2\"\n      in ESplit_cfgRM_step_can_be_simulated)\n      apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n      apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"d2\"\n      and n=\"n2\"\n      and m=\"Suc n2\"\n      in cfgRM.step_detail_before_some_position)\n      apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n      apply(rule cfgRM.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d1x S1 d2x S2 S1x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1x S1 d2x S2 S1x S')(*strict*)\n  apply(rename_tac S2x)\n  apply(rename_tac d1x S1 d2x S2 S1x S2x)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1x S1 d2x S2 S1x S2x)(*strict*)\n   prefer 2\n   apply(rule_tac\n      S=\"S1x\"\n      and b=\"b\"\n      and x=\"liftB \\<alpha>3\"\n      and v=\"\\<beta>1 @ \\<beta>2\"\n      in EValidSplit_take_prefix)\n      apply(rename_tac d1x S1 d2x S2 S1x S2x)(*strict*)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1x S2x)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1x S2x)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1x S2x)(*strict*)\n   apply(force)\n  apply(rename_tac d1x S1 d2x S2 S1x S2x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1x S1 d2x S2 S2x S1a S2a)(*strict*)\n  apply(rename_tac S1a S1b)\n  apply(rename_tac d1x S1 d2x S2 S2x S1a S1b)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1x S1 d2x S2 S2x S1a S1b)(*strict*)\n   prefer 2\n   apply(rule_tac\n      S=\"S2x\"\n      and b=\"b\"\n      and x=\"liftB \\<alpha>1 @ liftB \\<alpha>2\"\n      and v=\"\\<beta>1 @ \\<beta>2\"\n      in EValidSplit_take_prefix)\n      apply(rename_tac d1x S1 d2x S2 S2x S1a S1b)(*strict*)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S2x S1a S1b)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S2x S1a S1b)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S2x S1a S1b)(*strict*)\n   apply(force)\n  apply(rename_tac d1x S1 d2x S2 S2x S1a S1b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S1c S2a)(*strict*)\n  apply(rename_tac S2a S2b)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n   prefer 2\n   apply(rule_tac\n      ?S1.0=\"S1a\"\n      and S1'=\"S1b\"\n      and ?S2.0=\"S2a\"\n      and S2'=\"S2b\"\n      and ?d1.0=\"d1\"\n      and ?d2.0=\"d2\"\n      and ?n1.0=\"Suc n1\"\n      and ?n2.0=\"Suc n2\"\n      and v=\"\\<beta>1 @ \\<beta>2\"\n      and b=\"b\"\n      and ?x1.0=\"Esplit_signature S1b\"\n      in equal_split_prefix)\n                  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n                  apply(force)\n                 apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n                 apply(force)\n                apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n                apply(force)\n               apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n               apply(force)\n              apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n              apply(force)\n             apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n             apply(force)\n            apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n            apply(force)\n           apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n           apply(force)\n          apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n          apply(force)\n         apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n         apply(force)\n        apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n        apply(force)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n   apply(force)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n  apply(subgoal_tac \"setA (Esplit_signature S1b) = {}\")\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n   prefer 2\n   apply (simp add: Esplit_signature_append)\n   apply(rule setA_liftB)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n  apply(subgoal_tac \"setA (Esplit_signature S2b) = {}\")\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n   prefer 2\n   apply (simp add: Esplit_signature_append)\n   apply(simp add: setAConcat setA_liftB)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n  apply (simp add: Esplit_signature_append)\n  apply(subgoal_tac \"EValidSplitExt S1\")\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"G'\"\n      and G'=\"G\"\n      and d=\"d1x\"\n      and n=\"n1\"\n      in Esplit_derivation_enforces_EValidSplitExt)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n       apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n   apply(force)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n  apply(subgoal_tac \"EValidSplitExt S2\")\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"G'\"\n      and G'=\"G\"\n      and d=\"d2x\"\n      and n=\"n2\"\n      in Esplit_derivation_enforces_EValidSplitExt)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n       apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n   apply(force)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n  apply(subgoal_tac \"EValidSplitExt (S1a@S1b)\")\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"G'\"\n      and G'=\"G\"\n      and d=\"derivation_append d1x (der2 S1 \\<lparr>prod_lhs = A1, prod_rhs = \\<beta>2\\<rparr> (S1a @ S1b)) n1\"\n      and n=\"Suc n1\"\n      in Esplit_derivation_enforces_EValidSplitExt)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n       apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n    apply(rule Esplit.derivation_append_preserves_derivation_initial)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n      apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n    apply(rule Esplit.derivation_append_preserves_derivation)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n      apply(rule Esplit.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n     apply(rule Esplit.der2_is_derivation)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n    apply(clarsimp)\n    apply(simp add: der2_def)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n   apply(simp add: derivation_append_def der2_def)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n  apply(subgoal_tac \"EValidSplitExt (S2a@S2b)\")\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"G'\"\n      and G'=\"G\"\n      and d=\"derivation_append d2x (der2 S2 \\<lparr>prod_lhs = A2, prod_rhs = []\\<rparr> (S2a @ S2b)) n2\"\n      and n=\"Suc n2\"\n      in Esplit_derivation_enforces_EValidSplitExt)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n       apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n    apply(rule Esplit.derivation_append_preserves_derivation_initial)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n      apply(simp add: Esplit_TSstructure_def F2LR1input_def)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n    apply(rule Esplit.derivation_append_preserves_derivation)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n      apply(rule Esplit.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n     apply(rule Esplit.der2_is_derivation)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n    apply(clarsimp)\n    apply(simp add: der2_def)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n   apply(simp add: derivation_append_def der2_def)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b)(*strict*)\n  apply(case_tac A1)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n   apply(subgoal_tac \"False\")\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"d1\"\n      and n=\"n1\"\n      and \\<pi>=\"map the (get_labels d1 n1)\"\n      in cfgRM_reachable_only_l3_nonterminals)\n        apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n        apply(force)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n      apply(simp add: cfgRM.trans_der_def cfgRM.derivation_initial_def)\n      apply(rule conjI)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n       apply(rule cfgRM.derivation_initial_belongs)\n        apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n        apply(simp add: split_TSstructure_def)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n       apply(simp add: cfgRM.trans_der_def cfgRM.derivation_initial_def)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n      apply(rule_tac\n      t=\"length (get_labels d1 n1)\"\n      and s=\"n1\"\n      in ssubst)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n       apply (metis get_labels_length)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n      apply(rule conjI)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n       apply(rule_tac\n      G=\"G'\"\n      in cfgRM.get_labels_the_Some_on_defined_positions)\n        apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n        apply(force)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n      apply(rule conjI)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n       apply(case_tac \"d1 0\")\n        apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n        apply(clarsimp)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba a)(*strict*)\n       apply(clarsimp)\n       apply(case_tac a)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba a option baa)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba baa)(*strict*)\n       apply(simp add: cfg_initial_configurations_def)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n     apply(clarsimp)\n     apply(rule_tac\n      t=\"length (get_labels d1 n1)\"\n      and s=\"n1\"\n      in ssubst)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n      apply (metis get_labels_length)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n   apply(rule_tac\n      xs=\"teB b # Esplit_signature S1b\"\n      in rev_cases)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba ys y)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"butlast (\\<beta>1 @ teA (cons_l2   q ba) # ys @ [y]) = SSX\" for SSX)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba ys y)(*strict*)\n    prefer 2\n    apply(rule butlast_direct)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q ba ys y)(*strict*)\n   apply(clarsimp)\n   apply(simp add: filterA_distrib_append filterA_liftB)\n   apply (metis only_l3_nonterminals_drop only_l3_nonterminals_l2_at_front)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2)(*strict*)\n   prefer 2\n   apply(rule_tac\n      Sa=\"S1a\"\n      and Sb=\"S1b\"\n      in get_revert_prod_sound)\n               apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2)(*strict*)\n               apply(force)\n              apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2)(*strict*)\n              apply(force)\n             apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2)(*strict*)\n             prefer 2\n             apply(force)\n            apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2)(*strict*)\n            prefer 3\n            apply(force)\n           apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2)(*strict*)\n           prefer 3\n           apply(force)\n          apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2)(*strict*)\n          prefer 3\n          apply(force)\n         apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2)(*strict*)\n         apply(force)\n        apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2)(*strict*)\n        apply(force)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2)(*strict*)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2)(*strict*)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2)(*strict*)\n   apply(force)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2)(*strict*)\n  apply(subgoal_tac \"get_revert_prod (restrict G G' (S2a @ S2b) (length S2a)) = Some \\<lparr>prod_lhs = cons_l3 q1 ba q2, prod_rhs = \\<beta>2\\<rparr>\")\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2)(*strict*)\n  apply(simp add: get_revert_prod_def)\n  apply(case_tac \"get_DT_revert_position (restrict G G' (S2a @ S2b) (Suc (length \\<beta>1 + length \\<beta>2)))\")\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2)(*strict*)\n   apply(force)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 a)(*strict*)\n  apply(clarsimp)\n  apply(simp add: get_DT_revert_position_def)\n  apply(case_tac \"\\<exists>rp. is_DT_revert_position (restrict G G' (S2a @ S2b) (Suc (length \\<beta>1 + length \\<beta>2))) rp\")\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 a)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 rp)(*strict*)\n  apply(thin_tac \"get_prod_at_DT_revert_position (restrict G G' (S2a @ S2b) (Suc (length \\<beta>1 + length \\<beta>2))) (THE rp. is_DT_revert_position (restrict G G' (S2a @ S2b) (Suc (length \\<beta>1 + length \\<beta>2))) rp \\<and> (\\<forall>rp'. is_DT_revert_position (restrict G G' (S2a @ S2b) (Suc (length \\<beta>1 + length \\<beta>2))) rp' \\<longrightarrow> leq rp rp')) = \\<lparr>prod_lhs = cons_l3 q1 ba q2, prod_rhs = \\<beta>2\\<rparr>\")\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 rp)(*strict*)\n  apply(subgoal_tac \"restrict G G' S2 (length (\\<beta>1 @ \\<beta>2 @ [teB b])) = restrict G G' (S2a @ S2b) (Suc (length \\<beta>1 + length \\<beta>2))\")\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 rp)(*strict*)\n   apply(rule_tac\n      w=\"\\<beta>1@\\<beta>2@[teB b]\"\n      and S=\"S2\"\n      in no_pre_DT_revert_position)\n         apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 rp)(*strict*)\n         apply(force)\n        apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 rp)(*strict*)\n        apply(force)\n       apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 rp)(*strict*)\n       apply(force)\n      apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 rp)(*strict*)\n      apply(force)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 rp)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 rp)(*strict*)\n    apply(rule_tac\n      t=\"restrict G G' S2 (length (\\<beta>1 @ \\<beta>2 @ [teB b]))\"\n      and s=\"restrict G G' (S2a @ S2b) (Suc (length \\<beta>1 + length \\<beta>2))\"\n      in ssubst)\n     apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 rp)(*strict*)\n     apply(force)\n    apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 rp)(*strict*)\n    apply(force)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 rp)(*strict*)\n   apply(force)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 rp)(*strict*)\n  apply(thin_tac \"cfgRM.derivation_initial G' d1\")\n  apply(thin_tac \"d1 n1 = Some (pair e1 \\<lparr>cfg_conf = \\<beta>1 @ teA (cons_l3   q1 ba q2) # teB b # liftB \\<alpha>3\\<rparr>)\")\n  apply(thin_tac \"d1 (Suc n1) = Some (pair (Some \\<lparr>prod_lhs = cons_l3 q1 ba q2, prod_rhs = \\<beta>2\\<rparr>) \\<lparr>cfg_conf = \\<beta>1 @ \\<beta>2 @ teB b # liftB \\<alpha>3\\<rparr>)\")\n  apply(thin_tac \"cfgRM.derivation_initial G' d2\")\n  apply(thin_tac \"d2 n2 = Some (pair e2 \\<lparr>cfg_conf = \\<beta>1 @ \\<beta>2 @ teB b # liftB \\<alpha>1 @ teA A2 # liftB \\<alpha>2\\<rparr>)\")\n  apply(thin_tac \"d2 (Suc n2) = Some (pair (Some \\<lparr>prod_lhs = A2, prod_rhs = []\\<rparr>) \\<lparr>cfg_conf = \\<beta>1 @ \\<beta>2 @ teB b # liftB \\<alpha>1 @ liftB \\<alpha>2\\<rparr>)\")\n  apply(thin_tac \"\\<lparr>prod_lhs = cons_l3 q1 ba q2, prod_rhs = \\<beta>2\\<rparr> \\<in> cfg_productions G'\")\n  apply(thin_tac \"\\<lparr>prod_lhs = A2, prod_rhs = []\\<rparr> \\<in> cfg_productions G'\")\n  apply(thin_tac \"Esplit.derivation_initial G' d1x\")\n  apply(thin_tac \"d1x n1 = Some (pair e1 S1)\")\n  apply(thin_tac \"Esplit_signature S1 = \\<beta>1 @ teA (cons_l3   q1 ba q2) # teB b # liftB \\<alpha>3\")\n  apply(thin_tac \"get_labels d1x n1 = get_labels d1 n1\")\n  apply(thin_tac \"Esplit.derivation_initial G' d2x\")\n  apply(thin_tac \"d2x n2 = Some (pair e2 S2)\")\n  apply(thin_tac \"get_labels d2x n2 = get_labels d2 n2\")\n  apply(thin_tac \"EValidSplit G' S1\")\n  apply(thin_tac \"EValidSplit G' (S1a @ S1b)\")\n  apply(thin_tac \"Esplit_step_relation G' S1 \\<lparr>prod_lhs = cons_l3 q1 ba q2, prod_rhs = \\<beta>2\\<rparr> (S1a @ S1b)\")\n  apply(thin_tac \"Esplit_signature S1a = \\<beta>1 @ \\<beta>2 @ [teB b]\")\n  apply(thin_tac \"length S1a = Suc (length \\<beta>1 + length \\<beta>2)\")\n  apply(thin_tac \"Esplit_signature S1b = liftB \\<alpha>3\")\n  apply(thin_tac \"restrict G G' (S1a @ S1b) (Suc (length \\<beta>1 + length \\<beta>2)) = restrict G G' (S2a @ S2b) (Suc (length \\<beta>1 + length \\<beta>2))\")\n  apply(thin_tac \"setA (liftB \\<alpha>3) = {}\")\n  apply(thin_tac \"setA (liftB \\<alpha>1 @ liftB \\<alpha>2) = {}\")\n  apply(thin_tac \"EValidSplitExt S1\")\n  apply(thin_tac \"EValidSplitExt (S1a @ S1b)\")\n  apply(thin_tac \"is_DT_revert_position (restrict G G' (S2a @ S2b) (Suc (length \\<beta>1 + length \\<beta>2))) rp\")\n  apply(rule_tac\n      t=\"length (\\<beta>1 @ \\<beta>2 @ [teB b])\"\n      and s=\"Suc(length (\\<beta>1 @ \\<beta>2))\"\n      in ssubst)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 rp)(*strict*)\n   apply(force)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 rp)(*strict*)\n  apply(rule_tac\n      t=\"Suc (length \\<beta>1 + length \\<beta>2)\"\n      and s=\"Suc(length (\\<beta>1 @ \\<beta>2))\"\n      in ssubst)\n   apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 rp)(*strict*)\n   apply(force)\n  apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 rp)(*strict*)\n  apply(rule_tac restrict_equal_before_step_nonterminal)\n            apply(rename_tac d1x S1 d2x S2 S1a S1b S2a S2b q1 ba q2 rp)(*strict*)\n            apply(force)+\n  done\n\ntheorem F_SDPDA_TO_CFG_STD__enforces_cfg_LRk: \"\n  valid_simple_dpda G\n  \\<Longrightarrow> valid_cfg G'\n  \\<Longrightarrow> cfg_sub G' (F_SDPDA_TO_CFG_STD G)\n  \\<Longrightarrow> cfg_nonterminals G' = cfgLM_accessible_nonterminals G' \\<inter> cfgSTD_Nonblockingness_nonterminals G'\n  \\<Longrightarrow> \\<not> duplicate_marking G\n  \\<Longrightarrow> cfg_LRk G' (Suc 0)\"\n  apply(subgoal_tac \"valid_cfg (F_SDPDA_TO_CFG_STD G)\")\n   prefer 2\n   apply (metis F_SDPDA_TO_CFG_STD__makes_CFG)\n  apply(subgoal_tac \"F2LR1inputx G' G\")\n   prefer 2\n   apply(simp add: F2LR1inputx_def)\n   apply(rule duplicate_marking_to_duplicate_markingH)\n    apply(simp add: valid_simple_dpda_def valid_dpda_def valid_pda_def)\n   apply(force)\n  apply(subgoal_tac \"split_TSstructure G'\")\n   prefer 2\n   apply(rule F2LR1input_implies_split_TSstructure)\n   apply(simp add: F2LR1input_def)\n   apply(force)\n  apply(simp add: cfg_LRk_def)\n  apply(clarsimp)\n  apply(rename_tac d1 n1 \\<delta>1 A1 y1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 v)(*strict*)\n  apply(case_tac \"y1\")\n   apply(rename_tac d1 n1 \\<delta>1 A1 y1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 v)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 v)(*strict*)\n   apply(simp add: kPrefix_def)\n   apply(clarsimp)\n   apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2)(*strict*)\n   apply(rule_tac\n      ?d1.0=\"d1\"\n      and ?d2.0=\"d2\"\n      in F_SDPDA_TO_CFG_STD__enforces_cfg_LRk_1)\n               apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2)(*strict*)\n               apply(force)+\n  apply(rename_tac d1 n1 \\<delta>1 A1 y1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 v a list)(*strict*)\n  apply(rename_tac a w1)\n  apply(rename_tac d1 n1 \\<delta>1 A1 y1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 v a w1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 v a w1)(*strict*)\n  apply(case_tac v)\n   apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 v a w1)(*strict*)\n   apply(case_tac y2)\n    apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 v a w1)(*strict*)\n    apply(simp add: kPrefix_def)\n   apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 v a w1 aa list)(*strict*)\n   apply(rename_tac b w2)\n   apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 v a w1 b w2)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2 a w1 b w2)(*strict*)\n   apply(simp add: kPrefix_def)\n   apply(clarsimp)\n   apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2 w1 b w2)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2 w1 b w2)(*strict*)\n    prefer 2\n    apply(rule_tac\n      G=\"G'\"\n      and d=\"d1\"\n      and n=\"n1\"\n      and m=\"Suc n1\"\n      in cfgRM.step_detail_before_some_position)\n      apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2 w1 b w2)(*strict*)\n      apply(rule cfgRM.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2 w1 b w2)(*strict*)\n     apply(force)\n    apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2 w1 b w2)(*strict*)\n    apply(force)\n   apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2 w1 b w2)(*strict*)\n   apply(clarsimp)\n   apply(simp add: cfgRM_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2 w1 b w2 l r)(*strict*)\n   apply(subgoal_tac \"r=teB b # liftB w1\")\n    apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2 w1 b w2 l r)(*strict*)\n    prefer 2\n    apply (metis Cons_eq_appendI setA_liftB liftB.simps(2) append_Nil terminalTailEquals1)\n   apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2 w1 b w2 l r)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d1 n1 e1 e1' d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2 w1 b w2 l)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d1 n1 e1 e1' d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2 w1 b w2 l)(*strict*)\n    prefer 2\n    apply(rule_tac\n      G=\"G'\"\n      and d=\"d2\"\n      and n=\"n2\"\n      and m=\"Suc n2\"\n      in cfgRM.step_detail_before_some_position)\n      apply(rename_tac d1 n1 e1 e1' d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2 w1 b w2 l)(*strict*)\n      apply(rule cfgRM.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac d1 n1 e1 e1' d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2 w1 b w2 l)(*strict*)\n     apply(force)\n    apply(rename_tac d1 n1 e1 e1' d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2 w1 b w2 l)(*strict*)\n    apply(force)\n   apply(rename_tac d1 n1 e1 e1' d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2 w1 b w2 l)(*strict*)\n   apply(clarsimp)\n   apply(simp add: cfgRM_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac d1 n1 e1 e1' d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2 w1 b w2 l la r)(*strict*)\n   apply(subgoal_tac \"r=teB b # liftB w2\")\n    apply(rename_tac d1 n1 e1 e1' d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2 w1 b w2 l la r)(*strict*)\n    prefer 2\n    apply (metis Cons_eq_appendI setA_liftB liftB.simps(2) append_Nil terminalTailEquals1)\n   apply(rename_tac d1 n1 e1 e1' d2 n2 \\<delta>2 A2 e2 e2' \\<omega>2 w1 b w2 l la r)(*strict*)\n   apply(clarsimp)\n   apply(thin_tac \"setA (liftB w1) = {}\")\n   apply(thin_tac \"setA (liftB w2) = {}\")\n   apply(rename_tac \\<delta>1 \\<delta>2)\n   apply(rename_tac d1 n1 e1 e1' d2 n2 e2 e2' w1 b w2 l la)(*strict*)\n   apply(subgoal_tac \"X\" for X)\n    apply(rename_tac d1 n1 e1 e1' d2 n2 e2 e2' w1 b w2 l la)(*strict*)\n    prefer 2\n    apply(rule_tac\n      G=\"G'\"\n      and G'=\"G\"\n      and ?d1.0=\"d1\"\n      and ?d2.0=\"d2\"\n      in LR1_property_part2)\n            apply(rename_tac d1 n1 e1 e1' d2 n2 e2 e2' w1 b w2 l la)(*strict*)\n            apply(force)\n           apply(rename_tac d1 n1 e1 e1' d2 n2 e2 e2' w1 b w2 l la)(*strict*)\n           apply(force)\n          apply(rename_tac d1 n1 e1 e1' d2 n2 e2 e2' w1 b w2 l la)(*strict*)\n          apply(force)\n         apply(rename_tac d1 n1 e1 e1' d2 n2 e2 e2' w1 b w2 l la)(*strict*)\n         apply(force)\n        apply(rename_tac d1 n1 e1 e1' d2 n2 e2 e2' w1 b w2 l la)(*strict*)\n        apply(force)\n       apply(rename_tac d1 n1 e1 e1' d2 n2 e2 e2' w1 b w2 l la)(*strict*)\n       apply(force)\n      apply(rename_tac d1 n1 e1 e1' d2 n2 e2 e2' w1 b w2 l la)(*strict*)\n      apply(force)\n     apply(rename_tac d1 n1 e1 e1' d2 n2 e2 e2' w1 b w2 l la)(*strict*)\n     apply(force)\n    apply(rename_tac d1 n1 e1 e1' d2 n2 e2 e2' w1 b w2 l la)(*strict*)\n    apply(force)\n   apply(rename_tac d1 n1 e1 e1' d2 n2 e2 e2' w1 b w2 l la)(*strict*)\n   apply(force)\n  apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 v a w1 aa list)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 a w1 aa list)(*strict*)\n  apply(simp add: kPrefix_def)\n  apply(clarsimp)\n  apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 w1 aa list)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 w1 aa list)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"G'\"\n      and d=\"d1\"\n      and n=\"n1\"\n      and m=\"Suc n1\"\n      in cfgRM.step_detail_before_some_position)\n     apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 w1 aa list)(*strict*)\n     apply(rule cfgRM.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 w1 aa list)(*strict*)\n    apply(force)\n   apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 w1 aa list)(*strict*)\n   apply(force)\n  apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 w1 aa list)(*strict*)\n  apply(clarsimp)\n  apply(simp add: cfgRM_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 w1 aa list l r)(*strict*)\n  apply(subgoal_tac \"r=teB aa # liftB w1\")\n   apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 w1 aa list l r)(*strict*)\n   prefer 2\n   apply (metis Cons_eq_appendI setA_liftB liftB.simps(2) append_Nil terminalTailEquals1)\n  apply(rename_tac d1 n1 \\<delta>1 A1 e1 e1' \\<omega>1 d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 w1 aa list l r)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 n1 e1 e1' d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 w1 aa list l)(*strict*)\n  apply(subgoal_tac \"X\" for X)\n   apply(rename_tac d1 n1 e1 e1' d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 w1 aa list l)(*strict*)\n   prefer 2\n   apply(rule_tac\n      G=\"G'\"\n      and d=\"d2\"\n      and n=\"n2\"\n      and m=\"Suc n2\"\n      in cfgRM.step_detail_before_some_position)\n     apply(rename_tac d1 n1 e1 e1' d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 w1 aa list l)(*strict*)\n     apply(rule cfgRM.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac d1 n1 e1 e1' d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 w1 aa list l)(*strict*)\n    apply(force)\n   apply(rename_tac d1 n1 e1 e1' d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 w1 aa list l)(*strict*)\n   apply(force)\n  apply(rename_tac d1 n1 e1 e1' d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 w1 aa list l)(*strict*)\n  apply(clarsimp)\n  apply(simp add: cfgRM_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac d1 n1 e1 e1' d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 w1 aa list l la r)(*strict*)\n  apply(subgoal_tac \"r=liftB y2\")\n   apply(rename_tac d1 n1 e1 e1' d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 w1 aa list l la r)(*strict*)\n   prefer 2\n   apply (metis Cons_eq_appendI setA_liftB liftB.simps(2) append_Nil terminalTailEquals1)\n  apply(rename_tac d1 n1 e1 e1' d2 n2 \\<delta>2 A2 y2 e2 e2' \\<omega>2 w1 aa list l la r)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 n1 e1 e1' d2 n2 y2 e2 e2' w1 aa list l la)(*strict*)\n  apply(thin_tac \"setA (liftB y2) = {}\")\n  apply(thin_tac \"setA (liftB w1) = {}\")\n  apply(case_tac e1')\n  apply(rename_tac d1 n1 e1 e1' d2 n2 y2 e2 e2' w1 aa list l la prod_lhsa prod_rhsa)(*strict*)\n  apply(case_tac e2')\n  apply(rename_tac d1 n1 e1 e1' d2 n2 y2 e2 e2' w1 aa list l la prod_lhsa prod_rhsa prod_lhsaa prod_rhsaa)(*strict*)\n  apply(rename_tac b \\<alpha> l1 cons_l2 A1 r1 A2 r2)\n  apply(rename_tac d1 n1 e1 e1' d2 n2 y2 e2 e2' w1 b \\<alpha> l1 cons_l2 A1 r1 A2 r2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 cons_l2 A1 r1 A2 r2)(*strict*)\n  apply(subgoal_tac \"False\")\n   apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 cons_l2 A1 r1 A2 r2)(*strict*)\n   apply(force)\n  apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 cons_l2 A1 r1 A2 r2)(*strict*)\n  apply(rule_tac\n      xs=\"r2\"\n      in rev_cases)\n   apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 cons_l2 A1 r1 A2 r2)(*strict*)\n   prefer 2\n   apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 cons_l2 A1 r1 A2 r2 ys y)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 cons_l2 A1 r1 A2 ys y)(*strict*)\n   apply(subgoal_tac \"LR1ProdForm G'\")\n    apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 cons_l2 A1 r1 A2 ys y)(*strict*)\n    prefer 2\n    apply(simp add: split_TSstructure_def F2LR1inputx_def)\n    apply(rule sub_of_F_SDPDA_TO_CFG_STD__implies_LR1ProdForm)\n    apply(force)\n   apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 cons_l2 A1 r1 A2 ys y)(*strict*)\n   apply(simp add: LR1ProdForm_def)\n   apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 l2a A1 r1 A2 ys y)(*strict*)\n   apply(erule_tac\n      x=\"\\<lparr>prod_lhs = A2, prod_rhs = ys @ [y]\\<rparr>\"\n      in ballE)\n    apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 l2a A1 r1 A2 ys y)(*strict*)\n    prefer 2\n    apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 cons_l2 A1 r1 A2 ys y)(*strict*)\n    apply(force)\n   apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 l2a A1 r1 A2 ys y)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 l2a A1 r1 A2 ys y ba q1 q2 q3 q4 A1a)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 l2a A1 r1 A2 ys y ba q1 q2 q3 q4 A1a)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 l2a A1 r1 ba q1 q2 A1a)(*strict*)\n    apply(rule_tac\n      xs=\"\\<alpha>\"\n      in rev_cases)\n     apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 l2a A1 r1 ba q1 q2 A1a)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 l2a A1 r1 ba q1 q2 A1a ys y)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b l1 l2a A1 r1 ba q1 q2 A1a ys y)(*strict*)\n    apply(simp add: liftB_commutes_over_concat)\n   apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 l2a A1 r1 A2 ys y ba q1 q2 q3 q4 A1a)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 cons_l2 A1 r1 A2 ys y ba q1 q2 q3 q4 A1a)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 cons_l2 A1 r1 ba q1 q2 q3 A1a)(*strict*)\n    apply(rule_tac\n      xs=\"\\<alpha>\"\n      in rev_cases)\n     apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 cons_l2 A1 r1 ba q1 q2 q3 A1a)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 cons_l2 A1 r1 ba q1 q2 q3 A1a ys y)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b l1 cons_l2 A1 r1 ba q1 q2 q3 A1a ys y)(*strict*)\n    apply(simp add: liftB_commutes_over_concat)\n   apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 l2a A1 r1 A2 ys y ba q1 q2 q3 q4 A1a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 l2a A1 r1 A2 ys y q1 q2 q3 q4 A1a A2a)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 l2a A1 r1 A2 ys y q1 q2 q3 q4 A1a A2a)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 l2a A1 r1 q1 q2 A1a A2a)(*strict*)\n    apply(rule_tac\n      xs=\"\\<alpha>\"\n      in rev_cases)\n     apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 l2a A1 r1 q1 q2 A1a A2a)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 l2a A1 r1 q1 q2 A1a A2a ys y)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b l1 l2a A1 r1 q1 q2 A1a A2a ys y)(*strict*)\n    apply(simp add: liftB_commutes_over_concat)\n   apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 l2a A1 r1 A2 ys y q1 q2 q3 q4 A1a A2a)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 l2a A1 r1 A2 ys y q1 q2 q3 q4 A1a A2a)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 l2a A1 r1 q1 q2 q3 A1a A2a)(*strict*)\n    apply(rule_tac\n      xs=\"\\<alpha>\"\n      in rev_cases)\n     apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 l2a A1 r1 q1 q2 q3 A1a A2a)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 l2a A1 r1 q1 q2 q3 A1a A2a ys y)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b l1 l2a A1 r1 q1 q2 q3 A1a A2a ys y)(*strict*)\n    apply(simp add: liftB_commutes_over_concat)\n   apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 cons_l2 A1 r1 A2 ys y q1 q2 q3 q4 A1a A2a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 cons_l2 A1 r1 q1 q2 q3 q4 A1a A2a)(*strict*)\n   apply(rule_tac\n      xs=\"\\<alpha>\"\n      in rev_cases)\n    apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 cons_l2 A1 r1 q1 q2 q3 q4 A1a A2a)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 cons_l2 A1 r1 q1 q2 q3 q4 A1a A2a ys y)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b l1 cons_l2 A1 r1 q1 q2 q3 q4 A1a A2a ys y)(*strict*)\n   apply(simp add: liftB_commutes_over_concat)\n  apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 cons_l2 A1 r1 A2 r2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d1 n1 e1 d2 n2 y2 e2 w1 b \\<alpha> l1 A1 r1 A2)(*strict*)\n  apply(rename_tac \\<alpha>2 e2 \\<alpha>3 b \\<alpha>1 \\<beta>1 A1 \\<beta>2 A2)\n  apply(rename_tac d1 n1 e1 d2 n2 \\<alpha>2 e2 \\<alpha>3 b \\<alpha>1 \\<beta>1 A1 \\<beta>2 A2)(*strict*)\n  apply(rule_tac\n      ?d1.0=\"d1\"\n      and ?d2.0=\"d2\"\n      in F_SDPDA_TO_CFG_STD__enforces_cfg_LRk_3)\n           apply(rename_tac d1 n1 e1 d2 n2 \\<alpha>2 e2 \\<alpha>3 b \\<alpha>1 \\<beta>1 A1 \\<beta>2 A2)(*strict*)\n           apply(force)\n          apply(rename_tac d1 n1 e1 d2 n2 \\<alpha>2 e2 \\<alpha>3 b \\<alpha>1 \\<beta>1 A1 \\<beta>2 A2)(*strict*)\n          apply(force)\n         apply(rename_tac d1 n1 e1 d2 n2 \\<alpha>2 e2 \\<alpha>3 b \\<alpha>1 \\<beta>1 A1 \\<beta>2 A2)(*strict*)\n         apply(force)\n        apply(rename_tac d1 n1 e1 d2 n2 \\<alpha>2 e2 \\<alpha>3 b \\<alpha>1 \\<beta>1 A1 \\<beta>2 A2)(*strict*)\n        apply(force)\n       apply(rename_tac d1 n1 e1 d2 n2 \\<alpha>2 e2 \\<alpha>3 b \\<alpha>1 \\<beta>1 A1 \\<beta>2 A2)(*strict*)\n       apply(force)\n      apply(rename_tac d1 n1 e1 d2 n2 \\<alpha>2 e2 \\<alpha>3 b \\<alpha>1 \\<beta>1 A1 \\<beta>2 A2)(*strict*)\n      apply(force)\n     apply(rename_tac d1 n1 e1 d2 n2 \\<alpha>2 e2 \\<alpha>3 b \\<alpha>1 \\<beta>1 A1 \\<beta>2 A2)(*strict*)\n     apply(force)\n    apply(rename_tac d1 n1 e1 d2 n2 \\<alpha>2 e2 \\<alpha>3 b \\<alpha>1 \\<beta>1 A1 \\<beta>2 A2)(*strict*)\n    apply(force)\n   apply(rename_tac d1 n1 e1 d2 n2 \\<alpha>2 e2 \\<alpha>3 b \\<alpha>1 \\<beta>1 A1 \\<beta>2 A2)(*strict*)\n   apply(force)\n  apply(rename_tac d1 n1 e1 d2 n2 \\<alpha>2 e2 \\<alpha>3 b \\<alpha>1 \\<beta>1 A1 \\<beta>2 A2)(*strict*)\n  apply(force)\n  done\n\nhide_fact first_empty_rhs_with_left_degen_front\nhide_fact F_SDPDA_TO_CFG_STD__enforces_cfg_LRk_3\nhide_fact get_DT_revert_position_eq\nhide_fact get_DT_revert_position_eq2\nhide_fact get_revert_prod_sound\nhide_fact get_revert_prod_sound_rhs_empty\nhide_fact get_revert_prod_sound_rhs_push\nhide_fact get_revert_prod_sound_rhs_read\nhide_fact leq_elim_elim\nhide_fact leq_elim_gen\nhide_fact leq_gen_elim\nhide_fact leq_gen_gen\nhide_fact leq_leq_eq\nhide_fact LR1_property_part2\nhide_fact LR1_property_part2_equal_productions\nhide_fact LR1_property_part2_equal_productions2\nhide_fact no_pre_DT_revert_position\nhide_fact THE_get_DT_revert_position_eq\n  (* important F_SDPDA_TO_CFG_STD__enforces_cfg_LRk *)\n\nend\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_12_04_06_06_12/LR1_Property_Satisfaction__compute_latest_production.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6261241772283034, "lm_q2_score": 0.4148988457967688, "lm_q1q2_score": 0.2597781984574746}}
{"text": "(*\n * Copyright 2015, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\n(*  WP-specific Eisbach methods *)\n\ntheory Eisbach_WP\nimports\n  \"../../Eisbach_Methods\"\n  \"../NonDetMonadVCG\"\n  \"../../Conjuncts\"\n  \"../../Rule_By_Method\"\n  \"WPI\"\nbegin\n\n\ntext \\<open>\n  Methods for manipulating the post conditions of hoare triples as if they\n  were proper subgoals.\n\n  post_asm can be used with the @ attribute to modify existing proofs. Useful\n  for proving large postconditions in one proof and then subsequently decomposing it.\n\n\\<close>\ncontext begin\n\ndefinition \"packed_valid P f si r s \\<equiv> P si \\<and> (r, s) \\<in> fst (f si)\"\n\nlemma packed_validE:\"(\\<And>si r s. packed_valid P f si r s \\<Longrightarrow> Q r s) \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>\"\n  by (clarsimp simp: valid_def packed_valid_def)\n\nlemma packed_validI: \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace> \\<Longrightarrow> \\<forall>si r s. packed_valid P f si r s \\<longrightarrow> Q r s\"\n  apply (clarsimp simp: valid_def packed_valid_def)\n  by auto\n\ndefinition \"packed_validR P f si r s \\<equiv> P si \\<and> (Inr r, s) \\<in> fst (f si)\"\n\n\nlemma packed_validRE:\"(\\<And>si r s. packed_validR P f si r s \\<Longrightarrow> Q r s) \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,-\"\n  apply (clarsimp simp: validE_R_def validE_def valid_def packed_validR_def)\n  by (metis sum.case sumE)\n\nlemma packed_validRI: \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,- \\<Longrightarrow> \\<forall>si r s. packed_validR P f si r s \\<longrightarrow> Q r s\"\n  apply (clarsimp simp: valid_def validE_R_def validE_def packed_validR_def)\n  by fastforce\n\nlemma trivial_imp: \"\\<forall>r s. Q r s \\<longrightarrow> Q r s\" by simp\n\nlemma uncurry2: \"\\<forall>r s. Q r s \\<and> Q' r s \\<longrightarrow> Q'' r s \\<Longrightarrow> \\<forall>r s. Q r s \\<longrightarrow> Q' r s \\<longrightarrow> Q'' r s\"\n  by simp\n\nnamed_theorems hoare_post_imps\n\nlemmas [hoare_post_imps] = hoare_post_imp_R hoare_post_imp[rotated]\n\nmethod post_asm_raw methods m =\n  (drule hoare_post_imps,\n   atomize (full),\n   focus_concl\n     \\<open>intro impI allI,\n      m,\n      atomize (full),\n      ((rule uncurry2)+)?\\<close>,\n   rule trivial_imp)\n\nmethod post_asm methods m =\n  (post_asm_raw \\<open>(simp only: bipred_conj_def pred_conj_def)?,(elim conjE)?,m\\<close>)\n\n\nnamed_theorems packed_validEs\n\nlemmas [packed_validEs] = packed_validE packed_validRE\n\nnamed_theorems packed_validIs\n\nlemmas [packed_validIs] = packed_validI packed_validRI\n\nmethod post_raw methods m =\n  (focus_concl\n    \\<open>rule packed_validEs,\n     focus_concl \\<open>m,fold_subgoals\\<close>,\n     atomize (full),\n     rule packed_validI\\<close>)\n\nmethod post_strong methods m_distinct m_all =\n  (post_raw\n     \\<open>(simp only: pred_conj_def bipred_conj_def)?,\n      (intro impI conjI allI)?,\n      distinct_subgoals_strong \\<open>m_distinct\\<close>,\n      all \\<open>m_all\\<close>,\n      fold_subgoals\\<close>)\n\nmethod post methods m = post_strong \\<open>(assumption | erule mp)+\\<close> \\<open>m\\<close>\n\nend\n\n\ntext \\<open>\n  Method (meant to be used with @ as an attribute) used for producing multiple facts out of\n  a single hoare triple with a conjunction in its post condition.\n\\<close>\n\ncontext begin\n\nprivate lemma hoare_decompose:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. Q r s \\<and> Q' r s\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace> \\<and> \\<lbrace>P\\<rbrace> f \\<lbrace>Q'\\<rbrace>\"\n  by (fastforce simp add: valid_def pred_conj_def)\n\nprivate lemma hoare_decomposeE_R:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. Q r s \\<and> Q' r s\\<rbrace>,- \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,- \\<and> \\<lbrace>P\\<rbrace> f \\<lbrace>Q'\\<rbrace>,-\"\n  by (fastforce simp add: validE_R_def validE_def valid_def pred_conj_def split: prod.splits sum.splits)\n\nprivate lemma hoare_decomposeE_E:\n  \"\\<lbrace>P\\<rbrace> f -,\\<lbrace>\\<lambda>r s. Q r s \\<and> Q' r s\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f -,\\<lbrace>Q\\<rbrace> \\<and> \\<lbrace>P\\<rbrace> f -,\\<lbrace>Q'\\<rbrace>\"\n  by (fastforce simp add: validE_E_def validE_def valid_def pred_conj_def split: prod.splits sum.splits)\n\nprivate lemma hoare_decomposeE:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. E r s \\<and> E' r s\\<rbrace>,\\<lbrace>\\<lambda>r s. R r s \\<and> R' r s\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>E\\<rbrace>,- \\<and> \\<lbrace>P\\<rbrace> f \\<lbrace>E'\\<rbrace>,- \\<and> \\<lbrace>P\\<rbrace> f -,\\<lbrace>R\\<rbrace> \\<and> \\<lbrace>P\\<rbrace> f -,\\<lbrace>R'\\<rbrace>\"\n  by (fastforce simp add: validE_R_def validE_E_def validE_def valid_def pred_conj_def split: prod.splits sum.splits)\n\nprivate lemmas hoare_decomposes' = hoare_decompose hoare_decomposeE_R hoare_decomposeE_E hoare_decomposeE\n\nprivate method add_pred_conj = (subst pred_conj_def[symmetric])\nprivate method add_bipred_conj = (subst bipred_conj_def[symmetric])\n\nprivate lemmas hoare_decomposes[THEN conjE] =\n  hoare_decomposes'\n  hoare_decomposes'[# \\<open>add_pred_conj\\<close>]\n  hoare_decomposes'[# \\<open>add_bipred_conj\\<close>]\n  hoare_decomposeE[# \\<open>add_pred_conj, add_pred_conj\\<close>]\n  hoare_decomposeE[# \\<open>add_bipred_conj, add_pred_conj\\<close>]\n  hoare_decomposeE[# \\<open>add_pred_conj, add_bipred_conj\\<close>]\n  hoare_decomposeE[# \\<open>add_bipred_conj, add_bipred_conj\\<close>]\n\nmethod hoare_decompose = (elim hoare_decomposes)\n\nend\n\n\nnotepad begin\n  fix A :: \"'a \\<Rightarrow> bool\" and B C D f\n  assume A: \"\\<And>s. A s = True\" and\n         B: \"\\<And>s :: 'a. B s = True\" and\n         C: \"\\<And>s :: 'a. C s = True\" and\n         D: \"\\<And>s :: 'a. D s = True\" and\n         f: \"f = (return () :: ('a,unit) nondet_monad)\"\n\n  have f_valid[@ \\<open>hoare_decompose\\<close>,conjuncts]: \"\\<lbrace>A\\<rbrace> f \\<lbrace>\\<lambda>_. B and C and D\\<rbrace>\"\n  apply (simp add: f)\n  apply wp\n  by (simp add: B C D)\n\n  note f_valid' = conjuncts\n\n  have f_d: \"\\<lbrace>A\\<rbrace> f \\<lbrace>\\<lambda>_. D\\<rbrace>\" by (rule f_valid')\n\n  have f_valid_interm: \"\\<lbrace>A\\<rbrace> f \\<lbrace>\\<lambda>_. B and C and (\\<lambda>s. D s \\<longrightarrow> B s)\\<rbrace>\"\n  apply (post_strong \\<open>simp\\<close> \\<open>-\\<close>)\n  apply (wp f_valid')\n  by simp\n\n  (* All rotations are attempted when strengthening *)\n\n  have f_valid_interm: \"\\<lbrace>A\\<rbrace> f \\<lbrace>\\<lambda>_. (\\<lambda>s. D s \\<longrightarrow> B s) and B and C \\<rbrace>\"\n  apply (post_strong \\<open>simp\\<close> \\<open>-\\<close>, wp f_valid')\n  by simp\n\nend\n\n\n\n\nend\n", "meta": {"author": "amblafont", "repo": "AutoCorres", "sha": "a8e96bff9fb22d633ff473401947ca84235d3b73", "save_path": "github-repos/isabelle/amblafont-AutoCorres", "path": "github-repos/isabelle/amblafont-AutoCorres/AutoCorres-a8e96bff9fb22d633ff473401947ca84235d3b73/lib/Monad_WP/wp/Eisbach_WP.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.523420348936324, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.2596656053268259}}
{"text": "(*\n * Copyright 2015, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\n(*  WP-specific Eisbach methods *)\n\ntheory Eisbach_WP\nimports\n  \"../../Eisbach_Methods\"\n  \"../NonDetMonadVCG\"\n  \"../../Conjuncts\"\n  \"../../Rule_By_Method\"\n  \"WPI\"\nbegin\n\n\ntext \\<open> \n  Methods for manipulating the post conditions of hoare triples as if they\n  were proper subgoals.\n\n  post_asm can be used with the @ attribute to modify existing proofs. Useful\n  for proving large postconditions in one proof and then subsequently decomposing it.\n\n\\<close>\ncontext begin\n\ndefinition \"packed_valid P f si r s \\<equiv> P si \\<and> (r, s) \\<in> fst (f si)\"\n\nlemma packed_validE:\"(\\<And>si r s. packed_valid P f si r s \\<Longrightarrow> Q r s) \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>\"\n  by (clarsimp simp: valid_def packed_valid_def)\n\nlemma packed_validI: \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace> \\<Longrightarrow> \\<forall>si r s. packed_valid P f si r s \\<longrightarrow> Q r s\"\n  apply (clarsimp simp: valid_def packed_valid_def)\n  by auto\n\ndefinition \"packed_validR P f si r s \\<equiv> P si \\<and> (Inr r, s) \\<in> fst (f si)\"\n\n\nlemma packed_validRE:\"(\\<And>si r s. packed_validR P f si r s \\<Longrightarrow> Q r s) \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,-\"\n  apply (clarsimp simp: validE_R_def validE_def valid_def packed_validR_def)\n  by (metis sum.case sumE)\n\nlemma packed_validRI: \"\\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,- \\<Longrightarrow> \\<forall>si r s. packed_validR P f si r s \\<longrightarrow> Q r s\"\n  apply (clarsimp simp: valid_def validE_R_def validE_def packed_validR_def)\n  by fastforce\n\nlemma trivial_imp: \"\\<forall>r s. Q r s \\<longrightarrow> Q r s\" by simp\n\nlemma uncurry2: \"\\<forall>r s. Q r s \\<and> Q' r s \\<longrightarrow> Q'' r s \\<Longrightarrow> \\<forall>r s. Q r s \\<longrightarrow> Q' r s \\<longrightarrow> Q'' r s\"\n  by simp\n\nnamed_theorems hoare_post_imps\n\nlemmas [hoare_post_imps] = hoare_post_imp_R hoare_post_imp[rotated]\n\nmethod post_asm_raw methods m = \n  (drule hoare_post_imps,\n   atomize (full),\n   focus_concl \n     \\<open>intro impI allI, \n      m, \n      atomize (full),\n      ((rule uncurry2)+)?\\<close>,\n   rule trivial_imp)\n\nmethod post_asm methods m = \n  (post_asm_raw \\<open>(simp only: bipred_conj_def pred_conj_def)?,(elim conjE)?,m\\<close>)\n\n\nnamed_theorems packed_validEs\n\nlemmas [packed_validEs] = packed_validE packed_validRE\n\nnamed_theorems packed_validIs\n\nlemmas [packed_validIs] = packed_validI packed_validRI\n\nmethod post_raw methods m = \n  (focus_concl \n    \\<open>rule packed_validEs,\n     focus_concl \\<open>m,fold_subgoals\\<close>, \n     atomize (full),\n     rule packed_validI\\<close>)\n\nmethod post_strong methods m_distinct m_all = \n  (post_raw\n     \\<open>(simp only: pred_conj_def bipred_conj_def)?,\n      (intro impI conjI allI)?,\n      distinct_subgoals_strong \\<open>m_distinct\\<close>,\n      all \\<open>m_all\\<close>,\n      fold_subgoals\\<close>)\n\nmethod post methods m = post_strong \\<open>(assumption | erule mp)+\\<close> \\<open>m\\<close>\n\nend\n\n\ntext \\<open>\n  Method (meant to be used with @ as an attribute) used for producing multiple facts out of \n  a single hoare triple with a conjunction in its post condition.\n\\<close>\n\ncontext begin\n\nprivate lemma hoare_decompose: \n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. Q r s \\<and> Q' r s\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace> \\<and> \\<lbrace>P\\<rbrace> f \\<lbrace>Q'\\<rbrace>\"\n  by (fastforce simp add: valid_def pred_conj_def)\n\nprivate lemma hoare_decomposeE_R: \n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. Q r s \\<and> Q' r s\\<rbrace>,- \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>Q\\<rbrace>,- \\<and> \\<lbrace>P\\<rbrace> f \\<lbrace>Q'\\<rbrace>,-\"\n  by (fastforce simp add: validE_R_def validE_def valid_def pred_conj_def split: prod.splits sum.splits)\n\nprivate lemma hoare_decomposeE_E: \n  \"\\<lbrace>P\\<rbrace> f -,\\<lbrace>\\<lambda>r s. Q r s \\<and> Q' r s\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f -,\\<lbrace>Q\\<rbrace> \\<and> \\<lbrace>P\\<rbrace> f -,\\<lbrace>Q'\\<rbrace>\"\n  by (fastforce simp add: validE_E_def validE_def valid_def pred_conj_def split: prod.splits sum.splits)\n\nprivate lemma hoare_decomposeE:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>r s. E r s \\<and> E' r s\\<rbrace>,\\<lbrace>\\<lambda>r s. R r s \\<and> R' r s\\<rbrace> \\<Longrightarrow> \\<lbrace>P\\<rbrace> f \\<lbrace>E\\<rbrace>,- \\<and> \\<lbrace>P\\<rbrace> f \\<lbrace>E'\\<rbrace>,- \\<and> \\<lbrace>P\\<rbrace> f -,\\<lbrace>R\\<rbrace> \\<and> \\<lbrace>P\\<rbrace> f -,\\<lbrace>R'\\<rbrace>\"\n  by (fastforce simp add: validE_R_def validE_E_def validE_def valid_def pred_conj_def split: prod.splits sum.splits)\n\nprivate lemmas hoare_decomposes' = hoare_decompose hoare_decomposeE_R hoare_decomposeE_E hoare_decomposeE\n\nprivate method add_pred_conj = (subst pred_conj_def[symmetric])\nprivate method add_bipred_conj = (subst bipred_conj_def[symmetric])\n\nprivate lemmas hoare_decomposes[THEN conjE] = \n  hoare_decomposes' \n  hoare_decomposes'[# \\<open>add_pred_conj\\<close>]\n  hoare_decomposes'[# \\<open>add_bipred_conj\\<close>]\n  hoare_decomposeE[# \\<open>add_pred_conj, add_pred_conj\\<close>]\n  hoare_decomposeE[# \\<open>add_bipred_conj, add_pred_conj\\<close>]\n  hoare_decomposeE[# \\<open>add_pred_conj, add_bipred_conj\\<close>]\n  hoare_decomposeE[# \\<open>add_bipred_conj, add_bipred_conj\\<close>]\n\nmethod hoare_decompose = (elim hoare_decomposes)\n\nend\n\n\nnotepad begin\n  fix A :: \"'a \\<Rightarrow> bool\" and B C D f\n  assume A: \"\\<And>s. A s = True\" and\n         B: \"\\<And>s :: 'a. B s = True\" and\n         C: \"\\<And>s :: 'a. C s = True\" and\n         D: \"\\<And>s :: 'a. D s = True\" and\n         f: \"f = (return () :: ('a,unit) nondet_monad)\"\n\n  have f_valid[@ \\<open>hoare_decompose\\<close>,conjuncts]: \"\\<lbrace>A\\<rbrace> f \\<lbrace>\\<lambda>_. B and C and D\\<rbrace>\"\n  apply (simp add: f)\n  apply wp\n  by (simp add: B C D)\n\n  note f_valid' = conjuncts\n\n  have f_d: \"\\<lbrace>A\\<rbrace> f \\<lbrace>\\<lambda>_. D\\<rbrace>\" by (rule f_valid')\n\n  have f_valid_interm: \"\\<lbrace>A\\<rbrace> f \\<lbrace>\\<lambda>_. B and C and (\\<lambda>s. D s \\<longrightarrow> B s)\\<rbrace>\"\n  apply (post_strong \\<open>simp\\<close> \\<open>-\\<close>)\n  apply (wp f_valid')\n  by simp\n    \n  (* All rotations are attempted when strengthening *)\n\n  have f_valid_interm: \"\\<lbrace>A\\<rbrace> f \\<lbrace>\\<lambda>_. (\\<lambda>s. D s \\<longrightarrow> B s) and B and C \\<rbrace>\"\n  apply (post_strong \\<open>simp\\<close> \\<open>-\\<close>, wp f_valid')\n  by simp\n\nend\n\n\n\n\nend", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/l4v/lib/Monad_WP/wp/Eisbach_WP.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.523420348936324, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.2596656053268259}}
{"text": "section\\<open>Inductive Study of Confidentiality against the General Attacker\\<close>\n\ntheory  ConfidentialityGA imports NS_Public_Bad_GA begin\n\ntext\\<open>New subsidiary lemmas to reason on a generic agent initial state\\<close>\n\nlemma parts_initState: \"parts(initState C) = initState C\"\nby (cases C, simp)\n\nlemma analz_initState: \"analz(initState C) = initState C\"\nby (cases C, force dest: analz_into_parts)\n\n\ntext\\<open>Generalising over all initial secrets the existing treatment, which is limited to private encryption keys\\<close>\n\ndefinition staticSecret :: \"agent \\<Rightarrow> msg set\" where\n [simp]: \"staticSecret A == {Key (priEK A), Key (priSK A), Key (shrK A)}\"\n\n\ntext\\<open>More subsidiary lemmas combining initial secrets and knowledge of generic agent\\<close>\n\nlemma staticSecret_in_initState [simp]:\n\"staticSecret A \\<subseteq> initState A\"\nby (cases A, simp)\nthm parts_insert\n\nlemma staticSecretA_notin_initStateB:\n\"m \\<in> staticSecret A \\<Longrightarrow> m \\<in> initState B = (A=B)\"\nby (cases B, auto)\n\nlemma staticSecretA_notin_parts_initStateB:\n\"m \\<in> staticSecret A \\<Longrightarrow> m \\<in> parts(initState B) = (A=B)\"\nby (cases B, auto)\n\nlemma staticSecretA_notin_analz_initStateB:\n\"m \\<in> staticSecret A \\<Longrightarrow> m \\<in> analz(initState B) = (A=B)\"\nby (cases B, force dest: analz_into_parts)\n\nlemma staticSecret_synth_eq: \n\"m \\<in> staticSecret A \\<Longrightarrow> (m \\<in> synth H) = (m \\<in> H)\"\napply force\ndone\n\ndeclare staticSecret_def [simp del]\n\nlemma nonce_notin_analz_initState:\n  \"Nonce N \\<notin> analz(initState A)\" \nby(cases A, auto dest: analz_into_parts)\n\n\nsubsection\\<open>Protocol independent study\\<close>\n\nlemma staticSecret_parts_agent:\n \"\\<lbrakk>m \\<in> parts (knows C evs); m \\<in> staticSecret A\\<rbrakk> \\<Longrightarrow>  \n   A=C \\<or> \n  (\\<exists>D E X. Says D E X \\<in> set evs \\<and> m \\<in> parts{X}) \\<or>\n  (\\<exists>Y. Notes C Y \\<in> set evs \\<and> m \\<in> parts{Y})\"\napply (erule rev_mp)\napply (induct_tac evs)\ntxt\\<open>@{subgoals [display,indent =1]}\\<close>\napply (simp add: staticSecretA_notin_parts_initStateB)\napply (induct_tac a)\n(*Says*) \napply (rule impI) \napply simp\napply (drule parts_insert [THEN equalityD1, THEN subsetD])\napply blast\n(*Gets*)\napply simp\n(*Notes*)\napply simp\napply clarify \ntxt\\<open>@{subgoals [display,indent =1]}\\<close>\napply (drule parts_insert [THEN equalityD1, THEN subsetD])\napply blast\ndone\n\nlemma staticSecret_analz_agent:\n \"\\<lbrakk>m \\<in> analz (knows C evs); m \\<in> staticSecret A\\<rbrakk> \\<Longrightarrow>  \n   A=C \\<or> \n  (\\<exists>D E X. Says D E X \\<in> set evs \\<and> m \\<in> parts{X}) \\<or>\n  (\\<exists>Y. Notes C Y \\<in> set evs \\<and> m \\<in> parts{Y})\"\nby (drule analz_into_parts [THEN staticSecret_parts_agent])\n\nlemma secret_parts_agent:\n \"m \\<in> parts (knows C evs)  \\<Longrightarrow> m \\<in> initState C \\<or>\n (\\<exists>A B X. Says A B X \\<in> set evs \\<and> m \\<in> parts{X}) \\<or>\n (\\<exists>Y. Notes C Y \\<in> set evs \\<and> m \\<in> parts{Y})\"\napply (erule rev_mp)\napply (induct_tac \"evs\")\napply (simp add: parts_initState)\napply (induct_tac \"a\")\n(*Says*)\napply (rule impI)\napply simp\napply (drule parts_insert [THEN equalityD1, THEN subsetD])\napply blast\n(*Gets*)\napply simp\n(*Notes*)\napply simp \napply clarify\napply (drule parts_insert [THEN equalityD1, THEN subsetD])\napply blast\ndone\n\nsubsection\\<open>Protocol dependent study\\<close>\n\n(*NS_no_Notes moved up in NS_Public_Bad_GA.thy so that it's visible to a sibling theory of this one's\n\nAs with DolevYao, studying a guarantee similar to\nNS_no_Says_staticSecret makes the specialisation proof strategy collapse, because it elicits the same assumptions of the theorem that should be specified.\n*)\n\nlemma NS_staticSecret_parts_agent_weak:\n \"\\<lbrakk>m \\<in> parts (knows C evs); m \\<in> staticSecret A; \n   evs \\<in> ns_public\\<rbrakk> \\<Longrightarrow>\n  A=C \\<or> (\\<exists>D E X. Says D E X \\<in> set evs \\<and> m \\<in> parts{X})\"\napply (blast dest: NS_no_Notes staticSecret_parts_agent)\ndone\n\ntext\\<open>Can't prove the homologous theorem of NS\\_Says\\_Spy\\_staticSecret, hence the specialisation proof strategy cannot be applied\\<close>\n\n(*Simple though illustrative corollary*)\n(*note use of Says_imp_knows, an enforcement of the threat model*)\nlemma NS_staticSecret_parts_agent_parts:\n\"\\<lbrakk>m \\<in> parts (knows C evs); m \\<in> staticSecret A; A\\<noteq>C; evs \\<in> ns_public\\<rbrakk> \\<Longrightarrow>\n  m \\<in> parts(knows D evs)\"\napply (blast dest: NS_staticSecret_parts_agent_weak Says_imp_knows [THEN parts.Inj] parts_trans)\n(*Alternative proof\napply (blast dest: staticSecret_parts_agent NS_no_Notes Says_imp_knows [THEN parts.Inj] parts_trans)*)\ndone\n\ntext\\<open>\nThe previous theorems show that in general any agent could send anybody's initial secret, namely the threat model does not impose anything against it. However, the actual protocol specification will, where agents either follow the protocol or build messages out of their traffic analysis - this is actually the same in DY\n\nTherefore, we are only left with the direct proof strategy.\n\\<close>\n\nlemma NS_staticSecret_parts_agent:\n \"\\<lbrakk>m \\<in> parts (knows C evs); m \\<in> staticSecret A; \n   C\\<noteq>A; evs \\<in> ns_public\\<rbrakk>\n \\<Longrightarrow> \\<exists> B X. Says A B X \\<in> set evs \\<and> m \\<in> parts {X}\"\napply (erule rev_mp, erule ns_public.induct)\n(*Nil*)\napply (simp add: staticSecretA_notin_parts_initStateB)\n(*Fake*)\napply simp\napply clarify\napply (drule parts_insert [THEN equalityD1, THEN subsetD])(*shot1*)\napply (case_tac \"Aa=A\") \napply clarify\ntxt\\<open>@{subgoals [display,indent=1,goals_limit=2]}\\<close>\napply blast\n(*Aa\\<noteq>A*)\napply simp\napply clarify (*applies induction hypothesis!*)(*shot2*)\ntxt\\<open>@{subgoals [display,indent=1,goals_limit=1]}\\<close>\napply (drule Fake_parts_sing [THEN subsetD], simp)  (*shot3*)\napply (simp add: staticSecret_synth_eq) \ntxt\\<open>@{subgoals [display,indent=1,goals_limit=1]}\\<close>\napply (blast dest: NS_staticSecret_parts_agent_parts)\n(*rest!*)\napply (force simp add: staticSecret_def)+\ndone\n\n\nlemma NS_agent_see_staticSecret:\n \"\\<lbrakk>m \\<in> staticSecret A; C\\<noteq>A; evs \\<in> ns_public\\<rbrakk>\n \\<Longrightarrow> m \\<in> parts (knows C evs) = (\\<exists> B X. Says A B X \\<in> set evs \\<and> m \\<in> parts {X})\"\napply (force dest: NS_staticSecret_parts_agent Says_imp_knows [THEN parts.Inj] intro: parts_trans)\ndone\n\n\ndeclare analz.Decrypt [rule del]\n\nlemma analz_insert_analz: \"\n\\<lbrakk> c \\<notin> parts{Z}; \\<forall>K. Key K \\<notin> parts{Z}; c \\<in> analz(insert Z H)\\<rbrakk> \\<Longrightarrow> c \\<in> analz H\"\napply (erule rev_mp, erule rev_mp)\napply (erule analz.induct)\nprefer 4\napply clarify\ntxt\\<open>@{subgoals [display,indent=1,goals_limit=1]}\\<close>\napply (blast dest: parts.Body analz.Decrypt)\napply blast+\ndone\n\nlemma Agent_not_see_NA:\n     \"\\<lbrakk> Key (priEK B) \\<notin> analz(knows C evs); \n        Key (priEK A) \\<notin> analz(knows C evs);\n        \\<forall>S R Y. Says S R Y \\<in> set evs \\<longrightarrow> \n         Y = Crypt (pubEK B) \\<lbrace>Nonce NA, Agent A\\<rbrace> \\<or>\n         Y = Crypt (pubEK A) \\<lbrace>Nonce NA, Nonce NB\\<rbrace> \\<or>\n         Nonce NA \\<notin> parts{Y} \\<and> (\\<forall>K. Key K \\<notin> parts{Y});\n        C\\<noteq>A; C\\<noteq>B;  evs \\<in> ns_public\\<rbrakk>                     \n       \\<Longrightarrow> Nonce NA \\<notin> analz (knows C evs)\"\napply (erule rev_mp, erule rev_mp, erule rev_mp, erule ns_public.induct) \napply (simp add: nonce_notin_analz_initState)\napply clarify\napply simp\n(*fixing confidentiality of both private keys*)\napply (drule subset_insertI [THEN analz_mono, THEN contra_subsetD])+\ntxt\\<open>@{subgoals [display,indent=1,goals_limit=1]}\\<close>\napply (subgoal_tac \"\n        \\<forall>S R Y.\n           (S = Aa \\<and> R = Ba \\<and> Y = X \\<longrightarrow>\n            X = Crypt (pubK B) \\<lbrace>Nonce NA, Agent A\\<rbrace> \\<or>\n            X = Crypt (pubK A) \\<lbrace>Nonce NA, Nonce NB\\<rbrace> \\<or>\n            Nonce NA \\<notin> parts {X} \\<and> (\\<forall>K. Key K \\<notin> parts {X}))\")\nprefer 2 \napply blast \napply simp\ntxt\\<open>@{subgoals [display,indent=1,goals_limit=1]}\\<close>\napply (force dest!: analz_insert_analz)\n(*Alternative proof\napply (erule disjE) apply simp \napply (erule disjE) apply simp \napply (blast dest: analz_insert_analz)\n*)\napply auto\ndone\n\n\n\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Inductive_Confidentiality/GeneralAttacker/ConfidentialityGA.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.523420348936324, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.2596656053268259}}
{"text": "theory \"BAN_concrete_Andrew_Secure_RPC_cert_auto\"\nimports\n  \"ESPLogic\"\nbegin\n\n(* section:  BAN concrete Andrew Secure RPC  *)\n\n(* text: \n  Modeled after the model in the SPORE library.\n\n  Notable differences:\n\n    1. 'succ(x)' is invertible. Hence, we just model it as a tuple ('succ',x) of\n       a global constant 'succ' and the variable x.  This means that we only\n       exploit the tagging properties of 'succ', but do not assume any\n       information hiding.\n\n    2. Instead of implicit typing, we are using explicit global constants to\n       discern messages.\n *)\n\nrole A\nwhere \"A =\n  [ Send ''1'' <| sAV ''A'', sN ''Na'' |>\n  , Recv ''2'' <| sMV ''B'',\n                  PEnc <| sC ''2'', sN ''Na'', sMV ''Kab'' |>\n                       ( sKbd (AVar ''A'') (MVar ''B'') )\n               |>\n  , Send ''3'' ( PEnc <| sC ''3'', sN ''Na'' |> ( sMV ''Kab'' ) )\n  , Recv ''4'' ( sMV ''Nb'' )\n  ]\"\n\nrole B\nwhere \"B =\n  [ Recv ''1'' <| sMV ''A'', sMV ''Na'' |>\n  , Send ''2'' <| sAV ''B'',\n                  PEnc <| sC ''2'', sMV ''Na'', sN ''Kab'' |>\n                       ( sKbd (MVar ''A'') (AVar ''B'') )\n               |>\n  , Recv ''3'' ( PEnc <| sC ''3'', sMV ''Na'' |> ( sN ''Kab'' ) )\n  , Send ''4'' ( sN ''Nb'' )\n  ]\"\n\nprotocol Andrew\nwhere \"Andrew = { A, B }\"\n\nlocale restricted_Andrew_state = Andrew_state\n\ntype_invariant Andrew_msc_typing for Andrew\nwhere \"Andrew_msc_typing = mk_typing\n  [ ((B, ''A''), (KnownT B_1))\n  , ((A, ''B''), (KnownT A_2))\n  , ((A, ''Kab''), (SumT (KnownT A_2) (NonceT B ''Kab'')))\n  , ((B, ''Na''), (KnownT B_1))\n  , ((A, ''Nb''), (KnownT A_4))\n  ]\"\n\nsublocale Andrew_state < Andrew_msc_typing_state\nproof -\n  have \"(t,r,s) : approx Andrew_msc_typing\"\n  proof(cases rule: reachable_in_approxI_ext\n        [OF Andrew_msc_typing.monoTyp, completeness_cases_rule])\n    case (A_2_B t r s tid0)\n    then interpret state: Andrew_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = A_2_B\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (A_2_Kab t r s tid0)\n    then interpret state: Andrew_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = A_2_Kab\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''2'', LN ''Na'' tid0, s(MV ''Kab'' tid0) |}\n            ( Kbd ( s(AV ''A'' tid0) ) ( s(MV ''B'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (B_1_A t r s tid0)\n    then interpret state: Andrew_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = B_1_A\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (B_1_Na t r s tid0)\n    then interpret state: Andrew_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = B_1_Na\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  qed\n  thus \"Andrew_msc_typing_state t r s\" by unfold_locales auto\nqed\n\ntext{* Prove secrecy of long-term keys. *}\ncontext Andrew_state begin\n\n  (* This rule is unsafe in general, but OK here, \n     as we are only reasoning about static compromise. \n  *)\n  lemma static_longterm_key_reveal[dest!]:\n    \"predOrd t (LKR a) e ==> RLKR a : reveals t\"\n    by (auto intro: compr_predOrdI)\n\n  lemma longterm_private_key_secrecy:\n    assumes facts:\n      \"SK m : knows t\"\n      \"RLKR m ~: reveals t\"\n    shows \"False\"\n  using facts by (sources \"SK m\")\n\n  lemma longterm_sym_ud_key_secrecy:\n    assumes facts:\n      \"K m1 m2 : knows t\"\n      \"RLKR m1 ~: reveals t\"\n      \"RLKR m2 ~: reveals t\"\n    shows \"False\"\n  using facts by (sources \"K m1 m2\")\n\n  lemma longterm_sym_bd_key_secrecy:\n    assumes facts:\n      \"Kbd m1 m2 : knows t\"\n      \"RLKR m1 ~: reveals t\"\n      \"RLKR m2 ~: reveals t\"\n      \"m1 : Agent\"\n      \"m2 : Agent\"\n    shows \"False\"\n  proof -\n    from facts \n    have \"KShr (agents {m1, m2}) : knows t\"\n      by (auto simp: Kbd_def)\n    thus ?thesis using facts\n    proof (sources \"KShr (agents {m1, m2})\")\n    qed (auto simp: agents_def Agent_def)\n  qed\n\n  lemmas ltk_secrecy =\n    longterm_sym_ud_key_secrecy\n    longterm_sym_ud_key_secrecy[OF in_knows_predOrd1]\n    longterm_sym_bd_key_secrecy\n    longterm_sym_bd_key_secrecy[OF in_knows_predOrd1]\n    longterm_private_key_secrecy\n    longterm_private_key_secrecy[OF in_knows_predOrd1]\n\nend\n\n(* subsection:  Security Properties  *)\n\nlemma (in restricted_Andrew_state) B_sec_Kab:\n  assumes facts:\n    \"roleMap r tid0 = Some B\"\n    \"RLKR(s(AV ''B'' tid0)) ~: reveals t\"\n    \"RLKR(s(MV ''A'' tid0)) ~: reveals t\"\n    \"LN ''Kab'' tid0 : knows t\"\n  shows \"False\"\nusing facts proof(sources! \" LN ''Kab'' tid0 \")\n  case B_2_Kab note_unified facts = this facts\n  thus ?thesis by (auto dest!: ltk_secrecy)\nqed (safe?, simp_all?, insert facts, (fastforce+)?)\n\nlemma (in restricted_Andrew_state) A_sec_Kab:\n  assumes facts:\n    \"roleMap r tid0 = Some A\"\n    \"RLKR(s(AV ''A'' tid0)) ~: reveals t\"\n    \"RLKR(s(MV ''B'' tid0)) ~: reveals t\"\n    \"( tid0, A_2 ) : steps t\"\n    \"s(MV ''Kab'' tid0) : knows t\"\n  shows \"False\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''2'', LN ''Na'' tid0, s(MV ''Kab'' tid0) |}\n                       ( Kbd ( s(AV ''A'' tid0) ) ( s(MV ''B'' tid0) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (auto dest!: ltk_secrecy)\n  next\n    case (B_2_enc tid1) note_unified facts = this facts\n    hence \"Kbd ( s(AV ''B'' tid1) )\n               ( s(MV ''A'' tid1) ) = Kbd ( s(AV ''A'' tid0) ) ( s(MV ''B'' tid0) )\"\n      by simp note facts = this facts\n    thus ?thesis proof(cases rule: Kbd_cases)\n      case noswap note_unified facts = this facts\n      thus ?thesis by (fastforce dest: B_sec_Kab intro: event_predOrdI)\n    next\n      case swapped note_unified facts = this facts\n      thus ?thesis by (fastforce dest: B_sec_Kab intro: event_predOrdI)\n    qed (fastforce+)?\n  qed (safe?, simp_all?, insert facts, (fastforce+)?)\nqed\n\n(* text: \nNo agreement on the agent identities is achieved because they may be swapped\ndue to the bidirectional shared key. As Lowe noted this gives rise to an attack\non entity authentication.\n *)\n\nlemma (in restricted_Andrew_state) A_noninjective_agreement:\n  assumes facts:\n    \"roleMap r tid1 = Some A\"\n    \"RLKR(s(AV ''A'' tid1)) ~: reveals t\"\n    \"RLKR(s(MV ''B'' tid1)) ~: reveals t\"\n    \"( tid1, A_2 ) : steps t\"\n  shows\n    \"(?  tid2.\n        roleMap r tid2 = Some B &\n        LN ''Na'' tid1 = s(MV ''Na'' tid2) &\n        s(MV ''Kab'' tid1) = LN ''Kab'' tid2)\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''2'', LN ''Na'' tid1, s(MV ''Kab'' tid1) |}\n                       ( Kbd ( s(AV ''A'' tid1) ) ( s(MV ''B'' tid1) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (auto dest!: ltk_secrecy)\n  next\n    case (B_2_enc tid2) note_unified facts = this facts\n    thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\n  qed (safe?, simp_all?, insert facts, (fastforce+)?)\nqed\n\nlemma (in restricted_Andrew_state) B_noninjective_agreement:\n  assumes facts:\n    \"roleMap r tid1 = Some B\"\n    \"RLKR(s(AV ''B'' tid1)) ~: reveals t\"\n    \"RLKR(s(MV ''A'' tid1)) ~: reveals t\"\n    \"( tid1, B_3 ) : steps t\"\n  shows\n    \"(?  tid2.\n        roleMap r tid2 = Some A &\n        s(MV ''Na'' tid1) = LN ''Na'' tid2 &\n        LN ''Kab'' tid1 = s(MV ''Kab'' tid2))\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''3'', s(MV ''Na'' tid1) |} ( LN ''Kab'' tid1 ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (fastforce dest: B_sec_Kab intro: event_predOrdI)\n  next\n    case (A_3_enc tid2) note_unified facts = this facts\n    thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\n  qed (safe?, simp_all?, insert facts, (fastforce+)?)\nqed\n\nend", "meta": {"author": "meiersi", "repo": "scyther-proof", "sha": "84e42366a46f66f1b090651be3bfaa3497696280", "save_path": "github-repos/isabelle/meiersi-scyther-proof", "path": "github-repos/isabelle/meiersi-scyther-proof/scyther-proof-84e42366a46f66f1b090651be3bfaa3497696280/examples/spore/isabelle-proofs/BAN_concrete_Andrew_Secure_RPC_cert_auto.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5583269943353745, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.25956709700669656}}
{"text": "theory GTT_Transitive_Closure\n  imports GTT_Compose\nbegin\n\nsubsection \\<open>GTT closure under transitivity\\<close>\n\ninductive_set \\<Delta>_trancl_set :: \"('q, 'f) ta \\<Rightarrow> ('q, 'f) ta \\<Rightarrow> ('q \\<times> 'q) set\" for A B where\n  \\<Delta>_set_cong: \"TA_rule f ps p |\\<in>| rules A \\<Longrightarrow> TA_rule f qs q |\\<in>| rules B \\<Longrightarrow> length ps = length qs \\<Longrightarrow>\n   (\\<And>i. i < length qs \\<Longrightarrow> (ps ! i, qs ! i) \\<in> \\<Delta>_trancl_set A B) \\<Longrightarrow> (p, q) \\<in> \\<Delta>_trancl_set A B\"\n| \\<Delta>_set_eps1: \"(p, p') |\\<in>| eps A \\<Longrightarrow> (p, q) \\<in> \\<Delta>_trancl_set A B \\<Longrightarrow> (p', q) \\<in> \\<Delta>_trancl_set A B\"\n| \\<Delta>_set_eps2: \"(q, q') |\\<in>| eps B \\<Longrightarrow> (p, q) \\<in> \\<Delta>_trancl_set A B \\<Longrightarrow> (p, q') \\<in> \\<Delta>_trancl_set A B\"\n| \\<Delta>_set_trans: \"(p, q) \\<in> \\<Delta>_trancl_set A B \\<Longrightarrow> (q, r) \\<in> \\<Delta>_trancl_set A B \\<Longrightarrow> (p, r) \\<in> \\<Delta>_trancl_set A B\"\n\nlemma \\<Delta>_trancl_set_states: \"\\<Delta>_trancl_set \\<A> \\<B> \\<subseteq> fset (\\<Q> \\<A> |\\<times>| \\<Q> \\<B>)\"\nproof -\n  {fix p q assume \"(p, q) \\<in> \\<Delta>_trancl_set \\<A> \\<B>\" then have \"(p, q) \\<in> fset (\\<Q> \\<A> |\\<times>| \\<Q> \\<B>)\"\n      by (induct) (auto dest: rule_statesD eps_statesD simp flip: fmember_iff_member_fset)}\n  then show ?thesis by auto\nqed\n\nlemma finite_\\<Delta>_trancl_set [simp]: \"finite (\\<Delta>_trancl_set \\<A> \\<B>)\"\n  using finite_subset[OF \\<Delta>_trancl_set_states]\n  by simp\n\ncontext\nincludes fset.lifting\nbegin\nlift_definition \\<Delta>_trancl :: \"('q, 'f) ta \\<Rightarrow> ('q, 'f) ta \\<Rightarrow> ('q \\<times> 'q) fset\" is \\<Delta>_trancl_set by simp\nlemmas \\<Delta>_trancl_cong = \\<Delta>_set_cong [Transfer.transferred]\nlemmas \\<Delta>_trancl_eps1 = \\<Delta>_set_eps1 [Transfer.transferred]\nlemmas \\<Delta>_trancl_eps2 = \\<Delta>_set_eps2 [Transfer.transferred]\nlemmas \\<Delta>_trancl_cases = \\<Delta>_trancl_set.cases[Transfer.transferred]\nlemmas \\<Delta>_trancl_induct [consumes 1, case_names \\<Delta>_cong \\<Delta>_eps1 \\<Delta>_eps2 \\<Delta>_trans] = \\<Delta>_trancl_set.induct[Transfer.transferred]\nlemmas \\<Delta>_trancl_intros = \\<Delta>_trancl_set.intros[Transfer.transferred]\nlemmas \\<Delta>_trancl_simps = \\<Delta>_trancl_set.simps[Transfer.transferred]\nend\n\n\nlemma \\<Delta>_trancl_cl [simp]:\n  \"(\\<Delta>_trancl A B)|\\<^sup>+| = \\<Delta>_trancl A B\"\nproof -\n  {fix s t assume \"(s, t) |\\<in>| (\\<Delta>_trancl A B)|\\<^sup>+|\" then have \"(s, t) |\\<in>| \\<Delta>_trancl A B\"\n      by (induct rule: ftrancl_induct) (auto intro: \\<Delta>_trancl_intros)}\n  then show ?thesis by auto\nqed\n\nlemma \\<Delta>_trancl_states: \"\\<Delta>_trancl \\<A> \\<B> |\\<subseteq>| (\\<Q> \\<A> |\\<times>| \\<Q> \\<B>)\"\n  using \\<Delta>_trancl_set_states\n  by (metis \\<Delta>_trancl.rep_eq fSigma_cong less_eq_fset.rep_eq)\n\ndefinition GTT_trancl where\n  \"GTT_trancl G =\n    (let \\<Delta> = \\<Delta>_trancl (snd G) (fst G) in\n    (TA (rules (fst G)) (eps (fst G) |\\<union>| \\<Delta>),\n                   TA (rules (snd G)) (eps (snd G) |\\<union>| (\\<Delta>|\\<inverse>|))))\"\n\nlemma \\<Delta>_trancl_inv:\n  \"(\\<Delta>_trancl A B)|\\<inverse>| = \\<Delta>_trancl B A\"\nproof -\n  have [dest]: \"(p, q) |\\<in>| \\<Delta>_trancl A B \\<Longrightarrow> (q, p) |\\<in>| \\<Delta>_trancl B A\" for p q A B\n    by (induct rule: \\<Delta>_trancl_induct) (auto intro: \\<Delta>_trancl_intros)\n  show ?thesis by auto\nqed\n\nlemma gtt_states_GTT_trancl:\n  \"gtt_states (GTT_trancl G) |\\<subseteq>| gtt_states G\"\n  unfolding GTT_trancl_def\n  by (auto simp: gtt_states_def \\<Q>_def \\<Delta>_trancl_inv dest!: fsubsetD[OF \\<Delta>_trancl_states] simp flip: fmember_iff_member_fset)\n\nlemma gtt_syms_GTT_trancl:\n  \"gtt_syms (GTT_trancl G) = gtt_syms G\"\n  by (auto simp: GTT_trancl_def ta_sig_def \\<Delta>_trancl_inv)\n\nlemma GTT_trancl_base:\n  \"gtt_lang G \\<subseteq> gtt_lang (GTT_trancl G)\"\n  using gtt_lang_mono[of G \"GTT_trancl G\"] by (auto simp: \\<Delta>_trancl_inv GTT_trancl_def)\n\nlemma GTT_trancl_trans:\n  \"gtt_lang (GTT_comp (GTT_trancl G) (GTT_trancl G)) \\<subseteq> gtt_lang (GTT_trancl G)\"\nproof -\n  have [dest]: \"(p, q) |\\<in>| \\<Delta>\\<^sub>\\<epsilon> (TA (rules A) (eps A |\\<union>| (\\<Delta>_trancl B A)))\n    (TA (rules B) (eps B |\\<union>| (\\<Delta>_trancl A B))) \\<Longrightarrow> (p, q) |\\<in>| \\<Delta>_trancl A B\" for p q A B\n    by (induct rule: \\<Delta>\\<^sub>\\<epsilon>_induct) (auto intro: \\<Delta>_trancl_intros simp: \\<Delta>_trancl_inv[of B A, symmetric])\n  show ?thesis\n    by (intro gtt_lang_mono[of \"GTT_comp (GTT_trancl G) (GTT_trancl G)\" \"GTT_trancl G\"])\n       (auto simp: GTT_comp_def GTT_trancl_def fmember.abs_eq \\<Delta>_trancl_inv)\nqed\n\nlemma agtt_lang_base:\n  \"agtt_lang G \\<subseteq> agtt_lang (GTT_trancl G)\"\n  by (rule agtt_lang_mono) (auto simp: GTT_trancl_def \\<Delta>_trancl_inv)\n\n\nlemma \\<Delta>\\<^sub>\\<epsilon>_tr_incl:\n  \"\\<Delta>\\<^sub>\\<epsilon> (TA (rules A) (eps A |\\<union>| \\<Delta>_trancl B A)) (TA (rules B)  (eps B |\\<union>| \\<Delta>_trancl A B)) = \\<Delta>_trancl A B\"\n   (is \"?LS = ?RS\")\nproof -\n  {fix p q assume \"(p, q) |\\<in>| ?LS\" then have \"(p, q) |\\<in>| ?RS\"\n      by (induct rule: \\<Delta>\\<^sub>\\<epsilon>_induct)\n         (auto simp: \\<Delta>_trancl_inv[of B A, symmetric] intro: \\<Delta>_trancl_intros)}\n  moreover\n  {fix p q assume \"(p, q) |\\<in>| ?RS\" then have \"(p, q) |\\<in>| ?LS\"\n      by (induct rule: \\<Delta>_trancl_induct)\n        (auto simp: \\<Delta>_trancl_inv[of B A, symmetric] intro: \\<Delta>\\<^sub>\\<epsilon>_intros)}\n  ultimately show ?thesis\n    by auto\nqed\n\n\nlemma agtt_lang_trans:\n  \"gcomp_rel UNIV (agtt_lang (GTT_trancl G)) (agtt_lang (GTT_trancl G)) \\<subseteq> agtt_lang (GTT_trancl G)\"\nproof -\n  have [intro!, dest]: \"(p, q) |\\<in>| \\<Delta>\\<^sub>\\<epsilon> (TA (rules A) (eps A |\\<union>| (\\<Delta>_trancl B A)))\n    (TA (rules B) (eps B |\\<union>| (\\<Delta>_trancl A B))) \\<Longrightarrow> (p, q) |\\<in>| \\<Delta>_trancl A B\" for p q A B\n    by (induct rule: \\<Delta>\\<^sub>\\<epsilon>_induct) (auto intro: \\<Delta>_trancl_intros simp: \\<Delta>_trancl_inv[of B A, symmetric])\n  show ?thesis\n    by (rule subset_trans[OF gtt_comp_acomplete agtt_lang_mono])\n       (auto simp: GTT_comp_def GTT_trancl_def \\<Delta>_trancl_inv)\nqed\n\nlemma GTT_trancl_acomplete:\n  \"gtrancl_rel UNIV (agtt_lang G) \\<subseteq> agtt_lang (GTT_trancl G)\"\n  unfolding gtrancl_rel_def\n  using agtt_lang_base[of G] gmctxt_cl_mono_rel[OF agtt_lang_base[of G], of UNIV]\n  using agtt_lang_trans[of G]\n  unfolding gcomp_rel_def\n  by (intro kleene_trancl_induct) blast+\n\nlemma Restr_rtrancl_gtt_lang_eq_trancl_gtt_lang:\n  \"(gtt_lang G)\\<^sup>* = (gtt_lang G)\\<^sup>+\"\n  by (auto simp: rtrancl_trancl_reflcl simp del: reflcl_trancl dest: tranclD tranclD2 intro: gmctxt_cl_refl)\n\nlemma GTT_trancl_complete:\n  \"(gtt_lang G)\\<^sup>+ \\<subseteq> gtt_lang (GTT_trancl G)\"\n  using GTT_trancl_base subset_trans[OF gtt_comp_lang_complete GTT_trancl_trans]\n  by (metis trancl_id trancl_mono_set trans_O_iff)\n\nlemma trancl_gtt_lang_arg_closed:\n  assumes \"length ss = length ts\" \"\\<forall>i < length ts. (ss ! i, ts ! i) \\<in> (gtt_lang \\<G>)\\<^sup>+\"\n  shows \"(GFun f ss, GFun f ts) \\<in> (gtt_lang \\<G>)\\<^sup>+\" (is \"?e \\<in> _\")\nproof -\n  have \"all_ctxt_closed UNIV ((gtt_lang \\<G>)\\<^sup>+)\" by (intro all_ctxt_closed_trancl) auto\n  from all_ctxt_closedD[OF this _ assms] show ?thesis\n    by auto\nqed\n\nlemma \\<Delta>_trancl_sound:\n  assumes \"(p, q) |\\<in>| \\<Delta>_trancl A B\"\n  obtains s t where \"(s, t) \\<in> (gtt_lang (B, A))\\<^sup>+\" \"p |\\<in>| gta_der A s\" \"q |\\<in>| gta_der B t\"\n  using assms\nproof (induct arbitrary: thesis rule: \\<Delta>_trancl_induct)\n  case (\\<Delta>_cong f ps p qs q)\n  have \"\\<exists>si ti. (si, ti) \\<in> (gtt_lang (B, A))\\<^sup>+ \\<and> ps ! i |\\<in>| gta_der A (si) \\<and>\n      qs ! i |\\<in>| gta_der B (ti)\" if \"i < length qs\" for i\n    using \\<Delta>_cong(5)[OF that] by metis\n  then obtain ss ts where\n    \"\\<And>i. i < length qs \\<Longrightarrow> (ss i, ts i) \\<in> (gtt_lang (B, A))\\<^sup>+ \\<and> ps ! i |\\<in>| gta_der A (ss i) \\<and> qs ! i |\\<in>| gta_der B (ts i)\" by metis\n  then show ?case using \\<Delta>_cong(1-5)\n    by (intro \\<Delta>_cong(6)[of \"GFun f (map ss [0..<length ps])\" \"GFun f (map ts [0..<length qs])\"])\n       (auto simp: gta_der_def intro!: trancl_gtt_lang_arg_closed)\nnext\n  case (\\<Delta>_eps1 p p' q) then show ?case\n    by (metis gta_der_def ta_der_eps)\nnext\n  case (\\<Delta>_eps2 q q' p) then show ?case\n    by (metis gta_der_def ta_der_eps)\nnext\n  case (\\<Delta>_trans p q r)\n  obtain s1 t1 where \"(s1, t1) \\<in> (gtt_lang (B, A))\\<^sup>+\" \"p |\\<in>| gta_der A s1\" \"q |\\<in>| gta_der B t1\"\n    using \\<Delta>_trans(2) .note 1 = this\n  obtain s2 t2 where \"(s2, t2) \\<in> (gtt_lang (B, A))\\<^sup>+\" \"q |\\<in>| gta_der A s2\" \"r |\\<in>| gta_der B t2\"\n    using \\<Delta>_trans(4) . note 2 = this\n  have \"(t1, s2) \\<in> gtt_lang (B, A)\" using 1(1,3) 2(1,2)\n    by (auto simp: Restr_rtrancl_gtt_lang_eq_trancl_gtt_lang[symmetric] gtt_lang_join)\n  then have \"(s1, t2) \\<in> (gtt_lang (B, A))\\<^sup>+\" using 1(1) 2(1)\n    by (meson trancl.trancl_into_trancl trancl_trans)\n  then show ?case using 1(2) 2(3) by (auto intro: \\<Delta>_trans(5)[of s1 t2])\nqed\n\nlemma GTT_trancl_sound_aux:\n  assumes \"p |\\<in>| gta_der (TA (rules A) (eps A |\\<union>| (\\<Delta>_trancl B A))) s\"\n  shows \"\\<exists>t. (s, t) \\<in> (gtt_lang (A, B))\\<^sup>+ \\<and> p |\\<in>| gta_der A t\"\n  using assms\nproof (induct s arbitrary: p)\n  case (GFun f ss)\n  let ?eps = \"eps A |\\<union>| \\<Delta>_trancl B A\"\n  obtain qs q where q: \"TA_rule f qs q |\\<in>| rules A\" \"q = p \\<or> (q, p) |\\<in>| ?eps|\\<^sup>+|\" \"length qs = length ss\"\n   \"\\<And>i. i < length ss \\<Longrightarrow> qs ! i |\\<in>| gta_der (TA (rules A) ?eps) (ss ! i)\"\n    using GFun(2) by (auto simp: gta_der_def)\n  have \"\\<And>i. i < length ss \\<Longrightarrow> \\<exists>ti. (ss ! i, ti) \\<in> (gtt_lang (A, B))\\<^sup>+ \\<and> qs ! i |\\<in>| gta_der A (ti)\"\n    using GFun(1)[OF nth_mem q(4)] unfolding gta_der_def by fastforce\n  then obtain ts where ts: \"\\<And>i. i < length ss \\<Longrightarrow> (ss ! i, ts i) \\<in> (gtt_lang (A, B))\\<^sup>+ \\<and> qs ! i |\\<in>| gta_der A (ts i)\"\n    by metis\n  then have q': \"q |\\<in>| gta_der A (GFun f (map ts [0..<length ss]))\"\n    \"(GFun f ss, GFun f (map ts [0..<length ss])) \\<in> (gtt_lang (A, B))\\<^sup>+\" using q(1, 3)\n    by (auto simp: gta_der_def intro!: exI[of _ qs] exI[of _ q] trancl_gtt_lang_arg_closed)\n  {fix p q u assume ass: \"(p, q) |\\<in>| \\<Delta>_trancl B A\" \"(GFun f ss, u) \\<in> (gtt_lang (A, B))\\<^sup>+ \\<and> p |\\<in>| gta_der A u\"\n    from \\<Delta>_trancl_sound[OF this(1)] obtain s t\n      where \"(s, t) \\<in> (gtt_lang (A, B))\\<^sup>+\" \"p |\\<in>| gta_der B s\" \"q |\\<in>| gta_der A t\" . note st = this\n    have \"(u, s) \\<in> gtt_lang (A, B)\" using st conjunct2[OF ass(2)]\n      by (auto simp: Restr_rtrancl_gtt_lang_eq_trancl_gtt_lang[symmetric] gtt_lang_join)\n    then have \"(GFun f ss, t) \\<in> (gtt_lang (A, B))\\<^sup>+\"\n      using ass st(1) by (meson trancl_into_trancl2 trancl_trans)\n    then have \"\\<exists> s t. (GFun f ss, t) \\<in> (gtt_lang (A, B))\\<^sup>+ \\<and> q |\\<in>| gta_der A t\" using st by blast}\n  note trancl_step = this\n  show ?case\n  proof (cases \"q = p\")\n    case True\n    then show ?thesis using ts q(1, 3)\n      by (auto simp: gta_der_def intro!: exI[of _\"GFun f (map ts [0..< length ss])\"] trancl_gtt_lang_arg_closed) blast\n  next\n    case False\n    then have \"(q, p) |\\<in>| ?eps|\\<^sup>+|\" using q(2) by simp\n    then show ?thesis using q(1) q'\n    proof (induct rule: ftrancl_induct)\n      case (Base q p) from Base(1) show ?case\n      proof\n        assume \"(q, p) |\\<in>| eps A\" then show ?thesis using Base(2) ts q(3)\n          by (auto simp: gta_der_def intro!: exI[of _\"GFun f (map ts [0..< length ss])\"]\n                         trancl_gtt_lang_arg_closed exI[of _ qs] exI[of _ q])\n      next\n        assume \"(q, p) |\\<in>| (\\<Delta>_trancl B A)\"\n        then have \"(q, p) |\\<in>| \\<Delta>_trancl B A\" by (simp add: fmember.abs_eq)       \n        from trancl_step[OF this] show ?thesis using Base(3, 4)\n          by auto\n      qed\n    next\n      case (Step p q r)\n      from Step(2, 4-) obtain s' where s': \"(GFun f ss, s') \\<in> (gtt_lang (A, B))\\<^sup>+ \\<and> q |\\<in>| gta_der A s'\" by auto\n      show ?case using Step(3)\n      proof\n        assume \"(q, r) |\\<in>| eps A\" then show ?thesis using s'\n          by (auto simp: gta_der_def ta_der_eps intro!: exI[of _ s'])\n      next\n        assume \"(q, r) |\\<in>| \\<Delta>_trancl B A\"\n        then have \"(q, r) |\\<in>| \\<Delta>_trancl B A\" by (simp add: fmember.abs_eq)       \n        from trancl_step[OF this] show ?thesis using s' by auto\n      qed\n    qed\n  qed\nqed\n\nlemma GTT_trancl_asound:\n  \"agtt_lang (GTT_trancl G) \\<subseteq> gtrancl_rel UNIV (agtt_lang G)\"\nproof (intro subrelI, goal_cases LR)\n  case (LR s t)\n  then obtain s' q t' where *: \"(s, s') \\<in> (gtt_lang G)\\<^sup>+\"\n    \"q |\\<in>| gta_der (fst G) s'\" \"q |\\<in>| gta_der (snd G) t'\" \"(t', t) \\<in> (gtt_lang G)\\<^sup>+\"\n    by (auto simp: agtt_lang_def GTT_trancl_def trancl_converse \\<Delta>_trancl_inv\n      simp flip: gtt_lang_swap[of \"fst G\" \"snd G\", unfolded prod.collapse agtt_lang_def, simplified]\n      dest!: GTT_trancl_sound_aux)\n  then have \"(s', t') \\<in> agtt_lang G\" using *(2,3)\n    by (auto simp: agtt_lang_def)\n  then show ?case using *(1,4) unfolding gtrancl_rel_def\n    by auto\nqed\n\nlemma GTT_trancl_sound:\n  \"gtt_lang (GTT_trancl G) \\<subseteq> (gtt_lang G)\\<^sup>+\"\nproof -\n  note [dest] = GTT_trancl_sound_aux\n  have \"gtt_accept (GTT_trancl G) s t \\<Longrightarrow> (s, t) \\<in> (gtt_lang G)\\<^sup>+\" for s t unfolding gtt_accept_def\n  proof (induct rule: gmctxt_cl.induct)\n    case (base s t)\n    from base obtain q where join: \"q |\\<in>| gta_der (fst (GTT_trancl G)) s\" \"q |\\<in>| gta_der (snd (GTT_trancl G)) t\"\n      by (auto simp: agtt_lang_def)\n    obtain s' where \"(s, s') \\<in> (gtt_lang G)\\<^sup>+\" \"q |\\<in>| gta_der (fst G) s'\" using base join\n      by (auto simp: GTT_trancl_def \\<Delta>_trancl_inv agtt_lang_def)\n    moreover obtain t' where \"(t', t) \\<in> (gtt_lang G)\\<^sup>+\" \"q |\\<in>| gta_der (snd G) t'\" using join\n      by (auto simp: GTT_trancl_def gtt_lang_swap[of \"fst G\" \"snd G\", symmetric] trancl_converse \\<Delta>_trancl_inv)\n    moreover have \"(s', t') \\<in> gtt_lang G\" using calculation\n      by (auto simp: Restr_rtrancl_gtt_lang_eq_trancl_gtt_lang[symmetric] gtt_lang_join)\n    ultimately show \"(s, t) \\<in> (gtt_lang G)\\<^sup>+\" by (meson trancl.trancl_into_trancl trancl_trans)\n  qed (auto intro!: trancl_gtt_lang_arg_closed)\n  then show ?thesis by (auto simp: gtt_accept_def)\nqed\n\nlemma GTT_trancl_alang:\n  \"agtt_lang (GTT_trancl G) = gtrancl_rel UNIV (agtt_lang G)\"\n  using GTT_trancl_asound GTT_trancl_acomplete by blast\n\nlemma GTT_trancl_lang:\n  \"gtt_lang (GTT_trancl G) = (gtt_lang G)\\<^sup>+\"\n  using GTT_trancl_sound GTT_trancl_complete by blast\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Regular_Tree_Relations/GTT_Transitive_Closure.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.2595389365769605}}
{"text": "theory RepeatScorres\n  imports\n    RepeatShallow\n    RepeatMono\n    \"build/Generated_SCorres_Normal\"\nbegin\n\nsection \"Shallow repeat loop definition\"\n\noverloading repeat' \\<equiv> repeat\nbegin\ndefinition repeat' :: \"(64 word, ('a, 'b) StepParam \\<Rightarrow> bool, ('a, 'b) StepParam \\<Rightarrow> 'a, 'a, 'b) RepParam \\<Rightarrow> 'a\"\n  where\n\"repeat x =\n  repeatatm (unat (RepParam.n\\<^sub>f x))\n            (\\<lambda>(a :: 'a) (b :: 'b). (RepParam.stop\\<^sub>f x) \\<lparr>StepParam.acc\\<^sub>f = a, obsv\\<^sub>f = b\\<rparr>)\n            (\\<lambda>(a :: 'a) (b :: 'b). (RepParam.step\\<^sub>f x) \\<lparr>StepParam.acc\\<^sub>f = a, obsv\\<^sub>f = b\\<rparr>)\n            (RepParam.acc\\<^sub>f x)\n            (RepParam.obsv\\<^sub>f x)\"\nend (* of overloading *)\n\nsection \"Repeat loop scorres\"\n\ncontext shallow begin\n\nlemma vrepeat_bod_scorres:\n  \"\\<lbrakk>rel_leq \\<xi>' \\<xi>'';\n    valRel \\<xi>'' (x ::(64 word, ('c, 'd) StepParam \\<Rightarrow> bool,  ('c, 'd) StepParam \\<Rightarrow> 'c, 'c, 'd) RepParam)\n      (VRecord [VPrim (LU64 n), f, g, acc, obsv]); is_vvalfun f; is_vvalfun g;\n    vrepeat_bod \\<xi>' (unat n) (vvalfun_to_expr f) (vvalfun_to_expr g) acc obsv v'\\<rbrakk>\n   \\<Longrightarrow> valRel \\<xi>''\n              (repeatatm (unat (n\\<^sub>f x)) (\\<lambda>a b. stop\\<^sub>f x \\<lparr>StepParam.acc\\<^sub>f = a, obsv\\<^sub>f = b\\<rparr>)\n                (\\<lambda>a b. step\\<^sub>f x \\<lparr>StepParam.acc\\<^sub>f = a, obsv\\<^sub>f = b\\<rparr>) (RepParam.acc\\<^sub>f x) (RepParam.obsv\\<^sub>f x))\n              v'\"\n  apply (induct n arbitrary: acc x)\n   apply (clarsimp simp: valRel_RepParam)\n   apply (subst repeatatm.simps)\n   apply simp\n  apply (drule unatSuc; clarsimp)\n  apply (rename_tac n acc x b)\n  apply (case_tac b; clarsimp)\n   apply (clarsimp simp: valRel_RepParam)\n   apply (subst repeatatm.simps; clarsimp)\n   apply (erule notE)\n   apply (erule disjE; clarsimp)\n    apply (elim v_sem_appE v_sem_funE v_sem_varE; clarsimp)\n    apply (erule_tac x = \"\\<lparr>StepParam.acc\\<^sub>f = RepParam.acc\\<^sub>f x, obsv\\<^sub>f = RepParam.obsv\\<^sub>f x\\<rparr>\" in allE)\n    apply (erule_tac x = \"VRecord [v', obsv]\" in allE)\n    apply (erule impE, simp add: valRel_StepParam)\n    apply (erule_tac x = \"VPrim (LBool True)\" in allE)\n    apply (drule_tac \\<xi>b = \\<xi>'' in  v_sem_v_sem_all_rel_leqD(1)[rotated 1]; simp)\n   apply (elim v_sem_appE v_sem_afunE v_sem_varE; clarsimp)\n   apply (erule_tac x = \"\\<lparr>StepParam.acc\\<^sub>f = RepParam.acc\\<^sub>f x, obsv\\<^sub>f = RepParam.obsv\\<^sub>f x\\<rparr>\" in allE)\n   apply (erule_tac x = \"VRecord [v', obsv]\" in allE)\n   apply (erule impE, simp add: valRel_StepParam)\n   apply (erule_tac x = \"VPrim (LBool True)\" in allE)\n   apply (erule impE; simp?)\n   apply (rule rel_leqD[rotated 1]; assumption)\n  apply (rename_tac acc')\n  apply (drule_tac x = acc' in meta_spec)\n  apply clarsimp\n  apply (drule_tac\n      x = \"\\<lparr>RepParam.n\\<^sub>f = n, stop\\<^sub>f = stop\\<^sub>f x, step\\<^sub>f = step\\<^sub>f x,\n            acc\\<^sub>f = step\\<^sub>f x \\<lparr>StepParam.acc\\<^sub>f = RepParam.acc\\<^sub>f x, obsv\\<^sub>f = RepParam.obsv\\<^sub>f x\\<rparr>,\n            obsv\\<^sub>f = RepParam.obsv\\<^sub>f x \\<rparr>\" in meta_spec)\n  apply (elim meta_allE meta_impE; assumption?)\n   apply (clarsimp simp: valRel_RepParam)\n   apply (thin_tac \"_ \\<or> _\")\n   apply (thin_tac \"_, _ \\<turnstile> _ \\<Down> _\")\n   apply (elim disjE v_sem_appE v_sem_varE; clarsimp; elim v_sem_funE v_sem_afunE; clarsimp)\n    apply (erule_tac x = \"\\<lparr>StepParam.acc\\<^sub>f = RepParam.acc\\<^sub>f x, obsv\\<^sub>f = RepParam.obsv\\<^sub>f x\\<rparr>\" in allE)\n    apply (erule_tac x = \"VRecord [acc, obsv]\" in allE)\n    apply (erule impE, simp add: valRel_StepParam)\n    apply (erule_tac x = acc' in allE)\n    apply (drule_tac \\<xi>b = \\<xi>'' in  v_sem_v_sem_all_rel_leqD(1)[rotated 1]; simp)\n   apply (erule_tac x = \"\\<lparr>StepParam.acc\\<^sub>f = RepParam.acc\\<^sub>f x, obsv\\<^sub>f = RepParam.obsv\\<^sub>f x\\<rparr>\" in allE)\n   apply (erule_tac x = \"VRecord [acc, obsv]\" in allE)\n   apply (erule impE, simp add: valRel_StepParam)\n   apply (erule_tac x = acc' in allE)\n   apply (erule impE; simp?)\n   apply (rule rel_leqD[rotated 1]; assumption)\n  apply clarsimp\n  apply (subst (asm) valRel_RepParam; clarsimp)\n  apply (erule v_sem_appE; erule disjE; clarsimp; elim v_sem_funE v_sem_afunE v_sem_varE; clarsimp)\n   apply (erule_tac x = \"\\<lparr>StepParam.acc\\<^sub>f = RepParam.acc\\<^sub>f x, obsv\\<^sub>f = RepParam.obsv\\<^sub>f x\\<rparr>\" in allE)\n   apply (erule_tac x = \"VRecord [acc, obsv]\" in allE)\n   apply (erule impE, simp add: valRel_StepParam)\n   apply (erule_tac x = \"VPrim (LBool False)\" in allE)\n   apply (erule impE; simp?)\n   apply (rule rel_leqD[rotated 1]; assumption)\n   apply (subst repeatatm.simps; clarsimp)\n  apply (erule_tac x = \"\\<lparr>StepParam.acc\\<^sub>f = RepParam.acc\\<^sub>f x, obsv\\<^sub>f = RepParam.obsv\\<^sub>f x\\<rparr>\" in allE)\n  apply (erule_tac x = \"VRecord [acc, obsv]\" in allE)\n  apply (erule impE, simp add: valRel_StepParam)\n  apply (erule_tac x = \"VPrim (LBool False)\" in allE)\n  apply (erule impE, rule v_sem_v_sem_all_rel_leqD(1); simp)\n  apply (subst repeatatm.simps; clarsimp)\n  done\n\nlemma repeat_scorres: \n  \"\\<lbrakk>rel_leq \\<xi>' \\<xi>''; \\<xi>'' ''repeat'' = prepeat \\<xi>'\\<rbrakk> \\<Longrightarrow> \n     scorres repeat (AFun ''repeat'' ts []) \\<gamma> \\<xi>''\"\n  unfolding scorres_def\n  apply clarsimp\n  apply (erule v_sem_afunE; clarsimp)\n  apply (erule notE)\n  unfolding repeat'_def prepeat_def\n  apply clarsimp\n  apply (rule vrepeat_bod_scorres; simp?)\n  done\n\nend (* of context *)\n\nend", "meta": {"author": "zilinc", "repo": "popl23-artefact", "sha": "1fe1490d2d34f93dc01ada940c160477db3b9b72", "save_path": "github-repos/isabelle/zilinc-popl23-artefact", "path": "github-repos/isabelle/zilinc-popl23-artefact/popl23-artefact-1fe1490d2d34f93dc01ada940c160477db3b9b72/arrays/loops/RepeatScorres.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953797290153, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.25952217008764894}}
{"text": "theory sch\n  imports task2\nbegin\n\n\ndefinition Pr :: char where \"Pr = CHR ''p''\"\n\ndefinition G :: char where \"G = CHR ''g''\"\n\n\nfun sched_push :: \"tid \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate\" where\n  \"sched_push t (Sch p rn rp) s = Sch (p @ [(s (CHR ''p''), t)]) rn rp\"\n| \"sched_push t (Task st ent tp) s = undefined\"\n| \"sched_push t None s = undefined\"\n\nfun sched_assign :: \"tid \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate\" where\n  \"sched_assign t (Sch p rn rp) s = Sch p t (s (CHR ''p''))\"\n| \"sched_assign t (Task st ent tp) s = undefined\"\n| \"sched_assign t None s = undefined\"\n\nfun get_max_default :: \"real \\<times> tid \\<Rightarrow> (real \\<times> tid) list \\<Rightarrow> real \\<times> tid\" where\n  \"get_max_default (prior, t) [] = (prior, t)\"\n| \"get_max_default (prior, t) ((prior2, t2) # rest) =\n    (if prior \\<ge> prior2 then\n       get_max_default (prior, t) rest\n     else\n       get_max_default (prior2, t2) rest)\"\n\nfun get_max :: \"(real \\<times> tid) list \\<Rightarrow> real \\<times> tid\" where\n  \"get_max [] = (-1, -1)\"\n| \"get_max ((prior, t) # rest) = get_max_default (prior, t) rest\"\n\nfun del_proc :: \"(real \\<times> tid) list \\<Rightarrow> tid \\<Rightarrow> (real \\<times> tid) list\" where\n  \"del_proc [] t = []\"\n| \"del_proc ((prior, t) # rest) t2 =\n    (if t = t2 then rest\n     else (prior, t) # del_proc rest t2)\"\n\nfun sched_get_max :: \"estate \\<Rightarrow> state \\<Rightarrow> estate\" where\n  \"sched_get_max (Sch p rn rp) s =\n    (let (prior, t) = get_max p in Sch (del_proc p t) t prior)\"\n| \"sched_get_max (Task st ent tp) s = undefined\"\n| \"sched_get_max None s = undefined\"\n\nfun sched_get_max' :: \"estate \\<Rightarrow> estate\" where\n  \"sched_get_max' (Sch p rn rp) =\n    (let (prior, t) = get_max p in Sch (del_proc p t) t prior)\"\n| \"sched_get_max' (Task st ent tp) = undefined\"\n| \"sched_get_max' None = undefined\"\n\nlemma sched_get_max_eq:\n\"sched_get_max e s = sched_get_max' e\"\n  apply(cases e)\n  by auto\n\nfun sched_clear :: \"estate \\<Rightarrow> state \\<Rightarrow> estate\" where\n  \"sched_clear (Sch p rn rp) s = Sch [] (-1) (-1)\"\n| \"sched_clear (Task st ent tp) s = undefined\"\n| \"sched_clear None s = undefined\"\n\nfun sched_clear' :: \"estate \\<Rightarrow> estate\" where\n  \"sched_clear' (Sch p rn rp) = Sch [] (-1) (-1)\"\n| \"sched_clear' (Task st ent tp) = undefined\"\n| \"sched_clear' None = undefined\"\n\nlemma sched_clear_eq:\n\"sched_clear e s = sched_clear' e\"\n  apply(cases e)\n  by auto\n\n\nfun sched_del_proc :: \"tid \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate\" where\n  \"sched_del_proc t (Sch p rn rp) s = Sch (del_proc p t) rn rp\"\n| \"sched_del_proc t (Task st ent tp) s = undefined\"\n| \"sched_del_proc t None s = undefined\"\n\n\nfun sched_del_proc' :: \"tid \\<Rightarrow> estate \\<Rightarrow> estate\" where\n  \"sched_del_proc' t (Sch p rn rp) = Sch (del_proc p t) rn rp\"\n| \"sched_del_proc' t (Task st ent tp) = undefined\"\n| \"sched_del_proc' t None = undefined\"\n\nlemma sched_del_proc_eq:\n\"sched_del_proc t e s = sched_del_proc' t e\"\n  apply(cases e)\n  by auto\n\n\nfun run_now_assign :: \"real \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate\" where\n\"run_now_assign rn (Sch p n rp) s = (Sch p rn rp)\"\n\nfun run_prior_assign :: \"estate \\<Rightarrow> state \\<Rightarrow> estate\" where\n\"run_prior_assign (Sch p n rp) s = (Sch p n (s Pr))\"\n\n\ndefinition properp :: \"tid \\<Rightarrow> real \\<Rightarrow> bool\" where\n\"properp rn rp = ((rn = 1 \\<longleftrightarrow> rp = 2) \\<and> (rn = 2 \\<longleftrightarrow> rp = 1) \\<and> (rn = -1 \\<longleftrightarrow> rp = -1) \\<and> rp \\<in> {-1,1,2} \\<and> rn \\<in> {-1,1,2})\"\n\nfun properl :: \"(real \\<times> tid) list \\<Rightarrow> bool\" where\n  \"properl [] = True\"\n| \"properl ((rp,rn) # v) = (properl v \\<and> properp rn rp \\<and> rn > 0 \\<and> rn \\<noteq> 1)\"\n\nlemma properl_p1:\n\"properl (p @ [(a, b)]) = (properl p \\<and> properp b a \\<and> b > 0 \\<and> b \\<noteq> 1)\"\nproof(induction p arbitrary: a b)\n  case Nil\n  then show ?case \n    by auto\nnext\n  case (Cons c p)\n  show ?case\n    apply(cases c)\n    subgoal for ca cb\n      apply simp\n      using Cons[of a b]\n      by auto\ndone\nqed\n\nlemma properl_p2:\n\"properl p \\<Longrightarrow> properp rn rp \\<Longrightarrow> properp (snd(get_max_default (rp,rn) p)) (fst(get_max_default (rp,rn) p))\"\nproof(induction p arbitrary: rn rp)\n  case Nil\n  then show ?case \n    by auto\nnext\n  case (Cons c p)\n  then show ?case \n    apply(cases c)\n    subgoal for a b\n      by auto\n    done\nqed\n\n\nlemma properl_p3:\n\"properl p \\<Longrightarrow> properp (snd (get_max p)) (fst (get_max p)) \"\nproof(induction p)\n  case Nil\n  then show ?case \n    apply auto\n    unfolding properp_def\n    by auto\nnext\n  case (Cons c p)\n  then show ?case \n    apply(cases c)\n    subgoal for a b\n      apply auto\n      apply(rule properl_p2)\n      by auto\n    done\nqed\n\n\nlemma properl_p4:\n\"properl p \\<Longrightarrow> properl (del_proc p t)\"\nproof(induction p)\n  case Nil\n  then show ?case \n    by auto\nnext\n  case (Cons c p)\n  then show ?case \n    apply(cases c)\n    subgoal for a b\n     by auto\n    done\nqed\n\nlemma proper_getmax1':\n\"fst (get_max_default (a,b) p) < d \\<Longrightarrow> a' < d \\<Longrightarrow> fst (get_max_default (a,b) (p@[(a',b')])) < d\"\nproof(induction p arbitrary: a b)\n  case Nil\n  then show ?case \n    by auto\nnext\n  case (Cons g p)\n  then show ?case \n    apply(cases g)\n    subgoal for ga gb\n      by auto\n    done\nqed\n\nlemma proper_getmax1:\n\"fst (get_max p) < d \\<Longrightarrow> a' < d \\<Longrightarrow> fst (get_max(p@[(a',b')])) < d\"\nproof(induction p)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons g p)\n  then show ?case \n    apply (cases g)\n    subgoal for ga gb\n      apply auto\n      using proper_getmax1'\n      by auto\n    done\nqed\n\n\nlemma proper_getmax2:\n\"properl p \\<Longrightarrow> snd (get_max p) \\<noteq> 1 \\<and> (gb \\<noteq> 1 \\<longrightarrow> snd (get_max_default (ga, gb) p) \\<noteq> 1)\"\nproof(induction p arbitrary: ga gb)\n  case Nil\n  then show ?case \n    by auto\nnext\n  case (Cons h p)\n  then show ?case \n    apply (cases h)\n    subgoal for ha hb\n      by auto\n    done\nqed\n\nlemma properl_p5':\n  \"properl ((a,b)#p) \\<Longrightarrow> snd(get_max_default (a,b) p) > 0\"\nproof(induction p arbitrary: a b)\n  case Nil\n  then show ?case \n    by auto\nnext\n  case (Cons g p)\n  then show ?case \n    apply(cases g)\n    by auto\nqed\n\nlemma properl_p5:\n\"length p > 0 \\<Longrightarrow> properl p \\<Longrightarrow> properp (snd (get_max p)) (fst (get_max p)) \\<and> (snd (get_max p)) > 0 \\<and> (snd (get_max p)) \\<noteq> 1\"\nproof(induction p)\n  case Nil\n  then show ?case \n    by auto\nnext\n  case (Cons c p)\n  then show ?case \n    apply(cases c)\n    subgoal for a b\n      apply auto\n      subgoal\n      apply(rule properl_p2)\n         apply auto\n        done\n       prefer 2\n      subgoal\n        using proper_getmax2 apply auto\n        done\n      using properl_p5'[of 1 2 p] \n      apply auto\n      unfolding properp_def\n      by auto\n    done\nqed\n\n\n\ndefinition proper :: \"estate \\<Rightarrow> bool \" where\n\"proper schs = ((properp (run_now schs) (run_prior schs)) \\<and> properl (pool schs))\"\n\n\ndefinition SCH :: \"estate proc\" where\n\"SCH = EChoice [(req_ch 1[?]Pr,IF (\\<lambda> s. run_prior (fst s) \\<ge> (snd s) Pr) THEN Basic (sched_push 1) \n                   ELSE (IF (\\<lambda> s. run_now (fst s) = 2) THEN Cm (preempt_ch 2[!](\\<lambda>_ . 0)) ELSE Skip FI; Cm (run_ch 1[!](\\<lambda>_ . 0));Basic (run_now_assign 1);Basic run_prior_assign) FI),\n                (req_ch 2[?]Pr,IF (\\<lambda> s. run_prior (fst s) \\<ge> (snd s) Pr) THEN Basic (sched_push 2) \n                   ELSE (IF (\\<lambda> s. run_now (fst s) = 1) THEN Cm (preempt_ch 1[!](\\<lambda>_ . 0)) ELSE Skip FI; Cm (run_ch 2[!](\\<lambda>_ . 0));Basic (run_now_assign 2);Basic run_prior_assign) FI),\n                (free_ch 1[?]G,IF (\\<lambda> s. length (pool (fst s)) > 0) THEN ((Basic sched_get_max);(IF (\\<lambda> s. run_now (fst s) = 1)THEN Cm (run_ch 1[!](\\<lambda>_.0)) ELSE Cm (run_ch 2[!](\\<lambda>_.0)) FI)) \n                   ELSE Basic sched_clear FI),\n                (free_ch 2[?]G,IF (\\<lambda> s. length (pool (fst s)) > 0) THEN ((Basic sched_get_max);(IF (\\<lambda> s. run_now (fst s) = 1)THEN Cm (run_ch 1[!](\\<lambda>_.0)) ELSE Cm (run_ch 2[!](\\<lambda>_.0)) FI)) \n                   ELSE Basic sched_clear FI),\n                (exit_ch 1[?]G,Basic (sched_del_proc 1)),\n                (exit_ch 2[?]G,Basic (sched_del_proc 2))]\"\n\ndefinition QQ :: \"(real \\<times> tid) list \\<Rightarrow> tid \\<Rightarrow> real \\<Rightarrow> state \\<Rightarrow> estate assn \\<Rightarrow> estate assn\"where \n\"QQ p rn rp ss P = (\\<lambda> s t. (if rp \\<ge> 2 then s = (Sch (p @ [(2, 1)]) rn rp,ss(Pr:=2)) \\<and> (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (req_ch 1) 2 ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}))) t \n        else if rn = 2 then s = (Sch p 1 2, ss(Pr:=2)) \\<and> (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (req_ch 1) 2 ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})) @\\<^sub>t ((Out0\\<^sub>t (preempt_ch 2) 0) @\\<^sub>t (Out0\\<^sub>t (run_ch 1) 0) \\<or>\\<^sub>t (Waitp\\<^sub>t  ({preempt_ch 2},{})) @\\<^sub>t true\\<^sub>A \\<or>\\<^sub>t (Out0\\<^sub>t (preempt_ch 2) 0) @\\<^sub>t(Waitp\\<^sub>t  ({run_ch 1},{})) @\\<^sub>t true\\<^sub>A)) t \n                        else s = (Sch p 1 2, ss(Pr:=2)) \\<and> (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (req_ch 1) 2 ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})) @\\<^sub>t ((Out0\\<^sub>t (run_ch 1) 0) \\<or>\\<^sub>t (Waitp\\<^sub>t ({run_ch 1},{})) @\\<^sub>t true\\<^sub>A )) t)\n         \\<or> (\\<exists> v\\<noteq>2. (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (req_ch 1) v ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})) @\\<^sub>t true\\<^sub>A ) t)\n                        \\<or> (if rp \\<ge> 1 then s = (Sch (p @ [(1, 2)]) rn rp,ss(Pr:=1)) \\<and> (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (req_ch 2) 1 ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}))) t \n        else if rn = 1 then s = (Sch p 2 1, ss(Pr:=1)) \\<and> (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (req_ch 2) 1 ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})) @\\<^sub>t ((Out0\\<^sub>t (preempt_ch 1) 0) @\\<^sub>t (Out0\\<^sub>t (run_ch 2) 0) \\<or>\\<^sub>t (Waitp\\<^sub>t  ({preempt_ch 1},{})) @\\<^sub>t true\\<^sub>A \\<or>\\<^sub>t (Out0\\<^sub>t (preempt_ch 1) 0) @\\<^sub>t(Waitp\\<^sub>t  ({run_ch 2},{})) @\\<^sub>t true\\<^sub>A)) t \n                        else s = (Sch p 2 1, ss(Pr:=1)) \\<and> (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (req_ch 2) 1 ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})) @\\<^sub>t ((Out0\\<^sub>t (run_ch 2) 0) \\<or>\\<^sub>t (Waitp\\<^sub>t  ({run_ch 2},{})) @\\<^sub>t true\\<^sub>A )) t)\n         \\<or> (\\<exists> v\\<noteq>1. (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (req_ch 2) v ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})) @\\<^sub>t true\\<^sub>A ) t)\n         \\<or> (\\<exists> v. if length p > 0 then s = (sched_get_max'(Sch p rn rp),ss(G:=v)) \n                    \\<and> (if run_now(sched_get_max'(Sch p rn rp)) = 1 \n                        then (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (free_ch 1) v ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})) @\\<^sub>t ((Out0\\<^sub>t (run_ch 1) 0) \\<or>\\<^sub>t (Waitp\\<^sub>t  ({run_ch 1},{})) @\\<^sub>t true\\<^sub>A )) t  \n                        else (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (free_ch 1) v ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})) @\\<^sub>t ((Out0\\<^sub>t (run_ch 2) 0) \\<or>\\<^sub>t (Waitp\\<^sub>t  ({run_ch 2},{})) @\\<^sub>t true\\<^sub>A )) t) \n                  else s = (sched_clear'(Sch p rn rp),ss(G:=v)) \\<and> (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (free_ch 1) v ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}))) t)\n        \\<or>  (\\<exists> v. if length p > 0 then s = (sched_get_max'(Sch p rn rp),ss(G:=v)) \n                    \\<and> (if run_now(sched_get_max'(Sch p rn rp)) = 1 \n                        then (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (free_ch 2) v ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})) @\\<^sub>t ((Out0\\<^sub>t (run_ch 1) 0) \\<or>\\<^sub>t (Waitp\\<^sub>t  ({run_ch 1},{})) @\\<^sub>t true\\<^sub>A )) t  \n                        else (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (free_ch 2) v ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})) @\\<^sub>t ((Out0\\<^sub>t (run_ch 2) 0) \\<or>\\<^sub>t (Waitp\\<^sub>t  ({run_ch 2},{})) @\\<^sub>t true\\<^sub>A )) t) \n                  else s = (sched_clear'(Sch p rn rp),ss(G:=v)) \\<and> (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (free_ch 2) v ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}))) t)\n        \\<or>  (\\<exists> v. s = (sched_del_proc' 1 (Sch p rn rp),ss(G:=v)) \\<and> (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (exit_ch 1) v ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}))) t)\n        \\<or>  (\\<exists> v. s = (sched_del_proc' 2 (Sch p rn rp),ss(G:=v)) \\<and> (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (exit_ch 2) v ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}))) t))\"\n\nlemma Sch_Valid_1:\n\"\\<Turnstile> {\\<lambda>s t. s = (Sch p rn rp,ss) \\<and> P s t}\n   SCH\n    {\\<lambda> s t. QQ p rn rp ss P s t}\"\n  unfolding  SCH_def\n  apply(rule Valid_echoice)\n  apply auto\n  subgoal for i a p2\n    apply(cases i)\n    subgoal \n      apply auto\n      apply(rule exI[where x=\"\\<lambda> s t. (s = (Sch p rn rp, ss(Pr:=2)) \\<and> (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (req_ch 1) 2 ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}))) t) \\<or> \n                                     (\\<exists> v\\<noteq>2. s = (Sch p rn rp, ss(Pr:=v)) \\<and> (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (req_ch 1) v ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}))) t)\"])\n\n      apply(rule conjI)\n      subgoal \n        apply(rule Valid_pre_or)\n        subgoal\n        apply(rule Valid_strengthen_post)\n          prefer 2\n           apply(rule Valid_cond_sp)\n            apply(rule Valid_basic_sp1)\n           apply(rule Valid_seq)\n            apply(rule Valid_cond_sp)\n             apply(rule Valid_send_sp_assm0)\n            apply(rule Valid_skip)\n           apply(rule Valid_seq)\n            apply(rule Valid_send_sp_assm0)\n            apply(rule Valid_seq)\n            apply(rule Valid_basic_sp1)\n           apply(rule Valid_basic_sp1)\n          apply(rule entails_disjE')\n          subgoal\n            unfolding entails_def\n            apply(rule allI)+\n            subgoal for s tr\n              apply auto\n              unfolding QQ_def \n              apply(rule disjI1)\n              apply (auto simp add: Pr_def)\n              by (metis prod.exhaust_sel)\n            done\n          subgoal\n            unfolding entails_def\n            apply(rule allI)+\n            subgoal for s tr\n              apply auto\n              unfolding QQ_def \n              apply(rule disjI1)\n              apply(cases s)\n              apply (auto simp add: Pr_def pure_assn_def conj_assn_def join_assn_def)\n              subgoal for tr2 tr1b tr2a tr2b\n                apply(rule exI[where x=tr1b])\n                apply auto\n                apply(rule exI[where x=tr2b])\n                apply auto\n                unfolding disj_assn_def\n                apply(erule disjE)\n                subgoal \n                  apply(erule disjE)\n                  subgoal by auto\n                  subgoal \n                    apply(rule disjI2)\n                    apply(rule disjI1)\n                    by(auto simp add: true_assn_def)\n                  done\n                subgoal\n                apply(erule disjE)\n                  subgoal\n                    apply(rule disjI2)\n                    apply(rule disjI2)\n                    by(auto simp add: true_assn_def)\n                  subgoal\n                    apply(rule disjI2)\n                    apply(rule disjI1)\n                    by(auto simp add: true_assn_def)\n                  done\n                done\n              subgoal for tr2 tr1a tr2a\n                apply(rule exI[where x=tr1a])\n                by auto\n              done\n            done\n          done\n        subgoal\n          apply(rule Valid_ex_pre)\n          subgoal for v\n          apply(rule Valid_weaken_pre[where P'=\"\\<lambda> s t. (\\<up>(v\\<noteq>2) \\<and>\\<^sub>t (P (Sch p rn rp, ss)) @\\<^sub>t\n                    Inrdy\\<^sub>t (Sch p rn rp, ss) (req_ch 1) v ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}))t\"])\n          subgoal\n            unfolding entails_def pure_assn_def conj_assn_def\n            by auto\n          subgoal\n            apply(rule Valid_strengthen_post)\n             prefer 2\n             apply(rule Valid_true)\n            unfolding QQ_def\n            apply(rule entails_disjI2')\n            unfolding entails_def\n            by (auto simp add:pure_assn_def conj_assn_def join_assoc)\n          done\n        done\n      done\n      apply(rule conjI)\n      subgoal unfolding entails_def\n        apply(rule allI)+\n        subgoal for s tr\n          apply(rule impI)\n          apply simp\n          apply(rule allI)\n          subgoal for v\n            apply(cases \"v=2\")\n            subgoal apply(rule disjI1)\n              apply auto\n              apply(auto simp add:join_assn_def) \n              using inrdy_assn.intros(1) by blast\n            subgoal apply(rule disjI2)\n              apply auto\n              apply(rule exI[where x=v])\n              apply simp\n              apply(auto simp add:join_assn_def) \n              using inrdy_assn.intros(1) by blast\n            done\n          done\n        done\n      subgoal unfolding entails_def\n        apply(rule allI)+\n        subgoal for s tr\n          apply(rule impI)\n          apply simp\n          apply(rule allI)\n          subgoal for d\n          apply(rule impI)\n          apply(rule allI)\n          subgoal for v\n            apply(cases \"v=2\")\n            subgoal apply(rule disjI1)\n              apply auto\n              apply(auto simp add:join_assn_def) \n              using inrdy_assn.intros(2) by blast\n            subgoal apply(rule disjI2)\n              apply auto\n              apply(rule exI[where x=v])\n              apply simp\n              apply(auto simp add:join_assn_def) \n              using inrdy_assn.intros(2) by blast\n            done\n          done\n        done\n      done\n    done\n  subgoal for i'\n    apply(cases i')\n    subgoal\n      apply auto\n      apply(rule exI[where x=\"\\<lambda> s t. (s = (Sch p rn rp, ss(Pr:=1)) \\<and> (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (req_ch 2) 1 ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}))) t) \\<or> \n                                     (\\<exists> v\\<noteq>1. s = (Sch p rn rp, ss(Pr:=v)) \\<and> (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (req_ch 2) v ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}))) t)\"])\n      apply(rule conjI)\n      subgoal \n        apply(rule Valid_pre_or)\n        subgoal\n        apply(rule Valid_strengthen_post)\n          prefer 2\n           apply(rule Valid_cond_sp)\n            apply(rule Valid_basic_sp1)\n           apply(rule Valid_seq)\n            apply(rule Valid_cond_sp)\n             apply(rule Valid_send_sp_assm0)\n            apply(rule Valid_skip)\n           apply(rule Valid_seq)\n            apply(rule Valid_send_sp_assm0)\n            apply(rule Valid_seq)\n            apply(rule Valid_basic_sp1)\n           apply(rule Valid_basic_sp1)\n          apply(rule entails_disjE')\n          subgoal\n            unfolding entails_def\n            apply(rule allI)+\n            subgoal for s tr\n              apply auto\n              unfolding QQ_def \n              apply(rule disjI2)\n              apply(rule disjI2)\n              apply(rule disjI1)\n              apply (auto simp add: Pr_def)\n              by (metis prod.exhaust_sel)\n            done\n          subgoal\n            unfolding entails_def\n            apply(rule allI)+\n            subgoal for s tr\n              apply auto\n              unfolding QQ_def \n              apply(rule disjI2)\n              apply(rule disjI2)\n              apply(rule disjI1)\n              apply(cases s)\n              apply (auto simp add: Pr_def pure_assn_def conj_assn_def join_assn_def)\n              subgoal for tr2 tr1b tr2a tr2b\n                apply(rule exI[where x=tr1b])\n                apply auto\n                apply(rule exI[where x=tr2b])\n                apply auto\n                unfolding disj_assn_def\n                apply(erule disjE)\n                subgoal \n                  apply(erule disjE)\n                  subgoal by auto\n                  subgoal \n                    apply(rule disjI2)\n                    apply(rule disjI1)\n                    by(auto simp add: true_assn_def)\n                  done\n                subgoal\n                apply(erule disjE)\n                  subgoal\n                    apply(rule disjI2)\n                    apply(rule disjI2)\n                    by(auto simp add: true_assn_def)\n                  subgoal\n                    apply(rule disjI2)\n                    apply(rule disjI1)\n                    by(auto simp add: true_assn_def)\n                  done\n                done\n              subgoal for tr2 tr1a tr2a\n                apply(rule exI[where x=tr1a])\n                by auto\n              done\n            done\n          done\n        subgoal\n          apply(rule Valid_ex_pre)\n          subgoal for v\n          apply(rule Valid_weaken_pre[where P'=\"\\<lambda> s t. (\\<up>(v\\<noteq>1) \\<and>\\<^sub>t (P (Sch p rn rp, ss)) @\\<^sub>t\n                    Inrdy\\<^sub>t (Sch p rn rp, ss) (req_ch 2) v ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}))t\"])\n          subgoal\n            unfolding entails_def pure_assn_def conj_assn_def\n            by auto\n          subgoal\n            apply(rule Valid_strengthen_post)\n             prefer 2\n             apply(rule Valid_true)\n            unfolding QQ_def\n            apply(rule entails_disjI2')\n            unfolding entails_def\n            by (auto simp add:pure_assn_def conj_assn_def join_assoc)\n          done\n        done\n      done\n      apply(rule conjI)\n      subgoal unfolding entails_def\n        apply(rule allI)+\n        subgoal for s tr\n          apply(rule impI)\n          apply simp\n          apply(rule allI)\n          subgoal for v\n            apply(cases \"v=1\")\n            subgoal apply(rule disjI1)\n              apply auto\n              apply(auto simp add:join_assn_def) \n              using inrdy_assn.intros(1) by blast\n            subgoal apply(rule disjI2)\n              apply auto\n              apply(rule exI[where x=v])\n              apply simp\n              apply(auto simp add:join_assn_def) \n              using inrdy_assn.intros(1) by blast\n            done\n          done\n        done\n      subgoal unfolding entails_def\n        apply(rule allI)+\n        subgoal for s tr\n          apply(rule impI)\n          apply simp\n          apply(rule allI)\n          subgoal for d\n          apply(rule impI)\n          apply(rule allI)\n          subgoal for v\n            apply(cases \"v=1\")\n            subgoal apply(rule disjI1)\n              apply auto\n              apply(auto simp add:join_assn_def) \n              using inrdy_assn.intros(2) by blast\n            subgoal apply(rule disjI2)\n              apply auto\n              apply(rule exI[where x=v])\n              apply simp\n              apply(auto simp add:join_assn_def) \n              using inrdy_assn.intros(2) by blast\n            done\n          done\n        done\n      done\n    done\n  subgoal for i''\n    apply(cases i'')\n    subgoal\n      apply auto\n      apply(rule exI[where x=\"\\<lambda> s t. (\\<exists> v. s = (Sch p rn rp, ss(G:=v)) \\<and> (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (free_ch 1) v ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}))) t)\"])\n      apply(rule conjI)\n      subgoal \n        apply(rule Valid_strengthen_post)\n        prefer 2\n         apply(rule Valid_cond_sp)\n          apply(rule Valid_seq)\n           apply(rule Valid_basic_sp1)\n          apply(rule Valid_cond_sp)\n           apply(rule Valid_send_sp_assm0)\n          apply(rule Valid_send_sp_assm0)\n         apply(rule Valid_basic_sp1)\n        apply(rule entails_disjE')\n         apply(rule entails_disjE')\n        subgoal\n          unfolding QQ_def entails_def\n          apply(rule allI)+\n          apply(rule impI)\n          subgoal for s tr\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI1)\n            apply (auto simp add: pure_assn_def conj_assn_def join_assn_def disj_assn_def)\n            subgoal for v tr2 tr1a tr2a\n              apply(cases s)\n              apply(rule exI[where x=v])\n              by auto\n            subgoal for v tr1a tr2a tr1b tr2b\n              apply(cases s)\n              apply(rule exI[where x=v])\n              apply (auto simp add:true_assn_def)\n              apply(rule exI[where x=tr1a])\n              apply (auto simp add:true_assn_def)\n              done\n            done\n          done\n        subgoal\n          unfolding QQ_def entails_def\n          apply(rule allI)+\n          apply(rule impI)\n          subgoal for s tr\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI1)\n            apply (auto simp add: pure_assn_def conj_assn_def join_assn_def disj_assn_def)\n            subgoal for v tr2 tr1a tr2a\n              apply(cases s)\n              apply(rule exI[where x=v])\n              by auto\n            subgoal for v tr1a tr2a tr1b tr2b\n              apply(cases s)\n              apply(rule exI[where x=v])\n              apply (auto simp add:true_assn_def)\n              apply(rule exI[where x=tr1a])\n              apply (auto simp add:true_assn_def)\n              done\n            done\n          done\n        subgoal\n          unfolding QQ_def entails_def\n          apply(rule allI)+\n          apply(rule impI)\n          subgoal for s tr\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI1)\n            apply (auto simp add: pure_assn_def conj_assn_def join_assn_def disj_assn_def)\n            subgoal for v tr1 tr2\n              apply(cases s)\n              apply(rule exI[where x=v])\n              by auto\n            done\n          done\n        done\n      apply(rule conjI)\n      subgoal unfolding entails_def\n        apply(rule allI)+\n        apply(rule impI)\n        apply auto\n        by (metis (no_types, opaque_lifting) inrdy_assn.intros(1) join_assn_def)\n      subgoal unfolding entails_def\n        apply(rule allI)+\n        apply(rule impI)\n        apply auto\n        subgoal for tr d v\n          apply(rule exI[where x=v])\n          apply (auto simp add:join_assn_def)\n          apply(rule exI[where x=tr])\n          apply auto\n          apply(rule )\n          by auto\n        done\n      done\n    subgoal for i'''\n      apply(cases i''')\n    subgoal\n      apply auto\n      apply(rule exI[where x=\"\\<lambda> s t. (\\<exists> v. s = (Sch p rn rp, ss(G:=v)) \\<and> (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (free_ch 2) v ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}))) t)\"])\n      apply(rule conjI)\n      subgoal \n        apply(rule Valid_strengthen_post)\n        prefer 2\n         apply(rule Valid_cond_sp)\n          apply(rule Valid_seq)\n           apply(rule Valid_basic_sp1)\n          apply(rule Valid_cond_sp)\n           apply(rule Valid_send_sp_assm0)\n          apply(rule Valid_send_sp_assm0)\n         apply(rule Valid_basic_sp1)\n        apply(rule entails_disjE')\n         apply(rule entails_disjE')\n        subgoal\n          unfolding QQ_def entails_def\n          apply(rule allI)+\n          apply(rule impI)\n          subgoal for s tr\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI1)\n            apply (auto simp add: pure_assn_def conj_assn_def join_assn_def disj_assn_def)\n            subgoal for v tr2 tr1a tr2a\n              apply(cases s)\n              apply(rule exI[where x=v])\n              by auto\n            subgoal for v tr1a tr2a tr1b tr2b\n              apply(cases s)\n              apply(rule exI[where x=v])\n              apply (auto simp add:true_assn_def)\n              apply(rule exI[where x=tr1a])\n              apply (auto simp add:true_assn_def)\n              done\n            done\n          done\n        subgoal\n          unfolding QQ_def entails_def\n          apply(rule allI)+\n          apply(rule impI)\n          subgoal for s tr\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI1)\n            apply (auto simp add: pure_assn_def conj_assn_def join_assn_def disj_assn_def)\n            subgoal for v tr2 tr1a tr2a\n              apply(cases s)\n              apply(rule exI[where x=v])\n              by auto\n            subgoal for v tr1a tr2a tr1b tr2b\n              apply(cases s)\n              apply(rule exI[where x=v])\n              apply (auto simp add:true_assn_def)\n              apply(rule exI[where x=tr1a])\n              apply (auto simp add:true_assn_def)\n              done\n            done\n          done\n        subgoal\n          unfolding QQ_def entails_def\n          apply(rule allI)+\n          apply(rule impI)\n          subgoal for s tr\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI1)\n            apply (auto simp add: pure_assn_def conj_assn_def join_assn_def disj_assn_def)\n            subgoal for v tr1 tr2\n              apply(cases s)\n              apply(rule exI[where x=v])\n              by auto\n            done\n          done\n        done\n      apply(rule conjI)\n      subgoal unfolding entails_def\n        apply(rule allI)+\n        apply(rule impI)\n        apply auto\n        by (metis (no_types, opaque_lifting) inrdy_assn.intros(1) join_assn_def)\n      subgoal unfolding entails_def\n        apply(rule allI)+\n        apply(rule impI)\n        apply auto\n        subgoal for tr d v\n          apply(rule exI[where x=v])\n          apply (auto simp add:join_assn_def)\n          apply(rule exI[where x=tr])\n          apply auto\n          apply(rule )\n          by auto\n        done\n      done\n    subgoal for i''''\n      apply(cases i'''')\n      subgoal\n        apply auto\n        apply(rule exI[where x=\"\\<lambda> s t. (\\<exists> v. s = (Sch p rn rp, ss(G:=v)) \\<and> (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (exit_ch 1) v ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}))) t)\"])\n        apply(rule conjI)\n        subgoal\n          apply(rule Valid_ex_pre)\n          apply(rule Valid_strengthen_post)\n           prefer 2\n           apply(rule Valid_basic_sp1)\n          apply auto\n          unfolding QQ_def entails_def\n          apply(rule allI)+\n          apply(rule impI)\n          apply(rule disjI2)\n          apply(rule disjI2)\n          apply(rule disjI2)\n          apply(rule disjI2)\n          apply(rule disjI2)\n          apply(rule disjI2)\n          apply(rule disjI1)\n          by auto\n        apply(rule conjI)\n        subgoal\n          unfolding entails_def\n          apply auto\n          by (metis inrdy_assn.intros(1) join_assn_def)\n        subgoal\n          unfolding entails_def\n          apply (auto simp add:join_assn_def)\n          subgoal for tr d v\n            apply(rule exI[where x=v])\n            apply auto\n            apply(rule exI[where x=tr])\n            apply auto\n            apply(rule ) by auto\n          done\n        done\n      subgoal for i'''''\n        subgoal\n        apply auto\n        apply(rule exI[where x=\"\\<lambda> s t. (\\<exists> v. s = (Sch p rn rp, ss(G:=v)) \\<and> (P (Sch p rn rp, ss) @\\<^sub>t (Inrdy\\<^sub>t (Sch p rn rp, ss) (exit_ch 2) v ({},{req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}))) t)\"])\n        apply(rule conjI)\n        subgoal\n          apply(rule Valid_ex_pre)\n          apply(rule Valid_strengthen_post)\n           prefer 2\n           apply(rule Valid_basic_sp1)\n          apply auto\n          unfolding QQ_def entails_def\n          apply(rule allI)+\n          apply(rule impI)\n          apply(rule disjI2)\n          apply(rule disjI2)\n          apply(rule disjI2)\n          apply(rule disjI2)\n          apply(rule disjI2)\n          apply(rule disjI2)\n          apply(rule disjI2)\n          by auto\n        apply(rule conjI)\n        subgoal\n          unfolding entails_def\n          apply auto\n          by (metis inrdy_assn.intros(1) join_assn_def)\n        subgoal\n          unfolding entails_def\n          apply (auto simp add:join_assn_def)\n          subgoal for tr d v\n            apply(rule exI[where x=v])\n            apply auto\n            apply(rule exI[where x=tr])\n            apply auto\n            apply(rule ) by auto\n          done\n        done\n      done\n    done\n  done\n  done\n  done\n  done\n  done\n\n            \nfun SCH_tr:: \"nat \\<Rightarrow> estate ext_state \\<Rightarrow> estate tassn\" where\n  \"SCH_tr 0 (Sch p rn rp,ss)  = emp\\<^sub>t\" \n| \"SCH_tr (Suc k) (Sch p rn rp,ss) = (\n   (Inrdy\\<^sub>t (Sch p rn rp, ss) (req_ch 1) 2\n               ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})) \n              @\\<^sub>t (if rp \\<ge> 2 then SCH_tr k (Sch (p @ [(2, 1)]) rn rp,ss(Pr := 2)) \n               else if rn = 2 then Out0\\<^sub>t (preempt_ch 2) 0 @\\<^sub>t Out0\\<^sub>t (run_ch 1) 0 @\\<^sub>t SCH_tr k (Sch p 1 2,ss(Pr := 2)) \\<or>\\<^sub>t\n                                     Waitp\\<^sub>t  ({preempt_ch 2}, {}) @\\<^sub>t true\\<^sub>A \\<or>\\<^sub>t\n                                      Out0\\<^sub>t (preempt_ch 2) 0 @\\<^sub>t Waitp\\<^sub>t  ({run_ch 1}, {}) @\\<^sub>t true\\<^sub>A \n                              else Out0\\<^sub>t (run_ch 1) 0 @\\<^sub>t SCH_tr k (Sch p 1 2,ss(Pr := 2))\\<or>\\<^sub>t\n                                     Waitp\\<^sub>t ({run_ch 1}, {}) @\\<^sub>t true\\<^sub>A)\n \\<or>\\<^sub>t(\\<exists>\\<^sub>t v. \\<up>(v\\<noteq>2) \\<and>\\<^sub>t  Inrdy\\<^sub>t (Sch p rn rp, ss) (req_ch 1) v ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) @\\<^sub>t true\\<^sub>A ) \n \\<or>\\<^sub>t(Inrdy\\<^sub>t (Sch p rn rp, ss) (req_ch 2) 1\n               ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2})) \n              @\\<^sub>t (if rp \\<ge> 1 then SCH_tr k (Sch (p @ [(1, 2)]) rn rp,ss(Pr := 1)) \n               else if rn = 1 then Out0\\<^sub>t (preempt_ch 1) 0 @\\<^sub>t Out0\\<^sub>t (run_ch 2) 0 @\\<^sub>t SCH_tr k (Sch p 2 1,ss(Pr := 1)) \\<or>\\<^sub>t\n                                     Waitp\\<^sub>t  ({preempt_ch 1}, {}) @\\<^sub>t true\\<^sub>A \\<or>\\<^sub>t\n                                      Out0\\<^sub>t (preempt_ch 1) 0 @\\<^sub>t Waitp\\<^sub>t  ({run_ch 2}, {}) @\\<^sub>t true\\<^sub>A \n                              else Out0\\<^sub>t (run_ch 2) 0 @\\<^sub>t SCH_tr k (Sch p 2 1,ss(Pr := 1))\\<or>\\<^sub>t\n                                     Waitp\\<^sub>t ({run_ch 2}, {}) @\\<^sub>t true\\<^sub>A)\n  \\<or>\\<^sub>t(\\<exists>\\<^sub>t v. \\<up>(v\\<noteq>1) \\<and>\\<^sub>t  Inrdy\\<^sub>t (Sch p rn rp, ss) (req_ch 2) v ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) @\\<^sub>t true\\<^sub>A ) \n  \\<or>\\<^sub>t(\\<exists>\\<^sub>t v. Inrdy\\<^sub>t (Sch p rn rp, ss) (free_ch 1) v ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) @\\<^sub>t \n          (if length p > 0 then if run_now (sched_get_max' (Sch p rn rp)) = 1 \n                                then  (Out0\\<^sub>t (run_ch 1) 0 @\\<^sub>t SCH_tr k (sched_get_max' (Sch p rn rp), ss(G := v)) \\<or>\\<^sub>t\n                                       Waitp\\<^sub>t  ({run_ch 1}, {}) @\\<^sub>t true\\<^sub>A)\n                                else  (Out0\\<^sub>t (run_ch 2) 0 @\\<^sub>t SCH_tr k (sched_get_max' (Sch p rn rp), ss(G := v)) \\<or>\\<^sub>t\n                                       Waitp\\<^sub>t  ({run_ch 2}, {}) @\\<^sub>t true\\<^sub>A)\n                           else SCH_tr k (sched_clear' (Sch p rn rp), ss(G := v))))\n  \\<or>\\<^sub>t(\\<exists>\\<^sub>t v. Inrdy\\<^sub>t (Sch p rn rp, ss) (free_ch 2) v ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) @\\<^sub>t \n          (if length p > 0 then if run_now (sched_get_max' (Sch p rn rp)) = 1 \n                                then  (Out0\\<^sub>t (run_ch 1) 0 @\\<^sub>t SCH_tr k (sched_get_max' (Sch p rn rp), ss(G := v)) \\<or>\\<^sub>t\n                                       Waitp\\<^sub>t  ({run_ch 1}, {}) @\\<^sub>t true\\<^sub>A)\n                                else  (Out0\\<^sub>t (run_ch 2) 0 @\\<^sub>t SCH_tr k (sched_get_max' (Sch p rn rp), ss(G := v)) \\<or>\\<^sub>t\n                                       Waitp\\<^sub>t  ({run_ch 2}, {}) @\\<^sub>t true\\<^sub>A)\n                           else SCH_tr k (sched_clear' (Sch p rn rp), ss(G := v))))\n  \\<or>\\<^sub>t(\\<exists>\\<^sub>t v. Inrdy\\<^sub>t (Sch p rn rp, ss) (exit_ch 1) v ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) \n                             @\\<^sub>t SCH_tr k (sched_del_proc' 1 (Sch p rn rp), ss(G := v)))\n  \\<or>\\<^sub>t(\\<exists>\\<^sub>t v. Inrdy\\<^sub>t (Sch p rn rp, ss) (exit_ch 2) v ({}, {req_ch 1, req_ch 2, free_ch 1, free_ch 2, exit_ch 1, exit_ch 2}) \n                             @\\<^sub>t SCH_tr k (sched_del_proc' 2 (Sch p rn rp), ss(G := v)))\n)\"\n  \n\n\n\nlemma Valid_SCH_rep:\n  \"\\<Turnstile> {\\<lambda>s t. s = (Sch p rn rp,ss) \\<and> emp\\<^sub>t t}\n                      Rep SCH\n      {\\<lambda>s t. (\\<exists>n. (emp\\<^sub>t @\\<^sub>t SCH_tr n (Sch p rn rp,ss)) t)}\"\napply(rule Valid_rep'')\n  subgoal for n P\n    apply(induction n arbitrary:P p rn rp ss)\n    subgoal for P\n      apply auto\n      apply(rule Valid_strengthen_post)\n       prefer 2\n       apply(rule Valid_skip)\n      unfolding entails_def by auto\n    subgoal premises pre for n P p rn rp ss\n      subgoal\n        unfolding RepN.simps\n        apply(rule Valid_seq)\n         apply(rule Sch_Valid_1)\n        thm pre\n        unfolding QQ_def\n        apply(rule Valid_pre_or)\n        subgoal\n          apply(cases \"2\\<le>rp\")\n          subgoal \n            apply(rule Valid_strengthen_post)\n             prefer 2\n             apply simp\n             apply(rule pre)\n            apply(simp only:join_assoc)\n            apply(rule tassn_to_assn)\n            apply(rule entails_tassn_cancel_left)\n            unfolding entails_tassn_def\n            apply(rule allI)\n            apply(rule impI)\n            unfolding disj_assn_def SCH_tr.simps\n            apply(rule disjI1)\n            by auto\n          apply(cases \"rn = 2\")\n          subgoal \n            apply(rule Valid_strengthen_post)\n             prefer 2\n             apply simp\n             apply(rule pre)\n            apply(simp only:join_assoc)\n            apply(rule tassn_to_assn)\n            apply(rule entails_tassn_cancel_left)\n            unfolding entails_tassn_def\n            apply(rule allI)\n            apply(rule impI)\n            unfolding disj_assn_def SCH_tr.simps\n            apply(rule disjI1)\n            apply (auto simp add:join_assn_def true_assn_def)\n            subgoal by metis\n            subgoal by metis\n            subgoal by metis\n            done\n          subgoal \n            apply(rule Valid_strengthen_post)\n             prefer 2\n             apply simp\n             apply(rule pre)\n            apply(simp only:join_assoc)\n            apply(rule tassn_to_assn)\n            apply(rule entails_tassn_cancel_left)\n            unfolding entails_tassn_def\n            apply(rule allI)\n            apply(rule impI)\n            unfolding disj_assn_def SCH_tr.simps\n            apply(rule disjI1)\n            apply (auto simp add:join_assn_def true_assn_def)\n            by metis\n          done\n        apply(rule Valid_pre_or)\n        subgoal\n          apply(rule Valid_ex_pre)\n          apply(rule Valid_strengthen_post)\n          prefer 2\n           apply(rule Valid_true)\n          subgoal for v\n            apply(rule tassn_to_assn)\n            apply (simp del:SCH_tr.simps add:join_assoc)\n            apply(rule impI)\n            apply(rule entails_tassn_cancel_left)\n            unfolding entails_tassn_def\n            apply(rule allI)\n            apply(rule impI)\n            unfolding disj_assn_def SCH_tr.simps\n            apply(rule disjI2)\n            apply(rule disjI1)\n            by (auto simp add:join_assn_def true_assn_def ex_assn_def pure_assn_def conj_assn_def)\n          done\n        apply(rule Valid_pre_or)\n        subgoal\n          apply(cases \"1\\<le>rp\")\n          subgoal \n            apply(rule Valid_strengthen_post)\n             prefer 2\n             apply simp\n             apply(rule pre)\n            apply(simp only:join_assoc)\n            apply(rule tassn_to_assn)\n            apply(rule entails_tassn_cancel_left)\n            unfolding entails_tassn_def\n            apply(rule allI)\n            apply(rule impI)\n            unfolding disj_assn_def SCH_tr.simps\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI1)\n            by auto\n          apply(cases \"rn = 1\")\n          subgoal \n            apply(rule Valid_strengthen_post)\n             prefer 2\n             apply simp\n             apply(rule pre)\n            apply(simp only:join_assoc)\n            apply(rule tassn_to_assn)\n            apply(rule entails_tassn_cancel_left)\n            unfolding entails_tassn_def\n            apply(rule allI)\n            apply(rule impI)\n            unfolding disj_assn_def SCH_tr.simps\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI1)\n            apply (auto simp add:join_assn_def true_assn_def)\n            subgoal by metis\n            subgoal by metis\n            subgoal by metis\n            done\n          subgoal \n            apply(rule Valid_strengthen_post)\n             prefer 2\n             apply simp\n             apply(rule pre)\n            apply(simp only:join_assoc)\n            apply(rule tassn_to_assn)\n            apply(rule entails_tassn_cancel_left)\n            unfolding entails_tassn_def\n            apply(rule allI)\n            apply(rule impI)\n            unfolding disj_assn_def SCH_tr.simps\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI1)\n            apply (auto simp add:join_assn_def true_assn_def)\n            by metis\n          done\n        apply(rule Valid_pre_or)\n        subgoal\n          apply(rule Valid_ex_pre)\n          apply(rule Valid_strengthen_post)\n          prefer 2\n           apply(rule Valid_true)\n          subgoal for v\n            apply(rule tassn_to_assn)\n            apply (simp del:SCH_tr.simps add:join_assoc)\n            apply(rule impI)\n            apply(rule entails_tassn_cancel_left)\n            unfolding entails_tassn_def\n            apply(rule allI)\n            apply(rule impI)\n            unfolding disj_assn_def SCH_tr.simps\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI2)\n            apply(rule disjI1)\n            by (auto simp add:join_assn_def true_assn_def ex_assn_def pure_assn_def conj_assn_def)\n          done\n        apply(rule Valid_pre_or)\n        subgoal\n          apply(rule Valid_ex_pre)\n          subgoal for v\n          apply(cases \"length p > 0\")\n            subgoal\n              apply(cases \"run_now (sched_get_max' (Sch p rn rp)) = 1\")\n              subgoal\n                apply (simp del: SCH_tr.simps)\n                 apply(cases \"get_max p\")\n                subgoal for pp tt\n                  apply (simp del: SCH_tr.simps)\n                  apply(rule Valid_strengthen_post)\n                   prefer 2\n                   apply(rule pre)\n                  apply(rule tassn_to_assn)\n                  apply(simp del: SCH_tr.simps add: join_assoc)\n                  apply(rule entails_tassn_cancel_left)\n                  unfolding entails_tassn_def\n                  apply(rule allI)\n                  apply(rule impI)\n                  unfolding disj_assn_def SCH_tr.simps\n                  apply(rule disjI2)\n                  apply(rule disjI2)\n                  apply(rule disjI2)\n                  apply(rule disjI2)\n                  apply(rule disjI1)\n                  apply (auto simp add:join_assn_def true_assn_def ex_assn_def pure_assn_def conj_assn_def)\n                  subgoal by metis\n                  subgoal by metis\n                  done\n                done\n              subgoal\n                apply (simp del: SCH_tr.simps)\n                 apply(cases \"get_max p\")\n                subgoal for pp tt\n                  apply (simp del: SCH_tr.simps)\n                  apply(rule Valid_strengthen_post)\n                   prefer 2\n                   apply(rule pre)\n                  apply(rule tassn_to_assn)\n                  apply(simp del: SCH_tr.simps add: join_assoc)\n                  apply(rule entails_tassn_cancel_left)\n                  unfolding entails_tassn_def\n                  apply(rule allI)\n                  apply(rule impI)\n                  unfolding disj_assn_def SCH_tr.simps\n                  apply(rule disjI2)\n                  apply(rule disjI2)\n                  apply(rule disjI2)\n                  apply(rule disjI2)\n                  apply(rule disjI1)\n                  apply (auto simp add:join_assn_def true_assn_def ex_assn_def pure_assn_def conj_assn_def)\n                  subgoal by metis\n                  subgoal by metis\n                  done\n                done\n              done\n            subgoal\n              apply (simp del: SCH_tr.simps)\n              apply(rule Valid_strengthen_post)\n              prefer 2\n              apply(rule pre)\n              apply(rule tassn_to_assn)\n              apply(simp del: SCH_tr.simps add: join_assoc)\n              apply(rule entails_tassn_cancel_left)\n              unfolding entails_tassn_def\n              apply(rule allI)\n              apply(rule impI)\n              unfolding disj_assn_def SCH_tr.simps\n              apply(rule disjI2)\n              apply(rule disjI2)\n              apply(rule disjI2)\n              apply(rule disjI2)\n              apply(rule disjI1)\n              by(auto simp add: ex_assn_def)\n            done\n          done\n        apply(rule Valid_pre_or)\n        subgoal\n          apply(rule Valid_ex_pre)\n          subgoal for v\n          apply(cases \"length p > 0\")\n            subgoal\n              apply(cases \"run_now (sched_get_max' (Sch p rn rp)) = 1\")\n              subgoal\n                apply (simp del: SCH_tr.simps)\n                 apply(cases \"get_max p\")\n                subgoal for pp tt\n                  apply (simp del: SCH_tr.simps)\n                  apply(rule Valid_strengthen_post)\n                   prefer 2\n                   apply(rule pre)\n                  apply(rule tassn_to_assn)\n                  apply(simp del: SCH_tr.simps add: join_assoc)\n                  apply(rule entails_tassn_cancel_left)\n                  unfolding entails_tassn_def\n                  apply(rule allI)\n                  apply(rule impI)\n                  unfolding disj_assn_def SCH_tr.simps\n                  apply(rule disjI2)\n                  apply(rule disjI2)\n                  apply(rule disjI2)\n                  apply(rule disjI2)\n                  apply(rule disjI2)\n                  apply (auto simp add:join_assn_def true_assn_def ex_assn_def pure_assn_def conj_assn_def)\n                  subgoal by metis\n                  subgoal by metis\n                  done\n                done\n              subgoal\n                apply (simp del: SCH_tr.simps)\n                 apply(cases \"get_max p\")\n                subgoal for pp tt\n                  apply (simp del: SCH_tr.simps)\n                  apply(rule Valid_strengthen_post)\n                   prefer 2\n                   apply(rule pre)\n                  apply(rule tassn_to_assn)\n                  apply(simp del: SCH_tr.simps add: join_assoc)\n                  apply(rule entails_tassn_cancel_left)\n                  unfolding entails_tassn_def\n                  apply(rule allI)\n                  apply(rule impI)\n                  unfolding disj_assn_def SCH_tr.simps\n                  apply(rule disjI2)\n                  apply(rule disjI2)\n                  apply(rule disjI2)\n                  apply(rule disjI2)\n                  apply(rule disjI2)\n                  apply(rule disjI1)\n                  apply (auto simp add:join_assn_def true_assn_def ex_assn_def pure_assn_def conj_assn_def)\n                  subgoal by metis\n                  subgoal by metis\n                  done\n                done\n              done\n            subgoal\n              apply (simp del: SCH_tr.simps)\n              apply(rule Valid_strengthen_post)\n              prefer 2\n              apply(rule pre)\n              apply(rule tassn_to_assn)\n              apply(simp del: SCH_tr.simps add: join_assoc)\n              apply(rule entails_tassn_cancel_left)\n              unfolding entails_tassn_def\n              apply(rule allI)\n              apply(rule impI)\n              unfolding disj_assn_def SCH_tr.simps\n              apply(rule disjI2)\n              apply(rule disjI2)\n              apply(rule disjI2)\n              apply(rule disjI2)\n              apply(rule disjI2)\n              apply(rule disjI1)\n              by(auto simp add: ex_assn_def)\n            done\n          done\n        apply(rule Valid_pre_or)\n        subgoal\n          apply(rule Valid_ex_pre)\n          subgoal for v\n            apply (simp del: SCH_tr.simps)\n            apply(rule Valid_strengthen_post)\n              prefer 2\n              apply(rule pre)\n              apply(rule tassn_to_assn)\n              apply(simp del: SCH_tr.simps add: join_assoc)\n              apply(rule entails_tassn_cancel_left)\n              unfolding entails_tassn_def\n              apply(rule allI)\n              apply(rule impI)\n              unfolding disj_assn_def SCH_tr.simps\n              apply(rule disjI2)\n              apply(rule disjI2)\n              apply(rule disjI2)\n              apply(rule disjI2)\n              apply(rule disjI2)\n              apply(rule disjI2)\n              apply(rule disjI1)\n              by(auto simp add: ex_assn_def)\n            done\n          subgoal\n          apply(rule Valid_ex_pre)\n          subgoal for v\n            apply (simp del: SCH_tr.simps)\n            apply(rule Valid_strengthen_post)\n              prefer 2\n              apply(rule pre)\n              apply(rule tassn_to_assn)\n              apply(simp del: SCH_tr.simps add: join_assoc)\n              apply(rule entails_tassn_cancel_left)\n              unfolding entails_tassn_def\n              apply(rule allI)\n              apply(rule impI)\n              unfolding disj_assn_def SCH_tr.simps\n              apply(rule disjI2)\n              apply(rule disjI2)\n              apply(rule disjI2)\n              apply(rule disjI2)\n              apply(rule disjI2)\n              apply(rule disjI2)\n              apply(rule disjI2)\n              by(auto simp add: ex_assn_def)\n            done\n          done\n        done\n      done\n    done\n\n\n\n        \n\n\n\n\nend", "meta": {"author": "AgHHL", "repo": "lics2023", "sha": "e2ea9c15a8c0e1bf658679274ee87f30baf4abc3", "save_path": "github-repos/isabelle/AgHHL-lics2023", "path": "github-repos/isabelle/AgHHL-lics2023/lics2023-e2ea9c15a8c0e1bf658679274ee87f30baf4abc3/case2/sch.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953651858117, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.25952216355204033}}
{"text": "section {* Correctness of Type Checker *}\n\ntheory Wasm_Checker_Properties imports Wasm_Checker Wasm_Properties begin\n\nsubsection {* Soundness *}\n\nlemma b_e_check_single_type_sound:\n  assumes \"type_update (Type x1) (to_ct_list t_in) (Type t_out) = Type x2\"\n          \"c_types_agree (Type x2) tm\"\n          \"\\<C> \\<turnstile> [e] : (t_in _> t_out)\"\n  shows \"\\<exists>tn. c_types_agree (Type x1) tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\n  using assms(2) b_e_typing.weakening[OF assms(3)] type_update_type[OF assms(1)]\n  by auto\n\nlemma b_e_check_single_top_sound:\n  assumes \"type_update (TopType x1) (to_ct_list t_in) (Type t_out) = TopType x2\"\n          \"c_types_agree (TopType x2) tm\"\n          \"\\<C> \\<turnstile> [e] : (t_in _> t_out)\"\n  shows \"\\<exists>tn. c_types_agree (TopType x1) tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\nproof -\n  obtain t_ag where t_ag_def:\"ct_suffix (to_ct_list t_out) x2\"\n                             \"tm = t_ag @ t_out\"\n                             \"c_types_agree (TopType x1) (t_ag @ t_in)\"\n    using type_update_top_top[OF assms(1,2)]\n    by fastforce\n  hence \"\\<C> \\<turnstile> [e] : (t_ag@t_in _> t_ag@t_out)\"\n    using b_e_typing.weakening[OF assms(3)]\n    by fastforce\n  thus ?thesis\n    using t_ag_def\n    by fastforce\nqed\n\nlemma b_e_check_single_top_not_bot_sound:\n  assumes \"type_update ts (to_ct_list t_in) (TopType []) = ts'\"\n          \"ts \\<noteq> Bot\"\n          \"ts' \\<noteq> Bot\"\n  shows \"\\<exists>tn. c_types_agree ts tn \\<and> suffix t_in tn\"\nproof (cases ts)\n  case (TopType x1)\n  then obtain t_int where \"consume (TopType x1) (to_ct_list t_in) = t_int\" \"t_int \\<noteq> Bot\"\n    using assms(1,2,3)\n    by fastforce\n  thus ?thesis\n    using TopType ct_suffix_ct_list_compat_exists ct_suffix_ts_conv_suffix\n    unfolding consume.simps\n    by (metis append_Nil c_types_agree.simps(2) ct_suffix_def)\nnext\n  case (Type x2)\n  then obtain t_int where \"consume (Type x2) (to_ct_list t_in) = t_int\" \"t_int \\<noteq> Bot\"\n    using assms(1,2,3)\n    by fastforce\n  thus ?thesis\n    using c_types_agree_id Type consume_type suffixI ct_suffix_ts_conv_suffix\n    by fastforce\nnext\n  case Bot\n  thus ?thesis\n    using assms(2)\n    by simp\nqed\n\nlemma b_e_check_single_type_not_bot_sound:\n  assumes \"type_update ts (to_ct_list t_in) (Type t_out) = ts'\"\n          \"ts \\<noteq> Bot\"\n          \"ts' \\<noteq> Bot\"\n          \"c_types_agree ts' tm\"\n          \"\\<C> \\<turnstile> [e] : (t_in _> t_out)\"\n  shows \"\\<exists>tn. c_types_agree ts tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\n  using assms b_e_check_single_type_sound\nproof (cases ts)\n  case (TopType x1)\n  then obtain x1' where x_def:\"TopType x1' = ts'\"\n    using assms\n    by (simp, metis (full_types) produce.simps(1) produce.simps(6))\n  thus ?thesis\n    using assms b_e_check_single_top_sound TopType\n    by fastforce\nnext\n  case (Type x2)\n  then obtain x2' where x_def:\"Type x2' = ts'\"\n    using assms\n    by (simp, metis (full_types) produce.simps(2) produce.simps(6))\n  thus ?thesis\n    using assms b_e_check_single_type_sound Type\n    by fastforce\nnext\n  case Bot\n  thus ?thesis\n    using assms(2)\n    by simp\nqed\n\nlemma b_e_check_single_sound_unop_testop_cvtop:\n  assumes \"check_single \\<C> e tn' = tm'\"\n          \"(e = (Unop t uw) \\<and> unop_t_agree op t)\n           \\<or> (e = (Testop t uv) \\<and> is_int_t t)\n           \\<or> (e = (Cvtop t1 Convert t sx) \\<and> convert_cond t1 t sx)\n           \\<or> (e = (Cvtop t1 Reinterpret t sx) \\<and> ((t1 \\<noteq> t) \\<and> t_length t1 = t_length t \\<and> sx = None))\"\n          \"c_types_agree tm' tm\"\n          \"tn' \\<noteq> Bot\"\n          \"tm' \\<noteq> Bot\"\n shows \"\\<exists>tn. c_types_agree tn' tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\nproof -\n  have \"(e = (Cvtop t1 Convert t sx) \\<Longrightarrow> convert_cond t1 t sx)\"\n    using assms(2)\n    by simp\n  have 1:\"type_update tn' (to_ct_list [t]) (Type [arity_1_result e]) = tm'\"\n    using assms arity_1_result_def\n    unfolding to_ct_list_def\n    apply (simp del: convert_cond.simps)\n    apply fastforce\n    done\n  have \"\\<C> \\<turnstile> [e] : ([t] _> [arity_1_result e])\"\n    using assms(2) b_e_typing.intros(2,3,6,9,10)\n    unfolding arity_1_result_def\n    apply simp\n    apply (metis (no_types, lifting) assms(1,5) b_e.simps(801,803,805) b_e_typing.reinterpret b_e_typing.testop check_single.simps(2))\n    done\n  thus ?thesis\n    using b_e_check_single_type_not_bot_sound[OF 1 assms(4,5,3)]\n    by fastforce\nqed\n\nlemma b_e_check_single_sound_binop_relop:\n  assumes \"check_single \\<C> e tn' = tm'\"\n          \"((e = Binop t iop \\<and> binop_t_agree op t)\n            \\<or> (e = Relop t irop \\<and> relop_t_agree irop t))\"\n          \"c_types_agree tm' tm\"\n          \"tn' \\<noteq> Bot\"\n          \"tm' \\<noteq> Bot\"\n shows \"\\<exists>tn. c_types_agree tn' tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\nproof -\n  have \"type_update tn' (to_ct_list [t,t]) (Type [arity_2_result e]) = tm'\"\n    using assms arity_2_result_def\n    unfolding to_ct_list_def\n    by auto\n  moreover\n  have \"\\<C> \\<turnstile> [e] : ([t,t] _> [arity_2_result e])\"\n    using assms(2) b_e_typing.intros(4,5,7,8)\n    unfolding arity_2_result_def\n    by (metis (no_types) assms(1,2,5) b_e.simps(802,804) b_e_typing.relop binop check_single.simps(3))\n  ultimately\n  show ?thesis\n    using b_e_check_single_type_not_bot_sound[OF _ assms(4,5,3)]\n    by fastforce\nqed\n\nlemma b_e_type_checker_sound:\n  assumes \"b_e_type_checker \\<C> es (tn _> tm)\"\n  shows \"\\<C> \\<turnstile> es : (tn _> tm)\"\nproof -\n  fix e tn'\n  have \"b_e_type_checker \\<C> es (tn _> tm) \\<Longrightarrow>\n          \\<C> \\<turnstile> es : (tn _> tm)\"\n  and \"\\<And>tm' tm.\n       check \\<C> es tn' = tm' \\<Longrightarrow>\n       c_types_agree tm' tm \\<Longrightarrow>\n         \\<exists>tn. c_types_agree tn' tn \\<and> \\<C> \\<turnstile> es : (tn _> tm)\"\n  and \"\\<And>tm' tm.\n       check_single \\<C> e tn' = tm' \\<Longrightarrow>\n       c_types_agree tm' tm \\<Longrightarrow>\n       tn' \\<noteq> Bot \\<Longrightarrow>\n       tm' \\<noteq> Bot \\<Longrightarrow>\n         \\<exists>tn. c_types_agree tn' tn \\<and> \\<C> \\<turnstile> [e] : (tn _> tm)\"\n  proof (induction rule: b_e_type_checker_check_check_single.induct)\n    case (1 \\<C> es tn' tm)\n    thus ?case\n      by simp\n  next\n    case (2 \\<C> es' ts)\n    show ?case\n    proof (cases es')\n      case Nil\n      thus ?thesis\n        using 2(5,6)\n        by (simp add: b_e_type_empty)\n    next\n      case (Cons e es)\n        thus ?thesis\n        proof (cases ts)\n        case (TopType x1)\n        have check_expand:\"check \\<C> es (check_single \\<C> e ts) = tm'\"\n          using 2(5,6) TopType Cons\n          by simp\n        obtain ts' where ts'_def:\"check_single \\<C> e ts = ts'\"\n          by blast\n        obtain t_int where t_int_def:\"\\<C> \\<turnstile> es : (t_int _> tm)\"\n                                     \"c_types_agree ts' t_int\"\n          using 2(2)[OF Cons TopType check_expand 2(6)] ts'_def\n          by blast\n        obtain t_int' where \"c_types_agree ts t_int'\" \"\\<C> \\<turnstile> [e] : (t_int' _> t_int)\"\n          using 2(1)[OF Cons _ ts'_def] TopType c_types_agree.simps(3) t_int_def(2)\n          by blast\n        thus ?thesis\n          using t_int_def(1) b_e_type_comp_conc Cons\n          by fastforce\n      next\n        case (Type x2)\n        have check_expand:\"check \\<C> es (check_single \\<C> e ts) = tm'\"\n          using 2(5,6) Type Cons\n          by simp\n        obtain ts' where ts'_def:\"check_single \\<C> e ts = ts'\"\n          by blast\n        obtain t_int where t_int_def:\"\\<C> \\<turnstile> es : (t_int _> tm)\"\n                                     \"c_types_agree ts' t_int\"\n          using 2(4)[OF Cons Type check_expand 2(6)] ts'_def\n          by blast\n        obtain t_int' where \"c_types_agree ts t_int'\" \"\\<C> \\<turnstile> [e] : (t_int' _> t_int)\"\n          using 2(3)[OF Cons _ ts'_def] Type c_types_agree.simps(3) t_int_def(2)\n          by blast\n        thus ?thesis\n          using t_int_def(1) b_e_type_comp_conc Cons\n          by fastforce\n      next\n        case Bot\n        then show ?thesis\n          using 2(5,6) Cons\n          by auto\n      qed\n    qed\n  next\n    case (3 \\<C> v ts)\n    hence \"type_update ts [] (Type [typeof v]) = tm'\"\n      by simp\n    moreover\n    have \"\\<C> \\<turnstile> [C v] : ([] _> [typeof v])\"\n      using b_e_typing.intros(1)\n      by blast\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 3(3,4,2)]\n      by (metis list.simps(8) to_ct_list_def)\n  next\n    case (4 \\<C> t op ts)\n    hence \"unop_t_agree op t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_unop_testop_cvtop 4\n      by fastforce\n  next\n    case (5 \\<C> t op ts)\n    hence \"binop_t_agree op t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_binop_relop 5\n      by fastforce\n  next\n    case (6 \\<C> t op ts)\n    hence \"is_int_t t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_unop_testop_cvtop 6\n      by fastforce\n  next\n    case (7 \\<C> t op ts)\n    hence \"relop_t_agree op t\"\n      by (simp, meson)\n    thus ?case\n      using b_e_check_single_sound_binop_relop 7\n      by fastforce\n  next\n    case (8 \\<C> t1 t2 sx ts)\n    hence \"convert_cond t1 t2 sx\"\n      by (simp del: convert_cond.simps, meson)\n    thus ?case\n      using b_e_check_single_sound_unop_testop_cvtop 8\n      by fastforce\n  next\n    case (9 \\<C> t1 t2 sx ts)\n    hence \"t1 \\<noteq> t2 \\<and>  t_length t1 = t_length t2 \\<and> sx = None\"\n      by (simp, presburger)\n    thus ?case\n      using b_e_check_single_sound_unop_testop_cvtop 9\n      by fastforce\n  next\n    case (10 \\<C> ts)\n    thus ?case\n      using b_e_typing.intros(8) c_types_agree_not_bot_exists\n      by blast\n  next\n    case (11 \\<C> ts)\n    thus ?case\n      using b_e_typing.intros(9,32)\n      by fastforce\n  next\n    case (12 \\<C> ts)\n    thus ?case\n    proof (cases ts)\n      case (TopType x1)\n      thus ?thesis\n        proof (cases x1 rule: List.rev_cases)\n          case Nil\n          have \"\\<C> \\<turnstile> [Drop] : (tm@[T_i32] _> tm)\"\n            using b_e_typing.intros(10,32)\n            by fastforce\n          thus ?thesis\n            using c_types_agree_top1 Nil TopType\n            by fastforce\n        next\n          case (snoc ys y)\n            hence temp1:\"(consume (TopType (ys@[y])) [TAny]) = tm'\"\n              using 12 TopType type_update_empty\n              by (metis check_single.simps(10))\n            hence temp2:\"c_types_agree (TopType ys) tm\"\n              using consume_top_geq[OF temp1] 12(2,3,4)\n              by (metis Suc_leI add_diff_cancel_right' append_eq_conv_conj consume.simps(2)\n                        ct_suffix_def length_Cons length_append list.size(3) trans_le_add2\n                        zero_less_Suc)\n            obtain t where \"ct_list_compat [y] (to_ct_list [t])\"\n              using ct_list_compat_exists\n              unfolding ct_list_compat_def to_ct_list_def list_all2_map2\n              by (metis list_all2_Cons1 list_all2_Nil)\n            hence \"c_types_agree ts (tm@[t])\"\n              using temp2 ct_suffix_extend_ct_list_compat snoc TopType\n              by (simp add: to_ct_list_def)\n            thus ?thesis\n              using b_e_typing.intros(10,32)\n              by fastforce\n        qed\n    next\n      case (Type x2)\n      thus ?thesis\n      proof (cases x2 rule: List.rev_cases)\n        case Nil\n        hence \"(consume (Type []) [TAny]) = tm'\"\n          using 12 Type type_update_empty\n          by fastforce\n        thus ?thesis\n          using 12(4) ct_list_compat_def ct_suffix_def to_ct_list_def\n          by simp\n      next\n        case (snoc ys y)\n            hence temp1:\"(consume (Type (ys@[y])) [TAny]) = tm'\"\n              using 12 Type type_update_empty\n              by (metis check_single.simps(10))\n            hence temp2:\"c_types_agree (Type ys) tm\"\n              using 12(2,3,4) ct_suffix_def\n              by (simp, metis One_nat_def butlast_conv_take butlast_snoc c_types_agree.simps(1)\n                              length_Cons list.size(3))\n            obtain t where \"ct_list_compat [TSome y] (to_ct_list [t])\"\n              using ct_list_compat_exists\n              unfolding ct_list_compat_def to_ct_list_def list_all2_map2\n              by (metis list_all2_Cons1 list_all2_Nil)\n            hence \"c_types_agree ts (tm@[t])\"\n              using temp2 ct_suffix_extend_ct_list_compat snoc Type\n              by (simp add: ct_list_compat_def to_ct_list_def)\n            thus ?thesis\n              using b_e_typing.intros(10,32)\n              by fastforce\n      qed\n    qed simp\n  next\n    case (13 \\<C> ts)\n    thus ?case\n    proof (cases ts)\n      case (TopType x1)\n      consider\n          (1) \"length x1 = 0\"\n        | (2) \"length x1 = 1\"\n        | (3) \"length x1 = 2\"\n        | (4) \"length x1 \\<ge> 3\"\n        by linarith\n      thus ?thesis\n      proof (cases)\n        case 1\n        hence \"tm' = TopType [TAny]\"\n          using TopType 13\n          by simp\n        then obtain t'' tm'' where tm_def:\"tm = tm''@[t'']\"\n          using 13(2) ct_suffix_def\n          by (simp, metis Nil_is_append_conv append_butlast_last_id checker_type.inject(1)\n                          ct_prefixI ct_prefix_nil(2) produce.simps(1) produce_nil)\n        have \"\\<C> \\<turnstile> [Select] : ([t'',t'',T_i32] _> [t''])\"\n          using b_e_typing.intros(11)\n          by blast\n        thus ?thesis\n          using TopType 13 1 tm_def b_e_typing.intros(32) c_types_agree.simps(2) c_types_agree_top1\n          by fastforce\n      next\n        case 2\n        have \"type_update_select (TopType x1) = tm'\"\n          using 13 TopType\n          unfolding check_single.simps\n          by simp\n        hence x1_def:\"ct_list_compat x1 [TSome T_i32]\" \"tm' = TopType [TAny]\"\n          using type_update_select_length1[OF _ 2 13(4)]\n          by simp_all\n        then obtain t'' tm'' where tm_def:\"tm = tm''@[t'']\"\n          using 13(2) ct_suffix_def\n          by (metis Nil_is_append_conv append_butlast_last_id c_types_agree.simps(2) ct_prefixI\n                    ct_prefix_nil(2) list.simps(8) to_ct_list_def)\n        have \"c_types_agree (TopType x1) ((tm''@[t'',t''])@[T_i32])\"\n          using x1_def(1)\n          by (metis c_types_agree_top2 list.simps(8,9) to_ct_list_def)\n        thus ?thesis\n          using TopType b_e_typing.intros(11,32) tm_def\n          by auto\n      next\n        case 3\n        have \"type_update_select (TopType x1) = tm'\"\n          using 13 TopType\n          unfolding check_single.simps\n          by simp\n        then obtain ct1 ct2 where x1_def:\"x1 = [ct1, ct2]\"\n                                         \"ct_compat ct2 (TSome T_i32)\"\n                                         \"tm' = TopType [ct1]\"\n          using type_update_select_length2[OF _ 3 13(4)]\n          by blast\n        then obtain t'' tm'' where tm_def:\"tm = tm''@[t'']\"\n                                          \"ct_list_compat [ct1] [(TSome t'')]\"\n          using 13(2) c_types_agree_imp_ct_list_compat[of \"[ct1]\" tm]\n          by (metis append_Nil2 append_butlast_last_id append_eq_append_conv_if append_eq_conv_conj\n                    ct_list_compat_length diff_Suc_1 length_Cons length_butlast length_map\n                    list.simps(8,9) list.size(3) nat.distinct(2) to_ct_list_def)\n        hence \"ct_list_compat x1 (to_ct_list [ t'', T_i32])\"\n          using x1_def(1,2)\n          unfolding ct_list_compat_def to_ct_list_def\n          by fastforce\n        hence \"c_types_agree (TopType x1) ((tm''@[t''])@[t'',T_i32])\"\n          using c_types_agree_top2\n          by blast\n        thus ?thesis\n          using TopType b_e_typing.intros(11,32) tm_def\n          by auto\n      next\n        case 4\n        then obtain nat where nat_def:\"length x1 = Suc (Suc (Suc nat))\"\n          by (metis add_eq_if diff_Suc_1 le_Suc_ex numeral_3_eq_3 nat.distinct(2))\n        hence tm'_def:\"type_update_select (TopType x1) = tm'\"\n          using 13 TopType\n          by simp\n        then obtain tm_int where \"(select_return_top x1\n                                    (x1 ! (length x1 - 2))\n                                    (x1 ! (length x1 - 3))) = tm_int\"\n                                 \"tm_int \\<noteq> Bot\"\n          using nat_def 13(4)\n          unfolding type_update_select.simps\n          by fastforce\n        then obtain x2 where x2_def:\"(select_return_top x1\n                                       (x1 ! (length x1 - 2))\n                                       (x1 ! (length x1 - 3))) = TopType x2\"\n          using select_return_top_exists\n          by fastforce\n        have \"ct_suffix x1 [TAny, TAny, TSome T_i32] \\<or> ct_suffix [TAny, TAny, TSome T_i32] x1\"\n          using tm'_def nat_def 13(4)\n          by (simp, metis (full_types) produce.simps(6))\n        hence tm'_eq:\"tm' = TopType x2\"\n          using tm'_def nat_def 13(4) x2_def\n          by force\n        then obtain cts' ct1 ct2 ct3 where cts'_def:\"x1 = cts'@[ct1, ct2, ct3]\"\n                                                    \"ct_compat ct3 (TSome T_i32)\"\n          using type_update_select_length3 tm'_def 4\n          by blast\n        then obtain c' cm' where tm_def:\"tm = cm'@[c']\"\n                                        \"ct_suffix cts' (to_ct_list cm')\"\n                                        \"ct_compat (x1 ! (length x1 - 2)) (TSome c')\"\n                                        \"ct_compat (x1 ! (length x1 - 3)) (TSome c')\"\n          using select_return_top_ct_compat[OF x2_def 4] tm'_eq 4 13(2)\n          by fastforce\n        then obtain as bs where cm'_def:\"cm' = as@bs\"\n                                        \"ct_list_compat (to_ct_list bs) cts'\"\n          using ct_list_compat_cons_ct_list1 ct_list_compat_ts_conv_eq\n          by (metis ct_suffix_def to_ct_list_append(2))\n        hence \"ct_compat ct1 (TSome c')\"\n              \"ct_compat ct2 (TSome c')\"\n          using cts'_def tm_def\n          apply simp_all\n          apply (metis append.assoc append_Cons append_Nil length_append_singleton nth_append_length)\n          done\n        hence \"c_types_agree ts (cm'@[c',c',T_i32])\"\n          using c_types_agree_top2[of _ _ as] cm'_def(1) TopType\n                ct_list_compat_concat[OF ct_list_compat_commute[OF cm'_def(2)]] cts'_def\n          unfolding to_ct_list_def ct_list_compat_def\n          by fastforce\n        thus ?thesis\n          using b_e_typing.intros(11,32) tm_def\n          by auto\n      qed\n    next\n      (* TODO: refactor *)\n      case (Type x2)\n      hence x2_cond:\"(length x2 \\<ge> 3 \\<and> (x2!(length x2-2)) = (x2!(length x2-3)))\"\n        using 13\n        by (simp, meson)\n      hence tm'_def:\"consume (Type x2) [TAny, TSome T_i32] = tm'\"\n        using 13 Type\n        by simp\n      obtain ts' ts'' where cts_def:\"x2 = ts'@ ts''\" \"length ts'' = 3\"\n        using x2_cond\n        by (metis append_take_drop_id diff_diff_cancel length_drop)\n      then obtain t1 ts''2 where \"ts'' = t1#ts''2\" \"length ts''2 = Suc (Suc 0)\"\n        using List.length_Suc_conv[of ts' \"Suc (Suc 0)\"]\n        by (metis length_Suc_conv numeral_3_eq_3)\n      then obtain t2 t3 where \"ts'' = [t1,t2,t3]\"\n        using List.length_Suc_conv[of ts''2 \"Suc 0\"]\n        by (metis length_0_conv length_Suc_conv)\n      hence cts_def2:\"x2 = ts'@ [t1,t2,t3]\"\n        using cts_def\n        by simp\n      have ts'_suffix:\"ct_suffix [TAny, TSome T_i32] (to_ct_list (ts' @ [t1, t2, t3]))\"\n        using tm'_def 13(4)\n        by (simp, metis cts_def2)\n      hence tm'_def:\"tm' = Type (ts'@[t1])\"\n        using tm'_def 13(4) cts_def2\n        by simp\n      obtain as bs where \"(to_ct_list (ts' @ [t1])) @ (to_ct_list ([t2, t3])) = as@bs\"\n                         \"ct_list_compat bs [TAny, TSome T_i32]\"\n        using ts'_suffix\n        unfolding ct_suffix_def to_ct_list_def\n        by fastforce\n      hence \"t3 = T_i32\"\n        unfolding to_ct_list_def ct_list_compat_def\n        by (metis (no_types, lifting) Nil_is_map_conv append_eq_append_conv ct_compat.simps(1)\n                  length_Cons list.sel(1,3) list.simps(9) list_all2_Cons2 list_all2_lengthD)\n      moreover\n      have \"t1 = t2\"\n        using x2_cond cts_def2\n        by (simp, metis append.left_neutral append_Cons append_assoc length_append_singleton\n                        nth_append_length)\n      ultimately\n      have \"c_types_agree (Type x2) ((ts'@[t1,t1])@[T_i32])\"\n        using cts_def2\n        by simp\n      thus ?thesis\n        using b_e_typing.intros(11,32) Type tm'_def 13(2)\n        by fastforce\n    qed simp\n  next\n    case (14 \\<C> tn'' tm'' es ts)\n    hence \"type_update ts (to_ct_list tn'') (Type tm'') = tm'\"\n      by auto\n    moreover\n    have \"(b_e_type_checker (\\<C>\\<lparr>label := ([tm''] @ (label \\<C>))\\<rparr>) es (tn'' _> tm''))\"\n      using 14\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Block (tn'' _> tm'') es] : (tn'' _> tm'')\"\n      using b_e_typing.intros(12)[OF _ 14(1)]\n      by blast\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 14(4,5,3)]\n      by blast\n  next\n    case (15 \\<C> tn'' tm'' es ts)\n    hence \"type_update ts (to_ct_list tn'') (Type tm'') = tm'\"\n      by auto\n    moreover\n    have \"(b_e_type_checker (\\<C>\\<lparr>label := ([tn''] @ (label \\<C>))\\<rparr>) es (tn'' _> tm''))\"\n      using 15\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Loop (tn'' _> tm'') es] : (tn'' _> tm'')\"\n      using b_e_typing.intros(13)[OF _ 15(1)]\n      by blast\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 15(4,5,3)]\n      by blast\n  next\n    case (16 \\<C> tn'' tm'' es1 es2 ts)\n    hence \"type_update ts (to_ct_list (tn''@[T_i32])) (Type tm'') = tm'\"\n      by auto\n    moreover\n    have \"(b_e_type_checker (\\<C>\\<lparr>label := ([tm''] @ (label \\<C>))\\<rparr>) es1 (tn'' _> tm''))\"\n         \"(b_e_type_checker (\\<C>\\<lparr>label := ([tm''] @ (label \\<C>))\\<rparr>) es2 (tn'' _> tm''))\"\n      using 16\n      by (simp, meson)+\n    hence \"\\<C> \\<turnstile> [If (tn'' _> tm'') es1 es2] : (tn''@[T_i32] _> tm'')\"\n      using b_e_typing.intros(14)[OF _ 16(1,2)]\n      by blast\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 16(5,6,4)]\n      by blast\n  next\n    case (17 \\<C> i ts)\n    hence \"type_update ts (to_ct_list ((label \\<C>)!i)) (TopType []) = tm'\"\n      by auto\n    moreover\n    have \"i < length (label \\<C>)\"\n      using 17\n      by (simp, meson)\n    ultimately\n    show ?case\n      using b_e_check_single_top_not_bot_sound[OF _ 17(3,4)]\n            b_e_typing.intros(15)\n            b_e_typing.intros(32)\n      by (metis suffix_def)\n  next\n    case (18 \\<C> i ts)\n    hence \"type_update ts (to_ct_list ((label \\<C>)!i @ [T_i32])) (Type ((label \\<C>)!i)) = tm'\"\n      by auto\n    moreover\n    have \"i < length (label \\<C>)\"\n      using 18\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Br_if i] : ((label \\<C>)!i @ [T_i32] _> (label \\<C>)!i)\"\n      using b_e_typing.intros(16)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 18(3,4,2)]\n      by fastforce\n  next\n    case (19 \\<C> \"is\" i ts)\n    then obtain tls where tls_def:\"(same_lab (is@[i]) (label \\<C>)) = Some tls\"\n      by fastforce\n    hence \"type_update ts (to_ct_list (tls @ [T_i32])) (TopType []) = tm'\"\n      using 19\n      by simp\n    thus ?case\n      using b_e_check_single_top_not_bot_sound[OF _ 19(3,4)]\n            b_e_typing.intros(17)[OF same_lab_conv_list_all[OF tls_def]]\n            b_e_typing.intros(32)\n      by (metis suffix_def)\n  next\n    case (20 \\<C> ts)\n    then obtain ts_r where \"(return \\<C>) = Some ts_r\"\n      by fastforce\n    moreover\n    hence \"type_update ts (to_ct_list ts_r) (TopType []) = tm'\"\n      using 20\n      by simp\n    ultimately\n    show ?case\n      using b_e_check_single_top_not_bot_sound[OF _ 20(3,4)]\n            b_e_typing.intros(18,32)\n      by (metis suffix_def)\n  next\n    case (21 \\<C> i ts)\n    obtain tn'' tm'' where func_def:\"(func_t \\<C>)!i = (tn'' _> tm'')\"\n      using tf.exhaust\n      by blast\n    hence \"type_update ts (to_ct_list tn'') (Type tm'') = tm'\"\n      using 21\n      by auto\n    moreover\n    have \"i < length (func_t \\<C>)\"\n      using 21\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Call i] : (tn'' _> tm'')\"\n      using b_e_typing.intros(19) func_def\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 21(3,4,2)]\n      by fastforce\n  next\n    case (22 \\<C> i ts)\n    obtain tn'' tm'' where type_def:\"(types_t \\<C>)!i = (tn'' _> tm'')\"\n      using tf.exhaust\n      by blast\n    hence \"type_update ts (to_ct_list (tn''@[T_i32])) (Type tm'') = tm'\"\n      using 22\n      by auto\n    moreover\n    have \"length (table \\<C>) \\<ge> 1  \\<and> i < length (types_t \\<C>)\"\n      using 22\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Call_indirect i] : (tn''@[T_i32] _> tm'')\"\n      using b_e_typing.intros(20) type_def\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 22(3,4,2)]\n      by fastforce\n  next\n    case (23 \\<C> i ts)\n    hence \"type_update ts [] (Type [(local \\<C>)!i]) = tm'\"\n      by auto\n    moreover\n    have \"i < length (local \\<C>)\"\n      using 23\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Get_local i] : ([] _> [(local \\<C>)!i])\"\n      using b_e_typing.intros(21)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 23(3,4,2)]\n      unfolding to_ct_list_def\n      by (metis list.map_disc_iff)\n  next\n    case (24 \\<C> i ts)\n    hence \"type_update ts (to_ct_list [(local \\<C>)!i]) (Type []) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"i < length (local \\<C>)\"\n      using 24\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Set_local i] : ([(local \\<C>)!i] _> [])\"\n      using b_e_typing.intros(22)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 24(3,4,2)]\n      by fastforce\n  next\n    case (25 \\<C> i ts)\n    hence \"type_update ts (to_ct_list [(local \\<C>)!i]) (Type [(local \\<C>)!i]) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"i < length (local \\<C>)\"\n      using 25\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Tee_local i] : ([(local \\<C>)!i] _> [(local \\<C>)!i])\"\n      using b_e_typing.intros(23)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 25(3,4,2)]\n      by fastforce\n  next\n    case (26 \\<C> i ts)\n    hence \"type_update ts [] (Type [tg_t ((global \\<C>)!i)]) = tm'\"\n      by auto\n    moreover\n    have \"i < length (global \\<C>)\"\n      using 26\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Get_global i] : ([] _> [tg_t ((global \\<C>)!i)])\"\n      using b_e_typing.intros(24)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 26(3,4,2)]\n      unfolding to_ct_list_def\n      by (metis list.map_disc_iff)\n  next\n    case (27 \\<C> i ts)\n    hence \"type_update ts (to_ct_list [tg_t ((global \\<C>)!i)]) (Type []) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"i < length (global \\<C>) \\<and> is_mut (global \\<C> ! i)\"\n      using 27\n      by (simp, meson)\n    then obtain t where \"(global \\<C> ! i) = \\<lparr>tg_mut = T_mut, tg_t = t\\<rparr>\" \"i < length (global \\<C>)\"\n      unfolding is_mut_def\n      by (cases \"global \\<C> ! i\", auto)\n    hence \"\\<C> \\<turnstile> [Set_global i] : ([tg_t (global \\<C> ! i)] _> [])\"\n      using b_e_typing.intros(25)[of i \\<C> \"tg_t (global \\<C> ! i)\"]\n      unfolding is_mut_def tg_t_def\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 27(3,4,2)]\n      by fastforce\n  next\n    case (28 \\<C> t tp_sx a off ts)\n    hence \"type_update ts (to_ct_list [T_i32]) (Type [t]) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"length (memory \\<C>) \\<ge> 1  \\<and> load_store_t_bounds a (option_projl tp_sx) t\"\n      using 28\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Load t tp_sx a off] : ([T_i32] _> [t])\"\n      using b_e_typing.intros(26)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 28(3,4,2)]\n      by fastforce\n  next\n    case (29 \\<C> t tp a off ts)\n    hence \"type_update ts (to_ct_list [T_i32,t]) (Type []) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"length (memory \\<C>) \\<ge> 1  \\<and> load_store_t_bounds a tp t\"\n      using 29\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Store t tp a off] : ([T_i32,t] _> [])\"\n      using b_e_typing.intros(27)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 29(3,4,2)]\n      by fastforce\n  next\n    case (30 \\<C> ts)\n    hence \"type_update ts [] (Type [T_i32]) = tm'\"\n      by auto\n    moreover\n    have \"length (memory \\<C>) \\<ge> 1 \" \n      using 30\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Current_memory] : ([] _> [T_i32])\"\n      using b_e_typing.intros(28)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 30(3,4,2)]\n      unfolding to_ct_list_def\n      by (metis list.map_disc_iff)\n  next\n    case (31 \\<C> ts)\n    hence \"type_update ts (to_ct_list [T_i32]) (Type [T_i32]) = tm'\"\n      unfolding to_ct_list_def\n      by auto\n    moreover\n    have \"length (memory \\<C>) \\<ge> 1 \" \n      using 31\n      by (simp, meson)\n    hence \"\\<C> \\<turnstile> [Grow_memory] : ([T_i32] _> [T_i32])\"\n      using b_e_typing.intros(29)\n      by fastforce\n    ultimately\n    show ?case\n      using b_e_check_single_type_not_bot_sound[OF _ 31(3,4,2)]\n      by fastforce\n  qed\n  thus ?thesis\n    using assms\n    by simp\nqed\n\nsubsection {* Completeness *}\n\nlemma check_single_imp:\n  assumes \"check_single \\<C> e ctn = ctm\"\n          \"ctm \\<noteq> Bot\"\n  shows \"check_single \\<C> e = id\n         \\<or> check_single \\<C> e = (\\<lambda>ctn. type_update_select ctn)\n         \\<or> (\\<exists>cons prods. (check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)))\"\n  using assms\n  apply (cases rule: check_single.cases[of \"(\\<C>, e, ctn)\"])\n  apply (fastforce split: if_splits option.splits tf.splits)+\n  done\n\nlemma check_equiv_fold:\n  \"check \\<C> es ts = foldl (\\<lambda> ts e. (case ts of Bot \\<Rightarrow> Bot | _ \\<Rightarrow> check_single \\<C> e ts)) ts es\"\nproof (induction es arbitrary: ts)\n  case Nil\n  thus ?case\n    by simp\nnext\n  case (Cons e es)\n  obtain ts' where ts'_def:\"check \\<C> (e # es) ts = ts'\"\n    by blast\n  show ?case\n  proof (cases \"ts = Bot\")\n    case True\n    thus ?thesis\n      using ts'_def\n      by (induction es, simp_all)\n  next\n    case False\n    thus ?thesis\n      using ts'_def Cons\n      by (cases ts, simp_all)\n  qed\nqed\n\nlemma check_neq_bot_snoc:\n  assumes \"check \\<C> (es@[e]) ts \\<noteq> Bot\"\n  shows \"check \\<C> es ts \\<noteq> Bot\"\n  using assms\nproof (induction es arbitrary: ts)\n  case Nil\n  thus ?case\n    by (cases ts, simp_all)\nnext\n  case (Cons a es)\n  thus ?case\n    by (cases ts, simp_all)\nqed\n\nlemma check_unfold_snoc:\n  assumes \"check \\<C> es ts \\<noteq> Bot\"\n  shows \"check \\<C> (es@[e]) ts = check_single \\<C> e (check \\<C> es ts)\"\nproof -\n  obtain f where f_def:\"f = (\\<lambda> e ts. (case ts of Bot \\<Rightarrow> Bot | _ \\<Rightarrow> check_single \\<C> e ts))\"\n    by blast\n  have f_simp:\"\\<And>ts. ts \\<noteq> Bot \\<Longrightarrow> (f e ts = check_single \\<C> e ts)\"\n  proof -\n    fix ts\n    show \"ts \\<noteq> Bot \\<Longrightarrow> (f e ts = check_single \\<C> e ts)\"\n      using f_def\n      by (cases ts, simp_all)\n  qed\n  have \"check \\<C> (es@[e]) ts = foldl (\\<lambda> ts e. (case ts of Bot \\<Rightarrow> Bot | _ \\<Rightarrow> check_single \\<C> e ts)) ts (es@[e])\"\n    using check_equiv_fold\n    by simp\n  also\n  have \"... = foldr (\\<lambda> e ts. (case ts of Bot \\<Rightarrow> Bot | _ \\<Rightarrow> check_single \\<C> e ts)) (rev (es@[e])) ts\"\n    using foldl_conv_foldr\n    by fastforce\n  also\n  have \"... = f e (foldr (\\<lambda> e ts. (case ts of Bot \\<Rightarrow> Bot | _ \\<Rightarrow> check_single \\<C> e ts)) (rev es) ts)\"\n    using f_def\n    by simp\n  also\n  have \"... = f e (check \\<C> es ts)\"\n    using foldr_conv_foldl[of _ \"(rev es)\" ts] rev_rev_ident[of es] check_equiv_fold\n    by simp\n  also\n  have \"... = check_single \\<C> e (check \\<C> es ts)\"\n    using assms f_simp\n    by simp\n  finally\n  show ?thesis .\nqed\n\nlemma check_single_imp_weakening:\n  assumes \"check_single \\<C> e (Type t1s) = ctm\"\n          \"ctm \\<noteq> Bot\"\n          \"c_types_agree ctn t1s\"\n          \"c_types_agree ctm t2s\"\n  shows \"\\<exists>ctm'. check_single \\<C> e ctn = ctm' \\<and> c_types_agree ctm' t2s\"\nproof -\n  consider (1) \"check_single \\<C> e = id\" \n         | (2) \"check_single \\<C> e = (\\<lambda>ctn. type_update_select ctn)\"\n         | (3) \"(\\<exists>cons prods. (check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)))\"\n    using check_single_imp assms\n    by blast\n  thus ?thesis\n  proof (cases)\n    case 1\n    thus ?thesis\n      using assms(1,3,4)\n      by fastforce\n  next\n    (* TODO: better proof *)\n    case 2\n    note outer_2 = 2\n    hence t1s_cond:\"(length t1s \\<ge> 3 \\<and> (t1s!(length t1s-2)) = (t1s!(length t1s-3)))\"\n      using assms(1,2)\n      by (simp, meson)\n    hence ctm_def:\"ctm = consume (Type t1s) [TAny, TSome T_i32]\"\n      using assms(1,2) 2\n      by simp\n    then obtain c_t where c_t_def:\"ctm = Type c_t\"\n      using assms(2)\n      by (meson consume.simps(1))\n    hence t2s_eq:\"t2s = c_t\"\n      using assms(4)\n      by simp\n    hence t2s_len:\"length t2s > 0\"\n      using t1s_cond ctm_def c_t_def assms(2)\n      by (metis Suc_leI Suc_n_not_le_n checker_type.inject(2) consume.simps(1)\n                diff_is_0_eq dual_order.trans length_0_conv length_Cons length_greater_0_conv\n                nat.simps(3) numeral_3_eq_3 take_eq_Nil)\n    have t1s_suffix_full:\"ct_suffix [TAny, TSome T_i32] (to_ct_list t1s)\"\n      using assms(2) ctm_def ct_suffix_less\n      by (metis consume.simps(1))\n    hence t1s_suffix:\"ct_suffix [TSome T_i32] (to_ct_list t1s)\"\n      using assms(2) ctm_def ct_suffix_less\n      by (metis append_butlast_last_id last.simps list.distinct(1))\n    obtain t t1s' where t1s_suffix2:\"t1s = t1s'@[t,t,T_i32]\"\n      using type_update_select_type_length3 assms(1) c_t_def outer_2\n      by fastforce\n    hence t2s_def:\"t2s = t1s'@[t]\"\n      using ctm_def c_t_def t2s_eq t1s_suffix assms(2) t1s_suffix_full\n      by simp\n    show ?thesis\n      using assms(1,3,4)\n    proof (cases ctn)\n      case (TopType x1)\n      consider\n          (1) \"length x1 = 0\"\n        | (2) \"length x1 = 1\"\n        | (3) \"length x1 = 2\"\n        | (4) \"length x1 \\<ge> 3\"\n        by linarith\n      thus ?thesis\n      proof (cases)\n        case 1\n        hence \"check_single \\<C> e ctn = TopType [TAny]\"\n          using 2 TopType\n          by simp\n        thus ?thesis\n          using ct_suffix_singleton to_ct_list_def t2s_len\n          by auto\n      next\n        case 2\n        hence \"ct_suffix [TSome T_i32] x1\"\n          using assms(3) TopType ct_suffix_imp_ct_list_compat ct_suffix_shared t1s_suffix\n          by (metis One_nat_def append_Nil c_types_agree.simps(2) ct_list_compat_commute ct_suffix_def\n                    diff_self_eq_0 drop_0 length_Cons list.size(3))\n        hence \"check_single \\<C> e ctn = TopType [TAny]\"\n          using outer_2 TopType 2\n          by simp\n        thus ?thesis\n          using t2s_len ct_suffix_singleton\n          by (simp add: to_ct_list_def)\n      next\n        case 3\n        have \"ct_list_compat (to_ct_list t1s) (to_ct_list (t1s' @ [t, t, T_i32]))\"\n          using t1s_suffix2\n          by (simp add: ct_list_compat_ts_conv_eq)\n        hence temp1:\"to_ct_list t1s = (to_ct_list (t1s' @ [t])) @ (to_ct_list [t, T_i32])\"\n          using t1s_suffix2 to_ct_list_def\n          by simp\n        hence \"ct_suffix (to_ct_list [t, T_i32]) (to_ct_list t1s)\"\n          using ct_suffix_def[of \"(to_ct_list [t, T_i32])\" \"(to_ct_list t1s)\"]\n          by (simp add: ct_suffix_cons_it)\n        hence \"ct_suffix (to_ct_list [t, T_i32]) x1\"\n          using assms(3) TopType 3\n          by (simp, metis temp1 append_Nil ct_suffix_cons2 ct_suffix_def length_Cons length_map\n                          list.size(3) numeral_2_eq_2 to_ct_list_def)\n        hence temp3:\"ct_list_compat (to_ct_list [t, T_i32]) x1\"\n          using 3 ct_suffix_imp_ct_list_compat\n          unfolding to_ct_list_def\n          by (metis Suc_leI ct_list_compat_commute diff_is_0_eq drop_0 length_Cons length_map lessI\n                    list.size(3) numeral_2_eq_2)\n        hence temp4:\"ct_suffix [TSome T_i32] x1\" \n          using ct_suffix_less[of \"[TSome t]\" \"[TSome T_i32]\" x1]\n                ct_suffix_extend_ct_list_compat[of \"[]\" \"[]\"] ct_suffix_nil\n          unfolding to_ct_list_def\n          by fastforce\n        hence \"ct_suffix (take 1 x1) (to_ct_list [t])\"\n          using temp3 ct_suffix_nil ct_list_compat_commute ct_suffix_extend_ct_list_compat[of \"[]\" \"[]\" \"(take 1 x1)\" \"(to_ct_list [t])\"]\n          unfolding to_ct_list_def\n          by (simp, metis butlast.simps(2) butlast_conv_take ct_list_compat_take diff_Suc_1 length_Cons\n                          list.distinct(1) list.size(3))\n        thus ?thesis\n          using TopType 2 3 ct_suffix_nil temp3 temp4 t2s_def to_ct_list_def\n          apply (simp, safe)\n          apply (metis append.assoc ct_suffix_def)\n          done\n      next\n        case 4\n        then obtain nat where nat_def:\"length x1 = Suc (Suc (Suc nat))\"\n          by (metis add_eq_if diff_Suc_1 le_Suc_ex numeral_3_eq_3 nat.distinct(2))\n        obtain x1' x x' x'' where x1_split:\"x1 = x1'@[x,x',x'']\"\n        proof -\n          assume local_assms:\"(\\<And>x1' x x' x''. x1 = x1' @ [x, x', x''] \\<Longrightarrow> thesis)\"\n          obtain x1' x1'' where tn_split:\"x1 = x1'@x1''\"\n                               \"length x1'' = 3\"\n            using 4\n            by (metis append_take_drop_id diff_diff_cancel length_drop)\n          then obtain x x1''2 where \"x1'' = x#x1''2\" \"length x1''2 = Suc (Suc 0)\"\n            by (metis length_Suc_conv numeral_3_eq_3)\n          then obtain x' x'' where tn''_def:\"x1''= [x,x',x'']\"\n            using List.length_Suc_conv[of x1''2 \"Suc 0\"]\n            by (metis length_0_conv length_Suc_conv)\n          thus ?thesis\n            using tn_split local_assms\n            by simp\n        qed\n        hence a:\"ct_suffix (x1'@[x,x',x'']) (to_ct_list (t1s' @ [t, t, T_i32]))\"\n          using t1s_suffix2 assms(3) TopType\n          by simp\n        hence b:\"ct_suffix (x1'@[x,x']) (to_ct_list (t1s' @ [t, t])) \\<and> (ct_compat x'' (TSome T_i32))\"\n          using to_ct_list_def ct_suffix_unfold_one[of \"(x1'@[x,x'])\" \"x''\" \"to_ct_list (t1s' @ [t, t])\"]\n          by fastforce\n        hence c:\"ct_suffix (x1'@[x]) (to_ct_list (t1s' @ [t])) \\<and> (ct_compat x' (TSome t))\"\n          using to_ct_list_def ct_suffix_unfold_one[of \"(x1'@[x])\" \"x'\" \"to_ct_list (t1s' @ [t])\"]\n          by fastforce\n        hence d:\"ct_suffix x1' (to_ct_list t1s') \\<and> (ct_compat x (TSome t))\"\n          using to_ct_list_def ct_suffix_unfold_one[of \"(x1')\" \"x\" \"to_ct_list (t1s')\"]\n          by fastforce\n        have \"(take (length x1 - 3) x1) = x1'\"\n          using x1_split\n          by simp\n        have x'_ind:\"(x1!(length x1-2)) = x'\"\n          using x1_split List.nth_append_length[of \"x1' @ [x]\"]\n          by simp\n        have x_ind:\"(x1!(length x1-3)) = x\"\n          using x1_split\n          by simp\n        have \"ct_suffix [TSome T_i32] x1\"\n          using b x1_split ct_suffix_def ct_list_compat_def ct_suffixI[of x1 \"x1' @ [x, x']\"]\n          by simp\n        hence \"check_single \\<C> e (TopType x1) = (select_return_top x1 (x1!(length x1-2)) (x1!(length x1-3)))\"\n          using type_update_select_conv_select_return_top[OF _ 4]\n          unfolding 2\n          by blast\n        moreover\n        have \"... = (TopType (x1'@[x])) \\<or> ... = (TopType (x1'@[x']))\"\n          apply (cases x; cases x')\n          using x1_split 4 nat_def 2 x_ind x'_ind c d\n          by simp_all\n        moreover\n        have \"ct_suffix (x1'@[x]) (to_ct_list t2s)\"\n          by (simp add: c t2s_def)\n        moreover\n        have \"ct_suffix (x1'@[x']) (to_ct_list t2s)\"\n          using ct_suffix_unfold_one[symmetric, of x' \"(TSome t)\" x1' \"(to_ct_list t1s')\"] c d\n                t2s_def\n          unfolding to_ct_list_def\n          by fastforce\n        ultimately\n        show ?thesis\n          using TopType\n          by auto\n      qed\n    qed simp_all\n  next\n    case 3\n    then obtain cons prods where c_s_def:\"check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)\"\n      by blast\n    hence ctm_def:\"ctm = type_update (Type t1s) cons prods\"\n      using assms(1)\n      by fastforce\n    hence cons_suffix:\"ct_suffix cons (to_ct_list t1s)\"\n      using assms\n      by (simp, metis (full_types) produce.simps(6))\n    hence t_int_def:\"consume (Type t1s) cons = (Type (take (length t1s - length cons) t1s))\"\n      using ctm_def\n      by simp\n    hence ctm_def2:\"ctm = produce (Type (take (length t1s - length cons) t1s)) prods\"\n      using ctm_def\n      by simp\n    show ?thesis\n    proof (cases ctn)\n      case (TopType x1)\n      hence \"ct_suffix x1 (to_ct_list t1s)\"\n        using assms(3)\n        by simp\n      thus ?thesis\n        using assms(2) ctm_def2\n      proof (cases prods)\n        case (TopType x1)\n        thus ?thesis\n          using consume_c_types_agree[OF t_int_def assms(3)] ctm_def2 assms(4) c_s_def\n          by (metis c_types_agree.elims(2) produce.simps(3,4) type_update.simps)\n      next\n        case (Type x2)\n        hence ctm_def3:\"ctm = Type ((take (length t1s - length cons) t1s)@ x2)\"\n          using ctm_def2\n          by simp\n        have \"ct_suffix x1 cons \\<or> ct_suffix cons x1\"\n          using ct_suffix_shared assms(3) TopType cons_suffix\n          by auto\n        thus ?thesis\n        proof (rule disjE)\n          assume \"ct_suffix x1 cons\"\n          hence \"consume (TopType x1) cons = TopType []\"\n            by (simp add: ct_suffix_length)\n          hence \"check_single \\<C> e ctn = TopType (to_ct_list x2)\"\n            using c_s_def TopType Type\n            by simp\n          thus ?thesis\n            using TopType ctm_def3 assms(4) c_types_agree_top2 ct_list_compat_refl\n            by auto\n        next\n          assume \"ct_suffix cons x1\"\n          hence 4:\"consume (TopType x1) cons = TopType (take (length x1 - length cons ) x1)\"\n            by (simp add: ct_suffix_length)\n          hence 3:\"check_single \\<C> e ctn = TopType ((take (length x1 - length cons ) x1) @ to_ct_list x2)\"\n            using c_s_def TopType Type\n            by simp\n          have \"((take (length t1s - length cons ) t1s) @  x2) = t2s\"\n            using assms(4) ctm_def3\n            by simp\n          have \"c_types_agree (TopType (take (length x1 - length cons ) x1)) (take (length t1s - length cons) t1s)\"\n            using consume_c_types_agree[OF t_int_def assms(3)] 4 TopType\n            by simp\n          hence \"c_types_agree (TopType (take (length x1 - length cons ) x1 @ to_ct_list x2)) (take (length t1s - length cons) t1s @ x2)\"\n            unfolding c_types_agree.simps to_ct_list_def\n            by (simp add: ct_suffix_cons2 ct_suffix_cons_it ct_suffix_extend_ct_list_compat)\n          thus ?thesis\n            using ctm_def3 assms 3\n            by simp\n        qed\n      qed simp\n    next\n      case (Type x2)\n      thus ?thesis\n        using assms\n        by simp\n    next\n      case Bot\n      thus ?thesis\n        using assms\n        by simp\n    qed\n  qed\nqed\n\nlemma b_e_type_checker_compose:\n  assumes \"b_e_type_checker \\<C> es (t1s _> t2s)\"\n          \"b_e_type_checker \\<C> [e] (t2s _> t3s)\"\n  shows \"b_e_type_checker \\<C> (es @ [e]) (t1s _> t3s)\"\nproof -\n  have \"c_types_agree (check_single \\<C> e (Type t2s)) t3s\"\n    using assms(2)\n    by simp\n  then obtain ctm where ctm_def:\"check_single \\<C> e (Type t2s) = ctm\"\n                                \"c_types_agree ctm t3s\"\n                                \"ctm \\<noteq> Bot\"\n    by fastforce\n  have \"c_types_agree (check \\<C> es (Type t1s)) t2s\"\n    using assms(1)\n    by simp\n  then obtain ctn where ctn_def:\"check \\<C> es (Type t1s) = ctn\"\n                                \"c_types_agree ctn t2s\"\n                                \"ctn \\<noteq> Bot\"\n    by fastforce\n  thus ?thesis\n    using check_single_imp_weakening[OF ctm_def(1,3) ctn_def(2) ctm_def(2)]\n          check_unfold_snoc[of \\<C> es \"(Type t1s)\" e]\n    by simp\nqed\n\nlemma b_e_check_single_type_type:\n  assumes \"check_single \\<C> e xs = (Type tm)\"\n  shows \"\\<exists>tn. xs = (Type tn)\"\nproof -\n  consider (1) \"check_single \\<C> e = id\" \n         | (2) \"check_single \\<C> e = (\\<lambda>ctn. type_update_select ctn)\"\n         | (3) \"(\\<exists>cons prods. (check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)))\"\n    using check_single_imp assms\n    by blast\n  thus ?thesis\n  proof (cases)\n    case 1\n    thus ?thesis\n      using assms\n      by simp\n  next\n    case 2\n    note outer_2 = 2\n    thus ?thesis\n      using assms\n    proof (cases xs)\n      case (TopType x1)\n      consider\n          (1) \"length x1 = 0\"\n        | (2) \"length x1 = Suc 0\"\n        | (3) \"length x1 = Suc (Suc 0)\"\n        | (4) \"length x1 \\<ge> 3\"\n        by linarith\n      thus ?thesis\n      proof cases\n        case 1\n        thus ?thesis\n          using assms 2 TopType\n          by simp\n      next\n        case 2\n        thus ?thesis\n          using assms outer_2 TopType produce_type_type\n          by fastforce\n      next\n        case 3\n        thus ?thesis\n          using assms 2 TopType\n          by (simp, metis checker_type.distinct(1) checker_type.distinct(5))\n      next\n        case 4\n        then obtain nat where nat_def:\"length x1 = Suc (Suc (Suc nat))\"\n          by (metis add_eq_if diff_Suc_1 le_Suc_ex numeral_3_eq_3 nat.distinct(2))\n        thus ?thesis\n          using assms 2 TopType\n        proof -\n          {\n            assume a1: \"produce (if ct_suffix [TAny, TAny, TSome T_i32] x1 then TopType (take (length x1 - length [TAny, TAny, TSome T_i32]) x1) else if ct_suffix x1 [TAny, TAny, TSome T_i32] then TopType [] else Bot) (select_return_top x1 (x1 ! Suc nat) (x1 ! nat)) = Type tm\"\n            obtain tts :: \"checker_type \\<Rightarrow> t list\" where\n              f2: \"\\<forall>c. (\\<forall>ca ts. produce c ca \\<noteq> Type ts) \\<or> c = Type (tts c)\"\n              using produce_type_type by moura\n            then have f3: \"\\<And>ts. \\<not> ct_suffix [TAny, TAny, TSome T_i32] x1 \\<or> Type tm \\<noteq> Type ts\"\n              using a1 by fastforce\n            then have \"\\<And>ts. \\<not> ct_suffix x1 [TAny, TAny, TSome T_i32] \\<or> Type tm \\<noteq> Type ts\"\n              using f2 a1 by fastforce\n            then have False\n              using f3 a1 by fastforce\n          }\n          thus ?thesis\n            using assms 2 TopType nat_def\n            by simp\n        qed\n      qed\n    qed simp_all\n  next\n    case 3\n    then obtain cons prods where check_def:\"check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)\"\n      by blast\n    hence \"produce (consume xs cons) prods = (Type tm)\"\n      using assms(1)\n      by simp\n    thus ?thesis\n      using assms check_def consume_type_type produce_type_type\n      by blast\n  qed\nqed\n\nlemma b_e_check_single_weaken_type:\n  assumes \"check_single \\<C> e (Type tn) = (Type tm)\"\n  shows \"check_single \\<C> e (Type (ts@tn)) = Type (ts@tm)\"\nproof -\n  consider (1) \"check_single \\<C> e = id\" \n         | (2) \"check_single \\<C> e = (\\<lambda>ctn. type_update_select ctn)\"\n         | (3) \"(\\<exists>cons prods. (check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)))\"\n    using check_single_imp assms\n    by blast\n  thus ?thesis\n  proof (cases)\n    case 1\n    thus ?thesis\n      using assms(1)\n      by simp\n  next\n    case 2\n    hence cond:\"(length tn \\<ge> 3 \\<and> (tn!(length tn-2)) = (tn!(length tn-3)))\"\n      using assms\n      by (simp, metis checker_type.distinct(5))\n    hence \"consume (Type tn) [TAny, TSome T_i32] = (Type tm)\"\n      using assms 2\n      by simp\n    hence \"consume (Type (ts@tn)) [TAny, TSome T_i32] = (Type (ts@tm))\"\n      using consume_weaken_type\n      by blast\n    moreover\n    have \"(length (ts@tn) \\<ge> 3 \\<and> ((ts@tn)!(length (ts@tn)-2)) = ((ts@tn)!(length (ts@tn)-3)))\"\n      using cond\n      by (simp, metis add.commute add_leE nth_append_length_plus numeral_Bit1 numeral_One\n                      one_add_one ordered_cancel_comm_monoid_diff_class.diff_add_assoc2)\n    ultimately\n    show ?thesis\n      using 2\n      by simp\n  next\n    case 3\n    then obtain cons prods where check_def:\"check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)\"\n      by blast\n    hence \"produce (consume (Type tn) cons) prods = (Type tm)\"\n      using assms(1)\n      by simp\n    then obtain t_int where t_int_def:\"consume (Type tn) cons = (Type t_int)\"\n      by (metis consume.simps(1) produce.simps(6))\n    thus ?thesis\n      using assms(1) check_def\n            consume_weaken_type[OF t_int_def, of ts]\n            produce_weaken_type[of t_int prods tm ts]\n      by simp\n  qed\nqed\n\nlemma b_e_check_single_weaken_top:\n  assumes \"check_single \\<C> e (Type tn) = TopType tm\"\n  shows \"check_single \\<C> e (Type (ts@tn)) = TopType tm\"\nproof -\n  consider (1) \"check_single \\<C> e = id\" \n         | (2) \"check_single \\<C> e = (\\<lambda>ctn. type_update_select ctn)\"\n         | (3) \"(\\<exists>cons prods. (check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)))\"\n    using check_single_imp assms\n    by blast\n  thus ?thesis\n  proof (cases)\n    case 1\n    thus ?thesis\n      using assms\n      by simp\n  next\n    case 2\n    thus ?thesis\n      using assms\n      by (simp, metis checker_type.distinct(1) checker_type.distinct(3) consume.simps(1))\n  next\n    case 3\n    then obtain cons prods where check_def:\"check_single \\<C> e = (\\<lambda>ctn. type_update ctn cons prods)\"\n      by blast\n    hence \"produce (consume (Type tn) cons) prods = (TopType tm)\"\n      using assms(1)\n      by simp\n    moreover\n    then obtain t_int where t_int_def:\"consume (Type tn) cons = (Type t_int)\"\n      by (metis checker_type.distinct(3) consume.simps(1) produce.simps(6))\n    ultimately\n    show ?thesis\n      using check_def consume_weaken_type\n      by (cases prods, auto)\n  qed\nqed\n\nlemma b_e_check_weaken_type:\n  assumes \"check \\<C> es (Type tn) = (Type tm)\"\n  shows \"check \\<C> es (Type (ts@tn)) = (Type (ts@tm))\"\n  using assms\nproof (induction es arbitrary: tn tm rule: List.rev_induct)\n  case Nil\n  thus ?case\n    by simp\nnext\n  case (snoc e es)\n  hence \"check_single \\<C> e (check \\<C> es (Type tn)) = Type tm\"\n    using check_unfold_snoc[OF check_neq_bot_snoc]\n    by (metis checker_type.distinct(5))\n  thus ?case\n    using b_e_check_single_weaken_type b_e_check_single_type_type snoc\n    by (metis check_unfold_snoc checker_type.distinct(5))\nqed\n\nlemma check_bot: \"check \\<C> es Bot = Bot\"\n  by (simp add: list.case_eq_if)\n\nlemma b_e_check_weaken_top:\n  assumes \"check \\<C> es (Type tn) = (TopType tm)\"\n  shows \"check \\<C> es (Type (ts@tn)) = (TopType tm)\"\n  using assms\nproof (induction es arbitrary: tn tm)\n  case Nil\n  thus ?case\n    by simp\nnext\n  case (Cons e es)\n  show ?case\n  proof (cases \"(check_single \\<C> e (Type tn))\")\n    case (TopType x1)\n    hence \"check_single \\<C> e (Type (ts@tn)) = TopType x1\"\n      using b_e_check_single_weaken_top\n      by blast\n    thus ?thesis\n      using TopType Cons\n      by simp\n  next\n    case (Type x2)\n    hence \"check_single \\<C> e (Type (ts@tn)) = Type (ts@x2)\"\n      using b_e_check_single_weaken_type\n      by blast\n    thus ?thesis\n      using Cons Type\n      by fastforce\n  next\n    case Bot\n    thus ?thesis\n      using check_bot Cons\n      by simp\n  qed\n  \nqed\n\nlemma b_e_type_checker_weaken:\n  assumes \"b_e_type_checker \\<C> es (t1s _> t2s)\"\n  shows \"b_e_type_checker \\<C> es (ts@t1s _> ts@t2s)\"\nproof -\n  have \"c_types_agree (check \\<C> es (Type t1s)) t2s\"\n    using assms(1)\n    by simp\n  then obtain ctn where ctn_def:\"check \\<C> es (Type t1s) = ctn\"\n                                \"c_types_agree ctn t2s\"\n                                \"ctn \\<noteq> Bot\"\n    by fastforce\n  show ?thesis\n  proof (cases ctn)\n    case (TopType x1)\n    thus ?thesis\n      using ctn_def(1,2) b_e_check_weaken_top[of \\<C> es t1s x1 ts]\n      by (metis append_assoc b_e_type_checker.simps c_types_agree_imp_ct_list_compat c_types_agree_top2)\n  next\n    case (Type x2)\n    thus ?thesis\n      using ctn_def(1,2) b_e_check_weaken_type[of \\<C> es t1s x2 ts]\n      by simp\n  next\n    case Bot\n    thus ?thesis\n      using ctn_def(3)\n      by simp\n  qed\nqed\n\nlemma b_e_type_checker_complete:\n  assumes \"\\<C> \\<turnstile> es : (tn _> tm)\"\n  shows \"b_e_type_checker \\<C> es (tn _> tm)\"\n  using assms\nproof (induction es \"(tn _> tm)\" arbitrary: tn tm rule: b_e_typing.induct)\n  case (select \\<C> t)\n  have \"ct_list_compat [TAny, TSome T_i32] [TSome t, TSome T_i32]\"\n    by (simp add: to_ct_list_def ct_list_compat_def)\n  thus ?case\n    using ct_suffix_extend_ct_list_compat[OF ct_suffix_nil[of \"[TSome t]\"]] to_ct_list_def\n    by auto\nnext\n  case (br_table \\<C> ts \"is\" i t1s t2s)\n  show ?case\n    using list_all_conv_same_lab[OF br_table]\n    by (auto simp add: to_ct_list_def ct_suffix_nil ct_suffix_cons_it)\nnext\n  case (set_global i \\<C> t)\n  thus ?case\n    using to_ct_list_def ct_suffix_refl is_mut_def tg_t_def\n    by auto\nnext\n  case (composition \\<C> es t1s t2s e t3s)\n  thus ?case\n    using b_e_type_checker_compose\n    by simp\nnext\n  case (weakening \\<C> es t1s t2s ts)\n  thus ?case\n    using b_e_type_checker_weaken\n    by simp\nqed (auto simp add: to_ct_list_def ct_suffix_refl ct_suffix_nil ct_suffix_cons_it\n                    ct_suffix_singleton_any)\n\ntheorem b_e_typing_equiv_b_e_type_checker:\n  shows \"(\\<C> \\<turnstile> es : tf) = (b_e_type_checker \\<C> es tf)\"\n  using b_e_type_checker_sound b_e_type_checker_complete\n  by (metis tf.exhaust)\n\nend\n", "meta": {"author": "WasmCert", "repo": "WasmCert-Isabelle", "sha": "f61ec8eab5d551347a268e858e83b7ac7da0d8b5", "save_path": "github-repos/isabelle/WasmCert-WasmCert-Isabelle", "path": "github-repos/isabelle/WasmCert-WasmCert-Isabelle/WasmCert-Isabelle-f61ec8eab5d551347a268e858e83b7ac7da0d8b5/WebAssembly/Wasm_Checker_Properties.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953651858117, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.25952216355204033}}
{"text": "(*  Title:      HOL/Auth/n_mutualEx_lemma_inv__1_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n  \n\ntheory n_mutualEx_lemma_inv__1_on_rules imports n_mutualEx_lemma_on_inv__1\nbegin\nsection{*All lemmas on causal relation between inv__1*}\nlemma lemma_inv__1_on_rules:\n  assumes b1: \"r \\<in> rules N\" and b2: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__1  p__Inv3 p__Inv4)\"\n  shows \"invHoldForRule Interp s f r (invariants N)\"\n  proof -\n  have c1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n  apply (cut_tac b1, auto) done\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\"\n      have \"invHoldForRule Interp s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_TryVsinv__1) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\"\n      have \"invHoldForRule Interp s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_CritVsinv__1) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\"\n      have \"invHoldForRule Interp s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_ExitVsinv__1) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n      have \"invHoldForRule Interp s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_IdleVsinv__1) done\n    }\n\n  ultimately show \"invHoldForRule Interp s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "lyj238Gmail", "repo": "gsteProof", "sha": "3070d08e1f31a93be6fde85ab6b65d489c05f99e", "save_path": "github-repos/isabelle/lyj238Gmail-gsteProof", "path": "github-repos/isabelle/lyj238Gmail-gsteProof/gsteProof-3070d08e1f31a93be6fde85ab6b65d489c05f99e/mutualEx/n_mutualEx_lemma_inv__1_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6370307944803831, "lm_q2_score": 0.4073334000459302, "lm_q1q2_score": 0.25948391944965465}}
{"text": "(*******************************************************************************\n \n  Project: IsaNet\n\n  Author:  Tobias Klenze, ETH Zurich <tobias.klenze@inf.ethz.ch>\n  Version: JCSPaper.1.0\n  Isabelle Version: Isabelle2021-1\n\n  Copyright (c) 2022 Tobias Klenze\n  Licence: Mozilla Public License 2.0 (MPL) / BSD-3-Clause (dual license)\n\n*******************************************************************************)\n\nsection \\<open>EPIC Level 1 in the Strong Attacker Model\\<close>\ntheory EPIC_L1_SA\n  imports\n    \"../Parametrized_Dataplane_3_directed\"\n    \"../infrastructure/Keys\"\nbegin\n\ntype_synonym EPIC_HF = \"(unit, msgterm) HF\"\ntype_synonym UINFO = \"nat\"\n\nlocale epic_l1_defs = network_assums_direct _ _ _ auth_seg0 \n  for auth_seg0 :: \"(msgterm \\<times> ahi list) set\" +\n  fixes no_oracle :: \"msgterm \\<Rightarrow> UINFO \\<Rightarrow> bool\"\nbegin\n\n\n(******************************************************************************)\nsubsection \\<open>Hop validation check and extract functions\\<close>\n(******************************************************************************)\n\ntext\\<open>The predicate @{term \"hf_valid\"} is given to the concrete parametrized model as a parameter.\nIt ensures the authenticity of the hop authenticator in the hop field. The predicate takes an authenticated\ninfo field (in this model always a numeric value, hence the matching on Num ts), an unauthenticated\ninfo field uinfo, the hop field to be validated and in some cases the next hop field.\n\nWe distinguish if there is a next hop field (this yields the two cases below). If there is not, then\nthe hop authenticator @{text \"\\<sigma>\"} simply consists of a MAC over the authenticated info field and the local\nrouting information of the hop, using the key of the hop to which the hop field belongs. If on the\nother hand, there is a subsequent hop field, then the uhi field of that hop field is also included\nin the MAC computation.\n\nThe hop authenticator @{text \"\\<sigma>\"} is used to compute both the hop validation field and the uhi field.\nThe first is computed as a MAC over the path origin (pair of absolute timestamp ts and the relative\ntimestamp given in uinfo), using the hop authenticator as a key to the MAC. The hop authenticator\nis not secret, and any end host can use it to create a valid hvf. The uhi field, according to the \nprotocol description, is @{text \"\\<sigma>\"} shortened to a few bytes. We model this as applying the hash on @{text \"\\<sigma>\"}.\n\nThe predicate @{term \"hf_valid\"} checks if the hop authenticator, hvf and uhi field are computed\ncorrectly.\\<close>\nfun hf_valid :: \"msgterm \\<Rightarrow> UINFO\n    \\<Rightarrow> EPIC_HF\n    \\<Rightarrow> EPIC_HF option \\<Rightarrow> bool\" where \n  \"hf_valid (Num ts) uinfo \\<lparr>AHI = ahi, UHI = uhi, HVF = x\\<rparr> (Some \\<lparr>AHI = ahi2, UHI = uhi2, HVF = x2\\<rparr>) \\<longleftrightarrow> \n    (\\<exists>\\<sigma> upif downif. \\<sigma> = Mac[macKey (ASID ahi)] (L [Num ts, upif, downif, uhi2]) \\<and>\n          ASIF (DownIF ahi) downif \\<and> ASIF (UpIF ahi) upif \\<and> uhi = Hash \\<sigma> \\<and> x = Mac[\\<sigma>] \\<langle>Num ts, Num uinfo\\<rangle>)\"\n| \"hf_valid (Num ts) uinfo \\<lparr>AHI = ahi, UHI = uhi, HVF = x\\<rparr> None \\<longleftrightarrow> \n    (\\<exists>\\<sigma> upif downif. \\<sigma> = Mac[macKey (ASID ahi)] (L [Num ts, upif, downif]) \\<and>\n          ASIF (DownIF ahi) downif \\<and> ASIF (UpIF ahi) upif \\<and> uhi = Hash \\<sigma> \\<and> x = Mac[\\<sigma>] \\<langle>Num ts, Num uinfo\\<rangle>)\"\n| \"hf_valid _ _ _ _ = False\"\n\ndefinition upd_uinfo :: \"nat \\<Rightarrow> EPIC_HF \\<Rightarrow> nat\" where\n  \"upd_uinfo uinfo hf \\<equiv> uinfo\"\n\ntext\\<open>We can extract the entire path from the uhi field, since it includes the hop authenticator, \nwhich includes the local forwarding information as well as, recursively, all upstream hop \nauthenticators and their hop information.\nHowever, the parametrized model defines the extract function to operate on the hop validation field,\nnot the uhi field. We therefore define a separate function that extracts the path from a hvf. \nWe can do so, as both hvf and uhi contain the hop authenticator.\nInternally, that function uses @{term \"extrUhi\"}.\\<close>\nfun extrUhi :: \"msgterm \\<Rightarrow> ahi list\" where\n  \"extrUhi (Hash (Mac[macKey asid] (L [ts, upif, downif, uhi2])))\n = \\<lparr>UpIF = term2if upif, DownIF = term2if downif, ASID = asid\\<rparr> # extrUhi uhi2\"\n| \"extrUhi (Hash (Mac[macKey asid] (L [ts, upif, downif])))\n = [\\<lparr>UpIF = term2if upif, DownIF = term2if downif, ASID = asid\\<rparr>]\"\n| \"extrUhi _ = []\"\n\ntext\\<open>This function extracts from a hop validation field (HVF hf) the entire path.\\<close>\nfun extr :: \"msgterm \\<Rightarrow> ahi list\" where\n  \"extr (Mac[\\<sigma>] _) = extrUhi (Hash \\<sigma>)\" \n   | \"extr _ = []\"\n\ntext\\<open>Extract the authenticated info field from a hop validation field.\\<close>\nfun extr_ainfo :: \"msgterm \\<Rightarrow> msgterm\" where \n  \"extr_ainfo (Mac[_] \\<langle>Num ts, _\\<rangle>) = Num ts\"\n| \"extr_ainfo _ = \\<epsilon>\"\n\nabbreviation term_ainfo :: \"msgterm \\<Rightarrow> msgterm\" where\n  \"term_ainfo \\<equiv> id\"\n\ntext\\<open>When observing a hop field, an attacker learns the HVF and the UHI. The AHI only contains \npublic information that are not terms.\\<close>\nfun terms_hf :: \"EPIC_HF \\<Rightarrow> msgterm set\" where \n  \"terms_hf hf = {HVF hf, UHI hf}\"\n\nabbreviation terms_uinfo :: \"UINFO \\<Rightarrow> msgterm set\" where \n  \"terms_uinfo x \\<equiv> {}\"\n\ntext\\<open>An authenticated info field is always a number (corresponding to a timestamp). The \n     unauthenticated info field is as well a number, representing combination of timestamp offset\n     and SRC address.\\<close>\ndefinition auth_restrict where \n  \"auth_restrict ainfo uinfo l \\<equiv> (\\<exists>ts. ainfo = Num ts)\"\n\ntext\\<open>We now define useful properties of the above definition.\\<close>\nlemma hf_valid_invert:\n  \"hf_valid tsn uinfo hf mo \\<longleftrightarrow>\n   ((\\<exists>ahi ahi2 \\<sigma> ts upif downif asid x upif2 downif2 asid2 uhi uhi2 x2.\n     hf = \\<lparr>AHI = ahi, UHI = uhi, HVF = x\\<rparr> \\<and>\n     ASID ahi = asid \\<and> ASIF (DownIF ahi) downif \\<and> ASIF (UpIF ahi) upif \\<and>\n     mo = Some \\<lparr>AHI = ahi2, UHI = uhi2, HVF = x2\\<rparr> \\<and>\n     ASID ahi2 = asid2 \\<and> ASIF (DownIF ahi2) downif2 \\<and> ASIF (UpIF ahi2) upif2 \\<and>\n     \\<sigma> = Mac[macKey asid] (L [tsn, upif, downif, uhi2]) \\<and>\n     tsn = Num ts \\<and>\n     uhi = Hash \\<sigma> \\<and>\n     x = Mac[\\<sigma>] \\<langle>tsn, Num uinfo\\<rangle>)\n \\<or> (\\<exists>ahi \\<sigma> ts upif downif asid uhi x.\n     hf = \\<lparr>AHI = ahi, UHI = uhi, HVF = x\\<rparr> \\<and>\n     ASID ahi = asid \\<and> ASIF (DownIF ahi) downif \\<and> ASIF (UpIF ahi) upif \\<and>\n     mo = None \\<and>\n     \\<sigma> = Mac[macKey asid] (L [tsn, upif, downif]) \\<and>\n     tsn = Num ts \\<and>\n     uhi = Hash \\<sigma> \\<and>\n     x = Mac[\\<sigma>] \\<langle>tsn, Num uinfo\\<rangle>)\n    )\"\n  apply(auto elim!: hf_valid.elims) using option.exhaust ASIF.simps by metis+\n\nlemma hf_valid_auth_restrict[dest]: \"hf_valid ainfo uinfo hf z \\<Longrightarrow> auth_restrict ainfo uinfo l\"\n  by(auto simp add: hf_valid_invert auth_restrict_def)\n\nlemma auth_restrict_ainfo[dest]: \"auth_restrict ainfo uinfo l \\<Longrightarrow> \\<exists>ts. ainfo = Num ts\"\n  by(auto simp add: auth_restrict_def)\n\nlemma info_hvf: \n  assumes \"hf_valid ainfo uinfo m z\" \"HVF m = Mac[\\<sigma>] \\<langle>ainfo', Num uinfo'\\<rangle> \\<or> hf_valid ainfo' uinfo' m z'\" \n  shows \"uinfo = uinfo'\" \"ainfo' = ainfo\"\n  using assms by(auto simp add: hf_valid_invert)\n\n\n(******************************************************************************)\nsubsection\\<open>Definitions and properties of the added intruder knowledge\\<close>\n(******************************************************************************)\ntext\\<open>Here we define two sets which are added to the intruder knowledge: @{text \"ik_add\"}, which contains hop\nauthenticators. And @{text \"ik_oracle\"}, which contains the oracle's output to the strong attacker.\\<close>\nprint_locale dataplane_3_directed_defs \nsublocale dataplane_3_directed_defs _ _ _ auth_seg0 hf_valid auth_restrict extr extr_ainfo term_ainfo \n                 terms_hf terms_uinfo upd_uinfo no_oracle\n  by unfold_locales\n\nabbreviation is_oracle where \"is_oracle ainfo t \\<equiv> \\<not> no_oracle ainfo t \"\n\n\ndeclare TWu.holds_set_list[dest]\ndeclare TWu.holds_takeW_is_identity[simp]\ndeclare parts_singleton[dest]\n\ntext\\<open>This additional Intruder Knowledge allows us to model the attacker's access not only to the \nhop validation fields and segment identifiers of authorized segments (which are already given in \n@{text \"ik_hfs\"}), but to the underlying hop authenticators that are used to create them.\\<close>\n\ndefinition ik_add :: \"msgterm set\" where\n  \"ik_add \\<equiv> { \\<sigma> | ainfo uinfo l hf \\<sigma>.  \n                 (ainfo::msgterm, l::(EPIC_HF list)) \\<in> \n                 ((local.auth_seg2 uinfo)::((msgterm \\<times> EPIC_HF list) set))\n                  \\<and> hf \\<in> set l \\<and> HVF hf = Mac[\\<sigma>] \\<langle>ainfo, Num uinfo\\<rangle> }\"\n\nlemma ik_addI:\n  \"\\<lbrakk>(ainfo, l) \\<in> local.auth_seg2 uinfo; hf \\<in> set l; HVF hf = Mac[\\<sigma>] \\<langle>ainfo, Num uinfo\\<rangle>\\<rbrakk> \\<Longrightarrow> \\<sigma> \\<in> ik_add\"\n  by(auto simp add: ik_add_def)\n\nlemma ik_add_form: \"t \\<in> local.ik_add \\<Longrightarrow> \\<exists> asid l . t = Mac[macKey asid] l\"\n(*  using [[unify_trace_failure]]*)\n  by(auto simp add: ik_add_def auth_seg2_def dest!: TWu.holds_set_list)\n    (auto simp add: hf_valid_invert)\n\nlemma parts_ik_add[simp]: \"parts ik_add = ik_add\"\n  by (auto intro!: parts_Hash dest: ik_add_form)\n\ntext\\<open>This is the oracle output provided to the adversary. Only those hop validation fields and \nsegment identifiers whose path origin (combination of ainfo uinfo) is not contained in \n@{term \"no_oracle\"} appears here.\\<close>\ndefinition ik_oracle :: \"msgterm set\" where \n  \"ik_oracle = {t | t ainfo hf l uinfo . hf \\<in> set l \\<and> hfs_valid_None ainfo uinfo l \\<and> \n                    is_oracle ainfo uinfo \\<and> (\\<forall>uinfo' . (ainfo, l) \\<notin> auth_seg2 uinfo') \\<and> \n                   (t = HVF hf \\<or> t = UHI hf) }\"\n\nlemma ik_oracle_parts_form:\n\"t \\<in> ik_oracle \\<Longrightarrow> \n  (\\<exists> asid l ainfo uinfo . t = Mac[Mac[macKey asid] l] \\<langle>ainfo, uinfo\\<rangle>) \\<or>\n  (\\<exists> asid l . t = Hash (Mac[macKey asid] l))\"\n  by(auto simp add: ik_oracle_def hf_valid_invert dest!: TWu.holds_set_list)\n\nlemma parts_ik_oracle[simp]: \"parts ik_oracle = ik_oracle\"\n  by (auto intro!: parts_Hash dest: ik_oracle_parts_form)\n\nlemma ik_oracle_simp: \"t \\<in> ik_oracle \\<longleftrightarrow>\n      (\\<exists>ainfo hf l uinfo. hf \\<in> set l \\<and> hfs_valid_None ainfo uinfo l \\<and> is_oracle ainfo uinfo\n                       \\<and> (\\<forall>uinfo'. (ainfo, l) \\<notin> auth_seg2 uinfo') \\<and> (t = HVF hf \\<or> t = UHI hf))\"\n  by(rule iffI, frule ik_oracle_parts_form)\n    (auto simp add: ik_oracle_def hf_valid_invert)\n\n(******************************************************************************)\nsubsection\\<open>Properties of the intruder knowledge, including @{text \"ik_add\"} and  @{text \"ik_oracle\"}\\<close>\n(******************************************************************************)\ntext\\<open>We now instantiate the parametrized model's definition of the intruder knowledge, using the\ndefinitions of @{text \"ik_add\"} and  @{text \"ik_oracle\"} from above. We then prove the properties \nthat we need to instantiate the @{text \"dataplane_3_directed\"} locale.\\<close>\nsublocale\n  dataplane_3_directed_ik_defs _ _ _ auth_seg0 terms_uinfo no_oracle hf_valid auth_restrict extr extr_ainfo term_ainfo \n                  terms_hf upd_uinfo ik_add ik_oracle \n  by unfold_locales\n\nlemma ik_hfs_form: \"t \\<in> parts ik_hfs \\<Longrightarrow> \\<exists> t' . t = Hash t'\"\n  by(auto 3 4 simp add: auth_seg2_def hf_valid_invert)\n\ndeclare ik_hfs_def[simp del]\n\nlemma parts_ik_hfs[simp]: \"parts ik_hfs = ik_hfs\"\n  by (auto intro!: parts_Hash ik_hfs_form)\n\ntext\\<open>This lemma allows us not only to expand the definition of @{term \"ik_hfs\"}, but also \nto obtain useful properties, such as a term being a Hash, and it being part of a valid hop field.\\<close>\nlemma ik_hfs_simp: \n  \"t \\<in> ik_hfs \\<longleftrightarrow> (\\<exists>t' . t = Hash t') \\<and> (\\<exists>hf . (t = HVF hf \\<or> t = UHI hf)\n                    \\<and> (\\<exists>hfs. hf \\<in> set hfs \\<and> (\\<exists>ainfo uinfo . (ainfo, hfs) \\<in> auth_seg2 uinfo\n                    \\<and> (\\<exists>nxt. hf_valid ainfo uinfo hf nxt))))\" (is \"?lhs \\<longleftrightarrow> ?rhs\")\nproof \n  assume asm: \"?lhs\" \n  then obtain ainfo uinfo hf hfs where \n    dfs: \"hf \\<in> set hfs\" \"(ainfo, hfs) \\<in> auth_seg2 uinfo\" \"t = HVF hf \\<or> t = UHI hf\"\n    by(auto simp add: ik_hfs_def)\n  then have \"hfs_valid_None ainfo uinfo hfs\"  \"(ainfo, AHIS hfs) \\<in> auth_seg0\"\n    by(auto simp add: auth_seg2_def)\n  then show \"?rhs\" using asm dfs \n    using upd_uinfo_def \n    by (auto 3 4 simp add: auth_seg2_def intro!: ik_hfs_form exI[of _ hf] exI[of _ hfs] \n                     dest: TWu.holds_set_list_no_update)\nqed(auto simp add: ik_hfs_def)\n\n(******************************************************************************)\nsubsubsection \\<open>Properties of Intruder Knowledge\\<close>\n(******************************************************************************)\nlemma auth_ainfo[dest]: \"\\<lbrakk>(ainfo, hfs) \\<in> auth_seg2 uinfo\\<rbrakk> \\<Longrightarrow> \\<exists> ts . ainfo = Num ts\"\n  by(auto simp add: auth_seg2_def)\n\ntext \\<open>There are no ciphertexts (or signatures) in @{term \"parts ik\"}. Thus, @{term \"analz ik\"}\nand @{term \"parts ik\"} are identical.\\<close>\nlemma analz_parts_ik[simp]: \"analz ik = parts ik\"\n  apply(rule no_crypt_analz_is_parts)\n  by(auto simp add: ik_def auth_seg2_def auth_restrict_def ik_hfs_simp)\n    (auto simp add: ik_add_def ik_oracle_def auth_seg2_def hf_valid_invert hfs_valid_prefix_generic_def \n          dest!: TWu.holds_set_list)\n\nlemma parts_ik[simp]: \"parts ik = ik\"\n  by(auto 3 4 simp add: ik_def auth_seg2_def auth_restrict_def dest!: parts_singleton_set)\n\nlemma key_ik_bad: \"Key (macK asid) \\<in> ik \\<Longrightarrow> asid \\<in> bad\"\n  by(auto simp add: ik_def hf_valid_invert ik_oracle_simp)\n    (auto 3 4 simp add: auth_seg2_def ik_hfs_simp ik_add_def hf_valid_invert)\n\n(******************************************************************************)\nsubsubsection\\<open>Hop authenticators are agnostic to uinfo field\\<close>\n(******************************************************************************)\ntext\\<open>Those hop validation fields contained in @{term \"auth_seg2\"} or that can be generated from the hop\nauthenticators in @{text \"ik_add\"} have the property that they are agnostic about the uinfo field. If a\nhop validation field is contained in @{term \"auth_seg2\"} (resp. derivable from @{text \"ik_add\"}), \nthen a field with a different uinfo is also contained (resp. derivable).\nTo show this, we first define a function that updates uinfo in a hop validation field.\\<close>\nfun uinfo_change_hf :: \"UINFO \\<Rightarrow> EPIC_HF \\<Rightarrow> EPIC_HF\" where\n  \"uinfo_change_hf new_uinfo hf = \n    (case HVF hf of Mac[\\<sigma>] \\<langle>ainfo, uinfo\\<rangle> \\<Rightarrow> hf\\<lparr>HVF := Mac[\\<sigma>] \\<langle>ainfo, Num new_uinfo\\<rangle>\\<rparr> | _ \\<Rightarrow> hf)\"\n\nfun uinfo_change :: \"UINFO \\<Rightarrow> EPIC_HF list \\<Rightarrow> EPIC_HF list\" where \n  \"uinfo_change new_uinfo hfs = map (uinfo_change_hf new_uinfo) hfs\"\n\nlemma uinfo_change_valid: \n  \"hfs_valid ainfo uinfo l nxt \\<Longrightarrow> hfs_valid ainfo new_uinfo (uinfo_change new_uinfo l) nxt\"\n  apply(induction l nxt rule: TWu.holds.induct[where ?upd=upd_uinfo])\n  apply auto\n  subgoal for info x y ys nxt\n    by(cases \"map (uinfo_change_hf new_uinfo) ys\")\n      (cases info, auto 3 4 simp add: TWu.holds_split_tail hf_valid_invert upd_uinfo_def)+\n  by(auto 3 4 simp add: TWu.holds_split_tail hf_valid_invert TWu.holds.simps upd_uinfo_def)\n\nlemma uinfo_change_hf_AHI: \"AHI (uinfo_change_hf new_uinfo hf) = AHI hf\"\n  apply(cases \"HVF hf\") apply auto\n  subgoal for x apply(cases x) apply auto\n    subgoal for x1 x2 apply(cases x2) by auto\n    done\n  done\n\nlemma uinfo_change_hf_AHIS[simp]: \"AHIS (map (uinfo_change_hf new_uinfo) l) = AHIS l\"\n  apply(induction l) using uinfo_change_hf_AHI by auto\n\nlemma uinfo_change_auth_seg2:\n  assumes \"hf_valid ainfo uinfo m z\" \"\\<sigma> = Mac[Key (macK asid)] j\"\n          \"HVF m = Mac[\\<sigma>] \\<langle>ainfo, Num uinfo'\\<rangle>\" \"\\<sigma> \\<in> ik_add\" \"no_oracle ainfo uinfo\"\n  shows \"\\<exists>hfs. m \\<in> set hfs \\<and> (\\<exists>uinfo''. (ainfo, hfs) \\<in> auth_seg2 uinfo'')\"\nproof-\n  from assms(4) obtain ainfo_add uinfo_add l_add hf_add where\n    \"(ainfo_add, l_add) \\<in> auth_seg2 uinfo_add\" \"hf_add \\<in> set l_add\" \"HVF hf_add = Mac[\\<sigma>] \\<langle>ainfo_add, Num uinfo_add\\<rangle>\"\n    by(auto simp add: ik_add_def)\n  then have add: \"m \\<in> set (uinfo_change uinfo l_add)\" \"(ainfo_add, (uinfo_change uinfo l_add)) \\<in> auth_seg2 uinfo\"\n    using assms(1-3,5) apply(auto simp add: auth_seg2_def simp del: AHIS_def)\n       apply(auto simp add: hf_valid_invert intro!: image_eqI dest!: TWu.holds_set_list)[1]\n       apply(auto simp add: auth_restrict_def intro!: exI elim: ahi_eq dest: uinfo_change_valid simp del: AHIS_def)\n    by(auto simp add: hf_valid_invert upd_uinfo_def dest!: TWu.holds_set_list_no_update)\n  then have \"ainfo_add = ainfo\" \n    using assms(1) by(auto simp add: auth_seg2_def dest!: TWu.holds_set_list dest: info_hvf)\n  then show ?thesis using add by fastforce\nqed\n\nlemma MAC_synth_oracle:\n  assumes \"hf_valid ainfo uinfo m z\" \"HVF m \\<in> ik_oracle\"\n  shows \"is_oracle ainfo uinfo\"\n  using assms \n  by(auto simp add: ik_oracle_def assms(1) hf_valid_invert upd_uinfo_def \n             dest!: TWu.holds_set_list_no_update)\n\nlemma ik_oracle_is_oracle:\n  \"\\<lbrakk>Mac[\\<sigma>] \\<langle>ainfo, Num uinfo\\<rangle> \\<in> ik_oracle\\<rbrakk> \\<Longrightarrow> is_oracle ainfo uinfo\"\n  by (auto simp add: ik_oracle_def dest: info_hvf)\n     (auto dest!: TWu.holds_set_list_no_update simp add: hf_valid_invert upd_uinfo_def)\n\nlemma MAC_synth_helper:\n\"\\<lbrakk>hf_valid ainfo uinfo m z; no_oracle ainfo uinfo;\n  HVF m = Mac[\\<sigma>] \\<langle>ainfo, Num uinfo\\<rangle>; \\<sigma> = Mac[Key (macK asid)] j; \\<sigma> \\<in> ik \\<or> HVF m \\<in> ik\\<rbrakk>\n       \\<Longrightarrow> \\<exists>hfs. m \\<in> set hfs \\<and> (\\<exists>uinfo'. (ainfo, hfs) \\<in> auth_seg2 uinfo')\"\n  apply(auto simp add: ik_def ik_hfs_simp \n                 dest: MAC_synth_oracle ik_add_form ik_oracle_parts_form[simplified])\n  prefer 3 subgoal by(auto elim!: uinfo_change_auth_seg2)\n  prefer 3 subgoal by(auto elim!: uinfo_change_auth_seg2 intro: ik_addI dest: info_hvf HOL.sym)\n  by(auto simp add: hf_valid_invert)\n\ntext\\<open>This definition helps with the limiting the number of cases generated. We don't require it, \nbut it is convenient. Given a hop validation field and an asid, return if the hvf has the expected\nformat.\\<close>\ndefinition mac_format :: \"msgterm \\<Rightarrow> as \\<Rightarrow> bool\" where \n  \"mac_format m asid \\<equiv> \\<exists> j ts uinfo . m = Mac[Mac[macKey asid] j] \\<langle>Num ts, uinfo\\<rangle>\"\n\ntext\\<open>If a valid hop field is derivable by the attacker, but does not belong to the attacker, and is\nover a path origin that does not belong to an oracle query, then the hop field is already \ncontained in the set of authorized segments.\\<close>\nlemma MAC_synth:\n  assumes \"hf_valid ainfo uinfo m z\" \"HVF m \\<in> synth ik\" \"mac_format (HVF m) asid\"\n    \"asid \\<notin> bad\" \"no_oracle ainfo uinfo\" \n  shows \"\\<exists>hfs . m \\<in> set hfs \\<and> (\\<exists>uinfo'. (ainfo, hfs) \\<in> auth_seg2 uinfo')\"\n  using assms\n  apply(auto simp add: mac_format_def elim!: MAC_synth_helper dest!: key_ik_bad)\n  apply(auto simp add: ik_def ik_hfs_simp dest: ik_add_form dest!: ik_oracle_parts_form) (* takes a few seconds *)\n  using assms(1) by(auto dest: info_hvf simp add: hf_valid_invert)\n\n(******************************************************************************)\nsubsection\\<open>Direct proof goals for interpretation of @{text \"dataplane_3_directed\"}\\<close>\n(******************************************************************************)\n\nlemma COND_honest_hf_analz:\n  assumes \"ASID (AHI hf) \\<notin> bad\" \"hf_valid ainfo uinfo hf nxt\" \"terms_hf hf \\<subseteq> synth (analz ik)\"\n    \"no_oracle ainfo uinfo\"\n    shows \"terms_hf hf \\<subseteq> analz ik\"\nproof-\n  let ?asid = \"ASID (AHI hf)\"\n  from assms(3) have hf_synth_ik: \"HVF hf \\<in> synth ik\" \"UHI hf \\<in> synth ik\" by auto\n  from assms(2) have \"mac_format (HVF hf) ?asid\"\n    by(auto simp add: mac_format_def hf_valid_invert)\n  then obtain hfs uinfo where \"hf \\<in> set hfs\" \"(ainfo, hfs) \\<in> auth_seg2 uinfo\"\n    using assms(1,2,4) hf_synth_ik by(auto dest!: MAC_synth)\n  then have \"HVF hf \\<in> ik\" \"UHI hf \\<in> ik\" \n    using assms(2)\n    by(auto simp add: ik_hfs_def intro!: ik_ik_hfs intro!: exI) \n  then show ?thesis by auto\nqed\n\nlemma COND_terms_hf: \n  assumes \"hf_valid ainfo uinfo hf z\" and \"HVF hf \\<in> ik\" and \"no_oracle ainfo uinfo\"\n  shows \"\\<exists>hfs. hf \\<in> set hfs \\<and> (\\<exists>uinfo . (ainfo, hfs) \\<in> auth_seg2 uinfo)\"\nproof-\n  obtain hfs ainfo where hfs_def: \"hf \\<in> set hfs\" \"(ainfo, hfs) \\<in> auth_seg2 uinfo\"\n  using assms by(auto 3 4 simp add: hf_valid_invert ik_hfs_simp ik_def dest: ahi_eq\n                             dest!: ik_oracle_is_oracle ik_add_form)\n  then obtain hfs ainfo where hfs_def: \"hf \\<in> set hfs\" \"(ainfo, hfs) \\<in> auth_seg2 uinfo\" by auto\n  show ?thesis \n    using hfs_def apply (auto simp add: auth_seg2_def dest!: TWu.holds_set_list)\n    using hfs_def assms(1) by (auto simp add: auth_seg2_def dest: info_hvf)\nqed\n\n\nlemma COND_extr_prefix_path:\n  \"\\<lbrakk>hfs_valid ainfo uinfo l nxt; nxt = None\\<rbrakk> \\<Longrightarrow> prefix (extr_from_hd l) (AHIS l)\"\n  by(induction l nxt rule: TWu.holds.induct[where ?upd=upd_uinfo])\n    (auto simp add: upd_uinfo_def TWu.holds_split_tail TWu.holds.simps(1) hf_valid_invert,\n     auto split: list.split_asm simp add: hf_valid_invert intro!: ahi_eq elim: ASIF.elims)\n\nlemma COND_path_prefix_extr:\n  \"prefix (AHIS (hfs_valid_prefix ainfo uinfo l nxt))\n          (extr_from_hd l)\"\n  apply(induction l nxt rule: TWu.takeW.induct[where ?Pa=\"hf_valid ainfo\",where ?upd=upd_uinfo])\n  by(auto simp add: upd_uinfo_def TWu.takeW_split_tail TWu.takeW.simps(1))\n    (auto 3 4 simp add: hf_valid_invert intro!: ahi_eq elim: ASIF.elims)\n\nlemma COND_hf_valid_uinfo:\n  \"\\<lbrakk>hf_valid ainfo uinfo hf nxt; hf_valid ainfo' uinfo' hf nxt'\\<rbrakk> \\<Longrightarrow> uinfo' = uinfo\"\n  by(auto dest: info_hvf)\n\nlemma COND_upd_uinfo_ik: \n    \"\\<lbrakk>terms_uinfo uinfo \\<subseteq> synth (analz ik); terms_hf hf \\<subseteq> synth (analz ik)\\<rbrakk> \n    \\<Longrightarrow> terms_uinfo (upd_uinfo uinfo hf) \\<subseteq> synth (analz ik)\"\n  by (auto simp add: upd_uinfo_def)\n\nlemma COND_upd_uinfo_no_oracle: \n  \"no_oracle ainfo uinfo \\<Longrightarrow> no_oracle ainfo (upd_uinfo uinfo fld)\"\n  by (auto simp add: upd_uinfo_def)\n\nlemma COND_auth_restrict_upd:\n      \"auth_restrict ainfo uinfo (x#y#hfs) \n   \\<Longrightarrow> auth_restrict ainfo (upd_uinfo uinfo y) (y#hfs)\"\n  by (auto simp add: auth_restrict_def upd_uinfo_def)\n\n\n(******************************************************************************)\nsubsection\\<open>Instantiation of @{text \"dataplane_3_directed\"} locale\\<close>\n(******************************************************************************)\nprint_locale dataplane_3_directed\nsublocale\n  dataplane_3_directed _ _ _ auth_seg0 terms_uinfo terms_hf hf_valid auth_restrict extr extr_ainfo term_ainfo \n            upd_uinfo ik_add \n            ik_oracle no_oracle\n  apply unfold_locales\n  using COND_terms_hf COND_honest_hf_analz COND_extr_prefix_path\n  COND_path_prefix_extr COND_hf_valid_uinfo COND_upd_uinfo_ik COND_upd_uinfo_no_oracle \n  COND_auth_restrict_upd by auto\n\nend\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/IsaNet/instances/EPIC_L1_SA.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926665999540698, "lm_q2_score": 0.43782349911420193, "lm_q1q2_score": 0.25948336460000776}}
{"text": "theory Matching\nimports Semantics\nbegin\n\nsubsection\\<open>Boolean Matcher Algebra\\<close>\n\nlemma MatchOr: \"matches \\<gamma> (MatchOr m1 m2) p \\<longleftrightarrow> matches \\<gamma> m1 p \\<or> matches \\<gamma> m2 p\"\n  by(simp add: MatchOr_def)\n\nlemma opt_MatchAny_match_expr_correct: \"matches \\<gamma> (opt_MatchAny_match_expr m) = matches \\<gamma> m\"\n proof -\n  have \"matches \\<gamma> (opt_MatchAny_match_expr_once m) = matches \\<gamma> m\" for m\n   apply(simp add: fun_eq_iff)\n   by(induction m rule: opt_MatchAny_match_expr_once.induct) (simp_all)\n   thus ?thesis\n    apply(simp add: opt_MatchAny_match_expr_def)\n    apply(rule repeat_stabilize_induct)\n     by(simp)+\n qed\n    \n\nlemma matcheq_matchAny: \"\\<not> has_primitive m \\<Longrightarrow> matcheq_matchAny m \\<longleftrightarrow> matches \\<gamma> m p\"\n  by(induction m) simp_all\n\nlemma matcheq_matchNone: \"\\<not> has_primitive m \\<Longrightarrow> matcheq_matchNone m \\<longleftrightarrow> \\<not> matches \\<gamma> m p\"\n  by(auto dest: matcheq_matchAny matachAny_matchNone)\n\nlemma matcheq_matchNone_not_matches: \"matcheq_matchNone m \\<Longrightarrow> \\<not> matches \\<gamma> m p\"\n  by(induction m rule: matcheq_matchNone.induct) auto\n\n\ntext\\<open>Lemmas about matching in the @{const iptables_bigstep} semantics.\\<close>\n\nlemma matches_rule_iptables_bigstep:\n  assumes \"matches \\<gamma> m p \\<longleftrightarrow> matches \\<gamma> m' p\"\n  shows \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule m a], s\\<rangle> \\<Rightarrow> t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule m' a], s\\<rangle> \\<Rightarrow> t\" (is \"?l \\<longleftrightarrow>?r\")\nproof -\n  {\n    fix m m'\n    assume \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule m a], s\\<rangle> \\<Rightarrow> t\" \"matches \\<gamma> m p \\<longleftrightarrow> matches \\<gamma> m' p\"\n    hence \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule m' a], s\\<rangle> \\<Rightarrow> t\"\n      by (induction \"[Rule  m a]\" s t rule: iptables_bigstep_induct)\n         (auto intro: iptables_bigstep.intros simp: Cons_eq_append_conv dest: skipD)\n  }\n  with assms show ?thesis by blast\nqed\n\nlemma matches_rule_and_simp_help:\n  assumes \"matches \\<gamma> m p\"\n  shows \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule (MatchAnd m m') a'], Undecided\\<rangle> \\<Rightarrow> t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule m' a'], Undecided\\<rangle> \\<Rightarrow> t\" (is \"?l \\<longleftrightarrow>?r\")\nproof\n  assume ?l thus ?r\n    by (induction \"[Rule (MatchAnd m m') a']\" Undecided t rule: iptables_bigstep_induct)\n       (auto intro: iptables_bigstep.intros simp: assms Cons_eq_append_conv dest: skipD)\nnext\n  assume ?r thus ?l\n    by (induction \"[Rule m' a']\" Undecided t rule: iptables_bigstep_induct)\n       (auto intro: iptables_bigstep.intros simp: assms Cons_eq_append_conv dest: skipD)\nqed\n\nlemma matches_MatchNot_simp: \n  assumes \"matches \\<gamma> m p\"\n  shows \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule (MatchNot m) a], Undecided\\<rangle> \\<Rightarrow> t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[], Undecided\\<rangle> \\<Rightarrow> t\" (is \"?l \\<longleftrightarrow> ?r\")\nproof\n  assume ?l thus ?r\n    by (induction \"[Rule (MatchNot m) a]\" \"Undecided\" t rule: iptables_bigstep_induct)\n       (auto intro: iptables_bigstep.intros simp: assms Cons_eq_append_conv dest: skipD)\nnext\n  assume ?r\n  hence \"t = Undecided\"\n    by (metis skipD)\n  with assms show ?l\n    by (fastforce intro: nomatch)\nqed\n\nlemma matches_MatchNotAnd_simp:\n  assumes \"matches \\<gamma> m p\"\n  shows \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule (MatchAnd (MatchNot m) m') a], Undecided\\<rangle> \\<Rightarrow> t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[], Undecided\\<rangle> \\<Rightarrow> t\" (is \"?l \\<longleftrightarrow> ?r\")\nproof\n  assume ?l thus ?r\n    by (induction \"[Rule (MatchAnd (MatchNot m) m') a]\" \"Undecided\" t rule: iptables_bigstep_induct)\n       (auto intro: iptables_bigstep.intros simp add: assms Cons_eq_append_conv dest: skipD)\nnext\n  assume ?r\n  hence \"t = Undecided\"\n    by (metis skipD)\n  with assms show ?l\n    by (fastforce intro: nomatch)\nqed\n  \nlemma matches_rule_and_simp:\n  assumes \"matches \\<gamma> m p\"\n  shows \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule (MatchAnd m m') a'], s\\<rangle> \\<Rightarrow> t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule m' a'], s\\<rangle> \\<Rightarrow> t\"\nproof (cases s)\n  case Undecided\n  with assms show ?thesis\n    by (simp add: matches_rule_and_simp_help)\nnext\n  case Decision\n  thus ?thesis by (metis decision decisionD)\nqed\n\nlemma iptables_bigstep_MatchAnd_comm:\n  \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule (MatchAnd m1 m2) a], s\\<rangle> \\<Rightarrow> t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule (MatchAnd m2 m1) a], s\\<rangle> \\<Rightarrow> t\"\nproof -\n  { fix m1 m2\n    have \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule (MatchAnd m1 m2) a], s\\<rangle> \\<Rightarrow> t \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule (MatchAnd m2 m1) a], s\\<rangle> \\<Rightarrow> t\"\n      proof (induction \"[Rule (MatchAnd m1 m2) a]\" s t rule: iptables_bigstep_induct)\n        case Seq thus ?case\n          by (metis Nil_is_append_conv append_Nil butlast_append butlast_snoc seq)\n      qed (auto intro: iptables_bigstep.intros)\n  }\n  thus ?thesis by blast\nqed\n\n\nsubsection\\<open>Add match\\<close>\n\ndefinition add_match :: \"'a match_expr \\<Rightarrow> 'a rule list \\<Rightarrow> 'a rule list\" where\n  \"add_match m rs = map (\\<lambda>r. case r of Rule m' a' \\<Rightarrow> Rule (MatchAnd m m') a') rs\"\n\nlemma add_match_split: \"add_match m (rs1@rs2) = add_match m rs1 @ add_match m rs2\"\n  unfolding add_match_def\n  by (fact map_append)\n\nlemma add_match_split_fst: \"add_match m (Rule m' a' # rs) = Rule (MatchAnd m m') a' # add_match m rs\"\n  unfolding add_match_def\n  by simp\n\n\nlemma add_match_distrib:\n  \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>add_match m1 (add_match m2 rs), s\\<rangle> \\<Rightarrow> t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>add_match m2 (add_match m1 rs), s\\<rangle> \\<Rightarrow> t\"\nproof -\n  {\n    fix m1 m2\n    have \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>add_match m1 (add_match m2 rs), s\\<rangle> \\<Rightarrow> t \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>add_match m2 (add_match m1 rs), s\\<rangle> \\<Rightarrow> t\"\n      proof (induction rs arbitrary: s)\n        case Nil thus ?case by (simp add: add_match_def)\n        next\n        case (Cons r rs)\n        from Cons obtain m a where r: \"r = Rule m a\" by (cases r) simp\n        with Cons.prems obtain ti where 1: \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule (MatchAnd m1 (MatchAnd m2 m)) a], s\\<rangle> \\<Rightarrow> ti\" and 2: \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>add_match m1 (add_match m2 rs), ti\\<rangle> \\<Rightarrow> t\"\n          apply(simp add: add_match_split_fst)\n          apply(erule seqE_cons)\n          by simp\n        from 1 r have base: \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule (MatchAnd m2 (MatchAnd m1 m)) a], s\\<rangle> \\<Rightarrow> ti\"\n           by (metis matches.simps(1) matches_rule_iptables_bigstep)\n        from 2 Cons.IH have IH: \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>add_match m2 (add_match m1 rs), ti\\<rangle> \\<Rightarrow> t\" by simp\n        from base IH seq'_cons have \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>Rule (MatchAnd m2 (MatchAnd m1 m)) a # add_match m2 (add_match m1 rs), s\\<rangle> \\<Rightarrow> t\" by fast\n        thus ?case using r by(simp add: add_match_split_fst[symmetric])\n      qed\n  }\n  thus ?thesis by blast\nqed\n\nlemma add_match_split_fst': \"add_match m (a # rs) = add_match m [a] @ add_match m rs\"\n  by (simp add: add_match_split[symmetric])\n\n\n\nlemma matches_add_match_simp:\n  assumes m: \"matches \\<gamma> m p\"\n  shows \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>add_match m rs, s\\<rangle> \\<Rightarrow> t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow> t\" (is \"?l \\<longleftrightarrow> ?r\")\n  proof\n    assume ?l with m show ?r\n      proof (induction rs)\n        case Nil\n        thus ?case\n          unfolding add_match_def by simp\n      next\n        case (Cons r rs)\n        hence IH: \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>add_match m rs, s\\<rangle> \\<Rightarrow> t \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow> t\" by(simp add: add_match_split_fst)\n        obtain m' a where r: \"r = Rule m' a\" by (cases r)\n        with Cons.prems(2) obtain ti where \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule (MatchAnd m m') a], s\\<rangle> \\<Rightarrow> ti\" and \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>add_match m rs, ti\\<rangle> \\<Rightarrow> t\"\n          by(auto elim:seqE_cons simp add: add_match_split_fst)\n        with Cons.prems(1) IH have \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule m' a], s\\<rangle> \\<Rightarrow> ti\" by(simp add: matches_rule_and_simp)\n        with \\<open>\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>add_match m rs, ti\\<rangle> \\<Rightarrow> t\\<close> IH r show ?case by(metis decision state.exhaust iptables_bigstep_deterministic seq_cons)\n      qed\n  next\n    assume ?r with m show ?l\n      proof (induction rs)\n        case Nil\n        thus ?case\n          unfolding add_match_def by simp\n      next\n        case (Cons r rs)\n        hence IH: \" \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow> t \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>add_match m rs, s\\<rangle> \\<Rightarrow> t\" by(simp add: add_match_split_fst)\n        obtain m' a where r: \"r = Rule m' a\" by (cases r)\n        with Cons.prems(2) obtain ti where \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule m' a], s\\<rangle> \\<Rightarrow> ti\" and \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, ti\\<rangle> \\<Rightarrow> t\"\n          by(auto elim:seqE_cons simp add: add_match_split_fst)\n        with Cons.prems(1) IH have \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[Rule (MatchAnd m m') a], s\\<rangle> \\<Rightarrow> ti\" by(simp add: matches_rule_and_simp)\n        with \\<open>\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, ti\\<rangle> \\<Rightarrow> t\\<close> IH r show ?case \n          apply(simp add: add_match_split_fst)\n          by(metis decision state.exhaust iptables_bigstep_deterministic seq_cons)\n      qed\n  qed\n\nlemma matches_add_match_MatchNot_simp:\n  assumes m: \"matches \\<gamma> m p\"\n  shows \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>add_match (MatchNot m) rs, s\\<rangle> \\<Rightarrow> t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[], s\\<rangle> \\<Rightarrow> t\" (is \"?l s \\<longleftrightarrow> ?r s\")\n  proof (cases s)\n    case Undecided\n    have \"?l Undecided \\<longleftrightarrow> ?r Undecided\"\n      proof\n        assume \"?l Undecided\" with m show \"?r Undecided\"\n          proof (induction rs)\n            case Nil\n            thus ?case\n              unfolding add_match_def by simp\n          next\n            case (Cons r rs)\n            thus ?case\n              by (cases r) (metis matches_MatchNotAnd_simp skipD seqE_cons add_match_split_fst)\n          qed\n      next\n        assume \"?r Undecided\" with m show \"?l Undecided\"\n          proof (induction rs)\n            case Nil\n            thus ?case\n              unfolding add_match_def by simp\n          next\n            case (Cons r rs)\n            thus ?case\n              by (cases r) (metis matches_MatchNotAnd_simp skipD seq'_cons add_match_split_fst)\n          qed\n      qed\n    with Undecided show ?thesis by fast\n  next\n    case (Decision d)\n    thus ?thesis\n      by(metis decision decisionD)\n  qed\n\nlemma not_matches_add_match_simp:\n  assumes \"\\<not> matches \\<gamma> m p\"\n  shows \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>add_match m rs, Undecided\\<rangle> \\<Rightarrow> t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>[], Undecided\\<rangle> \\<Rightarrow> t\"\n  proof(induction rs)\n    case Nil\n    thus ?case\n      unfolding add_match_def by simp\n  next\n    case (Cons r rs)\n    thus ?case\n      by (cases r) (metis assms add_match_split_fst matches.simps(1) nomatch seq'_cons nomatchD seqE_cons)\n  qed\n\nlemma iptables_bigstep_add_match_notnot_simp: \n  \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>add_match (MatchNot (MatchNot m)) rs, s\\<rangle> \\<Rightarrow> t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>add_match m rs, s\\<rangle> \\<Rightarrow> t\"\n  proof(induction rs)\n    case Nil\n    thus ?case\n      unfolding add_match_def by simp\n  next\n    case (Cons r rs)\n    thus ?case\n      by (cases r)\n         (metis decision decisionD state.exhaust matches.simps(2) matches_add_match_simp not_matches_add_match_simp)\n  qed\n\n\nlemma add_match_match_not_cases:\n  \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>add_match (MatchNot m) rs, Undecided\\<rangle> \\<Rightarrow> Undecided \\<Longrightarrow> matches \\<gamma> m p \\<or> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, Undecided\\<rangle> \\<Rightarrow> Undecided\"\n  by (metis matches.simps(2) matches_add_match_simp)\n\n\nlemma not_matches_add_matchNot_simp:\n  \"\\<not> matches \\<gamma> m p \\<Longrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>add_match (MatchNot m) rs, s\\<rangle> \\<Rightarrow> t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow> t\"\n  by (simp add: matches_add_match_simp)\n\nlemma iptables_bigstep_add_match_and:\n  \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>add_match m1 (add_match m2 rs), s\\<rangle> \\<Rightarrow> t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>add_match (MatchAnd m1 m2) rs, s\\<rangle> \\<Rightarrow> t\"\n  proof(induction rs arbitrary: s t)\n    case Nil\n    thus ?case\n      unfolding add_match_def by simp\n  next\n    case(Cons r rs)\n    show ?case\n    proof (cases r, simp only: add_match_split_fst)\n      fix m a\n      show \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>Rule (MatchAnd m1 (MatchAnd m2 m)) a # add_match m1 (add_match m2 rs), s\\<rangle> \\<Rightarrow> t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>Rule (MatchAnd (MatchAnd m1 m2) m) a # add_match (MatchAnd m1 m2) rs, s\\<rangle> \\<Rightarrow> t\" (is \"?l \\<longleftrightarrow> ?r\")\n      proof\n        assume ?l with Cons.IH show ?r\n          apply -\n          apply(erule seqE_cons)\n          apply(case_tac s)\n          apply(case_tac ti)\n          apply (metis matches.simps(1) matches_rule_and_simp matches_rule_and_simp_help nomatch seq'_cons)\n          apply (metis add_match_split_fst matches.simps(1) matches_add_match_simp not_matches_add_match_simp seq_cons)\n          apply (metis decision decisionD)\n          done\n      next\n        assume ?r with Cons.IH show ?l\n          apply -\n          apply(erule seqE_cons)\n          apply(case_tac s)\n          apply(case_tac ti)\n          apply (metis matches.simps(1) matches_rule_and_simp matches_rule_and_simp_help nomatch seq'_cons)\n          apply (metis add_match_split_fst matches.simps(1) matches_add_match_simp not_matches_add_match_simp seq_cons)\n          apply (metis decision decisionD)\n          done\n        qed\n    qed\n  qed\n\n\nlemma optimize_matches_option_generic:\n  assumes \"\\<forall> r \\<in> set rs. P (get_match r)\"\n      and \"(\\<And>m m'. P m \\<Longrightarrow> f m = Some m' \\<Longrightarrow> matches \\<gamma> m' p = matches \\<gamma> m p)\"\n      and \"(\\<And>m. P m \\<Longrightarrow> f m = None \\<Longrightarrow> \\<not> matches \\<gamma> m p)\"\n  shows \"\\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>optimize_matches_option f rs, s\\<rangle> \\<Rightarrow> t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow> t\"\n      (is \"?lhs \\<longleftrightarrow> ?rhs\")\n  proof\n    assume ?rhs\n    from this assms show ?lhs\n    apply(induction rs s t rule: iptables_bigstep_induct)\n    apply(auto simp: optimize_matches_option_append intro: iptables_bigstep.intros split: option.split)\n    done\n  next\n    assume ?lhs\n    from this assms show ?rhs\n    apply(induction f rs arbitrary: s rule: optimize_matches_option.induct)\n     apply(simp; fail)\n    apply(simp split: option.split_asm)\n     apply(subgoal_tac \"\\<not> matches \\<gamma> m p\")\n     prefer 2 apply blast\n    apply (metis decision nomatch seq'_cons state.exhaust)\n    apply(erule seqE_cons)\n    apply(rule_tac t=ti in seq'_cons)\n     apply (meson matches_rule_iptables_bigstep)\n    by blast\n  qed\n\nlemma optimize_matches_generic: \"\\<forall> r \\<in> set rs. P (get_match r) \\<Longrightarrow> \n      (\\<And>m. P m \\<Longrightarrow> matches \\<gamma> (f m) p = matches \\<gamma> m p) \\<Longrightarrow>\n      \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>optimize_matches f rs, s\\<rangle> \\<Rightarrow> t \\<longleftrightarrow> \\<Gamma>,\\<gamma>,p\\<turnstile> \\<langle>rs, s\\<rangle> \\<Rightarrow> t\"\n  unfolding optimize_matches_def\n  apply(rule optimize_matches_option_generic)\n    apply(simp; fail)\n   apply(simp split: if_split_asm)\n   apply blast\n  apply(simp split: if_split_asm)\n  using matcheq_matchNone_not_matches by fast\nend\n", "meta": {"author": "diekmann", "repo": "Iptables_Semantics", "sha": "e0a2516bd885708fce875023b474ae341cbdee29", "save_path": "github-repos/isabelle/diekmann-Iptables_Semantics", "path": "github-repos/isabelle/diekmann-Iptables_Semantics/Iptables_Semantics-e0a2516bd885708fce875023b474ae341cbdee29/thy/Iptables_Semantics/Matching.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926665999540698, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.2594833646000077}}
{"text": "(******************************************************************************)\n(* Project: The Isabelle/UTP Proof System                                     *)\n(* File: Railways_Impl.thy                                                    *)\n(* Authors: Frank Zeyda and Simon Foster (University of York, UK)             *)\n(* Emails: frank.zeyda@york.ac.uk and simon.foster@york.ac.uk                 *)\n(******************************************************************************)\n(* LAST REVIEWED: 22 Sep 2017 *)\n\nsection {* Railways Implementation *}\n\ntheory Railways_Impl\nimports Railways_Spec\nbegin\n\nsubsection {* Interlocking FMU *}\n\nsubsubsection {* Initialisation *}\n\ndefinition init_ilock :: \"railways_state hrel\" where [urel_defs]:\n\"init_ilock =\n  (cdv, tc, relays, signals, switches) := (\n    mk_vector\\<^sub>u 11 true,\n    mk_vector\\<^sub>u 4 false,\n    mk_vector\\<^sub>u 5 false,\n    mk_vector\\<^sub>u 3 false,\n    mk_vector\\<^sub>u 5 \\<guillemotleft>STRAIGHT\\<guillemotright>)\"\n\nsubsubsection {* Cyclic Behaviour *}\n\nparagraph {* Relay Setting *}\n\ndefinition set_relays :: \"railways_state hrel\" where\n[urel_defs]: \"set_relays =\n  ((relays[1] := true) \\<triangleleft> TC[4] \\<and> \\<not> TC[3] \\<and> \\<not> R2 \\<and> \\<not> R4 \\<and> (*\\<not> CDV[3] \\<and>*) CDV[4] \\<and> CDV[5] \\<triangleright>\\<^sub>r II) ;;\n  ((relays[2] := true) \\<triangleleft> TC[3] \\<and> \\<not> TC[4] \\<and> \\<not> R1 \\<and> \\<not> R3 \\<and> \\<not> R4 \\<and> \\<not> R5 \\<and> (*\\<not> CDV[3] \\<and>*) CDV[4] \\<and> CDV[8] \\<and> CDV[9] \\<and> CDV[10] \\<and> CDV[1] \\<triangleright>\\<^sub>r II) ;;\n  ((relays[4] := true) \\<triangleleft> TC[3] \\<and> \\<not> TC[4] \\<and> \\<not> R1 \\<and> \\<not> R2 \\<and> \\<not> R3 \\<and> \\<not> R5 \\<and> (*\\<not> CDV[3] \\<and>*) CDV[4] \\<and> CDV[8] \\<and> CDV[9] \\<and> CDV[11] \\<and> CDV[2] \\<triangleright>\\<^sub>r II) ;;\n  ((relays[3] := true) \\<triangleleft> TC[1] \\<and> \\<not> R2 \\<and> \\<not> R4 \\<and> \\<not> R5 \\<and> (*\\<not> CDV[1] \\<and>*) CDV[10] \\<and> CDV[9] \\<and> CDV[8] \\<and> CDV[7] \\<and> CDV[6] \\<triangleright>\\<^sub>r II) ;;\n  ((relays[5] := true) \\<triangleleft> TC[2] \\<and> \\<not> R2 \\<and> \\<not> R3 \\<and> \\<not> R4 \\<and> (*\\<not> CDV[2] \\<and>*) CDV[11] \\<and> CDV[9] \\<and> CDV[8] \\<and> CDV[7] \\<and> CDV[6] \\<triangleright>\\<^sub>r II)\"\n\nparagraph {* Relay Clearing *}\n\ndefinition clear_relays :: \"railways_state hrel\" where\n[urel_defs]: \"clear_relays =\n  ((relays[1] := false) \\<triangleleft> R1 \\<and> \\<not> CDV[5] \\<triangleright>\\<^sub>r II) ;;\n  ((relays[2] := false) \\<triangleleft> R2 \\<and> \\<not> CDV[1] \\<triangleright>\\<^sub>r II) ;;\n  ((relays[3] := false) \\<triangleleft> R3 \\<and> \\<not> CDV[6] \\<triangleright>\\<^sub>r II) ;;\n  ((relays[4] := false) \\<triangleleft> R4 \\<and> \\<not> CDV[2] \\<triangleright>\\<^sub>r II) ;;\n  ((relays[5] := false) \\<triangleleft> R5 \\<and> \\<not> CDV[6] \\<triangleright>\\<^sub>r II)\"\n\nparagraph {* Switch Setting *}\n\ndefinition set_switches :: \"railways_state hrel\" where\n[urel_defs]: \"set_switches = (\n  (switches[1] := \\<guillemotleft>STRAIGHT\\<guillemotright>) ;;\n  ((switches[2] := \\<guillemotleft>STRAIGHT\\<guillemotright>) \\<triangleleft> R3 \\<or> R5 \\<triangleright>\\<^sub>r (switches[2] := \\<guillemotleft>DIVERGING\\<guillemotright>)) ;;\n  ((switches[3] := \\<guillemotleft>STRAIGHT\\<guillemotright>) \\<triangleleft> R1 \\<triangleright>\\<^sub>r (switches[3] := \\<guillemotleft>DIVERGING\\<guillemotright>)) ;;\n  (switches[4] := \\<guillemotleft>STRAIGHT\\<guillemotright>) ;;\n  ((switches[5] := \\<guillemotleft>STRAIGHT\\<guillemotright>) \\<triangleleft> R2 \\<or> R3 \\<triangleright>\\<^sub>r (switches[5] := \\<guillemotleft>DIVERGING\\<guillemotright>)))\"\n\nsubsubsection {* Signal Setting *}\n\ndefinition set_signals :: \"railways_state hrel\" where\n[urel_defs]: \"set_signals = (\n  (signals[1] := (R3 \\<and> SW5 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright> \\<and> SW2 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright> \\<and> SW4 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright>)) ;;\n  (signals[2] := (R5 \\<and> SW5 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright> \\<and> SW2 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright> \\<and> SW4 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright>)) ;;\n  (signals[3] := ((R1 \\<and> SW1 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright> \\<and> SW3 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright>) \\<or>\n    (R2 \\<and> SW1 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright> \\<and> SW3 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright> \\<and> SW2 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright> \\<and> SW5 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright>) \\<or>\n    (R4 \\<and> SW1 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright> \\<and> SW3 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright> \\<and> SW2 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright> \\<and> SW5 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright>))))\"\n\nparagraph {* Complete Cycle *}\n\ndefinition ilock_cycle :: \"railways_state hrel\" where [urel_defs]:\n\"ilock_cycle = (set_relays ;; clear_relays ;; set_switches ;; set_signals)\"\n\nsubsubsection {* Invariant Proofs *}\n\nparagraph {* Proof Support *}\n\nlemma relays_excl_inv_extr:\n\"`relays_excl_inv \\<and> P \\<Rightarrow> Q` = `relays_excl_inv \\<Rightarrow> P \\<Rightarrow> Q`\"\n  by (simp add: impl_alt_def utp_pred_laws.sup.assoc)\n\ntext {* Do \\<open>,\\<close>  and \\<open>;\\<close> have the same precedence? Are they right-associative? *}\n\nmethod ilock_relays_excl_inv_tac =\n  (hoare_split_inv; (\n    (unfold relays_excl_inv_extr)?,\n    (unfold relays_excl_inv_cases),\n    (rel_simp);\n    (unfold valid_relay_states_def),\n    (safe; simp)))\n\nparagraph {* Invariant Preservation *}\n\nlemma init_ilock_relays_excl_inv:\n\"\\<lbrace>true\\<rbrace>init_ilock\\<lbrace>relays_excl_inv\\<rbrace>\\<^sub>u\"\n  unfolding init_ilock_def by (rel_simp)\n\nlemma set_relays_relays_excl_inv:\n\"\\<lbrace>relays_excl_inv\\<rbrace>set_relays\\<lbrace>relays_excl_inv\\<rbrace>\\<^sub>u\"\n  unfolding set_relays_def by (ilock_relays_excl_inv_tac)\n\nlemma clear_relays_relays_excl_inv:\n\"\\<lbrace>relays_excl_inv\\<rbrace>clear_relays\\<lbrace>relays_excl_inv\\<rbrace>\\<^sub>u\"\n  unfolding clear_relays_def by (ilock_relays_excl_inv_tac)\n\nlemma set_switches_relays_excl_inv:\n\"\\<lbrace>relays_excl_inv\\<rbrace>set_switches\\<lbrace>relays_excl_inv\\<rbrace>\\<^sub>u\"\n  unfolding set_switches_def by (ilock_relays_excl_inv_tac)\n\nlemma set_signals_relays_excl_inv:\n\"\\<lbrace>relays_excl_inv\\<rbrace>set_signals\\<lbrace>relays_excl_inv\\<rbrace>\\<^sub>u\"\n  unfolding set_signals_def by (ilock_relays_excl_inv_tac)\n\nlemma \"\\<lbrace>relays_excl_inv\\<rbrace>ilock_cycle\\<lbrace>relays_excl_inv\\<rbrace>\\<^sub>u\"\napply (unfold ilock_cycle_def)\napply (hoare_split)\napply (rule set_relays_relays_excl_inv)\napply (rule clear_relays_relays_excl_inv)\napply (rule set_switches_relays_excl_inv)\napply (rule set_signals_relays_excl_inv)\ndone\nend", "meta": {"author": "isabelle-utp", "repo": "utp-main", "sha": "27bdf3aee6d4fc00c8fe4d53283d0101857e0d41", "save_path": "github-repos/isabelle/isabelle-utp-utp-main", "path": "github-repos/isabelle/isabelle-utp-utp-main/utp-main-27bdf3aee6d4fc00c8fe4d53283d0101857e0d41/fmi/Railways_Impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926665855647394, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.25948335830002073}}
{"text": "(*  Title:      HOL/NanoJava/State.thy\n    Author:     David von Oheimb\n    Copyright   2001 Technische Universitaet Muenchen\n*)\n\nsection \"Program State\"\n\ntheory State imports TypeRel begin\n\ndefinition body :: \"cname \\<times> mname => stmt\" where\n \"body \\<equiv> \\<lambda>(C,m). bdy (the (method C m))\"\n\ntext {* Locations, i.e.\\ abstract references to objects *}\ntypedecl loc \n\ndatatype val\n  = Null        --{* null reference *}\n  | Addr loc    --{* address, i.e. location of object *}\n\ntype_synonym fields\n        = \"(fname \\<rightharpoonup> val)\"\n\ntype_synonym\n        obj = \"cname \\<times> fields\"\n\ntranslations\n  (type) \"fields\" \\<leftharpoondown> (type) \"fname => val option\"\n  (type) \"obj\"    \\<leftharpoondown> (type) \"cname \\<times> fields\"\n\ndefinition init_vars :: \"('a \\<rightharpoonup> 'b) => ('a \\<rightharpoonup> val)\" where\n \"init_vars m == map_option (\\<lambda>T. Null) o m\"\n  \ntext {* private: *}\ntype_synonym heap = \"loc   \\<rightharpoonup> obj\"\ntype_synonym locals = \"vname \\<rightharpoonup> val\"  \n\ntext {* private: *}\nrecord  state\n        = heap   :: heap\n          locals :: locals\n\ntranslations\n  (type) \"heap\" \\<leftharpoondown> (type) \"loc => obj option\"\n  (type) \"locals\" \\<leftharpoondown> (type) \"vname => val option\"\n  (type) \"state\" \\<leftharpoondown> (type) \"(|heap :: heap, locals :: locals|)\"\n\ndefinition del_locs :: \"state => state\" where\n \"del_locs s \\<equiv> s (| locals := empty |)\"\n\ndefinition init_locs     :: \"cname => mname => state => state\" where\n \"init_locs C m s \\<equiv> s (| locals := locals s ++ \n                         init_vars (map_of (lcl (the (method C m)))) |)\"\n\ntext {* The first parameter of @{term set_locs} is of type @{typ state} \n        rather than @{typ locals} in order to keep @{typ locals} private.*}\ndefinition set_locs :: \"state => state => state\" where\n \"set_locs s s' \\<equiv> s' (| locals := locals s |)\"\n\ndefinition get_local     :: \"state => vname => val\" (\"_<_>\" [99,0] 99) where\n \"get_local s x  \\<equiv> the (locals s x)\"\n\n--{* local function: *}\ndefinition get_obj       :: \"state => loc => obj\" where\n \"get_obj s a \\<equiv> the (heap s a)\"\n\ndefinition obj_class     :: \"state => loc => cname\" where\n \"obj_class s a \\<equiv> fst (get_obj s a)\"\n\ndefinition get_field     :: \"state => loc => fname => val\" where\n \"get_field s a f \\<equiv> the (snd (get_obj s a) f)\"\n\n--{* local function: *}\ndefinition hupd       :: \"loc => obj => state => state\"   (\"hupd'(_|->_')\" [10,10] 1000) where\n \"hupd a obj s \\<equiv> s (| heap   := ((heap   s)(a\\<mapsto>obj))|)\"\n\ndefinition lupd       :: \"vname => val => state => state\" (\"lupd'(_|->_')\" [10,10] 1000) where\n \"lupd x v s   \\<equiv> s (| locals := ((locals s)(x\\<mapsto>v  ))|)\"\n\nnotation (xsymbols)\n  hupd  (\"hupd'(_\\<mapsto>_')\" [10,10] 1000) and\n  lupd  (\"lupd'(_\\<mapsto>_')\" [10,10] 1000)\n\ndefinition new_obj :: \"loc => cname => state => state\" where\n \"new_obj a C   \\<equiv> hupd(a\\<mapsto>(C,init_vars (field C)))\"\n\ndefinition upd_obj    :: \"loc => fname => val => state => state\" where\n \"upd_obj a f v s \\<equiv> let (C,fs) = the (heap s a) in hupd(a\\<mapsto>(C,fs(f\\<mapsto>v))) s\"\n\ndefinition new_Addr      :: \"state => val\" where\n \"new_Addr s == SOME v. (\\<exists>a. v = Addr a \\<and> (heap s) a = None) | v = Null\"\n\n\nsubsection \"Properties not used in the meta theory\"\n\nlemma locals_upd_id [simp]: \"s\\<lparr>locals := locals s\\<rparr> = s\" \nby simp\n\nlemma lupd_get_local_same [simp]: \"lupd(x\\<mapsto>v) s<x> = v\"\nby (simp add: lupd_def get_local_def)\n\nlemma lupd_get_local_other [simp]: \"x \\<noteq> y \\<Longrightarrow> lupd(x\\<mapsto>v) s<y> = s<y>\"\napply (drule not_sym)\nby (simp add: lupd_def get_local_def)\n\nlemma get_field_lupd [simp]:\n  \"get_field (lupd(x\\<mapsto>y) s) a f = get_field s a f\"\nby (simp add: lupd_def get_field_def get_obj_def)\n\nlemma get_field_set_locs [simp]:\n  \"get_field (set_locs l s) a f = get_field s a f\"\nby (simp add: lupd_def get_field_def set_locs_def get_obj_def)\n\nlemma get_field_del_locs [simp]:\n  \"get_field (del_locs s) a f = get_field s a f\"\nby (simp add: lupd_def get_field_def del_locs_def get_obj_def)\n\nlemma new_obj_get_local [simp]: \"new_obj a C s <x> = s<x>\"\nby (simp add: new_obj_def hupd_def get_local_def)\n\nlemma heap_lupd [simp]: \"heap (lupd(x\\<mapsto>y) s) = heap s\"\nby (simp add: lupd_def)\n\nlemma heap_hupd_same [simp]: \"heap (hupd(a\\<mapsto>obj) s) a = Some obj\"\nby (simp add: hupd_def)\n\nlemma heap_hupd_other [simp]: \"aa \\<noteq> a  \\<Longrightarrow> heap (hupd(aa\\<mapsto>obj) s) a = heap s a\"\napply (drule not_sym)\nby (simp add: hupd_def)\n\nlemma hupd_hupd [simp]: \"hupd(a\\<mapsto>obj) (hupd(a\\<mapsto>obj') s) = hupd(a\\<mapsto>obj) s\"\nby (simp add: hupd_def)\n\nlemma heap_del_locs [simp]: \"heap (del_locs s) = heap s\"\nby (simp add: del_locs_def)\n\nlemma heap_set_locs [simp]: \"heap (set_locs l s) = heap s\"\nby (simp add: set_locs_def)\n\nlemma hupd_lupd [simp]: \n  \"hupd(a\\<mapsto>obj) (lupd(x\\<mapsto>y) s) = lupd(x\\<mapsto>y) (hupd(a\\<mapsto>obj) s)\"\nby (simp add: hupd_def lupd_def)\n\nlemma hupd_del_locs [simp]: \n  \"hupd(a\\<mapsto>obj) (del_locs s) = del_locs (hupd(a\\<mapsto>obj) s)\"\nby (simp add: hupd_def del_locs_def)\n\nlemma new_obj_lupd [simp]: \n  \"new_obj a C (lupd(x\\<mapsto>y) s) = lupd(x\\<mapsto>y) (new_obj a C s)\"\nby (simp add: new_obj_def)\n\nlemma new_obj_del_locs [simp]: \n  \"new_obj a C (del_locs s) = del_locs (new_obj a C s)\"\nby (simp add: new_obj_def)\n\nlemma upd_obj_lupd [simp]: \n  \"upd_obj a f v (lupd(x\\<mapsto>y) s) = lupd(x\\<mapsto>y) (upd_obj a f v s)\"\nby (simp add: upd_obj_def Let_def split_beta)\n\nlemma upd_obj_del_locs [simp]: \n  \"upd_obj a f v (del_locs s) = del_locs (upd_obj a f v s)\"\nby (simp add: upd_obj_def Let_def split_beta)\n\nlemma get_field_hupd_same [simp]:\n \"get_field (hupd(a\\<mapsto>(C, fs)) s) a = the \\<circ> fs\"\napply (rule ext)\nby (simp add: get_field_def get_obj_def)\n\nlemma get_field_hupd_other [simp]:\n \"aa \\<noteq> a  \\<Longrightarrow> get_field (hupd(aa\\<mapsto>obj) s) a = get_field s a\"\napply (rule ext)\nby (simp add: get_field_def get_obj_def)\n\nlemma new_AddrD: \n\"new_Addr s = v \\<Longrightarrow> (\\<exists>a. v = Addr a \\<and> heap s a = None) | v = Null\"\napply (unfold new_Addr_def)\napply (erule subst)\napply (rule someI)\napply (rule disjI2)\napply (rule HOL.refl)\ndone\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/NanoJava/State.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5312093733737563, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.2593807164439105}}
{"text": "(*\n * Copyright (c) 2020, CleanQ Project - Systems Group, ETH Zurich\n * All rights reserved.\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n *\n * See \"LICENSE\" for details.\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\n\n\nsection \\<open>List Model Simpl proofs\\<close>\n\ntext \\<open>\n  Due to problems importing both SIMPL and COMPLX we split the files and have all the proofs\n  using SIMPL in this file\n\\<close>\n\ntheory CleanQ_ListModel_Simpl\n(*<*)\n  imports Main \"../Simpl/Vcg\" CleanQ_ListModel\n(*>*)\nbegin\n\n(* ==================================================================================== *)\nsubsection \\<open>Integration in SIMPL\\<close>\n(* ==================================================================================== *)\n\n\ntext \\<open>\n  We now integrate the the CleanQ List Model into SIMPL. For each of the two operations,\n  enqueue and dequeue, we specify a Hoare-triple with pre and post conditions, and\n  the operation.\n\\<close>\n\n(* ------------------------------------------------------------------------------------ *)\nsubsubsection \\<open>Enqueue Operation\\<close>\n(* ------------------------------------------------------------------------------------ *)\n\ntext \\<open>\n  We first show, that we can define a Hoare triple for the enqueue operations from both\n  agents X and Y, and that in both cases the invariant is preserved.\n\\<close>\n\nlemma CleanQ_List_enq_x_preserves_invariants : \n  \"\\<Gamma>\\<turnstile> \\<lbrace> rb' = \\<acute>ListRB \\<and> CleanQ_List_Invariants K \\<acute>ListRB \\<and> b \\<in> lSX \\<acute>ListRB \\<rbrace> \n        \\<acute>ListRB :== (CleanQ_List_enq_x b \\<acute>ListRB) \n      \\<lbrace> CleanQ_List_Invariants K \\<acute>ListRB \\<rbrace>\"\n  by(vcg, simp only: CleanQ_List_enq_x_Invariants)\n\n\nlemma CleanQ_List_enq_y_preserves_invariants : \n  \"\\<Gamma>\\<turnstile> \\<lbrace> rb' = \\<acute>ListRB \\<and> CleanQ_List_Invariants K \\<acute>ListRB \\<and> b \\<in> lSY \\<acute>ListRB \\<rbrace> \n        \\<acute>ListRB :== (CleanQ_List_enq_y b \\<acute>ListRB) \n      \\<lbrace> CleanQ_List_Invariants K \\<acute>ListRB \\<rbrace>\"\n  by(vcg, simp only: CleanQ_List_enq_y_Invariants)\n\ntext \\<open>\n  The same applies for the multi-step \\verb+eneuque_n+ operation.\n\\<close>\n\nlemma CleanQ_List_enq_n_x_preserves_invariants : \n  \"\\<Gamma>\\<turnstile> \\<lbrace> rb' = \\<acute>ListRB \\<and> CleanQ_List_Invariants K \\<acute>ListRB \n        \\<and> (\\<forall>b \\<in> set B. b \\<in> (lSX \\<acute>ListRB)) \\<and> distinct B \\<rbrace> \n        \\<acute>ListRB :== (CleanQ_List_enq_n_x B \\<acute>ListRB) \n      \\<lbrace> CleanQ_List_Invariants K \\<acute>ListRB \\<rbrace>\"\n  apply(vcg) using CleanQ_List_enq_n_x_Invariants by blast\n\nlemma CleanQ_List_enq_n_y_preserves_invariants : \n  \"\\<Gamma>\\<turnstile> \\<lbrace> rb' = \\<acute>ListRB \\<and> CleanQ_List_Invariants K \\<acute>ListRB \n        \\<and> (\\<forall>b \\<in> set B. b \\<in> (lSY \\<acute>ListRB)) \\<and> distinct B \\<rbrace> \n        \\<acute>ListRB :== (CleanQ_List_enq_n_y B \\<acute>ListRB) \n      \\<lbrace> CleanQ_List_Invariants K \\<acute>ListRB \\<rbrace>\"\n  apply(vcg) using CleanQ_List_enq_n_y_Invariants by blast\n\nend\n\n\n\n", "meta": {"author": "CleanQ-Project", "repo": "cleanq-proofs", "sha": "5212fcd2aceba0028bd1474e0553578a6091ca63", "save_path": "github-repos/isabelle/CleanQ-Project-cleanq-proofs", "path": "github-repos/isabelle/CleanQ-Project-cleanq-proofs/cleanq-proofs-5212fcd2aceba0028bd1474e0553578a6091ca63/CleanQ/CleanQ_ListModel_Simpl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5312093733737562, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.2593807164439104}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory SignedWords\nimports \"~~/src/HOL/Word/Word\"\nbegin\n\nsubsection {* Type definition *}\n\ntypedef ('a::len0) signed = \"UNIV :: 'a set\" ..\n\nlemma card_signed [simp]: \"CARD (('a::len0) signed) = CARD('a)\"\n  unfolding type_definition.card [OF type_definition_signed]\n  by simp\n\ninstantiation signed :: (len0) len0\nbegin\n\ndefinition\n  len_signed [simp]: \"len_of (x::'a::len0 signed itself) = len_of TYPE('a)\"\n\ninstance ..\n\nend\n\ninstance signed :: (len) len\n  by (intro_classes, simp)\n\ntype_synonym 'a sword = \"('a signed) word\"\ntype_synonym sword8 = \"8 sword\"\ntype_synonym sword16 = \"16 sword\"\ntype_synonym sword32 = \"32 sword\"\ntype_synonym sword64 = \"64 sword\"\n\nend\n", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/lib/SignedWords.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.25919102195464}}
{"text": "(*  Title:       OAWN_Convert.thy\n    License:     BSD 2-Clause. See LICENSE.\n    Author:      Timothy Bourke\n*)\n\nheader \"Transfer standard invariants into open invariants\"\n\ntheory OAWN_Convert\nimports AWN_SOS_Labels AWN_Invariants\n        OAWN_SOS OAWN_Invariants\nbegin\n\ndefinition initiali :: \"'i \\<Rightarrow> (('i \\<Rightarrow> 'g) \\<times> 'l) set \\<Rightarrow> ('g \\<times> 'l) set \\<Rightarrow> bool\"\nwhere \"initiali i OI CI \\<equiv> ({(\\<sigma> i, p)|\\<sigma> p. (\\<sigma>, p) \\<in> OI} = CI)\"\n\nlemma initialiI [intro]:\n  assumes OICI: \"\\<And>\\<sigma> p. (\\<sigma>, p) \\<in> OI \\<Longrightarrow> (\\<sigma> i, p) \\<in> CI\"\n      and CIOI: \"\\<And>\\<xi> p. (\\<xi>, p) \\<in> CI \\<Longrightarrow> \\<exists>\\<sigma>. \\<xi> = \\<sigma> i \\<and> (\\<sigma>, p) \\<in> OI\"\n    shows \"initiali i OI CI\"\n  unfolding initiali_def\n  by (intro set_eqI iffI) (auto elim!: OICI CIOI)\n\nlemma open_from_initialiD [dest]:\n  assumes \"initiali i OI CI\"\n      and \"(\\<sigma>, p) \\<in> OI\"\n    shows \"\\<exists>\\<xi>. \\<sigma> i = \\<xi> \\<and> (\\<xi>, p) \\<in> CI\"\n  using assms unfolding initiali_def by auto\n\nlemma closed_from_initialiD [dest]:\n  assumes \"initiali i OI CI\"\n      and \"(\\<xi>, p) \\<in> CI\"\n    shows \"\\<exists>\\<sigma>. \\<sigma> i = \\<xi> \\<and> (\\<sigma>, p) \\<in> OI\"\n  using assms unfolding initiali_def by auto\n\ndefinition\n  seql :: \"'i \\<Rightarrow> (('s \\<times> 'l) \\<Rightarrow> bool) \\<Rightarrow> (('i \\<Rightarrow> 's) \\<times> 'l) \\<Rightarrow> bool\"\nwhere\n  \"seql i P \\<equiv> (\\<lambda>(\\<sigma>, p). P (\\<sigma> i, p))\"\n\nlemma seqlI [intro]:\n  \"P (fst s i, snd s) \\<Longrightarrow> seql i P s\"\n  by (clarsimp simp: seql_def)\n\nlemma same_seql [elim]:\n  assumes \"\\<forall>j\\<in>{i}. \\<sigma>' j = \\<sigma> j\"\n      and \"seql i P (\\<sigma>', s)\"\n    shows \"seql i P (\\<sigma>, s)\"\n  using assms unfolding seql_def by (clarsimp)\n\nlemma seqlsimp:\n  \"seql i P (\\<sigma>, p) = P (\\<sigma> i, p)\"\n  unfolding seql_def by simp\n\nlemma other_steps_resp_local [intro!, simp]: \"other_steps (other A I) I\"\n  by (clarsimp elim!: otherE)\n\nlemma seql_onl_swap:\n  \"seql i (onl \\<Gamma> P) = onl \\<Gamma> (seql i P)\"\n  unfolding seql_def onl_def by simp\n\nlemma oseqp_sos_resp_local_steps [intro!, simp]:\n  fixes \\<Gamma> :: \"'p \\<Rightarrow> ('s, 'm, 'p, 'l) seqp\"\n  shows \"local_steps (oseqp_sos \\<Gamma> i) {i}\"\n  proof\n    fix \\<sigma> \\<sigma>' \\<zeta> \\<zeta>' :: \"nat \\<Rightarrow> 's\" and s a s'\n    assume tr: \"((\\<sigma>, s), a, \\<sigma>', s') \\<in> oseqp_sos \\<Gamma> i\"\n       and \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j\"\n    thus \"\\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and> ((\\<zeta>, s), a, (\\<zeta>', s')) \\<in> oseqp_sos \\<Gamma> i\"\n    proof induction\n      fix \\<sigma> \\<sigma>' l ms p\n      assume \"\\<sigma>' i = \\<sigma> i\"\n         and \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j\"\n      hence \"((\\<zeta>, {l}broadcast(ms).p), broadcast (ms (\\<sigma> i)), (\\<sigma>', p)) \\<in> oseqp_sos \\<Gamma> i\"\n        by (metis obroadcastT singleton_iff)\n      with \\<open>\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j\\<close> show \"\\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and>\n            ((\\<zeta>, {l}broadcast(ms).p), broadcast (ms (\\<sigma> i)), (\\<zeta>', p)) \\<in> oseqp_sos \\<Gamma> i\"\n        by blast\n    next\n      fix \\<sigma> \\<sigma>' :: \"nat \\<Rightarrow> 's\" and fmsg :: \"'m \\<Rightarrow> 's \\<Rightarrow> 's\" and msg l p\n      assume *:  \"\\<sigma>' i = fmsg msg (\\<sigma> i)\"\n         and **: \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j\"\n      hence \"\\<forall>j\\<in>{i}. (\\<zeta>(i := fmsg msg (\\<zeta> i))) j = \\<sigma>' j\" by clarsimp\n      moreover from * **\n        have \"((\\<zeta>, {l}receive(fmsg).p), receive msg, (\\<zeta>(i := fmsg msg (\\<zeta> i)), p)) \\<in> oseqp_sos \\<Gamma> i\"\n        by (metis fun_upd_same oreceiveT)\n      ultimately show \"\\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and>\n                            ((\\<zeta>, {l}receive(fmsg).p), receive msg, (\\<zeta>', p)) \\<in> oseqp_sos \\<Gamma> i\"\n        by blast\n    next\n      fix \\<sigma>' \\<sigma> l p and fas :: \"'s \\<Rightarrow> 's\"\n      assume *:  \"\\<sigma>' i = fas (\\<sigma> i)\"\n         and **: \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j\"\n      hence \"\\<forall>j\\<in>{i}. (\\<zeta>(i := fas (\\<zeta> i))) j = \\<sigma>' j\" by clarsimp\n      moreover from * ** have \"((\\<zeta>, {l}\\<lbrakk>fas\\<rbrakk> p), \\<tau>, (\\<zeta>(i := fas (\\<zeta> i)), p)) \\<in> oseqp_sos \\<Gamma> i\"\n        by (metis fun_upd_same oassignT)\n      ultimately show \"\\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and> ((\\<zeta>, {l}\\<lbrakk>fas\\<rbrakk> p), \\<tau>, (\\<zeta>', p)) \\<in> oseqp_sos \\<Gamma> i\"\n        by blast\n    next\n      fix g :: \"'s \\<Rightarrow> 's set\" and \\<sigma> \\<sigma>' l p\n      assume *:  \"\\<sigma>' i \\<in> g (\\<sigma> i)\"\n         and **: \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j\"\n      hence \"\\<forall>j\\<in>{i}. (SOME \\<zeta>'. \\<zeta>' i = \\<sigma>' i) j = \\<sigma>' j\" by simp (metis (lifting, full_types) some_eq_ex)\n      moreover with * ** have \"((\\<zeta>, {l}\\<langle>g\\<rangle> p), \\<tau>, (SOME \\<zeta>'. \\<zeta>' i = \\<sigma>' i, p)) \\<in> oseqp_sos \\<Gamma> i\"\n        by simp (metis oguardT step_seq_tau)\n      ultimately show \"\\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and> ((\\<zeta>, {l}\\<langle>g\\<rangle> p), \\<tau>, (\\<zeta>', p)) \\<in> oseqp_sos \\<Gamma> i\"\n        by blast\n    next\n      fix \\<sigma> pn a \\<sigma>' p'\n      assume \"((\\<sigma>, \\<Gamma> pn), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n         and IH: \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j \\<Longrightarrow> \\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and> ((\\<zeta>, \\<Gamma> pn), a, (\\<zeta>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n         and \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j\"\n      then obtain \\<zeta>' where \"\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j\"\n                       and \"((\\<zeta>, \\<Gamma> pn), a, (\\<zeta>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n        by blast\n      thus \"\\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and> ((\\<zeta>, call(pn)), a, (\\<zeta>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n        by blast\n    next\n      fix \\<sigma> p a \\<sigma>' p' q\n      assume \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n         and \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j \\<Longrightarrow> \\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and> ((\\<zeta>, p), a, (\\<zeta>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n         and \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j\"\n      then obtain \\<zeta>' where \"\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j\"\n                       and \"((\\<zeta>, p), a, (\\<zeta>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n        by blast\n      thus \"\\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and> ((\\<zeta>, p \\<oplus> q), a, (\\<zeta>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n        by blast\n    next\n      fix \\<sigma> p a \\<sigma>' q q'\n      assume \"((\\<sigma>, q), a, (\\<sigma>', q')) \\<in> oseqp_sos \\<Gamma> i\"\n         and \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j \\<Longrightarrow> \\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and> ((\\<zeta>, q), a, (\\<zeta>', q')) \\<in> oseqp_sos \\<Gamma> i\"\n         and \"\\<forall>j\\<in>{i}. \\<zeta> j = \\<sigma> j\"\n      then obtain \\<zeta>' where \"\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j\"\n                       and \"((\\<zeta>, q), a, (\\<zeta>', q')) \\<in> oseqp_sos \\<Gamma> i\"\n        by blast\n      thus \"\\<exists>\\<zeta>'. (\\<forall>j\\<in>{i}. \\<zeta>' j = \\<sigma>' j) \\<and> ((\\<zeta>, p \\<oplus> q), a, (\\<zeta>', q')) \\<in> oseqp_sos \\<Gamma> i\"\n        by blast\n    qed (simp_all, (metis ogroupcastT ounicastT onotunicastT osendT odeliverT)+)\n  qed\n\nlemma oseqp_sos_subreachable [intro!, simp]:\n  assumes \"trans OA = oseqp_sos \\<Gamma> i\"\n    shows \"subreachable OA (other ANY {i}) {i}\"\n  by rule (clarsimp simp add: assms(1))+\n\nlemma oseq_step_is_seq_step:\n    fixes \\<sigma> :: \"ip \\<Rightarrow> 's\"\n  assumes \"((\\<sigma>, p), a :: 'm seq_action, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n      and \"\\<sigma> i = \\<xi>\"\n    shows \"\\<exists>\\<xi>'. \\<sigma>' i = \\<xi>' \\<and> ((\\<xi>, p), a, (\\<xi>', p')) \\<in> seqp_sos \\<Gamma>\"\n  using assms proof induction\n    fix \\<sigma> \\<sigma>' l ms p\n    assume \"\\<sigma>' i = \\<sigma> i\"\n       and \"\\<sigma> i = \\<xi>\"\n    hence \"\\<sigma>' i = \\<xi>\" by simp\n    have \"((\\<xi>, {l}broadcast(ms).p), broadcast (ms \\<xi>), (\\<xi>, p)) \\<in> seqp_sos \\<Gamma>\"\n      by auto\n    with \\<open>\\<sigma> i = \\<xi>\\<close> and \\<open>\\<sigma>' i = \\<xi>\\<close> show \"\\<exists>\\<xi>'. \\<sigma>' i = \\<xi>'\n             \\<and> ((\\<xi>, {l}broadcast(ms).p), broadcast (ms (\\<sigma> i)), (\\<xi>', p)) \\<in> seqp_sos \\<Gamma>\"\n       by clarsimp\n  next\n    fix fmsg :: \"'m \\<Rightarrow> 's \\<Rightarrow> 's\" and msg :: 'm and \\<sigma>' \\<sigma> l p\n    assume \"\\<sigma>' i = fmsg msg (\\<sigma> i)\"\n       and \"\\<sigma> i = \\<xi>\"\n    have \"((\\<xi>, {l}receive(fmsg).p), receive msg, (fmsg msg \\<xi>, p)) \\<in> seqp_sos \\<Gamma>\"\n      by auto\n    with \\<open>\\<sigma>' i = fmsg msg (\\<sigma> i)\\<close> and \\<open>\\<sigma> i = \\<xi>\\<close>\n      show \"\\<exists>\\<xi>'. \\<sigma>' i = \\<xi>' \\<and> ((\\<xi>, {l}receive(fmsg).p), receive msg, (\\<xi>', p)) \\<in> seqp_sos \\<Gamma>\"\n         by clarsimp\n  qed (simp_all, (metis assignT choiceT1 choiceT2 groupcastT guardT\n                        callT unicastT notunicastT sendT deliverT step_seq_tau)+)\n\nlemma reachable_oseq_seqp_sos:\n  assumes \"(\\<sigma>, p) \\<in> reachable OA I\"\n      and \"initiali i (init OA) (init A)\"\n      and spo: \"trans OA = oseqp_sos \\<Gamma> i\"\n      and sp: \"trans A = seqp_sos \\<Gamma>\"\n      shows \"\\<exists>\\<xi>. \\<sigma> i = \\<xi> \\<and> (\\<xi>, p) \\<in> reachable A I\"\n  using assms(1) proof (induction rule: reachable_pair_induct)\n    fix \\<sigma> p\n    assume \"(\\<sigma>, p) \\<in> init OA\"\n    with \\<open>initiali i (init OA) (init A)\\<close> obtain \\<xi> where \"\\<sigma> i = \\<xi>\"\n                                                    and \"(\\<xi>, p) \\<in> init A\"\n      by auto\n    from \\<open>(\\<xi>, p) \\<in> init A\\<close> have \"(\\<xi>, p) \\<in> reachable A I\" ..\n    with \\<open>\\<sigma> i = \\<xi>\\<close> show \"\\<exists>\\<xi>. \\<sigma> i = \\<xi> \\<and> (\\<xi>, p) \\<in> reachable A I\"\n      by auto\n  next\n    fix \\<sigma> p \\<sigma>' p' a\n    assume \"(\\<sigma>, p) \\<in> reachable OA I\"\n       and IH: \"\\<exists>\\<xi>. \\<sigma> i = \\<xi> \\<and> (\\<xi>, p) \\<in> reachable A I\"\n       and otr: \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans OA\"\n       and \"I a\"\n    from IH obtain \\<xi> where \"\\<sigma> i = \\<xi>\"\n                       and cr: \"(\\<xi>, p) \\<in> reachable A I\"\n      by clarsimp\n    from otr and spo have \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\" by simp\n    with \\<open>\\<sigma> i = \\<xi>\\<close> obtain \\<xi>' where \"\\<sigma>' i = \\<xi>'\"\n                               and \"((\\<xi>, p), a, (\\<xi>', p')) \\<in> seqp_sos \\<Gamma>\"\n        by (auto dest!: oseq_step_is_seq_step)\n    from this(2) and sp have ctr: \"((\\<xi>, p), a, (\\<xi>', p')) \\<in> trans A\" by simp\n    from \\<open>(\\<xi>, p) \\<in> reachable A I\\<close> and ctr and \\<open>I a\\<close>\n      have \"(\\<xi>', p') \\<in> reachable A I\" ..\n    with \\<open>\\<sigma>' i = \\<xi>'\\<close> show \"\\<exists>\\<xi>. \\<sigma>' i = \\<xi> \\<and> (\\<xi>, p') \\<in> reachable A I\"\n      by blast\n  qed\n\nlemma reachable_oseq_seqp_sos':\n  assumes \"s \\<in> reachable OA I\"\n      and \"initiali i (init OA) (init A)\"\n      and \"trans OA = oseqp_sos \\<Gamma> i\"\n      and \"trans A = seqp_sos \\<Gamma>\"\n    shows \"\\<exists>\\<xi>. (fst s) i = \\<xi> \\<and> (\\<xi>, snd s) \\<in> reachable A I\"\n  using assms\n  by - (cases s, auto dest: reachable_oseq_seqp_sos)\n\ntext \\<open>\n  Any invariant shown in the (simpler) closed semantics can be transferred to an invariant in\n  the open semantics.\n\\<close>\n\ntheorem open_seq_invariant [intro]:\n  assumes \"A \\<TTurnstile> (I \\<rightarrow>) P\"\n      and \"initiali i (init OA) (init A)\"\n      and spo: \"trans OA = oseqp_sos \\<Gamma> i\"\n      and sp: \"trans A = seqp_sos \\<Gamma>\"\n    shows \"OA \\<Turnstile> (act I, other ANY {i} \\<rightarrow>) (seql i P)\"\n  proof -\n    have \"OA \\<TTurnstile> (I \\<rightarrow>) (seql i P)\"\n      proof (rule invariant_arbitraryI)\n        fix s                                      \n        assume \"s \\<in> reachable OA I\"\n        with \\<open>initiali i (init OA) (init A)\\<close> obtain \\<xi> where \"(fst s) i = \\<xi>\"\n                                                        and \"(\\<xi>, snd s) \\<in> reachable A I\"\n          by (auto dest: reachable_oseq_seqp_sos' [OF _ _ spo sp])\n        with \\<open>A \\<TTurnstile> (I \\<rightarrow>) P\\<close> have \"P (\\<xi>, snd s)\" by auto\n        with \\<open>(fst s) i = \\<xi>\\<close> show \"seql i P s\" by auto\n      qed\n    moreover from spo have \"subreachable OA (other ANY {i}) {i}\" ..\n    ultimately show ?thesis\n    proof (rule open_closed_invariant)\n      fix \\<sigma> \\<sigma>' s\n      assume \"\\<forall>j\\<in>{i}. \\<sigma>' j = \\<sigma> j\"\n         and \"seql i P (\\<sigma>', s)\"\n      thus \"seql i P (\\<sigma>, s)\" ..\n    qed\n  qed\n\ndefinition\n  seqll :: \"'i \\<Rightarrow> ((('s \\<times> 'l) \\<times> 'a \\<times> ('s \\<times> 'l)) \\<Rightarrow> bool)\n               \\<Rightarrow> ((('i \\<Rightarrow> 's) \\<times> 'l) \\<times> 'a \\<times> (('i \\<Rightarrow> 's) \\<times> 'l)) \\<Rightarrow> bool\"\nwhere\n  \"seqll i P \\<equiv> (\\<lambda>((\\<sigma>, p), a, (\\<sigma>', p')). P ((\\<sigma> i, p), a, (\\<sigma>' i, p')))\"\n\nlemma same_seqll [elim]:\n  assumes \"\\<forall>j\\<in>{i}. \\<sigma>\\<^sub>1' j = \\<sigma>\\<^sub>1 j\"\n      and \"\\<forall>j\\<in>{i}. \\<sigma>\\<^sub>2' j = \\<sigma>\\<^sub>2 j\"\n      and \"seqll i P ((\\<sigma>\\<^sub>1', s), a, (\\<sigma>\\<^sub>2', s'))\"\n    shows \"seqll i P ((\\<sigma>\\<^sub>1,  s), a, (\\<sigma>\\<^sub>2,  s'))\"\n  using assms unfolding seqll_def by (clarsimp)\n\nlemma seqllI [intro!]:\n  assumes \"P ((\\<sigma> i, p), a, (\\<sigma>' i, p'))\"\n    shows \"seqll i P ((\\<sigma>, p), a, (\\<sigma>', p'))\"\n  using assms unfolding seqll_def by simp\n\nlemma seqllD [dest]:\n  assumes \"seqll i P ((\\<sigma>, p), a, (\\<sigma>', p'))\"\n    shows \"P ((\\<sigma> i, p), a, (\\<sigma>' i, p'))\"\n  using assms unfolding seqll_def by simp\n\nlemma seqllsimp:\n  \"seqll i P ((\\<sigma>, p), a, (\\<sigma>', p')) = P ((\\<sigma> i, p), a, (\\<sigma>' i, p'))\"\n  unfolding seqll_def by simp\n\nlemma seqll_onll_swap:\n  \"seqll i (onll \\<Gamma> P) = onll \\<Gamma> (seqll i P)\"\n  unfolding seqll_def onll_def by simp\n\ntheorem open_seq_step_invariant [intro]:\n  assumes \"A \\<TTurnstile>\\<^sub>A (I \\<rightarrow>) P\"\n      and \"initiali i (init OA) (init A)\"\n      and spo: \"trans OA = oseqp_sos \\<Gamma> i\"\n      and sp: \"trans A = seqp_sos \\<Gamma>\"\n    shows \"OA \\<Turnstile>\\<^sub>A (act I, other ANY {i} \\<rightarrow>) (seqll i P)\"\n  proof -\n    have \"OA \\<TTurnstile>\\<^sub>A (I \\<rightarrow>) (seqll i P)\"\n    proof (rule step_invariant_arbitraryI)\n      fix \\<sigma> p a \\<sigma>' p'\n      assume or: \"(\\<sigma>, p) \\<in> reachable OA I\"\n         and otr: \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans OA\"\n         and \"I a\"\n      from or \\<open>initiali i (init OA) (init A)\\<close> spo sp obtain \\<xi> where \"\\<sigma> i = \\<xi>\"\n                                                             and cr: \"(\\<xi>, p) \\<in> reachable A I\"\n        by - (drule(3) reachable_oseq_seqp_sos', auto)\n      from otr and spo have \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\" by simp\n      with \\<open>\\<sigma> i = \\<xi>\\<close> obtain \\<xi>' where \"\\<sigma>' i = \\<xi>'\"\n                                 and ctr: \"((\\<xi>, p), a, (\\<xi>', p')) \\<in> seqp_sos \\<Gamma>\"\n        by (auto dest!: oseq_step_is_seq_step)\n      with sp have \"((\\<xi>, p), a, (\\<xi>', p')) \\<in> trans A\" by simp\n      with \\<open>A \\<TTurnstile>\\<^sub>A (I \\<rightarrow>) P\\<close> cr have \"P ((\\<xi>, p), a, (\\<xi>', p'))\" using \\<open>I a\\<close> ..\n      with \\<open>\\<sigma> i = \\<xi>\\<close> and \\<open>\\<sigma>' i = \\<xi>'\\<close> have \"P ((\\<sigma> i, p), a, (\\<sigma>' i, p'))\" by simp\n      thus \"seqll i P ((\\<sigma>, p), a, (\\<sigma>', p'))\" ..\n    qed\n    moreover from spo have \"local_steps (trans OA) {i}\" by simp\n    moreover have \"other_steps (other ANY {i}) {i}\" ..\n    ultimately show ?thesis\n    proof (rule open_closed_step_invariant)\n      fix \\<sigma> \\<zeta> a \\<sigma>' \\<zeta>' s s'\n      assume \"\\<forall>j\\<in>{i}. \\<sigma> j = \\<zeta> j\"\n         and \"\\<forall>j\\<in>{i}. \\<sigma>' j = \\<zeta>' j\"\n         and \"seqll i P ((\\<sigma>, s), a, (\\<sigma>', s'))\"\n        thus \"seqll i P ((\\<zeta>, s), a, (\\<zeta>', s'))\" ..\n    qed\n  qed\n\nend\n\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/AWN/OAWN_Convert.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.25919102195464}}
{"text": "(*  Title:       OAWN_Invariants.thy\n    License:     BSD 2-Clause. See LICENSE.\n    Author:      Timothy Bourke\n*)\n\nsection \"Generic open invariants on sequential AWN processes\"\n\ntheory OAWN_Invariants\nimports Invariants OInvariants\n        AWN_Cterms AWN_Labels AWN_Invariants\n        OAWN_SOS\nbegin\n\nsubsection \"Open invariants via labelled control terms\"\n\nlemma oseqp_sos_subterms:\n  assumes \"wellformed \\<Gamma>\"\n      and \"\\<exists>pn. p \\<in> subterms (\\<Gamma> pn)\"\n      and \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n    shows \"\\<exists>pn. p' \\<in> subterms (\\<Gamma> pn)\"\n  using assms\n  proof (induct p)\n    fix p1 p2\n    assume IH1: \"\\<exists>pn. p1 \\<in> subterms (\\<Gamma> pn) \\<Longrightarrow>\n                      ((\\<sigma>, p1), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i \\<Longrightarrow>\n                      \\<exists>pn. p' \\<in> subterms (\\<Gamma> pn)\"\n       and IH2: \"\\<exists>pn. p2 \\<in> subterms (\\<Gamma> pn) \\<Longrightarrow>\n                      ((\\<sigma>, p2), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i \\<Longrightarrow>\n                      \\<exists>pn. p' \\<in> subterms (\\<Gamma> pn)\"\n       and \"\\<exists>pn. p1 \\<oplus> p2 \\<in> subterms (\\<Gamma> pn)\"\n       and \"((\\<sigma>, p1 \\<oplus> p2), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n    from \\<open>\\<exists>pn. p1 \\<oplus> p2 \\<in> subterms (\\<Gamma> pn)\\<close> obtain pn\n                                            where \"p1 \\<in> subterms (\\<Gamma> pn)\"\n                                              and \"p2 \\<in> subterms (\\<Gamma> pn)\" by auto\n    from \\<open>((\\<sigma>, p1 \\<oplus> p2), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\\<close>\n      have \"((\\<sigma>, p1), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\n            \\<or> ((\\<sigma>, p2), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\" by auto\n    thus \"\\<exists>pn. p' \\<in> subterms (\\<Gamma> pn)\"\n    proof\n      assume \"((\\<sigma>, p1), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n      with \\<open>p1 \\<in> subterms (\\<Gamma> pn)\\<close> show ?thesis by (auto intro: IH1)\n    next\n      assume \"((\\<sigma>, p2), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n      with \\<open>p2 \\<in> subterms (\\<Gamma> pn)\\<close> show ?thesis by (auto intro: IH2)\n    qed\n  qed auto\n\nlemma oreachable_subterms:\n  assumes \"wellformed \\<Gamma>\"\n      and \"control_within \\<Gamma> (init A)\"\n      and \"trans A = oseqp_sos \\<Gamma> i\"\n      and \"(\\<sigma>, p) \\<in> oreachable A S U\"\n    shows \"\\<exists>pn. p \\<in> subterms (\\<Gamma> pn)\"\n  using assms(4)\n  proof (induct rule: oreachable_pair_induct)\n    fix \\<sigma> p\n    assume \"(\\<sigma>, p) \\<in> init A\"\n    with \\<open>control_within \\<Gamma> (init A)\\<close> show \"\\<exists>pn. p \\<in> subterms (\\<Gamma> pn)\" ..\n  next\n    fix \\<sigma> p a \\<sigma>' p'\n    assume \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and \"\\<exists>pn. p \\<in> subterms (\\<Gamma> pn)\"\n       and 3: \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A\"\n       and \"S \\<sigma> \\<sigma>' a\"\n    moreover from 3 and \\<open>trans A = oseqp_sos \\<Gamma> i\\<close>\n      have \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\" by simp\n    ultimately show \"\\<exists>pn. p' \\<in> subterms (\\<Gamma> pn)\"\n    using \\<open>wellformed \\<Gamma>\\<close>\n      by (auto elim: oseqp_sos_subterms)\n  qed\n\nlemma onl_oinvariantI [intro]:\n  assumes init: \"\\<And>\\<sigma> p l. \\<lbrakk> (\\<sigma>, p) \\<in> init A; l \\<in> labels \\<Gamma> p \\<rbrakk> \\<Longrightarrow> P (\\<sigma>, l)\"\n      and other: \"\\<And>\\<sigma> \\<sigma>' p l. \\<lbrakk> (\\<sigma>, p) \\<in> oreachable A S U;\n                                \\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l);\n                                U \\<sigma> \\<sigma>' \\<rbrakk> \\<Longrightarrow> \\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>', l)\"\n      and step: \"\\<And>\\<sigma> p a \\<sigma>' p' l'.\n                   \\<lbrakk> (\\<sigma>, p) \\<in> oreachable A S U;\n                     \\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l);\n                     ((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A;\n                     l' \\<in> labels \\<Gamma> p';\n                     S \\<sigma> \\<sigma>' a \\<rbrakk> \\<Longrightarrow> P (\\<sigma>', l')\"\n    shows \"A \\<Turnstile> (S, U \\<rightarrow>) onl \\<Gamma> P\"\n  proof\n    fix \\<sigma> p\n    assume \"(\\<sigma>, p) \\<in> init A\"\n    hence \"\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l)\" using init by simp\n    thus \"onl \\<Gamma> P (\\<sigma>, p)\" ..\n  next\n    fix \\<sigma> p a \\<sigma>' p'\n    assume rp: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and \"onl \\<Gamma> P (\\<sigma>, p)\"\n       and tr: \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A\"\n       and \"S \\<sigma> \\<sigma>' a\"\n    from \\<open>onl \\<Gamma> P (\\<sigma>, p)\\<close> have \"\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l)\" ..\n    with rp tr \\<open>S \\<sigma> \\<sigma>' a\\<close> have \"\\<forall>l'\\<in>labels \\<Gamma> p'. P (\\<sigma>', l')\" by (auto elim: step)\n    thus \"onl \\<Gamma> P (\\<sigma>', p')\" ..\n  next\n    fix \\<sigma> \\<sigma>' p\n    assume \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and \"onl \\<Gamma> P (\\<sigma>, p)\"\n       and \"U \\<sigma> \\<sigma>'\"\n    from \\<open>onl \\<Gamma> P (\\<sigma>, p)\\<close> have \"\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l)\" by auto\n    with \\<open>(\\<sigma>, p) \\<in> oreachable A S U\\<close> have \"\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>', l)\"\n        using \\<open>U \\<sigma> \\<sigma>'\\<close> by (rule other)\n    thus \"onl \\<Gamma> P (\\<sigma>', p)\" by auto\n  qed\n\nlemma global_oinvariantI [intro]:\n  assumes init: \"\\<And>\\<sigma> p. (\\<sigma>, p) \\<in> init A \\<Longrightarrow> P \\<sigma>\"\n      and other: \"\\<And>\\<sigma> \\<sigma>' p l. \\<lbrakk> (\\<sigma>, p) \\<in> oreachable A S U; P \\<sigma>; U \\<sigma> \\<sigma>' \\<rbrakk> \\<Longrightarrow> P \\<sigma>'\"\n      and step: \"\\<And>\\<sigma> p a \\<sigma>' p'.\n                   \\<lbrakk> (\\<sigma>, p) \\<in> oreachable A S U;\n                     P \\<sigma>;\n                     ((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A;\n                     S \\<sigma> \\<sigma>' a \\<rbrakk> \\<Longrightarrow> P \\<sigma>'\"\n    shows \"A \\<Turnstile> (S, U \\<rightarrow>) (\\<lambda>(\\<sigma>, _). P \\<sigma>)\"\n  proof\n    fix \\<sigma> p\n    assume \"(\\<sigma>, p) \\<in> init A\"\n    thus \"(\\<lambda>(\\<sigma>, _). P \\<sigma>) (\\<sigma>, p)\"\n      by simp (erule init)\n  next\n    fix \\<sigma> p a \\<sigma>' p'\n    assume rp: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and \"(\\<lambda>(\\<sigma>, _). P \\<sigma>) (\\<sigma>, p)\"\n       and tr: \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A\"\n       and \"S \\<sigma> \\<sigma>' a\"\n    from \\<open>(\\<lambda>(\\<sigma>, _). P \\<sigma>) (\\<sigma>, p)\\<close> have \"P \\<sigma>\" by simp\n    with rp have \"P \\<sigma>'\"\n      using tr \\<open>S \\<sigma> \\<sigma>' a\\<close> by (rule step)\n    thus \"(\\<lambda>(\\<sigma>, _). P \\<sigma>) (\\<sigma>', p')\" by simp\n  next\n    fix \\<sigma> \\<sigma>' p\n    assume \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and \"(\\<lambda>(\\<sigma>, _). P \\<sigma>) (\\<sigma>, p)\"\n       and \"U \\<sigma> \\<sigma>'\"\n    hence \"P \\<sigma>'\" by simp (erule other)\n    thus \"(\\<lambda>(\\<sigma>, _). P \\<sigma>) (\\<sigma>', p)\" by simp\n  qed\n\nlemma onl_oinvariantD [dest]:\n  assumes \"A \\<Turnstile> (S, U \\<rightarrow>) onl \\<Gamma> P\"\n      and \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and \"l \\<in> labels \\<Gamma> p\"\n    shows \"P (\\<sigma>, l)\"\n  using assms unfolding onl_def by auto\n\nlemma onl_oinvariant_weakenD [dest]:\n  assumes \"A \\<Turnstile> (S', U' \\<rightarrow>) onl \\<Gamma> P\"\n      and \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and \"l \\<in> labels \\<Gamma> p\"\n      and weakenS: \"\\<And>s s' a. S s s' a \\<Longrightarrow> S' s s' a\"\n      and weakenU: \"\\<And>s s'. U s s' \\<Longrightarrow> U' s s'\"\n    shows \"P (\\<sigma>, l)\"\n  proof -\n    from \\<open>(\\<sigma>, p) \\<in> oreachable A S U\\<close> have \"(\\<sigma>, p) \\<in> oreachable A S' U'\"\n      by (rule oreachable_weakenE)\n         (erule weakenS, erule weakenU)\n    with \\<open>A \\<Turnstile> (S', U' \\<rightarrow>) onl \\<Gamma> P\\<close> show \"P (\\<sigma>, l)\"\n      using \\<open>l \\<in> labels \\<Gamma> p\\<close> ..\n  qed\n\nlemma onl_oinvariant_initD [dest]:\n  assumes invP: \"A \\<Turnstile> (S, U \\<rightarrow>) onl \\<Gamma> P\"\n      and init: \"(\\<sigma>, p) \\<in> init A\"\n      and pnl:  \"l \\<in> labels \\<Gamma> p\"\n    shows \"P (\\<sigma>, l)\"\n  proof -\n    from init have \"(\\<sigma>, p) \\<in> oreachable A S U\" ..\n    with invP show ?thesis using pnl ..\n  qed\n\nlemma onl_oinvariant_sterms:\n  assumes wf: \"wellformed \\<Gamma>\"\n      and il: \"A \\<Turnstile> (S, U \\<rightarrow>) onl \\<Gamma> P\"\n      and rp: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and \"p'\\<in>sterms \\<Gamma> p\"\n      and \"l\\<in>labels \\<Gamma> p'\"\n    shows \"P (\\<sigma>, l)\"\n  proof -\n    from wf \\<open>p'\\<in>sterms \\<Gamma> p\\<close> \\<open>l\\<in>labels \\<Gamma> p'\\<close> have \"l\\<in>labels \\<Gamma> p\"\n      by (rule labels_sterms_labels)\n    with il rp show \"P (\\<sigma>, l)\" ..\n  qed\n\nlemma onl_oinvariant_sterms_weaken:\n  assumes wf: \"wellformed \\<Gamma>\"\n      and il: \"A \\<Turnstile> (S', U' \\<rightarrow>) onl \\<Gamma> P\"\n      and rp: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and \"p'\\<in>sterms \\<Gamma> p\"\n      and \"l\\<in>labels \\<Gamma> p'\"\n      and weakenS: \"\\<And>\\<sigma> \\<sigma>' a. S \\<sigma> \\<sigma>' a \\<Longrightarrow> S' \\<sigma> \\<sigma>' a\"\n      and weakenU: \"\\<And>\\<sigma> \\<sigma>'. U \\<sigma> \\<sigma>' \\<Longrightarrow> U' \\<sigma> \\<sigma>'\"\n    shows \"P (\\<sigma>, l)\"\n  proof -\n    from \\<open>(\\<sigma>, p) \\<in> oreachable A S U\\<close> have \"(\\<sigma>, p) \\<in> oreachable A S' U'\"\n      by (rule oreachable_weakenE)\n         (erule weakenS, erule weakenU)\n    with assms(1-2) show ?thesis using assms(4-5)\n      by (rule onl_oinvariant_sterms)\n  qed\n\nlemma otrans_from_sterms:\n  assumes \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n      and \"wellformed \\<Gamma>\"\n    shows \"\\<exists>p'\\<in>sterms \\<Gamma> p. ((\\<sigma>, p'), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n  using assms by (induction p rule: sterms_pinduct [OF \\<open>wellformed \\<Gamma>\\<close>]) auto\n\nlemma otrans_from_sterms':\n  assumes \"((\\<sigma>, p'), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n      and \"wellformed \\<Gamma>\"\n      and \"p' \\<in> sterms \\<Gamma> p\"\n    shows \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n  using assms by (induction p rule: sterms_pinduct [OF \\<open>wellformed \\<Gamma>\\<close>]) auto\n\nlemma otrans_to_dterms:\n  assumes \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n      and \"wellformed \\<Gamma>\"\n   shows \"\\<forall>r\\<in>sterms \\<Gamma> q. r \\<in> dterms \\<Gamma> p\"\n  using assms by (induction q) auto\n\ntheorem cterms_includes_sterms_of_oseq_reachable:\n  assumes \"wellformed \\<Gamma>\"\n      and \"control_within \\<Gamma> (init A)\"\n      and \"trans A = oseqp_sos \\<Gamma> i\"\n    shows \"\\<Union>(sterms \\<Gamma> ` snd ` oreachable A S U) \\<subseteq> cterms \\<Gamma>\"\n  proof\n    fix qs\n    assume \"qs \\<in> \\<Union>(sterms \\<Gamma> ` snd ` oreachable A S U)\"\n    then obtain \\<xi> and q where  *: \"(\\<xi>, q) \\<in> oreachable A S U\"\n                          and **: \"qs \\<in> sterms \\<Gamma> q\" by auto\n    from * have \"\\<And>x. x \\<in> sterms \\<Gamma> q \\<Longrightarrow> x \\<in> cterms \\<Gamma>\"\n    proof (induction rule: oreachable_pair_induct)\n      fix \\<sigma> p q\n      assume \"(\\<sigma>, p) \\<in> init A\"\n         and \"q \\<in> sterms \\<Gamma> p\"\n      from \\<open>control_within \\<Gamma> (init A)\\<close> and \\<open>(\\<sigma>, p) \\<in> init A\\<close>\n        obtain pn where \"p \\<in> subterms (\\<Gamma> pn)\" by auto\n      with \\<open>wellformed \\<Gamma>\\<close> show \"q \\<in> cterms \\<Gamma>\" using \\<open>q\\<in>sterms \\<Gamma> p\\<close>\n        by (rule subterms_sterms_in_cterms)\n    next\n      fix p \\<sigma> a \\<sigma>' q x\n      assume \"(\\<sigma>, p) \\<in> oreachable A S U\"\n         and IH: \"\\<And>x. x \\<in> sterms \\<Gamma> p \\<Longrightarrow> x \\<in> cterms \\<Gamma>\"\n         and \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A\"\n         and \"x \\<in> sterms \\<Gamma> q\"\n      from this(3) and \\<open>trans A = oseqp_sos \\<Gamma> i\\<close>\n        have step: \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\" by simp\n      from step \\<open>wellformed \\<Gamma>\\<close> obtain ps\n        where ps: \"ps \\<in> sterms \\<Gamma> p\"\n          and step': \"((\\<sigma>, ps), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n        by (rule otrans_from_sterms [THEN bexE])\n      from ps have \"ps \\<in> cterms \\<Gamma>\" by (rule IH)\n      moreover from step' \\<open>wellformed \\<Gamma>\\<close> \\<open>x \\<in> sterms \\<Gamma> q\\<close> have \"x \\<in> dterms \\<Gamma> ps\"\n        by (rule otrans_to_dterms [rule_format])\n      ultimately show \"x \\<in> cterms \\<Gamma>\" by (rule ctermsDI)\n    qed\n    thus \"qs \\<in> cterms \\<Gamma>\" using ** .\n  qed\n\ncorollary oseq_reachable_in_cterms:\n  assumes \"wellformed \\<Gamma>\"\n      and \"control_within \\<Gamma> (init A)\"\n      and \"trans A = oseqp_sos \\<Gamma> i\"\n      and \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and \"p' \\<in> sterms \\<Gamma> p\"\n    shows \"p' \\<in> cterms \\<Gamma>\"\n  using assms(1-3)\n  proof (rule cterms_includes_sterms_of_oseq_reachable [THEN subsetD])\n    from assms(4-5) show \"p' \\<in> \\<Union>(sterms \\<Gamma> ` snd ` oreachable A S U)\"\n      by (auto elim!: rev_bexI)\n  qed\n\nlemma oseq_invariant_ctermI:\n  assumes wf: \"wellformed \\<Gamma>\"\n      and cw: \"control_within \\<Gamma> (init A)\"\n      and sl: \"simple_labels \\<Gamma>\"\n      and sp: \"trans A = oseqp_sos \\<Gamma> i\"\n      and init: \"\\<And>\\<sigma> p l. \\<lbrakk>\n                   (\\<sigma>, p) \\<in> init A;\n                   l\\<in>labels \\<Gamma> p\n                 \\<rbrakk> \\<Longrightarrow> P (\\<sigma>, l)\"\n      and other: \"\\<And>\\<sigma> \\<sigma>' p l. \\<lbrakk>\n                   (\\<sigma>, p) \\<in> oreachable A S U;\n                   l\\<in>labels \\<Gamma> p;\n                   P (\\<sigma>, l);\n                   U \\<sigma> \\<sigma>' \\<rbrakk> \\<Longrightarrow> P (\\<sigma>', l)\"\n      and local: \"\\<And>p l \\<sigma> a q l' \\<sigma>' pp. \\<lbrakk>\n                 p\\<in>cterms \\<Gamma>;\n                 l\\<in>labels \\<Gamma> p;\n                 P (\\<sigma>, l);\n                 ((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i;\n                 ((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A;\n                 l'\\<in>labels \\<Gamma> q;\n                 (\\<sigma>, pp)\\<in>oreachable A S U;\n                 p\\<in>sterms \\<Gamma> pp;\n                 (\\<sigma>', q)\\<in>oreachable A S U;\n                 S \\<sigma> \\<sigma>' a\n               \\<rbrakk> \\<Longrightarrow> P (\\<sigma>', l')\"\n    shows \"A \\<Turnstile> (S, U \\<rightarrow>) onl \\<Gamma> P\"\n  proof\n       fix \\<sigma> p l\n    assume \"(\\<sigma>, p) \\<in> init A\"\n       and *: \"l \\<in> labels \\<Gamma> p\"\n      with init show \"P (\\<sigma>, l)\" by auto\n  next\n       fix \\<sigma> p a \\<sigma>' q l'\n    assume sr: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and pl: \"\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l)\"\n       and tr: \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A\"\n       and A6: \"l' \\<in> labels \\<Gamma> q\"\n       and \"S \\<sigma> \\<sigma>' a\"\n      thus \"P (\\<sigma>', l')\"\n    proof -\n      from sr and tr and \\<open>S \\<sigma> \\<sigma>' a\\<close> have A7: \"(\\<sigma>', q) \\<in> oreachable A S U\"\n        by - (rule oreachable_local')\n      from tr and sp have tr': \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\" by simp\n      then obtain p' where \"p' \\<in> sterms \\<Gamma> p\"\n                       and A4: \"((\\<sigma>, p'), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n        by (blast dest: otrans_from_sterms [OF _ wf])\n      from wf cw sp sr this(1) have A1: \"p'\\<in>cterms \\<Gamma>\"\n        by (rule oseq_reachable_in_cterms)\n      from labels_not_empty [OF wf] obtain ll where A2: \"ll\\<in>labels \\<Gamma> p'\"\n          by blast\n      with \\<open>p'\\<in>sterms \\<Gamma> p\\<close> have \"ll\\<in>labels \\<Gamma> p\"\n        by (rule labels_sterms_labels [OF wf])\n      with pl have A3: \"P (\\<sigma>, ll)\" by simp\n      from sr \\<open>p'\\<in>sterms \\<Gamma> p\\<close>\n        obtain pp where A7: \"(\\<sigma>, pp)\\<in>oreachable A S U\"\n                    and A8: \"p'\\<in>sterms \\<Gamma> pp\"\n        by auto\n      from sr tr \\<open>S \\<sigma> \\<sigma>' a\\<close> have A9: \"(\\<sigma>', q)\\<in>oreachable A S U\"\n        by - (rule oreachable_local')\n      from sp and \\<open>((\\<sigma>, p'), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\\<close>\n        have A5: \"((\\<sigma>, p'), a, (\\<sigma>', q)) \\<in> trans A\" by simp\n      from A1 A2 A3 A4 A5 A6 A7 A8 A9 \\<open>S \\<sigma> \\<sigma>' a\\<close> show ?thesis by (rule local)\n    qed\n  next\n    fix \\<sigma> \\<sigma>' p l\n    assume sr: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and \"\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l)\"\n       and \"U \\<sigma> \\<sigma>'\"\n    show \"\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>', l)\"\n    proof\n      fix l\n      assume \"l\\<in>labels \\<Gamma> p\"\n      with \\<open>\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l)\\<close> have \"P (\\<sigma>, l)\" ..\n      with sr and \\<open>l\\<in>labels \\<Gamma> p\\<close>\n        show \"P (\\<sigma>', l)\" using \\<open>U \\<sigma> \\<sigma>'\\<close> by (rule other)\n    qed\n  qed\n\nlemma oseq_invariant_ctermsI:\n  assumes wf: \"wellformed \\<Gamma>\"\n      and cw: \"control_within \\<Gamma> (init A)\"\n      and sl: \"simple_labels \\<Gamma>\"\n      and sp: \"trans A = oseqp_sos \\<Gamma> i\"\n      and init: \"\\<And>\\<sigma> p l. \\<lbrakk>\n                   (\\<sigma>, p) \\<in> init A;\n                   l\\<in>labels \\<Gamma> p\n                 \\<rbrakk> \\<Longrightarrow> P (\\<sigma>, l)\"\n      and other: \"\\<And>\\<sigma> \\<sigma>' p l. \\<lbrakk>\n                   wellformed \\<Gamma>;\n                   (\\<sigma>, p) \\<in> oreachable A S U;\n                   l\\<in>labels \\<Gamma> p;\n                   P (\\<sigma>, l);\n                   U \\<sigma> \\<sigma>' \\<rbrakk> \\<Longrightarrow> P (\\<sigma>', l)\"\n      and local: \"\\<And>p l \\<sigma> a q l' \\<sigma>' pp pn. \\<lbrakk>\n                 wellformed \\<Gamma>;\n                 p\\<in>ctermsl (\\<Gamma> pn);\n                 not_call p;\n                 l\\<in>labels \\<Gamma> p;\n                 P (\\<sigma>, l);\n                 ((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i;\n                 ((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A;\n                 l'\\<in>labels \\<Gamma> q;\n                 (\\<sigma>, pp)\\<in>oreachable A S U;\n                 p\\<in>sterms \\<Gamma> pp;\n                 (\\<sigma>', q)\\<in>oreachable A S U;\n                 S \\<sigma> \\<sigma>' a\n               \\<rbrakk> \\<Longrightarrow> P (\\<sigma>', l')\"\n    shows \"A \\<Turnstile> (S, U \\<rightarrow>) onl \\<Gamma> P\"\n  proof (rule oseq_invariant_ctermI [OF wf cw sl sp])\n    fix \\<sigma> p l\n    assume \"(\\<sigma>, p) \\<in> init A\"\n       and \"l \\<in> labels \\<Gamma> p\"\n    thus \"P (\\<sigma>, l)\" by (rule init)\n  next\n    fix \\<sigma> \\<sigma>' p l\n    assume \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and \"l \\<in> labels \\<Gamma> p\"\n       and \"P (\\<sigma>, l)\"\n       and \"U \\<sigma> \\<sigma>'\"\n    with wf show \"P (\\<sigma>', l)\" by (rule other)\n  next\n    fix p l \\<sigma> a q l' \\<sigma>' pp\n    assume \"p \\<in> cterms \\<Gamma>\"\n       and otherassms: \"l \\<in> labels \\<Gamma> p\"\n           \"P (\\<sigma>, l)\"\n           \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n           \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A\"\n           \"l' \\<in> labels \\<Gamma> q\"\n           \"(\\<sigma>, pp) \\<in> oreachable A S U\"\n           \"p \\<in> sterms \\<Gamma> pp\"\n           \"(\\<sigma>', q) \\<in> oreachable A S U\"\n           \"S \\<sigma> \\<sigma>' a\"\n    from this(1) obtain pn where \"p \\<in> ctermsl(\\<Gamma> pn)\"\n                             and \"not_call p\"\n      unfolding cterms_def' [OF wf] by auto\n    with wf show \"P (\\<sigma>', l')\"\n      using otherassms by (rule local)\n  qed\n\nsubsection \"Open step invariants via labelled control terms\"\n\nlemma onll_ostep_invariantI [intro]:\n  assumes *: \"\\<And>\\<sigma> p l a \\<sigma>' p' l'. \\<lbrakk> (\\<sigma>, p)\\<in>oreachable A S U;\n                                   ((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A;\n                                   S \\<sigma> \\<sigma>' a;\n                                   l \\<in>labels \\<Gamma> p;\n                                   l'\\<in>labels \\<Gamma> p' \\<rbrakk>\n                                 \\<Longrightarrow> P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n    shows \"A \\<Turnstile>\\<^sub>A (S, U \\<rightarrow>) onll \\<Gamma> P\"\n  proof\n    fix \\<sigma> p \\<sigma>' p' a\n    assume \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A\"\n       and \"S \\<sigma> \\<sigma>' a\"\n    hence \"\\<forall>l\\<in>labels \\<Gamma> p. \\<forall>l'\\<in>labels \\<Gamma> p'. P ((\\<sigma>, l), a, (\\<sigma>', l'))\" by (auto elim!: *)\n    thus \"onll \\<Gamma> P ((\\<sigma>, p), a, (\\<sigma>', p'))\" ..\n  qed\n\nlemma onll_ostep_invariantE [elim]:\n  assumes \"A \\<Turnstile>\\<^sub>A (S, U \\<rightarrow>) onll \\<Gamma> P\"\n      and \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A\"\n      and \"S \\<sigma> \\<sigma>' a\"\n      and lp:  \"l \\<in>labels \\<Gamma> p\"\n      and lp': \"l'\\<in>labels \\<Gamma> p'\"\n    shows \"P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n  proof -\n    from assms(1-4) have \"onll \\<Gamma> P ((\\<sigma>, p), a, (\\<sigma>', p'))\" ..\n    with lp lp' show \"P ((\\<sigma>, l), a, (\\<sigma>', l'))\" by auto\n  qed\n\nlemma onll_ostep_invariantD [dest]:\n  assumes \"A \\<Turnstile>\\<^sub>A (S, U \\<rightarrow>) onll \\<Gamma> P\"\n      and \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A\"\n      and \"S \\<sigma> \\<sigma>' a\"\n    shows \"\\<forall>l\\<in>labels \\<Gamma> p. \\<forall>l'\\<in>labels \\<Gamma> p'. P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n  using assms by auto\n\nlemma onll_ostep_invariant_weakenD [dest]:\n  assumes \"A \\<Turnstile>\\<^sub>A (S', U' \\<rightarrow>) onll \\<Gamma> P\"\n      and \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A\"\n      and \"S' \\<sigma> \\<sigma>' a\"\n      and weakenS: \"\\<And>s s' a. S s s' a \\<Longrightarrow> S' s s' a\"\n      and weakenU: \"\\<And>s s'. U s s' \\<Longrightarrow> U' s s'\"\n    shows \"\\<forall>l\\<in>labels \\<Gamma> p. \\<forall>l'\\<in>labels \\<Gamma> p'. P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n  proof -\n    from \\<open>(\\<sigma>, p) \\<in> oreachable A S U\\<close> have \"(\\<sigma>, p) \\<in> oreachable A S' U'\"\n      by (rule oreachable_weakenE)\n         (erule weakenS, erule weakenU)\n    with \\<open>A \\<Turnstile>\\<^sub>A (S', U' \\<rightarrow>) onll \\<Gamma> P\\<close> show ?thesis\n      using \\<open>((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A\\<close> and \\<open>S' \\<sigma> \\<sigma>' a\\<close> ..\n  qed\n\nlemma onll_ostep_to_invariantI [intro]:\n  assumes sinv: \"A \\<Turnstile>\\<^sub>A (S, U \\<rightarrow>) onll \\<Gamma> Q\"\n      and wf: \"wellformed \\<Gamma>\"\n      and init: \"\\<And>\\<sigma> l p. \\<lbrakk> (\\<sigma>, p) \\<in> init A; l\\<in>labels \\<Gamma> p \\<rbrakk> \\<Longrightarrow> P (\\<sigma>, l)\"\n      and other: \"\\<And>\\<sigma> \\<sigma>' p l.\n                    \\<lbrakk> (\\<sigma>, p) \\<in> oreachable A S U;\n                      l\\<in>labels \\<Gamma> p;\n                      P (\\<sigma>, l);\n                      U \\<sigma> \\<sigma>' \\<rbrakk> \\<Longrightarrow> P (\\<sigma>', l)\"\n      and local: \"\\<And>\\<sigma> p l \\<sigma>' l' a.\n                    \\<lbrakk> (\\<sigma>, p) \\<in> oreachable A S U;\n                      l\\<in>labels \\<Gamma> p;\n                      P (\\<sigma>, l);\n                      Q ((\\<sigma>, l), a, (\\<sigma>', l'));\n                      S \\<sigma> \\<sigma>' a\\<rbrakk> \\<Longrightarrow> P (\\<sigma>', l')\"\n    shows \"A \\<Turnstile> (S, U \\<rightarrow>) onl \\<Gamma> P\"\n  proof\n    fix \\<sigma> p l\n    assume \"(\\<sigma>, p) \\<in> init A\" and \"l\\<in>labels \\<Gamma> p\"\n      thus \"P (\\<sigma>, l)\" by (rule init)\n  next\n    fix \\<sigma> p a \\<sigma>' p' l'\n    assume sr: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and lp: \"\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l)\"\n       and tr: \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A\"\n       and \"S \\<sigma> \\<sigma>' a\"\n       and lp': \"l' \\<in> labels \\<Gamma> p'\"\n      show \"P (\\<sigma>', l')\"\n    proof -\n      from lp obtain l where \"l\\<in>labels \\<Gamma> p\" and \"P (\\<sigma>, l)\"\n        using labels_not_empty [OF wf] by auto\n      from sinv sr tr \\<open>S \\<sigma> \\<sigma>' a\\<close> this(1) lp' have \"Q ((\\<sigma>, l), a, (\\<sigma>', l'))\" ..\n      with sr \\<open>l\\<in>labels \\<Gamma> p\\<close> \\<open>P (\\<sigma>, l)\\<close> show \"P (\\<sigma>', l')\" using \\<open>S \\<sigma> \\<sigma>' a\\<close> by (rule local)\n    qed\n  next\n    fix \\<sigma> \\<sigma>' p l\n    assume \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and \"\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l)\"\n       and \"U \\<sigma> \\<sigma>'\"\n      show \"\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>', l)\"\n    proof\n      fix l\n      assume \"l\\<in>labels \\<Gamma> p\"\n      with \\<open>\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l)\\<close> have \"P (\\<sigma>, l)\" ..\n      with \\<open>(\\<sigma>, p) \\<in> oreachable A S U\\<close> and \\<open>l\\<in>labels \\<Gamma> p\\<close>\n      show \"P (\\<sigma>', l)\" using \\<open>U \\<sigma> \\<sigma>'\\<close> by (rule other)\n    qed\n  qed\n\nlemma onll_ostep_invariant_sterms:\n  assumes wf: \"wellformed \\<Gamma>\"\n      and si: \"A \\<Turnstile>\\<^sub>A (S, U \\<rightarrow>) onll \\<Gamma> P\"\n      and sr: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and sos: \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A\"\n      and \"S \\<sigma> \\<sigma>' a\"\n      and \"l'\\<in>labels \\<Gamma> q\"\n      and \"p'\\<in>sterms \\<Gamma> p\"\n      and \"l\\<in>labels \\<Gamma> p'\"\n    shows \"P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n  proof -\n    from wf \\<open>p'\\<in>sterms \\<Gamma> p\\<close> \\<open>l\\<in>labels \\<Gamma> p'\\<close> have \"l\\<in>labels \\<Gamma> p\"\n      by (rule labels_sterms_labels)\n    with si sr sos \\<open>S \\<sigma> \\<sigma>' a\\<close> show \"P ((\\<sigma>, l), a, (\\<sigma>', l'))\" using \\<open>l'\\<in>labels \\<Gamma> q\\<close> ..\n  qed\n\nlemma oseq_step_invariant_sterms:\n  assumes inv: \"A \\<Turnstile>\\<^sub>A (S, U \\<rightarrow>) onll \\<Gamma> P\"\n      and wf: \"wellformed \\<Gamma>\"\n      and sp: \"trans A = oseqp_sos \\<Gamma> i\"\n      and \"l'\\<in>labels \\<Gamma> q\"\n      and sr: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and tr: \"((\\<sigma>, p'), a, (\\<sigma>', q)) \\<in> trans A\"\n      and \"S \\<sigma> \\<sigma>' a\"\n      and \"p'\\<in>sterms \\<Gamma> p\"\n    shows \"\\<forall>l\\<in>labels \\<Gamma> p'. P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n  proof\n    from assms(3, 6) have \"((\\<sigma>, p'), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\" by simp\n    hence \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n      using wf \\<open>p'\\<in>sterms \\<Gamma> p\\<close>  by (rule otrans_from_sterms')\n    with assms(3) have trp: \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A\" by simp\n    fix l assume \"l \\<in> labels \\<Gamma> p'\"\n    with wf inv sr trp \\<open>S \\<sigma> \\<sigma>' a\\<close> \\<open>l'\\<in>labels \\<Gamma> q\\<close> \\<open>p'\\<in>sterms \\<Gamma> p\\<close>\n      show \"P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n        by - (erule(7) onll_ostep_invariant_sterms)\n  qed\n\nlemma oseq_step_invariant_sterms_weaken:\n  assumes inv: \"A \\<Turnstile>\\<^sub>A (S, U \\<rightarrow>) onll \\<Gamma> P\"\n      and wf: \"wellformed \\<Gamma>\"\n      and sp: \"trans A = oseqp_sos \\<Gamma> i\"\n      and \"l'\\<in>labels \\<Gamma> q\"\n      and sr: \"(\\<sigma>, p) \\<in> oreachable A S' U'\"\n      and tr: \"((\\<sigma>, p'), a, (\\<sigma>', q)) \\<in> trans A\"\n      and \"S' \\<sigma> \\<sigma>' a\"\n      and \"p'\\<in>sterms \\<Gamma> p\"\n      and weakenS: \"\\<And>\\<sigma> \\<sigma>' a. S' \\<sigma> \\<sigma>' a \\<Longrightarrow> S \\<sigma> \\<sigma>' a\"\n      and weakenU: \"\\<And>\\<sigma> \\<sigma>'. U' \\<sigma> \\<sigma>' \\<Longrightarrow> U \\<sigma> \\<sigma>'\"\n    shows \"\\<forall>l\\<in>labels \\<Gamma> p'. P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n  proof -\n    from \\<open>S' \\<sigma> \\<sigma>' a\\<close> have \"S \\<sigma> \\<sigma>' a\" by (rule weakenS)\n    from \\<open>(\\<sigma>, p) \\<in> oreachable A S' U'\\<close>\n      have Ir: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n        by (rule oreachable_weakenE)\n           (erule weakenS, erule weakenU)\n    with assms(1-4) show ?thesis\n      using tr \\<open>S \\<sigma> \\<sigma>' a\\<close> \\<open>p'\\<in>sterms \\<Gamma> p\\<close>\n      by (rule oseq_step_invariant_sterms)\n  qed\n\nlemma onll_ostep_invariant_any_sterms:\n  assumes wf: \"wellformed \\<Gamma>\"\n      and si: \"A \\<Turnstile>\\<^sub>A (S, U \\<rightarrow>) onll \\<Gamma> P\"\n      and sr: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and sos: \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A\"\n      and \"S \\<sigma> \\<sigma>' a\"\n      and \"l'\\<in>labels \\<Gamma> q\"\n    shows \"\\<forall>p'\\<in>sterms \\<Gamma> p. \\<forall>l\\<in>labels \\<Gamma> p'. P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n  by (intro ballI) (rule onll_ostep_invariant_sterms [OF assms])\n\nlemma oseq_step_invariant_ctermI [intro]:\n  assumes wf: \"wellformed \\<Gamma>\"\n      and cw: \"control_within \\<Gamma> (init A)\"\n      and sl: \"simple_labels \\<Gamma>\"\n      and sp: \"trans A = oseqp_sos \\<Gamma> i\"\n      and local: \"\\<And>p l \\<sigma> a q l' \\<sigma>' pp. \\<lbrakk>\n                   p\\<in>cterms \\<Gamma>;\n                   l\\<in>labels \\<Gamma> p;\n                   ((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i;\n                   ((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A;\n                   l'\\<in>labels \\<Gamma> q;\n                   (\\<sigma>, pp) \\<in> oreachable A S U;\n                   p\\<in>sterms \\<Gamma> pp;\n                   (\\<sigma>', q) \\<in> oreachable A S U;\n                   S \\<sigma> \\<sigma>' a\n                 \\<rbrakk> \\<Longrightarrow> P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n    shows \"A \\<Turnstile>\\<^sub>A (S, U \\<rightarrow>) onll \\<Gamma> P\"\n  proof\n       fix \\<sigma> p l a \\<sigma>' q l'\n    assume sr: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and tr: \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A\"\n       and \"S \\<sigma> \\<sigma>' a\"\n       and pl: \"l \\<in> labels \\<Gamma> p\"\n       and A5: \"l' \\<in> labels \\<Gamma> q\"\n    from this(2) and sp have \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\" by simp\n    then obtain p' where \"p' \\<in> sterms \\<Gamma> p\"\n                     and A3: \"((\\<sigma>, p'), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n      by (blast dest: otrans_from_sterms [OF _ wf])\n    from this(2) and sp have A4: \"((\\<sigma>, p'), a, (\\<sigma>', q)) \\<in> trans A\" by simp\n    from wf cw sp sr \\<open>p'\\<in>sterms \\<Gamma> p\\<close> have A1: \"p'\\<in>cterms \\<Gamma>\"\n      by (rule oseq_reachable_in_cterms)\n    from sr \\<open>p'\\<in>sterms \\<Gamma> p\\<close>\n      obtain pp where A6: \"(\\<sigma>, pp)\\<in>oreachable A S U\"\n                  and A7: \"p'\\<in>sterms \\<Gamma> pp\"\n      by auto\n    from sr tr \\<open>S \\<sigma> \\<sigma>' a\\<close> have A8: \"(\\<sigma>', q)\\<in>oreachable A S U\"\n      by - (erule(2) oreachable_local')\n    from wf cw sp sr have \"\\<exists>pn. p \\<in> subterms (\\<Gamma> pn)\"\n      by (rule oreachable_subterms)           \n    with sl wf have \"\\<forall>p'\\<in>sterms \\<Gamma> p. l \\<in> labels \\<Gamma> p'\"\n      using pl by (rule simple_labels_in_sterms)\n    with \\<open>p' \\<in> sterms \\<Gamma> p\\<close> have \"l \\<in> labels \\<Gamma> p'\" by simp\n    with A1 show \"P ((\\<sigma>, l), a, (\\<sigma>', l'))\" using A3 A4 A5 A6 A7 A8 \\<open>S \\<sigma> \\<sigma>' a\\<close>\n      by (rule local)\n  qed\n\nlemma oseq_step_invariant_ctermsI [intro]:\n  assumes wf: \"wellformed \\<Gamma>\"\n      and \"control_within \\<Gamma> (init A)\"\n      and \"simple_labels \\<Gamma>\"\n      and \"trans A = oseqp_sos \\<Gamma> i\"\n      and local: \"\\<And>p l \\<sigma> a q l' \\<sigma>' pp pn. \\<lbrakk>\n                   wellformed \\<Gamma>;\n                   p\\<in>ctermsl (\\<Gamma> pn);\n                   not_call p;\n                   l\\<in>labels \\<Gamma> p;\n                   ((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i;\n                   ((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A;\n                   l'\\<in>labels \\<Gamma> q;\n                   (\\<sigma>, pp) \\<in> oreachable A S U;\n                   p\\<in>sterms \\<Gamma> pp;\n                   (\\<sigma>', q) \\<in> oreachable A S U;\n                   S \\<sigma> \\<sigma>' a\n                 \\<rbrakk> \\<Longrightarrow> P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n    shows \"A \\<Turnstile>\\<^sub>A (S, U \\<rightarrow>) onll \\<Gamma> P\"\n  using assms(1-4) proof (rule oseq_step_invariant_ctermI)\n    fix p l \\<sigma> a q l' \\<sigma>' pp\n    assume \"p \\<in> cterms \\<Gamma>\"\n       and otherassms: \"l \\<in> labels \\<Gamma> p\"\n           \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n           \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A\"\n           \"l' \\<in> labels \\<Gamma> q\"\n           \"(\\<sigma>, pp) \\<in> oreachable A S U\"\n           \"p \\<in> sterms \\<Gamma> pp\"\n           \"(\\<sigma>', q) \\<in> oreachable A S U\"\n           \"S \\<sigma> \\<sigma>' a\"\n    from this(1) obtain pn where \"p \\<in> ctermsl(\\<Gamma> pn)\"\n                             and \"not_call p\"\n      unfolding cterms_def' [OF wf] by auto\n    with wf show \"P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n      using otherassms by (rule local)\n qed\n\nlemma open_seqp_action [elim]:\n  assumes \"wellformed \\<Gamma>\"\n      and \"((\\<sigma> i, p), a, (\\<sigma>' i, p')) \\<in> seqp_sos \\<Gamma>\"\n    shows \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n  proof -\n    from assms obtain ps where \"ps\\<in>sterms \\<Gamma> p\"\n                           and \"((\\<sigma> i, ps), a, (\\<sigma>' i, p')) \\<in> seqp_sos \\<Gamma>\"\n      by - (drule trans_from_sterms, auto)\n    thus ?thesis\n    proof (induction p)\n      fix p1 p2\n      assume \"\\<lbrakk> ps \\<in> sterms \\<Gamma> p1; ((\\<sigma> i, ps), a, \\<sigma>' i, p') \\<in> seqp_sos \\<Gamma> \\<rbrakk>\n              \\<Longrightarrow> ((\\<sigma>, p1), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n         and \"\\<lbrakk> ps \\<in> sterms \\<Gamma> p2; ((\\<sigma> i, ps), a, \\<sigma>' i, p') \\<in> seqp_sos \\<Gamma> \\<rbrakk>\n              \\<Longrightarrow> ((\\<sigma>, p2), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n         and \"ps \\<in> sterms \\<Gamma> (p1 \\<oplus> p2)\"\n         and \"((\\<sigma> i, ps), a, (\\<sigma>' i, p')) \\<in> seqp_sos \\<Gamma>\"\n      with assms(1) show \"((\\<sigma>, p1 \\<oplus> p2), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n        by simp (metis oseqp_sos.ochoiceT1 oseqp_sos.ochoiceT2)\n    next\n      fix l fip fmsg p1 p2\n      assume IH1: \"\\<lbrakk> ps \\<in> sterms \\<Gamma> p1; ((\\<sigma> i, ps), a, \\<sigma>' i, p') \\<in> seqp_sos \\<Gamma> \\<rbrakk>\n                    \\<Longrightarrow> ((\\<sigma>, p1), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n         and IH2: \"\\<lbrakk> ps \\<in> sterms \\<Gamma> p2; ((\\<sigma> i, ps), a, \\<sigma>' i, p') \\<in> seqp_sos \\<Gamma> \\<rbrakk>\n                    \\<Longrightarrow> ((\\<sigma>, p2), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n         and \"ps \\<in> sterms \\<Gamma> ({l}unicast(fip, fmsg). p1 \\<triangleright> p2)\"\n         and \"((\\<sigma> i, ps), a, (\\<sigma>' i, p')) \\<in> seqp_sos \\<Gamma>\"\n      from this(3-4) have \"((\\<sigma> i, {l}unicast(fip, fmsg). p1 \\<triangleright> p2), a, (\\<sigma>' i, p')) \\<in> seqp_sos \\<Gamma>\"\n        by simp\n      thus \"((\\<sigma>, {l}unicast(fip, fmsg). p1 \\<triangleright> p2), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n      proof (rule seqp_unicastTE)\n        assume \"a = unicast (fip (\\<sigma> i)) (fmsg (\\<sigma> i))\"\n           and \"\\<sigma>' i = \\<sigma> i\"\n           and \"p' = p1\"\n        thus ?thesis by auto\n      next\n        assume \"a = \\<not>unicast (fip (\\<sigma> i))\"\n           and \"\\<sigma>' i = \\<sigma> i\"\n           and \"p' = p2\"\n        thus ?thesis by auto\n      qed\n    next\n      fix p\n      assume \"ps \\<in> sterms \\<Gamma> (call(p))\"\n         and \"((\\<sigma> i, ps), a, (\\<sigma>' i, p')) \\<in> seqp_sos \\<Gamma>\"\n      with assms(1) have \"((\\<sigma>, ps), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n        by (cases ps) auto\n      with assms(1) \\<open>ps \\<in> sterms \\<Gamma> (call(p))\\<close> have \"((\\<sigma>, \\<Gamma> p), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n        by - (rule otrans_from_sterms', simp_all)\n      thus \"((\\<sigma>, call(p)), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\" by auto\n    qed auto\n  qed\n\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/AWN/OAWN_Invariants.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621765008857981, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.25917279984343794}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |                    May 2005               |\n            |                   June 2005  (modified)   |\n            |              September 2005  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |               November 2005  (modified)   |\n            |                  April 2006  (modified)   |\n            |                  March 2007  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory CSP_F_op_rep_par\nimports CSP_F_op_alpha_par CSP_T_op_rep_par\nbegin\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite UnionT and InterT.                 *)\n(*                  Union (B ` A) = (UN x:A. B x)                      *)\n(*                  Inter (B ` A) = (INT x:A. B x)                     *)\n\n(*\ndeclare Union_image_eq [simp del]\ndeclare Inter_image_eq [simp del]\n*)\n\ndeclare Sup_image_eq [simp del]\ndeclare Inf_image_eq [simp del]\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite (notick | t = <>)                 *)\n(*                                                                     *)\n(*                  disj_not1: (~ P | Q) = (P --> Q)                   *)\n\ndeclare disj_not1 [simp del]\n\n(*============================================================*\n |                                                            |\n |            replicated alphabetized parallel                |\n |                                                            |\n *============================================================*)\n\n(*** Inductive_parallel ***)\n\nlemma in_failures_Inductive_parallel_lm1: \n       \"Y Int insert Tick (Ev ` snd a) Un\n        Union {Y Int insert Tick (Ev ` X) |X Y. EX P. ((P, X), Y) : set PXYs} =\n          Union {Ya Int insert Tick (Ev ` X) |X Ya.\n                 EX P. P = fst a & X = snd a & Ya = Y | ((P, X), Ya) : set PXYs}\"\nby (auto)\n\nlemma in_failures_Inductive_parallel_lm2: \n  \"((P, X), Y) : set s ==> X <= Union (snd ` fst ` set s)\"\napply (auto)\napply (rule_tac x=\"((P, X), Y)\" in bexI)\nby (simp_all)\n\nlemma in_failures_Inductive_parallel_lm3:\n   \"Union {Y Int insert Tick (Ev ` X) |X Y. EX P. ((P, X), Y) : set zs} <=\n    insert Tick (Ev ` Union (snd ` fst ` set zs))\"\napply (rule)\napply (simp)\napply (elim conjE exE)\napply (simp)\napply (elim conjE disjE)\napply (simp)\napply (rule disjI2)\napply (auto)\napply (simp add: image_iff)\napply (rule_tac x=\"((P, X), Y)\" in bexI)\napply (auto)\ndone\n\nlemma in_failures_Inductive_parallel_lm4:\n   \"Union {Y Int insert Tick (Ev ` X) |X Y. EX P. ((P, X), Y) : set zs} Int\n    insert Tick (Ev ` Union (snd ` fst ` set zs))\n    = Union {Y Int insert Tick (Ev ` X) |X Y. EX P. ((P, X), Y) : set zs}\"\napply (rule Int_subset_eq)\napply (simp add: in_failures_Inductive_parallel_lm3)\ndone\n\n(* main *)\n\nlemma in_failures_Inductive_parallel_lm:\n \"PXs ~= [] --> (ALL f.\n   (f :f failures([||] PXs) M) =\n         (EX u. (sett(u) <= insert Tick (Ev ` Union (snd ` set PXs)) & \n          (EX Z. f = (u, Z) &\n          (EX PXYs. map fst PXYs = PXs &\n          (Z Int insert Tick (Ev ` Union (snd ` set PXs))\n           = Union {(Y Int insert Tick (Ev ` X))|X Y. EX P. ((P,X),Y) : set PXYs} &\n          (ALL P X Y. ((P,X),Y) : set PXYs --> ((u rest-tr X), Y) :f failures(P) M)))))))\"\napply (induct_tac PXs)\n\n(* case 0 *)\n apply (simp)\n\n(* case 1 *)\n apply (case_tac \"list = []\")\n apply (simp)\n apply (intro allI)\n apply (simp add: in_failures_Alpha_parallel)\n apply (simp add: in_failures)\n apply (rule iffI)\n (* => *)\n  apply (elim conjE exE)\n  apply (simp)\n  apply (erule disjE)\n\n   apply (rule_tac x=\"[(a,Y)]\" in exI)\n   apply (simp)\n\n    apply (rule conjI)\n    apply (simp add: Evset_def pair_eq_decompo)\n    apply (fast)\n    apply (intro allI impI)\n    apply (simp add: pair_eq_decompo)\n\n   apply (case_tac \"Tick ~: Z\")\n    apply (rule_tac x=\"[(a,Y)]\" in exI)\n    apply (simp add: Evset_def pair_eq_decompo)\n(*    apply (fast) *)\n   (* Tick : Z *)\n    apply (rule_tac x=\"[(a,insert Tick Y)]\" in exI)\n    apply (simp)\n\n    apply (simp add: rest_tr_Tick_sett)\n    apply (elim conjE exE)\n    apply (simp add: pair_eq_decompo)\n    apply (rule conjI)\n    apply (fast)\n    apply (rule proc_T2_T3, simp)\n    apply (simp)\n\n (* <= *)\n  apply (elim conjE exE)\n  apply (simp)\n  apply (subgoal_tac \"EX bb. PXYs=[(a,bb)]\")\n  apply (elim conjE exE)\n  apply (subgoal_tac \"aa rest-tr {} = <> | aa rest-tr {} = <Tick>\")\n  apply (erule disjE)\n\n   (* <> *)\n   apply (rule_tac x=\"bb\" in exI)\n   apply (rule_tac x=\"{}\" in exI)\n   apply (simp add: pair_eq_decompo)\n\n   (* <Tick> *)\n   apply (rule_tac x=\"bb\" in exI)\n   apply (rule_tac x=\"{}\" in exI)\n   apply (simp add: pair_eq_decompo)\n\n   apply (simp add: rest_tr_empty)\n   apply (force)\n\n(* step case *)\napply (simp add: in_failures_Alpha_parallel)\napply (intro allI impI)\napply (rule iffI)\n\n(* => *)\n apply (elim conjE exE, simp)\n apply (rule_tac x=\"(a,Y) # PXYs\" in exI)\n apply (simp add: pair_eq_decompo)\n apply (simp add: in_failures_Inductive_parallel_lm1)\n\n apply (intro allI impI)\n apply (drule_tac x=\"P\" in spec)\n apply (drule_tac x=\"X\" in spec)\n apply (drule_tac x=\"Ya\" in spec)\n apply (simp)\n apply (subgoal_tac \"X <= Union (snd ` set list)\")\n apply (simp add: rest_tr_of_rest_tr_subset)\n\n apply (rotate_tac -4)\n apply (drule sym)\n apply (simp add: in_failures_Inductive_parallel_lm2)\n\n(* <= *)\n apply (simp)\n apply (elim conjE exE)\n\n apply (subgoal_tac \"EX bb zs. PXYs = (a, bb) # zs & map fst zs = list\")\n apply (elim conjE exE)\n apply (rule_tac x=\"bb\" in exI)\n apply (rule_tac x=\n    \"Union {Y Int insert Tick (Ev ` X) |X Y. EX P. ((P, X), Y) : set zs}\" in exI)\n apply (simp)\n apply (rule conjI)\n apply (simp add: pair_eq_decompo)\n apply (rotate_tac -1)\n apply (drule sym)\n apply (simp)\n apply (simp add: in_failures_Inductive_parallel_lm4)\n apply (simp add: in_failures_Inductive_parallel_lm1)\n\n apply (rule_tac x=\"zs\" in exI)\n apply (rotate_tac -1)\n apply (drule sym)\n apply (simp add: in_failures_Inductive_parallel_lm4)\n\n apply (intro allI impI)\n apply (subgoal_tac \"X <= Union (snd ` set list)\")\n apply (simp add: rest_tr_of_rest_tr_subset)\n apply (simp add: in_failures_Inductive_parallel_lm2)\napply (auto)\ndone\n\n(*** remove ALL ***)\n\nlemma in_failures_Inductive_parallel:\n \"PXs ~= [] ==> \n   (f :f failures([||] PXs) M) =\n         (EX u. (sett(u) <= insert Tick (Ev ` Union (snd ` set PXs)) & \n          (EX Z. f = (u, Z) &\n          (EX PXYs. map fst PXYs = PXs &\n          (Z Int insert Tick (Ev ` Union (snd ` set PXs))\n           = Union {(Y Int insert Tick (Ev ` X))|X Y. EX P. ((P,X),Y) : set PXYs} &\n          (ALL P X Y. ((P,X),Y) : set PXYs --> ((u rest-tr X), Y) :f failures(P) M))))))\"\nby (simp add: in_failures_Inductive_parallel_lm)\n\n(*** Semantics for replicated alphabetized parallel on F ***)\n\nlemma failures_Inductive_parallel:\n  \"PXs ~= []\n   ==> failures([||] PXs) M =\n      {f. (EX u. (sett(u) <= insert Tick (Ev ` Union (snd ` set PXs)) & \n          (EX Z. f = (u, Z) &\n          (EX PXYs. map fst PXYs = PXs &\n          (Z Int insert Tick (Ev ` Union (snd ` set PXs))\n           = Union {(Y Int insert Tick (Ev ` X))|X Y. EX P. ((P,X),Y) : set PXYs} &\n          (ALL P X Y. ((P,X),Y) : set PXYs --> ((u rest-tr X), Y) :f failures(P) M))))))}f\"\napply (simp add: in_failures_Inductive_parallel[THEN sym])\ndone\n\n(************************************\n |              traces              |\n ************************************)\n\nlemma sett_in_failures_Inductive_parallel:\n  \"[| PXs ~= [] ; (t,X) :f failures([||] PXs) M |] \n   ==> sett t <= insert Tick (Ev ` Union (snd ` set PXs))\"\nby (simp add: in_failures_Inductive_parallel)\n\n(*---------------------------------------------------------*\n |        another expression of Inductive_parallel_eval          |\n *---------------------------------------------------------*)\n\nlemma in_failures_Inductive_parallel_nth:\n \"PXs ~= [] ==> \n   (f :f failures([||] PXs) M) =\n         (EX u. (sett(u) <= insert Tick (Ev ` Union (snd ` set PXs)) & \n          (EX Z. f = (u, Z) &\n          (EX Ys. length PXs = length Ys &\n          (Z Int insert Tick (Ev ` Union (snd ` set PXs))\n           = Union {((Ys!i) Int insert Tick (Ev ` (snd (PXs!i))))|i. i < length PXs} &\n          (ALL i. i < length PXs --> ((u rest-tr (snd (PXs!i))), Ys!i) :f \n            failures(fst (PXs!i)) M))))))\"\napply (simp add: in_failures_Inductive_parallel)\napply (simp add: set_nth)\napply (rule iffI)\n\n(* => *)\n apply (elim conjE exE)\n apply (simp)\n apply (rule_tac x=\"map snd PXYs\" in exI)\n apply (simp)\n apply (rotate_tac 3)\n apply (drule sym)\n apply (simp)\n apply (rule conjI)\n apply (simp add: pair_eq_decompo)\n\n apply (rule equalityI)\n (* <= *)\n  apply (rule)\n  apply (simp)\n  apply (elim conjE exE)\n  apply (simp)\n  apply (elim conjE disjE)\n   apply (simp)\n   apply (rule_tac x=\"map snd PXYs ! i Int\n                      insert Tick (Ev ` snd (map fst PXYs ! i))\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"i\" in exI)\n   apply (simp)\n\n   apply (rule_tac x=\"map snd PXYs ! i Int\n                      insert Tick (Ev ` snd (map fst PXYs ! i))\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"i\" in exI)\n   apply (simp)\n\n (* => *)\n  apply (rule)\n  apply (simp)\n  apply (elim conjE exE)\n  apply (simp)\n  apply (elim conjE disjE)\n   apply (simp)\n   apply (rule_tac x=\n     \"(snd (PXYs ! i)) Int insert Tick (Ev ` snd (fst (PXYs ! i)))\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"snd (fst (PXYs ! i))\" in exI)\n   apply (rule_tac x=\"snd (PXYs ! i)\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"i\" in exI)\n   apply (simp)\n\n   apply (rule_tac x=\n     \"(snd (PXYs ! i)) Int insert Tick (Ev ` snd (fst (PXYs ! i)))\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"snd (fst (PXYs ! i))\" in exI)\n   apply (rule_tac x=\"snd (PXYs ! i)\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"i\" in exI)\n   apply (simp)\n\n  apply (intro allI impI)\n  apply (drule_tac x=\"fst (fst (PXYs ! i))\" in spec)\n  apply (drule_tac x=\"snd (fst (PXYs ! i))\" in spec)\n  apply (drule_tac x=\"snd (PXYs ! i)\" in spec)\n  apply (simp)\n  apply (fast)\n\n (* => *)\n apply (elim conjE exE)\n apply (simp)\n apply (rule_tac x=\"zip PXs Ys\" in exI)\n apply (simp add: map_fst_zip_eq)\n\n apply (rule conjI)\n apply (simp add: pair_eq_decompo)\n\n apply (rule equalityI)\n (* <= *)\n  apply (rule)\n  apply (simp)\n  apply (elim conjE exE)\n  apply (simp)\n  apply (elim conjE disjE)\n   apply (simp)\n   apply (rule_tac x=\"Ys ! i Int insert Tick (Ev ` snd (PXs ! i))\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"snd (PXs ! i)\" in exI)\n   apply (rule_tac x=\"Ys ! i\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"i\" in exI)\n   apply (simp)\n\n   apply (rule_tac x=\"Ys ! i Int insert Tick (Ev ` snd (PXs ! i))\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"snd (PXs ! i)\" in exI)\n   apply (rule_tac x=\"Ys ! i\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"i\" in exI)\n   apply (simp)\n\n (* => *)\n  apply (rule)\n  apply (simp)\n  apply (elim conjE exE)\n  apply (simp)\n  apply (elim conjE disjE)\n   apply (simp)\n   apply (rule_tac x=\"Ys ! i Int insert Tick (Ev ` snd (PXs ! i))\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"i\" in exI)\n   apply (simp)\n\n   apply (rule_tac x=\"Ys ! i Int insert Tick (Ev ` snd (PXs ! i))\" in exI)\n   apply (simp)\n   apply (rule_tac x=\"i\" in exI)\n   apply (simp)\n\n  apply (intro allI impI)\n  apply (elim conjE exE)\n  apply (drule_tac x=\"i\" in spec)\n  apply (simp add: pair_eq_decompo)\ndone\n\n(*============================================================*\n |                                                            |\n |              indexed alphabetized parallel                 |\n |                                                            |\n *============================================================*)\n\n(*** failures Inductive_parallel ***)\n\nlemma in_failures_Rep_parallel_lm1:\n  \"[| Is isListOf I ; length Ys = length Is |] ==>\n    Union {(Ys ! i Int insert Tick (Ev ` snd (map PXf Is ! i))) |i. i < length Ys} =\n    Union {(Ys ! (THE n. Is ! n = i & n < length Is) Int\n            insert Tick (Ev ` snd (PXf i))) | i. i : I}\"\napply (rule)\n\n (* <= *)\n apply (rule)\n apply (simp)\n apply (elim conjE exE)\n apply (rule_tac x=\n   \"Ys ! (THE n. Is ! n = (Is ! i) & n < length Is) Int\n    insert Tick (Ev ` snd (PXf (Is ! i)))\" in exI)\n apply (simp add: isListOf_THE_nth)\n apply (rule_tac x=\"(Is ! i)\" in exI)\n apply (simp add: isListOf_THE_nth)\n apply (simp add: isListOf_nth_in_index)\n\n (* => *)\n apply (rule)\n apply (simp)\n apply (elim conjE exE)\n apply (simp)\n apply (erule isListOf_index_to_nthE)\n apply (drule_tac x=\"i\" in bspec, simp)\n apply (elim conjE exE, simp)\n apply (simp add: isListOf_THE_nth)\n apply (rule_tac x=\n   \"Ys ! n Int insert Tick (Ev ` snd (PXf (Is ! n)))\" in exI)\n apply (simp)\n apply (rule_tac x=\"n\" in exI)\n apply (simp)\ndone\n\nlemma in_failures_Rep_parallel_lm2:\n  \"Is isListOf I ==>\n   Union {(Yf i Int insert Tick (Ev ` snd (PXf i))) |i. i : I} =\n   Union {(map Yf Is ! i Int insert Tick (Ev ` snd (map PXf Is ! i))) |i. i < length Is}\"\napply (rule)\n\n (* <= *)\n apply (rule)\n apply (simp)\n apply (elim conjE exE)\n apply (erule isListOf_index_to_nthE)\n apply (drule_tac x=\"i\" in bspec, simp)\n apply (elim conjE exE, simp)\n apply (rule_tac x=\n   \"map Yf Is ! n Int insert Tick (Ev ` snd (map PXf Is ! n))\" in exI)\n apply (simp)\n apply (rule_tac x=\"n\" in exI)\n apply (simp)\n\n (* => *)\n apply (rule)\n apply (simp)\n apply (elim conjE exE)\n apply (rule_tac x= \"Yf (Is!i) Int insert Tick (Ev ` snd (PXf (Is!i)))\" in exI)\n apply (simp)\n apply (rule_tac x=\"(Is!i)\" in exI)\n apply (simp add: isListOf_nth_in_index)\ndone\n\nlemma in_failures_Rep_parallel:\n  \"[| I ~= {} ; finite I |]\n   ==> (f :f failures ([||]:I PXf) M) =\n         (EX u. (sett(u) <= insert Tick (Ev ` Union (snd ` PXf ` I)) & \n          (EX Z. f = (u, Z) &\n          (EX Yf. \n          (Z Int insert Tick (Ev ` Union (snd ` PXf ` I))\n           = Union {((Yf i) Int insert Tick (Ev ` (snd (PXf i))))|i. i : I} &\n          (ALL i:I. ((u rest-tr (snd (PXf i))), Yf i) :f failures(fst (PXf i)) M))))))\"\napply (simp add: Rep_parallel_def)\napply (subgoal_tac \"EX Is. Is isListOf I\")\napply (elim conjE exE)\napply (subgoal_tac \"(map PXf (SOME Is. Is isListOf I)) ~= []\")\napply (simp add: in_failures_Inductive_parallel_nth)\napply (rule someI2)\n apply (simp)\n apply (rule iffI)\n\n  (* => *)\n  apply (elim conjE exE)\n  apply (rename_tac Is' Is u Z Ys)\n  apply (rule_tac x=\"u\" in exI)\n  apply (simp add: isListOf_set_eq)\n  apply (rule_tac x= \"(%i. (Ys!(THE n. (Is!n) = i & n<length Is)))\" in exI)\n  apply (rule conjI)\n  apply (simp add: in_failures_Rep_parallel_lm1)\n  apply (rule ballI)\n\n  apply (rotate_tac 4)\n  apply (erule isListOf_index_to_nthE)\n  apply (drule_tac x=\"i\" in bspec, simp)\n  apply (elim conjE exE, simp)\n\n  apply (rotate_tac 2)\n  apply (drule sym)\n  apply (simp add: isListOf_THE_nth)\n\n  (* <= *)\n  apply (elim conjE exE)\n  apply (rename_tac Is' Is u Z Yf)\n  apply (rule_tac x=\"u\" in exI)\n  apply (simp add: isListOf_set_eq)\n  apply (rule_tac x= \"map Yf Is\" in exI)\n  apply (simp)\n  apply (rule conjI)\n  apply (rule in_failures_Rep_parallel_lm2, simp)\n  apply (intro allI impI)\n  apply (drule_tac x=\"Is ! i\" in bspec)\n  apply (simp add: isListOf_nth_in_index)\n  apply (simp)\n\n apply (rule someI2)\n apply (simp)\n apply (simp add: isListOf_nonemptyset)\n\napply (simp add: isListOf_EX)\ndone\n\nlemmas in_failures_par = in_failures_Alpha_parallel\n                         in_failures_Inductive_parallel\n                         in_failures_Rep_parallel\n\n(*** Semantics for indexed alphabetized parallel on F ***)\n\nlemma failures_Rep_parallel:\n  \"[| I ~= {} ; finite I |]\n   ==> failures ([||]:I PXf) M =\n      {f. (EX u. (sett(u) <= insert Tick (Ev ` Union (snd ` PXf ` I)) & \n          (EX Z. f = (u, Z) &\n          (EX Yf. \n          (Z Int insert Tick (Ev ` Union (snd ` PXf ` I))\n           = Union {((Yf i) Int insert Tick (Ev ` (snd (PXf i))))|i. i : I} &\n          (ALL i:I. ((u rest-tr (snd (PXf i))), Yf i) :f failures(fst (PXf i)) M))))))}f\"\napply (simp add: in_failures_Rep_parallel[THEN sym])\ndone\n\n(************************************\n |              traces              |\n ************************************)\n\nlemma sett_in_failures_Rep_parallel:\n  \"[| I ~= {} ; finite I ; (t,X) :f failures([||]:I PXf) M |] \n   ==> sett t <= insert Tick (Ev ` Union (snd ` PXf ` I))\"\nby (simp add: in_failures_Rep_parallel)\n\n(****************** to add it again ******************)\n\ndeclare disj_not1      [simp]\n(*\ndeclare Union_image_eq [simp]\ndeclare Inter_image_eq [simp]\n*)\ndeclare Sup_image_eq [simp]\ndeclare Inf_image_eq [simp]\nend\n", "meta": {"author": "pefribeiro", "repo": "CSP-Prover", "sha": "8967cc482e5695fca4abb52d9dc2cf36b7b7a44e", "save_path": "github-repos/isabelle/pefribeiro-CSP-Prover", "path": "github-repos/isabelle/pefribeiro-CSP-Prover/CSP-Prover-8967cc482e5695fca4abb52d9dc2cf36b7b7a44e/CSP_F/CSP_F_op_rep_par.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5621765008857981, "lm_q2_score": 0.46101677931231594, "lm_q1q2_score": 0.25917279984343794}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: GPL-2.0-only\n *)\n\ntheory ExampleSystem\nimports ArchAccess_AC\nbegin\n\ncontext begin interpretation Arch . (*FIXME: arch_split*)\n\ndefinition\n  nat_to_bl :: \"nat \\<Rightarrow> nat \\<Rightarrow> bool list option\"\nwhere\n  \"nat_to_bl bits n \\<equiv>\n    if n \\<ge> 2^bits then\n      None\n    else\n      Some $ bin_to_bl bits (of_nat n)\"\n\nlemma nat_to_bl_id [simp]: \"nat_to_bl (size (x :: (('a::len) word))) (unat x) = Some (to_bl x)\"\n  apply (clarsimp simp: nat_to_bl_def to_bl_def)\n  apply (auto simp: le_def word_size)\n  done\n\n\n(*---------------------------------------------------------*)\n\nsubsection \\<open>Purpose\\<close>\n\ntext \\<open>\n\nThis file defines some example systems using the access control\ndefinitions. The aim is a sanity check of the AC definitions, to\nensure they enable to reason about reasonable systems.\n\nIn particular, we want to make sure that\n\n  . the function state_objs_to_policy does not connect everything to\n  everything (Example 1)\n  . we can talk about components sharing cnodes\n  . we can talk about components sharing frames\n  . we can have more than 1 untrusted component\n  . we can have an EP between two untrusted components\n\n\\<close>\n\n(*---------------------------------------------------------*)\n\nsubsection \\<open>Generic functions / lemmas\\<close>\n\n\ntext \\<open>Defining the authority between labels.\n\nIn addition to the intuitive authority we want, we need to add all the\nauthority required to have a wellformed graph. So we define\ncomplete_AgentAuthGraph to add these 'extra' authorities (at least all\nthe ones not depending on the current label). These are:\n\n  . self-authority (each label needs all the authorities to itself).\n  . if Control edge is present between 2 labels then we add all\n    authorities between them.\n  . Control authority is transitive: we add an Control edge\n    between 2 labels if we can connect them via Control\n    edges. Actually we add all authorities because of the second\n    clause.\n\n\\<close>\n\n\ndefinition\n  complete_AuthGraph :: \"'a auth_graph \\<Rightarrow> 'a set \\<Rightarrow> 'a auth_graph\"\nwhere\n  \"complete_AuthGraph g ls \\<equiv>\n     g \\<union> {(l,a,l) | a l. l \\<in> ls}\"\n\ntext \\<open>converting a nat to a bool list of size 10 - for the cnodes\\<close>\n\ndefinition\n  the_nat_to_bl :: \"nat \\<Rightarrow> nat \\<Rightarrow> bool list\"\nwhere\n  \"the_nat_to_bl sz n \\<equiv> the (nat_to_bl sz n)\"\n\ndefinition\n  the_nat_to_bl_10  :: \"nat \\<Rightarrow> bool list\"\nwhere\n  \"the_nat_to_bl_10 n \\<equiv> the_nat_to_bl 10 n\"\n\nlemma tcb_cnode_index_nat_to_bl:\n  \"n<10 \\<Longrightarrow> the_nat_to_bl_10 n \\<noteq> tcb_cnode_index n\"\n  by (clarsimp simp: the_nat_to_bl_10_def the_nat_to_bl_def\n                     tcb_cnode_index_def\n                     nat_to_bl_def to_bl_def bin_to_bl_aux_def)\n\n\n(*---------------------------------------------------------*)\nsubsection \\<open>Example 1\\<close>\n\ntext \\<open>\n\nThis example aims at checking that we can extract a reasonable policy\nfrom the state, i.e. that the function state_objs_to_policy does not connect\neverything to everything.\n\nThis example is a system Sys1 made of 2 main components UT1 and T1,\nconnected through and endpoint EP1. EP1 is made of one single kernel\nobject: obj1_0x9, the endpoint. Both UT1 and T1 contains:\n\n  . one TCB (obj1_0xC07 and obj1_0xC08 resp.)\n  . one vspace made up of one top-level page table (obj1_BF7 and obj1_0xBF9 resp.)\n  . each top-level pt contains a single page table (obj1_0xC00000 and obj1_0xC05000 resp.)\n  . one cspace made up of one cnode (obj1_0x6 and obj1_0x7 resp.)\n  . each cspace contains 4 caps:\n         one to the tcb\n         one to the cnode itself\n         one to the vspace\n         one to the ep\n\nUT1 can send to the ep while T1 can receive from it.\n\nAttempt to ASCII art:\n\n\n          --------    ----                      ----     --------\n          |       |   |  |                      |  |     |      |\n          V       |   |  V     S             R  |  V     |      V\nobj1_0xC07(tcb)-->obj1_0x6(cnode)--->obj1_0x9(ep)<---obj1_0x7(cnode)<--obj1_0xC08(tcb)\n  |               |                                   |            |\n  V               |                                   |            V\nobj1_0xBF7(pt)<-----                                    -------> obj1_0xBF9(pt)\n  |                                                                |\n  V                                                                V\nobj1_0xC00000(pt)                                                obj1_0xC05000(pt)\n\n\n(the references are derived from the dump of the SAC system)\n\n\nThe aim is to be able to prove\n\n  pas_refined Sys1PAS s1\n\nwhere Sys1PAS is the label graph defining the AC policy for Sys1 and\ns1 is the state of Sys1 described above.\n\nThis shows that the aag extracted from s1 (by state_objs_to_policy) is\nincluded in the policy graph Sys1PAS.\n\n\\<close>\n\n\nsubsubsection \\<open>Defining the State\\<close>\n\ntext \\<open>We need to define the asids of each pt to ensure that\nthe object is included in the right ASID-label\\<close>\n\ntext \\<open>UT1's ASID\\<close>\n\ndefinition\n  asid1_0xBF7 :: asid\nwhere\n  \"asid1_0xBF7 \\<equiv> 1<<asid_low_bits\"\n\ntext \\<open>T1's ASID\\<close>\n\ndefinition\n  asid1_0xBF9 :: asid\nwhere\n  \"asid1_0xBF9 \\<equiv> 2<<asid_low_bits\"\n\nlemma \"asid_high_bits_of asid1_0xBF9 \\<noteq> asid_high_bits_of asid1_0xBF7\"\nby (simp add: asid1_0xBF7_def asid_high_bits_of_def asid1_0xBF9_def asid_low_bits_def)\n\n\ntext \\<open>UT1's CSpace\\<close>\ndefinition\n  caps1_0x6 :: cnode_contents\nwhere\n  \"caps1_0x6 \\<equiv>\n   (empty_cnode 10)\n      ( (the_nat_to_bl_10 1)\n            \\<mapsto> ThreadCap 0xC07,\n        (the_nat_to_bl_10 2)\n            \\<mapsto> CNodeCap 6 undefined undefined,\n        (the_nat_to_bl_10 3)\n            \\<mapsto> ArchObjectCap (PageTableCap 0xBF7 (Some (asid1_0xBF7,0))),\n        (the_nat_to_bl_10 318)\n            \\<mapsto> EndpointCap 9 0 {AllowSend} )\"\n\n\ndefinition\n  obj1_0x6 :: kernel_object\nwhere\n  \"obj1_0x6 \\<equiv> CNode 10 caps1_0x6\"\n\ntext \\<open>T1's Cspace\\<close>\n\ndefinition\n  caps1_0x7 :: cnode_contents\nwhere\n  \"caps1_0x7 \\<equiv>\n   (empty_cnode 10)\n      ( (the_nat_to_bl_10 1)\n            \\<mapsto> ThreadCap 0xC08,\n        (the_nat_to_bl_10 2)\n            \\<mapsto> CNodeCap 7 undefined undefined,\n        (the_nat_to_bl_10 3)\n           \\<mapsto> ArchObjectCap (PageTableCap 0xBF9 (Some (asid1_0xBF9,0))),\n        (the_nat_to_bl_10 318)\n           \\<mapsto> EndpointCap 9 0 {AllowRecv}) \"\n\ndefinition\n  obj1_0x7 :: kernel_object\nwhere\n  \"obj1_0x7 \\<equiv> CNode 10 caps1_0x7\"\n\n\ntext \\<open>endpoint between UT1 and T1\\<close>\n\ndefinition\n  obj1_0x9 :: kernel_object\nwhere\n  \"obj1_0x9 \\<equiv> Endpoint IdleEP\"\n\n\ntext \\<open>UT1's VSpace\\<close>\n\ndefinition\n  pt1_0xC00000 :: pt\nwhere\n  \"pt1_0xC00000 \\<equiv> (\\<lambda>_. InvalidPTE)\"\n\ndefinition\n  obj1_0xC00000 :: kernel_object\nwhere\n  \"obj1_0xC00000 \\<equiv> ArchObj (PageTable pt1_0xC00000)\"\n\ndefinition\n  pt1_0xBF7 :: pt\nwhere\n  \"pt1_0xBF7 \\<equiv>\n    (\\<lambda>_. InvalidPTE)\n     (0 := PageTablePTE\n              (ucast (addrFromPPtr 0xC00000 >> pageBits))\n              undefined )\"\n\n(* used addrFromPPtr because proof gives me ptrFromAddr.. TODO: check\nif it's right *)\n\ndefinition\n  obj1_0xBF7 :: kernel_object\nwhere\n  \"obj1_0xBF7 \\<equiv> ArchObj (PageTable pt1_0xBF7)\"\n\n\ntext \\<open>T1's VSpace\\<close>\n\n\ndefinition\n  pt1_0xC05000 :: pt\nwhere\n  \"pt1_0xC05000 \\<equiv>\n    (\\<lambda>_. InvalidPTE)\"\n\n\ndefinition\n  obj1_0xC05000 :: kernel_object\nwhere\n  \"obj1_0xC05000 \\<equiv> ArchObj (PageTable pt1_0xC05000)\"\n\n\ndefinition\n  pt1_0xBF9 :: pt\nwhere\n  \"pt1_0xBF9 \\<equiv>\n    (\\<lambda>_. InvalidPTE)\n     (0 := PageTablePTE\n             (ucast (addrFromPPtr 0xC05000 >> pageBits))\n             undefined )\"\n\n(* used addrFromPPtr because proof gives me ptrFromAddr.. TODO: check\nif it's right *)\n\ndefinition\n  obj1_0xBF9 :: kernel_object\nwhere\n  \"obj1_0xBF9 \\<equiv> ArchObj (PageTable pt1_0xBF9)\"\n\n\ntext \\<open>UT1's tcb\\<close>\n\ndefinition\n  obj1_0xC07 :: kernel_object\nwhere\n  \"obj1_0xC07 \\<equiv>\n   TCB \\<lparr>\n     tcb_ctable             = CNodeCap 6 undefined undefined,\n     tcb_vtable             = ArchObjectCap (PageTableCap 0xBF7 (Some (asid1_0xBF7, 0))),\n     tcb_reply              = ReplyCap 0xC07 True {AllowGrant,AllowWrite}, \\<comment> \\<open>master reply cap to itself\\<close>\n     tcb_caller             = NullCap,\n     tcb_ipcframe           = NullCap,\n     tcb_state              = Running,\n     tcb_fault_handler      = undefined,\n     tcb_ipc_buffer         = undefined,\n     tcb_fault              = undefined,\n     tcb_bound_notification = None,\n     tcb_mcpriority         = undefined,\n     tcb_arch               = \\<lparr>tcb_context = undefined\\<rparr> \\<rparr>\"\n\n\ntext \\<open>T1's tcb\\<close>\n\ndefinition\n  obj1_0xC08 :: kernel_object\nwhere\n  \"obj1_0xC08 \\<equiv>\n   TCB \\<lparr>\n     tcb_ctable             = CNodeCap 7 undefined undefined,\n     tcb_vtable             = ArchObjectCap (PageTableCap 0xBF9 (Some (asid1_0xBF9, 0))),\n     tcb_reply              = ReplyCap 0xC08 True {AllowGrant,AllowWrite}, \\<comment> \\<open>master reply cap to itself\\<close>\n     tcb_caller             = NullCap,\n     tcb_ipcframe           = NullCap,\n     tcb_state              = BlockedOnReceive 9 \\<lparr> receiver_can_grant = False \\<rparr>,\n     tcb_fault_handler      = undefined,\n     tcb_ipc_buffer         = undefined,\n     tcb_fault              = undefined,\n     tcb_bound_notification = None,\n     tcb_mcpriority         = undefined,\n     tcb_arch               = \\<lparr>tcb_context = undefined\\<rparr>\\<rparr>\"\n\ndefinition\n \"obj1_10 \\<equiv> CNode 10 (Map.empty([] \\<mapsto> cap.NullCap))\"\n\n\n(* the boolean in BlockedOnReceive is True if the object can receive but not send.\nbut Tom says it only matters if the sender can grant - which is not the case of the UT1 - I think *)\n\ndefinition\n  kh1 :: kheap\nwhere\n  \"kh1 \\<equiv> [0x6 \\<mapsto> obj1_0x6,\n           0x7 \\<mapsto> obj1_0x7,\n           0x9 \\<mapsto> obj1_0x9,\n           0xA \\<mapsto> obj1_10,\n           0xBF7 \\<mapsto> obj1_0xBF7,\n           0xBF9 \\<mapsto> obj1_0xBF9,\n           0xC07 \\<mapsto> obj1_0xC07,\n           0xC08 \\<mapsto> obj1_0xC08,\n           0xC00000 \\<mapsto> obj1_0xC00000,\n           0xC05000 \\<mapsto> obj1_0xC05000]\"\n\nlemmas kh1_obj_def =\n  obj1_0x6_def obj1_0x7_def obj1_0x9_def obj1_10_def obj1_0xBF7_def obj1_0xBF9_def\n  obj1_0xC00000_def obj1_0xC05000_def obj1_0xC07_def obj1_0xC08_def\n\ndefinition exst1 :: \"det_ext\" where\n  \"exst1 \\<equiv> \\<lparr>work_units_completed_internal = undefined,\n             scheduler_action_internal = undefined,\n             ekheap_internal = \\<lambda>x. None,\n             domain_list_internal = undefined,\n             domain_index_internal = undefined,\n             cur_domain_internal = undefined,\n             domain_time_internal = undefined,\n             ready_queues_internal = undefined,\n             cdt_list_internal = undefined\\<rparr>\"\n\ndefinition\n  s1 :: \"det_ext state\"\nwhere\n  \"s1 \\<equiv>  \\<lparr>\n    kheap = kh1,\n    cdt = Map.empty,\n    is_original_cap = undefined,\n    cur_thread = undefined,\n    idle_thread = undefined,\n    machine_state = undefined,\n    interrupt_irq_node = (\\<lambda>_. 10),\n    interrupt_states = undefined,\n    arch_state = \\<lparr>\n        riscv_asid_table = (\\<lambda>_. None),\n        riscv_global_pts = undefined,\n        riscv_kernel_vspace = undefined\n        \\<rparr>,\n     exst = exst1\n    \\<rparr>\"\n\n\nsubsubsection \\<open>Defining the policy graph\\<close>\n\n\ndatatype Sys1Labels =\n    UT1 | T1 | EP1 | IRQ1\n\ndefinition\n  Sys1AgentMap :: \"Sys1Labels agent_map\"\nwhere\n  \"Sys1AgentMap \\<equiv>\n   (\\<lambda>_. undefined)\n     (0x6 := UT1,\n      0x7 := T1,\n      0x9 := EP1,\n      0xA := IRQ1,\n      0xBF7 := UT1,\n      0xBF9 := T1,\n      0xC00000 := UT1,\n      0xC05000 := T1,\n      0xC07 := UT1,\n      0xC08 := T1 )\"\n\nlemma Sys1AgentMap_simps:\n  \"Sys1AgentMap 0x6 = UT1\"\n  \"Sys1AgentMap 0x7 = T1\"\n  \"Sys1AgentMap 0x9 = EP1\"\n  \"Sys1AgentMap 0xA = IRQ1\"\n  \"Sys1AgentMap 0xBF7 = UT1\"\n  \"Sys1AgentMap 0xBF9 = T1\"\n  \"Sys1AgentMap 0xC00000 = UT1\"\n  \"Sys1AgentMap 0xC05000 = T1\"\n  \"Sys1AgentMap 0xC07 = UT1\"\n  \"Sys1AgentMap 0xC08 = T1\"\n  unfolding Sys1AgentMap_def by simp_all\n\ndefinition\n  Sys1AuthGraph_aux :: \"Sys1Labels auth_graph\"\nwhere\n    \"Sys1AuthGraph_aux \\<equiv>\n  { (UT1, auth.SyncSend,    EP1),\n    (UT1, auth.Reset,   EP1),\n    (T1,  auth.Receive, EP1),\n    (T1,  auth.Reset,   EP1) }\"\n\ndefinition\n  Sys1AuthGraph:: \"Sys1Labels auth_graph\"\nwhere\n    \"Sys1AuthGraph \\<equiv> complete_AuthGraph Sys1AuthGraph_aux {T1, UT1}\"\n\n\ndefinition\n  Sys1ASIDMap :: \"Sys1Labels agent_asid_map\"\nwhere\n  \"Sys1ASIDMap \\<equiv>\n    (\\<lambda>x. if (asid_high_bits_of x = asid_high_bits_of asid1_0xBF7)\n          then UT1\n         else if (asid_high_bits_of x = asid_high_bits_of asid1_0xBF9)\n          then T1 else undefined)\"\n\ndefinition Sys1PAS :: \"Sys1Labels PAS\" where\n  \"Sys1PAS \\<equiv> \\<lparr> pasObjectAbs = Sys1AgentMap, pasASIDAbs = Sys1ASIDMap, pasIRQAbs = (\\<lambda>_. IRQ1),\n               pasPolicy = Sys1AuthGraph, pasSubject = UT1, pasMayActivate = True,\n               pasMayEditReadyQueues = True, pasMaySendIrqs = True, pasDomainAbs = undefined \\<rparr>\"\n\nsubsubsection \\<open>Proof of pas_refined for Sys1\\<close>\n\nlemma caps1_0x7_well_formed: \"well_formed_cnode_n 10 caps1_0x7\"\n  apply (clarsimp simp: caps1_0x7_def well_formed_cnode_n_def)\n  apply (clarsimp simp: the_nat_to_bl_10_def the_nat_to_bl_def nat_to_bl_def)\n  apply (clarsimp simp: empty_cnode_def dom_def)\n  apply (rule set_eqI, clarsimp)\n  apply (rule iffI)\n   apply (elim disjE, insert len_bin_to_bl, simp_all)[1]\n  apply clarsimp\n  done\n\nlemma caps1_0x6_well_formed: \"well_formed_cnode_n 10 caps1_0x6\"\n  apply (clarsimp simp: caps1_0x6_def well_formed_cnode_n_def)\n  apply (clarsimp simp: the_nat_to_bl_10_def the_nat_to_bl_def nat_to_bl_def)\n  apply (clarsimp simp: empty_cnode_def dom_def)\n  apply (rule set_eqI, clarsimp)\n  apply (rule iffI)\n   apply (elim disjE, insert len_bin_to_bl, simp_all)[1]\n  apply clarsimp\n  done\n\n(* clagged from KernelInit_R *)\nlemma empty_cnode_apply[simp]:\n  \"(empty_cnode n xs = Some cap) = (length xs = n \\<and> cap = NullCap)\"\n  by (auto simp add: empty_cnode_def)\n\n\nlemma s1_caps_of_state :\n  \"caps_of_state s1 p = Some cap \\<Longrightarrow>\n     cap = NullCap \\<or>\n     (p,cap) \\<in>\n       { ((6::obj_ref,(the_nat_to_bl_10 1)),  ThreadCap 0xC07),\n         ((6::obj_ref,(the_nat_to_bl_10 2)),  CNodeCap 6 undefined undefined),\n         ((6::obj_ref,(the_nat_to_bl_10 3)),  ArchObjectCap (PageTableCap 0xBF7 (Some (asid1_0xBF7, 0)))),\n         ((6::obj_ref,(the_nat_to_bl_10 318)),EndpointCap  9 0 {AllowSend}),\n         ((7::obj_ref,(the_nat_to_bl_10 1)),  ThreadCap 0xC08),\n         ((7::obj_ref,(the_nat_to_bl_10 2)),  CNodeCap 7 undefined undefined),\n         ((7::obj_ref,(the_nat_to_bl_10 3)),  ArchObjectCap (PageTableCap 0xBF9 (Some (asid1_0xBF9, 0)))),\n         ((7::obj_ref,(the_nat_to_bl_10 318)),EndpointCap  9 0 {AllowRecv}) ,\n         ((0xC07::obj_ref, (tcb_cnode_index 0)), CNodeCap 6 undefined undefined ),\n         ((0xC07::obj_ref, (tcb_cnode_index 1)), ArchObjectCap (PageTableCap 0xBF7 (Some (asid1_0xBF7, 0)))),\n         ((0xC07::obj_ref, (tcb_cnode_index 2)), ReplyCap 0xC07 True {AllowGrant,AllowWrite}),\n         ((0xC07::obj_ref, (tcb_cnode_index 3)), NullCap),\n         ((0xC07::obj_ref, (tcb_cnode_index 4)), NullCap),\n         ((0xC08::obj_ref, (tcb_cnode_index 0)), CNodeCap 7 undefined undefined ),\n         ((0xC08::obj_ref, (tcb_cnode_index 1)), ArchObjectCap (PageTableCap 0xBF9 (Some (asid1_0xBF9, 0)))),\n         ((0xC08::obj_ref, (tcb_cnode_index 2)), ReplyCap 0xC08 True {AllowGrant,AllowWrite}),\n         ((0xC08::obj_ref, (tcb_cnode_index 3)), NullCap),\n         ((0xC08::obj_ref, (tcb_cnode_index 4)), NullCap)} \"\n  apply (insert caps1_0x7_well_formed)\n  apply (insert caps1_0x6_well_formed)\n  apply (simp add: caps_of_state_cte_wp_at cte_wp_at_cases s1_def kh1_def kh1_obj_def)\n  apply (case_tac p, clarsimp)\n  apply (clarsimp split: if_splits)\n     apply (clarsimp simp: cte_wp_at_cases tcb_cap_cases_def\n                     split: if_split_asm)+\n   apply (clarsimp simp: caps1_0x7_def split: if_splits)\n  apply (clarsimp simp: caps1_0x6_def cte_wp_at_cases  split: if_splits)\n  done\n\n\nlemma Sys1_wellformed: \"pas_wellformed Sys1PAS\"\n  apply (clarsimp simp: Sys1PAS_def\n                     policy_wellformed_def\n                     Sys1AuthGraph_def\n                     Sys1AuthGraph_aux_def\n                     complete_AuthGraph_def)\n  apply blast\n  done\n\nlemma tcb_states_of_state_1:\n  \"tcb_states_of_state s1 = [0xC08 \\<mapsto> thread_state.BlockedOnReceive 9 \\<lparr> receiver_can_grant = False \\<rparr>,  0xC07 \\<mapsto> thread_state.Running ]\"\n  unfolding s1_def tcb_states_of_state_def\n  apply (rule ext)\n  apply (simp add: get_tcb_def)\n  apply (simp add: kh1_def kh1_obj_def )\n  done\n\nlemma thread_bound_ntfns_1:\n  \"thread_bound_ntfns s1 = Map.empty\"\n  unfolding s1_def thread_bound_ntfns_def\n  apply (rule ext)\n  apply (simp add: get_tcb_def)\n  apply (simp add: kh1_def kh1_obj_def )\n  done\n\ndeclare AllowSend_def[simp] AllowRecv_def[simp]\n\nlemma domains_of_state_s1[simp]:\n  \"domains_of_state s1 = {}\"\n  apply (rule equalityI)\n   apply (rule subsetI)\n   apply clarsimp\n   apply (erule domains_of_state_aux.induct)\n   apply (simp add: s1_def exst1_def)\n  apply simp\n  done\n\nlemma vs_refs_aux_empty_pt[simp]:\n  \"vs_refs_aux lvl (PageTable empty_pt) = {}\"\n  by (clarsimp simp: vs_refs_aux_def graph_of_def pte_ref2_def)\n\nlemma is_aligned_0xC00000[simp]:\n  \"ptrFromPAddr (addr_from_ppn (UCAST(64 \\<rightarrow> 52) (addrFromPPtr 0xC00000 >> pageBits))) = 0xC00000\"\n  by (subst ptrFromPAddr_addr_from_ppn; fastforce simp: bit_simps is_aligned_mask mask_def)\n\nlemma is_aligned_0xC05000[simp]:\n  \"ptrFromPAddr (addr_from_ppn (UCAST(64 \\<rightarrow> 52) (addrFromPPtr 0xC05000 >> pageBits))) = 0xC05000\"\n  by (subst ptrFromPAddr_addr_from_ppn; fastforce simp: bit_simps is_aligned_mask mask_def)\n\nlemma \"pas_refined Sys1PAS s1\"\n  apply (clarsimp simp: pas_refined_def)\n  apply (intro conjI)\n       subgoal by (simp add: Sys1_wellformed)\n      subgoal by (simp add: irq_map_wellformed_aux_def s1_def Sys1AgentMap_simps Sys1PAS_def)\n     subgoal by (simp add: tcb_domain_map_wellformed_aux_def)\n    apply (clarsimp simp: auth_graph_map_def Sys1PAS_def state_objs_to_policy_def)+\n    apply (erule state_bits_to_policy.cases, simp_all, clarsimp)\n          apply (drule s1_caps_of_state, clarsimp)\n          apply (simp add: Sys1AuthGraph_def complete_AuthGraph_def Sys1AuthGraph_aux_def)\n          apply (elim disjE conjE; solves\\<open>clarsimp simp: Sys1AgentMap_simps cap_auth_conferred_def cap_rights_to_auth_def\\<close>)\n         apply (drule s1_caps_of_state, clarsimp)\n         apply (elim disjE; solves \\<open>simp add: thread_bound_ntfns_def\\<close>)\n        apply (clarsimp simp: state_refs_of_def thread_st_auth_def tcb_states_of_state_1\n               Sys1AuthGraph_def Sys1AgentMap_simps\n               complete_AuthGraph_def\n               Sys1AuthGraph_aux_def\n               split: if_splits)\n       apply (simp add:  thread_bound_ntfns_1)\n      apply (simp add: s1_def) (* this is OK because cdt is empty..*)\n     apply (simp add: s1_def) (* this is OK because cdt is empty..*)\n    apply (fastforce simp: state_vrefs_def vs_refs_aux_def s1_def kh1_def kh1_obj_def\n                           pt1_0xC00000_def pt1_0xC05000_def pt1_0xBF9_def pt1_0xBF7_def\n                           Sys1AuthGraph_def Sys1AuthGraph_aux_def Sys1AgentMap_simps\n                           complete_AuthGraph_def ptr_range_def pte_ref2_def opt_map_def\n                    dest!: graph_ofD split: if_splits)\n   apply (rule subsetI, clarsimp)\n   apply (erule state_asids_to_policy_aux.cases)\n     apply (drule s1_caps_of_state, clarsimp)\n     apply (fastforce simp: Sys1AgentMap_simps Sys1PAS_def Sys1ASIDMap_def Sys1AuthGraph_def\n                            Sys1AuthGraph_aux_def complete_AuthGraph_def cap_auth_conferred_def\n                            asid1_0xBF9_def asid1_0xBF7_def asid_low_bits_def asid_high_bits_of_def)\n    apply (fastforce simp: state_vrefs_def vs_refs_aux_def s1_def kh1_def kh1_obj_def\n                           pt1_0xC00000_def pt1_0xC05000_def pt1_0xBF9_def pt1_0xBF7_def\n                           Sys1AuthGraph_def Sys1AuthGraph_aux_def Sys1AgentMap_simps\n                           complete_AuthGraph_def ptr_range_def pte_ref2_def opt_map_def\n                    dest!: graph_ofD split: if_splits)\n   apply (clarsimp simp: s1_def)\n  apply (rule subsetI, clarsimp)\n  apply (erule state_irqs_to_policy_aux.cases)\n  apply (simp add: Sys1AuthGraph_def complete_AuthGraph_def Sys1AuthGraph_aux_def Sys1PAS_def Sys1ASIDMap_def)\n  apply (drule s1_caps_of_state)\n  apply (fastforce simp: Sys1AgentMap_simps Sys1PAS_def Sys1ASIDMap_def Sys1AuthGraph_def\n                         Sys1AuthGraph_aux_def complete_AuthGraph_def cap_auth_conferred_def\n                         asid1_0xBF9_def asid1_0xBF7_def asid_low_bits_def asid_high_bits_of_def)\n  done\n\n\n(*---------------------------------------------------------*)\nsubsection \\<open>Example 2\\<close>\n\ntext \\<open>\n\nThis example systems Sys2 aims at checking that we can have 2\ncomponents, one untrusted UT2 and one truted T1, sharing a cnode obj2_5.\n\nBoth UT2 and T2 contains:\n\n  . one TCB (obj2_0xC07 and obj2_0xC08 resp.)\n  . one vspace made up of one top-level page table (obj2_0xBF7 and obj2_0xBF9 resp.)\n  . each top-level pt contains a single page table (obj2_0xC00000 and obj2_0xC05000 resp.)\n  . one cspace made up of one cnode (obj2_0x6 and obj2_0x7 resp.)\n  . each cspace contains 4 caps:\n         one to the tcb\n         one to the cnode itself\n         one to the vspace\n         one to obj2_5\n\n\nAttempt to ASCII art:\n\n\n          --------    ----                          ----     --------\n          |       |   |  |                          |  |     |      |\n          V       |   |  V     S             R      |  V     |      V\nobj2_0xC07(tcb)-->obj2_0x6(cnode)--->obj2_5(cnode)<---obj2_0x7(cnode)<--obj2_0xC08(tcb)\n  |               |                                   |            |\n  V               |                                   |            V\nobj2_0xBF7(pt)<-----                                    -------> obj2_0xBF9(pt)\n  |                                                                |\n  V                                                                V\nobj2_0xC00000(pt)                                                obj2_0xC05000(pt)\n\n\n(the references are derived from the dump of the SAC system)\n\n\nThe aim is to be able to prove\n\n  pas_refined Sys2PAS s2\n\nwhere Sys2PAS is the label graph defining the AC policy for Sys2 and\ns2 is the state of Sys2 described above.\n\nThis shows that the aag extracted from s2 (by state_objs_to_policy) is\nincluded in the policy graph Sys2PAS.\n\n\\<close>\n\n\nsubsubsection \\<open>Defining the State\\<close>\n\n\n\ntext \\<open>We need to define the asids of each pt to ensure that\nthe object is included in the right ASID-label\\<close>\n\ntext \\<open>UT2's ASID\\<close>\n\ndefinition\n  asid2_0xBF7 :: asid\nwhere\n  \"asid2_0xBF7 \\<equiv> 1<<asid_low_bits\"\n\ntext \\<open>T2's ASID\\<close>\n\ndefinition\n  asid2_0xBF9 :: asid\nwhere\n  \"asid2_0xBF9 \\<equiv> 2<<asid_low_bits\"\n\nlemma \"asid_high_bits_of asid2_0xBF9 \\<noteq> asid_high_bits_of asid2_0xBF7\"\nby (simp add: asid2_0xBF7_def asid_high_bits_of_def asid2_0xBF9_def asid_low_bits_def)\n\n\n\ntext \\<open>the intermediaite CSpace\\<close>\n\ndefinition\n  caps2_5 :: cnode_contents\nwhere\n  \"caps2_5 \\<equiv>\n   (empty_cnode 10)\"\n\ndefinition\n  obj2_5 :: kernel_object\nwhere\n  \"obj2_5 \\<equiv> CNode 10 caps2_5\"\n\n\n\ntext \\<open>UT2's CSpace\\<close>\n\ndefinition\n  caps2_0x6 :: cnode_contents\nwhere\n  \"caps2_0x6 \\<equiv>\n   (empty_cnode 10)\n      ( (the_nat_to_bl_10 1)\n            \\<mapsto> ThreadCap 0xC07,\n        (the_nat_to_bl_10 2)\n            \\<mapsto> CNodeCap 6 undefined undefined,\n        (the_nat_to_bl_10 3)\n            \\<mapsto> ArchObjectCap (PageTableCap 0xBF7\n                                             (Some (asid2_0xBF7, 0))),\n        (the_nat_to_bl_10 4)\n            \\<mapsto> CNodeCap 5 undefined undefined )\"\n\n\ndefinition\n  obj2_0x6 :: kernel_object\nwhere\n  \"obj2_0x6 \\<equiv> CNode 10 caps2_0x6\"\n\ntext \\<open>T2's Cspace\\<close>\n\ndefinition\n  caps2_0x7 :: cnode_contents\nwhere\n  \"caps2_0x7 \\<equiv>\n   (empty_cnode 10)\n      ( (the_nat_to_bl_10 1)\n            \\<mapsto> ThreadCap 0xC08,\n        (the_nat_to_bl_10 2)\n            \\<mapsto> CNodeCap 7 undefined undefined,\n        (the_nat_to_bl_10 3)\n           \\<mapsto> ArchObjectCap (PageTableCap 0xBF9\n                                            (Some (asid2_0xBF9, 0))),\n        (the_nat_to_bl_10 4)\n            \\<mapsto> CNodeCap 5 undefined undefined) \"\n\ndefinition\n  obj2_0x7 :: kernel_object\nwhere\n  \"obj2_0x7 \\<equiv> CNode 10 caps2_0x7\"\n\n\ntext \\<open>endpoint between UT2 and T2\\<close>\n\ndefinition\n  obj2_0x9 :: kernel_object\nwhere\n  \"obj2_0x9 \\<equiv> Endpoint IdleEP\"\n\n\ntext \\<open>UT2's VSpace\\<close>\n\ndefinition\n  pt2_0xC00000 :: pt\nwhere\n  \"pt2_0xC00000 \\<equiv> (\\<lambda>_. InvalidPTE)\"\n\ndefinition\n  obj2_0xC00000 :: kernel_object\nwhere\n  \"obj2_0xC00000 \\<equiv> ArchObj (PageTable pt2_0xC00000)\"\n\n\ndefinition\n  pt2_0xBF7 :: pt\nwhere\n  \"pt2_0xBF7 \\<equiv>\n    (\\<lambda>_. InvalidPTE)\n     (0 := PageTablePTE\n              (ucast (addrFromPPtr 0xC00000 >> pageBits))\n              undefined )\"\n\n(* used addrFromPPtr because proof gives me ptrFromAddr.. TODO: check\nif it's right *)\n\ndefinition\n  obj2_0xBF7 :: kernel_object\nwhere\n  \"obj2_0xBF7 \\<equiv> ArchObj (PageTable pt2_0xBF7)\"\n\n\ntext \\<open>T1's VSpace\\<close>\n\n\ndefinition\n  pt2_0xC05000 :: pt\nwhere\n  \"pt2_0xC05000 \\<equiv>\n    (\\<lambda>_. InvalidPTE)\"\n\ndefinition\n  obj2_0xC05000 :: kernel_object\nwhere\n  \"obj2_0xC05000 \\<equiv> ArchObj (PageTable pt2_0xC05000)\"\n\n\ndefinition\n  pt2_0xBF9 :: pt\nwhere\n  \"pt2_0xBF9 \\<equiv>\n    (\\<lambda>_. InvalidPTE)\n     (0 := PageTablePTE\n             (ucast (addrFromPPtr 0xC05000 >> pageBits))\n             undefined )\"\n\n(* used addrFromPPtr because proof gives me ptrFromAddr.. TODO: check\nif it's right *)\n\ndefinition\n  obj2_0xBF9 :: kernel_object\nwhere\n  \"obj2_0xBF9 \\<equiv> ArchObj (PageTable pt2_0xBF9)\"\n\n\ntext \\<open>UT1's tcb\\<close>\n\ndefinition\n  obj2_0xC07 :: kernel_object\nwhere\n  \"obj2_0xC07 \\<equiv>\n   TCB \\<lparr>\n     tcb_ctable             = CNodeCap 6 undefined undefined ,\n     tcb_vtable             = ArchObjectCap (PageTableCap 0xBF7 (Some (asid2_0xBF7, 0))),\n     tcb_reply              = ReplyCap 0xC07 True {AllowGrant,AllowWrite}, \\<comment> \\<open>master reply cap to itself\\<close>\n     tcb_caller             = NullCap,\n     tcb_ipcframe           = NullCap,\n     tcb_state              = Running,\n     tcb_fault_handler      = undefined,\n     tcb_ipc_buffer         = undefined,\n     tcb_fault              = undefined,\n     tcb_bound_notification = None,\n     tcb_mcpriority         = undefined,\n     tcb_arch               = \\<lparr>tcb_context = undefined\\<rparr>\\<rparr>\"\n\n\ntext \\<open>T1's tcb\\<close>\n\ndefinition\n  obj2_0xC08 :: kernel_object\nwhere\n  \"obj2_0xC08 \\<equiv>\n   TCB \\<lparr>\n     tcb_ctable             = CNodeCap 7 undefined undefined ,\n     tcb_vtable             = ArchObjectCap (PageTableCap 0xBF9 (Some (asid2_0xBF9,0))),\n     tcb_reply              = ReplyCap 0xC08 True {AllowGrant,AllowWrite}, \\<comment> \\<open>master reply cap to itself\\<close>\n     tcb_caller             = NullCap,\n     tcb_ipcframe           = NullCap,\n     tcb_state              = BlockedOnReceive 9 \\<lparr> receiver_can_grant = False \\<rparr>,\n     tcb_fault_handler      = undefined,\n     tcb_ipc_buffer         = undefined,\n     tcb_fault              = undefined,\n     tcb_bound_notification = None,\n     tcb_mcpriority         = undefined,\n     tcb_arch               = \\<lparr>tcb_context = undefined\\<rparr>\\<rparr>\"\n\n(* the boolean in BlockedOnReceive is True if the object can receive but not send.\nbut Tom says it only matters if the sender can grant - which is not the case of the UT1 - I think *)\n\ndefinition\n  kh2 :: kheap\nwhere\n  \"kh2 \\<equiv> [0x6 \\<mapsto> obj2_0x6,\n           0x7 \\<mapsto> obj2_0x7,\n           0x9 \\<mapsto> obj2_0x9,\n           0xBF7 \\<mapsto> obj2_0xBF7,\n           0xBF9 \\<mapsto> obj2_0xBF9,\n           0xC00000 \\<mapsto> obj2_0xC00000,\n           0xC05000 \\<mapsto> obj2_0xC05000,\n           0xC07 \\<mapsto> obj2_0xC07,\n           0xC08 \\<mapsto> obj2_0xC08 ]\"\n\nlemmas kh2_obj_def =\n  obj2_0x6_def obj2_0x7_def obj2_0x9_def obj2_0xBF7_def obj2_0xBF9_def\n  obj2_0xC00000_def obj2_0xC05000_def obj2_0xC07_def obj2_0xC08_def\n\n\ndefinition\n  s2 :: \"det_ext state\"\nwhere\n  \"s2 \\<equiv>  \\<lparr>\n    kheap = kh2,\n    cdt = Map.empty,\n    is_original_cap = undefined,\n    cur_thread = undefined,\n    idle_thread = undefined,\n    machine_state = undefined,\n    interrupt_irq_node = (\\<lambda>_. 9001),\n    interrupt_states = undefined,\n    arch_state = \\<lparr>\n        riscv_asid_table = (\\<lambda>_. None),\n        riscv_global_pts = undefined,\n        riscv_kernel_vspace = undefined\n        \\<rparr>,\n    exst = exst1\n    \\<rparr>\"\n\n\nsubsubsection \\<open>Defining the policy graph\\<close>\n\n\ndatatype Sys2Labels =\n    UT2 | T2 | IRQ2\n\ndefinition\n  Sys2AgentMap :: \"Sys2Labels agent_map\"\nwhere\n  \"Sys2AgentMap \\<equiv>\n   (\\<lambda>_. undefined)\n     (0x5 := UT2,\n      0x6 := UT2,\n      0x7 := T2,\n      0x9 := T2,\n      0xBF7 := UT2,\n      0xBF9 := T2,\n      0xC00000 := UT2,\n      0xC05000 := T2,\n      0xC07 := UT2,\n      0xC08 := T2,\n      9001 := IRQ2 )\"\n\n\ndefinition\n  Sys2AuthGraph_aux :: \"Sys2Labels auth_graph\"\nwhere\n    \"Sys2AuthGraph_aux \\<equiv>\n       { (T2, Control, UT2) }\"\n\ndefinition\n  Sys2AuthGraph:: \"Sys2Labels auth_graph\"\nwhere\n    \"Sys2AuthGraph \\<equiv> complete_AuthGraph Sys2AuthGraph_aux {T2, UT2}\"\n\n\ndefinition\n  Sys2ASIDMap :: \"Sys2Labels agent_asid_map\"\nwhere\n  \"Sys2ASIDMap \\<equiv>\n    (\\<lambda>_. undefined)\n     (asid2_0xBF7 := UT2,\n      asid2_0xBF9 := T2 )\"\n\ndefinition Sys2PAS :: \"Sys2Labels PAS\" where\n  \"Sys2PAS \\<equiv> \\<lparr> pasObjectAbs = Sys2AgentMap, pasASIDAbs = Sys2ASIDMap,\n              pasIRQAbs = (\\<lambda>_. IRQ2),\n              pasPolicy = Sys2AuthGraph, pasSubject = UT2, pasMayActivate = True, pasMayEditReadyQueues = True, pasMaySendIrqs = True, pasDomainAbs = undefined \\<rparr>\"\n\n\n\nsubsubsection \\<open>Proof of pas_refined for Sys2\\<close>\n\nlemma caps2_0x7_well_formed: \"well_formed_cnode_n 10 caps2_0x7\"\n  apply (clarsimp simp: caps2_0x7_def well_formed_cnode_n_def)\n  apply (clarsimp simp: the_nat_to_bl_10_def the_nat_to_bl_def nat_to_bl_def)\n  apply (clarsimp simp: empty_cnode_def dom_def)\n  apply (rule set_eqI, clarsimp)\n  apply (rule iffI)\n   apply (elim disjE, insert len_bin_to_bl, simp_all)[1]\n  apply clarsimp\n  done\n\nlemma caps2_0x6_well_formed: \"well_formed_cnode_n 10 caps2_0x6\"\n  apply (clarsimp simp: caps2_0x6_def well_formed_cnode_n_def)\n  apply (clarsimp simp: the_nat_to_bl_10_def the_nat_to_bl_def nat_to_bl_def)\n  apply (clarsimp simp: empty_cnode_def dom_def)\n  apply (rule set_eqI, clarsimp)\n  apply (rule iffI)\n   apply (elim disjE, insert len_bin_to_bl, simp_all)[1]\n  apply clarsimp\n  done\n\nlemma s2_caps_of_state :\n  \"caps_of_state s2 p = Some cap \\<Longrightarrow>\n     cap = NullCap \\<or>\n     (p,cap) \\<in>\n       { ((6::obj_ref,(the_nat_to_bl_10 1)),  ThreadCap 0xC07),\n         ((6::obj_ref,(the_nat_to_bl_10 2)),  CNodeCap 6 undefined undefined),\n         ((6::obj_ref,(the_nat_to_bl_10 3)),  ArchObjectCap (PageTableCap 0xBF7 (Some (asid2_0xBF7, 0)))),\n         ((6::obj_ref,(the_nat_to_bl_10 4)),  CNodeCap 5 undefined undefined),\n         ((7::obj_ref,(the_nat_to_bl_10 1)),  ThreadCap 0xC08),\n         ((7::obj_ref,(the_nat_to_bl_10 2)),  CNodeCap 7 undefined undefined),\n         ((7::obj_ref,(the_nat_to_bl_10 3)),  ArchObjectCap (PageTableCap 0xBF9 (Some (asid2_0xBF9, 0)))),\n         ((7::obj_ref,(the_nat_to_bl_10 4)),  CNodeCap 5 undefined undefined),\n         ((0xC07::obj_ref, (tcb_cnode_index 0)), CNodeCap 6 undefined undefined ),\n         ((0xC07::obj_ref, (tcb_cnode_index 1)), ArchObjectCap (PageTableCap 0xBF7 (Some (asid2_0xBF7, 0)))),\n         ((0xC07::obj_ref, (tcb_cnode_index 2)), ReplyCap 0xC07 True {AllowGrant,AllowWrite}),\n         ((0xC07::obj_ref, (tcb_cnode_index 3)), NullCap),\n         ((0xC07::obj_ref, (tcb_cnode_index 4)), NullCap),\n         ((0xC08::obj_ref, (tcb_cnode_index 0)), CNodeCap 7 undefined undefined ),\n         ((0xC08::obj_ref, (tcb_cnode_index 1)), ArchObjectCap (PageTableCap 0xBF9 (Some (asid2_0xBF9, 0)))),\n         ((0xC08::obj_ref, (tcb_cnode_index 2)), ReplyCap 0xC08 True {AllowGrant,AllowWrite}),\n         ((0xC08::obj_ref, (tcb_cnode_index 3)), NullCap),\n         ((0xC08::obj_ref, (tcb_cnode_index 4)), NullCap)} \"\n  apply (insert caps2_0x7_well_formed)\n  apply (insert caps2_0x6_well_formed)\n  apply (simp add: caps_of_state_cte_wp_at cte_wp_at_cases s2_def kh2_def kh2_obj_def)\n  apply (case_tac p, clarsimp)\n  apply (clarsimp simp: cte_wp_at_cases split: if_splits)\n     apply (clarsimp simp: tcb_cap_cases_def split: if_splits)+\n   apply (clarsimp simp: caps2_0x7_def split: if_splits)\n  apply (clarsimp simp: caps2_0x6_def cte_wp_at_cases  split: if_splits)\n  done\n\nlemma Sys2_wellformed: \"pas_wellformed Sys2PAS\"\n  apply (clarsimp simp: Sys2PAS_def policy_wellformed_def)\n  apply (intro conjI)\n  apply (simp_all add: Sys2AuthGraph_def complete_AuthGraph_def\n                       Sys2AuthGraph_aux_def)\n  done\n\nlemma Sys2AgentMap_simps:\n  \"Sys2AgentMap 5 = UT2\"\n  \"Sys2AgentMap 6 = UT2\"\n  \"Sys2AgentMap 7 = T2\"\n  \"Sys2AgentMap 9 = T2\"\n  \"Sys2AgentMap 0xBF7 = UT2\"\n  \"Sys2AgentMap 0xBF9 = T2\"\n  \"Sys2AgentMap 0xC00000 = UT2\"\n  \"Sys2AgentMap 0xC05000 = T2\"\n  \"Sys2AgentMap 0xC07 = UT2\"\n  \"Sys2AgentMap 0xC08 = T2\"\n  \"Sys2AgentMap 9001 = IRQ2\"\n  by (simp_all add: Sys2AgentMap_def)\n\nlemma domains_of_state_s2[simp]:\n  \"domains_of_state s2 = {}\"\n  apply (rule equalityI)\n   apply (rule subsetI)\n   apply clarsimp\n   apply (erule domains_of_state_aux.induct)\n   apply (simp add: s2_def exst1_def)\n  apply simp\n  done\n\nlemma thread_bound_ntfns_2[simp]:\n  \"thread_bound_ntfns s2 = Map.empty\"\n  unfolding s2_def thread_bound_ntfns_def\n  apply (rule ext)\n  apply (simp add: get_tcb_def)\n  apply (simp add: kh2_def kh2_obj_def)\n  done\n\nlemma \"pas_refined Sys2PAS s2\"\n  apply (clarsimp simp: pas_refined_def)\n  apply (intro conjI)\n      apply (simp add: Sys2_wellformed)\n     apply (simp add: Sys2PAS_def s2_def Sys2AgentMap_def\n                      irq_map_wellformed_aux_def)\n    apply (clarsimp simp: auth_graph_map_def\n                          Sys2PAS_def\n                          state_objs_to_policy_def\n                          state_bits_to_policy_def tcb_domain_map_wellformed_aux_def)+\n    apply (erule state_bits_to_policyp.cases, simp_all)\n         apply (drule s2_caps_of_state, clarsimp)\n         apply (elim disjE, simp_all add: cap_auth_conferred_def\n                                          Sys2AgentMap_simps\n                                          Sys2AuthGraph_def Sys2AuthGraph_aux_def\n                                          complete_AuthGraph_def\n                              split: if_split_asm)[1]\n        apply (drule s2_caps_of_state, clarsimp)\n        apply (elim disjE, simp_all)[1]\n       apply (clarsimp simp: state_refs_of_def s2_def kh2_def kh2_obj_def\n                       split: if_splits)\n       apply (clarsimp split:if_splits option.splits\n                       simp: thread_st_auth_def tcb_states_of_state_def\n                             Sys2AgentMap_simps Sys2AuthGraph_def\n                             complete_AuthGraph_def Sys2AuthGraph_aux_def\n                      dest!: get_tcb_SomeD)\n      apply (simp add: s2_def) (* this is OK because cdt is empty..*)\n     apply (simp add: s2_def) (* this is OK because cdt is empty..*)\n    apply (fastforce simp: state_vrefs_def vs_refs_aux_def s2_def kh2_def kh2_obj_def pt2_0xBF9_def\n                           pt2_0xBF7_def pt2_0xC05000_def pt2_0xC00000_def Sys2AgentMap_simps\n                           Sys2AuthGraph_def Sys2AuthGraph_aux_def complete_AuthGraph_def\n                           pte_ref2_def graph_of_def opt_map_def ptr_range_def\n                    split: if_splits)\n   apply clarsimp\n   apply (erule state_asids_to_policy_aux.cases)\n    apply clarsimp\n    apply (fastforce simp: Sys2PAS_def Sys2AuthGraph_def Sys2AuthGraph_aux_def\n                           complete_AuthGraph_def Sys2AgentMap_simps asid_low_bits_def\n                           Sys2ASIDMap_def asid2_0xBF7_def asid2_0xBF9_def\n                    dest!: s2_caps_of_state)\n   apply (clarsimp simp: state_vrefs_def vs_refs_aux_def s2_def kh2_def kh2_obj_def\n                  split: if_splits)\n   apply (clarsimp simp: s2_def)\n  apply (clarsimp)\n  apply (erule state_irqs_to_policy_aux.cases)\n  apply (fastforce simp: Sys2PAS_def Sys2AuthGraph_def Sys2AuthGraph_aux_def\n                         complete_AuthGraph_def Sys2AgentMap_simps\n                         Sys2ASIDMap_def asid2_0xBF7_def asid2_0xBF9_def\n                  dest!: s2_caps_of_state)\n  done\n\nend\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/proof/access-control/RISCV64/ExampleSystem.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631698328917, "lm_q2_score": 0.42632159254749036, "lm_q1q2_score": 0.25905993029561447}}
{"text": "theory CoCallFix\nimports CoCallAnalysisSig CoCallAnalysisBinds ArityAnalysisSig \"Launchbury.Env-Nominal\"  ArityAnalysisFix\nbegin\n\n\nlocale CoCallArityAnalysis =\n  fixes cccExp :: \"exp \\<Rightarrow> (Arity \\<rightarrow> AEnv \\<times> CoCalls)\"\nbegin\n\ndefinition Aexp :: \"exp \\<Rightarrow> (Arity \\<rightarrow> AEnv)\"\n  where \"Aexp e = (\\<Lambda> a. fst (cccExp e \\<cdot> a))\"\n\nsublocale ArityAnalysis Aexp.\n\nabbreviation Aexp_syn' (\"\\<A>\\<^bsub>_\\<^esub>\") where \"\\<A>\\<^bsub>a\\<^esub> \\<equiv> (\\<lambda>e. Aexp e\\<cdot>a)\"\nabbreviation Aexp_bot_syn' (\"\\<A>\\<^sup>\\<bottom>\\<^bsub>_\\<^esub>\") where \"\\<A>\\<^sup>\\<bottom>\\<^bsub>a\\<^esub> \\<equiv> (\\<lambda>e. fup\\<cdot>(Aexp e)\\<cdot>a)\"\n\nlemma Aexp_eq:\n  \"\\<A>\\<^bsub>a\\<^esub> e = fst (cccExp e \\<cdot> a)\"\n  unfolding Aexp_def by (rule beta_cfun) (intro cont2cont)\n\nlemma fup_Aexp_eq:\n  \"fup\\<cdot>(Aexp e)\\<cdot>a = fst (fup\\<cdot>(cccExp e)\\<cdot>a)\"\n  by (cases a)(simp_all add: Aexp_eq)\n\n\ndefinition CCexp :: \"exp \\<Rightarrow> (Arity \\<rightarrow> CoCalls)\" where \"CCexp \\<Gamma> = (\\<Lambda> a. snd (cccExp \\<Gamma>\\<cdot>a))\"\nlemma CCexp_eq:\n  \"CCexp e\\<cdot>a = snd (cccExp e \\<cdot> a)\"\n  unfolding CCexp_def by (rule beta_cfun) (intro cont2cont)\n\nlemma fup_CCexp_eq:\n  \"fup\\<cdot>(CCexp e)\\<cdot>a = snd (fup\\<cdot>(cccExp e)\\<cdot>a)\"\n  by (cases a)(simp_all add: CCexp_eq)\n\nsublocale CoCallAnalysis CCexp.\n\ndefinition CCfix :: \"heap \\<Rightarrow> (AEnv \\<times> CoCalls) \\<rightarrow> CoCalls\"\n  where \"CCfix \\<Gamma> = (\\<Lambda> aeG. (\\<mu> G'. ccBindsExtra \\<Gamma>\\<cdot>(fst aeG , G') \\<squnion> snd aeG))\"\n\nlemma CCfix_eq:\n  \"CCfix \\<Gamma>\\<cdot>(ae,G) = (\\<mu> G'. ccBindsExtra \\<Gamma>\\<cdot>(ae, G') \\<squnion> G)\"\n  unfolding CCfix_def\n  by simp\n\nlemma CCfix_unroll: \"CCfix \\<Gamma>\\<cdot>(ae,G) = ccBindsExtra \\<Gamma>\\<cdot>(ae, CCfix \\<Gamma>\\<cdot>(ae,G)) \\<squnion> G\"\n  unfolding  CCfix_eq\n  apply (subst fix_eq)\n  apply simp\n  done\n\nlemma fup_ccExp_restr_subst': \n  assumes \"\\<And> a. cc_restr S (CCexp e[x::=y]\\<cdot>a) = cc_restr S (CCexp e\\<cdot>a)\"\n  shows \"cc_restr S (fup\\<cdot>(CCexp e[x::=y])\\<cdot>a) = cc_restr S (fup\\<cdot>(CCexp e)\\<cdot>a)\"\n  using assms\n  by (cases a) (auto simp del: cc_restr_cc_restr simp add: cc_restr_cc_restr[symmetric])\n\nlemma ccBindsExtra_restr_subst': \n  assumes \"\\<And> x' e a. (x',e) \\<in> set \\<Gamma> \\<Longrightarrow> cc_restr S (CCexp e[x::=y]\\<cdot>a) = cc_restr S (CCexp e\\<cdot>a)\"\n  assumes \"x \\<notin> S\"\n  assumes \"y \\<notin> S\"\n  assumes \"domA \\<Gamma> \\<subseteq> S\"\n  shows  \"cc_restr S (ccBindsExtra  \\<Gamma>[x::h=y]\\<cdot>(ae, G)) \n       = cc_restr S (ccBindsExtra  \\<Gamma>\\<cdot>(ae f|` S , cc_restr S G))\"\n  apply (simp add: ccBindsExtra_simp ccBinds_eq ccBind_eq Int_absorb2[OF assms(4)] fv_subst_int[OF assms(3,2)])\n  apply (intro arg_cong2[where f = \"(\\<squnion>)\"] refl  arg_cong[OF mapCollect_cong])\n  apply (subgoal_tac \"k \\<in> S\")\n  apply (auto intro: fup_ccExp_restr_subst'[OF assms(1)[OF map_of_SomeD]] simp add: fv_subst_int[OF assms(3,2)]   fv_subst_int2[OF assms(3,2)] ccSquare_def)[1]\n  apply (metis assms(4) contra_subsetD domI dom_map_of_conv_domA)\n  apply (subgoal_tac \"k \\<in> S\")\n  apply (auto intro: fup_ccExp_restr_subst'[OF assms(1)[OF map_of_SomeD]]\n              simp add: fv_subst_int[OF assms(3,2)]   fv_subst_int2[OF assms(3,2)] ccSquare_def cc_restr_twist[where S = S] simp del: cc_restr_cc_restr)[1]\n  apply (subst fup_ccExp_restr_subst'[OF assms(1)[OF map_of_SomeD]], assumption)\n  apply (simp add: fv_subst_int[OF assms(3,2)]   fv_subst_int2[OF assms(3,2)] )\n  apply (subst fup_ccExp_restr_subst'[OF assms(1)[OF map_of_SomeD]], assumption)\n  apply (simp add: fv_subst_int[OF assms(3,2)]   fv_subst_int2[OF assms(3,2)] )\n  apply (metis assms(4) contra_subsetD domI dom_map_of_conv_domA)\n  done\n\nlemma ccBindsExtra_restr:\n  assumes \"domA \\<Gamma> \\<subseteq> S\"\n  shows \"cc_restr S (ccBindsExtra \\<Gamma>\\<cdot>(ae, G)) = cc_restr S (ccBindsExtra \\<Gamma>\\<cdot>(ae f|` S, cc_restr S G))\"\n  using assms\n  apply (simp add: ccBindsExtra_simp ccBinds_eq ccBind_eq Int_absorb2)\n  apply (intro arg_cong2[where f = \"(\\<squnion>)\"] refl arg_cong[OF mapCollect_cong])\n  apply (subgoal_tac \"k \\<in> S\")\n  apply simp\n  apply (metis contra_subsetD domI dom_map_of_conv_domA)\n  apply (subgoal_tac \"k \\<in> S\")\n  apply simp\n  apply (metis contra_subsetD domI dom_map_of_conv_domA)\n  done\n\nlemma CCfix_restr:\n  assumes \"domA \\<Gamma> \\<subseteq> S\"\n  shows \"cc_restr S (CCfix \\<Gamma>\\<cdot>(ae, G)) = cc_restr S (CCfix \\<Gamma>\\<cdot>(ae f|` S, cc_restr S G))\"\n  unfolding CCfix_def\n  apply simp\n  apply (rule parallel_fix_ind[where P = \"\\<lambda> x y . cc_restr S x = cc_restr S y\"])\n  apply simp\n  apply rule\n  apply simp\n  apply (subst (1 2) ccBindsExtra_restr[OF assms])\n  apply (auto)\n  done\n\nlemma ccField_CCfix:\n  shows \"ccField (CCfix \\<Gamma>\\<cdot>(ae, G)) \\<subseteq> fv \\<Gamma> \\<union> ccField G\"\n  unfolding CCfix_def\n  apply simp\n  apply (rule fix_ind[where P = \"\\<lambda> x . ccField x \\<subseteq> fv \\<Gamma> \\<union> ccField G\"])\n  apply (auto dest!: subsetD[OF ccField_ccBindsExtra])\n  done\n\n\nlemma CCfix_restr_subst':\n  assumes \"\\<And> x' e a. (x',e) \\<in> set \\<Gamma> \\<Longrightarrow> cc_restr S (CCexp e[x::=y]\\<cdot>a) = cc_restr S (CCexp e\\<cdot>a)\"\n  assumes \"x \\<notin> S\"\n  assumes \"y \\<notin> S\"\n  assumes \"domA \\<Gamma> \\<subseteq> S\"\n  shows \"cc_restr S (CCfix \\<Gamma>[x::h=y]\\<cdot>(ae, G)) = cc_restr S (CCfix \\<Gamma>\\<cdot>(ae f|` S, cc_restr S G))\"\n  unfolding CCfix_def\n  apply simp\n  apply (rule parallel_fix_ind[where P = \"\\<lambda> x y . cc_restr S x = cc_restr S y\"])\n  apply simp\n  apply rule\n  apply simp\n  apply (subst  ccBindsExtra_restr_subst'[OF assms], assumption)\n  apply (subst ccBindsExtra_restr[OF assms(4)]) back \n  apply (auto)\n  done\n\n\nend\n\nlemma Aexp_eqvt[eqvt]:  \"\\<pi> \\<bullet> (CoCallArityAnalysis.Aexp cccExp e) = CoCallArityAnalysis.Aexp (\\<pi> \\<bullet> cccExp) (\\<pi> \\<bullet> e)\"\n  apply (rule cfun_eqvtI) unfolding CoCallArityAnalysis.Aexp_eq by perm_simp rule\n\nlemma CCexp_eqvt[eqvt]:  \"\\<pi> \\<bullet> (CoCallArityAnalysis.CCexp cccExp e) = CoCallArityAnalysis.CCexp (\\<pi> \\<bullet> cccExp) (\\<pi> \\<bullet> e)\"\n  apply (rule cfun_eqvtI) unfolding CoCallArityAnalysis.CCexp_eq by perm_simp rule\n\nlemma CCfix_eqvt[eqvt]: \"\\<pi> \\<bullet> (CoCallArityAnalysis.CCfix cccExp \\<Gamma>) = CoCallArityAnalysis.CCfix (\\<pi> \\<bullet> cccExp) (\\<pi> \\<bullet> \\<Gamma>)\"\n  unfolding CoCallArityAnalysis.CCfix_def by perm_simp (simp_all add: Abs_cfun_eqvt)\n\nlemma ccFix_cong[fundef_cong]:\n  \"\\<lbrakk> (\\<And> e. e \\<in> snd ` set heap2 \\<Longrightarrow> cccexp1 e = cccexp2 e); heap1 = heap2 \\<rbrakk>\n      \\<Longrightarrow> CoCallArityAnalysis.CCfix cccexp1 heap1 = CoCallArityAnalysis.CCfix cccexp2 heap2\"\n   unfolding CoCallArityAnalysis.CCfix_def\n   apply (rule arg_cong) back\n   apply (rule ccBindsExtra_cong)\n   apply (auto simp add: CoCallArityAnalysis.CCexp_def)\n   done\n\n\ncontext CoCallArityAnalysis\nbegin\ndefinition cccFix ::  \"heap \\<Rightarrow> ((AEnv \\<times> CoCalls) \\<rightarrow> (AEnv \\<times> CoCalls))\"\n  where \"cccFix \\<Gamma> = (\\<Lambda> i. (Afix \\<Gamma>\\<cdot>(fst i \\<squnion> (\\<lambda>_.up\\<cdot>0) f|` thunks \\<Gamma>), CCfix \\<Gamma>\\<cdot>(Afix \\<Gamma>\\<cdot>(fst i  \\<squnion> (\\<lambda>_.up\\<cdot>0) f|` (thunks \\<Gamma>)), snd i)))\"\n\nlemma cccFix_eq:\n  \"cccFix \\<Gamma>\\<cdot>i = (Afix \\<Gamma>\\<cdot>(fst i \\<squnion> (\\<lambda>_.up\\<cdot>0) f|` thunks \\<Gamma>), CCfix \\<Gamma>\\<cdot>(Afix \\<Gamma>\\<cdot>(fst i  \\<squnion> (\\<lambda>_.up\\<cdot>0) f|` (thunks \\<Gamma>)), snd i))\"\n  unfolding cccFix_def\n  by (rule beta_cfun)(intro cont2cont)\nend\n\nlemma cccFix_eqvt[eqvt]: \"\\<pi> \\<bullet> (CoCallArityAnalysis.cccFix cccExp \\<Gamma>) = CoCallArityAnalysis.cccFix  (\\<pi> \\<bullet> cccExp) (\\<pi> \\<bullet> \\<Gamma>)\"\n  apply (rule cfun_eqvtI) unfolding CoCallArityAnalysis.cccFix_eq by perm_simp rule\n\nlemma cccFix_cong[fundef_cong]:\n  \"\\<lbrakk> (\\<And> e. e \\<in> snd ` set heap2 \\<Longrightarrow> cccexp1 e = cccexp2 e); heap1 = heap2 \\<rbrakk>\n      \\<Longrightarrow> CoCallArityAnalysis.cccFix cccexp1 heap1 = CoCallArityAnalysis.cccFix cccexp2 heap2\"\n   unfolding CoCallArityAnalysis.cccFix_def\n   apply (rule cfun_eqI)\n   apply auto\n   apply (rule arg_cong[OF Afix_cong], auto simp add: CoCallArityAnalysis.Aexp_def)[1]\n   apply (rule arg_cong2[OF ccFix_cong Afix_cong ])\n   apply (auto simp add: CoCallArityAnalysis.Aexp_def)\n   done\n\n\nsubsubsection \\<open>The non-recursive case\\<close>\n\ndefinition ABind_nonrec :: \"var \\<Rightarrow> exp \\<Rightarrow> AEnv \\<times> CoCalls \\<rightarrow> Arity\\<^sub>\\<bottom>\"\nwhere\n  \"ABind_nonrec x e = (\\<Lambda> i. (if isVal e \\<or> x--x\\<notin>(snd i) then fst i x else up\\<cdot>0))\"\n\nlemma ABind_nonrec_eq:\n  \"ABind_nonrec x e\\<cdot>(ae,G) = (if isVal e \\<or> x--x\\<notin>G then ae x else up\\<cdot>0)\"\n  unfolding ABind_nonrec_def\n  apply (subst beta_cfun)\n  apply (rule cont_if_else_above)\n  apply auto\n  by (metis in_join join_self_below(4))\n\nlemma ABind_nonrec_eqvt[eqvt]: \"\\<pi> \\<bullet> (ABind_nonrec x e) = ABind_nonrec (\\<pi> \\<bullet> x) (\\<pi> \\<bullet> e)\"\n  apply (rule cfun_eqvtI)\n  apply (case_tac xa, simp)\n  unfolding ABind_nonrec_eq\n  by perm_simp rule\n\nlemma ABind_nonrec_above_arg:\n  \"ae x \\<sqsubseteq> ABind_nonrec x e \\<cdot> (ae, G)\"\nunfolding ABind_nonrec_eq by auto\n\ndefinition Aheap_nonrec where\n  \"Aheap_nonrec x e = (\\<Lambda> i. esing x\\<cdot>(ABind_nonrec x e\\<cdot>i))\"\n\nlemma Aheap_nonrec_simp:\n  \"Aheap_nonrec x e\\<cdot>i = esing x\\<cdot>(ABind_nonrec x e\\<cdot>i)\"\n  unfolding Aheap_nonrec_def by simp\n\nlemma Aheap_nonrec_lookup[simp]:\n  \"(Aheap_nonrec x e\\<cdot>i) x = ABind_nonrec x e\\<cdot>i\"\n  unfolding Aheap_nonrec_simp by simp\n\nlemma Aheap_nonrec_eqvt'[eqvt]:\n  \"\\<pi> \\<bullet> (Aheap_nonrec x e) = Aheap_nonrec (\\<pi> \\<bullet> x) (\\<pi> \\<bullet> e)\"\n  apply (rule cfun_eqvtI)\n  unfolding Aheap_nonrec_simp\n  by (perm_simp, rule)\n\n\ncontext CoCallArityAnalysis\nbegin\n\n  definition Afix_nonrec\n   where \"Afix_nonrec x e = (\\<Lambda> i. fup\\<cdot>(Aexp e)\\<cdot>(ABind_nonrec x e \\<cdot> i) \\<squnion> fst i)\"\n\n  lemma Afix_nonrec_eq[simp]:\n    \"Afix_nonrec x e \\<cdot> i = fup\\<cdot>(Aexp e)\\<cdot>(ABind_nonrec x e \\<cdot> i) \\<squnion> fst i\"\n    unfolding Afix_nonrec_def\n    by (rule beta_cfun) simp\n\n  definition CCfix_nonrec\n   where \"CCfix_nonrec x e = (\\<Lambda> i. ccBind x e \\<cdot> (Aheap_nonrec x e\\<cdot>i, snd i)  \\<squnion> ccProd (fv e) (ccNeighbors x (snd i) - (if isVal e then {} else {x})) \\<squnion> snd i)\"\n\n  lemma CCfix_nonrec_eq[simp]:\n    \"CCfix_nonrec x e \\<cdot> i = ccBind x e\\<cdot>(Aheap_nonrec x e\\<cdot>i, snd i)  \\<squnion> ccProd (fv e) (ccNeighbors x (snd i) - (if isVal e then {} else {x})) \\<squnion> snd i\"\n    unfolding CCfix_nonrec_def\n    by (rule beta_cfun) (intro cont2cont)\n\n  definition cccFix_nonrec ::  \"var \\<Rightarrow> exp \\<Rightarrow> ((AEnv \\<times> CoCalls) \\<rightarrow> (AEnv \\<times> CoCalls))\"\n    where \"cccFix_nonrec x e = (\\<Lambda> i. (Afix_nonrec x e \\<cdot>i , CCfix_nonrec x e \\<cdot>i))\"\n\n  lemma cccFix_nonrec_eq[simp]:\n    \"cccFix_nonrec x e\\<cdot>i = (Afix_nonrec x e \\<cdot>i , CCfix_nonrec x e \\<cdot>i)\"\n    unfolding cccFix_nonrec_def\n    by (rule beta_cfun) (intro cont2cont)\n\nend\n\n\nlemma AFix_nonrec_eqvt[eqvt]: \"\\<pi> \\<bullet> (CoCallArityAnalysis.Afix_nonrec cccExp x e) = CoCallArityAnalysis.Afix_nonrec (\\<pi> \\<bullet> cccExp) (\\<pi> \\<bullet> x) (\\<pi> \\<bullet> e)\"\n  apply (rule cfun_eqvtI)\n  unfolding CoCallArityAnalysis.Afix_nonrec_eq\n  by perm_simp rule\n\n\nlemma CCFix_nonrec_eqvt[eqvt]: \"\\<pi> \\<bullet> (CoCallArityAnalysis.CCfix_nonrec cccExp x e) = CoCallArityAnalysis.CCfix_nonrec (\\<pi> \\<bullet> cccExp) (\\<pi> \\<bullet> x) (\\<pi> \\<bullet> e)\"\n  apply (rule cfun_eqvtI)\n  unfolding CoCallArityAnalysis.CCfix_nonrec_eq\n  by perm_simp rule\n\nlemma cccFix_nonrec_eqvt[eqvt]: \"\\<pi> \\<bullet> (CoCallArityAnalysis.cccFix_nonrec cccExp x e) = CoCallArityAnalysis.cccFix_nonrec (\\<pi> \\<bullet> cccExp) (\\<pi> \\<bullet> x) (\\<pi> \\<bullet> e)\"\n  apply (rule cfun_eqvtI)\n  unfolding CoCallArityAnalysis.cccFix_nonrec_eq\n  by perm_simp rule\n\nsubsubsection \\<open>Combining the cases\\<close>\n\ncontext CoCallArityAnalysis\nbegin\n  definition cccFix_choose ::  \"heap \\<Rightarrow> ((AEnv \\<times> CoCalls) \\<rightarrow> (AEnv \\<times> CoCalls))\"\n    where \"cccFix_choose \\<Gamma> = (if nonrec \\<Gamma> then case_prod cccFix_nonrec (hd \\<Gamma>) else cccFix \\<Gamma>)\"\n\n  lemma cccFix_choose_simp1[simp]:\n    \"\\<not> nonrec \\<Gamma> \\<Longrightarrow> cccFix_choose \\<Gamma> = cccFix \\<Gamma>\"\n  unfolding cccFix_choose_def by simp\n\n  lemma cccFix_choose_simp2[simp]:\n    \"x \\<notin> fv e \\<Longrightarrow> cccFix_choose [(x,e)] = cccFix_nonrec x e\"\n  unfolding cccFix_choose_def nonrec_def by auto\n\nend\n\nlemma cccFix_choose_eqvt[eqvt]: \"\\<pi> \\<bullet> (CoCallArityAnalysis.cccFix_choose cccExp \\<Gamma>) = CoCallArityAnalysis.cccFix_choose (\\<pi> \\<bullet> cccExp) (\\<pi> \\<bullet> \\<Gamma>)\"\n  unfolding CoCallArityAnalysis.cccFix_choose_def \n  apply (cases nonrec \\<pi>  rule: eqvt_cases[where x = \\<Gamma>])\n  apply (perm_simp, rule)\n  apply simp\n  apply (erule nonrecE)\n  apply (simp )\n\n  apply simp\n  done\n\nlemma cccFix_nonrec_cong[fundef_cong]:\n  \"cccexp1 e = cccexp2 e  \\<Longrightarrow> CoCallArityAnalysis.cccFix_nonrec cccexp1 x e = CoCallArityAnalysis.cccFix_nonrec cccexp2 x e\"\n   apply (rule cfun_eqI)\n   unfolding CoCallArityAnalysis.cccFix_nonrec_eq\n   unfolding CoCallArityAnalysis.Afix_nonrec_eq\n   unfolding CoCallArityAnalysis.CCfix_nonrec_eq\n   unfolding CoCallArityAnalysis.fup_Aexp_eq\n   apply (simp only: )\n   apply (rule arg_cong[OF ccBind_cong])\n   apply simp\n   unfolding CoCallArityAnalysis.CCexp_def\n   apply simp\n   done\n\nlemma cccFix_choose_cong[fundef_cong]:\n  \"\\<lbrakk> (\\<And> e. e \\<in> snd ` set heap2 \\<Longrightarrow> cccexp1 e = cccexp2 e); heap1 = heap2 \\<rbrakk>\n      \\<Longrightarrow> CoCallArityAnalysis.cccFix_choose cccexp1 heap1 = CoCallArityAnalysis.cccFix_choose cccexp2 heap2\"\n   unfolding CoCallArityAnalysis.cccFix_choose_def\n   apply (rule cfun_eqI)\n   apply (auto elim!: nonrecE)\n   apply (rule arg_cong[OF cccFix_nonrec_cong], auto)\n   apply (rule arg_cong[OF cccFix_cong], auto)[1]\n   done\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Call_Arity/CoCallFix.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631556226292, "lm_q2_score": 0.42632159254749036, "lm_q1q2_score": 0.25905992423747276}}
{"text": "theory Friend\nimports \"../Observation_Setup\" Friend_Value_Setup\nbegin\n\n\nsubsection \\<open>Declassification bound\\<close>\n\nfun T :: \"(state,act,out) trans \\<Rightarrow> bool\"\nwhere \"T (Trans _ _ _ _) = False\"\n\ntext \\<open>The bound follows the same ``while-or-last-before'' scheme as the bound for post\nconfidentiality (Section~\\ref{sec:post-bound}), alternating between open (\\<open>BO\\<close>) and\nclosed (\\<open>BC\\<close>) phases.\n\nThe access window is initially open, because the two users are known not to exist when the system\nis initialized, so there cannot be friendship between them.\n\nThe bound also incorporates the static knowledge that the friendship status alternates between\n\\<open>False\\<close> and \\<open>True\\<close>.\\<close>\n\nfun alternatingFriends :: \"value list \\<Rightarrow> bool \\<Rightarrow> bool\" where\n  \"alternatingFriends [] _ = True\"\n| \"alternatingFriends (FrVal st # vl) st' \\<longleftrightarrow> st' = (\\<not>st) \\<and> alternatingFriends vl st\"\n| \"alternatingFriends (OVal _ # vl) st = alternatingFriends vl st\"\n\ninductive BO :: \"value list \\<Rightarrow> value list \\<Rightarrow> bool\"\nand BC :: \"value list \\<Rightarrow> value list \\<Rightarrow> bool\"\nwhere\n BO_FrVal[simp,intro!]:\n  \"BO (map FrVal fs) (map FrVal fs)\"\n|BO_BC[intro]:\n  \"BC vl vl1 \\<Longrightarrow>\n   BO (map FrVal fs @ OVal False # vl) (map FrVal fs @ OVal False # vl1)\"\n(*  *)\n|BC_FrVal[simp,intro!]:\n  \"BC (map FrVal fs) (map FrVal fs1)\"\n|BC_BO[intro]:\n  \"BO vl vl1 \\<Longrightarrow> (fs = [] \\<longleftrightarrow> fs1 = []) \\<Longrightarrow> (fs \\<noteq> [] \\<Longrightarrow> last fs = last fs1) \\<Longrightarrow>\n   BC (map FrVal fs  @ OVal True # vl)\n      (map FrVal fs1 @ OVal True # vl1)\"\n\ndefinition \"B vl vl1 \\<equiv> BO vl vl1 \\<and> alternatingFriends vl1 False\"\n\n\nlemma BO_Nil_Nil: \"BO vl vl1 \\<Longrightarrow> vl = [] \\<Longrightarrow> vl1 = []\"\nby (cases rule: BO.cases) auto\n\nno_notation relcomp (infixr \"O\" 75)\n\ninterpretation BD_Security_IO where\nistate = istate and step = step and\n\\<phi> = \\<phi> and f = f and \\<gamma> = \\<gamma> and g = g and T = T and B = B\ndone\n\nsubsection \\<open>Unwinding proof\\<close>\n\n(* Key lemma: *)\nlemma eqButUID_step_\\<gamma>_out:\nassumes ss1: \"eqButUID s s1\"\nand step: \"step s a = (ou,s')\" and step1: \"step s1 a = (ou1,s1')\"\nand \\<gamma>: \"\\<gamma> (Trans s a ou s')\"\nand os: \"open s \\<longrightarrow> friendIDs s = friendIDs s1\"\nshows \"ou = ou1\"\nproof -\n  from \\<gamma> obtain uid where uid: \"userOfA a = Some uid \\<and> uid \\<in> UIDs \\<and> uid \\<noteq> UID1 \\<and> uid \\<noteq> UID2\n                              \\<or> userOfA a = None\"\n    using UID1_UID2_UIDs  by (cases \"userOfA a\") auto\n  { fix uid\n    assume \"uid \\<in>\\<in> friendIDs s UID1 \\<or> uid \\<in>\\<in> friendIDs s UID2\" and \"uid \\<in> UIDs\"\n    with os have \"friendIDs s = friendIDs s1\" unfolding open_def openByF_def by auto\n  } note fIDs = this\n  { fix uid uid'\n    assume uid: \"uid \\<noteq> UID1\" \"uid \\<noteq> UID2\"\n    have \"friendIDs s uid = friendIDs s1 uid\" (is ?f_eq)\n     and \"pendingFReqs s uid = pendingFReqs s1 uid\" (is ?pFR_eq)\n     and \"uid \\<in>\\<in> friendIDs s uid' \\<longleftrightarrow> uid \\<in>\\<in> friendIDs s1 uid'\" (is ?f_iff)\n     and \"uid \\<in>\\<in> pendingFReqs s uid' \\<longleftrightarrow> uid \\<in>\\<in> pendingFReqs s1 uid'\" (is ?pFR_iff)\n     and \"friendReq s uid uid' = friendReq s1 uid uid'\" (is ?FR_eq)\n     and \"friendReq s uid' uid = friendReq s1 uid' uid\" (is ?FR_eq')\n    proof -\n      show ?f_eq ?pFR_eq using uid ss1 UID1_UID2_UIDs unfolding eqButUID_def\n        by (auto intro!: eqButUIDf_not_UID)\n      show ?f_iff ?pFR_iff using uid ss1 UID1_UID2_UIDs unfolding eqButUID_def\n        by (auto intro!: eqButUIDf_not_UID')\n      from uid have \"\\<not> (uid,uid') \\<in> {(UID1,UID2), (UID2,UID1)}\" by auto\n      then show ?FR_eq ?FR_eq' using ss1 UID1_UID2_UIDs unfolding eqButUID_def\n        by (auto intro!: eqButUID12_not_UID)\n    qed\n  } note simps = this eqButUID_def r_defs s_defs c_defs l_defs u_defs d_defs\n  note facts = ss1 step step1 uid\n  show ?thesis\n  proof (cases a)\n    case (Ract ra) then show ?thesis using facts by (cases ra) (auto simp add: simps)\n  next\n    case (Sact sa) then show ?thesis using facts by (cases sa) (auto simp add: simps)\n  next\n    case (Cact ca) then show ?thesis using facts by (cases ca) (auto simp add: simps)\n  next\n    case (Lact la)\n      then show ?thesis using facts proof (cases la)\n        case (lFriends uid p uid')\n          with \\<gamma> have uid: \"uid \\<in> UIDs\" using Lact by auto\n          then have uid_uid': \"uid \\<in>\\<in> friendIDs s uid' \\<longleftrightarrow> uid \\<in>\\<in> friendIDs s1 uid'\"\n            using ss1 UID1_UID2_UIDs unfolding eqButUID_def by (intro eqButUIDf_not_UID') auto\n          show ?thesis\n          proof (cases \"(uid' = UID1 \\<or> uid' = UID2) \\<and> uid \\<in>\\<in> friendIDs s uid'\")\n            case True\n              with uid have \"friendIDs s = friendIDs s1\" by (intro fIDs) auto\n              then show ?thesis using lFriends facts Lact by (auto simp: simps)\n          next\n            case False\n              then show ?thesis using lFriends facts Lact simps(1) uid_uid' by (auto simp: simps)\n          qed\n      next\n        case (lPosts uid p)\n          then have o: \"\\<And>PID. owner s PID = owner s1 PID\"\n                and n: \"\\<And>PID. post s PID = post s1 PID\"\n                and PIDs: \"postIDs s = postIDs s1\"\n                and viss: \"vis s = vis s1\"\n                and fu: \"\\<And>uid'. uid \\<in>\\<in> friendIDs s uid' \\<longleftrightarrow> uid \\<in>\\<in> friendIDs s1 uid'\"\n                and e: \"e_listPosts s uid p \\<longleftrightarrow> e_listPosts s1 uid p\"\n            using ss1 uid Lact unfolding eqButUID_def l_defs by (auto simp add: simps(3))\n          have \"listPosts s uid p = listPosts s1 uid p\"\n            unfolding listPosts_def o n PIDs fu viss ..\n          with e show ?thesis using Lact lPosts step step1 by auto\n      qed (auto simp add: simps)\n  next\n    case (Uact ua) then show ?thesis using facts by (cases ua) (auto simp add: simps)\n  next\n    case (Dact da) then show ?thesis using facts by (cases da) (auto simp add: simps)\n  qed\nqed\n\n\n(* helper *) lemma toggle_friends12_True:\nassumes rs: \"reach s\"\n    and IDs: \"IDsOK s [UID1, UID2] []\"\n    and nf12: \"\\<not>friends12 s\"\nobtains al oul\nwhere \"sstep s al = (oul, createFriend s UID1 (pass s UID1) UID2)\"\n  and \"al \\<noteq> []\" and \"eqButUID s (createFriend s UID1 (pass s UID1) UID2)\"\n  and \"friends12 (createFriend s UID1 (pass s UID1) UID2)\"\n  and \"O (traceOf s al) = []\" and \"V (traceOf s al) = [FrVal True]\"\nproof cases\n  assume \"UID1 \\<in>\\<in> pendingFReqs s UID2 \\<or> UID2 \\<in>\\<in> pendingFReqs s UID1\"\n  then show thesis proof\n    assume pFR: \"UID1 \\<in>\\<in> pendingFReqs s UID2\"\n    let ?a = \"Cact (cFriend UID2 (pass s UID2) UID1)\"\n    let ?s' = \"createFriend s UID1 (pass s UID1) UID2\"\n    let ?trn = \"Trans s ?a outOK ?s'\"\n    have step: \"step s ?a = (outOK, ?s')\" using IDs pFR UID1_UID2\n      unfolding createFriend_sym[of \"s\" \"UID1\" \"pass s UID1\" \"UID2\" \"pass s UID2\"]\n      by (auto simp add: c_defs)\n    moreover then have \"\\<phi> ?trn\" and \"f ?trn = FrVal True\" and \"friends12 ?s'\"\n      by (auto simp: c_defs friends12_def)\n    moreover have \"\\<not>\\<gamma> ?trn\" using UID1_UID2_UIDs by auto\n    ultimately show thesis using nf12 rs\n      by (intro that[of \"[?a]\" \"[outOK]\"]) (auto intro: Cact_cFriend_step_eqButUID)\n  next\n    assume pFR: \"UID2 \\<in>\\<in> pendingFReqs s UID1\"\n    let ?a = \"Cact (cFriend UID1 (pass s UID1) UID2)\"\n    let ?s' = \"createFriend s UID1 (pass s UID1) UID2\"\n    let ?trn = \"Trans s ?a outOK ?s'\"\n    have step: \"step s ?a = (outOK, ?s')\" using IDs pFR UID1_UID2 by (auto simp add: c_defs)\n    moreover then have \"\\<phi> ?trn\" and \"f ?trn = FrVal True\" and \"friends12 ?s'\"\n      by (auto simp: c_defs friends12_def)\n    moreover have \"\\<not>\\<gamma> ?trn\" using UID1_UID2_UIDs by auto\n    ultimately show thesis using nf12 rs\n      by (intro that[of \"[?a]\" \"[outOK]\"]) (auto intro: Cact_cFriend_step_eqButUID)\n  qed\nnext\n  assume pFR: \"\\<not>(UID1 \\<in>\\<in> pendingFReqs s UID2 \\<or> UID2 \\<in>\\<in> pendingFReqs s UID1)\"\n  let ?a1 = \"Cact (cFriendReq UID2 (pass s UID2) UID1 emptyReq)\"\n  let ?s1 = \"createFriendReq s UID2 (pass s UID2) UID1 emptyReq\"\n  let ?trn1 = \"Trans s ?a1 outOK ?s1\"\n  let ?a2 = \"Cact (cFriend UID1 (pass ?s1 UID1) UID2)\"\n  let ?s2 = \"createFriend ?s1 UID1 (pass ?s1 UID1) UID2\"\n  let ?trn2 = \"Trans ?s1 ?a2 outOK ?s2\"\n  have eFR: \"e_createFriendReq s UID2 (pass s UID2) UID1 emptyReq\" using IDs pFR nf12\n    using reach_friendIDs_symmetric[OF rs]\n    by (auto simp add: c_defs friends12_def)\n  then have step1: \"step s ?a1 = (outOK, ?s1)\" by auto\n  moreover then have \"\\<not>\\<phi> ?trn1\" and \"\\<not>\\<gamma> ?trn1\" using UID1_UID2_UIDs by auto\n  moreover have \"eqButUID s ?s1\" by (intro Cact_cFriendReq_step_eqButUID[OF step1]) auto\n  moreover have rs1: \"reach ?s1\" using step1 by (intro reach_PairI[OF rs])\n  moreover have step2: \"step ?s1 ?a2 = (outOK, ?s2)\" using IDs by (auto simp: c_defs)\n  moreover then have \"\\<phi> ?trn2\" and \"f ?trn2 = FrVal True\" and \"friends12 ?s2\"\n    by (auto simp: c_defs friends12_def)\n  moreover have \"\\<not>\\<gamma> ?trn2\" using UID1_UID2_UIDs by auto\n  moreover have \"eqButUID ?s1 ?s2\" by (intro Cact_cFriend_step_eqButUID[OF step2 rs1]) auto\n  moreover have \"?s2 = createFriend s UID1 (pass s UID1) UID2\"\n    using eFR by (intro createFriendReq_createFriend_absorb)\n  ultimately show thesis using nf12 rs\n    by (intro that[of \"[?a1, ?a2]\" \"[outOK, outOK]\"]) (auto intro: eqButUID_trans)\nqed\n\n(* helper *) lemma toggle_friends12_False:\nassumes rs: \"reach s\"\n    and IDs: \"IDsOK s [UID1, UID2] []\"\n    and f12: \"friends12 s\"\nobtains al oul\nwhere \"sstep s al = (oul, deleteFriend s UID1 (pass s UID1) UID2)\"\n  and \"al \\<noteq> []\" and \"eqButUID s (deleteFriend s UID1 (pass s UID1) UID2)\"\n  and \"\\<not>friends12 (deleteFriend s UID1 (pass s UID1) UID2)\"\n  and \"O (traceOf s al) = []\" and \"V (traceOf s al) = [FrVal False]\"\nproof -\n  let ?a = \"Dact (dFriend UID1 (pass s UID1) UID2)\"\n  let ?s' = \"deleteFriend s UID1 (pass s UID1) UID2\"\n  let ?trn = \"Trans s ?a outOK ?s'\"\n  have step: \"step s ?a = (outOK, ?s')\" using IDs f12 UID1_UID2\n    by (auto simp add: d_defs friends12_def)\n  moreover then have \"\\<phi> ?trn\" and \"f ?trn = FrVal False\" and \"\\<not>friends12 ?s'\"\n    using reach_friendIDs_symmetric[OF rs] by (auto simp: d_defs friends12_def)\n  moreover have \"\\<not>\\<gamma> ?trn\" using UID1_UID2_UIDs by auto\n  ultimately show thesis using f12 rs\n    by (intro that[of \"[?a]\" \"[outOK]\"]) (auto intro: Dact_dFriend_step_eqButUID)\nqed\n\n\ndefinition \\<Delta>0 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>0 s vl s1 vl1 \\<equiv>\n eqButUID s s1 \\<and> friendIDs s = friendIDs s1 \\<and> open s \\<and>\n BO vl vl1 \\<and> alternatingFriends vl1 (friends12 s1)\"\n\ndefinition \\<Delta>1 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>1 s vl s1 vl1 \\<equiv> (\\<exists>fs fs1.\n eqButUID s s1 \\<and> \\<not>open s \\<and>\n alternatingFriends vl1 (friends12 s1) \\<and>\n vl = map FrVal fs \\<and> vl1 = map FrVal fs1)\"\n\ndefinition \\<Delta>2 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>2 s vl s1 vl1 \\<equiv> (\\<exists>fs fs1 vlr vlr1.\n eqButUID s s1 \\<and> \\<not>open s \\<and> BO vlr vlr1 \\<and>\n alternatingFriends vl1 (friends12 s1) \\<and>\n (fs = [] \\<longleftrightarrow> fs1 = []) \\<and>\n (fs \\<noteq> [] \\<longrightarrow> last fs = last fs1) \\<and>\n (fs = [] \\<longrightarrow> friendIDs s = friendIDs s1) \\<and>\n vl =  map FrVal fs  @ OVal True # vlr \\<and>\n vl1 = map FrVal fs1 @ OVal True # vlr1)\"\n\nlemma \\<Delta>2_I:\nassumes \"eqButUID s s1\" \"\\<not>open s\" \"BO vlr vlr1\" \"alternatingFriends vl1 (friends12 s1)\"\n        \"fs = [] \\<longleftrightarrow> fs1 = []\" \"fs \\<noteq> [] \\<longrightarrow> last fs = last fs1\"\n        \"fs = [] \\<longrightarrow> friendIDs s = friendIDs s1\"\n        \"vl =  map FrVal fs  @ OVal True # vlr\"\n        \"vl1 = map FrVal fs1 @ OVal True # vlr1\"\nshows \"\\<Delta>2 s vl s1 vl1\"\nusing assms unfolding \\<Delta>2_def by blast\n\n\nlemma istate_\\<Delta>0:\nassumes B: \"B vl vl1\"\nshows \"\\<Delta>0 istate vl istate vl1\"\nusing assms unfolding \\<Delta>0_def istate_def B_def open_def openByA_def openByF_def friends12_def\nby auto\n\nlemma unwind_cont_\\<Delta>0: \"unwind_cont \\<Delta>0 {\\<Delta>0,\\<Delta>1,\\<Delta>2}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>0 s vl s1 vl1 \\<or>\n                           \\<Delta>1 s vl s1 vl1 \\<or>\n                           \\<Delta>2 s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \\<Delta>0: \"\\<Delta>0 s vl s1 vl1\"\n  then have rs: \"reach s\" and ss1: \"eqButUID s s1\" and fIDs: \"friendIDs s = friendIDs s1\"\n        and os: \"open s\" and BO: \"BO vl vl1\" and aF1: \"alternatingFriends vl1 (friends12 s1)\"\n    using reachNT_reach unfolding \\<Delta>0_def by auto\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof-\n    have ?react proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\"\n      assume step: \"step s a = (ou, s')\" and T: \"\\<not> T ?trn\" and c: \"consume ?trn vl vl'\"\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n      proof cases\n        assume \\<phi>: \"\\<phi> ?trn\"\n        then have vl: \"vl = f ?trn # vl'\" using c by (auto simp: consume_def)\n        from BO have ?match proof (cases \"f ?trn\")\n          case (FrVal fv)\n            with BO vl obtain vl1' where vl1': \"vl1 = f ?trn # vl1'\" and BO': \"BO vl' vl1'\"\n            proof (cases rule: BO.cases)\n              case (BO_BC vl'' vl1'' fs)\n                moreover with vl FrVal obtain fs' where \"fs = fv # fs'\" by (cases fs) auto\n                ultimately show ?thesis using FrVal BO_BC vl\n                  by (intro that[of \"map FrVal fs' @ OVal False # vl1''\"]) auto\n            qed auto\n            from fIDs have f12: \"friends12 s = friends12 s1\" unfolding friends12_def by auto\n            show ?match using \\<phi> step rs FrVal proof (cases rule: \\<phi>E)\n              case (Friend uid p uid')\n                then have IDs1: \"IDsOK s1 [UID1, UID2] []\"\n                  using ss1 unfolding eqButUID_def by auto\n                let ?s1' = \"createFriend s1 UID1 (pass s1 UID1) UID2\"\n                have s': \"s' = createFriend s UID1 p UID2\"\n                  using Friend step by (auto simp: createFriend_sym)\n                have ss': \"eqButUID s s'\" using rs step Friend\n                  by (auto intro: Cact_cFriend_step_eqButUID)\n                moreover then have os': \"open s'\" using os eqButUID_open_eq by auto\n                moreover obtain al oul where al: \"sstep s1 al = (oul, ?s1')\" \"al \\<noteq> []\"\n                                         and tr1: \"O (traceOf s1 al) = []\"\n                                                  \"V (traceOf s1 al) = [FrVal True]\"\n                                         and f12s1': \"friends12 ?s1'\"\n                                         and s1s1': \"eqButUID s1 ?s1'\"\n                  using rs1 IDs1 Friend unfolding f12 by (auto elim: toggle_friends12_True)\n                moreover have \"friendIDs s' = friendIDs ?s1'\"\n                  using Friend(6) f12 unfolding s'\n                  by (intro eqButUID_createFriend12_friendIDs_eq[OF ss1 rs rs1]) auto\n                ultimately have \"\\<Delta>0 s' vl' ?s1' vl1'\"\n                  using ss1 BO' aF1 unfolding \\<Delta>0_def vl1' Friend(3)\n                  by (auto intro: eqButUID_trans eqButUID_sym)\n                moreover have \"\\<not>\\<gamma> ?trn\" using Friend UID1_UID2_UIDs by auto\n                ultimately show ?match using tr1 vl1' Friend\n                  by (intro matchI_ms[OF al]) (auto simp: consumeList_def)\n            next\n              case (Unfriend uid p uid')\n                then have IDs1: \"IDsOK s1 [UID1, UID2] []\"\n                  using ss1 unfolding eqButUID_def by auto\n                let ?s1' = \"deleteFriend s1 UID1 (pass s1 UID1) UID2\"\n                have s': \"s' = deleteFriend s UID1 p UID2\"\n                  using Unfriend step by (auto simp: deleteFriend_sym)\n                have ss': \"eqButUID s s'\" using rs step Unfriend\n                  by (auto intro: Dact_dFriend_step_eqButUID)\n                moreover then have os': \"open s'\" using os eqButUID_open_eq by auto\n                moreover obtain al oul where al: \"sstep s1 al = (oul, ?s1')\" \"al \\<noteq> []\"\n                                         and tr1: \"O (traceOf s1 al) = []\"\n                                                  \"V (traceOf s1 al) = [FrVal False]\"\n                                         and f12s1': \"\\<not>friends12 ?s1'\"\n                                         and s1s1': \"eqButUID s1 ?s1'\"\n                  using rs1 IDs1 Unfriend unfolding f12 by (auto elim: toggle_friends12_False)\n                moreover have \"friendIDs s' = friendIDs ?s1'\"\n                  using fIDs unfolding s' by (auto simp: d_defs)\n                ultimately have \"\\<Delta>0 s' vl' ?s1' vl1'\"\n                  using ss1 BO' aF1 unfolding \\<Delta>0_def vl1' Unfriend(3)\n                  by (auto intro: eqButUID_trans eqButUID_sym)\n                moreover have \"\\<not>\\<gamma> ?trn\" using Unfriend UID1_UID2_UIDs by auto\n                ultimately show ?match using tr1 vl1' Unfriend\n                  by (intro matchI_ms[OF al]) (auto simp: consumeList_def)\n            qed auto\n        next\n          case (OVal ov)\n            with BO vl obtain vl1' where vl1': \"vl1 = OVal False # vl1'\"\n                                      and vl': \"vl = OVal False # vl'\"\n                                      and BC: \"BC vl' vl1'\"\n            proof (cases rule: BO.cases)\n              case (BO_BC vl'' vl1'' fs)\n                moreover then have \"fs = []\" using vl unfolding OVal by (cases fs) auto\n                ultimately show thesis using vl by (intro that[of vl1'']) auto\n            qed auto\n            then have \"f ?trn = OVal False\" using vl by auto\n            with \\<phi> step rs show ?match proof (cases rule: \\<phi>E)\n              case (CloseF uid p uid')\n                let ?s1' = \"deleteFriend s1 uid p uid'\"\n                let ?trn1 = \"Trans s1 a outOK ?s1'\"\n                have s': \"s' = deleteFriend s uid p uid'\" using CloseF step by auto\n                have step1: \"step s1 a = (outOK, ?s1')\"\n                  using CloseF step ss1 fIDs unfolding eqButUID_def by (auto simp: d_defs)\n                have s's1': \"eqButUID s' ?s1'\" using eqButUID_step[OF ss1 step step1 rs rs1] .\n                moreover have os': \"\\<not>open s'\" using CloseF os unfolding open_def by auto\n                moreover have fIDs': \"friendIDs s' = friendIDs ?s1'\"\n                  using fIDs unfolding s' by (auto simp: d_defs)\n                moreover have f12s1: \"friends12 s1 = friends12 ?s1'\"\n                  using CloseF(2) UID1_UID2_UIDs unfolding friends12_def d_defs by auto\n                from BC have \"\\<Delta>1 s' vl' ?s1' vl1' \\<or> \\<Delta>2 s' vl' ?s1' vl1'\"\n                proof (cases rule: BC.cases)\n                  case (BC_FrVal fs fs1)\n                    then show ?thesis using aF1 os' fIDs' f12s1 s's1' unfolding \\<Delta>1_def vl1' by auto\n                next\n                  case (BC_BO vlr vlr1 fs fs1)\n                    then have \"\\<Delta>2 s' vl' ?s1' vl1'\" using s's1' os' aF1 f12s1 fIDs' unfolding vl1'\n                      by (intro \\<Delta>2_I[of _ _ _ _ _ fs fs1]) auto\n                    then show ?thesis ..\n                qed\n                moreover have \"open s1\" \"\\<not>open ?s1'\"\n                  using ss1 os s's1' os' by (auto simp: eqButUID_open_eq)\n                moreover then have \"\\<phi> ?trn1\" unfolding CloseF by auto\n                ultimately show ?match using step1 vl1' CloseF UID1_UID2 UID1_UID2_UIDs\n                  by (intro matchI[of s1 a outOK ?s1' vl1 vl1']) (auto simp: consume_def)\n            next\n              case (CloseA uid p uid' p')\n                let ?s1' = \"createUser s1 uid p uid' p'\"\n                let ?trn1 = \"Trans s1 a outOK ?s1'\"\n                have s': \"s' = createUser s uid p uid' p'\" using CloseA step by auto\n                have step1: \"step s1 a = (outOK, ?s1')\"\n                  using CloseA step ss1 unfolding eqButUID_def by (auto simp: c_defs)\n                have s's1': \"eqButUID s' ?s1'\" using eqButUID_step[OF ss1 step step1 rs rs1] .\n                moreover have os': \"\\<not>open s'\" using CloseA os unfolding open_def by auto\n                moreover have fIDs': \"friendIDs s' = friendIDs ?s1'\"\n                  using fIDs unfolding s' by (auto simp: c_defs)\n                moreover have f12s1: \"friends12 s1 = friends12 ?s1'\"\n                  unfolding friends12_def by (auto simp: c_defs)\n                from BC have \"\\<Delta>1 s' vl' ?s1' vl1' \\<or> \\<Delta>2 s' vl' ?s1' vl1'\"\n                proof (cases rule: BC.cases)\n                  case (BC_FrVal fs fs1)\n                    then show ?thesis using aF1 os' fIDs' f12s1 s's1' unfolding \\<Delta>1_def vl1' by auto\n                next\n                  case (BC_BO vlr vlr1 fs fs1)\n                    then have \"\\<Delta>2 s' vl' ?s1' vl1'\" using s's1' os' aF1 f12s1 fIDs' unfolding vl1'\n                      by (intro \\<Delta>2_I[of _ _ _ _ _ fs fs1]) auto\n                    then show ?thesis ..\n                qed\n                moreover have \"open s1\" \"\\<not>open ?s1'\"\n                  using ss1 os s's1' os' by (auto simp: eqButUID_open_eq)\n                moreover then have \"\\<phi> ?trn1\" unfolding CloseA by auto\n                ultimately show ?match using step1 vl1' CloseA UID1_UID2 UID1_UID2_UIDs\n                  by (intro matchI[of s1 a outOK ?s1' vl1 vl1']) (auto simp: consume_def)\n            qed auto\n        qed\n        then show \"?match \\<or> ?ignore\" ..\n      next\n        assume n\\<phi>: \"\\<not>\\<phi> ?trn\"\n        then have os': \"open s = open s'\" and f12s': \"friends12 s = friends12 s'\"\n          using step_open_\\<phi>[OF step] step_friends12_\\<phi>[OF step] by auto\n        have vl': \"vl' = vl\" using n\\<phi> c by (auto simp: consume_def)\n        show ?thesis proof (cases \"a \\<noteq> Cact (cFriend UID1 (pass s UID1) UID2) \\<and>\n                                   a \\<noteq> Cact (cFriend UID2 (pass s UID2) UID1) \\<and>\n                                   a \\<noteq> Dact (dFriend UID1 (pass s UID1) UID2) \\<and>\n                                   a \\<noteq> Dact (dFriend UID2 (pass s UID2) UID1)\")\n          case True\n            obtain ou1 s1' where step1: \"step s1 a = (ou1, s1')\" by (cases \"step s1 a\") auto\n            let ?trn1 = \"Trans s1 a ou1 s1'\"\n            have fIDs': \"friendIDs s' = friendIDs s1'\"\n              using eqButUID_step_friendIDs_eq[OF ss1 rs rs1 step step1 True fIDs] .\n            from True n\\<phi> have n\\<phi>': \"\\<not>\\<phi> ?trn1\" using eqButUID_step_\\<phi>[OF ss1 rs rs1 step step1] by auto\n            then have f12s1': \"friends12 s1 = friends12 s1'\"\n              using step_friends12_\\<phi>[OF step1] by auto\n            have \"eqButUID s' s1'\" using eqButUID_step[OF ss1 step step1 rs rs1] .\n            then have \"\\<Delta>0 s' vl' s1' vl1\" using os fIDs' aF1 BO\n              unfolding \\<Delta>0_def os' f12s1' vl' by auto\n            then have ?match\n              using step1 n\\<phi>' fIDs eqButUID_step_\\<gamma>_out[OF ss1 step step1]\n              by (intro matchI[of s1 a ou1 s1' vl1 vl1]) (auto simp: consume_def)\n            then show \"?match \\<or> ?ignore\" ..\n        next\n          case False\n            with n\\<phi> have \"ou \\<noteq> outOK\" by auto\n            then have \"s' = s\" using step False by auto\n            then have ?ignore using \\<Delta>0 False UID1_UID2_UIDs unfolding vl' by (intro ignoreI) auto\n            then show \"?match \\<or> ?ignore\" ..\n        qed\n      qed\n    qed\n    then show ?thesis using BO BO_Nil_Nil by auto\n  qed\nqed\n\nlemma unwind_cont_\\<Delta>1: \"unwind_cont \\<Delta>1 {\\<Delta>1, \\<Delta>0}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>1 s vl s1 vl1 \\<or> \\<Delta>0 s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and 1: \"\\<Delta>1 s vl s1 vl1\"\n  from rsT have rs: \"reach s\" by (intro reachNT_reach)\n  from 1 obtain fs fs1\n  where ss1: \"eqButUID s s1\" and os: \"\\<not>open s\"\n    and aF1: \"alternatingFriends vl1 (friends12 s1)\"\n    and vl: \"vl = map FrVal fs\" and vl1: \"vl1 = map FrVal fs1\"\n    unfolding \\<Delta>1_def by auto\n  from os have IDs: \"IDsOK s [UID1, UID2] []\" unfolding open_defs by auto\n  then have IDs1: \"IDsOK s1 [UID1, UID2] []\" using ss1 unfolding eqButUID_def by auto\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof cases\n    assume fs1: \"fs1 = []\"\n    have ?react proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\"\n      assume step: \"step s a = (ou, s')\" and T: \"\\<not> T ?trn\" and c: \"consume ?trn vl vl'\"\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n      proof cases\n        assume \\<phi>: \"\\<phi> ?trn\"\n        with vl c obtain fv fs' where vl': \"vl' = map FrVal fs'\" and fv: \"f ?trn = FrVal fv\"\n          by (cases fs) (auto simp: consume_def)\n        from \\<phi> step rs fv have ss': \"eqButUID s s'\"\n          by (elim \\<phi>E) (auto intro: Cact_cFriend_step_eqButUID Dact_dFriend_step_eqButUID)\n        then have \"\\<not>open s'\" using os by (auto simp: eqButUID_open_eq)\n        moreover have \"eqButUID s' s1\" using ss1 ss' by (auto intro: eqButUID_sym eqButUID_trans)\n        ultimately have \"\\<Delta>1 s' vl' s1 vl1\" using aF1 unfolding \\<Delta>1_def vl' vl1 by auto\n        moreover have \"\\<not>\\<gamma> ?trn\" using \\<phi> step rs fv UID1_UID2_UIDs by (elim \\<phi>E) auto\n        ultimately have ?ignore by (intro ignoreI) auto\n        then show \"?match \\<or> ?ignore\" ..\n      next\n        assume n\\<phi>: \"\\<not>\\<phi> ?trn\"\n        then have os': \"open s = open s'\" and f12s': \"friends12 s = friends12 s'\"\n          using step_open_\\<phi>[OF step] step_friends12_\\<phi>[OF step] by auto\n        have vl': \"vl' = vl\" using n\\<phi> c by (auto simp: consume_def)\n        show ?thesis proof (cases \"a \\<noteq> Cact (cFriend UID1 (pass s UID1) UID2) \\<and>\n                                   a \\<noteq> Cact (cFriend UID2 (pass s UID2) UID1) \\<and>\n                                   a \\<noteq> Dact (dFriend UID1 (pass s UID1) UID2) \\<and>\n                                   a \\<noteq> Dact (dFriend UID2 (pass s UID2) UID1)\")\n          case True\n            obtain ou1 s1' where step1: \"step s1 a = (ou1, s1')\" by (cases \"step s1 a\") auto\n            let ?trn1 = \"Trans s1 a ou1 s1'\"\n            from True n\\<phi> have n\\<phi>': \"\\<not>\\<phi> ?trn1\" using eqButUID_step_\\<phi>[OF ss1 rs rs1 step step1] by auto\n            then have f12s1': \"friends12 s1 = friends12 s1'\"\n              using step_friends12_\\<phi>[OF step1] by auto\n            have \"eqButUID s' s1'\" using eqButUID_step[OF ss1 step step1 rs rs1] .\n            then have \"\\<Delta>1 s' vl' s1' vl1\" using os aF1 vl vl1\n              unfolding \\<Delta>1_def os' vl' f12s1' by auto\n            then have ?match\n              using step1 n\\<phi>' os eqButUID_step_\\<gamma>_out[OF ss1 step step1]\n              by (intro matchI[of s1 a ou1 s1' vl1 vl1]) (auto simp: consume_def)\n            then show \"?match \\<or> ?ignore\" ..\n        next\n          case False\n            with n\\<phi> have \"ou \\<noteq> outOK\" by auto\n            then have \"s' = s\" using step False by auto\n            then have ?ignore using 1 False UID1_UID2_UIDs unfolding vl' by (intro ignoreI) auto\n            then show \"?match \\<or> ?ignore\" ..\n        qed\n      qed\n    qed\n    then show ?thesis using fs1 unfolding vl1 by auto\n  next\n    assume \"fs1 \\<noteq> []\"\n    then obtain fs1' where fs1: \"fs1 = (\\<not>friends12 s1) # fs1'\"\n                       and aF1': \"alternatingFriends (map FrVal fs1') (\\<not>friends12 s1)\"\n      using aF1 unfolding vl1 by (cases fs1) auto\n    obtain al oul s1' where \"sstep s1 al = (oul, s1')\" \"al \\<noteq> []\" \"eqButUID s1 s1'\"\n                            \"friends12 s1' = (\\<not>friends12 s1)\"\n                            \"O (traceOf s1 al) = []\" \"V (traceOf s1 al) = [FrVal (\\<not>friends12 s1)]\"\n      using rs1 IDs1\n      by (cases \"friends12 s1\") (auto intro: toggle_friends12_True toggle_friends12_False)\n    moreover then have \"\\<Delta>1 s vl s1' (map FrVal fs1')\"\n      using os aF1' vl ss1 unfolding \\<Delta>1_def by (auto intro: eqButUID_sym eqButUID_trans)\n    ultimately have ?iact using vl1 unfolding fs1\n      by (intro iactionI_ms[of s1 al oul s1'])\n         (auto simp: consumeList_def O_Nil_never list_ex_iff_length_V)\n    then show ?thesis ..\n  qed\nqed\n\nlemma unwind_cont_\\<Delta>2: \"unwind_cont \\<Delta>2 {\\<Delta>2,\\<Delta>0}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>2 s vl s1 vl1 \\<or> \\<Delta>0 s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and 2: \"\\<Delta>2 s vl s1 vl1\"\n  from rsT have rs: \"reach s\" by (intro reachNT_reach)\n  obtain fs fs1 vlr vlr1\n  where ss1: \"eqButUID s s1\" and os: \"\\<not>open s\" and BO: \"BO vlr vlr1\"\n    and aF1: \"alternatingFriends vl1 (friends12 s1)\"\n    and vl:  \"vl =  map FrVal fs  @ OVal True # vlr\"\n    and vl1: \"vl1 = map FrVal fs1 @ OVal True # vlr1\"\n    and fs_fs1: \"fs = [] \\<longleftrightarrow> fs1 = []\"\n    and last_fs: \"fs \\<noteq> [] \\<longrightarrow> last fs = last fs1\"\n    and fs_fIDs: \"fs = [] \\<longrightarrow> friendIDs s = friendIDs s1\"\n    using 2 unfolding \\<Delta>2_def by auto\n  from os have IDs: \"IDsOK s [UID1, UID2] []\" unfolding open_defs by auto\n  then have IDs1: \"IDsOK s1 [UID1, UID2] []\" using ss1 unfolding eqButUID_def by auto\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof cases\n    assume \"length fs1 > 1\"\n    then obtain fs1'\n    where fs1: \"fs1 = (\\<not>friends12 s1) # fs1'\" and fs1': \"fs1' \\<noteq> []\"\n      and last_fs': \"last fs1 = last fs1'\"\n      and aF1': \"alternatingFriends (map FrVal fs1' @ OVal True # vlr1) (\\<not>friends12 s1)\"\n      using vl1 aF1 by (cases fs1) auto\n    obtain al oul s1' where \"sstep s1 al = (oul, s1')\" \"al \\<noteq> []\" \"eqButUID s1 s1'\"\n                            \"friends12 s1' = (\\<not>friends12 s1)\"\n                            \"O (traceOf s1 al) = []\" \"V (traceOf s1 al) = [FrVal (\\<not>friends12 s1)]\"\n      using rs1 IDs1\n      by (cases \"friends12 s1\") (auto intro: toggle_friends12_True toggle_friends12_False)\n    moreover then have \"\\<Delta>2 s vl s1' (map FrVal fs1' @ OVal True # vlr1)\"\n      using os aF1' vl ss1 fs1' last_fs' fs_fs1 last_fs BO unfolding fs1\n      by (intro \\<Delta>2_I[of _ _ vlr vlr1 _ fs fs1'])\n         (auto intro: eqButUID_sym eqButUID_trans)\n    ultimately have ?iact using vl1 unfolding fs1\n      by (intro iactionI_ms[of s1 al oul s1'])\n         (auto simp: consumeList_def O_Nil_never list_ex_iff_length_V)\n    then show ?thesis ..\n  next\n    assume len1_leq_1: \"\\<not> length fs1 > 1\"\n    have ?react proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\"  let ?trn1 = \"Trans s1 a ou s'\"\n      assume step: \"step s a = (ou, s')\" and T: \"\\<not> T ?trn\" and c: \"consume ?trn vl vl'\"\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n      proof cases\n        assume \\<phi>: \"\\<phi> ?trn\"\n        show ?thesis proof cases\n          assume \"length fs > 1\"\n          then obtain fv fs'\n          where fs1: \"fs = fv # fs'\" and fs1': \"fs' \\<noteq> []\"\n            and last_fs': \"last fs = last fs'\"\n            using vl by (cases fs) auto\n          with \\<phi> c have fv: \"f ?trn = FrVal fv\" and vl': \"vl' = map FrVal fs' @ OVal True # vlr\"\n            unfolding vl consume_def by auto\n          from \\<phi> step rs fv have ss': \"eqButUID s s'\"\n            by (elim \\<phi>E) (auto intro: Cact_cFriend_step_eqButUID Dact_dFriend_step_eqButUID)\n          then have \"\\<not>open s'\" using os by (auto simp: eqButUID_open_eq)\n          moreover have \"eqButUID s' s1\" using ss1 ss' by (auto intro: eqButUID_sym eqButUID_trans)\n          ultimately have \"\\<Delta>2 s' vl' s1 vl1\"\n            using aF1 vl' fs1' fs_fs1 last_fs BO unfolding fs1 vl1\n            by (intro \\<Delta>2_I[of _ _ vlr vlr1 _ fs' fs1])\n               (auto intro: eqButUID_sym eqButUID_trans)\n          moreover have \"\\<not>\\<gamma> ?trn\" using \\<phi> step rs fv UID1_UID2_UIDs by (elim \\<phi>E) auto\n          ultimately have ?ignore by (intro ignoreI) auto\n          then show \"?match \\<or> ?ignore\" ..\n        next\n          assume len_leq_1: \"\\<not> length fs > 1\"\n          show ?thesis proof cases\n            assume fs: \"fs = []\"\n            then have fs1: \"fs1 = []\" and fIDs: \"friendIDs s = friendIDs s1\"\n              using fs_fs1 fs_fIDs by auto\n            from fs \\<phi> c have ov: \"f ?trn = OVal True\" and vl': \"vl' = vlr\"\n              unfolding vl consume_def by auto\n            with \\<phi> step rs have ?match proof (cases rule: \\<phi>E)\n              case (OpenF uid p uid')\n                let ?s1' = \"createFriend s1 uid p uid'\"\n                let ?trn1 = \"Trans s1 a outOK ?s1'\"\n                have s': \"s' = createFriend s uid p uid'\" using OpenF step by auto\n                have \"eqButUIDf (pendingFReqs s) (pendingFReqs s1)\"\n                  using ss1 unfolding eqButUID_def by auto\n                then have \"uid' \\<in>\\<in> pendingFReqs s uid \\<longleftrightarrow> uid' \\<in>\\<in> pendingFReqs s1 uid\"\n                  using OpenF by (intro eqButUIDf_not_UID') auto\n                then have step1: \"step s1 a = (outOK, ?s1')\"\n                  using OpenF step ss1 fIDs unfolding eqButUID_def by (auto simp: c_defs)\n                have s's1': \"eqButUID s' ?s1'\" using eqButUID_step[OF ss1 step step1 rs rs1] .\n                moreover have os': \"open s'\" using OpenF unfolding open_def by auto\n                moreover have fIDs': \"friendIDs s' = friendIDs ?s1'\"\n                  using fIDs unfolding s' by (auto simp: c_defs)\n                moreover have f12s1: \"friends12 s1 = friends12 ?s1'\"\n                  using OpenF(2) UID1_UID2_UIDs unfolding friends12_def c_defs by auto\n                ultimately have \"\\<Delta>0 s' vl' ?s1' vlr1\"\n                  using BO aF1 unfolding \\<Delta>0_def vl' vl1 fs1 by auto\n                moreover have \"\\<not>open s1\" \"open ?s1'\"\n                  using ss1 os s's1' os' by (auto simp: eqButUID_open_eq)\n                moreover then have \"\\<phi> ?trn1\" unfolding OpenF by auto\n                ultimately show ?match using step1 vl1 fs1 OpenF UID1_UID2 UID1_UID2_UIDs\n                  by (intro matchI[of s1 a outOK ?s1' vl1 vlr1]) (auto simp: consume_def)\n            qed auto\n            then show ?thesis ..\n          next\n            assume \"fs \\<noteq> []\"\n            then obtain fv where fs: \"fs = [fv]\" using len_leq_1 by (cases fs) auto\n            then have fs1: \"fs1 = [fv]\" using len1_leq_1 fs_fs1 last_fs by (cases fs1) auto\n            with aF1 have f12s1: \"friends12 s1 = (\\<not>fv)\" unfolding vl1 by auto\n            have fv: \"f ?trn = FrVal fv\" and vl': \"vl' = OVal True # vlr\"\n              using c \\<phi> unfolding vl fs by (auto simp: consume_def)\n            with \\<phi> step rs have ?match proof (cases rule: \\<phi>E)\n              case (Friend uid p uid')\n                then have IDs1: \"IDsOK s1 [UID1, UID2] []\"\n                  using ss1 unfolding eqButUID_def by auto\n                have fv: \"fv = True\" using fv Friend by auto\n                let ?s1' = \"createFriend s1 UID1 (pass s1 UID1) UID2\"\n                have s': \"s' = createFriend s UID1 p UID2\"\n                  using Friend step by (auto simp: createFriend_sym)\n                have ss': \"eqButUID s s'\" using rs step Friend\n                  by (auto intro: Cact_cFriend_step_eqButUID)\n                moreover then have os': \"\\<not>open s'\" using os eqButUID_open_eq by auto\n                moreover obtain al oul where al: \"sstep s1 al = (oul, ?s1')\" \"al \\<noteq> []\"\n                                         and tr1: \"O (traceOf s1 al) = []\"\n                                                  \"V (traceOf s1 al) = [FrVal True]\"\n                                         and f12s1': \"friends12 ?s1'\"\n                                         and s1s1': \"eqButUID s1 ?s1'\"\n                  using rs1 IDs1 Friend f12s1 unfolding fv by (auto elim: toggle_friends12_True)\n                moreover have \"friendIDs s' = friendIDs ?s1'\"\n                  using Friend(6) f12s1 unfolding s' fv\n                  by (intro eqButUID_createFriend12_friendIDs_eq[OF ss1 rs rs1]) auto\n                ultimately have \"\\<Delta>2 s' vl' ?s1' (OVal True # vlr1)\"\n                  using BO ss1 aF1 unfolding vl' vl1 fs1 f12s1 fv\n                  by (intro \\<Delta>2_I[of _ _ _ _ _ \"[]\" \"[]\"])\n                     (auto intro: eqButUID_trans eqButUID_sym)\n                moreover have \"\\<not>\\<gamma> ?trn\" using Friend UID1_UID2_UIDs by auto\n                ultimately show ?match using tr1 vl1 Friend unfolding fs1 fv\n                  by (intro matchI_ms[OF al]) (auto simp: consumeList_def)\n            next\n              case (Unfriend uid p uid')\n                then have IDs1: \"IDsOK s1 [UID1, UID2] []\"\n                  using ss1 unfolding eqButUID_def by auto\n                have fv: \"fv = False\" using fv Unfriend by auto\n                let ?s1' = \"deleteFriend s1 UID1 (pass s1 UID1) UID2\"\n                have s': \"s' = deleteFriend s UID1 p UID2\"\n                  using Unfriend step by (auto simp: deleteFriend_sym)\n                have ss': \"eqButUID s s'\" using rs step Unfriend\n                  by (auto intro: Dact_dFriend_step_eqButUID)\n                moreover then have os': \"\\<not>open s'\" using os eqButUID_open_eq by auto\n                moreover obtain al oul where al: \"sstep s1 al = (oul, ?s1')\" \"al \\<noteq> []\"\n                                         and tr1: \"O (traceOf s1 al) = []\"\n                                                  \"V (traceOf s1 al) = [FrVal False]\"\n                                         and f12s1': \"\\<not>friends12 ?s1'\"\n                                         and s1s1': \"eqButUID s1 ?s1'\"\n                  using rs1 IDs1 Unfriend f12s1 unfolding fv by (auto elim: toggle_friends12_False)\n                moreover have \"friendIDs s' = friendIDs ?s1'\"\n                  using Unfriend(6) f12s1 unfolding s' fv\n                  by (intro eqButUID_deleteFriend12_friendIDs_eq[OF ss1 rs rs1])\n                ultimately have \"\\<Delta>2 s' vl' ?s1' (OVal True # vlr1)\"\n                  using BO ss1 aF1 unfolding vl' vl1 fs1 f12s1 fv\n                  by (intro \\<Delta>2_I[of _ _ _ _ _ \"[]\" \"[]\"])\n                     (auto intro: eqButUID_trans eqButUID_sym)\n                moreover have \"\\<not>\\<gamma> ?trn\" using Unfriend UID1_UID2_UIDs by auto\n                ultimately show ?match using tr1 vl1 Unfriend unfolding fs1 fv\n                  by (intro matchI_ms[OF al]) (auto simp: consumeList_def)\n            qed auto\n            then show ?thesis ..\n          qed\n        qed\n      next\n        assume n\\<phi>: \"\\<not>\\<phi> ?trn\"\n        then have os': \"open s = open s'\" and f12s': \"friends12 s = friends12 s'\"\n          using step_open_\\<phi>[OF step] step_friends12_\\<phi>[OF step] by auto\n        have vl': \"vl' = vl\" using n\\<phi> c by (auto simp: consume_def)\n        show ?thesis proof (cases \"a \\<noteq> Cact (cFriend UID1 (pass s UID1) UID2) \\<and>\n                                   a \\<noteq> Cact (cFriend UID2 (pass s UID2) UID1) \\<and>\n                                   a \\<noteq> Dact (dFriend UID1 (pass s UID1) UID2) \\<and>\n                                   a \\<noteq> Dact (dFriend UID2 (pass s UID2) UID1)\")\n          case True\n            obtain ou1 s1' where step1: \"step s1 a = (ou1, s1')\" by (cases \"step s1 a\") auto\n            let ?trn1 = \"Trans s1 a ou1 s1'\"\n            from True n\\<phi> have n\\<phi>': \"\\<not>\\<phi> ?trn1\" using eqButUID_step_\\<phi>[OF ss1 rs rs1 step step1] by auto\n            then have f12s1': \"friends12 s1 = friends12 s1'\"\n              using step_friends12_\\<phi>[OF step1] by auto\n            have \"eqButUID s' s1'\" using eqButUID_step[OF ss1 step step1 rs rs1] .\n            moreover have \"friendIDs s = friendIDs s1 \\<longrightarrow> friendIDs s' = friendIDs s1'\"\n              using eqButUID_step_friendIDs_eq[OF ss1 rs rs1 step step1 True] ..\n            ultimately have \"\\<Delta>2 s' vl' s1' vl1\"\n              using os' os aF1 BO fs_fs1 last_fs fs_fIDs unfolding f12s1' vl' vl vl1\n              by (intro \\<Delta>2_I) auto\n            then have ?match\n              using step1 n\\<phi>' os eqButUID_step_\\<gamma>_out[OF ss1 step step1]\n              by (intro matchI[of s1 a ou1 s1' vl1 vl1]) (auto simp: consume_def)\n            then show \"?match \\<or> ?ignore\" ..\n        next\n          case False\n            with n\\<phi> have \"ou \\<noteq> outOK\" by auto\n            then have \"s' = s\" using step False by auto\n            then have ?ignore using 2 False UID1_UID2_UIDs unfolding vl' by (intro ignoreI) auto\n            then show \"?match \\<or> ?ignore\" ..\n        qed\n      qed\n    qed\n    then show ?thesis unfolding vl by auto\n  qed\nqed\n\n\ndefinition Gr where\n\"Gr =\n {\n (\\<Delta>0, {\\<Delta>0,\\<Delta>1,\\<Delta>2}),\n (\\<Delta>1, {\\<Delta>1,\\<Delta>0}),\n (\\<Delta>2, {\\<Delta>2,\\<Delta>0})\n }\"\n\n\ntheorem secure: secure\napply (rule unwind_decomp_secure_graph[of Gr \\<Delta>0])\nunfolding Gr_def\napply (simp, smt insert_subset order_refl)\nusing\nistate_\\<Delta>0 unwind_cont_\\<Delta>0 unwind_cont_\\<Delta>1 unwind_cont_\\<Delta>2\nunfolding Gr_def by (auto intro: unwind_cont_mono)\n\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/CoSMed/Friend_Confidentiality/Friend.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.399811640739795, "lm_q1q2_score": 0.25899726838774856}}
{"text": "(*  Title:      HOL/Hoare/HeapSyntaxAbort.thy\n    Author:     Tobias Nipkow\n    Copyright   2002 TUM\n*)\n\ntheory HeapSyntaxAbort imports Hoare_Logic_Abort Heap begin\n\nsubsection \"Field access and update\"\n\ntext{* Heap update @{text\"p^.h := e\"} is now guarded against @{term p}\nbeing Null. However, @{term p} may still be illegal,\ne.g. uninitialized or dangling. To guard against that, one needs a\nmore detailed model of the heap where allocated and free addresses are\ndistinguished, e.g. by making the heap a map, or by carrying the set\nof free addresses around. This is needed anyway as soon as we want to\nreason about storage allocation/deallocation. *}\n\nsyntax\n  \"_refupdate\" :: \"('a \\<Rightarrow> 'b) \\<Rightarrow> 'a ref \\<Rightarrow> 'b \\<Rightarrow> ('a \\<Rightarrow> 'b)\"\n   (\"_/'((_ \\<rightarrow> _)')\" [1000,0] 900)\n  \"_fassign\"  :: \"'a ref => id => 'v => 's com\"\n   (\"(2_^._ :=/ _)\" [70,1000,65] 61)\n  \"_faccess\"  :: \"'a ref => ('a ref \\<Rightarrow> 'v) => 'v\"\n   (\"_^._\" [65,1000] 65)\ntranslations\n  \"_refupdate f r v\" == \"f(CONST addr r := v)\"\n  \"p^.f := e\" => \"(p \\<noteq> CONST Null) \\<rightarrow> (f := _refupdate f p e)\"\n  \"p^.f\" => \"f(CONST addr p)\"\n\n\ndeclare fun_upd_apply[simp del] fun_upd_same[simp] fun_upd_other[simp]\n\n\ntext \"An example due to Suzuki:\"\n\nlemma \"VARS v n\n  {w = Ref w0 & x = Ref x0 & y = Ref y0 & z = Ref z0 &\n   distinct[w0,x0,y0,z0]}\n  w^.v := (1::int); w^.n := x;\n  x^.v := 2; x^.n := y;\n  y^.v := 3; y^.n := z;\n  z^.v := 4; x^.n := z\n  {w^.n^.n^.v = 4}\"\nby vcg_simp\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/Hoare/HeapSyntaxAbort.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5813030906443134, "lm_q2_score": 0.44552953503957266, "lm_q1q2_score": 0.2589876956918275}}
{"text": "(*\n# Licensed to the Apache Software Foundation (ASF) under one\n# or more contributor license agreements.  See the NOTICE file\n# distributed with this work for additional information\n# regarding copyright ownership.  The ASF licenses this file\n# to you under the Apache License, Version 2.0 (the\n# \"License\"); you may not use this file except in compliance\n# with the License.  You may obtain a copy of the License at\n#\n#   http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing,\n# software distributed under the License is distributed on an\n# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n# KIND, either express or implied.  See the License for the\n# specific language governing permissions and limitations\n# under the License.\n*)\n\ntheory TrustLevel\n  imports Main\nbegin\n\nlocale TrustLevel=\n  fixes trusted::'trustlevel\n    and untrusted::'trustlevel\n    and is_trusted::\"'trustlevel\\<Rightarrow>bool\"\n  assumes TRUSTLEVELHLR1:\"is_trusted trusted\"\n  assumes TRUSTLEVELHLR2:\"\\<not>is_trusted untrusted\"\n  assumes TRUSTLEVELHLR3:\"(x::'trustlevel)=trusted\\<or>x=untrusted\"\nbegin\n\nlemma TRUSTLEVELHLR4:\"trusted\\<noteq>untrusted\"\nproof\n  assume 0:\"trusted=untrusted\"\n  from TRUSTLEVELHLR1 have \"is_trusted untrusted\" by (auto simp: 0)\n  from this show \"False\" by (auto simp: TRUSTLEVELHLR2)\nqed\n\nend\n\nprint_locale! TrustLevel\n\nend\n", "meta": {"author": "apache", "repo": "incubator-teaclave-verification", "sha": "566a295590a4d9040a2e330a35f832673aa93365", "save_path": "github-repos/isabelle/apache-incubator-teaclave-verification", "path": "github-repos/isabelle/apache-incubator-teaclave-verification/incubator-teaclave-verification-566a295590a4d9040a2e330a35f832673aa93365/access_control_module/TrustLevel.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.2589699453660218}}
{"text": "(*  Title:      HOL/IMPP/Misc.thy\n    Author:     David von Oheimb, TUM\n*)\n\nsection \\<open>Several examples for Hoare logic\\<close>\n\ntheory Misc\nimports Hoare\nbegin\n\noverloading\n  newlocs \\<equiv> newlocs\n  setlocs \\<equiv> setlocs\n  getlocs \\<equiv> getlocs\n  update \\<equiv> update\nbegin\n\ndefinition newlocs :: locals\n  where \"newlocs == %x. undefined\"\n\ndefinition setlocs :: \"state => locals => state\"\n  where \"setlocs s l' == case s of st g l => st g l'\"\n\ndefinition getlocs :: \"state => locals\"\n  where \"getlocs s == case s of st g l => l\"\n\ndefinition update  :: \"state => vname => val => state\"\n  where \"update s vn v ==\n    case vn of\n      Glb gn => (case s of st g l => st (g(gn:=v)) l)\n    | Loc ln => (case s of st g l => st g (l(ln:=v)))\"\n\nend\n\n\nsubsection \"state access\"\n\nlemma getlocs_def2: \"getlocs (st g l) = l\"\napply (unfold getlocs_def)\napply simp\ndone\n\nlemma update_Loc_idem2 [simp]: \"s[Loc Y::=s<Y>] = s\"\napply (unfold update_def)\napply (induct_tac s)\napply (simp add: getlocs_def2)\ndone\n\nlemma update_overwrt [simp]: \"s[X::=x][X::=y] = s[X::=y]\"\napply (unfold update_def)\napply (induct_tac X)\napply  auto\napply  (induct_tac [!] s)\napply  auto\ndone\n\nlemma getlocs_Loc_update [simp]: \"(s[Loc Y::=k])<Y'> = (if Y=Y' then k else s<Y'>)\"\napply (unfold update_def)\napply (induct_tac s)\napply (simp add: getlocs_def2)\ndone\n\nlemma getlocs_Glb_update [simp]: \"getlocs (s[Glb Y::=k]) = getlocs s\"\napply (unfold update_def)\napply (induct_tac s)\napply (simp add: getlocs_def2)\ndone\n\nlemma getlocs_setlocs [simp]: \"getlocs (setlocs s l) = l\"\napply (unfold setlocs_def)\napply (induct_tac s)\napply auto\napply (simp add: getlocs_def2)\ndone\n\nlemma getlocs_setlocs_lemma: \"getlocs (setlocs s (getlocs s')[Y::=k]) = getlocs (s'[Y::=k])\"\napply (induct_tac Y)\napply (rule_tac [2] ext)\napply auto\ndone\n\n(*unused*)\nlemma classic_Local_valid: \n\"\\<forall>v. G|={%Z s. P Z (s[Loc Y::=v]) & s<Y> = a (s[Loc Y::=v])}.  \n  c .{%Z s. Q Z (s[Loc Y::=v])} ==> G|={P}. LOCAL Y:=a IN c .{Q}\"\napply (unfold hoare_valids_def)\napply (simp (no_asm_use) add: triple_valid_def2)\napply clarsimp\napply (drule_tac x = \"s<Y>\" in spec)\napply (tactic \"smp_tac \\<^context> 1 1\")\napply (drule spec)\napply (drule_tac x = \"s[Loc Y::=a s]\" in spec)\napply (simp (no_asm_use))\napply (erule (1) notE impE)\napply (tactic \"smp_tac \\<^context> 1 1\")\napply simp\ndone\n\nlemma classic_Local: \"\\<forall>v. G|-{%Z s. P Z (s[Loc Y::=v]) & s<Y> = a (s[Loc Y::=v])}.  \n  c .{%Z s. Q Z (s[Loc Y::=v])} ==> G|-{P}. LOCAL Y:=a IN c .{Q}\"\napply (rule export_s)\napply (rule hoare_derivs.Local [THEN conseq1])\napply (erule spec)\napply force\ndone\n\nlemma classic_Local_indep: \"[| Y~=Y'; G|-{P}. c .{%Z s. s<Y'> = d} |] ==>  \n  G|-{%Z s. P Z (s[Loc Y::=a s])}. LOCAL Y:=a IN c .{%Z s. s<Y'> = d}\"\napply (rule classic_Local)\napply clarsimp\napply (erule conseq12)\napply clarsimp\napply (drule sym)\napply simp\ndone\n\nlemma Local_indep: \"[| Y~=Y'; G|-{P}. c .{%Z s. s<Y'> = d} |] ==>  \n  G|-{%Z s. P Z (s[Loc Y::=a s])}. LOCAL Y:=a IN c .{%Z s. s<Y'> = d}\"\napply (rule export_s)\napply (rule hoare_derivs.Local)\napply clarsimp\ndone\n\nlemma weak_Local_indep: \"[| Y'~=Y; G|-{P}. c .{%Z s. s<Y'> = d} |] ==>  \n  G|-{%Z s. P Z (s[Loc Y::=a s])}. LOCAL Y:=a IN c .{%Z s. s<Y'> = d}\"\napply (rule weak_Local)\napply auto\ndone\n\n\nlemma export_Local_invariant: \"G|-{%Z s. Z = s<Y>}. LOCAL Y:=a IN c .{%Z s. Z = s<Y>}\"\napply (rule export_s)\napply (rule_tac P' = \"%Z s. s'=s & True\" and Q' = \"%Z s. s'<Y> = s<Y>\" in conseq12)\nprefer 2\napply  clarsimp\napply (rule hoare_derivs.Local)\napply clarsimp\napply (rule trueI)\ndone\n\nlemma classic_Local_invariant: \"G|-{%Z s. Z = s<Y>}. LOCAL Y:=a IN c .{%Z s. Z = s<Y>}\"\napply (rule classic_Local)\napply clarsimp\napply (rule trueI [THEN conseq12])\napply clarsimp\ndone\n\nlemma Call_invariant: \"G|-{P}. BODY pn .{%Z s. Q Z (setlocs s (getlocs s')[X::=s<Res>])} ==>  \n  G|-{%Z s. s'=s & I Z (getlocs (s[X::=k Z])) & P Z (setlocs s newlocs[Loc Arg::=a s])}.  \n  X:=CALL pn (a) .{%Z s. I Z (getlocs (s[X::=k Z])) & Q Z s}\"\napply (rule_tac s'1 = \"s'\" and\n  Q' = \"%Z s. I Z (getlocs (s[X::=k Z])) = I Z (getlocs (s'[X::=k Z])) & Q Z s\" in\n  hoare_derivs.Call [THEN conseq12])\napply  (simp (no_asm_simp) add: getlocs_setlocs_lemma)\napply force\ndone\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/IMPP/Misc.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.2589699453660218}}
{"text": "theory Kruskal_Impl\n  imports Kruskal_Refine \"SeprefTime.IICF_DArray_List\"\n        Union_Find_Disjoint_Sets\nbegin\n\ncontext\n  fixes t ::  \"nat \\<Rightarrow> nat\"\nbegin\n  definition mop_sortEdges   where\n    \"mop_sortEdges l = (SPECT (emb (\\<lambda>(L,n). n= Max (insert 0 (set (map fst L) \\<union> set (map (snd o snd) L))) \\<and> sorted_wrt edges_less_eq L \\<and> distinct L \\<and> set L = set l) (enat (t (length l)))))\"\n  \n    sepref_register \"mop_sortEdges\"  \nend\n\nlocale sortMaxnode = \n  fixes sortEdges_impl :: \"(nat \\<times> int \\<times> nat) list \\<Rightarrow> ((nat \\<times> int \\<times> nat) list * nat) Heap\" \n    and sort_time' :: \"nat \\<Rightarrow> nat\"\n  assumes   \n      sortEdges_impl[sepref_fr_rules]: \"\\<And>t. (sortEdges_impl, PR_CONST (mop_sortEdges t)) \\<in>\n        [\\<lambda>l. sort_time' (length l) \\<le> t (length l)]\\<^sub>a\n      (list_assn (nat_assn \\<times>\\<^sub>a int_assn \\<times>\\<^sub>a nat_assn))\\<^sup>k \\<rightarrow> (list_assn (nat_assn \\<times>\\<^sub>a int_assn \\<times>\\<^sub>a nat_assn)\\<times>\\<^sub>a nat_assn)\"\n\n\n\n \n\n  \nlemma set_uprod_nonempty[simp]: \"set_uprod x \\<noteq> {}\"\n  apply(cases x) by auto\n\n\nlocale Kruskal_intermediate_Impl0 = Kruskal_intermediate E forest connected path weight for E forest connected path \n      and weight :: \"nat uprod \\<Rightarrow> int\"  +\n    fixes getEdges  :: \"(nat \\<times> int \\<times> nat) list nrest\"\n      and getEdges_impl :: \"(nat \\<times> int \\<times> nat) list Heap\" \n      and getEdges_time sort_time :: nat\n(*      and sortEdges  :: \"(nat \\<times> int \\<times> nat) list \\<Rightarrow> ((nat \\<times> int \\<times> nat) list * nat) nrest\"\n      and sortEdges_impl :: \"(nat \\<times> int \\<times> nat) list \\<Rightarrow> ((nat \\<times> int \\<times> nat) list * nat) Heap\" *)\n      and empty_uf_time indep_test_time insert_uf_time :: nat\n    assumes           \n        E_nonempty: \"E\\<noteq>{}\"\n      and  \n        getEdges_refine: \"getEdges \\<le> \\<Down> Id (SPECT (emb (\\<lambda>L. lst_graph_P' weight L E) (enat getEdges_time)))\"\n      and\n        getEdges_impl[sepref_fr_rules]: \"(uncurry0 getEdges_impl, uncurry0 getEdges) \\<in> unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a list_assn (nat_assn \\<times>\\<^sub>a int_assn \\<times>\\<^sub>a nat_assn)\"\n(*       and\n        sortEdges_refine': \"sortEdges l \\<le> (SPECT (emb (\\<lambda>(L,n). n= Max (set (map fst l) \\<union> set (map (snd o snd) l)) \\<and> sorted_wrt edges_less_eq L \\<and> distinct L \\<and> set L = set l) (enat sort_time)))\"\n     and\n        sortEdges_impl[sepref_fr_rules]: \"(sortEdges_impl, sortEdges) \\<in>\n                (list_assn (nat_assn \\<times>\\<^sub>a int_assn \\<times>\\<^sub>a nat_assn))\\<^sup>k \\<rightarrow>\\<^sub>a (list_assn (nat_assn \\<times>\\<^sub>a int_assn \\<times>\\<^sub>a nat_assn)\\<times>\\<^sub>a nat_assn)\"\n     \n*)\n                                                   \nbegin\n\nthm conc_fun_br\n\nabbreviation \"sortEdges \\<equiv> mop_sortEdges (\\<lambda>_. sort_time)\"\n\n\n(*\nlemma sortEdges_refine: \n  assumes a: \"V = set (map fst l) \\<union> set (map (snd o snd) l)\"\n    shows \"sortEdges l = \\<Down> (br fst (\\<lambda>(l,n). n= Max V)) (SPECT (emb (\\<lambda>L. sorted_wrt edges_less_eq L \\<and> distinct L \\<and> set L = set l) (enat sort_time)))\"\nproof -\n  have gg: \"(\\<lambda>x. (case x of (l, n) \\<Rightarrow> n = Max V) \\<and> sorted_wrt edges_less_eq (fst x) \\<and> distinct (fst x) \\<and> set (fst x) = set l)\n        =(\\<lambda>(L, n). n = Max (set (map fst l) \\<union> set (map (snd o snd) l)) \\<and> sorted_wrt edges_less_eq L \\<and> distinct L \\<and> set L = set l)\"\n    unfolding a by auto\n  show ?thesis \n    apply(simp only: conc_fun_br gg) by(rule sortEdges_refine')\nqed *)\n\nabbreviation \"insert_time \\<equiv> 23\"\nabbreviation \"empty_forest_time \\<equiv> 12\"\n\n\nsublocale Kruskal_intermediate_time  E forest connected  path weight\n        empty_forest_time empty_uf_time indep_test_time insert_time insert_uf_time getEdges_time sort_time\n  apply unfold_locales .\n\n\n\nterm obtain_sorted_carrier''\n       \ndefinition (in -) obtain_sorted_carrier'''_aux  where\n  \"obtain_sorted_carrier'''_aux gE sE c =\n      do {\n    l \\<leftarrow> gE;\n    ASSERT (length l = card c);\n    sE l\n}\" \n\nabbreviation \"obtain_sorted_carrier''' \\<equiv> obtain_sorted_carrier'''_aux getEdges sortEdges E\"\n \nlemma distinct_mset_eq:\"distinct a \\<Longrightarrow> mset a = mset b \\<Longrightarrow> distinct b\"\n  by (metis card_distinct distinct_card set_mset_mset size_mset)\n\nlemma quicksort_by_rel_distinct: \"distinct l \\<Longrightarrow> distinct (quicksort_by_rel edges_less_eq [] l)\"\n  by (auto intro: distinct_mset_eq)\n\ndefinition \"add_size_rel   = br fst (\\<lambda>(l,n). n= Max V)\"\n\n\n\nlemma max_node_is_Max_V: \" E = (\\<lambda>(a, _, y). Upair a y) ` set la \\<Longrightarrow> max_node la = Max V\"\nproof -\n  assume E: \"E = (\\<lambda>(a, _, y). Upair a y) ` set la\"\n  have pff: \"fst ` set la \\<union>  (\\<lambda>x. snd (snd x)) ` set la = (\\<Union>x\\<in>set la. case x of (x1, x1a, x2a) \\<Rightarrow> {x1, x2a})\"\n    by (auto simp add: rev_image_eqI)  \n  have \"V \\<noteq> {}\" using E_nonempty V_def by auto\n  then have Mo: \"Max V = Max (insert 0 V)\" by auto \n  show ?thesis unfolding Mo unfolding V_def\n  unfolding E apply simp \n  by (auto simp add:  max_node_def prod.case_distrib pff ) \nqed\n\nlemma lst_graph_P_V: \"lst_graph_P la E \\<Longrightarrow> V = (fst ` set la \\<union> (\\<lambda>x. snd (snd x)) ` set la)\" \n  by (auto simp: emb_eq_Some_conv lst_graph_P_def V_def rev_image_eqI) \n\n \n\nlemma  k: \"\\<And>V::nat set. finite V \\<Longrightarrow> V \\<noteq> {} \\<Longrightarrow> Max V = Max (insert 0 V)\" by auto\n\nlemma *: \"(la::((nat*int*nat) list)) \\<noteq> [] \\<Longrightarrow> Max (insert 0 (fst ` set la \\<union> (\\<lambda>x. snd (snd x)) ` set la)) = Max (fst ` set la \\<union> (\\<lambda>x. snd (snd x)) ` set la)\"\nproof -\n  assume \"la \\<noteq> []\"\n  then have \"fst ` set la \\<union> (snd \\<circ> snd) ` set la \\<noteq> {}\" by auto\n  then show ?thesis apply(intro k[symmetric])  apply simp by simp\nqed\n\n\nlemma obtain_sorted_carrier'''_refine: \"obtain_sorted_carrier''' \\<le> \\<Down>add_size_rel obtain_sorted_carrier''\"\n  unfolding obtain_sorted_carrier'''_aux_def  add_size_rel_def\n  apply(rule bindT_refine')      \n   apply(rule getEdges_refine) apply safe\n  apply(auto simp: emb_eq_Some_conv  dest!:  split: if_splits)\n  unfolding conc_fun_br  mop_sortEdges_def \n  apply(auto  simp: le_fun_def emb'_def dest: lst_graph_P_V split: if_splits)\n  apply(rule le_R_ASSERTI)\n  apply(rule ASSERT_leI) apply simp\n  apply(rule SPECT_refine) apply (auto split: if_splits)    \n  apply(subst * ) subgoal apply auto using E_nonempty by auto \n  by (metis (mono_tags) fst_conv in_br_conv lst_graph_P_V prod_case_simp) \n   \n    \n\ndefinition (in -) initState''_aux where\n  \"initState''_aux mn eft eut\\<equiv> do {\n    initial_union_find \\<leftarrow> mop_per_init (\\<lambda>_. eut) (mn + 1);\n    ASSERT ( card (Domain initial_union_find) = mn + 1);\n    e \\<leftarrow> mop_empty_list (\\<lambda>_. eft);\n    RETURNT (initial_union_find, e)      \n    }\" \n\n\nabbreviation \"initState'' mn == initState''_aux mn empty_forest_time empty_uf_time\"\n\n definition (in -) \"addEdge''_aux uf a w b T iut it = do {\n  uf \\<leftarrow> mop_per_union (\\<lambda>_. iut) uf a b;\n  T' \\<leftarrow> mop_push_list (\\<lambda>_.  it) (a,w,b) T;\n  RETURNT (uf, T')\n  }\"\n\nabbreviation \"addEdge'' uf a w b T == addEdge''_aux uf a w b T insert_uf_time insert_time\"\n\ndefinition (in -) \"notcompare uf a b itt = do {\n      i \\<leftarrow> mop_per_compare (\\<lambda>_. itt) uf a b;\n      RETURNT (\\<not>i)\n     }\"\n\n\n definition (in -) kruskal3_aux \n   where \"kruskal3_aux E gE sE eft eut iut it   itt \\<equiv> do {\n    (sl,mn) \\<leftarrow> obtain_sorted_carrier'''_aux gE sE E;\n    ASSERT (mn = Max (Kruskal_intermediate_defs.V E));\n    s \\<leftarrow> initState''_aux mn eft eut ;\n    (per, spanning_forest) \\<leftarrow> nfoldli sl (\\<lambda>_. True)\n        (\\<lambda>(a,w,b) (uf, T). do { \n            ASSERT (a \\<in> Domain uf \\<and> b \\<in> Domain uf);\n            ASSERT ( card (Domain uf) = Max (Kruskal_intermediate_defs.V E) + 1);\n            i \\<leftarrow> notcompare uf a b itt;\n            if i then\n              do { \n                ASSERT ((a,w,b)\\<notin>set T);\n                addEdge''_aux uf a w b T iut it\n              }\n            else \n              RETURNT (uf,T)\n        }) s;\n        RETURNT spanning_forest\n      }\"\n\nabbreviation \"kruskal3 \\<equiv> kruskal3_aux E getEdges sortEdges  empty_forest_time empty_uf_time\n                      insert_uf_time  insert_time  indep_test_time\"\n\n  definition per_supset_rel :: \"('a per \\<times> 'a per) set\" where\n    \"per_supset_rel\n      \\<equiv> {(p1,p2). p1 \\<inter> Domain p2 \\<times> Domain p2 = p2 \\<and> p1 - (Domain p2 \\<times> Domain p2) \\<subseteq> Id}\"\n\n definition \"kk_rel n \\<equiv> per_supset_rel \\<inter> ({p. Domain p = {0..<n}} \\<times> UNIV)\"\n\nlemma kk_relD: \"x\\<in> kk_rel n \\<Longrightarrow> x\\<in>per_supset_rel\" unfolding kk_rel_def by auto\n\n  lemma per_supset_rel_dom: \"(p1, p2) \\<in> per_supset_rel \\<Longrightarrow> Domain p1 \\<supseteq> Domain p2\"\n    by (auto simp: per_supset_rel_def)\n  \n  lemma per_supset_compare:\n    \"(p1, p2) \\<in> per_supset_rel \\<Longrightarrow> x1\\<in>Domain p2 \\<Longrightarrow> x2\\<in>Domain p2 \\<Longrightarrow> per_compare p1 x1 x2 \\<longleftrightarrow> per_compare p2 x1 x2\"\n    by (auto simp: per_supset_rel_def)\n  \n  lemma per_supset_union: \"(p1, p2) \\<in> per_supset_rel \\<Longrightarrow> x1\\<in>Domain p2 \\<Longrightarrow> x2\\<in>Domain p2 \\<Longrightarrow>\n    (per_union p1 x1 x2, per_union p2 x1 x2) \\<in> per_supset_rel\"\n    apply (clarsimp simp: per_supset_rel_def per_union_def Domain_unfold )\n    apply (intro subsetI conjI)\n    apply blast\n    apply force\n    done\n\n  lemma per_kk_rel_union: \n    assumes \"(p1, p2) \\<in> kk_rel n\" and inDom: \"x1\\<in>Domain p2\" \"x2\\<in>Domain p2\"\n    shows \"(per_union p1 x1 x2, per_union p2 x1 x2) \\<in> kk_rel n\"\n  proof -\n    from assms(1) have \"(p1, p2) \\<in> per_supset_rel\" by(auto dest: kk_relD)\n    with inDom have ss: \"(per_union p1 x1 x2, per_union p2 x1 x2) \\<in> per_supset_rel\" \n      by(auto intro: per_supset_union)\n\n    from assms(1) have \"Domain p1 = {0..<n}\" by (auto simp: kk_rel_def)\n    then have \"Domain (per_union p1 x1 x2) = {0..<n}\" by simp\n    with ss show ?thesis unfolding kk_rel_def by auto\n  qed\n\nlemma per_initN_refine: \"(per_init' (Max V + 1), per_init V) \\<in> per_supset_rel\"\n  unfolding per_supset_rel_def per_init'_def per_init_def max_node_def\n  by (auto simp: less_Suc_eq_le  ) \n\nlemma per_init'_refine: \"SPECT [per_init' (Max V  + 1) \\<mapsto> enat empty_uf_time] \\<le> \\<Down> per_supset_rel (SPECT [per_init V \\<mapsto> enat empty_uf_time])\"\n  apply(rule SPECT_refine)   using per_initN_refine by (auto split: if_splits)\n  \nlemma gg: \"{(i, i) |i. i < X} = (\\<lambda>i. (i,i)) ` {i. i < X}\" by auto\n   \n\nlemma ff: \"\\<And>X. card (Domain {(i, i) |i. i < X}) = X\"\n  unfolding Domain_fst apply(subst card_image)\n  subgoal by (smt fst_conv inj_onI mem_Collect_eq) \n  subgoal unfolding gg apply(subst card_image) by auto  \n  done\n\n\nlemma initState''_refine: \"initState'' (Max V) \\<le> \\<Down>(kk_rel (Max V + 1) \\<times>\\<^sub>r Id) initState'\"\n  unfolding initState'_aux_def initState''_aux_def mop_empty_list_def  kk_rel_def\n  unfolding mop_per_init_def\n  apply(rule bindT_refine') apply(rule per_init'_refine)\n\n  apply(refine_rcg  ) \n  subgoal by (auto split: if_splits simp: ff   per_init'_def )   \n  unfolding conc_fun_RES \n    apply(rule T_specifies_I)               \n  apply(vcg' \\<open>-\\<close>  )  \n  apply(rule Sup_upper)  by (auto simp: per_init'_def numeral_eq_enat split: if_splits)  \n\n   \n\nlemma SPECT_bind_RETURNT: \"SPECT [x \\<mapsto> t] \\<bind> (\\<lambda>i. RETURNT (f i)) = SPECT [f x \\<mapsto> t]\"\n  unfolding bindT_def by(auto split: nrest.split)\n\ntheorem kruskal3_refine: \"kruskal3 \\<le> \\<Down> Id kruskal2\"\n  unfolding kruskal2_aux_def kruskal3_aux_def Let_def\n  apply (refine_rcg obtain_sorted_carrier'''_refine   )\n            (*supply RELATESI[where R=\"per_supset_rel::(nat per \\<times> _) set\", refine_dref_RELATES]*)\n            supply RELATESI[where R=\"kk_rel (Max V + 1)::(nat per \\<times> _) set\", refine_dref_RELATES]\n             apply refine_dref_type \n  subgoal unfolding add_size_rel_def by (auto simp: in_br_conv)\n  subgoal apply (simp add: add_size_rel_def in_br_conv  )\n    using initState''_refine  by simp  \n          apply (auto simp add: add_size_rel_def in_br_conv per_supset_compare\n                        per_supset_union \n                      dest: per_supset_rel_dom\n                      simp del: per_compare_def )\n  subgoal by(auto dest!: kk_relD per_supset_rel_dom)    \n  subgoal by(auto dest!: kk_relD per_supset_rel_dom)  \n  subgoal by(auto simp: kk_rel_def) \n  subgoal apply(auto dest!: kk_relD simp: SPECT_bind_RETURNT le_fun_def notcompare_def mop_per_compare_def)\n    by (meson Domain.simps local.per_supset_compare per_compare_def)+  \n  subgoal unfolding addEdge'_aux_def addEdge''_aux_def mop_per_union_def mop_push_list_def\n    apply(refine_rcg)\n     apply refine_dref_type            \n    subgoal apply (rule SPECT_refine) by (auto  split: if_splits intro: per_kk_rel_union)\n    subgoal apply (rule RETURNT_refine) by(auto split: if_splits)   \n    done\n  done\n\nend\n\n\n       \n\nlocale Kruskal_intermediate_Impl = Kruskal_intermediate_Impl0\n  + UnionFind_Impl + sortMaxnode   +\n  assumes \n  [simp]:  \"uf_init_time (Suc (Max V)) \\<le> empty_uf_time\" \n    \"uf_cmp_time (Suc (Max V)) \\<le> indep_test_time\" \n    \"uf_union_time (Suc (Max V)) \\<le> insert_uf_time\" \n    \"sort_time' (card E) \\<le> sort_time\"\nbegin\n\nsection \\<open>Kruskal\\<close>\n\n\n  lemma [fcomp_norm_simps]: \"list_assn (nat_assn \\<times>\\<^sub>a int_assn \\<times>\\<^sub>a nat_assn) = id_assn\"\n    by (auto simp: list_assn_pure_conv)\n  lemma [fcomp_norm_simps]: \" (nat_assn \\<times>\\<^sub>a int_assn \\<times>\\<^sub>a nat_assn) = id_assn\"\n    by (auto simp: )\n\n  lemma [sepref_import_param]: \"(sort_edges,sort_edges)\\<in>\\<langle>Id\\<times>\\<^sub>rId\\<times>\\<^sub>rId\\<rangle>list_rel \\<rightarrow>\\<langle>Id\\<times>\\<^sub>rId\\<times>\\<^sub>rId\\<rangle>list_rel\" by simp\n  lemma [sepref_import_param]: \"(max_node, max_node) \\<in> \\<langle>Id\\<times>\\<^sub>rId\\<times>\\<^sub>rId\\<rangle>list_rel \\<rightarrow> nat_rel\" by simp\n\n  sepref_register \"getEdges\" :: \"(nat \\<times> int \\<times> nat) list nrest\"\n  sepref_register uf_init :: \"nat \\<Rightarrow> uf Heap\"\n  sepref_register uf_cmp :: \"uf \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> bool Heap\"\n  sepref_register uf_union :: \"uf \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> uf Heap\"\n \ndeclare getEdges_impl [sepref_fr_rules]\n\n \n\nsepref_definition kruskal is\n  \"uncurry0 kruskal3\" :: \"(unit_assn)\\<^sup>k \\<rightarrow>\\<^sub>a da_assn (nat_assn \\<times>\\<^sub>a int_assn \\<times>\\<^sub>a nat_assn)\"\n  unfolding kruskal3_aux_def obtain_sorted_carrier'''_aux_def initState''_aux_def\n      addEdge''_aux_def notcompare_def nfoldli_def\n  using [[goals_limit = 2]]\n   \n  apply sepref_dbg_preproc\n  apply sepref_dbg_cons_init\n  apply sepref_dbg_id \n     apply sepref_dbg_monadify\n\n         apply sepref_dbg_opt_init\n\n  apply sepref_dbg_trans \n \n  apply sepref_dbg_opt\n  apply sepref_dbg_cons_solve \\<comment> \\<open>Frame rule, recovering the invalidated list \n    or pure elements, propagating recovery over the list structure\\<close>\n  apply sepref_dbg_cons_solve \\<comment> \\<open>Trivial frame rule\\<close>\n  apply sepref_dbg_constraints\n      done  \n\n\n  concrete_definition (in -) kruskal' \n    uses Kruskal_intermediate_Impl.kruskal_def\n\n\nthm kruskal3_refine kruskal2_refine   kruskal1_refine kruskal0_refine minWeightBasis3_refine\n \nthm kruskal.refine kruskal3_refine kruskal2_refine   kruskal1_refine kruskal0_refine minWeightBasis3_refine\n\n\nabbreviation \"MST == minBasis\"\n\nterm minWeightBasis3\n\n(* TODO: *) \n\nlemma k3: \"(kruskal3,kruskal2) \\<in> \\<langle>Id\\<rangle>nrest_rel\"\n  apply(rule nrest_relI) by (rule kruskal3_refine) \nlemma k2: \"(kruskal2,kruskal1) \\<in> \\<langle>lst_graph_rel\\<rangle>nrest_rel\"\n  apply(rule nrest_relI) by (rule kruskal2_refine) \nlemma k1: \"(kruskal1,kruskal0) \\<in> \\<langle>Id\\<rangle>nrest_rel\"\n  apply(rule nrest_relI) by (rule kruskal1_refine) \nlemma k0: \"(kruskal0,minWeightBasis3) \\<in> \\<langle>Id\\<rangle>nrest_rel\"\n  apply(rule nrest_relI) by (rule kruskal0_refine) \nlemma kmw: \"(minWeightBasis3,SPECT (emb minBasis (enat minBasis_time))) \\<in> \\<langle>Id\\<rangle>nrest_rel\"\n  apply(rule nrest_relI)  \n  by (rule minWeightBasis3_refine)\n\nlemmas k_ref_spec = k3[FCOMP k2, FCOMP k1, FCOMP k0, FCOMP kmw]\n\n\n  lemma [fcomp_norm_simps]: \"list_assn (nat_assn \\<times>\\<^sub>a int_assn \\<times>\\<^sub>a nat_assn) = id_assn\"\n    by (auto simp: list_assn_pure_conv)\nlemmas kruskal_ref_spec = kruskal.refine[FCOMP k_ref_spec]\n\nthm minBasis_time_def\nlemma kruskal_correct_forest:\n  shows \"<$ minBasis_time> kruskal <\\<lambda>r. (\\<exists>\\<^sub>Ara. hr_comp (da_assn id_assn) lst_graph_rel ra r * \\<up> (MST ra))>\\<^sub>t\"\nproof -\n  thm extract_cost_ub \n  note l= hn_refine_ref[OF _  kruskal_ref_spec[to_hnr] ]\n  thm extract_cost_ub[OF l, where Cost_ub=\"minBasis_time\", simplified in_ran_emb_special_case]\n  have ht: \"<emp * $ minBasis_time> kruskal <\\<lambda>r. emp * (\\<exists>\\<^sub>Ara. hr_comp (da_assn id_assn) lst_graph_rel ra r * \\<up> (ra \\<in> dom ((emb MST (enat minBasis_time)))))>\\<^sub>t\"\n    apply(rule extract_cost_ub[OF l, where Cost_ub=\"minBasis_time\" ])\n    by (auto simp: in_ran_emb_special_case)  \n\n  from ht show ?thesis by auto        \nqed\nthm minBasis_time_def \nend\n(*\nthm extract_cost_ub[where M= \"(emb Pr t)\", no_vars]\n\nlemma \"hn_refine \\<Gamma> c \\<Gamma>' R (SPECT (emb Pr t))  \\<Longrightarrow>\n<\\<Gamma> * $ t> c <\\<lambda>r. \\<Gamma>' * (\\<exists>\\<^sub>Ara. R ra r * \\<up> (Pr ra))>\\<^sub>t\"\nproof -\n  assume \"hn_refine \\<Gamma> c \\<Gamma>' R (SPECT (emb Pr t))\"\n  from extract_cost_ub[OF this, of t]\n  show ?thesis by (simp add: ran_emb')\nqed\n \n\nlemma array_length_rule_raw [hoare_triple]:\n  \"<dyn_array_raw (xs, n) p * $1>\n   array_length p\n   <\\<lambda>r. dyn_array_raw (xs, n) p * \\<up>(r = n)>\"\n  unfolding dyn_array'_def array_length_def \n  apply(cases p)\n  by (sep_auto simp: zero_time)  \n \n\nlemma array_max_rule_raw [hoare_triple]:\n  \"<dyn_array_raw (xs, n) p * $1>\n   array_max p\n   <\\<lambda>r. dyn_array_raw (xs, n) p * \\<up>(r = length xs)>\"\n  unfolding array_max_def \n  apply (cases p)\n  by (sep_auto heap: length_rule simp: zero_time)  \n\n\nlemma double_length_raw_rule2 [hoare_triple]:\n  \"length xs = n \\<Longrightarrow>\n   <dyn_array_raw (xs, length xs) p * $(length xs * 5 + 5)>\n   double_length p\n   <dyn_array_raw (double_length_fun (xs, n))>\\<^sub>t\" \n  using double_length_raw_rule[of xs n p] by(simp add: mult.commute) \n\nlemma push_array_raw_rule [hoare_triple]:\n  \"n \\<le> length xs \\<Longrightarrow>\n   <dyn_array_raw (xs, n) p * $( length xs *5+9)>\n   push_array x p\n   <dyn_array_raw (push_array_fun x (xs, n))>\\<^sub>t\" \n  unfolding  \n    push_array_def  \n  apply(sep_auto heap: array_max_rule_raw push_array_basic_raw_rule\n          array_length_rule_raw  double_length_raw_rule2)\n  subgoal apply(subst array_copy_length) by simp_all\n  by sep_auto\n\nlemma push_array_rule''' [hoare_triple]:\n  \"n \\<le> length xs \\<Longrightarrow>\n   <dyn_array' (xs, n) p * $19>\n   push_array x p\n   <dyn_array' (push_array_fun x (xs, n))>\\<^sub>t\" \n  unfolding  \n    push_array_def\n  apply(sep_auto heap: array_max_rule' array_length_rule' push_array_basic_rule')\n   apply(sep_auto heap: double_length_rule' )\n  using push_array_basic_rule'\n  unfolding double_length_fun.simps\n  apply(sep_auto simp only: heap: push_array_basic_rule')\n  subgoal apply(subst array_copy_length) by simp_all\n  by sep_auto\n   \nthm array_max_rule'\n\n*)\nend", "meta": {"author": "adrilow", "repo": "Proof-of-the-amortized-time-complexity-of-the-Union-Find-data-structure-in-Isabelle-HOL", "sha": "293b12752261dac7f741483b62b27891bf4be1cc", "save_path": "github-repos/isabelle/adrilow-Proof-of-the-amortized-time-complexity-of-the-Union-Find-data-structure-in-Isabelle-HOL", "path": "github-repos/isabelle/adrilow-Proof-of-the-amortized-time-complexity-of-the-Union-Find-data-structure-in-Isabelle-HOL/Proof-of-the-amortized-time-complexity-of-the-Union-Find-data-structure-in-Isabelle-HOL-293b12752261dac7f741483b62b27891bf4be1cc/Kruskal_Impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.538983220687684, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.25896994536602175}}
{"text": "(* Title: RTS/JVM_RTS/JVMSemantics.thy *)\n(* Author: Susannah Mansky, UIUC 2020 *)\n\nsection \"Instantiating @{term Semantics} with Jinja JVM\"\n\ntheory JVMSemantics\nimports \"../Common/Semantics\" JinjaDCI.JVMExec\nbegin\n\nfun JVMsmall :: \"jvm_prog \\<Rightarrow> jvm_state \\<Rightarrow> jvm_state set\" where\n\"JVMsmall P \\<sigma> = { \\<sigma>'. exec (P, \\<sigma>) = Some \\<sigma>' }\"\n\nlemma JVMsmall_prealloc_pres:\nassumes pre: \"preallocated (fst(snd \\<sigma>))\"\n  and \"\\<sigma>' \\<in> JVMsmall P \\<sigma>\"\nshows \"preallocated (fst(snd \\<sigma>'))\"\nusing exec_prealloc_pres[OF pre] assms by(cases \\<sigma>, cases \\<sigma>', auto)\n\nlemma JVMsmall_det: \"JVMsmall P \\<sigma> = {} \\<or> (\\<exists>\\<sigma>'. JVMsmall P \\<sigma> = {\\<sigma>'})\"\nby auto\n\ndefinition JVMendset :: \"jvm_state set\" where\n\"JVMendset \\<equiv> { (xp,h,frs,sh). frs = [] \\<or> (\\<exists>x. xp = Some x) }\"\n\nlemma JVMendset_final: \"\\<sigma> \\<in> JVMendset \\<Longrightarrow> \\<forall>P. JVMsmall P \\<sigma> = {}\"\n by(auto simp: JVMendset_def)\n\nlemma start_state_nend:\n \"start_state P \\<notin> JVMendset\"\n by(simp add: start_state_def JVMendset_def)\n\ninterpretation JVMSemantics: Semantics JVMsmall JVMendset\n by unfold_locales (auto dest: JVMendset_final)\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Regression_Test_Selection/JVM_RTS/JVMSemantics.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297746074044134, "lm_q2_score": 0.41111086923216805, "lm_q1q2_score": 0.2589071862703758}}
{"text": "theory flash83Rev imports flashPub\nbegin\nsection{*Main defintions*}\nlemma NI_FAckVsInv83:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv83 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_InvVsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1VsInv83:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1_HomeVsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_2VsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_GetXVsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_Nak1VsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_Nak2VsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_Nak3VsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_PutX1VsInv83:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv83:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv83:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv83:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv83:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv83:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv83:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv83:  \n  (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv83:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv83:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX10VsInv83:  \n  (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX10_homeVsInv83:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX11VsInv83:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_Get_GetVsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Nak1VsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Nak2VsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Nak3VsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Put1VsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Put2VsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Put3VsInv83:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_PutVsInv83:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n     have allCases:\"formEval  ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true ))  s  \\<or>formEval   (neg ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true )) )  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume b1:\"formEval ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true ))  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n\n    moreover\n                       {assume b1:\"formEval  (neg ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true )) )  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_PutXAcksDoneVsInv83:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv83 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P3 s\"\n\n         \n        apply(    simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma NI_NakVsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Nak_ClearVsInv83:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv83 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_Nak_HomeVsInv83:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv83 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_Remote_GetX_NakVsInv83:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_Nak_HomeVsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_PutXVsInv83:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_PutX_HomeVsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Nak1VsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Nak2VsInv83:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Put1VsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Put2VsInv83:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_PutVsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_PutXVsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceVsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceHomeVsInv83:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv83 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_ReplaceHomeShrVldVsInv83:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv83 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_ReplaceShrVldVsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ShWbVsInv83:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv83 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P3 s\"\n\n         \n        apply(    simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' Home) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''ShWbMsg_Cmd'') )  ( Const SHWB_ShWb ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma NI_WbVsInv83:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv83 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P3 s\"\n\n         \n        apply(    simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''WbMsg_Cmd'') )  ( Const WB_Wb ))    ( eqn ( IVar ( Para ''CacheState'' Home) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_GetX1VsInv83:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv83 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_GetX_GetX2VsInv83:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv83 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_GetX_PutX1VsInv83:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv83 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX2VsInv83:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv83 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX3VsInv83:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv83 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX4VsInv83:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv83 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_Get_GetVsInv83:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv83 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_Get_PutVsInv83:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv83 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n     have allCases:\"formEval  ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true ))  s  \\<or>formEval   (neg ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true )) )  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume b1:\"formEval ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true ))  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n\n    moreover\n                       {assume b1:\"formEval  (neg ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true )) )  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Local_PutXVsInv83:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv83 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_ReplaceVsInv83:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv83 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Remote_GetVsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_GetXVsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_PutXVsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_ReplaceVsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma StoreVsInv83:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv83 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma StoreHomeVsInv83:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv83 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash83Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5964331462646254, "lm_q2_score": 0.4339814648038985, "lm_q1q2_score": 0.25884093047351997}}
{"text": "subsection \\<open>RightShiftNode Phase\\<close>\n\ntheory RightShiftPhase\n  imports\n    Common\n    Proofs.StampEvalThms\nbegin\n\nphase RightShiftNode\n  terminating size\nbegin\n\n(* Value level proofs *)\n(* Has counter-example if x not 32-bit *)\nlemma val_ReturnXOnZeroShift:\n  assumes \"val[x >> (IntVal 32 0)] \\<noteq> UndefVal\"\n  and     \"x = IntVal 32 xv\"\n  shows \"val[x >> (IntVal 32 0)] = x\"  \n  using assms apply (cases x; auto)\n  sorry\n\n(* Exp level proofs *)\nlemma exp_ReturnXOnZeroShift:\n  assumes \"stamp_expr x = IntegerStamp 32 lo hi\"\n  and     \"wf_stamp x\"\nshows \"exp[x >> const(IntVal 32 0)] \\<ge> exp[x]\" \n  apply auto\n  subgoal premises p for m p xa\n  proof - \n    obtain xa where xa: \"[m,p] \\<turnstile> x \\<mapsto> xa\"\n      using p(1) by auto\n    then have 1: \"intval_right_shift xa (IntVal 32 0) \\<noteq> UndefVal\"\n      using evalDet p(1) p(2) by blast\n    then have 2: \"wf_value (IntVal 32 0)\"\n      using p(3) by auto\n    then have equals: \"xa = val[xa >> (IntVal 32 0)]\"\n      using val_ReturnXOnZeroShift apply (cases xa; auto) \n      sorry\n    then have 3: \"[m,p] \\<turnstile> x \\<mapsto> intval_right_shift xa (IntVal (32::nat) (0::64 word))\"\n      by (simp add: xa)\n    then show ?thesis\n      using evalDet p(1) xa by blast\n  qed\n  done\n\ntext \\<open>Optimisations\\<close>\n(* Need to prove exp_ReturnXOnZeroShift *)\noptimization ReturnXOnZeroShift: \"(x >> const(new_int 32 0)) \\<longmapsto> x when \n                                  ((stamp_expr x = IntegerStamp 32 lo hi) \\<and> (wf_stamp x))\"\n   using exp_ReturnXOnZeroShift by fastforce\n\nend (* End of RightShiftNode *)\n\nend (* End of file *)", "meta": {"author": "uqcyber", "repo": "veriopt-releases", "sha": "4ffab3c91bbd699772889dbf263bb6d2582256d7", "save_path": "github-repos/isabelle/uqcyber-veriopt-releases", "path": "github-repos/isabelle/uqcyber-veriopt-releases/veriopt-releases-4ffab3c91bbd699772889dbf263bb6d2582256d7/Optimizations/Canonicalizations/RightShiftPhase.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185351961013, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.25874785484305357}}
{"text": "theory inEvenData\n\nimports bundle.SB\n  begin\n\ntypedef inEven=\"{cin}\"\n  by auto\n\n\ninstantiation inEven::\"{somechan,finite}\"\nbegin\ndefinition \"Rep = Rep_inEven\"\ninstance\n  apply(standard)\n  apply(auto simp add: Rep_inEven_def cEmpty_def)\n  apply(auto simp add: ctype_empty_iff)\n  using ctype_empty_iff\n  apply (metis Rep_inEven cMsg.simps ex_in_conv insertE insert_iff)\n  apply (meson Rep_inEven_inject injI) using cMsg.elims Rep_inEven apply simp\n  using type_definition.Abs_image type_definition_inEven typedef_finite_UNIV by fastforce\nend\n\ndefinition \"Evenin \\<equiv> Abs_inEven cin\"\n\nfree_constructors inEven for \"Evenin\"\n  by (metis(full_types) Abs_inEven_cases singletonD)\n\nlemma Andin1_rep [simp]: \"Rep (Evenin) = cin\"\n  using Rep_inEven Rep_inEven_def by auto\n\nfun inEvenChan::\"('bool::type \\<Rightarrow> 'a::type) \\<Rightarrow> 'bool \\<Rightarrow> inEven \\<Rightarrow> 'a\" where\n\"inEvenChan Cc1 bool Evenin = Cc1 bool\"\n\nabbreviation \"buildEveninSBE \\<equiv> inEvenChan (Untimed o \\<N>)\" \n\nlemma buildevenin_ctype: \"buildEveninSBE a c \\<in> ctype (Rep c)\"\n  sorry\n\nlemma buildevenin_inj: \"inj buildEveninSBE\"\n  sorry\n\nlemma buildevenin_range: \"range (\\<lambda>a. buildEveninSBE a c) = ctype (Rep c)\"\n  sorry\n\nlemma buildevenin_surj: assumes \"sbElem_well (Some sbe)\"\n  shows \"sbe \\<in> range buildEveninSBE\"\nproof -\n  have ctypewell:\"\\<And> c. sbe c\\<in> ctype (Rep c)\"\n    using assms by auto\n  hence \"\\<And>c. sbe c \\<in> range (\\<lambda>a. buildEveninSBE a c)\"\n    by (simp add: buildevenin_range)\n  hence \"\\<exists>prod. sbe = buildEveninSBE prod\"\n    apply(subst fun_eq_iff,auto)\n    sorry\n  thus ?thesis\n    by auto\nqed\n\nabbreviation \"buildEveninSB \\<equiv> inEvenChan (Rep_cfun (smap ((Untimed o \\<N>))))\" \n\nend", "meta": {"author": "yyisgladiator", "repo": "demo", "sha": "2a57300dfa7268721c78c233ee6b0a5454acce1f", "save_path": "github-repos/isabelle/yyisgladiator-demo", "path": "github-repos/isabelle/yyisgladiator-demo/demo-2a57300dfa7268721c78c233ee6b0a5454acce1f/src/demo/evenA/inEvenData.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185205547239, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.25874784814994234}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      SyntaxTest.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2006-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n(*<*)\n\ntheory SyntaxTest imports HeapList VcgCon begin\n\n\nrecord Example1 =\n  A :: \"nat list\"\n  B :: \"nat\"\n\nlemma \"\\<lbrace> (length \\<ordmasculine>A = length \\<ordfeminine>A) \\<and> (\\<ordmasculine>A ! i = \\<ordfeminine>A ! i) \\<rbrace> = \n         {x. (length (A (fst x)) = length (A (snd x))) \\<and> \n             ((A (fst x))!i = (A (snd x))!i) }\"\nby auto\n\nrecord \"globals\" =\n alloc_' :: \"ref list\"\n free_':: nat\n GA_' :: \"ref list list\"\n next_' :: \"ref \\<Rightarrow> ref\"\n cont_' :: \"ref \\<Rightarrow> nat\"\n\nrecord localsd = \n  n1_' :: \"nat\"\n  n2_' :: \"ref \\<Rightarrow> nat\"\n\nrecord ('g,'a) vars = \"'g state\" +\n  A_' :: \"nat list\"\n  AA_' :: \"nat list list\"\n  I_' :: nat\n  M_' :: nat\n  N_' :: nat\n  R_' :: int\n  R1_' :: \"'a list\"\n  S_' :: int\n  B_' :: bool\n  Abr_':: string\n  p_' :: ref\n  q_' :: ref\n  d_' :: nat\n\nrecord ('g,'a) vars1 = \"'g state\" +\n  A_' :: \"nat list\"\n  AA_' :: \"nat list list\"\n  I_' :: nat\n  M_' :: nat\n  N_' :: nat\n  R_' :: int\n  R1_' :: \"'a list\"\n  S_' :: int\n  B_' :: bool\n  Abr_':: string\n  p_' :: ref\n  q_' :: ref\n  d_' :: nat\n\nlemma \"{..<3::nat} = {} \\<Longrightarrow> False\"\nby (simp add: Iio_eq_empty_iff_nat)\n\n\nlemma Example1:\n \"\\<Gamma>,{} \\<turnstile>\\<^bsub>/{}\\<^esub> (COBEGIN\n      SCHEME [0 \\<le> i < n]\n     (SKIP,\n     \\<lbrace>\\<acute>M = 0\\<rbrace>,\n     \\<lbrace>(\\<ordmasculine>M = \\<ordfeminine>M)\\<rbrace>\\<^sub>r ,\n     {(x,y). (\\<exists>x1 y1. x=Normal x1 \\<and> y=Normal y1 \\<and> (M_' x1=  M_' y1))},\n     \\<lbrace> True \\<rbrace>,\n      \\<lbrace> True \\<rbrace>)\n    COEND)\n SAT [\\<lbrace>\\<acute>M = 0\\<rbrace>, {(x,y). (\\<exists>x1 y1. x=Normal x1 \\<and> y=Normal y1 \\<and> (M_' x1=  M_' y1))},\n     {(x,y). (\\<exists>x1 y1. x=Normal x1 \\<and> y=Normal y1 \\<and> (M_' x1=  M_' y1))}, \\<lbrace> True \\<rbrace>, \\<lbrace> True \\<rbrace>]\"\napply (rule Parallel)\napply (auto simp add:Pre_def Rely_def Com_def Guar_def Post_def Abr_def)\napply (auto intro!: Conseq)\napply(rule_tac x=\"\\<lbrace>\\<acute>M = 0\\<rbrace>\" in exI)\napply simp\napply(rule_tac x=\"{(x,y). (\\<exists>x1 y1. x=Normal x1 \\<and> y=Normal y1 \\<and> (M_' x1=  M_' y1))}\" in exI)\napply simp\napply(rule_tac x=\"{(x,y). (\\<exists>x1 y1. x=Normal x1 \\<and> y=Normal y1 \\<and> (M_' x1=  M_' y1))}\" in exI)\napply simp\napply(rule_tac x=\"\\<lbrace>\\<acute>M = 0\\<rbrace>\" in exI)\napply (subgoal_tac \"lrghoare \\<Gamma> {} {} SKIP \\<lbrace>\\<acute>M = 0\\<rbrace>\n                 {(x,y). (\\<exists>x1 y1. x=Normal x1 \\<and> y=Normal y1 \\<and> (M_' x1=  M_' y1))}\n                 {(x,y). (\\<exists>x1 y1. x=Normal x1 \\<and> y=Normal y1 \\<and> (M_' x1=  M_' y1))} \\<lbrace>\\<acute>M = 0\\<rbrace> \\<lbrace>\\<acute>M = 0\\<rbrace>\")\nprefer 2\nby (auto simp add: Norm_def Sta_def intro!:Skip)\n\nthm Conseq LocalRG_HoareDef.Conseq\nlemma Example2:\n \"\\<Gamma>,{} \\<turnstile>\\<^bsub>/{}\\<^esub> (COBEGIN\n      SCHEME [0 \\<le> i < n]\n     (SKIP,\n     \\<lbrace>\\<acute>M = 0\\<rbrace>,\n     {(x,y). (\\<exists>x1 y1. x=Normal x1 \\<and> y=Normal y1 \\<and> x=y)},\n     {(x,y). (\\<exists>x1 y1. x=Normal x1 \\<and> y=Normal y1 \\<and> x=y)},\n     \\<lbrace> True \\<rbrace>,\n      \\<lbrace> True \\<rbrace>)\n    COEND)\n SAT [\\<lbrace>\\<acute>M = 0\\<rbrace>, {(x,y). (\\<exists>x1 y1. x=Normal x1 \\<and> y=Normal y1 \\<and> x=y)},\n     {(x,y). (\\<exists>x1 y1. x=Normal x1 \\<and> y=Normal y1 \\<and> x=y)}, \\<lbrace> True \\<rbrace>, \\<lbrace> True \\<rbrace>]\"\napply (rule Parallel)\napply (auto simp add:Pre_def Rely_def Com_def Guar_def Post_def Abr_def)\napply (auto intro!: Conseq)\napply(rule_tac x=\"\\<lbrace>\\<acute>M = 0\\<rbrace>\" in exI)\napply simp\napply(rule_tac x=\"{(x,y). (\\<exists>x1 y1. x=Normal x1 \\<and> y=Normal y1 \\<and> x=y)}\" in exI)\napply simp\napply(rule_tac x=\"{(x,y). (\\<exists>x1 y1. x=Normal x1 \\<and> y=Normal y1 \\<and> x=y)}\" in exI)\napply simp\napply(rule_tac x=\"\\<lbrace>\\<acute>M = 0\\<rbrace>\" in exI)\napply (subgoal_tac \"lrghoare \\<Gamma> {} {} SKIP \\<lbrace>\\<acute>M = 0\\<rbrace>\n                {(x, y). (\\<exists>x1. x = Normal x1) \\<and> (\\<exists>y1. y = Normal y1) \\<and> x = y}\n                {(x, y). (\\<exists>x1. x = Normal x1) \\<and> (\\<exists>y1. y = Normal y1) \\<and> x = y} \\<lbrace>\\<acute>M = 0\\<rbrace> \\<lbrace>\\<acute>M = 0\\<rbrace>\")\nprefer 2\napply (rule Skip)\napply (simp add: Sta_def)\napply (simp add: Norm_def)\napply (simp add: Norm_def)\nby auto\n\n\nlemma Example3:\n \"\\<Gamma>,{} \\<turnstile>\\<^bsub>/{}\\<^esub> (COBEGIN\n      SCHEME [0 \\<le> i < n]\n     (SKIP,\n     \\<lbrace> True \\<rbrace>,\n     \\<lbrace>True \\<rbrace>,\n     \\<lbrace> True \\<rbrace>,\n     \\<lbrace> True \\<rbrace>,\n     \\<lbrace> True \\<rbrace>)\n    COEND)\n SAT [\\<lbrace> True \\<rbrace>, \\<lbrace> True \\<rbrace>, \\<lbrace> True \\<rbrace>, \\<lbrace> True \\<rbrace>, \\<lbrace> True \\<rbrace>]\"\napply (auto simp add: Parallel)\napply (rule Parallel)\napply (auto simp add:Pre_def Rely_def Com_def Guar_def Post_def Abr_def)\napply (rule Skip)\napply (auto intro!: Skip simp:Sta_def Norm_def)[1]\nsorry\n\n\n\n(*lemma Example1:\n \"\\<Gamma>,{} \\<turnstile>\\<^bsub>/{}\\<^esub> (COBEGIN\n      SCHEME [0 \\<le> i < n]\n     (\\<acute>A :== \\<acute>A [i := 0],\n     \\<lbrace> n < length \\<acute>A \\<rbrace>,\n     \\<lbrace> length \\<ordmasculine>A = length \\<ordfeminine>A \\<and> \\<ordmasculine>A ! i = \\<ordfeminine>A ! i \\<rbrace>,\n     \\<lbrace> length \\<ordmasculine>A = length \\<ordfeminine>A \\<and> (\\<forall>j<n. i \\<noteq> j \\<longrightarrow> \\<ordmasculine>A ! j = \\<ordfeminine>A ! j) \\<rbrace>,\n     \\<lbrace> \\<acute>A ! i = 0 \\<rbrace>)\n    COEND)\n sat [\\<lbrace> n < length \\<acute>A \\<rbrace>, \\<lbrace> \\<ordmasculine>A = \\<ordfeminine>A \\<rbrace>, \\<lbrace> True \\<rbrace>, \\<lbrace> \\<forall>i < n. \\<acute>A ! i = 0 \\<rbrace>, \\<lbrace> \\<forall>i < n. \\<acute>A ! i = 0 \\<rbrace>]\"\n*)\n\n\n\n\nhoarestate h = PA :: nat\n\nhoarestate h1 = h + KA::nat\n                    v::ref\n                    q_' :: ref\n                    free_':: nat\n                    d_'::nat\n \n\n\nprocedures (imports h1)  Foo (q,d|d) = \"\\<acute>q :== \\<acute>q;;\\<acute>free:==0;;\\<acute>d:==0\"\n\ncontext Foo_impl\nbegin\nthm Foo_impl\nthm Foo_body_def\nend\ncontext h1\nbegin\nterm  \"\\<acute>KA :== 3 -1 ;; \\<acute>PA:==1\"\nend\n\nterm \"\\<acute>n1 :==\\<^sub>g 3 - 1\"\nterm \"\\<acute>I :==\\<^sub>g \\<acute>free\"\nterm \"\\<acute>R :==\\<^sub>g 3 - 1\"\nterm \"\\<acute>I :==\\<^sub>g \\<acute>A!i\"\nterm \" \\<acute>A!i :== j\"\nterm \" \\<acute>AA :== \\<acute>AA!![i,j]\"\nterm \" \\<acute>AA!![i,j] :== \\<acute>AA\"\nterm \"\\<acute>A!i :==\\<^sub>g j\"\nterm \"\\<acute>p :==\\<^sub>g \\<acute>GA!i!j\"\nterm \"\\<acute>p :==\\<^sub>g \\<acute>GA!i!j\"\nterm \"\\<acute>GA!i!j :==\\<^sub>g \\<acute>p\"\nterm \"\\<acute>p :==\\<^sub>g \\<acute>p \\<rightarrow> \\<acute>next\"\nterm \"\\<acute>p \\<rightarrow> \\<acute>next :==\\<^sub>g \\<acute>p\"\nterm \"\\<acute>p \\<rightarrow> \\<acute>next \\<rightarrow> \\<acute>next :==\\<^sub>g \\<acute>p\"\nterm \"\\<acute>p :== NEW sz [\\<acute>next :== Null,\\<acute>cont :== 0]\"\nterm \"\\<acute>p\\<rightarrow>\\<acute>next :==\\<^sub>g NEW sz [\\<acute>next :== Null,\\<acute>cont :== 0]\"\nterm \"\\<acute>p :== NNEW sz [\\<acute>next :== Null,\\<acute>cont :== 0]\"\nterm \"\\<acute>p\\<rightarrow>\\<acute>next :==\\<^sub>g NNEW sz [\\<acute>next :== Null,\\<acute>cont :== 0]\"\nterm \"\\<acute>B :==\\<^sub>g \\<acute>N + 1 < 0 \\<and> \\<acute>M + \\<acute>N < n\"\nterm \"\\<acute>B :==\\<^sub>g \\<acute>N + 1 < 0 \\<or>  \\<acute>M + \\<acute>N < n\"\nterm \"\\<acute>I :==\\<^sub>g \\<acute>N mod n\"\nterm \"\\<acute>I :==\\<^sub>g \\<acute>N div n\"\nterm \"\\<acute>R :==\\<^sub>g \\<acute>R div n\"\nterm \"\\<acute>R :==\\<^sub>g \\<acute>R mod n\"\nterm \"\\<acute>R :==\\<^sub>g \\<acute>R * n\"\nterm \"\\<acute>I :==\\<^sub>g \\<acute>I - \\<acute>N\"\nterm \"\\<acute>R :==\\<^sub>g \\<acute>R - \\<acute>S\"\nterm \"\\<acute>R :==\\<^sub>g int \\<acute>I\"\nterm \"\\<acute>I :==\\<^sub>g nat \\<acute>R\"\nterm \"\\<acute>R :==\\<^sub>g -\\<acute>R\"\nterm \"IF\\<^sub>g \\<acute>A!i < \\<acute>N THEN c1 ELSE c2 FI\"\nterm \"AWAIT\\<^sub>g \\<acute>A!i < \\<acute>N (IF True THEN SKIP ELSE SKIP FI)\"\nterm \"WHILE\\<^sub>g \\<acute>A!i < \\<acute>N DO c OD\"\nterm \"WHILE\\<^sub>g \\<acute>A!i < \\<acute>N INV \\<lbrace>foo\\<rbrace> DO c OD\"\nterm \"WHILE\\<^sub>g \\<acute>A!i < \\<acute>N INV \\<lbrace>foo\\<rbrace> VAR bar x DO c OD\"\nterm \"WHILE\\<^sub>g \\<acute>A!i < \\<acute>N INV \\<lbrace>foo\\<rbrace> VAR bar x DO c OD;;cd\"\nterm \"c;;WHILE\\<^sub>g \\<acute>A!i < \\<acute>N INV \\<lbrace>foo\\<rbrace> VAR MEASURE \\<acute>N + \\<acute>M DO c;;c OD;;c\"\ncontext Foo_impl\nbegin\nterm \"\\<acute>q :== CALL Foo(\\<acute>p,\\<acute>M)\" \nterm \"\\<acute>q :== CALL\\<^sub>g Foo(\\<acute>p,\\<acute>M + 1)\" \nterm \"\\<acute>q :== CALL Foo(\\<acute>p\\<rightarrow>\\<acute>next,\\<acute>M)\" \nterm \"\\<acute>q \\<rightarrow> \\<acute>next :== CALL Foo(\\<acute>p,\\<acute>M)\" \nterm \"COBEGIN (\\<acute>q :== CALL Foo(\\<acute>p\\<rightarrow>\\<acute>next,\\<acute>M)) \\<parallel> (\\<acute>q :== CALL Foo(\\<acute>p\\<rightarrow>\\<acute>next,\\<acute>M)) COEND\"\nend\n\nend\n\n(*>*) ", "meta": {"author": "CompSoftVer", "repo": "CSim2", "sha": "b09a4d77ea089168b1805db5204ac151df2b9eff", "save_path": "github-repos/isabelle/CompSoftVer-CSim2", "path": "github-repos/isabelle/CompSoftVer-CSim2/CSim2-b09a4d77ea089168b1805db5204ac151df2b9eff/ConCSimpl/SyntaxTest.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632979641571, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.25871760111903436}}
{"text": "(*<*)\ntheory Preliminaries\nimports Abbrevs\nbegin\n\n\nrecord foorecord = fld\\<^sub>1 :: nat fld\\<^sub>2 ::nat\ndatatype foodatatype = Foo\nnotation (latex output)\nFoo (\"\\<^latex>\\<open>\\\\constructor{Foo}\\<close>\")\n\n(* TODO:\nsetup {*add_constructor_syntax \"latex\" \"Preliminaries.foodatatype\" *}\n*)\n(*>*)\nsection \\<open>Preliminaries \\label{sec:preliminaries}\\<close>\ntext \\<open>\nThe formalization presented in this papaer is mechanized and checked within the generic interactive theorem prover \\emph{Isabelle}\\cite{Paulson:IGTP94}. \nIsabelle is called generic as it provides a framework to formalize various \\emph{object logics} declared via natural deduction style inference rules.\nThe object logic that we employ for our formalization is the higher order logic of \\emph{Isabelle/HOL}\\cite{Nipkow:IHOL02}. \n\nThis article is written using Isabelle's document generation facilities, which guarantees a close correspondence between the presentation and the actual theory files.\nWe distinguish formal entities typographically from other text. \nWe use a sans serif font for types and constants (including functions and predicates), \\eg @{term \"map\"}, a slanted serif font for free variables, \\eg @{term \"x\"}, and a slanted sans serif font for bound variables, \\eg @{term \"Bind x. x\"}.\nSmall capitals are used for data type constructors, \\eg @{term[names_short] \"Foo\"}, and type variables have a leading tick, \\eg  @{typ \"'a\"}. HOL keywords are typeset in type-writer font, \\eg \\holkeyword{let}. %We also take the freedom to borrow C notation, \\eg @{term \"UnsgndT\"} when presenting C0.\n\nTo group common premises and to support modular reasoning Isabelle provides \\emph{locales}\\cite{Ballarin:TYPES03-34,Ballarin:MKM06-31}. \nA locale provides a name for a context of fixed parameters and premises, together with an elaborate infrastructure to define new locales by inheriting and extending other locales, prove theorems within locales and interpret (instantiate) locales. In our formalization we employ this infrastructure to separate the memory system from the programming language semantics. \n\nThe logical and mathematical notions follow the standard notational conventions with a bias towards functional programming. \nWe only present the more unconventional parts here. \nWe prefer curried function application, \\eg @{term \"f a b\"} instead of @{term [mode=uncurry] \"f a b\"}.\nIn this setting the latter becomes a function application to \\emph{one} argument, which happens to be a pair.\n\nIsabelle/HOL provides a library of standard types like Booleans, natural numbers, integers, total functions, pairs, lists, and sets. Moreover, there are packages to define new data types and records. \nIsabelle allows polymorphic types, \\eg @{typ \"'a list\"} is the list type with type variable @{typ \"'a\"}. \nIn HOL all functions are total, \\eg @{typ \"nat \\<Rightarrow> nat\"} is a total function on natural numbers. \nA function update is @{thm fun_upd_def[of f y v]}.\nTo formalize partial functions the type @{typ \"'a option\"} is used. \nIt is a data type with two constructors, one to inject values of the base type, \\eg @{term \"Some x\"}, and the additional element @{term \"None\"}. \nA base value can be projected with the function @{term \"the\"}, which is defined by the sole equation @{thm option.sel [of x]}. \nSince HOL is a total logic the term @{term \"the None\"} is still a well-defined yet un(der)specified value. \nPartial functions are usually represented by the type \\<open>\\<^latex>\\<open>\\tfreeify{\\<close>'a\\<^latex>\\<open>}\\<close> \\<Rightarrow> \\<^latex>\\<open>\\tfreeify{\\<close>'b\\<^latex>\\<open>}\\<close> option\\<close>, abbreviated as @{typ  \"'a \\<rightharpoonup> 'b\"}. \nThey are commonly used as \\emph{maps}. \n%With @{term \"map_of xs\"} we construct a map from an association list, \\ie a list of key~/~value pairs. \nWe denote the domain of map  @{term \"m\"} by @{term \"dom m\"}. % not used: and to its range by @{term \"ran m\"}. \nA map update is written as @{term \"m(a := Some v)\"}.\n%With @{term \"m\\<^sub>1 ++ m\\<^sub>2\"} we add the map @{term \"m\\<^sub>2\"} to map @{term \"m\\<^sub>1\"}, where entries of @{term \"m\\<^sub>1\"} are overwritten if necessary. \nWe can restrict the domain of a map @{term \"m\"} to a set @{term \"A\"} by @{term \"m |` A\"}. \n%Subsumption of maps is defined as @{thm \"map_le_def\" [of m\\<^sub>1 m\\<^sub>2]} and composition of maps as @{thm \"map_comp_def\" [of m\\<^sub>1 m\\<^sub>2]}.\n\n%\\paragraph{Lists.}\nThe syntax and the operations for lists are similar to functional programming languages like ML or Haskell. \nThe empty list is @{term \"[]\"}, with @{term \"x#xs\"} the element @{term \"x\"} is `consed' to the list @{term \"xs\"}.%, the head of list @{term \"xs\"} is @{term \"hd xs\"} and the remainder, its tail, is @{term \"tl xs\"}. \nWith @{term \"xs@ys\"} list @{term \"ys\"} is appended to list @{term \"xs\"}.\nWith the term @{term \"map f xs\"} the function @{term \"f\"} is applied to all elements in @{term \"xs\"}. \nThe length of a list is @{term \"length xs\"}, the @{term n}-th element of a list can be selected with @{term \"xs!n\"} and can be updated via @{term \"xs[n:=v]\"}. With @{term \"dropWhile P xs\"} the prefix for which all elements satisfy predicate @{term \"P\"} are dropped from list @{term \"xs\"}.\n%With @{term \"set xs\"} we obtain the set of elements in list @{term \"xs\"}.\n%Filtering those elements from a list for which predicate @{term \"P\"} holds is achieved by @{term [eta_contract=false] \"[x\\<in>xs. P x]\"}.\n%With @{term \"replicate n e\"} we denote a list that consists of @{term n} elements @{term e}.\n\n%\\paragraph{Sets.}\nSets come along with the standard operations like union, \\ie @{term \"A \\<union> B\"}, membership, \\ie @{term \"x \\<in> A\"} and set inversion, \\ie @{term \"- A\"}.\n\n%intersection, \\ie @{term \"A \\<inter> B\"} and \n%The set image @{term \"f ` A\"} yields a new set by applying function @{term \"f\"} to every element in set @{term \"A\"}.\n\n\n\n\n%\\paragraph{Records.}\n%A record is constructed by assigning all of its fields, \\eg @{term \"\\<lparr>fld\\<^sub>1 = v\\<^sub>1, fld\\<^sub>2 = v\\<^sub>2\\<rparr>\"}.\n%Field @{term [names_short]\"fld\\<^sub>1\"} of record @{term \"r\"} is selected by @{term[names_short] \"fld\\<^sub>1 r\"} and updated with a value @{term \"x\"} via @{term[names_short] \"r\\<lparr>fld\\<^sub>1 := x\\<rparr>\"}. \n\n%\\paragraph{Tuples.}\n%The first and second component of a pair can be accessed with the functions @{const fst} and @{const snd}. \nTuples with more than two components are pairs nested to the right.\n\n\\<close>\n(*<*)\nend\n(*>*)\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Store_Buffer_Reduction/Preliminaries.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.476579651063676, "lm_q1q2_score": 0.25871759406963407}}
{"text": "theory MoreCurrAutomation\nimports DataRefinementMore\nbegin\n\n\nthm T_g_specifies_I\n\ndefinition (in -) mm3 where\n  \"mm3 t A = (case A of None \\<Rightarrow> None | Some t' \\<Rightarrow> if t'\\<le>t then Some (t-t') else None)\"\n\n\nlemma Some_le_mm3_Some_conv: \"Some t \\<le> mm3 t' (Some t'') \\<longleftrightarrow> (t'' \\<le> t' \\<and> t \\<le> (t' - t''))\"\n  by (simp add: mm3_def)\n  \n\nlemma Some_le_emb'_conv: \"Some t \\<le> emb' Q ft x \\<longleftrightarrow> Q x \\<and> t \\<le> ft x\"\n  by (auto simp: emb'_def)\n\n\nlemma Some_eq_emb'_conv: \"Some t = emb' Q ft x \\<longleftrightarrow> Q x \\<and> t = ft x\"\n        \"emb' Q ft x = Some t  \\<longleftrightarrow> Q x \\<and> t = ft x\"\n  by (auto simp: emb'_def)\n\ndefinition  whileIET :: \"('a \\<Rightarrow> bool) \\<Rightarrow> ('a \\<Rightarrow> 'c) \\<Rightarrow> ('a \\<Rightarrow> bool)\n                           \\<Rightarrow> ('a \\<Rightarrow> ('a,'c::{complete_lattice,plus,zero}) nrest)\n                           \\<Rightarrow> 'a \\<Rightarrow> ('a,'c) nrest\" where\n  \"\\<And>E c. whileIET I E b c = whileT b c\"\n\n\n\nsubsection \\<open>Progress prover\\<close>\n\n\ndefinition \"progress m \\<equiv> \\<forall>s' M. m = SPECT M \\<longrightarrow> M s' \\<noteq> None \\<longrightarrow> M s' > Some 0\"\nlemma progressD: \"progress m \\<Longrightarrow> m=SPECT M \\<Longrightarrow> M s' \\<noteq> None \\<Longrightarrow> M s' > Some 0\"\n  by (auto simp: progress_def)\n\n\nsubsection \\<open>Progress rules\\<close>\n\nnamed_theorems progress_rules\n\nlemma progress_SELECT_iff: \"progress (SELECT P t) \\<longleftrightarrow> t > 0\"\n  unfolding progress_def SELECT_def emb'_def by (auto split: option.splits)\n\nlemmas [progress_rules] = progress_SELECT_iff[THEN iffD2]\n\nlemma progress_REST_iff: \"progress (REST [x \\<mapsto> t]) \\<longleftrightarrow> t>0\"\n  by (auto simp: progress_def)\n\nlemmas [progress_rules] = progress_REST_iff[THEN iffD2]\n\nlemma progress_ASSERT_bind[progress_rules]: \"\\<lbrakk>\\<Phi> \\<Longrightarrow> progress (f ()) \\<rbrakk> \\<Longrightarrow> progress (ASSERT \\<Phi>\\<bind>f)\"\n  apply (cases \\<Phi>)\n   apply (auto simp: progress_def less_fun_def)\n  sorry\n\n\nlemma progress_SPECT_emb[progress_rules]: \"t > 0 \\<Longrightarrow> progress (SPECT (emb P t))\" by(auto simp: progress_def emb'_def)\n\n\nlemma Sup_Some: \"Sup (S::enat option set) = Some e \\<Longrightarrow> \\<exists>x\\<in>S. (\\<exists>i. x = Some i)\"\n  unfolding Sup_option_def by (auto split: if_splits)\n\nlemma progress_bind[progress_rules]: assumes \"progress m \\<or> (\\<forall>x. progress (f x))\"\n  shows \"progress (m\\<bind>f)\"\n  sorry\n\nmethod progress methods solver = \n  (rule asm_rl[of \"progress _\"] , (simp add: le_fun_def less_fun_def split: prod.splits | intro allI impI conjI | determ \\<open>rule progress_rules\\<close> | rule disjI1; progress \\<open>solver\\<close>; fail | rule disjI2; progress \\<open>solver\\<close>; fail | solver)+) []\n\n\nsubsection \\<open>VCG splitter\\<close>\n\n\n\nML \\<open>\n\n  structure VCG_Case_Splitter = struct\n    fun dest_case ctxt t =\n      case strip_comb t of\n        (Const (case_comb, _), args) =>\n          (case Ctr_Sugar.ctr_sugar_of_case ctxt case_comb of\n             NONE => NONE\n           | SOME {case_thms, ...} =>\n               let\n                 val lhs = Thm.prop_of (hd (case_thms))\n                   |> HOLogic.dest_Trueprop |> HOLogic.dest_eq |> fst;\n                 val arity = length (snd (strip_comb lhs));\n                 (*val conv = funpow (length args - arity) Conv.fun_conv\n                   (Conv.rewrs_conv (map mk_meta_eq case_thms));*)\n               in\n                 SOME (nth args (arity - 1), case_thms)\n               end)\n      | _ => NONE;\n    \n    fun rewrite_with_asm_tac ctxt k =\n      Subgoal.FOCUS (fn {context = ctxt', prems, ...} =>\n        Local_Defs.unfold0_tac ctxt' [nth prems k]) ctxt;\n    \n    fun split_term_tac ctxt case_term = (\n      case dest_case ctxt case_term of\n        NONE => no_tac\n      | SOME (arg,case_thms) => let \n            val stac = asm_full_simp_tac (put_simpset HOL_basic_ss ctxt addsimps case_thms) \n          in \n          (*CHANGED o stac\n          ORELSE'*)\n          (\n            Induct.cases_tac ctxt false [[SOME arg]] NONE []\n            THEN_ALL_NEW stac\n          ) \n        end 1\n    \n    \n    )\n\n    fun split_tac ctxt = Subgoal.FOCUS_PARAMS (fn {context = ctxt, ...} => ALLGOALS (\n        SUBGOAL (fn (t, _) => case Logic.strip_imp_concl t of\n          @{mpat \"Trueprop (Some _ \\<le> T_g _ ?prog)\"} => split_term_tac ctxt prog\n         | @{mpat \"Trueprop (progress ?prog)\"} => split_term_tac ctxt prog  \n     (*   | @{mpat \"Trueprop (Case_Labeling.CTXT _ _ _ (valid _ _ ?prog))\"} => split_term_tac ctxt prog *)\n        | _ => no_tac\n        ))\n      ) ctxt \n      THEN_ALL_NEW TRY o Hypsubst.hyp_subst_tac ctxt\n\n  end\n\\<close>\n\nmethod_setup vcg_split_case = \\<open>Scan.succeed (fn ctxt => SIMPLE_METHOD' (CHANGED o (VCG_Case_Splitter.split_tac ctxt)))\\<close>\n\n\nnamed_theorems vcg_rules' \nmethod vcg'_step methods solver uses rules =\n    (intro rules vcg_rules' | vcg_split_case \n        | (progress simp;fail)  | (solver; fail))\n\nmethod vcg' methods solver uses rules = repeat_all_new \\<open>vcg'_step solver rules: rules\\<close>\n\n\n\nlemma T_g_SPECT2_I[vcg_rules']: \n  fixes t' :: \"'b\\<Rightarrow>enat\" (* \"'b:: {complete_lattice,minus,plus,ord}\" *)\n  assumes \"(\\<And> x. X x \\<Longrightarrow> (Some (t' + t x ) \\<le> Q x))\"\n  shows \"Some t' \\<le> T_g Q (SPECT (emb' X t))\"\n  apply(auto simp: T_g_def)\n  apply(rule Inf_greatest) apply auto\n  unfolding mii_g_def mm_g_def emb'_def apply (auto split: option.splits)\n  subgoal using assms by force\n  subgoal for x tx using assms[of x] apply simp  \n    by (simp add: enat_adjoint le_fun_def)  \n  subgoal for x tx using assms[of x] apply simp  \n    by (metis ab_semigroup_add_class.add_ac(1) add.commute le_iff_add)  \n  done\n\n\nlemma T_g_bindT_I[vcg_rules']: \n  \"\\<And>t. Some t \\<le>  T_g (\\<lambda>y. T_g Q (f y) ) M \\<Longrightarrow>  Some t \\<le> T_g Q (M \\<bind> f)\"\n  sorry\n\n\nlemma T_g_SPECT_I[vcg_rules']:  \"\\<And>t. (Some (t' + t ) \\<le> Q x)\n    \\<Longrightarrow>  Some t' \\<le> T_g Q (SPECT [ x \\<mapsto> t])\"\n  sorry\n\nlemma (in -) While[vcg_rules']:\n  fixes I and E :: \"'a \\<Rightarrow> 'c::{complete_lattice,minus,zero,order,plus}\" and b C s0\n  assumes  \"I s0\"  \"(\\<And>s. I s \\<Longrightarrow> b s \\<Longrightarrow> Some 0 \\<le> T_g (\\<lambda>s'. mm3 (E s) (if I s' then Some (E s') else None)) (C s)) \"\n     \"(\\<And>s. progress (C s))\"\n     \"(\\<And>x. \\<not> b x \\<Longrightarrow>  I x \\<Longrightarrow>  (E x) \\<le> (E s0) \\<Longrightarrow>   Some (t +  ((E s0) - E x)) \\<le> Q x)\"\n   shows   \"Some t \\<le> T_g Q  (whileIET I E b C s0)\"\n  sorry\n\nlemma (in -) if_T_g[vcg_rules']: \"(b \\<Longrightarrow> t \\<le> T_g Q Ma) \\<Longrightarrow> (\\<not>b \\<Longrightarrow> t \\<le> T_g Q Mb) \\<Longrightarrow> t  \\<le> T_g Q  (if b then Ma else Mb)\"\n   by (simp add: split_def)\n\n\nlemma (in -) T_g_ASSERT_I[vcg_rules']: \"(\\<Phi> \\<Longrightarrow> Some t \\<le> Q ()) \\<Longrightarrow> \\<Phi> \\<Longrightarrow> Some t \\<le> T_g Q (ASSERT \\<Phi>)\"\n  sorry\n\n\nlemma (in -) T_SELECT[vcg_rules']: \n  assumes  \n    \"\\<forall>x. \\<not> P x \\<Longrightarrow> Some tt \\<le> T_g Q (SPECT [None \\<mapsto> tf])\"\n  and p: \"(\\<And>x. P x \\<Longrightarrow> Some tt \\<le> T_g Q (SPECT [Some x \\<mapsto> tf]) )\"\nshows \"Some tt \\<le> T_g Q (SELECT P tf)\"\n  sorry\n\nlemma (in-) RETURNT_T_I[vcg_rules']: \"t \\<le> Q x \\<Longrightarrow> t  \\<le> T_g Q (RETURNT x)\"\n  sorry \n\n\nsubsection \\<open>Monotonicity rules for refine_vcg proofs\\<close>\n\n\nlemma RECT_mono[refine_mono]:\n  assumes [simp]: \"mono2 B'\"\n  assumes LE: \"\\<And>F x. (B' F x) \\<le> timerefine FF (B F x) \"\n  shows \" (RECT B' x) \\<le> timerefine FF (RECT B x)\"\n  unfolding RECT_def\n  apply clarsimp  \n  using LE gfp_mono le_fun_def   sorry  \n\n\nlemma WHILET_refine:\n  assumes R0: \"(x,x')\\<in>R\"\n  assumes COND_REF: \"\\<And>x x'. \\<lbrakk> (x,x')\\<in>R \\<rbrakk> \\<Longrightarrow> b x = b' x'\"\n  assumes STEP_REF: \n    \"\\<And>x x'. \\<lbrakk> (x,x')\\<in>R; b x; b' x' \\<rbrakk> \\<Longrightarrow> f x \\<le> \\<Down>R (timerefine F  (f' x'))\"\n  shows \"whileT b f x \\<le> \\<Down>R (timerefine F (whileT b' f' x'))\"\n  sorry\n\nlemma (in -) whileT_mono: \n  assumes \"\\<And>x. b x \\<Longrightarrow> c x \\<le> timerefine F (c' x)\"\n  shows \" (whileT b c x) \\<le> timerefine F (whileT b c' x)\" (*\n  unfolding whileT_def apply(rule RECT_mono)\n    subgoal by(refine_mono)  \n  apply auto apply(rule bindT_mono) using assms by auto *) sorry\n\n\nthm bindT_refine'\n\nlemma bindT_refine_g:\n  fixes R' :: \"('a\\<times>'b) set\" and R::\"('c\\<times>'d) set\"\n  assumes R1: \"M \\<le> \\<Down> R' (timerefine F M')\"\n  assumes R2: \"\\<And>x x' t t'. \\<lbrakk> (x,x')\\<in>R'; \n    nofailT M; nofailT M'; inresT2 M x t;  inresT2 M' x' t';\n      t \\<le> (\\<lambda>c. Sum_any (\\<lambda>a. t' a * F a c))  \n  \\<rbrakk> \\<Longrightarrow> f x \\<le> \\<Down> R (timerefine F (f' x'))\"\n  shows \"bindT M (\\<lambda>x. f x) \\<le> \\<Down> R (timerefine F (bindT M' (\\<lambda>x'. f' x')))\"\n    sorry\n\nlemma bindT_refine_g':\n  fixes R' :: \"('a\\<times>'b) set\" and R::\"('c\\<times>'d) set\"\n  assumes R1: \"M \\<le> \\<Down> R' (timerefine F M')\"\n  assumes R2: \"\\<And>x x' t t'. \\<lbrakk> (x,x')\\<in>R'; \n    nofailT M; nofailT M'; inresT2 M x t;  inresT2 M' x' t';\n      t \\<le> (\\<lambda>c. Sum_any (\\<lambda>a. t' a * F a c))  \n  \\<rbrakk> \\<Longrightarrow> f x \\<le>   (timerefine F (f' x'))\"\n  shows \"bindT M (\\<lambda>x. f x) \\<le>  (timerefine F (bindT M' (\\<lambda>x'. f' x')))\"\n    sorry\n\nlemma timerefine_ASSERT: \"(\\<Phi>' \\<Longrightarrow> \\<Phi>) \\<Longrightarrow> ASSERT \\<Phi> \\<le> timerefine F (ASSERT \\<Phi>')\"\n  by (auto simp: timerefine_def ASSERT_def iASSERT_def RETURNT_def le_fun_def)\n\n\nlemma assumes \"(\\<And>s t. P s = Some t \\<Longrightarrow> \\<exists>s'. Some t \\<le> Q s' \\<and> (s, s') \\<in> R)\"\n  shows SPECT_refine: \"SPECT P \\<le> \\<Down> R (SPECT Q)\"\n  sorry\n\nlemma timerefine_SPECT:\n  assumes \"\\<And>x. P' x = None \\<Longrightarrow> P x = None\"\n    and \"\\<And>x x2. P' x = Some x2 \\<Longrightarrow> P x \\<le> Some (\\<lambda>cc. Sum_any (\\<lambda>ac. x2 ac * F ac cc))\"\nshows \"SPECT P \\<le> timerefine F (SPECT P')\"\n  unfolding timerefine_def\n  apply (auto split: option.splits simp: le_fun_def)\n  using assms by auto\n\nlemma timerefine_RETURNT:\n  assumes \"x=x'\"\nshows \"RETURNT x \\<le> timerefine F (RETURNT x')\"\n  unfolding RETURNT_def \n  using assms by (auto intro!: timerefine_SPECT simp: le_fun_def) \n\n\nthm SELECT_refine\nlemma SELECT_refine_g:\n  fixes T     \n  assumes \"\\<And>x'. P' x' \\<Longrightarrow> \\<exists>x. P x\"\n  assumes \"\\<And>x. P x \\<Longrightarrow>   P' x\"\n  assumes \"T \\<le> (\\<lambda>cc. Sum_any (\\<lambda>ac. T' ac * F ac cc))\"\n  shows \"SELECT P T \\<le> timerefine F (SELECT P' T')\"\n  unfolding SELECT_def\n  apply (auto split: if_splits)\n   using assms \n   by (auto intro!: timerefine_SPECT simp: emb'_def split: if_splits option.splits)\n (*\nproof -\n  have \"SELECT P T \\<le> SELECT P T'\"\n    using s1 assms(3) by auto\n  also have \"\\<dots> \\<le> SELECT P' T'\"\n    unfolding s2 apply safe\n    using assms(1,2) by auto  \n  finally show ?thesis .\nqed *)\n\n\n\nlemma If_refine: \"b = b' \\<Longrightarrow>\n  (b \\<Longrightarrow> b' \\<Longrightarrow> S1 \\<le> \\<Down> R (timerefine F S1')) \\<Longrightarrow>\n  (\\<not> b \\<Longrightarrow> \\<not> b' \\<Longrightarrow> S2 \\<le> \\<Down> R (timerefine F S2')) \\<Longrightarrow> (if b then S1 else S2) \\<le> \\<Down> R (timerefine F (if b' then S1' else S2'))\"\n  by auto\n\nlemma Case_prod_refine: \"(x,x')\\<in> \\<langle>S1,S2\\<rangle>prod_rel \\<Longrightarrow>\n  (\\<And>x x' y y'. (x,x')\\<in>S1 \\<Longrightarrow> (y,y')\\<in>S2 \\<Longrightarrow> C x y  \\<le> \\<Down> R (timerefine F (C' x' y')))\n  \\<Longrightarrow> (case x of (a,b) \\<Rightarrow> C a b) \\<le> \\<Down> R (timerefine F (case x' of (a',b') \\<Rightarrow> C' a' b'))\"\n  by (auto split: prod.split)\n\nlemma case_prod_refine_g2:\n  fixes P Q :: \"'a \\<Rightarrow> 'b \\<Rightarrow> ('c,_) nrest\"\n  assumes\n    \"\\<And>a b. P a b \\<le> \\<Down>R (timerefine FF (Q a b))\"\n  shows\n \"(case x of (a,b) \\<Rightarrow> P a b) \\<le> \\<Down>R (timerefine FF (case x of (a,b) \\<Rightarrow> Q a b))\"\n  using assms \n  by (simp add: split_def)\n\nlemma case_prod_refine_g:\n  fixes P Q :: \"'a \\<Rightarrow> 'b \\<Rightarrow> ('c,_) nrest\"\n  assumes\n    \"\\<And>a b. P a b \\<le> timerefine FF (Q a b)\"\n  shows\n \"(case x of (a,b) \\<Rightarrow> P a b) \\<le> timerefine FF (case x of (a,b) \\<Rightarrow> Q a b)\"\n  using assms \n  by (simp add: split_def)\n\nlemma bindT_mono_g: \n  \"m \\<le> timerefine FF m' \\<Longrightarrow> (\\<And>x. nofailT m' \\<Longrightarrow>  f x \\<le> timerefine FF (f' x))\n   \\<Longrightarrow> bindT m f \\<le> timerefine FF (bindT  m' f')\"\n  sorry\n\n\nlemma le_ASSERTI_g2:\n  fixes M :: \"(_,_) nrest\"\n  shows \"(\\<Phi> \\<Longrightarrow> M \\<le> \\<Down> R ( timerefine FF M' )) \\<Longrightarrow> M \\<le> \\<Down> R (timerefine FF (ASSERT \\<Phi> \\<bind> (\\<lambda>_. M')))\"\n  sorry\n\nlemma le_ASSERTI_g:\n  fixes M :: \"(_,_) nrest\"\n  shows \"(\\<Phi> \\<Longrightarrow> M \\<le> timerefine FF M') \\<Longrightarrow> M \\<le> timerefine FF (ASSERT \\<Phi> \\<bind> (\\<lambda>_. M'))\"\n  sorry\n\n\nlemma ASSERT_leI2: \n  fixes M :: \"(_,_) nrest\"\n  shows \"\\<Phi> \\<Longrightarrow> (\\<Phi> \\<Longrightarrow> M \\<le> \\<Down> R( timerefine FF M')) \\<Longrightarrow>ASSERT \\<Phi> \\<bind> (\\<lambda>_. M) \\<le>  \\<Down> R (timerefine FF M')\"\n  sorry\n\nlemma ASSERT_leI: \n  fixes M :: \"(_,_) nrest\"\n  shows \"\\<Phi> \\<Longrightarrow> (\\<Phi> \\<Longrightarrow> M \\<le> timerefine FF M') \\<Longrightarrow> ASSERT \\<Phi> \\<bind> (\\<lambda>_. M) \\<le> timerefine FF M'\"\n  sorry\n\nthm case_option_mono\nlemma case_option_mono_g:\n  assumes \"fn \\<le> timerefine FF fn'\"\n  assumes \"\\<And>v. x=Some v \\<Longrightarrow> fs v \\<le> timerefine FF (fs' v)\"\n  shows \"case_option fn fs x \\<le> timerefine FF (case_option fn' fs' x)\"\n  using assms by (auto split: option.split)\n\n\nlemma case_prod_mono_g: \n  \"\\<lbrakk>\\<And>a b. p=(a,b) \\<Longrightarrow> f a b \\<le> timerefine FF (f' a b)\\<rbrakk> \\<Longrightarrow> case_prod f p \\<le> timerefine FF (case_prod f' p)\"\n  by (auto split: prod.split)\n\n\nlemma nofailT_ASSERT_bind_g:\n  fixes M :: \"(_,_) nrest\"\n  shows \"nofailT (ASSERT P \\<bind> (\\<lambda>_. M)) \\<longleftrightarrow> (P \\<and> nofailT M)\"\n  sorry\n\n\nlemma inresT2_REST:\n  \"\\<And>t. inresT2 (REST X) x t \\<longleftrightarrow> (\\<exists>t'\\<ge>enat o t. X x = Some t')\" \n  unfolding inresT2_def \n  by auto\n\nlemma inresT2_SPEC[refine_pw_simps]: \"inresT2 (SPEC a b) = (\\<lambda>x t. a x \\<and>  b x \\<ge> t)\"\n  unfolding SPEC_def inresT2_REST\n  apply(rule ext)\n  by(auto simp: le_fun_def split:  if_splits)\n\n\n\nlemma inresT2_SELECT:\n \"inresT2 (SELECT Q tt) x t'\n     \\<longleftrightarrow> ((case x of None \\<Rightarrow> \\<not>(\\<exists>x. Q x) | Some x \\<Rightarrow> Q x)  \\<and> (t' \\<le> tt))\"\n  by(auto simp: inresT2_def SELECT_def le_fun_def emb'_def) \n\nlemma pw_inresT2_bindT: \"\\<And>t. inresT2 (bindT m f) r t \\<longleftrightarrow>\n     (nofailT m \\<longrightarrow> (\\<exists>r' t' t''. inresT2 m r' t' \\<and> inresT2 (f r') r t'' \\<and> t = t' + t''))\"\n  sorry\n\n\n\n  \n\n\nlemma if_distrib2: \"(if b then x else y) * z = (if b then x * z else y * z)\"\n  by(simp add: if_distrib)\n\n\nsection \\<open>Trans rules\\<close>\n\nlemma conc_trans_2:\n  assumes A: \"C \\<le> \\<Down>R (timerefine F B)\" and B: \"B \\<le> \\<Down>R' (timerefine F' A)\" \n  shows \"C \\<le> \\<Down>R (\\<Down>R'(timerefine F (timerefine F' A)))\"\n  sorry\n\nsection \\<open>enum setup\\<close>\n\n \n\nlemma (in enum) sum_to_foldr: \"sum f UNIV  \n      = foldr (\\<lambda>x a. a + f x) enum 0\"\n  (*= sum_list (map f enum_class.enum)\"  *)\n  unfolding UNIV_enum using enum_distinct\n  apply(simp add: sum.distinct_set_conv_list  )\n  apply(simp only: sum_list.eq_foldr foldr_map)  \n  by (metis add.commute comp_apply)  \n\nlemma (in enum) Sum_any_to_foldr: \"Sum_any f  \n      = foldr (\\<lambda>x a. a + f x) enum 0\"\n  apply(subst Sum_any.expand_superset[where A=UNIV])\n  by (simp_all add: sum_to_foldr)\n\n\n\n\ndefinition nfoldli where\n  \"nfoldli l c f s = RECT (\\<lambda>D (l,s). (case l of \n    [] \\<Rightarrow> RETURNT s \n    | x#ls \\<Rightarrow> if c s then do { s\\<leftarrow>f x s; D (ls, s)} else RETURNT s\n  )) (l, s)\"\n\n\ndefinition nfoldliIE :: \"('d list \\<Rightarrow> 'd list \\<Rightarrow> 'a \\<Rightarrow>  bool) \\<Rightarrow> ('b::{complete_lattice,plus,zero}) \\<Rightarrow> 'd list \\<Rightarrow> ('a \\<Rightarrow> bool) \\<Rightarrow> ('d \\<Rightarrow> 'a \\<Rightarrow> ('a,'b) nrest) \\<Rightarrow> 'a \\<Rightarrow> ('a,'b) nrest\" where\n  \"nfoldliIE I E l c f s = nfoldli l c f s\"\n\n\n\n\nlemma nfoldliIE_rule:\n  assumes I0: \"I [] l0 \\<sigma>0\"\n  assumes IS: \"\\<And>x l1 l2 \\<sigma>. \\<lbrakk> l0=l1@x#l2; I l1 (x#l2) \\<sigma>; c \\<sigma> \\<rbrakk> \\<Longrightarrow> f x \\<sigma> \\<le> SPECT (emb (I (l1@[x]) l2) (body_time))\"\n  assumes FNC: \"\\<And>l1 l2 \\<sigma>. \\<lbrakk> l0=l1@l2; I l1 l2 \\<sigma>; \\<not>c \\<sigma> \\<rbrakk> \\<Longrightarrow> P \\<sigma>\"  \n  assumes FC: \"\\<And>\\<sigma>. \\<lbrakk> I l0 [] \\<sigma> \\<rbrakk> \\<Longrightarrow> P \\<sigma>\"  \n  assumes T: \"\\<And>x. (body_time x * (enat (length l0))) \\<le> t x\"\n  shows \"nfoldliIE I body_time l0 c f \\<sigma>0 \\<le> SPECT (emb P t)\"\n  sorry\n\n\n\n\nlemma T_conseq4:\n  assumes \n    \"T_g Q' f \\<ge> Some t'\"\n    \"\\<And>x t'' M. Q' x = Some t'' \\<Longrightarrow> (Q x) \\<ge> Some ((t - t') + t'')\" \n  shows \"T_g Q f \\<ge> Some t\" sorry\n\nlemma T_conseq6:\n  assumes \n    \"T_g Q f \\<ge> Some t'\"\n    \"\\<And>x t'' M. Q x = Some t'' \\<Longrightarrow>   t' \\<ge> t\" \n  shows \"T_g Q f \\<ge> Some (t::'a:: {complete_lattice,minus,plus})\" \n  oops\n\n\n \n\ndefinition \"monadic_WHILE b f s \\<equiv> do {\n  RECT (\\<lambda>D s. do { \n    bv \\<leftarrow> b s;\n    if bv then do {\n      s \\<leftarrow> f s;\n      D s\n    } else do {RETURNT s}\n  }) s\n}\"\ndefinition monadic_WHILEIE  where\n  \"monadic_WHILEIE I E bm c s = monadic_WHILE bm c s\" \n\nlemma monadic_WHILE_refine2: \n  assumes \n    \"(x, x') \\<in> R\"\n    \"\\<And>x x'. (x, x') \\<in> R \\<Longrightarrow> bm x \\<le> \\<Down>Id (bm' x')\"\n    and \"\\<And>x x' t. (x, x') \\<in> R \\<Longrightarrow> nofailT (bm' x') \\<Longrightarrow> inresT2 (bm' x') True t \\<Longrightarrow> c x \\<le> \\<Down>R (c' x')\"\n  shows \"(monadic_WHILE bm c x) \\<le> \\<Down>R (monadic_WHILE bm' c' x')\"\n  sorry\n\n\n\nfun Someplus where\n  \"Someplus None _ = None\"\n| \"Someplus _ None = None\"\n| \"Someplus (Some a) (Some b) = Some (a+b)\"\n\n\ndefinition mm22 :: \"( ('a\\<Rightarrow> enat) option) \\<Rightarrow> (   ('a\\<Rightarrow> enat) option) \\<Rightarrow> (   ('a\\<Rightarrow> enat) option)\" where\n  \"mm22 r m = (case m  of None \\<Rightarrow> Some \\<infinity>\n                                | Some mt \\<Rightarrow>\n                                  (case r of None \\<Rightarrow> None | Some rt \\<Rightarrow> (if mt \\<le> rt then Some (rt - mt) else None)))\"\n\n\nlemma \n  fixes s0 :: 'a and I :: \"'a \\<Rightarrow> bool\" and E :: \"'a \\<Rightarrow> ('c \\<Rightarrow> nat)\" and t :: \"'c \\<Rightarrow> enat\"\n  assumes\n  step: \"(\\<And>s. I s \\<Longrightarrow> Some 0 \\<le> T_g (\\<lambda>b. if b then T_g (\\<lambda>s'. if I s' \\<and> E s' \\<le> E s\n                   then Some ((\\<lambda>x. enat (E s x - E s' x))) else None)  (c s)\n                    else mm22 (Q s) (Someplus (Some t) (mm3 (enat o (E s0)) (Some (enat o (E s)))))) (bm s))\"\n and  progress: \"\\<And>s. progress (c s)\"\n and  i: \"I s0\"\nshows neueWhile_rule': \"Some t \\<le> T_g Q (monadic_WHILEIE I E bm c s0)\"\n  sorry\n\n\ndefinition \"G b d = (if b then Some d else None)\"\ndefinition \"H Qs t Es0 Es = mm22 Qs (Someplus (Some t) (mm3 (Es0) (Some (Es))))\"\n\n\nlemma \n  fixes s0 :: 'a and I :: \"'a \\<Rightarrow> bool\" and E :: \"'a \\<Rightarrow> ('c \\<Rightarrow> nat)\" and t :: \"'c \\<Rightarrow> enat\"\n  assumes\n  step: \"(\\<And>s. I s \\<Longrightarrow> Some 0 \\<le> T_g (\\<lambda>b. if b then T_g  (\\<lambda>s'. G (I s' \\<and> E s' \\<le> E s) (E s - E s')) (c s)\n               else H (Q s) t (E s0) (E s))  (bm s))\"\n and  progress: \"\\<And>s. progress (c s)\"\n and  i: \"I s0\"\nshows neueWhile_rule'': \"Some t \\<le> T_g Q (monadic_WHILEIE I E bm c s0)\"\n  apply(rule neueWhile_rule')  \n  unfolding monadic_WHILEIE_def \n  subgoal for s using step[of s] apply (simp add: ) unfolding H_def G_def o_def by (auto cong: if_cong)\n    using assms by auto \n\n\n\n\ndefinition [to_relAPP]: \"list_set_rel R \\<equiv> \\<langle>R\\<rangle>list_rel O br set distinct\"\n\n\n\nlemma le_ASSERTI_f:\n  fixes M :: \"(_,_ \\<Rightarrow> enat) nrest\"\n  shows \"(\\<Phi> \\<Longrightarrow> M \\<le> M') \\<Longrightarrow> M \\<le> ASSERT \\<Phi> \\<bind> (\\<lambda>_. M')\"\n  sorry\n\n\n\n\nsection \"some Monadic Refinement Automation\"\n\n\nML \\<open>\nstructure Refine = struct\n\n  structure vcg = Named_Thms\n    ( val name = @{binding refine_vcg}\n      val description = \"Refinement Framework: \" ^ \n        \"Verification condition generation rules (intro)\" )\n\n  structure vcg_cons = Named_Thms\n    ( val name = @{binding refine_vcg_cons}\n      val description = \"Refinement Framework: \" ^\n        \"Consequence rules tried by VCG\" )\n\n  structure refine0 = Named_Thms\n    ( val name = @{binding refine0}\n      val description = \"Refinement Framework: \" ^\n        \"Refinement rules applied first (intro)\" )\n\n  structure refine = Named_Thms\n    ( val name = @{binding refine}\n      val description = \"Refinement Framework: Refinement rules (intro)\" )\n\n  structure refine2 = Named_Thms\n    ( val name = @{binding refine2}\n      val description = \"Refinement Framework: \" ^\n        \"Refinement rules 2nd stage (intro)\" )\n\n  (* If set to true, the product splitter of refine_rcg is disabled. *)\n  val no_prod_split = \n    Attrib.setup_config_bool @{binding refine_no_prod_split} (K false);\n\n  fun rcg_tac add_thms ctxt = \n    let \n      val cons_thms = vcg_cons.get ctxt\n      val ref_thms = (refine0.get ctxt \n        @ add_thms @ refine.get ctxt @ refine2.get ctxt);\n      val prod_ss = (Splitter.add_split @{thm prod.split} \n        (put_simpset HOL_basic_ss ctxt));\n      val prod_simp_tac = \n        if Config.get ctxt no_prod_split then \n          K no_tac\n        else\n          (simp_tac prod_ss THEN' \n            REPEAT_ALL_NEW (resolve_tac ctxt @{thms impI allI}));\n    in\n      REPEAT_ALL_NEW_FWD (DETERM o FIRST' [\n        resolve_tac ctxt ref_thms,\n        resolve_tac ctxt cons_thms THEN' resolve_tac ctxt ref_thms,\n        prod_simp_tac\n      ])\n    end;\n\n  fun post_tac ctxt = REPEAT_ALL_NEW_FWD (FIRST' [\n    eq_assume_tac,\n    (*match_tac ctxt thms,*)\n    SOLVED' (Tagged_Solver.solve_tac ctxt)]) \n         \n\nend;\n\\<close>\nsetup \\<open>Refine.vcg.setup\\<close>\nsetup \\<open>Refine.vcg_cons.setup\\<close>\nsetup \\<open>Refine.refine0.setup\\<close>\nsetup \\<open>Refine.refine.setup\\<close>\nsetup \\<open>Refine.refine2.setup\\<close>\n(*setup {* Refine.refine_post.setup *}*)\n\nmethod_setup refine_rcg = \n  \\<open>Attrib.thms >> (fn add_thms => fn ctxt => SIMPLE_METHOD' (\n    Refine.rcg_tac add_thms ctxt THEN_ALL_NEW_FWD (TRY o Refine.post_tac ctxt)\n  ))\\<close> \n  \"Refinement framework: Generate refinement conditions\"     \n\nmethod_setup refine_vcg = \n  \\<open>Attrib.thms >> (fn add_thms => fn ctxt => SIMPLE_METHOD' (\n    Refine.rcg_tac (add_thms @ Refine.vcg.get ctxt) ctxt THEN_ALL_NEW_FWD (TRY o Refine.post_tac ctxt)\n  ))\\<close> \n  \"Refinement framework: Generate refinement and verification conditions\"\n\n\n\nsubsection \"setup for refine_vcg\"\n \nlemma If_refine_plain[refine]: \"b = b' \\<Longrightarrow>\n  (b \\<Longrightarrow> b' \\<Longrightarrow> S1 \\<le> \\<Down> R S1') \\<Longrightarrow>\n  (\\<not> b \\<Longrightarrow> \\<not> b' \\<Longrightarrow> S2 \\<le> \\<Down> R S2') \\<Longrightarrow> (if b then S1 else S2) \\<le> \\<Down> R (if b' then S1' else S2')\"\n  by auto\n\nlemma Case_option_refine[refine]: \"(x,x')\\<in> \\<langle>S\\<rangle>option_rel \\<Longrightarrow>\n  (\\<And>y y'. (y,y')\\<in>S \\<Longrightarrow> S2 y  \\<le> \\<Down> R (S2' y')) \\<Longrightarrow> S1 \\<le> \\<Down> R S1'\n  \\<Longrightarrow> (case x of None \\<Rightarrow> S1 | Some y \\<Rightarrow> S2 y) \\<le> \\<Down> R (case x' of None \\<Rightarrow> S1' | Some y' \\<Rightarrow> S2' y')\"\n  by(auto split: option.split)\n\nlemma [refine0]: \"\\<And>S. S \\<le> \\<Down> Id S\" by simp                                          \nlemma refine_plain_ASSERT_bind[refine0]:\n    \"\\<Phi> \\<Longrightarrow> (\\<Phi> \\<Longrightarrow> S \\<le> \\<Down> R S') \\<Longrightarrow> ASSERT \\<Phi> \\<bind> (\\<lambda>_. S) \\<le> \\<Down> R S'\"\n   sorry\n\n\nlemma le_R_ASSERTI: \"(\\<Phi> \\<Longrightarrow> M \\<le> \\<Down> R M') \\<Longrightarrow>  M \\<le> \\<Down> R (ASSERT \\<Phi> \\<bind> (\\<lambda>_. M'))\"\n  sorry\n\ndeclare le_R_ASSERTI [refine0]\n\nthm refine0\n\ndeclare bindT_refine [refine]\ndeclare WHILET_refine [refine]\nthm refine\nthm refine2\nthm refine_vcg\n\nlemma [refine_vcg_cons]: \"m \\<le> SPECT \\<Phi> \\<Longrightarrow> (\\<And>x. \\<Phi> x \\<le> \\<Psi> x) \\<Longrightarrow> m \\<le> SPECT \\<Psi>\"\n  by (metis dual_order.trans le_funI nres_order_simps(2))  \nthm refine_vcg_cons\n \n\n\n\nend", "meta": {"author": "maxhaslbeck", "repo": "Sepreftime", "sha": "c1c987b45ec886d289ba215768182ac87b82f20d", "save_path": "github-repos/isabelle/maxhaslbeck-Sepreftime", "path": "github-repos/isabelle/maxhaslbeck-Sepreftime/Sepreftime-c1c987b45ec886d289ba215768182ac87b82f20d/moreCurr/MoreCurrAutomation.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.258717594069634}}
{"text": "(*  Title:      HOL/Library/Phantom_Type.thy\n    Author:     Andreas Lochbihler\n*)\n\nsection \\<open>A generic phantom type\\<close>\n\ntheory Phantom_Type\nimports \"MainRLT\"\nbegin\n\ndatatype ('a, 'b) phantom = phantom (of_phantom: 'b)\n\nlemma type_definition_phantom': \"type_definition of_phantom phantom UNIV\"\nby(unfold_locales) simp_all\n\nlemma phantom_comp_of_phantom [simp]: \"phantom \\<circ> of_phantom = id\"\n  and of_phantom_comp_phantom [simp]: \"of_phantom \\<circ> phantom = id\"\nby(simp_all add: o_def id_def)\n\nsyntax \"_Phantom\" :: \"type \\<Rightarrow> logic\" (\"(1Phantom/(1'(_')))\")\ntranslations\n  \"Phantom('t)\" => \"CONST phantom :: _ \\<Rightarrow> ('t, _) phantom\"\n\ntyped_print_translation \\<open>\n  let\n    fun phantom_tr' ctxt (Type (\\<^type_name>\\<open>fun\\<close>, [_, Type (\\<^type_name>\\<open>phantom\\<close>, [T, _])])) ts =\n          list_comb\n            (Syntax.const \\<^syntax_const>\\<open>_Phantom\\<close> $ Syntax_Phases.term_of_typ ctxt T, ts)\n      | phantom_tr' _ _ _ = raise Match;\n  in [(\\<^const_syntax>\\<open>phantom\\<close>, phantom_tr')] end\n\\<close>\n\nlemma of_phantom_inject [simp]:\n  \"of_phantom x = of_phantom y \\<longleftrightarrow> x = y\"\nby(cases x y rule: phantom.exhaust[case_product phantom.exhaust]) simp\n\nend\n", "meta": {"author": "dtraytel", "repo": "HOLRLT", "sha": "e9029da59bb3af0c835604a65308498f9696a364", "save_path": "github-repos/isabelle/dtraytel-HOLRLT", "path": "github-repos/isabelle/dtraytel-HOLRLT/HOLRLT-e9029da59bb3af0c835604a65308498f9696a364/HOLRLT/Library/Phantom_Type.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632831725051, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.25871759406963396}}
{"text": "(******************************************************************************)\n(* Project: The Isabelle/UTP Proof System                                     *)\n(* File: Interlocking.thy                                                     *)\n(* Authors: Frank Zeyda and Simon Foster (University of York, UK)             *)\n(* Emails: frank.zeyda@york.ac.uk and simon.foster@york.ac.uk                 *)\n(******************************************************************************)\n(* LAST REVIEWED: 22 Sep 2017 *)\n\nsection {* Interlocking FMU Model *}\n\ntheory Interlocking\nimports Vector Topology utp_hoare_ext\nbegin recall_syntax\n\n(* declare One_nat_def [simp del] *)\n\nlemma inv_subst_weakening_lemma:\n\"`I \\<Rightarrow> s \\<dagger> I` \\<Longrightarrow> `I \\<and> P \\<Rightarrow> s \\<dagger> I`\"\napply (rel_simp)\ndone\n\nsubsection {* Interlocking State *}\n\nalphabet ilock_state =\n  cdv :: \"bool vector\"\n  tc :: \"bool vector\"\n  relays :: \"bool vector\"\n  signals :: \"bool vector\"\n  switches :: \"switch vector\"\n\ntext \\<open>Convenience syntax for indexed access of @{const cdv}.\\<close>\n\nabbreviation CDV :: \"nat \\<Rightarrow> (bool, ilock_state) uexpr\" (\"CDV[_]\") where\n\"CDV[i] \\<equiv> &cdv[i]\\<^sub>u\"\n\ntext \\<open>Convenience syntax for indexed access of @{const tc}.\\<close>\n\nabbreviation TC :: \"nat \\<Rightarrow> (bool, ilock_state) uexpr\" (\"TC[_]\") where\n\"TC[i] \\<equiv> &tc[i]\\<^sub>u\"\n\ntext \\<open>Convenience syntax for accessing elements of @{const relays}.\\<close>\n\nabbreviation \"R1 \\<equiv> &relays[1]\\<^sub>u\"\nabbreviation \"R2 \\<equiv> &relays[2]\\<^sub>u\"\nabbreviation \"R3 \\<equiv> &relays[3]\\<^sub>u\"\nabbreviation \"R4 \\<equiv> &relays[4]\\<^sub>u\"\nabbreviation \"R5 \\<equiv> &relays[5]\\<^sub>u\"\n\ntext \\<open>Convenience syntax for accessing elements of @{const switches}.\\<close>\n\nabbreviation \"SW1 \\<equiv> &switches[1]\\<^sub>u\"\nabbreviation \"SW2 \\<equiv> &switches[2]\\<^sub>u\"\nabbreviation \"SW3 \\<equiv> &switches[3]\\<^sub>u\"\nabbreviation \"SW4 \\<equiv> &switches[4]\\<^sub>u\"\nabbreviation \"SW5 \\<equiv> &switches[5]\\<^sub>u\"\n\nsubsection {* Proof Support *}\n\ntext \\<open>Interpretations for the @{type ilock_state} alphabet type.\\<close>\n\ninterpretation ilock_var_interp1:\n  lens_interp \"\\<lambda>r. (cdv\\<^sub>v r, tc\\<^sub>v r, relays\\<^sub>v r, signals\\<^sub>v r, switches\\<^sub>v r, more r)\"\napply (unfold_locales)\napply (rule injI)\napply (clarsimp)\ndone\n\ninterpretation ilock_var_interp2:\n  lens_interp \"\\<lambda>(r, r'). (cdv\\<^sub>v r, cdv\\<^sub>v r', tc\\<^sub>v r, tc\\<^sub>v r', relays\\<^sub>v r, relays\\<^sub>v r',\n    signals\\<^sub>v r, signals\\<^sub>v r', switches\\<^sub>v r, switches\\<^sub>v r', more r, more r')\"\napply (unfold_locales)\napply (rule injI)\napply (clarsimp)\ndone\n\nsubsection {* Initial State *}\n\ndefinition init_ilock :: \"ilock_state hrel\" where [urel_defs]:\n\"init_ilock =\n  ((cdv, tc, relays, signals, switches) := (\n    mk_vector\\<^sub>u 11 true,\n    mk_vector\\<^sub>u 4 false,\n    mk_vector\\<^sub>u 5 false,\n    mk_vector\\<^sub>u 3 false,\n    vector_from_list\\<^sub>u [STRAIGHT, DIVERGING, DIVERGING, STRAIGHT, DIVERGING]))\"\n\nsubsection {* Cyclic Behaviour *}\n\ntext \\<open>We break down the cyclic behaviour into four separate operations.\\<close>\n\nsubsubsection {* Relay Setting *}\n\ndefinition set_relays :: \"ilock_state hrel\" where\n[urel_defs]: \"set_relays =\n  ((relays[1] := true) \\<triangleleft> TC[4] \\<and> \\<not> TC[3] \\<and> \\<not> R2 \\<and> \\<not> R4 \\<and> (*\\<not> CDV[3] \\<and>*) CDV[4] \\<and> CDV[5] \\<triangleright>\\<^sub>r II) ;;\n  ((relays[2] := true) \\<triangleleft> TC[3] \\<and> \\<not> TC[4] \\<and> \\<not> R1 \\<and> \\<not> R3 \\<and> \\<not> R4 \\<and> \\<not> R5 \\<and> (*\\<not> CDV[3] \\<and>*) CDV[4] \\<and> CDV[8] \\<and> CDV[9] \\<and> CDV[10] \\<and> CDV[1] \\<triangleright>\\<^sub>r II) ;;\n  ((relays[4] := true) \\<triangleleft> TC[3] \\<and> \\<not> TC[4] \\<and> \\<not> R1 \\<and> \\<not> R2 \\<and> \\<not> R3 \\<and> \\<not> R5 \\<and> (*\\<not> CDV[3] \\<and>*) CDV[4] \\<and> CDV[8] \\<and> CDV[9] \\<and> CDV[11] \\<and> CDV[2] \\<triangleright>\\<^sub>r II) ;;\n  ((relays[3] := true) \\<triangleleft> TC[1] \\<and> \\<not> R2 \\<and> \\<not> R4 \\<and> \\<not> R5 \\<and> (*\\<not> CDV[1] \\<and>*) CDV[10] \\<and> CDV[9] \\<and> CDV[8] \\<and> CDV[7] \\<and> CDV[6] \\<triangleright>\\<^sub>r II) ;;\n  ((relays[5] := true) \\<triangleleft> TC[2] \\<and> \\<not> R2 \\<and> \\<not> R3 \\<and> \\<not> R4 \\<and> (*\\<not> CDV[2] \\<and>*) CDV[11] \\<and> CDV[9] \\<and> CDV[8] \\<and> CDV[7] \\<and> CDV[6] \\<triangleright>\\<^sub>r II)\"\n\nsubsubsection {* Relay Clearing *}\n\ndefinition clear_relays :: \"ilock_state hrel\" where\n[urel_defs]: \"clear_relays =\n  ((relays[1] := false) \\<triangleleft> R1 \\<and> \\<not> CDV[5] \\<triangleright>\\<^sub>r II) ;;\n  ((relays[2] := false) \\<triangleleft> R2 \\<and> \\<not> CDV[1] \\<triangleright>\\<^sub>r II) ;;\n  ((relays[3] := false) \\<triangleleft> R3 \\<and> \\<not> CDV[6] \\<triangleright>\\<^sub>r II) ;;\n  ((relays[4] := false) \\<triangleleft> R4 \\<and> \\<not> CDV[2] \\<triangleright>\\<^sub>r II) ;;\n  ((relays[5] := false) \\<triangleleft> R5 \\<and> \\<not> CDV[6] \\<triangleright>\\<^sub>r II)\"\n\nsubsubsection {* Switch Setting *}\n\ndefinition set_switches :: \"ilock_state hrel\" where\n[urel_defs]: \"set_switches = (\n  (switches[1] := \\<guillemotleft>STRAIGHT\\<guillemotright>) ;;\n  ((switches[2] := \\<guillemotleft>STRAIGHT\\<guillemotright>) \\<triangleleft> R3 \\<or> R5 \\<triangleright>\\<^sub>r (switches[2] := \\<guillemotleft>DIVERGING\\<guillemotright>)) ;;\n  ((switches[3] := \\<guillemotleft>STRAIGHT\\<guillemotright>) \\<triangleleft> R1 \\<triangleright>\\<^sub>r (switches[3] := \\<guillemotleft>DIVERGING\\<guillemotright>)) ;;\n  (switches[4] := \\<guillemotleft>STRAIGHT\\<guillemotright>) ;;\n  ((switches[5] := \\<guillemotleft>STRAIGHT\\<guillemotright>) \\<triangleleft> R2 \\<or> R3 \\<triangleright>\\<^sub>r (switches[5] := \\<guillemotleft>DIVERGING\\<guillemotright>)))\"\n\nsubsubsection {* Signal Setting *}\n\ndefinition set_signals :: \"ilock_state hrel\" where\n[urel_defs]: \"set_signals = (\n  (signals[1] := (R3 \\<and> SW5 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright> \\<and> SW2 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright> \\<and> SW4 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright>)) ;;\n  (signals[2] := (R5 \\<and> SW5 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright> \\<and> SW2 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright> \\<and> SW4 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright>)) ;;\n  (signals[3] := ((R1 \\<and> SW1 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright> \\<and> SW3 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright>) \\<or>\n    (R2 \\<and> SW1 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright> \\<and> SW3 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright> \\<and> SW2 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright> \\<and> SW5 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright>) \\<or>\n    (R4 \\<and> SW1 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright> \\<and> SW3 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright> \\<and> SW2 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright> \\<and> SW5 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright>))))\"\n\nsubsubsection {* Complete Cycle *}\n\ndefinition ilock_cycle :: \"ilock_state hrel\" where [urel_defs]:\n\"ilock_cycle = (set_relays ;; clear_relays ;; set_switches ;; set_signals)\"\n\nsubsection {* Invariants *}\n\ntext \\<open>We next prove several invariants of the interlocking model.\\<close>\n\nsubsubsection {* Type Invariant *}\n\ntext \\<open>The type invariant establishes that all vectors have the correct size.\\<close>\n\ndefinition ilock_type_inv :: \"ilock_state upred\" where [urel_defs]:\n\"ilock_type_inv = (\n  #\\<^sub>u(&cdv) =\\<^sub>u 11 \\<and>\n  #\\<^sub>u(&tc) =\\<^sub>u 4 \\<and>\n  #\\<^sub>u(&relays) =\\<^sub>u 5 \\<and>\n  #\\<^sub>u(&signals) =\\<^sub>u 3 \\<and>\n  #\\<^sub>u(&switches) =\\<^sub>u 5)\"\n\ntext {* Method for proving the interlocking type invariant. *}\n\nlemma ilock_type_inv_rules:\n\"\\<lbrace>ilock_type_inv\\<rbrace>S\\<lbrace>ilock_type_inv\\<rbrace>\\<^sub>u \\<Longrightarrow>\n \\<lbrace>ilock_type_inv \\<and> P\\<rbrace>S\\<lbrace>ilock_type_inv\\<rbrace>\\<^sub>u\"\n\"`ilock_type_inv \\<Rightarrow> s \\<dagger> ilock_type_inv` \\<Longrightarrow>\n `ilock_type_inv \\<and> P \\<Rightarrow> s \\<dagger> ilock_type_inv`\"\napply (rel_simp)\napply (erule inv_subst_weakening_lemma)\ndone\n\ntext {* The tactic below is a bit quicker than @{method hoare_auto}. *}\n\nmethod ilock_type_inv_tac =\n  (hoare_split_inv add: ilock_type_inv_rules; rel_simp)\n\nlemma init_ilock_type_inv:\n\"\\<lbrace>true\\<rbrace>init_ilock\\<lbrace>ilock_type_inv\\<rbrace>\\<^sub>u\"\napply (rel_simp)\ndone\n\nlemma set_relays_type_inv:\n\"\\<lbrace>ilock_type_inv\\<rbrace>set_relays\\<lbrace>ilock_type_inv\\<rbrace>\\<^sub>u\"\n(* unfolding set_relays_def by (hoare_auto) *)\n  unfolding set_relays_def by (ilock_type_inv_tac)\n\nlemma clear_relays_type_inv:\n\"\\<lbrace>ilock_type_inv\\<rbrace>clear_relays\\<lbrace>ilock_type_inv\\<rbrace>\\<^sub>u\"\n(* unfolding clear_relays_def by (hoare_auto) *)\n  unfolding clear_relays_def by (ilock_type_inv_tac)\n\nlemma set_switches_type_inv:\n\"\\<lbrace>ilock_type_inv\\<rbrace>set_switches\\<lbrace>ilock_type_inv\\<rbrace>\\<^sub>u\"\n(* unfolding set_switches_def by (hoare_auto) *)\n  unfolding set_switches_def by (ilock_type_inv_tac)\n\nlemma set_signals_type_inv:\n\"\\<lbrace>ilock_type_inv\\<rbrace>set_signals\\<lbrace>ilock_type_inv\\<rbrace>\\<^sub>u\"\n(* unfolding set_signals_def by (hoare_auto) *)\n  unfolding set_signals_def by (ilock_type_inv_tac)\n\nlemma \"\\<lbrace>ilock_type_inv\\<rbrace>ilock_cycle\\<lbrace>ilock_type_inv\\<rbrace>\\<^sub>u\"\napply (unfold ilock_cycle_def)\napply (hoare_split)\napply (rule set_relays_type_inv)\napply (rule clear_relays_type_inv)\napply (rule set_switches_type_inv)\napply (rule set_signals_type_inv)\ndone\n\nsubsubsection {* Relays Invariant *}\n\ntext \\<open>Ensures that at most one relay can be activated at a time.\\<close>\n\ndefinition relays_inv :: \"ilock_state upred\" where [upred_defs]:\n\"relays_inv = (\n  (#\\<^sub>u(&relays) =\\<^sub>u 5) \\<and>\n  (R1 \\<Rightarrow> \\<not> R2 \\<and> \\<not> R4) \\<and>\n  (R2 \\<Rightarrow> \\<not> R1 \\<and> \\<not> R3 \\<and> \\<not> R4 \\<and> \\<not> R5) \\<and>\n  (R4 \\<Rightarrow> \\<not> R1 \\<and> \\<not> R2 \\<and> \\<not> R3 \\<and> \\<not> R5) \\<and>\n  (R3 \\<Rightarrow> \\<not> R2 \\<and> \\<not> R4 \\<and> \\<not> R5) \\<and>\n  (R5 \\<Rightarrow> \\<not> R2 \\<and> \\<not> R3 \\<and> \\<not> R4))\"\n\nparagraph {* Proof Support *}\n\ndefinition valid_relay_states :: \"(bool vector) set\" where\n\"valid_relay_states =\n vector_from_list ` {\n  [OFF, OFF, OFF, OFF, OFF],\n  [ON, OFF, OFF, OFF, OFF],\n  [ON, OFF, OFF, OFF, ON],\n  [ON, OFF, ON, OFF, OFF],\n  [OFF, ON, OFF, OFF, OFF],\n  [OFF, OFF, ON, OFF, OFF],\n  [ON, OFF, ON, OFF, OFF],\n  [OFF, OFF, OFF, ON, OFF],\n  [OFF, OFF, OFF, OFF, ON],\n  [ON, OFF, OFF, OFF, ON]}\"\n\nlemma eq_vector_from_list_5:\n\"size v = 5 \\<Longrightarrow>\n  (v = vector_from_list [b1, b2, b3, b4, b5]) =\n  (v\\<^bold>[1\\<^bold>] = b1 \\<and> v\\<^bold>[2\\<^bold>] = b2 \\<and> v\\<^bold>[3\\<^bold>] = b3 \\<and> v\\<^bold>[4\\<^bold>] = b4 \\<and> v\\<^bold>[5\\<^bold>] = b5)\"\napply (subst vector_equality)\napply (clarsimp)\napply (safe; clarsimp)\napply (subgoal_tac \"i \\<in> {1, 2, 3, 4, 5}\")\napply (safe; clarsimp)\napply (safe; clarsimp)\ndone\n\nlemma relays_inv_cases:\n\"relays_inv = (&relays \\<in>\\<^sub>u \\<guillemotleft>valid_relay_states\\<guillemotright>)\"\napply (unfold relays_inv_def)\napply (rel_simp)\napply (safe; clarsimp?)\napply (unfold valid_relay_states_def)\napply (simp_all add: eq_vector_from_list_5)\napply (safe; clarsimp)+\ndone\n\nlemma relays_inv_split:\n\"`relays_inv \\<Rightarrow> P` = `\\<^bold>\\<forall> v\\<in>\\<guillemotleft>valid_relay_states\\<guillemotright> \\<bullet> P\\<lbrakk>\\<guillemotleft>v\\<guillemotright> / &relays\\<rbrakk>`\"\napply (unfold relays_inv_cases)\napply (pred_simp robust)\napply (safe; clarsimp)\ndone\n\nlemma relays_inv_extr:\n\"`relays_inv \\<and> P \\<Rightarrow> Q` = `relays_inv \\<Rightarrow> P \\<Rightarrow> Q`\"\n  by (simp add: impl_alt_def utp_pred_laws.sup.assoc)\n\nlemma hoare_relays_inv_split:\n\"(\\<And>rs. rs \\<in> valid_relay_states \\<Longrightarrow> \\<lbrace>ilock_type_inv\\<rbrace>S\\<lbrakk>\\<guillemotleft>rs\\<guillemotright>/$relays\\<rbrakk>\\<lbrace>I\\<rbrace>\\<^sub>u) \\<Longrightarrow>\n \\<lbrace>ilock_type_inv \\<and> relays_inv\\<rbrace>S\\<lbrace>I\\<rbrace>\\<^sub>u\"\napply (unfold relays_inv_cases)\napply (rel_simp)\ndone\n\nmethod hoare_relays_inv_tac = (\n  (rule hoare_relays_inv_split),\n  (unfold valid_relay_states_def),\n  (clarsimp; safe))\n\ntext {* Do \\<open>,\\<close>  and \\<open>;\\<close> have the same precedence? Are they right-associative? *}\n\nmethod ilock_relays_inv_tac =\n  (hoare_split_inv; (\n    (unfold relays_inv_extr)?,\n    (unfold relays_inv_cases),\n    (rel_simp);\n    (unfold valid_relay_states_def),\n    (safe; simp)))\n\nparagraph {* Invariant Preservation *}\n\nlemma init_ilock_relays_inv:\n\"\\<lbrace>true\\<rbrace>init_ilock\\<lbrace>relays_inv\\<rbrace>\\<^sub>u\"\n  unfolding init_ilock_def by (rel_simp)\n\nlemma set_relays_relays_inv:\n\"\\<lbrace>relays_inv\\<rbrace>set_relays\\<lbrace>relays_inv\\<rbrace>\\<^sub>u\"\n  unfolding set_relays_def by (ilock_relays_inv_tac)\n\nlemma clear_relays_relays_inv:\n\"\\<lbrace>relays_inv\\<rbrace>clear_relays\\<lbrace>relays_inv\\<rbrace>\\<^sub>u\"\n  unfolding clear_relays_def by (ilock_relays_inv_tac)\n\nlemma set_switches_relays_inv:\n\"\\<lbrace>relays_inv\\<rbrace>set_switches\\<lbrace>relays_inv\\<rbrace>\\<^sub>u\"\n  unfolding set_switches_def by (ilock_relays_inv_tac)\n\nlemma set_signals_relays_inv:\n\"\\<lbrace>relays_inv\\<rbrace>set_signals\\<lbrace>relays_inv\\<rbrace>\\<^sub>u\"\n  unfolding set_signals_def by (ilock_relays_inv_tac)\n\nlemma \"\\<lbrace>relays_inv\\<rbrace>ilock_cycle\\<lbrace>relays_inv\\<rbrace>\\<^sub>u\"\napply (unfold ilock_cycle_def)\napply (hoare_split)\napply (rule set_relays_relays_inv)\napply (rule clear_relays_relays_inv)\napply (rule set_switches_relays_inv)\napply (rule set_signals_relays_inv)\ndone\n\nsubsection {* Switches Invariant *}\n\n(*\ndefinition switches_inv :: \"ilock_state upred\" where\n[urel_defs]: \"switches_inv = (\n  (#\\<^sub>u(&switches) =\\<^sub>u 5) \\<and>\n  (SW1 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright>) \\<and>\n  ((SW2 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright>) \\<triangleleft> R3 \\<or> R5 \\<triangleright> (SW2 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright>)) \\<and>\n  ((SW3 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright>) \\<triangleleft> R1 \\<triangleright> (SW3 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright>)) \\<and>\n  (SW4 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright>) \\<and>\n  ((SW5 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright>) \\<triangleleft> R2 \\<or> R3 \\<triangleright> (SW5 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright>))\n)\"\n*)\n\ndefinition switches_inv :: \"ilock_state upred\" where\n[urel_defs]: \"switches_inv = (\n  (#\\<^sub>u(&switches) =\\<^sub>u 5) \\<and>\n  (R1 \\<Rightarrow> SW1 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright> \\<and> SW3 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright>) \\<and>\n  (R2 \\<Rightarrow> SW1 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright> \\<and> SW2 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright> \\<and> SW3 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright> \\<and> SW5 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright>) \\<and>\n  (R3 \\<Rightarrow> SW2 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright> \\<and> SW4 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright> \\<and> SW5 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright>) \\<and>\n  (R4 \\<Rightarrow> SW1 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright> \\<and> SW2 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright> \\<and> SW3 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright> \\<and> SW5 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright>) \\<and>\n  (R5 \\<Rightarrow> SW2 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright> \\<and> SW4 =\\<^sub>u \\<guillemotleft>STRAIGHT\\<guillemotright> \\<and> SW5 =\\<^sub>u \\<guillemotleft>DIVERGING\\<guillemotright>)\n)\"\n\nlemma switches_inv_rules:\n\"`switches_inv \\<Rightarrow> s \\<dagger> switches_inv` \\<Longrightarrow>\n `switches_inv \\<and> P \\<Rightarrow> s \\<dagger> switches_inv`\"\napply (erule inv_subst_weakening_lemma)\ndone\n\nlemma init_ilock_switches_inv:\n\"\\<lbrace>true\\<rbrace>init_ilock\\<lbrace>switches_inv\\<rbrace>\\<^sub>u\"\n  unfolding init_ilock_def by (rel_simp)\n\n(***********************)\n(* REVIEWED UNTIL HERE *)\n(***********************)\n\nlemma set_switches_subst_relay_simps:\n\"(switches := e ;; S)\\<lbrakk>\\<guillemotleft>f\\<guillemotright>/$relays\\<rbrakk> =\n (switches := e\\<lbrakk>\\<guillemotleft>f\\<guillemotright>/&relays\\<rbrakk> ;; (S\\<lbrakk>\\<guillemotleft>f\\<guillemotright>/$relays\\<rbrakk>))\"\n\"((switches := e1 \\<triangleleft> b \\<triangleright>\\<^sub>r switches := e2) ;; R)\\<lbrakk>\\<guillemotleft>f\\<guillemotright>/$relays\\<rbrakk> =\n ((switches := e1\\<lbrakk>\\<guillemotleft>f\\<guillemotright>/&relays\\<rbrakk> \\<triangleleft> b\\<lbrakk>\\<guillemotleft>f\\<guillemotright>/&relays\\<rbrakk> \\<triangleright>\\<^sub>r switches := e2\\<lbrakk>\\<guillemotleft>f\\<guillemotright>/&relays\\<rbrakk>) ;; R\\<lbrakk>\\<guillemotleft>f\\<guillemotright>/$relays\\<rbrakk>)\"\napply (rel_auto)+\napply (blast)+\ndone\n\nlemma switches_assign_lemma:\n\"switches := (&switches(i \\<mapsto> \\<guillemotleft>v\\<guillemotright>)\\<^sub>u)\\<lbrakk>\\<guillemotleft>e\\<guillemotright>/&relays\\<rbrakk> =\n switches := (&switches(i\\<lbrakk>\\<guillemotleft>e\\<guillemotright>/&relays\\<rbrakk> \\<mapsto> \\<guillemotleft>v\\<guillemotright>)\\<^sub>u)\"\napply (rel_auto)\ndone\n\nlemma more_simps:\n\"(s \\<dagger> (1::(nat, '\\<alpha>) uexpr)) = 1\"\n\"(s \\<dagger> (2::(nat, '\\<alpha>) uexpr)) = 2\"\n\"(s \\<dagger> (3::(nat, '\\<alpha>) uexpr)) = 3\"\n\"(s \\<dagger> (4::(nat, '\\<alpha>) uexpr)) = 4\"\n\"(s \\<dagger> (5::(nat, '\\<alpha>) uexpr)) = 5\"\n\"i \\<in> {1..length l} \\<Longrightarrow> \\<guillemotleft>vector_from_list l\\<guillemotright>(\\<guillemotleft>i\\<guillemotright>)\\<^sub>a = \\<guillemotleft>l ! (i - 1)\\<guillemotright>\"\n\"(S \\<triangleleft> \\<guillemotleft>True\\<guillemotright> \\<triangleright>\\<^sub>r T) = S\"\n\"(S \\<triangleleft> \\<guillemotleft>False \\<guillemotright>\\<triangleright>\\<^sub>r T) = T\"\napply (rel_simp)+\ndone\n\nlemma\n\"\\<lbrace>ilock_type_inv\\<rbrace>set_switches\\<lbrakk>\\<guillemotleft>rs\\<guillemotright>/$relays\\<rbrakk>\\<lbrace>I\\<rbrace>\\<^sub>u =\n \\<lbrace>ilock_type_inv\\<rbrace>set_switches\\<lbrakk>\\<guillemotleft>rs\\<guillemotright>/$relays\\<rbrakk>\\<lbrace>I\\<lbrakk>\\<guillemotleft>rs\\<guillemotright>/&relays\\<rbrakk>\\<rbrace>\\<^sub>u\"\napply (rel_simp robust)\nsledgehammer\noops\n\nlemma set_switches_switches_inv:\n\"\\<lbrace>ilock_type_inv \\<and> relays_inv\\<rbrace>set_switches\\<lbrace>switches_inv\\<rbrace>\\<^sub>u\"\napply (hoare_relays_inv_tac)\napply (unfold set_switches_def)\napply (simp_all only: set_switches_subst_relay_simps)\napply (simp_all add: switches_assign_lemma more_simps usubst unrest)\napply (unfold switches_inv_def)\napply (hoare_split_inv)\n\nprofile (rel_simp robust)+\ndone\n\n(***********************)\n(* REVIEWED UNTIL HERE *)\n(***********************)\n\nsubsection {* Signals Invariant *}\n\ndefinition signals_inv :: \"ilock_state upred\" where [upred_defs]:\n\"signals_inv = (\n  (#\\<^sub>u(&signals) =\\<^sub>u 3) \\<and>\n  (R3 \\<Leftrightarrow> &signals[1]\\<^sub>u) \\<and>\n  (R5 \\<Leftrightarrow> &signals[2]\\<^sub>u) \\<and>\n  ((R1 \\<or> R2 \\<or> R4) \\<Leftrightarrow> &signals[3]\\<^sub>u))\"\n\nparagraph {* Invariant Preservation *}\n\nlemma init_ilock_signals_inv:\n\"\\<lbrace>true\\<rbrace>init_ilock\\<lbrace>signals_inv\\<rbrace>\\<^sub>u\"\n  unfolding init_ilock_def by (rel_simp)\n\ntext {* I think we have to prove the switches invariant first...! *}\n\nlemma set_relays_signals_inv:\n\"\\<lbrace>ilock_type_inv\\<rbrace>set_switches ;; set_signals\\<lbrace>signals_inv\\<rbrace>\\<^sub>u\"\noops\n\nsubsection {* Proof Experiments *}\n\nlemma uvector_from_list_simps [simp]:\n\"i \\<in> {1..length l} \\<Longrightarrow> (vector_from_list\\<^sub>u l)[i]\\<^sub>u = \\<guillemotleft>l ! (i - 1)\\<guillemotright>\"\napply (pred_simp)\ndone\nend", "meta": {"author": "isabelle-utp", "repo": "utp-main", "sha": "27bdf3aee6d4fc00c8fe4d53283d0101857e0d41", "save_path": "github-repos/isabelle/isabelle-utp-utp-main", "path": "github-repos/isabelle/isabelle-utp-utp-main/utp-main-27bdf3aee6d4fc00c8fe4d53283d0101857e0d41/fmi/Interlocking.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632831725051, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.25871759406963396}}
{"text": "(*  Title:      HOL/TLA/Memory/Memory.thy\n    Author:     Stephan Merz, University of Munich\n*)\n\nsection {* RPC-Memory example: Memory specification *}\n\ntheory Memory\nimports MemoryParameters ProcedureInterface\nbegin\n\ntype_synonym memChType = \"(memOp, Vals) channel\"\ntype_synonym memType = \"(Locs => Vals) stfun\"  (* intention: MemLocs => MemVals *)\ntype_synonym resType = \"(PrIds => Vals) stfun\"\n\nconsts\n  (* state predicates *)\n  MInit      :: \"memType => Locs => stpred\"\n  PInit      :: \"resType => PrIds => stpred\"\n  (* auxiliary predicates: is there a pending read/write request for\n     some process id and location/value? *)\n  RdRequest  :: \"memChType => PrIds => Locs => stpred\"\n  WrRequest  :: \"memChType => PrIds => Locs => Vals => stpred\"\n\n  (* actions *)\n  GoodRead   :: \"memType => resType => PrIds => Locs => action\"\n  BadRead    :: \"memType => resType => PrIds => Locs => action\"\n  ReadInner  :: \"memChType => memType => resType => PrIds => Locs => action\"\n  Read       :: \"memChType => memType => resType => PrIds => action\"\n  GoodWrite  :: \"memType => resType => PrIds => Locs => Vals => action\"\n  BadWrite   :: \"memType => resType => PrIds => Locs => Vals => action\"\n  WriteInner :: \"memChType => memType => resType => PrIds => Locs => Vals => action\"\n  Write      :: \"memChType => memType => resType => PrIds => Locs => action\"\n  MemReturn  :: \"memChType => resType => PrIds => action\"\n  MemFail    :: \"memChType => resType => PrIds => action\"\n  RNext      :: \"memChType => memType => resType => PrIds => action\"\n  UNext      :: \"memChType => memType => resType => PrIds => action\"\n\n  (* temporal formulas *)\n  RPSpec     :: \"memChType => memType => resType => PrIds => temporal\"\n  UPSpec     :: \"memChType => memType => resType => PrIds => temporal\"\n  MSpec      :: \"memChType => memType => resType => Locs => temporal\"\n  IRSpec     :: \"memChType => memType => resType => temporal\"\n  IUSpec     :: \"memChType => memType => resType => temporal\"\n\n  RSpec      :: \"memChType => resType => temporal\"\n  USpec      :: \"memChType => temporal\"\n\n  (* memory invariant: in the paper, the invariant is hidden in the definition of\n     the predicate S used in the implementation proof, but it is easier to verify\n     at this level. *)\n  MemInv    :: \"memType => Locs => stpred\"\n\ndefs\n  MInit_def:         \"MInit mm l == PRED mm!l = #InitVal\"\n  PInit_def:         \"PInit rs p == PRED rs!p = #NotAResult\"\n\n  RdRequest_def:     \"RdRequest ch p l == PRED\n                         Calling ch p & (arg<ch!p> = #(read l))\"\n  WrRequest_def:     \"WrRequest ch p l v == PRED\n                         Calling ch p & (arg<ch!p> = #(write l v))\"\n  (* a read that doesn't raise BadArg *)\n  GoodRead_def:      \"GoodRead mm rs p l == ACT\n                        #l : #MemLoc & ((rs!p)$ = $(mm!l))\"\n  (* a read that raises BadArg *)\n  BadRead_def:       \"BadRead mm rs p l == ACT\n                        #l ~: #MemLoc & ((rs!p)$ = #BadArg)\"\n  (* the read action with l visible *)\n  ReadInner_def:     \"ReadInner ch mm rs p l == ACT\n                         $(RdRequest ch p l)\n                         & (GoodRead mm rs p l  |  BadRead mm rs p l)\n                         & unchanged (rtrner ch ! p)\"\n  (* the read action with l quantified *)\n  Read_def:          \"Read ch mm rs p == ACT (EX l. ReadInner ch mm rs p l)\"\n\n  (* similar definitions for the write action *)\n  GoodWrite_def:     \"GoodWrite mm rs p l v == ACT\n                        #l : #MemLoc & #v : #MemVal\n                        & ((mm!l)$ = #v) & ((rs!p)$ = #OK)\"\n  BadWrite_def:      \"BadWrite mm rs p l v == ACT\n                        ~ (#l : #MemLoc & #v : #MemVal)\n                        & ((rs!p)$ = #BadArg) & unchanged (mm!l)\"\n  WriteInner_def:    \"WriteInner ch mm rs p l v == ACT\n                        $(WrRequest ch p l v)\n                        & (GoodWrite mm rs p l v  |  BadWrite mm rs p l v)\n                        & unchanged (rtrner ch ! p)\"\n  Write_def:         \"Write ch mm rs p l == ACT (EX v. WriteInner ch mm rs p l v)\"\n\n  (* the return action *)\n  MemReturn_def:     \"MemReturn ch rs p == ACT\n                       (   ($(rs!p) ~= #NotAResult)\n                        & ((rs!p)$ = #NotAResult)\n                        & Return ch p (rs!p))\"\n\n  (* the failure action of the unreliable memory *)\n  MemFail_def:       \"MemFail ch rs p == ACT\n                        $(Calling ch p)\n                        & ((rs!p)$ = #MemFailure)\n                        & unchanged (rtrner ch ! p)\"\n  (* next-state relations for reliable / unreliable memory *)\n  RNext_def:         \"RNext ch mm rs p == ACT\n                       (  Read ch mm rs p\n                        | (EX l. Write ch mm rs p l)\n                        | MemReturn ch rs p)\"\n  UNext_def:         \"UNext ch mm rs p == ACT\n                        (RNext ch mm rs p | MemFail ch rs p)\"\n\n  RPSpec_def:        \"RPSpec ch mm rs p == TEMP\n                        Init(PInit rs p)\n                        & [][ RNext ch mm rs p ]_(rtrner ch ! p, rs!p)\n                        & WF(RNext ch mm rs p)_(rtrner ch ! p, rs!p)\n                        & WF(MemReturn ch rs p)_(rtrner ch ! p, rs!p)\"\n  UPSpec_def:        \"UPSpec ch mm rs p == TEMP\n                        Init(PInit rs p)\n                        & [][ UNext ch mm rs p ]_(rtrner ch ! p, rs!p)\n                        & WF(RNext ch mm rs p)_(rtrner ch ! p, rs!p)\n                        & WF(MemReturn ch rs p)_(rtrner ch ! p, rs!p)\"\n  MSpec_def:         \"MSpec ch mm rs l == TEMP\n                        Init(MInit mm l)\n                        & [][ EX p. Write ch mm rs p l ]_(mm!l)\"\n  IRSpec_def:        \"IRSpec ch mm rs == TEMP\n                        (ALL p. RPSpec ch mm rs p)\n                        & (ALL l. #l : #MemLoc --> MSpec ch mm rs l)\"\n  IUSpec_def:        \"IUSpec ch mm rs == TEMP\n                        (ALL p. UPSpec ch mm rs p)\n                        & (ALL l. #l : #MemLoc --> MSpec ch mm rs l)\"\n\n  RSpec_def:         \"RSpec ch rs == TEMP (EEX mm. IRSpec ch mm rs)\"\n  USpec_def:         \"USpec ch == TEMP (EEX mm rs. IUSpec ch mm rs)\"\n\n  MemInv_def:        \"MemInv mm l == PRED  #l : #MemLoc --> mm!l : #MemVal\"\n\nlemmas RM_action_defs =\n  MInit_def PInit_def RdRequest_def WrRequest_def MemInv_def\n  GoodRead_def BadRead_def ReadInner_def Read_def\n  GoodWrite_def BadWrite_def WriteInner_def Write_def\n  MemReturn_def RNext_def\n\nlemmas UM_action_defs = RM_action_defs MemFail_def UNext_def\n\nlemmas RM_temp_defs = RPSpec_def MSpec_def IRSpec_def\nlemmas UM_temp_defs = UPSpec_def MSpec_def IUSpec_def\n\n\n(* The reliable memory is an implementation of the unreliable one *)\nlemma ReliableImplementsUnReliable: \"|- IRSpec ch mm rs --> IUSpec ch mm rs\"\n  by (force simp: UNext_def UPSpec_def IUSpec_def RM_temp_defs elim!: STL4E [temp_use] squareE)\n\n(* The memory spec implies the memory invariant *)\nlemma MemoryInvariant: \"|- MSpec ch mm rs l --> [](MemInv mm l)\"\n  by (auto_invariant simp: RM_temp_defs RM_action_defs)\n\n(* The invariant is trivial for non-locations *)\nlemma NonMemLocInvariant: \"|- #l ~: #MemLoc --> [](MemInv mm l)\"\n  by (auto simp: MemInv_def intro!: necT [temp_use])\n\nlemma MemoryInvariantAll:\n    \"|- (ALL l. #l : #MemLoc --> MSpec ch mm rs l) --> (ALL l. [](MemInv mm l))\"\n  apply clarify\n  apply (auto elim!: MemoryInvariant [temp_use] NonMemLocInvariant [temp_use])\n  done\n\n(* The memory engages in an action for process p only if there is an\n   unanswered call from p.\n   We need this only for the reliable memory.\n*)\n\nlemma Memoryidle: \"|- ~$(Calling ch p) --> ~ RNext ch mm rs p\"\n  by (auto simp: Return_def RM_action_defs)\n\n(* Enabledness conditions *)\n\nlemma MemReturn_change: \"|- MemReturn ch rs p --> <MemReturn ch rs p>_(rtrner ch ! p, rs!p)\"\n  by (force simp: MemReturn_def angle_def)\n\nlemma MemReturn_enabled: \"!!p. basevars (rtrner ch ! p, rs!p) ==>\n      |- Calling ch p & (rs!p ~= #NotAResult)\n         --> Enabled (<MemReturn ch rs p>_(rtrner ch ! p, rs!p))\"\n  apply (tactic\n    {* action_simp_tac @{context} [@{thm MemReturn_change} RSN (2, @{thm enabled_mono}) ] [] 1 *})\n  apply (tactic\n    {* action_simp_tac (@{context} addsimps [@{thm MemReturn_def}, @{thm Return_def},\n      @{thm rtrner_def}]) [exI] [@{thm base_enabled}, @{thm Pair_inject}] 1 *})\n  done\n\nlemma ReadInner_enabled: \"!!p. basevars (rtrner ch ! p, rs!p) ==>\n      |- Calling ch p & (arg<ch!p> = #(read l)) --> Enabled (ReadInner ch mm rs p l)\"\n  apply (case_tac \"l : MemLoc\")\n  apply (force simp: ReadInner_def GoodRead_def BadRead_def RdRequest_def\n    intro!: exI elim!: base_enabled [temp_use])+\n  done\n\nlemma WriteInner_enabled: \"!!p. basevars (mm!l, rtrner ch ! p, rs!p) ==>\n      |- Calling ch p & (arg<ch!p> = #(write l v))\n         --> Enabled (WriteInner ch mm rs p l v)\"\n  apply (case_tac \"l:MemLoc & v:MemVal\")\n  apply (force simp: WriteInner_def GoodWrite_def BadWrite_def WrRequest_def\n    intro!: exI elim!: base_enabled [temp_use])+\n  done\n\nlemma ReadResult: \"|- Read ch mm rs p & (!l. $(MemInv mm l)) --> (rs!p)` ~= #NotAResult\"\n  by (force simp: Read_def ReadInner_def GoodRead_def BadRead_def MemInv_def)\n\nlemma WriteResult: \"|- Write ch mm rs p l --> (rs!p)` ~= #NotAResult\"\n  by (auto simp: Write_def WriteInner_def GoodWrite_def BadWrite_def)\n\nlemma ReturnNotReadWrite: \"|- (ALL l. $MemInv mm l) & MemReturn ch rs p\n         --> ~ Read ch mm rs p & (ALL l. ~ Write ch mm rs p l)\"\n  by (auto simp: MemReturn_def dest!: WriteResult [temp_use] ReadResult [temp_use])\n\nlemma RWRNext_enabled: \"|- (rs!p = #NotAResult) & (!l. MemInv mm l)\n         & Enabled (Read ch mm rs p | (? l. Write ch mm rs p l))\n         --> Enabled (<RNext ch mm rs p>_(rtrner ch ! p, rs!p))\"\n  by (force simp: RNext_def angle_def elim!: enabled_mono2\n    dest: ReadResult [temp_use] WriteResult [temp_use])\n\n\n(* Combine previous lemmas: the memory can make a visible step if there is an\n   outstanding call for which no result has been produced.\n*)\nlemma RNext_enabled: \"!!p. !l. basevars (mm!l, rtrner ch!p, rs!p) ==>\n      |- (rs!p = #NotAResult) & Calling ch p & (!l. MemInv mm l)\n         --> Enabled (<RNext ch mm rs p>_(rtrner ch ! p, rs!p))\"\n  apply (auto simp: enabled_disj [try_rewrite] intro!: RWRNext_enabled [temp_use])\n  apply (case_tac \"arg (ch w p)\")\n   apply (tactic {* action_simp_tac (@{context} addsimps [@{thm Read_def},\n     temp_rewrite @{context} @{thm enabled_ex}]) [@{thm ReadInner_enabled}, exI] [] 1 *})\n   apply (force dest: base_pair [temp_use])\n  apply (erule contrapos_np)\n  apply (tactic {* action_simp_tac (@{context} addsimps [@{thm Write_def},\n    temp_rewrite @{context} @{thm enabled_ex}])\n    [@{thm WriteInner_enabled}, exI] [] 1 *})\n  done\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/TLA/Memory/Memory.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.665410558746814, "lm_q2_score": 0.38861802670584894, "lm_q1q2_score": 0.25859053828942324}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |               November 2004               |\n            |                   June 2005  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |                October 2005  (modified)   |\n            |                  April 2006  (modified)   |\n            |                January 2007  (modified)   |\n            |                  April 2007  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2007         |\n            |                January 2008  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2009         |\n            |                   June 2009  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2016         |\n            |                  April 2016  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory CSP_syntax\nimports Infra\nbegin\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite UnionT and InterT.                 *)\n(*                  Union (B ` A) = (UN x:A. B x)                      *)\n(*                  Inter (B ` A) = (INT x:A. B x)                     *)\n\n(* for Isabelle 2016\ndeclare Union_image_eq [simp del]\ndeclare Inter_image_eq [simp del]\n*)\n\n(*-----------------------------------------------------------*\n |                                                           |\n |    Process Type Definitions                               |\n |                                                           |\n |             'a proc : type of process expressions         |\n |                       'n : process name                   |\n |                       'a : event                          |\n |                                                           |\n *-----------------------------------------------------------*)\n\n(*********************************************************************\n                       process expression\n *********************************************************************)\n\ntype_synonym\n   'a sets_nats = \"('a set set, nat set) sum\"\ntype_synonym\n   'a aset_anat = \"('a set, nat) sum\"\n\ndatatype \n ('p,'a) proc\n    = STOP\n\n    | SKIP\n\n    | DIV\n\n    | Act_prefix     \"'a\" \"('p,'a) proc\"      (\"(1_ /-> _)\" [150,80] 80)\n\n    | Ext_pre_choice \"'a set\" \"'a => ('p,'a) proc\"\n                                               (\"(1? :_ /-> _)\" [900,80] 80)\n    | Ext_choice     \"('p,'a) proc\" \"('p,'a) proc\"  \n                                               (\"(1_ /[+] _)\" [72,73] 72)\n    | Int_choice     \"('p,'a) proc\" \"('p,'a) proc\"  \n                                               (\"(1_ /|~| _)\" [64,65] 64)\n    | Rep_int_choice \"'a sets_nats\" \"'a aset_anat => ('p,'a) proc\"\n                                               (\"(1!! :_ .. /_)\" [900,68] 68) \n    | IF             \"bool\" \"('p,'a) proc\" \"('p,'a) proc\"\n                                 (\"(0IF _ /THEN _ /ELSE _)\" [900,88,88] 88)\n(*                               (\"(0IF _ /THEN _ /ELSE _)\" [900,60,60] 88) *)\n    | Parallel       \"('p,'a) proc\" \"'a set\" \"('p,'a) proc\"  \n                                               (\"(1_ /|[_]| _)\" [76,0,77] 76)\n    | Hiding         \"('p,'a) proc\" \"'a set\"   (\"(1_ /-- _)\" [84,85] 84)\n\n    | Renaming       \"('p,'a) proc\" \"('a * 'a) set\"\n                                               (\"(1_ /[[_]])\" [84,0] 84)\n(*                                               (\"(1_ /[[_]])\" [84,0] 84) *)\n    | Seq_compo      \"('p,'a) proc\" \"('p,'a) proc\"  \n                                               (\"(1_ /;; _)\" [79,78] 78)\n    | Depth_rest     \"('p,'a) proc\" \"nat\"  \n                                               (\"(1_ /|. _)\" [84,900] 84)\n    | Proc_name      \"'p\"                      (\"$_\" [900] 90)\n\n(*--------------------------------------------------------------------*\n |                                                                    |\n | (1) binding power:                                                 |\n |      Proc_Name > IF > {Hiding, Renaming, Restriction} >            |\n |      {Act_prefix, Ext_pre_choice} > Seq_compo > Parallel >         |\n |      Ext_choice > Rep_int_choice > int_choice                      |\n |                                                                    |\n |   The binding power 90 is higher than ones of processes ops.       |\n |                                                                    |\n | (2) About (\"(1_ /-> _)\" [150,80] 80)                               |\n |      The nth operator ! has the power 101.                         |\n |      So, 150 > 101 is needed.                                      |\n |                                                                    |\n | (3) \"selector\" is necessary for having our CSP expressive          |\n |     with respect to the domain for stable-failures model F.        |\n |                                                                    |\n *--------------------------------------------------------------------*)\n\n(*** external prefix ***)\n\nsyntax\n  \"@Ext_pre_choice\"  :: \"pttrn => 'a set => ('p,'a) proc \n                => ('p,'a) proc\"  (\"(1? _:_ /-> _)\" [900,900,80] 80)\n\ntranslations\n  \"? x:X -> P\"  == \"? :X -> (%x. P)\"\n\n\nsyntax\n  \"@Ext_pre_choice_UNIV\" ::  \"pttrn => ('p,'a) proc => ('p,'a) proc\"\n                                           (\"(1? _ /-> _)\" [900,80] 80)\ntranslations\n  \"? x -> P\"    == \"? x:(CONST UNIV) -> P\"\n\n\n(*** replicated internal choice (bound variable, UNIV) ***)\n\nsyntax\n  \"@Rep_int_choice\":: \n      \"pttrn => 'a sets_nats => ('p,'a) proc => ('p,'a) proc\"  \n                               (\"(1!! _:_ .. /_)\" [900,900,68] 68)\ntranslations\n  \"!! c:C .. P\"    == \"!! :C .. (%c. P)\"\n\n(* this is not collect *)\n(*\nsyntax\n  \"@Rep_int_choice_UNIV\":: \n      \"pttrn => ('p,'a) proc => ('p,'a) proc\"\n                               (\"(1!! _ .. /_)\" [900,68] 68)\n\ntranslations\n  \"!! c .. P\"      == \"!! c:UNIV .. P\"\n*)\n\n(*** set, nat ***)\n\n(*\nconsts\n  Rep_int_choice_set :: \n    \"'a set set => ('a set => ('p,'a) proc) => ('p,'a) proc\"\n                                      (\"(1!set :_ .. /_)\" [900,68] 68)\n  Rep_int_choice_nat ::\n    \"nat set => (nat => ('p,'a) proc) => ('p,'a) proc\"\n                                      (\"(1!nat :_ .. /_)\" [900,68] 68)\n\ndefs\n  Rep_int_choice_set_def:\n        \"!set :Xs .. Pf == !! c:(type1 Xs) .. (Pf ((inv type1) c))\"\n  Rep_int_choice_nat_def:\n        \"!nat :N .. Pf == !! c:(type2 N) .. (Pf ((inv type2) c))\"\n*)\n\ndefinition\n  Rep_int_choice_set :: \n    \"'a set set => ('a set => ('p,'a) proc) => ('p,'a) proc\"\n                                      (\"(1!set :_ .. /_)\" [900,68] 68)\n  where\n  \"!set :Xs .. Pf == !! c:(type1 Xs) .. (Pf ((inv type1) c))\"\n\ndefinition\n  Rep_int_choice_nat ::\n    \"nat set => (nat => ('p,'a) proc) => ('p,'a) proc\"\n                                      (\"(1!nat :_ .. /_)\" [900,68] 68)\n  where\n  Rep_int_choice_nat_def:\n        \"!nat :N .. Pf == !! c:(type2 N) .. (Pf ((inv type2) c))\"\n\n(* bound variable *)\n\nsyntax\n  \"@Rep_int_choice_set\" :: \n     \"pttrn => ('a set) set => ('a set => ('p,'a) proc) => ('p,'a) proc\"\n                                      (\"(1!set _:_ .. /_)\" [900,900,68] 68)\n  \"@Rep_int_choice_nat\" :: \n     \"pttrn => nat set => (nat => ('p,'a) proc) => ('p,'a) proc\"\n                                      (\"(1!nat _:_ .. /_)\" [900,900,68] 68)\n\ntranslations\n    \"!set X:Xs .. P\" == \"!set :Xs .. (%X. P)\"\n    \"!nat n:N .. P\"  == \"!nat :N .. (%n. P)\"\n\n(* UNIV *)\n\nsyntax\n  \"@Rep_int_choice_set_UNIV\" ::\n     \"pttrn => ('a set => ('p,'a) proc) => ('p,'a) proc\"\n                                      (\"(1!set _ .. /_)\" [900,68] 68)\n  \"@Rep_int_choice_nat_UNIV\" ::\n     \"pttrn => (nat => ('p,'a) proc) => ('p,'a) proc\"\n                                      (\"(1!nat _ .. /_)\" [900,68] 68)\n\ntranslations\n      \"!set X .. P\" == \"!set X:(CONST UNIV) .. P\"\n      \"!nat n .. P\" == \"!nat n:(CONST UNIV) .. P\"\n\n(*** com ***)\n(* Isabelle 2013\nconsts\n  Rep_int_choice_com :: \"'a set => ('a => ('p,'a) proc) => ('p,'a) proc\"\n                                      (\"(1! :_ .. /_)\" [900,68] 68)\ndefs\n  Rep_int_choice_com_def :\n     \"! :A .. Pf == !set X:{{a} |a. a : A} .. Pf (the_elem(X))\"\n*)\n\ndefinition\n  Rep_int_choice_com :: \"'a set => ('a => ('p,'a) proc) => ('p,'a) proc\"\n                                      (\"(1! :_ .. /_)\" [900,68] 68)\n  where\n  \"! :A .. Pf == !set X:{{a} |a. a : A} .. Pf (the_elem(X))\"\n\nsyntax\n  \"@Rep_int_choice_com\" ::\n      \"pttrn => 'a set => ('a => ('p,'a) proc) => ('p,'a) proc\"\n                                      (\"(1! _:_ .. /_)\" [900,900,68] 68)\n  \"@Rep_int_choice_com_UNIV\" ::\n      \"pttrn => ('a => ('p,'a) proc) => ('p,'a) proc\"\n                                      (\"(1! _ .. /_)\" [900,68] 68)\ntranslations\n    \"! x:X .. P\" == \"! :X .. (%x. P)\"\n      \"! x .. P\" == \"! x:(CONST UNIV) .. P\"\n\n(*** f ***)\n\n(* Isabelle 2013\nconsts\n  Rep_int_choice_f ::\n    \"('b => 'a) => 'b set => ('b => ('p,'a) proc) => ('p,'a) proc\"\n                                      (\"(1!<_> :_ .. /_)\" [0,900,68] 68)\n\ndefs\n Rep_int_choice_f_def : \n        \"!<f> :X .. Pf == ! :(f ` X) .. (%x. (Pf ((inv f) x)))\"\n*)\n\ndefinition\n  Rep_int_choice_f ::\n    \"('b => 'a) => 'b set => ('b => ('p,'a) proc) => ('p,'a) proc\"\n                                      (\"(1!<_> :_ .. /_)\" [0,900,68] 68)\n  where\n  \"!<f> :X .. Pf == ! :(f ` X) .. (%x. (Pf ((inv f) x)))\"\n\nsyntax\n  \"@Rep_int_choice_f\"::\n      \"('b => 'a) => pttrn => 'b set => ('p,'a) proc => ('p,'a) proc\"\n                                      (\"(1!<_> _:_ .. /_)\" [0,900,900,68] 68)\n  \"@Rep_int_choice_f_UNIV\"::\n      \"('b => 'a) => pttrn => ('p,'a) proc => ('p,'a) proc\"\n                                      (\"(1!<_> _ .. /_)\" [900,900,68] 68)\n\ntranslations\n    \"!<f> x:X .. P\" == \"!<f> :X .. (%x. P)\"\n    \"!<f> x .. P\"   == \"!<f> x:(CONST UNIV) .. P\"\n\nlemmas Rep_int_choice_ss_def =\n       Rep_int_choice_set_def\n       Rep_int_choice_nat_def\n       Rep_int_choice_com_def\n       Rep_int_choice_f_def\n\n(*** internal prefix choice ***)\n\n(* 2013\nconsts\n  Int_pre_choice :: \"'a set => ('a => ('p,'a) proc) => ('p,'a) proc\"  \n                                      (\"(1! :_ /-> _)\" [900,80] 80)\n\ndefs\n  Int_pre_choice_def : \"! :X -> Pf == ! :X .. (%x. x -> (Pf x))\"\n*)\n\ndefinition\n  Int_pre_choice :: \"'a set => ('a => ('p,'a) proc) => ('p,'a) proc\"  \n                                      (\"(1! :_ /-> _)\" [900,80] 80)\n  where\n  \"! :X -> Pf == ! :X .. (%x. x -> (Pf x))\"\n\nsyntax\n  \"@Int_pre_choice\"  :: \"pttrn => 'a set => ('p,'a) proc \n                         => ('p,'a) proc\"  (\"(1! _:_ /-> _)\" [900,900,80] 80)\n\n  \"@Int_pre_choice_UNIV\" ::  \"pttrn => ('p,'a) proc => ('p,'a) proc\"\n                                           (\"(1! _ /-> _)\" [900,80] 80)\n\ntranslations\n  \"! x:X -> P\"  == \"! :X -> (%x. P)\"\n  \"! x -> P\"    == \"! x:(CONST UNIV) -> P\"\n\n(*** sending and receiving prefixes ***)\n\n(* Isabelle 2013\nconsts\n  Send_prefix :: \"('x => 'a) => 'x => ('p,'a) proc => ('p,'a) proc\" \n                                      (\"(1_ ! _ /-> _)\" [900,1000,80] 80)\n  Nondet_send_prefix :: \"('x => 'a) => 'x set => \n                         ('x => ('p,'a) proc) => ('p,'a) proc\" \n  Rec_prefix  :: \"('x => 'a) => 'x set => \n                  ('x => ('p,'a) proc) => ('p,'a) proc\" \n\ndefs\n  Send_prefix_def : \n    \"a ! x -> P    == a x -> P\"\n  Nondet_send_prefix_def : \n    \"Nondet_send_prefix f X Pf == ! :(f ` X) -> (%x. (Pf ((inv f) x)))\"\n  Rec_prefix_def : \n    \"Rec_prefix f X Pf == ? :(f ` X) -> (%x. (Pf ((inv f) x)))\"\n*)\n\ndefinition\n  Send_prefix :: \"('x => 'a) => 'x => ('p,'a) proc => ('p,'a) proc\" \n                                      (\"(1_ ! _ /-> _)\" [900,1000,80] 80)\n  where\n  \"a ! x -> P    == a x -> P\"\n\ndefinition\n  Nondet_send_prefix :: \"('x => 'a) => 'x set => \n                         ('x => ('p,'a) proc) => ('p,'a) proc\" \n  where\n  \"Nondet_send_prefix f X Pf == ! :(f ` X) -> (%x. (Pf ((inv f) x)))\"\n\ndefinition\n  Rec_prefix  :: \"('x => 'a) => 'x set => \n                  ('x => ('p,'a) proc) => ('p,'a) proc\" \n  where\n  \"Rec_prefix f X Pf == ? :(f ` X) -> (%x. (Pf ((inv f) x)))\"\n\n(*\nThe sending \"a ! v -> P\" causes syntactical ambiguity.\nSo, it is recommended to directly use \"a v -> P\" instead of \"a ! v -> P\".\n*)\n\nsyntax\n  \"@Nondet_send_prefix\" :: \n     \"('x => 'a) => pttrn => 'x set => ('p,'a) proc => ('p,'a) proc\"\n                               (\"(1_ !? _:_ /-> _)\" [900,900,1000,80] 80)\n\n  \"@Nondet_send_prefix_UNIV\" :: \n     \"('x => 'a) => pttrn => ('p,'a) proc => ('p,'a) proc\"\n                               (\"(1_ !? _ /-> _)\" [900,900,80] 80)\n\n  \"@Rec_prefix\" :: \n     \"('x => 'a) => pttrn => 'x set => ('p,'a) proc => ('p,'a) proc\"\n                               (\"(1_ ? _:_ /-> _)\" [900,900,1000,80] 80)\n  \"@Rec_Prefix_UNIV\" :: \n     \"('x => 'a) => pttrn => ('p,'a) proc => ('p,'a) proc\"\n                               (\"(1_ ? _ /-> _)\" [900,900,80] 80)\n\ntranslations\n  \"a !? x:X -> P\" == \"CONST Nondet_send_prefix a X (%x. P)\"\n  \"a !? x -> P\"   == \"a !? x:(CONST UNIV) -> P\"\n\n  \"a ? x:X -> P\"  == \"CONST Rec_prefix a X (%x. P)\"\n  \"a ? x -> P\"    == \"a? x:(CONST UNIV) -> P\"\n\n(*** unfolding syntactic sugar ***)\n\nlemmas csp_prefix_ss_def = Int_pre_choice_def\n                           Send_prefix_def\n                           Nondet_send_prefix_def\n                           Rec_prefix_def\n\n(*** parallel ***)\n\nabbreviation\n   Interleave :: \"('p,'a) proc => ('p,'a) proc\n                    => ('p,'a) proc\"  (\"(1_ /||| _)\" [76,77] 76)\nwhere \"P ||| Q == P |[{}]| Q\"\n\nabbreviation\n   Synchro   :: \"('p,'a) proc => ('p,'a) proc\n                    => ('p,'a) proc\"  (\"(1_ /|| _)\" [76,77] 76)\nwhere \"P || Q == P |[UNIV]| Q\"\n\n(*\nsyntax\n  \"_Interleave\"    :: \"('p,'a) proc => ('p,'a) proc\n                    => ('p,'a) proc\"  (\"(1_ /||| _)\" [76,77] 76)\n  \"_Synchro\"       :: \"('p,'a) proc => ('p,'a) proc\n                    => ('p,'a) proc\"  (\"(1_ /|| _)\" [76,77] 76)\n\ntranslations\n  \"P ||| Q\"     == \"P |[{}]| Q\"\n  \"P || Q\"      == \"P |[UNIV]| Q\"\n*)\n\n(* Isabelle 2013\nconsts\n  Alpha_parallel :: \"('p,'a) proc => 'a set => 'a set => ('p,'a) proc\n                      => ('p,'a) proc\"  (\"(1_ /(2|[_,/_]|)/ _)\" [76,0,0,77] 76)\ndefs\n  Alpha_parallel_def :\n   \"P |[X,Y]| Q  == (P |[- X]| SKIP) |[X Int Y]| (Q |[- Y]| SKIP)\"\n*)\n\ndefinition\n  Alpha_parallel :: \"('p,'a) proc => 'a set => 'a set => ('p,'a) proc\n                      => ('p,'a) proc\"  (\"(1_ /(2|[_,/_]|)/ _)\" [76,0,0,77] 76)\n  where\n  \"P |[X,Y]| Q  == (P |[- X]| SKIP) |[X Int Y]| (Q |[- Y]| SKIP)\"\n\nprimrec\n  Inductive_parallel :: \"(('p,'a) proc * 'a set) list\n                   => ('p,'a) proc\"  (\"(1[||] _)\" [78] 78)\nwhere\n  \"[||] [] = SKIP\"\n |\"[||] (PX # PXs) = (fst PX) |[snd PX, Union (snd ` set PXs)]| ([||] PXs)\"\n\n(* Isabelle 2013 \nconsts\n  Rep_parallel :: \"'i set => ('i => (('p,'a) proc * 'a set))\n                      => ('p,'a) proc\"  (\"(1[||]:_ /_)\" [90,78] 78)\n\ndefs\n  Rep_parallel_def :\n   \"[||]:I PXf == [||] (map PXf (SOME Is. Is isListOf I))\"\n*)   \n\ndefinition\n  Rep_parallel :: \"'i set => ('i => (('p,'a) proc * 'a set))\n                      => ('p,'a) proc\"  (\"(1[||]:_ /_)\" [90,78] 78)\n  where\n  Rep_parallel_def :\n   \"[||]:I PXf == [||] (map PXf (SOME Is. Is isListOf I))\"\n\nsyntax\n  \"@Rep_parallel\" :: \n     \"pttrn => 'i set => (('p,'a) proc * 'a set)\n                      => ('p,'a) proc\"  (\"(1[||] _:_ .. /_)\" [900,90,78] 78)\n\ntranslations\n  \"[||] i:I .. PX\"  == \"[||]:I (%i. PX)\"\n\n(************************************\n |           empty Index            |\n ************************************)\n\nlemma Rep_parallel_empty[simp]: \"I = {} ==> [||]:I PXf = SKIP\"\nby (simp add: Rep_parallel_def)\n\n(************************************\n |            one Index             |\n ************************************)\n\nlemma Rep_parallel_one: \n  \"I = {i} ==> [||]:I PXf = (fst (PXf i)) |[snd (PXf i), {}]| SKIP\"\nby (simp add: Rep_parallel_def)\n\n(*** timeout ***)\n\nabbreviation\n Timeout_abb :: \"('p,'a) proc => ('p,'a) proc \n             => ('p,'a) proc\"  (\"(1_ /[> _)\" [73,74] 73)\n where \"P [> Q == (P |~| STOP) [+] Q\"\n\n(*\nsyntax\n  \"_Timeout\"  :: \"('p,'a) proc => ('p,'a) proc \n               => ('p,'a) proc\"  (\"(1_ /[> _)\" [73,74] 73)\ntranslations\n  \"P [> Q\"      == \"(P |~| STOP) [+] Q\"\n*)\n\n(*** it is sometimes useful to prevent automatic unfolding [> ***)\n\n(* Isabelle 2013\nconsts\n  Timeout  :: \"('p,'a) proc => ('p,'a) proc \n               => ('p,'a) proc\"  (\"(1_ /[>def _)\" [73,74] 73)\ndefs\n  Timeout_def : \"P [>def Q == P [> Q\"\n*)  \n\ndefinition\n  Timeout  :: \"('p,'a) proc => ('p,'a) proc \n               => ('p,'a) proc\"  (\"(1_ /[>def _)\" [73,74] 73)\n  where\n  Timeout_def : \"P [>def Q == P [> Q\"\n\n\n(************************************\n |       Renaming by lists          |\n ************************************)\n\nprimrec\n  Renaming_List  :: \"('p,'a) proc => ('a * 'a) set list => ('p,'a) proc\"\n                                               (\"(1_ /[[ _ ]]*)\" [84,0] 84)\nwhere\n  \"P [[ [] ]]* = P\"\n |\"P [[ r#rs ]]* = P[[r]] [[ rs ]]*\"\n\n\n(* --------------------------------------------------- *\n             pipe operator (CSP-Prover 5)\n * --------------------------------------------------- *)\n\n(* Isabelle 2013\nconsts\n Pipe :: \"('p,'a) proc => \n          ('x => 'a) => ('x => 'a) => ('x => 'a) =>\n          ('p,'a) proc => ('p,'a) proc\"\n          (\"(1_ /<[_,_,_]> _)\" [76,0,0,0,77] 76)\n\ndefs\n Pipe_def: \n   \"P <[left,mid,right]> Q == \n   (P[[right<==>mid]] \n    |[range left Un range mid, range mid Un range right]| \n    Q[[left<==>mid]]) -- (range mid)\"\n*)\n\ndefinition\n Pipe :: \"('p,'a) proc => \n          ('x => 'a) => ('x => 'a) => ('x => 'a) =>\n          ('p,'a) proc => ('p,'a) proc\"\n          (\"(1_ /<[_,_,_]> _)\" [76,0,0,0,77] 76)\n\n  where\n   \"P <[left,mid,right]> Q == \n   (P[[right<==>mid]] \n    |[range left Un range mid, range mid Un range right]| \n    Q[[left<==>mid]]) -- (range mid)\"\n\n(*===================================================================*\n\n(1) We assume that a process-name-function PNfun is given for \n    defining the meaning of each process-name.\n\n    When you define a type of process names, you have to define\n    the function PNfun by \"overloaded\" as follows:\n\n      defs (overloaded)\n      PNfun_test_def :  \"PNfun == ...\"\n\n(2) There are two kinds of approahes for fixed points, i.e. \n    cms and cpo approaches. You can defin the mode for fixed \n    points by\n\n      defs FPmode = CPOmode  \n    or\n      defs FPmode = CMSmode\n\n    In addtion, you can use MIXmode as follows\n\n      defs FPmode = CMSmode\n\n    It means the least fixed point (in subset order) is used for\n    giving the meaning of process names based on cpo approach, and if\n    the process function is guarded then cms appoach is also used\n    because the least fixed point is the unique fixed point in this\n    case.\n\n *==================================================================*)\n\n(* Isabelle 2013\nconsts PNfun :: \"'p => ('p,'a) proc\"  (* Definition of process names *)\n*)\n\ntype_synonym ('p,'a) pnfun = \"'p => ('p,'a) proc\"\nconsts PNfun :: \"('p,'a) pnfun\"  (* Definition of process names *)\n\ndatatype fpmode = CPOmode | CMSmode | MIXmode\nconsts FPmode :: \"fpmode\"\n\n(* overloading test:\noverloading FP_CPOmode == \n  \"FPmode :: fpmode\"\nbegin\n  definition \"FPmode == CPOmode\"\nend\n\nlemma \"FPmode = CPOmode\"\napply (simp add:FP_CPOmode_def)\ndone\n*)\n\nlemma CPOmode_or_CMSmode_or_MIXmode_lm: \n   \"m = FPmode --> m = CPOmode | m = CMSmode | m = MIXmode\"\napply (induct_tac m)\napply (auto)\ndone\n\nlemma CPOmode_or_CMSmode_or_MIXmode: \n  \"FPmode = CPOmode | FPmode = CMSmode | FPmode = MIXmode\"\nby (simp add: CPOmode_or_CMSmode_or_MIXmode_lm)\n\n(*-------*\n | CHAOS |\n *-------*)\n\n(* This CHAOS may cause some error on process definition ... ? *)\n\ndatatype 'a ChaosName = Chaos \"'a set\"\n\nprimrec\n  Chaosfun :: \"'a ChaosName => ('a ChaosName, 'a) proc\"\nwhere\n  \"Chaosfun   (Chaos A) = (! x:A -> $(Chaos A)) |~| STOP\"\n\n(* Isabelle 2013\ndefs (overloaded)\nSet_Chaosfun_def [simp]: \"PNfun == Chaosfun \n*)\n\noverloading Set_Chaosfun == \n  \"PNfun :: ('a ChaosName, 'a) pnfun\"\nbegin\n  definition \"PNfun (pn::'a ChaosName) == Chaosfun pn\"\nend\n\n(* test of overloading *)\nlemma \"((PNfun pn)::('a ChaosName, 'a) proc) = Chaosfun pn\"\napply (simp add: Set_Chaosfun_def)\ndone\n\n(* Isabelle 2013\nconsts CHAOS :: \"'a set => ('a ChaosName, 'a) proc\"\ndefs   CHAOS_def : \"CHAOS == (%A. $(Chaos A))\"\n*)\n\ndefinition\n  CHAOS :: \"'a set => ('a ChaosName, 'a) proc\"\n  where\n  CHAOS_def : \"CHAOS == (%A. $(Chaos A))\"\n\n\n(* --------------------------------------- *\n     an example of recursive processes\n\ndatatype AB = A | B\n\nconsts ABfun :: \"AB => (AB,nat) proc\"\n\nprimrec\n  \"ABfun  A = 0 -> $B\"\n  \"ABfun  B = 1 -> $A\"\n\ndefs (overloaded)\nPNfun_AB_def : \"PNfun == ABfun\"\n\n * --------------------------------------- *)\n\n(*********************************************************************\n            substitution by functions : 'p => ('a,'p) proc\n *********************************************************************)\n\n\nprimrec\n  Subst_procfun :: \"('p,'a) proc => ('p => ('q,'a) proc)\n                   => ('q,'a) proc\"  (\"_ <<\" [1000] 1000)\nwhere\n  \"STOP<<Pf         = STOP\"\n |\"SKIP<<Pf         = SKIP\"\n |\"DIV<<Pf          = DIV\"\n |\"(a -> P)<<Pf     = a -> P<<Pf\"\n |\"(? :X -> Qf)<<Pf = ? a:X -> (Qf a)<<Pf\"\n |\"(P [+] Q)<<Pf    = P<<Pf [+] Q<<Pf\"\n |\"(P |~| Q)<<Pf    = P<<Pf |~| Q<<Pf\"\n |\"(!! :C .. Qf)<<Pf = !! c:C .. (Qf c)<<Pf\"\n |\"(IF b THEN P ELSE Q)<<Pf = IF b THEN P<<Pf ELSE Q<<Pf\"\n |\"(P |[X]| Q)<<Pf  = P<<Pf |[X]| Q<<Pf\"\n |\"(P -- X)<<Pf     = P<<Pf -- X\"\n |\"(P [[r]])<<Pf    = P<<Pf [[r]]\"\n |\"(P ;; Q)<<Pf     = P<<Pf ;; Q<<Pf\"\n |\"(P |. n)<<Pf     = P<<Pf |. n\"\n |\"($p) <<Pf        = Pf p\"\n\n (* Isabelle 2013\nconsts\n  Subst_procfun_prod :: \n     \"('p => ('q,'a) proc) => \n      ('q => ('r,'a) proc) => ('p => ('r,'a) proc)\"\n                                     (\"_ <<<\" [1000] 1000)\ndefs\n  Subst_procfun_prod_def: \"Pf <<< == (%Qf p. (Pf p)<<Qf)\"\n*)\n\ndefinition\n  Subst_procfun_prod :: \n     \"('p => ('q,'a) proc) => \n      ('q => ('r,'a) proc) => ('p => ('r,'a) proc)\"\n                                     (\"_ <<<\" [1000] 1000)\n  where\n  \"Pf <<< == (%Qf p. (Pf p)<<Qf)\"\n\n(* lemmas *)\n\nlemma Subst_procfun_Rep_int_choice_set[simp]:\n  \"(!set :Xs .. Qf)<<Pf      = !set X:Xs .. (Qf X)<<Pf\"\nby (simp add: Rep_int_choice_ss_def)\n\nlemma Subst_procfun_Rep_int_choice_nat[simp]:\n  \"(!nat :N .. Qf)<<Pf      = !nat n:N .. (Qf n)<<Pf\"\nby (simp add: Rep_int_choice_ss_def)\n\nlemma Subst_procfun_Rep_int_choice_com[simp]:\n  \"(! :X .. Qf)<<Pf      = ! x:X .. (Qf x)<<Pf\"\nby (simp add: Rep_int_choice_com_def)\n\nlemma Subst_procfun_Rep_int_choice_f[simp]:\n  \"(!<f> :X .. Qf)<<Pf      = !<f> x:X .. (Qf x)<<Pf\"\nby (simp add: Rep_int_choice_f_def)\n\nlemma Subst_procfun_prod_p:\n  \"(Pf <<< Qf) p = (Pf p) << Qf\"\nby (simp add: Subst_procfun_prod_def)\n\n\n(* for sinding and receiving *)\n\nlemma Subst_procfun_Send_prefix[simp]:\n  \"(a ! v -> P)<<Pf      = a ! v -> P<<Pf\"\nby (simp add: csp_prefix_ss_def)\n\nlemma Subst_procfun_Rec_prefix[simp]:\n  \"(a ? x:X -> Pf x)<<Qf      = a ? x:X ->(Pf x)<<Qf\"\nby (simp add: csp_prefix_ss_def)\n\nlemma Subst_procfun_Int_pre_choice[simp]:\n  \"(! :X -> Pf)<<Qf      = ! x:X -> (Pf x)<<Qf\"\nby (simp add: csp_prefix_ss_def)\n\nlemma Subst_procfun_Nondet_send_prefix[simp]:\n  \"(a !? x:X -> Pf x)<<Qf      = a !? x:X ->(Pf x)<<Qf\"\nby (simp add: csp_prefix_ss_def)\n\n(* subst *)\n\nlemma Subst_procfun_Alpha_parallel[simp]: (* <- added for Alpha_parallel *)\n  \"(P |[X,Y]| Q)<<Pf = (P<<Pf) |[X,Y]| (Q<<Pf)\"\nby (simp add: Alpha_parallel_def)\n\nlemma Subst_procfun_Pipe[simp]:\n  \"(P <[left,mid,right]> Q)<<Pf = (P<<Pf) <[left,mid,right]> (Q<<Pf)\"\nby (simp add: Pipe_def)\n\n\n(*************************************************************\n                   Syntactical functions\n *************************************************************)\n\n(*** guarded fun) ***)\n\n(*** noPN ***)\n\nprimrec\n  noPN   :: \"('p,'a) proc => bool\"   (* no Proc_name *)\nwhere\n  \"noPN STOP          = True\"\n |\"noPN SKIP          = True\"\n |\"noPN DIV           = True\"\n |\"noPN (a -> P)      = noPN P\"\n |\"noPN (? :X -> Pf)  = (ALL a. noPN (Pf a))\"\n |\"noPN (P [+] Q)     = (noPN P & noPN Q)\"\n |\"noPN (P |~| Q)     = (noPN P & noPN Q)\"\n |\"noPN (!! :C .. Pf) = (ALL c. noPN (Pf c))\"\n |\"noPN (IF b THEN P ELSE Q) = (noPN P & noPN Q)\"\n |\"noPN (P |[X]| Q)   = (noPN P & noPN Q)\"\n |\"noPN (P -- X)      = noPN P\"\n |\"noPN (P [[r]])     = noPN P\"\n |\"noPN (P ;; Q)      = (noPN P & noPN Q)\"\n |\"noPN (P |. n)      = noPN P\"\n |\"noPN ($p)          = False\"\n\n(*** gSKIP ***)\n\nprimrec\n  gSKIP  :: \"('p,'a) proc => bool\"   (* guarded SKIP *)\nwhere\n  \"gSKIP STOP          = True\"\n |\"gSKIP SKIP          = False\"\n |\"gSKIP DIV           = True\"\n |\"gSKIP (a -> P)      = True\"\n |\"gSKIP (? :X -> Pf)  = True\"\n |\"gSKIP (P [+] Q)     = (gSKIP P & gSKIP Q)\"\n |\"gSKIP (P |~| Q)     = (gSKIP P & gSKIP Q)\"\n |\"gSKIP (!! :C .. Pf) = (ALL c. gSKIP (Pf c))\"\n |\"gSKIP (IF b THEN P ELSE Q) = (gSKIP P & gSKIP Q)\"\n |\"gSKIP (P |[X]| Q)   = (gSKIP P | gSKIP Q)\"\n |\"gSKIP (P -- X)      = False\"\n |\"gSKIP (P [[r]])     = gSKIP P\"\n |\"gSKIP (P ;; Q)      = (gSKIP P | gSKIP Q)\"\n |\"gSKIP (P |. n)      = (gSKIP P | n=0)\"\n |\"gSKIP ($p)          = False\"\n\n(*** no hide ***)\n\nprimrec\n  noHide :: \"('p,'a) proc => bool\"   (* no Hide      *)\nwhere\n  \"noHide STOP          = True\"\n |\"noHide SKIP          = True\"\n |\"noHide DIV           = True\"\n |\"noHide (a -> P)      = noHide P\"\n |\"noHide (? :X -> Pf)  = (ALL a. noHide (Pf a))\"\n |\"noHide (P [+] Q)     = (noHide P & noHide Q)\"\n |\"noHide (P |~| Q)     = (noHide P & noHide Q)\"\n |\"noHide (!! :C .. Pf) = (ALL c. noHide (Pf c))\"\n |\"noHide (IF b THEN P ELSE Q) = (noHide P & noHide Q)\"\n |\"noHide (P |[X]| Q)   = (noHide P & noHide Q)\"\n |\"noHide (P -- X)      = noPN P\"\n |\"noHide (P [[r]])     = noHide P\"\n |\"noHide (P ;; Q)      = (noHide P & noHide Q)\"\n |\"noHide (P |. n)      = (noHide P | n=0)\"\n |\"noHide ($p)          = True\"\n\n(*** guarded ***)\n\nprimrec\n  guarded:: \"('p,'a) proc => bool\"   (* guarded proc *)\nwhere\n  \"guarded STOP          = True\"\n |\"guarded SKIP          = True\"\n |\"guarded DIV           = True\"\n |\"guarded (a -> P)      = noHide P\"\n |\"guarded (? :X -> Pf)  = (ALL a. noHide (Pf a))\"\n |\"guarded (P [+] Q)     = (guarded P & guarded Q)\"\n |\"guarded (P |~| Q)     = (guarded P & guarded Q)\"\n |\"guarded (!! :C .. Pf) = (ALL c. guarded (Pf c))\"\n |\"guarded (IF b THEN P ELSE Q) = (guarded P & guarded Q)\"\n |\"guarded (P |[X]| Q)   = (guarded P & guarded Q)\"\n |\"guarded (P -- X)      = noPN P\"\n |\"guarded (P [[r]])     = guarded P\"\n |\"guarded (P ;; Q)      = ((guarded P & gSKIP P & noHide Q) | \n                           (guarded P & guarded Q))\"\n |\"guarded (P |. n)      = (guarded P | n=0)\"\n |\"guarded ($p)          = False\"\n\n(*** for process function ***)\n\n(*\nconsts\n  noPNfun   :: \"('p => ('q,'a) proc) => bool\"\n  gSKIPfun  :: \"('p => ('q,'a) proc) => bool\"\n  noHidefun :: \"('p => ('q,'a) proc) => bool\"\n  guardedfun:: \"('p => ('q,'a) proc) => bool\"\n\ndefs\n  noPNfun_def   : \"noPNfun Pf    == (ALL p. noPN (Pf p))\"\n  gSKIPfun_def  : \"gSKIPfun Pf   == (ALL p. gSKIP (Pf p))\"\n  noHidefun_def : \"noHidefun Pf  == (ALL p. noHide (Pf p))\"\n  guardedfun_def: \"guardedfun Pf == (ALL p. guarded (Pf p))\"\n*)\n\ndefinition\n  noPNfun   :: \"('p => ('q,'a) proc) => bool\"\n  where \n  \"noPNfun Pf    == (ALL p. noPN (Pf p))\"\n\ndefinition\n  gSKIPfun  :: \"('p => ('q,'a) proc) => bool\"\n  where\n  \"gSKIPfun Pf   == (ALL p. gSKIP (Pf p))\"\n\ndefinition\n  noHidefun :: \"('p => ('q,'a) proc) => bool\"\n  where\n  \"noHidefun Pf  == (ALL p. noHide (Pf p))\"\n\ndefinition\n  guardedfun:: \"('p => ('q,'a) proc) => bool\"\n  where\n  \"guardedfun Pf == (ALL p. guarded (Pf p))\"\n\n  (****** short notations ******)\n\n(* noPN *)\n\nlemma noPN_Rep_int_choice_set[simp]:\n  \"noPN (!set :Xs .. Pf) = (ALL X. noPN (Pf X))\"\nby (simp add: Rep_int_choice_ss_def)\n\nlemma noPN_Rep_int_choice_nat[simp]:\n  \"noPN (!nat :N .. Pf) = (ALL n. noPN (Pf n))\"\nby (simp add: Rep_int_choice_ss_def)\n\nlemma noPN_Rep_int_choice_com[simp]:\n  \"noPN (! :X .. Pf) = (ALL a. noPN (Pf a))\"\napply (auto simp add: Rep_int_choice_com_def)\napply (drule_tac x=\"{a}\" in spec)\napply (simp)\ndone\n\nlemma noPN_Rep_int_choice_f[simp]:\n  \"[| inj f ; ALL a. noPN (Pf a) |] ==> noPN (!<f> :X .. Pf)\"\nby (simp add: Rep_int_choice_f_def)\n\nlemma noPN_Alpha_parallel[simp]:\n  \"noPN (P |[X,Y]| Q) = (noPN P & noPN Q)\"\nby (simp add: Alpha_parallel_def)\n\n(* gSKIP *)\n\nlemma gSKIP_Rep_int_choice_set[simp]:\n  \"gSKIP (!set :Xs .. Pf) = (ALL X. gSKIP (Pf X))\"\nby (simp add: Rep_int_choice_ss_def)\n\nlemma gSKIP_Rep_int_choice_nat[simp]:\n  \"gSKIP (!nat :N .. Pf) = (ALL n. gSKIP (Pf n))\"\nby (simp add: Rep_int_choice_ss_def)\n\nlemma gSKIP_Rep_int_choice_com[simp]:\n  \"gSKIP (! :X .. Pf) = (ALL a. gSKIP (Pf a))\"\napply (auto simp add: Rep_int_choice_com_def)\napply (drule_tac x=\"{a}\" in spec)\napply (simp)\ndone\n\nlemma gSKIP_Rep_int_choice_f[simp]:\n  \"[| inj f ; ALL a. gSKIP (Pf a) |] ==> gSKIP (!<f> :X .. Pf)\"\nby (simp add: Rep_int_choice_f_def)\n\nlemma gSKIP_Alpha_parallel[simp]:\n  \"gSKIP (P |[X,Y]| Q) = (gSKIP P | gSKIP Q)\"\nby (simp add: Alpha_parallel_def)\n\n(* noHide *)\n\nlemma noHide_Rep_int_choice_set[simp]:\n  \"noHide (!set :Xs .. Pf) = (ALL X. noHide (Pf X))\"\nby (simp add: Rep_int_choice_ss_def)\n\nlemma noHide_Rep_int_choice_nat[simp]:\n  \"noHide (!nat :N .. Pf) = (ALL n. noHide (Pf n))\"\nby (simp add: Rep_int_choice_ss_def)\n\nlemma noHide_Rep_int_choice_com[simp]:\n  \"noHide (! :X .. Pf) = (ALL a. noHide (Pf a))\"\napply (auto simp add: Rep_int_choice_com_def)\napply (drule_tac x=\"{a}\" in spec)\napply (simp)\ndone\n\nlemma noHide_Rep_int_choice_f[simp]:\n  \"[| inj f ; ALL a. noHide (Pf a) |]\n   ==> noHide (!<f> :X .. Pf)\"\nby (simp add: Rep_int_choice_f_def)\n\nlemma noHide_Alpha_parallel[simp]:\n  \"noHide (P |[X,Y]| Q) = (noHide P & noHide Q)\"\nby (simp add: Alpha_parallel_def)\n\n(* guarded *)\n\nlemma guarded_Rep_int_choice_set[simp]:\n  \"guarded (!set :Xs .. Pf) = (ALL X. guarded (Pf X))\"\nby (simp add: Rep_int_choice_ss_def)\n\nlemma guarded_Rep_int_choice_nat[simp]:\n  \"guarded (!nat :N .. Pf) = (ALL n. guarded (Pf n))\"\nby (simp add: Rep_int_choice_ss_def)\n\nlemma guarded_Rep_int_choice_com[simp]:\n  \"guarded (! :X .. Pf) = (ALL a. guarded (Pf a))\"\napply (auto simp add: Rep_int_choice_com_def)\napply (drule_tac x=\"{a}\" in spec)\napply (simp)\ndone\n\nlemma guarded_Rep_int_choice_f[simp]:\n  \"[| inj f ; ALL a. guarded (Pf a) |] \n   ==> guarded (!<f> :X .. Pf)\"\nby (simp add: Rep_int_choice_f_def)\n\nlemma guarded_Alpha_parallel[simp]:\n  \"guarded (P |[X,Y]| Q) = (guarded P & guarded Q)\"\nby (simp add: Alpha_parallel_def)\n\n\n(* --------- for sinding and receiving --------- *)\n\n(* noPN *)\n\nlemma noPN_Send_prefix[simp]:\n  \"noPN (a ! v -> P) = noPN(P)\"\nby (simp add: csp_prefix_ss_def)\n\nlemma noPN_Rec_prefix[simp]:\n  \"noPN (a ? x:X -> Pf x) = (ALL x. noPN(Pf (inv a x)))\"\nby (simp add: csp_prefix_ss_def)\n\nlemma noPN_Int_pre_choice[simp]:\n  \"noPN (! :X -> Pf) = (ALL x. noPN(Pf x))\"\nby (simp add: csp_prefix_ss_def)\n\nlemma noPN__Nondet_send_prefix[simp]:\n  \"noPN (a !? x:X -> Pf x) = (ALL x. noPN(Pf (inv a x)))\"\nby (simp add: csp_prefix_ss_def)\n\n(* gSKIP *)\n\nlemma gSKIP_Send_prefix[simp]:\n  \"gSKIP (a ! v -> P)\"\nby (simp add: csp_prefix_ss_def)\n\nlemma gSKIP_Rec_prefix[simp]:\n  \"gSKIP (a ? x:X -> Pf x)\"\nby (simp add: csp_prefix_ss_def)\n\nlemma gSKIP_Int_pre_choice[simp]:\n  \"gSKIP (! :X -> Pf)\"\nby (simp add: csp_prefix_ss_def)\n\nlemma gSKIP__Nondet_send_prefix[simp]:\n  \"gSKIP (a !? x:X -> Pf x)\"\nby (simp add: csp_prefix_ss_def)\n\n(* noHide *)\n\nlemma noHide_Send_prefix[simp]:\n  \"noHide (a ! v -> P) = noHide(P)\"\nby (simp add: csp_prefix_ss_def)\n\nlemma noHide_Rec_prefix[simp]:\n  \"noHide (a ? x:X -> Pf x) = (ALL x. noHide(Pf (inv a x)))\"\nby (simp add: csp_prefix_ss_def)\n\nlemma noHide_Int_pre_choice[simp]:\n  \"noHide (! :X -> Pf) = (ALL x. noHide(Pf x))\"\nby (simp add: csp_prefix_ss_def)\n\nlemma noHide__Nondet_send_prefix[simp]:\n  \"noHide (a !? x:X -> Pf x) = (ALL x. noHide(Pf (inv a x)))\"\nby (simp add: csp_prefix_ss_def)\n\n(* guarded *)\n\nlemma guarded_Send_prefix[simp]:\n  \"guarded (a ! v -> P) = noHide(P)\"\nby (simp add: csp_prefix_ss_def)\n\nlemma guarded_Rec_prefix[simp]:\n  \"guarded (a ? x:X -> Pf x) = (ALL x. noHide(Pf (inv a x)))\"\nby (simp add: csp_prefix_ss_def)\n\nlemma guarded_Int_pre_choice[simp]:\n  \"guarded (! :X -> Pf) = (ALL x. noHide(Pf x))\"\nby (simp add: csp_prefix_ss_def)\n\nlemma guarded__Nondet_send_prefix[simp]:\n  \"guarded (a !? x:X -> Pf x) = (ALL x. noHide(Pf (inv a x)))\"\nby (simp add: csp_prefix_ss_def)\n\n(* --------- for pipe --------- *)\n\n(* noPN *)\n\nlemma noPN_Pipe[simp]:\n  \"noPN (P <[left,mid,right]> Q) = ((noPN P) & (noPN Q))\"\nby (simp add: Pipe_def)\n\n(* gSKIP *)\n\nlemma gSKIP_Pipe[simp]:\n  \"gSKIP (P <[left,mid,right]> Q) = False\"\nby (simp add: Pipe_def)\n\n(* noHide *)\n\nlemma noHide_Pipe[simp]:\n  \"noHide (P <[left,mid,right]> Q) = (noPN P & noPN Q)\"\nby (simp add: Pipe_def)\n\n(* guarded *)\n\nlemma guarded_Pipe[simp]:\n  \"guarded (P <[left,mid,right]> Q) = (noPN P & noPN Q)\"\nby (simp add: Pipe_def)\n\n(*-----------------------------------------------------*\n |                   Substitution                      |\n *-----------------------------------------------------*)\n\nlemma noPN_Subst_lm: \"noPN P --> noPN (P<<Pf)\"\napply (induct_tac P)\napply (simp_all)\ndone\n\nlemma noPN_Subst: \"noPN P ==> noPN (P<<Pf)\"\nby (simp add: noPN_Subst_lm)\n\nlemma noPN_Subst_Pf: \"noPNfun Pf ==> noPN (P<<Pf)\"\napply (induct_tac P)\napply (simp_all)\napply (simp add: noPNfun_def)\ndone\n\nlemma noHide_Subst_lm: \"(noHide P & noHidefun Pf) --> noHide (P<<Pf)\"\napply (induct_tac P)\napply (simp_all)\napply (simp add: noPN_Subst)\napply (force)\napply (simp add: noHidefun_def)\ndone\n\nlemma noHide_Subst: \"[| noHide P ; noHidefun Pf |] ==> noHide (P<<Pf)\"\nby (simp add: noHide_Subst_lm)\n\nlemma gSKIP_Subst_lm: \"(gSKIP P) --> gSKIP (P<<Pf)\"\napply (induct_tac P)\napply (simp_all)\ndone\n\nlemma gSKIP_Subst: \"(gSKIP P) ==> gSKIP (P<<Pf)\"\nby (simp add: gSKIP_Subst_lm)\n\nlemma guarded_Subst_lm: \"(guarded P & noHidefun Pf) --> guarded (P<<Pf)\"\napply (induct_tac P)\napply (simp_all)\napply (simp add: noHide_Subst)\napply (intro allI impI)\napply (simp add: noHide_Subst)\napply (simp add: noPN_Subst)\napply (intro allI impI)\napply (elim conjE exE disjE)\napply (simp add: gSKIP_Subst noHide_Subst)\napply (simp)\napply (force)\ndone\n\nlemma guarded_Subst: \"[| guarded P ; noHidefun Pf |] ==> guarded (P<<Pf)\"\nby (simp add: guarded_Subst_lm)\n\n(*********************************************************\n             termination relation for proc\n *********************************************************)\n\n(* Isabelle 2005\nconsts\n  procterm :: \"(('p,'a) proc * ('p,'a) proc) set\"\n\ninductive procterm\nintros\n  \"(P, a -> P)             : procterm\"\n  \"(Pf a, ? :X -> Pf)      : procterm\"\n  \"(P, P [+] Q)            : procterm\"\n  \"(Q, P [+] Q)            : procterm\"\n  \"(P, P |~| Q)            : procterm\"\n  \"(Q, P |~| Q)            : procterm\"\n  \"(Pf c, !! :C .. Pf)     : procterm\"\n  \"(P, IF b THEN P ELSE Q) : procterm\"\n  \"(Q, IF b THEN P ELSE Q) : procterm\"\n  \"(P, P |[X]| Q)          : procterm\"\n  \"(Q, P |[X]| Q)          : procterm\"\n  \"(P, P -- X)             : procterm\"\n  \"(P, P [[r]])            : procterm\"\n  \"(P, P ;; Q)             : procterm\"\n  \"(Q, P ;; Q)             : procterm\"\n  \"(P, P |. n)             : procterm\"\n*)\n\ninductive_set\n  procterm :: \"(('p,'a) proc * ('p,'a) proc) set\"\nwhere\n  \"(P, a -> P)             : procterm\" |\n  \"(Pf a, ? :X -> Pf)      : procterm\" |\n  \"(P, P [+] Q)            : procterm\" |\n  \"(Q, P [+] Q)            : procterm\" |\n  \"(P, P |~| Q)            : procterm\" |\n  \"(Q, P |~| Q)            : procterm\" |\n  \"(Pf c, !! :C .. Pf)     : procterm\" |\n  \"(P, IF b THEN P ELSE Q) : procterm\" |\n  \"(Q, IF b THEN P ELSE Q) : procterm\" |\n  \"(P, P |[X]| Q)          : procterm\" |\n  \"(Q, P |[X]| Q)          : procterm\" |\n  \"(P, P -- X)             : procterm\" |\n  \"(P, P [[r]])            : procterm\" |\n  \"(P, P ;; Q)             : procterm\" |\n  \"(Q, P ;; Q)             : procterm\" |\n  \"(P, P |. n)             : procterm\"\n\nlemma wf_procterm: \"wf procterm\"\n  apply (unfold wf_def)\n  apply (intro strip)\n  apply (induct_tac x)\n\n  apply (erule allE, erule mp, intro strip,\n         erule procterm.cases,\n         simp, simp, simp, simp, simp, simp,\n         simp, simp, simp, simp, simp, simp,\n         simp, simp, simp, simp)+\ndone\n\n(* procterm.elims in Isabelle 2005 \n   -->  procterm.cases in Isabelle 2007 *)\n\n(*-------------------------------------------------------* \n |                                                       |\n |      decompostion controlled by Not_Decompo_Flag      |\n |                                                       |\n *-------------------------------------------------------*)\n(* Isabelle 2013\nconsts Not_Decompo_Flag :: bool\ndefs   Not_Decompo_Flag_def : \"Not_Decompo_Flag == True\"\n*)\n\ndefinition\n  Not_Decompo_Flag :: bool\n  where\n  Not_Decompo_Flag_def : \"Not_Decompo_Flag == True\"\n\nlemma on_Not_Decompo_Flag: \"Not_Decompo_Flag & R ==> R\"\nby (simp)\n\nlemma off_Not_Decompo_Flag: \"R ==> Not_Decompo_Flag & R\"\nby (simp add: Not_Decompo_Flag_def)\n\nlemma off_Not_Decompo_Flag_True: \"Not_Decompo_Flag\"\nby (simp add: Not_Decompo_Flag_def)\n\n(*\nML_setup {*\n    val ON_Not_Decompo_Flag       = thms \"on_Not_Decompo_Flag\";\n    val OFF_Not_Decompo_Flag      = thms \"off_Not_Decompo_Flag\";\n    val OFF_Not_Decompo_Flag_True = thms \"off_Not_Decompo_Flag_True\";\n*}\nfor Isabelle 2007\n*)\n\nML {*\n    val ON_Not_Decompo_Flag       = @{thms on_Not_Decompo_Flag};\n    val OFF_Not_Decompo_Flag      = @{thms off_Not_Decompo_Flag};\n    val OFF_Not_Decompo_Flag_True = @{thms off_Not_Decompo_Flag_True};\n*}\n\n(*-------------------------------------------------------* \n |                                                       |\n |        rewriting controlled by Not_Rewrite_Flag       |\n |                      CSP-Prover 5                     |\n *-------------------------------------------------------*)\n(* Isabelle 2013\nconsts Not_Rewrite_Flag :: bool\ndefs   Not_Rewrite_Flag_def : \"Not_Rewrite_Flag == True\"\n*)\n\ndefinition\n  Not_Rewrite_Flag :: bool\n  where\n  \"Not_Rewrite_Flag == True\"\n\nlemma on_Not_Rewrite_Flag: \"Not_Rewrite_Flag & R ==> R\"\nby (simp)\n\nlemma off_Not_Rewrite_Flag: \"R ==> Not_Rewrite_Flag & R\"\nby (simp add: Not_Rewrite_Flag_def)\n\nlemma off_Not_Rewrite_Flag_True: \"Not_Rewrite_Flag\"\nby (simp add: Not_Rewrite_Flag_def)\n\nlemmas off_All_Flag_True = off_Not_Decompo_Flag_True\n                           off_Not_Rewrite_Flag_True\n\nML {*\n    val ON_Not_Rewrite_Flag       = @{thms on_Not_Rewrite_Flag};\n    val OFF_Not_Rewrite_Flag      = @{thms off_Not_Rewrite_Flag};\n    val OFF_Not_Rewrite_Flag_True = @{thms off_Not_Rewrite_Flag_True};\n    val OFF_All_Flag_True         = @{thms off_All_Flag_True};\n*}\n\n(* 0 *)\n(****************** to add them again ******************)\n(*\ndeclare Union_image_eq [simp]\ndeclare Inter_image_eq [simp]\n*)\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/CSP/CSP_syntax.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6654105454764747, "lm_q2_score": 0.38861802670584894, "lm_q1q2_score": 0.25859053313233016}}
{"text": "chapter\\<open>Heuristics\\<close>\ntext\\<open>As part of this inference technique, we make use of certain \\emph{heuristics} to abstract away\nconcrete values into registers. This allows us to generalise from examples of behaviour. These\nheuristics are as follows.\n\n\\begin{description}\n  \\item [Store and Reuse] - This heuristic aims to recognise when input values are subsequently used\nas an output. Such behaviour is generalised by storing the relevant input in a register, and\nreplacing the literal output with the content of the register. This enables the EFSM to\n\\emph{predict} how the underlying system might behave when faced with unseen inputs.\n  \\item [Increment and Reset] - This heuristic is a naive attempt to introduce additive behaviour.\nThe idea here is that if we want to merge two transitions with identical input values and different\nnumeric outputs, for example $\\textit{coin}:1[i_0=50]/o_0:=50$ and $\\textit{coin}:1[i_0=50]/o_0:=100$,\nthen the behaviour must depend on the value of an internal variable. This heuristic works by\ndropping the input guard and adding an update to a fresh register, in this case summing the current\nregister value with the input. A similar principle can be applied to other numeric functions such as\nsubtraction.\n  \\item [Same Register] - Because of the way heuristics are applied, it is possible for different\nregisters to be introduced to serve the same purpose. This heuristic attempts to identify when this\nhas happened and merge the two registers.\n  \\item [Least Upper Bound] - In certain situations, transitions may produce the same output for\ndifferent inputs. This technique forms the least upper bound of the transition guards\n--- their disjunction --- such that they can be merged into a single behaviour.\n  \\item [Distinguishing Guards] - Under certain circumstances, we explicitly do not want to merge\ntwo transitions into one. This heuristic resolves nondeterminism between transitions by attempting\nto find apply mutually exclusive guards to each transition such that their behaviour is distinguished.\n\\end{description}\\<close>\n\nsection\\<open>Store and Reuse\\<close>\ntext\\<open>An obvious candidate for generalisation is the ``store and reuse'' pattern. This manifests\nitself  when the input of one transition is subsequently used as the output of another. Recognising\nthis usage pattern allows us to introduce a \\emph{storage register} to abstract away concrete data\nvalues and replace two transitions whose outputs differ with a single transition that outputs the\ncontent of the register.\\<close>\n\ntheory Store_Reuse\nimports \"../Inference\"\nbegin\ndatatype ioTag = In | Out\n\ninstantiation ioTag :: linorder begin\nfun less_ioTag :: \"ioTag \\<Rightarrow> ioTag \\<Rightarrow> bool\" where\n  \"In < Out = True\" |\n  \"Out < _ = False\" |\n  \"In < In = False\"\n\ndefinition less_eq_ioTag :: \"ioTag \\<Rightarrow> ioTag \\<Rightarrow> bool\" where\n  \"less_eq_ioTag x y = (x < y \\<or> x = y)\"\ndeclare less_eq_ioTag_def [simp]\n\ninstance\n  apply standard\n  using less_ioTag.elims(2) apply fastforce\n     apply simp\n    apply (metis ioTag.exhaust less_eq_ioTag_def)\n  using less_eq_ioTag_def less_ioTag.elims(2) apply blast\n  by (metis (full_types) ioTag.exhaust less_eq_ioTag_def less_ioTag.simps(1))\nend\n\ntype_synonym index = \"nat \\<times> ioTag \\<times> nat\"\n\nfun lookup :: \"index \\<Rightarrow> trace \\<Rightarrow> value\" where\n  \"lookup (actionNo, In, inx) t = (let (_, inputs, _) = nth t actionNo in nth inputs inx)\" |\n  \"lookup (actionNo, Out, inx) t = (let (_, _, outputs) = nth t actionNo in nth outputs inx)\"\n\nabbreviation actionNum :: \"index \\<Rightarrow> nat\" where\n  \"actionNum i \\<equiv> fst i\"\n\nabbreviation ioTag :: \"index \\<Rightarrow> ioTag\" where\n  \"ioTag i \\<equiv> fst (snd i)\"\n\nabbreviation inx :: \"index \\<Rightarrow> nat\" where\n  \"inx i \\<equiv> snd (snd i)\"\n\nprimrec index :: \"value list \\<Rightarrow> nat \\<Rightarrow> ioTag \\<Rightarrow> nat \\<Rightarrow> index fset\" where\n  \"index [] _ _ _ = {||}\" |\n  \"index (h#t) actionNo io ind = finsert (actionNo, io, ind) (index t actionNo io (ind + 1))\"\n\ndefinition io_index :: \"nat \\<Rightarrow> value list \\<Rightarrow> value list \\<Rightarrow> index fset\" where\n  \"io_index actionNo inputs outputs = (index inputs actionNo In 0) |\\<union>| (index outputs actionNo Out 0)\"\n\ndefinition indices :: \"trace \\<Rightarrow> index fset\" where\n  \"indices e = foldl (|\\<union>|) {||} (map (\\<lambda>(actionNo, (label, inputs, outputs)). io_index actionNo inputs outputs) (enumerate 0 e))\"\n\ndefinition get_by_id_intratrace_matches :: \"trace \\<Rightarrow> (index \\<times> index) fset\" where\n  \"get_by_id_intratrace_matches e = ffilter (\\<lambda>(a, b). lookup a e = lookup b e \\<and> actionNum a \\<le> actionNum b \\<and> a \\<noteq> b) (indices e |\\<times>| indices e)\"\n\n(*\n  If the EFSM is nondeterministic, we need to make sure it chooses the right path so that it recognises\n  the input trace.\n*)\ndefinition i_step :: \"execution \\<Rightarrow> iEFSM \\<Rightarrow> cfstate \\<Rightarrow> registers \\<Rightarrow> label \\<Rightarrow> inputs \\<Rightarrow> (transition \\<times> cfstate \\<times> tids \\<times> registers) option\" where\n  \"i_step tr e s r l i = (let\n    poss_steps = (i_possible_steps e s r l i);\n    possibilities = ffilter (\\<lambda>(u, s', t). recognises_execution (tm e) s' (evaluate_updates t i r) tr) poss_steps in\n    case random_member possibilities of\n      None \\<Rightarrow> None |\n      Some (u, s', t) \\<Rightarrow>\n      Some (t, s', u, (evaluate_updates t i r))\n  )\"\n\ntype_synonym match = \"(((transition \\<times> tids) \\<times> ioTag \\<times> nat) \\<times> ((transition \\<times> tids) \\<times> ioTag \\<times> nat))\"\n\ndefinition \"exec2trace t = map (\\<lambda>(label, inputs, _). (label, inputs)) t\"\nprimrec (nonexhaustive) walk_up_to :: \"nat \\<Rightarrow> iEFSM \\<Rightarrow> nat \\<Rightarrow> registers \\<Rightarrow> trace \\<Rightarrow> (transition \\<times> tids)\" where\n  \"walk_up_to n e s r (h#t) =\n    (case (i_step (exec2trace t) e s r (fst h) (fst (snd h))) of\n      (Some (transition, s', uid, updated)) \\<Rightarrow> (case n of 0 \\<Rightarrow> (transition, uid) | Suc m \\<Rightarrow> walk_up_to m e s' updated t)\n    )\"\n\ndefinition find_intertrace_matches_aux :: \"(index \\<times> index) fset \\<Rightarrow> iEFSM \\<Rightarrow> trace \\<Rightarrow> match fset\" where\n  \"find_intertrace_matches_aux intras e t = fimage (\\<lambda>((e1, io1, inx1), (e2, io2, inx2)). (((walk_up_to e1 e 0 <> t), io1, inx1), ((walk_up_to e2 e 0 <> t), io2, inx2))) intras\"\n\ndefinition find_intertrace_matches :: \"log \\<Rightarrow> iEFSM \\<Rightarrow> match list\" where\n  \"find_intertrace_matches l e = filter (\\<lambda>((e1, io1, inx1), (e2, io2, inx2)). e1 \\<noteq> e2) (concat (map (\\<lambda>(t, m). sorted_list_of_fset (find_intertrace_matches_aux m e t)) (zip l (map get_by_id_intratrace_matches l))))\"\n\ndefinition total_max_input :: \"iEFSM \\<Rightarrow> nat\" where\n  \"total_max_input e = (case EFSM.max_input (tm e) of None \\<Rightarrow> 0 | Some i \\<Rightarrow> i)\"\n\ndefinition total_max_reg :: \"iEFSM \\<Rightarrow> nat\" where\n  \"total_max_reg e = (case EFSM.max_reg (tm e) of None \\<Rightarrow> 0 | Some i \\<Rightarrow> i)\"\n\ndefinition remove_guard_add_update :: \"transition \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> transition\" where\n  \"remove_guard_add_update t inputX outputX = \\<lparr>\n    Label = (Label t), Arity = (Arity t),\n    Guards = (filter (\\<lambda>g. \\<not> gexp_constrains g (V (vname.I inputX))) (Guards t)),\n    Outputs = (Outputs t),\n    Updates = (outputX, (V (vname.I inputX)))#(Updates t)\n  \\<rparr>\"\n\ndefinition generalise_output :: \"transition \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> transition\" where\n  \"generalise_output t regX outputX = \\<lparr>\n      Label = (Label t),\n      Arity = (Arity t),\n      Guards = (Guards t),\n      Outputs = list_update (Outputs t) outputX (V (R regX)),\n      Updates = (Updates t)\n    \\<rparr>\"\n\ndefinition is_generalised_output_of :: \"transition \\<Rightarrow> transition \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"is_generalised_output_of t' t r p = (t' = generalise_output t r p)\"\n\nprimrec count :: \"'a \\<Rightarrow> 'a list \\<Rightarrow> nat\" where\n  \"count _ [] = 0\" |\n  \"count a (h#t) = (if a = h then 1+(count a t) else count a t)\"\n\ndefinition replaceAll :: \"iEFSM \\<Rightarrow> transition \\<Rightarrow> transition \\<Rightarrow> iEFSM\" where\n  \"replaceAll e old new = fimage (\\<lambda>(uid, (from, dest), t). if t = old then (uid, (from, dest), new) else (uid, (from, dest), t)) e\"\n\nprimrec generalise_transitions :: \"((((transition \\<times> tids) \\<times> ioTag \\<times> nat) \\<times> (transition \\<times> tids) \\<times> ioTag \\<times> nat) \\<times>\n     ((transition \\<times> tids) \\<times> ioTag \\<times> nat) \\<times> (transition \\<times> tids) \\<times> ioTag \\<times> nat) list \\<Rightarrow> iEFSM \\<Rightarrow> iEFSM\" where\n  \"generalise_transitions [] e = e\" |\n  \"generalise_transitions (h#t) e = (let\n    ((((orig1, u1), _), (orig2, u2), _), (((gen1, u1'), _), (gen2, u2), _)) = h in\n   generalise_transitions t (replaceAll (replaceAll e orig1 gen1) orig2 gen2))\"\n\ndefinition strip_uids :: \"(((transition \\<times> tids) \\<times> ioTag \\<times> nat) \\<times> (transition \\<times> tids) \\<times> ioTag \\<times> nat) \\<Rightarrow> ((transition \\<times> ioTag \\<times> nat) \\<times> (transition \\<times> ioTag \\<times> nat))\" where\n  \"strip_uids x = (let (((t1, u1), io1, in1), (t2, u2), io2, in2) = x in ((t1, io1, in1), (t2, io2, in2)))\"\n\ndefinition modify :: \"match list \\<Rightarrow> tids \\<Rightarrow> tids \\<Rightarrow> iEFSM \\<Rightarrow> iEFSM option\" where\n  \"modify matches u1 u2 old = (let relevant = filter (\\<lambda>(((_, u1'), io, _), (_, u2'), io', _). io = In \\<and> io' = Out \\<and> (u1 = u1' \\<or> u2 = u1' \\<or> u1 = u2' \\<or> u2 = u2')) matches;\n                                   newReg = case max_reg old of None \\<Rightarrow> 1 | Some r \\<Rightarrow> r + 1;\n                                   replacements = map (\\<lambda>(((t1, u1), io1, inx1), (t2, u2), io2, inx2). (((remove_guard_add_update t1 inx1 newReg, u1), io1, inx1), (generalise_output t2 newReg inx2, u2), io2, inx2)) relevant;\n                                   comparisons = zip relevant replacements;\n                                   stripped_replacements = map strip_uids replacements;\n                                   to_replace = filter (\\<lambda>(_, s). count (strip_uids s) stripped_replacements > 1) comparisons in\n                                if to_replace = [] then None else Some ((generalise_transitions to_replace old))\n                              )\"\n\n(* type_synonym update_modifier = \"transition \\<Rightarrow> transition \\<Rightarrow> nat \\<Rightarrow> iEFSM \\<Rightarrow> iEFSM \\<Rightarrow> (iEFSM \\<times> (nat \\<Rightarrow> nat) \\<times> (nat \\<Rightarrow> nat)) option\" *)\ndefinition heuristic_1 :: \"log \\<Rightarrow> update_modifier\" where\n  \"heuristic_1 l t1 t2 s new _ old check = (case modify (find_intertrace_matches l old) t1 t2 new of\n    None \\<Rightarrow> None |\n    Some e \\<Rightarrow> if check (tm e) then Some e else None\n  )\"\n\nlemma remove_guard_add_update_preserves_outputs:\n  \"Outputs (remove_guard_add_update t i r) = Outputs t\"\n  by (simp add: remove_guard_add_update_def)\n\nlemma remove_guard_add_update_preserves_label:\n  \"Label (remove_guard_add_update t i r) = Label t\"\n  by (simp add: remove_guard_add_update_def)\n\nlemma remove_guard_add_update_preserves_arity:\n  \"Arity (remove_guard_add_update t i r) = Arity t\"\n  by (simp add: remove_guard_add_update_def)\n\nlemmas remove_guard_add_update_preserves = remove_guard_add_update_preserves_label\n                                           remove_guard_add_update_preserves_arity\n                                           remove_guard_add_update_preserves_outputs\n\ndefinition is_generalisation_of :: \"transition \\<Rightarrow> transition \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"is_generalisation_of t' t i r = (t' = remove_guard_add_update t i r \\<and>\n                                    i < Arity t \\<and>\n                                    (\\<exists>v. Eq (V (vname.I i)) (L v) \\<in> set (Guards t)) \\<and>\n                                    r \\<notin> set (map fst (Updates t)))\"\n\nlemma generalise_output_preserves_label:\n  \"Label (generalise_output t r p) = Label t\"\n  by (simp add: generalise_output_def)\n\nlemma generalise_output_preserves_arity:\n  \"Arity (generalise_output t r p) = Arity t\"\n  by (simp add: generalise_output_def)\n\nlemma generalise_output_preserves_guard:\n  \"Guards (generalise_output t r p) = Guards t\"\n  by (simp add: generalise_output_def)\n\nlemma generalise_output_preserves_output_length:\n  \"length (Outputs (generalise_output t r p)) = length (Outputs t)\"\n  by (simp add: generalise_output_def)\n\nlemma generalise_output_preserves_updates:\n  \"Updates (generalise_output t r p) = Updates t\"\n  by (simp add: generalise_output_def)\n\nlemmas generalise_output_preserves = generalise_output_preserves_label\n                                     generalise_output_preserves_arity\n                                     generalise_output_preserves_output_length\n                                     generalise_output_preserves_guard\n                                     generalise_output_preserves_updates\n\ndefinition is_proper_generalisation_of :: \"transition \\<Rightarrow> transition \\<Rightarrow> iEFSM \\<Rightarrow> bool\" where\n \"is_proper_generalisation_of t' t e = (\\<exists>i \\<le> total_max_input e. \\<exists> r \\<le> total_max_reg e.\n                                        is_generalisation_of t' t i r \\<and>\n                                        (\\<forall>u \\<in> set (Updates t). fst u \\<noteq> r) \\<and>\n                                        (\\<forall>i \\<le> max_input (tm e). \\<forall>u \\<in> set (Updates t). fst u \\<noteq> r)\n                                       )\"\n\n(* Recognising the same input used in multiple guards *)\ndefinition generalise_input :: \"transition \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> transition\" where\n  \"generalise_input t r i = \\<lparr>\n      Label = Label t,\n      Arity = Arity t,\n      Guards = map (\\<lambda>g. case g of Eq (V (I i')) (L _) \\<Rightarrow> if i = i' then Eq (V (I i)) (V (R r)) else g | _ \\<Rightarrow> g) (Guards t),\n      Outputs = Outputs t,\n      Updates = Updates t\n    \\<rparr>\"\n\nfun structural_count :: \"((transition \\<times> ioTag \\<times> nat) \\<times> (transition \\<times> ioTag \\<times> nat)) \\<Rightarrow> ((transition \\<times> ioTag \\<times> nat) \\<times> (transition \\<times> ioTag \\<times> nat)) list \\<Rightarrow> nat\" where\n  \"structural_count _ [] = 0\" |\n  \"structural_count a (((t1', io1', i1'), (t2', io2', i2'))#t) = (\n    let ((t1, io1, i1), (t2, io2, i2)) = a in\n    if same_structure t1 t1' \\<and> same_structure t2 t2' \\<and>\n       io1 = io1' \\<and> io2 = io2' \\<and>\n       i1 = i1' \\<and> i2 = i2'\n    then\n      1+(structural_count a t)\n    else\n      structural_count a t\n    )\"\n\ndefinition remove_guards_add_update :: \"transition \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> transition\" where\n  \"remove_guards_add_update t inputX outputX = \\<lparr>\n    Label = (Label t), Arity = (Arity t),\n    Guards = [],\n    Outputs = (Outputs t),\n    Updates = (outputX, (V (vname.I inputX)))#(Updates t)\n  \\<rparr>\"\n\ndefinition modify_2 :: \"match list \\<Rightarrow> tids \\<Rightarrow> tids \\<Rightarrow> iEFSM \\<Rightarrow> iEFSM option\" where\n  \"modify_2 matches u1 u2 old = (let relevant = filter (\\<lambda>(((_, u1'), io, _), (_, u2'), io', _). io = In \\<and> io' = In \\<and> (u1 = u1' \\<or> u2 = u1' \\<or> u1 = u2' \\<or> u2 = u2')) matches;\n                                   newReg = case max_reg old of None \\<Rightarrow> 1 | Some r \\<Rightarrow> r + 1;\n                                   replacements = map (\\<lambda>(((t1, u1), io1, inx1), (t2, u2), io2, inx2).\n                                                  (((remove_guards_add_update t1 inx1 newReg, u1), io1, inx1),\n                                                    (generalise_input t2 newReg inx2, u2), io2, inx2)) relevant;\n                                   comparisons = zip relevant replacements;\n                                   stripped_replacements = map strip_uids replacements;\n                                   to_replace = filter (\\<lambda>(_, s). structural_count (strip_uids s) stripped_replacements > 1) comparisons in\n                                if to_replace = [] then None else Some ((generalise_transitions to_replace old))\n                              )\"\n\n(* type_synonym update_modifier = \"transition \\<Rightarrow> transition \\<Rightarrow> nat \\<Rightarrow> iEFSM \\<Rightarrow> iEFSM \\<Rightarrow> (iEFSM \\<times> (nat \\<Rightarrow> nat) \\<times> (nat \\<Rightarrow> nat)) option\" *)\ndefinition heuristic_2 :: \"log \\<Rightarrow> update_modifier\" where\n  \"heuristic_2 l t1 t2 s new _ old check = (case modify_2 (find_intertrace_matches l old) t1 t2 new of\n    None \\<Rightarrow> None |\n    Some e \\<Rightarrow> if check (tm e) then Some e else None\n  )\"\nhide_const ioTag.In\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Extended_Finite_State_Machine_Inference/heuristics/Store_Reuse.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5467381667555714, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.25843409746310547}}
{"text": "(*\n    Author:      David Sanan                   \n    Maintainer:  David Sanan, sanan@ntu.edu.sg\n    License:     LGPL\n*)\n\n(*  Title:      Hoare.thy\n    Author:     Norbert Schirmer, TU Muenchen\n     \t        David Sanan, NTU Singapore\n\nCopyright (C) 2016-2020 David Sanan, 2004-2008 Norbert Schirmer\nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection {* Auxiliary Definitions/Lemmas to Facilitate Hoare Logic *}\ntheory Hoare imports LocalRG_HoareDef begin\n\n(*\nsyntax \n\n\"_hoarep_emptyFaults\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,\n   'f set,'s assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n    (\"(3_,_/\\<turnstile> (_/ (_)/ _,/_))\" [61,60,1000,20,1000,1000]60)\n\n\"_hoarep_emptyCtx\"::\n\"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n    (\"(3_/\\<turnstile>\\<^bsub>'/_\\<^esub> (_/ (_)/ _,/_))\" [61,60,1000,20,1000,1000]60)\n\n\"_hoarep_emptyCtx_emptyFaults\"::\n\"[('s,'p,'f) body,'s assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n    (\"(3_/\\<turnstile> (_/ (_)/ _,/_))\" [61,1000,20,1000,1000]60)\n\n\"_hoarep_noAbr\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,'f set,\n    's assn,('s,'p,'f) com, 's assn] => bool\"\n    (\"(3_,_/\\<turnstile>\\<^bsub>'/_\\<^esub> (_/ (_)/ _))\" [61,60,60,1000,20,1000]60)\n\n\"_hoarep_noAbr_emptyFaults\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,'s assn,('s,'p,'f) com, 's assn] => bool\"\n    (\"(3_,_/\\<turnstile> (_/ (_)/ _))\" [61,60,1000,20,1000]60)\n\n\"_hoarep_emptyCtx_noAbr\"::\n\"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com, 's assn] => bool\"\n    (\"(3_/\\<turnstile>\\<^bsub>'/_\\<^esub> (_/ (_)/ _))\" [61,60,1000,20,1000]60)\n\n\"_hoarep_emptyCtx_noAbr_emptyFaults\"::\n\"[('s,'p,'f) body,'s assn,('s,'p,'f) com, 's assn] => bool\"\n    (\"(3_/\\<turnstile> (_/ (_)/ _))\" [61,1000,20,1000]60)\n\n\n\n\"_hoaret_emptyFaults\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,\n    's assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n    (\"(3_,_/\\<turnstile>\\<^sub>t (_/ (_)/ _,/_))\" [61,60,1000,20,1000,1000]60)\n\n\"_hoaret_emptyCtx\"::\n\"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n    (\"(3_/\\<turnstile>\\<^sub>t\\<^bsub>'/_\\<^esub> (_/ (_)/ _,/_))\" [61,60,1000,20,1000,1000]60)\n\n\"_hoaret_emptyCtx_emptyFaults\"::\n\"[('s,'p,'f) body,'s assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n    (\"(3_/\\<turnstile>\\<^sub>t (_/ (_)/ _,/_))\" [61,1000,20,1000,1000]60)\n\n\"_hoaret_noAbr\"::\n\"[('s,'p,'f) body,'f set, ('s,'p) quadruple set,\n    's assn,('s,'p,'f) com, 's assn] => bool\"\n    (\"(3_,_/\\<turnstile>\\<^sub>t\\<^bsub>'/_\\<^esub> (_/ (_)/ _))\" [61,60,60,1000,20,1000]60)\n\n\"_hoaret_noAbr_emptyFaults\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,'s assn,('s,'p,'f) com, 's assn] => bool\"\n    (\"(3_,_/\\<turnstile>\\<^sub>t (_/ (_)/ _))\" [61,60,1000,20,1000]60)\n\n\"_hoaret_emptyCtx_noAbr\"::\n\"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com, 's assn] => bool\"\n    (\"(3_/\\<turnstile>\\<^sub>t\\<^bsub>'/_\\<^esub> (_/ (_)/ _))\" [61,60,1000,20,1000]60)\n\n\"_hoaret_emptyCtx_noAbr_emptyFaults\"::\n\"[('s,'p,'f) body,'s assn,('s,'p,'f) com, 's assn] => bool\"\n    (\"(3_/\\<turnstile>\\<^sub>t (_/ (_)/ _))\" [61,1000,20,1000]60)\n\n\nsyntax (ascii)\n\n\"_hoarep_emptyFaults\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,\n     's assn,('s,'p,'f) com, 's assn,'s assn] \\<Rightarrow> bool\"\n   (\"(3_,_/|- (_/ (_)/ _,/_))\" [61,60,1000,20,1000,1000]60)\n\n\"_hoarep_emptyCtx\"::\n\"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n   (\"(3_/|-'/_ (_/ (_)/ _,/_))\" [61,60,1000,20,1000,1000]60)\n\n\"_hoarep_emptyCtx_emptyFaults\"::\n\"[('s,'p,'f) body,'s assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n   (\"(3_/|-(_/ (_)/ _,/_))\" [61,1000,20,1000,1000]60)\n\n\"_hoarep_noAbr\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,'f set,\n   's assn,('s,'p,'f) com, 's assn] => bool\"\n   (\"(3_,_/|-'/_ (_/ (_)/ _))\" [61,60,60,1000,20,1000]60)\n\n\"_hoarep_noAbr_emptyFaults\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,'s assn,('s,'p,'f) com, 's assn] => bool\"\n   (\"(3_,_/|-(_/ (_)/ _))\" [61,60,1000,20,1000]60)\n\n\"_hoarep_emptyCtx_noAbr\"::\n\"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com, 's assn] => bool\"\n   (\"(3_/|-'/_ (_/ (_)/ _))\" [61,60,1000,20,1000]60)\n\n\"_hoarep_emptyCtx_noAbr_emptyFaults\"::\n\"[('s,'p,'f) body,'s assn,('s,'p,'f) com, 's assn] => bool\"\n   (\"(3_/|-(_/ (_)/ _))\" [61,1000,20,1000]60)\n\n\"_hoaret_emptyFault\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,\n     's assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n   (\"(3_,_/|-t (_/ (_)/ _,/_))\" [61,60,1000,20,1000,1000]60)\n\n\"_hoaret_emptyCtx\"::\n\"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n   (\"(3_/|-t'/_ (_/ (_)/ _,/_))\" [61,60,1000,20,1000,1000]60)\n\n\"_hoaret_emptyCtx_emptyFaults\"::\n\"[('s,'p,'f) body,'s assn,('s,'p,'f) com, 's assn,'s assn] => bool\"\n   (\"(3_/|-t(_/ (_)/ _,/_))\" [61,1000,20,1000,1000]60)\n\n\"_hoaret_noAbr\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,'f set,\n   's assn,('s,'p,'f) com, 's assn] => bool\"\n   (\"(3_,_/|-t'/_ (_/ (_)/ _))\" [61,60,60,1000,20,1000]60)\n\n\"_hoaret_noAbr_emptyFaults\"::\n\"[('s,'p,'f) body,('s,'p) quadruple set,'s assn,('s,'p,'f) com, 's assn] => bool\"\n   (\"(3_,_/|-t(_/ (_)/ _))\" [61,60,1000,20,1000]60)\n\n\"_hoaret_emptyCtx_noAbr\"::\n\"[('s,'p,'f) body,'f set,'s assn,('s,'p,'f) com, 's assn] => bool\"\n   (\"(3_/|-t'/_ (_/ (_)/ _))\" [61,60,1000,20,1000]60)\n\n\"_hoaret_emptyCtx_noAbr_emptyFaults\"::\n\"[('s,'p,'f) body,'s assn,('s,'p,'f) com, 's assn] => bool\"\n   (\"(3_/|-t(_/ (_)/ _))\" [61,1000,20,1000]60)\n*)\n(*\ntranslations\n \n\n \"\\<Gamma>\\<turnstile> P c Q,A\"  == \"\\<Gamma>\\<turnstile>\\<^bsub>/{}\\<^esub> P c Q,A\" \n \"\\<Gamma>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"  == \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n\n \"\\<Gamma>,\\<Theta>\\<turnstile> P c Q\"  == \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c Q\"\n \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q\"  == \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,{}\"\n \"\\<Gamma>,\\<Theta>\\<turnstile> P c Q,A\" == \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c Q,A\" \n\n \"\\<Gamma>\\<turnstile> P c Q\"    ==  \"\\<Gamma>\\<turnstile>\\<^bsub>/{}\\<^esub> P c Q\"\n \"\\<Gamma>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q\"  == \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> P c Q\"\n \"\\<Gamma>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q\"  <=  \"\\<Gamma>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,{}\"\n \"\\<Gamma>\\<turnstile> P c Q\"    <=  \"\\<Gamma>\\<turnstile> P c Q,{}\"\n\n\n\n\n \"\\<Gamma>\\<turnstile>\\<^sub>t P c Q,A\"   == \"\\<Gamma>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\n \"\\<Gamma>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"  == \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n\n \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t P c Q\"   == \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q\"\n \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q\" == \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,{}\"\n \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t P c Q,A\"   == \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\n \n \"\\<Gamma>\\<turnstile>\\<^sub>t P c Q\"    == \"\\<Gamma>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q\"\n \"\\<Gamma>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q\"  == \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q\"\n \"\\<Gamma>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q\"  <=  \"\\<Gamma>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,{}\"\n \"\\<Gamma>\\<turnstile>\\<^sub>t P c Q\"    <=  \"\\<Gamma>\\<turnstile>\\<^sub>t P c Q,{}\"\n\n\nterm \"\\<Gamma>\\<turnstile> P c Q\"\nterm \"\\<Gamma>\\<turnstile> P c Q,A\"\n\nterm \"\\<Gamma>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q\"\nterm \"\\<Gamma>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n\nterm \"\\<Gamma>,\\<Theta>\\<turnstile> P c Q\"\nterm \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q\"\n\nterm \"\\<Gamma>,\\<Theta>\\<turnstile> P c Q,A\"\nterm \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n\n\nterm \"\\<Gamma>\\<turnstile>\\<^sub>t P c Q\"\nterm \"\\<Gamma>\\<turnstile>\\<^sub>t P c Q,A\"\n\nterm \"\\<Gamma>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q\"\nterm \"\\<Gamma>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n\nterm \"\\<Gamma>,\\<Theta>\\<turnstile> P c Q\"\nterm \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q\"\n\nterm \"\\<Gamma>,\\<Theta>\\<turnstile> P c Q,A\"\nterm \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n*)\n\nlocale hoare =\n  fixes \\<Gamma>::\"('s,'p,'f,'a) body\" \n\n\nprimrec assoc:: \"('a \\<times>'b) list \\<Rightarrow> 'a \\<Rightarrow> 'b \"\nwhere\n\"assoc [] x = undefined\" |\n\"assoc (p#ps) x = (if fst p = x then (snd p) else assoc ps x)\"\n\nlemma conjE_simp: \"(P \\<and> Q \\<Longrightarrow> PROP R) \\<equiv> (P \\<Longrightarrow> Q \\<Longrightarrow> PROP R)\"\n  by rule simp_all\n\nlemma CollectInt_iff: \"{s. P s} \\<inter> {s. Q s} = {s. P s \\<and> Q s}\"\n  by auto\n\nlemma Compl_Collect:\"-(Collect b) = {x. \\<not>(b x)}\"\n  by fastforce\n\nlemma Collect_False: \"{s. False} = {}\"\n  by simp\n\nlemma Collect_True: \"{s. True} = UNIV\"\n  by simp\n\nlemma triv_All_eq: \"\\<forall>x. P \\<equiv> P\"\n  by simp\n\nlemma triv_Ex_eq: \"\\<exists>x. P \\<equiv> P\"\n  by simp\n\nlemma Ex_True: \"\\<exists>b. b\"\n   by blast\n\nlemma Ex_False: \"\\<exists>b. \\<not>b\"\n  by blast\n\ndefinition mex::\"('a \\<Rightarrow> bool) \\<Rightarrow> bool\"\n  where \"mex P = Ex P\"\n\ndefinition meq::\"'a \\<Rightarrow> 'a \\<Rightarrow> bool\"\n  where \"meq s Z = (s = Z)\"\n\nlemma subset_unI1: \"A \\<subseteq> B \\<Longrightarrow> A \\<subseteq> B \\<union> C\" \n  by blast\n\nlemma subset_unI2: \"A \\<subseteq> C \\<Longrightarrow> A \\<subseteq> B \\<union> C\" \n  by blast\n\nlemma split_paired_UN: \"(\\<Union>p. (P p)) = (\\<Union>a b. (P (a,b)))\" \n  by auto\n\nlemma in_insert_hd: \"f \\<in> insert f X\"\n  by simp\n \nlemma lookup_Some_in_dom: \"\\<Gamma> p = Some bdy \\<Longrightarrow> p \\<in> dom \\<Gamma>\"\n  by auto\n\nlemma unit_object: \"(\\<forall>u::unit. P u) = P ()\"\n  by auto\n\nlemma unit_ex: \"(\\<exists>u::unit. P u) = P ()\"\n  by auto\n\nlemma unit_meta: \"(\\<And>(u::unit). PROP P u) \\<equiv> PROP P ()\"\n  by auto\n\nlemma unit_UN: \"(\\<Union>z::unit. P z) = P ()\"\n  by auto\n\nlemma subset_singleton_insert1: \"y = x \\<Longrightarrow> {y} \\<subseteq> insert x A\"\n  by auto\n\nlemma subset_singleton_insert2: \"{y} \\<subseteq> A \\<Longrightarrow> {y} \\<subseteq> insert x A\"\n  by auto\n\nlemma in_Specs_simp: \"(\\<forall>x\\<in>\\<Union>Z. {(P Z, p, Q Z, A Z)}. Prop x) =\n       (\\<forall>Z. Prop (P Z,p,Q Z,A Z))\"\n  by auto\n\nlemma in_set_Un_simp: \"(\\<forall>x\\<in>A \\<union> B. P x) = ((\\<forall>x \\<in> A. P x) \\<and> (\\<forall>x \\<in> B. P x))\"\n  by auto\n\nlemma split_all_conj: \"(\\<forall>x. P x \\<and> Q x) = ((\\<forall>x. P x) \\<and> (\\<forall>x. Q x))\"\n  by blast\n\nlemma image_Un_single_simp: \"f ` (\\<Union>Z. {P Z}) = (\\<Union>Z. {f (P Z)}) \"\n  by auto\n\n\n\nlemma measure_lex_prod_def': \n  \"f <*mlex*> r \\<equiv> ({(x,y). (x,y) \\<in> measure f \\<or> f x=f y \\<and> (x,y) \\<in>  r})\"\n  by (auto simp add: mlex_prod_def inv_image_def)\n\nlemma in_measure_iff: \"(x,y) \\<in> measure f = (f x < f y)\"\n  by (simp add: measure_def inv_image_def)\n\nlemma in_lex_iff: \n  \"((a,b),(x,y)) \\<in> r <*lex*> s = ((a,x) \\<in> r \\<or> (a=x \\<and> (b,y)\\<in>s))\"\n  by (simp add: lex_prod_def)\n\nlemma in_mlex_iff:\n  \"(x,y) \\<in> f <*mlex*> r = (f x < f y \\<or> (f x=f y \\<and> (x,y) \\<in> r))\"\n  by (simp add: measure_lex_prod_def' in_measure_iff)\n\nlemma in_inv_image_iff: \"(x,y) \\<in> inv_image r f = ((f x, f y) \\<in> r)\" \n  by (simp add: inv_image_def)\n\ntext {* This is actually the same as @{thm [source] wf_mlex}. However, this basic\nproof took me so long that I'm not willing to delete it.\n*}\nlemma wf_measure_lex_prod [simp,intro]:\n  assumes wf_r: \"wf r\"\n  shows \"wf (f <*mlex*> r)\"\nproof (rule ccontr)\n  assume \" \\<not> wf (f <*mlex*> r)\"\n  then\n  obtain g where \"\\<forall>i. (g (Suc i), g i) \\<in> f <*mlex*> r\"\n    by (auto simp add: wf_iff_no_infinite_down_chain)\n  hence g: \"\\<forall>i. (g (Suc i), g i) \\<in> measure f \\<or>\n    f (g (Suc i)) = f (g i) \\<and> (g (Suc i), g i) \\<in> r\"\n    by (simp add: measure_lex_prod_def')\n  hence le_g: \"\\<forall>i. f (g (Suc i)) \\<le> f (g i)\"\n    by (auto simp add: in_measure_iff order_le_less)\n  have \"wf (measure f)\"\n    by simp\n  hence \" \\<forall>Q. (\\<exists>x. x \\<in> Q) \\<longrightarrow> (\\<exists>z\\<in>Q. \\<forall>y. (y, z) \\<in> measure f \\<longrightarrow> y \\<notin> Q)\"\n    by (simp add: wf_eq_minimal)\n  from this [rule_format, of \"g ` UNIV\"]\n  have \"\\<exists>z. z \\<in> range g \\<and> (\\<forall>y. (y, z) \\<in> measure f \\<longrightarrow> y \\<notin> range g)\"\n    by auto\n  then obtain z where \n    z: \"z \\<in> range g\" and\n    min_z: \"\\<forall>y. f y < f z \\<longrightarrow> y \\<notin> range g\"\n    by (auto simp add: in_measure_iff)\n  from z obtain k where \n    k: \"z = g k\"\n    by auto\n  have \"\\<forall>i. k \\<le> i \\<longrightarrow> f (g i) = f (g k)\" \n  proof (intro allI impI) \n    fix i\n    assume \"k \\<le> i\" then show \"f (g i) = f (g k)\"\n    proof (induct i)\n      case 0\n      have \"k \\<le> 0\" by fact hence \"k = 0\" by simp\n      thus \"f (g 0) = f (g k)\"\n        by simp\n    next\n      case (Suc n)\n      have k_Suc_n: \"k \\<le> Suc n\" by fact\n      then show \"f (g (Suc n)) = f (g k)\"\n      proof (cases \"k = Suc n\")\n        case True\n        thus ?thesis by simp\n      next\n        case False\n        with k_Suc_n\n        have \"k \\<le> n\"\n          by simp\n        with Suc.hyps\n        have n_k: \"f (g n) = f (g k)\" by simp\n        from le_g have le: \"f (g (Suc n)) \\<le> f (g n)\"\n          by simp\n        show ?thesis\n        proof (cases \"f (g (Suc n)) = f (g n)\")\n          case True with n_k show ?thesis by simp\n        next\n          case False\n          with le have \"f (g (Suc n)) < f (g n)\"\n            by simp\n          with n_k k have \"f (g (Suc n)) < f z\"\n            by simp\n          with min_z have \"g (Suc n) \\<notin> range g\"\n            by blast\n          hence False by simp\n          thus ?thesis\n            by simp\n        qed\n      qed\n    qed\n  qed\n  with k [symmetric] have \"\\<forall>i. k \\<le> i \\<longrightarrow> f (g i) = f z\" \n    by simp\n  hence \"\\<forall>i. k \\<le> i \\<longrightarrow> f (g (Suc i)) = f (g i)\"\n    by simp\n  with g have \"\\<forall>i. k \\<le> i \\<longrightarrow> (g (Suc i),(g i)) \\<in> r\"\n    by (auto simp add: in_measure_iff order_less_le )\n  hence \"\\<forall>i. (g (Suc (i+k)),(g (i+k))) \\<in> r\"\n    by simp\n  then\n  have \"\\<exists>f. \\<forall>i. (f (Suc i), f i) \\<in> r\"\n    by - (rule exI [where x=\"\\<lambda>i. g (i+k)\"],simp) \n  with wf_r show False\n    by (simp add: wf_iff_no_infinite_down_chain)\nqed\n\nlemmas all_imp_to_ex = all_simps (5)  \n(*\"!!P Q. (ALL x. P x --> Q) = ((EX x. P x) --> Q)\"\n\n Avoid introduction of existential quantification of states on negative\n position.\n*)\n\n", "meta": {"author": "CompSoftVer", "repo": "CSim2", "sha": "b09a4d77ea089168b1805db5204ac151df2b9eff", "save_path": "github-repos/isabelle/CompSoftVer-CSim2", "path": "github-repos/isabelle/CompSoftVer-CSim2/CSim2-b09a4d77ea089168b1805db5204ac151df2b9eff/ConCSimpl/Hoare.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.2584340904811179}}
{"text": "section \\<open>Code Generation for SCC-Computation \\label{sec:scc_code}\\<close>\ntheory Gabow_SCC_Code\nimports \n  Gabow_SCC \n  Gabow_Skeleton_Code\n  CAVA_Base.CAVA_Code_Target\nbegin\n\n\nsection \\<open>Automatic Refinement to Efficient Data Structures\\<close>\ncontext fr_graph_impl_loc\nbegin\n  schematic_goal last_seg_code_aux: \n    \"(?c,last_seg_impl)\\<in>GSi_rel \\<rightarrow> \\<langle>\\<langle>node_rel\\<rangle>list_set_rel\\<rangle>nres_rel\"\n    unfolding last_seg_impl_def_opt[abs_def] \n    using [[autoref_trace_failed_id]]\n    apply (autoref (keep_goal,trace))\n    done\n  concrete_definition (in -) last_seg_code \n    uses fr_graph_impl_loc.last_seg_code_aux\n  lemmas [autoref_rules] = last_seg_code.refine[OF locale_this]\n\n  context begin interpretation autoref_syn .\n\n    \n\n  schematic_goal compute_SCC_code_aux:\n    \"(?c,compute_SCC_impl) \\<in> \\<langle>\\<langle>\\<langle>node_rel\\<rangle>list_set_rel\\<rangle>list_rel\\<rangle>nres_rel\"\n    unfolding compute_SCC_impl_def[abs_def] initial_impl_def GS_initial_impl_def\n    unfolding path_is_empty_impl_def is_on_stack_impl_def is_done_impl_def \n      is_done_oimpl_def\n    unfolding GS.is_on_stack_impl_def GS.is_done_impl_def\n    using [[autoref_trace_failed_id]]\n    apply (autoref (keep_goal,trace))\n    done\n\n  concrete_definition (in -) compute_SCC_code \n    uses fr_graph_impl_loc.compute_SCC_code_aux\n  lemmas [autoref_rules] = compute_SCC_code.refine[OF locale_this] \n\n  schematic_goal last_seg_tr_aux: \"RETURN ?c \\<le> last_seg_code s\"\n    unfolding last_seg_code_def by refine_transfer\n  concrete_definition (in -) last_seg_tr uses fr_graph_impl_loc.last_seg_tr_aux\n  lemmas [refine_transfer] = last_seg_tr.refine[OF locale_this]\n\n  schematic_goal compute_SCC_tr_aux: \"RETURN ?c \\<le> compute_SCC_code node_eq_impl node_hash_impl node_def_hash_size g\"\n    unfolding compute_SCC_code_def by refine_transfer\n  concrete_definition (in -) compute_SCC_tr \n    uses fr_graph_impl_loc.compute_SCC_tr_aux\n  lemmas [refine_transfer] = compute_SCC_tr.refine[OF locale_this]\nend\n\nexport_code compute_SCC_tr checking SML\n\nsection \\<open>Correctness Theorem\\<close>\n\ntheorem compute_SCC_tr_correct:\n  \\<comment> \\<open>Correctness theorem for the constant we extracted to SML\\<close>\n  fixes Re and node_rel :: \"('vi \\<times> 'v) set\"\n  fixes G :: \"('v,'more) graph_rec_scheme\"\n  assumes A: \n      \"(G_impl,G)\\<in>\\<langle>Re,node_rel\\<rangle>g_impl_rel_ext\"\n      \"(node_eq_impl, (=)) \\<in> node_rel \\<rightarrow> node_rel \\<rightarrow> bool_rel\"\n      \"is_bounded_hashcode node_rel node_eq_impl node_hash_impl\"\n      \"(is_valid_def_hm_size TYPE('vi) node_def_hash_size)\"\n  \n  assumes C: \"fr_graph G\"\n  shows \"RETURN (compute_SCC_tr node_eq_impl node_hash_impl node_def_hash_size G_impl) \n  \\<le> \\<Down>(\\<langle>\\<langle>node_rel\\<rangle>list_set_rel\\<rangle>list_rel) (fr_graph.compute_SCC_spec G)\"\nproof -\n  from C interpret fr_graph G .\n  have I: \"fr_graph_impl_loc Re node_rel node_eq_impl node_hash_impl node_def_hash_size G_impl G\"\n    apply unfold_locales using A .\n  then interpret fr_graph_impl_loc Re node_rel node_eq_impl node_hash_impl node_def_hash_size G_impl G .\n\n  note compute_SCC_tr.refine[OF I]\n  also note compute_SCC_code.refine[OF I, THEN nres_relD]\n  also note compute_SCC_impl_refine\n  also note compute_SCC_correct\n  finally show ?thesis using A by simp\nqed\n\nsection \\<open>Extraction of Benchmark Code\\<close>\n\nschematic_goal list_set_of_list_aux: \n  \"(?c,set)\\<in>\\<langle>nat_rel\\<rangle>list_rel \\<rightarrow> \\<langle>nat_rel\\<rangle>list_set_rel\"\n  by autoref\nconcrete_definition list_set_of_list uses list_set_of_list_aux\n\nterm compute_SCC_tr\n\ndefinition compute_SCC_tr_nat :: \"_ \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> nat list list\"\n  where \"compute_SCC_tr_nat \\<equiv> compute_SCC_tr\"\n\n(*export_code \n  compute_SCC_tr_nat\n  succ_of_list_impl\n  nat_of_integer\n  integer_of_nat\n  list_set_of_list\n  in SML module_name CSCC_Gabow\n  file \"Gabow_Benchmark/cscc_gabow.sml\"\n*)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Gabow_SCC/Gabow_SCC_Code.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5851011542032312, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.2584233853947827}}
{"text": "(*\n    Author:      David Sanan\n    Maintainer:  David Sanan, sanan at ntu edu sg\n    License:     LGPL\n*)\n\n(*  Title:      SmallStepCon.thy\n    Author:     David Sanan, NTU\n\nCopyright (C) 2015-2016 David Sanan \nSome rights reserved, NTU\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection {* Small-Step Semantics and Infinite Computations*} \n\ntheory SmallStepCon imports \"EmbSimpl.SmallStep\" \"SemanticCon\"  \n                            \"TerminationCon\"\n                            (* \"Sep_Algebra.Sep_Heap_Instance\" \n                            \"Actions.ActionsSemantics\" *)\nbegin\n\ntext {* The redex of a statement is the substatement, which is actually altered\nby the next step in the small-step semantics.\n*}\nprimrec redex:: \"('s,'p,'f,'e)com \\<Rightarrow> ('s,'p,'f,'e)com\"\nwhere\n\"redex Skip = Skip\" |\n\"redex (Basic f e) = (Basic f e)\" |\n\"redex (Spec r e) = (Spec r e)\" |\n\"redex (Seq c\\<^sub>1 c\\<^sub>2) = redex c\\<^sub>1\" |\n\"redex (Cond b c\\<^sub>1 c\\<^sub>2) = (Cond b c\\<^sub>1 c\\<^sub>2)\" |\n\"redex (While b c) = (While b c)\" |\n\"redex (Call p) = (Call p)\" |\n\"redex (DynCom d) = (DynCom d)\" |\n\"redex (Guard f b c) = (Guard f b c)\" |\n\"redex (Throw) = Throw\" |\n\"redex (Catch c\\<^sub>1 c\\<^sub>2) = redex c\\<^sub>1\" |\n\"redex (Await b c e) = (Await b c e)\"\n\n\n\nsubsection {*Small-Step Computation: @{text \"\\<Gamma>\\<turnstile>\\<^sub>c(c, s) \\<rightarrow> (c', s')\"}*}\ntype_synonym ('s,'p,'f,'e) config = \"('s,'p,'f,'e)com  \\<times> ('s,'f) xstate\"\n\ninductive \n      \"step_e\"::\"[('s,'p,'f,'e) body,('s,'p,'f,'e) config,('s,'p,'f,'e) config] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>c (_ \\<rightarrow>\\<^sub>e/ _)\" [81,81,81] 100)  \n  for \\<Gamma>::\"('s,'p,'f,'e) body\"\nwhere\nEnv: \"\\<Gamma>\\<turnstile>\\<^sub>c (Ps, Normal s) \\<rightarrow>\\<^sub>e (Ps, t)\"\n|Env_n: \"(\\<forall>t'. t\\<noteq>Normal t') \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c (Ps, t) \\<rightarrow>\\<^sub>e (Ps, t)\"\n\nlemma etranE: \"\\<Gamma>\\<turnstile>\\<^sub>c c \\<rightarrow>\\<^sub>e c' \\<Longrightarrow> (\\<And>P s t. c = (P, s) \\<Longrightarrow> c' = (P, t) \\<Longrightarrow> Q) \\<Longrightarrow> Q\"\n  by (induct c, induct c', erule  step_e.cases, blast)\n\ninductive_cases stepe_Normal_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Ps,Normal s) \\<rightarrow>\\<^sub>e (Ps,t)\"\n\ninductive_cases stepe_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Ps,s) \\<rightarrow>\\<^sub>e (Ps,t)\"\n\ninductive_cases stepe_not_norm_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Ps,s) \\<rightarrow>\\<^sub>e (Ps,Abrupt t)\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Ps,s) \\<rightarrow>\\<^sub>e (Ps,Stuck)\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Ps,s) \\<rightarrow>\\<^sub>e (Ps,Fault t)\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Ps,s) \\<rightarrow>\\<^sub>e (Ps,Normal t)\"\n\nlemma env_c_c'_false:\n   assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c', s')\" \n   shows \"~(c=c')  \\<Longrightarrow> P\"\nusing step_m etranE by blast\n\nlemma eenv_normal_s'_normal_s:\n   assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c', Normal s')\" \n   shows \"(\\<And>s1. s\\<noteq>Normal s1)  \\<Longrightarrow> P\"\nusing step_m \nby (cases, auto)\n\nlemma env_normal_s'_normal_s:\n   assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c', Normal s') \" \n   shows \"\\<exists>s1. s= Normal s1\"\nusing step_m \nby (cases, auto)\n\nlemma env_c_c':\n   assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c', s')\" \n   shows \"(c=c')\"\nusing env_c_c'_false step_m by fastforce \n\nlemma env_normal_s:\n   assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c', s') \\<and> s\\<noteq>s'\" \n   shows \"\\<exists>sa. s = Normal sa\"\nusing prod.inject step_e.cases step_m by fastforce\n\nlemma env_not_normal_s:\n   assumes a1:\"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c', s')\" and  a2:\"(\\<forall>t. s\\<noteq>Normal t)\" \n   shows \"s=s'\"\nusing a1 a2\nby (cases rule:step_e.cases,auto) \n\nlemma env_not_normal_s_not_norma_t:\n   assumes a1:\"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c', s')\" and  a2:\"(\\<forall>t. s\\<noteq>Normal t)\" \n   shows \"(\\<forall>t. s'\\<noteq>Normal t)\"\nusing a1 a2 env_not_normal_s\nby blast\n\nlemma stepe_not_Fault_f_end:\n  assumes step_e: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, s) \\<rightarrow>\\<^sub>e (c\\<^sub>1', s')\"\n  shows \"s'\\<notin> Fault ` f \\<Longrightarrow> s \\<notin> Fault ` f\"\nproof (cases s) \n  case (Fault f')\n    assume s'_f:\"s' \\<notin> Fault ` f\" and\n           \"s = Fault f'\" \n    then have \"s=s'\" using step_e \n    using env_normal_s xstate.distinct(3) by blast  \n  thus ?thesis using s'_f Fault by blast\nqed (auto)\n\ninductive       \n      \"stepc\"::\"[('s,'p,'f,'e) body,('s,'p,'f,'e) config,('s,'p,'f,'e) config] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>c (_ \\<rightarrow>/ _)\" [81,81,81] 100)  \n  for \\<Gamma>::\"('s,'p,'f,'e) body\"\nwhere\n\n  Basicc: \"\\<Gamma>\\<turnstile>\\<^sub>c(Basic f e,Normal s) \\<rightarrow> (Skip,Normal (f s))\"\n\n| Specc: \"(s,t) \\<in> r \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(Spec r e,Normal s) \\<rightarrow> (Skip,Normal t)\"\n| SpecStuckc: \"\\<forall>t. (s,t) \\<notin> r \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(Spec r e,Normal s) \\<rightarrow> (Skip,Stuck)\"\n\n| Guardc: \"s\\<in>g \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(Guard f g c,Normal s) \\<rightarrow> (c,Normal s)\"\n  \n| GuardFaultc: \"s\\<notin>g \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(Guard f g c,Normal s) \\<rightarrow> (Skip,Fault f)\"\n\n\n| Seqc: \"\\<Gamma>\\<turnstile>\\<^sub>c(c\\<^sub>1,s) \\<rightarrow> (c\\<^sub>1',s')\n        \\<Longrightarrow> \n        \\<Gamma>\\<turnstile>\\<^sub>c(Seq c\\<^sub>1 c\\<^sub>2,s) \\<rightarrow> (Seq c\\<^sub>1' c\\<^sub>2, s')\"\n| SeqSkipc: \"\\<Gamma>\\<turnstile>\\<^sub>c(Seq Skip c\\<^sub>2,s) \\<rightarrow> (c\\<^sub>2, s)\"\n| SeqThrowc: \"\\<Gamma>\\<turnstile>\\<^sub>c(Seq Throw c\\<^sub>2,Normal s) \\<rightarrow> (Throw, Normal s)\"\n\n| CondTruec:  \"s\\<in>b \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(Cond b c\\<^sub>1 c\\<^sub>2,Normal s) \\<rightarrow> (c\\<^sub>1,Normal s)\"\n| CondFalsec: \"s\\<notin>b \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(Cond b c\\<^sub>1 c\\<^sub>2,Normal s) \\<rightarrow> (c\\<^sub>2,Normal s)\"\n\n| WhileTruec: \"\\<lbrakk>s\\<in>b\\<rbrakk> \n              \\<Longrightarrow> \n              \\<Gamma>\\<turnstile>\\<^sub>c(While b c,Normal s) \\<rightarrow> (Seq c (While b c),Normal s)\"\n\n| WhileFalsec: \"\\<lbrakk>s\\<notin>b\\<rbrakk> \n               \\<Longrightarrow> \n               \\<Gamma>\\<turnstile>\\<^sub>c(While b c,Normal s) \\<rightarrow> (Skip,Normal s)\"\n\n\n| Awaitc:  \"\\<lbrakk>s\\<in>b; \\<Gamma>1=\\<Gamma>\\<^sub>\\<not>\\<^sub>a ; \\<Gamma>1\\<turnstile>\\<langle>ca1,Normal s\\<rangle> \\<Rightarrow> t; \n             \\<not>(\\<exists>t'. t = Abrupt t')\\<rbrakk> \\<Longrightarrow> \n            \\<Gamma>\\<turnstile>\\<^sub>c(Await b ca1 e,Normal s) \\<rightarrow> (Skip,t)\"\n\n| AwaitAbruptc: \"\\<lbrakk>s\\<in>b; \\<Gamma>1=\\<Gamma>\\<^sub>\\<not>\\<^sub>a ; \\<Gamma>1\\<turnstile>\\<langle>ca1,Normal s\\<rangle> \\<Rightarrow> t; \n                  t = Abrupt t'\\<rbrakk> \\<Longrightarrow> \n                 \\<Gamma>\\<turnstile>\\<^sub>c(Await b ca1 e,Normal s) \\<rightarrow> (Throw,Normal t')\"\n\n| Callc: \"\\<lbrakk>\\<Gamma> p = Some bdy ; bdy\\<noteq>Call p\\<rbrakk> \\<Longrightarrow>\n         \\<Gamma>\\<turnstile>\\<^sub>c(Call p,Normal s) \\<rightarrow> (bdy,Normal s)\"\n\n| CallUndefinedc: \"\\<Gamma> p=None \\<Longrightarrow>\n         \\<Gamma>\\<turnstile>\\<^sub>c(Call p,Normal s) \\<rightarrow> (Skip,Stuck)\"\n\n| DynComc: \"\\<Gamma>\\<turnstile>\\<^sub>c(DynCom c,Normal s) \\<rightarrow> (c s,Normal s)\"\n\n| Catchc: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(c\\<^sub>1,s) \\<rightarrow> (c\\<^sub>1',s')\\<rbrakk>\n          \\<Longrightarrow>\n          \\<Gamma>\\<turnstile>\\<^sub>c(Catch c\\<^sub>1 c\\<^sub>2,s) \\<rightarrow> (Catch c\\<^sub>1' c\\<^sub>2,s')\"\n\n| CatchThrowc: \"\\<Gamma>\\<turnstile>\\<^sub>c(Catch Throw c\\<^sub>2,Normal s) \\<rightarrow> (c\\<^sub>2,Normal s)\"\n| CatchSkipc: \"\\<Gamma>\\<turnstile>\\<^sub>c(Catch Skip c\\<^sub>2,s) \\<rightarrow> (Skip,s)\"\n\n| FaultPropc:  \"\\<lbrakk>c\\<noteq>Skip; redex c = c\\<rbrakk> \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(c,Fault f) \\<rightarrow> (Skip,Fault f)\"\n| StuckPropc:  \"\\<lbrakk>c\\<noteq>Skip; redex c = c\\<rbrakk> \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(c,Stuck) \\<rightarrow> (Skip,Stuck)\"\n| AbruptPropc: \"\\<lbrakk>c\\<noteq>Skip; redex c = c\\<rbrakk> \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(c,Abrupt f) \\<rightarrow> (Skip,Abrupt f)\"\n                                                              \nlemmas stepc_induct = stepc.induct [of _ \"(c,s)\" \"(c',s')\", split_format (complete), case_names\nBasicc Specc SpecStuckc Guardc GuardFaultc Seqc SeqSkipc SeqThrowc CondTruec CondFalsec\nWhileTruec WhileFalsec Awaitc AwaitAbruptc Callc CallUndefinedc DynComc Catchc CatchThrowc CatchSkipc\nFaultPropc StuckPropc AbruptPropc, induct set]\n\n\ninductive_cases stepc_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Skip,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Guard f g c,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Basic f e,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Spec r e,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Seq c1 c2,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Cond b c1 c2,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(While b c,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Await b c2 e,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Call p,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(DynCom c,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Throw,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,s) \\<rightarrow> u\"\n\ninductive_cases stepc_not_normal_elim_cases:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Call p,Abrupt s) \\<rightarrow> (p',s')\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Call p, Fault f) \\<rightarrow> (p',s')\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Call p, Stuck) \\<rightarrow> (p',s')\"\n \n\nlemma Guardc_not_c:\"Guard f g c \\<noteq> c\"\nproof (induct c)\nqed auto\n\nlemma Catch_not_c1:\"Catch c1 c2 \\<noteq> c1\"\nproof (induct c1)\nqed auto\n\nlemma Catch_not_c:\"Catch c1 c2 \\<noteq> c2\"\nproof (induct c2)\nqed auto\n\nlemma seq_not_eq1: \"Seq c1 c2\\<noteq>c1\"\n  by (induct c1) auto\n\nlemma seq_not_eq2: \"Seq c1 c2\\<noteq>c2\"\n  by (induct c2) auto\n\nlemma if_not_eq1: \"Cond b c1 c2 \\<noteq>c1\"\n  by (induct c1) auto\n\nlemma if_not_eq2: \"Cond b c1 c2\\<noteq>c2\"\n  by (induct c2) auto\n\n\nlemmas seq_and_if_not_eq [simp] = seq_not_eq1 seq_not_eq2 \nseq_not_eq1 [THEN not_sym] seq_not_eq2 [THEN not_sym] \nif_not_eq1 if_not_eq2 if_not_eq1 [THEN not_sym] if_not_eq2 [THEN not_sym]\nCatch_not_c1 Catch_not_c Catch_not_c1 [THEN not_sym] Catch_not_c[THEN not_sym] \nGuardc_not_c Guardc_not_c[THEN not_sym]\n\ninductive_cases stepc_elim_cases_Seq_Seq:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Seq c1 c2,s) \\<rightarrow> (Seq c1' c2,s')\" \n\ninductive_cases stepc_elim_cases_Seq_Seq1:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Seq c1 c2,Fault f) \\<rightarrow> (q,s')\" \nthm stepc_elim_cases_Seq_Seq1\n\ninductive_cases stepc_elim_cases_Catch_Catch:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,s) \\<rightarrow> (Catch c1' c2,s')\" \n\ninductive_cases stepc_elim_cases_Catch_Catch1:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Seq c1 c2,Fault f) \\<rightarrow> (q,s')\" \n\ninductive_cases stepc_elim_cases_Seq_skip:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Seq Skip c2,s) \\<rightarrow> u\" \n\"\\<Gamma>\\<turnstile>\\<^sub>c(Seq (Guard f g c1) c2,s) \\<rightarrow> u\"\n\n\ninductive_cases stepc_elim_cases_Catch_skip:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch Skip c2,s) \\<rightarrow> u\"\n\ninductive_cases stepc_elim_cases_Await_skip:\n\"\\<Gamma>\\<turnstile>\\<^sub>c (Await b c e, Normal s) \\<rightarrow> (Skip,t)\"\n\ninductive_cases stepc_elim_cases_Await_throw:\n\"\\<Gamma>\\<turnstile>\\<^sub>c (Await b c e, Normal s) \\<rightarrow> (Throw,t)\"\n\ninductive_cases stepc_elim_cases_Catch_throw:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,s) \\<rightarrow> (Throw, Normal s1)\" \n\ninductive_cases stepc_elim_cases_Catch_skip_c2:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,s) \\<rightarrow> (c2,s)\"\n\ninductive_cases stepc_Normal_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Skip,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Guard f g c,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Basic f e,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Spec r e,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Seq c1 c2,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Cond b c1 c2,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(While b c,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Await b c e,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Call p,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(DynCom c,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Throw,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,Normal s) \\<rightarrow> u\"\n\n\ntext \\<open> The final configuration is either of the form @{text \"(Skip,_)\"} for normal\ntermination, or @{term \"(Throw,Normal s)\"} in case the program was started in \na @{term \"Normal\"} state and terminated abruptly. The @{const \"Abrupt\"} state is not used to\nmodel abrupt termination, in contrast to the big-step semantics. Only if the\nprogram starts in an @{const \"Abrupt\"} states it ends in the same @{term \"Abrupt\"}\nstate.\\<close>\n\ndefinition final:: \"('s,'p,'f,'e) config \\<Rightarrow> bool\" where\n\"final cfg \\<equiv> (fst cfg=Skip \\<or> ((fst cfg=Throw) \\<and> (\\<exists>s. snd cfg=Normal s)))\"\n\ndefinition final_valid::\"('s,'p,'f,'e) config \\<Rightarrow> bool\" where\n\"final_valid cfg = ((fst cfg=Skip \\<or> fst cfg=Throw) \\<and> (\\<exists>s. snd cfg=Normal s))\"\n\nabbreviation \n \"stepc_rtrancl\" :: \"[('s,'p,'f,'e) body,('s,'p,'f,'e) config,('s,'p,'f,'e) config] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>c (_ \\<rightarrow>\\<^sup>*/ _)\" [81,81,81] 100)\n where                                \n  \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sup>* cf1 \\<equiv> ((CONST stepc \\<Gamma>))\\<^sup>*\\<^sup>* cf0 cf1\" \n  (* \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sup>* cf1 \\<equiv> (CONST ((stepc \\<Gamma>) \\<union> (step_e \\<Gamma>)))\\<^sup>*\\<^sup>* cf0 cf1\" *)\n\nabbreviation \n \"stepc_trancl\" :: \"[('s,'p,'f,'e) body,('s,'p,'f,'e) config,('s,'p,'f,'e) config] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>c (_ \\<rightarrow>\\<^sup>+/ _)\" [81,81,81] 100)\n where\n  \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sup>+ cf1 \\<equiv> (CONST stepc \\<Gamma>)\\<^sup>+\\<^sup>+ cf0 cf1\"\n\nlemma \n   assumes \n           step_a: \"\\<Gamma>\\<turnstile>\\<^sub>c(Await b c e, Normal s) \\<rightarrow> (t,u)\"\n   shows step_await_step_c:\"(\\<Gamma>\\<^sub>\\<not>\\<^sub>a)\\<turnstile>(c, Normal s) \\<rightarrow>\\<^sup>* (sequential t,u)\" \nusing step_a\nproof cases\n  fix t1\n  assume\n      \"(t, u) = (Skip, t1)\" \"s \\<in> b\" \"(\\<Gamma>\\<^sub>\\<not>\\<^sub>a)\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> t1\" \"\\<forall>t'. t1 \\<noteq> Abrupt t'\"\n  thus ?thesis \n   by (cases u) \n   (auto intro: exec_impl_steps_Fault exec_impl_steps_Normal exec_impl_steps_Stuck)\nnext\n  fix t1\n  assume \"(t, u) = (Throw, Normal t1)\" \"s \\<in> b\" \"(\\<Gamma>\\<^sub>\\<not>\\<^sub>a)\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> Abrupt t1\"\n  thus ?thesis by (simp add: exec_impl_steps_Normal_Abrupt)\nqed\n\nlemma \n   assumes (* exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" and\n           b: \"s \\<in> b\" and *)\n           step_a: \"\\<Gamma>\\<turnstile>\\<^sub>c(Await b c e, Normal s) \\<rightarrow> u\"\n   shows step_await_final1:\"final u\"\nusing step_a \nproof cases\n  case  (1 t) thus \"final u\"  by (simp add: final_def)\nnext\n  case (2 t)\n  thus \"final u\" by (simp add: exec_impl_steps_Normal_Abrupt final_def)\nqed\n\nlemma step_Abrupt_end: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, s) \\<rightarrow> (c\\<^sub>1', s')\"\n  shows \"s'=Abrupt x \\<Longrightarrow> s=Abrupt x\"\nusing step\nby induct auto\n\n\nlemma step_Stuck_end: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, s) \\<rightarrow> (c\\<^sub>1', s')\"\n  shows \"s'=Stuck \\<Longrightarrow> \n          s=Stuck \\<or> \n          (\\<exists>r x e. redex c\\<^sub>1 = Spec r e \\<and> s=Normal x \\<and> (\\<forall>t. (x,t)\\<notin>r)) \\<or> \n          (\\<exists>p x. redex c\\<^sub>1=  Call p \\<and> s=Normal x \\<and> \\<Gamma> p = None) \\<or>\n          (\\<exists>b c x e.  redex c\\<^sub>1 = Await b c e \\<and> s=Normal x \\<and> x \\<in> b \\<and> (\\<Gamma>\\<^sub>\\<not>\\<^sub>a)\\<turnstile>\\<langle>c,s\\<rangle>\\<Rightarrow>s')\"\nusing step\nby induct auto\n\nlemma step_Fault_end: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, s) \\<rightarrow> (c\\<^sub>1', s')\"\n  shows \"s'=Fault f \\<Longrightarrow> \n          s=Fault f \\<or> \n          (\\<exists>g c x.  redex c\\<^sub>1 = Guard f g c \\<and> s=Normal x \\<and> x \\<notin> g) \\<or>\n          (\\<exists>b c1 x e.  redex c\\<^sub>1 = Await b c1 e \\<and> s=Normal x \\<and> x \\<in> b \\<and> (\\<Gamma>\\<^sub>\\<not>\\<^sub>a)\\<turnstile>\\<langle>c1,s\\<rangle>\\<Rightarrow>s')\"\nusing step \nby induct auto\n\nlemma step_not_Fault_f_end:\n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, s) \\<rightarrow> (c\\<^sub>1', s')\"\n  shows \"s'\\<notin> Fault ` f \\<Longrightarrow> s \\<notin> Fault ` f\"\nusing step \nby induct auto\n\n  \n\ninductive \n      \"step_ce\"::\"[('s,'p,'f,'e) body,('s,'p,'f,'e) config,('s,'p,'f,'e) config] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>c (_ \\<rightarrow>\\<^sub>c\\<^sub>e/ _)\" [81,81,81] 100)  \n  for \\<Gamma>::\"('s,'p,'f,'e) body\"\nwhere\nc_step: \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow> cf1 \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sub>c\\<^sub>e cf1 \"\n|e_step: \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sub>e cf1 \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sub>c\\<^sub>e cf1 \"\n\nlemmas step_ce_induct = step_ce.induct [of _ \"(c,s)\" \"(c',s')\", split_format (complete), case_names\nc_step e_step, induct set]\n\n\ninductive_cases step_ce_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sub>c\\<^sub>e cf1\"\n\n\nlemma step_c_normal_normal: assumes a1: \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow> cf1\"\n      shows \"\\<And> c\\<^sub>1 s s'. \\<lbrakk>cf0 = (c\\<^sub>1,Normal s);cf1=(c\\<^sub>1,s');(\\<forall>sa. \\<not>(s'=Normal sa))\\<rbrakk>\n          \\<Longrightarrow> P\"\nusing a1 \nby (induct rule: stepc.induct, induct, auto)\n\nlemma normal_not_normal_eq_p: \n  assumes a1: \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sub>c\\<^sub>e cf1\"\n  shows \"\\<And> c\\<^sub>1 s s'. \\<lbrakk>cf0 = (c\\<^sub>1,Normal s);cf1=(c\\<^sub>1,s');(\\<forall>sa. \\<not>(s'=Normal sa))\\<rbrakk>\n          \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sub>e cf1 \\<and> \\<not>( \\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow> cf1)\"\nby (meson step_c_normal_normal step_e.intros)\n\nlemma call_not_normal_skip_always:\n  assumes a0:\"\\<Gamma>\\<turnstile>\\<^sub>c(Call p,s) \\<rightarrow> (p1,s1)\" and\n          a1:\"\\<forall>sn. s \\<noteq> Normal sn\" and\n          a2:\"p1\\<noteq>Skip\"\n  shows \"P\" \nproof(cases s)\n  case Normal thus ?thesis using a1 by fastforce\nnext\n  case Stuck \n  then have a0:\"\\<Gamma>\\<turnstile>\\<^sub>c(Call p,Stuck) \\<rightarrow> (p1,s1)\" using a0 by auto\n  show ?thesis using  a1 a2 stepc_not_normal_elim_cases(3)[OF a0] by fastforce\nnext\n  case (Fault f) \n  then have a0:\"\\<Gamma>\\<turnstile>\\<^sub>c(Call p,Fault f) \\<rightarrow> (p1,s1)\" using a0 by auto\n  show ?thesis using  a1 a2 stepc_not_normal_elim_cases(2)[OF a0] by fastforce\nnext\n  case (Abrupt a)\n  then have a0:\"\\<Gamma>\\<turnstile>\\<^sub>c(Call p,Abrupt a) \\<rightarrow> (p1,s1)\" using a0 by auto\n  show ?thesis using  a1 a2 stepc_not_normal_elim_cases(1)[OF a0] by fastforce\nqed\n\nlemma call_f_step_not_s_eq_t_false:\n  assumes \n     a0:\"\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow> (Q,t)\" and\n     a1:\"(redex P = Call fn \\<and> \\<Gamma> fn = Some bdy \\<and> s=Normal s' \\<and> ~(s=t)) \\<or>\n         (redex P = Call fn \\<and> \\<Gamma> fn = Some bdy \\<and> s=Normal s' \\<and> s=t \\<and> P=Q \\<and> \\<Gamma> fn \\<noteq> Some (Call fn))\"\n  shows \"False\"\nusing a0 a1\nproof (induct rule:stepc_induct)\nqed(fastforce+,auto)\n\nlemma call_f_step_ce_not_s_eq_t_env_step:\n  assumes \n     a0:\"\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow>\\<^sub>c\\<^sub>e (Q,t)\" and\n     a1:\"(redex P = Call fn \\<and> \\<Gamma> fn = Some bdy \\<and> s=Normal s' \\<and> ~(s=t)) \\<or>\n         (redex P = Call fn \\<and> \\<Gamma> fn = Some bdy \\<and> s=Normal s' \\<and> s=t \\<and> P=Q \\<and> \\<Gamma> fn \\<noteq> Some (Call fn)) \"\n  shows \"\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow>\\<^sub>e (Q,t)\"\nproof-\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow>\\<^sub>e (Q,t) \\<or> \\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow> (Q,t)\"\n  using a0 step_ce_elim_cases by fastforce\n  thus ?thesis using call_f_step_not_s_eq_t_false a1 by fastforce\nqed\n\n\n  \nabbreviation \n \"stepce_rtrancl\" :: \"[('s,'p,'f,'e) body,('s,'p,'f,'e) config,('s,'p,'f,'e) config] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>c (_ \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>*/ _)\" [81,81,81] 100)\n where                                \n  \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* cf1 \\<equiv> ((CONST step_ce \\<Gamma>))\\<^sup>*\\<^sup>* cf0 cf1\" \n  (* \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sup>* cf1 \\<equiv> (CONST ((stepc \\<Gamma>) \\<union> (step_e \\<Gamma>)))\\<^sup>*\\<^sup>* cf0 cf1\" *)\n\nabbreviation \n \"stepce_trancl\" :: \"[('s,'p,'f,'e) body,('s,'p,'f,'e) config,('s,'p,'f,'e) config] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>c (_ \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>+/ _)\" [81,81,81] 100)\n where\n  \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>+ cf1 \\<equiv> (CONST step_ce \\<Gamma>)\\<^sup>+\\<^sup>+ cf0 cf1\"\n\nsubsection {*Parallel Computation: @{text \"\\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sub>p  (c', s')\"}*}\ntype_synonym ('s,'p,'f,'e) par_Simpl = \"('s,'p,'f,'e)com  list\" \ntype_synonym ('s,'p,'f,'e) par_config = \"('s,'p,'f,'e) par_Simpl \\<times> ('s,'f) xstate\"\n\ndefinition final_c:: \"('s,'p,'f,'e) par_config \\<Rightarrow> bool\" where\n\"final_c cfg = (\\<forall>i. i<length (fst cfg) \\<longrightarrow> final ((fst cfg)!i, snd cfg))\"\n\ninductive \n      \"step_pe\"::\"[('s,'p,'f,'e) body,('s,'p,'f,'e) par_config,('s,'p,'f,'e) par_config] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>p (_ \\<rightarrow>\\<^sub>e/ _)\" [81,81,81] 100)  \n  for \\<Gamma>::\"('s,'p,'f,'e) body\"\nwhere\nParEnv: \"\\<Gamma>\\<turnstile>\\<^sub>p (Ps, Normal s) \\<rightarrow>\\<^sub>e (Ps, Normal t)\"\n\n\n\n\nlemma ptranE: \"\\<Gamma>\\<turnstile>\\<^sub>p c \\<rightarrow>\\<^sub>e c' \\<Longrightarrow> (\\<And>P s t. c = (P, s) \\<Longrightarrow> c' = (P, t) \\<Longrightarrow> Q) \\<Longrightarrow> Q\"\n  by (induct c, induct c', erule  step_pe.cases, blast)\n\ninductive_cases step_pe_Normal_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>\\<^sub>p(PS,Normal s) \\<rightarrow>\\<^sub>e (Ps,t)\"\n\ninductive_cases step_pe_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>\\<^sub>p(PS,s) \\<rightarrow>\\<^sub>e (Ps,t)\"\n\ninductive_cases step_pe_not_norm_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>\\<^sub>p(Ps,s) \\<rightarrow>\\<^sub>e (Ps,Abrupt t)\"\n \"\\<Gamma>\\<turnstile>\\<^sub>p(Ps,s) \\<rightarrow>\\<^sub>e (Ps,Stuck)\"\n \"\\<Gamma>\\<turnstile>\\<^sub>p(Ps,s) \\<rightarrow>\\<^sub>e (Ps,Fault t)\"\n\nlemma env_pe_c_c'_false:\n   assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>p (c, s) \\<rightarrow>\\<^sub>e (c', s')\" \n   shows \"~(c=c')  \\<Longrightarrow> P\"\nusing step_m ptranE by blast\n\nlemma env_pe_c_c':\n   assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>p (c, s) \\<rightarrow>\\<^sub>e (c', s')\" \n   shows \"(c=c')\"\nusing env_pe_c_c'_false step_m by fastforce \n\nlemma env_pe_normal_s:\n   assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>p (c, s) \\<rightarrow>\\<^sub>e (c', s') \\<and> s\\<noteq>s'\" \n   shows \"\\<exists>sa. s = Normal sa\"\nusing prod.inject step_pe.cases step_m by fastforce\n\nlemma env_pe_not_normal_s:\n   assumes a1:\"\\<Gamma>\\<turnstile>\\<^sub>p (c, s) \\<rightarrow>\\<^sub>e (c', s')\" and  a2:\"(\\<forall>t. s\\<noteq>Normal t)\" \n   shows \"s=s'\"\nusing a1 a2\nby (cases rule:step_pe.cases,auto) \n\nlemma env_pe_not_normal_s_not_norma_t:\n   assumes a1:\"\\<Gamma>\\<turnstile>\\<^sub>p (c, s) \\<rightarrow>\\<^sub>e (c', s')\" and  a2:\"(\\<forall>t. s\\<noteq>Normal t)\" \n   shows \"(\\<forall>t. s'\\<noteq>Normal t)\"\nusing a1 a2 env_pe_not_normal_s\nby blast\n\n\ninductive       \n\"step_p\"::\"[('s,'p,'f,'e) body, ('s,'p,'f,'e) par_config, \n            ('s,'p,'f,'e) par_config] \\<Rightarrow> bool\"\n(\"_\\<turnstile>\\<^sub>p (_ \\<rightarrow>/ _)\" [81,81,81] 100)  \nwhere\n ParComp: \"\\<lbrakk>i<length Ps;  \\<Gamma>\\<turnstile>\\<^sub>c(Ps!i,s) \\<rightarrow> (r,s')\\<rbrakk> \\<Longrightarrow>  \n           \\<Gamma>\\<turnstile>\\<^sub>p(Ps, s) \\<rightarrow> (Ps[i:=r], s')\"\n\nlemmas steppe_induct = step_p.induct [of _ \"(c,s)\" \"(c',s')\", split_format (complete), case_names\nParComp, induct set]\n\ninductive_cases step_p_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>\\<^sub>p(Ps, s) \\<rightarrow> u\"\n\ninductive_cases step_p_pair_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>\\<^sub>p(Ps, s) \\<rightarrow> (Qs, t)\"\n\ninductive_cases step_p_Normal_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>\\<^sub>p(Ps, Normal s) \\<rightarrow> u\"\n\n\nlemma par_ctranE: \"\\<Gamma> \\<turnstile>\\<^sub>p c \\<rightarrow> c' \\<Longrightarrow>\n  (\\<And>i Ps s r t. c = (Ps, s) \\<Longrightarrow> c' = (Ps[i := r], t) \\<Longrightarrow> i < length Ps \\<Longrightarrow>\n     \\<Gamma> \\<turnstile>\\<^sub>c (Ps!i, s) \\<rightarrow> (r, t) \\<Longrightarrow> P) \\<Longrightarrow> P\"\nby (induct c, induct c', erule step_p.cases, blast)\n\nsubsection \\<open>Computations\\<close>\nsubsubsection \\<open>Sequential computations\\<close>\n\ntype_synonym ('s,'p,'f,'e) confs = \n  \"('s,'p,'f,'e) body \\<times>(('s,'p,'f,'e) config) list\"\n\ninductive_set cptn :: \"(('s,'p,'f,'e) confs) set\"\nwhere\n  CptnOne: \" (\\<Gamma>, [(P,s)]) \\<in> cptn\"\n| CptnEnv: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow>\\<^sub>e (P,t); (\\<Gamma>,(P, t)#xs) \\<in> cptn \\<rbrakk> \\<Longrightarrow>\n             (\\<Gamma>,(P,s)#(P,t)#xs) \\<in> cptn\"\n| CptnComp: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow> (Q,t); (\\<Gamma>,(Q, t)#xs) \\<in> cptn \\<rbrakk> \\<Longrightarrow> \n              (\\<Gamma>,(P,s)#(Q,t)#xs) \\<in> cptn\"\n\ninductive_cases cptn_elim_cases [cases set]:\n\"(\\<Gamma>, [(P,s)]) \\<in> cptn\"\n\"(\\<Gamma>,(P,s)#(Q,t)#xs) \\<in> cptn\"\n\"(\\<Gamma>,(P,s)#(P,t)#xs) \\<in> cptn\"\n\ninductive_cases cptn_elim_cases_pair [cases set]:\n\"(\\<Gamma>, [x]) \\<in> cptn\"\n\"(\\<Gamma>, x#x1#xs) \\<in> cptn\"\n\nlemma cptn_dest:\"(\\<Gamma>,(P,s)#(Q,t)#xs) \\<in> cptn \\<Longrightarrow> (\\<Gamma>,(Q,t)#xs)\\<in> cptn\"\nby (auto dest: cptn_elim_cases)\n\nlemma cptn_dest_pair:\"(\\<Gamma>,x#x1#xs) \\<in> cptn \\<Longrightarrow> (\\<Gamma>,x1#xs)\\<in> cptn\"\nproof -\n  assume \"(\\<Gamma>,x#x1#xs) \\<in> cptn\"\n  thus ?thesis using cptn_dest prod.collapse by metis\nqed\n\nlemma cptn_dest1:\"(\\<Gamma>,(P,s)#(Q,t)#xs) \\<in> cptn \\<Longrightarrow> (\\<Gamma>,(P,s)#[(Q,t)])\\<in> cptn\"\nproof -\n  assume a1: \"(\\<Gamma>, (P, s) # (Q, t) # xs) \\<in> cptn\"\n  have \"(\\<Gamma>, [(Q, t)]) \\<in> cptn\"\n    by (meson cptn.CptnOne)\n  thus ?thesis       \n  proof (cases s)\n    case (Normal s') \n     then have f1: \"(\\<Gamma>, (P, Normal s') # (Q, t) # xs) \\<in> cptn\"\n       using Normal a1 by blast\n     have \"(\\<Gamma>, [(P, t)]) \\<in> cptn \\<longrightarrow> (\\<Gamma>, [(P, Normal s'), (P, t)]) \\<in> cptn\"\n       by (simp add: Env cptn.CptnEnv)       \n     thus ?thesis\n      using f1 by (metis (no_types) Normal `(\\<Gamma>, [(Q, t)]) \\<in> cptn` cptn.CptnComp cptn_elim_cases(2))\n  next\n    case (Abrupt x) thus ?thesis  \n     using `(\\<Gamma>, [(Q, t)]) \\<in> cptn` a1 cptn.CptnComp cptn_elim_cases(2) CptnEnv by metis\n  next\n    case (Stuck) thus ?thesis \n     using `(\\<Gamma>, [(Q, t)]) \\<in> cptn` a1 cptn.CptnComp cptn_elim_cases(2) CptnEnv by metis\n  next \n    case (Fault f) thus ?thesis\n     using `(\\<Gamma>, [(Q, t)]) \\<in> cptn` a1 cptn.CptnComp cptn_elim_cases(2) CptnEnv by metis\n  qed\nqed\n\nlemma cptn_dest1_pair:\"(\\<Gamma>,x#x1#xs) \\<in> cptn \\<Longrightarrow> (\\<Gamma>,x#[x1])\\<in> cptn\"\nproof -\n  assume \"(\\<Gamma>,x#x1#xs) \\<in> cptn\"\n  thus ?thesis using cptn_dest1 prod.collapse by metis\nqed\n\nlemma cptn_append_is_cptn [rule_format]: \n \"\\<forall>b a. (\\<Gamma>,b#c1)\\<in>cptn \\<longrightarrow>  (\\<Gamma>,a#c2)\\<in>cptn \\<longrightarrow> (b#c1)!length c1=a \\<longrightarrow> (\\<Gamma>,b#c1@c2)\\<in>cptn\"\napply(induct c1)\n apply simp\napply clarify\napply(erule cptn.cases,simp_all)\napply (simp add: cptn.CptnEnv)\nby (simp add: cptn.CptnComp)\n\nlemma cptn_dest_2:\n  \"(\\<Gamma>,a#xs@ys) \\<in> cptn  \\<Longrightarrow> (\\<Gamma>,a#xs)\\<in> cptn\"\nproof (induct \"xs\" arbitrary: a)\n  case Nil thus ?case using cptn.simps by fastforce \nnext\n  case (Cons x xs') \n  then have \"(\\<Gamma>,a#[x])\\<in>cptn\" by (simp add: cptn_dest1_pair)\n  also have \"(\\<Gamma>, x # xs') \\<in> cptn\"\n    using Cons.hyps Cons.prems cptn_dest_pair by fastforce    \n  ultimately show ?case using cptn_append_is_cptn [of \\<Gamma> a \"[x]\" x xs']\n    by force    \nqed   \n\n\nlemma last_not_F:\nassumes \n  a0:\"(\\<Gamma>,xs)\\<in>cptn\"  \nshows \"snd (last xs) \\<notin> Fault ` F \\<Longrightarrow> \\<forall>i < length xs. snd (xs!i) \\<notin> Fault ` F\"\nusing a0\nproof(induct) print_cases\n  case (CptnOne \\<Gamma> p s) thus ?case by auto\nnext\n  case (CptnEnv  \\<Gamma> P s t xs) \n  thus ?case using stepe_not_Fault_f_end\n  proof -\n  { fix nn :: nat\n    have \"snd (last ((P, t) # xs)) \\<notin> Fault ` F\"\n      using CptnEnv.prems by force\n    then have \"\\<not> nn < length ((P, s) # (P, t) # xs) \\<or> snd (((P, s) # (P, t) # xs) ! nn) \\<notin> Fault ` F\"\n      by (metis (no_types) CptnEnv.hyps(1) CptnEnv.hyps(3) length_Cons less_Suc_eq_0_disj nth_Cons_0 nth_Cons_Suc snd_conv stepe_not_Fault_f_end) \n  }\n  then have \"\\<forall>n. \\<not> n < length ((P, s) # (P, t) # xs) \\<or> snd (((P, s) # (P, t) # xs) ! n) \\<notin> Fault ` F\"\n    by meson\n  then show ?thesis\n    by metis\n  qed    \nnext\n  case (CptnComp \\<Gamma> P s Q t xs) \n  have \"snd (last ((Q, t) # xs)) \\<notin> Fault ` F\"\n    using CptnComp.prems by force\n  then have all:\"\\<forall>i<length ((Q, t) # xs). snd (((Q, t) # xs) ! i) \\<notin> Fault ` F\"\n    using CptnComp.hyps by force\n  then have \"t \\<notin> Fault ` F\"\n    by force\n  then have \"s \\<notin> Fault ` F\" using step_not_Fault_f_end\n    using CptnComp.hyps(1) by blast\n  then have zero:\"snd (P,s) \\<notin> Fault ` F\" by auto\n  show ?case \n  proof -\n  { fix nn :: nat\n    have \"\\<not> nn < length ((P, s) # (Q, t) # xs) \\<or> snd (((P, s) # (Q, t) # xs) ! nn) \\<notin> Fault ` F\"\n      by (metis (no_types) \\<open>\\<forall>i<length ((Q, t) # xs). snd (((Q, t) # xs) ! i) \\<notin> Fault ` F\\<close> \\<open>snd (P, s) \\<notin> Fault ` F\\<close> diff_Suc_1 length_Cons less_Suc_eq_0_disj nth_Cons') \n  }\n  then show ?thesis\n    by meson\n  qed \nqed\n\ndefinition cp :: \"('s,'p,'f,'e) body \\<Rightarrow> ('s,'p,'f,'e) com \\<Rightarrow> \n                  ('s,'f) xstate \\<Rightarrow> (('s,'p,'f,'e) confs) set\" where\n  \"cp \\<Gamma> P s \\<equiv> {(\\<Gamma>1,l). l!0=(P,s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>1=\\<Gamma>}\"  \n\n \n\nlemma cp_sub: \n  assumes a0: \"(\\<Gamma>,(x#l0)@l1) \\<in> cp \\<Gamma> P s\"\n  shows \"(\\<Gamma>,(x#l0)) \\<in> cp \\<Gamma> P s\"\nproof -\n  have \"(x#l0)!0 = (P,s)\" using a0 unfolding cp_def by auto\n  also have \"(\\<Gamma>,(x#l0))\\<in>cptn\" using a0 unfolding cp_def\n  using cptn_dest_2 by fastforce\n  ultimately show ?thesis using a0 unfolding cp_def by blast\nqed\n\nsubsubsection \\<open>Parallel computations\\<close>\n\ntype_synonym ('s,'p,'f,'e) par_confs = \"('s,'p,'f,'e) body \\<times>(('s,'p,'f,'e) par_config) list\"\n\ninductive_set par_cptn :: \"('s,'p,'f,'e) par_confs set\"\nwhere\n  ParCptnOne: \"(\\<Gamma>, [(P,s)]) \\<in> par_cptn\"\n| ParCptnEnv: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>p(P,s) \\<rightarrow>\\<^sub>e (P,t);(\\<Gamma>,(P, t)#xs) \\<in> par_cptn \\<rbrakk> \\<Longrightarrow>(\\<Gamma>,(P,s)#(P,t)#xs) \\<in> par_cptn\"\n| ParCptnComp: \"\\<lbrakk> \\<Gamma> \\<turnstile>\\<^sub>p(P,s) \\<rightarrow> (Q,t); (\\<Gamma>,(Q,t)#xs) \\<in> par_cptn \\<rbrakk> \\<Longrightarrow> (\\<Gamma>,(P,s)#(Q,t)#xs) \\<in> par_cptn\"\n\ninductive_cases par_cptn_elim_cases [cases set]:\n\"(\\<Gamma>, [(P,s)]) \\<in> par_cptn\"\n\"(\\<Gamma>,(P,s)#(Q,t)#xs) \\<in> par_cptn\"\n\nlemma pe_ce: \n  assumes a1:\"\\<Gamma>\\<turnstile>\\<^sub>p(P,s) \\<rightarrow>\\<^sub>e (P,t)\"\n  shows \"\\<forall>i<length P. \\<Gamma>\\<turnstile>\\<^sub>c(P!i,s) \\<rightarrow>\\<^sub>e (P!i,t)\"\nproof -\n  {fix i\n   assume \"i< length P\"\n   have \"\\<Gamma>\\<turnstile>\\<^sub>c(P!i,s) \\<rightarrow>\\<^sub>e (P!i,t)\" using a1\n  by (metis Env Env_n env_pe_not_normal_s)\n  }\n  thus \"\\<forall>i<length P. \\<Gamma>\\<turnstile>\\<^sub>c(P!i,s) \\<rightarrow>\\<^sub>e (P!i,t)\" by blast\nqed\n\ntype_synonym ('s,'p,'f,'e) par_com = \"('s,'p,'f,'e) com list\"\n\ndefinition par_cp :: \"('s,'p,'f,'e) body \\<Rightarrow> ('s,'p,'f,'e) com list \\<Rightarrow> ('s,'f) xstate \\<Rightarrow> (('s,'p,'f,'e) par_confs) set\" \nwhere\n  \"par_cp \\<Gamma> P s \\<equiv> {(\\<Gamma>1,l). l!0=(P,s) \\<and> (\\<Gamma>,l) \\<in> par_cptn \\<and> \\<Gamma>1=\\<Gamma>}\"  \n\n(* definition par_cp :: \"('s,'p,'f,'e) body \\<Rightarrow> ('s,'p,'f,'e) com list \\<Rightarrow> ('s,'f) xstate \\<Rightarrow> (('s,'p,'f,'e) par_confs) set\" \nwhere\n  \"par_cp \\<Gamma> P s \\<equiv> {(\\<Gamma>1,l). l!0=(P,s) \\<and> (\\<Gamma>,l) \\<in> par_cptn \\<and> \\<Gamma>1=\\<Gamma>}\" *)\n\nlemma par_cptn_dest:\"(\\<Gamma>,(P,s)#(Q,t)#xs) \\<in> par_cptn \\<Longrightarrow> (\\<Gamma>,(Q,t)#xs)\\<in> par_cptn\"\nby (auto dest: par_cptn_elim_cases)\n\n\ntext {*\nlemmas about single step computation\n*}\n\n\n(* ************************************************************************ *)\nsubsection {* Structural Properties of Small Step Computations *}\n(* ************************************************************************ *)\nlemma redex_not_Seq: \"redex c = Seq c1 c2 \\<Longrightarrow> P\"\n  apply (induct c)\n  apply auto\n  done\nlemma redex_not_Catch: \"redex c = Catch c1 c2 \\<Longrightarrow> P\"\n  apply (induct c)\n  apply auto\n  done\n\n\n\n\nlemma no_step_final':\n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c cfg \\<rightarrow> cfg'\"\n  shows \"final cfg \\<Longrightarrow> P\"\nusing step\n  by (cases cfg, cases cfg') (auto intro: no_step_final)\n\n\nlemma step_Abrupt:\n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s')\"\n  shows \"\\<And>x. s=Abrupt x \\<Longrightarrow> s'=Abrupt x\"\nusing step\nby (induct) auto\n\nlemma step_Fault: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s')\"\n  shows \"\\<And>f. s=Fault f \\<Longrightarrow> s'=Fault f\"\nusing step\nby (induct) auto\n\nlemma step_Stuck: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s')\"\n  shows \"\\<And>f. s=Stuck \\<Longrightarrow> s'=Stuck\"\nusing step\nby (induct) auto\n\nlemma step_not_normal_not_normal:\n  assumes step:\"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s')\"\n  shows \"\\<forall>s1. s\\<noteq>Normal s1 \\<Longrightarrow> \\<forall>s1. s' \\<noteq> Normal s1\"\nusing step step_Abrupt step_Stuck step_Fault\nby (induct) auto\n\nlemma step_not_normal_s_eq_t:\n  assumes step:\"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', t)\"\n  shows \"\\<forall>s1. s\\<noteq>Normal s1 \\<Longrightarrow> s=t\"\nusing step step_Abrupt step_Stuck step_Fault\nby (induct) auto\n\nlemma ce_not_normal_s:\n   assumes a1:\"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sub>c\\<^sub>e cf1\"\n   shows \"\\<And> c\\<^sub>1 c\\<^sub>2 s s'. \\<lbrakk>cf0 = (c\\<^sub>1,s);cf1=(c\\<^sub>2,s');(\\<forall>sa. (s\\<noteq>Normal sa))\\<rbrakk>\n                     \\<Longrightarrow> s=s'\"\nusing a1\napply (clarify, cases rule:step_ce.cases)\nby (metis step_not_normal_s_eq_t env_not_normal_s)+\n\nlemma SeqSteps: \n  assumes steps: \"\\<Gamma>\\<turnstile>\\<^sub>c cfg\\<^sub>1\\<rightarrow>\\<^sup>* cfg\\<^sub>2\"\n  shows \"\\<And> c\\<^sub>1 s c\\<^sub>1' s'. \\<lbrakk>cfg\\<^sub>1 = (c\\<^sub>1,s);cfg\\<^sub>2=(c\\<^sub>1',s')\\<rbrakk>\n          \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(Seq c\\<^sub>1 c\\<^sub>2,s) \\<rightarrow>\\<^sup>* (Seq c\\<^sub>1' c\\<^sub>2, s')\"\nusing steps\nproof (induct rule: converse_rtranclp_induct [case_names Refl Trans]) \n  case Refl\n  thus ?case\n    by simp\nnext\n  case (Trans cfg\\<^sub>1 cfg'')      \n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c cfg\\<^sub>1 \\<rightarrow> cfg''\" using Trans.hyps(1) by blast\n  have steps: \"\\<Gamma>\\<turnstile>\\<^sub>c cfg'' \\<rightarrow>\\<^sup>* cfg\\<^sub>2\" by fact\n  have cfg\\<^sub>1: \"cfg\\<^sub>1 = (c\\<^sub>1, s)\" and cfg\\<^sub>2: \"cfg\\<^sub>2 = (c\\<^sub>1', s')\"  by fact+\n  obtain c\\<^sub>1'' s'' where cfg'': \"cfg''=(c\\<^sub>1'',s'')\"\n    by (cases cfg'') auto\n  from step cfg\\<^sub>1 cfg'' \n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1,s) \\<rightarrow> (c\\<^sub>1'',s'')\"\n    by simp  \n  hence \"\\<Gamma>\\<turnstile>\\<^sub>c (Seq c\\<^sub>1 c\\<^sub>2,s) \\<rightarrow> (Seq c\\<^sub>1'' c\\<^sub>2,s'')\" by (simp add: Seqc)    \n  also from Trans.hyps (3) [OF cfg'' cfg\\<^sub>2]\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Seq c\\<^sub>1'' c\\<^sub>2, s'') \\<rightarrow>\\<^sup>* (Seq c\\<^sub>1' c\\<^sub>2, s')\" .\n  finally show ?case .\nqed\n\nlemma CatchSteps: \n  assumes steps: \"\\<Gamma>\\<turnstile>\\<^sub>ccfg\\<^sub>1\\<rightarrow>\\<^sup>* cfg\\<^sub>2\"\n  shows \"\\<And> c\\<^sub>1 s c\\<^sub>1' s'. \\<lbrakk>cfg\\<^sub>1 = (c\\<^sub>1,s); cfg\\<^sub>2=(c\\<^sub>1',s')\\<rbrakk>\n          \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(Catch c\\<^sub>1 c\\<^sub>2,s) \\<rightarrow>\\<^sup>* (Catch c\\<^sub>1' c\\<^sub>2, s')\"\nusing steps\nproof (induct rule: converse_rtranclp_induct [case_names Refl Trans])\n  case Refl\n  thus ?case\n    by simp\nnext\n  case (Trans cfg\\<^sub>1 cfg'')\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c cfg\\<^sub>1 \\<rightarrow> cfg''\" by fact\n  have steps: \"\\<Gamma>\\<turnstile>\\<^sub>c cfg'' \\<rightarrow>\\<^sup>* cfg\\<^sub>2\" by fact\n  have cfg\\<^sub>1: \"cfg\\<^sub>1 = (c\\<^sub>1, s)\" and cfg\\<^sub>2: \"cfg\\<^sub>2 = (c\\<^sub>1', s')\"  by fact+\n  obtain c\\<^sub>1'' s'' where cfg'': \"cfg''=(c\\<^sub>1'',s'')\"\n    by (cases cfg'') auto\n  from step cfg\\<^sub>1 cfg'' \n  have s: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1,s) \\<rightarrow> (c\\<^sub>1'',s'')\"\n    by simp\n  hence \"\\<Gamma>\\<turnstile>\\<^sub>c (Catch c\\<^sub>1 c\\<^sub>2,s) \\<rightarrow> (Catch c\\<^sub>1'' c\\<^sub>2,s'')\"\n    by (rule stepc.Catchc)\n  also from Trans.hyps (3) [OF cfg'' cfg\\<^sub>2]\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Catch c\\<^sub>1'' c\\<^sub>2, s'') \\<rightarrow>\\<^sup>* (Catch c\\<^sub>1' c\\<^sub>2, s')\" .\n  finally show ?case .      \nqed\n\nlemma steps_Fault: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, Fault f) \\<rightarrow>\\<^sup>* (Skip, Fault f)\"\nproof (induct c)\n  case (Seq c\\<^sub>1 c\\<^sub>2)\n  have steps_c\\<^sub>1: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, Fault f) \\<rightarrow>\\<^sup>* (Skip, Fault f)\" by fact\n  have steps_c\\<^sub>2: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>2, Fault f) \\<rightarrow>\\<^sup>* (Skip, Fault f)\" by fact\n  from SeqSteps [OF steps_c\\<^sub>1 refl refl]\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Seq c\\<^sub>1 c\\<^sub>2, Fault f) \\<rightarrow>\\<^sup>* (Seq Skip c\\<^sub>2, Fault f)\".\n  also\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Seq Skip c\\<^sub>2, Fault f) \\<rightarrow> (c\\<^sub>2, Fault f)\" by (rule SeqSkipc)\n  also note steps_c\\<^sub>2\n  finally show ?case by simp\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have steps_c\\<^sub>1: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, Fault f) \\<rightarrow>\\<^sup>* (Skip, Fault f)\" by fact\n  from CatchSteps [OF steps_c\\<^sub>1 refl refl]\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Catch c\\<^sub>1 c\\<^sub>2, Fault f) \\<rightarrow>\\<^sup>* (Catch Skip c\\<^sub>2, Fault f)\".\n  also\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Catch Skip c\\<^sub>2, Fault f) \\<rightarrow> (Skip, Fault f)\" by (rule CatchSkipc) \n  finally show ?case by simp\nqed (fastforce intro: stepc.intros)+\n\n\nlemma steps_Stuck: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, Stuck) \\<rightarrow>\\<^sup>* (Skip, Stuck)\"\nproof (induct c)\n  case (Seq c\\<^sub>1 c\\<^sub>2)\n  have steps_c\\<^sub>1: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, Stuck) \\<rightarrow>\\<^sup>* (Skip, Stuck)\" by fact\n  have steps_c\\<^sub>2: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>2, Stuck) \\<rightarrow>\\<^sup>* (Skip, Stuck)\" by fact\n  from SeqSteps [OF steps_c\\<^sub>1 refl refl]\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Seq c\\<^sub>1 c\\<^sub>2, Stuck) \\<rightarrow>\\<^sup>* (Seq Skip c\\<^sub>2, Stuck)\".\n  also\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Seq Skip c\\<^sub>2, Stuck) \\<rightarrow> (c\\<^sub>2, Stuck)\" by (rule SeqSkipc)\n  also note steps_c\\<^sub>2\n  finally show ?case by simp\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have steps_c\\<^sub>1: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, Stuck) \\<rightarrow>\\<^sup>* (Skip, Stuck)\" by fact\n  from CatchSteps [OF steps_c\\<^sub>1 refl refl]\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Catch c\\<^sub>1 c\\<^sub>2, Stuck) \\<rightarrow>\\<^sup>* (Catch Skip c\\<^sub>2, Stuck)\" .\n  also\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Catch Skip c\\<^sub>2, Stuck) \\<rightarrow> (Skip, Stuck)\" by (rule CatchSkipc) \n  finally show ?case by simp\nqed (fastforce intro: stepc.intros)+\n\nlemma steps_Abrupt: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, Abrupt s) \\<rightarrow>\\<^sup>* (Skip, Abrupt s)\"\nproof (induct c)\n  case (Seq c\\<^sub>1 c\\<^sub>2)\n  have steps_c\\<^sub>1: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, Abrupt s) \\<rightarrow>\\<^sup>* (Skip, Abrupt s)\" by fact\n  have steps_c\\<^sub>2: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>2, Abrupt s) \\<rightarrow>\\<^sup>* (Skip, Abrupt s)\" by fact\n  from SeqSteps [OF steps_c\\<^sub>1 refl refl]\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Seq c\\<^sub>1 c\\<^sub>2, Abrupt s) \\<rightarrow>\\<^sup>* (Seq Skip c\\<^sub>2, Abrupt s)\".\n  also\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Seq Skip c\\<^sub>2, Abrupt s) \\<rightarrow> (c\\<^sub>2, Abrupt s)\" by (rule SeqSkipc)\n  also note steps_c\\<^sub>2\n  finally show ?case by simp\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have steps_c\\<^sub>1: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, Abrupt s) \\<rightarrow>\\<^sup>* (Skip, Abrupt s)\" by fact\n  from CatchSteps [OF steps_c\\<^sub>1 refl refl]\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Catch c\\<^sub>1 c\\<^sub>2, Abrupt s) \\<rightarrow>\\<^sup>* (Catch Skip c\\<^sub>2, Abrupt s)\".\n  also\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Catch Skip c\\<^sub>2, Abrupt s) \\<rightarrow> (Skip, Abrupt s)\" by (rule CatchSkipc) \n  finally show ?case by simp\nqed (fastforce intro: stepc.intros)+\n\nlemma step_Fault_prop: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s')\"\n  shows \"\\<And>f. s=Fault f \\<Longrightarrow> s'=Fault f\"\nusing step\nby (induct) auto\n\nlemma step_Abrupt_prop: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s')\"\n  shows \"\\<And>x. s=Abrupt x \\<Longrightarrow> s'=Abrupt x\"\nusing step\nby (induct) auto\n\nlemma step_Stuck_prop: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s')\"\n  shows \"s=Stuck \\<Longrightarrow> s'=Stuck\"\nusing step\nby (induct) auto\n\nlemma steps_Fault_prop: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sup>* (c', s')\"\n  shows \"s=Fault f \\<Longrightarrow> s'=Fault f\"\nusing step\nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl thus ?case by simp\nnext\n  case (Trans c s c'' s'')\n  thus ?case by (simp add: step_Fault_prop)    \nqed\n\nlemma steps_Abrupt_prop: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sup>* (c', s')\"\n  shows \"s=Abrupt t \\<Longrightarrow> s'=Abrupt t\"\nusing step\nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl thus ?case by simp\nnext\n  case (Trans c s c'' s'')\n  thus ?case\n    by (auto intro: step_Abrupt_prop)\nqed\n\nlemma steps_Stuck_prop: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sup>* (c', s')\"\n  shows \"s=Stuck \\<Longrightarrow> s'=Stuck\"\nusing step\nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl thus ?case by simp   \nnext\n  case (Trans c s c'' s'')\n  thus ?case\n    by (auto intro: step_Stuck_prop)\nqed\n\nlemma step_seq_throw_normal:\nassumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s')\" and\n        c_val: \"c=Seq Throw Q \\<and> c'=Throw\"\nshows \"\\<exists>sa. s=Normal sa\"\nusing step c_val\nproof (cases s)\n  case Normal \n  thus \"\\<exists>sa. s=Normal sa\" by auto\nnext\n  case Abrupt\n  thus \"\\<exists>sa. s=Normal sa\" using step c_val stepc_elim_cases(5)[of \\<Gamma> Throw Q s \"(Throw,s')\"] by auto \nnext \n  case Stuck\n  thus \"\\<exists>sa. s=Normal sa\" using step c_val stepc_elim_cases(5)[of \\<Gamma> Throw Q s \"(Throw,s')\"] by auto\nnext\n  case Fault\n    thus \"\\<exists>sa. s=Normal sa\" using step c_val stepc_elim_cases(5)[of \\<Gamma> Throw Q s \"(Throw,s')\"] by auto\nqed\n\n\nlemma step_catch_throw_normal:\nassumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s')\" and\n        c_val: \"c=Catch Throw Q \\<and> c'=Throw\"\nshows \"\\<exists>sa. s=Normal sa\"\nusing step c_val\nproof (cases s)\n  case Normal \n  thus \"\\<exists>sa. s=Normal sa\" by auto\nnext\n  case Abrupt\n  thus \"\\<exists>sa. s=Normal sa\" using step c_val stepc_elim_cases(12)[of \\<Gamma> Throw Q s \"(Throw,s')\"] by auto \nnext \n  case Stuck\n  thus \"\\<exists>sa. s=Normal sa\" using step c_val stepc_elim_cases(12)[of \\<Gamma> Throw Q s \"(Throw,s')\"] by auto\nnext\n  case Fault\n    thus \"\\<exists>sa. s=Normal sa\" using step c_val stepc_elim_cases(12)[of \\<Gamma> Throw Q s \"(Throw,s')\"] by auto\nqed\n\nlemma step_normal_to_normal[rule_format]:\nassumes step:\"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sup>* (c', s')\" and\n        sn: \"s = Normal sa\" and\n        finalc':\"(\\<Gamma>\\<turnstile>\\<^sub>c (c', s') \\<rightarrow>\\<^sup>*(c1, s1) \\<and>  (\\<exists>sb. s1 = Normal sb))\"\nshows \" (\\<exists>sc. s'=Normal sc)\"\nusing step sn finalc'                                  \n proof (induct arbitrary: sa rule: converse_rtranclp_induct2 [case_names Refl Trans])\n   case Refl show ?case by (simp add: Refl.prems)              \n next     \n   case (Trans c s c'' s'') thm converse_rtranclpE2 \n     thus ?case\n     proof (cases s'')  \n      case (Abrupt a1) thus ?thesis using finalc' by (metis steps_Abrupt_prop Trans.hyps(2))                \n     next\n      case Stuck thus ?thesis using finalc' by (metis steps_Stuck_prop Trans.hyps(2))          \n     next\n      case Fault thus ?thesis using finalc' by (metis steps_Fault_prop Trans.hyps(2))        \n     next \n      case Normal thus ?thesis using Trans.hyps(3) finalc' by blast \n    qed \nqed\n\nlemma step_spec_skip_normal_normal:\n  assumes a0:\"\\<Gamma>\\<turnstile>\\<^sub>c (c,s)  \\<rightarrow> (c',s')\" and\n          a1:\"c=Spec r e\" and\n          a2: \"s=Normal s1\" and\n          a3: \"c'=Skip\" and\n          a4: \"(\\<exists>t. (s1,t) \\<in> r)\"\n  shows \"\\<exists>s1'. s'=Normal s1'\"\nproof (cases s')  \n  case (Normal u) thus ?thesis by auto\nnext\n  case Stuck \n    have \"\\<forall>f r b p e. \\<not> f\\<turnstile>\\<^sub>c (LanguageCon.com.Spec r e, Normal b) \\<rightarrow> p \\<or> \n            (\\<exists>ba. p = (Skip::('b, 'a, 'c,'d) com, Normal ba) \\<and> (b, ba) \\<in> r) \\<or> \n            p = (Skip, Stuck) \\<and> (\\<forall>ba. (b, ba) \\<notin> r)\"\n      by (meson stepc_Normal_elim_cases(4))\n      thus ?thesis using a0 a1 a2 a4 by blast\nnext\n  case (Fault f) \n  have \"\\<forall>f r b p e. \\<not> f\\<turnstile>\\<^sub>c (LanguageCon.com.Spec r e, Normal b) \\<rightarrow> p \\<or> \n            (\\<exists>ba. p = (Skip::('b, 'a, 'c,'d) com, Normal ba) \\<and> (b, ba) \\<in> r) \\<or> \n            p = (Skip, Stuck) \\<and> (\\<forall>ba. (b, ba) \\<notin> r)\"\n    by (meson stepc_Normal_elim_cases(4))\n    thus ?thesis using a0 a1 a2 a4 by blast                       \nnext\n  have \"\\<forall>f r b p e. \\<not> f\\<turnstile>\\<^sub>c (LanguageCon.com.Spec r e, Normal b) \\<rightarrow> p \\<or> \n        (\\<exists>ba. p = (Skip::('b, 'a, 'c,'d) com, Normal ba) \\<and> (b, ba) \\<in> r) \\<or> \n        p = (Skip, Stuck) \\<and> (\\<forall>ba. (b, ba) \\<notin> r)\"\n    by (meson stepc_Normal_elim_cases(4))\n    thus ?thesis using a0 a1 a2 a4 by blast\nqed\n\n\ntext{* if not Normal not environmental *}\n\n(* \n\nNOTE\nCall always change the program now \n\nlemma no_advance_call_inf:\nassumes a0: \"redex p1 = Call f\" and\n        a1: \"(\\<Gamma> f) = Some (Call f)\" \nshows \"\\<Gamma>\\<turnstile>\\<^sub>c (p1,Normal s) \\<rightarrow> (p1, Normal s)\"\nusing a0 a1\nproof (induct p1)\n  case (Catch) thus ?case by (simp add: Catchc)\nnext\n  case (Seq) thus ?case by (simp add: Seqc)\nnext\n  case (Call) thus ?case\n    by (simp add: Callc) \nqed(auto) *)\n\nlemma no_advance_seq:\nassumes a0: \"P = Seq p1 p2\" and\n        a1: \"\\<Gamma>\\<turnstile>\\<^sub>c (p1,Normal s) \\<rightarrow> (p1, Normal s)\"\nshows \"\\<Gamma>\\<turnstile>\\<^sub>c (P,Normal s) \\<rightarrow> (P, Normal s)\"\nby (simp add: Seqc a0 a1)\n\nlemma no_advance_catch:\nassumes a0: \"P = Catch p1 p2\" and\n        a1: \"\\<Gamma>\\<turnstile>\\<^sub>c (p1,Normal s) \\<rightarrow> (p1, Normal s)\"\nshows \"\\<Gamma>\\<turnstile>\\<^sub>c (P,Normal s) \\<rightarrow> (P, Normal s)\"\nby (simp add: Catchc a0 a1)\n\nlemma not_step_c_env: \n\"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c, s') \\<Longrightarrow> \n (\\<And>sa. \\<not>(s=Normal sa)) \\<Longrightarrow> \n  (\\<And>sa. \\<not>(s'=Normal sa))\"\nby (fastforce elim:stepe_elim_cases)\n\nlemma step_c_env_not_normal_eq_state: \n\"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c, s') \\<Longrightarrow> \n (\\<And>sa. \\<not>(s=Normal sa)) \\<Longrightarrow> \n  s=s'\"\nby (fastforce elim:stepe_elim_cases)\n\nlemma not_eq_not_env:\n   assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>c\\<^sub>e (c', s')\" \n   shows \"~(c=c') \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c', s') \\<Longrightarrow> P\"\nusing step_m etranE by blast\n\n\nlemma step_ce_not_step_e_step_c:\n   assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>c\\<^sub>e (c', s')\" \n   shows \"\\<not> (\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c', s')) \\<Longrightarrow>(\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s'))\"\nusing step_m  step_ce_elim_cases by blast\n\nlemma step_ce_notNormal:   \n   assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>c\\<^sub>e (c', s')\" \n   shows \"(\\<forall>sa. \\<not>(s=Normal sa)) \\<Longrightarrow> s'=s\"\nusing step_m\nproof (induct rule:step_ce_induct) \n  case (e_step a b a' b')\n  have \"\\<forall>f p pa. \\<not> f\\<turnstile>\\<^sub>c p \\<rightarrow>\\<^sub>e pa \\<or> (\\<exists>c. (\\<exists>x. p = (c::('b, 'a, 'c,'d) LanguageCon.com, x)) \\<and> (\\<exists>x. pa = (c, x)))\"\n    by (fastforce elim:etranE stepe_elim_cases)\n  thus ?case\n    using stepe_elim_cases e_step.hyps e_step.prems by blast\nnext\n  case (c_step a b a' b')\n  thus ?case \n  proof (cases b)\n    case (Normal) thus ?thesis using c_step.prems by auto   \n  next\n    case (Stuck) thus ?thesis  \n      using SmallStepCon.step_Stuck_prop c_step.hyps by blast \n  next\n    case (Fault f) thus ?thesis \n     using SmallStepCon.step_Fault_prop c_step.hyps by fastforce\n  next\n    case (Abrupt a) thus ?thesis\n      using SmallStepCon.step_Abrupt_prop c_step.hyps by fastforce \n  qed\nqed\n\nlemma steps_ce_not_Normal:  \n   assumes step_m: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (c', s')\" \n   shows \"\\<forall>sa. \\<not>(s=Normal sa) \\<Longrightarrow> s'=s\"\nusing step_m\nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl then show ?case by auto\nnext\n  case (Trans a b a' b') \n  thus ?case using step_ce_notNormal by blast \nqed\n\nlemma steps_not_normal_ce_c: \n  assumes steps: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (c', s')\"\n  shows         \"( \\<forall>sa. \\<not>(s=Normal sa)) \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sup>* (c', s')\"\nusing steps\nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl thus ?case by auto\nnext\n  case (Trans a b a' b') \n    then have \"b=b'\" using step_ce_notNormal by blast\n    then have \"\\<Gamma>\\<turnstile>\\<^sub>c (a', b') \\<rightarrow>\\<^sup>* (c', s')\" using `b=b'` Trans.hyps(3) Trans.prems by blast\n    then have \"\\<Gamma>\\<turnstile>\\<^sub>c (a, b) \\<rightarrow> (a', b') \\<or> \\<Gamma>\\<turnstile>\\<^sub>c (a, b) \\<rightarrow>\\<^sub>e (a', b')\"\n      using Trans.hyps(1) by (fastforce elim: step_ce_elim_cases)\n    thus ?case\n    proof\n      assume \"\\<Gamma>\\<turnstile>\\<^sub>c (a, b) \\<rightarrow> (a', b')\" \n      thus ?thesis using `\\<Gamma>\\<turnstile>\\<^sub>c (a', b') \\<rightarrow>\\<^sup>* (c', s')` by auto \n    next\n      assume \"\\<Gamma>\\<turnstile>\\<^sub>c (a, b) \\<rightarrow>\\<^sub>e (a', b')\"   \n       have \"a = a'\"\n         by (meson Trans.hyps(1) `\\<Gamma>\\<turnstile>\\<^sub>c (a, b) \\<rightarrow>\\<^sub>e (a', b')` not_eq_not_env)   \n         thus ?thesis using `\\<Gamma>\\<turnstile>\\<^sub>c (a', b') \\<rightarrow>\\<^sup>* (c', s')` `b = b'` by force           \n    qed\nqed\n\nlemma steps_c_ce: \n  assumes steps: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sup>* (c', s')\"\n  shows         \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (c', s')\"\nusing steps\nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl thus ?case by auto\nnext\n  case (Trans a b a' b') \n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (a, b) \\<rightarrow>\\<^sub>c\\<^sub>e (a', b')\"\n    using Trans.hyps(1) c_step by blast\n  thus ?case\n    by (simp add: Trans.hyps(3) converse_rtranclp_into_rtranclp)\nqed\n\nlemma steps_not_normal_c_ce: \n  assumes steps: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sup>* (c', s')\"\n  shows         \"( \\<forall>sa. \\<not>(s=Normal sa)) \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (c', s')\"\nby (simp add: steps steps_c_ce)\n\nlemma steps_not_normal_c_eq_ce:\nassumes normal: \"( \\<forall>sa. \\<not>(s=Normal sa))\"\nshows         \" \\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sup>* (c', s') =  \\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (c', s')\"\nusing normal\nusing steps_c_ce steps_not_normal_ce_c by auto \n\nlemma steps_ce_Fault: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, Fault f) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (Skip, Fault f)\"\nby (simp add: SmallStepCon.steps_Fault steps_c_ce)\n\nlemma steps_ce_Stuck: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, Stuck) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (Skip, Stuck)\"\nby (simp add: SmallStepCon.steps_Stuck steps_c_ce)\n\nlemma steps_ce_Abrupt: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, Abrupt a) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (Skip, Abrupt a)\"\nby (simp add: SmallStepCon.steps_Abrupt steps_c_ce)\n\nlemma step_ce_seq_throw_normal:\nassumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>c\\<^sub>e (c', s')\" and\n        c_val: \"c=Seq Throw Q \\<and> c'=Throw\"\nshows \"\\<exists>sa. s=Normal sa\"\nusing step c_val not_eq_not_env \n      step_ce_not_step_e_step_c step_seq_throw_normal by blast\n\nlemma step_ce_catch_throw_normal:\nassumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>c\\<^sub>e (c', s')\" and\n        c_val: \"c=Catch Throw Q \\<and> c'=Throw\"\nshows \"\\<exists>sa. s=Normal sa\"\nusing step c_val not_eq_not_env\n      step_ce_not_step_e_step_c step_catch_throw_normal  by blast \n\nlemma step_ce_normal_to_normal[rule_format]:\nassumes step:\"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (c', s')\" and\n        sn: \"s = Normal sa\" and\n        finalc':\"(\\<Gamma>\\<turnstile>\\<^sub>c (c', s') \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>*(c1, s1) \\<and>  (\\<exists>sb. s1 = Normal sb))\"\nshows \"         \n       (\\<exists>sc. s'=Normal sc)\"\nusing step sn finalc' steps_ce_not_Normal by blast      \n\nlemma SeqSteps_ce: \n  assumes steps: \"\\<Gamma>\\<turnstile>\\<^sub>c cfg\\<^sub>1\\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* cfg\\<^sub>2\"\n  shows \"\\<And> c\\<^sub>1 s c\\<^sub>1' s'. \\<lbrakk>cfg\\<^sub>1 = (c\\<^sub>1,s);cfg\\<^sub>2=(c\\<^sub>1',s')\\<rbrakk>\n          \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(Seq c\\<^sub>1 c\\<^sub>2,s) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (Seq c\\<^sub>1' c\\<^sub>2, s')\"\nusing steps\nproof (induct rule: converse_rtranclp_induct [case_names Refl Trans]) \n  case Refl\n  thus ?case\n    by simp\nnext\n  case (Trans cfg\\<^sub>1 cfg'') \n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c cfg\\<^sub>1 \\<rightarrow> cfg'' \\<or> \\<Gamma>\\<turnstile>\\<^sub>c cfg\\<^sub>1 \\<rightarrow>\\<^sub>e cfg''\" \n   using step_ce_elim_cases by blast\n  thus ?case \n  proof\n    assume a1:\"\\<Gamma>\\<turnstile>\\<^sub>c cfg\\<^sub>1 \\<rightarrow>\\<^sub>e cfg''\"          \n    have \"\\<forall>f p pa. \\<not> f\\<turnstile>\\<^sub>c p \\<rightarrow>\\<^sub>e pa \\<or> (\\<exists>c. \n                   (\\<exists>x. p = (c::('a, 'b, 'c,'d) LanguageCon.com, x)) \\<and> (\\<exists>x. pa = (c, x)))\"\n      by (meson etranE)\n    then obtain cc :: \"('b \\<Rightarrow> ('a, 'b, 'c,'d) LanguageCon.com option) \\<Rightarrow> \n                              ('a, 'b, 'c,'d) LanguageCon.com \\<times> ('a, 'c) xstate \\<Rightarrow> \n                              ('a, 'b, 'c,'d) LanguageCon.com \\<times> ('a, 'c) xstate \\<Rightarrow> \n                              ('a, 'b, 'c,'d) LanguageCon.com\" and \n                xx :: \"('b \\<Rightarrow> ('a, 'b, 'c,'d) LanguageCon.com option) \\<Rightarrow> \n                       ('a, 'b, 'c,'d) LanguageCon.com \\<times> ('a, 'c) xstate \\<Rightarrow> \n                       ('a, 'b, 'c,'d) LanguageCon.com \\<times> ('a, 'c) xstate \\<Rightarrow> ('a, 'c) xstate\" and\n                xxa :: \"('b \\<Rightarrow> ('a, 'b, 'c,'d) LanguageCon.com option) \\<Rightarrow> \n                        ('a, 'b, 'c,'d) LanguageCon.com \\<times> ('a, 'c) xstate \\<Rightarrow> \n                       ('a, 'b, 'c,'d) LanguageCon.com \\<times> ('a, 'c) xstate \\<Rightarrow> ('a, 'c) xstate\" where\n      f1: \"\\<forall>f p pa. \\<not> f\\<turnstile>\\<^sub>c p \\<rightarrow>\\<^sub>e pa \\<or> p = (cc f p pa, xx f p pa) \\<and> pa = (cc f p pa, xxa f p pa)\"\n      by (metis (no_types))\n    have f2: \"\\<forall>f c x xa. \\<not> f\\<turnstile>\\<^sub>c (c::('a, 'b, 'c,'d) LanguageCon.com, x) \\<rightarrow>\\<^sub>e (c, xa) \\<or> \n                            (\\<exists>a. x = Normal a) \\<or> (\\<forall>a. xa \\<noteq> Normal a) \\<and> x = xa\"\n      by (metis stepe_elim_cases)\n    have f3: \"(c\\<^sub>1, xxa \\<Gamma> cfg\\<^sub>1 cfg'') = cfg''\"\n      using f1 by (metis Trans.prems(1) a1 fst_conv)\n    hence \"\\<Gamma>\\<turnstile>\\<^sub>c (LanguageCon.com.Seq c\\<^sub>1 c\\<^sub>2, xxa \\<Gamma> cfg\\<^sub>1 cfg'') \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (LanguageCon.com.Seq c\\<^sub>1' c\\<^sub>2, s')\"\n      using Trans.hyps(3) Trans.prems(2) by force\n    thus ?thesis\n      using f3 f2 by (metis (no_types) Env Trans.prems(1) a1 e_step r_into_rtranclp \n                       rtranclp.rtrancl_into_rtrancl rtranclp_idemp)   \n  next\n     assume \"\\<Gamma>\\<turnstile>\\<^sub>c cfg\\<^sub>1 \\<rightarrow> cfg''\"\n     thus ?thesis\n      proof -\n        have \"\\<forall>p. \\<exists>c x. p = (c::('a, 'b, 'c,'d) LanguageCon.com, x::('a, 'c) xstate)\"\n          by auto\n        thus ?thesis\n          by (metis (no_types) Seqc Trans.hyps(3) Trans.prems(1) Trans.prems(2) \n                   `\\<Gamma>\\<turnstile>\\<^sub>c cfg\\<^sub>1 \\<rightarrow> cfg''` c_step converse_rtranclp_into_rtranclp)\n      qed\n  qed\nqed\n\n\nlemma CatchSteps_ce: \n  assumes steps: \"\\<Gamma>\\<turnstile>\\<^sub>ccfg\\<^sub>1\\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* cfg\\<^sub>2\"\n  shows \"\\<And> c\\<^sub>1 s c\\<^sub>1' s'. \\<lbrakk>cfg\\<^sub>1 = (c\\<^sub>1,s); cfg\\<^sub>2=(c\\<^sub>1',s')\\<rbrakk>\n          \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(Catch c\\<^sub>1 c\\<^sub>2,s) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (Catch c\\<^sub>1' c\\<^sub>2, s')\"\nusing steps\nproof (induct rule: converse_rtranclp_induct [case_names Refl Trans])\n  case Refl\n  thus ?case\n    by simp\nnext\n  case (Trans cfg\\<^sub>1 cfg'')\nthen have \"\\<Gamma>\\<turnstile>\\<^sub>c cfg\\<^sub>1 \\<rightarrow> cfg'' \\<or> \\<Gamma>\\<turnstile>\\<^sub>c cfg\\<^sub>1 \\<rightarrow>\\<^sub>e cfg''\" \n   using step_ce_elim_cases by blast\n  thus ?case \n  proof\n    assume a1:\"\\<Gamma>\\<turnstile>\\<^sub>c cfg\\<^sub>1 \\<rightarrow>\\<^sub>e cfg''\"        \n    have \"\\<forall>f p pa. \\<not> f\\<turnstile>\\<^sub>c p \\<rightarrow>\\<^sub>e pa \\<or> (\\<exists>c. (\\<exists>x. p = (c::('a, 'b, 'c,'d) LanguageCon.com, x)) \\<and> (\\<exists>x. pa = (c, x)))\"\n      by (meson etranE)\n    then obtain cc :: \"('b \\<Rightarrow>('a, 'b, 'c, 'd) LanguageCon.com option) \\<Rightarrow>\n                        ('a, 'b, 'c, 'd) LanguageCon.com \\<times> ('a, 'c) xstate \\<Rightarrow>\n                        ('a, 'b, 'c, 'd) LanguageCon.com \\<times> ('a, 'c) xstate \\<Rightarrow>\n                        ('a, 'b, 'c, 'd) LanguageCon.com\" and \n                xx :: \"('b \\<Rightarrow>('a, 'b, 'c, 'd) LanguageCon.com option) \\<Rightarrow>\n                       ('a, 'b, 'c, 'd) LanguageCon.com \\<times> ('a, 'c) xstate \\<Rightarrow>\n                       ('a, 'b, 'c, 'd) LanguageCon.com \\<times> ('a, 'c) xstate \\<Rightarrow> \n                       ('a, 'c) xstate\" and \n                xxa :: \"('b \\<Rightarrow>('a, 'b, 'c, 'd) LanguageCon.com option) \\<Rightarrow>\n                         ('a, 'b, 'c, 'd) LanguageCon.com \\<times> ('a, 'c) xstate \\<Rightarrow>\n                         ('a, 'b, 'c, 'd) LanguageCon.com \\<times> ('a, 'c) xstate \\<Rightarrow> ('a, 'c) xstate\" where\n      f1: \"\\<forall>f p pa. \\<not> f\\<turnstile>\\<^sub>c p \\<rightarrow>\\<^sub>e pa \\<or> p = (cc f p pa, xx f p pa) \\<and> pa = (cc f p pa, xxa f p pa)\"\n      by (metis (no_types))\n    have f2: \"\\<forall>f c x xa. \\<not> f\\<turnstile>\\<^sub>c (c::('a, 'b, 'c,'d) LanguageCon.com, x) \\<rightarrow>\\<^sub>e (c, xa) \\<or> \n                         (\\<exists>a. x = Normal a) \\<or> (\\<forall>a. xa \\<noteq> Normal a) \\<and> x = xa\"\n      by (metis stepe_elim_cases)\n    have f3: \"(c\\<^sub>1, xxa \\<Gamma> cfg\\<^sub>1 cfg'') = cfg''\"\n      using f1 by (metis Trans.prems(1) a1 fst_conv)\n    hence \"\\<Gamma>\\<turnstile>\\<^sub>c (LanguageCon.com.Catch c\\<^sub>1 c\\<^sub>2, xxa \\<Gamma> cfg\\<^sub>1 cfg'') \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (LanguageCon.com.Catch c\\<^sub>1' c\\<^sub>2, s')\"\n      using Trans.hyps(3) Trans.prems(2) by force\n    thus ?thesis\n      using f3 f2 by (metis (no_types) Env Trans.prems(1) a1 e_step r_into_rtranclp rtranclp.rtrancl_into_rtrancl rtranclp_idemp)              \n  next\n    assume \"\\<Gamma>\\<turnstile>\\<^sub>c cfg\\<^sub>1 \\<rightarrow> cfg''\"\n    thus ?thesis\n    proof -\n      obtain cc :: \"('a, 'b, 'c, 'd) LanguageCon.com \\<times> ('a, 'c) xstate \\<Rightarrow> ('a, 'b, 'c, 'd) LanguageCon.com\" and xx :: \"('a, 'b, 'c, 'd) LanguageCon.com \\<times> ('a, 'c) xstate \\<Rightarrow> ('a, 'c) xstate\" where\n        f1: \"\\<forall>p. p = (cc p, xx p)\"\n        by (meson old.prod.exhaust)\n      hence \"\\<And>c. \\<Gamma>\\<turnstile>\\<^sub>c (LanguageCon.com.Catch c\\<^sub>1 c, s) \\<rightarrow> (LanguageCon.com.Catch (cc cfg'') c, xx cfg'')\"\n        by (metis (no_types) Catchc Trans.prems(1) `\\<Gamma>\\<turnstile>\\<^sub>c cfg\\<^sub>1 \\<rightarrow> cfg''`)\n      thus ?thesis\n        using f1 by (meson Trans.hyps(3) Trans.prems(2) c_step converse_rtranclp_into_rtranclp)\n    qed      \n  qed\nqed\n\nlemma step_change_p_or_eq_Ns: \n    assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P,Normal s) \\<rightarrow> (Q,s')\"\n    shows  \"\\<not>(P=Q)\"\nusing step\nproof (induct P arbitrary: Q s s')\nqed(fastforce elim: stepc_Normal_elim_cases)+\n\n \nlemma step_change_p_or_eq_s: \n    assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P,s) \\<rightarrow> (Q,s')\"\n    shows  \"\\<not>(P=Q)\"\nusing step\nproof (induct P arbitrary: Q s s')\nqed (fastforce elim: stepc_elim_cases)+\n\nsubsection {* Relation between @{term \"stepc_rtrancl\"} and @{term \"cptn\"} *}\n\nlemma stepc_rtrancl_cptn:\n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c,s) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (cf,sf)\"           \n  shows \"\\<exists>xs. (\\<Gamma>,(c, s)#xs) \\<in> cptn \\<and>(cf,sf) = (last ((c,s)#xs))\"\nusing step \nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans]) \n  case Refl thus ?case using cptn.CptnOne by auto\nnext\n  case (Trans c s c' s')  \n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c', s') \\<or> \\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s')\"\n    by (meson Trans.hyps(1) step_ce.simps)\n  then show ?case\n  proof\n    assume prem:\"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sub>e (c', s')\"       \n    then have ceqc':\"c=c'\" using prem env_c_c'\n      by auto           \n    obtain xs where xs_s:\"(\\<Gamma>, (c', s') # xs) \\<in> cptn \\<and> (cf, sf) = last ((c', s') # xs)\"\n      using Trans(3) by auto \n    then have xs_f: \"(\\<Gamma>, (c, s)#(c', s') # xs) \\<in> cptn\" \n    using cptn.CptnEnv ceqc'  prem by fastforce\n    also have \"last ((c', s') # xs) = last ((c,s)#(c', s') # xs)\" by auto\n    then have \"(cf, sf) = last ((c, s) # (c', s') # xs)\"\n      using   xs_s by auto\n    thus ?thesis\n      using  xs_f by blast\n  next\n    assume prem:\"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s')\" \n    obtain xs where xs_s:\"(\\<Gamma>, (c', s') # xs) \\<in> cptn \\<and> (cf, sf) = last ((c', s') # xs) \"\n      using Trans(3) by auto \n    have \"(\\<Gamma>, (c, s) # (c', s') # xs) \\<in> cptn\" using cptn.CptnComp \n      using xs_s prem by blast \n    also have \"last ((c', s') # xs) = last ((c,s)#(c', s') # xs)\" by auto\n    ultimately show ?thesis using xs_s by fastforce\n  qed \nqed\n\n\nlemma cptn_stepc_rtrancl:\n  assumes cptn_step: \"(\\<Gamma>,(c, s)#xs) \\<in> cptn\" and\n          cf_last:\"(cf,sf) = (last ((c,s)#xs))\"\n  shows \"\\<Gamma>\\<turnstile>\\<^sub>c (c,s) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (cf,sf)\"\nusing cptn_step cf_last\nproof (induct xs arbitrary: c s) \n  case Nil\n  thus ?case by simp \nnext\n  case (Cons a xs c s) \n  then obtain ca sa where eq_pair: \"a=(ca,sa)\" and \"(cf, sf) = last ((ca,sa) # xs) \" \n       using Cons by (fastforce)  \n  have f1: \"\\<forall>f p pa. \\<not> (f::'a \\<Rightarrow> ('b, _, 'c,'d) LanguageCon.com option)\\<turnstile>\\<^sub>c p \\<rightarrow> pa \\<or> f\\<turnstile>\\<^sub>c p \\<rightarrow>\\<^sub>c\\<^sub>e pa\"\n    by (simp add: c_step)\n  have f2: \"(\\<Gamma>, (c, s) # (ca, sa) # xs) \\<in> cptn\"\n    using `(\\<Gamma>, (c, s) # a # xs) \\<in> cptn` eq_pair by blast\n  have f3: \"\\<forall>f p pa. \\<not> (f::'a \\<Rightarrow> ('b, _, 'c,'d) LanguageCon.com option)\\<turnstile>\\<^sub>c p \\<rightarrow>\\<^sub>e pa \\<or> f\\<turnstile>\\<^sub>c p \\<rightarrow>\\<^sub>c\\<^sub>e pa\"\n    using e_step by blast\n  have \"\\<forall>c x. (\\<Gamma>, (c, x) # xs) \\<notin> cptn \\<or> (cf, sf) \\<noteq> last ((c, x) # xs) \\<or> \\<Gamma>\\<turnstile>\\<^sub>c (c, x) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (cf, sf)\"\n    using Cons.hyps by blast\n  thus ?case\n    using f3 f2 f1 by (metis (no_types) `(cf, sf) = last ((ca, sa) # xs)` converse_rtranclp_into_rtranclp cptn_elim_cases(2)) \nqed\n\nlemma three_elems_list:\n  assumes a1:\"length l > 2\"\n  shows \"\\<exists>a0 a1 a2 l1. l=a0#a1#a2#l1\"\nusing a1 by (metis Cons_nth_drop_Suc One_nat_def Suc_1 Suc_leI add_lessD1 drop_0 length_greater_0_conv list.size(3) not_numeral_le_zero one_add_one)  \n\nlemma cptn_stepc_rtran:\n  assumes cptn_step: \"(\\<Gamma>,x#xs) \\<in> cptn\" and          \n          a1:\"Suc i < length (x#xs)\"\n  shows \"\\<Gamma>\\<turnstile>\\<^sub>c ((x#xs)!i) \\<rightarrow>\\<^sub>c\\<^sub>e ((x#xs)!(Suc i))\"\nusing cptn_step a1\nproof (induct i arbitrary: x xs)\n  case 0\n    then obtain x1 xs1 where xs:\"xs=x1#xs1\"\n      by (metis length_Cons less_not_refl list.exhaust list.size(3))    \n    then have \"(x#x1#xs1)!Suc 0 = x1\" by fastforce  \n    have x_x1_cptn:\"(\\<Gamma>,x#x1#xs1)\\<in>cptn\" using 0 xs by auto    \n    then have \"(\\<Gamma>,x1#xs1)\\<in>cptn\"\n      using cptn_dest_pair by fastforce\n    then have \"\\<Gamma>\\<turnstile>\\<^sub>cx \\<rightarrow>\\<^sub>e x1 \\<or> \\<Gamma>\\<turnstile>\\<^sub>cx \\<rightarrow> x1\" \n      using cptn_elim_cases_pair x_x1_cptn  by blast        \n    then have \"\\<Gamma>\\<turnstile>\\<^sub>c x \\<rightarrow>\\<^sub>c\\<^sub>e x1\"\n      by (metis c_step e_step)\n    then show ?case \n      by (simp add: xs)\nnext\n   case (Suc i)\n    then have \"Suc i < length xs\" by auto\n    moreover then obtain x1 xs1 where xs:\"xs=x1#xs1\"\n      by (metis (full_types) list.exhaust list.size(3) not_less0)\n    moreover then have \"(\\<Gamma>,x1#xs1) \\<in> cptn\" using Suc cptn_dest_pair by blast\n    ultimately have \"\\<Gamma>\\<turnstile>\\<^sub>c ((x1 # xs1) ! i) \\<rightarrow>\\<^sub>c\\<^sub>e ((x1 # xs1) ! Suc i)\" \n      using Suc by auto\n    thus ?case using Suc xs by auto\nqed \n     \n      \nlemma cptn_stepconf_rtrancl:\n  assumes cptn_step: \"(\\<Gamma>,cfg1#xs) \\<in> cptn\" and\n          cf_last:\"cfg2 = (last (cfg1#xs))\"\n  shows \"\\<Gamma>\\<turnstile>\\<^sub>c cfg1 \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* cfg2\"\nusing cptn_step cf_last\nby (metis cptn_stepc_rtrancl prod.collapse)\n\nlemma cptn_all_steps_rtrancl:\n  assumes cptn_step: \"(\\<Gamma>,cfg1#xs) \\<in> cptn\"          \n  shows \"\\<forall>i<length (cfg1#xs). \\<Gamma>\\<turnstile>\\<^sub>c cfg1 \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* ((cfg1#xs)!i)\"\nusing cptn_step \nproof (induct xs arbitrary: cfg1)\n  case Nil thus ?case by auto\nnext\n  case (Cons x xs1) thus ?case\n  proof -\n     have hyp:\"\\<forall>i<length (x # xs1). \\<Gamma>\\<turnstile>\\<^sub>c x \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* ((x # xs1) ! i)\"\n       using Cons.hyps Cons.prems cptn_dest_pair by blast      \n     thus ?thesis\n     proof\n     {\n        fix i\n        assume a0:\"i<length (cfg1 # x # xs1)\"\n        then have \"Suc 0 < length (cfg1 # x # xs1)\"\n          by simp\n        hence \"\\<Gamma>\\<turnstile>\\<^sub>c (cfg1 # x # xs1) ! 0 \\<rightarrow>\\<^sub>c\\<^sub>e ((cfg1 # x # xs1) ! Suc 0)\"\n          using Cons.prems cptn_stepc_rtran by blast\n        then have \"\\<Gamma>\\<turnstile>\\<^sub>c cfg1 \\<rightarrow>\\<^sub>c\\<^sub>e x\" using Cons by simp\n        also have  \"i < Suc (Suc (length xs1))\"\n          using a0 by force\n        ultimately have \"\\<Gamma>\\<turnstile>\\<^sub>c cfg1 \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (cfg1 # x # xs1) ! i\" using hyp Cons\n         using converse_rtranclp_into_rtranclp hyp less_Suc_eq_0_disj \n         by auto \n     } thus ?thesis by auto qed\n  qed\nqed\n\nlemma cptn_env_same_prog:\nassumes a0: \"(\\<Gamma>, l) \\<in> cptn\" and\n        a1:  \"\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))\" and\n        a2: \"Suc j < length l\"\nshows \"fst (l!j) =  fst (l!0)\"\nusing a0 a1 a2\nproof (induct j arbitrary: l)\n  case 0 thus ?case by auto\nnext\n  case (Suc j) \n    then have \"fst (l!j) =  fst (l!0)\" by fastforce\n    thus ?case using Suc \n      by (metis (no_types) env_c_c' lessI prod.collapse)\nqed\n\nlemma takecptn_is_cptn [rule_format, elim!]:\n  \"\\<forall>j. (\\<Gamma>,c) \\<in> cptn \\<longrightarrow> (\\<Gamma>, take (Suc j) c) \\<in> cptn\"\napply(induct \"c\")\n apply(force elim: cptn.cases)\napply clarify\napply(case_tac j)\n apply simp\n apply(rule CptnOne)\napply simp\napply(force intro:cptn.intros elim:cptn.cases)\ndone\n\n\n\nlemma dropcptn_is_cptn [rule_format,elim!]:\n  \"\\<forall>j<length c. (\\<Gamma>,c) \\<in> cptn \\<longrightarrow> (\\<Gamma>, drop j c) \\<in> cptn\"\napply(induct \"c\")\n apply(force elim: cptn.cases)\napply clarify\napply(case_tac j,simp+)\napply(erule cptn.cases)\n  apply simp\n apply force\napply force\ndone\n\nlemma takepar_cptn_is_par_cptn [rule_format,elim]:\n  \"\\<forall>j. (\\<Gamma>,c) \\<in> par_cptn \\<longrightarrow> (\\<Gamma>,take (Suc j) c) \\<in> par_cptn\"\napply(induct \"c\")\n apply(force elim: cptn.cases)\napply clarify\napply(case_tac j,simp)\n apply(rule ParCptnOne)\napply(force intro:par_cptn.intros elim:par_cptn.cases)\ndone\n\nlemma droppar_cptn_is_par_cptn [rule_format]:\n  \"\\<forall>j<length c. (\\<Gamma>,c) \\<in> par_cptn \\<longrightarrow> (\\<Gamma>,drop j c) \\<in> par_cptn\"\napply(induct \"c\")\n apply(force elim: par_cptn.cases)\napply clarify\napply(case_tac j,simp+)\napply(erule par_cptn.cases)\n  apply simp\n apply force\napply force\ndone\n\n\nsubsection\\<open>Modular Definition of Computation\\<close>\ndefinition lift :: \"('s,'p,'f,'e) com \\<Rightarrow> ('s,'p,'f,'e) config \\<Rightarrow> ('s,'p,'f,'e) config\" where\n  \"lift Q \\<equiv> \\<lambda>(P, s).  ((Seq P Q), s)\" \n\ndefinition lift_catch :: \"('s,'p,'f,'e) com \\<Rightarrow> ('s,'p,'f,'e) config \\<Rightarrow> ('s,'p,'f,'e) config\" where\n  \"lift_catch Q \\<equiv> \\<lambda>(P, s).  (Catch P Q, s)\"     \n\n\ninductive_set cptn_mod :: \"(('s,'p,'f,'e) confs) set\"\nwhere\n  CptnModOne: \"(\\<Gamma>,[(P, s)]) \\<in> cptn_mod\"\n| CptnModEnv: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow>\\<^sub>e (P,t);(\\<Gamma>,(P, t)#xs) \\<in> cptn_mod \\<rbrakk> \\<Longrightarrow> \n               (\\<Gamma>,(P, s)#(P, t)#xs) \\<in> cptn_mod\"\n| CptnModSkip: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow> (Skip,t); redex P = P;\n                (\\<Gamma>,(Skip, t)#xs) \\<in> cptn_mod \\<rbrakk> \\<Longrightarrow> \n                (\\<Gamma>,(P,s)#(Skip, t)#xs) \\<in>cptn_mod\"\n\n| CptnModThrow: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow> (Throw,t); redex P = P;\n                (\\<Gamma>,(Throw, t)#xs) \\<in> cptn_mod \\<rbrakk> \\<Longrightarrow> \n                (\\<Gamma>,(P,s)#(Throw, t)#xs) \\<in>cptn_mod\"\n\n| CptnModCondT: \"\\<lbrakk>(\\<Gamma>,(P0, Normal s)#ys) \\<in> cptn_mod; s \\<in> b \\<rbrakk> \\<Longrightarrow> \n                (\\<Gamma>,((Cond b P0 P1), Normal s)#(P0, Normal s)#ys) \\<in> cptn_mod\"\n| CptnModCondF: \"\\<lbrakk>(\\<Gamma>,(P1, Normal s)#ys) \\<in> cptn_mod; s \\<notin> b \\<rbrakk> \\<Longrightarrow> \n                (\\<Gamma>,((Cond b P0 P1), Normal s)#(P1, Normal s)#ys) \\<in> cptn_mod\"\n| CptnModSeq1: \n  \"\\<lbrakk>(\\<Gamma>,(P0, s)#xs) \\<in> cptn_mod; zs=map (lift P1) xs \\<rbrakk> \\<Longrightarrow> \n   (\\<Gamma>,((Seq P0 P1), s)#zs) \\<in> cptn_mod\"\n\n| CptnModSeq2: \n  \"\\<lbrakk>(\\<Gamma>, (P0, s)#xs) \\<in> cptn_mod; fst(last ((P0, s)#xs)) = Skip;\n    (\\<Gamma>,(P1, snd(last ((P0, s)#xs)))#ys) \\<in> cptn_mod;\n    zs=(map (lift P1) xs)@((P1, snd(last ((P0, s)#xs)))#ys) \\<rbrakk> \\<Longrightarrow> \n   (\\<Gamma>,((Seq P0 P1), s)#zs) \\<in> cptn_mod\"\n(*| CptnModSeq3:\n  \"\\<lbrakk> (\\<Gamma>,(P1, s)#xs) \\<in> cptn_mod\\<rbrakk> \\<Longrightarrow> (\\<Gamma>,((Seq Skip P1), s)#(P1, s)#xs) \\<in> cptn_mod\"*)\n\n| CptnModSeq3: \n  \"\\<lbrakk>(\\<Gamma>, (P0, Normal s)#xs) \\<in> cptn_mod; \n    fst(last ((P0, Normal s)#xs)) = Throw;\n    snd(last ((P0, Normal s)#xs)) = Normal s'; \n    (\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod; \n    zs=(map (lift P1) xs)@((Throw,Normal s')#ys) \\<rbrakk> \\<Longrightarrow>\n   (\\<Gamma>,((Seq P0 P1), Normal s)#zs) \\<in> cptn_mod\"\n\n| CptnModWhile1: \n  \"\\<lbrakk>(\\<Gamma>, (P, Normal s)#xs) \\<in> cptn_mod; s \\<in> b; \n    zs=map (lift (While b P)) xs \\<rbrakk> \\<Longrightarrow> \n    (\\<Gamma>, ((While b P), Normal s)#\n      ((Seq P (While b P)),Normal s)#zs) \\<in> cptn_mod\"\n\n| CptnModWhile2: \n  \"\\<lbrakk> (\\<Gamma>, (P, Normal s)#xs) \\<in> cptn_mod; \n     fst(last ((P, Normal s)#xs))=Skip; s \\<in> b; \n     zs=(map (lift (While b P)) xs)@\n      (While b P, snd(last ((P, Normal s)#xs)))#ys; \n      (\\<Gamma>,(While b P, snd(last ((P, Normal s)#xs)))#ys) \\<in> \n        cptn_mod\\<rbrakk> \\<Longrightarrow> \n   (\\<Gamma>,(While b P, Normal s)#\n     (Seq P (While b P), Normal s)#zs) \\<in> cptn_mod\"\n\n| CptnModWhile3: \n  \"\\<lbrakk> (\\<Gamma>, (P, Normal s)#xs) \\<in> cptn_mod; \n     fst(last ((P, Normal s)#xs))=Throw; s \\<in> b;\n     snd(last ((P, Normal s)#xs)) = Normal s'; \n    (\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod;  \n     zs=(map (lift (While b P)) xs)@((Throw,Normal s')#ys)\\<rbrakk> \\<Longrightarrow> \n   (\\<Gamma>,(While b P, Normal s)#\n     (Seq P (While b P), Normal s)#zs) \\<in> cptn_mod\"\n\n| CptnModCall: \"\\<lbrakk>(\\<Gamma>,(bdy, Normal s)#ys) \\<in> cptn_mod;\\<Gamma> p = Some bdy; bdy\\<noteq>Call p \\<rbrakk> \\<Longrightarrow> \n                (\\<Gamma>,((Call p), Normal s)#(bdy, Normal s)#ys) \\<in> cptn_mod\" \n| CptnModDynCom: \"\\<lbrakk>(\\<Gamma>,(c s, Normal s)#ys) \\<in> cptn_mod \\<rbrakk> \\<Longrightarrow> \n                  (\\<Gamma>,(DynCom c, Normal s)#(c s, Normal s)#ys) \\<in> cptn_mod\"\n\n| CptnModGuard: \"\\<lbrakk>(\\<Gamma>,(c, Normal s)#ys) \\<in> cptn_mod; s \\<in> g \\<rbrakk> \\<Longrightarrow> \n                 (\\<Gamma>,(Guard f g c, Normal s)#(c, Normal s)#ys) \\<in> cptn_mod\"\n\n| CptnModCatch1: \"\\<lbrakk>(\\<Gamma>,(P0, s)#xs) \\<in> cptn_mod; zs=map (lift_catch P1) xs \\<rbrakk>\n                 \\<Longrightarrow> (\\<Gamma>,((Catch P0 P1), s)#zs) \\<in> cptn_mod\"\n| CptnModCatch2: \n  \"\\<lbrakk>(\\<Gamma>, (P0, s)#xs) \\<in> cptn_mod; fst(last ((P0, s)#xs)) = Skip; \n    (\\<Gamma>,(Skip,snd(last ((P0, s)#xs)))#ys) \\<in> cptn_mod;  \n    zs=(map (lift_catch P1) xs)@((Skip,snd(last ((P0, s)#xs)))#ys) \\<rbrakk> \\<Longrightarrow> \n   (\\<Gamma>,((Catch P0 P1), s)#zs) \\<in> cptn_mod\"\n\n| CptnModCatch3: \n  \"\\<lbrakk>(\\<Gamma>, (P0, Normal s)#xs) \\<in> cptn_mod; fst(last ((P0, Normal s)#xs)) = Throw; \n  snd(last ((P0, Normal s)#xs)) = Normal s';\n  (\\<Gamma>,(P1, snd(last ((P0, Normal s)#xs)))#ys) \\<in> cptn_mod; \n  zs=(map (lift_catch P1) xs)@((P1, snd(last ((P0, Normal s)#xs)))#ys) \\<rbrakk> \\<Longrightarrow> \n   (\\<Gamma>,((Catch P0 P1), Normal s)#zs) \\<in> cptn_mod\"\n\n\nlemmas CptnMod_induct = cptn_mod.induct [of _ \"[(c,s)]\", split_format (complete), case_names\nCptnModOne CptnModEnv CptnModSkip CptnModThrow CptnModCondT CptnModCondF \nCptnModSeq1 CptnModSeq2 CptnModSeq3 CptnModSeq4 CptnModWhile1 CptnModWhile2 CptnModWhile3 CptnModCall CptnModDynCom CptnModGuard \nCptnModCatch1 CptnModCatch2 CptnModCatch3, induct set]\n\ninductive_cases CptnMod_elim_cases [cases set]:\n\"(\\<Gamma>,(Skip, s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Guard f g c, s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Basic f e, s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Spec r e, s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Seq c1 c2, s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Cond b c1 c2, s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Await b c2 e, s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Call p, s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(DynCom c,s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Throw,s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Catch c1 c2,s)#u#xs) \\<in> cptn_mod\"\n\n\ninductive_cases CptnMod_Normal_elim_cases [cases set]:\n\"(\\<Gamma>,(Skip, Normal s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Guard f g c, Normal s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Basic f e, Normal s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Spec r e, Normal s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Seq c1 c2, Normal s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Cond b c1 c2, Normal s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Await b c2 e, Normal s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Call p, Normal s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(DynCom c,Normal s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Throw,Normal s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(Catch c1 c2,Normal s)#u#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(P,Normal s)#(P,s')#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(P,Abrupt s)#(P,Abrupt s')#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(P,Stuck)#(P,Stuck)#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(P,Fault f)#(P,Fault f)#xs) \\<in> cptn_mod\"\n\ninductive_cases CptnMod_env_elim_cases [cases set]:\n\"(\\<Gamma>,(P,Normal s)#(P,s')#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(P,Abrupt s)#(P,Abrupt s')#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(P,Stuck)#(P,Stuck)#xs) \\<in> cptn_mod\"\n\"(\\<Gamma>,(P,Fault f)#(P,Fault f)#xs) \\<in> cptn_mod\"\n\n\nsubsection \\<open>Equivalence of small semantics and computational\\<close>\n\nlemma last_length: \"((a#xs)!(length xs))=last (a#xs)\"\n  by (induct xs) auto\n\ndefinition catch_cond \nwhere\n\"catch_cond zs Q xs P s s'' s' \\<Gamma> \\<equiv> (zs=(map (lift_catch Q) xs) \\<or>\n             ((fst(((P, s)#xs)!length xs)=Throw \\<and>\n               snd(last ((P, s)#xs)) = Normal s' \\<and> s=Normal s''\\<and>\n               (\\<exists>ys. (\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod \\<and> \n                zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n                ((fst(((P, s)#xs)!length xs)=Skip \\<and> \n                 (\\<exists>ys. (\\<Gamma>,(Skip,snd(last ((P, s)#xs)))#ys) \\<in> cptn_mod \\<and>                   \n                 zs=(map (lift_catch Q) xs)@((Skip,snd(last ((P, s)#xs)))#ys)))))\n\"\n\nlemma div_catch: assumes cptn_m:\"(\\<Gamma>,list) \\<in> cptn_mod\"\nshows \"(\\<forall>s P Q zs. list=(Catch P Q, s)#zs \\<longrightarrow>\n       (\\<exists>xs s' s''. \n          (\\<Gamma>,(P, s)#xs) \\<in> cptn_mod  \\<and> \n             catch_cond zs Q xs P s s'' s' \\<Gamma>))  \n            \"\nunfolding catch_cond_def\nusing cptn_m\nproof (induct rule: cptn_mod.induct)\ncase (CptnModOne \\<Gamma> P s)\n  thus ?case using cptn_mod.CptnModOne by blast \nnext\n  case (CptnModSkip  \\<Gamma> P s t xs) \n  from CptnModSkip.hyps\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow> (Skip, t)\" by auto\n  from CptnModSkip.hyps\n  have noskip: \"~(P=Skip)\" using stepc_elim_cases(1) by blast  \n  have no_catch: \"\\<forall>p1 p2. \\<not>(P=Catch p1 p2)\" using CptnModSkip.hyps(2) redex_not_Catch by auto\n  from CptnModSkip.hyps\n  have in_cptn_mod: \"(\\<Gamma>, (Skip, t) # xs) \\<in> cptn_mod\" by auto  \n  then show ?case using no_catch by simp\nnext\n  case (CptnModThrow  \\<Gamma> P s t xs) \n  from CptnModThrow.hyps\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow> (Throw, t)\" by auto \n  from CptnModThrow.hyps\n  have in_cptn_mod: \"(\\<Gamma>, (Throw, t) # xs) \\<in> cptn_mod\" by auto \n  have no_catch: \"\\<forall>p1 p2. \\<not>(P=Catch p1 p2)\" using CptnModThrow.hyps(2) redex_not_Catch by auto\n  then show ?case by auto\nnext\n  case (CptnModCondT \\<Gamma> P0 s ys b P1)\n  thus ?case using CptnModOne by blast\nnext\n  case (CptnModCondF \\<Gamma> P0 s ys b P1)\n  thus ?case using CptnModOne by blast\nnext\n  case (CptnModCatch1 sa P Q zs)\n  thus ?case by blast\nnext\n  case (CptnModCatch2 \\<Gamma> P0 s xs ys zs P1) \n  from CptnModCatch2.hyps(3) \n  have last:\"fst (((P0, s) # xs) ! length xs) = Skip\" \n       by (simp add: last_length) \n  have P0cptn:\"(\\<Gamma>, (P0, s) # xs) \\<in> cptn_mod\" by fact          \n  then have \"zs = map (lift_catch P1) xs @((Skip,snd(last ((P0, s)#xs)))#ys)\" by (simp add:CptnModCatch2.hyps)\n  show ?case\n  proof -{\n    fix sa P Q zsa    \n    assume eq:\"(Catch P0 P1, s) # zs = (Catch P Q, sa) # zsa\"\n    then have \"P0 =P \\<and> P1 = Q \\<and> s=sa \\<and> zs=zsa\" by auto\n    then have \"(P0, s) = (P, sa)\" by auto \n    have \"last ((P0, s) # xs) = ((P, sa) # xs) ! length xs\"\n      by (simp add: `P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa` last_length)\n    then have \"zs = (map (lift_catch Q) xs)@((Skip,snd(last ((P0, s)#xs)))#ys)\"\n      using `P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa` `zs = map (lift_catch P1) xs @ ((Skip,snd(last ((P0, s)#xs)))#ys)` \n      by force    \n    then have \"(\\<exists>xs s' s''. ((\\<Gamma>,(P, s)#xs) \\<in> cptn_mod  \\<and> \n             ((zs=(map (lift_catch Q) xs) \\<or>\n             ((fst(((P, s)#xs)!length xs)=Throw \\<and>\n               snd(last ((P, s)#xs)) = Normal s' \\<and>  s=Normal s''\\<and>\n               (\\<exists>ys. (\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod \\<and> \n                zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n                (\\<exists>ys. ((fst(((P, s)#xs)!length xs)=Skip \\<and> (\\<Gamma>,(Skip,snd(last ((P, s)#xs)))#ys) \\<in> cptn_mod \\<and>                 \n                 zs=(map (lift_catch Q) xs)@((Skip,snd(last ((P0, s)#xs)))#ys))))))))\"\n    using P0cptn  `P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa`  last  CptnModCatch2.hyps(4) by blast \n   } \n   thus ?thesis by auto\n  qed\nnext\n  case (CptnModCatch3 \\<Gamma> P0 s xs s' P1 ys zs)\n  from CptnModCatch3.hyps(3)  \n  have last:\"fst (((P0, Normal s) # xs) ! length xs) = Throw\" \n       by (simp add: last_length) \n  from CptnModCatch3.hyps(4) \n  have lastnormal:\"snd (last ((P0, Normal s) # xs)) = Normal s'\"\n      by (simp add: last_length)\n  have P0cptn:\"(\\<Gamma>, (P0, Normal s) # xs) \\<in> cptn_mod\" by fact\n  from CptnModCatch3.hyps(5) have P1cptn:\"(\\<Gamma>, (P1, snd (((P0, Normal s) # xs) ! length xs)) # ys) \\<in> cptn_mod\"\n      by (simp add: last_length)          \n  then have \"zs = map (lift_catch P1) xs @ (P1, snd (last ((P0, Normal s) # xs))) # ys\" by (simp add:CptnModCatch3.hyps)\n  show ?case\n  proof -{\n    fix sa P Q zsa    \n    assume eq:\"(Catch P0 P1, Normal s) # zs = (Catch P Q, Normal sa) # zsa\"\n    then have \"P0 =P \\<and> P1 = Q \\<and> Normal s= Normal sa \\<and> zs=zsa\" by auto     \n    have \"last ((P0, Normal s) # xs) = ((P, Normal sa) # xs) ! length xs\"\n      by (simp add: `P0 = P \\<and> P1 = Q \\<and> Normal s = Normal sa \\<and> zs = zsa` last_length)\n    then have \"zsa = map (lift_catch Q) xs @ (Q, snd (((P, Normal sa) # xs) ! length xs)) # ys\"\n      using `P0 = P \\<and> P1 = Q \\<and> Normal s = Normal sa \\<and> zs = zsa` `zs = map (lift_catch P1) xs @ (P1, snd (last ((P0, Normal s) # xs))) # ys` by force\n    then have \"(\\<Gamma>, (P, Normal s) # xs) \\<in> cptn_mod \\<and> (fst(((P, Normal s)#xs)!length xs)=Throw \\<and>\n               snd(last ((P, Normal s)#xs)) = Normal s' \\<and> \n              (\\<exists>ys. (\\<Gamma>,(Q, snd(((P, Normal s)#xs)!length xs))#ys) \\<in> cptn_mod \\<and> \n              zs=(map (lift_catch Q) xs)@((Q, snd(((P, Normal s)#xs)!length xs))#ys)))\" \n      using lastnormal P1cptn P0cptn `P0 = P \\<and> P1 = Q \\<and> Normal s = Normal sa \\<and> zs = zsa` last \n       by auto    \n    }note this [of P0 P1 s zs] thus ?thesis by blast qed\nnext\n  case (CptnModEnv \\<Gamma> P s t xs)  \n  then have step:\"(\\<Gamma>, (P, t) # xs) \\<in> cptn_mod\" by auto  \n  have step_e: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow>\\<^sub>e (P, t)\" using CptnModEnv by auto\n  show ?case     \n    proof (cases P)\n      case (Catch P1 P2) \n      then have eq_P_Catch:\"(P, t) # xs = (LanguageCon.com.Catch P1 P2, t) # xs\" by auto      \n      then  obtain xsa t' t'' where \n         p1:\"(\\<Gamma>, (P1, t) # xsa) \\<in> cptn_mod\" and p2:\"\n     (xs = map (lift_catch P2) xsa \\<or>\n      fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \\<and>\n      snd (last ((P1, t) # xsa)) = Normal t' \\<and>\n      t = Normal t'' \\<and>\n      (\\<exists>ys. (\\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<in> cptn_mod \\<and>\n            xs =\n            map (lift_catch P2) xsa @\n            (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<or>\n            fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Skip \\<and>\n            (\\<exists>ys.(\\<Gamma>,(Skip,snd(last ((P1, t)#xsa)))#ys) \\<in> cptn_mod \\<and> \n            xs = map (lift_catch P2) xsa @\n            ((LanguageCon.com.Skip, snd (last ((P1, t) # xsa)))#ys)))\" \n        using CptnModEnv(3) by auto\n      have all_step:\"(\\<Gamma>, (P1, s)#((P1, t) # xsa)) \\<in> cptn_mod\"\n        by (metis p1 Env Env_n cptn_mod.CptnModEnv env_normal_s step_e)       \n      show ?thesis using p2 \n      proof  \n        assume \"xs = map (lift_catch P2) xsa\"\n        have \"(P, t) # xs = map (lift_catch P2) ((P1, t) # xsa)\"\n          by (simp add: `xs = map (lift_catch P2) xsa` lift_catch_def local.Catch)\n        thus ?thesis using all_step eq_P_Catch by fastforce\n      next \n        assume \n         \"fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \\<and>\n          snd (last ((P1, t) # xsa)) = Normal t' \\<and>\n          t = Normal t'' \\<and>\n          (\\<exists>ys. (\\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<in> cptn_mod \\<and>\n                xs =\n                map (lift_catch P2) xsa @\n                (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<or>\n                fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Skip \\<and>\n           (\\<exists>ys. (\\<Gamma>,(Skip,snd(last ((P1, t)#xsa)))#ys) \\<in> cptn_mod \\<and> \n            xs = map (lift_catch P2) xsa @\n            ((LanguageCon.com.Skip, snd (last ((P1, t) # xsa)))#ys))\"      \n         then show ?thesis \n         proof\n           assume \n            a1:\"fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \\<and>\n             snd (last ((P1, t) # xsa)) = Normal t' \\<and>\n             t = Normal t'' \\<and>\n             (\\<exists>ys. (\\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<in> cptn_mod \\<and>\n                xs = map (lift_catch P2) xsa @\n                       (P2, snd (((P1, t) # xsa) ! length xsa)) # ys)\"\n            then obtain ys where p2_exec:\"(\\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<in> cptn_mod \\<and>\n                xs = map (lift_catch P2) xsa @\n                       (P2, snd (((P1, t) # xsa) ! length xsa)) # ys\" \n            by fastforce\n            from a1 obtain t1 where t_normal: \"t=Normal t1\" \n              using env_normal_s'_normal_s by blast\n            have f1:\"fst (((P1, s)#(P1, t) # xsa) ! length ((P1, t)#xsa)) = LanguageCon.com.Throw\"\n              using a1 by fastforce\n             from a1 have last_normal: \"snd (last ((P1, s)#(P1, t) # xsa)) = Normal t'\"\n               by fastforce \n             then have p2_long_exec: \"(\\<Gamma>, (P2, snd (((P1, s)#(P1, t) # xsa) ! length ((P1, s)#xsa))) # ys) \\<in> cptn_mod \\<and>\n                (P, t)#xs = map (lift_catch P2) ((P1, t) # xsa) @\n                       (P2, snd (((P1, s)#(P1, t) # xsa) ! length ((P1, s)#xsa))) # ys\" using p2_exec \n                by (simp add: lift_catch_def local.Catch)                  \n             thus ?thesis using  a1 f1 last_normal all_step eq_P_Catch \n               by (clarify, metis (no_types) list.size(4) not_step_c_env  step_e)            \n           next\n           assume \n            as1:\"fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Skip \\<and>\n           (\\<exists>ys. (\\<Gamma>,(Skip,snd(last ((P1, t)#xsa)))#ys) \\<in> cptn_mod \\<and> \n            xs = map (lift_catch P2) xsa @\n            ((LanguageCon.com.Skip, snd (last ((P1, t) # xsa)))#ys))\"               \n            then obtain ys where p1:\"(\\<Gamma>,(Skip,snd(last ((P1, t)#xsa)))#ys) \\<in> cptn_mod \\<and> \n                         (P, t)#xs = map (lift_catch P2) ((P1, t) # xsa) @\n                          ((LanguageCon.com.Skip, snd (last ((P1, t) # xsa)))#ys)\"\n            proof -\n              assume a1: \"\\<And>ys. (\\<Gamma>, (LanguageCon.com.Skip, snd (last ((P1, t) # xsa))) # ys) \\<in> cptn_mod \\<and> (P, t) # xs = map (lift_catch P2) ((P1, t) # xsa) @ (LanguageCon.com.Skip, snd (last ((P1, t) # xsa))) # ys \\<Longrightarrow> thesis\"\n              have \"(LanguageCon.com.Catch P1 P2, t) # map (lift_catch P2) xsa = map (lift_catch P2) ((P1, t) # xsa)\"\n                by (simp add: lift_catch_def)\n              thus ?thesis\n                using a1 as1 eq_P_Catch by moura\n            qed            \n            from as1 have p2: \"fst (((P1, s)#(P1, t) # xsa) ! length ((P1, t) #xsa)) = LanguageCon.com.Skip\"\n                 by fastforce                              \n            thus ?thesis using p1 all_step eq_P_Catch by fastforce\n          qed\n      qed\n    qed (auto)\nqed(force+)\n\n\ndefinition seq_cond \nwhere\n\"seq_cond zs Q xs P s s'' s' \\<Gamma> \\<equiv> (zs=(map (lift Q) xs) \\<or>\n             ((fst(((P, s)#xs)!length xs)=Skip \\<and> \n               (\\<exists>ys. (\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod \\<and> \n                zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n             ((fst(((P, s)#xs)!length xs)=Throw \\<and> \n                 snd(last ((P, s)#xs)) = Normal s' \\<and>  s=Normal s''\\<and>\n                 (\\<exists>ys.  (\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod \\<and>\n                      zs=(map (lift Q) xs)@((Throw,Normal s')#ys)))))\n\"\n\nlemma div_seq: assumes cptn_m:\"(\\<Gamma>,list) \\<in> cptn_mod\"\nshows \"(\\<forall>s P Q zs. list=(Seq P Q, s)#zs \\<longrightarrow>\n       (\\<exists>xs s' s''. \n          (\\<Gamma>,(P, s)#xs) \\<in> cptn_mod  \\<and> \n             seq_cond zs Q xs P s s'' s' \\<Gamma>))  \n            \"\nunfolding seq_cond_def\nusing cptn_m\nproof (induct rule: cptn_mod.induct)\n  case (CptnModOne \\<Gamma> P s)\n  thus ?case using cptn_mod.CptnModOne by blast \nnext\n  case (CptnModSkip  \\<Gamma> P s t xs) \n  from CptnModSkip.hyps\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow> (Skip, t)\" by auto\n  from CptnModSkip.hyps\n  have noskip: \"~(P=Skip)\" using stepc_elim_cases(1) by blast  \n  have x: \"\\<forall>c c1 c2. redex c = Seq c1 c2 \\<Longrightarrow> False\"\n          using redex_not_Seq by blast\n  from CptnModSkip.hyps\n  have in_cptn_mod: \"(\\<Gamma>, (Skip, t) # xs) \\<in> cptn_mod\" by auto  \n  then show ?case using CptnModSkip.hyps(2) SmallStepCon.redex_not_Seq by blast\nnext\n  case (CptnModThrow  \\<Gamma> P s t xs)\n  from CptnModThrow.hyps\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow> (Throw, t)\" by auto \n  moreover from CptnModThrow.hyps\n  have in_cptn_mod: \"(\\<Gamma>, (Throw, t) # xs) \\<in> cptn_mod\" by auto \n  have no_seq: \"\\<forall>p1 p2. \\<not>(P=Seq p1 p2)\" using CptnModThrow.hyps(2) redex_not_Seq by auto\n  ultimately show ?case by auto   \nnext \n  case (CptnModCondT \\<Gamma> P0 s ys b P1)\n  thus ?case by auto\nnext\n  case (CptnModCondF \\<Gamma> P0 s ys b P1)\n  thus ?case by auto\nnext\n  case (CptnModSeq1 \\<Gamma> P0 s xs zs P1)\n  thus ?case by blast\nnext \n  case (CptnModSeq2 \\<Gamma> P0 s xs P1 ys zs) \n  from CptnModSeq2.hyps(3) last_length have last:\"fst (((P0, s) # xs) ! length xs) = Skip\" \n       by (simp add: last_length) \n  have P0cptn:\"(\\<Gamma>, (P0, s) # xs) \\<in> cptn_mod\" by fact\n  from CptnModSeq2.hyps(4) have P1cptn:\"(\\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod\"\n      by (simp add: last_length)          \n  then have \"zs = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys\" by (simp add:CptnModSeq2.hyps)\n  show ?case\n  proof -{\n    fix sa P Q zsa    \n    assume eq:\"(Seq P0 P1, s) # zs = (Seq P Q, sa) # zsa\"\n    then have \"P0 =P \\<and> P1 = Q \\<and> s=sa \\<and> zs=zsa\" by auto \n     have \"last ((P0, s) # xs) = ((P, sa) # xs) ! length xs\"\n            by (simp add: `P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa` last_length)\n    then have \"zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys\"\n         using `P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa` `zs = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys` \n         by force    \n    then have \"(\\<exists>xs s' s''. (\\<Gamma>, (P, sa) # xs) \\<in> cptn_mod \\<and>\n                        (zsa = map (lift Q) xs \\<or>              \n                         fst (((P, sa) # xs) ! length xs) = Skip \\<and>\n                             (\\<exists>ys. (\\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<in> cptn_mod \\<and>\n                             zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<or>\n                        ((fst(((P, sa)#xs)!length xs)=Throw \\<and> \n                          snd(last ((P, sa)#xs)) = Normal s' \\<and>  s=Normal s''\\<and>\n                         (\\<exists>ys. (\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod \\<and>\n                               zsa=(map (lift Q) xs)@((Throw,Normal s')#ys))))))\n               \" \n        using P0cptn P1cptn  `P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa` last \n        by blast                 \n   }  \n   thus ?case by auto qed     \nnext\n  case (CptnModSeq3 \\<Gamma> P0 s xs s' ys zs P1) \n  from CptnModSeq3.hyps(3) \n  have last:\"fst (((P0, Normal s) # xs) ! length xs) = Throw\" \n       by (simp add: last_length) \n  have P0cptn:\"(\\<Gamma>, (P0, Normal s) # xs) \\<in> cptn_mod\" by fact\n  from CptnModSeq3.hyps(4) \n  have lastnormal:\"snd (last ((P0, Normal s) # xs)) = Normal s'\"\n      by (simp add: last_length)          \n  then have \"zs = map (lift P1) xs @ ((Throw, Normal s')#ys)\" by (simp add:CptnModSeq3.hyps)\n  show ?case\n  proof -{\n    fix sa P Q zsa    \n    assume eq:\"(Seq P0 P1, Normal s) # zs = (Seq P Q, Normal sa) # zsa\"\n    then have \"P0 =P \\<and> P1 = Q \\<and> Normal s=Normal sa \\<and> zs=zsa\" by auto\n    then have \"(P0, Normal s) = (P, Normal sa)\" by auto \n    have \"last ((P0, Normal s) # xs) = ((P, Normal sa) # xs) ! length xs\"\n                    by (simp add: `P0 = P \\<and> P1 = Q \\<and> Normal s = Normal sa \\<and> zs = zsa` last_length)\n    then have zsa:\"zsa = (map (lift Q) xs)@((Throw,Normal s')#ys)\"\n                    using `P0 = P \\<and> P1 = Q \\<and> Normal s = Normal sa \\<and> zs = zsa` `zs = map (lift P1) xs @ ((Throw, Normal s')#ys)` \n    by force\n    then have a1:\"(\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod\" using CptnModSeq3.hyps(5) by blast               \n     have \"(P, Normal sa::('b, 'c) xstate) = (P0, Normal s)\"\n    using `P0 = P \\<and> P1 = Q \\<and> Normal s = Normal sa \\<and> zs = zsa` by auto  \n    then have \"(\\<exists>xs s'. (\\<Gamma>, (P, Normal sa) # xs) \\<in> cptn_mod \\<and>\n                        (zsa = map (lift Q) xs \\<or>              \n                         fst (((P,Normal sa) # xs) ! length xs) = Skip \\<and>\n                             (\\<exists>ys. (\\<Gamma>, (Q, snd (((P, Normal sa) # xs) ! length xs)) # ys) \\<in> cptn_mod \\<and>\n                             zsa = map (lift Q) xs @ (Q, snd (((P, Normal sa) # xs) ! length xs)) # ys) \\<or>\n                        ((fst(((P, Normal sa)#xs)!length xs)=Throw \\<and> \n                          snd(last ((P, Normal sa)#xs)) = Normal s' \\<and>\n                          (\\<exists>ys. (\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod \\<and>\n                          zsa=(map (lift Q) xs)@((Throw,Normal s')#ys))))))\"\n     using P0cptn zsa a1 last lastnormal \n       by blast \n   }  \n   thus ?thesis by auto qed  \nnext \n  case (CptnModEnv \\<Gamma> P s t zs) \n  then have step:\"(\\<Gamma>, (P, t) # zs) \\<in> cptn_mod\" by auto\n  have step_e: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow>\\<^sub>e (P, t)\" using CptnModEnv by auto  \n  show ?case     \n    proof (cases P)\n      case (Seq P1 P2) \n      then have eq_P:\"(P, t) # zs = (LanguageCon.com.Seq P1 P2, t) # zs\" by auto      \n      then  obtain xs t' t'' where \n         p1:\"(\\<Gamma>, (P1, t) # xs) \\<in> cptn_mod\" and p2:\"\n     (zs = map (lift P2) xs \\<or>\n      fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \\<and>      \n      (\\<exists>ys. (\\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<in> cptn_mod \\<and>\n            zs =\n            map (lift P2) xs @\n            (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<or>\n      fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n      snd (last ((P1, t) # xs)) = Normal t' \\<and>\n      t = Normal t'' \\<and> (\\<exists>ys. (\\<Gamma>,(Throw,Normal t')#ys) \\<in> cptn_mod \\<and> \n      zs =\n      map (lift P2) xs @\n      ((LanguageCon.com.Throw, Normal t')#ys))) \" \n        using CptnModEnv(3) by auto\n      have all_step:\"(\\<Gamma>, (P1, s)#((P1, t) # xs)) \\<in> cptn_mod\"\n       by (metis p1 Env Env_n cptn_mod.CptnModEnv env_normal_s step_e)         \n      show ?thesis using p2 \n      proof  \n        assume \"zs = map (lift P2) xs\"\n        have \"(P, t) # zs = map (lift P2) ((P1, t) # xs)\"\n          by (simp add: `zs = map (lift P2) xs` lift_def local.Seq)\n        thus ?thesis using all_step eq_P by fastforce\n      next \n        assume \n         \"fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \\<and>      \n         (\\<exists>ys. (\\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<in> cptn_mod \\<and>\n            zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<or>\n          fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n           snd (last ((P1, t) # xs)) = Normal t' \\<and>\n           t = Normal t'' \\<and> (\\<exists>ys. (\\<Gamma>,(Throw,Normal t')#ys) \\<in> cptn_mod \\<and> \n           zs = map (lift P2) xs @ ((LanguageCon.com.Throw, Normal t')#ys))\"\n         then show ?thesis \n         proof\n           assume \n            a1:\"fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \\<and>      \n               (\\<exists>ys. (\\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<in> cptn_mod \\<and>\n               zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys)\"\n               from a1 obtain ys where \n                   p2_exec:\"(\\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<in> cptn_mod \\<and>\n                       zs = map (lift P2) xs @\n                       (P2, snd (((P1, t) # xs) ! length xs)) # ys\" \n                by auto \n               have f1:\"fst (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs)) = LanguageCon.com.Skip\"\n                 using a1 by fastforce             \n               then have p2_long_exec: \n                 \"(\\<Gamma>, (P2, snd (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs))) # ys) \\<in> cptn_mod \\<and>\n                  (P, t)#zs = map (lift P2) ((P1, t) # xs) @\n                       (P2, snd (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs))) # ys\" \n             using p2_exec by (simp add: lift_def local.Seq)     \n             thus ?thesis using a1 f1 all_step eq_P by blast            \n           next\n           assume \n            a1:\"fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n            snd (last ((P1, t) # xs)) = Normal t' \\<and> t = Normal t'' \\<and> \n          (\\<exists>ys. (\\<Gamma>,(Throw,Normal t')#ys) \\<in> cptn_mod \\<and> \n           zs = map (lift P2) xs @ ((LanguageCon.com.Throw, Normal t')#ys))\"             \n             then have last_throw:\n               \"fst (((P1, s)#(P1, t) # xs) ! length ((P1, t) #xs)) = LanguageCon.com.Throw\" \n               by fastforce\n             from a1 have last_normal: \"snd (last ((P1, s)#(P1, t) # xs)) = Normal t'\"\n               by fastforce\n             have seq_lift:\n               \"(LanguageCon.com.Seq P1 P2, t) # map (lift P2) xs = map (lift P2) ((P1, t) # xs)\"\n                by (simp add: a1 lift_def)             \n            thus  ?thesis using a1 last_throw last_normal all_step eq_P         \n              by (clarify, metis (no_types, lifting) append_Cons env_normal_s'_normal_s  step_e)                 \n          qed\n      qed\n    qed (auto) \nqed (force)+\n\n\nlemma cptn_onlyif_cptn_mod_aux:\nassumes stepseq:\"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow> (Q,t)\" and\n        stepmod:\"(\\<Gamma>,(Q,t)#xs) \\<in> cptn_mod\"\nshows \"(\\<Gamma>,(P,s)#(Q,t)#xs) \\<in> cptn_mod\"\nusing stepseq stepmod\nproof (induct arbitrary: xs)\n  case (Basicc f s) \n  thus ?case by (simp add: cptn_mod.CptnModSkip stepc.Basicc)\nnext\n  case (Specc s t r)\n  thus ?case by (simp add: cptn_mod.CptnModSkip stepc.Specc) \nnext\n  case (SpecStuckc s r)\n  thus ?case by (simp add: cptn_mod.CptnModSkip stepc.SpecStuckc)\nnext\n  case (Guardc s g f c)\n  thus ?case by (simp add: cptn_mod.CptnModGuard) \nnext\n  case (GuardFaultc)\n  thus ?case by (simp add: cptn_mod.CptnModSkip stepc.GuardFaultc)\nnext\n  case (Seqc c1 s c1' s' c2)\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c1, s) \\<rightarrow> (c1', s')\" by (simp add: Seqc.hyps(1))\n  then have nsc1: \"c1\\<noteq>Skip\" using stepc_elim_cases(1) by blast \n  have assum: \"(\\<Gamma>, (Seq c1' c2, s') # xs) \\<in> cptn_mod\" using Seqc.prems by blast\n  have divseq:\"(\\<forall>s P Q zs. (Seq c1' c2, s') # xs=(Seq P Q, s)#zs \\<longrightarrow>\n                (\\<exists>xs sv' sv''. ((\\<Gamma>,(P, s)#xs) \\<in> cptn_mod  \\<and> \n                           (zs=(map (lift Q) xs) \\<or>\n                           ((fst(((P, s)#xs)!length xs)=Skip \\<and> \n                             (\\<exists>ys. (\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod \\<and> \n                              zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n                           ((fst(((P, s)#xs)!length xs)=Throw \\<and> \n                               snd(last ((P, s)#xs)) = Normal sv' \\<and>  s'=Normal sv''\\<and>\n                             (\\<exists>ys.  (\\<Gamma>,(Throw,Normal sv')#ys) \\<in> cptn_mod \\<and>\n                              zs=(map (lift Q) xs)@((Throw,Normal sv')#ys))\n                               ))))\n                            \n                 ))\"  using div_seq [OF assum] unfolding seq_cond_def by auto\n   {fix sa P Q zsa\n       assume ass:\"(Seq c1' c2, s') # xs = (Seq P Q, sa) # zsa\"\n       then have eqs:\"c1' = P \\<and> c2 = Q \\<and> s' = sa \\<and> xs = zsa\" by auto\n       then have \"(\\<exists>xs sv' sv''. (\\<Gamma>, (P, sa) # xs) \\<in> cptn_mod \\<and>\n                        (zsa = map (lift Q) xs \\<or>              \n                         fst (((P, sa) # xs) ! length xs) = Skip \\<and>\n                             (\\<exists>ys. (\\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<in> cptn_mod \\<and>\n                             zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<or>\n                        ((fst(((P, sa)#xs)!length xs)=Throw \\<and> \n                          snd(last ((P, sa)#xs)) = Normal sv' \\<and>  s'=Normal sv''\\<and>\n                          (\\<exists>ys.  (\\<Gamma>,(Throw,Normal sv')#ys) \\<in> cptn_mod \\<and>\n                              zsa=(map (lift Q) xs)@((Throw,Normal sv')#ys))))))\" \n             using ass divseq by blast\n    } note conc=this [of c1' c2 s' xs]    \n     then obtain xs' sa' sa''\n       where  split:\"(\\<Gamma>, (c1', s') # xs') \\<in> cptn_mod \\<and>\n                     (xs = map (lift c2) xs' \\<or>                   \n                     fst (((c1', s') # xs') ! length xs') = Skip \\<and>\n                        (\\<exists>ys. (\\<Gamma>, (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n                         xs = map (lift c2) xs' @ (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<or>\n                     ((fst(((c1', s')#xs')!length xs')=Throw \\<and> \n                         snd(last ((c1', s')#xs')) = Normal sa' \\<and> s'=Normal sa''\\<and>\n                         (\\<exists>ys.  (\\<Gamma>,(Throw,Normal sa')#ys) \\<in> cptn_mod \\<and>\n                              xs=(map (lift c2) xs')@((Throw,Normal sa')#ys))\n                         )))\"  by blast\n  then have \"(xs = map (lift c2) xs' \\<or>                   \n                     fst (((c1', s') # xs') ! length xs') = Skip \\<and>\n                        (\\<exists>ys. (\\<Gamma>, (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n                         xs = map (lift c2) xs' @ (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<or>\n                     ((fst(((c1', s')#xs')!length xs')=Throw \\<and> \n                         snd(last ((c1', s')#xs')) = Normal sa' \\<and> s'=Normal sa''\\<and>\n                         (\\<exists>ys.  (\\<Gamma>,(Throw,Normal sa')#ys) \\<in> cptn_mod \\<and>\n                              xs=(map (lift c2) xs')@((Throw,Normal sa')#ys)))))\" by auto\n  thus ?case \n  proof{           \n       assume c1'nonf:\"xs = map (lift c2) xs'\"\n       then have c1'cptn:\"(\\<Gamma>, (c1', s') # xs') \\<in> cptn_mod\" using split by blast\n       then have induct_step: \"(\\<Gamma>, (c1, s) # (c1', s')#xs') \\<in> cptn_mod\"\n         using Seqc.hyps(2)  by blast\n       then have \"(Seq c1' c2, s')#xs = map (lift c2) ((c1', s')#xs')\"\n            using c1'nonf\n            by (simp add: CptnModSeq1 lift_def)\n       thus ?thesis \n            using c1'nonf c1'cptn induct_step by (auto simp add: CptnModSeq1)\n    next\n      assume \"fst (((c1', s') # xs') ! length xs') = Skip \\<and>\n              (\\<exists>ys. (\\<Gamma>, (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n                  xs = map (lift c2) xs' @ (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<or>\n             ((fst(((c1', s')#xs')!length xs')=Throw \\<and> \n                snd(last ((c1', s')#xs')) = Normal sa' \\<and>  s'=Normal sa''\\<and>\n                (\\<exists>ys.  (\\<Gamma>,(Throw,Normal sa')#ys) \\<in> cptn_mod \\<and>\n                              xs=(map (lift c2) xs')@((Throw,Normal sa')#ys))))\"  \n      thus ?thesis\n      proof\n         assume assth:\"fst (((c1', s') # xs') ! length xs') = Skip \\<and>\n              (\\<exists>ys. (\\<Gamma>, (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n                  xs = map (lift c2) xs' @ (c2, snd (((c1', s') # xs') ! length xs')) # ys)\"\n         then obtain ys \n             where split':\"(\\<Gamma>, (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n                  xs = map (lift c2) xs' @ (c2, snd (((c1', s') # xs') ! length xs')) # ys\"\n             by auto    \n         then have c1'cptn:\"(\\<Gamma>, (c1', s') # xs') \\<in> cptn_mod\" using split by blast\n         then have induct_step: \"(\\<Gamma>, (c1, s) # (c1', s')#xs') \\<in> cptn_mod\"\n         using Seqc.hyps(2)  by blast                \n         then have seqmap:\"(Seq c1 c2, s)#(Seq c1' c2, s')#xs = map (lift c2) ((c1,s)#(c1', s')#xs') @ (c2, snd (((c1', s') # xs') ! length xs')) # ys\"\n        using split'   \n         by (simp add: CptnModSeq2 lift_def) \n        then have lastc1:\"last ((c1, s) # (c1', s') # xs') = ((c1', s') # xs') ! length xs'\"\n          by (simp add: last_length) \n        then have lastc1skip:\"fst (last ((c1, s) # (c1', s') # xs')) = Skip\" \n          using assth by fastforce          \n        thus ?thesis \n           using seqmap split' last_length cptn_mod.CptnModSeq2 \n                 induct_step lastc1 lastc1skip \n           by fastforce\n    next\n        assume assm:\"((fst(((c1', s')#xs')!length xs')=Throw \\<and> \n                snd(last ((c1', s')#xs')) = Normal sa' \\<and>  s'=Normal sa''\\<and>\n                (\\<exists>ys.  (\\<Gamma>,(Throw,Normal sa')#ys) \\<in> cptn_mod \\<and>\n                 xs=(map (lift c2) xs')@((Throw,Normal sa')#ys))))\"\n        then have s'eqsa'': \"s'=Normal sa''\" by auto\n        then have snormal: \"\\<exists>ns. s=Normal ns\" by (metis Seqc.hyps(1) step_Abrupt_prop step_Fault_prop step_Stuck_prop xstate.exhaust)\n        then have c1'cptn:\"(\\<Gamma>, (c1', s') # xs') \\<in> cptn_mod\" using split by blast        \n        then have induct_step: \"(\\<Gamma>, (c1, s) # (c1', s')#xs') \\<in> cptn_mod\"\n        using Seqc.hyps(2)  by blast \n        then obtain ys where seqmap:\"(Seq c1' c2, s')#xs = (map (lift c2) ((c1', s')#xs'))@((Throw,Normal sa')#ys)\"\n        using assm\n        proof -\n          assume a1: \"\\<And>ys. (LanguageCon.com.Seq c1' c2, s') # xs = map (lift c2) ((c1', s') # xs') @ (LanguageCon.com.Throw, Normal sa') # ys \\<Longrightarrow> thesis\"\n          have \"(LanguageCon.com.Seq c1' c2, Normal sa'') # map (lift c2) xs' = map (lift c2) ((c1', s') # xs')\"\n            by (simp add: assm lift_def)\n          thus ?thesis\n            using a1 assm by moura\n        qed  \n        then have lastc1:\"last ((c1, s) # (c1', s') # xs') = ((c1', s') # xs') ! length xs'\"\n                   by (simp add: last_length) \n        then have lastc1skip:\"fst (last ((c1, s) # (c1', s') # xs')) = Throw\" \n             using assm by fastforce\n        then have \"snd (last ((c1, s) # (c1', s') # xs')) = Normal sa'\"\n             using assm by force        \n        thus ?thesis\n            using assm c1'cptn induct_step lastc1skip snormal seqmap s'eqsa'' \n            by (auto simp add:cptn_mod.CptnModSeq3)\n   qed\n  }qed    \n          \nnext\n  case (SeqSkipc c2 s xs)\n  have c2incptn:\"(\\<Gamma>, (c2, s) # xs) \\<in> cptn_mod\" by fact\n  then have 1:\"(\\<Gamma>, [(Skip, s)]) \\<in> cptn_mod\" by (simp add: cptn_mod.CptnModOne)\n  then have 2:\"fst(last ([(Skip, s)])) = Skip\" by fastforce\n  then have 3:\"(\\<Gamma>,(c2, snd(last [(Skip, s)]))#xs) \\<in> cptn_mod\" \n      using c2incptn by auto  \n  then have \"(c2,s)#xs=(map (lift c2) [])@(c2, snd(last [(Skip, s)]))#xs\" \n       by (auto simp add:lift_def)\n  thus ?case using 1 2 3 by (simp add: CptnModSeq2)\nnext\n  case (SeqThrowc c2 s xs)  \n  have \"(\\<Gamma>, [(Throw, Normal s)]) \\<in> cptn_mod\" by (simp add: cptn_mod.CptnModOne) \n  then obtain ys where ys_nil:\"ys=[]\" and last:\"(\\<Gamma>, (Throw, Normal s)#ys)\\<in> cptn_mod\"\n   by auto\n  moreover have \"fst (last ((Throw, Normal s)#ys)) = Throw\" using ys_nil last by auto\n  moreover have \"snd (last ((Throw, Normal s)#ys)) = Normal s\" using ys_nil last by auto\n  moreover from ys_nil have \"(map (lift c2) ys) = []\" by auto  \n  ultimately show ?case using SeqThrowc.prems cptn_mod.CptnModSeq3 by fastforce  \nnext\n  case (CondTruec s b c1 c2)\n  thus ?case by (simp add: cptn_mod.CptnModCondT)\nnext\n  case (CondFalsec s b c1 c2)\n  thus ?case by (simp add: cptn_mod.CptnModCondF)\nnext\n case (WhileTruec s1 b c)\n have sinb: \"s1\\<in>b\" by fact\n have SeqcWhile: \"(\\<Gamma>, (Seq c (While b c), Normal s1) # xs) \\<in> cptn_mod\" by fact  \n have divseq:\"(\\<forall>s P Q zs. (Seq c (While b c), Normal s1) # xs=(Seq P Q, s)#zs \\<longrightarrow>\n                (\\<exists>xs s'. ((\\<Gamma>,(P, s)#xs) \\<in> cptn_mod  \\<and> \n                           (zs=(map (lift Q) xs) \\<or>\n                           ((fst(((P, s)#xs)!length xs)=Skip \\<and> \n                             (\\<exists>ys. (\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod \\<and> \n                              zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n                           ((fst(((P, s)#xs)!length xs)=Throw \\<and> \n                               snd(last ((P, s)#xs)) = Normal s' \\<and>\n                              (\\<exists>ys.  (\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod \\<and>\n                      zs=(map (lift Q) xs)@((Throw,Normal s')#ys))))))                            \n                 ))\" using div_seq [OF SeqcWhile] by (auto simp add: seq_cond_def)\n{fix sa P Q zsa\n       assume ass:\"(Seq c (While b c), Normal s1) # xs = (Seq P Q, sa) # zsa\"\n       then have eqs:\"c = P \\<and> (While b c) = Q \\<and> Normal s1 = sa \\<and> xs = zsa\" by auto\n       then have \"(\\<exists>xs s'. (\\<Gamma>, (P, sa) # xs) \\<in> cptn_mod \\<and>\n                        (zsa = map (lift Q) xs \\<or>              \n                         fst (((P, sa) # xs) ! length xs) = Skip \\<and>\n                             (\\<exists>ys. (\\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<in> cptn_mod \\<and>\n                             zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<or>\n                        ((fst(((P, sa)#xs)!length xs)=Throw \\<and> \n                          snd(last ((P, sa)#xs)) = Normal s' \\<and>\n                          (\\<exists>ys.  (\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod \\<and>\n                      zsa=(map (lift Q) xs)@((Throw,Normal s')#ys))\n                        ))))\" \n             using ass divseq by auto\n    } note conc=this [of c \"While b c\" \"Normal s1\" xs] \n   then obtain xs' s' \n        where  split:\"(\\<Gamma>, (c, Normal s1) # xs') \\<in> cptn_mod \\<and>\n     (xs = map (lift (While b c)) xs' \\<or>\n      fst (((c, Normal s1) # xs') ! length xs') = Skip \\<and>\n      (\\<exists>ys. (\\<Gamma>, (While b c, snd (((c, Normal s1) # xs') ! length xs')) # ys)\n            \\<in> cptn_mod \\<and>\n            xs =\n            map (lift (While b c)) xs' @\n            (While b c, snd (((c, Normal s1) # xs') ! length xs')) # ys) \\<or>\n      fst (((c, Normal s1) # xs') ! length xs') = Throw \\<and>\n      snd (last ((c, Normal s1) # xs')) = Normal s' \\<and> \n      (\\<exists>ys.  (\\<Gamma>, ((Throw, Normal s')#ys)) \\<in> cptn_mod \\<and>\n      xs = map (lift (While b c)) xs' @ ((Throw, Normal s')#ys)))\"  by auto\n then have \"(xs = map (lift (While b c)) xs' \\<or>\n            fst (((c, Normal s1) # xs') ! length xs') = Skip \\<and>\n            (\\<exists>ys. (\\<Gamma>, (While b c, snd (((c, Normal s1) # xs') ! length xs')) # ys)\n                  \\<in> cptn_mod \\<and>\n                  xs =\n                  map (lift (While b c)) xs' @\n                  (While b c, snd (((c, Normal s1) # xs') ! length xs')) # ys) \\<or>\n            fst (((c, Normal s1) # xs') ! length xs') = Throw \\<and>\n            snd (last ((c, Normal s1) # xs')) = Normal s' \\<and>\n            (\\<exists>ys.  (\\<Gamma>, ((Throw, Normal s')#ys)) \\<in> cptn_mod \\<and>\n          xs = map (lift (While b c)) xs' @ ((Throw, Normal s')#ys)))\" ..\n thus ?case\n proof{ \n   assume 1:\"xs = map (lift (While b c)) xs'\"  \n   have 3:\"(\\<Gamma>, (c, Normal s1) # xs') \\<in> cptn_mod\" using split by auto   \n   then show ?thesis using \"1\" cptn_mod.CptnModWhile1 sinb by fastforce \n next\n   assume \"fst (((c, Normal s1) # xs') ! length xs') = Skip \\<and>\n          (\\<exists>ys. (\\<Gamma>, (While b c, snd (((c, Normal s1) # xs') ! length xs')) # ys)\n                \\<in> cptn_mod \\<and>\n                xs =\n                map (lift (While b c)) xs' @\n                (While b c, snd (((c, Normal s1) # xs') ! length xs')) # ys) \\<or>\n          fst (((c, Normal s1) # xs') ! length xs') = Throw \\<and>\n          snd (last ((c, Normal s1) # xs')) = Normal s' \\<and>\n          (\\<exists>ys.  (\\<Gamma>, ((Throw, Normal s')#ys)) \\<in> cptn_mod \\<and>\n          xs = map (lift (While b c)) xs' @ ((Throw, Normal s')#ys))\"\n   thus ?case\n   proof\n     assume asm:\"fst (((c, Normal s1) # xs') ! length xs') = Skip \\<and>\n             (\\<exists>ys. (\\<Gamma>, (While b c, snd (((c, Normal s1) # xs') ! length xs')) # ys)\n             \\<in> cptn_mod \\<and>\n             xs =\n             map (lift (While b c)) xs' @\n             (While b c, snd (((c, Normal s1) # xs') ! length xs')) # ys)\"\n     then obtain ys \n       where asm':\"(\\<Gamma>, (While b c, snd (last ((c, Normal s1) # xs'))) # ys)\n                   \\<in> cptn_mod \n                   \\<and> xs = map (lift (While b c)) xs' @\n                       (While b c, snd (last ((c, Normal s1) # xs'))) # ys\" \n              by (auto simp add: last_length)\n     moreover have 3:\"(\\<Gamma>, (c, Normal s1) # xs') \\<in> cptn_mod\" using split by auto\n     moreover from asm have \"fst (last ((c, Normal s1) # xs'))  = Skip\"\n          by (simp add: last_length) \n     ultimately show ?case using sinb by (auto simp add:CptnModWhile2)\n   next\n    assume asm:\" fst (((c, Normal s1) # xs') ! length xs') = Throw \\<and>\n          snd (last ((c, Normal s1) # xs')) = Normal s' \\<and>\n          (\\<exists>ys.  (\\<Gamma>, ((Throw, Normal s')#ys)) \\<in> cptn_mod \\<and>\n          xs = map (lift (While b c)) xs' @ ((Throw, Normal s')#ys))\"   \n     moreover have 3:\"(\\<Gamma>, (c, Normal s1) # xs') \\<in> cptn_mod\" using split by auto\n     moreover from asm have \"fst (last ((c, Normal s1) # xs'))  = Throw\"\n          by (simp add: last_length) \n     ultimately show ?case using sinb by (auto simp add:CptnModWhile3)\n   qed\n }qed  \nnext\n case (WhileFalsec s b c)\n thus ?case by (simp add: cptn_mod.CptnModSkip stepc.WhileFalsec)\nnext\n  case (Awaitc s b c t)\n  thus ?case by (simp add: cptn_mod.CptnModSkip stepc.Awaitc)\nnext\n  case (AwaitAbruptc s b c t t')\n  thus ?case by (simp add: cptn_mod.CptnModThrow stepc.AwaitAbruptc) \nnext\n  case (Callc p bdy s)\n  thus ?case by (simp add: cptn_mod.CptnModCall) \nnext\n  case (CallUndefinedc p s)\n  thus ?case by (simp add: cptn_mod.CptnModSkip stepc.CallUndefinedc)\nnext\n  case (DynComc c s)\n  thus ?case by (simp add: cptn_mod.CptnModDynCom) \nnext\n  case (Catchc c1 s c1' s' c2)\n   have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c1, s) \\<rightarrow> (c1', s')\" by (simp add: Catchc.hyps(1))\n  then have nsc1: \"c1\\<noteq>Skip\" using stepc_elim_cases(1) by blast \n  have assum: \"(\\<Gamma>, (Catch c1' c2, s') # xs) \\<in> cptn_mod\" \n  using Catchc.prems by blast\n  have divcatch:\"(\\<forall>s P Q zs. (Catch c1' c2, s') # xs=(Catch P Q, s)#zs \\<longrightarrow>\n  (\\<exists>xs s' s''. ((\\<Gamma>,(P, s)#xs) \\<in> cptn_mod  \\<and> \n             (zs=(map (lift_catch Q) xs) \\<or>\n             ((fst(((P, s)#xs)!length xs)=Throw \\<and>\n               snd(last ((P, s)#xs)) = Normal s' \\<and>  s=Normal s''\\<and>\n               (\\<exists>ys. (\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod \\<and> \n                zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n                ((fst(((P, s)#xs)!length xs)=Skip \\<and>  \n                  (\\<exists>ys. (\\<Gamma>,(Skip,snd(last ((P, s)#xs)))#ys) \\<in> cptn_mod \\<and>                   \n                 zs=(map (lift_catch Q) xs)@((Skip,snd(last ((P, s)#xs)))#ys))                \n                 ))))\n   ))\" using div_catch [OF assum] by (auto simp add: catch_cond_def)\n   {fix sa P Q zsa\n       assume ass:\"(Catch c1' c2, s') # xs = (Catch P Q, sa) # zsa\"\n       then have eqs:\"c1' = P \\<and> c2 = Q \\<and> s' = sa \\<and> xs = zsa\" by auto\n       then have \"(\\<exists>xs sv' sv''. ((\\<Gamma>,(P, sa)#xs) \\<in> cptn_mod  \\<and> \n             (zsa=(map (lift_catch Q) xs) \\<or>\n             ((fst(((P, sa)#xs)!length xs)=Throw \\<and>\n               snd(last ((P, sa)#xs)) = Normal sv' \\<and>  s'=Normal sv''\\<and>\n               (\\<exists>ys. (\\<Gamma>,(Q, snd(((P, sa)#xs)!length xs))#ys) \\<in> cptn_mod \\<and> \n                zsa=(map (lift_catch Q) xs)@((Q, snd(((P, sa)#xs)!length xs))#ys)))) \\<or>\n                ((fst(((P, sa)#xs)!length xs)=Skip \\<and>                  \n                 (\\<exists>ys. (\\<Gamma>,(Skip,snd(last ((P, sa)#xs)))#ys) \\<in> cptn_mod \\<and>                   \n                 zsa=(map (lift_catch Q) xs)@((Skip,snd(last ((P, sa)#xs)))#ys))))))\n   )\"   using ass divcatch by blast\n    } note conc=this [of c1' c2 s' xs]    \n     then obtain xs' sa' sa''\n       where split:\n         \"(\\<Gamma>, (c1', s') # xs') \\<in> cptn_mod \\<and> \n          (xs = map (lift_catch c2) xs' \\<or>\n          fst (((c1', s') # xs') ! length xs') = Throw \\<and>\n          snd (last ((c1', s') # xs')) = Normal sa' \\<and> s' = Normal sa'' \\<and>\n          (\\<exists>ys. (\\<Gamma>, (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n                xs = map (lift_catch c2) xs' @\n                (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<or>\n          fst (((c1', s') # xs') ! length xs') = Skip \\<and>\n          (\\<exists>ys. (\\<Gamma>,(Skip,snd(last ((c1', s')#xs')))#ys) \\<in> cptn_mod \\<and>                   \n                 xs=(map (lift_catch c2) xs')@((Skip,snd(last ((c1', s')#xs')))#ys)))\"          \n        by blast\n  then have \"(xs = map (lift_catch c2) xs' \\<or>\n          fst (((c1', s') # xs') ! length xs') = Throw \\<and>\n          snd (last ((c1', s') # xs')) = Normal sa' \\<and> s' = Normal sa'' \\<and>\n          (\\<exists>ys. (\\<Gamma>, (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n                xs = map (lift_catch c2) xs' @\n                (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<or>\n          fst (((c1', s') # xs') ! length xs') = Skip \\<and>\n          (\\<exists>ys. (\\<Gamma>,(Skip,snd(last ((c1', s')#xs')))#ys) \\<in> cptn_mod \\<and>                   \n                 xs=(map (lift_catch c2) xs')@((Skip,snd(last ((c1', s')#xs')))#ys)))\"          \n        by auto\n  thus ?case \n  proof{           \n       assume c1'nonf:\"xs = map (lift_catch c2) xs'\"\n       then have c1'cptn:\"(\\<Gamma>, (c1', s') # xs') \\<in> cptn_mod\" using split by blast\n       then have induct_step: \"(\\<Gamma>, (c1, s) # (c1', s')#xs') \\<in> cptn_mod\"\n         using Catchc.hyps(2)  by blast\n       then have \"(Catch c1' c2, s')#xs = map (lift_catch c2) ((c1', s')#xs')\"\n            using c1'nonf\n            by (simp add: CptnModCatch1 lift_catch_def)\n       thus ?thesis \n            using c1'nonf c1'cptn induct_step by (auto simp add: CptnModCatch1)\n    next\n      assume \"fst (((c1', s') # xs') ! length xs') = Throw \\<and>\n                snd (last ((c1', s') # xs')) = Normal sa' \\<and> s' = Normal sa'' \\<and>\n                (\\<exists>ys. (\\<Gamma>, (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n                xs =map (lift_catch c2) xs' @ (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<or>\n               fst (((c1', s') # xs') ! length xs') = Skip \\<and>\n                (\\<exists>ys. (\\<Gamma>,(Skip,snd(last ((c1', s')#xs')))#ys) \\<in> cptn_mod \\<and>                   \n                 xs=(map (lift_catch c2) xs')@((Skip,snd(last ((c1', s')#xs')))#ys))\"  \n      thus ?thesis\n      proof\n         assume assth:\n               \"fst (((c1', s') # xs') ! length xs') = Throw \\<and>\n                snd (last ((c1', s') # xs')) = Normal sa' \\<and> s' = Normal sa'' \\<and>\n                (\\<exists>ys. (\\<Gamma>, (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n                xs =map (lift_catch c2) xs' @ (c2, snd (((c1', s') # xs') ! length xs')) # ys)\"\n             then have s'eqsa'': \"s'=Normal sa''\" by auto\n             then have snormal: \"\\<exists>ns. s=Normal ns\" by (metis Catchc.hyps(1) step_Abrupt_prop step_Fault_prop step_Stuck_prop xstate.exhaust)\n             then obtain ys \n             where split':\"(\\<Gamma>, (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<in> cptn_mod \\<and>\n                xs =map (lift_catch c2) xs' @ (c2, snd (((c1', s') # xs') ! length xs')) # ys\"\n                using assth by auto    \n         then have c1'cptn:\"(\\<Gamma>, (c1', s') # xs') \\<in> cptn_mod\" \n              using split by blast\n         then have induct_step: \"(\\<Gamma>, (c1, s) # (c1', s')#xs') \\<in> cptn_mod\"\n              using Catchc.hyps(2)  by blast                \n         then have seqmap:\"(Catch c1 c2, s)#(Catch c1' c2, s')#xs = map (lift_catch c2) ((c1,s)#(c1', s')#xs') @ (c2, snd (((c1', s') # xs') ! length xs')) # ys\"\n              using split' by (simp add: CptnModCatch3 lift_catch_def) \n        then have lastc1:\"last ((c1, s) # (c1', s') # xs') = ((c1', s') # xs') ! length xs'\"\n             by (simp add: last_length) \n        then have lastc1skip:\"fst (last ((c1, s) # (c1', s') # xs')) = Throw\" \n             using assth by fastforce\n        then have \"snd (last ((c1, s) # (c1', s') # xs')) = Normal sa'\"\n             using assth by force\n        thus ?thesis using snormal seqmap s'eqsa'' split' last_length  cptn_mod.CptnModCatch3 induct_step lastc1 lastc1skip\n             by fastforce \n    next\n        assume assm:\" fst (((c1', s') # xs') ! length xs') = Skip \\<and> \n                       (\\<exists>ys. (\\<Gamma>,(Skip,snd(last ((c1', s')#xs')))#ys) \\<in> cptn_mod \\<and>                   \n                      xs=(map (lift_catch c2) xs')@((Skip,snd(last ((c1', s')#xs')))#ys))\"\n        then have c1'cptn:\"(\\<Gamma>, (c1', s') # xs') \\<in> cptn_mod\" using split by blast\n        then have induct_step: \"(\\<Gamma>, (c1, s) # (c1', s')#xs') \\<in> cptn_mod\"\n        using Catchc.hyps(2)  by blast \n        then have \"map (lift_catch c2) ((c1', s') # xs') = (Catch c1' c2, s') # map (lift_catch c2) xs'\" \n          by (auto simp add: lift_catch_def)\n        then obtain ys \n             where seqmap:\"(Catch c1' c2, s')#xs = (map (lift_catch c2) ((c1', s')#xs'))@((Skip,snd(last ((c1', s')#xs')))#ys)\"\n        using assm by fastforce\n        then have lastc1:\"last ((c1, s) # (c1', s') # xs') = ((c1', s') # xs') ! length xs'\"\n                   by (simp add: last_length) \n        then have lastc1skip:\"fst (last ((c1, s) # (c1', s') # xs')) = Skip\" \n             using assm by fastforce\n        then have \"snd (last ((c1, s) # (c1', s') # xs')) = snd (last ((c1', s') # xs'))\"\n             using assm by force\n        thus ?thesis \n            using assm c1'cptn induct_step lastc1skip seqmap by (auto simp add:cptn_mod.CptnModCatch2)\n    qed\n  }qed              \nnext\n  case (CatchThrowc c2 s)\n  have c2incptn:\"(\\<Gamma>, (c2, Normal s) # xs) \\<in> cptn_mod\" by fact\n  then have 1:\"(\\<Gamma>, [(Throw, Normal s)]) \\<in> cptn_mod\" by (simp add: cptn_mod.CptnModOne)\n  then have 2:\"fst(last ([(Throw, Normal s)])) = Throw\" by fastforce\n  then have 3:\"(\\<Gamma>,(c2, snd(last [(Throw, Normal s)]))#xs) \\<in> cptn_mod\" \n      using c2incptn by auto  \n  then have \"(c2,Normal s)#xs=(map (lift c2) [])@(c2, snd(last [(Throw, Normal s)]))#xs\" \n       by (auto simp add:lift_def)\n  thus ?case using 1 2 3 by (simp add: CptnModCatch3)\nnext\n  case (CatchSkipc c2 s)\n  have \"(\\<Gamma>, [(Skip, s)]) \\<in> cptn_mod\" by (simp add: cptn_mod.CptnModOne)\n  then obtain ys where ys_nil:\"ys=[]\" and last:\"(\\<Gamma>, (Skip,  s)#ys)\\<in> cptn_mod\"\n    by auto\n  moreover have \"fst (last ((Skip,  s)#ys)) = Skip\" using ys_nil last by auto\n  moreover have \"snd (last ((Skip,  s)#ys)) = s\" using ys_nil last by auto\n  moreover from ys_nil have \"(map (lift_catch c2) ys) = []\" by auto  \n  ultimately show ?case using CatchSkipc.prems by simp (simp add: cptn_mod.CptnModCatch2 ys_nil)\nnext\n  case (FaultPropc c f)\n  thus ?case by (simp add: cptn_mod.CptnModSkip stepc.FaultPropc) \nnext\n  case (AbruptPropc c f)\n  thus ?case by (simp add: cptn_mod.CptnModSkip stepc.AbruptPropc)\nnext\n  case (StuckPropc c)\n  thus ?case by (simp add: cptn_mod.CptnModSkip stepc.StuckPropc)\nqed\n\nlemma cptn_onlyif_cptn_mod: \nassumes cptn_asm:\"(\\<Gamma>,c) \\<in> cptn\"\nshows  \"(\\<Gamma>,c) \\<in> cptn_mod\"\nusing cptn_asm\nproof (induct) \n case CptnOne thus ?case by (rule CptnModOne)\nnext\n case (CptnEnv \\<Gamma> P t xs s) thus ?case by (simp add: cptn_mod.CptnModEnv) \nnext\n case CptnComp thus ?case\n by (simp add: cptn_onlyif_cptn_mod_aux)\nqed\n\nlemma lift_is_cptn: \nassumes cptn_asm:\"(\\<Gamma>,c)\\<in>cptn\"\nshows \"(\\<Gamma>,map (lift P) c) \\<in> cptn\"\nusing cptn_asm\nproof (induct)\n case CptnOne thus ?case using cptn.simps by fastforce\nnext\n  case (CptnEnv \\<Gamma> P s t xs) thus ?case \n      by (cases rule:step_e.cases, \n          (simp add: cptn.CptnEnv step_e.Env lift_def), \n          (simp add: cptn.CptnEnv step_e.Env_n lift_def))\nnext                                              \n  case CptnComp thus ?case by (simp add: Seqc cptn.CptnComp lift_def)\nqed\n\nlemma lift_catch_is_cptn:\nassumes cptn_asm:\"(\\<Gamma>,c)\\<in>cptn\"\nshows \"(\\<Gamma>,map (lift_catch P) c) \\<in> cptn\"\nusing cptn_asm\nproof (induct)\n  case CptnOne thus ?case using cptn.simps by fastforce\nnext\n  case CptnEnv thus ?case  by (cases rule:step_e.cases, \n          (simp add: cptn.CptnEnv step_e.Env lift_catch_def), \n          (simp add: cptn.CptnEnv step_e.Env_n lift_catch_def))\nnext\n  case CptnComp thus ?case by (simp add: Catchc cptn.CptnComp lift_catch_def)\nqed\n\nlemma last_lift: \"\\<lbrakk>xs\\<noteq>[]; fst(xs!(length xs - (Suc 0)))=Q\\<rbrakk> \n \\<Longrightarrow> fst((map (lift P) xs)!(length (map (lift P) xs)- (Suc 0)))=Seq Q P\"\n  by (cases \"(xs ! (length xs - (Suc 0)))\") (simp add:lift_def)\n\nlemma last_lift_catch: \"\\<lbrakk>xs\\<noteq>[]; fst(xs!(length xs - (Suc 0)))=Q\\<rbrakk> \n \\<Longrightarrow> fst((map (lift_catch P) xs)!(length (map (lift_catch P) xs)- (Suc 0)))=Catch Q P\"\n  by (cases \"(xs ! (length xs - (Suc 0)))\") (simp add:lift_catch_def)\n\nlemma last_fst [rule_format]: \"P((a#x)!length x) \\<longrightarrow> \\<not>P a \\<longrightarrow> P (x!(length x - (Suc 0)))\" \n  by (induct x) simp_all\n\n\nlemma last_fst_esp: \n \"fst(((P,s)#xs)!(length xs))=Skip \\<Longrightarrow> P\\<noteq>Skip \\<Longrightarrow> fst(xs!(length xs - (Suc 0)))=Skip\" \napply(erule last_fst)\napply simp\ndone\n\nlemma last_snd: \"xs\\<noteq>[] \\<Longrightarrow> \n  snd(((map (lift P) xs))!(length (map (lift P) xs) - (Suc 0)))=snd(xs!(length xs - (Suc 0)))\"\n  by (cases \"(xs ! (length xs - (Suc 0)))\") (simp_all add:lift_def)\n\nlemma last_snd_catch: \"xs\\<noteq>[] \\<Longrightarrow> \n  snd(((map (lift_catch P) xs))!(length (map (lift_catch P) xs) - (Suc 0)))=snd(xs!(length xs - (Suc 0)))\"\n  by (cases \"(xs ! (length xs - (Suc 0)))\") (simp_all add:lift_catch_def)\n\nlemma Cons_lift: \"((Seq P Q), s) # (map (lift Q) xs) = map (lift Q) ((P, s) # xs)\"\n  by (simp add:lift_def)\nthm last_map eq_snd_iff list.inject list.simps(9) last_length\nlemma Cons_lift_catch: \"((Catch P Q), s) # (map (lift_catch Q) xs) = map (lift_catch Q) ((P, s) # xs)\"\n  by (simp add:lift_catch_def)\n\nlemma Cons_lift_append: \n  \"((Seq P Q), s) # (map (lift Q) xs) @ ys = map (lift Q) ((P, s) # xs)@ ys \"\n  by (simp add:lift_def)\n\nlemma Cons_lift_catch_append: \n  \"((Catch P Q), s) # (map (lift_catch Q) xs) @ ys = map (lift_catch Q) ((P, s) # xs)@ ys \"\n  by (simp add:lift_catch_def)\n\nlemma lift_nth: \"i<length xs \\<Longrightarrow> map (lift Q) xs ! i = lift Q  (xs! i)\"\n  by (simp add:lift_def)\n\nlemma lift_catch_nth: \"i<length xs \\<Longrightarrow> map (lift_catch Q) xs ! i = lift_catch Q  (xs! i)\"\n  by (simp add:lift_catch_def)\nthm list.simps(9) last_length lift_catch_def Cons_lift_catch\nlemma snd_lift: \"i< length xs \\<Longrightarrow> snd(lift Q (xs ! i))= snd (xs ! i)\"\n  by (cases \"xs!i\") (simp add:lift_def)\n\nlemma snd_lift_catch: \"i< length xs \\<Longrightarrow> snd(lift_catch Q (xs ! i))= snd (xs ! i)\"\n  by (cases \"xs!i\") (simp add:lift_catch_def)\n\nlemma Normal_Normal: \nassumes p1:\"(\\<Gamma>, (P, Normal s) # a # as) \\<in> cptn\" and       \n        p2:\"(\\<exists>sb. snd (last ((P, Normal s) # a # as))  = Normal sb)\"\nshows \"\\<exists>sa. snd a = Normal sa\"\nproof -\n   obtain la1 la2 where last_prod:\"last ((P, Normal s)# a#as) = (la1,la2)\" by fastforce\n   obtain a1 a2 where a_prod:\"a=(a1,a2)\" by fastforce\n   from p1 have clos_p_a:\"\\<Gamma>\\<turnstile>\\<^sub>c (P,Normal s) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (a1, a2)\" using a_prod cptn_elim_cases(2)\n    proof -\n      have f1: \"(\\<Gamma>, (P, Normal s) # (a1, a2) # as) \\<in> cptn\"\n        using a_prod p1 by fastforce\n      have \"last [(a1, a2)] = (a1, a2)\"\n        by auto\n      thus ?thesis\n        using f1 by (metis (no_types) cptn_dest1 cptn_stepconf_rtrancl last_ConsR not_Cons_self2)\n    qed  \n   then have \"\\<Gamma>\\<turnstile>\\<^sub>c (fst a, snd a) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>*  (la1,la2)\"\n   proof -\n     from p1 have \"(\\<Gamma>,(a # as)) \\<in> cptn\" using a_prod cptn_dest by blast\n     thus ?thesis by (metis cptn_stepconf_rtrancl last_ConsR last_prod list.distinct(1) prod.collapse) \n   qed \n   then obtain bb where \"Normal bb = la2\" using last_prod p2 by auto\n   thus ?thesis by (metis (no_types) `\\<Gamma>\\<turnstile>\\<^sub>c (fst a, snd a) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (la1, la2)` steps_ce_not_Normal)\nqed\n  \n\nlemma lift_P1: \n assumes map_cptn:\"(\\<Gamma>, map (lift Q) ((P, s) # xs)) \\<in> cptn\" and\n         P_ends:\"fst (last ((P, s) # xs)) = Skip\"\n shows \"(\\<Gamma>, map (lift Q) ((P, s) # xs) @ [(Q, snd (last ((P, s) # xs)))]) \\<in> cptn\"\nusing map_cptn P_ends\nproof (induct xs arbitrary: P s) \n  case Nil\n  have P0_skips: \"P=Skip\" using Nil.prems(2) by auto   \n  have \"(\\<Gamma>,[(Seq Skip Q, s), (Q, s)]) \\<in> cptn\"\n    by (simp add: cptn.CptnComp SeqSkipc cptn.CptnOne)\n  then show ?case using P0_skips by (simp add: lift_def)\nnext\n  case (Cons a xs)\n  have \"(\\<Gamma>, map (lift Q) ((P, s) # a # xs)) \\<in> cptn\"\n    using Cons.prems(1) by blast  \n  have \"fst (last ( a # xs)) = Skip\" using Cons.prems(2) by auto\n  also have seq_PQ:\"(\\<Gamma>,(Seq P Q,s) # (map (lift Q) (a#xs))) \\<in> cptn\"\n    by (metis Cons.prems(1) Cons_lift)\n  then have \"(\\<Gamma>,(map (lift Q) (a#xs))) \\<in> cptn\"\n    proof -\n      assume a1:\"(\\<Gamma>, (Seq P Q, s) # map (lift Q) (a # xs)) \\<in> cptn\"            \n      then obtain a1 a2 xs1 where a2: \"map (lift Q) (a#xs) = ((a1,a2)#xs1)\" by fastforce \n      thus ?thesis  using cptn_dest using seq_PQ by auto \n    qed \n  then have \"(\\<Gamma>, map (lift Q) (a#xs) @ [(Q, snd (last ((a#xs))))]) \\<in> cptn\" \n   by (metis Cons.hyps(1) calculation prod.collapse)   \n  then have t1:\"(\\<Gamma>, (Seq (fst a) Q, (snd a))#map (lift Q) xs @ [(Q, snd (last ((P, s)#(a#xs))))]) \\<in> cptn\"\n   by (simp add: Cons_lift_append)\n  then have \"(\\<Gamma>,(Seq P Q,s) # (Seq (fst a) Q, (snd a))#map (lift Q) xs)\\<in> cptn\"\n   using seq_PQ by (simp add: Cons_lift)  \n  then have t2: \"(\\<Gamma>,(Seq P Q,s) # [(Seq (fst a) Q, (snd a))]) \\<in> cptn\"\n   using cptn_dest1 by blast\n  then have\"((Seq P Q,s) # [(Seq (fst a) Q, (snd a))])!length [(Seq (fst a) Q, (snd a))] = (Seq (fst a) Q, (snd a))\"\n   by auto  \n  then have \"(\\<Gamma>,(Seq P Q,s) # [(Seq (fst a) Q, (snd a))]@map (lift Q) xs @ [(Q, snd (last ((P, s)#(a#xs))))])\\<in> cptn\"\n   using cptn_append_is_cptn t1 t2 by blast   \n  then have \"(\\<Gamma>, map (lift Q) ((P,s)#(fst a, snd a)#xs) @[(Q, snd (last ((P, s)#(a#xs))))])\\<in>cptn\"\n   using Cons_lift_append append_Cons append_Nil by metis\n  thus ?case by auto    \nqed\n\n\nlemma lift_catch_P1: \n assumes map_cptn:\"(\\<Gamma>, map (lift_catch Q) ((P, Normal s) # xs)) \\<in> cptn\" and\n         P_ends:\"fst (last ((P, Normal s) # xs)) = Throw\" and\n         P_ends_normal:\"\\<exists>p. snd(last ((P, Normal s) # xs)) = Normal p\"\n shows \"(\\<Gamma>, map (lift_catch Q) ((P, Normal s) # xs) @ [(Q, snd (last ((P, Normal s) # xs)))]) \\<in> cptn\"\nusing map_cptn P_ends P_ends_normal\nproof (induct xs arbitrary: P s) \n  case Nil\n  have P0_skips: \"P=Throw\" using Nil.prems(2) by auto   \n  have \"(\\<Gamma>,[(Catch Throw Q, Normal s), (Q, Normal s)]) \\<in> cptn\"\n    by (simp add: cptn.CptnComp CatchThrowc cptn.CptnOne)\n  then show ?case using P0_skips by (simp add: lift_catch_def)\nnext\n  case (Cons a xs) \n  have s1:\"(\\<Gamma>, map (lift_catch Q) ((P, Normal s) # a # xs)) \\<in> cptn\"\n    using Cons.prems(1) by blast \n  have s2:\"fst (last ( a # xs)) = Throw\" using Cons.prems(2) by auto\n  then obtain p where s3:\"snd(last (a #xs)) = Normal p\" using Cons.prems(3) by auto\n  also have seq_PQ:\"(\\<Gamma>,(Catch P Q,Normal s) # (map (lift_catch Q) (a#xs))) \\<in> cptn\"\n    by (metis Cons.prems(1) Cons_lift_catch) thm Cons.hyps\n  then have axs_in_cptn:\"(\\<Gamma>,(map (lift_catch Q) (a#xs))) \\<in> cptn\"\n    proof -\n      assume a1:\"(\\<Gamma>, (Catch P Q, Normal s) # map (lift_catch Q) (a # xs)) \\<in> cptn\"            \n      then obtain a1 a2 xs1 where a2: \"map (lift_catch Q) (a#xs) = ((a1,a2)#xs1)\" by fastforce \n      thus ?thesis  using cptn_dest using seq_PQ by auto \n    qed \n  then have \"(\\<Gamma>, map (lift_catch Q) (a#xs) @ [(Q, snd (last ((a#xs))))]) \\<in> cptn\" \n    proof (cases \"xs=[]\")\n      case True thus ?thesis using s2 s3 axs_in_cptn by (metis Cons.hyps eq_snd_iff last_ConsL)\n    next\n      case False            \n      from seq_PQ have seq:\"(\\<Gamma>,(Catch P Q,Normal s) # (Catch (fst a) Q,snd a)#map (lift_catch Q) xs)\\<in> cptn\"\n        by (simp add: Cons_lift_catch)                         \n      obtain cf sf where last_map_axs:\"(cf,sf)=last (map (lift_catch Q) (a#xs))\" using prod.collapse by blast\n      have \"\\<forall>p ps. (ps=[] \\<and> last [p] = p) \\<or> (ps\\<noteq>[] \\<and> last (p#ps) = last ps)\" by simp              \n      then have tranclos:\"\\<Gamma>\\<turnstile>\\<^sub>c (Catch P Q,Normal s) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (Catch (fst a) Q,snd a)\" using Cons_lift_catch\n            by (metis (no_types) cptn_dest1 cptn_stepc_rtrancl not_Cons_self2 seq)\n      have tranclos_a:\"\\<Gamma>\\<turnstile>\\<^sub>c (Catch (fst a) Q,snd a) \\<rightarrow>\\<^sub>c\\<^sub>e\\<^sup>* (cf,sf)\"\n           by (metis Cons_lift_catch axs_in_cptn cptn_stepc_rtrancl last_map_axs prod.collapse)      \n      have snd_last:\"snd (last (map (lift_catch Q) (a#xs))) = snd (last (a #xs))\"\n      proof - \n         have eqslist:\"snd(((map (lift_catch Q) (a#xs)))!(length (map (lift_catch Q) xs)))= snd((a#xs)!(length xs))\" \n           using last_snd_catch by fastforce  \n         have \"(lift_catch Q a)#(map (lift_catch Q) xs) = (map (lift_catch Q) (a#xs))\" by auto\n         then have \"(map (lift_catch Q) (a#xs))!(length (map (lift_catch Q) xs)) = last (map (lift_catch Q) (a#xs))\"\n           using last_length [of \"(lift_catch Q a)\" \"(map (lift_catch Q) xs)\"] by auto\n         thus ?thesis using eqslist by (simp add:last_length)\n      qed\n      then obtain p1 where  \"(snd a) = Normal p1\"\n         by (metis tranclos_a last_map_axs s3 snd_conv step_ce_normal_to_normal tranclos)   \n      moreover obtain a1 a2 where aeq:\"a = (a1,a2)\" by fastforce \n      moreover have \"fst (last ((a1,a2) # xs)) = Throw\" using s2 False by auto  \n      moreover have \"(\\<Gamma>, map (lift_catch Q) ((a1,a2) # xs)) \\<in> cptn\" using aeq axs_in_cptn False by auto  \n      moreover have \"\\<exists>p. snd (last ((a1,a2) # xs)) = Normal p\" using s3 aeq by auto\n      moreover have \"a2 = Normal p1\" using aeq calculation(1) by auto \n      ultimately have \"(\\<Gamma>, map (lift_catch Q) ((a1,a2) # xs) @\n                           [(Q, snd (last ((a1,a2) # xs)))])\\<in> cptn\" \n                 using Cons.hyps aeq by blast\n      thus ?thesis using aeq by force \n    qed      \n  then have t1:\"(\\<Gamma>, (Catch (fst a) Q, (snd a))#map (lift_catch Q) xs @ [(Q, snd (last ((P, Normal s)#(a#xs))))]) \\<in> cptn\"\n   by (simp add: Cons_lift_catch_append)\n  then have \"(\\<Gamma>,(Catch P Q,Normal s) # (Catch (fst a) Q, (snd a))#map (lift_catch Q) xs)\\<in> cptn\"\n   using seq_PQ by (simp add: Cons_lift_catch)  \n  then have t2: \"(\\<Gamma>,(Catch P Q,Normal s) # [(Catch (fst a) Q, (snd a))]) \\<in> cptn\"\n   using cptn_dest1 by blast\n  then have\"((Catch P Q,Normal s) # [(Catch (fst a) Q, (snd a))])!length [(Catch (fst a) Q, (snd a))] = (Catch (fst a) Q, (snd a))\"\n   by auto  \n  then have \"(\\<Gamma>,(Catch P Q,Normal s) # [(Catch (fst a) Q, (snd a))]@map (lift_catch Q) xs @ [(Q, snd (last ((P, Normal s)#(a#xs))))])\\<in> cptn\"\n   using cptn_append_is_cptn t1 t2 by blast\n  then have \"(\\<Gamma>, map (lift_catch Q) ((P,Normal s)#(fst a, snd a)#xs) @[(Q, snd (last ((P,Normal s)#(a#xs))))])\\<in>cptn\"\n   using Cons_lift_catch_append append_Cons append_Nil by metis\n  thus ?case by auto    \nqed\n\nlemma seq2:\nassumes \n    p1:\"(\\<Gamma>, (P0, s) # xs) \\<in> cptn_mod\" and\n    p2:\"(\\<Gamma>, (P0, s) # xs) \\<in> cptn\" and\n    p3:\"fst (last ((P0, s) # xs)) = Skip\" and\n    p4:\"(\\<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod\" and\n    p5:\"(\\<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \\<in> cptn\" and\n    p6:\"zs = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys\"\nshows \"(\\<Gamma>, (Seq P0 P1, s) # zs) \\<in> cptn\"\nusing p1 p2 p3 p4 p5 p6\nproof -\nhave last_skip:\"fst (last ((P0, s) # xs)) = Skip\" using p3 by blast \n  have \"(\\<Gamma>, (map (lift P1) ((P0, s) # xs))@(P1, snd (last ((P0, s) # xs))) # ys) \\<in> cptn\"\n  proof -\n    have \"(\\<Gamma>,map (lift P1) ((P0, s) #xs)) \\<in> cptn\"\n      using p2 lift_is_cptn by blast \n    then have \"(\\<Gamma>,map (lift P1) ((P0, s) #xs)@[(P1, snd (last ((P0, s) # xs)))]) \\<in> cptn\" \n      using last_skip lift_P1 by blast \n    then have \"(\\<Gamma>,(Seq P0 P1, s) # map (lift P1) xs@[(P1, snd (last ((P0, s) # xs)))]) \\<in> cptn\"\n         by (simp add: Cons_lift_append)\n    moreover have \"last ((Seq P0 P1, s) # map (lift P1) xs @[(P1, snd (last ((P0, s) # xs)))]) = (P1, snd (last ((P0, s) # xs)))\" \n      by auto  \n    moreover have \"last ((Seq P0 P1, s) # map (lift P1) xs @[(P1, snd (last ((P0, s) # xs)))]) =\n                   ((Seq P0 P1, s) # map (lift P1) xs @[(P1, snd (last ((P0, s) # xs)))])!length (map (lift P1) xs @[(P1, snd (last ((P0, s) # xs)))])\" \n      by (metis last_length)             \n    ultimately have \"(\\<Gamma>, (Seq P0 P1, s) # map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys)\\<in> cptn\" \n      using cptn_append_is_cptn p5 by fastforce\n    thus ?thesis by (simp add: Cons_lift_append)\n  qed \n  thus ?thesis  \n    by (simp add: Cons_lift_append p6)\nqed\n\nlemma seq3:\nassumes\n    p1:\"(\\<Gamma>, (P0, Normal s) # xs) \\<in> cptn_mod\" and\n    p2:\"(\\<Gamma>, (P0, Normal s) # xs) \\<in> cptn\" and\n    p3:\"fst (last ((P0, Normal s) # xs)) = Throw\" and\n    p4:\"snd (last ((P0, Normal s) # xs)) = Normal s'\" and\n    p5:\"(\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod\" and\n    p6:\"(\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn\" and\n    p7:\"zs = map (lift P1) xs @((Throw,Normal s')#ys)\" \nshows \"(\\<Gamma>, (Seq P0 P1, Normal s) # zs) \\<in> cptn\"\nusing p1 p2 p3 p4 p5 p6 p7\nproof (induct xs arbitrary: zs P0 s) \n  case Nil thus ?case using SeqThrowc cptn.simps by fastforce\nnext\n  case (Cons a as)\n  then obtain sa where \"snd a = Normal sa\" by (meson Normal_Normal)\n  obtain a1 a2 where a_prod:\"a=(a1,a2)\" by fastforce\n  obtain la1 la2 where last_prod:\"last (a#as) = (la1,la2)\" by fastforce \n  then have lasst_aas_last: \"last (a#as) = (last ((P0, Normal s) # a # as))\" by auto    \n  then have \"la1 = Throw\" using Cons.prems(3) last_prod by force\n  have \"la2 = Normal s'\" using Cons.prems(4) last_prod lasst_aas_last by force\n  have f1: \"(\\<Gamma>, (a1, a2) # as) \\<in> cptn\"\n    using Cons.prems(2) a_prod cptn_dest by blast\n  have f2: \"Normal sa = a2\"\n    using `snd a = Normal sa` a_prod by force\n  have \"(\\<Gamma>, a # as) \\<in> cptn_mod\"\n    using f1 a_prod cptn_onlyif_cptn_mod by blast\n  then have hyp:\"(\\<Gamma>, (Seq a1 P1, Normal sa) # \n            map (lift P1) as @ ((Throw,Normal s')#ys)) \\<in> cptn\"\n        using Cons.hyps Cons.prems(3) Cons.prems(4)  Cons.prems(5) Cons.prems(6) a_prod f1 f2 by fastforce\n  thus ?case\n  proof -\n    have \"(Seq a1 P1, a2) # map (lift P1) as @((Throw,Normal s')#ys) = zs\"\n      by (simp add: Cons.prems(7) Cons_lift_append a_prod)\n    thus ?thesis\n      by (metis (no_types, lifting) Cons.prems(2) Seqc a_prod cptn.CptnComp cptn.CptnEnv Env cptn_elim_cases(2) f2 hyp)     \n  qed \nqed\n\nlemma cptn_if_cptn_mod: \nassumes cptn_mod_asm:\"(\\<Gamma>,c) \\<in> cptn_mod\"\nshows  \"(\\<Gamma>,c) \\<in> cptn\"\nusing cptn_mod_asm\nproof (induct)\n  case (CptnModOne) thus ?case using cptn.CptnOne by blast\nnext\n  case CptnModSkip thus ?case by (simp add: cptn.CptnComp) \nnext\n  case CptnModThrow thus ?case by (simp add: cptn.CptnComp) \nnext \n  case CptnModCondT thus ?case by (simp add: CondTruec cptn.CptnComp) \nnext\n  case CptnModCondF thus ?case by (simp add: CondFalsec cptn.CptnComp)\nnext\n  case (CptnModSeq1 \\<Gamma> P0 s xs zs P1) \n  have \"(\\<Gamma>, map (lift P1) ((P0, s) # xs)) \\<in> cptn\"\n    using CptnModSeq1.hyps(2) lift_is_cptn by blast\n  thus ?case by (simp add: Cons_lift CptnModSeq1.hyps(3))\nnext\n  case (CptnModSeq2 \\<Gamma> P0 s xs P1 ys zs)   \n  thus ?case by (simp add:seq2)\nnext\n  case (CptnModSeq3 \\<Gamma> P0 s xs s' zs P1) \n  thus ?case by (simp add: seq3)\nnext\n  case (CptnModWhile1  \\<Gamma> P s xs b zs) thus ?case by (metis Cons_lift WhileTruec cptn.CptnComp lift_is_cptn)\nnext \n  case (CptnModWhile2  \\<Gamma> P s xs b zs ys)    \n  then have \"(\\<Gamma>, (Seq P (While b P), Normal s) # zs) \\<in> cptn\" \n    by (simp add:seq2)  \n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c(While b P,Normal s) \\<rightarrow> (Seq P (While b P),Normal s)\" \n    by (simp add: CptnModWhile2.hyps(4) WhileTruec)\n  thus ?case\n   by (simp add: `(\\<Gamma>, (Seq P (While b P), Normal s) # zs) \\<in> cptn` cptn.CptnComp) \nnext\n  case (CptnModWhile3  \\<Gamma> P s xs b s' ys zs) \n  then have \"(\\<Gamma>,(Seq P (While b P), Normal s) # zs) \\<in> cptn\"\n     by (simp add: seq3)     \n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c(While b P,Normal s) \\<rightarrow> (Seq P (While b P),Normal s)\" by (simp add: CptnModWhile3.hyps(4) WhileTruec)\n  thus ?case by (simp add: `(\\<Gamma>, (Seq P (While b P), Normal s) # zs) \\<in> cptn` cptn.CptnComp)\nnext \n  case (CptnModCall \\<Gamma> bdy s ys p) thus ?case by (simp add: Callc cptn.CptnComp) \nnext\n  case (CptnModDynCom \\<Gamma> c s ys) thus ?case by (simp add: DynComc cptn.CptnComp)\nnext\n  case (CptnModGuard \\<Gamma> c s ys g f) thus ?case by (simp add: Guardc cptn.CptnComp)\nnext\n  case (CptnModCatch1 \\<Gamma> P0 s xs zs P1)\n  have \"(\\<Gamma>, map (lift_catch P1) ((P0, s) # xs)) \\<in> cptn\"\n    using CptnModCatch1.hyps(2) lift_catch_is_cptn by blast\n  thus ?case by (simp add: Cons_lift_catch CptnModCatch1.hyps(3))\nnext\n  case (CptnModCatch2 \\<Gamma> P0 s xs ys zs P1)\n  thus ?case\n  proof (induct xs arbitrary: zs P0 s) \n    case Nil thus ?case using CatchSkipc cptn.simps by fastforce\n  next\n    case (Cons a as)\n    then obtain sa where \"snd a = sa\" by auto\n    then obtain a1 a2 where a_prod:\"a=(a1,a2)\" and sa_a2: \"a2 =sa\" \n           by fastforce\n    obtain la1 la2 where last_prod:\"last (a#as) = (la1,la2)\" by fastforce \n    then have lasst_aas_last: \"last (a#as) = (last ((P0, s) # a # as))\" by auto    \n    then have \"la1 = Skip\" using Cons.prems(3) last_prod by force\n    have f1: \"(\\<Gamma>, (a1, a2) # as) \\<in> cptn\"\n      using Cons.prems(2) a_prod cptn_dest by blast\n    have \"(\\<Gamma>, a # as) \\<in> cptn_mod\"\n      using f1 a_prod cptn_onlyif_cptn_mod by blast\n    then have hyp:\"(\\<Gamma>, (Catch a1 P1, a2) # \n              map (lift_catch P1) as @ ((Skip, la2)#ys)) \\<in> cptn\"\n          using Cons.hyps Cons.prems a_prod f1 last_prod by fastforce\n    thus ?case\n    proof -\n      have f1:\"(Catch a1 P1, a2) # map (lift_catch P1) as @ ((Skip, la2)#ys) = zs\"\n        using Cons.prems(4) Cons_lift_catch_append a_prod last_prod by (simp add: Cons.prems(6))         \n      have \"(\\<Gamma>, map (lift_catch P1) ((P0, s) # a # as)) \\<in> cptn\"\n       using Cons.prems(2) lift_catch_is_cptn by blast\n      hence \"(\\<Gamma>, (LanguageCon.com.Catch P0 P1, s) # (LanguageCon.com.Catch a1 P1, a2) # map (lift_catch P1) as) \\<in> cptn\"\n        by (metis (no_types) Cons_lift_catch a_prod)\n      hence \"(\\<Gamma>, (LanguageCon.com.Catch P0 P1, s) # zs) \\<in> cptn \\<or> (\\<Gamma>, (LanguageCon.com.Catch P0 P1, s) # (LanguageCon.com.Catch a1 P1, a2) # map (lift_catch P1) as) \\<in> cptn \\<and> (\\<not> \\<Gamma>\\<turnstile>\\<^sub>c (LanguageCon.com.Catch P0 P1, s) \\<rightarrow>\\<^sub>e (LanguageCon.com.Catch P0 P1, a2) \\<or> (\\<Gamma>, (LanguageCon.com.Catch P0 P1, a2) # map (lift_catch P1) as) \\<notin> cptn \\<or> LanguageCon.com.Catch a1 P1 \\<noteq> LanguageCon.com.Catch P0 P1)\"\n        using f1 cptn.CptnEnv hyp by blast\n      thus ?thesis\n       by (metis (no_types) f1 cptn.CptnComp cptn_elim_cases(2) hyp)\n     qed\n   qed\nnext \n  case (CptnModCatch3  \\<Gamma> P0 s xs s' P1 ys zs)\n  thus ?case\n  proof (induct xs arbitrary: zs P0 s) \n    case Nil thus ?case using CatchThrowc cptn.simps by fastforce\n  next\n    case (Cons a as)\n    then obtain sa where \"snd a = Normal sa\" by (meson Normal_Normal)\n    obtain a1 a2 where a_prod:\"a=(a1,a2)\" by fastforce\n    obtain la1 la2 where last_prod:\"last (a#as) = (la1,la2)\" by fastforce \n    then have lasst_aas_last: \"last (a#as) = (last ((P0, Normal s) # a # as))\" by auto    \n    then have \"la1 = Throw\" using Cons.prems(3) last_prod by force\n    have \"la2 = Normal s'\" using Cons.prems(4) last_prod lasst_aas_last by force\n    have f1: \"(\\<Gamma>, (a1, a2) # as) \\<in> cptn\"\n      using Cons.prems(2) a_prod cptn_dest by blast\n    have f2: \"Normal sa = a2\"\n      using `snd a = Normal sa` a_prod by force\n    have \"(\\<Gamma>, a # as) \\<in> cptn_mod\"\n      using f1 a_prod cptn_onlyif_cptn_mod by blast\n    then have hyp:\"(\\<Gamma>, (Catch a1 P1, Normal sa) # \n              map (lift_catch P1) as @ (P1, snd (last ((a1, Normal sa) # as))) # ys) \\<in> cptn\"\n          using Cons.hyps Cons.prems a_prod f1 f2 by auto\n    thus ?case\n    proof -\n      have \"\\<Gamma>\\<turnstile>\\<^sub>c (P0, Normal s) \\<rightarrow>\\<^sub>e (P0, a2)\"\n        by (fastforce intro: step_e.intros)\n      then have transit:\"\\<Gamma>\\<turnstile>\\<^sub>c(P0,Normal s) \\<rightarrow>\\<^sub>c\\<^sub>e (a1,Normal sa)\" \n            by (metis (no_types) Cons.prems(2) a_prod c_step cptn_elim_cases(2) e_step f2)\n      then have transit_catch:\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch P0 P1,Normal s) \\<rightarrow>\\<^sub>c\\<^sub>e (Catch a1 P1,Normal sa)\"\n            by (metis (no_types) Catchc c_step e_step env_c_c' step_ce_elim_cases step_e.intros(1)) \n      have \"(Catch a1 P1, a2) # map (lift_catch P1) as @ (P1, la2) # ys = zs\"\n        using Cons.prems Cons_lift_catch_append a_prod last_prod by auto        \n      have \"a=(a1, Normal sa)\" using a_prod f2 by auto\n      have \"snd (last ((a1, Normal sa) # as)) = Normal s'\"\n          using `a = (a1, Normal sa)` `snd (last ((P0, Normal s) # a # as)) = Normal s'` lasst_aas_last by fastforce\n      hence f1: \"snd (last ((a1, Normal sa) # as)) = la2\"\n          using `la2 = Normal s'` by blast\n      have \"\\<Gamma>\\<turnstile>\\<^sub>c (LanguageCon.com.Catch P0 P1, Normal s) \\<rightarrow>\\<^sub>c\\<^sub>e (LanguageCon.com.Catch a1 P1, a2)\"\n          using f2 transit_catch by blast\n      thus ?thesis\n        using f1 `(LanguageCon.com.Catch a1 P1, a2) # map (lift_catch P1) as @ (P1, la2) # ys = zs`  \n              cptn.CptnComp cptn.CptnEnv f2 hyp not_eq_not_env step_ce_not_step_e_step_c \n        by metis\n    qed\n  qed\nnext \n  case (CptnModEnv) thus ?case by (simp add: cptn.CptnEnv)\nqed\n\nlemma cptn_eq_cptn_mod: \nshows  \"(x \\<in>cptn_mod)  = (x\\<in>cptn)\"\nby (cases x, auto simp add: cptn_if_cptn_mod cptn_onlyif_cptn_mod)\n\nlemma cptn_eq_cptn_mod_set: \nshows  \"cptn_mod  = cptn\"\nby (auto simp add: cptn_if_cptn_mod cptn_onlyif_cptn_mod)\n\nsubsection \\<open>Computational modular semantic for nested calls\\<close>\ninductive_set cptn_mod_nest_call :: \"(nat\\<times>('s,'p,'f,'e) confs) set\"\nwhere\n  CptnModNestOne: \"(n,\\<Gamma>,[(P, s)]) \\<in> cptn_mod_nest_call\"\n| CptnModNestEnv: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow>\\<^sub>e (P,t);(n,\\<Gamma>,(P, t)#xs) \\<in> cptn_mod_nest_call\\<rbrakk> \\<Longrightarrow> \n                     (n,\\<Gamma>,(P, s)#(P, t)#xs) \\<in> cptn_mod_nest_call\"\n| CptnModNestSkip: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow> (Skip,t); redex P = P; \n                     \\<forall>f. ((\\<exists>sn. s = Normal sn) \\<and> (\\<Gamma> f) = Some Skip \\<longrightarrow> P  \\<noteq> Call f  );\n                (n,\\<Gamma>,(Skip, t)#xs) \\<in> cptn_mod_nest_call \\<rbrakk> \\<Longrightarrow> \n                (n,\\<Gamma>,(P,s)#(Skip, t)#xs) \\<in>cptn_mod_nest_call\"\n\n| CptnModNestThrow: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow> (Throw,t); redex P = P; \n                     \\<forall>f. ((\\<exists>sn. s = Normal sn) \\<and> (\\<Gamma> f) = Some Throw \\<longrightarrow> P  \\<noteq> Call f  );\n                      (n,\\<Gamma>,(Throw, t)#xs) \\<in> cptn_mod_nest_call \\<rbrakk> \\<Longrightarrow> \n                      (n,\\<Gamma>,(P,s)#(Throw, t)#xs) \\<in>cptn_mod_nest_call\"\n\n| CptnModNestCondT: \"\\<lbrakk>(n,\\<Gamma>,(P0, Normal s)#ys) \\<in> cptn_mod_nest_call; s \\<in> b \\<rbrakk> \\<Longrightarrow> \n                    (n,\\<Gamma>,((Cond b P0 P1), Normal s)#(P0, Normal s)#ys) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestCondF: \"\\<lbrakk>(n,\\<Gamma>,(P1, Normal s)#ys) \\<in> cptn_mod_nest_call; s \\<notin> b \\<rbrakk> \\<Longrightarrow> \n                     (n,\\<Gamma>,((Cond b P0 P1), Normal s)#(P1, Normal s)#ys) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestSeq1: \n  \"\\<lbrakk>(n,\\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call; zs=map (lift P1) xs \\<rbrakk> \\<Longrightarrow> \n   (n,\\<Gamma>,((Seq P0 P1), s)#zs) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestSeq2: \n  \"\\<lbrakk>(n,\\<Gamma>, (P0, s)#xs) \\<in> cptn_mod_nest_call; fst(last ((P0, s)#xs)) = Skip;\n    (n,\\<Gamma>,(P1, snd(last ((P0, s)#xs)))#ys) \\<in> cptn_mod_nest_call;\n    zs=(map (lift P1) xs)@((P1, snd(last ((P0, s)#xs)))#ys) \\<rbrakk> \\<Longrightarrow> \n   (n,\\<Gamma>,((Seq P0 P1), s)#zs) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestSeq3: \n  \"\\<lbrakk>(n,\\<Gamma>, (P0, Normal s)#xs) \\<in> cptn_mod_nest_call; \n    fst(last ((P0, Normal s)#xs)) = Throw;\n    snd(last ((P0, Normal s)#xs)) = Normal s'; \n    (n,\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod_nest_call; \n    zs=(map (lift P1) xs)@((Throw,Normal s')#ys) \\<rbrakk> \\<Longrightarrow>\n   (n,\\<Gamma>,((Seq P0 P1), Normal s)#zs) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestWhile1: \n  \"\\<lbrakk>(n,\\<Gamma>, (P, Normal s)#xs) \\<in> cptn_mod_nest_call; s \\<in> b; \n    zs=map (lift (While b P)) xs \\<rbrakk> \\<Longrightarrow> \n    (n,\\<Gamma>, ((While b P), Normal s)#\n      ((Seq P (While b P)),Normal s)#zs) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestWhile2: \n  \"\\<lbrakk> (n,\\<Gamma>, (P, Normal s)#xs) \\<in> cptn_mod_nest_call; \n     fst(last ((P, Normal s)#xs))=Skip; s \\<in> b; \n     zs=(map (lift (While b P)) xs)@\n      (While b P, snd(last ((P, Normal s)#xs)))#ys; \n      (n,\\<Gamma>,(While b P, snd(last ((P, Normal s)#xs)))#ys) \\<in> \n        cptn_mod_nest_call\\<rbrakk> \\<Longrightarrow> \n   (n,\\<Gamma>,(While b P, Normal s)#\n     (Seq P (While b P), Normal s)#zs) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestWhile3: \n  \"\\<lbrakk> (n,\\<Gamma>, (P, Normal s)#xs) \\<in> cptn_mod_nest_call; \n     fst(last ((P, Normal s)#xs))=Throw; s \\<in> b;\n     snd(last ((P, Normal s)#xs)) = Normal s'; \n    (n,\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod_nest_call;  \n     zs=(map (lift (While b P)) xs)@((Throw,Normal s')#ys)\\<rbrakk> \\<Longrightarrow> \n   (n,\\<Gamma>,(While b P, Normal s)#\n     (Seq P (While b P), Normal s)#zs) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestCall: \"\\<lbrakk>(n,\\<Gamma>,(bdy, Normal s)#ys) \\<in> cptn_mod_nest_call;\\<Gamma> p = Some bdy; bdy\\<noteq>Call p \\<rbrakk> \\<Longrightarrow> \n                 (Suc n, \\<Gamma>,((Call p), Normal s)#(bdy, Normal s)#ys) \\<in> cptn_mod_nest_call\" \n\n| CptnModNestDynCom: \"\\<lbrakk>(n,\\<Gamma>,(c s, Normal s)#ys) \\<in> cptn_mod_nest_call \\<rbrakk> \\<Longrightarrow> \n                 (n,\\<Gamma>,(DynCom c, Normal s)#(c s, Normal s)#ys) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestGuard: \"\\<lbrakk>(n,\\<Gamma>,(c, Normal s)#ys) \\<in> cptn_mod_nest_call; s \\<in> g \\<rbrakk> \\<Longrightarrow> \n                  (n,\\<Gamma>,(Guard f g c, Normal s)#(c, Normal s)#ys) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestCatch1: \"\\<lbrakk>(n,\\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call; zs=map (lift_catch P1) xs \\<rbrakk>\n                 \\<Longrightarrow> (n,\\<Gamma>,((Catch P0 P1), s)#zs) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestCatch2: \n  \"\\<lbrakk>(n,\\<Gamma>, (P0, s)#xs) \\<in> cptn_mod_nest_call; fst(last ((P0, s)#xs)) = Skip; \n    (n,\\<Gamma>,(Skip,snd(last ((P0, s)#xs)))#ys) \\<in> cptn_mod_nest_call;  \n    zs=(map (lift_catch P1) xs)@((Skip,snd(last ((P0, s)#xs)))#ys) \\<rbrakk> \\<Longrightarrow> \n   (n,\\<Gamma>,((Catch P0 P1), s)#zs) \\<in> cptn_mod_nest_call\"\n\n| CptnModNestCatch3: \n  \"\\<lbrakk>(n,\\<Gamma>, (P0, Normal s)#xs) \\<in> cptn_mod_nest_call; fst(last ((P0, Normal s)#xs)) = Throw; \n  snd(last ((P0, Normal s)#xs)) = Normal s';\n  (n,\\<Gamma>,(P1, snd(last ((P0, Normal s)#xs)))#ys) \\<in> cptn_mod_nest_call; \n  zs=(map (lift_catch P1) xs)@((P1, snd(last ((P0, Normal s)#xs)))#ys) \\<rbrakk> \\<Longrightarrow> \n   (n,\\<Gamma>,((Catch P0 P1), Normal s)#zs) \\<in> cptn_mod_nest_call\"\n\nlemmas CptnMod_nest_call_induct = cptn_mod_nest_call.induct [of _ _ \"[(c,s)]\", split_format (complete), case_names\nCptnModOne CptnModEnv CptnModSkip CptnModThrow CptnModCondT CptnModCondF \nCptnModSeq1 CptnModSeq2 CptnModSeq3 CptnModSeq4 CptnModWhile1 CptnModWhile2 CptnModWhile3 CptnModCall CptnModDynCom CptnModGuard \nCptnModCatch1 CptnModCatch2 CptnModCatch3, induct set]\n\ninductive_cases CptnModNest_elim_cases [cases set]:\n\"(n,\\<Gamma>,(Skip, s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(Guard f g c, s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(Basic f e, s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(Spec r e, s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(Seq c1 c2, s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(Cond b c1 c2, s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(Await b c2 e, s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(Call p, s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(DynCom c,s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(Throw,s)#u#xs) \\<in> cptn_mod_nest_call\"\n\"(n,\\<Gamma>,(Catch c1 c2,s)#u#xs) \\<in> cptn_mod_nest_call\"\n\ninductive_cases stepc_elim_cases_Seq_Seq':\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Seq c1 c2,s) \\<rightarrow> (Seq c1' c2',s')\" \n\ninductive_cases stepc_elim_cases_Catch_Catch':\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,s) \\<rightarrow> (Catch c1' c2',s')\" \n\ninductive_cases CptnModNest_same_elim_cases [cases set]:\n\"(n,\\<Gamma>,(u, s)#(u,t)#xs) \\<in> cptn_mod_nest_call\"\n\ninductive_cases CptnModNest_elim_cases_Stuck [cases set]:\n\"(n,\\<Gamma>,(P, Stuck)#(Skip, s)#xs) \\<in> cptn_mod_nest_call\"\n\ninductive_cases CptnModNest_elim_cases_Fault [cases set]:\n\"(n,\\<Gamma>,(P, Fault f)#(Skip, s)#xs) \\<in> cptn_mod_nest_call\"\n\ninductive_cases CptnModNest_elim_cases_Abrupt [cases set]:\n\"(n,\\<Gamma>,(P, Abrupt as)#(Skip, s)#xs) \\<in> cptn_mod_nest_call\"\n\ninductive_cases  CptnModNest_elim_cases_Call_Stuck [cases set]:\n\"(n,\\<Gamma>,(Call p, s)#(Skip, Stuck)#xs) \\<in> cptn_mod_nest_call\"\n\ninductive_cases  CptnModNest_elim_cases_Call [cases set]:\n\"(0, \\<Gamma>,((Call p), Normal s)#(bdy, Normal s)#ys) \\<in> cptn_mod_nest_call\"\n\ninductive_cases  CptnEmpty [cases set]:\n\"(n, \\<Gamma>,[]) \\<in> cptn_mod_nest_call\"\n\ninductive_cases  CptnModNest_elim_cases_Call_normal [cases set]:\n\"(Suc n, \\<Gamma>,((Call p), Normal s)#(bdy, Normal s)#ys) \\<in> cptn_mod_nest_call\"\n\nlemma cptn_mod_nest_mono1: \"(n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call  \\<Longrightarrow> (Suc n,\\<Gamma>,cfs)\\<in> cptn_mod_nest_call\"\nproof (induct rule:cptn_mod_nest_call.induct)\n  case (CptnModNestOne) thus ?case using cptn_mod_nest_call.CptnModNestOne by auto\nnext\n  case (CptnModNestEnv) thus ?case using cptn_mod_nest_call.CptnModNestEnv by fastforce\nnext\n   case (CptnModNestSkip) thus ?case using cptn_mod_nest_call.CptnModNestSkip by fastforce\nnext\n   case (CptnModNestThrow) thus ?case using cptn_mod_nest_call.intros(4)  by fastforce\nnext\n   case (CptnModNestCondT n) thus ?case \n     using cptn_mod_nest_call.CptnModNestCondT[of \"Suc n\"] by fastforce\nnext\n  case (CptnModNestCondF n) thus ?case \n    using cptn_mod_nest_call.CptnModNestCondF[of \"Suc n\"] by fastforce\nnext\n  case (CptnModNestSeq1 n) thus ?case \n    using cptn_mod_nest_call.CptnModNestSeq1[of \"Suc n\"] by fastforce\nnext\n  case (CptnModNestSeq2 n) thus ?case \n     using cptn_mod_nest_call.CptnModNestSeq2[of \"Suc n\"] by fastforce\nnext\n  case (CptnModNestSeq3 n) thus ?case \n     using cptn_mod_nest_call.CptnModNestSeq3[of \"Suc n\"] by fastforce\nnext\n  case (CptnModNestWhile1 n) thus ?case \n     using cptn_mod_nest_call.CptnModNestWhile1[of \"Suc n\"] by fastforce\nnext\n  case (CptnModNestWhile2 n) thus ?case \n     using cptn_mod_nest_call.CptnModNestWhile2[of \"Suc n\"] by fastforce\nnext\n  case (CptnModNestWhile3 n) thus ?case \n     using cptn_mod_nest_call.CptnModNestWhile3[of \"Suc n\"] by fastforce\nnext\n case (CptnModNestCall) thus ?case \n     using cptn_mod_nest_call.CptnModNestCall by fastforce\nnext \n case (CptnModNestDynCom) thus ?case \n     using cptn_mod_nest_call.CptnModNestDynCom by fastforce\nnext\n case (CptnModNestGuard n) thus ?case \n     using cptn_mod_nest_call.CptnModNestGuard[of \"Suc n\"] by fastforce\nnext\n case (CptnModNestCatch1 n) thus ?case \n     using cptn_mod_nest_call.CptnModNestCatch1[of \"Suc n\"] by fastforce\nnext\n case (CptnModNestCatch2 n) thus ?case \n     using cptn_mod_nest_call.CptnModNestCatch2[of \"Suc n\"] by fastforce\nnext\n case (CptnModNestCatch3 n) thus ?case \n     using cptn_mod_nest_call.CptnModNestCatch3[of \"Suc n\"] by fastforce\nqed\n\nlemma cptn_mod_nest_mono2: \n  \"(n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call  \\<Longrightarrow> m>n \\<Longrightarrow>\n   (m,\\<Gamma>,cfs)\\<in> cptn_mod_nest_call\"\nproof (induct \"m-n\" arbitrary: m n)\n  case 0 thus ?case by auto\nnext\n  case (Suc k) \n  have \"m - Suc n = k\"\n    using Suc.hyps(2) Suc.prems(2) Suc_diff_Suc Suc_inject by presburger\n  then show ?case\n    using Suc.hyps(1) Suc.prems(1) Suc.prems(2) cptn_mod_nest_mono1 less_Suc_eq by blast   \nqed\n\nlemma cptn_mod_nest_mono: \n  \"(n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call  \\<Longrightarrow> m\\<ge>n \\<Longrightarrow>\n   (m,\\<Gamma>,cfs)\\<in> cptn_mod_nest_call\"\nproof (cases \"n=m\")\n  assume \"(n, \\<Gamma>, cfs) \\<in> cptn_mod_nest_call\" and  \n          \"n = m\"  thus ?thesis by auto\nnext\n  assume \"(n, \\<Gamma>, cfs) \\<in> cptn_mod_nest_call\" and  \n         \"n\\<le>m\" and\n         \"n \\<noteq> m\"  \n   thus ?thesis by (auto simp add: cptn_mod_nest_mono2)\nqed\n\nsubsection \\<open>Lemmas on normalization\\<close>\n\n(* lemma step_sequence_flatten:\n  assumes exec: \"\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow> (Q,t)\" \n  shows \"\\<Gamma>\\<turnstile>\\<^sub>c(sequence Seq (flatten P),s) \\<rightarrow> (sequence Seq (flatten Q),t)\"\nusing exec\nproof (induct rule: stepc_induct)\n  case (Guardc s g f c) thus ?case using stepc.Guardc\n  case (Seqc c1 s c2 s' c2')\n  then have \" \\<Gamma>\\<turnstile>\\<^sub>c (Seq (LanguageCon.sequence LanguageCon.com.Seq (LanguageCon.flatten c1)) c2', s) \\<rightarrow>\n                   (Seq (LanguageCon.sequence LanguageCon.com.Seq (LanguageCon.flatten c2)) c2', s') \" \n    using stepc.Seqc by fastforce    \n  thus ?case sorry\nqed(auto intro:stepc.intros)+\n\nlemma normalice_step:\n  assumes exec:\"\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow> (Q,t)\" \n  shows  \"\\<Gamma>\\<turnstile>\\<^sub>c( normalizec P,s) \\<rightarrow> (normalizec Q,t)\"\nusing exec\nproof(induct rule:stepc_induct)\n  case (Catchc P s Q t c2)\n    thus ?case\n   *) \n(* qed(auto intro: stepc.intros) *)\n\nsubsection \\<open>Equivalence of comp mod semantics and comp mod nested\\<close>\n\ndefinition catch_cond_nest\nwhere\n\"catch_cond_nest zs Q xs P s s'' s' \\<Gamma> n \\<equiv> (zs=(map (lift_catch Q) xs) \\<or>\n             ((fst(((P, s)#xs)!length xs)=Throw \\<and>\n               snd(last ((P, s)#xs)) = Normal s' \\<and> s=Normal s''\\<and>\n               (\\<exists>ys. (n,\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod_nest_call \\<and> \n                zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n                ((fst(((P, s)#xs)!length xs)=Skip \\<and> \n                 (\\<exists>ys. (n,\\<Gamma>,(Skip,snd(last ((P, s)#xs)))#ys) \\<in> cptn_mod_nest_call \\<and>                   \n                 zs=(map (lift_catch Q) xs)@((Skip,snd(last ((P, s)#xs)))#ys)))))\n\"\n\nlemma div_catch_nest: assumes cptn_m:\"(n,\\<Gamma>,list) \\<in> cptn_mod_nest_call\"\nshows \"(\\<forall>s P Q zs. list=(Catch P Q, s)#zs \\<longrightarrow>\n       (\\<exists>xs s' s''. \n          (n, \\<Gamma>,(P, s)#xs) \\<in> cptn_mod_nest_call  \\<and> \n             catch_cond_nest zs Q xs P s s'' s' \\<Gamma> n))  \n            \"\nunfolding catch_cond_nest_def\nusing cptn_m\nproof (induct rule: cptn_mod_nest_call.induct)\ncase (CptnModNestOne \\<Gamma> P s)\n  thus ?case using cptn_mod_nest_call.CptnModNestOne by blast \nnext\n  case (CptnModNestSkip  \\<Gamma> P s t n xs) \n  from CptnModNestSkip.hyps\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow> (Skip, t)\" by auto\n  from CptnModNestSkip.hyps\n  have noskip: \"~(P=Skip)\" using stepc_elim_cases(1) by blast  \n  have no_catch: \"\\<forall>p1 p2. \\<not>(P=Catch p1 p2)\" using CptnModNestSkip.hyps(2) redex_not_Catch by auto\n  from CptnModNestSkip.hyps\n  have in_cptn_mod: \"(n,\\<Gamma>, (Skip, t) # xs) \\<in> cptn_mod_nest_call\" by auto  \n  then show ?case using no_catch by simp\nnext\n  case (CptnModNestThrow  \\<Gamma> P s t n xs) \n  from CptnModNestThrow.hyps\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow> (Throw, t)\" by auto \n  from CptnModNestThrow.hyps\n  have in_cptn_mod: \"(n,\\<Gamma>, (Throw, t) # xs) \\<in> cptn_mod_nest_call\" by auto \n  have no_catch: \"\\<forall>p1 p2. \\<not>(P=Catch p1 p2)\" using CptnModNestThrow.hyps(2) redex_not_Catch by auto\n  then show ?case by auto\nnext\n  case (CptnModNestCondT \\<Gamma> P0 s ys b P1)\n  thus ?case using CptnModOne by blast\nnext\n  case (CptnModNestCondF \\<Gamma> P0 s ys b P1)\n  thus ?case using CptnModOne by blast\nnext\n  case (CptnModNestCatch1 sa P Q zs)\n  thus ?case by blast\nnext\n  case (CptnModNestCatch2 n \\<Gamma> P0 s xs ys zs P1) \n  from CptnModNestCatch2.hyps(3) \n  have last:\"fst (((P0, s) # xs) ! length xs) = Skip\" \n       by (simp add: last_length) \n  have P0cptn:\"(n,\\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call\" by fact          \n  then have \"zs = map (lift_catch P1) xs @((Skip,snd(last ((P0, s)#xs)))#ys)\" by (simp add:CptnModNestCatch2.hyps)\n  show ?case\n  proof -{\n    fix sa P Q zsa    \n    assume eq:\"(Catch P0 P1, s) # zs = (Catch P Q, sa) # zsa\"\n    then have \"P0 =P \\<and> P1 = Q \\<and> s=sa \\<and> zs=zsa\" by auto\n    then have \"(P0, s) = (P, sa)\" by auto \n    have \"last ((P0, s) # xs) = ((P, sa) # xs) ! length xs\"\n      by (simp add: `P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa` last_length)\n    then have \"zs = (map (lift_catch Q) xs)@((Skip,snd(last ((P0, s)#xs)))#ys)\"\n      using `P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa` `zs = map (lift_catch P1) xs @ ((Skip,snd(last ((P0, s)#xs)))#ys)` \n      by force    \n    then have \"(\\<exists>xs s' s''. ((n,\\<Gamma>,(P, s)#xs) \\<in> cptn_mod_nest_call  \\<and> \n             ((zs=(map (lift_catch Q) xs) \\<or>\n             ((fst(((P, s)#xs)!length xs)=Throw \\<and>\n               snd(last ((P, s)#xs)) = Normal s' \\<and>  s=Normal s''\\<and>\n               (\\<exists>ys. (n,\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod_nest_call \\<and> \n                zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n                (\\<exists>ys. ((fst(((P, s)#xs)!length xs)=Skip \\<and> (n,\\<Gamma>,(Skip,snd(last ((P, s)#xs)))#ys) \\<in> cptn_mod_nest_call \\<and>                 \n                 zs=(map (lift_catch Q) xs)@((Skip,snd(last ((P0, s)#xs)))#ys))))))))\"\n    using P0cptn  `P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa`  last  CptnModNestCatch2.hyps(4) by blast \n   } \n   thus ?thesis by auto\n  qed\nnext\n  case (CptnModNestCatch3 n \\<Gamma> P0 s xs s' P1 ys zs)\n  from CptnModNestCatch3.hyps(3)  \n  have last:\"fst (((P0, Normal s) # xs) ! length xs) = Throw\" \n       by (simp add: last_length) \n  from CptnModNestCatch3.hyps(4) \n  have lastnormal:\"snd (last ((P0, Normal s) # xs)) = Normal s'\"\n      by (simp add: last_length)\n  have P0cptn:\"(n,\\<Gamma>, (P0, Normal s) # xs) \\<in> cptn_mod_nest_call\" by fact\n  from CptnModNestCatch3.hyps(5) \n    have P1cptn:\"(n,\\<Gamma>, (P1, snd (((P0, Normal s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call\"\n      by (simp add: last_length)          \n  then have \"zs = map (lift_catch P1) xs @ (P1, snd (last ((P0, Normal s) # xs))) # ys\" \n    by (simp add:CptnModNestCatch3.hyps)\n  show ?case\n  proof -{\n    fix sa P Q zsa    \n    assume eq:\"(Catch P0 P1, Normal s) # zs = (Catch P Q, Normal sa) # zsa\"\n    then have \"P0 =P \\<and> P1 = Q \\<and> Normal s= Normal sa \\<and> zs=zsa\" by auto     \n    have \"last ((P0, Normal s) # xs) = ((P, Normal sa) # xs) ! length xs\"\n      by (simp add: `P0 = P \\<and> P1 = Q \\<and> Normal s = Normal sa \\<and> zs = zsa` last_length)\n    then have \"zsa = map (lift_catch Q) xs @ (Q, snd (((P, Normal sa) # xs) ! length xs)) # ys\"\n      using `P0 = P \\<and> P1 = Q \\<and> Normal s = Normal sa \\<and> zs = zsa` `zs = map (lift_catch P1) xs @ (P1, snd (last ((P0, Normal s) # xs))) # ys` by force\n    then have \"(n,\\<Gamma>, (P, Normal s) # xs) \\<in> cptn_mod_nest_call \\<and> (fst(((P, Normal s)#xs)!length xs)=Throw \\<and>\n               snd(last ((P, Normal s)#xs)) = Normal s' \\<and> \n              (\\<exists>ys. (n,\\<Gamma>,(Q, snd(((P, Normal s)#xs)!length xs))#ys) \\<in> cptn_mod_nest_call \\<and> \n              zs=(map (lift_catch Q) xs)@((Q, snd(((P, Normal s)#xs)!length xs))#ys)))\" \n      using lastnormal P1cptn P0cptn `P0 = P \\<and> P1 = Q \\<and> Normal s = Normal sa \\<and> zs = zsa` last \n       by auto    \n    }note this [of P0 P1 s zs] thus ?thesis by blast qed\nnext\n  case (CptnModNestEnv \\<Gamma> P s t n xs)  \n  then have step:\"(n, \\<Gamma>, (P, t) # xs) \\<in> cptn_mod_nest_call\" by auto  \n  have step_e: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow>\\<^sub>e (P, t)\" using CptnModNestEnv by auto\n  show ?case     \n    proof (cases P)\n      case (Catch P1 P2) \n      then have eq_P_Catch:\"(P, t) # xs = (LanguageCon.com.Catch P1 P2, t) # xs\" by auto      \n      then  obtain xsa t' t'' where \n         p1:\"(n,\\<Gamma>, (P1, t) # xsa) \\<in> cptn_mod_nest_call\" and \n        p2:\" (xs = map (lift_catch P2) xsa \\<or>\n            fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \\<and>\n            snd (last ((P1, t) # xsa)) = Normal t' \\<and>\n            t = Normal t'' \\<and>\n            (\\<exists>ys. (n,\\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<in> cptn_mod_nest_call \\<and>\n              xs = map (lift_catch P2) xsa @ (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<or>\n                fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Skip \\<and>\n                (\\<exists>ys.(n,\\<Gamma>,(Skip,snd(last ((P1, t)#xsa)))#ys) \\<in> cptn_mod_nest_call \\<and> \n                xs = map (lift_catch P2) xsa @\n                ((LanguageCon.com.Skip, snd (last ((P1, t) # xsa)))#ys)))\" \n        using CptnModNestEnv(3) by auto\n      have all_step:\"(n,\\<Gamma>, (P1, s)#((P1, t) # xsa)) \\<in> cptn_mod_nest_call\"\n        using p1 Env Env_n cptn_mod.CptnModEnv env_normal_s step_e\n      proof -\n        have f1: \"SmallStepCon.redex P = SmallStepCon.redex P1\"\n          using local.Catch by auto\n        obtain bb :: \"('b, 'c) xstate \\<Rightarrow> 'b\" where\n          \"\\<forall>x2. (\\<exists>v5. x2 = Normal v5) = (x2 = Normal (bb x2))\"\n          by moura\n        then have \"s = t \\<or> s = Normal (bb s)\"\n          by (metis (no_types) env_normal_s step_e)\n        then show ?thesis\n          using f1 by (metis (no_types) Env Env_n cptn_mod_nest_call.CptnModNestEnv p1)\n      qed\n      show ?thesis using p2 \n      proof  \n        assume \"xs = map (lift_catch P2) xsa\"\n        have \"(P, t) # xs = map (lift_catch P2) ((P1, t) # xsa)\"\n          by (simp add: `xs = map (lift_catch P2) xsa` lift_catch_def local.Catch)\n        thus ?thesis using all_step eq_P_Catch by fastforce\n      next \n        assume \n         \"fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \\<and>\n          snd (last ((P1, t) # xsa)) = Normal t' \\<and>\n          t = Normal t'' \\<and>\n          (\\<exists>ys. (n,\\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<in> cptn_mod_nest_call \\<and>\n                xs =\n                map (lift_catch P2) xsa @\n                (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<or>\n                fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Skip \\<and>\n           (\\<exists>ys. (n,\\<Gamma>,(Skip,snd(last ((P1, t)#xsa)))#ys) \\<in> cptn_mod_nest_call \\<and> \n            xs = map (lift_catch P2) xsa @\n            ((LanguageCon.com.Skip, snd (last ((P1, t) # xsa)))#ys))\"      \n         then show ?thesis \n         proof\n           assume \n            a1:\"fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Throw \\<and>\n             snd (last ((P1, t) # xsa)) = Normal t' \\<and>\n             t = Normal t'' \\<and>\n             (\\<exists>ys. (n,\\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<in> cptn_mod_nest_call \\<and>\n                xs = map (lift_catch P2) xsa @\n                       (P2, snd (((P1, t) # xsa) ! length xsa)) # ys)\"\n            then obtain ys where p2_exec:\"(n,\\<Gamma>, (P2, snd (((P1, t) # xsa) ! length xsa)) # ys) \\<in> cptn_mod_nest_call \\<and>\n                xs = map (lift_catch P2) xsa @\n                       (P2, snd (((P1, t) # xsa) ! length xsa)) # ys\" \n            by fastforce\n            from a1 obtain t1 where t_normal: \"t=Normal t1\" \n              using env_normal_s'_normal_s by blast\n            have f1:\"fst (((P1, s)#(P1, t) # xsa) ! length ((P1, t)#xsa)) = LanguageCon.com.Throw\"\n              using a1 by fastforce\n             from a1 have last_normal: \"snd (last ((P1, s)#(P1, t) # xsa)) = Normal t'\"\n               by fastforce \n             then have p2_long_exec: \"(n,\\<Gamma>, (P2, snd (((P1, s)#(P1, t) # xsa) ! length ((P1, s)#xsa))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                (P, t)#xs = map (lift_catch P2) ((P1, t) # xsa) @\n                       (P2, snd (((P1, s)#(P1, t) # xsa) ! length ((P1, s)#xsa))) # ys\" using p2_exec \n                by (simp add: lift_catch_def local.Catch)                  \n             thus ?thesis using  a1 f1 last_normal all_step eq_P_Catch \n               by (clarify, metis (no_types) list.size(4) not_step_c_env  step_e)            \n           next\n           assume \n            as1:\"fst (((P1, t) # xsa) ! length xsa) = LanguageCon.com.Skip \\<and>\n           (\\<exists>ys. (n,\\<Gamma>,(Skip,snd(last ((P1, t)#xsa)))#ys) \\<in> cptn_mod_nest_call \\<and> \n            xs = map (lift_catch P2) xsa @\n            ((LanguageCon.com.Skip, snd (last ((P1, t) # xsa)))#ys))\"               \n            then obtain ys where p1:\"(n,\\<Gamma>,(Skip,snd(last ((P1, t)#xsa)))#ys) \\<in> cptn_mod_nest_call \\<and> \n                         (P, t)#xs = map (lift_catch P2) ((P1, t) # xsa) @\n                          ((LanguageCon.com.Skip, snd (last ((P1, t) # xsa)))#ys)\"\n            proof -\n              assume a1: \"\\<And>ys. (n,\\<Gamma>, (LanguageCon.com.Skip, snd (last ((P1, t) # xsa))) # ys) \\<in> cptn_mod_nest_call \\<and> \n                         (P, t) # xs = map (lift_catch P2) ((P1, t) # xsa) @ \n                         (LanguageCon.com.Skip, snd (last ((P1, t) # xsa))) # ys \\<Longrightarrow> \n                         thesis\"\n              have \"(LanguageCon.com.Catch P1 P2, t) # map (lift_catch P2) xsa = map (lift_catch P2) ((P1, t) # xsa)\"\n                by (simp add: lift_catch_def)\n              thus ?thesis\n                using a1 as1 eq_P_Catch by moura\n            qed            \n            from as1 have p2: \"fst (((P1, s)#(P1, t) # xsa) ! length ((P1, t) #xsa)) = LanguageCon.com.Skip\"\n                 by fastforce                              \n            thus ?thesis using p1 all_step eq_P_Catch by fastforce\n          qed\n      qed\n    qed (auto)\nqed(force+)\n\n\ndefinition seq_cond_nest\nwhere\n\"seq_cond_nest zs Q xs P s s'' s' \\<Gamma> n \\<equiv> (zs=(map (lift Q) xs) \\<or>\n             ((fst(((P, s)#xs)!length xs)=Skip \\<and> \n               (\\<exists>ys. (n,\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod_nest_call \\<and> \n                zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n             ((fst(((P, s)#xs)!length xs)=Throw \\<and> \n                 snd(last ((P, s)#xs)) = Normal s' \\<and>  s=Normal s''\\<and>\n                 (\\<exists>ys.  (n,\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod_nest_call \\<and>\n                      zs=(map (lift Q) xs)@((Throw,Normal s')#ys)))))\n\"\n\nlemma div_seq_nest: assumes cptn_m:\"(n,\\<Gamma>,list) \\<in> cptn_mod_nest_call\"\nshows \"(\\<forall>s P Q zs. list=(Seq P Q, s)#zs \\<longrightarrow>\n       (\\<exists>xs s' s''. \n          (n,\\<Gamma>,(P, s)#xs) \\<in> cptn_mod_nest_call  \\<and> \n             seq_cond_nest zs Q xs P s s'' s' \\<Gamma> n))  \n            \"\nunfolding seq_cond_nest_def\nusing cptn_m\nproof (induct rule: cptn_mod_nest_call.induct)\n  case (CptnModNestOne \\<Gamma> P s)\n  thus ?case using cptn_mod_nest_call.CptnModNestOne \n   by blast\nnext\n  case (CptnModNestSkip  \\<Gamma> P s t n xs) \n  from CptnModNestSkip.hyps\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow> (Skip, t)\" by auto\n  from CptnModNestSkip.hyps\n  have noskip: \"~(P=Skip)\" using stepc_elim_cases(1) by blast  \n  have x: \"\\<forall>c c1 c2. redex c = Seq c1 c2 \\<Longrightarrow> False\"\n          using redex_not_Seq by blast\n  from CptnModNestSkip.hyps\n  have in_cptn_mod: \"(n,\\<Gamma>, (Skip, t) # xs) \\<in> cptn_mod_nest_call\" by auto  \n  then show ?case using CptnModNestSkip.hyps(2) SmallStepCon.redex_not_Seq by blast\nnext\n  case (CptnModNestThrow  \\<Gamma> P s t xs)\n  from CptnModNestThrow.hyps\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow> (Throw, t)\" by auto \n  moreover from CptnModNestThrow.hyps \n  have no_seq: \"\\<forall>p1 p2. \\<not>(P=Seq p1 p2)\" using CptnModNestThrow.hyps(2) redex_not_Seq by auto\n  ultimately show ?case by auto   \nnext \n  case (CptnModNestCondT \\<Gamma> P0 s ys b P1)\n  thus ?case by auto\nnext\n  case (CptnModNestCondF \\<Gamma> P0 s ys b P1)\n  thus ?case by auto\nnext\n  case (CptnModNestSeq1 n \\<Gamma> P0 s xs zs P1) thus ?case \n    by blast   \nnext \n  case (CptnModNestSeq2 n \\<Gamma> P0 s xs P1 ys zs) \n  from CptnModNestSeq2.hyps(3) last_length have last:\"fst (((P0, s) # xs) ! length xs) = Skip\" \n       by (simp add: last_length) \n  have P0cptn:\"(n,\\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call\" by fact\n  from CptnModNestSeq2.hyps(4) have P1cptn:\"(n,\\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call\"\n      by (simp add: last_length)          \n  then have \"zs = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys\" by (simp add:CptnModNestSeq2.hyps)\n  show ?case\n  proof -{\n    fix sa P Q zsa    \n    assume eq:\"(Seq P0 P1, s) # zs = (Seq P Q, sa) # zsa\"\n    then have \"P0 =P \\<and> P1 = Q \\<and> s=sa \\<and> zs=zsa\" by auto \n     have \"last ((P0, s) # xs) = ((P, sa) # xs) ! length xs\"\n            by (simp add: `P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa` last_length)\n    then have \"zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys\"\n         using `P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa` `zs = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys` \n         by force    \n    then have \"(\\<exists>xs s' s''. (n,\\<Gamma>, (P, sa) # xs) \\<in> cptn_mod_nest_call \\<and>\n                        (zsa = map (lift Q) xs \\<or>              \n                         fst (((P, sa) # xs) ! length xs) = Skip \\<and>\n                             (\\<exists>ys. (n,\\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n                             zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<or>\n                        ((fst(((P, sa)#xs)!length xs)=Throw \\<and> \n                          snd(last ((P, sa)#xs)) = Normal s' \\<and>  s=Normal s''\\<and>\n                         (\\<exists>ys. (n,\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod_nest_call \\<and>\n                               zsa=(map (lift Q) xs)@((Throw,Normal s')#ys))))))\n               \" \n        using P0cptn P1cptn  `P0 = P \\<and> P1 = Q \\<and> s = sa \\<and> zs = zsa` last \n        by blast                 \n   }  \n   thus ?case by auto qed     \nnext\n  case (CptnModNestSeq3 n \\<Gamma> P0 s xs s' ys zs P1) \n  from CptnModNestSeq3.hyps(3) \n  have last:\"fst (((P0, Normal s) # xs) ! length xs) = Throw\" \n       by (simp add: last_length) \n  have P0cptn:\"(n,\\<Gamma>, (P0, Normal s) # xs) \\<in> cptn_mod_nest_call\" by fact\n  from CptnModNestSeq3.hyps(4) \n  have lastnormal:\"snd (last ((P0, Normal s) # xs)) = Normal s'\"\n      by (simp add: last_length)          \n  then have \"zs = map (lift P1) xs @ ((Throw, Normal s')#ys)\" by (simp add:CptnModNestSeq3.hyps)\n  show ?case\n  proof -{\n    fix sa P Q zsa    \n    assume eq:\"(Seq P0 P1, Normal s) # zs = (Seq P Q, Normal sa) # zsa\"\n    then have \"P0 =P \\<and> P1 = Q \\<and> Normal s=Normal sa \\<and> zs=zsa\" by auto\n    then have \"(P0, Normal s) = (P, Normal sa)\" by auto \n    have \"last ((P0, Normal s) # xs) = ((P, Normal sa) # xs) ! length xs\"\n                    by (simp add: `P0 = P \\<and> P1 = Q \\<and> Normal s = Normal sa \\<and> zs = zsa` last_length)\n    then have zsa:\"zsa = (map (lift Q) xs)@((Throw,Normal s')#ys)\"\n                    using `P0 = P \\<and> P1 = Q \\<and> Normal s = Normal sa \\<and> zs = zsa` `zs = map (lift P1) xs @ ((Throw, Normal s')#ys)` \n    by force\n    then have a1:\"(n,\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod_nest_call\" using CptnModNestSeq3.hyps(5) by blast               \n     have \"(P, Normal sa::('b, 'c) xstate) = (P0, Normal s)\"\n    using `P0 = P \\<and> P1 = Q \\<and> Normal s = Normal sa \\<and> zs = zsa` by auto  \n    then have \"(\\<exists>xs s'. (n,\\<Gamma>, (P, Normal sa) # xs) \\<in> cptn_mod_nest_call \\<and>\n                        (zsa = map (lift Q) xs \\<or>              \n                         fst (((P,Normal sa) # xs) ! length xs) = Skip \\<and>\n                             (\\<exists>ys. (n,\\<Gamma>, (Q, snd (((P, Normal sa) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n                             zsa = map (lift Q) xs @ (Q, snd (((P, Normal sa) # xs) ! length xs)) # ys) \\<or>\n                        ((fst(((P, Normal sa)#xs)!length xs)=Throw \\<and> \n                          snd(last ((P, Normal sa)#xs)) = Normal s' \\<and>\n                          (\\<exists>ys. (n,\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod_nest_call \\<and>\n                          zsa=(map (lift Q) xs)@((Throw,Normal s')#ys))))))\"\n     using P0cptn zsa a1 last lastnormal \n       by blast \n   }  \n   thus ?thesis by auto qed  \nnext \n  case (CptnModNestEnv  \\<Gamma> P s t n zs) \n  then have step:\"(n,\\<Gamma>, (P, t) # zs) \\<in> cptn_mod_nest_call\" by auto\n  have step_e: \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow>\\<^sub>e (P, t)\" using CptnModNestEnv by auto  \n  show ?case     \n    proof (cases P)\n      case (Seq P1 P2) \n      then have eq_P:\"(P, t) # zs = (LanguageCon.com.Seq P1 P2, t) # zs\" by auto      \n      then  obtain xs t' t'' where \n         p1:\"(n,\\<Gamma>, (P1, t) # xs) \\<in> cptn_mod_nest_call\" and p2:\"\n     (zs = map (lift P2) xs \\<or>\n      fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \\<and>      \n      (\\<exists>ys. (n,\\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n            zs =\n            map (lift P2) xs @\n            (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<or>\n      fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n      snd (last ((P1, t) # xs)) = Normal t' \\<and>\n      t = Normal t'' \\<and> (\\<exists>ys. (n,\\<Gamma>,(Throw,Normal t')#ys) \\<in> cptn_mod_nest_call \\<and> \n      zs =\n      map (lift P2) xs @\n      ((LanguageCon.com.Throw, Normal t')#ys))) \" \n        using CptnModNestEnv(3) by auto\n      have all_step:\"(n,\\<Gamma>, (P1, s)#((P1, t) # xs)) \\<in> cptn_mod_nest_call\" \n        using p1 Env Env_n cptn_mod_nest_call.CptnModNestEnv env_normal_s step_e\n      proof -\n        have \"SmallStepCon.redex P = SmallStepCon.redex P1\"\n          by (metis SmallStepCon.redex.simps(4) local.Seq)\n        then show ?thesis\n          by (metis (no_types) Env Env_n cptn_mod_nest_call.CptnModNestEnv env_normal_s p1 step_e)\n      qed             \n      show ?thesis using p2 \n      proof  \n        assume \"zs = map (lift P2) xs\"\n        have \"(P, t) # zs = map (lift P2) ((P1, t) # xs)\"\n          by (simp add: `zs = map (lift P2) xs` lift_def local.Seq)\n        thus ?thesis using all_step eq_P by fastforce\n      next \n        assume \n         \"fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \\<and>      \n         (\\<exists>ys. (n,\\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n            zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<or>\n          fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n           snd (last ((P1, t) # xs)) = Normal t' \\<and>\n           t = Normal t'' \\<and> (\\<exists>ys. (n,\\<Gamma>,(Throw,Normal t')#ys) \\<in> cptn_mod_nest_call \\<and> \n           zs = map (lift P2) xs @ ((LanguageCon.com.Throw, Normal t')#ys))\"\n         then show ?thesis \n         proof\n           assume \n            a1:\"fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Skip \\<and>      \n               (\\<exists>ys. (n,\\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n               zs = map (lift P2) xs @ (P2, snd (((P1, t) # xs) ! length xs)) # ys)\"\n               from a1 obtain ys where \n                   p2_exec:\"(n,\\<Gamma>, (P2, snd (((P1, t) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n                       zs = map (lift P2) xs @\n                       (P2, snd (((P1, t) # xs) ! length xs)) # ys\" \n                by auto \n               have f1:\"fst (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs)) = LanguageCon.com.Skip\"\n                 using a1 by fastforce             \n               then have p2_long_exec: \n                 \"(n,\\<Gamma>, (P2, snd (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                  (P, t)#zs = map (lift P2) ((P1, t) # xs) @\n                       (P2, snd (((P1, s)#(P1, t) # xs) ! length ((P1, t)#xs))) # ys\" \n             using p2_exec by (simp add: lift_def local.Seq)     \n             thus ?thesis using a1 f1 all_step eq_P by blast            \n           next\n           assume \n            a1:\"fst (((P1, t) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n            snd (last ((P1, t) # xs)) = Normal t' \\<and> t = Normal t'' \\<and> \n          (\\<exists>ys. (n,\\<Gamma>,(Throw,Normal t')#ys) \\<in> cptn_mod_nest_call \\<and> \n           zs = map (lift P2) xs @ ((LanguageCon.com.Throw, Normal t')#ys))\"             \n             then have last_throw:\n               \"fst (((P1, s)#(P1, t) # xs) ! length ((P1, t) #xs)) = LanguageCon.com.Throw\" \n               by fastforce\n             from a1 have last_normal: \"snd (last ((P1, s)#(P1, t) # xs)) = Normal t'\"\n               by fastforce\n             have seq_lift:\n               \"(LanguageCon.com.Seq P1 P2, t) # map (lift P2) xs = map (lift P2) ((P1, t) # xs)\"\n                by (simp add: a1 lift_def)             \n            thus  ?thesis using a1 last_throw last_normal all_step eq_P         \n              by (clarify, metis (no_types, lifting) append_Cons env_normal_s'_normal_s  step_e)                 \n          qed\n      qed\n    qed (auto) \nqed (force)+\n\nlemma map_lift_eq_xs_xs':\"map (lift a) xs = map (lift a) xs' \\<Longrightarrow> xs=xs'\" \nproof (induct xs arbitrary: xs')\n  case Nil thus ?case by auto\nnext\n  case (Cons x xsa)\n  then have a0:\"(lift a) x # map (lift a) xsa = map (lift a) (x # xsa)\"\n    by fastforce \n  also obtain x' xsa' where xs':\"xs' = x'#xsa'\" \n    using Cons by auto\n  ultimately have a1:\"map (lift a) (x # xsa) =map (lift a) (x' # xsa')\"\n    using Cons by auto\n  then have xs:\"xsa=xsa'\" using a0 a1 Cons by fastforce\n  then have \"(lift a) x' = (lift a) x\" using a0 a1  by auto\n  then have \"x' = x\" unfolding lift_def\n    by (metis (no_types, lifting) LanguageCon.com.inject(3) \n               case_prod_beta old.prod.inject prod.collapse)   \n  thus ?case using xs xs' by auto\nqed\n\nlemma map_lift_catch_eq_xs_xs':\"map (lift_catch a) xs = map (lift_catch a) xs' \\<Longrightarrow> xs=xs'\" \nproof (induct xs arbitrary: xs')\n  case Nil thus ?case by auto\nnext\n  case (Cons x xsa)\n  then have a0:\"(lift_catch a) x # map (lift_catch a) xsa = map (lift_catch a) (x # xsa)\"\n    by auto \n  also obtain x' xsa' where xs':\"xs' = x'#xsa'\" \n    using Cons by auto\n  ultimately have a1:\"map (lift_catch a) (x # xsa) =map (lift_catch a) (x' # xsa')\"\n    using Cons by auto  \n  then have xs:\"xsa=xsa'\" using a0 a1 Cons by fastforce  \n  then have \"(lift_catch a) x' = (lift_catch a) x\" using a0 a1  by auto\n  then have \"x' = x\" unfolding lift_catch_def\n    by (metis (no_types, lifting) LanguageCon.com.inject(9) \n               case_prod_beta old.prod.inject prod.collapse)   \n  thus ?case using xs xs' by auto\nqed\n\nlemma map_lift_all_seq:\n assumes a0:\"zs=map (lift a) xs\" and\n         a1:\"i<length zs\"\n shows \"\\<exists>b. fst (zs!i) = Seq b a\"\nusing a0 a1\nproof (induct zs arbitrary: xs i)\n  case Nil thus ?case by auto\nnext\n  case (Cons z1 zsa) thus ?case unfolding lift_def\n  proof -\n    assume a1: \"z1 # zsa = map (\\<lambda>b. case b of (P, s) \\<Rightarrow> (LanguageCon.com.Seq P a, s)) xs\"\n    have \"\\<forall>p c. \\<exists>x. \\<forall>pa ca xa. \n            (pa \\<noteq> (ca::('a, 'b, 'c, 'd) LanguageCon.com, xa::('a, 'c) xstate) \\<or> ca = fst pa) \\<and> \n            ((c::('a, 'b, 'c, 'd) LanguageCon.com) \\<noteq> fst p \\<or> (c, x::('a, 'c) xstate) = p)\"\n      by fastforce\n    then obtain xx :: \"('a, 'b, 'c, 'd) LanguageCon.com \\<times> ('a, 'c) xstate \\<Rightarrow> ('a, 'b, 'c, 'd) LanguageCon.com \\<Rightarrow> ('a, 'c) xstate\" where\n      \"\\<And>p c x ca pa. (p \\<noteq> (c::('a, 'b, 'c, 'd) LanguageCon.com, x::('a, 'c) xstate) \\<or> c = fst p) \\<and> (ca \\<noteq> fst pa \\<or> (ca, xx pa ca) = pa)\"\n      by (metis (full_types))  \n    then show ?thesis\n      using a1 \\<open>i < length (z1 # zsa)\\<close>\n      by (simp add: Cons.hyps Cons.prems(1) case_prod_beta')\n  qed\nqed\n\nlemma map_lift_catch_all_catch:\n assumes a0:\"zs=map (lift_catch a) xs\" and\n         a1:\"i<length zs\"\n shows \"\\<exists>b. fst (zs!i) = Catch b a\"\nusing a0 a1\nproof (induct zs arbitrary: xs i)\n  case Nil thus ?case by auto\nnext\n  case (Cons z1 zsa) thus ?case unfolding lift_catch_def\n  proof -\n    assume a1: \"z1 # zsa = map (\\<lambda>b. case b of (P, s) \\<Rightarrow> (LanguageCon.com.Catch P a, s)) xs\"\n    have \"\\<forall>p c. \\<exists>x. \\<forall>pa ca xa. \n            (pa \\<noteq> (ca::('a, 'b, 'c, 'd) LanguageCon.com, xa::('a, 'c) xstate) \\<or> ca = fst pa) \\<and> \n            ((c::('a, 'b, 'c, 'd) LanguageCon.com) \\<noteq> fst p \\<or> (c, x::('a, 'c) xstate) = p)\"\n      by fastforce\n    then obtain xx :: \"('a, 'b, 'c, 'd) LanguageCon.com \\<times> ('a, 'c) xstate \\<Rightarrow> ('a, 'b, 'c, 'd) LanguageCon.com \\<Rightarrow> ('a, 'c) xstate\" where\n      \"\\<And>p c x ca pa. (p \\<noteq> (c::('a, 'b, 'c, 'd) LanguageCon.com, x::('a, 'c) xstate) \\<or> c = fst p) \\<and> (ca \\<noteq> fst pa \\<or> (ca, xx pa ca) = pa)\"\n      by (metis (full_types))  \n    then show ?thesis\n      using a1 \\<open>i < length (z1 # zsa)\\<close>\n      by (simp add: Cons.hyps Cons.prems(1) case_prod_beta')\n  qed\nqed\n\nlemma map_lift_some_eq_pos:\n assumes a0:\"map (lift P) xs @ (P1, s1)#ys = \n             map (lift P) xs'@ (P2, s2)#ys'\" and\n         a1:\"\\<forall>p0. P1\\<noteq>Seq p0 P\" and\n         a2:\"\\<forall>p0. P2\\<noteq>Seq p0 P\" \n shows \"length xs = length xs'\"\nproof -\n  {assume ass:\"length xs \\<noteq> length xs'\"\n   { assume ass:\"length xs < length xs'\"\n     then have False using a0  map_lift_all_seq a1 a2\n     by (metis (no_types, lifting) fst_conv length_map nth_append nth_append_length)\n   }note l=this\n   { assume ass:\"length xs > length xs'\"\n     then have False using a0  map_lift_all_seq a1 a2\n     by (metis (no_types, lifting) fst_conv length_map nth_append nth_append_length)\n   }  then have False using l ass by fastforce\n  }\n  thus ?thesis by auto\nqed\n\nlemma map_lift_some_eq:\n assumes a0:\"map (lift P) xs @ (P1, s1)#ys = \n             map (lift P) xs'@ (P2, s2)#ys'\" and\n        a1:\"\\<forall>p0. P1\\<noteq>Seq p0 P\" and\n        a2:\"\\<forall>p0. P2\\<noteq>Seq p0 P\" \n shows \"xs' = xs \\<and> ys = ys'\"\nproof -\n  have \"length xs = length xs'\" using a0 map_lift_some_eq_pos a1 a2 by blast\n  also have \"xs' = xs\" using a0 assms calculation map_lift_eq_xs_xs' by fastforce\n  ultimately show ?thesis using a0 by fastforce\nqed\n\nlemma map_lift_catch_some_eq_pos:\n assumes a0:\"map (lift_catch P) xs @ (P1, s1)#ys = \n             map (lift_catch P) xs'@ (P2, s2)#ys'\" and\n         a1:\"\\<forall>p0. P1\\<noteq>Catch p0 P\" and\n         a2:\"\\<forall>p0. P2\\<noteq>Catch p0 P\" \n shows \"length xs = length xs'\"\nproof -\n  {assume ass:\"length xs \\<noteq> length xs'\"\n   { assume ass:\"length xs < length xs'\"\n     then have False using a0  map_lift_catch_all_catch a1 a2\n     by (metis (no_types, lifting) fst_conv length_map nth_append nth_append_length)\n   }note l=this\n   { assume ass:\"length xs > length xs'\"\n     then have False using a0  map_lift_catch_all_catch a1 a2\n     by (metis (no_types, lifting) fst_conv length_map nth_append nth_append_length)\n   }  then have False using l ass by fastforce\n  }\n  thus ?thesis by auto\nqed\n\nlemma map_lift_catch_some_eq:\n assumes a0:\"map (lift_catch P) xs @ (P1, s1)#ys = \n             map (lift_catch P) xs'@ (P2, s2)#ys'\" and\n        a1:\"\\<forall>p0. P1\\<noteq>Catch p0 P\" and\n        a2:\"\\<forall>p0. P2\\<noteq>Catch p0 P\" \n shows \"xs' = xs \\<and> ys = ys'\"\nproof -\n  have \"length xs = length xs'\" using a0 map_lift_catch_some_eq_pos a1 a2 by blast\n  also have \"xs' = xs\" using a0 assms calculation map_lift_catch_eq_xs_xs' by fastforce\n  ultimately show ?thesis using a0 by fastforce\nqed\n\n\nlemma Seq_P_Not_finish:\n assumes\n   a0:\"zs = map (lift Q) xs\" and\n   a1:\"(m, \\<Gamma>,(LanguageCon.com.Seq P Q, s) # zs) \\<in> cptn_mod_nest_call\" and\n   a2:\"seq_cond_nest zs Q xs' P s s'' s' \\<Gamma> m\" \nshows \"xs=xs'\"\nusing a2 unfolding seq_cond_nest_def \nproof\n  assume \"zs= map (lift Q) xs'\"\n  then have  \"map (lift Q) xs' = \n              map (lift Q) xs\" using a0 by auto \n  thus ?thesis using map_lift_eq_xs_xs' by fastforce\nnext\n  assume \n    ass:\"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<or>\n         fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n         snd (last ((P, s) # xs')) = Normal s' \\<and>\n         s = Normal s'' \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift Q) xs' @ (LanguageCon.com.Throw, Normal s') # ys)\"\n   {assume \n     ass:\"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \\<and>\n        (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)\"\n      then obtain ys where \n         zs:\"zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys\" \n             by auto \n      then have zs_while:\"fst (zs!(length (map (lift Q) xs'))) =\n                   Q\"  by (metis fstI nth_append_length) \n      have \"length zs = length (map (lift Q) xs' @\n         (Q, snd (((P, s) # xs') ! length xs')) # ys)\" \n          using zs by auto\n      then have \"(length (map (lift Q) xs')) < \n                  length zs\" by auto       \n      then have ?thesis using a0 zs_while map_lift_all_seq\n         using seq_and_if_not_eq(4) by fastforce     \n   }note l = this\n   {assume ass:\"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n         snd (last ((P, s) # xs')) = Normal s' \\<and>\n         s = Normal s'' \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift Q) xs' @ (LanguageCon.com.Throw, Normal s') # ys)\"\n      then obtain ys where \n            zs:\"zs = map (lift Q) xs' @ \n                 (LanguageCon.com.Throw, Normal s') # ys\" by auto\n      then have zs_while:\n          \"fst (zs!(length (map (lift Q) xs'))) = Throw\"  by (metis fstI nth_append_length) \n       have \"length zs = length (map (lift Q) xs' @(LanguageCon.com.Throw, Normal s') # ys)\" \n           using zs by auto\n       then have \"(length (map (lift Q) xs')) < \n                  length zs\" by auto       \n       then have ?thesis using a0 zs_while map_lift_all_seq\n         using seq_and_if_not_eq(4) by fastforce\n   } thus ?thesis using l ass by auto\nqed\n\nlemma Seq_P_Ends_Normal:\n assumes\n   a0:\"zs = map (lift Q) xs @ (Q, snd (last ((P, s) # xs))) # ys\" and\n   a0':\"fst (last ((P, s) # xs)) = Skip\" and\n   a1:\"(m, \\<Gamma>,(LanguageCon.com.Seq P Q, s) # zs) \\<in> cptn_mod_nest_call\" and\n   a2:\"seq_cond_nest zs Q xs' P s s'' s' \\<Gamma> m\" \nshows \"xs=xs' \\<and> (m,\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod_nest_call\"\nusing a2 unfolding seq_cond_nest_def \nproof\n  assume ass:\"zs= map (lift Q) xs'\"\n  then have  \"map (lift Q) xs' = \n              map (lift Q) xs @ (Q, snd (last ((P, s) # xs))) # ys\" using a0 by auto \n  then have zs_while:\"fst (zs!(length (map (lift Q) xs))) = Q\"  \n    by (metis a0 fstI nth_append_length) \n  also have \"length zs = \n             length (map (lift Q) xs @ (Q, snd (last ((P, s) # xs))) # ys)\" \n    using a0 by auto\n  then have \"(length (map (lift Q) xs)) < length zs\" by auto       \n  then show ?thesis using ass zs_while map_lift_all_seq\n           using seq_and_if_not_eq(4)\n  by metis   \nnext\n  assume \n    ass:\"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<or>\n         fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n         snd (last ((P, s) # xs')) = Normal s' \\<and>\n         s = Normal s'' \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift Q) xs' @ (LanguageCon.com.Throw, Normal s') # ys)\"\n   {assume \n     ass:\"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \\<and>\n        (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)\"\n      then obtain ys' where \n         zs:\"zs = map (lift Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys' \\<and>\n             (m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys') \\<in> cptn_mod_nest_call\" \n             by auto \n      then have ?thesis\n        using  map_lift_some_eq[of Q xs Q _ ys xs' Q _ ys'] \n               zs  a0 seq_and_if_not_eq(4)[of Q] \n        by auto               \n   }note l = this\n   {assume ass:\"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n         snd (last ((P, s) # xs')) = Normal s' \\<and>\n         s = Normal s'' \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift Q) xs' @ (LanguageCon.com.Throw, Normal s') # ys)\"\n      then obtain ys' where \n         zs:\"zs = map (lift Q) xs' @ (LanguageCon.com.Throw, Normal s') # ys' \\<and>\n             (m, \\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys') \\<in> cptn_mod_nest_call\" \n         by auto\n      then have zs_while:\n          \"fst (zs!(length (map (lift Q) xs'))) = Throw\"  by (metis fstI nth_append_length)       \n      have False\n        by (metis (no_types) LanguageCon.com.distinct(17) \n              LanguageCon.com.distinct(71) \n              a0 a0' ass last_length\n              map_lift_some_eq seq_and_if_not_eq(4) zs)\n      then have ?thesis\n        by metis\n   } thus ?thesis using l ass by auto\nqed\n\nlemma Seq_P_Ends_Abort:\n assumes\n   a0:\"zs = map (lift Q) xs @ (Throw, Normal s') # ys\" and\n   a0':\"fst (last ((P, Normal s) # xs)) = Throw\" and\n   a0'':\"snd(last ((P, Normal s) # xs)) = Normal s'\" and\n   a1:\"(m, \\<Gamma>,(LanguageCon.com.Seq P Q, Normal s) # zs) \\<in> cptn_mod_nest_call\" and\n   a2:\"seq_cond_nest zs Q xs' P (Normal s) ns'' ns' \\<Gamma> m\" \nshows \"xs=xs' \\<and> (m,\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod_nest_call\"\nusing a2 unfolding seq_cond_nest_def \nproof\n  assume ass:\"zs= map (lift Q) xs'\"\n  then have  \"map (lift Q) xs' = \n              map (lift Q) xs @ (Throw, Normal s') # ys\" using a0 by auto \n  then have zs_while:\"fst (zs!(length (map (lift Q) xs))) = Throw\"  \n    by (metis a0  fstI nth_append_length) \n  also have \"length zs = \n             length (map (lift Q) xs @ (Throw, Normal s') # ys)\" \n    using a0 by auto\n  then have \"(length (map (lift Q) xs)) < length zs\" by auto       \n  then show ?thesis using ass zs_while map_lift_all_seq    \n    by (metis (no_types) LanguageCon.com.simps(82))    \nnext\n  assume \n    ass:\"fst (((P, Normal s) # xs') ! length xs') = LanguageCon.com.Skip \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, Normal s) # xs') ! length xs')) # ys)\n          \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift Q) xs' @\n              (Q, snd (((P, Normal s) # xs') ! length xs')) # ys) \\<or>\n         fst (((P, Normal s) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n         snd (last ((P, Normal s) # xs')) = Normal ns' \\<and>\n         Normal s = Normal ns'' \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (LanguageCon.com.Throw, Normal ns') # ys) \\<in> cptn_mod_nest_call \\<and>\n            zs = map (lift Q) xs' @ (LanguageCon.com.Throw, Normal ns') # ys)\"\n   {assume \n     ass:\"fst (((P, Normal s) # xs') ! length xs') = LanguageCon.com.Skip \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, Normal s) # xs') ! length xs')) # ys)\n          \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift Q) xs' @\n              (Q, snd (((P, Normal s) # xs') ! length xs')) # ys)\"\n      then obtain ys' where \n         zs:\"(m, \\<Gamma>, (Q, snd (((P, Normal s) # xs') ! length xs')) # ys')\n               \\<in> cptn_mod_nest_call \\<and>\n            zs = map (lift Q) xs' @ \n              (Q, snd (((P, Normal s) # xs') ! length xs')) # ys'\" \n             by auto \n      then have ?thesis\n        using a0 seq_and_if_not_eq(4)[of Q]\n         by (metis LanguageCon.com.distinct(17) LanguageCon.com.distinct(71) \n             a0' ass last_length map_lift_some_eq)                        \n   }note l = this\n   {assume ass:\"fst (((P, Normal s) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n         snd (last ((P, Normal s) # xs')) = Normal ns' \\<and>\n         Normal s = Normal ns'' \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (LanguageCon.com.Throw, Normal ns') # ys) \\<in> cptn_mod_nest_call \\<and>\n            zs = map (lift Q) xs' @ (LanguageCon.com.Throw, Normal ns') # ys)\"\n      then obtain ys' where \n         zs:\"(m, \\<Gamma>, (LanguageCon.com.Throw, Normal ns') # ys') \\<in> cptn_mod_nest_call \\<and>\n            zs = map (lift Q) xs' @ (LanguageCon.com.Throw, Normal ns') # ys'\" \n         by auto\n      then have zs_while:\n          \"fst (zs!(length (map (lift Q) xs'))) = Throw\"  \n        by (metis fstI nth_append_length)             \n      then have ?thesis using a0 ass map_lift_some_eq by blast        \n   } thus ?thesis using l ass by auto\nqed\n\nlemma Catch_P_Not_finish:\n assumes\n   a0:\"zs = map (lift_catch Q) xs\" and   \n   a1:\"catch_cond_nest zs Q xs' P s s'' s' \\<Gamma> m\" \nshows \"xs=xs'\"\nusing a1 unfolding catch_cond_nest_def \nproof\n  assume \"zs= map (lift_catch Q) xs'\"\n  then have  \"map (lift_catch Q) xs' = \n              map (lift_catch Q) xs\" using a0 by auto \n  thus ?thesis using map_lift_catch_eq_xs_xs' by fastforce\nnext\n  assume \n    ass:\"\n         fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n         snd (last ((P, s) # xs')) = Normal s' \\<and>\n         s = Normal s'' \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<or>\n         fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift_catch Q) xs' @ (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys)\"\n   {assume \n     ass:\"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift_catch Q) xs' @ (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys)\"\n      then obtain ys where \n         zs:\"(m, \\<Gamma>, (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n            zs = map (lift_catch Q) xs' @ (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys\" \n             by auto \n      then have zs_while:\"fst (zs!(length (map (lift_catch Q) xs'))) = Skip \"  \n        by (metis fstI nth_append_length) \n      have \"length zs = length (map (lift Q) xs' @\n         (Q, snd (((P, s) # xs') ! length xs')) # ys)\" \n          using zs by auto\n      then have \"(length (map (lift Q) xs')) < \n                  length zs\" by auto       \n      then have ?thesis using a0 zs_while map_lift_catch_all_catch\n         using seq_and_if_not_eq(12) by fastforce     \n   }note l = this\n   {assume ass:\"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n         snd (last ((P, s) # xs')) = Normal s' \\<and>\n         s = Normal s'' \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)\"\n      then obtain ys where \n            zs:\"zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys\" by auto\n      then have zs_while:\n        \"fst (zs!(length (map (lift Q) xs'))) = Q\"\n         by (metis (no_types) eq_fst_iff length_map nth_append_length zs) \n       have \"length zs = length (map (lift Q) xs' @(LanguageCon.com.Throw, Normal s') # ys)\" \n           using zs by auto\n       then have \"(length (map (lift Q) xs')) < \n                  length zs\" by auto       \n       then have ?thesis using a0 zs_while map_lift_catch_all_catch\n         by fastforce\n   } thus ?thesis using l ass by auto\nqed\n\nlemma Catch_P_Ends_Normal:\n assumes\n   a0:\"zs = map (lift_catch Q) xs @ (Q, snd (last ((P, Normal s) # xs))) # ys\" and\n   a0':\"fst (last ((P, Normal s) # xs)) = Throw\" and\n   a0'':\"snd (last ((P, Normal s) # xs)) = Normal s'\" and\n   a1:\"catch_cond_nest zs Q xs' P (Normal s) ns'' ns' \\<Gamma> m\" \nshows \"xs=xs' \\<and> (m,\\<Gamma>,(Q, snd(((P, Normal s)#xs)!length xs))#ys) \\<in> cptn_mod_nest_call\"\nusing a1 unfolding catch_cond_nest_def \nproof\n  assume ass:\"zs= map (lift_catch Q) xs'\"\n  then have  \"map (lift_catch Q) xs' = \n              map (lift_catch Q) xs @ (Q, snd (last ((P, Normal s) # xs))) # ys\" using a0 by auto \n  then have zs_while:\"fst (zs!(length (map (lift_catch Q) xs))) = Q\"\n    by (metis a0 fstI nth_append_length)      \n  also have \"length zs = \n             length (map (lift_catch Q) xs @ (Q, snd (last ((P, Normal s) # xs))) # ys)\" \n    using a0 by auto\n  then have \"(length (map (lift_catch Q) xs)) < length zs\" by auto       \n  then show ?thesis using ass zs_while map_lift_catch_all_catch\n           using seq_and_if_not_eq(12)\n  by metis\nnext\n  assume \n    ass:\"fst (((P, Normal s) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n         snd (last ((P, Normal s) # xs')) = Normal ns' \\<and>\n         Normal s = Normal ns'' \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, Normal s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift_catch Q) xs' @ (Q, snd (((P, Normal s) # xs') ! length xs')) # ys) \\<or>\n         fst (((P, Normal s) # xs') ! length xs') = LanguageCon.com.Skip \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (LanguageCon.com.Skip, snd (last ((P, Normal s) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift_catch Q) xs' @ (LanguageCon.com.Skip, snd (last ((P, Normal s) # xs'))) # ys)\"\n   {assume \n     ass:\"fst (((P, Normal s) # xs') ! length xs') = LanguageCon.com.Skip \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (LanguageCon.com.Skip, snd (last ((P, Normal s) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift_catch Q) xs' @ (LanguageCon.com.Skip, snd (last ((P, Normal s) # xs'))) # ys)\"\n      then obtain ys' where \n         zs:\"(m, \\<Gamma>, (LanguageCon.com.Skip, snd (last ((P, Normal s) # xs'))) # ys') \\<in> cptn_mod_nest_call \\<and>\n             zs = map (lift_catch Q) xs' @ (LanguageCon.com.Skip, snd (last ((P, Normal s) # xs'))) # ys'\" \n             by auto \n      then have ?thesis\n        using  map_lift_catch_some_eq[of Q xs Q _ ys xs' Skip _ ys'] \n               zs  a0 seq_and_if_not_eq(12)[of Q]\n        by (metis LanguageCon.com.distinct(17) LanguageCon.com.distinct(19) a0' ass last_length)                        \n   }note l = this\n   {assume ass:\"fst (((P, Normal s) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n                snd (last ((P, Normal s) # xs')) = Normal ns' \\<and>\n                Normal s = Normal ns'' \\<and>\n                (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, Normal s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n                zs = map (lift_catch Q) xs' @ (Q, snd (((P, Normal s) # xs') ! length xs')) # ys)\"\n      then obtain ys' where \n         zs:\"(m, \\<Gamma>, (Q, snd (((P, Normal s) # xs') ! length xs')) # ys') \\<in> cptn_mod_nest_call \\<and>\n                zs = map (lift_catch Q) xs' @ (Q, snd (((P, Normal s) # xs') ! length xs')) # ys'\" \n         by auto\n      then have zs_while:\n          \"fst (zs!(length (map (lift_catch Q) xs'))) = Q\"  by (metis fstI nth_append_length)       \n\n      then have ?thesis \n        using LanguageCon.com.distinct(17) LanguageCon.com.distinct(71) \n            a0 a0' ass last_length map_lift_catch_some_eq[of Q xs Q _ ys xs' Q _ ys']  \n            seq_and_if_not_eq(12) zs\n        by blast        \n   } thus ?thesis using l ass by auto\nqed\n \nlemma Catch_P_Ends_Skip:\n assumes\n   a0:\"zs = map (lift_catch Q) xs @ (Skip, snd (last ((P, s) # xs))) # ys\" and\n   a0':\"fst (last ((P,s) # xs)) = Skip\" and\n   a1:\"catch_cond_nest zs Q xs' P s ns'' ns' \\<Gamma> m\" \nshows \"xs=xs' \\<and> (m,\\<Gamma>,(Skip,snd(last ((P,s) # xs)))#ys) \\<in> cptn_mod_nest_call\"\nusing a1 unfolding catch_cond_nest_def \nproof\n  assume ass:\"zs= map (lift_catch Q) xs'\"\n  then have  \"map (lift_catch Q) xs' = \n              map (lift_catch Q) xs @ (Skip, snd (last ((P, s) # xs))) # ys\" using a0 by auto \n  then have zs_while:\"fst (zs!(length (map (lift_catch Q) xs))) = Skip\"  \n    by (metis a0  fstI nth_append_length) \n  also have \"length zs = \n             length (map (lift_catch Q) xs @ (Skip, snd (last ((P, s) # xs))) # ys)\" \n    using a0 by auto\n  then have \"(length (map (lift_catch Q) xs)) < length zs\" by auto       \n  then show ?thesis using ass zs_while map_lift_catch_all_catch\n    by (metis LanguageCon.com.distinct(19))    \nnext\n  assume \n    ass:\"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n         snd (last ((P, s) # xs')) = Normal ns' \\<and>\n         s = Normal ns'' \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<or>\n         fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift_catch Q) xs' @ (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys)\"\n   {assume \n     ass:\"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Skip \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift_catch Q) xs' @ (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys)\"\n      then obtain ys' where \n         zs:\"(m, \\<Gamma>, (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys') \\<in> cptn_mod_nest_call \\<and>\n             zs = map (lift_catch Q) xs' @ (LanguageCon.com.Skip, snd (last ((P, s) # xs'))) # ys'\" \n             by auto \n      then have ?thesis\n        using a0 seq_and_if_not_eq(12)[of Q] a0' ass last_length map_lift_catch_some_eq\n        using LanguageCon.com.distinct(19) by blast                \n   }note l = this\n   {assume ass:\"fst (((P, s) # xs') ! length xs') = LanguageCon.com.Throw \\<and>\n         snd (last ((P, s) # xs')) = Normal ns' \\<and>\n         s = Normal ns'' \\<and>\n         (\\<exists>ys. (m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys)\"\n      then obtain ys' where \n         zs:\"(m, \\<Gamma>, (Q, snd (((P, s) # xs') ! length xs')) # ys') \\<in> cptn_mod_nest_call \\<and>\n         zs = map (lift_catch Q) xs' @ (Q, snd (((P, s) # xs') ! length xs')) # ys'\" \n         by auto\n      then have zs_while:\n          \"fst (zs!(length (map (lift_catch Q) xs'))) = Q\"  \n        by (metis fstI nth_append_length)             \n      then have ?thesis \n        using a0 seq_and_if_not_eq(12)[of Q] a0' ass last_length map_lift_catch_some_eq\n        by (metis LanguageCon.com.distinct(17) LanguageCon.com.distinct(19))               \n   } thus ?thesis using l ass by auto\nqed\n\n\nlemma not_func_redex_cptn_mod_nest_n': \nassumes a0:\"\\<Gamma>\\<turnstile>\\<^sub>c (P,s) \\<rightarrow> (Q, t)\" and\n        a1:\"(n,\\<Gamma>,(Q,t)#xs) \\<in>  cptn_mod_nest_call\" and \n        a2:\"(\\<forall>fn. redex P \\<noteq> Call fn) \\<or> \n            (redex P = Call fn \\<and> \\<Gamma> fn = None) \\<or> \n            (redex P = Call fn \\<and> (\\<forall>sa. s\\<noteq>Normal sa))\"\nshows \"(n,\\<Gamma>,(P,s)#(Q,t)#xs) \\<in>  cptn_mod_nest_call\"\nusing a0 a1 a2\nproof (induct arbitrary: xs) \n  case (Basicc f s)   \n  thus ?case by (simp add: Basicc cptn_mod_nest_call.CptnModNestSkip stepc.Basicc)\nnext\n  case (Specc s t r)\n  thus ?case by (simp add: Specc cptn_mod_nest_call.CptnModNestSkip stepc.Specc)\nnext\n  case (SpecStuckc s r)\n  thus ?case by (simp add: SpecStuckc cptn_mod_nest_call.CptnModNestSkip stepc.SpecStuckc)\nnext\n  case (Guardc s g f c) \n    thus ?case by (simp add: cptn_mod_nest_call.CptnModNestGuard) \nnext\n\n  case (GuardFaultc s g f c)\n  thus ?case by (simp add: GuardFaultc cptn_mod_nest_call.CptnModNestSkip stepc.GuardFaultc)\nnext\ncase (Seqc c1 s c1' s' c2)\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c1, s) \\<rightarrow> (c1', s')\" by (simp add: Seqc.hyps(1))\n  then have nsc1: \"c1\\<noteq>Skip\" using stepc_elim_cases(1) by blast \n  have assum: \"(n, \\<Gamma>, (Seq c1' c2, s') # xs) \\<in> cptn_mod_nest_call\" using Seqc.prems by blast\n  have divseq:\"(\\<forall>s P Q zs. (Seq c1' c2, s') # xs=(Seq P Q, s)#zs \\<longrightarrow>\n                (\\<exists>xs sv' sv''. ((n,\\<Gamma>,(P, s)#xs) \\<in> cptn_mod_nest_call  \\<and> \n                           (zs=(map (lift Q) xs) \\<or>\n                           ((fst(((P, s)#xs)!length xs)=Skip \\<and> \n                             (\\<exists>ys. (n,\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod_nest_call \\<and> \n                              zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n                           ((fst(((P, s)#xs)!length xs)=Throw \\<and> \n                               snd(last ((P, s)#xs)) = Normal sv' \\<and>  s'=Normal sv''\\<and>\n                             (\\<exists>ys.  (n,\\<Gamma>,(Throw,Normal sv')#ys) \\<in> cptn_mod_nest_call \\<and>\n                              zs=(map (lift Q) xs)@((Throw,Normal sv')#ys))\n                               ))))\n                            \n                 ))\"  using div_seq_nest [OF assum] unfolding seq_cond_nest_def by auto\n   {fix sa P Q zsa\n       assume ass:\"(Seq c1' c2, s') # xs = (Seq P Q, sa) # zsa\"\n       then have eqs:\"c1' = P \\<and> c2 = Q \\<and> s' = sa \\<and> xs = zsa\" by auto\n       then have \"(\\<exists>xs sv' sv''. (n,\\<Gamma>, (P, sa) # xs) \\<in> cptn_mod_nest_call \\<and>\n                        (zsa = map (lift Q) xs \\<or>              \n                         fst (((P, sa) # xs) ! length xs) = Skip \\<and>\n                             (\\<exists>ys. (n,\\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n                             zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<or>\n                        ((fst(((P, sa)#xs)!length xs)=Throw \\<and> \n                          snd(last ((P, sa)#xs)) = Normal sv' \\<and>  s'=Normal sv''\\<and>\n                          (\\<exists>ys.  (n,\\<Gamma>,(Throw,Normal sv')#ys) \\<in> cptn_mod_nest_call \\<and>\n                              zsa=(map (lift Q) xs)@((Throw,Normal sv')#ys))))))\" \n             using ass divseq by blast\n    } note conc=this [of c1' c2 s' xs]    \n     then obtain xs' sa' sa''\n       where  split:\"(n,\\<Gamma>, (c1', s') # xs') \\<in> cptn_mod_nest_call \\<and>\n                     (xs = map (lift c2) xs' \\<or>                   \n                     fst (((c1', s') # xs') ! length xs') = Skip \\<and>\n                        (\\<exists>ys. (n,\\<Gamma>, (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n                         xs = map (lift c2) xs' @ (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<or>\n                     ((fst(((c1', s')#xs')!length xs')=Throw \\<and> \n                         snd(last ((c1', s')#xs')) = Normal sa' \\<and> s'=Normal sa''\\<and>\n                         (\\<exists>ys.  (n,\\<Gamma>,(Throw,Normal sa')#ys) \\<in> cptn_mod_nest_call \\<and>\n                              xs=(map (lift c2) xs')@((Throw,Normal sa')#ys))\n                         )))\"  by blast\n  then have \"(xs = map (lift c2) xs' \\<or>                   \n                   fst (((c1', s') # xs') ! length xs') = Skip \\<and>\n                      (\\<exists>ys. (n,\\<Gamma>, (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n                       xs = map (lift c2) xs' @ (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<or>\n                   ((fst(((c1', s')#xs')!length xs')=Throw \\<and> \n                       snd(last ((c1', s')#xs')) = Normal sa' \\<and> s'=Normal sa''\\<and>\n                       (\\<exists>ys.  (n,\\<Gamma>,(Throw,Normal sa')#ys) \\<in> cptn_mod_nest_call \\<and>\n                            xs=(map (lift c2) xs')@((Throw,Normal sa')#ys)))))\" \n    by auto\n  thus ?case \n  proof{           \n       assume c1'nonf:\"xs = map (lift c2) xs'\"\n       then have c1'cptn:\"(n,\\<Gamma>, (c1', s') # xs') \\<in> cptn_mod_nest_call\" using split by blast\n       then have induct_step: \"(n,\\<Gamma>, (c1, s) # (c1', s')#xs') \\<in> cptn_mod_nest_call\"\n         using Seqc.hyps(2) Seqc.prems(2) SmallStepCon.redex.simps(4) by auto  \n       then have \"(Seq c1' c2, s')#xs = map (lift c2) ((c1', s')#xs')\"\n         using c1'nonf\n         by (simp add: lift_def)\n       thus ?thesis \n         using c1'nonf c1'cptn induct_step by (auto simp add: CptnModNestSeq1)\n    next\n      assume \"fst (((c1', s') # xs') ! length xs') = Skip \\<and>\n              (\\<exists>ys. (n,\\<Gamma>, (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n                  xs = map (lift c2) xs' @ (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<or>\n             ((fst(((c1', s')#xs')!length xs')=Throw \\<and> \n                snd(last ((c1', s')#xs')) = Normal sa' \\<and>  s'=Normal sa''\\<and>\n                (\\<exists>ys.  (n,\\<Gamma>,(Throw,Normal sa')#ys) \\<in> cptn_mod_nest_call \\<and>\n                              xs=(map (lift c2) xs')@((Throw,Normal sa')#ys))))\"  \n      thus ?thesis\n      proof\n       assume assth:\"fst (((c1', s') # xs') ! length xs') = Skip \\<and>\n            (\\<exists>ys. (n,\\<Gamma>, (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n                xs = map (lift c2) xs' @ (c2, snd (((c1', s') # xs') ! length xs')) # ys)\"\n       then obtain ys \n           where split':\"(n,\\<Gamma>, (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n                xs = map (lift c2) xs' @ (c2, snd (((c1', s') # xs') ! length xs')) # ys\"\n           by auto    \n       then have c1'cptn:\"(n,\\<Gamma>, (c1', s') # xs') \\<in> cptn_mod_nest_call\" using split by blast\n       then have induct_step: \"(n,\\<Gamma>, (c1, s) # (c1', s')#xs') \\<in> cptn_mod_nest_call\"\n       using Seqc.hyps(2) Seqc.prems(2) SmallStepCon.redex.simps(4) by auto                \n       then have seqmap:\"(Seq c1 c2, s)#(Seq c1' c2, s')#xs = map (lift c2) ((c1,s)#(c1', s')#xs') @ (c2, snd (((c1', s') # xs') ! length xs')) # ys\"\n      using split' by (simp add:  lift_def) \n      then have lastc1:\"last ((c1, s) # (c1', s') # xs') = ((c1', s') # xs') ! length xs'\"\n        by (simp add: last_length) \n      then have lastc1skip:\"fst (last ((c1, s) # (c1', s') # xs')) = Skip\" \n           using assth by fastforce          \n      thus ?thesis \n        using seqmap split' cptn_mod_nest_call.CptnModNestSeq2\n              induct_step lastc1 lastc1skip\n        by (metis (no_types) Cons_lift_append )               \n    next\n        assume assm:\"((fst(((c1', s')#xs')!length xs')=Throw \\<and> \n                snd(last ((c1', s')#xs')) = Normal sa' \\<and>  s'=Normal sa''\\<and>\n                (\\<exists>ys.(n,\\<Gamma>,(Throw,Normal sa')#ys) \\<in> cptn_mod_nest_call \\<and>\n                 xs=(map (lift c2) xs')@((Throw,Normal sa')#ys))))\"\n        then have s'eqsa'': \"s'=Normal sa''\" by auto\n        then have snormal: \"\\<exists>ns. s=Normal ns\" by (metis Seqc.hyps(1) step_Abrupt_prop step_Fault_prop step_Stuck_prop xstate.exhaust)\n        then have c1'cptn:\"(n,\\<Gamma>, (c1', s') # xs') \\<in> cptn_mod_nest_call\" using split by blast        \n        then have induct_step: \"(n,\\<Gamma>, (c1, s) # (c1', s')#xs') \\<in> cptn_mod_nest_call\"\n        using Seqc.hyps(2) Seqc.prems(2) SmallStepCon.redex.simps(4) by auto \n        then obtain ys where seqmap:\"(Seq c1' c2, s')#xs = (map (lift c2) ((c1', s')#xs'))@((Throw,Normal sa')#ys)\"\n        using assm\n        proof -\n          assume a1: \"\\<And>ys. (LanguageCon.com.Seq c1' c2, s') # xs = map (lift c2) ((c1', s') # xs') @ (LanguageCon.com.Throw, Normal sa') # ys \\<Longrightarrow> thesis\"\n          have \"(LanguageCon.com.Seq c1' c2, Normal sa'') # map (lift c2) xs' = map (lift c2) ((c1', s') # xs')\"\n            by (simp add: assm lift_def)\n          thus ?thesis\n            using a1 assm by moura\n        qed  \n        then have lastc1:\"last ((c1, s) # (c1', s') # xs') = ((c1', s') # xs') ! length xs'\"\n                   by (simp add: last_length) \n        then have lastc1skip:\"fst (last ((c1, s) # (c1', s') # xs')) = Throw\" \n             using assm by fastforce\n        then have \"snd (last ((c1, s) # (c1', s') # xs')) = Normal sa'\"\n             using assm by force        \n        thus ?thesis\n            using assm c1'cptn induct_step lastc1skip snormal seqmap s'eqsa'' \n            by (auto simp add:cptn_mod_nest_call.CptnModNestSeq3)\n   qed\n  }qed    \nnext\n  case (SeqSkipc c2 s xs)\n  have c2incptn:\"(n,\\<Gamma>, (c2, s) # xs) \\<in> cptn_mod_nest_call\" by fact\n  then have 1:\"(n,\\<Gamma>, [(Skip, s)]) \\<in> cptn_mod_nest_call\"\n    by (simp add: cptn_mod_nest_call.CptnModNestOne)\n  then have 2:\"fst(last ([(Skip, s)])) = Skip\" by fastforce\n  then have 3:\"(n,\\<Gamma>,(c2, snd(last [(Skip, s)]))#xs) \\<in> cptn_mod_nest_call\" \n      using c2incptn by auto  \n  then have \"(c2,s)#xs=(map (lift c2) [])@(c2, snd(last [(Skip, s)]))#xs\" \n       by (auto simp add:lift_def)\n  thus ?case using 1 2 3 by (simp add: CptnModNestSeq2)   \nnext\n  case (SeqThrowc c2 s xs)  \n  have \"(n,\\<Gamma>, [(Throw, Normal s)]) \\<in> cptn_mod_nest_call\" \n    by (simp add: cptn_mod_nest_call.CptnModNestOne) \n  then obtain ys where \n    ys_nil:\"ys=[]\" and \n    last:\"(n, \\<Gamma>, (Throw, Normal s)#ys)\\<in> cptn_mod_nest_call\"\n   by auto\n  moreover have \"fst (last ((Throw, Normal s)#ys)) = Throw\" using ys_nil last by auto\n  moreover have \"snd (last ((Throw, Normal s)#ys)) = Normal s\" using ys_nil last by auto\n  moreover from ys_nil have \"(map (lift c2) ys) = []\" by auto  \n  ultimately show ?case using SeqThrowc.prems cptn_mod_nest_call.CptnModNestSeq3 by fastforce      \n\nnext\n  case (CondTruec s b c1 c2)\n  thus ?case by (simp add: cptn_mod_nest_call.CptnModNestCondT)\nnext\n  case (CondFalsec s b c1 c2)\n  thus ?case by (simp add: cptn_mod_nest_call.CptnModNestCondF)\nnext\n case (WhileTruec s1 b c)\n have sinb: \"s1\\<in>b\" by fact\n have SeqcWhile: \"(n,\\<Gamma>, (Seq c (While b c), Normal s1) # xs) \\<in> cptn_mod_nest_call\" \n   by fact  \n have divseq:\"(\\<forall>s P Q zs. (Seq c (While b c), Normal s1) # xs=(Seq P Q, s)#zs \\<longrightarrow>\n                (\\<exists>xs s'. ((n,\\<Gamma>,(P, s)#xs) \\<in> cptn_mod_nest_call  \\<and> \n                           (zs=(map (lift Q) xs) \\<or>\n                           ((fst(((P, s)#xs)!length xs)=Skip \\<and> \n                             (\\<exists>ys. (n,\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod_nest_call \\<and> \n                              zs=(map (lift (Q)) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n                           ((fst(((P, s)#xs)!length xs)=Throw \\<and> \n                               snd(last ((P, s)#xs)) = Normal s' \\<and>\n                              (\\<exists>ys.  (n,\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod_nest_call \\<and>\n                      zs=(map (lift Q) xs)@((Throw,Normal s')#ys))))))                            \n                 ))\" using div_seq_nest [OF SeqcWhile] by (auto simp add: seq_cond_nest_def)\n{fix sa P Q zsa\n       assume ass:\"(Seq c (While b c), Normal s1) # xs = (Seq P Q, sa) # zsa\"\n       then have eqs:\"c = P \\<and> (While b c) = Q \\<and> Normal s1 = sa \\<and> xs = zsa\" by auto\n       then have \"(\\<exists>xs s'. (n,\\<Gamma>, (P, sa) # xs) \\<in> cptn_mod_nest_call \\<and>\n                        (zsa = map (lift Q) xs \\<or>              \n                         fst (((P, sa) # xs) ! length xs) = Skip \\<and>\n                             (\\<exists>ys. (n,\\<Gamma>, (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n                             zsa = map (lift Q) xs @ (Q, snd (((P, sa) # xs) ! length xs)) # ys) \\<or>\n                        ((fst(((P, sa)#xs)!length xs)=Throw \\<and> \n                          snd(last ((P, sa)#xs)) = Normal s' \\<and>\n                          (\\<exists>ys.  (n,\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod_nest_call \\<and>\n                      zsa=(map (lift Q) xs)@((Throw,Normal s')#ys))\n                        ))))\" \n             using ass divseq by auto\n    } note conc=this [of c \"While b c\" \"Normal s1\" xs] \n   then obtain xs' s' \n        where  split:\"(n,\\<Gamma>, (c, Normal s1) # xs') \\<in> cptn_mod_nest_call \\<and>\n     (xs = map (lift (While b c)) xs' \\<or>\n      fst (((c, Normal s1) # xs') ! length xs') = Skip \\<and>\n      (\\<exists>ys. (n,\\<Gamma>, (While b c, snd (((c, Normal s1) # xs') ! length xs')) # ys)\n            \\<in> cptn_mod_nest_call \\<and>\n            xs =\n            map (lift (While b c)) xs' @\n            (While b c, snd (((c, Normal s1) # xs') ! length xs')) # ys) \\<or>\n      fst (((c, Normal s1) # xs') ! length xs') = Throw \\<and>\n      snd (last ((c, Normal s1) # xs')) = Normal s' \\<and> \n      (\\<exists>ys.  (n,\\<Gamma>, ((Throw, Normal s')#ys)) \\<in> cptn_mod_nest_call \\<and>\n      xs = map (lift (While b c)) xs' @ ((Throw, Normal s')#ys)))\"  by auto\n then have \"(xs = map (lift (While b c)) xs' \\<or>\n            fst (((c, Normal s1) # xs') ! length xs') = Skip \\<and>\n            (\\<exists>ys. (n,\\<Gamma>, (While b c, snd (((c, Normal s1) # xs') ! length xs')) # ys)\n                  \\<in> cptn_mod_nest_call \\<and>\n                  xs =\n                  map (lift (While b c)) xs' @\n                  (While b c, snd (((c, Normal s1) # xs') ! length xs')) # ys) \\<or>\n            fst (((c, Normal s1) # xs') ! length xs') = Throw \\<and>\n            snd (last ((c, Normal s1) # xs')) = Normal s' \\<and>\n            (\\<exists>ys.  (n,\\<Gamma>, ((Throw, Normal s')#ys)) \\<in> cptn_mod_nest_call \\<and>\n          xs = map (lift (While b c)) xs' @ ((Throw, Normal s')#ys)))\" ..\n thus ?case\n proof{ \n   assume 1:\"xs = map (lift (While b c)) xs'\"  \n   have 3:\"(n, \\<Gamma>, (c, Normal s1) # xs') \\<in> cptn_mod_nest_call\" using split by auto   \n   then show ?thesis \n     using \"1\" cptn_mod_nest_call.CptnModNestWhile1 sinb by fastforce \n next\n   assume \"fst (((c, Normal s1) # xs') ! length xs') = Skip \\<and>\n          (\\<exists>ys. (n,\\<Gamma>, (While b c, snd (((c, Normal s1) # xs') ! length xs')) # ys)\n                \\<in> cptn_mod_nest_call \\<and>\n                xs =\n                map (lift (While b c)) xs' @\n                (While b c, snd (((c, Normal s1) # xs') ! length xs')) # ys) \\<or>\n          fst (((c, Normal s1) # xs') ! length xs') = Throw \\<and>\n          snd (last ((c, Normal s1) # xs')) = Normal s' \\<and>\n          (\\<exists>ys.  (n,\\<Gamma>, ((Throw, Normal s')#ys)) \\<in> cptn_mod_nest_call \\<and>\n          xs = map (lift (While b c)) xs' @ ((Throw, Normal s')#ys))\"\n   thus ?case\n   proof\n     assume asm:\"fst (((c, Normal s1) # xs') ! length xs') = Skip \\<and>\n             (\\<exists>ys. (n,\\<Gamma>, (While b c, snd (((c, Normal s1) # xs') ! length xs')) # ys)\n             \\<in> cptn_mod_nest_call \\<and>\n             xs =\n             map (lift (While b c)) xs' @\n             (While b c, snd (((c, Normal s1) # xs') ! length xs')) # ys)\"\n     then obtain ys \n       where asm':\"(n,\\<Gamma>, (While b c, snd (last ((c, Normal s1) # xs'))) # ys)\n                   \\<in> cptn_mod_nest_call \n                   \\<and> xs = map (lift (While b c)) xs' @\n                       (While b c, snd (last ((c, Normal s1) # xs'))) # ys\" \n              by (auto simp add: last_length)\n     moreover have 3:\"(n,\\<Gamma>, (c, Normal s1) # xs') \\<in> cptn_mod_nest_call\" using split by auto\n     moreover from asm have \"fst (last ((c, Normal s1) # xs'))  = Skip\"\n          by (simp add: last_length) \n     ultimately show ?case using sinb by (auto simp add:CptnModNestWhile2)\n   next\n    assume asm:\" fst (((c, Normal s1) # xs') ! length xs') = Throw \\<and>\n          snd (last ((c, Normal s1) # xs')) = Normal s' \\<and>\n          (\\<exists>ys.  (n,\\<Gamma>, ((Throw, Normal s')#ys)) \\<in> cptn_mod_nest_call \\<and>\n          xs = map (lift (While b c)) xs' @ ((Throw, Normal s')#ys))\"   \n     moreover have 3:\"(n,\\<Gamma>, (c, Normal s1) # xs') \\<in> cptn_mod_nest_call\" \n       using split by auto\n     moreover from asm have \"fst (last ((c, Normal s1) # xs'))  = Throw\"\n          by (simp add: last_length) \n     ultimately show ?case using sinb by (auto simp add:CptnModNestWhile3)\n   qed\n }qed  \nnext\n case (WhileFalsec s b c)\n thus ?case by (simp add: cptn_mod_nest_call.CptnModNestSkip stepc.WhileFalsec)\nnext\n  case (Awaitc s b c t)\n  thus ?case by (simp add: cptn_mod_nest_call.CptnModNestSkip stepc.Awaitc)\nnext\n  case (AwaitAbruptc s b c t t')\n  thus ?case by (simp add: cptn_mod_nest_call.CptnModNestThrow stepc.AwaitAbruptc) \nnext\n  case (Callc p bdy s)\n  thus ?case using SmallStepCon.redex.simps(7) by auto  \nnext\n  case (CallUndefinedc p s)\n  then have \"p = fn\" by auto\n  thus ?case using CallUndefinedc\n  proof -\n    have \"(LanguageCon.com.Call fn \\<inter>\\<^sub>g\\<^sub>s (LanguageCon.com.Skip::('b, 'a, 'c,'d) LanguageCon.com)) \\<noteq> Some LanguageCon.com.Skip\"\n      by simp\n    then show ?thesis\n      by (metis (no_types) CallUndefinedc.hyps LanguageCon.com.inject(6) LanguageCon.inter_guards.simps(79) SmallStepCon.redex.simps(7) \\<open>(n, \\<Gamma>, (LanguageCon.com.Skip, Stuck) # xs) \\<in> cptn_mod_nest_call\\<close> cptn_mod_nest_call.CptnModNestSkip stepc.CallUndefinedc)\n  qed \nnext\n  case (DynComc c s)\n  thus ?case by (simp add: cptn_mod_nest_call.CptnModNestDynCom) \nnext\n  case (Catchc c1 s c1' s' c2)\n   have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c1, s) \\<rightarrow> (c1', s')\" by (simp add: Catchc.hyps(1))\n  then have nsc1: \"c1\\<noteq>Skip\" using stepc_elim_cases(1) by blast \n  have assum: \"(n,\\<Gamma>, (Catch c1' c2, s') # xs) \\<in> cptn_mod_nest_call\" \n  using Catchc.prems by blast\n  have divcatch:\"(\\<forall>s P Q zs. (Catch c1' c2, s') # xs=(Catch P Q, s)#zs \\<longrightarrow>\n  (\\<exists>xs s' s''. ((n,\\<Gamma>,(P, s)#xs) \\<in> cptn_mod_nest_call  \\<and> \n             (zs=(map (lift_catch Q) xs) \\<or>\n             ((fst(((P, s)#xs)!length xs)=Throw \\<and>\n               snd(last ((P, s)#xs)) = Normal s' \\<and>  s=Normal s''\\<and>\n               (\\<exists>ys. (n,\\<Gamma>,(Q, snd(((P, s)#xs)!length xs))#ys) \\<in> cptn_mod_nest_call \\<and> \n                zs=(map (lift_catch Q) xs)@((Q, snd(((P, s)#xs)!length xs))#ys)))) \\<or>\n                ((fst(((P, s)#xs)!length xs)=Skip \\<and>  \n                  (\\<exists>ys. (n,\\<Gamma>,(Skip,snd(last ((P, s)#xs)))#ys) \\<in> cptn_mod_nest_call \\<and>                   \n                 zs=(map (lift_catch Q) xs)@((Skip,snd(last ((P, s)#xs)))#ys))                \n                 ))))\n   ))\" using div_catch_nest [OF assum] by (auto simp add: catch_cond_nest_def)\n   {fix sa P Q zsa\n       assume ass:\"(Catch c1' c2, s') # xs = (Catch P Q, sa) # zsa\"\n       then have eqs:\"c1' = P \\<and> c2 = Q \\<and> s' = sa \\<and> xs = zsa\" by auto\n       then have \"(\\<exists>xs sv' sv''. ((n, \\<Gamma>,(P, sa)#xs) \\<in> cptn_mod_nest_call  \\<and> \n             (zsa=(map (lift_catch Q) xs) \\<or>\n             ((fst(((P, sa)#xs)!length xs)=Throw \\<and>\n               snd(last ((P, sa)#xs)) = Normal sv' \\<and>  s'=Normal sv''\\<and>\n               (\\<exists>ys. (n,\\<Gamma>,(Q, snd(((P, sa)#xs)!length xs))#ys) \\<in> cptn_mod_nest_call \\<and> \n                zsa=(map (lift_catch Q) xs)@((Q, snd(((P, sa)#xs)!length xs))#ys)))) \\<or>\n                ((fst(((P, sa)#xs)!length xs)=Skip \\<and>                  \n                 (\\<exists>ys. (n,\\<Gamma>,(Skip,snd(last ((P, sa)#xs)))#ys) \\<in> cptn_mod_nest_call \\<and>                   \n                 zsa=(map (lift_catch Q) xs)@((Skip,snd(last ((P, sa)#xs)))#ys))))))\n   )\"   using ass divcatch by blast\n    } note conc=this [of c1' c2 s' xs]    \n     then obtain xs' sa' sa''\n       where split:\n         \"(n,\\<Gamma>, (c1', s') # xs') \\<in> cptn_mod_nest_call \\<and> \n          (xs = map (lift_catch c2) xs' \\<or>\n          fst (((c1', s') # xs') ! length xs') = Throw \\<and>\n          snd (last ((c1', s') # xs')) = Normal sa' \\<and> s' = Normal sa'' \\<and>\n          (\\<exists>ys. (n,\\<Gamma>, (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n                xs = map (lift_catch c2) xs' @\n                (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<or>\n          fst (((c1', s') # xs') ! length xs') = Skip \\<and>\n          (\\<exists>ys. (n,\\<Gamma>,(Skip,snd(last ((c1', s')#xs')))#ys) \\<in> cptn_mod_nest_call \\<and>                   \n                 xs=(map (lift_catch c2) xs')@((Skip,snd(last ((c1', s')#xs')))#ys)))\"          \n        by blast\n  then have \"(xs = map (lift_catch c2) xs' \\<or>\n          fst (((c1', s') # xs') ! length xs') = Throw \\<and>\n          snd (last ((c1', s') # xs')) = Normal sa' \\<and> s' = Normal sa'' \\<and>\n          (\\<exists>ys. (n,\\<Gamma>, (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n                xs = map (lift_catch c2) xs' @\n                (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<or>\n          fst (((c1', s') # xs') ! length xs') = Skip \\<and>\n          (\\<exists>ys. (n,\\<Gamma>,(Skip,snd(last ((c1', s')#xs')))#ys) \\<in> cptn_mod_nest_call \\<and>                   \n                 xs=(map (lift_catch c2) xs')@((Skip,snd(last ((c1', s')#xs')))#ys)))\"          \n        by auto\n  thus ?case \n  proof{           \n       assume c1'nonf:\"xs = map (lift_catch c2) xs'\"\n       then have c1'cptn:\"(n,\\<Gamma>, (c1', s') # xs') \\<in> cptn_mod_nest_call\" using split by blast\n       then have induct_step: \"(n, \\<Gamma>, (c1, s) # (c1', s')#xs') \\<in> cptn_mod_nest_call\"\n         using Catchc.hyps(2) Catchc.prems(2) SmallStepCon.redex.simps(11) by auto  \n       then have \"(Catch c1' c2, s')#xs = map (lift_catch c2) ((c1', s')#xs')\"\n            using c1'nonf\n            by (simp add: CptnModCatch1 lift_catch_def)\n       thus ?thesis \n            using c1'nonf c1'cptn induct_step \n       by (auto simp add: CptnModNestCatch1)\n    next\n      assume \"fst (((c1', s') # xs') ! length xs') = Throw \\<and>\n                snd (last ((c1', s') # xs')) = Normal sa' \\<and> s' = Normal sa'' \\<and>\n                (\\<exists>ys. (n,\\<Gamma>, (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n                xs =map (lift_catch c2) xs' @ (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<or>\n               fst (((c1', s') # xs') ! length xs') = Skip \\<and>\n                (\\<exists>ys. (n,\\<Gamma>,(Skip,snd(last ((c1', s')#xs')))#ys) \\<in> cptn_mod_nest_call \\<and>                   \n                 xs=(map (lift_catch c2) xs')@((Skip,snd(last ((c1', s')#xs')))#ys))\"  \n      thus ?thesis\n      proof\n         assume assth:\n               \"fst (((c1', s') # xs') ! length xs') = Throw \\<and>\n                snd (last ((c1', s') # xs')) = Normal sa' \\<and> s' = Normal sa'' \\<and>\n                (\\<exists>ys. (n,\\<Gamma>, (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n                xs =map (lift_catch c2) xs' @ (c2, snd (((c1', s') # xs') ! length xs')) # ys)\"\n             then have s'eqsa'': \"s'=Normal sa''\" by auto\n             then have snormal: \"\\<exists>ns. s=Normal ns\" by (metis Catchc.hyps(1) step_Abrupt_prop step_Fault_prop step_Stuck_prop xstate.exhaust)\n             then obtain ys \n             where split':\"(n,\\<Gamma>, (c2, snd (((c1', s') # xs') ! length xs')) # ys) \\<in> cptn_mod_nest_call \\<and>\n                xs =map (lift_catch c2) xs' @ (c2, snd (((c1', s') # xs') ! length xs')) # ys\"\n                using assth by auto    \n         then have c1'cptn:\"(n,\\<Gamma>, (c1', s') # xs') \\<in> cptn_mod_nest_call\" \n              using split by blast\n         then have induct_step: \"(n,\\<Gamma>, (c1, s) # (c1', s')#xs') \\<in> cptn_mod_nest_call\"\n              using Catchc.hyps(2) Catchc.prems(2) SmallStepCon.redex.simps(11) by auto                \n         then have seqmap:\"(Catch c1 c2, s)#(Catch c1' c2, s')#xs = map (lift_catch c2) ((c1,s)#(c1', s')#xs') @ (c2, snd (((c1', s') # xs') ! length xs')) # ys\"\n              using split' by (simp add: CptnModCatch3 lift_catch_def) \n        then have lastc1:\"last ((c1, s) # (c1', s') # xs') = ((c1', s') # xs') ! length xs'\"\n             by (simp add: last_length) \n        then have lastc1skip:\"fst (last ((c1, s) # (c1', s') # xs')) = Throw\" \n             using assth by fastforce\n        then have \"snd (last ((c1, s) # (c1', s') # xs')) = Normal sa'\"\n             using assth by force\n        thus ?thesis using snormal seqmap s'eqsa'' split' \n              last_length  cptn_mod_nest_call.CptnModNestCatch3 \n              induct_step lastc1 lastc1skip\n              using Cons_lift_catch_append by fastforce           \n    next\n        assume assm:\" fst (((c1', s') # xs') ! length xs') = Skip \\<and> \n                       (\\<exists>ys. (n,\\<Gamma>,(Skip,snd(last ((c1', s')#xs')))#ys) \\<in> cptn_mod_nest_call \\<and>                   \n                      xs=(map (lift_catch c2) xs')@((Skip,snd(last ((c1', s')#xs')))#ys))\"\n        then have c1'cptn:\"(n,\\<Gamma>, (c1', s') # xs') \\<in> cptn_mod_nest_call\" using split by blast\n        then have induct_step: \"(n,\\<Gamma>, (c1, s) # (c1', s')#xs') \\<in> cptn_mod_nest_call\"\n        using Catchc.hyps(2) Catchc.prems(2) SmallStepCon.redex.simps(11) by auto \n        then have \"map (lift_catch c2) ((c1', s') # xs') = (Catch c1' c2, s') # map (lift_catch c2) xs'\" \n          by (auto simp add: lift_catch_def)\n        then obtain ys \n             where seqmap:\"(Catch c1' c2, s')#xs = (map (lift_catch c2) ((c1', s')#xs'))@((Skip,snd(last ((c1', s')#xs')))#ys)\"\n        using assm by fastforce\n        then have lastc1:\"last ((c1, s) # (c1', s') # xs') = ((c1', s') # xs') ! length xs'\"\n                   by (simp add: last_length) \n        then have lastc1skip:\"fst (last ((c1, s) # (c1', s') # xs')) = Skip\" \n             using assm by fastforce\n        then have \"snd (last ((c1, s) # (c1', s') # xs')) = snd (last ((c1', s') # xs'))\"\n             using assm by force\n        thus ?thesis \n            using assm c1'cptn induct_step lastc1skip seqmap \n            by (auto simp add:cptn_mod_nest_call.CptnModNestCatch2)\n    qed\n  }qed              \nnext\n  case (CatchThrowc c2 s)\n  have c2incptn:\"(n,\\<Gamma>, (c2, Normal s) # xs) \\<in> cptn_mod_nest_call\" by fact\n  then have 1:\"(n,\\<Gamma>, [(Throw, Normal s)]) \\<in> cptn_mod_nest_call\" \n    by (simp add: cptn_mod_nest_call.CptnModNestOne)\n  then have 2:\"fst(last ([(Throw, Normal s)])) = Throw\" by fastforce\n  then have 3:\"(n,\\<Gamma>,(c2, snd(last [(Throw, Normal s)]))#xs) \\<in> cptn_mod_nest_call\" \n      using c2incptn by auto  \n  then have \"(c2,Normal s)#xs=(map (lift c2) [])@(c2, snd(last [(Throw, Normal s)]))#xs\" \n       by (auto simp add:lift_def)\n  thus ?case using 1 2 3 by (simp add: CptnModNestCatch3)\nnext\n  case (CatchSkipc c2 s)\n  have \"(n,\\<Gamma>, [(Skip, s)]) \\<in> cptn_mod_nest_call\" \n    by (simp add: cptn_mod_nest_call.CptnModNestOne)\n  then obtain ys where \n    ys_nil:\"ys=[]\" and \n    last:\"(n,\\<Gamma>, (Skip,  s)#ys)\\<in> cptn_mod_nest_call\"\n    by auto\n  moreover have \"fst (last ((Skip,  s)#ys)) = Skip\" using ys_nil last by auto\n  moreover have \"snd (last ((Skip,  s)#ys)) = s\" using ys_nil last by auto\n  moreover from ys_nil have \"(map (lift_catch c2) ys) = []\" by auto  \n  ultimately show ?case using CatchSkipc.prems \n     by simp (simp add: cptn_mod_nest_call.CptnModNestCatch2 ys_nil)\nnext\n  case (FaultPropc c f)\n  thus ?case by (simp add: cptn_mod_nest_call.CptnModNestSkip stepc.FaultPropc) \nnext\n  case (AbruptPropc c f)\n  thus ?case by (simp add: cptn_mod_nest_call.CptnModNestSkip stepc.AbruptPropc)\nnext\n  case (StuckPropc c)\n  thus ?case by (simp add: cptn_mod_nest_call.CptnModNestSkip stepc.StuckPropc)\nqed\n\n\n\n\nlemma not_func_redex_cptn_mod_nest_n_env: \nassumes a0:\"\\<Gamma>\\<turnstile>\\<^sub>c (P,s) \\<rightarrow>\\<^sub>e (P, t)\" and\n        a1:\"(n,\\<Gamma>,(P,t)#xs) \\<in>  cptn_mod_nest_call\"         \nshows \"(n,\\<Gamma>,(P,s)#(P,t)#xs) \\<in>  cptn_mod_nest_call\"\n  by (simp add: a0 a1 cptn_mod_nest_call.CptnModNestEnv)\n\n\nlemma cptn_mod_nest_cptn_mod:\"(n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call  \\<Longrightarrow> (\\<Gamma>,cfs)\\<in> cptn_mod\"\nby (induct rule:cptn_mod_nest_call.induct, (fastforce simp:cptn_mod.intros )+)\n\n\nlemma cptn_mod_cptn_mod_nest: \"(\\<Gamma>,cfs)\\<in> cptn_mod \\<Longrightarrow> \\<exists>n. (n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call\"\nproof (induct rule:cptn_mod.induct)\n   case (CptnModSkip \\<Gamma> P s t xs) \n   then obtain n where cptn_nest:\"(n, \\<Gamma>, (Skip, t) # xs) \\<in> cptn_mod_nest_call\" by auto   \n    {assume asm:\"\\<forall>f. ((\\<exists>sn. s = Normal sn) \\<and> (\\<Gamma> f) = Some Skip \\<longrightarrow> P  \\<noteq> Call f  )\"     \n     then have ?case using CptnModNestSkip[OF CptnModSkip(1) CptnModSkip(2) asm cptn_nest] by auto\n    }note t1=this\n    {assume asm:\"\\<not> (\\<forall>f. ((\\<exists>sn. s = Normal sn) \\<and> (\\<Gamma> f) = Some Skip \\<longrightarrow> P  \\<noteq> Call f))\"\n     then obtain f where asm:\"((\\<exists>sn. s = Normal sn) \\<and> (\\<Gamma> f) = Some Skip \\<and> P  = Call f)\" by auto \n      then obtain sn where normal_s:\"s=Normal sn\" by auto\n     then have t_eq_s:\"t=s\" using asm cptn_nest normal_s\n       by (metis CptnModSkip.hyps(1) LanguageCon.com.simps(22) \n           LanguageCon.inter_guards.simps(79) LanguageCon.inter_guards_Call \n           Pair_inject stepc_Normal_elim_cases(9))\n     then have \"(Suc n, \\<Gamma>,((Call f), Normal sn)#(Skip, Normal sn)#xs) \\<in> cptn_mod_nest_call\"\n       using asm cptn_nest normal_s CptnModNestCall by fastforce        \n     then have ?case using asm normal_s t_eq_s by fastforce\n    }note t2 = this\n    then show ?case using t1 t2 by fastforce  \nnext\n   case (CptnModThrow \\<Gamma> P s t xs)  \n   then obtain n where cptn_nest:\"(n, \\<Gamma>, (Throw, t) # xs) \\<in> cptn_mod_nest_call\" by auto   \n    {assume asm:\"\\<forall>f. ((\\<exists>sn. s = Normal sn) \\<and> (\\<Gamma> f) = Some Throw \\<longrightarrow> P  \\<noteq> Call f  )\"     \n     then have ?case using CptnModNestThrow[OF CptnModThrow(1) CptnModThrow(2) asm cptn_nest] by auto\n    }note t1=this\n    {assume asm:\"\\<not> (\\<forall>f. ((\\<exists>sn. s = Normal sn) \\<and> (\\<Gamma> f) = Some Throw \\<longrightarrow> P  \\<noteq> Call f))\"\n     then obtain f where asm:\"((\\<exists>sn. s = Normal sn) \\<and> (\\<Gamma> f) = Some Throw \\<and> P  = Call f)\" by auto \n      then obtain sn where normal_s:\"s=Normal sn\" by auto\n     then have t_eq_s:\"t=s\" using asm cptn_nest normal_s\n       by (metis CptnModThrow.hyps(1) LanguageCon.com.simps(22) \n           LanguageCon.inter_guards.simps(79) LanguageCon.inter_guards_Call \n           Pair_inject stepc_Normal_elim_cases(9))\n     then have \"(Suc n, \\<Gamma>,((Call f), Normal sn)#(Throw, Normal sn)#xs) \\<in> cptn_mod_nest_call\"\n       using asm cptn_nest normal_s CptnModNestCall by fastforce        \n     then have ?case using asm normal_s t_eq_s by fastforce\n    }note t2 = this\n    then show ?case using t1 t2 by fastforce\nnext\n   case (CptnModSeq2 \\<Gamma> P0 s xs P1 ys zs) \n   obtain n where n:\"(n, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call\" using CptnModSeq2(2) by auto\n   also obtain m where m:\"(m, \\<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n     using CptnModSeq2(5) by auto\n   ultimately show ?case\n   proof (cases \"n\\<ge>m\") \n     case True thus ?thesis  \n       using cptn_mod_nest_mono[of m \\<Gamma> _ n] m n CptnModSeq2 cptn_mod_nest_call.CptnModNestSeq2 by blast\n   next  \n     case False \n     thus ?thesis\n       using cptn_mod_nest_mono[of n \\<Gamma> _ m] m n CptnModSeq2 \n             cptn_mod_nest_call.CptnModNestSeq2 le_cases3 by blast      \n   qed\nnext\n   case (CptnModSeq3 \\<Gamma> P0 s xs s' ys zs P1) \n   obtain n where n:\"(n, \\<Gamma>, (P0, Normal s) # xs) \\<in> cptn_mod_nest_call\" using CptnModSeq3(2) by auto\n   also obtain m where m:\"(m, \\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn_mod_nest_call\"\n     using CptnModSeq3(6) by auto\n   ultimately show ?case\n   proof (cases \"n\\<ge>m\") \n     case True thus ?thesis  \n       using cptn_mod_nest_mono[of m \\<Gamma> _ n] m n CptnModSeq3 cptn_mod_nest_call.CptnModNestSeq3\n       by fastforce\n   next  \n     case False \n     thus ?thesis\n       using cptn_mod_nest_mono[of n \\<Gamma> _ m] m n CptnModSeq3\n             cptn_mod_nest_call.CptnModNestSeq3 le_cases3\n      proof -\n        have f1: \"\\<not> n \\<le> m \\<or> (m, \\<Gamma>, (P0, Normal s) # xs) \\<in> cptn_mod_nest_call\"\n          by (metis cptn_mod_nest_mono[of n \\<Gamma> _ m] n)\n        have \"n \\<le> m\"\n          using False by linarith\n        then have \"(m, \\<Gamma>, (P0, Normal s) # xs) \\<in> cptn_mod_nest_call\"\n          using f1 by metis\n        then show ?thesis\n          by (metis (no_types) CptnModSeq3(3) CptnModSeq3(4) CptnModSeq3(7) \n                   cptn_mod_nest_call.CptnModNestSeq3 m)\n      qed          \n   qed\nnext\n   case (CptnModWhile2 \\<Gamma> P s xs b zs ys) \n   obtain n where n:\"(n, \\<Gamma>, (P, Normal s) # xs) \\<in> cptn_mod_nest_call\" using CptnModWhile2(2) by auto\n   also obtain m where \n     m:\" (m, \\<Gamma>, (LanguageCon.com.While b P, snd (last ((P, Normal s) # xs))) # ys) \\<in> \n          cptn_mod_nest_call\"\n     using CptnModWhile2(7) by auto\n   ultimately show ?case\n   proof (cases \"n\\<ge>m\") \n     case True thus ?thesis  \n       using cptn_mod_nest_mono[of m \\<Gamma> _ n] m n \n             CptnModWhile2 cptn_mod_nest_call.CptnModNestWhile2 by metis\n   next  \n     case False \n     thus ?thesis       \n    proof -\n      have f1: \"\\<not> n \\<le> m \\<or> (m, \\<Gamma>, (P, Normal s) # xs) \\<in> cptn_mod_nest_call\"\n        using cptn_mod_nest_mono[of n \\<Gamma> _ m] n by presburger\n      have \"n \\<le> m\"\n        using False by linarith\n      then have \"(m, \\<Gamma>, (P, Normal s) # xs) \\<in> cptn_mod_nest_call\"\n        using f1 by metis\n      then show ?thesis\n        by (metis (no_types) CptnModWhile2(3) CptnModWhile2(4) CptnModWhile2(5) \n                  cptn_mod_nest_call.CptnModNestWhile2 m)\n    qed \n   qed\nnext\n   case (CptnModWhile3 \\<Gamma> P s xs b s' ys zs)\n   obtain n where n:\"(n, \\<Gamma>, (P, Normal s) # xs) \\<in> cptn_mod_nest_call\" \n     using CptnModWhile3(2) by auto\n   also obtain m where \n     m:\" (m, \\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn_mod_nest_call\"\n     using CptnModWhile3(7) by auto\n   ultimately show ?case\n   proof (cases \"n\\<ge>m\") \n     case True thus ?thesis  \n     proof -\n      have \"(n, \\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn_mod_nest_call\"\n        using True cptn_mod_nest_mono[of m \\<Gamma> _ n] m by presburger\n      then show ?thesis\n        by (metis (no_types) CptnModWhile3.hyps(3) CptnModWhile3.hyps(4) \n            CptnModWhile3.hyps(5) CptnModWhile3.hyps(8) cptn_mod_nest_call.CptnModNestWhile3 n)\n     qed \n   next  \n     case False \n     thus ?thesis  using m n cptn_mod_nest_call.CptnModNestWhile3 cptn_mod_nest_mono[of n \\<Gamma> _ m]\n       by (metis CptnModWhile3.hyps(3) CptnModWhile3.hyps(4) \n           CptnModWhile3.hyps(5) CptnModWhile3.hyps(8) le_cases)\n   qed\nnext\n  case (CptnModCatch2 \\<Gamma> P0 s xs ys zs P1) \n  obtain n where n:\"(n, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call\" using CptnModCatch2(2) by auto\n   also obtain m where m:\"(m, \\<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n     using CptnModCatch2(5) by auto\n   ultimately show ?case\n   proof (cases \"n\\<ge>m\") \n     case True thus ?thesis  \n       using cptn_mod_nest_mono[of m \\<Gamma> _ n] m n \n             CptnModCatch2 cptn_mod_nest_call.CptnModNestCatch2 by blast\n   next  \n     case False \n     thus ?thesis\n       using cptn_mod_nest_mono[of n \\<Gamma> _ m] m n CptnModCatch2 \n             cptn_mod_nest_call.CptnModNestCatch2 le_cases3 by blast      \n   qed\nnext\n  case (CptnModCatch3 \\<Gamma> P0 s xs s' ys zs P1) \n   obtain n where n:\"(n, \\<Gamma>, (P0, Normal s) # xs) \\<in> cptn_mod_nest_call\" \n     using CptnModCatch3(2) by auto\n   also obtain m where m:\"(m, \\<Gamma>, (ys, snd (last ((P0, Normal s) # xs))) # zs) \\<in> cptn_mod_nest_call\"\n     using CptnModCatch3(6) by auto\n   ultimately show ?case\n   proof (cases \"n\\<ge>m\") \n     case True thus ?thesis  \n       using cptn_mod_nest_mono[of m \\<Gamma> _ n] m n CptnModCatch3 cptn_mod_nest_call.CptnModNestCatch3\n       by fastforce\n   next  \n     case False \n     thus ?thesis\n       using cptn_mod_nest_mono[of n \\<Gamma> _ m] m n CptnModCatch3 \n             cptn_mod_nest_call.CptnModNestCatch3 le_cases3\n      proof -\n        have f1: \"\\<not> n \\<le> m \\<or> (m, \\<Gamma>, (P0, Normal s) # xs) \\<in> cptn_mod_nest_call\"\n          using \\<open>\\<And>cfs. \\<lbrakk>(n, \\<Gamma>, cfs) \\<in> cptn_mod_nest_call; n \\<le> m\\<rbrakk> \\<Longrightarrow> (m, \\<Gamma>, cfs) \\<in> cptn_mod_nest_call\\<close> n by presburger\n        have \"n \\<le> m\"\n          using False by auto\n        then have \"(m, \\<Gamma>, (P0, Normal s) # xs) \\<in> cptn_mod_nest_call\"\n          using f1 by meson\n        then show ?thesis\n          by (metis (no_types) \\<open>P1 = map (lift_catch ys) xs @ (ys, snd (last ((P0, Normal s) # xs))) # zs\\<close> \\<open>fst (last ((P0, Normal s) # xs)) = LanguageCon.com.Throw\\<close> \\<open>snd (last ((P0, Normal s) # xs)) = Normal s'\\<close> cptn_mod_nest_call.CptnModNestCatch3 m)\n      qed      \n   qed\nqed(fastforce intro: cptn_mod_nest_call.intros)+\n\nlemma cptn_mod_eq_cptn_mod_nest:\n  \"(\\<Gamma>,cfs)\\<in> cptn_mod \\<longleftrightarrow> (\\<exists>n. (n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call)\"\n  using cptn_mod_cptn_mod_nest cptn_mod_nest_cptn_mod by auto\n\nlemma cptn_mod_eq_cptn_mod_nest':\n  \"\\<exists>n. ((\\<Gamma>,cfs)\\<in> cptn_mod \\<longleftrightarrow> (n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call)\"\n  using cptn_mod_eq_cptn_mod_nest by auto\n\nlemma cptn_mod_eq_cptn_mod_nest1:\n  \"(\\<Gamma>,cfs)\\<in> cptn_mod = (\\<exists>n. (n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call)\"\n  using cptn_mod_cptn_mod_nest cptn_mod_nest_cptn_mod by auto\n\n\nlemma cptn_eq_cptn_mod_nest:\n  \"(\\<Gamma>,cfs)\\<in> cptn = (\\<exists>n. (n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call)\"\n  using cptn_eq_cptn_mod_set cptn_mod_cptn_mod_nest cptn_mod_nest_cptn_mod by blast\n\n\nsubsection \\<open>computation on nested calls limit\\<close>\nsubsection \\<open>Elimination theorems\\<close>\nlemma mod_env_not_component:\nshows    \"\\<not> \\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow> (P, t)\"\nproof \n  assume a3:\"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow> (P, t)\"           \n  thus  False using step_change_p_or_eq_s a3 by fastforce\nqed\n\nlemma elim_cptn_mod_nest_step_c:\n assumes a0:\"(n,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" and\n         a1:\"cfg = (P,s)#(Q,t)#cfg1\"         \n shows \"\\<Gamma>\\<turnstile>\\<^sub>c (P,s) \\<rightarrow> (Q,t) \\<or> \\<Gamma>\\<turnstile>\\<^sub>c (P,s) \\<rightarrow>\\<^sub>e (Q,t)\"\nproof-\n  have \"(\\<Gamma>,cfg) \\<in>  cptn\" using a0 cptn_mod_nest_cptn_mod\n    using cptn_eq_cptn_mod_set by auto \n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c (P,s) \\<rightarrow>\\<^sub>c\\<^sub>e (Q,t)\" using a1\n    by (metis c_step cptn_elim_cases(2) e_step)\n  thus ?thesis\n    using step_ce_not_step_e_step_c by blast  \nqed\n\nlemma elim_cptn_mod_nest_call_env:\n assumes a0:\"(n,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" and\n         a1:\"cfg = (P,s)#(P,t)#cfg1\"  and\n         a2:\"\\<forall>f. \\<Gamma> f = Some (LanguageCon.com.Call f) \\<and> \n                 (\\<exists>sn. s = Normal sn) \\<and> s = t \\<longrightarrow> SmallStepCon.redex P \\<noteq> LanguageCon.com.Call f\"\n shows \"(n,\\<Gamma>,(P,t)#cfg1) \\<in>  cptn_mod_nest_call\"\n using a0 a1 a2\nproof (induct arbitrary: P cfg1 s t rule:cptn_mod_nest_call.induct ) \ncase (CptnModNestSeq1 n \\<Gamma> P0 sa xs zs P1)\n   then obtain xs' where \"xs =  (P0, t)#xs'\" unfolding lift_def by fastforce\n   then have step:\"(n, \\<Gamma>, (P0, t) # xs') \\<in> cptn_mod_nest_call\" using CptnModNestSeq1 by fastforce        \n   have \"(P, t) = lift P1 (P0, t) \\<and> cfg1 = map (lift P1) xs'\"\n      using CptnModNestSeq1.hyps(3) CptnModNestSeq1.prems(1) \\<open>xs = (P0, t) # xs'\\<close> by auto\n    then have \"(n, \\<Gamma>, (LanguageCon.com.Seq P0 P1, t) # cfg1) \\<in> cptn_mod_nest_call\"\n      by (meson cptn_mod_nest_call.CptnModNestSeq1 local.step)\n    then show ?case\n      using CptnModNestSeq1.prems(1) by fastforce  \nnext\n  case (CptnModNestSeq2 n \\<Gamma> P0 sa xs P1 ys zs) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs') \n    then have x:\"x=(P0,t)\" \n    proof-\n      have \"zs=(Seq P0 P1,t)#cfg1\" using Cons by fastforce\n      thus ?thesis using Cons(7) unfolding lift_def\n      proof -\n        assume \"zs = map (\\<lambda>a. case a of (P, s) \\<Rightarrow> (LanguageCon.com.Seq P P1, s)) (x # xs') @ \n                     (P1, snd (last ((P0, sa) # x # xs'))) # ys\"\n        then have \"LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0 P1 \\<and> snd x = t\"\n          by (simp add: \\<open>zs = (LanguageCon.com.Seq P0 P1, t) # cfg1\\<close> case_prod_beta)\n        then show ?thesis\n          by fastforce\n      qed \n    qed\n    then have step:\"(n, \\<Gamma>, (P0, t) # xs') \\<in> cptn_mod_nest_call\" using Cons by fastforce         \n    have \"fst (last ((P0, t) # xs')) = LanguageCon.com.Skip\"\n      using Cons.prems(3) \\<open>x = (P0, t)\\<close> by force\n    then show ?case\n      using Cons.prems(4) Cons.prems(6) CptnModNestSeq2.prems(1) x \n            cptn_mod_nest_call.CptnModNestSeq2 local.step by fastforce\n  qed          \nnext \n  case (CptnModNestSeq3 n \\<Gamma> P0 sa xs s' ys zs P1) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs') \n    then have x:\"x=(P0,t)\" \n    proof-\n      have zs:\"zs=(Seq P0 P1,t)#cfg1\" using Cons by fastforce\n      have \"(LanguageCon.com.Seq (fst x) P1, snd x) = lift P1 x\"\n         by (simp add: lift_def prod.case_eq_if)\n      then have \"LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0 P1 \\<and> snd x = t\"\n         using Cons.prems(7) zs by force\n      then show ?thesis\n          by fastforce                \n    qed\n    then have step:\"(n, \\<Gamma>, (P0, t) # xs') \\<in> cptn_mod_nest_call\" using Cons by fastforce         \n    then obtain t' where t:\"t=Normal t'\" \n      using Normal_Normal Cons(2) Cons(5) cptn_mod_nest_cptn_mod cptn_eq_cptn_mod_set x\n      by (metis snd_eqD)\n    then show ?case using x Cons(5) Cons(6) cptn_mod_nest_call.CptnModNestSeq3 step\n    proof -\n      have \"last ((P0, Normal t') # xs') = last ((P0, Normal sa) # x # xs')\"\n        using t x by force\n      then have \"fst (last ((P0, Normal t') # xs')) = LanguageCon.com.Throw\"\n        using Cons.prems(3) by presburger\n      then show ?thesis\n        using Cons.prems(4) Cons.prems(5) Cons.prems(7) \n              CptnModNestSeq3.prems(1) cptn_mod_nest_call.CptnModNestSeq3 \n              local.step t x by fastforce\n    qed       \n  qed       \nnext\n  case (CptnModNestCatch1 n \\<Gamma> P0 s xs zs P1) \n   then obtain xs' where \"xs =  (P0, t)#xs'\" unfolding lift_catch_def by fastforce\n   then have step:\"(n, \\<Gamma>, (P0, t) # xs') \\<in> cptn_mod_nest_call\" using CptnModNestCatch1 by fastforce        \n   have \"(P, t) = lift_catch P1 (P0, t) \\<and> cfg1 = map (lift_catch P1) xs'\"\n      using CptnModNestCatch1.hyps(3) CptnModNestCatch1.prems(1) \\<open>xs = (P0, t) # xs'\\<close> by auto\n    then have \"(n, \\<Gamma>, (Catch P0 P1, t) # cfg1) \\<in> cptn_mod_nest_call\"\n      by (meson cptn_mod_nest_call.CptnModNestCatch1 local.step)\n    then show ?case\n      using CptnModNestCatch1.prems(1) by fastforce  \nnext\n  case (CptnModNestCatch2 n \\<Gamma> P0 sa xs ys zs P1) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs') \n    then have x:\"x=(P0,t)\" \n    proof-\n      have zs:\"zs=(Catch P0 P1,t)#cfg1\" using Cons by fastforce\n      have \"(LanguageCon.com.Catch (fst x) P1, snd x) = lift_catch P1 x\"\n         by (simp add: lift_catch_def prod.case_eq_if)\n      then have \"LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0 P1 \\<and> snd x = t\"\n         using Cons.prems(6) zs by fastforce           \n      then show ?thesis\n          by fastforce                \n    qed\n    then have step:\"(n, \\<Gamma>, (P0, t) # xs') \\<in> cptn_mod_nest_call\" using Cons by fastforce             \n    have \"fst (last ((P0, t) # xs')) = LanguageCon.com.Skip\"\n      using Cons.prems(3) x by auto\n    then show ?case\n      using Cons.prems(4) Cons.prems(6) CptnModNestCatch2.prems(1) \n            cptn_mod_nest_call.CptnModNestCatch2 local.step x by fastforce \n  qed          \nnext\n  case (CptnModNestCatch3 n \\<Gamma> P0 sa xs s' P1 ys zs) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs')\n    then have x:\"x=(P0,t)\" \n    proof-\n      have zs:\"zs=(Catch P0 P1,t)#cfg1\" using Cons by fastforce\n      thus ?thesis using Cons(8) lift_catch_def unfolding lift_def\n      proof -\n        assume \"zs = map (lift_catch P1) (x # xs') @ (P1, snd (last ((P0, Normal sa) # x # xs'))) # ys\"\n        then have \"LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0 P1 \\<and> snd x = t\"\n          by (simp add: case_prod_unfold lift_catch_def zs)          \n        then show ?thesis\n          by fastforce\n      qed \n    qed\n    then have step:\"(n, \\<Gamma>, (P0, t) # xs') \\<in> cptn_mod_nest_call\" using Cons by fastforce\n    then obtain t' where t:\"t=Normal t'\" \n      using Normal_Normal Cons(2) Cons(5) cptn_mod_nest_cptn_mod cptn_eq_cptn_mod_set x\n      by (metis snd_eqD)\n    then show ?case \n    proof -\n      have \"last ((P0, Normal t') # xs') = last ((P0, Normal sa) # x # xs')\"\n        using t x by force\n      then have \"fst (last ((P0, Normal t') # xs')) = LanguageCon.com.Throw\"\n        using Cons.prems(3) by presburger\n      then show ?thesis\n        using Cons.prems(4) Cons.prems(5) Cons.prems(7) \n              CptnModNestCatch3.prems(1) cptn_mod_nest_call.CptnModNestCatch3 \n              local.step t x by fastforce\n    qed\n  qed   \nqed(fastforce+)\n\n\nlemma elim_cptn_mod_nest_not_env_call:\n assumes a0:\"(n,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" and\n         a1:\"cfg = (P,s)#(Q,t)#cfg1\" and\n         a2:\"(\\<forall>f. redex P \\<noteq> Call f) \\<or>  \n             SmallStepCon.redex P = LanguageCon.com.Call fn \\<and> \\<Gamma> fn = None \\<or>\n            (redex P = Call fn \\<and> (\\<forall>sa. s\\<noteq>Normal sa))\"  \n shows \"(n,\\<Gamma>,(Q,t)#cfg1) \\<in>  cptn_mod_nest_call\"\n using a0 a1 a2\nproof (induct arbitrary: P Q cfg1 s t rule:cptn_mod_nest_call.induct )\ncase (CptnModNestSeq1 n \\<Gamma> P0 s xs zs P1)\n   then obtain P0' xs' where \"xs =  (P0', t)#xs'\" unfolding lift_def by fastforce\n   then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\" using CptnModNestSeq1 by fastforce        \n   have Q:\"(Q, t) = lift P1 (P0', t) \\<and> cfg1 = map (lift P1) xs'\"\n     using CptnModNestSeq1.hyps(3) CptnModNestSeq1.prems(1) \\<open>xs = (P0', t) # xs'\\<close> by auto\n   also then have \"(n, \\<Gamma>, (LanguageCon.com.Seq P0' P1, t) # cfg1) \\<in> cptn_mod_nest_call\"\n     by (meson cptn_mod_nest_call.CptnModNestSeq1 local.step)\n   ultimately show ?case\n     using CptnModNestSeq1.prems(1)\n     by (simp add: Cons_lift Q)   \nnext\n  case (CptnModNestSeq2 n \\<Gamma> P0 sa xs P1 ys zs) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs')\n    then have x:\"\\<exists>P0'. x=(P0',t)\" \n    proof-\n      obtain P0'' where zs: \"zs=(Seq P0'' P1,t)#cfg1\" using Cons(7) Cons(8) \n        unfolding lift_def by (simp add: Cons_eq_append_conv case_prod_beta') \n      thus ?thesis using Cons(7) unfolding lift_def\n      proof -\n        assume \"zs = map (\\<lambda>a. case a of (P, s) \\<Rightarrow> (LanguageCon.com.Seq P P1, s)) (x # xs') @ \n                     (P1, snd (last ((P0, sa) # x # xs'))) # ys\"\n        then have \"LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0'' P1 \\<and> snd x = t\"\n          by (simp add: zs case_prod_beta)\n        also have \"sa=s\" using Cons by fastforce\n        ultimately show ?thesis by (meson eq_snd_iff)           \n      qed \n    qed\n    then obtain P0' where x:\"x=(P0',t)\" by auto\n    then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\" using Cons by force\n    have \"fst (last ((P0', t) # xs')) = LanguageCon.com.Skip\"\n      using Cons.prems(3) x by force\n    then show ?case\n      using Cons.prems(4) Cons.prems(6) CptnModNestSeq2.prems(1) x \n           local.step cptn_mod_nest_call.CptnModNestSeq2[of n \\<Gamma> P0' t xs' P1 ys] Cons_lift_append\n           by (metis (no_types, lifting) last_ConsR list.inject list.simps(3))        \n  qed          \nnext \n  case (CptnModNestSeq3 n \\<Gamma> P0 sa xs s' ys zs P1) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs') \n    then have x:\"\\<exists>P0'. x=(P0',t)\"\n    proof-\n      obtain P0' where zs:\"zs=(Seq P0' P1,t)#cfg1\" using Cons(8) Cons(9) \n        unfolding lift_def\n        unfolding lift_def by (simp add: Cons_eq_append_conv case_prod_beta')\n      have \"(LanguageCon.com.Seq (fst x) P1, snd x) = lift P1 x\"\n         by (simp add: lift_def prod.case_eq_if)\n      then have \"LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0' P1 \\<and> snd x = t\"\n         using zs by (simp add: Cons.prems(7)) \n      then show ?thesis by (meson eq_snd_iff)                        \n    qed\n    then obtain P0' where x:\"x=(P0',t)\" by auto\n    then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\"\n    proof -\n      have f1: \"LanguageCon.com.Seq P0 P1 = P \\<and> Normal sa = s\"\n        using CptnModNestSeq3.prems(1) by blast\n      then have \"SmallStepCon.redex P = SmallStepCon.redex P0\"\n        by (metis SmallStepCon.redex.simps(4))\n      then show ?thesis\n        using f1 Cons.prems(2) CptnModNestSeq3.prems(2) x by presburger\n    qed      \n    then obtain t' where t:\"t=Normal t'\" \n      using Normal_Normal Cons(2) Cons(5) cptn_mod_nest_cptn_mod cptn_eq_cptn_mod_set x\n      by (metis snd_eqD)\n    then show ?case using x Cons(5) Cons(6) cptn_mod_nest_call.CptnModNestSeq3 step\n    proof -\n      have \"last ((P0', Normal t') # xs') = last ((P0, Normal sa) # x # xs')\"\n        using t x by force\n      also then have \"fst (last ((P0', Normal t') # xs')) = LanguageCon.com.Throw\"\n        using Cons.prems(3) by presburger\n      ultimately show ?thesis\n        using Cons.prems(4) Cons.prems(5) Cons.prems(7) \n              CptnModNestSeq3.prems(1) cptn_mod_nest_call.CptnModNestSeq3[of n \\<Gamma> P0' t' xs' s' ys] \n              local.step t x  Cons_lift_append\n      by (metis (no_types, lifting) list.sel(3))               \n    qed       \n  qed       \nnext\n  case (CptnModNestCatch1 n \\<Gamma> P0 s xs zs P1) \n   then obtain P0' xs' where xs:\"xs =  (P0', t)#xs'\" unfolding lift_catch_def by fastforce\n   then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\" using CptnModNestCatch1 by fastforce        \n   have Q:\"(Q, t) = lift_catch P1 (P0', t) \\<and> cfg1 = map (lift_catch P1) xs'\"\n      using CptnModNestCatch1.hyps(3) CptnModNestCatch1.prems(1) xs by auto\n    then have \"(n, \\<Gamma>, (Catch P0' P1, t) # cfg1) \\<in> cptn_mod_nest_call\"\n      by (meson cptn_mod_nest_call.CptnModNestCatch1 local.step)\n    then show ?case\n      using CptnModNestCatch1.prems(1) by (simp add:Cons_lift_catch Q)\nnext\n  case (CptnModNestCatch2 n \\<Gamma> P0 sa xs ys zs P1) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs') \n    then have x:\"\\<exists>P0'. x=(P0',t)\" \n    proof-\n      obtain P0' where zs:\"zs=(Catch P0' P1,t)#cfg1\" using Cons unfolding lift_catch_def\n        by (simp add: case_prod_unfold)\n      have \"(LanguageCon.com.Catch (fst x) P1, snd x) = lift_catch P1 x\"\n         by (simp add: lift_catch_def prod.case_eq_if)\n      then have \"LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0' P1 \\<and> snd x = t\"\n         using Cons.prems(6) zs by fastforce           \n      then show ?thesis by (meson eq_snd_iff)          \n    qed\n    then obtain P0' where x:\"x=(P0',t)\" by auto\n    then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\"     \n      using Cons.prems(2) CptnModNestCatch2.prems(1) CptnModNestCatch2.prems(2) x by force\n\n    have skip:\"fst (last ((P0', t) # xs')) = LanguageCon.com.Skip\"\n      using Cons.prems(3) x by auto\n    show ?case\n    proof -\n      have \"(P, s) # (Q, t) # cfg1 = (LanguageCon.com.Catch P0 P1, sa) # map (lift_catch P1) (x # xs') @ \n              (LanguageCon.com.Skip, snd (last ((P0, sa) # x # xs'))) # ys\"\n        using CptnModNestCatch2.prems  Cons.prems(6) by auto\n      then show ?thesis \n        using Cons_lift_catch_append Cons.prems(4) \n              cptn_mod_nest_call.CptnModNestCatch2[OF local.step skip] last.simps list.distinct(1)\n              x \n        by (metis (no_types)  list.sel(3) x)\n    qed\n  qed          \nnext\n  case (CptnModNestCatch3 n \\<Gamma> P0 sa xs s' P1 ys zs) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs')\n    then have x:\"\\<exists>P0'. x=(P0',t)\" \n    proof-\n      obtain P0' where zs:\"zs=(Catch P0' P1,t)#cfg1\" using Cons unfolding lift_catch_def\n        by (simp add: case_prod_unfold)\n      thus ?thesis using Cons(8) lift_catch_def unfolding lift_def\n      proof -\n        assume \"zs = map (lift_catch P1) (x # xs') @ (P1, snd (last ((P0, Normal sa) # x # xs'))) # ys\"\n        then have \"LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0' P1 \\<and> snd x = t\"\n          by (simp add: case_prod_unfold lift_catch_def zs)          \n        then show ?thesis by (meson eq_snd_iff)  \n      qed \n    qed\n    then obtain P0' where x:\"x=(P0',t)\" by auto\n    then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\" using Cons\n      using Cons.prems(2) CptnModNestCatch3.prems(1) CptnModNestCatch3.prems(2) x by force\n    then obtain t' where t:\"t=Normal t'\" \n      using Normal_Normal Cons(2) Cons(5) cptn_mod_nest_cptn_mod cptn_eq_cptn_mod_set x\n      by (metis snd_eqD)\n    then show ?case \n    proof -\n      have \"last ((P0', Normal t') # xs') = last ((P0, Normal sa) # x # xs')\"\n        using t x by force\n      also then have \"fst (last ((P0', Normal t') # xs')) = LanguageCon.com.Throw\"\n        using Cons.prems(3) by presburger\n      ultimately show ?thesis\n        using Cons.prems(4) Cons.prems(5) Cons.prems(7) \n              CptnModNestCatch3.prems(1) cptn_mod_nest_call.CptnModNestCatch3[of n \\<Gamma> P0' t' xs' s' P1] \n              local.step t x by (metis Cons_lift_catch_append list.sel(3)) \n    qed\n  qed\nnext\ncase (CptnModNestWhile1 n \\<Gamma> P0 s' xs b zs) \n  thus ?case\n   using cptn_mod_nest_call.CptnModNestSeq1 list.inject by blast   \nnext\n  case (CptnModNestWhile2 n \\<Gamma> P0 s' xs b zs ys)  \n  have \"(LanguageCon.com.While b P0, Normal s') = (P, s) \\<and> \n        (LanguageCon.com.Seq P0 (LanguageCon.com.While b P0), Normal s') # zs = (Q, t) # cfg1\"\n    using CptnModNestWhile2.prems by fastforce\n  then show ?case\n    using CptnModNestWhile2.hyps(1) CptnModNestWhile2.hyps(3) \n          CptnModNestWhile2.hyps(5) CptnModNestWhile2.hyps(6) \n          cptn_mod_nest_call.CptnModNestSeq2 by blast\nnext\n  case (CptnModNestWhile3 n \\<Gamma> P0 s' xs b zs) thus ?case\n    by (metis (no_types) CptnModNestWhile3.hyps(1) CptnModNestWhile3.hyps(3) CptnModNestWhile3.hyps(5) \n                         CptnModNestWhile3.hyps(6) CptnModNestWhile3.hyps(8) CptnModNestWhile3.prems \n                         cptn_mod_nest_call.CptnModNestSeq3 list.inject)  \nqed(fastforce+)\n\ninductive_cases stepc_call_skip_normal:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Call p,Normal s) \\<rightarrow> (Skip,s')\"\n\nlemma elim_cptn_mod_nest_call_n_greater_zero:\n assumes a0:\"(n,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" and\n         a1:\"cfg = (P,Normal s)#(Q,t)#cfg1 \\<and> P = Call f \\<and> \\<Gamma> f = Some Q \\<and> P\\<noteq>Q\"\n shows  \"n>0\" \n  using a0 a1 by (induct rule:cptn_mod_nest_call.induct, fastforce+)\n\n\nlemma elim_cptn_mod_nest_call_0_False:\n assumes a0:\"(0,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" and\n         a1:\"cfg = (P,Normal s)#(Q,t)#cfg1 \\<and> P = Call f \\<and> \\<Gamma> f = Some Q \\<and> P\\<noteq>Q\"\nshows \"PP\"\nusing a0 a1 elim_cptn_mod_nest_call_n_greater_zero \nby fastforce\n\nlemma elim_cptn_mod_nest_call_n_dec1:\n assumes a0:\"(n,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" and\n         a1:\"cfg = (P,Normal s)#(Q,t)#cfg1 \\<and> P = Call f \\<and> \\<Gamma> f = Some Q \\<and> t= Normal s \\<and> P\\<noteq>Q\"\n shows \"(n-1,\\<Gamma>,(Q,t)#cfg1) \\<in>  cptn_mod_nest_call\"\n using a0 a1 \n  by (induct rule:cptn_mod_nest_call.induct,fastforce+)\n\nlemma elim_cptn_mod_nest_call_n_dec:\n assumes a0:\"(n,\\<Gamma>,(Call f,Normal s)#(the (\\<Gamma> f),Normal s)#cfg1) \\<in>  cptn_mod_nest_call\" and\n         a1:\"\\<Gamma> f = Some Q \" and a2:\"Call f\\<noteq>the (\\<Gamma> f)\"\n       shows \"(n-1,\\<Gamma>,(the (\\<Gamma> f),Normal s)#cfg1) \\<in>  cptn_mod_nest_call\"\n  using elim_cptn_mod_nest_call_n_dec1\n using a0 a1 a2\n  by fastforce\n\n\nlemma elim_cptn_mod_nest_call_n:\n assumes a0:\"(n,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" and\n         a1:\"cfg = (P, s)#(Q,t)#cfg1\"          \n shows \"(n,\\<Gamma>,(Q,t)#cfg1) \\<in>  cptn_mod_nest_call\"\n using a0 a1 \nproof (induct arbitrary: P Q cfg1 s t rule:cptn_mod_nest_call.induct )\ncase (CptnModNestCall n \\<Gamma> bdy sa ys p)\n  thus ?case using cptn_mod_nest_mono1 list.inject by blast\nnext \ncase (CptnModNestSeq1 n \\<Gamma> P0 s xs zs P1) \n   then obtain P0' xs' where \"xs =  (P0', t)#xs'\" unfolding lift_def by fastforce\n   then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\" using CptnModNestSeq1 by fastforce        \n   have Q:\"(Q, t) = lift P1 (P0', t) \\<and> cfg1 = map (lift P1) xs'\"\n     using CptnModNestSeq1.hyps(3) CptnModNestSeq1.prems(1) \\<open>xs = (P0', t) # xs'\\<close> by auto\n   also then have \"(n, \\<Gamma>, (LanguageCon.com.Seq P0' P1, t) # cfg1) \\<in> cptn_mod_nest_call\"\n     by (meson cptn_mod_nest_call.CptnModNestSeq1 local.step)\n   ultimately show ?case\n     using CptnModNestSeq1.prems(1)\n     by (simp add: Cons_lift Q)   \nnext\n  case (CptnModNestSeq2 n \\<Gamma> P0 sa xs P1 ys zs) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs')\n    then have x:\"\\<exists>P0'. x=(P0',t)\" \n    proof-\n      obtain P0'' where zs: \"zs=(Seq P0'' P1,t)#cfg1\" using Cons(7) Cons(8) \n        unfolding lift_def by (simp add: Cons_eq_append_conv case_prod_beta') \n      thus ?thesis using Cons(7) unfolding lift_def\n      proof -\n        assume \"zs = map (\\<lambda>a. case a of (P, s) \\<Rightarrow> (LanguageCon.com.Seq P P1, s)) (x # xs') @ \n                     (P1, snd (last ((P0, sa) # x # xs'))) # ys\"\n        then have \"LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0'' P1 \\<and> snd x = t\"\n          by (simp add: zs case_prod_beta)\n        also have \"sa=s\" using Cons by fastforce\n        ultimately show ?thesis by (meson eq_snd_iff)           \n      qed \n    qed\n    then obtain P0' where x:\"x=(P0',t)\" by auto\n    then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\" using Cons by force\n    have \"fst (last ((P0', t) # xs')) = LanguageCon.com.Skip\"\n      using Cons.prems(3) x by force\n    then show ?case\n      using Cons.prems(4) Cons.prems(6) CptnModNestSeq2.prems(1) x \n           local.step cptn_mod_nest_call.CptnModNestSeq2[of n \\<Gamma> P0' t xs' P1 ys] Cons_lift_append\n           by (metis (no_types, lifting) last_ConsR list.inject list.simps(3))        \n  qed          \nnext \n  case (CptnModNestSeq3 n \\<Gamma> P0 sa xs s' ys zs P1) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs') \n    then have x:\"\\<exists>P0'. x=(P0',t)\"\n    proof-\n      obtain P0' where zs:\"zs=(Seq P0' P1,t)#cfg1\" using Cons(8) Cons(9) \n        unfolding lift_def\n        unfolding lift_def by (simp add: Cons_eq_append_conv case_prod_beta')\n      have \"(LanguageCon.com.Seq (fst x) P1, snd x) = lift P1 x\"\n         by (simp add: lift_def prod.case_eq_if)\n      then have \"LanguageCon.com.Seq (fst x) P1 = LanguageCon.com.Seq P0' P1 \\<and> snd x = t\"\n         using zs by (simp add: Cons.prems(7)) \n      then show ?thesis by (meson eq_snd_iff)                        \n    qed\n    then obtain P0' where x:\"x=(P0',t)\" by auto\n    then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\" using Cons by fastforce         \n    then obtain t' where t:\"t=Normal t'\" \n      using Normal_Normal Cons(2) Cons(5) cptn_mod_nest_cptn_mod cptn_eq_cptn_mod_set x\n      by (metis snd_eqD)\n    then show ?case using x Cons(5) Cons(6) cptn_mod_nest_call.CptnModNestSeq3 step\n    proof -\n      have \"last ((P0', Normal t') # xs') = last ((P0, Normal sa) # x # xs')\"\n        using t x by force\n      also then have \"fst (last ((P0', Normal t') # xs')) = LanguageCon.com.Throw\"\n        using Cons.prems(3) by presburger\n      ultimately show ?thesis\n        using Cons.prems(4) Cons.prems(5) Cons.prems(7) \n              CptnModNestSeq3.prems(1) cptn_mod_nest_call.CptnModNestSeq3[of n \\<Gamma> P0' t' xs' s' ys] \n              local.step t x  Cons_lift_append\n      by (metis (no_types, lifting) list.sel(3))               \n    qed       \n  qed       \nnext\n  case (CptnModNestCatch1 n \\<Gamma> P0 s xs zs P1) \n   then obtain P0' xs' where xs:\"xs =  (P0', t)#xs'\" unfolding lift_catch_def by fastforce\n   then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\" using CptnModNestCatch1 by fastforce        \n   have Q:\"(Q, t) = lift_catch P1 (P0', t) \\<and> cfg1 = map (lift_catch P1) xs'\"\n      using CptnModNestCatch1.hyps(3) CptnModNestCatch1.prems(1) xs by auto\n    then have \"(n, \\<Gamma>, (Catch P0' P1, t) # cfg1) \\<in> cptn_mod_nest_call\"\n      by (meson cptn_mod_nest_call.CptnModNestCatch1 local.step)\n    then show ?case\n      using CptnModNestCatch1.prems(1) by (simp add:Cons_lift_catch Q)\nnext\n  case (CptnModNestCatch2 n \\<Gamma> P0 sa xs ys zs P1) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs') \n    then have x:\"\\<exists>P0'. x=(P0',t)\" \n    proof-\n      obtain P0' where zs:\"zs=(Catch P0' P1,t)#cfg1\" using Cons unfolding lift_catch_def\n        by (simp add: case_prod_unfold)\n      have \"(LanguageCon.com.Catch (fst x) P1, snd x) = lift_catch P1 x\"\n         by (simp add: lift_catch_def prod.case_eq_if)\n      then have \"LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0' P1 \\<and> snd x = t\"\n         using Cons.prems(6) zs by fastforce           \n      then show ?thesis by (meson eq_snd_iff)          \n    qed\n    then obtain P0' where x:\"x=(P0',t)\" by auto\n    then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\" using Cons by fastforce             \n    have skip:\"fst (last ((P0', t) # xs')) = LanguageCon.com.Skip\"\n      using Cons.prems(3) x by auto\n    show ?case\n    proof -\n      have \"(P, s) # (Q, t) # cfg1 = (LanguageCon.com.Catch P0 P1, sa) # map (lift_catch P1) (x # xs') @ \n              (LanguageCon.com.Skip, snd (last ((P0, sa) # x # xs'))) # ys\"\n        using CptnModNestCatch2.prems  Cons.prems(6) by auto\n      then show ?thesis \n        using Cons_lift_catch_append Cons.prems(4) \n              cptn_mod_nest_call.CptnModNestCatch2[OF local.step skip] last.simps list.distinct(1)\n              x \n        by (metis (no_types)  list.sel(3) x)\n    qed\n  qed          \nnext\n  case (CptnModNestCatch3 n \\<Gamma> P0 sa xs s' P1 ys zs) \n  thus ?case \n  proof (induct xs)\n    case Nil thus ?case using Nil.prems(6) Nil.prems(7) by force\n  next\n    case (Cons x xs')\n    then have x:\"\\<exists>P0'. x=(P0',t)\" \n    proof-\n      obtain P0' where zs:\"zs=(Catch P0' P1,t)#cfg1\" using Cons unfolding lift_catch_def\n        by (simp add: case_prod_unfold)\n      thus ?thesis using Cons(8) lift_catch_def unfolding lift_def\n      proof -\n        assume \"zs = map (lift_catch P1) (x # xs') @ (P1, snd (last ((P0, Normal sa) # x # xs'))) # ys\"\n        then have \"LanguageCon.com.Catch (fst x) P1 = LanguageCon.com.Catch P0' P1 \\<and> snd x = t\"\n          by (simp add: case_prod_unfold lift_catch_def zs)          \n        then show ?thesis by (meson eq_snd_iff)  \n      qed \n    qed\n    then obtain P0' where x:\"x=(P0',t)\" by auto\n    then have step:\"(n, \\<Gamma>, (P0', t) # xs') \\<in> cptn_mod_nest_call\" using Cons by fastforce\n    then obtain t' where t:\"t=Normal t'\" \n      using Normal_Normal Cons(2) Cons(5) cptn_mod_nest_cptn_mod cptn_eq_cptn_mod_set x\n      by (metis snd_eqD)\n    then show ?case \n    proof -\n      have \"last ((P0', Normal t') # xs') = last ((P0, Normal sa) # x # xs')\"\n        using t x by force\n      also then have \"fst (last ((P0', Normal t') # xs')) = LanguageCon.com.Throw\"\n        using Cons.prems(3) by presburger\n      ultimately show ?thesis\n        using Cons.prems(4) Cons.prems(5) Cons.prems(7) \n              CptnModNestCatch3.prems(1) cptn_mod_nest_call.CptnModNestCatch3[of n \\<Gamma> P0' t' xs' s' P1] \n              local.step t x by (metis Cons_lift_catch_append list.sel(3)) \n    qed\n  qed\nnext\ncase (CptnModNestWhile1 n \\<Gamma> P0 s' xs b zs) \n  thus ?case\n   using cptn_mod_nest_call.CptnModNestSeq1 list.inject by blast   \nnext\n  case (CptnModNestWhile2 n \\<Gamma> P0 s' xs b zs ys)  \n  have \"(LanguageCon.com.While b P0, Normal s') = (P, s) \\<and> \n        (LanguageCon.com.Seq P0 (LanguageCon.com.While b P0), Normal s') # zs = (Q, t) # cfg1\"\n    using CptnModNestWhile2.prems by fastforce\n  then show ?case\n    using CptnModNestWhile2.hyps(1) CptnModNestWhile2.hyps(3) \n          CptnModNestWhile2.hyps(5) CptnModNestWhile2.hyps(6) \n          cptn_mod_nest_call.CptnModNestSeq2 by blast\nnext\n  case (CptnModNestWhile3 n \\<Gamma> P0 s' xs b zs) thus ?case\n    by (metis (no_types) CptnModNestWhile3.hyps(1) CptnModNestWhile3.hyps(3) CptnModNestWhile3.hyps(5) \n                         CptnModNestWhile3.hyps(6) CptnModNestWhile3.hyps(8) CptnModNestWhile3.prems \n                         cptn_mod_nest_call.CptnModNestSeq3 list.inject)  \nqed (fastforce+) \n\n\n\n\ndefinition min_call where\n\"min_call n \\<Gamma> cfs \\<equiv> (n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call \\<and> (\\<forall>m<n. \\<not>((m,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call))\"\n\nlemma minimum_nest_call:\n  \"(m,\\<Gamma>,cfs) \\<in> cptn_mod_nest_call \\<Longrightarrow>\n   \\<exists>n. min_call n \\<Gamma> cfs\"\nunfolding min_call_def\nproof (induct arbitrary: m rule:cptn_mod_nest_call.induct) \n case (CptnModNestOne) thus ?case using cptn_mod_nest_call.CptnModNestOne by blast \nnext\n  case (CptnModNestEnv \\<Gamma> P s t n xs) \n  then have \"\\<not> \\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow> (P, t)\" \n   using mod_env_not_component step_change_p_or_eq_s by blast \n  then obtain min_n where min:\"(min_n, \\<Gamma>, (P, t) # xs) \\<in> cptn_mod_nest_call \\<and> \n                             (\\<forall>m<min_n.  (m, \\<Gamma>, (P, t) # xs) \\<notin> cptn_mod_nest_call)\" \n    using CptnModNestEnv by blast\n  then have  \"(min_n, \\<Gamma>, (P,s)#(P, t) # xs) \\<in> cptn_mod_nest_call\"     \n    using cptn_mod_nest_call.CptnModNestEnv CptnModNestEnv by blast\n  also have \"(\\<forall>m<min_n. (m, \\<Gamma>, (P, s)#(P, t) # xs) \\<notin> cptn_mod_nest_call)\"\n    using elim_cptn_mod_nest_call_n min by fastforce    \n  ultimately show ?case by auto  \nnext\n  case (CptnModNestSkip \\<Gamma> P s t n xs)    \n  then obtain min_n where \n     min:\"(min_n, \\<Gamma>, (LanguageCon.com.Skip, t) # xs) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_n. (m, \\<Gamma>, (LanguageCon.com.Skip, t) # xs) \\<notin> cptn_mod_nest_call)\" \n    by auto\n  then have \"(min_n, \\<Gamma>, (P,s)#(LanguageCon.com.Skip, t) # xs) \\<in> cptn_mod_nest_call\"\n    using cptn_mod_nest_call.CptnModNestSkip CptnModNestSkip by blast\n  also have \"(\\<forall>m<min_n. (m, \\<Gamma>, (P, s)#(LanguageCon.com.Skip, t) # xs) \\<notin> cptn_mod_nest_call)\"\n    using elim_cptn_mod_nest_call_n min by blast      \n  ultimately show ?case by fastforce   \nnext\n   case (CptnModNestThrow \\<Gamma> P s t n xs) thus ?case\n     by (meson cptn_mod_nest_call.CptnModNestThrow elim_cptn_mod_nest_call_n)    \nnext\n  case (CptnModNestCondT n \\<Gamma> P0 s xs b P1) thus ?case\n    by (meson cptn_mod_nest_call.CptnModNestCondT elim_cptn_mod_nest_call_n)\nnext\n  case (CptnModNestCondF n \\<Gamma> P1 s xs b P0) thus ?case\n    by (meson cptn_mod_nest_call.CptnModNestCondF elim_cptn_mod_nest_call_n)\nnext\n  case (CptnModNestSeq1 n \\<Gamma> P s xs zs Q) thus ?case\n    by (metis (no_types, lifting) Seq_P_Not_finish cptn_mod_nest_call.CptnModNestSeq1 div_seq_nest)\nnext\n  case (CptnModNestSeq2 n \\<Gamma> P s xs Q ys zs) \n  then obtain min_p where \n     min_p:\"(min_p, \\<Gamma>, (P,  s) # xs) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_p. (m, \\<Gamma>, (P, s) # xs) \\<notin> cptn_mod_nest_call)\" \n    by auto \n  from CptnModNestSeq2(5) obtain min_q where\n    min_q:\"(min_q, \\<Gamma>, (Q, snd (last ((P, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_q. (m, \\<Gamma>, (Q, snd (last ((P, s) # xs))) # ys) \\<notin> cptn_mod_nest_call)\"\n  by auto\n  thus ?case\n  proof(cases \"min_p\\<ge>min_q\")\n    case True\n    then have \"(min_p, \\<Gamma>, (Q, snd (last ((P,s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n      using min_q using cptn_mod_nest_mono by blast \n    then have \"(min_p, \\<Gamma>, (Seq P Q, s) # zs) \\<in> cptn_mod_nest_call\"\n      using conjunct1[OF min_p] cptn_mod_nest_call.CptnModNestSeq2[of min_p \\<Gamma> P s xs Q ys zs] \n            CptnModNestSeq2(6)  CptnModNestSeq2(3)\n    by blast\n    also have \"\\<forall>m<min_p. (m, \\<Gamma>,(Seq P Q,s) # zs) \\<notin> cptn_mod_nest_call\"\n      by (metis CptnModNestSeq2.hyps(3) CptnModNestSeq2.hyps(6) Seq_P_Ends_Normal div_seq_nest min_p)      \n    ultimately show ?thesis by auto\n  next\n    case False \n    then have \"(min_q, \\<Gamma>, (P,  s) # xs) \\<in> cptn_mod_nest_call\"\n      using min_p cptn_mod_nest_mono by force \n    then have \"(min_q, \\<Gamma>, (Seq P Q, s) # zs) \\<in> cptn_mod_nest_call\"\n      using conjunct1[OF min_q] cptn_mod_nest_call.CptnModNestSeq2[of min_q \\<Gamma> P s xs Q ys zs] \n            CptnModNestSeq2(6)  CptnModNestSeq2(3)\n    by blast\n    also have \"\\<forall>m<min_q. (m, \\<Gamma>,(Seq P Q,s) # zs) \\<notin> cptn_mod_nest_call\"\n     proof -\n      {fix m\n      assume min_m:\"m<min_q\"\n      then have \"(m, \\<Gamma>,(Seq P Q, s) # zs) \\<notin> cptn_mod_nest_call\"\n      proof -\n      {assume ass:\"(m, \\<Gamma>, (Seq P Q, s) # zs) \\<in> cptn_mod_nest_call\"\n       then obtain xs' s' s'' where \n          m_cptn:\"(m, \\<Gamma>, (P, s) # xs') \\<in> cptn_mod_nest_call \\<and> \n                   seq_cond_nest zs Q xs' P s s'' s' \\<Gamma> m\" \n         using  \n          div_seq_nest[of m \\<Gamma> \"(LanguageCon.com.Seq P Q, s) # zs\"]\n          by fastforce\n       then have \"seq_cond_nest zs Q xs' P s s'' s' \\<Gamma> m\" by auto\n       then have ?thesis\n         using Seq_P_Ends_Normal[OF CptnModNestSeq2(6) CptnModNestSeq2(3) ass]\n               min_m min_q \n         by (metis last_length)          \n      } thus ?thesis by auto\n      qed\n      }thus ?thesis by auto\n    qed  \n    ultimately show ?thesis by auto\n  qed\nnext\n  case (CptnModNestSeq3 n \\<Gamma> P s xs s' ys zs Q) \n  then obtain min_p where \n     min_p:\"(min_p, \\<Gamma>, (P, Normal s) # xs) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_p. (m, \\<Gamma>, (P, Normal s) # xs) \\<notin> cptn_mod_nest_call)\" \n    by auto \n  from CptnModNestSeq3(6) obtain min_q where\n    min_q:\"(min_q, \\<Gamma>, (Throw, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_q. (m, \\<Gamma>, (Throw, Normal s') # ys) \\<notin> cptn_mod_nest_call)\"\n  by auto\n  thus ?case\n  proof(cases \"min_p\\<ge>min_q\")\n    case True \n    then have \"(min_p, \\<Gamma>, (Throw, Normal s') # ys) \\<in> cptn_mod_nest_call\"\n      using min_q using cptn_mod_nest_mono by blast \n    then have \"(min_p, \\<Gamma>, (Seq P Q, Normal s) # zs) \\<in> cptn_mod_nest_call\"\n      using conjunct1[OF min_p] cptn_mod_nest_call.CptnModNestSeq3[of min_p \\<Gamma> P s xs s' ys zs Q] \n            CptnModNestSeq3(4)  CptnModNestSeq3(3) CptnModNestSeq3(7)\n    by blast\n    also have \"\\<forall>m<min_p. (m, \\<Gamma>,(Seq P Q,Normal s) # zs) \\<notin> cptn_mod_nest_call\"\n      by (metis CptnModNestSeq3.hyps(3) CptnModNestSeq3.hyps(4) CptnModNestSeq3.hyps(7) Seq_P_Ends_Abort div_seq_nest min_p)\n    ultimately show ?thesis by auto\n  next\n    case False\n    then have \"(min_q, \\<Gamma>, (P,  Normal s) # xs) \\<in> cptn_mod_nest_call\"\n      using min_p cptn_mod_nest_mono by force \n    then have \"(min_q, \\<Gamma>, (Seq P Q, Normal s) # zs) \\<in> cptn_mod_nest_call\"\n      using conjunct1[OF min_q] cptn_mod_nest_call.CptnModNestSeq3[of min_q \\<Gamma> P s xs s' ys zs Q] \n            CptnModNestSeq3(4)  CptnModNestSeq3(3) CptnModNestSeq3(7)\n    by blast\n    also have \"\\<forall>m<min_q. (m, \\<Gamma>,(Seq P Q,Normal s) # zs) \\<notin> cptn_mod_nest_call\"\n      by (metis CptnModNestSeq3.hyps(3) CptnModNestSeq3.hyps(4) CptnModNestSeq3.hyps(7) Seq_P_Ends_Abort div_seq_nest min_q)     \n    ultimately show ?thesis by auto\n  qed \nnext\n  case (CptnModNestWhile1 n \\<Gamma> P s xs b zs) \n  then obtain min_n where \n     min:\"(min_n, \\<Gamma>, (P, Normal s) # xs) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_n. (m, \\<Gamma>, (P, Normal s) # xs) \\<notin> cptn_mod_nest_call)\" \n    by auto\n  then have \"(min_n, \\<Gamma>, (While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \\<in> cptn_mod_nest_call\"\n    using cptn_mod_nest_call.CptnModNestWhile1[of min_n \\<Gamma> P s xs b zs] CptnModNestWhile1\n    by meson \n  also have \"\\<forall>m<min_n. (m, \\<Gamma>,(While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \\<notin> cptn_mod_nest_call\"\n    by (metis CptnModNestWhile1.hyps(4) Seq_P_Not_finish div_seq_nest elim_cptn_mod_nest_call_n min) \n  ultimately show ?case by auto\nnext\n  case (CptnModNestWhile2 n \\<Gamma> P s xs b zs ys) \n  then obtain min_n_p where \n     min_p:\"(min_n_p, \\<Gamma>, (P, Normal s) # xs) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_n_p. (m, \\<Gamma>, (P, Normal s) # xs) \\<notin> cptn_mod_nest_call)\" \n    by auto\n  from CptnModNestWhile2 obtain min_n_w where\n     min_w:\"(min_n_w, \\<Gamma>, (LanguageCon.com.While b P, snd (last ((P, Normal s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_n_w. (m, \\<Gamma>, (LanguageCon.com.While b P, snd (last ((P, Normal s) # xs))) # ys)\n               \\<notin> cptn_mod_nest_call)\"\n    by auto\n  thus ?case \n  proof (cases \"min_n_p\\<ge>min_n_w\")\n    case True \n    then have \"(min_n_p, \\<Gamma>, \n      (LanguageCon.com.While b P, snd (last ((P, Normal s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n      using min_w using cptn_mod_nest_mono by blast \n    then have \"(min_n_p, \\<Gamma>, (While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \\<in> cptn_mod_nest_call\"\n      using min_p cptn_mod_nest_call.CptnModNestWhile2[of min_n_p \\<Gamma> P s xs b zs] CptnModNestWhile2\n      by blast\n    also have \"\\<forall>m<min_n_p. (m, \\<Gamma>,(While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \\<notin> cptn_mod_nest_call\"\n      by (metis CptnModNestWhile2.hyps(3) CptnModNestWhile2.hyps(5) \n                Seq_P_Ends_Normal div_seq_nest elim_cptn_mod_nest_call_n min_p)    \n    ultimately show ?thesis by auto  \n  next\n    case False\n    then have False:\"min_n_p<min_n_w\" by auto\n    then have \"(min_n_w, \\<Gamma>, (P, Normal s) # xs) \\<in> cptn_mod_nest_call\"\n      using min_p  cptn_mod_nest_mono by force \n    then have \"(min_n_w, \\<Gamma>, (While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \\<in> cptn_mod_nest_call\"\n      using min_w min_p cptn_mod_nest_call.CptnModNestWhile2[of min_n_w \\<Gamma> P s xs b zs] CptnModNestWhile2\n      by blast\n    also have \"\\<forall>m<min_n_w. (m, \\<Gamma>,(While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \\<notin> cptn_mod_nest_call\"      \n    proof -\n      {fix m\n      assume min_m:\"m<min_n_w\"\n      then have \"(m, \\<Gamma>,(While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \\<notin> cptn_mod_nest_call\"\n      proof -\n      {assume \"(m, \\<Gamma>,(While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \\<in> cptn_mod_nest_call\"\n       then have a1:\"(m, \\<Gamma>,(Seq P (While b P), Normal s) # zs) \\<in> cptn_mod_nest_call\"      \n         using elim_cptn_mod_nest_not_env_call by fastforce\n       then obtain xs' s' s'' where \n          m_cptn:\"(m, \\<Gamma>, (P, Normal s) # xs') \\<in> cptn_mod_nest_call  \\<and> \n                   seq_cond_nest zs (While b P) xs' P (Normal s) s'' s' \\<Gamma> m\" \n         using  \n          div_seq_nest[of m \\<Gamma> \"(LanguageCon.com.Seq P (LanguageCon.com.While b P), Normal s) # zs\"]\n          by fastforce\n       then have \"seq_cond_nest zs (While b P) xs' P (Normal s) s'' s' \\<Gamma> m\" by auto\n       then have ?thesis unfolding seq_cond_nest_def\n         by (metis CptnModNestWhile2.hyps(3) CptnModNestWhile2.hyps(5) Seq_P_Ends_Normal a1 last_length m_cptn min_m min_w)           \n     } thus ?thesis by auto\n     qed\n     }thus ?thesis by auto\n    qed\n    ultimately show ?thesis by auto\n  qed\nnext\n  case (CptnModNestWhile3 n \\<Gamma> P s xs b s' ys zs) \n  then obtain min_n_p where \n     min_p:\"(min_n_p, \\<Gamma>, (P, Normal s) # xs) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_n_p. (m, \\<Gamma>, (P, Normal s) # xs) \\<notin> cptn_mod_nest_call)\" \n    by auto\n  from CptnModNestWhile3 obtain min_n_w where\n     min_w:\"(min_n_w, \\<Gamma>, (Throw, snd (last ((P, Normal s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_n_w. (m, \\<Gamma>, (Throw, snd (last ((P, Normal s) # xs))) # ys)\n               \\<notin> cptn_mod_nest_call)\"\n    by auto\n  thus ?case \n  proof (cases \"min_n_p\\<ge>min_n_w\")\n    case True \n    then have \"(min_n_p, \\<Gamma>, \n      (Throw, snd (last ((P, Normal s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n      using min_w using cptn_mod_nest_mono by blast \n    then have \"(min_n_p, \\<Gamma>, (While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \\<in> cptn_mod_nest_call\"\n      using min_p cptn_mod_nest_call.CptnModNestWhile3[of min_n_p \\<Gamma> P s xs b s' ys zs] \n            CptnModNestWhile3\n      by fastforce\n    also have \"\\<forall>m<min_n_p. (m, \\<Gamma>,(While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \\<notin> cptn_mod_nest_call\"\n      by (metis CptnModNestWhile3.hyps(3) CptnModNestWhile3.hyps(5) CptnModNestWhile3.hyps(8) \n            Seq_P_Ends_Abort div_seq_nest elim_cptn_mod_nest_call_n min_p)    \n    ultimately show ?thesis by auto  \n  next\n    case False\n    then have False:\"min_n_p<min_n_w\" by auto\n    then have \"(min_n_w, \\<Gamma>, (P, Normal s) # xs) \\<in> cptn_mod_nest_call\"\n      using min_p  cptn_mod_nest_mono by force \n    then have \"(min_n_w, \\<Gamma>, (While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \\<in> cptn_mod_nest_call\"\n      using min_w min_p cptn_mod_nest_call.CptnModNestWhile3[of min_n_w \\<Gamma> P s xs b s' ys zs] \n            CptnModNestWhile3\n      by fastforce      \n    also have \"\\<forall>m<min_n_w. (m, \\<Gamma>,(While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \\<notin> cptn_mod_nest_call\"\n    proof -\n      {fix m\n      assume min_m:\"m<min_n_w\"\n      then have \"(m, \\<Gamma>,(While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \\<notin> cptn_mod_nest_call\"\n      proof -\n      {assume \"(m, \\<Gamma>,(While b P, Normal s) # (Seq P (While b P), Normal s) # zs) \\<in> cptn_mod_nest_call\"\n       then have s1:\"(m, \\<Gamma>,(Seq P (While b P), Normal s) # zs) \\<in> cptn_mod_nest_call\"      \n         using elim_cptn_mod_nest_not_env_call by fastforce\n       then obtain xs' s' s'' where \n          m_cptn:\"(m, \\<Gamma>, (P, Normal s) # xs') \\<in> cptn_mod_nest_call  \\<and> \n                   seq_cond_nest zs (While b P) xs' P (Normal s) s'' s' \\<Gamma> m\" \n         using  \n          div_seq_nest[of m \\<Gamma> \"(LanguageCon.com.Seq P (LanguageCon.com.While b P), Normal s) # zs\"]\n          by fastforce\n       then have \"seq_cond_nest zs (While b P) xs' P (Normal s) s'' s' \\<Gamma> m\" by auto\n       then have ?thesis unfolding seq_cond_nest_def\n         by (metis CptnModNestWhile3.hyps(3) CptnModNestWhile3.hyps(5) CptnModNestWhile3.hyps(8) Seq_P_Ends_Abort s1 m_cptn min_m min_w)       \n     } thus ?thesis by auto\n     qed\n     }thus ?thesis by auto\n    qed\n    ultimately show ?thesis by auto\n  qed\nnext\n  case (CptnModNestCall n \\<Gamma> bdy s xs f) thus ?case\n  proof -\n    { fix nn :: \"nat \\<Rightarrow> nat\"\n     obtain nna :: nat where\n      ff1: \"(nna, \\<Gamma>, (bdy, Normal s) # xs) \\<in> cptn_mod_nest_call \\<and> (\\<forall>n. \\<not> n < nna \\<or> (n, \\<Gamma>, (bdy, Normal s) # xs) \\<notin> cptn_mod_nest_call)\"\n      by (meson CptnModNestCall.hyps(2))\n    moreover\n    { assume \"(nn (nn (Suc nna)), \\<Gamma>, (bdy, Normal s) # xs) \\<in> cptn_mod_nest_call\"\n      then have \"\\<not> Suc (nn (nn (Suc nna))) < Suc nna\"\n        using ff1 by blast\n      then have \"(nn (Suc nna), \\<Gamma>, (LanguageCon.com.Call f, Normal s) # (bdy, Normal s) # xs) \\<in> cptn_mod_nest_call \\<longrightarrow> (\\<exists>n. (n, \\<Gamma>, (LanguageCon.com.Call f, Normal s) # (bdy, Normal s) # xs) \\<in> cptn_mod_nest_call \\<and> \n                (\\<not> nn n < n \\<or> (nn n, \\<Gamma>, (LanguageCon.com.Call f, Normal s) # (bdy, Normal s) # xs) \\<notin> cptn_mod_nest_call))\"\n        using ff1 by (meson CptnModNestCall.hyps(3) CptnModNestCall.hyps(4) cptn_mod_nest_call.CptnModNestCall less_trans_Suc) }\n    ultimately have \"\\<exists>n. (n, \\<Gamma>, (LanguageCon.com.Call f, Normal s) # (bdy, Normal s) # xs) \\<in> cptn_mod_nest_call \\<and> (\\<not> nn n < n \\<or> (nn n, \\<Gamma>, (LanguageCon.com.Call f, Normal s) # (bdy, Normal s) # xs) \\<notin> cptn_mod_nest_call)\"\n      by (metis (no_types) CptnModNestCall.hyps(3) CptnModNestCall.hyps(4) cptn_mod_nest_call.CptnModNestCall elim_cptn_mod_nest_call_n) }\n   then show ?thesis\n     by meson\n  qed     \nnext \n case (CptnModNestDynCom n \\<Gamma> c s xs) thus ?case\n   by (meson cptn_mod_nest_call.CptnModNestDynCom elim_cptn_mod_nest_call_n)\nnext\n  case (CptnModNestGuard n \\<Gamma> c s xs g f) thus ?case \n    by (meson cptn_mod_nest_call.CptnModNestGuard elim_cptn_mod_nest_call_n)   \nnext\n case (CptnModNestCatch1 n \\<Gamma> P s xs  zs Q) thus ?case\n   by (metis (no_types, lifting) Catch_P_Not_finish cptn_mod_nest_call.CptnModNestCatch1 div_catch_nest)\nnext\n case (CptnModNestCatch2 n \\<Gamma> P s xs ys zs Q) \n then obtain min_p where \n     min_p:\"(min_p, \\<Gamma>, (P,  s) # xs) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_p. (m, \\<Gamma>, (P, s) # xs) \\<notin> cptn_mod_nest_call)\" \n    by auto \n  from CptnModNestCatch2(5) obtain min_q where\n    min_q:\"(min_q, \\<Gamma>, (Skip, snd (last ((P, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_q. (m, \\<Gamma>, (Skip, snd (last ((P, s) # xs))) # ys) \\<notin> cptn_mod_nest_call)\"\n  by auto\n  thus ?case\n  proof(cases \"min_p\\<ge>min_q\")\n    case True\n    then have \"(min_p, \\<Gamma>, (Skip, snd (last ((P,s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n      using min_q using cptn_mod_nest_mono by blast \n    then have \"(min_p, \\<Gamma>, (Catch P Q, s) # zs) \\<in> cptn_mod_nest_call\"\n      using conjunct1[OF min_p] cptn_mod_nest_call.CptnModNestCatch2[of min_p \\<Gamma> P s xs] \n            CptnModNestCatch2(6)  CptnModNestCatch2(3)\n    by blast\n    also have \"\\<forall>m<min_p. (m, \\<Gamma>,(Catch P Q,s) # zs) \\<notin> cptn_mod_nest_call\"\n     proof -\n      {fix m\n      assume min_m:\"m<min_p\"\n      then have \"(m, \\<Gamma>,(Catch P Q, s) # zs) \\<notin> cptn_mod_nest_call\"\n      proof -\n      {assume ass:\"(m, \\<Gamma>, (Catch P Q, s) # zs) \\<in> cptn_mod_nest_call\"\n       then obtain xs' s' s'' where \n          m_cptn:\"(m, \\<Gamma>, (P, s) # xs') \\<in> cptn_mod_nest_call \\<and> \n                   catch_cond_nest zs Q xs' P s s'' s' \\<Gamma> m\" \n         using  \n          div_catch_nest[of m \\<Gamma> \"(Catch P Q, s) # zs\"]\n          by fastforce\n       then have \"catch_cond_nest zs Q xs' P s s'' s' \\<Gamma> m\" by auto\n       then have \"xs=xs'\" \n         using Catch_P_Ends_Skip[OF CptnModNestCatch2(6) CptnModNestCatch2(3)]   \n         by fastforce\n       then have \"(m, \\<Gamma>, (P,s) # xs) \\<in> cptn_mod_nest_call\"\n         using m_cptn by auto\n       then have False using min_p min_m by fastforce\n    } thus ?thesis by auto\n    qed\n    }thus ?thesis by auto\n  qed\n  ultimately show ?thesis by auto\n  next\n    case False\n    then have \"(min_q, \\<Gamma>, (P,  s) # xs) \\<in> cptn_mod_nest_call\"\n      using min_p cptn_mod_nest_mono by force \n    then have \"(min_q, \\<Gamma>, (Catch P Q, s) # zs) \\<in> cptn_mod_nest_call\"\n      using conjunct1[OF min_q] cptn_mod_nest_call.CptnModNestCatch2[of min_q \\<Gamma> P s xs ] \n            CptnModNestCatch2(6)  CptnModNestCatch2(3)\n    by blast\n    also have \"\\<forall>m<min_q. (m, \\<Gamma>,(Catch P Q,s) # zs) \\<notin> cptn_mod_nest_call\"\n     proof -\n      {fix m\n      assume min_m:\"m<min_q\"\n      then have \"(m, \\<Gamma>,(Catch P Q, s) # zs) \\<notin> cptn_mod_nest_call\"\n      proof -\n      {assume ass:\"(m, \\<Gamma>, (Catch P Q, s) # zs) \\<in> cptn_mod_nest_call\"\n       then obtain xs' s' s'' where \n          m_cptn:\"(m, \\<Gamma>, (P, s) # xs') \\<in> cptn_mod_nest_call \\<and> \n                   catch_cond_nest zs Q xs' P s s'' s' \\<Gamma> m\" \n         using  \n          div_catch_nest[of m \\<Gamma> \"(Catch P Q, s) # zs\"]\n          by fastforce\n       then have \"catch_cond_nest zs Q xs' P s s'' s' \\<Gamma> m\" by auto\n       then have ?thesis\n         using Catch_P_Ends_Skip[OF CptnModNestCatch2(6) CptnModNestCatch2(3)]\n               min_m min_q \n       by blast         \n      } thus ?thesis by auto\n      qed\n      }thus ?thesis by auto\n    qed  \n    ultimately show ?thesis by auto\n  qed\nnext\n case (CptnModNestCatch3 n \\<Gamma> P s xs s' Q ys zs ) then obtain min_p where \n     min_p:\"(min_p, \\<Gamma>, (P, Normal s) # xs) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_p. (m, \\<Gamma>, (P, Normal s) # xs) \\<notin> cptn_mod_nest_call)\" \n    by auto \n  from CptnModNestCatch3(6)  CptnModNestCatch3(4) obtain min_q where\n    min_q:\"(min_q, \\<Gamma>, (Q,  snd (last ((P, Normal s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n        (\\<forall>m<min_q. (m, \\<Gamma>, (Q,  snd (last ((P, Normal s) # xs))) # ys) \\<notin> cptn_mod_nest_call)\"\n  by auto\n  thus ?case\n  proof(cases \"min_p\\<ge>min_q\")\n    case True\n    then have \"(min_p, \\<Gamma>, (Q,  snd (last ((P, Normal s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n      using min_q using cptn_mod_nest_mono by blast \n    then have \"(min_p, \\<Gamma>, (Catch P Q, Normal s) # zs) \\<in> cptn_mod_nest_call\"\n      using conjunct1[OF min_p] cptn_mod_nest_call.CptnModNestCatch3[of min_p \\<Gamma> P s xs s' Q ys zs] \n            CptnModNestCatch3(4)  CptnModNestCatch3(3) CptnModNestCatch3(7)\n    by fastforce\n    also have \"\\<forall>m<min_p. (m, \\<Gamma>,(Catch P Q,Normal s) # zs) \\<notin> cptn_mod_nest_call\"\n     proof -\n      {fix m\n      assume min_m:\"m<min_p\"\n      then have \"(m, \\<Gamma>,(Catch P Q, Normal s) # zs) \\<notin> cptn_mod_nest_call\"\n      proof -\n      {assume ass:\"(m, \\<Gamma>, (Catch P Q,Normal s) # zs) \\<in> cptn_mod_nest_call\"\n       then obtain xs' ns' ns'' where \n          m_cptn:\"(m, \\<Gamma>, (P, Normal s) # xs') \\<in> cptn_mod_nest_call \\<and> \n                   catch_cond_nest zs Q xs' P (Normal s) ns'' ns' \\<Gamma> m\" \n         using  \n          div_catch_nest[of m \\<Gamma> \"(Catch P Q, Normal s) # zs\"]\n          by fastforce\n       then have \"catch_cond_nest zs Q xs' P (Normal s) ns'' ns' \\<Gamma> m\" by auto       \n       then have \"xs=xs'\" \n         using  Catch_P_Ends_Normal[OF CptnModNestCatch3(7)  CptnModNestCatch3(3) CptnModNestCatch3(4)]   \n         by fastforce\n       then have \"(m, \\<Gamma>, (P,Normal s) # xs) \\<in> cptn_mod_nest_call\"\n         using m_cptn by auto\n       then have False using min_p min_m by fastforce\n    } thus ?thesis by auto\n    qed\n    }thus ?thesis by auto\n  qed\n  ultimately show ?thesis by auto\n  next\n    case False\n    then have \"(min_q, \\<Gamma>, (P,  Normal s) # xs) \\<in> cptn_mod_nest_call\"\n      using min_p cptn_mod_nest_mono by force \n    then have \"(min_q, \\<Gamma>, (Catch P Q, Normal s) # zs) \\<in> cptn_mod_nest_call\"\n      using conjunct1[OF min_q] cptn_mod_nest_call.CptnModNestCatch3[of min_q \\<Gamma> P s xs s' ] \n            CptnModNestCatch3(4)  CptnModNestCatch3(3) CptnModNestCatch3(7)\n    by blast\n    also have \"\\<forall>m<min_q. (m, \\<Gamma>,(Catch P Q,Normal s) # zs) \\<notin> cptn_mod_nest_call\"\n     proof -\n      {fix m\n      assume min_m:\"m<min_q\"\n      then have \"(m, \\<Gamma>,(Catch P Q, Normal s) # zs) \\<notin> cptn_mod_nest_call\"\n      proof -\n      {assume ass:\"(m, \\<Gamma>, (Catch P Q, Normal s) # zs) \\<in> cptn_mod_nest_call\"\n       then obtain xs' ns' ns'' where \n          m_cptn:\"(m, \\<Gamma>, (P, Normal s) # xs') \\<in> cptn_mod_nest_call \\<and> \n                   catch_cond_nest zs Q xs' P (Normal s) ns'' ns' \\<Gamma> m\" \n         using  \n          div_catch_nest[of m \\<Gamma> \"(Catch P Q, Normal s) # zs\"]\n          by fastforce\n       then have \"catch_cond_nest zs Q xs' P (Normal s) ns'' ns' \\<Gamma> m\" by auto\n       then have ?thesis\n         using Catch_P_Ends_Normal[OF CptnModNestCatch3(7) CptnModNestCatch3(3)  CptnModNestCatch3(4)]\n               min_m min_q \n         by (metis last_length)                                \n      } thus ?thesis by auto\n      qed\n      }thus ?thesis by auto\n    qed  \n    ultimately show ?thesis by auto\n  qed  \nqed\n\n  lemma elim_cptn_mod_min_nest_call:\n assumes a0:\"min_call n \\<Gamma> cfg\" and\n         a1:\"cfg = (P,s)#(Q,t)#cfg1\" and\n         a2:\"(\\<forall>f. redex P \\<noteq> Call f) \\<or>  \n             SmallStepCon.redex P = LanguageCon.com.Call fn \\<and> \\<Gamma> fn = None \\<or>\n            (redex P = Call fn \\<and> (\\<forall>sa. s\\<noteq>Normal sa)) \\<or>\n            (redex P = Call fn \\<and> P=Q)\"     \n shows \"min_call n \\<Gamma> ((Q,t)#cfg1)\"\nproof -\n  have a0: \"(n,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" and\n       a0': \"(\\<forall>m<n. (m, \\<Gamma>, cfg) \\<notin> cptn_mod_nest_call)\"\n  using a0 unfolding min_call_def by auto\n  then have \"(n,\\<Gamma>,(Q,t)#cfg1) \\<in>  cptn_mod_nest_call\"  \n    using a0 a1 elim_cptn_mod_nest_call_n by blast\n  also have \"(\\<forall>m<n. (m, \\<Gamma>, (Q,t)#cfg1) \\<notin> cptn_mod_nest_call)\"      \n  proof-\n  { assume \"\\<not>(\\<forall>m<n. (m, \\<Gamma>, (Q,t)#cfg1) \\<notin> cptn_mod_nest_call)\"\n    then obtain m where \n      asm0:\"m<n\" and \n      asm1:\"(m, \\<Gamma>, (Q,t)#cfg1) \\<in> cptn_mod_nest_call\"\n    by auto\n    then have \"(m, \\<Gamma>, cfg) \\<in> cptn_mod_nest_call\" \n      using  a0 a1 a2  cptn_mod_nest_cptn_mod cptn_if_cptn_mod cptn_mod_nest_call.CptnModNestEnv\n          cptn_elim_cases(2)  not_func_redex_cptn_mod_nest_n'          \n      by (metis (no_types, lifting) mod_env_not_component)\n\n    then have False using a0' asm0 by auto\n  } thus ?thesis by auto qed\n  ultimately show ?thesis unfolding min_call_def by auto\nqed\n\n  \n\nlemma elim_call_cptn_mod_min_nest_call:\n assumes a0:\"min_call n \\<Gamma> cfg\" and\n         a1:\"cfg = (P,s)#(Q,t)#cfg1\" and\n         a2:\"P = Call f \\<and>  \n             \\<Gamma> f = Some Q \\<and> (\\<exists>sa. s=Normal sa) \\<and> P\\<noteq>Q\"          \n shows \"min_call (n-1) \\<Gamma> ((Q,t)#cfg1)\"\nproof -\n  obtain s' where a0: \"(n,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" and\n       a0': \"(\\<forall>m<n. (m, \\<Gamma>, cfg) \\<notin> cptn_mod_nest_call)\" and\n       a2': \"s= Normal s'\" \n    using a0 a2 unfolding min_call_def by auto  \n  then have \"(n-1,\\<Gamma>,(Q,t)#cfg1) \\<in>  cptn_mod_nest_call\" \n    using a1 a2 a2' elim_cptn_mod_nest_call_n_dec[of n \\<Gamma> f s' cfg1 Q]\n    by (metis (no_types, lifting) SmallStepCon.redex.simps(7) call_f_step_not_s_eq_t_false \n         cptn_elim_cases(2) cptn_eq_cptn_mod_set cptn_mod_nest_cptn_mod option.sel)   \n  thus ?thesis\n  proof -\n    obtain nn :: \"(('b, 'a, 'c, 'd) LanguageCon.com \\<times> ('b, 'c) xstate) list \\<Rightarrow> \n                  ('a \\<Rightarrow> ('b, 'a, 'c, 'd) LanguageCon.com option) \\<Rightarrow> nat \\<Rightarrow> nat\" where\n      \"\\<forall>x0 x1 x2. (\\<exists>v3<x2. (v3, x1, x0) \\<in> cptn_mod_nest_call) = \n                  (nn x0 x1 x2 < x2 \\<and> (nn x0 x1 x2, x1, x0) \\<in> cptn_mod_nest_call)\"\n      by moura\n    then have f1: \"\\<forall>n f ps. (\\<not> min_call n f ps \\<or> (n, f, ps) \\<in> cptn_mod_nest_call \\<and> \n                            (\\<forall>na. \\<not> na < n \\<or> (na, f, ps) \\<notin> cptn_mod_nest_call)) \\<and> \n                            (min_call n f ps \\<or> (n, f, ps) \\<notin> cptn_mod_nest_call \\<or> \n                    nn ps f n < n \\<and> (nn ps f n, f, ps) \\<in> cptn_mod_nest_call)\"\n      by (meson min_call_def)\n    then have f2: \"(n, \\<Gamma>, (P, s) # (Q, t) # cfg1) \\<in> cptn_mod_nest_call \\<and> \n                   (\\<forall>na. \\<not> na < n \\<or> (na, \\<Gamma>, (P, s) # (Q, t) # cfg1) \\<notin> cptn_mod_nest_call)\"\n      using a1 assms(1) by blast\n    obtain bb :: 'b where\n      f3: \"s = Normal bb\"\n      using a2 by blast\n    then have f4: \"(LanguageCon.com.Call f, Normal bb) = (P, s)\"\n      using a2 by blast\n    have f5: \"n - 1 < n\"\n      using f2 by (metis (no_types) Suc_diff_Suc a2 diff_Suc_eq_diff_pred elim_cptn_mod_nest_call_n_greater_zero lessI minus_nat.diff_0)\n    have f6: \"(LanguageCon.com.Call f, Normal bb) = (P, s)\"\n      using f3 a2 by blast\n    have f7: \"Normal bb = t\"\n      using f4 f2 by (metis (no_types) SmallStepCon.redex.simps(7) a2 \n                            call_f_step_not_s_eq_t_false cptn_elim_cases(2) \n                            cptn_eq_cptn_mod_set cptn_mod_nest_cptn_mod)\n    have \"(nn ((Q, t) # cfg1) \\<Gamma> (n - 1), \\<Gamma>, (Q, Normal bb) # cfg1) \\<in> cptn_mod_nest_call \\<longrightarrow> \n              (Suc (nn ((Q, t) # cfg1) \\<Gamma> (n - 1)), \\<Gamma>, \n            (LanguageCon.com.Call f, Normal bb) # (Q, Normal bb) # cfg1) \\<in> cptn_mod_nest_call\"\n      using a2 cptn_mod_nest_call.CptnModNestCall by fastforce\n    then show ?thesis\n      using f7 f6 f5 f2 f1 \\<open>(n - 1, \\<Gamma>, (Q, t) # cfg1) \\<in> cptn_mod_nest_call\\<close> less_trans_Suc by blast\n  qed  \n  \nqed\n\nlemma redex_not_call_seq_catch:\n assumes a0:\"redex P = Call f \\<and> P\\<noteq>Call f\"          \n shows \"\\<exists>p1 p2. P = Seq p1 p2 \\<or> P = Catch p1 p2\"\nusing a0 unfolding min_call_def\nproof(induct P)\nqed(fastforce+)\n\nlemma skip_all_skip:\n  assumes a0:\"(\\<Gamma>,cfg)\\<in>cptn\" and\n          a1:\"cfg = (Skip,s)#cfg1\"\n  shows \"\\<forall>i<length cfg. fst(cfg!i) = Skip\"\nusing a0 a1\nproof(induct cfg1 arbitrary:cfg s)\n  case Nil thus ?case by auto\nnext\n  case (Cons x xs)\n  then obtain s' where x:\"x = (Skip,s')\"\n    by (metis CptnMod_elim_cases(1) cptn_eq_cptn_mod_set  stepc_elim_cases(1))\n  moreover have cptn:\"(\\<Gamma>,x#xs)\\<in>cptn\"\n    using Cons.prems(1) Cons.prems(2) cptn_dest_pair by blast\n  moreover have \n    xs:\"x # xs = (LanguageCon.com.Skip, s') # xs\" using x by auto\n  ultimately show ?case using Cons(1)[OF cptn xs] Cons(3)\n    using diff_Suc_1 fstI length_Cons less_Suc_eq_0_disj nth_Cons' by auto \nqed\n\nlemma skip_all_skip_throw:\n  assumes a0:\"(\\<Gamma>,cfg)\\<in>cptn\" and\n          a1:\"cfg = (Throw,s)#cfg1\"\n  shows \"\\<forall>i<length cfg. fst(cfg!i) = Skip \\<or> fst(cfg!i) = Throw\"\nusing a0 a1\nproof(induct cfg1 arbitrary:cfg s)\n  case Nil thus ?case by auto\nnext\n  case (Cons x xs)\n  then obtain s' where x:\"x = (Skip,s') \\<or> x = (Throw, s')\"\n    by (metis CptnMod_elim_cases(10) cptn_eq_cptn_mod_set)    \n  then have cptn:\"(\\<Gamma>,x#xs)\\<in>cptn\"\n    using Cons.prems(1) Cons.prems(2) cptn_dest_pair by blast\n  show ?case using x\n  proof \n    assume \"x=(Skip,s')\" thus ?thesis using skip_all_skip Cons(3)\n      using cptn fstI length_Cons less_Suc_eq_0_disj nth_Cons' nth_Cons_Suc skip_all_skip \n      by fastforce \n  next\n    assume x:\"x=(Throw,s')\"\n    moreover have cptn:\"(\\<Gamma>,x#xs)\\<in>cptn\"\n      using Cons.prems(1) Cons.prems(2) cptn_dest_pair by blast\n    moreover have \n      xs:\"x # xs = (LanguageCon.com.Throw, s') # xs\" using x by auto\n    ultimately show ?case using Cons(1)[OF cptn xs] Cons(3)\n    using diff_Suc_1 fstI length_Cons less_Suc_eq_0_disj nth_Cons' by auto \n  qed  \nqed\n\n  \nlemma skip_min_nested_call_0:\n  assumes a0:\"min_call n \\<Gamma> cfg\" and\n          a1:\"cfg = (Skip,s)#cfg1\"\n  shows \"n=0\"\nproof -\n  have asm0:\"(n, \\<Gamma>, cfg) \\<in> cptn_mod_nest_call\" and \n       asm1:\"(\\<forall>m<n. (m, \\<Gamma>, cfg) \\<notin> cptn_mod_nest_call)\"  \n       using a0 unfolding min_call_def by auto  \n  show ?thesis using a1 asm0 asm1\n  proof (induct cfg1 arbitrary: cfg s n)\n    case Nil thus ?case\n      using cptn_mod_nest_call.CptnModNestOne neq0_conv by blast\n  next\n    case (Cons x xs)\n      then obtain Q s' where cfg:\"cfg = (LanguageCon.com.Skip, s) # (Q,s') # xs\" by force\n      then have min_call:\"min_call n \\<Gamma> cfg\" using Cons unfolding min_call_def by auto\n      then have \"(\\<forall>f. SmallStepCon.redex Skip \\<noteq> LanguageCon.com.Call f)\" by auto\n      then have \"min_call n \\<Gamma> ((Q, s')#xs)\" \n        using elim_cptn_mod_min_nest_call[OF min_call cfg] cfg\n        by simp\n      thus ?case using Cons cfg unfolding min_call_def\n      proof -\n        assume a1: \"(n, \\<Gamma>, (Q, s') # xs) \\<in> cptn_mod_nest_call \\<and> (\\<forall>m<n. (m, \\<Gamma>, (Q, s') # xs) \\<notin> cptn_mod_nest_call)\"\n        have \"LanguageCon.com.Skip = Q\"\n          by (metis (no_types) \\<open>(n, \\<Gamma>, cfg) \\<in> cptn_mod_nest_call\\<close> cfg cptn_dest1_pair cptn_if_cptn_mod cptn_mod_nest_cptn_mod fst_conv last.simps last_length length_Cons lessI not_Cons_self2 skip_all_skip)\n        then show ?thesis\n          using a1 by (meson Cons.hyps)\n      qed      \n  qed\nqed\n\nlemma throw_min_nested_call_0:\n  assumes a0:\"min_call n \\<Gamma> cfg\" and\n          a1:\"cfg = (Throw,s)#cfg1\"\n  shows \"n=0\"\nproof -\n  have asm0:\"(n, \\<Gamma>, cfg) \\<in> cptn_mod_nest_call\" and \n       asm1:\"(\\<forall>m<n. (m, \\<Gamma>, cfg) \\<notin> cptn_mod_nest_call)\"  \n       using a0 unfolding min_call_def by auto  \n  show ?thesis using a1 asm0 asm1\n  proof (induct cfg1 arbitrary: cfg s n)\n    case Nil thus ?case\n      using cptn_mod_nest_call.CptnModNestOne neq0_conv by blast\n  next\n    case (Cons x xs)\n      then obtain s' where x:\"x = (Skip,s') \\<or> x = (Throw, s')\"\n         using CptnMod_elim_cases(10) cptn_eq_cptn_mod_set\n         by (metis cptn_mod_nest_cptn_mod)      \n      then obtain Q where cfg:\"cfg = (LanguageCon.com.Throw, s) # (Q,s') # xs\"\n        using Cons  by force\n      then have min_call:\"min_call n \\<Gamma> cfg\" using Cons unfolding min_call_def by auto\n      then have \"(\\<forall>f. SmallStepCon.redex Skip \\<noteq> LanguageCon.com.Call f)\" by auto\n      then have min_call':\"min_call n \\<Gamma> ((Q, s')#xs)\" \n        using elim_cptn_mod_min_nest_call[OF min_call cfg] cfg\n        by simp\n      from x show ?case\n      proof\n        assume \"x=(Skip,s')\"\n        thus ?thesis using skip_min_nested_call_0 min_call' Cons(2) cfg by fastforce\n      next       \n        assume \"x=(Throw,s')\"\n        thus ?thesis using Cons(1,2) min_call' cfg unfolding min_call_def  \n          by blast \n      qed      \n  qed\nqed\n\n\n\ntext {* function to calculate that there is not any subsequent where the nested call is n *}\ndefinition cond_seq_1\nwhere \n\"cond_seq_1 n \\<Gamma> c1 s xs c2 zs ys \\<equiv> ((n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call \\<and> \n                       fst(last((c1,s)#xs)) = Skip \\<and>\n                        (n,\\<Gamma>,((c2, snd(last ((c1, s)#xs)))#ys)) \\<in> cptn_mod_nest_call \\<and>\n                       zs=(map (lift c2) xs)@((c2, snd(last ((c1, s)#xs)))#ys))\"\n\ndefinition cond_seq_2\nwhere\n\"cond_seq_2 n \\<Gamma> c1 s xs c2 zs ys s' s'' \\<equiv>  s= Normal s'' \\<and> \n                    (n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call \\<and> \n                    fst(last ((c1, s)#xs)) = Throw \\<and>\n                    snd(last ((c1, s)#xs)) = Normal s' \\<and> \n                    (n,\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod_nest_call \\<and> \n                     zs=(map (lift c2) xs)@((Throw,Normal s')#ys)\"\n\ndefinition cond_catch_1\nwhere \n\"cond_catch_1 n \\<Gamma> c1 s xs c2 zs ys \\<equiv> ((n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call \\<and> \n                       fst(last((c1,s)#xs)) = Skip \\<and>\n                        (n,\\<Gamma>,((Skip, snd(last ((c1, s)#xs)))#ys)) \\<in> cptn_mod_nest_call \\<and>\n                       zs=(map (lift_catch c2) xs)@((Skip, snd(last ((c1, s)#xs)))#ys))\"\n\ndefinition cond_catch_2\nwhere\n\"cond_catch_2 n \\<Gamma> c1 s xs c2 zs ys s' s'' \\<equiv> s= Normal s'' \\<and> \n                    (n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call \\<and> \n                    fst(last ((c1, s)#xs)) = Throw \\<and>\n                    snd(last ((c1, s)#xs)) = Normal s' \\<and> \n                    (n,\\<Gamma>,(c2,Normal s')#ys) \\<in> cptn_mod_nest_call \\<and> \n                     zs=(map (lift_catch c2) xs)@((c2,Normal s')#ys)\"\n\nfun biggest_nest_call :: \"('s,'p,'f,'e)com \\<Rightarrow> \n                         ('s,'f) xstate \\<Rightarrow> \n                         (('s,'p,'f,'e) config) list \\<Rightarrow> \n                         ('s,'p,'f,'e) body \\<Rightarrow> \n                         nat \\<Rightarrow> bool\"\nwhere\n \"biggest_nest_call (Seq c1 c2) s zs \\<Gamma> n  = \n   (if (\\<exists>xs. ((min_call n \\<Gamma> ((c1,s)#xs)) \\<and> (zs=map (lift c2) xs))) then\n       let xsa = (SOME xs. (min_call n \\<Gamma> ((c1,s)#xs)) \\<and> (zs=map (lift c2) xs)) in\n       (biggest_nest_call c1 s xsa \\<Gamma> n)\n    else if (\\<exists>xs ys. cond_seq_1 n \\<Gamma> c1 s xs c2 zs ys) then\n         let xsa = (SOME xs. \\<exists>ys. cond_seq_1 n \\<Gamma> c1 s xs c2 zs ys);\n             ysa = (SOME ys. cond_seq_1 n \\<Gamma> c1 s xsa c2 zs ys) in\n         if (min_call n \\<Gamma> ((c2, snd(last ((c1, s)#xsa)))#ysa)) then True\n         else (biggest_nest_call c1 s xsa \\<Gamma> n)            \n   else let xsa = (SOME xs. \\<exists>ys s' s''. cond_seq_2 n \\<Gamma> c1 s xs c2 zs ys s' s'') in\n           (biggest_nest_call c1 s xsa \\<Gamma> n))\"      \n|\"biggest_nest_call (Catch c1 c2) s zs \\<Gamma> n  = \n  (if (\\<exists>xs. ((min_call n \\<Gamma> ((c1,s)#xs)) \\<and> (zs=map (lift_catch c2) xs))) then\n    let xsa = (SOME xs. (min_call n \\<Gamma> ((c1,s)#xs)) \\<and> (zs=map (lift_catch c2) xs)) in\n       (biggest_nest_call c1 s xsa \\<Gamma> n)\n    else if (\\<exists>xs ys. cond_catch_1 n \\<Gamma> c1 s xs c2 zs ys) then\n         let xsa = (SOME xs. \\<exists>ys. cond_catch_1 n \\<Gamma> c1 s xs c2 zs ys) in            \n                 (biggest_nest_call c1 s xsa \\<Gamma> n)\n   else let xsa = (SOME xs. \\<exists>ys s' s''. cond_catch_2 n \\<Gamma> c1 s xs c2 zs ys s' s'');\n            ysa = (SOME ys. \\<exists>s' s''. cond_catch_2 n \\<Gamma> c1 s xsa c2 zs ys s' s'') in\n         if (min_call n \\<Gamma> ((c2, snd(last ((c1, s)#xsa)))#ysa)) then True\n         else (biggest_nest_call c1 s xsa \\<Gamma> n))\"\n|\"biggest_nest_call _ _ _ _ _ = False\"\n\n\nlemma min_call_less_eq_n:\n  \"(n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call \\<Longrightarrow>     \n   (n,\\<Gamma>,(c2, snd(last ((c1, s)#xs)))#ys) \\<in> cptn_mod_nest_call \\<Longrightarrow>\n   min_call p \\<Gamma> ((c1, s)#xs) \\<and> min_call q \\<Gamma> ((c2, snd(last ((c1, s)#xs)))#ys) \\<Longrightarrow>\n   p\\<le>n \\<and> q\\<le>n\"\nunfolding min_call_def\nusing le_less_linear by blast\n\nlemma min_call_seq_less_eq_n':\n  \"(n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call \\<Longrightarrow>     \n   min_call p \\<Gamma> ((c1, s)#xs)  \\<Longrightarrow>\n   p\\<le>n\"\nunfolding min_call_def\nusing le_less_linear by blast\n\nlemma min_call_seq2:\n  \"min_call n \\<Gamma> ((Seq c1 c2,s)#zs) \\<Longrightarrow>\n   (n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call \\<Longrightarrow> \n    fst(last ((c1, s)#xs)) = Skip \\<Longrightarrow>\n   (n,\\<Gamma>,(c2, snd(last ((c1, s)#xs)))#ys) \\<in> cptn_mod_nest_call \\<Longrightarrow>\n    zs=(map (lift c2) xs)@((c2, snd(last ((c1, s)#xs)))#ys) \\<Longrightarrow>\n   min_call n \\<Gamma> ((c1, s)#xs) \\<or> min_call n \\<Gamma> ((c2, snd(last ((c1, s)#xs)))#ys)\n   \"\nproof -\n  assume a0:\"min_call n \\<Gamma> ((Seq c1 c2,s)#zs)\" and\n         a1:\"(n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call\" and\n         a2:\"fst(last ((c1, s)#xs)) = Skip\" and\n         a3:\"(n,\\<Gamma>,(c2, snd(last ((c1, s)#xs)))#ys) \\<in> cptn_mod_nest_call\" and\n         a4:\"zs=(map (lift c2) xs)@((c2, snd(last ((c1, s)#xs)))#ys)\"\n  then obtain p q where min_calls: \n    \"min_call p \\<Gamma> ((c1, s)#xs) \\<and> min_call q \\<Gamma> ((c2, snd(last ((c1, s)#xs)))#ys)\"\n    using a1 a3 minimum_nest_call by blast\n  then have p_q:\"p\\<le>n \\<and> q\\<le>n\" using a0 a1  a3 a4 min_call_less_eq_n by blast\n  {\n    assume ass0:\"p<n \\<and> q <n\"     \n    then have \"(p,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call\" and\n              \"(q,\\<Gamma>,(c2, snd(last ((c1, s)#xs)))#ys) \\<in> cptn_mod_nest_call\"\n      using min_calls unfolding min_call_def by auto\n    then have ?thesis\n    proof (cases \"p\\<le>q\")\n      case True \n      then have q_cptn_c1:\"(q, \\<Gamma>, (c1, s) # xs) \\<in> cptn_mod_nest_call\" \n        using cptn_mod_nest_mono min_calls unfolding min_call_def  \n        by blast\n      have q_cptn_c2:\"(q, \\<Gamma>, (c2, snd (last ((c1, s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n       using min_calls unfolding min_call_def by auto\n      then have \"(q,\\<Gamma>,((Seq c1 c2,s)#zs)) \\<in>cptn_mod_nest_call\"\n        using True min_calls a2 a4  CptnModNestSeq2[OF q_cptn_c1 a2 q_cptn_c2 a4] \n        by auto\n      thus ?thesis using ass0 a0 unfolding min_call_def by auto\n    next\n      case False\n      then have q_cptn_c1:\"(p, \\<Gamma>, (c1, s) # xs) \\<in> cptn_mod_nest_call\" \n        using  min_calls unfolding min_call_def  \n        by blast\n      have q_cptn_c2:\"(p, \\<Gamma>, (c2, snd (last ((c1, s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n       using min_calls False unfolding min_call_def\n       by (metis (no_types, lifting) cptn_mod_nest_mono2 not_less)\n      then have \"(p,\\<Gamma>,((Seq c1 c2,s)#zs)) \\<in>cptn_mod_nest_call\"\n        using False min_calls a2 a4  CptnModNestSeq2[OF q_cptn_c1 a2 q_cptn_c2 a4] \n        by auto\n      thus ?thesis using ass0 a0 unfolding min_call_def by auto\n    qed\n  }note l=this\n  {\n    assume ass0:\"p\\<ge>n \\<or> q \\<ge>n\" \n    then have ?thesis using p_q min_calls by fastforce\n  }\n  thus ?thesis using l by fastforce\nqed\n\nlemma min_call_seq3:\n  \"min_call n \\<Gamma> ((Seq c1 c2,s)#zs) \\<Longrightarrow>\n   s= Normal s'' \\<Longrightarrow>\n   (n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call \\<Longrightarrow> \n    fst(last ((c1, s)#xs)) = Throw \\<Longrightarrow>\n    snd(last ((c1, s)#xs)) = Normal s' \\<Longrightarrow>\n   (n,\\<Gamma>,(Throw, snd(last ((c1, s)#xs)))#ys) \\<in> cptn_mod_nest_call \\<Longrightarrow>\n    zs=(map (lift c2) xs)@((Throw, snd(last ((c1, s)#xs)))#ys) \\<Longrightarrow>\n   min_call n \\<Gamma> ((c1, s)#xs)\n   \"\nproof -\n  assume a0:\"min_call n \\<Gamma> ((Seq c1 c2,s)#zs)\" and\n         a0':\"s= Normal s''\" and\n         a1:\"(n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call\" and\n         a2:\"fst(last ((c1, s)#xs)) = Throw\" and\n         a2':\"snd(last ((c1, s)#xs)) = Normal s'\" and\n         a3:\"(n,\\<Gamma>,(Throw, snd(last ((c1, s)#xs)))#ys) \\<in> cptn_mod_nest_call\" and\n         a4:\"zs=(map (lift c2) xs)@((Throw, snd(last ((c1, s)#xs)))#ys)\"\n  then obtain p where min_calls: \n    \"min_call p \\<Gamma> ((c1, s)#xs) \\<and> min_call 0 \\<Gamma> ((Throw, snd(last ((c1, s)#xs)))#ys)\"\n    using a1 a3 minimum_nest_call throw_min_nested_call_0  by metis\n  then have p_q:\"p\\<le>n \\<and> 0\\<le>n\" using a0 a1  a3 a4 min_call_less_eq_n by blast\n  {\n    assume ass0:\"p<n \\<and> 0 <n\"     \n    then have \"(p,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call\" and\n              \"(0,\\<Gamma>,(Throw, snd(last ((c1, s)#xs)))#ys) \\<in> cptn_mod_nest_call\"\n      using min_calls unfolding min_call_def by auto\n    then have ?thesis\n    proof (cases \"p\\<le>0\")\n      case True \n      then have q_cptn_c1:\"(0, \\<Gamma>, (c1, Normal s'') # xs) \\<in> cptn_mod_nest_call\" \n        using cptn_mod_nest_mono min_calls a0' unfolding min_call_def  \n        by blast\n      have q_cptn_c2:\"(0, \\<Gamma>, (Throw, snd (last ((c1, s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n       using min_calls unfolding min_call_def by auto\n      then have \"(0,\\<Gamma>,((Seq c1 c2,s)#zs)) \\<in>cptn_mod_nest_call\"\n        using True min_calls a2 a4 a2' a0'  CptnModNestSeq3[OF q_cptn_c1 ] \n        by auto\n      thus ?thesis using ass0 a0 unfolding min_call_def by auto\n    next\n      case False\n      then have q_cptn_c1:\"(p, \\<Gamma>, (c1, Normal s'') # xs) \\<in> cptn_mod_nest_call\" \n        using  min_calls a0' unfolding min_call_def  \n        by blast\n      have q_cptn_c2:\"(p, \\<Gamma>, (Throw, snd (last ((c1, s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n       using min_calls False unfolding min_call_def\n       by (metis (no_types, lifting) cptn_mod_nest_mono2 not_less)\n      then have \"(p,\\<Gamma>,((Seq c1 c2,s)#zs)) \\<in>cptn_mod_nest_call\"\n        using False min_calls a2 a4 a0' a2'  CptnModNestSeq3[OF q_cptn_c1]\n        by auto       \n      thus ?thesis using ass0 a0 unfolding min_call_def by auto\n    qed\n  }note l=this\n  {\n    assume ass0:\"p\\<ge>n \\<or> 0 \\<ge>n\" \n    then have ?thesis using p_q min_calls by fastforce\n  }\n  thus ?thesis using l by fastforce\nqed\n\nlemma min_call_catch2:\n  \"min_call n \\<Gamma> ((Catch c1 c2,s)#zs) \\<Longrightarrow>   \n   (n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call \\<Longrightarrow> \n    fst(last ((c1, s)#xs)) = Skip \\<Longrightarrow>    \n   (n,\\<Gamma>,(Skip, snd(last ((c1, s)#xs)))#ys) \\<in> cptn_mod_nest_call \\<Longrightarrow>\n    zs=(map (lift_catch c2) xs)@((Skip, snd(last ((c1, s)#xs)))#ys) \\<Longrightarrow>\n   min_call n \\<Gamma> ((c1, s)#xs)\n   \"\nproof -\n  assume a0:\"min_call n \\<Gamma> ((Catch c1 c2,s)#zs)\" and        \n         a1:\"(n,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call\" and\n         a2:\"fst(last ((c1, s)#xs)) = Skip\" and        \n         a3:\"(n,\\<Gamma>,(Skip, snd(last ((c1, s)#xs)))#ys) \\<in> cptn_mod_nest_call\" and\n         a4:\"zs=(map (lift_catch c2) xs)@((Skip, snd(last ((c1, s)#xs)))#ys)\"\n  then obtain p where min_calls: \n    \"min_call p \\<Gamma> ((c1, s)#xs) \\<and> min_call 0 \\<Gamma> ((Skip, snd(last ((c1, s)#xs)))#ys)\"\n    using a1 a3 minimum_nest_call skip_min_nested_call_0  by metis\n  then have p_q:\"p\\<le>n \\<and> 0\\<le>n\" using a0 a1  a3 a4 min_call_less_eq_n by blast\n  {\n    assume ass0:\"p<n \\<and> 0 <n\"     \n    then have \"(p,\\<Gamma>, (c1, s)#xs) \\<in> cptn_mod_nest_call\" and\n              \"(0,\\<Gamma>,(Skip, snd(last ((c1, s)#xs)))#ys) \\<in> cptn_mod_nest_call\"\n      using min_calls unfolding min_call_def by auto\n    then have ?thesis\n    proof (cases \"p\\<le>0\")\n      case True \n      then have q_cptn_c1:\"(0, \\<Gamma>, (c1, s) # xs) \\<in> cptn_mod_nest_call\" \n        using cptn_mod_nest_mono min_calls  unfolding min_call_def  \n        by blast\n      have q_cptn_c2:\"(0, \\<Gamma>, (Skip, snd (last ((c1, s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n       using min_calls unfolding min_call_def by auto\n      then have \"(0,\\<Gamma>,((Catch c1 c2,s)#zs)) \\<in>cptn_mod_nest_call\"\n        using True min_calls a2 a4    CptnModNestCatch2[OF q_cptn_c1 ] \n        by auto\n      thus ?thesis using ass0 a0 unfolding min_call_def by auto\n    next\n      case False\n      then have q_cptn_c1:\"(p, \\<Gamma>, (c1, s) # xs) \\<in> cptn_mod_nest_call\" \n        using  min_calls  unfolding min_call_def  \n        by blast\n      have q_cptn_c2:\"(p, \\<Gamma>, (Skip, snd (last ((c1, s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n       using min_calls False unfolding min_call_def\n       by (metis (no_types, lifting) cptn_mod_nest_mono2 not_less)\n      then have \"(p,\\<Gamma>,((Catch c1 c2,s)#zs)) \\<in>cptn_mod_nest_call\"\n        using False min_calls a2 a4   CptnModNestCatch2[OF q_cptn_c1]\n        by auto       \n      thus ?thesis using ass0 a0 unfolding min_call_def by auto\n    qed\n  }note l=this\n  {\n    assume ass0:\"p\\<ge>n \\<or> 0 \\<ge>n\" \n    then have ?thesis using p_q min_calls by fastforce\n  }\n  thus ?thesis using l by fastforce\nqed\n\nlemma min_call_catch_less_eq_n:\n  \"(n,\\<Gamma>, (c1, Normal s)#xs) \\<in> cptn_mod_nest_call \\<Longrightarrow>        \n   (n,\\<Gamma>,(c2, snd(last ((c1, Normal s)#xs)))#ys) \\<in> cptn_mod_nest_call \\<Longrightarrow>    \n   min_call p \\<Gamma> ((c1, Normal s)#xs) \\<and> min_call q \\<Gamma> ((c2, snd(last ((c1, Normal s)#xs)))#ys) \\<Longrightarrow>\n   p\\<le>n \\<and> q\\<le>n\"\nunfolding min_call_def\nusing le_less_linear by blast\n\nlemma min_call_catch3:\n  \"min_call n \\<Gamma> ((Catch c1 c2,Normal s)#zs) \\<Longrightarrow>\n   (n,\\<Gamma>, (c1, Normal s)#xs) \\<in> cptn_mod_nest_call \\<Longrightarrow> \n    fst(last ((c1, Normal s)#xs)) = Throw \\<Longrightarrow>\n    snd(last ((c1, Normal s)#xs)) = Normal s' \\<Longrightarrow>\n   (n,\\<Gamma>,(c2, snd(last ((c1, Normal s)#xs)))#ys) \\<in> cptn_mod_nest_call \\<Longrightarrow>\n    zs=(map (lift_catch c2) xs)@((c2, snd(last ((c1, Normal s)#xs)))#ys) \\<Longrightarrow>\n   min_call n \\<Gamma> ((c1, Normal s)#xs) \\<or> min_call n \\<Gamma> ((c2, snd(last ((c1, Normal s)#xs)))#ys)\n   \"\nproof -\n  assume a0:\"min_call n \\<Gamma> ((Catch c1 c2,Normal s)#zs)\" and\n         a1:\"(n,\\<Gamma>, (c1, Normal s)#xs) \\<in> cptn_mod_nest_call\" and\n         a2:\"fst(last ((c1, Normal s)#xs)) = Throw\" and\n         a2':\"snd(last ((c1, Normal s)#xs)) = Normal s'\" and\n         a3:\"(n,\\<Gamma>,(c2, snd(last ((c1, Normal s)#xs)))#ys) \\<in> cptn_mod_nest_call\" and\n         a4:\"zs=(map (lift_catch c2) xs)@((c2, snd(last ((c1, Normal s)#xs)))#ys)\"\n  then obtain p q where min_calls: \n    \"min_call p \\<Gamma> ((c1, Normal s)#xs) \\<and> min_call q \\<Gamma> ((c2, snd(last ((c1, Normal s)#xs)))#ys)\"\n    using a1 a3 minimum_nest_call by blast\n  then have p_q:\"p\\<le>n \\<and> q\\<le>n\" \n    using a1 a2 a2' a3 a4 min_call_less_eq_n by blast\n  {\n    assume ass0:\"p<n \\<and> q <n\"     \n    then have \"(p,\\<Gamma>, (c1, Normal s)#xs) \\<in> cptn_mod_nest_call\" and\n              \"(q,\\<Gamma>,(c2, snd(last ((c1, Normal s)#xs)))#ys) \\<in> cptn_mod_nest_call\"\n      using min_calls unfolding min_call_def by auto\n    then have ?thesis\n    proof (cases \"p\\<le>q\")\n      case True \n      then have q_cptn_c1:\"(q, \\<Gamma>, (c1,Normal s) # xs) \\<in> cptn_mod_nest_call\" \n        using cptn_mod_nest_mono min_calls unfolding min_call_def  \n        by blast\n      have q_cptn_c2:\"(q, \\<Gamma>, (c2, snd (last ((c1, Normal s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n       using min_calls unfolding min_call_def by auto\n      then have \"(q,\\<Gamma>,((Catch c1 c2, Normal s)#zs)) \\<in>cptn_mod_nest_call\"\n        using True min_calls a2 a2' a4  CptnModNestCatch3[OF q_cptn_c1 a2 a2' q_cptn_c2 a4] \n        by auto\n      thus ?thesis using ass0 a0 unfolding min_call_def by auto\n    next\n      case False\n      then have q_cptn_c1:\"(p, \\<Gamma>, (c1, Normal s) # xs) \\<in> cptn_mod_nest_call\" \n        using  min_calls unfolding min_call_def  \n        by blast\n      have q_cptn_c2:\"(p, \\<Gamma>, (c2, snd (last ((c1, Normal s) # xs))) # ys) \\<in> cptn_mod_nest_call\"\n       using min_calls False unfolding min_call_def\n       by (metis (no_types, lifting) cptn_mod_nest_mono2 not_less)\n      then have \"(p,\\<Gamma>,((Catch c1 c2,Normal s)#zs)) \\<in>cptn_mod_nest_call\"\n        using False min_calls a2 a4  CptnModNestCatch3[OF q_cptn_c1 a2 a2' q_cptn_c2 a4] \n        by auto\n      thus ?thesis using ass0 a0 unfolding min_call_def by auto\n    qed\n  }note l=this\n  {\n    assume ass0:\"p\\<ge>n \\<or> q \\<ge>n\" \n    then have ?thesis using p_q min_calls by fastforce\n  }\n  thus ?thesis using l by fastforce\nqed\n\nlemma min_call_seq_c1_not_finish:\n  \"min_call n \\<Gamma> cfg \\<Longrightarrow>\n   cfg = (LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1 \\<Longrightarrow>\n   (n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call \\<Longrightarrow>\n   (Q, t) # cfg1 = map (lift P1) xs \\<Longrightarrow>\n   min_call  n \\<Gamma> ((P0, s)#xs)\n   \"\nproof -\n  assume a0:\"min_call n \\<Gamma> cfg\" and\n        a1:\" cfg = (LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1\" and\n        a2:\"(n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call\" and\n        a3:\"(Q, t) # cfg1 = map (lift P1) xs\" \n  then have \"(n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call\" using a2 by auto\n  moreover have \"\\<forall>m<n. (m, \\<Gamma>,(P0, s)#xs) \\<notin> cptn_mod_nest_call\"\n  proof-\n    {fix m\n     assume ass:\"m<n\"\n     {  assume ass1:\"(m, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call\"\n       then have \"(m,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" \n         using a1 a3 CptnModNestSeq1[OF ass1] by auto\n       then have False using ass a0 unfolding min_call_def by auto\n     }\n     then have \"(m, \\<Gamma>, (P0, s) # xs) \\<notin> cptn_mod_nest_call\" by auto\n    } then show ?thesis by auto\n  qed\n  ultimately show ?thesis unfolding min_call_def by auto\nqed\n\nlemma min_call_seq_not_finish:\n  \" min_call  n \\<Gamma> ((P0, s)#xs) \\<Longrightarrow>\n   cfg = (LanguageCon.com.Seq P0 P1, s) #  cfg1 \\<Longrightarrow>  \n    cfg1 = map (lift P1) xs \\<Longrightarrow>\n   min_call n \\<Gamma> cfg \n   \"\nproof -\n  assume a0:\"min_call  n \\<Gamma> ((P0, s)#xs)\" and\n        a1:\" cfg = (LanguageCon.com.Seq P0 P1, s) #  cfg1\" and        \n        a2:\" cfg1 = map (lift P1) xs\" \n  then have \"(n, \\<Gamma>,cfg) \\<in> cptn_mod_nest_call\" \n    using a0 a1 a2 CptnModNestSeq1[of n \\<Gamma> P0 s xs \"cfg1\" P1] unfolding min_call_def \n    by auto\n  moreover have \"\\<forall>m<n. (m, \\<Gamma>,cfg) \\<notin> cptn_mod_nest_call\"\n  proof-\n    {fix m\n     assume ass:\"m<n\"\n     {  assume ass1:\"(m, \\<Gamma>, cfg) \\<in> cptn_mod_nest_call\"\n       then have \"(m,\\<Gamma>,(P0, s)#xs) \\<in>  cptn_mod_nest_call\" \n         using a1 a2 by (metis (no_types) Seq_P_Not_finish div_seq_nest) \n       then have False using ass a0 unfolding min_call_def by auto\n     }\n     then have \"(m, \\<Gamma>, cfg) \\<notin> cptn_mod_nest_call\" by auto\n    } then show ?thesis by auto\n  qed\n  ultimately show ?thesis unfolding min_call_def by auto\nqed\n\nlemma min_call_catch_c1_not_finish:\n  \"min_call n \\<Gamma> cfg \\<Longrightarrow>\n   cfg = (LanguageCon.com.Catch P0 P1, s) # (Q, t) # cfg1 \\<Longrightarrow>\n   (n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call \\<Longrightarrow>\n   (Q, t) # cfg1 = map (lift_catch P1) xs \\<Longrightarrow>\n   min_call  n \\<Gamma> ((P0, s)#xs)\n   \"\nproof -\n  assume a0:\"min_call n \\<Gamma> cfg\" and\n        a1:\" cfg = (LanguageCon.com.Catch P0 P1, s) # (Q, t) # cfg1\" and\n        a2:\"(n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call\" and\n        a3:\"(Q, t) # cfg1 = map (lift_catch P1) xs\" \n  then have \"(n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call\" using a2 by auto\n  moreover have \"\\<forall>m<n. (m, \\<Gamma>,(P0, s)#xs) \\<notin> cptn_mod_nest_call\"\n  proof-\n    {fix m\n     assume ass:\"m<n\"\n     {  assume ass1:\"(m, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call\"\n       then have \"(m,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" \n         using a1 a3 CptnModNestCatch1[OF ass1] by auto\n       then have False using ass a0 unfolding min_call_def by auto\n     }\n     then have \"(m, \\<Gamma>, (P0, s) # xs) \\<notin> cptn_mod_nest_call\" by auto\n    } then show ?thesis by auto\n  qed\n  ultimately show ?thesis unfolding min_call_def by auto\nqed\n\nlemma min_call_catch_not_finish:\n  \" min_call  n \\<Gamma> ((P0, s)#xs) \\<Longrightarrow>\n   cfg = (LanguageCon.com.Catch P0 P1, s) #  cfg1 \\<Longrightarrow>  \n    cfg1 = map (lift_catch P1) xs \\<Longrightarrow>\n   min_call n \\<Gamma> cfg \n   \"\nproof -\n  assume a0:\"min_call  n \\<Gamma> ((P0, s)#xs)\" and\n        a1:\" cfg = (Catch P0 P1, s) #  cfg1\" and        \n        a2:\" cfg1 = map (lift_catch P1) xs\" \n  then have \"(n, \\<Gamma>,cfg) \\<in> cptn_mod_nest_call\" \n    using a0 a1 a2 CptnModNestCatch1[of n \\<Gamma> P0 s xs \"cfg1\" P1] unfolding min_call_def \n    by auto\n  moreover have \"\\<forall>m<n. (m, \\<Gamma>,cfg) \\<notin> cptn_mod_nest_call\"\n  proof-\n    {fix m\n     assume ass:\"m<n\"\n     {  assume ass1:\"(m, \\<Gamma>, cfg) \\<in> cptn_mod_nest_call\"\n       then have \"(m,\\<Gamma>,(P0, s)#xs) \\<in>  cptn_mod_nest_call\" \n         using a1 a2 by (metis (no_types) Catch_P_Not_finish div_catch_nest) \n       then have False using ass a0 unfolding min_call_def by auto\n     }\n     then have \"(m, \\<Gamma>, cfg) \\<notin> cptn_mod_nest_call\" by auto\n    } then show ?thesis by auto\n  qed\n  ultimately show ?thesis unfolding min_call_def by auto\nqed\n\nlemma seq_xs_no_empty: assumes\n     seq:\"seq_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \\<Gamma> n\" and\n     cfg:\"cfg = (LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1\" and\n     a0:\"SmallStepCon.redex (LanguageCon.com.Seq P0 P1) = LanguageCon.com.Call f\"\n     shows\"\\<exists>Q' xs'. Q=Seq Q' P1 \\<and> xs=(Q',t)#xs'\"\nusing seq\nunfolding lift_def seq_cond_nest_def\nproof\n    assume \"(Q, t) # cfg1 = map (\\<lambda>(P, s). (LanguageCon.com.Seq P P1, s)) xs\"\n    thus ?thesis by auto\nnext\n  assume \"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \\<and>\n        (\\<exists>ys. (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n              (Q, t) # cfg1 =\n              map (\\<lambda>(P, s). (LanguageCon.com.Seq P P1, s)) xs @\n              (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<or>\n        fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n        snd (last ((P0, s) # xs)) = Normal s' \\<and>\n        s = Normal s'' \\<and>\n        (\\<exists>ys. (n, \\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and>\n              (Q, t) # cfg1 =\n              map (\\<lambda>(P, s). (LanguageCon.com.Seq P P1, s)) xs @\n              (LanguageCon.com.Throw, Normal s') # ys)\"\n  thus ?thesis\n  proof \n    assume ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \\<and>\n        (\\<exists>ys. (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n              (Q, t) # cfg1 =\n              map (\\<lambda>(P, s). (LanguageCon.com.Seq P P1, s)) xs @\n              (P1, snd (((P0, s) # xs) ! length xs)) # ys)\"\n    show ?thesis \n    proof (cases xs)\n      case Nil thus ?thesis using cfg a0 ass by auto\n    next\n      case (Cons xa xsa)\n      then obtain a b where xa:\"xa = (a,b)\" by fastforce\n      obtain pps :: \"(('a, 'b, 'c, 'd) LanguageCon.com \\<times> ('a, 'c) xstate) list\" where\n            \"(Q, t) # cfg1 = ((case (a, b) of (c, x) \\<Rightarrow> (LanguageCon.com.Seq c P1, x)) # map (\\<lambda>(c, y). \n                             (LanguageCon.com.Seq c P1, y)) xsa) @ \n                             (P1, snd (((P0, s) # xs) ! length xs)) # pps\"\n        using xa ass local.Cons by moura\n       then show ?thesis\n         by (simp add: xa local.Cons)\n    qed      \n  next\n    assume ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n        snd (last ((P0, s) # xs)) = Normal s' \\<and>\n        s = Normal s'' \\<and>\n        (\\<exists>ys. (n, \\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and>\n              (Q, t) # cfg1 =\n              map (\\<lambda>(P, s). (LanguageCon.com.Seq P P1, s)) xs @\n              (LanguageCon.com.Throw, Normal s') # ys)\"\n    thus ?thesis\n    proof (cases xs)\n      case Nil thus ?thesis using cfg a0 ass by auto\n    next\n      case (Cons xa xsa)\n      then obtain a b where xa:\"xa = (a,b)\" by fastforce\n      obtain pps :: \"(('a, 'b, 'c, 'd) LanguageCon.com \\<times> ('a, 'c) xstate) list\" where\n        \"(Q, t) # cfg1 = ((case (a, b) of (c, x) \\<Rightarrow> (LanguageCon.com.Seq c P1, x)) # map (\\<lambda>(c, y). \n              (LanguageCon.com.Seq c P1, y)) xsa) @ (LanguageCon.com.Throw, Normal s') # pps\"\n        using ass local.Cons xa by force\n      then show ?thesis\n        by (simp add: local.Cons xa)\n    qed           \n  qed\nqed\n\nlemma catch_xs_no_empty: assumes\n     seq:\"catch_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \\<Gamma> n\" and\n     cfg:\"cfg = (LanguageCon.com.Catch P0 P1, s) # (Q, t) # cfg1\" and\n     a0:\"SmallStepCon.redex (LanguageCon.com.Catch P0 P1) = LanguageCon.com.Call f\"\n     shows\"\\<exists>Q' xs'. Q=Catch Q' P1 \\<and> xs=(Q',t)#xs'\"\nusing seq\nunfolding lift_catch_def catch_cond_nest_def\nproof\n    assume \"(Q, t) # cfg1 = map (\\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs\"\n    thus ?thesis by auto\nnext\n  assume \"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n    snd (last ((P0, s) # xs)) = Normal s' \\<and>\n    s = Normal s'' \\<and>\n    (\\<exists>ys. (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n          (Q, t) # cfg1 = map (\\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @ \n                                          (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<or>\n    fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \\<and>\n    (\\<exists>ys. (n, \\<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n          (Q, t) # cfg1 =\n          map (\\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @ \n                         (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys)\"\n  thus ?thesis\n  proof \n    assume ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n                snd (last ((P0, s) # xs)) = Normal s' \\<and>\n                s = Normal s'' \\<and>\n                (\\<exists>ys. (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n                  (Q, t) # cfg1 = map (\\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @ \n                                          (P1, snd (((P0, s) # xs) ! length xs)) # ys)\"\n    show ?thesis \n    proof (cases xs)\n      case Nil thus ?thesis using cfg a0 ass by auto\n    next\n      case (Cons xa xsa)\n      then obtain a b where xa:\"xa = (a,b)\" by fastforce\n      obtain pps :: \"(('a, 'b, 'c, 'd) LanguageCon.com \\<times> ('a, 'c) xstate) list\" where\n       \"(Q, t) # cfg1 = ((case (a, b) of (c, x) \\<Rightarrow> (LanguageCon.com.Catch c P1, x)) # \n            map (\\<lambda>(c, y). (LanguageCon.com.Catch c P1, y)) xsa) @ \n                           (P1, snd (((P0, s) # xs) ! length xs)) # pps\"\n       using ass local.Cons xa by moura\n     then show ?thesis\n       by (simp add: local.Cons xa)\n    qed     \n  next\n    assume ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \\<and>\n    (\\<exists>ys. (n, \\<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n          (Q, t) # cfg1 =\n          map (\\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @ \n                         (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys)\"\n    thus ?thesis\n    proof (cases xs)\n      case Nil thus ?thesis using cfg a0 ass by auto\n    next\n      case (Cons xa xsa)\n      then obtain a b where xa:\"xa = (a,b)\" by fastforce      \n      obtain pps :: \"(('a, 'b, 'c, 'd) LanguageCon.com \\<times> ('a, 'c) xstate) list\" where\n        \"(Q, t) # cfg1 = ((case (a, b) of (c, x) \\<Rightarrow> \n           (LanguageCon.com.Catch c P1, x)) # map (\\<lambda>(c, y). \n             (LanguageCon.com.Catch c P1, y)) xsa) @ \n               (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # pps\"\n        using ass local.Cons xa by force\n      then show ?thesis\n        by (simp add: local.Cons xa)\n    qed        \n  qed\nqed\n\nlemma redex_call_cptn_mod_min_nest_call_gr_zero:\n assumes a0:\"min_call n \\<Gamma> cfg\" and\n         a1:\"cfg = (P,s)#(Q,t)#cfg1\" and\n         a2:\"redex P = Call f \\<and>  \n             \\<Gamma> f = Some bdy \\<and> (\\<exists>sa. s=Normal sa) \\<and> t=s\" and\n         a3:\"\\<Gamma>\\<turnstile>\\<^sub>c(P,s)\\<rightarrow>(Q,t)\"\n shows \"n>0\"\nusing a0 a1 a2 a3\nproof (induct P arbitrary: Q cfg1 cfg s t n)\n  case (Call f1) thus ?case\n   by (metis SmallStepCon.redex.simps(7) elim_cptn_mod_nest_call_n_greater_zero min_call_def option.distinct(1) stepc_Normal_elim_cases(9))\nnext\n  case (Seq P0 P1) \n  then obtain xs s' s'' where \n          p0_cptn:\"(n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call\"  and \n          seq:\"seq_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \\<Gamma> n\"\n  using div_seq_nest[of n \\<Gamma> cfg] unfolding min_call_def by blast\n  then obtain m where min:\"min_call m \\<Gamma> ((P0, s)#xs)\"\n    using minimum_nest_call by blast \n  have xs':\"\\<exists>Q' xs'. Q=Seq Q' P1 \\<and> xs=(Q',t)#xs'\"\n     using seq Seq seq_xs_no_empty by auto \n  then have \"0<m\" using Seq(1,5,6) min\n    using SmallStepCon.redex.simps(4) stepc_elim_cases_Seq_Seq by fastforce\n  thus ?case by (metis min min_call_def not_gr0 p0_cptn) \nnext\n  case (Catch P0 P1)\n then obtain xs s' s'' where \n          p0_cptn:\"(n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call\"  and \n          seq:\"catch_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \\<Gamma> n\"\n  using div_catch_nest[of n \\<Gamma> cfg] unfolding min_call_def by blast\n  then obtain m where min:\"min_call m \\<Gamma> ((P0, s)#xs)\"\n    using minimum_nest_call by blast \n  obtain Q' xs' where xs':\"Q=Catch Q' P1 \\<and> xs=(Q',t)#xs'\"\n     using catch_xs_no_empty[OF seq Catch(4)] Catch by blast\n  then have \"0<m\" using Catch(1,5,6) min\n    using SmallStepCon.redex.simps(4) stepc_elim_cases_Catch_Catch by fastforce\n  thus ?case by (metis min min_call_def not_gr0 p0_cptn)\nqed(auto)\n\n  \n\nlemma elim_redex_call_cptn_mod_min_nest_call:\n assumes a0:\"min_call n \\<Gamma> cfg\" and\n         a1:\"cfg = (P,s)#(Q,t)#cfg1\" and\n         a2:\"redex P = Call f \\<and>  \n             \\<Gamma> f = Some bdy \\<and> (\\<exists>sa. s=Normal sa) \\<and> t=s \" and\n         a3:\"biggest_nest_call P s ((Q,t)#cfg1) \\<Gamma> n\"  \n shows \"min_call n \\<Gamma> ((Q,t)#cfg1)\"\nusing a0 a1 a2 a3 \nproof (induct P arbitrary: Q cfg1 cfg s t n)  \n  case Cond thus ?case by fastforce\nnext\n  case (Seq P0 P1) \n  then obtain xs s' s'' where \n          p0_cptn:\"(n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call\"  and \n          seq:\"seq_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \\<Gamma> n\"\n  using div_seq_nest[of n \\<Gamma> cfg] unfolding min_call_def by blast\n  \n  show ?case using seq unfolding seq_cond_nest_def \n  proof\n    assume ass:\"(Q, t) # cfg1 = map (lift P1) xs\"   \n    then obtain Q' xs' where xs':\"Q=Seq Q' P1 \\<and> xs=(Q',t)#xs'\"\n      unfolding lift_def by fastforce\n    then have ctpn_P0:\"(P0, s) # xs = (P0, s) # (Q', t) # xs'\" by auto\n    then have min_p0:\"min_call n \\<Gamma> ((P0, s)#xs)\"\n      using min_call_seq_c1_not_finish[OF Seq(3) Seq(4) p0_cptn] ass by auto\n    then have ex_xs:\"\\<exists>xs. min_call n \\<Gamma> ((P0, s)#xs) \\<and> (Q, t) # cfg1 = map (lift P1) xs\" \n      using ass by auto\n    then have min_xs:\"min_call n \\<Gamma> ((P0, s)#xs) \\<and> (Q, t) # cfg1 = map (lift P1) xs\" \n      using min_p0 ass by auto\n    have \"xs= (SOME xs. (min_call n \\<Gamma> ((P0, s)#xs) \\<and> (Q, t) # cfg1 = map (lift P1) xs))\"\n    proof -\n      have \"\\<forall>xsa. min_call n \\<Gamma> ((P0, s)#xsa) \\<and> (Q, t) # cfg1 = map (lift P1) xsa \\<longrightarrow> xsa = xs\"\n        using xs' ass by (metis map_lift_eq_xs_xs')\n      thus ?thesis using min_xs some_equality by (metis (mono_tags, lifting))\n    qed\n    then have big:\"biggest_nest_call P0 s ((Q', t) # xs') \\<Gamma> n\" \n      using biggest_nest_call.simps(1)[of P0 P1 s \"((Q, t) # cfg1)\" \\<Gamma> n] \n            Seq(6) xs' ex_xs by auto         \n    have reP0:\"redex P0 = (Call f) \\<and> \\<Gamma> f = Some bdy \\<and> \n              (\\<exists>saa. s = Normal saa) \\<and> t = s \" using Seq(5) xs' by auto    \n    have min_call:\"min_call n \\<Gamma> ((Q', t) # xs')\" \n       using Seq(1)[OF min_p0 ctpn_P0 reP0] big xs' ass by auto\n    thus ?thesis using min_call_seq_not_finish[OF min_call] ass xs' by blast\n  next\n    assume ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \\<and>\n                  (\\<exists>ys. (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n                  (Q, t) # cfg1 = map (lift P1) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<or>\n                fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n                  snd (last ((P0, s) # xs)) = Normal s' \\<and>\n                  s = Normal s'' \\<and>\n                  (\\<exists>ys. (n, \\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and>\n                     (Q, t) # cfg1 = map (lift P1) xs @ (LanguageCon.com.Throw, Normal s') # ys)\"\n    {assume ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \\<and>\n            (\\<exists>ys. (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n            (Q, t) # cfg1 = map (lift P1) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys)\"     \n     have ?thesis \n     proof (cases xs)\n       case Nil thus ?thesis using Seq ass by fastforce\n     next\n       case (Cons xa xsa)\n       then obtain ys where \n         seq2_ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \\<and> \n          (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n          (Q, t) # cfg1 = map (lift P1) (xa#xsa) @ (P1, snd (((P0, s) # xs) ! length xs)) # ys\"\n          using ass by auto \n        then obtain mq mp1 where \n         min_call_q:\"min_call mq \\<Gamma> ((P0, s) # xs)\" and\n         min_call_p1:\"min_call mp1 \\<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)\"         \n       using seq2_ass minimum_nest_call p0_cptn by fastforce               \n       then have mp: \"mq\\<le>n \\<and> mp1 \\<le>n\"\n         using seq2_ass min_call_less_eq_n[of n \\<Gamma> P0 s xs P1 ys  mq mp1] \n             Seq(3,4) p0_cptn by (simp add: last_length)\n       have min_call:\"min_call n \\<Gamma> ((P0, s) # xs) \\<or> \n             min_call n \\<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)\"\n         using seq2_ass min_call_seq2[of n \\<Gamma> P0 P1 s \"(Q, t) # cfg1\" xs ys] \n             Seq(3,4) p0_cptn by (simp add: last_length local.Cons)       \n       from seq2_ass obtain Q' where Q':\"Q=Seq Q' P1 \\<and> xa=(Q',t)\"          \n       unfolding lift_def   \n         by (metis (mono_tags, lifting) fst_conv length_greater_0_conv \n             list.simps(3) list.simps(9) nth_Cons_0 nth_append prod.case_eq_if prod.collapse snd_conv)  \n       then have q'_n_cptn:\"(n,\\<Gamma>,(Q',t)#xsa)\\<in>cptn_mod_nest_call\" using p0_cptn Q' Cons\n         using elim_cptn_mod_nest_call_n by blast \n       show ?thesis\n       proof(cases \"mp1=n\")\n         case True\n         then have \"min_call n \\<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)\"\n           using min_call_p1 by auto\n         then have min_P1:\"min_call n \\<Gamma> ((P1, snd ((xa # xsa) ! length xsa)) # ys)\"\n           using Cons seq2_ass by fastforce         \n         then have p1_n_cptn:\"(n, \\<Gamma>,  (Q, t) # cfg1) \\<in> cptn_mod_nest_call\"\n           using Seq.prems(1) Seq.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast\n         also then have \"(\\<forall>m<n. (m, \\<Gamma>, (Q, t) # cfg1) \\<notin> cptn_mod_nest_call)\" \n         proof-\n         { fix m\n           assume ass:\"m<n\" \n           { assume Q_m:\"(m, \\<Gamma>, (Q, t) # cfg1) \\<in> cptn_mod_nest_call\"             \n            then have False using min_P1 ass Q' Cons unfolding min_call_def\n            proof -\n              assume a1: \"(n, \\<Gamma>, (P1, snd ((xa # xsa) ! length xsa)) # ys) \\<in> cptn_mod_nest_call \\<and> (\\<forall>m<n. (m, \\<Gamma>, (P1, snd ((xa # xsa) ! length xsa)) # ys) \\<notin> cptn_mod_nest_call)\"\n              have f2: \"\\<forall>n f ps. (n, f, ps) \\<notin> cptn_mod_nest_call \\<or> (\\<forall>x c ca psa. ps \\<noteq> (LanguageCon.com.Seq (c::('b, 'a, 'c,'d) LanguageCon.com) ca, x) # psa \\<or> (\\<exists>ps b ba. (n, f, (c, x) # ps) \\<in> cptn_mod_nest_call \\<and> seq_cond_nest psa ca ps c x ba b f n))\"\n                using div_seq_nest by blast\n              have f3: \"(P1, snd (last ((Q', t) # xsa))) # ys = (P1, snd (((P0, s) # xs) ! length xs)) # ys\"\n                by (simp add: Q' last_length local.Cons)\n              have \"fst (last ((Q', t) # xsa)) = LanguageCon.com.Skip\"\n                by (metis (no_types) Q' last_ConsR last_length list.distinct(1) local.Cons seq2_ass)\n              then show ?thesis\n                using f3 f2 a1 by (metis (no_types) Cons_lift_append Q' Seq_P_Ends_Normal Q_m ass seq2_ass)\n            qed\n           } \n         } then show ?thesis by auto\n         qed           \n         ultimately show ?thesis unfolding min_call_def by auto\n       next\n         case False\n         then have \"mp1<n\" using mp by auto\n         then have not_min_call_p1_n:\"\\<not> min_call n \\<Gamma> ((P1, snd (last ((P0, s) # xs))) # ys)\"\n           using min_call_p1 last_length unfolding min_call_def by metis\n         then have min_call:\"min_call n \\<Gamma> ((P0, s) # xs)\" \n           using min_call last_length unfolding min_call_def by metis\n         then have \"(P0, s) # xs = (P0, s) # xa#xsa\"\n           using Cons by auto\n         then have big:\"biggest_nest_call P0 s (((Q',t))#xsa) \\<Gamma> n\"\n         proof-\n           have \"\\<not>(\\<exists>xs. min_call n \\<Gamma> ((P0, s)#xs) \\<and> (Q, t) # cfg1 = map (lift P1) xs)\"\n             using min_call seq2_ass Cons\n            proof -\n              have \"min_call n \\<Gamma> ((LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1)\"\n                using Seq.prems(1) Seq.prems(2) by blast\n              then show ?thesis\n                by (metis (no_types) Seq_P_Not_finish append_Nil2 list.simps(3) \n                          local.Cons min_call_def same_append_eq seq seq2_ass)\n            qed\n            moreover have \"\\<exists>xs ys. cond_seq_1 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys\"\n              using seq2_ass p0_cptn unfolding cond_seq_1_def \n              by (metis last_length local.Cons) \n            moreover have \"(SOME xs. \\<exists>ys. cond_seq_1 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys) = xs\"  \n            proof -\n              let ?P = \"\\<lambda>xsa. \\<exists>ys. (n, \\<Gamma>, (P0, s) # xsa) \\<in> cptn_mod_nest_call \\<and>\n                   fst (last ((P0, s) # xsa)) = LanguageCon.com.Skip \\<and>\n                   (n, \\<Gamma>, (P1, snd (last ((P0, s) # xsa))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                   (Q, t) # cfg1 = map (lift P1) xsa @ (P1, snd (last ((P0, s) # xsa))) # ys\"             \n              have \"(\\<And>x. \\<exists>ys. (n, \\<Gamma>, (P0, s) # x) \\<in> cptn_mod_nest_call \\<and>\n               fst (last ((P0, s) # x)) = LanguageCon.com.Skip \\<and>\n               (n, \\<Gamma>, (P1, snd (last ((P0, s) # x))) # ys) \\<in> cptn_mod_nest_call \\<and>\n               (Q, t) # cfg1 = map (lift P1) x @ (P1, snd (last ((P0, s) # x))) # ys \\<Longrightarrow>\n                   x = xs)\"              \n              by (metis Seq_P_Ends_Normal cptn_mod_nest_call.CptnModNestSeq2 seq)\n              moreover have \"\\<exists>ys. (n, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call \\<and>\n                   fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \\<and>\n                   (n, \\<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                   (Q, t) # cfg1 = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys\"\n                using ass  p0_cptn by (simp add: last_length)               \n              ultimately show ?thesis using some_equality[of ?P xs]\n                 unfolding cond_seq_1_def by blast \n            qed\n            moreover have \"(SOME ys. cond_seq_1 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys) = ys\"\n            proof -\n               let ?P = \"\\<lambda>ys. (n, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call \\<and>\n                   fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \\<and>\n                   (n, \\<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                   (Q, t) # cfg1 = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys\"\n                have \"(n, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call \\<and>\n                   fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \\<and>\n                   (n, \\<Gamma>, (P1, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                   (Q, t) # cfg1 = map (lift P1) xs @ (P1, snd (last ((P0, s) # xs))) # ys\"\n                 using p0_cptn seq2_ass Cons   by (simp add: last_length) \n                then show ?thesis using some_equality[of ?P ys]\n                 unfolding cond_seq_1_def by fastforce      \n            qed\n            ultimately have \"biggest_nest_call P0 s xs \\<Gamma> n\"\n              using not_min_call_p1_n Seq(6) \n                    biggest_nest_call.simps(1)[of P0 P1 s \"(Q, t) # cfg1\" \\<Gamma> n]\n              by presburger\n            then show ?thesis  using Cons Q' by auto\n          qed\n          have C:\"(P0, s) # xs = (P0, s) # (Q', t) # xsa\" using Cons Q' by auto\n          have reP0:\"redex P0 = (Call f) \\<and> \\<Gamma> f = Some bdy \\<and> \n            (\\<exists>saa. s = Normal saa) \\<and> t = s\" using Seq(5) Q' by auto\n          then have min_call:\"min_call n \\<Gamma> ((Q', t) # xsa)\" using Seq(1)[OF min_call C reP0 big]\n            by auto\n          have p1_n_cptn:\"(n, \\<Gamma>,  (Q, t) # cfg1) \\<in> cptn_mod_nest_call\"\n            using Seq.prems(1) Seq.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast\n          also then have \"(\\<forall>m<n. (m, \\<Gamma>, (Q, t) # cfg1) \\<notin> cptn_mod_nest_call)\" \n          proof-\n           { fix m\n             assume ass:\"m<n\" \n             { assume Q_m:\"(m, \\<Gamma>, (Q, t) # cfg1) \\<in> cptn_mod_nest_call\" \n               then obtain xsa' s1 s1' where \n                  p0_cptn:\"(m, \\<Gamma>,(Q', t)#xsa') \\<in> cptn_mod_nest_call\"  and\n                  seq:\"seq_cond_nest cfg1 P1 xsa' Q' t s1 s1' \\<Gamma> m\"\n               using div_seq_nest[of m \\<Gamma> \"(Q, t) # cfg1\"] Q' by blast\n               then have \"xsa=xsa'\" \n                 using seq2_ass \n                 Seq_P_Ends_Normal[of cfg1 P1 xsa Q' t ys m \\<Gamma> xsa' s1 s1'] Cons\n                 by (metis Cons_lift_append Q' Q_m last.simps last_length list.inject list.simps(3)) \n               then have False using min_call p0_cptn ass unfolding min_call_def by auto \n             } \n           } then show ?thesis by auto qed\n             \n         ultimately show ?thesis unfolding min_call_def by auto\n       qed    \n     qed\n    }note l=this\n    {assume ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n             snd (last ((P0, s) # xs)) = Normal s' \\<and>\n            s = Normal s'' \\<and> (\\<exists>ys. (n, \\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and>\n          (Q, t) # cfg1 = map (lift P1) xs @ (LanguageCon.com.Throw, Normal s') # ys)\"          \n     have ?thesis\n     proof (cases \"\\<Gamma>\\<turnstile>\\<^sub>c(LanguageCon.com.Seq P0 P1, s) \\<rightarrow> (Q,t)\")\n       case True \n       thus  ?thesis\n       proof (cases xs)\n          case Nil thus ?thesis using Seq ass by fastforce\n       next\n         case (Cons xa xsa)\n         then obtain ys where \n           seq2_ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n             snd (last ((P0, s) # xs)) = Normal s' \\<and>\n            s = Normal s'' \\<and>  (n, \\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and>\n           (Q, t) # cfg1 = map (lift P1) xs @ (LanguageCon.com.Throw, Normal s') # ys\"\n            using ass by auto \n         then have t_eq:\"t=Normal s''\" using Seq by fastforce\n         obtain mq mp1 where \n           min_call_q:\"min_call mq \\<Gamma> ((P0, s) # xs)\" and\n           min_call_p1:\"min_call mp1 \\<Gamma> ((Throw, snd (((P0, s) # xs) ! length xs)) # ys)\"         \n         using seq2_ass minimum_nest_call p0_cptn by (metis last_length)\n         then have mp1_zero:\"mp1=0\" by (simp add: throw_min_nested_call_0)\n         then have min_call: \"min_call n \\<Gamma> ((P0, s) # xs)\"  \n           using seq2_ass min_call_seq3[of n \\<Gamma> P0 P1 s \"(Q, t) # cfg1\" s'' xs s' ys]\n             Seq(3,4) p0_cptn by (metis last_length)      \n         have n_z:\"n>0\" using redex_call_cptn_mod_min_nest_call_gr_zero[OF Seq(3) Seq(4) Seq(5) True]\n           by auto          \n         from seq2_ass obtain Q' where Q':\"Q=Seq Q' P1 \\<and> xa=(Q',t)\"          \n           unfolding lift_def using Cons\n          proof -\n            assume a1: \"\\<And>Q'. Q = LanguageCon.com.Seq Q' P1 \\<and> xa = (Q', t) \\<Longrightarrow> thesis\"\n            have \"(LanguageCon.com.Seq (fst xa) P1, snd xa) = ((Q, t) # cfg1) ! 0\"\n             using seq2_ass unfolding lift_def\n              by (simp add: Cons case_prod_unfold)\n            then show ?thesis\n              using a1 by fastforce\n          qed  \n         have big_call:\"biggest_nest_call P0 s ((Q',t)#xsa) \\<Gamma> n\"\n         proof-\n           have \"\\<not>(\\<exists>xs. min_call n \\<Gamma> ((P0, s)#xs) \\<and> (Q, t) # cfg1 = map (lift P1) xs)\"\n             using min_call seq2_ass Cons Seq.prems(1) Seq.prems(2)\n           by (metis Seq_P_Not_finish append_Nil2 list.simps(3) min_call_def same_append_eq seq)\n           moreover have \"\\<not>(\\<exists>xs ys. cond_seq_1 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys)\" \n             using min_call seq2_ass p0_cptn Cons Seq.prems(1) Seq.prems(2) \n             unfolding cond_seq_1_def\n            by (metis com.distinct(17) com.distinct(71) last_length \n                      map_lift_some_eq seq_and_if_not_eq(4))\n           moreover have \"(SOME xs. \\<exists>ys s' s''. cond_seq_2 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys s' s'') = xs\"\n           proof-\n             let ?P=\"\\<lambda>xsa. \\<exists>ys s' s''. s= Normal s'' \\<and> \n                    (n,\\<Gamma>, (P0, s)#xs) \\<in> cptn_mod_nest_call \\<and> \n                    fst(last ((P0, s)#xs)) = Throw \\<and>\n                    snd(last ((P0, s)#xs)) = Normal s' \\<and> \n                    (n,\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod_nest_call \\<and> \n                     ((Q, t) # cfg1)=(map (lift P1) xs)@((Throw,Normal s')#ys)\"\n             have \"(\\<And>x. \\<exists>ys s' s''. s= Normal s'' \\<and> \n                    (n,\\<Gamma>, (P0, s)#x) \\<in> cptn_mod_nest_call \\<and> \n                    fst(last ((P0, s)#x)) = Throw \\<and>\n                    snd(last ((P0, s)#x)) = Normal s' \\<and> \n                    (n,\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod_nest_call \\<and> \n                     ((Q, t) # cfg1)=(map (lift P1) x)@((Throw,Normal s')#ys) \\<Longrightarrow>\n                    x=xs)\" using map_lift_some_eq seq2_ass by fastforce\n             moreover have \"\\<exists>ys s' s''. s= Normal s'' \\<and> \n                    (n,\\<Gamma>, (P0, s)#xs) \\<in> cptn_mod_nest_call \\<and> \n                    fst(last ((P0, s)#xs)) = Throw \\<and>\n                    snd(last ((P0, s)#xs)) = Normal s' \\<and> \n                    (n,\\<Gamma>,(Throw,Normal s')#ys) \\<in> cptn_mod_nest_call \\<and> \n                     ((Q, t) # cfg1)=(map (lift P1) xs)@((Throw,Normal s')#ys)\" \n                using ass p0_cptn by (simp add: last_length Cons)\n            ultimately show ?thesis using some_equality[of ?P xs]\n                 unfolding cond_seq_2_def by blast\n         qed\n           ultimately have \"biggest_nest_call P0 s xs \\<Gamma> n\"\n            using  Seq(6) \n                  biggest_nest_call.simps(1)[of P0 P1 s \"(Q, t) # cfg1\" \\<Gamma> n]\n            by presburger\n           then show ?thesis  using Cons Q' by auto\n         qed         \n         have min_call:\"min_call n \\<Gamma> ((Q',t)#xsa)\" \n           using Seq(1)[OF min_call _ _ big_call] Seq(5) Cons Q' by fastforce   \n         then have p1_n_cptn:\"(n, \\<Gamma>,  (Q, t) # cfg1) \\<in> cptn_mod_nest_call\"\n            using Seq.prems(1) Seq.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast   \n         also then have \"(\\<forall>m<n. (m, \\<Gamma>, (Q, t) # cfg1) \\<notin> cptn_mod_nest_call)\" \n          proof-\n           { fix m\n             assume ass:\"m<n\" \n             { assume Q_m:\"(m, \\<Gamma>, (Q, t) # cfg1) \\<in> cptn_mod_nest_call\" \n               then obtain xsa' s1 s1' where \n                  p0_cptn:\"(m, \\<Gamma>,(Q', t)#xsa') \\<in> cptn_mod_nest_call\"  and\n                  seq:\"seq_cond_nest cfg1 P1 xsa' Q' (Normal s'') s1 s1' \\<Gamma> m\"\n               using div_seq_nest[of m \\<Gamma> \"(Q, t) # cfg1\"] Q' t_eq by blast\n               then have \"xsa=xsa'\" \n                 using seq2_ass \n                 Seq_P_Ends_Abort[of cfg1 P1 xsa s' ys Q' s'' m \\<Gamma> xsa' s1 s1' ] Cons Q' Q_m\n                 by (simp add: Cons_lift_append last_length t_eq)                 \n               then have False using min_call p0_cptn ass unfolding min_call_def by auto \n             } \n           } then show ?thesis by auto qed          \n         ultimately show ?thesis unfolding min_call_def by auto\n       qed\n     next\n       case False \n       then have env:\"\\<Gamma>\\<turnstile>\\<^sub>c(LanguageCon.com.Seq P0 P1, s) \\<rightarrow>\\<^sub>e (Q,t)\" using Seq\n         by (meson elim_cptn_mod_nest_step_c min_call_def)\n       moreover then have Q:\"Q=Seq P0 P1\" using env_c_c' by blast        \n       ultimately show ?thesis using Seq\n        proof -\n          obtain nn :: \"(('b, 'a, 'c,'d) LanguageCon.com \\<times> ('b, 'c) xstate) list \\<Rightarrow> \n                         ('a \\<Rightarrow> ('b, 'a, 'c,'d) LanguageCon.com option) \\<Rightarrow> nat \\<Rightarrow> nat\" where\n            f1: \"\\<forall>x0 x1 x2. (\\<exists>v3<x2. (v3, x1, x0) \\<in> cptn_mod_nest_call) = (nn x0 x1 x2 < x2 \\<and> (nn x0 x1 x2, x1, x0) \\<in> cptn_mod_nest_call)\"\n            by moura\n          have f2: \"(n, \\<Gamma>, (LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1) \\<in> cptn_mod_nest_call \\<and> (\\<forall>n. \\<not> n < n \\<or> (n, \\<Gamma>, (LanguageCon.com.Seq P0 P1, s) # (Q, t) # cfg1) \\<notin> cptn_mod_nest_call)\"\n            using local.Seq(3) local.Seq(4) min_call_def by blast\n          then have \"\\<not> nn ((Q, t) # cfg1) \\<Gamma> n < n \\<or> (nn ((Q, t) # cfg1) \\<Gamma> n, \\<Gamma>, (Q, t) # cfg1) \\<notin> cptn_mod_nest_call\"\n            using False env env_c_c'  not_func_redex_cptn_mod_nest_n_env \n            by (metis Seq.prems(1) Seq.prems(2) min_call_def)\n          then show ?thesis\n            using f2 f1 by (meson elim_cptn_mod_nest_call_n min_call_def)\n        qed\n     qed          \n    }\n    thus ?thesis using l ass by fastforce\n  qed\nnext\n  case (Catch P0 P1) \nthen obtain xs s' s'' where \n          p0_cptn:\"(n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call\"  and \n          catch:\"catch_cond_nest ((Q,t)#cfg1) P1 xs P0 s s'' s' \\<Gamma> n\"\n  using div_catch_nest[of n \\<Gamma> cfg] unfolding min_call_def by blast\n  \n  show ?case using catch unfolding catch_cond_nest_def \n  proof\n    assume ass:\"(Q, t) # cfg1 = map (lift_catch P1) xs\"   \n    then obtain Q' xs' where xs':\"Q=Catch Q' P1 \\<and> xs=(Q',t)#xs'\"\n      unfolding lift_catch_def by fastforce\n    then have ctpn_P0:\"(P0, s) # xs = (P0, s) # (Q', t) # xs'\" by auto\n    then have min_p0:\"min_call n \\<Gamma> ((P0, s)#xs)\"\n      using min_call_catch_c1_not_finish[OF Catch(3) Catch(4) p0_cptn] ass by auto\n    then have ex_xs:\"\\<exists>xs. min_call n \\<Gamma> ((P0, s)#xs) \\<and> (Q, t) # cfg1 = map (lift_catch P1) xs\" \n      using ass by auto\n    then have min_xs:\"min_call n \\<Gamma> ((P0, s)#xs) \\<and> (Q, t) # cfg1 = map (lift_catch P1) xs\" \n      using min_p0 ass by auto\n    have \"xs= (SOME xs. (min_call n \\<Gamma> ((P0, s)#xs) \\<and> (Q, t) # cfg1 = map (lift_catch P1) xs))\"\n    proof -\n      have \"\\<forall>xsa. min_call n \\<Gamma> ((P0, s)#xsa) \\<and> (Q, t) # cfg1 = map (lift_catch P1) xsa \\<longrightarrow> xsa = xs\"\n        using xs' ass by (metis map_lift_catch_eq_xs_xs')\n      thus ?thesis using min_xs some_equality by (metis (mono_tags, lifting))\n    qed\n    then have big:\"biggest_nest_call P0 s ((Q', t) # xs') \\<Gamma> n\" \n      using biggest_nest_call.simps(2)[of P0 P1 s \"((Q, t) # cfg1)\" \\<Gamma> n] \n            Catch(6) xs' ex_xs by auto          \n    have reP0:\"redex P0 = (Call f) \\<and> \\<Gamma> f = Some bdy \\<and> \n              (\\<exists>saa. s = Normal saa) \\<and> t = s \" using Catch(5) xs' by auto    \n    have min_call:\"min_call n \\<Gamma> ((Q', t) # xs')\" \n       using Catch(1)[OF min_p0 ctpn_P0 reP0] big xs' ass by auto\n    thus ?thesis using min_call_catch_not_finish[OF min_call] ass xs' by blast\n  next\n    assume ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n                snd (last ((P0, s) # xs)) = Normal s' \\<and>\n                s = Normal s'' \\<and>\n               (\\<exists>ys. (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n                  (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<or>\n                   fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \\<and>\n                  (\\<exists>ys. (n, \\<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                (Q, t) # cfg1 = map (lift_catch P1) xs @ (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys)\" \n    {assume ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n                snd (last ((P0, s) # xs)) = Normal s' \\<and>\n                s = Normal s'' \\<and>\n               (\\<exists>ys. (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n                  (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys)\"     \n     have ?thesis \n     proof (cases xs)\n       case Nil thus ?thesis using Catch ass by fastforce\n     next\n       case (Cons xa xsa)\n       then obtain ys where \n         catch2_ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and>\n                snd (last ((P0, s) # xs)) = Normal s' \\<and>\n                s = Normal s'' \\<and>\n                (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and>\n                (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys\"\n          using ass by auto \n        then obtain mq mp1 where \n         min_call_q:\"min_call mq \\<Gamma> ((P0, s) # xs)\" and\n         min_call_p1:\"min_call mp1 \\<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)\"         \n       using catch2_ass minimum_nest_call p0_cptn by fastforce               \n       then have mp: \"mq\\<le>n \\<and> mp1 \\<le>n\"\n         using catch2_ass min_call_less_eq_n \n             Catch(3,4) p0_cptn by (metis last_length) \n       have min_call:\"min_call n \\<Gamma> ((P0, s) # xs) \\<or> \n             min_call n \\<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)\"\n         using catch2_ass min_call_catch3[of n \\<Gamma> P0 P1 s'' \"(Q, t) # cfg1\" xs s' ys] \n             Catch(3,4) p0_cptn by (metis last_length)       \n       from catch2_ass obtain Q' where Q':\"Q=Catch Q' P1 \\<and> xa=(Q',t)\"          \n       unfolding lift_catch_def\n        proof -\n          assume a1: \"\\<And>Q'. Q = LanguageCon.com.Catch Q' P1 \\<and> xa = (Q', t) \\<Longrightarrow> thesis\"\n          assume \"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Throw \\<and> snd (last ((P0, s) # xs)) = Normal s' \\<and> s = Normal s'' \\<and> (n, \\<Gamma>, (P1, snd (((P0, s) # xs) ! length xs)) # ys) \\<in> cptn_mod_nest_call \\<and> (Q, t) # cfg1 = map (\\<lambda>(P, s). (LanguageCon.com.Catch P P1, s)) xs @ (P1, snd (((P0, s) # xs) ! length xs)) # ys\"\n          then have \"(LanguageCon.com.Catch (fst xa) P1, snd xa) = ((Q, t) # cfg1) ! 0\"\n            by (simp add: local.Cons prod.case_eq_if)\n          then show ?thesis\n            using a1 by force\n        qed            \n       then have q'_n_cptn:\"(n,\\<Gamma>,(Q',t)#xsa)\\<in>cptn_mod_nest_call\" using p0_cptn Q' Cons\n         using elim_cptn_mod_nest_call_n by blast \n       show ?thesis\n       proof(cases \"mp1=n\")\n         case True\n         then have \"min_call n \\<Gamma> ((P1, snd (((P0, s) # xs) ! length xs)) # ys)\"\n           using min_call_p1 by auto\n         then have min_P1:\"min_call n \\<Gamma> ((P1, snd ((xa # xsa) ! length xsa)) # ys)\"\n           using Cons catch2_ass by fastforce         \n         then have p1_n_cptn:\"(n, \\<Gamma>,  (Q, t) # cfg1) \\<in> cptn_mod_nest_call\"\n           using Catch.prems(1) Catch.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast\n         also then have \"(\\<forall>m<n. (m, \\<Gamma>, (Q, t) # cfg1) \\<notin> cptn_mod_nest_call)\" \n         proof-\n         { fix m\n           assume ass:\"m<n\" \n           { assume Q_m:\"(m, \\<Gamma>, (Q, t) # cfg1) \\<in> cptn_mod_nest_call\"   \n             then have t_eq_s:\"t=Normal s''\" using Catch catch2_ass by fastforce                      \n            then obtain xsa' s1 s1' where \n                  p0_cptn:\"(m, \\<Gamma>,(Q', t)#xsa') \\<in> cptn_mod_nest_call\"  and\n                  catch_cond:\"catch_cond_nest cfg1 P1 xsa' Q' (Normal s'') s1 s1' \\<Gamma> m\"\n              using Q_m div_catch_nest[of m \\<Gamma> \"(Q, t) # cfg1\"] Q' by blast\n            have fst:\"fst (last ((Q', Normal s'') # xsa)) = LanguageCon.com.Throw\" \n              using catch2_ass Cons Q' by (simp add: last_length  t_eq_s)\n            have cfg:\"cfg1 = map (lift_catch P1) xsa @ (P1, snd (last ((Q', Normal s'') # xsa))) # ys\"\n              using catch2_ass Cons Q' by (simp add: last_length  t_eq_s)\n            have snd:\"snd (last ((Q', Normal s'') # xsa)) = Normal s'\"\n              using catch2_ass Cons Q' by (simp add: last_length  t_eq_s)\n            then have \"xsa=xsa' \\<and> \n                   (m, \\<Gamma>, (P1, snd (((Q', Normal s'') # xsa) ! length xsa)) # ys) \\<in> cptn_mod_nest_call\" \n              using catch2_ass Catch_P_Ends_Normal[OF cfg fst snd catch_cond] Cons\n              by auto \n            then have False using min_P1 ass Q' t_eq_s unfolding min_call_def by auto              \n           } \n         } then show ?thesis by auto\n         qed           \n         ultimately show ?thesis unfolding min_call_def by auto\n       next\n         case False\n         then have \"mp1<n\" using mp by auto\n         then have not_min_call_p1_n:\"\\<not> min_call n \\<Gamma> ((P1, snd (last ((P0, s) # xs))) # ys)\"\n           using min_call_p1 last_length unfolding min_call_def by metis\n         then have min_call:\"min_call n \\<Gamma> ((P0, s) # xs)\" \n           using min_call last_length unfolding min_call_def by metis\n         then have \"(P0, s) # xs = (P0, s) # xa#xsa\"\n           using Cons by auto\n         then have big:\"biggest_nest_call P0 s (((Q',t))#xsa) \\<Gamma> n\"\n         proof-\n           have \"\\<not>(\\<exists>xs. min_call n \\<Gamma> ((P0, s)#xs) \\<and> (Q, t) # cfg1 = map (lift_catch P1) xs)\"\n             using min_call catch2_ass Cons\n            proof -\n              have \"min_call n \\<Gamma> ((Catch P0 P1, s) # (Q, t) # cfg1)\"\n                using Catch.prems(1) Catch.prems(2) by blast\n              then show ?thesis\n                by (metis (no_types) Catch_P_Not_finish append_Nil2 list.simps(3) \n                     same_append_eq catch catch2_ass)\n            qed\n            moreover have \"\\<not>(\\<exists>xs ys. cond_catch_1 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys)\"\n              unfolding cond_catch_1_def using catch2_ass \n              by (metis Catch_P_Ends_Skip LanguageCon.com.distinct(17) catch last_length)\n            moreover have \"\\<exists>xs ys. cond_catch_2 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys s' s''\"\n              using catch2_ass p0_cptn unfolding cond_catch_2_def last_length\n              by metis \n            moreover have \"(SOME xs. \\<exists>ys s' s''. cond_catch_2 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys s' s'') = xs\"  \n            proof -\n              let ?P = \"\\<lambda>xsa. s = Normal s'' \\<and>\n                              (n, \\<Gamma>, (P0, s) # xsa) \\<in> cptn_mod_nest_call \\<and>\n                              fst (last ((P0, s) # xsa)) = LanguageCon.com.Throw \\<and>\n                              snd (last ((P0, s) # xsa)) = Normal s' \\<and>\n                               (n, \\<Gamma>, (P1, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and> \n                               (Q, t) # cfg1 = map (lift_catch P1) xsa @ (P1, Normal s') # ys\"             \n              have \"(\\<And>x. \\<exists>ys s' s''. s = Normal s'' \\<and>\n                              (n, \\<Gamma>, (P0, s) # x) \\<in> cptn_mod_nest_call \\<and>\n                              fst (last ((P0, s) # x)) = LanguageCon.com.Throw \\<and>\n                              snd (last ((P0, s) # x)) = Normal s' \\<and>\n                               (n, \\<Gamma>, (P1, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and> \n                               (Q, t) # cfg1 = map (lift_catch P1) x @ (P1, Normal s') # ys \\<Longrightarrow>\n                   x = xs)\"              \n              by (metis Catch_P_Ends_Normal catch)\n              moreover have \"\\<exists>ys. s = Normal s'' \\<and>\n                              (n, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call \\<and>\n                              fst (last ((P0, s) # xs)) = LanguageCon.com.Throw \\<and>\n                              snd (last ((P0, s) # xs)) = Normal s' \\<and>\n                               (n, \\<Gamma>, (P1, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and> \n                               (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, Normal s') # ys\"\n                using ass  p0_cptn   by (metis (full_types) last_length )             \n              ultimately show ?thesis using some_equality[of ?P xs]\n                 unfolding cond_catch_2_def by blast \n            qed\n            moreover have \"(SOME ys. \\<exists>s' s''. cond_catch_2 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys s' s'') = ys\"\n            proof -\n               let ?P = \"\\<lambda>ysa. s = Normal s'' \\<and>\n                              (n, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call \\<and>\n                              fst (last ((P0, s) # xs)) = LanguageCon.com.Throw \\<and>\n                              snd (last ((P0, s) # xs)) = Normal s' \\<and>\n                               (n, \\<Gamma>, (P1, Normal s') # ysa) \\<in> cptn_mod_nest_call \\<and> \n                               (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, Normal s') # ysa\"\n                have \"(\\<And>x.  \\<exists>s' s''. s = Normal s'' \\<and>\n                          (n, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call \\<and>\n                          fst (last ((P0, s) # xs)) = LanguageCon.com.Throw \\<and>\n                          snd (last ((P0, s) # xs)) = Normal s' \\<and>\n                          (n, \\<Gamma>, (P1, Normal s') # x) \\<in> cptn_mod_nest_call \\<and> (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, Normal s') # x \\<Longrightarrow>\n                          x = ys)\" using catch2_ass by auto \n                moreover have \"s = Normal s'' \\<and>\n                      (n, \\<Gamma>, (P0, s) # xs) \\<in> cptn_mod_nest_call \\<and>\n                       fst (last ((P0, s) # xs)) = LanguageCon.com.Throw \\<and>\n                       snd (last ((P0, s) # xs)) = Normal s' \\<and>\n                      (n, \\<Gamma>, (P1, Normal s') # ys) \\<in> cptn_mod_nest_call \\<and> \n                       (Q, t) # cfg1 = map (lift_catch P1) xs @ (P1, Normal s') # ys\"\n                using ass  p0_cptn by (metis (full_types) catch2_ass last_length p0_cptn)             \n                ultimately show ?thesis using some_equality[of ?P ys]\n                 unfolding cond_catch_2_def by blast\n            qed            \n            ultimately have \"biggest_nest_call P0 s xs \\<Gamma> n\"\n              using not_min_call_p1_n Catch(6) \n                    biggest_nest_call.simps(2)[of P0 P1 s \"(Q, t) # cfg1\" \\<Gamma> n]\n              by presburger\n            then show ?thesis  using Cons Q' by auto\n          qed\n          have C:\"(P0, s) # xs = (P0, s) # (Q', t) # xsa\" using Cons Q' by auto\n          have reP0:\"redex P0 = (Call f) \\<and> \\<Gamma> f = Some bdy \\<and> \n            (\\<exists>saa. s = Normal saa) \\<and> t = s \" using Catch(5) Q' by auto\n          then have min_call:\"min_call n \\<Gamma> ((Q', t) # xsa)\" using Catch(1)[OF min_call C reP0 big]\n            by auto\n          have p1_n_cptn:\"(n, \\<Gamma>,  (Q, t) # cfg1) \\<in> cptn_mod_nest_call\"\n            using Catch.prems(1) Catch.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast\n          also then have \"(\\<forall>m<n. (m, \\<Gamma>, (Q, t) # cfg1) \\<notin> cptn_mod_nest_call)\" \n          proof-\n           { fix m\n             assume ass:\"m<n\" \n             { assume Q_m:\"(m, \\<Gamma>, (Q, t) # cfg1) \\<in> cptn_mod_nest_call\" \n               then have t_eq_s:\"t=Normal s''\" using Catch catch2_ass by fastforce\n               then obtain xsa' s1 s1' where \n                  p0_cptn:\"(m, \\<Gamma>,(Q', t)#xsa') \\<in> cptn_mod_nest_call\"  and\n                  catch_cond:\"catch_cond_nest cfg1 P1 xsa' Q' (Normal s'') s1 s1' \\<Gamma> m\"\n               using Q_m div_catch_nest[of m \\<Gamma> \"(Q, t) # cfg1\"] Q' by blast\n               have fst:\"fst (last ((Q', Normal s'') # xsa)) = LanguageCon.com.Throw\" \n                 using catch2_ass Cons Q' by (simp add: last_length  t_eq_s)\n              have cfg:\"cfg1 = map (lift_catch P1) xsa @ (P1, snd (last ((Q', Normal s'') # xsa))) # ys\"\n                 using catch2_ass Cons Q' by (simp add: last_length  t_eq_s)\n              have snd:\"snd (last ((Q', Normal s'') # xsa)) = Normal s'\"\n                using catch2_ass Cons Q' by (simp add: last_length  t_eq_s)\n               then have \"xsa=xsa'\" \n                 using catch2_ass Catch_P_Ends_Normal[OF cfg fst snd catch_cond] Cons\n                 by auto \n               then have False using min_call p0_cptn ass unfolding min_call_def by auto \n             } \n           } then show ?thesis by auto qed\n         ultimately show ?thesis unfolding min_call_def by auto\n       qed    \n     qed\n    }note l=this\n    {assume ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \\<and>\n             (\\<exists>ys. (n, \\<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n             (Q, t) # cfg1 = map (lift_catch P1) xs @ (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys)\"\n     have ?thesis\n     proof (cases \"\\<Gamma>\\<turnstile>\\<^sub>c(Catch P0 P1, s) \\<rightarrow> (Q,t)\")\n       case True \n       thus  ?thesis\n       proof (cases xs)\n          case Nil thus ?thesis using Catch ass by fastforce\n       next\n         case (Cons xa xsa)\n         then obtain ys where \n           catch2_ass:\"fst (((P0, s) # xs) ! length xs) = LanguageCon.com.Skip \\<and>\n             (n, \\<Gamma>, (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n             (Q, t) # cfg1 = map (lift_catch P1) xs @ (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys\"\n            using ass by auto \n         then have t_eq:\"t=s\" using Catch by fastforce\n         obtain mq mp1 where \n           min_call_q:\"min_call mq \\<Gamma> ((P0, s) # xs)\" and\n           min_call_p1:\"min_call mp1 \\<Gamma> ((Skip, snd (((P0, s) # xs) ! length xs)) # ys)\"         \n         using catch2_ass minimum_nest_call p0_cptn by (metis last_length)\n         then have mp1_zero:\"mp1=0\" by (simp add: skip_min_nested_call_0)\n         then have min_call: \"min_call n \\<Gamma> ((P0, s) # xs)\"  \n           using catch2_ass min_call_catch2[of n \\<Gamma> P0 P1 s \"(Q, t) # cfg1\" xs ys]\n             Catch(3,4) p0_cptn by (metis last_length)      \n         have n_z:\"n>0\" using redex_call_cptn_mod_min_nest_call_gr_zero[OF Catch(3) Catch(4) Catch(5) True]\n           by auto          \n         from catch2_ass obtain Q' where Q':\"Q=Catch Q' P1 \\<and> xa=(Q',t)\"          \n           unfolding lift_catch_def using Cons\n          proof -\n            assume a1: \"\\<And>Q'. Q = Catch Q' P1 \\<and> xa = (Q', t) \\<Longrightarrow> thesis\"\n            have \"(Catch (fst xa) P1, snd xa) = ((Q, t) # cfg1) ! 0\"\n             using catch2_ass unfolding lift_catch_def\n              by (simp add: Cons case_prod_unfold)\n            then show ?thesis\n              using a1 by fastforce\n          qed  \n         have big_call:\"biggest_nest_call P0 s ((Q',t)#xsa) \\<Gamma> n\"\n         proof-\n           have \"\\<not>(\\<exists>xs. min_call n \\<Gamma> ((P0, s)#xs) \\<and> (Q, t) # cfg1 = map (lift_catch P1) xs)\"\n             using min_call catch2_ass Cons\n           proof -\n             have \"min_call n \\<Gamma> ((Catch P0 P1, s) # (Q, t) # cfg1)\"\n               using Catch.prems(1) Catch.prems(2) by blast\n             then show ?thesis\n               by (metis (no_types) Catch_P_Not_finish append_Nil2 list.simps(3) \n                     same_append_eq catch catch2_ass)\n           qed\n           moreover have \"(\\<exists>xs ys. cond_catch_1 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys)\"\n             using catch2_ass p0_cptn unfolding cond_catch_1_def last_length\n             by metis\n           moreover have \"(SOME xs. \\<exists>ys. cond_catch_1 n \\<Gamma> P0 s xs P1 ((Q, t) # cfg1) ys) = xs\"\n           proof -\n             let ?P = \"\\<lambda>xsa. \\<exists>ys. (n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call \\<and> \n                            fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \\<and>\n                             (n, \\<Gamma>, (LanguageCon.com.Skip, \n                                snd (last ((P0, s) # xsa))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                             (Q, t) # cfg1 = map (lift_catch P1) xsa @ \n                               (LanguageCon.com.Skip, snd (last ((P0, s) # xsa))) # ys\"\n             have \"\\<And>xsa. \\<exists>ys. (n, \\<Gamma>,(P0, s)#xsa) \\<in> cptn_mod_nest_call \\<and> \n                             fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \\<and>\n                             (n, \\<Gamma>, (LanguageCon.com.Skip, \n                                snd (last ((P0, s) # xsa))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                             (Q, t) # cfg1 = map (lift_catch P1) xsa @ \n                               (LanguageCon.com.Skip, snd (last ((P0, s) # xsa))) # ys \\<Longrightarrow>\n                           xsa = xs\"\n             using Catch_P_Ends_Skip catch  catch2_ass map_lift_catch_some_eq by fastforce  \n             moreover have \"\\<exists>ys. (n, \\<Gamma>,(P0, s)#xs) \\<in> cptn_mod_nest_call \\<and>\n                               fst (last ((P0, s) # xs)) = LanguageCon.com.Skip \\<and>\n                             (n, \\<Gamma>, (LanguageCon.com.Skip, \n                                snd (last ((P0, s) # xs))) # ys) \\<in> cptn_mod_nest_call \\<and>\n                             (Q, t) # cfg1 = map (lift_catch P1) xs @ \n                               (LanguageCon.com.Skip, snd (last ((P0, s) # xs))) # ys\" \n               using ass p0_cptn by (simp add: last_length) \n             ultimately show ?thesis using some_equality[of ?P xs]\n                 unfolding cond_catch_1_def by blast \n           qed           \n           ultimately have \"biggest_nest_call P0 s xs \\<Gamma> n\"\n            using  Catch(6) \n                  biggest_nest_call.simps(2)[of P0 P1 s \"(Q, t) # cfg1\" \\<Gamma> n]\n            by presburger\n           then show ?thesis  using Cons Q' by auto\n         qed         \n         have min_call:\"min_call n \\<Gamma> ((Q',t)#xsa)\" \n           using Catch(1)[OF min_call _ _  big_call] Catch(5) Cons Q' by fastforce   \n         then have p1_n_cptn:\"(n, \\<Gamma>,  (Q, t) # cfg1) \\<in> cptn_mod_nest_call\"\n            using Catch.prems(1) Catch.prems(2) elim_cptn_mod_nest_call_n min_call_def by blast   \n         also then have \"(\\<forall>m<n. (m, \\<Gamma>, (Q, t) # cfg1) \\<notin> cptn_mod_nest_call)\" \n          proof-\n           { fix m\n             assume ass:\"m<n\" \n             { assume Q_m:\"(m, \\<Gamma>, (Q, t) # cfg1) \\<in> cptn_mod_nest_call\" \n               then obtain xsa' s1 s1' where \n                  p0_cptn:\"(m, \\<Gamma>,(Q', t)#xsa') \\<in> cptn_mod_nest_call\"  and\n                  seq:\"catch_cond_nest cfg1 P1 xsa' Q' t s1 s1' \\<Gamma> m\"\n               using div_catch_nest[of m \\<Gamma> \"(Q, t) # cfg1\"] Q' t_eq by blast\n               then have \"xsa=xsa'\" \n                 using catch2_ass \n                 Catch_P_Ends_Skip[of cfg1 P1 xsa Q' t ys xsa' s1 s1']  \n                 Cons Q' Q_m \n                 by (simp add:  last_length)                 \n               then have False using min_call p0_cptn ass unfolding min_call_def by auto \n             } \n           } then show ?thesis by auto qed          \n         ultimately show ?thesis unfolding min_call_def by auto\n       qed\n     next\n       case False \n       then have env:\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch P0 P1, s) \\<rightarrow>\\<^sub>e (Q,t)\" using Catch\n         by (meson elim_cptn_mod_nest_step_c min_call_def)\n       moreover then have Q:\"Q=Catch P0 P1\" using env_c_c' by blast        \n       ultimately show ?thesis using Catch\n        proof -\n          obtain nn :: \"(('b, 'a, 'c,'d) LanguageCon.com \\<times> ('b, 'c) xstate) list \\<Rightarrow> ('a \\<Rightarrow> ('b, 'a, 'c,'d) LanguageCon.com option) \\<Rightarrow> nat \\<Rightarrow> nat\" where\n            f1: \"\\<forall>x0 x1 x2. (\\<exists>v3<x2. (v3, x1, x0) \\<in> cptn_mod_nest_call) = (nn x0 x1 x2 < x2 \\<and> (nn x0 x1 x2, x1, x0) \\<in> cptn_mod_nest_call)\"\n            by moura\n          have f2: \"(n, \\<Gamma>, (LanguageCon.com.Catch P0 P1, s) # (Q, t) # cfg1) \\<in> cptn_mod_nest_call \\<and> (\\<forall>n. \\<not> n < n \\<or> (n, \\<Gamma>, (LanguageCon.com.Catch P0 P1, s) # (Q, t) # cfg1) \\<notin> cptn_mod_nest_call)\"\n            using local.Catch(3) local.Catch(4) min_call_def by blast\n          then have \"\\<not> nn ((Q, t) # cfg1) \\<Gamma> n < n \\<or> (nn ((Q, t) # cfg1) \\<Gamma> n, \\<Gamma>, (Q, t) # cfg1) \\<notin> cptn_mod_nest_call\"\n            using False env env_c_c'  not_func_redex_cptn_mod_nest_n_env \n            by (metis Catch.prems(1) Catch.prems(2) min_call_def)\n          then show ?thesis\n            using f2 f1 by (meson elim_cptn_mod_nest_call_n min_call_def)\n        qed\n     qed   \n    }\n    thus ?thesis using l ass by fastforce\n  qed   \nqed (fastforce)+\n\n\nlemma cptn_mod_nest_n_1:\n  assumes a0:\"(n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call\" and\n          a1:\"cfs=(p,s)#cfs'\" and\n          a2:\"\\<not> (min_call n \\<Gamma> cfs)\"\n  shows \"(n-1,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call\"\nusing a0 a1 a2 \nby (metis (no_types, lifting) Suc_diff_1 Suc_leI cptn_mod_nest_mono less_nat_zero_code min_call_def not_less)\n\nlemma cptn_mod_nest_tl_n_1:\n  assumes a0:\"(n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call\" and\n          a1:\"cfs=(p,s)#(q,t)#cfs'\" and\n          a2:\"\\<not> (min_call n \\<Gamma> cfs)\"\n  shows \"(n-1,\\<Gamma>,(q,t)#cfs') \\<in>  cptn_mod_nest_call\"\n  using a0 a1 a2\nby (meson elim_cptn_mod_nest_call_n cptn_mod_nest_n_1) \n\nlemma cptn_mod_nest_tl_not_min:\n  assumes a0:\"(n,\\<Gamma>,cfg) \\<in>  cptn_mod_nest_call\" and\n          a1:\"cfg=(p,s)#cfg'\" and\n          a2:\"\\<not> (min_call n \\<Gamma> cfg)\"\n  shows \"\\<not> (min_call n \\<Gamma> cfg')\"\nproof (cases cfg')\n  case Nil \n  have \"(\\<Gamma>, []) \\<notin> cptn\"\n    using cptn.simps by auto\n  then show ?thesis unfolding min_call_def\n    using cptn_eq_cptn_mod_set cptn_mod_nest_cptn_mod local.Nil by blast  \nnext\n  case (Cons xa cfga)\n  then obtain q t where \"xa = (q,t)\" by fastforce\n  then have \"(n-1,\\<Gamma>,cfg') \\<in>  cptn_mod_nest_call\"\n    using a0 a1 a2 cptn_mod_nest_tl_n_1 Cons by fastforce\n  also then have \"(n,\\<Gamma>,cfg') \\<in>  cptn_mod_nest_call\"\n    using cptn_mod_nest_mono Nat.diff_le_self by blast\n  ultimately show ?thesis unfolding min_call_def\n    using a0 a2 min_call_def by force \nqed\n  \n  \n\ndefinition cpn :: \"nat \\<Rightarrow> ('s,'p,'f,'e) body \\<Rightarrow> ('s,'p,'f,'e) com \\<Rightarrow> \n                  ('s,'f) xstate \\<Rightarrow> (('s,'p,'f,'e) confs) set\" \nwhere\n \"cpn n \\<Gamma> P s \\<equiv> {(\\<Gamma>1,l). l!0=(P,s) \\<and> (n,\\<Gamma>,l) \\<in> cptn_mod_nest_call \\<and> \\<Gamma>1=\\<Gamma>}\"\n\n\nlemma cptn_mod_same_n:\n  assumes a0:\"(\\<Gamma>,cfs)\\<in> cptn_mod\" \n  shows \"\\<exists>n. (n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call\"\nproof -\n show ?thesis using cptn_mod_nest_mono cptn_mod_cptn_mod_nest\n by (metis a0 cptn_mod_nest_mono2 leI)\nqed\n\nlemma cptn_mod_same_n1:\n  assumes a0:\"(\\<Gamma>,cfs)\\<in> cptn_mod\" and \n          a1:\"(\\<Gamma>,cfs1)\\<in> cptn_mod\"\n  shows \"\\<exists>n. (n,\\<Gamma>,cfs) \\<in>  cptn_mod_nest_call \\<and> (n,\\<Gamma>,cfs1) \\<in>  cptn_mod_nest_call\"\nproof -\n show ?thesis using cptn_mod_nest_mono cptn_mod_cptn_mod_nest\n by (metis a0 a1 cptn_mod_nest_mono2 leI)\nqed\n\n\nlemma dropcptn_is_cptn1 [rule_format,elim!]:\n  \"\\<forall>j<length c. (n,\\<Gamma>,c) \\<in> cptn_mod_nest_call \\<longrightarrow> (n,\\<Gamma>, drop j c) \\<in> cptn_mod_nest_call\"\nproof -\n  {fix j\n   assume \"j<length c \\<and> (n,\\<Gamma>,c) \\<in> cptn_mod_nest_call\"\n   then have \"(n,\\<Gamma>, drop j c) \\<in> cptn_mod_nest_call\" \n   proof(induction j arbitrary: c)\n     case 0 then show ?case by auto\n   next\n     case (Suc j) \n     then obtain a b c' where \"c=a#b#c'\"\n       by (metis Cons_nth_drop_Suc Suc_lessE drop_0 less_trans_Suc zero_less_Suc)\n     then also have \"j<length (b#c')\" using Suc by auto\n     ultimately moreover have \"(n, \\<Gamma>, drop j (b # c')) \\<in> cptn_mod_nest_call\" using elim_cptn_mod_nest_call_n[of n \\<Gamma> c] Suc\n       by (metis surj_pair) \n     ultimately show ?case by auto  \n   qed\n } thus ?thesis by auto \nqed\n\n   \n\nsubsection \\<open>Compositionality of the Semantics\\<close>\n\nsubsubsection \\<open>Definition of the conjoin operator\\<close>\n\ndefinition same_length :: \"('s,'p,'f,'e) par_confs \\<Rightarrow> (('s,'p,'f,'e) confs) list \\<Rightarrow> bool\" where\n  \"same_length c clist \\<equiv> (\\<forall>i<length clist. length(snd (clist!i))=length (snd c))\"\n\nlemma same_length_non_pair:\n  assumes a1:\"same_length c clist \" and\n          a2:\"clist'=map (\\<lambda>x. snd x) clist\"\n  shows \"(\\<forall>i <length clist'. length( (clist'!i))=length (snd c))\"\nusing a1 a2 by (auto simp add: same_length_def)\n\n\ndefinition same_state :: \"('s,'p,'f,'e) par_confs \\<Rightarrow> (('s,'p,'f,'e) confs) list \\<Rightarrow> bool\" where\n  \"same_state c clist \\<equiv> (\\<forall>i <length clist. \\<forall>j<length (snd c). snd((snd c)!j) = snd((snd (clist!i))!j))\"\n\nlemma same_state_non_pair:\n  assumes a1:\"same_state c clist \" and\n          a2:\"clist'=map (\\<lambda>x. snd x) clist\"\n  shows \"(\\<forall>i <length clist'. \\<forall>j<length (snd c). snd((snd c)!j) = snd( (clist'!i)!j))\"\nusing a1 a2 by (auto simp add: same_state_def)\n\ndefinition same_program :: \"('s,'p,'f,'e) par_confs \\<Rightarrow> (('s,'p,'f,'e) confs) list \\<Rightarrow> bool\" where\n  \"same_program c clist \\<equiv> (\\<forall>j<length (snd c). fst((snd c)!j) = map (\\<lambda>x. fst(nth (snd x) j)) clist)\"\n\nlemma same_program_non_pair:\n  assumes a1:\"same_program c clist \" and\n          a2:\"clist'=map (\\<lambda>x. snd x) clist\"\n  shows \"(\\<forall>j<length (snd c). fst((snd c)!j) = map (\\<lambda>x. fst(nth x j)) clist')\"\nusing a1 a2 by (auto simp add: same_program_def)\n\ndefinition same_functions :: \"('s,'p,'f,'e) par_confs \\<Rightarrow> (('s,'p,'f,'e) confs) list \\<Rightarrow> bool\" where\n \"same_functions c clist \\<equiv> \\<forall>i <length clist. fst (clist!i) = fst c\"\n\ndefinition compat_label :: \"('s,'p,'f,'e) par_confs \\<Rightarrow> (('s,'p,'f,'e) confs) list \\<Rightarrow> bool\" where\n  \"compat_label c clist \\<equiv> \n     (\\<forall>j. Suc j<length (snd c) \\<longrightarrow> \n         ( ((fst c)\\<turnstile>\\<^sub>p((snd c)!j)  \\<rightarrow> ((snd c)!(Suc j))) \\<and> \n            (\\<exists>i<length clist. \n               ((fst (clist!i))\\<turnstile>\\<^sub>c ((snd (clist!i))!j)  \\<rightarrow> ((snd (clist!i))!(Suc j))) \\<and> \n            (\\<forall>l<length clist. \n               l\\<noteq>i \\<longrightarrow>  (fst (clist!l))\\<turnstile>\\<^sub>c (snd (clist!l))!j  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc j))  ))) \\<or> \n         ((fst c)\\<turnstile>\\<^sub>p((snd c)!j)  \\<rightarrow>\\<^sub>e ((snd c)!(Suc j)) \\<and> \n          (\\<forall>i<length clist.  (fst (clist!i))\\<turnstile>\\<^sub>c (snd (clist!i))!j  \\<rightarrow>\\<^sub>e ((snd (clist!i))!(Suc j))   )))\"\n\nlemma compat_label_tran_0:\n assumes assm1:\"compat_label c clist \\<and> length (snd c) > Suc 0\" \n shows  \"((fst c)\\<turnstile>\\<^sub>p((snd c)!0)  \\<rightarrow> ((snd c)!(Suc 0))) \\<or> \n      ((fst c)\\<turnstile>\\<^sub>p((snd c)!0)  \\<rightarrow>\\<^sub>e ((snd c)!(Suc 0)))\"    \n  using assm1 unfolding compat_label_def\n by blast\n  \n  \ndefinition conjoin :: \"(('s,'p,'f,'e) par_confs) \\<Rightarrow> (('s,'p,'f,'e) confs) list \\<Rightarrow> bool\"  (\"_ \\<propto> _\" [65,65] 64) where\n  \"c \\<propto> clist \\<equiv> (same_length c clist) \\<and> (same_state c clist) \\<and> (same_program c clist) \\<and> \n                (compat_label c clist) \\<and> (same_functions c clist)\"\n\n\nlemma conjoin_same_length: \n   \"c \\<propto> clist \\<Longrightarrow> \\<forall>i < length (snd c). length (fst ((snd c)!i)) =  length clist\"\nproof (auto)\n  fix i\n  assume a1:\"c \\<propto> clist\"\n  assume a2:\"i < length (snd c)\"\n  then have \"(\\<forall>j<length (snd c). fst((snd c)!j) = map (\\<lambda>x. fst(nth (snd x) j)) clist)\"\n    using a1 unfolding conjoin_def same_program_def by auto\n  thus \"length (fst (snd c ! i)) = length clist\" by (simp add: a2)\nqed\n\nlemma \"c \\<propto> clist \\<Longrightarrow>\n       i< length (snd c) \\<and> j < length (snd c) \\<Longrightarrow>  \n       length (fst ((snd c)!i)) = length (fst ((snd c)!j))\"\nusing conjoin_same_length by fastforce\n\nlemma conjoin_same_length_i_suci:\"c \\<propto> clist \\<Longrightarrow>\n       Suc i< length (snd c) \\<Longrightarrow>\n       length (fst ((snd c)!i)) = length (fst ((snd c)!(Suc i)))\"\nusing conjoin_same_length by fastforce\n\nlemma conjoin_same_program_i:\n  \"c \\<propto> clist \\<Longrightarrow>\n   j < length (snd c) \\<Longrightarrow>\n   i < length clist \\<Longrightarrow>\n   fst ((snd (clist!i))!j) = (fst ((snd c)!j))!i\"\nproof -\n  assume a0:\"c \\<propto> clist\" and\n         a1:\"j < length (snd c)\" and\n         a2:\"i < length clist\"\n  have \"length (fst ((snd c)!j)) = length clist\"\n    using conjoin_same_length a0 a1 by fastforce\n  also have \"fst (snd c ! j) = map (\\<lambda>x. fst (snd x ! j)) clist\"\n    using a0 a1 unfolding conjoin_def same_program_def by fastforce\n  ultimately show ?thesis using a2 by fastforce\nqed\n\nlemma conjoin_same_program_i_j:\n  \"c \\<propto> clist \\<Longrightarrow>\n   Suc j < length (snd c) \\<Longrightarrow>\n   \\<forall>l< length clist. fst ((snd (clist!l))!j) = fst ((snd (clist!l))!(Suc j)) \\<Longrightarrow>\n   fst ((snd c)!j) = (fst ((snd c)!(Suc j)))\"\nproof -\n  assume a0:\"c \\<propto> clist\" and\n         a1:\"Suc j < length (snd c)\" and\n         a2:\"\\<forall>l< length clist. fst ((snd (clist!l))!j) = fst ((snd (clist!l))!(Suc j))\"\n  have \"length (fst ((snd c)!j)) = length clist\"\n    using conjoin_same_length a0 a1 by fastforce\n  then have \"map (\\<lambda>x. fst (snd x ! j)) clist = map (\\<lambda>x. fst (snd x ! (Suc j))) clist\"\n    using a2 by (metis (no_types, lifting) in_set_conv_nth map_eq_conv) \n  moreover have \"fst (snd c ! j) = map (\\<lambda>x. fst (snd x ! j)) clist\"\n    using a0 a1 unfolding conjoin_def same_program_def by fastforce\n  moreover have \"fst (snd c ! Suc j) = map (\\<lambda>x. fst (snd x ! Suc j)) clist\"\n    using a0 a1 unfolding conjoin_def same_program_def by fastforce\n  ultimately show ?thesis by fastforce\nqed\n\nlemma conjoin_last_same_state:\n  assumes a0: \"(\\<Gamma>,l)\\<propto> clist\" and\n   a1: \"i < length clist\" and\n   a2: \"(snd (clist!i))\\<noteq>[]\"\n   shows \"snd (last (snd (clist!i))) = snd (last l)\"\nproof -\n  have \"length l = length (snd (clist!i))\" \n    using a0 a1 unfolding conjoin_def same_length_def by fastforce\n  also then have length_l:\"length l \\<noteq>0\" using a2 by fastforce\n  ultimately have \"last (snd (clist!i)) = (snd (clist!i))!((length l)-1)\" \n    using a1 a2 \n    by (simp add: last_conv_nth)\n  thus ?thesis using length_l a0 a1 unfolding conjoin_def same_state_def\n    by (simp add:  a2 last_conv_nth )      \nqed\n\nlemma list_eq_if [rule_format]: \n  \"\\<forall>ys. xs=ys \\<longrightarrow> (length xs = length ys) \\<longrightarrow> (\\<forall>i<length xs. xs!i=ys!i)\"\n  by (induct xs) auto\n\n\n\nlemma list_eq: \"(length xs = length ys \\<and> (\\<forall>i<length xs. xs!i=ys!i)) = (xs=ys)\"\napply(rule iffI)\n apply clarify\n apply(erule nth_equalityI)\n apply simp+\ndone\n\nlemma nth_tl: \"\\<lbrakk> ys!0=a; ys\\<noteq>[] \\<rbrakk> \\<Longrightarrow> ys=(a#(tl ys))\"\n  by (cases ys) simp_all\n\nlemma nth_tl_if [rule_format]: \"ys\\<noteq>[] \\<longrightarrow> ys!0=a \\<longrightarrow> P ys \\<longrightarrow> P (a#(tl ys))\"\n  by (induct ys) simp_all\n\nlemma nth_tl_onlyif [rule_format]: \"ys\\<noteq>[] \\<longrightarrow> ys!0=a \\<longrightarrow> P (a#(tl ys)) \\<longrightarrow> P ys\"\n  by (induct ys) simp_all\n\nlemma nth_tl_eq [rule_format]: \"ys\\<noteq>[] \\<longrightarrow> ys!0=a \\<longrightarrow> P (a#(tl ys)) = P ys\"\n  by (induct ys) simp_all\n\nlemma nth_tl_pair: \"\\<lbrakk>p=(u,ys); ys!0=a; ys\\<noteq>[] \\<rbrakk> \\<Longrightarrow> p=(u,(a#(tl ys)))\"\nby (simp add: SmallStepCon.nth_tl)\n\nlemma nth_tl_eq_Pair [rule_format]: \"p=(u,ys) \\<longrightarrow> ys\\<noteq>[] \\<longrightarrow> ys!0=a \\<longrightarrow> P ((u,a#(tl ys))) = P (u,ys)\"\n  by (induct ys) simp_all\n\n\n\nlemma tl_in_cptn: \"\\<lbrakk> (g,a#xs) \\<in>cptn; xs\\<noteq>[] \\<rbrakk> \\<Longrightarrow> (g,xs)\\<in>cptn\"\n  by (force elim: cptn.cases)\n\n\nlemma tl_zero[rule_format]: \n  \" Suc j<length ys \\<longrightarrow> P (ys!Suc j) \\<longrightarrow> P (tl(ys)!j)\"\n  by (simp add: List.nth_tl)\n\nlemma tl_zero1[rule_format]:\n  \"Suc j<length ys \\<longrightarrow>P (tl(ys)!j) \\<longrightarrow>P (ys!Suc j)\"\n by (simp add: List.nth_tl)\n\nlemma tl_zero_eq [rule_format]:\n  \"Suc j<length ys \\<longrightarrow> (P (tl(ys)!j) = P (ys!Suc j))\"\nby (simp add: List.nth_tl)\n\nlemma tl_zero_eq' :\n   \"\\<forall>j. Suc j<length ys \\<longrightarrow> (P (tl(ys)!j) = P (ys!Suc j))\"\nusing tl_zero_eq by blast\n\nlemma tl_zero_pair:\"i < length ys \\<Longrightarrow> length ys = length zs \\<Longrightarrow>\n       Suc j < length (snd (ys!i)) \\<Longrightarrow>\n       snd (zs!i) = tl (snd (ys!i)) \\<Longrightarrow>        \n       P ((snd (ys!i))!(Suc j)) =\n       P ((snd (zs!i))!j)\"  \n  by (simp add: tl_zero_eq)\n\n\nlemma tl_zero_pair':\"\\<forall>i < length ys. length ys = length zs \\<longrightarrow>\n       Suc j < length (snd (ys!i)) \\<longrightarrow>\n       snd (zs!i) = tl (snd (ys!i)) \\<longrightarrow>        \n       (P ((snd (ys!i))!(Suc j)) =\n       P ((snd (zs!i))!j))\"  \nusing tl_zero_pair by blast\n\nlemma tl_zero_pair2:\"i < length ys \\<Longrightarrow> length ys = length zs \\<Longrightarrow>\n       Suc (Suc j) < length (snd (ys!i)) \\<Longrightarrow>\n       snd (zs!i) = tl (snd (ys!i)) \\<Longrightarrow>        \n       P ((snd (ys!i))!(Suc (Suc j))) ((snd (ys!i))!(Suc j))  =\n       P ((snd (zs!i))!(Suc j)) ((snd (zs!i))!j)\"  \n  by (simp add: tl_zero_eq)\n\nlemma tl_zero_pair2':\"\\<forall>i < length ys. length ys = length zs \\<longrightarrow>\n       Suc (Suc j) < length (snd (ys!i)) \\<longrightarrow>\n       snd (zs!i) = tl (snd (ys!i)) \\<longrightarrow>        \n       P ((snd (ys!i))!(Suc (Suc j))) ((snd (ys!i))!(Suc j))  =\n       P ((snd (zs!i))!(Suc j)) ((snd (zs!i))!j)\"  \nusing tl_zero_pair2  by blast\n\nlemma tl_zero_pair21:\"\\<forall>i < length ys. length ys = length zs \\<longrightarrow>\n       Suc (Suc j) < length (snd (ys!i)) \\<longrightarrow>\n       snd (zs!i) = tl (snd (ys!i)) \\<longrightarrow>        \n       P  ((snd (ys!i))!(Suc j))  ((snd (ys!i))!(Suc (Suc j)))=\n       P ((snd (zs!i))!j) ((snd (zs!i))!(Suc j)) \"\nby (metis SmallStepCon.nth_tl list.size(3) not_less0 nth_Cons_Suc)  \n\nlemma tl_pair:\"Suc (Suc j) < length l \\<Longrightarrow>     \n       l1 = tl l \\<Longrightarrow>\n       P (l!(Suc (Suc j))) (l!(Suc j)) =\n       P (l1!(Suc j)) (l1!j)\"\nby (simp add: tl_zero_eq)\n\nlemma list_as_map: \n  assumes \n     a1:\"length clist > 0\" and \n     a2: \"xs = (map (\\<lambda>x. fst (hd x)) clist)\" and\n     a3: \"ys = (map (\\<lambda>x. tl x) clist)\" and\n     a4: \"\\<forall>i< length clist. length (clist!i) > 0\" and     \n     a5: \"\\<forall>i < length clist. \\<forall>j< length clist. \\<forall>k<length  (clist!i).\n           snd ((clist!i)!k) = snd ((clist!j)!k)\" and\n     a6: \"\\<forall>i < length clist. \\<forall>j< length clist. \n            length (clist!i) = length (clist!j)\" \n     shows \"clist = map (\\<lambda>i. (fst i,snd ((clist!0)!0))#snd i) (zip xs ys)\"\nproof-\n  let ?clist'= \"map (\\<lambda>i. (fst i,snd ((clist!0)!0))#snd i) (zip xs ys)\"\n  have lens:\"length clist = length ?clist'\"  using a2 a3 by auto   \n  have \"(\\<forall>i<length clist. clist ! i = ?clist' ! i)\" \n  proof -\n    {\n      fix i    \n      assume a11:\"i<length clist\"\n      have xs_clist:\"xs!i = fst (hd (clist!i))\" using a2 a11 by auto\n      have ys_clist:\"ys!i = tl (clist ! i)\" using a3 a11 by auto\n      have snd_zero:\"snd (hd (clist!i)) = snd ((clist!0)!0)\" using a5 a4 \n        by (metis (no_types, lifting) a1 a11 hd_conv_nth less_numeral_extra(3) list.size(3))\n      then have \"(\\<lambda>i. (fst i,snd ((clist!0)!0))#snd i) ((zip xs ys)!i) = clist !i\"               \n        proof -\n          have f1: \"length xs = length clist\"\n            using a2 length_map by blast\n          have \"\\<not> (0::nat) < 0\"\n            by (meson less_not_refl)\n          thus ?thesis\n            using f1 by (metis (lifting) a11 a3 a4 \n                         fst_conv length_map list.exhaust_sel \n                         list.size(3) nth_zip prod.collapse \n                         snd_conv snd_zero xs_clist ys_clist)\n        qed      \n      then have \"clist ! i = ?clist' ! i\" using lens a11 by force\n    } \n    thus ?thesis by auto    \n  qed\n  thus ?thesis using lens list_eq by blast\nqed\n\nlemma list_as_map': \n  assumes \n     a1:\"length clist > 0\" and \n     a2: \"xs = (map (\\<lambda>x. hd x) clist)\" and\n     a3: \"ys = (map (\\<lambda>x. tl x) clist)\" and\n     a4: \"\\<forall>i< length clist. length (clist!i) > 0\"\n     shows \"clist = map (\\<lambda>i. (fst i)#snd i) (zip xs ys)\"\nproof-\n  let ?clist'= \"map (\\<lambda>i.(fst i)#snd i) (zip xs ys)\"\n  have lens:\"length clist = length ?clist'\" using a2 a3 by auto  \n  have \"(\\<forall>i<length clist. clist ! i = ?clist' ! i)\" \n  proof -\n    {\n      fix i    \n      assume a11:\"i<length clist\"\n      have xs_clist:\"xs!i = hd (clist!i)\" using a2 a11 by auto\n      have ys_clist:\"ys!i = tl (clist ! i)\" using a3 a11 by auto \n      then have \"(\\<lambda>i. fst i#snd i) ((zip xs ys)!i) = clist !i\"  \n        using xs_clist ys_clist a11 a2 a3 a4 by fastforce  \n      then have \"clist ! i = ?clist' ! i\" using lens a11 by force\n    } \n    thus ?thesis by auto    \n  qed\n  thus ?thesis using lens list_eq by blast\nqed\n\n\nlemma conjoin_tl: \n  assumes \n    a1: \"(\\<Gamma>,x#xs) \\<propto> ys\" and\n    a2:\"zs = map (\\<lambda>i. (fst i, tl (snd i))) ys\"    \n   shows \"(\\<Gamma>,xs) \\<propto> zs\"\nproof -\n  have s_p:\"same_program (\\<Gamma>,x#xs) ys\" using a1 unfolding conjoin_def by simp\n  have s_l:\"same_length (\\<Gamma>,x#xs) ys\" using a1 unfolding conjoin_def by simp\n  have \"\\<forall>i<length zs. snd (zs!i) = tl (snd (ys!i))\"\n    by (simp add: a2)    \n  {\n    have \"same_length (\\<Gamma>,xs) zs\" using a1 a2 unfolding conjoin_def \n     by (simp add: same_length_def)\n  } moreover note same_len = this\n  {    \n    {\n       fix j\n       assume a11:\"j<length (snd (\\<Gamma>, xs))\"                                                               \n       then have fst_suc:\"fst (snd (\\<Gamma>, xs) ! j) = fst(snd (\\<Gamma>,x#xs)! Suc j)\"\n         by auto       \n       then have \"fst (snd (\\<Gamma>, xs) ! j) = map (\\<lambda>x. fst (snd x ! j)) zs\" \n       proof -\n         have s_l_y_z:\"length ys = length zs\" using a2 by fastforce\n         have Suc_j_l_ys:\"\\<forall>i < length ys. Suc j < length (snd (ys!i))\" \n           using a11 s_l unfolding same_length_def by fastforce\n         have tail: \"\\<forall>i < length ys. snd (zs!i) = tl (snd (ys!i))\" using a2 \n           by fastforce                  \n         then have l_xs_zs_eq:\"length (fst (snd (\\<Gamma>, xs) ! j)) = length zs\"\n            using fst_suc s_l_y_z s_p a11 unfolding same_program_def by auto         \n         then have \"\\<forall>i<length ys. \n           fst (snd (\\<Gamma>, x#xs) ! Suc j)!i = fst (snd (ys!i) ! (Suc j))\"\n             using s_p a11 unfolding same_program_def by fastforce\n         then have \"\\<forall>i<length zs. \n           fst (snd (\\<Gamma>, x#xs) ! Suc j)!i = fst (snd (zs!i) ! (j))\"\n           using Suc_j_l_ys tail s_l_y_z tl_zero_pair by metis\n        then have \"\\<forall>i<length zs. \n           fst (snd (\\<Gamma>, xs) ! j)!i = map (\\<lambda>x. fst (snd x !  j)) zs!i\"\n          using fst_suc by auto\n        also have \"length (fst (snd (\\<Gamma>, xs) ! j)) = \n                   length (map (\\<lambda>x. fst (snd x !  j)) zs) \" \n          using l_xs_zs_eq by auto\n        ultimately show ?thesis using  l_xs_zs_eq list_eq by metis\n       qed                 \n    }\n    then have \"same_program  (\\<Gamma>,xs) zs\"\n    unfolding conjoin_def  same_program_def same_length_def     \n    by blast    \n  }moreover note same_prog = this\n  {\n    have \"same_state  (\\<Gamma>,xs) zs\" \n    using a1 a2 unfolding conjoin_def same_length_def same_state_def\n    apply auto\n    by (metis (no_types, hide_lams) List.nth_tl Suc_less_eq diff_Suc_1 length_tl nth_Cons_Suc)    \n  }moreover note same_sta = this\n  {\n    have \"same_functions  (\\<Gamma>,xs) zs\" \n     using a1 a2 unfolding conjoin_def\n     apply auto\n     apply (simp add: same_functions_def)          \n     done\n  }moreover note same_fun = this\n  { {\n      fix j\n      assume a11:\"Suc j<length (snd (\\<Gamma>, xs))\"\n      have s_l_y_z:\"length ys = length zs\" using a2 by fastforce\n      have Suc_j_l_ys:\"\\<forall>i < length ys. Suc (Suc j) < length (snd (ys!i))\" \n        using a11 s_l unfolding same_length_def by fastforce\n      have tail: \"\\<forall>i < length ys. snd (zs!i) = tl (snd (ys!i))\" using a2 \n        by fastforce    \n      have same_env: \"\\<forall>i < length ys. (fst (ys!i)) = \\<Gamma>\"\n        using a1 unfolding conjoin_def same_functions_def by auto\n      have fst: \"\\<forall>x. fst(\\<Gamma>, x) = \\<Gamma>\" by auto\n      then have fun_ys_eq_fun_zs: \"\\<forall>i < length ys. (fst (ys!i)) = (fst (zs!i))\"\n        using same_env s_l_y_z\n        proof -\n          have \"\\<forall>n. \\<not> n < length ys \\<or> fst (zs ! n) = fst (ys ! n)\"\n            by (simp add: a2)\n          thus ?thesis\n            by presburger\n        qed\n      have suc_j:\"Suc (Suc j) < length (snd (\\<Gamma>, x#xs))\" using a11 by auto      \n     then have or_compat:\"( (\\<Gamma> \\<turnstile>\\<^sub>p((snd  (\\<Gamma>, x#xs))!(Suc j))  \\<rightarrow> ((snd  (\\<Gamma>, x#xs))!(Suc (Suc j)))) \\<and> \n            (\\<exists>i<length ys. \n               ((fst (ys!i))\\<turnstile>\\<^sub>c ((snd (ys!i))!(Suc j))  \\<rightarrow> ((snd (ys!i))!(Suc (Suc j)))) \\<and> \n            (\\<forall>l<length ys. \n               l\\<noteq>i \\<longrightarrow> (fst (ys!l))\\<turnstile>\\<^sub>c (snd (ys!l))!(Suc j)  \\<rightarrow>\\<^sub>e ((snd (ys!l))!(Suc (Suc j)))  ))) \\<or> \n            (\\<Gamma>\\<turnstile>\\<^sub>p((snd  (\\<Gamma>, x#xs))!(Suc j))  \\<rightarrow>\\<^sub>e ((snd  (\\<Gamma>, x#xs))!(Suc (Suc j))) \\<and> \n            (\\<forall>i<length ys. (fst (ys!i))\\<turnstile>\\<^sub>c (snd (ys!i))!(Suc j)  \\<rightarrow>\\<^sub>e ((snd (ys!i))!(Suc (Suc j)))))\"\n        using suc_j a1 same_env unfolding conjoin_def compat_label_def fst by auto\n       then have \n         \"( (fst (\\<Gamma>, xs) \\<turnstile>\\<^sub>p((snd  (\\<Gamma>, xs))!(j))  \\<rightarrow> ((snd  (\\<Gamma>,xs))!((Suc j)))) \\<and> \n              (\\<exists>i<length zs. \n                 ((fst (zs!i))\\<turnstile>\\<^sub>c ((snd (zs!i))!( j))  \\<rightarrow> ((snd (zs!i))!( (Suc j)))) \\<and> \n              (\\<forall>l<length zs. \n                 l\\<noteq>i \\<longrightarrow> (fst (zs!l))\\<turnstile>\\<^sub>c (snd (zs!l))!( j)  \\<rightarrow>\\<^sub>e (( snd (zs!l))!( (Suc j)))  )))\\<or>\n               ((fst (\\<Gamma>, xs)\\<turnstile>\\<^sub>p((snd  (\\<Gamma>, xs))!(j))  \\<rightarrow>\\<^sub>e ((snd  (\\<Gamma>, xs))!((Suc j))) \\<and> \n           (\\<forall>i<length zs. (fst (zs!i))\\<turnstile>\\<^sub>c (snd (zs!i))!(j)  \\<rightarrow>\\<^sub>e ((snd (zs!i))!((Suc j)))   )))\"\n       proof \n         assume a21:\"( (\\<Gamma> \\<turnstile>\\<^sub>p((snd  (\\<Gamma>, x#xs))!(Suc j))  \\<rightarrow> ((snd  (\\<Gamma>, x#xs))!(Suc (Suc j)))) \\<and> \n              (\\<exists>i<length ys. \n                 ((fst (ys!i))\\<turnstile>\\<^sub>c ((snd (ys!i))!(Suc j))  \\<rightarrow> ((snd (ys!i))!(Suc (Suc j)))) \\<and> \n              (\\<forall>l<length ys. \n                 l\\<noteq>i \\<longrightarrow> (fst (ys!l))\\<turnstile>\\<^sub>c (snd (ys!l))!(Suc j)  \\<rightarrow>\\<^sub>e ((snd (ys!l))!(Suc (Suc j)))  )))\" \n          then obtain i where \n              f1:\"( (\\<Gamma> \\<turnstile>\\<^sub>p((snd  (\\<Gamma>, x#xs))!(Suc j))  \\<rightarrow> ((snd  (\\<Gamma>, x#xs))!(Suc (Suc j)))) \\<and> \n              (i<length ys \\<and> \n                 ((fst (ys!i))\\<turnstile>\\<^sub>c ((snd (ys!i))!(Suc j))  \\<rightarrow> ((snd (ys!i))!(Suc (Suc j)))) \\<and> \n              (\\<forall>l<length ys. \n                 l\\<noteq>i \\<longrightarrow> (fst (ys!l))\\<turnstile>\\<^sub>c (snd (ys!l))!(Suc j)  \\<rightarrow>\\<^sub>e ((snd (ys!l))!(Suc (Suc j)))  )))\"       \n           by auto \n          then have \"( (\\<Gamma> \\<turnstile>\\<^sub>p((snd  (\\<Gamma>, x#xs))!(Suc j))  \\<rightarrow> ((snd  (\\<Gamma>, x#xs))!(Suc (Suc j)))) \\<and> \n              (\\<exists>i<length ys. \n                 ((fst (ys!i))\\<turnstile>\\<^sub>c ((snd (zs!i))!( j))  \\<rightarrow> ((snd (zs!i))!( (Suc j)))) \\<and> \n              (\\<forall>l<length ys. \n                 l\\<noteq>i \\<longrightarrow> (fst (ys!l))\\<turnstile>\\<^sub>c (snd (zs!l))!( j)  \\<rightarrow>\\<^sub>e (( snd (zs!l))!( (Suc j)))  )))\"\n            proof -\n                have f1: \"\\<Gamma>\\<turnstile>\\<^sub>p snd (\\<Gamma>, x # xs) ! Suc j \\<rightarrow> snd (\\<Gamma>, x # xs) ! Suc (Suc j) \\<and> i < length ys \\<and> fst (ys ! i)\\<turnstile>\\<^sub>c snd (ys ! i) ! Suc j \\<rightarrow> snd (ys ! i) ! Suc (Suc j) \\<and> (\\<forall>n. (\\<not> n < length ys \\<or> n = i) \\<or> fst (ys ! n)\\<turnstile>\\<^sub>c snd (ys ! n) ! Suc j \\<rightarrow>\\<^sub>e snd (ys ! n) ! Suc (Suc j))\"\n                  using f1 by blast\n                have f2: \"j < length (snd (\\<Gamma>, xs))\"\n                  by (meson Suc_lessD a11)\n                have f3: \"\\<forall>n. \\<not> n < length zs \\<or> length (snd (zs ! n)) = length (snd (\\<Gamma>, xs))\"\n                  using same_len same_length_def by blast\n                have \"\\<forall>n. \\<not> n < length ys \\<or> snd (zs ! n) = tl (snd (ys ! n))\"\n                  using tail by blast\n                thus ?thesis\n                  using f3 f2 f1 by (metis (no_types) List.nth_tl a11 s_l_y_z)\n              qed           \n             then have\"( (\\<Gamma> \\<turnstile>\\<^sub>p((snd  (\\<Gamma>, xs))!(j))  \\<rightarrow> ((snd  (\\<Gamma>,xs))!((Suc j)))) \\<and> \n              (\\<exists>i<length zs. \n                 ((fst (zs!i))\\<turnstile>\\<^sub>c ((snd (zs!i))!( j))  \\<rightarrow> ((snd (zs!i))!( (Suc j)))) \\<and> \n              (\\<forall>l<length zs. \n                 l\\<noteq>i \\<longrightarrow> (fst (zs!l))\\<turnstile>\\<^sub>c (snd (zs!l))!( j)  \\<rightarrow>\\<^sub>e (( snd (zs!l))!( (Suc j)))  )))\"\n              using same_env s_l_y_z fun_ys_eq_fun_zs by force\n             then have\"( (fst (\\<Gamma>, xs) \\<turnstile>\\<^sub>p((snd  (\\<Gamma>, xs))!(j))  \\<rightarrow> ((snd  (\\<Gamma>,xs))!((Suc j)))) \\<and> \n              (\\<exists>i<length zs. \n                 ((fst (zs!i))\\<turnstile>\\<^sub>c ((snd (zs!i))!( j))  \\<rightarrow> ((snd (zs!i))!( (Suc j)))) \\<and> \n              (\\<forall>l<length zs. \n                 l\\<noteq>i \\<longrightarrow> (fst (zs!l))\\<turnstile>\\<^sub>c (snd (zs!l))!( j)  \\<rightarrow>\\<^sub>e (( snd (zs!l))!( (Suc j)))  )))\"\n             by auto\n             thus ?thesis\n             by auto\n      next    \n        assume a22:\n            \"(\\<Gamma>\\<turnstile>\\<^sub>p((snd  (\\<Gamma>, x#xs))!(Suc j))  \\<rightarrow>\\<^sub>e ((snd  (\\<Gamma>, x#xs))!(Suc (Suc j))) \\<and> \n            (\\<forall>i<length ys. (fst (ys!i))\\<turnstile>\\<^sub>c (snd (ys!i))!(Suc j)  \\<rightarrow>\\<^sub>e ((snd (ys!i))!(Suc (Suc j)))   ))\"\n        then have \n          \"(\\<Gamma>\\<turnstile>\\<^sub>p((snd  (\\<Gamma>, x#xs))!(Suc j))  \\<rightarrow>\\<^sub>e ((snd  (\\<Gamma>, x#xs))!(Suc (Suc j))) \\<and> \n           (\\<forall>i<length ys. (fst (ys!i))\\<turnstile>\\<^sub>c (snd (zs!i))!(j)  \\<rightarrow>\\<^sub>e ((snd (zs!i))!((Suc j)))   ))\"\n        using Suc_j_l_ys tail s_l_y_z tl_zero_pair21 by metis\n        then have\n          \"(\\<Gamma>\\<turnstile>\\<^sub>p((snd  (\\<Gamma>, xs))!(j))  \\<rightarrow>\\<^sub>e ((snd  (\\<Gamma>, xs))!((Suc j))) \\<and> \n           (\\<forall>i<length zs. (fst (zs!i))\\<turnstile>\\<^sub>c (snd (zs!i))!(j)  \\<rightarrow>\\<^sub>e ((snd (zs!i))!((Suc j)))   ))\"\n          using same_env s_l_y_z fun_ys_eq_fun_zs by fastforce\n        thus ?thesis by auto \n      qed\n    }\n    then have \"compat_label  (\\<Gamma>,xs) zs\"\n    using compat_label_def by blast \n  } note same_label = this\n  ultimately show ?thesis using conjoin_def by auto\nqed\n\n\n\nlemma clist_tail: \n  assumes \n    a1:\"length xs = length clist\" and\n    a2: \"ys = (map (\\<lambda>i. (\\<Gamma>,(fst i,s)#snd i)) (zip xs clist))\"\n shows \"\\<forall>i < length ys. tl (snd (ys!i)) = clist!i \"\nusing a1 a2\nproof -   \n   show ?thesis using a2\n   by (simp add: a1)           \nqed   \n\n\nlemma clist_map: \n   assumes \n    a1:\"length xs = length clist\" \n   shows \"clist = map ((\\<lambda>p. tl (snd p)) \\<circ> (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))) (zip xs clist)\"\nproof -\n  have f1: \"map snd (zip xs clist) = clist\"\n    using a1 map_snd_zip by blast\n  have \"map snd (zip xs clist) = map ((\\<lambda>p. tl (snd p)) \\<circ> (\\<lambda>p. (\\<Gamma>, (fst p, s) # snd p))) (zip xs clist)\"\n    by simp\n  thus ?thesis\n    using f1 by presburger\nqed\n\n\nlemma clist_map1: \n   assumes \n    a1:\"length xs = length clist\"     \n   shows \"clist = map (\\<lambda>p. tl (snd p)) (map (\\<lambda>i. (\\<Gamma>,(fst i,s)#snd i)) (zip xs clist))\"\nproof -\n   have \"clist = map ((\\<lambda>p. tl (snd p)) \\<circ> (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))) (zip xs clist)\" \n   using a1  clist_map by fastforce\n   thus ?thesis by auto\nqed\n\nlemma clist_map2:\n     \"(clist = map (\\<lambda>p. tl (snd p)) (l::('a \\<times>'b list) list) ) \\<Longrightarrow>\n       clist = map (\\<lambda>p. (snd p)) (map (\\<lambda>p. (fst p, tl (snd p))) (l::('a \\<times>'b list) list)) \"\nby auto\n\nlemma map_snd:\n   assumes a1: \"y = map  (\\<lambda>x. f x) l\"\n   shows   \"y=(map snd (map (\\<lambda>x. (g x, f x)) l)) \"\nby (simp add: assms)\n \nlemmas map_snd_sym = map_snd[THEN sym]\n\nlemma map_snd':\n   shows   \" map  (\\<lambda>x. f x) l=(map snd (map (\\<lambda>x. (g x, f x)) l)) \"\nby simp\n\nlemma clist_snd:\n assumes a1: \"(\\<Gamma>, a # ys) \\<propto> map (\\<lambda>x. (fst x, tl (snd x)))\n                    (map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i)) (zip xs clist))\" and\n         a2: \"length clist > 0 \\<and> length clist = length xs\"\n shows \"clist = (map snd\n          (map (\\<lambda>x. (\\<Gamma>, (fst x, snd (clist ! 0 ! 0)) # snd x))\n            (zip (map (\\<lambda>x. fst (hd x)) clist) (map tl clist))))\"\nproof -\n     let ?concat_zip = \"(\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\"  \n     let ?clist_ext = \"map ?concat_zip (zip xs clist)\"\n     let ?exec_run = \"(xs, s) # a # ys\"\n     let ?exec = \"(\\<Gamma>,?exec_run)\"\n     let ?exec_ext = \"map (\\<lambda>x. (fst x, tl (snd x))) ?clist_ext\"\n     let ?zip = \"(zip (map (\\<lambda>x. fst (hd x)) clist) \n                         (map (\\<lambda>x. tl x) clist))\"\n  have \\<Gamma>_all: \"\\<forall>i < length ?clist_ext. fst (?clist_ext !i) = \\<Gamma>\"\n       by auto       \n  have len:\"length xs = length clist\" using a2 by auto\n  then have len_clist_exec:\n   \"length clist = length ?exec_ext\" \n   by fastforce    \n  then have len_clist_exec_map:\n    \"length ?exec_ext = \n              length (map (\\<lambda>x. (\\<Gamma>, (fst x,snd ((clist!0)!0))#snd x)) \n                          ?zip)\" \n   by fastforce               \n  then have clist_snd:\"clist = map (\\<lambda>x. snd x) ?exec_ext\"\n    using clist_map1 [of xs clist \\<Gamma> s] clist_map2 len by blast   \n  then have clist_len_eq_ays: \n      \"\\<forall>i < length clist. length( (clist!i))=length (snd (\\<Gamma>,a#ys))\"      \n    using len  same_length_non_pair a1 conjoin_def\n    by blast\n  then have clist_gz:\"\\<forall>i < length clist. length (clist!i) > 0\" \n    by fastforce\n  have clist_len_eq: \n     \"\\<forall>i < length clist. \\<forall>j < length clist. \n        length (clist ! i) = length (clist ! j)\" \n    using clist_len_eq_ays by auto          \n  have clist_same_state: \n    \"\\<forall>i < length clist. \\<forall>j< length clist. \\<forall>k<length  (clist!i).\n       snd ((clist!i)!k) = snd ((clist!j)!k)\"\n  proof -\n    have \n      \"(\\<forall>i <length clist. \\<forall>j<length (snd (\\<Gamma>, a # ys)). snd((snd (\\<Gamma>, a # ys))!j) = snd( (clist!i)!j))\"\n      using len clist_snd conjoin_def a1 conjoin_def same_state_non_pair \n    by blast\n    thus ?thesis using clist_len_eq_ays by (metis (no_types))\n  qed      \n  then have clist_map:\n    \"clist = map (\\<lambda>i. (fst i,snd ((clist!0)!0))#snd i) ?zip\"\n    using list_as_map a2 clist_gz clist_len_eq by blast      \n  moreover have \"map (\\<lambda>i. (fst i,snd ((clist!0)!0))#snd i) ?zip =\n             map snd (map (\\<lambda>x. (\\<Gamma>, (fst x, snd (clist ! 0 ! 0)) # snd x))\n       (zip (map (\\<lambda>x. fst (hd x)) clist) (map tl clist)))\"\n  using map_snd' by auto\n  ultimately show ?thesis by auto   \nqed\n\nlemma list_as_zip:\n assumes a1: \"(\\<Gamma>, a # ys) \\<propto> map (\\<lambda>x. (fst x, tl (snd x)))\n                    (map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i)) (zip xs clist))\" and\n         a2: \"length clist > 0 \\<and> length clist = length xs\"\n shows \"  map (\\<lambda>x. (fst x, tl (snd x)))\n                    (map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i)) (zip xs clist)) =\n          map (\\<lambda>x. (\\<Gamma>, (fst x,snd ((clist!0)!0))#snd x)) \n                       (zip (map (\\<lambda>x. fst (hd x)) clist) \n                         (map (\\<lambda>x. tl x) clist))\"\nproof -\n     let ?concat_zip = \"(\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\"  \n     let ?clist_ext = \"map ?concat_zip (zip xs clist)\"\n     let ?exec_run = \"(xs, s) # a # ys\"\n     let ?exec = \"(\\<Gamma>,?exec_run)\"\n     let ?exec_ext = \"map (\\<lambda>x. (fst x, tl (snd x))) ?clist_ext\"\n     let ?zip = \"(zip (map (\\<lambda>x. fst (hd x)) clist) \n                         (map (\\<lambda>x. tl x) clist))\"\n  have \\<Gamma>_all: \"\\<forall>i < length ?clist_ext. fst (?clist_ext !i) = \\<Gamma>\"\n       by auto       \n  have len:\"length xs = length clist\" using a2 by auto\n  then have len_clist_exec:\n   \"length clist = length ?exec_ext\" \n   by fastforce    \n  then have len_clist_exec_map:\n    \"length ?exec_ext = \n              length (map (\\<lambda>x. (\\<Gamma>, (fst x,snd ((clist!0)!0))#snd x)) \n                          ?zip)\" \n   by fastforce               \n  then have clist_snd:\"clist = map (\\<lambda>x. snd x) ?exec_ext\"\n    using clist_map1 [of xs clist \\<Gamma> s] clist_map2 len by blast   \n  then have clist_len_eq_ays: \n      \"\\<forall>i < length clist. length( (clist!i))=length (snd (\\<Gamma>,a#ys))\"      \n    using len  same_length_non_pair a1 conjoin_def\n    by blast\n  then have clist_gz:\"\\<forall>i < length clist. length (clist!i) > 0\" \n    by fastforce\n  have clist_len_eq: \n     \"\\<forall>i < length clist. \\<forall>j < length clist. \n        length (clist ! i) = length (clist ! j)\" \n    using clist_len_eq_ays by auto          \n  have clist_same_state: \n    \"\\<forall>i < length clist. \\<forall>j< length clist. \\<forall>k<length  (clist!i).\n       snd ((clist!i)!k) = snd ((clist!j)!k)\"\n  proof -\n    have \n      \"(\\<forall>i <length clist. \\<forall>j<length (snd (\\<Gamma>, a # ys)). snd((snd (\\<Gamma>, a # ys))!j) = snd( (clist!i)!j))\"\n      using len clist_snd conjoin_def a1 conjoin_def same_state_non_pair \n    by blast\n    thus ?thesis using clist_len_eq_ays by (metis (no_types))\n  qed      \n  then have clist_map:\n    \"clist = map (\\<lambda>i. (fst i,snd ((clist!0)!0))#snd i) ?zip\"\n    using list_as_map a2 clist_gz clist_len_eq by blast      \n  then have \"\\<forall>i < length clist. \n                clist ! i = (fst (?zip!i),snd ((clist!0)!0)) # snd (?zip!i)\"\n  using len nth_map length_map by (metis (no_types, lifting))\n  then have \n    \"\\<forall>i < length clist. \n     ?exec_ext ! i = (\\<Gamma>, (fst (?zip!i),snd ((clist!0)!0)) # snd (?zip!i))\" \n  using \\<Gamma>_all len  by fastforce           \n  moreover have \"\\<forall>i < length clist. \n    (\\<Gamma>, (fst (?zip!i),snd ((clist!0)!0)) # snd (?zip!i)) = \n    (map (\\<lambda>x. (\\<Gamma>, (fst x,snd ((clist!0)!0))#snd x)) \n                          ?zip)!i\" \n  by auto        \n  ultimately have \n     \"\\<forall>i < length clist. \n       ?exec_ext ! i =(map (\\<lambda>x. (\\<Gamma>, (fst x,snd ((clist!0)!0))#snd x)) \n                          ?zip)!i\" \n  by auto\n  then also have \"length clist = length ?exec_ext\" \n  using len by fastforce \n  ultimately have exec_ext_eq_clist_map:\n     \"\\<forall>i < length ?exec_ext. \n       ?exec_ext ! i =(map (\\<lambda>x. (\\<Gamma>, (fst x,snd ((clist!0)!0))#snd x)) \n                          ?zip)!i\" \n  by presburger\n  then moreover have \"length ?exec_ext = \n              length (map (\\<lambda>x. (\\<Gamma>, (fst x,snd ((clist!0)!0))#snd x)) \n                          ?zip)\" \n  using len clist_map by fastforce    \n  ultimately show ?thesis\n     using list_eq by blast  \nqed\n\nlemma hd_nth:\n   assumes a1:\"i< length l \\<and> ( length( (l!i)) > 0)\"\n   shows \"f (hd (l!i)) = f (nth (l!i) 0)\"\nusing assms hd_conv_nth by fastforce\n\nlemma map_hd_nth:\n   assumes a1:\"(\\<forall>i <length l. length( (l!i)) > 0)\"\n   shows \"map (\\<lambda>x. f (hd x)) l = map (\\<lambda>x. f (nth (x) 0)) l\"\nproof -  \n   have \"\\<forall>i < length l. (map (\\<lambda>x. f (hd x)) l)!i = f (nth (l!i) 0)\"\n    using hd_nth a1 by auto\n  moreover have \"\\<forall>i < length l. (map (\\<lambda>x. f (nth x 0)) l)!i = f (nth (l!i) 0)\"\n    using hd_nth a1 by auto\n  ultimately have f1:\"\\<forall>i < length l. (map (\\<lambda>x. f (hd x)) l)!i =(map (\\<lambda>x. f (nth x 0)) l)!i \"\n    by auto\n  moreover have f2:\"length (map (\\<lambda>x. f (hd x)) l) = length l\"\n    by auto   \n  moreover have \"length (map (\\<lambda>x. f (nth x 0)) l) = length l\" by auto\n  ultimately show ?thesis using nth_equalityI by metis\nqed\n\nlemma \"i<length clist \\<Longrightarrow> clist!i = (x1,ys) \\<Longrightarrow> ys = (map (\\<lambda>x. (fst (hd (snd x)),s)#tl (snd x)) clist)!i \\<Longrightarrow>\n         ys = (map (\\<lambda>x. (fst x, s)#snd x) \n               (zip (map (\\<lambda>x. fst (hd (snd x))) clist) \n                    (map (\\<lambda>x. tl (snd x)) clist)))!i\"\nproof (induct ys)\n  case Nil thus ?case by auto\nnext\n  case (Cons y ys) \n  have \"\\<forall>n ps f. \\<not> n < length ps \\<or> map f ps ! n = (f (ps ! n::'a \\<times> ('b \\<times> 'c) list)::('b \\<times> 'c) list)\"\n    by force\n  hence \"y # ys = (fst (hd (snd (clist ! i))), s) # tl (snd (clist ! i))\"\n    using Cons.prems(1) Cons.prems(3) by presburger\n  thus ?case\n    using Cons.prems(1) by auto\nqed\n\n  \n\nlemma clist_map_zip:\"xs\\<noteq>[] \\<Longrightarrow> (\\<Gamma>,(xs,s)#ys) \\<propto> clist \\<Longrightarrow> \n      clist = map (\\<lambda>i. (\\<Gamma>,(fst i,s)#(snd i))) (zip xs ((map (\\<lambda>x. tl (snd x))) clist))\"\nproof -\n  let ?clist = \"map snd clist\"\n  assume a1: \"xs\\<noteq>[]\"\n  assume a2:  \"(\\<Gamma>,(xs,s)#ys) \\<propto> clist\"\n  then have all_in_clist_not_empty:\"\\<forall>i < length ?clist. (?clist!i) \\<noteq> []\"\n   unfolding conjoin_def same_length_def by auto\n  then have hd_clist:\"\\<forall>i < length ?clist. hd (?clist!i) = (?clist!i)!0\" \n     by (simp add: hd_conv_nth)  \n  then have all_xs:\"\\<forall>i< length ?clist. fst (hd (?clist!i)) = xs!i\"\n   using  a2 unfolding conjoin_def same_program_def by auto\n  \n  then have  all_s: \"\\<forall>i < length ?clist. snd (hd (?clist!i)) = s\"\n    using a2 hd_clist unfolding conjoin_def same_state_def by fastforce\n  have fst_clist_\\<Gamma>:\"\\<forall>i < length clist. fst (clist!i) = \\<Gamma>\"\n    using a2 unfolding conjoin_def same_functions_def by auto \n   have p2:\"length xs = length clist\" using conjoin_same_length a2\n   by fastforce\n  \n  \n  then have \"\\<forall>i< length (map (\\<lambda>x. fst (hd x)) ?clist). \n               (map (\\<lambda>x. fst (hd x)) ?clist)!i = xs!i\"\n    using all_xs by auto\n  also have \"length (map (\\<lambda>x. fst (hd x)) ?clist) = length xs\" using p2 by auto\n  ultimately have \"(map (\\<lambda>x. fst (hd x)) ?clist) = xs\"\n   using nth_equalityI by metis\n  then have xs_clist:\"map (\\<lambda>x. fst (hd (snd x))) clist = xs\" by auto\n       \n  have clist_hd_tl:\"\\<forall>i < length ?clist. ?clist!i = hd (?clist!i) # (tl (?clist!i))\"\n   using all_in_clist_not_empty list.exhaust_sel by blast   \n  then have \"\\<forall>i < length ?clist. ?clist!i =(fst  (hd (?clist!i)),snd  (hd (?clist!i)))# (tl (?clist!i))\"\n    by auto\n  then have \"?clist = map (\\<lambda>x. (fst (hd x),snd (hd x))#tl x) ?clist\" \n   using length_map list_eq_iff_nth_eq list_update_id map_update nth_list_update_eq\n   by (metis (no_types, lifting) length_map list_eq_iff_nth_eq list_update_id map_update nth_list_update_eq)\n  then have \"?clist = map (\\<lambda>x. (fst (hd x),s)#tl x) ?clist\"\n   using all_s length_map nth_equalityI nth_map\n    by (metis (no_types, lifting) ) \n  then have map_clist:\"map (\\<lambda>x. (fst (hd (snd x)),s)#tl (snd x)) clist = ?clist\" \n   by auto   \n  then have \"(map (\\<lambda>x. (fst x, s)#snd x) \n               (zip (map (\\<lambda>x. fst (hd (snd x))) clist) \n                    (map (\\<lambda>x. tl (snd x)) clist))) =  ?clist\"     \n    using map_clist  by (auto intro: nth_equalityI) \n  then have \"\\<forall>i<length clist. clist!i =  (\\<Gamma>,(map (\\<lambda>x. (fst x, s)#snd x) \n               (zip xs \n                   (map (\\<lambda>x. tl (snd x)) clist)))!i)\" \n   using  xs_clist fst_clist_\\<Gamma>  by auto   \n  also have \"length clist = length (map (\\<lambda>i. (\\<Gamma>,(fst i,s)#(snd i))) (zip xs ((map (\\<lambda>x. tl (snd x))) clist)))\" \n    using p2 by auto\n  ultimately show \"clist = map (\\<lambda>i. (\\<Gamma>,(fst i,s)#(snd i))) (zip xs ((map (\\<lambda>x. tl (snd x))) clist))\" \n    using length_map length_zip nth_equalityI nth_map \n    by (metis (no_types, lifting)) \nqed\n            \nlemma aux_if' : \n  assumes a:\"length clist > 0 \\<and> length clist = length xs \\<and> \n             (\\<forall>i<length xs. (\\<Gamma>,(xs!i,s)#clist!i) \\<in> cptn) \\<and> \n             ((\\<Gamma>,(xs, s)#ys) \\<propto> map (\\<lambda>i. (\\<Gamma>,(fst i,s)#snd i)) (zip xs clist))\"\n  shows \"(\\<Gamma>,(xs, s)#ys) \\<in> par_cptn\"\nusing a\nproof (induct ys arbitrary: xs s clist) \n  case Nil then show ?case by (simp add: par_cptn.ParCptnOne)\nnext\n  case (Cons a ys xs s clist)     \n     let ?concat_zip = \"(\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\"  \n     let ?com_clist_xs = \"map ?concat_zip (zip xs clist)\"\n     let ?xs_a_ys_run = \"(xs, s) # a # ys\"\n     let ?xs_a_ys_run_exec = \"(\\<Gamma>,?xs_a_ys_run)\"\n     let ?com_clist' = \"map (\\<lambda>x. (fst x, tl (snd x))) ?com_clist_xs\"\n     let ?xs' = \"(map (\\<lambda>x. fst (hd x)) clist)\"     \n     let ?clist' = \"(map (\\<lambda>x. tl x) clist)\"\n     let ?zip_xs'_clist' = \"zip ?xs' \n                            ?clist'\"         \n     obtain as sa where a_pair:\"a=(as,sa)\" by fastforce\n       let ?comp_clist'_alt = \"map (\\<lambda>x. (\\<Gamma>, (fst x,snd ((clist!0)!0))#snd x)) ?zip_xs'_clist' \"\n       let ?clist'_alt = \"map (\\<lambda>x. snd x) ?comp_clist'_alt\"\n       let ?comp_a_ys = \"(\\<Gamma>, (as,sa) # ys)\"   \n     have conjoin_hyp1:\n       \"(\\<Gamma>, (as,sa) # ys) \\<propto> ?com_clist'\"\n       using conjoin_tl using a_pair Cons by blast     \n     then have conjoin_hyp:\n       \"(\\<Gamma>, (as,sa) # ys) \\<propto> map (\\<lambda>x. (\\<Gamma>, (fst x,snd ((clist!0)!0))#snd x)) ?zip_xs'_clist'\"\n     using list_as_zip Cons.prems by fastforce    \n     have len:\"length xs = length clist\" using Cons by auto \n     have clist_snd_map:\n        \"(map snd\n          (map (\\<lambda>x. (\\<Gamma>, (fst x, snd (clist ! 0 ! 0)) # snd x))\n         (zip (map (\\<lambda>x. fst (hd x)) clist) (map tl clist)))) = clist\"\n       using clist_snd Cons.prems conjoin_hyp1 by fastforce\n     have eq_len_clist_clist':\n       \"length ?clist' > 0\" using Cons.prems by auto  \n     have \"(\\<forall>i <length clist. \\<forall>j<length (snd ?comp_a_ys). snd((snd ?comp_a_ys)!j) = snd( (clist!i)!j))\"\n        using clist_snd_map conjoin_hyp conjoin_def same_state_non_pair[of ?comp_a_ys ?comp_clist'_alt ?clist'_alt]\n         by fastforce   \n     then have \"\\<forall>i<length clist.\n                  sa = snd ( (clist ! i)!0)\" by fastforce\n     also have clist_i_grz:\"(\\<forall>i <length clist. length( (clist!i)) > 0)\"\n         using clist_snd_map conjoin_hyp conjoin_def same_length_non_pair[of ?comp_a_ys ?comp_clist'_alt ?clist'_alt]\n     by fastforce  \n     ultimately have all_i_sa_hd_clist:\"\\<forall>i<length clist.\n                  sa = snd (hd (clist ! i))\"\n     by (simp add: hd_conv_nth)      \n     have as_sa_eq_xs'_s':\"as = ?xs' \\<and>  sa = snd ((clist!0)!0)\" \n     proof -              \n       have \"(\\<forall>j<length (snd ?comp_a_ys). fst((snd ?comp_a_ys)!j) = \n                map (\\<lambda>x. fst(nth x j)) ?clist'_alt)\"       \n       using conjoin_hyp conjoin_def same_program_non_pair[of ?comp_a_ys ?comp_clist'_alt ?clist'_alt]\n       by fast\n       then have are_eq:\"fst((snd ?comp_a_ys)!0) = \n                map (\\<lambda>x. fst(nth x 0)) ?clist'_alt\" by fastforce\n       have fst_exec_is_as:\"fst((snd ?comp_a_ys)!0) =as\" by auto              \n       then have \"map (\\<lambda>x. fst(hd x)) clist=map (\\<lambda>x. fst(x!0)) clist\"\n         using map_hd_nth clist_i_grz by auto \n       then have \"map (\\<lambda>x. fst(nth x 0)) ?clist'_alt =?xs'\" using clist_snd_map map_hd_nth\n        by fastforce\n       moreover have \"(\\<forall>i <length clist. \\<forall>j<length (snd ?comp_a_ys). snd((snd ?comp_a_ys)!j) = snd( (clist!i)!j))\"\n        using clist_snd_map conjoin_hyp conjoin_def same_state_non_pair[of ?comp_a_ys ?comp_clist'_alt ?clist'_alt]\n         by fastforce\n       ultimately show ?thesis using are_eq fst_exec_is_as\n          using Cons.prems by force \n    qed\n    then have conjoin_hyp:\n       \"(\\<Gamma>, (as,sa) # ys) \\<propto> map (\\<lambda>x. (\\<Gamma>, (fst x,sa)#snd x))\n                            (zip as (map tl clist))\"\n    using conjoin_hyp by auto\n    then have eq_len_as_clist':\n       \"length as = length ?clist'\" using Cons.prems as_sa_eq_xs'_s' by auto\n    then have len_as_ys_eq:\"length as = length xs\" using Cons.prems by auto\n    have \" (\\<forall>i<length as. (\\<Gamma>, ((as!i),sa)#(map (\\<lambda>x. tl x) clist)!i) \\<in> cptn)\" \n     using Cons.prems cptn_dest clist_snd_map len \n    proof -     \n      have \"\\<forall>i<length clist. clist!i = (hd (clist!i))#(tl (clist!i))\" \n       using clist_i_grz \n      by auto\n      then have \"(\\<forall>i<length clist. (\\<Gamma>, (xs ! i, s) # (hd (clist!i))#(tl (clist!i))) \\<in> cptn)\"\n      using Cons.prems by auto\n      then have f1:\"(\\<forall>i<length clist. (\\<Gamma>, (hd (clist!i))#(tl (clist!i))) \\<in> cptn)\"\n      by (metis list.distinct(2) tl_in_cptn) \n      then have \"(\\<forall>i<length clist. (\\<Gamma>, ((as!i),sa)#(tl (clist!i))) \\<in> cptn)\"\n      using as_sa_eq_xs'_s' all_i_sa_hd_clist by auto      \n      then have \"(\\<forall>i<length clist. (\\<Gamma>, ((as!i),sa)#(map (\\<lambda>x. tl x) clist)!i) \\<in> cptn)\"\n      by auto\n      thus ?thesis using  len clist_i_grz len_as_ys_eq by auto\n   qed\n   then have a_ys_par_cptn:\"(\\<Gamma>, (as, sa) # ys) \\<in> par_cptn\"           \n   using \n    conjoin_hyp eq_len_clist_clist' eq_len_as_clist'[THEN sym] Cons.hyps\n   by blast  \n   have \\<Gamma>_all: \"\\<forall>i < length ?com_clist_xs. fst (?com_clist_xs !i) = \\<Gamma>\"\n   by auto\n   have Gamma: \"\\<Gamma>= (fst ?xs_a_ys_run_exec)\" by fastforce  \n   have exec: \"?xs_a_ys_run = (snd ?xs_a_ys_run_exec)\" by fastforce  \n   have split_par:\n       \"\\<Gamma>\\<turnstile>\\<^sub>p ((xs, s) # a # ys) ! 0 \\<rightarrow> ((a # ys) ! 0) \\<or>\n        \\<Gamma>\\<turnstile>\\<^sub>p ((xs, s) # a # ys) ! 0 \\<rightarrow>\\<^sub>e ((a # ys) ! 0)\"     \n       using compat_label_def compat_label_tran_0\n             Cons.prems Gamma exec \n             compat_label_tran_0[of \"(\\<Gamma>, (xs, s) # a # ys)\" \n                                   \"(map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i)) (zip xs clist))\"]    \n       unfolding conjoin_def by auto      \n     {\n      assume \"\\<Gamma>\\<turnstile>\\<^sub>p ((xs, s) # a # ys) ! 0 \\<rightarrow> ((a # ys) ! 0)\"      \n      then have  \" (\\<Gamma>, (xs, s) # a # ys) \\<in> par_cptn\" \n      using a_ys_par_cptn a_pair par_cptn.ParCptnComp by fastforce\n     } note env_sol=this\n     {\n      assume \" \\<Gamma>\\<turnstile>\\<^sub>p ((xs, s) # a # ys) ! 0 \\<rightarrow>\\<^sub>e ((a # ys) ! 0)\"      \n      then have env_tran:\" \\<Gamma>\\<turnstile>\\<^sub>p (xs, s)  \\<rightarrow>\\<^sub>e (as,sa)\" using a_pair by auto\n      have \"xs = as\"\n       by (meson env_pe_c_c'_false env_tran)\n      then have \" (\\<Gamma>, (xs, s) # a # ys) \\<in> par_cptn\" \n      using a_ys_par_cptn a_pair env_tran ParCptnEnv  by blast\n     }\n     then show \"(\\<Gamma>, (xs, s) # a # ys) \\<in> par_cptn\" using env_sol Cons split_par by fastforce\nqed\n\nlemma mapzip_upd:\" length as = length clist  \\<Longrightarrow>\n       (map (\\<lambda>j. (as ! j, sa) # clist ! j) [0..<length as]) =  \n       map (\\<lambda>j. ((fst j, sa)#snd j)) (zip as clist)\"\nproof -    \n    assume a2: \"length as = length clist\"   \n    have \"\\<forall>i < length  (map (\\<lambda>j. (as ! j, sa) # clist ! j) [0..<length as]). (map (\\<lambda>j. (as ! j, sa) # clist ! j) [0..<length as])!i = map (\\<lambda>j. ((fst j, sa)#snd j)) (zip as clist)!i\"  \n     using a2\n      by auto\n  moreover have \"length (map (\\<lambda>j. (as ! j, sa) # clist ! j) [0..<length as]) =\n         length (map (\\<lambda>j. ((fst j, sa)#snd j)) (zip as clist))\"\n     using a2 by auto   \n  ultimately have \"(map (\\<lambda>j. (as ! j, sa) # clist ! j) [0..<length as]) = map (\\<lambda>j. ((fst j, sa)#snd j)) (zip as clist)\"\n     using nth_equalityI by blast\n  thus \"map (\\<lambda>j. (as ! j, sa) # clist ! j) [0..<length as] = \n        map (\\<lambda>j. (fst j, sa) # snd j) (zip as clist) \"\n      by auto\nqed\n\nlemma aux_if : \n  assumes a:\" length clist = length xs \\<and> \n             (\\<forall>i<length xs. (\\<Gamma>,(xs!i,s)#clist!i) \\<in> cptn) \\<and> \n             ((\\<Gamma>,(xs, s)#ys) \\<propto> map (\\<lambda>i. (\\<Gamma>,(fst i,s)#snd i)) (zip xs clist))\"\n  shows \"(\\<Gamma>,(xs, s)#ys) \\<in> par_cptn\"\nusing a\nproof (cases \"length clist\")\n case 0 \n    then have clist_empty:\"clist = []\" by auto\n    then have map_clist_empty:\"map (\\<lambda>i. (\\<Gamma>,(fst i,s)#snd i)) (zip xs clist) = []\"\n      by fastforce\n    then have conjoin:\"(\\<Gamma>,(xs, s)#ys) \\<propto> []\" using a by auto   \n    then have all_eq:\"\\<forall>j<length (snd (\\<Gamma>,(xs, s)#ys)). fst (snd (\\<Gamma>,(xs, s)#ys) ! j) = []\"\n      using conjoin_def same_program_def\n    by (simp add: conjoin_def same_program_def)\n    from conjoin          \n    show ?thesis using conjoin\n    proof (induct ys arbitrary: s xs) \n       case Nil then show ?case by (simp add: par_cptn.ParCptnOne)\n    next\n       case (Cons a ys)          \n         then have conjoin_ind:\"(\\<Gamma>, (xs, s) # a # ys) \\<propto> []\" by auto\n         then have  \"(\\<Gamma>,(a # ys)) \\<propto> []\" \n           by (auto simp add:conjoin_def same_length_def \n                 same_state_def same_program_def same_functions_def\n                 compat_label_def)\n         moreover obtain as sa where pair_a: \"a=(as,sa)\" using Cons by fastforce\n         ultimately have ays_par_cptn:\"(\\<Gamma>, a # ys) \\<in> par_cptn\" using Cons.hyps by auto\n         have \"\\<forall>j. Suc j<length (snd (\\<Gamma>,(xs, s)#(as,sa)#ys)) \\<longrightarrow> \n                   \\<not>(\\<exists>i<length []. \n                     ((fst ([]!i))\\<turnstile>\\<^sub>c ((snd ([]!i))!j)  \\<rightarrow> ((snd ([]!i))!(Suc j))))\"\n         using conjoin_def compat_label_def by fastforce\n         then have \"(\\<forall>j. Suc j<length (snd (\\<Gamma>,(xs, s)#(as,sa)#ys)) \\<longrightarrow> \n                    ((fst (\\<Gamma>,(xs, s)#(as,sa)#ys))\\<turnstile>\\<^sub>p((snd (\\<Gamma>,(xs, s)#(as,sa)#ys))!j)  \\<rightarrow>\\<^sub>e ((snd (\\<Gamma>,(xs, s)#(as,sa)#ys))!(Suc j))))\"\n         using conjoin_def compat_label_def conjoin_ind pair_a by blast\n         then have env_tran:\"\\<Gamma>\\<turnstile>\\<^sub>p (xs, s)  \\<rightarrow>\\<^sub>e (as,sa)\" by auto               \n         then show \" (\\<Gamma>, (xs, s) # a # ys) \\<in> par_cptn\" \n         using ays_par_cptn pair_a env_tran ParCptnEnv env_pe_c_c'_false by blast\n   qed\nnext\n case Suc\n    then have \"length clist > 0\" by auto\n    then show ?thesis using a aux_if' by blast\nqed\n\nlemma snormal_enviroment:\"s = Normal nsa \\<or> s = sa \\<and> (\\<forall>sa. s \\<noteq> Normal sa) \\<Longrightarrow>\n        \\<Gamma>\\<turnstile>\\<^sub>c (x, s) \\<rightarrow>\\<^sub>e (x, sa)\"\nby (metis Env Env_n)\n\nlemma aux_onlyif [rule_format]: \"\\<forall>xs s. (\\<Gamma>,(xs, s)#ys) \\<in> par_cptn \\<longrightarrow> \n  (\\<exists>clist. (length clist = length xs) \\<and> \n  (\\<Gamma>, (xs, s)#ys) \\<propto> map (\\<lambda>i. (\\<Gamma>, (fst i,s)#(snd i))) (zip xs clist) \\<and> \n  (\\<forall>i<length xs. (\\<Gamma>, (xs!i,s)#(clist!i)) \\<in> cptn))\"\nproof (induct ys) \n  case Nil \n  {fix xs s\n    assume \"(\\<Gamma>, [(xs, s)]) \\<in> par_cptn\"\n    have f1:\"length (map (\\<lambda>i. []) [0..<length xs]) = length xs\" by auto\n    have f2:\"(\\<Gamma>, [(xs, s)]) \\<propto> map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\n                              (zip xs (map (\\<lambda>i. []) [0..<length xs]))\"\n    unfolding conjoin_def same_length_def same_functions_def same_state_def same_program_def compat_label_def            \n      by(simp, rule nth_equalityI,simp,simp)\n    note h = conjI[OF f1 f2]\n    have f3:\"(\\<forall>i<length xs. (\\<Gamma>, (xs ! i, s) # (map (\\<lambda>i. []) [0..<length xs]) ! i) \\<in> cptn)\"\n      by (simp add: cptn.CptnOne)\n    note this = conjI[OF h f3]\n    }\n     thus ?case by blast\nnext\n  case (Cons a ys) \n  {fix  xs s\n   assume a1:\"(\\<Gamma>, (xs, s) # a # ys) \\<in> par_cptn\"\n   then obtain as sa where a_pair: \"a=(as,sa)\" by fastforce\n   then have par_cptn':\"(\\<Gamma>,( (as,sa)#ys)) \\<in> par_cptn\"\n    using a1 par_cptn_dest by blast \n   then obtain clist where hyp: \"\n              length clist = length as \\<and>\n              (\\<Gamma>, (as, sa) #\n                   ys) \\<propto> map (\\<lambda>i. (\\<Gamma>, (fst i, sa) # snd i)) (zip as clist) \\<and>\n              (\\<forall>i<length as. (\\<Gamma>, (as ! i, sa) # clist ! i) \\<in> cptn)\"\n     using Cons.hyps by fastforce\n   have a11:\"(\\<Gamma>, (xs, s) # (as,sa) # ys) \\<in> par_cptn\" using a1 a_pair by auto\n   have par_cptn_dest:\"\\<Gamma>\\<turnstile>\\<^sub>p (xs, s) \\<rightarrow>\\<^sub>e (as, sa) \\<or> \\<Gamma>\\<turnstile>\\<^sub>p (xs, s) \\<rightarrow> (as, sa)\"\n     using par_cptn_elim_cases par_cptn' a1  a_pair by blast \n   {\n     assume a1: \"\\<Gamma>\\<turnstile>\\<^sub>p (xs, s) \\<rightarrow>\\<^sub>e (as, sa)\"          \n     then have xs_as_eq:\"xs=as\" by (meson env_pe_c_c'_false)\n     then have ce:\"\\<forall>i < length xs. \\<Gamma>\\<turnstile>\\<^sub>c (xs!i, s) \\<rightarrow>\\<^sub>e (as!i, sa)\" using a1 pe_ce by fastforce\n     let ?clist=\"(map (\\<lambda>j. (xs!j, sa)#(clist!j)) [0..<length xs])\"    \n     have s1:\"length ?clist = length xs\"\n       by auto\n     have s2:\"(\\<forall>i<length xs. (\\<Gamma>, (xs ! i, s) # ?clist ! i) \\<in> cptn)\"  \n        using a1 hyp CptnEnv xs_as_eq ce by fastforce\n     have s3:\"(\\<Gamma>, (xs, s) #\n                       (as,sa) # ys) \\<propto> map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\n                                   (zip xs ?clist)\"     \n     proof -        \n         have s_len:\"same_length (\\<Gamma>, (xs, s) # (as,sa) # ys) \n                           (map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\n                                   (zip xs ?clist))\"\n               using hyp conjoin_def same_length_def xs_as_eq a1 by fastforce\n         have s_state: \"same_state (\\<Gamma>, (xs, s) # (as,sa) # ys) \n                           (map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\n                                   (zip xs ?clist))\"\n              using hyp\n              apply (simp add:hyp conjoin_def same_state_def  a1)              \n              apply clarify\n              apply(case_tac j) \n              by (simp add: xs_as_eq,simp add: xs_as_eq)\n         have s_function: \"same_functions (\\<Gamma>, (xs, s) # (as,sa) # ys) \n                           (map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\n                                   (zip xs ?clist))\"\n              using hyp conjoin_def same_functions_def a1 by fastforce\n         have s_program: \"same_program (\\<Gamma>, (xs, s) # (as,sa) # ys) \n                           (map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\n                                   (zip xs ?clist))\"          \n              using hyp\n              apply (simp add:hyp conjoin_def same_program_def same_length_def a1)\n              apply clarify\n              apply(case_tac j)                \n                apply(rule nth_equalityI) \n                apply(simp,simp)              \n              by(rule nth_equalityI, simp add: hyp xs_as_eq, simp add:xs_as_eq)\n         have s_compat:\"compat_label (\\<Gamma>, (xs, s) # (xs,sa) # ys) \n                           (map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\n                                   (zip xs ?clist))\" \n            using hyp a1 pe_ce\n            apply (simp add:hyp conjoin_def compat_label_def)\n            apply clarify\n            apply(case_tac j,simp add: xs_as_eq)\n               apply blast\n              apply (simp add: xs_as_eq step_e.intros step_pe.intros)\n             apply clarify\n            apply(erule_tac x=nat in allE,erule impE,assumption)             \n            apply(erule disjE,simp)\n            apply clarify\n            apply(rule_tac x=i in exI) \n            using hyp by (fastforce)+                            \n        thus ?thesis using s_len s_program s_state s_function conjoin_def xs_as_eq\n            by blast\n     qed\n     then have \n      \"(\\<exists>clist.\n                  length clist = length xs \\<and>\n                  (\\<Gamma>, (xs, s) #\n                       a # ys) \\<propto> map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\n                                   (zip xs clist) \\<and>\n                  (\\<forall>i<length xs. (\\<Gamma>, (xs ! i, s) # clist ! i) \\<in> cptn))\"\n     using s1 s2 a_pair by blast\n   } note s1=this\n\n   {\n     assume a1':\"\\<Gamma>\\<turnstile>\\<^sub>p (xs, s) \\<rightarrow> (as, sa)\"\n     then obtain i r where \n       inter_tran:\"i < length xs \\<and> \\<Gamma>\\<turnstile>\\<^sub>c (xs ! i, s) \\<rightarrow> (r, sa) \\<and> as = xs[i := r]\" \n     using step_p_pair_elim_cases by metis     \n     then have xs_as_eq_len: \"length xs = length as\" by simp\n     from inter_tran \n      have s_states:\"\\<exists>nsa. s=Normal nsa \\<or> (s=sa \\<and> (\\<forall>sa. (s\\<noteq>Normal sa)))\"\n      using step_not_normal_s_eq_t by blast\n     have as_xs:\"\\<forall>i'<length as. (i'=i \\<and> as!i'=r) \\<or> (as!i'=xs!i')\" \n       using xs_as_eq_len by (simp add: inter_tran nth_list_update)\n     let ?clist=\"(map (\\<lambda>j. (as!j, sa)#(clist!j)) [0..<length xs]) [i:=((r, sa)#(clist!i))]\"\n     have s1:\"length ?clist = length xs\"\n       by auto\n     have s2:\"(\\<forall>i'<length xs. (\\<Gamma>, (xs ! i', s) # ?clist ! i') \\<in> cptn)\" \n        proof -\n         {fix i'\n          assume a1:\"i' < length xs\"          \n          have \"(\\<Gamma>, (xs ! i', s) # ?clist ! i') \\<in> cptn\"\n          proof (cases \"i=i'\")\n            case True \n             thus ?thesis using inter_tran  hyp cptn.CptnComp               \n              apply simp \n              by fastforce  \n          next              \n            case False            \n            thus ?thesis using s_states inter_tran  False hyp cptn.CptnComp a1\n              apply clarify\n              apply simp\n              apply(erule_tac x=i' in allE)\n              apply (simp)\n              apply(rule CptnEnv) \n              by (auto simp add: Env Env_n)\n          qed\n         } \n        thus ?thesis by fastforce\n      qed\n     then have s3:\"(\\<Gamma>, (xs, s) #\n                       (as,sa) # ys) \\<propto> map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\n                                   (zip xs ?clist)\"\n     proof -        \n        from hyp have \n         len_list:\"length clist = length as\" by auto\n        from hyp have same_len:\"same_length (\\<Gamma>, (as, sa) # ys)  \n                      (map (\\<lambda>i. (\\<Gamma>, (fst i, sa) # snd i)) (zip as clist))\"\n          using conjoin_def by auto        \n        have s_len: \"same_length (\\<Gamma>, (xs, s) # (as,sa) # ys) \n                           (map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\n                                   (zip xs ?clist))\"  \n          using \n            same_len  inter_tran  \n            unfolding conjoin_def same_length_def\n            apply clarify \n            apply(case_tac \"i=ia\")            \n            by (auto simp add: len_list)            \n        have s_state: \"same_state (\\<Gamma>, (xs, s) # (as,sa) # ys) \n                           (map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\n                                   (zip xs ?clist))\"\n              using hyp inter_tran unfolding conjoin_def same_state_def\n               apply clarify\n               apply(case_tac j, simp, simp (no_asm_simp))\n               apply(case_tac \"i=ia\",simp , simp )\n              by (metis (no_types, hide_lams) as_xs nth_list_update_eq xs_as_eq_len)              \n        have s_function: \"same_functions (\\<Gamma>, (xs, s) # (as,sa) # ys) \n                           (map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\n                                   (zip xs ?clist))\"\n              using hyp conjoin_def same_functions_def a1 by fastforce\n        have s_program: \"same_program (\\<Gamma>, (xs, s) # (as,sa) # ys) \n                           (map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\n                                   (zip xs ?clist))\"          \n          using hyp inter_tran unfolding conjoin_def same_program_def\n           apply clarify\n           apply(case_tac j,simp)           \n           apply(rule nth_equalityI,simp,simp)\n           apply simp\n           apply(rule nth_equalityI,simp,simp)\n           apply(erule_tac x=nat and P=\"\\<lambda>j. H j \\<longrightarrow> (fst (a j))=((b j))\" for H a b in allE)\n           apply(case_tac nat)\n           apply clarify\n           apply(case_tac \"i=ia\",simp,simp)\n           apply clarify\n           by(case_tac \"i=ia\",simp,simp)                   \n        have s_compat:\"compat_label (\\<Gamma>, (xs, s) # (as,sa) # ys) \n                           (map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\n                                   (zip xs ?clist))\" \n        using inter_tran hyp s_states\n        unfolding conjoin_def compat_label_def\n         apply clarify\n         apply(case_tac j)\n          apply(rule conjI,simp)\n           apply(erule ParComp,assumption)\n           apply clarify\n           apply(rule exI[where x=i],simp)\n          apply clarify\n          apply (rule snormal_enviroment,assumption)\n         apply simp\n         apply(erule_tac x=nat and P=\"\\<lambda>j. H j \\<longrightarrow> (P j \\<or> Q j)\" for H P Q in allE,simp)\n         apply (thin_tac \"s = Normal nsa \\<or> s = sa \\<and> (\\<forall>sa. s \\<noteq> Normal sa)\")\n        apply(erule disjE )\n         apply clarify\n         apply(rule_tac x=ia in exI,simp)\n         apply(rule conjI)\n          apply(case_tac \"i=ia\",simp,simp)\n         apply clarify\n         apply(case_tac \"i=l\",simp)\n          apply(case_tac \"l=ia\",simp,simp)\n          apply(erule_tac x=l in allE,erule impE,assumption,erule impE, assumption,simp)\n         apply simp\n         apply(erule_tac x=l in allE,erule impE,assumption,erule impE, assumption,simp)\n        apply clarify\n        apply (thin_tac \" \\<forall>ia<length xs. (\\<Gamma>, (xs[i := r] ! ia, sa) # clist ! ia) \\<in> cptn\")\n        apply(erule_tac x=ia and P=\"\\<lambda>j. H j \\<longrightarrow> (P j)\" for H P in allE, erule impE, assumption)\n        by(case_tac \"i=ia\",simp,simp)               \n        thus ?thesis using s_len s_program s_state s_function conjoin_def  \n          by blast\n     qed     \n     then have \"(\\<exists>clist.\n                  length clist = length xs \\<and>\n                  (\\<Gamma>, (xs, s) #\n                       a # ys) \\<propto> map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\n                                   (zip xs clist) \\<and>\n                  (\\<forall>i<length xs. (\\<Gamma>, (xs ! i, s) # clist ! i) \\<in> cptn))\"\n     using s1 s2 a_pair by blast\n   } \n   then have \n      \"(\\<exists>clist.\n                  length clist = length xs \\<and>\n                  (\\<Gamma>, (xs, s) #\n                       a # ys) \\<propto> map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\n                                   (zip xs clist) \\<and>\n                  (\\<forall>i<length xs. (\\<Gamma>, (xs ! i, s) # clist ! i) \\<in> cptn))\"\n      using s1 par_cptn_dest by fastforce\n  }  \n  thus ?case by auto\nqed  \n\nlemma one_iff_aux_if:\"xs\\<noteq>[] \\<Longrightarrow> (\\<forall>ys. ((\\<Gamma>,((xs, s)#ys)) \\<in> par_cptn) = \n (\\<exists>clist. length clist= length xs \\<and> \n ((\\<Gamma>,(xs, s)#ys) \\<propto> map (\\<lambda>i. (\\<Gamma>,(fst i,s)#(snd i))) (zip xs clist)) \\<and> \n (\\<forall>i<length xs. (\\<Gamma>,(xs!i,s)#(clist!i)) \\<in> cptn))) \\<Longrightarrow>\n (par_cp \\<Gamma> (xs) s = {(\\<Gamma>1,c). \\<exists>clist. (length clist)=(length xs) \\<and>\n (\\<forall>i<length clist. clist!i \\<in> cp \\<Gamma> (xs!i) s) \\<and> (\\<Gamma>,c) \\<propto> clist \\<and> \\<Gamma>1=\\<Gamma>})\"\nproof\n  assume a1:\"xs\\<noteq>[]\"\n  assume a2:\"\\<forall>ys. ((\\<Gamma>, (xs, s) # ys) \\<in> par_cptn) =\n         (\\<exists>clist.\n             length clist = length xs \\<and>\n             (\\<Gamma>,\n              (xs, s) #\n              ys) \\<propto> map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\n                      (zip xs clist) \\<and>\n             (\\<forall>i<length xs.\n                 (\\<Gamma>, (xs ! i, s) # clist ! i) \\<in> cptn))\"         \n   show \"par_cp \\<Gamma> xs s \\<subseteq> \n             {(\\<Gamma>1, c). \\<exists>clist.\n               length clist = length xs \\<and>\n               (\\<forall>i<length clist. clist ! i \\<in> cp \\<Gamma> (xs ! i) s) \\<and>\n               (\\<Gamma>, c) \\<propto> clist \\<and> \\<Gamma>1 = \\<Gamma>}\"\n   proof-{     \n     fix x\n     let ?show = \"x\\<in> {(\\<Gamma>1, c). \\<exists>clist.\n       length clist = length xs \\<and>\n       (\\<forall>i<length clist. clist ! i \\<in> cp \\<Gamma> (xs ! i) s) \\<and>\n        (\\<Gamma>, c) \\<propto> clist \\<and> \\<Gamma>1 = \\<Gamma>}\"\n     assume a3:\"x\\<in>par_cp \\<Gamma> xs s\"   \n     then obtain y where x_pair: \"x=(\\<Gamma>,y)\"\n       unfolding par_cp_def by auto       \n     have ?show          \n     proof (cases y)\n        case Nil then \n         show ?show using a1 a2 a3 x_pair\n          unfolding par_cp_def cp_def\n          by (force elim:par_cptn.cases)\n     next \n        case (Cons a list) then\n          show ?show using a1 a2 a3 x_pair\n          unfolding par_cp_def cp_def         \n          by(auto, rule_tac x=\"map (\\<lambda>i. (\\<Gamma>,(fst i, s) # snd i)) (zip xs clist)\" in exI,simp)\n     qed\n   } thus ?thesis using a1 a2 by auto \n   qed\n   {   \n   show \"{(\\<Gamma>1, c). \\<exists>clist.\n          length clist = length xs \\<and>\n          (\\<forall>i<length clist. clist ! i \\<in> cp \\<Gamma> (xs ! i) s) \\<and>\n          (\\<Gamma>, c) \\<propto> clist \\<and> \\<Gamma>1 = \\<Gamma>} \\<subseteq> par_cp \\<Gamma> xs s\" using a1 a2 \n   proof-\n     { \n     fix x\n     assume a3:\"x\\<in>{(\\<Gamma>1, c). \\<exists>clist.\n          length clist = length xs \\<and>\n          (\\<forall>i<length clist. clist ! i \\<in> cp \\<Gamma> (xs ! i) s) \\<and>\n          (\\<Gamma>, c) \\<propto> clist \\<and> \\<Gamma>1 = \\<Gamma>}\"\n     then obtain c where x_pair: \"x=(\\<Gamma>,c)\"  by auto\n     then obtain clist where \n      props:\"length clist = length xs \\<and>\n           (\\<forall>i<length clist. clist ! i \\<in> cp \\<Gamma> (xs ! i) s) \\<and>\n           (\\<Gamma>, c) \\<propto> clist \" using a3 by auto\n     then have \"x\\<in>par_cp \\<Gamma> xs s\"\n       proof (cases c)\n         case Nil \n         have clist_0: \n           \"clist ! 0 \\<in> cp \\<Gamma> (xs ! 0) s\" using props a1 \n         by auto\n         thus \"x\\<in>par_cp \\<Gamma> xs s\"  \n           using a1 a2 props Nil x_pair\n         unfolding cp_def conjoin_def same_length_def \n         apply clarify                  \n         by(erule cptn.cases,fastforce,fastforce,fastforce)\n       next\n         case (Cons a ys) \n         then obtain a1 a2 where a_pair: \"a=(a1,a2)\" \n           using props by fastforce \n         from a2 have \n               a2:\"(((\\<Gamma>, (xs, s) # ys) \\<in> par_cptn) =\n                   (\\<exists>clist. length clist = length xs \\<and>\n                   (\\<Gamma>, (xs, s) # ys) \\<propto> map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i)) (zip xs clist) \\<and>\n                   (\\<forall>i<length xs. (\\<Gamma>, (xs ! i, s) # clist ! i) \\<in> cptn)))\" by auto\n         have a2_s:\"a2=s\" using a1 props a_pair Cons\n           unfolding  conjoin_def   same_state_def  cp_def         \n           by force\n         have a1_xs:\"a1 = xs\"\n           using  props a_pair Cons \n           unfolding par_cp_def conjoin_def  same_program_def cp_def           \n           apply clarify\n           apply(erule_tac x=0 and P=\"\\<lambda>j. H j \\<longrightarrow> (fst (s j))=((t j))\" for H s t in allE)                      \n           by(rule nth_equalityI,auto)   \n         then have conjoin_clist_xs:\"(\\<Gamma>, (xs,s)#ys) \\<propto> clist\"     \n           using a1  props a_pair Cons a1_xs a2_s by auto\n         also then have \"clist = map (\\<lambda>i. (\\<Gamma>,(fst i,s)#(snd i))) (zip xs ((map (\\<lambda>x. tl (snd x))) clist))\"             \n           using clist_map_zip a1  by fastforce\n         ultimately have conjoin_map:\"(\\<Gamma>, (xs, s) # ys) \\<propto> map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i)) (zip xs ((map (\\<lambda>x. tl (snd x))) clist))\"\n           using props x_pair Cons a_pair a1_xs a2_s by auto    \n         have \"\\<And>n. \\<not> n < length xs \\<or> clist ! n \\<in> {(f, ps). ps ! 0 = (xs ! n, a2) \\<and> (\\<Gamma>, ps) \\<in> cptn \\<and> f = \\<Gamma>}\"\n               using a1_xs a2_s props cp_def by fastforce\n         then have clist_cptn:\"(\\<forall>i<length clist. (fst (clist!i) = \\<Gamma>) \\<and> \n                                 (\\<Gamma>, snd (clist!i)) \\<in> cptn \\<and>\n                                 (snd (clist!i))!0 = (xs!i,s))\"\n         using a1_xs a2_s props by fastforce         \n                       \n          {fix i\n          assume a4: \"i<length xs\"     \n          then have clist_i_cptn:\"(fst (clist!i) = \\<Gamma>) \\<and> \n                     (\\<Gamma>, snd (clist!i)) \\<in> cptn \\<and>\n                     (snd (clist!i))!0 = (xs!i,s)\"\n           using props clist_cptn by fastforce \n          from a4 props have a4':\"i<length clist\" by auto\n          have lengz:\"length (snd (clist!i))>0\" \n            using conjoin_clist_xs a4'\n            unfolding  conjoin_def same_length_def \n           by auto\n          then have clist_hd_tl:\"snd (clist!i) =  hd (snd (clist!i)) # tl (snd (clist ! i))\"\n            by auto        \n          also have \" hd (snd (clist!i)) =  (snd (clist!i))!0\"\n            using a4' lengz by (simp add: hd_conv_nth)\n          ultimately have clist_i_tl:\"snd (clist!i) =  (xs!i,s) # tl (snd (clist ! i))\"\n            using clist_i_cptn by fastforce\n          also have \"tl (snd (clist ! i)) = map (\\<lambda>x. tl (snd x)) clist!i\"\n            using nth_map a4' \n          by auto\n          ultimately have snd_clist:\"snd (clist!i) =  (xs ! i, s) # map (\\<lambda>x. tl (snd x)) clist ! i\"\n            by auto\n          also have \"(clist!i) = (fst (clist!i),snd (clist!i))\"\n            by auto\n          ultimately have \"(clist!i) =(\\<Gamma>, (xs ! i, s) # map (\\<lambda>x. tl (snd x)) clist ! i)\"\n           using clist_i_cptn by auto\n          then have \"(\\<Gamma>, (xs ! i, s) # map (\\<lambda>x. tl (snd x)) clist ! i) \\<in> cptn\" \n             using clist_i_cptn by auto\n          } \n          then have clist_in_cptn:\"(\\<forall>i<length xs. (\\<Gamma>, (xs ! i, s) # ((map (\\<lambda>x. tl (snd x))) clist) ! i) \\<in> cptn)\"\n          by auto\n         have same_length_clist_xs:\"length ((map (\\<lambda>x. tl (snd x))) clist)  = length xs\"\n           using props by auto\n         then have \"(\\<exists>clist. length clist = length xs \\<and>\n                        (\\<Gamma>, (xs, s) # ys) \\<propto> map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i)) (zip xs clist) \\<and>\n                        (\\<forall>i<length xs. (\\<Gamma>, (xs ! i, s) # clist ! i) \\<in> cptn))\"\n         using  a1  props x_pair a_pair Cons a1_xs a2_s conjoin_clist_xs clist_in_cptn\n            conjoin_map clist_map by blast         \n         then have \"(\\<Gamma>, c) \\<in> par_cptn\" using  a1 a2  props x_pair a_pair Cons a1_xs a2_s\n         unfolding par_cp_def by simp          \n         thus \"x\\<in>par_cp \\<Gamma> xs s\"  \n           using a1 a2  props x_pair a_pair Cons a1_xs a2_s\n         unfolding par_cp_def conjoin_def  same_length_def same_program_def same_state_def same_functions_def compat_label_def \n           by simp          \n       qed\n     }\n     thus ?thesis using a1 a2 by auto  \n   qed\n  } \nqed\n\n\n\nlemma one_iff_aux_only_if:\"xs\\<noteq>[] \\<Longrightarrow>  \n (par_cp \\<Gamma> (xs) s = {(\\<Gamma>1,c). \\<exists>clist. (length clist)=(length xs) \\<and>\n (\\<forall>i<length clist. clist!i \\<in> cp \\<Gamma> (xs!i) s) \\<and> (\\<Gamma>,c) \\<propto> clist \\<and> \\<Gamma>1=\\<Gamma>}) \\<Longrightarrow>\n(\\<forall>ys. ((\\<Gamma>,((xs, s)#ys)) \\<in> par_cptn) = \n (\\<exists>clist. length clist= length xs \\<and> \n ((\\<Gamma>,(xs, s)#ys) \\<propto> map (\\<lambda>i. (\\<Gamma>,(fst i,s)#(snd i))) (zip xs clist)) \\<and> \n (\\<forall>i<length xs. (\\<Gamma>,(xs!i,s)#(clist!i)) \\<in> cptn)))\"\nproof\n  fix ys\n  assume a1: \"xs\\<noteq>[]\"\n  assume a2: \"par_cp \\<Gamma> xs s =\n          {(\\<Gamma>1, c).\n           \\<exists>clist.\n              length clist = length xs \\<and>\n              (\\<forall>i<length clist.\n                  clist ! i \\<in> cp \\<Gamma> (xs ! i) s) \\<and>\n              (\\<Gamma>, c) \\<propto> clist \\<and> \\<Gamma>1 = \\<Gamma>}\"\n  from a1 a2 show\n  \"((\\<Gamma>, (xs, s) # ys) \\<in> par_cptn) =\n          (\\<exists>clist.\n              length clist = length xs \\<and>\n              (\\<Gamma>,\n               (xs, s) #\n               ys) \\<propto> map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\n                       (zip xs clist) \\<and>\n              (\\<forall>i<length xs.\n                  (\\<Gamma>, (xs ! i, s) # clist ! i) \\<in> cptn))\"\n  proof auto\n    {assume a3:\"(\\<Gamma>, (xs, s) # ys) \\<in> par_cptn\"\n     then show \"\\<exists>clist.\n       length clist = length xs \\<and>\n       (\\<Gamma>,\n        (xs, s) #\n        ys) \\<propto> map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\n                (zip xs clist) \\<and>\n       (\\<forall>i<length xs. (\\<Gamma>, (xs ! i, s) # clist ! i) \\<in> cptn)\"\n       using a1 a2 by (simp add: aux_onlyif)\n    }\n    {fix clist ::\"(('a, 'b, 'c, 'd) LanguageCon.com \\<times>\n             ('a, 'c) xstate) list list\"\n    assume a3: \"length clist = length xs\"\n    assume a4:\"(\\<Gamma>, (xs, s) # ys) \\<propto> \n               map (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))\n                (zip xs clist)\"\n    assume a5: \"\\<forall>i<length xs. (\\<Gamma>, (xs ! i, s) # clist ! i)\n                     \\<in> cptn\"\n    show \"(\\<Gamma>, (xs, s) # ys) \\<in> par_cptn\" \n    using a3 a4 a5 using aux_if by blast \n    }\n  qed\nqed\n\nlemma one_iff_aux: \"xs\\<noteq>[] \\<Longrightarrow> (\\<forall>ys. ((\\<Gamma>,((xs, s)#ys)) \\<in> par_cptn) = \n (\\<exists>clist. length clist= length xs \\<and> \n ((\\<Gamma>,(xs, s)#ys) \\<propto> map (\\<lambda>i. (\\<Gamma>,(fst i,s)#(snd i))) (zip xs clist)) \\<and> \n (\\<forall>i<length xs. (\\<Gamma>,(xs!i,s)#(clist!i)) \\<in> cptn))) = \n (par_cp \\<Gamma> (xs) s = {(\\<Gamma>1,c). \\<exists>clist. (length clist)=(length xs) \\<and>\n (\\<forall>i<length clist. clist!i \\<in> cp \\<Gamma> (xs!i) s) \\<and> (\\<Gamma>,c) \\<propto> clist \\<and> \\<Gamma>1=\\<Gamma>})\"\nproof \n  assume a1:\"xs\\<noteq>[]\"\n  {assume a2:\"(\\<forall>ys. ((\\<Gamma>,((xs, s)#ys)) \\<in> par_cptn) = \n   (\\<exists>clist. length clist= length xs \\<and> \n   ((\\<Gamma>,(xs, s)#ys) \\<propto> map (\\<lambda>i. (\\<Gamma>,(fst i,s)#(snd i))) (zip xs clist)) \\<and> \n   (\\<forall>i<length xs. (\\<Gamma>,(xs!i,s)#(clist!i)) \\<in> cptn)))\"\n    then show \"(par_cp \\<Gamma> (xs) s = {(\\<Gamma>1,c). \\<exists>clist. (length clist)=(length xs) \\<and>\n   (\\<forall>i<length clist. clist!i \\<in> cp \\<Gamma> (xs!i) s) \\<and> (\\<Gamma>,c) \\<propto> clist \\<and> \\<Gamma>1=\\<Gamma>})\"\n    by (auto simp add: a1 a2 one_iff_aux_if)\n  }\n  {assume a2:\"(par_cp \\<Gamma> (xs) s = {(\\<Gamma>1,c). \\<exists>clist. (length clist)=(length xs) \\<and>\n   (\\<forall>i<length clist. clist!i \\<in> cp \\<Gamma> (xs!i) s) \\<and> (\\<Gamma>,c) \\<propto> clist \\<and> \\<Gamma>1=\\<Gamma>})\"    \n    then show \"(\\<forall>ys. ((\\<Gamma>,((xs, s)#ys)) \\<in> par_cptn) = \n   (\\<exists>clist. length clist= length xs \\<and> \n   ((\\<Gamma>,(xs, s)#ys) \\<propto> map (\\<lambda>i. (\\<Gamma>,(fst i,s)#(snd i))) (zip xs clist)) \\<and> \n   (\\<forall>i<length xs. (\\<Gamma>,(xs!i,s)#(clist!i)) \\<in> cptn)))\"\n   by (auto simp add: a1 a2 one_iff_aux_only_if)\n  }\nqed\n  \n\n\ntheorem one: \n\"xs\\<noteq>[] \\<Longrightarrow>  \n par_cp \\<Gamma> xs s = \n    {(\\<Gamma>1,c). \\<exists>clist. (length clist)=(length xs) \\<and> \n             (\\<forall>i<length clist. (clist!i) \\<in> cp \\<Gamma> (xs!i) s) \\<and> \n             (\\<Gamma>,c) \\<propto> clist \\<and> \\<Gamma>1=\\<Gamma>}\"\n\napply(frule one_iff_aux)\napply(drule sym)\napply(erule iffD2)\napply clarify\napply(rule iffI) \n apply(erule aux_onlyif)\napply clarify\napply(force intro:aux_if)\ndone\n\n(************************************************************************ *)\n(* subsection {* Equivalence between Small-Step and Big-Step Semantics *} *)\n(* ************************************************************************ *)\n \n(* \n\n?\\<Gamma>\\<turnstile>\\<^sub>c (LanguageCon.com.Seq ?c1.0 ?c2.0, ?s) \\<rightarrow>\n       (LanguageCon.com.Seq ?c1' ?c2.0,\n        ?s') \\<Longrightarrow>\n(?\\<Gamma>\\<turnstile>\\<^sub>c (?c1.0, ?s) \\<rightarrow> (?c1', ?s') \\<Longrightarrow> ?P) \\<Longrightarrow>\n?P\n\nlemma \n   assumes \n           step_a: \"\\<Gamma>\\<turnstile>\\<^sub>c(Await b c, Normal s) \\<rightarrow> (t,u)\"\n   shows step_await_step_c:\"(\\<Gamma>\\<^sub>\\<not>\\<^sub>a)\\<turnstile>(c, Normal s) \\<rightarrow>\\<^sup>* (sequential t,u)\" \nusing step_a\nproof cases\n  fix t1\n  assume\n      \"(t, u) = (Skip, t1)\" \"s \\<in> b\" \"\\<Gamma>\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> t1\" \"\\<forall>t'. t1 \\<noteq> Abrupt t'\"\n  thus ?thesis \n   by (cases u) \n   (auto intro: exec_impl_steps_Fault exec_impl_steps_Normal exec_impl_steps_Stuck)\nnext\n  fix t1\n  assume \"(t, u) = (Throw, Normal t1)\" \"s \\<in> b\" \"\\<Gamma>\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> Abrupt t1\"\n  thus ?thesis by (simp add: exec_impl_steps_Normal_Abrupt)\nqed\n\nlemma \n   assumes (* exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" and\n           b: \"s \\<in> b\" and *)\n           step_a: \"\\<Gamma>\\<turnstile>\\<^sub>c(Await b c, Normal s) \\<rightarrow> u\"\n   shows step_await_final1:\"final u\"\nusing step_a \nproof cases\n  case  (1 t) thus \"final u\"  by (simp add: final_def)\nnext\n  case (2 t)\n  thus \"final u\" by (simp add: exec_impl_steps_Normal_Abrupt final_def)\nqed\n\nlemma step_Abrupt_end: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, s) \\<rightarrow> (c\\<^sub>1', s')\"\n  shows \"s'=Abrupt x \\<Longrightarrow> s=Abrupt x\"\nusing step\nby induct auto\n\n\nlemma step_Stuck_end: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, s) \\<rightarrow> (c\\<^sub>1', s')\"\n  shows \"s'=Stuck \\<Longrightarrow> \n          s=Stuck \\<or> \n          (\\<exists>r x. redex c\\<^sub>1 = Spec r \\<and> s=Normal x \\<and> (\\<forall>t. (x,t)\\<notin>r)) \\<or> \n          (\\<exists>p x. redex c\\<^sub>1=  Call p \\<and> s=Normal x \\<and> \\<Gamma> p = None) \\<or>\n          (\\<exists>b c x.  redex c\\<^sub>1 = Await b c \\<and> s=Normal x \\<and> x \\<in> b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle>\\<Rightarrow>s')\"\nusing step\nby induct auto\n\nlemma step_Fault_end: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, s) \\<rightarrow> (c\\<^sub>1', s')\"\n  shows \"s'=Fault f \\<Longrightarrow> \n          s=Fault f \\<or> \n          (\\<exists>g c x.  redex c\\<^sub>1 = Guard f g c \\<and> s=Normal x \\<and> x \\<notin> g) \\<or>\n          (\\<exists>b c1 x.  redex c\\<^sub>1 = Await b c1 \\<and> s=Normal x \\<and> x \\<in> b \\<and> \\<Gamma>\\<turnstile>\\<langle>c1,s\\<rangle>\\<Rightarrow>s')\"\nusing step \nby induct auto\n\n\n\n(* ************************************************************************ *)\nsubsection {* Infinite Computations: @{text \"\\<Gamma>\\<turnstile>(c, s) \\<rightarrow> \\<dots>(\\<infinity>)\"}*}\n(* ************************************************************************ *)\n\ndefinition inf_c:: \"('s,'p,'f,'e) body \\<Rightarrow> ('s,'p,'f,'e) config \\<Rightarrow> bool\"\n (\"_\\<turnstile>\\<^sub>c _ \\<rightarrow> \\<dots>'(\\<infinity>')\" [60,80] 100) where\n\"\\<Gamma>\\<turnstile>\\<^sub>c cfg \\<rightarrow> \\<dots>(\\<infinity>) \\<equiv> (\\<exists>f. f (0::nat) = cfg \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>\\<^sub>cf i \\<rightarrow> f (i+1)))\" \n\nlemma not_infI: \"\\<lbrakk>\\<And>f. \\<lbrakk>f 0 = cfg; \\<And>i. \\<Gamma>\\<turnstile>\\<^sub>cf i \\<rightarrow> f (Suc i)\\<rbrakk> \\<Longrightarrow> False\\<rbrakk>  \n                \\<Longrightarrow> \\<not>\\<Gamma>\\<turnstile>\\<^sub>c cfg \\<rightarrow> \\<dots>(\\<infinity>)\"\n  by (auto simp add: inf_c_def)\n\n(* ************************************************************************ *)\nsubsection {* Equivalence between Termination and the Absence of Infinite Computations*}\n(* ************************************************************************ *)\n\n\nlemma step_preserves_termination: \n  assumes step: \"\\<Gamma>\\<turnstile>(c,s) \\<rightarrow> (c',s')\"\n  shows \"\\<Gamma>\\<turnstile>c\\<down>s \\<Longrightarrow> \\<Gamma>\\<turnstile>c'\\<down>s'\"  \nusing step\nproof (induct)\n  case Basic thus ?case by (fastforce intro: terminates.intros)\nnext\n  case Spec thus ?case by (fastforce intro: terminates.intros)\nnext\n  case SpecStuck thus ?case by (fastforce intro: terminates.intros)\nnext\n  case Guard thus ?case \n    by (fastforce intro: terminates.intros elim: terminates_Normal_elim_cases)\nnext\n  case GuardFault thus ?case by (fastforce intro: terminates.intros)\nnext\n  case (Seq c\\<^sub>1 s c\\<^sub>1' s' c\\<^sub>2) thus ?case\n    apply (cases s)\n    apply     (cases s')\n    apply         (fastforce intro: terminates.intros step_extend \n                    elim: terminates_Normal_elim_cases)\n    apply (fastforce intro: terminates.intros dest: step_Abrupt_prop \n      step_Fault_prop step_Stuck_prop)+\n    done\nnext\n  case (SeqSkip c\\<^sub>2 s) \n  thus ?case \n    apply (cases s)\n    apply (fastforce intro: terminates.intros exec.intros\n            elim: terminates_Normal_elim_cases )+\n    done\nnext\n  case (SeqThrow c\\<^sub>2 s) \n  thus ?case \n    by (fastforce intro: terminates.intros exec.intros\n            elim: terminates_Normal_elim_cases )\nnext\n  case CondTrue \n  thus ?case \n    by (fastforce intro: terminates.intros exec.intros\n            elim: terminates_Normal_elim_cases )\nnext\n  case CondFalse \n  thus ?case \n    by (fastforce intro: terminates.intros \n            elim: terminates_Normal_elim_cases )\nnext\n  case WhileTrue\n  thus ?case \n    by (fastforce intro: terminates.intros \n            elim: terminates_Normal_elim_cases )\nnext\n  case WhileFalse \n  thus ?case \n    by (fastforce intro: terminates.intros \n            elim: terminates_Normal_elim_cases )\nnext\n  case Call \n  thus ?case \n    by (fastforce intro: terminates.intros \n            elim: terminates_Normal_elim_cases )\nnext\n  case CallUndefined\n  thus ?case \n    by (fastforce intro: terminates.intros \n            elim: terminates_Normal_elim_cases )\nnext\n  case DynCom\n  thus ?case \n    by (fastforce intro: terminates.intros \n            elim: terminates_Normal_elim_cases )\nnext\n  case (Catch c\\<^sub>1 s c\\<^sub>1' s' c\\<^sub>2) thus ?case\n    apply (cases s)\n    apply     (cases s')\n    apply         (fastforce intro: terminates.intros step_extend \n                    elim: terminates_Normal_elim_cases)\n    apply (fastforce intro: terminates.intros dest: step_Abrupt_prop \n      step_Fault_prop step_Stuck_prop)+\n    done\nnext\n  case CatchThrow\n  thus ?case \n   by (fastforce intro: terminates.intros exec.intros\n            elim: terminates_Normal_elim_cases )\nnext\n  case (CatchSkip c\\<^sub>2 s) \n  thus ?case \n    by (cases s) (fastforce intro: terminates.intros)+\nnext\n  case FaultProp thus ?case by (fastforce intro: terminates.intros)\nnext\n  case StuckProp thus ?case by (fastforce intro: terminates.intros)\nnext\n  case AbruptProp thus ?case by (fastforce intro: terminates.intros)\nnext \n  case Await thus ?case using terminates_Skip' by blast \nnext \n  case AwaitAbrupt thus ?case by (fastforce intro: terminates.intros)\nqed\n\nlemma steps_preserves_termination: \n  assumes steps: \"\\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>* (c',s')\"\n  shows \"\\<Gamma>\\<turnstile>c\\<down>s \\<Longrightarrow> \\<Gamma>\\<turnstile>c'\\<down>s'\"\nusing steps\nproof (induct rule: rtranclp_induct2 [consumes 1, case_names Refl Trans])\n  case Refl thus ?case  .\nnext\n  case Trans\n  thus ?case\n    by (blast dest: step_preserves_termination)\nqed\n\nML {*\n  ML_Thms.bind_thm (\"tranclp_induct2\", Split_Rule.split_rule @{context}\n    (Rule_Insts.read_instantiate @{context}\n      [(((\"a\", 0), Position.none), \"(aa,ab)\"), (((\"b\", 0), Position.none), \"(ba,bb)\")] []\n      @{thm tranclp_induct}));\n*}\n\nthm tranclp_induct2 tranclp_induct\n\nlemma steps_preserves_termination': \n  assumes steps: \"\\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>+ (c',s')\"\n  shows \"\\<Gamma>\\<turnstile>c\\<down>s \\<Longrightarrow> \\<Gamma>\\<turnstile>c'\\<down>s'\"\nusing steps\nproof (induct rule: tranclp_induct2 [consumes 1, case_names Step Trans])\n  case Step thus ?case by (blast intro: step_preserves_termination)\nnext\n  case Trans\n  thus ?case\n    by (blast dest: step_preserves_termination)\nqed\n\n\n\ndefinition head_com:: \"('s,'p,'f,'e) com \\<Rightarrow> ('s,'p,'f,'e) com\"\nwhere\n\"head_com c =\n  (case c of\n     Seq c\\<^sub>1 c\\<^sub>2 \\<Rightarrow> c\\<^sub>1\n   | Catch c\\<^sub>1 c\\<^sub>2 \\<Rightarrow> c\\<^sub>1\n   | _ \\<Rightarrow> c)\"\n\n  \ndefinition head:: \"('s,'p,'f,'e) config \\<Rightarrow> ('s,'p,'f,'e) config\"\n  where \"head cfg = (head_com (fst cfg), snd cfg)\"\n\nlemma le_Suc_cases: \"\\<lbrakk>\\<And>i. \\<lbrakk>i < k\\<rbrakk> \\<Longrightarrow> P i; P k\\<rbrakk> \\<Longrightarrow> \\<forall>i<(Suc k). P i\"\n  apply clarify\n  apply (case_tac \"i=k\")\n  apply auto\n  done\n\nlemma redex_Seq_False: \"\\<And>c' c''. (redex c = Seq c'' c') = False\"\n  by (induct c) auto\n\nlemma redex_Catch_False: \"\\<And>c' c''. (redex c = Catch c'' c') = False\"\n  by (induct c) auto\n\n\nlemma infinite_computation_extract_head_Seq:\n  assumes inf_comp: \"\\<forall>i::nat. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (i+1)\"\n  assumes f_0: \"f 0 = (Seq c\\<^sub>1 c\\<^sub>2,s)\"\n  assumes not_fin: \"\\<forall>i<k. \\<not> final (head (f i))\"\n  shows \"\\<forall>i<k. (\\<exists>c' s'. f (i + 1) = (Seq c' c\\<^sub>2, s')) \\<and>  \n               \\<Gamma>\\<turnstile>head (f i) \\<rightarrow> head (f (i+1))\"\n        (is \"\\<forall>i<k. ?P i\")\nusing not_fin\nproof (induct k)\n  case 0\n  show ?case by simp\nnext\n  case (Suc k)\n  have not_fin_Suc: \n    \"\\<forall>i<Suc k. \\<not> final (head (f i))\" by fact\n  from this[rule_format] have not_fin_k: \n    \"\\<forall>i<k. \\<not> final (head (f i))\" \n    apply clarify\n    apply (subgoal_tac \"i < Suc k\")\n    apply blast\n    apply simp\n    done\n\n  from Suc.hyps [OF this]\n  have hyp: \"\\<forall>i<k. (\\<exists>c' s'. f (i + 1) = (Seq c' c\\<^sub>2, s')) \\<and> \n                   \\<Gamma>\\<turnstile> head (f i) \\<rightarrow> head (f (i + 1))\".\n  show ?case\n  proof (rule le_Suc_cases)\n    fix i \n    assume \"i < k\"\n    then show \"?P i\"\n      by (rule hyp [rule_format])\n  next\n    show \"?P k\"\n    proof -\n      from hyp [rule_format, of \"k - 1\"] f_0\n      obtain c' fs' L' s' where  f_k: \"f k = (Seq c' c\\<^sub>2, s')\"\n        by (cases k) auto\n      from inf_comp [rule_format, of k] f_k\n      have \"\\<Gamma>\\<turnstile>(Seq c' c\\<^sub>2, s') \\<rightarrow> f (k + 1)\"\n        by simp\n      moreover\n      from not_fin_Suc [rule_format, of k] f_k\n      have \"\\<not> final (c',s')\"\n        by (simp add: final_def head_def head_com_def)\n      ultimately\n      obtain c'' s'' where\n         \"\\<Gamma>\\<turnstile>(c', s') \\<rightarrow> (c'', s'')\" and\n         \"f (k + 1) = (Seq c'' c\\<^sub>2, s'')\"\n        by cases (auto simp add: redex_Seq_False final_def)\n      with f_k\n      show ?thesis\n        by (simp add: head_def head_com_def)\n    qed\n  qed\nqed\n\nlemma infinite_computation_extract_head_Catch:\n  assumes inf_comp: \"\\<forall>i::nat. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (i+1)\"\n  assumes f_0: \"f 0 = (Catch c\\<^sub>1 c\\<^sub>2,s)\"\n  assumes not_fin: \"\\<forall>i<k. \\<not> final (head (f i))\"\n  shows \"\\<forall>i<k. (\\<exists>c' s'. f (i + 1) = (Catch c' c\\<^sub>2, s')) \\<and>  \n               \\<Gamma>\\<turnstile>head (f i) \\<rightarrow> head (f (i+1))\"\n        (is \"\\<forall>i<k. ?P i\")\nusing not_fin\nproof (induct k)\n  case 0\n  show ?case by simp\nnext\n  case (Suc k)\n  have not_fin_Suc: \n    \"\\<forall>i<Suc k. \\<not> final (head (f i))\" by fact\n  from this[rule_format] have not_fin_k: \n    \"\\<forall>i<k. \\<not> final (head (f i))\" \n    apply clarify\n    apply (subgoal_tac \"i < Suc k\")\n    apply blast\n    apply simp\n    done\n\n  from Suc.hyps [OF this]\n  have hyp: \"\\<forall>i<k. (\\<exists>c' s'. f (i + 1) = (Catch c' c\\<^sub>2, s')) \\<and> \n                   \\<Gamma>\\<turnstile> head (f i) \\<rightarrow> head (f (i + 1))\".\n  show ?case\n  proof (rule le_Suc_cases)\n    fix i \n    assume \"i < k\"\n    then show \"?P i\"\n      by (rule hyp [rule_format])\n  next\n    show \"?P k\"\n    proof -\n      from hyp [rule_format, of \"k - 1\"] f_0\n      obtain c' fs' L' s' where  f_k: \"f k = (Catch c' c\\<^sub>2, s')\"\n        by (cases k) auto\n      from inf_comp [rule_format, of k] f_k\n      have \"\\<Gamma>\\<turnstile>(Catch c' c\\<^sub>2, s') \\<rightarrow> f (k + 1)\"\n        by simp\n      moreover\n      from not_fin_Suc [rule_format, of k] f_k\n      have \"\\<not> final (c',s')\"\n        by (simp add: final_def head_def head_com_def)\n      ultimately\n      obtain c'' s'' where\n         \"\\<Gamma>\\<turnstile>(c', s') \\<rightarrow> (c'', s'')\" and\n         \"f (k + 1) = (Catch c'' c\\<^sub>2, s'')\"\n        by cases (auto simp add: redex_Catch_False final_def)+\n      with f_k\n      show ?thesis\n        by (simp add: head_def head_com_def)\n    qed\n  qed\nqed\n\nlemma no_inf_Throw: \"\\<not> \\<Gamma>\\<turnstile>(Throw,s) \\<rightarrow> \\<dots>(\\<infinity>)\"\nproof \n  assume \"\\<Gamma>\\<turnstile> (Throw, s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n  then obtain f where\n    step [rule_format]: \"\\<forall>i::nat. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (i+1)\" and\n    f_0: \"f 0 = (Throw, s)\"\n    by (auto simp add: inf_def)\n  from step [of 0, simplified f_0] step [of 1]\n  show False\n    by cases (auto elim: step_elim_cases)\nqed\n\nlemma split_inf_Seq: \n  assumes inf_comp: \"\\<Gamma>\\<turnstile>(Seq c\\<^sub>1 c\\<^sub>2,s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n  shows \"\\<Gamma>\\<turnstile>(c\\<^sub>1,s) \\<rightarrow> \\<dots>(\\<infinity>) \\<or> \n         (\\<exists>s'. \\<Gamma>\\<turnstile>(c\\<^sub>1,s) \\<rightarrow>\\<^sup>* (Skip,s') \\<and> \\<Gamma>\\<turnstile>(c\\<^sub>2,s') \\<rightarrow> \\<dots>(\\<infinity>))\"\nproof -\n  from inf_comp obtain f where\n    step: \"\\<forall>i::nat. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (i+1)\" and\n    f_0: \"f 0 = (Seq c\\<^sub>1 c\\<^sub>2, s)\"\n    by (auto simp add: inf_def)\n  from f_0 have head_f_0: \"head (f 0) = (c\\<^sub>1,s)\" \n    by (simp add: head_def head_com_def)\n  show ?thesis\n  proof (cases \"\\<exists>i. final (head (f i))\")\n    case True\n    def k\\<equiv>\"(LEAST i. final (head (f i)))\"\n    have less_k: \"\\<forall>i<k. \\<not> final (head (f i))\"\n      apply (intro allI impI)\n      apply (unfold k_def)\n      apply (drule not_less_Least)\n      apply auto\n      done\n    from infinite_computation_extract_head_Seq [OF step f_0 this]\n    obtain step_head: \"\\<forall>i<k. \\<Gamma>\\<turnstile> head (f i) \\<rightarrow> head (f (i + 1))\" and\n           conf: \"\\<forall>i<k. (\\<exists>c' s'. f (i + 1) = (Seq c' c\\<^sub>2, s'))\"\n      by blast \n    from True\n    have final_f_k: \"final (head (f k))\"\n      apply -\n      apply (erule exE)\n      apply (drule LeastI)\n      apply (simp add: k_def)\n      done\n    moreover\n    from f_0 conf [rule_format, of \"k - 1\"]\n    obtain c' s' where f_k: \"f k = (Seq c' c\\<^sub>2,s')\"\n      by (cases k) auto\n    moreover\n    from step_head have steps_head: \"\\<Gamma>\\<turnstile>head (f 0) \\<rightarrow>\\<^sup>* head (f k)\"\n    proof (induct k)\n      case 0 thus ?case by simp\n    next\n      case (Suc m)\n      have step: \"\\<forall>i<Suc m. \\<Gamma>\\<turnstile> head (f i) \\<rightarrow> head (f (i + 1))\" by fact\n      hence \"\\<forall>i<m. \\<Gamma>\\<turnstile> head (f i) \\<rightarrow> head (f (i + 1))\"\n        by auto\n      hence \"\\<Gamma>\\<turnstile> head (f 0) \\<rightarrow>\\<^sup>*  head (f m)\"\n        by (rule Suc.hyps)\n      also from step [rule_format, of m]\n      have \"\\<Gamma>\\<turnstile> head (f m) \\<rightarrow> head (f (m + 1))\" by simp\n      finally show ?case by simp\n    qed\n    {\n      assume f_k: \"f k = (Seq Skip c\\<^sub>2, s')\"\n      with steps_head\n      have \"\\<Gamma>\\<turnstile>(c\\<^sub>1,s) \\<rightarrow>\\<^sup>* (Skip,s')\"\n        using head_f_0\n        by (simp add: head_def head_com_def)\n      moreover\n      from step [rule_format, of k] f_k\n      obtain \"\\<Gamma>\\<turnstile>(Seq Skip c\\<^sub>2,s') \\<rightarrow> (c\\<^sub>2,s')\" and\n        f_Suc_k: \"f (k + 1) = (c\\<^sub>2,s')\"\n        by (fastforce elim: step.cases intro: step.intros)\n      def g\\<equiv>\"\\<lambda>i. f (i + (k + 1))\"\n      from f_Suc_k\n      have g_0: \"g 0 = (c\\<^sub>2,s')\"\n        by (simp add: g_def)\n      from step\n      have \"\\<forall>i. \\<Gamma>\\<turnstile>g i \\<rightarrow> g (i + 1)\"\n        by (simp add: g_def)\n      with g_0 have \"\\<Gamma>\\<turnstile>(c\\<^sub>2,s') \\<rightarrow> \\<dots>(\\<infinity>)\"\n        by (auto simp add: inf_def)\n      ultimately\n      have ?thesis\n        by auto\n    }\n    moreover\n    {\n      fix x\n      assume s': \"s'=Normal x\" and f_k: \"f k = (Seq Throw c\\<^sub>2, s')\"\n      from step [rule_format, of k] f_k s'\n      obtain \"\\<Gamma>\\<turnstile>(Seq Throw c\\<^sub>2,s') \\<rightarrow> (Throw,s')\" and\n        f_Suc_k: \"f (k + 1) = (Throw,s')\"\n        by (fastforce elim: step_elim_cases intro: step.intros)\n      def g\\<equiv>\"\\<lambda>i. f (i + (k + 1))\"\n      from f_Suc_k\n      have g_0: \"g 0 = (Throw,s')\"\n        by (simp add: g_def)\n      from step\n      have \"\\<forall>i. \\<Gamma>\\<turnstile>g i \\<rightarrow> g (i + 1)\"\n        by (simp add: g_def)\n      with g_0 have \"\\<Gamma>\\<turnstile>(Throw,s') \\<rightarrow> \\<dots>(\\<infinity>)\"\n        by (auto simp add: inf_def)\n      with no_inf_Throw\n      have ?thesis\n        by auto\n    }\n    ultimately \n    show ?thesis\n      by (auto simp add: final_def head_def head_com_def)\n  next\n    case False\n    then have not_fin: \"\\<forall>i. \\<not> final (head (f i))\"\n      by blast\n    have \"\\<forall>i. \\<Gamma>\\<turnstile>head (f i) \\<rightarrow> head (f (i + 1))\"\n    proof \n      fix k\n      from not_fin \n      have \"\\<forall>i<(Suc k). \\<not> final (head (f i))\"\n        by simp\n      \n      from infinite_computation_extract_head_Seq [OF step f_0 this ]\n      show \"\\<Gamma>\\<turnstile> head (f k) \\<rightarrow> head (f (k + 1))\" by simp\n    qed\n    with head_f_0 have \"\\<Gamma>\\<turnstile>(c\\<^sub>1,s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n      by (auto simp add: inf_def)\n    thus ?thesis\n      by simp\n  qed\nqed\n\nlemma split_inf_Catch: \n  assumes inf_comp: \"\\<Gamma>\\<turnstile>(Catch c\\<^sub>1 c\\<^sub>2,s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n  shows \"\\<Gamma>\\<turnstile>(c\\<^sub>1,s) \\<rightarrow> \\<dots>(\\<infinity>) \\<or> \n         (\\<exists>s'. \\<Gamma>\\<turnstile>(c\\<^sub>1,s) \\<rightarrow>\\<^sup>* (Throw,Normal s') \\<and> \\<Gamma>\\<turnstile>(c\\<^sub>2,Normal s') \\<rightarrow> \\<dots>(\\<infinity>))\"\nproof -\n  from inf_comp obtain f where\n    step: \"\\<forall>i::nat. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (i+1)\" and\n    f_0: \"f 0 = (Catch c\\<^sub>1 c\\<^sub>2, s)\"\n    by (auto simp add: inf_def)\n  from f_0 have head_f_0: \"head (f 0) = (c\\<^sub>1,s)\" \n    by (simp add: head_def head_com_def)\n  show ?thesis\n  proof (cases \"\\<exists>i. final (head (f i))\")\n    case True\n    def k\\<equiv>\"(LEAST i. final (head (f i)))\"\n    have less_k: \"\\<forall>i<k. \\<not> final (head (f i))\"\n      apply (intro allI impI)\n      apply (unfold k_def)\n      apply (drule not_less_Least)\n      apply auto\n      done\n    from infinite_computation_extract_head_Catch [OF step f_0 this]\n    obtain step_head: \"\\<forall>i<k. \\<Gamma>\\<turnstile> head (f i) \\<rightarrow> head (f (i + 1))\" and\n           conf: \"\\<forall>i<k. (\\<exists>c' s'. f (i + 1) = (Catch c' c\\<^sub>2, s'))\"\n      by blast \n    from True\n    have final_f_k: \"final (head (f k))\"\n      apply -\n      apply (erule exE)\n      apply (drule LeastI)\n      apply (simp add: k_def)\n      done\n    moreover\n    from f_0 conf [rule_format, of \"k - 1\"]\n    obtain c' s' where f_k: \"f k = (Catch c' c\\<^sub>2,s')\"\n      by (cases k) auto\n    moreover\n    from step_head have steps_head: \"\\<Gamma>\\<turnstile>head (f 0) \\<rightarrow>\\<^sup>* head (f k)\"\n    proof (induct k)\n      case 0 thus ?case by simp\n    next\n      case (Suc m)\n      have step: \"\\<forall>i<Suc m. \\<Gamma>\\<turnstile> head (f i) \\<rightarrow> head (f (i + 1))\" by fact\n      hence \"\\<forall>i<m. \\<Gamma>\\<turnstile> head (f i) \\<rightarrow> head (f (i + 1))\"\n        by auto\n      hence \"\\<Gamma>\\<turnstile> head (f 0) \\<rightarrow>\\<^sup>*  head (f m)\"\n        by (rule Suc.hyps)\n      also from step [rule_format, of m]\n      have \"\\<Gamma>\\<turnstile> head (f m) \\<rightarrow> head (f (m + 1))\" by simp\n      finally show ?case by simp\n    qed\n    {\n      assume f_k: \"f k = (Catch Skip c\\<^sub>2, s')\"\n      with steps_head\n      have \"\\<Gamma>\\<turnstile>(c\\<^sub>1,s) \\<rightarrow>\\<^sup>* (Skip,s')\"\n        using head_f_0\n        by (simp add: head_def head_com_def)\n      moreover\n      from step [rule_format, of k] f_k\n      obtain \"\\<Gamma>\\<turnstile>(Catch Skip c\\<^sub>2,s') \\<rightarrow> (Skip,s')\" and\n        f_Suc_k: \"f (k + 1) = (Skip,s')\"\n        by (fastforce elim: step.cases intro: step.intros)\n      from step [rule_format, of \"k+1\", simplified f_Suc_k]\n      have ?thesis\n        by (rule no_step_final') (auto simp add: final_def)\n    }\n    moreover\n    {\n      fix x\n      assume s': \"s'=Normal x\" and f_k: \"f k = (Catch Throw c\\<^sub>2, s')\"\n      with steps_head\n      have \"\\<Gamma>\\<turnstile>(c\\<^sub>1,s) \\<rightarrow>\\<^sup>* (Throw,s')\"\n        using head_f_0\n        by (simp add: head_def head_com_def)\n      moreover\n      from step [rule_format, of k] f_k s'\n      obtain \"\\<Gamma>\\<turnstile>(Catch Throw c\\<^sub>2,s') \\<rightarrow> (c\\<^sub>2,s')\" and\n        f_Suc_k: \"f (k + 1) = (c\\<^sub>2,s')\"\n        by (fastforce elim: step_elim_cases intro: step.intros)\n      def g\\<equiv>\"\\<lambda>i. f (i + (k + 1))\"\n      from f_Suc_k\n      have g_0: \"g 0 = (c\\<^sub>2,s')\"\n        by (simp add: g_def)\n      from step\n      have \"\\<forall>i. \\<Gamma>\\<turnstile>g i \\<rightarrow> g (i + 1)\"\n        by (simp add: g_def)\n      with g_0 have \"\\<Gamma>\\<turnstile>(c\\<^sub>2,s') \\<rightarrow> \\<dots>(\\<infinity>)\"\n        by (auto simp add: inf_def)\n      ultimately\n      have ?thesis\n        using s'\n        by auto\n    }\n    ultimately \n    show ?thesis\n      by (auto simp add: final_def head_def head_com_def)\n  next\n    case False\n    then have not_fin: \"\\<forall>i. \\<not> final (head (f i))\"\n      by blast\n    have \"\\<forall>i. \\<Gamma>\\<turnstile>head (f i) \\<rightarrow> head (f (i + 1))\"\n    proof \n      fix k\n      from not_fin \n      have \"\\<forall>i<(Suc k). \\<not> final (head (f i))\"\n        by simp\n      \n      from infinite_computation_extract_head_Catch [OF step f_0 this ]\n      show \"\\<Gamma>\\<turnstile> head (f k) \\<rightarrow> head (f (k + 1))\" by simp\n    qed\n    with head_f_0 have \"\\<Gamma>\\<turnstile>(c\\<^sub>1,s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n      by (auto simp add: inf_def)\n    thus ?thesis\n      by simp\n  qed\nqed\n\nlemma Skip_no_step: \"\\<Gamma>\\<turnstile>(Skip,s) \\<rightarrow> cfg \\<Longrightarrow> P\"\n  apply (erule no_step_final')\n  apply (simp add: final_def)\n  done\n\nlemma not_inf_Stuck: \"\\<not> \\<Gamma>\\<turnstile>(c,Stuck) \\<rightarrow> \\<dots>(\\<infinity>)\"\nproof (induct c)\n  case Skip\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Skip, Stuck)\" \n    from f_step [of 0] f_0\n    show False\n      by (auto elim: Skip_no_step)\n  qed\nnext\n  case (Basic g) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Basic g, Stuck)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Spec r) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Spec r, Stuck)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Seq c\\<^sub>1 c\\<^sub>2)\n  show ?case\n  proof \n    assume \"\\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, Stuck) \\<rightarrow> \\<dots>(\\<infinity>)\"\n    from split_inf_Seq [OF this] Seq.hyps\n    show False\n      by (auto dest: steps_Stuck_prop)\n  qed\nnext\n  case (Cond b c\\<^sub>1 c\\<^sub>2) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Cond b c\\<^sub>1 c\\<^sub>2, Stuck)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (While b c) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (While b c, Stuck)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Call p) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Call p, Stuck)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (DynCom d) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (DynCom d, Stuck)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Guard m g c)\n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Guard m g c, Stuck)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case Throw\n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Throw, Stuck)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  show ?case\n  proof \n    assume \"\\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, Stuck) \\<rightarrow> \\<dots>(\\<infinity>)\"\n    from split_inf_Catch [OF this] Catch.hyps\n    show False\n      by (auto dest: steps_Stuck_prop)\n  qed  \nnext \n  case (Await b c)\n  show ?case \n   proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Await b c, Stuck)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nqed\n\nlemma not_inf_Fault: \"\\<not> \\<Gamma>\\<turnstile>(c,Fault x) \\<rightarrow> \\<dots>(\\<infinity>)\"\nproof (induct c)\n  case Skip\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Skip, Fault x)\" \n    from f_step [of 0] f_0\n    show False\n      by (auto elim: Skip_no_step)\n  qed\nnext\n  case (Basic g) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Basic g, Fault x)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Spec r) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Spec r, Fault x)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Seq c\\<^sub>1 c\\<^sub>2)\n  show ?case\n  proof \n    assume \"\\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, Fault x) \\<rightarrow> \\<dots>(\\<infinity>)\"\n    from split_inf_Seq [OF this] Seq.hyps\n    show False\n      by (auto dest: steps_Fault_prop)\n  qed\nnext\n  case (Cond b c\\<^sub>1 c\\<^sub>2) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Cond b c\\<^sub>1 c\\<^sub>2, Fault x)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (While b c) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (While b c, Fault x)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Call p) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Call p, Fault x)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (DynCom d) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (DynCom d, Fault x)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Guard m g c)\n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Guard m g c, Fault x)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case Throw\n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Throw, Fault x)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  show ?case\n  proof \n    assume \"\\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, Fault x) \\<rightarrow> \\<dots>(\\<infinity>)\"\n    from split_inf_Catch [OF this] Catch.hyps\n    show False\n      by (auto dest: steps_Fault_prop)\n  qed  \nnext\n  case (Await b c) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Await b c, Fault x)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nqed\n\nlemma not_inf_Abrupt: \"\\<not> \\<Gamma>\\<turnstile>(c,Abrupt s) \\<rightarrow> \\<dots>(\\<infinity>)\"\nproof (induct c)\n  case Skip\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Skip, Abrupt s)\" \n    from f_step [of 0] f_0\n    show False\n      by (auto elim: Skip_no_step)\n  qed\nnext\n  case (Basic g) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Basic g, Abrupt s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Spec r) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Spec r, Abrupt s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Seq c\\<^sub>1 c\\<^sub>2)\n  show ?case\n  proof \n    assume \"\\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, Abrupt s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n    from split_inf_Seq [OF this] Seq.hyps\n    show False\n      by (auto dest: steps_Abrupt_prop)\n  qed\nnext\n  case (Cond b c\\<^sub>1 c\\<^sub>2) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Cond b c\\<^sub>1 c\\<^sub>2, Abrupt s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (While b c) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (While b c, Abrupt s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Call p) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Call p, Abrupt s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (DynCom d) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (DynCom d, Abrupt s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Guard m g c)\n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Guard m g c, Abrupt s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case Throw\n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Throw, Abrupt s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  show ?case\n  proof \n    assume \"\\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, Abrupt s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n    from split_inf_Catch [OF this] Catch.hyps\n    show False\n      by (auto dest: steps_Abrupt_prop)\n  qed  \ncase (Await b c) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Await b c, Abrupt s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nqed\n\n\ntheorem terminates_impl_no_infinite_computation:\n  assumes termi: \"\\<Gamma>\\<turnstile>c \\<down> s\"\n  shows \"\\<not> \\<Gamma>\\<turnstile>(c,s) \\<rightarrow> \\<dots>(\\<infinity>)\"\nusing termi\nproof (induct)\n  case (Skip s) thus ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Skip, Normal s)\" \n    from f_step [of 0] f_0\n    show False\n      by (auto elim: Skip_no_step)\n  qed\nnext\n  case (Basic g s) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Basic g, Normal s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Spec r s) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Spec r, Normal s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Guard s g c m)\n  have g: \"s \\<in> g\" by fact\n  have hyp: \"\\<not> \\<Gamma>\\<turnstile> (c, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Guard m g c, Normal s)\" \n    from f_step [of 0] f_0  g\n    have \"f 1 = (c,Normal s)\"\n      by (fastforce elim: step_elim_cases)\n    with f_step\n    have \"\\<Gamma>\\<turnstile> (c, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with hyp show False ..\n  qed\nnext\n  case (GuardFault s g m c)\n  have g: \"s \\<notin> g\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Guard m g c, Normal s)\" \n    from g f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Fault c m) \n  thus ?case\n    by (rule not_inf_Fault)\nnext\n  case (Seq c\\<^sub>1 s c\\<^sub>2)\n  show ?case\n  proof \n    assume \"\\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n    from split_inf_Seq [OF this] Seq.hyps\n    show False\n      by (auto intro: steps_Skip_impl_exec)\n  qed\nnext\n  case (CondTrue s b c1 c2)\n  have b: \"s \\<in> b\" by fact\n  have hyp_c1: \"\\<not> \\<Gamma>\\<turnstile> (c1, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Cond b c1 c2, Normal s)\" \n    from b f_step [of 0] f_0\n    have \"f 1 = (c1,Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step\n    have \"\\<Gamma>\\<turnstile> (c1, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with hyp_c1 show False by simp\n  qed    \nnext\n  case (CondFalse s b c2 c1)\n  have b: \"s \\<notin> b\" by fact\n  have hyp_c2: \"\\<not> \\<Gamma>\\<turnstile> (c2, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Cond b c1 c2, Normal s)\" \n    from b f_step [of 0] f_0\n    have \"f 1 = (c2,Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step\n    have \"\\<Gamma>\\<turnstile> (c2, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with hyp_c2 show False by simp\n  qed\nnext    \n  case (WhileTrue s b c)\n  have b: \"s \\<in> b\" by fact\n  have hyp_c: \"\\<not> \\<Gamma>\\<turnstile> (c, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\" by fact\n  have hyp_w: \"\\<forall>s'. \\<Gamma>\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> s' \\<longrightarrow> \n                     \\<Gamma>\\<turnstile>While b c \\<down> s' \\<and> \\<not> \\<Gamma>\\<turnstile> (While b c, s') \\<rightarrow> \\<dots>(\\<infinity>)\" by fact\n  have not_inf_Seq: \"\\<not> \\<Gamma>\\<turnstile> (Seq c (While b c), Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n  proof \n    assume \"\\<Gamma>\\<turnstile> (Seq c (While b c), Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n    from split_inf_Seq [OF this] hyp_c hyp_w show False\n      by (auto intro: steps_Skip_impl_exec)\n  qed\n  show ?case\n  proof \n    assume \"\\<Gamma>\\<turnstile> (While b c, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n    then obtain f where\n      f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\" and\n      f_0: \"f 0 = (While b c, Normal s)\" \n      by (auto simp add: inf_def)\n    from f_step [of 0] f_0 b\n    have \"f 1 = (Seq c (While b c),Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step\n    have \"\\<Gamma>\\<turnstile> (Seq c (While b c), Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with not_inf_Seq show False by simp\n  qed\nnext\n  case (WhileFalse s b c)\n  have b: \"s \\<notin> b\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (While b c, Normal s)\" \n    from b f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Call p bdy s)\n  have bdy: \"\\<Gamma> p = Some bdy\" by fact\n  have hyp: \"\\<not> \\<Gamma>\\<turnstile> (bdy, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Call p, Normal s)\" \n    from bdy f_step [of 0] f_0\n    have \"f 1 = (bdy,Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step\n    have \"\\<Gamma>\\<turnstile> (bdy, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with hyp show False by simp\n  qed    \nnext\n  case (CallUndefined p s)\n  have no_bdy: \"\\<Gamma> p = None\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Call p, Normal s)\" \n    from no_bdy f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Stuck c)\n  show ?case\n    by (rule not_inf_Stuck)\nnext\n  case (DynCom c s)\n  have hyp: \"\\<not> \\<Gamma>\\<turnstile> (c s, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (DynCom c, Normal s)\" \n    from f_step [of 0] f_0\n    have \"f (Suc 0) = (c s, Normal s)\"\n      by (auto elim: step_elim_cases)\n    with f_step have \"\\<Gamma>\\<turnstile> (c s, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with hyp\n    show False by simp\n  qed\nnext (\\<Gamma>,c) \\<propto> clist\n  case (Throw s) thus ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Throw, Normal s)\" \n    from f_step [of 0] f_0\n    show False\n      by (auto elim: step_elim_cases)\n  qed  \nnext\n  case (Abrupt c)\n  show ?case\n    by (rule not_inf_Abrupt)\nnext\n  case (Catch c\\<^sub>1 s c\\<^sub>2)\n  show ?case\n  proof \n    assume \"\\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n    from split_inf_Catch [OF this] Catch.hyps\n    show False\n      by (auto intro: steps_Throw_impl_exec)\n  qed\nnext\n  case (AwaitTrue s b c)\n  have b: \"s \\<in> b\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Await b c, Normal s)\" \n    from b f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nqed\n\n\ndefinition\n termi_call_steps :: \"('s,'p,'f,'e) body \\<Rightarrow> (('s \\<times> 'p) \\<times> ('s \\<times> 'p))set\"\nwhere\n\"termi_call_steps \\<Gamma> =\n {((t,q),(s,p)). \\<Gamma>\\<turnstile>Call p\\<down>Normal s \\<and> \n       (\\<exists>c. \\<Gamma>\\<turnstile>(Call p,Normal s) \\<rightarrow>\\<^sup>+ (c,Normal t) \\<and> redex c = Call q)}\"\n\n\nprimrec subst_redex:: \"('s,'p,'f,'e)com \\<Rightarrow> ('s,'p,'f,'e)com \\<Rightarrow> ('s,'p,'f,'e)com\"\nwhere\n\"subst_redex Skip c = c\" |\n\"subst_redex (Basic f) c = c\" |\n\"subst_redex (Spec r) c = c\" |\n\"subst_redex (Seq c\\<^sub>1 c\\<^sub>2) c  = Seq (subst_redex c\\<^sub>1 c) c\\<^sub>2\" |\n\"subst_redex (Cond b c\\<^sub>1 c\\<^sub>2) c = c\" |\n\"subst_redex (While b c') c = c\" |\n\"subst_redex (Await b c') c = c\" |\n\"subst_redex (Call p) c = c\" |\n\"subst_redex (DynCom d) c = c\" |\n\"subst_redex (Guard f b c') c = c\" |\n\"subst_redex (Throw) c = c\" |\n\"subst_redex (Catch c\\<^sub>1 c\\<^sub>2) c = Catch (subst_redex c\\<^sub>1 c) c\\<^sub>2\"\n\nlemma subst_redex_redex:\n  \"subst_redex c (redex c) = c\"\n  by (induct c) auto\n\nlemma redex_subst_redex: \"redex (subst_redex c r) = redex r\"\n  by (induct c) auto\n  \nlemma step_redex':\n  shows \"\\<Gamma>\\<turnstile>(redex c,s) \\<rightarrow> (r',s') \\<Longrightarrow> \\<Gamma>\\<turnstile>(c,s) \\<rightarrow> (subst_redex c r',s')\"\nby (induct c) (auto intro: step.Seq step.Catch)\n\n\nlemma step_redex:\n  shows \"\\<Gamma>\\<turnstile>(r,s) \\<rightarrow> (r',s') \\<Longrightarrow> \\<Gamma>\\<turnstile>(subst_redex c r,s) \\<rightarrow> (subst_redex c r',s')\"\nby (induct c) (auto intro: step.Seq step.Catch)\n\nlemma steps_redex:\n  assumes steps: \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow>\\<^sup>* (r', s')\"\n  shows \"\\<And>c. \\<Gamma>\\<turnstile>(subst_redex c r,s) \\<rightarrow>\\<^sup>* (subst_redex c r',s')\"\nusing steps\nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl \n  show \"\\<Gamma>\\<turnstile> (subst_redex c r', s') \\<rightarrow>\\<^sup>* (subst_redex c r', s')\"\n    by simp\nnext\n  case (Trans r s r'' s'')\n  have \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow> (r'', s'')\" by fact\n  from step_redex [OF this]\n  have \"\\<Gamma>\\<turnstile> (subst_redex c r, s) \\<rightarrow> (subst_redex c r'', s'')\".\n  also  \n  have \"\\<Gamma>\\<turnstile> (subst_redex c r'', s'') \\<rightarrow>\\<^sup>* (subst_redex c r', s')\" by fact\n  finally show ?case .\nqed\n\nML {*\n  ML_Thms.bind_thm (\"trancl_induct2\", Split_Rule.split_rule @{context}\n    (Rule_Insts.read_instantiate @{context}\n      [(((\"a\", 0), Position.none), \"(aa, ab)\"), (((\"b\", 0), Position.none), \"(ba, bb)\")] []\n      @{thm trancl_induct}));\n*}\n\nlemma steps_redex':\n  assumes steps: \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow>\\<^sup>+ (r', s')\"\n  shows \"\\<And>c. \\<Gamma>\\<turnstile>(subst_redex c r,s) \\<rightarrow>\\<^sup>+ (subst_redex c r',s')\"\nusing steps\nproof (induct rule: tranclp_induct2 [consumes 1,case_names Step Trans])\n  case (Step r' s')\n  have \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow> (r', s')\" by fact\n  then have \"\\<Gamma>\\<turnstile> (subst_redex c r, s) \\<rightarrow> (subst_redex c r', s')\"\n    by (rule step_redex)\n  then show \"\\<Gamma>\\<turnstile> (subst_redex c r, s) \\<rightarrow>\\<^sup>+ (subst_redex c r', s')\"..\nnext\n  case (Trans r' s' r'' s'')\n  have \"\\<Gamma>\\<turnstile> (subst_redex c r, s) \\<rightarrow>\\<^sup>+ (subst_redex c r', s')\" by fact\n  also\n  have \"\\<Gamma>\\<turnstile> (r', s') \\<rightarrow> (r'', s'')\" by fact\n  hence \"\\<Gamma>\\<turnstile> (subst_redex c r', s') \\<rightarrow> (subst_redex c r'', s'')\"\n    by (rule step_redex)\n  finally show \"\\<Gamma>\\<turnstile> (subst_redex c r, s) \\<rightarrow>\\<^sup>+ (subst_redex c r'', s'')\" .\nqed\n\nprimrec seq:: \"(nat \\<Rightarrow> ('s,'p,'f,'e)com) \\<Rightarrow> 'p \\<Rightarrow> nat \\<Rightarrow> ('s,'p,'f,'e)com\"\nwhere\n\"seq c p 0 = Call p\" |\n\"seq c p (Suc i) = subst_redex (seq c p i) (c i)\"\n\n\nlemma renumber':\n  assumes f: \"\\<forall>i. (a,f i) \\<in> r\\<^sup>* \\<and> (f i,f(Suc i)) \\<in> r\" \n  assumes a_b: \"(a,b) \\<in> r\\<^sup>*\" \n  shows \"b = f 0 \\<Longrightarrow> (\\<exists>f. f 0 = a \\<and> (\\<forall>i. (f i, f(Suc i)) \\<in> r))\"\nusing a_b\nproof (induct rule: converse_rtrancl_induct [consumes 1])\n  assume \"b = f 0\"\n  with f show \"\\<exists>f. f 0 = b \\<and> (\\<forall>i. (f i, f (Suc i)) \\<in> r)\"\n    by blast\nnext\n  fix a z\n  assume a_z: \"(a, z) \\<in> r\" and \"(z, b) \\<in> r\\<^sup>*\" \n  assume \"b = f 0 \\<Longrightarrow> \\<exists>f. f 0 = z \\<and> (\\<forall>i. (f i, f (Suc i)) \\<in> r)\"\n         \"b = f 0\"\n  then obtain f where f0: \"f 0 = z\" and seq: \"\\<forall>i. (f i, f (Suc i)) \\<in> r\"\n    by iprover\n  {\n    fix i have \"((\\<lambda>i. case i of 0 \\<Rightarrow> a | Suc i \\<Rightarrow> f i) i, f i) \\<in> r\"\n      using seq a_z f0\n      by (cases i) auto\n  }\n  then\n  show \"\\<exists>f. f 0 = a \\<and> (\\<forall>i. (f i, f (Suc i)) \\<in> r)\"\n    by - (rule exI [where x=\"\\<lambda>i. case i of 0 \\<Rightarrow> a | Suc i \\<Rightarrow> f i\"],simp)\nqed\n\nlemma renumber:\n \"\\<forall>i. (a,f i) \\<in> r\\<^sup>* \\<and> (f i,f(Suc i)) \\<in> r \n \\<Longrightarrow> \\<exists>f. f 0 = a \\<and> (\\<forall>i. (f i, f(Suc i)) \\<in> r)\"\n  by (blast dest:renumber')\n\nlemma lem:\n  \"\\<forall>y. r\\<^sup>+\\<^sup>+ a y \\<longrightarrow> P a \\<longrightarrow> P y \n   \\<Longrightarrow> ((b,a) \\<in> {(y,x). P x \\<and> r x y}\\<^sup>+) = ((b,a) \\<in> {(y,x). P x \\<and> r\\<^sup>+\\<^sup>+ x y})\"\napply(rule iffI)\n apply clarify\n apply(erule trancl_induct)\n  apply blast\n apply(blast intro:tranclp_trans)\napply clarify\napply(erule tranclp_induct)\n apply blast\napply(blast intro:trancl_trans)\ndone\n\ncorollary terminates_impl_no_infinite_trans_computation:\n assumes terminates: \"\\<Gamma>\\<turnstile>c\\<down>s\"\n shows \"\\<not>(\\<exists>f. f 0 = (c,s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow>\\<^sup>+ f(Suc i)))\"\nproof -\n  have \"wf({(y,x). \\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow> y}\\<^sup>+)\"\n  proof (rule wf_trancl)\n    show \"wf {(y, x). \\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow> y}\"\n    proof (simp only: wf_iff_no_infinite_down_chain,clarify,simp)\n      fix f\n      assume \"\\<forall>i. \\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>* f i \\<and> \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n      hence \"\\<exists>f. f (0::nat) = (c,s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i))\"\n        by (rule renumber [to_pred])\n      moreover from terminates_impl_no_infinite_computation [OF terminates]\n      have \"\\<not> (\\<exists>f. f (0::nat) = (c, s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)))\"\n        by (simp add: inf_def)\n      ultimately show False\n        by simp\n    qed\n  qed\n  hence \"\\<not> (\\<exists>f. \\<forall>i. (f (Suc i), f i)\n                 \\<in> {(y, x). \\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow> y}\\<^sup>+)\"\n    by (simp add: wf_iff_no_infinite_down_chain)\n  thus ?thesis\n  proof (rule contrapos_nn)\n    assume \"\\<exists>f. f (0::nat) = (c, s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow>\\<^sup>+ f (Suc i))\"\n    then obtain f where\n      f0: \"f 0 = (c, s)\" and\n      seq: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow>\\<^sup>+ f (Suc i)\"\n      by iprover\n    show \n      \"\\<exists>f. \\<forall>i. (f (Suc i), f i) \\<in> {(y, x). \\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow> y}\\<^sup>+\"\n    proof (rule exI [where x=f],rule allI)\n      fix i\n      show \"(f (Suc i), f i) \\<in> {(y, x). \\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow> y}\\<^sup>+\"\n      proof -   \n        {\n          fix i have \"\\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>* f i\"\n          proof (induct i)\n            case 0 show \"\\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* f 0\"\n              by (simp add: f0)\n          next\n            case (Suc n)\n            have \"\\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* f n\"  by fact\n            with seq show \"\\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* f (Suc n)\"\n              by (blast intro: tranclp_into_rtranclp rtranclp_trans)\n          qed\n        }\n        hence \"\\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>* f i\"\n          by iprover\n        with seq have\n          \"(f (Suc i), f i) \\<in> {(y, x). \\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow>\\<^sup>+ y}\"\n          by clarsimp\n        moreover \n        have \"\\<forall>y. \\<Gamma>\\<turnstile>f i \\<rightarrow>\\<^sup>+ y\\<longrightarrow>\\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* f i\\<longrightarrow>\\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* y\"\n          by (blast intro: tranclp_into_rtranclp rtranclp_trans)\n        ultimately \n        show ?thesis \n          by (subst lem )\n      qed\n    qed\n  qed\nqed\n\ntheorem wf_termi_call_steps: \"wf (termi_call_steps \\<Gamma>)\"\nproof (simp only: termi_call_steps_def wf_iff_no_infinite_down_chain,\n       clarify,simp)\n  fix f\n  assume inf: \"\\<forall>i. (\\<lambda>(t, q) (s, p).\n                \\<Gamma>\\<turnstile>Call p \\<down> Normal s \\<and>\n                (\\<exists>c. \\<Gamma>\\<turnstile> (Call p, Normal s) \\<rightarrow>\\<^sup>+ (c, Normal t) \\<and> redex c = Call q))\n             (f (Suc i)) (f i)\"\n  def s\\<equiv>\"\\<lambda>i::nat. fst (f i)\" \n  def p\\<equiv>\"\\<lambda>i::nat. snd (f i)::'b\"\n  from inf\n  have inf': \"\\<forall>i. \\<Gamma>\\<turnstile>Call (p i) \\<down> Normal (s i) \\<and>\n               (\\<exists>c. \\<Gamma>\\<turnstile> (Call (p i), Normal (s i)) \\<rightarrow>\\<^sup>+ (c, Normal (s (i+1))) \\<and> \n                    redex c = Call (p (i+1)))\"\n    apply -\n    apply (rule allI)\n    apply (erule_tac x=i in allE)\n    apply (auto simp add: s_def p_def)\n    done\n  show False\n  proof -\n    from inf'\n    have \"\\<exists>c. \\<forall>i. \\<Gamma>\\<turnstile>Call (p i) \\<down> Normal (s i) \\<and>\n               \\<Gamma>\\<turnstile> (Call (p i), Normal (s i)) \\<rightarrow>\\<^sup>+ (c i, Normal (s (i+1))) \\<and> \n                    redex (c i) = Call (p (i+1))\"\n      apply -\n      apply (rule choice)\n      by blast\n    then obtain c where\n      termi_c: \"\\<forall>i. \\<Gamma>\\<turnstile>Call (p i) \\<down> Normal (s i)\" and\n      steps_c: \"\\<forall>i. \\<Gamma>\\<turnstile> (Call (p i), Normal (s i)) \\<rightarrow>\\<^sup>+ (c i, Normal (s (i+1)))\" and\n      red_c:   \"\\<forall>i. redex (c i) = Call (p (i+1))\"\n      by auto\n    def g\\<equiv>\"\\<lambda>i. (seq c (p 0) i,Normal (s i)::('a,'c) xstate)\"\n    from red_c [rule_format, of 0]\n    have \"g 0 = (Call (p 0), Normal (s 0))\"\n      by (simp add: g_def)\n    moreover\n    {\n      fix i\n      have \"redex (seq c (p 0) i) = Call (p i)\"\n        by (induct i) (auto simp add: redex_subst_redex red_c)\n      from this [symmetric]\n      have \"subst_redex (seq c (p 0) i) (Call (p i)) = (seq c (p 0) i)\"\n        by (simp add: subst_redex_redex)\n    } note subst_redex_seq = this\n    have \"\\<forall>i. \\<Gamma>\\<turnstile> (g i) \\<rightarrow>\\<^sup>+ (g (i+1))\"\n    proof \n      fix i\n      from steps_c [rule_format, of i]\n      have \"\\<Gamma>\\<turnstile> (Call (p i), Normal (s i)) \\<rightarrow>\\<^sup>+ (c i, Normal (s (i + 1)))\".\n      from steps_redex' [OF this, of \"(seq c (p 0) i)\"]\n      have \"\\<Gamma>\\<turnstile> (subst_redex (seq c (p 0) i) (Call (p i)), Normal (s i)) \\<rightarrow>\\<^sup>+\n                (subst_redex (seq c (p 0) i) (c i), Normal (s (i + 1)))\" .\n      hence \"\\<Gamma>\\<turnstile> (seq c (p 0) i, Normal (s i)) \\<rightarrow>\\<^sup>+ \n                 (seq c (p 0) (i+1), Normal (s (i + 1)))\"\n        by (simp add: subst_redex_seq)\n      thus \"\\<Gamma>\\<turnstile> (g i) \\<rightarrow>\\<^sup>+ (g (i+1))\"\n        by (simp add: g_def)\n    qed\n    moreover\n    from terminates_impl_no_infinite_trans_computation [OF termi_c [rule_format, of 0]]\n    have \"\\<not> (\\<exists>f. f 0 = (Call (p 0), Normal (s 0)) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile> f i \\<rightarrow>\\<^sup>+ f (Suc i)))\" .\n    ultimately show False\n      by auto\n  qed\nqed\n\n\nlemma no_infinite_computation_implies_wf: \n  assumes not_inf: \"\\<not> \\<Gamma>\\<turnstile> (c, s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n  shows \"wf {(c2,c1). \\<Gamma> \\<turnstile> (c,s) \\<rightarrow>\\<^sup>* c1 \\<and> \\<Gamma> \\<turnstile> c1 \\<rightarrow> c2}\"\nproof (simp only: wf_iff_no_infinite_down_chain,clarify, simp)\n  fix f\n  assume \"\\<forall>i. \\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* f i \\<and> \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n  hence \"\\<exists>f. f 0 = (c, s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i))\"\n    by (rule renumber [to_pred])\n  moreover from not_inf\n  have \"\\<not> (\\<exists>f. f 0 = (c, s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)))\"\n    by (simp add: inf_def)\n  ultimately show False\n    by simp\nqed\n\nlemma not_final_Stuck_step: \"\\<not> final (c,Stuck) \\<Longrightarrow> \\<exists>c' s'. \\<Gamma>\\<turnstile> (c, Stuck) \\<rightarrow> (c',s')\"\nby (induct c) (fastforce intro: step.intros simp add: final_def)+\n\nlemma not_final_Abrupt_step: \n  \"\\<not> final (c,Abrupt s) \\<Longrightarrow> \\<exists>c' s'. \\<Gamma>\\<turnstile> (c, Abrupt s) \\<rightarrow> (c',s')\"\nby (induct c) (fastforce intro: step.intros simp add: final_def)+\n\nlemma not_final_Fault_step: \n  \"\\<not> final (c,Fault f) \\<Longrightarrow> \\<exists>c' s'. \\<Gamma>\\<turnstile> (c, Fault f) \\<rightarrow> (c',s')\"\nby (induct c) (fastforce intro: step.intros simp add: final_def)+\n\nlemma not_final_Normal_step: \n  \"\\<not> final (c,Normal s) \\<and> ((\\<exists>b c1. redex c = Await b c1) \\<longrightarrow> \\<Gamma>\\<turnstile>c \\<down> Normal s) \\<Longrightarrow> \\<exists>c' s'. \\<Gamma>\\<turnstile> (c, Normal s) \\<rightarrow> (c',s')\"\nproof (induct c) \n  case Skip thus ?case by (simp add: final_def)\nnext\n  case Basic thus ?case by (meson step.Basic)\nnext\n  case (Spec r)\n  thus ?case by (meson step.Spec step.SpecStuck)    \nnext\n  case (Seq c\\<^sub>1 c\\<^sub>2)\n  thus ?case by (metis SeqSkip SeqThrow final_def fst_conv redex.simps(4) step.Seq terminates_Normal_elim_cases(5))\nnext\n  case (Cond b c1 c2)\n  show ?case\n    by (cases \"s \\<in> b\") (fastforce intro: step.intros)+\nnext\n  case (While b c)\n  show ?case\n    by (cases \"s \\<in> b\") (fastforce intro: step.intros)+\nnext\n  case (Call p)\n  show ?case\n  by (cases \"\\<Gamma> p\") (fastforce intro: step.intros)+\nnext\n  case DynCom thus ?case by (fastforce intro: step.intros)\nnext\n  case (Guard f g c)\n  show ?case\n    by (cases \"s \\<in> g\") (fastforce intro: step.intros)+\nnext\n  case Throw\n  thus ?case by (fastforce intro: step.intros simp add: final_def)\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  thus ?case\n    by (cases \"final (c\\<^sub>1,Normal s)\") (fastforce intro: step.intros elim: terminates_Normal_elim_cases simp add: final_def)+\nnext\n  case (Await b c) \n  then obtain ba c1 where x:\"(\\<exists>ba c1. redex (Await b c) = Await ba c1)\" by simp\n  then have \"\\<Gamma>\\<turnstile>Await b c \\<down> Normal s\" using x Await.prems by blast \n  also have \"s \\<in> b\" by (meson `\\<Gamma>\\<turnstile>Await b c \\<down> Normal s` terminates_Normal_elim_cases(12))\n  moreover have \"\\<exists>t. \\<Gamma>\\<turnstile>\\<langle>c, Normal s\\<rangle> \\<Rightarrow> t\" by (meson calculation terminates_Normal_elim_cases(12) terminates_implies_exec) \n  ultimately show ?case using AwaitAbrupt  step.Await by fastforce\nqed\n\nlemma final_termi:\n\"final (c,s) \\<Longrightarrow> \\<Gamma>\\<turnstile>c\\<down>s\"\n  by (cases s) (auto simp add: final_def terminates.intros)\n\nlemma split_computation: \nassumes steps: \"\\<Gamma>\\<turnstile> (c, s) \\<rightarrow>\\<^sup>* (c\\<^sub>f, s\\<^sub>f)\"\nassumes not_final: \"\\<not> final (c,s)\"\nassumes final: \"final (c\\<^sub>f,s\\<^sub>f)\"\nshows \"\\<exists>c' s'. \\<Gamma>\\<turnstile> (c, s) \\<rightarrow> (c',s') \\<and> \\<Gamma>\\<turnstile> (c', s') \\<rightarrow>\\<^sup>* (c\\<^sub>f, s\\<^sub>f)\"\nusing steps not_final final\nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl thus ?case by simp\nnext\n  case (Trans c s c' s')\n  thus ?case by auto\nqed\n\n\nlemma wf_implies_termi_reach_step_case:\nassumes hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (c, Normal s) \\<rightarrow> (c', s')\\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" and\n        hyp1:\"(\\<And>b c1. (redex c = Await b c1) \\<Longrightarrow> \\<Gamma>\\<turnstile>c1 \\<down> Normal s \\<and> s\\<in>b)\"\nshows \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\nusing hyp hyp1\nproof (induct c)\n  case Skip show ?case by (fastforce intro: terminates.intros)\nnext\n  case Basic show ?case by (fastforce intro: terminates.intros)\nnext\n  case (Spec r)\n  show ?case\n    by (cases \"\\<exists>t. (s,t)\\<in>r\") (fastforce intro: terminates.intros)+\nnext\n  case (Seq c\\<^sub>1 c\\<^sub>2)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (c', s') \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\"\nusing Seq.prems by blast \n   have hyp': \"(\\<And>b c1. (redex (Seq c\\<^sub>1 c\\<^sub>2)  = Await b c1) \\<Longrightarrow> \\<Gamma>\\<turnstile>c1 \\<down> Normal s \\<and> s\\<in>b)\" by fact \n  show ?case \n  proof (rule terminates.Seq)\n    {\n      fix c' s'\n      assume step_c\\<^sub>1: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow> (c', s')\"      \n      assume red: \"(\\<And>b c1. (redex c\\<^sub>1  = Await b c1) \\<Longrightarrow> \\<Gamma>\\<turnstile>c1 \\<down> Normal s \\<and> s\\<in>b)\"\n      have \"\\<Gamma>\\<turnstile>c' \\<down> s'\"\n      proof -\n        from step_c\\<^sub>1\n        have \"\\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (Seq c' c\\<^sub>2, s')\"\n          by (simp add: step.Seq)          \n        from hyp [OF this]\n        have \"\\<Gamma>\\<turnstile>Seq c' c\\<^sub>2 \\<down> s'\".\n        thus \"\\<Gamma>\\<turnstile>c'\\<down> s'\"\n          by cases auto\n      qed\n    } \n    from Seq.hyps (1) [OF this]\n    show \"\\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s\" using terminates_Skip' by (simp add: hyp') \n  next\n    show \"\\<forall>s'. \\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> s' \\<longrightarrow> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\"\n    proof (intro allI impI)\n      fix s'\n      assume exec_c\\<^sub>1: \"\\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> s'\"\n      show \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\"\n      proof (cases \"final (c\\<^sub>1,Normal s)\")\n        case True\n        hence \"c\\<^sub>1=Skip \\<or> c\\<^sub>1=Throw\"\n          by (simp add: final_def)\n        thus ?thesis\n        proof\n          assume Skip: \"c\\<^sub>1=Skip\"\n          have s1:\"\\<Gamma>\\<turnstile>(Seq Skip c\\<^sub>2,Normal s) \\<rightarrow> (c\\<^sub>2,Normal s) \\<and>\\<not> (\\<exists>b c1. Seq c\\<^sub>1 c\\<^sub>2 = Await b c1)\"\n            by (simp add: step.SeqSkip)          \n          from hyp \n          have \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s\" using local.Skip s1 by blast \n          moreover from exec_c\\<^sub>1 Skip\n          have \"s'=Normal s\"\n            by (auto elim: exec_Normal_elim_cases)\n          ultimately show ?thesis by simp\n        next\n          assume Throw: \"c\\<^sub>1=Throw\"\n          with exec_c\\<^sub>1 have \"s'=Abrupt s\"\n            by (auto elim: exec_Normal_elim_cases)\n          thus ?thesis\n            by auto\n        qed\n      next\n        case False        \n        from exec_impl_steps [OF exec_c\\<^sub>1]\n        obtain c\\<^sub>f t where \n          steps_c\\<^sub>1: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow>\\<^sup>* (c\\<^sub>f, t)\" and\n          fin:\"(case s' of\n                 Abrupt x \\<Rightarrow> c\\<^sub>f = Throw \\<and> t = Normal x\n                | _ \\<Rightarrow> c\\<^sub>f = Skip \\<and> t = s')\"\n          by (fastforce split: xstate.splits)\n        with fin have final: \"final (c\\<^sub>f,t)\"\n          by (cases s') (auto simp add: final_def)\n        from split_computation [OF steps_c\\<^sub>1 False this]\n        obtain c'' s'' where\n          first: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow> (c'', s'')\" and\n          rest: \"\\<Gamma>\\<turnstile> (c'', s'') \\<rightarrow>\\<^sup>* (c\\<^sub>f, t)\" \n          by blast\n        from step.Seq [OF first]\n        have \"\\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (Seq c'' c\\<^sub>2, s'')\" by auto\n        from hyp [OF this]\n        have termi_s'': \"\\<Gamma>\\<turnstile>Seq c'' c\\<^sub>2 \\<down> s''\".\n        show ?thesis\n        proof (cases s'')\n          case (Normal x)\n          from termi_s'' [simplified Normal]\n          have termi_c\\<^sub>2: \"\\<forall>t. \\<Gamma>\\<turnstile> \\<langle>c'',Normal x\\<rangle> \\<Rightarrow> t \\<longrightarrow> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> t\"\n            by cases\n          show ?thesis\n          proof (cases \"\\<exists>x'. s'=Abrupt x'\")\n            case False\n            with fin obtain \"c\\<^sub>f=Skip\" \"t=s'\"\n              by (cases s') auto\n            from steps_Skip_impl_exec [OF rest [simplified this]] Normal\n            have \"\\<Gamma>\\<turnstile> \\<langle>c'',Normal x\\<rangle> \\<Rightarrow> s'\"\n              by simp\n            from termi_c\\<^sub>2 [rule_format, OF this]\n            show \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\" .\n          next\n            case True\n            with fin obtain x' where s': \"s'=Abrupt x'\" and \"c\\<^sub>f=Throw\" \"t=Normal x'\"\n              by auto\n            from steps_Throw_impl_exec [OF rest [simplified this]] Normal \n            have \"\\<Gamma>\\<turnstile> \\<langle>c'',Normal x\\<rangle> \\<Rightarrow> Abrupt x'\"\n              by simp\n            from termi_c\\<^sub>2 [rule_format, OF this] s'\n            show \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\" by simp\n           qed\n        next\n          case (Abrupt x)\n          from steps_Abrupt_prop [OF rest this]\n          have \"t=Abrupt x\" by simp\n          with fin have \"s'=Abrupt x\"\n            by (cases s') auto\n          thus \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\" \n            by auto\n        next\n          case (Fault f)\n          from steps_Fault_prop [OF rest this]\n          have \"t=Fault f\" by simp\n          with fin have \"s'=Fault f\"\n            by (cases s') auto\n          thus \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\" \n            by auto\n        next\n          case Stuck\n          from steps_Stuck_prop [OF rest this]\n          have \"t=Stuck\" by simp\n          with fin have \"s'=Stuck\"\n            by (cases s') auto\n          thus \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\" \n            by auto\n        qed\n      qed\n    qed\n  qed\nnext\n  case (Cond b c\\<^sub>1 c\\<^sub>2)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Cond b c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (c', s') \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\"\nby (simp add: Cond.prems(1)) \n  show ?case\n  proof (cases \"s\\<in>b\") \n    case True\n    then have \"\\<Gamma>\\<turnstile> (Cond b c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (c\\<^sub>1, Normal s) \"\n     by (simp add: step.CondTrue)     \n    from hyp [OF this] have \"\\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s\".\n    with True show ?thesis\n      by (auto intro: terminates.intros)\n  next\n    case False\n    then have \"\\<Gamma>\\<turnstile> (Cond b c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (c\\<^sub>2, Normal s)\"\n      by (simp add: step.CondFalse)\n    from hyp [OF this] have \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s\".\n    with False show ?thesis\n      by (auto intro: terminates.intros)\n  qed\nnext\n  case (While b c)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (While b c, Normal s) \\<rightarrow> (c', s')   \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by fact\n  show ?case\n  proof (cases \"s\\<in>b\") \n    case True\n    then have \"\\<Gamma>\\<turnstile> (While b c, Normal s) \\<rightarrow> (Seq c (While b c), Normal s)\"\n      by (simp add: step.WhileTrue)\n    from hyp [OF this] have \"\\<Gamma>\\<turnstile>(Seq c (While b c)) \\<down> Normal s\".\n    with True show ?thesis\n      by (auto elim: terminates_Normal_elim_cases intro: terminates.intros)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates.intros)\n  qed\nnext\n  case (Call p)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Call p, Normal s) \\<rightarrow> (c', s')  \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by (simp add: Call.prems)\n  show ?case\n  proof (cases \"\\<Gamma> p\")\n    case None\n    thus ?thesis\n      by (auto intro: terminates.intros)\n  next\n    case (Some bdy)\n    then have \"\\<Gamma>\\<turnstile> (Call p, Normal s) \\<rightarrow> (bdy, Normal s)\"\n      by (simp add: step.Call)\n    from hyp [OF this] have \"\\<Gamma>\\<turnstile>bdy \\<down> Normal s\".\n    with Some show ?thesis\n      by (auto intro: terminates.intros)\n  qed\nnext\n  case (DynCom c)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (DynCom c, Normal s) \\<rightarrow> (c', s')  \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by fact\n  have \"\\<Gamma>\\<turnstile> (DynCom c, Normal s) \\<rightarrow> (c s, Normal s)\"\n    by (simp add: step.DynCom)\n  from hyp [OF this] have \"\\<Gamma>\\<turnstile>c s \\<down> Normal s\".\n  then show ?case\n    by (auto intro: terminates.intros)\nnext\n  case (Guard f g c)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Guard f g c, Normal s) \\<rightarrow> (c', s')   \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by fact\n  show ?case\n  proof (cases \"s\\<in>g\")\n    case True\n    then have \"\\<Gamma>\\<turnstile> (Guard f g c, Normal s) \\<rightarrow> (c, Normal s) \"\n      by (simp add: step.Guard) thm step.Guard\n    from hyp [OF this] have \"\\<Gamma>\\<turnstile>c\\<down> Normal s\".\n    with True show ?thesis\n      by (auto intro: terminates.intros)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates.intros)\n  qed\nnext \n  case Throw show ?case by (auto intro: terminates.intros)\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (c', s')   \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by fact\n  have hyp': \"(\\<And>b c1. (redex (Catch c\\<^sub>1 c\\<^sub>2) = Await b c1) \\<Longrightarrow> \\<Gamma>\\<turnstile>c1 \\<down> Normal s \\<and> s\\<in>b)\" by fact\n  show ?case\n  proof (rule terminates.Catch)\n    {\n      fix c' s'\n      assume step_c\\<^sub>1: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow> (c', s')\"\n      assume red: \"(\\<And>b c1. (redex c\\<^sub>1  = Await b c1) \\<Longrightarrow> \\<Gamma>\\<turnstile>c1 \\<down> Normal s \\<and> s\\<in>b)\"\n      have \"\\<Gamma>\\<turnstile>c' \\<down> s'\"\n      proof -\n        from step_c\\<^sub>1\n        have \"\\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (Catch c' c\\<^sub>2, s') \"\n          by (simp add: step.Catch)\n        from hyp [OF this]\n        have \"\\<Gamma>\\<turnstile>Catch c' c\\<^sub>2 \\<down> s'\".\n        thus \"\\<Gamma>\\<turnstile>c'\\<down> s'\"\n          by cases auto\n      qed\n    } \n    from Catch.hyps (1) [OF this]\n    show \"\\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s\" using terminates_Skip' by (simp add: hyp')\n  next  \n    show \"\\<forall>s'. \\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Abrupt s' \\<longrightarrow> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s'\"\n    proof (intro allI impI)\n      fix s'\n      assume exec_c\\<^sub>1: \"\\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Abrupt s'\"\n      show \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s'\"\n      proof (cases \"final (c\\<^sub>1,Normal s)\")\n        case True\n        with exec_c\\<^sub>1\n        have Throw: \"c\\<^sub>1=Throw\"\n          by (auto simp add: final_def elim: exec_Normal_elim_cases)\n        have s1: \"\\<Gamma>\\<turnstile>(Catch Throw c\\<^sub>2,Normal s) \\<rightarrow> (c\\<^sub>2,Normal s)\"\n          by (simp add: step.CatchThrow)\n        from hyp \n        have \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s\" using local.Throw s1 by blast \n        moreover from exec_c\\<^sub>1 Throw\n        have \"s'=s\"\n          by (auto elim: exec_Normal_elim_cases)\n        ultimately show ?thesis by simp\n      next\n        case False\n        from exec_impl_steps [OF exec_c\\<^sub>1]\n        obtain c\\<^sub>f t where \n          steps_c\\<^sub>1: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow>\\<^sup>* (Throw, Normal s')\" \n          by (fastforce split: xstate.splits)\n        from split_computation [OF steps_c\\<^sub>1 False]\n        obtain c'' s'' where\n          first: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow> (c'', s'')\" and\n          rest: \"\\<Gamma>\\<turnstile> (c'', s'') \\<rightarrow>\\<^sup>* (Throw, Normal s')\" \n          by (auto simp add: final_def)\n        from step.Catch [OF first]\n        have \"\\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (Catch c'' c\\<^sub>2, s'')\" by auto\n        from hyp [OF this] \n        have \"\\<Gamma>\\<turnstile>Catch c'' c\\<^sub>2 \\<down> s''\".\n        moreover\n        from steps_Throw_impl_exec [OF rest]\n        have \"\\<Gamma>\\<turnstile> \\<langle>c'',s''\\<rangle> \\<Rightarrow> Abrupt s'\".\n        moreover\n        from rest obtain x where \"s''=Normal x\"\n          by (cases s'')\n             (auto dest: steps_Fault_prop steps_Abrupt_prop steps_Stuck_prop)\n        ultimately show ?thesis\n          by (fastforce elim: terminates_elim_cases)\n      qed\n    qed\n  qed\nnext\n  case (Await b c) \n  have hyp':\"\\<And>ba c1. redex (Await b c) = Await ba c1 \\<Longrightarrow> \\<Gamma>\\<turnstile>c1 \\<down> Normal s \\<and> s \\<in> ba\" by fact \n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Await b c, Normal s) \\<rightarrow> (c', s') \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by (simp add: final_termi step_await_final1)\n  have red:\"redex (Await b c)  = Await b c\" by auto  \n  then have \"\\<And>b1 c1. (redex (Await b c)  = Await b1 c1) \\<Longrightarrow> b1=b \\<and> c1 = c\" by simp\n  then have \" \\<Gamma>\\<turnstile>c \\<down> Normal s \\<and> s \\<in> b\" by (simp add: Await.prems(2))\n  show ?case\n  by (simp add: `\\<Gamma>\\<turnstile>c \\<down> Normal s \\<and> s \\<in> b` terminates.AwaitTrue)      \nqed\n\n\nlemma wf_implies_termi_reach_step_case':\nassumes hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (c, Normal s) \\<rightarrow> (c', s')\\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" and\n        hyp1:\"~(\\<exists>b c1. redex c = Await b c1)\"\nshows \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\nusing hyp hyp1\nproof (induct c)\n  case Skip show ?case by (fastforce intro: terminates.intros)\nnext\n  case Basic show ?case by (fastforce intro: terminates.intros)\nnext\n  case (Spec r)\n  show ?case\n    by (cases \"\\<exists>t. (s,t)\\<in>r\") (fastforce intro: terminates.intros)+\nnext\n  case (Seq c\\<^sub>1 c\\<^sub>2)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (c', s') \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\"\nusing Seq.prems by blast\n  have hyp': \"~(\\<exists>b c1. redex (Seq c\\<^sub>1 c\\<^sub>2) = Await b c1)\" by fact\n  show ?case \n  proof (rule terminates.Seq)\n    {\n      fix c' s'\n      assume step_c\\<^sub>1: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow> (c', s')\"\n      assume red:  \"~(\\<exists>b c1. redex c\\<^sub>1 = Await b c1)\"      \n      have \"\\<Gamma>\\<turnstile>c' \\<down> s'\"\n      proof -\n        from step_c\\<^sub>1\n        have \"\\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (Seq c' c\\<^sub>2, s')\"\n          by (simp add: step.Seq)          \n        from hyp [OF this]\n        have \"\\<Gamma>\\<turnstile>Seq c' c\\<^sub>2 \\<down> s'\".\n        thus \"\\<Gamma>\\<turnstile>c'\\<down> s'\"\n          by cases auto\n      qed\n    } \n    from Seq.hyps (1) [OF this]\n    show \"\\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s\"using hyp' by force \n  next\n    show \"\\<forall>s'. \\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> s' \\<longrightarrow> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\"\n    proof (intro allI impI)\n      fix s'\n      assume exec_c\\<^sub>1: \"\\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> s'\"\n      show \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\"\n      proof (cases \"final (c\\<^sub>1,Normal s)\")\n        case True\n        hence \"c\\<^sub>1=Skip \\<or> c\\<^sub>1=Throw\"\n          by (simp add: final_def)\n        thus ?thesis\n        proof\n          assume Skip: \"c\\<^sub>1=Skip\"\n          have s1:\"\\<Gamma>\\<turnstile>(Seq Skip c\\<^sub>2,Normal s) \\<rightarrow> (c\\<^sub>2,Normal s) \\<and>\\<not> (\\<exists>b c1. Seq c\\<^sub>1 c\\<^sub>2 = Await b c1)\"\n            by (simp add: step.SeqSkip)          \n          from hyp \n          have \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s\" using local.Skip s1 by blast \n          moreover from exec_c\\<^sub>1 Skip\n          have \"s'=Normal s\"\n            by (auto elim: exec_Normal_elim_cases)\n          ultimately show ?thesis by simp\n        next\n          assume Throw: \"c\\<^sub>1=Throw\"\n          with exec_c\\<^sub>1 have \"s'=Abrupt s\"\n            by (auto elim: exec_Normal_elim_cases)\n          thus ?thesis\n            by auto\n        qed\n      next\n        case False        \n        from exec_impl_steps [OF exec_c\\<^sub>1]\n        obtain c\\<^sub>f t where \n          steps_c\\<^sub>1: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow>\\<^sup>* (c\\<^sub>f, t)\" and\n          fin:\"(case s' of\n                 Abrupt x \\<Rightarrow> c\\<^sub>f = Throw \\<and> t = Normal x\n                | _ \\<Rightarrow> c\\<^sub>f = Skip \\<and> t = s')\"\n          by (fastforce split: xstate.splits)\n        with fin have final: \"final (c\\<^sub>f,t)\"\n          by (cases s') (auto simp add: final_def)\n        from split_computation [OF steps_c\\<^sub>1 False this]\n        obtain c'' s'' where\n          first: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow> (c'', s'')\" and\n          rest: \"\\<Gamma>\\<turnstile> (c'', s'') \\<rightarrow>\\<^sup>* (c\\<^sub>f, t)\" \n          by blast\n        from step.Seq [OF first]\n        have \"\\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (Seq c'' c\\<^sub>2, s'')\" by auto\n        from hyp [OF this]\n        have termi_s'': \"\\<Gamma>\\<turnstile>Seq c'' c\\<^sub>2 \\<down> s''\".\n        show ?thesis\n        proof (cases s'')\n          case (Normal x)\n          from termi_s'' [simplified Normal]\n          have termi_c\\<^sub>2: \"\\<forall>t. \\<Gamma>\\<turnstile> \\<langle>c'',Normal x\\<rangle> \\<Rightarrow> t \\<longrightarrow> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> t\"\n            by cases\n          show ?thesis\n          proof (cases \"\\<exists>x'. s'=Abrupt x'\")\n            case False\n            with fin obtain \"c\\<^sub>f=Skip\" \"t=s'\"\n              by (cases s') auto\n            from steps_Skip_impl_exec [OF rest [simplified this]] Normal\n            have \"\\<Gamma>\\<turnstile> \\<langle>c'',Normal x\\<rangle> \\<Rightarrow> s'\"\n              by simp\n            from termi_c\\<^sub>2 [rule_format, OF this]\n            show \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\" .\n          next\n            case True\n            with fin obtain x' where s': \"s'=Abrupt x'\" and \"c\\<^sub>f=Throw\" \"t=Normal x'\"\n              by auto\n            from steps_Throw_impl_exec [OF rest [simplified this]] Normal \n            have \"\\<Gamma>\\<turnstile> \\<langle>c'',Normal x\\<rangle> \\<Rightarrow> Abrupt x'\"\n              by simp\n            from termi_c\\<^sub>2 [rule_format, OF this] s'\n            show \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\" by simp\n           qed\n        next\n          case (Abrupt x)\n          from steps_Abrupt_prop [OF rest this]\n          have \"t=Abrupt x\" by simp\n          with fin have \"s'=Abrupt x\"\n            by (cases s') auto\n          thus \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\" \n            by auto\n        next\n          case (Fault f)\n          from steps_Fault_prop [OF rest this]\n          have \"t=Fault f\" by simp\n          with fin have \"s'=Fault f\"\n            by (cases s') auto\n          thus \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\" \n            by auto\n        next\n          case Stuck\n          from steps_Stuck_prop [OF rest this]\n          have \"t=Stuck\" by simp\n          with fin have \"s'=Stuck\"\n            by (cases s') auto\n          thus \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\" \n            by auto\n        qed\n      qed\n    qed\n  qed\nnext\n  case (Cond b c\\<^sub>1 c\\<^sub>2)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Cond b c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (c', s') \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\"\nby (simp add: Cond.prems(1)) \n  show ?case\n  proof (cases \"s\\<in>b\") \n    case True\n    then have \"\\<Gamma>\\<turnstile> (Cond b c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (c\\<^sub>1, Normal s) \"\n     by (simp add: step.CondTrue)     \n    from hyp [OF this] have \"\\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s\".\n    with True show ?thesis\n      by (auto intro: terminates.intros)\n  next\n    case False\n    then have \"\\<Gamma>\\<turnstile> (Cond b c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (c\\<^sub>2, Normal s)\"\n      by (simp add: step.CondFalse)\n    from hyp [OF this] have \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s\".\n    with False show ?thesis\n      by (auto intro: terminates.intros)\n  qed\nnext\n  case (While b c)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (While b c, Normal s) \\<rightarrow> (c', s')   \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by fact\n  show ?case\n  proof (cases \"s\\<in>b\") \n    case True\n    then have \"\\<Gamma>\\<turnstile> (While b c, Normal s) \\<rightarrow> (Seq c (While b c), Normal s)\"\n      by (simp add: step.WhileTrue)\n    from hyp [OF this] have \"\\<Gamma>\\<turnstile>(Seq c (While b c)) \\<down> Normal s\".\n    with True show ?thesis\n      by (auto elim: terminates_Normal_elim_cases intro: terminates.intros)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates.intros)\n  qed\nnext\n  case (Call p)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Call p, Normal s) \\<rightarrow> (c', s')  \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by (simp add: Call.prems)\n  show ?case\n  proof (cases \"\\<Gamma> p\")\n    case None\n    thus ?thesis\n      by (auto intro: terminates.intros)\n  next\n    case (Some bdy)\n    then have \"\\<Gamma>\\<turnstile> (Call p, Normal s) \\<rightarrow> (bdy, Normal s)\"\n      by (simp add: step.Call)\n    from hyp [OF this] have \"\\<Gamma>\\<turnstile>bdy \\<down> Normal s\".\n    with Some show ?thesis\n      by (auto intro: terminates.intros)\n  qed\nnext\n  case (DynCom c)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (DynCom c, Normal s) \\<rightarrow> (c', s')  \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by fact\n  have \"\\<Gamma>\\<turnstile> (DynCom c, Normal s) \\<rightarrow> (c s, Normal s)\"\n    by (simp add: step.DynCom)\n  from hyp [OF this] have \"\\<Gamma>\\<turnstile>c s \\<down> Normal s\".\n  then show ?case\n    by (auto intro: terminates.intros)\nnext\n  case (Guard f g c)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Guard f g c, Normal s) \\<rightarrow> (c', s')   \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by fact\n  show ?case\n  proof (cases \"s\\<in>g\")\n    case True\n    then have \"\\<Gamma>\\<turnstile> (Guard f g c, Normal s) \\<rightarrow> (c, Normal s) \"\n      by (simp add: step.Guard) thm step.Guard\n    from hyp [OF this] have \"\\<Gamma>\\<turnstile>c\\<down> Normal s\".\n    with True show ?thesis\n      by (auto intro: terminates.intros)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates.intros)\n  qed\nnext \n  case Throw show ?case by (auto intro: terminates.intros)\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (c', s')   \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by fact\n  have hyp': \"~(\\<exists>b c1. redex (Catch c\\<^sub>1 c\\<^sub>2) = Await b c1)\" by fact\n  show ?case\n  proof (rule terminates.Catch)\n    {\n      fix c' s'\n      assume step_c\\<^sub>1: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow> (c', s')\"\n      assume red: \"~(\\<exists>b c1. redex c\\<^sub>1  = Await b c1)\"\n      have \"\\<Gamma>\\<turnstile>c' \\<down> s'\"\n      proof -\n        from step_c\\<^sub>1\n        have \"\\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (Catch c' c\\<^sub>2, s') \"\n          by (simp add: step.Catch)\n        from hyp [OF this]\n        have \"\\<Gamma>\\<turnstile>Catch c' c\\<^sub>2 \\<down> s'\".\n        thus \"\\<Gamma>\\<turnstile>c'\\<down> s'\"\n          by cases auto\n      qed\n    } \n    from Catch.hyps (1) [OF this]\n    show \"\\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s\" using hyp' by force\n  next  \n    show \"\\<forall>s'. \\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Abrupt s' \\<longrightarrow> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s'\"\n    proof (intro allI impI)\n      fix s'\n      assume exec_c\\<^sub>1: \"\\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Abrupt s'\"\n      show \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s'\"\n      proof (cases \"final (c\\<^sub>1,Normal s)\")\n        case True\n        with exec_c\\<^sub>1\n        have Throw: \"c\\<^sub>1=Throw\"\n          by (auto simp add: final_def elim: exec_Normal_elim_cases)\n        have s1: \"\\<Gamma>\\<turnstile>(Catch Throw c\\<^sub>2,Normal s) \\<rightarrow> (c\\<^sub>2,Normal s)\"\n          by (simp add: step.CatchThrow)\n        from hyp \n        have \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s\" using local.Throw s1 by blast \n        moreover from exec_c\\<^sub>1 Throw\n        have \"s'=s\"\n          by (auto elim: exec_Normal_elim_cases)\n        ultimately show ?thesis by simp\n      next\n        case False\n        from exec_impl_steps [OF exec_c\\<^sub>1]\n        obtain c\\<^sub>f t where \n          steps_c\\<^sub>1: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow>\\<^sup>* (Throw, Normal s')\" \n          by (fastforce split: xstate.splits)\n        from split_computation [OF steps_c\\<^sub>1 False]\n        obtain c'' s'' where\n          first: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow> (c'', s'')\" and\n          rest: \"\\<Gamma>\\<turnstile> (c'', s'') \\<rightarrow>\\<^sup>* (Throw, Normal s')\" \n          by (auto simp add: final_def)\n        from step.Catch [OF first]\n        have \"\\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (Catch c'' c\\<^sub>2, s'')\" by auto\n        from hyp [OF this] \n        have \"\\<Gamma>\\<turnstile>Catch c'' c\\<^sub>2 \\<down> s''\".\n        moreover\n        from steps_Throw_impl_exec [OF rest]\n        have \"\\<Gamma>\\<turnstile> \\<langle>c'',s''\\<rangle> \\<Rightarrow> Abrupt s'\".\n        moreover\n        from rest obtain x where \"s''=Normal x\"\n          by (cases s'')\n             (auto dest: steps_Fault_prop steps_Abrupt_prop steps_Stuck_prop)\n        ultimately show ?thesis\n          by (fastforce elim: terminates_elim_cases)\n      qed\n    qed\n  qed\nnext\n  case (Await b c)       \n  show ?case\n  using Await.prems(2) by auto   \nqed\n\n\nlemma Await_finish:\"\\<And>c2 s2 b c. \\<Gamma>\\<turnstile> (Await b c, s1) \\<rightarrow> (c2, s2) \\<Longrightarrow> \\<Gamma>\\<turnstile>c2 \\<down> s2\"\nby (metis Abrupt Fault Stuck final_termi step_await_final1 step_preserves_termination xstate.exhaust)\n\n                                                            \nlemma wf_implies_termi_reach:\nassumes wf: \"wf {(cfg2,cfg1). \\<Gamma> \\<turnstile> (c,s) \\<rightarrow>\\<^sup>* cfg1 \\<and> \\<Gamma> \\<turnstile> cfg1 \\<rightarrow> cfg2}\"\nshows \"\\<And>c1 s1. \\<lbrakk>\\<Gamma> \\<turnstile> (c,s) \\<rightarrow>\\<^sup>* cfg1;  cfg1=(c1,s1)\\<rbrakk>\\<Longrightarrow> \\<Gamma>\\<turnstile>c1\\<down>s1\"\nusing wf \nproof (induct cfg1,simp)\n  fix c1 s1\n  assume reach: \"\\<Gamma>\\<turnstile> (c, s) \\<rightarrow>\\<^sup>* (c1, s1)\"\n  assume hyp_raw: \"\\<And>y c2 s2.\n           \\<lbrakk>\\<Gamma>\\<turnstile> (c1, s1) \\<rightarrow> (c2, s2); \\<Gamma>\\<turnstile> (c, s) \\<rightarrow>\\<^sup>* (c2, s2); y = (c2, s2)\\<rbrakk>\n           \\<Longrightarrow> \\<Gamma>\\<turnstile>c2 \\<down> s2\"\n  have hyp: \"\\<And>c2 s2. \\<Gamma>\\<turnstile> (c1, s1) \\<rightarrow> (c2, s2) \\<Longrightarrow> \\<Gamma>\\<turnstile>c2 \\<down> s2\"\n    apply -\n    apply (rule hyp_raw)\n    apply   assumption\n    using reach \n    apply  simp\n    apply (rule refl)\n    done\n  \n  show \"\\<Gamma>\\<turnstile>c1 \\<down> s1\"\n  proof (cases s1)  \n    case (Normal s1')             \n    with  wf_implies_termi_reach_step_case' [OF hyp [simplified Normal]] \n    show ?thesis\n      by auto\n  qed (auto intro: terminates.intros)\nqed\n\ntheorem no_infinite_computation_impl_terminates:\n  assumes not_inf: \"\\<not> \\<Gamma>\\<turnstile> (c, s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n  shows \"\\<Gamma>\\<turnstile>c\\<down>s\"\nproof -\n  from no_infinite_computation_implies_wf [OF not_inf]\n  have wf: \"wf {(c2, c1). \\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* c1 \\<and> \\<Gamma>\\<turnstile>c1 \\<rightarrow> c2}\".\n  show ?thesis\n    by (rule wf_implies_termi_reach [OF wf]) auto\nqed\n\ncorollary terminates_iff_no_infinite_computation: \n  \"\\<Gamma>\\<turnstile>c\\<down>s = (\\<not> \\<Gamma>\\<turnstile> (c, s) \\<rightarrow> \\<dots>(\\<infinity>))\"\n  apply (rule)\n  apply  (erule terminates_impl_no_infinite_computation)\n  apply (erule no_infinite_computation_impl_terminates)\n  done\n\n(* ************************************************************************* *)\nsubsection {* Generalised Redexes *} \n(* ************************************************************************* *)\n\ntext {*\nFor an important lemma for the completeness proof of the Hoare-logic for\ntotal correctness we need a generalisation of @{const \"redex\"} that not only\nyield the redex itself but all the enclosing statements as well.\n*}\n\nprimrec redexes:: \"('s,'p,'f,'e)com \\<Rightarrow> ('s,'p,'f,'e)com set\"\nwhere\n\"redexes Skip = {Skip}\" |\n\"redexes (Basic f) = {Basic f}\" |\n\"redexes (Spec r) = {Spec r}\" |\n\"redexes (Seq c\\<^sub>1 c\\<^sub>2) = {Seq c\\<^sub>1 c\\<^sub>2} \\<union> redexes c\\<^sub>1\" |\n\"redexes (Cond b c\\<^sub>1 c\\<^sub>2) = {Cond b c\\<^sub>1 c\\<^sub>2}\" |\n\"redexes (While b c) = {While b c}\" |\n\"redexes (Call p) = {Call p}\" |\n\"redexes (DynCom d) = {DynCom d}\" |\n\"redexes (Guard f b c) = {Guard f b c}\" |\n\"redexes (Throw) = {Throw}\" |\n\"redexes (Catch c\\<^sub>1 c\\<^sub>2) = {Catch c\\<^sub>1 c\\<^sub>2} \\<union> redexes c\\<^sub>1\" |\n\"redexes (Await b c) = {Await b c}\"\n\nlemma root_in_redexes: \"c \\<in> redexes c\"\n  apply (induct c)\n  apply auto\n  done\n\nlemma redex_in_redexes: \"redex c \\<in> redexes c\"\n  apply (induct c)\n  apply auto\n  done\n\nlemma redex_redexes: \"\\<And>c'. \\<lbrakk>c' \\<in> redexes c; redex c' = c'\\<rbrakk> \\<Longrightarrow> redex c = c'\" \n  apply (induct c)\n  apply auto\n  done\n\nlemma step_redexes:\n  shows \"\\<And>r r'. \\<lbrakk>\\<Gamma>\\<turnstile>(r,s) \\<rightarrow> (r',s'); r \\<in> redexes c\\<rbrakk> \n  \\<Longrightarrow> \\<exists>c'. \\<Gamma>\\<turnstile>(c,s) \\<rightarrow> (c',s') \\<and> r' \\<in> redexes c'\"\nproof (induct c)\n  case Skip thus ?case by (fastforce intro: step.intros elim: step_elim_cases)\nnext\n  case Basic thus ?case by (fastforce intro: step.intros elim: step_elim_cases)\nnext\n  case Spec thus ?case by (fastforce intro: step.intros elim: step_elim_cases)\nnext\n  case (Seq c\\<^sub>1 c\\<^sub>2)\n  have \"r \\<in> redexes (Seq c\\<^sub>1 c\\<^sub>2)\" by fact\n  hence r: \"r = Seq c\\<^sub>1 c\\<^sub>2 \\<or> r \\<in> redexes c\\<^sub>1\"\n    by simp\n  have step_r: \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow> (r', s')\" by fact\n  from r show ?case\n  proof \n    assume \"r = Seq c\\<^sub>1 c\\<^sub>2\"\n    with step_r\n    show ?case\n      by (auto simp add: root_in_redexes)\n  next\n    assume r: \"r \\<in> redexes c\\<^sub>1\"\n    from Seq.hyps (1) [OF step_r this] \n    obtain c' where \n      step_c\\<^sub>1: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, s) \\<rightarrow> (c', s')\" and\n      r': \"r' \\<in> redexes c'\"\n      by blast\n    from step.Seq [OF step_c\\<^sub>1]\n    have \"\\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, s) \\<rightarrow> (Seq c' c\\<^sub>2, s')\".\n    with r'\n    show ?case\n      by auto\n  qed\nnext\n  case Cond \n  thus ?case \n    by (fastforce intro: step.intros elim: step_elim_cases simp add: root_in_redexes)\nnext\n  case While \n  thus ?case \n    by (fastforce intro: step.intros elim: step_elim_cases simp add: root_in_redexes)\nnext\n  case Call thus ?case \n    by (fastforce intro: step.intros elim: step_elim_cases simp add: root_in_redexes)\nnext\n  case DynCom thus ?case \n    by (fastforce intro: step.intros elim: step_elim_cases simp add: root_in_redexes)\nnext\n  case Guard thus ?case \n    by (fastforce intro: step.intros elim: step_elim_cases simp add: root_in_redexes)\nnext\n  case Throw thus ?case \n    by (fastforce intro: step.intros elim: step_elim_cases simp add: root_in_redexes)\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have \"r \\<in> redexes (Catch c\\<^sub>1 c\\<^sub>2)\" by fact\n  hence r: \"r = Catch c\\<^sub>1 c\\<^sub>2 \\<or> r \\<in> redexes c\\<^sub>1\"\n    by simp\n  have step_r: \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow> (r', s')\" by fact\n  from r show ?case\n  proof \n    assume \"r = Catch c\\<^sub>1 c\\<^sub>2\"\n    with step_r\n    show ?case\n      by (auto simp add: root_in_redexes)\n  next\n    assume r: \"r \\<in> redexes c\\<^sub>1\"\n    from Catch.hyps (1) [OF step_r this] \n    obtain c' where \n      step_c\\<^sub>1: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, s) \\<rightarrow> (c', s')\" and\n      r': \"r' \\<in> redexes c'\"\n      by blast\n    from step.Catch [OF step_c\\<^sub>1]\n    have \"\\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, s) \\<rightarrow> (Catch c' c\\<^sub>2, s')\".\n    with r'\n    show ?case\n      by auto\n  qed\nnext case (Await b c)  \n     thus ?case \n     by (fastforce intro: step.intros elim: step_elim_cases simp add: root_in_redexes)\nqed \n\nlemma steps_redexes:\n  assumes steps: \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow>\\<^sup>* (r', s')\"\n  shows \"\\<And>c. r \\<in> redexes c \\<Longrightarrow> \\<exists>c'. \\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>* (c',s') \\<and> r' \\<in> redexes c'\"\nusing steps \nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl\n  then\n  show \"\\<exists>c'. \\<Gamma>\\<turnstile> (c, s') \\<rightarrow>\\<^sup>* (c', s') \\<and> r' \\<in> redexes c'\"\n    by auto\nnext\n  case (Trans r s r'' s'')\n  have \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow> (r'', s'')\" \"r \\<in> redexes c\" by fact+\n  from step_redexes [OF this]\n  obtain c' where\n    step: \"\\<Gamma>\\<turnstile> (c, s) \\<rightarrow> (c', s'')\" and\n    r'': \"r'' \\<in> redexes c'\"\n    by blast\n  note step\n  also\n  from Trans.hyps (3) [OF r'']\n  obtain c'' where\n    steps: \"\\<Gamma>\\<turnstile> (c', s'') \\<rightarrow>\\<^sup>* (c'', s')\" and\n    r': \"r' \\<in> redexes c''\"\n    by blast\n  note steps\n  finally\n  show ?case\n    using r'\n    by blast\nqed\n\n\n\nlemma steps_redexes':\n  assumes steps: \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow>\\<^sup>+ (r', s')\"\n  shows \"\\<And>c. r \\<in> redexes c \\<Longrightarrow> \\<exists>c'. \\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>+ (c',s') \\<and> r' \\<in> redexes c'\"\nusing steps \nproof (induct rule: tranclp_induct2 [consumes 1, case_names Step Trans])\n  case (Step r' s' c') \n  have \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow> (r', s')\" \"r \\<in> redexes c'\" by fact+\n  from step_redexes [OF this]\n  show ?case\n    by (blast intro: r_into_trancl)\nnext\n  case (Trans r' s' r'' s'')\n  from Trans obtain c' where\n    steps: \"\\<Gamma>\\<turnstile> (c, s) \\<rightarrow>\\<^sup>+ (c', s')\" and\n    r': \"r' \\<in> redexes c'\"\n    by blast\n  note steps\n  moreover\n  have \"\\<Gamma>\\<turnstile> (r', s') \\<rightarrow> (r'', s'')\" by fact\n  from step_redexes [OF this r'] obtain c'' where\n    step: \"\\<Gamma>\\<turnstile> (c', s') \\<rightarrow> (c'', s'')\" and\n    r'': \"r'' \\<in> redexes c''\"\n    by blast\n  note step\n  finally show ?case\n    using r'' by blast\nqed\n\nlemma step_redexes_Seq:\n  assumes step: \"\\<Gamma>\\<turnstile>(r,s) \\<rightarrow> (r',s')\"\n  assumes Seq: \"Seq r c\\<^sub>2 \\<in> redexes c\"\n  shows \"\\<exists>c'. \\<Gamma>\\<turnstile>(c,s) \\<rightarrow> (c',s') \\<and> Seq r' c\\<^sub>2 \\<in> redexes c'\"\nproof -\n  from step.Seq [OF step]\n  have \"\\<Gamma>\\<turnstile> (Seq r c\\<^sub>2, s) \\<rightarrow> (Seq r' c\\<^sub>2, s')\".\n  from step_redexes [OF this Seq] \n  show ?thesis .\nqed\n\nlemma steps_redexes_Seq:\n  assumes steps: \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow>\\<^sup>* (r', s')\"\n  shows \"\\<And>c. Seq r c\\<^sub>2 \\<in> redexes c \\<Longrightarrow> \n              \\<exists>c'. \\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>* (c',s') \\<and> Seq r' c\\<^sub>2 \\<in> redexes c'\"\nusing steps \nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl\n  then show ?case\n    by (auto)\n\nnext\n  case (Trans r s r'' s'')\n  have \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow> (r'', s'')\" \"Seq r c\\<^sub>2 \\<in> redexes c\" by fact+\n  from step_redexes_Seq [OF this]\n  obtain c' where\n    step: \"\\<Gamma>\\<turnstile> (c, s) \\<rightarrow> (c', s'')\" and\n    r'': \"Seq r'' c\\<^sub>2 \\<in> redexes c'\"\n    by blast\n  note step\n  also\n  from Trans.hyps (3) [OF r'']\n  obtain c'' where\n    steps: \"\\<Gamma>\\<turnstile> (c', s'') \\<rightarrow>\\<^sup>* (c'', s')\" and\n    r': \"Seq r' c\\<^sub>2 \\<in> redexes c''\"\n    by blast\n  note steps\n  finally\n  show ?case\n    using r'\n    by blast\nqed\n\nlemma steps_redexes_Seq':\n  assumes steps: \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow>\\<^sup>+ (r', s')\"\n  shows \"\\<And>c. Seq r c\\<^sub>2 \\<in> redexes c \n             \\<Longrightarrow> \\<exists>c'. \\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>+ (c',s') \\<and> Seq r' c\\<^sub>2 \\<in> redexes c'\"\nusing steps \nproof (induct rule: tranclp_induct2 [consumes 1, case_names Step Trans])\n  case (Step r' s' c') \n  have \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow> (r', s')\" \"Seq r c\\<^sub>2 \\<in> redexes c'\" by fact+\n  from step_redexes_Seq [OF this]\n  show ?case\n    by (blast intro: r_into_trancl)\nnext\n  case (Trans r' s' r'' s'')\n  from Trans obtain c' where\n    steps: \"\\<Gamma>\\<turnstile> (c, s) \\<rightarrow>\\<^sup>+ (c', s')\" and\n    r': \"Seq r' c\\<^sub>2 \\<in> redexes c'\"\n    by blast\n  note steps\n  moreover\n  have \"\\<Gamma>\\<turnstile> (r', s') \\<rightarrow> (r'', s'')\" by fact\n  from step_redexes_Seq [OF this r'] obtain c'' where\n    step: \"\\<Gamma>\\<turnstile> (c', s') \\<rightarrow> (c'', s'')\" and\n    r'': \"Seq r'' c\\<^sub>2 \\<in> redexes c''\"\n    by blast\n  note step\n  finally show ?case\n    using r'' by blast\nqed\n\nlemma step_redexes_Catch:\n  assumes step: \"\\<Gamma>\\<turnstile>(r,s) \\<rightarrow> (r',s')\"\n  assumes Catch: \"Catch r c\\<^sub>2 \\<in> redexes c\"\n  shows \"\\<exists>c'. \\<Gamma>\\<turnstile>(c,s) \\<rightarrow> (c',s') \\<and> Catch r' c\\<^sub>2 \\<in> redexes c'\"\nproof -\n  from step.Catch [OF step]\n  have \"\\<Gamma>\\<turnstile> (Catch r c\\<^sub>2, s) \\<rightarrow> (Catch r' c\\<^sub>2, s')\".\n  from step_redexes [OF this Catch] \n  show ?thesis .\nqed\n\nlemma steps_redexes_Catch:\n  assumes steps: \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow>\\<^sup>* (r', s')\"\n  shows \"\\<And>c. Catch r c\\<^sub>2 \\<in> redexes c \\<Longrightarrow> \n              \\<exists>c'. \\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>* (c',s') \\<and> Catch r' c\\<^sub>2 \\<in> redexes c'\"\nusing steps \nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl\n  then show ?case\n    by (auto)\n\nnext\n  case (Trans r s r'' s'')\n  have \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow> (r'', s'')\" \"Catch r c\\<^sub>2 \\<in> redexes c\" by fact+\n  from step_redexes_Catch [OF this]\n  obtain c' where\n    step: \"\\<Gamma>\\<turnstile> (c, s) \\<rightarrow> (c', s'')\" and\n    r'': \"Catch r'' c\\<^sub>2 \\<in> redexes c'\"\n    by blast\n  note step\n  also\n  from Trans.hyps (3) [OF r'']\n  obtain c'' where\n    steps: \"\\<Gamma>\\<turnstile> (c', s'') \\<rightarrow>\\<^sup>* (c'', s')\" and\n    r': \"Catch r' c\\<^sub>2 \\<in> redexes c''\"\n    by blast\n  note steps\n  finally\n  show ?case\n    using r'\n    by blast\nqed\n\nlemma steps_redexes_Catch':\n  assumes steps: \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow>\\<^sup>+ (r', s')\"\n  shows \"\\<And>c. Catch r c\\<^sub>2 \\<in> redexes c \n             \\<Longrightarrow> \\<exists>c'. \\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>+ (c',s') \\<and> Catch r' c\\<^sub>2 \\<in> redexes c'\"\nusing steps \nproof (induct rule: tranclp_induct2 [consumes 1, case_names Step Trans])\n  case (Step r' s' c') \n  have \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow> (r', s')\" \"Catch r c\\<^sub>2 \\<in> redexes c'\" by fact+\n  from step_redexes_Catch [OF this]\n  show ?case\n    by (blast intro: r_into_trancl)\nnext\n  case (Trans r' s' r'' s'')\n  from Trans obtain c' where\n    steps: \"\\<Gamma>\\<turnstile> (c, s) \\<rightarrow>\\<^sup>+ (c', s')\" and\n    r': \"Catch r' c\\<^sub>2 \\<in> redexes c'\"\n    by blast\n  note steps\n  moreover\n  have \"\\<Gamma>\\<turnstile> (r', s') \\<rightarrow> (r'', s'')\" by fact\n  from step_redexes_Catch [OF this r'] obtain c'' where\n    step: \"\\<Gamma>\\<turnstile> (c', s') \\<rightarrow> (c'', s'')\" and\n    r'': \"Catch r'' c\\<^sub>2 \\<in> redexes c''\"\n    by blast\n  note step\n  finally show ?case\n    using r'' by blast\nqed\n\nlemma redexes_subset:\"\\<And>c'. c' \\<in> redexes c \\<Longrightarrow> redexes c' \\<subseteq> redexes c\"\n  by (induct c) auto\n\nlemma redexes_preserves_termination:\n  assumes termi: \"\\<Gamma>\\<turnstile>c\\<down>s\"\n  shows \"\\<And>c'. c' \\<in> redexes c \\<Longrightarrow> \\<Gamma>\\<turnstile>c'\\<down>s\"  \nusing termi\nby induct (auto intro: terminates.intros)\n\n*)\nend", "meta": {"author": "CompSoftVer", "repo": "CSim", "sha": "816d36b7523796ace031c429003d82e9244eff9c", "save_path": "github-repos/isabelle/CompSoftVer-CSim", "path": "github-repos/isabelle/CompSoftVer-CSim/CSim-816d36b7523796ace031c429003d82e9244eff9c/CSimpl/SmallStepCon.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5851011542032312, "lm_q2_score": 0.44167300566462553, "lm_q1q2_score": 0.25842338539478266}}
{"text": "(*  Title:      HOL/Auth/Guard/Guard_Shared.thy\n    Author:     Frederic Blanqui, University of Cambridge Computer Laboratory\n    Copyright   2002  University of Cambridge\n*)\n\nsection\\<open>lemmas on guarded messages for protocols with symmetric keys\\<close>\n\ntheory Guard_Shared imports Guard GuardK \"../Shared\" begin\n\nsubsection\\<open>Extensions to Theory \\<open>Shared\\<close>\\<close>\n\ndeclare initState.simps [simp del]\n\nsubsubsection\\<open>a little abbreviation\\<close>\n\nabbreviation\n  Ciph :: \"agent => msg => msg\" where\n  \"Ciph A X == Crypt (shrK A) X\"\n\nsubsubsection\\<open>agent associated to a key\\<close>\n\ndefinition agt :: \"key => agent\" where\n\"agt K == SOME A. K = shrK A\"\n\nlemma agt_shrK [simp]: \"agt (shrK A) = A\"\nby (simp add: agt_def)\n\nsubsubsection\\<open>basic facts about \\<^term>\\<open>initState\\<close>\\<close>\n\nlemma no_Crypt_in_parts_init [simp]: \"Crypt K X \\<notin> parts (initState A)\"\nby (cases A, auto simp: initState.simps)\n\nlemma no_Crypt_in_analz_init [simp]: \"Crypt K X \\<notin> analz (initState A)\"\nby auto\n\nlemma no_shrK_in_analz_init [simp]: \"A \\<notin> bad\n\\<Longrightarrow> Key (shrK A) \\<notin> analz (initState Spy)\"\nby (auto simp: initState.simps)\n\nlemma shrK_notin_initState_Friend [simp]: \"A \\<noteq> Friend C\n\\<Longrightarrow> Key (shrK A) \\<notin> parts (initState (Friend C))\"\nby (auto simp: initState.simps)\n\nlemma keyset_init [iff]: \"keyset (initState A)\"\nby (cases A, auto simp: keyset_def initState.simps)\n\nsubsubsection\\<open>sets of symmetric keys\\<close>\n\ndefinition shrK_set :: \"key set => bool\" where\n\"shrK_set Ks \\<equiv> \\<forall>K. K \\<in> Ks \\<longrightarrow> (\\<exists>A. K = shrK A)\"\n\nlemma in_shrK_set: \"[| shrK_set Ks; K \\<in> Ks |] ==> \\<exists>A. K = shrK A\"\nby (simp add: shrK_set_def)\n\nlemma shrK_set1 [iff]: \"shrK_set {shrK A}\"\nby (simp add: shrK_set_def)\n\nlemma shrK_set2 [iff]: \"shrK_set {shrK A, shrK B}\"\nby (simp add: shrK_set_def)\n\nsubsubsection\\<open>sets of good keys\\<close>\n\ndefinition good :: \"key set \\<Rightarrow> bool\" where\n\"good Ks \\<equiv> \\<forall>K. K \\<in> Ks \\<longrightarrow> agt K \\<notin> bad\"\n\nlemma in_good: \"[| good Ks; K \\<in> Ks |] ==> agt K \\<notin> bad\"\nby (simp add: good_def)\n\nlemma good1 [simp]: \"A \\<notin> bad \\<Longrightarrow> good {shrK A}\"\nby (simp add: good_def)\n\nlemma good2 [simp]: \"[| A \\<notin> bad; B \\<notin> bad |] ==> good {shrK A, shrK B}\"\nby (simp add: good_def)\n\n\nsubsection\\<open>Proofs About Guarded Messages\\<close>\n\nsubsubsection\\<open>small hack\\<close>\n\nlemma shrK_is_invKey_shrK: \"shrK A = invKey (shrK A)\"\nby simp\n\nlemmas shrK_is_invKey_shrK_substI = shrK_is_invKey_shrK [THEN ssubst]\n\nlemmas invKey_invKey_substI = invKey [THEN ssubst]\n\nlemma \"Nonce n \\<in> parts {X} \\<Longrightarrow> Crypt (shrK A) X \\<in> guard n {shrK A}\"\napply (rule shrK_is_invKey_shrK_substI, rule invKey_invKey_substI)\nby (rule Guard_Nonce, simp+)\n\nsubsubsection\\<open>guardedness results on nonces\\<close>\n\nlemma guard_ciph [simp]: \"shrK A \\<in> Ks \\<Longrightarrow> Ciph A X \\<in> guard n Ks\"\nby (rule Guard_Nonce, simp)\n\nlemma guardK_ciph [simp]: \"shrK A \\<in> Ks \\<Longrightarrow> Ciph A X \\<in> guardK n Ks\"\nby (rule Guard_Key, simp)\n\nlemma Guard_init [iff]: \"Guard n Ks (initState B)\"\nby (induct B, auto simp: Guard_def initState.simps)\n\nlemma Guard_knows_max': \"Guard n Ks (knows_max' C evs)\n==> Guard n Ks (knows_max C evs)\"\nby (simp add: knows_max_def)\n\nlemma Nonce_not_used_Guard_spies [dest]: \"Nonce n \\<notin> used evs\n\\<Longrightarrow> Guard n Ks (spies evs)\"\nby (auto simp: Guard_def dest: not_used_not_known parts_sub)\n\nlemma Nonce_not_used_Guard [dest]: \"[| evs \\<in> p; Nonce n \\<notin> used evs;\nGets_correct p; one_step p |] ==> Guard n Ks (knows (Friend C) evs)\"\nby (auto simp: Guard_def dest: known_used parts_trans)\n\nlemma Nonce_not_used_Guard_max [dest]: \"[| evs \\<in> p; Nonce n \\<notin> used evs;\nGets_correct p; one_step p |] ==> Guard n Ks (knows_max (Friend C) evs)\"\nby (auto simp: Guard_def dest: known_max_used parts_trans)\n\nlemma Nonce_not_used_Guard_max' [dest]: \"[| evs \\<in> p; Nonce n \\<notin> used evs;\nGets_correct p; one_step p |] ==> Guard n Ks (knows_max' (Friend C) evs)\"\napply (rule_tac H=\"knows_max (Friend C) evs\" in Guard_mono)\nby (auto simp: knows_max_def)\n\nsubsubsection\\<open>guardedness results on keys\\<close>\n\nlemma GuardK_init [simp]: \"n \\<notin> range shrK \\<Longrightarrow> GuardK n Ks (initState B)\"\nby (induct B, auto simp: GuardK_def initState.simps)\n\nlemma GuardK_knows_max': \"[| GuardK n A (knows_max' C evs); n \\<notin> range shrK |]\n==> GuardK n A (knows_max C evs)\"\nby (simp add: knows_max_def)\n\nlemma Key_not_used_GuardK_spies [dest]: \"Key n \\<notin> used evs\n\\<Longrightarrow> GuardK n A (spies evs)\"\nby (auto simp: GuardK_def dest: not_used_not_known parts_sub)\n\nlemma Key_not_used_GuardK [dest]: \"[| evs \\<in> p; Key n \\<notin> used evs;\nGets_correct p; one_step p |] ==> GuardK n A (knows (Friend C) evs)\"\nby (auto simp: GuardK_def dest: known_used parts_trans)\n\nlemma Key_not_used_GuardK_max [dest]: \"[| evs \\<in> p; Key n \\<notin> used evs;\nGets_correct p; one_step p |] ==> GuardK n A (knows_max (Friend C) evs)\"\nby (auto simp: GuardK_def dest: known_max_used parts_trans)\n\nlemma Key_not_used_GuardK_max' [dest]: \"[| evs \\<in> p; Key n \\<notin> used evs;\nGets_correct p; one_step p |] ==> GuardK n A (knows_max' (Friend C) evs)\"\napply (rule_tac H=\"knows_max (Friend C) evs\" in GuardK_mono)\nby (auto simp: knows_max_def)\n\nsubsubsection\\<open>regular protocols\\<close>\n\ndefinition regular :: \"event list set => bool\" where\n\"regular p \\<equiv> \\<forall>evs A. evs \\<in> p \\<longrightarrow> (Key (shrK A) \\<in> parts (spies evs)) = (A \\<in> bad)\"\n\nlemma shrK_parts_iff_bad [simp]: \"[| evs \\<in> p; regular p |] ==>\n(Key (shrK A) \\<in> parts (spies evs)) = (A \\<in> bad)\"\nby (auto simp: regular_def)\n\nlemma shrK_analz_iff_bad [simp]: \"[| evs \\<in> p; regular p |] ==>\n(Key (shrK A) \\<in> analz (spies evs)) = (A \\<in> bad)\"\nby auto\n\nlemma Guard_Nonce_analz: \"[| Guard n Ks (spies evs); evs \\<in> p;\nshrK_set Ks; good Ks; regular p |] ==> Nonce n \\<notin> analz (spies evs)\"\napply (clarify, simp only: knows_decomp)\napply (drule Guard_invKey_keyset, simp+, safe)\napply (drule in_good, simp)\napply (drule in_shrK_set, simp+, clarify)\napply (frule_tac A=A in shrK_analz_iff_bad)\nby (simp add: knows_decomp)+\n\nlemma GuardK_Key_analz:\n  assumes \"GuardK n Ks (spies evs)\" \"evs \\<in> p\" \"shrK_set Ks\"\n    \"good Ks\" \"regular p\" \"n \\<notin> range shrK\"\n  shows \"Key n \\<notin> analz (spies evs)\"\nproof (rule ccontr)\n  assume \"\\<not> Key n \\<notin> analz (knows Spy evs)\"\n  then have *: \"Key n \\<in> analz (spies' evs \\<union> initState Spy)\"\n    by (simp add: knows_decomp)\n  from \\<open>GuardK n Ks (spies evs)\\<close>\n  have \"GuardK n Ks (spies' evs \\<union> initState Spy)\"\n    by (simp add: knows_decomp)  \n  then have \"GuardK n Ks (spies' evs)\"\n    and \"finite (spies' evs)\" \"keyset (initState Spy)\"\n    by simp_all\n  moreover have \"Key n \\<notin> initState Spy\"\n    using \\<open>n \\<notin> range shrK\\<close> by (simp add: image_iff initState_Spy)\n  ultimately obtain K\n    where \"K \\<in> Ks\" and **: \"Key K \\<in> analz (spies' evs \\<union> initState Spy)\"\n    using * by (auto dest: GuardK_invKey_keyset)\n  from \\<open>K \\<in> Ks\\<close> and \\<open>good Ks\\<close> have \"agt K \\<notin> bad\"\n    by (auto dest: in_good)\n  from \\<open>K \\<in> Ks\\<close> \\<open>shrK_set Ks\\<close> obtain A\n    where \"K = shrK A\"\n    by (auto dest: in_shrK_set)\n  then have \"agt K \\<in> bad\"\n    using ** \\<open>evs \\<in> p\\<close> \\<open>regular p\\<close> shrK_analz_iff_bad [of evs p \"agt K\"]\n    by (simp add: knows_decomp)\n  with \\<open>agt K \\<notin> bad\\<close> show False by simp\nqed\n\nend\n", "meta": {"author": "m-fleury", "repo": "isabelle-emacs", "sha": "756c662195e138a1941d22d4dd7ff759cbf6b6b9", "save_path": "github-repos/isabelle/m-fleury-isabelle-emacs", "path": "github-repos/isabelle/m-fleury-isabelle-emacs/isabelle-emacs-756c662195e138a1941d22d4dd7ff759cbf6b6b9/src/HOL/Auth/Guard/Guard_Shared.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526660244838, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.2582924724987522}}
{"text": "(*  Title:      HOL/Auth/TLS.thy\n    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory\n    Copyright   1997  University of Cambridge\n\nInductive relation \"tls\" for the TLS (Transport Layer Security) protocol.\nThis protocol is essentially the same as SSL 3.0.\n\nAbstracted from \"The TLS Protocol, Version 1.0\" by Tim Dierks and Christopher\nAllen, Transport Layer Security Working Group, 21 May 1997,\nINTERNET-DRAFT draft-ietf-tls-protocol-03.txt.  Section numbers below refer\nto that memo.\n\nAn RSA cryptosystem is assumed, and X.509v3 certificates are abstracted down\nto the trivial form {A, publicKey(A)}privateKey(Server), where Server is a\nglobal signing authority.\n\nA is the client and B is the server, not to be confused with the constant\nServer, who is in charge of all public keys.\n\nThe model assumes that no fraudulent certificates are present, but it does\nassume that some private keys are to the spy.\n\nREMARK.  The event \"Notes A {|Agent B, Nonce PMS|}\" appears in ClientKeyExch,\nCertVerify, ClientFinished to record that A knows M.  It is a note from A to\nherself.  Nobody else can see it.  In ClientKeyExch, the Spy can substitute\nhis own certificate for A's, but he cannot replace A's note by one for himself.\n\nThe Note event avoids a weakness in the public-key model.  Each\nagent's state is recorded as the trace of messages.  When the true client (A)\ninvents PMS, he encrypts PMS with B's public key before sending it.  The model\ndoes not distinguish the original occurrence of such a message from a replay.\nIn the shared-key model, the ability to encrypt implies the ability to\ndecrypt, so the problem does not arise.\n\nProofs would be simpler if ClientKeyExch included A's name within\nCrypt KB (Nonce PMS).  As things stand, there is much overlap between proofs\nabout that message (which B receives) and the stronger event\nNotes A {|Agent B, Nonce PMS|}.\n*)\n\nsection{*The TLS Protocol: Transport Layer Security*}\n\ntheory TLS imports Public \"~~/src/HOL/Library/Nat_Bijection\" begin\n\ndefinition certificate :: \"[agent,key] => msg\" where\n    \"certificate A KA == Crypt (priSK Server) {|Agent A, Key KA|}\"\n\ntext{*TLS apparently does not require separate keypairs for encryption and\nsignature.  Therefore, we formalize signature as encryption using the\nprivate encryption key.*}\n\ndatatype role = ClientRole | ServerRole\n\nconsts\n  (*Pseudo-random function of Section 5*)\n  PRF  :: \"nat*nat*nat => nat\"\n\n  (*Client, server write keys are generated uniformly by function sessionK\n    to avoid duplicating their properties.  They are distinguished by a\n    tag (not a bool, to avoid the peculiarities of if-and-only-if).\n    Session keys implicitly include MAC secrets.*)\n  sessionK :: \"(nat*nat*nat) * role => key\"\n\nabbreviation\n  clientK :: \"nat*nat*nat => key\" where\n  \"clientK X == sessionK(X, ClientRole)\"\n\nabbreviation\n  serverK :: \"nat*nat*nat => key\" where\n  \"serverK X == sessionK(X, ServerRole)\"\n\n\nspecification (PRF)\n  inj_PRF: \"inj PRF\"\n  --{*the pseudo-random function is collision-free*}\n   apply (rule exI [of _ \"%(x,y,z). prod_encode(x, prod_encode(y,z))\"])\n   apply (simp add: inj_on_def prod_encode_eq)\n   done\n\nspecification (sessionK)\n  inj_sessionK: \"inj sessionK\"\n  --{*sessionK is collision-free; also, no clientK clashes with any serverK.*}\n   apply (rule exI [of _ \n         \"%((x,y,z), r). prod_encode(case_role 0 1 r, \n                           prod_encode(x, prod_encode(y,z)))\"])\n   apply (simp add: inj_on_def prod_encode_eq split: role.split) \n   done\n\naxiomatization where\n  --{*sessionK makes symmetric keys*}\n  isSym_sessionK: \"sessionK nonces \\<in> symKeys\" and\n\n  --{*sessionK never clashes with a long-term symmetric key  \n     (they don't exist in TLS anyway)*}\n  sessionK_neq_shrK [iff]: \"sessionK nonces \\<noteq> shrK A\"\n\n\ninductive_set tls :: \"event list set\"\n  where\n   Nil:  --{*The initial, empty trace*}\n         \"[] \\<in> tls\"\n\n | Fake: --{*The Spy may say anything he can say.  The sender field is correct,\n          but agents don't use that information.*}\n         \"[| evsf \\<in> tls;  X \\<in> synth (analz (spies evsf)) |]\n          ==> Says Spy B X # evsf \\<in> tls\"\n\n | SpyKeys: --{*The spy may apply @{term PRF} and @{term sessionK}\n                to available nonces*}\n         \"[| evsSK \\<in> tls;\n             {Nonce NA, Nonce NB, Nonce M} <= analz (spies evsSK) |]\n          ==> Notes Spy {| Nonce (PRF(M,NA,NB)),\n                           Key (sessionK((NA,NB,M),role)) |} # evsSK \\<in> tls\"\n\n | ClientHello:\n         --{*(7.4.1.2)\n           PA represents @{text CLIENT_VERSION}, @{text CIPHER_SUITES} and @{text COMPRESSION_METHODS}.\n           It is uninterpreted but will be confirmed in the FINISHED messages.\n           NA is CLIENT RANDOM, while SID is @{text SESSION_ID}.\n           UNIX TIME is omitted because the protocol doesn't use it.\n           May assume @{term \"NA \\<notin> range PRF\"} because CLIENT RANDOM is \n           28 bytes while MASTER SECRET is 48 bytes*}\n         \"[| evsCH \\<in> tls;  Nonce NA \\<notin> used evsCH;  NA \\<notin> range PRF |]\n          ==> Says A B {|Agent A, Nonce NA, Number SID, Number PA|}\n                # evsCH  \\<in>  tls\"\n\n | ServerHello:\n         --{*7.4.1.3 of the TLS Internet-Draft\n           PB represents @{text CLIENT_VERSION}, @{text CIPHER_SUITE} and @{text COMPRESSION_METHOD}.\n           SERVER CERTIFICATE (7.4.2) is always present.\n           @{text CERTIFICATE_REQUEST} (7.4.4) is implied.*}\n         \"[| evsSH \\<in> tls;  Nonce NB \\<notin> used evsSH;  NB \\<notin> range PRF;\n             Says A' B {|Agent A, Nonce NA, Number SID, Number PA|}\n               \\<in> set evsSH |]\n          ==> Says B A {|Nonce NB, Number SID, Number PB|} # evsSH  \\<in>  tls\"\n\n | Certificate:\n         --{*SERVER (7.4.2) or CLIENT (7.4.6) CERTIFICATE.*}\n         \"evsC \\<in> tls ==> Says B A (certificate B (pubK B)) # evsC  \\<in>  tls\"\n\n | ClientKeyExch:\n         --{*CLIENT KEY EXCHANGE (7.4.7).\n           The client, A, chooses PMS, the PREMASTER SECRET.\n           She encrypts PMS using the supplied KB, which ought to be pubK B.\n           We assume @{term \"PMS \\<notin> range PRF\"} because a clash betweem the PMS\n           and another MASTER SECRET is highly unlikely (even though\n           both items have the same length, 48 bytes).\n           The Note event records in the trace that she knows PMS\n               (see REMARK at top). *}\n         \"[| evsCX \\<in> tls;  Nonce PMS \\<notin> used evsCX;  PMS \\<notin> range PRF;\n             Says B' A (certificate B KB) \\<in> set evsCX |]\n          ==> Says A B (Crypt KB (Nonce PMS))\n              # Notes A {|Agent B, Nonce PMS|}\n              # evsCX  \\<in>  tls\"\n\n | CertVerify:\n        --{*The optional Certificate Verify (7.4.8) message contains the\n          specific components listed in the security analysis, F.1.1.2.\n          It adds the pre-master-secret, which is also essential!\n          Checking the signature, which is the only use of A's certificate,\n          assures B of A's presence*}\n         \"[| evsCV \\<in> tls;\n             Says B' A {|Nonce NB, Number SID, Number PB|} \\<in> set evsCV;\n             Notes A {|Agent B, Nonce PMS|} \\<in> set evsCV |]\n          ==> Says A B (Crypt (priK A) (Hash{|Nonce NB, Agent B, Nonce PMS|}))\n              # evsCV  \\<in>  tls\"\n\n        --{*Finally come the FINISHED messages (7.4.8), confirming PA and PB\n          among other things.  The master-secret is PRF(PMS,NA,NB).\n          Either party may send its message first.*}\n\n | ClientFinished:\n        --{*The occurrence of Notes A {|Agent B, Nonce PMS|} stops the\n          rule's applying when the Spy has satisfied the \"Says A B\" by\n          repaying messages sent by the true client; in that case, the\n          Spy does not know PMS and could not send ClientFinished.  One\n          could simply put @{term \"A\\<noteq>Spy\"} into the rule, but one should not\n          expect the spy to be well-behaved.*}\n         \"[| evsCF \\<in> tls;\n             Says A  B {|Agent A, Nonce NA, Number SID, Number PA|}\n               \\<in> set evsCF;\n             Says B' A {|Nonce NB, Number SID, Number PB|} \\<in> set evsCF;\n             Notes A {|Agent B, Nonce PMS|} \\<in> set evsCF;\n             M = PRF(PMS,NA,NB) |]\n          ==> Says A B (Crypt (clientK(NA,NB,M))\n                        (Hash{|Number SID, Nonce M,\n                               Nonce NA, Number PA, Agent A,\n                               Nonce NB, Number PB, Agent B|}))\n              # evsCF  \\<in>  tls\"\n\n | ServerFinished:\n        --{*Keeping A' and A'' distinct means B cannot even check that the\n          two messages originate from the same source. *}\n         \"[| evsSF \\<in> tls;\n             Says A' B  {|Agent A, Nonce NA, Number SID, Number PA|}\n               \\<in> set evsSF;\n             Says B  A  {|Nonce NB, Number SID, Number PB|} \\<in> set evsSF;\n             Says A'' B (Crypt (pubK B) (Nonce PMS)) \\<in> set evsSF;\n             M = PRF(PMS,NA,NB) |]\n          ==> Says B A (Crypt (serverK(NA,NB,M))\n                        (Hash{|Number SID, Nonce M,\n                               Nonce NA, Number PA, Agent A,\n                               Nonce NB, Number PB, Agent B|}))\n              # evsSF  \\<in>  tls\"\n\n | ClientAccepts:\n        --{*Having transmitted ClientFinished and received an identical\n          message encrypted with serverK, the client stores the parameters\n          needed to resume this session.  The \"Notes A ...\" premise is\n          used to prove @{text Notes_master_imp_Crypt_PMS}.*}\n         \"[| evsCA \\<in> tls;\n             Notes A {|Agent B, Nonce PMS|} \\<in> set evsCA;\n             M = PRF(PMS,NA,NB);\n             X = Hash{|Number SID, Nonce M,\n                       Nonce NA, Number PA, Agent A,\n                       Nonce NB, Number PB, Agent B|};\n             Says A  B (Crypt (clientK(NA,NB,M)) X) \\<in> set evsCA;\n             Says B' A (Crypt (serverK(NA,NB,M)) X) \\<in> set evsCA |]\n          ==>\n             Notes A {|Number SID, Agent A, Agent B, Nonce M|} # evsCA  \\<in>  tls\"\n\n | ServerAccepts:\n        --{*Having transmitted ServerFinished and received an identical\n          message encrypted with clientK, the server stores the parameters\n          needed to resume this session.  The \"Says A'' B ...\" premise is\n          used to prove @{text Notes_master_imp_Crypt_PMS}.*}\n         \"[| evsSA \\<in> tls;\n             A \\<noteq> B;\n             Says A'' B (Crypt (pubK B) (Nonce PMS)) \\<in> set evsSA;\n             M = PRF(PMS,NA,NB);\n             X = Hash{|Number SID, Nonce M,\n                       Nonce NA, Number PA, Agent A,\n                       Nonce NB, Number PB, Agent B|};\n             Says B  A (Crypt (serverK(NA,NB,M)) X) \\<in> set evsSA;\n             Says A' B (Crypt (clientK(NA,NB,M)) X) \\<in> set evsSA |]\n          ==>\n             Notes B {|Number SID, Agent A, Agent B, Nonce M|} # evsSA  \\<in>  tls\"\n\n | ClientResume:\n         --{*If A recalls the @{text SESSION_ID}, then she sends a FINISHED\n             message using the new nonces and stored MASTER SECRET.*}\n         \"[| evsCR \\<in> tls;\n             Says A  B {|Agent A, Nonce NA, Number SID, Number PA|}: set evsCR;\n             Says B' A {|Nonce NB, Number SID, Number PB|} \\<in> set evsCR;\n             Notes A {|Number SID, Agent A, Agent B, Nonce M|} \\<in> set evsCR |]\n          ==> Says A B (Crypt (clientK(NA,NB,M))\n                        (Hash{|Number SID, Nonce M,\n                               Nonce NA, Number PA, Agent A,\n                               Nonce NB, Number PB, Agent B|}))\n              # evsCR  \\<in>  tls\"\n\n | ServerResume:\n         --{*Resumption (7.3):  If B finds the @{text SESSION_ID} then he can \n             send a FINISHED message using the recovered MASTER SECRET*}\n         \"[| evsSR \\<in> tls;\n             Says A' B {|Agent A, Nonce NA, Number SID, Number PA|}: set evsSR;\n             Says B  A {|Nonce NB, Number SID, Number PB|} \\<in> set evsSR;\n             Notes B {|Number SID, Agent A, Agent B, Nonce M|} \\<in> set evsSR |]\n          ==> Says B A (Crypt (serverK(NA,NB,M))\n                        (Hash{|Number SID, Nonce M,\n                               Nonce NA, Number PA, Agent A,\n                               Nonce NB, Number PB, Agent B|})) # evsSR\n                \\<in>  tls\"\n\n | Oops:\n         --{*The most plausible compromise is of an old session key.  Losing\n           the MASTER SECRET or PREMASTER SECRET is more serious but\n           rather unlikely.  The assumption @{term \"A\\<noteq>Spy\"} is essential: \n           otherwise the Spy could learn session keys merely by \n           replaying messages!*}\n         \"[| evso \\<in> tls;  A \\<noteq> Spy;\n             Says A B (Crypt (sessionK((NA,NB,M),role)) X) \\<in> set evso |]\n          ==> Says A Spy (Key (sessionK((NA,NB,M),role))) # evso  \\<in>  tls\"\n\n(*\nProtocol goals:\n* M, serverK(NA,NB,M) and clientK(NA,NB,M) will be known only to the two\n     parties (though A is not necessarily authenticated).\n\n* B upon receiving CertVerify knows that A is present (But this\n    message is optional!)\n\n* A upon receiving ServerFinished knows that B is present\n\n* Each party who has received a FINISHED message can trust that the other\n  party agrees on all message components, including PA and PB (thus foiling\n  rollback attacks).\n*)\n\ndeclare Says_imp_knows_Spy [THEN analz.Inj, dest]\ndeclare parts.Body  [dest]\ndeclare analz_into_parts [dest]\ndeclare Fake_parts_insert_in_Un  [dest]\n\n\ntext{*Automatically unfold the definition of \"certificate\"*}\ndeclare certificate_def [simp]\n\ntext{*Injectiveness of key-generating functions*}\ndeclare inj_PRF [THEN inj_eq, iff]\ndeclare inj_sessionK [THEN inj_eq, iff]\ndeclare isSym_sessionK [simp]\n\n\n(*** clientK and serverK make symmetric keys; no clashes with pubK or priK ***)\n\nlemma pubK_neq_sessionK [iff]: \"publicKey b A \\<noteq> sessionK arg\"\nby (simp add: symKeys_neq_imp_neq)\n\ndeclare pubK_neq_sessionK [THEN not_sym, iff]\n\nlemma priK_neq_sessionK [iff]: \"invKey (publicKey b A) \\<noteq> sessionK arg\"\nby (simp add: symKeys_neq_imp_neq)\n\ndeclare priK_neq_sessionK [THEN not_sym, iff]\n\nlemmas keys_distinct = pubK_neq_sessionK priK_neq_sessionK\n\n\nsubsection{*Protocol Proofs*}\n\ntext{*Possibility properties state that some traces run the protocol to the\nend.  Four paths and 12 rules are considered.*}\n\n\n(** These proofs assume that the Nonce_supply nonces\n        (which have the form  @ N. Nonce N \\<notin> used evs)\n    lie outside the range of PRF.  It seems reasonable, but as it is needed\n    only for the possibility theorems, it is not taken as an axiom.\n**)\n\n\ntext{*Possibility property ending with ClientAccepts.*}\nlemma \"[| \\<forall>evs. (@ N. Nonce N \\<notin> used evs) \\<notin> range PRF;  A \\<noteq> B |]\n      ==> \\<exists>SID M. \\<exists>evs \\<in> tls.\n            Notes A {|Number SID, Agent A, Agent B, Nonce M|} \\<in> set evs\"\napply (intro exI bexI)\napply (rule_tac [2] tls.Nil\n                    [THEN tls.ClientHello, THEN tls.ServerHello,\n                     THEN tls.Certificate, THEN tls.ClientKeyExch,\n                     THEN tls.ClientFinished, THEN tls.ServerFinished,\n                     THEN tls.ClientAccepts], possibility, blast+)\ndone\n\n\ntext{*And one for ServerAccepts.  Either FINISHED message may come first.*}\nlemma \"[| \\<forall>evs. (@ N. Nonce N \\<notin> used evs) \\<notin> range PRF; A \\<noteq> B |]\n      ==> \\<exists>SID NA PA NB PB M. \\<exists>evs \\<in> tls.\n           Notes B {|Number SID, Agent A, Agent B, Nonce M|} \\<in> set evs\"\napply (intro exI bexI)\napply (rule_tac [2] tls.Nil\n                    [THEN tls.ClientHello, THEN tls.ServerHello,\n                     THEN tls.Certificate, THEN tls.ClientKeyExch,\n                     THEN tls.ServerFinished, THEN tls.ClientFinished, \n                     THEN tls.ServerAccepts], possibility, blast+)\ndone\n\n\ntext{*Another one, for CertVerify (which is optional)*}\nlemma \"[| \\<forall>evs. (@ N. Nonce N \\<notin> used evs) \\<notin> range PRF;  A \\<noteq> B |]\n       ==> \\<exists>NB PMS. \\<exists>evs \\<in> tls.\n              Says A B (Crypt (priK A) (Hash{|Nonce NB, Agent B, Nonce PMS|})) \n                \\<in> set evs\"\napply (intro exI bexI)\napply (rule_tac [2] tls.Nil\n                    [THEN tls.ClientHello, THEN tls.ServerHello,\n                     THEN tls.Certificate, THEN tls.ClientKeyExch,\n                     THEN tls.CertVerify], possibility, blast+)\ndone\n\n\ntext{*Another one, for session resumption (both ServerResume and ClientResume).\n  NO tls.Nil here: we refer to a previous session, not the empty trace.*}\nlemma \"[| evs0 \\<in> tls;\n          Notes A {|Number SID, Agent A, Agent B, Nonce M|} \\<in> set evs0;\n          Notes B {|Number SID, Agent A, Agent B, Nonce M|} \\<in> set evs0;\n          \\<forall>evs. (@ N. Nonce N \\<notin> used evs) \\<notin> range PRF;\n          A \\<noteq> B |]\n      ==> \\<exists>NA PA NB PB X. \\<exists>evs \\<in> tls.\n                X = Hash{|Number SID, Nonce M,\n                          Nonce NA, Number PA, Agent A,\n                          Nonce NB, Number PB, Agent B|}  &\n                Says A B (Crypt (clientK(NA,NB,M)) X) \\<in> set evs  &\n                Says B A (Crypt (serverK(NA,NB,M)) X) \\<in> set evs\"\napply (intro exI bexI)\napply (rule_tac [2] tls.ClientHello\n                    [THEN tls.ServerHello,\n                     THEN tls.ServerResume, THEN tls.ClientResume], possibility, blast+)\ndone\n\n\nsubsection{*Inductive proofs about tls*}\n\n\n(** Theorems of the form X \\<notin> parts (spies evs) imply that NOBODY\n    sends messages containing X! **)\n\ntext{*Spy never sees a good agent's private key!*}\nlemma Spy_see_priK [simp]:\n     \"evs \\<in> tls ==> (Key (privateKey b A) \\<in> parts (spies evs)) = (A \\<in> bad)\"\nby (erule tls.induct, force, simp_all, blast)\n\nlemma Spy_analz_priK [simp]:\n     \"evs \\<in> tls ==> (Key (privateKey b A) \\<in> analz (spies evs)) = (A \\<in> bad)\"\nby auto\n\nlemma Spy_see_priK_D [dest!]:\n    \"[|Key (privateKey b A) \\<in> parts (knows Spy evs);  evs \\<in> tls|] ==> A \\<in> bad\"\nby (blast dest: Spy_see_priK)\n\n\ntext{*This lemma says that no false certificates exist.  One might extend the\n  model to include bogus certificates for the agents, but there seems\n  little point in doing so: the loss of their private keys is a worse\n  breach of security.*}\nlemma certificate_valid:\n    \"[| certificate B KB \\<in> parts (spies evs);  evs \\<in> tls |] ==> KB = pubK B\"\napply (erule rev_mp)\napply (erule tls.induct, force, simp_all, blast) \ndone\n\nlemmas CX_KB_is_pubKB = Says_imp_spies [THEN parts.Inj, THEN certificate_valid]\n\n\nsubsubsection{*Properties of items found in Notes*}\n\nlemma Notes_Crypt_parts_spies:\n     \"[| Notes A {|Agent B, X|} \\<in> set evs;  evs \\<in> tls |]\n      ==> Crypt (pubK B) X \\<in> parts (spies evs)\"\napply (erule rev_mp)\napply (erule tls.induct, \n       frule_tac [7] CX_KB_is_pubKB, force, simp_all)\napply (blast intro: parts_insertI)\ndone\n\ntext{*C may be either A or B*}\nlemma Notes_master_imp_Crypt_PMS:\n     \"[| Notes C {|s, Agent A, Agent B, Nonce(PRF(PMS,NA,NB))|} \\<in> set evs;\n         evs \\<in> tls |]\n      ==> Crypt (pubK B) (Nonce PMS) \\<in> parts (spies evs)\"\napply (erule rev_mp)\napply (erule tls.induct, force, simp_all)\ntxt{*Fake*}\napply (blast intro: parts_insertI)\ntxt{*Client, Server Accept*}\napply (blast dest!: Notes_Crypt_parts_spies)+\ndone\n\ntext{*Compared with the theorem above, both premise and conclusion are stronger*}\nlemma Notes_master_imp_Notes_PMS:\n     \"[| Notes A {|s, Agent A, Agent B, Nonce(PRF(PMS,NA,NB))|} \\<in> set evs;\n         evs \\<in> tls |]\n      ==> Notes A {|Agent B, Nonce PMS|} \\<in> set evs\"\napply (erule rev_mp)\napply (erule tls.induct, force, simp_all)\ntxt{*ServerAccepts*}\napply blast\ndone\n\n\nsubsubsection{*Protocol goal: if B receives CertVerify, then A sent it*}\n\ntext{*B can check A's signature if he has received A's certificate.*}\nlemma TrustCertVerify_lemma:\n     \"[| X \\<in> parts (spies evs);\n         X = Crypt (priK A) (Hash{|nb, Agent B, pms|});\n         evs \\<in> tls;  A \\<notin> bad |]\n      ==> Says A B X \\<in> set evs\"\napply (erule rev_mp, erule ssubst)\napply (erule tls.induct, force, simp_all, blast)\ndone\n\ntext{*Final version: B checks X using the distributed KA instead of priK A*}\nlemma TrustCertVerify:\n     \"[| X \\<in> parts (spies evs);\n         X = Crypt (invKey KA) (Hash{|nb, Agent B, pms|});\n         certificate A KA \\<in> parts (spies evs);\n         evs \\<in> tls;  A \\<notin> bad |]\n      ==> Says A B X \\<in> set evs\"\nby (blast dest!: certificate_valid intro!: TrustCertVerify_lemma)\n\n\ntext{*If CertVerify is present then A has chosen PMS.*}\nlemma UseCertVerify_lemma:\n     \"[| Crypt (priK A) (Hash{|nb, Agent B, Nonce PMS|}) \\<in> parts (spies evs);\n         evs \\<in> tls;  A \\<notin> bad |]\n      ==> Notes A {|Agent B, Nonce PMS|} \\<in> set evs\"\napply (erule rev_mp)\napply (erule tls.induct, force, simp_all, blast)\ndone\n\ntext{*Final version using the distributed KA instead of priK A*}\nlemma UseCertVerify:\n     \"[| Crypt (invKey KA) (Hash{|nb, Agent B, Nonce PMS|})\n           \\<in> parts (spies evs);\n         certificate A KA \\<in> parts (spies evs);\n         evs \\<in> tls;  A \\<notin> bad |]\n      ==> Notes A {|Agent B, Nonce PMS|} \\<in> set evs\"\nby (blast dest!: certificate_valid intro!: UseCertVerify_lemma)\n\n\nlemma no_Notes_A_PRF [simp]:\n     \"evs \\<in> tls ==> Notes A {|Agent B, Nonce (PRF x)|} \\<notin> set evs\"\napply (erule tls.induct, force, simp_all)\ntxt{*ClientKeyExch: PMS is assumed to differ from any PRF.*}\napply blast\ndone\n\n\nlemma MS_imp_PMS [dest!]:\n     \"[| Nonce (PRF (PMS,NA,NB)) \\<in> parts (spies evs);  evs \\<in> tls |]\n      ==> Nonce PMS \\<in> parts (spies evs)\"\napply (erule rev_mp)\napply (erule tls.induct, force, simp_all)\ntxt{*Fake*}\napply (blast intro: parts_insertI)\ntxt{*Easy, e.g. by freshness*}\napply (blast dest: Notes_Crypt_parts_spies)+\ndone\n\n\n\n\nsubsubsection{*Unicity results for PMS, the pre-master-secret*}\n\ntext{*PMS determines B.*}\nlemma Crypt_unique_PMS:\n     \"[| Crypt(pubK B)  (Nonce PMS) \\<in> parts (spies evs);\n         Crypt(pubK B') (Nonce PMS) \\<in> parts (spies evs);\n         Nonce PMS \\<notin> analz (spies evs);\n         evs \\<in> tls |]\n      ==> B=B'\"\napply (erule rev_mp, erule rev_mp, erule rev_mp)\napply (erule tls.induct, analz_mono_contra, force, simp_all (no_asm_simp))\ntxt{*Fake, ClientKeyExch*}\napply blast+\ndone\n\n\n(** It is frustrating that we need two versions of the unicity results.\n    But Notes A {|Agent B, Nonce PMS|} determines both A and B.  Sometimes\n    we have only the weaker assertion Crypt(pubK B) (Nonce PMS), which\n    determines B alone, and only if PMS is secret.\n**)\n\ntext{*In A's internal Note, PMS determines A and B.*}\nlemma Notes_unique_PMS:\n     \"[| Notes A  {|Agent B,  Nonce PMS|} \\<in> set evs;\n         Notes A' {|Agent B', Nonce PMS|} \\<in> set evs;\n         evs \\<in> tls |]\n      ==> A=A' & B=B'\"\napply (erule rev_mp, erule rev_mp)\napply (erule tls.induct, force, simp_all)\ntxt{*ClientKeyExch*}\napply (blast dest!: Notes_Crypt_parts_spies)\ndone\n\n\nsubsection{*Secrecy Theorems*}\n\ntext{*Key compromise lemma needed to prove @{term analz_image_keys}.\n  No collection of keys can help the spy get new private keys.*}\nlemma analz_image_priK [rule_format]:\n     \"evs \\<in> tls\n      ==> \\<forall>KK. (Key(priK B) \\<in> analz (Key`KK Un (spies evs))) =\n          (priK B \\<in> KK | B \\<in> bad)\"\napply (erule tls.induct)\napply (simp_all (no_asm_simp)\n                del: image_insert\n                add: image_Un [THEN sym]\n                     insert_Key_image Un_assoc [THEN sym])\ntxt{*Fake*}\napply spy_analz\ndone\n\n\ntext{*slightly speeds up the big simplification below*}\nlemma range_sessionkeys_not_priK:\n     \"KK <= range sessionK ==> priK B \\<notin> KK\"\nby blast\n\n\ntext{*Lemma for the trivial direction of the if-and-only-if*}\nlemma analz_image_keys_lemma:\n     \"(X \\<in> analz (G Un H)) --> (X \\<in> analz H)  ==>\n      (X \\<in> analz (G Un H))  =  (X \\<in> analz H)\"\nby (blast intro: analz_mono [THEN subsetD])\n\n(** Strangely, the following version doesn't work:\n\\<forall>Z. (Nonce N \\<in> analz (Key`(sessionK`Z) Un (spies evs))) =\n    (Nonce N \\<in> analz (spies evs))\"\n**)\n\nlemma analz_image_keys [rule_format]:\n     \"evs \\<in> tls ==>\n      \\<forall>KK. KK <= range sessionK -->\n              (Nonce N \\<in> analz (Key`KK Un (spies evs))) =\n              (Nonce N \\<in> analz (spies evs))\"\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (safe del: iffI)\napply (safe del: impI iffI intro!: analz_image_keys_lemma)\napply (simp_all (no_asm_simp)               (*faster*)\n                del: image_insert imp_disjL (*reduces blow-up*)\n                add: image_Un [THEN sym]  Un_assoc [THEN sym]\n                     insert_Key_singleton\n                     range_sessionkeys_not_priK analz_image_priK)\napply (simp_all add: insert_absorb)\ntxt{*Fake*}\napply spy_analz\ndone\n\ntext{*Knowing some session keys is no help in getting new nonces*}\nlemma analz_insert_key [simp]:\n     \"evs \\<in> tls ==>\n      (Nonce N \\<in> analz (insert (Key (sessionK z)) (spies evs))) =\n      (Nonce N \\<in> analz (spies evs))\"\nby (simp del: image_insert\n         add: insert_Key_singleton analz_image_keys)\n\n\nsubsubsection{*Protocol goal: serverK(Na,Nb,M) and clientK(Na,Nb,M) remain secure*}\n\n(** Some lemmas about session keys, comprising clientK and serverK **)\n\n\ntext{*Lemma: session keys are never used if PMS is fresh.\n  Nonces don't have to agree, allowing session resumption.\n  Converse doesn't hold; revealing PMS doesn't force the keys to be sent.\n  THEY ARE NOT SUITABLE AS SAFE ELIM RULES.*}\nlemma PMS_lemma:\n     \"[| Nonce PMS \\<notin> parts (spies evs);\n         K = sessionK((Na, Nb, PRF(PMS,NA,NB)), role);\n         evs \\<in> tls |]\n   ==> Key K \\<notin> parts (spies evs) & (\\<forall>Y. Crypt K Y \\<notin> parts (spies evs))\"\napply (erule rev_mp, erule ssubst)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB) \napply (force, simp_all (no_asm_simp))\ntxt{*Fake*}\napply (blast intro: parts_insertI)\ntxt{*SpyKeys*}\napply blast\ntxt{*Many others*}\napply (force dest!: Notes_Crypt_parts_spies Notes_master_imp_Crypt_PMS)+\ndone\n\nlemma PMS_sessionK_not_spied:\n     \"[| Key (sessionK((Na, Nb, PRF(PMS,NA,NB)), role)) \\<in> parts (spies evs);\n         evs \\<in> tls |]\n      ==> Nonce PMS \\<in> parts (spies evs)\"\nby (blast dest: PMS_lemma)\n\nlemma PMS_Crypt_sessionK_not_spied:\n     \"[| Crypt (sessionK((Na, Nb, PRF(PMS,NA,NB)), role)) Y\n           \\<in> parts (spies evs);  evs \\<in> tls |]\n      ==> Nonce PMS \\<in> parts (spies evs)\"\nby (blast dest: PMS_lemma)\n\ntext{*Write keys are never sent if M (MASTER SECRET) is secure.\n  Converse fails; betraying M doesn't force the keys to be sent!\n  The strong Oops condition can be weakened later by unicity reasoning,\n  with some effort.\n  NO LONGER USED: see @{text clientK_not_spied} and @{text serverK_not_spied}*}\nlemma sessionK_not_spied:\n     \"[| \\<forall>A. Says A Spy (Key (sessionK((NA,NB,M),role))) \\<notin> set evs;\n         Nonce M \\<notin> analz (spies evs);  evs \\<in> tls |]\n      ==> Key (sessionK((NA,NB,M),role)) \\<notin> parts (spies evs)\"\napply (erule rev_mp, erule rev_mp)\napply (erule tls.induct, analz_mono_contra)\napply (force, simp_all (no_asm_simp))\ntxt{*Fake, SpyKeys*}\napply blast+\ndone\n\n\ntext{*If A sends ClientKeyExch to an honest B, then the PMS will stay secret.*}\nlemma Spy_not_see_PMS:\n     \"[| Notes A {|Agent B, Nonce PMS|} \\<in> set evs;\n         evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad |]\n      ==> Nonce PMS \\<notin> analz (spies evs)\"\napply (erule rev_mp, erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp))\ntxt{*Fake*}\napply spy_analz\ntxt{*SpyKeys*}\napply force\napply (simp_all add: insert_absorb) \ntxt{*ClientHello, ServerHello, ClientKeyExch: mostly freshness reasoning*}\napply (blast dest: Notes_Crypt_parts_spies)\napply (blast dest: Notes_Crypt_parts_spies)\napply (blast dest: Notes_Crypt_parts_spies)\ntxt{*ClientAccepts and ServerAccepts: because @{term \"PMS \\<notin> range PRF\"}*}\napply force+\ndone\n\n\ntext{*If A sends ClientKeyExch to an honest B, then the MASTER SECRET\n  will stay secret.*}\nlemma Spy_not_see_MS:\n     \"[| Notes A {|Agent B, Nonce PMS|} \\<in> set evs;\n         evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad |]\n      ==> Nonce (PRF(PMS,NA,NB)) \\<notin> analz (spies evs)\"\napply (erule rev_mp, erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp))\ntxt{*Fake*}\napply spy_analz\ntxt{*SpyKeys: by secrecy of the PMS, Spy cannot make the MS*}\napply (blast dest!: Spy_not_see_PMS)\napply (simp_all add: insert_absorb)\ntxt{*ClientAccepts and ServerAccepts: because PMS was already visible;\n  others, freshness etc.*}\napply (blast dest: Notes_Crypt_parts_spies Spy_not_see_PMS \n                   Notes_imp_knows_Spy [THEN analz.Inj])+\ndone\n\n\n\nsubsubsection{*Weakening the Oops conditions for leakage of clientK*}\n\ntext{*If A created PMS then nobody else (except the Spy in replays)\n  would send a message using a clientK generated from that PMS.*}\nlemma Says_clientK_unique:\n     \"[| Says A' B' (Crypt (clientK(Na,Nb,PRF(PMS,NA,NB))) Y) \\<in> set evs;\n         Notes A {|Agent B, Nonce PMS|} \\<in> set evs;\n         evs \\<in> tls;  A' \\<noteq> Spy |]\n      ==> A = A'\"\napply (erule rev_mp, erule rev_mp)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all)\ntxt{*ClientKeyExch*}\napply (blast dest!: PMS_Crypt_sessionK_not_spied)\ntxt{*ClientFinished, ClientResume: by unicity of PMS*}\napply (blast dest!: Notes_master_imp_Notes_PMS \n             intro: Notes_unique_PMS [THEN conjunct1])+\ndone\n\n\ntext{*If A created PMS and has not leaked her clientK to the Spy,\n  then it is completely secure: not even in parts!*}\nlemma clientK_not_spied:\n     \"[| Notes A {|Agent B, Nonce PMS|} \\<in> set evs;\n         Says A Spy (Key (clientK(Na,Nb,PRF(PMS,NA,NB)))) \\<notin> set evs;\n         A \\<notin> bad;  B \\<notin> bad;\n         evs \\<in> tls |]\n      ==> Key (clientK(Na,Nb,PRF(PMS,NA,NB))) \\<notin> parts (spies evs)\"\napply (erule rev_mp, erule rev_mp)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp))\ntxt{*ClientKeyExch*}\napply blast \ntxt{*SpyKeys*}\napply (blast dest!: Spy_not_see_MS)\ntxt{*ClientKeyExch*}\napply (blast dest!: PMS_sessionK_not_spied)\ntxt{*Oops*}\napply (blast intro: Says_clientK_unique)\ndone\n\n\nsubsubsection{*Weakening the Oops conditions for leakage of serverK*}\n\ntext{*If A created PMS for B, then nobody other than B or the Spy would\n  send a message using a serverK generated from that PMS.*}\nlemma Says_serverK_unique:\n     \"[| Says B' A' (Crypt (serverK(Na,Nb,PRF(PMS,NA,NB))) Y) \\<in> set evs;\n         Notes A {|Agent B, Nonce PMS|} \\<in> set evs;\n         evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad;  B' \\<noteq> Spy |]\n      ==> B = B'\"\napply (erule rev_mp, erule rev_mp)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all)\ntxt{*ClientKeyExch*}\napply (blast dest!: PMS_Crypt_sessionK_not_spied)\ntxt{*ServerResume, ServerFinished: by unicity of PMS*}\napply (blast dest!: Notes_master_imp_Crypt_PMS \n             dest: Spy_not_see_PMS Notes_Crypt_parts_spies Crypt_unique_PMS)+\ndone\n\n\ntext{*If A created PMS for B, and B has not leaked his serverK to the Spy,\n  then it is completely secure: not even in parts!*}\nlemma serverK_not_spied:\n     \"[| Notes A {|Agent B, Nonce PMS|} \\<in> set evs;\n         Says B Spy (Key(serverK(Na,Nb,PRF(PMS,NA,NB)))) \\<notin> set evs;\n         A \\<notin> bad;  B \\<notin> bad;  evs \\<in> tls |]\n      ==> Key (serverK(Na,Nb,PRF(PMS,NA,NB))) \\<notin> parts (spies evs)\"\napply (erule rev_mp, erule rev_mp)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp))\ntxt{*Fake*}\napply blast \ntxt{*SpyKeys*}\napply (blast dest!: Spy_not_see_MS)\ntxt{*ClientKeyExch*}\napply (blast dest!: PMS_sessionK_not_spied)\ntxt{*Oops*}\napply (blast intro: Says_serverK_unique)\ndone\n\n\nsubsubsection{*Protocol goals: if A receives ServerFinished, then B is present\n     and has used the quoted values PA, PB, etc.  Note that it is up to A\n     to compare PA with what she originally sent.*}\n\ntext{*The mention of her name (A) in X assures A that B knows who she is.*}\nlemma TrustServerFinished [rule_format]:\n     \"[| X = Crypt (serverK(Na,Nb,M))\n               (Hash{|Number SID, Nonce M,\n                      Nonce Na, Number PA, Agent A,\n                      Nonce Nb, Number PB, Agent B|});\n         M = PRF(PMS,NA,NB);\n         evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad |]\n      ==> Says B Spy (Key(serverK(Na,Nb,M))) \\<notin> set evs -->\n          Notes A {|Agent B, Nonce PMS|} \\<in> set evs -->\n          X \\<in> parts (spies evs) --> Says B A X \\<in> set evs\"\napply (erule ssubst)+\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp))\ntxt{*Fake: the Spy doesn't have the critical session key!*}\napply (blast dest: serverK_not_spied)\ntxt{*ClientKeyExch*}\napply (blast dest!: PMS_Crypt_sessionK_not_spied)\ndone\n\ntext{*This version refers not to ServerFinished but to any message from B.\n  We don't assume B has received CertVerify, and an intruder could\n  have changed A's identity in all other messages, so we can't be sure\n  that B sends his message to A.  If CLIENT KEY EXCHANGE were augmented\n  to bind A's identity with PMS, then we could replace A' by A below.*}\nlemma TrustServerMsg [rule_format]:\n     \"[| M = PRF(PMS,NA,NB);  evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad |]\n      ==> Says B Spy (Key(serverK(Na,Nb,M))) \\<notin> set evs -->\n          Notes A {|Agent B, Nonce PMS|} \\<in> set evs -->\n          Crypt (serverK(Na,Nb,M)) Y \\<in> parts (spies evs)  -->\n          (\\<exists>A'. Says B A' (Crypt (serverK(Na,Nb,M)) Y) \\<in> set evs)\"\napply (erule ssubst)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp) add: ex_disj_distrib)\ntxt{*Fake: the Spy doesn't have the critical session key!*}\napply (blast dest: serverK_not_spied)\ntxt{*ClientKeyExch*}\napply (clarify, blast dest!: PMS_Crypt_sessionK_not_spied)\ntxt{*ServerResume, ServerFinished: by unicity of PMS*}\napply (blast dest!: Notes_master_imp_Crypt_PMS \n             dest: Spy_not_see_PMS Notes_Crypt_parts_spies Crypt_unique_PMS)+\ndone\n\n\nsubsubsection{*Protocol goal: if B receives any message encrypted with clientK\n      then A has sent it*}\n\ntext{*ASSUMING that A chose PMS.  Authentication is\n     assumed here; B cannot verify it.  But if the message is\n     ClientFinished, then B can then check the quoted values PA, PB, etc.*}\n\nlemma TrustClientMsg [rule_format]:\n     \"[| M = PRF(PMS,NA,NB);  evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad |]\n      ==> Says A Spy (Key(clientK(Na,Nb,M))) \\<notin> set evs -->\n          Notes A {|Agent B, Nonce PMS|} \\<in> set evs -->\n          Crypt (clientK(Na,Nb,M)) Y \\<in> parts (spies evs) -->\n          Says A B (Crypt (clientK(Na,Nb,M)) Y) \\<in> set evs\"\napply (erule ssubst)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp))\ntxt{*Fake: the Spy doesn't have the critical session key!*}\napply (blast dest: clientK_not_spied)\ntxt{*ClientKeyExch*}\napply (blast dest!: PMS_Crypt_sessionK_not_spied)\ntxt{*ClientFinished, ClientResume: by unicity of PMS*}\napply (blast dest!: Notes_master_imp_Notes_PMS dest: Notes_unique_PMS)+\ndone\n\n\nsubsubsection{*Protocol goal: if B receives ClientFinished, and if B is able to\n     check a CertVerify from A, then A has used the quoted\n     values PA, PB, etc.  Even this one requires A to be uncompromised.*}\nlemma AuthClientFinished:\n     \"[| M = PRF(PMS,NA,NB);\n         Says A Spy (Key(clientK(Na,Nb,M))) \\<notin> set evs;\n         Says A' B (Crypt (clientK(Na,Nb,M)) Y) \\<in> set evs;\n         certificate A KA \\<in> parts (spies evs);\n         Says A'' B (Crypt (invKey KA) (Hash{|nb, Agent B, Nonce PMS|}))\n           \\<in> set evs;\n         evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad |]\n      ==> Says A B (Crypt (clientK(Na,Nb,M)) Y) \\<in> set evs\"\nby (blast intro!: TrustClientMsg UseCertVerify)\n\n(*22/9/97: loads in 622s, which is 10 minutes 22 seconds*)\n(*24/9/97: loads in 672s, which is 11 minutes 12 seconds [stronger theorems]*)\n(*29/9/97: loads in 481s, after removing Certificate from ClientKeyExch*)\n(*30/9/97: loads in 476s, after removing unused theorems*)\n(*30/9/97: loads in 448s, after fixing ServerResume*)\n\n(*08/9/97: loads in 189s (pike), after much reorganization,\n           back to 621s on albatross?*)\n\n(*10/2/99: loads in 139s (pike)\n           down to 433s on albatross*)\n\n(*5/5/01: conversion to Isar script\n          loads in 137s (perch)\n          the last ML version loaded in 122s on perch, a 600MHz machine:\n                twice as fast as pike.  No idea why it's so much slower!\n          The Isar script is slower still, perhaps because simp_all simplifies\n          the assumptions be default.\n*)\n\n(*20/11/11: loads in 5.8s elapses time, 9.3s CPU time on dual-core laptop*)\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "isabelle", "sha": "990accf749b8a6e037d25012258ecae20d59ca62", "save_path": "github-repos/isabelle/Josh-Tilles-isabelle", "path": "github-repos/isabelle/Josh-Tilles-isabelle/isabelle-990accf749b8a6e037d25012258ecae20d59ca62/src/HOL/Auth/TLS.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7185943805178139, "lm_q2_score": 0.35936414516010196, "lm_q1q2_score": 0.2582370552716372}}
{"text": "theory SafeSubRename\n  imports WTLemma SubstExp\nbegin\n  \n\ndefinition rename_use_env where\n  \"rename_use_env r_s x y = (add_use_env (rem_use_env r_s x) y (r_s x))\"  \n  \nlemma rename_leq_use_env: \"\\<lbrakk> leq_use_env r_x r_s \\<rbrakk> \\<Longrightarrow>\n  leq_use_env (rename_use_env r_x x y) (rename_use_env r_s x y)\"\n  apply (simp add: leq_use_env_def)\n  apply (auto)\n  apply (simp add: rename_use_env_def)\n  apply (simp add: add_use_env_def)\n  apply (simp add: rem_use_env_def)\n  done\n  \nlemma rename_ereq_use_env: \"ereq_use_env y tau = rename_use_env (ereq_use_env x tau) x y\"\n  apply (case_tac \"\\<forall> x'. ereq_use_env y tau x' = rename_use_env (ereq_use_env x tau) x y x'\")\n   apply (auto)\n  apply (simp add: ereq_use_env_def)\n  apply (simp add: one_use_env_def)\n  apply (simp add: rename_use_env_def)\n  apply (simp add: add_use_env_def)\n  apply (case_tac \"y = x'\")\n   apply (auto)\n  apply (simp add: rem_use_env_def)\n  apply (case_tac \"x = x'\")\n   apply (auto)\n  done\n \nlemma rename_ereq_use_env2: \"\\<lbrakk> z \\<noteq> x ; z \\<noteq> y\\<rbrakk> \\<Longrightarrow> ereq_use_env z tau = rename_use_env (ereq_use_env z tau) x y\"    \n  apply (case_tac \"\\<forall> x'. ereq_use_env z tau x' = rename_use_env (ereq_use_env z tau) x y x'\")\n   apply (auto)\n  apply (simp add: ereq_use_env_def)\n  apply (simp add: one_use_env_def)\n  apply (simp add: rename_use_env_def)\n  apply (simp add: add_use_env_def)\n  apply (case_tac \"z = x'\")\n   apply (auto)\n   apply (simp add: rem_use_env_def)\n  apply (case_tac \"y = x'\")\n   apply (auto)\n  apply (simp add: rem_use_env_def)\n  apply (case_tac \"x = x'\")\n   apply (auto)\n  done    \n    \nlemma rename_req_use_env: \"req_use_env y tau = rename_use_env (req_use_env x tau) x y\"\n  apply (case_tac \"\\<forall> x'. req_use_env y tau x' = rename_use_env (req_use_env x tau) x y x'\")\n   apply (auto)\n  apply (simp add: req_use_env_def)\n  apply (simp add: one_use_env_def)\n  apply (simp add: rename_use_env_def)\n  apply (simp add: add_use_env_def)\n  apply (case_tac \"y = x'\")\n   apply (auto)\n  apply (simp add: rem_use_env_def)\n  apply (case_tac \"x = x'\")\n   apply (auto)\n  done\n \nlemma rename_req_use_env2: \"\\<lbrakk> z \\<noteq> x ; z \\<noteq> y\\<rbrakk> \\<Longrightarrow> req_use_env z tau = rename_use_env (req_use_env z tau) x y\"    \n  apply (case_tac \"\\<forall> x'. req_use_env z tau x' = rename_use_env (req_use_env z tau) x y x'\")\n   apply (auto)\n  apply (simp add: req_use_env_def)\n  apply (simp add: one_use_env_def)\n  apply (simp add: rename_use_env_def)\n  apply (simp add: add_use_env_def)\n  apply (case_tac \"z = x'\")\n   apply (auto)\n   apply (simp add: rem_use_env_def)\n  apply (case_tac \"y = x'\")\n   apply (auto)\n  apply (simp add: rem_use_env_def)\n  apply (case_tac \"x = x'\")\n   apply (auto)\n  done\n    \nlemma rename_add_use_env: \"add_use_env (rename_use_env r_s x y) y r = rename_use_env (add_use_env r_s x r) x y\"    \n  apply (case_tac \"\\<forall> x'. add_use_env (rename_use_env r_s x y) y r x' = rename_use_env (add_use_env r_s x r) x y x'\")\n   apply (auto)\n  apply (simp add: rename_use_env_def)\n  apply (simp add: add_use_env_def)  \n  apply (case_tac \"y = x'\")\n   apply (auto)\n  apply (simp add: rem_use_env_def)\n  apply (case_tac \"x = x'\")\n   apply (auto)\n  done\n\nlemma rename_add_use_env2: \"\\<lbrakk> z \\<noteq> x; z \\<noteq> y \\<rbrakk> \\<Longrightarrow> add_use_env (rename_use_env r_s x y) z r = rename_use_env (add_use_env r_s z r) x y\"    \n  apply (case_tac \"\\<forall> x'. add_use_env (rename_use_env r_s x y) z r x' = rename_use_env (add_use_env r_s z r) x y x'\")    \n   apply (auto)\n  apply (simp add: rename_use_env_def)\n  apply (simp add: add_use_env_def)  \n  apply (case_tac \"y = x'\")\n   apply (auto)\n  apply (simp add: rem_use_env_def)\n  apply (case_tac \"z = x'\")\n   apply (auto)\n  apply (simp add: rem_use_env_def)\n  apply (case_tac \"x = x'\")\n   apply (auto)\n  done\n \nlemma rename_add_use_env3: \"\\<lbrakk> r_s x = NoPerm \\<rbrakk> \\<Longrightarrow> add_use_env r_s y r = rename_use_env (add_use_env r_s x r) x y\"\n  apply (case_tac \"\\<forall> x'. add_use_env r_s y r x' = rename_use_env (add_use_env r_s x r) x y x'\")\n   apply (auto)\n  apply (simp add: rename_use_env_def)\n  apply (simp add: add_use_env_def)\n  apply (case_tac \"y = x'\")\n   apply (auto)\n  apply (simp add: rem_use_env_def)\n  apply (case_tac \"x = x'\")\n   apply (auto)\n  done\n  \nlemma rename_comp_use_env: \"comp_use_env (rename_use_env r_x x y) (rename_use_env r_s x y) = rename_use_env (comp_use_env r_x r_s) x y\"    \n  apply (case_tac \"\\<forall> x'. comp_use_env (rename_use_env r_x x y) (rename_use_env r_s x y) x' = rename_use_env (comp_use_env r_x r_s) x y x'\")\n   apply (auto)\n  apply (simp add: comp_use_env_def)\n  apply (simp add: rename_use_env_def)\n  apply (simp add: add_use_env_def)\n  apply (case_tac \"y = x'\")\n   apply (auto)\n  apply (simp add: rem_use_env_def)\n  apply (case_tac \"x = x'\")\n   apply (auto)\n  done\n    \nlemma rename_diff_use_env: \"diff_use_env (rename_use_env r_x x y) (rename_use_env r_s x y) = rename_use_env (diff_use_env r_x r_s) x y\"    \n  apply (case_tac \"\\<forall> x'. diff_use_env (rename_use_env r_x x y) (rename_use_env r_s x y) x' = rename_use_env (diff_use_env r_x r_s) x y x'\")\n  apply (auto)\n  apply (simp add: diff_use_env_def)\n  apply (simp add: rename_use_env_def)\n  apply (simp add: add_use_env_def)\n  apply (case_tac \"y = x'\")\n   apply (auto)\n  apply (simp add: rem_use_env_def)\n  apply (case_tac \"x = x'\")\n   apply (auto)\n  done\n    \nlemma rename_lift_use_env: \"lift_use_env (rename_use_env r_s x y) r = rename_use_env (lift_use_env r_s r) x y\"  \n  apply (case_tac \"\\<forall> x'. lift_use_env (rename_use_env r_s x y) r x' = rename_use_env (lift_use_env r_s r) x y x'\")\n   apply (auto)\n  apply (case_tac r)\n    apply (auto)\n  apply (simp add: rename_use_env_def)\n  apply (simp add: add_use_env_def)\n  apply (case_tac \"y = x'\")\n   apply (auto)\n   apply (simp add: rem_use_env_def)\n   apply (case_tac \"x = x'\")\n    apply (auto)\n  apply (simp add: rem_use_env_def)\n  apply (case_tac \"x = x'\")\n   apply (auto)\n  done\n  \nlemma aff_rename_use_env: \"\\<lbrakk> aff_use_env r_s a \\<rbrakk> \\<Longrightarrow> aff_use_env (rename_use_env r_s x y) a\"    \n  apply (simp add: aff_use_env_def)\n  apply (case_tac a)\n    apply (auto)\n   apply (simp add: rename_use_env_def)\n   apply (simp add: add_use_env_def)\n   apply (simp add: weak_use_env_def)\n   apply (auto)\n   apply (erule_tac x=\"xa\" in allE)\n   apply (simp add: rem_use_env_def)\n   apply (case_tac \"x = xa\")\n    apply (auto)\n  apply (simp add: rename_use_env_def)\n  apply (simp add: add_use_env_def)\n  apply (simp add: null_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (simp add: rem_use_env_def)\n  done\n  (*\nlemma safe_lift_rename_use_env: \"\\<lbrakk> safe_use_lift r_s r \\<rbrakk> \\<Longrightarrow> safe_use_lift (rename_use_env r_s x y) r\"\n  apply (simp add: rename_use_env_def)\n  apply (simp add: add_use_env_def)\n  apply (case_tac r)\n    apply (auto)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (simp add: rem_use_env_def)\n  apply (case_tac \"x = xa\")\n   apply (auto)\n  done*)\n\nlemma disj_rename_use_env: \"\\<lbrakk> disj_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> disj_use_env (rename_use_env r_x x y) (rename_use_env r_s x y)\"\n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (auto)\n   apply (simp add: rename_use_env_def)\n   apply (simp add: add_use_env_def)\n   apply (auto)\n   apply (simp add: rem_use_env_def)\n   apply (auto)\n  apply (simp add: rename_use_env_def)\n  apply (simp add: add_use_env_def)\n  apply (auto)\n  apply (simp add: rem_use_env_def)\n  apply (auto)\n  done\n    \n    \nlemma artp_var_case1: \"\\<lbrakk>y \\<noteq> x; add_env env (Var x) t (Var x) = Some tau_x; leq_use_env (ereq_use_env (Var x) tau_x) r_s1;\n        leq_use_env r_s2 (diff_use_env r_s1 (comp_use_env (ereq_use_env (Var x) tau_x) r_ex)); leq_use_env rx r_s2; leq_use_env r_ex r_s1;\n        leq_use_env (diff_use_env (ereq_use_env (Var x) tau_x) (comp_use_env (ereq_use_env (Var x) tau_x) r_ex)) rx\\<rbrakk>\n       \\<Longrightarrow> \\<exists>r_ex tau_x.\n              add_env env (Var y) t (Var y) = Some tau_x \\<and>\n              leq_use_env (ereq_use_env (Var y) tau_x) (rename_use_env r_s1 (Var x) (Var y)) \\<and>\n              leq_use_env (rename_use_env r_s2 (Var x) (Var y))\n               (diff_use_env (rename_use_env r_s1 (Var x) (Var y)) (comp_use_env (ereq_use_env (Var y) tau_x) r_ex)) \\<and>\n              leq_use_env (rename_use_env rx (Var x) (Var y)) (rename_use_env r_s2 (Var x) (Var y)) \\<and>\n              leq_use_env r_ex (rename_use_env r_s1 (Var x) (Var y)) \\<and>\n              leq_use_env (diff_use_env (ereq_use_env (Var y) tau_x) (comp_use_env (ereq_use_env (Var y) tau_x) r_ex)) (rename_use_env rx (Var x) (Var y))\"\n  apply (simp add: add_env_def)\n  apply (auto)\n   apply (case_tac \"\\<not> leq_perm (end_req_perm tau_x) (r_s1 (Var x))\")\n    apply (cut_tac r_x=\"ereq_use_env (Var x) tau_x\" and r_s=\"r_s1\" and x=\"Var x\" in spec_leq_perm)\n     apply (simp)\n    apply (simp add: ereq_use_env_def)\n    apply (simp add: one_use_env_def)\n   apply (simp add: leq_use_env_def)\n   apply (simp add: ereq_use_env_def)\n   apply (simp add: one_use_env_def)\n   apply (simp add: rename_use_env_def)\n   apply (simp add: add_use_env_def)\n  apply (cut_tac x=\"Var x\" and y=\"Var y\" and tau=\"tau_x\" in rename_ereq_use_env)\n  apply (simp)\n  apply (case_tac \"\\<not> comp_use_env (ereq_use_env (Var y) tau_x) (rename_use_env r_ex (Var x) (Var y)) =\n    rename_use_env (comp_use_env (ereq_use_env (Var x) tau_x) r_ex) (Var x) (Var y)\")\n   apply (cut_tac r_x=\"ereq_use_env (Var x) tau_x\" and r_s=\"r_ex\" and x=\"Var x\" and y=\"Var y\" in rename_comp_use_env)\n   apply (simp)\n  apply (rule_tac x=\"rename_use_env r_ex (Var x) (Var y)\" in exI)\n  apply (auto)\n     apply (cut_tac r_x=\"r_s1\" and r_s=\"comp_use_env (ereq_use_env (Var x) tau_x) r_ex\" and x=\"Var x\" and y=\"Var y\" in rename_diff_use_env)\n     apply (simp)\n     apply (rule_tac rename_leq_use_env)\n     apply (simp)\n    apply (rule_tac rename_leq_use_env)\n    apply (simp)\n   apply (rule_tac rename_leq_use_env)\n   apply (simp)\n  apply (cut_tac r_x=\"ereq_use_env (Var x) tau_x\" and r_s=\"comp_use_env (ereq_use_env (Var x) tau_x) r_ex\" and x=\"Var x\" and y=\"Var y\" in rename_diff_use_env)\n  apply (simp)\n  apply (rule_tac rename_leq_use_env)\n  apply (simp)\n  done\n\n  \nlemma artp_var_case2: \"\\<lbrakk>Var y \\<noteq> xa; add_env env (Var x) t xa = Some tau_x; leq_use_env (ereq_use_env xa tau_x) r_s1;\n        leq_use_env r_s2 (diff_use_env r_s1 (comp_use_env (ereq_use_env xa tau_x) r_ex)); leq_use_env rx r_s2; leq_use_env r_ex r_s1;\n        leq_use_env (diff_use_env (ereq_use_env xa tau_x) (comp_use_env (ereq_use_env xa tau_x) r_ex)) rx; Var x \\<noteq> xa\\<rbrakk>\n       \\<Longrightarrow> leq_use_env (ereq_use_env xa tau_x) (rename_use_env r_s1 (Var x) (Var y)) \\<and>\n           (\\<exists>r_ex. leq_use_env (rename_use_env r_s2 (Var x) (Var y))\n                    (diff_use_env (rename_use_env r_s1 (Var x) (Var y)) (comp_use_env (ereq_use_env xa tau_x) r_ex)) \\<and>\n                   leq_use_env (rename_use_env rx (Var x) (Var y)) (rename_use_env r_s2 (Var x) (Var y)) \\<and>\n                   leq_use_env r_ex (rename_use_env r_s1 (Var x) (Var y)) \\<and>\n                   leq_use_env (diff_use_env (ereq_use_env xa tau_x) (comp_use_env (ereq_use_env xa tau_x) r_ex)) (rename_use_env rx (Var x) (Var y)))\"\n  apply (auto)\n   apply (case_tac \"\\<not>  leq_use_env (ereq_use_env xa tau_x) (rename_use_env r_s1 (Var x) (Var y)) = \n    leq_use_env (rename_use_env (ereq_use_env xa tau_x) (Var x) (Var y)) (rename_use_env r_s1 (Var x) (Var y))\")\n    apply (cut_tac z=\"xa\" and x=\"Var x\" and y=\"Var y\" and tau=\"tau_x\" in rename_ereq_use_env2)\n      apply (simp_all)\n   apply (rule_tac rename_leq_use_env)\n   apply (simp)\n  apply (case_tac \"\\<not> rename_use_env (ereq_use_env xa tau_x) (Var x) (Var y) = ereq_use_env xa tau_x\")\n   apply (cut_tac z=\"xa\" and x=\"Var x\" and y=\"Var y\" and tau=\"tau_x\" in rename_ereq_use_env2)\n  apply (simp_all)\n  apply (cut_tac r_x=\"ereq_use_env xa tau_x\" and r_s=\"r_ex\" and x=\"Var x\" and y=\"Var y\" in rename_comp_use_env)\n  apply (simp_all)\n  apply (rule_tac x=\"rename_use_env r_ex (Var x) (Var y)\" in exI)\n  apply (auto)\n     apply (cut_tac r_x=\"r_s1\" and r_s=\"comp_use_env (ereq_use_env xa tau_x) r_ex\" and x=\"Var x\" and y=\"Var y\" in rename_diff_use_env)\n     apply (simp_all)\n     apply (rule_tac rename_leq_use_env)\n     apply (simp)\n    apply (rule_tac rename_leq_use_env)\n    apply (simp)\n   apply (rule_tac rename_leq_use_env)\n   apply (simp)\n  apply (cut_tac r_x=\"ereq_use_env xa tau_x\" and r_s=\"comp_use_env (ereq_use_env xa tau_x) r_ex\" and x=\"Var x\" and y=\"Var y\" in rename_diff_use_env)\n  apply (simp_all)\n  apply (rule_tac rename_leq_use_env)\n  apply (simp)\n  done\n    \nlemma alpha_rename_type_preserve: \"\\<lbrakk> well_typed (add_env env (Var x) t) r_s1 e tau r_s2 rx; (*env x = None;*)\n  y \\<notin> free_vars e; y \\<notin> lam_vars e \\<rbrakk> \\<Longrightarrow>\n  well_typed (add_env env (Var y) t) (rename_use_env r_s1 (Var x) (Var y)) (deep_alpha_rename e x y) tau\n    (rename_use_env r_s2 (Var x) (Var y)) (rename_use_env rx (Var x) (Var y))\"\n  apply (induct e arbitrary: env tau t r_s1 r_s2 rx)\n        apply (auto)\n    (* const + op cases *)\n           apply (rule_tac x=\"Var x\" in rename_leq_use_env)\n           apply (simp_all)\n          apply (rule_tac x=\"Var x\" in rename_leq_use_env)\n          apply (simp_all)\n         apply (rule_tac x=\"Var x\" in rename_leq_use_env)\n         apply (simp_all)\n        apply (rule_tac x=\"Var x\" in rename_leq_use_env)\n        apply (simp_all)\n    (* var case. *)\n       apply (case_tac \"xa = VarType x\")\n        apply (auto)\n         apply (simp add: add_env_def)\n        apply (rule_tac artp_var_case1)\n              apply (auto)\n       apply (case_tac xa)\n        apply (auto)\n          apply (simp add: add_env_def)\n         apply (simp add: add_env_def)\n         apply (rule_tac artp_var_case2)\n                apply (auto)\n         apply (simp add: add_env_def)\n        apply (simp add: add_env_def)\n       apply (simp add: add_env_def)\n       apply (rule_tac artp_var_case2)\n              apply (auto)\n       apply (simp add: add_env_def)\n    (* pair case *)\n        apply (cut_tac r_s=\"rx1\" and x=\"Var x\" and y=\"Var y\" and r=\"r\" in rename_lift_use_env)\n        apply (cut_tac r_s=\"rx2\" and x=\"Var x\" and y=\"Var y\" and r=\"r\" in rename_lift_use_env)\n        apply (rule_tac x=\"rename_use_env r_s2a (Var x) (Var y)\" in exI)\n        apply (rule_tac x=\"rename_use_env r_s3 (Var x) (Var y)\" in exI)\n        apply (rule_tac x=\"rename_use_env rx1 (Var x) (Var y)\" in exI)\n        apply (auto)\n        apply (rule_tac x=\"rename_use_env rx2 (Var x) (Var y)\" in exI)\n        apply (auto)\n             apply (rule_tac rename_leq_use_env)\n             apply (simp)\n            apply (rule_tac rename_leq_use_env)\n            apply (simp)(*\n           apply (rule_tac safe_lift_rename_use_env)\n           apply (simp)\n          apply (rule_tac safe_lift_rename_use_env)\n          apply (simp)*)\n         apply (rule_tac disj_rename_use_env)\n         apply (simp)\n        apply (cut_tac r_x=\"r_s3\" and r_s=\"r_ex\" and x=\"Var x\" and y=\"Var y\" in rename_diff_use_env)\n        apply (rule_tac x=\"rename_use_env r_ex (Var x) (Var y)\" in exI)\n        apply (auto)\n           apply (rule_tac rename_leq_use_env)\n           apply (simp)\n          apply (rule_tac rename_leq_use_env)\n          apply (simp)\n         apply (rule_tac rename_leq_use_env)\n         apply (simp)\n        apply (case_tac \"req_type (PairTy t1 t2 r) = Prim\")\n         apply (simp add: pair_req_def)\n         apply (rule_tac leq_empty_use_env)\n        apply (simp add: pair_req_def)\n        apply (simp add: rename_comp_use_env)\n        apply (simp add: rename_diff_use_env)\n        apply (rule_tac rename_leq_use_env)\n        apply (simp)\n    (* if case *)\n       apply (rule_tac x=\"rename_use_env rx' (Var x) (Var y)\" in exI)\n       apply (rule_tac x=\"rename_use_env r_s2a (Var x) (Var y)\" in exI)\n       apply (auto)\n       apply (rule_tac x=\"rename_use_env rx1 (Var x) (Var y)\" in exI)\n       apply (auto)\n       apply (rule_tac x=\"rename_use_env rx2 (Var x) (Var y)\" in exI)\n       apply (auto)\n       apply (cut_tac r_x=\"rx1\" and r_s=\"rx2\" and x=\"Var x\" and y=\"Var y\" in rename_comp_use_env)\n       apply (auto)\n    (* lam case p1. *)(*\n      apply (cut_tac y=\"Var y\" and x=\"Var x\" and e=\"e\" in rename_ref_vars2)\n        apply (auto)*)\n     apply (rule_tac x=\"rename_use_env rxa (Var x) (Var y)\" in exI)\n     apply (auto)\n        apply (rule_tac x=\"rename_use_env r_end (Var x) (Var y)\" in exI)\n        apply (rule_tac x=\"rename_use_env r_s' (Var x) (Var y)\" in exI)\n        apply (cut_tac env=\"env\" and x=\"Var x\" and t=\"t\" and t'=\"t1\" in double_add_env)\n        apply (cut_tac env=\"env\" and x=\"Var y\" and t=\"t\" and t'=\"t1\" in double_add_env)\n        apply (cut_tac r_s=\"rxa\" and x=\"Var x\" and y=\"Var y\" and r=\"r\" in rename_add_use_env)\n        apply (simp)\n       apply (rule_tac aff_rename_use_env)\n       apply (simp)\n      apply (rule_tac rename_leq_use_env)\n      apply (simp)\n     apply (rule_tac x=\"rename_use_env r_ex (Var x) (Var y)\" in exI)\n     apply (auto)\n        apply (cut_tac r_x=\"r_s1\" and r_s=\"r_ex\" and x=\"Var x\" and y=\"Var y\" in rename_diff_use_env)\n        apply (simp)\n        apply (rule_tac rename_leq_use_env)\n        apply (simp)\n       apply (rule_tac rename_leq_use_env)\n       apply (simp)\n      apply (rule_tac rename_leq_use_env)\n      apply (simp)\n     apply (cut_tac r_x=\"rxa\" and r_s=\"r_ex\" and x=\"Var x\" and y=\"Var y\" in rename_diff_use_env)\n     apply (simp)\n     apply (rule_tac rename_leq_use_env)\n     apply (simp)\n    (* lam case p2. *)(*\n    apply (cut_tac z=\"x1a\" and x=\"Var x\" and y=\"Var y\" and e=\"e\" in rename_ref_vars1)\n      apply (auto)*)\n   apply (rule_tac x=\"rename_use_env rxa (Var x) (Var y)\" in exI)\n   apply (auto)\n      apply (rule_tac x=\"rename_use_env r_end (Var x) (Var y)\" in exI)\n      apply (rule_tac x=\"rename_use_env r_s' (Var x) (Var y)\" in exI)\n      apply (cut_tac env=\"env\" and x=\"Var x1a\" and y=\"Var x\" and t=\"t\" and t'=\"t1\" in almost_comm_add_env)\n       apply (simp_all)\n      apply (cut_tac env=\"env\" and x=\"Var x1a\" and y=\"Var y\" and t=\"t\" and t'=\"t1\" in almost_comm_add_env)\n       apply (simp_all)\n      apply (cut_tac r_s=\"rxa\" and x=\"Var x\" and y=\"Var y\" and z=\"Var x1a\" and r=\"r\" in rename_add_use_env2)\n        apply (simp_all)\n     apply (rule_tac aff_rename_use_env)\n     apply (simp)\n    apply (rule_tac rename_leq_use_env)\n    apply (simp)\n   apply (rule_tac x=\"rename_use_env r_ex (Var x) (Var y)\" in exI)\n   apply (auto)\n      apply (cut_tac r_x=\"r_s1\" and r_s=\"r_ex\" and x=\"Var x\" and y=\"Var y\" in rename_diff_use_env)\n      apply (simp)\n      apply (rule_tac rename_leq_use_env)\n      apply (simp)\n     apply (rule_tac rename_leq_use_env)\n     apply (simp)\n    apply (rule_tac rename_leq_use_env)\n    apply (simp)\n   apply (cut_tac r_x=\"rxa\" and r_s=\"r_ex\" and x=\"Var x\" and y=\"Var y\" in rename_diff_use_env)\n   apply (simp)\n   apply (rule_tac rename_leq_use_env)\n   apply (simp)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"rename_use_env r_s2a (Var x) (Var y)\" in exI)\n  apply (rule_tac x=\"rename_use_env rx1 (Var x) (Var y)\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rename_use_env rx2 (Var x) (Var y)\" in exI)\n  apply (rule_tac x=\"rename_use_env r_s3 (Var x) (Var y)\" in exI)\n  apply (auto)\n  apply (cut_tac r_s=\"rx2\" and x=\"Var x\" and y=\"Var y\" and r=\"r\" in rename_lift_use_env)\n  apply (simp)\n  apply (cut_tac r_x=\"rx1\" and r_s=\"lift_use_env rx2 r\" and x=\"Var x\" and y=\"Var y\" in rename_comp_use_env)\n  apply (cut_tac r_x=\"comp_use_env rx1 (lift_use_env rx2 r)\" and r_s=\"r_ex\" and x=\"Var x\" and y=\"Var y\" in rename_comp_use_env)\n  apply (rule_tac x=\"rename_use_env r_ex (Var x) (Var y)\" in exI)\n  apply (auto)\n        apply (cut_tac r_x=\"r_s3\" and r_s=\"comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex\" and x=\"Var x\" and y=\"Var y\" in rename_diff_use_env)\n        apply (simp)\n        apply (rule_tac rename_leq_use_env)\n        apply (simp)(*\n       apply (rule_tac safe_lift_rename_use_env)\n       apply (simp)*)\n      apply (rule_tac rename_leq_use_env)\n      apply (simp)\n     apply (rule_tac disj_rename_use_env)\n     apply (simp)\n    apply (rule_tac rename_leq_use_env)\n    apply (simp)\n   apply (rule_tac rename_leq_use_env)\n   apply (simp)\n  apply (simp add: app_req_def)\n  apply (auto)\n   apply (rule_tac leq_empty_use_env)\n  apply (cut_tac r_x=\"rx1\" and r_s=\"rx2\" and x=\"Var x\" and y=\"Var y\" in rename_comp_use_env)\n  apply (simp)\n  apply (cut_tac r_x=\"comp_use_env rx1 rx2\" and r_s=\"comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex\" and x=\"Var x\" and y=\"Var y\" in rename_diff_use_env)\n  apply (simp)\n  apply (rule_tac rename_leq_use_env)\n  apply (simp)\n  done\n    \n\nlemma alpha_rename_free_var_id: \"\\<lbrakk> x \\<noteq> y \\<rbrakk> \\<Longrightarrow> x \\<notin> free_vars (deep_alpha_rename e x y)\"\n  apply (induct e)\n        apply (auto)\n  apply (case_tac xa)\n   apply (auto)\n  apply (case_tac \"x = x1\")\n   apply (auto)\n  done       \n\nlemma alpha_rename_free_var_none: \"\\<lbrakk> a \\<notin> free_vars e; a \\<noteq> y \\<rbrakk> \\<Longrightarrow> a \\<notin> free_vars (deep_alpha_rename e x y)\"     \n  apply (induction e)\n        apply (auto)\n   apply (case_tac xa)\n    apply (auto)\n   apply (case_tac \"x = x1\")\n    apply (auto)\n  apply (cut_tac e=\"e\" and x=\"a\" and y=\"y\" in alpha_rename_free_var_id)\n   apply (auto)\n  done\n    \nlemma alpha_rename_lam_var_none: \"\\<lbrakk> a \\<notin> lam_vars e; a \\<noteq> y \\<rbrakk> \\<Longrightarrow> a \\<notin> lam_vars (deep_alpha_rename e x y)\"  \n  apply (induct e)\n       apply (auto)\n  apply (case_tac xa)\n   apply (auto)\n  apply (case_tac \"x = x1\")\n   apply (auto)\n  done\n  \nlemma lam_var_remove_free_var_none: \"\\<lbrakk> x \\<notin> free_vars e \\<rbrakk> \\<Longrightarrow> x \\<notin> free_vars (lam_var_remove e a b)\"    \n  apply (induct e)\n       apply (auto)\n   apply (case_tac \"x \\<noteq> b\")\n    apply (cut_tac e=\"e\" and a=\"x\" and x=\"a\" and y=\"b\" in alpha_rename_free_var_none)\n      apply (auto)\n  apply (case_tac \"x \\<noteq> b\")\n   apply (cut_tac e=\"e\" and x=\"x\" and y=\"b\" in alpha_rename_free_var_id)\n    apply (auto)\n  done\n\nlemma lam_var_remove_lam_var_none: \"\\<lbrakk> x \\<notin> lam_vars e; x \\<noteq> b \\<rbrakk> \\<Longrightarrow> x \\<notin> lam_vars (lam_var_remove e a b)\"  \n  apply (induct e)  \n       apply (auto)\n  apply (cut_tac a=\"x\" and e=\"e\" and x=\"a\" and y=\"b\" in alpha_rename_lam_var_none)\n    apply (auto)\n  done    \n    \nlemma lam_var_remove_type_preserve: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; y \\<notin> free_vars e; y \\<notin> lam_vars e \\<rbrakk> \\<Longrightarrow>\n  well_typed env r_s1 (lam_var_remove e x y) tau r_s2 rx\"\n  apply (induct e arbitrary: env tau r_s1 r_s2 rx)\n        apply (auto)\n    (* pair case *)\n      apply (rule_tac x=\"r_s2a\" in exI)\n      apply (rule_tac x=\"r_s3\" in exI)\n      apply (rule_tac x=\"rx1\" in exI)\n      apply (auto)\n      apply (rule_tac x=\"rx2\" in exI)\n      apply (auto)\n    (* if case *)\n     apply (rule_tac x=\"rx'\" in exI)\n     apply (rule_tac x=\"r_s2a\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx1\" in exI)\n     apply (auto)\n     apply (rule_tac x=\"rx2\" in exI)\n     apply (auto)\n    (* lam case p1. *)\n    apply (rule_tac x=\"rxa\" in exI)\n    apply (auto)\n    apply (rule_tac x=\"rename_use_env r_end (Var x) (Var y)\" in exI)\n    apply (rule_tac x=\"rename_use_env r_s' (Var x) (Var y)\" in exI)\n    apply (rule_tac ?r_s1.0=\"rem_use_env (add_use_env rxa (Var y) r) (Var x)\" in well_typed_incr_start_perm)\n     apply (cut_tac r_s=\"rxa\" and x=\"Var y\" and y=\"Var x\" and r=\"r\" in almost_comm_rem_add_use_env)\n      apply (simp_all)\n     apply (case_tac \"\\<not> add_use_env (rem_use_env rxa (Var x)) (Var y) r = rename_use_env (add_use_env rxa (Var x) r) (Var x) (Var y)\")\n      apply (case_tac \"\\<not> (\\<forall> x'. add_use_env (rem_use_env rxa (Var x)) (Var y) r x' = rename_use_env (add_use_env rxa (Var x) r) (Var x) (Var y) x')\")\n       apply (auto)\n      apply (simp add: rename_use_env_def)\n      apply (simp add: add_use_env_def)\n      apply (case_tac \"Var y = x'\")\n       apply (auto)\n      apply (simp add: rem_use_env_def)\n      apply (case_tac \"Var x = x'\")\n       apply (auto)\n     apply (rule_tac alpha_rename_type_preserve)\n       apply (simp_all)\n    apply (rule_tac self_rem_leq_use_env)\n    (* lam case p2. *)\n   apply (rule_tac x=\"rxa\" in exI)\n   apply (auto)\n   apply (rule_tac x=\"r_end\" in exI)\n   apply (rule_tac x=\"r_s'\" in exI)\n   apply (auto)\n    (* app case *)\n  apply (rule_tac x=\"t1\" in exI)\n  apply (rule_tac x=\"r\" in exI)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"r_s2a\" in exI)\n  apply (rule_tac x=\"rx1\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"rx2\" in exI)\n  apply (rule_tac x=\"r_s3\" in exI)\n  apply (auto)\n  done    \n    \n    (* basically, we want to make sure that when we replace a var, we dont end up with the post_vars of vl overlapping with\n      any of the ref vars of e. in other words, that we arent changing any of the ref vars. now the thing is, when we do lam var remove,\n      we dont expect any of the ref vars to change actually  *)\nlemma lam_var_list_remove_type_preserve: \"\\<lbrakk> well_typed env r_s1 e tau r_s2 rx; unique_post_vars vl;(* pre_vars vl \\<subseteq> lam_vars e;*)\n  post_vars vl \\<inter> (free_vars e \\<union> lam_vars e) = {} \\<rbrakk> \\<Longrightarrow> well_typed env r_s1 (lam_var_list_remove e vl) tau r_s2 rx\"\n  apply (induct vl arbitrary: e)\n   apply (auto)\n  apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s1\" and e=\"e\" and tau=\"tau\" and ?r_s2.0=\"r_s2\" and rx=\"rx\" and x=\"a\" and y=\"b\" in lam_var_remove_type_preserve)\n      apply (auto)\n  apply (case_tac \"\\<not> post_vars vl \\<inter> (free_vars (lam_var_remove e a b) \\<union> lam_vars (lam_var_remove e a b)) = {}\")\n   apply (auto)\n    apply (cut_tac e=\"e\" and x=\"x\" and a=\"a\" and b=\"b\" in lam_var_remove_free_var_none)\n     apply (auto)\n  apply (cut_tac e=\"e\" and x=\"x\" and a=\"a\" and b=\"b\" in lam_var_remove_lam_var_none)\n    apply (auto)\n  done         \n    \n \nlemma alpha_rename_free_var_some: \"\\<lbrakk> x \\<in> free_vars e; x \\<noteq> a; x \\<noteq> b \\<rbrakk> \\<Longrightarrow> x \\<in> free_vars (deep_alpha_rename e a b)\"    \n  apply (induct e)\n        apply (auto)\n  apply (case_tac xa)\n   apply (auto)\n  done\n    \nlemma lam_var_remove_free_var_some: \"\\<lbrakk> x \\<in> free_vars e; x \\<noteq> b \\<rbrakk> \\<Longrightarrow> x \\<in> free_vars (lam_var_remove e a b)\"    \n  apply (induct e)\n       apply (auto)\n  apply (rule_tac alpha_rename_free_var_some)\n    apply (auto)\n  done    \n    \nlemma lam_var_list_remove_free_var_some: \"\\<lbrakk> x \\<in> free_vars e; x \\<notin> post_vars vl \\<rbrakk> \\<Longrightarrow> x \\<in> free_vars (lam_var_list_remove e vl)\"    \n  apply (induct vl arbitrary: e)\n   apply (auto)\n  apply (cut_tac x=\"x\" and e=\"e\" and a=\"a\" and b=\"b\" in lam_var_remove_free_var_some)\n    apply (auto)\n  done        \n    \nlemma lam_var_list_remove_lam_var_none1: \"\\<lbrakk> x \\<notin> lam_vars e; x \\<notin> post_vars vl \\<rbrakk> \\<Longrightarrow> x \\<notin> lam_vars (lam_var_list_remove e vl)\"        \n  apply (induct vl arbitrary: e)\n   apply (auto)\n  apply (cut_tac e=\"e\" and x=\"x\" and a=\"a\" and b=\"b\" in lam_var_remove_lam_var_none)\n    apply (auto)\n  done\n    \nlemma alpha_rename_lam_var_none2: \"\\<lbrakk> x \\<noteq> b \\<rbrakk> \\<Longrightarrow> x \\<notin> lam_vars (deep_alpha_rename e x b)\"    \n  apply (induct e)\n        apply (auto)\n  apply (case_tac xa)\n   apply (auto)\n  apply (case_tac \"x = x1\")\n   apply (auto)\n  done\n    \nlemma lam_var_remove_lam_var_none2: \"\\<lbrakk> x \\<noteq> b \\<rbrakk> \\<Longrightarrow> x \\<notin> lam_vars (lam_var_remove e x b)\"    \n  apply (induct e)\n       apply (auto)\n  apply (cut_tac e=\"e\" and x=\"x\" and b=\"b\" in alpha_rename_lam_var_none2)\n   apply (auto)\n  done    \n    \nlemma lam_var_list_remove_lam_var_none2: \"\\<lbrakk> x \\<in> pre_vars vl; x \\<notin> post_vars vl \\<rbrakk> \\<Longrightarrow> x \\<notin> lam_vars (lam_var_list_remove e vl)\"    \n  apply (induct vl arbitrary: e)\n   apply (auto)\n  apply (cut_tac e=\"e\" and x=\"x\" and b=\"b\" in lam_var_remove_lam_var_none2)\n   apply (auto)\n  apply (cut_tac e=\"lam_var_remove e x b\" and x=\"x\" and vl=\"vl\" in lam_var_list_remove_lam_var_none1)\n    apply (auto)\n  done        \n    \nlemma lam_var_list_remove_free_var_some_rev: \"\\<lbrakk> x \\<in> free_vars (lam_var_list_remove e vl) \\<rbrakk> \\<Longrightarrow> x \\<in> free_vars e\"\n  apply (induction vl arbitrary: e)\n   apply (auto)\n  apply (case_tac \"x \\<notin> free_vars e\")\n   apply (auto)\n  apply (cut_tac x=\"x\" and e=\"e\" and a=\"a\" and b=\"b\" in lam_var_remove_free_var_none)\n   apply (auto)\n  done\n \nlemma lam_var_list_remove_free_var_none: \"\\<lbrakk> x \\<notin> free_vars e \\<rbrakk> \\<Longrightarrow> x \\<notin> free_vars (lam_var_list_remove e vl)\"    \n  apply (case_tac \"x \\<in> free_vars (lam_var_list_remove e vl)\")\n   apply (auto)\n  apply (cut_tac x=\"x\" and e=\"e\" and vl=\"vl\" in lam_var_list_remove_free_var_some_rev)\n   apply (auto)\n  done        \n\n    \nend", "meta": {"author": "anon-ef", "repo": "perm_lang_ef2", "sha": "0fcb6e4c175193cc7b94f297a8aaa605f502d711", "save_path": "github-repos/isabelle/anon-ef-perm_lang_ef2", "path": "github-repos/isabelle/anon-ef-perm_lang_ef2/perm_lang_ef2-0fcb6e4c175193cc7b94f297a8aaa605f502d711/perm_ref/SafeSubRename.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6001883735630721, "lm_q2_score": 0.4301473485858429, "lm_q1q2_score": 0.2581694375402049}}
{"text": "theory UPPAAL_State_Networks_Impl\n  imports TA_Impl.Normalized_Zone_Semantics_Impl UPPAAL_State_Networks\nbegin\n\nchapter \\<open>Implementation of UPPAAL Style Networks\\<close>\n\nno_notation OR (infix \"or\" 60)\n\nlemma step_resets:\n  \"\\<forall> c \\<in> set r'. \\<exists> x pc. Some (INSTR (STOREC c x)) = P pc\"\n  if \"stepc cmd u (pc, st, s, f, r) = Some (pc', st', s', f', r')\"\n    \"\\<forall> c \\<in> set r. \\<exists> x pc. Some (INSTR (STOREC c x)) = P pc\" \"P pc = Some cmd\"\n  using that\n  apply -\n  apply (erule stepc.elims)\n  by (auto split: option.splits if_splits elim!: step.elims) metis+\n\nlemma step_resets':\n  \"\\<forall> c \\<in> set r'. \\<exists> x pc. Some (INSTR (STOREC c x)) = P pc\"\n  if \"step instr (pc, st, s, f, r) = Some (pc', st', s', f', r')\"\n    \"\\<forall> c \\<in> set r. \\<exists> x pc. Some (INSTR (STOREC c x)) = P pc\" \"P pc = Some (INSTR instr)\"\n  using that\n  by (auto split: option.splits if_splits elim!: step.elims) metis+\n\nlemma step_resets'':\n  \"\\<forall> c \\<in> set r'. \\<exists> x pc. Some (STOREC c x) = P pc\"\n  if \"step instr (pc, st, s, f, r) = Some (pc', st', s', f', r')\"\n    \"\\<forall> c \\<in> set r. \\<exists> x pc. Some (STOREC c x) = P pc\" \"P pc = Some instr\"\n  using that\n  by (auto split: option.splits if_splits elim!: step.elims) metis+\n\nlemma steps_reset:\n  \"\\<forall> c \\<in> set r'. \\<exists> x pc. Some (STOREC c x) = P pc\"\n  if \"steps P n (pc, st, s, f, r) (pc', st', s', f', r')\" \"\\<forall> c \\<in> set r. \\<exists> x pc. Some (STOREC c x) = P pc\"\n  using that\n  by (induction P \\<equiv> P n \"(pc, st, s, f, r :: nat list)\" \"(pc', st', s', f', r')\" arbitrary: pc st s f r rule: steps.induct)\n     (auto dest!: step_resets''[where P = P])\n\nlemma exec_reset:\n  \"\\<forall> c \\<in> set r'. \\<exists> x pc. Some (STOREC c x) = P pc\"\n  if \"Some ((pc', st', s', f', r'), pcs') = exec P n (pc, st, s, f, []) pcs\"\n  using exec_steps[OF that[symmetric]] steps_reset by force\n\nlemma exec_pointers:\n  \"\\<forall> pc \\<in> set pcs'. \\<exists> pc instr. Some instr = P pc\"\n  if \"Some ((pc', st', s', f', r'), pcs') = exec P n (pc, st, s, f, r) pcs\"\n     \"\\<forall> pc \\<in> set pcs. \\<exists> pc instr. Some instr = P pc\"\n  using that\n  apply (induction rule: exec.induct)\n  by (auto split: option.splits if_splits) metis+\n\nlemma exec_pointers':\n  \"\\<forall> pc \\<in> set pcs'. \\<exists> pc instr. Some instr = P pc\"\n  if \"Some ((pc', st', s', f', r'), pcs') = exec P n (pc, st, s, f, r) []\"\n  using that exec_pointers by fastforce\n\ncontext Prod_TA_Defs\nbegin\n\nlemma finite_range_I':\n  assumes \"\\<forall>A\\<in>{0..<p}. finite (range (snd (N ! A)))\"\n    shows \"finite (range (I' s))\"\n    using assms unfolding inv_of_def Product_TA_Defs.product_ta_def N_s_def\n    by (auto simp: inv_of_def p_def intro!: Product_TA_Defs.finite_invariant_of_product)\n\nlemma range_prod_invariant:\n  \"range prod_invariant = range (I' s)\"\n  unfolding prod_invariant_def using I'_simp by auto\n\nlemma finite_rangeI:\n  assumes \"\\<forall>A\\<in>{0..<p}. finite (range (snd (N ! A)))\"\n  shows \"finite (range prod_invariant)\"\n  using assms by (metis finite_range_I' range_prod_invariant)\n\nthm prod_trans_i_alt_def\n\nend\n\n\ncontext Equiv_TA_Defs\nbegin\n\nthm defs.prod_trans_i_alt_def\n\nlemma states'_len_simp[simp]:\n  \"length L = p\" if \"L \\<in> defs.states' s\"\n  using that\n  using Product_TA_Defs.states_length defs.N_s_def state_ta_def by fastforce\n\n\n\n lemma [simp]:\n  \"defs.p = p\"\n  unfolding defs.p_def by simp\n\nlemma P_Storec_iff:\n  \"(Some (INSTR (STOREC x xa)) = P pc) \\<longleftrightarrow> (Some (STOREC x xa) = PF pc)\"\n  unfolding stripfp_def apply (cases \"P pc\")\n   apply force\n  subgoal for a\n    by (cases a) auto\n  done\n\n(* XXX Unused but is explaining what is going on below *)\nlemma product_trans_i_resets:\n  \"collect_clkvt (Product_TA_Defs.product_trans_i (defs.N_s s))\n  \\<subseteq> {c. \\<exists> x pc. Some (INSTR (STOREC c x)) = P pc}\"\n  unfolding collect_clkvt_def\n  unfolding Product_TA_Defs.product_trans_i_def\n  apply clarsimp\n  unfolding defs.N_s_def\n  unfolding trans_of_def\n  unfolding defs.T_s_def\n  unfolding state_ta_def\n  unfolding state_trans_t_def\n  unfolding make_f_def\n  apply (clarsimp split: option.split_asm)\n  by (auto dest: exec_reset simp: P_Storec_iff)\n\n(* XXX Unused but is explaining what is going on below *)\nlemma product_trans_s_resets:\n  \"collect_clkvt (Product_TA_Defs.product_trans_s (defs.N_s s))\n  \\<subseteq> {c. \\<exists> x pc. Some (INSTR (STOREC c x)) = P pc}\"\n  unfolding collect_clkvt_def\n  unfolding Product_TA_Defs.product_trans_s_def\n  apply clarsimp\n  unfolding defs.N_s_def\n  unfolding trans_of_def\n  unfolding defs.T_s_def\n  unfolding state_ta_def\n  unfolding state_trans_t_def\n  unfolding make_f_def\n  apply (clarsimp split: option.split_asm)\n  by (auto dest: exec_reset simp: P_Storec_iff)\n\nlemma product_trans_resets:\n  \"collect_clkvt (\\<Union>s. defs.T' s) \\<subseteq> {c. \\<exists> x pc. Some (INSTR (STOREC c x)) = P pc}\"\n  unfolding trans_of_def\n  unfolding Product_TA_Defs.product_ta_def\n  apply simp\n  unfolding Product_TA_Defs.product_trans_def\n  unfolding collect_clkvt_def\n  apply safe\n  unfolding Product_TA_Defs.product_trans_i_def Product_TA_Defs.product_trans_s_def\n   apply clarsimp_all\n  unfolding defs.N_s_def\n  unfolding trans_of_def\n  unfolding defs.T_s_def\n  unfolding state_ta_def\n  unfolding state_trans_t_def\n  unfolding make_f_def\n  apply (clarsimp_all split: option.split_asm)\n  by (auto dest: exec_reset simp: P_Storec_iff)\n\nlemma product_trans_guards:\n  \"Timed_Automata.collect_clkt (\\<Union>s. defs.T' s)\n  \\<subseteq> {constraint_pair ac | ac. \\<exists> pc. Some (CEXP ac) = P pc}\"\n  unfolding trans_of_def\n  unfolding Product_TA_Defs.product_ta_def\n  apply simp\n  unfolding Product_TA_Defs.product_trans_def\n  unfolding Timed_Automata.collect_clkt_def collect_clock_pairs_def\n  apply safe\n  unfolding Product_TA_Defs.product_trans_i_def Product_TA_Defs.product_trans_s_def\n   apply clarsimp_all\n  unfolding defs.N_s_def\n  unfolding trans_of_def\n  unfolding defs.T_s_def\n  unfolding state_ta_def\n  unfolding state_trans_t_def\n  unfolding make_g_def\n   apply (clarsimp_all split: option.split_asm)\n  subgoal premises prems\n    using prems(1,3-)\n    unfolding set_map_filter\n    by - (drule exec_pointers'; auto split: option.splits; auto split: instrc.split_asm; metis)\n  subgoal premises prems\n    using prems(1,2,4-)\n    apply safe\n    unfolding set_map_filter\n    by (drule exec_pointers'; auto split: option.splits; auto split: instrc.split_asm; metis)+\n  done\n\nend\n\ndatatype bexp =\n  not bexp | \"and\" bexp bexp | or bexp bexp | imply bexp bexp | \\<comment> \\<open>Boolean connectives\\<close>\n  loc nat nat | \\<comment> \\<open>Is process p in location l?\\<close>\n  eq nat int \\<comment> \\<open>Does var i equal x?\\<close> |\n  le nat int |\n  lt nat int |\n  ge nat int |\n  gt nat int\n\nfun check_bexp :: \"bexp \\<Rightarrow> nat list \\<Rightarrow> int list \\<Rightarrow> bool\" where\n  \"check_bexp (not a) L s \\<longleftrightarrow> \\<not> check_bexp a L s\" |\n  \"check_bexp (and a b ) L s \\<longleftrightarrow> check_bexp a L s \\<and> check_bexp b L s\" |\n  \"check_bexp (or a b ) L s \\<longleftrightarrow> check_bexp a L s \\<or> check_bexp b L s\" |\n  \"check_bexp (imply a b ) L s \\<longleftrightarrow> (check_bexp a L s \\<longrightarrow> check_bexp b L s)\" |\n  \"check_bexp (loc p l) L _ \\<longleftrightarrow> L ! p = l\" |\n  \"check_bexp (eq i x) _ s \\<longleftrightarrow> s ! i = x\" |\n  \"check_bexp (le i x) _ s \\<longleftrightarrow> s ! i \\<le> x\" |\n  \"check_bexp (lt i x) _ s \\<longleftrightarrow> s ! i < x\" |\n  \"check_bexp (ge i x) _ s \\<longleftrightarrow> s ! i \\<ge> x\" |\n  \"check_bexp (gt i x) _ s \\<longleftrightarrow> s ! i > x\"\n\ndatatype formula =\n  EX bexp | EG bexp | AX bexp | AG bexp | Leadsto bexp bexp\n\nabbreviation \"repeat x n \\<equiv> map (\\<lambda> _. x) [0..<n]\"\n\nabbreviation \"conv_prog P pc \\<equiv> map_option (map_instrc real_of_int) (P pc)\"\nabbreviation \"conv_A' \\<equiv> \\<lambda> (T, I). (T, conv_cc o I)\"\n\nfun hd_of_formula :: \"formula \\<Rightarrow> nat list \\<Rightarrow> int list \\<Rightarrow> bool\" where\n  \"hd_of_formula (formula.EX \\<phi>) = check_bexp \\<phi>\" |\n  \"hd_of_formula (EG \\<phi>) = check_bexp \\<phi>\" |\n  \"hd_of_formula (AX \\<phi>) = Not oo check_bexp \\<phi>\" |\n  \"hd_of_formula (AG \\<phi>) = Not oo check_bexp \\<phi>\" |\n  \"hd_of_formula (Leadsto \\<phi> _) = check_bexp \\<phi>\"\n\nsubsection \\<open>Pre-compiled networks with states and clocks as natural numbers\\<close>\nlocale UPPAAL_Reachability_Problem_precompiled_defs =\n  fixes p :: nat \\<comment> \\<open>Number of processes\\<close>\n    and m :: nat \\<comment> \\<open>Number of clocks\\<close>\n    (*\n    and k :: \"nat list list\"\n      -- \"Clock ceiling. Maximal constant appearing in automaton for each state\"\n    *)\n    and max_steps :: nat \\<comment> \\<open>Maximal number of execution for steps of programs in the automaton\\<close>\n    and inv :: \"(nat, int) cconstraint list list\" \\<comment> \\<open>Clock invariants on locations per process\\<close>\n    and pred :: \"addr list list\" \\<comment> \\<open>State invariants on locations per process\\<close>\n    and trans :: \"(addr * nat act * addr * nat) list list list\"\n      \\<comment> \\<open>Transitions between states per process\\<close>\n    and prog :: \"int instrc option list\"\n    and formula :: formula \\<comment> \\<open>Model checking formula\\<close>\n    and bounds :: \"(int * int) list\"\nbegin\n  definition \"clkp_set' \\<equiv>\n    \\<Union> (collect_clock_pairs ` set (concat inv))\n    \\<union> {constraint_pair ac | ac. Some (CEXP ac) \\<in> set prog}\"\n  definition clk_set'_def: \"clk_set' =\n    (fst ` clkp_set' \\<union> {c. \\<exists> x. Some (INSTR (STOREC c x)) \\<in> set prog})\"\n\n  text \\<open>Definition of the corresponding network\\<close>\n  definition \"I i l \\<equiv> if l < length (inv ! i) then inv ! i ! l else []\"\n  definition \"T i \\<equiv>\n    {(l, trans ! i ! l ! j) | l j. l < length (trans ! i) \\<and> j < length (trans ! i ! l)}\"\n  definition \"P \\<equiv> map (\\<lambda> P l. P ! l) pred\"\n  definition \"PROG pc \\<equiv> (if pc < length prog then prog ! pc else None)\"\n  definition N :: \"(nat, int, nat) unta\" where\n    \"N \\<equiv> (PROG, map (\\<lambda> i. (T i, I i)) [0..<p], P, bounds)\"\n  definition \"init \\<equiv> repeat (0::nat) p\"\n  definition \"F \\<equiv> hd_of_formula formula\"\n\n  sublocale equiv: Equiv_TA_Defs N max_steps .\n\n  thm equiv.defs.prod_trans_i_alt_def\n\n  abbreviation \"EA \\<equiv> equiv.state_ta\"\n\n  abbreviation \"A \\<equiv> equiv.defs.prod_ta\"\n\n  lemma [simp]:\n    \"equiv.p = p\"\n    unfolding equiv.p_def N_def Equiv_TA_Defs.p_def by simp\n\n  lemma [simp]:\n    \"length (equiv.defs.N_s s) = p\"\n    unfolding equiv.defs.N_s_def by simp\n\n  lemma length_N[simp]:\n    \"length equiv.defs.N = p\"\n    by simp\n\n  lemma\n    \"equiv.defs.I' s L = concat (map (\\<lambda> q. if q < p then I q (L ! q) else []) [0..<length L])\"\n    unfolding inv_of_def\n    unfolding Product_TA_Defs.product_ta_def\n    apply simp\n    unfolding Product_TA_Defs.product_invariant_def\n    unfolding equiv.defs.N_s_def inv_of_def\n    apply (rule arg_cong[where f = concat])\n    unfolding Equiv_TA_Defs.state_ta_def\n      apply simp\n    unfolding N_def Equiv_TA_Defs.state_inv_def\n      by simp\n\nend (* End of definitions locale *)\n\n  lemma snd_comp[simp]:\n    \"snd o (\\<lambda> i. (f i, g i)) = g\"\n  by auto\n\nlocale UPPAAL_Reachability_Problem_precompiled =\n  UPPAAL_Reachability_Problem_precompiled_defs +\n  assumes process_length: \"length inv = p\" \"length trans = p\" \"length pred = p\"\n    and lengths:\n    \"\\<forall> i < p. length (pred ! i) = length (trans ! i) \\<and> length (inv ! i) = length (trans ! i)\"\n    and state_set: \"\\<forall> T \\<in> set trans. \\<forall> xs \\<in> set T. \\<forall> (_, _, _, l) \\<in> set xs. l < length T\"\n  assumes consts_nats: \"snd ` clkp_set' \\<subseteq> \\<nat>\"\n  (* XXX This could also be subset for now but is left like this as an input sanity check right now *)\n  assumes clock_set: \"clk_set' = {1..m}\"\n    and p_gt_0: \"p > 0\"\n    and m_gt_0: \"m > 0\"\n    (* XXX Can get rid of these two? *)\n    and processes_have_trans: \"\\<forall> i < p. trans ! i \\<noteq> []\" \\<comment> \\<open>Necessary for refinement\\<close>\n    and start_has_trans: \"\\<forall> q < p. trans ! q ! 0 \\<noteq> []\" \\<comment> \\<open>Necessary for refinement\\<close>\n  (* XXX Do not need this but a useful cautious check for the user? *)\n  assumes resets_zero: \"\\<forall> x c. Some (INSTR (STOREC c x)) \\<in> set prog \\<longrightarrow> x = 0\"\n\n(*\nlocale UPPAAL_Reachability_Problem_precompiled =\n  UPPAAL_Reachability_Problem_precompiled_raw +\n  assumes discrete_state_finite: \"\\<forall> i < p. \\<forall> l < length (trans ! i). finite {s. (pred ! i ! l) s}\"\n*)\nbegin\n\n  lemma consts_nats':\n    \"\\<forall> I \\<in> set inv. \\<forall> cc \\<in> set I. \\<forall> (c, d) \\<in> collect_clock_pairs cc. d \\<in> \\<nat>\"\n    (* \"\\<forall> T \\<in> set trans. \\<forall> xs \\<in> set T. \\<forall> (g, _) \\<in> set xs. \\<forall> (c, d) \\<in> collect_clock_pairs g. d \\<in> \\<nat>\" *)\n    \"\\<forall> ac. Some (CEXP ac) \\<in> set prog \\<longrightarrow> (snd (constraint_pair ac) \\<in> \\<nat>)\"\n    using consts_nats unfolding clkp_set'_def by force+\n\n  thm equiv.defs.collect_clkt_prod_trans_subs\n  thm equiv.defs.collect_clki_prod_invariant[of init]\n  thm equiv.defs.collect_clkvt_prod_trans_subs\n\n  term \"range (snd (equiv.defs.N ! p))\" term \"snd (equiv.defs.N ! p)\"\n    term \"set inv\" term \"set (concat inv)\"\n    term \"equiv.defs.N\"\n\n  lemma clk_pairs_N_inv:\n    \"\\<Union> (collect_clock_pairs ` range (snd x)) \\<subseteq> \\<Union> (collect_clock_pairs ` set (concat inv))\"\n    if \"x \\<in> set equiv.defs.N\" for x\n    using that process_length(1)\n    unfolding equiv.state_ta_def equiv.state_inv_def equiv.p_def\n    unfolding N_def I_def\n    by clarsimp (auto split: if_split_asm dest: nth_mem)+\n\n  lemma clkp_set_simp_1:\n    \"\\<Union> (collect_clock_pairs ` set (concat inv)) \\<supseteq> Timed_Automata.collect_clki (snd A)\"\n    unfolding equiv.defs.prod_ta_def inv_of_def\n    apply (rule subset_trans)\n     apply simp\n     apply (rule equiv.defs.collect_clki_prod_invariant')\n    unfolding Timed_Automata.collect_clki_def using clk_pairs_N_inv nth_mem by blast\n\n  lemma clk_set_simp_2:\n    \"{c. \\<exists> x. Some (INSTR (STOREC c x)) \\<in> set prog} \\<supseteq> collect_clkvt (trans_of A)\"\n    unfolding equiv.defs.prod_ta_def trans_of_def\n    apply (rule subset_trans)\n     apply simp\n     apply (rule equiv.defs.collect_clkvt_prod_trans_subs)\n    apply (rule subset_trans)\n     apply (rule equiv.product_trans_resets)\n    unfolding N_def PROG_def by (auto dest!: nth_mem) metis\n\n  lemma clkp_set_simp_3:\n    \"{constraint_pair ac | ac. Some (CEXP ac) \\<in> set prog} \\<supseteq> Timed_Automata.collect_clkt (trans_of A)\"\n    unfolding equiv.defs.prod_ta_def trans_of_def\n    apply (rule subset_trans)\n     apply simp\n     apply (rule equiv.defs.collect_clkt_prod_trans_subs)\n    apply (rule subset_trans)\n     apply (rule equiv.product_trans_guards)\n    unfolding N_def PROG_def by (auto dest!: nth_mem)\n\n  lemma clkp_set'_subs:\n    \"Timed_Automata.clkp_set A \\<subseteq> clkp_set'\"\n    using clkp_set_simp_1 clkp_set_simp_3\n    by (auto simp add: clkp_set'_def Timed_Automata.clkp_set_def inv_of_def)\n\n  lemma clk_set'_subs:\n    \"clk_set A \\<subseteq> clk_set'\"\n    using clkp_set'_subs clk_set_simp_2 by (auto simp: clk_set'_def)\n\n  lemma clk_set:\n    \"clk_set A \\<subseteq> {1..m}\"\n    using clock_set m_gt_0 clk_set'_subs by auto\n\n  lemma\n    \"\\<forall>(_, d)\\<in>Timed_Automata.clkp_set A. d \\<in> \\<int>\"\n    unfolding Ints_def by auto\n\n  lemma clkp_set'_consts_nat:\n    \"\\<forall>(_, d)\\<in>clkp_set'. d \\<in> \\<nat>\"\n    using consts_nats' unfolding clkp_set'_def\n    apply auto\n     apply force\n    by (metis snd_conv)\n\n  lemma clkp_set_consts_nat:\n    \"\\<forall>(_, d)\\<in>Timed_Automata.clkp_set A. d \\<in> \\<nat>\"\n    using clkp_set'_subs clkp_set'_consts_nat by auto\n\n  lemma finite_clkp_set':\n    \"finite clkp_set'\"\n    unfolding clkp_set'_def\n    using [[simproc add: finite_Collect]]\n    by (auto simp: inj_on_def intro!: finite_vimageI)\n\n  lemma finite_clkp_set_A[intro, simp]:\n    \"finite (Timed_Automata.clkp_set A)\"\n    using clkp_set'_subs finite_clkp_set' by (rule finite_subset)\n\n  lemma clkp_set'_bounds:\n    \"a \\<in> {Suc 0..m}\" if \"(a, b) \\<in> clkp_set'\"\n    using that clock_set unfolding clk_set'_def by auto\n\n  lemma finite_range_inv_of_A[intro, simp]:\n    \"finite (range (inv_of A))\"\n    unfolding inv_of_def equiv.defs.prod_ta_def\n    apply simp\n    apply (rule equiv.defs.finite_rangeI)\n      apply simp\n    unfolding Equiv_TA_Defs.state_ta_def\n    apply simp\n    unfolding equiv.state_inv_def\n    unfolding N_def\n    unfolding I_def\n    by (auto intro: finite_subset[where B = \"{[]}\"])\n\n  (* XXX Interesting for finiteness *)\n  (* XXX Move *)\n  lemma Collect_fold_pair:\n    \"{f a b | a b. P a b} = (\\<lambda> (a, b). f a b) ` {(a, b). P a b}\" for P\n    by auto\n\n  lemma finite_T[intro, simp]:\n    \"finite (trans_of A)\"\n  unfolding trans_of_def equiv.defs.prod_ta_def\n  proof (simp, rule equiv.defs.finite_prod_trans, goal_cases)\n    case (1 s)\n    show \"\\<forall>l q. q < equiv.defs.p \\<longrightarrow> (equiv.defs.P ! q) l s \\<longrightarrow> (bounded equiv.B) s\"\n      apply simp\n      unfolding equiv.state_ta_def equiv.state_pred_def\n      by (simp split: option.split)\n  next\n    case 2\n    show \"finite {s. bounded equiv.B s}\" by (rule equiv.bounded_finite)\n  next\n    case 3\n    show ?case\n    proof\n      fix A assume A: \"A \\<in> set equiv.defs.N\"\n      have\n        \"{(l, j). l < length (trans ! i) \\<and> j < length (trans ! i ! l)}\n        = \\<Union> ((\\<lambda> l. {(l, j) | j. j < length (trans ! i ! l)}) ` {l. l < length (trans ! i)})\" for i\n        by auto\n      then have \"finite (T q)\" if \"q < p\" for q\n        using that unfolding T_def by (fastforce simp: Collect_fold_pair)\n      then have \"finite (fst (equiv.N ! q))\" if \"q < p\" for q\n        using that unfolding N_def by simp\n      then have \"finite (equiv.state_trans q)\" if \"q < p\" for q\n        using that\n        unfolding Equiv_TA_Defs.state_trans_t_def\n        using [[simproc add: finite_Collect]]\n          by auto\n      then show \"finite (fst A)\" using A unfolding Equiv_TA_Defs.state_ta_def by auto\n    qed\n  qed (auto simp: p_gt_0)\n\n  sublocale TA_Start_No_Ceiling A \"(init, s\\<^sub>0)\" m\n    using clkp_set_consts_nat clk_set m_gt_0 by - (standard; blast)\n\n(*\n  sublocale Reachability_Problem_no_ceiling A \"(init, s\\<^sub>0)\" \"PR_CONST (\\<lambda> (l, s). F l s)\" m\n    using clkp_set_consts_nat clk_set m_gt_0 by - (standard; blast)\n*)\n\n  lemma [simp]:\n    \"length P = p\"\n    unfolding P_def using process_length(3) by simp\n\n  lemma [simp]:\n    \"length equiv.I = p\"\n    unfolding N_def by simp\n\n  lemma [simp]:\n    \"length equiv.N = p\"\n    unfolding N_def by simp\n\nend (* End of locale *)\n\n(*\ncontext UPPAAL_Reachability_Problem_precompiled_defs\nbegin\n  (*definition \"clkp_set'' \\<equiv>\n    \\<Union> (collect_clock_pairs ` set (concat inv))\n    \\<union> {constraint_pair ac | ac. Some (CEXP ac) \\<in> set prog}\"\n*)\n\n  definition \"clkp_set'' i l \\<equiv>\n    collect_clock_pairs (inv ! i ! l) \\<union> \\<Union> ((\\<lambda> (g, _). collect_clock_pairs g) ` set (trans ! i ! l))\"\n\nend\n*)\n\n(*\nlocale UPPAAL_Reachability_Problem_precompiled_ceiling =\n  UPPAAL_Reachability_Problem_precompiled +\n  fixes k :: \"nat list list list\"\n  (*\n    and k_length: \"length k = p\" \"\\<forall> l \\<in> set k. length l = m + 1\"\n      -- \\<open>Zero entry is just a dummy for the zero clock\\<close>\n    (* XXX Make this an abbreviation? *)\n  assumes k_ceiling:\n    (* \"\\<forall> c \\<in> {1..m}. k ! c = Max ({d. (c, d) \\<in> clkp_set'} \\<union> {0})\" *)\n    \"\\<forall> (c, d) \\<in> clkp_set'. int (k ! c) \\<ge> d\"\n    \"k ! 0 = 0\"\n  *)\nbegin\n\n  definition\n    \"k_fun \\<equiv> \\<lambda> (l, s). \\<lambda> c. if 0 < c \\<and> c \\<le> m then Max {k ! i ! (l ! i) ! c | i. i < p} else 0\"\n\n  lemma [intro, simp]:\n    \"k_fun st 0 = 0\"\n    unfolding k_fun_def by (simp split: prod.split)\n\n  lemma [intro, simp]:\n    \"k_fun st i = 0\" if \"i > m\"\n    unfolding k_fun_def using that by (simp split: prod.split)\n\n  lemma [intro]:\n    \"b \\<le> int (k_fun a)\" if \"(a, b) \\<in> clkp_set A\"\n    using that k_ceiling clkp_set'_subs k_length clkp_set'_bounds unfolding k_fun_def by force\n\n  sublocale Reachability_Problem \"(init, s\\<^sub>0)\" \"PR_CONST (\\<lambda> (l, s). F l s)\" m A k_fun\n    using clkp_set_consts_nat clk_set m_gt_0 apply - apply standard\n       prefer 4 apply simp\n      prefer 3 apply simp\n      oops\n\nend (* End of locale *)\n*)\n\nend (* End of theory *)\n", "meta": {"author": "wimmers", "repo": "munta", "sha": "62cb1a4a4dbcfcf62c365e90faba15b0012d5a12", "save_path": "github-repos/isabelle/wimmers-munta", "path": "github-repos/isabelle/wimmers-munta/munta-62cb1a4a4dbcfcf62c365e90faba15b0012d5a12/Uppaal_Networks/UPPAAL_State_Networks_Impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.600188359260205, "lm_q2_score": 0.4301473485858429, "lm_q1q2_score": 0.2581694313878645}}
{"text": "theory Modelica_Blocks_Core\n  imports \"../Modelica_Core\"\nbegin\n  \nconsts\n  eps\\<^sub>m :: real\n  \ntype_synonym ('a, 'l, 'c) mcon = \"('a \\<Longrightarrow> ('l, 'c) mst_scheme)\"\n  \ntranslations\n  (type) \"('a, 'l, 'c) mcon\" <= (type) \"('a \\<Longrightarrow> ('l, 'c) mst_scheme)\"\n  \ndatatype ('l, 'c) mevgrd =\n  TimeEvent (ofTimeEvent: \"real \\<Rightarrow> bool\") | StateEvent (ofStateEvent: \"(real, 'l, 'c) mexpr\")\n  \nrecord (overloaded) ('l, 'c) mblock = \n  mieqs :: \"('l, 'c) mst_scheme upred\"               -- {* Initial Equations *}\n  mdeqs :: \"('l, 'c) mrel\"                           -- {* Differential Equations *}\n  maeqs :: \"('l, 'c) mst_scheme upred\"               -- {* Algebraic Equations *}\n  mqeqs :: \"('l, 'c) mst_scheme upred\"               -- {* Discrete Equations *}\n  mreqs :: \"('l, 'c) mst_scheme hrel set\"            -- {* Reset Equations *}\n  mzcfs :: \"(real, ('l, 'c) mst_scheme) uexpr set\"   -- {* Zero Crossing Expressions *}\n  mtevs :: \"real \\<Rightarrow> bool\"                            -- {* Time Event Expressions *}\n  \ndefinition \"EvInv eps z  = (\\<lceil>z\\<rceil>\\<^sub>< >\\<^sub>u -eps \\<Rightarrow> \\<lceil>z\\<rceil>\\<^sub>> >\\<^sub>u -eps)\"\ndefinition \"EvExit eps z = (\\<lceil>z\\<rceil>\\<^sub>< >\\<^sub>u 0 \\<and> \\<lceil>z\\<rceil>\\<^sub>> \\<le>\\<^sub>u 0)\"\n  \ndefinition interleave_r :: \"'a hrel set \\<Rightarrow> 'a hrel\" (\"|||\\<^sub>r _\") where\n\"interleave_r A = (\\<Sqinter> xs\\<in>{xs. set(xs) = A} \\<bullet> (;; p : xs \\<bullet> p))\" \n  \ndefinition svid_fst :: \"'a \\<Longrightarrow> 'a \\<times> 'b\" (\"\\<^bold>v\\<^sub>0\") where\n[lens_defs]: \"svid_fst = fst\\<^sub>L\"\n\ndefinition svid_snd :: \"'b \\<Longrightarrow> 'a \\<times> 'b\" (\"\\<^bold>v\\<^sub>1\") where\n[lens_defs]: \"svid_snd = snd\\<^sub>L\"\n\nsyntax\n  \"_svid_fst\" :: \"svid\" (\"\\<^bold>v\\<^sub>0\")\n  \"_svid_snd\" :: \"svid\" (\"\\<^bold>v\\<^sub>1\")  \n  \ntranslations\n  \"_svid_fst\" == \"CONST svid_fst\"\n  \"_svid_snd\" == \"CONST svid_snd\"\n  \nlemma skip_lens_ext_fst:\n  \"II \\<oplus>\\<^sub>p (\\<^bold>v\\<^sub>0 \\<times>\\<^sub>L \\<^bold>v\\<^sub>0) = ($\\<^bold>v\\<^sub>0\\<acute> =\\<^sub>u $\\<^bold>v\\<^sub>0)\"\n  by (rel_auto)\n  \nlemma fst_snd_eq_skip: \n  \"($\\<^bold>v\\<^sub>0\\<acute> =\\<^sub>u $\\<^bold>v\\<^sub>0 \\<and> $\\<^bold>v\\<^sub>1\\<acute> =\\<^sub>u $\\<^bold>v\\<^sub>1) = II\"\n  by (rel_auto)\n    \nlemma iterate_skip_lemma_1: \n  \"($\\<^bold>v\\<^sub>0\\<acute> =\\<^sub>u $\\<^bold>v\\<^sub>0 \\<and> $\\<^bold>v\\<^sub>1\\<acute> =\\<^sub>u $\\<^bold>v\\<^sub>0) ;; (II \\<triangleleft> &\\<^bold>v\\<^sub>0 =\\<^sub>u &\\<^bold>v\\<^sub>1 \\<triangleright>\\<^sub>r X) = \\<^bold>v\\<^sub>1 := &\\<^bold>v\\<^sub>0\"\n  by (rel_auto)\n    \ndefinition iterate :: \"'a hrel \\<Rightarrow> 'a hrel\" where\n\"iterate P = (\\<exists> $\\<^bold>v\\<^sub>1;$\\<^bold>v\\<^sub>1\\<acute> \\<bullet> (\\<nu> X \\<bullet> (P \\<oplus>\\<^sub>p (\\<^bold>v\\<^sub>0 \\<times>\\<^sub>L \\<^bold>v\\<^sub>0) \\<and> $\\<^bold>v\\<^sub>1\\<acute> =\\<^sub>u $\\<^bold>v\\<^sub>0) ;; (II \\<triangleleft> &\\<^bold>v\\<^sub>0 =\\<^sub>u &\\<^bold>v\\<^sub>1 \\<triangleright>\\<^sub>r X))) \\<restriction>\\<^sub>e (\\<^bold>v\\<^sub>0 \\<times>\\<^sub>L \\<^bold>v\\<^sub>0)\"\n  \nlemma iterate_II: \"iterate II = II\"\n  by (simp add: iterate_def skip_lens_ext_fst iterate_skip_lemma_1 lfp_const, rel_auto)\n\ndefinition mblock_comp :: \"('l,'c) mblock \\<Rightarrow> ('l,'c) mblock \\<Rightarrow> ('l,'c) mblock\" (infixr \"\\<oplus>\\<^sub>m\" 85) where\n[upred_defs, mo_defs]:\n\"A \\<oplus>\\<^sub>m B = \\<lparr> mieqs = (mieqs A \\<and> mieqs B)\n          , mdeqs = (mdeqs A \\<and> mdeqs B)\n          , maeqs = (maeqs A \\<and> maeqs B)\n          , mqeqs = (mqeqs A \\<and> mqeqs B)\n          , mreqs = (mreqs A \\<union> mreqs B)\n          , mzcfs = (mzcfs A \\<union> mzcfs B)\n          , mtevs = (\\<lambda> t. mtevs A t \\<or> mtevs B t) \\<rparr>\"\n    \n(* FIXME: Take account of time events here too. *)\n    \ndefinition mblock_sem :: \n  \"_ \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> ('l::t2_space,'c::t2_space) mblock \\<Rightarrow> ('l,'c) mrel\" (\"'(_,_,_') \\<Turnstile> \\<lbrakk>_\\<rbrakk>\\<^sub>m\") where\n[upred_defs, mo_defs]:\n\"(\\<epsilon>, s, q) \\<Turnstile> \\<lbrakk>M\\<rbrakk>\\<^sub>m =  \n  (let I = mieqs M; D = mdeqs M; A = maeqs M; Q = mqeqs M; R = mreqs M; Z = mzcfs M; T = mtevs M in\n   \\<^bold>R\\<^sub>s(true\\<^sub>r \\<turnstile> false \\<diamondop> [I \\<and> Q \\<and> A]\\<^sub>C\\<^sub>>) ;;\n   (\\<mu>\\<^sub>R X \\<bullet> ([D \\<and> \\<lceil>\\<lceil>A\\<rceil>\\<^sub>>\\<rceil>\\<^sub>h \\<and> q \\<leftarrow>\\<^sub>h $q]\\<^sub>H \n                 inv (\\<not> \\<guillemotleft>T\\<guillemotright>($mtime\\<acute>)\\<^sub>a) \\<and> (\\<And> z\\<in>Z \\<bullet> EvInv \\<epsilon> z) \n                 until\\<^sub>H ((\\<guillemotleft>T\\<guillemotright>($mtime\\<acute>)\\<^sub>a) \\<or> (\\<Or> z\\<in>Z \\<bullet> EvExit \\<epsilon> z))) ;;\n            \\<^bold>R\\<^sub>s(true\\<^sub>r \\<turnstile> false \\<diamondop> [iterate($s\\<acute> =\\<^sub>u $s \\<and> \\<lceil>Q\\<rceil>\\<^sub>> \\<and> \\<lceil>A\\<rceil>\\<^sub>>) ;; |||\\<^sub>r R]\\<^sub>C) ;; X))\"\n\n(*\ndefinition timeGuards :: \"('l, 'c) mblock \\<Rightarrow> ((real \\<Rightarrow> bool) \\<times> ('l, 'c) mrel) list\" where\n[upred_defs, mo_defs]:\n\"timeGuards M = map (\\<lambda> (g, e). (ofTimeEvent g, e)) (filter (is_TimeEvent \\<circ> fst) (mgrds M))\"\n\ndefinition stateGuards :: \"('l, 'c) mblock \\<Rightarrow> ((real, 'l, 'c) mexpr \\<times> ('l, 'c) mrel) list\" where\n[upred_defs, mo_defs]:\n\"stateGuards M = map (\\<lambda> (g, e). (ofStateEvent g, e)) (filter (Not \\<circ> is_TimeEvent \\<circ> fst) (mgrds M))\"\n\ntext {* A time event is triggered whenever the internal clock hits one of the instants in\n  the given set of real number. *}\n  \ndefinition ti_event :: \"(real \\<Rightarrow> bool) \\<Rightarrow> ('l, 'c) mst_scheme hrel\" where\n[upred_defs, mo_defs]: \"ti_event P = (\\<guillemotleft>P\\<guillemotright>($time\\<acute>)\\<^sub>a)\"\n  \ntext {* State events are recorded whenever the given function crosses zero. A zero crossing event \n  is registered at some non-deterministically chosen instant when the function $zcf$ was previously \n  $\\ge eps$ and it becomes less than $eps$. There is not one point which satisifies this specification \n  and then event can occur at any $t$ when $zcf(t) \\in [0,eps)$ *}\n  \ndefinition zc_event :: \"(real, ('l, 'c) mst_scheme) uexpr \\<Rightarrow> ('l, 'c) mst_scheme hrel \\<times> ('l, 'c) mst_scheme hrel\" where\n[upred_defs, mo_defs]: \"zc_event zcf = (\\<lceil>zcf\\<rceil>\\<^sub>> \\<ge>\\<^sub>u 0, (\\<lceil>zcf \\<ge>\\<^sub>u \\<guillemotleft>eps\\<^sub>m\\<guillemotright>\\<rceil>\\<^sub>< \\<and> \\<lceil>zcf <\\<^sub>u \\<guillemotleft>eps\\<^sub>m\\<guillemotright>\\<rceil>\\<^sub>>))\"\n  \ntext {* When the zero-crossing function was previously close to 0, but now it is sufficiently far\n  away ($> eps$), a \"phantom\" event iteration executes which simply resets the previous value\n  of the zero crossing function to that point so that any correspondonding when statement is\n  re-enabled. *}\n\ndefinition zc_restore :: \"(real, ('l, 'c) mst_scheme) uexpr \\<Rightarrow> ('l, 'c) mst_scheme hrel\" where\n[upred_defs, mo_defs]: \"zc_restore zcf = (\\<lceil>zcf <\\<^sub>u \\<guillemotleft>eps\\<^sub>m\\<guillemotright>\\<rceil>\\<^sub><  \\<and> \\<lceil>zcf \\<ge>\\<^sub>u \\<guillemotleft>eps\\<^sub>m\\<guillemotright>\\<rceil>\\<^sub>>)\"\n\ndefinition minvs :: \"('l, 'c) mblock \\<Rightarrow> ('l, 'c) mst_scheme hrel\" where\n[upred_defs, mo_defs]: \n  \"minvs M = foldr (op \\<and>) (map (fst \\<circ> zc_event \\<circ> fst) (stateGuards M)) true\"\n\ndefinition mconds :: \"('l, 'c) mblock \\<Rightarrow> ('l, 'c) mst_scheme hrel\" where\n[upred_defs, mo_defs]: \n  \"mconds M = (foldr (op \\<or>) (map (snd \\<circ> zc_event \\<circ> fst) (stateGuards M)) false \\<or>\n               foldr (op \\<or>) (map (zc_restore \\<circ> fst) (stateGuards M)) false \\<or> \n               foldr (op \\<or>) (map (ti_event \\<circ> fst) (timeGuards M)) false)\"\n  \ntext {* For discrete events, we first execute each time event up to once, and then enter iteration\n  for the state events. *}\n  \ndefinition mdeqs :: \"('l::t2_space,'c::t2_space) mblock \\<Rightarrow> ('l,'c) mrel\" where\n[upred_defs, mo_defs]: \"mdeqs M = \n   (foldr (op ;;) (map (\\<lambda> (R, dq). dq \\<triangleleft> \\<guillemotleft>R\\<guillemotright>(&\\<^bold>c:time)\\<^sub>a \\<triangleright>\\<^sub>R II\\<^sub>R) (timeGuards M)) II\\<^sub>R) ;;\n   (\\<mu>\\<^sub>R X \\<bullet> foldr \n           (\\<lambda> (zcf, dq) q. \n           (dq ;; X) \\<triangleleft> (\\<lceil>zcf\\<rceil>\\<^sub>< \\<ge>\\<^sub>u \\<guillemotleft>eps\\<^sub>m\\<guillemotright>)\\<lbrakk>&\\<^bold>d/&\\<^bold>c\\<rbrakk> \\<and> (\\<lceil>zcf\\<rceil>\\<^sub>< <\\<^sub>u \\<guillemotleft>eps\\<^sub>m\\<guillemotright>) \\<triangleright>\\<^sub>R q) (stateGuards M) II\\<^sub>R)\"\n (* zcf  previously not satisfied ---^               ^--- now it is *)\n\ndefinition CoreTime :: \"('l::t2_space,'c::t2_space) mblock\" where\n[upred_defs, mo_defs]:\n  \"CoreTime = \\<lparr> minit = (&time =\\<^sub>u 0), mceqs = &time \\<leftarrow>\\<^sub>h ($time + \\<guillemotleft>ti\\<guillemotright>), mgrds = [] \\<rparr>\"\n\ndefinition mblock_comp :: \"('l,'c) mblock \\<Rightarrow> ('l,'c) mblock \\<Rightarrow> ('l,'c) mblock\" (infixr \"\\<oplus>\\<^sub>m\" 85) where\n[upred_defs, mo_defs]:\n\"A \\<oplus>\\<^sub>m B = \\<lparr> minit = (minit A \\<and> minit B)\n          , mceqs = (mceqs A \\<and> mceqs B)\n          , mgrds = (mgrds A @ mgrds B) \\<rparr>\"\n  \ndefinition mblock_sem :: \"('l::t2_space,'c::t2_space) mblock \\<Rightarrow> ('l,'c) mrel\" (\"\\<lbrakk>_\\<rbrakk>\\<^sub>m\") where\n[upred_defs, mo_defs]:\n\"\\<lbrakk>M\\<rbrakk>\\<^sub>m = (let M' = CoreTime \\<oplus>\\<^sub>m M in\n        \\<^bold>R\\<^sub>s(true\\<^sub>r \\<turnstile> false \\<diamondop> [minit M']\\<^sub>C\\<^sub>>) ;; \n        (\\<mu>\\<^sub>R X \\<bullet> \\<^bold>d :=\\<^sub>R &\\<^bold>c ;; ([mceqs M']\\<^sub>H [minvs M' | mconds M']\\<^sub>H\\<^sup>+ (mdeqs M')) ;; X))\"\n*)\n  \ndefault_sort t2_space\n\nend\n", "meta": {"author": "isabelle-utp", "repo": "utp-main", "sha": "27bdf3aee6d4fc00c8fe4d53283d0101857e0d41", "save_path": "github-repos/isabelle/isabelle-utp-utp-main", "path": "github-repos/isabelle/isabelle-utp-utp-main/utp-main-27bdf3aee6d4fc00c8fe4d53283d0101857e0d41/modelica/noncomp/Modelica_Blocks_Core.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6513548511303336, "lm_q2_score": 0.39606816627404173, "lm_q1q2_score": 0.2579809214808927}}
{"text": "theory Cell\n  imports Simpl.Vcg \"Rust-Verification.Rust_Semantics\"\nbegin\n\ntext \\<open>Formalization of Cell<T>. In this theory, we interpret &Cell<T> as\na SharedReadWrite pointer to the location.\\<close>\n\nrecord cell_env = globals_ram +\n  self :: tagged_ref\n  return :: tagged_ref\n\nrecord cell_set_env = cell_env +\n  val :: tagged_ref\n\nrecord cell_swap_env = cell_env +\n  other :: tagged_ref\n  tmp :: tagged_ref \\<comment> \\<open>inlining local variable for ptr::swap\\<close>\n\n(* TODO: Current definition demands only read grant of argument, but it should be owner grant\n * because Cell::set moves the argument.\n *)\ndefinition cell_set_body :: \"(cell_set_env, 'p, rust_error) com\" where\n  \"cell_set_body == copy_betw_places val self\"\n\n(* TODO: We need to define a \"calling convention\" for handling arguments/return value.\n *)\ndefinition cell_get_body :: \"(cell_env, 'p, rust_error) com\" where\n  \"cell_get_body == copy_betw_places self return\"\n\ntext \\<open>The implementation of Cell::swap is basically along the following lines\n(inlining ptr::swap):\n\n``` rust\nif ptr::eq(self, other) {\n  return\n}\n\nlet tmp = uninit();\n*tmp = *self;\n*self = *other;\n*other = *tmp;\n```\n\naccording to \\<^url>\\<open>https://doc.rust-lang.org/src/core/cell.rs.html#364-375\\<close> and\n\\<^url>\\<open>https://doc.rust-lang.org/src/core/ptr/mod.rs.html#373-388\\<close>.\n\\<close>\n\ndefinition cell_swap_body :: \"(cell_swap_env, 'p, rust_error) com\" where\n  \"cell_swap_body ==\n    IFR {s. ptr_eq (self s) (other s)}\n    THEN\n      Skip\n    ELSE\n      \\<comment> \\<open>Initializing tmp with uninit\\<close>\n      Basic (\\<lambda>s. (let (r, s') = heap_new uninit s in s'\\<lparr> tmp := r \\<rparr>));;\n\n      \\<comment> \\<open>*tmp = *self\\<close>\n      copy_betw_places self tmp;;\n      \\<comment> \\<open>*self = *other\\<close>\n      copy_betw_places other self;;\n      \\<comment> \\<open>*self = *tmp\\<close>\n      copy_betw_places tmp other\n    FI\n\"\n\nlemma cell_set_value_safety: \"\\<Gamma> \\<turnstile>\\<^sub>t\n  {s. wf_heap s\n  \\<and> permission_is SharedReadWrite (self s) s\n  \\<and> readable (val s) s}\n  cell_set_body\n  {s. True}\"\n  unfolding cell_set_body_def\n  apply vcg\n  by (auto simp add: Let_def)\n\n\\<comment> \\<open>A proof that shows self and val have the same value after Cell::set.\\<close>\nlemma cell_set_value: \"\\<Gamma> \\<turnstile>\\<^sub>t\n  {s. wf_heap s\n  \\<and> permission_is SharedReadWrite (self s) s\n  \\<and> readable (val s) s}\n  cell_set_body\n  {s. memread (self s) s = memread (val s) s}\"\n  unfolding cell_set_body_def\n  apply vcg\n  apply (auto simp add: Let_def)\n  by (metis nth_list_update_eq nth_list_update_neq)\n\nlemma cell_get_value_safety: \"\\<Gamma> \\<turnstile>\\<^sub>t\n  {s. wf_heap s\n  \\<and> permission_is SharedReadWrite (self s) s\n  \\<and> writable (return s) s}\n  cell_get_body\n  {s. True}\"\n  unfolding cell_get_body_def\n  apply vcg\n  by (auto simp add: Let_def)\n\n\\<comment> \\<open>A proof that shows self and return have the same value after Cell::get.\\<close>\nlemma cell_get_value: \"\\<Gamma> \\<turnstile>\\<^sub>t\n  {s. wf_heap s\n  \\<and> permission_is SharedReadWrite (self s) s\n  \\<and> writable (return s) s}\n  cell_get_body\n  {s. memread (self s) s = memread (return s) s}\"\n  unfolding cell_get_body_def\n  apply vcg\n  apply (auto simp add: Let_def)\n  by (metis nth_list_update_eq nth_list_update_neq)\n\nlemma cell_swap_safety: \"\\<Gamma> \\<turnstile>\\<^sub>t\n  {s. wf_heap s\n  \\<and> permission_is SharedReadWrite (self s) s\n  \\<and> permission_is SharedReadWrite (other s) s}\n  cell_swap_body\n  {s. True}\"\n  unfolding cell_swap_body_def\n  apply vcg\n  apply (auto simp add: Let_def nth_append)\n  using permission_is_imp_writable writable_pop_tags by auto\n\n\\<comment> \\<open>A proof that shows Cell::swap(self, other) swaps the value in the memory.\\<close>\nlemma cell_swap_correctness: \"\\<Gamma> \\<turnstile>\\<^sub>t\n  {s. wf_heap s\n  \\<and> permission_is SharedReadWrite (self s) s\n  \\<and> permission_is SharedReadWrite (other s) s\n  \\<and> memread (self s) s = x\n  \\<and> memread (other s) s = y}\n  cell_swap_body\n  {s. memread (self s) s = y \\<and> memread (other s) s = x}\"\n  unfolding cell_swap_body_def\n  apply vcg\n  apply (auto simp add: Let_def nth_append)\n  using permission_is_imp_writable writable_pop_tags by auto\n\nend", "meta": {"author": "pandaman64", "repo": "sabi", "sha": "a5de6b33cb0e5b9e6f0e610de0a3536236d1a694", "save_path": "github-repos/isabelle/pandaman64-sabi", "path": "github-repos/isabelle/pandaman64-sabi/sabi-a5de6b33cb0e5b9e6f0e610de0a3536236d1a694/Rustv/Tests/ex/Cell.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5888891163376235, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.2578294935052086}}
{"text": "(*******************************************************************************\n \n  Project: IsaNet\n\n  Author:  Tobias Klenze, ETH Zurich <tobias.klenze@inf.ethz.ch>\n  Version: JCSPaper.1.0\n  Isabelle Version: Isabelle2021-1\n\n  Copyright (c) 2022 Tobias Klenze\n  Licence: Mozilla Public License 2.0 (MPL) / BSD-3-Clause (dual license)\n\n*******************************************************************************)\n\nsection \\<open>ICING variant\\<close>\ntext\\<open>We abstract and simplify from the protocol ICING in several ways. First, we only consider \nProofs of Consent (PoC), not Proofs of Provenance (PoP). Our framework does not support proving the\npath validation properties that PoPs provide, and it also currently does not support XOR, and \ndynamically changing hop fields.\nThus, instead of embedding $A_i \\oplus PoP_{0,1}$, we embed $A_i$ directly.\nWe also remove the payload from the Hash that is included in each packet.\n\nWe offer three versions of this protocol:\n\\begin{itemize}\n\\item @{text \"ICING\"}, which contains our best effort at modeling the protocol as accurately as \npossible.\n\\item @{text \"ICING_variant\"}, in which we strip down the protocol to what is required to obtain the\nsecurity guarantees and remove unnecessary fields.\n\\item @{text \"ICING_variant2\"}, in which we furthermore simplify the protocol. The key of the MAC in\nthis protocol is only the key of the AS, as opposed to a key derived specifically for this hop field.\nIn order to prove that this scheme is secure, we have to assume that ASes only occur once on an\nauthorized path, since otherwise the MAC for two different hop fields (by the same AS) would be the\nsame, and the AS could not distinguish the hop fields based on the MAC.\n\\end{itemize}\\<close>\ntheory ICING_variant\n  imports\n    \"../Parametrized_Dataplane_3_undirected\"\nbegin\n\nlocale icing_defs = network_assums_undirect _ _ _ auth_seg0 \n  for auth_seg0 :: \"(msgterm \\<times> ahi list) set\"\nbegin\n\n(******************************************************************************)\nsubsection \\<open>Hop validation check and extract functions\\<close>\n(******************************************************************************)\ntype_synonym ICING_HF = \"(unit, unit) HF\"\n\ntext\\<open>The term @{term \"sntag\"} is a key that is derived from the key of an AS and a specific\nhop field. We use it in the computation of @{term \"hf_valid\"}.\\<close>\n\nfun sntag :: \"ahi \\<Rightarrow> msgterm\" where\n  \"sntag \\<lparr>UpIF = upif, DownIF = downif, ASID = asid\\<rparr> = \\<langle>macKey asid,\\<langle>if2term upif,if2term downif\\<rangle>\\<rangle>\"\n\nlemma sntag_eq: \"sntag ahi2 = sntag ahi1 \\<Longrightarrow> ahi2 = ahi1\"\n  by(cases ahi1,cases ahi2) auto\n\ntext\\<open>The predicate @{term \"hf_valid\"} is given to the concrete parametrized model as a parameter.\nIt ensures the authenticity of the hop authenticator in the hop field. The predicate takes an \nexpiration timestamp (in this model always a numeric value, hence the matching on \n@{term \"Num PoC_i_expire\"}), the entire segment and the hop field to be validated.\\<close>\nfun hf_valid :: \"msgterm \\<Rightarrow> msgterm\n    \\<Rightarrow> ICING_HF list\n    \\<Rightarrow> ICING_HF \n    \\<Rightarrow> bool\" where \n  \"hf_valid (Num PoC_i_expire) uinfo hfs \\<lparr>AHI = ahi, UHI = uhi, HVF = x\\<rparr> \\<longleftrightarrow> uhi = () \\<and> \n    x = Mac[sntag ahi] (L ((Num PoC_i_expire)#(map (hf2term o AHI) hfs))) \\<and> uinfo = \\<epsilon>\"\n| \"hf_valid _ _ _ _ = False\"\n\ntext\\<open>We can extract the entire path (past and future) from the hvf field.\\<close>\nfun extr :: \"msgterm \\<Rightarrow> ahi list\" where\n  \"extr (Mac[_] (L hfs))\n = map term2hf (tl hfs)\"\n| \"extr _ = []\"\n\ntext\\<open>Extract the authenticated info field from a hop validation field.\\<close>\nfun extr_ainfo :: \"msgterm \\<Rightarrow> msgterm\" where \n  \"extr_ainfo (Mac[_] (L (Num ts # xs))) = Num ts\"\n| \"extr_ainfo _ = \\<epsilon>\"\n\nabbreviation term_ainfo :: \"msgterm \\<Rightarrow> msgterm\" where\n  \"term_ainfo \\<equiv> id\"\n\ntext\\<open>An authenticated info field is always a number (corresponding to a timestamp). The \n     unauthenticated info field is set to the empty term @{term \"\\<epsilon>\"}.\\<close>\ndefinition auth_restrict where \n  \"auth_restrict ainfo uinfo l \\<equiv> (\\<exists>ts. ainfo = Num ts) \\<and> (uinfo = \\<epsilon>)\"\n\ntext\\<open>When observing a hop field, an attacker learns the HVF. UHI is empty and the AHI only contains \npublic information that are not terms.\\<close>\nfun terms_hf :: \"ICING_HF \\<Rightarrow> msgterm set\" where \n  \"terms_hf hf = {HVF hf}\"\n\nabbreviation terms_uinfo :: \"msgterm \\<Rightarrow> msgterm set\" where \n  \"terms_uinfo x \\<equiv> {x}\"\n\nabbreviation no_oracle where \"no_oracle \\<equiv> (\\<lambda> _ _. True)\"\n\ntext\\<open>We now define useful properties of the above definition.\\<close>\nlemma hf_valid_invert:\n  \"hf_valid tsn uinfo hfs hf \\<longleftrightarrow>\n(\\<exists> ts ahi. tsn = Num ts \\<and> ahi = AHI hf \\<and>\nUHI hf = () \\<and>\nHVF hf = Mac[sntag ahi] (L ((Num ts)#(map (hf2term o AHI) hfs))) \\<and> uinfo = \\<epsilon>)\"\n  apply(cases hf) by(auto elim!: hf_valid.elims)\n\nlemma hf_valid_auth_restrict[dest]: \"hf_valid ainfo uinfo hfs hf \\<Longrightarrow> auth_restrict ainfo uinfo l\"\n  by(auto simp add: hf_valid_invert auth_restrict_def)\n\nlemma auth_restrict_ainfo[dest]: \"auth_restrict ainfo uinfo l \\<Longrightarrow> \\<exists>ts. ainfo = Num ts\"\n  by(auto simp add: auth_restrict_def)\nlemma auth_restrict_uinfo[dest]: \"auth_restrict ainfo uinfo l \\<Longrightarrow> uinfo = \\<epsilon>\"\n  by(auto simp add: auth_restrict_def)\n\n\nlemma info_hvf: \n  assumes \"hf_valid ainfo uinfo hfs m\" \"hf_valid ainfo' uinfo' hfs' m'\" \n          \"HVF m = HVF m'\" \"m \\<in> set hfs\" \"m' \\<in> set hfs'\"\n  shows \"ainfo' = ainfo\" \"m' = m\"\n  using assms\n  apply(auto simp add: hf_valid_invert intro: ahi_eq)\n  apply(cases m,cases m')\n  by(auto intro: sntag_eq)\n\n\n(******************************************************************************)\nsubsection\\<open>Definitions and properties of the added intruder knowledge\\<close>\n(******************************************************************************)\ntext\\<open>Here we define a @{text \"ik_add\"} and @{text \"ik_oracle\"} as being empty, as these features are\nnot used in this instance model.\\<close>\nprint_locale dataplane_3_undirected_defs\nsublocale dataplane_3_undirected_defs _ _ _ auth_seg0 hf_valid auth_restrict extr extr_ainfo \n  term_ainfo terms_hf terms_uinfo no_oracle\n  by unfold_locales\n\ndeclare parts_singleton[dest]\n\nabbreviation ik_add :: \"msgterm set\" where \"ik_add \\<equiv> {}\"\n\nabbreviation ik_oracle :: \"msgterm set\" where \"ik_oracle \\<equiv> {}\"\n\nlemma uinfo_empty[dest]: \"(ainfo, hfs) \\<in> auth_seg2 uinfo \\<Longrightarrow> uinfo = \\<epsilon>\"\n  by(auto simp add: auth_seg2_def auth_restrict_def)\n\n(******************************************************************************)\nsubsection\\<open>Properties of the intruder knowledge, including @{text \"ik_add\"} and  @{text \"ik_oracle\"}\\<close>\n  (******************************************************************************)\ntext\\<open>We now instantiate the parametrized model's definition of the intruder knowledge, using the\ndefinitions of @{text \"ik_add\"} and  @{text \"ik_oracle\"} from above. We then prove the properties \nthat we need to instantiate the @{text \"dataplane_3_undirected\"} locale.\\<close>\nprint_locale dataplane_3_undirected_ik_defs\nsublocale\n  dataplane_3_undirected_ik_defs _ _ _ auth_seg0 terms_uinfo no_oracle hf_valid auth_restrict extr \n    extr_ainfo term_ainfo terms_hf ik_add ik_oracle\n  by unfold_locales\n\nlemma ik_hfs_form: \"t \\<in> parts ik_hfs \\<Longrightarrow> \\<exists> t' . t = Hash t'\"\n  apply auto apply(drule parts_singleton)\n  by(auto simp add: auth_seg2_def hf_valid_invert)\n\ndeclare ik_hfs_def[simp del]\n\nlemma parts_ik_hfs[simp]: \"parts ik_hfs = ik_hfs\"\n  by (auto intro!: parts_Hash ik_hfs_form)\n\ntext\\<open>This lemma allows us not only to expand the definition of @{term \"ik_hfs\"}, but also \nto obtain useful properties, such as a term being a Hash, and it being part of a valid hop field.\\<close>\nlemma ik_hfs_simp: \n  \"t \\<in> ik_hfs \\<longleftrightarrow> (\\<exists>t' . t = Hash t') \\<and> (\\<exists>hf . t = HVF hf\n                    \\<and> (\\<exists>hfs. hf \\<in> set hfs \\<and> (\\<exists>ainfo uinfo. (ainfo, hfs) \\<in> auth_seg2 uinfo\n                    \\<and> hf_valid ainfo uinfo hfs hf)))\" (is \"?lhs \\<longleftrightarrow> ?rhs\")\nproof \n  assume asm: \"?lhs\" \n  then obtain ainfo uinfo hf hfs where \n    dfs: \"hf \\<in> set hfs\" \"(ainfo, hfs) \\<in> auth_seg2 uinfo\" \"t = HVF hf\"\n    by(auto simp add: ik_hfs_def)\n  then obtain uinfo where \"hfs_valid_prefix ainfo uinfo [] hfs = hfs\"  \"(ainfo, AHIS hfs) \\<in> auth_seg0\"\n    by(auto simp add: auth_seg2_def)\n  then show \"?rhs\" using asm dfs\n    by (auto 3 4 simp add: auth_seg2_def intro!: ik_hfs_form exI[of _ hf]) \nqed(auto simp add: ik_hfs_def)\n\nlemma ik_uinfo_empty[simp]: \"ik_uinfo = {\\<epsilon>}\" \n  by(auto simp add: ik_uinfo_def auth_seg2_def auth_restrict_def intro!: exI[of _ \"[]\"])\ndeclare ik_uinfo_def[simp del]\n\n(******************************************************************************)\nsubsubsection \\<open>Properties of Intruder Knowledge\\<close>\n(******************************************************************************)\nlemma auth_ainfo[dest]: \"\\<lbrakk>(ainfo, hfs) \\<in> auth_seg2 uinfo\\<rbrakk> \\<Longrightarrow> \\<exists> ts . ainfo = Num ts\"\n  by(auto simp add: auth_seg2_def)\n\nlemma Num_ik[intro]: \"Num ts \\<in> ik\"\n  by(auto simp add: ik_def auth_seg2_def auth_restrict_def intro!: exI[of _ \"[]\"])\n\ntext \\<open>There are no ciphertexts (or signatures) in @{term \"parts ik\"}. Thus, @{term \"analz ik\"}\nand @{term \"parts ik\"} are identical.\\<close>\nlemma analz_parts_ik[simp]: \"analz ik = parts ik\"\n  by(rule no_crypt_analz_is_parts)\n    (auto simp add: ik_def auth_seg2_def ik_hfs_simp auth_restrict_def)\n\nlemma parts_ik[simp]: \"parts ik = ik\"\n  by(auto 3 4 simp add: ik_def auth_seg2_def auth_restrict_def dest!: parts_singleton_set)\n\nlemma sntag_synth_bad: \"sntag ahi \\<in> synth ik \\<Longrightarrow> ASID ahi \\<in> bad\"\n  apply(cases ahi)\n  by(auto simp add: ik_def ik_hfs_simp)\n\n(******************************************************************************)\nsubsection\\<open>Direct proof goals for interpretation of @{text \"dataplane_3_undirected\"}\\<close>\n(******************************************************************************)\n\nlemma COND_honest_hf_analz:\n  assumes \"ASID (AHI hf) \\<notin> bad\" \"hf_valid ainfo uinfo hfs hf\" \"terms_hf hf \\<subseteq> synth (analz ik)\"\n    \"no_oracle ainfo uinfo\" \"hf \\<in> set hfs\"\n    shows \"terms_hf hf \\<subseteq> analz ik\"\nproof-\n  from assms(3) have hf_synth_ik: \"HVF hf \\<in> synth ik\" by auto\n  then have \"\\<exists>hfs uinfo. hf \\<in> set hfs \\<and> (ainfo, hfs) \\<in> auth_seg2 uinfo\"\n    using assms(1,2,4,5) \n    apply(auto simp add: ik_def hf_valid_invert ik_hfs_simp)\n    subgoal for ts' hf' hfs'\n      using HF.equality by (fastforce dest!: sntag_eq intro: exI[of _ hfs'])\n    by(auto simp add: ik_hfs_simp ik_def hf_valid_invert sntag_synth_bad)\n  then have \"HVF hf \\<in> ik\"\n    using assms(2)\n    by(auto simp add: ik_hfs_def intro!: ik_ik_hfs intro!: exI) \n  then show ?thesis by auto\nqed\n\nlemma COND_terms_hf: \n  assumes \"hf_valid ainfo uinfo hfs hf\" and \"HVF hf \\<in> ik\" and \"no_oracle ainfo uinfo\" and \"hf \\<in> set hfs\"\n  shows \"\\<exists>hfs. hf \\<in> set hfs \\<and> (\\<exists>uinfo' . (ainfo, hfs) \\<in> auth_seg2 uinfo')\"\n  using assms apply(auto 3 4 simp add: hf_valid_invert ik_hfs_simp ik_def dest: ahi_eq)\n  apply(frule sntag_eq)\n  apply(auto simp add: ik_def ik_hfs_simp)\n  by (metis (mono_tags, lifting) HF.surjective old.unit.exhaust)\n\nlemma COND_extr:\n    \"\\<lbrakk>hf_valid ainfo uinfo l hf\\<rbrakk> \\<Longrightarrow> extr (HVF hf) = AHIS l\"\n  by(auto simp add: hf_valid_invert)\n\nlemma COND_hf_valid_uinfo:\n    \"\\<lbrakk>hf_valid ainfo uinfo l hf; hf_valid ainfo' uinfo' l' hf\\<rbrakk> \n    \\<Longrightarrow> uinfo' = uinfo\"\n  by(auto simp add: hf_valid_invert)\n\n(******************************************************************************)\nsubsection\\<open>Instantiation of @{text \"dataplane_3_undirected\"} locale\\<close>\n(******************************************************************************)\nprint_locale dataplane_3_undirected\nsublocale\n  dataplane_3_undirected _ _ _ auth_seg0 hf_valid auth_restrict extr extr_ainfo term_ainfo terms_uinfo ik_add terms_hf \n            ik_oracle  no_oracle\n  apply unfold_locales\n  using COND_terms_hf COND_honest_hf_analz COND_extr COND_hf_valid_uinfo by auto\n\nend\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/IsaNet/instances/ICING_variant.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736783928749127, "lm_q2_score": 0.4493926344647596, "lm_q1q2_score": 0.2578068443095664}}
{"text": "theory Bisim_Struct_Cong\n  imports Bisim_Pres Sim_Struct_Cong Structural_Congruence\nbegin\n\ncontext env begin\n\nlemma bisim_par_comm:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  \n  shows \"\\<Psi> \\<rhd> P \\<parallel> Q \\<sim> Q \\<parallel> P\"\nproof -\n  let ?X = \"{((\\<Psi>::'b), \\<lparr>\\<nu>*xvec\\<rparr>((P::('a, 'b, 'c) psi) \\<parallel> Q), \\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> P)) | xvec \\<Psi> P Q. xvec \\<sharp>* \\<Psi>}\"\n  \n  have \"eqvt ?X\"\n    by(force simp add: eqvt_def pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst] eqvts)\n\n  have \"(\\<Psi>, P \\<parallel> Q, Q \\<parallel> P) \\<in> ?X\"\n    apply auto by(rule_tac x=\"[]\" in exI) auto\n  thus ?thesis\n  proof(coinduct rule: bisim_weak_coinduct)\n    case(c_stat_eq \\<Psi> PQ QP)\n    from `(\\<Psi>, PQ, QP) \\<in> ?X`\n    obtain xvec P Q where P_frQ: \"PQ = \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q)\" and Q_frP: \"QP = \\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> P)\" and \"xvec \\<sharp>* \\<Psi>\"\n      by auto\n\n    obtain A\\<^sub>P \\<Psi>\\<^sub>P where FrP: \"extract_frame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\" and \"A\\<^sub>P \\<sharp>* Q\"\n      by(rule_tac C=\"(\\<Psi>, Q)\" in fresh_frame) auto\n    obtain A\\<^sub>Q \\<Psi>\\<^sub>Q where FrQ: \"extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\" and \"A\\<^sub>Q \\<sharp>* A\\<^sub>P\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P\"\n      by(rule_tac C=\"(\\<Psi>, A\\<^sub>P, \\<Psi>\\<^sub>P)\" in fresh_frame) auto\n    from FrQ `A\\<^sub>Q \\<sharp>* A\\<^sub>P` `A\\<^sub>P \\<sharp>* Q` have \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q\" by(force dest: extract_frame_fresh_chain)\n    have \"\\<langle>(xvec@A\\<^sub>P@A\\<^sub>Q), \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q\\<rangle> \\<simeq>\\<^sub>F \\<langle>(xvec@A\\<^sub>Q@A\\<^sub>P), \\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>P\\<rangle>\"\n      by(simp add: frame_chain_append)\n        (metis frame_res_chain_pres frame_res_chain_comm frame_nil_stat_eq composition_sym Associativity Commutativity Frame_stat_eq_trans)\n    with FrP FrQ P_frQ Q_frP `A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P` `A\\<^sub>Q \\<sharp>* A\\<^sub>P` `xvec \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>`\n    show ?case by(auto simp add: frame_chain_append)\n  next\n    case(c_sim \\<Psi> PQ QP)\n    from `(\\<Psi>, PQ, QP) \\<in> ?X`    \n    obtain xvec P Q where P_frQ: \"PQ = \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q)\" and Q_frP: \"QP = \\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> P)\"\n                      and \"xvec \\<sharp>* \\<Psi>\"\n      by auto\n    moreover have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q) \\<leadsto>[?X] \\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> P)\"\n    proof -\n      have \"\\<Psi> \\<rhd> P \\<parallel> Q \\<leadsto>[?X] Q \\<parallel> P\"\n      proof -\n\tnote `eqvt ?X`\n\tmoreover have \"\\<And>\\<Psi> P Q. (\\<Psi>, P \\<parallel> Q, Q \\<parallel> P) \\<in> ?X\"\n\t  apply auto by(rule_tac x=\"[]\" in exI) auto\n\tmoreover have \"\\<And>\\<Psi> P Q xvec. \\<lbrakk>(\\<Psi>, P, Q) \\<in> ?X; xvec \\<sharp>* \\<Psi>\\<rbrakk> \\<Longrightarrow> (\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>P, \\<lparr>\\<nu>*xvec\\<rparr>Q) \\<in> ?X\"\n\t  apply(induct xvec, auto)\n\t  by(rule_tac x=\"xvec@xveca\" in exI) (auto simp add: res_chain_append)\n\tultimately show ?thesis by(rule sim_par_comm) \n      qed\n      moreover note `eqvt ?X` `xvec \\<sharp>* \\<Psi>`\n      moreover have \"\\<And>\\<Psi> P Q x. \\<lbrakk>(\\<Psi>, P, Q) \\<in> ?X; x \\<sharp> \\<Psi>\\<rbrakk> \\<Longrightarrow> (\\<Psi>, \\<lparr>\\<nu>x\\<rparr>P, \\<lparr>\\<nu>x\\<rparr>Q) \\<in> ?X\"\n\tapply auto\n\tby(rule_tac x=\"x#xvec\" in exI) auto\n      ultimately show ?thesis by(rule res_chain_pres) \n    qed\n    ultimately show ?case by simp\n  next\n    case(c_ext \\<Psi> PQ QP \\<Psi>')\n    from `(\\<Psi>, PQ, QP) \\<in> ?X`\n    obtain xvec P Q where P_frQ: \"PQ = \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q)\" and Q_frP: \"QP = \\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> P)\"\n                      and \"xvec \\<sharp>* \\<Psi>\"\n      by auto\n    \n    obtain p where \"(p \\<bullet> xvec) \\<sharp>* \\<Psi>\"\n               and \"(p \\<bullet> xvec) \\<sharp>* P\"\n               and \"(p \\<bullet> xvec) \\<sharp>* Q\"\n               and \"(p \\<bullet> xvec) \\<sharp>* \\<Psi>'\"\n               and S: \"(set p) \\<subseteq> (set xvec) \\<times> (set(p \\<bullet> xvec))\" and \"distinct_perm p\"\n      by(rule_tac c=\"(\\<Psi>, P, Q, \\<Psi>')\" in name_list_avoiding) auto\n\n    from `(p \\<bullet> xvec) \\<sharp>* P` `(p \\<bullet> xvec) \\<sharp>* Q` S have \"\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q) = \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>(p \\<bullet> (P \\<parallel> Q))\"\n      by(subst res_chain_alpha) auto\n    hence P_q_alpha: \"\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q) = \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> P) \\<parallel> (p \\<bullet> Q))\"\n      by(simp add: eqvts)\n\n    from `(p \\<bullet> xvec) \\<sharp>* P` `(p \\<bullet> xvec) \\<sharp>* Q` S have \"\\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> P) = \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>(p \\<bullet> (Q \\<parallel> P))\"\n      by(subst res_chain_alpha) auto\n    hence Q_p_alpha: \"\\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> P) = \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> Q) \\<parallel> (p \\<bullet> P))\"\n      by(simp add: eqvts)\n\n    from `(p \\<bullet> xvec) \\<sharp>* \\<Psi>` `(p \\<bullet> xvec) \\<sharp>* \\<Psi>'` have \"(\\<Psi> \\<otimes> \\<Psi>', \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> P) \\<parallel> (p \\<bullet> Q)), \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> Q) \\<parallel> (p \\<bullet> P))) \\<in> ?X\"\n      by auto\n    with P_frQ Q_frP P_q_alpha Q_p_alpha show ?case by simp\n  next\n    case(c_sym \\<Psi> PR QR)\n    thus ?case by blast\n  qed\nqed\n\nlemma bisim_res_comm:\n  fixes x :: name\n  and   \\<Psi> :: 'b\n  and   y :: name\n  and   P :: \"('a, 'b, 'c) psi\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>y\\<rparr>P) \\<sim> \\<lparr>\\<nu>y\\<rparr>(\\<lparr>\\<nu>x\\<rparr>P)\"\nproof(cases \"x=y\")\n  case True\n  thus ?thesis by(blast intro: bisim_reflexive)\nnext\n  case False\n  {\n    fix x::name and y::name and P::\"('a, 'b, 'c) psi\"\n    assume \"x \\<sharp> \\<Psi>\" and \"y \\<sharp> \\<Psi>\"\n    let ?X = \"{((\\<Psi>::'b), \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>y\\<rparr>(P::('a, 'b, 'c) psi)), \\<lparr>\\<nu>y\\<rparr>(\\<lparr>\\<nu>x\\<rparr>P)) | \\<Psi> x y P. x \\<sharp> \\<Psi> \\<and> y \\<sharp> \\<Psi>}\"\n    from `x \\<sharp> \\<Psi>` `y \\<sharp> \\<Psi>` have \"(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>y\\<rparr>P), \\<lparr>\\<nu>y\\<rparr>(\\<lparr>\\<nu>x\\<rparr>P)) \\<in> ?X\" by auto\n    hence \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>y\\<rparr>P) \\<sim> \\<lparr>\\<nu>y\\<rparr>(\\<lparr>\\<nu>x\\<rparr>P)\"\n    proof(coinduct rule: bisim_coinduct)\n      case(c_stat_eq \\<Psi> xyP yxP)\n      from `(\\<Psi>, xyP, yxP) \\<in> ?X` obtain x y P where \"x \\<sharp> \\<Psi>\" and \"y \\<sharp> \\<Psi>\" and \"xyP = \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>y\\<rparr>P)\" and \"yxP = \\<lparr>\\<nu>y\\<rparr>(\\<lparr>\\<nu>x\\<rparr>P)\" by auto\n      moreover obtain A\\<^sub>P \\<Psi>\\<^sub>P where \"extract_frame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\" and \"x \\<sharp> A\\<^sub>P\" and \"y \\<sharp> A\\<^sub>P\"\n\tby(rule_tac C=\"(x, y, \\<Psi>)\" in fresh_frame) auto\n      ultimately show ?case by(force intro: frame_res_comm Frame_stat_eq_trans)\n    next\n      case(c_sim \\<Psi> xyP yxP)\n      from `(\\<Psi>, xyP, yxP) \\<in> ?X` obtain x y P where \"x \\<sharp> \\<Psi>\" and \"y \\<sharp> \\<Psi>\" and \"xyP = \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>y\\<rparr>P)\" and \"yxP = \\<lparr>\\<nu>y\\<rparr>(\\<lparr>\\<nu>x\\<rparr>P)\" by auto\n      note `x \\<sharp> \\<Psi>` `y \\<sharp> \\<Psi>`\n      moreover have \"eqvt ?X\" by(force simp add: eqvt_def pt_fresh_bij[OF pt_name_inst, OF at_name_inst])\n      hence \"eqvt(?X \\<union> bisim)\" by auto\n      moreover have \"\\<And>\\<Psi> P. (\\<Psi>, P, P) \\<in> ?X \\<union> bisim\" by(blast intro: bisim_reflexive)\n      moreover have \"\\<And>\\<Psi> x y P. \\<lbrakk>x \\<sharp> \\<Psi>; y \\<sharp> \\<Psi>\\<rbrakk> \\<Longrightarrow> (\\<Psi>, \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>y\\<rparr>P), \\<lparr>\\<nu>y\\<rparr>(\\<lparr>\\<nu>x\\<rparr>P)) \\<in> ?X \\<union> bisim\" by auto\n      ultimately have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>y\\<rparr>P) \\<leadsto>[(?X \\<union> bisim)] \\<lparr>\\<nu>y\\<rparr>(\\<lparr>\\<nu>x\\<rparr>P)\" by(rule res_comm)\n      with `xyP = \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>y\\<rparr>P)` `yxP = \\<lparr>\\<nu>y\\<rparr>(\\<lparr>\\<nu>x\\<rparr>P)` show ?case\n\tby simp\n    next\n      case(c_ext \\<Psi> xyP yxP \\<Psi>')\n      from `(\\<Psi>, xyP, yxP) \\<in> ?X` obtain x y P where \"x \\<sharp> \\<Psi>\" and \"y \\<sharp> \\<Psi>\" and xy_peq: \"xyP = \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>y\\<rparr>P)\" and yx_peq: \"yxP = \\<lparr>\\<nu>y\\<rparr>(\\<lparr>\\<nu>x\\<rparr>P)\" by auto\n      show ?case\n      proof(case_tac \"x=y\")\n\tassume \"x = y\"\n\twith xy_peq yx_peq show ?case\n\t  by(blast intro: bisim_reflexive)\n      next\n\tassume \"x \\<noteq> y\"\n\tobtain x' where \"x' \\<sharp> \\<Psi>\" and \"x' \\<sharp> \\<Psi>'\" and \"x' \\<noteq> x\" and \"x' \\<noteq> y\" and \"x' \\<sharp> P\" by(generate_fresh \"name\") (auto simp add: fresh_prod)\n\tobtain y' where \"y' \\<sharp> \\<Psi>\" and \"y' \\<sharp> \\<Psi>'\" and \"y' \\<noteq> x\" and \"x' \\<noteq> y'\" and \"y' \\<noteq> y\" and \"y' \\<sharp> P\" by(generate_fresh \"name\") (auto simp add: fresh_prod)\n\twith xy_peq `y' \\<sharp> P` `x' \\<sharp> P` `x \\<noteq> y` `x' \\<noteq> y` `y' \\<noteq> x` have \"\\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>y\\<rparr>P) = \\<lparr>\\<nu>x'\\<rparr>(\\<lparr>\\<nu>y'\\<rparr>([(x, x')] \\<bullet> [(y, y')] \\<bullet> P))\"\n\t  apply(subst alpha_res[of x']) apply(simp add: abs_fresh) by(subst alpha_res[of y' _ y]) (auto simp add: eqvts calc_atm)\n\tmoreover with yx_peq `y' \\<sharp> P` `x' \\<sharp> P` `x \\<noteq> y` `x' \\<noteq> y` `y' \\<noteq> x` `x' \\<noteq> y'` have \"\\<lparr>\\<nu>y\\<rparr>(\\<lparr>\\<nu>x\\<rparr>P) = \\<lparr>\\<nu>y'\\<rparr>(\\<lparr>\\<nu>x'\\<rparr>([(y, y')] \\<bullet> [(x, x')] \\<bullet> P))\"\n\t  apply(subst alpha_res[of y']) apply(simp add: abs_fresh) by(subst alpha_res[of x' _ x]) (auto simp add: eqvts calc_atm)\n\twith `x \\<noteq> y` `x' \\<noteq> y` `y' \\<noteq> y` `x' \\<noteq> x` `y' \\<noteq> x` `x' \\<noteq> y'` have \"\\<lparr>\\<nu>y\\<rparr>(\\<lparr>\\<nu>x\\<rparr>P) = \\<lparr>\\<nu>y'\\<rparr>(\\<lparr>\\<nu>x'\\<rparr>([(x, x')] \\<bullet> [(y, y')] \\<bullet> P))\"\n\t  by(subst perm_compose) (simp add: calc_atm)\n\tmoreover from `x' \\<sharp> \\<Psi>` `x' \\<sharp> \\<Psi>'` `y' \\<sharp> \\<Psi>` `y' \\<sharp> \\<Psi>'` have \"(\\<Psi> \\<otimes> \\<Psi>', \\<lparr>\\<nu>x'\\<rparr>(\\<lparr>\\<nu>y'\\<rparr>([(x, x')] \\<bullet> [(y, y')] \\<bullet> P)), \\<lparr>\\<nu>y'\\<rparr>(\\<lparr>\\<nu>x'\\<rparr>([(x, x')] \\<bullet> [(y, y')] \\<bullet> P))) \\<in> ?X\"\n\t  by auto\n\tultimately show ?case using xy_peq yx_peq by simp\n      qed\n    next\n      case(c_sym \\<Psi> xyP yxP)\n      thus ?case by auto\n    qed\n  }\n  moreover obtain x'::name where \"x' \\<sharp> \\<Psi>\" and \"x' \\<sharp> P\" and \"x' \\<noteq> x\" and \"x' \\<noteq> y\"\n    by(generate_fresh \"name\") auto\n  moreover obtain y'::name where \"y' \\<sharp> \\<Psi>\" and \"y' \\<sharp> P\" and \"y' \\<noteq> x\" and \"y' \\<noteq> y\" and \"y' \\<noteq> x'\"\n    by(generate_fresh \"name\") auto\n  ultimately have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x'\\<rparr>(\\<lparr>\\<nu>y'\\<rparr>([(y, y'), (x, x')] \\<bullet> P)) \\<sim> \\<lparr>\\<nu>y'\\<rparr>(\\<lparr>\\<nu>x'\\<rparr>([(y, y'), (x, x')] \\<bullet> P))\" by auto\n  thus ?thesis using `x' \\<sharp> P` `x' \\<noteq> x` `x' \\<noteq> y` `y' \\<sharp> P` `y' \\<noteq> x` `y' \\<noteq> y` `y' \\<noteq> x'` `x \\<noteq> y`\n    apply(subst alpha_res[where x=x and y=x' and P=P], auto)\n    apply(subst alpha_res[where x=y and y=y' and P=P], auto)\n    apply(subst alpha_res[where x=x and y=x' and P=\"\\<lparr>\\<nu>y'\\<rparr>([(y, y')] \\<bullet> P)\"], auto simp add: abs_fresh fresh_left)\n    apply(subst alpha_res[where x=y and y=y' and P=\"\\<lparr>\\<nu>x'\\<rparr>([(x, x')] \\<bullet> P)\"], auto simp add: abs_fresh fresh_left)\n    by(subst perm_compose) (simp add: eqvts calc_atm)\nqed\n\nlemma bisim_res_comm':\n  fixes x    :: name\n  and   \\<Psi>   :: 'b\n  and   xvec :: \"name list\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n\n  assumes \"x \\<sharp> \\<Psi>\"\n  and     \"xvec \\<sharp>* \\<Psi>\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>*xvec\\<rparr>P) \\<sim> \\<lparr>\\<nu>*xvec\\<rparr>(\\<lparr>\\<nu>x\\<rparr>P)\"\nusing assms\nby(induct xvec) (auto intro: bisim_res_comm bisim_reflexive bisim_res_pres bisim_transitive)\n\nlemma bisim_scope_ext:\n  fixes x :: name\n  and   \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes \"x \\<sharp> P\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q) \\<sim> P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q\"\nproof -\n  {\n    fix x::name and Q :: \"('a, 'b, 'c) psi\"\n    assume \"x \\<sharp> \\<Psi>\" and \"x \\<sharp> P\"\n    let ?X1 = \"{((\\<Psi>::'b), \\<lparr>\\<nu>*xvec\\<rparr>(\\<lparr>\\<nu>x\\<rparr>((P::('a, 'b, 'c) psi) \\<parallel> Q)), \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q)) | \\<Psi> xvec x P Q. x \\<sharp> \\<Psi> \\<and> x \\<sharp> P \\<and> xvec \\<sharp>* \\<Psi>}\"\n    let ?X2 = \"{((\\<Psi>::'b), \\<lparr>\\<nu>*xvec\\<rparr>((P::('a, 'b, 'c) psi) \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q), \\<lparr>\\<nu>*xvec\\<rparr>(\\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q))) | \\<Psi> xvec x P Q. x \\<sharp> \\<Psi> \\<and> x \\<sharp> P \\<and> xvec \\<sharp>* \\<Psi>}\"\n    let ?X = \"?X1 \\<union> ?X2\"\n\n    from `x \\<sharp> \\<Psi>` `x \\<sharp> P` have \"(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q), P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q) \\<in> ?X\"\n      by(auto, rule_tac x=\"[]\" in exI) (auto simp add: fresh_list_nil)\n    moreover have \"eqvt ?X\"\n      by(rule eqvt_union)\n    (force simp add: eqvt_def eqvts pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst] pt_fresh_bij[OF pt_name_inst, OF at_name_inst])+\n    ultimately have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q) \\<sim> P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q\"\n    proof(coinduct rule: transitive_coinduct)\n      case(c_stat_eq \\<Psi> R T)\n      show ?case\n      proof(case_tac \"(\\<Psi>, R, T) \\<in> ?X1\")\n\tassume \"(\\<Psi>, R, T) \\<in> ?X1\"\n\tthen obtain xvec x P Q where \"R = \\<lparr>\\<nu>*xvec\\<rparr>(\\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q))\" and \"T = \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q)\" and \"xvec \\<sharp>* \\<Psi>\" and \"x \\<sharp> P\" and \"x \\<sharp> \\<Psi>\"\n\t  by auto\n\tmoreover obtain A\\<^sub>P \\<Psi>\\<^sub>P where FrP: \"extract_frame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\" and \"x \\<sharp> A\\<^sub>P\" and \"A\\<^sub>P \\<sharp>* Q\"\n\t  by(rule_tac C=\"(\\<Psi>, x, Q)\" in fresh_frame) auto\n\tmoreover obtain A\\<^sub>Q \\<Psi>\\<^sub>Q where FrQ: \"extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\" and \"x \\<sharp> A\\<^sub>Q\" and \"A\\<^sub>Q \\<sharp>* A\\<^sub>P\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P\"\n\t  by(rule_tac C=\"(\\<Psi>, x, A\\<^sub>P, \\<Psi>\\<^sub>P)\" in fresh_frame) auto\n\tmoreover from FrQ `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* A\\<^sub>P` have \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q\"\n\t  by(drule_tac extract_frame_fresh_chain) auto\n\tmoreover from `x \\<sharp> P` `x \\<sharp> A\\<^sub>P` FrP have \"x \\<sharp> \\<Psi>\\<^sub>P\" by(drule_tac extract_frame_fresh) auto\n\tultimately show ?case\n\t  by(force simp add: frame_chain_append intro: frame_res_comm' Frame_stat_eq_trans frame_res_chain_pres)\n      next\n\tassume \"(\\<Psi>, R, T) \\<notin> ?X1\"\n\twith `(\\<Psi>, R, T) \\<in> ?X` have \"(\\<Psi>, R, T) \\<in> ?X2\" by blast\n\tthen obtain xvec x P Q where \"T = \\<lparr>\\<nu>*xvec\\<rparr>(\\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q))\" and \"R = \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q)\" and \"xvec \\<sharp>* \\<Psi>\" and \"x \\<sharp> P\" and \"x \\<sharp> \\<Psi>\"\n\t  by auto\n\tmoreover obtain A\\<^sub>P \\<Psi>\\<^sub>P where FrP: \"extract_frame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\" and \"x \\<sharp> A\\<^sub>P\" and \"A\\<^sub>P \\<sharp>* Q\"\n\t  by(rule_tac C=\"(\\<Psi>, x, Q)\" in fresh_frame) auto\n\tmoreover obtain A\\<^sub>Q \\<Psi>\\<^sub>Q where FrQ: \"extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\" and \"x \\<sharp> A\\<^sub>Q\" and \"A\\<^sub>Q \\<sharp>* A\\<^sub>P\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P\"\n\t  by(rule_tac C=\"(\\<Psi>, x, A\\<^sub>P, \\<Psi>\\<^sub>P)\" in fresh_frame) auto\n\tmoreover from FrQ `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* A\\<^sub>P` have \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q\"\n\t  by(drule_tac extract_frame_fresh_chain) auto\n\tmoreover from `x \\<sharp> P` `x \\<sharp> A\\<^sub>P` FrP have \"x \\<sharp> \\<Psi>\\<^sub>P\" by(drule_tac extract_frame_fresh) auto\n\tultimately show ?case\n\t  apply auto\n\t  by(force simp add: frame_chain_append intro: frame_res_comm' Frame_stat_eq_trans frame_res_chain_pres Frame_stat_eq_sym)\n      qed\n    next\n      case(c_sim \\<Psi> R T)\n      let ?Y = \"{(\\<Psi>, P, Q) | \\<Psi> P P' Q' Q. \\<Psi> \\<rhd> P \\<sim> P' \\<and> ((\\<Psi>, P', Q') \\<in> ?X \\<or> \\<Psi> \\<rhd> P' \\<sim> Q') \\<and> \\<Psi> \\<rhd> Q' \\<sim> Q}\"\n      from `eqvt ?X` have \"eqvt ?Y\" by blast\n      have C1: \"\\<And>\\<Psi> R T y. \\<lbrakk>(\\<Psi>, R, T) \\<in> ?Y; (y::name) \\<sharp> \\<Psi>\\<rbrakk> \\<Longrightarrow> (\\<Psi>, \\<lparr>\\<nu>y\\<rparr>R, \\<lparr>\\<nu>y\\<rparr>T) \\<in> ?Y\"\n      proof -\n\tfix \\<Psi> R T y\n\tassume \"(\\<Psi>, R, T) \\<in> ?Y\"\n\tthen obtain R' T' where \"\\<Psi> \\<rhd> R \\<sim> R'\" and \"(\\<Psi>, R', T') \\<in> (?X \\<union> bisim)\" and \"\\<Psi> \\<rhd> T' \\<sim> T\" by force\n\tassume \"(y::name) \\<sharp> \\<Psi>\" \n\tshow \"(\\<Psi>, \\<lparr>\\<nu>y\\<rparr>R, \\<lparr>\\<nu>y\\<rparr>T) \\<in> ?Y\"\n\tproof(case_tac \"(\\<Psi>, R', T') \\<in> ?X\")\n\t  assume \"(\\<Psi>, R', T') \\<in> ?X\"\n\t  show ?thesis\n\t  proof(case_tac \"(\\<Psi>, R', T') \\<in> ?X1\")\n\t    assume \"(\\<Psi>, R', T') \\<in> ?X1\"\n\t    then obtain xvec x P Q where R'eq: \"R' = \\<lparr>\\<nu>*xvec\\<rparr>(\\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q))\" and T'eq: \"T' = \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q)\"\n                                     and \"xvec \\<sharp>* \\<Psi>\" and \"x \\<sharp> P\" and \"x \\<sharp> \\<Psi>\"\n\t      by auto\n\t    from `\\<Psi> \\<rhd> R \\<sim> R'` `y \\<sharp> \\<Psi>` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>y\\<rparr>R \\<sim> \\<lparr>\\<nu>y\\<rparr>R'\" by(rule bisim_res_pres)\n\t    moreover from `xvec \\<sharp>* \\<Psi>` `y \\<sharp> \\<Psi>` `x \\<sharp> P` `x \\<sharp> \\<Psi>` have \"(\\<Psi>, \\<lparr>\\<nu>*(y#xvec)\\<rparr>\\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q), \\<lparr>\\<nu>*(y#xvec)\\<rparr>(P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q)) \\<in> ?X1\"\n\t      by(force simp del: res_chain.simps)\n\t    with R'eq T'eq have \"(\\<Psi>, \\<lparr>\\<nu>y\\<rparr>R', \\<lparr>\\<nu>y\\<rparr>T') \\<in> ?X \\<union> bisim\" by simp\n\t    moreover from `\\<Psi> \\<rhd> T' \\<sim> T` `y \\<sharp> \\<Psi>` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>y\\<rparr>T' \\<sim> \\<lparr>\\<nu>y\\<rparr>T\" by(rule bisim_res_pres)\n\t    ultimately show ?thesis by blast\n\t  next\n\t    assume \"(\\<Psi>, R', T') \\<notin> ?X1\"\n\t    with `(\\<Psi>, R', T') \\<in> ?X` have \"(\\<Psi>, R', T') \\<in> ?X2\" by blast\n\t    then obtain xvec x P Q where T'eq: \"T' = \\<lparr>\\<nu>*xvec\\<rparr>(\\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q))\" and R'eq: \"R' = \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q)\" and \"xvec \\<sharp>* \\<Psi>\" and \"x \\<sharp> P\" and \"x \\<sharp> \\<Psi>\"\n\t      by auto\n\t    from `\\<Psi> \\<rhd> R \\<sim> R'` `y \\<sharp> \\<Psi>` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>y\\<rparr>R \\<sim> \\<lparr>\\<nu>y\\<rparr>R'\" by(rule bisim_res_pres)\n\t    moreover from `xvec \\<sharp>* \\<Psi>` `y \\<sharp> \\<Psi>` `x \\<sharp> P` `x \\<sharp> \\<Psi>` have \"(\\<Psi>, \\<lparr>\\<nu>*(y#xvec)\\<rparr>(P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q), \\<lparr>\\<nu>*(y#xvec)\\<rparr>(\\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q))) \\<in> ?X2\"\n\t      by(force simp del: res_chain.simps)\n\t    with R'eq T'eq have \"(\\<Psi>, \\<lparr>\\<nu>y\\<rparr>R', \\<lparr>\\<nu>y\\<rparr>T') \\<in> ?X \\<union> bisim\" by simp\n\t    moreover from `\\<Psi> \\<rhd> T' \\<sim> T` `y \\<sharp> \\<Psi>` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>y\\<rparr>T' \\<sim> \\<lparr>\\<nu>y\\<rparr>T\" by(rule bisim_res_pres)\n\t    ultimately show ?thesis by blast\n\t  qed\n\tnext\n\t  assume \"(\\<Psi>, R', T') \\<notin> ?X\"\n\t  with `(\\<Psi>, R', T') \\<in> ?X \\<union> bisim` have \"\\<Psi> \\<rhd> R' \\<sim> T'\" by blast\n\t  with `\\<Psi> \\<rhd> R \\<sim> R'` `\\<Psi> \\<rhd> T' \\<sim> T` `y \\<sharp> \\<Psi>` show ?thesis\n\t    by(blast dest: bisim_res_pres)\n\tqed\n      qed\n      \n      show ?case\n      proof(case_tac \"(\\<Psi>, R, T) \\<in> ?X1\")\n\tassume \"(\\<Psi>, R, T) \\<in> ?X1\"\n\tthen obtain xvec x P Q where Req: \"R = \\<lparr>\\<nu>*xvec\\<rparr>(\\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q))\" and Teq: \"T = \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q)\" and \"xvec \\<sharp>* \\<Psi>\" and \"x \\<sharp> P\" and \"x \\<sharp> \\<Psi>\"\n\t  by auto\n\thave \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(\\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q)) \\<leadsto>[?Y] \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q)\"\n\tproof -\n\t  have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q) \\<leadsto>[?Y] P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q\"\n\t  proof -\n\t    note `x \\<sharp> P` `x \\<sharp> \\<Psi>` `eqvt ?Y`\n\t    moreover have \"\\<And>\\<Psi> P. (\\<Psi>, P, P) \\<in> ?Y\" by(blast intro: bisim_reflexive)\n\t    moreover have \"\\<And>x \\<Psi> P Q xvec. \\<lbrakk>x \\<sharp> \\<Psi>; x \\<sharp> P; xvec \\<sharp>* \\<Psi>\\<rbrakk> \\<Longrightarrow> (\\<Psi>, \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q)), \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q)) \\<in> ?Y\"\n\t    proof -\n\t      fix x \\<Psi> P Q xvec\n\t      assume \"(x::name) \\<sharp> (\\<Psi>::'b)\" and \"x \\<sharp> (P::('a, 'b, 'c) psi)\" and \"(xvec::name list) \\<sharp>* \\<Psi>\"\n\t      from `x \\<sharp> \\<Psi>` `xvec \\<sharp>* \\<Psi>` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q)) \\<sim> \\<lparr>\\<nu>*xvec\\<rparr>(\\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q))\"\n\t\tby(rule bisim_res_comm')\n\t      moreover from `xvec \\<sharp>* \\<Psi>` `x \\<sharp> \\<Psi>` `x \\<sharp> P` have \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(\\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q)), \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q)) \\<in> ?X \\<union> bisim\"\n\t\tby blast\n\t      ultimately show \"(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q)), \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q)) \\<in> ?Y\" \n\t\tby(blast intro: bisim_reflexive)\n\t    qed\n\t    moreover have \"\\<And>\\<Psi> xvec P x. \\<lbrakk>x \\<sharp> \\<Psi>; xvec \\<sharp>* \\<Psi>\\<rbrakk> \\<Longrightarrow> (\\<Psi>, \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>*xvec\\<rparr>P), \\<lparr>\\<nu>*xvec\\<rparr>(\\<lparr>\\<nu>x\\<rparr>P)) \\<in> ?Y\"\n\t      by(blast intro: bisim_res_comm' bisim_reflexive)\n\t    ultimately show ?thesis by(rule scope_ext_left)\n\t  qed\n\t  thus ?thesis using `eqvt ?Y` `xvec \\<sharp>* \\<Psi>` C1 \n\t    by(rule res_chain_pres)\n\tqed\n\twith Req Teq show ?case by simp\n      next\n\tassume \"(\\<Psi>, R, T) \\<notin> ?X1\"\n\twith `(\\<Psi>, R, T) \\<in> ?X` have \"(\\<Psi>, R, T) \\<in> ?X2\" by blast\n\tthen obtain xvec x P Q where Teq: \"T = \\<lparr>\\<nu>*xvec\\<rparr>(\\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q))\" and Req: \"R = \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q)\" and \"xvec \\<sharp>* \\<Psi>\" and \"x \\<sharp> P\" and \"x \\<sharp> \\<Psi>\"\n\t  by auto\n\thave \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q) \\<leadsto>[?Y] \\<lparr>\\<nu>*xvec\\<rparr>(\\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q))\"\n\tproof -\n\t  have \"\\<Psi> \\<rhd> P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q \\<leadsto>[?Y] \\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q)\"\n\t  proof -\n\t    note `x \\<sharp> P` `x \\<sharp> \\<Psi>` `eqvt ?Y`\n\t    moreover have \"\\<And>\\<Psi> P. (\\<Psi>, P, P) \\<in> ?Y\" by(blast intro: bisim_reflexive)\n\t    moreover have \"\\<And>x \\<Psi> P Q xvec. \\<lbrakk>x \\<sharp> \\<Psi>; x \\<sharp> P; xvec \\<sharp>* \\<Psi>\\<rbrakk> \\<Longrightarrow> (\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q), \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q))) \\<in> ?Y\"\n\t    proof -\n\t      fix x \\<Psi> P Q xvec\n\t      assume \"(x::name) \\<sharp> (\\<Psi>::'b)\" and \"x \\<sharp> (P::('a, 'b, 'c) psi)\" and \"(xvec::name list) \\<sharp>* \\<Psi>\"\n\t      from `xvec \\<sharp>* \\<Psi>` `x \\<sharp> \\<Psi>` `x \\<sharp> P` have \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q), \\<lparr>\\<nu>*xvec\\<rparr>(\\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q))) \\<in> ?X \\<union> bisim\"\n\t\tby blast\n\t      moreover from `x \\<sharp> \\<Psi>` `xvec \\<sharp>* \\<Psi>` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(\\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q)) \\<sim> \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q))\"\n\t\tby(blast intro: bisim_res_comm' bisimE)\n\t      ultimately show \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q), \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q))) \\<in> ?Y\" \n\t\tby(blast intro: bisim_reflexive)\n\t    qed\n\t    ultimately show ?thesis by(rule scope_ext_right)\n\t  qed\n\t  thus ?thesis using `eqvt ?Y` `xvec \\<sharp>* \\<Psi>` C1 \n\t    by(rule res_chain_pres)\n\tqed\n\twith Req Teq show ?case by simp\n      qed\n    next\n      case(c_ext \\<Psi> R T \\<Psi>')\n      show ?case\n      proof(case_tac \"(\\<Psi>, R, T) \\<in> ?X1\")\n\tassume \"(\\<Psi>, R, T) \\<in> ?X1\"\n\tthen obtain xvec x P Q where Req: \"R = \\<lparr>\\<nu>*xvec\\<rparr>(\\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q))\" and Teq: \"T = \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q)\" and \"xvec \\<sharp>* \\<Psi>\" and \"x \\<sharp> P\" and \"x \\<sharp> \\<Psi>\"\n\t  by auto\n\tobtain y::name where \"y \\<sharp> P\" and \"y \\<sharp> Q\" and \"y \\<sharp> xvec\" and \"y \\<sharp> \\<Psi>\" and \"y \\<sharp> \\<Psi>'\"\n\t  by(generate_fresh \"name\", auto simp add: fresh_prod)\n\n\tobtain p where \"(p \\<bullet> xvec) \\<sharp>* \\<Psi>\" and \"(p \\<bullet> xvec) \\<sharp>* P\" and \"(p \\<bullet> xvec) \\<sharp>* Q\" and \"(p \\<bullet> xvec) \\<sharp>* \\<Psi>'\"\n                  and \"x \\<sharp> (p \\<bullet> xvec)\" and \"y \\<sharp> (p \\<bullet> xvec)\"\n                   and S: \"(set p) \\<subseteq> (set xvec) \\<times> (set(p \\<bullet> xvec))\" and \"distinct_perm p\"\n\t  by(rule_tac c=\"(\\<Psi>, P, Q, x, y, \\<Psi>')\" in name_list_avoiding) auto\n\t\n\t\n\tfrom `y \\<sharp> P` have \"(p \\<bullet> y) \\<sharp> (p \\<bullet> P)\" by(simp add: pt_fresh_bij[OF pt_name_inst, OF at_name_inst])\n\twith S `y \\<sharp> xvec` `y \\<sharp> (p \\<bullet> xvec)` have \"y \\<sharp> (p \\<bullet> P)\" by simp\n\twith `(p \\<bullet> xvec) \\<sharp>* \\<Psi>` `y \\<sharp> \\<Psi>` `(p \\<bullet> xvec) \\<sharp>* \\<Psi>'` `y \\<sharp> \\<Psi>'`\n\thave \"(\\<Psi> \\<otimes> \\<Psi>', \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>(\\<lparr>\\<nu>y\\<rparr>((p \\<bullet> P) \\<parallel> (p \\<bullet> [(x, y)] \\<bullet> Q))), \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> P) \\<parallel> (\\<lparr>\\<nu>y\\<rparr>(p \\<bullet> [(x, y)] \\<bullet> Q)))) \\<in> ?X\"\n\t  by auto\n\tmoreover from Req `(p \\<bullet> xvec) \\<sharp>* P` `(p \\<bullet> xvec) \\<sharp>* Q` `y \\<sharp> xvec` `y \\<sharp> (p \\<bullet> xvec)` `x \\<sharp> (p \\<bullet> xvec)` `y \\<sharp> P` `y \\<sharp> Q` `x \\<sharp> P` S\n\thave \"R = \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>(\\<lparr>\\<nu>y\\<rparr>((p \\<bullet> P) \\<parallel> (p \\<bullet> [(x, y)] \\<bullet> Q)))\"\n\t  apply(erule_tac rev_mp)\n\t  apply(subst alpha_res[of y])\n\t  apply(clarsimp simp add: eqvts)\n\t  apply(subst res_chain_alpha[of p])\n\t  by(auto simp add: eqvts)\n\tmoreover from Teq `(p \\<bullet> xvec) \\<sharp>* P` `(p \\<bullet> xvec) \\<sharp>* Q` `y \\<sharp> xvec` `y \\<sharp> (p \\<bullet> xvec)` `x \\<sharp> (p \\<bullet> xvec)` `y \\<sharp> P` `y \\<sharp> Q` `x \\<sharp> P` S\n\thave \"T = \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> P) \\<parallel> \\<lparr>\\<nu>y\\<rparr>(p \\<bullet> [(x, y)] \\<bullet> Q))\"\n\t  apply(erule_tac rev_mp)\n\t  apply(subst alpha_res[of y])\n\t  apply(clarsimp simp add: eqvts)\n\t  apply(subst res_chain_alpha[of p])\n\t  by(auto simp add: eqvts)\n\tultimately show ?case\n\t  by blast\n      next\n\tassume \"(\\<Psi>, R, T) \\<notin> ?X1\"\n\twith `(\\<Psi>, R, T) \\<in> ?X` have \"(\\<Psi>, R, T) \\<in> ?X2\" by blast\n\tthen obtain xvec x P Q where Teq: \"T = \\<lparr>\\<nu>*xvec\\<rparr>(\\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q))\" and Req: \"R = \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> \\<lparr>\\<nu>x\\<rparr>Q)\" and \"xvec \\<sharp>* \\<Psi>\" and \"x \\<sharp> P\" and \"x \\<sharp> \\<Psi>\"\n\t  by auto\n\tobtain y::name where \"y \\<sharp> P\" and \"y \\<sharp> Q\" and \"y \\<sharp> xvec\" and \"y \\<sharp> \\<Psi>\" and \"y \\<sharp> \\<Psi>'\"\n\t  by(generate_fresh \"name\", auto simp add: fresh_prod)\n\n\tobtain p where \"(p \\<bullet> xvec) \\<sharp>* \\<Psi>\" and \"(p \\<bullet> xvec) \\<sharp>* P\" and \"(p \\<bullet> xvec) \\<sharp>* Q\" and \"(p \\<bullet> xvec) \\<sharp>* \\<Psi>'\"\n                   and \"x \\<sharp> (p \\<bullet> xvec)\" and \"y \\<sharp> (p \\<bullet> xvec)\"\n                   and S: \"(set p) \\<subseteq> (set xvec) \\<times> (set(p \\<bullet> xvec))\" and \"distinct_perm p\"\n\t  by(rule_tac c=\"(\\<Psi>, P, Q, x, y, \\<Psi>')\" in name_list_avoiding) auto\n\t\n\tfrom `y \\<sharp> P` have \"(p \\<bullet> y) \\<sharp> (p \\<bullet> P)\" by(simp add: pt_fresh_bij[OF pt_name_inst, OF at_name_inst])\n\twith S `y \\<sharp> xvec` `y \\<sharp> (p \\<bullet> xvec)` have \"y \\<sharp> (p \\<bullet> P)\" by simp\n\twith `(p \\<bullet> xvec) \\<sharp>* \\<Psi>` `y \\<sharp> \\<Psi>` `(p \\<bullet> xvec) \\<sharp>* \\<Psi>'` `y \\<sharp> \\<Psi>'`\n\thave \"(\\<Psi> \\<otimes> \\<Psi>', \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> P) \\<parallel> \\<lparr>\\<nu>y\\<rparr>(p \\<bullet> [(x, y)] \\<bullet> Q)), \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>(\\<lparr>\\<nu>y\\<rparr>((p \\<bullet> P) \\<parallel> (p \\<bullet> [(x, y)] \\<bullet> Q)))) \\<in> ?X2\"\n\t  by auto\n\tmoreover from Teq `(p \\<bullet> xvec) \\<sharp>* P` `(p \\<bullet> xvec) \\<sharp>* Q` `y \\<sharp> xvec` `y \\<sharp> (p \\<bullet> xvec)` `x \\<sharp> (p \\<bullet> xvec)` `y \\<sharp> P` `y \\<sharp> Q` `x \\<sharp> P` S\n\thave \"T = \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>(\\<lparr>\\<nu>y\\<rparr>((p \\<bullet> P) \\<parallel> (p \\<bullet> [(x, y)] \\<bullet> Q)))\"\n\t  apply(erule_tac rev_mp)\n\t  apply(subst alpha_res[of y])\n\t  apply(clarsimp simp add: eqvts)\n\t  apply(subst res_chain_alpha[of p])\n\t  by(auto simp add: eqvts)\n\tmoreover from Req `(p \\<bullet> xvec) \\<sharp>* P` `(p \\<bullet> xvec) \\<sharp>* Q` `y \\<sharp> xvec` `y \\<sharp> (p \\<bullet> xvec)` `x \\<sharp> (p \\<bullet> xvec)` `y \\<sharp> P` `y \\<sharp> Q` `x \\<sharp> P` S\n\thave \"R = \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> P) \\<parallel> \\<lparr>\\<nu>y\\<rparr>(p \\<bullet> [(x, y)] \\<bullet> Q))\"\n\t  apply(erule_tac rev_mp)\n\t  apply(subst alpha_res[of y])\n\t  apply(clarsimp simp add: eqvts)\n\t  apply(subst res_chain_alpha[of p])\n\t  by(auto simp add: eqvts)\n\tultimately show ?case\n\t  by blast\n      qed\n    next\n      case(c_sym \\<Psi> P Q)\n      thus ?case\n\tby(blast dest: bisimE)\n    qed\n  }\n  moreover obtain y::name where \"y \\<sharp> \\<Psi>\" and \"y \\<sharp> P\" \"y \\<sharp> Q\"\n    by(generate_fresh \"name\") auto\n  ultimately have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>y\\<rparr>(P \\<parallel> ([(x, y)] \\<bullet> Q)) \\<sim> P \\<parallel> \\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> Q)\" by auto\n  thus ?thesis using assms `y \\<sharp> P` `y \\<sharp> Q`\n    apply(subst alpha_res[where x=x and y=y and P=Q], auto)\n    by(subst alpha_res[where x=x and y=y and P=\"P \\<parallel> Q\"]) auto\nqed\n\nlemma bisim_scope_ext_chain:\n  fixes xvec :: \"name list\"\n  and   \\<Psi>    :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes \"xvec \\<sharp>* \\<Psi>\"\n  and     \"xvec \\<sharp>* P\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q) \\<sim> P \\<parallel> (\\<lparr>\\<nu>*xvec\\<rparr>Q)\"\nusing assms\nby(induct xvec) (auto intro: bisim_scope_ext bisim_reflexive bisim_transitive bisim_res_pres) \n\n(* only used for bisim up-to\nlemma par_assoc_right:\n  fixes \\<Psi>   :: 'b\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   Q   :: \"('a, 'b, 'c) psi\"\n  and   R   :: \"('a, 'b, 'c) psi\"\n  and   Rel :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n\n  assumes \"eqvt Rel\"\n  and     C1: \"\\<And>\\<Psi>' S T U. (\\<Psi>, S \\<parallel> (T \\<parallel> U),(S \\<parallel> T) \\<parallel> U) \\<in> Rel\"\n  and     C2: \"\\<And>xvec \\<Psi>' S T U. \\<lbrakk>xvec \\<sharp>* \\<Psi>'; xvec \\<sharp>* S\\<rbrakk> \\<Longrightarrow> (\\<Psi>', S \\<parallel> (\\<lparr>\\<nu>*xvec\\<rparr>(T \\<parallel> U)), \\<lparr>\\<nu>*xvec\\<rparr>((S \\<parallel> T) \\<parallel> U)) \\<in> Rel\"\n  and     C3: \"\\<And>xvec \\<Psi>' S T U. \\<lbrakk>xvec \\<sharp>* \\<Psi>'; xvec \\<sharp>* U\\<rbrakk> \\<Longrightarrow> (\\<Psi>', \\<lparr>\\<nu>*xvec\\<rparr>(S \\<parallel> (T \\<parallel> U)), (\\<lparr>\\<nu>*xvec\\<rparr>(S \\<parallel> T)) \\<parallel> U) \\<in> Rel\"\n  and     C4: \"\\<And>\\<Psi>' S T xvec. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel; xvec \\<sharp>* \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', \\<lparr>\\<nu>*xvec\\<rparr>S, \\<lparr>\\<nu>*xvec\\<rparr>T) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> P \\<parallel> (Q \\<parallel> R) \\<leadsto>[Rel] (P \\<parallel> Q) \\<parallel> R\"\nusing `eqvt Rel`\nproof(induct rule: simI[of _ _ _ _ \"()\"])\n  case(c_sim \\<alpha> PQR) \n  from `bn \\<alpha> \\<sharp>* (P \\<parallel> Q \\<parallel> R)` have \"bn \\<alpha> \\<sharp>* P\" and \"bn \\<alpha> \\<sharp>* Q\" and \"bn \\<alpha> \\<sharp>* R\" by simp+\n  hence \"bn \\<alpha> \\<sharp>* (P \\<parallel> Q)\" by simp\n  from `\\<Psi> \\<rhd> (P \\<parallel> Q) \\<parallel> R \\<longmapsto>\\<alpha> \\<prec> PQR` `bn \\<alpha> \\<sharp>* \\<Psi>` `bn \\<alpha> \\<sharp>* (P \\<parallel> Q)` `bn \\<alpha> \\<sharp>* R`\n  show ?case using `bn \\<alpha> \\<sharp>* subject \\<alpha>`    \n  proof(induct rule: par_cases[where C = \"(\\<Psi>, P, Q, R, \\<alpha>)\"])\n    case(c_par2 R' A\\<^sub>P\\<^sub>Q \\<Psi>\\<^sub>P\\<^sub>Q)\n    from `A\\<^sub>P\\<^sub>Q \\<sharp>* (\\<Psi>, P, Q, R, \\<alpha>)` have \"A\\<^sub>P\\<^sub>Q \\<sharp>* Q\" and  \"A\\<^sub>P\\<^sub>Q \\<sharp>* R\" \"A\\<^sub>P\\<^sub>Q \\<sharp>* P\"\n      by simp+\n    with `extract_frame(P \\<parallel> Q) = \\<langle>A\\<^sub>P\\<^sub>Q, \\<Psi>\\<^sub>P\\<^sub>Q\\<rangle>` `distinct A\\<^sub>P\\<^sub>Q`\n    obtain A\\<^sub>Q \\<Psi>\\<^sub>Q A\\<^sub>P \\<Psi>\\<^sub>P where \"A\\<^sub>P\\<^sub>Q = A\\<^sub>P@A\\<^sub>Q\" and \"\\<Psi>\\<^sub>P\\<^sub>Q = \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q\" and FrQ: \"extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" and  FrP: \"extract_frame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\"\n                           and \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q\"\n      by(rule_tac merge_frameE) (auto dest: extract_frame_fresh_chain)\n    from `A\\<^sub>P\\<^sub>Q = A\\<^sub>P@A\\<^sub>Q` `A\\<^sub>P\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>P\\<^sub>Q \\<sharp>* P` `A\\<^sub>P\\<^sub>Q \\<sharp>* Q` `A\\<^sub>P\\<^sub>Q \\<sharp>* R` `A\\<^sub>P\\<^sub>Q \\<sharp>* \\<alpha>`\n    have \"A\\<^sub>Q \\<sharp>* \\<Psi>\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\" and \"A\\<^sub>Q \\<sharp>* P\" and \"A\\<^sub>P \\<sharp>* P\" and \"A\\<^sub>Q \\<sharp>* Q\" and \"A\\<^sub>P \\<sharp>* Q\" and \"A\\<^sub>Q \\<sharp>* \\<alpha>\" and \"A\\<^sub>P \\<sharp>* \\<alpha>\" and \"A\\<^sub>P \\<sharp>* R\" and \"A\\<^sub>Q \\<sharp>* R\"\n      by simp+\n    from `\\<Psi> \\<otimes> \\<Psi>\\<^sub>P\\<^sub>Q \\<rhd> R \\<longmapsto>\\<alpha> \\<prec> R'` `\\<Psi>\\<^sub>P\\<^sub>Q = \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q` have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>\\<alpha> \\<prec> R'\"\n      by(metis stat_eq_transition Associativity Commutativity Composition)\n    hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<parallel> R \\<longmapsto>\\<alpha> \\<prec> (Q \\<parallel> R')\" using FrQ `bn \\<alpha> \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P` `A\\<^sub>Q \\<sharp>* R` `A\\<^sub>Q \\<sharp>* \\<alpha>`\n      by(rule_tac Par2) auto\n    hence \"\\<Psi> \\<rhd> P \\<parallel> (Q \\<parallel> R) \\<longmapsto>\\<alpha> \\<prec> P \\<parallel> (Q \\<parallel> R')\" using FrP `bn \\<alpha> \\<sharp>* P` `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* R` `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>P \\<sharp>* \\<alpha>`\n      by(rule_tac Par2) auto\n    moreover have \"(\\<Psi>, P \\<parallel> (Q \\<parallel> R'),(P \\<parallel> Q) \\<parallel> R') \\<in> Rel\" by(rule C1)\n    ultimately show ?case by blast\n  next\n    case(c_par1 PQ A\\<^sub>R \\<Psi>\\<^sub>R)\n    from `A\\<^sub>R \\<sharp>* (\\<Psi>, P, Q, R, \\<alpha>)` have \"A\\<^sub>R \\<sharp>* Q\" and \"A\\<^sub>R \\<sharp>* R\" and \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* \\<alpha>\"\n      by simp+\n    have FrR: \"extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by fact\n    with `bn \\<alpha> \\<sharp>* R` `A\\<^sub>R \\<sharp>* \\<alpha>` have \"bn \\<alpha> \\<sharp>* \\<Psi>\\<^sub>R\" by(auto dest: extract_frame_fresh_chain)\n    with `bn \\<alpha> \\<sharp>* \\<Psi>` have \"bn \\<alpha> \\<sharp>* (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R)\" by force\n    with `\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<parallel> Q \\<longmapsto>\\<alpha> \\<prec> PQ`\n    show ?case using `bn \\<alpha> \\<sharp>* P` `bn \\<alpha> \\<sharp>* Q` `bn \\<alpha> \\<sharp>* subject \\<alpha>` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* Q`\n    proof(induct rule: par_cases_subject[where C = \"(A\\<^sub>R, \\<Psi>\\<^sub>R, P, Q, R, \\<Psi>)\"])\n      case(c_par1 P' A\\<^sub>Q \\<Psi>\\<^sub>Q)\n      from `A\\<^sub>Q \\<sharp>* (A\\<^sub>R, \\<Psi>\\<^sub>R, P, Q, R, \\<Psi>)` have \"A\\<^sub>Q \\<sharp>* A\\<^sub>R\" and \"A\\<^sub>Q \\<sharp>* P\" and \"A\\<^sub>Q \\<sharp>* R\" and \"A\\<^sub>Q \\<sharp>* Q\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\"\n\tby simp+\n      from `A\\<^sub>R \\<sharp>* Q` `extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>` `A\\<^sub>Q \\<sharp>* A\\<^sub>R` have \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q\"\n        by(drule_tac extract_frame_fresh_chain) auto\n      from `(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<longmapsto>\\<alpha> \\<prec> P'` have \"\\<Psi> \\<otimes> (\\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R) \\<rhd> P \\<longmapsto>\\<alpha> \\<prec> P'\" \n\tby(metis stat_eq_transition Associativity Commutativity Composition)\n      hence \"\\<Psi> \\<rhd> P \\<parallel> (Q \\<parallel> R) \\<longmapsto>\\<alpha> \\<prec> P' \\<parallel> (Q \\<parallel> R)\"\n        using `extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>` `extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>` `A\\<^sub>Q \\<sharp>* A\\<^sub>R` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q` `bn \\<alpha> \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>Q \\<sharp>* P` `A\\<^sub>Q \\<sharp>* \\<alpha>` `bn \\<alpha> \\<sharp>* R` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* Q` `A\\<^sub>R \\<sharp>* \\<alpha>`\n        by(rule_tac Par1[where A\\<^sub>Q=\"A\\<^sub>Q@A\\<^sub>R\"]) auto\n      moreover have \"(\\<Psi>, P' \\<parallel> (Q \\<parallel> R),(P' \\<parallel> Q) \\<parallel> R) \\<in> Rel\" by(rule C1)\n      ultimately show ?case by blast\n    next\n      case(c_par2 Q' A\\<^sub>P \\<Psi>\\<^sub>P)\n      from `A\\<^sub>P \\<sharp>* (A\\<^sub>R, \\<Psi>\\<^sub>R, P, Q, R, \\<Psi>)` have \"A\\<^sub>P \\<sharp>* A\\<^sub>R\" and \"A\\<^sub>P \\<sharp>* R\" and \"A\\<^sub>P \\<sharp>* P\"  and \"A\\<^sub>P \\<sharp>* Q\"  and \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\"\n\tby simp+\n      have FrP: \"extract_frame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" by fact\n      from `A\\<^sub>R \\<sharp>* P` FrP `A\\<^sub>P \\<sharp>* A\\<^sub>R` have \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P\"\n\tby(drule_tac extract_frame_fresh_chain) auto\n      from `(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<longmapsto>\\<alpha> \\<prec> Q'`\n      have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>\\<alpha> \\<prec> Q'\"\n        by(rule stat_eq_transition) (rule associativity_sym)\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<parallel> R \\<longmapsto>\\<alpha> \\<prec> Q' \\<parallel> R\"\n        using `extract_frame R = \\<langle>A\\<^sub>R,\\<Psi>\\<^sub>R\\<rangle>` `bn \\<alpha> \\<sharp>* R` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P` `A\\<^sub>R \\<sharp>* Q` `A\\<^sub>R \\<sharp>* \\<alpha>`\n\tby(rule_tac Par1) auto\n      hence \"\\<Psi> \\<rhd> P \\<parallel> (Q \\<parallel> R) \\<longmapsto>\\<alpha> \\<prec> P \\<parallel> (Q' \\<parallel> R)\"\n        using `extract_frame P = \\<langle>A\\<^sub>P,\\<Psi>\\<^sub>P\\<rangle>` `bn \\<alpha> \\<sharp>* P` `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>P \\<sharp>* R` `A\\<^sub>P \\<sharp>* \\<alpha>`\n        by(rule_tac Par2) auto\n      moreover have \"(\\<Psi>, P \\<parallel> (Q' \\<parallel> R),(P \\<parallel> Q') \\<parallel> R) \\<in> Rel\" by(rule C1)\n      ultimately show ?case by blast\n    next\n      case(c_comm1 \\<Psi>\\<^sub>Q M N Q' A\\<^sub>P \\<Psi>\\<^sub>P K xvec R' A\\<^sub>Q) \n      from `A\\<^sub>Q \\<sharp>* (A\\<^sub>P, \\<Psi>\\<^sub>P, P, Q, R, \\<Psi>)`\n      have \"A\\<^sub>Q \\<sharp>* P\" and \"A\\<^sub>Q \\<sharp>* Q\" and \"A\\<^sub>Q \\<sharp>* R\" and \"A\\<^sub>Q \\<sharp>* A\\<^sub>P\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P\"  and \"A\\<^sub>Q \\<sharp>* \\<Psi>\" by simp+\n      from `A\\<^sub>R \\<sharp>* (A\\<^sub>P, \\<Psi>\\<^sub>P, P, Q, R, \\<Psi>)` have \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* Q\" and \"A\\<^sub>R \\<sharp>* R\" and \"A\\<^sub>R \\<sharp>* A\\<^sub>P\"  and \"A\\<^sub>R \\<sharp>* \\<Psi>\" by simp+\n      from `xvec \\<sharp>* (A\\<^sub>P,  \\<Psi>\\<^sub>P, P, Q, R, \\<Psi>)` have \"xvec \\<sharp>* A\\<^sub>P\" and \"xvec \\<sharp>* P\" and \"xvec \\<sharp>* Q\" and \"xvec \\<sharp>* \\<Psi>\" by simp+\n\n      have FrQ: \"extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" by fact\n      with `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* A\\<^sub>P` have \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q\"\n\tby(drule_tac extract_frame_fresh_chain) auto\n      have FrR: \"extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by fact\n      with `A\\<^sub>P \\<sharp>* R` `A\\<^sub>R \\<sharp>* A\\<^sub>P` have \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R\"\n\tby(drule_tac extract_frame_fresh_chain) auto\n      from `(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> R'` `A\\<^sub>P \\<sharp>* R` `xvec \\<sharp>* A\\<^sub>P` `xvec \\<sharp>* K` `distinct xvec` have \"A\\<^sub>P \\<sharp>* N\" \n\tby(rule_tac output_fresh_chain_derivative) auto\n\n      from `(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> Q'` have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> Q'\"\n\tby(metis stat_eq_transition Associativity Commutativity Composition)\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<parallel> Q \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> (P \\<parallel> Q')\" using FrP `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>P \\<sharp>* M` `A\\<^sub>P \\<sharp>* N`\n\tby(rule_tac Par2) auto\n      moreover from FrP FrQ `A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>Q \\<sharp>* A\\<^sub>P` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P` have \"extract_frame(P \\<parallel> Q) = \\<langle>(A\\<^sub>P@A\\<^sub>Q), \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q\\<rangle>\"\n\tby simp\n      moreover from  `(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> R'` have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> R'\"\n\tby(metis stat_eq_transition Associativity)\n      moreover note `extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>`\n      moreover from `(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> M \\<leftrightarrow> K` have \"\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> M \\<leftrightarrow> K\"\n\tby(metis stat_eq_ent Associativity Commutativity Composition)\n      ultimately have \"\\<Psi> \\<rhd> (P \\<parallel> Q) \\<parallel> R \\<longmapsto>\\<tau> \\<prec> \\<lparr>\\<nu>*xvec\\<rparr>((P \\<parallel> Q') \\<parallel> R')\"\n\tusing `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* P` `A\\<^sub>Q \\<sharp>* P` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* Q` `A\\<^sub>R \\<sharp>* Q` `A\\<^sub>P \\<sharp>* R` `A\\<^sub>Q \\<sharp>* R` `A\\<^sub>R \\<sharp>* R`\n              `A\\<^sub>P \\<sharp>* M` `A\\<^sub>Q \\<sharp>* M` `A\\<^sub>R \\<sharp>* K` `A\\<^sub>R \\<sharp>* A\\<^sub>P` `A\\<^sub>Q \\<sharp>* A\\<^sub>R` `xvec \\<sharp>* P` `xvec \\<sharp>* Q`\n\tby(rule_tac Comm1) (assumption | simp)+\n      moreover from `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* P` have \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>((P \\<parallel> Q') \\<parallel> R'), P \\<parallel> (\\<lparr>\\<nu>*xvec\\<rparr>(Q' \\<parallel> R'))) \\<in> Rel\"\n\tby(rule C2)\n      ultimately show ?case by blast\n    next\n      case(c_comm2 \\<Psi>\\<^sub>R M xvec N Q' A\\<^sub>Q \\<Psi>\\<^sub>Q K R' A\\<^sub>R) \n      from `A\\<^sub>Q \\<sharp>* (A\\<^sub>P,  \\<Psi>\\<^sub>P, P, Q, R, \\<Psi>)`\n      have \"A\\<^sub>Q \\<sharp>* P\" and \"A\\<^sub>Q \\<sharp>* Q\" and \"A\\<^sub>Q \\<sharp>* R\" and \"A\\<^sub>Q \\<sharp>* A\\<^sub>P\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P\" by simp+\n      from `A\\<^sub>R \\<sharp>* (A\\<^sub>P,  \\<Psi>\\<^sub>P, P, Q, R, \\<Psi>)` have \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* Q\" and \"A\\<^sub>R \\<sharp>* R\" and \"A\\<^sub>R \\<sharp>* A\\<^sub>P\"and \"A\\<^sub>R \\<sharp>* \\<Psi>\" by simp+\n      from `xvec \\<sharp>* (A\\<^sub>P,  \\<Psi>\\<^sub>P, P, Q, R, \\<Psi>)` have \"xvec \\<sharp>* A\\<^sub>P\" and \"xvec \\<sharp>* P\" and \"xvec \\<sharp>* Q\" and \"xvec \\<sharp>* \\<Psi>\" by simp+\n\n      have FrQ: \"extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" by fact\n      with `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* A\\<^sub>P` have \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q\"\n\tby(drule_tac extract_frame_fresh_chain) auto\n      have FrR: \"extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by fact\n      with `A\\<^sub>P \\<sharp>* R` `A\\<^sub>R \\<sharp>* A\\<^sub>P` have \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R\"\n\tby(drule_tac extract_frame_fresh_chain) auto\n\n      from `(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'` `A\\<^sub>P \\<sharp>* Q` `xvec \\<sharp>* A\\<^sub>P` `xvec \\<sharp>* M` `distinct xvec` have \"A\\<^sub>P \\<sharp>* N\" \n\tby(rule_tac output_fresh_chain_derivative) auto\n\n      from `(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'` have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'\"\n\tby(metis stat_eq_transition Associativity Commutativity Composition)\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<parallel> Q \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> (P \\<parallel> Q')\" using FrP `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>P \\<sharp>* M` `A\\<^sub>P \\<sharp>* N` `xvec \\<sharp>* P` `xvec \\<sharp>* A\\<^sub>P`\n\tby(rule_tac Par2) auto\n      moreover from FrP FrQ `A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>Q \\<sharp>* A\\<^sub>P` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P` have \"extract_frame(P \\<parallel> Q) = \\<langle>(A\\<^sub>P@A\\<^sub>Q), \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q\\<rangle>\"\n\tby simp+\n      moreover from  `(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>K\\<lparr>N\\<rparr> \\<prec> R'` have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>K\\<lparr>N\\<rparr> \\<prec> R'\"\n\tby(metis stat_eq_transition Associativity)\n      moreover note `extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>`\n      moreover from `(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> K \\<leftrightarrow> M` have \"\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> K \\<leftrightarrow> M\"\n\tby(metis stat_eq_ent Associativity Commutativity Composition)\n      ultimately have \"\\<Psi> \\<rhd> (P \\<parallel> Q) \\<parallel> R \\<longmapsto>\\<tau> \\<prec> \\<lparr>\\<nu>*xvec\\<rparr>((P \\<parallel> Q') \\<parallel> R')\"\n\tusing `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* P` `A\\<^sub>Q \\<sharp>* P` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* Q` `A\\<^sub>R \\<sharp>* Q` `A\\<^sub>P \\<sharp>* R` `A\\<^sub>Q \\<sharp>* R` `A\\<^sub>R \\<sharp>* R`\n              `A\\<^sub>P \\<sharp>* M` `A\\<^sub>Q \\<sharp>* M` `A\\<^sub>R \\<sharp>* K` `A\\<^sub>R \\<sharp>* A\\<^sub>P` `A\\<^sub>Q \\<sharp>* A\\<^sub>R` `xvec \\<sharp>* R`\n\tby(rule_tac Comm2) (assumption | simp)+\n      moreover from `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* P` have \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>((P \\<parallel> Q') \\<parallel> R'), P \\<parallel> (\\<lparr>\\<nu>*xvec\\<rparr>(Q' \\<parallel> R'))) \\<in> Rel\"\n\tby(rule C2)\n      ultimately show ?case by blast\n    qed\n  next\n    case(c_comm1 \\<Psi>\\<^sub>Q\\<^sub>R M N P' A\\<^sub>P \\<Psi>\\<^sub>P K xvec QR' A\\<^sub>Q\\<^sub>R)\n    from `xvec \\<sharp>* (\\<Psi>, P, Q, R, \\<alpha>)` have \"xvec \\<sharp>* Q\" and \"xvec \\<sharp>* R\" by simp+\n    from `A\\<^sub>Q\\<^sub>R \\<sharp>* (\\<Psi>, P, Q, R, \\<alpha>)` have \"A\\<^sub>Q\\<^sub>R \\<sharp>* Q\" and \"A\\<^sub>Q\\<^sub>R \\<sharp>* R\" and \"A\\<^sub>Q\\<^sub>R \\<sharp>* \\<Psi>\" by simp+\n    from `A\\<^sub>P \\<sharp>* (Q \\<parallel> R)` have \"A\\<^sub>P \\<sharp>* Q\" and \"A\\<^sub>P \\<sharp>* R\" by simp+\n    have P_trans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q\\<^sub>R \\<rhd> P \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> P'\" and FrP: \"extract_frame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" and MeqK: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q\\<^sub>R \\<turnstile> M \\<leftrightarrow> K\" by fact+\n    note `\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<parallel> R \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> QR'`  \n    moreover from `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* \\<Psi>\\<^sub>P` have \"xvec \\<sharp>* (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P)\" by force\n    moreover note `xvec \\<sharp>* Q``xvec \\<sharp>* R` `xvec \\<sharp>* K`\n         `extract_frame(Q \\<parallel> R) = \\<langle>A\\<^sub>Q\\<^sub>R, \\<Psi>\\<^sub>Q\\<^sub>R\\<rangle>` `distinct A\\<^sub>Q\\<^sub>R` \n    moreover from `A\\<^sub>Q\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>Q\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P` have \"A\\<^sub>Q\\<^sub>R \\<sharp>* (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P)\" by force\n    ultimately show ?case using `A\\<^sub>Q\\<^sub>R \\<sharp>* Q` `A\\<^sub>Q\\<^sub>R \\<sharp>* R` `A\\<^sub>Q\\<^sub>R \\<sharp>* K`\n    proof(induct rule: par_cases_output_frame)\n      case(c_par1 Q' A\\<^sub>Q \\<Psi>\\<^sub>Q A\\<^sub>R \\<Psi>\\<^sub>R)\n      have Aeq: \"A\\<^sub>Q\\<^sub>R = A\\<^sub>Q@A\\<^sub>R\" and \\<Psi>eq: \"\\<Psi>\\<^sub>Q\\<^sub>R = \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R\" by fact+\n      from P_trans \\<Psi>eq have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> P'\"\n\tby(metis stat_eq_transition Associativity Commutativity Composition)\n      moreover note FrP\n      moreover from `(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'` have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'\"\n\tby(metis stat_eq_transition Associativity Commutativity Composition)\n      moreover note `extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>`\n      moreover from MeqK \\<Psi>eq have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M \\<leftrightarrow> K\"\n\tby(metis stat_eq_ent Associativity Commutativity Composition)\n      moreover from `A\\<^sub>P \\<sharp>* R` `A\\<^sub>P \\<sharp>* A\\<^sub>Q\\<^sub>R` Aeq `extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>` have \"A\\<^sub>P \\<sharp>* A\\<^sub>Q\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R\"\n\tby(auto dest:  extract_frame_fresh_chain)\n      moreover from `A\\<^sub>Q\\<^sub>R \\<sharp>* P` `A\\<^sub>Q\\<^sub>R \\<sharp>* \\<Psi>` Aeq have \"A\\<^sub>Q \\<sharp>* P\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\" by simp+\n      ultimately have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<parallel> Q \\<longmapsto>\\<tau> \\<prec> \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> Q')\"\n\tusing `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* P` `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>P \\<sharp>* M` `A\\<^sub>P \\<sharp>* A\\<^sub>Q` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>Q \\<sharp>* P` `A\\<^sub>Q \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* K` `xvec \\<sharp>* P`\n\tby(rule_tac Comm1) (assumption | force)+\n      moreover from `A\\<^sub>Q\\<^sub>R \\<sharp>* \\<Psi>` Aeq have \"A\\<^sub>R \\<sharp>* \\<Psi>\" by simp\n      moreover from `A\\<^sub>Q\\<^sub>R \\<sharp>* P` Aeq have \"A\\<^sub>R \\<sharp>* P\" by simp\n      ultimately have \"\\<Psi> \\<rhd> (P \\<parallel> Q) \\<parallel> R \\<longmapsto>\\<tau> \\<prec> (\\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> Q')) \\<parallel> R\" using `extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>` `A\\<^sub>R \\<sharp>* Q`\n\tby(rule_tac Par1) (assumption | simp)+\n      moreover from `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* R` have \"(\\<Psi>, (\\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> Q')) \\<parallel> R, \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> (Q' \\<parallel> R))) \\<in> Rel\"\n\tby(rule C3)\n      ultimately show ?case by blast\n    next\n      case(c_par2 R' A\\<^sub>Q \\<Psi>\\<^sub>Q A\\<^sub>R \\<Psi>\\<^sub>R)\n      have Aeq: \"A\\<^sub>Q\\<^sub>R = A\\<^sub>Q@A\\<^sub>R\" and \\<Psi>eq: \"\\<Psi>\\<^sub>Q\\<^sub>R = \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R\" by fact+\n      from `A\\<^sub>Q\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>Q\\<^sub>R \\<sharp>* P` `A\\<^sub>Q\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P` `A\\<^sub>P \\<sharp>* A\\<^sub>Q\\<^sub>R` Aeq have \"A\\<^sub>R \\<sharp>* \\<Psi>\" and \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P\" and \"A\\<^sub>P \\<sharp>* A\\<^sub>R\" and \"A\\<^sub>P \\<sharp>* A\\<^sub>Q\" and \"A\\<^sub>R \\<sharp>* P\" by simp+\n      from `A\\<^sub>Q\\<^sub>R \\<sharp>* \\<Psi>` Aeq have \"A\\<^sub>Q \\<sharp>* \\<Psi>\" by simp\n      from `A\\<^sub>Q\\<^sub>R \\<sharp>* P` Aeq have \"A\\<^sub>Q \\<sharp>* P\" by simp\n      from `A\\<^sub>Q\\<^sub>R \\<sharp>* P` `A\\<^sub>P \\<sharp>* A\\<^sub>Q\\<^sub>R` Aeq FrP have \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P\" by(auto dest: extract_frame_fresh_chain)\n      from `A\\<^sub>P \\<sharp>* A\\<^sub>Q\\<^sub>R` `extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>` `extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>` Aeq `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>P \\<sharp>* R` have \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q\" and  \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R\" by(auto dest: extract_frame_fresh_chain)\n      have R_trans: \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> R'\" and FrR: \"extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by fact+\n      then obtain K' where Keq_k': \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> K' \\<leftrightarrow> K\" and \"A\\<^sub>P \\<sharp>* K'\" and \"A\\<^sub>Q \\<sharp>* K'\"\n      using `A\\<^sub>P \\<sharp>* R` `A\\<^sub>Q \\<sharp>* R` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>Q \\<sharp>* A\\<^sub>R` `A\\<^sub>P \\<sharp>* A\\<^sub>R` `A\\<^sub>R \\<sharp>* R` `A\\<^sub>R \\<sharp>* R` `A\\<^sub>R \\<sharp>* K` `distinct A\\<^sub>R` `xvec \\<sharp>* K` `distinct xvec`\n\tby(rule_tac B=\"A\\<^sub>P@A\\<^sub>Q\" in obtain_output_prefix) (assumption | force)+\n      from P_trans \\<Psi>eq have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> P'\"\n\tby(metis stat_eq_transition Associativity Commutativity Composition)\n      moreover then obtain M' where Meq_m': \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>P \\<turnstile> M \\<leftrightarrow> M'\" and \"A\\<^sub>Q \\<sharp>* M'\" and \"A\\<^sub>R \\<sharp>* M'\"\n        using `A\\<^sub>Q \\<sharp>* P` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>P \\<sharp>* A\\<^sub>R` `A\\<^sub>P \\<sharp>* A\\<^sub>Q` `A\\<^sub>P \\<sharp>* P` `A\\<^sub>P \\<sharp>* M` `distinct A\\<^sub>P` `extract_frame P = \\<langle>A\\<^sub>P,\\<Psi>\\<^sub>P\\<rangle>`\n        by(rule_tac B=\"A\\<^sub>Q@A\\<^sub>R\" in obtain_input_prefix) (assumption | force)+\n      note `((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>P \\<turnstile> M \\<leftrightarrow> M'`\n      moreover hence \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> M \\<leftrightarrow> M'\"\n\tby(metis stat_eq_ent Associativity Commutativity Composition)\n      moreover with MeqK Keq_k' \\<Psi>eq have Meq_k': \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>P \\<turnstile> K' \\<leftrightarrow> M'\"\n\tby(metis stat_eq_ent Associativity Commutativity Composition chan_eq_trans)\n      ultimately have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<longmapsto>K'\\<lparr>N\\<rparr> \\<prec> P'\" using FrP `distinct A\\<^sub>P` `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* P` `A\\<^sub>P \\<sharp>* M` `A\\<^sub>P \\<sharp>* K'` `A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R` `(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> P'`\n\tby(rule_tac input_rename_subject) auto\n      moreover from `A\\<^sub>Q\\<^sub>R \\<sharp>* P` `A\\<^sub>Q\\<^sub>R \\<sharp>* N` Aeq have \"A\\<^sub>Q \\<sharp>* P\" and \"A\\<^sub>Q \\<sharp>* N\" by simp+\n      ultimately have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<parallel> Q \\<longmapsto>K'\\<lparr>N\\<rparr> \\<prec> P' \\<parallel> Q\" using `extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>Q \\<sharp>* K'` `A\\<^sub>Q \\<sharp>* \\<Psi>`\n\tby(rule_tac Par1) (assumption | force)+\n      moreover from FrP `extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>` `A\\<^sub>P \\<sharp>* A\\<^sub>Q` `A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P`\n      have \"extract_frame(P \\<parallel> Q) = \\<langle>(A\\<^sub>P@A\\<^sub>Q), \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q\\<rangle>\" by simp+\n      moreover have \"\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q) \\<rhd> R \\<longmapsto>M'\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> R'\"\n      proof -\n        from R_trans have \"\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q) \\<rhd> R \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> R'\" by(metis Associativity stat_eq_transition)\n        moreover from MeqK have \"(\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q)) \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> M \\<leftrightarrow> K\" using \\<Psi>eq\n\t  by(metis stat_eq_ent Associativity Commutativity Composition)\n        moreover from Meq_m' have \"(\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q)) \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> M \\<leftrightarrow> M'\" using \\<Psi>eq\n\t  by(metis stat_eq_ent Associativity Commutativity Composition)\n        moreover note `extract_frame R = \\<langle>A\\<^sub>R,\\<Psi>\\<^sub>R\\<rangle>` `distinct A\\<^sub>R` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>R \\<sharp>* R` `A\\<^sub>R \\<sharp>* K` `A\\<^sub>R \\<sharp>* M'`\n        ultimately show ?thesis\n          by(rule_tac output_rename_subject) auto\n      qed\n      moreover note FrR\n      moreover from Meq_k' have \"\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> K' \\<leftrightarrow> M'\"\n\tby(metis stat_eq_ent Associativity Commutativity Composition)\n      ultimately have \"\\<Psi> \\<rhd> (P \\<parallel> Q) \\<parallel> R \\<longmapsto>\\<tau> \\<prec> \\<lparr>\\<nu>*xvec\\<rparr>((P' \\<parallel> Q) \\<parallel> R')\"\n\tusing `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* P` `A\\<^sub>Q \\<sharp>* P` `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* Q` `A\\<^sub>P \\<sharp>* R` `A\\<^sub>Q \\<sharp>* R` `A\\<^sub>P \\<sharp>* K'` `A\\<^sub>Q \\<sharp>* K'` `A\\<^sub>P \\<sharp>* A\\<^sub>R` `A\\<^sub>Q \\<sharp>* A\\<^sub>R`\n              `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* Q` `A\\<^sub>R \\<sharp>* R` `A\\<^sub>R \\<sharp>* M'` `xvec \\<sharp>* P` `xvec \\<sharp>* Q`\n\tby(rule_tac Comm1) (assumption | simp)+\n      moreover from `xvec \\<sharp>* \\<Psi>` have \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>((P' \\<parallel> Q) \\<parallel> R'), \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> (Q \\<parallel> R'))) \\<in> Rel\"\n\tby(metis C1 C4)\n      ultimately show ?case by blast\n    qed\n  next\n    case(c_comm2 \\<Psi>\\<^sub>Q\\<^sub>R M xvec N P' A\\<^sub>P \\<Psi>\\<^sub>P K QR' A\\<^sub>Q\\<^sub>R)\n    from `A\\<^sub>Q\\<^sub>R \\<sharp>* (\\<Psi>, P, Q, R, \\<alpha>)` have \"A\\<^sub>Q\\<^sub>R \\<sharp>* Q\" and \"A\\<^sub>Q\\<^sub>R \\<sharp>* R\" and \"A\\<^sub>Q\\<^sub>R \\<sharp>* \\<Psi>\" by simp+\n    from `A\\<^sub>P \\<sharp>* (Q \\<parallel> R)` `xvec \\<sharp>* (Q \\<parallel> R)` have \"A\\<^sub>P \\<sharp>* Q\" and \"A\\<^sub>P \\<sharp>* R\" and \"xvec \\<sharp>* Q\" and \"xvec \\<sharp>* R\" by simp+\n    have P_trans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q\\<^sub>R \\<rhd> P \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\" and FrP: \"extract_frame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" and MeqK: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q\\<^sub>R \\<turnstile> K \\<leftrightarrow> M\" by fact+\n    note `\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<parallel> R \\<longmapsto>K\\<lparr>N\\<rparr> \\<prec> QR'` `extract_frame(Q \\<parallel> R) = \\<langle>A\\<^sub>Q\\<^sub>R, \\<Psi>\\<^sub>Q\\<^sub>R\\<rangle>` `distinct A\\<^sub>Q\\<^sub>R` \n    moreover from `A\\<^sub>Q\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>Q\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P` have \"A\\<^sub>Q\\<^sub>R \\<sharp>* (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P)\" by force\n    ultimately show ?case using `A\\<^sub>Q\\<^sub>R \\<sharp>* Q` `A\\<^sub>Q\\<^sub>R \\<sharp>* R` `A\\<^sub>Q\\<^sub>R \\<sharp>* K`\n    proof(induct rule: par_cases_input_frame)\n      case(c_par1 Q' A\\<^sub>Q \\<Psi>\\<^sub>Q A\\<^sub>R \\<Psi>\\<^sub>R)\n      have Aeq: \"A\\<^sub>Q\\<^sub>R = A\\<^sub>Q@A\\<^sub>R\" and \\<Psi>eq: \"\\<Psi>\\<^sub>Q\\<^sub>R = \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R\" by fact+\n      from P_trans \\<Psi>eq have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n\tby(metis stat_eq_transition Associativity Commutativity Composition)\n      moreover note FrP\n      moreover from `(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>K\\<lparr>N\\<rparr> \\<prec> Q'` have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<longmapsto>K\\<lparr>N\\<rparr> \\<prec> Q'\"\n\tby(metis stat_eq_transition Associativity Commutativity Composition)\n      moreover note `extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>`\n      moreover from MeqK \\<Psi>eq have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> K \\<leftrightarrow> M\"\n\tby(metis stat_eq_ent Associativity Commutativity Composition)\n      moreover from `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>P \\<sharp>* R` `A\\<^sub>P \\<sharp>* A\\<^sub>Q\\<^sub>R` Aeq `extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>` `extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>`\n      have \"A\\<^sub>P \\<sharp>* A\\<^sub>Q\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R\" by(auto dest: extract_frame_fresh_chain)\n      moreover from `A\\<^sub>Q\\<^sub>R \\<sharp>* \\<Psi>`  `A\\<^sub>Q\\<^sub>R \\<sharp>* P` Aeq have \"A\\<^sub>Q \\<sharp>* \\<Psi>\" and \"A\\<^sub>Q \\<sharp>* P\" by simp+\n      ultimately have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<parallel> Q \\<longmapsto>\\<tau> \\<prec> \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> Q')\"\n\tusing `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* P` `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>P \\<sharp>* M` `A\\<^sub>P \\<sharp>* A\\<^sub>Q` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>Q \\<sharp>* P` `A\\<^sub>Q \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* K` `xvec \\<sharp>* Q`\n\tby(rule_tac Comm2) (assumption | force)+\n      moreover from `A\\<^sub>Q\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>Q\\<^sub>R \\<sharp>* P` Aeq have \"A\\<^sub>R \\<sharp>* \\<Psi>\" and \"A\\<^sub>R \\<sharp>* P\" by simp+\n      ultimately have \"\\<Psi> \\<rhd> (P \\<parallel> Q) \\<parallel> R \\<longmapsto>\\<tau> \\<prec> (\\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> Q')) \\<parallel> R\" using `extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>` `A\\<^sub>R \\<sharp>* Q`\n\tby(rule_tac Par1) (assumption | simp)+\n      moreover from `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* R` have \"(\\<Psi>, (\\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> Q')) \\<parallel> R, \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> (Q' \\<parallel> R))) \\<in> Rel\"\n\tby(rule C3)\n      ultimately show ?case by blast\n    next\n      case(c_par2 R' A\\<^sub>Q \\<Psi>\\<^sub>Q A\\<^sub>R \\<Psi>\\<^sub>R)\n      have Aeq: \"A\\<^sub>Q\\<^sub>R = A\\<^sub>Q@A\\<^sub>R\" and \\<Psi>eq: \"\\<Psi>\\<^sub>Q\\<^sub>R = \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R\" by fact+\n      from `A\\<^sub>Q\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>Q\\<^sub>R \\<sharp>* P` `A\\<^sub>Q\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P` `A\\<^sub>P \\<sharp>* A\\<^sub>Q\\<^sub>R` Aeq \n      have \"A\\<^sub>R \\<sharp>* \\<Psi>\" and \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P\" and \"A\\<^sub>P \\<sharp>* A\\<^sub>R\" and \"A\\<^sub>P \\<sharp>* A\\<^sub>Q\" and \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P\" by simp+\n      have R_trans: \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>K\\<lparr>N\\<rparr> \\<prec> R'\" and FrR: \"extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by fact+\n      then obtain K' where Keq_k': \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> K \\<leftrightarrow> K'\" and \"A\\<^sub>P \\<sharp>* K'\" and \"A\\<^sub>Q \\<sharp>* K'\"\n      using `A\\<^sub>P \\<sharp>* R` `A\\<^sub>Q \\<sharp>* R` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>Q \\<sharp>* A\\<^sub>R` `A\\<^sub>P \\<sharp>* A\\<^sub>R` `A\\<^sub>R \\<sharp>* R` `A\\<^sub>R \\<sharp>* R` `A\\<^sub>R \\<sharp>* K` `distinct A\\<^sub>R`\n\tby(rule_tac B=\"A\\<^sub>P@A\\<^sub>Q\" in obtain_input_prefix) (assumption | force)+\n      from P_trans \\<Psi>eq have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n\tby(metis stat_eq_transition Associativity Commutativity Composition)\n      moreover from MeqK Keq_k' \\<Psi>eq have Meq_k': \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>P \\<turnstile> K \\<leftrightarrow> K'\" and Meq_k: \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>P \\<turnstile> K \\<leftrightarrow> M\"\n\tby(metis stat_eq_ent Associativity Commutativity Composition)+\n      moreover from `A\\<^sub>P \\<sharp>* R` `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>P \\<sharp>* A\\<^sub>Q\\<^sub>R` FrR `extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>` Aeq have \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R\"\n\tby(auto dest: extract_frame_fresh_chain)\n      ultimately have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<longmapsto>K'\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\" using FrP `distinct A\\<^sub>P` `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* P` `A\\<^sub>P \\<sharp>* M` `A\\<^sub>P \\<sharp>* K'`\n\tby(rule_tac output_rename_subject) auto\n      moreover from `A\\<^sub>Q\\<^sub>R \\<sharp>* P` `A\\<^sub>Q\\<^sub>R \\<sharp>* N` `A\\<^sub>Q\\<^sub>R \\<sharp>* xvec` Aeq have \"A\\<^sub>Q \\<sharp>* P\" and \"A\\<^sub>Q \\<sharp>* N\" and \"A\\<^sub>Q \\<sharp>* xvec\" by simp+\n      ultimately have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<parallel> Q \\<longmapsto>K'\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> (P' \\<parallel> Q)\" using `extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>Q \\<sharp>* K'` `xvec \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* \\<Psi>`\n\tby(rule_tac Par1) (assumption | force)+\n      moreover from FrP `extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>` `A\\<^sub>P \\<sharp>* A\\<^sub>Q` `A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P`\n      have \"extract_frame(P \\<parallel> Q) = \\<langle>(A\\<^sub>P@A\\<^sub>Q), \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q\\<rangle>\" by simp+\n      moreover from R_trans have \"\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q) \\<rhd> R \\<longmapsto>K\\<lparr>N\\<rparr> \\<prec> R'\" by(metis Associativity stat_eq_transition)\n      moreover note FrR\n      moreover from Keq_k' have \"\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> K \\<leftrightarrow> K'\"\n\tby(metis stat_eq_ent Associativity Commutativity Composition chan_eq_trans)\n      ultimately have \"\\<Psi> \\<rhd> (P \\<parallel> Q) \\<parallel> R \\<longmapsto>\\<tau> \\<prec> \\<lparr>\\<nu>*xvec\\<rparr>((P' \\<parallel> Q) \\<parallel> R')\"\n\tusing `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* P` `A\\<^sub>Q \\<sharp>* P` `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* Q` `A\\<^sub>P \\<sharp>* R` `A\\<^sub>Q \\<sharp>* R` `A\\<^sub>P \\<sharp>* K'` `A\\<^sub>Q \\<sharp>* K'` `A\\<^sub>P \\<sharp>* A\\<^sub>R` `A\\<^sub>Q \\<sharp>* A\\<^sub>R`\n              `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* Q` `A\\<^sub>R \\<sharp>* R` `A\\<^sub>R \\<sharp>* K` `xvec \\<sharp>* R`\n\tby(rule_tac Comm2) (assumption | simp)+\n      moreover from `xvec \\<sharp>* \\<Psi>` have \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>((P' \\<parallel> Q) \\<parallel> R'), \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> (Q \\<parallel> R'))) \\<in> Rel\"\n\tby(metis C1 C4)\n      ultimately show ?case by blast\n    qed\n  qed\nqed\n*)\nlemma bisim_par_assoc:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   R :: \"('a, 'b, 'c) psi\"\n\n  shows \"\\<Psi> \\<rhd> (P \\<parallel> Q) \\<parallel> R \\<sim> P \\<parallel> (Q \\<parallel> R)\"\nproof -\n  let ?X = \"{(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>((P \\<parallel> Q) \\<parallel> R), \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> (Q \\<parallel> R))) | \\<Psi> xvec P Q R. xvec \\<sharp>* \\<Psi>}\"\n  let ?Y = \"{(\\<Psi>, P, Q) | \\<Psi> P P' Q' Q. \\<Psi> \\<rhd> P \\<sim> P' \\<and> (\\<Psi>, P', Q') \\<in> ?X \\<and> \\<Psi> \\<rhd> Q' \\<sim> Q}\"\n\n  have \"(\\<Psi>, (P \\<parallel> Q) \\<parallel> R, P \\<parallel> (Q \\<parallel> R)) \\<in> ?X\"\n    by(auto, rule_tac x=\"[]\" in exI) auto\n  moreover have \"eqvt ?X\" by(force simp add: eqvt_def simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst] eqvts)\n  ultimately show ?thesis\n  proof(coinduct rule: weak_transitive_coinduct')\n    case(c_stat_eq \\<Psi> PQR PQR')\n    from `(\\<Psi>, PQR, PQR') \\<in> ?X` obtain xvec P Q R where \"xvec \\<sharp>* \\<Psi>\" and \"PQR = \\<lparr>\\<nu>*xvec\\<rparr>((P \\<parallel> Q) \\<parallel> R)\" and \"PQR' = \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> (Q \\<parallel> R))\"\n      by auto\n    moreover obtain A\\<^sub>P \\<Psi>\\<^sub>P where FrP: \"extract_frame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\" and \"A\\<^sub>P \\<sharp>* Q\" and \"A\\<^sub>P \\<sharp>* R\"\n      by(rule_tac C=\"(\\<Psi>, Q, R)\" in fresh_frame) auto\n    moreover obtain A\\<^sub>Q \\<Psi>\\<^sub>Q where FrQ: \"extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\" and \"A\\<^sub>Q \\<sharp>* A\\<^sub>P\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P\" and \"A\\<^sub>Q \\<sharp>* R\"\n      by(rule_tac C=\"(\\<Psi>, A\\<^sub>P, \\<Psi>\\<^sub>P, R)\" in fresh_frame) auto\n    moreover obtain A\\<^sub>R \\<Psi>\\<^sub>R where FrR: \"extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" and \"A\\<^sub>R \\<sharp>* \\<Psi>\" and \"A\\<^sub>R \\<sharp>* A\\<^sub>P\" and \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P\" and \"A\\<^sub>R \\<sharp>* A\\<^sub>Q\" and \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q\"\n      by(rule_tac C=\"(\\<Psi>, A\\<^sub>P, \\<Psi>\\<^sub>P, A\\<^sub>Q, \\<Psi>\\<^sub>Q)\" in fresh_frame) auto\n    moreover from FrQ `A\\<^sub>P \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* A\\<^sub>P` have \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q\"\n      by(drule_tac extract_frame_fresh_chain) auto\n    moreover from FrR `A\\<^sub>P \\<sharp>* R` `A\\<^sub>R \\<sharp>* A\\<^sub>P` have \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R\"\n      by(drule_tac extract_frame_fresh_chain) auto\n    moreover from FrR `A\\<^sub>Q \\<sharp>* R` `A\\<^sub>R \\<sharp>* A\\<^sub>Q` have \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R\"\n      by(drule_tac extract_frame_fresh_chain) auto\n    ultimately show ?case using fresh_comp_chain\n      by auto (metis frame_chain_append composition_sym Associativity frame_nil_stat_eq frame_res_chain_pres)\n  next\n    case(c_sim \\<Psi> T S)\n    from `(\\<Psi>, T, S) \\<in> ?X` obtain xvec P Q R where \"xvec \\<sharp>* \\<Psi>\" and T_eq: \"T = \\<lparr>\\<nu>*xvec\\<rparr>((P \\<parallel> Q) \\<parallel> R)\"\n                                               and S_eq: \"S = \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> (Q \\<parallel> R))\"\n      by auto\n    from `eqvt ?X`have \"eqvt ?Y\" by blast\n    have C1: \"\\<And>\\<Psi> T S yvec. \\<lbrakk>(\\<Psi>, T, S) \\<in> ?Y; yvec \\<sharp>* \\<Psi>\\<rbrakk> \\<Longrightarrow> (\\<Psi>, \\<lparr>\\<nu>*yvec\\<rparr>T, \\<lparr>\\<nu>*yvec\\<rparr>S) \\<in> ?Y\"\n    proof -\n      fix \\<Psi> T S yvec\n      assume \"(\\<Psi>, T, S) \\<in> ?Y\"\n      then obtain T' S' where \"\\<Psi> \\<rhd> T \\<sim> T'\" and \"(\\<Psi>, T', S') \\<in> ?X\" and \"\\<Psi> \\<rhd> S' \\<sim> S\" by force\n      assume \"(yvec::name list) \\<sharp>* \\<Psi>\" \n      from `(\\<Psi>, T', S') \\<in> ?X` obtain xvec P Q R where T'eq: \"T' = \\<lparr>\\<nu>*xvec\\<rparr>((P \\<parallel> Q) \\<parallel> R)\" and S'eq: \"S' = \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> (Q \\<parallel> R))\"\n                                                  and \"xvec \\<sharp>* \\<Psi>\"\n\tby auto\n      from `\\<Psi> \\<rhd> T \\<sim> T'` `yvec \\<sharp>* \\<Psi>` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*yvec\\<rparr>T \\<sim> \\<lparr>\\<nu>*yvec\\<rparr>T'\" by(rule bisim_res_chain_pres)\n      moreover from `xvec \\<sharp>* \\<Psi>` `yvec \\<sharp>* \\<Psi>` have \"(\\<Psi>, \\<lparr>\\<nu>*(yvec@xvec)\\<rparr>((P \\<parallel> Q) \\<parallel> R), \\<lparr>\\<nu>*(yvec@xvec)\\<rparr>(P \\<parallel> (Q \\<parallel> R))) \\<in> ?X\"\n\tby force\n      with T'eq S'eq have \"(\\<Psi>, \\<lparr>\\<nu>*yvec\\<rparr>T', \\<lparr>\\<nu>*yvec\\<rparr>S') \\<in> ?X\" by(simp add: res_chain_append)\n      moreover from `\\<Psi> \\<rhd> S' \\<sim> S` `yvec \\<sharp>* \\<Psi>` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*yvec\\<rparr>S' \\<sim> \\<lparr>\\<nu>*yvec\\<rparr>S\" by(rule bisim_res_chain_pres)\n      ultimately show \"(\\<Psi>, \\<lparr>\\<nu>*yvec\\<rparr>T, \\<lparr>\\<nu>*yvec\\<rparr>S) \\<in> ?Y\" by blast\n    qed\n    have C2: \"\\<And>\\<Psi> T S y. \\<lbrakk>(\\<Psi>, T, S) \\<in> ?Y; y \\<sharp> \\<Psi>\\<rbrakk> \\<Longrightarrow> (\\<Psi>, \\<lparr>\\<nu>y\\<rparr>T, \\<lparr>\\<nu>y\\<rparr>S) \\<in> ?Y\"\n      by(drule_tac yvec2=\"[y]\" in C1) auto\n\n    have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>((P \\<parallel> Q) \\<parallel> R) \\<leadsto>[?Y] \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> (Q \\<parallel> R))\"\n    proof -\n      have \"\\<Psi> \\<rhd> (P \\<parallel> Q) \\<parallel> R \\<leadsto>[?Y] P \\<parallel> (Q \\<parallel> R)\" \n      proof -\n\tnote `eqvt ?Y`\n\tmoreover have \"\\<And>\\<Psi> P Q R. (\\<Psi>, (P \\<parallel> Q) \\<parallel> R, P \\<parallel> (Q \\<parallel> R)) \\<in> ?Y\"\n\tproof -\n\t  fix \\<Psi> P Q R\n\t  have \"(\\<Psi>::'b, ((P::('a, 'b, 'c) psi) \\<parallel> Q) \\<parallel> R, P \\<parallel> (Q \\<parallel> R)) \\<in> ?X\"\n\t    by(auto, rule_tac x=\"[]\" in exI) auto\n\t  thus \"(\\<Psi>, (P \\<parallel> Q) \\<parallel> R, P \\<parallel> (Q \\<parallel> R)) \\<in> ?Y\"\n\t    by(blast intro: bisim_reflexive)\n\tqed\n\tmoreover have \"\\<And>xvec \\<Psi> P Q R. \\<lbrakk>xvec \\<sharp>* \\<Psi>; xvec \\<sharp>* P\\<rbrakk> \\<Longrightarrow> (\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>((P \\<parallel> Q) \\<parallel> R), P \\<parallel> (\\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> R))) \\<in> ?Y\"\n\tproof -\n\t  fix xvec \\<Psi> P Q R\n\t  assume \"(xvec::name list) \\<sharp>* (\\<Psi>::'b)\" and \"xvec \\<sharp>* (P::('a, 'b, 'c) psi)\"\n\t  from `xvec \\<sharp>* \\<Psi>` have \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>((P \\<parallel> Q) \\<parallel> R), \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> (Q \\<parallel> R))) \\<in> ?X\" by blast\n\t  moreover from `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* P` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> (Q \\<parallel> R)) \\<sim> P \\<parallel> (\\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> R))\"\n\t    by(rule bisim_scope_ext_chain)\n\t  ultimately show \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>((P \\<parallel> Q) \\<parallel> R), P \\<parallel> (\\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> R))) \\<in> ?Y\"\n\t    by(blast intro: bisim_reflexive)\n\tqed\n\tmoreover have \"\\<And>xvec \\<Psi> P Q R. \\<lbrakk>xvec \\<sharp>* \\<Psi>; xvec \\<sharp>* R\\<rbrakk> \\<Longrightarrow> (\\<Psi>, (\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q)) \\<parallel> R, \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> (Q \\<parallel> R))) \\<in> ?Y\"\n\tproof -\n\t  fix xvec \\<Psi> P Q R\n\t  assume \"(xvec::name list) \\<sharp>* (\\<Psi>::'b)\" and \"xvec \\<sharp>* (R::('a, 'b, 'c) psi)\"\n\t  have \"\\<Psi> \\<rhd> (\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q)) \\<parallel> R \\<sim> R \\<parallel> (\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q))\" by(rule bisim_par_comm)\n\t  moreover from `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* R` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(R \\<parallel> (P \\<parallel> Q)) \\<sim> R \\<parallel> (\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q))\" by(rule bisim_scope_ext_chain)\n\t  hence \"\\<Psi> \\<rhd> R \\<parallel> (\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q)) \\<sim> \\<lparr>\\<nu>*xvec\\<rparr>(R \\<parallel> (P \\<parallel> Q))\" by(rule bisimE)\n\t  moreover from `xvec \\<sharp>* \\<Psi>` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(R \\<parallel> (P \\<parallel> Q)) \\<sim> \\<lparr>\\<nu>*xvec\\<rparr>((P \\<parallel> Q) \\<parallel> R)\"\n\t    by(metis bisim_res_chain_pres bisim_par_comm)\n\t  moreover from `xvec \\<sharp>* \\<Psi>` have \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>((P \\<parallel> Q) \\<parallel> R), \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> (Q \\<parallel> R))) \\<in> ?X\" by blast\n\t  ultimately show \"(\\<Psi>, (\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q)) \\<parallel> R, \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> (Q \\<parallel> R))) \\<in> ?Y\"  by(blast dest: bisim_transitive intro: bisim_reflexive)\n\tqed\n\tultimately show ?thesis using C1\n\t  by(rule par_assoc_left)\n      qed\n      thus ?thesis using `eqvt ?Y` `xvec \\<sharp>* \\<Psi>` C2\n\tby(rule res_chain_pres)\n    qed\n    with T_eq S_eq show ?case by simp\n  next\n    case(c_ext \\<Psi> T S \\<Psi>')\n    from `(\\<Psi>, T, S) \\<in> ?X` obtain xvec P Q R where \"xvec \\<sharp>* \\<Psi>\" and T_eq: \"T = \\<lparr>\\<nu>*xvec\\<rparr>((P \\<parallel> Q) \\<parallel> R)\"\n                                               and S_eq: \"S = \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> (Q \\<parallel> R))\"\n      by auto\n    obtain p where \"(p \\<bullet> xvec) \\<sharp>* \\<Psi>\" and \"(p \\<bullet> xvec) \\<sharp>* P\" and \"(p \\<bullet> xvec) \\<sharp>* Q\" and \"(p \\<bullet> xvec) \\<sharp>* R\" and \"(p \\<bullet> xvec) \\<sharp>* \\<Psi>'\"\n               and S: \"(set p) \\<subseteq> (set xvec) \\<times> (set(p \\<bullet> xvec))\" and \"distinct_perm p\"\n      by(rule_tac c=\"(\\<Psi>, P, Q, R, \\<Psi>')\" in name_list_avoiding) auto\n\n    from `(p \\<bullet> xvec) \\<sharp>* \\<Psi>` `(p \\<bullet> xvec) \\<sharp>* \\<Psi>'` have \"(\\<Psi> \\<otimes> \\<Psi>', \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>(((p \\<bullet> P) \\<parallel> (p \\<bullet> Q)) \\<parallel> (p \\<bullet> R)), \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> P) \\<parallel> ((p \\<bullet> Q) \\<parallel> (p \\<bullet> R)))) \\<in> ?X\"\n      by auto\n    moreover from T_eq `(p \\<bullet> xvec) \\<sharp>* P` `(p \\<bullet> xvec) \\<sharp>* Q` `(p \\<bullet> xvec) \\<sharp>* R` S have \"T = \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>(((p \\<bullet> P) \\<parallel> (p \\<bullet> Q)) \\<parallel> (p \\<bullet> R))\"\n      apply auto by(subst res_chain_alpha[of p]) auto\n    moreover from S_eq `(p \\<bullet> xvec) \\<sharp>* P` `(p \\<bullet> xvec) \\<sharp>* Q` `(p \\<bullet> xvec) \\<sharp>* R` S have \"S = \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> P) \\<parallel> ((p \\<bullet> Q) \\<parallel> (p \\<bullet> R)))\"\n      apply auto by(subst res_chain_alpha[of p]) auto\n    ultimately show ?case by simp\n  next\n    case(c_sym \\<Psi> T S)\n    from `(\\<Psi>, T, S) \\<in> ?X` obtain xvec P Q R where \"xvec \\<sharp>* \\<Psi>\" and T_eq: \"T = \\<lparr>\\<nu>*xvec\\<rparr>((P \\<parallel> Q) \\<parallel> R)\"\n                                               and S_eq: \"\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> (Q \\<parallel> R)) = S\"\n      by auto\n    \n    from `xvec \\<sharp>* \\<Psi>` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> (Q \\<parallel> R)) \\<sim> \\<lparr>\\<nu>*xvec\\<rparr>((R \\<parallel> Q) \\<parallel> P)\"\n      by(metis bisim_par_comm bisim_par_pres bisim_transitive bisim_res_chain_pres)\n    moreover from `xvec \\<sharp>* \\<Psi>` have \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>((R \\<parallel> Q) \\<parallel> P), \\<lparr>\\<nu>*xvec\\<rparr>(R \\<parallel> (Q \\<parallel> P))) \\<in> ?X\" by blast\n    moreover from `xvec \\<sharp>* \\<Psi>` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(R \\<parallel> (Q \\<parallel> P)) \\<sim> \\<lparr>\\<nu>*xvec\\<rparr>((P \\<parallel> Q) \\<parallel> R)\"\n      by(metis bisim_par_comm bisim_par_pres bisim_transitive bisim_res_chain_pres)\n    ultimately show ?case using T_eq S_eq by(blast dest: bisim_transitive)\n  qed\nqed    \n\nlemma bisim_par_nil:\n  fixes P :: \"('a, 'b, 'c) psi\"\n\n  shows \"\\<Psi> \\<rhd> P \\<parallel> \\<zero> \\<sim> P\"\nproof -\n  let ?X1 = \"{(\\<Psi>, P \\<parallel> \\<zero>, P) | \\<Psi> P. True}\"\n  let ?X2 = \"{(\\<Psi>, P, P \\<parallel> \\<zero>) | \\<Psi> P. True}\"\n  let ?X = \"?X1 \\<union> ?X2\"\n  have \"eqvt ?X\" by(auto simp add: eqvt_def)\n  have \"(\\<Psi>, P \\<parallel> \\<zero>, P) \\<in> ?X\" by simp\n  thus ?thesis\n  proof(coinduct rule: bisim_weak_coinduct)\n    case(c_stat_eq \\<Psi> Q R)\n    show ?case\n    proof(case_tac \"(\\<Psi>, Q, R) \\<in> ?X1\")\n      assume \"(\\<Psi>, Q, R) \\<in> ?X1\"\n      then obtain P where \"Q = P \\<parallel> \\<zero>\" and \"R = P\" by auto\n      moreover obtain A\\<^sub>P \\<Psi>\\<^sub>P where \"extract_frame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\"\n\tby(rule fresh_frame)\n      ultimately show ?case\n\tapply auto by(metis frame_res_chain_pres frame_nil_stat_eq Identity Associativity Assertion_stat_eq_trans Commutativity)\n    next\n      assume \"(\\<Psi>, Q, R) \\<notin> ?X1\"\n      with `(\\<Psi>, Q, R) \\<in> ?X` have \"(\\<Psi>, Q, R) \\<in> ?X2\" by blast\n      then obtain P where \"Q = P\" and \"R = P \\<parallel> \\<zero>\" by auto\n      moreover obtain A\\<^sub>P \\<Psi>\\<^sub>P where \"extract_frame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\"\n\tby(rule fresh_frame)\n      ultimately show ?case\n\tapply auto by(metis frame_res_chain_pres frame_nil_stat_eq Identity Associativity Assertion_stat_eq_trans Assertion_stat_eq_sym Commutativity)\n    qed\n  next\n    case(c_sim \\<Psi> Q R)\n    thus ?case using `eqvt ?X`\n      by(auto intro: par_nil_left par_nil_right)\n  next\n    case(c_ext \\<Psi> Q R \\<Psi>')\n    thus ?case by auto\n  next\n    case(c_sym \\<Psi> Q R)\n    thus ?case by auto\n  qed\nqed\n\nlemma bisim_res_nil:\n  fixes x :: name\n  and   \\<Psi> :: 'b\n  \n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>\\<zero> \\<sim> \\<zero>\"\nproof -\n  {\n    fix x::name\n    assume \"x \\<sharp> \\<Psi>\"\n    have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>\\<zero> \\<sim> \\<zero>\"\n    proof -\n      let ?X1 = \"{(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>\\<zero>, \\<zero>) | \\<Psi> x. x \\<sharp> \\<Psi>}\"\n      let ?X2 = \"{(\\<Psi>, \\<zero>, \\<lparr>\\<nu>x\\<rparr>\\<zero>) | \\<Psi> x. x \\<sharp> \\<Psi>}\"\n      let ?X = \"?X1 \\<union> ?X2\"\n\n      from `x \\<sharp> \\<Psi>` have \"(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>\\<zero>, \\<zero>) \\<in> ?X\" by auto\n      thus ?thesis\n      proof(coinduct rule: bisim_weak_coinduct)\n\tcase(c_stat_eq \\<Psi> P Q)\n\tthus ?case using fresh_comp by(force intro: frame_res_fresh Frame_stat_eq_sym)\n      next\n\tcase(c_sim \\<Psi> P Q)\n\tthus ?case\n\t  by(force intro: res_nil_left res_nil_right)\n      next\n\tcase(c_ext \\<Psi> P Q \\<Psi>')\n\tobtain y where \"y \\<sharp> \\<Psi>\" and \"y \\<sharp> \\<Psi>'\" and \"y \\<noteq> x\"\n\t  by(generate_fresh \"name\") (auto simp add: fresh_prod)\n\tshow ?case\n\tproof(case_tac \"(\\<Psi>, P, Q) \\<in> ?X1\")\n\t  assume \"(\\<Psi>, P, Q) \\<in> ?X1\"\n\t  then obtain x where \"P = \\<lparr>\\<nu>x\\<rparr>\\<zero>\" and \"Q = \\<zero>\" by auto\n\t  moreover have \"\\<lparr>\\<nu>x\\<rparr>\\<zero> = \\<lparr>\\<nu>y\\<rparr> \\<zero>\" by(subst alpha_res) auto\n\t  ultimately show ?case using `y \\<sharp> \\<Psi>` `y \\<sharp> \\<Psi>'` by auto\n\tnext\n\t  assume \"(\\<Psi>, P, Q) \\<notin> ?X1\"\n\t  with `(\\<Psi>, P, Q) \\<in> ?X` have \"(\\<Psi>, P, Q) \\<in> ?X2\" by auto\n\t  then obtain x where \"Q = \\<lparr>\\<nu>x\\<rparr>\\<zero>\" and \"P = \\<zero>\" by auto\n\t  moreover have \"\\<lparr>\\<nu>x\\<rparr>\\<zero> = \\<lparr>\\<nu>y\\<rparr> \\<zero>\" by(subst alpha_res) auto\n\t  ultimately show ?case using `y \\<sharp> \\<Psi>` `y \\<sharp> \\<Psi>'` by auto\n\tqed\n      next\n\tcase(c_sym \\<Psi> P Q)\n\tthus ?case by auto\n      qed\n    qed\n  }\n  moreover obtain y::name where \"y \\<sharp> \\<Psi>\" by(generate_fresh \"name\") auto\n  ultimately have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>y\\<rparr>\\<zero> \\<sim> \\<zero>\" by auto\n  thus ?thesis by(subst alpha_res[where x=x and y=y]) auto\nqed\n\nlemma bisim_output_push_res:\n  fixes x :: name\n  and   \\<Psi> :: 'b\n  and   M :: 'a\n  and   N :: 'a\n  and   P :: \"('a, 'b, 'c) psi\"\n\n  assumes \"x \\<sharp> M\"\n  and     \"x \\<sharp> N\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(M\\<langle>N\\<rangle>.P) \\<sim> M\\<langle>N\\<rangle>.\\<lparr>\\<nu>x\\<rparr>P\"\nproof -\n  {\n    fix x::name and P::\"('a, 'b, 'c) psi\"\n    assume \"x \\<sharp> \\<Psi>\" and \"x \\<sharp> M\" and \"x \\<sharp> N\"\n    let ?X1 = \"{(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>(M\\<langle>N\\<rangle>.P), M\\<langle>N\\<rangle>.\\<lparr>\\<nu>x\\<rparr>P) | \\<Psi> x M N P. x \\<sharp> \\<Psi> \\<and> x \\<sharp> M \\<and> x \\<sharp> N}\"\n    let ?X2 = \"{(\\<Psi>, M\\<langle>N\\<rangle>.\\<lparr>\\<nu>x\\<rparr>P, \\<lparr>\\<nu>x\\<rparr>(M\\<langle>N\\<rangle>.P)) | \\<Psi> x M N P. x \\<sharp> \\<Psi> \\<and> x \\<sharp> M \\<and> x \\<sharp> N}\"\n    let ?X = \"?X1 \\<union> ?X2\"\n  \n    have \"eqvt ?X\" by(rule_tac eqvt_union) (force simp add: eqvt_def pt_fresh_bij[OF pt_name_inst, OF at_name_inst] eqvts)+\n    from `x \\<sharp> \\<Psi>` `x \\<sharp> M` `x \\<sharp> N`  have \"(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>(M\\<langle>N\\<rangle>.P), M\\<langle>N\\<rangle>.\\<lparr>\\<nu>x\\<rparr>P) \\<in> ?X\" by auto\n    hence \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(M\\<langle>N\\<rangle>.P) \\<sim> M\\<langle>N\\<rangle>.\\<lparr>\\<nu>x\\<rparr>P\"\n    proof(coinduct rule: bisim_coinduct)\n      case(c_stat_eq \\<Psi> Q R)\n      thus ?case using fresh_comp by(force intro: frame_res_fresh Frame_stat_eq_sym)\n    next\n      case(c_sim \\<Psi> Q R)\n      thus ?case using `eqvt ?X`\n\tby(force intro: output_push_res_left output_push_res_right bisim_reflexive)\n    next\n      case(c_ext \\<Psi> Q R \\<Psi>')\n      show ?case\n      proof(case_tac \"(\\<Psi>, Q, R) \\<in> ?X1\")\n\tassume \"(\\<Psi>, Q, R) \\<in> ?X1\"\n\tthen obtain x M N P where Qeq: \"Q = \\<lparr>\\<nu>x\\<rparr>(M\\<langle>N\\<rangle>.P)\" and Req: \"R = M\\<langle>N\\<rangle>.\\<lparr>\\<nu>x\\<rparr>P\" and \"x \\<sharp> \\<Psi>\" and \"x \\<sharp> M\" and \"x \\<sharp> N\" by auto\n\tobtain y::name where \"y \\<sharp> \\<Psi>\" and \"y \\<sharp> \\<Psi>'\" and \"y \\<sharp> M\" and \"y \\<sharp> N\" and \"y \\<sharp> P\"\n\t  by(generate_fresh \"name\") (auto simp add: fresh_prod)\n\t\n\tmoreover hence \"(\\<Psi> \\<otimes> \\<Psi>', \\<lparr>\\<nu>y\\<rparr>(M\\<langle>N\\<rangle>.([(x, y)] \\<bullet> P)), M\\<langle>N\\<rangle>.\\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> P)) \\<in> ?X\" by auto\n\tmoreover from Qeq `x \\<sharp> M` `y \\<sharp> M` `x \\<sharp> N` `y \\<sharp> N` `y \\<sharp> P` have \"Q = \\<lparr>\\<nu>y\\<rparr>(M\\<langle>N\\<rangle>.([(x, y)] \\<bullet> P))\"\n\t  apply auto by(subst alpha_res[of y]) (auto simp add: eqvts)\n\tmoreover from Req `y \\<sharp> P` have \"R = M\\<langle>N\\<rangle>.\\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> P)\"\n\t  apply auto by(subst alpha_res[of y]) (auto simp add: eqvts)\n\tultimately show ?case by blast\n      next\n\tassume \"(\\<Psi>, Q, R) \\<notin> ?X1\"\n\twith `(\\<Psi>, Q, R) \\<in> ?X` have \"(\\<Psi>, Q, R) \\<in> ?X2\" by blast\n\tthen obtain x M N P where Req: \"R = \\<lparr>\\<nu>x\\<rparr>(M\\<langle>N\\<rangle>.P)\" and Qeq: \"Q = M\\<langle>N\\<rangle>.\\<lparr>\\<nu>x\\<rparr>P\" and \"x \\<sharp> \\<Psi>\" and \"x \\<sharp> M\" and \"x \\<sharp> N\" by auto\n\tobtain y::name where \"y \\<sharp> \\<Psi>\" and \"y \\<sharp> \\<Psi>'\" and \"y \\<sharp> M\" and \"y \\<sharp> N\" and \"y \\<sharp> P\"\n\t  by(generate_fresh \"name\") (auto simp add: fresh_prod)\n\t\n\tmoreover hence \"(\\<Psi> \\<otimes> \\<Psi>', \\<lparr>\\<nu>y\\<rparr>(M\\<langle>N\\<rangle>.([(x, y)] \\<bullet> P)), M\\<langle>N\\<rangle>.\\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> P)) \\<in> ?X\" by auto\n\tmoreover from Req `x \\<sharp> M` `y \\<sharp> M` `x \\<sharp> N` `y \\<sharp> N` `y \\<sharp> P` have \"R = \\<lparr>\\<nu>y\\<rparr>(M\\<langle>N\\<rangle>.([(x, y)] \\<bullet> P))\"\n\t  apply auto by(subst alpha_res[of y]) (auto simp add: eqvts)\n\tmoreover from Qeq `y \\<sharp> P` have \"Q = M\\<langle>N\\<rangle>.\\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> P)\"\n\t  apply auto by(subst alpha_res[of y]) (auto simp add: eqvts)\n\tultimately show ?case by blast\n      qed\n    next\n      case(c_sym \\<Psi> R Q)\n      thus ?case by blast\n    qed\n  }\n  moreover obtain y::name where \"y \\<sharp> \\<Psi>\" and \"y \\<sharp> M\" and \"y \\<sharp> N\" \"y \\<sharp> P\"\n    by(generate_fresh \"name\") auto\n  ultimately have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>y\\<rparr>(M\\<langle>N\\<rangle>.([(x, y)] \\<bullet> P)) \\<sim> M\\<langle>N\\<rangle>.\\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> P)\" by auto\n  thus ?thesis using assms `y \\<sharp> P` `y \\<sharp> M` `y \\<sharp> N`\n    apply(subst alpha_res[where x=x and y=y and P=P], auto)\n    by(subst alpha_res[where x=x and y=y and P=\"M\\<langle>N\\<rangle>.P\"]) auto\nqed\n\nlemma bisim_input_push_res:\n  fixes x    :: name\n  and   \\<Psi>    :: 'b\n  and   M    :: 'a\n  and   xvec :: \"name list\"\n  and   N    :: 'a\n  and   P    :: \"('a, 'b, 'c) psi\"\n\n  assumes \"x \\<sharp> M\"\n  and     \"x \\<sharp> xvec\"\n  and     \"x \\<sharp> N\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(M\\<lparr>\\<lambda>*xvec N\\<rparr>.P) \\<sim> M\\<lparr>\\<lambda>*xvec N\\<rparr>.\\<lparr>\\<nu>x\\<rparr>P\"\nproof -\n  {\n    fix x::name and P::\"('a, 'b, 'c) psi\"\n    assume \"x \\<sharp> \\<Psi>\" and \"x \\<sharp> M\" and \"x \\<sharp> N\" and \"x \\<sharp> xvec\"\n    let ?X1 = \"{(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>(M\\<lparr>\\<lambda>*xvec N\\<rparr>.P), M\\<lparr>\\<lambda>*xvec N\\<rparr>.\\<lparr>\\<nu>x\\<rparr>P) | \\<Psi> x M xvec N P. x \\<sharp> \\<Psi> \\<and> x \\<sharp> M \\<and> x \\<sharp> xvec \\<and> x \\<sharp> N}\"\n    let ?X2 = \"{(\\<Psi>, M\\<lparr>\\<lambda>*xvec N\\<rparr>.\\<lparr>\\<nu>x\\<rparr>P, \\<lparr>\\<nu>x\\<rparr>(M\\<lparr>\\<lambda>*xvec N\\<rparr>.P)) | \\<Psi> x M xvec N P. x \\<sharp> \\<Psi> \\<and> x \\<sharp> M \\<and> x \\<sharp> xvec \\<and> x \\<sharp> N}\"\n    let ?X = \"?X1 \\<union> ?X2\"\n  \n    have \"eqvt ?X\" by(rule_tac eqvt_union) (force simp add: eqvt_def pt_fresh_bij[OF pt_name_inst, OF at_name_inst] eqvts)+\n\n    from `x \\<sharp> \\<Psi>` `x \\<sharp> M` `x \\<sharp> xvec` `x \\<sharp> N` have \"(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>(M\\<lparr>\\<lambda>*xvec N\\<rparr>.P), M\\<lparr>\\<lambda>*xvec N\\<rparr>.\\<lparr>\\<nu>x\\<rparr>P) \\<in> ?X\" by blast\n    hence \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(M\\<lparr>\\<lambda>*xvec N\\<rparr>.P) \\<sim> M\\<lparr>\\<lambda>*xvec N\\<rparr>.\\<lparr>\\<nu>x\\<rparr>P\"\n    proof(coinduct rule: bisim_coinduct)\n      case(c_stat_eq \\<Psi> Q R)\n      thus ?case using fresh_comp by(force intro: frame_res_fresh Frame_stat_eq_sym)\n    next\n      case(c_sim \\<Psi> Q R)\n      thus ?case using `eqvt ?X`\n        by(auto intro!: input_push_res_left input_push_res_right intro: bisim_reflexive)\n    next\n      case(c_ext \\<Psi> Q R \\<Psi>')\n      show ?case\n      proof(case_tac \"(\\<Psi>, Q, R) \\<in> ?X1\")\n\tassume \"(\\<Psi>, Q, R) \\<in> ?X1\"\n\tthen obtain x M xvec N P where Qeq: \"Q = \\<lparr>\\<nu>x\\<rparr>(M\\<lparr>\\<lambda>*xvec N\\<rparr>.P)\" and Req: \"R = M\\<lparr>\\<lambda>*xvec N\\<rparr>.\\<lparr>\\<nu>x\\<rparr>P\" and \"x \\<sharp> \\<Psi>\"\n                                   and \"x \\<sharp> M\" and \"x \\<sharp> xvec\" and \"x \\<sharp> N\" by auto\n\tobtain y::name where \"y \\<sharp> \\<Psi>\" and \"y \\<sharp> \\<Psi>'\" and \"y \\<sharp> M\" and \"y \\<sharp> N\" and \"y \\<sharp> P\" and \"y \\<sharp> xvec\"\n\t  by(generate_fresh \"name\") (auto simp add: fresh_prod)\n\t\n\tmoreover hence \"(\\<Psi> \\<otimes> \\<Psi>', \\<lparr>\\<nu>y\\<rparr>(M\\<lparr>\\<lambda>*xvec N\\<rparr>.([(x, y)] \\<bullet> P)), M\\<lparr>\\<lambda>*xvec N\\<rparr>.\\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> P)) \\<in> ?X\" by force\n\tmoreover from Qeq `x \\<sharp> M` `y \\<sharp> M` `x \\<sharp> xvec` `y \\<sharp> xvec` `x \\<sharp> N` `y \\<sharp> N` `y \\<sharp> P` have \"Q = \\<lparr>\\<nu>y\\<rparr>(M\\<lparr>\\<lambda>*xvec N\\<rparr>.([(x, y)] \\<bullet> P))\"\n\t  apply auto by(subst alpha_res[of y]) (auto simp add: eqvts input_chain_fresh)\n\tmoreover from Req `y \\<sharp> P` have \"R = M\\<lparr>\\<lambda>*xvec N \\<rparr>.\\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> P)\"\n\t  apply auto by(subst alpha_res[of y]) (auto simp add: eqvts)\n\tultimately show ?case by blast\n      next\n\tassume \"(\\<Psi>, Q, R) \\<notin> ?X1\"\n\twith `(\\<Psi>, Q, R) \\<in> ?X` have \"(\\<Psi>, Q, R) \\<in> ?X2\" by blast\n\tthen obtain x M xvec N P where Req: \"R = \\<lparr>\\<nu>x\\<rparr>(M\\<lparr>\\<lambda>*xvec N\\<rparr>.P)\" and Qeq: \"Q = M\\<lparr>\\<lambda>*xvec N\\<rparr>.\\<lparr>\\<nu>x\\<rparr>P\" and \"x \\<sharp> \\<Psi>\"\n                                   and \"x \\<sharp> M\" and \"x \\<sharp> xvec\" and \"x \\<sharp> N\" by auto\n\tobtain y::name where \"y \\<sharp> \\<Psi>\" and \"y \\<sharp> \\<Psi>'\" and \"y \\<sharp> M\" and \"y \\<sharp> N\" and \"y \\<sharp> P\" and \"y \\<sharp> xvec\"\n\t  by(generate_fresh \"name\") (auto simp add: fresh_prod)\n\n\tmoreover hence \"(\\<Psi> \\<otimes> \\<Psi>', \\<lparr>\\<nu>y\\<rparr>(M\\<lparr>\\<lambda>*xvec N\\<rparr>.([(x, y)] \\<bullet> P)), M\\<lparr>\\<lambda>*xvec N\\<rparr>.\\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> P)) \\<in> ?X\" by force\n\tmoreover from Req `x \\<sharp> M` `y \\<sharp> M` `x \\<sharp> xvec` `y \\<sharp> xvec` `x \\<sharp> N` `y \\<sharp> N` `y \\<sharp> P` have \"R = \\<lparr>\\<nu>y\\<rparr>(M\\<lparr>\\<lambda>*xvec N\\<rparr>.([(x, y)] \\<bullet> P))\"\n\t  apply auto by(subst alpha_res[of y]) (auto simp add: eqvts input_chain_fresh)\n\tmoreover from Qeq `y \\<sharp> P` have \"Q = M\\<lparr>\\<lambda>*xvec N \\<rparr>.\\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> P)\"\n\t  apply auto by(subst alpha_res[of y]) (auto simp add: eqvts)\n\tultimately show ?case by blast\n      qed\n    next\n      case(c_sym \\<Psi> R Q)\n      thus ?case by blast\n    qed\n  }\n  moreover obtain y::name where \"y \\<sharp> \\<Psi>\" and \"y \\<sharp> M\" and \"y \\<sharp> N\" and \"y \\<sharp> P\" and \"y \\<sharp> xvec\"\n    by(generate_fresh \"name\") auto\n  ultimately have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>y\\<rparr>(M\\<lparr>\\<lambda>*xvec N\\<rparr>.([(x, y)] \\<bullet> P)) \\<sim> M\\<lparr>\\<lambda>*xvec N\\<rparr>.\\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> P)\" by auto\n  thus ?thesis using assms `y \\<sharp> P` `y \\<sharp> M` `y \\<sharp> N` `y \\<sharp> xvec`\n    apply(subst alpha_res[where x=x and y=y and P=P], auto)\n    by(subst alpha_res[where x=x and y=y and P=\"M\\<lparr>\\<lambda>*xvec N\\<rparr>.P\"]) (auto simp add: input_chain_fresh eqvts)\nqed\n\nlemma bisim_case_push_res:\n  fixes x  :: name\n  and   \\<Psi>  :: 'b\n  and   Cs :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n\n  assumes \"x \\<sharp> (map fst Cs)\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(Cases Cs) \\<sim> Cases(map (\\<lambda>(\\<phi>, P). (\\<phi>, \\<lparr>\\<nu>x\\<rparr>P)) Cs)\"\nproof -\n  {\n    fix x::name and Cs::\"('c \\<times> ('a, 'b, 'c) psi) list\"\n    assume \"x \\<sharp> \\<Psi>\" and \"x \\<sharp> (map fst Cs)\"\n    let ?X1 = \"{(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>(Cases Cs), Cases(map (\\<lambda>(\\<phi>, P). (\\<phi>, \\<lparr>\\<nu>x\\<rparr>P)) Cs)) | \\<Psi> x Cs. x \\<sharp> \\<Psi> \\<and> x \\<sharp> (map fst Cs)}\"\n    let ?X2 = \"{(\\<Psi>, Cases(map (\\<lambda>(\\<phi>, P). (\\<phi>, \\<lparr>\\<nu>x\\<rparr>P)) Cs), \\<lparr>\\<nu>x\\<rparr>(Cases Cs)) | \\<Psi> x Cs. x \\<sharp> \\<Psi> \\<and> x \\<sharp> (map fst Cs)}\"\n    let ?X = \"?X1 \\<union> ?X2\"\n  \n    have \"eqvt ?X\" apply(rule_tac eqvt_union) \n      apply(auto simp add: eqvt_def eqvts)\n      apply(rule_tac x=\"p \\<bullet> x\" in exI)\n      apply(rule_tac x=\"p \\<bullet> Cs\" in exI)\n      apply(perm_extend_simp)\n      apply(auto simp add: eqvts)\n      apply(simp add: pt_fresh_bij[OF pt_name_inst, OF at_name_inst])\n      apply(drule_tac pi=p in pt_fresh_bij1[OF pt_name_inst, OF at_name_inst])\n      apply(drule_tac pi=p in pt_fresh_bij1[OF pt_name_inst, OF at_name_inst])\n      apply(simp add: eqvts)\n      apply(perm_extend_simp)\n      apply(simp add: eqvts)\n      apply(rule_tac x=\"p \\<bullet> x\" in exI)\n      apply(rule_tac x=\"p \\<bullet> Cs\" in exI)\n      apply auto\n      apply(perm_extend_simp)\n      apply(simp add: pt_fresh_bij[OF pt_name_inst, OF at_name_inst])\n      apply(drule_tac pi=p in pt_fresh_bij1[OF pt_name_inst, OF at_name_inst])\n      apply(drule_tac pi=p in pt_fresh_bij1[OF pt_name_inst, OF at_name_inst])\n      apply(simp add: eqvts)\n      apply(perm_extend_simp)\n      by(simp add: eqvts)    \n    \n    from `x \\<sharp> \\<Psi>` `x \\<sharp> map fst Cs` have \"(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>(Cases Cs), Cases(map (\\<lambda>(\\<phi>, P). (\\<phi>, \\<lparr>\\<nu>x\\<rparr>P)) Cs)) \\<in> ?X\" by auto\n    hence \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(Cases Cs) \\<sim> Cases(map (\\<lambda>(\\<phi>, P). (\\<phi>, \\<lparr>\\<nu>x\\<rparr>P)) Cs)\"\n    proof(coinduct rule: bisim_coinduct)\n      case(c_stat_eq \\<Psi> Q R)\n      thus ?case using fresh_comp by(force intro: frame_res_fresh Frame_stat_eq_sym)\n    next\n      case(c_sim \\<Psi> Q R)\n      thus ?case using `eqvt ?X`\n\tby(force intro: case_push_res_left case_push_res_right bisim_reflexive)\n    next\n      case(c_ext \\<Psi> Q R \\<Psi>')\n      show ?case\n      proof(case_tac \"(\\<Psi>, Q, R) \\<in> ?X1\")\n\tassume \"(\\<Psi>, Q, R) \\<in> ?X1\"\n\tthen obtain x Cs where Qeq: \"Q = \\<lparr>\\<nu>x\\<rparr>(Cases Cs)\" and Req: \"R = Cases(map (\\<lambda>(\\<phi>, P). (\\<phi>, \\<lparr>\\<nu>x\\<rparr>P)) Cs)\"\n                           and \"x \\<sharp> \\<Psi>\" and \"x \\<sharp> (map fst Cs)\" by blast\n\tobtain y::name where \"y \\<sharp> \\<Psi>\" and \"y \\<sharp> \\<Psi>'\" and \"y \\<sharp> Cs\"\n\t  by(generate_fresh \"name\") (auto simp add: fresh_prod)\n\tfrom `y \\<sharp> Cs` `x \\<sharp> (map fst Cs)` have \"y \\<sharp> map fst ([(x, y)] \\<bullet> Cs)\" by(induct Cs) (auto simp add: fresh_list_cons fresh_list_nil)\n\n\tmoreover with `y \\<sharp> \\<Psi>` `y \\<sharp> \\<Psi>'` have \"(\\<Psi> \\<otimes> \\<Psi>', \\<lparr>\\<nu>y\\<rparr>(Cases ([(x, y)] \\<bullet> Cs)), Cases(map (\\<lambda>(\\<phi>, P). (\\<phi>, \\<lparr>\\<nu>y\\<rparr>P)) ([(x, y)] \\<bullet> Cs))) \\<in> ?X\"\n\t  by auto\n\tmoreover from Qeq `y \\<sharp> Cs` have \"Q = \\<lparr>\\<nu>y\\<rparr>(Cases([(x, y)] \\<bullet> Cs))\"\n\t  apply auto by(subst alpha_res[of y]) (auto simp add: eqvts)\n\tmoreover from Req `y \\<sharp> Cs` `x \\<sharp> (map fst Cs)` have \"R = Cases(map (\\<lambda>(\\<phi>, P). (\\<phi>, \\<lparr>\\<nu>y\\<rparr>P)) ([(x, y)] \\<bullet> Cs))\" \n\t  by(induct Cs arbitrary: R) (auto simp add: fresh_list_cons fresh_prod alpha_res)\n\tultimately show ?case by blast\n      next\n\tassume \"(\\<Psi>, Q, R) \\<notin> ?X1\"\n\twith `(\\<Psi>, Q, R) \\<in> ?X` have \"(\\<Psi>, Q, R) \\<in> ?X2\" by blast\n\tthen obtain x Cs where Req: \"R = \\<lparr>\\<nu>x\\<rparr>(Cases Cs)\" and Qeq: \"Q = Cases(map (\\<lambda>(\\<phi>, P). (\\<phi>, \\<lparr>\\<nu>x\\<rparr>P)) Cs)\"\n                           and \"x \\<sharp> \\<Psi>\" and \"x \\<sharp> (map fst Cs)\" by blast\n\tobtain y::name where \"y \\<sharp> \\<Psi>\" and \"y \\<sharp> \\<Psi>'\" and \"y \\<sharp> Cs\"\n\t  by(generate_fresh \"name\") (auto simp add: fresh_prod)\n\tfrom `y \\<sharp> Cs` `x \\<sharp> (map fst Cs)` have \"y \\<sharp> map fst ([(x, y)] \\<bullet> Cs)\" by(induct Cs) (auto simp add: fresh_list_cons fresh_list_nil)\n\t\n\tmoreover with `y \\<sharp> \\<Psi>` `y \\<sharp> \\<Psi>'` have \"(\\<Psi> \\<otimes> \\<Psi>', \\<lparr>\\<nu>y\\<rparr>(Cases ([(x, y)] \\<bullet> Cs)), Cases(map (\\<lambda>(\\<phi>, P). (\\<phi>, \\<lparr>\\<nu>y\\<rparr>P)) ([(x, y)] \\<bullet> Cs))) \\<in> ?X\"\n\t  by auto\n\tmoreover from Req `y \\<sharp> Cs` have \"R = \\<lparr>\\<nu>y\\<rparr>(Cases([(x, y)] \\<bullet> Cs))\"\n\t  apply auto by(subst alpha_res[of y]) (auto simp add: eqvts)\n\tmoreover from Qeq `y \\<sharp> Cs` `x \\<sharp> (map fst Cs)` have \"Q = Cases(map (\\<lambda>(\\<phi>, P). (\\<phi>, \\<lparr>\\<nu>y\\<rparr>P)) ([(x, y)] \\<bullet> Cs))\" \n\t  by(induct Cs arbitrary: Q) (auto simp add: fresh_list_cons fresh_prod alpha_res)\n\tultimately show ?case by blast\n      qed\n    next\n      case(c_sym \\<Psi> R Q)\n      thus ?case by blast\n    qed\n  }\n  moreover obtain y::name where \"y \\<sharp> \\<Psi>\" and \"y \\<sharp> Cs\" by(generate_fresh \"name\") auto\n  moreover from `x \\<sharp> map fst Cs` have \"y \\<sharp> map fst([(x, y)] \\<bullet> Cs)\" \n    by(induct Cs) (auto simp add: fresh_left calc_atm)\n  ultimately have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>y\\<rparr>(Cases ([(x, y)] \\<bullet> Cs)) \\<sim> Cases(map (\\<lambda>(\\<phi>, P). (\\<phi>, \\<lparr>\\<nu>y\\<rparr>P)) ([(x, y)] \\<bullet> Cs))\"\n    by auto\n  moreover from `y \\<sharp> Cs` have \"\\<lparr>\\<nu>y\\<rparr>(Cases ([(x, y)] \\<bullet> Cs)) =  \\<lparr>\\<nu>x\\<rparr>(Cases Cs)\"\n    by(simp add: alpha_res eqvts)\n  moreover from `x \\<sharp> map fst Cs` `y \\<sharp> Cs` have \"Cases(map (\\<lambda>(\\<phi>, P). (\\<phi>, \\<lparr>\\<nu>y\\<rparr>P)) ([(x, y)] \\<bullet> Cs)) = Cases(map (\\<lambda>(\\<phi>, P). (\\<phi>, \\<lparr>\\<nu>x\\<rparr>P)) Cs)\"\n    by(induct Cs) (auto simp add: alpha_res)\n  ultimately show ?thesis by auto\nqed\n\nlemma bang_ext:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  \n  assumes \"guarded P\"\n\n  shows \"\\<Psi> \\<rhd> !P \\<sim> P \\<parallel> !P\"\nproof -\n  let ?X = \"{(\\<Psi>, !P, P \\<parallel> !P) | \\<Psi> P. guarded P} \\<union> {(\\<Psi>, P \\<parallel> !P, !P) | \\<Psi> P. guarded P}\"\n  from `guarded P` have \"(\\<Psi>, !P, P \\<parallel> !P) \\<in> ?X\" by auto\n  thus ?thesis\n  proof(coinduct rule: bisim_coinduct)\n    case(c_stat_eq \\<Psi> Q R)\n    from `(\\<Psi>, Q, R) \\<in> ?X` obtain P where Eq: \"(Q = !P \\<and> R = P \\<parallel> !P) \\<or> (Q = P \\<parallel> !P \\<and> R = !P)\" and \"guarded P\"\n      by auto\n    obtain A\\<^sub>P \\<Psi>\\<^sub>P where FrP: \"extract_frame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\" by(rule fresh_frame)\n    from FrP `guarded P` have \"\\<Psi>\\<^sub>P \\<simeq> S_bottom'\" by(blast dest: guarded_stat_eq)\n    from `\\<Psi>\\<^sub>P \\<simeq> S_bottom'` have \"\\<Psi> \\<otimes> S_bottom' \\<simeq> \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> S_bottom'\" by(metis Identity Composition Assertion_stat_eq_trans Commutativity Assertion_stat_eq_sym)\n    hence \"\\<langle>A\\<^sub>P, \\<Psi> \\<otimes> S_bottom'\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P, \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> S_bottom'\\<rangle>\"\n      by(force intro: frame_res_chain_pres)\n    moreover from `A\\<^sub>P \\<sharp>* \\<Psi>` have \"\\<langle>\\<epsilon>, \\<Psi> \\<otimes> S_bottom'\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P, \\<Psi> \\<otimes> S_bottom'\\<rangle>\"\n      by(rule_tac Frame_stat_eq_sym) (force intro: frame_res_fresh_chain)\n    ultimately show ?case using Eq `A\\<^sub>P \\<sharp>* \\<Psi>` FrP\n      by auto (blast dest: Frame_stat_eq_trans Frame_stat_eq_sym)+\n  next\n    case(c_sim \\<Psi> Q R)\n    thus ?case by(auto intro: bang_ext_left bang_ext_right bisim_reflexive)\n  next\n    case(c_ext \\<Psi> Q R)\n    thus ?case by auto\n  next\n    case(c_sym \\<Psi> Q R)\n    thus ?case by auto\n  qed\nqed\n  \nlemma bisim_par_pres_sym:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   R :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<sim> Q\"\n\n  shows \"\\<Psi> \\<rhd> R \\<parallel> P \\<sim> R \\<parallel> Q\"\nusing assms\nby(metis bisim_par_comm bisim_par_pres bisim_transitive)\n\nlemma bisim_scope_ext_sym:\n  fixes x :: name\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   P :: \"('a, 'b, 'c) psi\"\n\n  assumes \"x \\<sharp> \\<Psi>\"\n  and     \"x \\<sharp> Q\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(P \\<parallel> Q) \\<sim> (\\<lparr>\\<nu>x\\<rparr>P) \\<parallel> Q\"\nusing assms\nby(metis bisim_scope_ext bisim_transitive bisim_par_comm bisim_symmetric bisim_res_pres)\n\nlemma bisim_scope_ext_chain_sym:\n  fixes xvec :: \"name list\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n\n  assumes \"xvec \\<sharp>* \\<Psi>\"\n  and     \"xvec \\<sharp>* Q\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q) \\<sim> (\\<lparr>\\<nu>*xvec\\<rparr>P) \\<parallel> Q\"\nusing assms\nby(induct xvec) (auto intro: bisim_scope_ext_sym bisim_reflexive bisim_transitive bisim_res_pres)\n\nlemma bisim_par_pres_aux_sym:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   R :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q\"\n  and     \"extract_frame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\"\n  and     \"A\\<^sub>R \\<sharp>* \\<Psi>\"\n  and     \"A\\<^sub>R \\<sharp>* P\"\n  and     \"A\\<^sub>R \\<sharp>* Q\"\n\n  shows \"\\<Psi> \\<rhd> R \\<parallel> P \\<sim> R \\<parallel> Q\"\nusing assms\nby(metis bisim_par_comm bisim_par_pres_aux bisim_transitive)\n\nlemma bang_nontau_derivative:\n  fixes \\<Psi>   :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha>    :: \"'a action\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> !P \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> P'\"\n  and     \"\\<Psi> \\<rhd> P \\<sim> Q\"\n  and     \"bn \\<alpha> \\<sharp>* \\<Psi>\"\n  and     \"bn \\<alpha> \\<sharp>* P\"\n  and     \"bn \\<alpha> \\<sharp>* Q\"\n  and     \"bn \\<alpha> \\<sharp>* subject \\<alpha>\"\n  and     \"guarded Q\"\n  and     \"\\<alpha> \\<noteq> \\<tau>\"\n\n  obtains \\<pi>' Q' R T where \"\\<Psi> \\<rhd> !Q \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> Q'\" and \"\\<Psi> \\<rhd> P' \\<sim> R \\<parallel> !P\" and \"\\<Psi> \\<rhd> Q' \\<sim> T \\<parallel> !Q\" and \"\\<Psi> \\<rhd> R \\<sim> T\"\n                   and \"((supp R)::name set) \\<subseteq> supp P'\" and \"((supp T)::name set) \\<subseteq> supp Q'\"\nproof -\n  from `\\<Psi> \\<rhd> !P \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> P'` have \"guarded P\" apply - by(ind_cases \"\\<Psi> \\<rhd> !P \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> P'\") (auto simp add: psi.inject)\n  assume \"\\<And>\\<pi>' Q' R T. \\<lbrakk>\\<Psi> \\<rhd> !Q \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> Q'; \\<Psi> \\<rhd> P' \\<sim> R \\<parallel> !P; \\<Psi> \\<rhd> Q' \\<sim> T \\<parallel> !Q; \\<Psi> \\<rhd> R \\<sim> T; ((supp R)::name set) \\<subseteq> supp P';\n                    ((supp T)::name set) \\<subseteq> supp Q'\\<rbrakk> \\<Longrightarrow> thesis\"\n  moreover from `\\<Psi> \\<rhd> !P \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> P'` `bn \\<alpha> \\<sharp>* subject \\<alpha>` `bn \\<alpha> \\<sharp>* \\<Psi>` `bn \\<alpha> \\<sharp>* P` `bn \\<alpha> \\<sharp>* Q` `\\<Psi> \\<rhd> P \\<sim> Q` `guarded Q`  `\\<alpha> \\<noteq> \\<tau>`\n  have \"\\<exists>Q' \\<pi>' T R . \\<Psi> \\<rhd> !Q \\<longmapsto>\\<pi>' @ \\<alpha>  \\<prec> Q' \\<and> \\<Psi> \\<rhd> P' \\<sim> R \\<parallel> !P \\<and> \\<Psi> \\<rhd> Q' \\<sim> T \\<parallel> !Q \\<and> \\<Psi> \\<rhd> R \\<sim> T \\<and>\n                  ((supp R)::name set) \\<subseteq> supp P' \\<and> ((supp T)::name set) \\<subseteq> supp Q'\"\n  proof(nominal_induct avoiding: Q rule: bang_induct')\n    case(c_alpha \\<pi> \\<alpha> P' p Q)\n    moreover have \"\\<alpha> \\<noteq> \\<tau>\" using `(p\\<bullet>\\<alpha>) \\<noteq> \\<tau>`\n      by(subst perm_bool[where pi=p,symmetric]) (simp add: eqvts)\n    ultimately obtain Q' \\<pi>' T R where Q_trans: \"\\<Psi> \\<rhd> !Q \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> Q'\" and \"\\<Psi> \\<rhd> P' \\<sim> R \\<parallel> (P \\<parallel> !P)\" and \"\\<Psi> \\<rhd> Q' \\<sim> T \\<parallel> !Q\" and \"\\<Psi> \\<rhd> R \\<sim> T\"\n                         and suppR: \"((supp R)::name set) \\<subseteq> supp P'\" and suppT: \"((supp T)::name set) \\<subseteq> supp Q'\"\n      by blast\n    from Q_trans have \"distinct(bn \\<alpha>)\" by(rule bound_output_distinct)\n    have S: \"set p \\<subseteq> set(bn \\<alpha>) \\<times> set(bn(p \\<bullet> \\<alpha>))\" by fact\n    from Q_trans `bn(p \\<bullet> \\<alpha>) \\<sharp>* Q` `bn(p \\<bullet> \\<alpha>) \\<sharp>* \\<alpha>` `bn \\<alpha> \\<sharp>* subject \\<alpha>` `distinct(bn \\<alpha>)` have \"bn(p \\<bullet> \\<alpha>) \\<sharp>* Q'\"\n      by(drule_tac free_fresh_chain_derivative) simp+\n    with Q_trans `bn(p \\<bullet> \\<alpha>) \\<sharp>* \\<alpha>` S `bn \\<alpha> \\<sharp>* subject \\<alpha>` have \"\\<Psi> \\<rhd> !Q \\<longmapsto>\\<pi>' @ (p \\<bullet> \\<alpha>) \\<prec> (p \\<bullet> Q')\"\n      by(force simp add: residual_alpha)\n    moreover from `\\<Psi> \\<rhd> P' \\<sim> R \\<parallel> (P \\<parallel> !P)` have \"(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P') \\<sim> (p \\<bullet> (R \\<parallel> (P \\<parallel> !P)))\"\n      by(rule bisim_closed)\n    with `bn \\<alpha> \\<sharp>* \\<Psi>` `bn \\<alpha> \\<sharp>* P` `bn(p \\<bullet> \\<alpha>) \\<sharp>* \\<Psi>` `bn(p \\<bullet> \\<alpha>) \\<sharp>* P` S have \"\\<Psi> \\<rhd> (p \\<bullet> P') \\<sim> (p \\<bullet> R) \\<parallel> (P \\<parallel> !P)\"\n      by(simp add: eqvts)\n    moreover from `\\<Psi> \\<rhd> Q' \\<sim> T \\<parallel> !Q` have \"(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> Q') \\<sim> (p \\<bullet> (T \\<parallel> !Q))\"\n      by(rule bisim_closed)\n    with `bn \\<alpha> \\<sharp>* \\<Psi>` `bn \\<alpha> \\<sharp>* Q` `bn(p \\<bullet> \\<alpha>) \\<sharp>* \\<Psi>` `bn(p \\<bullet> \\<alpha>) \\<sharp>* Q` S have \"\\<Psi> \\<rhd> (p \\<bullet> Q') \\<sim> (p \\<bullet> T) \\<parallel> !Q\"\n      by(simp add: eqvts)\n    moreover from `\\<Psi> \\<rhd> R \\<sim> T` have \"(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> R) \\<sim> (p \\<bullet> T)\"\n      by(rule bisim_closed)\n    with `bn \\<alpha> \\<sharp>* \\<Psi>` `bn(p \\<bullet> \\<alpha>) \\<sharp>* \\<Psi>` S have \"\\<Psi> \\<rhd> (p \\<bullet> R) \\<sim> (p \\<bullet> T)\"\n      by(simp add: eqvts)\n    moreover from suppR have \"((supp(p \\<bullet> R))::name set) \\<subseteq> supp(p \\<bullet> P')\"\n      apply(erule_tac rev_mp)\n      by(subst subset_closed[of p, symmetric]) (simp add: eqvts)\n    moreover from suppT have \"((supp(p \\<bullet> T))::name set) \\<subseteq> supp(p \\<bullet> Q')\"\n      apply(erule_tac rev_mp)\n      by(subst subset_closed[of p, symmetric]) (simp add: eqvts)\n    ultimately show ?case by blast\n  next\n    case(c_par1 \\<pi> \\<alpha> P' Q)\n    from `\\<Psi> \\<rhd> P \\<sim> Q` `\\<Psi> \\<rhd> P \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> P'` `bn \\<alpha> \\<sharp>* \\<Psi>` `bn \\<alpha> \\<sharp>* Q` \n    obtain \\<pi>' Q' where Q_trans: \"\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> Q'\" and \"\\<Psi> \\<rhd> P' \\<sim> Q'\"\n      by(blast dest: bisimE simE)\n    from Q_trans have \"\\<Psi> \\<otimes> S_bottom' \\<rhd> Q \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> Q'\" by(metis stat_eq_transition Identity Assertion_stat_eq_sym)\n    hence \"\\<Psi> \\<rhd> Q \\<parallel> !Q \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> (Q' \\<parallel> !Q)\" using `bn \\<alpha> \\<sharp>* Q`\n      by(drule_tac Par1[where Q=\"!Q\"]) (assumption|simp add: option.map_ident)+\n    hence \"\\<Psi> \\<rhd> !Q \\<longmapsto>map_option (F_assert o push_prov) \\<pi>' @ \\<alpha> \\<prec> (Q' \\<parallel> !Q)\" using `guarded Q` by(rule Bang)\n    moreover from `guarded P` have \"\\<Psi> \\<rhd> P' \\<parallel> !P \\<sim> P' \\<parallel> (P \\<parallel> !P)\" by(metis bang_ext bisim_par_pres_sym)\n    moreover have \"\\<Psi> \\<rhd> Q' \\<parallel> !Q \\<sim> Q' \\<parallel> !Q\" by(rule bisim_reflexive)\n    ultimately show ?case using `\\<Psi> \\<rhd> P' \\<sim> Q'` by(force simp add: psi.supp)\n  next\n    case(c_par2 \\<pi> \\<alpha> P' A\\<^sub>P \\<Psi>\\<^sub>P Q)\n    then obtain Q' \\<pi>' T R where Q_trans: \"\\<Psi> \\<rhd> !Q \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> Q'\" and \"\\<Psi> \\<rhd> P' \\<sim> R \\<parallel> !P\" and \"\\<Psi> \\<rhd> Q' \\<sim> T \\<parallel> !Q\" and \"\\<Psi> \\<rhd> R \\<sim> T\"\n                         and suppR: \"((supp R)::name set) \\<subseteq> supp P'\" and suppT: \"((supp T)::name set) \\<subseteq> supp Q'\"\n      by blast\n    note Q_trans\n    from `\\<Psi> \\<rhd> P' \\<sim> R \\<parallel> !P` have \"\\<Psi> \\<rhd> P \\<parallel> P' \\<sim> R \\<parallel> (P \\<parallel> !P)\"\n      by(metis bisim_par_pres_sym bisim_par_comm bisim_transitive bisim_par_assoc)\n    with Q_trans show ?case using `\\<Psi> \\<rhd> Q' \\<sim> T \\<parallel> !Q` `\\<Psi> \\<rhd> R \\<sim> T` suppR suppT\n      by(force simp add: psi.supp)\n  next\n    case(c_comm1 M N P' K xvec A\\<^sub>P \\<Psi>\\<^sub>P yvec zvec P'' Q)\n    thus ?case by blast\n  next\n    case(c_comm2 M xvec N P' K P'' Q)\n    thus ?case by blast\n  next\n    case(c_bang \\<pi> \\<alpha> P' Q)\n    then obtain Q' \\<pi>' T R where Q_trans: \"\\<Psi> \\<rhd> !Q \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> Q'\" and \"\\<Psi> \\<rhd> P' \\<sim> R \\<parallel> (P \\<parallel> !P)\" and \"\\<Psi> \\<rhd> Q' \\<sim> T \\<parallel> !Q\" and \"\\<Psi> \\<rhd> R \\<sim> T\"\n                         and suppR: \"((supp R)::name set) \\<subseteq> supp P'\" and suppT: \"((supp T)::name set) \\<subseteq> supp Q'\"\n      by blast\n    from `\\<Psi> \\<rhd> P' \\<sim> R \\<parallel> (P \\<parallel> !P)` `guarded P` have \"\\<Psi> \\<rhd> P' \\<sim> R \\<parallel> !P\" by(metis bang_ext bisim_par_pres_sym bisim_transitive bisim_symmetric)\n    with Q_trans show ?case using `\\<Psi> \\<rhd> Q' \\<sim> T \\<parallel> !Q` `\\<Psi> \\<rhd> R \\<sim> T` suppR suppT\n      by blast\n  qed\n  ultimately show ?thesis by blast\nqed\n\nlemma bang_tau_derivative:\n  fixes \\<Psi>   :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha>    :: \"'a action\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> !P \\<longmapsto>\\<pi> @ \\<tau> \\<prec> P'\"\n  and     \"\\<Psi> \\<rhd> P \\<sim> Q\"\n  and     \"guarded Q\"\n\n  obtains Q' R T where \"\\<Psi> \\<rhd> !Q \\<longmapsto>None @ \\<tau> \\<prec> Q'\" and \"\\<Psi> \\<rhd> P' \\<sim> R \\<parallel> !P\" and \"\\<Psi> \\<rhd> Q' \\<sim> T \\<parallel> !Q\" and \"\\<Psi> \\<rhd> R \\<sim> T\"\n                   and \"((supp R)::name set) \\<subseteq> supp P'\" and \"((supp T)::name set) \\<subseteq> supp Q'\"\nproof -\n  from `\\<Psi> \\<rhd> !P \\<longmapsto>\\<pi> @ \\<tau> \\<prec> P'` have \"guarded P\" apply - by(ind_cases \"\\<Psi> \\<rhd> !P \\<longmapsto>\\<pi> @ \\<tau> \\<prec> P'\") (auto simp add: psi.inject)\n  assume \"\\<And>Q' R T. \\<lbrakk>\\<Psi> \\<rhd> !Q \\<longmapsto>None @ \\<tau> \\<prec> Q'; \\<Psi> \\<rhd> P' \\<sim> R \\<parallel> !P; \\<Psi> \\<rhd> Q' \\<sim> T \\<parallel> !Q; \\<Psi> \\<rhd> R \\<sim> T; ((supp R)::name set) \\<subseteq> supp P';\n                    ((supp T)::name set) \\<subseteq> supp Q'\\<rbrakk> \\<Longrightarrow> thesis\"\n  moreover from tau_no_provenance'[OF `\\<Psi> \\<rhd> !P \\<longmapsto>\\<pi> @ \\<tau> \\<prec> P'`] `\\<Psi> \\<rhd> P \\<sim> Q` `guarded Q` \n  have \"\\<exists>Q' T R . \\<Psi> \\<rhd> !Q \\<longmapsto>None @ \\<tau>  \\<prec> Q' \\<and> \\<Psi> \\<rhd> P' \\<sim> R \\<parallel> !P \\<and> \\<Psi> \\<rhd> Q' \\<sim> T \\<parallel> !Q \\<and> \\<Psi> \\<rhd> R \\<sim> T \\<and>\n                  ((supp R)::name set) \\<subseteq> supp P' \\<and> ((supp T)::name set) \\<subseteq> supp Q'\"\n  proof(nominal_induct avoiding: Q rule: bang_tau_induct)\n    case(c_par1 P' Q)\n    have \"bn(\\<tau>) \\<sharp>* \\<Psi>\" and \"bn(\\<tau>) \\<sharp>* Q\" by simp_all\n    with `\\<Psi> \\<rhd> P \\<sim> Q` `\\<Psi> \\<rhd> P \\<longmapsto>None @ \\<tau> \\<prec> P'`\n    obtain \\<pi>' Q' where Q_trans: \"\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi>' @ \\<tau> \\<prec> Q'\" and \"\\<Psi> \\<rhd> P' \\<sim> Q'\"\n      by(blast dest: bisimE simE)\n    from Q_trans have \"\\<Psi> \\<otimes> S_bottom' \\<rhd> Q \\<longmapsto>\\<pi>' @ \\<tau> \\<prec> Q'\" by(metis stat_eq_transition Identity Assertion_stat_eq_sym)\n    hence \"\\<Psi> \\<rhd> Q \\<parallel> !Q \\<longmapsto>\\<pi>' @ \\<tau> \\<prec> (Q' \\<parallel> !Q)\"\n      by(drule_tac Par1[where Q=\"!Q\"]) (assumption|simp add: option.map_ident)+\n    hence \"\\<Psi> \\<rhd> !Q \\<longmapsto>map_option (F_assert o push_prov) \\<pi>' @ \\<tau> \\<prec> (Q' \\<parallel> !Q)\" using `guarded Q` by(rule Bang)\n    hence \"\\<Psi> \\<rhd> !Q \\<longmapsto>None @ \\<tau> \\<prec> (Q' \\<parallel> !Q)\"\n      by(metis tau_no_provenance')\n    moreover from `guarded P` have \"\\<Psi> \\<rhd> P' \\<parallel> !P \\<sim> P' \\<parallel> (P \\<parallel> !P)\" by(metis bang_ext bisim_par_pres_sym)\n    moreover have \"\\<Psi> \\<rhd> Q' \\<parallel> !Q \\<sim> Q' \\<parallel> !Q\" by(rule bisim_reflexive)\n    ultimately show ?case using `\\<Psi> \\<rhd> P' \\<sim> Q'` by(force simp add: psi.supp)\n  next\n    case(c_par2 P')\n    then obtain Q' T R where Q_trans: \"\\<Psi> \\<rhd> !Q \\<longmapsto>None @ \\<tau> \\<prec> Q'\" and \"\\<Psi> \\<rhd> P' \\<sim> R \\<parallel> !P\" and \"\\<Psi> \\<rhd> Q' \\<sim> T \\<parallel> !Q\" and \"\\<Psi> \\<rhd> R \\<sim> T\"\n                         and suppR: \"((supp R)::name set) \\<subseteq> supp P'\" and suppT: \"((supp T)::name set) \\<subseteq> supp Q'\"\n      by blast\n    note Q_trans\n    from `\\<Psi> \\<rhd> P' \\<sim> R \\<parallel> !P` have \"\\<Psi> \\<rhd> P \\<parallel> P' \\<sim> R \\<parallel> (P \\<parallel> !P)\"\n      by(metis bisim_par_pres_sym bisim_par_comm bisim_transitive bisim_par_assoc)\n    with tau_no_provenance'[OF Q_trans] show ?case using `\\<Psi> \\<rhd> Q' \\<sim> T \\<parallel> !Q` `\\<Psi> \\<rhd> R \\<sim> T` suppR suppT\n      by(force simp add: psi.supp)\n  next\n    case(c_comm1 M N P' K xvec A\\<^sub>P \\<Psi>\\<^sub>P yvec zvec P'' Q)\n    from `\\<Psi> \\<rhd> P \\<sim> Q` have \"\\<Psi> \\<rhd> Q \\<leadsto>[bisim] P\" by(metis bisimE)\n    with `\\<Psi> \\<rhd> P \\<longmapsto>Some (\\<langle>A\\<^sub>P; yvec, K\\<rangle>) @ M\\<lparr>N\\<rparr> \\<prec> P'` obtain \\<pi> Q' where Q_trans: \"\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ M\\<lparr>N\\<rparr> \\<prec> Q'\" and \"\\<Psi> \\<rhd> Q' \\<sim> P'\"\n      by(force dest: simE)\n    from Q_trans have \"\\<Psi> \\<otimes> S_bottom' \\<rhd> Q \\<longmapsto>\\<pi> @ M\\<lparr>N\\<rparr> \\<prec> Q'\" by(metis stat_eq_transition Identity Assertion_stat_eq_sym)\n    from Q_trans obtain A\\<^sub>Q \\<Psi>\\<^sub>Q tvec K' where FrQ: \"extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\" and \"A\\<^sub>Q \\<sharp>* P\" and \"A\\<^sub>Q \\<sharp>* Q\" and \"A\\<^sub>Q \\<sharp>* M\" and \"A\\<^sub>Q \\<sharp>* N\" and \"A\\<^sub>Q \\<sharp>* xvec\" and \"A\\<^sub>Q \\<sharp>* yvec\" and \"A\\<^sub>Q \\<sharp>* zvec\" and \"A\\<^sub>Q \\<sharp>* tvec\" and \"tvec \\<sharp>* \\<Psi>\" and \"tvec \\<sharp>* Q\" and \"tvec \\<sharp>* P\" and \"tvec \\<sharp>* M\" and \"tvec \\<sharp>* N\" and \"tvec \\<sharp>* xvec\" and \"tvec \\<sharp>* yvec\" and \"tvec \\<sharp>* zvec\" and \"distinct tvec\" and \"distinct A\\<^sub>Q\" and \\<pi>: \"\\<pi> = Some(\\<langle>A\\<^sub>Q; tvec, K'\\<rangle>)\" and \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M \\<leftrightarrow> K'\"\n      by(drule_tac C=\"(\\<Psi>, Q, M, P, xvec, yvec, zvec)\" in input_provenance) auto\n    have \"tvec \\<sharp>* \\<Psi>\\<^sub>Q\" using `tvec \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* tvec` FrQ\n      by(auto dest: extract_frame_fresh_chain)\n    have \"zvec \\<sharp>* \\<Psi>\\<^sub>Q\" using `zvec \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* zvec` FrQ\n      by(auto dest: extract_frame_fresh_chain)\n    have \"zvec \\<sharp>* K'\" using `zvec \\<sharp>* Q` Q_trans `A\\<^sub>Q \\<sharp>* zvec` `tvec \\<sharp>* zvec`\n      unfolding \\<pi>\n      by(auto dest!: trans_fresh_provenance simp add: frame_chain_fresh_chain'')\n    have \"xvec \\<sharp>* K'\" using `xvec \\<sharp>* Q` Q_trans `A\\<^sub>Q \\<sharp>* xvec` `tvec \\<sharp>* xvec`\n      unfolding \\<pi>\n      by(auto dest!: trans_fresh_provenance simp add: frame_chain_fresh_chain'')\n    note FrQ\n    moreover from FrQ `guarded Q` have \"\\<Psi>\\<^sub>Q \\<simeq> S_bottom'\" by(blast dest: guarded_stat_eq)\n    have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<one> \\<turnstile> M \\<leftrightarrow> K'\" using `\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M \\<leftrightarrow> K'`\n      by (metis Assertion_stat_eq_def Associativity Identity stat_eq_ent)\n    from `\\<Psi> \\<rhd> !P \\<longmapsto> Some (\\<langle>\\<epsilon>, \\<langle>zvec, M\\<rangle>\\<rangle>) @ K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P''` `\\<Psi>\\<^sub>Q \\<simeq> S_bottom'`\n    have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> !P \\<longmapsto> Some (\\<langle>\\<epsilon>, \\<langle>zvec, M\\<rangle>\\<rangle>) @ K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P''\"\n      by(metis stat_eq_transition Identity composition_sym Assertion_stat_eq_sym)      \n    hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> !P \\<longmapsto> Some (\\<langle>\\<epsilon>, \\<langle>zvec, M\\<rangle>\\<rangle>) @ K'\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P''\"\n      using `\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<one> \\<turnstile> M \\<leftrightarrow> K'` `zvec \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* P` `A\\<^sub>Q \\<sharp>* M`\n      `distinct zvec` `zvec \\<sharp>* P` `A\\<^sub>Q \\<sharp>* zvec` `zvec \\<sharp>* \\<Psi>\\<^sub>Q` `zvec \\<sharp>* K'`\n      apply(subst frame_res_chainbase[symmetric])\n      by(rule_tac comm1_aux[where A\\<^sub>P=A\\<^sub>Q]) (auto intro!: Frame_stat_imp_refl)\n    hence \"\\<Psi> \\<rhd> !P \\<longmapsto> Some (\\<langle>\\<epsilon>, \\<langle>zvec, M\\<rangle>\\<rangle>) @ K'\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P''\" using `\\<Psi>\\<^sub>Q \\<simeq> S_bottom'`\n      by(metis stat_eq_transition Identity composition_sym Assertion_stat_eq_sym)\n    with `xvec \\<sharp>* K'` `\\<Psi> \\<rhd> P \\<sim> Q` `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* P` `xvec \\<sharp>* Q` `guarded Q`\n    obtain Q'' \\<pi>' T R where Q_trans': \"\\<Psi> \\<rhd> !Q \\<longmapsto>\\<pi>' @ K'\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q''\" and \"\\<Psi> \\<rhd> P'' \\<sim> R \\<parallel> !P\" and \"\\<Psi> \\<rhd> Q'' \\<sim> T \\<parallel> !Q\" and \"\\<Psi> \\<rhd> R \\<sim> T\"\n      and suppR: \"((supp R)::name set) \\<subseteq> supp P''\" and suppT: \"((supp T)::name set) \\<subseteq> supp Q''\"\n      by(rule_tac bang_nontau_derivative) auto\n    from Q_trans' `\\<Psi>\\<^sub>Q \\<simeq> S_bottom'` have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> !Q \\<longmapsto>\\<pi>' @ K'\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q''\"\n      by(metis stat_eq_transition Identity composition_sym Assertion_stat_eq_sym)\n    then obtain uvec M' where \"uvec \\<sharp>* \\<Psi>\" and \"uvec \\<sharp>* Q\" and \"uvec \\<sharp>* P\" and \"uvec \\<sharp>* M\" and \"uvec \\<sharp>* N\" and \"uvec \\<sharp>* xvec\" and \"uvec \\<sharp>* yvec\" and \"uvec \\<sharp>* zvec\" and \"uvec \\<sharp>* tvec\" and \"distinct uvec\" and \\<pi>': \"\\<pi>' = Some(\\<langle>([]); uvec, M'\\<rangle>)\" and \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<one> \\<turnstile> M' \\<leftrightarrow> K'\" and \"uvec \\<sharp>* A\\<^sub>Q\"\n      unfolding residual_inject\n      by(drule_tac C=\"(\\<Psi>, \\<Psi>\\<^sub>Q,Q, M, P, xvec, yvec, zvec,tvec,A\\<^sub>Q)\" in output_provenance) auto\n    hence \"\\<Psi> \\<otimes> \\<one> \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M' \\<leftrightarrow> K'\"\n      by(metis Associativity associativity_sym stat_eq_ent)\n    have \"A\\<^sub>Q \\<sharp>* M'\" using `A\\<^sub>Q \\<sharp>* Q` Q_trans' `uvec \\<sharp>* A\\<^sub>Q`\n      unfolding \\<pi>'\n      by(auto dest!: trans_fresh_provenance simp add: frame_chain_fresh_chain'' frame_chain_fresh_chain)    \n    have \"tvec \\<sharp>* M'\" using `tvec \\<sharp>* Q` Q_trans' `uvec \\<sharp>* tvec`\n      unfolding \\<pi>'\n      by(auto dest!: trans_fresh_provenance simp add: frame_chain_fresh_chain'' frame_chain_fresh_chain)\n    with `\\<Psi> \\<otimes> S_bottom' \\<rhd> Q \\<longmapsto>\\<pi> @ M\\<lparr>N\\<rparr> \\<prec> Q'` FrQ `distinct A\\<^sub>Q` `A\\<^sub>Q \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* \\<Psi>` `distinct tvec` `A\\<^sub>Q \\<sharp>* tvec` `tvec \\<sharp>* \\<Psi>` `\\<Psi> \\<otimes> \\<one> \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M' \\<leftrightarrow> K'` `A\\<^sub>Q \\<sharp>* M'` `tvec \\<sharp>* Q`\n    have \"\\<Psi> \\<otimes> S_bottom' \\<rhd> Q \\<longmapsto>\\<pi> @ M'\\<lparr>N\\<rparr> \\<prec> Q'\"\n      unfolding \\<pi>\n      by(rule_tac comm2_aux[where A\\<^sub>Q=\"[]\" and A\\<^sub>P=\"[]\"]) (assumption|auto)+\n    moreover from `(\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<one> \\<turnstile> M' \\<leftrightarrow> K'` `\\<Psi>\\<^sub>Q \\<simeq> S_bottom'` have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<one> \\<turnstile> M' \\<leftrightarrow> K'\" by(metis stat_eq_ent Identity composition_sym Assertion_stat_eq_sym)\n    ultimately have \"\\<Psi> \\<rhd> Q \\<parallel> !Q \\<longmapsto>None @ \\<tau> \\<prec> (\\<lparr>\\<nu>*xvec\\<rparr>(Q' \\<parallel> Q''))\" using `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* M` `xvec \\<sharp>* Q` `\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> !Q \\<longmapsto>\\<pi>' @ K'\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q''` `tvec \\<sharp>* \\<Psi>` `tvec \\<sharp>* \\<Psi>\\<^sub>Q` `tvec \\<sharp>* Q`\n       `uvec \\<sharp>* \\<Psi>` `uvec \\<sharp>* Q`\n      unfolding \\<pi> \\<pi>'\n      by(rule_tac Comm1) (assumption | simp)+\n    hence \"\\<Psi> \\<rhd> !Q \\<longmapsto>None @ \\<tau> \\<prec> (\\<lparr>\\<nu>*xvec\\<rparr>(Q' \\<parallel> Q''))\" using `guarded Q` by(drule_tac Bang) auto\n    moreover from `\\<Psi> \\<rhd> P'' \\<sim> R \\<parallel> !P` `guarded P` `xvec \\<sharp>* \\<Psi>` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> P'') \\<sim> \\<lparr>\\<nu>*xvec\\<rparr>((P' \\<parallel> R) \\<parallel> (P \\<parallel> !P))\"\n      by(metis bisim_par_pres_sym bang_ext bisim_transitive bisim_par_assoc bisim_symmetric bisim_res_chain_pres)\n    with `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* P` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> P'') \\<sim> (\\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> R)) \\<parallel> (P \\<parallel> !P)\"\n      by(metis bisim_scope_ext_chain_sym bisim_transitive psi_fresh_vec)\n    moreover from `\\<Psi> \\<rhd> Q'' \\<sim> T \\<parallel> !Q` `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* Q` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(Q' \\<parallel> Q'') \\<sim> (\\<lparr>\\<nu>*xvec\\<rparr>(Q' \\<parallel> T)) \\<parallel> !Q\"\n      by(metis bisim_par_pres_sym bisim_transitive bisim_par_assoc bisim_symmetric bisim_res_chain_pres bisim_scope_ext_chain_sym psi_fresh_vec)\n    moreover from `\\<Psi> \\<rhd> R \\<sim> T` `\\<Psi> \\<rhd> Q' \\<sim> P'` `xvec \\<sharp>* \\<Psi>` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> R) \\<sim> \\<lparr>\\<nu>*xvec\\<rparr>(Q' \\<parallel> T)\"\n      by(metis bisim_par_pres_sym bisim_transitive bisim_res_chain_pres bisim_par_comm bisimE(4))\n    moreover from suppR have \"((supp(\\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> R)))::name set) \\<subseteq>  supp((\\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> P'')))\"\n      by(auto simp add: psi.supp res_chain_supp)\n    moreover from suppT have \"((supp(\\<lparr>\\<nu>*xvec\\<rparr>(Q' \\<parallel> T)))::name set) \\<subseteq>  supp((\\<lparr>\\<nu>*xvec\\<rparr>(Q' \\<parallel> Q'')))\"\n      by(auto simp add: psi.supp res_chain_supp)\n    ultimately show ?case by blast\n  next\n    case(c_comm2 M xvec N P' K A\\<^sub>P \\<Psi>\\<^sub>P yvec zvec P'' Q)\n    from `\\<Psi> \\<rhd> P \\<sim> Q` have \"\\<Psi> \\<rhd> Q \\<leadsto>[bisim] P\" by(metis bisimE)\n    with `\\<Psi> \\<rhd> P \\<longmapsto>Some (\\<langle>A\\<^sub>P; yvec, K\\<rangle>) @ M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'` `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* Q`\n    obtain \\<pi> Q' where Q_trans: \"\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'\" and \"\\<Psi> \\<rhd> Q' \\<sim> P'\"\n      by(force dest: simE)\n    from Q_trans have \"\\<Psi> \\<otimes> S_bottom' \\<rhd> Q \\<longmapsto>\\<pi> @ M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'\" by(metis stat_eq_transition Identity Assertion_stat_eq_sym)\n    from Q_trans obtain A\\<^sub>Q \\<Psi>\\<^sub>Q tvec K' where FrQ: \"extract_frame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\" and \"A\\<^sub>Q \\<sharp>* P\" and \"A\\<^sub>Q \\<sharp>* Q\" and \"A\\<^sub>Q \\<sharp>* M\" and \"A\\<^sub>Q \\<sharp>* N\" and \"A\\<^sub>Q \\<sharp>* xvec\" and \"A\\<^sub>Q \\<sharp>* yvec\" and \"A\\<^sub>Q \\<sharp>* zvec\" and \"A\\<^sub>Q \\<sharp>* tvec\" and \"tvec \\<sharp>* \\<Psi>\" and \"tvec \\<sharp>* Q\" and \"tvec \\<sharp>* P\" and \"tvec \\<sharp>* M\" and \"tvec \\<sharp>* N\" and \"tvec \\<sharp>* xvec\" and \"tvec \\<sharp>* yvec\" and \"tvec \\<sharp>* zvec\" and \"distinct tvec\" and \"distinct A\\<^sub>Q\" and \\<pi>: \"\\<pi> = Some(\\<langle>A\\<^sub>Q; tvec, K'\\<rangle>)\" and \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> K' \\<leftrightarrow> M\"\n      unfolding residual_inject\n      by(drule_tac C=\"(\\<Psi>, Q, M, P, xvec, yvec, zvec)\" in output_provenance) auto\n    have \"tvec \\<sharp>* \\<Psi>\\<^sub>Q\" using `tvec \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* tvec` FrQ\n      by(auto dest: extract_frame_fresh_chain)\n    have \"zvec \\<sharp>* \\<Psi>\\<^sub>Q\" using `zvec \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* zvec` FrQ\n      by(auto dest: extract_frame_fresh_chain)\n    have \"zvec \\<sharp>* K'\" using `zvec \\<sharp>* Q` Q_trans `A\\<^sub>Q \\<sharp>* zvec` `tvec \\<sharp>* zvec`\n      unfolding \\<pi>\n      by(auto dest!: trans_fresh_provenance simp add: frame_chain_fresh_chain'')\n    have \"xvec \\<sharp>* K'\" using `xvec \\<sharp>* Q` Q_trans `A\\<^sub>Q \\<sharp>* xvec` `tvec \\<sharp>* xvec`\n      unfolding \\<pi>\n      by(auto dest!: trans_fresh_provenance simp add: frame_chain_fresh_chain'')\n    note FrQ\n    moreover from FrQ `guarded Q` have \"\\<Psi>\\<^sub>Q \\<simeq> S_bottom'\" by(blast dest: guarded_stat_eq)\n    have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<one> \\<turnstile> K' \\<leftrightarrow> M\" using `\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> K' \\<leftrightarrow> M`\n      by (metis Assertion_stat_eq_def Associativity Identity stat_eq_ent)\n    from `\\<Psi> \\<rhd> !P \\<longmapsto> Some (\\<langle>\\<epsilon>, \\<langle>zvec, M\\<rangle>\\<rangle>) @ K\\<lparr>N\\<rparr> \\<prec> P''` `\\<Psi>\\<^sub>Q \\<simeq> S_bottom'`\n    have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> !P \\<longmapsto> Some (\\<langle>\\<epsilon>, \\<langle>zvec, M\\<rangle>\\<rangle>) @ K\\<lparr>N\\<rparr> \\<prec> P''\"\n      by(metis stat_eq_transition Identity composition_sym Assertion_stat_eq_sym)      \n    hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> !P \\<longmapsto> Some (\\<langle>\\<epsilon>, \\<langle>zvec, M\\<rangle>\\<rangle>) @ K'\\<lparr>N\\<rparr> \\<prec> P''\"\n      using `\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<one> \\<turnstile> K' \\<leftrightarrow> M` `zvec \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* P` `A\\<^sub>Q \\<sharp>* M`\n      `distinct zvec` `zvec \\<sharp>* P` `A\\<^sub>Q \\<sharp>* zvec` `zvec \\<sharp>* \\<Psi>\\<^sub>Q` `zvec \\<sharp>* K'`\n      apply(subst frame_res_chainbase[symmetric])\n      by(rule_tac comm2_aux[where A\\<^sub>P=A\\<^sub>Q]) (auto intro!: Frame_stat_imp_refl)\n    hence \"\\<Psi> \\<rhd> !P \\<longmapsto> Some (\\<langle>\\<epsilon>, \\<langle>zvec, M\\<rangle>\\<rangle>) @ K'\\<lparr>N\\<rparr> \\<prec> P''\" using `\\<Psi>\\<^sub>Q \\<simeq> S_bottom'`\n      by(metis stat_eq_transition Identity composition_sym Assertion_stat_eq_sym)\n    with `xvec \\<sharp>* K'` `\\<Psi> \\<rhd> P \\<sim> Q` `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* P` `xvec \\<sharp>* Q` `guarded Q`\n    obtain Q'' \\<pi>' T R where Q_trans': \"\\<Psi> \\<rhd> !Q \\<longmapsto>\\<pi>' @ K'\\<lparr>N\\<rparr> \\<prec> Q''\" and \"\\<Psi> \\<rhd> P'' \\<sim> R \\<parallel> !P\" and \"\\<Psi> \\<rhd> Q'' \\<sim> T \\<parallel> !Q\" and \"\\<Psi> \\<rhd> R \\<sim> T\"\n      and suppR: \"((supp R)::name set) \\<subseteq> supp P''\" and suppT: \"((supp T)::name set) \\<subseteq> supp Q''\"\n      by(rule_tac bang_nontau_derivative) auto\n    from Q_trans' `\\<Psi>\\<^sub>Q \\<simeq> S_bottom'` have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> !Q \\<longmapsto>\\<pi>' @ K'\\<lparr>N\\<rparr> \\<prec> Q''\"\n      by(metis stat_eq_transition Identity composition_sym Assertion_stat_eq_sym)\n    then obtain uvec M' where \"uvec \\<sharp>* \\<Psi>\" and \"uvec \\<sharp>* Q\" and \"uvec \\<sharp>* P\" and \"uvec \\<sharp>* M\" and \"uvec \\<sharp>* N\" and \"uvec \\<sharp>* xvec\" and \"uvec \\<sharp>* yvec\" and \"uvec \\<sharp>* zvec\" and \"uvec \\<sharp>* tvec\" and \"distinct uvec\" and \\<pi>': \"\\<pi>' = Some(\\<langle>([]); uvec, M'\\<rangle>)\" and \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<one> \\<turnstile> K' \\<leftrightarrow> M'\" and \"uvec \\<sharp>* A\\<^sub>Q\"\n      by(drule_tac C=\"(\\<Psi>, \\<Psi>\\<^sub>Q,Q, M, P, xvec, yvec, zvec,tvec,A\\<^sub>Q)\" in input_provenance) auto\n    hence \"\\<Psi> \\<otimes> \\<one> \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> K' \\<leftrightarrow> M'\"\n      by(metis Associativity associativity_sym stat_eq_ent)\n    have \"A\\<^sub>Q \\<sharp>* M'\" using `A\\<^sub>Q \\<sharp>* Q` Q_trans' `uvec \\<sharp>* A\\<^sub>Q`\n      unfolding \\<pi>'\n      by(auto dest!: trans_fresh_provenance simp add: frame_chain_fresh_chain'' frame_chain_fresh_chain)    \n    have \"tvec \\<sharp>* M'\" using `tvec \\<sharp>* Q` Q_trans' `uvec \\<sharp>* tvec`\n      unfolding \\<pi>'\n      by(auto dest!: trans_fresh_provenance simp add: frame_chain_fresh_chain'' frame_chain_fresh_chain)\n    with `\\<Psi> \\<otimes> S_bottom' \\<rhd> Q \\<longmapsto>\\<pi> @ M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'` FrQ `distinct A\\<^sub>Q` `A\\<^sub>Q \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* \\<Psi>` `distinct tvec` `A\\<^sub>Q \\<sharp>* tvec` `tvec \\<sharp>* \\<Psi>` `\\<Psi> \\<otimes> \\<one> \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> K' \\<leftrightarrow> M'` `A\\<^sub>Q \\<sharp>* M'` `tvec \\<sharp>* Q`\n    have \"\\<Psi> \\<otimes> S_bottom' \\<rhd> Q \\<longmapsto>\\<pi> @ M'\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'\"\n      unfolding \\<pi>\n      by(rule_tac comm1_aux[where A\\<^sub>Q=\"[]\" and A\\<^sub>P=\"[]\"]) (assumption|auto)+\n    moreover from `(\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<one> \\<turnstile> K' \\<leftrightarrow> M'` `\\<Psi>\\<^sub>Q \\<simeq> S_bottom'` have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<one> \\<turnstile> K' \\<leftrightarrow> M'\" by(metis stat_eq_ent Identity composition_sym Assertion_stat_eq_sym)\n    ultimately have \"\\<Psi> \\<rhd> Q \\<parallel> !Q \\<longmapsto>None @ \\<tau> \\<prec> (\\<lparr>\\<nu>*xvec\\<rparr>(Q' \\<parallel> Q''))\" using `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* M` `xvec \\<sharp>* Q` `\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> !Q \\<longmapsto>\\<pi>' @ K'\\<lparr>N\\<rparr> \\<prec> Q''` `tvec \\<sharp>* \\<Psi>` `tvec \\<sharp>* \\<Psi>\\<^sub>Q` `tvec \\<sharp>* Q`\n       `uvec \\<sharp>* \\<Psi>` `uvec \\<sharp>* Q`\n      unfolding \\<pi> \\<pi>'\n      by(rule_tac Comm2) (assumption | simp)+\n    hence \"\\<Psi> \\<rhd> !Q \\<longmapsto>None @ \\<tau> \\<prec> (\\<lparr>\\<nu>*xvec\\<rparr>(Q' \\<parallel> Q''))\" using `guarded Q` by(drule_tac Bang) auto\n    moreover from `\\<Psi> \\<rhd> P'' \\<sim> R \\<parallel> !P` `guarded P` `xvec \\<sharp>* \\<Psi>` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> P'') \\<sim> \\<lparr>\\<nu>*xvec\\<rparr>((P' \\<parallel> R) \\<parallel> (P \\<parallel> !P))\"\n      by(metis bisim_par_pres_sym bang_ext bisim_transitive bisim_par_assoc bisim_symmetric bisim_res_chain_pres)\n    with `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* P` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> P'') \\<sim> (\\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> R)) \\<parallel> (P \\<parallel> !P)\"\n      by(metis bisim_scope_ext_chain_sym bisim_transitive psi_fresh_vec)\n    moreover from `\\<Psi> \\<rhd> Q'' \\<sim> T \\<parallel> !Q` `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* Q` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(Q' \\<parallel> Q'') \\<sim> (\\<lparr>\\<nu>*xvec\\<rparr>(Q' \\<parallel> T)) \\<parallel> !Q\"\n      by(metis bisim_par_pres_sym bisim_transitive bisim_par_assoc bisim_symmetric bisim_res_chain_pres bisim_scope_ext_chain_sym psi_fresh_vec)\n    moreover from `\\<Psi> \\<rhd> R \\<sim> T` `\\<Psi> \\<rhd> Q' \\<sim> P'` `xvec \\<sharp>* \\<Psi>` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> R) \\<sim> \\<lparr>\\<nu>*xvec\\<rparr>(Q' \\<parallel> T)\"\n      by(metis bisim_par_pres_sym bisim_transitive bisim_res_chain_pres bisim_par_comm bisimE(4))\n    moreover from suppR have \"((supp(\\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> R)))::name set) \\<subseteq>  supp((\\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> P'')))\"\n      by(auto simp add: psi.supp res_chain_supp)\n    moreover from suppT have \"((supp(\\<lparr>\\<nu>*xvec\\<rparr>(Q' \\<parallel> T)))::name set) \\<subseteq>  supp((\\<lparr>\\<nu>*xvec\\<rparr>(Q' \\<parallel> Q'')))\"\n      by(auto simp add: psi.supp res_chain_supp)\n    ultimately show ?case by blast\n  next\n    case(c_bang P' Q)\n    then obtain Q' T R where Q_trans: \"\\<Psi> \\<rhd> !Q \\<longmapsto>None @ \\<tau> \\<prec> Q'\" and \"\\<Psi> \\<rhd> P' \\<sim> R \\<parallel> (P \\<parallel> !P)\" and \"\\<Psi> \\<rhd> Q' \\<sim> T \\<parallel> !Q\" and \"\\<Psi> \\<rhd> R \\<sim> T\"\n                         and suppR: \"((supp R)::name set) \\<subseteq> supp P'\" and suppT: \"((supp T)::name set) \\<subseteq> supp Q'\"\n      by blast\n    from `\\<Psi> \\<rhd> P' \\<sim> R \\<parallel> (P \\<parallel> !P)` `guarded P` have \"\\<Psi> \\<rhd> P' \\<sim> R \\<parallel> !P\" by(metis bang_ext bisim_par_pres_sym bisim_transitive bisim_symmetric)\n    with Q_trans show ?case using `\\<Psi> \\<rhd> Q' \\<sim> T \\<parallel> !Q` `\\<Psi> \\<rhd> R \\<sim> T` suppR suppT\n      by blast\n  qed\n  ultimately show ?thesis by blast\nqed\n\nlemma bang_derivative:\n  fixes \\<Psi>   :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha>    :: \"'a action\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> !P \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> P'\"\n  and     \"\\<Psi> \\<rhd> P \\<sim> Q\"\n  and     \"bn \\<alpha> \\<sharp>* \\<Psi>\"\n  and     \"bn \\<alpha> \\<sharp>* P\"\n  and     \"bn \\<alpha> \\<sharp>* Q\"\n  and     \"bn \\<alpha> \\<sharp>* subject \\<alpha>\"\n  and     \"guarded Q\"\n\n  obtains \\<pi>' Q' R T where \"\\<Psi> \\<rhd> !Q \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> Q'\" and \"\\<Psi> \\<rhd> P' \\<sim> R \\<parallel> !P\" and \"\\<Psi> \\<rhd> Q' \\<sim> T \\<parallel> !Q\" and \"\\<Psi> \\<rhd> R \\<sim> T\"\n                   and \"((supp R)::name set) \\<subseteq> supp P'\" and \"((supp T)::name set) \\<subseteq> supp Q'\"\n  using assms\n  by(cases \"\\<alpha> = \\<tau>\") (auto intro: bang_nontau_derivative bang_tau_derivative)\n\nlemma struct_cong_bisim:\n  fixes P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes \"P \\<equiv>\\<^sub>s Q\"\n\n  shows \"P \\<sim> Q\"\nusing assms\nby(induct rule: struct_cong.induct)\n  (auto intro: bisim_reflexive bisim_symmetric bisim_transitive bisim_par_comm bisim_par_assoc bisim_par_nil bisim_res_nil bisim_res_comm bisim_scope_ext bisim_case_push_res bisim_input_push_res bisim_output_push_res bang_ext)\n\nlemma bisim_bang_pres:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<sim> Q\"\n  and     \"guarded P\"\n  and     \"guarded Q\"\n\n  shows \"\\<Psi> \\<rhd> !P \\<sim> !Q\"\nproof -\n  let ?X = \"{(\\<Psi>, R \\<parallel> !P, R \\<parallel> !Q) | \\<Psi> P Q R. \\<Psi> \\<rhd> P \\<sim> Q \\<and> guarded P \\<and> guarded Q}\"\n  let ?Y = \"{(\\<Psi>, P, Q) | \\<Psi> P P' Q' Q. \\<Psi> \\<rhd> P \\<sim> P' \\<and> (\\<Psi>, P', Q') \\<in> ?X \\<and> \\<Psi> \\<rhd> Q' \\<sim> Q}\"\n  from assms have \"(\\<Psi>, \\<zero> \\<parallel> !P, \\<zero> \\<parallel> !Q) \\<in> ?X\" by(blast intro: bisim_reflexive)\n\n  moreover have \"eqvt ?X\" \n    apply(auto simp add: eqvt_def)\n    apply(drule_tac p=p in bisim_closed)\n    by force\n  ultimately have \"\\<Psi> \\<rhd> \\<zero> \\<parallel> !P \\<sim> \\<zero> \\<parallel> !Q\"\n  proof(coinduct rule: weak_transitive_coinduct)\n    case(c_stat_eq \\<Psi> P Q)\n    thus ?case by auto\n  next\n    case(c_sim \\<Psi> RP RQ)\n    from `(\\<Psi>, RP, RQ) \\<in> ?X` obtain P Q R where \"\\<Psi> \\<rhd> P \\<sim> Q\" and \"guarded P\" and \"guarded Q\"\n                                           and \"RP = R \\<parallel> !P\" and \"RQ = R \\<parallel> !Q\"\n      by auto\n    note `\\<Psi> \\<rhd> P \\<sim> Q` \n    moreover from `eqvt ?X` have \"eqvt ?Y\" by blast\n    moreover note `guarded P` `guarded Q` bisimE(2) bisimE(3) bisimE(4) stat_eq_bisim bisim_closed bisim_par_assoc[THEN bisim_symmetric] \n                  bisim_par_pres bisim_par_pres_aux_sym bisim_res_chain_pres bisim_scope_ext_chain_sym bisim_transitive\n    moreover have \"\\<And>\\<Psi> P Q R T. \\<lbrakk>\\<Psi> \\<rhd> P \\<sim> Q; (\\<Psi>, Q, R) \\<in> ?Y; \\<Psi> \\<rhd> R \\<sim> T\\<rbrakk> \\<Longrightarrow> (\\<Psi>, P, T) \\<in> ?Y\"\n      by auto (metis bisim_transitive)\n    moreover have \"\\<And>\\<Psi> P Q R. \\<lbrakk>\\<Psi> \\<rhd> P \\<sim> Q; guarded P; guarded Q\\<rbrakk> \\<Longrightarrow> (\\<Psi>, R \\<parallel> !P, R \\<parallel> !Q) \\<in> ?Y\" by(blast intro: bisim_reflexive)\n    moreover have \"\\<And>\\<Psi> P \\<pi> \\<alpha> P' Q. \\<lbrakk>\\<Psi> \\<rhd> !P \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> P'; \\<Psi> \\<rhd> P \\<sim> Q; bn \\<alpha> \\<sharp>* \\<Psi>;  bn \\<alpha> \\<sharp>* P;  bn \\<alpha> \\<sharp>* Q; guarded Q; bn \\<alpha> \\<sharp>* subject \\<alpha>\\<rbrakk> \\<Longrightarrow>\n                                         \\<exists>\\<pi>' Q' R T.  \\<Psi> \\<rhd> !Q \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> Q' \\<and> \\<Psi> \\<rhd> P' \\<sim> R \\<parallel> !P \\<and>  \\<Psi> \\<rhd> Q' \\<sim> T \\<parallel> !Q \\<and>\n                                                   \\<Psi> \\<rhd> R \\<sim> T \\<and> ((supp R)::name set) \\<subseteq> supp P' \\<and> \n                                                   ((supp T)::name set) \\<subseteq> supp Q'\"\n      by(blast elim: bang_derivative)\n    ultimately have \"\\<Psi> \\<rhd> R \\<parallel> !P \\<leadsto>[?Y] R \\<parallel> !Q\"\n      by(rule bang_pres)\n    with `RP = R \\<parallel> !P` `RQ = R \\<parallel> !Q` show ?case\n      by blast\n  next\n    case(c_ext \\<Psi> RP RQ \\<Psi>')\n    thus ?case by(blast dest: bisimE)\n  next\n    case(c_sym \\<Psi> RP RQ)\n    thus ?case by(blast dest: bisimE)\n  qed\n  thus ?thesis\n    by(metis bisim_transitive bisim_par_nil bisim_symmetric bisim_par_comm)\nqed\n\nend\n\nend\n\n", "meta": {"author": "IlmariReissumies", "repo": "newpsi", "sha": "201517d55b6ed1632a5bff2a585367278b5bc67b", "save_path": "github-repos/isabelle/IlmariReissumies-newpsi", "path": "github-repos/isabelle/IlmariReissumies-newpsi/newpsi-201517d55b6ed1632a5bff2a585367278b5bc67b/Bisim_Struct_Cong.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.257774190440236}}
{"text": "theory FOR_Check_Impl\n  imports FOR_Check\n   Regular_Tree_Relations.Regular_Relation_Impl\n   NF_Impl\nbegin\n\nsection \\<open>Inference checking implementation\\<close>\n\n(* we define epsilon free agtt/gtt constructions *)\ndefinition \"ftrancl_eps_free_closures \\<A> = eps_free_automata (eps \\<A>) \\<A>\"\nabbreviation \"ftrancl_eps_free_reg \\<A> \\<equiv> Reg (fin \\<A>) (ftrancl_eps_free_closures (ta \\<A>))\"\n\nlemma ftrancl_eps_free_ta_derI:\n  \"(eps \\<A>)|\\<^sup>+| = eps \\<A> \\<Longrightarrow> ta_der (ftrancl_eps_free_closures \\<A>) (term_of_gterm t) = ta_der \\<A> (term_of_gterm t)\"\n  using eps_free[of \\<A>] ta_res_eps_free[of \\<A>]\n  by (auto simp add: ftrancl_eps_free_closures_def)\n\nlemma \\<L>_ftrancl_eps_free_closuresI:\n  \"(eps (ta \\<A>))|\\<^sup>+| = eps (ta \\<A>) \\<Longrightarrow> \\<L> (ftrancl_eps_free_reg \\<A>) = \\<L> \\<A>\"\n  using ftrancl_eps_free_ta_derI[of \"ta \\<A>\"]\n  unfolding \\<L>_def by (auto simp: gta_lang_def gta_der_def)\n\ndefinition \"root_step R \\<F> \\<equiv> (let (TA1, TA2) = agtt_grrstep R \\<F> in\n  (ftrancl_eps_free_closures TA1, TA2))\"\n\ndefinition AGTT_trancl_eps_free :: \"('q, 'f) gtt \\<Rightarrow> ('q + 'q, 'f) gtt\" where\n  \"AGTT_trancl_eps_free \\<G> = (let (\\<A>, \\<B>) = AGTT_trancl \\<G> in\n    (ftrancl_eps_free_closures \\<A>, \\<B>))\"\n\ndefinition GTT_trancl_eps_free where\n  \"GTT_trancl_eps_free \\<G> = (let (\\<A>, \\<B>) = GTT_trancl \\<G> in\n   (ftrancl_eps_free_closures \\<A>,\n    ftrancl_eps_free_closures \\<B>))\"\n\ndefinition AGTT_comp_eps_free where\n  \"AGTT_comp_eps_free \\<G>\\<^sub>1 \\<G>\\<^sub>2 = (let (\\<A>, \\<B>) = AGTT_comp' \\<G>\\<^sub>1 \\<G>\\<^sub>2 in\n    (ftrancl_eps_free_closures \\<A>, \\<B>))\"\n\ndefinition GTT_comp_eps_free where\n  \"GTT_comp_eps_free \\<G>\\<^sub>1 \\<G>\\<^sub>2 =(let (\\<A>, \\<B>) = GTT_comp' \\<G>\\<^sub>1 \\<G>\\<^sub>2 in\n    (ftrancl_eps_free_closures \\<A>, ftrancl_eps_free_closures \\<B>))\"\n\n(* epsilon free proves *)\nlemma eps_free_relable [simp]:\n  \"is_gtt_eps_free (relabel_gtt \\<G>) = is_gtt_eps_free \\<G>\"\n  by (auto simp: is_gtt_eps_free_def relabel_gtt_def fmap_states_gtt_def fmap_states_ta_def)\n\nlemma eps_free_prod_swap:\n  \"is_gtt_eps_free (\\<A>, \\<B>) \\<Longrightarrow> is_gtt_eps_free (\\<B>, \\<A>)\"\n  by (auto simp: is_gtt_eps_free_def)\n\nlemma eps_free_root_step:\n  \"is_gtt_eps_free (root_step R \\<F>)\"\n  by (auto simp add: case_prod_beta is_gtt_eps_free_def root_step_def pair_at_to_agtt'_def ftrancl_eps_free_closures_def)\n\nlemma eps_free_AGTT_trancl_eps_free:\n  \"is_gtt_eps_free \\<G> \\<Longrightarrow> is_gtt_eps_free (AGTT_trancl_eps_free \\<G>)\"\n  by (auto simp: case_prod_beta is_gtt_eps_free_def AGTT_trancl_def Let_def\n      AGTT_trancl_eps_free_def ftrancl_eps_free_closures_def)\n\nlemma eps_free_GTT_trancl_eps_free:\n  \"is_gtt_eps_free \\<G> \\<Longrightarrow> is_gtt_eps_free (GTT_trancl_eps_free \\<G>)\"\n  by (auto simp: case_prod_beta is_gtt_eps_free_def GTT_trancl_eps_free_def ftrancl_eps_free_closures_def)\n\nlemma eps_free_AGTT_comp_eps_free:\n  \"is_gtt_eps_free \\<G>\\<^sub>2 \\<Longrightarrow> is_gtt_eps_free (AGTT_comp_eps_free \\<G>\\<^sub>1 \\<G>\\<^sub>2)\"\n  by (auto simp: case_prod_beta is_gtt_eps_free_def AGTT_comp_eps_free_def\n    ftrancl_eps_free_closures_def AGTT_comp_def fmap_states_gtt_def fmap_states_ta_def)\n\nlemma eps_free_GTT_comp_eps_free:\n  \"is_gtt_eps_free (GTT_comp_eps_free \\<G>\\<^sub>1 \\<G>\\<^sub>2)\"\n  by (auto simp: case_prod_beta is_gtt_eps_free_def GTT_comp_eps_free_def ftrancl_eps_free_closures_def)\n\nlemmas eps_free_const =\n  eps_free_prod_swap\n  eps_free_root_step\n  eps_free_AGTT_trancl_eps_free\n  eps_free_GTT_trancl_eps_free\n  eps_free_AGTT_comp_eps_free\n  eps_free_GTT_comp_eps_free\n\n(* lang preserve proofs *)\nlemma agtt_lang_derI:\n  assumes \"\\<And> t. ta_der (fst \\<A>) (term_of_gterm t) = ta_der (fst \\<B>) (term_of_gterm t)\"\n    and \"\\<And> t. ta_der (snd \\<A>) (term_of_gterm t) = ta_der (snd \\<B>) (term_of_gterm t)\"\n  shows \"agtt_lang \\<A> = agtt_lang \\<B>\" using assms\n  by (auto simp: agtt_lang_def gta_der_def)\n\nlemma agtt_lang_root_step_conv:\n  \"agtt_lang (root_step R \\<F>) = agtt_lang (agtt_grrstep R \\<F>)\"\n  using ftrancl_eps_free_ta_derI[OF agtt_grrstep_eps_trancl(1), of R \\<F>]\n  by (auto simp: case_prod_beta root_step_def intro!: agtt_lang_derI)\n\nlemma agtt_lang_AGTT_trancl_eps_free_conv:\n  assumes \"is_gtt_eps_free \\<G>\"\n  shows \"agtt_lang (AGTT_trancl_eps_free \\<G>) = agtt_lang (AGTT_trancl \\<G>)\"\nproof -\n  let ?eps = \"eps (fst (AGTT_trancl \\<G>))\"\n  have \"?eps |O| ?eps = {||}\" using assms\n    by (auto simp: AGTT_trancl_def is_gtt_eps_free_def Let_def fmap_states_ta_def)\n  from ftrancl_eps_free_ta_derI[OF frelcomp_empty_ftrancl_simp[OF this]]\n  show ?thesis\n    by (auto simp: case_prod_beta AGTT_trancl_eps_free_def intro!: agtt_lang_derI)\nqed\n\nlemma agtt_lang_GTT_trancl_eps_free_conv:\n  assumes \"is_gtt_eps_free \\<G>\"\n  shows \"agtt_lang (GTT_trancl_eps_free \\<G>) = agtt_lang (GTT_trancl \\<G>)\"\nproof -\n  have \"(eps (fst (GTT_trancl \\<G>)))|\\<^sup>+| = eps (fst (GTT_trancl \\<G>))\"\n    \"(eps (snd (GTT_trancl \\<G>)))|\\<^sup>+| = eps (snd (GTT_trancl \\<G>))\" using assms\n    by (auto simp: GTT_trancl_def Let_def is_gtt_eps_free_def \\<Delta>_trancl_inv)\n  from ftrancl_eps_free_ta_derI[OF this(1)] ftrancl_eps_free_ta_derI[OF this(2)]\n  show ?thesis\n    by (auto simp: case_prod_beta GTT_trancl_eps_free_def intro!: agtt_lang_derI)\nqed\n\nlemma agtt_lang_AGTT_comp_eps_free_conv:\n  assumes \"is_gtt_eps_free \\<G>\\<^sub>1\" \"is_gtt_eps_free \\<G>\\<^sub>2\"\n  shows \"agtt_lang (AGTT_comp_eps_free \\<G>\\<^sub>1 \\<G>\\<^sub>2) = agtt_lang (AGTT_comp' \\<G>\\<^sub>1 \\<G>\\<^sub>2)\"\nproof -\n  have \"(eps (fst (AGTT_comp' \\<G>\\<^sub>1 \\<G>\\<^sub>2)))|\\<^sup>+| = eps (fst (AGTT_comp' \\<G>\\<^sub>1 \\<G>\\<^sub>2))\" using assms\n    by (auto simp: is_gtt_eps_free_def fmap_states_gtt_def fmap_states_ta_def\n      case_prod_beta AGTT_comp_def gtt_interface_def \\<Q>_def intro!: frelcomp_empty_ftrancl_simp)\n  from ftrancl_eps_free_ta_derI[OF this] show ?thesis\n    by (auto simp: case_prod_beta AGTT_comp_eps_free_def intro!: agtt_lang_derI)\nqed\n\nlemma agtt_lang_GTT_comp_eps_free_conv:\n  assumes \"is_gtt_eps_free \\<G>\\<^sub>1\" \"is_gtt_eps_free \\<G>\\<^sub>2\"\n  shows \"agtt_lang (GTT_comp_eps_free \\<G>\\<^sub>1 \\<G>\\<^sub>2) = agtt_lang (GTT_comp' \\<G>\\<^sub>1 \\<G>\\<^sub>2)\"\nproof -\n  have \"(eps (fst (GTT_comp' \\<G>\\<^sub>1 \\<G>\\<^sub>2)))|\\<^sup>+| = eps (fst (GTT_comp' \\<G>\\<^sub>1 \\<G>\\<^sub>2))\"\n    \"(eps (snd (GTT_comp' \\<G>\\<^sub>1 \\<G>\\<^sub>2)))|\\<^sup>+| = eps (snd (GTT_comp' \\<G>\\<^sub>1 \\<G>\\<^sub>2))\" using assms\n    by (auto simp: is_gtt_eps_free_def fmap_states_gtt_def fmap_states_ta_def \\<Delta>\\<^sub>\\<epsilon>_fmember\n      case_prod_beta GTT_comp_def gtt_interface_def \\<Q>_def dest!: ground_ta_der_statesD\n      intro!: frelcomp_empty_ftrancl_simp)\n  from ftrancl_eps_free_ta_derI[OF this(1)] ftrancl_eps_free_ta_derI[OF this(2)]\n  show ?thesis\n    by (auto simp: case_prod_beta GTT_comp_eps_free_def intro!: agtt_lang_derI)\nqed\n\nfun gtt_of_gtt_rel_impl :: \"('f \\<times> nat) fset \\<Rightarrow> ('f :: linorder, 'v) fin_trs list \\<Rightarrow> ftrs gtt_rel \\<Rightarrow> (nat, 'f) gtt option\" where\n  \"gtt_of_gtt_rel_impl \\<F> Rs (ARoot is) = liftO1 (\\<lambda>R. relabel_gtt (root_step R \\<F>)) (is_to_trs' Rs is)\"\n| \"gtt_of_gtt_rel_impl \\<F> Rs (GInv g) = liftO1 prod.swap (gtt_of_gtt_rel_impl \\<F> Rs g)\"\n| \"gtt_of_gtt_rel_impl \\<F> Rs (AUnion g1 g2) = liftO2 (\\<lambda>g1 g2. relabel_gtt (AGTT_union' g1 g2)) (gtt_of_gtt_rel_impl \\<F> Rs g1) (gtt_of_gtt_rel_impl \\<F> Rs g2)\"\n| \"gtt_of_gtt_rel_impl \\<F> Rs (ATrancl g) = liftO1 (relabel_gtt \\<circ> AGTT_trancl_eps_free) (gtt_of_gtt_rel_impl \\<F> Rs g)\"\n| \"gtt_of_gtt_rel_impl \\<F> Rs (GTrancl g) = liftO1 GTT_trancl_eps_free (gtt_of_gtt_rel_impl \\<F> Rs g)\"\n| \"gtt_of_gtt_rel_impl \\<F> Rs (AComp g1 g2) = liftO2 (\\<lambda>g1 g2. relabel_gtt (AGTT_comp_eps_free g1 g2)) (gtt_of_gtt_rel_impl \\<F> Rs g1) (gtt_of_gtt_rel_impl \\<F> Rs g2)\"\n| \"gtt_of_gtt_rel_impl \\<F> Rs (GComp g1 g2) = liftO2 (\\<lambda>g1 g2. relabel_gtt (GTT_comp_eps_free g1 g2)) (gtt_of_gtt_rel_impl \\<F> Rs g1) (gtt_of_gtt_rel_impl \\<F> Rs g2)\"\n\nlemma gtt_of_gtt_rel_impl_is_gtt_eps_free:\n  \"gtt_of_gtt_rel_impl \\<F> Rs g = Some g' \\<Longrightarrow> is_gtt_eps_free g'\"\nproof (induct g arbitrary: g')\n  case (AUnion g1 g2)\n  then show ?case\n    by (auto simp: is_gtt_eps_free_def AGTT_union_def fmap_states_gtt_def fmap_states_ta_def ta_union_def relabel_gtt_def)\nqed (auto simp: eps_free_const)\n\nlemma gtt_of_gtt_rel_impl_gtt_of_gtt_rel:\n  \"gtt_of_gtt_rel_impl \\<F> Rs g \\<noteq> None \\<longleftrightarrow> gtt_of_gtt_rel \\<F> Rs g \\<noteq> None\" (is \"?Ls \\<longleftrightarrow> ?Rs\")\nproof -\n  have \"?Ls \\<Longrightarrow> ?Rs\" by (induct g) auto\n  moreover have \"?Rs \\<Longrightarrow> ?Ls\" by (induct g) auto\n  ultimately show ?thesis by blast\nqed\n\nlemma gtt_of_gtt_rel_impl_sound:\n  \"gtt_of_gtt_rel_impl \\<F> Rs g = Some g' \\<Longrightarrow> gtt_of_gtt_rel \\<F> Rs g = Some g'' \\<Longrightarrow> agtt_lang g' = agtt_lang g''\"\nproof (induct g arbitrary: g' g'')\n  case (ARoot x)\n  then show ?case by (simp add: agtt_lang_root_step_conv)\nnext\n  case (GInv g)\n  then have \"agtt_lang (prod.swap g') = agtt_lang (prod.swap g'')\" by auto\n  then show ?case\n    by (metis converse_agtt_lang converse_converse)\nnext\n  case (AUnion g1 g2)\n  then show ?case\n    by simp (metis AGTT_union'_sound option.sel)\nnext\n  case (ATrancl g)\n  then show ?case\n    using agtt_lang_AGTT_trancl_eps_free_conv[OF gtt_of_gtt_rel_impl_is_gtt_eps_free, of \\<F> Rs g]\n    by simp (metis AGTT_trancl_sound option.sel)\nnext\n  case (GTrancl g)\n  then show ?case\n    using agtt_lang_GTT_trancl_eps_free_conv[OF gtt_of_gtt_rel_impl_is_gtt_eps_free, of \\<F> Rs g]\n    by simp (metis GTT_trancl_alang option.sel) \nnext\n  case (AComp g1 g2)\n  then show ?case\n    using agtt_lang_AGTT_comp_eps_free_conv[OF gtt_of_gtt_rel_impl_is_gtt_eps_free, of \\<F> Rs g\n      \"the (gtt_of_gtt_rel_impl \\<F> Rs g1)\" \"the (gtt_of_gtt_rel_impl \\<F> Rs g2)\"]\n    by simp (metis AGTT_comp'_sound agtt_lang_AGTT_comp_eps_free_conv gtt_of_gtt_rel_impl_is_gtt_eps_free option.sel) \nnext\n  case (GComp g1 g2)\n  then show ?case\n    using agtt_lang_GTT_comp_eps_free_conv[OF gtt_of_gtt_rel_impl_is_gtt_eps_free, of \\<F> Rs g\n      \"the (gtt_of_gtt_rel_impl \\<F> Rs g1)\" \"the (gtt_of_gtt_rel_impl \\<F> Rs g2)\"]\n    by simp (metis agtt_lang_GTT_comp_eps_free_conv gtt_comp'_alang gtt_of_gtt_rel_impl_is_gtt_eps_free option.sel) \nqed\n\n(* eps free closure constructions *)\nlemma \\<L>_eps_free_nhole_ctxt_closure_reg:\n  assumes \"is_ta_eps_free (ta \\<A>)\"\n  shows \"\\<L> (ftrancl_eps_free_reg (nhole_ctxt_closure_reg \\<F> \\<A>)) = \\<L> (nhole_ctxt_closure_reg \\<F> \\<A>)\"\nproof -\n  have \"eps (ta (nhole_ctxt_closure_reg \\<F> \\<A>)) |O| eps (ta (nhole_ctxt_closure_reg \\<F> \\<A>)) = {||}\" using assms\n    by (auto simp: nhole_ctxt_closure_reg_def gen_nhole_ctxt_closure_reg_def\n      gen_nhole_ctxt_closure_automaton_def ta_union_def reflcl_over_nhole_ctxt_ta_def\n      fmap_states_reg_def is_ta_eps_free_def fmap_states_ta_def reg_Restr_Q\\<^sub>f_def)\n  from frelcomp_empty_ftrancl_simp[OF this] show ?thesis\n    by (intro \\<L>_ftrancl_eps_free_closuresI) simp\nqed\n\nlemma \\<L>_eps_free_ctxt_closure_reg:\n  assumes \"is_ta_eps_free (ta \\<A>)\"\n  shows \"\\<L> (ftrancl_eps_free_reg (ctxt_closure_reg \\<F> \\<A>)) = \\<L> (ctxt_closure_reg \\<F> \\<A>)\"\nproof -\n  have \"eps (ta (ctxt_closure_reg \\<F> \\<A>)) |O| eps (ta (ctxt_closure_reg \\<F> \\<A>)) = {||}\" using assms\n    by (auto simp: ctxt_closure_reg_def gen_ctxt_closure_reg_def Let_def\n      gen_ctxt_closure_automaton_def ta_union_def reflcl_over_single_ta_def\n      fmap_states_reg_def is_ta_eps_free_def fmap_states_ta_def reg_Restr_Q\\<^sub>f_def)\n  from frelcomp_empty_ftrancl_simp[OF this] show ?thesis\n    by (intro \\<L>_ftrancl_eps_free_closuresI) simp\nqed\n\nlemma \\<L>_eps_free_parallel_closure_reg:\n  assumes \"is_ta_eps_free (ta \\<A>)\"\n  shows \"\\<L> (ftrancl_eps_free_reg (parallel_closure_reg \\<F> \\<A>)) = \\<L> (parallel_closure_reg \\<F> \\<A>)\"\nproof -\n  have \"eps (ta (parallel_closure_reg \\<F> \\<A>)) |O| eps (ta (parallel_closure_reg \\<F> \\<A>)) = {||}\" using assms\n    by (auto simp: parallel_closure_reg_def gen_parallel_closure_automaton_def Let_def ta_union_def\n      refl_over_states_ta_def fmap_states_reg_def is_ta_eps_free_def fmap_states_ta_def reg_Restr_Q\\<^sub>f_def)\n  from frelcomp_empty_ftrancl_simp[OF this] show ?thesis\n    by (intro \\<L>_ftrancl_eps_free_closuresI) simp\nqed\n\nabbreviation \"eps_free_reg' S R \\<equiv> Reg (fin R) (eps_free_automata S (ta R))\"\n\ndefinition \"eps_free_mctxt_closure_reg \\<F> \\<A> =\n  (let \\<B> = mctxt_closure_reg \\<F> \\<A> in\n  eps_free_reg' ((\\<lambda> p. (fst p, Inr cl_state)) |`| (eps (ta \\<B>)) |\\<union>| eps (ta \\<B>)) \\<B>)\"\n\ndefinition \"eps_free_nhole_mctxt_reflcl_reg \\<F> \\<A> =\n  (let \\<B> = nhole_mctxt_reflcl_reg \\<F> \\<A> in\n  eps_free_reg' ((\\<lambda> p. (fst p, Inl (Inr cl_state))) |`| (eps (ta \\<B>)) |\\<union>| eps (ta \\<B>)) \\<B>)\"\n\ndefinition \"eps_free_nhole_mctxt_closure_reg \\<F> \\<A> =\n  (let \\<B> = nhole_mctxt_closure_reg \\<F> \\<A> in\n  eps_free_reg' ((\\<lambda> p. (fst p, (Inr cl_state))) |`| (eps (ta \\<B>)) |\\<union>| eps (ta \\<B>)) \\<B>)\"\n\nlemma \\<L>_eps_free_reg'I:\n  \"(eps (ta \\<A>))|\\<^sup>+| = S \\<Longrightarrow> \\<L> (eps_free_reg' S \\<A>) = \\<L> \\<A>\"\n  by (auto simp:  \\<L>_def gta_lang_def gta_der_def ta_res_eps_free simp flip: eps_free) \n\nlemma \\<L>_eps_free_mctxt_closure_reg:\n  assumes \"is_ta_eps_free (ta \\<A>)\"\n  shows \"\\<L> (eps_free_mctxt_closure_reg \\<F> \\<A>) = \\<L> (mctxt_closure_reg \\<F> \\<A>)\" using assms\n  unfolding eps_free_mctxt_closure_reg_def Let_def\n  apply (intro \\<L>_eps_free_reg'I)\n  apply (auto simp: comp_def mctxt_closure_reg_def is_ta_eps_free_def Let_def\n    gen_nhole_mctxt_closure_automaton_def reflcl_over_nhole_mctxt_ta_def ta_union_def\n    reflcl_over_nhole_ctxt_ta_def  gen_mctxt_closure_reg_def reg_Restr_Q\\<^sub>f_def\n    fmap_states_reg_def fmap_states_ta_def dest: ftranclD ftranclD2)\n  by (meson fimageI finsert_iff finterI fr_into_trancl ftrancl_into_trancl)\n\nlemma \\<L>_eps_free_nhole_mctxt_reflcl_reg:\n  assumes \"is_ta_eps_free (ta \\<A>)\"\n  shows \"\\<L> (eps_free_nhole_mctxt_reflcl_reg \\<F> \\<A>) = \\<L> (nhole_mctxt_reflcl_reg \\<F> \\<A>)\" using assms\n  unfolding eps_free_nhole_mctxt_reflcl_reg_def Let_def\n  apply (intro \\<L>_eps_free_reg'I)\n  apply (auto simp: comp_def nhole_mctxt_reflcl_reg_def is_ta_eps_free_def Let_def\n    nhole_mctxt_closure_reg_def gen_nhole_mctxt_closure_reg_def reg_union_def ta_union_def\n    gen_nhole_mctxt_closure_automaton_def reflcl_over_nhole_mctxt_ta_def\n    reflcl_over_nhole_ctxt_ta_def reg_Restr_Q\\<^sub>f_def fmap_states_reg_def fmap_states_ta_def dest: ftranclD ftranclD2)\n  by (meson fimageI finsert_iff finterI fr_into_trancl ftrancl_into_trancl)\n\nlemma \\<L>_eps_free_nhole_mctxt_closure_reg:\n  assumes \"is_ta_eps_free (ta \\<A>)\"\n  shows \"\\<L> (eps_free_nhole_mctxt_closure_reg \\<F> \\<A>) = \\<L> (nhole_mctxt_closure_reg \\<F> \\<A>)\" using assms\n  unfolding eps_free_nhole_mctxt_closure_reg_def Let_def\n  apply (intro \\<L>_eps_free_reg'I)\n  apply (auto simp: comp_def nhole_mctxt_closure_reg_def is_ta_eps_free_def Let_def\n    gen_nhole_mctxt_closure_reg_def reg_Restr_Q\\<^sub>f_def fmap_states_reg_def fmap_states_ta_def\n    gen_nhole_mctxt_closure_automaton_def reflcl_over_nhole_mctxt_ta_def ta_union_def\n    reflcl_over_nhole_ctxt_ta_def dest: ftranclD ftranclD2)\n  by (meson fimageI finsert_iff finterI fr_into_trancl ftrancl_into_trancl)\n\nfun rr1_of_rr1_rel_impl :: \"('f \\<times> nat) fset \\<Rightarrow> ('f :: linorder, 'v) fin_trs list \\<Rightarrow> ftrs rr1_rel \\<Rightarrow> (nat, 'f) reg option\"\nand rr2_of_rr2_rel_impl :: \"('f \\<times> nat) fset \\<Rightarrow> ('f, 'v) fin_trs list \\<Rightarrow> ftrs rr2_rel \\<Rightarrow> (nat, 'f option \\<times> 'f option) reg option\" where\n  \"rr1_of_rr1_rel_impl \\<F> Rs R1Terms = Some (relabel_reg (term_reg \\<F>))\"\n| \"rr1_of_rr1_rel_impl \\<F> Rs (R1NF is) = liftO1 (\\<lambda>R. (simplify_reg (nf_reg (fst |`| R) \\<F>))) (is_to_trs' Rs is)\"\n| \"rr1_of_rr1_rel_impl \\<F> Rs (R1Inf r) = liftO1 (\\<lambda>R.\n    let \\<A> = trim_reg R in\n    simplify_reg (proj_1_reg (Inf_reg_impl \\<A>))\n  ) (rr2_of_rr2_rel_impl \\<F> Rs r)\"\n| \"rr1_of_rr1_rel_impl \\<F> Rs (R1Proj i r) = (case i of 0 \\<Rightarrow>\n      liftO1 (trim_reg \\<circ> proj_1_reg) (rr2_of_rr2_rel_impl \\<F> Rs r)\n    | _ \\<Rightarrow> liftO1 (trim_reg \\<circ> proj_2_reg) (rr2_of_rr2_rel_impl \\<F> Rs r))\"\n| \"rr1_of_rr1_rel_impl \\<F> Rs (R1Union s1 s2) =\n    liftO2 (\\<lambda> x y. relabel_reg (reg_union x y)) (rr1_of_rr1_rel_impl \\<F> Rs s1) (rr1_of_rr1_rel_impl \\<F> Rs s2)\"\n| \"rr1_of_rr1_rel_impl \\<F> Rs (R1Inter s1 s2) =\n    liftO2 (\\<lambda> x y. simplify_reg (reg_intersect x y)) (rr1_of_rr1_rel_impl \\<F> Rs s1) (rr1_of_rr1_rel_impl \\<F> Rs s2)\"\n| \"rr1_of_rr1_rel_impl \\<F> Rs (R1Diff s1 s2) = liftO2 (\\<lambda> x y. relabel_reg (trim_reg (difference_reg x y))) (rr1_of_rr1_rel_impl \\<F> Rs s1) (rr1_of_rr1_rel_impl \\<F> Rs s2)\"\n\n| \"rr2_of_rr2_rel_impl \\<F> Rs (R2GTT_Rel g w x) =\n    (case w of PRoot \\<Rightarrow>\n      (case x of ESingle \\<Rightarrow> liftO1 (simplify_reg \\<circ> GTT_to_RR2_root_reg) (gtt_of_gtt_rel_impl \\<F> Rs g)\n        | EParallel \\<Rightarrow> liftO1 (simplify_reg \\<circ> reflcl_reg (lift_sig_RR2 |`| \\<F>) \\<circ> GTT_to_RR2_root_reg) (gtt_of_gtt_rel_impl \\<F> Rs g)\n        | EStrictParallel \\<Rightarrow> liftO1 (simplify_reg \\<circ> GTT_to_RR2_root_reg) (gtt_of_gtt_rel_impl \\<F> Rs g))\n      | PNonRoot \\<Rightarrow>\n      (case x of ESingle \\<Rightarrow> liftO1 (simplify_reg \\<circ> ftrancl_eps_free_reg \\<circ> nhole_ctxt_closure_reg (lift_sig_RR2 |`| \\<F>) \\<circ> GTT_to_RR2_root_reg) (gtt_of_gtt_rel_impl \\<F> Rs g)\n        | EParallel \\<Rightarrow> liftO1 (simplify_reg \\<circ> eps_free_nhole_mctxt_reflcl_reg (lift_sig_RR2 |`| \\<F>) \\<circ> GTT_to_RR2_root_reg) (gtt_of_gtt_rel_impl \\<F> Rs g)\n        | EStrictParallel \\<Rightarrow> liftO1 (simplify_reg \\<circ> eps_free_nhole_mctxt_closure_reg (lift_sig_RR2 |`| \\<F>) \\<circ> GTT_to_RR2_root_reg) (gtt_of_gtt_rel_impl \\<F> Rs g))\n      | PAny \\<Rightarrow>\n      (case x of ESingle \\<Rightarrow> liftO1 (simplify_reg \\<circ> ftrancl_eps_free_reg \\<circ> ctxt_closure_reg (lift_sig_RR2 |`| \\<F>) \\<circ> GTT_to_RR2_root_reg) (gtt_of_gtt_rel_impl \\<F> Rs g)\n        | EParallel \\<Rightarrow> liftO1 (simplify_reg \\<circ> ftrancl_eps_free_reg \\<circ> parallel_closure_reg (lift_sig_RR2 |`| \\<F>) \\<circ> GTT_to_RR2_root_reg) (gtt_of_gtt_rel_impl \\<F> Rs g)\n        | EStrictParallel \\<Rightarrow> liftO1 (simplify_reg \\<circ> eps_free_mctxt_closure_reg (lift_sig_RR2 |`| \\<F>) \\<circ> GTT_to_RR2_root_reg) (gtt_of_gtt_rel_impl \\<F> Rs g)))\"\n| \"rr2_of_rr2_rel_impl \\<F> Rs (R2Diag s) =\n    liftO1 (\\<lambda> x. fmap_funs_reg (\\<lambda>f. (Some f, Some f)) x) (rr1_of_rr1_rel_impl \\<F> Rs s)\"\n| \"rr2_of_rr2_rel_impl \\<F> Rs (R2Prod s1 s2) =\n    liftO2 (\\<lambda> x y. simplify_reg (pair_automaton_reg x y)) (rr1_of_rr1_rel_impl \\<F> Rs s1) (rr1_of_rr1_rel_impl \\<F> Rs s2)\"\n| \"rr2_of_rr2_rel_impl \\<F> Rs (R2Inv r) = liftO1 (fmap_funs_reg prod.swap) (rr2_of_rr2_rel_impl \\<F> Rs r)\"\n| \"rr2_of_rr2_rel_impl \\<F> Rs (R2Union r1 r2) =\n    liftO2 (\\<lambda> x y. relabel_reg (reg_union x y)) (rr2_of_rr2_rel_impl \\<F> Rs r1) (rr2_of_rr2_rel_impl \\<F> Rs r2)\"\n| \"rr2_of_rr2_rel_impl \\<F> Rs (R2Inter r1 r2) =\n    liftO2 (\\<lambda> x y. simplify_reg (reg_intersect x y)) (rr2_of_rr2_rel_impl \\<F> Rs r1) (rr2_of_rr2_rel_impl \\<F> Rs r2)\"\n| \"rr2_of_rr2_rel_impl \\<F> Rs (R2Diff r1 r2) = liftO2 (\\<lambda> x y. simplify_reg (difference_reg x y)) (rr2_of_rr2_rel_impl \\<F> Rs r1) (rr2_of_rr2_rel_impl \\<F> Rs r2)\"\n| \"rr2_of_rr2_rel_impl \\<F> Rs (R2Comp r1 r2) = liftO2 (\\<lambda> x y. simplify_reg (rr2_compositon \\<F> x y))\n     (rr2_of_rr2_rel_impl \\<F> Rs r1) (rr2_of_rr2_rel_impl \\<F> Rs r2)\"\n\nlemmas ta_simp_unfold = simplify_reg_def relabel_reg_def trim_reg_def relabel_ta_def term_reg_def\nlemma is_ta_eps_free_trim_reg [intro!]:\n  \"is_ta_eps_free (ta R) \\<Longrightarrow> is_ta_eps_free (ta (trim_reg R))\"\n  by (simp add: is_ta_eps_free_def trim_reg_def trim_ta_def ta_restrict_def)\n\nlemma is_ta_eps_free_relabel_reg [intro!]:\n  \"is_ta_eps_free (ta R) \\<Longrightarrow> is_ta_eps_free (ta (relabel_reg R))\"\n  by (simp add: is_ta_eps_free_def relabel_reg_def relabel_ta_def fmap_states_ta_def)\n\nlemma is_ta_eps_free_simplify_reg [intro!]:\n  \"is_ta_eps_free (ta R) \\<Longrightarrow> is_ta_eps_free (ta (simplify_reg R))\"\n  by (simp add: is_ta_eps_free_def ta_simp_unfold fmap_states_ta_def trim_ta_def ta_restrict_def)\n\nlemma is_ta_emptyI [simp]:\n \"is_ta_eps_free (TA R {||}) \\<longleftrightarrow> True\"\n  by (simp add: is_ta_eps_free_def)\n\nlemma is_ta_empty_trim_reg:\n  \"is_ta_eps_free (ta A) \\<Longrightarrow> eps (ta (trim_reg A)) = {||}\"\n  by (auto simp: is_ta_eps_free_def trim_reg_def trim_ta_def ta_restrict_def)\n\nlemma is_proj_ta_eps_empty:\n  \"is_ta_eps_free (ta R) \\<Longrightarrow> is_ta_eps_free (ta (proj_1_reg R))\"\n  \"is_ta_eps_free (ta R) \\<Longrightarrow> is_ta_eps_free (ta (proj_2_reg R))\"\n  by (auto simp: is_ta_eps_free_def proj_1_reg_def proj_2_reg_def collapse_automaton_reg_def collapse_automaton_def\n    fmap_funs_reg_def fmap_funs_ta_def trim_reg_def trim_ta_def ta_restrict_def)\n\nlemma is_pod_ta_eps_empty:\n  \"is_ta_eps_free (ta R) \\<Longrightarrow> is_ta_eps_free (ta L) \\<Longrightarrow> is_ta_eps_free (ta (reg_intersect R L))\"\n  by (auto simp: reg_intersect_def prod_ta_def prod_epsRp_def prod_epsLp_def is_ta_eps_free_def)\n\nlemma is_fmap_funs_reg_eps_empty:\n  \"is_ta_eps_free (ta R) \\<Longrightarrow>  is_ta_eps_free (ta (fmap_funs_reg f R))\"\n  by (auto simp: fmap_funs_reg_def fmap_funs_ta_def is_ta_eps_free_def)\n\nlemma is_collapse_automaton_reg_eps_empty:\n  \"is_ta_eps_free (ta R) \\<Longrightarrow>  is_ta_eps_free (ta (collapse_automaton_reg R))\"\n  by (auto simp: collapse_automaton_reg_def collapse_automaton_def is_ta_eps_free_def)\n\nlemma is_pair_automaton_reg_eps_empty:\n  \"is_ta_eps_free (ta R) \\<Longrightarrow> is_ta_eps_free (ta L) \\<Longrightarrow> is_ta_eps_free (ta (pair_automaton_reg R L))\"\n  by (auto simp: pair_automaton_reg_def pair_automaton_def is_ta_eps_free_def)\n\nlemma is_reflcl_automaton_eps_free:\n  \"is_ta_eps_free A \\<Longrightarrow> is_ta_eps_free (reflcl_automaton (lift_sig_RR2 |`| \\<F>) A)\"\n  by (auto simp: is_ta_eps_free_def reflcl_automaton_def ta_union_def gen_reflcl_automaton_def Let_def fmap_states_ta_def)\n\nlemma is_GTT_to_RR2_root_eps_empty:\n  \"is_gtt_eps_free \\<G> \\<Longrightarrow> is_ta_eps_free (GTT_to_RR2_root \\<G>)\"\n  by (auto simp: is_gtt_eps_free_def GTT_to_RR2_root_def pair_automaton_def is_ta_eps_free_def)\n\nlemma is_term_automata_eps_empty:\n  \"is_ta_eps_free (ta (term_reg \\<F>)) \\<longleftrightarrow> True\"\n  by (auto simp: is_ta_eps_free_def term_reg_def term_automaton_def)\n\nlemma is_ta_eps_free_eps_free_automata [simp]:\n  \" is_ta_eps_free (eps_free_automata S R) \\<longleftrightarrow> True\"\n  by (auto simp: eps_free_automata_def is_ta_eps_free_def)\n\nlemma rr2_of_rr2_rel_impl_eps_free:\n  shows \"\\<forall> A. rr1_of_rr1_rel_impl \\<F> Rs r1 = Some A \\<longrightarrow> is_ta_eps_free (ta A)\"\n   \"\\<forall> A. rr2_of_rr2_rel_impl \\<F> Rs r2 = Some A \\<longrightarrow> is_ta_eps_free (ta A)\"\nproof (induct r1 and r2)\ncase R1Terms\n  then show ?case\n    by (auto simp: is_ta_eps_free_def term_automaton_def fmap_states_ta_def ta_simp_unfold)\nnext\n  case (R1NF x)\n  then show ?case\n    by (auto simp: nf_reg_def nf_ta_def)\nnext\n  case (R1Inf x)\n  then show ?case\n    by (auto simp: Inf_reg_impl_def Let_def Inf_reg_def Inf_automata_def is_ta_empty_trim_reg intro!: is_proj_ta_eps_empty)\nnext\n  case (R1Proj n x2)\n  then show ?case\n    by (cases n) (auto  intro!: is_proj_ta_eps_empty)\nnext\n  case (R1Union x1 x2)\n  then show ?case\n    by (simp add: reg_union_def ta_union_def fmap_states_ta_def is_ta_eps_free_def relabel_reg_def relabel_ta_def)\nnext\n  case (R1Inter x1 x2)\n  then show ?case\n    by (auto intro: is_pod_ta_eps_empty)\nnext\n  case (R1Diff x1 x2)\n  then show ?case\n    by (auto simp: difference_reg_def Let_def complement_reg_def ps_reg_def ps_ta_def intro!: is_pod_ta_eps_empty)\nnext\n  case (R2GTT_Rel x1 x2 x3)\n  then show ?case \n    by (cases x2; cases x3) (auto simp: GTT_to_RR2_root_reg_def ftrancl_eps_free_closures_def\n      eps_free_nhole_mctxt_closure_reg_def eps_free_nhole_mctxt_reflcl_reg_def Let_def\n      eps_free_mctxt_closure_reg_def reflcl_reg_def\n      dest: gtt_of_gtt_rel_impl_is_gtt_eps_free\n      intro!: is_GTT_to_RR2_root_eps_empty is_reflcl_automaton_eps_free)\nnext\n  case (R2Diag x)\n  then show ?case by (auto simp: fmap_funs_reg_def fmap_funs_ta_def is_ta_eps_free_def)\nnext\n  case (R2Prod x1 x2)\n  then show ?case by (auto intro: is_pair_automaton_reg_eps_empty)\nnext\n  case (R2Inv x)\n  then show ?case by (auto simp: fmap_funs_reg_def fmap_funs_ta_def is_ta_eps_free_def)\nnext\n  case (R2Union x1 x2)\n  then show ?case by (simp add: reg_union_def ta_union_def fmap_states_ta_def is_ta_eps_free_def relabel_reg_def relabel_ta_def)\nnext\n  case (R2Inter x1 x2)\n  then show ?case by (auto intro: is_pod_ta_eps_empty)\nnext\n  case (R2Diff x1 x2)\n  then show ?case by (auto simp: difference_reg_def Let_def complement_reg_def ps_reg_def ps_ta_def intro!: is_pod_ta_eps_empty)\nnext\n  case (R2Comp x1 x2)\n  then show ?case by (auto simp: is_term_automata_eps_empty rr2_compositon_def Let_def\n     intro!: is_pod_ta_eps_empty is_fmap_funs_reg_eps_empty is_collapse_automaton_reg_eps_empty is_pair_automaton_reg_eps_empty)\nqed\n\nlemma rr_of_rr_rel_impl_complete:\n  \"rr1_of_rr1_rel_impl \\<F> Rs r1 \\<noteq> None \\<longleftrightarrow> rr1_of_rr1_rel \\<F> Rs r1 \\<noteq> None\"\n  \"rr2_of_rr2_rel_impl \\<F> Rs r2 \\<noteq> None \\<longleftrightarrow> rr2_of_rr2_rel \\<F> Rs r2 \\<noteq> None\"\nproof (induct r1 and r2)\n  case (R1Proj n x2)\n  then show ?case by (cases n) auto\nnext\n  case (R2GTT_Rel x1 n p)\n  then show ?case using gtt_of_gtt_rel_impl_gtt_of_gtt_rel[of \\<F> Rs]\n    by (cases p; cases n) auto\nqed auto\n\nlemma \\<Q>_fmap_funs_reg [simp]:\n  \"\\<Q>\\<^sub>r (fmap_funs_reg f \\<A>) = \\<Q>\\<^sub>r \\<A>\"\n  by (auto simp: fmap_funs_reg_def)\n\nlemma ta_reachable_fmap_funs_reg [simp]:\n  \"ta_reachable (ta (fmap_funs_reg f \\<A>)) = ta_reachable (ta \\<A>)\"\n  by (auto simp: fmap_funs_reg_def)\n\nlemma collapse_reg_cong:\n  \"\\<Q>\\<^sub>r \\<A> |\\<subseteq>| ta_reachable (ta \\<A>) \\<Longrightarrow> \\<Q>\\<^sub>r \\<B> |\\<subseteq>| ta_reachable (ta \\<B>) \\<Longrightarrow> \\<L> \\<A> = \\<L> \\<B> \\<Longrightarrow> \\<L> (collapse_automaton_reg \\<A>) = \\<L> (collapse_automaton_reg \\<B>)\"\n  by (auto simp: collapse_automaton_reg_def \\<L>_def collapse_automaton')\n\nlemma \\<L>_fmap_funs_reg_cong:\n  \"\\<L> \\<A> = \\<L> \\<B> \\<Longrightarrow> \\<L> (fmap_funs_reg h \\<A>) = \\<L> (fmap_funs_reg h \\<B>)\"\n  by (auto simp: fmap_funs_\\<L>)\n\nlemma \\<L>_pair_automaton_reg_cong:\n  \"\\<L> \\<A> = \\<L> \\<B> \\<Longrightarrow> \\<L> \\<C> = \\<L> \\<D> \\<Longrightarrow> \\<L> (pair_automaton_reg \\<A> \\<C>) = \\<L> (pair_automaton_reg \\<B> \\<D>)\"\n  by (auto simp: pair_automaton')\n\nlemma \\<L>_nhole_ctxt_closure_reg_cong:\n  \"\\<L> \\<A> = \\<L> \\<B> \\<Longrightarrow> \\<F> = \\<G> \\<Longrightarrow> \\<L> (nhole_ctxt_closure_reg \\<F> \\<A>) = \\<L> (nhole_ctxt_closure_reg \\<G> \\<B>)\"\n  by (auto simp: nhole_ctxtcl_lang)\n\nlemma \\<L>_nhole_mctxt_closure_reg_cong:\n  \"\\<L> \\<A> = \\<L> \\<B> \\<Longrightarrow> \\<F> = \\<G> \\<Longrightarrow> \\<L> (nhole_mctxt_closure_reg \\<F> \\<A>) = \\<L> (nhole_mctxt_closure_reg \\<G> \\<B>)\"\n  by (auto simp: nhole_gmctxt_closure_lang)\n\nlemma \\<L>_ctxt_closure_reg_cong:\n  \"\\<L> \\<A> = \\<L> \\<B> \\<Longrightarrow> \\<F> = \\<G> \\<Longrightarrow> \\<L> (ctxt_closure_reg \\<F> \\<A>) = \\<L> (ctxt_closure_reg \\<G> \\<B>)\"\n  by (auto simp: gctxt_closure_lang)\n\nlemma \\<L>_parallel_closure_reg_cong:\n  \"\\<L> \\<A> = \\<L> \\<B> \\<Longrightarrow> \\<F> = \\<G> \\<Longrightarrow> \\<L> (parallel_closure_reg \\<F> \\<A>) = \\<L> (parallel_closure_reg \\<G> \\<B>)\"\n  by (auto simp: parallelcl_gmctxt_lang)\n\nlemma \\<L>_mctxt_closure_reg_cong:\n  \"\\<L> \\<A> = \\<L> \\<B> \\<Longrightarrow> \\<F> = \\<G> \\<Longrightarrow> \\<L> (mctxt_closure_reg \\<F> \\<A>) = \\<L> (mctxt_closure_reg \\<G> \\<B>)\"\n  by (auto simp: gmctxt_closure_lang)\n\nlemma \\<L>_nhole_mctxt_reflcl_reg_cong:\n  \"\\<L> \\<A> = \\<L> \\<B> \\<Longrightarrow> \\<F> = \\<G> \\<Longrightarrow> \\<L> (nhole_mctxt_reflcl_reg \\<F> \\<A>) = \\<L> (nhole_mctxt_reflcl_reg \\<G> \\<B>)\"\n  unfolding nhole_mctxt_reflcl_lang\n  by (intro arg_cong2[where ?f = \"(\\<union>)\"] \\<L>_nhole_mctxt_closure_reg_cong) auto\n\ndeclare equalityI[rule del]\ndeclare fsubsetI[rule del]\nlemma \\<L>_proj_1_reg_cong:\n  \"\\<L> \\<A> = \\<L> \\<B> \\<Longrightarrow> \\<L> (proj_1_reg \\<A>) = \\<L> (proj_1_reg \\<B>)\"\n  by (auto simp: proj_1_reg_def \\<L>_trim intro!: collapse_reg_cong \\<L>_fmap_funs_reg_cong)\n\nlemma \\<L>_proj_2_reg_cong:\n  \"\\<L> \\<A> = \\<L> \\<B> \\<Longrightarrow> \\<L> (proj_2_reg \\<A>) = \\<L> (proj_2_reg \\<B>)\"\n  by (auto simp: proj_2_reg_def \\<L>_trim intro!: collapse_reg_cong \\<L>_fmap_funs_reg_cong)\n\nlemma rr2_of_rr2_rel_impl_sound:\n  assumes  \"\\<forall>R \\<in> set Rs. lv_trs (fset R) \\<and> ffunas_trs R |\\<subseteq>| \\<F>\"\n  shows \"\\<And> A B. rr1_of_rr1_rel_impl \\<F> Rs r1 = Some A \\<Longrightarrow> rr1_of_rr1_rel \\<F> Rs r1 = Some B \\<Longrightarrow> \\<L> A = \\<L> B\"\n  \"\\<And> A B. rr2_of_rr2_rel_impl \\<F> Rs r2 = Some A \\<Longrightarrow> rr2_of_rr2_rel \\<F> Rs r2 = Some B \\<Longrightarrow> \\<L> A = \\<L> B\"\nproof (induct r1 and r2)\n  case (R1Inf r)\n  then obtain C D where inf: \"rr2_of_rr2_rel_impl \\<F> Rs r = Some C\" \"rr2_of_rr2_rel \\<F> Rs r = Some D\"\n     \"\\<L> C = \\<L> D\" by auto\n  have spec: \"RR2_spec C (eval_rr2_rel (fset \\<F>) (map fset Rs) r)\" \"RR2_spec D (eval_rr2_rel (fset \\<F>) (map fset Rs) r)\"\n    using rr12_of_rr12_rel_correct(2)[OF assms, rule_format, OF inf(2)] inf(3)\n    by (auto simp: RR2_spec_def)\n  then have trim_spec: \"RR2_spec (trim_reg C) (eval_rr2_rel (fset \\<F>) (map fset Rs) r)\"\n    \"RR2_spec (trim_reg D) (eval_rr2_rel (fset \\<F>) (map fset Rs) r)\"\n    by (auto simp: RR2_spec_def \\<L>_trim)\n  let ?C = \"Inf_reg (trim_reg C) (Q_infty (ta (trim_reg C)) \\<F>)\" let ?D = \"Inf_reg (trim_reg D) (Q_infty (ta (trim_reg D)) \\<F>)\" \n  from spec have *: \"\\<L> (Inf_reg_impl (trim_reg C)) = \\<L> ?C\"\n    using eval_rr12_rel_sig(2)[of \"fset \\<F>\" \"map fset Rs\" r]\n    by (intro Inf_reg_impl_sound) (auto simp: RR2_spec_def \\<L>_trim \\<T>\\<^sub>G_equivalent_def)\n  from spec have **: \"\\<L> (Inf_reg_impl (trim_reg D)) = \\<L> ?D\"\n    using eval_rr12_rel_sig(2)[of \"fset \\<F>\" \"map fset Rs\" r]\n    by (intro Inf_reg_impl_sound) (auto simp: RR2_spec_def \\<L>_trim \\<T>\\<^sub>G_equivalent_def)\n  then have C: \"RR2_spec ?C {(s, t) | s t. gpair s t \\<in> \\<L> ?C}\" and\n    D: \"RR2_spec ?D {(s, t) | s t. gpair s t \\<in> \\<L> ?D}\"\n    using subset_trans[OF Inf_automata_subseteq[of \"trim_reg C\" \\<F>], of \"\\<L> C\"] spec\n    using subset_trans[OF Inf_automata_subseteq[of \"trim_reg D\" \\<F>], of \"\\<L> D\"]\n    using eval_rr12_rel_sig(2)[of \"fset \\<F>\" \"map fset Rs\" r]\n    by (auto simp: RR2_spec_def \\<L>_trim \\<T>\\<^sub>G_equivalent_def intro!: equalityI fsubsetI)\n  from * ** have r: \"\\<L> (proj_1_reg (Inf_reg_impl (trim_reg C))) = \\<L> (proj_1_reg ?C)\"\n    \"\\<L> (proj_1_reg (Inf_reg_impl (trim_reg D))) = \\<L> (proj_1_reg ?D)\"\n    by (auto intro: \\<L>_proj_1_reg_cong)\n  from \\<L>_Inf_reg[OF trim_spec(1), of \\<F>] \\<L>_Inf_reg[OF trim_spec(2), of \\<F>]\n  show ?case using R1Inf eval_rr12_rel_sig(2)[of \"fset \\<F>\" \"map fset Rs\" r]\n    by (auto simp: liftO1_def r inf \\<T>\\<^sub>G_equivalent_def \\<L>_proj(1)[OF C] \\<L>_proj(1)[OF D])\nnext\n  case (R1Proj n x2)\n  then show ?case by (cases n)\n    (auto simp: liftO1_def \\<L>_trim proj_1_reg_def proj_2_reg_def intro!: fsubsetI \\<L>_fmap_funs_reg_cong collapse_reg_cong, (meson fin_mono trim_reg_reach)+)\nnext\n  case (R2GTT_Rel g p n) note IH = this\n  note ass = R2GTT_Rel\n  consider (a) \"\\<exists> A. gtt_of_gtt_rel_impl \\<F> Rs g = Some A\" | (b) \"gtt_of_gtt_rel_impl \\<F> Rs g = None\" by blast\n  then show ?case\n  proof cases\n    case a then obtain C D where gtt [simp]: \"gtt_of_gtt_rel_impl \\<F> Rs g = Some C\"\n      \"gtt_of_gtt_rel \\<F> Rs g = Some D\" using gtt_of_gtt_rel_impl_gtt_of_gtt_rel by blast\n    from gtt_of_gtt_rel_impl_sound[OF this]\n    have spec [simp]: \"agtt_lang C = agtt_lang D\" by auto\n    have eps [simp]: \"is_ta_eps_free (ta (GTT_to_RR2_root_reg C))\"\n      using gtt_of_gtt_rel_impl_is_gtt_eps_free[OF gtt(1)]\n      by (auto simp: GTT_to_RR2_root_reg_def GTT_to_RR2_root_def pair_automaton_def is_ta_eps_free_def is_gtt_eps_free_def)\n    have lang: \"\\<L> (GTT_to_RR2_root_reg C) = \\<L> (GTT_to_RR2_root_reg D)\"\n      by (metis (no_types, lifting) GTT_to_RR2_root RR2_spec_def spec)\n    show ?thesis\n    proof (cases p)\n      case PRoot\n      then show ?thesis using IH spec lang\n        by (cases n) (auto simp: \\<L>_eps_free \\<L>_reflcl_reg)\n    next\n      case PNonRoot\n      then show ?thesis using IH\n        by (cases n) (auto simp: \\<L>_eps_free \\<L>_eps_free_nhole_ctxt_closure_reg[OF eps]\n        \\<L>_eps_free_nhole_mctxt_reflcl_reg[OF eps] \\<L>_eps_free_nhole_mctxt_closure_reg[OF eps]\n        lang intro: \\<L>_nhole_ctxt_closure_reg_cong \\<L>_nhole_mctxt_reflcl_reg_cong \\<L>_nhole_mctxt_closure_reg_cong)\n    next\n      case PAny\n      then show ?thesis using IH\n        by (cases n) (auto simp: \\<L>_eps_free \\<L>_eps_free_ctxt_closure_reg[OF eps]\n          \\<L>_eps_free_parallel_closure_reg[OF eps] \\<L>_eps_free_mctxt_closure_reg[OF eps] lang\n          intro!: \\<L>_ctxt_closure_reg_cong \\<L>_parallel_closure_reg_cong \\<L>_mctxt_closure_reg_cong)\n    qed\n  next\n    case b then show ?thesis using IH\n      by (cases p; cases n) auto\n  qed\nnext\n  case (R2Comp x1 x2)\n  then show ?case\n    by (auto simp: liftO1_def rr2_compositon_def \\<L>_trim \\<L>_intersect Let_def\n        intro!: \\<L>_pair_automaton_reg_cong \\<L>_fmap_funs_reg_cong collapse_reg_cong arg_cong2[where ?f = \"(\\<inter>)\"])\nqed (auto simp: liftO1_def \\<L>_intersect \\<L>_union \\<L>_trim \\<L>_difference_reg intro!: \\<L>_fmap_funs_reg_cong \\<L>_pair_automaton_reg_cong)\ndeclare equalityI[intro!]\ndeclare fsubsetI[intro!]\n\nlemma rr12_of_rr12_rel_impl_correct:\n  assumes  \"\\<forall>R \\<in> set Rs. lv_trs (fset R) \\<and> ffunas_trs R |\\<subseteq>| \\<F>\"\n  shows \"\\<forall>ta1. rr1_of_rr1_rel_impl \\<F> Rs r1 = Some ta1 \\<longrightarrow> RR1_spec ta1 (eval_rr1_rel (fset \\<F>) (map fset Rs) r1)\"\n    \"\\<forall>ta2. rr2_of_rr2_rel_impl \\<F> Rs r2 = Some ta2 \\<longrightarrow> RR2_spec ta2 (eval_rr2_rel (fset \\<F>) (map fset Rs) r2)\"\n  using rr12_of_rr12_rel_correct(1)[OF assms, of r1]\n  using rr12_of_rr12_rel_correct(2)[OF assms, of r2]\n  using rr2_of_rr2_rel_impl_sound(1)[OF assms, of r1]\n  using rr2_of_rr2_rel_impl_sound(2)[OF assms, of r2]\n  using rr_of_rr_rel_impl_complete(1)[of \\<F> Rs r1]\n  using rr_of_rr_rel_impl_complete(2)[of \\<F> Rs r2]\n  by (force simp: RR1_spec_def RR2_spec_def)+\n\nlemma check_inference_rrn_impl_correct:\n  assumes sig: \"\\<T>\\<^sub>G (fset \\<F>) \\<noteq> {}\" and Rs: \"\\<forall>R \\<in> set Rs. lv_trs (fset R) \\<and> ffunas_trs R |\\<subseteq>| \\<F>\"\n  assumes infs: \"\\<And>fvA. fvA \\<in> set infs \\<Longrightarrow> formula_spec (fset \\<F>) (map fset Rs) (fst (snd fvA)) (snd (snd fvA)) (fst fvA)\"\n  assumes inf: \"check_inference rr1_of_rr1_rel_impl rr2_of_rr2_rel_impl \\<F> Rs infs (l, step, fm, is) = Some (fm', vs, A')\"\n  shows \"l = length infs \\<and> fm = fm' \\<and> formula_spec (fset \\<F>) (map fset Rs) vs A' fm'\"\n  using check_inference_correct[where ?rr1c = rr1_of_rr1_rel_impl and ?rr2c = rr2_of_rr2_rel_impl, OF assms]\n  using rr12_of_rr12_rel_impl_correct[OF Rs]\n  by auto\n\ndefinition check_sig_nempty where\n  \"check_sig_nempty \\<F> = (0 |\\<in>| snd |`| \\<F>)\"\n\ndefinition check_trss where\n  \"check_trss \\<R> \\<F> = list_all (\\<lambda> R. lv_trs (fset R) \\<and> funas_trs (fset R) \\<subseteq> fset \\<F>) \\<R>\"\n\nlemma check_sig_nempty:\n  \"check_sig_nempty \\<F> \\<longleftrightarrow> \\<T>\\<^sub>G (fset \\<F>) \\<noteq> {}\" (is \"?Ls \\<longleftrightarrow> ?Rs\")\nproof -\n  {assume ?Ls then obtain a where \"(a, 0) |\\<in>| \\<F>\" by (auto simp: check_sig_nempty_def)\n    then have \"GFun a [] \\<in> \\<T>\\<^sub>G (fset \\<F>)\"\n      by (intro const) (simp add: fmember_iff_member_fset)\n    then have ?Rs by blast}\n  moreover\n  {assume ?Rs then obtain s where \"s \\<in> \\<T>\\<^sub>G (fset \\<F>)\" by blast\n    then obtain a where \"(a, 0) |\\<in>| \\<F>\" unfolding fmember_iff_member_fset\n      by (induct s) (auto, force)\n    then have ?Ls unfolding check_sig_nempty_def\n      by (auto simp: fimage_iff fBex_def)}\n  ultimately show ?thesis by blast\nqed\n\nlemma check_trss:\n  \"check_trss \\<R> \\<F> \\<longleftrightarrow> (\\<forall> R \\<in> set \\<R>. lv_trs (fset R) \\<and> ffunas_trs R |\\<subseteq>| \\<F>)\"\n  unfolding check_trss_def list_all_iff\n  by (auto simp: fmember_iff_member_fset ffunas_trs.rep_eq less_eq_fset.rep_eq)\n\nfun check_inference_list :: \"('f \\<times> nat) fset \\<Rightarrow> ('f ::  {compare,linorder}, 'v) fin_trs list\n  \\<Rightarrow> (nat \\<times> ftrs inference \\<times> ftrs formula \\<times> info list) list\n  \\<Rightarrow> (ftrs formula \\<times> nat list \\<times> (nat, 'f option list) reg) list option\" where\n  \"check_inference_list \\<F> Rs infs = do {\n     guard (check_sig_nempty \\<F>);\n     guard (check_trss Rs \\<F>);\n     foldl (\\<lambda> tas inf. do {\n        tas' \\<leftarrow> tas;\n        r \\<leftarrow> check_inference rr1_of_rr1_rel_impl rr2_of_rr2_rel_impl \\<F> Rs tas' inf;\n        Some (tas' @ [r])\n      })\n      (Some []) infs\n  }\"\n\nlemma check_inference_list_correct:\n  assumes \"check_inference_list \\<F> Rs infs = Some fvAs\"\n  shows \"length infs = length fvAs \\<and> (\\<forall> i < length fvAs. fst (snd (snd (infs ! i))) = fst (fvAs ! i)) \\<and>\n   (\\<forall> i < length fvAs. formula_spec (fset \\<F>) (map fset Rs) (fst (snd (fvAs ! i))) (snd (snd (fvAs ! i))) (fst (fvAs ! i)))\"\n  using assms\nproof (induct infs arbitrary: fvAs rule: rev_induct)\n  note [simp] = bind_eq_Some_conv guard_simps\n  {case Nil\n    then show ?case by auto\n  next\n    case (snoc a infs)\n    have inv: \"\\<T>\\<^sub>G (fset \\<F>) \\<noteq> {}\" \"\\<forall>R\\<in>set Rs. lv_trs (fset R) \\<and> ffunas_trs R |\\<subseteq>| \\<F>\"\n      using snoc(2) by (auto simp: check_sig_nempty check_trss)\n    from snoc(2) obtain fvAs' l steps fm fm' is' vs A' where\n      ch: \"check_inference_list \\<F> Rs infs = Some fvAs'\" \"a = (l, steps, fm, is')\"\n      \"check_inference rr1_of_rr1_rel_impl rr2_of_rr2_rel_impl \\<F> Rs fvAs' (l, steps, fm, is') = Some (fm', vs, A')\" \"fvAs = fvAs' @ [(fm', vs, A')]\"\n      by (auto simp del: check_inference.simps) (metis prod_cases4)\n    from snoc(1)[OF ch(1)] have \"fvA \\<in> set fvAs' \\<Longrightarrow> formula_spec (fset \\<F>) (map fset Rs) (fst (snd fvA)) (snd (snd fvA)) (fst fvA)\" for fvA\n      by (auto dest: in_set_idx)\n    from check_inference_rrn_impl_correct[OF inv this, of fvAs'] this\n    show ?case using snoc(1)[OF ch(1)] ch\n      by (auto simp del: check_inference.simps simp: nth_append)\n  }\nqed\n\nfun check_certificate where\n  \"check_certificate \\<F> Rs A fm (Certificate infs claim n) = do {\n    guard (n < length infs);\n    guard (A \\<longleftrightarrow> claim = Nonempty);\n    guard (fm = fst (snd (snd (infs ! n))));\n    fvA \\<leftarrow> check_inference_list \\<F> Rs (take (Suc n) infs);\n    (let E = reg_empty (snd (snd (last fvA))) in\n     case claim of Empty \\<Rightarrow> Some E\n       | _ \\<Rightarrow> Some (\\<not> E))\n  }\"\n\ndefinition formula_unsatisfiable where\n  \"formula_unsatisfiable \\<F> Rs fm \\<longleftrightarrow> (formula_satisfiable \\<F> Rs fm = False)\"\n\ndefinition correct_certificate where\n  \"correct_certificate \\<F> Rs claim infs n \\<equiv>\n    (claim = Empty \\<longleftrightarrow> (formula_unsatisfiable (fset \\<F>) (map fset Rs) (fst (snd (snd (infs ! n))))) \\<and>\n     claim = Nonempty \\<longleftrightarrow> formula_satisfiable (fset \\<F>) (map fset Rs) (fst (snd (snd (infs ! n)))))\"\n\nlemma check_certificate_sound:\n  assumes \"check_certificate \\<F> Rs A fm (Certificate infs claim n) = Some B\"\n  shows \"fm = fst (snd (snd (infs ! n)))\" \"A \\<longleftrightarrow> claim = Nonempty\"\n  using assms by (auto simp: bind_eq_Some_conv guard_simps)\n\nlemma check_certificate_correct:\n  assumes \"check_certificate \\<F> Rs A fm (Certificate infs claim n) = Some B\"\n  shows \"(B = True \\<longrightarrow> correct_certificate \\<F> Rs claim infs n) \\<and>\n    (B = False \\<longrightarrow> correct_certificate \\<F> Rs (case_claim Nonempty Empty claim) infs n)\"\nproof -\n  note [simp] = bind_eq_Some_conv guard_simps\n  from assms obtain fvAs where inf: \"check_inference_list \\<F> Rs (take (Suc n) infs) = Some fvAs\"\n    by auto\n  from assms have len: \"n < length infs\" by auto\n  from check_inference_list_correct[OF inf] have\n    inv: \"length fvAs = n + 1\"\n    \"fst (snd (snd (infs ! n))) = fst (fvAs ! n)\"\n    \"formula_spec (fset \\<F>) (map fset Rs) (fst (snd (last fvAs))) (snd (snd (last fvAs))) (fst (last fvAs))\"\n    using len last_conv_nth[of fvAs] by force+\n  have nth: \"fst (last fvAs) = fst (fvAs ! n)\" using inv(1)\n    using len last_conv_nth[of fvAs] by force\n  note spec = formula_spec_empty[OF _ inv(3)] formula_spec_nt_empty_form_sat[OF _ inv(3)]\n  consider (a) \"claim = Empty\" | (b) \"claim = Nonempty\" using claim.exhaust by blast\n  then show ?thesis\n  proof cases\n    case a\n    then have *: \"B = reg_empty (snd (snd (last fvAs)))\" using inv\n      using assms len last_conv_nth[of fvAs]\n      by (auto simp: inf simp del: check_inference_list.simps)\n    show ?thesis using a inv spec unfolding *\n      by (auto simp: formula_satisfiable_def nth correct_certificate_def formula_unsatisfiable_def simp del: reg_empty)\n  next\n    case b\n    then have *: \"B \\<longleftrightarrow> \\<not> (reg_empty (snd (snd (last fvAs))))\" using inv\n      using assms len last_conv_nth[of fvAs]\n      by (auto simp: inf simp del: check_inference_list.simps)\n    show ?thesis using b inv spec unfolding *\n      by (auto simp: formula_satisfiable_def nth formula_unsatisfiable_def correct_certificate_def simp del: reg_empty)\n  qed\nqed\n\n\ndefinition check_certificate_string ::\n  \"(integer list \\<times> fvar) fset \\<Rightarrow>\n   ((integer list, integer list) Term.term \\<times> (integer list, integer list) Term.term) fset list \\<Rightarrow>\n   bool \\<Rightarrow> ftrs formula \\<Rightarrow> ftrs certificate \\<Rightarrow> bool option\"\n  where \"check_certificate_string = check_certificate\"\n\n\n(***********************************)\nexport_code check_certificate_string Var Fun fset_of_list nat_of_integer Certificate\n  R2GTT_Rel R2Eq R2Reflc R2Step R2StepEq R2Steps R2StepsEq R2StepsNF R2ParStep R2RootStep\n  R2RootStepEq R2RootSteps R2RootStepsEq R2NonRootStep R2NonRootStepEq R2NonRootSteps\n  R2NonRootStepsEq R2Meet R2Join\n  ARoot GSteps PRoot ESingle Empty Size EDistribAndOr\n  R1Terms R1Fin\n  FRR1 FRestrict FTrue FFalse\n  IRR1 Fwd in Haskell module_name FOR\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/FO_Theory_Rewriting/FOR_Check_Impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5195213219520929, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.25773132209900823}}
{"text": "theory Sep_Generic_Wp\nimports \n  \"../lib/Sep_Algebra_Add\" \n  \"../lib/Frame_Infer\"\n  \"../lib/Monad\"\n  \"HOL-Library.Extended_Nat\" (* TODO: This gives us Complex_Main. Too much for this theory! *)\n  \"../basic/kernel/LLVM_Shallow\" (* TODO: Just used for acostC datatype. Move this datatype! *)\n  \"../cost/Enat_Cost\"\nbegin\n\n\n  (* TODO: Move, to Sep_Lift *)  \n  text \\<open>Lifting Assertions over Product\\<close>\n  definition FST :: \"('a \\<Rightarrow> bool) \\<Rightarrow> 'a \\<times> 'b::zero \\<Rightarrow> bool\" \n    where \"FST P \\<equiv> \\<lambda>(a,b). P a \\<and> b=0\"\n  \n  definition SND :: \"('b \\<Rightarrow> bool) \\<Rightarrow> 'a::zero \\<times> 'b \\<Rightarrow> bool\" \n    where \"SND P \\<equiv> \\<lambda>(a,b). a=0 \\<and> P b\"\n    \n  \n  lemma FST_project_frame: \"(FST P \\<and>* F) (a, b) \\<longleftrightarrow> (P ** (\\<lambda>a. F (a,b))) a\"\n    unfolding sep_conj_def\n    by (force simp add: sep_algebra_simps FST_def) \n\n  lemma SND_project_frame: \"(SND P \\<and>* F) (a, b) \\<longleftrightarrow> (P ** (\\<lambda>b. F (a,b))) b\"\n    unfolding sep_conj_def\n    by (force simp add: sep_algebra_simps SND_def) \n    \n        \n  lemma FST_conj_conv: \"(FST P ** FST Q) = FST (P**Q)\"  \n    unfolding sep_conj_def\n    by (force simp add: sep_algebra_simps FST_def) \n\n  lemma SND_conj_conv: \"(SND P ** SND Q) = SND (P**Q)\"  \n    unfolding sep_conj_def\n    by (force simp add: sep_algebra_simps SND_def) \n    \n        \n  lemma FST_apply[sep_algebra_simps]: \"FST P (a,b) \\<longleftrightarrow> P a \\<and> b=0\"\n    unfolding FST_def by auto\n    \n  lemma SND_apply[sep_algebra_simps]: \"SND P (a,b) \\<longleftrightarrow> P b \\<and> a=0\"\n    unfolding SND_def by auto\n\n\n\ndeclare [[coercion_enabled = false]]\nhide_const (open) Transcendental.pi\n\n\nsection \\<open>General VCG Setup for Separation Logic\\<close>\n\n(* TODO: Move to Library *)\n\nlocale generic_wp_defs =\n  fixes wp :: \"'c \\<Rightarrow> ('r \\<Rightarrow> 's \\<Rightarrow> bool) \\<Rightarrow> 's \\<Rightarrow> bool\"\nbegin\n  definition \"htripleF \\<alpha> F P c Q \\<equiv> (\\<forall>s. (P**F) (\\<alpha> s) \\<longrightarrow>\n      wp c (\\<lambda>r s'. (Q r ** F) (\\<alpha> s')) s)\"\n\n  definition \"htriple \\<alpha> P c Q \\<equiv> (\\<forall>F s. (P**F) (\\<alpha> s) \\<longrightarrow>\n      wp c (\\<lambda>r s'. (Q r ** F) (\\<alpha> s')) s)\"\n\n  lemma htriple_as_F_eq: \"htriple \\<alpha> P c Q = (\\<forall>F. htripleF \\<alpha> F P c Q)\"    \n    unfolding htriple_def htripleF_def by blast\n      \nend\n\n\nlocale generic_wp = generic_wp_defs wp\n  for wp :: \"'c \\<Rightarrow> ('r \\<Rightarrow> 's \\<Rightarrow> bool) \\<Rightarrow> 's \\<Rightarrow> bool\" +\n  assumes wp_comm_inf: \"inf (wp c Q) (wp c Q') = wp c (inf Q Q')\"\nbegin\n\n  lemma wp_comm_conj: \"wp c (\\<lambda>r. Q r and Q' r) s \\<longleftrightarrow> wp c Q s \\<and> wp c Q' s\"\n    using wp_comm_inf[of c Q Q']\n    unfolding inf_fun_def inf_bool_def by metis\n\n  lemma wp_comm_conjI: \"\\<lbrakk> wp c Q s; wp c Q' s \\<rbrakk> \\<Longrightarrow> wp c (\\<lambda>r s. Q r s \\<and> Q' r s) s\"\n    using wp_comm_inf[of c Q Q']\n    unfolding inf_fun_def inf_bool_def by metis\n\n\n  lemma wp_mono: \"Q\\<le>Q' \\<Longrightarrow> wp c Q \\<le> wp c Q'\"\n    by (metis (mono_tags) antisym_conv le_inf_iff order_refl wp_comm_inf)\n\n  lemma wp_monoI:\n    assumes \"wp c Q s\"\n    assumes \"\\<And>r x. Q r x \\<Longrightarrow> Q' r x\"\n    shows \"wp c Q' s\"\n    using assms wp_mono[of Q Q' c] by auto\n      \n  lemma htripleI:     \n    assumes \"\\<And>F s. (P**F) (\\<alpha> s) \\<Longrightarrow> wp c (\\<lambda>r s'. (Q r ** F) (\\<alpha> s')) s\"\n    shows \"htriple \\<alpha> P c Q\"\n    using assms by (auto simp: htriple_def)\n\n  lemma htripleFI:     \n    assumes \"\\<And>s. (P**F) (\\<alpha> s) \\<Longrightarrow> wp c (\\<lambda>r s'. (Q r ** F) (\\<alpha> s')) s\"\n    shows \"htripleF \\<alpha> F P c Q\"\n    using assms by (auto simp: htripleF_def)\n        \n  lemma htripleD:  \n    assumes \"htriple \\<alpha> P c Q\"\n    assumes \"(P**F) (\\<alpha> s)\"\n    shows \"wp c (\\<lambda>r s'. (Q r ** F) (\\<alpha> s')) s\"\n    using assms by (auto simp: htriple_def)\n    \n  lemma htriple_triv[simp, intro!]: \"htriple \\<alpha> sep_false c Q\"\n    by (auto simp: htriple_def)\n      \n  lemma frame_rule: \"htriple \\<alpha> P c Q \\<Longrightarrow> htriple \\<alpha> (P ** F) c (\\<lambda>r. Q r ** F)\"\n    unfolding htriple_def\n    by (fastforce)\n\n  lemma cons_rule:\n    assumes \"htriple \\<alpha> P c Q\"\n    assumes \"\\<And>s. P' s \\<Longrightarrow> P s\"\n    assumes \"\\<And>r s. Q r s \\<Longrightarrow> Q' r s\"\n    shows \"htriple \\<alpha> P' c Q'\"\n    unfolding htriple_def\n  proof clarsimp\n    fix F s\n    assume \"(P' \\<and>* F) (\\<alpha> s)\"\n    with assms(2) have \"(P \\<and>* F) (\\<alpha> s)\"\n      using sep_conj_impl1 by blast\n    with assms(1) have \"wp c (\\<lambda>r s'. (Q r \\<and>* F) (\\<alpha> s')) s\"\n      unfolding htriple_def by auto\n    thus \"wp c (\\<lambda>r s'. (Q' r \\<and>* F) (\\<alpha> s')) s\"\n      apply (rule wp_monoI)\n      using assms(3)\n      using sep_conj_impl1 by blast\n  qed\n\n  lemma cons_post_rule:\n    assumes \"htriple \\<alpha> P c Q\"\n    assumes \"\\<And>r s. Q r s \\<Longrightarrow> Q' r s\"\n    shows \"htriple \\<alpha> P c Q'\"\n    using cons_rule assms by blast\n  \n  \n  lemma htriple_alt:\n    \"htriple \\<alpha> P c Q \n      = (\\<forall>p s f. p##f \\<and> \\<alpha> s = p + f \\<and> P p \\<longrightarrow> wp c (\\<lambda>r s'. \\<exists>p'. p'##f \\<and> \\<alpha> s'=p'+f \\<and> Q r p') s)\"\n  proof (rule iffI, goal_cases)\n    case 1\n    show ?case\n      using htripleD[OF 1, where F=\"EXACT x\" for x]\n        by (auto simp: sep_conj_def)\n    \n  next\n    case 2\n    show ?case proof (rule htripleI)\n      fix F s \n      assume \"(P \\<and>* F) (\\<alpha> s)\"\n      then obtain p f where \"p##f\" \"P p\" \"F f\" \"\\<alpha> s = p+f\"\n        by (blast elim: sep_conjE)\n      with 2 have \"wp c (\\<lambda>r s'. \\<exists>p'. p' ## f \\<and> \\<alpha> s' = p' + f \\<and> Q r p') s\" by blast\n      then show \"wp c (\\<lambda>r s'. (Q r \\<and>* F) (\\<alpha> s')) s\"\n        apply (rule wp_monoI)\n        using \\<open>F f\\<close> by (auto intro: sep_conjI)\n    qed\n  qed\n  \n  lemma htripleI': \n    assumes \"\\<And>p s f. \\<lbrakk> p##f; \\<alpha> s = p + f; P p\\<rbrakk> \\<Longrightarrow> wp c (\\<lambda>r s'. \\<exists>p'. p'##f \\<and> \\<alpha> s'=p'+f \\<and> Q r p') s\"\n    shows \"htriple \\<alpha> P c Q\"\n    using assms by (auto simp: htriple_alt)\n\n  lemma htripleD': \n    assumes \"htriple \\<alpha> P c Q\"\n    assumes \"p##f\" \"\\<alpha> s = p + f\" \"P p\"\n    shows \"wp c (\\<lambda>r s'. \\<exists>p'. p'##f \\<and> \\<alpha> s'=p'+f \\<and> Q r p') s\"\n    using assms by (auto simp: htriple_alt)\n        \n    \n    \n  lemma htriple_extract_pre_pure: \n    \"htriple \\<alpha> (\\<up>\\<Phi>**P) c Q \\<longleftrightarrow> \\<Phi> \\<longrightarrow> htriple \\<alpha> P c Q\"  \n    by (cases \\<Phi>) (auto simp: sep_algebra_simps)\n    \n  (*\n  lemma htriple_extract_pre_EXS: \n    assumes \"\\<And>x s. \\<Phi> x \\<Longrightarrow> P s \\<Longrightarrow> f x ## s\"\n    shows \"htriple \\<alpha> (EXS x. \\<up>\\<Phi> x ** EXACT (f x) ** P) c Q \\<longleftrightarrow> (\\<exists>x. \\<Phi> x \\<and> htriple \\<alpha> (EXACT (f x) ** P) c Q)\"\n    apply rule\n  *)  \n    \n  thm htripleD\n  \n  thm option.simps\n  \n  lemma sv_htripleD:\n    assumes \"htriple \\<alpha> P c Q\"\n    assumes \"(P**F) (\\<alpha> s)\"\n    assumes \"\\<And>r s. (Q r ** F) (\\<alpha> s) \\<Longrightarrow> Q' r s\"\n    shows \"wp c Q' s\"\n    using assms \n    by (force simp: htriple_def intro: wp_monoI)\n  \n  lemma sv_htripleFD:\n    assumes \"htripleF \\<alpha> F P c Q\"\n    assumes \"(P**F) (\\<alpha> s)\"\n    assumes \"\\<And>r s. (Q r ** F) (\\<alpha> s) \\<Longrightarrow> Q' r s\"\n    shows \"wp c Q' s\"\n    using assms \n    by (force simp: htripleF_def intro: wp_monoI)\n    \n    \n  lemma htriple_conj_pure:\n    fixes \\<alpha>\n    assumes \"htriple \\<alpha> P c Q\"\n    assumes \"htriple \\<alpha> P c (\\<lambda>r. \\<up>\\<Phi> r ** sep_true)\"\n    shows \"htriple \\<alpha> P c (\\<lambda>r. \\<up>\\<Phi> r ** Q r)\"\n  proof (rule htripleI)  \n    fix F s\n    assume \"(P**F) (\\<alpha> s)\"\n    from wp_comm_conjI[OF assms[THEN htripleD,OF this]]\n    show \"wp c (\\<lambda>r s'. ((\\<up>\\<Phi> r \\<and>* Q r) \\<and>* F) (\\<alpha> s')) s\"\n      apply (rule wp_monoI)\n      using and_pure_true unfolding entails_def by blast\n      \n  qed    \n\n  \n  text \\<open>With garbage collection\\<close>\n  abbreviation \"htriple_gc GC \\<alpha> P c Q \\<equiv> htriple \\<alpha> P c (\\<lambda>r. Q r ** GC)\"\n  \n  lemma htriple_to_gc: \"\\<lbrakk> \\<box>\\<turnstile>GC; htriple \\<alpha> P c Q \\<rbrakk> \\<Longrightarrow> htriple_gc GC \\<alpha> P c Q\"\n    apply (erule cons_rule)\n    apply simp\n    by (metis abel_semigroup.commute entails_def sep.mult.abel_semigroup_axioms sep_conj_empty sep_globalise)\n  \n      \nend\n\n\n\nexperiment begin\n  text \\<open>Precondition defined by semantics relation:\n    \\<^item> \\<open>T c s\\<close> command terminates in state \\<open>s\\<close>\n    \\<^item> \\<open>R c s r s'\\<close> command yields result \\<open>r\\<close> and new state \\<open>s'\\<close>\n  \\<close>\n  \n  definition \"my_wp T (R::_ \\<Rightarrow> 's\\<Rightarrow>_\\<Rightarrow>'s\\<Rightarrow>bool) c Q s \\<equiv> T c s \\<and> (\\<forall>r s'. R c s r s' \\<longrightarrow> Q r s')\"\n  \n\n  interpretation generic_wp \"my_wp T R\"  \n    apply unfold_locales\n    unfolding my_wp_def\n    by auto\n  \n\nend\n\n\n\n\ndefinition STATE :: \"('s \\<Rightarrow> 'a::sep_algebra) \\<Rightarrow> ('a \\<Rightarrow> bool) \\<Rightarrow> 's \\<Rightarrow> bool\" \n  where \"STATE \\<alpha> P s \\<equiv> P (\\<alpha> s)\"\n\nlemma STATE_assn_cong[fri_extract_congs]: \"P\\<equiv>P' \\<Longrightarrow> STATE \\<alpha> P s \\<equiv> STATE \\<alpha> P' s\" by simp\n  \nlemma STATE_extract[vcg_normalize_simps]:\n  \"STATE \\<alpha> (\\<up>\\<Phi>) h \\<longleftrightarrow> \\<Phi> \\<and> STATE \\<alpha> \\<box> h\"\n  \"STATE \\<alpha> (\\<up>\\<Phi> ** P) h \\<longleftrightarrow> \\<Phi> \\<and> STATE \\<alpha> P h\"\n  \"STATE \\<alpha> (EXS x. Q x) h \\<longleftrightarrow> (\\<exists>x. STATE \\<alpha> (Q x) h)\"\n  \"STATE \\<alpha> (\\<lambda>_. False) h \\<longleftrightarrow> False\"\n  \"STATE \\<alpha> ((\\<lambda>_. False) ** P) h \\<longleftrightarrow> False\"\n  by (auto simp: STATE_def sep_algebra_simps pred_lift_extract_simps)\n \n\ndefinition POSTCOND :: \"('s \\<Rightarrow> 'a::sep_algebra) \\<Rightarrow> ('a \\<Rightarrow> bool) \\<Rightarrow> 's \\<Rightarrow> bool\" \n  where [vcg_tag_defs]: \"POSTCOND \\<alpha> \\<equiv> STATE \\<alpha>\"\n  \nlemma POSTCONDI:\n  \"STATE \\<alpha> A h \\<Longrightarrow> POSTCOND \\<alpha> A h\"\n  by (auto simp add: POSTCOND_def)\nlemma POSTCOND_cong[vcg_normalize_congs]: \"POSTCOND \\<alpha> A = POSTCOND \\<alpha> A\" ..\n\nlemma POSTCOND_triv_simps[vcg_normalize_simps]:\n  \"POSTCOND \\<alpha> sep_true h\"\n  \"\\<not>POSTCOND \\<alpha> sep_false h\"\n  unfolding POSTCOND_def STATE_def by auto\n  \nlemma start_entailsE:\n  assumes \"STATE \\<alpha> P h\"\n  assumes \"ENTAILS P P'\"\n  shows \"STATE \\<alpha> P' h\"\n  using assms unfolding STATE_def ENTAILS_def entails_def\n  by auto\n\ndeclaration \\<open>\n  K (Basic_VCG.add_xformer (@{thms POSTCONDI},@{binding postcond_xformer},\n    fn ctxt => eresolve_tac ctxt @{thms start_entailsE}\n  ))\n\\<close>\n\n\nnamed_theorems htriple_vcg_intros\nnamed_theorems htriple_vcg_intro_congs\ndefinition [vcg_tag_defs]: \"DECOMP_HTRIPLE \\<phi> \\<equiv> \\<phi>\"\nlemma DECOMP_HTRIPLEI: \"\\<phi> \\<Longrightarrow> DECOMP_HTRIPLE \\<phi>\" unfolding vcg_tag_defs by simp\n\n \ncontext generic_wp begin\n  thm frame_rule\n  thm cons_rule  \n    \n  lemma htriple_vcg_frame_erule[vcg_frame_erules]:\n    assumes S: \"STATE \\<alpha> P' s\"\n    assumes F: \"PRECOND (FRAME P' P F)\"\n    assumes HT: \"htriple \\<alpha> P c Q\"  \n    assumes P: \"\\<And>r s. STATE \\<alpha> (Q r ** F) s \\<Longrightarrow> PRECOND (EXTRACT (Q' r s))\"\n    shows \"wp c Q' s\"\n  proof -\n    from S F have \"(P \\<and>* F) (\\<alpha> s)\"\n      unfolding vcg_tag_defs\n      by (metis (no_types) FRAME_def entails_def STATE_def)\n    with P show ?thesis\n      unfolding vcg_tag_defs\n      by (metis (no_types) STATE_def sv_htripleD[OF HT])\n      \n  qed\n\n  lemma htripleF_vcg_frame_erule[vcg_frame_erules]:\n    assumes S: \"STATE \\<alpha> P' s\"\n    assumes F: \"PRECOND (FRAME P' P F)\"\n    assumes HT: \"htripleF \\<alpha> F P c Q\"  \n    assumes P: \"\\<And>r s. STATE \\<alpha> (Q r ** F) s \\<Longrightarrow> PRECOND (EXTRACT (Q' r s))\"\n    shows \"wp c Q' s\"\n  proof -\n    from S F have \"(P \\<and>* F) (\\<alpha> s)\"\n      unfolding vcg_tag_defs\n      by (metis (no_types) FRAME_def entails_def STATE_def)\n    with P show ?thesis\n      unfolding vcg_tag_defs\n      by (metis (no_types) STATE_def sv_htripleFD[OF HT])\n      \n  qed\n  \n  \n  \n  lemma htriple_vcgI': \n    assumes \"\\<And>F s. STATE \\<alpha> (P**F) s \\<Longrightarrow> wp c (\\<lambda>r. POSTCOND \\<alpha> (Q r ** F)) s\"\n    shows \"htriple \\<alpha> P c Q\"\n    apply (rule htripleI)\n    using assms unfolding vcg_tag_defs STATE_def .\n  \n  lemma htriple_vcgI[htriple_vcg_intros]: \n    assumes \"\\<And>F s. STATE \\<alpha> (P**F) s \\<Longrightarrow> EXTRACT (wp c (\\<lambda>r. POSTCOND \\<alpha> (Q r ** F)) s)\"\n    shows \"htriple \\<alpha> P c Q\"\n    apply (rule htripleI)\n    using assms unfolding vcg_tag_defs STATE_def .\n\n  lemma htripleF_vcgI[htriple_vcg_intros]: \n    assumes \"\\<And>s. STATE \\<alpha> (P**F) s \\<Longrightarrow> EXTRACT (wp c (\\<lambda>r. POSTCOND \\<alpha> (Q r ** F)) s)\"\n    shows \"htripleF \\<alpha> F P c Q\"\n    apply (rule htripleFI)\n    using assms unfolding vcg_tag_defs STATE_def .\n    \n      \n  lemma htriple_decompI[vcg_decomp_rules]: \n    \"DECOMP_HTRIPLE (htriple \\<alpha> P c Q) \\<Longrightarrow> htriple \\<alpha> P c Q\"\n    \"DECOMP_HTRIPLE (htripleF \\<alpha> F P c Q) \\<Longrightarrow> htripleF \\<alpha> F P c Q\"\n    unfolding vcg_tag_defs by auto\n\n  lemma htriple_assn_cong[htriple_vcg_intro_congs]: \n    \"P\\<equiv>P' \\<Longrightarrow> Q\\<equiv>Q' \\<Longrightarrow>  htriple \\<alpha> P c Q \\<equiv> htriple \\<alpha> P' c Q'\" by simp\n\n  lemma htripleF_assn_cong[htriple_vcg_intro_congs]: \n    \"P\\<equiv>P' \\<Longrightarrow> Q\\<equiv>Q' \\<Longrightarrow>  htripleF \\<alpha> F P c Q \\<equiv> htripleF \\<alpha> F P' c Q'\" by simp\n            \n  lemma htriple_ent_pre:\n    \"P\\<turnstile>P' \\<Longrightarrow> htriple \\<alpha> P' c Q \\<Longrightarrow> htriple \\<alpha> P c Q\"\n    unfolding entails_def\n    apply (erule cons_rule) by blast+\n    \n  lemma htriple_ent_post:\n    \"\\<lbrakk>\\<And>r. Q r \\<turnstile> Q' r\\<rbrakk> \\<Longrightarrow> htriple \\<alpha> P c Q \\<Longrightarrow> htriple \\<alpha> P c Q'\"\n    unfolding entails_def\n    apply (erule cons_rule) by blast+\n   \n  lemma htriple_pure_preI: \"\\<lbrakk>pure_part P \\<Longrightarrow> htriple \\<alpha> P c Q\\<rbrakk> \\<Longrightarrow> htriple \\<alpha> P c Q\"  \n    by (meson htriple_def pure_partI sep_conjE)\n    \n     \nend\n\n\ndeclaration \\<open>\n  K (Basic_VCG.add_xformer (@{thms DECOMP_HTRIPLEI},@{binding decomp_htriple_xformer},\n    fn ctxt => \n      (full_simp_tac (put_simpset HOL_basic_ss ctxt \n        addsimps (Named_Theorems.get ctxt @{named_theorems vcg_tag_defs})\n        |> fold Simplifier.add_cong (Named_Theorems.get ctxt @{named_theorems htriple_vcg_intro_congs})\n      ))\n      THEN' resolve_tac ctxt (Named_Theorems.get ctxt @{named_theorems htriple_vcg_intros})\n  ))\n\\<close>\n\n\n\nsection \\<open>a General framework for abstract and concrete costs\\<close>\n\ntext \\<open>This locale fixes a type of concrete costs \\<open>'cc\\<close> which is used in \\<open>mres\\<close> and a type for\n      abstract costs \\<open>'ca\\<close> which should be used in the separation logic with (resource) credits. \n      There is some invariant that has to hold between the credits currently available \"on the heap\"\n      and the resources spent in the computation, \\<open>I\\<close> captures that.\n      Also it needs to be possible to deduct the resources used by the computation from the credits,\n      this is captured by \\<open>minus\\<close>.\n      \\<close>\n\nlocale cost_framework =\n  fixes\n    I :: \"'cc::{monoid_add} \\<Rightarrow> 'ca \\<Rightarrow> bool\"\n  and minus :: \"'ca \\<Rightarrow> 'cc \\<Rightarrow> 'ca\" \\<comment> \\<open>takes abstract credits, and returns the effect of consuming\n                                        the concrete resources\\<close>\nassumes minus_0[simp]: \"\\<And>y. minus y 0 = y\"\n  and I_0[simp,intro!]: \"I 0 cr\"\n  and minus_minus_add: \"\\<And>a b c. minus (minus a b) c = minus a (b + c)\"\n  \\<comment> \\<open>TODO: maybe some of these are redundant\\<close>\n  and I1: \"\\<And>a b c. I (a + b) c \\<Longrightarrow> I b (minus c a)\"\n  and I2: \"\\<And>a b c. I (a + b) c \\<Longrightarrow> I a c\"\n  and I3:  \"\\<And>a b c. I a (minus c b) \\<Longrightarrow> I b c \\<Longrightarrow> I (b + a) c\"\nbegin\n\n\n  definition  wp :: \"('d, 'e, _, 'a, 'f) M \\<Rightarrow> _ \\<Rightarrow> _\" where\n    \"wp m Q \\<equiv> \\<lambda>(s,cr). mwp (run m s) bot bot bot (\\<lambda>r c s. Q r (s,minus cr c) \\<and> I c cr)\"\n\n(*\n  term \"\\<alpha> x \\<le> y \\<longleftrightarrow> x \\<le> \\<gamma> y\"    \n*)\n    \n  interpretation generic_wp wp\n    apply unfold_locales\n    unfolding wp_def fun_eq_iff inf_fun_def inf_bool_def mwp_def\n    by (auto split: mres.split)\n\n\n  lemma wp_return: \"wp (return x) Q s \\<longleftrightarrow> Q x s\"\n    by (auto simp: wp_def run_simps minus_0 I_0)\n\n  lemma wp_fail: \"\\<not> wp (fail x) Q s\"\n    by (auto simp: wp_def run_simps)\n\n  lemma wp_fcheck: \"wp (fcheck e \\<Phi>) Q s \\<longleftrightarrow> \\<Phi> \\<and> Q () s\"\n    by (auto simp: wp_def run_simps minus_0 I_0 split: if_splits)\n\n  (* TODO: refactor that proof, should not need to unfold mwp_def at that stage *)\n  lemma wp_bind: \"wp (m\\<bind>f) Q s = wp m (\\<lambda>x. wp (f x) Q) s\"\n    apply (auto simp: wp_def run_simps split: prod.splits)\n    unfolding mwp_def apply (auto split: mres.splits simp add: minus_minus_add)\n    subgoal\n      by (metis I1)\n    subgoal\n      by (metis I2)\n    subgoal\n      by (metis I3)\n    done\n    \n  lemma wp_consume: \"wp (consume c) Q (s,cr) \\<longleftrightarrow> I c cr \\<and> Q () (s,minus cr c)\"  \n    unfolding wp_def mwp_def consume_def by (auto split: mres.split)\n    \nend\n\n\n\ninterpretation nat: cost_framework \"\\<lambda>(c::nat) (cr::nat). cr-c+c=cr\" \"(-)\"\n  apply standard\n  by auto\n\ninterpretation int: cost_framework \"\\<lambda>(c::int) (cr::int). True\" \"(-)\"\n  apply standard\n  by auto\n\nlocale cost_framework2 = cost_framework I minus for I :: \"'cc::{monoid_add} \\<Rightarrow> 'ca::{plus} \\<Rightarrow> bool\" and minus +\n  assumes I_left_mono: \"\\<And>x c d. I x c \\<Longrightarrow> I x (c+d)\" \\<comment> \\<open>@{thm ordered_comm_monoid_add_class.add_increasing2}\\<close>\n  assumes minus_add_assoc2: \"\\<And>x c d. I x c \\<Longrightarrow> minus (c + d) x = minus c x + d\" \\<comment> \\<open>@{thm ordered_cancel_comm_monoid_diff_class.diff_add_assoc2}\\<close>\nbegin\n\n\nend\n\nlocale cost_framework3 = cost_framework2 I minus for I :: \"'cc::{monoid_add} \\<Rightarrow> 'ca::{plus} \\<Rightarrow> bool\" and minus +\n  fixes lift :: \"'cc \\<Rightarrow> 'ca\"\n  assumes I_add1: \"\\<And>c cr. I c (lift c + cr)\" \\<comment> \\<open>@{thm le_add1}\\<close>\n  assumes add_minus_cancel: \"\\<And>c cr. minus (lift c + cr) c = cr\" \\<comment> \\<open>@{thm Extended_Nat.add_diff_cancel_enat}\\<close>\nbegin\n\n\nend\n\n\n\n\n  \nterm acostC  \n  \n\n\ncontext cost_framework begin                     \n\nabbreviation \"I_fun \\<equiv> (\\<lambda>cc ca. \\<forall>x. I (the_acost cc x) (the_acost ca x))\"\nabbreviation \"minus_fun \\<equiv> (\\<lambda>ca cc. acostC (\\<lambda>x. minus (the_acost ca x) (the_acost cc x)))\"\n\n  lemma fun_cost_framework: \"cost_framework I_fun minus_fun\"\n    apply unfold_locales\n    apply (simp_all add: zero_acost_def I_0 minus_0 minus_minus_add fun_eq_iff)\n    subgoal for a b c by (cases a;cases b;cases c; auto)\n    subgoal for a b c by (cases a;cases b;cases c; auto simp: I1)\n    subgoal for a b c by (cases a;cases b;cases c; auto intro: I2)\n    subgoal for a b c by (cases a;cases b;cases c; auto simp: I3)\n    done\nend\n\ncontext cost_framework3\nbegin\n\n\nlemma fun_cost_framework2: \"cost_framework2 I_fun minus_fun\"\n  unfolding cost_framework2_def\n  apply safe apply (fact fun_cost_framework)\n  apply unfold_locales\n  subgoal for x c d by(cases x; cases c; cases d) (auto intro: I_left_mono)\n  subgoal for x c d by(cases x; cases c; cases d) (auto intro: minus_add_assoc2)\n  done\n\n\nabbreviation \"lift_fun \\<equiv> (\\<lambda>cc. acostC (\\<lambda>x. lift (the_acost cc x)))\"\n\nlemma fun_cost_framework3: \"cost_framework3 I_fun minus_fun lift_fun\"\n  unfolding cost_framework3_def\n  apply safe apply (fact fun_cost_framework2)\n  apply unfold_locales\n  subgoal for c cr by(cases c; cases cr) (auto intro: I_add1)\n  subgoal for c cr by(cases c; cases cr) (auto intro: add_minus_cancel)\n  done\n\n\nend\n\n\nsection \\<open>Setup for mres-Monad\\<close>\n\n  lemma \"cr-c+c=(cr::nat) \\<longleftrightarrow> cr\\<ge>c\" by auto\n  lemma \"cr-c+c=(cr::int) \\<longleftrightarrow> True\" by auto\n\n\n  lemma enat_diff_diff: \"a - enat b - enat c = a - enat (b + c)\"\n    apply(cases a) by auto\n  lemma enat_aux1: \"c - enat (a + b) + enat (a + b) = c \\<Longrightarrow> c - enat a + enat a = c\"\n    apply(cases c) by auto\n    \n  definition le_cost_ecost :: \"cost \\<Rightarrow> ecost \\<Rightarrow> bool\" \n    where \"le_cost_ecost cc ca \\<equiv> \\<forall>x. enat (the_acost cc x) \\<le> (the_acost ca x)\"\n\n  definition minus_ecost_cost :: \"ecost \\<Rightarrow> cost \\<Rightarrow> ecost\"\n    where \"minus_ecost_cost ca cc \\<equiv> acostC (\\<lambda>x. (the_acost ca x) - enat (the_acost cc x))\"\n      \n  interpretation cost_framework le_cost_ecost minus_ecost_cost\n    unfolding le_cost_ecost_def minus_ecost_cost_def\n    apply (rule cost_framework.fun_cost_framework)\n    apply standard\n    apply (auto simp flip: zero_enat_def)\n    subgoal by (metis enat_diff_diff)\n    subgoal\n      by (smt add.commute add_diff_cancel_enat add_right_mono enat.distinct(1) enat_aux1 eq_iff le_iff_add linear of_nat_add of_nat_eq_enat)\n    subgoal\n      by (meson enat_ord_simps(1) le_add1 order_subst2)\n    subgoal\n      by (metis add_diff_cancel_enat add_left_mono enat.simps(3) le_iff_add plus_enat_simps(1))\n    done\n\n    \n  (*      \n  term pi  \n  interpretation cost_framework \"\\<lambda>(c::nat) (cr::enat). cr-c+c=cr\" \"(-)\"\n    apply standard\n         apply (auto simp: zero_enat_def)\n    subgoal\n      by (metis enat_diff_diff)\n    subgoal\n      by (metis enat_diff_diff add_diff_assoc_enat add_diff_cancel_left' enat_ord_simps(1)\n                idiff_enat_enat le_add_same_cancel1 zero_le)\n    subgoal\n      by (metis enat_aux1)\n    subgoal\n      by (metis enat_diff_diff add.assoc add.commute plus_enat_simps(1))\n    done\n  *)\n\n  (*\n  lemma enat_nat_I_conv: \"cr - enat c + enat c = cr \\<longleftrightarrow> cr \\<ge> c\"\n    by (cases cr; cases c; auto)\n  *)\n\n  (* Definition for presentation *)\n  lemma natenat_alt: \"wp m Q = (\\<lambda>(s, cr). mwp (run m s) bot bot bot (\\<lambda>r c s. Q r (s, minus_ecost_cost cr c) \\<and> le_cost_ecost c cr))\" unfolding wp_def ..\n\n  (* Definition for presentation in paper *)\n  lemma wp_alt: \"wp m Q (s,cr::ecost) = (\\<exists>r (c::cost) s'. run m s = SUCC r c s' \\<and> Q r (s', minus_ecost_cost cr c) \\<and> le_cost_ecost c cr )\"\n    unfolding wp_def mwp_def by (fastforce split: mres.splits)\n\n  interpretation generic_wp wp \n    apply unfold_locales \n    unfolding wp_def fun_eq_iff inf_fun_def inf_bool_def mwp_def\n    by (auto split: mres.split)\n\n  declare wp_return[vcg_normalize_simps]\n\n  declare wp_fail[vcg_normalize_simps]\n\n  declare wp_fcheck[vcg_normalize_simps]\n\n  declare wp_bind[vcg_normalize_simps]\n\n  thm vcg_normalize_simps\n\n  \n  \n  (* TODO: Move *)\n  instantiation enat :: stronger_sep_algebra begin\n    definition \"(_::enat) ## _ \\<equiv> True\"\n  \n    instance\n      apply standard\n      apply (simp_all add: sep_disj_enat_def)\n      done\n      \n  end\n  \n  \n  instantiation acost :: (type,stronger_sep_algebra) stronger_sep_algebra begin\n    definition \"f1 ## f2 \\<longleftrightarrow> (\\<forall>x. the_acost f1 x ## the_acost f2 x)\"\n    (*definition [simp]: \"(f1 + f2) = acostC (\\<lambda>x. the_acost f1 x + the_acost f2 x)\"\n    definition [simp]: \"0 x \\<equiv> 0\"\n    *)\n  \n    instance\n      apply standard\n      unfolding sep_disj_acost_def plus_acost_alt zero_acost_def\n      apply (auto simp: sep_algebra_simps split: acost.splits)\n      done  \n    \n  end\n  \n  \n\ndefinition time_credits_assn :: \"ecost \\<Rightarrow> (_ \\<times> ecost \\<Rightarrow> bool)\" (\"$_\" [900] 900) where \"($c) \\<equiv> SND (EXACT c)\"\n\nterm \"a ** $c\"\nterm \"c ** $a\"\n\ndefinition \"GC \\<equiv> SND sep_true\"\n  \nlemma GC_absorb[simp]: \"(GC ** GC) = GC\" by (auto simp: GC_def sep_algebra_simps SND_conj_conv)\n\nlemma entails_GC: \"$c \\<turnstile> GC\" unfolding GC_def time_credits_assn_def\n  by (auto simp: entails_def SND_def) (* TODO: Monotonicity of FST,SND as lemmas? *)\n\nlemma \"$0 = \\<box>\" oops \n  \nlemma empty_ent_GC: \"\\<box>\\<turnstile>GC\" unfolding GC_def time_credits_assn_def\n  by (auto simp: entails_def SND_def sep_algebra_simps) \n\n\nlemma dollar_aux_conv: \"($c) (aa, ba) = (aa=0 \\<and> ba=c)\"\n  unfolding time_credits_assn_def EXACT_def SND_def\n  by auto\n\n\nlemma \"F \\<turnstile> GC ** G \\<Longrightarrow> $c ** F \\<turnstile> GC ** G\"\n  by (metis (no_types, lifting) GC_absorb conj_entails_mono entails_GC sep_conj_assoc)\n  \nlemma htriple_to_GC: \"\\<lbrakk> htriple \\<alpha> P c Q \\<rbrakk> \\<Longrightarrow> htriple_gc GC \\<alpha> P c Q\"\n  using htriple_to_gc[OF empty_ent_GC] .\n  \nlemma time_credits_add: \"($A ** $B) = $(A+B)\"   \n  by (simp add: EXACT_split SND_conj_conv sep_disj_acost_def sep_disj_enat_def time_credits_assn_def)  \n\n  \n\n(* For presentation *)\nlemma \"($c) (s,c') \\<longleftrightarrow> s=0 \\<and> c'=c\"\n  unfolding time_credits_assn_def by (simp add: sep_algebra_simps SND_def) (* TODO: Lemmas for SND! *)\n  \nlemma \"($c) a \\<longleftrightarrow> a=(0,c)\"  \n  unfolding time_credits_assn_def by (cases a) (simp add: sep_algebra_simps SND_def)\n    \ndefinition \"lift_\\<alpha>_cost \\<alpha> \\<equiv> \\<lambda>(s,c). (\\<alpha> s,c)\"  \n\n\nlemma cost_ecost_minus_add_assoc2: \"le_cost_ecost x c \\<Longrightarrow> minus_ecost_cost (c + d) x = minus_ecost_cost c x + d\"\n  apply(cases x; cases c; cases d) apply(auto simp: minus_ecost_cost_def le_cost_ecost_def)\n  by (simp add: add.commute add_diff_assoc_enat)\n\nlemma cost_ecost_add_increasing2: \"le_cost_ecost x c \\<Longrightarrow> le_cost_ecost x (c + d)\"  \n  apply(cases x; cases c; cases d) apply (auto simp:   le_cost_ecost_def) \n  by (simp add:  add_increasing2) \n\nlemma cost_ecost_add1: \"le_cost_ecost c (lift_acost c + cr')\" \n  apply(cases cr') by (auto simp: le_cost_ecost_def lift_acost_def )\n\nlemma cost_ecost_add_minus_cancel: \"minus_ecost_cost (lift_acost c + cr') c = cr'\"  \n  apply(cases cr') by (auto simp: minus_ecost_cost_def lift_acost_def )\n    \nlemma consume_rule_aux: \"htriple (lift_\\<alpha>_cost \\<alpha>) ($(lift_acost c)) (consume c) (\\<lambda>_. \\<box>)\"  \n  apply (rule htripleI)\n  apply clarify\n  apply (simp add: wp_consume time_credits_assn_def lift_\\<alpha>_cost_def)\nproof (rule conjI)\n  fix F s cr\n  assume \"(SND (EXACT (lift_acost c)) \\<and>* F) ((\\<alpha> s, cr))\"\n  from this have \"(EXACT (lift_acost c) \\<and>* (\\<lambda>b. F (\\<alpha> s, b))) cr\" by (simp add: SND_project_frame)\n  then obtain cr' where [simp]: \"lift_acost c ## cr'\" \"cr = lift_acost c + cr'\" and F: \"F (\\<alpha> s, cr')\"\n    by (rule sep_conjE) (simp add: sep_algebra_simps)\n  have \"0 \\<preceq> cr'\"\n    by (simp add: sep_substate_def) \n  show \"le_cost_ecost c cr\" by (simp add: cost_ecost_add1)\n  \n  show \"F (\\<alpha> s, minus_ecost_cost cr c)\" using F by (simp add: cost_ecost_add_minus_cancel)\nqed    \n  \nlemmas consume_rule = htriple_to_GC[OF consume_rule_aux]\n\n    \nsection \\<open>experiment: Hoare-triple without Time\\<close>  \n \n  \n      \n    \n    \n    \n    \n    \n    \n    \n    \n  \n  text \\<open>Weakest precondition without time\\<close>\n  definition \"wpn m Q s \\<equiv> mwp (run m s) bot bot bot (\\<lambda>r c s'. c=0 \\<and> Q r s')\"\n  \n  lemma wpn_def': \"wpn m Q s = (\\<exists>r s'. run m s = SUCC r 0 s' \\<and> Q r s')\"\n    unfolding wpn_def mwp_def\n    by (auto split: mres.split)\n  \n  (* TODO: Move *)  \n  lemma le_cost_zero_conv[simp]: \"le_cost_ecost c 0 \\<longleftrightarrow> c=0\"\n    unfolding le_cost_ecost_def by (cases c; auto simp: zero_acost_def zero_enat_def)\n  \n    \n  lemma wpn_alt: \"wpn m Q s = wp m (FST o Q) (s,0)\"\n    unfolding wp_def wpn_def mwp_def\n    by (auto split: mres.split simp: zero_enat_def FST_def)\n\n  lemma wpn_alt': \"wpn m Q s = wp m (\\<lambda>r (s,c). Q r s \\<and> c=0) (s,0)\"\n    unfolding wp_def wpn_def mwp_def\n    by (auto split: mres.split simp: zero_enat_def FST_def)\n    \n      \n  interpretation notime: generic_wp wpn  \n    apply unfold_locales \n    unfolding wpn_def fun_eq_iff inf_fun_def inf_bool_def mwp_def\n    by (auto split: mres.split)\n\n        \n  lemma wpn_return[vcg_normalize_simps]: \"wpn (return x) Q s \\<longleftrightarrow> Q x s\"\n    by (auto simp: wpn_def run_simps)\n\n  lemma wpn_fail[vcg_normalize_simps]: \"\\<not> wpn (fail x) Q s\"\n    by (auto simp: wpn_def run_simps)\n\n  lemma wpn_fcheck[vcg_normalize_simps]: \"wpn (fcheck e \\<Phi>) Q s \\<longleftrightarrow> \\<Phi> \\<and> Q () s\"\n    by (auto simp: wpn_def run_simps split: if_splits)\n\n  (* TODO: refactor that proof, should not need to unfold mwp_def at that stage *)\n  (* TODO: Intuitively, want equality here: BUT, equality only holds if costs cannot be negative! *)\n  lemma wpn_bind[vcg_decomp_rules]: \"wpn m (\\<lambda>x. wpn (f x) Q) s \\<Longrightarrow> wpn (m\\<bind>f) Q s\"\n    apply (auto simp: wpn_def[abs_def] run_simps split: prod.splits)\n    unfolding mwp_def \n    by (auto \n      split: mres.splits \n      simp add: minus_minus_add dest!: addcost_SUCC_D)\n  \n  (*      \n  lemma wpn_bind: \"wpn (m\\<bind>f) Q s = wpn m (\\<lambda>x. wpn (f x) Q) s\"\n    apply (auto simp: wpn_def run_simps split: prod.splits)\n    unfolding mwp_def \n    apply (auto \n      split: mres.splits \n      simp add: minus_minus_add dest!: addcost_SUCC_D)\n    xxx. ctd here: need positive costs, \n      otherwise negatove+positive can cancel out.\n      \n  *)\n  \n  \n  lemma notime_return_rule: \"notime.htriple \\<alpha> P (return x) (\\<lambda>r. \\<up>(r=x)**P)\" for \\<alpha>\n    by vcg\n  \n      \n  text \\<open>Transfer of Hoare-Triples\\<close>\n    \n  (* TODO: Move *)\n  lemma wp_time_mono: \"wp m Q (s,c) \\<Longrightarrow> wp m (\\<lambda>r (s',c'). \\<exists>cc'. c'=cc'+d \\<and> Q r (s',cc')) (s,c+d)\"\n    unfolding wp_def mwp_def\n    apply (auto simp add: algebra_simps sep_algebra_simps SND_def sep_conj_def split: mres.split)\n    subgoal by (intro exI conjI; assumption?) (rule cost_ecost_minus_add_assoc2)\n    subgoal by (rule cost_ecost_add_increasing2)\n    done\n      \n  lemma notime_to_htriple:\n    fixes c :: \"('a, 'b, cost, 'd, 'e) M\"\n    assumes H: \"notime.htriple \\<alpha> P c Q\"\n    shows \"htriple (lift_\\<alpha>_cost \\<alpha>) (FST P) c (FST o Q)\"\n    unfolding lift_\\<alpha>_cost_def\n    apply (rule htripleI)\n    apply clarify\n  proof -\n    fix F a and b :: ecost\n    assume \"(FST P \\<and>* F) (\\<alpha> a, b)\"\n    hence \"(P ** (\\<lambda>a. F (a,b))) (\\<alpha> a)\"\n      by (simp add: sep_algebra_simps FST_project_frame)\n    from notime.htripleD[OF H this] have \"wpn c (\\<lambda>r s'. (Q r \\<and>* (\\<lambda>a. F (a, b))) (\\<alpha> s')) a\" .\n    then have \"wp c (\\<lambda>x (a, ba). (Q x \\<and>* (\\<lambda>a. F (a, b))) (\\<alpha> a) \\<and> ba = 0) (a, 0)\"\n      unfolding wpn_alt FST_def comp_def by simp\n    from wp_time_mono[OF this, of b] have \"wp c (\\<lambda>r (s', c'). c' = b \\<and> (Q r \\<and>* (\\<lambda>a. F (a, b))) (\\<alpha> s')) (a, b)\"\n      by simp\n    then show \"wp c (\\<lambda>r s'. ((FST \\<circ> Q) r \\<and>* F) (case s' of (s, x) \\<Rightarrow> (\\<alpha> s, x))) (a, b)\"  \n      apply (rule wp_monoI)\n      apply (auto simp: FST_project_frame)\n      done\n  qed  \n\n  lemma htriple_to_notime:\n    assumes H: \"htriple (lift_\\<alpha>_cost \\<alpha>) (FST P) c (FST o Q)\"\n    shows \"notime.htriple \\<alpha> P c Q\"\n    apply (rule notime.htripleI)\n    unfolding wpn_alt\n  proof -  \n    fix F s\n    assume A: \"(P \\<and>* F) (\\<alpha> s)\"\n    \n    show \"wp c (FST \\<circ> (\\<lambda>r s'. (Q r \\<and>* F) (\\<alpha> s'))) (s, 0)\"\n      apply (rule wp_monoI)\n      apply (rule htripleD[OF H, where F=\"FST F\"])\n      unfolding lift_\\<alpha>_cost_def\n      apply (auto simp: FST_conj_conv sep_algebra_simps A)\n      done\n  qed      \n  \n  lemma notime_htriple_eq: \"notime.htriple \\<alpha> P c Q = htriple (lift_\\<alpha>_cost \\<alpha>) (FST P) c (FST o Q)\"\n    by (blast intro: notime_to_htriple htriple_to_notime)\n  \n\n  definition \"wlp c Q s \\<equiv> mwp (run c s) top top top (\\<lambda>r c s. Q r s)\"\n  lemma wlp_true[simp, intro!]:\n    \"wlp c (\\<lambda>_ _. True) s\"\n    \"wlp c top s\"\n    by (auto simp: wlp_def mwp_def split: mres.splits)\n    \n  lemma wlp_return[simp]: \"wlp (return x) Q s = Q x s\"\n    by (auto simp: wlp_def run_simps)\n        \n  \nsection \\<open>experiment: cost type for Space\\<close>\n\n\ndatatype space_cost = Space_Cost (sca: nat) (scb: nat) (* highest point,  how far below that mark at the moment *)\n\n\n(*\n\n  mm_alloc n \\<Longrightarrow> \\<lambda>(m,c). (max m (c+n),c+n)\n  mm_free n \\<Longrightarrow> \\<lambda>(m,c). assert(n\\<le>c), (m,c-n)\n\n\n*)\n\n\nfun max_cost where \"max_cost (Space_Cost h _) = h\"\nfun curr_cost where \"curr_cost (Space_Cost h c) = int h - int c\"\n\ndefinition \"new_h m1 c1 m2 c2 \\<equiv> (max (int m1) (((int m1 - int c1)+int m2)))\"\ndefinition \"new_c m1 c1 m2 c2 \\<equiv> (new_h m1 c1 m2 c2 - ((int m1 - int c1)+(int m2 - int c2)))\"\n\nlemma new_h_nonneg: \"new_h m1 c1 m2 c2 \\<ge> 0\"\n  by (auto simp: new_h_def)\n\nlemma new_c_nonneg: \"new_c m1 c1 m2 c2 \\<ge> 0\"\n  by (auto simp: new_c_def new_h_def)\n\ninstantiation space_cost :: plus\nbegin\n  lemma fixes m1 c1 m2 c2 :: nat\n    shows \"(max (int m1) (((int m1 - int c1)+int m2))) - ((int m1 - int c1)+(int m2 - int c2)) \\<ge> 0\"\n    by auto\n\nlemma \"new_h m1 c1 m2 c2 - ((int m1 - int c1)+(int m2 - int c2)) \\<ge> 0\"\n  by (auto simp: new_h_def)\n\n  fun plus_space_cost :: \"space_cost \\<Rightarrow> space_cost \\<Rightarrow> space_cost\" where\n    \"plus_space_cost (Space_Cost m1 c1) (Space_Cost m2 c2) =\n             Space_Cost (nat (new_h m1 c1 m2 c2)) (nat (new_c m1 c1 m2 c2))\"\n\n  instance ..\nend\n\n\ninstantiation space_cost :: monoid_add\nbegin\n  definition zero_space_cost :: space_cost where \"zero_space_cost = Space_Cost 0 0\"\n\n  instance\n    apply standard\n    subgoal for a b c\n      apply(cases a; cases b; cases c)\n      apply (simp add: new_h_nonneg new_c_nonneg) apply safe\n      subgoal for m1 c1 m2 c2 m3 c3\n        apply(subst (2) new_h_def)\n        apply(simp add: new_c_nonneg  new_h_nonneg)\n        apply(subst (4) new_h_def)\n        apply(simp add: new_c_nonneg  new_h_nonneg)\n        by (auto simp: new_h_def new_c_def max.assoc)\n      subgoal for m1 c1 m2 c2 m3 c3\n        apply(subst (3) new_c_def)\n        apply(simp add: new_c_nonneg  new_h_nonneg)\n        apply(subst (3) new_c_def)\n        apply(subst (3) new_h_def)\n        apply(simp add: new_c_nonneg  new_h_nonneg)\n        apply(subst (2) new_c_def)\n        apply(simp add: new_c_nonneg  new_h_nonneg)\n        by (auto simp: new_h_def new_c_def max.assoc)\n      done\n    subgoal for a apply(cases a)\n      subgoal for m c\n        by (auto simp: new_h_def new_c_def zero_space_cost_def)\n      done\n    subgoal for a apply(cases a)\n      subgoal for m c\n        by (auto simp: new_h_def new_c_def zero_space_cost_def)\n      done\n    done\nend\n\n\ntext \\<open>the Invariant denotes, that maximum space \\<open>m\\<close> is at most the number of space_credits \\<open>n\\<close>\\<close>\n\nfun space_I :: \"space_cost \\<Rightarrow> nat \\<Rightarrow> bool\"  where\n  \"space_I (Space_Cost m c) n \\<longleftrightarrow> m\\<le>n\"\n\nfun space_minus :: \"nat \\<Rightarrow> space_cost \\<Rightarrow> nat\"  where\n  \"space_minus  n (Space_Cost m c) = n - m + c\"\n\\<comment> \\<open>if space_I holds, this is n - (m-c), i.e. credits minus newly occupied space\\<close>\n\ninterpretation space: cost_framework \"space_I\" \"space_minus\"\n  apply standard\n  subgoal for a by(simp add: zero_space_cost_def)\n  subgoal for cr apply (simp add: zero_space_cost_def) done\n  subgoal for a b c apply(cases b; cases c) by (simp add: new_c_def new_h_def)\n  subgoal for a b c apply(cases a; cases b) by (simp add: new_c_def new_h_def)\n  subgoal for a b c apply(cases a; cases b) by (simp add: new_c_def new_h_def)\n  subgoal for a b c apply(cases a; cases b) by (simp add: new_c_def new_h_def)\n  done\n\n\nlemma space_minus_aux: \"space_I b 0 \\<Longrightarrow> Space_Cost 0 (space_minus 0 b) = b\"\n  apply(cases b) by simp\n\n\ntext \\<open>The test \\<open>sm\\<le>cr\\<close> makes sure that the maximum of space \\<open>sm\\<close> used does not exceed \n      the allowed space by the \"space-credits\" cr.\n      When before executing \\<open>m\\<close> there are \\<open>cr\\<close> credits, after the execution there will be\n      \\<open>cr - (sm-c)\\<close>, i.e. the credits before minus the number of consumed space,\n      see @{const curr_cost}.\\<close>\n\nlemma \"space.wp m Q (s,cr) = (\\<exists>r sm c s'. run m s = SUCC r (Space_Cost sm c) s'\n                                   \\<and> Q r (s', cr - sm + c) \\<and> sm\\<le>cr )\"\n    unfolding space.wp_def  mwp_def\n    apply (auto split: mres.splits)\n    subgoal for a b c apply(cases b)\n      by simp\n    done\n\n\n(* TODO: again clash with type class lifting with prod for sep_algebra!\ninstantiation prod :: (monoid_add,monoid_add) monoid_add\nbegin\n\nend\n\nlemma\n  assumes \"cost_framework I1 minus1\"\n    and \"cost_framework I2 minus2\"\n  shows \"cost_framework (\\<lambda>(a,b) (c,d). I1 a c \\<and> I2 b d) (\\<lambda>(a,b) (c,d). (minus1 a c, minus2 b d))\"\n*)\n\nend\n", "meta": {"author": "lammich", "repo": "isabelle_llvm_time", "sha": "42dd7f59998d76047bb4b6bce76d8f67b53a08b6", "save_path": "github-repos/isabelle/lammich-isabelle_llvm_time", "path": "github-repos/isabelle/lammich-isabelle_llvm_time/isabelle_llvm_time-42dd7f59998d76047bb4b6bce76d8f67b53a08b6/thys/vcg/Sep_Generic_Wp.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5195213219520929, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.25773132209900823}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory SimpStrategy\nimports Main\nbegin\n\ntext \\<open>\nSupport for defining alternative simplifier strategies for some parts of terms\nor some premises of rewrite rules. The \"name\" parameter to the simp_strategy\nconstant is used to identify which simplification strategy should be used on\nthis term. Note that, although names have type nat, it is safe for them to all\nbe defined as 0. The important thing is that the simplifier doesn't know they're\nequal.\n\\<close>\n\ndefinition\n  simp_strategy :: \"nat \\<Rightarrow> ('a :: {}) \\<Rightarrow> 'a\"\nwhere\n  \"simp_strategy name x \\<equiv> x\"\n\ntext \\<open>\nThis congruence rule forbids the simplifier from simplifying the arguments of\nsimp_strategy normally.\n\\<close>\n\nlemma simp_strategy_cong[cong]:\n  \"simp_strategy name x = simp_strategy name x\"\n  by simp\n\ntext \\<open>\nThis strategy, or rather lack thereof, can be used to forbid simplification.\n\\<close>\n\ndefinition\n  NoSimp :: nat\nwhere \"NoSimp = 0\"\n\ntext \\<open>\nThis strategy indicates that a boolean subterm should be simplified only by\nusing explicit assumptions of the simpset.\n\\<close>\n\ndefinition\n  ByAssum :: nat\nwhere \"ByAssum = 0\"\n\nlemma Eq_TrueI_ByAssum:\n  \"P \\<Longrightarrow> simp_strategy ByAssum P \\<equiv> True\"\n  by (simp add: simp_strategy_def)\n\nsimproc_setup simp_strategy_ByAssum (\"simp_strategy ByAssum b\") =\n  \\<open>K (fn ss => fn ct => let\n      val b = Thm.dest_arg ct\n      val t = Thm.instantiate ([],[(((\"P\",0),@{typ bool}), b)])\n        @{thm Eq_TrueI_ByAssum}\n      val prems = Raw_Simplifier.prems_of ss\n    in get_first (try (fn p => p RS t)) prems end)\\<close>\n\nlemma ByAssum:\n  \"simp_strategy ByAssum P \\<Longrightarrow> P\"\n  by (simp add: simp_strategy_def)\n\nlemma simp_ByAssum_test:\n  \"P \\<Longrightarrow> simp_strategy ByAssum P\"\n  by simp\n\ntext \\<open>\nGeneric framework for instantiating a simproc which simplifies within a\nsimp_strategy with a given simpset.\n\nThe boolean determines whether simp_strategy Name True should be rewritten\nto True.\n\\<close>\n\nlemma simp_strategy_Eq_True:\n  \"simp_strategy name True \\<equiv> True\"\n  by (simp add: simp_strategy_def)\n\nML \\<open>\nfun simp_strategy_True_conv ct = case Thm.term_of ct of\n    (Const (@{const_name simp_strategy}, _) $ _ $ @{term True})\n      => Thm.instantiate ([], [(((\"name\",0), @{typ nat}), Thm.dest_arg1 ct)])\n          @{thm simp_strategy_Eq_True}\n  | _ => Conv.all_conv ct\n\nfun new_simp_strategy thy (name : term) ss rewr_True =\nlet\n  val ctxt = Proof_Context.init_global thy;\n  val ss = Simplifier.make_simproc ctxt (\"simp_strategy_\" ^ fst (dest_Const name))\n    {lhss = [@{term simp_strategy} $ name $ @{term x}],\n     proc = (fn _ => fn ctxt' => fn ct =>\n        ct\n        |> (Conv.arg_conv (Simplifier.rewrite (put_simpset ss ctxt'))\n          then_conv (if rewr_True then simp_strategy_True_conv\n                      else Conv.all_conv))\n        |> (fn c => if Thm.is_reflexive c then NONE else SOME c))\n     }\nin\n  ss\nend\n\\<close>\n\nend\n", "meta": {"author": "amblafont", "repo": "AutoCorres", "sha": "a8e96bff9fb22d633ff473401947ca84235d3b73", "save_path": "github-repos/isabelle/amblafont-AutoCorres", "path": "github-repos/isabelle/amblafont-AutoCorres/AutoCorres-a8e96bff9fb22d633ff473401947ca84235d3b73/lib/SimpStrategy.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5234203489363239, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.25762128574129756}}
{"text": "(*  Title:      JinjaThreads/J/WellType.thy\n    Author:     Tobias Nipkow, Andreas Lochbihler\n*)\n\nsection \\<open>Well-typedness of Jinja expressions\\<close>\n\ntheory WellType\nimports\n  Expr\n  State\n  \"../Common/ExternalCallWF\"\n  \"../Common/WellForm\"\n  \"../Common/SemiType\"\nbegin\n\ndeclare Listn.lesub_list_impl_same_size[simp del]\ndeclare listE_length [simp del]\n\ntype_synonym \n  env  = \"vname \\<rightharpoonup> ty\"\n\ninductive\n  WT :: \"(ty \\<Rightarrow> ty \\<Rightarrow> ty \\<Rightarrow> bool) \\<Rightarrow> 'addr J_prog \\<Rightarrow> env \\<Rightarrow> 'addr expr \\<Rightarrow> ty \\<Rightarrow> bool\" (\"_,_,_ \\<turnstile> _ :: _\"   [51,51,51,51]50)\n  and WTs :: \"(ty \\<Rightarrow> ty \\<Rightarrow> ty \\<Rightarrow> bool) \\<Rightarrow> 'addr J_prog \\<Rightarrow> env \\<Rightarrow> 'addr expr list \\<Rightarrow> ty list \\<Rightarrow> bool\" \n    (\"_,_,_ \\<turnstile> _ [::] _\"   [51,51,51,51]50)\n  for is_lub :: \"ty \\<Rightarrow> ty \\<Rightarrow> ty \\<Rightarrow> bool\" (\"\\<turnstile> lub'((_,/ _)') = _\" [51,51,51] 50)\n  and P :: \"'addr J_prog\"\nwhere\n\n  WTNew:\n  \"is_class P C  \\<Longrightarrow>\n  is_lub,P,E \\<turnstile> new C :: Class C\"\n\n| WTNewArray:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: Integer; is_type P (T\\<lfloor>\\<rceil>) \\<rbrakk> \\<Longrightarrow>\n  is_lub,P,E \\<turnstile> newA T\\<lfloor>e\\<rceil> :: T\\<lfloor>\\<rceil>\"\n\n| WTCast:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: T; P \\<turnstile> U \\<le> T \\<or> P \\<turnstile> T \\<le> U; is_type P U \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> Cast U e :: U\"\n\n| WTInstanceOf:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: T; P \\<turnstile> U \\<le> T \\<or> P \\<turnstile> T \\<le> U; is_type P U; is_refT U \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> e instanceof U :: Boolean\"\n\n| WTVal:\n  \"typeof v = Some T \\<Longrightarrow>\n  is_lub,P,E \\<turnstile> Val v :: T\"\n\n| WTVar:\n  \"E V = Some T \\<Longrightarrow>\n  is_lub,P,E \\<turnstile> Var V :: T\"\n\n| WTBinOp:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e1 :: T1; is_lub,P,E \\<turnstile> e2 :: T2; P \\<turnstile> T1\\<guillemotleft>bop\\<guillemotright>T2 :: T \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> e1\\<guillemotleft>bop\\<guillemotright>e2 :: T\"\n\n| WTLAss:\n  \"\\<lbrakk> E V = Some T;  is_lub,P,E \\<turnstile> e :: T';  P \\<turnstile> T' \\<le> T;  V \\<noteq> this \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> V:=e :: Void\"\n\n| WTAAcc:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> a :: T\\<lfloor>\\<rceil>; is_lub,P,E \\<turnstile> i :: Integer \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> a\\<lfloor>i\\<rceil> :: T\"\n\n| WTAAss:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> a :: T\\<lfloor>\\<rceil>; is_lub,P,E \\<turnstile> i :: Integer; is_lub,P,E \\<turnstile> e :: T'; P \\<turnstile> T' \\<le> T \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> a\\<lfloor>i\\<rceil> := e :: Void\"\n\n| WTALength:\n  \"is_lub,P,E \\<turnstile> a :: T\\<lfloor>\\<rceil> \\<Longrightarrow> is_lub,P,E \\<turnstile> a\\<bullet>length :: Integer\"\n\n| WTFAcc:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: U; class_type_of' U = \\<lfloor>C\\<rfloor>; P \\<turnstile> C sees F:T (fm) in D \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> e\\<bullet>F{D} :: T\"\n\n| WTFAss:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e\\<^sub>1 :: U; class_type_of' U = \\<lfloor>C\\<rfloor>; P \\<turnstile> C sees F:T (fm) in D; is_lub,P,E \\<turnstile> e\\<^sub>2 :: T'; P \\<turnstile> T' \\<le> T \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> e\\<^sub>1\\<bullet>F{D}:=e\\<^sub>2 :: Void\"\n\n| WTCAS:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e1 :: U; class_type_of' U = \\<lfloor>C\\<rfloor>; P \\<turnstile> C sees F:T (fm) in D; volatile fm; \n     is_lub,P,E \\<turnstile> e2 :: T'; P \\<turnstile> T' \\<le> T; is_lub,P,E \\<turnstile> e3 :: T''; P \\<turnstile> T'' \\<le> T \\<rbrakk>\n  \\<Longrightarrow>  is_lub,P,E \\<turnstile> e1\\<bullet>compareAndSwap(D\\<bullet>F, e2, e3) :: Boolean\"\n\n| WTCall:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: U; class_type_of' U = \\<lfloor>C\\<rfloor>; P \\<turnstile> C sees M:Ts \\<rightarrow> T = meth in D;\n     is_lub,P,E \\<turnstile> es [::] Ts'; P \\<turnstile> Ts' [\\<le>] Ts \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> e\\<bullet>M(es) :: T\"\n\n| WTBlock:\n  \"\\<lbrakk> is_type P T;  is_lub,P,E(V \\<mapsto> T) \\<turnstile> e :: T'; case vo of None \\<Rightarrow> True | \\<lfloor>v\\<rfloor> \\<Rightarrow> \\<exists>T'. typeof v = \\<lfloor>T'\\<rfloor> \\<and> P \\<turnstile> T' \\<le> T \\<rbrakk>\n  \\<Longrightarrow>  is_lub,P,E \\<turnstile> {V:T=vo; e} :: T'\"\n\n| WTSynchronized:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> o' :: T; is_refT T; T \\<noteq> NT; is_lub,P,E \\<turnstile> e :: T' \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> sync(o') e :: T'\"\n\n\\<comment> \\<open>Note that insync is not statically typable.\\<close>\n\n| WTSeq:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e\\<^sub>1::T\\<^sub>1;  is_lub,P,E \\<turnstile> e\\<^sub>2::T\\<^sub>2 \\<rbrakk>\n  \\<Longrightarrow>  is_lub,P,E \\<turnstile> e\\<^sub>1;;e\\<^sub>2 :: T\\<^sub>2\"\n\n| WTCond:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: Boolean;  is_lub,P,E \\<turnstile> e\\<^sub>1::T\\<^sub>1;  is_lub,P,E \\<turnstile> e\\<^sub>2::T\\<^sub>2; \\<turnstile> lub(T\\<^sub>1, T\\<^sub>2) = T \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> if (e) e\\<^sub>1 else e\\<^sub>2 :: T\"\n\n| WTWhile:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: Boolean;  is_lub,P,E \\<turnstile> c::T \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> while (e) c :: Void\"\n\n| WTThrow:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: Class C; P \\<turnstile> C \\<preceq>\\<^sup>* Throwable \\<rbrakk> \\<Longrightarrow> \n  is_lub,P,E \\<turnstile> throw e :: Void\"\n\n| WTTry:\n  \"\\<lbrakk> is_lub,P,E \\<turnstile> e\\<^sub>1 :: T;  is_lub,P,E(V \\<mapsto> Class C) \\<turnstile> e\\<^sub>2 :: T; P \\<turnstile> C \\<preceq>\\<^sup>* Throwable \\<rbrakk>\n  \\<Longrightarrow> is_lub,P,E \\<turnstile> try e\\<^sub>1 catch(C V) e\\<^sub>2 :: T\"\n\n| WTNil: \"is_lub,P,E \\<turnstile> [] [::] []\"\n\n| WTCons: \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: T; is_lub,P,E \\<turnstile> es [::] Ts \\<rbrakk> \\<Longrightarrow> is_lub,P,E \\<turnstile> e#es [::] T#Ts\"\n\nabbreviation WT' :: \"'addr J_prog \\<Rightarrow> env \\<Rightarrow> 'addr expr \\<Rightarrow> ty \\<Rightarrow> bool\" (\"_,_ \\<turnstile> _ :: _\" [51,51,51] 50)\nwhere \"WT' P \\<equiv> WT (TypeRel.is_lub P) P\"\n\nabbreviation WTs' :: \"'addr J_prog \\<Rightarrow> env \\<Rightarrow> 'addr expr list \\<Rightarrow> ty list \\<Rightarrow> bool\" (\"_,_ \\<turnstile> _ [::] _\" [51,51,51] 50)\nwhere \"WTs' P \\<equiv> WTs (TypeRel.is_lub P) P\"\n\ndeclare WT_WTs.intros[intro!]\n\ninductive_simps WTs_iffs [iff]:\n  \"is_lub',P,E \\<turnstile> [] [::] Ts\"\n  \"is_lub',P,E \\<turnstile> e#es [::] T#Ts\"\n  \"is_lub',P,E \\<turnstile> e#es [::] Ts\"\n\nlemma WTs_conv_list_all2: \n  fixes is_lub \n  shows \"is_lub,P,E \\<turnstile> es [::] Ts = list_all2 (WT is_lub P E) es Ts\"\nby(induct es arbitrary: Ts)(auto simp add: list_all2_Cons1 elim: WTs.cases)\n\nlemma WTs_append [iff]: \"\\<And>is_lub Ts. (is_lub,P,E \\<turnstile> es\\<^sub>1 @ es\\<^sub>2 [::] Ts) =\n  (\\<exists>Ts\\<^sub>1 Ts\\<^sub>2. Ts = Ts\\<^sub>1 @ Ts\\<^sub>2 \\<and> is_lub,P,E \\<turnstile> es\\<^sub>1 [::] Ts\\<^sub>1 \\<and> is_lub,P,E \\<turnstile> es\\<^sub>2[::]Ts\\<^sub>2)\"\nby(auto simp add: WTs_conv_list_all2 list_all2_append1 dest: list_all2_lengthD[symmetric])\n\ninductive_simps WT_iffs [iff]:\n  \"is_lub',P,E \\<turnstile> Val v :: T\"\n  \"is_lub',P,E \\<turnstile> Var V :: T\"\n  \"is_lub',P,E \\<turnstile> e\\<^sub>1;;e\\<^sub>2 :: T\\<^sub>2\"\n  \"is_lub',P,E \\<turnstile> {V:T=vo; e} :: T'\"\n\ninductive_cases WT_elim_cases[elim!]:\n  \"is_lub',P,E \\<turnstile> V :=e :: T\"\n  \"is_lub',P,E \\<turnstile> sync(o') e :: T\"\n  \"is_lub',P,E \\<turnstile> if (e) e\\<^sub>1 else e\\<^sub>2 :: T\"\n  \"is_lub',P,E \\<turnstile> while (e) c :: T\"\n  \"is_lub',P,E \\<turnstile> throw e :: T\"\n  \"is_lub',P,E \\<turnstile> try e\\<^sub>1 catch(C V) e\\<^sub>2 :: T\"\n  \"is_lub',P,E \\<turnstile> Cast D e :: T\"\n  \"is_lub',P,E \\<turnstile> e instanceof U :: T\"\n  \"is_lub',P,E \\<turnstile> a\\<bullet>F{D} :: T\"\n  \"is_lub',P,E \\<turnstile> a\\<bullet>F{D} := v :: T\"\n  \"is_lub',P,E \\<turnstile> e\\<bullet>compareAndSwap(D\\<bullet>F, e', e'') :: T\"\n  \"is_lub',P,E \\<turnstile> e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2 :: T\"\n  \"is_lub',P,E \\<turnstile> new C :: T\"\n  \"is_lub',P,E \\<turnstile> newA T\\<lfloor>e\\<rceil> :: T'\"\n  \"is_lub',P,E \\<turnstile> a\\<lfloor>i\\<rceil> := e :: T\"\n  \"is_lub',P,E \\<turnstile> a\\<lfloor>i\\<rceil> :: T\"\n  \"is_lub',P,E \\<turnstile> a\\<bullet>length :: T\"\n  \"is_lub',P,E \\<turnstile> e\\<bullet>M(ps) :: T\"\n  \"is_lub',P,E \\<turnstile> sync(o') e :: T\"\n  \"is_lub',P,E \\<turnstile> insync(a) e :: T\"\n\nlemma fixes is_lub :: \"ty \\<Rightarrow> ty \\<Rightarrow> ty \\<Rightarrow> bool\" (\"\\<turnstile> lub'((_,/ _)') = _\" [51,51,51] 50)\n  assumes is_lub_unique: \"\\<And>T1 T2 T3 T4. \\<lbrakk> \\<turnstile> lub(T1, T2) = T3; \\<turnstile> lub(T1, T2) = T4 \\<rbrakk> \\<Longrightarrow> T3 = T4\"\n  shows WT_unique: \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: T; is_lub,P,E \\<turnstile> e :: T' \\<rbrakk> \\<Longrightarrow> T = T'\"\n  and WTs_unique: \"\\<lbrakk> is_lub,P,E \\<turnstile> es [::] Ts; is_lub,P,E \\<turnstile> es [::] Ts' \\<rbrakk> \\<Longrightarrow> Ts = Ts'\"\napply(induct arbitrary: T' and Ts' rule: WT_WTs.inducts)\napply blast\napply blast\napply blast\napply blast\napply fastforce\napply fastforce\napply(fastforce dest: WT_binop_fun)\napply fastforce\napply fastforce\napply fastforce\napply fastforce\napply(fastforce dest: sees_field_fun)\napply(fastforce dest: sees_field_fun)\napply blast\napply(fastforce dest: sees_method_fun)\napply fastforce\napply fastforce\napply fastforce\napply(blast dest: is_lub_unique)\napply fastforce\napply fastforce\napply blast\napply fastforce\napply fastforce\ndone\n\nlemma fixes is_lub\n  shows wt_env_mono: \"is_lub,P,E \\<turnstile> e :: T \\<Longrightarrow> (\\<And>E'. E \\<subseteq>\\<^sub>m E' \\<Longrightarrow> is_lub,P,E' \\<turnstile> e :: T)\"\n  and wts_env_mono: \"is_lub,P,E \\<turnstile> es [::] Ts \\<Longrightarrow> (\\<And>E'. E \\<subseteq>\\<^sub>m E' \\<Longrightarrow> is_lub,P,E' \\<turnstile> es [::] Ts)\"\napply(induct rule: WT_WTs.inducts)\napply(simp add: WTNew)\napply(simp add: WTNewArray)\napply(fastforce simp: WTCast)\napply(fastforce simp: WTInstanceOf)\napply(fastforce simp: WTVal)\napply(simp add: WTVar map_le_def dom_def)\napply(fastforce simp: WTBinOp)\napply(force simp:map_le_def)\napply(simp add: WTAAcc)\napply(simp add: WTAAss, fastforce)\napply(simp add: WTALength, fastforce)\napply(fastforce simp: WTFAcc)\napply(fastforce simp: WTFAss del:WT_WTs.intros WT_elim_cases)\napply blast\napply(fastforce)\napply(fastforce simp: map_le_def WTBlock)\napply(fastforce simp: WTSynchronized)\napply(fastforce simp: WTSeq)\napply(fastforce simp: WTCond)\napply(fastforce simp: WTWhile)\napply(fastforce simp: WTThrow)\napply(fastforce simp: WTTry map_le_def dom_def)\napply(fastforce)+\ndone\n\nlemma fixes is_lub\n  shows WT_fv: \"is_lub,P,E \\<turnstile> e :: T \\<Longrightarrow> fv e \\<subseteq> dom E\"\n  and WT_fvs: \"is_lub,P,E \\<turnstile> es [::] Ts \\<Longrightarrow> fvs es \\<subseteq> dom E\"\napply(induct rule:WT_WTs.inducts)\napply(simp_all del: fun_upd_apply)\napply fast+\ndone\n\nlemma fixes is_lub\n  shows WT_expr_locks: \"is_lub,P,E \\<turnstile> e :: T \\<Longrightarrow> expr_locks e = (\\<lambda>ad. 0)\"\n  and WTs_expr_lockss: \"is_lub,P,E \\<turnstile> es [::] Ts \\<Longrightarrow> expr_lockss es = (\\<lambda>ad. 0)\"\nby(induct rule: WT_WTs.inducts)(auto)\n\nlemma\n  fixes is_lub :: \"ty \\<Rightarrow> ty \\<Rightarrow> ty \\<Rightarrow> bool\" (\"\\<turnstile> lub'((_,/ _)') = _\" [51,51,51] 50)\n  assumes is_lub_is_type: \"\\<And>T1 T2 T3. \\<lbrakk> \\<turnstile> lub(T1, T2) = T3; is_type P T1; is_type P T2 \\<rbrakk> \\<Longrightarrow> is_type P T3\"\n  and wf: \"wf_prog wf_md P\"\n  shows WT_is_type: \"\\<lbrakk> is_lub,P,E \\<turnstile> e :: T; ran E \\<subseteq> types P \\<rbrakk> \\<Longrightarrow> is_type P T\"\n  and WTs_is_type: \"\\<lbrakk> is_lub,P,E \\<turnstile> es [::] Ts; ran E \\<subseteq> types P \\<rbrakk> \\<Longrightarrow> set Ts \\<subseteq> types P\"\napply(induct rule: WT_WTs.inducts)\napply simp\napply simp\napply simp\napply simp\napply (simp add:typeof_lit_is_type)\napply (fastforce intro:nth_mem simp add: ran_def)\napply(simp add: WT_binop_is_type)\napply(simp)\napply(simp del: is_type_array add: is_type_ArrayD)\napply(simp)\napply(simp)\napply(simp add:sees_field_is_type[OF _ wf])\napply(simp)\napply simp\napply(fastforce dest: sees_wf_mdecl[OF wf] simp:wf_mdecl_def)\napply(fastforce simp add: ran_def split: if_split_asm)\napply(simp add: is_class_Object[OF wf])\napply(simp)\napply(simp)\napply(fastforce intro: is_lub_is_type)\napply(simp)\napply(simp)\napply simp\napply simp\napply simp\ndone\n\nlemma\n  fixes is_lub1 :: \"ty \\<Rightarrow> ty \\<Rightarrow> ty \\<Rightarrow> bool\" (\"\\<turnstile>1 lub'((_,/ _)') = _\" [51,51,51] 50)\n  and is_lub2 :: \"ty \\<Rightarrow> ty \\<Rightarrow> ty \\<Rightarrow> bool\" (\"\\<turnstile>2 lub'((_,/ _)') = _\" [51,51,51] 50)\n  assumes wf: \"wf_prog wf_md P\"\n  and is_lub1_into_is_lub2: \"\\<And>T1 T2 T3. \\<lbrakk> \\<turnstile>1 lub(T1, T2) = T3; is_type P T1; is_type P T2 \\<rbrakk> \\<Longrightarrow> \\<turnstile>2 lub(T1, T2) = T3\"\n  and is_lub2_is_type: \"\\<And>T1 T2 T3. \\<lbrakk> \\<turnstile>2 lub(T1, T2) = T3; is_type P T1; is_type P T2 \\<rbrakk> \\<Longrightarrow> is_type P T3\"\n  shows WT_change_is_lub: \"\\<lbrakk> is_lub1,P,E \\<turnstile> e :: T; ran E \\<subseteq> types P \\<rbrakk> \\<Longrightarrow> is_lub2,P,E \\<turnstile> e :: T\"\n  and WTs_change_is_lub: \"\\<lbrakk> is_lub1,P,E \\<turnstile> es [::] Ts; ran E \\<subseteq> types P \\<rbrakk> \\<Longrightarrow> is_lub2,P,E \\<turnstile> es [::] Ts\"\nproof(induct rule: WT_WTs.inducts)\n  case (WTBlock U E V e' T vo)\n  from \\<open>is_type P U\\<close> \\<open>ran E \\<subseteq> types P\\<close>\n  have \"ran (E(V \\<mapsto> U)) \\<subseteq> types P\" by(auto simp add: ran_def)\n  hence \"is_lub2,P,E(V \\<mapsto> U) \\<turnstile> e' :: T\" by(rule WTBlock)\n  with \\<open>is_type P U\\<close> show ?case\n    using \\<open>case vo of None \\<Rightarrow> True | \\<lfloor>v\\<rfloor> \\<Rightarrow> \\<exists>T'. typeof v = \\<lfloor>T'\\<rfloor> \\<and> P \\<turnstile> T' \\<le> U\\<close> by auto\nnext\n  case (WTCond E e e1 T1 e2 T2 T)\n  from \\<open>ran E \\<subseteq> types P\\<close> have \"is_lub2,P,E \\<turnstile> e :: Boolean\" \"is_lub2,P,E \\<turnstile> e1 :: T1\" \"is_lub2,P,E \\<turnstile> e2 :: T2\"\n    by(rule WTCond)+\n  moreover from is_lub2_is_type wf \\<open>is_lub2,P,E \\<turnstile> e1 :: T1\\<close> \\<open>ran E \\<subseteq> types P\\<close>\n  have \"is_type P T1\" by(rule WT_is_type)\n  from is_lub2_is_type wf \\<open>is_lub2,P,E \\<turnstile> e2 :: T2\\<close> \\<open>ran E \\<subseteq> types P\\<close>\n  have \"is_type P T2\" by(rule WT_is_type)\n  with \\<open>\\<turnstile>1 lub(T1, T2) = T\\<close> \\<open>is_type P T1\\<close>\n  have \"\\<turnstile>2 lub(T1, T2) = T\" by(rule is_lub1_into_is_lub2)\n  ultimately show ?case ..\nnext\n  case (WTTry E e1 T V C e2)\n  from \\<open>ran E \\<subseteq> types P\\<close> have \"is_lub2,P,E \\<turnstile> e1 :: T\" by(rule WTTry)\n  moreover from \\<open>P \\<turnstile> C \\<preceq>\\<^sup>* Throwable\\<close> have \"is_class P C\"\n    by(rule is_class_sub_Throwable[OF wf])\n  with \\<open>ran E \\<subseteq> types P\\<close> have \"ran (E(V \\<mapsto> Class C)) \\<subseteq> types P\"\n    by(auto simp add: ran_def)\n  hence \"is_lub2,P,E(V \\<mapsto> Class C) \\<turnstile> e2 :: T\" by(rule WTTry)\n  ultimately show ?case using \\<open>P \\<turnstile> C \\<preceq>\\<^sup>* Throwable\\<close> ..\nqed auto\n\nsubsection \\<open>Code generator setup\\<close>\n\nlemma WTBlock_code:\n  \"\\<And>is_lub. \\<lbrakk> is_type P T; is_lub,P,E(V \\<mapsto> T) \\<turnstile> e :: T'; \n     case vo of None \\<Rightarrow> True | \\<lfloor>v\\<rfloor> \\<Rightarrow> case typeof v of None \\<Rightarrow> False | Some T' \\<Rightarrow> P \\<turnstile> T' \\<le> T \\<rbrakk>\n  \\<Longrightarrow>  is_lub,P,E \\<turnstile> {V:T=vo; e} :: T'\"\nby(auto)\n\nlemmas [code_pred_intro] =\n  WTNew WTNewArray WTCast WTInstanceOf WTVal WTVar WTBinOp WTLAss WTAAcc WTAAss WTALength WTFAcc WTFAss WTCAS WTCall \ndeclare \n  WTBlock_code [code_pred_intro WTBlock']\nlemmas [code_pred_intro] =\n  WTSynchronized WTSeq WTCond WTWhile WTThrow WTTry\n  WTNil WTCons\n\ncode_pred\n  (modes:\n    (i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool) \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool, \n    (i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool) \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool)\n  [detect_switches, skip_proof]\n  WT\nproof -\n  case WT\n  from WT.prems show thesis\n  proof cases\n    case (WTBlock T V e vo)\n    thus thesis using WT.WTBlock'[OF refl refl refl, of V T vo e] by(auto)\n  qed(assumption|erule WT.that[OF refl refl refl]|rule refl)+\nnext\n  case WTs\n  from WTs.prems WTs.that show thesis by cases blast+\nqed\n\ninductive is_lub_sup :: \"'m prog \\<Rightarrow> ty \\<Rightarrow> ty \\<Rightarrow> ty \\<Rightarrow> bool\"\nfor P T1 T2 T3\nwhere\n  \"sup P T1 T2 = OK T3 \\<Longrightarrow> is_lub_sup P T1 T2 T3\"\n\ncode_pred\n  (modes: i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool, i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool)\n  is_lub_sup\n.\n\ndefinition WT_code :: \"'addr J_prog \\<Rightarrow> env \\<Rightarrow> 'addr expr \\<Rightarrow> ty \\<Rightarrow> bool\" (\"_,_ \\<turnstile> _ ::'' _\" [51,51,51] 50)\nwhere \"WT_code P \\<equiv> WT (is_lub_sup P) P\"\n\ndefinition WTs_code :: \"'addr J_prog \\<Rightarrow> env \\<Rightarrow> 'addr expr list \\<Rightarrow> ty list \\<Rightarrow> bool\" (\"_,_ \\<turnstile> _ [::''] _\" [51,51,51] 50)\nwhere \"WTs_code P \\<equiv> WTs (is_lub_sup P) P\"\n\nlemma assumes wf: \"wf_prog wf_md P\"\n  shows WT_code_into_WT: \n  \"\\<lbrakk> P,E \\<turnstile> e ::' T; ran E \\<subseteq> types P \\<rbrakk> \\<Longrightarrow> P,E \\<turnstile> e :: T\"\n\n  and WTs_code_into_WTs:\n  \"\\<lbrakk> P,E \\<turnstile> es [::'] Ts; ran E \\<subseteq> types P \\<rbrakk> \\<Longrightarrow> P,E \\<turnstile> es [::] Ts\"\nproof -\n  assume ran: \"ran E \\<subseteq> types P\"\n  { assume wt: \"P,E \\<turnstile> e ::' T\"\n    show \"P,E \\<turnstile> e :: T\"\n      by(rule WT_change_is_lub[OF wf _ _ wt[unfolded WT_code_def] ran])(blast elim!: is_lub_sup.cases intro: sup_is_lubI[OF wf] is_lub_is_type[OF wf])+ }\n  { assume wts: \"P,E \\<turnstile> es [::'] Ts\"\n    show \"P,E \\<turnstile> es [::] Ts\"\n      by(rule WTs_change_is_lub[OF wf _ _ wts[unfolded WTs_code_def] ran])(blast elim!: is_lub_sup.cases intro: sup_is_lubI[OF wf] is_lub_is_type[OF wf])+ }\nqed\n\nlemma assumes wf: \"wf_prog wf_md P\"\n  shows WT_into_WT_code: \n  \"\\<lbrakk> P,E \\<turnstile> e :: T; ran E \\<subseteq> types P \\<rbrakk> \\<Longrightarrow> P,E \\<turnstile> e ::' T\"\n\n  and WT_into_WTs_code_OK:\n  \"\\<lbrakk> P,E \\<turnstile> es [::] Ts; ran E \\<subseteq> types P \\<rbrakk> \\<Longrightarrow> P,E \\<turnstile> es [::'] Ts\"\nproof -\n  assume ran: \"ran E \\<subseteq> types P\"\n  { assume wt: \"P,E \\<turnstile> e :: T\"\n    show \"P,E \\<turnstile> e ::' T\" unfolding WT_code_def\n      by(rule WT_change_is_lub[OF wf _ _ wt ran])(blast intro!: is_lub_sup.intros intro: is_lub_subD[OF wf] sup_is_type[OF wf] elim!: is_lub_sup.cases)+ }\n  { assume wts: \"P,E \\<turnstile> es [::] Ts\"\n    show \"P,E \\<turnstile> es [::'] Ts\" unfolding WTs_code_def\n      by(rule WTs_change_is_lub[OF wf _ _ wts ran])(blast intro!: is_lub_sup.intros intro: is_lub_subD[OF wf] sup_is_type[OF wf] elim!: is_lub_sup.cases)+ }\nqed\n\ntheorem WT_eq_WT_code:\n  assumes \"wf_prog wf_md P\"\n  and \"ran E \\<subseteq> types P\"\n  shows \"P,E \\<turnstile> e :: T \\<longleftrightarrow> P,E \\<turnstile> e ::' T\"\nusing assms by(blast intro: WT_code_into_WT WT_into_WT_code)\n\ncode_pred\n  (modes: i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool, i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool)\n  [inductify]\n  WT_code \n.\n\ncode_pred\n  (modes: i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> bool, i \\<Rightarrow> i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool)\n  [inductify]\n  WTs_code \n.\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/JinjaThreads/J/WellType.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6442251064863697, "lm_q2_score": 0.399811640739795, "lm_q1q2_score": 0.2575686968300846}}
{"text": "theory sas_analysis\nimports \"sas\" \"DFP.DFP_law_DFtick\"\nbegin\n\n\n\ndeclare inj_def [simp add]\ndeclare Let_def [simp add]\n\ndeclare Rec_prefix_def [simp add]\ndeclare Send_prefix_def [simp add]\n\nlemma rawPosition_Int_adjust_eq_empty [simp]: \"{| rawPosition i |}\\<^sub>c \\<inter> {| adjust i |}\\<^sub>c = {}\"\n  by (auto)\n\n\nlemma rawPosition_Int_servoCmd_eq_empty [simp]: \"{| rawPosition i |}\\<^sub>c \\<inter> {| servoCmd i |}\\<^sub>c = {}\"\n  by (auto)\n\n\nlemma adjust_DONT_Renames_rawPosition [simp]: \"a \\<in> {| rawPosition i |}\\<^sub>c \\<Longrightarrow>\n       {x::Events \\<in> {| rawPosition i |}\\<^sub>c.\n                      (x, a) \\<in> ehsvOutput i<==adjust i} = { a }\"\n  apply (simp add: Renaming2_channel_def Renaming2_channel_fun_def fun_to_rel_def Image_def)\n  by (auto)\n\n\nlemma adjust_DONT_Renames_servoCmd [simp]: \"a \\<in> {| servoCmd i |}\\<^sub>c \\<Longrightarrow>\n       {x::Events \\<in> {| servoCmd i |}\\<^sub>c.\n                      (x, a) \\<in> ehsvOutput i<==adjust i} = { a }\"\n  apply (simp add: Renaming2_channel_def Renaming2_channel_fun_def fun_to_rel_def Image_def)\n  by (auto)\n\n\nlemma unwind_EHSV : \"$EHSV i [[ ehsvOutput i <== adjust i ]] =F\n            ? p:{| rawPosition(i) |}\\<^sub>c -> ? e:{| servoCmd(i) |}\\<^sub>c -> ? f:{ adjust(i) ((inv (rawPosition i) p) - disp (dOmega (inv (servoCmd i) e))) } -> $EHSV i [[ ehsvOutput i <== adjust i ]]\"\n  apply (cspF_unwind_left, simp_all, cspF_ren_left)\n  by (rule cspF_decompo, simp, cspF_step_left, cspF_step_left, cspF_ren_left)+\n\n\nlemma unwind_Raw : \"$Raw i p0 =F ? p:{ rawPosition(i) p0 } -> (? p:{ rawPosition(i) p0 } -> $Raw i p0\n                                                               [+] (? adj:{| adjust(i) |}\\<^sub>c \\<rightarrow> $Raw i (saturate (p0 + (inv (adjust i) adj))) ))\n                                 [+] (? adj:{| adjust(i) |}\\<^sub>c \\<rightarrow> $Raw i (saturate (p0 + (inv (adjust i) adj))) )\"\n  apply (cspF_unwind_left, cspF_hsf_left)\n  apply (rule cspF_decompo, simp)\n  apply (rule cspF_decompo, simp)\n  by (cspF_unwind_left)\n\n\nlemma feedbackPos_DONT_Renames_rawPosition [simp]: \"a \\<in> {| rawPosition i |}\\<^sub>c \\<Longrightarrow>\n       {x::Events \\<in> {| rawPosition i |}\\<^sub>c.\n                      (x, a) \\<in> lvdtOutput i<==feedbackPos i} = { a }\"\n  apply (simp add: Renaming2_channel_def Renaming2_channel_fun_def fun_to_rel_def Image_def)\n  by (auto)\n\n\nlemma rawPosition_Renaming_coreMoved_simp [simp]: \"a \\<in> {| rawPosition i |}\\<^sub>c \\<Longrightarrow>\n       {x::Events \\<in> {| coreMoved i |}\\<^sub>c.\n                      (x, a) \\<in> coreMoved i<==rawPosition i} = { coreMoved i (inv (rawPosition i) a) }\"\n  apply (simp add: Renaming2_channel_def Renaming2_channel_fun_def fun_to_rel_def Image_def)\n  by (auto)\n\nlemma unwind_LVDT : \"$LVDT i [[coreMoved i<==rawPosition i]] [[lvdtOutput i<==feedbackPos i]] =F\n            ? p:{| rawPosition(i) |}\\<^sub>c \\<rightarrow> ? f:{ feedbackPos i (inv (rawPosition i) p) } \\<rightarrow> $LVDT i [[ coreMoved i <== rawPosition i ]] [[ lvdtOutput i <== feedbackPos i ]]\"\n  apply (cspF_unwind_left, cspF_step_left, cspF_step_left)\n  apply (rule cspF_decompo, simp, erule rangeE)\n  by (cspF_step_left)+\n\n\n\nlemma unwind_PCU : \"PCU i p0 =F (\n              ? p:{| rawPosition(i) |}\\<^sub>c -> ? e:{| servoCmd(i) |}\\<^sub>c -> ? f:{ adjust(i) ((inv (rawPosition i) p) - disp (dOmega (inv (servoCmd i) e))) } -> $EHSV i [[ ehsvOutput i <== adjust i ]]\n              |[ {| rawPosition i, adjust i |}\\<^sub>c ]|\n              ( ? p:{ rawPosition(i) p0 } -> (? p:{ rawPosition(i) p0 } -> $Raw i p0\n                                        [+] (? adj:{| adjust(i) |}\\<^sub>c \\<rightarrow> $Raw i (saturate (p0 + (inv (adjust i) adj))) ))\n                [+] (? adj:{| adjust(i) |}\\<^sub>c \\<rightarrow> $Raw i (saturate (p0 + (inv (adjust i) adj))) ))\n            )\n            |[ {| rawPosition i |}\\<^sub>c ]|\n            ( ? p:{| rawPosition(i) |}\\<^sub>c \\<rightarrow> (? f:{ feedbackPos(i) (modulate (senseVoltage (inv (rawPosition i) p))) } -> ($LVDT i [[ coreMoved i <== rawPosition i ]] [[ lvdtOutput i <== feedbackPos i ]])) )\"\n\n  apply (simp add: PCU_def)\n  apply (rule cspF_decompo, simp)\n  apply (rule cspF_decompo, simp)\n  apply (rule unwind_EHSV)\n  apply (rule unwind_Raw)\n  apply (rule unwind_LVDT)\n  done\n\n\nlemma unwind_ACE : \"$ACE i =F (? p:{| controlCmd(i) |}\\<^sub>c -> ? f:{| feedbackPos(i) |}\\<^sub>c ->\n                              ? x:{ servoCmd(i) (saturate((inv (controlCmd i) p) - (inv (feedbackPos i) f))) } -> $ACE i)\"\n  by (cspF_auto)\n\n\n\n\n\n\nlemma unwind_ACE_PCU :\n    \"ACE_PCU i p0 =F\n            (? p:{| controlCmd(i) |}\\<^sub>c -> ? f:{| feedbackPos(i) |}\\<^sub>c ->\n                              ? x:{ servoCmd(i) (saturate((inv (controlCmd i) p) - (inv (feedbackPos i) f))) } -> $ACE i)\n            |[ {| servoCmd i, feedbackPos i |}\\<^sub>c ]|\n            ((? p:{| rawPosition(i) |}\\<^sub>c -> ? e:{| servoCmd(i) |}\\<^sub>c -> ? f:{ adjust(i) ((inv (rawPosition i) p) - disp (dOmega (inv (servoCmd i) e))) } -> $EHSV i [[ ehsvOutput i <== adjust i ]]\n              |[ {| rawPosition i, adjust i |}\\<^sub>c ]|\n              ( ? p:{ rawPosition(i) p0 } -> (? p:{ rawPosition(i) p0 } -> $Raw i p0\n                                        [+] (? adj:{| adjust(i) |}\\<^sub>c \\<rightarrow> $Raw i (saturate (p0 + (inv (adjust i) adj))) ))\n                [+] (? adj:{| adjust(i) |}\\<^sub>c \\<rightarrow> $Raw i (saturate (p0 + (inv (adjust i) adj))) ))\n             )\n             |[ {| rawPosition i |}\\<^sub>c ]|\n             ( ? p:{| rawPosition(i) |}\\<^sub>c \\<rightarrow> (? f:{ feedbackPos(i) (modulate (senseVoltage (inv (rawPosition i) p))) } -> ($LVDT i [[ coreMoved i <== rawPosition i ]] [[ lvdtOutput i <== feedbackPos i ]])) ))\"\n\n  apply (simp add: ACE_PCU_def)\n  apply (rule cspF_rw_left, rule cspF_decompo, simp, rule unwind_ACE)\n  apply (rule unwind_PCU)\n  by (cspF_hsf)\n\n\n\n\n\n\n\n\ndefinition PCUadj\nwhere \"PCUadj i aa adj ==\n       ? x:{adjust i adj} \n        -> ( ($EHSV i [[ehsvOutput i<==adjust i]] \n             |[{| rawPosition i, adjust i |}\\<^sub>c]|\n             $Raw i (saturate (aa + inv (adjust i) x)) \n             |[{| rawPosition i |}\\<^sub>c]|\n             $LVDT i [[coreMoved i<==rawPosition i]] [[lvdtOutput i<==feedbackPos i]]))\"\n\n\ndefinition ACE_PCUadj\nwhere \"ACE_PCUadj i aa adj == $ACE i |[{| servoCmd i, feedbackPos i |}\\<^sub>c]| PCUadj i aa adj\"\n\n\n\nlemma unwind_ACE_PCUadj :\n    \"$ACE i |[{| servoCmd i, feedbackPos i |}\\<^sub>c]| PCUadj i aa adj =F \n       (? p:{| controlCmd(i) |}\\<^sub>c -> ? f:{| feedbackPos(i) |}\\<^sub>c ->\n                              ? x:{ servoCmd(i) (saturate((inv (controlCmd i) p) - (inv (feedbackPos i) f))) } -> $ACE i)\n       |[{| servoCmd i, feedbackPos i |}\\<^sub>c]|\n       ? x:{adjust i adj} -> (($EHSV i [[ehsvOutput i<==adjust i]] \n                             |[{| rawPosition i, adjust i |}\\<^sub>c]|\n                             $Raw i (saturate (aa + inv (adjust i) x)) \n                             |[{| rawPosition i |}\\<^sub>c]|\n                             $LVDT i [[coreMoved i<==rawPosition i]] [[lvdtOutput i<==feedbackPos i]]))\"\n  \n  apply (rule cspF_decompo, simp)\n  apply (rule unwind_ACE)\n  apply (simp add: PCUadj_def)\n  done\n\n\n\ndeclare inj_def [simp del]\ndeclare Let_def [simp del]\n\ndeclare Rec_prefix_def [simp del]\ndeclare Send_prefix_def [simp del]\n\n\nend", "meta": {"author": "jbjj", "repo": "jbjj.github.io", "sha": "1b7e124895eb11189cc92b3cc3f7ad2565d3ed3c", "save_path": "github-repos/isabelle/jbjj-jbjj.github.io", "path": "github-repos/isabelle/jbjj-jbjj.github.io/jbjj.github.io-1b7e124895eb11189cc92b3cc3f7ad2565d3ed3c/publications/sbmf2022/sas_analysis.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6150878696277514, "lm_q2_score": 0.4186969093556867, "lm_q1q2_score": 0.25753538999531306}}
{"text": "theory Review_RAut_NCPC_PAut\nimports \"../Observation_Setup\" Review_Value_Setup \"Bounded_Deducibility_Security.Compositional_Reasoning\"\nbegin\n\nsubsection \\<open>Confidentiality from users who are not the review's author, a PC member, or an author of the paper\\<close>\n\ntext \\<open>We verify the following property:\n\n\\ \\\\\nA group of users UIDs learn nothing\nabout the various updates to the N'th review of a paper PID\n(save for the inexistence of any updates) unless/until\n\\begin{itemize}\n\\item a user in UIDs is the review's author, or\n\\item a user in UIDs becomes a PC member in the paper's conference\nhaving no conflict with that paper and the\nconference moves to the discussion phase, or\n\\item a user in UIDs become a PC member in the paper's conference\nor an author of the paper and the conference moves to the notification phase\n\\end{itemize}\n\\<close>\n\ntype_synonym \"value\" = rcontent\n\nfun f :: \"(state,act,out) trans \\<Rightarrow> value\" where\n\"f (Trans _ (Uact (uReview cid uid p pid n rc)) _ _) = rc\"\n|\n\"f (Trans _ (UUact (uuReview cid uid p pid n rc)) _ _) = rc\"\n\nfun T :: \"(state,act,out) trans \\<Rightarrow> bool\" where\n\"T (Trans _ _ ou s') =\n (\\<exists> uid \\<in> UIDs.\n    isREVNth s' uid PID N\n    \\<or>\n    (\\<exists> cid. PID \\<in>\\<in> paperIDs s' cid \\<and> isPC s' cid uid \\<and> pref s' uid PID \\<noteq> Conflict \\<and> phase s' cid \\<ge> disPH)\n    \\<or>\n    (\\<exists> cid. PID \\<in>\\<in> paperIDs s' cid \\<and> isPC s' cid uid \\<and> phase s' cid \\<ge> notifPH)\n    \\<or>\n    isAUT s' uid PID \\<and> (\\<exists> cid. PID \\<in>\\<in> paperIDs s' cid \\<and> phase s' cid \\<ge> notifPH)\n )\"\n\ndeclare T.simps [simp del]\n\ndefinition B :: \"value list \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"B vl vl1 \\<equiv> vl \\<noteq> []\"\n\ninterpretation BD_Security_IO where\nistate = istate and step = step and\n\\<phi> = \\<phi> and f = f and \\<gamma> = \\<gamma> and g = g and T = T and B = B\ndone\n\nlemma reachNT_non_isPC_isChair:\nassumes \"reachNT s\" and \"uid \\<in> UIDs\"\nshows\n\"\\<not> isRevNth s cid uid PID N \\<and>\n (PID \\<in>\\<in> paperIDs s cid \\<and> isPC s cid uid \\<longrightarrow>\n    (pref s uid PID = Conflict \\<or> phase s cid < disPH) \\<and> phase s cid < notifPH) \\<and>\n (PID \\<in>\\<in> paperIDs s cid \\<and> isChair s cid uid \\<longrightarrow>\n    (pref s uid PID = Conflict \\<or> phase s cid < disPH) \\<and> phase s cid < notifPH) \\<and>\n (isAut s cid uid PID \\<longrightarrow> phase s cid < notifPH)\"\nusing assms apply induct\napply (auto simp: istate_def)[]\napply(intro conjI)\n  subgoal for trn apply(cases trn, simp add: T.simps reachNT_reach isAUT_def isREVNth_def)[] .\n  subgoal for trn apply(cases trn, simp add: T.simps reachNT_reach isAUT_def isREVNth_def)[]\n    apply (metis not_less) .\n  subgoal for trn apply(cases trn, simp add: T.simps reachNT_reach isAUT_def isREVNth_def)[]\n    apply (metis isChair_isPC not_less reachNT_reach reach_PairI) .\n  subgoal for trn apply(cases trn, simp add: T.simps reachNT_reach isAUT_def isREVNth_def)[]\n    apply (metis isAut_paperIDs not_less reachNT_reach reach_PairI) .\ndone\n\nlemma T_\\<phi>_\\<gamma>:\nassumes 1: \"reachNT s\" and 2: \"step s a = (ou,s')\" \"\\<phi> (Trans s a ou s')\"\nshows \"\\<not> \\<gamma> (Trans s a ou s')\"\nusing reachNT_non_isPC_isChair[OF 1] 2 unfolding T.simps \\<phi>_def2\napply (auto simp: u_defs uu_defs isRev_imp_isRevNth_getReviewIndex)\nby (metis isRev_imp_isRevNth_getReviewIndex)+\n\n(* major *) lemma eqExcPID_N_step_out:\nassumes s's1': \"eqExcPID_N s s1\"\nand step: \"step s a = (ou,s')\" and step1: \"step s1 a = (ou1,s1')\"\nand sT: \"reachNT s\" and s1: \"reach s1\"\nand PID: \"PID \\<in>\\<in> paperIDs s cid\"\nand UIDs: \"userOfA a \\<in> UIDs\"\nshows \"ou = ou1\"\nproof-\n  note s = reachNT_reach[OF sT]\n  note Inv = reachNT_non_isPC_isChair[OF sT UIDs]\n  note eqs = eqExcPID_N_imp[OF s's1']\n  note eqs' = eqExcPID_N_imp1[OF s's1']\n  note eqss = eqExcPID_N_imp2[OF s's1'] eqExcPID_N_imp3'[OF s s's1']\n\n  note simps[simp] = c_defs u_defs uu_defs r_defs l_defs Paper_dest_conv eqExcPID_N_def eeqExcPID_N_def eqExcD\n  note * = step step1 eqs eqs' eqss s s1 UIDs PID paperIDs_equals[OF s] Inv\n\n  show ?thesis\n  proof (cases a)\n    case (Cact x1)\n    with * show ?thesis by (cases x1; auto)\n  next\n    case (Uact x2)\n    with * show ?thesis by (cases x2; auto)\n  next\n    case (UUact x3)\n    with * show ?thesis by (cases x3; auto)\n  next\n    case (Ract x4)\n    with * show ?thesis\n    proof (cases x4)\n      case (rMyReview x81 x82 x83 x84)\n      with Ract * show ?thesis\n        by clarsimp (metis getRevRole_Some_Rev_isRevNth)\n    next\n      case (rReviews x91 x92 x93 x94)\n      with Ract * show ?thesis\n        by clarsimp (metis not_less)\n    next\n      case (rFinalReviews x121 x122 x123 x124)\n      with Ract * show ?thesis\n        by clarsimp (metis not_less)\n    qed auto\n  next\n    case (Lact x5)\n    with * show ?thesis by (cases x5; auto; presburger)\n  qed\nqed\n\ndefinition \\<Delta>1 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>1 s vl s1 vl1 \\<equiv>\n (\\<forall> cid. PID \\<in>\\<in> paperIDs s cid \\<longrightarrow> phase s cid < revPH) \\<and> s = s1 \\<and> B vl vl1\"\n\ndefinition \\<Delta>2 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>2 s vl s1 vl1 \\<equiv>\n \\<exists> cid.\n   PID \\<in>\\<in> paperIDs s cid \\<and> phase s cid = revPH \\<and>\n   \\<not> (\\<exists> uid. isREVNth s uid PID N) \\<and>\n   s = s1 \\<and> B vl vl1\"\n\n(* Note: In the similar property from discussion confidentiality we have only 3 non-exit phases\ninstead of 4, not having a phase like \\<Delta>2: this is because there the agent affecting the documents (chairs),\nmust have been assigned in a previous phase; here reviewers are assigned in the same phase\nin which they can edit.   *)\n\ndefinition \\<Delta>3 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>3 s vl s1 vl1 \\<equiv>\n \\<exists> cid uid. PID \\<in>\\<in> paperIDs s cid \\<and> phase s cid = revPH \\<and> isREVNth s uid PID N \\<and> eqExcPID_N s s1\"\n\ndefinition \\<Delta>4 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>4 s vl s1 vl1 \\<equiv>\n \\<exists> cid. PID \\<in>\\<in> paperIDs s cid \\<and> phase s cid > revPH \\<and> eqExcPID_N s s1 \\<and> vl1 = []\"\n\ndefinition \\<Delta>e :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>e s vl s1 vl1 \\<equiv>\n vl \\<noteq> [] \\<and>\n (\\<exists> cid. PID \\<in>\\<in> paperIDs s cid \\<and> phase s cid > revPH \\<and> \\<not> (\\<exists> uid. isREVNth s uid PID N))\"\n\nlemma istate_\\<Delta>1:\nassumes B: \"B vl vl1\"\nshows \"\\<Delta>1 istate vl istate vl1\"\nusing B unfolding \\<Delta>1_def B_def istate_def by auto\n\nlemma unwind_cont_\\<Delta>1: \"unwind_cont \\<Delta>1 {\\<Delta>1,\\<Delta>2,\\<Delta>e}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>1 s vl s1 vl1 \\<or> \\<Delta>2 s vl s1 vl1 \\<or> \\<Delta>e s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \"\\<Delta>1 s vl s1 vl1\"\n  hence rs: \"reach s\" and ss1: \"s1 = s\" and vl: \"vl \\<noteq> []\"\n  and PID_ph: \"\\<And> cid. PID \\<in>\\<in> paperIDs s cid \\<Longrightarrow> phase s cid < revPH\"\n  using reachNT_reach unfolding \\<Delta>1_def B_def by auto\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof-\n    have ?react proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\"  let ?trn1 = \"Trans s1 a ou s'\"\n      assume step: \"step s a = (ou, s')\" and T: \"\\<not> T ?trn\" and c: \"consume ?trn vl vl'\"\n      have \\<phi>: \"\\<not> \\<phi> ?trn\"\n        apply(cases a)\n        subgoal by simp\n        subgoal for x2 apply(cases x2) using step PID_ph by (fastforce simp: u_defs)+\n        subgoal for x3 apply(cases x3) using step PID_ph by (fastforce simp: uu_defs)+\n        by simp_all\n      hence vl': \"vl' = vl\" using c unfolding consume_def by auto\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n      proof-\n        have ?match proof\n          show \"validTrans ?trn1\" unfolding ss1 using step by simp\n        next\n          show \"consume ?trn1 vl1 vl1\" unfolding consume_def ss1 using \\<phi> by auto\n        next\n          show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n        next\n          assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\" unfolding ss1 by simp\n        next\n          show \"?\\<Delta> s' vl' s' vl1\"\n          proof(cases \"\\<exists> cid. PID \\<in>\\<in> paperIDs s cid\")\n            case False note PID = False\n            have PID_ph': \"\\<And> cid. PID \\<in>\\<in> paperIDs s' cid \\<Longrightarrow> phase s' cid < revPH\" using PID step rs\n            apply(cases a)\n              subgoal for _ x1 apply(cases x1) apply(fastforce simp: c_defs)+ .\n              subgoal for _ x2 apply(cases x2) apply(fastforce simp: u_defs)+ .\n              subgoal for _ x3 apply(cases x3) apply(fastforce simp: uu_defs)+ .\n              by auto\n            hence \"\\<Delta>1 s' vl' s' vl1\" unfolding \\<Delta>1_def B_def vl' using PID_ph' vl by auto\n            thus ?thesis by auto\n          next\n            case True\n            then obtain CID where PID: \"PID \\<in>\\<in> paperIDs s CID\" by auto\n            hence ph: \"phase s CID < revPH\" using PID_ph by auto\n            have PID': \"PID \\<in>\\<in> paperIDs s' CID\" by (metis PID paperIDs_mono step)\n            show ?thesis\n            proof(cases \"phase s' CID < revPH\")\n              case True note ph' = True\n              hence \"\\<Delta>1 s' vl' s' vl1\" unfolding \\<Delta>1_def B_def vl' using vl ph' PID' apply auto\n              by (metis reach_PairI paperIDs_equals rs step)\n              thus ?thesis by auto\n            next\n              case False note ph' = False\n              have \"\\<not> (\\<exists> uid. isRevNth s CID uid PID N)\" using rs ph isRevNth_geq_revPH by fastforce\n              hence ph_isRev': \"phase s' CID = revPH \\<and> \\<not> (\\<exists> uid. isRevNth s' CID uid PID N)\"\n              using ph' ph PID step rs\n              apply(cases a)\n                subgoal for x1 apply(cases x1) apply(fastforce simp: c_defs)+ .\n                subgoal for x2 apply(cases x2) apply(fastforce simp: u_defs)+ .\n                subgoal for x3 apply(cases x3) apply(fastforce simp: uu_defs)+ .\n              by auto\n              hence \"\\<not> (\\<exists> uid. isREVNth s' uid PID N)\"\n              by (metis PID' isREVNth_imp_isRevNth reach_PairI rs1 ss1 step)\n              hence \"\\<Delta>2 s' vl' s' vl1\"\n              unfolding \\<Delta>2_def B_def isREVNth_def vl' using vl ph' PID' ph_isRev' by auto\n              thus ?thesis by auto\n            qed\n          qed\n        qed\n        thus ?thesis by simp\n      qed\n    qed\n    thus ?thesis using vl by auto\n  qed\nqed\n\nlemma unwind_cont_\\<Delta>2: \"unwind_cont \\<Delta>2 {\\<Delta>2,\\<Delta>3,\\<Delta>e}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>2 s vl s1 vl1 \\<or> \\<Delta>3 s vl s1 vl1 \\<or> \\<Delta>e s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \"\\<Delta>2 s vl s1 vl1\"\n  then obtain CID where rs: \"reach s\" and ph: \"phase s CID = revPH\" (is \"?ph = _\")\n  and PID: \"PID \\<in>\\<in> paperIDs s CID\" and ss1: \"s1 = s\"\n  and vl: \"vl \\<noteq> []\" and uid: \"\\<not> (\\<exists> uid. isREVNth s uid PID N)\"\n  using reachNT_reach unfolding \\<Delta>2_def B_def by auto\n  hence uid: \"\\<not> (\\<exists> uid. isRevNth s CID uid PID N)\" by (metis isREVNth_def)\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof-\n    have ?react proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\"  let ?trn1 = \"Trans s1 a ou s'\"\n      let ?ph' = \"phase s' CID\"\n      assume step: \"step s a = (ou, s')\" and T: \"\\<not> T ?trn\" and c: \"consume ?trn vl vl'\"\n      have \\<phi>: \"\\<not> \\<phi> ?trn\"\n        apply(cases a)\n        subgoal by simp\n        subgoal for x2 apply(cases x2)\n          using step ph uid apply (auto simp: u_defs isRev_def3)\n          by (metis PID paperIDs_equals rs)\n        subgoal for x3 apply(cases x3)\n          using step ph apply (auto simp: uu_defs)\n          by (metis PID n_not_Suc_n paperIDs_equals rs)\n        by simp_all\n      hence vl': \"vl' = vl\" using c unfolding consume_def by auto\n      have PID': \"PID \\<in>\\<in> paperIDs s' CID\" by (metis paperIDs_mono step PID)\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n      proof-\n        have ?match proof\n          show \"validTrans ?trn1\" unfolding ss1 using step by simp\n        next\n          show \"consume ?trn1 vl1 vl1\" unfolding consume_def ss1 using \\<phi> by auto\n        next\n          show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n        next\n          assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\" unfolding ss1 by simp\n        next\n          show \"?\\<Delta> s' vl' s' vl1\"\n          proof(cases \"?ph' = revPH\")\n            case True note ph' = True\n            show ?thesis\n            proof(cases \"\\<exists> uid. isRevNth s' CID uid PID N\")\n              case False\n              hence \"\\<not> (\\<exists> uid. isREVNth s' uid PID N)\"\n              by (metis reach_PairI PID' isREVNth_imp_isRevNth rs1 ss1 step)\n              hence \"\\<Delta>2 s' vl' s' vl1\" unfolding \\<Delta>2_def B_def vl' using vl ph' PID' by auto\n              thus ?thesis by auto\n            next\n              case True  hence \"\\<exists> uid. isREVNth s' uid PID N\" by (metis isREVNth_def)\n              hence \"\\<Delta>3 s' vl' s' vl1\" unfolding \\<Delta>3_def vl' using vl ph' PID' by auto\n              thus ?thesis by auto\n            qed\n          next\n            case False hence 1: \"?ph' > revPH \\<and> \\<not> (\\<exists> uid. isRevNth s' CID uid PID N)\"\n              using PID ph uid step rs\n              apply(cases a)\n              subgoal for x1 apply(cases x1) apply(fastforce simp: c_defs)+ .\n              subgoal for x2 apply(cases x2) apply(fastforce simp: u_defs)+ .\n              subgoal for x3 apply(cases x3) apply(fastforce simp: uu_defs)+ .\n              by auto\n            hence \"\\<not> (\\<exists> uid. isREVNth s' uid PID N)\"\n            by (metis reach_PairI PID' isREVNth_imp_isRevNth rs1 ss1 step)\n            hence \"\\<Delta>e s' vl' s' vl1\" unfolding \\<Delta>e_def vl' using vl PID' 1 by auto\n            thus ?thesis by auto\n          qed\n        qed\n        thus ?thesis by simp\n      qed\n    qed\n    thus ?thesis using vl by simp\n  qed\nqed\n\nlemma unwind_cont_\\<Delta>3: \"unwind_cont \\<Delta>3 {\\<Delta>3,\\<Delta>4,\\<Delta>e}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>3 s vl s1 vl1 \\<or> \\<Delta>4 s vl s1 vl1 \\<or> \\<Delta>e s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \"\\<Delta>3 s vl s1 vl1\"\n  then obtain CID uid where uuid: \"isREVNth s uid PID N\"\n  and rs: \"reach s\" and ph: \"phase s CID = revPH\" (is \"?ph = _\") and ss1: \"eqExcPID_N s s1\"\n  and PID: \"PID \\<in>\\<in> paperIDs s CID\" using reachNT_reach unfolding \\<Delta>3_def by blast\n  hence uid: \"isRevNth s CID uid PID N\" by (metis isREVNth_imp_isRevNth)\n  hence uid_notin: \"uid \\<notin> UIDs\" using reachNT_non_isPC_isChair[OF rsT] by auto\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof(cases vl1)\n    case (Cons v1 vl1') note vl1 = Cons\n    have uid1: \"isRevNth s CID uid PID N\" using ss1 uid unfolding eqExcPID_N_def by auto\n    define a1 where \"a1 \\<equiv> Uact (uReview CID uid (pass s uid) PID N v1)\"\n    obtain s1' ou1 where step1: \"step s1 a1 = (ou1,s1')\" by (metis prod.exhaust)\n    let ?trn1 = \"Trans s1 a1 ou1 s1'\"\n    have s1s1': \"eqExcPID_N s1 s1'\" using a1_def step1 uReview_uuReview_step_eqExcPID_N by blast\n    have ss1': \"eqExcPID_N s s1'\" using eqExcPID_N_trans[OF ss1 s1s1'] .\n    hence many_s1': \"PID \\<in>\\<in> paperIDs s1' CID\" \"isRevNth s1' CID uid PID N\"\n    \"phase s1' CID = revPH\" \"pass s1' uid = pass s uid\"\n    using uid PID ph unfolding eqExcPID_N_def by auto\n    hence more_s1': \"uid \\<in>\\<in> userIDs s1'\" \"CID \\<in>\\<in> confIDs s1'\"\n    by (metis paperIDs_confIDs reach_PairI roles_userIDs rs1 step1 many_s1'(1))+\n    have f: \"f ?trn1 = v1\" unfolding a1_def by simp\n    have rs1': \"reach s1'\" using rs1 step1 by (auto intro: reach_PairI)\n    have ou1: \"ou1 = outOK\"\n    using step1 uid1 ph unfolding a1_def apply ( simp add: u_defs uu_defs many_s1' more_s1' isRev_def2)\n    by (metis isRevNth_getReviewIndex many_s1' rs1)\n    have ?iact proof\n      show \"step s1 a1 = (ou1,s1')\" by fact\n    next\n      show \\<phi>: \"\\<phi> ?trn1\" using ou1 unfolding a1_def by simp\n      thus \"consume ?trn1 vl1 vl1'\" using f unfolding consume_def vl1 by simp\n    next\n      show \"\\<not> \\<gamma> ?trn1\" by (simp add: a1_def uid_notin)\n    next\n      have \"\\<Delta>3 s vl s1' vl1'\" unfolding \\<Delta>3_def using ph PID ss1' uuid by auto\n      thus \"?\\<Delta> s vl s1' vl1'\" by simp\n    qed\n    thus ?thesis by auto\n  next\n    case Nil note vl1 = Nil\n    have ?react proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\"\n      let ?ph' = \"phase s' CID\"\n      assume step: \"step s a = (ou, s')\" and T: \"\\<not> T ?trn\" and c: \"consume ?trn vl vl'\"\n      have PID': \"PID \\<in>\\<in> paperIDs s' CID\" using PID rs by (metis paperIDs_mono step)\n      have uid': \"isRevNth s' CID uid PID N\"\n      using uid step rs ph PID isRevNth_persistent by auto\n      have uuid': \"isREVNth s' uid PID N\" by (metis isREVNth_def uid')\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n      proof(cases \"\\<phi> ?trn\")\n        case False note \\<phi> = False\n        have vl: \"vl' = vl\" using c \\<phi> unfolding consume_def by (cases vl) auto\n        obtain ou1 and s1' where step1: \"step s1 a = (ou1,s1')\" by (metis prod.exhaust)\n        let ?trn1 = \"Trans s1 a ou1 s1'\"\n        have s's1': \"eqExcPID_N s' s1'\" using eqExcPID_N_step[OF ss1 step step1] .\n        have \\<phi>1: \"\\<not> \\<phi> ?trn1\" using \\<phi> unfolding eqExcPID_N_step_\\<phi>[OF ss1 step step1] .\n        have ?match proof\n          show \"validTrans ?trn1\" using step1 by simp\n        next\n          show \"consume ?trn1 vl1 vl1\" unfolding consume_def using \\<phi>1 by auto\n        next\n          show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n        next\n          assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\"\n          using eqExcPID_N_step_out[OF ss1 step step1 rsT rs1 PID] by simp\n        next\n          show \"?\\<Delta> s' vl' s1' vl1\"\n          proof(cases \"?ph' = revPH\")\n            case True\n            hence \"\\<Delta>3 s' vl' s1' vl1\" using PID' s's1' uuid' unfolding \\<Delta>3_def by auto\n            thus ?thesis by auto\n          next\n            case False hence \"?ph' > revPH\"\n            using ph rs step by (metis le_less phase_increases2 prod.sel(2))\n            hence \"\\<Delta>4 s' vl' s1' vl1\" using s's1' PID' unfolding \\<Delta>4_def vl1 by auto\n            thus ?thesis by auto\n          qed\n        qed\n        thus ?thesis by simp\n      next\n        case True note \\<phi> = True\n        have s's: \"eqExcPID_N s' s\" using eqExcPID_N_sym[OF \\<phi>_step_eqExcPID_N[OF \\<phi> step]] .\n        have s's1: \"eqExcPID_N s' s1\" using eqExcPID_N_trans[OF s's ss1] .\n        have ?ignore proof\n          show \"\\<not> \\<gamma> ?trn\" using T_\\<phi>_\\<gamma> \\<phi> rsT step by auto\n        next\n          show \"?\\<Delta> s' vl' s1 vl1\"\n          proof(cases \"?ph' = revPH\")\n            case True\n            hence \"\\<Delta>3 s' vl' s1 vl1\" using s's1 PID' uuid' unfolding \\<Delta>3_def by auto\n            thus ?thesis by auto\n          next\n            case False hence \"?ph' > revPH\"\n            using ph rs step using eqExcPID_N_def s's by auto\n            hence \"\\<Delta>4 s' vl' s1 vl1\" using s's1 PID' unfolding \\<Delta>4_def vl1 by auto\n            thus ?thesis by auto\n          qed\n        qed\n        thus ?thesis by auto\n      qed\n    qed\n    thus ?thesis using vl1 by auto\n  qed\nqed\n\nlemma unwind_cont_\\<Delta>4: \"unwind_cont \\<Delta>4 {\\<Delta>4,\\<Delta>e}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>4 s vl s1 vl1 \\<or> \\<Delta>e s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \"\\<Delta>4 s vl s1 vl1\"\n  then obtain CID where rs: \"reach s\" and ph: \"phase s CID > revPH\" (is \"?ph > _\")\n  and PID: \"PID \\<in>\\<in> paperIDs s CID\" and ss1: \"eqExcPID_N s s1\" and vl1: \"vl1 = []\"\n  using reachNT_reach unfolding \\<Delta>4_def by auto\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof-\n    have \"?react\"\n    proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\"\n      let ?ph' = \"phase s' CID\"\n      assume step: \"step s a = (ou, s')\" and T: \"\\<not> T ?trn\" and c: \"consume ?trn vl vl'\"\n      have PID': \"PID \\<in>\\<in> paperIDs s' CID\" using PID rs by (metis paperIDs_mono step)\n      have ph': \"phase s' CID > revPH\" using ph rs by (meson less_le_trans local.step phase_increases)\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n      proof(cases \"\\<phi> ?trn\")\n        case False note \\<phi> = False\n        have vl: \"vl' = vl\" using c \\<phi> unfolding consume_def by (cases vl) auto\n        obtain ou1 and s1' where step1: \"step s1 a = (ou1,s1')\" by (metis prod.exhaust)\n        let ?trn1 = \"Trans s1 a ou1 s1'\"\n        have s's1': \"eqExcPID_N s' s1'\" using eqExcPID_N_step[OF ss1 step step1] .\n        have \\<phi>1: \"\\<not> \\<phi> ?trn1\" using \\<phi> unfolding eqExcPID_N_step_\\<phi>[OF ss1 step step1] .\n        have ?match proof\n          show \"validTrans ?trn1\" using step1 by simp\n        next\n          show \"consume ?trn1 vl1 vl1\" unfolding consume_def using \\<phi>1 by auto\n        next\n          show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n        next\n          assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\"\n          using eqExcPID_N_step_out[OF ss1 step step1 rsT rs1 PID] by simp\n        next\n          have \"\\<Delta>4 s' vl' s1' vl1\" using ph' PID' s's1' unfolding \\<Delta>4_def vl1 by auto\n          thus \"?\\<Delta> s' vl' s1' vl1\" by simp\n        qed\n        thus ?thesis by simp\n      next\n        case True note \\<phi> = True\n        have s's: \"eqExcPID_N s' s\" using eqExcPID_N_sym[OF \\<phi>_step_eqExcPID_N[OF \\<phi> step]] .\n        have s's1: \"eqExcPID_N s' s1\" using eqExcPID_N_trans[OF s's ss1] .\n        have ?ignore proof\n          show \"\\<not> \\<gamma> ?trn\" using T_\\<phi>_\\<gamma> \\<phi> rsT step by auto\n        next\n          have \"\\<Delta>4 s' vl' s1 vl1\" using s's1 PID' ph' vl1 unfolding \\<Delta>4_def by auto\n          thus \"?\\<Delta> s' vl' s1 vl1\" by auto\n        qed\n        thus ?thesis by simp\n      qed\n    qed\n    thus ?thesis using vl1 by simp\n  qed\nqed\n\n(* Exit arguments: *)\ndefinition K1exit where\n\"K1exit cid s \\<equiv> PID \\<in>\\<in> paperIDs s cid \\<and> phase s cid > revPH \\<and> \\<not> (\\<exists> uid. isRevNth s cid uid PID N)\"\n\nlemma invarNT_K1exit: \"invarNT (K1exit cid)\"\nunfolding invarNT_def apply (safe dest!: reachNT_reach)\n  subgoal for _ a apply(cases a)\n    subgoal for x1 apply(cases x1) apply (fastforce simp add: c_defs K1exit_def geq_noPH_confIDs)+ .\n    subgoal for x2 apply(cases x2) apply (fastforce simp add: u_defs K1exit_def paperIDs_equals)+ .\n    subgoal for x3 apply(cases x3) apply (fastforce simp add: uu_defs K1exit_def)+ .\n    by auto\n  done\n\nlemma noVal_K1exit: \"noVal (K1exit cid) v\"\napply(rule no\\<phi>_noVal)\nunfolding no\\<phi>_def apply safe\n  subgoal for _ a apply(cases a)\n    subgoal by (fastforce simp add: c_defs K1exit_def)\n    subgoal for x2 apply(cases x2) apply (auto simp add: u_defs K1exit_def)\n      apply (metis less_not_refl paperIDs_equals reachNT_reach) .\n    subgoal for x3 apply(cases x3) apply (auto simp add: uu_defs K1exit_def)\n      apply (metis isRev_def3 paperIDs_equals reachNT_reach) .\n    by auto\n  done\n\nlemma unwind_exit_\\<Delta>e: \"unwind_exit \\<Delta>e\"\nproof\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \\<Delta>e: \"\\<Delta>e s vl s1 vl1\"\n  hence vl: \"vl \\<noteq> []\" using reachNT_reach unfolding \\<Delta>e_def by auto\n  then obtain CID where \"K1exit CID s\" using \\<Delta>e unfolding K1exit_def \\<Delta>e_def isREVNth_def by auto\n  thus \"vl \\<noteq> [] \\<and> exit s (hd vl)\" apply(simp add: vl)\n  by (metis rsT exitI2 invarNT_K1exit noVal_K1exit)\nqed\n\ntheorem secure: secure\napply(rule unwind_decomp4_secure[of \\<Delta>1 \\<Delta>2 \\<Delta>e \\<Delta>3 \\<Delta>4])\nusing\nistate_\\<Delta>1\nunwind_cont_\\<Delta>1 unwind_cont_\\<Delta>2 unwind_cont_\\<Delta>3 unwind_cont_\\<Delta>4\nunwind_exit_\\<Delta>e\nby auto\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/CoCon/Review_Confidentiality/Review_RAut_NCPC_PAut.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.2574799024313704}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\n(* License: BSD, terms see file ./LICENSE *)\n\ntheory ArrayAssertion\n\nimports\n  ArchArraysMemInstance\n  \"StructSupport\"\n\nbegin\n\nlemma array_tag_n_eq:\n  \"(array_tag_n n :: ('a :: c_type['b :: finite]) field_desc typ_desc) =\n  TypDesc (TypAggregate\n    (map (\\<lambda>n. DTPair (adjust_ti (typ_info_t TYPE('a)) (\\<lambda>x. index x n)\n            (\\<lambda>x f. Arrays.update f n x)) (replicate n CHR ''1'')) [0..<n]))\n  (typ_name (typ_uinfo_t TYPE('a)) @ ''_array_'' @ nat_to_bin_string (card (UNIV :: 'b :: finite set)))\"\n  apply (induct n)\n   apply (simp add: typ_info_array array_tag_def eval_nat_numeral array_tag_n.simps empty_typ_info_def)\n   apply (simp add: typ_info_array array_tag_def eval_nat_numeral array_tag_n.simps empty_typ_info_def)\n   apply (simp add: ti_typ_combine_def Let_def)\n   done\n\nlemma typ_info_array':\n  \"typ_info_t TYPE ('a :: c_type['b :: finite]) =\n  TypDesc (TypAggregate\n    (map (\\<lambda>n. DTPair (adjust_ti (typ_info_t TYPE('a)) (\\<lambda>x. index x n)\n            (\\<lambda>x f. Arrays.update f n x)) (replicate n CHR ''1'')) [0..<(card (UNIV :: 'b :: finite set))]))\n  (typ_name (typ_uinfo_t TYPE('a)) @ ''_array_'' @ nat_to_bin_string (card (UNIV :: 'b :: finite set)))\"\n  by (simp add: typ_info_array array_tag_def array_tag_n_eq)\n\ndefinition\n  \"uinfo_array_tag_n_m (v :: 'a itself) n m = TypDesc\n    (TypAggregate (map (\\<lambda>i. DTPair (typ_uinfo_t TYPE('a)) (replicate i CHR ''1'')) [0 ..< n]))\n    (typ_name (typ_uinfo_t TYPE('a :: c_type)) @ ''_array_'' @ nat_to_bin_string m)\"\n\nlemma map_td_list_map:\n  \"map_td_list f = map (map_td_pair f)\"\n  by (rule ext, rename_tac x) (induct_tac x, simp_all)\n\nlemma uinfo_array_tag_n_m_eq:\n  \"n \\<le> CARD('b)\n    \\<Longrightarrow> export_uinfo (array_tag_n n :: (('a :: wf_type)['b :: finite]) field_desc typ_desc)\n        = uinfo_array_tag_n_m TYPE ('a) n (CARD('b))\"\n  apply (clarsimp simp: uinfo_array_tag_n_m_def array_tag_n_eq map_td_list_map\n                        o_def adjust_ti_def map_td_map typ_uinfo_t_def export_uinfo_def)\n  apply (fastforce intro: map_td_extI simp: field_norm_blah)\n  done\n\nlemma typ_uinfo_array_tag_n_m_eq:\n  \"typ_uinfo_t TYPE (('a :: wf_type)['b :: finite])\n        = uinfo_array_tag_n_m TYPE ('a) (CARD('b)) (CARD('b))\"\n  by (simp add: typ_uinfo_t_def typ_info_array array_tag_def uinfo_array_tag_n_m_eq)\n\ntext \\<open>Alternative to h_t_valid for arrays. This allows reasoning\nabout arrays of variable width.\\<close>\ndefinition h_t_array_valid :: \"heap_typ_desc \\<Rightarrow> ('a :: c_type) ptr \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"h_t_array_valid htd ptr n = valid_footprint htd (ptr_val ptr) (uinfo_array_tag_n_m TYPE ('a) n n)\"\n\ntext \\<open>Assertion that pointer p is within an array that continues for at least n more elements.\\<close>\ndefinition\n  \"array_assertion (p :: ('a :: c_type) ptr) n htd\n    = (\\<exists>q i j. h_t_array_valid htd q j\n        \\<and> p = CTypesDefs.ptr_add q (int i) \\<and> i < j \\<and> i + n \\<le> j)\"\n\nlemma array_assertion_shrink_right:\n  \"array_assertion p n htd \\<Longrightarrow> n' \\<le> n \\<Longrightarrow> array_assertion p n' htd\"\n  by (fastforce simp: array_assertion_def)\n\nlemma array_assertion_shrink_leftD:\n  \"array_assertion p n htd \\<Longrightarrow> j < n \\<Longrightarrow> array_assertion (CTypesDefs.ptr_add p (int j)) (n - j) htd\"\n  apply (clarsimp simp: array_assertion_def)\n  apply (rule exI, rule_tac x=\"i + j\" in exI, rule exI, erule conjI)\n  apply (simp add: CTypesDefs.ptr_add_def field_simps)\n  done\n\nlemma array_assertion_shrink_leftI:\n  \"array_assertion (CTypesDefs.ptr_add p (- (int j))) (n + j) htd\n    \\<Longrightarrow> n \\<noteq> 0 \\<Longrightarrow> array_assertion p n htd\"\n  apply (drule_tac j=j in array_assertion_shrink_leftD, simp)\n  apply (simp add: CTypesDefs.ptr_add_def)\n  done\n\nlemma h_t_array_valid:\n  \"h_t_valid htd gd (p :: (('a :: wf_type)['b :: finite]) ptr)\n    \\<Longrightarrow> h_t_array_valid htd (ptr_coerce p :: 'a ptr) (CARD('b))\"\n  by (clarsimp simp: h_t_valid_def h_t_array_valid_def typ_uinfo_array_tag_n_m_eq)\n\nlemma array_ptr_valid_array_assertionD:\n  \"h_t_valid htd gd (p :: (('a :: wf_type)['b :: finite]) ptr)\n    \\<Longrightarrow> array_assertion (ptr_coerce p :: 'a ptr) (CARD('b)) htd\"\n  apply (clarsimp simp: array_assertion_def dest!: h_t_array_valid)\n  apply (fastforce intro: exI[where x=0])\n  done\n\nlemma array_ptr_valid_array_assertionI:\n  \"h_t_valid htd gd (q :: (('a :: wf_type)['b :: finite]) ptr)\n    \\<Longrightarrow> q = ptr_coerce p\n    \\<Longrightarrow> n \\<le> CARD('b)\n    \\<Longrightarrow> array_assertion (p :: 'a ptr) n htd\"\n  by (auto dest: array_ptr_valid_array_assertionD\n           simp: array_assertion_shrink_right)\n\nlemma h_t_array_valid_array_assertion:\n  \"h_t_array_valid htd ptr n \\<Longrightarrow> 0 < n\n   \\<Longrightarrow> array_assertion ptr n htd\"\n  apply (simp add: array_assertion_def)\n  apply (fastforce intro: exI[where x=0])\n  done\n\ntext \\<open>Derived from array_assertion, an appropriate assertion for performing\na pointer addition, or for dereferencing a pointer addition (the strong case).\n\nIn either case, there must be an array connecting the two ends of the pointer\ntransition, with the caveat that the last address can be just out of the array\nif the pointer is not dereferenced, thus the strong/weak distinction.\n\nIf the pointer doesn't actually move, nothing is learned.\n\\<close>\ndefinition ptr_add_assertion :: \"('a :: c_type) ptr \\<Rightarrow> int \\<Rightarrow> bool \\<Rightarrow> heap_typ_desc \\<Rightarrow> bool\" where\n  \"ptr_add_assertion ptr offs strong htd \\<equiv>\n    offs = 0 \\<or>\n    array_assertion (if offs < 0 then CTypesDefs.ptr_add ptr offs else ptr)\n                    (if offs < 0 then nat (- offs) else if strong then Suc (nat offs) else nat offs)\n                    htd\"\n\nlemma ptr_add_assertion_positive:\n  \"offs \\<ge> 0 \\<Longrightarrow> ptr_add_assertion ptr offs strong htd\n    = (offs = 0 \\<or> array_assertion ptr (case strong of True \\<Rightarrow> Suc (nat offs)\n        | False \\<Rightarrow> nat offs) htd)\"\n  by (simp add: ptr_add_assertion_def)\n\nlemma ptr_add_assertion_negative:\n  \"offs < 0 \\<Longrightarrow> ptr_add_assertion ptr offs strong htd\n    = array_assertion (CTypesDefs.ptr_add ptr offs) (nat (- offs)) htd\"\n  by (simp add: ptr_add_assertion_def)\n\nlemma ptr_add_assertion_uint[simp]:\n  \"ptr_add_assertion ptr (uint offs) strong htd\n    = (offs = 0 \\<or> array_assertion ptr\n        (case strong of True \\<Rightarrow> Suc (unat offs) | False \\<Rightarrow> unat offs) htd)\"\n  by (metis ptr_add_assertion_positive uint_nonnegative unat_def unsigned_eq_0_iff)\n\ntext \\<open>Ignore char and void pointers. The C standard specifies that arithmetic on\nchar and void pointers doesn't create any special checks.\\<close>\n\ndefinition ptr_add_assertion' :: \"('a :: c_type) ptr \\<Rightarrow> int \\<Rightarrow> bool \\<Rightarrow> heap_typ_desc \\<Rightarrow> bool\" where\n  \"ptr_add_assertion' ptr offs strong htd =\n     (typ_uinfo_t TYPE('a) = typ_uinfo_t TYPE(word8)\n      \\<or> typ_uinfo_t TYPE ('a) = typ_uinfo_t TYPE(unit)\n      \\<or> ptr_add_assertion ptr offs strong htd)\"\n\n(* Useful for clearing away these assumptions. *)\nlemma td_diff_from_typ_name:\n  \"typ_name td \\<noteq> typ_name td' \\<Longrightarrow> td \\<noteq> td'\"\n  by clarsimp\n\nlemma typ_name_void:\n  \"typ_name (typ_uinfo_t TYPE(unit)) = ''unit''\"\n by (simp add: typ_uinfo_t_def)\n\nlemmas ptr_add_assertion' = ptr_add_assertion'_def td_diff_from_typ_name typ_name_void\n\ntext \\<open>Mechanism for retyping a range of memory to a non-constant array size.\\<close>\n\ndefinition ptr_arr_retyps :: \"nat \\<Rightarrow> ('a :: c_type) ptr \\<Rightarrow> heap_typ_desc \\<Rightarrow> heap_typ_desc\" where\n  \"ptr_arr_retyps n p \\<equiv>\n    htd_update_list (ptr_val p)\n        (map (\\<lambda>i. list_map (typ_slice_t (uinfo_array_tag_n_m TYPE('a) n n) i))\n             [0..<n * size_of TYPE('a)])\"\n\nlemma ptr_arr_retyps_to_retyp:\n  \"n = CARD('b :: finite)\n    \\<Longrightarrow> ptr_arr_retyps n (p :: ('c :: wf_type) ptr) = ptr_retyp (ptr_coerce p :: ('c['b]) ptr)\"\n  by (auto simp: ptr_arr_retyps_def ptr_retyp_def typ_slices_def typ_uinfo_array_tag_n_m_eq)\n\nlemma size_td_uinfo_array_tag_n_m[simp]:\n  \"size_td (uinfo_array_tag_n_m (t :: 'a :: c_type itself) n m)\n   = size_of (TYPE('a)) * n\"\n  apply (induct n)\n   apply (simp add: uinfo_array_tag_n_m_def)\n  apply (simp add: uinfo_array_tag_n_m_def size_of_def)\n  done\n\nlemma typ_slice_list_array:\n  \"x < size_td td * n\n    \\<Longrightarrow> typ_slice_list (map (\\<lambda>i. DTPair td (nm i)) [0..<n]) x\n        = typ_slice_t td (x mod size_td td)\"\nproof (induct n arbitrary: x nm)\n  case 0 thus ?case by simp\nnext\n  note if_split[split del]\n  case (Suc n)\n  from Suc.prems show ?case\n    apply (simp add: upt_conv_Cons map_Suc_upt[symmetric]\n                del: upt.simps)\n    apply (split if_split, intro conjI impI)\n     apply auto[1]\n    apply (simp add: o_def)\n    apply (subst Suc.hyps)\n     apply arith\n    apply (metis mod_geq)\n    done\nqed\n\nlemma h_t_array_valid_field:\n  \"h_t_array_valid htd (p :: 'a :: wf_type ptr) n\n    \\<Longrightarrow> k < n\n    \\<Longrightarrow> gd (p +\\<^sub>p int k)\n    \\<Longrightarrow> h_t_valid htd gd (p +\\<^sub>p int k)\"\n  supply if_split[split del]\n  apply (clarsimp simp: h_t_array_valid_def h_t_valid_def valid_footprint_def\n                        size_of_def[symmetric, where t=\"TYPE('a)\"] Let_def)\n  apply (drule_tac x=\"k * size_of TYPE('a) + y\" in spec)\n  apply (drule mp)\n   apply (frule_tac k=\"size_of TYPE('a)\" in mult_le_mono1[where j=n, OF Suc_leI])\n   apply (simp add: mult.commute)\n  apply (clarsimp simp: ptr_add_def add.assoc)\n  apply (erule map_le_trans[rotated])\n  apply (clarsimp simp: uinfo_array_tag_n_m_def)\n  apply (subst typ_slice_list_array)\n   apply (frule_tac k=\"size_of TYPE('a)\" in mult_le_mono1[where j=n, OF Suc_leI])\n   apply (simp add: mult.commute size_of_def)\n  apply (simp add: size_of_def list_map_mono)\n  done\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/c-parser/umm_heap/ArrayAssertion.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318479832804, "lm_q2_score": 0.4263215925474903, "lm_q1q2_score": 0.2574691872223809}}
{"text": "theory CoronaAppThree\n  imports InfrastructureThree\nbegin\nlocale scenarioCoronaThree = scenarioCoronaTwo +\n\nfixes corona_actorsR :: \"identity set\"\ndefines corona_actorsR_def: \"corona_actorsR \\<equiv> {''Alice'', ''Bob'', ''Charly'', ''David'', ''Eve'', ''Flo''}\"\n\nfixes corona_locationsR :: \"location set\"\ndefines corona_locationsR_def: \"corona_locationsR \\<equiv> {Location 0, Location 1}\"\nfixes pubR :: \"location\"\ndefines pubR_def: \"pubR \\<equiv> Location 0\"\nfixes shopR :: \"location\"\ndefines shopR_def: \"shopR \\<equiv> Location 1\"\n\nfixes identifiableR' :: \"[efid, (identity * efid)set] \\<Rightarrow> bool\"\ndefines identifiableR'_def: \"identifiableR' eid A \\<equiv> is_singleton{(Id,Eid). (Id, Eid) \\<in> A \\<and> Eid = eid}\"\n\nfixes global_policyR'' :: \"[infrastructure, efid] \\<Rightarrow> bool\"\ndefines global_policyR''_def: \"global_policyR'' I eid \\<equiv>  \n             \\<not>(identifiableR' eid \n                ((\\<Inter> (kgra(graphI I)(''Eve'')`(nodes(graphI I))))\n                 - {(x,y). x = ''Eve''}))\"\n\n(* The intersection above might be empty yet there could be individual l: nodes (graphI I)\n   for which identifiability is given*)\nfixes global_policyR' :: \"[infrastructure, efid] \\<Rightarrow> bool\"\ndefines global_policyR'_def: \"global_policyR' I eid \\<equiv>  \n             \\<forall> l \\<in> nodes(graphI I). \\<not>(identifiableR' eid \n                (kgra(graphI I)(''Eve'') l - {(x,y). x = ''Eve''}))\"\n\n(* The strongest one and the one we need is the following policy. *)\nfixes global_policyR :: \"[infrastructure, efid] \\<Rightarrow> bool\"\ndefines global_policyR_def: \"global_policyR I eid \\<equiv>  \n             \\<forall> L. 0 < card L \\<longrightarrow> L \\<subseteq> nodes(graphI I) \\<longrightarrow> (\\<not>(identifiableR' eid \n               ((\\<Inter> (kgra(graphI I)(''Eve'')`L)\n                          - {(x,y). x = ''Eve''}))))\"\n\nfixes ex_credsR :: \"identity \\<Rightarrow> efidlist\"\ndefines ex_credsR_def: \n          \"ex_credsR \\<equiv>  (\\<lambda> x. if x = ''Alice'' then (Efids (Efid 1) 0 (\\<lambda> n. Efid (2^(n+1)))) else \n                            (if x = ''Bob'' then  (Efids (Efid 2) 0 (\\<lambda> n. Efid (3^(n+1)))) else \n                            (if x = ''Charly'' then (Efids (Efid 3) 0 (\\<lambda> n. Efid (5^(n+1)))) else\n                            (if x = ''David'' then (Efids (Efid 4) 0 (\\<lambda> n. Efid (7^(n+1)))) else\n                            (if x = ''Eve'' then (Efids (Efid 5) 0 (\\<lambda> n. Efid (11^(n+1)))) else \n                            (if x = ''Flo'' then (Efids (Efid 6) 0 (\\<lambda> n. Efid (13^(n+1)))) else\n                                 (Efids (Efid 0) 0 (\\<lambda> n. Efid (17^(n+1))))))))))\"\n(*\nfixes ex_credsR' :: \"identity \\<Rightarrow> efidlist\"\ndefines ex_credsR'_def: \n          \"ex_credsR' \\<equiv> (\\<lambda> x. if x = ''Alice'' then (Efids (Efid 1) 0 (\\<lambda> n. Efid (2^(n+1)))) else \n                            (if x = ''Bob'' then  (Efids (Efid 2) 1 (\\<lambda> n. Efid (3^(n+1)))) else \n                            (if x = ''Charly'' then (Efids (Efid 3) 0 (\\<lambda> n. Efid (5^(n+1)))) else\n                            (if x = ''David'' then (Efids (Efid 4) 0 (\\<lambda> n. Efid (7^(n+1)))) else\n                            (if x = ''Eve'' then (Efids (Efid 5) 0 (\\<lambda> n. Efid (11^(n+1)))) else \n                                 (Efids (Efid 0) 0 (\\<lambda> n. Efid (13^(n+1)))))))))\"\n\nfixes ex_credsR'' :: \"identity \\<Rightarrow> efidlist\"\ndefines ex_credsR''_def: \n          \"ex_credsR'' \\<equiv> (\\<lambda> x. if x = ''Alice'' then (Efids (Efid 1) 0 (\\<lambda> n. Efid (2^(n+1)))) else \n                            (if x = ''Bob'' then  (Efids (Efid 2) 1 (\\<lambda> n. Efid (3^(n+1)))) else \n                            (if x = ''Charly'' then (Efids (Efid 3) 0 (\\<lambda> n. Efid (5^(n+1)))) else\n                            (if x = ''David'' then (Efids (Efid 4) 0 (\\<lambda> n. Efid (7^(n+1)))) else\n                            (if x = ''Eve'' then (Efids (Efid 5) 1 (\\<lambda> n. Efid (11^(n+1)))) else \n                                 (Efids (Efid 0) 0 (\\<lambda> n. Efid (13^(n+1)))))))))\"\n*)\nfixes ex_locsR :: \"location \\<Rightarrow> string * (dlm * data) set\"\ndefines \"ex_locsR \\<equiv> (\\<lambda> x. ('''',{}))\"\n\nfixes ex_loc_assR :: \"location \\<Rightarrow> identity set\"\ndefines ex_loc_assR_def: \"ex_loc_assR \\<equiv>\n          (\\<lambda> x. if x = pubR then {''Alice'', ''Bob'', ''Eve''}  \n                 else (if x = shopR then {''Charly'', ''David'', ''Flo''} \n                       else {}))\"\n(*\nfixes ex_loc_assR' :: \"location \\<Rightarrow> identity set\"\ndefines ex_loc_assR'_def: \"ex_loc_assR' \\<equiv>\n          (\\<lambda> x. if x = pubR then {''Alice'', ''Eve''}  \n                 else (if x = shopR then { ''Bob'', ''Charly'', ''David''} \n                       else {}))\"\nfixes ex_loc_assR'' :: \"location \\<Rightarrow> identity set\"\ndefines ex_loc_assR''_def: \"ex_loc_assR'' \\<equiv>\n          (\\<lambda> x. if x = pubR then {''Alice''}  \n                 else (if x = shopR then {''Eve'', ''Bob'', ''Charly'', ''David''} \n                       else {}))\"\n*)\nfixes ex_efidsR :: \"location \\<Rightarrow> efid set\"\ndefines ex_efidsR_def: \"ex_efidsR \\<equiv> \n          (\\<lambda> x. if x = pubR then {Efid 2, Efid 3, Efid 11}\n                else (if x = shopR then {Efid 5, Efid 7, Efid 13}\n                      else {}))\"\n(*\nfixes ex_efidsR' :: \"location \\<Rightarrow> efid set\"\ndefines ex_efidsR'_def: \"ex_efidsR' \\<equiv> \n          (\\<lambda> x. if x = pubR then {Efid 2, Efid 11}\n                else (if x = shopR then {Efid 9, Efid 5, Efid 7}\n                      else {}))\"\n\nfixes ex_efidsR'' :: \"location \\<Rightarrow> efid set\"\ndefines ex_efidsR''_def: \"ex_efidsR'' \\<equiv> \n          (\\<lambda> x. if x = pubR then {Efid 2}\n                else (if x = shopR then {Efid 121, Efid 3, Efid 5, Efid 7}\n                      else {}))\"\n*)\nfixes ex_knosR :: \"identity \\<Rightarrow> location \\<Rightarrow> (identity * efid) set\"\ndefines ex_knosR_def: \"ex_knosR \\<equiv> (\\<lambda> x :: identity. \n                  (if x = ''Eve'' then (\\<lambda> l :: location. {} :: (identity * efid) set) \n                   else (\\<lambda> l :: location. {} :: (identity * efid) set)))\"\n(*\nfixes ex_knosR' :: \"identity \\<Rightarrow> location \\<Rightarrow> (identity * efid) set\"\ndefines ex_knosR'_def: \"ex_knosR' \\<equiv> (\\<lambda> x :: identity. \n                  (if x = ''Eve'' then \n                     (\\<lambda> l :: location.\n                        (if l = pubR then \n                                  ({(''Alice'', Efid 2),(''Alice'', Efid 3),(''Alice'', Efid 11),\n                                    (''Bob'', Efid 2),(''Bob'', Efid 3),(''Bob'', Efid 11),\n                                    (''Eve'', Efid 2),(''Eve'', Efid 3),(''Eve'', Efid 11)})\n                         else {})) \n                   else (\\<lambda> l :: location. {} :: (identity * efid) set)))\"\n\nfixes ex_knosR'' :: \"identity \\<Rightarrow> location \\<Rightarrow> (identity * efid) set\"\ndefines ex_knosR''_def: \"ex_knosR'' \\<equiv> (\\<lambda> x :: identity.                       \n                  (if x = ''Eve'' then \n                      (\\<lambda> l :: location.\n                           (if l = pubR then \n                                  ({(''Alice'', Efid 2),(''Alice'', Efid 3),(''Alice'', Efid 11),\n                                    (''Bob'', Efid 2),(''Bob'', Efid 3),(''Bob'', Efid 11),\n                                    (''Eve'', Efid 2),(''Eve'', Efid 3),(''Eve'', Efid 11)})\n                            else (if l = shopR then \n                                     ({(''Eve'', Efid 121),(''Eve'', Efid 9),(''Eve'', Efid 5),(''Eve'', Efid 7),\n                                       (''Bob'', Efid 121),(''Bob'', Efid 9),(''Bob'', Efid 5),(''Bob'', Efid 7), \n                                       (''Charly'', Efid 121),(''Charly'', Efid 9),(''Charly'', Efid 5),(''Charly'', Efid 7),\n                                       (''David'', Efid 121),(''David'', Efid 9),(''David'', Efid 5),(''David'', Efid 7)})\n                                   else {})))\n                   else (\\<lambda> l :: location. {} :: (identity * efid) set)))\"\n*)\n(* The nicer representation with case suffers from\n   not so nice presentation in the cases (need to unfold the syntax)  \nfixes ex_loc_ass_alt :: \"location \\<Rightarrow> identity set\"\ndefines ex_loc_ass_alt_def: \"ex_loc_ass_alt \\<equiv>\n          (\\<lambda> x.  (case x of \n             Location (Suc 0) \\<Rightarrow> {''Alice'', ''Bob'', ''Eve''}  \n           | Location (Suc (Suc 0)) \\<Rightarrow> {''Charly'', ''David''} \n           |  _ \\<Rightarrow> {}))\"\n*)\n(* Alternative attack that persisted even in Level Two: \n   Bob gets isolated by Alice leaving pub so he's alone with Eve.\n   Here in level 3 it should not persist any more because we have the number of actors\n   restriction in the locations. *)\nfixes ex_credsRi :: \"identity \\<Rightarrow> efidlist\"\ndefines ex_credsRi_def: \n          \"ex_credsRi \\<equiv> (\\<lambda> x. if x = ''Alice'' then (Efids (Efid 1) 1 (\\<lambda> n. Efid (2^(n+1)))) else \n                            (if x = ''Bob'' then  (Efids (Efid 2) 0 (\\<lambda> n. Efid (3^(n+1)))) else \n                            (if x = ''Charly'' then (Efids (Efid 3) 0 (\\<lambda> n. Efid (5^(n+1)))) else\n                            (if x = ''David'' then (Efids (Efid 4) 0 (\\<lambda> n. Efid (7^(n+1)))) else\n                            (if x = ''Eve'' then (Efids (Efid 5) 0 (\\<lambda> n. Efid (11^(n+1)))) else \n                            (if x = ''Flo'' then (Efids (Efid 6) 0 (\\<lambda> n. Efid (13^(n+1)))) else \n                                 (Efids (Efid 0) 0 (\\<lambda> n. Efid (17^(n+1))))))))))\"\n\nfixes ex_loc_assRi :: \"location \\<Rightarrow> identity set\"\ndefines ex_loc_assRi_def: \"ex_loc_assRi \\<equiv>\n          (\\<lambda> x. if x = pubR then {''Bob'', ''Eve''}  \n                 else (if x = shopR then {''Alice'', ''Charly'', ''David'',''Flo''} \n                       else {}))\"\n\nfixes ex_efidsRi :: \"location \\<Rightarrow> efid set\"\ndefines ex_efidsRi_def: \"ex_efidsRi \\<equiv> \n          (\\<lambda> x. if x = pubR then {Efid 3, Efid 11}\n                else (if x = shopR then {Efid 4, Efid 5, Efid 7, Efid 13}\n                      else {}))\"\n\nfixes ex_knosRi :: \"identity \\<Rightarrow> location \\<Rightarrow> (identity * efid) set\"\ndefines ex_knosRi_def: \"ex_knosRi \\<equiv>(\\<lambda> x :: identity. \n                  (if x = ''Eve'' then \n                     (\\<lambda> l :: location.\n                        (if l = pubR then \n                                  ({(''Bob'', Efid 3),(''Bob'', Efid 11),\n                                    (''Eve'', Efid 3),(''Eve'', Efid 11)})\n                         else {})) \n                   else (\\<lambda> l :: location. {} :: (identity * efid) set)))\"\n\n\n(* initial *)\nfixes ex_graphR :: \"igraph\"\ndefines ex_graphR_def: \"ex_graphR \\<equiv> Lgraph {(pubR, shopR)} ex_loc_assR ex_credsR ex_locsR ex_efidsR ex_knosR\"\n\n(* Eve gets the ex_knos \nfixes ex_graphR' :: \"igraph\"\ndefines ex_graphR'_def: \"ex_graphR' \\<equiv> Lgraph {(pubR, shopR)} ex_loc_assR ex_credsR ex_locsR ex_efidsR ex_knosR'\"\n*)\n(* Bob goes to shop \nfixes ex_graphR'' :: \"igraph\"\ndefines ex_graphR''_def: \"ex_graphR'' \\<equiv> Lgraph {(pubR, shopR)} ex_loc_assR' ex_credsR ex_locsR ex_efidsR' ex_knosR'\"\n*)\n(* Eve goes to shop \nfixes ex_graphR''' :: \"igraph\"\ndefines ex_graphR'''_def: \"ex_graphR''' \\<equiv> Lgraph {(pubR, shopR)} ex_loc_assR'' ex_credsR ex_locsR ex_efidsR'' ex_knosR'\"\n*)\n(* Eve gets ex_knos at shop \nfixes ex_graphR'''' :: \"igraph\"\ndefines ex_graphR''''_def: \"ex_graphR'''' \\<equiv> Lgraph {(pubR, shopR)} ex_loc_assR'' ex_credsR ex_locsR ex_efidsR'' ex_knosR''\"\n*)\n(* Same as above: the nicer representation with case suffers from\n   not so nice presentation in the cases (need to unfold the syntax) \nfixes local_policies_alt :: \"[igraph, location] \\<Rightarrow> policy set\"\ndefines local_policies_alt_def: \"local_policies_alt G \\<equiv> \n    (\\<lambda> x. case x of \n         Location (Suc 0) \\<Rightarrow> {(\\<lambda> y. True, {put,get,move,eval})}\n       | Location 0 \\<Rightarrow> {((\\<lambda> y. has G (y, ''PIN'')), {put,get,move,eval})} \n       | Location (Suc (Suc (Suc 0))) \\<Rightarrow> {(\\<lambda> y. True, {put,get,move,eval})}\n       | Location (Suc (Suc 0)) \\<Rightarrow>\n                {((\\<lambda> y. (\\<exists> n. (n  @\\<^bsub>G\\<^esub> hospital) \\<and> Actor n = y \\<and> \n                           has G (y, ''skey''))), {put,get,move,eval})} \n       | _ \\<Rightarrow>  {})\"\n*)\n(* Second attack: Alice goes and then Bob is alone with Eve, so Eve can get and make the identification *)\n(* Alice goes to shop*)\nfixes ex_graphRi :: \"igraph\"\ndefines ex_graphRi_def: \"ex_graphRi \\<equiv> Lgraph {(pubR, shopR)} ex_loc_assRi ex_credsRi ex_locsT ex_efidsRi ex_knosR\"\n\n(* Eve gets the ex_knos *)\nfixes ex_graphRii :: \"igraph\"\ndefines ex_graphRii_def: \"ex_graphRii \\<equiv> Lgraph {(pubR, shopR)} ex_loc_assRi ex_credsRi ex_locsR ex_efidsRi ex_knosRi\"\n\nfixes local_policiesR :: \"[igraph, location] \\<Rightarrow> policy set\"\ndefines local_policiesR_def: \"local_policiesR G \\<equiv> \n    (\\<lambda> x. if x = pubR then  {(\\<lambda> y. True, {get,move})}\n          else (if x = shopR then {(\\<lambda> y. True, {get,move})} \n                else {}))\"\n\n(* problems with case in locales?\ndefines local_policies_def: \"local_policies G x \\<equiv> \n     (case x of \n       home \\<Rightarrow> {(\\<lambda> y. True, {put,get,move,eval})}\n     | sphone \\<Rightarrow> {((\\<lambda> y. has G (y, ''PIN'')), {put,get,move,eval})} \n     | cloud \\<Rightarrow> {(\\<lambda> y. True, {put,get,move,eval})}\n     | hospital \\<Rightarrow> {((\\<lambda> y. (\\<exists> n. (n  @\\<^bsub>G\\<^esub> hospital) \\<and> Actor n = y \\<and> \n                           has G (y, ''skey''))), {put,get,move,eval})} \n     | _ \\<Rightarrow>  {})\"\n*)\n\nfixes rmapR :: \"InfrastructureThree.infrastructure \\<Rightarrow> InfrastructureTwo.infrastructure\"\ndefines rmapR_def:\n\"rmapR I \\<equiv> InfrastructureThree.ref_map I local_policiesT\"\n\nfixes corona_scenarioR :: \"infrastructure\"\ndefines corona_scenarioR_def:\n\"corona_scenarioR \\<equiv> Infrastructure ex_graphR local_policiesR\"\nfixes IcoronaR :: \"infrastructure set\"\ndefines IcoronaR_def:\n  \"IcoronaR \\<equiv> {corona_scenarioR}\"\n\n(* other states of scenario *)\n(* First step: Bob goes to shop *)\n(*\nfixes corona_scenarioR' :: \"infrastructure\"\ndefines corona_scenarioR'_def: \"corona_scenarioR' \\<equiv> Infrastructure ex_graphR' local_policiesR\"\nfixes CoronaR' :: \"infrastructure set\"\ndefines CoronaR'_def: \"CoronaR' \\<equiv> {corona_scenarioR'}\"\nfixes corona_scenarioR'' :: \"infrastructure\"\ndefines corona_scenarioR''_def: \"corona_scenarioR'' \\<equiv> Infrastructure ex_graphR'' local_policiesR\"\nfixes CoronaR'' :: \"infrastructure set\"\ndefines Corona''_def: \"CoronaR'' \\<equiv> {corona_scenarioR''}\"\nfixes corona_scenarioR''' :: \"infrastructure\"\ndefines corona_scenarioR'''_def: \"corona_scenarioR''' \\<equiv> Infrastructure ex_graphR''' local_policiesR\"\nfixes CoronaR''' :: \"infrastructure set\"\ndefines CoronaR'''_def: \"CoronaR''' \\<equiv> {corona_scenarioR'''}\"\nfixes corona_scenarioR'''' :: \"infrastructure\"\ndefines corona_scenarioR''''_def: \"corona_scenarioR'''' \\<equiv> Infrastructure ex_graphR'''' local_policiesR\"\nfixes CoronaR'''' :: \"infrastructure set\"\ndefines CoronaR''''_def: \"CoronaR'''' \\<equiv> {corona_scenarioR''''}\"\n*)\n(* Second attack where Alice leaves *)\nfixes corona_scenarioRi :: \"infrastructure\"\ndefines corona_scenarioRi_def: \"corona_scenarioRi \\<equiv> Infrastructure ex_graphRi local_policiesR\"\nfixes CoronaRi :: \"infrastructure set\"\ndefines CoronaRi_def: \"CoronaRi \\<equiv> {corona_scenarioRi}\" \nfixes corona_scenarioRii :: \"infrastructure\" \ndefines corona_scenarioRii_def: \"corona_scenarioRii \\<equiv> Infrastructure ex_graphRii local_policiesR\" \nfixes CoronaRii :: \"infrastructure set\"\ndefines CoronaRii_def: \"CoronaRii \\<equiv> {corona_scenarioRii}\"\n\nfixes corona_statesR\ndefines corona_statesR_def: \"corona_statesR \\<equiv> { I. corona_scenarioR \\<rightarrow>\\<^sub>i* I }\"\nfixes corona_KripkeR\ndefines \"corona_KripkeR \\<equiv> Kripke corona_statesR IcoronaR\"\nfixes scoronaR \ndefines \"scoronaR \\<equiv> {x. \\<exists> n. \\<not> global_policyR'' x (Efid n)}\"  \nfixes scoronaR' \ndefines \"scoronaR' \\<equiv> {x. \\<exists> n. \\<not> global_policyR x (Efid n)}\"  \n(* *)\nbegin\n(* actor invariants for example *)\nlemma all_actors: \"actors_graph(graphI corona_scenarioR) = corona_actorsR\"\nproof (simp add: corona_scenarioR_def corona_actorsR_def ex_graphR_def actors_graph_def nodes_def\n                 ex_loc_assR_def, rule equalityI)\n  show \"{x. \\<exists>y. (y = shopR \\<longrightarrow>\n             (shopR = pubR \\<longrightarrow> x = ''Alice'' \\<or> x = ''Bob'' \\<or> x = ''Eve'') \\<and>\n             (shopR \\<noteq> pubR \\<longrightarrow> x = ''Charly'' \\<or> x = ''David'' \\<or> x = ''Flo'')) \\<and>\n            (y \\<noteq> shopR \\<longrightarrow>\n             (y = pubR \\<longrightarrow> (\\<exists>y. y = shopR \\<or> y = pubR \\<and> pubR = shopR) \\<and> (x = ''Alice'' \\<or> x = ''Bob'' \\<or> x = ''Eve'')) \\<and>\n             y = pubR)}\n    \\<subseteq> {''Alice'', ''Bob'', ''Charly'', ''David'', ''Eve'', ''Flo''}\"\n    by fastforce\nnext show \"{''Alice'', ''Bob'', ''Charly'', ''David'', ''Eve'', ''Flo''}\n    \\<subseteq> {x. \\<exists>y. (y = shopR \\<longrightarrow>\n                (shopR = pubR \\<longrightarrow> x = ''Alice'' \\<or> x = ''Bob'' \\<or> x = ''Eve'') \\<and>\n                (shopR \\<noteq> pubR \\<longrightarrow> x = ''Charly'' \\<or> x = ''David'' \\<or> x = ''Flo'')) \\<and>\n               (y \\<noteq> shopR \\<longrightarrow>\n                (y = pubR \\<longrightarrow> (\\<exists>y. y = shopR \\<or> y = pubR \\<and> pubR = shopR) \\<and> (x = ''Alice'' \\<or> x = ''Bob'' \\<or> x = ''Eve'')) \\<and>\n                y = pubR)}\"\n    using pubR_def shopR_def by auto\nqed\n\nlemma all_corona_actors: \"(corona_scenarioR, y) \\<in> {(x::infrastructure, y::infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \n              \\<Longrightarrow> actors_graph(graphI y) = corona_actorsR\"\n  using all_actors same_actors by auto\n\nlemma numbers_acors_inv_corona_scenarioR: \"l \\<in> nodes (graphI corona_scenarioR) \\<Longrightarrow>\ncard (agra (graphI corona_scenarioR) l) \\<ge> 2\"\n  by (simp add: corona_scenarioR_def corona_actorsR_def ex_graphR_def actors_graph_def nodes_def\n                 ex_loc_assR_def shopR_def pubR_def, force)\n\nlemma numbers_actors_inv_corona_scenarioR: \"l \\<in> nodes (graphI corona_scenarioR) \\<Longrightarrow>\ncard (agra (graphI corona_scenarioR) l) \\<ge> 3\"\n  by (simp add: corona_scenarioR_def corona_actorsR_def ex_graphR_def actors_graph_def nodes_def\n                 ex_loc_assR_def shopR_def pubR_def, force)\n\nlemma actors_unique_init_lem: \"\\<forall>a l l'.\n       l \\<in> InfrastructureThree.nodes (InfrastructureThree.graphI corona_scenarioR) \\<longrightarrow>\n       a \\<in> InfrastructureThree.agra (InfrastructureThree.graphI corona_scenarioR) l \\<longrightarrow>\n       a \\<in> InfrastructureThree.agra (InfrastructureThree.graphI corona_scenarioR) l' \\<longrightarrow> l = l'\"\n  by (simp add: corona_scenarioR_def ex_graphR_def ex_loc_assR_def nodes_def ex_credsR_def ex_efidsR_def\n             shopR_def pubR_def ex_knosR_def ex_locsR_def actors_graph_def)\n\n\n(* nodes invariants *)\nlemma same_nodes: \"(corona_scenarioR, s) \\<in> {(x::InfrastructureThree.infrastructure, y::InfrastructureThree.infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>*\n\\<Longrightarrow> InfrastructureThree.nodes (graphI corona_scenarioR) = InfrastructureThree.nodes (graphI s)\"\n  using InfrastructureThree.same_nodes by blast\n\n\n(* efids invariants *)\n\nlemma isthere_lem00: \" a \\<in>  agra (graphI corona_scenarioR) l \\<Longrightarrow> l \\<in> nodes (graphI corona_scenarioR) \\<Longrightarrow>\n            efids_cur (cgra (graphI corona_scenarioR) a) \\<in> egra (graphI corona_scenarioR) l\"\n  apply (simp add: corona_scenarioR_def ex_graphR_def ex_loc_assR_def nodes_def ex_credsR_def ex_efidsR_def\n             shopR_def pubR_def)\n  by (smt (z3) One_nat_def Zero_not_Suc char.inject insertE list.inject location.inject shopR_def singleton_iff)\n\n\nlemma efids_root_lem: \"a \\<in> actors_graph (InfrastructureThree.graphI corona_scenarioR) \\<Longrightarrow> \n                      a' \\<in> actors_graph (InfrastructureThree.graphI corona_scenarioR) \\<Longrightarrow>\n                 a \\<noteq> a' \\<Longrightarrow>\n                  efids_root (cgra (InfrastructureThree.graphI corona_scenarioR) a) \\<noteq> \n                  efids_root (cgra (InfrastructureThree.graphI corona_scenarioR) a')\"\n    apply (simp add: rmapR_def ref_map_def move_graph_a_def  corona_scenarioR_def)\n  apply (simp add: repl_efr_def ex_graphR_def ex_credsR_def)\n  by (smt CollectD InfrastructureThree.actors_graph_def InfrastructureThree.agra.simps InfrastructureThree.gra.simps InfrastructureThree.nodes_def ex_loc_assR_def insertE prod.inject singletonD)\n\n(*\nlemma efids_root_minus: \"(corona_scenarioR, I) \\<in> {(x::infrastructure, y::infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \n      \\<Longrightarrow> a \\<in> InfrastructureThree.agra (InfrastructureThree.graphI I) l \n      \\<Longrightarrow> l \\<in> InfrastructureThree.nodes (InfrastructureThree.graphI I)  \\<Longrightarrow>\n(\\<lambda>x. efids_root (InfrastructureThree.cgra (InfrastructureThree.graphI I) x)) `\n       (InfrastructureThree.agra (InfrastructureThree.graphI I) l - {a}) =\n       (\\<lambda>a. efids_root (InfrastructureThree.cgra (InfrastructureThree.graphI I) a)) `\n       InfrastructureThree.agra (InfrastructureThree.graphI I) l -\n       {efids_root (InfrastructureThree.cgra (InfrastructureThree.graphI I) a)}\"\n  apply auto\n  apply (frule InfrastructureThree.eroots_inj_on_inv)\n  sorry\n  using efids_root_lem inj_on_def apply blast\n  by (metis (mono_tags, lifting) InfrastructureThree.actors_graph_def inj_on_def mem_Collect_eq)\n*)\n(* efids_list initial invariants*)\n\nlemma efid_in_range_corona_scenarioR: \"(\\<forall> l \\<in> nodes (graphI corona_scenarioR).\n         (\\<forall> e \\<in> (egra (InfrastructureThree.graphI corona_scenarioR) l).\n         (\\<exists> a \\<in> actors_graph (graphI corona_scenarioR). \n             e \\<in> range (efids_list (InfrastructureThree.cgra (graphI corona_scenarioR) a)))))\"\n  apply (simp add: corona_scenarioR_def ex_graphR_def nodes_def)\n  apply (rule allI)\n   apply (rule impI)+\n   apply (rule ballI)\n  apply (simp add: ex_efidsR_def actors_graph_def ex_loc_assR_def)\n  apply (erule exE)\n  apply (erule disjE)\n   apply (simp add: pubR_def shopR_def ex_credsR_def nodes_def)\n   apply (erule disjE)\n    apply (rule_tac x = \"''Alice''\" in exI)\n  apply simp\n    apply blast\n   apply (erule disjE)\n  apply (rule_tac x = \"''Bob''\" in exI)\n  apply simp\n    apply blast\n   apply (rule_tac x = \"''Eve''\" in exI)\n  apply simp\n    apply blast\n   apply (simp add: pubR_def shopR_def ex_credsR_def nodes_def)\n   apply (erule disjE)\n   apply (rule_tac x = \"''Charly''\" in exI)\n  apply simp\n   apply (erule disjE)\n   apply (rule_tac x = \"''David''\" in exI)\n  apply simp\n  apply (rule_tac x = \"''Flo''\" in exI)\n  by simp\n\nlemma efid_kgra_in_range_corona_scenarioR: \"(\\<forall> l \\<in> InfrastructureThree.nodes (InfrastructureThree.graphI corona_scenarioR). \n         (\\<forall> h \\<in> InfrastructureThree.actors_graph(InfrastructureThree.graphI corona_scenarioR).\n         (\\<forall> e \\<in> (snd`((InfrastructureThree.kgra (InfrastructureThree.graphI corona_scenarioR) h l))).\n         (\\<exists> a \\<in> InfrastructureThree.actors_graph (InfrastructureThree.graphI corona_scenarioR). \n           e \\<in> range (InfrastructureThree.efids_list (InfrastructureThree.cgra (InfrastructureThree.graphI corona_scenarioR) a))))))\"\n  by (simp add: corona_scenarioR_def ex_graphR_def nodes_def\n                 ex_credsR_def ex_locsR_def ex_efidsR_def ex_knosR_def pubR_def shopR_def)\n\nlemma efid_eq_efid_cur_corona_scenarioR: \"lb \\<in> InfrastructureThree.nodes (InfrastructureThree.graphI corona_scenarioR) \\<Longrightarrow>\n       e \\<in> InfrastructureThree.egra (InfrastructureThree.graphI corona_scenarioR) lb \\<Longrightarrow>\n       \\<exists>a\\<in>InfrastructureThree.agra (InfrastructureThree.graphI corona_scenarioR) lb.\n          e = efids_cur (InfrastructureThree.cgra (InfrastructureThree.graphI corona_scenarioR) a)\"\n  apply (simp add: corona_scenarioR_def ex_graphR_def nodes_def ex_loc_assR_def \n                 ex_credsR_def ex_locsR_def ex_efidsR_def ex_knosR_def pubR_def shopR_def)\n  using shopR_def by fastforce\n\n\nlemma not_ex_elem_empty_int: \"\\<not>(\\<exists> x. (x \\<in> A \\<and> x \\<in> B)) \\<Longrightarrow> A \\<inter> B = {}\"\n  by (rule no_elem_inter_disjoint)\n\nlemma range_disjoint_corona_scenarioR[rule_format]: \"\\<forall>a\\<in>InfrastructureThree.actors_graph (InfrastructureThree.graphI corona_scenarioR).\n       \\<forall>a'\\<in>InfrastructureThree.actors_graph (InfrastructureThree.graphI corona_scenarioR).\n          a \\<noteq> a' \\<longrightarrow>\n          range\n           (InfrastructureThree.efids_list\n             (InfrastructureThree.cgra (InfrastructureThree.graphI corona_scenarioR) a)) \\<inter>\n          range\n           (InfrastructureThree.efids_list\n             (InfrastructureThree.cgra (InfrastructureThree.graphI corona_scenarioR) a')) =\n          {}\"\nproof (unfold corona_scenarioR_def ex_graphR_def ex_credsR_def, simp)\n  show \" \\<forall>a\\<in>InfrastructureThree.actors_graph\n         (InfrastructureThree.igraph.Lgraph {(pubR, shopR)} ex_loc_assR\n           (\\<lambda>x. if x = ''Alice'' then Efids (Efid 1) 0 (\\<lambda>n. Efid (2 ^ (n + 1)))\n                else if x = ''Bob'' then Efids (Efid 2) 0 (\\<lambda>n. Efid (3 ^ (n + 1)))\n                     else if x = ''Charly'' then Efids (Efid 3) 0 (\\<lambda>n. Efid (5 ^ (n + 1)))\n                          else if x = ''David'' then Efids (Efid 4) 0 (\\<lambda>n. Efid (7 ^ (n + 1)))\n                               else if x = ''Eve'' then Efids (Efid 5) 0 (\\<lambda>n. Efid (11 ^ (n + 1)))\n                                    else if x = ''Flo'' then Efids (Efid 6) 0 (\\<lambda>n. Efid (13 ^ (n + 1)))\n                                         else Efids (Efid 0) 0 (\\<lambda>n. Efid (17 ^ (n + 1))))\n           ex_locsR ex_efidsR ex_knosR).\n       (a = ''Flo'' \\<longrightarrow>\n        (\\<forall>a'\\<in>InfrastructureThree.actors_graph\n               (InfrastructureThree.igraph.Lgraph {(pubR, shopR)} ex_loc_assR\n                 (\\<lambda>x. if x = ''Alice'' then Efids (Efid 1) 0 (\\<lambda>n. Efid (2 ^ (n + 1)))\n                      else if x = ''Bob'' then Efids (Efid 2) 0 (\\<lambda>n. Efid (3 ^ (n + 1)))\n                           else if x = ''Charly'' then Efids (Efid 3) 0 (\\<lambda>n. Efid (5 ^ (n + 1)))\n                                else if x = ''David'' then Efids (Efid 4) 0 (\\<lambda>n. Efid (7 ^ (n + 1)))\n                                     else if x = ''Eve'' then Efids (Efid 5) 0 (\\<lambda>n. Efid (11 ^ (n + 1)))\n                                          else if x = ''Flo'' then Efids (Efid 6) 0 (\\<lambda>n. Efid (13 ^ (n + 1)))\n                                               else Efids (Efid 0) 0 (\\<lambda>n. Efid (17 ^ (n + 1))))\n                 ex_locsR ex_efidsR ex_knosR).\n            (a' = ''Eve'' \\<longrightarrow> range (\\<lambda>x. Efid (13 * 13 ^ x)) \\<inter> range (\\<lambda>x. Efid (11 * 11 ^ x)) = {}) \\<and>\n            (a' \\<noteq> ''Eve'' \\<longrightarrow>\n             (a' = ''David'' \\<longrightarrow> range (\\<lambda>x. Efid (13 * 13 ^ x)) \\<inter> range (\\<lambda>x. Efid (7 * 7 ^ x)) = {}) \\<and>\n             (a' \\<noteq> ''David'' \\<longrightarrow>\n              (a' = ''Charly'' \\<longrightarrow> range (\\<lambda>x. Efid (13 * 13 ^ x)) \\<inter> range (\\<lambda>x. Efid (5 * 5 ^ x)) = {}) \\<and>\n              (a' \\<noteq> ''Charly'' \\<longrightarrow>\n               (a' = ''Bob'' \\<longrightarrow> range (\\<lambda>x. Efid (13 * 13 ^ x)) \\<inter> range (\\<lambda>x. Efid (3 * 3 ^ x)) = {}) \\<and>\n               (a' \\<noteq> ''Bob'' \\<longrightarrow>\n                (a' = ''Alice'' \\<longrightarrow> range (\\<lambda>x. Efid (13 * 13 ^ x)) \\<inter> range (\\<lambda>x. Efid (2 * 2 ^ x)) = {}) \\<and>\n                (a' \\<noteq> ''Alice'' \\<longrightarrow>\n                 ''Flo'' \\<noteq> a' \\<longrightarrow> range (\\<lambda>x. Efid (13 * 13 ^ x)) \\<inter> range (\\<lambda>x. Efid (17 * 17 ^ x)) = {}))))))) \\<and>\n       (a \\<noteq> ''Flo'' \\<longrightarrow>\n        (a = ''Eve'' \\<longrightarrow>\n         (\\<forall>a'\\<in>InfrastructureThree.actors_graph\n                (InfrastructureThree.igraph.Lgraph {(pubR, shopR)} ex_loc_assR\n                  (\\<lambda>x. if x = ''Alice'' then Efids (Efid 1) 0 (\\<lambda>n. Efid (2 ^ (n + 1)))\n                       else if x = ''Bob'' then Efids (Efid 2) 0 (\\<lambda>n. Efid (3 ^ (n + 1)))\n                            else if x = ''Charly'' then Efids (Efid 3) 0 (\\<lambda>n. Efid (5 ^ (n + 1)))\n                                 else if x = ''David'' then Efids (Efid 4) 0 (\\<lambda>n. Efid (7 ^ (n + 1)))\n                                      else if x = ''Eve'' then Efids (Efid 5) 0 (\\<lambda>n. Efid (11 ^ (n + 1)))\n                                           else if x = ''Flo'' then Efids (Efid 6) 0 (\\<lambda>n. Efid (13 ^ (n + 1)))\n                                                else Efids (Efid 0) 0 (\\<lambda>n. Efid (17 ^ (n + 1))))\n                  ex_locsR ex_efidsR ex_knosR).\n             (a' = ''Flo'' \\<longrightarrow> range (\\<lambda>x. Efid (11 * 11 ^ x)) \\<inter> range (\\<lambda>x. Efid (13 * 13 ^ x)) = {}) \\<and>\n             (a' \\<noteq> ''Flo'' \\<longrightarrow>\n              (a' = ''David'' \\<longrightarrow> range (\\<lambda>x. Efid (11 * 11 ^ x)) \\<inter> range (\\<lambda>x. Efid (7 * 7 ^ x)) = {}) \\<and>\n              (a' \\<noteq> ''David'' \\<longrightarrow>\n               (a' = ''Charly'' \\<longrightarrow> range (\\<lambda>x. Efid (11 * 11 ^ x)) \\<inter> range (\\<lambda>x. Efid (5 * 5 ^ x)) = {}) \\<and>\n               (a' \\<noteq> ''Charly'' \\<longrightarrow>\n                (a' = ''Bob'' \\<longrightarrow> range (\\<lambda>x. Efid (11 * 11 ^ x)) \\<inter> range (\\<lambda>x. Efid (3 * 3 ^ x)) = {}) \\<and>\n                (a' \\<noteq> ''Bob'' \\<longrightarrow>\n                 (a' = ''Alice'' \\<longrightarrow> range (\\<lambda>x. Efid (11 * 11 ^ x)) \\<inter> range (\\<lambda>x. Efid (2 * 2 ^ x)) = {}) \\<and>\n                 (a' \\<noteq> ''Alice'' \\<longrightarrow>\n                  ''Eve'' \\<noteq> a' \\<longrightarrow> range (\\<lambda>x. Efid (11 * 11 ^ x)) \\<inter> range (\\<lambda>x. Efid (17 * 17 ^ x)) = {}))))))) \\<and>\n        (a \\<noteq> ''Eve'' \\<longrightarrow>\n         (a = ''David'' \\<longrightarrow>\n          (\\<forall>a'\\<in>InfrastructureThree.actors_graph\n                 (InfrastructureThree.igraph.Lgraph {(pubR, shopR)} ex_loc_assR\n                   (\\<lambda>x. if x = ''Alice'' then Efids (Efid 1) 0 (\\<lambda>n. Efid (2 ^ (n + 1)))\n                        else if x = ''Bob'' then Efids (Efid 2) 0 (\\<lambda>n. Efid (3 ^ (n + 1)))\n                             else if x = ''Charly'' then Efids (Efid 3) 0 (\\<lambda>n. Efid (5 ^ (n + 1)))\n                                  else if x = ''David'' then Efids (Efid 4) 0 (\\<lambda>n. Efid (7 ^ (n + 1)))\n                                       else if x = ''Eve'' then Efids (Efid 5) 0 (\\<lambda>n. Efid (11 ^ (n + 1)))\n                                            else if x = ''Flo'' then Efids (Efid 6) 0 (\\<lambda>n. Efid (13 ^ (n + 1)))\n                                                 else Efids (Efid 0) 0 (\\<lambda>n. Efid (17 ^ (n + 1))))\n                   ex_locsR ex_efidsR ex_knosR).\n              (a' = ''Flo'' \\<longrightarrow> range (\\<lambda>x. Efid (7 * 7 ^ x)) \\<inter> range (\\<lambda>x. Efid (13 * 13 ^ x)) = {}) \\<and>\n              (a' \\<noteq> ''Flo'' \\<longrightarrow>\n               (a' = ''Eve'' \\<longrightarrow> range (\\<lambda>x. Efid (7 * 7 ^ x)) \\<inter> range (\\<lambda>x. Efid (11 * 11 ^ x)) = {}) \\<and>\n               (a' \\<noteq> ''Eve'' \\<longrightarrow>\n                (a' = ''Charly'' \\<longrightarrow> range (\\<lambda>x. Efid (7 * 7 ^ x)) \\<inter> range (\\<lambda>x. Efid (5 * 5 ^ x)) = {}) \\<and>\n                (a' \\<noteq> ''Charly'' \\<longrightarrow>\n                 (a' = ''Bob'' \\<longrightarrow> range (\\<lambda>x. Efid (7 * 7 ^ x)) \\<inter> range (\\<lambda>x. Efid (3 * 3 ^ x)) = {}) \\<and>\n                 (a' \\<noteq> ''Bob'' \\<longrightarrow>\n                  (a' = ''Alice'' \\<longrightarrow> range (\\<lambda>x. Efid (7 * 7 ^ x)) \\<inter> range (\\<lambda>x. Efid (2 * 2 ^ x)) = {}) \\<and>\n                  (a' \\<noteq> ''Alice'' \\<longrightarrow>\n                   ''David'' \\<noteq> a' \\<longrightarrow> range (\\<lambda>x. Efid (7 * 7 ^ x)) \\<inter> range (\\<lambda>x. Efid (17 * 17 ^ x)) = {}))))))) \\<and>\n         (a \\<noteq> ''David'' \\<longrightarrow>\n          (a = ''Charly'' \\<longrightarrow>\n           (\\<forall>a'\\<in>InfrastructureThree.actors_graph\n                  (InfrastructureThree.igraph.Lgraph {(pubR, shopR)} ex_loc_assR\n                    (\\<lambda>x. if x = ''Alice'' then Efids (Efid 1) 0 (\\<lambda>n. Efid (2 ^ (n + 1)))\n                         else if x = ''Bob'' then Efids (Efid 2) 0 (\\<lambda>n. Efid (3 ^ (n + 1)))\n                              else if x = ''Charly'' then Efids (Efid 3) 0 (\\<lambda>n. Efid (5 ^ (n + 1)))\n                                   else if x = ''David'' then Efids (Efid 4) 0 (\\<lambda>n. Efid (7 ^ (n + 1)))\n                                        else if x = ''Eve'' then Efids (Efid 5) 0 (\\<lambda>n. Efid (11 ^ (n + 1)))\n                                             else if x = ''Flo'' then Efids (Efid 6) 0 (\\<lambda>n. Efid (13 ^ (n + 1)))\n                                                  else Efids (Efid 0) 0 (\\<lambda>n. Efid (17 ^ (n + 1))))\n                    ex_locsR ex_efidsR ex_knosR).\n               (a' = ''Flo'' \\<longrightarrow> range (\\<lambda>x. Efid (5 * 5 ^ x)) \\<inter> range (\\<lambda>x. Efid (13 * 13 ^ x)) = {}) \\<and>\n               (a' \\<noteq> ''Flo'' \\<longrightarrow>\n                (a' = ''Eve'' \\<longrightarrow> range (\\<lambda>x. Efid (5 * 5 ^ x)) \\<inter> range (\\<lambda>x. Efid (11 * 11 ^ x)) = {}) \\<and>\n                (a' \\<noteq> ''Eve'' \\<longrightarrow>\n                 (a' = ''David'' \\<longrightarrow> range (\\<lambda>x. Efid (5 * 5 ^ x)) \\<inter> range (\\<lambda>x. Efid (7 * 7 ^ x)) = {}) \\<and>\n                 (a' \\<noteq> ''David'' \\<longrightarrow>\n                  (a' = ''Bob'' \\<longrightarrow> range (\\<lambda>x. Efid (5 * 5 ^ x)) \\<inter> range (\\<lambda>x. Efid (3 * 3 ^ x)) = {}) \\<and>\n                  (a' \\<noteq> ''Bob'' \\<longrightarrow>\n                   (a' = ''Alice'' \\<longrightarrow> range (\\<lambda>x. Efid (5 * 5 ^ x)) \\<inter> range (\\<lambda>x. Efid (2 * 2 ^ x)) = {}) \\<and>\n                   (a' \\<noteq> ''Alice'' \\<longrightarrow>\n                    ''Charly'' \\<noteq> a' \\<longrightarrow> range (\\<lambda>x. Efid (5 * 5 ^ x)) \\<inter> range (\\<lambda>x. Efid (17 * 17 ^ x)) = {}))))))) \\<and>\n          (a \\<noteq> ''Charly'' \\<longrightarrow>\n           (a = ''Bob'' \\<longrightarrow>\n            (\\<forall>a'\\<in>InfrastructureThree.actors_graph\n                   (InfrastructureThree.igraph.Lgraph {(pubR, shopR)} ex_loc_assR\n                     (\\<lambda>x. if x = ''Alice'' then Efids (Efid 1) 0 (\\<lambda>n. Efid (2 ^ (n + 1)))\n                          else if x = ''Bob'' then Efids (Efid 2) 0 (\\<lambda>n. Efid (3 ^ (n + 1)))\n                               else if x = ''Charly'' then Efids (Efid 3) 0 (\\<lambda>n. Efid (5 ^ (n + 1)))\n                                    else if x = ''David'' then Efids (Efid 4) 0 (\\<lambda>n. Efid (7 ^ (n + 1)))\n                                         else if x = ''Eve'' then Efids (Efid 5) 0 (\\<lambda>n. Efid (11 ^ (n + 1)))\n                                              else if x = ''Flo'' then Efids (Efid 6) 0 (\\<lambda>n. Efid (13 ^ (n + 1)))\n                                                   else Efids (Efid 0) 0 (\\<lambda>n. Efid (17 ^ (n + 1))))\n                     ex_locsR ex_efidsR ex_knosR).\n                (a' = ''Flo'' \\<longrightarrow> range (\\<lambda>x. Efid (3 * 3 ^ x)) \\<inter> range (\\<lambda>x. Efid (13 * 13 ^ x)) = {}) \\<and>\n                (a' \\<noteq> ''Flo'' \\<longrightarrow>\n                 (a' = ''Eve'' \\<longrightarrow> range (\\<lambda>x. Efid (3 * 3 ^ x)) \\<inter> range (\\<lambda>x. Efid (11 * 11 ^ x)) = {}) \\<and>\n                 (a' \\<noteq> ''Eve'' \\<longrightarrow>\n                  (a' = ''David'' \\<longrightarrow> range (\\<lambda>x. Efid (3 * 3 ^ x)) \\<inter> range (\\<lambda>x. Efid (7 * 7 ^ x)) = {}) \\<and>\n                  (a' \\<noteq> ''David'' \\<longrightarrow>\n                   (a' = ''Charly'' \\<longrightarrow> range (\\<lambda>x. Efid (3 * 3 ^ x)) \\<inter> range (\\<lambda>x. Efid (5 * 5 ^ x)) = {}) \\<and>\n                   (a' \\<noteq> ''Charly'' \\<longrightarrow>\n                    (a' = ''Alice'' \\<longrightarrow> range (\\<lambda>x. Efid (3 * 3 ^ x)) \\<inter> range (\\<lambda>x. Efid (2 * 2 ^ x)) = {}) \\<and>\n                    (a' \\<noteq> ''Alice'' \\<longrightarrow>\n                     ''Bob'' \\<noteq> a' \\<longrightarrow> range (\\<lambda>x. Efid (3 * 3 ^ x)) \\<inter> range (\\<lambda>x. Efid (17 * 17 ^ x)) = {}))))))) \\<and>\n           (a \\<noteq> ''Bob'' \\<longrightarrow>\n            (a = ''Alice'' \\<longrightarrow>\n             (\\<forall>a'\\<in>InfrastructureThree.actors_graph\n                    (InfrastructureThree.igraph.Lgraph {(pubR, shopR)} ex_loc_assR\n                      (\\<lambda>x. if x = ''Alice'' then Efids (Efid 1) 0 (\\<lambda>n. Efid (2 ^ (n + 1)))\n                           else if x = ''Bob'' then Efids (Efid 2) 0 (\\<lambda>n. Efid (3 ^ (n + 1)))\n                                else if x = ''Charly'' then Efids (Efid 3) 0 (\\<lambda>n. Efid (5 ^ (n + 1)))\n                                     else if x = ''David'' then Efids (Efid 4) 0 (\\<lambda>n. Efid (7 ^ (n + 1)))\n                                          else if x = ''Eve'' then Efids (Efid 5) 0 (\\<lambda>n. Efid (11 ^ (n + 1)))\n                                               else if x = ''Flo'' then Efids (Efid 6) 0 (\\<lambda>n. Efid (13 ^ (n + 1)))\n                                                    else Efids (Efid 0) 0 (\\<lambda>n. Efid (17 ^ (n + 1))))\n                      ex_locsR ex_efidsR ex_knosR).\n                 (a' = ''Flo'' \\<longrightarrow> range (\\<lambda>x. Efid (2 * 2 ^ x)) \\<inter> range (\\<lambda>x. Efid (13 * 13 ^ x)) = {}) \\<and>\n                 (a' \\<noteq> ''Flo'' \\<longrightarrow>\n                  (a' = ''Eve'' \\<longrightarrow> range (\\<lambda>x. Efid (2 * 2 ^ x)) \\<inter> range (\\<lambda>x. Efid (11 * 11 ^ x)) = {}) \\<and>\n                  (a' \\<noteq> ''Eve'' \\<longrightarrow>\n                   (a' = ''David'' \\<longrightarrow> range (\\<lambda>x. Efid (2 * 2 ^ x)) \\<inter> range (\\<lambda>x. Efid (7 * 7 ^ x)) = {}) \\<and>\n                   (a' \\<noteq> ''David'' \\<longrightarrow>\n                    (a' = ''Charly'' \\<longrightarrow> range (\\<lambda>x. Efid (2 * 2 ^ x)) \\<inter> range (\\<lambda>x. Efid (5 * 5 ^ x)) = {}) \\<and>\n                    (a' \\<noteq> ''Charly'' \\<longrightarrow>\n                     (a' = ''Bob'' \\<longrightarrow> range (\\<lambda>x. Efid (2 * 2 ^ x)) \\<inter> range (\\<lambda>x. Efid (3 * 3 ^ x)) = {}) \\<and>\n                     (a' \\<noteq> ''Bob'' \\<longrightarrow>\n                      ''Alice'' \\<noteq> a' \\<longrightarrow> range (\\<lambda>x. Efid (2 * 2 ^ x)) \\<inter> range (\\<lambda>x. Efid (17 * 17 ^ x)) = {}))))))) \\<and>\n            (a \\<noteq> ''Alice'' \\<longrightarrow>\n             (\\<forall>a'\\<in>InfrastructureThree.actors_graph\n                    (InfrastructureThree.igraph.Lgraph {(pubR, shopR)} ex_loc_assR\n                      (\\<lambda>x. if x = ''Alice'' then Efids (Efid 1) 0 (\\<lambda>n. Efid (2 ^ (n + 1)))\n                           else if x = ''Bob'' then Efids (Efid 2) 0 (\\<lambda>n. Efid (3 ^ (n + 1)))\n                                else if x = ''Charly'' then Efids (Efid 3) 0 (\\<lambda>n. Efid (5 ^ (n + 1)))\n                                     else if x = ''David'' then Efids (Efid 4) 0 (\\<lambda>n. Efid (7 ^ (n + 1)))\n                                          else if x = ''Eve'' then Efids (Efid 5) 0 (\\<lambda>n. Efid (11 ^ (n + 1)))\n                                               else if x = ''Flo'' then Efids (Efid 6) 0 (\\<lambda>n. Efid (13 ^ (n + 1)))\n                                                    else Efids (Efid 0) 0 (\\<lambda>n. Efid (17 ^ (n + 1))))\n                      ex_locsR ex_efidsR ex_knosR).\n                 (a' = ''Flo'' \\<longrightarrow> range (\\<lambda>x. Efid (17 * 17 ^ x)) \\<inter> range (\\<lambda>x. Efid (13 * 13 ^ x)) = {}) \\<and>\n                 (a' \\<noteq> ''Flo'' \\<longrightarrow>\n                  (a' = ''Eve'' \\<longrightarrow> range (\\<lambda>x. Efid (17 * 17 ^ x)) \\<inter> range (\\<lambda>x. Efid (11 * 11 ^ x)) = {}) \\<and>\n                  (a' \\<noteq> ''Eve'' \\<longrightarrow>\n                   (a' = ''David'' \\<longrightarrow> range (\\<lambda>x. Efid (17 * 17 ^ x)) \\<inter> range (\\<lambda>x. Efid (7 * 7 ^ x)) = {}) \\<and>\n                   (a' \\<noteq> ''David'' \\<longrightarrow>\n                    (a' = ''Charly'' \\<longrightarrow> range (\\<lambda>x. Efid (17 * 17 ^ x)) \\<inter> range (\\<lambda>x. Efid (5 * 5 ^ x)) = {}) \\<and>\n                    (a' \\<noteq> ''Charly'' \\<longrightarrow>\n                     (a' = ''Bob'' \\<longrightarrow> range (\\<lambda>x. Efid (17 * 17 ^ x)) \\<inter> range (\\<lambda>x. Efid (3 * 3 ^ x)) = {}) \\<and>\n                     (a' \\<noteq> ''Bob'' \\<longrightarrow>\n                      (a' = ''Alice'' \\<longrightarrow> range (\\<lambda>x. Efid (17 * 17 ^ x)) \\<inter> range (\\<lambda>x. Efid (2 * 2 ^ x)) = {}) \\<and>\n                      (a' \\<noteq> ''Alice'' \\<longrightarrow> a = a')))))))))))))\"\n    apply (rule ballI)+\n    apply (rule conjI)\n     apply (rule impI)+\n    apply (rule ballI)+\n    apply (rule conjI)\n      apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_13_11, simp, simp)\n     apply (rule impI)+\n     apply (rule conjI)\n      apply (rule impI)+\n    apply (rule coprime_range_disjointOO)\n    apply (rule coprime_13_7, simp, simp)\n     apply (rule impI)+\n     apply (rule conjI)\n      apply (rule impI)+\n    apply (rule coprime_range_disjointOO)\n    apply (rule coprime_13_5, simp, simp)\n     apply (rule impI)+\n     apply (rule conjI)\n      apply (rule impI)+\n    apply (rule coprime_range_disjointOO)\n    apply (rule coprime_13_3, simp, simp)\n     apply (rule impI)+\n     apply (rule conjI)\n      apply (rule impI)+\n    apply (rule coprime_range_disjointOO)\n    apply (rule coprime_13_2, simp, simp)\n     apply (rule impI)+\n    apply (rule coprime_range_disjointOO)\n        apply (rule coprime_13_17, simp, simp)\n    apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n    apply (rule ballI)+\n    apply (rule conjI)\n      apply (rule impI)+\n    apply (rule coprime_range_disjointOO)\n    apply (rule coprime_11_13, simp, simp)\n     apply (rule impI)+\n     apply (rule conjI)\n      apply (rule impI)+\n    apply (rule coprime_range_disjointOO)\n    apply (rule coprime_11_7, simp, simp)\n     apply (rule impI)+\n     apply (rule conjI)\n      apply (rule impI)+\n    apply (rule coprime_range_disjointOO)\n    apply (rule coprime_11_5, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n      apply (rule impI)+\n    apply (rule coprime_range_disjointOO)\n        apply (rule coprime_11_3, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n      apply (rule impI)+\n    apply (rule coprime_range_disjointOO)\n        apply (rule coprime_11_2, arith, arith)\n     apply (rule impI)+\n     apply (rule coprime_range_disjointOO)\n    apply (rule coprime_11_17, simp, simp)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n    apply (rule ballI)+\n    apply (rule conjI)\n      apply (rule impI)+\n    apply (rule coprime_range_disjointOO)\n    apply (rule coprime_7_13, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_7_11, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_7_5, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_7_3, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_7_2, arith, arith)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_7_17, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n    apply (rule ballI)+\n    apply (rule conjI)\n      apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_5_13, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_5_11, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_5_7, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_5_3, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_5_2, arith, arith)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_5_17, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n    apply (rule ballI)+\n    apply (rule conjI)\n      apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_3_13, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_3_11, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_3_7, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_3_5, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_3_2, arith, arith)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_3_17, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n    apply (rule ballI)+\n    apply (rule conjI)\n      apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_2_13, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_2_11, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_2_7, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_2_5, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_2_3, arith, arith)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_2_17, arith, arith)\n     apply (rule impI)+\n    apply (rule ballI)+\n    apply (rule conjI)\n      apply (rule impI)+\n     apply (rule coprime_range_disjointOO)\n    apply (rule coprime_17_13, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_17_11, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n     apply (rule coprime_range_disjointOO)\n    apply (rule coprime_17_7, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_17_5, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n      apply (rule coprime_range_disjointOO)\n    apply (rule coprime_17_3, arith, arith)\n     apply (rule impI)+\n     apply (rule conjI)\n     apply (rule impI)+\n     apply (rule coprime_range_disjointOO)\n    apply (rule coprime_17_2, arith, arith)\n     apply (rule impI)+\n    by (smt (z3) InfrastructureThree.actors_graph_def InfrastructureThree.agra.simps all_not_in_conv ex_loc_assR_def insertE mem_Collect_eq)\nqed\n\n\n(* initially inj *)\nlemma inj_efids_list_init_lem: \" \\<forall>a\\<in>InfrastructureThree.actors_graph (InfrastructureThree.graphI corona_scenarioR).\n       inj (InfrastructureThree.efids_list (InfrastructureThree.cgra (InfrastructureThree.graphI corona_scenarioR) a))\"\n  apply (simp add: corona_scenarioR_def ex_graphR_def ex_loc_assR_def nodes_def ex_credsR_def ex_efidsR_def\n             shopR_def pubR_def ex_knosR_def ex_locsR_def actors_graph_def)\n  apply (rule allI)\nby (simp add: inj_def)\n\n(* Initial kgra invariant *)\nlemma kgra_init_lem: \"\\<forall>l a. InfrastructureThree.kgra (InfrastructureThree.graphI corona_scenarioR) a l = {}\"\n  apply (simp add: corona_scenarioR_def ex_graphR_def ex_loc_assR_def nodes_def ex_credsR_def ex_efidsR_def\n             shopR_def pubR_def)\n  using ex_knosR_def by force\n\n(* Initial finiteness invariants needed in the \"pea-counting\" lemma last_lem *)\nlemma finite_egra_init_lem: \"\\<forall>l\\<in>InfrastructureThree.nodes (InfrastructureThree.graphI corona_scenarioR).\n       finite (InfrastructureThree.egra (InfrastructureThree.graphI corona_scenarioR) l)\"\n  by (simp add: corona_scenarioR_def ex_graphR_def ex_loc_assR_def nodes_def ex_credsR_def ex_efidsR_def\n             shopR_def pubR_def)\n\nlemma finite_agra_init_lem: \"\\<forall>l\\<in>InfrastructureThree.nodes (InfrastructureThree.graphI corona_scenarioR).\n       finite (InfrastructureThree.agra (InfrastructureThree.graphI corona_scenarioR) l)\"\n  by (simp add: corona_scenarioR_def ex_graphR_def ex_loc_assR_def nodes_def ex_credsR_def ex_efidsR_def\n             shopR_def pubR_def)\n\n\ntext \\<open>Other invariants are that the efids at egra l are in fact efids of the actors at\n      that location, i.e. \n       e \\<in> egra G l = (\\<exists>! a \\<in> agra G l.  e \\<in> efid_list (cgra G a) (for InfrastructureThree))\n                      .....        /\\ e = efid_root (cgra G a) \n            \\<close>\n\nlemma rtrancl_imp_step: \"(I \\<rightarrow>\\<^sub>n y) \\<Longrightarrow>  (I, y) \\<in> {(x::InfrastructureTwo.infrastructure, y::InfrastructureTwo.infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \"\n  by (simp add: r_into_rtrancl) \n  \nlemma rtrancl_imp_two_step: \"(I \\<rightarrow>\\<^sub>n y) \\<Longrightarrow>  (y \\<rightarrow>\\<^sub>n z) \\<Longrightarrow> (I, z) \\<in> {(x::InfrastructureTwo.infrastructure, y::InfrastructureTwo.infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \"\n  by (simp add: converse_rtrancl_into_rtrancl)\n\n\n\nlemma refmapThree_lem: \"\\<forall>s::InfrastructureThree.infrastructure.\n       (corona_scenarioR, s) \\<in> {(x::InfrastructureThree.infrastructure, y::InfrastructureThree.infrastructure). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<longrightarrow>\n       (\\<forall>s'::InfrastructureThree.infrastructure. s \\<rightarrow>\\<^sub>n s' \\<longrightarrow> (rmapR s, rmapR s')  \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>*)\"\nproof (clarify, frule same_nodes, frule init_state_policy, erule state_transition_in.cases)\n(* move case *)\n  show \"\\<And>s s' G I a l l' I'.\n       (corona_scenarioR, s) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n       InfrastructureThree.nodes (InfrastructureThree.graphI corona_scenarioR) =\n       InfrastructureThree.nodes (InfrastructureThree.graphI s) \\<Longrightarrow>\n       InfrastructureThree.delta corona_scenarioR = InfrastructureThree.delta s \\<Longrightarrow>\n       s = I \\<Longrightarrow>\n       s' = I' \\<Longrightarrow>\n       G = InfrastructureThree.graphI I \\<Longrightarrow>\n       a @\\<^bsub>G\\<^esub> l \\<Longrightarrow>\n       l \\<in> InfrastructureThree.nodes G \\<Longrightarrow>\n       l' \\<in> InfrastructureThree.nodes G \\<Longrightarrow>\n       a \\<in> InfrastructureThree.actors_graph G \\<Longrightarrow>\n       InfrastructureThree.enables I l' (Actor a) move \\<Longrightarrow>\n       I' =\n       InfrastructureThree.infrastructure.Infrastructure\n        (InfrastructureThree.move_graph_a a l l' (InfrastructureThree.graphI I)) (InfrastructureThree.delta I) \\<Longrightarrow>\n       (rmapR s, rmapR s') \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>*\"\n  proof (case_tac \"l = l'\")\n    show \"\\<And>s s' G I a l l' I'.\n       (corona_scenarioR, s) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n       InfrastructureThree.nodes (InfrastructureThree.graphI corona_scenarioR) =\n       InfrastructureThree.nodes (InfrastructureThree.graphI s) \\<Longrightarrow>\n       InfrastructureThree.delta corona_scenarioR = InfrastructureThree.delta s \\<Longrightarrow>\n       s = I \\<Longrightarrow>\n       s' = I' \\<Longrightarrow>\n       G = InfrastructureThree.graphI I \\<Longrightarrow>\n       a @\\<^bsub>G\\<^esub> l \\<Longrightarrow>\n       l \\<in> InfrastructureThree.nodes G \\<Longrightarrow>\n       l' \\<in> InfrastructureThree.nodes G \\<Longrightarrow>\n       a \\<in> InfrastructureThree.actors_graph G \\<Longrightarrow>\n       InfrastructureThree.enables I l' (Actor a) move \\<Longrightarrow>\n       I' =\n       InfrastructureThree.infrastructure.Infrastructure\n        (InfrastructureThree.move_graph_a a l l' (InfrastructureThree.graphI I)) (InfrastructureThree.delta I) \\<Longrightarrow>\n       l = l' \\<Longrightarrow> (rmapR s, rmapR s') \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>*\"\n      using InfrastructureThree.move_graph_eq InfrastructureThree.ref_map_def rmapR_def by force\n  next show \"\\<And>s s' G I a l l' I'.\n       (corona_scenarioR, s) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n       InfrastructureThree.nodes (InfrastructureThree.graphI corona_scenarioR) =\n       InfrastructureThree.nodes (InfrastructureThree.graphI s) \\<Longrightarrow>\n       InfrastructureThree.delta corona_scenarioR = InfrastructureThree.delta s \\<Longrightarrow>\n       s = I \\<Longrightarrow>\n       s' = I' \\<Longrightarrow>\n       G = InfrastructureThree.graphI I \\<Longrightarrow>\n       a @\\<^bsub>G\\<^esub> l \\<Longrightarrow>\n       l \\<in> InfrastructureThree.nodes G \\<Longrightarrow>\n       l' \\<in> InfrastructureThree.nodes G \\<Longrightarrow>\n       a \\<in> InfrastructureThree.actors_graph G \\<Longrightarrow>\n       InfrastructureThree.enables I l' (Actor a) move \\<Longrightarrow>\n       I' =\n       InfrastructureThree.infrastructure.Infrastructure\n        (InfrastructureThree.move_graph_a a l l' (InfrastructureThree.graphI I)) (InfrastructureThree.delta I) \\<Longrightarrow>\n       l \\<noteq> l' \\<Longrightarrow> (rmapR s, rmapR s') \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \"\n      apply (case_tac  \"4 \\<le> card (InfrastructureThree.agra (InfrastructureThree.graphI I) l) \")\n       prefer 2\n       apply (subgoal_tac \"s = s'\")\n      apply force\n       apply (simp add: move_graph_a_def)\n      apply (smt (verit, del_insts) InfrastructureThree.delta.simps InfrastructureThree.graphI.simps InfrastructureThree.infrastructure.exhaust InfrastructureThree.move_graph_a_def InfrastructureThree.move_graph_eq)\n(* *)\n      apply (rule_tac I = \"rmapR s\" and y = \"rmapR s'\" in rtrancl_imp_step)\n    apply (rule_tac  I = \"rmapR s\" and I' = \"rmapR s'\" and l = l and l' = l' \n                             and a = a \n in InfrastructureTwo.state_transition_in.move)\n            apply (rule refl)\n         apply (simp add: InfrastructureThree.atI_def InfrastructureThree.ref_map_def InfrastructureTwo.atI_def rmapR_def)\n           apply (simp add: nodes_def InfrastructureThree.atI_def InfrastructureThree.ref_map_def InfrastructureTwo.atI_def rmapR_def)\n    apply (simp add: InfrastructureTwo.nodes_def)\n    apply (simp add: InfrastructureThree.nodes_def InfrastructureThree.ref_map_def InfrastructureTwo.nodes_def rmapR_def)\n      apply (simp add:  rmapR_def InfrastructureThree.ref_map_def InfrastructureTwo.actors_graph_def \n                        InfrastructureThree.actors_graph_def InfrastructureTwo.nodes_def InfrastructureThree.nodes_def) \n    apply (simp add: rmapR_def InfrastructureThree.ref_map_def \n                     InfrastructureThree.enables_def InfrastructureTwo.enables_def local_policiesT_def shopT_def pubT_def)\n    apply (metis InfrastructureThree.delta.simps One_nat_def corona_scenarioR_def empty_iff local_policiesR_def pubR_def shopR_def)\n (* Only remaining subgoal \"rmapR s' =\n       InfrastructureTwo.infrastructure.Infrastructure\n        (InfrastructureTwo.move_graph_a a l l' (InfrastructureTwo.graphI (rmapR s))) (InfrastructureTwo.delta (rmapR s))\n    We need to provide an invariant that proves that for all reachable state the additions restrictions\n    on numbers of actors is preserved.\n*)\n(*      apply (subgoal_tac \"3 \\<le> card (InfrastructureThree.agra (InfrastructureThree.graphI I) l') \")\n      prefer 2 \n      using numbers_actors_inv_corona_scenarioR numbers_actors_inv_refl apply blast *)\n(*      apply (subgoal_tac \"2 \\<le> card (InfrastructureThree.agra (InfrastructureThree.graphI I) l) \")\n      prefer 2 \n      using numbers_acors_inv_corona_scenarioR numbers_actors_inv_refl apply blast *)\n    apply (simp add: InfrastructureTwo.move_graph_a_def InfrastructureThree.move_graph_a_def\n                     rmapR_def InfrastructureThree.ref_map_def \n                     local_policiesT_def shopT_def pubT_def)\n(* here *)\n    apply (rule conjI)\n     apply (rule impI)+\n     apply (rule conjI)\n    apply (simp add: InfrastructureTwo.efids_inc_ind_def InfrastructureThree.efids_inc_ind_def) \n      apply (simp add: InfrastructureTwo.efids_cur_def InfrastructureThree.efids_cur_def\n                        InfrastructureTwo.efids_inc_ind_def InfrastructureThree.efids_inc_ind_def)\n      apply force\n      using numbers_actors_inv_corona_scenarioR numbers_actors_inv_refl by presburger \n(*    by (simp add: InfrastructureTwo.efids_cur_def InfrastructureThree.efids_cur_def\n                        InfrastructureTwo.efids_inc_ind_def InfrastructureThree.efids_inc_ind_def) *) \nqed\nnext show \"\\<And>s s' G I a l I'.\n       (corona_scenarioR, s) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n       InfrastructureThree.nodes (InfrastructureThree.graphI corona_scenarioR) =\n       InfrastructureThree.nodes (InfrastructureThree.graphI s) \\<Longrightarrow>\n       InfrastructureThree.delta corona_scenarioR = InfrastructureThree.delta s \\<Longrightarrow>\n       s = I \\<Longrightarrow>\n       s' = I' \\<Longrightarrow>\n       G = InfrastructureThree.graphI I \\<Longrightarrow>\n       a @\\<^bsub>G\\<^esub> l \\<Longrightarrow>\n       l \\<in> InfrastructureThree.nodes G \\<Longrightarrow>\n       InfrastructureThree.enables I l (Actor a) get \\<Longrightarrow>\n       I' =\n       InfrastructureThree.infrastructure.Infrastructure\n        (InfrastructureThree.igraph.Lgraph (InfrastructureThree.gra G) (InfrastructureThree.agra G)\n          (InfrastructureThree.cgra G) (InfrastructureThree.lgra G) (InfrastructureThree.egra G)\n          ((InfrastructureThree.kgra G)\n           (a := (InfrastructureThree.kgra G a)\n              (l := {(x, y). x \\<in> InfrastructureThree.agra G l \\<and> y \\<in> InfrastructureThree.egra G l}))))\n        (InfrastructureThree.delta I) \\<Longrightarrow>\n       (rmapR s, rmapR s') \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>*\"\n  proof (rule rtrancl_imp_step, rule_tac I =  \"rmapR s\" and I' = \"rmapR s'\" and l = l  and a = a  \n        in InfrastructureTwo.state_transition_in.get, \n        rule refl, simp add: rmapR_def ref_map_def atI_def InfrastructureTwo.atI_def\n        local_policiesT_def InfrastructureTwo.nodes_def shopT_def pubT_def)\n    show \"\\<And>s s' G I a l I'.\n       (corona_scenarioR, s) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n       InfrastructureThree.nodes (InfrastructureThree.graphI corona_scenarioR) =\n       InfrastructureThree.nodes (InfrastructureThree.graphI s) \\<Longrightarrow>\n       InfrastructureThree.delta corona_scenarioR = InfrastructureThree.delta s \\<Longrightarrow>\n       s = I \\<Longrightarrow>\n       s' = I' \\<Longrightarrow>\n       G = InfrastructureThree.graphI I \\<Longrightarrow>\n       a @\\<^bsub>G\\<^esub> l \\<Longrightarrow>\n       l \\<in> InfrastructureThree.nodes G \\<Longrightarrow>\n       InfrastructureThree.enables I l (Actor a) get \\<Longrightarrow>\n       I' =\n       InfrastructureThree.infrastructure.Infrastructure\n        (InfrastructureThree.igraph.Lgraph (InfrastructureThree.gra G) (InfrastructureThree.agra G)\n          (InfrastructureThree.cgra G) (InfrastructureThree.lgra G) (InfrastructureThree.egra G)\n          ((InfrastructureThree.kgra G)\n           (a := (InfrastructureThree.kgra G a)\n              (l := {(x, y). x \\<in> InfrastructureThree.agra G l \\<and> y \\<in> InfrastructureThree.egra G l}))))\n        (InfrastructureThree.delta I) \\<Longrightarrow>\n       l \\<in> InfrastructureTwo.nodes (InfrastructureTwo.graphI (rmapR s))\"\n      apply (simp add: rmapR_def local_policiesT_def ref_map_def)\n      using InfrastructureTwo.nodes_def InfrastructureThree.nodes_def by fastforce\n  next show \"\\<And>s s' G I a l I'.\n       (corona_scenarioR, s) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n       InfrastructureThree.nodes (InfrastructureThree.graphI corona_scenarioR) =\n       InfrastructureThree.nodes (InfrastructureThree.graphI s) \\<Longrightarrow>\n       InfrastructureThree.delta corona_scenarioR = InfrastructureThree.delta s \\<Longrightarrow>\n       s = I \\<Longrightarrow>\n       s' = I' \\<Longrightarrow>\n       G = InfrastructureThree.graphI I \\<Longrightarrow>\n       a @\\<^bsub>G\\<^esub> l \\<Longrightarrow>\n       l \\<in> InfrastructureThree.nodes G \\<Longrightarrow>\n       InfrastructureThree.enables I l (Actor a) get \\<Longrightarrow>\n       I' =\n       InfrastructureThree.infrastructure.Infrastructure\n        (InfrastructureThree.igraph.Lgraph (InfrastructureThree.gra G) (InfrastructureThree.agra G)\n          (InfrastructureThree.cgra G) (InfrastructureThree.lgra G) (InfrastructureThree.egra G)\n          ((InfrastructureThree.kgra G)\n           (a := (InfrastructureThree.kgra G a)\n              (l := {(x, y). x \\<in> InfrastructureThree.agra G l \\<and> y \\<in> InfrastructureThree.egra G l}))))\n        (InfrastructureThree.delta I) \\<Longrightarrow>\n       InfrastructureTwo.enables (rmapR s) l (Actor a) get\"\n   proof (simp add: rmapR_def ref_map_def nodes_def enables_def InfrastructureTwo.enables_def\n              local_policiesT_def InfrastructureTwo.nodes_def shopT_def pubT_def)\n     show \"\\<And>s s' G I a l I'.\n       (corona_scenarioR, I) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n       {x. \\<exists>y. (x, y) \\<in> InfrastructureThree.gra (InfrastructureThree.graphI corona_scenarioR) \\<or>\n               (y, x) \\<in> InfrastructureThree.gra (InfrastructureThree.graphI corona_scenarioR)} =\n       {x. \\<exists>y. (x, y) \\<in> InfrastructureThree.gra (InfrastructureThree.graphI I) \\<or>\n               (y, x) \\<in> InfrastructureThree.gra (InfrastructureThree.graphI I)} \\<Longrightarrow>\n       InfrastructureThree.delta corona_scenarioR = InfrastructureThree.delta I \\<Longrightarrow>\n       s = I \\<Longrightarrow>\n       s' =\n       InfrastructureThree.infrastructure.Infrastructure\n        (InfrastructureThree.igraph.Lgraph (InfrastructureThree.gra (InfrastructureThree.graphI I))\n          (InfrastructureThree.agra (InfrastructureThree.graphI I))\n          (InfrastructureThree.cgra (InfrastructureThree.graphI I))\n          (InfrastructureThree.lgra (InfrastructureThree.graphI I))\n          (InfrastructureThree.egra (InfrastructureThree.graphI I))\n          ((InfrastructureThree.kgra (InfrastructureThree.graphI I))\n           (a := (InfrastructureThree.kgra (InfrastructureThree.graphI I) a)\n              (l := InfrastructureThree.agra (InfrastructureThree.graphI I) l \\<times>\n                    InfrastructureThree.egra (InfrastructureThree.graphI I) l))))\n        (InfrastructureThree.delta I) \\<Longrightarrow>\n       G = InfrastructureThree.graphI I \\<Longrightarrow>\n       a @\\<^bsub>InfrastructureThree.graphI I\\<^esub> l \\<Longrightarrow>\n       \\<exists>y. (l, y) \\<in> InfrastructureThree.gra (InfrastructureThree.graphI I) \\<or>\n           (y, l) \\<in> InfrastructureThree.gra (InfrastructureThree.graphI I) \\<Longrightarrow>\n       \\<exists>x\\<in>InfrastructureThree.delta I (InfrastructureThree.graphI I) l. case x of (p, e) \\<Rightarrow> get \\<in> e \\<and> p (Actor a) \\<Longrightarrow>\n       I' =\n       InfrastructureThree.infrastructure.Infrastructure\n        (InfrastructureThree.igraph.Lgraph (InfrastructureThree.gra (InfrastructureThree.graphI I))\n          (InfrastructureThree.agra (InfrastructureThree.graphI I))\n          (InfrastructureThree.cgra (InfrastructureThree.graphI I))\n          (InfrastructureThree.lgra (InfrastructureThree.graphI I))\n          (InfrastructureThree.egra (InfrastructureThree.graphI I))\n          ((InfrastructureThree.kgra (InfrastructureThree.graphI I))\n           (a := (InfrastructureThree.kgra (InfrastructureThree.graphI I) a)\n              (l := InfrastructureThree.agra (InfrastructureThree.graphI I) l \\<times>\n                    InfrastructureThree.egra (InfrastructureThree.graphI I) l))))\n        (InfrastructureThree.delta I) \\<Longrightarrow>\n       l \\<noteq> Location (Suc 0) \\<longrightarrow> l = Location 0\"\n        by (metis InfrastructureThree.delta.simps One_nat_def corona_scenarioR_def empty_iff local_policiesR_def pubR_def shopR_def)\n    qed\n  next show \"\\<And>s s' G I a l I'.\n       (corona_scenarioR, s) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n       InfrastructureThree.nodes (InfrastructureThree.graphI corona_scenarioR) =\n       InfrastructureThree.nodes (InfrastructureThree.graphI s) \\<Longrightarrow>\n       InfrastructureThree.delta corona_scenarioR = InfrastructureThree.delta s \\<Longrightarrow>\n       s = I \\<Longrightarrow>\n       s' = I' \\<Longrightarrow>\n       G = InfrastructureThree.graphI I \\<Longrightarrow>\n       a @\\<^bsub>G\\<^esub> l \\<Longrightarrow>\n       l \\<in> InfrastructureThree.nodes G \\<Longrightarrow>\n       InfrastructureThree.enables I l (Actor a) get \\<Longrightarrow>\n       I' =\n       InfrastructureThree.infrastructure.Infrastructure\n        (InfrastructureThree.igraph.Lgraph (InfrastructureThree.gra G) (InfrastructureThree.agra G)\n          (InfrastructureThree.cgra G) (InfrastructureThree.lgra G) (InfrastructureThree.egra G)\n          ((InfrastructureThree.kgra G)\n           (a := (InfrastructureThree.kgra G a)\n              (l := {(x, y). x \\<in> InfrastructureThree.agra G l \\<and> y \\<in> InfrastructureThree.egra G l}))))\n        (InfrastructureThree.delta I) \\<Longrightarrow>\n       rmapR s' =\n       InfrastructureTwo.infrastructure.Infrastructure\n        (InfrastructureTwo.igraph.Lgraph (InfrastructureTwo.gra (InfrastructureTwo.graphI (rmapR s)))\n          (InfrastructureTwo.agra (InfrastructureTwo.graphI (rmapR s)))\n          (InfrastructureTwo.cgra (InfrastructureTwo.graphI (rmapR s)))\n          (InfrastructureTwo.lgra (InfrastructureTwo.graphI (rmapR s)))\n          (InfrastructureTwo.egra (InfrastructureTwo.graphI (rmapR s)))\n          ((InfrastructureTwo.kgra (InfrastructureTwo.graphI (rmapR s)))\n           (a := (InfrastructureTwo.kgra (InfrastructureTwo.graphI (rmapR s)) a)\n              (l := {(x, y).\n                     x \\<in> InfrastructureTwo.agra (InfrastructureTwo.graphI (rmapR s)) l \\<and>\n                     y \\<in> InfrastructureTwo.egra (InfrastructureTwo.graphI (rmapR s)) l}))))\n        (InfrastructureTwo.delta (rmapR s))\"\nby (simp add: rmapR_def ref_map_def)\nqed\nnext show \"\\<And>s s' G I a l I'.\n       (corona_scenarioR, s) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n       InfrastructureThree.nodes (InfrastructureThree.graphI corona_scenarioR) =\n       InfrastructureThree.nodes (InfrastructureThree.graphI s) \\<Longrightarrow>\n       InfrastructureThree.delta corona_scenarioR = InfrastructureThree.delta s \\<Longrightarrow>\n       s = I \\<Longrightarrow>\n       s' = I' \\<Longrightarrow>\n       G = InfrastructureThree.graphI I \\<Longrightarrow>\n       a @\\<^bsub>G\\<^esub> l \\<Longrightarrow>\n       InfrastructureThree.enables I l (Actor a) put \\<Longrightarrow>\n       I' =\n       InfrastructureThree.infrastructure.Infrastructure\n        (InfrastructureThree.put_graph_efid a l (InfrastructureThree.graphI I)) (InfrastructureThree.delta I) \\<Longrightarrow>\n       (rmapR s, rmapR s') \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>*\"\n  proof (rule rtrancl_imp_step, rule_tac I = \"rmapR s\" and I' = \"rmapR s'\" and l = l  \n                             and a = a \n in InfrastructureTwo.state_transition_in.put, rule refl, simp add: rmapR_def ref_map_def atI_def InfrastructureTwo.atI_def\n     ,simp add: rmapR_def ref_map_def nodes_def enables_def InfrastructureTwo.enables_def\n              local_policiesT_def InfrastructureTwo.nodes_def shopT_def pubT_def)\n    show \"\\<And>s s' G I a l I'.\n       (corona_scenarioR, I) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n       {x. \\<exists>y. (x, y) \\<in> InfrastructureThree.gra (InfrastructureThree.graphI corona_scenarioR) \\<or>\n               (y, x) \\<in> InfrastructureThree.gra (InfrastructureThree.graphI corona_scenarioR)} =\n       {x. \\<exists>y. (x, y) \\<in> InfrastructureThree.gra (InfrastructureThree.graphI I) \\<or>\n               (y, x) \\<in> InfrastructureThree.gra (InfrastructureThree.graphI I)} \\<Longrightarrow>\n       InfrastructureThree.delta corona_scenarioR = InfrastructureThree.delta I \\<Longrightarrow>\n       s = I \\<Longrightarrow>\n       s' =\n       InfrastructureThree.infrastructure.Infrastructure\n        (InfrastructureThree.put_graph_efid a l (InfrastructureThree.graphI I)) (InfrastructureThree.delta I) \\<Longrightarrow>\n       G = InfrastructureThree.graphI I \\<Longrightarrow>\n       a @\\<^bsub>InfrastructureThree.graphI I\\<^esub> l \\<Longrightarrow>\n       \\<exists>x\\<in>InfrastructureThree.delta I (InfrastructureThree.graphI I) l. case x of (p, e) \\<Rightarrow> put \\<in> e \\<and> p (Actor a) \\<Longrightarrow>\n       I' =\n       InfrastructureThree.infrastructure.Infrastructure\n        (InfrastructureThree.put_graph_efid a l (InfrastructureThree.graphI I)) (InfrastructureThree.delta I) \\<Longrightarrow>\n       l \\<noteq> Location (Suc 0) \\<longrightarrow> l = Location 0\"\n      using all_not_in_conv corona_scenarioR_def local_policiesR_def pubR_def shopR_def by fastforce\n  next show \"\\<And>s s' G I a l I'.\n       (corona_scenarioR, s) \\<in> {(x, y). x \\<rightarrow>\\<^sub>n y}\\<^sup>* \\<Longrightarrow>\n       InfrastructureThree.nodes (InfrastructureThree.graphI corona_scenarioR) =\n       InfrastructureThree.nodes (InfrastructureThree.graphI s) \\<Longrightarrow>\n       InfrastructureThree.delta corona_scenarioR = InfrastructureThree.delta s \\<Longrightarrow>\n       s = I \\<Longrightarrow>\n       s' = I' \\<Longrightarrow>\n       G = InfrastructureThree.graphI I \\<Longrightarrow>\n       a @\\<^bsub>G\\<^esub> l \\<Longrightarrow>\n       InfrastructureThree.enables I l (Actor a) put \\<Longrightarrow>\n       I' =\n       InfrastructureThree.infrastructure.Infrastructure\n        (InfrastructureThree.put_graph_efid a l (InfrastructureThree.graphI I)) (InfrastructureThree.delta I) \\<Longrightarrow>\n       rmapR s' =\n       InfrastructureTwo.infrastructure.Infrastructure\n        (InfrastructureTwo.put_graph_efid a l (InfrastructureTwo.graphI (rmapR s))) (InfrastructureTwo.delta (rmapR s))\"\n      apply (simp add: rmapR_def ref_map_def)\n    apply (simp add: put_graph_efid_def InfrastructureTwo.put_graph_efid_def)\n      apply (rule conjI)\n       apply (rule ext, simp add: InfrastructureThree.efids_inc_ind_def InfrastructureTwo.efids_inc_ind_def)\n       apply (rule ext, simp)\n      apply (rule impI)\n      by (simp add: InfrastructureThree.efids_cur_def InfrastructureTwo.efids_cur_def\n                       InfrastructureThree.efids_inc_ind_def InfrastructureTwo.efids_inc_ind_def)\nqed\nqed\n\n\ntheorem refmapThree: \"corona_KripkeT \\<sqsubseteq>\\<^sub>rmapR corona_KripkeR\"\nproof (rule strong_mt'', simp add: corona_KripkeR_def corona_KripkeT_def corona_statesR_def corona_statesT_def state_transition_refl_def, rule conjI)\n  show \"IcoronaR \\<subseteq> {I. (corona_scenarioR, I) \\<in> {(x, y). x \\<rightarrow>\\<^sub>i y}\\<^sup>*}\"\n    using IcoronaR_def by fastforce\nnext show \"IcoronaT \\<subseteq> {I. (corona_scenarioT, I) \\<in> {(x, y). x \\<rightarrow>\\<^sub>i y}\\<^sup>*} \\<and>\n    rmapR ` IcoronaR \\<subseteq> IcoronaT \\<and>\n    (\\<forall>s. (\\<exists>s0\\<in>IcoronaR. (s0, s) \\<in> {(x, y). x \\<rightarrow>\\<^sub>i y}\\<^sup>*) \\<longrightarrow>\n         (\\<forall>s'. s \\<rightarrow>\\<^sub>i s' \\<longrightarrow> (rmapR s, rmapR s') \\<in> {(x, y). x \\<rightarrow>\\<^sub>i y}\\<^sup>*)) \"\n     apply (rule conjI)\n    using IcoronaT_def apply blast\n    apply (rule conjI)\n     apply (simp add: rmapR_def ref_map_def IcoronaT_def IcoronaR_def corona_scenarioT_def corona_scenarioR_def\n                      ex_graphT_def ex_graphR_def pubT_def pubR_def  ex_loc_assR_def\n            ex_loc_assT_def ext ex_credsT_def  ex_credsR_def ex_locsT_def ex_locsR_def \n            ex_efidsR_def ex_efidsT_def shopT_def shopR_def\n            ex_knosR_def ex_knosT_def repl_efr_def)\n    using IcoronaR_def InfrastructureTwo.state_transition_infra_def InfrastructureThree.state_transition_infra_def refmapThree_lem by auto\nqed\n\nlemma step1: \"corona_scenarioR  \\<rightarrow>\\<^sub>n corona_scenarioR'\"\n  oops\n\nlemma step1r: \"corona_scenarioR  \\<rightarrow>\\<^sub>n* corona_scenarioR'\"\n  oops\n\n(* These lemmas are all now on unreachable states\n\n\nlemma step2r: \"corona_scenarioR'  \\<rightarrow>\\<^sub>n* corona_scenarioR''\"\n  oops\n\nlemma step3: \"corona_scenarioR''  \\<rightarrow>\\<^sub>n corona_scenarioR'''\"\n  oops\n\nlemma step3r: \"corona_scenarioR''  \\<rightarrow>\\<^sub>n* corona_scenarioR'''\"\n  oops\n\nlemma step4: \"corona_scenarioR'''  \\<rightarrow>\\<^sub>n corona_scenarioR''''\"\n  oops\n\nlemma step4r: \"corona_scenarioR'''  \\<rightarrow>\\<^sub>n* corona_scenarioR''''\"\n  oops\n*)\n\n(*\nlemma corona_refR: \"[\\<N>\\<^bsub>(IcoronaR,scoronaR)\\<^esub>] \\<oplus>\\<^sub>\\<and>\\<^bsup>(IcoronaR,scoronaR)\\<^esup> \\<sqsubseteq>\n                  ([\\<N>\\<^bsub>(IcoronaR,CoronaR')\\<^esub>, \\<N>\\<^bsub>(CoronaR',CoronaR'')\\<^esub>,  \\<N>\\<^bsub>(CoronaR'',CoronaR''')\\<^esub>, \\<N>\\<^bsub>(CoronaR''',scoronaR)\\<^esub>] \\<oplus>\\<^sub>\\<and>\\<^bsup>(IcoronaR,scoronaR)\\<^esup>)\"\n  oops\n\nlemma att_coronaR: \"\\<turnstile>([\\<N>\\<^bsub>(IcoronaR,CoronaR')\\<^esub>, \\<N>\\<^bsub>(CoronaR',CoronaR'')\\<^esub>,  \\<N>\\<^bsub>(CoronaR'',CoronaR''')\\<^esub>, \\<N>\\<^bsub>(CoronaR''',scoronaR)\\<^esub>] \\<oplus>\\<^sub>\\<and>\\<^bsup>(IcoronaR,scoronaR)\\<^esup>)\"\n  oops\n*)\n\nlemma corona_abs_attR: \"\\<turnstile>\\<^sub>V([\\<N>\\<^bsub>(IcoronaR,scoronaR)\\<^esub>] \\<oplus>\\<^sub>\\<and>\\<^bsup>(IcoronaR,scoronaR)\\<^esup>)\"\n  oops\n\nlemma corona_attR: \"corona_KripkeR \\<turnstile> EF {x. \\<exists> n. \\<not>(global_policyR'' x (Efid n))}\"\n  oops\n\ntheorem corona_EFR: \"corona_KripkeR \\<turnstile> EF scoronaR\"\n  oops\n\ntheorem corona_ATT: \"\\<exists> A. \\<turnstile> A \\<and> attack A = (IcoronaR,scoronaR)\"\n  oops\n\ntheorem corona_EFR': \"corona_KripkeR \\<turnstile> EF scoronaR\"\n  oops\n\n  thm contrapos_corr\n\n(* As at level Two, global_policyR'' holds *)\nlemma kgra_disj_imp_not_identifiable: \n\"''Eve'' \\<in>  actors_graph  (graphI I) \\<Longrightarrow>\n\\<exists> l \\<in> nodes (graphI I). \\<exists> l' \\<in> nodes (graphI I). l \\<noteq> l' \\<Longrightarrow>\n(\\<forall> a \\<in> actors_graph  (graphI I).\n     (\\<forall> l \\<in> nodes (graphI I). \\<forall> l' \\<in> nodes (graphI I). \n         (l \\<noteq> l' \\<longrightarrow> (kgra (graphI I) a l) \\<inter> kgra(graphI I) a l' = {})))\n\\<Longrightarrow> global_policyR'' I eid \"\n  apply (simp add: global_policyR''_def identifiableR'_def)\n  apply (erule bexE)+\n  apply (subgoal_tac \"{(Id, Eid).\n            (\\<forall>x\\<in>InfrastructureThree.nodes (InfrastructureThree.graphI I).\n                (Id, Eid) \\<in> InfrastructureThree.kgra (InfrastructureThree.graphI I) ''Eve'' x) \\<and>\n            Id \\<noteq> ''Eve'' \\<and> Eid = eid} = {}\")\n   apply (erule ssubst)\n   apply (simp add: is_singleton_def)\n  by (smt (verit, ccfv_threshold) IntI case_prodI2 case_prod_conv empty_Collect_eq empty_iff split_part)\n\n\n(* Proof idea for global_policyR and global_policyR' is again that all intersections are empty\n   and thus for any subset of intersections we have that policy holds (the single set being the\n   special care global_policyR')\nlemma global_policy_strength: \"global_policyR I eid \\<Longrightarrow> global_policyR'' I eid\"\n\n  using global_policyR''_def global_policyR_def by blast\n*)\nthm bspec\nthm ballI\n\nlemma set_spec: \"\\<forall> L\\<subseteq> S. P L \\<Longrightarrow> L' \\<subseteq> S \\<Longrightarrow> P L'\"\n  by simp\n\nlemma set_allI:  \"(\\<And> L'. L' \\<subseteq> S \\<Longrightarrow> P L') \\<Longrightarrow> \\<forall> L\\<subseteq> S. P L \"\n  by simp\n\n(*\nlemma global_policy_strengthO: \"global_policyR I eid \\<Longrightarrow> global_policyR' I eid\"\nproof (simp add: global_policyR_def global_policyR'_def)\n  show \"\\<forall>L\\<subseteq>InfrastructureThree.nodes (InfrastructureThree.graphI I).\n       \\<not> identifiableR' eid\n           (\\<Inter> (InfrastructureThree.kgra (InfrastructureThree.graphI I) ''Eve'' ` L) - {(x, y). x = ''Eve''}) \\<Longrightarrow>\n    \\<forall>l\\<in>InfrastructureThree.nodes (InfrastructureThree.graphI I).\n       \\<not> identifiableR' eid (InfrastructureThree.kgra (InfrastructureThree.graphI I) ''Eve'' l - {(x, y). x = ''Eve''})\"\n    apply (rule ballI)\n    apply (drule_tac L' = \"{l}\" in set_spec)\n    by simp+\nqed\n\nlemma global_policy_strengthOO: \"global_policyR'' I eid \\<Longrightarrow> global_policyR' I eid \\<Longrightarrow> global_policyR I eid\"\nproof (simp add: global_policyR_def global_policyR'_def global_policyR''_def)\n  show \"\\<not> identifiableR' eid\n        (\\<Inter> (InfrastructureThree.kgra (InfrastructureThree.graphI I) ''Eve'' `\n             InfrastructureThree.nodes (InfrastructureThree.graphI I)) -\n         {(x, y). x = ''Eve''}) \\<Longrightarrow>\n    \\<forall>l\\<in>InfrastructureThree.nodes (InfrastructureThree.graphI I).\n       \\<not> identifiableR' eid\n           (InfrastructureThree.kgra (InfrastructureThree.graphI I) ''Eve'' l - {(x, y). x = ''Eve''}) \\<Longrightarrow>\n    \\<forall>L\\<subseteq>InfrastructureThree.nodes (InfrastructureThree.graphI I).\n       \\<not> identifiableR' eid\n           (\\<Inter> (InfrastructureThree.kgra (InfrastructureThree.graphI I) ''Eve'' ` L) - {(x, y). x = ''Eve''})\"\n    apply (rule set_allI)\n    apply (unfold identifiableR'_def)\n    apply (simp add: is_singleton_def)\n    apply (rule allI)+\n\n\n  oops\n*)\n\n\n(* We can already establish non-identifiability for subsets L with more than 2 elements.\n   This should follow simply from disjointness of the kgra set intersections for all pairs of \n   locations. *)\nlemma card_two_two_not_eq_elem: \"2 \\<le> card L \\<Longrightarrow> \\<exists>l\\<in>L. \\<exists>l'\\<in>L. l \\<noteq> l'\"\n  apply (subgoal_tac \"L \\<noteq> {}\")\n   prefer 2\n  apply force\n  apply (subgoal_tac \"\\<exists> x. x \\<in> L\")\n  prefer 2\n   apply auto[1]\n  apply (erule exE)\n  apply (subgoal_tac \"L - {x} \\<noteq> {}\")\n  prefer 2\n   apply (metis Suc_n_not_le_n card.empty card.infinite card_Suc_Diff1 not_numeral_le_zero numeral_2_eq_2)\n  apply (subgoal_tac \"\\<exists> y. y \\<in> (L - {x})\")\n   prefer 2\n   apply auto[1]\n  apply (rule_tac x = x in bexI)\n  apply (erule exE)\n   apply (rule_tac x = y in bexI)\n    apply force\n   apply simp\n  by assumption\n\n\nlemma all_kgra_disj_imp_greater_two_inv: \"(\\<forall> a \\<in> actors_graph (graphI I). \n     (\\<forall> l \\<in> nodes (graphI I). \\<forall> l' \\<in> nodes (graphI I). \n      (l \\<noteq> l' \\<longrightarrow> (kgra (graphI I) a l) \\<inter> kgra(graphI I) a l' = {}))) \\<Longrightarrow>\n      L \\<subseteq> nodes(graphI I)  \\<Longrightarrow> card L \\<ge> 2 \\<Longrightarrow> \n      ''Eve'' \\<in> actors_graph (graphI I) \\<Longrightarrow>\n      (\\<not>(identifiableR' eid \n               ((\\<Inter> (kgra(graphI I)(''Eve'')`L))\n                          - {(x,y). x = ''Eve''})))\"\n  apply (simp add: identifiableR'_def) \n  apply (subgoal_tac \" {(Id, Eid).\n         (\\<forall>x\\<in>L. (Id, Eid) \\<in> InfrastructureThree.kgra (InfrastructureThree.graphI I) ''Eve'' x) \\<and>\n         Id \\<noteq> ''Eve'' \\<and> Eid = eid} = {}\")\n   apply (rotate_tac -1)\n   apply (erule ssubst)\n   apply (simp add: is_singleton_def)\n  apply (rule equalityI)\n   prefer 2\n   apply simp\n  apply (rule subsetI)\n  apply simp\n  apply (case_tac x)\n  apply simp\n  apply (subgoal_tac \"\\<exists> l \\<in> L. (\\<exists> l' \\<in> L. l \\<noteq> l')\")\n   apply (erule bexE)+\n  apply (erule conjE)\n   apply (frule_tac x = l in bspec, assumption)\n   apply (drule_tac x = l' in bspec, assumption)\n   apply (drule_tac x = \"''Eve''\" in bspec)\n  prefer 2\n    apply (meson disjoint_iff in_mono)\n   apply assumption\nby (erule card_two_two_not_eq_elem)\n\nlemma empty_kgra: \"kgra (graphI I)(''Eve'')` {} = {}\"\n  by (rule image_empty)\n\n(* The remaining case: empty or just one l *)\nlemma \"\\<Inter> ({{}}) = {}\"\n  by (rule cInf_singleton)\n\nlemma empty_minus: \"({} - {(x, y). x = ''Eve''}) = {}\"\n  by (rule empty_Diff)\n\nlemma \"card {} = 0\"\n  by (rule card.empty)\n\nlemma \"finite S \\<Longrightarrow> I \\<notin> S \\<Longrightarrow> card (insert I S) = Suc (card S)\"\n  by(rule card_insert_disjoint)\n\nlemma \"card {l :: location} = 1\"\n  by simp\n\nlemma \"(l:: location) \\<in> L \\<Longrightarrow> card L < (2 :: nat) \\<Longrightarrow> L = {l}\"\n   apply (subgoal_tac \"card L = 1\")\n    apply (metis card_1_singletonE empty_iff insertE)\n   apply (subgoal_tac \"card L > 0\")\n   apply linarith\n  apply (subgoal_tac \"finite L\")\n  using card_gt_0_iff apply blast\n  oops\n\n\nlemma all_kgra_disj_imp_less_two_inv: \n     \"L \\<subseteq> nodes(graphI I)  \\<Longrightarrow> card L < 2 \\<Longrightarrow> \n      ''Eve'' \\<in> actors_graph (graphI I) \\<Longrightarrow> 0 < card L \\<Longrightarrow>\n\\<forall>l\\<in>InfrastructureThree.nodes (InfrastructureThree.graphI I).\n       {(Id, Eid).\n        (Id, Eid) \\<in> InfrastructureThree.kgra (InfrastructureThree.graphI I) ''Eve'' l \\<and> Id \\<noteq> ''Eve'' \\<and> Eid = eid} \\<noteq>\n       {} \\<longrightarrow>\n       2 \\<le> card {(Id, Eid).\n                  (Id, Eid) \\<in> InfrastructureThree.kgra (InfrastructureThree.graphI I) ''Eve'' l \\<and>\n                  Id \\<noteq> ''Eve'' \\<and> Eid = eid} \\<Longrightarrow>\n      (\\<not>(identifiableR' eid \n               (((\\<Inter> (kgra(graphI I)(''Eve'')`L)\n                          - {(x,y). x = ''Eve''})))))\"\n  apply (subgoal_tac \"finite L\")\n  prefer 2\n  using card_gt_0_iff apply blast\n  apply (subgoal_tac \"card L = 1\")\n   prefer 2\n   apply linarith\n  apply (subgoal_tac \"\\<exists> l. L = {l}\")\n   prefer 2\n   apply (meson card_1_singletonE)\n  apply (erule exE)\n  apply simp\n  apply (simp add: identifiableR'_def)\n  apply (subgoal_tac \"{(Id, Eid).\n     (Id, Eid) \\<in> InfrastructureThree.kgra (InfrastructureThree.graphI I) ''Eve'' l \\<and> Id \\<noteq> ''Eve'' \\<and> Eid = eid} = {} \n\\<or>\ncard({(Id, Eid).\n     (Id, Eid) \\<in> InfrastructureThree.kgra (InfrastructureThree.graphI I) ''Eve'' l \\<and> Id \\<noteq> ''Eve'' \\<and> Eid = eid}) \\<ge> 2\")\n   apply (erule disjE)\n  apply (rotate_tac -1)\n  apply (erule ssubst)\n  apply (simp add: is_singleton_def)+\n   apply force\n  apply (case_tac \"{(Id, Eid).\n     (Id, Eid) \\<in> InfrastructureThree.kgra (InfrastructureThree.graphI I) ''Eve'' l \\<and> Id \\<noteq> ''Eve'' \\<and> Eid = eid} = {}\")\n   apply simp\n  apply (rule disjI2)\nby simp\n\n(* putting the previous two cases together *)\nlemma all_kgra_disj_imp_inv: \"''Eve'' \\<in> InfrastructureThree.actors_graph (InfrastructureThree.graphI I) \\<Longrightarrow>\n     (\\<forall> a \\<in> actors_graph (graphI I).\n     (\\<forall> l \\<in> nodes (graphI I). \\<forall> l' \\<in> nodes (graphI I). \n      (l \\<noteq> l' \\<longrightarrow> (kgra (graphI I) a l) \\<inter> kgra(graphI I) a l' = {}))) \\<Longrightarrow>\n     (\\<forall> l \\<in> nodes (graphI I). {(Id, Eid).\n          (Id, Eid) \\<in> InfrastructureThree.kgra (InfrastructureThree.graphI I) ''Eve'' l \\<and> Id \\<noteq> ''Eve'' \\<and> Eid = eid} \\<noteq>\n         {} \\<longrightarrow>\n     ( 2 \\<le> card {(Id, Eid).\n                    (Id, Eid) \\<in> InfrastructureThree.kgra (InfrastructureThree.graphI I) ''Eve'' l \\<and>\n                    Id \\<noteq> ''Eve'' \\<and> Eid = eid})) \\<Longrightarrow> global_policyR I eid\"\n  apply (unfold global_policyR_def)\n  apply (rule allI)\n  apply (rule impI)+\n  apply (subgoal_tac \"(0 < card L \\<and> card L < 2) \\<or> card L \\<ge> 2\")\n   prefer 2\n   apply arith\n  apply (erule disjE)\n  apply (rule all_kgra_disj_imp_less_two_inv, assumption, simp, assumption, simp, assumption)\n  using all_kgra_disj_imp_greater_two_inv by presburger\n\n(* *)\n\n(* Should be the same as the global_policy and the intersection should follow *)\nlemma global_policy_valid: \"(corona_scenarioR  \\<rightarrow>\\<^sub>n* y) \\<Longrightarrow>  global_policyR y eid\"\n  apply (rule all_kgra_disj_imp_inv)\n  apply (simp add: InfrastructureThree.state_transition_in_refl_def all_corona_actors corona_actorsR_def)\n   apply (rule theoremAOO, simp add: state_transition_in_refl_def)\n       apply (simp add: kgra_init_lem)\n  apply (simp add: inj_efids_list_init_lem)\n  apply (simp add: actors_unique_init_lem)\n  apply (simp add: range_disjoint_corona_scenarioR)\n   apply (simp add: efid_eq_efid_cur_corona_scenarioR)\n  apply (rule last_lemOO)\n           apply (simp add: state_transition_in_refl_def)\n  using kgra_init_lem apply blast\n  using range_disjoint_corona_scenarioR apply blast\n  apply (smt (verit, best) InfrastructureThree.efids_cur_in_efids_listO disjoint_iff inj_onI range_disjoint_corona_scenarioR)\n  using inj_efids_list_init_lem apply blast\n  using actors_unique_init_lem apply blast\n  using local.isthere_lem00 apply blast\n    apply (rule finite_egra_init_lem) \n   apply (rule finite_agra_init_lem)\n  using numbers_actors_inv_corona_scenarioR by blast \n\n\nlemma  AG_all_sO_n: \"(\\<forall>y. (x,y)\\<in> {(x,y). state_transition_in x y}\\<^sup>* \\<longrightarrow> y \\<in> s) \\<Longrightarrow> x \\<in> AG s\"\n  apply (rule AG_all_sO)\n  by (smt (verit) Collect_cong InfrastructureThree.state_transition_infra_def split_cong state_transition_refl_def)\n\ntheorem RR_cycle_succeeds: \"corona_KripkeR \\<turnstile> AG {x. \\<forall> n. global_policyR x (Efid n)}\"\n  apply (simp add: check_def)\n  apply (rule subsetI)\n  apply (simp add: corona_KripkeR_def IcoronaR_def corona_statesR_def)\n  apply (rule conjI)\n  using EF_lem2a EF_step_star_rev apply blast\n  apply (rule AG_all_sO_n)\n  apply (rule allI)\n  apply (rule impI)\n  apply (rule CollectI, rule allI)\n  apply (rule global_policy_valid)\nby (simp add: state_transition_in_refl_def)\n \n\nend\nend\n", "meta": {"author": "flokam", "repo": "CoronaApp", "sha": "6258178b8f9d10f43e0825d99cbb0126ee51612c", "save_path": "github-repos/isabelle/flokam-CoronaApp", "path": "github-repos/isabelle/flokam-CoronaApp/CoronaApp-6258178b8f9d10f43e0825d99cbb0126ee51612c/IsabelleCorona/CoronaAppThree.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6039318337259584, "lm_q2_score": 0.4263215925474903, "lm_q1q2_score": 0.25746918114417666}}
{"text": "(*\n    Author:      David Sanan\n    Maintainer:  David Sanan, sanan at ntu edu sg\n    License:     LGPL\n*)\n\n(*  Title:      LocalRG_HoareDef.thy\n    Author:     David Sanan, NTU\n\nCopyright (C) 2015-2016 David Sanan \nSome rights reserved, NTU\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\ntheory LocalRG_HoareDef           \nimports \"SmallStepCon\" \"EmbSimpl.HoarePartialProps\" \"HOL-Library.Countable\"\nbegin\nsection \\<open>Validity  of Correctness Formulas\\<close>\n\nsubsection \\<open>Aux\\<close>\n\nabbreviation (input)\n  set_fun :: \"'a set \\<Rightarrow> 'a \\<Rightarrow> bool\"  (\"_\\<^sub>f\") where\n  \"set_fun s \\<equiv> \\<lambda>v. v\\<in>s\"\n\nabbreviation (input)\n  fun_set :: \"('a \\<Rightarrow> bool) \\<Rightarrow> 'a set\"  (\"_\\<^sub>s\") where\n  \"fun_set f \\<equiv> {\\<sigma>. f \\<sigma>}\"\n\n\nlemma tl_pair:\"Suc (Suc j) < length l \\<Longrightarrow>     \n       l1 = tl l \\<Longrightarrow>\n       P (l!(Suc j)) (l!(Suc (Suc j)))=\n       P  (l1!j) (l1!(Suc j))\"\nby (simp add: tl_zero_eq)\n\nlemma for_all_k_sublist:\nassumes a0:\"Suc (Suc j)<length l\" and\n      a1:\"(\\<forall>k < j. P ((tl l)!k) ((tl l)!(Suc k)))\" and\n      a2:\"P (l!0) (l!(Suc 0))\" \nshows \"(\\<forall>k < Suc j.  P (l!k) (l!(Suc k)))\"\nproof -\n  {fix k\n   assume aa0:\"k < Suc j\"\n   have \"P (l!k) (l!(Suc k))\"\n   proof (cases k)\n     case 0 thus ?thesis using a2 by auto\n   next\n     case (Suc k1) thus ?thesis using aa0 a0 a1 a2\n       by (metis SmallStepCon.nth_tl Suc_less_SucD dual_order.strict_trans length_greater_0_conv nth_Cons_Suc zero_less_Suc)\n   qed\n  } thus ?thesis by auto\nqed\n\n\nsubsection \\<open>Validity for Component Programs.\\<close>\n\ntype_synonym ('s,'f) tran = \"('s,'f) xstate \\<times> ('s,'f) xstate\"\ntype_synonym ('s,'p,'f,'e) rgformula =  \n   \"(('s,'p,'f,'e) com \\<times>      \n    ('s set) \\<times>         \n    (('s,'f) tran) set \\<times>\n    (('s,'f) tran) set \\<times>\n    ('s set) \\<times> \n    ('s set))\" (* A *)\n    \ntype_synonym ('s,'p,'f,'e) sextuple =  \n   \"('p \\<times>     \n    ('s set) \\<times>         \n    (('s,'f) tran) set \\<times> \n    (('s,'f) tran) set \\<times> \n    ('s set) \\<times>\n    ('s set))\" (* A *)    \n\ndefinition Sta :: \"'s set \\<Rightarrow> (('s,'f) tran) set \\<Rightarrow> bool\" where\n  \"Sta \\<equiv> \\<lambda>f g. (\\<forall>x y x'. x' \\<in> f \\<and> x=Normal x' \\<longrightarrow>  (x,y)\\<in> g \\<longrightarrow> (\\<exists>y'. y=Normal y' \\<and> y' \\<in> f))\"\n\nlemma Sta_intro:\"Sta a R \\<Longrightarrow> Sta b R \\<Longrightarrow> Sta (a \\<inter> b) R\"\nunfolding Sta_def by fastforce\n\nlemma Sta_assoc:\"Sta (a \\<inter> (b \\<inter> c)) R = Sta ((a\\<inter>b)\\<inter>c) R\"\nunfolding Sta_def by fastforce\n\nlemma Sta_comm:\"Sta (a \\<inter> b) R = Sta (b \\<inter> a) R\" \nunfolding Sta_def by fastforce\n\nlemma Sta_add:\"Sta (a \\<inter> b) R \\<Longrightarrow> Sta (a \\<inter> c) R \\<Longrightarrow>\n       Sta (a \\<inter> b \\<inter> c) R\"\nunfolding Sta_def by fastforce\n\nlemma Sta_tran:\"Sta a R \\<Longrightarrow> a = b \\<Longrightarrow> Sta b R\"\nby auto\n\ndefinition Norm:: \"(('s,'f) tran) set \\<Rightarrow> bool\" where\n  \"Norm \\<equiv> \\<lambda>g. (\\<forall>x y. (x, y) \\<in> g \\<longrightarrow> (\\<exists>x' y'. x=Normal x' \\<and> y=Normal y'))\"\n\ndefinition env_tran::\n    \"('p \\<Rightarrow> ('s, 'p, 'f,'e) LanguageCon.com option)\n     \\<Rightarrow> ('s set)\n        \\<Rightarrow> (('s, 'p, 'f,'e) LanguageCon.com \\<times> ('s, 'f) xstate) list\n           \\<Rightarrow> ('s,'f) tran set \\<Rightarrow> bool\"\nwhere\n\"env_tran \\<Gamma> q l rely \\<equiv> snd(l!0) \\<in> Normal ` q \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                  \n                   (snd(l!i), snd(l!(Suc i))) \\<in> rely)\n\"\n\ndefinition env_tran_right::\n    \"('p \\<Rightarrow> ('s, 'p, 'f,'e) LanguageCon.com option)     \n        \\<Rightarrow> (('s, 'p, 'f,'e) LanguageCon.com \\<times> ('s, 'f) xstate) list\n           \\<Rightarrow> ('s,'f) tran set \\<Rightarrow> bool\"\nwhere\n\"env_tran_right \\<Gamma> l rely \\<equiv> \n   (\\<forall>i. Suc i<length l \\<longrightarrow> \n        \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                  \n        (snd(l!i), snd(l!(Suc i))) \\<in> rely)\n\"\n\nlemma env_tran_tail:\"env_tran_right \\<Gamma> (x#l) R \\<Longrightarrow> env_tran_right \\<Gamma> l R\"\nunfolding env_tran_right_def\nby fastforce\n\nlemma env_tran_subr:\nassumes a0:\"env_tran_right \\<Gamma> (l1@l2) R\"\nshows \"env_tran_right \\<Gamma> l1 R\"\nunfolding env_tran_right_def\nproof -\n  {fix i\n  assume a1:\"Suc i< length l1\"\n  assume a2:\"\\<Gamma>\\<turnstile>\\<^sub>c l1 ! i \\<rightarrow>\\<^sub>e l1 ! Suc i\"\n  then have \"Suc i < length (l1@l2)\" using a1 by fastforce\n  also then have \"\\<Gamma>\\<turnstile>\\<^sub>c (l1@l2) ! i \\<rightarrow>\\<^sub>e (l1@l2) ! Suc i\" \n  proof -\n    show ?thesis\n      by (simp add: Suc_lessD a1 a2 nth_append)\n  qed\n  ultimately have f1:\"(snd ((l1@l2)! i), snd ((l1@l2) ! Suc i)) \\<in> R\"\n  using a0 unfolding env_tran_right_def by auto\n  then have \"(snd (l1! i), snd (l1 ! Suc i)) \\<in>  R\"\n  using a1\nproof -\n  have \"\\<forall>ps psa n. if n < length ps then (ps @ psa) ! n = (ps ! n::('b, 'a, 'c,'d) LanguageCon.com \\<times> ('b, 'c) xstate) \n                   else (ps @ psa) ! n = psa ! (n - length ps)\"\n    by (meson nth_append)\n  then show ?thesis\n    using f1 \\<open>Suc i < length l1\\<close> by force\nqed \n  } then show \n   \"\\<forall>i. Suc i < length l1 \\<longrightarrow>\n        \\<Gamma>\\<turnstile>\\<^sub>c l1 ! i \\<rightarrow>\\<^sub>e l1 ! Suc i \\<longrightarrow>\n        (snd (l1 ! i), snd (l1 ! Suc i)) \\<in> R\"\n   by blast\nqed\n\ndefinition Satis where \"Satis \\<equiv> True\"\n\ndefinition sep_conj where \"sep_conj \\<equiv> True\"\n\nlemma env_tran_subl:\"env_tran_right \\<Gamma> (l1@l2) R \\<Longrightarrow> env_tran_right \\<Gamma> l2 R\"\nproof (induct \"l1\")\n  case Nil thus ?case by auto\nnext\n  case (Cons a l1) thus ?case by (fastforce intro:append_Cons env_tran_tail )\nqed\n\nlemma env_tran_R_R':\"env_tran_right \\<Gamma> l R \\<Longrightarrow>  \n                     (R  \\<subseteq> R') \\<Longrightarrow>\n                     env_tran_right \\<Gamma> l R'\"\nunfolding env_tran_right_def Satis_def sep_conj_def\napply clarify\napply (erule allE)\napply auto\ndone\n\n\nlemma env_tran_normal:\nassumes a0:\"env_tran_right \\<Gamma> l rely \\<and> Sta q rely \\<and>  snd(l!i) = Normal s1 \\<and> s1\\<in>q\" and\n        a1:\"Suc i < length l \\<and>  \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i))\"\nshows \"\\<exists>s1 s2. snd(l!i) = Normal s1 \\<and> snd(l!(Suc i)) = Normal s2 \\<and> s2\\<in>q\"\nusing a0 a1 unfolding env_tran_right_def Sta_def by fastforce\n\nlemma no_env_tran_not_normal:\nassumes a0:\"env_tran_right \\<Gamma> l rely \\<and> Sta q rely \\<and>  snd(l!i) = Normal s1 \\<and> s1\\<in>q\" and\n        a1:\"Suc i < length l \\<and>  \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i))\" and\n        a2:\"(\\<forall>s1. \\<not> (snd(l!i) = Normal s1)) \\<or> (\\<forall>s2. \\<not> (snd (l!Suc i) = Normal s2))\"\nshows \"P\"\nusing a0 a1 a2 unfolding env_tran_right_def Sta_def by fastforce \n \ndefinition assum :: \n  \"('s set \\<times> ('s,'f) tran set) \\<Rightarrow> (('s,'p,'f,'e) confs) set\" where\n  \"assum \\<equiv> \\<lambda>(pre, rely). \n             {c. snd((snd c)!0) \\<in> Normal ` pre \\<and> \n                 (\\<forall>i. Suc i<length (snd c) \\<longrightarrow> \n                 (fst c)\\<turnstile>\\<^sub>c((snd c)!i)  \\<rightarrow>\\<^sub>e ((snd c)!(Suc i)) \\<longrightarrow>                  \n                   (snd((snd c)!i), snd((snd c)!(Suc i))) \\<in>  rely)}\"\n\ndefinition assum1 :: \n  \"('s set \\<times> ('s,'f) tran set) \\<Rightarrow>\n   'f set \\<Rightarrow>\n     (('s,'p,'f,'e) confs) set\" where\n  \"assum1 \\<equiv> \\<lambda>(pre, rely) F. \n             {(\\<Gamma>,comp). snd(comp!0) \\<in> Normal ` pre \\<and> \n                 (\\<forall>i. Suc i<length comp \\<longrightarrow> \n                  \\<Gamma>\\<turnstile>\\<^sub>c(comp!i)  \\<rightarrow>\\<^sub>e (comp!(Suc i)) \\<longrightarrow>                  \n                   (snd(comp!i), snd(comp!(Suc i))) \\<in>  rely)}\"\n\n\nlemma assum_R_R': \n  \"(\\<Gamma>, l) \\<in> assum(p, R) \\<Longrightarrow>\n    snd(l!0) \\<in> Normal `  p' \\<Longrightarrow>\n    R \\<subseteq> R'  \\<Longrightarrow> \n   (\\<Gamma>, l) \\<in> assum(p', R')\"\nproof -\nassume a0:\"(\\<Gamma>, l) \\<in> assum(p, R)\" and\n       a1:\"snd(l!0) \\<in> Normal `  p'\" and\n       a2: \" R \\<subseteq> R'\"\n  then have \"env_tran_right \\<Gamma> l R\" \n    unfolding assum_def using env_tran_right_def\n    by force\n  then have \"env_tran_right \\<Gamma> l R'\" \n    using  a2 env_tran_R_R' by blast\n  thus ?thesis using a1 unfolding assum_def unfolding env_tran_right_def\n    by fastforce\nqed\n\n\nlemma same_prog_p:\n  \"(\\<Gamma>,(P,s)#(P,t)#l)\\<in>cptn \\<Longrightarrow>\n   (\\<Gamma>,(P,s)#(P,t)#l) \\<in> assum (p,R) \\<Longrightarrow>\n   Sta p R  \\<Longrightarrow>\n   \\<exists>t1. t=Normal t1 \\<and> t1 \\<in> p\n  \" \nproof -\nassume a0: \"(\\<Gamma>,(P,s)#(P,t)#l)\\<in>cptn\" and\n         a1: \"(\\<Gamma>,(P,s)#(P,t)#l) \\<in> assum (p,R)\" and\n         a2: \"Sta p R\"\n  then have \"Suc 0 < length ((P,s)#(P,t)#l)\" \n    by fastforce\n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c(((P,s)#(P,t)#l)!0)  \\<rightarrow>\\<^sub>c\\<^sub>e (((P,s)#(P,t)#l)!(Suc 0))\" \n    using a0 cptn_stepc_rtran by fastforce \n  then have step_ce:\"\\<Gamma>\\<turnstile>\\<^sub>c(((P,s)#(P,t)#l)!0)  \\<rightarrow>\\<^sub>e (((P,s)#(P,t)#l)!(Suc 0)) \\<or>\n             \\<Gamma>\\<turnstile>\\<^sub>c(((P,s)#(P,t)#l)!0)  \\<rightarrow> (((P,s)#(P,t)#l)!(Suc 0))\"\n    using step_ce_elim_cases by blast  \n  then obtain s1 where s:\"s=Normal s1 \\<and> s1 \\<in> p\" \n    using a1 unfolding assum_def\n    by fastforce\n  have \"\\<exists>t1. t=Normal t1 \\<and> t1 \\<in> p \"\n  using step_ce\n  proof\n    {assume step_e:\"\\<Gamma>\\<turnstile>\\<^sub>c ((P, s) # (P, t) # l) ! 0 \\<rightarrow>\\<^sub>e\n          ((P, s) # (P, t) # l) ! Suc 0\"\n     have ?thesis \n     using a2 a1 s unfolding Sta_def assum_def \n     proof -\n       have \"(Suc 0 < length ((P, s) # (P, t) # l))\"\n         by fastforce\n       then have assm:\"(s, t) \\<in> R\"\n         using s a1 step_e\n         unfolding assum_def  by fastforce\n       then obtain t1 s2 where s_t:\"s= Normal s2 \\<and> t = Normal t1\" \n         using a2 s unfolding Sta_def by fastforce \n       then have R:\"(s,t)\\<in>R\" \n         using assm  unfolding Satis_def by fastforce\n       then have \"s2=s1\" using s s_t by fastforce\n       then have \"t1\\<in>p\" \n         using a2 s s_t R unfolding Sta_def Norm_def by blast\n       thus ?thesis using s_t by blast\n     qed thus ?thesis by auto\n    } \n    next\n    { \n      assume step:\"\\<Gamma>\\<turnstile>\\<^sub>c ((P, s) # (P, t) # l) ! 0 \\<rightarrow>\n          ((P, s) # (P, t) # l) ! Suc 0\"\n      then have \"P\\<noteq>P \\<or> s=t\"\n      proof -\n        have \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow> (P, t)\"\n          using local.step by force\n        then show ?thesis\n          using step_change_p_or_eq_s by blast\n      qed\n      then show ?thesis using s by fastforce\n    }\n  qed thus  ?thesis by auto\nqed\n\nlemma tl_of_assum_in_assum:\n  \"(\\<Gamma>,(P,s)#(P,t)#l)\\<in>cptn \\<Longrightarrow>\n   (\\<Gamma>,(P,s)#(P,t)#l) \\<in> assum (p,R) \\<Longrightarrow>\n   Sta p R  \\<Longrightarrow>\n   (\\<Gamma>,(P,t)#l) \\<in> assum (p,R)\n  \" \nproof -\n  assume a0: \"(\\<Gamma>,(P,s)#(P,t)#l)\\<in>cptn\" and\n         a1: \"(\\<Gamma>,(P,s)#(P,t)#l) \\<in> assum (p,R)\" and\n         a2: \"Sta p R \"\n  \n  then obtain t1 where t1:\"t=Normal t1 \\<and> t1 \\<in>p\" \n   using same_prog_p by blast\n  then have \"env_tran_right \\<Gamma> ((P,s)#(P,t)#l) R\"\n    using env_tran_right_def a1 unfolding assum_def\n    by force\n  then have \"env_tran_right \\<Gamma> ((P,t)#l) R\"\n    using env_tran_tail by auto\n  thus ?thesis using t1 unfolding assum_def env_tran_right_def by auto\nqed\n\nlemma tl_of_assum_in_assum1:\n  \"(\\<Gamma>,(P,s)#(Q,t)#l)\\<in>cptn \\<Longrightarrow>\n   (\\<Gamma>,(P,s)#(Q,t)#l) \\<in> assum (p,R) \\<Longrightarrow>\n   t \\<in> Normal ` q \\<Longrightarrow>\n   (\\<Gamma>,(Q,t)#l) \\<in> assum (q,R) \n  \" \nproof -\n  assume a0: \"(\\<Gamma>,(P,s)#(Q,t)#l)\\<in>cptn\" and\n         a1: \"(\\<Gamma>,(P,s)#(Q,t)#l) \\<in> assum (p,R)\" and\n         a2: \"t \\<in> Normal ` q\"  \n  then have \"env_tran_right \\<Gamma> ((P,s)#(Q,t)#l) R\"\n    using env_tran_right_def a1 unfolding assum_def\n    by force\n  then have \"env_tran_right \\<Gamma> ((Q,t)#l) R\"\n    using env_tran_tail by auto\n  thus ?thesis using a2 unfolding assum_def env_tran_right_def by auto\nqed\n            \nlemma sub_assum:\n  assumes a0: \"(\\<Gamma>,(x#l0)@l1) \\<in> assum (p,R)\"\n  shows \"(\\<Gamma>,x#l0) \\<in> assum (p,R)\"    \nproof -\n  {have p0:\"snd x \\<in> Normal ` p\" \n    using a0 unfolding assum_def by force\n  then have \"env_tran_right \\<Gamma> ((x#l0)@l1) R\"\n    using a0 unfolding assum_def \n    by (auto simp add: env_tran_right_def)\n  then have env:\"env_tran_right \\<Gamma> (x#l0) R\" \n    using env_tran_subr by blast \n  also have \"snd ((x#l0)!0)  \\<in> Normal ` p\" \n    using p0 by fastforce\n  ultimately have \"snd ((x#l0)!0)  \\<in> Normal ` p \\<and> \n                  (\\<forall>i. Suc i<length (x#l0) \\<longrightarrow> \n                       \\<Gamma>\\<turnstile>\\<^sub>c((x#l0)!i)  \\<rightarrow>\\<^sub>e ((x#l0)!(Suc i)) \\<longrightarrow>                  \n                       (snd((x#l0)!i), snd((x#l0)!(Suc i))) \\<in> R)\"\n   unfolding env_tran_right_def by auto\n  }    \n  then show ?thesis  unfolding assum_def by auto\nqed      \n\nlemma sub_assum_r:\n  assumes a0: \"(\\<Gamma>,l0@x1#l1) \\<in> assum (p,R)\" and\n          a1: \"(snd x1) \\<in> Normal ` q\"\n  shows \"(\\<Gamma>,x1#l1) \\<in> assum (q,R)\"\nproof -\n  have \"env_tran_right  \\<Gamma> (l0@x1#l1) R\"\n    using a0 unfolding assum_def env_tran_right_def\n    by fastforce\n  then have \"env_tran_right \\<Gamma> (x1#l1) R\"\n    using env_tran_subl by auto\n  thus ?thesis using a1 unfolding assum_def env_tran_right_def by fastforce\nqed\n\ndefinition comm :: \n  \"(('s,'f) tran) set \\<times> \n   ('s set \\<times> 's set) \\<Rightarrow>\n   'f set \\<Rightarrow> \n     (('s,'p,'f,'e) confs) set\" where\n  \"comm \\<equiv> \\<lambda>(guar, (q,a)) F. \n            {c. snd (last (snd c)) \\<notin> Fault ` F  \\<longrightarrow> \n                (\\<forall>i. \n                 Suc i<length (snd c) \\<longrightarrow> \n                 (fst c)\\<turnstile>\\<^sub>c((snd c)!i)  \\<rightarrow> ((snd c)!(Suc i)) \\<longrightarrow>                                        \n                   (snd((snd c)!i), snd((snd c)!(Suc i))) \\<in> guar) \\<and> \n                 (final (last (snd c))  \\<longrightarrow>                   \n                    ((fst (last (snd c)) = Skip \\<and> \n                      snd (last (snd c)) \\<in> Normal ` q)) \\<or>\n                    (fst (last (snd c)) = Throw \\<and> \n                      snd (last (snd c)) \\<in> Normal ` a))}\"\n\ndefinition comm1 :: \n  \"(('s,'f) tran) set \\<times> \n   ('s set \\<times> 's set) \\<Rightarrow>\n   'f set \\<Rightarrow> \n     (('s,'p,'f,'e) confs) set\" where\n  \"comm1 \\<equiv> \\<lambda>(guar, (q,a)) F. \n            {(\\<Gamma>,comp). snd (last comp) \\<notin> Fault ` F  \\<longrightarrow> \n                (\\<forall>i. \n                 Suc i<length comp \\<longrightarrow> \n                 \\<Gamma>\\<turnstile>\\<^sub>c(comp!i)  \\<rightarrow> (comp!(Suc i)) \\<longrightarrow>                                        \n                   (snd(comp!i), snd(comp!(Suc i))) \\<in> guar) \\<and> \n                 (final (last comp)  \\<longrightarrow>                   \n                    ((fst (last comp) = Skip \\<and> \n                      snd (last comp) \\<in> Normal ` q)) \\<or>\n                    (fst (last comp) = Throw \\<and> \n                      snd (last comp) \\<in> Normal ` a))}\"\n\nlemma comm_dest:\n\"(\\<Gamma>, l)\\<in> comm (G,(q,a)) F \\<Longrightarrow>\n snd (last l) \\<notin> Fault ` F \\<Longrightarrow>\n (\\<forall>i. Suc i<length l \\<longrightarrow>\n   \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow> \n    (snd(l!i), snd(l!(Suc i))) \\<in>  G)\"\nunfolding comm_def\napply clarify\napply (drule mp)\napply fastforce\napply (erule conjE)\napply (erule allE)\nby auto\n\nlemma comm_dest1:\n\"(\\<Gamma>, l)\\<in> comm (G,(q,a)) F \\<Longrightarrow>\n snd (last l) \\<notin> Fault ` F \\<Longrightarrow>\n Suc i<length l \\<Longrightarrow>\n \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<Longrightarrow>\n(snd(l!i), snd(l!(Suc i))) \\<in> G\"\nunfolding comm_def\napply clarify\napply (drule mp)\napply fastforce\napply (erule conjE)\napply (erule allE)\nby auto\n\nlemma comm_dest2:\n  assumes a0: \"(\\<Gamma>, l)\\<in> comm (G,(q,a)) F\" and\n          a1: \"final (last l)\" and\n          a2: \"snd (last l) \\<notin> Fault ` F\" \n  shows  \" ((fst (last l) = Skip \\<and> \n            snd (last l) \\<in> Normal ` q)) \\<or>\n            (fst (last l) = Throw \\<and> \n            snd (last l) \\<in> Normal ` a)\"\nproof -\n  show ?thesis using a0 a1 a2 unfolding comm_def by auto\nqed\n\nlemma comm_des3:\n  assumes a0: \"(\\<Gamma>, l)\\<in> comm (G,(q,a)) F\" and\n          a1: \"snd (last l) \\<notin> Fault ` F\"\n shows \"final (last l) \\<longrightarrow> ((fst (last l) = Skip \\<and> \n            snd (last l) \\<in> Normal ` q)) \\<or>\n            (fst (last l) = Throw \\<and> \n            snd (last l) \\<in> Normal ` a)\"\nusing a0 a1 unfolding comm_def by auto\n\nlemma commI:\n  assumes a0:\"snd (last l) \\<notin> Fault ` F \\<Longrightarrow>\n             (\\<forall>i. \n                 Suc i<length l \\<longrightarrow> \n                 \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                                               \n                   (snd(l!i), snd(l!(Suc i))) \\<in> G) \\<and> \n                 (final (last l)  \\<longrightarrow>                   \n                    ((fst (last l) = Skip \\<and> \n                      snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                      snd (last l) \\<in> Normal ` a))\"\nshows \"(\\<Gamma>,l)\\<in>comm (G, (q,a)) F\"\nusing a0  unfolding comm_def\napply clarify\nby simp\n\nlemma comm_conseq:\n  \"(\\<Gamma>,l) \\<in> comm(G', (q',a')) F \\<Longrightarrow>\n       G' \\<subseteq> G \\<and>\n       q' \\<subseteq> q \\<and>\n       a' \\<subseteq> a \\<Longrightarrow>\n      (\\<Gamma>,l) \\<in> comm (G,(q,a)) F\"\nproof -\n  assume a0:\"(\\<Gamma>,l) \\<in> comm(G', (q',a')) F\" and\n         a1:\" G' \\<subseteq> G  \\<and>\n        q' \\<subseteq> q \\<and>\n        a' \\<subseteq> a\"\n  {\n    assume a:\"snd (last l) \\<notin> Fault ` F \"\n    have l:\"(\\<forall>i. \n           Suc i<length l \\<longrightarrow> \n           \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                                          \n             (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n    proof -\n      {fix i ns ns'\n      assume a00:\"Suc i<length l\" and\n             a11:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i))\"             \n      have \"(snd(l!i), snd(l!(Suc i))) \\<in>  G\" \n      proof -\n        have \"(snd(l!i), snd(l!(Suc i))) \\<in>  G'\"\n        using comm_dest1 [OF a0 a a00 a11]  by auto\n        thus ?thesis using a1 unfolding Satis_def sep_conj_def by fastforce\n      qed\n      } thus ?thesis by auto\n    qed  \n    have \"(final (last l)  \\<longrightarrow>                   \n                    ((fst (last l) = Skip \\<and> \n                      snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                      snd (last l) \\<in> Normal ` a))\"\n    proof -\n      {assume a33:\"final (last l)\"\n      then have \"((fst (last l) = Skip \\<and> \n                      snd (last l) \\<in> Normal ` q')) \\<or>\n                    (fst (last l) = Throw \\<and> \n                      snd (last l) \\<in> Normal ` a')\"\n      using comm_dest2[OF a0 a33 a] by auto\n      then have \"((fst (last l) = Skip \\<and> \n                      snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                      snd (last l) \\<in> Normal ` a)\"\n      using a1 by fastforce\n     } thus ?thesis by auto\n    qed\n    note res1 = conjI[OF l this] \n  } thus ?thesis unfolding comm_def by simp\nqed   \n\nlemma  no_comp_tran_no_final_comm:\n  assumes a0:\"\\<forall>i<length l. \\<not> final (l!i)\" and\n          a1:\"\\<forall>i<length l. fst (l!i) = C\" and a2:\"length l>0\"\n        shows \"(\\<Gamma>,l)\\<in>comm(G, (q,a)) F\"\nproof-\n  have n_comp:\"\\<forall>i. Suc i < length l \\<longrightarrow> \\<not> (\\<Gamma>\\<turnstile>\\<^sub>c (l!i) \\<rightarrow> (l!Suc i))\" using a1\n    by (metis Suc_lessD mod_env_not_component prod.collapse)\n  {assume a00:\"snd (last l) \\<notin> Fault ` F\" \n    {fix i\n      assume \"Suc i< length(l)\" and \n             \"\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i))\"  \n      then have False using n_comp by auto\n    }\n    moreover {\n      assume \"final (last l)\"\n      then have False using a0 a2\n        using last_conv_nth by force\n      }\n      ultimately have ?thesis unfolding comm_def using a00 by auto\n  } thus ?thesis unfolding comm_def by auto   \nqed\n\ndefinition com_validity :: \n  \"('s,'p,'f,'e) body \\<Rightarrow>  'f set \\<Rightarrow> ('s,'p,'f,'e) com \\<Rightarrow> \n    's set \\<Rightarrow> (('s,'f) tran) set \\<Rightarrow>  (('s,'f) tran) set \\<Rightarrow>  \n    's set \\<Rightarrow>  's set \\<Rightarrow>  bool\" \n    (\"_ \\<Turnstile>\\<^bsub>'/_\\<^esub>/ _ sat [_,_, _, _,_]\" [61,60,0,0,0,0,0,0] 45) where\n  \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> Pr sat [p, R, G, q,a] \\<equiv> \n   \\<forall>s. cp \\<Gamma> Pr s \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F\"\n\ndefinition com_cvalidity::\n \"('s,'p,'f,'e) body \\<Rightarrow>\n    ('s,'p,'f,'e) sextuple set \\<Rightarrow>\n    'f set \\<Rightarrow>\n    ('s,'p,'f,'e) com \\<Rightarrow> \n    's set \\<Rightarrow>          \n    (('s,'f) tran) set \\<Rightarrow> \n    (('s,'f) tran) set \\<Rightarrow>  \n    's set \\<Rightarrow> \n    's set \\<Rightarrow>\n      bool\" \n    (\"_,_ \\<Turnstile>\\<^bsub>'/_\\<^esub>/ _ sat [_,_, _, _,_]\" [61,60,0,0,0,0,0,0] 45) where\n  \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> Pr sat [p, R, G, q,a] \\<equiv> \n   (\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]) \\<longrightarrow> \n     \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> Pr sat [p, R, G, q,a]\"\n\ndefinition com_validityn :: \n  \"('s,'p,'f,'e) body \\<Rightarrow> nat \\<Rightarrow> 'f set  \\<Rightarrow> ('s,'p,'f,'e) com \\<Rightarrow> \n    's set \\<Rightarrow> (('s,'f) tran) set \\<Rightarrow>  (('s,'f) tran) set \\<Rightarrow>  \n    's set \\<Rightarrow>  's set \\<Rightarrow>  bool\" \n    (\"_ \\<Turnstile>_\\<^bsub>'/_\\<^esub>/ _ sat [_,_, _, _,_]\" [61,0,60,0,0,0,0,0,0] 45) where\n  \"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> Pr sat [p, R, G, q,a] \\<equiv> \n   \\<forall>s. cpn n \\<Gamma> Pr s \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F\"\n\ndefinition com_cvalidityn::\n \"('s,'p,'f,'e) body \\<Rightarrow>\n    ('s,'p,'f,'e) sextuple set \\<Rightarrow> nat \\<Rightarrow>\n    'f set \\<Rightarrow>\n    ('s,'p,'f,'e) com \\<Rightarrow> \n    's set \\<Rightarrow>          \n    (('s,'f) tran) set \\<Rightarrow> \n    (('s,'f) tran) set \\<Rightarrow>  \n    's set \\<Rightarrow> \n    's set \\<Rightarrow>\n      bool\" \n    (\"_,_ \\<Turnstile>_\\<^bsub>'/_\\<^esub>/ _ sat [_,_, _, _,_]\" [61,60,0,0,0,0,0,0,0] 45) where\n  \"\\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> Pr sat [p, R, G, q,a] \\<equiv> \n   (\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]) \\<longrightarrow> \n     \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> Pr sat [p, R, G, q,a]\"\n\n\nlemma com_valid_iff_nvalid:\"(\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> Pr sat [p, R, G, q,a]) = (\\<forall>n. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> Pr sat [p, R, G, q,a])\"\n  apply (simp only: com_validity_def com_validityn_def cp_def cpn_def cptn_eq_cptn_mod_nest)\n  by fast\n\nlemma com_cnvalid_to_cvalid: \"(\\<forall>n. (\\<Gamma>,\\<Theta>\\<Turnstile>n\\<^bsub>/F\\<^esub> Pr sat [p, R, G, q,a])) \\<Longrightarrow> (\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> Pr sat [p, R, G, q,a])\"\n  apply (unfold com_cvalidityn_def com_cvalidity_def com_valid_iff_nvalid [THEN eq_reflection])\n  by fast\n\n\nlemma etran_in_comm:\n  \"(\\<Gamma>,(P, t) # xs) \\<in> comm(G, (q,a)) F  \\<Longrightarrow> \n    \\<not> (\\<Gamma>\\<turnstile>\\<^sub>c((P,s))  \\<rightarrow> ((P,t))) \\<Longrightarrow>\n    (\\<Gamma>,(P, s) # (P, t) # xs) \\<in> cptn \\<Longrightarrow>    \n   (\\<Gamma>,(P, s) # (P, t) # xs) \\<in> comm(G, (q,a)) F\" \nproof -\n  assume a1:\"(\\<Gamma>,(P, t) # xs) \\<in> comm(G, (q,a)) F\" and\n         a2:\"\\<not> \\<Gamma>\\<turnstile>\\<^sub>c((P,s))  \\<rightarrow> ((P,t))\" and\n         a3:\"(\\<Gamma>,(P, s) # (P, t) # xs) \\<in> cptn\"\n  show ?thesis using comm_def a1 a2 a3\n  proof -\n     {\n     let ?l1 = \"(P, t) # xs\"\n     let ?l = \"(P, s) # ?l1\"\n     assume a00:\"snd (last ?l) \\<notin> Fault ` F\"\n     have concl:\"(\\<forall>i ns ns'. Suc i<length ?l \\<longrightarrow> \n               \\<Gamma>\\<turnstile>\\<^sub>c(?l!i)  \\<rightarrow> (?l!(Suc i)) \\<longrightarrow>                          \n                 (snd(?l!i), snd(?l!(Suc i))) \\<in>  G)\"\n     proof -\n       {fix i ns ns'\n        assume a11:\"Suc i < length  ?l\" and\n               a12:\"\\<Gamma>\\<turnstile>\\<^sub>c (?l ! i) \\<rightarrow> ( ?l ! Suc i)\"               \n        have p1:\"(\\<forall>i ns ns'. Suc i<length ?l1 \\<longrightarrow> \n               \\<Gamma>\\<turnstile>\\<^sub>c(?l1!i)  \\<rightarrow> (?l1!(Suc i)) \\<longrightarrow>                             \n               (snd(?l1!i), snd(?l1!(Suc i))) \\<in>  G)\"\n        using a1 a3 a00 unfolding comm_def by auto\n        have \"(snd (?l ! i), snd (?l ! Suc i)) \\<in>  G\"         \n        proof (cases i)\n          case 0 \n          have  \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow> (P, t)\" using a12 0 by auto\n          thus ?thesis using a2 by auto             \n        next\n          case (Suc n) thus ?thesis\n          proof -\n            have f1: \"\\<Gamma>\\<turnstile>\\<^sub>c ((P, t) # xs) ! n \\<rightarrow> ((P, t) # xs) ! Suc n\"\n              using Suc a12 by fastforce\n            have f2: \"Suc n < length ((P, t) # xs)\"\n              using Suc a11 by fastforce                       \n            have \"snd (last ((P, t) # xs)) \\<notin> Fault ` F\"\n                by (metis (no_types) a00 last.simps list.distinct(1))\n            hence \"(snd (((P, t) # xs) ! n), snd (((P, t) # xs) ! Suc n)) \\<in> G\"\n              using f2 f1 a1 comm_dest1  by blast            \n            thus ?thesis\n              by (simp add: Suc)\n          qed  \n        qed\n       } thus ?thesis by auto\n     qed\n     have concr:\"(final (last ?l)  \\<longrightarrow>                   \n                    ((fst (last ?l) = Skip \\<and> \n                      snd (last ?l) \\<in> Normal ` q)) \\<or>\n                    (fst (last ?l) = Throw \\<and> \n                      snd (last ?l) \\<in> Normal ` a))\"\n     using a1 a00 unfolding comm_def by auto\n     note res1=conjI[OF concl concr] }   \n     thus ?thesis unfolding comm_def by auto qed\nqed\n\nlemma ctran_in_comm:   \n  \" (Normal s,Normal s) \\<in> G  \\<Longrightarrow>\n   (\\<Gamma>,(Q, Normal s) # xs) \\<in> comm(G, (q,a)) F  \\<Longrightarrow>        \n   (\\<Gamma>,(P, Normal s) # (Q, Normal s) # xs) \\<in> comm(G, (q,a)) F\"\nproof -\n  assume a1:\"(Normal s,Normal s) \\<in> G\" and\n         a2:\"(\\<Gamma>,(Q, Normal s) # xs) \\<in> comm(G, (q,a)) F\"          \n  show ?thesis using comm_def a1 a2\n  proof -\n     {\n     let ?l1 = \"(Q, Normal s) # xs\"\n     let ?l = \"(P, Normal s) # ?l1\"\n      assume a00:\"snd (last ?l) \\<notin> Fault ` F\"\n     have concl:\"(\\<forall>i. Suc i<length ?l \\<longrightarrow> \n               \\<Gamma>\\<turnstile>\\<^sub>c(?l!i)  \\<rightarrow> (?l!(Suc i)) \\<longrightarrow>                                              \n                 (snd(?l!i), snd(?l!(Suc i))) \\<in>  G)\"\n     proof -\n       {fix i ns ns'\n        assume a11:\"Suc i < length  ?l\" and\n               a12:\"\\<Gamma>\\<turnstile>\\<^sub>c (?l ! i) \\<rightarrow> ( ?l ! Suc i)\" \n        have p1:\"(\\<forall>i. Suc i<length ?l1 \\<longrightarrow> \n               \\<Gamma>\\<turnstile>\\<^sub>c(?l1!i)  \\<rightarrow> (?l1!(Suc i)) \\<longrightarrow>                              \n               (snd(?l1!i), snd(?l1!(Suc i))) \\<in>  G)\"\n        using a2 a00 unfolding comm_def by auto\n        have \"(snd (?l ! i), snd (?l ! Suc i)) \\<in> G\"   \n        proof (cases i)\n          case 0     \n          then have \"snd (((P, Normal s) # (Q, Normal s) # xs) ! i) = Normal s \\<and> \n                     snd (((P, Normal s) # (Q, Normal s) # xs) ! (Suc i)) = Normal s\"                \n            by fastforce\n          also have \"(Normal s, Normal s) \\<in> G\"\n             using Satis_def a1 by blast\n          ultimately show  ?thesis using a1 Satis_def by auto            \n        next\n          case (Suc n) thus ?thesis using p1 a2  a11 a12 \n          proof -\n            have f1: \"\\<Gamma>\\<turnstile>\\<^sub>c ((Q, Normal s) # xs) ! n \\<rightarrow> ((Q, Normal s) # xs) ! Suc n\"\n              using Suc a12 by fastforce\n            have f2: \"Suc n < length ((Q, Normal s) # xs)\"\n              using Suc a11 by fastforce\n            thus ?thesis using Suc f1 nth_Cons_Suc p1 by auto \n          qed  \n        qed\n       } thus ?thesis by auto\n     qed\n     have concr:\"(final (last ?l)  \\<longrightarrow> \n                  snd (last ?l) \\<notin> Fault ` F  \\<longrightarrow>\n                    ((fst (last ?l) = Skip \\<and> \n                      snd (last ?l) \\<in> Normal ` q)) \\<or>\n                    (fst (last ?l) = Throw \\<and> \n                      snd (last ?l) \\<in> Normal ` a))\"\n     using a2 unfolding comm_def by auto\n     note res=conjI[OF concl concr]}\n     thus ?thesis unfolding comm_def by auto qed\nqed\n\nlemma not_final_in_comm:\n \"(\\<Gamma>,(Q, Normal s) # xs) \\<in> comm(G, (q,a)) F \\<Longrightarrow>\n  \\<not> final (last ((Q, Normal s) # xs)) \\<Longrightarrow>\n  (\\<Gamma>,(Q, Normal s) # xs) \\<in> comm(G, (q',a')) F\"\nunfolding comm_def by force\n\nlemma comm_union:\n assumes \n   a0: \"(\\<Gamma>,xs) \\<in> comm(G, (q,a)) F\" and\n   a1: \"(\\<Gamma>,ys) \\<in> comm(G, (q',a')) F\" and\n   a2: \"xs\\<noteq>[] \\<and> ys\\<noteq>[]\" and\n   a3: \"( snd (last xs),snd (ys!0)) \\<in> G\" and\n   a4: \"(\\<Gamma>,xs@ys) \\<in> cptn\"\n shows \"(\\<Gamma>,xs@ys) \\<in> comm(G, (q',a')) F\" \nproof -\n{\n  let ?l=\"xs@ys\" \n  assume a00:\"snd (last (xs@ys)) \\<notin> Fault ` F\"\n  have last_ys:\"last (xs@ys) = last ys\" using a2 by fastforce\n  have concl:\"(\\<forall>i. Suc i<length ?l \\<longrightarrow> \n             \\<Gamma>\\<turnstile>\\<^sub>c(?l!i)  \\<rightarrow> (?l!(Suc i)) \\<longrightarrow>                                            \n               (snd(?l!i), snd(?l!(Suc i))) \\<in> G)\"\n   proof -\n     {fix i ns ns'\n      assume a11:\"Suc i < length  ?l\" and\n             a12:\"\\<Gamma>\\<turnstile>\\<^sub>c (?l ! i) \\<rightarrow> ( ?l ! Suc i)\" \n      have all_ys:\"\\<forall>i\\<ge>length xs. (xs@ys)!i = ys!(i-(length xs))\"\n          by (simp add: nth_append)   \n      have all_xs:\"\\<forall>i<length xs. (xs@ys)!i = xs!i\"\n            by (simp add: nth_append)\n      have \"(snd(?l!i), snd(?l!(Suc i))) \\<in>  G\"\n      proof (cases \"Suc i>length xs\")\n        case True                                 \n        have \"Suc (i - (length xs)) < length ys\" using a11 True by fastforce\n        moreover have \"\\<Gamma>\\<turnstile>\\<^sub>c (ys ! (i-(length xs))) \\<rightarrow> ( ys ! ((Suc i)-(length xs)))\" \n          using a12 all_ys True by fastforce          \n        moreover have \"snd (last ys) \\<notin> Fault ` F\" using last_ys a00 by fastforce   \n        ultimately have \"(snd(ys!(i-(length xs))), snd(ys!Suc (i-(length xs)))) \\<in> G\" \n        using a1 comm_dest1[of \\<Gamma> ys G q' a' F \"i-length xs\"] True Suc_diff_le by fastforce \n        thus ?thesis using True all_ys Suc_diff_le by fastforce\n      next\n        case False note F1=this  thus ?thesis \n        proof (cases \"Suc i < length xs\")\n          case True              \n          then have \"snd ((xs@ys)!(length xs -1)) \\<notin> Fault ` F\"\n            using a00 a2 a4 \n             by (simp add: last_not_F )         \n          then have \"snd (last xs) \\<notin> Fault ` F\" using all_xs a2 by (simp add: last_conv_nth )          \n          moreover have \"\\<Gamma>\\<turnstile>\\<^sub>c (xs ! i) \\<rightarrow> ( xs ! Suc i)\" \n            using True all_xs a12 by fastforce          \n          ultimately have\"(snd(xs!i), snd(xs!(Suc i))) \\<in> G\"\n            using a0 comm_dest1[of \\<Gamma> xs G q a F i] True by fastforce\n          thus ?thesis using True all_xs by fastforce\n        next\n          case False\n          then have suc_i:\"Suc i = length xs\" using F1 by fastforce\n          then have i:\"i=length xs -1\" using a2 by fastforce          \n          then show ?thesis using a3 \n            by (simp add: a2 all_xs all_ys  last_conv_nth ) \n        qed\n      qed\n     } thus ?thesis by auto          \n   qed\n   have concr:\"(final (last ?l)  \\<longrightarrow>                 \n                  ((fst (last ?l) = Skip \\<and> \n                    snd (last ?l) \\<in> Normal ` q')) \\<or>\n                  (fst (last ?l) = Throw \\<and> \n                    snd (last ?l) \\<in> Normal ` a'))\"\n   using a1 last_ys a00 a2 comm_des3 by fastforce\n   note res=conjI[OF concl concr]}\n   thus ?thesis unfolding comm_def by auto \nqed\n\n\n\nlemma cpn_rule1:\"(\\<forall>s. cpn n \\<Gamma> P s \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F) \\<Longrightarrow>\n      (\\<forall>s l. (\\<Gamma>,l)\\<in>cpn n \\<Gamma> P s \\<and> (\\<Gamma>,l)\\<in> assum (p, R) \\<longrightarrow> (\\<Gamma>,l) \\<in> comm(G, (q,a)) F)\"\nproof-\n  assume a0:\"\\<forall>s. cpn n \\<Gamma> P s \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F\"\n  {fix s l    \n    assume a00:\"(\\<Gamma>,l)\\<in>cpn n \\<Gamma> P s \\<and> (\\<Gamma>,l)\\<in> assum (p, R)\"    \n    then have \"cpn n \\<Gamma> P s \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F\" using a0 by auto    \n    then have \"(\\<Gamma>,l) \\<in> comm(G, (q,a)) F\" using a00 unfolding cpn_def assum_def comm_def\n      by blast\n    } then show ?thesis by auto\n  qed\n\nlemma cpn_rule2:\"(\\<forall>s l. (\\<Gamma>,l)\\<in>cpn n \\<Gamma> P s \\<and> (\\<Gamma>,l)\\<in> assum (p, R) \\<longrightarrow> (\\<Gamma>,l) \\<in> comm(G, (q,a)) F) \\<Longrightarrow>\n                (\\<forall>s. cpn n \\<Gamma> P s \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F)\"\nproof-\n  assume a0:\"\\<forall>s l. (\\<Gamma>,l)\\<in>cpn n \\<Gamma> P s \\<and> (\\<Gamma>,l)\\<in> assum (p, R) \\<longrightarrow> (\\<Gamma>,l) \\<in> comm(G, (q,a)) F\"\n  {fix s l\n     assume a00:\"(\\<Gamma>,l)\\<in> cpn n \\<Gamma> P s \\<and> (\\<Gamma>,l)\\<in>assum(p, R)\"        \n    then have \"(\\<Gamma>,l) \\<in> comm(G, (q,a)) F\" using a0 unfolding cpn_def assum_def comm_def\n      by blast\n   } then show ?thesis  unfolding cpn_def by fastforce\n qed\n\nlemma cpn_rule:\"(\\<forall>s l. (\\<Gamma>,l)\\<in>cpn n \\<Gamma> P s \\<and> (\\<Gamma>,l)\\<in> assum (p, R) \\<longrightarrow> (\\<Gamma>,l) \\<in> comm(G, (q,a)) F) =\n                (\\<forall>s. cpn n \\<Gamma> P s \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F)\"\n  using cpn_rule1 cpn_rule2\n  by metis\n\nlemma split_list_i:\"i<length l \\<Longrightarrow>\n                    \\<exists>l1 l2. l = l1@(l!i#l2)\"\nproof(induct l arbitrary: i)\n  case Nil\n  then show ?case by auto\nnext\n  case (Cons a l)\n  then show ?case\n    using id_take_nth_drop by blast\nqed\n\nlemma sub_assum1:\n  assumes a0: \"(\\<Gamma>,l0@l1) \\<in> assum (p,R)\" and a1:\"l0\\<noteq>[]\"\n  shows \"(\\<Gamma>,l0) \\<in> assum (p,R)\"\n  by (metis a0 a1 append_self_conv2 id_take_nth_drop length_greater_0_conv sub_assum take_0)   \n \n\n\n(* text{* \n@{text rel_safe} specifies that the relation leaves unmodifed any fragment out of the \nstate\n*}\ndefinition rel_safe:: \"(('l::sep_algebra,'g::sep_algebra) transition \\<Rightarrow> bool) \\<Rightarrow> bool\"\nwhere\n\"rel_safe R \\<equiv> \\<forall>h h1 h2 t. R (h1,t) \\<and> ((h1 \\<uplus>\\<^sub>p h2) h) \\<longrightarrow> R (h, t \\<uplus> h2)\"\n\ndefinition mem_safe::\n\"(('l::sep_algebra,'g::sep_algebra) state,'p,'f) body \\<Rightarrow> \n (('l,'g) state,'p,'f) com \\<Rightarrow> \n (('l,'g) transition \\<Rightarrow> bool) \\<Rightarrow> \n   bool\"\nwhere\n \"mem_safe \\<Gamma> f R \\<equiv> \\<forall>h h1 h2 t1. \n      ((\\<forall>c\\<in> cp \\<Gamma> f (Normal h1). \n        final_valid(last (snd c)) \\<and> (Normal t1 =  snd (last (snd c))) \\<and>\n        (\\<forall>i. Suc i<length (snd c) \\<longrightarrow> \n                 (fst c)\\<turnstile>\\<^sub>c((snd c)!i)  \\<rightarrow>\\<^sub>e ((snd c)!(Suc i)) \\<longrightarrow>                  \n                   (snd((snd c)!i), snd((snd c)!(Suc i))) \\<in> \n                     (case_prod (\\<lambda>x y. (Normal x, Normal y))) ` (R))) \\<and>      \n        (h1 \\<uplus>\\<^sub>p h2) h \\<longrightarrow>\n        (\\<forall>c\\<in> cp \\<Gamma> f (Normal h). \n          final_valid(last (snd c)) \\<and>\n          (\\<forall>i. Suc i<length (snd c) \\<longrightarrow> \n              (fst c)\\<turnstile>\\<^sub>c((snd c)!i)  \\<rightarrow>\\<^sub>e ((snd c)!(Suc i)) \\<longrightarrow>                  \n              (snd((snd c)!i), snd((snd c)!(Suc i))) \\<in> \n                (case_prod (\\<lambda>x y. (Normal x, Normal y))) ` (R)) \\<longrightarrow>\n              (Normal (t1 \\<uplus> h2) =  snd (last (snd c)))))     \n      \"                         \n *)\n\n     \nsubsection \\<open>Validity for Parallel Programs.\\<close>\ndefinition All_End :: \"('s,'p,'f,'e) par_config \\<Rightarrow> bool\" where\n  \"All_End xs \\<equiv> fst xs \\<noteq>[] \\<and> (\\<forall>i<length (fst xs). final ((fst xs)!i,snd xs))\"\n\ndefinition par_assum :: \n  \"('s set \\<times>  \n   (('s,'f) tran) set) \\<Rightarrow>\n   (('s,'p,'f,'e) par_confs) set\" where\n  \"par_assum \\<equiv> \n     \\<lambda>(pre, rely). {c. \n       snd((snd c)!0) \\<in> Normal ` pre \\<and> (\\<forall>i. Suc i<length (snd c) \\<longrightarrow> \n       (fst c)\\<turnstile>\\<^sub>p((snd c)!i)  \\<rightarrow>\\<^sub>e ((snd c)!(Suc i)) \\<longrightarrow>        \n         (snd((snd c)!i), snd((snd c)!(Suc i))) \\<in> rely)}\"\n           \ndefinition par_comm :: \n  \"((('s,'f) tran) set  \\<times> \n     ('s set \\<times> 's set))  \\<Rightarrow> \n    'f set \\<Rightarrow>\n   (('s,'p,'f,'e) par_confs) set\" where\n  \"par_comm \\<equiv> \n     \\<lambda>(guar, (q,a)) F. \n     {c. snd (last (snd c)) \\<notin> Fault ` F \\<longrightarrow> \n         (\\<forall>i. \n            Suc i<length (snd c) \\<longrightarrow> \n            (fst c)\\<turnstile>\\<^sub>p((snd c)!i)  \\<rightarrow> ((snd c)!(Suc i)) \\<longrightarrow>                        \n              (snd((snd c)!i), snd((snd c)!(Suc i))) \\<in> guar) \\<and> \n                (All_End (last (snd c)) \\<longrightarrow> \n                   (\\<exists>j<length (fst (last (snd c))). fst (last (snd c))!j=Throw \\<and> \n                        snd (last (snd c)) \\<in> Normal ` a) \\<or>\n                   (\\<forall>j<length (fst (last (snd c))). fst (last (snd c))!j=Skip \\<and>\n                        snd (last (snd c)) \\<in> Normal ` q))}\"\n\ndefinition par_com_validity :: \n  \"('s,'p,'f,'e) body \\<Rightarrow> \n   'f set \\<Rightarrow>\n   ('s,'p,'f,'e) par_com \\<Rightarrow>  \n   ('s set) \\<Rightarrow> \n   ((('s,'f) tran) set) \\<Rightarrow> \n   ((('s,'f) tran) set) \\<Rightarrow> \n   ('s set) \\<Rightarrow>\n   ('s set) \\<Rightarrow> \n     bool\"  \n(\"_ \\<Turnstile>\\<^bsub>'/_\\<^esub>/ _ SAT [_, _, _, _,_]\" [61,60,0,0,0,0,0,0] 45) where\n  \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> Ps SAT [pre, R, G, q,a] \\<equiv> \n   \\<forall>s. par_cp \\<Gamma> Ps s \\<inter> par_assum(pre, R)  \\<subseteq> par_comm(G, (q,a)) F\"\n   \ndefinition par_com_cvalidity :: \n  \"('s,'p,'f,'e) body \\<Rightarrow>\n    ('s,'p,'f,'e) sextuple set \\<Rightarrow>\n   'f set \\<Rightarrow>\n  ('s,'p,'f,'e) par_com \\<Rightarrow>   \n   ('s set) \\<Rightarrow> \n   ((('s,'f) tran) set) \\<Rightarrow> \n   ((('s,'f) tran) set) \\<Rightarrow> \n   ('s set) \\<Rightarrow>\n   ('s set) \\<Rightarrow> \n     bool\"  \n(\"_,_ \\<Turnstile>\\<^bsub>'/_\\<^esub>/ _ SAT [_, _, _, _,_]\" [61,60,0,0,0,0,0,0] 45) where\n  \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> Ps SAT [p,  R, G, q,a] \\<equiv> \n  (\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. (\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a])) \\<longrightarrow>\n   \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> Ps SAT [p, R, G, q,a]\"\n   \ndeclare Un_subset_iff [simp del] sup.bounded_iff [simp del]\n\ninductive\nlrghoare :: \"[('s,'p,'f,'e) body,\n             ('s,'p,'f,'e) sextuple set,\n              'f set,\n              ('s,'p,'f,'e) com,  \n              ('s set),  \n              (('s,'f) tran) set, (('s,'f) tran) set,\n              's set,\n               's set] \\<Rightarrow> bool\"\n    (\"_,_ \\<turnstile>\\<^bsub>'/_\\<^esub> _ sat [_, _, _, _,_]\" [61,61,60,60,0,0,0,0] 45)\nwhere\n Skip: \"\\<lbrakk> Sta q R; (\\<forall>s. (Normal s, Normal s) \\<in> G) \\<rbrakk> \\<Longrightarrow>\n         \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> Skip sat [q, R, G, q,a] \"\n\n|Spec: \"\\<lbrakk>Sta p R;Sta q R;\n        (\\<forall>s t. s\\<in>p \\<and> (s,t)\\<in>r \\<longrightarrow> (Normal s,Normal t) \\<in> G);\n         p \\<subseteq> {s. (\\<forall>t. (s,t)\\<in>r \\<longrightarrow> t \\<in> q) \\<and> (\\<exists>t. (s,t) \\<in> r)} \\<rbrakk> \\<Longrightarrow> \n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (Spec r e) sat [p, R, G, q,a]\"\n\n| Basic: \"\\<lbrakk> Sta p R;Sta q R;\n           (\\<forall>s t. s\\<in>p \\<and> (t=f s) \\<longrightarrow> (Normal s,Normal t) \\<in> G);\n            p \\<subseteq> {s. f s \\<in> q} \\<rbrakk> \\<Longrightarrow>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (Basic f e) sat [p, R, G, q,a]\"\n\n| If: \"\\<lbrakk>Sta p R;  (\\<forall>s. (Normal s, Normal s) \\<in> G); \n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b, R, G, q,a]; \n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c2 sat [p \\<inter> (-b), R, G, q,a]\\<rbrakk> \\<Longrightarrow>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (Cond b c1 c2) sat [p,  R, G, q,a]\"\n\n| While: \"\\<lbrakk> Sta p R; Sta (p \\<inter> (-b)) R; Sta a R; (\\<forall>s. (Normal s,Normal s) \\<in> G);\n            \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c sat [p \\<inter> b, R, G, p,a]\\<rbrakk> \\<Longrightarrow>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (While b c) sat [p, R, G, p \\<inter> (-b),a]\"\n\n| Seq: \"\\<lbrakk>Sta a R; Sta p R; (\\<forall>s. (Normal s,Normal s) \\<in> G); \n         \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p, R, G, q,a]; \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c2 sat [q, R, G, r,a]\\<rbrakk> \\<Longrightarrow>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (Seq c1 c2) sat [p, R, G, r,a]\"\n\n| Await: \"\\<lbrakk> Sta p R; Sta q R; Sta a R;\n            \\<forall>V. \\<Gamma>\\<^sub>\\<not>\\<^sub>a,{}\\<turnstile>\\<^bsub>/F\\<^esub> \n                  (p \\<inter> b \\<inter> {V}) c \n                  ({s. (Normal V, Normal s) \\<in> G} \\<inter> q),\n                  ({s. (Normal V, Normal s) \\<in> G} \\<inter> a)\\<rbrakk> \\<Longrightarrow>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (Await b c e) sat [p, R, G, q,a]\"\n\n| Guard: \"\\<lbrakk>Sta (p \\<inter> g) R; (\\<forall>s. (Normal s, Normal s) \\<in> G); \n           \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c sat [p \\<inter> g, R, G, q,a]\\<rbrakk> \\<Longrightarrow>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (Guard f g c) sat [p \\<inter> g, R, G, q,a]\"\n\n| Guarantee:  \"\\<lbrakk> Sta p R; (\\<forall>s. (Normal s, Normal s) \\<in> G); f\\<in>F;\n                 \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c sat [p \\<inter> g, R, G, q,a] \\<rbrakk> \\<Longrightarrow>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (Guard f g c) sat [p, R, G, q,a]\"\n\n| CallRec: \"\\<lbrakk>(c,p,R,G,q,a) \\<in> Specs; \n             \\<forall>(c,p,R,G,q,a)\\<in> Specs. c \\<in> dom \\<Gamma> \\<and> \n              Sta p R \\<and> (\\<forall>s. (Normal s,Normal s) \\<in> G)\\<and>  \n             \\<Gamma>,\\<Theta> \\<union> Specs \\<turnstile>\\<^bsub>/F\\<^esub> (the (\\<Gamma> c)) sat [p,  R, G, q,a];\n            Sta p R; (\\<forall>s. (Normal s, Normal s) \\<in> G)\\<rbrakk> \\<Longrightarrow>\n            \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\" \n\n| Asm: \"\\<lbrakk>(c,p,R,G,q,a) \\<in> \\<Theta>\\<rbrakk> \\<Longrightarrow>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\" \n\n| Call: \"\\<lbrakk>\n         Sta p R; (\\<forall>s. (Normal s, Normal s) \\<in> G);c \\<in> dom \\<Gamma>; \n         \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (the (\\<Gamma> c)) sat [p, R, G, q,a]\\<rbrakk>  \\<Longrightarrow>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\" \n\n| DynCom: \"\\<lbrakk>(Sta p R) \\<and> (Sta q R) \\<and> (Sta a R) \\<and>\n            (\\<forall>s. (Normal s,Normal s) \\<in> G);\n            (\\<forall>s \\<in> p. (\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (c s) sat [p, R, G, q,a]))\\<rbrakk> \\<Longrightarrow>\n            \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (DynCom c) sat [p, R, G, q,a]\"\n\n| Throw: \"\\<lbrakk>Sta a R; (\\<forall>s. (Normal s, Normal s) \\<in> G) \\<rbrakk> \\<Longrightarrow>\n         \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> Throw sat [a,  R, G, q,a] \"\n\n| Catch: \"\\<lbrakk>Sta q R; (\\<forall>s. (Normal s, Normal s) \\<in> G); \n           \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p, R, G, q,r]; \n           \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c2 sat [r, R, G, q,a]\\<rbrakk> \\<Longrightarrow>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> (Catch c1 c2) sat [p, R, G, q,a]\"\n\n| Conseq: \"\\<forall>s \\<in> p. \n             (\\<exists>p' R' G' q' a' \\<Theta>'.  \n             (s\\<in> p') \\<and>\n              R \\<subseteq> R' \\<and>            \n             G' \\<subseteq> G \\<and>             \n             q' \\<subseteq> q \\<and>\n             a' \\<subseteq> a \\<and> \\<Theta>' \\<subseteq> \\<Theta> \\<and>                       \n            (\\<Gamma>,\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p', R', G', q',a']) ) \n            \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q,a]\"\n\n| Conj_post: \" \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q,a] \\<Longrightarrow>\n                \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q',a'] \n            \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q \\<inter> q',a \\<inter> a']\"\n  \n| Conj_Inter: \"sa\\<noteq>({}::nat set) \\<Longrightarrow> \n               \\<forall>i\\<in>sa. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q i,a] \\<Longrightarrow>                \n               \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G,\\<Inter>i\\<in>sa. q i,a]\" \n\n  \ninductive_cases hoare_elim_cases [cases set]:\n \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> Skip sat [p, R, G, q,a]\"\n\nthm hoare_elim_cases\n(*\nlemma \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> Skip sat [p, R, G, q,a] \\<Longrightarrow> \n        \\<forall>s \\<in> p. \n          (\\<exists>p' R' G' q' a'.  \n           (s\\<in> p') \\<and>\n            R \\<subseteq> R' \\<and>            \n            G' \\<subseteq> G \\<and>             \n            q' \\<subseteq> q \\<and>\n            a' \\<subseteq> a \\<and>                        \n           (\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p', R', G', q',a']) \\<and> p'=q' \\<and> Sta q' R' \\<and> Norm R' \\<and> (\\<forall>s. (Normal s, Normal s) \\<in> G'))\"\nproof -\n  assume a0:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> Skip sat [p, R, G, q,a]\"  \n  {\n   fix s\n   assume a01:\"s\\<in>p\"\n   have \"(\\<exists>p' R' G' q' a'.  \n           (s\\<in> p') \\<and>\n            R \\<subseteq> R' \\<and>            \n            G' \\<subseteq> G \\<and>             \n            q' \\<subseteq> q \\<and>\n            a' \\<subseteq> a \\<and>                        \n           (\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p', R', G', q',a']) \\<and> p'=q' \\<and> Sta q' R' \\<and> Norm R' \\<and> (\\<forall>s. (Normal s, Normal s) \\<in> G'))\"\n   proof (cases \"p=q\")\n    case True thus ?thesis using hoare_elim_cases   sorry\n   next\n    case False thus ?thesis sorry\n   qed\n  } thus ?thesis by fastforce\nqed*)\n\n(* lemma \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c sat [p, R, G, q,r] \\<Longrightarrow>\n       c\\<noteq>Throw \\<Longrightarrow>\n       Sta p R\"\nsorry *)\n(*\n| Env:  \"\\<lbrakk>noawaits c; \\<Gamma>\\<^sub>\\<not>\\<^sub>a,{}\\<turnstile>\\<^bsub>/F\\<^esub> (p ) (sequential c) q,(a)\\<rbrakk> \\<Longrightarrow>\n         \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> c sat [p, sep_empty, Emp, Emp, q,a]\"\n        \n| Hide: \"\\<lbrakk>\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c sat [p, (I \\<and>* I'), (R \\<and>* R'), (G \\<and>* G'), q,a]; \n         (I  \\<triangleright> R); \n         (I  \\<triangleright> G)\n          \\<rbrakk> \\<Longrightarrow> \n         \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> c sat [p, I, R, G, q,a]\" \n\n|Frame: \"\\<lbrakk>\n        \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c sat [p, I, R, G , q,a]; \n        I'  \\<triangleright> R'; I'  \\<triangleright> G';\n        Sta r (R'\\<and>*tran_Id);\n        (\\<forall>s t. (r imp (I'\\<and>*sep_true))(s,t));\n        (rel_safe R); (rel_safe (G\\<and>*tran_True)) \\<rbrakk>  \\<Longrightarrow>\n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> c sat [p\\<and>*r, I \\<and>* I', R \\<and>* R', G \\<and>* G', q\\<and>*r,a\\<and>*r]\"\n*)\n\n\ndefinition Pre :: \" ('s,'p,'f,'e)rgformula \\<Rightarrow> ('s set)\" where\n  \"Pre x \\<equiv> fst(snd x)\"\n\ndefinition Post :: \"('s,'p,'f,'e) rgformula \\<Rightarrow> ('s set)\" where\n  \"Post x \\<equiv>  fst(snd(snd(snd(snd x))))\"\n\ndefinition Abr ::  \"('s,'p,'f,'e) rgformula \\<Rightarrow> ('s set)\" where\n  \"Abr x \\<equiv> snd(snd(snd(snd(snd x))))\"\n\ndefinition Rely :: \"('s,'p,'f,'e) rgformula \\<Rightarrow> (('s,'f) tran) set\" where\n  \"Rely x \\<equiv> fst(snd(snd x))\"\n\ndefinition Guar ::  \"('s,'p,'f,'e) rgformula \\<Rightarrow> (('s,'f) tran) set\" where\n  \"Guar x \\<equiv> fst(snd(snd(snd x)))\"\n\ndefinition Com :: \"('s,'p,'f,'e) rgformula \\<Rightarrow> ('s ,'p,'f,'e) com\" where\n  \"Com x \\<equiv> fst  x\"\n\n\ninductive\n  par_rghoare ::  \"[('s,'p,'f,'e) body,\n              ('s,'p,'f,'e) sextuple set,\n              'f set,\n              ( ('s,'p,'f,'e) rgformula) list,  \n              's set,              \n              (('s,'f) tran) set, (('s,'f) tran) set,\n              's set,\n               's set] \\<Rightarrow> bool\"\n    (\"_,_ \\<turnstile>\\<^bsub>'/_\\<^esub> _ SAT [_, _, _, _,_]\" [61,60,60,0,0,0,0] 45)\nwhere\n  Parallel:\n  \"\\<lbrakk> \\<forall>i<length xs. R \\<union> (\\<Union>j\\<in>{j. j<length xs \\<and> j\\<noteq>i}. (Guar(xs!j))) \\<subseteq> (Rely(xs!i));\n    (\\<Union>j<length xs. (Guar(xs!j))) \\<subseteq> G;\n     p \\<subseteq> (\\<Inter>i<length xs. (Pre(xs!i)));\n    (\\<Inter>i<length xs. (Post(xs!i))) \\<subseteq> q;\n    (\\<Union>i<length xs. (Abr(xs!i))) \\<subseteq> a;                 \n    \\<forall>i<length xs. \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> Com(xs!i) sat [Pre(xs!i),Rely(xs!i),Guar(xs!i),Post(xs!i),Abr(xs!i)] \\<rbrakk>\n   \\<Longrightarrow>  \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> xs SAT [p, R, G, q,a]\" \n \nsection {* Soundness *}\n\nlemma skip_suc_i:\n  assumes a1:\"(\\<Gamma>, l) \\<in> cptn \\<and> fst (l!i) = Skip\"   \n  assumes a2:\"i+1 < length l\"\n  shows \"fst (l!(i+1)) = Skip\"\nproof -\n  from a2 a1 obtain l1 ls where \"l=l1#ls\" \n    by (metis list.exhaust list.size(3) not_less0) \n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c (l!i) \\<rightarrow>\\<^sub>c\\<^sub>e (l!(Suc i))\" using cptn_stepc_rtran a1 a2\n    by fastforce \n  thus ?thesis using a1 a2 step_ce_elim_cases\n    by (metis (no_types) Suc_eq_plus1 not_eq_not_env prod.collapse stepc_elim_cases(1))\nqed \n\nlemma throw_suc_i:\n  assumes a1:\"(\\<Gamma>, l) \\<in> cptn \\<and> (fst(l!i) = Throw \\<and> snd(l!i) = Normal s1)\"   \n  assumes a2:\"Suc i < length l\"\n  assumes a3:\"env_tran_right \\<Gamma> l rely \\<and> Sta q rely \\<and> s1 \\<in> q\"\n  shows \"fst (l!(Suc i)) =  Throw \\<and> (\\<exists>s2. snd(l!(Suc i)) = Normal s2 \\<and> s2 \\<in>q)\"\nproof -\n  have fin:\"final (l!i)\" using a1 unfolding final_def by auto \n  from a2 a1 obtain l1 ls where \"l=l1#ls\" \n    by (metis list.exhaust list.size(3) not_less0) \n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c (l!i) \\<rightarrow>\\<^sub>c\\<^sub>e (l!(Suc i))\" using cptn_stepc_rtran a1 a2\n    by fastforce then have \"\\<Gamma>\\<turnstile>\\<^sub>c (l!i) \\<rightarrow> (l!(Suc i)) \\<or> \\<Gamma>\\<turnstile>\\<^sub>c (l!i) \\<rightarrow>\\<^sub>e (l!(Suc i))\"\n    using step_ce_elim_cases by blast\n  thus ?thesis proof                                          \n    assume \"\\<Gamma>\\<turnstile>\\<^sub>c (l!i) \\<rightarrow> (l!(Suc i))\" thus ?thesis using fin no_step_final' by blast\n  next\n    assume \"\\<Gamma>\\<turnstile>\\<^sub>c (l!i) \\<rightarrow>\\<^sub>e (l!(Suc i))\" thus ?thesis \n      using a1 a3 a2 env_tran_normal by (metis (no_types, lifting)  env_c_c' prod.collapse) \n  qed \nqed \n\nlemma i_skip_all_skip:assumes a1:\"(\\<Gamma>, l) \\<in> cptn \\<and> fst (l!i) = Skip\"\n      assumes a2: \"i\\<le>j \\<and> j < (length l)\"\n      assumes a3:\"n=j-i\"\n      (* assumes a4:\"env_tran_right \\<Gamma> l rely\" *)\n      shows \"fst (l!j) = Skip\"\nusing a1 a2 a3\nproof (induct n arbitrary: i j)\n  case 0\n  then have \"Suc i = Suc j\" by simp  \n  thus ?case using \"0.prems\" skip_suc_i by fastforce\nnext\n  case (Suc n)    \n  then have \"length l > Suc i\" by auto \n  then have \"i<j\" using Suc by fastforce\n  moreover then have \"j-1< length l\" using Suc by fastforce\n  moreover then have \"j  - i = Suc n\" using Suc by fastforce\n  ultimately have \"fst (l ! (j)) = LanguageCon.com.Skip\" using Suc  skip_suc_i\n    by (metis (no_types, lifting) Suc_diff_Suc Suc_eq_plus1 Suc_leI `Suc i < length l` diff_Suc_1)        \n  also have \"j=j\" using Cons using Suc.prems(2) by linarith  \n  ultimately show ?case using Suc by (metis (no_types))\nqed\n\nlemma i_throw_all_throw:assumes a1:\"(\\<Gamma>, l) \\<in> cptn \\<and> (fst (l!i) = Throw \\<and> snd (l!i) = Normal s1)\"\n      assumes a2: \"i\\<le>j \\<and> j < (length l)\"\n      assumes a3:\"n=j-i\"\n      assumes a4:\"env_tran_right \\<Gamma> l rely \\<and> Sta q rely \\<and> s1\\<in>q\" \n      shows \"fst (l!j) = Throw \\<and> (\\<exists>s2. snd(l!j) = Normal s2  \\<and> s2\\<in>q)\"\nusing a1 a2 a3 a4\nproof (induct n arbitrary: i j s1)\n  case 0\n  then have \"Suc i = Suc j\" by simp  \n  thus ?case using \"0.prems\" skip_suc_i by fastforce\nnext\n  case (Suc n)    \n  then have l_suc:\"length l > Suc i\" by linarith \n  then have \"i<j\" using Suc.prems(3) by linarith \n  moreover then have \"j-1< length l\" by (simp add: Suc.prems(2) less_imp_diff_less) \n  moreover then have \"j - Suc i = n\" by (metis Suc_diff_Suc Suc_inject \\<open>i < j\\<close> Suc(4))\n  ultimately obtain s2 where \"fst (l ! (j-1)) = LanguageCon.com.Throw \\<and> snd (l ! (j-1)) = Normal s2 \\<and> s2\\<in>q\"\n    using Suc(1)[of i s1 \"j-1\"] Suc(2) Suc(5)\n    by (metis (no_types, lifting) Suc_diff_Suc diff_Suc_eq_diff_pred diff_zero less_imp_Suc_add not_le not_less_eq_eq zero_less_Suc) \n  also have \"Suc (j - 1) < length l\" using Suc by arith\n  ultimately have \"fst (l ! (j)) = LanguageCon.com.Throw \\<and> (\\<exists>s2. snd(l!j) = Normal s2 \\<and> s2\\<in>q)\" \n    using Suc(2-5) throw_suc_i[of \\<Gamma> l \"j-1\" s2 rely q] a4\n    by fastforce\n  also have \"j=j\" using Cons using Suc.prems(2) by linarith  \n  ultimately show ?case using Suc by (metis (no_types))\nqed    \n\nlemma only_one_component_tran_j:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!i) = Skip  \\<or> fst (l!i) = Throw \" and \n         a1': \"snd (l!i) = Normal x \\<and> x \\<in> q\" and\n         a2: \"i\\<le>j \\<and> Suc j < length l\" and\n         a3: \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\" and \n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta q rely\"    \n   shows \"P\"\nproof -   \n   have \"fst (l!j) = Skip  \\<or> (fst (l!i) = Throw \\<and> snd(l!i) = Normal x)\" \n   using a0 a1 a1' a2 a3 a4 i_skip_all_skip by fastforce           \n   also have \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\" using a3 by fastforce \n   ultimately show ?thesis\nby (meson SmallStepCon.final_def SmallStepCon.no_step_final' Suc_lessD a0 a2  a4 i_throw_all_throw a1')  \nqed     \n\nlemma only_one_component_tran_all_j:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!i) = Skip  \\<or> (fst (l!i) = Throw \\<and> snd(l!i) = Normal s1)\" and \n         a1': \"snd (l!i) = Normal x \\<and> x \\<in> q\" and\n         a2: \"Suc i<length l\" and\n         a3: \"\\<forall>j. i\\<le>j \\<and> Suc j < length l \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"  and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta q rely\"              \n   shows \"P\" \nusing a0 a1 a2 a3 a4 a1' only_one_component_tran_j \nby (metis lessI less_Suc_eq_le) \n\n\nlemma zero_skip_all_skip: \n      assumes a1:\"(\\<Gamma>, l) \\<in> cptn \\<and> fst (l!0) = Skip \\<and>  i < length l\"\n      shows \"fst (l!i) = Skip\"\nusing a1 i_skip_all_skip by blast\n\nlemma all_skip:\n   assumes\n      a0:\"(\\<Gamma>,x)\\<in>cptn\" and\n      a1:\"x!0 = (Skip,s)\"\nshows \"(\\<forall>i<length x. fst(x!i) = Skip)\"\nusing a0 a1 zero_skip_all_skip by fastforce\n\nlemma zero_throw_all_throw:\n      assumes a1:\"(\\<Gamma>, l) \\<in> cptn \\<and> fst (l!0) = Throw \\<and> \n                  snd(l!0) = Normal s1 \\<and>  i < length l \\<and> s1\\<in>q\"\n      assumes a2: \"env_tran_right \\<Gamma> l rely \\<and> Sta q rely\" \n      shows \"fst (l!i) = Throw \\<and> (\\<exists>s2. snd (l!i) = Normal s2)\"\nusing a1 a2 i_throw_all_throw by (metis le0) \n\nlemma only_one_component_tran_0:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"(fst (l!0) = Skip) \\<or> (fst (l!0) = Throw)\" and                  \n         a1': \"snd (l!0) = Normal x \\<and> x \\<in> q\" and\n         a2: \"Suc j < length l\" and\n         a3: \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"  and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta q rely\"         \n   shows \"P\"      \n  proof-\n   have a2':\"0\\<le>j \\<and> Suc j<length l\" using a2 by arith\n   show ?thesis \n   using only_one_component_tran_j[OF a0 a1 a1' a2' a3 a4] by auto\nqed\n\nlemma not_step_comp_step_env:\n assumes a0:  \"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"(Suc j<length l)\" and \n         a2: \"(\\<forall>k < j. \\<not>((\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))))\"\n  shows \"(\\<forall>k < j. ((\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))))\"\nproof -\n  {fix k\n   assume asm: \"k<j\"\n   also then have \"Suc k<length l\" using a1 a2 by auto\n   ultimately have \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>c\\<^sub>e (l!(Suc k)))\" using a0 cptn_stepc_rtran\n  proof -\n    obtain nn :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat\" where\n      f1: \"\\<forall>x0 x1. (\\<exists>v2>x1. x0 = Suc v2) = (x1 < nn x0 x1 \\<and> x0 = Suc (nn x0 x1))\"\n      by moura\n    obtain pp :: \"nat \\<Rightarrow> (('b, 'a, 'c,'d) LanguageCon.com \\<times> ('b, 'c) xstate) list \\<Rightarrow> \n                 ('b, 'a, 'c,'d) LanguageCon.com \\<times> ('b, 'c) xstate\" and \n           pps :: \"nat \\<Rightarrow> (('b, 'a, 'c,'d) LanguageCon.com \\<times> ('b, 'c) xstate) list \\<Rightarrow> \n                  (('b, 'a, 'c,'d) LanguageCon.com \\<times> ('b, 'c) xstate) list\" where\n      \"\\<forall>x0 x1. (\\<exists>v2 v3. x1 = v2 # v3 \\<and> length v3 = x0) = (x1 = pp x0 x1 # pps x0 x1 \\<and> length (pps x0 x1) = x0)\"\n      by moura\n    then have f2: \"l = pp (nn (length l) k) l # pps (nn (length l) k) l \\<and> length (pps (nn (length l) k) l) = nn (length l) k\"\n      using f1 by (meson Suc_lessE \\<open>Suc k < length l\\<close> length_Suc_conv)\n    then have f3: \"Suc k < length (pp (nn (length l) k) l # pps (nn (length l) k) l)\"\n      by (metis \\<open>Suc k < length l\\<close>)\n    have \"(\\<Gamma>, pp (nn (length l) k) l # pps (nn (length l) k) l) \\<in> cptn\"\n      using f2 a0 by presburger\n    then have \"\\<Gamma>\\<turnstile>\\<^sub>c (pp (nn (length l) k) l # pps (nn (length l) k) l) ! k \\<rightarrow>\\<^sub>c\\<^sub>e (pp (nn (length l) k) l # pps (nn (length l) k) l) ! Suc k\"\n      using f3 by (meson cptn_stepc_rtran)\n    then show ?thesis\n      using f2 by auto\n  qed \n   also have \"\\<not>((\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))))\" using a2 asm by auto\n   ultimately have \"((\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\" using step_ce_elim_cases by blast\n  } thus ?thesis by auto\nqed\n\nlemma cptn_i_env_same_prog:\nassumes a0: \"(\\<Gamma>, l) \\<in> cptn\" and\n        a1:  \"\\<forall>k < j. k\\<ge>i \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))\" and\n        a2: \"i\\<le>j \\<and> j < length l\"\nshows \"fst (l!j) =  fst (l!i)\"\nusing a0 a1 a2\nproof (induct \"j-i\" arbitrary: l j i)\n  case 0 thus ?case by auto    \nnext\n  case (Suc n)     \n    then have lenl:\"length l>Suc 0\" by fastforce    \n    have \"j>0\" using Suc by linarith\n    then obtain j1 where prev:\"j=Suc j1\" \n      using not0_implies_Suc by blast     \n    then obtain a0 a1 l1 where l:\"l=a0#l1@[a1]\" \n    using Suc lenl by (metis add.commute add.left_neutral length_Cons list.exhaust list.size(3) not_add_less1 rev_exhaust)     \n    then have al1_cptn:\"(\\<Gamma>,a0#l1)\\<in> cptn\"\n      using Suc.prems(1) Suc.prems(3) tl_in_cptn cptn_dest_2\n      by blast\n    have i_j:\"i\\<le>j1\" using Suc prev by auto\n    have \"\\<forall>k < j1. k\\<ge>i \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c((a0#l1)!k)  \\<rightarrow>\\<^sub>e ((a0#l1)!(Suc k)))\"\n    proof -\n       {fix k\n        assume a0:\"k<j1 \\<and> k\\<ge>i\"\n        then have \"(\\<Gamma>\\<turnstile>\\<^sub>c((a0#l1)!k)  \\<rightarrow>\\<^sub>e ((a0#l1)!(Suc k)))\" \n        using  l Suc(4) prev lenl Suc(5)\n        proof -   \n          have suc_k_j:\"Suc k < j\" using a0 prev by blast\n          have j1_l_l1:\"j1 < Suc (length l1)\" \n            using Suc.prems(3) l prev by auto\n          have \"k < Suc j1\"\n            using `k < j1 \\<and> i \\<le> k` less_Suc_eq by blast\n          hence f3: \"k < j\"\n            using prev by blast\n          hence ksuc:\"k < Suc (Suc j1)\"\n            using less_Suc_eq prev by blast\n          hence f4: \"k < Suc (length l1)\"\n            using  prev Suc.prems(3) l a0 j1_l_l1 less_trans \n            by blast            \n          have f6: \"\\<Gamma>\\<turnstile>\\<^sub>c l ! k \\<rightarrow>\\<^sub>e (l ! Suc k)\"\n            using f3 Suc(4) a0 by blast\n          have k_l1:\"k < length l1\"\n            using f3 Suc.prems(3) i_j l suc_k_j  by auto                            \n          thus ?thesis\n          proof (cases k)\n            case 0 thus ?thesis using f6 l  k_l1\n                by (simp add: nth_append)\n          next  \n            case (Suc k1) thus ?thesis \n              using f6  f4 l k_l1 \n              by (simp add: nth_append)\n          qed\n        qed\n       }thus ?thesis by auto\n    qed\n    then have fst:\"fst ((a0#l1)!i)=fst ((a0#l1)!j1)\"\n      using Suc(1)[of j1 i \"a0#l1\"] \n            Suc(2) Suc(3) Suc(4) Suc(5) prev al1_cptn i_j\n      by (metis (mono_tags, lifting) Suc_diff_le Suc_less_eq diff_Suc_1 l length_Cons length_append_singleton)\n    have len_l:\"length l = Suc (length (a0#l1))\" using l by auto\n    then have f1:\"i<length (a0#l1)\" using Suc.prems(3) i_j prev by linarith\n    then have f2:\"j1<length (a0#l1)\" using Suc.prems(3) len_l prev by auto\n    have i_l:\"fst (l!i) = fst ((a0#l1)!i)\" \n      using l prev f1 f2 fst \n      by (metis (no_types) append_Cons nth_append)\n    also have j1_l:\"fst (l!j1) = fst ((a0#l1)!j1)\"\n    using l prev f1 f2 fst \n      by (metis (no_types) append_Cons nth_append)\n    then have \"fst (l!i) = fst (l!j1)\" using\n      i_l j1_l fst by auto      \n    thus ?case using Suc prev by (metis env_c_c' i_j lessI prod.collapse)          \nqed  \n  \n\nlemma cptn_tran_ce_i: \n   assumes a1:\"(\\<Gamma>, l) \\<in> cptn  \\<and>  i + 1 < length l\"\n   shows \"\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>c\\<^sub>e (l!(Suc i))\"\nproof -\n  from a1\n  obtain a1 l1 where \"l=a1#l1\" using cptn.simps by blast\n  thus  ?thesis using a1 cptn_stepc_rtran by fastforce\nqed\n\nlemma zero_final_always_env_0: \n      assumes a1:\"(\\<Gamma>, l) \\<in> cptn\" and\n              a2: \"fst (l!0) = Skip \\<or> fst (l!0) = Throw\" and\n              a2': \"snd(l!0) = Normal s1 \\<and> s1\\<in>q\" and\n              a3: \"Suc i < length l\" and\n              a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta q rely\"\n      shows \"\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i))\"\nproof -\n   have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>c\\<^sub>e (l!(Suc i))\" using a1 a2 a3 cptn_tran_ce_i by auto   \n   also have \"\\<not> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" using a1 a2 a3 a4 a2'\n     using only_one_component_tran_0 by metis           \n   ultimately show ?thesis by (simp add: step_ce.simps) \nqed\n\nlemma final_always_env_i: \n      assumes a1:\"(\\<Gamma>, l) \\<in> cptn\" and\n              a2: \"fst (l!0) = Skip \\<or> fst (l!0) = Throw\" and\n              a2': \"snd(l!0) = Normal s1 \\<and> s1\\<in>q\" and\n              a3: \"j\\<ge>i \\<and> Suc j<length l\" and\n              a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta q rely\"\n      shows \"\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j))\"\nproof -\n   have ce_tran:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>c\\<^sub>e (l!(Suc j))\" using a1 a2 a3 a4 cptn_tran_ce_i by auto   \n   then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)) \\<or> \\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))\" \n     using step_ce_elim_cases by blast\n   thus ?thesis\n   proof\n     assume \"\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j))\" then show ?thesis by auto\n   next\n     assume a01:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))\"\n      then  have \"\\<not> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"   \n        using a1 a2 a3 a4 a2' only_one_component_tran_j [OF a1]  \n        by blast\n      then show ?thesis using a01 ce_tran by (simp add: step_ce.simps) \n   qed\nqed\n\n\nsubsection {*Skip Sound*}\n\nlemma stable_q_r_q: \n  assumes a0:\"Sta q R\"  and       \n          a1: \"snd(l!i) \\<in> Normal ` q\" and\n          a2:\"(snd(l!i), snd(l!(Suc i))) \\<in> R\"\n  shows \"snd(l!(Suc i)) \\<in> Normal ` q\"\nusing a0  a1  a2 \nunfolding Sta_def  by fastforce \n\nlemma stability:\nassumes   a0:\"Sta q R\"  and                 \n          a1: \"snd(l!j) \\<in> Normal ` q\" and\n          a2: \"j\\<le>k \\<and> k < (length l)\" and\n          a3: \"n=k-j\" and\n          a4: \"\\<forall>i. j\\<le>i \\<and> i < k \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i))\" and\n          a5:\"env_tran_right \\<Gamma> l R \"\n      shows \"snd (l!k) \\<in> Normal ` q \\<and> fst (l!j) = fst (l!k)\"\nusing a0 a1 a2 a3 a4 a5 \nproof (induct n arbitrary: j k)\n  case 0\n    thus ?case by auto\nnext\n  case (Suc n) \n    then have \"length l > j + 1\" by arith     \n    moreover then have \"k-1< length l\" using Suc by fastforce    \n    moreover then have \"(k - 1) - j = n\" using Suc by fastforce\n    moreover then have  \"j\\<le>k-1\" using Suc by arith \n    moreover have \"\\<forall>i. j \\<le> i \\<and> i < k-1 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c (l ! i) \\<rightarrow>\\<^sub>e (l ! Suc i)\"\n      using Suc by fastforce    \n    ultimately have induct:\"snd (l! (k-1)) \\<in> Normal ` q \\<and> fst (l!j) = fst (l!(k-1))\" using Suc\n      by blast      \n    also have j_1:\"k-1+1=k\" using Cons Suc.prems(4) by auto \n    have f1:\"\\<forall>i. j\\<le>i \\<and> i < k \\<longrightarrow> (snd((snd (\\<Gamma>,l))!i), snd((snd (\\<Gamma>,l))!(Suc i))) \\<in>  R\"\n    using Suc unfolding env_tran_right_def by fastforce\n    have  k1:\"k - 1 < k\"\n      by (metis (no_types) Suc_eq_plus1 j_1 lessI)    \n    then have \"(snd((snd (\\<Gamma>,l))!(k-1)), snd((snd (\\<Gamma>,l))!(Suc (k-1)))) \\<in>  R\"    \n    using `j \\<le> k - 1` f1 by blast                           \n    ultimately have \"snd (l!k) \\<in> Normal ` q\" using stable_q_r_q Suc(2)  Suc(5)  by fastforce\n    also have \"fst (l!j) = fst (l!k)\"\n    proof -\n      have \"\\<Gamma>\\<turnstile>\\<^sub>c (l ! (k-1)) \\<rightarrow>\\<^sub>e (l ! k)\" using Suc(6) k1 `j\\<le>k-1` by fastforce\n      thus ?thesis using k1 prod.collapse env_c_c' induct by metis\n    qed\n    ultimately show ?case by meson\nqed\n\nlemma stable_only_env_i_j: \n  assumes a0:\"Sta q R\"  and                 \n          a1: \"snd(l!i) \\<in> Normal ` q\" and\n          a2: \"i<j \\<and> j < (length l)\" and\n          a3: \"n=j-i-1\" and\n          a4: \"\\<forall>k\\<ge>i. k < j \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))\" and\n          a5: \"env_tran_right \\<Gamma> l R\"\n      shows \"snd (l!j) \\<in> Normal ` q\"\nusing a0 a1 a2 a3 a4 a5  by (meson less_imp_le_nat  stability)\n\n  \nlemma stable_only_env_1: \n  assumes a0:\"Sta q R\"  and                 \n          a1: \"snd(l!i) \\<in> Normal ` q\" and\n          a2: \"i<j \\<and> j < (length l)\" and\n          a3: \"n=j-i-1\" and\n          a4: \"\\<forall>i. Suc i < length l \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i))\" and\n          a5: \"env_tran_right \\<Gamma> l R\"\n      shows \"snd (l!j) \\<in> Normal ` q\"\nusing a0 a1 a2 a3 a4 a5 \nby (meson stable_only_env_i_j less_trans_Suc)\n\n\nlemma stable_only_env_q: \n  assumes a0:\"Sta q R\"  and                 \n          a1: \"\\<forall>i. Suc i < length l \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i))\" and\n          a2: \"env_tran \\<Gamma> q l R\"\n      shows \"\\<forall>i. i < length l \\<longrightarrow> snd (l!i) \\<in> Normal ` q\"\nproof (cases \"0 < length l\")\n  case False thus ?thesis using a2 unfolding env_tran_def by fastforce \nnext\n  case True \n  thus ?thesis \n  proof - {\n    fix i\n    assume aa1:\"i < length l\"\n    have post_0:\"snd (l ! 0) \\<in> Normal ` q \" \n      using a2 unfolding env_tran_def by auto\n    then have \"snd (l ! i) \\<in> Normal ` q\"     \n    proof (cases i) \n      case 0 thus ?thesis using post_0 by auto\n    next\n      case (Suc n) \n      \n      have \"env_tran_right \\<Gamma> l R\" \n        using a2 env_tran_right_def unfolding env_tran_def by auto\n      also have \"0<i\" using Suc by auto\n      ultimately show ?thesis \n        using post_0 stable_only_env_1  a0 a1 a2 aa1  by blast\n    qed\n  } then show ?thesis by auto qed\nqed\n\n\n\nlemma Skip_sound1: \n  assumes a0:\"Sta q R\" and\n   a1:\"(\\<forall>s. (Normal s, Normal s) \\<in> G)\" and\n   a10:\"c \\<in> cp \\<Gamma> Skip s\" and\n   a11:\"c \\<in> assum(q, R)\" \n   shows \"c \\<in> comm (G, (q,a)) F\"\nproof -  \n  obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce  \n  { \n    assume \"snd (last l) \\<notin> Fault ` F\"\n    have cp:\"l!0=(Skip,s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\" using a10 cp_def c_prod by fastforce   \n    have assum:\"snd(l!0) \\<in> Normal ` q \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow>\n             (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n               (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n      using a11 c_prod unfolding assum_def by simp\n    have concl:\"(\\<forall>i. Suc i<length l \\<longrightarrow> \n           \\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                             \n             (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n    proof -\n    { fix i\n      assume asuc:\"Suc i<length l\"        \n      then have \"\\<not> (\\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\"\n        by (metis Suc_lessD cp prod.collapse prod.sel(1) stepc_elim_cases(1) zero_skip_all_skip)\n    } thus ?thesis by auto qed\n    have concr:\"(final (last l)  \\<longrightarrow>                    \n               ((fst (last l) = Skip \\<and> \n                snd (last l) \\<in> Normal ` q)) \\<or>\n                (fst (last l) = Throw \\<and> \n                snd (last l) \\<in> Normal ` (a)))\"\n    proof-\n    { \n      assume valid:\"final (last l)\"\n      have len_l:\"length l > 0\" using cp using cptn.simps by blast \n      then obtain a l1 where l:\"l=a#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n      have last_l:\"last l = l!(length l-1)\"\n        using last_length [of a l1] l by fastforce\n      then have fst_last_skip:\"fst (last l) = Skip\"             \n        by (metis `0 < length l` cp diff_less fst_conv zero_less_one zero_skip_all_skip)                           \n      have last_q: \"snd (last l) \\<in> Normal ` q\"    \n      proof -\n        have env: \"env_tran \\<Gamma> q l R\" using env_tran_def assum cp by blast\n        have env_right:\"env_tran_right \\<Gamma> l R \" using  a0 env_tran_right_def assum cp by metis\n        also obtain s1 where \"snd(l!0) = Normal s1 \\<and> s1\\<in>q\" \n          using assum by auto\n        ultimately have all_tran_env: \"\\<forall>i. Suc i < length l \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i))\"\n          using final_always_env_i cp zero_final_always_env_0 a0\n          by fastforce\n        then have \"\\<forall>i. i < length l \\<longrightarrow> snd (l!i) \\<in> Normal ` q\"\n          using stable_only_env_q  a0  env  by fastforce\n        thus ?thesis using last_l using len_l by fastforce    \n      qed\n      note res = conjI [OF fst_last_skip last_q]\n    } thus ?thesis by auto \n    qed\n    note res = conjI [OF concl concr]               \n  } thus ?thesis using c_prod unfolding comm_def by auto \nqed\n\n\nlemma Skip_sound: \n  \"Sta q R \\<Longrightarrow>       \n   (\\<forall>s. (Normal s, Normal s) \\<in> G)  \\<Longrightarrow>\n   \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> Skip sat [q,R, G, q,a]\" \nproof-\n  assume\n  a0:\"Sta q R\" and    \n  a1:\"(\\<forall>s. (Normal s, Normal s) \\<in> G)\"\n  {\n    fix s\n    have ass:\"cpn n \\<Gamma> Skip s \\<inter> assum(q, R) \\<subseteq> comm(G, (q,a)) F\"\n    proof-      \n    { fix c\n      assume a10:\"c \\<in> cpn n \\<Gamma> Skip s\" and a11:\"c \\<in> assum(q, R)\"\n      then have a10:\"c\\<in>cp \\<Gamma> Skip s\"\n        using cp_def cpn_def cptn_if_cptn_mod cptn_mod_nest_cptn_mod by blast\n      have \"c\\<in>comm(G, (q,a)) F\" using Skip_sound1[OF a0 a1 a10 a11] by auto      \n    } thus ?thesis by auto\n    qed \n  } \n  thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def) \nqed\n\nlemma Throw_sound1: \n  assumes a1:\"Sta a R\" and\n   a2:\"(\\<forall>s. (Normal s, Normal s) \\<in> G)\" and\n   a10:\"c \\<in> cp \\<Gamma> Throw s\" and\n   a11:\"c \\<in> assum(a, R)\"\nshows \"c \\<in> comm (G, (q,a)) F\"\nproof -  \n  obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce     \n  {\n    assume \"snd (last l) \\<notin> Fault ` F\"\n    have cp:\"l!0=(Throw,s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\" using a10 cp_def c_prod by fastforce\n    have assum:\"snd(l!0) \\<in> Normal ` (a) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n             (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n               (snd(l!i), snd(l!(Suc i))) \\<in> (R))\" \n      using a11 c_prod unfolding assum_def by simp\n    then have env_tran:\"env_tran_right \\<Gamma> l R\" using cp env_tran_right_def by auto\n    obtain a1 where a_normal:\"snd(l!0) = Normal a1 \\<and> a1 \\<in> a\"\n      using assum by auto\n    have concl:\"(\\<forall>i ns ns'. Suc i<length l \\<longrightarrow> \n           \\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                                           \n             (snd(l!i), snd(l!(Suc i))) \\<in>  (G))\"\n    proof -\n    { fix i\n      assume asuc:\"Suc i<length l\"\n      then have asuci:\"i<length l\" by fastforce\n      then have \"fst (l ! 0) = LanguageCon.com.Throw\" using cp by auto\n      moreover obtain s1 where \"snd (l ! 0) = Normal s1\" using assum by auto\n      ultimately have \"fst (l ! i) = Throw \\<and> (\\<exists>s2. snd (l ! i) = Normal s2)\"      \n        using cp a1 assum a_normal env_tran asuci zero_throw_all_throw\n        by fastforce\n      then have \"\\<not> (\\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\"\n        by (meson SmallStepCon.final_def SmallStepCon.no_step_final')           \n    } thus ?thesis by auto qed\n    have concr:\"(final (last l)  \\<longrightarrow>                    \n               ((fst (last l) = Skip \\<and> \n                snd (last l) \\<in> Normal ` q)) \\<or>\n                (fst (last l) = Throw \\<and> \n                snd (last l) \\<in> Normal ` (a)))\"\n    proof-\n    { \n      assume valid:\"final (last l)\"\n      have len_l:\"length l > 0\" using cp using cptn.simps by blast \n      then obtain a1 l1 where l:\"l=a1#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n      have last_l:\"last l = l!(length l-1)\"\n        using last_length [of a1 l1] l by fastforce\n      then have fst_last_skip:\"fst (last l) = Throw\"\n        by (metis a1 a_normal cp diff_less env_tran fst_conv len_l zero_less_one zero_throw_all_throw)                        \n      have last_q: \"snd (last l) \\<in> Normal ` (a)\"    \n      proof -\n        have env: \"env_tran \\<Gamma> a l R\" using env_tran_def assum cp by blast\n        have env_right:\"env_tran_right \\<Gamma> l R\" using env_tran_right_def assum cp by metis\n        then have all_tran_env: \"\\<forall>i. Suc i < length l \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i))\"\n        using final_always_env_i a1 assum cp zero_final_always_env_0 by fastforce            \n        then have \"\\<forall>i. i < length l \\<longrightarrow> snd (l!i) \\<in> Normal ` (a)\"\n        using stable_only_env_q  a1  env by fastforce\n        thus ?thesis using last_l using len_l by fastforce    \n      qed                \n      note res = conjI [OF fst_last_skip last_q]\n    } thus ?thesis by auto qed\n    note res = conjI [OF concl concr]               \n   }              \n   thus ?thesis using c_prod unfolding comm_def by auto \nqed          \n\nlemma Throw_sound: \n  \"Sta a R  \\<Longrightarrow>\n   (\\<forall>s. (Normal s, Normal s) \\<in> G) \\<Longrightarrow>\n   \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> Throw sat [a, R, G, q,a]\"\nproof -  \n assume   \n    a1:\"Sta a R\" and\n    a2:\" (\\<forall>s. (Normal s, Normal s) \\<in> G)\" {\n    fix s\n    have ass:\"cpn n \\<Gamma> Throw s \\<inter> assum(a, R) \\<subseteq> comm(G, (q,a)) F\"\n    proof-      \n    { fix c\n      assume a10:\"c \\<in> cpn n \\<Gamma> Throw s\" and a11:\"c \\<in> assum(a, R)\"\n      then have a10:\"c\\<in>cp \\<Gamma> Throw s\"\n        using cp_def cpn_def cptn_if_cptn_mod cptn_mod_nest_cptn_mod by blast\n      have \"c\\<in>comm(G, (q,a)) F\" using Throw_sound1[OF a1 a2 a10 a11] by auto      \n    } thus ?thesis by auto\n    qed \n  } \n  thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def) \nqed\n\nlemma no_comp_tran_before_i_0_g:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!0) = c \" and         \n         a2: \"Suc i<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"j < i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\" and\n         a4: \"\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))\" and\n         a5: \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(c, s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> \n                        (c1=Skip) \\<or> (c1=Throw \\<and> (\\<exists>s21. s2 = Normal s21))\" and        \n         a6: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc j) \\<in> Normal ` q\"\n   shows \"P\"\n  proof -\n   have \"Suc j < length l\" using a0 a1 a2 a3 a4 by fastforce\n   then have \"fst (l!j) = c\" \n     using a0 a1 a2 a3 a4 cptn_env_same_prog[of \\<Gamma> l j] by fastforce\n   then obtain s s1 c1 where l_0: \"l!j = (c, s) \\<and> l!(Suc j) = (c1,s1)\"  \n     by (metis (no_types) prod.collapse)    \n   moreover have \"snd (l!j) \\<in> Normal ` p\" using a4 stability[of p rely l 0 j j] a6 a3 a2\n    proof -\n      have \"\\<forall>B r ps n na nb f. \\<not> Sta B r \\<or> snd (ps ! n) \\<notin> Normal ` B \\<or> \\<not> n \\<le> na \\<or> \\<not> na < length ps \\<or> na - n \\<noteq> nb \\<or> (\\<exists>nb\\<ge>n. nb < na \\<and> \\<not> f\\<turnstile>\\<^sub>c ps ! nb \\<rightarrow>\\<^sub>e ps ! Suc nb) \\<or> \\<not> env_tran_right f ps r \\<or> snd (ps ! na) \\<in> Normal ` B \\<and> (fst (ps ! n)::('b, 'a, 'c,'d) LanguageCon.com) = fst (ps ! na)\"\n        using stability by blast\n      then show ?thesis\n        using Suc_lessD \\<open>Suc j < length l\\<close> a4 a6 by blast\n    qed      \n   then have suc_0_skip: \"(fst (l!Suc j) = Skip \\<or> fst (l!Suc j) = Throw) \\<and> \n                           (\\<exists>s2. snd(l!Suc j) = Normal s2 ) \" \n      using a5 a6 a3 SmallStepCon.step_Stuck_prop using fst_conv imageE l_0 snd_conv by auto \n   thus ?thesis using only_one_component_tran_j\n    proof -\n      have \"\\<forall>n na. \\<not> n < na \\<or> Suc n \\<le> na\"\n        using Suc_leI by satx  \n      thus ?thesis using only_one_component_tran_j[OF a0] suc_0_skip a6 a0 a2 a3\n        using imageE by blast          \n    qed\nqed\n\nlemma no_comp_tran_before_i:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = c\" and        \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"k\\<le>j \\<and> j < i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\" and\n         a4: \"\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))\" and\n          a5: \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(c, s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> \n                        (c1=Skip) \\<or> (c1=Throw \\<and> (\\<exists>s21. s2 = Normal s21))\" and        \n         a6: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc j) \\<in> Normal ` q\"\n   shows \"P\"\nusing a0 a1 a2 a3 a4 a5 a6\nproof (induct k arbitrary: l i j)\n  case 0 thus ?thesis using no_comp_tran_before_i_0_g by blast\nnext\n  case (Suc n) \n  then obtain a1 l1 where l: \"l=a1#l1\"\n    by (metis less_nat_zero_code list.exhaust list.size(3))\n  then have l1notempty:\"l1\\<noteq>[]\" using Suc by force    \n  then obtain i' where i': \"i=Suc i'\" using Suc \n    using less_imp_Suc_add by blast\n  then obtain j' where j': \"j=Suc j'\" using Suc\n    using Suc_le_D by blast      \n  have \"(\\<Gamma>,l1)\\<in>cptn\" using Suc l\n    using tl_in_cptn l1notempty by blast\n  moreover have \"fst (l1 ! n) = c\"\n    using Suc l l1notempty by force  \n  moreover have \"Suc i' < length l1 \\<and> n \\<le> i' \\<and> \\<Gamma>\\<turnstile>\\<^sub>c l1 ! i' \\<rightarrow> (l1 ! Suc i')\"\n    using Suc l l1notempty i' by auto\n  moreover have \"n \\<le> j' \\<and> j' < i' \\<and> \\<Gamma>\\<turnstile>\\<^sub>c l1 ! j' \\<rightarrow> (l1 ! Suc j')\"\n    using Suc l l1notempty i' j' by auto\n  moreover have \"\\<forall>k<j'. \\<Gamma>\\<turnstile>\\<^sub>c l1 ! k \\<rightarrow>\\<^sub>e (l1 ! Suc k)\"\n    using Suc l l1notempty j' by auto     \n  moreover have \"env_tran_right \\<Gamma> l1 rely \\<and> Sta q rely \\<and> Sta p rely \\<and> snd (l1!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l1!Suc j') \\<in> Normal ` q\" \n  proof -\n    have suc0:\"Suc 0 < length l\" using Suc by auto\n    have \"j>0\" using j' by auto\n    then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!0)  \\<rightarrow>\\<^sub>e (l!(Suc 0))\" using Suc(6) by blast\n    then have \"(snd(l!Suc 0) \\<in> Normal ` p)\" \n      using Suc(8) suc0 unfolding Sta_def env_tran_right_def by blast\n    also have \"snd (l!Suc j) \\<in> Normal ` q\" using Suc(8) by auto\n    ultimately show ?thesis using Suc(8) l by (metis env_tran_tail j' nth_Cons_Suc) \n  qed\n  ultimately show ?case using Suc(1)[of l1 i' j' ]  Suc(7)  Suc(8) j' l by auto\nqed\n\nlemma exists_first_occ: \"P (n::nat) \\<Longrightarrow> \\<exists>m. P m \\<and> (\\<forall>i<m. \\<not> P i)\"\nproof (induct n)\n  case 0 thus ?case by auto\nnext\n  case (Suc n) thus ?case\n  by (metis ex_least_nat_le not_less0) \nqed\n\nlemma exist_first_comp_tran':\nassumes a1: \"Suc i<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\"      \nshows \"\\<exists>j. (Suc j<length l \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))) \\<and> (\\<forall>k < j. \\<not>\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\nproof -\n  let ?P =  \"(\\<lambda>n. Suc n<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!n)  \\<rightarrow> (l!(Suc n))))\"\n  show ?thesis using exists_first_occ[of ?P i] a1 by auto  \nqed\n\nlemma exist_first_comp_tran:\nassumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n        a1: \"Suc i<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\"      \nshows \"\\<exists>j. j\\<le>i \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\nproof -\n  obtain j where  pj:\"(Suc j<length l \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))) \\<and> \n                     (\\<forall>k < j. \\<not>(Suc k<length l \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))))\"\n    using a1 exist_first_comp_tran' by blast\n  then have \"j\\<le>i\" using a1 pj by (cases \"j\\<le>i\", auto)\n  moreover have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))\" using pj by auto\n  moreover have \"(\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\" \n  proof -\n    {fix k\n    assume kj:\"k<j\"\n    then have \"Suc k \\<ge> length l \\<or>  \\<not> ( (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))) \" using pj by auto\n    then have \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))\"\n    proof\n      {assume \"length l \\<le> Suc k\" \n       thus ?thesis using kj pj by auto\n      }\n      {assume \"\\<not> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n       also have \"k + 1 < length l\" using kj pj by auto\n       ultimately show ?thesis\n         using a0 cptn_tran_ce_i step_ce_elim_cases by blast\n      }\n    qed\n    } thus ?thesis by auto\n  qed\n  ultimately show ?thesis by auto\nqed\n\n\nlemma skip_com_all_skip:\nassumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n        a1:\"fst (l!i) = Skip\" and\n        a2:\"i<length l\" \n   shows \"\\<forall>j. j\\<ge>i \\<and> j <length l \\<longrightarrow> fst (l!j) = Skip\"\nusing a0 a1 a2\nproof (induct \"length l - (i + 1)\" arbitrary: i)\n  case 0  thus ?case by (metis Suc_eq_plus1 Suc_leI diff_is_0_eq nat_less_le zero_less_diff) \nnext \n  case (Suc n)\n  then have l:\"Suc i < length l\" by arith\n  have n:\"n = (length l) - (Suc i + 1)\" using Suc by arith\n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow>\\<^sub>c\\<^sub>e l ! Suc i\" using cptn_tran_ce_i Suc\n    by (metis (no_types) Suc.hyps(2) a0 cptn_tran_ce_i zero_less_Suc zero_less_diff)\n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow> l ! Suc i \\<or> \\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow>\\<^sub>e l ! Suc i\" \n    using step_ce_elim_cases by blast  \n  then have or:\"fst(l!Suc i) = Skip\" \n  proof\n    {assume \"\\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow>\\<^sub>e l ! Suc i\" \n     thus ?thesis using Suc(4) by (metis env_c_c' prod.collapse)\n    }\n  next\n   {assume step:\"\\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow> l ! Suc i\" \n     {assume \"fst(l!i) = Skip\" \n      then have ?thesis using step\n        using SmallStepCon.final_def SmallStepCon.no_step_final' by blast\n     }note left = this\n     {assume \"fst(l!i) = Throw\"\n      then have ?thesis using step stepc_elim_cases\n      proof -\n        have \"\\<exists>x. l ! Suc i = (LanguageCon.com.Skip, x)\"\n          by (metis (no_types) \\<open>fst (l ! i) = LanguageCon.com.Throw\\<close> local.step stepc_elim_cases(11) surjective_pairing)\n        then show ?thesis\n          by fastforce\n      qed      \n     } then show ?thesis using Suc(4) left by auto\n    }\n  qed\n  show ?case using Suc(1)[OF n a0 or l] Suc(4) Suc(5) by (metis le_less_Suc_eq not_le) \nqed\n\nlemma terminal_com_all_term:\nassumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n        a1:\"fst (l!i) = Skip \\<or> fst (l!i) = Throw\" and\n        a2:\"i<length l\" \n   shows \"\\<forall>j. j\\<ge>i \\<and> j <length l \\<longrightarrow> fst (l!j) = Skip \\<or> fst (l!j) = Throw\"\nusing a0 a1 a2\nproof (induct \"length l - (i + 1)\" arbitrary: i)\n  case 0  thus ?case by (metis Suc_eq_plus1 Suc_leI diff_is_0_eq nat_less_le zero_less_diff) \nnext \n  case (Suc n)\n  then have l:\"Suc i < length l\" by arith\n  have n:\"n = (length l) - (Suc i + 1)\" using Suc by arith\n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow>\\<^sub>c\\<^sub>e l ! Suc i\" using cptn_tran_ce_i Suc\n    by (metis (no_types) Suc.hyps(2) a0 cptn_tran_ce_i zero_less_Suc zero_less_diff)\n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow> l ! Suc i \\<or> \\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow>\\<^sub>e l ! Suc i\" \n    using step_ce_elim_cases by blast  \n  then have or:\"fst(l!Suc i) = Skip \\<or> fst(l!Suc i) = Throw\" \n  proof\n    {assume \"\\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow>\\<^sub>e l ! Suc i\" \n     thus ?thesis using Suc(4) by (metis env_c_c' prod.collapse)\n    }\n  next\n   {assume step:\"\\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow> l ! Suc i\" \n     {assume \"fst(l!i) = Skip\" \n      then have ?thesis using step\n        using SmallStepCon.final_def SmallStepCon.no_step_final' by blast\n     }note left = this\n     {assume \"fst(l!i) = Throw\"\n      then have ?thesis using step stepc_elim_cases\n      proof -\n        have \"\\<exists>x. l ! Suc i = (LanguageCon.com.Skip, x)\"\n          by (metis (no_types) \\<open>fst (l ! i) = LanguageCon.com.Throw\\<close> local.step stepc_elim_cases(11) surjective_pairing)\n        then show ?thesis\n          by fastforce\n      qed      \n     } then show ?thesis using Suc(4) left by auto\n    }\n  qed\n  show ?case using Suc(1)[OF n a0 or l] Suc(4) Suc(5) by (metis le_less_Suc_eq not_le) \nqed\n\nlemma only_one_c_comp_tran:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!0) = c\" and         \n         a2: \"Suc i<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"i < j \\<and> Suc j < length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> fst (l!j) = c\" and\n         a4: \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(c, s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> \n                        ((c1=Skip) \\<or> (c1=Throw)) \" and\n         a5: \"(\\<forall>k < i. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n   shows \"P\"\nproof - \n  have fst:\"fst (l!i) = c\" using a0 a1 a5\n    by (simp add: a2 cptn_env_same_prog)\n  then have suci:\"fst (l!Suc i) = Skip \\<or> fst (l!Suc i) = Throw\" \n    using a4 by (metis a2 surjective_pairing) \n  then have \"fst (l!j) = Skip \\<or> fst (l!j) = Throw\" \n  proof -\n    have \"Suc i \\<le> j\"\n      using Suc_leI a3 by presburger\n    then show ?thesis\n      using Suc_lessD  terminal_com_all_term[OF a0 suci] a2 a3 by blast\n  qed \n  thus ?thesis\n  proof \n    {assume \"fst (l ! j) = Skip\"\n     then show ?thesis using a3 SmallStepCon.final_def SmallStepCon.no_step_final' by blast\n    }\n  next\n    {assume asm:\"fst (l ! j) = Throw\"\n     then show ?thesis       \n       proof (cases \"snd (l!i)\")\n         case Normal \n         thus ?thesis using a3 a2 fst asm\n           by (metis SmallStepCon.final_def SmallStepCon.no_step_final') \n       next\n         case Abrupt thus ?thesis using a3 a2 fst asm skip_com_all_skip\n             suci by (metis Suc_leI Suc_lessD a0 mod_env_not_component prod.collapse)\n           \n       next \n         case Fault thus ?thesis using a3 a2 fst asm skip_com_all_skip \n           suci by (metis Suc_leI Suc_lessD a0 mod_env_not_component prod.collapse)\n       next \n         case Stuck thus ?thesis using a3 a2 fst asm skip_com_all_skip \n             suci by (metis Suc_leI Suc_lessD a0 mod_env_not_component prod.collapse)\n       qed\n    } \n  qed\nqed\n\nlemma only_one_component_tran1:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!0) = c\" and         \n         a2: \"Suc i<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"j \\<noteq> i \\<and> Suc j < length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> fst (l!j) = c\" and\n         a4: \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(c, s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> \n                        ((c1=Skip) \\<or> (c1=Throw)) \" and\n         a5: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc j) \\<in> Normal ` q \"\n   shows \"P\"\nproof (cases \"j=i\")\n  case True thus ?thesis using a3 by auto\nnext\n  case False note j_neq_i=this \n  thus ?thesis\n  proof (cases \"j<i\")\n    case True \n    thus ?thesis \n    proof -\n      obtain bb :: \"'b set \\<Rightarrow> ('b \\<Rightarrow> ('b, 'c) xstate) \\<Rightarrow> ('b, 'c) xstate \\<Rightarrow> 'b\" where\n        \"\\<forall>x0 x1 x2. (\\<exists>v3. x2 = x1 v3 \\<and> v3 \\<in> x0) = (x2 = x1 (bb x0 x1 x2) \\<and> bb x0 x1 x2 \\<in> x0)\"\n        by moura\n      then have f1: \"\\<forall>x f B. x \\<notin> f ` B \\<or> x = f (bb B f x) \\<and> bb B f x \\<in> B\"\n        by (meson imageE)\n      then have \"\\<Gamma>\\<turnstile>\\<^sub>c (c, snd (l ! j)) \\<rightarrow> (fst (l ! Suc j), Normal (bb q Normal (snd (l ! Suc j))))\"\n        by (metis (no_types) a3 a5 surjective_pairing)\n      then show ?thesis\n        using f1 by (meson Suc_leI a0 a2 a4 a5 True only_one_component_tran_j)\n    qed  \n  next\n    case False \n    obtain j1 \n    where all_ev:\"j1\\<le>i \\<and>  \n                 (\\<Gamma>\\<turnstile>\\<^sub>c(l!j1)  \\<rightarrow> (l!(Suc j1))) \\<and> \n                 (\\<forall>k < j1. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n      using a0 a2 a3 exist_first_comp_tran by blast\n    then have fst:\"fst (l!j1) = c\" \n      using a0 a1 a2 cptn_env_same_prog le_imp_less_Suc less_trans_Suc by blast\n    have suc:\"Suc j1 < length l \\<and> \\<Gamma>\\<turnstile>\\<^sub>c l ! j1 \\<rightarrow> l ! Suc j1\" using all_ev a2\n       using Suc_lessD le_eq_less_or_eq less_trans_Suc by linarith\n    have evs:\"(\\<forall>k < j1. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\" using all_ev by auto\n    have j:\"j1 < j \\<and> Suc j < length l \\<and> \\<Gamma>\\<turnstile>\\<^sub>c l ! j \\<rightarrow> l ! Suc j \\<and> fst (l ! j) = c\"\n      using a3 all_ev False by auto\n    then show ?thesis \n      using only_one_c_comp_tran[OF a0 a1 suc j a4 evs] by auto   \n  qed\nqed  \n \nlemma only_one_component_tran_i:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = c\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"k\\<le>j \\<and> j \\<noteq> i \\<and> Suc j < length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> fst (l!j) = c\" and\n         a4: \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(c, s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> \n                        ((c1=Skip) \\<or> (c1=Throw)) \" and\n         a5: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc j) \\<in> Normal ` q \"\n   shows \"P\"\nusing a0 a1 a2 a3 a4 a5\nproof (induct k arbitrary: l i j p q)\n  case 0 show ?thesis using only_one_component_tran1[OF 0(1) 0(2) ]  0 by blast\nnext\n  case (Suc n) \n   then obtain a1 l1 where l: \"l=a1#l1\"\n    by (metis less_nat_zero_code list.exhaust list.size(3))\n  then have l1notempty:\"l1\\<noteq>[]\" using Suc by force    \n  then obtain i' where i': \"i=Suc i'\" using Suc \n    using less_imp_Suc_add using Suc_le_D by meson \n  then obtain j' where j': \"j=Suc j'\" using Suc\n    using Suc_le_D by meson      \n  have a0:\"(\\<Gamma>,l1)\\<in>cptn\" using Suc l\n    using tl_in_cptn l1notempty by meson\n  moreover have a1:\"fst (l1 ! n) = c\"\n    using Suc l l1notempty by force  \n  moreover have a2:\"Suc i' < length l1 \\<and> n \\<le> i' \\<and> \\<Gamma>\\<turnstile>\\<^sub>c l1 ! i' \\<rightarrow> (l1 ! Suc i')\"\n    using Suc l l1notempty i' by auto\n  moreover have a3:\"n \\<le> j' \\<and> j' \\<noteq> i' \\<and> Suc j' < length l1 \\<and> \\<Gamma>\\<turnstile>\\<^sub>c l1 ! j' \\<rightarrow> (l1 ! Suc j') \\<and> fst (l1!j') = c\"\n    using Suc l l1notempty i' j' by auto\n  moreover have a4:\"env_tran_right \\<Gamma> l1 rely \\<and>\n                  Sta p rely \\<and> snd (l1!n) \\<in> Normal ` p \\<and> \n                  Sta q rely \\<and> snd (l1 ! Suc j') \\<in> Normal ` q \" \n     using Suc(7) l j' unfolding env_tran_right_def by fastforce\n  show ?case using Suc(1)[OF a0 a1 a2 a3 Suc(6) a4] by auto\nqed\n\nlemma only_one_component_tran:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = c\" and         \n         a2: \"k\\<le>i \\<and>  i \\<noteq> j \\<and> Suc i<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i))) \\<and>   fst (l!i) = c\" and\n         a3: \"k\\<le>j \\<and> Suc j < length l\" and\n         a4: \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(c,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> \n                        ((c1=Skip) \\<or> (c1=Throw))\" and\n         a5: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q \"\n   shows \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\nusing a0 a1 a2 a3 a4 a5 only_one_component_tran_i\nproof -\n  {assume \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<or> (\\<not> \\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"\n   then have  \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n   proof\n     assume \"\\<Gamma>\\<turnstile>\\<^sub>c l ! j \\<rightarrow> (l ! Suc j)\" \n       then have j:\"Suc j<length l \\<and> k\\<le>j \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\" using a3 by auto\n       show ?thesis using only_one_component_tran_i[OF a0 a1 j a2 a4 a5] \n        by blast \n   next\n      assume \"\\<not> \\<Gamma>\\<turnstile>\\<^sub>c l ! j \\<rightarrow> (l ! Suc j)\"\n        thus ?thesis\n          by (metis Suc_eq_plus1 a0 a3 cptn_tran_ce_i step_ce_elim_cases)\n   qed\n  } thus ?thesis by auto\nqed\n  \nlemma only_one_component_tran_all_env:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = c\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i))) \\<and> fst (l!i) = c\" and\n         a3: \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(c,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> \n                        ((c1=Skip) \\<or> (c1=Throw))\" and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q \"\n   shows \"\\<forall>j. k\\<le>j \\<and> j\\<noteq>i \\<and> Suc j < (length l) \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\nproof -\n  {fix j\n  assume ass:\"k\\<le>j \\<and> j\\<noteq>i \\<and> Suc j < (length l)\"\n  then have a2:\"k \\<le> i \\<and> i \\<noteq> j \\<and> Suc i < length l \\<and> \\<Gamma>\\<turnstile>\\<^sub>c l ! i \\<rightarrow> l ! Suc i \\<and> fst (l ! i) = c\"\n    using a2 by auto\n  then have \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\" \n    using only_one_component_tran[OF a0 a1 ] a2 a3 ass a4 by blast\n  } thus ?thesis by auto\nqed\n\nlemma only_one_component_tran_all_not_comp:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = c\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i))) \\<and> fst (l!i) = c\" and\n         a3: \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(c, s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> \n                        ((c1=Skip) \\<or> (c1=Throw))\" and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q \"\n   shows \"\\<forall>j. k\\<le>j \\<and> j\\<noteq>i \\<and> Suc j < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"\nproof -\n  {fix j\n  assume ass:\"k\\<le>j \\<and> j\\<noteq>i \\<and> Suc j < (length l)\"\n  then have \"\\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"    \n      using a0 a1 a2 a3 a4 only_one_component_tran_i ass by blast   \n  } thus ?thesis by auto\nqed\n\nlemma final_exist_component_tran1:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n          a1: \"fst (l!i) = c\" and               \n          a2: \"env_tran \\<Gamma> q l R \\<and> Sta q R\" and\n          a3: \"i\\<le>j \\<and> j < length l \\<and> final (l!j)\" and          \n          a5: \"c\\<noteq>Skip \\<and> c\\<noteq>Throw\"\n  shows \"\\<exists>k. k\\<ge>i \\<and> k<j \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\nproof -\n  {assume \"\\<forall>k. k\\<ge>i \\<and>  k<j \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\" \n   then have \"\\<forall>k. k\\<ge>i \\<and>  k<j \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))\"\n   by (metis (no_types, lifting) Suc_eq_plus1 a0 a3 cptn_tran_ce_i less_trans_Suc step_ce_elim_cases)\n   then have \"fst (l!j) =  fst (l!i)\" using cptn_i_env_same_prog a0 a3 by blast \n   then have False using a3 a1 a5 unfolding final_def by auto\n  }  \n  thus ?thesis by auto\nqed  \n\nlemma final_exist_component_tran:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n          a1: \"fst (l!i) = c\" and                         \n          a2: \"i\\<le>j \\<and> j < length l \\<and> final (l!j)\" and          \n          a3: \"c\\<noteq>Skip \\<and> c\\<noteq>Throw\"\n  shows \"\\<exists>k. k\\<ge>i \\<and> k<j \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\nproof -\n  {assume \"\\<forall>k. k\\<ge>i \\<and>  k<j \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\" \n   then have \"\\<forall>k. k\\<ge>i \\<and>  k<j \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))\"\n   by (metis (no_types, lifting) Suc_eq_plus1 a0 a2 cptn_tran_ce_i less_trans_Suc step_ce_elim_cases)\n   then have \"fst (l!j) =  fst (l!i)\" using cptn_i_env_same_prog a0 a2 by blast \n   then have False using a2 a1 a3 unfolding final_def by auto\n  }  \n  thus ?thesis by auto\nqed\n\nlemma suc_not_final_final_c_tran:\n assumes a0: \"(\\<Gamma>, l) \\<in> cptn \" and \n         a1: \"Suc j< length l \\<and> \\<not>final (l!j) \\<and> final (l!Suc j)\"\n shows \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"\nproof -\n   obtain x xs where l:\"l = x#xs\" using a0 cptn.simps by blast\n   obtain c1 s1 c2 s2 where l1:\"l!j = (c1,s1) \\<and> l!(Suc j) = (c2,s2)\" using a1 by fastforce\n   have \"\\<not> \\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j))\" \n   proof -\n      { assume a:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j))\"\n        then have eq_fst:\"fst (l!j) = fst (l!Suc j)\" by (metis env_c_c' prod.collapse)\n        { assume \"fst (l!Suc j) = Skip\"\n          then have \"False\" using a1 eq_fst unfolding final_def by fastforce\n        }note p1=this\n        { assume \"fst (l!Suc j) = Throw \\<and> (\\<exists>s. snd (l!Suc j) = Normal s)\" \n          then have \"False\" using a1 eq_fst unfolding final_def\n          by (metis a eenv_normal_s'_normal_s local.l1 snd_conv)\n        }\n        then have False using a1 p1 unfolding final_def by fastforce\n      } thus ?thesis by auto\n   qed\n   also have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>c\\<^sub>e (l!(Suc j))\" using l cptn_stepc_rtran a0 a1 by fastforce  \n   ultimately show ?thesis using step_ce_not_step_e_step_c local.l1 by fastforce \nqed\n \nlemma final_exist_component_tran_final:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and                                  \n          a2: \"i\\<le>j \\<and> j < length l \\<and> final (l!j)\" and                             \n          a3: \"\\<not>final(l!i)\" \n  shows \"\\<exists>k. k\\<ge>i \\<and> k<j \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final(l!(Suc k))\"\nproof -\n  let ?P = \"\\<lambda>j. i\\<le>j \\<and> j < length l \\<and> final (l!j)\"\n  obtain k where k:\"?P k \\<and> (\\<forall>i<k. \\<not> ?P i)\" using a2 exists_first_occ[of ?P j] by auto\n  then have i_k_not_final:\"\\<forall>i'<k. i'\\<ge>i \\<longrightarrow> \\<not>final (l!i')\" using a2 by fastforce\n  have i_eq_j:\"i<j\" using a2 a3 using le_imp_less_or_eq by auto \n  then obtain pre_k  where pre_k:\"Suc pre_k = k\" using a2 k\n    by (metis a3 eq_iff le0 lessE neq0_conv) \n  then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!pre_k)  \\<rightarrow> (l!k)\"\n  proof -\n    have \"pre_k \\<ge>i\" using pre_k i_eq_j using a3 k le_Suc_eq by blast  \n    then have \"\\<not>(final (l!pre_k))\" using i_k_not_final pre_k by auto \n    thus ?thesis using suc_not_final_final_c_tran a0 a2 pre_k k by fastforce\n  qed\n  thus ?thesis using pre_k by (metis a2 a3 i_k_not_final k le_Suc_eq not_less_eq)\nqed \n\n\nsubsection {* Basic Sound *}\n\nlemma basic_skip:\n   \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Basic f e, s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> c1=Skip\"\nproof -\n  {fix s1 s2 c1\n   assume \"\\<Gamma>\\<turnstile>\\<^sub>c(Basic f e,s1)  \\<rightarrow> ((c1,s2))\"     \n   then have \"c1=Skip\" using stepc_elim_cases(3) by blast    \n  } thus ?thesis by auto \nqed  \n\nlemma no_comp_tran_before_i_basic:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Basic f e\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"k\\<le>j \\<and> j < i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\" and\n         a4: \"\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))\" and  \n         a5: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc j) \\<in> Normal ` q\"        \n   shows \"P\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Basic f e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  basic_skip by fastforce                  \n  thus ?thesis using  a0 a1 a2 a3 a4 a5 no_comp_tran_before_i by blast\nqed\n\nlemma only_one_component_tran_i_basic:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Basic f e\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"k\\<le>j \\<and> j \\<noteq> i \\<and> Suc j < length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> fst (l!j) =  Basic f e\" and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc j) \\<in> Normal ` q\"     \n   shows \"P\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Basic f e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  basic_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 a4 only_one_component_tran_i[OF a0 a1 a2 ] by blast\nqed   \n\nlemma only_one_component_tran_basic:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Basic f e\" and         \n         a2: \" k\\<le>i \\<and> i \\<noteq> j \\<and>  Suc i<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i))) \\<and> fst (l!i) = Basic f e\" and\n         a3: \"k\\<le>j  \\<and> Suc j < length l\" and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                       Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q\"       \n   shows \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Basic f e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  basic_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 a4 only_one_component_tran by blast\nqed   \n\nlemma only_one_component_tran_all_env_basic:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Basic f e\" and         \n         a2: \"k\\<le>i \\<and> Suc i<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i))) \\<and> fst (l!i) = Basic f e\" and        \n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                       Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q\"\n   shows \"\\<forall>j. k\\<le>j \\<and> j\\<noteq>i \\<and> Suc j < (length l) \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\nproof -\n  have b: \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Basic f e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  basic_skip by blast\n  show ?thesis \n    by (metis (no_types) a0 a1 a2 a3 only_one_component_tran_basic) \nqed   \n\nlemma only_one_component_tran_all_not_comp_basic:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Basic f e\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))  \\<and> fst (l!i) = Basic f e\" and         \n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                       Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q\"     \n   shows \"\\<forall>j. k\\<le>j \\<and> j\\<noteq>i \\<and> Suc j < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Basic f e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  basic_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 only_one_component_tran_all_not_comp by blast\nqed   \n\nlemma one_component_tran_basic:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!0) = Basic f e\" and         \n         a2: \"Suc k<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\" and\n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely\" and\n         a4:\"p \\<subseteq> {s. f s \\<in> q}\"\n           \n  shows \"\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Basic f e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  basic_skip by blast\n  also obtain j where first:\"(Suc j<length l \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))) \\<and> \n                 (\\<forall>k < j. \\<not>((\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))))\"\n    by (metis (no_types) a2 exist_first_comp_tran')\n  moreover then have prg_j:\"fst (l!j) = Basic f e\"  using a1 a0\n   by (metis cptn_env_same_prog not_step_comp_step_env)\n  moreover have sta_j:\"snd (l!j) \\<in> Normal ` p\"\n  proof -\n    have a0':\"0\\<le>j \\<and> j<(length l)\" using first by auto\n    have a1':\"(\\<forall>k. 0\\<le>k \\<and> k < j \\<longrightarrow> ((\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))))\" \n      using first not_step_comp_step_env a0 by fastforce   \n    thus ?thesis using stability first a3 a1'  a0' by blast \n  qed \n  then have \"snd (l!Suc j) \\<in> Normal ` q\" using a4 first prg_j\n  proof -\n    obtain s where \"snd (l!j) = Normal s \\<and> s\\<in>p\" using sta_j by fastforce\n    moreover then have \"fst(l!Suc j) = Skip \\<and> snd(l!Suc j) = Normal (f s)\" using first\n      by (metis fst_conv prg_j snd_conv stepc_Normal_elim_cases(3) surjective_pairing)\n    ultimately show ?thesis using a4 by fastforce\n  qed\n  then have \"\\<forall>i. 0\\<le>i \\<and> i\\<noteq>j \\<and> Suc i < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\"\n    using only_one_component_tran_all_not_comp_basic[OF a0 a1] first a3 \n          a0 a1 calculation(1) only_one_component_tran1 prg_j by blast \n  moreover then have \"k=j\" using a2 by fastforce\n  ultimately show ?thesis by auto\nqed   \n\nlemma one_component_tran_basic_env:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!0) = Basic f e\" and         \n         a2: \"Suc k<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\" and\n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely\" and\n         a4:\"p \\<subseteq> {s. f s \\<in> q}\"           \n  shows \"\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j))\"\nproof - \n  have \"\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> \\<not> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"\n  using one_component_tran_basic[OF a0 a1 a2 a3 a4] by auto\n  thus ?thesis using  a0 \n     by (metis Suc_eq_plus1 cptn_tran_ce_i step_ce_elim_cases)\nqed\n\nlemma final_exist_component_tran_basic:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n          a1: \"fst (l!i) = Basic f e\" and               \n          a2: \"env_tran \\<Gamma> q l R\" and\n          a3: \"i\\<le>j \\<and> j < length l \\<and> final (l!j)\" \n  shows \"\\<exists>k. k\\<ge>i \\<and> k<j \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\nproof - \n  show ?thesis using  a0 a1 a2 a3 final_exist_component_tran by blast\nqed   \n\n(*lemma assumes a0:\"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  c sat [p, R, G, q,a]\"\n      shows \"\\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub>  c sat [p, R, G, q,a]\"\nproof-\n  {     \n    assume a01:\"\\<forall>(b,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Call b) sat [p, R, G, q,a]\"\n    have \"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c sat [p, R, G, q,a]\"\n    proof-\n      {fix s l\n        assume a02:\"(\\<Gamma>,l)\\<in>cpn n \\<Gamma> c s\" and\n               a03:\"(\\<Gamma>,l)\\<in>assum(p, R)\"\n        have \"(\\<Gamma>,l)\\<in>comm(G, (q,a)) F\"  \n        proof-\n          have cpn_cp:\"(\\<Gamma>,l)\\<in>cp \\<Gamma> c s\" using a02\n            using cp_def cpn_def cptn_if_cptn_mod cptn_mod_nest_cptn_mod by fastforce\n        qed\n      } then show ?thesis unfolding  com_validityn_def cpn_def by auto\n    qed\n  } then show ?thesis unfolding com_cvalidityn_def by auto\nqed *)\n\nlemma Basic_sound1: \n  assumes a0:\"p \\<subseteq> {s. f s \\<in> q}\" and\n      a1:\"(\\<forall>s t. s\\<in>p \\<and> (t=f s) \\<longrightarrow> (Normal s,Normal t) \\<in> G)\" and\n      a2:\"Sta p R\" and\n      a3:\"Sta q R\" and\n      a10:\"c \\<in> cp \\<Gamma> (Basic f e) s\" and a11:\"c \\<in> assum(p, R)\"\n    shows \"c\\<in>comm(G, (q,a)) F\"\nproof -   \n  obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n   have cp:\"l!0=(Basic f e,s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\" using a10 cp_def c_prod by fastforce\n   have assum:\"snd(l!0) \\<in> Normal ` (p) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n             (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n               (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n   using a11 c_prod unfolding assum_def by simp\n   have concl:\"(\\<forall>i ns ns'. Suc i<length l \\<longrightarrow> \n           \\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                             \n           (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n   proof -\n   { fix k\n     assume a00:\"Suc k<length l\" and\n            a11:\"\\<Gamma>1\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"                \n     have len_l:\"length l > 0\" using cp using cptn.simps by blast \n     then obtain a l1 where l:\"l=a#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n     have last_l:\"last l = l!(length l-1)\"\n       using last_length [of a l1] l by fastforce\n     have env_tran:\"env_tran \\<Gamma> p l R\" using assum env_tran_def cp by blast\n     then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n       using env_tran env_tran_right_def a2 unfolding env_tran_def by auto\n     then have all_event:\"\\<forall>j. 0\\<le>j \\<and> j \\<noteq> k \\<and> Suc j < length l \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n       using one_component_tran_basic_env[of \\<Gamma> l f e k R] a0 a00 a11 a2 a3 assum cp \n             env_tran_right fst_conv\n       by metis\n     then have before_k_all_evn:\"\\<forall>j. 0\\<le>j \\<and> j < k  \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n           using a00 a11  by fastforce\n     then have k_basic:\"fst(l!k) = Basic f e \\<and> snd (l!k) \\<in> Normal ` (p)\" \n       using  cp env_tran_right a2 assum a00 a11  stability[of p R l 0 k k \\<Gamma>]\n       by force\n     have suc_k_skip_q:\"fst(l!Suc k) = Skip \\<and> snd (l!(Suc k)) \\<in> Normal ` q\"\n     proof \n       show suc_skip: \"fst(l!Suc k) = Skip\"\n         using a0 a00 a11  k_basic by (metis basic_skip surjective_pairing) \n     next\n       obtain s' where k_s: \"snd (l!k)=Normal s' \\<and> s' \\<in> (p)\" \n         using a00 a11  k_basic by auto\n       then have \"snd (l!(Suc k)) = Normal (f s')\"          \n         using a00 a11  k_basic stepc_Normal_elim_cases(3)\n         by (metis prod.inject surjective_pairing)          \n       then show \"snd (l!(Suc k)) \\<in> Normal ` q\" using a0 k_s by blast\n     qed\n     obtain s' s'' where \n        ss:\"snd (l!k) = Normal s' \\<and> s' \\<in> (p) \\<and>  \n           snd (l!(Suc k)) = Normal s'' \\<and> s'' \\<in> q\"\n       using suc_k_skip_q k_basic by fastforce         \n     then have \"(snd(l!k), snd(l!(Suc k))) \\<in>  G\"\n       using a0 a1 a2\n       by (metis Pair_inject a11 k_basic prod.exhaust_sel stepc_Normal_elim_cases(3))\n   } thus ?thesis by auto qed\n   have concr:\"(final (last l)  \\<longrightarrow> \n               snd (last l) \\<notin> Fault ` F  \\<longrightarrow>\n               ((fst (last l) = Skip \\<and> \n                snd (last l) \\<in> Normal ` q)) \\<or>\n                (fst (last l) = Throw \\<and> \n                snd (last l) \\<in> Normal ` (a)))\"\n   proof-\n   { \n     assume valid:\"final (last l)\"\n     have len_l:\"length l > 0\" using cp using cptn.simps by blast \n     then obtain a l1 where l:\"l=a#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n     have last_l:\"last l = l!(length l-1)\"\n       using last_length [of a l1] l by fastforce\n     have env_tran:\"env_tran \\<Gamma> p l R\" using assum env_tran_def cp by blast\n     then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n       using env_tran env_tran_right_def a2 unfolding env_tran_def by auto\n     have \"\\<exists>k. k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n     proof -             \n       have \"0\\<le> (length l-1)\" using len_l last_l by auto\n       moreover have \"(length l-1) < length l\" using len_l by auto\n       moreover have \"final (l!(length l-1))\" using valid last_l by auto\n       moreover have \"fst (l!0) = Basic f e\" using cp by auto\n       ultimately show ?thesis \n         using cp final_exist_component_tran_basic env_tran a2 by blast \n     qed\n     then obtain k where k_comp_tran: \"k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n       by auto\n     moreover then have \"Suc k < length l\" by auto\n     ultimately have all_event:\"\\<forall>j. 0\\<le>j \\<and> j \\<noteq> k \\<and> Suc j < length l \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n        using one_component_tran_basic_env[of \\<Gamma> l f e k R] a0  a11 a2 a3 assum cp \n             env_tran_right fst_conv by metis           \n     then have before_k_all_evn:\"\\<forall>j. 0\\<le>j \\<and> j < k  \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n           using k_comp_tran by fastforce\n     then have k_basic:\"fst(l!k) = Basic f e \\<and> snd (l!k) \\<in> Normal ` (p)\" \n       using  cp env_tran_right a2 assum k_comp_tran stability[of p R l 0 k k \\<Gamma>]\n       by force\n     have suc_k_skip_q:\"fst(l!Suc k) = Skip \\<and> snd (l!(Suc k)) \\<in> Normal ` q\"\n     proof \n       show suc_skip: \"fst(l!Suc k) = Skip\"\n         using a0 k_comp_tran k_basic by (metis basic_skip surjective_pairing) \n     next\n       obtain s' where k_s: \"snd (l!k)=Normal s' \\<and> s' \\<in> (p)\" \n         using k_comp_tran k_basic by auto\n       then have \"snd (l!(Suc k)) = Normal (f s')\"          \n         using k_comp_tran k_basic stepc_Normal_elim_cases(3)\n         by (metis prod.inject surjective_pairing)          \n       then show \"snd (l!(Suc k)) \\<in> Normal ` q\" using a0 using k_s by blast\n     qed\n     have after_k_all_evn:\"\\<forall>j. (Suc k)\\<le>j \\<and> Suc j < (length l)  \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n           using all_event k_comp_tran by fastforce                            \n     then have fst_last_skip:\"fst (last l) = Skip \\<and> \n                         snd ((last l)) \\<in> Normal ` q\"\n     using  a2 last_l len_l cp env_tran_right a3 suc_k_skip_q assum k_comp_tran \n            stability [of q R l \"Suc k\" \"((length l) - 1)\" _ \\<Gamma>] \n       by fastforce                 \n   } thus ?thesis by auto qed\n   note res = conjI [OF concl concr]                               \n   thus ?thesis using c_prod unfolding comm_def by auto \n qed\n\n\nlemma Basic_sound: \n       \"p \\<subseteq> {s. f s \\<in> q} \\<Longrightarrow>\n      (\\<forall>s t. s\\<in>p \\<and> (t=f s) \\<longrightarrow> (Normal s,Normal t) \\<in> G) \\<Longrightarrow>       \n       Sta p R \\<Longrightarrow>\n       Sta q R \\<Longrightarrow>       \n       \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub>  (Basic f e) sat [p, R, G, q,a]\"\nproof -  \n assume\n    a0:\"p \\<subseteq> {s. f s \\<in> q}\" and\n    a1:\"(\\<forall>s t. s\\<in>p \\<and> (t=f s) \\<longrightarrow> (Normal s,Normal t) \\<in> G)\" and\n    a2:\"Sta p R \" and\n    a3:\"Sta q R\" \n{\n    fix s\n    have \"cpn n \\<Gamma> (Basic f e) s \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cpn n \\<Gamma> (Basic f e) s\" and a11:\"c \\<in> assum(p, R)\"\n      then have a10:\"c\\<in>cp \\<Gamma> (Basic f e) s\"\n        using cp_def cpn_def cptn_if_cptn_mod cptn_mod_nest_cptn_mod by blast\n      have \"c\\<in>comm(G, (q,a)) F\" using Basic_sound1[OF a0 a1 a2 a3 a10 a11] by auto      \n    } thus ?thesis by auto\n    qed \n  } \n  thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def) \nqed\n\nsubsection {* Spec Sound *}\n\nlemma spec_skip:\n   \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Spec r e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> c1=Skip\"\nproof -\n  {fix s1 s2 c1\n   assume \"\\<Gamma>\\<turnstile>\\<^sub>c(Spec r e,s1)  \\<rightarrow> ((c1,s2))\"     \n   then have \"c1=Skip\" using stepc_elim_cases(4) by force    \n  } thus ?thesis by auto \nqed  \n\n\nlemma no_comp_tran_before_i_spec:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Spec r e\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"k\\<le>j \\<and> j < i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\" and\n         a4: \"\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))\" and\n         a5: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc j) \\<in> Normal ` q\" \n   shows \"P\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Spec r e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  spec_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 a4 a5 no_comp_tran_before_i by blast\nqed\n\nlemma only_one_component_tran_i_spec:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Spec r e\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"k\\<le>j \\<and> j \\<noteq> i \\<and> Suc j < length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> fst (l!j) =  Spec r e\" and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc j) \\<in> Normal ` q\"     \n   shows \"P\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Spec r e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  spec_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 a4 only_one_component_tran_i[OF a0 a1 a2 ] by blast\nqed   \n\nlemma only_one_component_tran_spec:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Spec r e\" and         \n         a2: \"k\\<le>i  \\<and> i \\<noteq> j \\<and> Suc i<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i))) \\<and> fst (l!i) =  Spec r e\" and\n         a3: \"k\\<le>j  \\<and> Suc j < length l\" and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q\"       \n   shows \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Spec r e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  spec_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 a4 only_one_component_tran by blast\nqed   \n\nlemma only_one_component_tran_all_env_spec:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Spec r e\" and         \n         a2: \"k\\<le>i \\<and> Suc i<length l \\<and>(\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))  \\<and> fst (l!i) =  Spec r e\" and         \n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q\"       \n   shows \"\\<forall>j. k\\<le>j \\<and> j\\<noteq>i \\<and> Suc j < (length l) \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Spec r e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  spec_skip by blast\n  thus ?thesis by (metis (no_types) a0 a1 a2 a3 only_one_component_tran_spec) \nqed   \n\nlemma only_one_component_tran_all_not_comp_spec:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Spec r e\" and         \n         a2: \"k\\<le>i \\<and> Suc i<length l \\<and>(\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))  \\<and> fst (l!i) =  Spec r e\" and         \n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q\"       \n   shows \"\\<forall>j. k\\<le>j \\<and> j\\<noteq>i \\<and> Suc j < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Spec r e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  spec_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 only_one_component_tran_all_not_comp by blast\nqed   \n\nlemma one_component_tran_spec:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!0) = Spec r e\" and         \n         a2: \"Suc k<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\" and\n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely\" and\n         a4:\"p \\<subseteq> {s. (\\<forall>t. (s,t)\\<in>r \\<longrightarrow> t \\<in> q) \\<and> (\\<exists>t. (s,t) \\<in> r)}\"\n           \n  shows \"\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Spec r e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  spec_skip by blast\n  also obtain j where first:\"(Suc j<length l \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!Suc j))) \\<and> \n                 (\\<forall>k < j. \\<not>((\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))))\"\n    by (metis (no_types) a2 exist_first_comp_tran')\n  moreover then have prg_j:\"fst (l!j) = Spec r e\" using a1 a0\n   by (metis cptn_env_same_prog not_step_comp_step_env)\n  moreover have sta_j:\"snd (l!j) \\<in> Normal ` p\"\n  proof -\n    have a0':\"0\\<le>j \\<and> j<(length l)\" using first by auto\n    have a1':\"(\\<forall>k. 0\\<le>k \\<and> k < j \\<longrightarrow> ((\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))))\" \n      using first not_step_comp_step_env a0 by fastforce   \n    thus ?thesis using stability first a3 a1'  a0' by blast \n  qed \n  then have \"snd (l!Suc j) \\<in> Normal ` q\" using a4 first prg_j\n  proof -\n    obtain s where s:\"snd (l!j) = Normal s \\<and> s\\<in>p\" using sta_j by fastforce       \n    then have suc_skip: \"fst (l!Suc j) = Skip\"\n      using spec_skip first prg_j a4 by (metis (no_types, lifting) prod.collapse)\n    moreover obtain s' where  \"snd (l!Suc j) = Normal s' \\<and> (s,s')\\<in>r\" \n      proof -\n      { have f1:\"(\\<Gamma>\\<turnstile>\\<^sub>c(fst(l!j),snd(l!j))  \\<rightarrow> (fst(l!Suc j),snd(l!Suc j)))\" using first by auto\n        obtain t where \"snd (l!Suc j) = Normal t\"\n        using step_spec_skip_normal_normal[of \\<Gamma> \"fst(l!j)\" \"snd(l!j)\" \"fst(l!Suc j)\" \"snd(l!Suc j)\" r] \n         suc_skip prg_j s a4 f1 by blast\n        moreover then have \"(s,t)\\<in>r\" using a4 s prg_j f1 suc_skip stepc_Normal_elim_cases(4)\n          by (metis (no_types, lifting)  stepc_Normal_elim_cases(4) prod.inject xstate.distinct(5) xstate.inject(1))\n        ultimately have \"\\<exists>t. snd (l!Suc j)= Normal t  \\<and> (s,t)\\<in>r\" by auto\n      }\n      then show \"(\\<And>s'. snd (l ! Suc j) = Normal s' \\<and> (s, s') \\<in> r \\<Longrightarrow> thesis) \\<Longrightarrow> thesis\" ..\n    qed             \n    then show ?thesis using a4 sta_j s by auto\n  qed\n  then have \"\\<forall>i. 0\\<le>i \\<and> i\\<noteq>j \\<and> Suc i < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\"\n    using only_one_component_tran_all_not_comp_spec[OF a0 a1] first a3 \n          a0 a1 calculation(1) only_one_component_tran1 prg_j by blast\n  moreover then have \"k=j\" using a2 by fastforce\n  ultimately show ?thesis by auto\nqed   \n\nlemma one_component_tran_spec_env:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!0) = Spec r e\" and         \n         a2: \"Suc k<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\" and\n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely\" and\n         a4:\"p \\<subseteq> {s. (\\<forall>t. (s,t)\\<in>r \\<longrightarrow> t \\<in> q) \\<and> (\\<exists>t. (s,t) \\<in> r)}\"           \n  shows \"\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j))\"\nproof - \n  have \"\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> \\<not> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"\n  using one_component_tran_spec[OF a0 a1 a2 a3 a4] by auto\n  thus ?thesis using  a0 \n     by (metis Suc_eq_plus1 cptn_tran_ce_i step_ce_elim_cases)\nqed\n\nlemma final_exist_component_tran_spec:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n          a1: \"fst (l!i) = Spec r e\" and               \n          a2: \"env_tran \\<Gamma> q l R \" and\n          a3: \"i\\<le>j \\<and> j < length l \\<and> final (l!j)\" \n  shows \"\\<exists>k. k\\<ge>i \\<and> k<j \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Spec r e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\" \n    using  spec_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 final_exist_component_tran by blast\nqed   \nlemma Spec_sound1: \n       \"p \\<subseteq> {s. (\\<forall>t. (s,t)\\<in>r \\<longrightarrow> t \\<in> q) \\<and> (\\<exists>t. (s,t) \\<in> r)} \\<Longrightarrow>\n       (\\<forall>s t. s\\<in>p  \\<and> (s,t)\\<in>r \\<longrightarrow> (Normal s, Normal t) \\<in> G) \\<Longrightarrow>       \n       Sta p R \\<Longrightarrow>\n       Sta q R \\<Longrightarrow> \n       c \\<in> cp \\<Gamma> (Spec r e) s \\<Longrightarrow>\n       c \\<in> assum(p, R) \\<Longrightarrow>\n       c \\<in> comm (G, (q,a)) F\"   \nproof -  \n assume\n  a0:\"p \\<subseteq> {s. (\\<forall>t. (s,t)\\<in>r \\<longrightarrow> t \\<in> q) \\<and> (\\<exists>t. (s,t) \\<in> r)}\" and\n  a1:\"(\\<forall>s t. s\\<in>p  \\<and> (s,t)\\<in>r \\<longrightarrow> (Normal s,Normal t) \\<in> G)\" and\n  a2:\"Sta p R\" and\n  a3:\"Sta q R\" and \n  a10:\"c \\<in> cp \\<Gamma> (Spec r e) s\" and\n  a11:\"c \\<in> assum(p, R)\"\n\n  obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n  have cp:\"l!0=(Spec r e,s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\" using a10 cp_def c_prod by fastforce\n   have assum:\"snd(l!0) \\<in> Normal ` (p) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n             (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n               (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n   using a11 c_prod unfolding assum_def by simp\n   have concl:\"(\\<forall>i ns ns'. Suc i<length l \\<longrightarrow> \n           \\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                                       \n             (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n   proof -\n   { fix k\n     assume a00:\"Suc k<length l\" and\n            a11:\"\\<Gamma>1\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"                \n     obtain ck sk csk ssk where tran_pair:\n       \"\\<Gamma>1\\<turnstile>\\<^sub>c (ck,sk)  \\<rightarrow> (csk, ssk) \\<and> (ck = fst (l!k)) \\<and> (sk = snd (l!k)) \\<and> (csk = fst (l!(Suc k))) \\<and> (ssk = snd (l!(Suc k)))\" \n       using a11 by fastforce\n     have len_l:\"length l > 0\" using cp using cptn.simps by blast \n     then obtain a l1 where l:\"l=a#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n     have last_l:\"last l = l!(length l-1)\"\n       using last_length [of a l1] l by fastforce\n     have env_tran:\"env_tran \\<Gamma> p l R\" using assum env_tran_def cp by blast\n     then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n       using env_tran env_tran_right_def unfolding env_tran_def by auto\n     then have all_event:\"\\<forall>j. 0\\<le>j \\<and> j \\<noteq> k \\<and> Suc j < length l \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n       using a00 a11   one_component_tran_spec_env[of \\<Gamma> l r e k R] \n             env_tran_right fst_conv a0 a2 a3 cp len_l assum\n       by fastforce\n     then have before_k_all_evn:\"\\<forall>j. 0\\<le>j \\<and> j < k  \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n           using a00 a11  by fastforce\n     then have k_basic:\"ck = Spec r e \\<and> sk \\<in> Normal ` (p)\" \n       using  cp  env_tran_right a2 assum a00 a11 stability[of p R l 0 k k \\<Gamma>] tran_pair\n       by force\n     have suc_skip: \"csk = Skip\"\n        using a0 a00 k_basic tran_pair spec_skip by blast\n     obtain s' where ss:\"sk = Normal s' \\<and> s' \\<in> (p)\" \n       using k_basic by fastforce\n     obtain s'' where suc_k_skip_q:\"ssk = Normal s'' \\<and> (s',s'')\\<in>r \"           \n     proof -                    \n       {from ss  obtain t where \"ssk = Normal t\" \n         using step_spec_skip_normal_normal[of \\<Gamma>1 ck sk csk ssk r e s'] \n               k_basic tran_pair a0 suc_skip\n         by blast                      \n       moreover then have \"(s',t)\\<in>r\" using a0 k_basic ss a11 suc_skip \n         by (metis (no_types, lifting)  stepc_Normal_elim_cases(4) tran_pair prod.inject xstate.distinct(5) xstate.inject(1))            \n       ultimately have \"\\<exists>t. ssk= Normal t  \\<and> (s',t)\\<in>r\" by auto\n       } \n     then show \"(\\<And>s''. ssk = Normal s''  \\<and> (s',s'')\\<in>r\\<Longrightarrow> thesis) \\<Longrightarrow> thesis\" ..\n     qed                                                                        \n     then have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n       using ss a1 tran_pair   by force\n   } thus ?thesis by auto qed\n   have concr:\"(final (last l)  \\<longrightarrow> ((fst (last l) = Skip \\<and> \n                                              snd (last l) \\<in> Normal ` q)) \\<or>\n                                              (fst (last l) = Throw \\<and> \n                                              snd (last l) \\<in> Normal ` (a)))\"\n   proof-\n   { \n     assume valid:\"final (last l)\"\n     have len_l:\"length l > 0\" using cp using cptn.simps by blast \n     then obtain a l1 where l:\"l=a#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n     have last_l:\"last l = l!(length l-1)\"\n       using last_length [of a l1] l by fastforce\n     have env_tran:\"env_tran \\<Gamma> p l R\" using assum env_tran_def cp by blast\n     then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n       using env_tran env_tran_right_def unfolding env_tran_def by auto\n     have \"\\<exists>k. k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n     proof -             \n       have \"0\\<le> (length l-1)\" using len_l last_l by auto\n       moreover have \"(length l-1) < length l\" using len_l by auto\n       moreover have \"final (l!(length l-1))\" using valid last_l by auto\n       moreover have \"fst (l!0) = Spec r e\" using cp by auto\n       ultimately show ?thesis \n         using cp final_exist_component_tran_spec env_tran  by blast \n     qed\n     then obtain k  where k_comp_tran: \"k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n       by auto\n     then obtain ck sk csk ssk where tran_pair:\n       \"\\<Gamma>1\\<turnstile>\\<^sub>c (ck,sk)  \\<rightarrow> (csk, ssk) \\<and> (ck = fst (l!k)) \\<and> (sk = snd (l!k)) \\<and> (csk = fst (l!(Suc k))) \\<and> (ssk = snd (l!(Suc k)))\" \n       using cp by fastforce\n     moreover then have \"Suc k < length l\" using k_comp_tran by auto\n     ultimately have all_event:\"\\<forall>j. 0\\<le>j \\<and> j \\<noteq> k \\<and> Suc j < length l \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n       using one_component_tran_spec_env[of \\<Gamma> l r e k R] a0  a11 a2 a3 assum cp \n             env_tran_right fst_conv            \n       by fastforce\n     then have before_k_all_evn:\"\\<forall>j. 0\\<le>j \\<and> j < k  \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n           using k_comp_tran by fastforce\n     then have k_basic:\"ck = Spec r e \\<and> sk \\<in> Normal ` (p)\" \n       using cp env_tran_right a2 assum tran_pair k_comp_tran stability[of p R l 0 k k \\<Gamma>] tran_pair\n       by force\n     have suc_skip: \"csk = Skip\"\n        using a0  k_basic tran_pair spec_skip by blast\n     have suc_k_skip_q:\"ssk \\<in> Normal ` q\"           \n     proof -         \n       obtain s' where k_s: \"sk =Normal s' \\<and> s' \\<in> (p)\" \n         using k_basic by auto\n       then obtain t where \"ssk = Normal t\" \n       using step_spec_skip_normal_normal[of \\<Gamma>1 ck sk csk ssk r] k_basic tran_pair a0 suc_skip\n       by blast           \n       then obtain t where \"ssk= Normal t\" by fastforce\n       then have \"(s',t)\\<in>r\" using  k_basic k_s a11 suc_skip \n         by (metis (no_types, lifting)  stepc_Normal_elim_cases(4) tran_pair prod.inject xstate.distinct(5) xstate.inject(1))\n       thus \"ssk \\<in> Normal ` q\"  using a0 k_s `ssk = Normal t` by blast \n     qed    \n     have after_k_all_evn:\"\\<forall>j. (Suc k)\\<le>j \\<and> Suc j < (length l)  \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n           using all_event k_comp_tran by fastforce                            \n     then have fst_last_skip:\"fst (last l) = Skip \\<and> \n                         snd ((last l)) \\<in> Normal ` q\"\n     using l tran_pair suc_skip last_l len_l cp \n           env_tran_right a3 suc_k_skip_q \n           assum k_comp_tran stability [of q R l \"Suc k\" \"((length l) - 1)\" _ \\<Gamma>] \n     by (metis One_nat_def Suc_eq_plus1 Suc_leI Suc_mono diff_Suc_1 lessI list.size(4))                  \n   } thus ?thesis by auto qed\n   note res = conjI [OF concl concr]                           \n   thus ?thesis using c_prod unfolding comm_def by auto \n qed\n \nlemma Spec_sound: \n       \"p \\<subseteq> {s. (\\<forall>t. (s,t)\\<in>r \\<longrightarrow> t \\<in> q) \\<and> (\\<exists>t. (s,t) \\<in> r)} \\<Longrightarrow>\n       (\\<forall>s t. s\\<in>p  \\<and> (s,t)\\<in>r \\<longrightarrow> (Normal s, Normal t) \\<in> G) \\<Longrightarrow>       \n       Sta p R \\<Longrightarrow>\n       Sta q R \\<Longrightarrow>    \n       \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub>  (Spec r e) sat [p, R, G, q,a]\"\nproof -  \n assume\n    a0:\"p \\<subseteq> {s. (\\<forall>t. (s,t)\\<in>r \\<longrightarrow> t \\<in> q) \\<and> (\\<exists>t. (s,t) \\<in> r)}\" and\n    a1:\"(\\<forall>s t. s\\<in>p  \\<and> (s,t)\\<in>r \\<longrightarrow> (Normal s,Normal t) \\<in> G)\" and\n    a2:\"Sta p R\" and\n    a3:\"Sta q R\" \n{\n    fix s\n    have \"cpn n \\<Gamma> (Spec r e) s \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cpn n \\<Gamma> (Spec r e) s\" and a11:\"c \\<in> assum(p, R)\"\n      then have a10:\"c\\<in>cp \\<Gamma> (Spec r e) s\"\n        using cp_def cpn_def cptn_if_cptn_mod cptn_mod_nest_cptn_mod by blast\n      have \"c\\<in>comm(G, (q,a)) F\" using Spec_sound1[OF a0 a1 a2 a3 a10 a11] by auto      \n    } thus ?thesis by auto\n    qed \n  } \n  thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def) \nqed\n\nsubsection {* Await Sound *}\n\nlemma await_skip:\n   \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Await b c e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> c1=Skip \\<or> (c1 = Throw \\<and> (\\<exists>s21. s2 =Normal s21 ))\"\nproof -\n  {fix s1 s2 c1\n   assume \"\\<Gamma>\\<turnstile>\\<^sub>c(Await b c e,s1)  \\<rightarrow> ((c1,s2))\"     \n   then have \"c1=Skip \\<or>  (c1 = Throw \\<and> (\\<exists>s21. s2 =Normal s21 ))\" using stepc_elim_cases(8) by blast    \n  } thus ?thesis by auto \nqed  \n\nlemma no_comp_tran_before_i_await:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Await b c e\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"k\\<le>j \\<and> j < i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\" and\n         a4: \"\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))\" and\n         a5: \"env_tran_right \\<Gamma> l rely  \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                         Sta q rely \\<and> snd (l!Suc j) \\<in> Normal ` q\"\n   shows \"P\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Await b c e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow>  c1=Skip \\<or> (c1 = Throw \\<and> (\\<exists>s21. s2 =Normal s21 ))\" \n    using  await_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 a4 a5 no_comp_tran_before_i by blast\nqed\n\nlemma only_one_component_tran_i_await:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Await b c e\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\" and\n         a3: \"k\\<le>j \\<and> j \\<noteq> i \\<and> Suc j < length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> fst (l!j) = Await b c e\" and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and> snd (l!Suc j) \\<in> Normal ` q\" \n   shows \"P\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Await b c e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\\<or>(c1 = Throw \\<and> (\\<exists>s21. s2 =Normal s21 ))\" \n    using  await_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 a4 only_one_component_tran_i by blast\nqed   \n\nlemma only_one_component_tran_await:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Await b c e\" and         \n         a2: \" k\\<le>i \\<and> i \\<noteq> j \\<and>  Suc i<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i))) \\<and> fst (l!i) = Await b c e\" and\n         a3: \"k\\<le>j  \\<and> Suc j < length l\" and\n         a4: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                       Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q\"     \n   shows \"(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Await b c e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\\<or>(c1 = Throw \\<and> (\\<exists>s21. s2 =Normal s21 ))\" \n    using  await_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 a4 only_one_component_tran by blast\nqed   \n\nlemma only_one_component_tran_all_env_await:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Await b c e\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))  \\<and> fst (l!i) = Await b c e\" and         \n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                       Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q\"       \n   shows \"\\<forall>j. k\\<le>j \\<and> j\\<noteq>i \\<and> Suc j < (length l) \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\nproof -\n  have  a:\"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Await b c e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\\<or>(c1 = Throw)\" \n    using  await_skip by blast\n  thus ?thesis by (metis (no_types) a0 a1 a2 a3 only_one_component_tran_await)\nqed\n   \n\nlemma only_one_component_tran_all_not_comp_await:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!k) = Await b c e\" and         \n         a2: \"Suc i<length l \\<and> k\\<le>i \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))  \\<and> fst (l!i) = Await b c e\" and         \n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!k) \\<in> Normal ` p \\<and> \n                                       Sta q rely \\<and> snd (l!Suc i) \\<in> Normal ` q\" \n   shows \"\\<forall>j. k\\<le>j \\<and> j\\<noteq>i \\<and> Suc j < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Await b c e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\\<or>(c1 = Throw \\<and> (\\<exists>s21. s2 =Normal s21 ))\" \n    using  await_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 only_one_component_tran_all_not_comp by blast\nqed   \n\nlemma one_component_tran_await:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!0) = Await b c e\" and         \n         a2: \"Suc k<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\" and\n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and>\n                                        Sta a rely\" and\n         a4:\"\\<forall>V. \\<Gamma>\\<^sub>\\<not>\\<^sub>a,{}\\<turnstile>\\<^bsub>/F\\<^esub> \n             (p \\<inter> b \\<inter> {V}) c\n             ({s. (Normal V, Normal s) \\<in> G} \\<inter> q),\n             ({s. (Normal V, Normal s) \\<in> G} \\<inter> a)\" and\n         a5:\"snd (last l) \\<notin> Fault ` F\"\n           \n  shows \"(\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))) \\<and>\n         (\\<exists>s s'. fst (l!k) = Await b c e \\<and> snd (l!k) \\<in> Normal ` (p) \\<and> snd (l!k) = Normal s \\<and> snd (l!Suc k) = Normal s' \\<and> \n            (snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> q) \\<or> \n             snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> a)))\"\nproof -\n  have  suc_skip:\"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Await b c e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\\<or> (c1=Throw \\<and> (\\<exists>s21. s2 =Normal s21 ))\" \n    using  await_skip by blast\n  also obtain j where first:\"(Suc j<length l \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))) \\<and> \n                 (\\<forall>k < j. \\<not>((\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))))\"\n    by (metis (no_types) a2 exist_first_comp_tran')\n  moreover then have prg_j:\"fst (l!j) = Await b c e\" using a1 a0\n   by (metis cptn_env_same_prog not_step_comp_step_env)\n  moreover have sta_j:\"snd (l!j) \\<in> Normal ` p\"\n  proof -\n    have a0':\"0\\<le>j \\<and> j<(length l)\" using first by auto\n    have a1':\"(\\<forall>k. 0\\<le>k \\<and> k < j \\<longrightarrow> ((\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k)))))\" \n      using first not_step_comp_step_env a0 by fastforce   \n    thus ?thesis using stability first a3 a1'  a0' by blast \n  qed \n  from sta_j obtain s where \n      k_basic:\"fst (l!j) = Await b c e \\<and> snd (l!j) = Normal s \\<and>  s \\<in> p \\<and> snd(l!j) \\<in> Normal ` p\" \n      using sta_j prg_j by fastforce\n  then have conc:\"snd (l!Suc j) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> q) \\<or> \n             snd (l!Suc j) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> a)\" \n  proof -    \n    have \"\\<Gamma>\\<^sub>\\<not>\\<^sub>a,{}\\<Turnstile>\\<^bsub>/F\\<^esub> \n                     (p \\<inter> b \\<inter> {s}) c \n                     ({s'. (Normal s, Normal s') \\<in> G} \\<inter> q),\n                     ({s'. (Normal s, Normal s') \\<in> G} \\<inter> a)\"\n      using  a4 hoare_sound by fastforce\n    then have e_auto:\"\\<Gamma>\\<^sub>\\<not>\\<^sub>a\\<Turnstile>\\<^bsub>/F\\<^esub> (p \\<inter> b \\<inter> {s}) c \n                     ({s'. (Normal s, Normal s') \\<in> G} \\<inter> q),\n                     ({s'. (Normal s, Normal s') \\<in> G} \\<inter> a)\" \n      unfolding cvalid_def by auto    \n    have f': \"\\<Gamma>\\<turnstile>\\<^sub>c(fst (l!j), snd(l!j))  \\<rightarrow> (fst(l!(Suc j)), snd(l!(Suc j)))\"      \n      using first by auto\n    have step_await:\"Suc j<length l \\<and> \\<Gamma>\\<turnstile>\\<^sub>c (Await b c e,snd(l!j))  \\<rightarrow> (fst(l!(Suc j)), snd(l!(Suc j)))\"\n             using f' k_basic first by fastforce           \n    then have s'_in_bp:\"s\\<in> b \\<and> s \\<in> p\"  using k_basic stepc_Normal_elim_cases(8) by metis\n    then have \"s \\<in> (p \\<inter> b)\"  by fastforce\n    moreover have test:\n      \"\\<exists>t. \\<Gamma>\\<^sub>\\<not>\\<^sub>a\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> t \\<and> \n       ((\\<exists>t'. t =Abrupt t' \\<and> snd(l!Suc j) = Normal t') \\<or>\n       (\\<forall>t'. t \\<noteq> Abrupt t' \\<and> snd(l!Suc j)=t))\"\n    proof -\n      fix t \n      { assume \"fst(l!Suc j) = Skip\"\n        then have step:\"\\<Gamma>\\<turnstile>\\<^sub>c (Await b c e,Normal s)  \\<rightarrow> (Skip, snd(l!Suc j))\"\n          using step_await k_basic by fastforce\n        have s'_b:\"s\\<in>b\" using s'_in_bp by fastforce\n        note step = stepc_elim_cases_Await_skip[OF step]\n        have h:\"(s \\<in> b \\<Longrightarrow> \\<Gamma>\\<^sub>\\<not>\\<^sub>a\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> snd(l!Suc j) \\<Longrightarrow> \\<forall>t'. snd(l!Suc j) \\<noteq> Abrupt t' \\<Longrightarrow>\n              \\<Gamma>\\<^sub>\\<not>\\<^sub>a\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> snd(l!Suc j) \\<and> (\\<forall>t'. snd(l!Suc j) \\<noteq> Abrupt t'))\" by auto\n        have ?thesis \n          using step[OF h] by fastforce\n      } note left = this\n      { assume \"fst(l!Suc j)= Throw \\<and> (\\<exists>s1. snd(l!Suc j) = Normal s1)\"\n        then obtain s1 where step:\"fst(l!Suc j)= Throw \\<and> snd(l!Suc j) = Normal s1\"\n          by fastforce\n        then have step: \"\\<Gamma>\\<turnstile>\\<^sub>c (Await b c e,Normal s)  \\<rightarrow> (Throw, snd(l!Suc j))\"\n          using step_await k_basic by fastforce\n        have s'_b:\"s\\<in>b\" using s'_in_bp by fastforce\n        note step = stepc_elim_cases_Await_throw[OF step]\n        have h:\"(\\<And>t'. snd(l!Suc j) = Normal t' \\<Longrightarrow> s \\<in> b \\<Longrightarrow> \\<Gamma>\\<^sub>\\<not>\\<^sub>a\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> Abrupt t' \\<Longrightarrow> \n                \\<Gamma>\\<^sub>\\<not>\\<^sub>a\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> Abrupt t' \\<and>  snd(l!Suc j) = Normal t')\"\n        by auto                \n        have ?thesis using step[OF h] by blast \n      } thus ?thesis using suc_skip  left  step_await suc_skip by blast \n    qed\n    then obtain t where e_step:\"\\<Gamma>\\<^sub>\\<not>\\<^sub>a\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> t \\<and> \n             ((\\<exists>t'. t =Abrupt t' \\<and> snd(l!Suc j) = Normal t') \\<or>\n             (\\<forall>t'. t \\<noteq> Abrupt t' \\<and> snd(l!Suc j)=t)) \" by fastforce\n    moreover have \"t \\<notin> Fault ` F\" \n    proof -           \n       {assume a10:\"t \\<in> Fault ` F\"\n       then obtain tf where \"t=Fault tf \\<and> tf\\<in>F\" by fastforce\n       then have \"snd(l!Suc j) = Fault tf \\<and> tf\\<in>F\" using e_step by fastforce\n       also have \"snd(l!Suc j) \\<notin> Fault  ` F\" \n         using last_not_F[of \\<Gamma> l F] a5 a1 step_await a0 by blast\n       ultimately have False by auto\n       } thus ?thesis by auto\n    qed\n    ultimately have t_q_a:\"t \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter>q) \\<union> \n                              Abrupt ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> a)\" \n      using e_auto unfolding valid_def by fastforce\n    thus ?thesis using e_step t_q_a  by blast                                                                       \n  qed       \n  then have \"\\<forall>i. 0\\<le>i \\<and> i\\<noteq>j \\<and> Suc i < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\"\n    using only_one_component_tran_all_not_comp_await[OF a0 a1] first a3 \n          a0 a1 calculation(1) only_one_component_tran1 prg_j by blast \n  moreover then have k:\"k=j\" using a2 by fastforce\n  ultimately have \"(\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))))\" by auto \n  also from conc k k_basic have \n     \"(\\<exists>s s'. fst (l!k) = Await b c e \\<and> snd (l!k) \\<in> Normal ` (p) \\<and> snd (l!k) = Normal s \\<and> snd (l!Suc k) = Normal s' \\<and> \n            (snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> q) \\<or> \n             snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> a)))\"\n     by fastforce\n  ultimately show ?thesis by auto\nqed \n\nlemma one_component_tran_await_env:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n         a1: \"fst (l!0) = Await b c e\" and         \n         a2: \"Suc k<length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\" and\n         a3: \"env_tran_right \\<Gamma> l rely \\<and> Sta p rely \\<and> snd (l!0) \\<in> Normal ` p \\<and> \n                                        Sta q rely \\<and>\n                                        Sta a rely\" and\n         a4:\"\\<forall>V. \\<Gamma>\\<^sub>\\<not>\\<^sub>a,{}\\<turnstile>\\<^bsub>/F\\<^esub> \n             (p \\<inter> b \\<inter> {V}) c\n             ({s. (Normal V, Normal s) \\<in> G} \\<inter> q),\n             ({s. (Normal V, Normal s) \\<in> G} \\<inter> a)\" and\n         a5:\"snd (last l) \\<notin> Fault ` F\"           \n  shows \"(\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))) \\<and> \n           (\\<exists>s s'. fst (l!k) = Await b c e \\<and> snd (l!k) \\<in> Normal ` (p) \\<and> \n                 snd (l!k) = Normal s \\<and> snd (l!Suc k) = Normal s' \\<and> \n                  (snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> q) \\<or> \n                   snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> a)))\"  \nproof - \n  have \"(\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> \\<not> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j)))) \\<and> \n        (\\<exists>s s'. fst (l!k) = Await b c e \\<and> snd (l!k) \\<in> Normal ` (p) \\<and> \n                snd (l!k) = Normal s \\<and> snd (l!Suc k) = Normal s' \\<and> \n                  (snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> q) \\<or> \n                   snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> a)))\"\n  using one_component_tran_await[OF a0 a1 a2 a3 a4 a5] by auto\n  thus ?thesis using  a0\n  by (metis Suc_eq_plus1 cptn_tran_ce_i step_ce_elim_cases)    \nqed\n\nlemma final_exist_component_tran_await:\n  assumes a0:\"(\\<Gamma>, l) \\<in> cptn\" and\n          a1: \"fst (l!i) = Await b c e\" and               \n          a2: \"env_tran \\<Gamma> q l R \" and\n          a3: \"i\\<le>j \\<and> j < length l \\<and> final (l!j)\" \n  shows \"\\<exists>k. k\\<ge>i \\<and> k<j \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\nproof -\n  have  \"\\<forall>s1 s2 c1. \\<Gamma>\\<turnstile>\\<^sub>c(Await b c e,s1)  \\<rightarrow> ((c1,s2)) \\<longrightarrow> (c1=Skip)\\<or>(c1 = Throw \\<and> (\\<exists>s21. s2 =Normal s21 ))\" \n    using  await_skip by blast\n  thus ?thesis using  a0 a1 a2 a3 final_exist_component_tran by blast\nqed   \n\ninductive_cases stepc_elim_cases_Await_Fault:\n\"\\<Gamma>\\<turnstile>\\<^sub>c (Await b c e, Normal s) \\<rightarrow> (u,Fault f)\"\n\nlemma Await_sound1: \n \"\\<forall>V. \\<Gamma>\\<^sub>\\<not>\\<^sub>a,{}\\<turnstile>\\<^bsub>/F\\<^esub> \n    (p \\<inter> b \\<inter> {V}) e \n    ({s. (Normal V, Normal s) \\<in> G} \\<inter> q),\n    ({s. (Normal V, Normal s) \\<in> G} \\<inter> a) \\<Longrightarrow>     \n Sta p R \\<Longrightarrow> Sta q R \\<Longrightarrow> Sta a R \\<Longrightarrow>   \n c \\<in> cp \\<Gamma> (Await b e e1) s \\<Longrightarrow>\n c \\<in> assum(p, R) \\<Longrightarrow>\n c \\<in> comm (G, (q,a)) F\"\nproof -  \n assume\n  a0: \"\\<forall>V. \\<Gamma>\\<^sub>\\<not>\\<^sub>a,{}\\<turnstile>\\<^bsub>/F\\<^esub> \n        (p \\<inter> b \\<inter> {V}) e \n        ({s. (Normal V, Normal s) \\<in> G} \\<inter> q),\n        ({s. (Normal V, Normal s) \\<in> G} \\<inter> a)\" and\n  a2:\"Sta p R\" and\n  a3:\"Sta q R\" and\n  a4:\"Sta a R\" and \n  a10:\"c \\<in> cp \\<Gamma> (Await b e e1) s\" and\n  a11:\"c \\<in> assum(p, R)\"\n\n  obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n  {assume last_fault:\"snd (last l) \\<notin> Fault ` F\"\n   have cp:\"l!0=(Await b e e1,s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\" using a10 cp_def c_prod by fastforce\n   have assum:\"snd(l!0) \\<in> Normal ` (p) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n             (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n               (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n   using a11 c_prod unfolding assum_def by simp\n   have concl:\"(\\<forall>i ns ns'. Suc i<length l \\<longrightarrow> \n           \\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                              \n             (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n   proof -\n   { fix k ns ns'\n     assume a00:\"Suc k<length l\" and\n            a11:\"\\<Gamma>1\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"                \n     have len_l:\"length l > 0\" using cp using cptn.simps by blast \n     then obtain a1 l1 where l:\"l=a1#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n     have env_tran:\"env_tran \\<Gamma> p l R\" using assum env_tran_def cp by blast\n     then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n       using env_tran env_tran_right_def unfolding env_tran_def by auto\n     then have all_event:\n          \"(\\<exists>s s'. fst (l!k) = Await b e e1 \\<and> snd (l!k) \\<in> Normal ` (p) \\<and> snd (l!k) = \n                   Normal s \\<and> snd (l!Suc k) = Normal s' \\<and> \n                  (snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> q) \\<or> \n                   snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> a)))\"\n       using a00 a11  one_component_tran_await_env[of \\<Gamma> l b e e1 k R p q a F G] env_tran_right cp len_l\n       using a0 a2 a3 a4 assum fst_conv last_fault by auto                                                                          \n     then obtain s' s'' where ss:\n       \"snd (l!k) = Normal s' \\<and> s' \\<in> (p) \\<and>  snd (l!Suc k) = Normal s'' \n        \\<and> (s'' \\<in> (({s. (Normal s', Normal s) \\<in> G} \\<inter> q)) \\<or> \n           s''\\<in> (({s. (Normal s', Normal s) \\<in> G} \\<inter> a)))\"\n     by fastforce \n     then have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n       using a2  by force\n   } thus ?thesis using c_prod by auto qed  \n   have concr:\"(final (last l)  \\<longrightarrow>                    \n               ((fst (last l) = Skip \\<and> \n                snd (last l) \\<in> Normal ` q)) \\<or>\n                (fst (last l) = Throw \\<and> \n                snd (last l) \\<in> Normal ` (a)))\"\n   proof-\n   { \n     assume valid:\"final (last l)\"         \n     have len_l:\"length l > 0\" using cp using cptn.simps by blast \n     then obtain a1 l1 where l:\"l=a1#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n     have last_l:\"last l = l!(length l-1)\"\n       using last_length [of a1 l1] l by fastforce\n     have env_tran:\"env_tran \\<Gamma> p l R\" using assum env_tran_def cp by blast\n     then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n       using env_tran env_tran_right_def unfolding env_tran_def by auto\n     have \"\\<exists>k. k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n     proof -             \n       have \"0\\<le> (length l-1)\" using len_l last_l by auto\n       moreover have \"(length l-1) < length l\" using len_l by auto\n       moreover have \"final (l!(length l-1))\" using valid last_l by auto\n       moreover have \"fst (l!0) = Await b e e1\" using cp by auto\n       ultimately show ?thesis \n         using  cp final_exist_component_tran_await env_tran by blast \n     qed\n     then obtain k  where k_comp_tran: \"k\\<ge>0 \\<and> Suc k < length l \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n       by fastforce\n     then obtain ck sk csk ssk where tran_pair:\n       \"\\<Gamma>1\\<turnstile>\\<^sub>c (ck,sk)  \\<rightarrow> (csk, ssk) \\<and> (ck = fst (l!k)) \\<and> (sk = snd (l!k)) \\<and> (csk = fst (l!(Suc k))) \\<and> (ssk = snd (l!(Suc k)))\" \n       using cp by fastforce         \n     have all_event:\n          \"(\\<forall>j. 0\\<le>j \\<and> j\\<noteq>k \\<and> Suc j < (length l) \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))) \\<and>\n           (\\<exists>s s'. fst (l!k) = Await b e e1 \\<and> snd (l!k) \\<in> Normal ` (p) \\<and> snd (l!k) = \n                   Normal s \\<and> snd (l!Suc k) = Normal s' \\<and> \n                  (snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> q) \\<or> \n                   snd (l!Suc k) \\<in> Normal ` ({s'. (Normal s, Normal s') \\<in> G} \\<inter> a)))\"\n       using  one_component_tran_await_env[of \\<Gamma> l b e e1 k R p q a F G] a0 a11 a2 a3 a4 assum cp \n              env_tran_right  len_l  fst_conv last_fault k_comp_tran  by fastforce\n     then have before_k_all_evn:\"\\<forall>j. 0\\<le>j \\<and> j < k  \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n           using k_comp_tran by fastforce\n     then obtain s' where k_basic:\"ck = Await b e e1 \\<and> sk \\<in> Normal ` (p) \\<and> sk = Normal s'\" \n       using cp env_tran_right a2 assum tran_pair k_comp_tran stability[of p R l 0 k k \\<Gamma>] tran_pair\n       by force        \n     have \"\\<Gamma>\\<^sub>\\<not>\\<^sub>a,{}\\<Turnstile>\\<^bsub>/F\\<^esub> \n                 (p \\<inter> b \\<inter> {s'}) e \n                 ({s. (Normal s', Normal s) \\<in> G} \\<inter> q),\n                 ({s. (Normal s', Normal s) \\<in> G} \\<inter> a)\"\n       using  a0 hoare_sound k_basic\n         by fastforce\n       then have e_auto:\"\\<Gamma>\\<^sub>\\<not>\\<^sub>a\\<Turnstile>\\<^bsub>/F\\<^esub> (p \\<inter> b \\<inter> {s'}) e \n                 ({s. (Normal s', Normal s) \\<in> G} \\<inter> q),\n                 ({s. (Normal s', Normal s) \\<in> G} \\<inter> a)\" \n         unfolding cvalid_def by auto   \n     have after_k_all_evn:\"\\<forall>j. (Suc k)\\<le>j \\<and> Suc j < (length l)  \\<longrightarrow> (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)))\"\n           using all_event k_comp_tran by fastforce          \n     have suc_skip: \"csk = Skip  \\<or> (csk = Throw \\<and> (\\<exists>s1. ssk = Normal s1))\"\n        using a0  k_basic tran_pair await_skip by blast\n     moreover {\n       assume at:\"csk = Skip\" \n       then have atom_tran:\"\\<Gamma>\\<^sub>\\<not>\\<^sub>a\\<turnstile>\\<langle>e,sk\\<rangle> \\<Rightarrow> ssk\"\n           using k_basic tran_pair k_basic cp stepc_elim_cases_Await_skip\n           by metis\n       have sk_in_normal_pb:\"sk \\<in> Normal ` (p \\<inter> b)\" \n         using k_basic tran_pair at cp stepc_elim_cases_Await_skip\n          by (metis (no_types, lifting) IntI image_iff)                                  \n       then have \"fst (last l) = Skip \\<and> \n                   snd ((last l)) \\<in> Normal ` q\" \n       proof (cases ssk)\n         case (Normal t)                                                  \n         then have \"ssk \\<in> Normal ` q\" \n           using sk_in_normal_pb k_basic e_auto Normal atom_tran unfolding valid_def\n           by blast\n         thus ?thesis\n           using at l tran_pair last_l len_l cp \n             env_tran_right a3  after_k_all_evn \n             assum k_comp_tran stability [of q R l \"Suc k\" \"((length l) - 1)\" _ \\<Gamma>]\n           by (metis (no_types, hide_lams) Suc_leI diff_Suc_eq_diff_pred diff_less less_one zero_less_diff)         \n       next\n          case (Abrupt t)\n          thus ?thesis \n           using at k_basic tran_pair k_basic cp stepc_elim_cases_Await_skip\n             by metis                \n       next\n          case (Fault f1)              \n          then have \"ssk \\<in> Normal ` q \\<or> ssk \\<in> Fault ` F\" \n            using k_basic sk_in_normal_pb e_auto Fault atom_tran unfolding valid_def by auto                          \n          thus ?thesis\n          proof\n            assume \"ssk \\<in> Normal ` q\" thus ?thesis using Fault by auto\n          next\n            assume suck_fault:\"ssk \\<in> Fault ` F\"\n            have \"\\<forall>i<length l. snd (l ! i) \\<notin> Fault ` F\" \n               using last_not_F[of \\<Gamma> l F] last_fault cp by auto\n            thus ?thesis \n               using cp tran_pair a11 k_comp_tran suck_fault\n               by (meson diff_less len_l less_imp_Suc_add less_one less_trans_Suc)                  \n          qed\n       next \n          case (Stuck)             \n          then have \"ssk \\<in> Normal ` q\" \n           using k_basic sk_in_normal_pb e_auto Stuck atom_tran unfolding valid_def\n           by blast\n          thus ?thesis using Stuck by auto                             \n       qed            \n     }\n     moreover {\n       assume at:\"(csk = Throw \\<and> (\\<exists>t. ssk = Normal t))\"\n       then obtain t where ssk_normal:\"ssk=Normal t\" by auto\n       then have atom_tran:\"\\<Gamma>\\<^sub>\\<not>\\<^sub>a\\<turnstile>\\<langle>e,sk\\<rangle> \\<Rightarrow> Abrupt t\"\n           using at k_basic tran_pair k_basic ssk_normal cp stepc_elim_cases_Await_throw xstate.inject(1)\n           by metis                        \n       also have \"sk \\<in> Normal ` (p \\<inter> b)\" \n           using k_basic tran_pair k_basic ssk_normal at cp stepc_elim_cases_Await_throw\n           by (metis (no_types, lifting) IntI imageE image_eqI stepc_elim_cases_Await_throw)               \n       then have \"ssk \\<in> Normal ` a\" \n         using e_auto k_basic ssk_normal atom_tran unfolding valid_def\n         by blast\n       then have \"(fst (last l) = Throw \\<and> snd (last l) \\<in> Normal ` (a))\"\n       using at l tran_pair last_l len_l cp \n           env_tran_right a4  after_k_all_evn\n           assum k_comp_tran stability [of a R l \"Suc k\" \"((length l) - 1)\" _ \\<Gamma>]        \n       by (metis (no_types, hide_lams) Suc_leI diff_Suc_eq_diff_pred diff_less less_one zero_less_diff)                    \n     }\n     ultimately have \"fst (last l) = Skip \\<and> \n                         snd ((last l)) \\<in> Normal ` q \\<or>\n                        (fst (last l) = Throw \\<and> snd (last l) \\<in> Normal ` (a))\"\n     by blast                     \n   } thus ?thesis by auto qed\n   note res = conjI [OF concl concr]               \n  }              \n  thus ?thesis using c_prod unfolding comm_def by auto \nqed \nsubsection {* If sound *}\n\nlemma cptn_assum_induct:\nassumes\n  a0: \"(\\<Gamma>,l) \\<in> (cp \\<Gamma> c s) \\<and> ((\\<Gamma>,l) \\<in> assum(p, R))\" and\n  a1: \"k < length l \\<and> l!k=(c1,Normal s') \\<and> s' \\<in> p1\"\nshows \"(\\<Gamma>,drop k l)\\<in> ((cp \\<Gamma> c1 (Normal s')) \\<inter> assum(p1, R) )\"\nproof -\n  have drop_k_s:\"(drop k l)!0 = (c1,Normal s')\" using a1 by fastforce\n  have p1:\"s' \\<in> p1\" using a1 by auto\n  have k_l:\"k < length l\" using a1 by auto\n  show ?thesis\n  proof\n    show \"(\\<Gamma>, drop k l) \\<in> cp \\<Gamma> c1 (Normal s')\" \n    unfolding cp_def \n    using dropcptn_is_cptn a0 a1 drop_k_s cp_def \n    by fastforce\n  next\n    let ?c= \"(\\<Gamma>,drop k l)\"\n    have l:\"snd((snd ?c!0)) \\<in> Normal ` p1\"\n     using p1 drop_k_s by auto\n    {fix i\n     assume a00:\"Suc i<length (snd ?c)\" \n     assume a11:\"(fst ?c)\\<turnstile>\\<^sub>c((snd ?c)!i)  \\<rightarrow>\\<^sub>e ((snd ?c)!(Suc i))\"\n     have \"(snd((snd ?c)!i), snd((snd ?c)!(Suc i))) \\<in> R \"\n     using a0 unfolding assum_def using a00 a11 by auto\n    } thus \"(\\<Gamma>, drop k l) \\<in> assum (p1, R)\" \n      using l unfolding assum_def by fastforce  \n  qed  \nqed\n\nlemma Await_sound: \n \"\\<forall>V. \\<Gamma>\\<^sub>\\<not>\\<^sub>a,{}\\<turnstile>\\<^bsub>/F\\<^esub> \n    (p \\<inter> b \\<inter> {V}) e \n    ({s. (Normal V, Normal s) \\<in> G} \\<inter> q),\n    ({s. (Normal V, Normal s) \\<in> G} \\<inter> a) \\<Longrightarrow>     \n Sta p R \\<Longrightarrow> Sta q R \\<Longrightarrow> Sta a R \\<Longrightarrow>   \n \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub>  (Await b e e1) sat [p, R, G, q,a]\"\nproof -  \n assume\n  a0: \"\\<forall>V. \\<Gamma>\\<^sub>\\<not>\\<^sub>a,{}\\<turnstile>\\<^bsub>/F\\<^esub> \n        (p \\<inter> b \\<inter> {V}) e \n        ({s. (Normal V, Normal s) \\<in> G} \\<inter> q),\n        ({s. (Normal V, Normal s) \\<in> G} \\<inter> a)\" and\n  a2:\"Sta p R\" and\n  a3:\"Sta q R\" and\n  a4:\"Sta a R\"  \n{\n    fix s\n    have \"cpn n \\<Gamma> (Await b e e1) s \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cpn n \\<Gamma> (Await b e e1) s\" and a11:\"c \\<in> assum(p, R)\"\n      then have a10:\"c\\<in>cp \\<Gamma> (Await b e e1) s\"\n        using cp_def cpn_def cptn_if_cptn_mod cptn_mod_nest_cptn_mod by blast\n      have \"c\\<in>comm(G, (q,a)) F\" using Await_sound1[OF a0 a2 a3 a4 a10 a11] by auto      \n    } thus ?thesis by auto\n    qed \n  } \n  thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def) \nqed\n\n\nlemma cptn_comm_induct:\nassumes\n  a0: \"(\\<Gamma>,l) \\<in> (cp \\<Gamma> c s)\" and\n  a1: \"l1 = drop j l \\<and> (\\<Gamma>, l1)\\<in> comm(G, (q,a)) F\" and\n  a2: \"k \\<ge> j \\<and> j < length l\" \nshows \"snd (last (l)) \\<notin> Fault ` F  \\<longrightarrow> ((Suc k < length l \\<longrightarrow>\n       \\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)) \\<longrightarrow>        \n       (snd(l!k), snd(l!(Suc k))) \\<in> G) \n      \\<and> (final (last (l))  \\<longrightarrow>           \n            ((fst (last (l)) = Skip \\<and> \n              snd (last (l)) \\<in> Normal ` q)) \\<or>\n            (fst (last (l)) = Throw \\<and> \n              snd (last (l)) \\<in> Normal ` (a))))\"\nproof -  \n  have pair_\\<Gamma>l:\"fst (\\<Gamma>,l1) = \\<Gamma> \\<and> snd (\\<Gamma>,l1) = l1\" by fastforce  \n  have a03:\"snd (last (l1)) \\<notin> Fault ` F  \\<longrightarrow>(\\<forall>i.                 \n               Suc i<length (snd (\\<Gamma>, l1)) \\<longrightarrow> \n               fst (\\<Gamma>, l1)\\<turnstile>\\<^sub>c((snd (\\<Gamma>, l1))!i)  \\<rightarrow> ((snd (\\<Gamma>, l1))!(Suc i)) \\<longrightarrow>                                             \n                 (snd((snd (\\<Gamma>, l1))!i), snd((snd (\\<Gamma>, l1))!(Suc i))) \\<in> G) \\<and> \n               (final (last (snd (\\<Gamma>, l1)))  \\<longrightarrow> \n                snd (last (snd (\\<Gamma>, l1))) \\<notin> Fault ` F  \\<longrightarrow>\n                  ((fst (last (snd (\\<Gamma>, l1))) = Skip \\<and> \n                    snd (last (snd (\\<Gamma>, l1))) \\<in> Normal ` q)) \\<or>\n                  (fst (last (snd (\\<Gamma>, l1))) = Throw \\<and> \n                    snd (last (snd (\\<Gamma>, l1))) \\<in> Normal ` (a)))\"\n  using a1 unfolding comm_def by fastforce\n  have last_l:\"last l1 = last l\" using a1 a2 by fastforce\n  show ?thesis  \n  proof -\n  {\n    assume \" snd (last l) \\<notin> Fault ` F\" \n    then have l1_f:\"snd (last l1) \\<notin> Fault ` F\" \n     using a03 a1 a2 by force        \n      { assume \"Suc k < length l\"\n      then have a2: \"k \\<ge> j \\<and> Suc k < length l\" using a2 by auto\n      have \"k \\<le> length l\" using a2 by fastforce\n      then have l1_l:\"(l!k = l1! (k - j) ) \\<and> (l!Suc k = l1!Suc (k - j))\"\n        using a1 a2 by fastforce    \n      have a00:\"Suc (k - j) < length l1\" using a1 a2 by fastforce\n      have \"\\<Gamma>\\<turnstile>\\<^sub>c(l1!(k-j))  \\<rightarrow> (l1!(Suc (k-j))) \\<longrightarrow>         \n        (snd((snd (\\<Gamma>, l1))!(k-j)), snd((snd (\\<Gamma>, l1))!(Suc (k-j)))) \\<in> G\"\n      using  pair_\\<Gamma>l a00 l1_f a03 by presburger\n      then have \" \\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)) \\<longrightarrow> \n        (snd (l ! k), snd (l ! Suc k)) \\<in> G \" \n        using l1_l last_l by auto\n    } then have l_side:\"Suc k < length l \\<longrightarrow>\n    \\<Gamma>\\<turnstile>\\<^sub>c l ! k \\<rightarrow> l ! Suc k \\<longrightarrow>   \n    (snd (l ! k), snd (l ! Suc k)) \\<in> G\" by auto \n    { \n      assume a10:\"final (last (l))\"              \n      then have final_eq: \"final (last (l1))\"\n        using a10 a1 a2 by fastforce\n      also have \"snd (last (l1)) \\<notin> Fault ` F\"\n        using last_l l1_f by fastforce\n      ultimately have \"((fst (last (snd (\\<Gamma>, l1))) = Skip \\<and> \n                        snd (last (snd (\\<Gamma>, l1))) \\<in> Normal ` q)) \\<or>\n                      (fst (last (snd (\\<Gamma>, l1))) = Throw \\<and> \n                        snd (last (snd (\\<Gamma>, l1))) \\<in> Normal ` (a))\"\n        using pair_\\<Gamma>l a03 by presburger\n      then have \"((fst (last (snd (\\<Gamma>, l))) = Skip \\<and> \n              snd (last (snd (\\<Gamma>, l))) \\<in> Normal ` q)) \\<or>\n              (fst (last (snd (\\<Gamma>, l))) = Throw \\<and> \n             snd (last (snd (\\<Gamma>, l))) \\<in> Normal ` (a))\"\n        using final_eq a1 a2 by auto \n     } then have \n      r_side: \n      \"SmallStepCon.final (last l) \\<longrightarrow>     \n      fst (last l) = LanguageCon.com.Skip \\<and> snd (last l) \\<in> Normal ` q \\<or>\n       fst (last l) = LanguageCon.com.Throw \\<and> snd (last l) \\<in> Normal ` a\"\n       by fastforce\n     note res=conjI[OF l_side r_side] \n   } thus ?thesis by auto\n   qed\nqed\n\nlemma cpn_assum_induct:\nassumes\n  a0: \"(\\<Gamma>,l) \\<in> (cpn n \\<Gamma> c s) \\<and> ((\\<Gamma>,l) \\<in> assum(p, R))\" and\n  a1: \"k < length l \\<and> l!k=(c1,Normal s') \\<and> s' \\<in> p1\"\nshows \"(\\<Gamma>,drop k l)\\<in> ((cpn n \\<Gamma> c1 (Normal s')) \\<inter> assum(p1, R) )\"\nproof -\n  have drop_k_s:\"(drop k l)!0 = (c1,Normal s')\" using a1 by fastforce\n  have p1:\"s' \\<in> p1\" using a1 by auto\n  have k_l:\"k < length l\" using a1 by auto\n  show ?thesis\n  proof\n    show \"(\\<Gamma>, drop k l) \\<in> cpn n \\<Gamma> c1 (Normal s')\" \n    unfolding cp_def \n    using  a0 a1  \n    by (simp add: cpn_def dropcptn_is_cptn1) \n  next\n    let ?c= \"(\\<Gamma>,drop k l)\"\n    have l:\"snd((snd ?c!0)) \\<in> Normal ` p1\"\n     using p1 drop_k_s by auto\n    {fix i\n     assume a00:\"Suc i<length (snd ?c)\" \n     assume a11:\"(fst ?c)\\<turnstile>\\<^sub>c((snd ?c)!i)  \\<rightarrow>\\<^sub>e ((snd ?c)!(Suc i))\"\n     have \"(snd((snd ?c)!i), snd((snd ?c)!(Suc i))) \\<in> R \"\n     using a0 unfolding assum_def using a00 a11 by auto\n    } thus \"(\\<Gamma>, drop k l) \\<in> assum (p1, R)\" \n      using l unfolding assum_def by fastforce  \n  qed  \nqed\n\nlemma cpn_comm_induct:\n  assumes\n  a1: \"l1 = drop j l \\<and> (\\<Gamma>, l1)\\<in> comm(G, (q,a)) F\" and\n  a2: \"k \\<ge> j \\<and> j < length l\" \nshows \"snd (last (l)) \\<notin> Fault ` F  \\<longrightarrow> ((Suc k < length l \\<longrightarrow>\n       \\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)) \\<longrightarrow>        \n       (snd(l!k), snd(l!(Suc k))) \\<in> G) \n      \\<and> (final (last (l))  \\<longrightarrow>           \n            ((fst (last (l)) = Skip \\<and> \n              snd (last (l)) \\<in> Normal ` q)) \\<or>\n            (fst (last (l)) = Throw \\<and> \n              snd (last (l)) \\<in> Normal ` (a))))\"\nproof -  \n  have pair_\\<Gamma>l:\"fst (\\<Gamma>,l1) = \\<Gamma> \\<and> snd (\\<Gamma>,l1) = l1\" by fastforce  \n  have a03:\"snd (last (l1)) \\<notin> Fault ` F  \\<longrightarrow>(\\<forall>i.                 \n               Suc i<length (snd (\\<Gamma>, l1)) \\<longrightarrow> \n               fst (\\<Gamma>, l1)\\<turnstile>\\<^sub>c((snd (\\<Gamma>, l1))!i)  \\<rightarrow> ((snd (\\<Gamma>, l1))!(Suc i)) \\<longrightarrow>                                             \n                 (snd((snd (\\<Gamma>, l1))!i), snd((snd (\\<Gamma>, l1))!(Suc i))) \\<in> G) \\<and> \n               (final (last (snd (\\<Gamma>, l1)))  \\<longrightarrow> \n                snd (last (snd (\\<Gamma>, l1))) \\<notin> Fault ` F  \\<longrightarrow>\n                  ((fst (last (snd (\\<Gamma>, l1))) = Skip \\<and> \n                    snd (last (snd (\\<Gamma>, l1))) \\<in> Normal ` q)) \\<or>\n                  (fst (last (snd (\\<Gamma>, l1))) = Throw \\<and> \n                    snd (last (snd (\\<Gamma>, l1))) \\<in> Normal ` (a)))\"\n  using a1 unfolding comm_def by fastforce\n  have last_l:\"last l1 = last l\" using a1 a2 by fastforce\n  show ?thesis  \n  proof -\n  {\n    assume \" snd (last l) \\<notin> Fault ` F\" \n    then have l1_f:\"snd (last l1) \\<notin> Fault ` F\" \n     using a03 a1 a2 by force        \n      { assume \"Suc k < length l\"\n      then have a2: \"k \\<ge> j \\<and> Suc k < length l\" using a2 by auto\n      have \"k \\<le> length l\" using a2 by fastforce\n      then have l1_l:\"(l!k = l1! (k - j) ) \\<and> (l!Suc k = l1!Suc (k - j))\"\n        using a1 a2 by fastforce    \n      have a00:\"Suc (k - j) < length l1\" using a1 a2 by fastforce\n      have \"\\<Gamma>\\<turnstile>\\<^sub>c(l1!(k-j))  \\<rightarrow> (l1!(Suc (k-j))) \\<longrightarrow>         \n        (snd((snd (\\<Gamma>, l1))!(k-j)), snd((snd (\\<Gamma>, l1))!(Suc (k-j)))) \\<in> G\"\n      using  pair_\\<Gamma>l a00 l1_f a03 by presburger\n      then have \" \\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)) \\<longrightarrow> \n        (snd (l ! k), snd (l ! Suc k)) \\<in> G \" \n        using l1_l last_l by auto\n    } then have l_side:\"Suc k < length l \\<longrightarrow>\n    \\<Gamma>\\<turnstile>\\<^sub>c l ! k \\<rightarrow> l ! Suc k \\<longrightarrow>   \n    (snd (l ! k), snd (l ! Suc k)) \\<in> G\" by auto \n    { \n      assume a10:\"final (last (l))\"              \n      then have final_eq: \"final (last (l1))\"\n        using a10 a1 a2 by fastforce\n      also have \"snd (last (l1)) \\<notin> Fault ` F\"\n        using last_l l1_f by fastforce\n      ultimately have \"((fst (last (snd (\\<Gamma>, l1))) = Skip \\<and> \n                        snd (last (snd (\\<Gamma>, l1))) \\<in> Normal ` q)) \\<or>\n                      (fst (last (snd (\\<Gamma>, l1))) = Throw \\<and> \n                        snd (last (snd (\\<Gamma>, l1))) \\<in> Normal ` (a))\"\n        using pair_\\<Gamma>l a03 by presburger\n      then have \"((fst (last (snd (\\<Gamma>, l))) = Skip \\<and> \n              snd (last (snd (\\<Gamma>, l))) \\<in> Normal ` q)) \\<or>\n              (fst (last (snd (\\<Gamma>, l))) = Throw \\<and> \n             snd (last (snd (\\<Gamma>, l))) \\<in> Normal ` (a))\"\n        using final_eq a1 a2 by auto \n     } then have \n      r_side: \n      \"SmallStepCon.final (last l) \\<longrightarrow>     \n      fst (last l) = LanguageCon.com.Skip \\<and> snd (last l) \\<in> Normal ` q \\<or>\n       fst (last l) = LanguageCon.com.Throw \\<and> snd (last l) \\<in> Normal ` a\"\n       by fastforce\n     note res=conjI[OF l_side r_side] \n   } thus ?thesis by auto\n   qed\nqed\n\n\nlemma If_sound: \n      \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b,  R, G, q,a] \\<Longrightarrow>\n       (\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b,  R, G, q,a]) \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c2 sat [p \\<inter> (-b),  R, G, q,a] \\<Longrightarrow>\n       (\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> c2 sat [p \\<inter> (-b),  R, G, q,a]) \\<Longrightarrow>      \n       Sta p R \\<Longrightarrow> (\\<forall>s. (Normal s, Normal s) \\<in> G)  \\<Longrightarrow> \n       \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Cond b c1 c2) sat [p, R, G, q,a]\"\nproof -  \n assume\n    a0:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b,  R, G, q,a]\" and\n    a1:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c2 sat [p \\<inter> (-b), R, G, q,a]\" and    \n    a2: \"\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b, R, G, q,a]\" and\n    a3: \"\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> c2 sat [p \\<inter> (-b), R, G, q,a]\" and\n    a4: \"Sta p R\" and\n    a5: \"(\\<forall>s. (Normal s, Normal s) \\<in> G)\"\n  { \n    fix s\n    assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"\n    then have a3:\"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c2 sat [p \\<inter> (-b), R, G, q,a]\" \n      using a3 com_cvalidityn_def  by fastforce \n    have a2:\"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b, R, G, q,a]\"\n      using a2 all_call com_cvalidityn_def  by fastforce \n    have \"cpn n \\<Gamma> (Cond b c1 c2)  s \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cpn n \\<Gamma> (Cond b c1 c2) s\" and a11:\"c \\<in> assum(p, R)\"\n      then have a10':\"c \\<in> cp \\<Gamma> (Cond b c1 c2) s\" unfolding cp_def cpn_def\n        using cptn_eq_cptn_mod_set cptn_mod_nest_cptn_mod by fastforce\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have \"c \\<in> comm(G, (q,a)) F\"      \n      proof - \n      {assume l_f:\"snd (last l) \\<notin> Fault ` F\"  \n       \n       have cp:\"l!0=((Cond b c1 c2),s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\" using a10' cp_def c_prod by fastforce\n       have \\<Gamma>1:\"(\\<Gamma>, l) = c\" using c_prod cp by blast\n       have assum:\"snd(l!0) \\<in> Normal ` (p) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n                   (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n       using a11 c_prod unfolding assum_def by simp\n       then have env_tran:\"env_tran \\<Gamma> p l R\" using env_tran_def cp by blast\n       then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n         using env_tran env_tran_right_def unfolding env_tran_def by auto\n       have concl:\"(\\<forall>i. Suc i<length l \\<longrightarrow> \n               \\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>               \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n       proof -\n       { fix k ns ns'\n         assume a00:\"Suc k<length l\" and\n                a21:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"                                                                           \n         obtain j where before_k_all_evnt:\"j\\<le>k \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n           using a00 a21 exist_first_comp_tran cp by blast\n         then obtain cj sj csj ssj where pair_j:\"(\\<Gamma>\\<turnstile>\\<^sub>c(cj,sj)  \\<rightarrow> (csj,ssj)) \\<and> cj = fst (l!j) \\<and> sj = snd (l!j) \\<and> csj = fst (l!(Suc j)) \\<and> ssj = snd(l!(Suc j))\"\n           by fastforce                                   \n         have k_basic:\"cj = (Cond b c1 c2) \\<and> sj \\<in> Normal ` (p)\" \n           using pair_j before_k_all_evnt cp env_tran_right a4 assum a00 stability[of p R l 0 j j \\<Gamma>]\n         by force\n         then obtain s' where ss:\"sj = Normal s' \\<and> s'\\<in> (p)\" by auto \n         then have ssj_normal_s:\"ssj = Normal s'\" using before_k_all_evnt k_basic pair_j\n           by (metis prod.collapse snd_conv stepc_Normal_elim_cases(6))          \n         have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n           using ss a2 unfolding Satis_def         \n         proof (cases \"k=j\")   \n           case True          \n             have \"(Normal s', Normal s') \\<in> G\" \n               using a5  by blast\n             thus \"(snd (l ! k), snd (l ! Suc k)) \\<in> G\"\n               using pair_j k_basic True ss ssj_normal_s by auto\n         next\n           case False\n           have j_length:\"Suc j < length l\" using a00 before_k_all_evnt by fastforce \n           have l_suc:\"l!(Suc j) = (csj, Normal s')\" \n             using before_k_all_evnt pair_j  ssj_normal_s\n             by fastforce\n           have l_k:\"j<k\" using  before_k_all_evnt False by fastforce\n           have \"s'\\<in>b \\<or> s'\\<notin>b\" by auto                         \n           thus \"(snd (l ! k), snd (l ! Suc k)) \\<in> G\"\n           proof\n             assume a000:\"s'\\<in>b\"\n             then have cj:\"csj=c1\" using k_basic pair_j ss \n               by (metis (no_types) fst_conv stepc_Normal_elim_cases(6))\n             moreover have p1:\"s' \\<in> (p \\<inter> b)\" using a000 ss by blast              \n             moreover  have \"cpn n \\<Gamma> csj ssj \\<inter> assum((p \\<inter> b), R) \\<subseteq> comm(G, (q,a)) F\"\n               using calculation a2 com_validityn_def cj by blast             \n             ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n               using l_suc j_length a10 a11 \\<Gamma>1  ssj_normal_s\n                     cpn_assum_induct[of \\<Gamma> l n \"(LanguageCon.com.Cond b c1 c2)\" s p R  \"Suc j\" c1 s' \"(p \\<inter> b)\"]\n               by blast                         \n             show ?thesis \n               using l_k drop_comm a00 a21  a10 \\<Gamma>1 l_f  \n               cpn_comm_induct\n               by fastforce                       \n           next\n             assume a000:\"s'\\<notin>b\"\n              then have cj:\"csj=c2\" using k_basic pair_j ss \n                  by (metis (no_types) fst_conv stepc_Normal_elim_cases(6))\n             moreover have p1:\"s' \\<in> (p \\<inter> (-b))\" using a000 ss by fastforce\n             moreover then have \"cpn n \\<Gamma> csj ssj \\<inter> assum((p \\<inter> (-b)), R)  \\<subseteq> comm(G, (q,a)) F\"\n               using a3 com_validityn_def cj by blast             \n             ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n               using l_suc j_length a10 a11 \\<Gamma>1  ssj_normal_s\n                     cpn_assum_induct[of \\<Gamma> l n \"(LanguageCon.com.Cond b c1 c2)\" s p R  \"Suc j\" c2 s' \"(p \\<inter> (-b))\"]\n               by fastforce             \n             show ?thesis \n             using l_k drop_comm a00 a21 a10 \\<Gamma>1 l_f\n             cpn_comm_induct\n             unfolding Satis_def by fastforce\n           qed\n         qed \n       } thus ?thesis by (simp add: c_prod cp) qed\n       have concr:\"(final (last l)  \\<longrightarrow>                    \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a)))\"\n       proof-\n       { \n         assume valid:\"final (last l)\" \n         assume not_fault:  \"snd (last l) \\<notin> Fault ` F\"                 \n         have \"\\<exists>k. k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final (l!(Suc k))\"\n         proof -             \n           have len_l:\"length l > 0\" using cp using cptn.simps by blast \n           then obtain a1 l1 where l:\"l=a1#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n           have last_l:\"last l = l!(length l-1)\"\n             using last_length [of a1 l1] l by fastforce\n           have final_0:\"\\<not>final(l!0)\" using cp unfolding final_def by auto\n           have \"0\\<le> (length l-1)\" using len_l last_l by auto\n           moreover have \"(length l-1) < length l\" using len_l by auto\n           moreover have \"final (l!(length l-1))\" using valid last_l by auto\n           moreover have \"fst (l!0) = LanguageCon.com.Cond b c1 c2\" using cp by auto\n           ultimately show ?thesis \n             using cp final_exist_component_tran_final env_tran_right final_0  \n             by blast \n         qed\n        then obtain k where a21: \"k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final (l!(Suc k))\"\n           by auto\n        then have a00:\"Suc k<length l\" by fastforce\n        then obtain j where before_k_all_evnt:\"j\\<le>k \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n           using a00 a21 exist_first_comp_tran cp by blast\n       then obtain cj sj csj ssj where pair_j:\"(\\<Gamma>\\<turnstile>\\<^sub>c(cj,sj)  \\<rightarrow> (csj,ssj)) \\<and> cj = fst (l!j) \\<and> sj = snd (l!j) \\<and> csj = fst (l!(Suc j)) \\<and> ssj = snd(l!(Suc j))\"\n         by fastforce\n       have j_length:\"Suc j < length l\" using a00 before_k_all_evnt by fastforce                                 \n       then have k_basic:\"cj = (Cond b c1 c2) \\<and> sj \\<in> Normal ` (p)\" \n         using  pair_j before_k_all_evnt cp env_tran_right a4 assum a00 stability[of p R l 0 j j \\<Gamma>]\n       by fastforce\n       then obtain s' where ss:\"sj = Normal s' \\<and> s'\\<in> (p)\" by auto \n       then have ssj_normal_s:\"ssj = Normal s'\" using before_k_all_evnt k_basic pair_j\n         by (metis prod.collapse snd_conv stepc_Normal_elim_cases(6))       \n       have l_suc:\"l!(Suc j) = (csj, Normal s')\" \n           using before_k_all_evnt pair_j  ssj_normal_s\n           by fastforce\n       have \"s'\\<in>b \\<or> s'\\<notin>b\" by auto \n       then have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a))\"\n       proof\n         assume a000:\"s'\\<in>b\"\n         then have cj:\"csj=c1\" using k_basic pair_j ss \n                  by (metis (no_types) fst_conv stepc_Normal_elim_cases(6))\n         moreover have p1:\"s' \\<in> (p \\<inter> b)\" using a000 ss by blast \n         moreover then have \"cpn n \\<Gamma> csj ssj \\<inter> assum((p \\<inter> b), R)  \\<subseteq> comm(G, (q,a)) F\"\n           using a2 com_validityn_def cj by blast         \n         ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n           using l_suc j_length a10 a11 \\<Gamma>1  ssj_normal_s\n                 cpn_assum_induct[of \\<Gamma> l n \"(LanguageCon.com.Cond b c1 c2)\" s p R  \"Suc j\" c1 s' \"(p \\<inter> b)\"]\n           by blast                   \n         thus ?thesis       \n           using j_length drop_comm   a10 \\<Gamma>1  cpn_comm_induct valid not_fault \n           by blast\n       next\n         assume a000:\"s'\\<notin>b\"\n         then have cj:\"csj=c2\" using k_basic pair_j ss \n                  by (metis (no_types) fst_conv stepc_Normal_elim_cases(6))\n         moreover have p1:\"s'\\<in>(p \\<inter> (-b))\" using a000 ss by blast \n         moreover then have \"cpn n \\<Gamma> csj ssj \\<inter> assum((p \\<inter> (-b)), R)  \\<subseteq> comm(G, (q,a)) F\"\n           using a3 com_validityn_def cj by blast         \n         ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n           using l_suc j_length a10 a11 \\<Gamma>1  ssj_normal_s\n                 cpn_assum_induct[of \\<Gamma> l n \"(LanguageCon.com.Cond b c1 c2)\" s p R  \"Suc j\" c2 s' \"(p \\<inter> (-b))\"]\n           by blast                   \n         thus ?thesis       \n           using j_length drop_comm a10 \\<Gamma>1  cpn_comm_induct valid not_fault \n           by blast\n       qed\n       } thus ?thesis using l_f by fastforce qed\n       note res = conjI [OF concl concr]              \n      }             \n      thus ?thesis using c_prod  unfolding comm_def by auto  qed      \n    } thus ?thesis by auto qed \n} thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def) \nqed\n\n\nlemma Asm_sound:\n   \"(c, p, R, G, q, a) \\<in> \\<Theta> \\<Longrightarrow>    \n    \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\n   \"\nproof -\n  assume\n   a0:\"(c, p, R, G, q, a) \\<in> \\<Theta>\"    \n   { fix s\n     assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Call c) sat [p,  R, G, q,a]\"\n     then have \"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\" using a0 by auto\n   } thus ?thesis unfolding com_cvalidityn_def by auto\nqed\n\nlemma events_p:\n  assumes  a0:\"(\\<Gamma>,cfg#l)\\<in>cptn\" and\n   a1:\"(\\<Gamma>,cfg#l) \\<in> assum (p,R)\" and\n   a2:\"i<length (cfg#l)\" and\n   a3:\"\\<forall>k\\<le>i. fst ((cfg#l)!k) = fst cfg\" and\n   a4:\"Sta p R \" \n shows \"\\<exists>t1. snd((cfg#l)!i)=Normal t1 \\<and> t1 \\<in> p\" \n  using a2 a3\nproof(induct i)\n  case 0\n  then show ?case using a1 a2 unfolding assum_def by auto\nnext\n  case (Suc n)\n  then have \"\\<exists>t1. snd ((cfg # l) ! n) = Normal t1 \\<and> t1 \\<in> p\" by auto \n  moreover have \"\\<Gamma>\\<turnstile>\\<^sub>c ((cfg#l)!n) \\<rightarrow>\\<^sub>e ((cfg#l)!(Suc n))\" using Suc a0\n    by (metis Env calculation less_Suc_eq_le less_not_refl nat_le_linear prod.collapse)\n  then have  \"(snd ((cfg#l)!n),snd ((cfg#l)!(Suc n)))\\<in>R\" using a1 Suc(2) \n    unfolding assum_def by auto\n  ultimately show ?case using a4 unfolding Sta_def by auto\nqed\n\n\nlemma not_val_zero:\"c \\<in> dom \\<Gamma> \\<Longrightarrow> Sta p R \\<Longrightarrow> \\<Gamma> \\<Turnstile>0\\<^bsub>/F\\<^esub> Call c sat [p,R, G, q,a]\"\nproof-\n  assume a0:\" c \\<in> dom \\<Gamma>\"\n  assume a1:\"Sta p R\"\n  {fix l s\n    assume a01:\"(\\<Gamma>,l) \\<in> cpn 0 \\<Gamma> (Call c) s \\<and> (\\<Gamma>,l)\\<in> assum(p, R)\"    \n    then have \"length l \\<ge> 1\" unfolding cpn_def using CptnEmpty\n      by (metis (no_types, lifting) One_nat_def Product_Type.Collect_case_prodD Suc_leI length_greater_0_conv snd_conv)\n    moreover {assume a02:\"length l = 1\"\n      then have \"l = [(Call c,s)]\" \n      proof -\n        have \"l ! 0 = (LanguageCon.com.Call c, s)\" using a01 unfolding cpn_def\n          by fastforce\n        then show ?thesis using a02\n          by (metis One_nat_def Suc_leI impossible_Cons length_greater_0_conv list.size(3) neq_Nil_conv nth_Cons_0 zero_neq_one) \n      qed \n      then have \"(\\<Gamma>,l) \\<in> comm(G, (q,a)) F\" unfolding comm_def final_def by auto\n    }\n    moreover {assume a02:\"length l > 1\"\n      then obtain a1 ls where l:\"l =(Call c, s)#a1#ls\" using a01 unfolding cpn_def\n        apply auto\n        by (metis (no_types, hide_lams) One_nat_def Suc_eq_plus1 less_not_refl list.exhaust list.size(3) list.size(4) not_less_zero nth_Cons_0 prod.collapse)   \n      have l_cptn:\"(\\<Gamma>,l)\\<in>cptn\" using a01 unfolding cpn_def\n        using cptn_eq_cptn_mod_nest by blast\n      then obtain m where min_call:\"min_call m \\<Gamma> l\"\n          using cptn_eq_cptn_mod_set cptn_mod_cptn_mod_nest minimum_nest_call by blast\n      { assume a03:\"\\<forall>i<length l. fst (l!i) = Call c\"        \n        then have \"(\\<Gamma>,l) \\<in> comm(G, (q,a)) F\" \n          using no_comp_tran_no_final_comm[OF _ a03] a02 unfolding final_def\n          by fastforce \n      }\n      moreover { assume a03:\"\\<not> (\\<forall>i<length l. fst (l!i) = Call c)\"\n        then obtain i where i:\"(i<length l \\<and> fst (l!i) \\<noteq> Call c)\"\n          by auto\n        then obtain j where cfg_j:\"fst (l!j) \\<noteq> Call c \\<and> (\\<forall>k<j. fst (l!k) = Call c)\"                     \n          by (fast dest: exists_first_occ[of \"\\<lambda>i. fst (l!i) \\<noteq> Call c\" i])\n        moreover have j:\"j>0 \\<and> j<length l\" using l i calculation\n          by (metis gr0I fstI leI le_less_trans nth_Cons') \n        ultimately have step:\"(\\<Gamma>\\<turnstile>\\<^sub>c (l!(j-1)) \\<rightarrow> (l!j))\"\n          using l l_cptn\n          by (metis One_nat_def Suc_pred cptn_stepc_rtran diff_less not_eq_not_env prod.collapse \n                   step_ce_elim_cases zero_less_one)\n        moreover obtain s' where j_1_cfg:\"snd (l!(j-1)) = Normal s' \\<and> s' \\<in> p\"\n          using cfg_j l a01[simplified l] j[simplified l] i a1 events_p[OF l_cptn[simplified l] _ _ _ a1, of \"j-1\"]\n          by force\n        then have j_cfg:\"l!j = (the (\\<Gamma> c), Normal s')\" using cfg_j a0\n           stepc_Normal_elim_cases(9) calculation\n          by (metis diff_less domIff j option.sel prod.collapse zero_less_one)        \n        ultimately have False\n        proof-\n          have \"(0,\\<Gamma>, drop (j-1) l) \\<in> cptn_mod_nest_call\" \n            using a01 unfolding cpn_def \n            by (simp add: dropcptn_is_cptn1 j less_imp_diff_less)      \n          then show ?thesis \n            using redex_call_cptn_mod_min_nest_call_gr_zero  j j_cfg j_1_cfg cfg_j step a0\n            by (metis Cons_nth_drop_Suc One_nat_def SmallStepCon.redex.simps(7) Suc_pred  \n                 diff_less domIff less_imp_diff_less min_call_def not_less_zero prod.collapse \n                 stepc_Normal_elim_cases(9) zero_less_one)             \n        qed          \n      }\n      ultimately have \"(\\<Gamma>,l) \\<in> comm(G, (q,a)) F\" by auto\n    }\n    ultimately have \"(\\<Gamma>,l)\\<in>comm(G, (q,a)) F\" by fastforce\n  } then show ?thesis unfolding com_validityn_def cpn_def by auto    \nqed\n\nlemma Call_sound: \n      \"f \\<in> dom \\<Gamma> \\<Longrightarrow>      \n       \\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> (the (\\<Gamma> f)) sat [p, R, G, q,a] \\<Longrightarrow>         \n       Sta p R \\<Longrightarrow> (\\<forall>s. (Normal s,Normal s) \\<in> G)  \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Call f) sat [p, R, G, q,a]\"\nproof -  \n  assume\n    a0:\"f \\<in> dom \\<Gamma>\" and\n    a2:\"\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> (the (\\<Gamma> f)) sat [p, R, G, q,a]\" and        \n    a3: \"Sta p R\" and\n    a4: \"(\\<forall>s. (Normal s, Normal s) \\<in> G)\"         \n  obtain bdy where a0:\"\\<Gamma> f = Some bdy\" using a0 by auto\n  { \n    fix s\n    assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Call c) sat [p,  R, G, q,a]\"  \n    then have a2:\"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> bdy sat [p, R, G, q,a]\" \n      using a0 a2 com_cvalidityn_def by fastforce\n    have \"cpn n \\<Gamma> (Call f)  s \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cpn n \\<Gamma> (Call f) s\" and a11:\"c \\<in> assum(p, R)\"\n      then have a10':\"c \\<in> cp \\<Gamma> (Call f) s\" \n        unfolding cpn_def cp_def using cptn_eq_cptn_mod_set cptn_mod_nest_cptn_mod by fastforce\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have \"c \\<in> comm(G, (q,a)) F\"      \n      proof - \n      {assume l_f:\"snd (last l) \\<notin> Fault ` F\"       \n        have cp:\"l!0=((Call f),s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\" using a10' cp_def c_prod by fastforce\n        have \\<Gamma>1:\"(\\<Gamma>, l) = c\" using c_prod cp by blast\n        have assum:\"snd(l!0) \\<in> Normal ` (p) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n                   (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n       using a11 c_prod unfolding assum_def by simp\n       then have env_tran:\"env_tran \\<Gamma> p l R\" using env_tran_def cp by blast\n       then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n         using env_tran env_tran_right_def unfolding env_tran_def by auto\n       have concl:\"(\\<forall>i. Suc i<length l \\<longrightarrow> \n               \\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                              \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n       proof -\n       { fix k ns ns'\n         assume a00:\"Suc k<length l\" and\n                a21:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"                                                      \n         obtain j where before_k_all_evnt:\"j\\<le>k \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n           using a00 a21 exist_first_comp_tran cp by blast\n         then obtain cj sj csj ssj where pair_j:\"(\\<Gamma>\\<turnstile>\\<^sub>c(cj,sj)  \\<rightarrow> (csj,ssj)) \\<and> cj = fst (l!j) \\<and> sj = snd (l!j) \\<and> csj = fst (l!(Suc j)) \\<and> ssj = snd(l!(Suc j))\"\n           by fastforce                                             \n         have k_basic:\"cj = (Call f) \\<and> sj \\<in> Normal ` (p)\" \n           using  pair_j before_k_all_evnt cp env_tran_right a3 assum a00 stability[of p R l 0 j j \\<Gamma>]\n           by force\n         then obtain s' where ss:\"sj = Normal s' \\<and> s'\\<in> (p)\" by auto \n         then have ssj_normal_s:\"ssj = Normal s'\" \n           using before_k_all_evnt k_basic pair_j a0 \n           by (metis not_None_eq snd_conv stepc_Normal_elim_cases(9))                     \n         have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n           using ss a2 \n         proof (cases \"k=j\")   \n           case True                                  \n           have \"(Normal s', Normal s') \\<in> G\" \n             using a4 by fastforce \n           thus \"(snd (l ! k), snd (l ! Suc k)) \\<in> G\"\n             using pair_j k_basic True ss ssj_normal_s by auto\n         next\n           case False   \n           have j_k:\"j<k\" using  before_k_all_evnt False by fastforce                      \n           thus \"(snd (l ! k), snd (l ! Suc k)) \\<in>  G\"\n           proof -\n             have j_length:\"Suc j < length l\" using a00 before_k_all_evnt by fastforce\n             have cj:\"csj=bdy\" using k_basic pair_j ss a0\n               by (metis fst_conv option.distinct(1) option.sel stepc_Normal_elim_cases(9))                \n             moreover have p1:\"s'\\<in>p\" using ss by blast \n             moreover then have \"cpn n \\<Gamma> csj ssj \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F\"\n               using a2 com_validityn_def cj by blast\n             moreover then have \"l!(Suc j) = (csj, Normal s')\" \n               using before_k_all_evnt pair_j cj ssj_normal_s\n               by fastforce\n             ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n               using  j_length a10 a11 \\<Gamma>1  ssj_normal_s                     \n               by (meson contra_subsetD cpn_assum_induct)                                \n             then show ?thesis \n             using a00 a21  \\<Gamma>1  j_k j_length l_f\n             cptn_comm_induct[of \\<Gamma> l \"Call f\" s _ \"Suc j\" G q a F k ]             \n             Suc_leI a10' by blast                 \n          qed            \n       qed \n       } thus ?thesis by (simp add: c_prod cp) qed\n       have concr:\"(final (last l)  \\<longrightarrow>                   \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a)))\"\n       proof-\n       { \n         assume valid:\"final (last l)\"                       \n         have \"\\<exists>k. k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final (l!(Suc k))\"\n         proof -             \n           have len_l:\"length l > 0\" using cp using cptn.simps by blast \n           then obtain a1 l1 where l:\"l=a1#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n           have last_l:\"last l = l!(length l-1)\"\n            using last_length [of a1 l1] l by fastforce         \n           have final_0:\"\\<not>final(l!0)\" using cp unfolding final_def by auto\n           have \"0\\<le> (length l-1)\" using len_l last_l by auto\n           moreover have \"(length l-1) < length l\" using len_l by auto\n           moreover have \"final (l!(length l-1))\" using valid last_l by auto\n           moreover have \"fst (l!0) = Call f\" using cp by auto\n           ultimately show ?thesis \n             using  cp final_exist_component_tran_final env_tran_right final_0 \n             by blast \n          qed\n          then obtain k where a21: \"k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final (l!(Suc k))\"\n            by auto\n          then have a00:\"Suc k<length l\" by fastforce\n          then obtain j where before_k_all_evnt:\"j\\<le>k \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n            using a00 a21 exist_first_comp_tran cp by blast\n          then obtain cj sj csj ssj where pair_j:\"(\\<Gamma>\\<turnstile>\\<^sub>c(cj,sj)  \\<rightarrow> (csj,ssj)) \\<and> cj = fst (l!j) \\<and> sj = snd (l!j) \\<and> csj = fst (l!(Suc j)) \\<and> ssj = snd(l!(Suc j))\"\n            by fastforce         \n          have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a))\"\n          proof -\n            have j_length:\"Suc j < length l\" using a00 before_k_all_evnt by fastforce                                 \n            then have k_basic:\"cj = (Call f) \\<and> sj \\<in> Normal ` (p)\" \n              using  pair_j before_k_all_evnt cp env_tran_right a3 assum a00 stability[of p R l 0 j j \\<Gamma>]\n              by force\n            then obtain s' where ss:\"sj = Normal s' \\<and> s'\\<in> (p)\" by auto \n            then have ssj_normal_s:\"ssj = Normal s'\" \n              using before_k_all_evnt k_basic pair_j a0 \n              by (metis not_None_eq snd_conv stepc_Normal_elim_cases(9))\n            have cj:\"csj=bdy\" using k_basic pair_j ss a0\n              by (metis fst_conv option.distinct(1) option.sel stepc_Normal_elim_cases(9))                \n            moreover have p1:\"s'\\<in>p\" using ss by blast \n            moreover then have \"cpn n \\<Gamma> csj ssj \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F\"\n              using a2 com_validityn_def cj by blast\n            moreover then have \"l!(Suc j) = (csj, Normal s')\" \n              using before_k_all_evnt pair_j cj ssj_normal_s\n              by fastforce\n            ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n              using  j_length a10 a11 \\<Gamma>1  ssj_normal_s              \n              by (meson contra_subsetD cpn_assum_induct)              \n            thus ?thesis       \n              using j_length l_f drop_comm a10' \\<Gamma>1 cptn_comm_induct[of \\<Gamma> l \"Call f\" s _ \"Suc j\" G q a F \"Suc j\"] valid  \n              by blast\n           qed\n         } thus ?thesis by auto \n         qed\n       note res = conjI [OF concl concr]}               \n       thus ?thesis using  c_prod unfolding comm_def by force qed      \n    } thus ?thesis by auto qed \n  } thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def) \nqed\n           \nlemma CallRec_sound:\n    \"(c, p, R, G, q, a) \\<in> Specs \\<Longrightarrow>\n     \\<forall>(c, p, R, G, q, a)\\<in>Specs.\n       c \\<in> dom \\<Gamma> \\<and>\n       Sta p R \\<and>  (\\<forall>s. (Normal s,Normal s) \\<in> G) \\<and>      \n       \\<Gamma>,\\<Theta> \\<union> Specs \\<turnstile>\\<^bsub>/F\\<^esub> the (\\<Gamma> c) sat [p, R, G, q,a] \\<and> \n       (\\<forall>x. \\<Gamma>,\\<Theta> \\<union> Specs \\<Turnstile>x \\<^bsub>/F\\<^esub> the (\\<Gamma> c) sat [p,R, G, q,a]) \\<Longrightarrow>\n    Sta p R \\<Longrightarrow> (\\<forall>s. (Normal s,Normal s) \\<in> G) \\<Longrightarrow>\n     \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> Call c sat [p,R, G, q,a]\"\nproof -\n  assume a0: \"(c, p, R, G, q, a) \\<in> Specs\" and\n     a1: \n    \"\\<forall>(c, p, R, G, q, a)\\<in>Specs.\n       c \\<in> dom \\<Gamma> \\<and> Sta p R \\<and> (\\<forall>s. (Normal s,Normal s) \\<in> G) \\<and>  \n       \\<Gamma>,\\<Theta> \\<union> Specs \\<turnstile>\\<^bsub>/F\\<^esub> the (\\<Gamma> c) sat [p, R, G, q,a] \\<and> \n       (\\<forall>x. \\<Gamma>,\\<Theta> \\<union> Specs \\<Turnstile>x \\<^bsub>/F\\<^esub> the (\\<Gamma> c) sat [p,R, G, q,a])\"\n  then have a1': \"c \\<in> dom \\<Gamma>\"  and       \n       a1'': \"\\<Gamma>,\\<Theta> \\<union> Specs \\<Turnstile>n \\<^bsub>/F\\<^esub> the (\\<Gamma> c) sat [p,R, G, q,a]\" using a0 by auto \n    from a1 have \n      valid_body:\n      \"\\<forall>(c, p, R, G, q, a)\\<in>Specs.\n       c \\<in> dom \\<Gamma> \\<and>  Sta p R \\<and>   (\\<forall>s. (Normal s,Normal s) \\<in> G) \\<and>    \n       (\\<forall>x. \\<Gamma>,\\<Theta> \\<union> Specs \\<Turnstile>x \\<^bsub>/F\\<^esub> the (\\<Gamma> c) sat [p,R, G, q,a])\" by fastforce\n  assume a5: \"Sta p R\" and\n         a6: \"(\\<forall>s. (Normal s,Normal s) \\<in> G)\" \n  obtain bdy where \\<Gamma>bdy:\"\\<Gamma> c = Some bdy\" using a1' by auto\n  have theta_specs: \n         \"\\<forall>(c, p, R, G, q, a)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> Call c sat [p,R, G, q,a] \\<Longrightarrow>\n          \\<forall>(c, p, R, G, q, a)\\<in>Specs. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> Call c sat [p,R, G, q,a]\"\n  proof(induct n)\n    case 0    \n    show \"\\<forall>(c, p, R, G, a, d)\\<in>Specs. \\<Gamma> \\<Turnstile>0\\<^bsub>/F\\<^esub> LanguageCon.com.Call c sat [p,R, G, a,d]\"\n    proof-\n      {fix c p R G a d\n        assume a00:\"(c, p, R, G, a, d) \\<in> Specs\"\n        then have \"c\\<in>dom \\<Gamma> \\<and> Sta p R\" using a1 by auto\n        then have \" \\<Gamma> \\<Turnstile>0\\<^bsub>/F\\<^esub> (LanguageCon.com.Call c) sat [p,R, G, a,d]\"\n          using not_val_zero  by fastforce\n      } then show ?thesis by auto \n    qed       \n  next\n    case (Suc n)\n    have hyp:\"\\<forall>(c, p, R, G, q, a)\\<in>\\<Theta>.  \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> Call c sat [p,R, G, q,a] \\<Longrightarrow>\n             \\<forall>(c, p, R, G, q, a)\\<in>Specs. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> Call c sat [p,R, G, q,a]\" by fact\n    have body:\"\\<forall>(c, p, R, G, q, a)\\<in>\\<Theta>.  \\<Gamma> \\<Turnstile>Suc n\\<^bsub>/F\\<^esub> Call c sat [p,R, G, q,a]\" by fact\n    then show ?case\n    proof-\n      { fix c p R G q a\n        assume a000:\"(c, p, R, G, q, a) \\<in> Specs\"\n        have ctxt_m:\"\\<forall>(c, p, R, G, q, a)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> Call c sat [p,R, G, q,a]\"\n          using body  cptn_mod_nest_mono  unfolding com_validityn_def cpn_def\n          by (fastforce simp add: cpn_rule)\n        then have valid_Proc:\"\\<forall>(c, p, R, G, q, a)\\<in>Specs. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> Call c sat [p,R, G, q,a]\"\n          using hyp by auto\n        have Sta:\"Sta p R\" using a1 a000 by auto\n        have c_dom:\" c \\<in> dom \\<Gamma>\" using a1 a000 by auto\n        have guar:\"\\<forall>s. (Normal s,Normal s)\\<in>G\" using a1 a000 by auto\n        let ?\\<Theta>'= \"\\<Theta> \\<union> Specs\"\n        from valid_Proc ctxt_m\n        have \"\\<forall>(c, p, R, G, q, a)\\<in>?\\<Theta>'. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> Call c sat [p,R, G, q,a]\"\n          by fastforce\n        with valid_body\n        have valid_body_m: \n          \"\\<forall>(c, p, R, G, q, a)\\<in>Specs. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> (the (\\<Gamma> c)) sat [p,R, G, q,a]\"\n          by (fastforce  simp:com_cvalidityn_def)    \n        then have valid_body:\"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> (the (\\<Gamma> c)) sat [p,R, G, q,a]\" using a000 by auto\n        then have \"\\<Gamma> \\<Turnstile>Suc n\\<^bsub>/F\\<^esub> Call c sat [p,R, G, q,a]\"\n        proof-\n        { fix l s \n          assume a01:\"(\\<Gamma>,l)\\<in>cpn (Suc n) \\<Gamma> (Call c) s \\<and> (\\<Gamma>,l)\\<in> assum(p, R)\"\n          then have \"length l \\<ge> 1\" unfolding cpn_def using CptnEmpty\n            by (metis (no_types, lifting) One_nat_def Product_Type.Collect_case_prodD Suc_leI length_greater_0_conv snd_conv)\n          moreover {\n            assume a02:\"length l = 1\"\n            then have \"l = [(Call c,s)]\" \n            proof -\n              have \"l ! 0 = (LanguageCon.com.Call c, s)\" using a01 unfolding cpn_def\n                by fastforce\n              then show ?thesis using a02\n                by (metis One_nat_def Suc_leI impossible_Cons \n                     length_greater_0_conv list.size(3) neq_Nil_conv nth_Cons_0 zero_neq_one) \n            qed \n            then have \"(\\<Gamma>,l) \\<in> comm(G, (q,a)) F\" unfolding comm_def final_def by auto\n          }\n          moreover {assume a02:\"length l > 1\"\n            then obtain a1 ls where l:\"l =(Call c, s)#a1#ls\" using a01 unfolding cpn_def\n              apply auto\n              by (metis (no_types, hide_lams) One_nat_def Suc_eq_plus1 less_not_refl list.exhaust list.size(3) list.size(4) not_less_zero nth_Cons_0 prod.collapse)   \n            have l_cptn:\"(\\<Gamma>,l)\\<in>cptn\" using a01 unfolding cpn_def\n              using cptn_eq_cptn_mod_nest by blast\n            then obtain m where min_call:\"min_call m \\<Gamma> l\"\n              using cptn_eq_cptn_mod_set cptn_mod_cptn_mod_nest minimum_nest_call by blast\n            { assume a03:\"\\<forall>i<length l. fst (l!i) = Call c\"     \n              then have \"(\\<Gamma>,l) \\<in> comm(G, (q,a)) F\" \n                using no_comp_tran_no_final_comm[OF _ a03] a02 unfolding final_def\n                by fastforce \n            }                                     \n            moreover{\n              assume a03:\"\\<not>(\\<forall>i<length l. fst (l!i) = Call c)\"\n              then obtain i where i:\"(i<length l \\<and> fst (l!i) \\<noteq> Call c)\"\n                by auto\n              then obtain j where cfg_j:\"fst (l!j) \\<noteq> Call c \\<and> (\\<forall>k<j. fst (l!k) = Call c)\"                     \n                by (fast dest: exists_first_occ[of \"\\<lambda>i. fst (l!i) \\<noteq> Call c\" i])\n              moreover have j:\"j>0 \\<and> j<length l\" using l i calculation\n                by (metis gr0I fstI leI le_less_trans nth_Cons') \n              ultimately have step:\"(\\<Gamma>\\<turnstile>\\<^sub>c (l!(j-1)) \\<rightarrow> (l!j))\"\n                using l l_cptn\n                by (metis One_nat_def Suc_pred cptn_stepc_rtran diff_less not_eq_not_env prod.collapse \n                   step_ce_elim_cases zero_less_one)\n              then obtain s' where j_1_cfg:\"snd (l!(j-1)) = Normal s' \\<and> s' \\<in> p\"\n                using cfg_j l a01[simplified l] j[simplified l] i Sta events_p[OF l_cptn[simplified l] _ _ _ Sta, of \"j-1\"]\n                by force\n              then have j_cfg:\"l!j = (the (\\<Gamma> c), Normal s')\" \n                using cfg_j c_dom stepc_Normal_elim_cases(9) step\n                by (metis diff_less domIff j option.sel prod.collapse zero_less_one)  \n              then have suc_n_call:\"(Suc n,\\<Gamma>, drop (j-1) l) \\<in> cptn_mod_nest_call\" \n                using a01 unfolding cpn_def\n                by (simp add: dropcptn_is_cptn1 j less_imp_diff_less)\n              have \"(n,\\<Gamma>, drop j l) \\<in> cptn_mod_nest_call\" \n              proof-\n                have \"\\<not> (\\<Gamma>\\<turnstile>\\<^sub>c (l!(j-1)) \\<rightarrow>\\<^sub>e (l!j))\" using step\n                  by (metis etranE mod_env_not_component)\n                then have \"(Suc n,\\<Gamma>, (Call c, Normal s')#(the (\\<Gamma> c),Normal s')#(drop (j+1) l)) \\<in> cptn_mod_nest_call\"\n                  using a01 j step cfg_j j_cfg j_1_cfg  suc_n_call\n                  by (metis (no_types, lifting) Cons_nth_drop_Suc One_nat_def Suc_eq_plus1 \n                    Suc_less_eq Suc_pred diff_less less_SucI prod.collapse zero_less_one)                  \n                then have \"(n,\\<Gamma>, (the (\\<Gamma> c),Normal s')#(drop (j+1) l)) \\<in> cptn_mod_nest_call\"\n                  using cfg_j j_cfg  elim_cptn_mod_nest_call_n_dec[OF _ ] c_dom by fastforce\n                then show ?thesis\n                  by (metis Cons_nth_drop_Suc Suc_eq_plus1 j j_cfg)\n              qed\n              moreover have \"(\\<Gamma>, drop j l) \\<in> assum(p,R)\" \n              proof-   \n                have \"(\\<Gamma>, take j l @ l ! j # drop (Suc j) l) \\<in> assum (p, R)\"\n                  using conjunct2[OF a01] id_take_nth_drop[OF conjunct2[OF j]] by auto                             \n                then show ?thesis \n                  using sub_assum_r[OF ]  j_1_cfg l j_cfg j\n                  by (metis Cons_nth_drop_Suc image_eqI snd_conv)                  \n              qed                              \n              ultimately have comm_drop:\"(\\<Gamma>, drop j l)\\<in> comm(G, (q,a)) F\"\n                using valid_body j_cfg j unfolding com_validityn_def cpn_def \n                by fastforce\n              have \"(\\<Gamma>,l) \\<in> comm(G, (q,a)) F\" \n              proof-\n                have h:\"\\<forall>j<length (take j l). fst ((take j l)!j) = (Call c)\" using j cfg_j by fastforce\n                then have comm_take:\"(\\<Gamma>,take j l) \\<in> comm(G, (q,a)) F\"\n                  using no_comp_tran_no_final_comm[of \"take j l\" \"Call c\"] j_1_cfg l j_cfg j cfg_j \n                  unfolding final_def by auto                \n                moreover have \"(snd (last (take j l)), snd (drop j l ! 0)) \\<in> G\"\n                proof-\n                  have \"length (take j l) = j\"using l j_1_cfg j j_cfg by auto\n                  moreover have \"(take j l)!(j-1) = l!(j-1)\"\n                    using l j_1_cfg j j_cfg by auto\n                  ultimately have \"last (take j l) = l!(j-1)\"\n                    using  j by (metis last_conv_nth less_numeral_extra(3) list.size(3)) \n                  then  show ?thesis using l j_1_cfg j j_cfg guar by auto\n                qed                                 \n                ultimately show ?thesis using  j_1_cfg j_cfg j cfg_j j l_cptn\n                  comm_union[OF comm_take comm_drop] by fastforce\n              qed                 \n             } ultimately have \"(\\<Gamma>,l)\\<in>comm(G, (q,a)) F\" by auto\n           }ultimately  have \"(\\<Gamma>,l)\\<in>comm(G, (q,a)) F\" by fastforce         \n         } thus ?thesis unfolding com_validityn_def using cpn_rule2 by blast \n       qed\n      } thus ?case by fastforce\n    qed\n  qed \n  then show ?thesis using a0 unfolding com_cvalidityn_def by auto     \nqed\n\nlemma Seq_env_P:assumes a0:\"\\<Gamma>\\<turnstile>\\<^sub>c(Seq P Q,s) \\<rightarrow>\\<^sub>e (Seq P Q,t)\"\n      shows \"\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow>\\<^sub>e (P,t)\"\nusing a0\nby (metis env_not_normal_s snormal_enviroment)\n\nlemma map_eq_state:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Seq c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \" and\n  a2:\"l1=map (lift c2) l2\"\nshows\n  \"\\<forall>i<length l1. snd (l1!i) = snd (l2!i)\"\nusing a0 a1 a2 unfolding cp_def\nby (simp add: snd_lift) \n\nlemma map_eq_seq_c:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Seq c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \" and\n  a2:\"l1=map (lift c2) l2\"\nshows\n  \"\\<forall>i<length l1. fst (l1!i) = Seq (fst (l2!i)) c2\"\nproof -\n  {fix i\n  assume a3:\"i<length l1\"\n  have \"fst (l1!i) = Seq (fst (l2!i)) c2\"\n  using a0 a1 a2 a3 unfolding lift_def\n    by (simp add: case_prod_unfold) \n  }thus ?thesis by auto\nqed \n\nlemma same_env_seq_c:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Seq c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \" and\n  a2:\"l1=map (lift c2) l2\"\nshows\n\"\\<forall>i. Suc i<length l2 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow>\\<^sub>e (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow>\\<^sub>e (l1!(Suc i))\" \nproof -\n  have a0a:\"(\\<Gamma>,l1) \\<in>cptn \\<and> l1!0 = ((Seq c1 c2),s)\" \n    using a0 unfolding cp_def by blast\n  have a1a: \"(\\<Gamma>,l2) \\<in>cptn \\<and> l2!0 = (c1,s)\"\n    using a1 unfolding cp_def by blast\n  {\n    fix i\n    assume a3:\"Suc i< length l2\"\n    have \"\\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow>\\<^sub>e (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow>\\<^sub>e (l1!(Suc i))\"\n    proof\n    {\n      assume a4:\"\\<Gamma>\\<turnstile>\\<^sub>c l2 ! i \\<rightarrow>\\<^sub>e l2 ! Suc i\"\n      obtain c1i s1i c1si s1si where l1prod:\"l1 ! i=(c1i,s1i) \\<and> l1!Suc i = (c1si,s1si)\"\n        by fastforce\n      obtain c2i s2i c2si s2si where l2prod:\"l2 ! i=(c2i,s2i) \\<and> l2!Suc i = (c2si,s2si)\"\n        by fastforce\n      then have \"c1i = (Seq c2i c2) \\<and> c1si = (Seq c2si c2)\"\n        using  a0 a1 a2 a3 a4  map_eq_seq_c l1prod\n        by (metis Suc_lessD  fst_conv length_map)\n      also have \"s2i=s1i \\<and> s2si=s1si\"\n        using  a0 a1 a4  a2 a3 l2prod map_eq_state l1prod\n        by (metis Suc_lessD  nth_map snd_conv snd_lift)        \n      ultimately show \"\\<Gamma>\\<turnstile>\\<^sub>c l1 ! i \\<rightarrow>\\<^sub>e (l1 ! Suc i)\" \n        using a4 l1prod l2prod\n        by (metis Env_n env_c_c' env_not_normal_s step_e.Env)\n    } \n    {\n      assume a4:\"\\<Gamma>\\<turnstile>\\<^sub>c l1 ! i \\<rightarrow>\\<^sub>e l1 ! Suc i\"\n      obtain c1i s1i c1si s1si where l1prod:\"l1 ! i=(c1i,s1i) \\<and> l1!Suc i = (c1si,s1si)\"\n        by fastforce\n      obtain c2i s2i c2si s2si where l2prod:\"l2 ! i=(c2i,s2i) \\<and> l2!Suc i = (c2si,s2si)\"\n        by fastforce\n      then have \"c1i = (Seq c2i c2) \\<and> c1si = (Seq c2si c2)\"\n        using  a0 a1 a2 a3 a4  map_eq_seq_c l1prod\n        by (metis Suc_lessD  fst_conv length_map)\n      also have \"s2i=s1i \\<and> s2si=s1si\"\n        using  a0 a1 a4  a2 a3 l2prod map_eq_state l1prod\n        by (metis Suc_lessD  nth_map snd_conv snd_lift)        \n      ultimately show \"\\<Gamma>\\<turnstile>\\<^sub>c l2 ! i \\<rightarrow>\\<^sub>e (l2 ! Suc i)\" \n        using a4 l1prod l2prod        \n        by (metis Env_n LanguageCon.com.inject(3) env_c_c' env_not_normal_s step_e.Env)   \n    }\n    qed\n   } \n  thus ?thesis by auto\nqed\n\n\n\nlemma same_comp_seq_c:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Seq c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \" and\n  a2:\"l1=map (lift c2) l2\"\nshows\n\"\\<forall>i. Suc i<length l2 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow> (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow> (l1!(Suc i))\" \nproof -\n  have a0a:\"(\\<Gamma>,l1) \\<in>cptn \\<and> l1!0 = ((Seq c1 c2),s)\" \n    using a0 unfolding cp_def by blast\n  have a1a: \"(\\<Gamma>,l2) \\<in>cptn \\<and> l2!0 = (c1,s)\"\n    using a1 unfolding cp_def by blast\n  {\n    fix i\n    assume a3:\"Suc i< length l2\"\n    have \"\\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow> (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow> (l1!(Suc i))\"\n    proof\n    {\n      assume a4:\"\\<Gamma>\\<turnstile>\\<^sub>c l2 ! i \\<rightarrow> l2 ! Suc i\"\n      obtain c1i s1i c1si s1si where l1prod:\"l1 ! i=(c1i,s1i) \\<and> l1!Suc i = (c1si,s1si)\"\n        by fastforce\n      obtain c2i s2i c2si s2si where l2prod:\"l2 ! i=(c2i,s2i) \\<and> l2!Suc i = (c2si,s2si)\"\n        by fastforce\n      then have \"c1i = (Seq c2i c2) \\<and> c1si = (Seq c2si c2)\"\n        using  a0 a1 a2 a3 a4  map_eq_seq_c l1prod\n        by (metis Suc_lessD  fst_conv length_map)\n      also have \"s2i=s1i \\<and> s2si=s1si\"\n        using  a0 a1 a4  a2 a3 l2prod map_eq_state l1prod\n        by (metis Suc_lessD  nth_map snd_conv snd_lift)        \n      ultimately show \"\\<Gamma>\\<turnstile>\\<^sub>c l1 ! i \\<rightarrow> (l1 ! Suc i)\" \n        using a4 l1prod l2prod\n        by (simp add: Seqc)        \n    } \n    {\n      assume a4:\"\\<Gamma>\\<turnstile>\\<^sub>c l1 ! i \\<rightarrow> l1 ! Suc i\"\n      obtain c1i s1i c1si s1si where l1prod:\"l1 ! i=(c1i,s1i) \\<and> l1!Suc i = (c1si,s1si)\"\n        by fastforce\n      obtain c2i s2i c2si s2si where l2prod:\"l2 ! i=(c2i,s2i) \\<and> l2!Suc i = (c2si,s2si)\"\n        by fastforce\n      then have \"c1i = (Seq c2i c2) \\<and> c1si = (Seq c2si c2)\"\n        using  a0 a1 a2 a3 a4  map_eq_seq_c l1prod\n        by (metis Suc_lessD  fst_conv length_map)\n      also have \"s2i=s1i \\<and> s2si=s1si\"\n        using  a0 a1 a4  a2 a3 l2prod map_eq_state l1prod\n        by (metis Suc_lessD  nth_map snd_conv snd_lift)        \n      ultimately show \"\\<Gamma>\\<turnstile>\\<^sub>c l2 ! i \\<rightarrow> (l2 ! Suc i)\" \n        using a4 l1prod l2prod stepc_elim_cases_Seq_Seq\n      by auto           \n    }\n    qed\n   } \n  thus ?thesis by auto\nqed\n\nlemma assum_map:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Seq c1 c2) s) \\<and> ((\\<Gamma>,l1) \\<in> assum(p, R))\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \" and\n  a2:\"l1=map (lift c2) l2\"  \nshows\n  \"((\\<Gamma>,l2) \\<in> assum(p, R))\"\nproof -\n  have a3: \"\\<forall>i. Suc i<length l2 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow>\\<^sub>e (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow>\\<^sub>e (l1!(Suc i))\" \n    using a0 a1 a2 same_env_seq_c by fastforce\n  have pair_\\<Gamma>l1:\"fst (\\<Gamma>,l1) = \\<Gamma> \\<and> snd (\\<Gamma>,l1) = l1\" by fastforce\n  have pair_\\<Gamma>l2:\"fst (\\<Gamma>,l2) = \\<Gamma> \\<and> snd (\\<Gamma>,l2) = l2\" by fastforce\n  have drop_k_s:\"l2!0 = (c1,s)\" using a1 cp_def by blast\n  have eq_length:\"length l1 = length l2\" using a2 by auto\n  obtain s' where normal_s:\"s = Normal s'\" \n    using  a0  unfolding cp_def   assum_def  by fastforce\n  then have p1:\"s'\\<in>p\" using a0 unfolding cp_def assum_def by fastforce  \n  show ?thesis \n  proof -    \n    let ?c= \"(\\<Gamma>,l2)\"\n    have l:\"snd((snd ?c!0)) \\<in> Normal ` (p)\"\n     using p1 drop_k_s a1 normal_s unfolding cp_def by auto\n    {fix i\n     assume a00:\"Suc i<length (snd ?c)\" \n     assume a11:\"(fst ?c)\\<turnstile>\\<^sub>c((snd ?c)!i)  \\<rightarrow>\\<^sub>e ((snd ?c)!(Suc i))\"\n     have \"(snd((snd ?c)!i), snd((snd ?c)!(Suc i))) \\<in> R\"\n     using a0 a1 a2 a3 map_eq_state unfolding assum_def \n     using a00 a11 eq_length by fastforce\n    } thus \"(\\<Gamma>, l2) \\<in> assum (p, R)\" \n      using l unfolding assum_def by fastforce  \n  qed  \nqed\n\nlemma comm_map':\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Seq c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \\<and> (\\<Gamma>, l2)\\<in> comm(G, (q,a)) F\" and\n  a2:\"l1=map (lift c2) l2\" \nshows\n  \"snd (last l1) \\<notin> Fault ` F  \\<longrightarrow>(Suc k < length l1 \\<longrightarrow>\n       \\<Gamma>\\<turnstile>\\<^sub>c(l1!k)  \\<rightarrow> (l1!(Suc k)) \\<longrightarrow> \n       (snd(l1!k), snd(l1!(Suc k))) \\<in>  G) \\<and> \n   (fst (last l1) = (Seq c c2) \\<and> final (c, snd (last l1)) \\<longrightarrow>     \n      (fst (last l1) = (Seq Skip c2) \\<and> \n        (snd (last  l1) \\<in> Normal ` q) \\<or>\n      (fst (last l1) = (Seq Throw c2) \\<and> \n        snd (last l1) \\<in> Normal ` (a))))\n     \"\nproof -\n  have a3:\"\\<forall>i. Suc i<length l2 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow> (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow> (l1!(Suc i))\" \n    using a0 a1 a2 same_comp_seq_c\n    by fastforce\n  have pair_\\<Gamma>l1:\"fst (\\<Gamma>,l1) = \\<Gamma> \\<and> snd (\\<Gamma>,l1) = l1\" by fastforce\n  have pair_\\<Gamma>l2:\"fst (\\<Gamma>,l2) = \\<Gamma> \\<and> snd (\\<Gamma>,l2) = l2\" by fastforce\n  have drop_k_s:\"l2!0 = (c1,s)\" using a1 cp_def by blast\n  have eq_length:\"length l1 = length l2\" using a2 by auto \n  then have len0:\"length l1>0\" using a0 unfolding cp_def \n    using Collect_case_prodD drop_k_s eq_length by auto\n  then have l1_not_empty:\"l1\\<noteq>[]\" by auto\n  then have l2_not_empty:\"l2 \\<noteq> []\" using a2 by blast       \n   have last_lenl1:\"last l1 = l1!((length l1) -1)\" \n        using last_conv_nth l1_not_empty by auto\n  have last_lenl2:\"last l2 = l2!((length l2) -1)\" \n       using last_conv_nth l2_not_empty by auto \n  have a03:\"snd (last l2) \\<notin> Fault ` F  \\<longrightarrow>(\\<forall>i ns ns'.                 \n               Suc i<length (snd (\\<Gamma>, l2)) \\<longrightarrow> \n               fst (\\<Gamma>, l2)\\<turnstile>\\<^sub>c((snd (\\<Gamma>, l2))!i)  \\<rightarrow> ((snd (\\<Gamma>, l2))!(Suc i)) \\<longrightarrow>                               \n                 (snd((snd (\\<Gamma>, l2))!i), snd((snd (\\<Gamma>, l2))!(Suc i))) \\<in> G) \\<and> \n               (final (last (snd (\\<Gamma>, l2)))  \\<longrightarrow>                 \n                  ((fst (last (snd (\\<Gamma>, l2))) = Skip \\<and> \n                    snd (last (snd (\\<Gamma>, l2))) \\<in> Normal ` q)) \\<or>\n                  (fst (last (snd (\\<Gamma>, l2))) = Throw \\<and> \n                    snd (last (snd (\\<Gamma>, l2))) \\<in> Normal ` (a)))\"\n  using a1 unfolding comm_def by fastforce\n  show ?thesis unfolding comm_def \n  proof -\n  { fix k ns ns'\n    assume a00a:\"snd (last l1) \\<notin> Fault ` F\"\n    assume a00:\"Suc k < length l1\"    \n    then have \"k \\<le> length l1\" using a2 by fastforce    \n    have a00:\"Suc k < length l2\" using eq_length a00 by fastforce\n    then have a00a:\"snd (last l2) \\<notin> Fault ` F\"\n    proof-\n      have \"snd (l1!((length l1) -1)) = snd (l2!((length l2) -1))\"      \n        using a2 a1 a0  map_eq_state eq_length l2_not_empty last_snd \n        by fastforce \n      then have \"snd(last l2) = snd (last l1)\"\n        using last_lenl1 last_lenl2 by auto\n      thus ?thesis using a00a by auto\n    qed\n    then have \"snd (last l1) \\<notin> Fault ` F \\<longrightarrow>\\<Gamma>\\<turnstile>\\<^sub>c(l1!k)  \\<rightarrow> (l1!(Suc k)) \\<longrightarrow>       \n      (snd((snd (\\<Gamma>, l1))!k), snd((snd (\\<Gamma>, l1))!(Suc k))) \\<in>  G\"\n    using  pair_\\<Gamma>l1 pair_\\<Gamma>l2 a00  a03 a3  eq_length a00a\n     by (metis Suc_lessD a0 a1 a2 map_eq_state)\n  } note l=this\n  {\n    assume a00: \"fst (last l1) = (Seq c c2) \\<and> final (c, snd (last l1))\" and\n           a01:\"snd (last (l1)) \\<notin> Fault ` F\"\n    then have c:\"c=Skip \\<or> c = Throw\"\n     unfolding final_def by auto    \n    then have fst_last_l2:\"fst (last l2) = c\"                               \n      using  last_lenl1 a00 l1_not_empty eq_length len0 a2 last_conv_nth last_lift \n      by fastforce      \n    also have last_eq:\"snd (last l2) = snd (last l1)\"      \n      using l2_not_empty a2 last_conv_nth last_lenl1 last_snd \n      by fastforce\n    ultimately have \"final (fst (last l2),snd (last l2))\" \n     using a00 by auto\n    then have \"final (last l2)\" by auto\n    also have \"snd (last (l2)) \\<notin> Fault ` F\"\n       using  last_eq a01 by auto\n    ultimately have \"(fst (last  l2)) = Skip \\<and> \n                    snd (last  l2) \\<in> Normal ` q \\<or>\n                  (fst (last l2) = Throw \\<and> \n                    snd (last l2) \\<in> Normal ` (a))\"\n    using a03 by auto\n    then have \"(fst (last l1) = (Seq Skip c2) \\<and> \n                    snd (last  l1) \\<in> Normal ` q) \\<or>\n                  (fst (last l1) = (Seq Throw c2) \\<and> \n                    snd (last l1) \\<in> Normal ` (a))\"\n    using last_eq fst_last_l2 a00 by force\n  }\n  thus ?thesis using l by auto qed\nqed\n\nlemma comm_map'':\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Seq c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \\<and> (\\<Gamma>, l2)\\<in> comm(G, (q,a)) F\" and\n  a2:\"l1=map (lift c2) l2\" \nshows\n  \"snd (last l1) \\<notin> Fault ` F \\<longrightarrow> ((Suc k < length l1 \\<longrightarrow>\n       \\<Gamma>\\<turnstile>\\<^sub>c(l1!k)  \\<rightarrow> (l1!(Suc k)) \\<longrightarrow>        \n       (snd(l1!k), snd(l1!(Suc k))) \\<in> G) \\<and> \n   (final (last l1) \\<longrightarrow>     \n      (fst (last l1) = Skip \\<and> \n        (snd (last  l1) \\<in> Normal ` r) \\<or>\n      (fst (last l1) = Throw \\<and> \n        snd (last l1) \\<in> Normal ` (a)))))\n     \"\nproof -\n  have a3:\"\\<forall>i. Suc i<length l2 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow> (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow> (l1!(Suc i))\" \n    using a0 a1 a2 same_comp_seq_c\n    by fastforce\n  have pair_\\<Gamma>l1:\"fst (\\<Gamma>,l1) = \\<Gamma> \\<and> snd (\\<Gamma>,l1) = l1\" by fastforce\n  have pair_\\<Gamma>l2:\"fst (\\<Gamma>,l2) = \\<Gamma> \\<and> snd (\\<Gamma>,l2) = l2\" by fastforce\n  have drop_k_s:\"l2!0 = (c1,s)\" using a1 cp_def by blast\n  have eq_length:\"length l1 = length l2\" using a2 by auto \n  then have len0:\"length l1>0\" using a0 unfolding cp_def \n    using Collect_case_prodD drop_k_s eq_length by auto\n  then have l1_not_empty:\"l1\\<noteq>[]\" by auto\n  then have l2_not_empty:\"l2 \\<noteq> []\" using a2 by blast       \n  have last_lenl1:\"last l1 = l1!((length l1) -1)\" \n        using last_conv_nth l1_not_empty by auto\n  have last_lenl2:\"last l2 = l2!((length l2) -1)\" \n       using last_conv_nth l2_not_empty by auto \n  have a03:\"snd (last l2) \\<notin> Fault ` F \\<longrightarrow>(\\<forall>i ns ns'.                 \n               Suc i<length (snd (\\<Gamma>, l2)) \\<longrightarrow> \n               fst (\\<Gamma>, l2)\\<turnstile>\\<^sub>c((snd (\\<Gamma>, l2))!i)  \\<rightarrow> ((snd (\\<Gamma>, l2))!(Suc i)) \\<longrightarrow>                                            \n                 (snd((snd (\\<Gamma>, l2))!i), snd((snd (\\<Gamma>, l2))!(Suc i))) \\<in> G) \\<and> \n               (final (last (snd (\\<Gamma>, l2)))  \\<longrightarrow>                 \n                  ((fst (last (snd (\\<Gamma>, l2))) = Skip \\<and> \n                    snd (last (snd (\\<Gamma>, l2))) \\<in> Normal ` q)) \\<or>\n                  (fst (last (snd (\\<Gamma>, l2))) = Throw \\<and> \n                    snd (last (snd (\\<Gamma>, l2))) \\<in> Normal ` (a)))\"\n  using a1 unfolding comm_def by fastforce\n  show ?thesis unfolding comm_def \n  proof -\n  { fix k ns ns'\n    assume a00a:\"snd (last l1) \\<notin> Fault ` F\"\n    assume a00:\"Suc k < length l1\"    \n    then have \"k \\<le> length l1\" using a2 by fastforce    \n    have a00:\"Suc k < length l2\" using eq_length a00 by fastforce   \n    then have a00a:\"snd (last l2) \\<notin> Fault ` F\"\n    proof-\n      have \"snd (l1!((length l1) -1)) = snd (l2!((length l2) -1))\"      \n        using a2 a1 a0  map_eq_state eq_length l2_not_empty last_snd \n        by fastforce \n      then have \"snd(last l2) = snd (last l1)\"\n        using last_lenl1 last_lenl2 by auto\n      thus ?thesis using a00a by auto\n    qed \n    then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l1!k)  \\<rightarrow> (l1!(Suc k)) \\<longrightarrow>         \n        (snd((snd (\\<Gamma>, l1))!k), snd((snd (\\<Gamma>, l1))!(Suc k))) \\<in> G\"\n       using  pair_\\<Gamma>l1 pair_\\<Gamma>l2 a00  a03 a3  eq_length a00a\n      by (metis (no_types,lifting) a2 Suc_lessD nth_map snd_lift)\n    } note l= this\n    {\n     assume a00: \"final (last l1)\"           \n     then have c:\"fst (last l1)=Skip \\<or> fst (last l1) = Throw\"\n       unfolding final_def by auto \n     moreover have \"fst (last l1) = Seq (fst (last l2)) c2\" \n       using a2 last_lenl1 eq_length\n      proof -\n        have \"last l2 = l2 ! (length l2 - 1)\"\n          using l2_not_empty last_conv_nth by blast\n        then show ?thesis\n          by (metis One_nat_def a2 l2_not_empty last_lenl1 last_lift)\n      qed\n      ultimately have False by simp  \n    } thus ?thesis using l  by auto qed\nqed\n\nlemma comm_map:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Seq c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \\<and> (\\<Gamma>, l2)\\<in> comm(G, (q,a)) F\" and\n  a2:\"l1=map (lift c2) l2\" \nshows\n  \"(\\<Gamma>, l1)\\<in> comm(G, (r,a)) F\"\nproof - \n  {fix i \n   have \"snd (last l1) \\<notin> Fault ` F  \\<longrightarrow>(Suc i < length (l1) \\<longrightarrow>\n        \\<Gamma>\\<turnstile>\\<^sub>c (l1 ! i) \\<rightarrow> (l1 ! (Suc i)) \\<longrightarrow>       \n        (snd (l1 ! i), snd (l1 ! Suc i)) \\<in> G) \\<and>\n        (SmallStepCon.final (last l1) \\<longrightarrow>                  \n                   fst (last l1) = LanguageCon.com.Skip \\<and>\n                   snd (last l1) \\<in> Normal ` r \\<or>\n                   fst (last l1) = LanguageCon.com.Throw \\<and>\n                   snd (last l1) \\<in> Normal ` a) \"\n      using comm_map''[of \\<Gamma> l1 c1 c2 s l2 G q a F i r] a0 a1 a2 \n      by fastforce\n   }  then show ?thesis using comm_def unfolding comm_def by force       \nqed\n(* declare[[show_types]]\nlemma \"(SOME e. e\\<in>{1::nat,2,3}) = 1 \\<or> (SOME e. e\\<in>{1::nat,2,3}) = 2 \\<or> (SOME e. e\\<in>{1::nat,2,3}) = 3\"\n  apply auto\n  by (metis (mono_tags, lifting) someI)*)\n\n\nlemma Seq_sound1:\nassumes\n  a0:\"(n,\\<Gamma>,x)\\<in>cptn_mod_nest_call\" and\n  a1:\"x!0 = ((Seq P Q),s)\" and\n  a2:\"\\<forall>i<length x. fst (x!i)\\<noteq> Q\" and\n  a3:\"\\<not> final (last x)\" and\n  a4:\"env_tran_right \\<Gamma> x rely\" and\n  a5:\"snd (x!0)\\<in> Normal ` p \\<and> Sta p rely \\<and> Sta a rely \" and \n  a6: \"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> P sat [p, rely, G, q,a]\" \nshows\n  \"\\<exists>xs. (\\<Gamma>,xs) \\<in> cpn n \\<Gamma> P s \\<and> x = map (lift Q) xs\"\nusing a0 a1 a2 a3 a4  a5 a6\nproof (induct arbitrary: P s p) \n  case (CptnModNestOne n \\<Gamma> C s1)\n  then have \"(\\<Gamma>, [(P,s)]) \\<in> cpn n \\<Gamma> P s \\<and> [(C, s1)] = map (lift Q) [(P,s)]\"\n    unfolding cpn_def lift_def\n    by (simp add: cptn_mod_nest_call.CptnModNestOne) \n  thus ?case by fastforce\nnext\n  case (CptnModNestEnv \\<Gamma> C s1 t1 n xsa)\n  then have C:\"C=Seq P Q\" unfolding lift_def by fastforce\n  have \"\\<exists>xs. (\\<Gamma>, xs) \\<in> cpn n \\<Gamma> P t1 \\<and> (C, t1) # xsa = map (lift Q) xs\"\n  proof -\n     have \"((C, t1) # xsa) ! 0 = (LanguageCon.com.Seq P Q, t1)\" using C by auto\n     moreover have \"\\<forall>i<length ((C, t1) # xsa). fst (((C, t1) # xsa) ! i) \\<noteq> Q\"\n       using CptnModNestEnv(5) by fastforce\n     moreover have \"\\<not> SmallStepCon.final (last ((C, t1) # xsa))\" using CptnModNestEnv(6) \n       by fastforce\n     moreover have \"snd (((C, t1) # xsa) ! 0) \\<in> Normal ` p\" \n       using CptnModNestEnv(8) CptnModNestEnv(1) CptnModNestEnv(7)\n       unfolding env_tran_right_def Sta_def by fastforce \n     ultimately show ?thesis\n       using CptnModNestEnv(3) CptnModNestEnv(7) CptnModNestEnv(8)  CptnModNestEnv(9) env_tran_tail by blast\n  qed \n  then obtain xs where hi:\"(\\<Gamma>, xs) \\<in> cpn n \\<Gamma> P t1 \\<and> (C, t1) # xsa = map (lift Q) xs\"\n    by fastforce\n  have s1_s:\"s1=s\" using  CptnModNestEnv unfolding cpn_def by auto\n  obtain xsa' where xs:\"xs=((P,t1)#xsa') \\<and> (n, \\<Gamma>,((P,t1)#xsa'))\\<in>cptn_mod_nest_call \\<and> (C, t1) # xsa = map (lift Q) ((P,t1)#xsa')\" \n    using hi  unfolding cpn_def by fastforce  \n  have env_tran:\"\\<Gamma>\\<turnstile>\\<^sub>c(P,s1) \\<rightarrow>\\<^sub>e (P,t1)\" using CptnModNestEnv Seq_env_P by (metis fst_conv nth_Cons_0)  \n  then have \"(n, \\<Gamma>,(P,s1)#(P,t1)#xsa')\\<in>cptn_mod_nest_call\" \n    using xs env_tran cptn_mod_nest_call.CptnModNestEnv by fastforce  \n  then have \"(\\<Gamma>,(P,s1)#(P,t1)#xsa') \\<in> cpn n \\<Gamma> P s\" \n    using cpn_def s1_s by fastforce\n  moreover have \"(C,s1)#(C, t1) # xsa = map (lift Q) ((P,s1)#(P,t1)#xsa')\"\n    using xs C unfolding lift_def by fastforce\n  ultimately show ?case by auto\nnext\n  case (CptnModNestSkip)\n  thus ?case by (metis SmallStepCon.redex_not_Seq fst_conv nth_Cons_0)\nnext\n  case (CptnModNestThrow)\n  thus ?case by (metis SmallStepCon.redex_not_Seq fst_conv nth_Cons_0)\nnext\n  case (CptnModNestSeq1 n \\<Gamma> P0 sa xsa zs P1)\n  then have a1:\"LanguageCon.com.Seq P Q = LanguageCon.com.Seq P0 P1\"\n    by fastforce  \n  have f1: \"sa = s\"\n    using CptnModNestSeq1.prems(1) by force\n  have f2: \"P = P0 \\<and> Q = P1\" using a1 by auto  \n  hence \"(\\<Gamma>, (P0, sa) # xsa) \\<in> cpn n \\<Gamma> P s\"\n    using f2 f1 CptnModNestSeq1.hyps(1) by (simp add: cpn_def)\n  thus ?case\n    using Cons_lift CptnModNestSeq1.hyps(3) a1 by fastforce   \nnext\n  case (CptnModNestSeq2 n \\<Gamma> P0 sa xsa P1 ys zs) \n  then have \"P0 = P \\<and> P1 = Q\" by auto\n  then obtain i where zs:\"fst (zs!i) = Q \\<and> (i< (length zs))\" using CptnModNestSeq2\n    by (metis (no_types, lifting) add_diff_cancel_left' fst_conv length_Cons length_append nth_append_length zero_less_Suc zero_less_diff)    \n  then have \"Suc i< length ((Seq P0 P1,sa)#zs)\" by fastforce\n  then have \"fst (((Seq P0 P1, sa) # zs)!Suc i) = Q\" using zs by fastforce    \n  thus ?case using CptnModNestSeq2(8) zs by auto\nnext\n  case (CptnModNestSeq3 n \\<Gamma> P1 sa xsa s' ys zs Q1 )          \n  have s'_a:\"s' \\<in>  a\"   \n  proof -\n    have  cpP1:\"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> cpn n \\<Gamma> P1 (Normal sa)\" \n      using CptnModNestSeq3.hyps(1)  unfolding cpn_def by fastforce\n    then have  cpP1':\"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> cp \\<Gamma> P1 (Normal sa)\"\n      using CptnModNestSeq3.hyps(1)  cptn_eq_cptn_mod_set cptn_mod_nest_cptn_mod \n      unfolding cp_def by fastforce       \n    have map:\"((Seq P1 Q1), Normal sa)#(map (lift Q1) xsa) = map (lift Q1)  ((P1, Normal sa) # xsa) \"\n      using CptnModSeq3 by (simp add: Cons_lift) \n    then \n    have \"(\\<Gamma>,((LanguageCon.com.Seq P1 Q1, Normal sa) # (map (lift Q1) xsa))) \\<in> assum (p,rely)\"\n    proof - \n      have \"env_tran_right \\<Gamma> ((LanguageCon.com.Seq P1 Q1, Normal sa) # (map (lift Q1) xsa)) rely\" \n        using  CptnModNestSeq3(11) CptnModNestSeq3(7) map\n        by (metis (no_types) Cons_lift_append CptnModNestSeq3.hyps(7) CptnModNestSeq3.prems(4) env_tran_subr) \n      thus ?thesis using CptnModNestSeq3(12) \n      unfolding assum_def env_tran_right_def by fastforce  \n    qed\n    moreover have \"(\\<Gamma>,((Seq P1 Q1), Normal sa)#(map (lift Q1) xsa)) \\<in> cpn n \\<Gamma> (Seq P1 Q1) (Normal sa)\"\n      using CptnModNestSeq3(7) CptnModNestSeq3.hyps(1)  cptn_mod_nest_call.CptnModNestSeq1\n      unfolding cpn_def by fastforce  \n    then have  \"(\\<Gamma>,((Seq P1 Q1), Normal sa)#(map (lift Q1) xsa)) \\<in> cp \\<Gamma> (Seq P1 Q1) (Normal sa)\"\n      using CptnModNestSeq3.hyps(1)  cptn_eq_cptn_mod_set cptn_mod.CptnModSeq1 cptn_mod_nest_cptn_mod \n      unfolding cp_def by fastforce      \n    ultimately have  \"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> assum (p,rely)\" \n      using assum_map map cpP1' by fastforce\n    then have \"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> comm (G,(q,a)) F\" \n      using cpP1 CptnModNestSeq3(13)  CptnModNestSeq3.prems(1) unfolding com_validityn_def by auto\n    thus ?thesis   \n      using CptnModNestSeq3(3)  CptnModNestSeq3(4)\n      unfolding comm_def final_def by fastforce\n  qed\n  have \"final (last ((LanguageCon.com.Throw, Normal s')# ys))\"\n  proof -\n    have cptn_mod:\"(n, \\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn_mod_nest_call\" \n      using CptnModNestSeq3(5) by (simp add: cptn_eq_cptn_mod_set)\n    then have cptn:\"(\\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn\"\n      using cptn_eq_cptn_mod_nest by auto\n    moreover have throw_0:\"((LanguageCon.com.Throw, Normal s') # ys)!0 = (Throw, Normal s') \\<and> 0 < length((LanguageCon.com.Throw, Normal s') # ys)\"\n      by force         \n    moreover have last:\"last ((LanguageCon.com.Throw, Normal s') # ys) = ((LanguageCon.com.Throw, Normal s') # ys)!((length ((LanguageCon.com.Throw, Normal s') # ys)) - 1)\"\n      using last_conv_nth by auto\n    moreover have env_tran:\"env_tran_right \\<Gamma> ((LanguageCon.com.Throw, Normal s') # ys) rely\" \n      using  CptnModNestSeq3(11)  CptnModNestSeq3(7) env_tran_subl env_tran_tail by blast           \n    ultimately obtain st' where \"fst (last ((LanguageCon.com.Throw, Normal s') # ys)) = Throw \\<and>        \n                     snd (last ((LanguageCon.com.Throw, Normal s') # ys)) = Normal st'\" \n    using zero_throw_all_throw[of \\<Gamma> \"((Throw, Normal s') # ys)\" \"s'\" \"(length ((Throw, Normal s') # ys))-1\" a rely]\n          s'_a CptnModNestSeq3(11) CptnModNestSeq3(12) by fastforce      \n    thus ?thesis using CptnModNestSeq3(10) final_def by blast\n  qed\n  thus ?case using CptnModNestSeq3(10) CptnModNestSeq3(7)\n    by force\nqed (auto)\n\nlemma Seq_sound2: \nassumes\n  a0:\"(\\<Gamma>,x)\\<in>cptn_mod\" and\n  a1:\"x!0 = ((Seq P Q),s)\" and\n  a2:\"\\<forall>i<length x. fst (x!i)\\<noteq> Q\" and\n  a3:\"fst (last x) = Throw \\<and> snd (last x) = Normal s'\" and\n  a4:\"env_tran_right \\<Gamma> x rely\"\nshows\n  \"\\<exists>xs s' ys. (\\<Gamma>,xs) \\<in> cp \\<Gamma> P s \\<and> x = ((map (lift Q) xs)@((Throw, Normal s')#ys))\"\nusing a0 a1 a2 a3 a4\nproof (induct arbitrary: P s s')\n  case (CptnModOne \\<Gamma> C s1)\n  then have \"(\\<Gamma>, [(P,s)]) \\<in> cp \\<Gamma> P s \\<and> [(C, s1)] = map (lift Q) [(P,s)]@[(Throw, Normal s')]\"\n    unfolding cp_def lift_def  by (simp add: cptn.CptnOne) \n  thus ?case by fastforce\nnext\n  case (CptnModEnv \\<Gamma> C s1 t1 xsa)\n  then have C:\"C=Seq P Q\" unfolding lift_def by fastforce\n  have \"\\<exists>xs s' ys. (\\<Gamma>, xs) \\<in> cp \\<Gamma> P t1 \\<and> (C, t1) # xsa = map (lift Q) xs@((Throw, Normal s')#ys)\"\n  proof -\n     have \"((C, t1) # xsa) ! 0 = (LanguageCon.com.Seq P Q, t1)\" using C by auto\n     moreover have \"\\<forall>i<length ((C, t1) # xsa). fst (((C, t1) # xsa) ! i) \\<noteq> Q\"\n       using CptnModEnv(5) by fastforce\n     moreover have \"fst (last ((C, t1) # xsa)) = Throw \\<and> snd (last ((C, t1) # xsa)) = Normal s'\" using CptnModEnv(6) \n       by fastforce\n     ultimately show ?thesis\n       using CptnModEnv(3) CptnModEnv(7) env_tran_tail by blast     \n  qed \n  then obtain xs s'' ys where hi:\"(\\<Gamma>, xs) \\<in> cp \\<Gamma> P t1 \\<and> (C, t1) # xsa = map (lift Q) xs@((Throw, Normal s'')#ys)\"\n    by fastforce\n  have s1_s:\"s1=s\" using  CptnModEnv unfolding cp_def by auto\n  have \"\\<exists>xsa' s'' ys. xs=((P,t1)#xsa') \\<and> (\\<Gamma>,((P,t1)#xsa'))\\<in>cptn \\<and> (C, t1) # xsa = map (lift Q) ((P,t1)#xsa')@((Throw, Normal s'')#ys)\" \n    using hi  unfolding cp_def\n  proof -\n      have \"(\\<Gamma>,xs)\\<in>cptn \\<and> xs!0 = (P,t1)\" using hi unfolding cp_def by fastforce\n      moreover then have \"xs\\<noteq>[]\" using cptn.simps by fastforce  \n      ultimately obtain xsa' where \"xs=((P,t1)#xsa')\" using SmallStepCon.nth_tl by fastforce \n      thus ?thesis\n        using hi using \\<open>(\\<Gamma>, xs) \\<in> cptn \\<and> xs ! 0 = (P, t1)\\<close> by auto \n  qed\n  then obtain xsa' s'' ys where xs:\"xs=((P,t1)#xsa') \\<and> (\\<Gamma>,((P,t1)#xsa'))\\<in>cptn \\<and> (C, t1) # xsa = map (lift Q) ((P,t1)#xsa')@((Throw, Normal s'')#ys)\"\n    by fastforce\n  have env_tran:\"\\<Gamma>\\<turnstile>\\<^sub>c(P,s1) \\<rightarrow>\\<^sub>e (P,t1)\" using CptnModEnv Seq_env_P by (metis fst_conv nth_Cons_0)  \n  then have \"(\\<Gamma>,(P,s1)#(P,t1)#xsa')\\<in>cptn\" using xs env_tran CptnEnv by fastforce  \n  then have \"(\\<Gamma>,(P,s1)#(P,t1)#xsa') \\<in> cp \\<Gamma> P s\" \n    using cp_def s1_s by fastforce\n  moreover have \"(C,s1)#(C, t1) # xsa = map (lift Q) ((P,s1)#(P,t1)#xsa')@((Throw, Normal s'')#ys)\"\n    using xs C unfolding lift_def by fastforce\n  ultimately show ?case by auto\nnext\n  case (CptnModSkip)\n  thus ?case by (metis SmallStepCon.redex_not_Seq fst_conv nth_Cons_0)\nnext\n  case (CptnModThrow)\n  thus ?case by (metis SmallStepCon.redex_not_Seq fst_conv nth_Cons_0)\nnext\n  case (CptnModSeq1 \\<Gamma> P0 sa xsa zs P1)  \n  thus ?case    \n  proof -\n    have a1:\"\\<forall>c p. fst (case p of (ca::('s, 'a, 'd,'e) LanguageCon.com, x::('s, 'd) xstate) \\<Rightarrow> \n                (LanguageCon.com.Seq ca c, x)) = LanguageCon.com.Seq (fst p) c\"\n      by simp\n    then have \"[] = xsa\"     \n    proof -\n     have \"[] \\<noteq> zs\"\n       using CptnModSeq1 by force\n     then show ?thesis\n       by (metis (no_types) LanguageCon.com.distinct(71) One_nat_def CptnModSeq1(3,6) \n                            last.simps last_conv_nth last_lift)\n    qed   \n    then have \"\\<forall>c. Throw = c \\<or> [] = zs\"\n      using CptnModSeq1(3) by fastforce\n    then show ?thesis\n      using CptnModSeq1.prems(3) by force\n  qed   \nnext\n  case (CptnModSeq2 \\<Gamma> P0 sa xsa P1 ys zs) \n  then have \"P0 = P \\<and> P1 = Q\" by auto\n  then obtain i where zs:\"fst (zs!i) = Q \\<and> (i< (length zs))\" using CptnModSeq2\n    by (metis (no_types, lifting) add_diff_cancel_left' fst_conv length_Cons length_append nth_append_length zero_less_Suc zero_less_diff)    \n  then have \"Suc i< length ((Seq P0 P1,sa)#zs)\" by fastforce\n  then have \"fst (((Seq P0 P1, sa) # zs)!Suc i) = Q\" using zs by fastforce    \n  thus ?case using CptnModSeq2(8) zs by auto\nnext \n  case (CptnModSeq3 \\<Gamma> P0 sa xsa s'' ys zs P1)  \n  then have \"P0 = P \\<and> P1 = Q \\<and> s=Normal sa\" by auto  \n  moreover then have \"(\\<Gamma>, (P0, Normal sa) # xsa)\\<in> cp \\<Gamma> P s\" \n    using CptnModSeq3(1)\n    by (simp add: cp_def cptn_eq_cptn_mod_set)  \n  moreover have \"last zs=(Throw, Normal s')\" using CptnModSeq3(10) CptnModSeq3.hyps(7) \n    by (simp add: prod_eqI)    \n  ultimately show ?case using  CptnModSeq3(7)\n    using Cons_lift_append by blast      \nqed (auto)\n\n\nlemma Seq_sound2': \nassumes\n  a0:\"(n,\\<Gamma>,x)\\<in>cptn_mod_nest_call\" and\n  a1:\"x!0 = ((Seq P Q),s)\" and\n  a2:\"\\<forall>i<length x. fst (x!i)\\<noteq> Q\" and\n  a3:\"fst (last x) = Throw \\<and> snd (last x) = Normal s'\" and\n  a4:\"env_tran_right \\<Gamma> x rely\"\nshows\n  \"\\<exists>xs s' ys. (\\<Gamma>,xs) \\<in> cpn n \\<Gamma> P s \\<and> x = ((map (lift Q) xs)@((Throw, Normal s')#ys))\"\nusing a0 a1 a2 a3 a4\nproof (induct arbitrary: P s s')\n  case (CptnModNestOne n \\<Gamma> C s1)\n  then have \"(\\<Gamma>, [(P,s)]) \\<in> cpn n \\<Gamma> P s \\<and> [(C, s1)] = map (lift Q) [(P,s)]@[(Throw, Normal s')]\"\n    unfolding cp_def lift_def  by (simp add: cptn.CptnOne) \n  thus ?case by fastforce\nnext\n  case (CptnModNestEnv \\<Gamma> C s1 t1 n xsa)\n  then have C:\"C=Seq P Q\" unfolding lift_def by fastforce\n  have \"\\<exists>xs s' ys. (\\<Gamma>, xs) \\<in> cpn n \\<Gamma> P t1 \\<and> (C, t1) # xsa = map (lift Q) xs@((Throw, Normal s')#ys)\"\n  proof -\n     have \"((C, t1) # xsa) ! 0 = (LanguageCon.com.Seq P Q, t1)\" using C by auto\n     moreover have \"\\<forall>i<length ((C, t1) # xsa). fst (((C, t1) # xsa) ! i) \\<noteq> Q\"\n       using CptnModNestEnv(5) by fastforce\n     moreover have \"fst (last ((C, t1) # xsa)) = Throw \\<and> snd (last ((C, t1) # xsa)) = Normal s'\" \n       using CptnModNestEnv(6) \n       by fastforce\n     ultimately show ?thesis\n       using CptnModNestEnv(3) CptnModNestEnv(7) env_tran_tail by blast     \n  qed \n  then obtain xs s'' ys where hi:\"(\\<Gamma>, xs) \\<in> cpn n \\<Gamma> P t1 \\<and> (C, t1) # xsa = map (lift Q) xs@((Throw, Normal s'')#ys)\"\n    by fastforce\n  have s1_s:\"s1=s\" using  CptnModNestEnv unfolding cp_def by auto\n  have \"\\<exists>xsa' s'' ys. xs=((P,t1)#xsa') \\<and> (n, \\<Gamma>,((P,t1)#xsa'))\\<in>cptn_mod_nest_call \\<and> (C, t1) # xsa = map (lift Q) ((P,t1)#xsa')@((Throw, Normal s'')#ys)\" \n    using hi  unfolding cp_def\n  proof -\n      have \"(n, \\<Gamma>,xs)\\<in>cptn_mod_nest_call \\<and> xs!0 = (P,t1)\" using hi unfolding cpn_def by fastforce\n      moreover then have \"xs\\<noteq>[]\" using cptn_mod_nest_call.simps by fastforce  \n      ultimately obtain xsa' where \"xs=((P,t1)#xsa')\" using SmallStepCon.nth_tl by fastforce \n      thus ?thesis\n        using hi using \\<open>(n, \\<Gamma>, xs) \\<in> cptn_mod_nest_call \\<and> xs ! 0 = (P, t1)\\<close> by auto \n  qed\n  then obtain xsa' s'' ys where xs:\"xs=((P,t1)#xsa') \\<and> (n, \\<Gamma>,((P,t1)#xsa'))\\<in>cptn_mod_nest_call \\<and> \n                (C, t1) # xsa = map (lift Q) ((P,t1)#xsa')@((Throw, Normal s'')#ys)\"\n    by fastforce\n  have env_tran:\"\\<Gamma>\\<turnstile>\\<^sub>c(P,s1) \\<rightarrow>\\<^sub>e (P,t1)\" using CptnModNestEnv Seq_env_P by (metis fst_conv nth_Cons_0)  \n  then have \"(n, \\<Gamma>,(P,s1)#(P,t1)#xsa')\\<in>cptn_mod_nest_call\" using xs env_tran cptn_mod_nest_call.CptnModNestEnv by blast    \n  then have \"(\\<Gamma>,(P,s1)#(P,t1)#xsa') \\<in> cpn n \\<Gamma> P s\" \n    using cpn_def s1_s by fastforce\n  moreover have \"(C,s1)#(C, t1) # xsa = map (lift Q) ((P,s1)#(P,t1)#xsa')@((Throw, Normal s'')#ys)\"\n    using xs C unfolding lift_def by fastforce\n  ultimately show ?case by auto\nnext\n  case (CptnModNestSkip)\n  thus ?case by (metis SmallStepCon.redex_not_Seq fst_conv nth_Cons_0)\nnext\n  case (CptnModNestThrow)\n  thus ?case by (metis SmallStepCon.redex_not_Seq fst_conv nth_Cons_0)\nnext\n  case (CptnModNestSeq1 n \\<Gamma> P0 sa xsa zs P1)  \n  thus ?case    \n  proof -\n    have a1:\"\\<forall>c p. fst (case p of (ca::('s, 'a, 'd,'e) LanguageCon.com, x::('s, 'd) xstate) \\<Rightarrow> \n                (LanguageCon.com.Seq ca c, x)) = LanguageCon.com.Seq (fst p) c\"\n      by simp\n    then have \"[] = xsa\"     \n    proof -\n     have \"[] \\<noteq> zs\"\n       using CptnModNestSeq1 by force\n     then show ?thesis\n       by (metis (no_types) LanguageCon.com.distinct(71) One_nat_def CptnModNestSeq1(3,6) \n                            last.simps last_conv_nth last_lift)\n    qed   \n    then have \"\\<forall>c. Throw = c \\<or> [] = zs\"\n      using CptnModNestSeq1(3) by fastforce\n    then show ?thesis\n      using CptnModNestSeq1.prems(3) by force\n  qed   \nnext\n  case (CptnModNestSeq2 n \\<Gamma> P0 sa xsa P1 ys zs) \n  then have \"P0 = P \\<and> P1 = Q\" by auto\n  then obtain i where zs:\"fst (zs!i) = Q \\<and> (i< (length zs))\" using CptnModNestSeq2\n    by (metis (no_types, lifting) add_diff_cancel_left' fst_conv length_Cons length_append nth_append_length zero_less_Suc zero_less_diff)    \n  then have \"Suc i< length ((Seq P0 P1,sa)#zs)\" by fastforce\n  then have \"fst (((Seq P0 P1, sa) # zs)!Suc i) = Q\" using zs by fastforce    \n  thus ?case using CptnModNestSeq2(8) zs by auto\nnext \n  case (CptnModNestSeq3 n \\<Gamma> P0 sa xsa s'' ys zs P1)  \n  then have \"P0 = P \\<and> P1 = Q \\<and> s=Normal sa\" by auto  \n  moreover then have \"(\\<Gamma>, (P0, Normal sa) # xsa)\\<in> cpn n \\<Gamma> P s\" \n    using CptnModNestSeq3(1)\n    by (simp add: cpn_def)  \n  moreover have \"last zs=(Throw, Normal s')\" using CptnModNestSeq3(10) CptnModNestSeq3.hyps(7) \n    by (simp add: prod_eqI)    \n  ultimately show ?case using  CptnModNestSeq3(7)\n    using Cons_lift_append by blast      \nqed (auto)\n\nlemma Last_Skip_Exist_Final: \nassumes\n  a0:\"(\\<Gamma>,x)\\<in>cptn\" and\n  a1:\"x!0 = ((Seq P Q),s)\" and\n  a2:\"\\<forall>i<length x. fst (x!i)\\<noteq> Q\" and\n  a3:\"fst(last x) = Skip\"  \nshows \n  \"\\<exists>c s' i. i<length x \\<and> x!i = (Seq c Q,s') \\<and> final (c,s')\"\nusing a0 a1 a2 a3 \nproof (induct arbitrary: P s)\n  case (CptnOne \\<Gamma> c s1) thus ?case by fastforce \nnext\n  case (CptnEnv \\<Gamma> C st t xsa) \n  thus ?case \n  proof -         \n    have \"LanguageCon.com.Seq P Q = C\"\n      using CptnEnv.prems(1) by auto\n    then show ?thesis\n      using CptnEnv.hyps(3) CptnEnv.prems(2) CptnEnv.prems(3) by fastforce\n  qed\nnext\n  case (CptnComp \\<Gamma> C st C' st' xsa) \n  then have c_seq:\"C = (Seq P Q) \\<and> st = s\" by force\n  from CptnComp show ?case proof(cases)\n    case (Seqc P1 P1' P2) \n    then have \"\\<exists>c s' i. i < length ((C', st') # xsa) \\<and> \n                        ((C', st') # xsa) ! i = (LanguageCon.com.Seq c Q, s') \\<and> \n                        SmallStepCon.final (c, s')\"\n      using CptnComp last.simps  by fastforce\n    thus ?thesis by fastforce \n  next\n    case (SeqThrowc C2 s') \n    thus ?thesis \n    proof -\n      have \"LanguageCon.com.Seq LanguageCon.com.Throw Q = C\"\n        using \\<open>C = LanguageCon.com.Seq LanguageCon.com.Throw C2\\<close> c_seq by blast\n      then show ?thesis\n        using \\<open>st = Normal s'\\<close> unfolding final_def by force\n    qed\n  next\n    case (FaultPropc) thus ?thesis \n      using c_seq redex_not_Seq by blast\n  next\n    case (StuckPropc) thus ?thesis \n      using c_seq redex_not_Seq by blast\n  next \n    case (AbruptPropc) thus ?thesis\n     using c_seq redex_not_Seq by blast \n  qed (auto)\nqed\n\nlemma Seq_sound3:                                                       \nassumes\n  a0:\"(n,\\<Gamma>,x)\\<in>cptn_mod_nest_call\" and\n  a1:\"x!0 = ((Seq P Q),s)\" and\n  a2:\"\\<forall>i<length x. fst (x!i)\\<noteq> Q\" and\n  a3:\"fst(last x) = Skip\" and\n  a4:\"env_tran_right \\<Gamma> x rely \" and\n  a5:\"snd (x!0)\\<in> Normal ` p \\<and> Sta p rely \\<and> Sta a rely\" and\n  a6: \"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> P sat [p, rely, G, q,a]\"\nshows\n  \"False\"\nusing a0 a1 a2 a3 a4 a5 a6\nproof (induct arbitrary: P s p) (* p) *)\n  case (CptnModNestOne n \\<Gamma> C s1)  \n    thus ?case by fastforce\nnext\n  case (CptnModNestEnv \\<Gamma> C s1 t1 n xsa)\n  then have C:\"C=Seq P Q\" unfolding lift_def by fastforce\n  thus ?case\n  proof -\n     have \"((C, t1) # xsa) ! 0 = (LanguageCon.com.Seq P Q, t1)\" using C by auto\n     moreover have \"\\<forall>i<length ((C, t1) # xsa). fst (((C, t1) # xsa) ! i) \\<noteq> Q\"\n       using CptnModNestEnv(5) by fastforce\n     moreover have \"fst (last ((C, t1) # xsa)) = LanguageCon.com.Skip\" using CptnModNestEnv(6)\n       by (simp add: SmallStepCon.final_def)        \n     moreover have \"snd (((C, t1) # xsa) ! 0) \\<in> Normal ` p\" \n       using CptnModNestEnv(8) CptnModNestEnv(1) CptnModNestEnv(7)\n       unfolding env_tran_right_def Sta_def by fastforce \n     ultimately show ?thesis\n       using CptnModNestEnv(3) CptnModNestEnv(7) CptnModNestEnv(8)  CptnModNestEnv(9) env_tran_tail\n       by blast\n  qed  \nnext\n  case (CptnModNestSkip)\n  thus ?case by (metis SmallStepCon.redex_not_Seq fst_conv nth_Cons_0)\nnext\n  case (CptnModNestThrow)\n  thus ?case by (metis SmallStepCon.redex_not_Seq fst_conv nth_Cons_0)\nnext\n  case (CptnModNestSeq1 n \\<Gamma> P0 sa xsa zs P1)\n  obtain cl where \"fst (last ((LanguageCon.com.Seq P0 P1, sa) # zs)) = Seq cl P1\"\n    using CptnModNestSeq1(3) by (metis One_nat_def fst_conv last.simps last_conv_nth last_lift map_is_Nil_conv)\n  thus ?case using CptnModNestSeq1(6) by auto\nnext\n case (CptnModNestSeq2 n \\<Gamma> P0 sa xsa P1 ys zs) \n  then have \"P0 = P \\<and> P1 = Q\" by auto\n  then obtain i where zs:\"fst (zs!i) = Q \\<and> (i< (length zs))\" using CptnModNestSeq2\n    by (metis (no_types, lifting) add_diff_cancel_left' fst_conv length_Cons length_append nth_append_length zero_less_Suc zero_less_diff)        \n  thus ?case using CptnModNestSeq2(8) zs by auto \nnext\n   case (CptnModNestSeq3 n \\<Gamma> P1 sa xsa s' ys zs Q1 )  \n  have s'_a:\"s' \\<in>  a\"   \n  proof -\n    have  cpnP1:\"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> cpn n \\<Gamma> P1 (Normal sa)\" \n      using CptnModNestSeq3.hyps(1)  unfolding  cpn_def\n      by fastforce   \n    then have  cpP1:\"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> cp \\<Gamma> P1 (Normal sa)\" \n      using CptnModNestSeq3.hyps(1)   cptn_mod_nest_cptn_mod cptn_if_cptn_mod unfolding cp_def cpn_def\n      by fastforce  \n    have map:\"((Seq P1 Q1), Normal sa)#(map (lift Q1) xsa) = map (lift Q1)  ((P1, Normal sa) # xsa) \"\n      using CptnModNestSeq3 by (simp add: Cons_lift) \n    then \n    have \"(\\<Gamma>,((LanguageCon.com.Seq P1 Q1, Normal sa) # (map (lift Q1) xsa))) \\<in> assum (p,rely)\"\n    proof - \n      have \"env_tran_right \\<Gamma> ((LanguageCon.com.Seq P1 Q1, Normal sa) # (map (lift Q1) xsa)) rely\" \n        using  CptnModNestSeq3(11) CptnModNestSeq3(7) map\n        by (metis (no_types) Cons_lift_append CptnModNestSeq3.hyps(7) CptnModNestSeq3.prems(4) env_tran_subr) \n      thus ?thesis using CptnModNestSeq3(12) \n      unfolding assum_def env_tran_right_def by fastforce  \n    qed\n    moreover have \"(\\<Gamma>,((Seq P1 Q1), Normal sa)#(map (lift Q1) xsa)) \\<in> cpn n \\<Gamma> (Seq P1 Q1) (Normal sa)\"\n      using  CptnModNestSeq3.hyps(1) \n            CptnModNestSeq1\n      unfolding  cpn_def by fastforce  \n    then have \"(\\<Gamma>,((Seq P1 Q1), Normal sa)#(map (lift Q1) xsa)) \\<in> cp \\<Gamma> (Seq P1 Q1) (Normal sa)\"\n      using CptnModNestSeq3.hyps(1) cp_def cptn_eq_cptn_mod_set \n            cptn_mod.CptnModSeq1 cptn_mod_nest_cptn_mod by fastforce\n    ultimately have  \"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> assum (p,rely)\" \n      using assum_map map cpP1 by fastforce\n    then have \"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> comm (G,(q,a)) F\" \n      using cpnP1 CptnModNestSeq3(13)  CptnModNestSeq3.prems(1) unfolding com_validityn_def by auto\n    thus ?thesis   \n      using CptnModNestSeq3(3)  CptnModNestSeq3(4)\n      unfolding comm_def final_def by fastforce\n  qed\n  have \"fst (last ((LanguageCon.com.Throw, Normal s') # ys)) = Throw\"\n  proof -\n    have cptn:\"(\\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn\" \n      using CptnModNestSeq3(5)\n      using cptn_eq_cptn_mod_nest by blast \n    moreover have throw_0:\"((LanguageCon.com.Throw, Normal s') # ys)!0 = (Throw, Normal s') \\<and> 0 < length((LanguageCon.com.Throw, Normal s') # ys)\"\n      by force         \n    moreover have last:\"last ((LanguageCon.com.Throw, Normal s') # ys) = ((LanguageCon.com.Throw, Normal s') # ys)!((length ((LanguageCon.com.Throw, Normal s') # ys)) - 1)\"\n      using last_conv_nth by auto\n    moreover have env_tran:\"env_tran_right \\<Gamma> ((LanguageCon.com.Throw, Normal s') # ys) rely\" \n      using  CptnModNestSeq3(11)  CptnModNestSeq3(7) env_tran_subl env_tran_tail by blast           \n    ultimately obtain st' where \"fst (last ((LanguageCon.com.Throw, Normal s') # ys)) = Throw \\<and>        \n                     snd (last ((LanguageCon.com.Throw, Normal s') # ys)) = Normal st'\" \n    using zero_throw_all_throw[of \\<Gamma> \"((Throw, Normal s') # ys)\" \"s'\" \"(length ((Throw, Normal s') # ys))-1\" a rely]\n          s'_a CptnModNestSeq3(11) CptnModNestSeq3(12) by fastforce      \n    thus ?thesis using CptnModNestSeq3(10) final_def by blast\n  qed\n  thus ?case using CptnModNestSeq3(10) CptnModNestSeq3(7)\n    by force\nqed(auto)\n\nlemma map_xs_ys:\n  assumes\n  a0:\"(\\<Gamma>, (P0, sa) # xsa) \\<in> cptn_mod\" and    \n  a1:\"fst (last ((P0, sa) # xsa)) = C\" and\n  a2:\"(\\<Gamma>, (P1, snd (last ((P0, sa) # xsa))) # ys) \\<in> cptn_mod\" and\n  a3:\"zs = map (lift P1) xsa @ (P1, snd (last ((P0, sa) # xsa))) # ys\" and\n  a4:\"((LanguageCon.com.Seq P0 P1, sa) # zs) ! 0 = (LanguageCon.com.Seq P Q, s)\" and\n  a5:\"i < length ((LanguageCon.com.Seq P0 P1, sa) # zs) \\<and> ((LanguageCon.com.Seq P0 P1, sa) # zs) ! i = (Q, sj)\" and\n  a6:\"\\<forall>j<i. fst (((LanguageCon.com.Seq P0 P1, sa) # zs) ! j) \\<noteq> Q\"\nshows \n  \"\\<exists>xs ys. (\\<Gamma>, xs) \\<in> cp \\<Gamma> P s \\<and>\n            (\\<Gamma>, ys) \\<in> cp \\<Gamma> Q (snd (xs ! (i - 1))) \\<and> (LanguageCon.com.Seq P0 P1, sa) # zs = map (lift Q) xs @ ys\"\nproof -\n  let ?P0 = \"(P0, sa) # xsa\"\n  have P_Q:\"P=P0 \\<and> s=sa \\<and> Q = P1\" using a4 by force\n  have i:\"i=(length ((P0, sa) # xsa))\"   \n  proof (cases \"i=(length ((P0, sa) # xsa))\")\n    case True thus ?thesis by auto\n  next\n    case False     \n    then have i:\"i<(length ((P0, sa) # xsa)) \\<or> i > (length ((P0, sa) # xsa))\" by auto\n    {\n      assume i:\"i<(length ((P0, sa) # xsa))\"\n      then have eq_map:\"((LanguageCon.com.Seq P0 P1, sa) # zs) ! i = map (lift P1) ((P0, sa) # xsa) ! i\" \n        using a3 Cons_lift_append by (metis (no_types, lifting) length_map nth_append) \n      then have  \"\\<exists>ci si. map (lift P1) ((P0, sa) # xsa) ! i = (Seq ci P1,si)\" \n        using i unfolding lift_def\n        proof -\n          have \"map (\\<lambda>(c, y). (LanguageCon.com.Seq c P1, y)) ((P0, sa) # xsa) ! i = (case ((P0, sa) # xsa) ! i of (c, x) \\<Rightarrow> (LanguageCon.com.Seq c P1, x))\"\n            by (meson \\<open>i < length ((P0, sa) # xsa)\\<close> nth_map)\n          then show \"\\<exists>c x. map (\\<lambda>(c, x). (LanguageCon.com.Seq c P1, x)) ((P0, sa) # xsa) ! i = (LanguageCon.com.Seq c P1, x)\"\n            by (simp add: case_prod_beta)\n        qed \n      then have  \"((LanguageCon.com.Seq P0 P1, sa) # zs) ! i \\<noteq> (Q, sj)\" \n        using P_Q eq_map by fastforce\n      then have ?thesis using a5 by auto\n    }note l=this\n    {\n      assume i:\"i>(length ((P0, sa) # xsa))\"\n      have \"fst (((LanguageCon.com.Seq P0 P1, sa) # zs) ! (length ?P0)) = Q\"\n        using a3 P_Q Cons_lift_append by (metis fstI length_map nth_append_length) \n      then have ?thesis using a6 i by auto\n    }\n    thus ?thesis using l i by auto\n   qed\n   then have  \"(\\<Gamma>, (P0, sa) # xsa) \\<in> cp \\<Gamma> P s\" \n    using a0  cptn_eq_cptn_mod P_Q unfolding cp_def by fastforce\n  also have \"(\\<Gamma>, (P1, snd (last ((P0, sa) # xsa))) # ys) \\<in> cp \\<Gamma> Q (snd (?P0 ! ((length ?P0) -1)))\" \n    using a3 cptn_eq_cptn_mod P_Q unfolding cp_def\n  proof -\n    have \"(\\<Gamma>, (Q, snd (last ((P0, sa) # xsa))) # ys) \\<in> cptn_mod\"\n      using a2 P_Q by blast\n    then have \"(\\<Gamma>, (Q, snd (last ((P0, sa) # xsa))) # ys) \\<in> {(f, ps). ps ! 0 = (Q, snd (((P0, sa) # xsa) ! (Suc (length xsa) - 1))) \\<and> (\\<Gamma>, ps) \\<in> cptn \\<and> f = \\<Gamma>}\"\n      by (simp add: cptn_eq_cptn_mod last_length)\n    then show \"(\\<Gamma>, (P1, snd (last ((P0, sa) # xsa))) # ys) \\<in> {(f, ps). ps ! 0 = (Q, snd (((P0, sa) # xsa) ! (length ((P0, sa) # xsa) - 1))) \\<and> (\\<Gamma>, ps) \\<in> cptn \\<and> f = \\<Gamma>}\"\n      using P_Q by force\n  qed \n  ultimately show ?thesis using a3 P_Q i using Cons_lift_append by blast\nqed\n\nlemma map_xs_ys':\n  assumes\n  a0:\"(n, \\<Gamma>, (P0, sa) # xsa) \\<in> cptn_mod_nest_call\" and    \n  a1:\"fst (last ((P0, sa) # xsa)) = C\" and\n  a2:\"(n,\\<Gamma>, (P1, snd (last ((P0, sa) # xsa))) # ys) \\<in> cptn_mod_nest_call\" and\n  a3:\"zs = map (lift P1) xsa @ (P1, snd (last ((P0, sa) # xsa))) # ys\" and\n  a4:\"((LanguageCon.com.Seq P0 P1, sa) # zs) ! 0 = (LanguageCon.com.Seq P Q, s)\" and\n  a5:\"i < length ((LanguageCon.com.Seq P0 P1, sa) # zs) \\<and> ((LanguageCon.com.Seq P0 P1, sa) # zs) ! i = (Q, sj)\" and\n  a6:\"\\<forall>j<i. fst (((LanguageCon.com.Seq P0 P1, sa) # zs) ! j) \\<noteq> Q\"\nshows \n  \"\\<exists>xs ys. (\\<Gamma>, xs) \\<in> cpn n \\<Gamma> P s \\<and>\n            (\\<Gamma>, ys) \\<in> cpn n \\<Gamma> Q (snd (xs ! (i - 1))) \\<and> (LanguageCon.com.Seq P0 P1, sa) # zs = map (lift Q) xs @ ys\"\nproof -\n  let ?P0 = \"(P0, sa) # xsa\"\n  have P_Q:\"P=P0 \\<and> s=sa \\<and> Q = P1\" using a4 by force\n  have i:\"i=(length ((P0, sa) # xsa))\"   \n  proof (cases \"i=(length ((P0, sa) # xsa))\")\n    case True thus ?thesis by auto\n  next\n    case False     \n    then have i:\"i<(length ((P0, sa) # xsa)) \\<or> i > (length ((P0, sa) # xsa))\" by auto\n    {\n      assume i:\"i<(length ((P0, sa) # xsa))\"\n      then have eq_map:\"((LanguageCon.com.Seq P0 P1, sa) # zs) ! i = map (lift P1) ((P0, sa) # xsa) ! i\" \n        using a3 Cons_lift_append by (metis (no_types, lifting) length_map nth_append) \n      then have  \"\\<exists>ci si. map (lift P1) ((P0, sa) # xsa) ! i = (Seq ci P1,si)\" \n        using i unfolding lift_def\n        proof -\n          have \"map (\\<lambda>(c, y). (LanguageCon.com.Seq c P1, y)) ((P0, sa) # xsa) ! i = (case ((P0, sa) # xsa) ! i of (c, x) \\<Rightarrow> (LanguageCon.com.Seq c P1, x))\"\n            by (meson \\<open>i < length ((P0, sa) # xsa)\\<close> nth_map)\n          then show \"\\<exists>c x. map (\\<lambda>(c, x). (LanguageCon.com.Seq c P1, x)) ((P0, sa) # xsa) ! i = (LanguageCon.com.Seq c P1, x)\"\n            by (simp add: case_prod_beta)\n        qed \n      then have  \"((LanguageCon.com.Seq P0 P1, sa) # zs) ! i \\<noteq> (Q, sj)\" \n        using P_Q eq_map by fastforce\n      then have ?thesis using a5 by auto\n    }note l=this\n    {\n      assume i:\"i>(length ((P0, sa) # xsa))\"\n      have \"fst (((LanguageCon.com.Seq P0 P1, sa) # zs) ! (length ?P0)) = Q\"\n        using a3 P_Q Cons_lift_append by (metis fstI length_map nth_append_length) \n      then have ?thesis using a6 i by auto\n    }\n    thus ?thesis using l i by auto\n   qed\n   then have  \"(\\<Gamma>, (P0, sa) # xsa) \\<in> cpn n \\<Gamma> P s\" \n    using a0  P_Q unfolding cpn_def by fastforce\n  also have \"(\\<Gamma>, (P1, snd (last ((P0, sa) # xsa))) # ys) \\<in> cpn n \\<Gamma> Q (snd (?P0 ! ((length ?P0) -1)))\" \n    using a3 cptn_eq_cptn_mod P_Q unfolding cpn_def\n  proof -\n    have \"(n, \\<Gamma>, (Q, snd (last ((P0, sa) # xsa))) # ys) \\<in> cptn_mod_nest_call\"\n      using a2 P_Q by blast\n    then have \"(\\<Gamma>, (Q, snd (last ((P0, sa) # xsa))) # ys) \\<in> {(f, ps). ps ! 0 = (Q, snd (((P0, sa) # xsa) ! (Suc (length xsa) - 1))) \\<and> \n              (n, \\<Gamma>, ps) \\<in> cptn_mod_nest_call \\<and> f = \\<Gamma>}\"\n      by (simp add: cptn_eq_cptn_mod last_length)\n    then show \"(\\<Gamma>, (P1, snd (last ((P0, sa) # xsa))) # ys) \\<in> {(f, ps). ps ! 0 = (Q, snd (((P0, sa) # xsa) ! (length ((P0, sa) # xsa) - 1))) \\<and> (n,\\<Gamma>, ps) \\<in> cptn_mod_nest_call \\<and> f = \\<Gamma>}\"\n      using P_Q by force\n  qed \n  ultimately show ?thesis using a3 P_Q i using Cons_lift_append by blast\nqed\n\n\n\nlemma Seq_sound4: \nassumes\n  a0:\"(n,\\<Gamma>,x)\\<in>cptn_mod_nest_call\" and\n  a1:\"x!0 = ((Seq P Q),s)\" and\n  a2:\"i<length x \\<and> x!i=(Q,sj)\" and\n  a3:\"\\<forall>j<i. fst(x!j)\\<noteq>Q\" and \n  a4:\"env_tran_right \\<Gamma> x rely\" and\n  a5:\"snd (x!0)\\<in> Normal ` p \\<and> Sta p rely \\<and> Sta a rely\" and\n  a6: \"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> P sat [p, rely, G, q,a]\"\nshows\n  \"\\<exists>xs ys. (\\<Gamma>,xs) \\<in> (cpn n \\<Gamma> P s) \\<and> (\\<Gamma>,ys) \\<in> (cpn n \\<Gamma> Q (snd (xs!(i-1)))) \\<and> x = (map (lift Q) xs)@ys\"\nusing a0 a1 a2 a3 a4 a5 a6\nproof (induct arbitrary: i sj P s p) \n   case (CptnModNestOne \\<Gamma> C s1)  \n    thus ?case by fastforce\nnext\n  case (CptnModNestEnv \\<Gamma> C st t n xsa)    \n  have a1:\"Seq P Q \\<noteq> Q\" by simp    \n  then have C_seq:\"C=(Seq P Q)\" using CptnModNestEnv by fastforce\n  then have \"fst(((C, st) # (C, t) # xsa)!0) \\<noteq>Q\" using CptnEnv a1 by auto\n  moreover have  n_q:\"fst(((C, st) # (C, t) # xsa)!1) \\<noteq>Q\" using CptnModNestEnv a1 by auto\n  moreover have \"fst(((C, st) # (C, t) # xsa)!i) =Q\" using CptnModNestEnv by auto\n  ultimately have i_suc: \"i> (Suc 0)\" \n    by (metis Suc_eq_plus1 Suc_lessI add.left_neutral neq0_conv) \n  then obtain i' where i':\"i=Suc i'\" by (meson lessE) \n  then have i_minus:\"i'=i-1\" by auto\n  have c_init:\"((C, t) # xsa) ! 0 = ((Seq P Q), t)\"\n    using CptnModNestEnv by auto \n  moreover have \"i'< length ((C,t)#xsa) \\<and> ((C,t)#xsa)!i' = (Q,sj)\"\n    using i' CptnModNestEnv(5) by force\n  moreover have \"\\<forall>j<i'. fst (((C, t) # xsa) ! j) \\<noteq> Q\"\n    using i' CptnModNestEnv(6) by force\n  moreover have \"snd (((C, t) # xsa) ! 0) \\<in> Normal ` p\" \n       using CptnModNestEnv(8) CptnModNestEnv(1) CptnModNestEnv(7)\n       unfolding env_tran_right_def Sta_def by fastforce \n  ultimately have hyp:\"\\<exists>xs ys.\n     (\\<Gamma>, xs) \\<in> cpn n \\<Gamma> P t \\<and>\n     (\\<Gamma>, ys) \\<in> cpn n \\<Gamma> Q (snd (xs ! (i'-1))) \\<and> (C, t) # xsa = map (lift Q) xs @ ys\"\n    using CptnModNestEnv(3) env_tran_tail  CptnModNestEnv(8) CptnModNestEnv(9) \n         CptnModNestEnv.prems(4) by blast  \n  then obtain xs ys where xs_cp:\"(\\<Gamma>, xs) \\<in> cpn n \\<Gamma> P t \\<and>\n     (\\<Gamma>, ys) \\<in> cpn n \\<Gamma> Q (snd (xs ! (i'-1))) \\<and> (C, t) # xsa = map (lift Q) xs @ ys\"\n    by fast\n  have \"(\\<Gamma>, (P,s)#xs) \\<in> cpn n \\<Gamma> P s\"\n  proof -\n    have \"xs!0 = (P,t)\" \n      using xs_cp unfolding cpn_def by blast\n    moreover have \"xs\\<noteq>[]\"\n      using xs_cp  n_q c_init unfolding cpn_def by auto \n    ultimately obtain xs' where xs':\"(n, \\<Gamma>, (P,t)#xs') \\<in> cptn_mod_nest_call \\<and> xs=(P,t)#xs'\" \n      using SmallStepCon.nth_tl xs_cp unfolding cpn_def by force\n    thus ?thesis \n    proof -\n      have \"(LanguageCon.com.Seq P Q, s) = (C, st)\"\n        using CptnModNestEnv.prems(1) by auto\n      then have \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow>\\<^sub>e (P, t)\"\n        using Seq_env_P CptnModNestEnv(1) by blast\n      then show ?thesis\n        by (simp add:xs' cpn_def cptn_mod_nest_call.CptnModNestEnv)\n    qed\n  qed\n  thus  ?case \n    using i_suc Cons_lift_append CptnModNestEnv.prems(1) i' i_minus xs_cp\n    by fastforce   \nnext\n  case (CptnModNestSkip)\n  thus ?case by (metis SmallStepCon.redex_not_Seq fst_conv nth_Cons_0)\nnext\n  case (CptnModNestThrow)\n  thus ?case by (metis SmallStepCon.redex_not_Seq fst_conv nth_Cons_0)\nnext\n  case (CptnModNestSeq1 n \\<Gamma> P0 sa xsa zs P1)  \n  then have P1_Q:\"P1 = Q\" by auto\n  let ?x = \"(LanguageCon.com.Seq P0 P1, sa) # zs\"\n  have \"\\<forall>j<length ?x. \\<exists>c s. ?x!j = (Seq c P1,s)\" using CptnModNestSeq1(3)\n  proof (induct xsa arbitrary: zs P0 P1 sa)\n    case Nil thus ?case by auto\n  next\n    case (Cons a xsa) \n    then obtain ac as where \"a=(ac,as)\" by fastforce\n    then have zs:\"zs = (Seq ac P1,as)#(map (lift P1)  xsa)\" \n      using Cons(2) \n      unfolding lift_def  by auto\n    have zs_eq:\"(map (lift P1)  xsa)=(map (lift P1)  xsa)\" by auto\n    note hyp=Cons(1)[OF zs_eq] \n    note hyp[of ac as]\n    thus ?case using zs Cons(2) by (metis One_nat_def diff_Suc_Suc diff_zero length_Cons less_Suc_eq_0_disj nth_Cons') \n  qed  \n  thus ?case using P1_Q CptnModNestSeq1(5) using fstI seq_not_eq2 by auto\nnext\n  case (CptnModNestSeq2 n \\<Gamma> P0 sa xsa P1 ys zs) \n  then show ?case using map_xs_ys'[OF CptnModNestSeq2(1) CptnModNestSeq2(3) CptnModNestSeq2(4) CptnModNestSeq2(6)\n                              CptnModNestSeq2(7) CptnModNestSeq2(8) CptnModNestSeq2(9)] by blast\nnext \n  case (CptnModNestSeq3 n \\<Gamma> P1 sa xsa s' ys zs Q1 ) \n  then have P_Q:\"P=P1 \\<and> Q = Q1\" by force\n  thus ?case\n  proof (cases \"Q1 = Throw\")\n    case True thus ?thesis using map_xs_ys'[of n \\<Gamma> P1 \"Normal sa\" xsa Throw Throw ys zs] \n      CptnModNestSeq3 by fastforce\n  next \n    case False note q_not_throw=this\n    have \"\\<forall>x. x< length ((LanguageCon.com.Seq P1 Q1, Normal sa) # zs) \\<longrightarrow>\n              ((LanguageCon.com.Seq P1 Q1, Normal sa) # zs) ! x \\<noteq> (Q, sj)\"\n    proof -\n    {\n      fix x\n      assume x_less:\"x< length ((LanguageCon.com.Seq P1 Q1, Normal sa) # zs)\"\n      have \"((LanguageCon.com.Seq P1 Q1, Normal sa) # zs) ! x \\<noteq> (Q, sj)\"\n      proof (cases \"x < length ((LanguageCon.com.Seq P1 Q1, Normal sa)#map (lift Q1) xsa)\")\n        case True \n        then have eq_map:\"((LanguageCon.com.Seq P1 Q1, Normal sa) # zs) ! x = map (lift Q1) ((P1, Normal sa) # xsa) ! x\"           \n          by (metis (no_types) Cons_lift Cons_lift_append CptnModNestSeq3.hyps(7) True nth_append)\n        then have  \"\\<exists>ci si. map (lift Q1) ((P1, Normal sa) # xsa) ! x = (Seq ci Q1,si)\" \n          using True unfolding lift_def\n        proof -\n          have \"x < length ((P1, Normal sa) # xsa)\"\n            using True by auto\n          then have \"map (\\<lambda>(c, y). (LanguageCon.com.Seq c Q1, y)) ((P1, Normal sa) # xsa) ! x = (case ((P1, Normal sa) # xsa) ! x of (c, x) \\<Rightarrow> (LanguageCon.com.Seq c Q1, x))\"\n            using nth_map by blast\n          then show \"\\<exists>c x1. map (\\<lambda>(c, x1). (LanguageCon.com.Seq c Q1, x1)) ((P1, Normal sa) # xsa) ! x = (LanguageCon.com.Seq c Q1, x1)\"\n            by (simp add: case_prod_beta')\n        qed            \n        then have  \"((LanguageCon.com.Seq P1 Q1, Normal sa) # zs) ! x \\<noteq> (Q, sj)\" \n          using P_Q eq_map by fastforce     \n        thus ?thesis using CptnModNestSeq3(10) by auto        \n      next\n        case False \n        have s'_a:\"s' \\<in>  a\"   \n        proof -\n        have  cpP1:\"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> cpn n \\<Gamma> P1 (Normal sa)\" \n          using CptnModNestSeq3.hyps(1) cptn_eq_cptn_mod_set unfolding cpn_def by fastforce\n        then have  cpP1':\"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> cp \\<Gamma> P1 (Normal sa)\" \n          unfolding cpn_def cp_def\n          using cptn_if_cptn_mod cptn_mod_nest_cptn_mod by fastforce \n        have map:\"((Seq P1 Q1), Normal sa)#(map (lift Q1) xsa) = map (lift Q1)  ((P1, Normal sa) # xsa) \"\n          using CptnModSeq3 by (simp add: Cons_lift) \n        then \n        have \"(\\<Gamma>,((LanguageCon.com.Seq P1 Q1, Normal sa) # (map (lift Q1) xsa))) \\<in> assum (p,rely)\"\n        proof - \n          have \"env_tran_right \\<Gamma> ((LanguageCon.com.Seq P1 Q1, Normal sa) # (map (lift Q1) xsa)) rely\" \n            using  CptnModNestSeq3(11) CptnModNestSeq3(7) map\n            by (metis (no_types) Cons_lift_append CptnModNestSeq3.hyps(7) CptnModNestSeq3.prems(4) env_tran_subr) \n          thus ?thesis using CptnModNestSeq3(12) \n          unfolding assum_def env_tran_right_def by fastforce  \n        qed\n        moreover have \"(\\<Gamma>,((Seq P1 Q1), Normal sa)#(map (lift Q1) xsa)) \\<in> cpn n \\<Gamma> (Seq P1 Q1) (Normal sa)\"\n          using CptnModNestSeq3(7) CptnModNestSeq3.hyps(1) cptn_eq_cptn_mod_set cptn_mod_nest_call.CptnModNestSeq1 \n          unfolding cpn_def  by fastforce  \n        then have  \"(\\<Gamma>,((Seq P1 Q1), Normal sa)#(map (lift Q1) xsa)) \\<in> cp \\<Gamma> (Seq P1 Q1) (Normal sa)\"\n          unfolding cpn_def cp_def\n          by (simp add: cptn_if_cptn_mod cptn_mod_nest_cptn_mod)\n        ultimately have  \"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> assum (p,rely)\" \n          using assum_map map cpP1' by fastforce\n        then have \"(\\<Gamma>, (P1, Normal sa) # xsa) \\<in> comm (G,(q,a)) F\" \n          using cpP1 CptnModNestSeq3(13)  CptnModNestSeq3.prems(1) unfolding com_validityn_def by auto\n        thus ?thesis   \n          using CptnModNestSeq3(3)  CptnModNestSeq3(4)\n          unfolding comm_def final_def by fastforce\n      qed\n      have all_throw:\"\\<forall>i<length ((LanguageCon.com.Throw, Normal s')# ys). \n              fst (((LanguageCon.com.Throw, Normal s')# ys)!i) = Throw\"\n      proof -\n       {fix i\n        assume i:\"i< length ((LanguageCon.com.Throw, Normal s')# ys)\"\n        have cptn:\"(n, \\<Gamma>, (LanguageCon.com.Throw, Normal s') # ys) \\<in> cptn_mod_nest_call\" \n          using CptnModNestSeq3(5) by auto\n        moreover have throw_0:\"((LanguageCon.com.Throw, Normal s') # ys)!0 = (Throw, Normal s') \\<and> 0 < length((LanguageCon.com.Throw, Normal s') # ys)\"\n          by force         \n        moreover have last:\"last ((LanguageCon.com.Throw, Normal s') # ys) = ((LanguageCon.com.Throw, Normal s') # ys)!((length ((LanguageCon.com.Throw, Normal s') # ys)) - 1)\"\n          using last_conv_nth by auto\n        moreover have env_tran:\"env_tran_right \\<Gamma> ((LanguageCon.com.Throw, Normal s') # ys) rely\" \n          using  CptnModNestSeq3(11)  CptnModNestSeq3(7) env_tran_subl env_tran_tail by blast           \n        ultimately have \n             \"fst (((LanguageCon.com.Throw, Normal s')# ys)!i) = Throw\"          \n        using zero_throw_all_throw[of \\<Gamma> \"((Throw, Normal s') # ys)\" \"s'\" \"i\" a rely]\n              s'_a  CptnModNestSeq3(12) i\n        using cptn_eq_cptn_mod_set cptn_mod_nest_cptn_mod by auto\n        }     \n        thus ?thesis using CptnModNestSeq3(10) final_def by blast        \n      qed      \n      then have \n        \"\\<forall>x\\<ge> length ((LanguageCon.com.Seq P1 Q1, Normal sa) # map (lift Q1) xsa). \n           x<length (((LanguageCon.com.Seq P1 Q1, Normal sa) # zs)) \\<longrightarrow>\n              fst (((LanguageCon.com.Seq P1 Q1, Normal sa) # zs) ! x) = Throw\"  \n      proof-\n      {\n        fix x \n        assume a1:\"x\\<ge> length ((LanguageCon.com.Seq P1 Q1, Normal sa) # map (lift Q1) xsa)\" and\n               a2:\"x<length (((LanguageCon.com.Seq P1 Q1, Normal sa) # zs))\"\n        then have \"((LanguageCon.com.Seq P1 Q1, Normal sa) # zs) ! x = \n                   ((LanguageCon.com.Throw, Normal s')# ys) !(x - (length ((LanguageCon.com.Seq P1 Q1, Normal sa) # map (lift Q1) xsa)))\"\n        using CptnModNestSeq3(7) by (metis Cons_lift Cons_lift_append not_le nth_append)\n        then have\"fst (((LanguageCon.com.Seq P1 Q1, Normal sa) # zs) ! x) = Throw\" \n          using all_throw a1 a2 CptnModNestSeq3.hyps(7)  by auto \n      } thus ?thesis by auto\n      qed       \n      thus ?thesis using False CptnModNestSeq3(7) q_not_throw P_Q x_less \n        by (metis fst_conv not_le)  \n    qed\n    } thus ?thesis by auto\n    qed\n    thus ?thesis using CptnModNestSeq3(9) by fastforce    \n  qed\nqed(auto)\n\n\n\ninductive_cases stepc_elim_cases_Seq_throw:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Seq c1 c2,s) \\<rightarrow> (Throw, Normal s1)\" \n\ninductive_cases stepc_elim_cases_Seq_skip_c2:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Seq c1 c2,s) \\<rightarrow> (c2,s)\"\n\n\nlemma seq_skip_throw:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Seq c1 c2,s) \\<rightarrow> (c2,s)  \\<Longrightarrow> c1= Skip \\<or> (c1=Throw \\<and> (\\<exists>s2'. s=Normal s2'))\"\napply (rule stepc_elim_cases_Seq_skip_c2)\napply fastforce\napply (auto)+\napply (fastforce intro:redex_not_Seq)+\ndone\n\nlemma Seq_sound: \n      \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p, R, G, q,a] \\<Longrightarrow>\n       \\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p, R, G, q,a] \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c2 sat [q, R, G, r,a] \\<Longrightarrow>\n       \\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> c2 sat [q, R, G, r,a] \\<Longrightarrow>        \n       Sta a R \\<and> Sta p R \\<Longrightarrow>  (\\<forall>s. (Normal s,Normal s) \\<in> G) \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Seq c1 c2) sat [p, R, G, r,a]\"\nproof -  \n  assume\n    a0:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p, R, G, q,a]\" and\n    a1:\"\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p, R, G, q,a]\" and\n    a2:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c2 sat [q, R, G, r,a]\" and    \n    a3: \"\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> c2 sat [q, R, G, r,a]\" and     \n    a4: \"Sta a R \\<and> Sta p R\" and\n    a5: \"(\\<forall>s. (Normal s, Normal s) \\<in> G)\"\n  { \n    fix s\n    assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"\n    then have a1:\"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p, R, G, q,a]\" \n      using a1 com_cvalidityn_def by fastforce  \n    then have a3: \"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c2 sat [q, R, G, r,a]\"\n      using a3 com_cvalidityn_def all_call by fastforce \n    have \"cpn n \\<Gamma> (Seq c1 c2)  s \\<inter> assum(p, R) \\<subseteq> comm(G, (r,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cpn n \\<Gamma> (Seq c1 c2) s\" and a11:\"c \\<in> assum(p, R)\"\n      then have a10':\"c \\<in> cp \\<Gamma> (Seq c1 c2) s\" unfolding cpn_def cp_def\n        using cptn_eq_cptn_mod_set cptn_mod_nest_cptn_mod by fastforce\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have cp:\"l!0=((Seq c1 c2),s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\" using a10' cp_def c_prod by fastforce\n      have cptn_nest:\"l!0=((Seq c1 c2),s) \\<and> (n,\\<Gamma>,l) \\<in> cptn_mod_nest_call \\<and> \\<Gamma>=\\<Gamma>1\" using a10 cpn_def c_prod by fastforce\n      have \\<Gamma>1:\"(\\<Gamma>, l) = c\" using c_prod cp by blast\n      have \"c \\<in> comm(G, (r,a)) F\"         \n      proof - \n      {\n       assume l_f:\"snd (last l) \\<notin> Fault ` F\"       \n       have assum:\"snd(l!0) \\<in> Normal ` (p) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n                 (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n       using a11 c_prod unfolding assum_def by simp\n       then have env_tran:\"env_tran \\<Gamma> p l R\" using env_tran_def cp by blast\n       then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n         using env_tran env_tran_right_def unfolding env_tran_def by auto       \n       have \"(\\<forall>i. Suc i<length l \\<longrightarrow> \n               \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                                             \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\\<and>\n             (final (last l)  \\<longrightarrow>                    \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal `  r)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` a))\"\n       proof (cases \"\\<forall>i<length l. fst (l!i)\\<noteq> c2\")\n         case True \n         then have no_c2:\"\\<forall>i<length l. fst (l!i)\\<noteq> c2\" by assumption\n         show ?thesis\n         proof (cases \"final (last l)\")\n           case True\n           then obtain s' where \"fst (last l) = Skip \\<or> (fst (last l) = Throw \\<and> snd (last l) = Normal s')\"  \n             using final_def by fast           \n           thus ?thesis\n           proof\n             assume \"fst (last l) = LanguageCon.com.Skip\" \n             then have \"False\" \n               using  no_c2 env_tran_right cptn_nest cptn_eq_cptn_mod_set Seq_sound3 a4 a1 assum\n               by blast\n             thus ?thesis by auto\n           next             \n             assume asm0:\"fst (last l) = LanguageCon.com.Throw \\<and> snd (last l) = Normal s'\"\n             then obtain lc1 s1' ys where cpn_lc1:\"(\\<Gamma>,lc1) \\<in> cpn n \\<Gamma> c1 s \\<and> l = ((map (lift c2) lc1)@((Throw, Normal s1')#ys))\"\n               using Seq_sound2'[of n \\<Gamma> l c1 c2 s s']  cptn_nest cptn_eq_cptn_mod_set env_tran_right no_c2 by blast\n             then have cp_lc1:\"(\\<Gamma>,lc1) \\<in> cp \\<Gamma> c1 s\"\n               using  cptn_if_cptn_mod cptn_mod_nest_cptn_mod split_conv \n               unfolding cp_def cpn_def by blast\n             let ?m_lc1 = \"map (lift c2) lc1\"\n             let ?lm_lc1 = \"(length ?m_lc1)\"\n             let ?last_m_lc1 = \"?m_lc1!(?lm_lc1-1)\"             \n             have lc1_not_empty:\"lc1 \\<noteq> []\"\n               using \\<Gamma>1 a10  cpn_lc1 cp by auto \n             then have map_cpn:\"(\\<Gamma>,?m_lc1) \\<in> cpn n \\<Gamma> (Seq c1 c2) s\"                  \n             proof -\n               have f1: \"lc1 ! 0 = (c1, s) \\<and> (n,\\<Gamma>, lc1) \\<in> cptn_mod_nest_call \\<and> \\<Gamma> = \\<Gamma>\"\n                 using cpn_lc1 cpn_def by blast\n               then have f2: \"(n, \\<Gamma>, ?m_lc1) \\<in> cptn_mod_nest_call\" \n               by (metis (no_types) Cons_lift cptn_mod_nest_call.CptnModNestSeq1 f1 lc1_not_empty list.exhaust nth_Cons_0)                               \n               then show ?thesis\n                 using f2 f1 lc1_not_empty by (simp add: cpn_def lift_def)\n             qed\n             then have map_cp:\"(\\<Gamma>,?m_lc1) \\<in> cp \\<Gamma> (Seq c1 c2) s\"\n               by (metis (no_types, lifting) cp_def cp_lc1 cpn_def lift_is_cptn mem_Collect_eq split_conv) \n             also have map_assum:\"(\\<Gamma>,?m_lc1) \\<in> assum (p,R)\"\n               using sub_assum a10 a11 \\<Gamma>1 cpn_lc1 lc1_not_empty \n               by (metis SmallStepCon.nth_tl map_is_Nil_conv)\n             ultimately have \"((\\<Gamma>,lc1) \\<in> assum(p, R))\"  \n               using \\<Gamma>1 assum_map cp_lc1 by blast                          \n             then have lc1_comm:\"(\\<Gamma>,lc1) \\<in> comm(G, (q,a)) F\"  \n               using a1  cpn_lc1 unfolding com_validityn_def by blast\n             then have m_lc1_comm:\"(\\<Gamma>,?m_lc1) \\<in> comm(G, (q,a)) F\"\n               using map_cp map_assum comm_map cp_lc1 by fastforce\n             then have last_m_lc1:\"last (?m_lc1) = (Seq (fst (last lc1)) c2,snd (last lc1))\"\n             proof -\n               have a000:\"\\<forall>p c. (LanguageCon.com.Seq (fst p) c, snd p) = lift c p\"\n                 using Cons_lift by force\n               then show ?thesis\n                 by (simp add: last_map a000 lc1_not_empty)\n             qed\n             then have last_length:\"last (?m_lc1) = ?last_m_lc1\"  \n               using lc1_not_empty last_conv_nth list.map_disc_iff by blast \n             then have l_map:\"l!(?lm_lc1-1)= ?last_m_lc1\" \n               using cpn_lc1\n               by (simp add:lc1_not_empty nth_append)\n             then have lm_lc1:\"l!(?lm_lc1) = (Throw, Normal s1')\"\n               using cpn_lc1 by (meson nth_append_length) \n             then have step:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!(?lm_lc1-1)) \\<rightarrow> (l!(?lm_lc1))\"\n             proof -\n               have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!(?lm_lc1-1)) \\<rightarrow>\\<^sub>c\\<^sub>e (l!(?lm_lc1))\"\n               proof -\n                 have f1: \"\\<forall>n na. \\<not> n < na \\<or> Suc (na - Suc n) = na - n\"\n                   by (meson Suc_diff_Suc)\n                 have \"map (lift c2) lc1 \\<noteq> []\"\n                   by (metis lc1_not_empty map_is_Nil_conv)\n                 then have f2: \"0 < length (map (lift c2) lc1)\"\n                   by (meson length_greater_0_conv)\n                 then have \"length (map (lift c2) lc1) - 1 + 1 < length (map (lift c2) lc1 @ (LanguageCon.com.Throw, Normal s1') # ys)\"\n                   by simp\n                 then show ?thesis\n                   using f2 f1\n                   by (metis Suc_pred' cp cpn_lc1 cptn_tran_ce_i)\n               qed\n               moreover have \"\\<not>\\<Gamma>\\<turnstile>\\<^sub>c(l!(?lm_lc1-1)) \\<rightarrow>\\<^sub>e (l!(?lm_lc1))\"\n               using  last_m_lc1 last_length l_map\n               proof -\n                 have \"(LanguageCon.com.Seq (fst (last lc1)) c2, snd (last lc1)) = l ! (length (map (lift c2) lc1) - 1)\"\n                   using l_map last_m_lc1 local.last_length by presburger\n                 then show ?thesis\n                   by (metis (no_types) LanguageCon.com.distinct(71) \\<open>l ! length (map (lift c2) lc1) = (LanguageCon.com.Throw, Normal s1')\\<close> env_c_c')\n               qed\n               ultimately show ?thesis using step_ce_elim_cases by blast        \n             qed\n             then have last_lc1_suc:\"snd (l!(?lm_lc1-1)) = snd (l!?lm_lc1) \\<and> fst (l!(?lm_lc1-1)) = Seq Throw c2\"\n               using lm_lc1 stepc_elim_cases_Seq_throw\n               by (metis One_nat_def asm0 append_is_Nil_conv cpn_lc1 diff_Suc_less fst_conv l_map last_conv_nth last_m_lc1 length_greater_0_conv list.simps(3) local.last_length no_c2 snd_conv)                            \n             then have a_normal:\"snd (l!?lm_lc1) \\<in> Normal ` (a)\" \n             proof\n               have last_lc1:\"fst (last lc1) = Throw \\<and> snd (last lc1) = Normal s1'\" \n               using last_length l_map lm_lc1 last_m_lc1 last_lc1_suc\n               by (metis LanguageCon.com.inject(3) fst_conv snd_conv)  \n               have \"final (last lc1)\" using last_lc1 final_def \n                 by blast\n               moreover have \"snd (last lc1)\\<notin> Fault ` F\" \n                 using last_lc1 by fastforce\n               ultimately have \"(fst (last lc1) = Throw \\<and> \n                      snd (last lc1) \\<in> Normal ` (a))\" \n                 using lc1_comm last_lc1 unfolding comm_def by force\n               thus ?thesis  using  l_map last_lc1_suc last_m_lc1 last_length by auto\n             qed                                         \n             have concl:\"(\\<forall>i. Suc i<length l \\<longrightarrow> \n               \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                                           \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n             proof-\n             { fix k ns ns'\n               assume a00:\"Suc k<length l\" and\n                a21:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"   \n                then have i_m_l:\"\\<forall>i <?lm_lc1  . l!i = ?m_lc1!i\" \n                  using cp_lc1\n                proof -\n                  have \"map (lift c2) lc1 \\<noteq> []\"\n                    by (meson lc1_not_empty list.map_disc_iff)\n                  then show ?thesis\n                    by (metis (no_types) cpn_lc1  nth_append)\n                qed\n                have last_not_F:\"snd (last ?m_lc1) \\<notin> Fault ` F\" \n                   using l_map last_lc1_suc lm_lc1 last_length by auto \n                have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n                proof (cases \"Suc k< ?lm_lc1\")\n                  case True \n                  then have a11': \"\\<Gamma>\\<turnstile>\\<^sub>c(?m_lc1!k)  \\<rightarrow> (?m_lc1!(Suc k))\" \n                    using a11 i_m_l True\n                  proof -\n                    have \"\\<forall>n na. \\<not> 0 < n - Suc na \\<or> na < n \"\n                      using diff_Suc_eq_diff_pred zero_less_diff by presburger\n                    then show ?thesis\n                      by (metis (no_types)  True a21 i_m_l  zero_less_diff)\n                  qed                  \n                  then have \"(snd(?m_lc1!k), snd(?m_lc1!(Suc k))) \\<in> G\"\n                  using a11' m_lc1_comm True comm_dest1 l_f last_not_F by fastforce\n                  thus ?thesis using i_m_l using  True by fastforce\n                next\n                  case False \n                  then have \"(Suc k=?lm_lc1) \\<or> (Suc k>?lm_lc1)\" by auto\n                  thus ?thesis \n                  proof\n                    {assume suck:\"(Suc k=?lm_lc1)\"\n                     then have k:\"k=?lm_lc1-1\" by auto\n                     have G_s1':\"(Normal s1', Normal s1')\\<in>G\" \n                       using a5 by auto               \n                     then show \"(snd (l!k), snd (l!Suc k)) \\<in> G\"               \n                     proof -\n                       have \"snd (l!Suc k) = Normal s1'\" \n                         using lm_lc1 suck by fastforce                                \n                       then show ?thesis using suck k G_s1' last_lc1_suc by fastforce\n                     qed\n                    }\n                  next\n                  { \n                    assume a001:\"Suc k>?lm_lc1\"\n                    have \"\\<forall>i. i\\<ge>(length lc1) \\<and> (Suc i < length l) \\<longrightarrow> \n                            \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\"\n                    using lm_lc1 lc1_not_empty\n                    proof -\n                      have \"env_tran_right \\<Gamma> l R\"\n                        by (metis  env_tran_right)\n                      then show ?thesis \n                       using a_normal cp fst_conv length_map \n                             lm_lc1 only_one_component_tran_j[of \\<Gamma> l ?lm_lc1 s1' a k R] snd_conv a21 a001 a00\n                             a4 by auto\n                    qed\n                    then have \"\\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n                      using a00 a001  by auto                    \n                    then show ?thesis using a21 by fastforce                    \n                  }\n                  qed \n                qed\n              } thus ?thesis by auto \n             qed \n             have concr:\"(final (last l)  \\<longrightarrow>                    \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` r)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` a))\" \n             proof -\n               have l_t:\"fst (last l) = Throw\" \n                 using lm_lc1 by (simp add: asm0)\n               have \"?lm_lc1 \\<le> length l -1\" using cpn_lc1 by fastforce\n               then have \"snd (l ! (length l - 1)) \\<in> Normal ` a\"\n                 using  cp a_normal a4  fst_conv  lm_lc1 snd_conv \n                         env_tran_right i_throw_all_throw[of \\<Gamma> l ?lm_lc1 s1' \"(length l -1)\" _ R a ]\n                       by (metis (no_types, lifting) One_nat_def diff_is_0_eq diff_less diff_less_Suc diff_zero image_iff length_greater_0_conv lessI less_antisym list.size(3) xstate.inject(1))                               \n               thus ?thesis using l_t \n                 by (simp add:  cpn_lc1 last_conv_nth)\n             qed\n             note res = conjI [OF concl concr]\n             then show ?thesis using  \\<Gamma>1 c_prod unfolding comm_def by auto\n           qed                  \n         next\n           case False\n           then obtain lc1 where cpn_lc1:\"(\\<Gamma>,lc1) \\<in> cpn n \\<Gamma> c1 s \\<and> l = map (lift c2) lc1\" \n             using Seq_sound1 assum False no_c2 env_tran_right cptn_nest cptn_eq_cptn_mod_set a4 a1 \n             by blast          \n           then have cp_lc1:\"(\\<Gamma>,lc1) \\<in> cp \\<Gamma> c1 s \"\n             using cp_def cpn_def cptn_if_cptn_mod cptn_mod_nest_cptn_mod by fastforce              \n           then have \"((\\<Gamma>,lc1) \\<in> assum(p, R))\"  \n              using \\<Gamma>1  cpn_lc1 a10' a11 assum_map by blast\n           then have \"(\\<Gamma>, lc1)\\<in> comm(G, (q,a)) F\" using cpn_lc1 a1\n             by (meson IntI com_validityn_def contra_subsetD)\n           then have \"(\\<Gamma>, l)\\<in> comm(G, (r,a)) F\"\n             using comm_map a10' \\<Gamma>1 cp_lc1 cpn_lc1 by blast\n           then show ?thesis using l_f\n             unfolding comm_def by auto\n         qed\n       next         \n         case False \n         then obtain k where k_len:\"k<length l \\<and> fst (l ! k) = c2\"\n           by blast         \n         then have \"\\<exists>m. (m < length l \\<and> fst (l ! m) = c2) \\<and>\n                   (\\<forall>i<m. \\<not> (i < length l \\<and> fst (l ! i) = c2))\"   \n           using a0 exists_first_occ[of \"(\\<lambda>i. i<length l  \\<and> fst (l ! i) = c2)\" k] \n           by blast\n         then obtain i where a0:\"i<length l \\<and> fst (l !i) = c2 \\<and>\n                                (\\<forall>j<i. (fst (l ! j) \\<noteq> c2))\"\n           by fastforce        \n         then obtain s2 where li:\"l!i =(c2,s2)\" by (meson eq_fst_iff)\n         then obtain lc1 lc2 where cp_lc1:\"(\\<Gamma>,lc1) \\<in> (cpn n \\<Gamma> c1 s) \\<and> \n                                 (\\<Gamma>,lc2) \\<in> (cpn n \\<Gamma> c2 (snd (lc1!(i-1)))) \\<and> \n                                 l = (map (lift c2) lc1)@lc2\"\n           using Seq_sound4[of n \\<Gamma> l c1 c2 s] a0 env_tran_right a4 a1 cptn_nest assum by blast  \n         then have cp_lc1':\"(\\<Gamma>,lc1) \\<in> (cp  \\<Gamma> c1 s) \\<and> \n                    (\\<Gamma>,lc2) \\<in> (cp  \\<Gamma> c2 (snd (lc1!(i-1))))\"\n           unfolding cp_def cpn_def cptn_eq_cptn_mod_nest by fastforce\n         have \"\\<forall>i < length l. snd (l!i) \\<notin> Fault ` F\"\n           using cp l_f last_not_F[of \\<Gamma> l F] by blast  \n         then have i_not_fault:\"snd (l!i) \\<notin> Fault ` F\" using a0 by blast\n         have length_c1_map:\"length lc1 = length (map (lift c2) lc1)\" \n           by fastforce      \n         then have i_map:\"i=length lc1\" \n           using cp_lc1 li a0 unfolding lift_def\n         proof -\n            assume a1: \"(\\<Gamma>, lc1) \\<in> cpn n \\<Gamma> c1 s \\<and> (\\<Gamma>, lc2) \\<in> cpn n \\<Gamma> c2 (snd (lc1 ! (i - 1))) \\<and> l = map (\\<lambda>(P, s). (LanguageCon.com.Seq P c2, s)) lc1 @ lc2\"\n            have f2: \"i < length l \\<and> fst (l ! i) = c2 \\<and> (\\<forall>n. \\<not> n < i \\<or> fst (l ! n) \\<noteq> c2)\"\n              using a0 by blast\n            have f3: \"(LanguageCon.com.Seq (fst (lc1 ! i)) c2, snd (lc1 ! i)) = lift c2 (lc1 ! i)\"\n              by (simp add: case_prod_unfold lift_def)            \n            then have \"fst (l ! length lc1) = c2\"\n              using a1 by (simp add: cpn_def nth_append)\n            thus ?thesis\n              using f3 f2 by (metis (no_types) nth_append cp_lc1 \n                 fst_conv length_map lift_nth linorder_neqE_nat seq_and_if_not_eq(4))\n         qed                  \n         have lc2_l:\"\\<forall>j<length lc2. lc2!j=l!(i+j)\"\n           using cp_lc1 length_c1_map i_map a0\n           by (metis nth_append_length_plus)                                                             \n         have lc1_not_empty:\"lc1 \\<noteq> []\"\n           using cp cp_lc1 unfolding cpn_def by fastforce      \n         have lc2_not_empty:\"lc2 \\<noteq> []\"\n           using a0 cp_lc1 i_map by auto                      \n         have l_is:\"s2= snd (last lc1)\"\n         using cp_lc1 li a0 lc1_not_empty i_map unfolding cpn_def\n         by (auto simp add: last_conv_nth lc2_l)       \n         let ?m_lc1 = \"map (lift c2) lc1\"\n         (* let ?lm_lc1 = \"(length ?m_lc1)\"\n         let ?last_m_lc1 = \"?m_lc1!(?lm_lc1-1)\" *)                         \n         have last_m_lc1:\"l!(i-1) = (Seq (fst (last lc1)) c2,s2)\"\n         proof -\n           have a000:\"\\<forall>p c. (LanguageCon.com.Seq (fst p) c, snd p) = lift c p\"\n             using Cons_lift by force\n           have \"length (map (lift c2) lc1) = i\"\n               using i_map by fastforce\n           then show ?thesis\n             by (metis (no_types) One_nat_def l_is a000 cp_lc1 diff_less last_conv_nth last_map \n            lc1_not_empty length_c1_map length_greater_0_conv less_Suc0 nth_append)                       \n         qed  \n         have last_mcl1_not_F:\"snd (last ?m_lc1) \\<notin> Fault ` F\"                 \n         proof -\n          have \"map (lift c2) lc1 \\<noteq> []\"\n            by (metis lc1_not_empty list.map_disc_iff)\n          then show ?thesis\n            by (metis (full_types) One_nat_def i_not_fault l_is last_conv_nth last_snd lc1_not_empty li snd_conv)\n         qed        \n         have map_cp:\"(\\<Gamma>,?m_lc1) \\<in> cpn n \\<Gamma> (Seq c1 c2) s\"               \n         proof -\n           have f1: \"lc1 ! 0 = (c1, s) \\<and> (n,\\<Gamma>, lc1) \\<in> cptn_mod_nest_call \\<and> \\<Gamma> = \\<Gamma>\"\n             using cp_lc1 cpn_def by blast\n           then have f2: \"(n,\\<Gamma>, ?m_lc1) \\<in> cptn_mod_nest_call\" using lc1_not_empty\n             by (metis Cons_lift SmallStepCon.nth_tl cptn_mod_nest_call.CptnModNestSeq1)\n           then show ?thesis\n             using f2 f1 lc1_not_empty by (simp add: cpn_def lift_def)\n         qed\n         then have map_cp':\"(\\<Gamma>,?m_lc1) \\<in> cp \\<Gamma> (Seq c1 c2) s\"\n           unfolding cpn_def cp_def\n           using cptn_eq_cptn_mod_nest by fastforce\n         also have map_assum:\"(\\<Gamma>,?m_lc1) \\<in> assum (p,R)\" \n           using sub_assum a10 a11 \\<Gamma>1 cp_lc1 lc1_not_empty \n           by (metis SmallStepCon.nth_tl map_is_Nil_conv)\n         ultimately have \"((\\<Gamma>,lc1) \\<in> assum(p, R))\"  \n           using \\<Gamma>1 assum_map using assum_map cp_lc1' by blast                          \n         then have lc1_comm:\"(\\<Gamma>,lc1) \\<in> comm(G, (q,a)) F\"  \n           using a1 cp_lc1 by (meson IntI com_validityn_def contra_subsetD)\n         then have m_lc1_comm:\"(\\<Gamma>,?m_lc1) \\<in> comm(G, (q,a)) F\"\n           using map_cp' map_assum comm_map cp_lc1' by fastforce         \n         then have i_step:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!(i-1)) \\<rightarrow> (l!i)\"\n         proof -\n           have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!(i-1)) \\<rightarrow>\\<^sub>c\\<^sub>e (l!(i))\"\n           proof -\n             have f1: \"\\<forall>n na. \\<not> n < na \\<or> Suc (na - Suc n) = na - n\"\n               by (meson Suc_diff_Suc)\n             have \"map (lift c2) lc1 \\<noteq> []\"\n               by (metis lc1_not_empty map_is_Nil_conv)\n             then have f2: \"0 < length (map (lift c2) lc1)\"\n               by (meson length_greater_0_conv)             \n             then have \"length (map (lift c2) lc1) - 1 + 1 < length (map (lift c2) lc1 @ lc2)\"\n               using f2 lc2_not_empty by simp\n             then show ?thesis\n             using f2 f1\n              proof -\n                have \"0 < i\"\n                  using f2 i_map by blast\n                then show ?thesis\n                  by (metis (no_types) One_nat_def Suc_diff_1 a0 add.right_neutral add_Suc_right cp cptn_tran_ce_i)\n              qed \n           qed \n           moreover have \"\\<not>\\<Gamma>\\<turnstile>\\<^sub>c(l!(i-1)) \\<rightarrow>\\<^sub>e (l!i)\"           \n             using li last_m_lc1\n             by (metis (no_types, lifting) env_c_c' seq_and_if_not_eq(4))\n           ultimately show ?thesis using step_ce_elim_cases by blast\n         qed         \n         then have step:\"\\<Gamma>\\<turnstile>\\<^sub>c(Seq (fst (last lc1)) c2,s2) \\<rightarrow> (c2, s2)\"\n           using last_m_lc1  li by fastforce\n         then obtain s2' where \n           last_lc1:\"fst (last lc1) = Skip \\<or> \n            fst (last lc1) = Throw \\<and> (s2 = Normal s2')\" \n           using seq_skip_throw by blast    \n         have final:\"final (last lc1)\" \n           using last_lc1 l_is unfolding final_def by auto\n(* look here for the property *******************************************************************************)\n         have normal_last:\"fst (last lc1) = Skip \\<and> snd (last lc1) \\<in> Normal ` q \\<or>\n                        fst (last lc1) = Throw \\<and> snd (last lc1) \\<in> Normal ` (a)\" \n         proof -         \n           have \"snd (last lc1) \\<notin> Fault ` F\"\n             using i_not_fault l_is li by auto\n           then show ?thesis\n             using final comm_dest2 lc1_comm by blast\n         qed\n         obtain s2' where lastlc1_normal:\"snd (last lc1) = Normal s2'\" \n           using normal_last by blast\n         then have Normals2:\"s2 = Normal s2'\" by (simp add: l_is ) \n         have Gs2':\"(Normal s2', Normal s2')\\<in>G\" using a5 by auto                     \n         have concl:\n           \"(\\<forall>i. Suc i<length l \\<longrightarrow> \n           \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                                    \n             (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n         proof-\n         { fix k \n           assume a00:\"Suc k<length l\" and\n            a21:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\" \n            have i_m_l:\"\\<forall>j <i . l!j = ?m_lc1!j\"             \n            proof -\n              have \"map (lift c2) lc1 \\<noteq> []\"\n                by (meson lc1_not_empty list.map_disc_iff)\n              then show ?thesis \n                using cp_lc1 i_map length_c1_map by (fastforce simp:nth_append)              \n            qed \n            have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n            proof (cases \"Suc k< i\")\n              case True \n              then have a11': \"\\<Gamma>\\<turnstile>\\<^sub>c(?m_lc1!k)  \\<rightarrow> (?m_lc1!(Suc k))\" \n                using a11 i_m_l True\n              proof -\n                have \"\\<forall>n na. \\<not> 0 < n - Suc na \\<or> na < n \"\n                  using diff_Suc_eq_diff_pred zero_less_diff by presburger\n                then show ?thesis using True a21 i_m_l by force                  \n              qed                                                             \n              have \"Suc k < length ?m_lc1\" using True i_map length_c1_map by metis\n              then have \"(snd(?m_lc1!k), snd(?m_lc1!(Suc k))) \\<in> G\"\n              using a11' last_mcl1_not_F  m_lc1_comm True i_map length_c1_map \n                    comm_dest1[of \\<Gamma>]\n                by blast\n              thus ?thesis using i_m_l using True by fastforce \n            next\n              case False                                            \n              have \"(Suc k=i) \\<or> (Suc k>i)\" using False by auto\n              thus ?thesis \n              proof\n              { assume suck:\"(Suc k=i)\" \n                then have k:\"k=i-1\" by auto                                                            \n                then show \"(snd (l!k), snd (l!Suc k)) \\<in> G\"               \n                proof -\n                  have \"snd (l!Suc k) = Normal s2'\" \n                    using Normals2 suck li by auto     \n                  moreover have \"snd (l ! k) = Normal s2'\"   \n                    using Normals2 k last_m_lc1 by fastforce                 \n                  moreover have \"\\<exists>p. p \\<in> G \"\n                    by (meson  case_prod_conv mem_Collect_eq Gs2')\n                  ultimately show ?thesis using suck k Normals2\n                    using Gs2'  by force                       \n                qed\n              }\n              next\n              { \n                assume a001:\"Suc k>i\"\n                then have k:\"k\\<ge>i\" by fastforce\n                then obtain k' where k':\"k=i+k'\" \n                  using add.commute le_Suc_ex by blast\n                {assume throw:\"c2=Throw \\<and> fst (last lc1) = Throw\"\n                 then have s2_in:\"s2' \\<in> a\" \n                   using Normals2 i_map normal_last li lastlc1_normal \n                   using image_iff snd_conv xstate.inject(1) by auto\n                \n                 then have \"\\<forall>k. k\\<ge>i \\<and> (Suc k < length l) \\<longrightarrow> \n                            \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n                  using Normals2 li lastlc1_normal a21 a001 a00 a4\n                        a0 throw env_tran_right only_one_component_tran_j snd_conv \n                   by (metis  cp env_tran_right)\n                  then have ?thesis using a21 a001 k a00 by blast                                  \n                }  note left=this\n                {assume \"\\<not>(c2=Throw \\<and> fst (last lc1) = Throw)\"\n                 then have \"fst (last lc1) = Skip\"\n                   using last_m_lc1 last_lc1\n                   by (metis step a0 l_is li prod.collapse stepc_Normal_elim_cases(11) stepc_Normal_elim_cases(5))                 \n                 then have s2_normal:\"s2 \\<in> Normal ` q\" \n                   using normal_last lastlc1_normal Normals2\n                   by fastforce\n                 have length_lc2:\"length l=i+length lc2\" \n                       using i_map cp_lc1 by fastforce\n                 have \"(\\<Gamma>,lc2) \\<in>  assum (q,R)\" \n                 proof -\n                   have left:\"snd (lc2!0) \\<in> Normal ` q\" \n                     using li lc2_l s2_normal lc2_not_empty by fastforce \n                   {\n                     fix j\n                     assume j_len:\"Suc j<length lc2\" and\n                            j_step:\"\\<Gamma>\\<turnstile>\\<^sub>c(lc2!j)  \\<rightarrow>\\<^sub>e (lc2!(Suc j))\"\n                     \n                     then have suc_len:\"Suc (i + j)<length l\" using j_len length_lc2\n                       by fastforce\n                     also then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!(i+j))  \\<rightarrow>\\<^sub>e (l! (Suc (i+ j)))\"\n                        using lc2_l j_step j_len by fastforce\n                     ultimately have \"(snd(lc2!j), snd(lc2!(Suc j))) \\<in> R\"\n                        using assum suc_len lc2_l j_len cp by fastforce \n                   }\n                   then show ?thesis using left \n                     unfolding assum_def by fastforce\n                 qed\n                 also have \"(\\<Gamma>,lc2) \\<in> cpn n \\<Gamma> c2 s2\"\n                   using cp_lc1 i_map l_is last_conv_nth lc1_not_empty by fastforce                 \n                 ultimately have comm_lc2:\"(\\<Gamma>,lc2) \\<in>  comm (G, (r,a)) F\"\n                   using a3 unfolding com_validityn_def by auto\n                 have lc2_last_f:\"snd (last lc2)\\<notin> Fault ` F\" \n                   using lc2_l lc2_not_empty l_f cp_lc1 by fastforce\n                 have suck':\"Suc k' < length lc2\" \n                   using k' a00 length_lc2 by arith\n                 moreover then have \"\\<Gamma>\\<turnstile>\\<^sub>c(lc2!k')  \\<rightarrow> (lc2!(Suc k'))\"  \n                   using k' lc2_l a21 by fastforce\n                 ultimately have \"(snd (lc2! k'), snd (lc2 ! Suc k')) \\<in> G\"\n                   using comm_lc2 lc2_last_f comm_dest1[of \\<Gamma> lc2 G r a F k'] \n                   by blast\n                 then have ?thesis using suck' lc2_l k' by fastforce\n                }                    \n                then show ?thesis using left by auto                 \n              }\n              qed \n            qed\n          } thus ?thesis by auto \n         qed note left=this\n         have right:\"(final (last l)  \\<longrightarrow>                    \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal `  r)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` a))\"\n         proof -\n         { assume final_l:\"final (last l)\" \n           have eq_last_lc2_l:\"last l=last lc2\" by (simp add: cp_lc1 lc2_not_empty)\n           then have final_lc2:\"final (last lc2)\" using final_l by auto\n           {\n             assume lst_lc1_throw:\"fst (last lc1) = Throw\"                        \n             then have c2_throw:\"c2 = Throw\" \n               using lst_lc1_throw step lastlc1_normal stepc_elim_cases_Seq_skip_c2\n               by fastforce                                                                  \n             have s2_a:\"s2 \\<in> Normal ` (a)\"\n               using normal_last \n               by (simp add: lst_lc1_throw l_is)\n             have all_ev:\"\\<forall>k<length l - 1. k\\<ge>i \\<and> (Suc k < length l) \\<longrightarrow> \n                            \\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))\"\n             proof -\n               have s2_in:\"s2' \\<in> a\" \n                 using Normals2 i_map normal_last li lastlc1_normal \n                 using image_iff snd_conv xstate.inject(1) lst_lc1_throw by auto\n               then have \"\\<forall>k. k\\<ge>i \\<and> (Suc k < length l) \\<longrightarrow> \n                            \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n                 using Normals2 li lastlc1_normal   a4\n                     a0 c2_throw env_tran_right only_one_component_tran_j snd_conv \n                 by (metis  cp env_tran_right)  \n               thus ?thesis by (metis Suc_eq_plus1 cp cptn_tran_ce_i step_ce_elim_cases)      \n             qed    \n             then have Throw:\"fst (l!(length l - 1)) = Throw\"\n             using cp c2_throw a0 cptn_i_env_same_prog[of \\<Gamma> l \"((length l)-1)\" i] \n               by fastforce                            \n             then have \"snd (l!(length l - 1)) \\<in> Normal ` (a) \\<and> fst (l!(length l - 1)) = Throw\"\n               using  all_ev a0 s2_a li a4 env_tran_right stability[of a R l i \"(length l) -1\" _ \\<Gamma>] Throw \n               by (metis One_nat_def Suc_pred length_greater_0_conv \n                         lessI linorder_not_less list.size(3) \n                         not_less0 not_less_eq_eq snd_conv)                              \n             then have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal `  r)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a))\" \n              using a0 by (metis last_conv_nth list.size(3) not_less0)                           \n          }  note left = this\n          {  assume \"fst (last lc1) = Skip\"                 \n             then have s2_normal:\"s2 \\<in> Normal ` q\" \n               using normal_last lastlc1_normal Normals2\n               by fastforce\n             have length_lc2:\"length l=i+length lc2\" \n                   using i_map cp_lc1 by fastforce\n             have \"(\\<Gamma>,lc2) \\<in>  assum (q,R)\" \n             proof -\n               have left:\"snd (lc2!0) \\<in> Normal ` q\" \n                 using li lc2_l s2_normal lc2_not_empty by fastforce \n               {\n                 fix j\n                 assume j_len:\"Suc j<length lc2\" and\n                        j_step:\"\\<Gamma>\\<turnstile>\\<^sub>c(lc2!j)  \\<rightarrow>\\<^sub>e (lc2!(Suc j))\"                 \n                 then have suc_len:\"Suc (i + j)<length l\" using j_len length_lc2\n                   by fastforce\n                 also then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!(i+j))  \\<rightarrow>\\<^sub>e (l! (Suc (i+ j)))\"\n                    using lc2_l j_step j_len by fastforce\n                 ultimately have \"(snd(lc2!j), snd(lc2!(Suc j))) \\<in> R\"\n                    using assum suc_len lc2_l j_len cp by fastforce \n               }\n               then show ?thesis using left \n                 unfolding assum_def by fastforce\n             qed\n             also have \"(\\<Gamma>,lc2) \\<in> cpn n \\<Gamma> c2 s2\"\n               using cp_lc1 i_map l_is last_conv_nth lc1_not_empty by fastforce\n             ultimately have comm_lc2:\"(\\<Gamma>,lc2) \\<in>  comm (G, (r,a)) F\"\n               using a3 unfolding com_validityn_def by auto\n             have lc2_last_f:\"snd (last lc2)\\<notin> Fault ` F\" \n               using lc2_l lc2_not_empty l_f cp_lc1 by fastforce             \n             then have \"((fst (last lc2) = Skip \\<and> \n                    snd (last lc2) \\<in> Normal `  r)) \\<or>\n                    (fst (last lc2) = Throw \\<and> \n                    snd (last lc2) \\<in> Normal ` a)\" \n             using final_lc2 comm_lc2 unfolding comm_def by auto\n             then have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal `  r)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` a)\" \n             using eq_last_lc2_l by auto\n          }\n          then have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` r)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` a)\" \n            using left using last_lc1 by auto\n        } thus ?thesis by auto qed         \n     thus ?thesis using left l_f \\<Gamma>1 unfolding comm_def by force       \n       qed             \n     } thus ?thesis using \\<Gamma>1 unfolding comm_def by auto qed\n   } thus ?thesis by auto qed \n } thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def) \nqed\n\nlemma Catch_env_P:assumes a0:\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch P Q,s) \\<rightarrow>\\<^sub>e (Catch P Q,t)\"\n      shows \"\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow>\\<^sub>e (P,t)\"\nusing a0\nby (metis env_not_normal_s snormal_enviroment)\n\nlemma map_catch_eq_state:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Catch c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \" and\n  a2:\"l1=map (lift_catch c2) l2\"\nshows\n  \"\\<forall>i<length l1. snd (l1!i) = snd (l2!i)\"\nusing a0 a1 a2 unfolding cp_def\nby (simp add: snd_lift_catch) \n\nlemma map_eq_catch_c:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Catch c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \" and\n  a2:\"l1=map (lift_catch c2) l2\"\nshows\n  \"\\<forall>i<length l1. fst (l1!i) = Catch (fst (l2!i)) c2\"\nproof -\n  {fix i\n  assume a3:\"i<length l1\"\n  have \"fst (l1!i) = Catch (fst (l2!i)) c2\"\n  using a0 a1 a2 a3 unfolding lift_catch_def\n    by (simp add: case_prod_unfold) \n  }thus ?thesis by auto\nqed \n\nlemma same_env_catch_c:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Catch c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \" and\n  a2:\"l1=map (lift_catch c2) l2\"\nshows\n\"\\<forall>i. Suc i<length l2 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow>\\<^sub>e (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow>\\<^sub>e (l1!(Suc i))\" \nproof -\n  have a0a:\"(\\<Gamma>,l1) \\<in>cptn \\<and> l1!0 = ((Catch c1 c2),s)\" \n    using a0 unfolding cp_def by blast\n  have a1a: \"(\\<Gamma>,l2) \\<in>cptn \\<and> l2!0 = (c1,s)\"\n    using a1 unfolding cp_def by blast\n  {\n    fix i\n    assume a3:\"Suc i< length l2\"\n    have \"\\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow>\\<^sub>e (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow>\\<^sub>e (l1!(Suc i))\"\n    proof\n    {\n      assume a4:\"\\<Gamma>\\<turnstile>\\<^sub>c l2 ! i \\<rightarrow>\\<^sub>e l2 ! Suc i\"\n      obtain c1i s1i c1si s1si where l1prod:\"l1 ! i=(c1i,s1i) \\<and> l1!Suc i = (c1si,s1si)\"\n        by fastforce\n      obtain c2i s2i c2si s2si where l2prod:\"l2 ! i=(c2i,s2i) \\<and> l2!Suc i = (c2si,s2si)\"\n        by fastforce\n      then have \"c1i = (Catch c2i c2) \\<and> c1si = (Catch c2si c2)\"\n        using  a0 a1 a2 a3 a4  l1prod \n        by (simp add: lift_catch_def)         \n      also have \"s2i=s1i \\<and> s2si=s1si\"\n        using  a0 a1 a4  a2 a3 l2prod  l1prod\n        by (simp add: lift_catch_def)         \n      ultimately show \"\\<Gamma>\\<turnstile>\\<^sub>c l1 ! i \\<rightarrow>\\<^sub>e (l1 ! Suc i)\" \n        using a4 l1prod l2prod\n        by (metis Env_n env_c_c' env_not_normal_s step_e.Env)\n    } \n    {\n      assume a4:\"\\<Gamma>\\<turnstile>\\<^sub>c l1 ! i \\<rightarrow>\\<^sub>e l1 ! Suc i\"\n      obtain c1i s1i c1si s1si where l1prod:\"l1 ! i=(c1i,s1i) \\<and> l1!Suc i = (c1si,s1si)\"\n        by fastforce\n      obtain c2i s2i c2si s2si where l2prod:\"l2 ! i=(c2i,s2i) \\<and> l2!Suc i = (c2si,s2si)\"\n        by fastforce\n      then have \"c1i = (Catch c2i c2) \\<and> c1si = (Catch c2si c2)\"\n        using  a0 a1 a2 a3 a4  l1prod\n        by (simp add: lift_catch_def)\n      also have \"s2i=s1i \\<and> s2si=s1si\"\n        using  a0 a1 a4  a2 a3 l2prod l1prod\n        by (simp add: lift_catch_def)      \n      ultimately show \"\\<Gamma>\\<turnstile>\\<^sub>c l2 ! i \\<rightarrow>\\<^sub>e (l2 ! Suc i)\" \n        using a4 l1prod l2prod       \n        by (metis Env_n LanguageCon.com.inject(9) env_c_c' env_not_normal_s step_e.Env)   \n    }\n    qed\n   } \n  thus ?thesis by auto\nqed\n\n\nlemma same_comp_catch_c:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Catch c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \" and\n  a2:\"l1=map (lift_catch c2) l2\"\nshows\n\"\\<forall>i. Suc i<length l2 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow> (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow> (l1!(Suc i))\" \nproof -\n  have a0a:\"(\\<Gamma>,l1) \\<in>cptn \\<and> l1!0 = ((Catch c1 c2),s)\" \n    using a0 unfolding cp_def by blast\n  have a1a: \"(\\<Gamma>,l2) \\<in>cptn \\<and> l2!0 = (c1,s)\"\n    using a1 unfolding cp_def by blast\n  {\n    fix i\n    assume a3:\"Suc i< length l2\"\n    have \"\\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow> (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow> (l1!(Suc i))\"\n    proof\n    {\n      assume a4:\"\\<Gamma>\\<turnstile>\\<^sub>c l2 ! i \\<rightarrow> l2 ! Suc i\"\n      obtain c1i s1i c1si s1si where l1prod:\"l1 ! i=(c1i,s1i) \\<and> l1!Suc i = (c1si,s1si)\"\n        by fastforce\n      obtain c2i s2i c2si s2si where l2prod:\"l2 ! i=(c2i,s2i) \\<and> l2!Suc i = (c2si,s2si)\"\n        by fastforce\n      then have \"c1i = (Catch c2i c2) \\<and> c1si = (Catch c2si c2)\"\n        using  a0 a1 a2 a3 a4  map_eq_catch_c l1prod\n        by (simp add: lift_catch_def)\n      also have \"s2i=s1i \\<and> s2si=s1si\"\n        using  a0 a1 a4  a2 a3 l2prod map_eq_state l1prod\n        by (simp add: lift_catch_def)          \n      ultimately show \"\\<Gamma>\\<turnstile>\\<^sub>c l1 ! i \\<rightarrow> (l1 ! Suc i)\" \n        using a4 l1prod l2prod\n        by (simp add: Catchc)        \n    } \n    {\n      assume a4:\"\\<Gamma>\\<turnstile>\\<^sub>c l1 ! i \\<rightarrow> l1 ! Suc i\"\n      obtain c1i s1i c1si s1si where l1prod:\"l1 ! i=(c1i,s1i) \\<and> l1!Suc i = (c1si,s1si)\"\n        by fastforce\n      obtain c2i s2i c2si s2si where l2prod:\"l2 ! i=(c2i,s2i) \\<and> l2!Suc i = (c2si,s2si)\"\n        by fastforce\n      then have \"c1i = (Catch c2i c2) \\<and> c1si = (Catch c2si c2)\"\n        using  a0 a1 a2 a3 a4  l1prod\n       by (simp add: lift_catch_def)          \n      also have \"s2i=s1i \\<and> s2si=s1si\"\n        using  a0 a1 a4  a2 a3 l2prod  l1prod\n        by (simp add: lift_catch_def)          \n      ultimately show \"\\<Gamma>\\<turnstile>\\<^sub>c l2 ! i \\<rightarrow> (l2 ! Suc i)\" \n        using a4 l1prod l2prod stepc_elim_cases_Catch_Catch Catch_not_c\n        by (metis (no_types))\n    }\n    qed\n   } \n  thus ?thesis by auto\nqed\n\nlemma assum_map_catch:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Catch c1 c2) s) \\<and> ((\\<Gamma>,l1) \\<in> assum(p, R))\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \" and\n  a2:\"l1=map (lift_catch c2) l2\"  \nshows\n  \"((\\<Gamma>,l2) \\<in> assum(p, R))\"\nproof -\n  have a3: \"\\<forall>i. Suc i<length l2 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow>\\<^sub>e (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow>\\<^sub>e (l1!(Suc i))\" \n    using a0 a1 a2 same_env_catch_c by fastforce\n  have pair_\\<Gamma>l1:\"fst (\\<Gamma>,l1) = \\<Gamma> \\<and> snd (\\<Gamma>,l1) = l1\" by fastforce\n  have pair_\\<Gamma>l2:\"fst (\\<Gamma>,l2) = \\<Gamma> \\<and> snd (\\<Gamma>,l2) = l2\" by fastforce\n  have drop_k_s:\"l2!0 = (c1,s)\" using a1 cp_def by blast\n  have eq_length:\"length l1 = length l2\" using a2 by auto\n  obtain s' where normal_s:\"s = Normal s'\" \n    using  a0  unfolding cp_def   assum_def  by fastforce\n  then have p1:\"s'\\<in>p\" using a0 unfolding cp_def assum_def by fastforce  \n  show ?thesis \n  proof -    \n    let ?c= \"(\\<Gamma>,l2)\"\n    have l:\"snd((snd ?c!0)) \\<in> Normal ` (p)\"\n     using p1 drop_k_s a1 normal_s unfolding cp_def by auto\n    {fix i\n     assume a00:\"Suc i<length (snd ?c)\" \n     assume a11:\"(fst ?c)\\<turnstile>\\<^sub>c((snd ?c)!i)  \\<rightarrow>\\<^sub>e ((snd ?c)!(Suc i))\"\n     have \"(snd((snd ?c)!i), snd((snd ?c)!(Suc i))) \\<in> R\"\n     using a0 a1 a2 a3 map_catch_eq_state unfolding assum_def \n     using a00 a11 eq_length by fastforce\n    } thus \"(\\<Gamma>, l2) \\<in> assum (p, R)\" \n      using l unfolding assum_def by fastforce  \n  qed  \nqed\n\nlemma comm_map'_catch:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Catch c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \\<and> (\\<Gamma>, l2)\\<in> comm(G, (q,a)) F\" and\n  a2:\"l1=map (lift_catch c2) l2\" \nshows\n  \"snd (last l1) \\<notin> Fault ` F  \\<longrightarrow>(Suc k < length l1 \\<longrightarrow>\n       \\<Gamma>\\<turnstile>\\<^sub>c(l1!k)  \\<rightarrow> (l1!(Suc k)) \\<longrightarrow>        \n       (snd(l1!k), snd(l1!(Suc k))) \\<in> G) \\<and> \n   (fst (last l1) = (Catch c c2) \\<and> final (c, snd (last l1)) \\<longrightarrow>     \n      (fst (last l1) = (Catch Skip c2) \\<and> \n        (snd (last  l1) \\<in> Normal ` q) \\<or>\n      (fst (last l1) = (Catch Throw c2) \\<and> \n        snd (last l1) \\<in> Normal ` (a))))\n     \"\nproof -\n  have a3:\"\\<forall>i. Suc i<length l2 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow> (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow> (l1!(Suc i))\" \n    using a0 a1 a2 same_comp_catch_c\n    by fastforce\n  have pair_\\<Gamma>l1:\"fst (\\<Gamma>,l1) = \\<Gamma> \\<and> snd (\\<Gamma>,l1) = l1\" by fastforce\n  have pair_\\<Gamma>l2:\"fst (\\<Gamma>,l2) = \\<Gamma> \\<and> snd (\\<Gamma>,l2) = l2\" by fastforce\n  have drop_k_s:\"l2!0 = (c1,s)\" using a1 cp_def by blast\n  have eq_length:\"length l1 = length l2\" using a2 by auto\n  have len0:\"length l2>0\" using a1 unfolding cp_def \n      using cptn.simps  by fastforce   \n  then have len0:\"length l1>0\" using eq_length by auto\n  then have l1_not_empty:\"l1\\<noteq>[]\" by auto\n  then have l2_not_empty:\"l2 \\<noteq> []\" using a2 by blast       \n   have last_lenl1:\"last l1 = l1!((length l1) -1)\" \n        using last_conv_nth l1_not_empty by auto\n  have last_lenl2:\"last l2 = l2!((length l2) -1)\" \n       using last_conv_nth l2_not_empty by auto \n  have a03:\"snd (last l2) \\<notin> Fault ` F  \\<longrightarrow>(\\<forall>i ns ns'.                 \n               Suc i<length (snd (\\<Gamma>, l2)) \\<longrightarrow> \n               fst (\\<Gamma>, l2)\\<turnstile>\\<^sub>c((snd (\\<Gamma>, l2))!i)  \\<rightarrow> ((snd (\\<Gamma>, l2))!(Suc i)) \\<longrightarrow>                               \n                 (snd((snd (\\<Gamma>, l2))!i), snd((snd (\\<Gamma>, l2))!(Suc i))) \\<in> G) \\<and> \n               (final (last (snd (\\<Gamma>, l2)))  \\<longrightarrow>                 \n                  ((fst (last (snd (\\<Gamma>, l2))) = Skip \\<and> \n                    snd (last (snd (\\<Gamma>, l2))) \\<in> Normal ` q)) \\<or>\n                  (fst (last (snd (\\<Gamma>, l2))) = Throw \\<and> \n                    snd (last (snd (\\<Gamma>, l2))) \\<in> Normal ` (a)))\"\n  using a1 unfolding comm_def by fastforce\n  show ?thesis unfolding comm_def \n  proof -\n  { fix k ns ns'\n    assume a00a:\"snd (last l1) \\<notin> Fault ` F\"\n    assume a00:\"Suc k < length l1\"    \n    then have \"k \\<le> length l1\" using a2 by fastforce    \n    have a00:\"Suc k < length l2\" using eq_length a00 by fastforce\n    then have a00a:\"snd (last l2) \\<notin> Fault ` F\"\n    proof-\n      have \"snd (l1!((length l1) -1)) = snd (l2!((length l2) -1))\"      \n        using a2 a1 a0  map_catch_eq_state eq_length l2_not_empty last_snd \n        by fastforce \n      then have \"snd(last l2) = snd (last l1)\"\n        using last_lenl1 last_lenl2 by auto\n      thus ?thesis using a00a by auto\n    qed\n    then have \"snd (last l1) \\<notin> Fault ` F \\<longrightarrow>\\<Gamma>\\<turnstile>\\<^sub>c(l1!k)  \\<rightarrow> (l1!(Suc k)) \\<longrightarrow>       \n      (snd((snd (\\<Gamma>, l1))!k), snd((snd (\\<Gamma>, l1))!(Suc k))) \\<in> G\"\n    using  pair_\\<Gamma>l1 pair_\\<Gamma>l2 a00  a03 a3  eq_length a00a\n     by (metis Suc_lessD a0 a1 a2 map_catch_eq_state)\n  } note l=this\n  {\n    assume a00: \"fst (last l1) = (Catch c c2) \\<and> final (c, snd (last l1))\" and\n           a01:\"snd (last (l1)) \\<notin> Fault ` F\"\n    then have c:\"c=Skip \\<or> c = Throw\"\n     unfolding final_def by auto    \n    then have fst_last_l2:\"fst (last l2) = c\"                               \n      using  last_lenl1 a00 l1_not_empty eq_length len0 a2 last_conv_nth last_lift_catch \n      by fastforce      \n    also have last_eq:\"snd (last l2) = snd (last l1)\"      \n      using l2_not_empty a2 last_conv_nth last_lenl1 last_snd_catch\n      by fastforce\n    ultimately have \"final (fst (last l2),snd (last l2))\" \n     using a00 by auto\n    then have \"final (last l2)\" by auto\n    also have \"snd (last (l2)) \\<notin> Fault ` F\"\n       using  last_eq a01 by auto\n    ultimately have \"(fst (last  l2)) = Skip \\<and> \n                    snd (last  l2) \\<in> Normal ` q \\<or>\n                  (fst (last l2) = Throw \\<and> \n                    snd (last l2) \\<in> Normal ` (a))\"\n    using a03 by auto\n    then have \"(fst (last l1) = (Catch Skip c2) \\<and> \n                    snd (last  l1) \\<in> Normal ` q) \\<or>\n                  (fst (last l1) = (Catch Throw c2) \\<and> \n                    snd (last l1) \\<in> Normal ` (a))\"\n    using last_eq fst_last_l2 a00 by force\n  }\n  thus ?thesis using l by auto qed\nqed\n\nlemma comm_map''_catch:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Catch c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \\<and> (\\<Gamma>, l2)\\<in> comm(G, (q,a)) F\" and\n  a2:\"l1=map (lift_catch c2) l2\" \nshows\n  \"snd (last l1) \\<notin> Fault ` F \\<longrightarrow> ((Suc k < length l1 \\<longrightarrow>\n       \\<Gamma>\\<turnstile>\\<^sub>c(l1!k)  \\<rightarrow> (l1!(Suc k)) \\<longrightarrow>        \n       (snd(l1!k), snd(l1!(Suc k))) \\<in>  G) \\<and> \n   (final (last l1) \\<longrightarrow>     \n      (fst (last l1) = Skip \\<and> \n        (snd (last  l1) \\<in> Normal ` r) \\<or>\n      (fst (last l1) = Throw \\<and> \n        snd (last l1) \\<in> Normal ` a))))\n     \"\nproof -\n  have a3:\"\\<forall>i. Suc i<length l2 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(l2!i)  \\<rightarrow> (l2!(Suc i)) = \n            \\<Gamma>\\<turnstile>\\<^sub>c(l1!i)  \\<rightarrow> (l1!(Suc i))\" \n    using a0 a1 a2 same_comp_catch_c\n    by fastforce\n  have pair_\\<Gamma>l1:\"fst (\\<Gamma>,l1) = \\<Gamma> \\<and> snd (\\<Gamma>,l1) = l1\" by fastforce\n  have pair_\\<Gamma>l2:\"fst (\\<Gamma>,l2) = \\<Gamma> \\<and> snd (\\<Gamma>,l2) = l2\" by fastforce\n  have drop_k_s:\"l2!0 = (c1,s)\" using a1 cp_def by blast\n   have eq_length:\"length l1 = length l2\" using a2 by auto\n  have len0:\"length l2>0\" using a1 unfolding cp_def \n      using cptn.simps  by fastforce   \n  then have len0:\"length l1>0\" using eq_length by auto\n  then have l1_not_empty:\"l1\\<noteq>[]\" by auto\n  then have l2_not_empty:\"l2 \\<noteq> []\" using a2 by blast       \n  have last_lenl1:\"last l1 = l1!((length l1) -1)\" \n        using last_conv_nth l1_not_empty by auto\n  have last_lenl2:\"last l2 = l2!((length l2) -1)\" \n       using last_conv_nth l2_not_empty by auto \n  have a03:\"snd (last l2) \\<notin> Fault ` F \\<longrightarrow>(\\<forall>i ns ns'.                 \n               Suc i<length (snd (\\<Gamma>, l2)) \\<longrightarrow> \n               fst (\\<Gamma>, l2)\\<turnstile>\\<^sub>c((snd (\\<Gamma>, l2))!i)  \\<rightarrow> ((snd (\\<Gamma>, l2))!(Suc i)) \\<longrightarrow>                                              \n                 (snd((snd (\\<Gamma>, l2))!i), snd((snd (\\<Gamma>, l2))!(Suc i))) \\<in> G) \\<and> \n               (final (last (snd (\\<Gamma>, l2)))  \\<longrightarrow>                 \n                  ((fst (last (snd (\\<Gamma>, l2))) = Skip \\<and> \n                    snd (last (snd (\\<Gamma>, l2))) \\<in> Normal ` q)) \\<or>\n                  (fst (last (snd (\\<Gamma>, l2))) = Throw \\<and> \n                    snd (last (snd (\\<Gamma>, l2))) \\<in> Normal ` (a)))\"\n  using a1 unfolding comm_def by fastforce\n  show ?thesis unfolding comm_def \n  proof -\n  { fix k ns ns'\n    assume a00a:\"snd (last l1) \\<notin> Fault ` F\"\n    assume a00:\"Suc k < length l1\"    \n    then have \"k \\<le> length l1\" using a2 by fastforce    \n    have a00:\"Suc k < length l2\" using eq_length a00 by fastforce   \n    then have a00a:\"snd (last l2) \\<notin> Fault ` F\"\n    proof-\n      have \"snd (l1!((length l1) -1)) = snd (l2!((length l2) -1))\"      \n        using a2 a1 a0  map_catch_eq_state eq_length l2_not_empty last_snd \n        by fastforce \n      then have \"snd(last l2) = snd (last l1)\"\n        using last_lenl1 last_lenl2 by auto\n      thus ?thesis using a00a by auto\n    qed \n    then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l1!k)  \\<rightarrow> (l1!(Suc k)) \\<longrightarrow>          \n        (snd((snd (\\<Gamma>, l1))!k), snd((snd (\\<Gamma>, l1))!(Suc k))) \\<in> G\"\n       using  pair_\\<Gamma>l1 pair_\\<Gamma>l2 a00  a03 a3  eq_length a00a\n      by (metis (no_types,lifting) a2 Suc_lessD nth_map snd_lift_catch)\n    } note l= this\n    {\n     assume a00: \"final (last l1)\"           \n     then have c:\"fst (last l1)=Skip \\<or> fst (last l1) = Throw\"\n       unfolding final_def by auto \n     moreover have \"fst (last l1) = Catch (fst (last l2)) c2\" \n       using a2 last_lenl1 eq_length\n      proof -\n        have \"last l2 = l2 ! (length l2 - 1)\"\n          using l2_not_empty last_conv_nth by blast\n        then show ?thesis\n          by (metis One_nat_def a2 l2_not_empty last_lenl1 last_lift_catch)\n      qed\n      ultimately have False by simp  \n    } thus ?thesis using l  by auto qed\nqed\n\nlemma comm_map_catch:\nassumes \n  a0:\"(\\<Gamma>,l1) \\<in> (cp \\<Gamma> (Catch c1 c2) s)\" and\n  a1:\"(\\<Gamma>,l2) \\<in> (cp \\<Gamma> c1 s) \\<and> (\\<Gamma>, l2)\\<in> comm(G, (q,a)) F\" and\n  a2:\"l1=map (lift_catch c2) l2\" \nshows\n  \"(\\<Gamma>, l1)\\<in> comm(G, (r,a)) F\"\nproof - \n  {fix i ns ns'\n   have \"snd (last l1) \\<notin> Fault ` F  \\<longrightarrow>(Suc i < length (l1) \\<longrightarrow>\n        \\<Gamma>\\<turnstile>\\<^sub>c (l1 ! i) \\<rightarrow> (l1 ! (Suc i)) \\<longrightarrow>       \n        (snd (l1 ! i), snd (l1 ! Suc i)) \\<in> G) \\<and>\n        (SmallStepCon.final (last l1) \\<longrightarrow>                  \n                   fst (last l1) = LanguageCon.com.Skip \\<and>\n                   snd (last l1) \\<in> Normal ` r \\<or>\n                   fst (last l1) = LanguageCon.com.Throw \\<and>\n                   snd (last l1) \\<in> Normal ` a) \"\n      using comm_map''_catch[of \\<Gamma> l1 c1 c2 s l2 G q a F i r] a0 a1 a2 \n      by fastforce\n   }  then show ?thesis using comm_def unfolding comm_def by force       \nqed\n\nlemma Catch_sound1: \nassumes\n  a0:\"(n,\\<Gamma>,x)\\<in>cptn_mod_nest_call\" and\n  a1:\"x!0 = ((Catch P Q),s)\" and\n  a2:\"\\<forall>i<length x. fst (x!i)\\<noteq> Q\" and\n  a3:\"\\<not> final (last x)\" and\n  a4:\"env_tran_right \\<Gamma> x rely\"\nshows\n  \"\\<exists>xs. (\\<Gamma>,xs) \\<in> cpn n \\<Gamma> P s \\<and> x = map (lift_catch Q) xs\"\nusing a0 a1 a2 a3 a4\nproof (induct arbitrary: P s)\n  case (CptnModNestOne n \\<Gamma> C s1)\n  then have \"(\\<Gamma>, [(P,s)]) \\<in> cpn n \\<Gamma> P s \\<and> [(C, s1)] = map (lift_catch Q) [(P,s)]\"\n    unfolding cpn_def lift_catch_def\n    by (simp add: cptn_mod_nest_call.CptnModNestOne) \n  thus ?case by fastforce\nnext\n  case (CptnModNestEnv \\<Gamma> C s1 t1 n xsa)\n  then have C:\"C=Catch P Q\" unfolding lift_catch_def by fastforce\n  have \"\\<exists>xs. (\\<Gamma>, xs) \\<in> cpn n \\<Gamma> P t1 \\<and> (C, t1) # xsa = map (lift_catch Q) xs\"\n  proof -\n     have \"((C, t1) # xsa) ! 0 = (Catch P Q, t1)\" using C by auto\n     moreover have \"\\<forall>i<length ((C, t1) # xsa). fst (((C, t1) # xsa) ! i) \\<noteq> Q\"\n       using CptnModNestEnv(5) by fastforce\n     moreover have \"\\<not> SmallStepCon.final (last ((C, t1) # xsa))\" using CptnModNestEnv(6) \n       by fastforce\n     ultimately show ?thesis\n       using CptnModNestEnv(3) CptnModNestEnv(7) env_tran_tail by blast     \n  qed \n  then obtain xs where hi:\"(\\<Gamma>, xs) \\<in> cpn n \\<Gamma> P t1 \\<and> (C, t1) # xsa = map (lift_catch Q) xs\"\n    by fastforce\n  have s1_s:\"s1=s\" using  CptnModNestEnv unfolding cpn_def by auto\n  obtain xsa' where xs:\"xs=((P,t1)#xsa') \\<and> (n,\\<Gamma>,((P,t1)#xsa'))\\<in>cptn_mod_nest_call \\<and> \n                  (C, t1) # xsa = map (lift_catch Q) ((P,t1)#xsa')\" \n    using hi  unfolding cpn_def by fastforce\n  \n  have env_tran:\"\\<Gamma>\\<turnstile>\\<^sub>c(P,s1) \\<rightarrow>\\<^sub>e (P,t1)\" using CptnModNestEnv Catch_env_P by (metis fst_conv nth_Cons_0)  \n  then have \"(n,\\<Gamma>,(P,s1)#(P,t1)#xsa')\\<in>cptn_mod_nest_call\" using xs env_tran \n    using cptn_mod_nest_call.CptnModNestEnv by blast \n  then have \"(\\<Gamma>,(P,s1)#(P,t1)#xsa') \\<in> cpn n \\<Gamma> P s\" \n    using cpn_def s1_s by fastforce\n  moreover have \"(C,s1)#(C, t1) # xsa = map (lift_catch Q) ((P,s1)#(P,t1)#xsa')\"\n    using xs C unfolding lift_catch_def by fastforce\n  ultimately show ?case by auto\nnext\n  case (CptnModNestSkip)\n  thus ?case by (metis SmallStepCon.redex_not_Catch fst_conv nth_Cons_0)\nnext\n  case (CptnModNestThrow)\n  thus ?case by (metis SmallStepCon.redex_not_Catch fst_conv nth_Cons_0)\nnext\n  case (CptnModNestCatch1 n \\<Gamma> P0 sa xsa zs P1)\n  then have a1:\"LanguageCon.com.Catch P Q = LanguageCon.com.Catch P0 P1\"\n    by fastforce  \n  have f1: \"sa = s\"\n    using CptnModNestCatch1.prems(1) by force\n  have f2: \"P = P0 \\<and> Q = P1\" using a1 by auto\n  have \"(n,\\<Gamma>, (P0, sa) # xsa) \\<in> cptn_mod_nest_call\"\n    by (metis CptnModNestCatch1.hyps(1))\n  hence \"(\\<Gamma>, (P0, sa) # xsa) \\<in> cpn n \\<Gamma> P s\"\n    using f2 f1 by (simp add: cpn_def)\n  thus ?case\n    using Cons_lift_catch CptnModNestCatch1.hyps(3) a1 by blast   \nnext\n case (CptnModNestCatch2 n \\<Gamma> P1 sa xsa  ys zs Q1)\n  have \"final (last ((Skip, sa)# ys))\"\n  proof -\n    have cptn:\"(n, \\<Gamma>, (Skip,snd (last ((P1, sa) # xsa))) # ys) \\<in> cptn_mod_nest_call\" \n      using CptnModNestCatch2(4) by (simp add: cptn_eq_cptn_mod_set)\n    then have cptn':\"(\\<Gamma>, (Skip,snd (last ((P1, sa) # xsa))) # ys) \\<in> cptn\"\n      using cptn_eq_cptn_mod_nest by blast       \n    moreover have throw_0:\"((Skip,snd (last ((P1, sa) # xsa))) # ys)!0 = (Skip, snd (last ((P1, sa) # xsa))) \\<and> 0 < length((Skip, snd (last ((P1, sa) # xsa))) # ys)\"\n      by force         \n    moreover have last:\"last ((Skip,snd (last ((P1, sa) # xsa))) # ys) = \n                      ((Skip,snd (last ((P1, sa) # xsa))) # ys)!((length ((Skip,snd (last ((P1, sa) # xsa))) # ys)) - 1)\"\n      using last_conv_nth by auto\n    moreover have env_tran:\"env_tran_right \\<Gamma> ((Skip,snd (last ((P1, sa) # xsa))) # ys) rely\" \n      using  CptnModNestCatch2.hyps(6) CptnModNestCatch2.prems(4) env_tran_subl env_tran_tail by blast          \n    ultimately obtain st' where \"fst (last ((Skip,snd (last ((P1, sa) # xsa))) # ys)) = Skip \\<and>        \n                     snd (last ((Skip,snd (last ((P1, sa) # xsa))) # ys)) = Normal st'\" \n      using  CptnModNestCatch2 zero_skip_all_skip[of \\<Gamma> \"((Skip,snd (last ((P1, sa) # xsa))) # ys)\" \"(length ((Skip,snd (last ((P1, sa) # xsa))) # ys))-1\"]\n      by (metis (no_types, hide_lams) SmallStepCon.final_def append_Cons diff_less fst_conv \n         last_appendR list.simps(3) zero_less_one)      \n    thus ?thesis using final_def by (metis fst_conv last.simps)       \n  qed\n  thus ?case \n    by (metis (no_types, lifting) CptnModNestCatch2.hyps(3) CptnModNestCatch2.hyps(6) \n        CptnModNestCatch2.prems(3) SmallStepCon.final_def append_is_Nil_conv last.simps \n        last_appendR list.simps(3) prod.collapse)     \nnext\n  case (CptnModNestCatch3 n \\<Gamma> P0 sa xsa sa' P1 ys zs)\n  then have \"P0 = P \\<and> P1 = Q\" by auto\n  then obtain i where zs:\"fst (zs!i) = Q \\<and> (i< (length zs))\" \n    using CptnModNestCatch3\n    by (metis (no_types, lifting) add_diff_cancel_left' fst_conv length_Cons length_append nth_append_length zero_less_Suc zero_less_diff)    \n  then have \"Suc i< length ((Catch P0 P1,Normal sa)#zs)\" by fastforce\n  then have \"fst (((Catch P0 P1, Normal sa) # zs)!Suc i) = Q\" using zs by fastforce    \n  thus ?case using CptnModNestCatch3(9) zs by auto\nqed (auto)\n\nlemma Catch_sound2: \nassumes\n  a0:\"(n,\\<Gamma>,x)\\<in>cptn_mod_nest_call\" and\n  a1:\"x!0 = ((Catch P Q),s)\" and\n  a2:\"\\<forall>i<length x. fst (x!i)\\<noteq> Q\" and\n  a3:\"fst (last x) = Skip\" and\n  a4:\"env_tran_right \\<Gamma> x rely\"\nshows\n  \"\\<exists>xs ys. (\\<Gamma>,xs) \\<in> cpn n \\<Gamma> P s \\<and> x = ((map (lift_catch Q) xs)@((Skip,snd(last xs))#ys))\"\nusing a0 a1 a2 a3 a4\nproof (induct arbitrary: P s)\n  case (CptnModNestOne n \\<Gamma> C s1)  \n  thus ?case by fastforce\nnext\n  case (CptnModNestEnv \\<Gamma> C s1 t1 n xsa)\n  then have C:\"C=Catch P Q\" unfolding lift_catch_def by fastforce\n  have \"\\<exists>xs ys. (\\<Gamma>, xs) \\<in> cpn n \\<Gamma> P t1 \\<and> (C, t1) # xsa = \n                map (lift_catch Q) xs@((Skip, snd(last xs))#ys)\"\n  proof -\n     have \"((C, t1) # xsa) ! 0 = (LanguageCon.com.Catch P Q, t1)\" using C by auto\n     moreover have \"\\<forall>i<length ((C, t1) # xsa). fst (((C, t1) # xsa) ! i) \\<noteq> Q\"\n       using CptnModNestEnv(5) by fastforce\n     moreover have \"fst (last ((C, t1) # xsa)) = Skip\" using CptnModNestEnv(6) \n       by fastforce\n     ultimately show ?thesis\n       using CptnModNestEnv(3) CptnModNestEnv(7) env_tran_tail by blast    \n  qed \n  then obtain xs ys where hi:\"(\\<Gamma>, xs) \\<in> cpn n \\<Gamma> P t1 \\<and> (C, t1) # xsa = map (lift_catch Q) xs@((Skip,snd(last ((P, t1)#xs)))#ys)\"\n    by fastforce\n  have s1_s:\"s1=s\" using  CptnModNestEnv unfolding cp_def by auto\n  have \"\\<exists>xsa' ys. xs=((P,t1)#xsa') \\<and> (n,\\<Gamma>,((P,t1)#xsa'))\\<in>cptn_mod_nest_call \\<and> (C, t1) # xsa = map (lift_catch Q) ((P,t1)#xsa')@((Skip, snd(last xs))#ys)\" \n    using hi  unfolding cp_def\n  proof -\n      have \"(n,\\<Gamma>,xs)\\<in>cptn_mod_nest_call \\<and> xs!0 = (P,t1)\" using hi unfolding cpn_def by fastforce\n      moreover then have \"xs\\<noteq>[]\" using CptnEmpty calculation by blast      \n      moreover  obtain xsa' where \"xs=((P,t1)#xsa')\" using SmallStepCon.nth_tl calculation by fastforce \n      ultimately show ?thesis\n        using hi by auto\n  qed\n  then obtain xsa' ys where xs:\"xs=((P,t1)#xsa') \\<and> (n,\\<Gamma>,((P,t1)#xsa'))\\<in>cptn_mod_nest_call \\<and> (C, t1) # xsa = \n                                    map (lift_catch Q) ((P,t1)#xsa')@((Skip,snd(last ((P,s1)#(P,t1)#xsa')))#ys)\"\n    by fastforce\n  have env_tran:\"\\<Gamma>\\<turnstile>\\<^sub>c(P,s1) \\<rightarrow>\\<^sub>e (P,t1)\" using CptnModNestEnv Catch_env_P by (metis fst_conv nth_Cons_0)  \n  then have \"(n,\\<Gamma>,(P,s1)#(P,t1)#xsa')\\<in>cptn_mod_nest_call\" using xs env_tran CptnEnv    \n    by (simp add: cptn_mod_nest_call.CptnModNestEnv)   \n  then have \"(\\<Gamma>,(P,s1)#(P,t1)#xsa') \\<in> cpn n \\<Gamma> P s\" \n    using cpn_def s1_s by fastforce\n  moreover have \"(C,s1)#(C, t1) # xsa = map (lift_catch Q) ((P,s1)#(P,t1)#xsa')@((Skip,snd(last ((P,s1)#(P,t1)#xsa')))#ys)\"\n    using xs C unfolding lift_catch_def\n    by auto\n  ultimately show ?case by fastforce \nnext\n  case (CptnModNestSkip)\n  thus ?case by (metis SmallStepCon.redex_not_Catch fst_conv nth_Cons_0)\nnext\n  case (CptnModNestThrow)\n  thus ?case by (metis SmallStepCon.redex_not_Catch fst_conv nth_Cons_0)\nnext\n  case (CptnModNestCatch1 n \\<Gamma> P0 sa xsa zs P1)  \n  thus ?case\n  proof -\n    have \"\\<forall>c x. (LanguageCon.com.Catch c P1, x) # zs = map (lift_catch P1) ((c, x) # xsa)\"\n      using Cons_lift_catch CptnModNestCatch1.hyps(3) by blast\n    then have \"(P0, sa) # xsa = []\"\n      by (metis (no_types) CptnModNestCatch1.prems(3) LanguageCon.com.distinct(19) One_nat_def last_conv_nth last_lift_catch map_is_Nil_conv)\n    then show ?thesis\n      by force\n  qed \nnext\n  case (CptnModNestCatch2 n \\<Gamma> P1 sa xsa  ys zs Q1) \n  then have \"P1 = P \\<and> Q1 = Q \\<and> sa = s\" by auto  \n  moreover then have \"(\\<Gamma>, (P1,sa) # xsa)\\<in> cpn n \\<Gamma> P s\" \n    using CptnModNestCatch2(1)\n    by (simp add: cpn_def cptn_eq_cptn_mod_set)  \n  moreover obtain s' where \"last zs=(Skip, s')\" \n  proof -\n    assume a1: \"\\<And>s'. last zs = (LanguageCon.com.Skip, s') \\<Longrightarrow> thesis\"\n    have \"\\<exists>x. last zs = (LanguageCon.com.Skip, x)\"\n      by (metis (no_types) CptnModNestCatch2.hyps(6) CptnModNestCatch2.prems(3) append_is_Nil_conv last_ConsR list.simps(3) prod.exhaust_sel)\n    then show ?thesis\n      using a1 by metis\n  qed        \n  ultimately show ?case \n    using Cons_lift_catch_append CptnModNestCatch2.hyps(6)  by fastforce  \nnext \n  case (CptnModNestCatch3 n \\<Gamma> P0 sa xsa sa' P1 ys zs)   \n  then have \"P0 = P \\<and> P1 = Q \\<and> s=Normal sa\" by auto\n  then obtain i where zs:\"fst (zs!i) = Q \\<and> (i< (length zs))\" \n    using CptnModNestCatch3    \n    by (metis (no_types, lifting) add_diff_cancel_left' fst_conv length_Cons length_append nth_append_length zero_less_Suc zero_less_diff)    \n  then have si:\"Suc i< length ((Catch P0 P1,Normal sa)#zs)\" by fastforce\n  then have \"fst (((Seq P0 P1, Normal sa) # zs)!Suc i) = Q\" using zs by fastforce    \n  thus ?case using CptnModNestCatch3(9) zs\n     by (metis si nth_Cons_Suc)\nqed (auto)\n\nlemma Catch_sound3: \nassumes\n  a0:\"(\\<Gamma>,x)\\<in>cptn\" and\n  a1:\"x!0 = ((Catch P Q),s)\" and\n  a2:\"\\<forall>i<length x. fst (x!i)\\<noteq> Q\" and\n  a3:\"fst(last x) = Throw\" and\n  a4:\"env_tran_right \\<Gamma> x rely \"\nshows\n  \"False\"\nusing a0 a1 a2 a3 a4\nproof (induct arbitrary: P s)\n  case (CptnOne \\<Gamma> C s1) thus ?case by auto\nnext\n  case (CptnEnv \\<Gamma> C st t xsa) \n    thus ?case\n    proof -\n      have f1: \"env_tran_right \\<Gamma> ((C, t) # xsa) rely\"\n        using CptnEnv.prems(4) env_tran_tail by blast\n      have \"LanguageCon.com.Catch P Q = C\"\n        using CptnEnv.prems(1) by auto\n      then show ?thesis\n        using f1 CptnEnv.hyps(3) CptnEnv.prems(2) CptnEnv.prems(3) by moura\n    qed\nnext  \n  case (CptnComp \\<Gamma> C st C' st' xsa)\n  then have c_catch:\"C = (Catch P Q) \\<and> st = s\" by force\n  from CptnComp show ?case proof(cases)\n    case (Catchc P1 P1' P2) thus ?thesis\n    proof -\n      have f1: \"env_tran_right \\<Gamma> ((C', st') # xsa) rely\"\n        using CptnComp.prems(4) env_tran_tail by blast\n      have \"Q = P2\"\n        using c_catch Catchc(1)  by blast\n      then show ?thesis\n        using f1 CptnComp.hyps(3) CptnComp.prems(2) CptnComp.prems(3) Catchc(2) by moura\n    qed\n  next\n    case  (CatchSkipc) thus ?thesis\n    proof -\n      have \"fst (((C', st') # xsa) ! 0) = LanguageCon.com.Skip\"\n        by (simp add: local.CatchSkipc(2))\n      then show ?thesis\n        by (metis (no_types) CptnComp.hyps(2) CptnComp.prems(3) LanguageCon.com.distinct(17) \n            last_ConsR last_length length_Cons lessI list.simps(3) zero_skip_all_skip)\n    qed    \n  next\n    case (SeqThrowc C2 s') thus ?thesis\n     by (simp add: c_catch)    \n  next\n     case (FaultPropc) thus ?thesis \n      using c_catch redex_not_Catch by blast \n  next\n    case (StuckPropc) thus ?thesis \n      using c_catch redex_not_Catch by blast\n  next\n    case (AbruptPropc) thus ?thesis \n      using c_catch redex_not_Catch by blast\n  qed (auto)\nqed\n\nlemma catch_map_xs_ys':\n  assumes\n  a0:\"(n, \\<Gamma>, (P0, sa) # xsa) \\<in> cptn_mod_nest_call\" and    \n  a1:\"fst (last ((P0, sa) # xsa)) = C\" and\n  a2:\"(n,\\<Gamma>, (P1, snd (last ((P0, sa) # xsa))) # ys) \\<in> cptn_mod_nest_call\" and\n  a3:\"zs = map (lift_catch P1) xsa @ (P1, snd (last ((P0, sa) # xsa))) # ys\" and\n  a4:\"((LanguageCon.com.Catch P0 P1, sa) # zs) ! 0 = (LanguageCon.com.Catch P Q, s)\" and\n  a5:\"i < length ((LanguageCon.com.Catch P0 P1, sa) # zs) \\<and> ((LanguageCon.com.Catch P0 P1, sa) # zs) ! i = (Q, sj)\" and\n  a6:\"\\<forall>j<i. fst (((LanguageCon.com.Catch P0 P1, sa) # zs) ! j) \\<noteq> Q\"\nshows \n  \"\\<exists>xs ys. (\\<Gamma>, xs) \\<in> cpn n \\<Gamma> P s \\<and>\n            (\\<Gamma>, ys) \\<in> cpn n \\<Gamma> Q (snd (xs ! (i - 1))) \\<and> (LanguageCon.com.Catch P0 P1, sa) # zs = map (lift_catch Q) xs @ ys\"\nproof -\n  let ?P0 = \"(P0, sa) # xsa\"\n  have P_Q:\"P=P0 \\<and> s=sa \\<and> Q = P1\" using a4 by force\n  have i:\"i=(length ((P0, sa) # xsa))\"   \n  proof (cases \"i=(length ((P0, sa) # xsa))\")\n    case True thus ?thesis by auto\n  next\n    case False     \n    then have i:\"i<(length ((P0, sa) # xsa)) \\<or> i > (length ((P0, sa) # xsa))\" by auto\n    {\n      assume i:\"i<(length ((P0, sa) # xsa))\"\n      then have eq_map:\"((LanguageCon.com.Catch P0 P1, sa) # zs) ! i = map (lift_catch P1) ((P0, sa) # xsa) ! i\" \n        using a3 Cons_lift_catch_append\n        by (metis (no_types, lifting) length_map nth_append) \n      then have  \"\\<exists>ci si. map (lift_catch P1) ((P0, sa) # xsa) ! i = (Catch ci P1,si)\" \n        using i unfolding lift_catch_def\n        by (metis a5 eq_map fst_conv length_map map_lift_catch_all_catch)\n      then have  \"((LanguageCon.com.Catch P0 P1, sa) # zs) ! i \\<noteq> (Q, sj)\" \n        using P_Q eq_map by fastforce\n      then have ?thesis using a5 by auto\n    }note l=this\n    {\n      assume i:\"i>(length ((P0, sa) # xsa))\"\n      have \"fst (((LanguageCon.com.Catch P0 P1, sa) # zs) ! (length ?P0)) = Q\"\n        using a3 P_Q Cons_lift_catch_append by (metis fstI length_map nth_append_length) \n      then have ?thesis using a6 i by auto\n    }\n    thus ?thesis using l i by auto\n   qed\n   then have  \"(\\<Gamma>, (P0, sa) # xsa) \\<in> cpn n \\<Gamma> P s\" \n    using a0  P_Q unfolding cpn_def by fastforce\n  also have \"(\\<Gamma>, (P1, snd (last ((P0, sa) # xsa))) # ys) \\<in> cpn n \\<Gamma> Q (snd (?P0 ! ((length ?P0) -1)))\" \n    using a3 cptn_eq_cptn_mod P_Q unfolding cpn_def\n  proof -\n    have \"(n, \\<Gamma>, (Q, snd (last ((P0, sa) # xsa))) # ys) \\<in> cptn_mod_nest_call\"\n      using a2 P_Q by blast\n    then have \"(\\<Gamma>, (Q, snd (last ((P0, sa) # xsa))) # ys) \\<in> {(f, ps). ps ! 0 = (Q, snd (((P0, sa) # xsa) ! (Suc (length xsa) - 1))) \\<and> \n              (n, \\<Gamma>, ps) \\<in> cptn_mod_nest_call \\<and> f = \\<Gamma>}\"\n      by (simp add: cptn_eq_cptn_mod last_length)\n    then show \"(\\<Gamma>, (P1, snd (last ((P0, sa) # xsa))) # ys) \\<in> {(f, ps). ps ! 0 = (Q, snd (((P0, sa) # xsa) ! (length ((P0, sa) # xsa) - 1))) \\<and> (n,\\<Gamma>, ps) \\<in> cptn_mod_nest_call \\<and> f = \\<Gamma>}\"\n      using P_Q by force\n  qed \n  ultimately show ?thesis using a3 P_Q i using Cons_lift_catch_append by blast\nqed\n\n\nlemma Catch_sound4: \nassumes\n  a0:\"(n,\\<Gamma>,x)\\<in>cptn_mod_nest_call\" and\n  a1:\"x!0 = ((Catch P Q),s)\" and\n  a2:\"i<length x \\<and> x!i=(Q,sj)\" and\n  a3:\"\\<forall>j<i. fst(x!j)\\<noteq>Q\" and \n  a4:\"env_tran_right \\<Gamma> x rely \"\nshows\n  \"\\<exists>xs ys. (\\<Gamma>,xs) \\<in> (cpn n \\<Gamma> P s) \\<and> (\\<Gamma>,ys) \\<in> (cpn n \\<Gamma> Q (snd (xs!(i-1)))) \\<and> x = (map (lift_catch Q) xs)@ys\"\nusing a0 a1 a2 a3 a4\nproof (induct arbitrary: i sj P s)\n  case (CptnModNestEnv \\<Gamma> C st t n xsa)  \n  have a1:\"Catch P Q \\<noteq> Q\" by simp    \n  then have C_catch:\"C=(Catch P Q)\" using CptnModNestEnv by fastforce\n  then have \"fst(((C, st) # (C, t) # xsa)!0) \\<noteq>Q\" using CptnEnv a1 by auto\n  moreover have  \"fst(((C, st) # (C, t) # xsa)!1) \\<noteq>Q\" using CptnModNestEnv a1 by auto\n  moreover have \"fst(((C, st) # (C, t) # xsa)!i) =Q\" using CptnModNestEnv by auto\n  ultimately have i_suc: \"i> (Suc 0)\" using CptnModNestEnv \n    by (metis Suc_eq_plus1 Suc_lessI add.left_neutral neq0_conv) \n  then obtain i' where i':\"i=Suc i'\" by (meson lessE) \n  then have i_minus:\"i'=i-1\" by auto  \n  have \"((C, t) # xsa) ! 0 = ((Catch P Q), t)\"\n    using CptnModNestEnv by auto \n  moreover have \"i'< length ((C,t)#xsa) \\<and> ((C,t)#xsa)!i' = (Q,sj)\"\n    using i' CptnModNestEnv(5) by force\n  moreover have \"\\<forall>j<i'. fst (((C, t) # xsa) ! j) \\<noteq> Q\"\n    using i' CptnModNestEnv(6) by force\n  ultimately have hyp:\"\\<exists>xs ys.\n     (\\<Gamma>, xs) \\<in> cpn n \\<Gamma> P t \\<and>\n     (\\<Gamma>, ys) \\<in> cpn n \\<Gamma> Q (snd (xs ! (i'-1))) \\<and> (C, t) # xsa = map (lift_catch Q) xs @ ys\"\n    using CptnModNestEnv(3) env_tran_tail CptnModNestEnv.prems(4)  by blast \n  then obtain xs ys where xs_cp:\"(\\<Gamma>, xs) \\<in> cpn n \\<Gamma> P t \\<and>\n     (\\<Gamma>, ys) \\<in> cpn n \\<Gamma> Q (snd (xs ! (i'-1))) \\<and> (C, t) # xsa = map (lift_catch Q) xs @ ys\"\n    by fast\n  have \"(\\<Gamma>, (P, s)#xs) \\<in> cpn n \\<Gamma> P s\"\n  proof -\n    have \"xs!0 = (P,t)\" \n      using xs_cp unfolding cpn_def by blast\n    moreover have \"xs\\<noteq>[]\"\n      using cpn_def CptnEmpty xs_cp by blast \n    ultimately obtain xs' where xs':\"(n,\\<Gamma>, (P,t)#xs') \\<in> cptn_mod_nest_call \\<and> xs=(P,t)#xs'\" \n      using SmallStepCon.nth_tl xs_cp unfolding cpn_def by force\n    thus ?thesis using cpn_def  \n    proof -\n      have \"(Catch P Q, s) = (C, st)\"\n        using CptnModNestEnv.prems(1) by auto\n      then have \"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow>\\<^sub>e (P, t)\"\n        using Catch_env_P CptnModNestEnv(1) by blast\n      then show ?thesis\n        by (simp add: cpn_def cptn_mod_nest_call.CptnModNestEnv xs')\n    qed\n  qed\n  thus  ?case \n    using i_suc Cons_lift_catch_append CptnModNestEnv.prems(1) i' i_minus xs_cp\n    by fastforce   \nnext\n  case (CptnModNestSkip \\<Gamma> P s t n xs)\n  then show ?case\n    by (metis (no_types) CptnModNestSkip.hyps(2) CptnModNestSkip.prems(1) \n    fst_conv nth_Cons_0 redex_not_Catch)\nnext\n  case (CptnModNestThrow \\<Gamma> P s t n xs)\n  then show ?case  \n    by (metis (no_types) CptnModNestThrow.hyps(2) CptnModNestThrow.prems(1) \n       fst_conv nth_Cons_0 redex_not_Catch)\nnext\n  case (CptnModNestCatch1 n \\<Gamma> P0 s xs zs P1)\n  then show ?case\n    by (metis Catch_not_c Cons_lift_catch LanguageCon.com.inject(9) \n            fst_conv map_lift_catch_all_catch nth_Cons_0)\nnext\n  case (CptnModNestCatch2 n \\<Gamma> P1 sa xsa  ys zs Q1) \n  then have P_Q:\"P=P1 \\<and> Q = Q1\" by force\n  thus ?case\n  proof (cases \"Q1 = Skip\")\n    case True thus ?thesis using catch_map_xs_ys' \n      CptnModNestCatch2 by blast\n  next \n    case False note q_not_throw=this\n    have \"\\<forall>x. x< length ((LanguageCon.com.Catch P1 Q1, sa) # zs) \\<longrightarrow>\n              ((LanguageCon.com.Catch P1 Q1,  sa) # zs) ! x \\<noteq> (Q, sj)\" using CptnModNestCatch2\n    proof -\n    {\n      fix x\n      assume x_less:\"x< length ((LanguageCon.com.Catch P1 Q1,  sa) # zs)\"\n      have \"((LanguageCon.com.Catch P1 Q1,  sa) # zs) ! x \\<noteq> (Q, sj)\"\n      proof (cases \"x < length ((LanguageCon.com.Catch P1 Q1, sa)#map (lift_catch Q1) xsa)\")\n        case True \n        then have eq_map:\"((LanguageCon.com.Catch P1 Q1, sa) # zs) ! x = map (lift_catch Q1) ((P1, sa) # xsa) ! x\"           \n          by (metis (no_types) Cons_lift_catch Cons_lift_catch_append CptnModNestCatch2(6) True nth_append)\n        then have  \"\\<exists>ci si. map (lift_catch Q1) ((P1, sa) # xsa) ! x = (Catch ci Q1,si)\" \n          using True unfolding lift_catch_def\n          by (metis Cons_lift_catch True eq_map map_lift_catch_all_catch surjective_pairing)\n        then have  \"((LanguageCon.com.Catch P1 Q1, sa) # zs) ! x \\<noteq> (Q, sj)\" \n          using P_Q eq_map by fastforce     \n        thus ?thesis using CptnModNestCatch2(10) by auto        \n      next\n        case False \n        let ?s' = \"snd (last ((P1, sa) # xsa))\"        \n      have all_throw:\"\\<forall>i<length ((LanguageCon.com.Skip, ?s')# ys). \n              fst (((Skip, ?s')# ys)!i) = Skip\" using CptnModNestCatch2\n        by (metis cptn_eq_cptn_mod_set cptn_mod_nest_cptn_mod skip_all_skip)         \n      then have \n        \"\\<forall>x\\<ge> length ((LanguageCon.com.Catch P1 Q1,  sa) # map (lift_catch Q1) xsa). \n           x<length (((LanguageCon.com.Catch P1 Q1, sa) # zs)) \\<longrightarrow>\n              fst (((LanguageCon.com.Catch P1 Q1, sa) # zs) ! x) = Skip\"  \n        using  Cons_lift_catch Cons_lift_catch_append CptnModNestCatch2.hyps(1) CptnModNestCatch2.hyps(3) \n              CptnModNestCatch2.hyps(4) CptnModNestCatch2.hyps(6) cptn_eq_cptn_mod_set \n              cptn_mod_nest_call.CptnModNestCatch2 cptn_mod_nest_cptn_mod  skip_com_all_skip \n      proof-\n      {\n        fix x \n        assume a1:\"x\\<ge> length ((Catch P1 Q1, sa) # map (lift_catch Q1) xsa)\" and\n               a2:\"x<length (((Catch P1 Q1, sa) # zs))\"\n        then have \"((Catch P1 Q1, sa) # zs) ! x = \n                   ((Skip, ?s')# ys) !(x - (length ((Catch P1 Q1, sa) # map (lift_catch Q1) xsa)))\"\n        using CptnModNestCatch2(6) by (metis Cons_lift_catch Cons_lift_catch_append not_le nth_append)\n        then have\"fst (((Catch P1 Q1, sa) # zs) ! x) = Skip\" \n          using all_throw a1 a2 CptnModNestCatch2.hyps(6)  by auto \n      } thus ?thesis by auto\n      qed       \n      thus ?thesis using False  q_not_throw P_Q x_less \n        by (metis fst_conv not_le)  \n    qed\n    } thus ?thesis by auto\n    qed\n    thus ?thesis using CptnModNestCatch2(8) by fastforce    \n  qed\nnext\n  case (CptnModNestCatch3 n \\<Gamma> P1 sa xsa  ys zs Q1)\n  then show ?case using catch_map_xs_ys'[OF CptnModNestCatch3(1) CptnModNestCatch3(3) CptnModNestCatch3(5)\n                                            CptnModNestCatch3(7) CptnModNestCatch3(8) CptnModNestCatch3(9)] \n     by blast\nqed(auto) \n\ninductive_cases stepc_elim_cases_Catch_throw:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,s) \\<rightarrow> (Throw, Normal s1)\" \n\ninductive_cases stepc_elim_cases_Catch_skip_c2:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,s) \\<rightarrow> (c2,s)\"\n\ninductive_cases stepc_elim_cases_Catch_skip_2:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,s) \\<rightarrow> (Skip, s)\"\n\nlemma catch_skip_throw:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,s) \\<rightarrow> (c2,s)  \\<Longrightarrow> (c2= Skip \\<and> c1=Skip) \\<or> (c1=Throw \\<and> (\\<exists>s2'. s=Normal s2'))\"\napply (rule stepc_elim_cases_Catch_skip_c2)\napply fastforce\napply (auto)+\nusing redex_not_Catch apply auto\ndone\n\nlemma catch_skip_throw1:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,s) \\<rightarrow> (Skip,s)  \\<Longrightarrow> (c1=Skip) \\<or> (c1=Throw \\<and> (\\<exists>s2'. s=Normal s2') \\<and> c2 = Skip)\"\napply (rule stepc_elim_cases_Catch_skip_2)\nusing redex_not_Catch apply auto\nusing redex_not_Catch by auto\n\n\nlemma Catch_sound: \n      \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p,  R, G, q,r] \\<Longrightarrow>\n       \\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p,  R, G, q,r] \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c2 sat [r,  R, G, q,a] \\<Longrightarrow>\n       \\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> c2 sat [r,  R, G, q,a] \\<Longrightarrow>        \n       Sta q R  \\<Longrightarrow>  (\\<forall>s. (Normal s,Normal s) \\<in> G) \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Catch c1 c2) sat [p, R, G, q,a]\"\nproof -  \n  assume\n    a0:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p, R, G, q,r]\" and\n    a1:\"\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p, R, G, q,r]\" and\n    a2:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c2 sat [r, R, G, q,a]\" and    \n    a3: \"\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> c2 sat [r, R, G, q,a]\" and     \n    a4: \"Sta q R \" and\n    a5: \"(\\<forall>s. (Normal s, Normal s) \\<in> G)\"       \n  { \n    fix s\n    assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"\n    then have a1:\"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p, R, G, q,r]\" \n      using a1 com_cvalidityn_def by fastforce  \n    then have a3: \"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c2 sat [r, R, G, q,a]\"\n      using a3 com_cvalidityn_def all_call by fastforce \n    have \"cpn n \\<Gamma> (Catch c1 c2)  s \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cpn n \\<Gamma> (Catch c1 c2) s\" and a11:\"c \\<in> assum(p, R)\"\n      then have a10':\"c \\<in> cp \\<Gamma> (Catch c1 c2) s\"\n        unfolding cpn_def cp_def\n        using cptn_if_cptn_mod cptn_mod_nest_cptn_mod by blast\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have cp:\"l!0=((Catch c1 c2),s) \\<and> (n,\\<Gamma>,l) \\<in> cptn_mod_nest_call \\<and> \\<Gamma>=\\<Gamma>1\" \n        using a10 cpn_def c_prod by fastforce\n      then have cp':\"l!0=((Catch c1 c2),s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\"\n        using cptn_eq_cptn_mod_nest by auto         \n      have \\<Gamma>1:\"(\\<Gamma>, l) = c\" using c_prod cp by blast\n      have \"c \\<in> comm(G, (q,a)) F\"         \n      proof - \n      {\n       assume l_f:\"snd (last l) \\<notin> Fault ` F\"       \n       have assum:\"snd(l!0) \\<in> Normal ` (p) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n                 (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n       using a11 c_prod unfolding assum_def by simp\n       then have env_tran:\"env_tran \\<Gamma> p l R\" using env_tran_def cp by blast\n       then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n         using env_tran env_tran_right_def unfolding env_tran_def by auto       \n       have \"(\\<forall>i. Suc i<length l \\<longrightarrow> \n               \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i))  \\<longrightarrow>              \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\\<and>\n             (final (last l)  \\<longrightarrow>                    \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a)))\"\n       proof (cases \"\\<forall>i<length l. fst (l!i)\\<noteq> c2\")\n         case True \n         then have no_c2:\"\\<forall>i<length l. fst (l!i)\\<noteq> c2\" by assumption\n         show ?thesis\n         proof (cases \"final (last l)\")\n           case True\n           then obtain s' where \"fst (last l) = Skip \\<or> (fst (last l) = Throw \\<and> snd (last l) = Normal s')\"  \n             using final_def by fast           \n           thus ?thesis\n           proof\n             assume \"fst (last l)= LanguageCon.com.Throw \\<and> snd (last l) = Normal s'\" \n             then have \"False\" using  no_c2 env_tran_right cp' cptn_eq_cptn_mod_set Catch_sound3\n               by blast\n             thus ?thesis by auto\n           next             \n             assume asm0:\"fst (last l) = Skip\"             \n             then obtain lc1 ys where cp_lc1:\"(\\<Gamma>,lc1) \\<in> cpn n \\<Gamma> c1 s \\<and> l = ((map (lift_catch c2) lc1)@((Skip,snd(last lc1))#ys))\"\n               using Catch_sound2 cp cptn_eq_cptn_mod_set env_tran_right no_c2 by blast\n             then have cp_lc1':\"(\\<Gamma>,lc1) \\<in> cp \\<Gamma> c1 s\"\n               unfolding cpn_def cp_def\n               using cptn_if_cptn_mod cptn_mod_nest_cptn_mod by fastforce \n             let ?m_lc1 = \"map (lift_catch c2) lc1\"\n             let ?lm_lc1 = \"(length ?m_lc1)\"\n             let ?last_m_lc1 = \"?m_lc1!(?lm_lc1-1)\"              \n             have lc1_not_empty:\"lc1 \\<noteq> []\"\n               using \\<Gamma>1 a10' cpn_def cp_lc1 cp by auto                 \n             then have map_cp:\"(\\<Gamma>,?m_lc1) \\<in> cpn n \\<Gamma> (Catch c1 c2) s\"               \n             proof -\n               have f1: \"lc1 ! 0 = (c1, s) \\<and> (n, \\<Gamma>, lc1) \\<in> cptn_mod_nest_call \\<and> \\<Gamma> = \\<Gamma>\"\n                 using cp_lc1 unfolding cpn_def by blast\n               then have f2: \"(n,\\<Gamma>, ?m_lc1) \\<in> cptn_mod_nest_call\" using lc1_not_empty\n                 by (metis Cons_lift_catch SmallStepCon.nth_tl cptn_mod_nest_call.CptnModNestCatch1)\n               then show ?thesis\n                 using f2 f1 lc1_not_empty by (simp add: cpn_def lift_catch_def)\n             qed\n             then have map_cp':\"(\\<Gamma>,?m_lc1) \\<in> cp \\<Gamma> (Catch c1 c2) s\" \n               unfolding cp_def cpn_def\n               using cp_def cp_lc1' lift_catch_is_cptn by fastforce\n             also have map_assum:\"(\\<Gamma>,?m_lc1) \\<in> assum (p,R)\"\n               using sub_assum a10 a11 \\<Gamma>1 cp_lc1 lc1_not_empty \n               by (metis SmallStepCon.nth_tl map_is_Nil_conv)\n             ultimately have \"((\\<Gamma>,lc1) \\<in> assum(p, R))\"  \n               using \\<Gamma>1 assum_map_catch cp_lc1' by blast                          \n             then have lc1_comm:\"(\\<Gamma>,lc1) \\<in> comm(G, (q,r)) F\"  \n               using a1 cp_lc1 by (meson IntI com_validityn_def contra_subsetD)\n             then have m_lc1_comm:\"(\\<Gamma>,?m_lc1) \\<in> comm(G, (q,r)) F\"\n               using map_cp map_assum comm_map_catch cp_lc1' map_cp' by blast\n             then have last_m_lc1:\"last (?m_lc1) = (Catch (fst (last lc1)) c2,snd (last lc1))\"\n             proof -\n               have a000:\"\\<forall>p c. (LanguageCon.com.Catch (fst p) c, snd p) = lift_catch c p\"\n                 using Cons_lift_catch by force\n               then show ?thesis\n                 by (simp add: last_map a000 lc1_not_empty)\n             qed\n             then have last_length:\"last (?m_lc1) = ?last_m_lc1\"  \n               using lc1_not_empty last_conv_nth list.map_disc_iff by blast \n             then have l_map:\"l!(?lm_lc1-1)= ?last_m_lc1\" \n               using cp_lc1\n               by (simp add:lc1_not_empty nth_append)\n             then have lm_lc1:\"l!(?lm_lc1) = (Skip, snd (last lc1))\"\n               using cp_lc1 by (meson nth_append_length) \n             then have step:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!(?lm_lc1-1)) \\<rightarrow> (l!(?lm_lc1))\"\n             proof -\n               have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!(?lm_lc1-1)) \\<rightarrow>\\<^sub>c\\<^sub>e (l!(?lm_lc1))\"\n               proof -\n                 have f1: \"0 \\<le> length ys\"\n                   by blast\n                 moreover have  \"Suc (length (map (lift_catch c2) lc1) + length ys) = \n                      length (map (lift_catch c2) lc1 @ (LanguageCon.com.Skip, snd (last lc1)) # ys)\"\n                   by force\n                 ultimately show ?thesis\n                   by (metis (no_types) Suc_diff_1 Suc_eq_plus1 cp' cp_lc1 cptn_tran_ce_i \n                              lc1_not_empty le_add_same_cancel1 length_greater_0_conv \n                    less_Suc_eq_le list.map_disc_iff)\n               qed                              \n               moreover have \"\\<not>\\<Gamma>\\<turnstile>\\<^sub>c(l!(?lm_lc1-1)) \\<rightarrow>\\<^sub>e (l!(?lm_lc1))\"\n               using  last_m_lc1 last_length l_map\n               proof -\n                 have \"(LanguageCon.com.Catch (fst (last lc1)) c2, snd (last lc1)) = l ! (length (map (lift_catch c2) lc1) - 1)\"\n                   using l_map last_m_lc1 local.last_length by presburger\n                 then show ?thesis\n                   by (metis LanguageCon.com.simps(30) env_c_c' lm_lc1)                   \n               qed\n               ultimately show ?thesis using step_ce_elim_cases by blast        \n             qed\n             have last_lc1_suc:\"snd (l!(?lm_lc1-1)) = snd (l!?lm_lc1)\"\n               using l_map  last_m_lc1 lm_lc1 local.last_length by force\n             then have step_catch:\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch (fst (last lc1)) c2,snd (last lc1)) \\<rightarrow> (Skip, snd (last lc1))\"               \n               using l_map last_m_lc1 lm_lc1 local.last_length local.step \n               by presburger \n             then obtain s2' where \n               last_lc1:\"fst (last lc1) = Skip  \\<or> \n               fst (last lc1) = Throw \\<and> (snd (last lc1) = Normal s2') \\<and> c2 = Skip\"\n             using catch_skip_throw1 by fastforce              \n             then have last_lc1_skip:\"fst (last lc1) = Skip\" \n             proof \n                assume \"fst (last lc1) = LanguageCon.com.Throw \\<and>\n                        snd (last lc1) = Normal s2' \\<and> c2 = LanguageCon.com.Skip\"\n                thus ?thesis using no_c2 asm0 \n                  by (simp add: cp_lc1 last_conv_nth ) \n             qed auto  \n             have last_not_F:\"snd (last ?m_lc1) \\<notin> Fault ` F\"\n             proof -\n               have \"snd ?last_m_lc1 = snd (l!(?lm_lc1-1))\"\n                 using l_map by auto \n               have \"(?lm_lc1-1)< length l\"using cp_lc1 by fastforce\n               also then have \"snd (l!(?lm_lc1-1))\\<notin> Fault ` F\"\n                 using cp' cp_lc1  l_f  last_not_F[of \\<Gamma> l F]\n                 by fastforce\n               ultimately show ?thesis using l_map last_length by fastforce\n             qed\n             then have q_normal:\"snd (l!?lm_lc1) \\<in> Normal ` q \" \n             proof -\n               have last_lc1:\"fst (last lc1) = Skip\" \n               using last_lc1_skip by fastforce  \n               have \"final (last lc1)\" using last_lc1 final_def \n                 by blast              \n               then show ?thesis \n                 using lc1_comm last_lc1 last_not_F \n                 unfolding comm_def\n                 using  last_lc1_suc comm_dest2 l_map lm_lc1 local.last_length\n                 by force\n             qed                                             \n             then obtain s1' where normal_lm_lc1:\"snd (l!?lm_lc1) = Normal s1' \\<and> s1' \\<in>q\" \n               by auto\n             have concl:\"(\\<forall>i ns ns'. Suc i<length l \\<longrightarrow> \n               \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>              \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n             proof-\n             { fix k ns ns'\n               assume a00:\"Suc k<length l\" and\n                a21:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"   \n                then have i_m_l:\"\\<forall>i <?lm_lc1  . l!i = ?m_lc1!i\" \n                  using cp_lc1\n                proof -\n                  have \"map (lift c2) lc1 \\<noteq> []\"\n                    by (meson lc1_not_empty list.map_disc_iff)\n                  then show ?thesis\n                    by (metis (no_types) cp_lc1  nth_append)\n                qed                                                         \n                have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n                proof (cases \"Suc k< ?lm_lc1\")\n                  case True \n                  then have a11': \"\\<Gamma>\\<turnstile>\\<^sub>c(?m_lc1!k)  \\<rightarrow> (?m_lc1!(Suc k))\" \n                    using a11 i_m_l True\n                  proof -\n                    have \"\\<forall>n na. \\<not> 0 < n - Suc na \\<or> na < n \"\n                      using diff_Suc_eq_diff_pred zero_less_diff by presburger\n                    then show ?thesis\n                      by (metis (no_types) True a21 i_m_l zero_less_diff)\n                  qed                 \n                  then have \"(snd(?m_lc1!k), snd(?m_lc1!(Suc k))) \\<in> G\"\n                  using a11' m_lc1_comm True comm_dest1 l_f last_not_F by fastforce\n                  thus ?thesis using i_m_l True by auto  \n                next\n                  case False \n                  then have \"(Suc k=?lm_lc1) \\<or> (Suc k>?lm_lc1)\" by auto\n                  thus ?thesis \n                  proof\n                    {assume suck:\"(Suc k=?lm_lc1)\"\n                     then have k:\"k=?lm_lc1-1\" by auto\n                     then obtain s1' where s1'_normal:\"snd(l!?lm_lc1) = Normal s1'\"\n                       using q_normal by fastforce\n                     have G_s1':\"(Normal s1', Normal s1')\\<in> G\" using a5 by auto\n                     then show \"(snd (l!k), snd (l!Suc k)) \\<in> G\"\n                     proof -\n                       have \"snd (l ! k) = Normal s1'\"\n                         using k last_lc1_suc s1'_normal by presburger\n                       then show ?thesis\n                         using G_s1' s1'_normal suck by force\n                     qed                                   \n                    }\n                  next\n                  { \n                    assume a001:\"Suc k>?lm_lc1\"\n                    have \"\\<forall>i. i\\<ge>(length lc1) \\<and> (Suc i < length l) \\<longrightarrow> \n                            \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)))\"\n                    using lm_lc1 lc1_not_empty\n                    proof -\n                      have \"env_tran_right \\<Gamma>1 l R\"\n                        by (metis cp env_tran_right)\n                      then show ?thesis \n                        using  cp' fst_conv length_map lm_lc1 a001 a21 a00 a4\n                              normal_lm_lc1 \n                        by (metis (no_types) only_one_component_tran_j)\n                    qed\n                    then have \"\\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n                      using a00 a001 by auto                    \n                    then show ?thesis using a21 by fastforce                    \n                  }\n                  qed \n                qed\n              } thus ?thesis by auto \n             qed \n             have concr:\"(final (last l)  \\<longrightarrow>                    \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a)))\" \n             proof -\n               have l_t:\"fst (last l) = Skip\" \n                 using lm_lc1 by (simp add: asm0)\n               have \"?lm_lc1 \\<le> length l -1\" using cp_lc1 by fastforce               \n               also have \"\\<forall>i. ?lm_lc1 \\<le>i \\<and> i<(length l -1) \\<longrightarrow>  \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i))\"        \n                 using cp' fst_conv length_map lm_lc1 a4\n                      normal_lm_lc1 only_one_component_tran_j[of \\<Gamma> l ?lm_lc1 s1' q ]\n                 by (metis Suc_eq_plus1 cptn_tran_ce_i env_tran_right less_diff_conv  step_ce_elim_cases)                                                                       \n               ultimately have \"snd (l ! (length l - 1)) \\<in> Normal ` q\"\n                 using cp_lc1 q_normal a4 env_tran_right stability[of q R l ?lm_lc1 \"(length l) -1\" _ \\<Gamma>] \n                 by fastforce               \n               thus ?thesis using l_t \n                 by (simp add:  cp_lc1 last_conv_nth)\n             qed\n             note res = conjI [OF concl concr]\n             then show ?thesis using  \\<Gamma>1 c_prod unfolding comm_def by auto\n           qed                  \n         next\n           case False\n           then obtain lc1 where cp_lc1:\"(\\<Gamma>,lc1) \\<in> cpn n \\<Gamma> c1 s \\<and> l = map (lift_catch c2) lc1\" \n             using Catch_sound1 False no_c2 env_tran_right cp cptn_eq_cptn_mod_set \n             by blast \n           then have cp_lc1':\"(\\<Gamma>,lc1) \\<in> cp \\<Gamma> c1 s\" \n             unfolding cpn_def cp_def\n             using cptn_eq_cptn_mod_nest by fastforce\n           then have \"((\\<Gamma>,lc1) \\<in> assum(p, R))\"  \n              using \\<Gamma>1  a10' a11 assum_map_catch cp_lc1\n              by blast\n           then have \"(\\<Gamma>, lc1)\\<in> comm(G, (q,r)) F\" using cp_lc1 a1\n             by (meson IntI com_validityn_def contra_subsetD)\n           then have \"(\\<Gamma>, l)\\<in> comm(G, (q,r)) F\"\n             using comm_map_catch a10' \\<Gamma>1 cp_lc1 cp_lc1' by fastforce\n           then show ?thesis using l_f False\n             unfolding comm_def by fastforce\n         qed\n       next         \n         case False \n         then obtain k where k_len:\"k<length l \\<and> fst (l ! k) = c2\"\n           by blast         \n         then have \"\\<exists>m. (m < length l \\<and> fst (l ! m) = c2) \\<and>\n                   (\\<forall>i<m. \\<not> (i < length l \\<and> fst (l ! i) = c2))\"   \n           using a0 exists_first_occ[of \"(\\<lambda>i. i<length l  \\<and> fst (l ! i) = c2)\" k] \n           by blast\n         then obtain i where a0:\"i<length l \\<and> fst (l !i) = c2 \\<and>\n                                (\\<forall>j<i. (fst (l ! j) \\<noteq> c2))\"\n           by fastforce        \n         then obtain s2 where li:\"l!i =(c2,s2)\" by (meson eq_fst_iff)\n         then obtain lc1 lc2 where cp_lc1:\"(\\<Gamma>,lc1) \\<in> (cpn n \\<Gamma> c1 s) \\<and> \n                                 (\\<Gamma>,lc2) \\<in> (cpn n \\<Gamma> c2 (snd (lc1!(i-1)))) \\<and> \n                                 l = (map (lift_catch c2) lc1)@lc2\"\n           using Catch_sound4 a0 cp env_tran_right by blast       \n         then have cp_lc1':\"(\\<Gamma>,lc1) \\<in> (cp \\<Gamma> c1 s) \\<and> \n                            (\\<Gamma>,lc2) \\<in> (cp \\<Gamma> c2 (snd (lc1!(i-1))))\"\n           unfolding cp_def cpn_def  using cptn_eq_cptn_mod_nest by fastforce\n         have i_not_fault:\"snd (l!i) \\<notin> Fault ` F\" using a0  cp' l_f last_not_F[of \\<Gamma> l F] by blast\n         have length_c1_map:\"length lc1 = length (map (lift_catch c2) lc1)\" \n           by fastforce      \n         then have i_map:\"i=length lc1\" \n           using cp_lc1 li a0 unfolding lift_catch_def \n         proof -\n            assume a1: \"(\\<Gamma>, lc1) \\<in> cpn n \\<Gamma> c1 s \\<and> (\\<Gamma>, lc2) \\<in> cpn n \\<Gamma> c2 (snd (lc1 ! (i - 1))) \\<and> l = map (\\<lambda>(P, s). (Catch P c2, s)) lc1 @ lc2\"\n            have f2: \"i < length l \\<and> fst (l ! i) = c2 \\<and> (\\<forall>n. \\<not> n < i \\<or> fst (l ! n) \\<noteq> c2)\"\n              using a0 by blast\n            have f3: \"(Catch (fst (lc1 ! i)) c2, snd (lc1 ! i)) = lift_catch c2 (lc1 ! i)\"\n              by (simp add: case_prod_unfold lift_catch_def)            \n            then have \"fst (l ! length lc1) = c2\"\n              using a1 by (simp add: cpn_def nth_append)\n            thus ?thesis\n              using f3 f2\n              by (metis (no_types, lifting) Pair_inject a0 cp_lc1 f3 \n                   length_c1_map li linorder_neqE_nat nth_append nth_map seq_and_if_not_eq(12))\n         qed                  \n         have lc2_l:\"\\<forall>j<length lc2. lc2!j=l!(i+j)\"\n           using cp_lc1 length_c1_map i_map a0\n           by (metis nth_append_length_plus)                                                             \n         have lc1_not_empty:\"lc1 \\<noteq> []\"\n           using cp cp_lc1 unfolding cpn_def by fastforce      \n         have lc2_not_empty:\"lc2 \\<noteq> []\"\n           using cpn_def cp_lc1 a0 i_map by force              \n         have l_is:\"s2= snd (last lc1)\"\n         using cp_lc1 li a0 lc1_not_empty unfolding cpn_def\n         by (auto simp add: i_map last_conv_nth lc2_l)\n         let ?m_lc1 = \"map (lift_catch c2) lc1\"\n         (* let ?lm_lc1 = \"(length ?m_lc1)\"\n         let ?last_m_lc1 = \"?m_lc1!(?lm_lc1-1)\" *)                         \n         have last_m_lc1:\"l!(i-1) = (Catch (fst (last lc1)) c2,s2)\"\n           using i_map  cp_lc1 l_is last_lift_catch last_snd_catch lc1_not_empty length_c1_map           \n         by (metis (no_types, lifting) One_nat_def diff_Suc_less last_conv_nth length_greater_0_conv nth_append prod.collapse)\n         have last_mcl1_not_F:\"snd (last ?m_lc1) \\<notin> Fault ` F\"\n           by (metis One_nat_def i_not_fault l_is last_conv_nth last_snd_catch li list.map_disc_iff snd_conv)                                  \n         have map_cp:\"(\\<Gamma>,?m_lc1) \\<in> cpn n \\<Gamma> (Catch c1 c2) s\"               \n         proof -\n           have f1: \"lc1 ! 0 = (c1, s) \\<and> (n,\\<Gamma>, lc1) \\<in> cptn_mod_nest_call \\<and> \\<Gamma> = \\<Gamma>\"\n             using cp_lc1 cpn_def by blast\n           then have f2: \"(n, \\<Gamma>, ?m_lc1) \\<in> cptn_mod_nest_call\" using lc1_not_empty\n             by (metis Cons_lift_catch SmallStepCon.nth_tl cptn_mod_nest_call.CptnModNestCatch1)                           \n           then show ?thesis\n             using f2 f1 lc1_not_empty by (simp add: cpn_def lift_catch_def)\n         qed\n         then have map_cp':\"(\\<Gamma>,?m_lc1) \\<in> cp \\<Gamma> (Catch c1 c2) s\"\n           unfolding cp_def cpn_def using cptn_eq_cptn_mod_nest by fastforce\n         also have map_assum:\"(\\<Gamma>,?m_lc1) \\<in> assum (p,R)\"\n           using sub_assum a10 a11 \\<Gamma>1 cp_lc1 lc1_not_empty \n           by (metis SmallStepCon.nth_tl map_is_Nil_conv)\n         ultimately have \"((\\<Gamma>,lc1) \\<in> assum(p, R))\"  \n           using \\<Gamma>1 assum_map_catch using assum_map cp_lc1 cp_lc1' by blast                          \n         then have lc1_comm:\"(\\<Gamma>,lc1) \\<in> comm(G, (q,r)) F\"  \n           using a1 cp_lc1 by (meson IntI com_validityn_def contra_subsetD)\n         then have m_lc1_comm:\"(\\<Gamma>,?m_lc1) \\<in> comm(G, (q,r)) F\"\n           using map_cp' map_assum comm_map_catch cp_lc1 cp_lc1'  by blast         \n         then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!(i-1)) \\<rightarrow> (l!i)\"\n         proof -\n           have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!(i-1)) \\<rightarrow>\\<^sub>c\\<^sub>e (l!(i))\"\n             by (metis Suc_eq_plus1 Suc_pred' a0 cp' cptn_tran_ce_i i_map \n                  lc1_not_empty length_greater_0_conv)\n           moreover have \"\\<not>\\<Gamma>\\<turnstile>\\<^sub>c(l!(i-1)) \\<rightarrow>\\<^sub>e (l!i)\"           \n             using li last_m_lc1\n             by (metis (no_types, lifting) env_c_c' seq_and_if_not_eq(12))\n           ultimately show ?thesis using step_ce_elim_cases by blast\n         qed         \n         then have step:\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch (fst (last lc1)) c2,s2) \\<rightarrow> (c2, s2)\"\n           using last_m_lc1  li by fastforce\n         then obtain s2' where \n           last_lc1:\"(fst (last lc1) = Skip \\<and> c2 = Skip) \\<or> \n            fst (last lc1) = Throw \\<and> (s2 = Normal s2')\" \n           using catch_skip_throw by blast    \n         have final:\"final (last lc1)\" \n           using last_lc1 l_is unfolding final_def by auto\n         have normal_last:\"fst (last lc1) = Skip \\<and> snd (last lc1) \\<in> Normal ` q \\<or>\n                        fst (last lc1) = Throw \\<and> snd (last lc1) \\<in> Normal ` r\"\n         proof -         \n           have \"snd (last lc1) \\<notin> Fault ` F\"\n             using i_not_fault l_is li by auto\n           then show ?thesis\n             using final comm_dest2 lc1_comm by blast\n         qed\n         obtain s2' where lastlc1_normal:\"snd (last lc1) = Normal s2'\" \n           using normal_last by blast\n         then have Normals2:\"s2 = Normal s2'\" by (simp add: l_is) \n         have Gs2':\" (Normal s2', Normal s2')\\<in>G\" using a5 by auto              \n         have concl:\n           \"(\\<forall>i. Suc i<length l \\<longrightarrow> \n           \\<Gamma>\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                              \n             (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n         proof-\n         { fix k ns ns'\n           assume a00:\"Suc k<length l\" and\n            a21:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"   \n            have i_m_l:\"\\<forall>j <i . l!j = ?m_lc1!j\"             \n            proof -\n              have \"map (lift c2) lc1 \\<noteq> []\"\n                by (meson lc1_not_empty list.map_disc_iff)\n              then show ?thesis \n                using cp_lc1 i_map length_c1_map by (fastforce simp:nth_append)              \n            qed \n            have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n            proof (cases \"Suc k< i\")\n              case True \n              then have a11': \"\\<Gamma>\\<turnstile>\\<^sub>c(?m_lc1!k)  \\<rightarrow> (?m_lc1!(Suc k))\" \n                using a11 i_m_l True\n              proof -\n                have \"\\<forall>n na. \\<not> 0 < n - Suc na \\<or> na < n \"\n                  using diff_Suc_eq_diff_pred zero_less_diff by presburger\n                then show ?thesis using True a21 i_m_l by force                  \n              qed                                                             \n              have \"Suc k < length ?m_lc1\" using True i_map length_c1_map by metis\n              then have \"(snd(?m_lc1!k), snd(?m_lc1!(Suc k))) \\<in> G\"\n              using a11' last_mcl1_not_F m_lc1_comm True i_map length_c1_map comm_dest1[of \\<Gamma>] \n                by blast\n              thus ?thesis using i_m_l True by auto  \n            next\n              case False                                            \n              have \"(Suc k=i) \\<or> (Suc k>i)\" using False by auto\n              thus ?thesis \n              proof\n              { assume suck:\"(Suc k=i)\" \n                then have k:\"k=i-1\" by auto                                                            \n                then show \"(snd (l!k), snd (l!Suc k)) \\<in> G\"\n                  using Gs2' Normals2 last_m_lc1 li suck by auto               \n              }\n              next\n              { \n                assume a001:\"Suc k>i\"\n                then have k:\"k\\<ge>i\" by fastforce\n                then obtain k' where k':\"k=i+k'\" \n                  using add.commute le_Suc_ex by blast\n                {assume skip:\"c2=Skip\"\n                 then have \"\\<forall>k. k\\<ge>i \\<and> (Suc k < length l) \\<longrightarrow> \n                            \\<not>(\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k)))\"\n                  using Normals2 li lastlc1_normal a21 a001 a00 a4\n                        a0 skip env_tran_right cp'\n                  by (metis SmallStepCon.final_def SmallStepCon.no_step_final' Suc_lessD skip_com_all_skip)                                      \n                 then have ?thesis using a21 a001 k a00 by blast\n                }  note left=this\n                {assume \"c2\\<noteq>Skip\"\n                 then have \"fst (last lc1) = Throw\"\n                   using last_m_lc1 last_lc1 by simp                                     \n                 then have s2_normal:\"s2 \\<in> Normal ` r\" \n                   using normal_last lastlc1_normal Normals2\n                   by fastforce\n                 have length_lc2:\"length l=i+length lc2\" \n                       using i_map cp_lc1 by fastforce\n                 have \"(\\<Gamma>,lc2) \\<in>  assum (r,R)\" \n                 proof -\n                   have left:\"snd (lc2!0) \\<in> Normal ` r\" \n                     using li lc2_l s2_normal lc2_not_empty by fastforce \n                   {\n                     fix j\n                     assume j_len:\"Suc j<length lc2\" and\n                            j_step:\"\\<Gamma>\\<turnstile>\\<^sub>c(lc2!j)  \\<rightarrow>\\<^sub>e (lc2!(Suc j))\"                     \n                     then have suc_len:\"Suc (i + j)<length l\" using j_len length_lc2\n                       by fastforce\n                     also then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!(i+j))  \\<rightarrow>\\<^sub>e (l! (Suc (i+ j)))\"\n                        using lc2_l j_step j_len by fastforce\n                     ultimately have \"(snd(lc2!j), snd(lc2!(Suc j))) \\<in> R\"\n                        using assum suc_len lc2_l j_len cp by fastforce \n                   }\n                   then show ?thesis using left \n                     unfolding assum_def by fastforce\n                 qed\n                 also have \"(\\<Gamma>,lc2) \\<in> cpn n \\<Gamma> c2 s2\"\n                   using cp_lc1 i_map l_is last_conv_nth lc1_not_empty by fastforce                 \n                 ultimately have comm_lc2:\"(\\<Gamma>,lc2) \\<in>  comm (G, (q,a)) F\"\n                   using a3 unfolding com_validityn_def by auto\n                 have lc2_last_f:\"snd (last lc2)\\<notin> Fault ` F\" \n                   using lc2_l lc2_not_empty l_f cp_lc1 by fastforce\n                 have suck':\"Suc k' < length lc2\" \n                   using k' a00 length_lc2 by arith\n                 moreover then have \"\\<Gamma>\\<turnstile>\\<^sub>c(lc2!k')  \\<rightarrow> (lc2!(Suc k'))\"  \n                   using k' lc2_l a21 by fastforce                 \n                 ultimately have \"(snd (lc2! k'), snd (lc2 ! Suc k')) \\<in> G\"\n                   using comm_lc2  lc2_last_f comm_dest1[of \\<Gamma> lc2 G q a F k'] \n                   by blast\n                 then have ?thesis using suck' lc2_l k' by fastforce\n                }                    \n                then show ?thesis using left by auto                 \n              }\n              qed \n            qed\n          } thus ?thesis by auto \n         qed note left=this\n         have right:\"(final (last l)  \\<longrightarrow>                    \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a)))\"\n         proof -\n         { assume final_l:\"final (last l)\" \n           have eq_last_lc2_l:\"last l=last lc2\" by (simp add: cp_lc1 lc2_not_empty)\n           then have final_lc2:\"final (last lc2)\" using final_l by auto\n           {\n             assume lst_lc1_skip:\"fst (last lc1) = Skip\"                        \n             then have c2_skip:\"c2 = Skip\" \n               using  step lastlc1_normal LanguageCon.com.distinct(17) last_lc1 \n               by auto                            \n             have Skip:\"fst (l!(length l - 1)) = Skip\"\n             using li Normals2  env_tran_right cp' c2_skip a0\n                     i_skip_all_skip[of \\<Gamma> l i \"(length l) - 1\" _] \n                by fastforce                       \n             have s2_a:\"s2 \\<in> Normal ` q\"\n               using normal_last \n               by (simp add: lst_lc1_skip l_is)\n             then have \"\\<forall>ia. i \\<le> ia \\<and> ia < length l - 1 \\<longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c l ! ia \\<rightarrow>\\<^sub>e l ! Suc ia\"\n               using c2_skip li Normals2 a0 cp' env_tran_right  final_def\n               by (metis (no_types, hide_lams) One_nat_def SmallStepCon.no_step_final' \n                   Suc_lessD add.right_neutral add_Suc_right \n                   cptn_tran_ce_i i_skip_all_skip less_diff_conv step_ce_elim_cases)                           \n             then have \"snd (l!(length l - 1)) \\<in> Normal ` q \\<and> fst (l!(length l - 1)) = Skip\"               \n               using a0 s2_a li a4 env_tran_right stability[of q R l i \"(length l) -1\" _ \\<Gamma>] Skip                \n               by (metis One_nat_def Suc_pred length_greater_0_conv lessI linorder_not_less list.size(3) \n                   not_less0 not_less_eq_eq snd_conv)\n             then have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a))\" \n              using a0 by (metis last_conv_nth list.size(3) not_less0)                           \n          }  note left = this\n          {  assume \"fst (last lc1) = Throw\"                 \n             then have s2_normal:\"s2 \\<in> Normal ` r\" \n               using normal_last lastlc1_normal Normals2\n               by fastforce\n             have length_lc2:\"length l=i+length lc2\" \n                   using i_map cp_lc1 by fastforce\n             have \"(\\<Gamma>,lc2) \\<in>  assum (r,R)\" \n             proof -\n               have left:\"snd (lc2!0) \\<in> Normal ` r\" \n                 using li lc2_l s2_normal lc2_not_empty by fastforce \n               {\n                 fix j\n                 assume j_len:\"Suc j<length lc2\" and\n                        j_step:\"\\<Gamma>\\<turnstile>\\<^sub>c(lc2!j)  \\<rightarrow>\\<^sub>e (lc2!(Suc j))\"\n                 \n                 then have suc_len:\"Suc (i + j)<length l\" using j_len length_lc2\n                   by fastforce\n                 also then have \"\\<Gamma>\\<turnstile>\\<^sub>c(l!(i+j))  \\<rightarrow>\\<^sub>e (l! (Suc (i+ j)))\"\n                    using lc2_l j_step j_len by fastforce\n                 ultimately have \"(snd(lc2!j), snd(lc2!(Suc j))) \\<in> R\"\n                    using assum suc_len lc2_l j_len cp by fastforce \n               }\n               then show ?thesis using left \n                 unfolding assum_def by fastforce\n             qed\n             also have \"(\\<Gamma>,lc2) \\<in> cpn n \\<Gamma> c2 s2\"\n               using cp_lc1 i_map l_is last_conv_nth lc1_not_empty by fastforce\n             ultimately have comm_lc2:\"(\\<Gamma>,lc2) \\<in>  comm (G, (q,a)) F\"\n               using a3 unfolding com_validityn_def by auto\n             have lc2_last_f:\"snd (last lc2)\\<notin> Fault ` F\" \n               using lc2_l lc2_not_empty l_f cp_lc1 by fastforce             \n             then have \"((fst (last lc2) = Skip \\<and> \n                    snd (last lc2) \\<in> Normal ` q)) \\<or>\n                    (fst (last lc2) = Throw \\<and> \n                    snd (last lc2) \\<in> Normal ` (a))\" \n             using final_lc2 comm_lc2 unfolding comm_def by auto\n             then have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a))\" \n             using eq_last_lc2_l by auto\n          }\n          then have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a))\" \n            using left using last_lc1 by auto\n        } thus ?thesis by auto qed         \n     thus ?thesis using left l_f \\<Gamma>1 unfolding comm_def by force       \n       qed             \n     } thus ?thesis using \\<Gamma>1 unfolding comm_def by auto qed\n   } thus ?thesis by auto qed \n } thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def) \nqed\n\n\n\nlemma DynCom_sound: \n      \"(\\<forall>s \\<in> p. ((\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (c1 s) sat [p, R, G, q,a]) \\<and> \n                 (\\<forall>n. (\\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> (c1 s) sat [p,R, G, q,a])))) \\<Longrightarrow>\n        (\\<forall>s. (Normal s, Normal s) \\<in> G) \\<Longrightarrow>\n       (Sta p R) \\<and> (Sta q R) \\<and> (Sta a R) \\<Longrightarrow>        \n        \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> (DynCom c1) sat [p,  R, G, q,a]\"\nproof -  \n  assume\n    a0:\"(\\<forall>s \\<in> p. ((\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (c1 s) sat [p, R, G, q,a]) \\<and> \n                 (\\<forall>n. (\\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> (c1 s) sat [p, R, G, q,a]))))\" and    \n    a1:\"\\<forall>s. (Normal s, Normal s) \\<in> G\" and  \n    a2: \"(Sta p R) \\<and> (Sta q R) \\<and> (Sta a R)\"               \n  { \n    fix s\n    assume all_DynCom:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"     \n    then have a0:\"(\\<forall>s \\<in> p. (\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> (c1 s) sat [p, R, G, q,a]))\"\n      using a0 unfolding com_cvalidityn_def by fastforce     \n    have \"cpn n \\<Gamma>(DynCom c1) s \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cpn n \\<Gamma> (DynCom c1) s\" and a11:\"c \\<in> assum(p, R)\"\n      then have a10':\"c \\<in> cp \\<Gamma> (DynCom c1) s\"\n        unfolding cp_def cpn_def\n        using cptn_eq_cptn_mod_set cptn_mod_nest_cptn_mod by fastforce\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have \"c \\<in> comm(G, (q,a)) F\"      \n      proof - \n      {assume l_f:\"snd (last l) \\<notin> Fault ` F\"       \n        have cp:\"l!0=(DynCom c1,s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\" \n          using a10' cp_def c_prod by fastforce\n        have \\<Gamma>1:\"(\\<Gamma>, l) = c\" using c_prod cp by blast\n        have assum:\"snd(l!0) \\<in> Normal ` (p) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n                   (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n       using a11 c_prod unfolding assum_def by simp\n       then have env_tran:\"env_tran \\<Gamma> p l R\" using env_tran_def cp by blast\n       then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n         using env_tran env_tran_right_def unfolding env_tran_def by auto\n       obtain ns where s_normal:\"s=Normal ns \\<and> ns\\<in> p\" \n         using cp assum by fastforce       \n       have concl:\"(\\<forall>i. Suc i<length l \\<longrightarrow> \n               \\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>             \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n       proof -\n       { fix k ns ns'\n         assume a00:\"Suc k<length l\" and\n                a21:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"                                     \n         obtain j where before_k_all_evnt:\"j\\<le>k \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n           using a00 a21 exist_first_comp_tran cp by blast\n         then obtain cj sj csj ssj where pair_j:\"(\\<Gamma>\\<turnstile>\\<^sub>c(cj,sj)  \\<rightarrow> (csj,ssj)) \\<and> cj = fst (l!j) \\<and> sj = snd (l!j) \\<and> csj = fst (l!(Suc j)) \\<and> ssj = snd(l!(Suc j))\"\n           by fastforce                                             \n         have k_basic:\"cj = (DynCom c1) \\<and> sj \\<in> Normal ` (p)\" \n           using  pair_j before_k_all_evnt a2 cp env_tran_right  assum a00 stability[of p R l 0 j j \\<Gamma>]\n           by force\n         then obtain s' where ss:\"sj = Normal s' \\<and> s'\\<in> (p)\" by auto \n         then have ssj_normal_s:\"ssj = Normal s'\" \n           using before_k_all_evnt k_basic pair_j a0 \n           by (metis snd_conv stepc_Normal_elim_cases(10))                     \n         have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n           using ss a2 unfolding Satis_def\n         proof (cases \"k=j\")   \n           case True                                  \n           have \"(Normal s', Normal s')\\<in>G\" using a1 by fastforce\n           thus \"(snd (l ! k), snd (l ! Suc k)) \\<in>  G\"\n             using pair_j k_basic True ss ssj_normal_s by auto\n         next\n           case False   \n           have j_k:\"j<k\" using  before_k_all_evnt False by fastforce                      \n           thus \"(snd (l ! k), snd (l ! Suc k)) \\<in> G\"\n           proof -\n             have j_length:\"Suc j < length l\" using a00 before_k_all_evnt by fastforce\n             have p1:\"s'\\<in>p \\<and> ssj=Normal s'\" using ss ssj_normal_s by fastforce\n             then have c1_valid:\"(\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> (c1 s') sat [p, R, G, q,a])\"\n               using a0 by fastforce\n             have cj:\"csj= (c1 s')\" using k_basic pair_j ss a0 s_normal\n             proof -\n               have \"\\<Gamma>\\<turnstile>\\<^sub>c (LanguageCon.com.DynCom c1, Normal s') \\<rightarrow> (csj, ssj)\"\n                 using k_basic pair_j ss by force\n               then have \"(csj, ssj) = (c1 s', Normal s')\"\n                 by (meson stepc_Normal_elim_cases(10))\n               then show ?thesis\n                 by blast\n             qed                                                       \n             moreover then have \"cpn n \\<Gamma> csj ssj \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F\"\n               using a2 com_validityn_def cj p1 c1_valid by blast             \n             moreover then have \"l!(Suc j) = (csj, Normal s')\" \n               using before_k_all_evnt pair_j cj ssj_normal_s\n               by fastforce\n             ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n               using  p1 j_length  a11 \\<Gamma>1  ssj_normal_s                     \n               using a10 cpn_assum_induct by fastforce                                        \n             then show ?thesis \n             using a00 a21  a10' \\<Gamma>1  j_k j_length l_f\n             cptn_comm_induct[of \\<Gamma> l \"DynCom c1\" s _ \"Suc j\" G q a F k ]\n             unfolding Satis_def by fastforce                         \n          qed            \n       qed \n       } thus ?thesis by (simp add: c_prod cp) qed\n       have concr:\"(final (last l)  \\<longrightarrow>                   \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a)))\"\n       proof-\n       { \n         assume valid:\"final (last l)\"                       \n         have \"\\<exists>k. k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final (l!(Suc k))\"\n         proof -             \n           have len_l:\"length l > 0\" using cp using cptn.simps by blast \n           then obtain a1 l1 where l:\"l=a1#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n           have last_l:\"last l = l!(length l-1)\"\n            using last_length [of a1 l1] l by fastforce         \n           have final_0:\"\\<not>final(l!0)\" using cp unfolding final_def by auto\n           have \"0\\<le> (length l-1)\" using len_l last_l by auto\n           moreover have \"(length l-1) < length l\" using len_l by auto\n           moreover have \"final (l!(length l-1))\" using valid last_l by auto\n           moreover have \"fst (l!0) = DynCom c1\" using cp by auto\n           ultimately show ?thesis \n             using a2 cp final_exist_component_tran_final env_tran_right final_0 \n             by blast \n          qed\n          then obtain k where a21: \"k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final (l!(Suc k))\"\n            by auto\n          then have a00:\"Suc k<length l\" by fastforce\n          then obtain j where before_k_all_evnt:\"j\\<le>k \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n            using a00 a21 exist_first_comp_tran cp by blast\n          then obtain cj sj csj ssj where pair_j:\"(\\<Gamma>\\<turnstile>\\<^sub>c(cj,sj)  \\<rightarrow> (csj,ssj)) \\<and> cj = fst (l!j) \\<and> sj = snd (l!j) \\<and> csj = fst (l!(Suc j)) \\<and> ssj = snd(l!(Suc j))\"\n            by fastforce         \n          have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a))\"\n          proof -\n            have j_length:\"Suc j < length l\" using a00 before_k_all_evnt by fastforce                                 \n            then have k_basic:\"cj = (DynCom c1) \\<and> sj \\<in> Normal ` (p)\" \n              using a2 pair_j before_k_all_evnt cp env_tran_right assum stability[of p R l 0 j j \\<Gamma>]\n              by force\n            then obtain s' where ss:\"sj = Normal s' \\<and> s'\\<in> (p)\" by auto \n            then have ssj_normal_s:\"ssj = Normal s'\" \n              using before_k_all_evnt k_basic pair_j a0 \n              by (metis snd_conv stepc_Normal_elim_cases(10))\n            have cj:\"csj=c1 s'\" using k_basic pair_j ss a0\n              by (metis fst_conv stepc_Normal_elim_cases(10))                \n            moreover have p1:\"s'\\<in>p\" using ss by blast \n            moreover then have \"cpn n \\<Gamma> csj ssj \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F\"\n              using a0 com_validityn_def cj by blast\n            moreover then have \"l!(Suc j) = (csj, Normal s')\" \n              using before_k_all_evnt pair_j cj ssj_normal_s\n              by fastforce\n            ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n              using  j_length a10 a11 \\<Gamma>1  ssj_normal_s              \n              by (meson contra_subsetD cpn_assum_induct)               \n            thus ?thesis       \n              using j_length l_f drop_comm a10' \\<Gamma>1 cptn_comm_induct[of \\<Gamma> l \"DynCom c1\" s _ \"Suc j\" G q a F \"Suc j\"] valid  \n              by blast\n           qed\n         } thus ?thesis by auto \n         qed\n       note res = conjI [OF concl concr]}               \n       thus ?thesis using  c_prod unfolding comm_def by force qed      \n    } thus ?thesis by auto qed \n  } thus ?thesis by (auto simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def) \nqed\n\nlemma Guard_sound:\n  \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> g, R, G, q,a] \\<Longrightarrow>\n   (\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> g, R, G, q,a]) \\<Longrightarrow>   \n   Sta (p \\<inter> g) R \\<Longrightarrow> (\\<forall>s. (Normal s, Normal s) \\<in> G) \\<Longrightarrow>\n    \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Guard f g c1) sat [p \\<inter> g, R, G, q,a]\"\nproof -  \n  assume\n    a0:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [(p \\<inter> g) , R, G, q,a]\" and\n    a1:\"(\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> g, R, G, q,a])\" and        \n    a2: \"Sta (p \\<inter> g) R\" and\n    a3: \"\\<forall>s. (Normal s, Normal s) \\<in> G\"\n  { \n    fix s\n    assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"  \n    then have a1:\"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> g, R, G, q,a]\" \n      using a1 com_cvalidityn_def by fastforce\n    have \"cpn n \\<Gamma> (Guard f g c1)  s \\<inter> assum(p \\<inter> g, R) \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cpn n \\<Gamma> (Guard f g c1) s\" and a11:\"c \\<in> assum(p \\<inter> g, R)\"\n      then have a10':\"c \\<in> cp \\<Gamma> (Guard f g c1) s\" \n        unfolding cpn_def cp_def using cptn_eq_cptn_mod_set cptn_mod_nest_cptn_mod by fastforce\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have \"c \\<in> comm(G, (q,a)) F\"      \n      proof - \n      {assume l_f:\"snd (last l) \\<notin> Fault ` F\"       \n        have cp:\"l!0=((Guard f g c1),s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\" using a10' cp_def c_prod by fastforce\n        have \\<Gamma>1:\"(\\<Gamma>, l) = c\" using c_prod cp by blast\n        have assum:\"snd(l!0) \\<in> Normal ` (p \\<inter> g) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n                   (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n       using a11 c_prod unfolding assum_def by simp\n       then have env_tran:\"env_tran \\<Gamma> (p \\<inter> g) l R\" using env_tran_def cp by blast\n       then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n         using env_tran env_tran_right_def unfolding env_tran_def by auto\n       have concl:\"(\\<forall>i. Suc i<length l \\<longrightarrow> \n               \\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                                            \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n       proof -\n       { fix k ns ns'\n         assume a00:\"Suc k<length l\" and\n                a21:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"                                                        \n         obtain j where before_k_all_evnt:\"j\\<le>k \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n           using a00 a21 exist_first_comp_tran cp by blast\n         then obtain cj sj csj ssj where pair_j:\"(\\<Gamma>\\<turnstile>\\<^sub>c(cj,sj)  \\<rightarrow> (csj,ssj)) \\<and> cj = fst (l!j) \\<and> sj = snd (l!j) \\<and> csj = fst (l!(Suc j)) \\<and> ssj = snd(l!(Suc j))\"\n           by fastforce                                             \n         have k_basic:\"cj =(Guard f g c1) \\<and> sj \\<in> Normal ` (p \\<inter> g)\" \n           using  pair_j before_k_all_evnt cp env_tran_right a2 assum a00 stability[of \"p \\<inter> g\" R l 0 j j \\<Gamma>]\n           by force\n         then obtain s' where ss:\"sj = Normal s' \\<and> s'\\<in> (p \\<inter> g)\" by auto \n         then have ssj_normal_s:\"ssj = Normal s'\" \n           using before_k_all_evnt k_basic pair_j a0 stepc_Normal_elim_cases(2)\n           by (metis (no_types, lifting)  IntD2 prod.inject)                                \n         have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n           using ss a2 unfolding Satis_def\n         proof (cases \"k=j\")   \n           case True                                  \n           have \" (Normal s', Normal s')\\<in>G\" using a3 by auto \n           thus \"(snd (l ! k), snd (l ! Suc k)) \\<in>  G\"\n             using pair_j k_basic True ss ssj_normal_s by auto\n         next\n           case False   \n           have j_k:\"j<k\" using  before_k_all_evnt False by fastforce                      \n           thus \"(snd (l ! k), snd (l ! Suc k)) \\<in>  G\"\n           proof -\n             have j_length:\"Suc j < length l\" using a00 before_k_all_evnt by fastforce\n             have cj:\"csj=c1\" using k_basic pair_j ss a0\n               by (metis (no_types, lifting) IntD2 fst_conv stepc_Normal_elim_cases(2))                             \n             moreover have p1:\"s' \\<in> (p \\<inter> g)\" using ss by blast \n             moreover then have \"cpn n \\<Gamma> csj ssj \\<inter> assum(p \\<inter> g, R) \\<subseteq> comm(G, (q,a)) F\"\n               using a1 com_validityn_def cj by blast\n             moreover then have \"l!(Suc j) = (csj, Normal s')\" \n               using before_k_all_evnt pair_j cj ssj_normal_s\n               by fastforce\n             ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n               using  j_length a10 a11 \\<Gamma>1  ssj_normal_s\n                     cpn_assum_induct\n               by fastforce                         \n             then show ?thesis \n             using a00 a21  a10' \\<Gamma>1  j_k j_length l_f\n             cptn_comm_induct[of \\<Gamma> l \"(Guard f g c1)\" s _ \"Suc j\" G q a F k ]\n             unfolding Satis_def by fastforce                         \n          qed            \n       qed \n       } thus ?thesis by (simp add: c_prod cp) qed\n       have concr:\"(final (last l)  \\<longrightarrow>                   \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a)))\"\n       proof-\n       { \n         assume valid:\"final (last l)\"                       \n         have \"\\<exists>k. k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final (l!(Suc k))\"\n         proof -             \n           have len_l:\"length l > 0\" using cp using cptn.simps by blast \n           then obtain a1 l1 where l:\"l=a1#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n           have last_l:\"last l = l!(length l-1)\"\n            using last_length [of a1 l1] l by fastforce         \n           have final_0:\"\\<not>final(l!0)\" using cp unfolding final_def by auto\n           have \"0\\<le> (length l-1)\" using len_l last_l by auto\n           moreover have \"(length l-1) < length l\" using len_l by auto\n           moreover have \"final (l!(length l-1))\" using valid last_l by auto\n           moreover have \"fst (l!0) = (Guard f g c1)\" using cp by auto\n           ultimately show ?thesis \n             using  cp final_exist_component_tran_final env_tran_right final_0 \n             by blast \n          qed\n          then obtain k where a21: \"k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final (l!(Suc k))\"\n            by auto\n          then have a00:\"Suc k<length l\" by fastforce\n          then obtain j where before_k_all_evnt:\"j\\<le>k \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n            using a00 a21 exist_first_comp_tran cp by blast\n          then obtain cj sj csj ssj where pair_j:\"(\\<Gamma>\\<turnstile>\\<^sub>c(cj,sj)  \\<rightarrow> (csj,ssj)) \\<and> cj = fst (l!j) \\<and> sj = snd (l!j) \\<and> csj = fst (l!(Suc j)) \\<and> ssj = snd(l!(Suc j))\"\n            by fastforce         \n          have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a))\"\n          proof -\n            have j_length:\"Suc j < length l\" using a00 before_k_all_evnt by fastforce                                 \n            then have k_basic:\"cj = (Guard f g c1) \\<and> sj \\<in> Normal ` (p \\<inter> g)\" \n              using  pair_j before_k_all_evnt cp env_tran_right a2 assum a00 stability[of \"p \\<inter> g\" R l 0 j j \\<Gamma>]\n              by force\n            then obtain s' where ss:\"sj = Normal s' \\<and> s'\\<in> (p \\<inter> g)\" by auto \n            then have ssj_normal_s:\"ssj = Normal s'\" \n              using before_k_all_evnt k_basic pair_j a1\n              by (metis (no_types, lifting) IntD2 Pair_inject stepc_Normal_elim_cases(2))               \n            have cj:\"csj=c1\" using k_basic pair_j ss a0\n              by (metis (no_types, lifting) fst_conv IntD2 stepc_Normal_elim_cases(2))                              \n            moreover have p1:\"s' \\<in> (p \\<inter> g)\" using ss by blast \n            moreover then have \"cpn n \\<Gamma> csj ssj \\<inter> assum((p \\<inter> g), R) \\<subseteq> comm(G, (q,a)) F\"\n              using a1 com_validityn_def cj by blast\n            moreover then have \"l!(Suc j) = (csj, Normal s')\" \n              using before_k_all_evnt pair_j cj ssj_normal_s\n              by fastforce\n            ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n              using  j_length a10 a11 \\<Gamma>1  ssj_normal_s cpn_assum_induct\n              by fastforce    \n            thus ?thesis       \n              using j_length l_f drop_comm a10' \\<Gamma>1 cptn_comm_induct[of \\<Gamma> l \"(Guard f g c1)\" s _ \"Suc j\" G q a F \"Suc j\"] valid  \n              by blast\n           qed\n         } thus ?thesis by auto \n         qed\n       note res = conjI [OF concl concr]}               \n       thus ?thesis using  c_prod unfolding comm_def by force qed      \n    } thus ?thesis by auto qed \n  } thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def) \nqed\n\n\nlemma Guarantee_sound:\n  \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [(p \\<inter> g),  R, G, q,a] \\<Longrightarrow>\n   \\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> g, R, G, q,a] \\<Longrightarrow>  \n   Sta p R \\<Longrightarrow> \n   f\\<in>F \\<Longrightarrow>\n   (\\<forall>s. (Normal s, Normal s) \\<in> G) \\<Longrightarrow> \n   \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Guard f g c1) sat [p, R, G, q,a]\"\nproof -  \n  assume\n    a0:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> g, R, G, q,a]\" and\n    a1:\"\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> g, R, G, q,a]\" and      \n    a2: \"Sta p R\" and\n    a3: \"(\\<forall>s. (Normal s, Normal s) \\<in> G)\" and\n    a4: \"f\\<in>F\"    \n  { \n    fix s\n    assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"  \n    then have a1:\"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> g, R, G, q,a]\" \n      using a1 com_cvalidityn_def by fastforce\n    have \"cpn n \\<Gamma> (Guard f g c1)  s \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {   \n      fix c     \n      assume a10:\"c \\<in> cpn n \\<Gamma> (Guard f g c1) s\" and a11:\"c \\<in> assum(p, R)\"\n      then have a10':\"c \\<in> cp \\<Gamma> (Guard f g c1) s\"\n        unfolding cp_def cpn_def using cptn_eq_cptn_mod_set cptn_mod_nest_cptn_mod by fast\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have \"c \\<in> comm(G, (q,a)) F\"      \n      proof - \n      {assume l_f:\"snd (last l) \\<notin> Fault ` F\"       \n        have cp:\"l!0=((Guard f g c1),s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\" using a10' cp_def c_prod by fastforce\n        have \\<Gamma>1:\"(\\<Gamma>, l) = c\" using c_prod cp by blast\n        have assum:\"snd(l!0) \\<in> Normal ` (p) \\<and> (\\<forall>i. Suc i<length l \\<longrightarrow> \n                 (\\<Gamma>1)\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<longrightarrow>                 \n                   (snd(l!i), snd(l!(Suc i))) \\<in> R)\" \n       using a11 c_prod unfolding assum_def by simp\n       then have env_tran:\"env_tran \\<Gamma> p l R\" using env_tran_def cp by blast\n       then have env_tran_right: \"env_tran_right \\<Gamma> l R\" \n         using env_tran env_tran_right_def unfolding env_tran_def by auto                     \n       have concl:\"(\\<forall>i ns ns'. Suc i<length l \\<longrightarrow> \n               \\<Gamma>1\\<turnstile>\\<^sub>c(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                 \n                 (snd(l!i), snd(l!(Suc i))) \\<in> G)\"\n       proof -\n       { fix k ns ns'\n         assume a00:\"Suc k<length l\" and\n                a21:\"\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))\"                                         \n         obtain j where before_k_all_evnt:\"j\\<le>k \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n           using a00 a21 exist_first_comp_tran cp by blast\n         then obtain cj sj csj ssj where pair_j:\"(\\<Gamma>\\<turnstile>\\<^sub>c(cj,sj)  \\<rightarrow> (csj,ssj)) \\<and> cj = fst (l!j) \\<and> sj = snd (l!j) \\<and> csj = fst (l!(Suc j)) \\<and> ssj = snd(l!(Suc j))\"\n           by fastforce                                                               \n         have k_basic:\"cj =(Guard f g c1) \\<and> sj \\<in> Normal ` (p)\" \n           using  pair_j before_k_all_evnt cp env_tran_right a2 assum a00 stability[of p R l 0 j j \\<Gamma>]\n           by force\n         then obtain s' where ss:\"sj = Normal s' \\<and> s'\\<in> (p)\" by auto          \n         have or:\"s'\\<in> (g \\<union> (-g))\" by fastforce\n         {assume \"s' \\<in> g\"\n          then have k_basic:\"cj =(Guard f g c1) \\<and> sj \\<in> Normal ` (p \\<inter> g)\" \n            using ss k_basic by fastforce\n          then have ss: \"sj = Normal s' \\<and> s'\\<in>  (p \\<inter> g)\"\n            using ss by fastforce\n          have ssj_normal_s:\"ssj = Normal s'\" \n           using ss before_k_all_evnt k_basic pair_j a0 stepc_Normal_elim_cases(2)\n           by (metis (no_types, lifting) IntD2 prod.inject)                                \n          have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n           using ss a2 unfolding Satis_def\n         proof (cases \"k=j\")   \n           case True                                  \n           have \"(Normal s', Normal s') \\<in> G\" using a3 by auto\n           thus \"(snd (l ! k), snd (l ! Suc k)) \\<in>  G\"\n             using pair_j k_basic True ss ssj_normal_s by auto\n         next\n           case False   \n           have j_k:\"j<k\" using  before_k_all_evnt False by fastforce                      \n           thus \"(snd (l ! k), snd (l ! Suc k)) \\<in>  G\"\n           proof -\n             have j_length:\"Suc j < length l\" using a00 before_k_all_evnt by fastforce\n             have cj:\"csj=c1\" using k_basic pair_j ss a0\n               by (metis (no_types, lifting) fst_conv IntD2 stepc_Normal_elim_cases(2))                             \n             moreover have p1:\"s' \\<in> (p \\<inter> g)\" using ss by blast \n             moreover then have \"cpn n \\<Gamma> csj ssj \\<inter> assum((p \\<inter> g), R) \\<subseteq> comm(G, (q,a)) F\"\n               using a1 com_validityn_def cj by blast\n             moreover then have \"l!(Suc j) = (csj, Normal s')\" \n               using before_k_all_evnt pair_j cj ssj_normal_s\n               by fastforce\n             ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n               using  j_length a10 a11 \\<Gamma>1  ssj_normal_s cpn_assum_induct\n               by fastforce                     \n              then show ?thesis \n              using a3 a00 a21  a10' \\<Gamma>1  j_k j_length l_f\n               cptn_comm_induct[of \\<Gamma> l \"(Guard f g c1)\" s _ \"Suc j\" G q a F k]\n              unfolding Satis_def by fastforce                         \n            qed            \n          qed\n         } note p1=this\n         {(* assume \"s' \\<in> (Collect (not (set_fun g)))\"\n          then have \"s'\\<notin>g\" by fastforce *)\n          assume \"s'\\<notin>g\"\n          then have csj_skip:\"csj= Skip \\<and> ssj=Fault f\" using k_basic ss pair_j \n            by (meson Pair_inject stepc_Normal_elim_cases(2))\n          then have \"snd (last l) = Fault f\" using pair_j\n          proof -\n            have \"j = k\" \n            proof -\n              have f1: \"k < length l\"\n                using a00 by linarith\n              have \"\\<not> SmallStepCon.final (l ! k)\"\n                by (metis SmallStepCon.no_step_final' a21)\n              then have \"\\<not> Suc j \\<le> k\"\n                using f1 SmallStepCon.final_def cp csj_skip i_skip_all_skip pair_j by blast\n              then show ?thesis\n                by (metis Suc_leI before_k_all_evnt le_eq_less_or_eq)\n            qed\n            then have False\n              using pair_j csj_skip by (metis a00 a4 cp image_eqI l_f last_not_F)\n            then show ?thesis\n              by metis\n          qed\n          then have False using a4 l_f by auto          \n         }\n         then have \"(snd(l!k), snd(l!(Suc k))) \\<in> G\"\n           using p1 or by fastforce\n       } thus ?thesis by (simp add: c_prod cp) qed\n       have concr:\"(final (last l)  \\<longrightarrow>                   \n                   ((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a)))\"\n       proof-\n       { \n         assume valid:\"final (last l)\"                       \n         have \"\\<exists>k. k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final (l!(Suc k))\"\n         proof -             \n           have len_l:\"length l > 0\" using cp using cptn.simps by blast \n           then obtain a1 l1 where l:\"l=a1#l1\" by (metis SmallStepCon.nth_tl length_greater_0_conv)\n           have last_l:\"last l = l!(length l-1)\"\n            using last_length [of a1 l1] l by fastforce         \n           have final_0:\"\\<not>final(l!0)\" using cp unfolding final_def by auto\n           have \"0\\<le> (length l-1)\" using len_l last_l by auto\n           moreover have \"(length l-1) < length l\" using len_l by auto\n           moreover have \"final (l!(length l-1))\" using valid last_l by auto\n           moreover have \"fst (l!0) = (Guard f g c1)\" using cp by auto\n           ultimately show ?thesis \n             using  cp final_exist_component_tran_final env_tran_right final_0 \n             by blast \n          qed\n          then obtain k where a21: \"k\\<ge>0 \\<and> k<((length l) - 1) \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow> (l!(Suc k))) \\<and> final (l!(Suc k))\"\n            by auto\n          then have a00:\"Suc k<length l\" by fastforce\n          then obtain j where before_k_all_evnt:\"j\\<le>k \\<and>  (\\<Gamma>\\<turnstile>\\<^sub>c(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> (\\<forall>k < j. (\\<Gamma>\\<turnstile>\\<^sub>c(l!k)  \\<rightarrow>\\<^sub>e (l!(Suc k))))\"\n            using a00 a21 exist_first_comp_tran cp by blast\n          then obtain cj sj csj ssj where pair_j:\"(\\<Gamma>\\<turnstile>\\<^sub>c(cj,sj)  \\<rightarrow> (csj,ssj)) \\<and> cj = fst (l!j) \\<and> sj = snd (l!j) \\<and> csj = fst (l!(Suc j)) \\<and> ssj = snd(l!(Suc j))\"\n            by fastforce         \n          have \"((fst (last l) = Skip \\<and> \n                    snd (last l) \\<in> Normal ` q)) \\<or>\n                    (fst (last l) = Throw \\<and> \n                    snd (last l) \\<in> Normal ` (a))\"\n          proof -\n            have j_length:\"Suc j < length l\" using a00 before_k_all_evnt by fastforce                                 \n            have k_basic:\"cj =(Guard f g c1) \\<and> sj \\<in> Normal ` (p)\" \n             using  pair_j before_k_all_evnt cp env_tran_right a2 assum a00 stability[of p R l 0 j j \\<Gamma>]\n             by force\n            then obtain s' where ss:\"sj = Normal s' \\<and> s'\\<in> (p)\" by auto \n            have or:\"s'\\<in> (g \\<union> (-g))\" by fastforce\n            {assume \"s' \\<in> g\"\n             then have k_basic:\"cj =(Guard f g c1) \\<and> sj \\<in> Normal ` (p \\<inter> g)\" \n               using ss k_basic by fastforce\n             then have ss: \"sj = Normal s' \\<and> s'\\<in> (p \\<inter> g)\"\n               using ss by fastforce\n             then have ssj_normal_s:\"ssj = Normal s'\" \n              using before_k_all_evnt k_basic pair_j a1\n              by (metis (no_types, lifting) Pair_inject IntD2 stepc_Normal_elim_cases(2))               \n             have cj:\"csj=c1\" using k_basic pair_j ss a0\n              by (metis (no_types, lifting) fst_conv IntD2 stepc_Normal_elim_cases(2))                              \n             moreover have p1:\"s'\\<in>(p \\<inter> g)\" using ss by blast \n             moreover then have \"cpn n \\<Gamma> csj ssj \\<inter> assum((p \\<inter> g), R)  \\<subseteq> comm(G, (q,a)) F\"\n               using a1 com_validityn_def cj by blast\n             moreover then have \"l!(Suc j) = (csj, Normal s')\" \n               using before_k_all_evnt pair_j cj ssj_normal_s\n               by fastforce\n             ultimately have drop_comm:\"((\\<Gamma>, drop (Suc j) l))\\<in> comm(G, (q,a)) F\"\n               using  j_length a10 a11 \\<Gamma>1  ssj_normal_s cpn_assum_induct\n               by fastforce                 \n            then have ?thesis       \n              using j_length l_f drop_comm a10' \\<Gamma>1 \n                     cptn_comm_induct[of \\<Gamma> l \"(Guard f g c1)\" s _ \"Suc j\" G q a F \"Suc j\"] valid  \n              by blast\n           }note left=this        \n           {\n            (* assume \"s' \\<in> (Collect (not (set_fun g)))\"\n            then have \"s'\\<notin>g\" by fastforce *)\n             assume \"s'\\<notin>g\"\n          then have \"csj= Skip \\<and> ssj=Fault f\" using k_basic ss pair_j \n            by (meson Pair_inject stepc_Normal_elim_cases(2))\n          then have \"snd (last l) = Fault f\" using pair_j\n            by (metis a4 cp imageI j_length l_f last_not_F)            \n          then have False using a4 l_f by auto           \n           }\n           thus ?thesis using or left by auto qed\n         } thus ?thesis by auto \n         qed\n       note res = conjI [OF concl concr]}               \n       thus ?thesis using  c_prod unfolding comm_def by force qed      \n    } thus ?thesis by auto qed \n  } thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def) \nqed\n\nlemma WhileNone:   \n   \"\\<Gamma>\\<turnstile>\\<^sub>c (While b c1, s1) \\<rightarrow> (LanguageCon.com.Skip, t1) \\<Longrightarrow>   \n    (n,\\<Gamma>, (Skip, t1) # xsa) \\<in> cptn_mod_nest_call \\<Longrightarrow>  \n    \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b,R, G, p,a] \\<Longrightarrow>\n    Sta p R \\<Longrightarrow>\n    Sta (p \\<inter> (-b)) R \\<Longrightarrow>\n    Sta a R \\<Longrightarrow>\n    (\\<forall>s. (Normal s, Normal s) \\<in> G) \\<Longrightarrow>            \n    (\\<Gamma>, (While b c1, s1) # (LanguageCon.com.Skip, t1) # xsa) \\<in> assum (p, R) \\<Longrightarrow>    \n    (\\<Gamma>, (While b c1, s1) # (LanguageCon.com.Skip, t1) # xsa) \\<in> comm (G,(p \\<inter> (-b)),a) F\"\nproof -\n  assume a0:\"\\<Gamma>\\<turnstile>\\<^sub>c (While b c1, s1) \\<rightarrow> (LanguageCon.com.Skip, t1)\" and\n         a1:\"(n,\\<Gamma>, (Skip, t1) # xsa) \\<in> cptn_mod_nest_call\" and\n         a2:\" \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b,R, G, p,a]\" and\n         a3:\"Sta p R\" and\n         a4:\"Sta (p \\<inter> (-b)) R\" and\n         a5:\"Sta a R\" and\n         a6:\"\\<forall>s. (Normal s, Normal s) \\<in> G\" and\n         a7:\"(\\<Gamma>, (While b c1, s1) # (LanguageCon.com.Skip, t1) # xsa) \\<in> assum (p, R)\"         \n  obtain s1' where s1N:\"s1=Normal s1' \\<and> s1'\\<in>p\" using a7 unfolding assum_def by fastforce\n  then have s1_t1:\"s1'\\<notin> b \\<and> t1=s1\" using a0\n    using LanguageCon.com.distinct(5) prod.inject \n    by (fastforce elim:stepc_Normal_elim_cases(7))\n  then have t1_Normal_post:\"t1\\<in> Normal ` (p \\<inter> (-b))\"\n    using s1N by fastforce\n  also have \"(\\<Gamma>, (While b c1, s1) # (LanguageCon.com.Skip, t1) # xsa)\\<in>cptn\"\n    using a1 a0 cptn.simps\n    using cptn_eq_cptn_mod_set cptn_mod_nest_cptn_mod by fastforce\n  ultimately have assum_skip:\n    \"(\\<Gamma>,(LanguageCon.com.Skip, t1) # xsa) \\<in> assum (( p \\<inter> (-b)), R)\"\n    using a1 a7 tl_of_assum_in_assum1 t1_Normal_post by fastforce\n  have skip_comm:\"(\\<Gamma>,(LanguageCon.com.Skip, t1) # xsa) \\<in> \n               comm (G,(( p \\<inter> (-b)),a)) F\" \n  proof- \n    obtain \\<Theta> where  \"(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Call c) sat [p , R, G, q,a])\" by auto\n    moreover have \"\\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> Skip sat [( p \\<inter> (-b)), R, G, ( p \\<inter> (-b)),a]\"\n      using Skip_sound[of \"(p \\<inter> - b)\"]  a4 a6   by blast\n    ultimately show ?thesis\n      using assum_skip  a1  unfolding com_cvalidityn_def com_validityn_def cpn_def\n      by fastforce\n  qed    \n  have G_ref:\"(Normal s1', Normal s1')\\<in>G\" using a6 by fastforce\n  thus ?thesis using skip_comm ctran_in_comm[of s1'] s1N s1_t1 by blast\nqed \n\nlemma while1:\n   \"(n,\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> cptn_mod_nest_call \\<Longrightarrow>    \n    s1 \\<in> b \\<Longrightarrow>\n    xsa = map (lift (While b c)) xs1 \\<Longrightarrow>\n    \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c sat [p \\<inter> b,R, G, p,a] \\<Longrightarrow>    \n    (\\<Gamma>, (While b c, Normal s1) #\n        (Seq c (LanguageCon.com.While b c), Normal s1) # xsa)\n       \\<in> assum (p, R)  \\<Longrightarrow>               \n    \\<forall>s. (Normal s, Normal s) \\<in> G \\<Longrightarrow> \n     (\\<Gamma>, (LanguageCon.com.While b c, Normal s1) #\n         (LanguageCon.com.Seq c (LanguageCon.com.While b c), Normal s1) # xsa)\n    \\<in> comm (G, p\\<inter>(-b), a) F\"\nproof -\nassume   \n  a0:\"(n,\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> cptn_mod_nest_call\" and\n  a1:\"s1 \\<in> b\" and\n  a2:\"xsa = map (lift (While b c)) xs1\" and\n  a3:\"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c sat [p \\<inter> b,R, G, p,a]\" and\n  a4:\"(\\<Gamma>, (While b c, Normal s1) #\n        (Seq c (While b c), Normal s1) # xsa)\n       \\<in> assum (p, R) \" and  \n  a5:\"\\<forall>s. (Normal s,Normal s) \\<in> G\" \n  have seq_map:\"(Seq c (While b c), Normal s1) # xsa=\n           map (lift (While b c)) ((c,Normal s1)#xs1)\"\n  using a2 unfolding lift_def by fastforce\n  have step:\"\\<Gamma>\\<turnstile>\\<^sub>c(While b c,Normal s1) \\<rightarrow> (Seq c (While b c),Normal s1)\" using a1\n    WhileTruec by fastforce\n  have s1_normal:\"s1 \\<in> p \\<and> s1 \\<in> b \" using a4 a1 unfolding assum_def by fastforce\n  then have G_ref:\"(Normal s1, Normal s1) \\<in> G\"  using a5 by fastforce \n  have s1_collect_p: \"Normal s1\\<in> Normal ` (p \\<inter> b)\" using s1_normal by fastforce\n  have \"(\\<Gamma>, map (lift (While b c)) ((c,Normal s1)#xs1))\\<in>cptn\" \n    using a2 cptn_eq_cptn_mod_nest lift_is_cptn a0  by blast \n  then have cptn_seq:\"(\\<Gamma>,(Seq c (While b c), Normal s1) # xsa) \\<in>cptn\" \n    using seq_map by auto\n  then have \"(\\<Gamma>, (While b c, Normal s1) # (Seq c (While b c), Normal s1) # xsa) \\<in> cptn\"\n    using step by (simp add: cptn.CptnComp) \n  then have assum_seq:\"(\\<Gamma>,(Seq c (While b c), Normal s1) # xsa)\\<in>assum (p, R)\"\n    using a4 tl_of_assum_in_assum1 s1_collect_p by fastforce\n  have cp_c:\"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> (cpn n \\<Gamma> c (Normal s1))\"\n    using a0 unfolding cpn_def by fastforce\n  then have cp_c':\"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> (cp \\<Gamma> c (Normal s1))\"\n    unfolding cp_def cpn_def using cptn_eq_cptn_mod_nest by fastforce    \n  also have cp_seq:\"(\\<Gamma>, (Seq c (While b c), Normal s1) # xsa) \\<in> (cp \\<Gamma> (Seq c (While b c)) (Normal s1))\"\n    using cptn_seq unfolding cp_def by fastforce\n  ultimately have \"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> assum(p,R)\"  \n    using assum_map assum_seq seq_map by fastforce  \n  then have \"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> assum((p \\<inter> b),R)\"\n    unfolding assum_def using s1_collect_p by fastforce\n  then have \"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> comm(G,(p,a)) F\"\n    using a3 cp_c unfolding com_validityn_def by fastforce\n  then have \"(\\<Gamma>, (Seq c (While b c), Normal s1) # xsa) \\<in> comm(G,(p,a)) F\"\n    using cp_seq cp_c' comm_map seq_map by fastforce\n  then have \"(\\<Gamma>, (While b c, Normal s1) # (Seq c (While b c), Normal s1) # xsa) \\<in> comm(G,(p,a)) F\"\n    using G_ref ctran_in_comm by fastforce\n  also have \"\\<not> final (last ((While b c, Normal s1) # (Seq c (While b c), Normal s1) # xsa))\"\n    using seq_map unfolding final_def lift_def  by (simp add: case_prod_beta' last_map)  \n  ultimately show ?thesis using not_final_in_comm[of \\<Gamma>] by blast\nqed\n\nlemma while2:\n   \" (n,\\<Gamma>, (While b c, Normal s1) #\n         (Seq c (While b c), Normal s1) # xsa) \\<in>cptn_mod_nest_call \\<Longrightarrow>\n    (n, \\<Gamma>, (c, Normal s1) # xs1) \\<in> cptn_mod_nest_call \\<Longrightarrow>\n    fst (last ((c, Normal s1) # xs1)) = LanguageCon.com.Skip \\<Longrightarrow>\n    s1 \\<in> b \\<Longrightarrow>\n    xsa = map (lift (While b c)) xs1 @\n    (While b c, snd (last ((c, Normal s1) # xs1))) # ys \\<Longrightarrow>\n    (n, \\<Gamma>, (While b c, snd (last ((c, Normal s1) # xs1))) # ys)\n      \\<in> cptn_mod_nest_call \\<Longrightarrow>\n     (\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c sat [p \\<inter> b, R, G, p,a] \\<Longrightarrow>    \n       (\\<Gamma>, (While b c, snd (last ((c, Normal s1) # xs1))) # ys)\n         \\<in> assum (p, R) \\<Longrightarrow>\n       (\\<Gamma>, (While b c, snd (last ((c, Normal s1) # xs1))) # ys)\n          \\<in> comm (G, p \\<inter> (-b), a) F) \\<Longrightarrow>\n    \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c sat [ p \\<inter> b, R, G, p,a] \\<Longrightarrow>\n    (\\<Gamma>, (While b c, Normal s1) #\n      (Seq c (While b c), Normal s1) # xsa)\n      \\<in> assum (p, R)  \\<Longrightarrow>\n     \\<forall>s. (Normal s,Normal s) \\<in> G  \\<Longrightarrow>     \n    (\\<Gamma>, (While b c, Normal s1) #\n         (Seq c (While b c), Normal s1) # xsa)\n      \\<in> comm (G,( p \\<inter> (-b), a)) F\"\nproof -\nassume a00:\"(n, \\<Gamma>, (While b c, Normal s1) #\n         (Seq c (While b c), Normal s1) # xsa) \\<in>cptn_mod_nest_call\" and\n       a0:\"(n,\\<Gamma>, (c, Normal s1) # xs1) \\<in> cptn_mod_nest_call\" and\n       a1:\" fst (last ((c, Normal s1) # xs1)) = LanguageCon.com.Skip\" and\n       a2:\"s1 \\<in> b\" and\n       a3:\"xsa = map (lift (While b c)) xs1 @\n            (While b c, snd (last ((c, Normal s1) # xs1))) # ys\" and\n       a4:\"(n,\\<Gamma>, (While b c, snd (last ((c, Normal s1) # xs1))) # ys)\n            \\<in> cptn_mod_nest_call\" and\n       a5:\"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c sat [p \\<inter> b, R, G, p,a]\" and       \n       a6:\"(\\<Gamma>, (While b c, Normal s1) #\n               (Seq c (While b c), Normal s1) # xsa)\n             \\<in> assum (p, R)\" and\n       a7:\"(\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c sat [p \\<inter> b, R, G, p,a] \\<Longrightarrow>    \n           (\\<Gamma>, (While b c, snd (last ((c, Normal s1) # xs1))) # ys)\n             \\<in> assum (p, R) \\<Longrightarrow>\n           (\\<Gamma>, (While b c, snd (last ((c, Normal s1) # xs1))) # ys)\n             \\<in> comm (G,p \\<inter> (-b), a) F)\" and\n       a8:\"\\<forall>s. (Normal s, Normal s) \\<in> G\" \n  let ?l= \"(While b c, Normal s1) #\n           (Seq c (While b c), Normal s1) # xsa\"\n  let ?sub_l=\"((While b c, Normal s1) # \n                 (Seq c (While b c), Normal s1) # \n                 map (lift (While b c)) xs1)\"\n  {\n  assume final_not_fault:\"snd (last ?l) \\<notin> Fault ` F\"\n  have a0':\"(\\<Gamma>, (c, Normal s1) # xs1) \\<in> cptn\"\n    using cptn_eq_cptn_mod_nest using a0 by auto\n  have a4:\"(\\<Gamma>, (While b c, snd (last ((c, Normal s1) # xs1))) # ys) \\<in> cptn\" \n    using cptn_eq_cptn_mod_nest using a4 by blast\n  have seq_map:\"(Seq c (While b c), Normal s1) # map (lift (While b c)) xs1=\n           map (lift (While b c)) ((c,Normal s1)#xs1)\"\n  using a2 unfolding lift_def by fastforce\n  have step:\"\\<Gamma>\\<turnstile>\\<^sub>c(While b c,Normal s1) \\<rightarrow> (Seq c (While b c),Normal s1)\" using a2\n    WhileTruec by fastforce\n  have s1_normal:\"s1\\<in>p \\<and> s1 \\<in> b \" using a6 a2 unfolding assum_def by fastforce\n  have G_ref:\"(Normal s1, Normal s1)\\<in>G \" \n    using a8 by blast\n  have s1_collect_p: \"Normal s1\\<in> Normal ` (p \\<inter> b)\" using s1_normal by fastforce\n  have \"(\\<Gamma>, map (lift (While b c)) ((c,Normal s1)#xs1))\\<in>cptn\" \n    using a2 cptn_eq_cptn_mod lift_is_cptn a0' by fastforce\n  then have cptn_seq:\"(\\<Gamma>,(Seq c (While b c), Normal s1) # map (lift (While b c)) xs1) \\<in>cptn\" \n    using seq_map by auto\n  then have \"(\\<Gamma>, (While b c, Normal s1) # \n                 (Seq c (While b c), Normal s1) # \n                  map (lift (While b c)) xs1) \\<in> cptn\"\n    using step by (simp add: cptn.CptnComp) \n  also have \"(\\<Gamma>, (While b c, Normal s1) #\n                 (Seq c (While b c), Normal s1) #\n                  map (lift (While b c)) xs1)\n          \\<in> assum (p, R)\"\n    using a6 a3 sub_assum by force \n  ultimately have assum_seq:\"(\\<Gamma>,(Seq c (While b c), Normal s1)  # \n                       map (lift (While b c)) xs1) \\<in> assum (p, R)\"\n    using a6 tl_of_assum_in_assum1 s1_collect_p \n          tl_of_assum_in_assum   by fastforce\n  have cpn_c:\"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> (cpn n \\<Gamma> c (Normal s1))\"\n    using a0 unfolding cpn_def by fastforce\n  have cp_c:\"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> (cp \\<Gamma> c (Normal s1))\"\n    using a0' unfolding cp_def by fastforce  \n  also have cp_seq:\"(\\<Gamma>, (Seq c (While b c), Normal s1) # map (lift (While b c)) xs1) \\<in> (cp \\<Gamma> (Seq c (While b c)) (Normal s1))\"\n    using cptn_seq unfolding cp_def by fastforce\n  ultimately have \"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> assum(p,R) \"  \n    using assum_map assum_seq seq_map  by fastforce  \n  then have \"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> assum((p \\<inter> b),R) \"\n    unfolding assum_def using s1_collect_p by fastforce\n  then have c_comm:\"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> comm(G,(p,a)) F\"\n    using a5 cpn_c unfolding com_validityn_def by fastforce\n  then have \"(\\<Gamma>, (Seq c (While b c), Normal s1) # map (lift (While b c)) xs1) \\<in> comm(G,(p,a)) F\"\n    using cp_seq cp_c comm_map seq_map by fastforce\n  then have comm_while:\"(\\<Gamma>, (While b c, Normal s1) # \n                            (Seq c (While b c), Normal s1) # \n                            map (lift (While b c)) xs1) \\<in> comm(G,(p,a)) F\"\n    using G_ref ctran_in_comm by fastforce\n  have final_last_c:\"final (last ((c,Normal s1)#xs1))\"\n    using a1 a3 unfolding final_def by fastforce\n  have last_while1:\"snd (last (map (lift (While b c)) ((c,Normal s1)#xs1))) = snd (last ((c, Normal s1) # xs1))\"\n    unfolding lift_def by (simp add: case_prod_beta' last_map)\n  have last_while2:\"(last (map (lift (While b c)) ((c,Normal s1)#xs1))) =\n           last ((While b c, Normal s1) # (Seq c (While b c), Normal s1) # map (lift (While b c)) xs1)\"\n    using seq_map by fastforce\n  have not_fault_final_last_c:\n    \"snd (last ( (c,Normal s1)#xs1)) \\<notin> Fault ` F\"\n  proof -    \n    have \"(length ?sub_l) - 1 < length ?l\" \n      using a3 by fastforce\n    then have \"snd (?l!((length ?sub_l) - 1))\\<notin> Fault ` F\"\n      using final_not_fault a3 a00 last_not_F[of \\<Gamma> ?l F]\n           cptn_eq_cptn_mod_set cptn_mod_nest_cptn_mod by blast  \n    thus ?thesis using last_while2 last_while1 seq_map\n      by (metis (no_types) Cons_lift_append  a3 diff_Suc_1 last_length length_Cons lessI nth_Cons_Suc nth_append)\n  qed\n  then have last_c_normal:\"snd (last ( (c,Normal s1)#xs1)) \\<in> Normal ` (p)\"\n    using c_comm a1 unfolding comm_def final_def by fastforce    \n  then obtain sl where sl:\"snd (last ( (c,Normal s1)#xs1)) = Normal sl\" by fastforce\n  have while_comm:\"(\\<Gamma>, (While b c, snd (last ((c, Normal s1) # xs1))) # ys) \\<in> comm(G,(p\\<inter>(-b),a)) F\"\n  proof -\n    have assum_while: \"(\\<Gamma>, (While b c, snd (last ((c, Normal s1) # xs1))) # ys)\n             \\<in> assum (p, R)\"\n      using last_c_normal a3 a6 sub_assum_r[of \\<Gamma> ?sub_l \"(While b c, snd (last ((c, Normal s1) # xs1)))\"  ys p R p] \n      by fastforce\n    thus ?thesis using a5 a7 by fastforce\n  qed      \n  have \"sl\\<in>p\" using last_c_normal sl by fastforce\n  then have G1_ref:\"(Normal sl, Normal sl)\\<in>G\" using a8 by auto\n  also have \"snd (last ?sub_l) = Normal sl\"\n    using last_while1 last_while2 sl by fastforce\n  ultimately have ?thesis \n    using  cptn_eq_cptn_mod_nest a00 a3 sl while_comm comm_union[OF comm_while]  \n    by fastforce    \n  } note p1 =this\n  {\n    assume final_not_fault:\"\\<not> (snd (last ?l) \\<notin> Fault ` F)\"\n    then have ?thesis unfolding comm_def by fastforce\n  } thus ?thesis using p1 by fastforce\nqed\n\nlemma while3:\n   \"(n, \\<Gamma>, (c, Normal s1) # xs1) \\<in> cptn_mod_nest_call \\<Longrightarrow>    \n    fst (last ((c, Normal s1) # xs1)) = Throw \\<Longrightarrow>\n    s1 \\<in> b \\<Longrightarrow>\n    snd (last ((c, Normal s1) # xs1)) = Normal sl \\<Longrightarrow>\n    (n,\\<Gamma>, (Throw, Normal sl) # ys) \\<in> cptn_mod_nest_call   \\<Longrightarrow>\n    \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c sat [p \\<inter> b,R, G, p,a] \\<Longrightarrow>    \n    (\\<Gamma>, (While b c, Normal s1) #\n         (Seq c (While b c), Normal s1) #  \n         (map (lift (While b c)) xs1 @\n           (Throw, Normal sl) # ys))\n       \\<in> assum (p, R)  \\<Longrightarrow>        \n     Sta p R \\<Longrightarrow>\n     Sta a R \\<Longrightarrow> \\<forall>s. (Normal s, Normal s) \\<in> G \\<Longrightarrow> \n    (\\<Gamma>, (While b c, Normal s1) #\n         (Seq c (While b c), Normal s1) #          \n         ((map (lift (While b c)) xs1 @\n           (Throw, Normal sl) # ys))) \\<in> comm (G, p\\<inter> (-b), a) F\n\"\nproof -\nassume a0:\"(n,\\<Gamma>, (c, Normal s1) # xs1) \\<in> cptn_mod_nest_call\" and\n       a1:\"fst (last ((c, Normal s1) # xs1)) = Throw\" and\n       a2:\"s1 \\<in> b\" and\n       a3:\"snd (last ((c, Normal s1) # xs1)) = Normal sl\" and\n       a4:\"(n,\\<Gamma>, (Throw, Normal sl) # ys) \\<in> cptn_mod_nest_call\" and\n       a5:\"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c sat [p \\<inter> b, R, G, p,a]\" and\n       a6:\"(\\<Gamma>, (While b c, Normal s1) #\n           (Seq c (While b c), Normal s1) #  \n           (map (lift (While b c)) xs1 @\n             (Throw, Normal sl) # ys))\n           \\<in> assum (p, R)\" and      \n       a7: \"Sta p R\" and\n       a8: \"Sta a R\" and       \n       a10:\"\\<forall>s. (Normal s,Normal s) \\<in> G\"  \n  have seq_map:\"(Seq c (While b c), Normal s1) # map (lift (While b c)) xs1=\n           map (lift (While b c)) ((c,Normal s1)#xs1)\"\n  using a2 unfolding lift_def by fastforce\n  have step:\"\\<Gamma>\\<turnstile>\\<^sub>c(While b c,Normal s1) \\<rightarrow> (Seq c (While b c),Normal s1)\" using a2\n    WhileTruec by fastforce\n  have s1_normal:\"s1\\<in>p \\<and> s1 \\<in> b \" using a6 a2 unfolding assum_def by fastforce\n  then have G_ref:\"(Normal s1, Normal s1)\\<in>G\" using a10 by auto\n  have s1_collect_p: \"Normal s1\\<in> Normal ` (p \\<inter> b)\" using s1_normal by fastforce\n  have \"(n, \\<Gamma>, map (lift (While b c)) ((c,Normal s1)#xs1))\\<in>cptn_mod_nest_call\" \n    using a2  lift_is_cptn a0\n    by (metis cptn_mod_nest_call.CptnModNestSeq1 seq_map) \n  then have cptn_seq:\"(n,\\<Gamma>,(Seq c (While b c), Normal s1) # map (lift (While b c)) xs1) \\<in>cptn_mod_nest_call\" \n    using seq_map by auto\n  then have cptn:\"(n,\\<Gamma>, (While b c, Normal s1) # \n                 (Seq c (While b c), Normal s1) # \n                  map (lift (While b c)) xs1) \\<in> cptn_mod_nest_call\"\n     by (meson a0 a2 cptn_mod_nest_call.CptnModNestWhile1) \n  also have \"(\\<Gamma>, (LanguageCon.com.While b c, Normal s1) #\n         (LanguageCon.com.Seq c (LanguageCon.com.While b c), Normal s1) #\n         map (lift (LanguageCon.com.While b c)) xs1)\n          \\<in> assum (p, R) \"\n    using a6 sub_assum by force \n  ultimately have assum_seq:\"(\\<Gamma>,(Seq c (While b c), Normal s1)  # \n                       map (lift (While b c)) xs1) \\<in> assum (p, R)\"\n    using a6 tl_of_assum_in_assum1 s1_collect_p \n          tl_of_assum_in_assum cptn_eq_cptn_mod_nest  by fast\n  have cpn_c:\"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> (cpn n \\<Gamma> c (Normal s1))\"\n    using a0 unfolding cpn_def by fastforce\n  then have cp_c:\"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> (cp \\<Gamma> c (Normal s1))\"\n    unfolding cp_def cpn_def using cptn_eq_cptn_mod_nest by auto\n  moreover have cp_seq:\"(\\<Gamma>, (Seq c (While b c), Normal s1) # map (lift (While b c)) xs1) \\<in> (cpn n \\<Gamma> (Seq c (While b c)) (Normal s1))\"\n    using cptn_seq unfolding cpn_def by fastforce\n  then have cp_seq':\"(\\<Gamma>, (Seq c (While b c), Normal s1) # map (lift (While b c)) xs1) \\<in> (cp \\<Gamma> (Seq c (While b c)) (Normal s1))\"\n    unfolding cp_def cpn_def using cptn_eq_cptn_mod_nest by auto\n  ultimately have \"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> assum(p,R)\"  \n    using assum_map assum_seq seq_map  by fastforce\n  then have \"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> assum((p \\<inter> b),R)\"\n    unfolding assum_def using s1_collect_p by fastforce\n  then have c_comm:\"(\\<Gamma>, ((c, Normal s1) # xs1)) \\<in> comm(G,(p,a)) F\"\n    using a5 cpn_c unfolding com_validityn_def by fastforce\n  then have \"(\\<Gamma>, (Seq c (While b c), Normal s1) # map (lift (While b c)) xs1) \\<in> comm(G,(p,a)) F\"\n    using cp_seq' cp_c comm_map seq_map by fastforce\n  then have comm_while:\"(\\<Gamma>, (While b c, Normal s1) # (Seq c (While b c), Normal s1) # map (lift (While b c)) xs1) \\<in> comm(G,(p,a)) F\"\n    using G_ref ctran_in_comm by fastforce\n  have final_last_c:\"final (last ((c,Normal s1)#xs1))\"\n    using a1 a3 unfolding final_def by fastforce\n  have not_fault_final_last_c:\n    \"snd (last ( (c,Normal s1)#xs1)) \\<notin> Fault ` F\"\n    using a3 by fastforce\n  then have sl_a:\"Normal sl \\<in> Normal ` (a)\"  \n    using final_last_c a1 c_comm unfolding comm_def\n    using  a3 comm_dest2   \n    by auto\n  have last_while1:\"snd (last (map (lift (While b c)) ((c,Normal s1)#xs1))) = snd (last ((c, Normal s1) # xs1))\"\n    unfolding lift_def by (simp add: case_prod_beta' last_map)\n  have last_while2:\"(last (map (lift (While b c)) ((c,Normal s1)#xs1))) =\n           last ((While b c, Normal s1) # (Seq c (While b c), Normal s1) # map (lift (While b c)) xs1)\"\n    using seq_map by fastforce\n  have throw_comm:\"(\\<Gamma>, (Throw, Normal sl) # ys) \\<in> comm(G,(p\\<inter>(-b),a)) F\"\n  proof -\n    have assum_throw: \"(\\<Gamma>, (Throw, Normal sl) # ys) \\<in> assum (a,R)\"\n      using sl_a a6 sub_assum_r[of _ \"(LanguageCon.com.While b c, Normal s1) #\n         (LanguageCon.com.Seq c (LanguageCon.com.While b c), Normal s1) #\n         map (lift (LanguageCon.com.While b c)) xs1\" \"(Throw, Normal sl)\" ] \n      by fastforce\n    also have \"(\\<Gamma>,(Throw, Normal sl) # ys) \\<in> cpn n \\<Gamma> Throw (Normal sl)\" \n      unfolding cpn_def using a4 by fastforce\n    ultimately show ?thesis using Throw_sound[of a R G \\<Gamma>] a10 a8   \n      unfolding com_cvalidityn_def com_validityn_def by fast\n  qed  \n  have p1:\"(LanguageCon.com.While b c, Normal s1) #\n    (LanguageCon.com.Seq c (LanguageCon.com.While b c), Normal s1) #\n    map (lift (LanguageCon.com.While b c)) xs1 \\<noteq>\n    [] \\<and>\n    (LanguageCon.com.Throw, Normal sl) # ys \\<noteq> []\" by auto  \n  have \"sl \\<in> a\" using sl_a by fastforce\n  then have G1_ref:\"(Normal sl, Normal sl) \\<in> G\" using a10 by auto\n  moreover have \"snd (last ((While b c, Normal s1) # \n                  (Seq c (While b c), Normal s1) # \n                  map (lift (While b c)) xs1)) = Normal sl\"\n    using last_while1 last_while2 a3 by fastforce\n  moreover have \"snd (((LanguageCon.com.Throw, Normal sl) # ys) ! 0) = Normal sl\"\n    by (metis nth_Cons_0 snd_conv)\n  ultimately have G:\"(snd (last ((While b c, Normal s1) # \n                  (Seq c (While b c), Normal s1) # \n                  map (lift (While b c)) xs1)),\n                  snd (((LanguageCon.com.Throw, Normal sl) # ys) ! 0)) \\<in> G\" by auto\n  have cptn:\"(\\<Gamma>, ((LanguageCon.com.While b c, Normal s1) #\n          (LanguageCon.com.Seq c (LanguageCon.com.While b c), Normal s1) #\n          map (lift (LanguageCon.com.While b c)) xs1) @\n         (LanguageCon.com.Throw, Normal sl) # ys)\n    \\<in> cptn\" using cptn a4  a0 a1 a3 a4 cptn_eq_cptn_mod_set cptn_mod.CptnModWhile3 s1_normal \n             cptn_eq_cptn_mod_nest by (metis append_Cons)\n  show ?thesis using a0  comm_union[OF comm_while throw_comm p1 G cptn] by auto       \nqed\n\n\ninductive_cases stepc_elim_cases_while_throw [cases set]:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(While b c, s) \\<rightarrow> (Throw, t)\"\n\n\nlemma WhileSound_aux:\n \"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b, R, G, p,a] \\<Longrightarrow>\n  Sta p R \\<Longrightarrow>\n  Sta  (p \\<inter> (-b)) R \\<Longrightarrow> \n  Sta a R \\<Longrightarrow>    \n  (n, \\<Gamma>,x)\\<in> cptn_mod_nest_call \\<Longrightarrow> \n  \\<forall>s. (Normal s, Normal s) \\<in> G \\<Longrightarrow>\n  \\<forall>s xs. x = ((While b c1),s)#xs \\<longrightarrow> \n     (\\<Gamma>,x)\\<in>assum(p,R) \\<longrightarrow> \n     (\\<Gamma>,x) \\<in> comm (G,(( p \\<inter> (-b)),a)) F\"\nproof -\n  assume a0: \"\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b, R, G, p,a] \" and\n         a1: \"Sta p R\" and\n         a2: \"Sta  (p \\<inter> (-b)) R\" and\n         a3: \"Sta a R\" and\n         a4: \"(n,\\<Gamma>,x)\\<in> cptn_mod_nest_call\" and\n         a5: \"\\<forall>s. (Normal s, Normal s) \\<in> G\" \n   {fix xs s \n   assume while_xs:\"x=((While b c1),s)#xs\" and\n          x_assum:\"(\\<Gamma>,x)\\<in>assum(p,R)\"\n   have \"(\\<Gamma>,x) \\<in> comm (G,(( p \\<inter> (-b)),a)) F\"\n   using a4 a0  while_xs x_assum\n   proof (induct arbitrary: xs s c1 rule:cptn_mod_nest_call.induct)\n     case (CptnModNestOne  \\<Gamma> C s1) thus ?case \n       using CptnModOne unfolding comm_def final_def\n       by auto\n   next\n     case (CptnModNestEnv  \\<Gamma> C s1 t1 n xsa) \n     then have c_while:\"C = While b c1\" by fastforce\n     have \"(\\<Gamma>, (C, t1) # xsa) \\<in> assum (p, R) \\<longrightarrow>\n                (\\<Gamma>, (C, t1) # xsa) \\<in> comm (G, p \\<inter> (-b), a) F\"  \n     using CptnModNestEnv by fastforce  \n     moreover have\"(n,\\<Gamma>,(C, s1)#(C, t1) # xsa) \\<in> cptn_mod_nest_call\"\n       using CptnModNestEnv(1,2) CptnModNestEnv.hyps(1) CptnModNestEnv.hyps(2)\n       using cptn_mod_nest_call.CptnModNestEnv by blast\n     then have  cptn_mod:\"(\\<Gamma>,(C, s1)#(C, t1) # xsa) \\<in> cptn\"    \n       using cptn_eq_cptn_mod_nest by blast  \n     then have \"(\\<Gamma>, (C, t1) # xsa) \\<in> assum (p, R)\"   \n       using tl_of_assum_in_assum CptnModNestEnv(6) a1 a2 a3 a4 a5\n       by blast\n     ultimately have \"(\\<Gamma>, (C, t1) # xsa) \\<in> comm (G, p \\<inter> (-b), a) F\"\n       by auto\n     also have \" \\<not> (\\<Gamma>\\<turnstile>\\<^sub>c((C,s1))  \\<rightarrow> ((C,t1)))\"\n       by (simp add: mod_env_not_component)      \n     ultimately show ?case \n       using cptn_mod etran_in_comm by blast\n   next \n     case (CptnModNestSkip \\<Gamma> C s1 t1 n xsa) \n     then have \"C=While b c1\" by auto\n     also have \"(n,\\<Gamma>, (LanguageCon.com.Skip, t1) # xsa) \\<in> cptn_mod_nest_call\"\n       using cptn_eq_cptn_mod_set CptnModNestSkip(4) by fastforce\n     thus ?case using WhileNone CptnModNestSkip a1 a2 a3 a4 a5  by blast\n   next\n     case (CptnModNestThrow  \\<Gamma> C s1 t1 n xsa) \n     then have \"C = While b c1\" by auto \n       thus ?case using stepc_elim_cases_while_throw CptnModNestThrow(1) \n       by blast\n   next \n     case (CptnModNestWhile1  n \\<Gamma> c s1 xs1 b1 xsa zs) \n     then have \"b=b1 \\<and> c=c1 \\<and> s=Normal s1\" by auto      \n     thus ?case\n     using a4 a5 CptnModNestWhile1 while1[of n \\<Gamma>] by blast\n   next \n     case (CptnModNestWhile2 n \\<Gamma> c s1 xs1 b1 xsa ys zs)\n     then have a00: \"(n,\\<Gamma>, (While b c, Normal s1) #\n         (Seq c (While b c), Normal s1) # xsa)\\<in>cptn_mod_nest_call\" \n       using cptn_mod_nest_call.CptnModNestWhile2 by fast   \n     then have eqs:\"b=b1 \\<and> c=c1 \\<and> s=Normal s1\"using CptnModNestWhile2 by auto\n     thus ?case using  a00 a4 a5 CptnModNestWhile2 while2[of n \\<Gamma> b c s1 xsa xs1 ys F p R G a] \n       by blast        \n   next\n     case (CptnModNestWhile3 n \\<Gamma> c s1 xs1 b1 sl ys zs)  \n     then have eqs:\"b=b1 \\<and> c=c1 \\<and> s=Normal s1\" by auto \n     then have \"(\\<Gamma>, (While b c, Normal s1) #\n         (Seq c (While b c), Normal s1) #          \n         ((map (lift (While b c)) xs1 @\n           (Throw, Normal sl) # ys))) \\<in> comm (G, p\\<inter>(-b), a) F\"        \n       using a1 a3 a4 a5 CptnModNestWhile3 while3[of n \\<Gamma> c s1 xs1 b sl ys F p R G a] \n       by fastforce   \n     thus ?case using eqs CptnModNestWhile3 by auto\n   qed (auto)\n  }\n  then show ?thesis by auto    \nqed\n\n\nlemma While_sound: \n      \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b, R, G, p,a] \\<Longrightarrow>\n       (\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b, R, G, p,a]) \\<Longrightarrow>       \n       Sta p R \\<Longrightarrow>     \n       Sta (p \\<inter> (-b)) R \\<Longrightarrow> Sta a R \\<Longrightarrow> \\<forall>s. (Normal s, Normal s) \\<in> G  \\<Longrightarrow>\n       \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> (While b c1) sat [p, R, G, p \\<inter> (-b),a]\"\nproof -  \n  assume\n    a0:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b, R, G, p,a]\" and\n    a1:\"\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n \\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b, R, G, p,a]\" and    \n    a2: \"Sta p R\" and\n    a3: \"Sta (p \\<inter> (-b)) R\" and\n    a4: \"Sta a R\" and\n    a5: \"\\<forall>s. (Normal s, Normal s) \\<in> G\" \n  { \n    fix s\n    assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"  \n    then have a1:\"(\\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> c1 sat [p \\<inter> b, R, G, p,a])\" \n      using a1 com_cvalidityn_def by fastforce\n    have \"cpn n \\<Gamma> (While b c1)  s \\<inter> assum(p, R) \\<subseteq> comm(G, (p \\<inter> (-b),a)) F\"\n    proof-\n      {fix c     \n        assume a10:\"c \\<in> cpn n \\<Gamma> (While b c1) s\" and a11:\"c \\<in> assum(p, R)\"\n        then have a10': \"c \\<in> cp  \\<Gamma> (While b c1) s\"\n          unfolding cp_def cpn_def using cptn_eq_cptn_mod_set cptn_mod_nest_cptn_mod by fastforce\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have cp:\"l!0=((While b c1),s) \\<and> (\\<Gamma>,l) \\<in> cptn \\<and> \\<Gamma>=\\<Gamma>1\" using a10' cp_def c_prod by fastforce      \n      have \\<Gamma>1:\"(\\<Gamma>, l) = c\" using c_prod cp by blast\n      obtain xs where \"l=((While b c1),s)#xs\" using cp\n      proof -\n        assume a1: \"\\<And>xs. l = (LanguageCon.com.While b c1, s) # xs \\<Longrightarrow> thesis\"\n        have \"[] \\<noteq> l\"\n          using cp cptn.simps by auto\n        then show ?thesis\n          using a1 by (metis (full_types) SmallStepCon.nth_tl cp)\n      qed \n      moreover have \"(n,\\<Gamma>,l)\\<in>cptn_mod_nest_call\" using a10\n        using \\<Gamma>1 cpn_def by fastforce  \n      ultimately have \"c \\<in> comm(G, (p \\<inter> (-b),a)) F\"\n      using a1 a2 a3 a4   WhileSound_aux a11 \\<Gamma>1 a5 \n        by blast\n      } thus ?thesis by auto qed\n  }\n  thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def)  \nqed\n\n\nlemma Conseq_sound:\n  \"(\\<forall>s\\<in> p.\n       \\<exists>p' R' G' q' a' I' \\<Theta>'.\n          s \\<in> p' \\<and>\n          R \\<subseteq> R' \\<and>            \n          G' \\<subseteq> G \\<and>             \n          q' \\<subseteq> q \\<and>\n          a' \\<subseteq> a \\<and> \\<Theta>' \\<subseteq> \\<Theta> \\<and>\n          \\<Gamma>,\\<Theta>' \\<turnstile>\\<^bsub>/F\\<^esub> P sat [p',R', G', q',a'] \\<and> \n          (\\<forall>n. \\<Gamma>,\\<Theta>' \\<Turnstile>n\\<^bsub>/F\\<^esub> P sat [p', R', G', q',a'])) \\<Longrightarrow>\n  \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> P sat [p,R, G, q,a]\" \nproof -\n  assume \n  a0: \"(\\<forall>s\\<in> p.\n       \\<exists>p' R' G' q' a' I' \\<Theta>'.\n          s \\<in> p' \\<and>\n          R \\<subseteq> R' \\<and>            \n          G' \\<subseteq> G \\<and>             \n          q' \\<subseteq> q \\<and>\n          a' \\<subseteq> a \\<and> \\<Theta>' \\<subseteq> \\<Theta> \\<and>\n          \\<Gamma>,\\<Theta>' \\<turnstile>\\<^bsub>/F\\<^esub> P sat [p',R', G', q',a'] \\<and> \n          (\\<forall>n. \\<Gamma>,\\<Theta>' \\<Turnstile>n\\<^bsub>/F\\<^esub> P sat [p', R', G', q',a']))\"\n  {\n    fix s\n    assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"\n    have \"cpn n \\<Gamma> P  s \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F\"\n    proof -\n    {\n      fix c\n      assume a10:\"c \\<in> cpn n \\<Gamma> P s\" and a11:\"c \\<in> assum(p, R)\"\n      then have a10':\"c\\<in>cp \\<Gamma> P s\" unfolding cp_def cpn_def cptn_eq_cptn_mod_nest by auto\n      obtain \\<Gamma>1 l where c_prod:\"c=(\\<Gamma>1,l)\" by fastforce\n      have cp:\"l!0=(P,s) \\<and> (n,\\<Gamma>,l) \\<in> cptn_mod_nest_call \\<and> \\<Gamma>=\\<Gamma>1\" using a10 cpn_def c_prod by fastforce\n      have \\<Gamma>1:\"(\\<Gamma>, l) = c\" using c_prod cp by blast \n      obtain xs where \"l=(P,s)#xs\" using cp\n      proof -\n        assume a1: \"\\<And>xs. l = (P, s) # xs \\<Longrightarrow> thesis\"\n        have \"[] \\<noteq> l\"\n          using cp cptn.simps\n          using CptnEmpty by force\n        then show ?thesis\n          using a1 by (metis (full_types) SmallStepCon.nth_tl cp)\n      qed\n      obtain ns where s:\"(s = Normal ns)\" using a10 a11 unfolding assum_def cpn_def by fastforce\n      then have \"ns \\<in> p\" using a10 a11 unfolding assum_def cpn_def by fastforce\n      then have ns:\"ns\\<in>p\" by auto\n      then have\n      \"\\<forall>s. s \\<in> p \\<longrightarrow> (\\<exists>p' R' G' q' a' \\<Theta>'. (s\\<in>p') \\<and>\n        R \\<subseteq> R' \\<and>            \n        G' \\<subseteq> G \\<and>             \n        q' \\<subseteq> q \\<and>\n        a' \\<subseteq> a \\<and> \\<Theta>' \\<subseteq> \\<Theta> \\<and>\n        (\\<Gamma>,\\<Theta>' \\<turnstile>\\<^bsub>/F\\<^esub> P sat [p',R', G', q',a']) \\<and> \n        (\\<forall>n. \\<Gamma>,\\<Theta>' \\<Turnstile>n\\<^bsub>/F\\<^esub> P sat [p', R', G', q',a']))\" using a0 by auto\n      then have \n       \"ns \\<in> p \\<longrightarrow> (\\<exists>p' R' G' q' a' \\<Theta>'. (ns \\<in> p' ) \\<and>\n        R \\<subseteq> R' \\<and>            \n        G' \\<subseteq> G \\<and>             \n        q' \\<subseteq> q \\<and>\n        a' \\<subseteq> a \\<and> \\<Theta>' \\<subseteq> \\<Theta> \\<and>\n        (\\<Gamma>,\\<Theta>' \\<turnstile>\\<^bsub>/F\\<^esub> P sat [p',R', G', q',a']) \\<and> \n        (\\<forall>n. \\<Gamma>,\\<Theta>' \\<Turnstile>n\\<^bsub>/F\\<^esub> P sat [p', R', G', q',a']))\" apply (rule allE) by auto     \n     then obtain p' R' G' q' a' \\<Theta>'   where\n     rels:\n       \"ns \\<in> p' \\<and>\n        R \\<subseteq> R' \\<and>            \n        G' \\<subseteq> G \\<and>             \n        q' \\<subseteq> q \\<and>\n        a' \\<subseteq> a \\<and> \\<Theta>' \\<subseteq> \\<Theta> \\<and>       \n        (\\<forall>n. \\<Gamma>,\\<Theta>' \\<Turnstile>n\\<^bsub>/F\\<^esub> P sat [p', R', G', q',a'])\" using ns by auto\n      then have \"s \\<in>  Normal ` p'\" using s by fastforce\n      then have \"(\\<Gamma>,l) \\<in> assum(p', R')\"\n        using a11 rels cp a11 c_prod assum_R_R'[of \\<Gamma> l p R p' R'] \n        by fastforce\n      then have \"(\\<Gamma>,l) \\<in> comm(G',(q',a')) F\" \n        using rels all_call a10 c_prod cp unfolding com_cvalidityn_def com_validityn_def \n        by blast\n      then have \"(\\<Gamma>,l) \\<in> comm(G, (q,a)) F\" \n        using c_prod cp comm_conseq[of \\<Gamma> l G' q' a' F G q a] rels by fastforce\n      then have \"c \\<in> comm(G, (q,a)) F\" using c_prod cp by fastforce\n    }                 \n    thus ?thesis unfolding comm_def by force qed      \n  } thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def)  \nqed   \n\nlemma Conj_post_sound:\n  \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> P sat [p,R, G, q,a] \\<and> \n   (\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> P sat [p, R, G, q,a]) \\<Longrightarrow> \n   \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> P sat [p,R, G, q',a'] \\<and> \n   (\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n \\<^bsub>/F\\<^esub> P sat [p, R, G, q',a']) \\<Longrightarrow>\n  \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> P sat [p,R, G, q \\<inter> q' ,a \\<inter> a']\" \nproof -\nassume a0: \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> P sat [p,R, G, q,a] \\<and> \n   (\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> P sat [p, R, G, q,a])\" and\n       a1: \" \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> P sat [p,R, G, q',a'] \\<and> \n   (\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n \\<^bsub>/F\\<^esub> P sat [p, R, G, q',a'])\"\n{\n    fix s\n    assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"\n    with a0 have a0:\"cpn n \\<Gamma> P  s \\<inter> assum(p, R) \\<subseteq> comm(G, (q,a)) F\"\n      unfolding com_cvalidityn_def com_validityn_def by auto\n    with a1 all_call have a1:\"cpn n \\<Gamma> P  s \\<inter> assum(p, R) \\<subseteq> comm(G, (q',a')) F\"\n      unfolding com_cvalidityn_def com_validityn_def by auto\n    have \"cpn n \\<Gamma> P  s \\<inter> assum(p, R) \\<subseteq> comm(G, (q\\<inter>q',a\\<inter>a')) F\"\n    proof -\n    {\n      fix c\n      assume a10:\"c \\<in> cpn n \\<Gamma> P s\" and a11:\"c \\<in> assum(p, R)\"\n      then have \"c \\<in> comm(G,(q,a)) F \\<and> c \\<in> comm(G,(q',a')) F\"\n        using a0 a1 by auto\n      then have  \"c\\<in>comm(G, (q\\<inter>q',a\\<inter>a')) F\"\n        unfolding comm_def by fastforce\n    }               \n    thus ?thesis unfolding comm_def by force qed      \n  } thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def)  \nqed  \n  \nlemma x91:\"sa\\<noteq>{} \\<Longrightarrow> c\\<in>comm(G, (\\<Inter>i\\<in>sa. q i,a)) F  = (\\<forall>i\\<in>sa. c\\<in>comm(G, q i,a) F)\"    \n  unfolding comm_def apply (auto simp add: Ball_def) \n   apply (frule spec ,  force)\n    by (frule spec,  force)\n\n  \n  \nlemma conj_inter_sound:\n\"sa \\<noteq> {} \\<Longrightarrow> \n \\<forall>i\\<in>sa. \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q i,a] \\<and> (\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> P sat [p,R, G, q i,a]) \\<Longrightarrow> \n \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> P sat [p,R, G, \\<Inter>i\\<in>sa. q i,a]\"\nproof -\n  assume a0':\"sa\\<noteq>{}\" and \n         a0: \"\\<forall>i\\<in>sa. \\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q i,a] \\<and> \n              (\\<forall>n. \\<Gamma>,\\<Theta> \\<Turnstile>n\\<^bsub>/F\\<^esub> P sat [p,R, G, q i,a])\" \n{\n    fix s\n    assume all_call:\"\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>n\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]\"\n    with a0 have a0:\"\\<forall>i\\<in>sa. cpn n \\<Gamma> P  s \\<inter> assum(p, R) \\<subseteq> comm(G, (q i,a)) F\"\n      unfolding com_cvalidityn_def com_validityn_def by auto    \n    have \"cpn n \\<Gamma> P  s \\<inter> assum(p, R) \\<subseteq> comm(G, (\\<Inter>i\\<in>sa. q i,a)) F\"\n    proof -\n    {\n      fix c\n      assume a10:\"c \\<in> cpn n \\<Gamma> P s\" and a11:\"c \\<in> assum(p, R)\"        \n      then have  \"(\\<forall>i\\<in>sa. c\\<in>comm(G, q i,a) F)\"        \n        using a0 by fastforce\n      then have \"c\\<in>comm(G, (\\<Inter>i\\<in>sa. q i,a)) F\" using x91[OF a0'] by blast\n    }               \n    thus ?thesis unfolding comm_def by force qed      \n  } thus ?thesis by (simp add: com_validityn_def[of \\<Gamma>] com_cvalidityn_def)  \nqed     \n\nlemma localRG_sound: \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> c sat [p, R, G, q,a] \\<Longrightarrow> (\\<And>n. \\<Gamma>,\\<Theta> \\<Turnstile>n \\<^bsub>/F\\<^esub> c sat [p, R, G, q,a])\"\nproof (induct rule:lrghoare.induct)\n  case Skip \n    thus ?case  by (simp add: Skip_sound)\nnext\n  case Spec\n    thus ?case  by (simp add: Spec_sound)\nnext\n  case Basic\n    thus ?case by (simp add: Basic_sound)\nnext\n  case Await\n    thus ?case by (simp add: Await_sound)\nnext\n  case Throw thus ?case by (simp add: Throw_sound)\nnext \n  case If thus ?case using If_sound by (simp add: If_sound)\nnext\n  case Asm thus ?case by (simp add: Asm_sound)\nnext \n  case CallRec thus ?case  by (simp add: CallRec_sound)\nnext\n  case Call thus ?case using Call_sound  by (simp add: Call_sound)\nnext\n  case Seq thus ?case by (simp add: Seq_sound)\nnext\n  case Catch thus ?case by (simp add: Catch_sound)\nnext\n  case DynCom thus ?case by (simp add: DynCom_sound)\nnext\n  case Guard thus ?case by (simp add: Guard_sound)\nnext\n  case Guarantee thus ?case by (simp add: Guarantee_sound)\nnext\n  case While thus ?case by (simp add: While_sound)\nnext\n  case (Conseq p R G q a \\<Gamma> \\<Theta> F P) thus ?case \n    using Conseq_sound by simp\nnext \n  case (Conj_post \\<Gamma> \\<Theta> F P p' R' G' q a q' a') thus ?case\n    using Conj_post_sound[of \\<Gamma> \\<Theta>] by simp\nnext\n  case (Conj_Inter sa \\<Gamma> \\<Theta> F P p' R' G' q a ) \n    thus ?case using conj_inter_sound[of sa \\<Gamma> \\<Theta>] by simp \nqed   \n\n\ndefinition ParallelCom :: \"('s,'p,'f,'e) rgformula list \\<Rightarrow> ('s,'p,'f,'e) par_com\"\nwhere\n\"ParallelCom Ps \\<equiv> map fst Ps\"\n\nlemma ParallelCom_Com:\"i<length xs \\<Longrightarrow> (ParallelCom xs)!i = Com (xs!i)\"\nunfolding ParallelCom_def Com_def by fastforce\n\n\nlemma etran_ctran_eq_p_normal_s: \"\\<Gamma>\\<turnstile>\\<^sub>c s1  \\<rightarrow> s1' \\<Longrightarrow>\n             \\<Gamma>\\<turnstile>\\<^sub>c s1  \\<rightarrow>\\<^sub>e s1' \\<Longrightarrow>\n            fst s1 = fst s1' \\<and> snd s1 = snd s1' \\<and> (\\<exists>ns1. snd s1 = Normal ns1)\"\nproof -\n   assume a0: \"\\<Gamma>\\<turnstile>\\<^sub>c s1  \\<rightarrow> s1'\" and\n          a1: \"\\<Gamma>\\<turnstile>\\<^sub>c s1  \\<rightarrow>\\<^sub>e s1'\"\n   then obtain ps1 ss1 ps1' ss1' where prod:\"s1 = (ps1,ss1) \\<and> s1' = (ps1', ss1')\"\n     by fastforce\n   then have \"ps1=ps1'\" using a1 etranE by fastforce\n   thus ?thesis using prod  a0 by (simp add: mod_env_not_component)\nqed\n\nlemma step_e_step_c_eq:\"\\<lbrakk> \n  (\\<Gamma>,l) \\<propto> clist;\n  Suc m < length l;\n  i < length clist; \n  (fst (clist!i))\\<turnstile>\\<^sub>c((snd (clist!i))!m) \\<rightarrow>\\<^sub>e  ((snd (clist!i))!Suc m);          \n  (fst (clist!i))\\<turnstile>\\<^sub>c((snd (clist!i))!m) \\<rightarrow>  ((snd (clist!i))!Suc m);\n  (\\<forall>l<length clist. \n     l\\<noteq>i \\<longrightarrow>  (fst (clist!l))\\<turnstile>\\<^sub>c (snd (clist!l))!m  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc m)))\n  \\<rbrakk> \\<Longrightarrow> \n  l!m = l!(Suc m) \\<and> (\\<exists>ns. snd (l!m) = Normal ns )\"\nproof -\n  assume a0:\"(\\<Gamma>,l) \\<propto> clist\" and\n         a1:\"Suc m < length l\" and\n         a2:\"i < length clist\" and\n         a3:\"(fst (clist!i))\\<turnstile>\\<^sub>c((snd (clist!i))!m) \\<rightarrow>\\<^sub>e  ((snd (clist!i))!Suc m)\" and\n         a4:\"(fst (clist!i))\\<turnstile>\\<^sub>c((snd (clist!i))!m) \\<rightarrow>  ((snd (clist!i))!Suc m)\" and\n         a5:\"(\\<forall>l<length clist. \n                 l\\<noteq>i \\<longrightarrow> (fst (clist!l))\\<turnstile>\\<^sub>c (snd (clist!l))!m  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc m)))\"\n  obtain fp fs sp ss \n    where prod_step: \" \n               \\<Gamma>\\<turnstile>\\<^sub>c (fp, fs) \\<rightarrow> (sp,ss) \\<and> \n              fp = fst (((snd (clist!i))!m)) \\<and> fs = snd (((snd (clist!i))!m)) \\<and> \n              sp = fst ((snd (clist!i))!(Suc m)) \\<and> ss = snd((snd (clist!i))!(Suc m)) \\<and>\n              \\<Gamma> = fst (clist!i)\"\n    using a0 a2 a1 a4 unfolding conjoin_def same_functions_def by fastforce \n  have snd_lj:\"(snd (l!m)) = snd ((snd (clist!i))!m)\"\n            using a0 a1 a2  unfolding conjoin_def same_state_def\n            by fastforce \n  have fst_clist_\\<Gamma>:\"\\<forall>i<length clist. fst(clist!i) = \\<Gamma>\" \n    using a0 unfolding conjoin_def same_functions_def by fastforce\n  have all_env: \"\\<forall>l<length clist. \n                    (fst (clist!l))\\<turnstile>\\<^sub>c (snd (clist!l))!m  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc m))\"\n    using a3 a5 a2 fst_clist_\\<Gamma> by fastforce\n  then have allP:\"\\<forall>l< length clist. fst ((snd (clist!l))!m) = fst ((snd (clist!l))!(Suc m))\"\n    by (fastforce elim:etranE)         \n  then have \"fst (l!m) = (fst (l!(Suc m)))\"\n    using a0 conjoin_same_program_i_j [of \"(\\<Gamma>,l)\"] a1 by fastforce\n  also have snd_l_normal:\"snd (l!m) = snd (l!(Suc m)) \\<and> (\\<exists>ns. snd (l!m) = Normal ns )\"\n  proof -                        \n    have \"(snd (l!Suc m)) = snd ((snd (clist!i))!(Suc m))\"\n      using a0 a1 a2 unfolding conjoin_def same_state_def\n      by fastforce\n    also have \"fs = ss \\<and> \n               (\\<exists>ns.  (snd ((snd (clist!i))!m) = Normal ns ))\"\n      using a1 a2  all_env prod_step allP\n      by (metis step_change_p_or_eq_s)       \n    ultimately show ?thesis using snd_lj prod_step a1  by fastforce\n  qed \n  ultimately show ?thesis using prod_eq_iff by blast      \nqed\n\nlemma two': \n  \"\\<lbrakk> \\<forall>i<length xs. R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n       \\<subseteq> (Rely (xs ! i));\n   p \\<subseteq> (\\<Inter>i<length xs. (Pre (xs ! i)));\n   \\<forall>i<length xs.\n    \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)];\n   length xs=length clist; (\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s; (\\<Gamma>,l)\\<in>par_assum (p, R) ;\n  \\<forall>i<length clist. clist!i\\<in>cp \\<Gamma> (Com(xs!i)) s; (\\<Gamma>,l) \\<propto> clist;(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]);\n  snd (last l) \\<notin> Fault ` F\\<rbrakk>\n  \\<Longrightarrow> \\<forall>j i ns ns'. i<length clist \\<and> Suc j<length l \\<longrightarrow> \n      \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>\\<^sub>e  ((snd (clist!i))!Suc j) \\<longrightarrow> \n      (snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in> Rely(xs!i)\"\nproof -\n  assume a0:\"\\<forall>i<length xs. R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n       \\<subseteq> (Rely (xs ! i))\" and\n         a1:\"p \\<subseteq> (\\<Inter>i<length xs. (Pre (xs ! i)))\" and\n         a2:\"\\<forall>i<length xs.\n    \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)]\" and\n         a3: \"length xs=length clist\" and\n         a4: \"(\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s\" and\n         a5: \"(\\<Gamma>,l)\\<in>par_assum (p, R)\" and\n         a6: \"\\<forall>i<length clist. clist!i\\<in>cp \\<Gamma> (Com(xs!i)) s\" and\n         a7: \"(\\<Gamma>,l) \\<propto> clist\" and\n         a8: \"(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a])\" and \n         a9: \"snd (last l) \\<notin> Fault ` F\"\n{\n  assume a10:\"\\<exists>i j ns ns'. \n              i<length clist \\<and> Suc j<length l \\<and> \n              \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>\\<^sub>e  ((snd (clist!i))!Suc j) \\<and> \n              \\<not>(snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in> Rely(xs!i)\"\n  then obtain j where \n    a10:\"\\<exists>i ns ns'. \n       i<length clist \\<and> Suc j<length l \\<and> \n       \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>\\<^sub>e  ((snd (clist!i))!Suc j) \\<and>\n       \\<not>(snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in> Rely(xs!i)\" by fastforce\n   let ?P = \"\\<lambda>j. \\<exists>i. i<length clist \\<and> Suc j<length l \\<and>\n      \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>\\<^sub>e  ((snd (clist!i))!Suc j) \\<and>       \n      (\\<not> (snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in> Rely(xs!i))\"        \n   obtain m where fist_occ:\"(?P m) \\<and> (\\<forall>i<m. \\<not> ?P i)\" using exists_first_occ[of ?P j] a10 by blast\n     then have \"?P m\" by fastforce\n     then obtain i where\n      fst_occ:\"i<length clist \\<and> Suc m<length l \\<and>\n      \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!m) \\<rightarrow>\\<^sub>e  ((snd (clist!i))!Suc m) \\<and>       \n      (\\<not> (snd((snd (clist!i))!m), snd((snd (clist!i))!Suc m)) \\<in> Rely(xs!i))\"\n     by fastforce\n    have notP:\"(\\<forall>i<m. \\<not> ?P i)\" using fist_occ by blast     \n    have fst_clist_\\<Gamma>:\"\\<forall>i<length clist. fst(clist!i) = \\<Gamma>\" \n      using a7 unfolding conjoin_def same_functions_def by fastforce\n    have compat:\"(\\<Gamma>\\<turnstile>\\<^sub>p(l!m)  \\<rightarrow> (l!(Suc m))) \\<and> \n            (\\<exists>i<length clist. \n               ((fst (clist!i))\\<turnstile>\\<^sub>c ((snd (clist!i))!m)  \\<rightarrow> ((snd (clist!i))!(Suc m))) \\<and> \n            (\\<forall>l<length clist. \n               l\\<noteq>i \\<longrightarrow>  (fst (clist!l))\\<turnstile>\\<^sub>c (snd (clist!l))!m  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc m)))) \\<or> \n         (\\<Gamma>\\<turnstile>\\<^sub>p(l!m)  \\<rightarrow>\\<^sub>e (l!(Suc m)) \\<and> \n          (\\<forall>i<length clist.  (fst (clist!i))\\<turnstile>\\<^sub>c (snd (clist!i))!m  \\<rightarrow>\\<^sub>e ((snd (clist!i))!(Suc m))))\"\n     using a7 fst_occ unfolding conjoin_def compat_label_def by simp\n     {\n       assume a20: \"(\\<Gamma>\\<turnstile>\\<^sub>p(l!m)  \\<rightarrow>\\<^sub>e (l!(Suc m)) \\<and> \n          (\\<forall>i<length clist.  (fst (clist!i))\\<turnstile>\\<^sub>c (snd (clist!i))!m  \\<rightarrow>\\<^sub>e ((snd (clist!i))!(Suc m))))\"\n       then have \"(snd (l!m),snd (l!(Suc m))) \\<in> R\"       \n       using fst_occ a5  unfolding par_assum_def by fastforce\n       then have \"(snd(l!m), snd(l!(Suc m))) \\<in>  Rely(xs!i)\"\n       using fst_occ a3 a0 by fastforce\n       then have \"(snd ((snd (clist!i))!m), snd ((snd (clist!i))!(Suc m)) ) \\<in>  Rely(xs!i)\" \n       using a7 fst_occ unfolding conjoin_def same_state_def by fastforce        \n       then have False using fst_occ by auto\n     }note l = this\n     {\n      assume a20:\"(\\<Gamma>\\<turnstile>\\<^sub>p(l!m)  \\<rightarrow> (l!(Suc m))) \\<and> \n            (\\<exists>i<length clist. \n               ((fst (clist!i))\\<turnstile>\\<^sub>c ((snd (clist!i))!m)  \\<rightarrow> ((snd (clist!i))!(Suc m))) \\<and> \n            (\\<forall>l<length clist. \n               l\\<noteq>i \\<longrightarrow>  (fst (clist!l))\\<turnstile>\\<^sub>c (snd (clist!l))!m  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc m))))\"\n      then obtain i'  \n      where i':\"i'<length clist \\<and> \n               ((fst (clist!i'))\\<turnstile>\\<^sub>c ((snd (clist!i'))!m)  \\<rightarrow> ((snd (clist!i'))!(Suc m))) \\<and> \n               (\\<forall>l<length clist. \n                 l\\<noteq>i' \\<longrightarrow>  (fst (clist!l))\\<turnstile>\\<^sub>c (snd (clist!l))!m  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc m)))\"\n      by fastforce\n      then have eq_\\<Gamma>:\"\\<Gamma> = fst (clist!i')\" using a7 unfolding conjoin_def same_functions_def by fastforce\n      obtain fp fs sp ss \n      where prod_step: \" \n               \\<Gamma>\\<turnstile>\\<^sub>c (fp, fs) \\<rightarrow> (sp,ss) \\<and> \n              fp = fst (((snd (clist!i'))!m)) \\<and> fs = snd (((snd (clist!i'))!m)) \\<and> \n              sp = fst ((snd (clist!i'))!(Suc m)) \\<and> ss = snd((snd (clist!i'))!(Suc m)) \\<and>\n              \\<Gamma> = fst (clist!i') \"\n      using a7 i' unfolding conjoin_def same_functions_def by fastforce            \n      then have False\n      proof (cases \"i = i'\")\n        case True       \n        then have \"l!m = l!(Suc m) \\<and> (\\<exists>ns. snd (l!m) = Normal ns )\"\n          using step_e_step_c_eq[OF a7] i' fst_occ eq_\\<Gamma> by blast\n        then have \"\\<Gamma>\\<turnstile>\\<^sub>p(l!m)  \\<rightarrow>\\<^sub>e (l!(Suc m))\" \n          using step_pe.ParEnv  by (metis prod.collapse)           \n        then have \"(snd (l ! m), snd (l ! Suc m)) \\<in> R \"\n          using fst_occ  a5 unfolding par_assum_def by fastforce\n        then have \"(snd (l ! m), snd (l ! Suc m)) \\<in> Rely (xs ! i)\"\n          using a0 a3 fst_occ by fastforce\n        then show ?thesis using fst_occ a7\n          unfolding conjoin_def same_state_def  \n          by fastforce         \n      next\n        case False  note not_eq = this       \n        thus ?thesis \n        proof (cases \"fp = sp\")\n          case True \n          then have  \"fs = ss \\<and> (\\<exists>ns. fs=Normal ns)\" \n            using prod_step  prod_step\n            using step_change_p_or_eq_s by blast  \n          \n          then have \"\\<Gamma>\\<turnstile>\\<^sub>c (fp, fs) \\<rightarrow>\\<^sub>e (sp, ss)\" using True step_e.Env \n            by fastforce\n          then have \"l!m = l!(Suc m) \\<and> (\\<exists>ns. snd (l!m) = Normal ns )\"\n            using step_e_step_c_eq[OF a7] prod_step i' fst_occ prod.collapse by auto\n          then have \"\\<Gamma>\\<turnstile>\\<^sub>p(l!m)  \\<rightarrow>\\<^sub>e (l!(Suc m))\" \n            using step_pe.ParEnv  by (metis prod.collapse)           \n          then have \"(snd (l ! m), snd (l ! Suc m)) \\<in> R \"\n            using fst_occ  a5 unfolding par_assum_def by fastforce\n          then have \"(snd (l ! m), snd (l ! Suc m)) \\<in> Rely (xs ! i)\"\n            using a0 a3 fst_occ by fastforce\n          then show ?thesis using fst_occ a7\n            unfolding conjoin_def same_state_def  \n          by fastforce                   \n        next\n          case False                    \n          let ?l1 = \"take (Suc (Suc m)) (snd(clist!i'))\"\n          have clist_cptn:\"(\\<Gamma>,snd(clist!i')) \\<in> cptn\" using a6 i' unfolding cp_def by fastforce\n          have sucm_len:\"Suc m < length (snd (clist!i'))\" \n            using i' fst_occ a7 unfolding conjoin_def same_length_def by fastforce          \n          then have summ_lentake:\"Suc m < length ?l1\" by fastforce\n          have len_l: \"0<length l\" using fst_occ by fastforce\n          also then have \"snd (clist!i')\\<noteq>[]\" \n            using i' a7 unfolding conjoin_def same_length_def by fastforce\n          ultimately have \"snd (last (snd (clist ! i'))) = snd (last l)\"\n            using a7 i' conjoin_last_same_state by fastforce\n          then have last_i_notF:\"snd (last (snd(clist!i'))) \\<notin> Fault ` F\" \n            using a9 by auto  \n          have \"\\<forall>i<length (snd(clist!i')).  snd (snd(clist!i') ! i) \\<notin> Fault ` F \" \n            using  last_not_F[OF clist_cptn last_i_notF] by auto \n          also have suc_m_i':\"Suc m < length (snd (clist !i'))\"\n            using fst_occ i' a7 unfolding conjoin_def same_length_def by fastforce\n          ultimately have last_take_not_f:\"snd (last (take (Suc (Suc m)) (snd(clist!i')))) \\<notin> Fault ` F\"\n            by (simp add: take_Suc_conv_app_nth)           \n          have not_env_step:\"\\<not> \\<Gamma>\\<turnstile>\\<^sub>c snd (clist ! i') ! m \\<rightarrow>\\<^sub>e snd (clist ! i') ! Suc m\"\n            using False etran_ctran_eq_p_normal_s i' prod_step by blast           \n          then have \"snd ((snd(clist!i'))!0)\\<in> Normal ` p\" \n            using len_l a7 i' a5 unfolding conjoin_def same_state_def par_assum_def by fastforce\n          then have \"snd ((snd(clist!i'))!0)\\<in> Normal ` (Pre (xs ! i'))\"\n            using a1 i' a3 by fastforce\n          then have \"snd ((take (Suc (Suc m)) (snd(clist!i')))!0)\\<in> Normal `(Pre (xs ! i'))\" \n            by fastforce       \n          moreover have \n          \"\\<forall>j. Suc j < Suc (Suc m) \\<longrightarrow>\n                \\<Gamma>\\<turnstile>\\<^sub>c snd (clist ! i') ! j \\<rightarrow>\\<^sub>e snd (clist ! i') ! Suc j \\<longrightarrow>\n                (snd (snd (clist ! i') ! j), snd (snd (clist ! i') ! Suc j)) \\<in> Rely (xs ! i')\" \n            using not_env_step fst_occ Suc_less_eq fist_occ i' less_SucE less_trans_Suc by auto\n          then have \"\\<forall>j. Suc j < length (take (Suc (Suc m)) (snd(clist!i'))) \\<longrightarrow>\n                \\<Gamma>\\<turnstile>\\<^sub>c snd (clist ! i') ! j \\<rightarrow>\\<^sub>e snd (clist ! i') ! Suc j \\<longrightarrow>\n                (snd (snd (clist ! i') ! j), snd (snd (clist ! i') ! Suc j)) \\<in> Rely (xs ! i')\"\n            by fastforce \n          ultimately have \"(\\<Gamma>, (take (Suc (Suc m)) (snd(clist!i')))) \\<in> \n                             assum ((Pre (xs ! i')),Rely (xs ! i'))\"\n            unfolding assum_def by fastforce         \n          moreover have \"(\\<Gamma>,snd(clist!i')) \\<in> cptn\" using a6 i' unfolding cp_def by fastforce\n          then have \"(\\<Gamma>,take (Suc (Suc m)) (snd(clist!i'))) \\<in> cptn\"\n            by (simp add: takecptn_is_cptn)              \n          then have \"(\\<Gamma>,take (Suc (Suc m)) (snd(clist!i'))) \\<in> cp \\<Gamma> (Com(xs!i')) s\"\n            using i' a3 a6 unfolding cp_def by fastforce          \n          ultimately have t:\"(\\<Gamma>,take (Suc (Suc m)) (snd(clist!i'))) \\<in> \n                              comm (Guar (xs ! i'), (Post (xs ! i'),Abr (xs ! i'))) F \"\n          using a8 a2 a3 i' unfolding com_cvalidity_def com_validity_def by fastforce               \n          have \"(snd(take (Suc (Suc m)) (snd(clist!i'))!m), \n                        snd(take (Suc (Suc m)) (snd(clist!i'))!(Suc m))) \\<in> Guar (xs ! i')\"\n            using eq_\\<Gamma>  i' comm_dest1[OF t last_take_not_f summ_lentake] by fastforce\n          \n          then have \"(snd( (snd(clist!i'))!m), \n                        snd((snd(clist!i'))!(Suc m))) \\<in> Guar (xs ! i')\"\n          by fastforce\n          then have \"(snd( (snd(clist!i))!m), \n                      snd((snd(clist!i))!(Suc m))) \\<in> Guar (xs ! i')\"\n           using a7 fst_occ unfolding conjoin_def same_state_def by (metis Suc_lessD i' snd_conv) \n          then have \"(snd( (snd(clist!i))!m), \n                      snd((snd(clist!i))!(Suc m))) \\<in> Rely (xs ! i)\"\n          using not_eq a0 i' a3 fst_occ by auto          \n          then have \"False\" using fst_occ by auto\n          then show ?thesis by auto\n        qed\n      qed\n     }  \n  then have False using compat l by auto\n} thus ?thesis by auto\nqed\n\nlemma two: \n  \"\\<lbrakk> \\<forall>i<length xs. R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n       \\<subseteq> (Rely (xs ! i));\n   p \\<subseteq> (\\<Inter>i<length xs. (Pre (xs ! i)));\n   \\<forall>i<length xs.\n    \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)];\n   length xs=length clist; (\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s; (\\<Gamma>,l)\\<in>par_assum (p, R);\n  \\<forall>i<length clist. clist!i\\<in>cp \\<Gamma> (Com(xs!i)) s; (\\<Gamma>,l) \\<propto> clist;(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]);\n  snd (last l) \\<notin> Fault ` F\\<rbrakk>\n  \\<Longrightarrow> \\<forall>j i ns ns'. i<length clist \\<and> Suc j<length l \\<longrightarrow> \n      \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>  ((snd (clist!i))!Suc j) \\<longrightarrow>       \n        (snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in> Guar(xs!i) \"\nproof -\n  assume a0:\"\\<forall>i<length xs. R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n       \\<subseteq> (Rely (xs ! i))\" and\n         a1:\"p \\<subseteq> (\\<Inter>i<length xs. (Pre (xs ! i)))\" and\n         a2:\"\\<forall>i<length xs.\n    \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)]\" and\n         a3: \"length xs=length clist\" and\n         a4: \"(\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s\" and\n         a5: \"(\\<Gamma>,l)\\<in>par_assum (p, R)\" and\n         a6: \"\\<forall>i<length clist. clist!i\\<in>cp \\<Gamma> (Com(xs!i)) s\" and\n         a7: \"(\\<Gamma>,l) \\<propto> clist\" and\n         a8: \"(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a])\" and \n         a9: \"snd (last l) \\<notin> Fault ` F\"\n  {\n     assume a10:\"(\\<exists>i j. i<length clist \\<and> Suc j<length l \\<and>  \n      \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>  ((snd (clist!i))!Suc j) \\<and> \n       \\<not> (snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in> Guar(xs!i)) \"\n     then obtain j where a10: \"\\<exists>i. i<length clist \\<and> Suc j<length l \\<and>\n      \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>  ((snd (clist!i))!Suc j) \\<and>        \n      \\<not> (snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in> Guar(xs!i)\"\n     by fastforce\n     let ?P = \"\\<lambda>j. \\<exists>i. i<length clist \\<and> Suc j<length l \\<and>\n      \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>  ((snd (clist!i))!Suc j) \\<and>       \n      \\<not> (snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in> Guar(xs!i)\"     \n     obtain m where fist_occ:\"?P m \\<and> (\\<forall>i<m. \\<not> ?P i)\" using exists_first_occ[of ?P j] a10 by blast\n     then have P:\"?P m\" by fastforce\n     then have notP:\"(\\<forall>i<m. \\<not> ?P i)\" using fist_occ by blast\n     obtain i ns ns' where fst_occ:\"i<length clist \\<and> Suc m<length l \\<and> \n      \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!m) \\<rightarrow>  ((snd (clist!i))!Suc m) \\<and>      \n      (\\<not> (snd((snd (clist!i))!m), snd((snd (clist!i))!Suc m)) \\<in>  Guar(xs!i))\"\n       using P by fastforce\n     have fst_clist_i: \"fst (clist!i) = \\<Gamma>\" \n         using a7 fst_occ unfolding conjoin_def same_functions_def \n         by fastforce\n     have \"clist!i\\<in>cp \\<Gamma> (Com(xs!i)) s\" using a6 fst_occ by fastforce\n     then have clistcp:\"(\\<Gamma>, snd (clist!i))\\<in>cp \\<Gamma> (Com(xs!i)) s\" \n         using  fst_occ a7 unfolding conjoin_def same_functions_def by fastforce\n     let ?li=\"take (Suc (Suc m)) (snd (clist!i))\"     \n     have \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)]\"\n       using a8 a2 a3 fst_occ unfolding com_cvalidity_def by fastforce\n     moreover have take_in_ass:\"(\\<Gamma>, take (Suc (Suc m)) (snd (clist!i))) \\<in> assum (Pre(xs!i), Rely(xs!i))\"     \n     proof -\n       have length_take_length_l:\"length (take (Suc (Suc m)) (snd (clist!i))) \\<le> length l\"\n         using a7 fst_occ unfolding conjoin_def same_length_def by auto\n       have \"snd((?li!0)) \\<in> Normal ` Pre(xs!i)\" \n       proof -\n         have \"(take (Suc (Suc m)) (snd (clist!i)))!0 = (snd (clist!i))!0\" by fastforce\n         moreover have \"snd (snd(clist!i)!0) = snd (l!0)\" \n           using a7 fst_occ unfolding conjoin_def same_state_def by fastforce\n         moreover have \"snd (l!0) \\<in> Normal ` p\" \n           using a5 unfolding par_assum_def by fastforce\n         ultimately show ?thesis using a1 a3 fst_occ by fastforce \n       qed note left=this\n       thus ?thesis  \n         using two'[OF a0 a1 a2 a3 a4 a5 a6 a7 a8 a9] fst_occ unfolding assum_def by fastforce\n       qed     \n     moreover have \"(\\<Gamma>,take (Suc (Suc m)) (snd (clist!i))) \\<in> cp \\<Gamma> (Com(xs!i)) s\"\n       using takecptn_is_cptn clistcp unfolding cp_def by fastforce      \n     ultimately have comm:\"(\\<Gamma>, take (Suc (Suc m)) (snd (clist!i)))\\<in>comm(Guar(xs!i),(Post (xs ! i),Abr (xs ! i))) F\"       \n        unfolding com_validity_def by fastforce  \n     also have not_fault:\"snd (last (take (Suc (Suc m)) (snd (clist!i))))  \\<notin> Fault ` F\"\n     proof -      \n       have cptn:\"(\\<Gamma>, snd (clist!i)) \\<in> cptn\" \n         using fst_clist_i a6 fst_occ unfolding cp_def by fastforce   \n       then have \"(snd (clist!i))\\<noteq>[]\" \n        using cptn.simps list.simps(3) \n        by fastforce               \n       then have \"snd (last (snd (clist!i))) = snd (last l)\"\n         using conjoin_last_same_state fst_occ a7 by fastforce\n       then have \"snd (last (snd (clist!i))) \\<notin> Fault ` F\" using a9\n         by simp\n       also have sucm:\"Suc m < length (snd (clist!i))\" \n         using fst_occ a7 unfolding conjoin_def same_length_def by fastforce\n       ultimately have sucm_not_fault:\"snd ((snd (clist!i))!(Suc m)) \\<notin> Fault ` F\"\n         using last_not_F cptn by blast \n       have \"length (take (Suc (Suc m)) (snd (clist!i))) = Suc (Suc m)\" \n         using sucm by fastforce\n       then have \"last (take (Suc (Suc m)) (snd (clist!i))) =  (take (Suc (Suc m)) (snd (clist!i)))!(Suc m)\"\n         by (metis Suc_diff_1 Suc_inject last_conv_nth list.size(3) old.nat.distinct(2) zero_less_Suc)\n       moreover have \"(take (Suc (Suc m)) (snd (clist!i)))!(Suc m) = (snd (clist!i))!(Suc m)\" \n         by fastforce      \n       ultimately show ?thesis using sucm_not_fault by fastforce\n     qed\n     then have \" (Suc m < length (snd (clist ! i)) ) \\<longrightarrow>\n                 (\\<Gamma>\\<turnstile>\\<^sub>c (snd (clist ! i)) ! m \\<rightarrow> (snd (clist ! i)) ! Suc m) \\<longrightarrow>                      \n                    (snd ((snd (clist ! i)) ! m), snd ((snd (clist ! i)) ! Suc m)) \\<in> Guar(xs!i)\"\n       using comm_dest [OF comm not_fault] by auto     \n     then have \"False\" using fst_occ using a7 unfolding conjoin_def same_length_def by fastforce\n  } thus ?thesis by fastforce\nqed\n\nlemma par_cptn_env_comp:\n  \"(\\<Gamma>,l) \\<in> par_cptn \\<and> Suc i<length l \\<Longrightarrow> \n   \\<Gamma>\\<turnstile>\\<^sub>p l!i \\<rightarrow>\\<^sub>e (l!(Suc i)) \\<or> \\<Gamma> \\<turnstile>\\<^sub>p l!i \\<rightarrow> (l!(Suc i))\"\nproof -\n  assume a0:\"(\\<Gamma>,l) \\<in> par_cptn \\<and> Suc i<length l\"         \n  then obtain c1 s1 c2 s2 where li:\"l!i=(c1,s1) \\<and> l!(Suc i) = (c2,s2)\"  by fastforce\n  obtain xs ys where l:\"l= xs@((l!i)#(l!(Suc i))#ys)\" using a0\n    by (metis Cons_nth_drop_Suc Suc_less_SucD id_take_nth_drop less_SucI)\n  moreover then have \"(drop (length xs) l) = ((l!i)#(l!(Suc i))#ys)\"\n    by (metis append_eq_conv_conj) \n  moreover then have \"length xs < length l\" using leI by fastforce \n  ultimately have \"(\\<Gamma>,((l!i)#(l!(Suc i))#ys))\\<in>par_cptn\" \n    using a0 droppar_cptn_is_par_cptn by fastforce\n  also then have \"(\\<Gamma>,(l!(Suc i))#ys)\\<in>par_cptn\" using par_cptn_dest li by fastforce\n  ultimately show ?thesis using li par_cptn_elim_cases(2)\n    by metis\nqed\n\n\nlemma three:\n  \"\\<lbrakk>xs\\<noteq>[]; \\<forall>i<length xs. R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n       \\<subseteq> (Rely (xs ! i));\n   p \\<subseteq> (\\<Inter>i<length xs. (Pre (xs ! i)));\n   \\<forall>i<length xs.\n     \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)];\n   length xs=length clist; (\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s; (\\<Gamma>,l) \\<in> par_assum(p, R);\n    \\<forall>i<length clist. clist!i\\<in>cp \\<Gamma> (Com(xs!i)) s; (\\<Gamma>,l) \\<propto> clist; (\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]);\n    snd (last l) \\<notin> Fault ` F\\<rbrakk>\n  \\<Longrightarrow> \\<forall>j i. i<length clist \\<and> Suc j<length l \\<longrightarrow>  \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>\\<^sub>e  ((snd (clist!i))!Suc j) \\<longrightarrow>\n      (snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in>            \n             (R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j))))\"\nproof -\n assume a0:\"xs\\<noteq>[]\" and\n        a1:\"\\<forall>i<length xs. R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n             \\<subseteq> (Rely (xs ! i))\" and\n        a2: \"p \\<subseteq> (\\<Inter>i<length xs.  (Pre (xs ! i)))\" and\n        a3: \"\\<forall>i<length xs.\n               \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)]\" and\n        a4: \"length xs=length clist\" and\n        a5: \"(\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s\" and\n        a6: \"(\\<Gamma>,l) \\<in> par_assum(p, R)\" and\n        a7: \"\\<forall>i<length clist. clist!i\\<in>cp \\<Gamma> (Com(xs!i)) s\" and\n        a8: \"(\\<Gamma>,l) \\<propto> clist\" and\n        a9: \"(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a])\" and\n        10: \"snd (last l) \\<notin> Fault ` F\" \n  {\n  fix j i ns ns'\n  assume a00:\"i<length clist \\<and> Suc j<length l\" and\n         a11: \"\\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>\\<^sub>e  ((snd (clist!i))!Suc j)\"         \n  then have two:\"\\<forall>j i ns ns'. i<length clist \\<and> Suc j<length l \\<longrightarrow> \n      \\<Gamma>\\<turnstile>\\<^sub>c((snd (clist!i))!j) \\<rightarrow>  ((snd (clist!i))!Suc j) \\<longrightarrow>      \n        (snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in> (Guar(xs!i))\"\n     using two[OF a1 a2 a3 a4 a5 a6 a7 a8 a9 10] by auto\n  then have j_lenl:\"Suc j<length l\" using a00 by fastforce\n  have i_lj:\"i<length (fst (l!j)) \\<and> i<length (fst (l!(Suc j)))\" \n            using conjoin_same_length a00 a8 by fastforce \n  have fst_clist_\\<Gamma>:\"\\<forall>i<length clist. fst(clist!i) = \\<Gamma>\" using a8 unfolding conjoin_def same_functions_def by fastforce\n  have \"(\\<Gamma>\\<turnstile>\\<^sub>p(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> \n            (\\<exists>i<length clist. \n               ((fst (clist!i))\\<turnstile>\\<^sub>c ((snd (clist!i))!j)  \\<rightarrow> ((snd (clist!i))!(Suc j))) \\<and> \n            (\\<forall>l<length clist. \n               l\\<noteq>i \\<longrightarrow>  (fst (clist!l))\\<turnstile>\\<^sub>c (snd (clist!l))!j  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc j)))) \\<or> \n         (\\<Gamma>\\<turnstile>\\<^sub>p(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)) \\<and> \n          (\\<forall>i<length clist.  (fst (clist!i))\\<turnstile>\\<^sub>c (snd (clist!i))!j  \\<rightarrow>\\<^sub>e ((snd (clist!i))!(Suc j))))\"\n  using a8 a00 unfolding conjoin_def compat_label_def by simp\n  then have compat_label:\"(\\<Gamma>\\<turnstile>\\<^sub>p(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> \n            (\\<exists>i<length clist. \n               (\\<Gamma>\\<turnstile>\\<^sub>c ((snd (clist!i))!j)  \\<rightarrow> ((snd (clist!i))!(Suc j))) \\<and> \n            (\\<forall>l<length clist. \n               l\\<noteq>i \\<longrightarrow>  \\<Gamma>\\<turnstile>\\<^sub>c (snd (clist!l))!j  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc j)))) \\<or> \n         (\\<Gamma>\\<turnstile>\\<^sub>p(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)) \\<and> \n          (\\<forall>i<length clist.  \\<Gamma>\\<turnstile>\\<^sub>c (snd (clist!i))!j  \\<rightarrow>\\<^sub>e ((snd (clist!i))!(Suc j))))\"\n  using fst_clist_\\<Gamma> by blast\n  then have \"(snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in>            \n               (R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. Guar (xs ! j)))\" \n  proof        \n    assume a10:\"(\\<Gamma>\\<turnstile>\\<^sub>p(l!j)  \\<rightarrow> (l!(Suc j))) \\<and> \n            (\\<exists>i<length clist. \n               (\\<Gamma>\\<turnstile>\\<^sub>c ((snd (clist!i))!j)  \\<rightarrow> ((snd (clist!i))!(Suc j))) \\<and> \n            (\\<forall>l<length clist. \n               l\\<noteq>i \\<longrightarrow>  \\<Gamma>\\<turnstile>\\<^sub>c (snd (clist!l))!j  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc j))))\" \n    then obtain i' where \n            a20:\"i'<length clist \\<and> \n             (\\<Gamma>\\<turnstile>\\<^sub>c ((snd (clist!i'))!j)  \\<rightarrow> ((snd (clist!i'))!(Suc j))) \\<and> \n             (\\<forall>l<length clist. \n                l\\<noteq>i' \\<longrightarrow>  \\<Gamma>\\<turnstile>\\<^sub>c (snd (clist!l))!j  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc j)))\" by blast    \n    thus ?thesis \n    proof (cases \"i'=i\")\n      case True note eq_i = this      \n      then obtain P S1 S2 where P:\"(snd (clist!i'))!j=(P,S1) \\<and> ((snd (clist!i'))!(Suc j)) = (P,S2)\"   \n        using a11 by (fastforce elim:etranE)       \n      thus ?thesis \n      proof (cases \"S1 = S2\")\n        case True \n        have snd_lj:\"(snd (l!j)) = snd ((snd (clist!i'))!j)\"\n            using a8 a20 a00 unfolding conjoin_def same_state_def\n            by fastforce     \n        have all_e:\"(\\<forall>l<length clist. \\<Gamma>\\<turnstile>\\<^sub>c (snd (clist!l))!j  \\<rightarrow>\\<^sub>e ((snd (clist!l))!(Suc j)))\"\n          using a11 a20 eq_i by fastforce\n        then have allP:\"\\<forall>l< length clist. fst ((snd (clist!l))!j) = fst ((snd (clist!l))!(Suc j))\"\n           by (fastforce elim:etranE)\n        then have \"fst (l!j) = (fst (l!(Suc j)))\"\n          using a8 conjoin_same_program_i_j [of \"(\\<Gamma>,l)\"] a00 by fastforce\n        also have \"snd (l!j) = snd (l!(Suc j))\"\n        proof -              \n          have \"(snd (l!Suc j)) = snd ((snd (clist!i'))!(Suc j))\"\n            using a8 a20 a00 unfolding conjoin_def same_state_def\n            by fastforce\n          then show ?thesis using snd_lj P True by auto\n        qed \n        ultimately have \"l!j = l!(Suc j)\" by (simp add: prod_eq_iff) \n        moreover have ns1:\"\\<exists>ns1. S1=Normal ns1\" \n          using P a20 step_change_p_or_eq_s by fastforce                    \n        ultimately have \"\\<Gamma>\\<turnstile>\\<^sub>p(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j))\" \n          using P step_pe.ParEnv snd_lj by (metis prod.collapse snd_conv)          \n        then have \"(snd (l ! j), snd (l ! Suc j)) \\<in> R \"\n          using a00 a6 unfolding par_assum_def by fastforce\n        then show ?thesis using a8 a00 \n          unfolding conjoin_def same_state_def  \n         by fastforce\n      next\n        case False thus ?thesis \n          using a20 P a11 step_change_p_or_eq_s by fastforce\n      qed\n    next\n      case False \n      have i'_clist:\"i' < length clist\" using a20 by fastforce\n      then have clist_i'_Guardxs:\"(snd((snd (clist!i'))!j), snd((snd (clist!i'))!Suc j)) \\<in> Guar(xs!i')\"\n        using two a00 False a8 unfolding conjoin_def same_state_def\n        by (metis a20)\n      have \"snd((snd (clist!i))!j) = snd (l!j) \\<and> snd((snd (clist!i))!Suc j) = snd (l!Suc j)\" \n        using a00 a20 a8 unfolding conjoin_def same_state_def by fastforce\n      also have \"snd((snd (clist!i'))!j) = snd (l!j) \\<and> snd((snd (clist!i'))!Suc j) = snd (l!Suc j)\"\n        using j_lenl a20 a8 unfolding conjoin_def same_state_def by fastforce\n      ultimately have \"snd((snd (clist!i))!j) = snd((snd (clist!i'))!j) \\<and> \n                    snd((snd (clist!i))!Suc j) = snd((snd (clist!i'))!Suc j)\" \n      by fastforce\n      then have clist_i_Guardxs:\n        \"(snd((snd (clist!i))!j), snd((snd (clist!i))!Suc j)) \\<in> \n            Guar(xs!i')\"  \n      using  clist_i'_Guardxs by fastforce      \n      thus ?thesis  \n        using False a20  a4 by fastforce        \n    qed\n  next\n    assume a10:\"(\\<Gamma>\\<turnstile>\\<^sub>p(l!j)  \\<rightarrow>\\<^sub>e (l!(Suc j)) \\<and> \n          (\\<forall>i<length clist.  \\<Gamma>\\<turnstile>\\<^sub>c (snd (clist!i))!j  \\<rightarrow>\\<^sub>e ((snd (clist!i))!(Suc j))))\"      \n    then have \"(snd (l ! j), snd (l ! Suc j)) \\<in> R\"\n      using a00 a10 a6 unfolding par_assum_def by fastforce\n    then show ?thesis using a8 a00 \n      unfolding conjoin_def same_state_def\n      by fastforce\n  qed\n  }  thus ?thesis by blast\nqed\n\ndefinition tran_True where \"tran_True \\<equiv> True\"\n\ndefinition after where \"after \\<equiv> True\"\n\nlemma four:\n  \"\\<lbrakk>xs\\<noteq>[];  \\<forall>i<length xs.  R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n       \\<subseteq>  (Rely (xs ! i));\n   (\\<Union>j<length xs.  (Guar (xs ! j))) \\<subseteq> (G);\n   p \\<subseteq> (\\<Inter>i<length xs.  (Pre (xs ! i)));\n   \\<forall>i<length xs.\n     \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i),  Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)];\n    (\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s; (\\<Gamma>,l) \\<in> par_assum(p, R); Suc i < length l;\n   \\<Gamma>\\<turnstile>\\<^sub>p (l!i) \\<rightarrow> (l!(Suc i));\n   (\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]);\n   snd (last l) \\<notin> Fault ` F\\<rbrakk>\n  \\<Longrightarrow> (snd (l ! i), snd (l ! Suc i)) \\<in> G\"\nproof -\n  assume a0:\"xs\\<noteq>[]\" and\n         a1:\"\\<forall>i<length xs.  R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n             \\<subseteq>  (Rely (xs ! i))\" and\n         a2:\"(\\<Union>j<length xs.  (Guar (xs ! j))) \\<subseteq> (G)\" and\n         a3:\"p \\<subseteq> (\\<Inter>i<length xs.  (Pre (xs ! i)))\" and\n         a4:\"\\<forall>i<length xs.\n           \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i),  Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)]\" and\n         a5:\"(\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s\" and\n         a6:\"(\\<Gamma>,l) \\<in> par_assum(p, R)\" and\n         a7: \"Suc i < length l\" and\n         a8:\"\\<Gamma>\\<turnstile>\\<^sub>p (l!i) \\<rightarrow> (l!(Suc i))\" and         \n         a10:\"(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a])\" and\n         a11:\"snd (last l) \\<notin> Fault ` F\"\n   have length_par_xs:\"length (ParallelCom xs) = length xs\" unfolding ParallelCom_def  by fastforce   \n   then have \"(ParallelCom xs)\\<noteq>[]\" using a0 by fastforce \n   then have \"(\\<Gamma>,l) \\<in>{(\\<Gamma>1,c). \\<exists>clist. (length clist)=(length (ParallelCom xs)) \\<and> \n               (\\<forall>i<length clist. (clist!i) \\<in> cp \\<Gamma> ((ParallelCom xs)!i) s) \\<and> (\\<Gamma>,c) \\<propto> clist \\<and> \\<Gamma>1=\\<Gamma>}\"\n     using one a5 by fastforce\n   then obtain clist where \"(length clist)=(length xs) \\<and> \n               (\\<forall>i<length clist. (clist!i) \\<in> cp \\<Gamma> ((ParallelCom xs)!i) s) \\<and> (\\<Gamma>,l) \\<propto> clist\"\n     using length_par_xs by auto\n   then have conjoin:\"(length clist)=(length xs) \\<and> \n               (\\<forall>i<length clist. (clist!i) \\<in> cp \\<Gamma>  (Com (xs ! i)) s) \\<and> (\\<Gamma>,l) \\<propto> clist\"\n     using ParallelCom_Com by fastforce\n   then have length_xs_clist:\"length xs = length clist\" by auto \n   have clist_cp:\"\\<forall>i<length clist. (clist!i) \\<in> cp \\<Gamma>  (Com (xs ! i)) s\" using conjoin by auto\n   have conjoin:\"(\\<Gamma>,l) \\<propto> clist\" using conjoin by auto     \n   have l_not_empty:\"l\\<noteq>[]\" using a5 par_cptn.simps unfolding par_cp_def by fastforce\n   then have l_g0:\"0<length l\" by fastforce  \n   then have last_l:\"last l = l!((length l) - 1)\" by (simp add: last_conv_nth)    \n   have \"\\<forall>i< length l. fst (l!i) = map (\\<lambda>x. fst ((snd x)!i)) clist\"\n     using conjoin unfolding conjoin_def same_program_def by fastforce\n   obtain Ps si Ps' ssi where li:\"l!i = (Ps,si) \\<and> l!(Suc i) = (Ps', ssi)\" by fastforce\n   then have \"\\<exists>j r. j<length Ps \\<and> Ps' = Ps[j:=r] \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c((Ps!j),si) \\<rightarrow> (r, ssi))\" \n     using a8 par_ctranE by fastforce\n   then obtain j r where step_c:\"j<length Ps \\<and> Ps' = Ps[j:=r] \\<and> (\\<Gamma>\\<turnstile>\\<^sub>c((Ps!j),si) \\<rightarrow> (r, ssi))\"\n     by auto   \n   have length_Ps_clist:\n     \"length Ps = length clist \\<and> length Ps = length Ps'\" \n     using conjoin a7 conjoin_same_length li step_c by fastforce\n   have from_step:\"(snd (clist!j))!i = ((Ps!j),si) \\<and> (snd (clist!j))!(Suc i) = (Ps'!j,ssi)\"  \n   proof -     \n     have f2: \"Ps = fst (snd (\\<Gamma>, l) ! i)\" and f2':\"Ps' = fst (snd (\\<Gamma>, l) ! (Suc i))\"\n       using li by auto\n     have f3:\"si = snd (snd (\\<Gamma>, l) ! i) \\<and> ssi = snd (snd (\\<Gamma>, l) ! (Suc i))\"\n       by (simp add: li)\n     then have \"(snd (clist!j))!i = ((Ps!j),si)\"\n       using f2 conjoin a7 step_c unfolding conjoin_def same_program_def same_state_def by force     \n     moreover have \"(snd (clist!j))!(Suc i) = (Ps'!j,ssi)\"\n       using f2' f3 conjoin a7 step_c length_Ps_clist \n      unfolding conjoin_def same_program_def same_state_def \n       by auto\n     ultimately show ?thesis by auto\n   qed      \n   then have step_clist:\"\\<Gamma>\\<turnstile>\\<^sub>c(snd (clist!j))!i \\<rightarrow> (snd (clist!j))!(Suc i)\" \n     using from_step  step_c by fastforce\n   have j_xs:\"j<length xs\" using step_c length_Ps_clist length_xs_clist by auto\n   have \"j<length clist\" using j_xs length_xs_clist by auto    \n   also have \n     \"\\<forall>i j ns ns'. j < length clist \\<and> Suc i < length l \\<longrightarrow>\n            \\<Gamma>\\<turnstile>\\<^sub>c snd (clist ! j) ! i \\<rightarrow> snd (clist ! j) ! Suc i \\<longrightarrow>             \n              (snd (snd (clist ! j) ! i), snd (snd (clist ! j) ! Suc i)) \\<in> Guar (xs ! j)\"\n    using two[OF a1 a3 a4 length_xs_clist a5 a6 clist_cp conjoin a10 a11] by auto\n   ultimately have \"(snd (snd (clist ! j) ! i), snd (snd (clist ! j) ! Suc i)) \\<in> Guar (xs ! j)\"\n     using a7 step_c length_Ps_clist step_clist by metis     \n   then have \"(snd (l!i), snd (l!(Suc i)))\\<in> Guar (xs ! j)\"\n      using from_step a2 length_xs_clist step_c li by fastforce\n   then show ?thesis using a2 j_xs\n     unfolding sep_conj_def tran_True_def after_def Satis_def by fastforce\nqed\n\nlemma same_program_last:\"l\\<noteq>[] \\<Longrightarrow> (\\<Gamma>,l) \\<propto> clist  \\<Longrightarrow> i<length clist \\<Longrightarrow>fst (last (snd (clist!i))) = fst (last l) ! i\" \nproof -\n   assume l_not_empty:\"l\\<noteq>[]\" and\n          conjoin: \"(\\<Gamma>,l) \\<propto> clist\" and\n          i_clist: \"i<length clist\"\n   have last_clist_eq_l:\"\\<forall>i<length clist. last (snd (clist!i)) = (snd (clist!i))!((length l) - 1)\"\n          using conjoin  last_conv_nth l_not_empty \n          unfolding conjoin_def same_length_def\n          by (metis length_0_conv snd_eqD) \n   then have last_l:\"last l = l!((length l)-1)\" using l_not_empty by (simp add: last_conv_nth)\n   have \"fst (last l) = map (\\<lambda>x. fst (snd x ! ((length l)-1))) clist\"\n     using l_not_empty last_l conjoin unfolding conjoin_def same_program_def  by auto\n   also have \"(map (\\<lambda>x. fst (snd x ! ((length l)-1))) clist)!i = \n            fst ((snd (clist!i))! ((length l)-1))\" using i_clist by fastforce\n   also have  \"fst ((snd (clist!i))! ((length l)-1)) = \n             fst ((snd (clist!i))! ((length (snd (clist!i)))-1))\" \n     using conjoin i_clist unfolding conjoin_def same_length_def by fastforce\n   also then have \"fst ((snd (clist!i))! ((length (snd (clist!i)))-1)) = fst (last (snd (clist!i)))\"\n     using i_clist l_not_empty conjoin last_clist_eq_l last_conv_nth unfolding conjoin_def same_length_def\n     by presburger\n   finally show ?thesis by auto\nqed\n\n\n\nlemma five:\n  \"\\<lbrakk>xs\\<noteq>[];  \\<forall>i<length xs.  R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n       \\<subseteq> (Rely (xs ! i));\n   p \\<subseteq> (\\<Inter>i<length xs. (Pre (xs ! i)));\n   (\\<Inter>i<length xs. (Post (xs ! i))) \\<subseteq> q;\n   (\\<Union>i<length xs. (Abr (xs ! i))) \\<subseteq> a ;\n   \\<forall>i < length xs.\n    \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)];\n    (\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s; (\\<Gamma>,l) \\<in> par_assum(p, R);\n   All_End (last l); snd (last l) \\<notin> Fault ` F;(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a]) \\<rbrakk> \\<Longrightarrow> \n                   (\\<exists>j<length (fst (last l)). fst (last l)!j=Throw \\<and> \n                        snd (last l) \\<in> Normal ` (a)) \\<or>\n                   (\\<forall>j<length (fst (last l)). fst (last l)!j=Skip \\<and>\n                        snd (last l) \\<in> Normal ` q)\"\nproof-\n  assume a0:\"xs\\<noteq>[]\" and \n         a1:\"\\<forall>i<length xs.  R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n                                                                     \\<subseteq>  (Rely (xs ! i))\" and\n         a2:\"p \\<subseteq> (\\<Inter>i<length xs. (Pre (xs ! i)))\" and\n         a3:\"(\\<Inter>i<length xs. (Post (xs ! i))) \\<subseteq> q\" and\n         a4:\"(\\<Union>i<length xs. (Abr (xs ! i))) \\<subseteq> a\" and\n         a5:\"\\<forall>i < length xs.\n               \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub>  Com (xs ! i) sat [Pre (xs!i), \n                                             Rely (xs ! i), Guar (xs ! i), \n                                             Post (xs ! i),Abr (xs ! i)]\" and\n         a6:\"(\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s\" and\n         a7:\"(\\<Gamma>,l) \\<in> par_assum(p, R)\"and\n         a8:\"All_End (last l)\" and\n         a9:\"snd (last l) \\<notin> Fault ` F\" and\n         a10:\"(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a])\"\n   have length_par_xs:\"length (ParallelCom xs) = length xs\" unfolding ParallelCom_def  by fastforce   \n   then have \"(ParallelCom xs)\\<noteq>[]\" using a0 by fastforce\n   then have \"(\\<Gamma>,l) \\<in>{(\\<Gamma>1,c). \\<exists>clist. (length clist)=(length (ParallelCom xs)) \\<and> \n               (\\<forall>i<length clist. (clist!i) \\<in> cp \\<Gamma> ((ParallelCom xs)!i) s) \\<and> (\\<Gamma>,c) \\<propto> clist \\<and> \\<Gamma>1=\\<Gamma>}\"\n     using one a6 by fastforce\n   then obtain clist where \"(length clist)=(length xs) \\<and> \n               (\\<forall>i<length clist. (clist!i) \\<in> cp \\<Gamma> ((ParallelCom xs)!i) s) \\<and> (\\<Gamma>,l) \\<propto> clist\"\n     using length_par_xs by auto\n   then have conjoin:\"(length clist)=(length xs) \\<and> \n               (\\<forall>i<length clist. (clist!i) \\<in> cp \\<Gamma>  (Com (xs ! i)) s) \\<and> (\\<Gamma>,l) \\<propto> clist\"\n     using ParallelCom_Com by fastforce\n   then have length_xs_clist:\"length xs = length clist\" by auto\n   (*have length_l_clist: \"length l = length clist\" \n     using conjoin unfolding conjoin_def same_length_def *)\n   have clist_cp:\"\\<forall>i<length clist. (clist!i) \\<in> cp \\<Gamma>  (Com (xs ! i)) s\" using conjoin by auto\n   have conjoin:\"(\\<Gamma>,l) \\<propto> clist\" using conjoin by auto\n   have l_not_empty:\"l\\<noteq>[]\" using a6 par_cptn.simps unfolding par_cp_def by fastforce\n   then have l_g0:\"0<length l\" by fastforce  \n   then have last_l:\"last l = l!((length l) - 1)\" by (simp add: last_conv_nth) \n   have clist_assum:\"\\<forall>i<length clist. (clist!i) \\<in> assum (Pre (xs!i),Rely (xs!i))\"     \n   proof -\n   { fix i\n     assume i_length:\"i<length clist\"\n     obtain \\<Gamma>1 li where clist:\"clist!i=(\\<Gamma>1,li)\" by fastforce    \n     then have \\<Gamma>eq:\"\\<Gamma>1=\\<Gamma>\" \n       using conjoin i_length unfolding conjoin_def same_functions_def by fastforce\n     have \"(\\<Gamma>1,li) \\<in> assum (Pre (xs!i),Rely (xs!i))\"\n     proof-\n       have l:\"snd (li!0) \\<in> Normal ` ( (Pre (xs!i)))\"\n       proof -  \n         have snd_l:\"snd (\\<Gamma>,l) = l\" by fastforce       \n         have \"snd (l!0) \\<in> Normal ` (p)\" \n         using a7 unfolding par_assum_def by fastforce         \n         also have \"snd (l!0) = snd (li!0)\"           \n           using i_length conjoin l_g0 clist \n           unfolding conjoin_def same_state_def by fastforce\n         finally show ?thesis using a2 i_length length_xs_clist\n            by auto \n       qed              \n       have r:\"(\\<forall>j. Suc j < length li \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>\\<^sub>c(li!j)  \\<rightarrow>\\<^sub>e (li!(Suc j)) \\<longrightarrow>                 \n                    (snd(li!j), snd(li!(Suc j))) \\<in> Rely (xs!i))\"        \n         using three[OF a0 a1 a2 a5 length_xs_clist a6 a7 clist_cp conjoin a10 a9]  \n               i_length conjoin a1 length_xs_clist clist                     \n         unfolding assum_def conjoin_def same_length_def by fastforce                                   \n       show ?thesis using l r \\<Gamma>eq unfolding assum_def by fastforce\n     qed \n     then have \"clist!i \\<in> assum (Pre (xs!i),Rely (xs!i))\" using clist by auto            \n   } thus ?thesis by auto\n   qed\n   then have clist_com:\"\\<forall>i<length clist. (clist!i) \\<in> comm  (Guar (xs!i),(Post(xs!i),Abr (xs!i))) F\"\n     using a5 unfolding com_cvalidity_def \n     using a10 unfolding com_validity_def using clist_cp length_xs_clist\n     by force              \n   have last_clist_eq_l:\"\\<forall>i<length clist. last (snd (clist!i)) = (snd (clist!i))!((length l) - 1)\"\n     using conjoin  last_conv_nth l_not_empty \n     unfolding conjoin_def same_length_def\n     by (metis length_0_conv snd_eqD) \n   then have last_clist_l:\"\\<forall>i<length clist. snd (last (snd (clist!i))) = snd (last l)\"\n     using last_l conjoin l_not_empty unfolding conjoin_def same_state_def same_length_def \n     by simp\n   show ?thesis\n   proof(cases \"\\<forall>i<length (fst (last l)). fst (last l)!i = Skip\")\n     assume ac1:\"\\<forall>i<length (fst (last l)). fst (last l)!i = Skip\"\n     have \"(\\<forall>j<length (fst (last l)). fst (last l) ! j = LanguageCon.com.Skip \\<and> snd (last l) \\<in> Normal ` q)\"\n     proof -\n       {fix j\n        assume aj:\"j<length (fst (last l))\"         \n        have \"\\<forall>i<length clist. snd (last (snd (clist!i))) \\<in> Normal ` Post(xs!i)\"\n        proof-\n          {fix i \n           assume a20:\"i<length clist\"\n           then have snd_last:\"snd (last (snd (clist!i))) = snd (last l)\" \n             using last_clist_l by fastforce\n           have last_clist_not_F:\"snd (last (snd (clist!i)))\\<notin> Fault ` F\"\n              using a9 last_clist_l a20 by fastforce\n           have \"fst (last l) ! i = Skip\" \n             using a20 ac1 conjoin_same_length[OF conjoin]\n             by (simp add: l_not_empty last_l )                       \n           also have \"fst (last l) ! i=fst (last (snd (clist!i)))\"\n             using same_program_last[OF l_not_empty conjoin a20]  by auto\n           finally have \"fst (last (snd (clist!i))) = Skip\" .\n           then have \"snd (last (snd (clist!i))) \\<in> Normal ` Post(xs!i)\" \n             using clist_com last_clist_not_F a20\n             unfolding comm_def final_def by fastforce\n          }  thus ?thesis by auto \n        qed             \n        then have \"\\<forall>i<length xs. snd (last l) \\<in> Normal ` Post(xs!i)\" \n          using last_clist_l length_xs_clist by fastforce\n        then have \"\\<forall>i<length xs. \\<exists>x\\<in>( Post(xs!i)). snd (last l) = Normal x\"\n          by fastforce\n        moreover have \"\\<forall>t. (\\<forall>i<length xs. t\\<in> Post (xs ! i))\\<longrightarrow> t\\<in> q\" using a3\n          by fastforce        \n        ultimately have \"(\\<exists>x\\<in> q. snd (last l) = Normal x)\" using a0\n           by (metis (mono_tags, lifting) length_greater_0_conv xstate.inject(1)) \n        then have \"snd (last l) \\<in> Normal ` q\" by fastforce          \n        then have \"fst (last l) ! j = LanguageCon.com.Skip \\<and> snd (last l) \\<in> Normal ` q\"\n          using aj ac1 by fastforce\n        } thus ?thesis by auto\n     qed      \n     thus ?thesis by auto\n   next\n     assume \"\\<not> (\\<forall>i<length (fst (last l)). fst (last l)!i = Skip)\"    \n     then obtain i where a20:\"i< length (fst (last l)) \\<and>  fst (last l)!i \\<noteq> Skip\" \n       by fastforce\n     then have last_i_throw:\"fst (last l)!i = Throw \\<and> (\\<exists>n. snd (last l) = Normal n)\" \n       using a8 unfolding All_End_def final_def by fastforce     \n     have \"length (fst (last l)) =  length clist\" \n       using conjoin_same_length[OF conjoin] l_not_empty last_l\n       by simp\n     then have i_length:\"i<length clist\" using a20 by fastforce\n     then have snd_last:\"snd (last (snd (clist!i))) = snd (last l)\" \n       using last_clist_l by fastforce\n     have last_clist_not_F:\"snd (last (snd (clist!i)))\\<notin> Fault ` F\"\n       using a9 last_clist_l i_length by fastforce\n     then have \"fst (last (snd (clist!i))) = fst (last l) ! i\" \n       using i_length same_program_last [OF l_not_empty conjoin] by fastforce\n     then have \"fst (last (snd (clist!i))) = Throw\"\n       using last_i_throw by fastforce\n     then have \"snd (last (snd (clist!i))) \\<in> Normal `  Abr(xs!i)\" \n       using clist_com last_clist_not_F i_length last_i_throw snd_last\n       unfolding comm_def final_def by fastforce\n     then have \"snd (last l)\\<in> Normal ` Abr(xs!i)\" using last_clist_l i_length\n       by fastforce\n     then have \"snd (last l)\\<in> Normal ` (a)\" using a4 a0 i_length length_xs_clist by fastforce\n     then have \"\\<exists>j<length (fst (last l)).\n        fst (last l) ! j = LanguageCon.com.Throw \\<and> snd (last l) \\<in> Normal ` a\"\n     using last_i_throw a20 by fastforce\n     thus ?thesis by auto\n   qed \nqed\n\n\nlemma ParallelEmpty [rule_format]:\n  \"\\<forall>i s. (\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom []) s \\<longrightarrow>\n  Suc i < length l \\<longrightarrow> \\<not> (\\<Gamma> \\<turnstile>\\<^sub>p (l!i) \\<rightarrow> (l!Suc i))\"\napply(induct_tac l)\n apply simp\napply clarify\napply(case_tac list,simp,simp)\napply(case_tac i)\n apply(simp add:par_cp_def ParallelCom_def) \n apply(erule par_ctranE,simp)\napply(simp add:par_cp_def ParallelCom_def)\napply clarify\napply(erule par_cptn.cases,simp)\n apply simp\nby (metis list.inject list.size(3) not_less0 step_p_pair_elim_cases)\n\nlemma ParallelEmpty2:\n  assumes a0:\"(\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom []) s\" and\n         a1: \"i < length l\" \n  shows \"fst (l!i) = []\"\nproof -\n  have paremp:\"ParallelCom [] = []\" unfolding ParallelCom_def by auto\n  then have l0:\"l!0 =([],s)\" using a0 unfolding par_cp_def by auto\n  then have \"(\\<Gamma>,l) \\<in> par_cptn\" using a0 unfolding par_cp_def by fastforce\n  thus ?thesis using l0 a1\n  proof (induct arbitrary: i s) \n    case ParCptnOne thus ?case by auto\n  next\n    case (ParCptnEnv \\<Gamma> P s1 t xs i s)\n    thus ?case\n    proof -\n      have f1: \"i < Suc (Suc (length xs))\"\n        using ParCptnEnv.prems(2) by auto\n      have \"(P, s1) = ([], s)\"\n        using ParCptnEnv.prems(1) by auto\n      then show ?thesis\n        using f1 by (metis (no_types) ParCptnEnv.hyps(3) diff_Suc_1 fst_conv length_Cons less_Suc_eq_0_disj nth_Cons')\n    qed    \n  next\n    case (ParCptnComp \\<Gamma> P s1 Q t xs)   \n    have \"(\\<Gamma>, (P,s1)#(Q, t) # xs) \\<in> par_cp \\<Gamma> (ParallelCom []) s1\" \n        using ParCptnComp(4) ParCptnComp(1) step_p_elim_cases by fastforce\n    then have \"\\<not> \\<Gamma>\\<turnstile>\\<^sub>p (P, s1) \\<rightarrow> (Q, t)\" using ParallelEmpty ParCptnComp by fastforce\n    thus ?case using ParCptnComp by auto\n  qed\nqed  \n\nlemma parallel_sound: \n  \"\\<forall>i<length xs.\n       R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n       \\<subseteq> (Rely (xs ! i)) \\<Longrightarrow>\n    (\\<Union>j<length xs. (Guar (xs ! j))) \\<subseteq> G \\<Longrightarrow>\n    p \\<subseteq> (\\<Inter>i<length xs. (Pre (xs ! i))) \\<Longrightarrow>\n    (\\<Inter>i<length xs. (Post (xs ! i))) \\<subseteq> q \\<Longrightarrow>\n    (\\<Union>i<length xs. (Abr (xs ! i))) \\<subseteq> a \\<Longrightarrow>    \n    \\<forall>i<length xs.\n       \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> Com (xs !i) sat [Pre (xs !i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)] \\<Longrightarrow>\n  \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> ParallelCom xs SAT [p, R, G, q,a]\n  \"\nproof -\n  assume \n  a0:\"\\<forall>i<length xs.\n      R \\<union> (\\<Union>j\\<in>{j. j < length xs \\<and> j \\<noteq> i}. (Guar (xs ! j)))\n       \\<subseteq>  (Rely (xs ! i))\" and\n   a1:\"(\\<Union>j<length xs.  (Guar (xs ! j))) \\<subseteq> G\" and\n   a2:\"p \\<subseteq> (\\<Inter>i<length xs.  (Pre (xs ! i)))\" and\n   a3:\"(\\<Inter>i<length xs.  (Post (xs ! i))) \\<subseteq> q\" and\n   a4:\"(\\<Union>i<length xs.  (Abr (xs ! i))) \\<subseteq> a\" and\n   a5:\"\\<forall>i<length xs.\n            \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> Com (xs !i) sat [Pre (xs !i), Rely (xs ! i), Guar (xs ! i), Post (xs ! i),Abr (xs ! i)]\"\n  { \n     assume a00:\"(\\<forall>(c,p,R,G,q,a)\\<in> \\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (Call c) sat [p, R, G, q,a])\"\n     { fix s l\n       assume a10: \"(\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s \\<and> (\\<Gamma>,l) \\<in> par_assum(p, R)\"       \n       then have c_par_cp:\"(\\<Gamma>,l) \\<in> par_cp \\<Gamma> (ParallelCom xs) s\" by auto\n       have c_par_assum: \"(\\<Gamma>,l) \\<in> par_assum(p, R)\" using a10 by auto\n       { fix i ns ns'\n         assume a20:\"snd (last l) \\<notin> Fault ` F\"\n         {\n            assume a30:\"Suc i<length l\"  and\n                   a31: \"\\<Gamma>\\<turnstile>\\<^sub>p(l!i)  \\<rightarrow> (l!(Suc i))\"                   \n            have xs_not_empty:\"xs\\<noteq>[]\" \n            proof -\n            {\n              assume \"xs = []\"\n              then have \"\\<not> (\\<Gamma> \\<turnstile>\\<^sub>p (l!i) \\<rightarrow> (l!Suc i))\" \n                using a30 a10 ParallelEmpty by fastforce\n              then have False using a31 by auto\n            } thus ?thesis by auto\n            qed            \n            then have \"(snd(l!i), snd(l!(Suc i))) \\<in>  G\"\n            using four[OF xs_not_empty a0 a1 a2 a5 c_par_cp c_par_assum a30 a31 a00 a20] by blast\n            \n         } then have \"Suc i<length l \\<longrightarrow> \n                     \\<Gamma>\\<turnstile>\\<^sub>p(l!i)  \\<rightarrow> (l!(Suc i)) \\<longrightarrow>                      \n                     (snd(l!i), snd(l!(Suc i))) \\<in> G \" by auto \n            note l = this\n         { assume a30:\"All_End (last l)\"\n           then have xs_not_empty:\"xs\\<noteq>[]\" \n           proof - \n           { assume xs_emp:\"xs=[]\"\n             have lenl:\"0<length l\" using a10 unfolding par_cp_def using par_cptn.simps by fastforce\n             then have \"(length l) - 1 < length l\" by fastforce\n             then have \"fst(l!((length l) - 1)) = []\" using ParallelEmpty2 a10 xs_emp by fastforce\n             then have False using a30 lenl unfolding All_End_def\n               by (simp add: last_conv_nth )              \n           } thus ?thesis by auto\n           qed\n           then have \"(\\<exists>j<length (fst (last l)). fst (last l)!j=Throw \\<and> \n                        snd (last l) \\<in> Normal ` (a)) \\<or>\n                      (\\<forall>j<length (fst (last l)). fst (last l)!j=Skip \\<and>\n                        snd (last l) \\<in> Normal ` q)\"\n           using five[OF xs_not_empty a0 a2 a3 a4 a5 c_par_cp c_par_assum a30 a20 a00] by blast\n         } then have \"All_End (last l) \\<longrightarrow> \n                      (\\<exists>j<length (fst (last l)). fst (last l)!j=Throw \\<and> \n                        snd (last l) \\<in> Normal ` (a)) \\<or>\n                   (\\<forall>j<length (fst (last l)). fst (last l)!j=Skip \\<and>\n                        snd (last l) \\<in> Normal ` q)\" by auto \n           note res1 = conjI[OF l this] \n       }\n       then have  \"(\\<Gamma>,l) \\<in> par_comm(G, (q,a)) F\" unfolding par_comm_def by auto       \n     } \n     then have \"\\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> (ParallelCom xs) SAT [p, R, G, q,a]\" \n       unfolding par_com_validity_def par_cp_def by fastforce\n  } thus ?thesis using par_com_cvalidity_def by fastforce\nqed\n\n\ntheorem  \n par_rgsound:\"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> Ps SAT [p, R, G, q,a] \\<Longrightarrow>\n  \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> (ParallelCom Ps) SAT [p, R, G, q,a]\"\nproof (induction rule:par_rghoare.induct)\n  case (Parallel xs R G p q a \\<Gamma> \\<Theta> F)\n    thus ?case using localRG_sound com_cnvalid_to_cvalid parallel_sound[of xs R G p q a \\<Gamma> \\<Theta> F] \n      by fast\nqed\nlemma Conseq':\"\\<forall>s. s\\<in>p \\<longrightarrow>\n              (\\<exists>p' q' a' R' G'. \n                (\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [(p' Z), (R' Z), (G' Z), (q' Z),(a' Z)]) \\<and>\n                   (\\<exists> Z. s\\<in>p' Z \\<and> (q' Z \\<subseteq> q) \\<and> (a' Z \\<subseteq> a) \\<and> (G' Z \\<subseteq> G) \\<and> (R \\<subseteq> R' Z)))\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q,a]\"\n  apply (rule Conseq)\n  by (meson order_refl)\n\nlemma conseq:\"\\<lbrakk>\\<forall>Z. \\<Gamma>,\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> P sat [(p' Z), (R' Z), (G' Z), (q' Z),(a' Z)]; \\<Theta>' \\<subseteq> \\<Theta> ;\n              \\<forall>s. s \\<in> p \\<longrightarrow> (\\<exists> Z. s\\<in>p' Z \\<and> (q' Z \\<subseteq> q) \\<and> (a' Z \\<subseteq> a) \\<and> (G' Z \\<subseteq> G) \\<and> (R \\<subseteq> R' Z))\\<rbrakk>\n              \\<Longrightarrow>\n               \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q,a]\"\nby (rule Conseq) (meson order_refl)\n\nlemma conseqPrePost[trans]:\n \"\\<Gamma>,\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p', R', G', q',a'] \\<Longrightarrow> \\<Theta>' \\<subseteq> \\<Theta> \\<Longrightarrow>\n  p\\<subseteq>p' \\<Longrightarrow> q' \\<subseteq> q \\<Longrightarrow> a' \\<subseteq> a \\<Longrightarrow> G' \\<subseteq> G \\<Longrightarrow> R \\<subseteq> R' \\<Longrightarrow> \n  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q,a]\"  \nby (rule conseq) auto\n\nlemma conseqPre[trans]:\n \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p', R, G, q,a] \\<Longrightarrow>\n  p\\<subseteq>p' \\<Longrightarrow>\n  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q,a]\"\nby (rule conseq) auto\n\nlemma conseqPost[trans]:\n \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q',a'] \\<Longrightarrow>\n  q'\\<subseteq>q \\<Longrightarrow>  a'\\<subseteq>a \\<Longrightarrow>\n  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q,a]\"\n  by (rule conseq) auto\n  \nlemma shows x:\"\\<exists>(sa'::nat set). (\\<forall>x. (x\\<in> sa) = ((to_nat x) \\<in> sa'))\"\n  by (metis (mono_tags, hide_lams) from_nat_to_nat imageE image_eqI)\n\n\nlemma not_empty_set_countable: \n  assumes a0:\"sa\\<noteq>({}::('a::countable) set)\" \n  shows \"{i. ((\\<lambda>i. i\\<in> sa) o from_nat) i}\\<noteq>{}\"\n  by (metis (full_types) Collect_empty_eq_bot assms comp_apply empty_def equals0I from_nat_to_nat)\n\nlemma eq_set_countable:\"(\\<Inter>i\\<in>{i. ((\\<lambda>i. i\\<in> sa) o from_nat) i}. (q o from_nat) i) = ((\\<Inter>i\\<in>sa. q i))\"     \n  apply auto\n  by (metis (no_types) from_nat_to_nat)\n  \nlemma conj_inter_countable[trans]: \n  assumes a0:\"sa\\<noteq>({}::('a::countable) set)\" and\n          a1:\"\\<forall>i\\<in>sa. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G, q i,a]\"\n  shows\"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G,(\\<Inter>i\\<in>sa. q i),a]\"  \nproof-\n  have \"\\<forall>i\\<in>{i. ((\\<lambda>i. i\\<in> sa) o from_nat) i}. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G,(q o from_nat) i,a]\"    \n    using a1 by auto\n  then have \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^bsub>/F\\<^esub> P sat [p, R, G,\\<Inter>i\\<in>{i. ((\\<lambda>i. i\\<in> sa) o from_nat) i}. (q o from_nat) i,a]\"\n    using Conj_Inter[OF not_empty_set_countable[OF a0]]   by auto    \n  thus ?thesis  using eq_set_countable\n    by metis    \nqed\n  \nlemma all_Post[trans]:\n  assumes a0:\"\\<forall>p_n::('a::countable). \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> C sat [P, R, G, Q p_n, Qa]\" \n  shows\"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> C sat [P, R, G,{s. \\<forall>p_n. s\\<in>Q p_n},Qa]\"      \nproof-  \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> C sat [P, R, G,(\\<Inter>p_n. Q  p_n),Qa]\"\n     using a0 conj_inter_countable[of UNIV]  by auto \n  moreover have s1:\"\\<forall>P. {s. \\<forall>p_n. s\\<in>P p_n} = (\\<Inter>p_n. P p_n)\"\n    by auto   \n  ultimately show ?thesis\n   by (simp add: s1)\nqed    \n  \nlemma all_Pre[trans]:\n  assumes a0:\"\\<forall>p_n. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> C sat [P p_n, R, G, Q, Qa]\" \n  shows\"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> C sat [{s. \\<forall>p_n. s\\<in>P p_n}, R, G,Q,Qa]\"\nproof-\n   {fix p_n     \n    have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> C sat [{s. \\<forall>p_n. s\\<in>P p_n}, R, G,Q,Qa]\" \n    proof-\n      have \"{v. \\<forall>n. v \\<in> P n} \\<subseteq> P p_n\" by force\n      then show ?thesis by (meson a0 LocalRG_HoareDef.conseqPrePost subset_eq)\n    qed\n  } thus ?thesis by auto \nqed\n    \nlemma Pre_Post_all:\n  assumes a0:\"\\<forall>p_n::('a::countable). \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> C sat [P p_n, R, G, Q p_n, Qa]\" \n  shows\"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> C sat [{s. \\<forall>p_n. s\\<in>P p_n}, R, G,{s. \\<forall>p_n. s\\<in>Q p_n},Qa]\"    \nproof-\n  {fix p_n\n     \n    have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> C sat [{s. \\<forall>p_n. s\\<in>P p_n}, R, G,Q p_n,Qa]\" \n    proof-\n      have \"{v. \\<forall>n. v \\<in> P n} \\<subseteq> P p_n\" by force\n      then show ?thesis by (meson a0 LocalRG_HoareDef.conseqPrePost subset_eq)\n    qed\n  }\n  then have f3:\"\\<forall>p_n. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> C sat [{s. \\<forall>p_n. s\\<in>P p_n}, R, G,Q p_n,Qa]\"\n    by auto\n  then have \"\\<forall>p_n. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> C sat [{s. \\<forall>p_n. s\\<in>P p_n}, R, G,{s. \\<forall>p_n. s\\<in>Q p_n},Qa]\"    \n    using all_Post by auto\n  moreover have s1:\"\\<forall>P. {s. \\<forall>p_n. s\\<in>P p_n} = (\\<Inter>p_n. P p_n)\"\n    by auto   \n  ultimately show ?thesis\n   by (simp add: s1)\nqed  \n  \n  \ninductive_cases hoare_elim_skip_cases [cases set]:\n\"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> Skip sat [p, R, G, q,a]\"\n\n\n\n(* abbreviation \n \"stepc_rtrancl\" :: \"[('s,'p,'f,'e) body,('s,'p,'f) config,('s,'p,'f) config] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>c (_ \\<rightarrow>\\<^sup>*/ _)\" [81,81,81] 100)\n where                                \n  \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sup>* cf1 \\<equiv> ((CONST stepc \\<Gamma>))\\<^sup>*\\<^sup>* cf0 cf1\" *)\n\n\nend\n\n", "meta": {"author": "CompSoftVer", "repo": "CSim", "sha": "816d36b7523796ace031c429003d82e9244eff9c", "save_path": "github-repos/isabelle/CompSoftVer-CSim", "path": "github-repos/isabelle/CompSoftVer-CSim/CSim-816d36b7523796ace031c429003d82e9244eff9c/CSimpl/LocalRG_HoareDef.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318337259583, "lm_q2_score": 0.42632159254749036, "lm_q1q2_score": 0.25746918114417666}}
{"text": "(* Author: Pascal Stoop, ETH Zurich\n   Author: Andreas Lochbihler, Digital Asset *)\n\nsection \\<open>Lazy types in generated code\\<close>\n\ntheory Code_Lazy\nimports Case_Converter\nkeywords\n  \"code_lazy_type\"\n  \"activate_lazy_type\"\n  \"deactivate_lazy_type\"\n  \"activate_lazy_types\"\n  \"deactivate_lazy_types\"\n  \"print_lazy_types\" :: thy_decl\nbegin\n\ntext \\<open>\n  This theory and the CodeLazy tool described in @{cite \"LochbihlerStoop2018\"}.\n\n  It hooks into Isabelle's code generator such that the generated code evaluates a user-specified\n  set of type constructors lazily, even in target languages with eager evaluation.\n  The lazy type must be algebraic, i.e., values must be built from constructors and a\n  corresponding case operator decomposes them. Every datatype and codatatype is algebraic\n  and thus eligible for lazification.\n\\<close>\n\nsubsection \\<open>The type \\<open>lazy\\<close>\\<close>\n\ntypedef 'a lazy = \"UNIV :: 'a set\" ..\nsetup_lifting type_definition_lazy\nlift_definition delay :: \"(unit \\<Rightarrow> 'a) \\<Rightarrow> 'a lazy\"  is \"\\<lambda>f. f ()\" .\nlift_definition force :: \"'a lazy \\<Rightarrow> 'a\" is \"\\<lambda>x. x\" .\n\ncode_datatype delay\nlemma force_delay [code]: \"force (delay f) = f ()\" by transfer (rule refl)\nlemma delay_force: \"delay (\\<lambda>_. force s) = s\" by transfer (rule refl)\n\ndefinition termify_lazy2 :: \"'a :: typerep lazy \\<Rightarrow> term\"\n  where \"termify_lazy2 x =\n  Code_Evaluation.App (Code_Evaluation.Const (STR ''Code_Lazy.delay'') (TYPEREP((unit \\<Rightarrow> 'a) \\<Rightarrow> 'a lazy)))\n    (Code_Evaluation.Const (STR ''Pure.dummy_pattern'') (TYPEREP((unit \\<Rightarrow> 'a))))\"\n\ndefinition termify_lazy ::\n  \"(String.literal \\<Rightarrow> 'typerep \\<Rightarrow> 'term) \\<Rightarrow>\n   ('term \\<Rightarrow> 'term \\<Rightarrow> 'term) \\<Rightarrow>\n   (String.literal \\<Rightarrow> 'typerep \\<Rightarrow> 'term \\<Rightarrow> 'term) \\<Rightarrow>\n   'typerep \\<Rightarrow> ('typerep \\<Rightarrow> 'typerep \\<Rightarrow> 'typerep) \\<Rightarrow> ('typerep \\<Rightarrow> 'typerep) \\<Rightarrow>\n   ('a \\<Rightarrow> 'term) \\<Rightarrow> 'typerep \\<Rightarrow> 'a :: typerep lazy \\<Rightarrow> 'term \\<Rightarrow> term\"\n  where \"termify_lazy _ _ _ _ _ _ _ _ x _ = termify_lazy2 x\"\n\ndeclare [[code drop: \"Code_Evaluation.term_of :: _ lazy \\<Rightarrow> _\"]]\n\nlemma term_of_lazy_code [code]:\n  \"Code_Evaluation.term_of x \\<equiv>\n   termify_lazy\n     Code_Evaluation.Const Code_Evaluation.App Code_Evaluation.Abs\n     TYPEREP(unit) (\\<lambda>T U. typerep.Typerep (STR ''fun'') [T, U]) (\\<lambda>T. typerep.Typerep (STR ''Code_Lazy.lazy'') [T])\n     Code_Evaluation.term_of TYPEREP('a) x (Code_Evaluation.Const (STR '''') (TYPEREP(unit)))\"\n  for x :: \"'a :: {typerep, term_of} lazy\"\n  by (rule term_of_anything)\n\ntext \\<open>\n  The implementations of \\<^typ>\\<open>_ lazy\\<close> using language primitives cache forced values.\n\n  Term reconstruction for lazy looks into the lazy value and reconstructs it to the depth it has been evaluated.\n  This is not done for Haskell as we do not know of any portable way to inspect whether a lazy value\n  has been evaluated to or not.\n\\<close>\n\ncode_printing code_module Lazy \\<rightharpoonup> (SML)\n\\<open>signature LAZY =\nsig\n  type 'a lazy;\n  val lazy : (unit -> 'a) -> 'a lazy;\n  val force : 'a lazy -> 'a;\n  val peek : 'a lazy -> 'a option\n  val termify_lazy : \n   (string -> 'typerep -> 'term) -> \n   ('term -> 'term -> 'term) -> \n   (string -> 'typerep -> 'term -> 'term) ->\n   'typerep -> ('typerep -> 'typerep -> 'typerep) -> ('typerep -> 'typerep) ->\n   ('a -> 'term) -> 'typerep -> 'a lazy -> 'term -> 'term;\nend;\n\nstructure Lazy : LAZY = \nstruct\n\ndatatype 'a content =\n   Delay of unit -> 'a\n | Value of 'a \n | Exn of exn;\n\ndatatype 'a lazy = Lazy of 'a content ref;\n\nfun lazy f = Lazy (ref (Delay f));\n\nfun force (Lazy x) = case !x of\n   Delay f => (\n     let val res = f (); val _ = x := Value res; in res end\n     handle exn => (x := Exn exn; raise exn))\n  | Value x => x\n  | Exn exn => raise exn;\n\nfun peek (Lazy x) = case !x of\n    Value x => SOME x\n  | _ => NONE;\n\nfun termify_lazy const app abs unitT funT lazyT term_of T x _ =\n  app (const \"Code_Lazy.delay\" (funT (funT unitT T) (lazyT T))) \n    (case peek x of SOME y => abs \"_\" unitT (term_of y)\n     | _ => const \"Pure.dummy_pattern\" (funT unitT T));\n\nend;\\<close> for type_constructor lazy constant delay force termify_lazy\n| type_constructor lazy \\<rightharpoonup> (SML) \"_ Lazy.lazy\"\n| constant delay \\<rightharpoonup> (SML) \"Lazy.lazy\"\n| constant force \\<rightharpoonup> (SML) \"Lazy.force\"\n| constant termify_lazy \\<rightharpoonup> (SML) \"Lazy.termify'_lazy\"\n\ncode_reserved SML Lazy\n\ncode_printing \\<comment> \\<open>For code generation within the Isabelle environment, we reuse the thread-safe\n  implementation of lazy from \\<^file>\\<open>~~/src/Pure/Concurrent/lazy.ML\\<close>\\<close>\n  code_module Lazy \\<rightharpoonup> (Eval) \\<open>\\<close> for constant undefined\n| type_constructor lazy \\<rightharpoonup> (Eval) \"_ Lazy.lazy\"\n| constant delay \\<rightharpoonup> (Eval) \"Lazy.lazy\"\n| constant force \\<rightharpoonup> (Eval) \"Lazy.force\"\n| code_module Termify_Lazy \\<rightharpoonup> (Eval)\n\\<open>structure Termify_Lazy = struct\nfun termify_lazy\n  (_: string -> typ -> term) (_: term -> term -> term)  (_: string -> typ -> term -> term)\n  (_: typ) (_: typ -> typ -> typ) (_: typ -> typ)\n  (term_of: 'a -> term) (T: typ) (x: 'a Lazy.lazy) (_: term) =\n  Const (\"Code_Lazy.delay\", (HOLogic.unitT --> T) --> Type (\"Code_Lazy.lazy\", [T])) $\n  (case Lazy.peek x of\n    SOME (Exn.Res x) => absdummy HOLogic.unitT (term_of x)\n  | _ => Const (\"Pure.dummy_pattern\", HOLogic.unitT --> T));\nend;\\<close> for constant termify_lazy\n| constant termify_lazy \\<rightharpoonup> (Eval) \"Termify'_Lazy.termify'_lazy\"\n\ncode_reserved Eval Termify_Lazy\n\ncode_printing\n  type_constructor lazy \\<rightharpoonup> (OCaml) \"_ Lazy.t\"\n| constant delay \\<rightharpoonup> (OCaml) \"Lazy.from'_fun\"\n| constant force \\<rightharpoonup> (OCaml) \"Lazy.force\"\n| code_module Termify_Lazy \\<rightharpoonup> (OCaml)\n\\<open>module Termify_Lazy : sig\n  val termify_lazy :\n   (string -> 'typerep -> 'term) ->\n   ('term -> 'term -> 'term) ->\n   (string -> 'typerep -> 'term -> 'term) ->\n   'typerep -> ('typerep -> 'typerep -> 'typerep) -> ('typerep -> 'typerep) ->\n   ('a -> 'term) -> 'typerep -> 'a Lazy.t -> 'term -> 'term\nend = struct\n\nlet termify_lazy const app abs unitT funT lazyT term_of ty x _ =\n  app (const \"Code_Lazy.delay\" (funT (funT unitT ty) (lazyT ty)))\n    (if Lazy.is_val x then abs \"_\" unitT (term_of (Lazy.force x))\n     else const \"Pure.dummy_pattern\" (funT unitT ty));;\n\nend;;\\<close> for constant termify_lazy\n| constant termify_lazy \\<rightharpoonup> (OCaml) \"Termify'_Lazy.termify'_lazy\"\n\ncode_reserved OCaml Lazy Termify_Lazy\n\n\ncode_printing\n  code_module Lazy \\<rightharpoonup> (Haskell) \\<open>\nmodule Lazy(Lazy, delay, force) where\n\nnewtype Lazy a = Lazy a\ndelay f = Lazy (f ())\nforce (Lazy x) = x\\<close> for type_constructor lazy constant delay force\n| type_constructor lazy \\<rightharpoonup> (Haskell) \"Lazy.Lazy _\"\n| constant delay \\<rightharpoonup> (Haskell) \"Lazy.delay\"\n| constant force \\<rightharpoonup> (Haskell) \"Lazy.force\"\n\ncode_reserved Haskell Lazy\n\ncode_printing\n  code_module Lazy \\<rightharpoonup> (Scala) \n\\<open>object Lazy {\n  final class Lazy[A] (f: Unit => A) {\n    var evaluated = false;\n    lazy val x: A = f(())\n\n    def get() : A = {\n      evaluated = true;\n      return x\n    }\n  }\n\n  def force[A] (x: Lazy[A]) : A = {\n    return x.get()\n  }\n\n  def delay[A] (f: Unit => A) : Lazy[A] = {\n    return new Lazy[A] (f)\n  }\n\n  def termify_lazy[Typerep, Term, A] (\n    const: String => Typerep => Term,\n    app: Term => Term => Term,\n    abs: String => Typerep => Term => Term,\n    unitT: Typerep,\n    funT: Typerep => Typerep => Typerep,\n    lazyT: Typerep => Typerep,\n    term_of: A => Term,\n    ty: Typerep,\n    x: Lazy[A],\n    dummy: Term) : Term = {\n    if (x.evaluated)\n      app(const(\"Code_Lazy.delay\")(funT(funT(unitT)(ty))(lazyT(ty))))(abs(\"_\")(unitT)(term_of(x.get())))\n    else\n      app(const(\"Code_Lazy.delay\")(funT(funT(unitT)(ty))(lazyT(ty))))(const(\"Pure.dummy_pattern\")(funT(unitT)(ty)))\n  }\n}\\<close> for type_constructor lazy constant delay force termify_lazy\n| type_constructor lazy \\<rightharpoonup> (Scala) \"Lazy.Lazy[_]\"\n| constant delay \\<rightharpoonup> (Scala) \"Lazy.delay\"\n| constant force \\<rightharpoonup> (Scala) \"Lazy.force\"\n| constant termify_lazy \\<rightharpoonup> (Scala) \"Lazy.termify'_lazy\"\n\ncode_reserved Scala Lazy\n\ntext \\<open>Make evaluation with the simplifier respect \\<^term>\\<open>delay\\<close>s.\\<close>\n\nlemma delay_lazy_cong: \"delay f = delay f\" by simp\nsetup \\<open>Code_Simp.map_ss (Simplifier.add_cong @{thm delay_lazy_cong})\\<close>        \n\nsubsection \\<open>Implementation\\<close>\n\nML_file \\<open>code_lazy.ML\\<close>\n\nsetup \\<open>\n  Code_Preproc.add_functrans (\"lazy_datatype\", Code_Lazy.transform_code_eqs)\n\\<close>\n\nend\n", "meta": {"author": "m-fleury", "repo": "isabelle-emacs", "sha": "756c662195e138a1941d22d4dd7ff759cbf6b6b9", "save_path": "github-repos/isabelle/m-fleury-isabelle-emacs", "path": "github-repos/isabelle/m-fleury-isabelle-emacs/isabelle-emacs-756c662195e138a1941d22d4dd7ff759cbf6b6b9/src/HOL/Library/Code_Lazy.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5312093733737563, "lm_q2_score": 0.4843800842769844, "lm_q1q2_score": 0.25730724104350416}}
{"text": "theory Simple_Network_Language_Renaming\n  imports Simple_Network_Language_Model_Checking\nbegin\n\nunbundle no_library_syntax\n\ntext \\<open>Helpful methods and theorems to work with tags:\\<close>\n\nlemmas TAG_cong = arg_cong[where f = \"TAG t\" for t]\n\nlemma TAG_mp:\n  assumes \"TAG t x\" \"x \\<Longrightarrow> y\"\n  shows \"TAG t y\"\n  using assms unfolding TAG_def by blast\n\nlemma TAG_mp':\n  assumes \"TAG t x\" \"x \\<Longrightarrow> y\"\n  shows y\n  using assms unfolding TAG_def by blast\n\nmethod tag uses keep = (determ \\<open>tags del: TAG keep: keep\\<close>, (simp only: TAG_def)?)\n\nmethod auto_tag uses keep = match conclusion in \"TAG t _\" (cut) for t \\<Rightarrow> \\<open>tag keep: TAG[of t] keep\\<close>\n\nlemmas all_mono_rule = all_mono[THEN mp, OF impI, rotated]\n\nlemma imp_mono_rule:\n  assumes \"P1 \\<longrightarrow> P2\"\n    and \"Q1 \\<Longrightarrow> P1\"\n    and \"Q1 \\<Longrightarrow> P2 \\<Longrightarrow> Q2\"\n  shows \"Q1 \\<longrightarrow> Q2\"\n  using assms by blast\n\nlemma Ball_mono:\n  assumes \"\\<forall>x \\<in> S. P x\" \"\\<And>x. x \\<in> S \\<Longrightarrow> P x \\<Longrightarrow> Q x\"\n  shows \"\\<forall>x \\<in> S. Q x\"\n  using assms by blast\n\nmethod prop_monos =\n  erule all_mono_rule\n  | erule (1) imp_mono_rule\n  | erule disj_mono[rule_format, rotated 2]\n\nlocale Prod_TA_Defs_urge =\n  fixes A :: \"('a, 's, 'c, 't :: {zero}, 'x, 'v :: linorder) nta\" and urge :: 'c\nbegin\n\ndefinition\n  \"add_reset \\<equiv> \\<lambda>(C, U, T, I).\n    (C, {}, (\\<lambda>(l, b, g, a, f, r, l'). (l, b, g, a, f, urge # r, l')) ` T, I)\"\n\ndefinition\n  \"add_inv \\<equiv> \\<lambda>(C, U, T, I). (C, U, T,\n    (\\<lambda>l. if l \\<in> U then acconstraint.LE urge 0 # I l else I l))\"\n\ndefinition \"A_urge \\<equiv>\n  (fst A, map add_reset (map add_inv (fst (snd A))), snd (snd A))\"\n\ndefinition\n  \"N_urge i \\<equiv> map add_reset (map add_inv (fst (snd A))) ! i\"\n\nend\n\nlocale Prod_TA_sem_urge =\n  Prod_TA_Defs_urge A urge + Prod_TA_sem A\n  for A :: \"('a, 's, 'c, 't :: {zero, time}, 'x, 'v :: linorder) nta\" and urge :: 'c +\n  assumes urge_not_in_invariants:\n    \"\\<forall>(_, _, _, I) \\<in> set (fst (snd A)). \\<forall>l. urge \\<notin> constraint_clk ` set (I l)\"\n  assumes urge_not_in_guards:\n    \"\\<forall>(_, _, T, _) \\<in> set (fst (snd A)). \\<forall>(l, b, g, a, f, r, l') \\<in> T. urge \\<notin> constraint_clk ` set g\"\n  assumes urge_not_in_resets:\n    \"\\<forall>(_, _, T, _) \\<in> set (fst (snd A)). \\<forall>(l, b, g, a, f, r, l') \\<in> T. urge \\<notin> set r\"\nbegin\n\nlemma N_urge_simp:\n  \"N_urge i = add_reset (add_inv (N i))\" if \"i < n_ps\"\n  using that unfolding N_urge_def N_def by (simp add: n_ps_def)\n\nlemma inv_add_reset:\n  \"inv (add_reset A') = inv A'\"\n  unfolding inv_def add_reset_def by (simp split: prod.splits)\n\nlemma inv_add_inv:\n  \"inv (add_inv (C, U, T, I)) = (\\<lambda>l. if l \\<in> U then acconstraint.LE urge 0 # I l else I l)\"\n  unfolding add_inv_def inv_def by simp\n\ndefinition\n  \"is_urgent L \\<equiv> \\<exists>p<n_ps. L ! p \\<in> urgent (N p)\"\n\nlemma map_nth':\n  \"map ((!) xs) [0..<n] = xs\" if \"n = length xs\"\n  using that List.map_nth by simp\n\nlemma A_urge_split:\n  \"A_urge = (broadcast, map N_urge [0..<n_ps], bounds)\"\n  unfolding broadcast_def N_urge_def bounds_def n_ps_def A_urge_def by (cases A)(simp add: map_nth')\n\nlemma inv_add_inv':\n  \"inv (add_inv A') =\n  (\\<lambda>l. if l \\<in> urgent A' then acconstraint.LE urge 0 # inv A' l else inv A' l)\"\n  apply (cases A')\n  apply (simp add: inv_add_inv urgent_def)\n  unfolding inv_def\n  apply auto\n  done\n\nlemma A_split':\n  \"A = (fst A, fst (snd A), snd (snd A))\"\n  by auto\n\nlemma is_urgent_simp:\n  \"(\\<exists>p<n_ps. L ! p \\<in> urgent (map N [0..<n_ps] ! p)) \\<longleftrightarrow> is_urgent L\"\n  unfolding is_urgent_def by auto\n\nlemma urgent_N_urge:\n  \"urgent (N_urge p) = {}\" if \"p < n_ps\"\n  using that unfolding N_def N_urge_def n_ps_def urgent_def add_reset_def add_inv_def\n  by (auto split: prod.split_asm)\n\nlemma committed_N_urge:\n  \"committed (N_urge p) = committed (N p)\" if \"p < n_ps\"\n  using that unfolding N_def N_urge_def n_ps_def committed_def add_reset_def add_inv_def\n  by (auto split: prod.split)\n\nlemma is_urgent_simp2:\n  \"(\\<exists>p<n_ps. L ! p \\<in> urgent (map N_urge [0..<n_ps] ! p)) \\<longleftrightarrow> False\"\n  unfolding is_urgent_def by (auto simp: urgent_N_urge)\n\nlemma inv_add_invI1:\n  \"u \\<turnstile> inv (add_inv (N p)) (L ! p)\" if \"u \\<turnstile> inv (N p) (L ! p)\" \"\\<not> is_urgent L\" \"p < n_ps\"\n  using that unfolding inv_add_inv' is_urgent_def by simp\n\nlemma inv_add_invI2:\n  \"u \\<turnstile> inv (add_inv (N p)) (L ! p)\" if \"u \\<turnstile> inv (N p) (L ! p)\" \"u urge \\<le> 0\" \"p < n_ps\"\n  using that unfolding inv_add_inv' is_urgent_def by (auto elim: guard_consI[rotated])\n\nlemma inv_add_invD:\n  \"u \\<turnstile> inv A' l\" if \"u \\<turnstile> inv (add_inv A') l\"\n  using that unfolding inv_add_inv' by (auto split: if_split_asm simp: clock_val_def)\n\nlemma inv_N_urge:\n  \"inv (N_urge p) = inv (add_inv (N p))\" if \"p < n_ps\"\n  using that by (simp add: N_urge_simp inv_add_reset)\n\nlemma N_urge_trans_simp:\n  \"trans (N_urge i) = (\\<lambda>(l, b, g, a, f, r, l'). (l, b, g, a, f, urge # r, l')) ` (trans (N i))\"\n  if \"i < n_ps\"\n  unfolding N_urge_simp[OF that] add_inv_def add_reset_def trans_def by (simp split: prod.splits)\n\nlemma trans_N_urgeD:\n  \"(l, b, g, a, f, urge # r, l') \\<in> trans (N_urge p)\"\n  if \"(l, b, g, a, f, r, l') \\<in> trans (N p)\" \"p < n_ps\"\n  using that by (force simp add: N_urge_trans_simp)\n\nlemma trans_N_urgeE:\n  assumes \"(l, b, g, a, f, r, l') \\<in> trans (N_urge p)\" \"p < n_ps\"\n  obtains \"(l, b, g, a, f, tl r, l') \\<in> trans (N p)\" \"r = urge # tl r\"\n  using assms by (force simp add: N_urge_trans_simp)\n\nlemma urge_not_in_inv:\n  \"urge \\<notin> constraint_clk ` set (inv (N p) l)\" if \"p < n_ps\"\n  using urge_not_in_invariants that unfolding N_def inv_def n_ps_def by (fastforce dest! :nth_mem)\n\nlemma urge_not_in_guards':\n  assumes \"(l, b, g, a, f, r, l') \\<in> trans (N p)\" \"p < n_ps\"\n  shows \"urge \\<notin> constraint_clk ` set g\"\n  using urge_not_in_guards assms unfolding N_def trans_def n_ps_def by (fastforce dest! :nth_mem)\n\nlemma urge_not_in_resets':\n  assumes \"(l, b, g, a, f, r, l') \\<in> trans (N p)\" \"p < n_ps\"\n  shows \"urge \\<notin> set r\"\n  using urge_not_in_resets assms unfolding N_def trans_def n_ps_def by (fastforce dest! :nth_mem)\n\nlemma clk_upd_clock_val_a_simp:\n  \"u(c := d) \\<turnstile>\\<^sub>a ac \\<longleftrightarrow> u \\<turnstile>\\<^sub>a ac\" if \"c \\<noteq> constraint_clk ac\"\n  using that by (cases ac) auto\n\nlemma clk_upd_clock_val_simp:\n  \"u(c := d) \\<turnstile> cc \\<longleftrightarrow> u \\<turnstile> cc\" if \"c \\<notin> constraint_clk ` set cc\"\n  using that unfolding clock_val_def list_all_def\n  by (force simp: image_def clk_upd_clock_val_a_simp)\n\nlemma inv_N_urgeI:\n  assumes \"u \\<turnstile> inv (N p) l\" \"p < n_ps\"\n  shows \"u(urge := 0) \\<turnstile> inv (N_urge p) l\"\n  using assms urge_not_in_inv[of p]\n  by (auto simp: inv_N_urge inv_add_inv' clk_upd_clock_val_simp intro!: guard_consI)\n\nlemma inv_N_urge_updI:\n  assumes \"u \\<turnstile> inv (N p) l\" \"p < n_ps\"\n  shows \"u(urge := d) \\<turnstile> inv (N p) l\"\n  using assms urge_not_in_inv[of p] by (auto simp: clk_upd_clock_val_simp)\n\nlemma inv_N_urge_upd_simp:\n  assumes \"p < n_ps\"\n  shows \"u(urge := d) \\<turnstile> inv (N p) l \\<longleftrightarrow> u \\<turnstile> inv (N p) l\"\n  using assms urge_not_in_inv[of p] by (auto simp: clk_upd_clock_val_simp)\n\nlemma inv_N_urge_updD:\n  assumes \"u(urge := d) \\<turnstile> inv (N p) l\" \"p < n_ps\"\n  shows \"u \\<turnstile> inv (N p) l\"\n  using assms urge_not_in_inv[of p] by (auto simp: clk_upd_clock_val_simp)\n\nlemma inv_N_urgeD:\n  assumes \"u \\<turnstile> inv (N_urge p) l\" \"p < n_ps\"\n  shows \"u(urge := d) \\<turnstile> inv (N p) l\"\n  using assms urge_not_in_inv[of p]\n  by (auto simp: inv_N_urge inv_add_inv' clk_upd_clock_val_simp split: if_split_asm elim: guard_consE)\n\nlemma inv_N_urge_urges:\n  assumes \"\\<forall>p<n_ps. u(urge := 0) \\<oplus> d \\<turnstile> inv (N_urge p) (L ! p)\" \"is_urgent L\"\n  shows \"d \\<le> 0\"\nproof -\n  from \\<open>is_urgent L\\<close> obtain p where \"p < n_ps\" \"L ! p \\<in> urgent (N p)\"\n    unfolding is_urgent_def by auto\n  then have \"acconstraint.LE urge 0 \\<in> set (inv (N_urge p) (L ! p))\"\n    by (simp add: inv_N_urge inv_add_inv')\n  with assms \\<open>p < n_ps \\<close> have \"u(urge := 0) \\<oplus> d \\<turnstile>\\<^sub>a acconstraint.LE urge 0\"\n    unfolding clock_val_def list_all_iff by auto\n  then show ?thesis\n    by (auto simp: cval_add_def)\nqed\n\nlemma trans_urge_upd_iff:\n  assumes \"(l, b, g, a, f, r, l') \\<in> trans (N p)\" \"p < n_ps\"\n  shows \"u(urge := d) \\<turnstile> g \\<longleftrightarrow> u \\<turnstile> g\"\n  using assms urge_not_in_guards' by (auto simp: clk_upd_clock_val_simp)\n\nlemma cval_add_0[simp]:\n  \"u \\<oplus> (0 :: 'tt :: time) = u\"\n  unfolding cval_add_def by simp\n\nlemma clock_val_reset_delay:\n  \"u(c := 0) \\<oplus> (d :: 'tt :: time) = (u \\<oplus> d)(c := d)\"\n  unfolding cval_add_def by auto\n\nlemma clock_set_upd_simp:\n  \"[r \\<rightarrow> d]u(c := d') = [r \\<rightarrow> d]u\" if \"c \\<in> set r\"\n  using that\n  apply (induction r arbitrary: u)\n   apply auto\n  oops\n\nlemma fun_upd_twist2:\n  \"f(a := x, b := x) = f(b := x, a := x)\"\n  by auto\n\nlemma clock_set_upd_simp:\n  \"[c # r \\<rightarrow> d]u(c := d') = [c # r \\<rightarrow> d]u\"\n  apply (induction r arbitrary: u)\n   apply simp\n  apply simp\n  apply (subst fun_upd_twist2)\n  apply auto\n  done\n\nlemma clock_set_commute_single:\n  \"[r \\<rightarrow> d]u(c := d') = ([r \\<rightarrow> d]u)(c := d')\" if \"c \\<notin> set r\"\n  using that by (induction r) auto\n\nlemma clock_set_upd_simp2:\n  \"([xs @ c # ys \\<rightarrow> d]u)(c := d') = ([xs @ ys \\<rightarrow> d]u)(c := d')\"\n  apply (induction xs)\n   apply (auto; fail)\n  apply (intro ext)\n  subgoal for a xs x\n    by (drule fun_cong[where x = x]) auto\n  done\n\nlemma clock_set_upd_simp3:\n  \"([xs \\<rightarrow> d]u)(c := d') = ([filter (\\<lambda>x. x \\<noteq> c) xs \\<rightarrow> d]u)(c := d')\"\n  apply (induction xs)\n   apply (auto; fail)\n  apply (rule ext)\n  apply auto\n  subgoal for xs x\n    by (drule fun_cong[where x = x]) auto\n  subgoal for a xs x\n    by (drule fun_cong[where x = x]) auto\n  done\n\ninterpretation urge: Prod_TA_sem A_urge .\n\nlemma urge_n_ps_eq:\n  \"urge.n_ps = n_ps\"\n  unfolding urge.n_ps_def n_ps_def unfolding A_urge_def by simp\n\nlemma urge_N_simp[simp]:\n  \"urge.N = N_urge\"\n  unfolding urge.N_def N_urge_def unfolding A_urge_def by simp\n\nlemma urge_states_eq:\n  \"urge.states = states\"\n  unfolding states_def urge.states_def urge_n_ps_eq\n  by (auto simp add: N_urge_trans_simp split: prod.splits)\n\ninterpretation Bisimulation_Invariant\n  \"\\<lambda>(L, s, u) (L', s', u'). step_u' A L s u L' s' u'\"\n  \"\\<lambda>(L, s, u) (L', s', u'). step_u' A_urge L s u L' s' u'\"\n  \"\\<lambda>(L, s, u) (L', s', u'). L' = L \\<and> s' = s \\<and> u' = u(urge := 0)\"\n  \"\\<lambda>(L, s, u). L \\<in> states\" \"\\<lambda>(L, s, u). True\"\nproof ((standard; clarsimp), goal_cases)\n  case (1 L s u L' s' u')\n  then show ?case\n  proof cases\n    case steps: (1 L'' s'' u'' a)\n    have *: \"(u \\<oplus> d)(urge := (u \\<oplus> d) urge - u urge) = u(urge := 0) \\<oplus> d\" for d\n      by (auto simp: cval_add_def)\n    from steps(1) \\<open>L \\<in> states\\<close> have \"L'' \\<in> states\"\n      by (rule states_inv)\n    then have [simp]: \"length L'' = n_ps\"\n      by (rule states_lengthD)\n    from steps(1) have\n      \"A_urge \\<turnstile> \\<langle>L, s, u(urge := 0)\\<rangle> \\<rightarrow>\\<^bsub>Del\\<^esub> \\<langle>L'', s'', u''(urge := u'' urge - u urge)\\<rangle>\"\n      apply cases\n      apply (subst A_urge_split)\n      apply (subst (asm) A_split)\n      apply (drule sym)\n      apply simp\n      unfolding TAG_def[of \"''urgent''\"]\n      apply (simp add: is_urgent_simp *)\n      apply (rule step_u.intros)\n         apply auto_tag\n         apply simp\n      subgoal\n        by (cases \"is_urgent L\")\n          (auto 4 3\n            intro: inv_N_urge_updI inv_add_invI1 inv_add_invI2\n            simp: inv_N_urge clock_val_reset_delay)\n      by (auto_tag, simp add: is_urgent_simp2)+\n    moreover from steps(3,2) have\n      \"A_urge \\<turnstile> \\<langle>L'', s'', u''(urge := u'' urge - u urge)\\<rangle> \\<rightarrow>\\<^bsub>a\\<^esub> \\<langle>L', s', u'(urge := 0)\\<rangle>\"\n      apply (cases; subst A_urge_split; subst (asm) A_split)\n         apply (all \\<open>drule sym\\<close>)\n      subgoal delay\n        by simp\n      subgoal internal for l b g a' f r l' N p B broadcast\n        unfolding TAG_def[of \"''range''\"]\n        apply simp\n        apply (rule step_u.intros)\n                  apply (auto_tag, drule (1) trans_N_urgeD, subst nth_map, simp, simp; fail)\n                 apply (auto_tag, subst nth_map, simp, simp add: committed_N_urge; fail)\n                apply (auto_tag; fail)\n               apply (tag keep: TAG[of \"''guard''\"] TAG[of \"TRANS _\"]; auto simp: trans_urge_upd_iff;\n            fail)\n              apply (all \\<open>auto_tag; auto intro: inv_N_urgeI\\<close>)\n        subgoal\n          unfolding clock_set.simps(2)[symmetric] clock_set_upd_simp ..\n        done\n      subgoal binary for a' broadcast' l1 b1 g1 f1 r1 l1' N' p l2 b2 g2 f2 r2 l2' q s'' B\n        unfolding TAG_def[of \"RECV ''range''\"] TAG_def[of \"SEND ''range''\"]\n        apply simp\n        apply (rule step_u.intros)\n                          apply (auto_tag; simp; fail)\n                         apply (auto_tag, drule (1) trans_N_urgeD, subst nth_map, simp, simp; fail)\n                        apply (auto_tag, drule (1) trans_N_urgeD, subst nth_map, simp, simp; fail)\n                       apply (auto_tag, subst nth_map, simp, simp add: committed_N_urge; fail)\n                      apply (auto_tag; fail)\n                     apply (auto_tag; fail)\n                    apply (tag keep: TAG[of \"''guard''\"] TAG[of \"TRANS _\"]; auto simp: trans_urge_upd_iff; fail)\n                   apply (tag keep: TAG[of \"''guard''\"] TAG[of \"TRANS _\"]; auto simp: trans_urge_upd_iff; fail)\n                  apply (all \\<open>auto_tag; auto intro: inv_N_urgeI\\<close>)\n        unfolding clock_set.simps(2)[symmetric] clock_set_upd_simp\n        apply (simp add: clock_set_upd_simp2)\n        done\n      subgoal broadcast for a' broadcast' l b g f r l' N' p ps bs gs fs rs ls' s'' B\n        unfolding TAG_def[of \"SEL ''range''\"] TAG_def[of \"SEND ''range''\"]\n        apply (simp add: subset_nat_0_atLeastLessThan_conv)\n        apply (rule step_u.intros)\n                            apply (auto_tag; simp; fail)\n                           apply (auto_tag, drule (1) trans_N_urgeD, subst nth_map, simp, simp; fail)\n                          apply (auto_tag, auto 4 3 dest: trans_N_urgeD; fail)\n                         apply (auto_tag, subst nth_map, simp, simp add: committed_N_urge; fail)\n                        apply (auto_tag; fail)\n                       apply (auto_tag; fail)\n                      apply (tag keep: TAG[of \"''guard''\"] TAG[of \"TRANS _\"]; auto simp: trans_urge_upd_iff; fail)\n                     apply (tag keep: TAG[of \"''guard''\"] TAG[of \"TRANS _\"]; auto simp: trans_urge_upd_iff; fail)\n                    apply (all \\<open>auto_tag; auto intro: inv_N_urgeI\\<close>)\n         apply (erule (1) trans_N_urgeE, force simp: trans_urge_upd_iff)\n        subgoal\n          unfolding clock_set.simps(2)[symmetric] clock_set_upd_simp\n          apply simp\n          apply (subst (2) clock_set_upd_simp3)\n          apply (subst clock_set_upd_simp3)\n          apply (simp add: filter_concat comp_def)\n          done\n        done\n      done\n    ultimately show \"A_urge \\<turnstile> \\<langle>L, s, u(urge := 0)\\<rangle> \\<rightarrow> \\<langle>L', s', u'(urge := 0)\\<rangle>\"\n      using \\<open>a \\<noteq> _\\<close> by (intro step_u'.intros)\n  qed\nnext\n  case (2 L s u L' s' u')\n  then show ?case\n  proof cases\n    case steps: (1 L'' s'' u'' a)\n    have *: \"(u(urge := 0) \\<oplus> d)(urge := (u(urge := 0) \\<oplus> d) urge + u urge) = u \\<oplus> d\" for d\n      unfolding cval_add_def by auto\n    from steps(1) \\<open>L \\<in> states\\<close> have \"L'' \\<in> states\"\n      by (rule urge.states_inv[unfolded urge_states_eq])\n    then have [simp]: \"length L'' = n_ps\"\n      by (rule states_lengthD)\n    have 1: \"([r\\<rightarrow>0]u'') urge = 0\" if \"r = urge # xs\" for r xs\n      by (subst that) simp\n    have 2: \"filter (\\<lambda>x. x \\<noteq> urge) r = filter (\\<lambda>x. x \\<noteq> urge) (tl r)\" if \"r = urge # tl r\" for r\n      by (subst that) simp\n    from steps(3,2) have \"u' urge = 0\"\n      apply (cases; subst (asm) A_urge_split)\n         apply (all \\<open>drule sym\\<close>)\n         apply (simp; fail)\n      subgoal delay\n        by (tag keep: TAG[of \"''new valuation''\"] TAG[of \"TRANS _\"] TAG[of \"''range''\"])\n          (auto elim!: trans_N_urgeE simp: 1; fail)\n      subgoal binary for a' broadcast' l1 b1 g1 f1 r1 l1' N p l2 b2 g2 f2 r2 l2' q s'' B\n        by (tag keep: TAG[of \"''new valuation''\"] TAG[of \"TRANS _\"] TAG[of \"RECV ''range''\"])\n          (auto elim!: trans_N_urgeE simp: 1[of _ \"tl r1 @ r2\"])\n      subgoal broadcast for a' broadcast' l b g f r l' N p ps bs gs fs rs ls' s'a B\n        by (tag keep: TAG[of \"''new valuation''\"] TAG[of \"TRANS _\"] TAG[of \"SEND ''range''\"])\n          (auto elim!: trans_N_urgeE simp: 1[of _ \"tl r @ concat (map rs ps)\"])\n      done\n    have **: \"\n      ([r\\<rightarrow>0]u'')(urge := u'' urge + u urge) = ([tl r\\<rightarrow>0]u'')(urge := u'' urge + u urge)\"\n      if \"r = urge # tl r\" for r\n      by (subst that) simp\n    from steps(1) have \"A \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow>\\<^bsub>Del\\<^esub> \\<langle>L'', s'', u''(urge := u'' urge + u urge)\\<rangle>\"\n      apply cases\n      apply (subst (asm) A_urge_split)\n      apply (subst A_split)\n      apply (drule sym)\n      apply simp\n      unfolding TAG_def[of \"''urgent''\"]\n      apply (simp add: is_urgent_simp *)\n      apply (rule step_u.intros)\n      subgoal\n        by auto_tag(auto dest!: inv_add_invD inv_N_urge_updD simp: inv_N_urge clock_val_reset_delay)\n        apply auto_tag\n       apply (tag keep: TAG[of \"''target invariant''\"] TAG[of \"''nonnegative''\"])\n       apply (auto simp add: is_urgent_simp2 is_urgent_simp dest: inv_N_urge_urges)\n      done\n    moreover from steps(3,2) have\n      \"A \\<turnstile> \\<langle>L'', s'', u''(urge := u'' urge + u urge)\\<rangle> \\<rightarrow>\\<^bsub>a\\<^esub> \\<langle>L', s', u'(urge := u'' urge + u urge)\\<rangle>\"\n      apply (cases; subst (asm) A_urge_split; subst A_split)\n         apply (all \\<open>drule sym\\<close>)\n      subgoal delay\n        by simp\n      subgoal internal for l b g a' f r l' N p B broadcast\n        unfolding TAG_def[of \"''range''\"]\n        apply simp\n        apply (rule step_u.intros)\n                  apply (auto_tag, erule (1) trans_N_urgeE, subst nth_map, simp, simp; fail)\n                 apply (auto_tag, subst nth_map, simp, simp add: committed_N_urge; fail)\n                apply (auto_tag; fail)\n               apply (auto_tag keep: TAG[of \"TRANS _\"];\n            auto intro: trans_N_urgeE simp: trans_urge_upd_iff; fail)\n              apply (all \\<open>auto_tag; auto intro: inv_N_urgeD; fail | succeed\\<close>)\n        apply (auto_tag keep: TAG[of \"TRANS _\"], erule (1) trans_N_urgeE,\n            subst clock_set_commute_single, rule urge_not_in_resets', (simp add: **)+; fail)\n        done\n      subgoal binary for a' broadcast' l1 b1 g1 f1 r1 l1' Na p l2 b2 g2 f2 r2 l2' q s'' B\n        unfolding TAG_def[of \"RECV ''range''\"] TAG_def[of \"SEND ''range''\"]\n        apply simp\n        apply (rule step_u.intros)\n                          apply (auto_tag; simp; fail)\n                         apply (auto_tag, erule (1) trans_N_urgeE, subst nth_map, simp, simp; fail)\n                        apply (auto_tag, erule (1) trans_N_urgeE, subst nth_map, simp, simp; fail)\n                       apply (auto_tag, subst nth_map, simp, simp add: committed_N_urge; fail)\n                      apply (auto_tag; fail)\n                     apply (auto_tag; fail)\n                    apply (auto_tag keep: TAG[of \"TRANS _\"];\n            auto intro: trans_N_urgeE simp: trans_urge_upd_iff; fail)\n                   apply (auto_tag keep: TAG[of \"TRANS _\"];\n            auto intro: trans_N_urgeE simp: trans_urge_upd_iff; fail)\n                  apply (all \\<open>auto_tag; auto intro: inv_N_urgeD; fail | succeed\\<close>)\n        apply (auto_tag keep: TAG[of \"TRANS _\"], erule (1) trans_N_urgeE, erule (1) trans_N_urgeE)\n        apply simp\n        apply (subst clock_set_upd_simp3)\n        apply (subst clock_set_commute_single)\n         apply (simp; rule conjI; erule (1) urge_not_in_resets')\n        apply (rule arg_cong)\n        subgoal premises prems\n          using urge_not_in_resets'[OF prems(7) \\<open>p < n_ps\\<close>] urge_not_in_resets'[OF prems(9) \\<open>q < n_ps\\<close>]\n          by (subst \\<open>r1 = _\\<close>, subst \\<open>r2 = _\\<close>, simp) (subst filter_True, auto)+\n        done\n      subgoal broadcast for a' broadcast' l b g f r l' N' p ps bs gs fs rs ls' s2 B\n        unfolding TAG_def[of \"SEL ''range''\"] TAG_def[of \"SEND ''range''\"]\n        apply (simp add: subset_nat_0_atLeastLessThan_conv)\n        apply (rule step_u.intros)\n                            apply (auto_tag; simp; fail)\n                           apply (auto_tag, erule (1) trans_N_urgeE, subst nth_map, simp, simp; fail)\n                          apply (auto_tag, auto 4 3 elim: trans_N_urgeE; fail)\n                         apply (auto_tag, subst nth_map, simp, simp add: committed_N_urge; fail)\n                        apply (auto_tag; fail)\n                       apply (auto_tag; fail)\n                      apply (auto_tag keep: TAG[of \"TRANS _\"]; auto elim: trans_N_urgeE simp: trans_urge_upd_iff; fail)\n                     apply (all \\<open>auto_tag; auto intro: inv_N_urgeD; fail | succeed\\<close>)\n        subgoal guards\n          by (auto_tag keep: TAG[of \"TRANS _\"]; auto elim!: trans_N_urgeE simp: trans_urge_upd_iff)\n        subgoal maximal\n          by (auto_tag, force simp: trans_urge_upd_iff dest: trans_N_urgeD)\n        subgoal new_valuation\n          apply (auto_tag keep: TAG[of \"TRANS _\"])\n          apply (subst clock_set_upd_simp3)\n          apply (simp add: filter_concat comp_def)\n          apply (subst clock_set_commute_single[symmetric], (simp; fail))\n          apply (rule arg_cong)\n          apply (fo_rule arg_cong2)\n          subgoal\n            apply (auto simp: 2 urge_not_in_resets' filter_id_conv elim!: trans_N_urgeE)\n            done\n          subgoal\n            apply (fo_rule arg_cong)\n            apply (fastforce elim: trans_N_urgeE simp: 2 urge_not_in_resets' filter_id_conv)+\n            done\n          done\n        done\n      done\n    ultimately show ?thesis\n      using \\<open>a \\<noteq> _\\<close> \\<open>u' urge = 0\\<close> by  (intros add: step_u'.intros) auto\n  qed\nnext\n  case (3 L s u L' s' u')\n  then show ?case\n    by (elim step_u'_elims states_inv)\nqed\n\nlemmas urge_bisim = Bisimulation_Invariant_axioms\n\nend (* Prod TA sem urge *)\n\n\n(* XXX All this stuff is duplicated *)\ncontext Simple_Network_Impl_Defs\nbegin\n\nlemma N_eq:\n  \\<open>N i = automaton_of (automata ! i)\\<close> if \\<open>i < n_ps\\<close>\n  using that unfolding N_def n_ps_def fst_conv snd_conv by (intro nth_map; simp)\n\n(* XXX Remove? *)\nlemma covn_N_eq:\n  \\<open>N i = automaton_of (automata ! i)\\<close> if \\<open>i < n_ps\\<close>\n  using that unfolding N_def n_ps_def fst_conv snd_conv by (intro nth_map; simp)\n\nend\n\ncontext Simple_Network_Impl_Defs\nbegin\n\nlemma dom_bounds: \"dom bounds = fst ` set bounds'\"\n  unfolding bounds_def by (simp add: dom_map_of_conv_image_fst)\n\nlemma mem_trans_N_iff:\n  \"t \\<in> Simple_Network_Language.trans (N i) \\<longleftrightarrow> t \\<in> set (fst (snd (snd (automata ! i))))\"\n  if \"i < n_ps\"\n  unfolding N_eq[OF that] by (auto split: prod.splits simp: automaton_of_def trans_def)\n\nlemma length_automata_eq_n_ps:\n  \"length automata = n_ps\"\n  unfolding n_ps_def by simp\n\nlemma N_p_trans_eq:\n  \"Simple_Network_Language.trans (N p) = set (fst (snd (snd (automata ! p))))\" if \"p < n_ps\"\n  using mem_trans_N_iff[OF that] by auto\n\nlemma loc_set_compute:\n  \"loc_set = \\<Union> ((\\<lambda>(_, _, t, _). \\<Union> ((\\<lambda>(l, _, _, _, _, _, l'). {l, l'}) ` set t)) ` set automata)\"\n  unfolding loc_set_def setcompr_eq_image\n  apply (auto simp: N_p_trans_eq n_ps_def)\n     apply (drule nth_mem, erule bexI[rotated], force)+\n   apply (drule mem_nth, force)+\n  done\n\nlemma var_set_compute:\n  \"var_set =\n  (\\<Union>S \\<in> (\\<lambda>t. (fst \\<circ> snd) ` set t) ` ((\\<lambda>(_, _, t, _). t) `  set automata). \\<Union>b \\<in> S. vars_of_bexp b) \\<union>\n  (\\<Union>S \\<in> (\\<lambda>t. (fst \\<circ> snd o snd \\<circ> snd \\<circ> snd) ` set t) ` ((\\<lambda>(_, _, t, _). t) `  set automata).\n    \\<Union>f \\<in> S. \\<Union> (x, e) \\<in> set f. {x} \\<union> vars_of_exp e)\"\n  unfolding var_set_def setcompr_eq_image\n  by (rule arg_cong2[where f = \"(\\<union>)\"]; auto simp: N_p_trans_eq n_ps_def,\n     (drule nth_mem, erule bexI[rotated],\n      metis (no_types, lifting) insert_iff mem_case_prodI prod.collapse)+,\n      (drule mem_nth, force)+)\n\nlemma states_loc_setD:\n  \"set L \\<subseteq> loc_set\" if \"L \\<in> states\"\n  using states_loc_set that by auto\n\nend (* Simple Network Impl Defs *)\n\n\ncontext Simple_Network_Impl\nbegin\n\nlemma sem_bounds_eq: \"sem.bounds = bounds\"\n  unfolding sem.bounds_def bounds_def unfolding sem_def by simp\n\nlemma n_ps_eq[simp]:\n  \"sem.n_ps = n_ps\"\n  unfolding n_ps_def sem.n_ps_def unfolding sem_def by auto\n\nlemma sem_loc_set_eq:\n  \"sem.loc_set = loc_set\"\n  unfolding sem.loc_set_def loc_set_def n_ps_eq setcompr_eq_image\n  apply (simp add: sem_N_eq N_eq)\n  apply (rule arg_cong2[where f = \"(\\<union>)\"])\n   apply (auto;\n      force split: prod.splits simp:  conv_automaton_def trans_def automaton_of_def n_ps_def)+\n  done\n\nlemma sem_states_eq:\n  \"sem.states = states\"\n  unfolding sem.states_def states_def n_ps_eq setcompr_eq_image\n  by (auto simp: sem_N_eq N_eq;\n      force simp:  conv_automaton_def trans_def automaton_of_def n_ps_def split: prod.splits)+\n\nend (* Simple Network Impl *)\n\n\nlocale Simple_Network_Rename_Defs =\n  Simple_Network_Impl_Defs automata broadcast bounds' for automata ::\n    \"('s list \\<times> 's list \\<times> (('a :: countable) act, 's, 'c, 't, 'x :: countable, int) transition list\n      \\<times> (('s :: countable) \\<times> ('c :: countable, 't) cconstraint) list) list\"\n    and broadcast bounds' +\n  fixes renum_acts   :: \"'a \\<Rightarrow> nat\"\n    and renum_vars   :: \"'x \\<Rightarrow> nat\"\n    and renum_clocks :: \"'c \\<Rightarrow> nat\"\n    and renum_states :: \"nat \\<Rightarrow> 's \\<Rightarrow> nat\"\nbegin\n\ndefinition\n  \"map_cconstraint f g xs = map (map_acconstraint f g) xs\"\n\ndefinition\n  \"renum_cconstraint = map_cconstraint renum_clocks id\"\n\ndefinition\n  \"renum_act = map_act renum_acts\"\n\ndefinition\n  \"renum_bexp = map_bexp renum_vars\"\n\ndefinition\n  \"renum_exp = map_exp renum_vars\"\n\ndefinition\n  \"renum_upd = map (\\<lambda>(x, upd). (renum_vars x, renum_exp upd))\"\n\ndefinition\n  \"renum_reset = map renum_clocks\"\n\ndefinition renum_automaton where\n  \"renum_automaton i \\<equiv> \\<lambda>(committed, urgent, trans, inv). let\n    committed' = map (renum_states i) committed;\n    urgent' = map (renum_states i) urgent;\n    trans' = map (\\<lambda>(l, b, g, a, upd, r, l').\n      (renum_states i l, renum_bexp b, renum_cconstraint g, renum_act a, renum_upd upd,\n       renum_reset r,  renum_states i l')\n    ) trans;\n    inv' = map (\\<lambda>(l, g). (renum_states i l, renum_cconstraint g)) inv\n  in (committed', urgent', trans', inv')\n\"\n\ndefinition\n  \"vars_inv \\<equiv> the_inv renum_vars\"\n\ndefinition\n  \"map_st \\<equiv> \\<lambda>(L, s). (map_index renum_states L, s o vars_inv)\"\n\ndefinition\n  \"clocks_inv \\<equiv> the_inv renum_clocks\"\n\ndefinition\n  \"map_u u = u o clocks_inv\"\n\nlemma map_u_add[simp]:\n  \"map_u (u \\<oplus> d) = map_u u \\<oplus> d\"\n  by (auto simp: map_u_def cval_add_def)\n\ndefinition renum_label where\n  \"renum_label = map_label renum_acts\"\n\nsublocale renum: Simple_Network_Impl_Defs\n  \"map_index renum_automaton automata\"\n  \"map renum_acts broadcast\"\n  \"map (\\<lambda>(a,p). (renum_vars a, p)) bounds'\"\n  .\n\nlemma renum_n_ps_simp[simp]:\n  \"renum.n_ps = n_ps\"\n  unfolding n_ps_def renum.n_ps_def by simp\n\nend (* Simple Network Rename Defs *)\n\n\nlocale Simple_Network_Rename_Defs_int =\n  Simple_Network_Rename_Defs automata +\n  Simple_Network_Impl automata\n  for automata ::\n    \"('s list \\<times> 's list \\<times> (('a :: countable) act, 's, 'c, int, 'x :: countable, int) transition list\n      \\<times> (('s :: countable) \\<times> ('c :: countable, int) cconstraint) list) list\"\nbegin\n\nsublocale renum: Simple_Network_Impl\n  \"map_index renum_automaton automata\"\n  \"map renum_acts broadcast\"\n  \"map (\\<lambda>(a,p). (renum_vars a, p)) bounds'\"\n  .\n\nend (* Simple Network Rename Defs int *)\n\nlemma\n  fixes f :: \"'b :: countable \\<Rightarrow> nat\"\n  assumes \"inj_on f S\" \"finite S\" \"infinite (UNIV :: 'b set)\"\n  shows extend_bij_inj: \"inj (extend_bij f S)\" and extend_bij_surj: \"surj (extend_bij f S)\"\n    and extend_bij_extends: \"\\<forall>x \\<in> S. extend_bij f S x = f x\"\nproof -\n  have \"infinite (\\<nat> :: nat set)\"\n    unfolding Nats_def by simp\n  from assms this have \"bij (extend_bij f S)\"\n    by (intro extend_bij_bij) auto\n  then show \"inj (extend_bij f S)\" and \"surj (extend_bij f S)\"\n    unfolding bij_def by fast+\n  from assms \\<open>infinite \\<nat>\\<close> show \"\\<forall>x \\<in> S. extend_bij f S x = f x\"\n    by (intro extend_bij_extends) auto\nqed\n\nlemma default_map_of_map:\n  \"default_map_of y (map (\\<lambda>(a, b). (f a, g b)) xs) (f a) = g (default_map_of x xs a)\"\n  if \"inj f\" \"y = g x\"\n  using that unfolding default_map_of_alt_def\n  by (auto 4 4 dest: injD[OF that(1)] map_of_SomeD simp: map_of_eq_None_iff map_of_mapk_SomeI)\n\nlemma default_map_of_map_2:\n  \"default_map_of y (map (\\<lambda>(a, b). (a, g b)) xs) a = g (default_map_of x xs a)\" if \"y = g x\"\n  unfolding default_map_of_alt_def using that by (auto simp: map_of_map)\n\nlemma map_of_map':\n  \"map_of (map (\\<lambda>(k, v). (k, f k v)) xs)\n  = (\\<lambda>k. case map_of xs k of Some v \\<Rightarrow> Some (f k v) | _ \\<Rightarrow> None)\"\n  by (induct xs) (auto simp: fun_eq_iff)\n\nlemma default_map_of_map_3:\n  \"default_map_of y (map (\\<lambda>(a, b). (a, g a b)) xs) a = g a (default_map_of x xs a)\"\n  if \"\\<And>k. y = g k x\"\n  unfolding default_map_of_alt_def using that by (auto simp: map_of_map')\n\nlemma dom_map_of_map:\n  \"dom (map_of (map (\\<lambda> (a, b). (f a, g b)) xs)) = f ` fst ` set xs\"\n  unfolding dom_map_of_conv_image_fst by (auto 4 3)\n\nlemma inj_image_eqI:\n  \"S = T\" if \"inj f\" \"f ` S = f ` T\"\n  using that by (meson inj_image_eq_iff)\n\n(* XXX Add this *)\nlemmas [finite_intros] = finite_set\n\nlemma map_of_NoneI:\n  \"map_of xs x = None\" if \"x \\<notin> fst ` set xs\"\n  by (simp add: map_of_eq_None_iff that)\n\nlemma bij_f_the_inv_f:\n  \"f (the_inv f x) = x\" if \"bij f\"\n  using that f_the_inv_f unfolding bij_def by (simp add: f_the_inv_f)\n\n\nfun map_sexp ::\n  \"(nat \\<Rightarrow> 's \\<Rightarrow> 's1) \\<Rightarrow> ('a \\<Rightarrow> 'a1) \\<Rightarrow> ('b \\<Rightarrow> 'b1) \\<Rightarrow> (nat, 's, 'a, 'b) sexp\n    \\<Rightarrow> (nat, 's1, 'a1, 'b1) sexp\"\n  where\n  \"map_sexp _ _ _ sexp.true = sexp.true\" |\n  \"map_sexp f g h (not e) = not (map_sexp f g h e)\" |\n  \"map_sexp f g h (and e1 e2) = and (map_sexp f g h e1) (map_sexp f g h e2)\" |\n  \"map_sexp f g h (sexp.or e1 e2) = sexp.or (map_sexp f g h e1) (map_sexp f g h e2)\" |\n  \"map_sexp f g h (imply e1 e2) = imply (map_sexp f g h e1) (map_sexp f g h e2)\" |\n  \"map_sexp f g h (eq i x) = eq (g i) (h x)\" |\n  \"map_sexp f g h (lt i x) = lt (g i) (h x)\" |\n  \"map_sexp f g h (le i x) = le (g i) (h x)\" |\n  \"map_sexp f g h (ge i x) = ge (g i) (h x)\" |\n  \"map_sexp f g h (gt i x) = gt (g i) (h x)\" |\n  \"map_sexp f g h (loc i x) = loc i (f i x)\"\n\nfun map_formula ::\n  \"(nat \\<Rightarrow> 's \\<Rightarrow> 's1) \\<Rightarrow> ('a \\<Rightarrow> 'a1) \\<Rightarrow> ('b \\<Rightarrow> 'b1)\n  \\<Rightarrow> (nat, 's, 'a, 'b) formula \\<Rightarrow> (nat, 's1, 'a1, 'b1) formula\"\nwhere\n  \"map_formula f g h (formula.EX \\<phi>) = formula.EX (map_sexp f g h \\<phi>)\" |\n  \"map_formula f g h (EG \\<phi>) = EG (map_sexp f g h \\<phi>)\" |\n  \"map_formula f g h (AX \\<phi>) = AX (map_sexp f g h \\<phi>)\" |\n  \"map_formula f g h (AG \\<phi>) = AG (map_sexp f g h \\<phi>)\" |\n  \"map_formula f g h (Leadsto \\<phi> \\<psi>) = Leadsto (map_sexp f g h \\<phi>) (map_sexp f g h \\<psi>)\"\n\n\nlocale Simple_Network_Impl_real =\n  fixes automata ::\n    \"('s list \\<times> 's list \\<times> ('a act, 's, 'c, real, 'x, int) transition list\n      \\<times> ('s \\<times> ('c, real) cconstraint) list) list\"\n    and broadcast :: \"'a list\"\n    and bounds' :: \"('x \\<times> (int \\<times> int)) list\"\nbegin\n\nsublocale Simple_Network_Impl_Defs automata broadcast bounds' .\n\nabbreviation \"sem \\<equiv> (set broadcast, map automaton_of automata, map_of bounds')\"\n\nsublocale Prod_TA_sem \"(set broadcast, map automaton_of automata, map_of bounds')\" .\n\nend\n\ncontext Simple_Network_Impl\nbegin\n\nlemma sem_state_guard_eq:\n  \"(fst \\<circ> snd) ` trans (sem.N p) = (fst \\<circ> snd) ` trans (N p)\" if \"p < n_ps\"\n  unfolding sem_N_eq[OF \\<open>p < n_ps\\<close>] N_eq[OF \\<open>p < n_ps\\<close>]\n  unfolding automaton_of_def conv_automaton_def trans_def\n  by (force split: prod.splits)\n\nlemma sem_state_update_eq:\n  \"(fst \\<circ> snd \\<circ> snd \\<circ> snd \\<circ> snd) ` trans (sem.N p) = (fst \\<circ> snd \\<circ> snd \\<circ> snd \\<circ> snd) ` trans (N p)\"\n  if \"p < n_ps\"\n  unfolding sem_N_eq[OF \\<open>p < n_ps\\<close>] N_eq[OF \\<open>p < n_ps\\<close>]\n  unfolding automaton_of_def conv_automaton_def trans_def\n  by (force split: prod.splits)\n\nlemma sem_var_set_eq:\n  \"sem.var_set = var_set\"\n  unfolding sem.var_set_def var_set_def n_ps_eq using sem_state_guard_eq sem_state_update_eq\n  by (simp cong: image_cong_simp add: setcompr_eq_image)\n\nend\n\nlocale Simple_Network_Rename_Defs_real =\n  Simple_Network_Rename_Defs automata +\n  Simple_Network_Impl_real automata\n  for automata ::\n    \"('s list \\<times> 's list\n      \\<times> (('a :: countable) act, 's, 'c, real, 'x :: countable, int) transition list\n      \\<times> (('s :: countable) \\<times> ('c :: countable, real) cconstraint) list) list\"\nbegin\n\nsublocale renum: Simple_Network_Impl_real\n  \"map_index renum_automaton automata\"\n  \"map renum_acts broadcast\"\n  \"map (\\<lambda>(a,p). (renum_vars a, p)) bounds'\"\n  .\n\nend (* Simple Network Rename Defs *)\n\nlocale Simple_Network_Rename' =\n  Simple_Network_Rename_Defs where automata = automata for automata ::\n    \"('s list \\<times> 's list\n      \\<times> (('a :: countable) act, 's, 'c, 't, 'x :: countable, int) transition list\n      \\<times> (('s :: countable) \\<times> ('c :: countable, 't) cconstraint) list) list\" +\n  assumes bij_renum_clocks: \"bij renum_clocks\"\n      and renum_states_inj: \"\\<forall>p<n_ps. inj (renum_states p)\"\n      and bij_renum_vars: \"bij renum_vars\"\n      and bounds'_var_set: \"fst ` set bounds' = var_set\"\n      and inj_renum_acts: \"inj renum_acts\"\n\nlocale Simple_Network_Rename_real =\n  Simple_Network_Rename_Defs_real where automata = automata +\n  Simple_Network_Rename' where automata = automata\n  for automata ::\n    \"('s list \\<times> 's list\n      \\<times> (('a :: countable) act, 's, 'c, real, 'x :: countable, int) transition list\n      \\<times> (('s :: countable) \\<times> ('c :: countable, real) cconstraint) list) list\" +\n  assumes urgency_removed: \"\\<forall>i < n_ps. urgent (N i) = {}\"\nbegin\n\nlemma aux_1:\n  \"(\\<lambda>x. case case x of\n          (l, g) \\<Rightarrow> (renum_states p l, renum_cconstraint g) of\n     (s, cc) \\<Rightarrow> (s, map conv_ac cc))\n  = (\\<lambda> (l, g). (renum_states p l, map conv_ac (renum_cconstraint g)))\n\"\n  by auto\n\nlemma clocks_inv_inv:\n  \"clocks_inv (renum_clocks a) = a\"\n  unfolding clocks_inv_def by (subst the_inv_f_f; rule bij_renum_clocks[THEN bij_is_inj] HOL.refl)\n\nlemma map_u_renum_cconstraint_clock_valI:\n  \"map_u u \\<turnstile> renum_cconstraint cc\" if \"u \\<turnstile> cc\"\n  using that\n  unfolding clock_val_def list_all_length\n  unfolding renum_cconstraint_def map_cconstraint_def\n  unfolding map_u_def\n  apply clarsimp\n  subgoal for n\n    by (cases \"cc ! n\") (auto 4 4 simp: clocks_inv_inv split: acconstraint.split)\n  done\n\nlemma map_u_renum_cconstraint_clock_valD:\n  \"u \\<turnstile> cc\" if \"map_u u \\<turnstile> renum_cconstraint cc\"\n  using that\n  unfolding clock_val_def list_all_length\n  unfolding renum_cconstraint_def map_cconstraint_def\n  unfolding map_u_def\n  apply clarsimp\n  subgoal for n\n    by (cases \"cc ! n\") (auto 4 4 simp: clocks_inv_inv split: acconstraint.split)\n  done\n\nlemma inj_renum_states: \"inj (renum_states p)\" if \"p < n_ps\"\n  using renum_states_inj \\<open>p < n_ps\\<close> by blast\n\nlemma inv_renum_sem_I:\n  assumes\n    \"u \\<turnstile> Simple_Network_Language.inv (N p) l\" \"p < n_ps\" \"l \\<in> loc_set\"\n  shows\n    \"map_u u \\<turnstile> Simple_Network_Language.inv (renum.N p) (renum_states p l)\"\n  using assms\n  unfolding inv_def\n  apply -\n  apply (subst (asm) N_eq, assumption)\n  apply (subst renum.N_eq, subst renum_n_ps_simp, assumption)\n  apply (subst nth_map_index, simp add: n_ps_def)\n  unfolding conv_automaton_def automaton_of_def\n  apply (auto split: prod.split_asm simp: renum_automaton_def comp_def)\n  unfolding aux_1\n  apply (subst default_map_of_map[where x = \"[]\"])\n  subgoal\n    by (intro inj_renum_states \\<open>p < n_ps\\<close>)\n   apply (simp add: renum_cconstraint_def map_cconstraint_def; fail)\n  apply (erule map_u_renum_cconstraint_clock_valI)\n  done\n\nlemma inv_renum_sem_D:\n  assumes\n    \"map_u u \\<turnstile> Simple_Network_Language.inv (renum.N p) (renum_states p l)\" \"p < n_ps\" \"l \\<in> loc_set\"\n  shows\n    \"u \\<turnstile> Simple_Network_Language.inv (N p) l\"\n  using assms\n  unfolding inv_def\n  apply -\n  apply (subst N_eq, assumption)\n  apply (subst (asm) renum.N_eq, subst renum_n_ps_simp, assumption)\n  apply (subst (asm) nth_map_index, simp add: n_ps_def)\n  unfolding conv_automaton_def automaton_of_def\n  apply (auto split: prod.split simp: renum_automaton_def comp_def)\n  unfolding aux_1\n  apply (subst (asm) default_map_of_map[where x = \"[]\"])\n  subgoal\n    by (intro inj_renum_states \\<open>p < n_ps\\<close>)\n   apply (simp add: renum_cconstraint_def map_cconstraint_def; fail)\n  apply (erule map_u_renum_cconstraint_clock_valD)\n  done\n\nlemma dom_the_inv_comp:\n  \"dom (m o the_inv f) = f ` dom m\" if \"inj f\" \"range f = UNIV\"\n  unfolding dom_def\n  apply auto\n  subgoal for x y\n    apply (subgoal_tac \"f (the_inv f x) = x\")\n     apply force\n    using that by (auto intro: f_the_inv_f)\n  subgoal for x y\n    using that by (auto simp: the_inv_f_f)\n  done\n\nlemma inj_renum_vars:\n  \"inj renum_vars\"\n  using bij_renum_vars unfolding bij_def ..\n\nlemma surj_renum_vars:\n  \"surj renum_vars\"\n  using bij_renum_vars unfolding bij_def ..\n\nlemma map_of_inv_map:\n  \"map_of xs (the_inv f x) = map_of (map (\\<lambda> (a, b). (f a, b)) xs) x\"\n  if \"inj f\" \"surj f\" \"the_inv f x \\<in> dom (map_of xs)\"\n  apply (subgoal_tac \"x = f (the_inv f x)\")\n  subgoal premises prems\n    using domD[OF that(3)] \\<open>inj f\\<close>\n    apply (subst (2) prems)\n    apply safe\n    apply (subst map_of_mapk_SomeI; assumption)\n    done\n  subgoal\n    apply (rule sym, rule f_the_inv_f)\n    using that by auto\n  done\n\nlemma dom_vars_invD:\n  assumes \"x \\<in> dom (s \\<circ> vars_inv)\"\n  shows \"x \\<in> renum_vars ` dom s\" (is ?A) and \"the_inv renum_vars x \\<in> dom s\" (is ?B)\nproof -\n  show ?A\n    using assms unfolding vars_inv_def dom_the_inv_comp[OF inj_renum_vars surj_renum_vars] .\n  then show ?B\n    apply (elim imageE)\n    apply simp\n    apply (subst the_inv_f_f, rule inj_renum_vars, assumption)\n    done\nqed\n\nlemma bounded_renumI:\n  assumes \"bounded (map_of bounds') s\"\n  shows \"bounded (map_of (map (\\<lambda>(a, y). (renum_vars a, y)) bounds')) (s o vars_inv)\"\n  using assms unfolding bounded_def\n  apply elims\n  apply intros\n  subgoal\n    unfolding dom_map_of_conv_image_fst vars_inv_def\n    by (auto intro!: image_cong simp: dom_the_inv_comp[OF inj_renum_vars surj_renum_vars] image_comp)\n  subgoal for x\n    apply (frule dom_vars_invD)\n    apply (frule dom_vars_invD(2))\n    apply (drule bspec, assumption)\n    apply (auto simp: map_of_inv_map[OF inj_renum_vars surj_renum_vars] vars_inv_def)\n    done\n  subgoal for x\n    apply (frule dom_vars_invD)\n    apply (frule dom_vars_invD(2))\n    apply (drule bspec, assumption)\n    apply (auto simp: map_of_inv_map[OF inj_renum_vars surj_renum_vars] vars_inv_def)\n    done\n  done\n\nlemma map_of_renum_vars_simp:\n  assumes\n    \"dom (s o vars_inv)\n     = dom (map_of (map (\\<lambda>(a, y). (renum_vars a, y)) bounds'))\"\n    \"x \\<in> dom s\" \"dom s \\<subseteq> var_set\"\n  shows \"map_of (map (\\<lambda>(a, y). (renum_vars a, y)) bounds') (renum_vars x) = map_of bounds' x\"\nproof -\n  have *:\n    \"map (\\<lambda>(a, y). (renum_vars a, y)) bounds' = map (\\<lambda>(a, y). (renum_vars a, y)) bounds'\"\n    by auto\n  have \"x \\<in> dom (map_of bounds')\"\n    unfolding dom_map_of_conv_image_fst\n    using assms\n    unfolding vars_inv_def\n    apply -\n    apply (subst (asm) dom_the_inv_comp, rule inj_renum_vars, rule surj_renum_vars)\n    apply (subst (asm) dom_map_of_map)\n    apply auto\n    apply (subst (asm) inj_on_image_eq_iff[OF inj_renum_vars])\n    by auto\n  then obtain y where \"map_of bounds' x = Some y\"\n    by auto\n  then show ?thesis\n    by (subst map_of_mapk_SomeI) (auto intro: inj_renum_vars)\nqed\n\nlemma bounded_renumD:\n  assumes\n    \"Simple_Network_Language.bounded\n     (map_of (map (\\<lambda>(a, y). (renum_vars a, y)) bounds')) (s o vars_inv)\"\n    and \"dom s \\<subseteq> var_set\"\n  shows \"Simple_Network_Language.bounded (map_of bounds') s\"\nproof -\n  show ?thesis\n    using assms(1)\n    unfolding bounded_def\n    apply elims\n    apply intros\n    subgoal\n      unfolding vars_inv_def\n      apply (subst (asm) dom_the_inv_comp[OF inj_renum_vars surj_renum_vars])\n      apply (subst (asm) dom_map_of_map)\n      apply (rule inj_image_eqI[OF inj_renum_vars], simp add: dom_map_of_conv_image_fst)\n      done\n    subgoal for x\n      using assms(2) unfolding vars_inv_def\n      apply (subst (asm) (2) dom_the_inv_comp[OF inj_renum_vars surj_renum_vars])\n      apply (drule bspec, erule imageI)\n      apply (simp add: the_inv_f_f[OF inj_renum_vars] map_of_renum_vars_simp[unfolded vars_inv_def])\n      done\n    subgoal for x\n      using assms(2) unfolding vars_inv_def\n      apply (subst (asm) (2) dom_the_inv_comp[OF inj_renum_vars surj_renum_vars])\n      apply (drule bspec, erule imageI)\n      apply (simp add: the_inv_f_f[OF inj_renum_vars] map_of_renum_vars_simp[unfolded vars_inv_def])\n      done\n    done\nqed\n\nlemma dom_bounds_var_set: \"dom bounds = var_set\"\n  unfolding dom_bounds using bounds'_var_set .\n\nlemma sem_states_loc_setD: \"L ! p \\<in> loc_set\" if \"p < length automata\" \"L \\<in> states\" for L p\n  using that states_loc_set by (force simp: n_ps_def)\n\nlemma trans_N_renumD:\n  assumes \"(l, b, g, a, f, r, l') \\<in> Simple_Network_Language.trans (N p)\" \"p < n_ps\"\n  shows \"(renum_states p l, renum_bexp b, renum_cconstraint g, renum_act a, renum_upd f, renum_reset r, renum_states p l')\n  \\<in> Simple_Network_Language.trans (renum.N p)\"\n  using assms\n  unfolding mem_trans_N_iff[OF assms(2)] renum.mem_trans_N_iff[unfolded renum_n_ps_simp, OF assms(2)]\n  by (force split: prod.split simp: renum_automaton_def n_ps_def)\n\nlemma match_assumption2:\n  assumes \"P a1 b1\" \"a1 = a\" \"b1 = b\" shows \"P a b\"\n  using assms by auto\n\nlemma inj_pair:\n  assumes \"inj f\" \"inj g\"\n  shows \"inj (\\<lambda>(a, b). (f a, g b))\"\n  using assms unfolding inj_on_def by auto\n\nlemma injective_functions:\n  \"inj renum_reset\" \"inj renum_upd\" \"inj renum_act\" \"inj renum_cconstraint\" \"inj renum_bexp\"\n  \"\\<And>p. p < length automata \\<Longrightarrow> inj (renum_states p)\"\n  subgoal\n    unfolding renum_reset_def using bij_renum_clocks[THEN bij_is_inj] by simp\n  subgoal\n    unfolding renum_upd_def renum_exp_def using bij_renum_vars[THEN bij_is_inj]\n    by (intro inj_pair exp.inj_map inj_mapI)\n  subgoal\n    unfolding renum_act_def using inj_renum_acts by (rule act.inj_map)\n  subgoal\n    unfolding renum_cconstraint_def map_cconstraint_def\n    by (intro inj_mapI acconstraint.inj_map bij_renum_clocks bij_is_inj bij_id)\n  subgoal\n    unfolding renum_bexp_def by (intro bexp.inj_map inj_renum_vars)\n  subgoal\n    by (rule inj_renum_states, simp add: n_ps_def)\n  done\n\nlemma trans_N_renumI:\n  assumes \"(\n    renum_states p l, renum_bexp b, renum_cconstraint g, renum_act a, renum_upd f, renum_reset r,\n    renum_states p l')\n  \\<in> trans (renum.N p)\"  \"p < n_ps\"\n  shows \"(l, b, g, a, f, r, l') \\<in> trans (N p)\"\n  using assms\n  unfolding mem_trans_N_iff[OF assms(2)] renum.mem_trans_N_iff[unfolded renum_n_ps_simp, OF assms(2)]\n  apply (clarsimp split: prod.split_asm simp: renum_automaton_def n_ps_def)\n  apply (fo_rule match_assumption2, assumption)\n   apply (auto elim!: injD[rotated, THEN sym] intro: injective_functions)\n  done\n\nlemma renum_acconstraint_eq_convD:\n  assumes \"map_acconstraint renum_clocks id g = conv_ac g'\"\n  obtains g1 where \"g = conv_ac g1\" \"g' = map_acconstraint renum_clocks id g1\"\n  subgoal premises\n    using assms\n    apply (cases g'; cases g; clarsimp)\n    subgoal for m c\n      by (rule that[of \"acconstraint.LT c m\"]; simp)\n    subgoal for m c\n      by (rule that[of \"acconstraint.LE c m\"]; simp)\n    subgoal for m c\n      by (rule that[of \"acconstraint.EQ c m\"]; simp)\n    subgoal for m c\n      by (rule that[of \"acconstraint.GT c m\"]; simp)\n    subgoal for m c\n      by (rule that[of \"acconstraint.GE c m\"]; simp)\n    done\n  done\n\nlemma renum_cconstraint_eq_convD:\n  assumes \"renum_cconstraint g = conv_cc g'\"\n  obtains g1 where \"g = conv_cc g1\" \"g' = renum_cconstraint g1\"\nproof -\n  let ?f = \"\\<lambda>(ac, ac'). SOME ac1. ac = conv_ac ac1 \\<and> ac' = map_acconstraint renum_clocks id ac1\"\n  let ?g = \"map ?f (zip g g')\"\n  from assms have \"length g = length g'\"\n    unfolding renum_cconstraint_def map_cconstraint_def by -(drule arg_cong[where f = length], simp)\n  then have \"g = conv_cc ?g \\<and> g' = renum_cconstraint ?g\"\n    using assms\n    by (simp add: comp_def renum_cconstraint_def map_cconstraint_def)\n       (induction rule: list_induct2; simp; elim conjE renum_acconstraint_eq_convD; smt someI)\n  then show ?thesis\n    by (blast intro: that)\nqed\n\nlemma trans_sem_N_renumI:\n  assumes \"(\n  renum_states p l, renum_bexp b, renum_cconstraint g, renum_act a, renum_upd f, renum_reset r,\n  renum_states p l')\n  \\<in> trans (renum.N p)\" \"p < n_ps\"\n  shows \"(l, b, g, a, f, r, l') \\<in> trans (N p)\"\n  using assms(1) \\<open>p < n_ps\\<close> by (simp add: trans_N_renumI)\n\nlemma trans_sem_N_renumI':\n  assumes \"(renum_states p l, b, g, a, f, r, l') \\<in> trans (renum.N p)\" \"p < n_ps\"\n  shows \"\\<exists> b' g' a' f' r' l1.\n    (l, b', g', a', f', r', l1) \\<in> Simple_Network_Language.trans (N p)\n    \\<and> b = renum_bexp b' \\<and> g = renum_cconstraint g' \\<and> a = renum_act a' \\<and> f = renum_upd f'\n    \\<and> r = renum_reset r' \\<and> l' = renum_states p l1\"\nproof -\n  obtain b' g' a' f' r' l1 where \"b = renum_bexp b'\" \"g = renum_cconstraint g'\" \"f = renum_upd f'\"\n    \"a = renum_act a'\" \"r = renum_reset r'\" \"l' = renum_states p l1\"\n    using assms\n    unfolding N_eq[OF assms(2)] renum.N_eq[unfolded renum_n_ps_simp, OF assms(2)]\n    apply (subst (asm) nth_map_index)\n    subgoal\n      by (simp add: n_ps_def)\n    unfolding renum_automaton_def automaton_of_def trans_def by (auto split: prod.split_asm)\n  with assms show ?thesis\n    by (fastforce dest!: trans_sem_N_renumI)\nqed\n\nlemma committed_renum_eq:\n  \"committed (renum.N p) = renum_states p ` committed (N p)\" if \"p < n_ps\"\n  unfolding\n    committed_def N_eq[OF \\<open>p < n_ps\\<close>] renum.N_eq[unfolded renum_n_ps_simp, OF \\<open>p < n_ps\\<close>]\n  apply (subst nth_map_index)\n  subgoal\n    using \\<open>p < n_ps\\<close> by (simp add: n_ps_def)\n  unfolding automaton_of_def conv_automaton_def renum_automaton_def by (simp split: prod.split)\n\nlemma urgent_renum_eq:\n  \"urgent (renum.N p) = renum_states p ` urgent (N p)\" if \"p < n_ps\"\n  unfolding\n    urgent_def N_eq[OF \\<open>p < n_ps\\<close>] renum.N_eq[unfolded renum_n_ps_simp, OF \\<open>p < n_ps\\<close>]\n  apply (subst nth_map_index)\n  subgoal\n    using \\<open>p < n_ps\\<close> by (simp add: n_ps_def)\n  unfolding automaton_of_def conv_automaton_def renum_automaton_def by (simp split: prod.split)\n\nlemma renum_urgency_removed:\n  \"\\<forall>i < n_ps. urgent (renum.N i) = {}\"\n  using urgency_removed\n  apply intros\n  apply (simp only: urgent_renum_eq)\n  apply simp\n  done\n\nlemma check_bexp_renumD:\n  \"check_bexp s b bv \\<Longrightarrow> check_bexp (s o vars_inv) (renum_bexp b) bv\"\nand is_val_renumD:\n  \"is_val s e v \\<Longrightarrow> is_val (s o vars_inv) (renum_exp e) v\"\n  apply (induction rule: check_bexp_is_val.inducts)\n  apply (auto\n      intro: check_bexp_is_val.intros\n      simp: renum_bexp_def renum_exp_def vars_inv_def the_inv_f_f[OF inj_renum_vars])\n  using is_val.simps apply fastforce+\n  done\n\nmethod solve_case =\n  auto \n    intro: check_bexp_is_val.intros\n    simp: renum_bexp_def renum_exp_def vars_inv_def the_inv_f_f[OF inj_renum_vars];\n  fail\n| use is_val.simps in fastforce\n\nlemma check_bexp_renumI:\n  \"check_bexp (s o vars_inv) (renum_bexp b) bv \\<Longrightarrow> check_bexp s b bv\"\n  and is_val_renumI:\n  \"is_val (s o vars_inv) (renum_exp e) v \\<Longrightarrow> is_val s e v\"\n  apply (induction\n      \"s o vars_inv\" \"renum_bexp b\" bv and \"s o vars_inv\" \"renum_exp e\" _\n      arbitrary: b and e rule: check_bexp_is_val.inducts)\n  subgoal for b\n    by (cases b; solve_case)\n  subgoal for e bv b\n    by (cases b; solve_case)\n  subgoal for e1 a e2 bv b\n    by (cases b; solve_case)\n  subgoal for e1 a e2 bv b\n    by (cases b; solve_case)\n  subgoal for e1 a e2 bv b\n    by (cases b; solve_case)\n  subgoal for a v bv x b\n    by (cases b; solve_case)\n  subgoal for a v bv x b\n    by (cases b; solve_case)\n  subgoal for a v bv x b\n    by (cases b; solve_case)\n  subgoal for a v bv x b\n    by (cases b; solve_case)\n  subgoal for a v bv x b\n    by (cases b; solve_case)\n  subgoal for c e\n    by (cases e; solve_case)\n  subgoal for x v e\n    by (cases e; solve_case)\n  subgoal for e1 v1 e2 v2 b bv e\n    by (auto simp: renum_bexp_def renum_exp_def; cases e; solve_case)\n  subgoal for e1 v1 e2 v2 f e\n    by (auto simp: renum_bexp_def renum_exp_def; cases e; solve_case)\n  subgoal for e1 v f e\n    by (cases e; solve_case)\n  done\n\nlemma renum_reset_map_u:\n  \"[renum_reset r\\<rightarrow>0]map_u u = map_u ([r\\<rightarrow>0]u)\"\n  unfolding map_u_def\n  apply (rule ext)\n  subgoal for x\n    apply (cases \"clocks_inv x \\<in> set r\"; simp add: clocks_inv_def)\n    subgoal\n      using bij_renum_clocks[THEN bij_is_surj]\n      by (auto\n            simp: renum_reset_def f_the_inv_f[OF bij_is_inj, OF bij_renum_clocks]\n            dest: imageI[where f = renum_clocks]\n         )\n    subgoal\n      by (subst clock_set_id)\n         (auto simp: renum_reset_def the_inv_f_f[OF bij_is_inj, OF bij_renum_clocks])\n    done\n  done\n\nlemma bounded_renumI':\n  assumes \"bounded bounds s'\"\n  shows \"bounded renum.bounds (s' o vars_inv)\"\n  using assms unfolding renum.bounds_def bounds_def by (simp add: bounded_renumI)\n\nlemma bounded_renumD':\n  assumes \"bounded renum.bounds (s' o vars_inv)\" \"dom s' \\<subseteq> var_set\"\n  shows \"bounded bounds s'\"\n  using assms unfolding renum.bounds_def bounds_def by (simp add: bounded_renumD)\n\nlemma is_upd_renumD:\n  assumes \"is_upd s f s'\"\n  shows \"is_upd (s o vars_inv) (renum_upd f) (s' o vars_inv)\"\n  using assms\n  unfolding is_upd_def\n  apply clarsimp\n  subgoal for xs\n    apply (inst_existentials \"map (\\<lambda>(x,v). (renum_vars x, v)) xs\")\n     apply (clarsimp elim!: list_all2_mono is_val_renumD simp: list.rel_map renum_upd_def; fail)\n    apply (rule ext)\n    subgoal premises prems for a\n      apply (induction xs arbitrary: s)\n       apply (simp; fail)\n      apply simp\n      apply (fo_rule arg_cong2)\n       apply (auto 4 4\n          simp: bij_f_the_inv_f[OF bij_renum_vars] the_inv_f_f[OF inj_renum_vars] vars_inv_def)\n      done\n    done\n  done\n\nlemma is_upds_renumD:\n  assumes \"is_upds s1 ps s'\"\n  shows \"is_upds (s1 o vars_inv) (map renum_upd ps) (s' o vars_inv)\"\n  using assms by induction (auto intro: is_upds.intros simp: comp_def dest!: is_upd_renumD)\n\nlemma Ball_mono:\n  assumes \"\\<forall>x \\<in> S. P x\" \"\\<And>x. x \\<in> S \\<Longrightarrow> P x \\<Longrightarrow> Q x\"\n  shows \"\\<forall>x \\<in> S. Q x\"\n  using assms by blast\n\nlemma atLeastLessThan_upperD:\n  assumes \"S \\<subseteq> {l..<u}\" \"x \\<in> S\"\n  shows \"x < u\"\n  using assms by auto\n\nlemma imp_mono_rule:\n  assumes \"P1 \\<longrightarrow> P2\"\n    and \"Q1 \\<Longrightarrow> P1\"\n    and \"Q1 \\<Longrightarrow> P2 \\<Longrightarrow> Q2\"\n  shows \"Q1 \\<longrightarrow> Q2\"\n  using assms by blast\n\nlemma inj_id:\n  \"inj id\"\n  by auto\n\nlemma step_single_renumD:\n  assumes \"step_u sem L s u a L' s' u'\" \"L \\<in> states\" \"dom s \\<subseteq> var_set\"\n  shows \"step_u renum.sem\n    (map_index renum_states L) (s o vars_inv) (map_u u)\n    (renum_label a)\n    (map_index renum_states L') (s' o vars_inv) (map_u u')\"\n  using assms(1-3)\n  apply (cases a)\n\n     supply [simp del] = map_map_index set_map\n    (* to keep the simplifier from breaking through locale abstractions *)\n\n(* Delay *)\n  subgoal\n    supply [simp] = length_automata_eq_n_ps L_len\n    apply (subst (asm) A_split)\n    apply (subst renum.A_split)\n    apply (simp only: renum_label_def label.map renum_n_ps_simp)\n    apply (erule step_u_elims')\n    apply simp\n    apply (rule step_u.intros)\n    subgoal\n      by auto_tag (auto 4 3 simp: dest: inv_renum_sem_I[OF _ _ sem_states_loc_setD])\n    subgoal\n      by assumption\n    subgoal\n      using renum_urgency_removed by - (tag, auto)\n    subgoal\n      by auto_tag (rule bounded_renumI')\n    done\n\n(* Internal *)\n  subgoal for a'\n    supply [simp] = length_automata_eq_n_ps L_len\n    apply (subst (asm) A_split)\n    apply (subst renum.A_split)\n    apply (simp only: renum_label_def label.map renum_n_ps_simp)\n    apply (erule step_u_elims')\n    unfolding TAG_def[of \"''range''\"]\n    apply simp\n    apply (rule step_u.intros)\n              apply (auto_tag, drule (1) trans_N_renumD, subst nth_map, (simp add: renum_act_def)+; fail)\n    subgoal\n      by auto_tag (auto simp: committed_renum_eq dest!: inj_renum_states[THEN injD, rotated])\n    subgoal\n      by auto_tag (erule check_bexp_renumD)\n    subgoal\n      by auto_tag (rule map_u_renum_cconstraint_clock_valI)\n    subgoal\n      apply (auto_tag keep: TAG[of \"''new loc''\"] TAG[of \"TRANS ''silent''\"])\n      apply clarsimp\n      apply (rule inv_renum_sem_I[OF _ _ sem_states_loc_setD[OF _ state_preservation_updI]])\n          apply fastforce+\n      done\n         apply (auto_tag, simp; fail)\n        apply (auto_tag, simp; fail)\n       apply (auto_tag, rule map_index_update; fail)\n      apply (auto_tag, simp add: renum_reset_map_u; fail)\n    subgoal\n      by (auto_tag, erule is_upd_renumD)\n    apply (auto_tag, erule bounded_renumI'; fail)\n    done\n\n(* Binary *)\n  subgoal for a'\n    supply [simp] = length_automata_eq_n_ps L_len\n    apply (subst (asm) A_split)\n    apply (subst renum.A_split)\n    apply (simp only: renum_label_def label.map renum_n_ps_simp)\n    apply (erule step_u_elims')\n    unfolding TAG_def[of \"RECV ''range''\"] TAG_def[of \"SEND ''range''\"]\n    apply simp\n    apply (rule step_u.intros)\n    subgoal\n      apply auto_tag\n      unfolding renum.broadcast_def\n      apply (clarsimp simp: set_map)\n      apply (drule injD[OF inj_renum_acts])\n      apply (subst (asm) broadcast_def, simp)\n      done\n\n                     apply (auto_tag, drule (1) trans_N_renumD, subst nth_map, (simp add: renum_act_def)+; fail)\n                    apply (auto_tag, drule (1) trans_N_renumD, subst nth_map, (simp add: renum_act_def)+; fail)\n    subgoal\n      by auto_tag (auto simp: committed_renum_eq dest!: inj_renum_states[THEN injD, rotated])\n\n    subgoal\n      by auto_tag (erule check_bexp_renumD)\n\n    subgoal\n      by auto_tag (erule check_bexp_renumD)\n\n    subgoal\n      by auto_tag (rule map_u_renum_cconstraint_clock_valI)\n\n    subgoal\n      by auto_tag (rule map_u_renum_cconstraint_clock_valI)\n\n    subgoal\n      apply (auto_tag keep: TAG[of \"''new loc''\"] TAG[of \"TRANS _\"])\n      apply clarsimp\n      apply (rule inv_renum_sem_I[OF _ _ sem_states_loc_setD[OF _ state_preservation_updI]])\n          apply (fastforce intro!: state_preservation_updI)+\n      done\n             apply (all \\<open>auto_tag\\<close>)\n             apply (simp; fail)+\n        apply (simp add: map_index_update; fail)\n       apply (simp add: renum_reset_map_u[symmetric] renum_reset_def; fail)\n      apply (erule is_upd_renumD; fail)\n     apply (erule is_upd_renumD; fail)\n    apply (erule bounded_renumI'; fail)\n    done\n\n\n(* Broadcast *)\n  subgoal for a'\n    supply [simp] = length_automata_eq_n_ps L_len\n    apply (subst (asm) A_split)\n    apply (subst renum.A_split)\n    apply (simp only: renum_label_def label.map renum_n_ps_simp)\n    apply (erule step_u_elims')\n    apply simp\n    unfolding TAG_def[of \"SEND ''range''\"]\n\n    apply (rule step_u.intros)\n\n(* Action is broadcast *)\n    subgoal\n      apply (tag keep: TAG[of \"''broadcast''\"])\n      unfolding renum.broadcast_def by (subst (asm) broadcast_def, simp add: set_map)\n\n                       apply (auto_tag, simp, drule (1) trans_N_renumD, subst nth_map, (simp add: renum_act_def)+; fail)\n\n                      apply (tag keep: TAG[of \"TRANS ''in''\"] TAG[of \"SEL _\"])\n                      apply (auto dest!: trans_N_renumD simp add: renum_act_def atLeastLessThan_upperD; fail)\n\n(* Condition for committed locations *)\n    subgoal\n      apply (tag keep: TAG[of \"SEL _\"] TAG[of \"''committed''\"])\n      apply (simp add: committed_renum_eq)\n      apply (erule disj_mono[rule_format, rotated 2], (simp; fail))\n      apply (erule disj_mono[rule_format, rotated 2])\n      subgoal\n        apply clarify\n        apply (rule rev_bexI, assumption)\n        apply (auto simp: committed_renum_eq)\n        done\n      apply (auto simp: committed_renum_eq dest!: inj_renum_states[THEN injD, rotated]; fail)\n      done\n\n                    apply (tag keep: TAG[of \"''bexp''\"], erule check_bexp_renumD; fail)\n                   apply (tag keep: TAG[of \"''bexp''\"], auto elim: check_bexp_renumD; fail)\n                  apply (tag keep: TAG[of \"''guard''\"], erule map_u_renum_cconstraint_clock_valI; fail)\n                 apply (tag keep: TAG[of \"''guard''\"], auto elim: map_u_renum_cconstraint_clock_valI; fail)\n\n(* Set of broadcast receivers is maximal *)\n    subgoal\n      apply (tag keep: TAG[of \"''maximal''\"])\n      apply simp\n      apply (erule all_mono[THEN mp, OF impI, rotated])\n      apply (erule (1) imp_mono_rule)\n      apply (erule (1) imp_mono_rule)\n      apply clarify\n      apply (drule trans_sem_N_renumI', assumption)\n      apply (clarsimp simp: renum_act_def)\n      apply (drule check_bexp_renumI)\n      apply (drule InD2[OF inj_renum_acts])\n      apply (fastforce dest!: map_u_renum_cconstraint_clock_valD)\n      done\n\n(* Target invariant *)\n    subgoal for l b g f r l' p ps bs gs fs rs ls' s'\n      apply (tag keep: TAG[of \"''target invariant''\"] TAG[of \"SEL _\"] TAG[of \"''new loc''\"] TAG[of \"TRANS _\"])\n      apply (subgoal_tac \"fold (\\<lambda>p L. L[p := ls' p]) ps L \\<in> states\")\n      subgoal\n        apply simp\n        apply (erule all_mono[THEN mp, OF impI, rotated], erule (1) imp_mono_rule, drule (1) inv_renum_sem_I)\n        subgoal\n          apply (rule sem_states_loc_setD, simp)\n          apply (rule state_preservation_updI)\n          subgoal\n            by blast\n          .\n        subgoal\n          apply (fo_rule match_assumption2[where P = clock_val], assumption, rule HOL.refl)\n          apply (drule states_lengthD, simp)\n          done\n        done\n      subgoal\n        apply (rule state_preservation_fold_updI)\n         apply (erule Ball_mono)\n         apply (simp add: atLeastLessThan_upperD; blast)\n        by simp\n      done\n              apply (tag keep: TAG[of \"SEND ''loc''\"], simp add: TAG_def; fail)\n             apply (tag, simp add: TAG_def; fail)\n            apply (tag keep: TAG[of \"SEL _\"], simp add: TAG_def; fail)\n           apply (tag keep: TAG[of \"SEL _\"], simp add: TAG_def; fail)\n          apply (auto_tag; fail)\n         apply (auto_tag; fail)\n\n        apply (tag keep: TAG[of \"''new loc''\"])\n        apply (simp add: map_trans_broad_aux1[symmetric] map_index_update; fail)\n       apply (tag keep: TAG[of \"''new valuation''\"])\n       apply (simp add: renum_reset_map_u[symmetric] renum_reset_def map_concat comp_def; fail)\n      apply (tag keep: TAG[of \"''upd''\"], erule is_upd_renumD; fail)\n     apply (tag keep: TAG[of \"''upds''\"], drule is_upds_renumD, simp add: comp_def; fail)\n    apply (tag keep: TAG[of \"''bounded''\"], erule bounded_renumI'; fail)\n    done\n  done\n\nlemma inj_the_inv:\n  \"inj (the_inv f)\" if \"bij f\"\n  by (auto simp: bij_f_the_inv_f[OF that] dest: arg_cong[where f = f] intro!: injI)\n\nlemma inj_vars_inv:\n  \"inj vars_inv\"\n  using bij_renum_vars unfolding vars_inv_def by (rule inj_the_inv)\n\nlemma comp_vars_inv_upd_commute:\n  \"(s o vars_inv)(x \\<mapsto> y) = s(vars_inv x \\<mapsto> y) o vars_inv\"\n  by (intro ext) (auto dest: injD[OF inj_vars_inv])\n\nlemma is_upd_renumI:\n  assumes \"is_upd (s o vars_inv) (renum_upd f) s'\"\n  shows \"is_upd s f (s' o renum_vars)\"\n  using assms\n  unfolding is_upd_def\n  apply clarsimp\n  subgoal for xs\n    apply (inst_existentials \"map (\\<lambda>(x,v). (vars_inv x, v)) xs\")\n     apply (clarsimp elim!: list_all2_mono dest!: is_val_renumI simp: list.rel_map renum_upd_def,\n            simp add: the_inv_f_f[OF inj_renum_vars] vars_inv_def; fail)\n    apply (rule ext)\n    subgoal premises prems for a\n      apply (induction xs arbitrary: s)\n       apply (simp add: the_inv_f_f[OF inj_renum_vars] vars_inv_def; fail)\n      apply (auto simp: comp_vars_inv_upd_commute)\n      done\n    done\n  done\n\nlemma is_upd_renumI':\n  assumes \"is_upd (s o vars_inv) (renum_upd f) s'\"\n  obtains s1 where \"is_upd s f s1\" \"s1 = s' o renum_vars\"\n  by (simp add: assms is_upd_renumI)\n\nlemma is_upd_renumI'':\n  assumes \"is_upd s (renum_upd f) s'\"\n  shows \"is_upd (s o renum_vars) f (s' o renum_vars)\"\nproof -\n  have \"s = (s o renum_vars) o vars_inv\"\n    by (intro ext) (auto simp: bij_f_the_inv_f[OF bij_renum_vars] vars_inv_def)\n  with assms  show ?thesis\n    by (intro is_upd_renumI) simp\nqed\n\nlemma is_upds_renumI:\n  assumes \"is_upds (s o vars_inv) (map renum_upd upds) s'\"\n  shows \"\\<exists>s1. is_upds s upds s1 \\<and> s1 = s' o renum_vars\"\n  using assms apply (induction \"s o vars_inv\" \"map renum_upd upds\" s' arbitrary: upds s)\n  subgoal for upds s\n    apply auto\n    apply (subgoal_tac \"s o vars_inv o renum_vars = s\")\n     apply (auto intro: is_upds.intros simp: comp_def)\n    apply (rule ext)\n    apply (simp add: vars_inv_def the_inv_f_f[OF inj_renum_vars])\n    done\n\n  apply clarsimp\n  apply (erule is_upd_renumI')\n  apply (auto simp: vars_inv_def bij_f_the_inv_f[OF bij_renum_vars] comp_def intro!: is_upds.intros)\n  done\n\nlemma is_upds_renumI'':\n  assumes \"is_upds s (map renum_upd ps) s'\"\n  shows \"is_upds (s o renum_vars) ps (s' o renum_vars)\"\n  using assms\n  by (induction \"map renum_upd ps\" s' arbitrary: ps) (auto intro: is_upd_renumI'' is_upds.intros)\n\nlemma bounded_renumD1:\n  assumes \"bounded renum.bounds s'\" \"dom (s' \\<circ> renum_vars) \\<subseteq> var_set\"\n  shows \"bounded bounds (s' o renum_vars)\"\n  using assms\n  by (intro bounded_renumD') (auto simp: vars_inv_def bij_f_the_inv_f[OF bij_renum_vars] comp_def)\n\nlemma renum_reset_append:\n  \"renum_reset xs @ renum_reset ys = renum_reset (xs @ ys)\"\n  unfolding renum_reset_def by simp\n\nlemma if_eq_distrib:\n  \"(if i = j then f i a else f j b) = (f j (if i = j then a else b))\"\n  by auto\n\nlemma dom_comp_eq_vimage:\n  \"dom (s o f) = f -` dom s\"\n  unfolding dom_def by auto\n\nlemma dom_comp_vars_inv_eqD:\n  assumes \"dom s' = dom (s o vars_inv)\"\n  shows \"dom (s' o renum_vars) = dom s\"\n  using assms inj_renum_vars surj_renum_vars unfolding vars_inv_def\n  by (subst (asm) dom_the_inv_comp) (auto simp: dom_comp_eq_vimage dest: injD)\n\nlemma sem_trans_upd_domD:\n  assumes \"(L ! p, b, g', a, f, r, l1) \\<in> trans (N p)\" \"p < n_ps\"\n  shows \"fst ` set f \\<subseteq> var_set\"\nproof -\n  from assms have \"fst ` set f \\<subseteq> var_set\"\n    unfolding var_set_def\n    apply -\n    apply (rule semilattice_sup_class.sup.coboundedI2)\n    apply clarsimp\n    apply (inst_existentials \"(fst \\<circ> snd \\<circ> snd \\<circ> snd \\<circ> snd) ` trans (N p)\" p)\n      apply force+\n    done\n  then show ?thesis .\nqed\n\nlemma SilD:\n  fixes map_action\n  assumes \"Sil a = map_act map_action a1\"\n  obtains a' where \"a1 = Sil a'\" \"a = map_action a'\"\n  using assms by (cases a1) auto\n\nlemma InD:\n  fixes map_action\n  assumes \"In a = map_act map_action a1\"\n  obtains a' where \"a1 = In a'\" \"a = map_action a'\"\n  using assms by (cases a1) auto\n\nlemma OutD:\n  fixes map_action\n  assumes \"Out a = map_act map_action a1\"\n  obtains a' where \"a1 = Out a'\" \"a = map_action a'\"\n  using assms by (cases a1) auto\n\nlemma In_OutD:\n  assumes \"In a = renum_act a1\" \"Out a = renum_act a2\"\n  obtains a' where \"a = renum_acts a'\" \"a1 = In a'\" \"a2 = Out a'\"\n  using assms unfolding renum_act_def by (elim InD OutD) (auto simp: injD[OF inj_renum_acts])\n\nlemma renum_sem_broadcast_eq:\n  \"renum.broadcast = renum_acts ` set broadcast\"\n  unfolding renum.broadcast_def by simp\n\nlemma inj_eq_iff:\n  \"f x = f y \\<longleftrightarrow> x = y\" if \"inj f\"\n  using that unfolding inj_def by auto\n\nlemma trans_sem_N_renum_broadcastI:\n  assumes\n    \"\\<forall>p\\<in>set ps. (renum_states p (L ! p), bs p, gs p, In a, fs p, rs p, ls p) \\<in> trans (renum.N p)\"\n    \"set ps \\<subseteq> {0..<n_ps}\"\n  obtains bs' gs' fs' rs' ls' a' where\n    \"\\<forall>p\\<in>set ps. (L ! p, bs' p, gs' p, In a', fs' p, rs' p, ls' p) \\<in> trans (N p)\"\n    \"\\<forall>p\\<in>set ps. bs p = renum_bexp (bs' p)\"\n    \"\\<forall>p\\<in>set ps. gs p = renum_cconstraint (gs' p)\"\n    \"ps \\<noteq> [] \\<longrightarrow> a = renum_acts a'\"\n    \"\\<forall>p\\<in>set ps. fs p = renum_upd (fs' p)\"\n    \"\\<forall>p\\<in>set ps. rs p = renum_reset (rs' p)\"\n    \"\\<forall>p\\<in>set ps. ls p = renum_states p (ls' p)\"\nproof -\n  define t where\n    \"t p \\<equiv> SOME (b', g', a', f', r', l1). (L ! p, b', g', a', f', r', l1) \\<in> trans (N p)\n    \\<and> bs p = renum_bexp b' \\<and> gs p = renum_cconstraint g' \\<and> In a = renum_act a' \\<and> fs p = renum_upd f'\n    \\<and> rs p = renum_reset r' \\<and> ls p = renum_states p l1\" for p\n  define bs' where \"bs' p \\<equiv> case t p of (b', g', a', f', r', l1) \\<Rightarrow> b'\" for p\n  define gs' where \"gs' p \\<equiv> case t p of (b', g', a', f', r', l1) \\<Rightarrow> g'\" for p\n  define as' where \"as' p \\<equiv> case t p of (b', g', a', f', r', l1) \\<Rightarrow> a'\" for p\n  define fs' where \"fs' p \\<equiv> case t p of (b', g', a', f', r', l1) \\<Rightarrow> f'\" for p\n  define rs' where \"rs' p \\<equiv> case t p of (b', g', a', f', r', l1) \\<Rightarrow> r'\" for p\n  define ls' where \"ls' p \\<equiv> case t p of (b', g', a', f', r', l1) \\<Rightarrow> l1\" for p\n\n  have *: \"case t p of (b', g', a', f', r', l1) \\<Rightarrow>\n    (L ! p, b', g', a', f', r', l1) \\<in> trans (N p)\n    \\<and> bs p = renum_bexp b' \\<and> gs p = renum_cconstraint g' \\<and> In a = renum_act a' \\<and> fs p = renum_upd f'\n    \\<and> rs p = renum_reset r' \\<and> ls p = renum_states p l1\" if \"p \\<in> set ps\" for p\n    using assms(1)\n    apply -\n    apply (drule bspec[OF _ that])\n    apply (drule trans_sem_N_renumI')\n    subgoal\n      using assms(2) that by auto\n    unfolding t_def by (elims, fo_rule someI, auto)\n\n  show ?thesis\n  proof (cases \"ps\")\n    case Nil\n    then show ?thesis\n      by (auto intro: that)\n  next\n    case (Cons p ps')\n    then have \"p \\<in> set ps\"\n      by auto\n    define a' where \"a' = as' p\"\n    have 1: \"as' q = a'\" and \"In a = renum_act a'\" if \"q \\<in> set ps\" for q\n      unfolding as'_def a'_def using *[OF that] *[OF \\<open>p \\<in> set ps\\<close>]\n      by (auto dest: injD[OF injective_functions(3)])\n    then obtain a1 where \"a' = In a1\" \"a = renum_acts a1\"\n      using \\<open>p \\<in> set ps\\<close> unfolding renum_act_def by (auto elim!: InD)\n    then show ?thesis\n      apply -\n      apply (rule that[of bs' gs' a1 fs' rs' ls'])\n      unfolding bs'_def gs'_def fs'_def rs'_def ls'_def\n            apply ((intros, frule *)?, auto simp: as'_def dest: 1; fail)+\n      done\n  qed\nqed\n\nlemmas all_mono_rule = all_mono[THEN mp, OF impI, rotated]\n\nmethod prop_monos =\n  erule all_mono_rule\n  | erule (1) imp_mono_rule\n  | erule disj_mono[rule_format, rotated 2]\n\nlemma inv_sem_N_renum_broadcastI:\n  assumes\n\"\\<forall>pa<n_ps.\n  [renum_reset r @ concat (map rs ps)\\<rightarrow>0]map_u u\n    \\<turnstile> inv (renum.N pa)\n        ((fold (\\<lambda>p L. L[p := ls p]) ps (map_index renum_states L)) [p := renum_states p l1] ! pa)\"\n\"\\<forall>p\\<in>set ps. rs p = renum_reset (rs' p)\"\n\"\\<forall>p\\<in>set ps. ls p = renum_states p (ls' p)\"\n\"\\<forall>p\\<in>set ps. ls' p \\<in> (\\<Union>(l, b, g, a, r, u, l') \\<in> trans (N p). {l, l'})\"\n\"l1 \\<in> (\\<Union>(l, b, g, a, r, u, l') \\<in> trans (N p). {l, l'})\"\n\"L \\<in> states\"\nshows\n\"\\<forall>pa<n_ps.\n  [r @ concat (map rs' ps)\\<rightarrow>0]u \\<turnstile> inv (N pa) ((fold (\\<lambda>p L. L[p := ls' p]) ps L) [p := l1] ! pa)\"\nproof -\n  have [simp]: \"renum_reset r @ concat (map rs ps) = renum_reset (r @ concat (map rs' ps))\"\n    using assms(2) by (simp cong: map_cong add: map_concat renum_reset_def)\n  have [simp]: \"length L = n_ps\"\n    using \\<open>L \\<in> states\\<close> by auto\n  have [simp]:\n    \"((fold (\\<lambda>p L. L[p := ls p]) ps (map_index renum_states L)) [p := renum_states p l1] ! q)\n    = renum_states q ((fold (\\<lambda>p L. L[p := ls' p]) ps L) [p := l1] ! q)\"\n    if \"q < n_ps\" for q\n    using assms(4-) that\n    apply (cases \"p = q\")\n     apply (simp add: fold_upds_aux_length)\n    apply (simp\n        add: assms(3) map_trans_broad_aux1[symmetric] fold_upds_aux_length\n        cong: fold_cong)\n    done\n  have \"(fold (\\<lambda>p L. L[p := ls' p]) ps L)[p := l1] ! q \\<in> loc_set\" if \"q < n_ps\" for q\n    using assms(4-)\n    apply (intro sem_states_loc_setD)\n    subgoal\n      using that by (simp add: n_ps_def)\n    apply (erule state_preservation_updI)\n    by (rule state_preservation_fold_updI)\n  then show ?thesis\n    using assms\n    by (auto dest: inv_renum_sem_D simp: renum_reset_map_u simp del: map_map_index set_map)\nqed\n\nmethod solve_triv =\n  assumption\n  | erule (1) bounded_renumD'; fail\n  | rule inv_renum_sem_D[OF _ _ sem_states_loc_setD]; simp; fail\n  | rule check_bexp_renumI; simp; fail\n  | rule map_u_renum_cconstraint_clock_valD; simp; fail\n  | rule is_upd_renumI is_upd_renumI'' is_upds_renumI'', simp; fail\n  | simp; fail\n  | simp add:\n      vars_inv_def bij_f_the_inv_f[OF bij_renum_vars] renum_reset_map_u[symmetric] map_index_update\n      renum_reset_append;\n    fail\n  | subst nth_map, (simp; fail)+; fail\n  | (rule state_preservation_updI, blast)+, simp; fail\n\nlemma trans_sem_upd_domI:\n  assumes \"(L ! p, b', g', a, f', r', l1) \\<in> trans (N p)\" \"dom s = var_set\" \"p < n_ps\"\n  shows \"\\<forall>(x, _)\\<in>set (renum_upd f'). x \\<in> dom (s o vars_inv)\"\n  unfolding renum_upd_def using assms\n  by (auto simp: dom_comp_eq_vimage vars_inv_def the_inv_f_f[OF inj_renum_vars]\n           dest!: sem_trans_upd_domD)\n\nlemma step_single_renumI:\n  assumes\n    \"step_u renum.sem\n      (map_index renum_states L) (s o vars_inv) (map_u u) a L' s' u'\"\n    \"L \\<in> states\" \"dom s \\<subseteq> var_set\" \"dom s = var_set\"\n  shows \"\\<exists> a1 L1 s1 u1. step_u sem L s u a1 L1 s1 u1 \\<and> renum_label a1 = a \\<and>\n    L' = map_index renum_states L1 \\<and> s' = s1 o vars_inv \\<and> u' = map_u u1\"\n  using assms(1-3)\n  supply [simp] = length_automata_eq_n_ps L_len\n  supply [simp del] = map_map_index set_map\n  apply (subst A_split)\n  apply (subst (asm) renum.A_split)\n  apply (simp only: renum_label_def label.map renum_n_ps_simp)\n\n  using [[goals_limit=2]]\n\n  apply (cases a)\n\n(* Delay *)\n  subgoal\n    apply (simp only:)\n    apply (erule step_u_elims')\n    apply intros\n        apply (rule step_u.intros)\n           apply (auto_tag keep: TAG[of \"''nonnegative''\"], simp, prop_monos+, solve_triv+)\n    subgoal\n      using urgency_removed by - (tag, auto)\n    apply auto_tag\n        apply (auto_tag?, solve_triv)+\n    done\n\n(* Internal *)\n  subgoal for a'\n    apply (simp only:)\n    apply (erule step_u_elims')\n    unfolding TAG_def\n    apply (drule sym[of \"map_index renum_states L ! _\"])\n    apply simp\n    apply (drule (1) trans_sem_N_renumI')\n    apply elims\n    unfolding renum_act_def\n    apply (rule SilD, assumption)\n\n    apply intros\n        apply (rule step_u.intros(2), unfold TAG_def)\n                  apply solve_triv\n\n                 apply (prop_monos; auto simp: committed_renum_eq dest: injD[OF inj_renum_states]; fail)\n\n                apply solve_triv\n               apply solve_triv\n\n(* Target invariant is satisified *)\n              apply (simp add: map_index_update[symmetric] renum_reset_map_u, prop_monos+, rule inv_renum_sem_D[OF _ _ sem_states_loc_setD], solve_triv+; fail)\n\n             apply solve_triv+\n\n(* Resulting state is bounded *)\n        apply (erule bounded_renumD1)\n    subgoal\n      apply (drule is_upd_dom)\n      subgoal\n        apply (simp add: dom_comp_eq_vimage)\n        unfolding renum_upd_def\n        apply (clarsimp simp: vars_inv_def the_inv_f_f[OF inj_renum_vars] set_map)\n        apply (drule (1) sem_trans_upd_domD)\n        using assms(4)\n        apply auto\n        done\n      apply (drule dom_comp_vars_inv_eqD, simp)\n      done\n\n       apply solve_triv\n\n      apply solve_triv\n\n(* or: auto *)\n     apply (rule ext)\n     apply solve_triv+\n    done\n\n\n(* Binary *)\n  subgoal for a'\n    apply (simp only:)\n    apply (erule step_u_elims')\n    unfolding TAG_def\n    apply (drule sym[of \"map_index renum_states L ! _\"])+\n    apply simp\n    apply (drule (1) trans_sem_N_renumI')\n    apply (drule (1) trans_sem_N_renumI')\n    apply elims\n    apply (rule In_OutD, assumption, assumption)\n\n    apply intros\n        apply (rule step_u.intros(3), unfold TAG_def)\n\n                        prefer 2\n                        apply solve_triv\n\n                        apply (clarsimp simp: renum_sem_broadcast_eq broadcast_def; fail)\n\n                        apply solve_triv\n\n    subgoal\n      by (auto simp: committed_renum_eq inj_eq_iff[OF inj_renum_states])\n\n                      apply solve_triv+\n\n(* Target invariant is satisified *)\n                  apply (simp add: map_index_update[symmetric] renum_reset_map_u renum_reset_append, prop_monos+, rule inv_renum_sem_D[OF _ _ sem_states_loc_setD], solve_triv+; fail)\n\n                 apply solve_triv+\n\n(* Resulting state is bounded *)\n        apply (erule bounded_renumD1)\n    subgoal premises prems\n      using prems(2,11-)\n      apply -\n      apply (drule is_upd_dom)\n      subgoal\n        using assms(4) by - (drule trans_sem_upd_domI; simp split: prod.splits)\n      apply (drule is_upd_dom)\n      subgoal\n        using assms(4) by - (drule trans_sem_upd_domI; simp split: prod.splits)\n      apply (simp, drule dom_comp_vars_inv_eqD, simp)\n      done\n    apply (solve_triv, solve_triv)\n     apply (rule ext; solve_triv)\n     apply solve_triv\n    done\n\n(* Broadcast *)\n  subgoal for a'\n    apply (simp only:)\n    apply (erule step_u_elims')\n    unfolding TAG_def[of \"SEND ''range''\"] TAG_def[of \"TRANS ''out''\"]\n    apply (drule TAG_mp[of \"SEND ''loc''\"], rotate_tac -1, erule sym, unfold TAG_def[of \"SEND ''loc''\"])\n    apply simp\n    apply (frule (1) trans_sem_N_renumI')\n    apply elims\n    subgoal for l b g f r l' p ps bs gs fs rs ls' s'a b' g' a'a f' r' l1\n      unfolding renum_act_def\n      unfolding TAG_def[of \"TRANS ''in''\"] TAG_def[of \"SEL _\"]\n      apply (rule OutD, assumption)\n\n      apply (simp add: atLeastLessThan_upperD)\n\n      apply (erule(1) trans_sem_N_renum_broadcastI)\n      apply (subgoal_tac \"map fs ps = map renum_upd (map fs' ps)\")\n       defer\n       apply (simp; fail)\n\n      subgoal for a1 bs' gs' fs' rs' ls1 a2\n\n        apply intros\n            apply (rule step_u.intros(4)[where ps = ps])\n\n                            prefer 2\n                            apply (tag keep: TAG[of \"TRANS ''out''\"], solve_triv)\n\n                            apply (auto_tag, clarsimp simp: renum_sem_broadcast_eq inj_eq_iff[OF inj_renum_acts] broadcast_def; fail)\n\n                            apply (auto_tag, cases \"ps = []\"; simp add: atLeastLessThan_upperD inj_eq_iff[OF inj_renum_acts]; fail)\n\n                            apply (auto_tag, prop_monos)\n\n        subgoal\n          by (auto simp: committed_renum_eq inj_eq_iff[OF inj_renum_states])\n\n                            apply prop_monos\n\n        subgoal\n          by (clarsimp simp: committed_renum_eq inj_eq_iff[OF inj_renum_states] atLeastLessThan_upperD, fast)\n\n        subgoal premises prems\n          using prems(38-) (* last premise only *)\n          by (auto simp: inj_eq_iff[OF inj_renum_states] committed_renum_eq)\n\n                            apply (auto_tag, solve_triv)\n\n                           apply (auto_tag, erule Ball_mono, solve_triv; fail)\n\n                          apply (auto_tag, solve_triv)\n\n        apply (auto_tag, erule Ball_mono, solve_triv)\n\n(* Set of broadcast receivers is maximal *)\n        subgoal\n          apply (tag keep: TAG[of \"''maximal''\"])\n          apply simp\n          apply prop_monos+\n          apply clarify\n          apply (drule (1) trans_N_renumD)+\n          apply (simp add: renum_act_def)\n          apply (drule check_bexp_renumD)\n          apply (drule map_u_renum_cconstraint_clock_valI)\n          apply blast\n          done\n\n(* Target invariant is satisified *)\n        apply (tag keep: TAG[of \"''target invariant''\"] TAG[of \"''new loc''\"] TAG[of \"''new valuation''\"])\n        apply (simp add: atLeastLessThan_upperD)\n        apply (erule (2) inv_sem_N_renum_broadcastI, blast, fast, solve_triv; fail)\n\n        apply (auto_tag, solve_triv?; fail)+\n\n        subgoal\n          apply (tag keep: TAG[of \"''bounded''\"] TAG[of \"''upd''\"] TAG[of \"''upds''\"])\n            (* Resulting state is bounded *)\n          apply (erule bounded_renumD1)\n\n          apply (drule is_upd_dom)\n          subgoal\n            using assms(4) by (intro trans_sem_upd_domI)\n\n          apply (drule is_upds_dom)\n          subgoal\n            using assms(4)\n            apply (simp add: set_map)\n            apply (drule trans_sem_upd_domI, assumption, assumption)\n            apply (erule Ball_mono, drule trans_sem_upd_domI, assumption, (simp add: atLeastLessThan_upperD; fail))\n            apply simp\n            done\n          apply (simp, drule dom_comp_vars_inv_eqD, simp)\n          done\n\n        apply solve_triv\n\n        apply (tag keep: TAG[of \"''new loc''\"], simp add: map_trans_broad_aux1 map_index_update cong: fold_cong; fail)\n\n        apply (determ \\<open>tags del: TAG\\<close>, unfold TAG_def)\n        apply (auto simp: vars_inv_def bij_f_the_inv_f[OF bij_renum_vars]; fail)\n\n        apply (tag keep: TAG[of \"''new valuation''\"], simp add: renum_reset_map_u[symmetric] renum_reset_def map_concat comp_def cong: map_cong; fail)\n        done\n      done\n    done\n  done\n\nlemma step_u_var_set_invariant:\n  assumes \"step_u sem L s u a L' s' u'\" \"dom s = var_set\"\n  shows \"dom s' = var_set\"\n  using assms dom_bounds_var_set by (auto 4 4 dest!: bounded_inv simp: bounded_def)\n\nlemmas step_u_invariants = states_inv step_u_var_set_invariant\n\ninterpretation single: Bisimulation_Invariant\n  \"\\<lambda>(L, s, u) (L', s', u'). \\<exists> a. step_u sem L s u a L' s' u'\"\n  \"\\<lambda>(L, s, u) (L', s', u'). \\<exists> a. step_u renum.sem L s u a L' s' u'\"\n  \"\\<lambda>(L, s, u) (L', s', u'). L' = map_index renum_states L \\<and> s' = s o vars_inv \\<and> u' = map_u u\"\n  \"\\<lambda> (L, s, u). L \\<in> states \\<and> dom s = var_set\" \"\\<lambda>_. True\"\n  apply standard\n  supply [simp del] = map_map_index set_map\n     apply clarsimp\n  subgoal for L s u L' s' u' a\n    by (drule (1) step_single_renumD, auto)\n  subgoal\n    by clarsimp (drule step_single_renumI[rotated]; blast)\n  subgoal\n    by clarsimp (intro conjI; elim step_u_invariants)\n  subgoal\n    .\n  done\n\ninterpretation Bisimulation_Invariant\n  \"\\<lambda>(L, s, u) (L', s', u'). step_u' sem L s u L' s' u'\"\n  \"\\<lambda>(L, s, u) (L', s', u'). step_u' renum.sem L s u L' s' u'\"\n  \"\\<lambda>(L, s, u) (L', s', u'). L' = map_index renum_states L \\<and> s' = s o vars_inv \\<and> u' = map_u u\"\n  \"\\<lambda> (L, s, u). L \\<in> states \\<and> dom s = var_set\" \"\\<lambda>_. True\"\nproof -\n  define rsem where \"rsem = renum.sem\"\n  note step_single_renumD = step_single_renumD[folded rsem_def]\n  show \"Bisimulation_Invariant\n     (\\<lambda>(L, s, u) (L', s', u'). sem \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow> \\<langle>L', s', u'\\<rangle>)\n     (\\<lambda>(L, s, u) (L', s', u'). renum.sem \\<turnstile> \\<langle>L, s, u\\<rangle> \\<rightarrow> \\<langle>L', s', u'\\<rangle>)\n     (\\<lambda>(L, s, u) (L', s', u').\n         L' = map_index renum_states L \\<and>\n         s' = (s o vars_inv) \\<and>\n         u' = map_u u)\n     (\\<lambda>(L, s, u). L \\<in> states \\<and> dom s = var_set) (\\<lambda>_. True)\"\n    unfolding rsem_def[symmetric]\n  proof ((standard; clarsimp split: prod.splits), goal_cases)\n    case (1 L s u L' s' u')\n    from 1(1) guess L1 s1 u1 a\n      by (elim step_u'_elims)\n    with 1(2-) show ?case\n      apply -\n      apply (rule step_u'.intros[where a = \"renum_label a\"])\n        apply (erule (1) step_single_renumD[where a = Del, unfolded renum_label_def, simplified], blast)\n       apply (cases a; simp add: renum_label_def; fail)\n      apply (erule step_single_renumD)\n       apply (blast dest: step_u_invariants)+\n      done\n  next\n    case (2 L s u L' s' u')\n    from 2(3) guess L1 s1 u1 a\n      by (elim step_u'_elims)\n    with 2(1,2) show ?case\n      apply -\n      apply (drule (1) step_single_renumI[folded rsem_def], blast)\n      apply safe\n      subgoal for a1\n        apply (drule step_single_renumI[folded rsem_def])\n          apply (blast dest: step_u_invariants)+\n        apply (subgoal_tac \"a1 = Del\")\n         apply clarsimp\n         apply intros\n            apply (erule step_u'.intros)\n             apply auto\n        apply (cases a1; simp add: renum_label_def)\n        done\n      done\n  next\n    case (3 x1 x1a x2a x1b x1c x2c)\n    then show ?case\n      by (elim step_u'_elims) (auto 4 4 dest: step_u_invariants)\n  qed\nqed\n\nlemmas renum_bisim = Bisimulation_Invariant_axioms\n\nend\n\nlocale Simple_Network_Impl_Formula_real =\n  Simple_Network_Rename_real where automata = automata\n  for automata ::\n    \"('s list \\<times> 's list\n      \\<times> (('a :: countable) act, 's, 'c, real, 'x :: countable, int) transition list\n      \\<times> (('s :: countable) \\<times> ('c :: countable, real) cconstraint) list) list\" +\n  fixes \\<Phi> :: \"(nat, 's, 'x, int) formula\"\n    and s\\<^sub>0 :: \"('x \\<times> int) list\"\n    and L\\<^sub>0 :: \"'s list\"\nbegin\n\ndefinition \\<Phi>' where\n  \"\\<Phi>' = map_formula renum_states renum_vars id \\<Phi>\"\n\ndefinition a\\<^sub>0 where\n  \"a\\<^sub>0 = (L\\<^sub>0, map_of s\\<^sub>0, \\<lambda>_. 0)\"\n\ndefinition a\\<^sub>0' where\n  \"a\\<^sub>0' = (map_index renum_states L\\<^sub>0, map_of (map (\\<lambda>(x, v). (renum_vars x, v)) s\\<^sub>0), \\<lambda>_. 0)\"\n\ncontext\n  assumes L\\<^sub>0_states: \"L\\<^sub>0 \\<in> states\"\n  assumes s\\<^sub>0_dom: \"fst ` set s\\<^sub>0 = var_set\" and s\\<^sub>0_distinct: \"distinct (map fst s\\<^sub>0)\"\nbegin\n\n(* Refine to subset of var_set? *)\nlemma state_eq_aux:\n  assumes \"x \\<notin> renum_vars ` var_set\"\n  shows \"vars_inv x \\<notin> var_set\"\n  unfolding vars_inv_def\nproof clarsimp\n  assume \"the_inv renum_vars x \\<in> var_set\"\n  then have \"renum_vars (the_inv renum_vars x) = x\"\n    by (intro f_the_inv_f inj_renum_vars) (simp add: surj_renum_vars)\n  with assms \\<open>_ \\<in> var_set\\<close> show False\n    by force\nqed\n\nlemma state_eq:\n  assumes \"fst ` set s\\<^sub>0 = var_set\" \"distinct (map fst s\\<^sub>0)\"\n  shows \"map_of (map (\\<lambda>(x, y). (renum_vars x, y)) s\\<^sub>0) = (map_of s\\<^sub>0 \\<circ>\\<circ>\\<circ> the_inv_into) UNIV renum_vars\"\n    (is \"?l = ?r\")\nproof (rule ext)\n  fix x\n  show \"?l x = ?r x\"\n  proof (cases \"x \\<in> renum_vars ` fst ` set s\\<^sub>0\")\n    case True\n    then show ?thesis\n      apply clarsimp\n      apply (subst map_of_mapk_SomeI')\n      subgoal\n        using inj_renum_vars by (auto intro: inj_on_subset)\n       apply (rule map_of_is_SomeI, rule assms, assumption)\n      apply (simp add: the_inv_f_f[OF inj_renum_vars] s\\<^sub>0_distinct)\n      done\n  next\n    case False\n    then have \"vars_inv x \\<notin> fst ` set s\\<^sub>0\"\n      using state_eq_aux assms(1) unfolding vars_inv_def by auto\n    with False show ?thesis\n      apply -\n      apply (frule map_of_NoneI)\n      apply (simp add: vars_inv_def)\n      apply (auto simp: map_of_eq_None_iff)\n      done\n  qed\nqed\n\ninterpretation Bisimulation_Invariant\n  \"\\<lambda>(L, s, u) (L', s', u'). step_u' sem L s u L' s' u'\"\n  \"\\<lambda>(L, s, u) (L', s', u'). step_u' renum.sem L s u L' s' u'\"\n  \"\\<lambda>(L, s, u) (L', s', u'). L' = map_index renum_states L \\<and> s' = s o vars_inv \\<and> u' = map_u u\"\n  \"\\<lambda> (L, s, u). L \\<in> states \\<and> dom s = var_set\" \"\\<lambda>_. True\"\n  by (rule renum_bisim)\n\nlemma start_equiv:\n  \"A_B.equiv' a\\<^sub>0 a\\<^sub>0'\"\n  unfolding A_B.equiv'_def a\\<^sub>0_def a\\<^sub>0'_def\n  apply (clarsimp simp: vars_inv_def, intro conjI)\n  subgoal\n    by (intro state_eq s\\<^sub>0_dom s\\<^sub>0_distinct)\n  subgoal\n    unfolding map_u_def by auto\n  subgoal\n    by (rule L\\<^sub>0_states)\n  subgoal\n    using s\\<^sub>0_dom dom_map_of_conv_image_fst[of s\\<^sub>0] by fastforce\n  done\n\nlemma check_sexp_equiv:\n  assumes \"A_B.equiv' (L, s, u) (L', s', u')\" \"locs_of_sexp e \\<subseteq> {0..<n_ps}\"\n  shows\n  \"check_sexp e L (the \\<circ> s) \\<longleftrightarrow>\n   check_sexp (map_sexp renum_states renum_vars id e) L' (the \\<circ> s')\"\n  using assms unfolding A_B.equiv'_def\n  by (induction e)\n     (simp add: inj_eq states_lengthD renum_states_inj vars_inv_def the_inv_f_f[OF inj_renum_vars])+\n\nlemma models_iff:\n  \"sem,a\\<^sub>0 \\<Turnstile> \\<Phi> = renum.sem,a\\<^sub>0' \\<Turnstile> \\<Phi>'\" if \"locs_of_formula \\<Phi> \\<subseteq> {0..<n_ps}\"\nproof -\n  have \"rel_ctl_formula compatible (ctl_of \\<Phi>) (ctl_of \\<Phi>')\"\n    using that unfolding \\<Phi>'_def\n    by (cases \\<Phi>; auto simp: check_sexp_equiv prop_of_def rel_fun_def)\n  with start_equiv show ?thesis\n    by (simp add: models_ctl_iff CTL_compatible[THEN rel_funD, symmetric])\nqed\n\nlemma has_deadlock_iff:\n  \"has_deadlock sem a\\<^sub>0 \\<longleftrightarrow> has_deadlock renum.sem a\\<^sub>0'\"\n  unfolding has_deadlock_def using start_equiv by (intro deadlock_iff, unfold A_B.equiv'_def) auto\n\nend (* Context for assumptions *)\n\nend (* Simple Network Rename real *)\n\n\n(* XXX Move *)\nlemma Bisimulation_Invariants_Bisimulation_Invariant:\n  assumes \"Bisimulation_Invariants A B sim PA PA PB PB\"\n  shows \"Bisimulation_Invariant A B sim PA PB\"\nproof -\n  interpret Bisimulation_Invariants A B sim PA PA PB PB\n    by (rule assms)\n  show ?thesis\n    by (standard; blast intro: A_B_step B_A_step)\nqed\n\n(* XXX Move *)\nlemma Bisimulation_Invariants_Bisimulation_Invariant_iff:\n  \"Bisimulation_Invariants A B sim PA PA PB PB \\<longleftrightarrow> Bisimulation_Invariant A B sim PA PB\"\n  using\n    Bisimulation_Invariants_Bisimulation_Invariant Bisimulation_Invariant_Bisimulation_Invariants\n  by blast\n\nlemmas Bisimulation_Invariant_composition =\n  Bisimulation_Invariant_Invariants_composition[\n    THEN Bisimulation_Invariants_Bisimulation_Invariant,\n    OF _ Bisimulation_Invariant_Bisimulation_Invariants]\n\nlemma Bisimulation_Invariant_refl:\n  \"Bisimulation_Invariant A A (=) P P\" if \"\\<And>a b. P a \\<Longrightarrow> A a b \\<Longrightarrow> P b\"\n  by (rule Bisimulation_Invariant.intro) (auto intro: that)\n\n\nlocale Simple_Network_Rename_int =\n  Simple_Network_Rename_Defs_int where automata = automata +\n  Simple_Network_Rename' where automata = automata\n  for automata ::\n    \"('s list \\<times> 's list\n      \\<times> (('a :: countable) act, 's, 'c, int, 'x :: countable, int) transition list\n      \\<times> (('s :: countable) \\<times> ('c :: countable, int) cconstraint) list) list\" +\n  assumes urgency_removed: \"\\<forall> (_, U, _, _) \\<in> set automata. U = []\"\nbegin\n\nlemma n_ps_eq1:\n  \"Prod_TA_Defs.n_ps\n        (set broadcast, map automaton_of (map conv_automaton automata),\n         map_of bounds') = n_ps\"\n  unfolding n_ps_def Prod_TA_Defs.n_ps_def by simp\n\nlemma var_set_eq1:\n  \"Prod_TA_Defs.var_set\n     (set broadcast, map automaton_of (map conv_automaton automata),\n      map_of bounds') = var_set\"\n  unfolding sem_def sem_var_set_eq[symmetric] by simp\n\nlemma urgency_removed':\n  \"\\<forall>i<n_ps. urgent\n  (Prod_TA_Defs.N (set broadcast, map automaton_of (map conv_automaton automata), map_of bounds') i)\n  = {}\"\n  unfolding urgent_def n_ps_def Prod_TA_Defs.n_ps_def Prod_TA_Defs.N_def\n  unfolding conv_automaton_def automaton_of_def\n  using urgency_removed by (fastforce dest: nth_mem split: prod.split)\n\nsublocale real: Simple_Network_Rename_real where automata = \"map conv_automaton automata\"\n  apply standard\n  unfolding n_ps_eq1 var_set_eq1\n  by (rule bij_renum_clocks renum_states_inj bij_renum_vars bounds'_var_set inj_renum_acts\n           urgency_removed')+\n\nlemma sem_unfold1:\n  \"real.sem = sem\"\n  unfolding sem_def by simp\n\nlemma var_set_eq:\n  \"real.var_set = sem.var_set\"\n  unfolding sem_unfold1[symmetric] ..\n\nlemma map_acconstraint_conv_ac_commute:\n  \"map_acconstraint renum_clocks id (conv_ac ac) = conv_ac (map_acconstraint renum_clocks id ac)\"\n  by (cases ac; simp)\n\nlemma map_ccconstraint_conv_cc_commute:\n  \"renum_cconstraint (conv_cc g) = conv_cc (renum_cconstraint g)\"\n  unfolding renum_cconstraint_def map_cconstraint_def by (simp add: map_acconstraint_conv_ac_commute)\n\nlemma rename_conv_automaton_commute:\n  \"real.renum_automaton n (conv_automaton x) = conv_automaton (real.renum_automaton n x)\"\n  unfolding real.renum_automaton_def conv_automaton_def\n  by (clarsimp split: prod.split simp: map_ccconstraint_conv_cc_commute)\n\nlemma sem_unfold2:\n  \"real.renum.sem = renum.sem\"\n  by (simp add: Simple_Network_Impl.sem_def rename_conv_automaton_commute)\n\nsublocale renum_bisim: Bisimulation_Invariant\n  \"\\<lambda>(L, s, u) (L', s', u'). step_u' sem L s u L' s' u'\"\n  \"\\<lambda>(L, s, u) (L', s', u'). step_u' renum.sem L s u L' s' u'\"\n  \"\\<lambda>(L, s, u) (L', s', u'). L' = map_index renum_states L \\<and> s' = s o vars_inv \\<and> u' = map_u u\"\n  \"\\<lambda> (L, s, u). L \\<in> sem.states \\<and> dom s = var_set\" \"\\<lambda>_. True\"\n  apply (rule Bisimulation_Invariant_sim_replace)\n   apply (rule Bisimulation_Invariant_composition)\n    apply (rule real.renum_bisim[unfolded sem_unfold1 sem_unfold2 sem_var_set_eq])\n   apply (rule Bisimulation_Invariant_refl)\n   apply auto\n  done\n\nlemmas renum_bisim = renum_bisim.Bisimulation_Invariant_axioms\n\nend\n\nlocale Simple_Network_Rename_Start' =\n  Simple_Network_Rename' where automata = automata\n  for automata ::\n    \"('s list \\<times> 's list\n      \\<times> (('a :: countable) act, 's, 'c, 't, 'x :: countable, int) transition list\n      \\<times> (('s :: countable) \\<times> ('c :: countable, 't) cconstraint) list) list\" +\n  fixes s\\<^sub>0 :: \"('x \\<times> int) list\"\n    and L\\<^sub>0 :: \"'s list\"\n  assumes L\\<^sub>0_states: \"L\\<^sub>0 \\<in> states\"\n  assumes s\\<^sub>0_dom: \"fst ` set s\\<^sub>0 = var_set\" and s\\<^sub>0_distinct: \"distinct (map fst s\\<^sub>0)\"\nbegin\n\nend\n\nlocale Simple_Network_Rename_Start_int =\n  Simple_Network_Rename_int where automata = automata +\n  Simple_Network_Rename_Start' where automata = automata\n  for automata ::\n    \"('s list \\<times> 's list\n      \\<times> (('a :: countable) act, 's, 'c, int, 'x :: countable, int) transition list\n      \\<times> (('s :: countable) \\<times> ('c :: countable, int) cconstraint) list) list\"\nbegin\n\ndefinition a\\<^sub>0 where\n  \"a\\<^sub>0 = (L\\<^sub>0, map_of s\\<^sub>0, \\<lambda>_. 0)\"\n\ndefinition a\\<^sub>0' where\n  \"a\\<^sub>0' = (map_index renum_states L\\<^sub>0, map_of (map (\\<lambda>(x, v). (renum_vars x, v)) s\\<^sub>0), \\<lambda>_. 0)\"\n\n(* Refine to subset of var_set? *)\nlemma state_eq_aux:\n  assumes \"x \\<notin> renum_vars ` var_set\"\n  shows \"vars_inv x \\<notin> var_set\"\n  unfolding vars_inv_def\nproof clarsimp\n  assume \"the_inv renum_vars x \\<in> var_set\"\n  then have \"renum_vars (the_inv renum_vars x) = x\"\n    by (intro f_the_inv_f real.inj_renum_vars) (simp add: real.surj_renum_vars)\n  with assms \\<open>_ \\<in> var_set\\<close> show False\n    by force\nqed\n\nlemma state_eq:\n  assumes \"fst ` set s\\<^sub>0 = var_set\" \"distinct (map fst s\\<^sub>0)\"\n  shows \"map_of (map (\\<lambda>(x, y). (renum_vars x, y)) s\\<^sub>0) = (map_of s\\<^sub>0 \\<circ>\\<circ>\\<circ> the_inv_into) UNIV renum_vars\"\n    (is \"?l = ?r\")\nproof (rule ext)\n  fix x\n  show \"?l x = ?r x\"\n  proof (cases \"x \\<in> renum_vars ` fst ` set s\\<^sub>0\")\n    case True\n    then show ?thesis\n      apply clarsimp\n      apply (subst map_of_mapk_SomeI')\n      subgoal\n        using real.inj_renum_vars by (auto intro: inj_on_subset)\n       apply (rule map_of_is_SomeI, rule assms, assumption)\n      apply (simp add: the_inv_f_f[OF real.inj_renum_vars] s\\<^sub>0_distinct)\n      done\n  next\n    case False\n    then have \"vars_inv x \\<notin> fst ` set s\\<^sub>0\"\n      using state_eq_aux assms(1) unfolding vars_inv_def by auto\n    with False show ?thesis\n      apply -\n      apply (frule map_of_NoneI)\n      apply (simp add: vars_inv_def)\n      apply (auto simp: map_of_eq_None_iff)\n      done\n  qed\nqed\n\nlemma start_equiv:\n  \"renum_bisim.A_B.equiv' a\\<^sub>0 a\\<^sub>0'\"\n  unfolding renum_bisim.A_B.equiv'_def a\\<^sub>0_def a\\<^sub>0'_def\n  apply (clarsimp simp: vars_inv_def, intro conjI)\n  subgoal\n    by (intro state_eq s\\<^sub>0_dom s\\<^sub>0_distinct)\n  subgoal\n    unfolding map_u_def by auto\n  subgoal\n    unfolding sem_states_eq by (rule L\\<^sub>0_states)\n  subgoal\n    using s\\<^sub>0_dom dom_map_of_conv_image_fst[of s\\<^sub>0] by fastforce\n  done\n\nlemma check_sexp_equiv:\n  assumes \"renum_bisim.A_B.equiv' (L, s, u) (L', s', u')\" \"locs_of_sexp e \\<subseteq> {0..<n_ps}\"\n  shows\n  \"check_sexp e L (the \\<circ> s) \\<longleftrightarrow>\n   check_sexp (map_sexp renum_states renum_vars id e) L' (the \\<circ> s')\"\n  using assms unfolding renum_bisim.A_B.equiv'_def\n  by (induction e)\n     (simp add:\n       inj_eq sem.states_lengthD renum_states_inj vars_inv_def the_inv_f_f[OF real.inj_renum_vars])+\n\nlemma check_sexp_compatible:\n  assumes \"locs_of_sexp e \\<subseteq> {0..<n_ps}\"\n  shows \"renum_bisim.compatible\n    (\\<lambda>(L, s, u). check_sexp e L (the \\<circ> s))\n    (\\<lambda>(L', s', u'). check_sexp (map_sexp renum_states renum_vars id e) L' (the \\<circ> s'))\"\n  using check_sexp_equiv[OF _ assms] by auto\n\nlemma has_deadlock_iff:\n  \"has_deadlock sem a\\<^sub>0 \\<longleftrightarrow> has_deadlock renum.sem a\\<^sub>0'\"\n  unfolding has_deadlock_def using start_equiv\n  by (intro renum_bisim.deadlock_iff, unfold renum_bisim.A_B.equiv'_def) auto\n\nlemma state_formula_compatible:\n  \"(\\<Union>x \\<in> set_state_formula \\<phi>. locs_of_sexp x) \\<subseteq> {0..<n_ps} \\<Longrightarrow>\n  rel_state_formula renum_bisim.compatible\n    (map_state_formula (\\<lambda>P (L, s, _). check_sexp P L (the o s)) \\<phi>)\n    (map_state_formula (\\<lambda>P (L, s, _).\n      check_sexp (map_sexp (\\<lambda>p. renum_states p) renum_vars id P) L (the o s))\n     \\<phi>)\" and path_formula_compatible:\n  \"(\\<Union>x \\<in> set_path_formula \\<psi>. locs_of_sexp x) \\<subseteq> {0..<n_ps} \\<Longrightarrow>\n  rel_path_formula renum_bisim.compatible\n    (map_path_formula (\\<lambda>P (L, s, _). check_sexp P L (the o s)) \\<psi>)\n    (map_path_formula (\\<lambda>P (L, s, _).\n      check_sexp (map_sexp (\\<lambda>p. renum_states p) renum_vars id P) L (the o s))\n     \\<psi>)\"\n   by (induction \\<phi> and \\<psi>) (auto simp: check_sexp_equiv prop_of_def rel_fun_def)\n\nlemmas models_state_compatible = renum_bisim.models_state_compatible[OF state_formula_compatible]\n\nend\n\nlocale Simple_Network_Rename_Formula_int =\n  Simple_Network_Rename_Start_int where automata = automata\n  for automata ::\n    \"('s list \\<times> 's list\n      \\<times> (('a :: countable) act, 's, 'c, int, 'x :: countable, int) transition list\n      \\<times> (('s :: countable) \\<times> ('c :: countable, int) cconstraint) list) list\" +\n  fixes \\<Phi> :: \"(nat, 's, 'x, int) formula\"\nbegin\n\ndefinition \\<Phi>' where\n  \"\\<Phi>' = map_formula renum_states renum_vars id \\<Phi>\"\n\nlemma models_iff:\n  \"sem,a\\<^sub>0 \\<Turnstile> \\<Phi> = renum.sem,a\\<^sub>0' \\<Turnstile> \\<Phi>'\" if \"locs_of_formula \\<Phi> \\<subseteq> {0..<n_ps}\"\nproof -\n  have \"rel_ctl_formula renum_bisim.compatible (ctl_of \\<Phi>) (ctl_of \\<Phi>')\"\n    using that unfolding \\<Phi>'_def\n    by (cases \\<Phi>; auto simp: check_sexp_equiv prop_of_def rel_fun_def)\n  with start_equiv show ?thesis\n    by (simp add: models_ctl_iff renum_bisim.CTL_compatible[THEN rel_funD, symmetric])\nqed\n\nend (* Simple Network Rename Formula int *)\n\n\n\n(* XXX Move *)\nlemma vars_of_bexp_finite[finite_intros]:\n  \"finite (vars_of_bexp (b::('a, 'b) bexp))\"\nand vars_of_exp_finite[finite_intros]:\n  \"finite (vars_of_exp (e::('a, 'b) exp))\"\n  by (induction b and e) auto\n\nlemma set_bexp_vars_of_bexp:\n  \"set_bexp (b::('a, 'b) bexp) = vars_of_bexp b\"\nand set_exp_vars_of_exp:\n  \"set_exp (e::('a, 'b) exp) = vars_of_exp e\"\n  by (induction b and e) auto\n\ndefinition (in Prod_TA_Defs)\n  \"act_set \\<equiv> (\\<Union> p \\<in> {0..<n_ps}. \\<Union> (l, e, g, a, _) \\<in> trans (N p). act.set_act a) \\<union> broadcast\"\n\nlemma (in Simple_Network_Impl) act_set_compute:\n  \"act_set =\n  \\<Union> ((\\<lambda>(_, _, t, _). \\<Union> ((\\<lambda>(l, e, g, a, _). act.set_act a) ` set t)) ` set automata) \\<union> set broadcast\"\n  unfolding act_set_def\n  apply (fo_rule arg_cong2)\n  apply (auto simp: N_p_trans_eq n_ps_def act_set_def broadcast_def)\n     apply (drule nth_mem, erule bexI[rotated], force)+\n   apply (drule mem_nth, force)+\n  done\n\nlemma set1_acconstraint_elim:\n  assumes \"c \\<in> set1_acconstraint ac\"\n  obtains x where \"(c, x) = constraint_pair ac\"\n  using assms by (cases ac) auto\n\nlemma (in Simple_Network_Impl)\n  assumes \"(x1, x2, T, I) \\<in> set automata\" \"(l, b, g, a, f, r, l') \\<in> set T\"\n  shows clk_set'I1[intro]: \"c \\<in> set r \\<Longrightarrow> c \\<in> clk_set'\"\n    and clk_set'I2[intro]: \"ac \\<in> set g \\<Longrightarrow> c \\<in> set1_acconstraint ac \\<Longrightarrow> c \\<in> clk_set'\"\n    and loc_setI1[intro]: \"l \\<in> loc_set\" and loc_setI2[intro]: \"l' \\<in> loc_set\"\n    and act_setI[intro]: \"a' \\<in> set_act a \\<Longrightarrow> a' \\<in> act_set\"\n    and var_setI1[intro]: \"v \\<in> set_bexp b \\<Longrightarrow> v \\<in> var_set\"\n    and var_setI2[intro]: \"(x, e) \\<in> set f \\<Longrightarrow> x \\<in> var_set\"\n    and var_setI3[intro]: \"(x, e) \\<in> set f \\<Longrightarrow> v \\<in> set_exp e \\<Longrightarrow> v \\<in> var_set\"\n  using assms unfolding\n    loc_set_compute act_set_compute var_set_compute set_bexp_vars_of_bexp set_exp_vars_of_exp\n    clk_set'_def\n         apply -\n         apply force\n        apply (fastforce elim: set1_acconstraint_elim simp: clkp_set'_def collect_clock_pairs_def)\n       apply (simp; blast)+\n  done\n\nlemma (in Simple_Network_Impl) clk_set'I3[intro]:\n  assumes \"(x1, x2, T, I) \\<in> set automata\"\n  shows \"(l, g') \\<in> set I \\<Longrightarrow> ac \\<in> set g' \\<Longrightarrow> c \\<in> set1_acconstraint ac \\<Longrightarrow> c \\<in> clk_set'\"\n  using assms unfolding clk_set'_def clkp_set'_def collect_clock_pairs_def\n  by (force elim!: set1_acconstraint_elim)\n\n\ndefinition\n  \"find_remove P = map_option (\\<lambda>(xs, x, ys). (x, xs @ ys)) o List.extract P\"\n\nfun merge_pairs :: \"('a \\<times> 'b list) list \\<Rightarrow> ('a \\<times> 'b list) list \\<Rightarrow> ('a \\<times> 'b list) list\" where\n  \"merge_pairs [] ys = ys\" |\n  \"merge_pairs ((k, v) # xs) ys = (case find_remove (\\<lambda>(k', _). k' = k) ys of\n    None \\<Rightarrow> (k, v) # merge_pairs xs ys\n  | Some ((_, v'), ys) \\<Rightarrow> (k, v @ v') # merge_pairs xs ys\n  )\"\n\n(*\ndefinition\n  \"conv_urge urge \\<equiv> \\<lambda>(committed, urgent, trans, inv).\n    (committed,\n     [],\n     map (\\<lambda>(l, b, g, a, f, r, l'). (l, b, g, a, f, urge # r, l')) trans,\n     map (\\<lambda>(l, cc). (l, if l \\<in> set urgent then acconstraint.LE urge 0 # cc else cc)) inv)\"\n*)\n\ndefinition\n  \"conv_urge urge \\<equiv> \\<lambda>(committed, urgent, trans, inv).\n    (committed,\n     [],\n     map (\\<lambda>(l, b, g, a, f, r, l'). (l, b, g, a, f, urge # r, l')) trans,\n     merge_pairs (map (\\<lambda>l. (l, [acconstraint.LE urge 0])) urgent) inv)\"\n\n(* XXX Generalized version. Move to library *)\nlemma map_of_distinct_upd2:\n  assumes \"x \\<notin> set (map fst xs)\"\n  shows \"map_of (xs @ (x,y) # ys) = (map_of (xs @ ys))(x \\<mapsto> y)\"\n  using assms by (induction xs) auto\n\n(* XXX Generalized version. Move to library *)\nlemma map_of_distinct_lookup:\n  assumes \"x \\<notin> set (map fst xs)\"\n  shows \"map_of (xs @ (x,y) # ys) x = Some y\"\n  using map_of_distinct_upd2[OF assms] by auto\n\nlemma find_remove_SomeD:\n  assumes \"find_remove P xs = Some (x, ys)\"\n  shows \"\\<exists>as bs. xs = as @ x # bs \\<and> ys = as @ bs \\<and> (\\<forall>x \\<in> set as. \\<not> P x) \\<and> P x\"\n  using assms unfolding find_remove_def by (auto dest: extract_SomeE)\n\nlemma find_map:\n  \"find Q (map f xs) = map_option f (find P xs)\" if \"\\<forall>x \\<in> set xs. Q (f x) \\<longleftrightarrow> P x\"\n  using that by (induction xs) auto\n\nlemma find_remove_map:\n  \"find_remove Q (map f xs) = map_option (\\<lambda>(x, xs). (f x, map f xs)) (find_remove P xs)\"\n  if \"\\<forall>x \\<in> set xs. Q (f x) \\<longleftrightarrow> P x\"\n  using that\n  by (induction xs)\n     (auto simp: find_remove_def extract_Nil_code extract_Cons_code split: option.split)\n\nlemma map_merge_pairs2:\n  \"map (\\<lambda>(k, v). (g k, map f v)) (merge_pairs xs ys)\n  = merge_pairs (map (\\<lambda>(k, v). (g k, map f v)) xs) (map (\\<lambda>(k, v). (g k, map f v)) ys)\"\n  if inj: \"inj_on g (fst ` (set xs \\<union> set ys))\"\nproof -\n  have *:\n    \"find_remove (\\<lambda>(k', _). k' = g k) (map (\\<lambda>(k, v). (g k, map f v)) ys)\n   = map_option\n      (\\<lambda>((k, v), ys). ((g k, map f v), map (\\<lambda>(k, v). (g k, map f v)) ys))\n      (find_remove (\\<lambda>(k', _). k' = k) ys)\"\n    if \"inj_on g (fst ` (set xs \\<union> set ys))\" \"k \\<in> fst ` set xs\" for k xs ys\n    using that\n    by (subst find_remove_map[where P = \"(\\<lambda>(k', _). k' = k)\"])\n      (auto elim: inj_onD[rotated, where A = \"fst ` (set xs \\<union> set ys)\"]\n        intro!: arg_cong2[where f = map_option])\n  show ?thesis\n    using inj\n  proof (induction xs arbitrary: ys)\n    case Nil\n    then show ?case\n      by simp\n  next\n    case (Cons x xs)\n    then show ?case\n      apply (auto split: prod.split option.split simp: *[OF Cons(2)])\n      apply (subst Cons.IH)\n       apply (drule find_remove_SomeD)\n       apply auto\n      done\n  qed\nqed\n\nlemma map_merge_pairs:\n  \"map (\\<lambda>(k, v). (k, map f v)) (merge_pairs xs ys)\n  = merge_pairs (map (\\<lambda>(k, v). (k, map f v)) xs) (map (\\<lambda>(k, v). (k, map f v)) ys)\"\n  using map_merge_pairs2[where g = id] by auto\n\nlemma map_map_commute:\n  \"map f (map g xs) = map g (map f xs)\" if \"\\<forall>x \\<in> set xs. f (g x) = g (f x)\"\n  using that by simp\n\nlemma conv_automaton_conv_urge_commute:\n  \"conv_automaton (conv_urge c A) = conv_urge c (conv_automaton A)\"\n  unfolding comp_def conv_automaton_def conv_urge_def\n  by (simp split: prod.split add: map_merge_pairs comp_def)\n\nlemma conv_automaton_conv_urge_commute':\n  \"conv_automaton o conv_urge c = conv_urge c o conv_automaton\"\n  unfolding comp_def conv_automaton_conv_urge_commute ..\n\nlocale Simple_Network_Rename_Defs_int_urge =\n  Simple_Network_Rename_Defs_int where automata = automata for automata ::\n    \"('s list \\<times> 's list\n      \\<times> (('a :: countable) act, 's, 'c, int, 'x :: countable, int) transition list\n      \\<times> (('s :: countable) \\<times> ('c :: countable, int) cconstraint) list) list\"\n  + fixes urge :: 'c\n\nlemma (in Simple_Network_Rename_Defs) conv_automaton_of:\n  \"Simple_Network_Language.conv_A (automaton_of A) = automaton_of (conv_automaton A)\"\n  unfolding automaton_of_def conv_automaton_def\n    Simple_Network_Language.conv_A_def\n  by (force\n      simp: default_map_of_alt_def map_of_map Simple_Network_Language.conv_t_def split: prod.splits\n     )\n\nlocale Simple_Network_Rename =\n  Simple_Network_Rename_Defs_int_urge where automata = automata for automata ::\n    \"('s list \\<times> 's list\n      \\<times> (('a :: countable) act, 's, 'c, int, 'x :: countable, int) transition list\n      \\<times> (('s :: countable) \\<times> ('c :: countable, int) cconstraint) list) list\" +\n  assumes renum_states_inj:\n    \"\\<forall>i<n_ps. \\<forall>x\\<in>loc_set. \\<forall>y\\<in>loc_set. renum_states i x = renum_states i y \\<longrightarrow> x = y\"\n  and renum_clocks_inj: \"inj_on renum_clocks (insert urge clk_set')\"\n  and renum_vars_inj:   \"inj_on renum_vars var_set\"\n  and renum_acts_inj: \"inj_on renum_acts act_set\"\n  and infinite_types:\n    \"infinite (UNIV :: 'c set)\" \"infinite (UNIV :: 'x set)\" \"infinite (UNIV :: 's set)\"\n    \"infinite (UNIV :: 'a set)\"\n  and bounds'_var_set: \"fst ` set bounds' = var_set\"\n  and loc_set_invs: \"\\<Union> ((\\<lambda>g. fst ` set g) ` set (map (snd o snd o snd) automata)) \\<subseteq> loc_set\"\n  and loc_set_committed: \"\\<Union> ((set o fst) ` set automata) \\<subseteq> loc_set\"\n  and loc_set_urgent: \"\\<Union> ((set o (fst o snd)) ` set automata) \\<subseteq> loc_set\"\n  and urge_not_in_clk_set: \"urge \\<notin> clk_set'\"\nbegin\n\nlemma clk_set'_finite:\n  \"finite clk_set'\"\n  unfolding clk_set'_def unfolding clkp_set'_def by (intro finite_intros) auto\n\n(* XXX Move *)\nlemmas [finite_intros] = trans_N_finite\n\nlemma set_act_finite[finite_intros]:\n  \"finite (set_act a)\"\n  by (cases a) auto\n\nlemma loc_set_finite:\n  \"finite loc_set\"\n  unfolding loc_set_def by (auto intro!: finite_intros)\n\n(* XXX Move *)\nlemma var_set_finite[finite_intros]:\n  \"finite var_set\"\n  unfolding var_set_def by (auto intro!: finite_intros)\n\nlemma act_set_finite:\n  \"finite act_set\"\n  unfolding act_set_def broadcast_def by (auto intro!: finite_intros)\n\nlemma bij_extend_bij_renum_clocks:\n  \"bij (extend_bij renum_clocks (insert urge clk_set'))\"\n  by (intro extend_bij_bij renum_clocks_inj clk_set'_finite infinite_types finite.insertI) simp\n\nlemma renum_vars_bij_extends[simp]:\n  \"extend_bij renum_vars var_set x = renum_vars x\" if \"x \\<in> var_set\"\n  by (intro extend_bij_extends[rule_format] renum_vars_inj var_set_finite infinite_types that)\n\nlemma bij_extend_bij_renum_states:\n  \"bij (extend_bij renum_vars var_set)\"\n  by (intro extend_bij_bij renum_vars_inj var_set_finite infinite_types) simp\n\nlemma inj_extend_bij_renum_states: \"inj (extend_bij (renum_states p) loc_set)\" if \"p < n_ps\"\n  using renum_states_inj infinite_types loc_set_finite \\<open>p < n_ps\\<close>\n  by (intro extend_bij_inj) (auto intro!: inj_onI)\n\nlemma renum_states_extend:\n  \"extend_bij (renum_states p) loc_set l = renum_states p l\" if \"l \\<in> loc_set\" \"p < n_ps\"\n  using renum_states_inj infinite_types loc_set_finite \\<open>p < n_ps\\<close> \\<open>l \\<in> loc_set\\<close>\n  by (intro extend_bij_extends[rule_format]) (auto intro!: inj_onI)\n\nlemma renum_acts_bij_extends[simp]:\n  \"extend_bij renum_acts act_set x = renum_acts x\" if \"x \\<in> act_set\"\n  by (intro extend_bij_extends[rule_format] renum_acts_inj act_set_finite infinite_types that)\n\nlemma inj_extend_bij_renum_acts: \"inj (extend_bij renum_acts act_set)\"\n  using renum_acts_inj infinite_types act_set_finite by (intro extend_bij_inj) auto\n\nlemma constraint_clk_conv_ac:\n  \"constraint_clk (conv_ac ac) = constraint_clk ac\"\n  by (cases ac) auto\n\ninterpretation urge: Prod_TA_sem_urge\n  \"(set broadcast, map (Simple_Network_Language.conv_A o automaton_of) automata, map_of bounds')\"\n  urge\n  apply (standard; clarsimp)\n  subgoal\n    using urge_not_in_clk_set\n    unfolding conv_automaton_of\n    unfolding automaton_of_def conv_automaton_def\n    apply (clarsimp split: prod.split_asm)\n    apply (drule default_map_of_in_listD)\n    unfolding clk_set'_def clkp_set'_def collect_clock_pairs_def\n    apply clarsimp\n    subgoal premises prems\n      using prems(1,7,8,10)\n      unfolding constraint_clk_conv_ac unfolding constraint_clk_constraint_pair\n      by force\n    done\n  subgoal\n    using urge_not_in_clk_set\n    unfolding conv_automaton_of\n    unfolding automaton_of_def conv_automaton_def\n    apply (clarsimp split: prod.split_asm)\n    unfolding clk_set'_def clkp_set'_def collect_clock_pairs_def\n    unfolding constraint_clk_conv_ac unfolding constraint_clk_constraint_pair\n    apply force\n    done\n\n  subgoal\n    using urge_not_in_clk_set\n    unfolding conv_automaton_of\n    unfolding automaton_of_def conv_automaton_def\n    apply (clarsimp split: prod.split_asm)\n    unfolding clk_set'_def clkp_set'_def collect_clock_pairs_def\n    apply force\n    done\n  done\n\n\nsublocale rename: Simple_Network_Rename_Defs_int\n  broadcast bounds'\n  \"extend_bij renum_acts act_set\"\n  \"extend_bij renum_vars var_set\"\n  \"extend_bij renum_clocks (insert urge clk_set')\"\n  \"\\<lambda>p. extend_bij (renum_states p) loc_set\"\n  \"map (conv_urge urge) automata\"\n  .\n\nsublocale rename: Simple_Network_Rename_int\n  broadcast bounds'\n  \"extend_bij renum_acts act_set\"\n  \"extend_bij renum_vars var_set\"\n  \"extend_bij renum_clocks (insert urge clk_set')\"\n  \"\\<lambda>p. extend_bij (renum_states p) loc_set\"\n  \"map (conv_urge urge) automata\"\n  apply (standard;\n      (intro allI impI bij_extend_bij_renum_clocks inj_extend_bij_renum_states\n        inj_extend_bij_renum_acts bij_extend_bij_renum_states bounds'_var_set)?)\n    apply (simp add: Prod_TA_Defs.n_ps_def; fail)\n  subgoal\n    unfolding bounds'_var_set rename.var_set_compute var_set_compute unfolding conv_urge_def\n    by (fo_rule arg_cong2; fastforce)\n  subgoal\n    unfolding conv_urge_def by auto\n  done\n\ndefinition\n  \"renum_upd' = map (\\<lambda>(x, upd). (renum_vars x, map_exp renum_vars upd))\"\n\ndefinition\n  \"renum_reset' = map renum_clocks\"\n\ndefinition renum_automaton' where\n  \"renum_automaton' i \\<equiv> \\<lambda>(committed, trans, inv). let\n    committed' = map (renum_states i) committed;\n    trans' = map (\\<lambda>(l, g, a, upd, r, l').\n      (renum_states i l,\n      map_cconstraint renum_clocks id g, renum_act a, renum_upd' upd, map renum_clocks r, \n      renum_states i l')\n    ) trans;\n    inv' = map (\\<lambda>(l, g). (renum_states i l, map_cconstraint renum_clocks id g)) inv\n  in (committed', trans', inv')\n\"\n\nlemmas renum_automaton'_alt_def = renum_automaton'_def[unfolded\n  renum_reset'_def renum_upd'_def map_cconstraint_def renum_act_def\n  ]\n\nlemma renum_automaton_eq:\n  \"rename.renum_automaton p (automata ! p) = renum_automaton p (automata ! p)\"\n  if \"p < n_ps\"\nproof -\n  have renum_clocks: \"extend_bij renum_clocks (insert urge clk_set') c = renum_clocks c\"\n    if \"c \\<in> clk_set'\" for c\n    apply (rule extend_bij_extends[rule_format])\n       apply (rule renum_clocks_inj clk_set'_finite finite.insertI)+\n    using that infinite_types by auto\n  have renum_cconstraint: \"rename.renum_cconstraint g = renum_cconstraint g\"\n    if \"\\<Union> (set1_acconstraint ` (set g)) \\<subseteq> clk_set'\" for g\n    unfolding rename.renum_cconstraint_def renum_cconstraint_def map_cconstraint_def\n    apply (rule map_cong, rule HOL.refl)\n    apply (rule acconstraint.map_cong_pred, rule HOL.refl)\n    using that\n    apply (auto intro: renum_clocks[simplified] simp: pred_acconstraint_def)\n    done\n  show ?thesis\n    using that[folded length_automata_eq_n_ps]\n    unfolding rename.renum_automaton_def renum_automaton_def\n    apply (clarsimp split: prod.split)\n    apply safe\n    subgoal committed\n      using loc_set_committed\n      by (subst renum_states_extend) (auto 4 3 simp: n_ps_def dest!: nth_mem)\n    subgoal urgent\n      using loc_set_urgent\n      by (subst renum_states_extend) (auto 4 3 simp: n_ps_def dest!: nth_mem)\n    subgoal start_locs\n      by (subst renum_states_extend) (auto simp: n_ps_def dest!: nth_mem)\n    subgoal state\n      unfolding rename.renum_bexp_def renum_bexp_def\n      by (auto dest!: nth_mem intro!: renum_vars_bij_extends bexp.map_cong_pred simp: pred_bexp_def)\n    subgoal guards\n      by (auto dest!: nth_mem intro!: renum_cconstraint)\n    subgoal actions\n      unfolding rename.renum_act_def renum_act_def\n      by (auto simp: pred_act_def dest!: nth_mem intro!: renum_acts_bij_extends act.map_cong_pred)\n    subgoal upds\n      unfolding renum_upd_def rename.renum_upd_def rename.renum_exp_def renum_exp_def\n      by (auto dest!: nth_mem intro!: renum_vars_bij_extends exp.map_cong_pred simp: pred_exp_def)\n    subgoal clock_resets\n      unfolding rename.renum_reset_def renum_reset_def by (auto dest!: nth_mem intro!: renum_clocks)\n    subgoal dest_locs\n      by (subst renum_states_extend) (auto simp: n_ps_def dest!: nth_mem)\n    subgoal inv_locs\n      using loc_set_invs\n      by (subst renum_states_extend) (auto 4 4 simp: n_ps_def dest!: nth_mem)\n    subgoal renum_clocks\n      by (auto dest!: nth_mem intro!: renum_cconstraint)\n    done\nqed\n\nlemma renum_urge_automaton_eq1:\n  \"renum_automaton p (conv_urge urge (automata ! p))\n  = conv_urge (renum_clocks urge) (renum_automaton p (automata ! p))\" if \"p < n_ps\"\n  unfolding renum_automaton_def conv_urge_def\n  apply (simp split: prod.split)\n  apply safe\n  subgoal\n    unfolding renum_reset_def by simp\n  unfolding renum_cconstraint_def map_cconstraint_def\n  apply (subst map_merge_pairs2)\n  subgoal\n    using loc_set_urgent loc_set_invs \\<open>p < n_ps\\<close> unfolding inj_on_def n_ps_def\n    by (auto; force\n        elim!: renum_states_inj[unfolded n_ps_def, simplified, rule_format, rotated -1]\n        intro: nth_mem)\n  apply (fo_rule arg_cong2; simp)\n  done\n\nlemma renum_urge_automaton_eq2:\n  \"rename.real.renum_automaton p (conv_urge urge (automata ! p))\n  = conv_urge\n      (extend_bij renum_clocks (insert urge clk_set') urge)\n      (rename.renum_automaton p (automata ! p))\"\n  if \"p < n_ps\"\n  unfolding rename.renum_automaton_def conv_urge_def\n  apply (simp split: prod.split)\n  apply safe\n  subgoal\n    unfolding rename.renum_reset_def by simp\n  unfolding rename.renum_cconstraint_def map_cconstraint_def\n  apply (subst map_merge_pairs2)\n  subgoal\n    by (rule inj_extend_bij_renum_states that subset_UNIV inj_on_subset)+\n  apply (fo_rule arg_cong2)\n   apply simp+\n  done\n\nlemma renum_urge_automaton_eq:\n  \"rename.real.renum_automaton p (conv_urge urge (automata ! p)) =\n   renum_automaton p (conv_urge urge (automata ! p))\" if \"p < n_ps\"\n  using that\n  unfolding renum_urge_automaton_eq1[OF that] renum_urge_automaton_eq2[OF that]\n  apply (fo_rule arg_cong2)\n  subgoal\n    by (intro\n      extend_bij_extends[rule_format] renum_clocks_inj clk_set'_finite finite.insertI infinite_types\n      ) auto\n  by (rule renum_automaton_eq)\n\nlemma rename_N_eq_sem:\n  \"rename.renum.sem =\n  Simple_Network_Language_Model_Checking.N\n    (map renum_acts broadcast)\n    (map_index renum_automaton (map (conv_urge urge) automata))\n    (map (\\<lambda>(a,p). (renum_vars a,p)) bounds')\n  \"\n  unfolding rename.renum.sem_def\n  unfolding Simple_Network_Language.conv_def\n  apply simp\n  apply (intro conjI)\n  subgoal\n    by (rule image_cong; intro HOL.refl renum_acts_bij_extends; simp add: act_set_def broadcast_def)\n  subgoal\n    apply (rule map_index_cong)\n    unfolding conv_automaton_of\n    apply safe\n    apply (fo_rule arg_cong)+\n    apply (erule renum_urge_automaton_eq[folded length_automata_eq_n_ps])\n    done\n  subgoal\n    using bounds'_var_set by - (fo_rule arg_cong, auto intro: renum_vars_bij_extends)\n  done\n\nlemma map_of_merge_pairs:\n  \"map_of (merge_pairs xs ys) = (\\<lambda>x.\n  (if x \\<in> fst ` set xs \\<and> x \\<in> fst ` set ys then Some (the (map_of xs x) @ the (map_of ys x))\n   else if x \\<in> fst ` set xs then map_of xs x\n   else map_of ys x))\"\nproof -\n  have 1: False if \"find_remove (\\<lambda>(k', _). k' = k) ys = None\" \"(k, x) \\<in> set ys\" for k x ys\n    using that unfolding find_remove_def by (auto simp: extract_None_iff)\n  have 2: \"map_of xs k = Some x\" if\n    \"find_remove (\\<lambda>(k', _). k' = k) xs = Some ((k', x), ys)\" for k k' x xs ys\n    using that\n    by (auto 4 4 split: option.split dest: map_of_SomeD find_remove_SomeD simp: map_add_def)\n  show ?thesis\n    apply (rule ext)\n    apply (induction xs arbitrary: ys)\n     apply (simp; fail)\n    apply (clarsimp split: if_split_asm option.split)\n    apply (auto 4 3 split: option.split simp: map_add_def dest: find_remove_SomeD 2 1)\n    done\nqed\n\nlemma default_map_of_merge_pairs:\n  \"default_map_of [] (merge_pairs xs ys) = (\\<lambda>x.\n  (if x \\<in> fst ` set xs then the (map_of xs x) @ default_map_of [] ys x\n   else default_map_of [] ys x))\"\n  unfolding default_map_of_alt_def map_of_merge_pairs\n  by (rule ext) (auto 4 3 dest: map_of_SomeD weak_map_of_SomeI split: if_split_asm)\n\nlemma automaton_of_conv_urge_commute:\n  \"automaton_of (conv_urge urge A) = urge.add_reset (urge.add_inv (automaton_of A))\"\n  unfolding conv_urge_def urge.add_reset_def urge.add_inv_def automaton_of_def\n  apply (clarsimp split: prod.splits)\n  apply (rule ext)\n  unfolding default_map_of_merge_pairs\n  apply auto\n  subgoal premises prems for _ urgent _ _ l\n  proof -\n    have *: \"map_of (map (\\<lambda>x. (x, [acconstraint.LE urge 0])) urgent)\n      = (\\<lambda>l. if l \\<in> set urgent then Some [acconstraint.LE urge 0] else None)\"\n      using map_of_map_keys[where\n          m = \"\\<lambda>l. if l \\<in> set urgent then Some [acconstraint.LE urge 0] else None\"]\n      by (force cong: map_cong simp: dom_def)\n    from \\<open>l \\<in> set urgent\\<close> show ?thesis\n      by (subst *) auto\n  qed\n  done\n\nlemma urge_commute:\n  \"rename.sem = urge.A_urge\"\n  unfolding rename.sem_def urge.A_urge_def\n  apply simp\n  unfolding conv_automaton_conv_urge_commute conv_automaton_of automaton_of_conv_urge_commute\n  by fast\n\nlemma conv_automaton_of':\n  \"automaton_of \\<circ> conv_automaton = Simple_Network_Language.conv_A o automaton_of\"\n  unfolding comp_def conv_automaton_of ..\n\nsublocale urge_bisim: Bisimulation_Invariant\n  \"\\<lambda>(L, s, u) (L', s', u'). step_u' sem L s u L' s' u'\"\n  \"\\<lambda>(L, s, u) (L', s', u'). step_u' rename.sem L s u L' s' u'\"\n  \"\\<lambda>(L, s, u) (L', s', u'). L' = L \\<and> s' = s \\<and> u' = u(urge := 0)\"\n  \"\\<lambda> (L, s, u). L \\<in> states\" \"\\<lambda>(L, s, u). True\"\n  unfolding urge_commute sem_def conv_automaton_of' by (rule urge.urge_bisim[unfolded conv_states])\n\nlemma check_sexp_equiv:\n  assumes \"urge_bisim.A_B.equiv' (L, s, u) (L', s', u')\"\n  shows \"check_sexp e L (the o s) = check_sexp e L' (the o s')\"\n  using assms unfolding urge_bisim.A_B.equiv'_def by simp\n\ncontext\n  fixes a\\<^sub>0 :: \"'s list \\<times> ('x \\<Rightarrow> int option) \\<times> ('c \\<Rightarrow> real)\"\n  assumes start: \"fst a\\<^sub>0 \\<in> states\" \"snd (snd a\\<^sub>0) urge = 0\"\nbegin\n\nlemma start_equiv: \"urge_bisim.A_B.equiv' a\\<^sub>0 a\\<^sub>0\"\n  using start unfolding urge_bisim.A_B.equiv'_def by auto\n\nlemma urge_models_iff:\n  \"sem,a\\<^sub>0 \\<Turnstile> \\<Phi> \\<longleftrightarrow> rename.sem,a\\<^sub>0 \\<Turnstile> \\<Phi>\"\nproof -\n  have \"rel_ctl_formula urge_bisim.compatible (ctl_of \\<Phi>) (ctl_of \\<Phi>)\"\n    by (cases \\<Phi>) (auto simp: prop_of_def rel_fun_def check_sexp_equiv)\n  with start_equiv show ?thesis\n    by (simp only: models_ctl_iff urge_bisim.CTL_compatible[THEN rel_funD, symmetric])\nqed\n\nlemma urge_has_deadlock_iff:\n  \"has_deadlock sem a\\<^sub>0 \\<longleftrightarrow> has_deadlock rename.sem a\\<^sub>0\"\n  unfolding has_deadlock_def using start_equiv\n  by (intro urge_bisim.deadlock_iff, unfold urge_bisim.A_B.equiv'_def) auto\n\nlemma state_formula_compatible:\n  \"(\\<Union>x \\<in> set_state_formula \\<phi>. locs_of_sexp x) \\<subseteq> {0..<n_ps} \\<Longrightarrow>\n  rel_state_formula urge_bisim.compatible\n    (map_state_formula (\\<lambda>P (L, s, _). check_sexp P L (the o s)) \\<phi>)\n    (map_state_formula (\\<lambda>P (L, s, _). check_sexp P L (the o s)) \\<phi>)\" and path_formula_compatible:\n  \"(\\<Union>x \\<in> set_path_formula \\<psi>. locs_of_sexp x) \\<subseteq> {0..<n_ps} \\<Longrightarrow>\n  rel_path_formula urge_bisim.compatible\n    (map_path_formula (\\<lambda>P (L, s, _). check_sexp P L (the o s)) \\<psi>)\n    (map_path_formula (\\<lambda>P (L, s, _). check_sexp P L (the o s)) \\<psi>)\"\n   by (induction \\<phi> and \\<psi>) (auto simp: check_sexp_equiv prop_of_def rel_fun_def)\n\nlemmas urge_models_state_compatible =\n  urge_bisim.models_state_compatible[OF state_formula_compatible]\n\nend (* Start State *)\n\nend (* Simple_Network_Rename *)\n\n\nlocale Simple_Network_Rename_Start =\n  Simple_Network_Rename where automata = automata\n  for automata ::\n    \"('s list \\<times> 's list\n      \\<times> (('a :: countable) act, 's, 'c, int, 'x :: countable, int) transition list\n      \\<times> (('s :: countable) \\<times> ('c :: countable, int) cconstraint) list) list\" +\n  fixes s\\<^sub>0 :: \"('x \\<times> int) list\"\n    and L\\<^sub>0 :: \"'s list\"\n  assumes L\\<^sub>0_states: \"L\\<^sub>0 \\<in> states\"\n      and s\\<^sub>0_dom: \"fst ` set s\\<^sub>0 = var_set\" and s\\<^sub>0_distinct: \"distinct (map fst s\\<^sub>0)\"\nbegin\n\nlemma rename_n_ps_eq:\n  \"rename.n_ps = n_ps\"\n  unfolding rename.length_automata_eq_n_ps[symmetric] n_ps_def by simp\n\nlemma rename_states_eq:\n  \"rename.states = states\"\n  unfolding rename.states_def states_def rename_n_ps_eq\n  by (simp add: rename.N_eq[unfolded rename_n_ps_eq] N_eq n_ps_def del: map_map)\n     (auto simp: automaton_of_def conv_urge_def trans_def split: prod.splits)\n\nlemma state_eq:\n  \"map_of (map (\\<lambda>(x, y). (extend_bij renum_vars var_set x, y)) s\\<^sub>0) =\n    map_of (map (\\<lambda>(x, y). (renum_vars x, y)) s\\<^sub>0)\"\n  using s\\<^sub>0_dom by - (rule arg_cong, auto intro: renum_vars_bij_extends)\n\nlemma sexp_eq:\n  assumes\n    \\<open>vars_of_sexp e \\<subseteq> var_set\\<close>\n    \\<open>set2_sexp e \\<subseteq> loc_set\\<close>\n    \\<open>locs_of_sexp e \\<subseteq> {0..<n_ps}\\<close>\n  shows \\<open>map_sexp (\\<lambda>p. extend_bij (renum_states p) loc_set) (extend_bij renum_vars var_set) id e =\n         map_sexp renum_states renum_vars id e\\<close>\n  using assms by (induction e; clarsimp simp: renum_states_extend)\n\nlemma L\\<^sub>0_dom:\n  \"length L\\<^sub>0 = n_ps\" \"set L\\<^sub>0 \\<subseteq> loc_set\"\n  using L\\<^sub>0_states by (auto intro!: states_loc_setD)\n\ndefinition\n  \"a\\<^sub>0 = (L\\<^sub>0, map_of s\\<^sub>0, \\<lambda>_. 0)\"\n\ndefinition\n  \"a\\<^sub>0' = (\n    map_index (\\<lambda>p. renum_states p) L\\<^sub>0,\n    map_of (map (\\<lambda>(x, y). (renum_vars x, y)) s\\<^sub>0),\n    \\<lambda>_. 0)\"\n\nsublocale rename: Simple_Network_Rename_Start_int\n  broadcast bounds'\n  \"extend_bij renum_acts act_set\"\n  \"extend_bij renum_vars var_set\"\n  \"extend_bij renum_clocks (insert urge clk_set')\"\n  \"\\<lambda>p. extend_bij (renum_states p) loc_set\"\n  s\\<^sub>0 L\\<^sub>0\n  \"map (conv_urge urge) automata\"\n  apply (standard; (rule L\\<^sub>0_states[folded rename_states_eq] s\\<^sub>0_distinct)?)\n  unfolding s\\<^sub>0_dom rename.bounds'_var_set[symmetric] bounds'_var_set ..\n\nlemma rename_a\\<^sub>0_eq:\n  \"rename.a\\<^sub>0 = a\\<^sub>0\"\n  unfolding rename.a\\<^sub>0_def a\\<^sub>0_def ..\n\nlemma rename_a\\<^sub>0'_eq:\n  \"rename.a\\<^sub>0' = a\\<^sub>0'\"\n  unfolding a\\<^sub>0'_def rename.a\\<^sub>0'_def\n  apply (clarsimp, rule conjI)\n  subgoal\n    using L\\<^sub>0_dom by (auto intro!: map_index_cong renum_states_extend)\n  subgoal\n    unfolding vars_inv_def using s\\<^sub>0_dom s\\<^sub>0_distinct\n    by (auto simp: state_eq Simple_Network_Rename_Defs.vars_inv_def)\n  done\n\nlemma has_deadlock_iff:\n  \"has_deadlock rename.renum.sem a\\<^sub>0' \\<longleftrightarrow> has_deadlock sem a\\<^sub>0\"\nproof -\n  have \"has_deadlock sem a\\<^sub>0 \\<longleftrightarrow> has_deadlock rename.sem a\\<^sub>0\"\n    by (rule urge_has_deadlock_iff) (auto intro: L\\<^sub>0_states simp: a\\<^sub>0_def)\n  also have \"\\<dots> \\<longleftrightarrow> has_deadlock rename.renum.sem a\\<^sub>0'\"\n    by (rule rename.has_deadlock_iff[unfolded rename_a\\<^sub>0_eq rename_a\\<^sub>0'_eq])\n  finally show ?thesis ..\nqed\n\nlemma N_eq_sem:\n  \"Simple_Network_Language_Model_Checking.N broadcast automata bounds' = sem\"\n  unfolding conv_alt_def sem_def\n  by safe (rule nth_equalityI; simp add: conv_N_eq N_eq sem_N_eq conv_automaton_of n_ps_def)\n\nlemma rename_N_eq_sem':\n  \"Simple_Network_Language_Model_Checking.N\n    (map renum_acts broadcast)\n    (map_index renum_automaton automata)\n    (map (\\<lambda>(a,p). (renum_vars a,p)) bounds')\n  = renum.sem\"\n  unfolding renum.sem_def\n  unfolding renum.conv_alt_def\n  by safe (rule nth_equalityI; simp add: conv_N_eq N_eq sem_N_eq conv_automaton_of n_ps_def)\n\nlemmas has_deadlock_iff' =\n  has_deadlock_iff[unfolded rename_N_eq_sem, folded N_eq_sem, unfolded a\\<^sub>0_def a\\<^sub>0'_def]\n\nlemmas start_equiv = start_equiv[of a\\<^sub>0, unfolded a\\<^sub>0_def, simplified, OF L\\<^sub>0_states]\n\nlemmas urge_models_state_compatible =\n  urge_models_state_compatible[THEN rel_funD, OF _ _ _ start_equiv,\n    of a\\<^sub>0, unfolded a\\<^sub>0_def, simplified, OF L\\<^sub>0_states]\n\nlemmas rename_models_state_compatible =\n  rename.models_state_compatible[THEN rel_funD, OF _ rename.start_equiv,\n    unfolded rename_a\\<^sub>0_eq a\\<^sub>0_def rename_n_ps_eq rename_a\\<^sub>0'_eq a\\<^sub>0'_def]\n\nlemmas models_state_compatible =\n  transp_equality[THEN transpD, OF urge_models_state_compatible rename_models_state_compatible]\n\nlemmas models_state_compatible' = models_state_compatible[unfolded rename_N_eq_sem, folded N_eq_sem]\n\nend\n\nlocale Simple_Network_Rename_Formula =\n  Simple_Network_Rename_Start where automata = automata\n  for automata ::\n    \"('s list \\<times> 's list\n      \\<times> (('a :: countable) act, 's, 'c, int, 'x :: countable, int) transition list\n      \\<times> (('s :: countable) \\<times> ('c :: countable, int) cconstraint) list) list\" +\n  fixes \\<Phi> :: \"(nat, 's, 'x, int) formula\"\n  assumes formula_dom:\n    \"set2_formula \\<Phi> \\<subseteq> loc_set\"\n    \"locs_of_formula \\<Phi> \\<subseteq> {0..<n_ps}\"\n    \"vars_of_formula \\<Phi> \\<subseteq> var_set\"\nbegin\n\nsublocale rename: Simple_Network_Rename_Formula_int\n  broadcast bounds'\n  \"extend_bij renum_acts act_set\"\n  \"extend_bij renum_vars var_set\"\n  \"extend_bij renum_clocks (insert urge clk_set')\"\n  \"\\<lambda>p. extend_bij (renum_states p) loc_set\"\n  s\\<^sub>0 L\\<^sub>0\n  \"map (conv_urge urge) automata\"\n  apply (standard; (rule L\\<^sub>0_states[folded rename_states_eq] s\\<^sub>0_distinct)?)\n  unfolding s\\<^sub>0_dom rename.bounds'_var_set[symmetric] bounds'_var_set .\n\ndefinition\n  \"\\<Phi>' = map_formula (\\<lambda>p. renum_states p) renum_vars id \\<Phi>\"\n\nlemma rename_\\<Phi>'_eq:\n  \"rename.\\<Phi>' = \\<Phi>'\"\n  using formula_dom unfolding rename.\\<Phi>'_def \\<Phi>'_def by (induction \\<Phi>; clarsimp simp: sexp_eq)\n\nlemma models_iff1:\n  \"rename.renum.sem,a\\<^sub>0' \\<Turnstile> \\<Phi>' \\<longleftrightarrow> rename.sem,a\\<^sub>0 \\<Turnstile> \\<Phi>\"\n  by (intro rename.models_iff[unfolded rename_a\\<^sub>0_eq rename_a\\<^sub>0'_eq rename_\\<Phi>'_eq rename_n_ps_eq]\n       formula_dom sym)\n\nlemma models_iff2:\n  \"rename.sem,a\\<^sub>0 \\<Turnstile> \\<Phi> \\<longleftrightarrow> sem,a\\<^sub>0 \\<Turnstile> \\<Phi>\"\n  by (rule sym, intro urge_models_iff formula_dom) (auto intro: formula_dom L\\<^sub>0_states simp: a\\<^sub>0_def)\n\nlemma models_iff:\n  \"rename.renum.sem,a\\<^sub>0' \\<Turnstile> \\<Phi>' \\<longleftrightarrow> sem,a\\<^sub>0 \\<Turnstile> \\<Phi>\"\n  unfolding models_iff1 models_iff2 ..\n\nlemmas models_iff' =\n  models_iff[unfolded rename_N_eq_sem, folded N_eq_sem, unfolded a\\<^sub>0_def a\\<^sub>0'_def \\<Phi>'_def]\n\nend (* Simple_Network_Rename_Formula *)\n\nend (* Theory *)", "meta": {"author": "wimmers", "repo": "munta", "sha": "62cb1a4a4dbcfcf62c365e90faba15b0012d5a12", "save_path": "github-repos/isabelle/wimmers-munta", "path": "github-repos/isabelle/wimmers-munta/munta-62cb1a4a4dbcfcf62c365e90faba15b0012d5a12/Simple_Networks/Simple_Network_Language_Renaming.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5312093733737563, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.2573072410435041}}
{"text": "theory Rename_Cfg\nimports \"../RefPoint/SM_Cfg\"\n  Type_System SM_Finite_Reachable Gen_Cfg_Bisim\n  \"HOL-Library.IArray\"\nbegin\n\n(* TODO: Move *)\nlemma set_list_bind[simp]: \"set (List.bind m f) = Set.bind (set m) (\\<lambda>x. set (f x))\"\n  by (auto simp: List.bind_def)\n\nlemma rel_mset_of_mapI:\n  assumes \"\\<forall>x\\<in>set l. R (f x) (g x)\"\n  shows \"rel_mset R (mset (map f l)) (mset (map g l))\"\n  using assms\n  apply (induction l)\n  apply (auto simp: rel_mset_Zero rel_mset_Plus)\n  done\n\n\n(* TODO: Move? *)\nlemma finite_max1_elemI:\n  assumes \"(\\<forall>x y. x\\<in>S \\<and> y\\<in>S \\<longrightarrow> x=y)\"  \n  shows \"finite S\"\nproof (cases \"S={}\")\n  case False \n  with assms obtain x where \"S={x}\" by auto\n  thus ?thesis by auto\nqed auto\n\n\nlemma left_unique_finite_sngI: \n  assumes \"left_unique R\" \n  shows \"finite {a. R a b}\"\nproof (rule finite_subset)\n  { \n    fix x y\n    assume \"x\\<in>{a. R a b}\" \"y\\<in>{a. R a b}\"\n    hence \"x=y\" using assms\n      by (auto dest: left_uniqueD)\n  } thus \"finite {a. R a b}\"\n    by (blast intro: finite_max1_elemI)\nqed auto   \n\n\n\nfunction approx_reachable_list_aux :: \"cmd \\<Rightarrow> cmd list\" where\n  \"approx_reachable_list_aux (Assign c x e) = [Assign c x e, Skip]\"\n| \"approx_reachable_list_aux (Assign_local c x e) = [Assign_local c x e, Skip]\"\n| \"approx_reachable_list_aux (Assign_global c x e) = [Assign_global c x e, Skip]\"\n| \"approx_reachable_list_aux (Test e) = [Test e, Skip]\"\n| \"approx_reachable_list_aux (Skip) = [Skip]\"\n| \"approx_reachable_list_aux (Seq c1 c2) = (approx_reachable_list_aux c2) @ (do { c1\\<leftarrow>approx_reachable_list_aux c1; [Seq c1 c2] })\"\n| \"approx_reachable_list_aux (Or c1 c2) = (Or c1 c2) # (approx_reachable_list_aux c1 @ approx_reachable_list_aux c2)\"\n| \"approx_reachable_list_aux (Break) = [Break,Invalid]\"\n| \"approx_reachable_list_aux (Continue) = [Continue,Invalid]\"\n| \"approx_reachable_list_aux (Iterate c1 c2) = Skip #\n    (do { c1\\<leftarrow>approx_reachable_list_aux c1; [Iterate c1 c2] })\n  @ (do { c2'\\<leftarrow>approx_reachable_list_aux c2; [Iterate c2' c2] })\"\n| \"approx_reachable_list_aux Invalid = [Invalid]\"\nby pat_completeness auto\n\ntermination\n  apply (relation \"reachable_term_order_aux <*mlex*> measure size\")\n  apply (metis wf_measure wf_mlex)\n  apply (auto simp: mlex_prod_def)\n  done\n\nlemma approx_reachable_list_aux_refine: \n  \"set (approx_reachable_list_aux c) = approx_reachable c\"\n  apply (induction c rule: approx_reachable.induct)\n  apply (simp_all)\n  done\n\ndefinition \"cfg_V0 prog \\<equiv> proc_decl.body ` set (program.processes prog)\"\ndefinition \"cfg_V0_list prog \\<equiv> remdups (map proc_decl.body (program.processes prog))\"\n\nlemma cfg_V0_list_invar: \"distinct (cfg_V0_list prog)\"\n  unfolding cfg_V0_list_def by auto\n\nlemma cfg_V0_list_refine: \"set (cfg_V0_list prog) = cfg_V0 prog\"\n  unfolding cfg_V0_list_def cfg_V0_def by auto\n\n\ndefinition \"approx_reachable_list prog \\<equiv> \n  remdups (concat (map approx_reachable_list_aux (cfg_V0_list prog)))\"\n\ndefinition \"approx_reachable_prog prog \\<equiv> \\<Union>(approx_reachable`(cfg_V0 prog))\"\n\n\nlemma approx_reachable_list_invar: \"distinct (approx_reachable_list prog)\"\n  unfolding approx_reachable_list_def\n  by auto\n\nlemma approx_reachable_list_refine: \n  \"set (approx_reachable_list prog) = approx_reachable_prog prog\"\n  unfolding approx_reachable_list_def approx_reachable_prog_def\n  by (auto simp: approx_reachable_list_aux_refine cfg_V0_list_refine)\n\ntext \\<open>CFG successors\\<close>\nprimrec cfg_succ :: \"cmd \\<Rightarrow> ((action+brk_ctd) \\<times> cmd) set\" where\n  \"cfg_succ (Assign c x e) = {((Inl (AAssign c x e)), Skip)}\"\n| \"cfg_succ (Assign_local c x e) = {((Inl (AAssign_local c x e)), Skip)}\"\n| \"cfg_succ (Assign_global c x e) = {((Inl (AAssign_global c x e)), Skip)}\"\n| \"cfg_succ (Test e) = {((Inl (ATest e)), Skip)}\"\n| \"cfg_succ (Seq c1 c2) =\n  ( if c1=Skip then \n      {((Inl ASkip), c2)}\n    else\n      { (e,if c1'=Skip then c2 else Seq c1' c2) | c1' e.  (e,c1')\\<in>cfg_succ c1}\n  )\"\n| \"cfg_succ (Or c1 c2) = cfg_succ c1 \\<union> cfg_succ c2\"\n| \"cfg_succ (Break) = {(Inr AIBreak, Invalid)}\"\n| \"cfg_succ (Continue) = {(Inr AIContinue, Invalid)}\"\n| cfg_succ_iterate: \n  \"cfg_succ (Iterate c cb) =\n  (if c=Skip then {(Inl ASkip, Iterate cb cb)} else {})\n  \\<union> (\n    \\<lambda> (Inl e,c') \\<Rightarrow> (Inl e, if c'=Skip then Iterate cb cb else Iterate c' cb)\n    | (Inr AIBreak,_) \\<Rightarrow> (Inl ASkip,Skip)\n    | (Inr AIContinue,_) \\<Rightarrow> (Inl ASkip, Iterate cb cb)\n  )`cfg_succ c\"\n| \"cfg_succ Skip = {}\"\n| \"cfg_succ Invalid = {}\"\n\n\ndeclare cfg_succ_iterate[simp del]\nlemma cfg_succ_iterate'[simp]: \"cfg_succ (Iterate c cb) = \n  (if c=Skip then {(Inl ASkip, Iterate cb cb)} else {})\n  \\<union> { (Inl e, if c'=Skip then Iterate cb cb else Iterate c' cb) | e c'. (Inl e, c') \\<in> cfg_succ c }\n  \\<union> (if \\<exists>c'. (Inr AIBreak,c')\\<in> cfg_succ c then { (Inl ASkip, Skip)} else {})\n  \\<union> (if \\<exists>c'. (Inr AIContinue,c')\\<in> cfg_succ c then { (Inl ASkip, Iterate cb cb)} else {})\"\n  unfolding cfg_succ_iterate\n  apply (rule sym)\n  apply (cases \"c=Skip\")\n  apply simp\n  apply safe\n  apply simp_all\n  apply force\n  apply (force split: if_split_asm)\n  apply (force split: if_split_asm)\n  apply (auto split: if_split_asm sum.splits brk_ctd.splits)\n  done\n\nlemma cfg_succ_iff_cfg: \"(a,c')\\<in>cfg_succ c \\<longleftrightarrow> cfg c a c'\"\n  apply rule\n  apply (induction c arbitrary: a c')\n  apply ((auto intro: cfg.intros split: if_split_asm) [])+\n  \n  apply (induction rule: cfg.induct)\n  apply auto\n  done\n\ntheorem cfg_succ_correct: \"cfg_succ c = {(a,c'). cfg c a c'}\"\n  using cfg_succ_iff_cfg by auto\n\nlemma cfg_succ_finite[simp, intro!]: \"finite (cfg_succ c)\"\n  apply (induction c)\n  using [[simproc add: finite_Collect]]\n  apply (simp_all del: cfg_succ_iterate' add: cfg_succ_iterate)\n  done\n \n\nprimrec cfg_succ_list :: \"cmd \\<Rightarrow> ((action+brk_ctd) \\<times> cmd) list\" where\n  \"cfg_succ_list (Assign ge x e) = [((Inl (AAssign ge x e)), Skip)]\"\n| \"cfg_succ_list (Assign_local ge x e) = [((Inl (AAssign_local ge x e)), Skip)]\"\n| \"cfg_succ_list (Assign_global ge x e) = [((Inl (AAssign_global ge x e)), Skip)]\"\n| \"cfg_succ_list (Test e) = [((Inl (ATest e)), Skip)]\"\n| \"cfg_succ_list (Seq c1 c2) =\n    ( if c1=Skip then \n        [((Inl ASkip), c2)] \n      else \n        map (\\<lambda>(e,c1'). (e,if c1'=Skip then c2 else Seq c1' c2)) (cfg_succ_list c1)\n    )\"\n| \"cfg_succ_list (Or c1 c2) = remdups (cfg_succ_list c1 @ cfg_succ_list c2)\"\n| \"cfg_succ_list (Break) = [(Inr AIBreak, Invalid)]\"\n| \"cfg_succ_list (Continue) = [(Inr AIContinue, Invalid)]\"\n| cfg_succ_list_iterate: \n  \"cfg_succ_list (Iterate c cb) =\n  (if c=Skip then [(Inl ASkip, Iterate cb cb)] else [])\n  @ remdups (map (\n    \\<lambda> (Inl e,c') \\<Rightarrow> (Inl e, if c'=Skip then Iterate cb cb else Iterate c' cb)\n    | (Inr AIBreak,_) \\<Rightarrow> (Inl ASkip,Skip)\n    | (Inr AIContinue,_) \\<Rightarrow> (Inl ASkip, Iterate cb cb)\n  ) (cfg_succ_list c))\"\n| \"cfg_succ_list Skip = []\"\n| \"cfg_succ_list Invalid = []\"\n\n(* FIXME: Strange, the simplifier should know such lemmas!? *)\nlemma Seq_ne_structural[simp]:\n  \"Seq a b \\<noteq> a\"\n  \"Seq a b \\<noteq> b\"\n  \"a \\<noteq> Seq a b\"\n  \"b \\<noteq> Seq a b\"\nproof -\n  show G1: \"Seq a b \\<noteq> a\"\n    by (induction a arbitrary: b) auto\n  show G2: \"Seq a b \\<noteq> b\"\n    by (induction b arbitrary: a) auto\n  show \"a \\<noteq> Seq a b\" using G1 by simp\n  show \"b \\<noteq> Seq a b\" using G2 by simp\nqed\n\nlemma cfg_succ_list_invar: \"distinct (cfg_succ_list c)\"\n  apply (induction c)\n  apply (auto simp: distinct_map)\n  apply (rule inj_onI)\n  apply (auto split: if_split_asm ) []\n  done  \n\nlemma cfg_succ_list_refine: \"set (cfg_succ_list c) = cfg_succ c\"\n  apply (induction c)\n  apply (simp_all only: cfg_succ.simps cfg_succ_list.simps \n    if_distrib[of set] if_same_eq set_map)\n  apply (simp_all)\n  apply (auto, force+) []\n  done\n\ndefinition \"cfg'_succ_list c \\<equiv> map (map_prod projl id) (filter (isl o fst) (cfg_succ_list c))\"\n\nlemma cfg'_succ_list_invar: \"distinct (cfg'_succ_list c)\"\n  unfolding cfg'_succ_list_def\n  apply (auto simp: distinct_map cfg_succ_list_invar intro!: inj_onI)\n  apply (rename_tac a a' foo)\n  apply (case_tac a, simp_all)\n  done\n  \nlemma cfg'_succ_list_refine: \"set (cfg'_succ_list c) = {(a,c'). cfg' c a c'}\"\n  unfolding cfg'_succ_list_def\n  by (force simp: cfg_succ_list_refine cfg'_def cfg_succ_correct)\n\n\n\n\n\ndefinition \"index_of l x \\<equiv> \n  if \\<exists>i<length l. l!i=x then\n    Some (THE i. i<length l \\<and> l!i=x)\n  else None\"\n\nlemma index_of_Some_conv:\n  assumes \"distinct l\"\n  shows \"index_of l x = Some i \\<longleftrightarrow> i < length l \\<and> l ! i = x\"\nproof safe\n  show \"index_of l x = Some i \\<Longrightarrow> i < length l\"\n    using assms unfolding index_of_def distinct_conv_nth\n    by (metis (mono_tags, lifting) option.distinct(1) option.inject theI)\n  show \"index_of l x = Some i \\<Longrightarrow> l ! i = x\"\n    using assms unfolding index_of_def distinct_conv_nth\n    by (metis (mono_tags, lifting) option.distinct(1) option.inject theI)\n  show \"i < length l \\<Longrightarrow> x = l ! i \\<Longrightarrow> index_of l (l ! i) = Some i\"\n    using assms unfolding index_of_def distinct_conv_nth by auto\nqed\n\nlemma dom_index_of: \"dom (index_of l) = set l\"\n  by (auto simp: index_of_def in_set_conv_nth split: if_split_asm)\n\nlemma index_of_None_conv: \"index_of l x = None \\<longleftrightarrow> x\\<notin>set l\"\n  using dom_index_of[of l] by auto\n\nlemma index_of_Nil: \"index_of [] x = None\"\n  by (auto simp: index_of_None_conv)\n\nlemma index_of_Cons: \"distinct (a#l) \n  \\<Longrightarrow> index_of (a#l) x = (if x=a then Some 0 else map_option Suc (index_of l x))\"\n  apply (auto simp: index_of_Some_conv)\n  apply (cases \"index_of (a # l) x\")\n  apply (simp_all only: )\n  apply (cases \"index_of l x\")\n  apply (simp_all only: ) [2]\n  apply (auto simp: index_of_Some_conv index_of_None_conv) [2]\n  apply (cases \"index_of l x\")\n  apply (simp_all only: )\n  apply (auto simp: index_of_Some_conv index_of_None_conv \n    in_set_conv_nth nth_Cons nth_eq_iff_index_eq split: nat.splits)\n  done\n\nprimrec cr_index_of where\n  \"cr_index_of [] x = None\"\n| \"cr_index_of (a#l) x = (if x=a then Some 0 else map_option Suc (cr_index_of l x))\"\n\nlemma cr_index_of_eq: \"distinct l \\<Longrightarrow> cr_index_of l = index_of l\"\n  apply (induction l)\n  apply (auto simp: index_of_Nil index_of_Cons)\n  done\n\nlocale sl_graph = asystem +\n  fixes rlist and succ_list\n  assumes rl_distinct: \"distinct rlist\"\n  assumes rl_reachable: \"E\\<^sup>* `` V0 \\<subseteq> set rlist\"\n  assumes rl_closed: \"\\<And>c c'. \\<lbrakk>c\\<in>set rlist; (c, c') \\<in> step\\<rbrakk> \\<Longrightarrow> c'\\<in>set rlist\"\n  assumes sl_distinct: \"c\\<in>set rlist \\<Longrightarrow> distinct (succ_list c)\"\n  assumes sl_succs: \"set (succ_list c) = {(a,c'). astep c a c'}\"\nbegin\n  definition \"succs_tab \\<equiv> map succ_list rlist\"\n\n  lemma astep_succs_tab_conv:\n    assumes R: \"c\\<in>set rlist\"\n    shows \"astep c a c' \\<longleftrightarrow> (\\<exists>i<length succs_tab. c=rlist!i \\<and> (a,c')\\<in>set (succs_tab!i))\"\n  proof -\n    from R obtain i where \"i<length rlist\" and RLI[simp]: \"rlist!i=c\"\n      by (auto simp: in_set_conv_nth)\n    hence 1: \"i<length succs_tab\" \"succs_tab!i=succ_list c\"\n      unfolding succs_tab_def\n      by auto\n\n    have AUX: \"\\<And>j. \\<lbrakk>c = rlist!j; j<length succs_tab\\<rbrakk> \\<Longrightarrow> i=j\" \n    proof -\n      fix j\n      assume \"c = rlist!j\" \"j<length succs_tab\"\n      hence \"rlist!j=rlist!i\" \"j<length rlist\" by (simp_all add: succs_tab_def)\n      with nth_eq_iff_index_eq[OF rl_distinct \\<open>i<length rlist\\<close> \\<open>j<length rlist\\<close>]  \n      show \"i=j\" by simp\n    qed\n\n    from 1 show ?thesis using sl_succs \n      by (auto dest: AUX)\n  qed\n\n  lemma succs_tab_invar: \"i<length succs_tab \\<Longrightarrow> distinct (succs_tab!i)\"\n    unfolding succs_tab_def \n    using rl_reachable sl_distinct\n    by auto\n\n  lemma succs_tab_rl: \"\\<lbrakk>i<length rlist; (a,c')\\<in>set (succs_tab!i)\\<rbrakk> \n    \\<Longrightarrow> c' \\<in> set rlist\"\n    unfolding succs_tab_def\n    apply (simp add: sl_succs)\n    apply (rule rl_closed[rotated])\n    unfolding step_def\n    apply blast\n    apply simp\n    done\n\n  definition \"mapped_succs_tab \\<equiv> IArray (\n    map (map (\\<lambda>(a,c'). (a,the (cr_index_of rlist c')))) succs_tab)\"\n\n  \n\n  definition \"\\<gamma> c \\<equiv> the (cr_index_of rlist c)\"\n  definition \"\\<alpha> i \\<equiv> rlist!i\"\n  definition \"succ_impl ci \\<equiv> \n    if ci<IArray.length mapped_succs_tab then \n      mapped_succs_tab!!ci\n    else []\"\n  definition \"astep_impl c a c' \\<equiv> (a,c')\\<in>set (succ_impl c)\"\n\n  lemma astep_succ_finite[simp, intro!]: \n    \"finite {(a,c'). astep_impl c a c'}\"\n    unfolding astep_impl_def\n    by auto\n\n  lemma astep_succ_finite_c[simp, intro!]:\n    \"finite ({c'. \\<exists>a. astep_impl c a c'})\"\n  proof -\n    have \"{c'. \\<exists>a. astep_impl c a c'} = snd`{(a,c'). astep_impl c a c'}\"\n      by auto\n    also have \"finite \\<dots>\" by auto\n    finally show ?thesis .\n  qed  \n\n  lemma \\<alpha>_inj: \"inj_on \\<alpha> {0..<length rlist}\"\n    by (auto intro!: inj_onI simp: \\<alpha>_def nth_eq_iff_index_eq[OF rl_distinct])\n\n  lemma \\<gamma>_inj: \"inj_on \\<gamma> (set rlist)\"\n    using rl_reachable\n    apply (auto intro!: inj_onI \n      simp: \\<gamma>_def rl_distinct \n      cr_index_of_eq)\n    by (metis index_of_None_conv index_of_Some_conv not_None_eq \n      option.sel rl_distinct)\n    \n  lemma \\<gamma>_\\<alpha>_inverse: \"i<length rlist \\<Longrightarrow> \\<gamma> (\\<alpha> i) = i\"  \n    unfolding \\<alpha>_def \\<gamma>_def\n    apply (auto simp: cr_index_of_eq[OF rl_distinct])\n    apply (cases \"index_of rlist (rlist ! i)\", simp_all)\n    apply (auto simp: index_of_None_conv index_of_Some_conv[OF rl_distinct]\n      simp: nth_eq_iff_index_eq[OF rl_distinct])\n    done\n    \n  lemma \\<alpha>_\\<gamma>_inverse: \"c\\<in>set rlist \\<Longrightarrow> \\<alpha> (\\<gamma> c) = c\"  \n    unfolding \\<alpha>_def \\<gamma>_def\n    apply (auto simp: cr_index_of_eq[OF rl_distinct])\n    apply (cases \"index_of rlist c\", simp_all)\n    apply (auto simp: index_of_None_conv index_of_Some_conv[OF rl_distinct]\n      simp: nth_eq_iff_index_eq[OF rl_distinct])\n    done\n\n  lemma \\<gamma>_invar: \"c\\<in>set rlist \\<Longrightarrow> \\<gamma> c < length rlist\"\n    apply (auto simp: \\<gamma>_def cr_index_of_eq rl_distinct)\n    by (metis index_of_None_conv index_of_Some_conv \n      not_None_eq option.sel rl_distinct)\n\n  lemma \\<alpha>_invar: \"i<length rlist \\<Longrightarrow> \\<alpha> i \\<in> set rlist\"\n    unfolding \\<alpha>_def by simp  \n\n  definition \"invar i \\<equiv> i<length rlist\"    \n  definition \"rel \\<equiv> brp \\<alpha> invar\"  \n  definition \"reli \\<equiv> brp \\<gamma> (\\<lambda>x. x\\<in>set rlist)\"  \n\n  lemma bi_unique_rel: \"bi_unique rel\"\n    apply (intro bi_uniqueI left_uniqueI right_uniqueI)\n    by (auto simp: rel_def build_relp_def invar_def\n      inj_onD[OF \\<alpha>_inj])\n\n  lemma bi_unique_reli: \"bi_unique reli\"\n    apply (intro bi_uniqueI left_uniqueI right_uniqueI)\n    by (auto simp: reli_def build_relp_def \n      inj_onD[OF \\<gamma>_inj])\n\n  lemma rel_inv_eq_reli: \"rel\\<inverse>\\<inverse> = reli\"\n    by (auto \n      intro!: ext \n      simp: rel_def reli_def build_relp_def invar_def\n      simp: \\<gamma>_\\<alpha>_inverse \\<alpha>_\\<gamma>_inverse \\<gamma>_invar \\<alpha>_invar\n      )\n\n  corollary reli_inv_eq_rel: \"reli\\<inverse>\\<inverse> = rel\"\n    using arg_cong[where f=\"\\<lambda>r. r\\<inverse>\\<inverse>\", OF rel_inv_eq_reli, simplified]\n    by simp\n\n  lemma rel_unfold1: \"c\\<in>set rlist \\<Longrightarrow> rel i c \\<longleftrightarrow> i = \\<gamma> c\"  \n    unfolding reli_inv_eq_rel[symmetric]\n    by (simp add: reli_def build_relp_def)\n\n  lemma is_reachable_criE:\n    assumes R: \"c \\<in> E\\<^sup>* `` V0\"\n    obtains i where \"cr_index_of rlist c = Some i\"\n  proof -\n    from R have IS: \"c\\<in>set rlist\" using rl_reachable by auto\n\n    show ?thesis\n      using IS\n      by (auto \n        simp: cr_index_of_eq[OF rl_distinct] index_of_Some_conv[OF rl_distinct]\n        simp: in_set_conv_nth\n        intro: that)\n  qed\n\n  lemma sim1i: \"\\<lbrakk> astep c1 a c2; reli c1 c1' \\<rbrakk> \\<Longrightarrow> \\<exists>c2'. reli c2 c2' \\<and> astep_impl c1' a c2'\"\n    apply (auto simp: reli_def build_relp_def)\n    apply (rule rl_closed, auto simp: step_def) []\n  proof -\n    assume R: \"c1\\<in>set rlist\" and S: \"astep c1 a c2\"\n    then obtain i where L: \"i<length succs_tab\" \n      and C1: \"c1=rlist!i\" and AC': \"(a,c2)\\<in>set (succs_tab!i)\"\n      by (auto simp: astep_succs_tab_conv)\n\n    have [simp]: \"i<length rlist\" using L by simp  \n    note [simp] = L\n\n    from C1 have [simp]: \"\\<gamma> c1 = i\"  \n      unfolding \\<gamma>_def\n      apply (cases \"cr_index_of rlist c1\")\n      apply simp_all\n      apply (auto simp: cr_index_of_eq[OF rl_distinct] \n        index_of_Some_conv[OF rl_distinct] index_of_None_conv \n        nth_eq_iff_index_eq[OF rl_distinct])        \n      done\n\n    show \"astep_impl (\\<gamma> c1) a (\\<gamma> c2)\" \n      using AC'\n      apply (auto simp: astep_impl_def succ_impl_def mapped_succs_tab_def)\n      apply (auto simp: \\<gamma>_def)\n      done\n  qed\n\n  lemma sim2i: \"\\<lbrakk> astep_impl c1' a c2'; reli c1 c1' \\<rbrakk> \\<Longrightarrow> \\<exists>c2. reli c2 c2' \\<and> astep c1 a c2\"\n  proof -\n    assume \"reli c1 c1'\"\n    hence R: \"c1\\<in>set rlist\" and [simp]: \"c1'=\\<gamma> c1\" \n      by (auto simp: reli_def build_relp_def)\n    \n    hence [simp]: \"\\<gamma> c1 < length rlist\"\n      unfolding \\<gamma>_def using rl_reachable\n      apply (cases \"cr_index_of rlist c1\", simp_all)\n      apply (auto simp: \\<alpha>_def cr_index_of_eq[OF rl_distinct] \n        index_of_None_conv index_of_Some_conv[OF rl_distinct])\n      done\n\n    have [simp]: \"rlist!\\<gamma> c1 = c1\"\n      unfolding \\<alpha>_def[symmetric]\n      by (simp add: \\<alpha>_\\<gamma>_inverse R)\n\n    assume \"astep_impl c1' a c2'\"\n    then obtain c2 where \"(a, c2) \\<in> set (succs_tab ! \\<gamma> c1)\" and [simp]: \"c2' = \\<gamma> c2\"\n      apply (auto simp: astep_impl_def succ_impl_def mapped_succs_tab_def)\n      apply (auto simp: \\<gamma>_def)\n      done\n    with astep_succs_tab_conv[THEN iffD2, OF R, OF exI, of c1' a c2]\n      have \"astep c1 a c2\" by auto\n     moreover hence \"c2\\<in>set rlist\" \n      using rl_closed[OF R, of c2] by (auto simp: step_def)\n    hence \"reli c2 c2'\"\n      by (auto simp: reli_def build_relp_def)\n    ultimately show \"\\<exists>c2. reli c2 c2' \\<and> astep c1 a c2\" by blast  \n  qed    \n\n  corollary sim1: \"\\<lbrakk> astep_impl c1' a c2'; rel c1' c1 \\<rbrakk> \\<Longrightarrow> \\<exists>c2. rel c2' c2 \\<and> astep c1 a c2\"\n    using sim2i unfolding reli_inv_eq_rel[symmetric] by simp\n\n  corollary sim2: \"\\<lbrakk> astep c1 a c2; rel c1' c1 \\<rbrakk> \\<Longrightarrow> \\<exists>c2'. rel c2' c2 \\<and> astep_impl c1' a c2'\"\n    using sim1i unfolding reli_inv_eq_rel[symmetric] by simp\n\n\n  lemma succ_impl_invar: \"distinct (succ_impl ci)\"\n    unfolding succ_impl_def mapped_succs_tab_def invar_def\n    using succs_tab_invar[of ci]\n    apply (clarsimp simp: distinct_map)\n    apply (fold \\<gamma>_def)\n    apply (rule inj_onI)\n    apply clarsimp (* TODO: This proof is not particular clean *)\n    apply (drule (1) succs_tab_rl[rotated])\n    apply (drule (1) succs_tab_rl[rotated])\n    by (metis \\<alpha>_\\<gamma>_inverse local.\\<alpha>_def)\n    \n  lemma succ_impl_invarc: \"\\<lbrakk>invar c; (a,c')\\<in>set (succ_impl c)\\<rbrakk> \\<Longrightarrow> invar c'\"\n    unfolding succ_impl_def mapped_succs_tab_def invar_def\n    apply (clarsimp)\n    by (metis \\<gamma>_def \\<gamma>_invar succs_tab_rl)\n        \n  lemma astep_impl_invarc: \"\\<lbrakk>invar c; astep_impl c a c'\\<rbrakk> \\<Longrightarrow> invar c'\"  \n    unfolding astep_impl_def\n    by (auto intro: succ_impl_invarc)\n\nend\n\nlemma path'_path_conv:\n  \"li'.cs.path c p c' \\<longleftrightarrow> cfg_lts.path c (map Inl p) c'\"\n  by (induction p arbitrary: c) (auto simp: cfg'_def)\n\nlemma approx_reachable_approx': \"li'.cs.reachable c c' \\<Longrightarrow> c' \\<in> approx_reachable c\"\n  using approx_reachable_approx[of c c']\n  by (auto simp: LTS.reachable_def path'_path_conv)\n\n(* TODO: Move *)\nlemma approx_reachable_closed':\n  assumes \"c\\<in>approx_reachable c0\"\n  assumes \"cfg' c a c'\"\n  shows \"c'\\<in>approx_reachable c0\"\n  using assms\n  unfolding cfg'_def\n  using approx_reachable_closed\n  by blast\n\ntype_synonym cmdc = nat\ntype_synonym local_config = \"(cmdc, local_state) Gen_Scheduler.local_config\"\ntype_synonym global_config = \"(cmdc, local_state, global_state) Gen_Scheduler.global_config\"\n\nlocale cprog = \n  fixes prog :: program\nbegin\n  sublocale comp: asystem \"\\<lambda>x. x\\<in>cfg_V0 prog\" cfg' .\n\n  sublocale comp: sl_graph \n    \"\\<lambda>x. x\\<in>cfg_V0 prog\" cfg' \n    \"approx_reachable_list prog\" \"cfg'_succ_list\" \n  apply unfold_locales\n  apply (simp_all \n    add: approx_reachable_list_invar approx_reachable_list_refine\n    add: cfg'_succ_list_invar cfg'_succ_list_refine\n    add: approx_reachable_prog_def \n    ) \n  using approx_reachable_approx'\n  apply (auto simp: comp.step_path_conv LTS.reachable_def) []\n\n  using approx_reachable_closed' unfolding comp.step_def\n  by blast\n\n  abbreviation \"cfgc \\<equiv> comp.astep_impl\"\n\n  definition init_pc :: \"proc_decl \\<Rightarrow> local_config\" where\n    \"init_pc pd \\<equiv> \\<lparr>\n      local_config.command = comp.\\<gamma> (proc_decl.body pd),\n      local_config.state = \\<lparr>\n        local_state.variables = init_valuation (proc_decl.local_vars pd)\n      \\<rparr>\n    \\<rparr>\"\n  \n  definition init_gc :: \"global_config\" where\n    \"init_gc \\<equiv> \\<lparr>\n      global_config.processes = mset (map init_pc (program.processes prog)),\n      global_config.state = \\<lparr>\n        global_state.variables = init_valuation (program.global_vars prog)\n      \\<rparr>\n    \\<rparr>\"\n\n\n  sublocale lih': Gen_Scheduler'_linit \n    cfgc la_en' la_ex' \n    \"{init_gc}\" global_config.state .\n\n  sublocale hc_bisim: Gen_Cfg_Bisim_Pre comp.rel\n    cfgc cfg' la_en' la_ex'\n    apply unfold_locales\n    apply (blast dest: comp.sim1)\n    apply (blast dest: comp.sim2)\n    done\n\n  lemma approx_reachable_prog0: \"p \\<in> set (program.processes prog) \\<Longrightarrow>\n         body p \\<in> approx_reachable_prog prog\"  \n    unfolding approx_reachable_prog_def\n    by (auto simp: cfg_V0_def intro!: bexI)\n\n\n  sublocale hc_bisim: Gen_Cfg_LBisim comp.rel\n    cfgc \"{init_gc}\" global_config.state\n    cfg' \"{SM_Semantics.init_gc prog}\" global_config.state la_en' la_ex'\n    apply unfold_locales\n    apply (auto \n      simp: init_gc_def SM_Semantics.init_gc_def \n      simp: init_pc_def SM_Semantics.init_pc_def \n      simp: hc_bisim.rel_gc_def hc_bisim.rel_lc_def\n      simp del: mset_map simp: mset_map[symmetric]\n      intro!: rel_mset_of_mapI)\n\n    apply (subst comp.rel_unfold1)\n    apply (unfold approx_reachable_list_refine)\n    apply (simp add: approx_reachable_prog0)\n    apply simp\n\n    apply (subst comp.rel_unfold1)\n    apply (unfold approx_reachable_list_refine)\n    apply (simp add: approx_reachable_prog0)\n    apply simp\n    done\n    \n  lemma lih'_accept_eq_li': \"lih'.sa.accept = li'.sa.accept prog\"  \n    by (rule hc_bisim.accept_bisim)\n\n\n  definition \"lc_\\<alpha> lc \\<equiv> \\<lparr>\n    local_config.command = comp.\\<alpha> (local_config.command lc),\n    local_config.state = local_config.state lc\n  \\<rparr>\"\n  definition \"lc_invar lc \\<equiv> comp.invar (local_config.command lc)\"\n\n  lemma hc_bisim_rel_lc_brp_conv: \"hc_bisim.rel_lc = brp lc_\\<alpha> lc_invar\"\n    apply (intro ext)\n    unfolding hc_bisim.rel_lc_def \n    unfolding comp.rel_def lc_\\<alpha>_def lc_invar_def build_relp_def\n    by auto\n    \n  definition \"gc_\\<alpha> gc \\<equiv> \\<lparr>\n    global_config.processes = image_mset lc_\\<alpha> (global_config.processes gc),\n    global_config.state = global_config.state gc\n  \\<rparr>\"\n  definition \"gc_invar gc \\<equiv> \\<forall>lc. lc \\<in># global_config.processes gc \\<longrightarrow> lc_invar lc\"\n\n  lemma hc_bisim_rel_gc_brp_conv: \"hc_bisim.rel_gc = brp gc_\\<alpha> gc_invar\"\n    apply (intro ext)\n    unfolding hc_bisim.rel_gc_def hc_bisim_rel_lc_brp_conv\n    unfolding comp.rel_def gc_\\<alpha>_def gc_invar_def\n    apply (auto simp: rel_mset_brp)\n    apply (auto simp: build_relp_def)\n    done\n\n  lemmas bi_unique_rel_gc = hc_bisim.bi_unique_rel_gcI[OF comp.bi_unique_rel] \n  lemmas bi_unique_rel_lc = hc_bisim.bi_unique_rel_lcI[OF comp.bi_unique_rel] \n\n  lemma run_sim_lih'_li: \"lih'.sa.is_run r \\<Longrightarrow> li'.sa.is_run prog (gc_\\<alpha> o r)\"\n    apply (rule hc_bisim.s1.br_run_sim)\n    unfolding hc_bisim_rel_gc_brp_conv\n    by auto\n\n  lemmas lih'_reachable_finite_sim = hc_bisim.s1.reachable_finite_sim\n\nend\n\ncontext well_typed_prog begin \n  sublocale cprog .\n\n  lemma lih'_accept_eq: \"lih'.sa.accept = ref_accept prog\"  \n    by (simp add: lih'_accept_eq_li' li'.accept_eq)\n\n  lemma lih'_is_run_sim: \"lih'.sa.is_run r \\<Longrightarrow> ref_is_run prog (Some o gc_\\<alpha> o r)\"\n    apply (drule run_sim_lih'_li)\n    unfolding li'.is_run_conv \n    by (auto simp: o_def)\n\n  lemma lih'_finite_reachable: \"finite ((g_E lih'.system_automaton)\\<^sup>* `` g_V0 lih'.system_automaton)\"\n    apply (rule lih'_reachable_finite_sim)\n    apply (rule li'_finite_reachable)\n    unfolding rel_of_pred_def\n    apply simp\n    apply (rule left_unique_finite_sngI)\n    using bi_unique_rel_gc\n    apply (simp add: bi_unique_alt_def)\n    done\n  \nend\n\n(* Executable *)\ntype_synonym comp_info = \"(cmd list \\<times> (action \\<times> nat) list iarray)\"\n(* TODO: Using a list is slow. Could use a hashmap to map commands to\n  their indices *)\n\ndefinition comp_info_of :: \"program \\<Rightarrow> comp_info\" where\n  \"comp_info_of prog \\<equiv> let\n  rlist = approx_reachable_list prog;\n  succs_tab = map cfg'_succ_list rlist;\n  mapped_succs_tab = IArray (\n    map (map (\\<lambda>(a,c'). (a,the (cr_index_of rlist c')))) succs_tab)\nin\n  (rlist,mapped_succs_tab)\"\n\ndefinition ccfg_succ_impl \n  :: \"comp_info \\<Rightarrow> nat \\<Rightarrow> (action \\<times> nat) list\"\nwhere\n  \"ccfg_succ_impl cinf c \\<equiv> \n    let mst=snd cinf in \n      if c<IArray.length mst then mst!!c else []\"\n\nlemma (in cprog) ccfg_succ_impl: \n  \"ccfg_succ_impl (comp_info_of prog) = comp.succ_impl\"\n  apply (intro ext)\n  unfolding comp.succ_impl_def comp.mapped_succs_tab_def comp.succs_tab_def\n  unfolding ccfg_succ_impl_def comp_info_of_def\n  by simp\n\ndefinition comp_\\<gamma>_impl :: \"comp_info \\<Rightarrow> cmd \\<Rightarrow> cmdc\" where\n  \"comp_\\<gamma>_impl cinf c \\<equiv> the (cr_index_of (fst cinf) c)\"\n\nlemma (in cprog) comp_\\<gamma>_impl: \"comp_\\<gamma>_impl (comp_info_of prog) = comp.\\<gamma>\"\n  apply (intro ext)\n  unfolding comp.\\<gamma>_def\n  unfolding comp_\\<gamma>_impl_def comp_info_of_def\n  by simp\n  \n\nexport_code comp_info_of ccfg_succ_impl comp_\\<gamma>_impl checking SML\n\n\nend\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/CAVA_LTL_Modelchecker/SM/Refine/Rename_Cfg.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953651858118, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.257291241538743}}
{"text": "theory flash85Rev imports flashPub\nbegin\nsection{*Main defintions*}\nlemma NI_FAckVsInv85:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv85 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_InvVsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1VsInv85:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1_HomeVsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_2VsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_GetXVsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_Nak1VsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_Nak2VsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_Nak3VsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_PutX1VsInv85:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv85:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv85:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv85:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv85:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv85:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv85:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv85:  \n  (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv85:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv85:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX10VsInv85:  \n  (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX10_homeVsInv85:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX11VsInv85:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_Get_GetVsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Nak1VsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Nak2VsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Nak3VsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Put1VsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Put2VsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Put3VsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_PutVsInv85:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_Local_PutXAcksDoneVsInv85:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv85 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_NakVsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Nak_ClearVsInv85:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv85 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_Nak_HomeVsInv85:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv85 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_Remote_GetX_NakVsInv85:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_Nak_HomeVsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_PutXVsInv85:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_PutX_HomeVsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Nak1VsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Nak2VsInv85:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Put1VsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Put2VsInv85:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_PutVsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_PutXVsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceVsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceHomeVsInv85:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv85 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_ReplaceHomeShrVldVsInv85:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv85 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_ReplaceShrVldVsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ShWbVsInv85:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv85 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_WbVsInv85:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv85 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_GetX_GetX1VsInv85:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv85 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_GetX_GetX2VsInv85:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv85 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_GetX_PutX1VsInv85:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv85 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_GetX_PutX2VsInv85:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv85 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_GetX_PutX3VsInv85:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv85 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_GetX_PutX4VsInv85:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv85 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_Get_GetVsInv85:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv85 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_Get_PutVsInv85:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv85 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_PutXVsInv85:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv85 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_ReplaceVsInv85:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv85 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Remote_GetVsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_GetXVsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_PutXVsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_ReplaceVsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma StoreVsInv85:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv85 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma StoreHomeVsInv85:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv85 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash85Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5774953651858118, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.257291241538743}}
{"text": "theory flash90Rev imports flashPub\nbegin\nsection{*Main defintions*}\n     \n     \n\nlemma lemmaOnPtrAtGetX[intro]:\n  assumes  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n    and a5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_GetX )) s\" and\n    a6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2)) s \" and\n    a7:\"\\<forall>f. f \\<in> (invariants   N) \\<longrightarrow> formEval f s \"\n shows  \"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n proof(rule ccontr)\n  assume b0:\"\\<not>formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n  have b1:\"formEval (inv2 iInv1 iInv2) s\"\n    apply(cut_tac a7)\n    \n    apply(drule_tac x=\"inv2  iInv1 iInv2\" in spec)\n    apply(cut_tac a7 a2 a3 a4,simp)\n    done\n with b0 a5 a6 show False\n  by auto\nqed  \n\n\n\nlemma lemmaOnPtrAtGet[intro]:\n  assumes  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n    and a5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get )) s\" and\n    a6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2)) s \" and\n    a7:\"\\<forall>f. f \\<in> (invariants   N) \\<longrightarrow> formEval f s \"\n shows  \"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n proof(rule ccontr)\n  assume b0:\"\\<not>formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n  have b1:\"formEval (inv3 iInv1 iInv2) s\"\n    apply(cut_tac a7)\n    \n    apply(drule_tac x=\"inv3  iInv1 iInv2\" in spec)\n    apply(cut_tac a7 a2 a3 a4,simp)\n    done\n with b0 a5 a6 show False\n  by auto\nqed  \n\nlemma lemmaOnPtr1[intro]:\n  assumes  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n    and a5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get )) s\" and\n    a6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2)) s \" and\n    a7:\"\\<forall>f. f \\<in> (invariants   N) \\<longrightarrow> formEval f s \" and\n    b2:\"iInv1' \\<le> N\" and  b3:\"iInv2' \\<le> N\" and  b4:\"iInv1'~=iInv2'  \" \n    and b5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1') )  ( Const UNI_Get )) s\" and\n    b6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1') )   (Const iInv2')) s \" and\n    b7:\"iInv2\\<noteq>iInv2'\"\n shows False\n proof -\n  have c1:\"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n    by(metis a2 a3 a4 a5 a6 a7 lemmaOnPtrAtGet)\n  have c2:\"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2') )  s\"\n    by(metis b2 b3 b4 b5 b6 a7 lemmaOnPtrAtGet)\n with c1 b7  show False\n  by auto\nqed  \n\n\nlemma lemmaOnPtr2[intro]:\n  assumes  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n    and a5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_GetX )) s\" and\n    a6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2)) s \" and\n    a7:\"\\<forall>f. f \\<in> (invariants   N) \\<longrightarrow> formEval f s \" and\n    b2:\"iInv1' \\<le> N\" and  b3:\"iInv2' \\<le> N\" and  b4:\"iInv1'~=iInv2'  \" \n    and b5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1') )  ( Const UNI_GetX )) s\" and\n    b6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1') )   (Const iInv2')) s \" and\n    b7:\"iInv2\\<noteq>iInv2'\"\n shows False\n proof -\n  have c1:\"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n    by(metis a2 a3 a4 a5 a6 a7 lemmaOnPtrAtGetX)\n  have c2:\"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2') )  s\"\n    by(metis b2 b3 b4 b5 b6 a7 lemmaOnPtrAtGetX)\n with c1 b7  show False\n  by auto\nqed \n\n\nlemma lemmaOnPtr3[intro]:\n  assumes  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n    and a5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get )) s\" and\n    a6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2)) s \" and\n    a7:\"\\<forall>f. f \\<in> (invariants   N) \\<longrightarrow> formEval f s \" and\n    b2:\"iInv1' \\<le> N\" and  b3:\"iInv2' \\<le> N\" and  b4:\"iInv1'~=iInv2'  \" \n    and b5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1') )  ( Const UNI_GetX )) s\" and\n    b6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1') )   (Const iInv2')) s \" and\n    b7:\"iInv2\\<noteq>iInv2'\"\n shows False\n proof -\n  have c1:\"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n    by(metis a2 a3 a4 a5 a6 a7 lemmaOnPtrAtGet)\n  have c2:\"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2') )  s\"\n    by(metis b2 b3 b4 b5 b6 a7 lemmaOnPtrAtGetX)\n with c1 b7  show False\n  by auto\nqed      \n\nabbreviation N::\"nat\"   where   \"N\\<equiv> M\"\nlemma NI_FAckVsInv90:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n     have allCases:\"formEval   (neg ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const true )) )  s  \\<or>formEval  ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const true ))  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume b1:\"formEval  (neg ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const true )) )  s\"\nhave \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n    }\n\n    moreover\n                       {assume b1:\"formEval ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const true ))  s\"\n\n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''ShWbMsg_Cmd'') )  ( Const SHWB_FAck ))    ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n    }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_InvVsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_InvAck_1VsInv90:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1_HomeVsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_InvAck_2VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_GetXVsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak1VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak2VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak3VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX1VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv90:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10VsInv90:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10_homeVsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX11VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_GetVsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_Get_Nak1VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak2VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak3VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put1VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put2VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put3VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_PutVsInv90:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_PutXAcksDoneVsInv90:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_NakVsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Nak_ClearVsInv90:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Nak_HomeVsInv90:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_NakVsInv90:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n       have \"?P3 s\"            \n     \n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_GetX ))     (neg ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2)) )  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n      \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n       have \"?P3 s\"   \n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_GetX ))   \n          (neg ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iRule2)) )  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iRule2))  ) ) \" in exI)\n        apply(rule conjI,simp)\n        apply force\n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  \n       have \"?P3 s\"   \n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iRule1) )  ( Const UNI_GetX ))  \n          ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iRule1) )   (Const iInv1))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  \n       have \"?P3 s\"   \n\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iRule1) )  ( Const UNI_GetX )) \n          (neg ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2)) )  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iRule1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n      \n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n                  \n         have \"?P3 s\"\n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iRule1) )  ( Const UNI_GetX ))   \n         ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iRule1) )   (Const iRule2))  ) ) \" in exI,auto)\n     \n        done\n\n      \n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast        \n\n                  \n\n   \n  \n \n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_Nak_HomeVsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv1))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  )    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv1))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  )    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv1))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  )    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_PutXVsInv90:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_GetX ))    ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv2) )   (Const iInv1))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv1))    ( eqn ( IVar ( Global ''NakcMsg_Cmd'') )  ( Const NAKC_Nakc ))  )    ( eqn ( IVar ( Para ''CacheState'' iRule2) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_PutX_HomeVsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Remote_Get_Nak1VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv1))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  )    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv1))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  )    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv1))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  )    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Nak2VsInv90:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))     (neg ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2)) )  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))  \n          (neg ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iRule2)) )  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iRule2))  ) ) \" in exI,rule conjI,simp,force)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iRule1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iRule1) )   (Const iInv1))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iRule1) )  ( Const UNI_Get ))     (neg ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2)) )  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iRule1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                   have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iRule1) )  ( Const UNI_Get ))   \n          ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iRule1) )   (Const iRule2))  ) ) \" in exI,simp)\n        by force\n        \n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Put1VsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Remote_Get_Put2VsInv90:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutVsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutXVsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_ReplaceVsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_ReplaceHomeVsInv90:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceHomeShrVldVsInv90:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceShrVldVsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_ShWbVsInv90:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_WbVsInv90:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_GetX1VsInv90:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_GetX2VsInv90:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX1VsInv90:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX2VsInv90:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX3VsInv90:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX4VsInv90:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_Get_GetVsInv90:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_Get_PutVsInv90:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_PutXVsInv90:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_ReplaceVsInv90:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_GetVsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_GetXVsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_PutXVsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma PI_Remote_ReplaceVsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma StoreVsInv90:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma StoreHomeVsInv90:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv90  iInv1  iInv2 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash90Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5774953651858118, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.257291241538743}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |                    May 2005               |\n            |                   June 2005  (modified)   |\n            |              September 2005  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |                October 2005  (modified)   |\n            |                  March 2007  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory CSP_T_law_rep_par\nimports CSP_T_law_alpha_par CSP_T_op_rep_par\nbegin\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite UnionT and InterT.                 *)\n(*                  Union (B ` A) = (UN x:A. B x)                      *)\n(*                  Inter (B ` A) = (INT x:A. B x)                     *)\n(*\ndeclare Union_image_eq [simp del]\ndeclare Inter_image_eq [simp del]\n*)\ndeclare Sup_image_eq [simp del]\ndeclare Inf_image_eq [simp del]\n\n(*****************************************************************\n\n         1. associativity of [||]:I\n         2. commutativity of [||]:I\n         3. \n         4. \n\n *****************************************************************)\n\n(*****************************************************\n   replace an index set with another equal index set\n *****************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_Rep_parallel_index_eq:\n   \"[| finite I1 ;\n       EX f. I2 = f ` I1 & inj_on f I1 &\n             (ALL i:I1. PXf2 (f i) = PXf1 i) |]\n    ==> [||]:I1 PXf1 =T[M,M] [||]:I2 PXf2\"\napply (simp add: cspT_semantics)\n\napply (case_tac \"I1 = {}\")\napply (simp)\napply (rule order_antisym)\n\n (* <= *)\n apply (rule)\n apply (elim conjE exE)\n apply (simp add: in_traces_par)\n apply (subgoal_tac \"Union (snd ` PXf2 ` f ` I1) = Union (snd ` PXf1 ` I1)\")\n apply (simp)\n apply (simp add: Union_index_fun)\n\n (* => *)\n apply (rule)\n apply (elim conjE exE)\n apply (simp add: in_traces_par)\n apply (subgoal_tac \"Union (snd ` PXf2 ` f ` I1) = Union (snd ` PXf1 ` I1)\")\n apply (simp)\n apply (simp add: Union_index_fun)\ndone\n\n(*********************************************************\n                [||]:I PXf ==> [||] PXs\n *********************************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_Index_to_Inductive_parallel:\n  \"[| finite I ; Is isListOf I |] ==>\n   [||]:I PXf =T[M,M] [||] (map PXf Is)\"\napply (simp add: cspT_semantics)\n\napply (case_tac \"I = {}\")\napply (simp)\n\napply (case_tac \"map PXf Is = []\")\napply (simp)\napply (rule order_antisym)\n\n (* <= *)\n apply (rule)\n apply (simp add: in_traces_Rep_parallel)\n apply (simp add: in_traces_Inductive_parallel_nth)\n apply (simp add: isListOf_set_eq)\n apply (intro allI impI)\n apply (elim conjE exE)\n apply (drule_tac x=\"Is!i\" in bspec)\n apply (simp add: isListOf_nth_in_index)\n apply (simp)\n\n (* => *)\n apply (rule)\n apply (simp add: in_traces_Rep_parallel)\n apply (simp add: in_traces_Inductive_parallel_nth)\n apply (simp add: isListOf_set_eq)\n apply (intro ballI)\n apply (elim conjE)\n apply (erule isListOf_index_to_nthE)\n apply (drule_tac x=\"i\" in bspec, simp)\n apply (elim exE conjE)\n apply (drule_tac x=\"n\" in spec, simp)\ndone\n\n(************************************\n |       [||]:I PXf and SKIP        |\n ************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_SKIP_Rep_parallel_right:\n  \"finite I ==>\n   (([||]:I PXf) |[Union (snd `  PXf ` I), {}]| SKIP) =T[M,M]\n   ([||]:I PXf)\"\napply (case_tac \"I={}\")\napply (simp add: cspT_SKIP_Alpha_parallel)\n\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_traces_par)\n\n apply (intro ballI)\n apply (elim conjE)\n apply (drule_tac x=\"i\" in bspec, simp)\n apply (subgoal_tac \"snd (PXf i) <= Union (snd ` PXf ` I)\")\n apply (simp add: rest_tr_of_rest_tr_subset)\n apply (force)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_traces_par in_traces)\n apply (simp add: rest_tr_empty)\n\n apply (intro ballI)\n apply (elim conjE)\n apply (drule_tac x=\"i\" in bspec, simp)\n apply (subgoal_tac \"snd (PXf i) <= Union (snd ` PXf ` I)\")\n apply (simp add: rest_tr_of_rest_tr_subset)\n apply (force)\ndone\n\n(************************************\n |        SKIP and [||]:I PXf       |\n ************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_SKIP_Rep_parallel_left:\n  \"finite I ==>\n   (SKIP |[{}, Union (snd ` PXf ` I)]| ([||]:I PXf)) =T[M,M]\n   ([||]:I PXf)\"\napply (subgoal_tac \n    \"(SKIP |[{}, Union (snd ` PXf ` I)]| ([||]:I PXf)) =T[M,M]\n     (([||]:I PXf) |[Union (snd ` PXf ` I), {}]| SKIP)\")\napply (rule cspT_trans)\napply (simp)\napply (simp add: cspT_SKIP_Rep_parallel_right)\napply (simp add: cspT_Alpha_parallel_commut)\ndone\n\n(*** left and right ***)\n\nlemmas cspT_SKIP_Rep_parallel = cspT_SKIP_Rep_parallel_left\n                                  cspT_SKIP_Rep_parallel_right\n\n(************************************\n |          associativity           |\n ************************************)\n\n(*------------------*\n |      csp law     |\n *------------------*)\n\nlemma cspT_Rep_parallel_assoc:\n \"[| I1 Int I2 = {} ; finite I1 ; finite I2 |] ==>\n  [||]:(I1 Un I2) PXf =T[M,M]\n  [||]:I1 PXf |[Union (snd ` PXf ` I1), Union (snd ` PXf ` I2)]| [||]:I2 PXf\"\n\napply (case_tac \"I1 = {}\")\napply (case_tac \"I2 = {}\")\napply (rule cspT_sym)\napply (simp add: cspT_SKIP_Alpha_parallel)\napply (rule cspT_sym)\napply (simp add: cspT_SKIP_Rep_parallel)\n\napply (case_tac \"I2 = {}\")\napply (rule cspT_sym)\napply (simp add: cspT_SKIP_Rep_parallel)\n\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n (* => *)\n apply (rule)\n apply (simp add: in_traces_par)\n apply (simp add: Union_snd_Un)\n apply (elim conjE)\n apply (rule conjI)\n\n  apply (intro ballI)\n  apply (drule_tac x=\"i\" in bspec, simp)\n  apply (subgoal_tac \"snd (PXf i) <= Union (snd ` PXf ` I1)\")\n  apply (simp add: rest_tr_of_rest_tr_subset)\n  apply (force)\n\n  apply (intro ballI)\n  apply (drule_tac x=\"i\" in bspec, simp)\n  apply (subgoal_tac \"snd (PXf i) <= Union (snd ` PXf ` I2)\")\n  apply (simp add: rest_tr_of_rest_tr_subset)\n  apply (force)\n\n (* <= *)\n apply (rule)\n apply (simp add: in_traces_par)\n apply (simp add: Union_snd_Un)\n apply (elim conjE)\n\n apply (intro ballI)\n apply (simp)\n apply (erule disjE)\n\n  apply (drule_tac x=\"i\" in bspec, simp)\n  apply (subgoal_tac \"snd (PXf i) <= Union (snd ` PXf ` I1)\")\n  apply (simp add: rest_tr_of_rest_tr_subset)\n  apply (force)\n\n  apply (drule_tac x=\"i\" in bspec, simp)\n  apply (subgoal_tac \"snd (PXf i) <= Union (snd ` PXf ` I2)\")\n  apply (simp add: rest_tr_of_rest_tr_subset)\n  apply (force)\ndone\n\n(************************************\n |             induct               |\n ************************************)\n\n(*------------------*\n |     csp law      |\n |   (derivable)    |\n *------------------*)\n\nlemma cspT_Rep_parallel_induct:\n \"[| finite I ; i ~: I |] ==>\n  [||]:(insert i I) PXf =T[M,M]\n  fst (PXf i) |[snd (PXf i), Union (snd ` PXf ` I)]| [||]:I PXf\"\napply (insert cspT_Rep_parallel_assoc[of \"{i}\" I PXf M])\napply (simp add: Rep_parallel_one)\napply (rule cspT_trans)\napply (simp)\n\napply (insert cspT_Alpha_parallel_assoc\n  [of \"fst (PXf i)\" \"snd (PXf i)\" \"{}\" \"SKIP\" \"Union (snd ` PXf ` I)\" \"[||]:I PXf\" M])\napply (rule cspT_trans)\napply (simp)\n\napply (rule cspT_decompo_Alpha_parallel)\napply (simp_all)\n\napply (simp add: cspT_SKIP_Rep_parallel)\ndone\n\n(****************** to add them again ******************)\n(*\ndeclare Union_image_eq [simp]\ndeclare Inter_image_eq [simp]\n*)\ndeclare Sup_image_eq [simp]\ndeclare Inf_image_eq [simp]\n\nend\n\n", "meta": {"author": "pefribeiro", "repo": "CSP-Prover", "sha": "8967cc482e5695fca4abb52d9dc2cf36b7b7a44e", "save_path": "github-repos/isabelle/pefribeiro-CSP-Prover", "path": "github-repos/isabelle/pefribeiro-CSP-Prover/CSP-Prover-8967cc482e5695fca4abb52d9dc2cf36b7b7a44e/CSP_T/CSP_T_law_rep_par.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5774953651858118, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.257291241538743}}
{"text": "(*  Title:      ZF/UNITY/SubstAx.thy\n    Author:     Sidi O Ehmety, Computer Laboratory\n    Copyright   2001  University of Cambridge\n\nTheory ported from HOL.\n*)\n\nsection\\<open>Weak LeadsTo relation (restricted to the set of reachable states)\\<close>\n\ntheory SubstAx\nimports WFair Constrains\nbegin\n\ndefinition\n  (* The definitions below are not `conventional', but yield simpler rules *)\n  Ensures :: \"[i,i] \\<Rightarrow> i\"            (infixl \\<open>Ensures\\<close> 60)  where\n  \"A Ensures B \\<equiv> {F \\<in> program. F \\<in> (reachable(F) \\<inter> A) ensures (reachable(F) \\<inter> B) }\"\n\ndefinition\n  LeadsTo :: \"[i, i] \\<Rightarrow> i\"            (infixl \\<open>\\<longmapsto>w\\<close> 60)  where\n  \"A \\<longmapsto>w B \\<equiv> {F \\<in> program. F:(reachable(F) \\<inter> A) \\<longmapsto> (reachable(F) \\<inter> B)}\"\n\n\n(*Resembles the previous definition of LeadsTo*)\n\n(* Equivalence with the HOL-like definition *)\nlemma LeadsTo_eq:\n\"st_set(B)\\<Longrightarrow> A \\<longmapsto>w B = {F \\<in> program. F:(reachable(F) \\<inter> A) \\<longmapsto> B}\"\n  unfolding LeadsTo_def\napply (blast dest: psp_stable2 leadsToD2 constrainsD2 intro: leadsTo_weaken)\ndone\n\nlemma LeadsTo_type: \"A \\<longmapsto>w B <=program\"\nby (unfold LeadsTo_def, auto)\n\n(*** Specialized laws for handling invariants ***)\n\n(** Conjoining an Always property **)\nlemma Always_LeadsTo_pre: \"F \\<in> Always(I) \\<Longrightarrow> (F:(I \\<inter> A) \\<longmapsto>w A') \\<longleftrightarrow> (F \\<in> A \\<longmapsto>w A')\"\nby (simp add: LeadsTo_def Always_eq_includes_reachable Int_absorb2 Int_assoc [symmetric] leadsToD2)\n\nlemma Always_LeadsTo_post: \"F \\<in> Always(I) \\<Longrightarrow> (F \\<in> A \\<longmapsto>w (I \\<inter> A')) \\<longleftrightarrow> (F \\<in> A \\<longmapsto>w A')\"\n  unfolding LeadsTo_def\napply (simp add: Always_eq_includes_reachable Int_absorb2 Int_assoc [symmetric] leadsToD2)\ndone\n\n(* Like 'Always_LeadsTo_pre RS iffD1', but with premises in the good order *)\nlemma Always_LeadsToI: \"\\<lbrakk>F \\<in> Always(C); F \\<in> (C \\<inter> A) \\<longmapsto>w A'\\<rbrakk> \\<Longrightarrow> F \\<in> A \\<longmapsto>w A'\"\nby (blast intro: Always_LeadsTo_pre [THEN iffD1])\n\n(* Like 'Always_LeadsTo_post RS iffD2', but with premises in the good order *)\nlemma Always_LeadsToD: \"\\<lbrakk>F \\<in> Always(C);  F \\<in> A \\<longmapsto>w A'\\<rbrakk> \\<Longrightarrow> F \\<in> A \\<longmapsto>w (C \\<inter> A')\"\nby (blast intro: Always_LeadsTo_post [THEN iffD2])\n\n(*** Introduction rules \\<in> Basis, Trans, Union ***)\n\nlemma LeadsTo_Basis: \"F \\<in> A Ensures B \\<Longrightarrow> F \\<in> A \\<longmapsto>w B\"\nby (auto simp add: Ensures_def LeadsTo_def)\n\nlemma LeadsTo_Trans:\n     \"\\<lbrakk>F \\<in> A \\<longmapsto>w B;  F \\<in> B \\<longmapsto>w C\\<rbrakk> \\<Longrightarrow> F \\<in> A \\<longmapsto>w C\"\napply (simp (no_asm_use) add: LeadsTo_def)\napply (blast intro: leadsTo_Trans)\ndone\n\nlemma LeadsTo_Union:\n\"\\<lbrakk>(\\<And>A. A \\<in> S \\<Longrightarrow> F \\<in> A \\<longmapsto>w B); F \\<in> program\\<rbrakk>\\<Longrightarrow>F \\<in> \\<Union>(S) \\<longmapsto>w B\"\napply (simp add: LeadsTo_def)\napply (subst Int_Union_Union2)\napply (rule leadsTo_UN, auto)\ndone\n\n(*** Derived rules ***)\n\nlemma leadsTo_imp_LeadsTo: \"F \\<in> A \\<longmapsto> B \\<Longrightarrow> F \\<in> A \\<longmapsto>w B\"\napply (frule leadsToD2, clarify)\napply (simp (no_asm_simp) add: LeadsTo_eq)\napply (blast intro: leadsTo_weaken_L)\ndone\n\n(*Useful with cancellation, disjunction*)\nlemma LeadsTo_Un_duplicate: \"F \\<in> A \\<longmapsto>w (A' \\<union> A') \\<Longrightarrow> F \\<in> A \\<longmapsto>w A'\"\nby (simp add: Un_ac)\n\nlemma LeadsTo_Un_duplicate2:\n     \"F \\<in> A \\<longmapsto>w (A' \\<union> C \\<union> C) \\<Longrightarrow> F \\<in> A \\<longmapsto>w (A' \\<union> C)\"\nby (simp add: Un_ac)\n\nlemma LeadsTo_UN:\n    \"\\<lbrakk>(\\<And>i. i \\<in> I \\<Longrightarrow> F \\<in> A(i) \\<longmapsto>w B); F \\<in> program\\<rbrakk>\n     \\<Longrightarrow>F:(\\<Union>i \\<in> I. A(i)) \\<longmapsto>w B\"\napply (simp add: LeadsTo_def)\napply (simp (no_asm_simp) del: UN_simps add: Int_UN_distrib)\napply (rule leadsTo_UN, auto)\ndone\n\n(*Binary union introduction rule*)\nlemma LeadsTo_Un:\n     \"\\<lbrakk>F \\<in> A \\<longmapsto>w C; F \\<in> B \\<longmapsto>w C\\<rbrakk> \\<Longrightarrow> F \\<in> (A \\<union> B) \\<longmapsto>w C\"\napply (subst Un_eq_Union)\napply (rule LeadsTo_Union)\napply (auto dest: LeadsTo_type [THEN subsetD])\ndone\n\n(*Lets us look at the starting state*)\nlemma single_LeadsTo_I:\n    \"\\<lbrakk>(\\<And>s. s \\<in> A \\<Longrightarrow> F:{s} \\<longmapsto>w B); F \\<in> program\\<rbrakk>\\<Longrightarrow>F \\<in> A \\<longmapsto>w B\"\napply (subst UN_singleton [symmetric], rule LeadsTo_UN, auto)\ndone\n\nlemma subset_imp_LeadsTo: \"\\<lbrakk>A \\<subseteq> B; F \\<in> program\\<rbrakk> \\<Longrightarrow> F \\<in> A \\<longmapsto>w B\"\napply (simp (no_asm_simp) add: LeadsTo_def)\napply (blast intro: subset_imp_leadsTo)\ndone\n\nlemma empty_LeadsTo: \"F \\<in> 0 \\<longmapsto>w A \\<longleftrightarrow> F \\<in> program\"\nby (auto dest: LeadsTo_type [THEN subsetD]\n            intro: empty_subsetI [THEN subset_imp_LeadsTo])\ndeclare empty_LeadsTo [iff]\n\nlemma LeadsTo_state: \"F \\<in> A \\<longmapsto>w state \\<longleftrightarrow> F \\<in> program\"\nby (auto dest: LeadsTo_type [THEN subsetD] simp add: LeadsTo_eq)\ndeclare LeadsTo_state [iff]\n\nlemma LeadsTo_weaken_R: \"\\<lbrakk>F \\<in> A \\<longmapsto>w A';  A'<=B'\\<rbrakk> \\<Longrightarrow> F \\<in> A \\<longmapsto>w B'\"\n  unfolding LeadsTo_def\napply (auto intro: leadsTo_weaken_R)\ndone\n\nlemma LeadsTo_weaken_L: \"\\<lbrakk>F \\<in> A \\<longmapsto>w A'; B \\<subseteq> A\\<rbrakk> \\<Longrightarrow> F \\<in> B \\<longmapsto>w A'\"\n  unfolding LeadsTo_def\napply (auto intro: leadsTo_weaken_L)\ndone\n\nlemma LeadsTo_weaken: \"\\<lbrakk>F \\<in> A \\<longmapsto>w A'; B<=A; A'<=B'\\<rbrakk> \\<Longrightarrow> F \\<in> B \\<longmapsto>w B'\"\nby (blast intro: LeadsTo_weaken_R LeadsTo_weaken_L LeadsTo_Trans)\n\nlemma Always_LeadsTo_weaken:\n\"\\<lbrakk>F \\<in> Always(C);  F \\<in> A \\<longmapsto>w A'; C \\<inter> B \\<subseteq> A;   C \\<inter> A' \\<subseteq> B'\\<rbrakk>\n      \\<Longrightarrow> F \\<in> B \\<longmapsto>w B'\"\napply (blast dest: Always_LeadsToI intro: LeadsTo_weaken Always_LeadsToD)\ndone\n\n(** Two theorems for \"proof lattices\" **)\n\nlemma LeadsTo_Un_post: \"F \\<in> A \\<longmapsto>w B \\<Longrightarrow> F:(A \\<union> B) \\<longmapsto>w B\"\nby (blast dest: LeadsTo_type [THEN subsetD]\n             intro: LeadsTo_Un subset_imp_LeadsTo)\n\nlemma LeadsTo_Trans_Un: \"\\<lbrakk>F \\<in> A \\<longmapsto>w B;  F \\<in> B \\<longmapsto>w C\\<rbrakk>\n      \\<Longrightarrow> F \\<in> (A \\<union> B) \\<longmapsto>w C\"\napply (blast intro: LeadsTo_Un subset_imp_LeadsTo LeadsTo_weaken_L LeadsTo_Trans dest: LeadsTo_type [THEN subsetD])\ndone\n\n(** Distributive laws **)\nlemma LeadsTo_Un_distrib: \"(F \\<in> (A \\<union> B) \\<longmapsto>w C)  \\<longleftrightarrow> (F \\<in> A \\<longmapsto>w C \\<and> F \\<in> B \\<longmapsto>w C)\"\nby (blast intro: LeadsTo_Un LeadsTo_weaken_L)\n\nlemma LeadsTo_UN_distrib: \"(F \\<in> (\\<Union>i \\<in> I. A(i)) \\<longmapsto>w B) \\<longleftrightarrow>  (\\<forall>i \\<in> I. F \\<in> A(i) \\<longmapsto>w B) \\<and> F \\<in> program\"\nby (blast dest: LeadsTo_type [THEN subsetD]\n             intro: LeadsTo_UN LeadsTo_weaken_L)\n\nlemma LeadsTo_Union_distrib: \"(F \\<in> \\<Union>(S) \\<longmapsto>w B)  \\<longleftrightarrow>  (\\<forall>A \\<in> S. F \\<in> A \\<longmapsto>w B) \\<and> F \\<in> program\"\nby (blast dest: LeadsTo_type [THEN subsetD]\n             intro: LeadsTo_Union LeadsTo_weaken_L)\n\n(** More rules using the premise \"Always(I)\" **)\n\nlemma EnsuresI: \"\\<lbrakk>F:(A-B) Co (A \\<union> B);  F \\<in> transient (A-B)\\<rbrakk> \\<Longrightarrow> F \\<in> A Ensures B\"\napply (simp add: Ensures_def Constrains_eq_constrains)\napply (blast intro: ensuresI constrains_weaken transient_strengthen dest: constrainsD2)\ndone\n\nlemma Always_LeadsTo_Basis: \"\\<lbrakk>F \\<in> Always(I); F \\<in> (I \\<inter> (A-A')) Co (A \\<union> A');\n         F \\<in> transient (I \\<inter> (A-A'))\\<rbrakk>\n  \\<Longrightarrow> F \\<in> A \\<longmapsto>w A'\"\napply (rule Always_LeadsToI, assumption)\napply (blast intro: EnsuresI LeadsTo_Basis Always_ConstrainsD [THEN Constrains_weaken] transient_strengthen)\ndone\n\n(*Set difference: maybe combine with leadsTo_weaken_L??\n  This is the most useful form of the \"disjunction\" rule*)\nlemma LeadsTo_Diff:\n     \"\\<lbrakk>F \\<in> (A-B) \\<longmapsto>w C;  F \\<in> (A \\<inter> B) \\<longmapsto>w C\\<rbrakk> \\<Longrightarrow> F \\<in> A \\<longmapsto>w C\"\nby (blast intro: LeadsTo_Un LeadsTo_weaken)\n\nlemma LeadsTo_UN_UN:\n     \"\\<lbrakk>(\\<And>i. i \\<in> I \\<Longrightarrow> F \\<in> A(i) \\<longmapsto>w A'(i)); F \\<in> program\\<rbrakk>\n      \\<Longrightarrow> F \\<in> (\\<Union>i \\<in> I. A(i)) \\<longmapsto>w (\\<Union>i \\<in> I. A'(i))\"\napply (rule LeadsTo_Union, auto)\napply (blast intro: LeadsTo_weaken_R)\ndone\n\n(*Binary union version*)\nlemma LeadsTo_Un_Un:\n  \"\\<lbrakk>F \\<in> A \\<longmapsto>w A'; F \\<in> B \\<longmapsto>w B'\\<rbrakk> \\<Longrightarrow> F:(A \\<union> B) \\<longmapsto>w (A' \\<union> B')\"\nby (blast intro: LeadsTo_Un LeadsTo_weaken_R)\n\n(** The cancellation law **)\n\nlemma LeadsTo_cancel2: \"\\<lbrakk>F \\<in> A \\<longmapsto>w(A' \\<union> B); F \\<in> B \\<longmapsto>w B'\\<rbrakk> \\<Longrightarrow> F \\<in> A \\<longmapsto>w (A' \\<union> B')\"\nby (blast intro: LeadsTo_Un_Un subset_imp_LeadsTo LeadsTo_Trans dest: LeadsTo_type [THEN subsetD])\n\nlemma Un_Diff: \"A \\<union> (B - A) = A \\<union> B\"\nby auto\n\nlemma LeadsTo_cancel_Diff2: \"\\<lbrakk>F \\<in> A \\<longmapsto>w (A' \\<union> B); F \\<in> (B-A') \\<longmapsto>w B'\\<rbrakk> \\<Longrightarrow> F \\<in> A \\<longmapsto>w (A' \\<union> B')\"\napply (rule LeadsTo_cancel2)\nprefer 2 apply assumption\napply (simp (no_asm_simp) add: Un_Diff)\ndone\n\nlemma LeadsTo_cancel1: \"\\<lbrakk>F \\<in> A \\<longmapsto>w (B \\<union> A'); F \\<in> B \\<longmapsto>w B'\\<rbrakk> \\<Longrightarrow> F \\<in> A \\<longmapsto>w (B' \\<union> A')\"\napply (simp add: Un_commute)\napply (blast intro!: LeadsTo_cancel2)\ndone\n\nlemma Diff_Un2: \"(B - A) \\<union> A = B \\<union> A\"\nby auto\n\nlemma LeadsTo_cancel_Diff1: \"\\<lbrakk>F \\<in> A \\<longmapsto>w (B \\<union> A'); F \\<in> (B-A') \\<longmapsto>w B'\\<rbrakk> \\<Longrightarrow> F \\<in> A \\<longmapsto>w (B' \\<union> A')\"\napply (rule LeadsTo_cancel1)\nprefer 2 apply assumption\napply (simp (no_asm_simp) add: Diff_Un2)\ndone\n\n(** The impossibility law **)\n\n(*The set \"A\" may be non-empty, but it contains no reachable states*)\nlemma LeadsTo_empty: \"F \\<in> A \\<longmapsto>w 0 \\<Longrightarrow> F \\<in> Always (state -A)\"\napply (simp (no_asm_use) add: LeadsTo_def Always_eq_includes_reachable)\napply (cut_tac reachable_type)\napply (auto dest!: leadsTo_empty)\ndone\n\n(** PSP \\<in> Progress-Safety-Progress **)\n\n(*Special case of PSP \\<in> Misra's \"stable conjunction\"*)\nlemma PSP_Stable: \"\\<lbrakk>F \\<in> A \\<longmapsto>w A';  F \\<in> Stable(B)\\<rbrakk>\\<Longrightarrow> F:(A \\<inter> B) \\<longmapsto>w (A' \\<inter> B)\"\napply (simp add: LeadsTo_def Stable_eq_stable, clarify)\napply (drule psp_stable, assumption)\napply (simp add: Int_ac)\ndone\n\nlemma PSP_Stable2: \"\\<lbrakk>F \\<in> A \\<longmapsto>w A'; F \\<in> Stable(B)\\<rbrakk> \\<Longrightarrow> F \\<in> (B \\<inter> A) \\<longmapsto>w (B \\<inter> A')\"\napply (simp (no_asm_simp) add: PSP_Stable Int_ac)\ndone\n\nlemma PSP: \"\\<lbrakk>F \\<in> A \\<longmapsto>w A'; F \\<in> B Co B'\\<rbrakk>\\<Longrightarrow> F \\<in> (A \\<inter> B') \\<longmapsto>w ((A' \\<inter> B) \\<union> (B' - B))\"\napply (simp (no_asm_use) add: LeadsTo_def Constrains_eq_constrains)\napply (blast dest: psp intro: leadsTo_weaken)\ndone\n\nlemma PSP2: \"\\<lbrakk>F \\<in> A \\<longmapsto>w A'; F \\<in> B Co B'\\<rbrakk>\\<Longrightarrow> F:(B' \\<inter> A) \\<longmapsto>w ((B \\<inter> A') \\<union> (B' - B))\"\nby (simp (no_asm_simp) add: PSP Int_ac)\n\nlemma PSP_Unless:\n\"\\<lbrakk>F \\<in> A \\<longmapsto>w A'; F \\<in> B Unless B'\\<rbrakk>\\<Longrightarrow> F:(A \\<inter> B) \\<longmapsto>w ((A' \\<inter> B) \\<union> B')\"\n  unfolding op_Unless_def\napply (drule PSP, assumption)\napply (blast intro: LeadsTo_Diff LeadsTo_weaken subset_imp_LeadsTo)\ndone\n\n(*** Induction rules ***)\n\n(** Meta or object quantifier ????? **)\nlemma LeadsTo_wf_induct: \"\\<lbrakk>wf(r);\n         \\<forall>m \\<in> I. F \\<in> (A \\<inter> f-``{m}) \\<longmapsto>w\n                            ((A \\<inter> f-``(converse(r) `` {m})) \\<union> B);\n         field(r)<=I; A<=f-``I; F \\<in> program\\<rbrakk>\n      \\<Longrightarrow> F \\<in> A \\<longmapsto>w B\"\napply (simp (no_asm_use) add: LeadsTo_def)\napply auto\napply (erule_tac I = I and f = f in leadsTo_wf_induct, safe)\napply (drule_tac [2] x = m in bspec, safe)\napply (rule_tac [2] A' = \"reachable (F) \\<inter> (A \\<inter> f -`` (converse (r) ``{m}) \\<union> B) \" in leadsTo_weaken_R)\napply (auto simp add: Int_assoc)\ndone\n\n\nlemma LessThan_induct: \"\\<lbrakk>\\<forall>m \\<in> nat. F:(A \\<inter> f-``{m}) \\<longmapsto>w ((A \\<inter> f-``m) \\<union> B);\n      A<=f-``nat; F \\<in> program\\<rbrakk> \\<Longrightarrow> F \\<in> A \\<longmapsto>w B\"\napply (rule_tac A1 = nat and f1 = \"\\<lambda>x. x\" in wf_measure [THEN LeadsTo_wf_induct])\napply (simp_all add: nat_measure_field)\napply (simp add: ltI Image_inverse_lessThan vimage_def [symmetric])\ndone\n\n\n(******\n To be ported ??? I am not sure.\n\n  integ_0_le_induct\n  LessThan_bounded_induct\n  GreaterThan_bounded_induct\n\n*****)\n\n(*** Completion \\<in> Binary and General Finite versions ***)\n\nlemma Completion: \"\\<lbrakk>F \\<in> A \\<longmapsto>w (A' \\<union> C);  F \\<in> A' Co (A' \\<union> C);\n         F \\<in> B \\<longmapsto>w (B' \\<union> C);  F \\<in> B' Co (B' \\<union> C)\\<rbrakk>\n      \\<Longrightarrow> F \\<in> (A \\<inter> B) \\<longmapsto>w ((A' \\<inter> B') \\<union> C)\"\napply (simp (no_asm_use) add: LeadsTo_def Constrains_eq_constrains Int_Un_distrib)\napply (blast intro: completion leadsTo_weaken)\ndone\n\nlemma Finite_completion_aux:\n     \"\\<lbrakk>I \\<in> Fin(X);F \\<in> program\\<rbrakk>\n      \\<Longrightarrow> (\\<forall>i \\<in> I. F \\<in> (A(i)) \\<longmapsto>w (A'(i) \\<union> C)) \\<longrightarrow>\n          (\\<forall>i \\<in> I. F \\<in> (A'(i)) Co (A'(i) \\<union> C)) \\<longrightarrow>\n          F \\<in> (\\<Inter>i \\<in> I. A(i)) \\<longmapsto>w ((\\<Inter>i \\<in> I. A'(i)) \\<union> C)\"\napply (erule Fin_induct)\napply (auto simp del: INT_simps simp add: Inter_0)\napply (rule Completion, auto)\napply (simp del: INT_simps add: INT_extend_simps)\napply (blast intro: Constrains_INT)\ndone\n\nlemma Finite_completion:\n     \"\\<lbrakk>I \\<in> Fin(X); \\<And>i. i \\<in> I \\<Longrightarrow> F \\<in> A(i) \\<longmapsto>w (A'(i) \\<union> C);\n         \\<And>i. i \\<in> I \\<Longrightarrow> F \\<in> A'(i) Co (A'(i) \\<union> C);\n         F \\<in> program\\<rbrakk>\n      \\<Longrightarrow> F \\<in> (\\<Inter>i \\<in> I. A(i)) \\<longmapsto>w ((\\<Inter>i \\<in> I. A'(i)) \\<union> C)\"\nby (blast intro: Finite_completion_aux [THEN mp, THEN mp])\n\nlemma Stable_completion:\n     \"\\<lbrakk>F \\<in> A \\<longmapsto>w A';  F \\<in> Stable(A');\n         F \\<in> B \\<longmapsto>w B';  F \\<in> Stable(B')\\<rbrakk>\n    \\<Longrightarrow> F \\<in> (A \\<inter> B) \\<longmapsto>w (A' \\<inter> B')\"\n  unfolding Stable_def\napply (rule_tac C1 = 0 in Completion [THEN LeadsTo_weaken_R])\n    prefer 5\n    apply blast\napply auto\ndone\n\nlemma Finite_stable_completion:\n     \"\\<lbrakk>I \\<in> Fin(X);\n         (\\<And>i. i \\<in> I \\<Longrightarrow> F \\<in> A(i) \\<longmapsto>w A'(i));\n         (\\<And>i. i \\<in> I \\<Longrightarrow>F \\<in> Stable(A'(i)));   F \\<in> program\\<rbrakk>\n      \\<Longrightarrow> F \\<in> (\\<Inter>i \\<in> I. A(i)) \\<longmapsto>w (\\<Inter>i \\<in> I. A'(i))\"\n  unfolding Stable_def\napply (rule_tac C1 = 0 in Finite_completion [THEN LeadsTo_weaken_R], simp_all)\napply (rule_tac [3] subset_refl, auto)\ndone\n\nML \\<open>\n(*proves \"ensures/leadsTo\" properties when the program is specified*)\nfun ensures_tac ctxt sact =\n  SELECT_GOAL\n    (EVERY [REPEAT (Always_Int_tac ctxt 1),\n            eresolve_tac ctxt @{thms Always_LeadsTo_Basis} 1\n                ORELSE   (*subgoal may involve LeadsTo, leadsTo or ensures*)\n                REPEAT (ares_tac ctxt [@{thm LeadsTo_Basis}, @{thm leadsTo_Basis},\n                                  @{thm EnsuresI}, @{thm ensuresI}] 1),\n            (*now there are two subgoals: co \\<and> transient*)\n            simp_tac (ctxt addsimps (Named_Theorems.get ctxt \\<^named_theorems>\\<open>program\\<close>)) 2,\n            Rule_Insts.res_inst_tac ctxt\n              [(((\"act\", 0), Position.none), sact)] [] @{thm transientI} 2,\n               (*simplify the command's domain*)\n            simp_tac (ctxt addsimps [@{thm domain_def}]) 3,\n            (* proving the domain part *)\n           clarify_tac ctxt 3,\n           dresolve_tac ctxt @{thms swap} 3, force_tac ctxt 4,\n           resolve_tac ctxt @{thms ReplaceI} 3, force_tac ctxt 3, force_tac ctxt 4,\n           asm_full_simp_tac ctxt 3, resolve_tac ctxt @{thms conjI} 3, simp_tac ctxt 4,\n           REPEAT (resolve_tac ctxt @{thms state_update_type} 3),\n           constrains_tac ctxt 1,\n           ALLGOALS (clarify_tac ctxt),\n           ALLGOALS (asm_full_simp_tac (ctxt addsimps [@{thm st_set_def}])),\n                      ALLGOALS (clarify_tac ctxt),\n          ALLGOALS (asm_lr_simp_tac ctxt)]);\n\\<close>\n\nmethod_setup ensures = \\<open>\n    Args.goal_spec -- Scan.lift Parse.embedded_inner_syntax >>\n    (fn (quant, s) => fn ctxt => SIMPLE_METHOD'' quant (ensures_tac ctxt s))\n\\<close> \"for proving progress properties\"\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/ZF/UNITY/SubstAx.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953651858117, "lm_q2_score": 0.44552953503957266, "lm_q1q2_score": 0.2572912415387429}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\n(* License: BSD, terms see file ./LICENSE *)\n\ntheory SepFrame\nimports SepTactic\nbegin\n\nclass heap_state_type'\n\ninstance heap_state_type' \\<subseteq> type ..\n\nconsts\n  hst_mem :: \"'a::heap_state_type' \\<Rightarrow> heap_mem\"\n  hst_mem_update :: \"(heap_mem \\<Rightarrow> heap_mem) \\<Rightarrow> 'a::heap_state_type' \\<Rightarrow> 'a\"\n  hst_htd :: \"'a::heap_state_type' \\<Rightarrow> heap_typ_desc\"\n  hst_htd_update :: \"(heap_typ_desc \\<Rightarrow> heap_typ_desc) \\<Rightarrow> 'a::heap_state_type' \\<Rightarrow> 'a\"\n\nclass heap_state_type = heap_state_type' +\n  assumes hst_htd_htd_update [simp]: \"hst_htd (hst_htd_update d s) = d (hst_htd s)\"\n  assumes hst_mem_mem_update [simp]: \"hst_mem (hst_mem_update h s) = h (hst_mem s)\"\n  assumes hst_htd_mem_update [simp]: \"hst_htd (hst_mem_update h s) = hst_htd s\"\n  assumes hst_mem_htd_update [simp]: \"hst_mem (hst_htd_update d s) = hst_mem s\"\n\ntranslations\n  \"s\\<lparr> hst_mem := x\\<rparr>\" <= \"CONST hst_mem_update (K_record x) s\"\n  \"s\\<lparr> hst_htd := x\\<rparr>\" <= \"CONST hst_htd_update (K_record x) s\"\n\ndefinition lift_hst :: \"'a::heap_state_type' \\<Rightarrow> heap_state\" where\n  \"lift_hst s \\<equiv> lift_state (hst_mem s,hst_htd s)\"\n\ndefinition point_eq_mod :: \"('a \\<Rightarrow> 'b) \\<Rightarrow> ('a \\<Rightarrow> 'b) \\<Rightarrow> 'a set \\<Rightarrow> bool\" where\n  \"point_eq_mod f g X \\<equiv> \\<forall>x. x \\<notin> X \\<longrightarrow> f x = g x\"\n\ndefinition exec_fatal :: \"('s,'b,'c) com \\<Rightarrow> ('s,'b,'c) body \\<Rightarrow> 's \\<Rightarrow> bool\" where\n  \"exec_fatal C \\<Gamma> s \\<equiv> (\\<exists>f. \\<Gamma> \\<turnstile> \\<langle>C,Normal s\\<rangle> \\<Rightarrow> Fault f) \\<or> (\\<Gamma> \\<turnstile> \\<langle>C,Normal s\\<rangle> \\<Rightarrow> Stuck)\"\n\ndefinition restrict_htd :: \"'s::heap_state_type' \\<Rightarrow> s_addr set \\<Rightarrow> 's\" where\n  \"restrict_htd s X \\<equiv> s\\<lparr> hst_htd := restrict_s (hst_htd s) X \\<rparr>\"\n\ndefinition restrict_safe_OK ::\n  \"'s \\<Rightarrow> 's \\<Rightarrow> ('s \\<Rightarrow> ('s,'c) xstate) \\<Rightarrow> s_addr set \\<Rightarrow> ('s::heap_state_type','b,'c) com \\<Rightarrow>\n     ('s,'b,'c) body \\<Rightarrow> bool\" where\n  \"restrict_safe_OK s t f X C \\<Gamma> \\<equiv>\n      \\<Gamma> \\<turnstile> \\<langle>C,(Normal (restrict_htd s X))\\<rangle> \\<Rightarrow> f (restrict_htd t X) \\<and>\n      point_eq_mod (lift_state (hst_mem t,hst_htd t)) (lift_state (hst_mem s,hst_htd s)) X\"\n\ndefinition restrict_safe ::\n  \"'s \\<Rightarrow> ('s,'c) xstate \\<Rightarrow> ('s::heap_state_type','b,'c) com \\<Rightarrow> ('s,'b,'c) body \\<Rightarrow> bool\" where\n  \"restrict_safe s t C \\<Gamma> \\<equiv>\n     \\<forall>X. (case t of\n            Normal t' \\<Rightarrow> restrict_safe_OK s t' Normal X C \\<Gamma>\n          | Abrupt t' \\<Rightarrow> restrict_safe_OK s t' Abrupt X C \\<Gamma>\n          | _ \\<Rightarrow> False) \\<or>\n         exec_fatal C \\<Gamma> (restrict_htd s X)\"\n\ndefinition mem_safe :: \"('s::{heap_state_type',type},'b,'c) com \\<Rightarrow> ('s,'b,'c) body \\<Rightarrow> bool\" where\n  \"mem_safe C \\<Gamma> \\<equiv> \\<forall>s t. \\<Gamma> \\<turnstile> \\<langle>C,Normal s\\<rangle> \\<Rightarrow> t \\<longrightarrow> restrict_safe s t C \\<Gamma>\"\n\ndefinition point_eq_mod_safe ::\n  \"'s::{heap_state_type',type} set \\<Rightarrow> ('s \\<Rightarrow> 's) \\<Rightarrow> ('s \\<Rightarrow> s_addr \\<Rightarrow> 'c) \\<Rightarrow> bool\" where\n  \"point_eq_mod_safe P f g \\<equiv> \\<forall>s X. restrict_htd s X \\<in> P \\<longrightarrow> point_eq_mod (g (f s)) (g s) X\"\n\ndefinition comm_restrict :: \"('s::{heap_state_type',type} \\<Rightarrow> 's) \\<Rightarrow> 's \\<Rightarrow> s_addr set \\<Rightarrow> bool\" where\n  \"comm_restrict f s X \\<equiv> f (restrict_htd s X) = restrict_htd (f s) X\"\n\ndefinition comm_restrict_safe :: \"'s set \\<Rightarrow> ('s::{heap_state_type',type} \\<Rightarrow> 's) \\<Rightarrow> bool\" where\n  \"comm_restrict_safe P f \\<equiv> \\<forall>s X. restrict_htd s X \\<in> P \\<longrightarrow> comm_restrict f s X\"\n\ndefinition htd_ind :: \"('a::{heap_state_type',type} \\<Rightarrow> 'b) \\<Rightarrow> bool\" where\n  \"htd_ind f \\<equiv> \\<forall>x s. f s = f (hst_htd_update x s)\"\n\ndefinition mono_guard :: \"'s::{heap_state_type',type} set \\<Rightarrow> bool\" where\n  \"mono_guard P \\<equiv> \\<forall>s X. restrict_htd s X \\<in> P \\<longrightarrow> s \\<in> P\"\n\ndefinition expr_htd_ind :: \"'s::{heap_state_type',type} set \\<Rightarrow> bool\" where\n  \"expr_htd_ind P \\<equiv> \\<forall>d s. s\\<lparr> hst_htd := d \\<rparr> \\<in> P = (s \\<in> P)\"\n\nprimrec intra_safe :: \"('s::heap_state_type','b,'c) com \\<Rightarrow>  bool\"\nwhere\n  \"intra_safe Skip = True\"\n| \"intra_safe (Basic f) = (comm_restrict_safe UNIV f \\<and>\n      point_eq_mod_safe UNIV f (\\<lambda>s. lift_state (hst_mem s,hst_htd s)))\"\n| \"intra_safe (Spec r) = (\\<forall>\\<Gamma>. mem_safe (Spec r) (\\<Gamma> :: ('s,'b,'c) body))\"\n| \"intra_safe (Seq C D) = (intra_safe C \\<and> intra_safe D)\"\n| \"intra_safe (Cond P C D) = (expr_htd_ind P \\<and> intra_safe C \\<and> intra_safe D)\"\n| \"intra_safe (While P C) = (expr_htd_ind P \\<and> intra_safe C)\"\n| \"intra_safe (Call p) = True\"\n| \"intra_safe (DynCom f) = (htd_ind f \\<and> (\\<forall>s. intra_safe (f s)))\"\n| \"intra_safe (Guard f P C) = (mono_guard P \\<and> (case C of\n      Basic g \\<Rightarrow> comm_restrict_safe P g \\<and>\n                 point_eq_mod_safe P g (\\<lambda>s. lift_state (hst_mem s,hst_htd s))\n      | _ \\<Rightarrow> intra_safe C))\"\n| \"intra_safe Throw = True\"\n| \"intra_safe (Catch C D) = (intra_safe C \\<and> intra_safe D)\"\n\ninstance state_ext :: (heap_state_type',type) heap_state_type' ..\n\noverloading\n  hs_mem_state \\<equiv> hst_mem\n  hs_mem_update_state \\<equiv> hst_mem_update\n  hs_htd_state \\<equiv> hst_htd\n  hs_htd_update_state \\<equiv> hst_htd_update\nbegin\n  definition hs_mem_state [simp]: \"hs_mem_state \\<equiv> hst_mem \\<circ> globals\"\n  definition hs_mem_update_state [simp]: \"hs_mem_update_state \\<equiv> globals_update \\<circ> hst_mem_update\"\n  definition hs_htd_state[simp]: \"hs_htd_state \\<equiv> hst_htd \\<circ> globals\"\n  definition hs_htd_update_state [simp]: \"hs_htd_update_state \\<equiv> globals_update \\<circ> hst_htd_update\"\nend\n\ninstance state_ext :: (heap_state_type,type) heap_state_type\n  by intro_classes auto\n\nprimrec\n  intra_deps :: \"('s','b,'c) com \\<Rightarrow> 'b set\"\nwhere\n  \"intra_deps Skip = {}\"\n| \"intra_deps (Basic f) = {}\"\n| \"intra_deps (Spec r) = {}\"\n| \"intra_deps (Seq C D) = (intra_deps C \\<union> intra_deps D)\"\n| \"intra_deps (Cond P C D) = (intra_deps C \\<union> intra_deps D)\"\n| \"intra_deps (While P C) = intra_deps C\"\n| \"intra_deps (Call p) = {p}\"\n| \"intra_deps (DynCom f) = \\<Union>{intra_deps (f s) | s. True}\"\n| \"intra_deps (Guard f P C) = intra_deps C\"\n| \"intra_deps Throw = {}\"\n| \"intra_deps (Catch C D) = (intra_deps C \\<union> intra_deps D)\"\n\n\ninductive_set\n  proc_deps :: \"('s','b,'c) com \\<Rightarrow> ('s,'b,'c) body \\<Rightarrow> 'b set\"\n  for \"C\" :: \"('s','b,'c) com\"\n  and \"\\<Gamma>\" :: \"('s,'b,'c) body\"\nwhere\n  \"x \\<in> intra_deps C \\<Longrightarrow> x \\<in> proc_deps C \\<Gamma>\"\n| \"\\<lbrakk> x \\<in> proc_deps C \\<Gamma>; \\<Gamma> x = Some D; y \\<in> intra_deps D \\<rbrakk> \\<Longrightarrow> y \\<in> proc_deps C \\<Gamma>\"\n\ntext \\<open>----\\<close>\n\nlemma point_eq_mod_refl [simp]:\n  \"point_eq_mod f f X\"\n  by (simp add: point_eq_mod_def)\n\nlemma point_eq_mod_subs:\n  \"\\<lbrakk> point_eq_mod f g Y; Y \\<subseteq> X \\<rbrakk> \\<Longrightarrow> point_eq_mod f g X\"\n  by (force simp: point_eq_mod_def)\n\nlemma point_eq_mod_trans:\n  \"\\<lbrakk> point_eq_mod x y X; point_eq_mod y z X \\<rbrakk> \\<Longrightarrow> point_eq_mod x z X\"\n  by (force simp: point_eq_mod_def)\n\nlemma mem_safe_NormalD:\n  \"\\<lbrakk> \\<Gamma> \\<turnstile> \\<langle>C,Normal s\\<rangle> \\<Rightarrow> Normal t; mem_safe C \\<Gamma>;\n      \\<not> exec_fatal C \\<Gamma> (restrict_htd s X) \\<rbrakk> \\<Longrightarrow>\n      (\\<Gamma> \\<turnstile> \\<langle>C,(Normal (restrict_htd s X))\\<rangle> \\<Rightarrow> Normal (restrict_htd t X) \\<and>\n       point_eq_mod (lift_state (hst_mem t,hst_htd t))\n          (lift_state (hst_mem s,hst_htd s)) X)\"\n  by (force simp: mem_safe_def restrict_safe_def restrict_safe_OK_def)\n\nlemma mem_safe_AbruptD:\n  \"\\<lbrakk> \\<Gamma> \\<turnstile> \\<langle>C,Normal s\\<rangle> \\<Rightarrow> Abrupt t; mem_safe C \\<Gamma>;\n      \\<not> exec_fatal C \\<Gamma> (restrict_htd s X) \\<rbrakk> \\<Longrightarrow>\n      (\\<Gamma> \\<turnstile> \\<langle>C,(Normal (restrict_htd s X))\\<rangle> \\<Rightarrow> Abrupt (restrict_htd t X) \\<and>\n       point_eq_mod (lift_state (hst_mem t,hst_htd t))\n          (lift_state (hst_mem s,hst_htd s)) X)\"\n  by (force simp: mem_safe_def restrict_safe_def restrict_safe_OK_def)\n\nlemma mem_safe_FaultD:\n  \"\\<lbrakk> \\<Gamma> \\<turnstile> \\<langle>C,Normal s\\<rangle> \\<Rightarrow> Fault f; mem_safe C \\<Gamma> \\<rbrakk> \\<Longrightarrow>\n      exec_fatal C \\<Gamma> (restrict_htd s X)\"\n  by (force simp: mem_safe_def restrict_safe_def)\n\nlemma mem_safe_StuckD:\n  \"\\<lbrakk> \\<Gamma> \\<turnstile> \\<langle>C,Normal s\\<rangle> \\<Rightarrow> Stuck; mem_safe C \\<Gamma> \\<rbrakk> \\<Longrightarrow>\n      exec_fatal C \\<Gamma> (restrict_htd s X)\"\n  by (force simp: mem_safe_def restrict_safe_def)\n\nlemma lift_state_d_restrict [simp]:\n  \"lift_state (h,(restrict_s d X)) = lift_state (h,d) |` X\"\n  by (auto simp: lift_state_def restrict_map_def restrict_s_def split: s_heap_index.splits)\n\nlemma dom_merge_restrict [simp]:\n  \"(x ++ y) |` dom y = y\"\n  by (rule map_add_restrict_dom_right)\n\nlemma dom_compl_restrict [simp]:\n  \"x |` (UNIV - dom x) = Map.empty\"\n  by (force simp: restrict_map_def)\n\nlemma lift_state_point_eq_mod:\n  \"\\<lbrakk> point_eq_mod (lift_state (h,d)) (lift_state (h',d')) X \\<rbrakk> \\<Longrightarrow>\n      lift_state (h,d) |` (UNIV - X) =\n          lift_state (h',d') |` (UNIV - X)\"\n  by (auto simp: point_eq_mod_def restrict_map_def)\n\nlemma htd_'_update_ind [simp]:\n  \"htd_ind f \\<Longrightarrow> f (hst_htd_update x s) = f s\"\n  by (simp add: htd_ind_def)\n\nlemma sep_frame':\n  assumes orig_spec:  \"\\<forall>s. \\<Gamma> \\<turnstile> \\<lbrace>s. P (f \\<acute>(\\<lambda>x. x)) (lift_hst \\<acute>(\\<lambda>x. x))\\<rbrace>\n                               C\n                               \\<lbrace>Q (g s \\<acute>(\\<lambda>x. x)) (lift_hst \\<acute>(\\<lambda>x. x))\\<rbrace>\"\n      and hi_f: \"htd_ind f\" and hi_g: \"htd_ind g\"\n      and hi_g': \"\\<forall>s. htd_ind (g s)\"\n      and safe: \"mem_safe (C::('s::heap_state_type,'b,'c) com) \\<Gamma>\"\n  shows \"\\<forall>s. \\<Gamma> \\<turnstile> \\<lbrace>s. (P (f \\<acute>(\\<lambda>x. x)) \\<and>\\<^sup>* R (h \\<acute>(\\<lambda>x. x))) (lift_hst \\<acute>(\\<lambda>x. x))\\<rbrace>\n                 C\n                 \\<lbrace>(Q (g s \\<acute>(\\<lambda>x. x)) \\<and>\\<^sup>* R (h s)) (lift_hst \\<acute>(\\<lambda>x. x))\\<rbrace>\"\nproof (rule, rule hoare_complete, simp only: valid_def, clarify)\n  fix ta x\n  assume ev: \"\\<Gamma>\\<turnstile> \\<langle>C,Normal x\\<rangle> \\<Rightarrow> ta\" and\n      pre: \"(P (f x) \\<and>\\<^sup>* R (h x)) (lift_hst x)\"\n  then obtain s\\<^sub>0 and s\\<^sub>1 where pre_P: \"P (f x) s\\<^sub>0\" and pre_R: \"R (h x) s\\<^sub>1\" and\n      disj: \"s\\<^sub>0 \\<bottom> s\\<^sub>1\" and m: \"lift_hst x = s\\<^sub>1 ++ s\\<^sub>0\"\n    by (clarsimp simp: sep_conj_def map_ac_simps)\n  with orig_spec hi_f have nofault: \"\\<not> exec_fatal C \\<Gamma>\n      (restrict_htd x (dom s\\<^sub>0))\"\n    by (force simp: exec_fatal_def image_def lift_hst_def cvalid_def valid_def\n                    restrict_htd_def\n              dest: hoare_sound)\n  show \"ta \\<in> Normal ` {t. (Q (g x t) \\<and>\\<^sup>* R (h x)) (lift_hst t)}\"\n  proof (cases ta)\n    case (Normal s)\n    moreover from this ev safe nofault have ev': \"\\<Gamma> \\<turnstile>\n        \\<langle>C,Normal (x\\<lparr> hst_htd := (restrict_s (hst_htd x) (dom s\\<^sub>0)) \\<rparr>)\\<rangle> \\<Rightarrow>\n           Normal (s\\<lparr> hst_htd := (restrict_s (hst_htd s) (dom s\\<^sub>0)) \\<rparr>)\" and\n        \"point_eq_mod (lift_state (hst_mem s,hst_htd s))\n            (lift_state (hst_mem x,hst_htd x)) (dom s\\<^sub>0)\"\n      by (auto simp: restrict_htd_def dest: mem_safe_NormalD)\n    moreover from this m disj have \"s\\<^sub>1 = lift_hst s |` (UNIV - dom s\\<^sub>0)\"\n      apply(clarsimp simp: lift_hst_def)\n      apply(subst lift_state_point_eq_mod)\n       apply(fastforce dest: sym)\n      apply(simp add: lift_hst_def lift_state_point_eq_mod map_add_restrict)\n      apply(subst restrict_map_subdom, auto dest: map_disjD)\n      done\n    ultimately show ?thesis using orig_spec hi_f hi_g hi_g' pre_P pre_R m\n      by (force simp: cvalid_def valid_def image_def lift_hst_def\n                      map_disj_def\n                intro: sep_conjI dest: hoare_sound)\n  next\n    case (Abrupt s) with ev safe nofault orig_spec pre_P hi_f m show ?thesis\n      by - (simp, drule spec, drule hoare_sound, drule_tac X=\"dom s\\<^sub>0\" in\n            mem_safe_AbruptD, assumption+,\n            force simp: valid_def cvalid_def lift_hst_def restrict_htd_def)\n  next\n    case (Fault f) with ev safe nofault show ?thesis\n      by (force dest: mem_safe_FaultD)\n  next\n    case Stuck with ev safe nofault show ?thesis\n      by (force dest: mem_safe_StuckD)\n  qed\nqed\n\nlemma sep_frame:\n  \"\\<lbrakk> k = (\\<lambda>s. (hst_mem s,hst_htd s));\n      \\<forall>s. \\<Gamma> \\<turnstile> \\<lbrace>s. P (f \\<acute>(\\<lambda>x. x)) (lift_state (k \\<acute>(\\<lambda>x. x)))\\<rbrace>\n              C\n              \\<lbrace>Q (g s \\<acute>(\\<lambda>x. x)) (lift_state (k \\<acute>(\\<lambda>x. x)))\\<rbrace>;\n      htd_ind f; htd_ind g; \\<forall>s. htd_ind (g s);\n      mem_safe (C::('s::heap_state_type,'b,'c) com) \\<Gamma> \\<rbrakk> \\<Longrightarrow>\n      \\<forall>s. \\<Gamma> \\<turnstile> \\<lbrace>s. (P (f \\<acute>(\\<lambda>x. x)) \\<and>\\<^sup>* R (h \\<acute>(\\<lambda>x. x))) (lift_state (k \\<acute>(\\<lambda>x. x)))\\<rbrace>\n               C\n               \\<lbrace>(Q (g s \\<acute>(\\<lambda>x. x)) \\<and>\\<^sup>* R (h s)) (lift_state (k \\<acute>(\\<lambda>x. x)))\\<rbrace>\"\n  apply(simp only:)\n  apply(fold lift_hst_def)\n  apply(erule (4) sep_frame')\n  done\n\n\nlemma point_eq_mod_safe [simp]:\n  \"\\<lbrakk> point_eq_mod_safe P f g; restrict_htd s X \\<in> P; x \\<notin> X \\<rbrakk> \\<Longrightarrow>\n      g (f s) x = (g s) x\"\n  apply(simp add: point_eq_mod_safe_def point_eq_mod_def)\n  apply(case_tac x, force)\n  done\n\nlemma comm_restrict_safe [simp]:\n  \"\\<lbrakk> comm_restrict_safe P f; restrict_htd s X \\<in> P \\<rbrakk> \\<Longrightarrow>\n        restrict_htd (f s ) X = f (restrict_htd s X)\"\n  by (simp add: comm_restrict_safe_def comm_restrict_def)\n\nlemma mono_guardD:\n  \"\\<lbrakk> mono_guard P; restrict_htd s X \\<in> P \\<rbrakk> \\<Longrightarrow> s \\<in> P\"\n  by (unfold mono_guard_def, fast)\n\nlemma expr_htd_ind:\n  \"expr_htd_ind P \\<Longrightarrow> restrict_htd s X \\<in> P = (s \\<in> P)\"\n  by (simp add: expr_htd_ind_def restrict_htd_def)\n\n(* exec.intros without those already declared as [intro] *)\nlemmas exec_other_intros = exec.intros(1-3) exec.intros(5-14) exec.intros(16-17) exec.intros(19-)\n\nlemma exec_fatal_Seq:\n  \"exec_fatal C \\<Gamma> s \\<Longrightarrow> exec_fatal (C;;D) \\<Gamma> s\"\n  by (force simp: exec_fatal_def intro: exec_other_intros)\n\nlemma exec_fatal_Seq2:\n  \"\\<lbrakk> \\<Gamma> \\<turnstile> \\<langle>C,Normal s\\<rangle> \\<Rightarrow> Normal t; exec_fatal D \\<Gamma> t \\<rbrakk> \\<Longrightarrow> exec_fatal (C;;D) \\<Gamma> s\"\n  by (force simp: exec_fatal_def intro: exec_other_intros)\n\nlemma exec_fatal_Cond:\n  \"exec_fatal (Cond P C D) \\<Gamma> s = (if s \\<in> P then exec_fatal C \\<Gamma> s else\n      exec_fatal D \\<Gamma> s)\"\n  by (force simp: exec_fatal_def intro: exec_other_intros\n            elim: exec_Normal_elim_cases)\n\nlemma exec_fatal_While:\n  \"\\<lbrakk> exec_fatal C \\<Gamma> s; s \\<in> P \\<rbrakk> \\<Longrightarrow> exec_fatal (While P C) \\<Gamma> s\"\n  by (force simp: exec_fatal_def intro: exec_other_intros\n            elim: exec_Normal_elim_cases)\n\nlemma exec_fatal_While2:\n  \"\\<lbrakk> exec_fatal (While P C) \\<Gamma> t; \\<Gamma> \\<turnstile> \\<langle>C,Normal s\\<rangle> \\<Rightarrow> Normal t; s \\<in> P \\<rbrakk> \\<Longrightarrow>\n      exec_fatal (While P C) \\<Gamma> s\"\n  by (force simp: exec_fatal_def intro: exec_other_intros\n            elim: exec_Normal_elim_cases)\n\nlemma exec_fatal_Call:\n  \"\\<lbrakk> \\<Gamma> p = Some C; exec_fatal C \\<Gamma> s \\<rbrakk> \\<Longrightarrow> exec_fatal (Call p) \\<Gamma> s\"\n  by (force simp: exec_fatal_def intro: exec_other_intros)\n\nlemma exec_fatal_DynCom:\n  \"exec_fatal (f s) \\<Gamma> s \\<Longrightarrow> exec_fatal (DynCom f) \\<Gamma> s\"\n  by (force simp: exec_fatal_def intro: exec_other_intros)\n\nlemma exec_fatal_Guard:\n  \"exec_fatal (Guard f P C) \\<Gamma> s = (s \\<in> P \\<longrightarrow> exec_fatal C \\<Gamma> s)\"\nproof (cases \"s \\<in> P\")\n  case True thus ?thesis\n    by (force simp: exec_fatal_def intro: exec_other_intros\n              elim: exec_Normal_elim_cases)\nnext\n  case False thus ?thesis\n    by (force simp: exec_fatal_def intro: exec_other_intros)\nqed\n\nlemma restrict_safe_Guard:\n  assumes restrict: \"restrict_safe s t C \\<Gamma>\"\n  shows \"restrict_safe s t (Guard f P C) \\<Gamma>\"\nproof (cases t)\n  case (Normal s) with restrict show ?thesis\n    by (force simp: restrict_safe_def restrict_safe_OK_def exec_fatal_Guard\n              intro: exec_other_intros)\nnext\n  case (Abrupt s) with restrict show ?thesis\n    by (force simp: restrict_safe_def restrict_safe_OK_def exec_fatal_Guard\n              intro: exec_other_intros)\nnext\n  case (Fault f) with restrict show ?thesis\n    by (force simp: restrict_safe_def exec_fatal_Guard)\nnext\n  case Stuck with restrict show ?thesis\n    by (force simp: restrict_safe_def exec_fatal_Guard)\nqed\n\nlemma restrict_safe_Guard2:\n  \"\\<lbrakk> s \\<notin> P; mono_guard P \\<rbrakk> \\<Longrightarrow> restrict_safe s (Fault f) (Guard f P C) \\<Gamma>\"\n  by (force simp: restrict_safe_def exec_fatal_def intro: exec_other_intros\n            dest: mono_guardD)\n\nlemma exec_fatal_Catch:\n  \"exec_fatal C \\<Gamma> s \\<Longrightarrow> exec_fatal (TRY C CATCH D END) \\<Gamma> s\"\n  by (force simp: exec_fatal_def intro: exec_other_intros)\n\nlemma exec_fatal_Catch2:\n  \"\\<lbrakk> \\<Gamma> \\<turnstile> \\<langle>C,Normal s\\<rangle> \\<Rightarrow> Abrupt t; exec_fatal D \\<Gamma> t \\<rbrakk> \\<Longrightarrow>\n      exec_fatal (TRY C CATCH D END) \\<Gamma> s\"\n  by (force simp: exec_fatal_def intro: exec_other_intros)\n\nlemma intra_safe_restrict [rule_format]:\n  assumes safe_env: \"\\<And>n C. \\<Gamma> n = Some C \\<Longrightarrow> intra_safe C\" and\n      exec: \"\\<Gamma> \\<turnstile> \\<langle>C,s\\<rangle> \\<Rightarrow> t\"\n  shows \"\\<forall>s'. s = Normal s' \\<longrightarrow> intra_safe C \\<longrightarrow> restrict_safe s' t C \\<Gamma>\"\nusing exec\nproof induct\n  case (Skip s) thus ?case\n    by (force simp: restrict_safe_def restrict_safe_OK_def intro: exec_other_intros)\nnext\n  case (Guard s' P C t f) show ?case\n  proof (cases \"\\<exists>g. C = Basic g\")\n    case False with Guard show ?thesis\n      by - (clarsimp, split com.splits, auto dest: restrict_safe_Guard)\n  next\n    case True with Guard show ?thesis\n      by (cases t) (force simp: restrict_safe_def restrict_safe_OK_def\n                                point_eq_mod_safe_def exec_fatal_Guard\n                          intro: exec_other_intros\n                          elim: exec_Normal_elim_cases,\n                    (fast elim: exec_Normal_elim_cases)+)\n  qed\nnext\n  case (GuardFault C f P s) thus ?case\n    by (force dest: restrict_safe_Guard2)\nnext\n  case (FaultProp C f) thus ?case by simp\nnext\n  case (Basic f s) thus ?case\n    by (force simp: restrict_safe_def restrict_safe_OK_def point_eq_mod_safe_def\n              intro: exec_other_intros)\nnext\n  case (Spec r s t) thus ?case\n    by (fastforce simp: mem_safe_def intro: exec.Spec)\nnext\n  case (SpecStuck r s) thus ?case\n    by (simp add: exec.SpecStuck mem_safe_StuckD restrict_safe_def)\nnext\n  case (Seq C s sa D ta) show ?case\n  proof (cases sa)\n    case (Normal s') with Seq show ?thesis\n      by (cases ta)\n         (clarsimp simp: restrict_safe_def restrict_safe_OK_def,\n          (drule_tac x=X in spec)+, auto intro: exec_other_intros point_eq_mod_trans\n                                               exec_fatal_Seq exec_fatal_Seq2)+\n  next\n    case (Abrupt s') with Seq show ?thesis\n      by (force simp: restrict_safe_def restrict_safe_OK_def\n                intro: exec_other_intros dest: exec_fatal_Seq\n                elim: exec_Normal_elim_cases)\n  next\n    case (Fault f) with Seq show ?thesis\n      by (force simp: restrict_safe_def dest: exec_fatal_Seq\n                elim: exec_Normal_elim_cases)\n  next\n    case Stuck with Seq show ?thesis\n      by (force simp: restrict_safe_def dest: exec_fatal_Seq\n                elim: exec_Normal_elim_cases)\n  qed\nnext\n  case (CondTrue s P C t D) thus ?case\n    by (cases t)\n       (auto simp: restrict_safe_def restrict_safe_OK_def exec_fatal_Cond\n             intro: exec_other_intros dest: expr_htd_ind split: if_split_asm)\nnext\n  case (CondFalse s P C t D) thus ?case\n    by (cases t)\n       (auto simp: restrict_safe_def restrict_safe_OK_def exec_fatal_Cond\n             intro: exec_other_intros dest: expr_htd_ind split: if_split_asm)\nnext\n  case (WhileTrue P C s s' t) show ?case\n  proof (cases s')\n    case (Normal sa) with WhileTrue show ?thesis\n      by (cases t)\n         (clarsimp simp: restrict_safe_def restrict_safe_OK_def,\n          (drule_tac x=X in spec)+, auto simp: expr_htd_ind intro: exec_other_intros\n               point_eq_mod_trans exec_fatal_While exec_fatal_While2)+\n  next\n    case (Abrupt sa) with WhileTrue show ?thesis\n      by (force simp: restrict_safe_def restrict_safe_OK_def expr_htd_ind\n                intro: exec_other_intros exec_fatal_While\n                elim: exec_Normal_elim_cases)\n  next\n    case (Fault f) with WhileTrue show ?thesis\n      by (force simp: restrict_safe_def expr_htd_ind intro: exec_fatal_While)\n  next\n    case Stuck with WhileTrue show ?thesis\n      by (force simp: restrict_safe_def expr_htd_ind intro: exec_fatal_While)\n  qed\nnext\n  case (WhileFalse P C s) thus ?case\n    by (force simp: restrict_safe_def restrict_safe_OK_def expr_htd_ind\n              intro: exec_other_intros)\nnext\n  case (Call C p s t) with safe_env show ?case\n    by (cases t)\n       (auto simp: restrict_safe_def restrict_safe_OK_def\n             intro: exec_fatal_Call exec_other_intros)\nnext\n  case (CallUndefined p s) thus ?case\n    by (force simp: restrict_safe_def exec_fatal_def intro: exec_other_intros)\n\nnext\n  case (StuckProp C) thus ?case by simp\nnext\n  case (DynCom f s t) thus ?case\n    by (cases t)\n       (auto simp: restrict_safe_def restrict_safe_OK_def\n                   restrict_htd_def\n             intro!: exec_other_intros exec_fatal_DynCom)\nnext\n  case (Throw s) thus ?case\n    by (force simp: restrict_safe_def restrict_safe_OK_def intro: exec_other_intros)\nnext\n  case (AbruptProp C s) thus ?case by simp\nnext\n  case (CatchMatch C D s s' t) thus ?case\n    by (cases t)\n       (clarsimp simp: restrict_safe_def, drule_tac x=X in spec,\n        auto simp: restrict_safe_OK_def intro: exec_other_intros point_eq_mod_trans\n             dest: exec_fatal_Catch exec_fatal_Catch2)+\nnext\n  case (CatchMiss C s t D) thus ?case\n    by (cases t)\n       (clarsimp simp: restrict_safe_def, drule_tac x=X in spec,\n        auto simp: restrict_safe_OK_def intro: exec_other_intros\n             dest: exec_fatal_Catch)+\nqed\n\nlemma intra_mem_safe:\n  \"\\<lbrakk> \\<And>n C. \\<Gamma> n = Some C \\<Longrightarrow> intra_safe C; intra_safe C \\<rbrakk> \\<Longrightarrow> mem_safe C \\<Gamma>\"\n  by (force  simp: mem_safe_def intro: intra_safe_restrict)\n\nlemma point_eq_mod_safe_triv:\n  \"(\\<And>s. g (f s) = g s) \\<Longrightarrow> point_eq_mod_safe P f g\"\n  by (simp add: point_eq_mod_safe_def point_eq_mod_def)\n\nlemma comm_restrict_safe_triv:\n  \"(\\<And>s X. f (s\\<lparr> hst_htd := restrict_s (hst_htd s) X \\<rparr>) =\n      (f s)\\<lparr> hst_htd := restrict_s (hst_htd (f s)) X \\<rparr>) \\<Longrightarrow> comm_restrict_safe P f\"\n  by (force simp: comm_restrict_safe_def comm_restrict_def restrict_htd_def)\n\nlemma mono_guard_UNIV [simp]:\n  \"mono_guard UNIV\"\n  by (force simp: mono_guard_def)\n\nlemma mono_guard_triv:\n  \"(\\<And>s X. s\\<lparr> hst_htd := X \\<rparr> \\<in> g \\<Longrightarrow> s \\<in> g) \\<Longrightarrow> mono_guard g\"\n  by (unfold mono_guard_def, unfold restrict_htd_def, fast)\n\nlemma mono_guard_triv2:\n  \"(\\<And>s X. s\\<lparr> hst_htd := X \\<rparr> \\<in> g = ((s::'a::heap_state_type') \\<in> g)) \\<Longrightarrow>\n      mono_guard g\"\n  by (unfold mono_guard_def, unfold restrict_htd_def, fast)\n\nlemma dom_restrict_s:\n  \"x \\<in> dom_s (restrict_s d X) \\<Longrightarrow> x \\<in> dom_s d \\<and> x \\<in> X\"\n  by (auto simp: restrict_s_def dom_s_def split: if_split_asm)\n\nlemma mono_guard_ptr_safe:\n  \"\\<lbrakk> \\<And>s. d s = hst_htd (s::'a::heap_state_type); htd_ind p \\<rbrakk> \\<Longrightarrow>\n      mono_guard {s. ptr_safe (p s) (d s)}\"\n  by (auto simp: mono_guard_def ptr_safe_def restrict_htd_def dest: subsetD dom_restrict_s)\n\nlemma point_eq_mod_safe_ptr_safe_update:\n  \"\\<lbrakk> d = (hst_htd::'a::heap_state_type \\<Rightarrow> heap_typ_desc);\n      m = (\\<lambda>s. hst_mem_update (heap_update (p s) ((v s)::'b::mem_type)) s);\n      h = hst_mem; k = (\\<lambda>s. lift_state (h s,d s)); htd_ind p \\<rbrakk> \\<Longrightarrow>\n      point_eq_mod_safe {s. ptr_safe (p s) (d s)} m k\"\n  apply (clarsimp simp: point_eq_mod_safe_def point_eq_mod_def ptr_safe_def heap_update_def\n                        restrict_htd_def lift_state_def\n                  intro!: heap_update_nmem_same\n                  split: s_heap_index.splits)\n  apply(subgoal_tac \"(a,SIndexVal) \\<in> s_footprint (p s)\")\n   apply(drule (1) subsetD)\n   apply(drule dom_restrict_s, clarsimp)\n  apply(drule intvlD, clarsimp)\n  apply(erule s_footprintI2)\n  done\n\nlemma field_ti_s_sub_typ:\n  \"field_lookup (export_uinfo (typ_info_t TYPE('b::mem_type))) f 0 = Some (typ_uinfo_t TYPE('a),b) \\<Longrightarrow>\n      s_footprint ((Ptr &(p\\<rightarrow>f))::'a::mem_type ptr) \\<subseteq> s_footprint (p::'b ptr)\"\n  by (drule field_ti_s_sub) (simp add: s_footprint_def)\n\nlemma ptr_safe_mono:\n  \"\\<lbrakk> ptr_safe (p::'a::mem_type ptr) d; field_lookup (typ_info_t TYPE('a)) f 0\n      = Some (t,n); export_uinfo t = typ_uinfo_t TYPE('b) \\<rbrakk> \\<Longrightarrow>\n      ptr_safe ((Ptr &(p\\<rightarrow>f))::'b::mem_type ptr) d\"\n  unfolding ptr_safe_def\n  by (drule field_lookup_export_uinfo_Some) (auto dest: field_ti_s_sub_typ)\n\nlemma point_eq_mod_safe_ptr_safe_update_fl:\n  \"\\<lbrakk> d = (hst_htd::'a::heap_state_type \\<Rightarrow> heap_typ_desc);\n      m = (\\<lambda>s. hst_mem_update (heap_update (Ptr &((p s)\\<rightarrow>f)) ((v s)::'b::mem_type)) s);\n      h = hst_mem; k = (\\<lambda>s. lift_state (h s,d s)); htd_ind p;\n      field_lookup (typ_info_t TYPE('c)) f 0 = Some (t,n);\n      export_uinfo t = typ_uinfo_t TYPE('b) \\<rbrakk> \\<Longrightarrow>\n      point_eq_mod_safe {s. ptr_safe ((p::'a \\<Rightarrow> 'c::mem_type ptr) s) (d s)} m k\"\n  apply(drule (3) point_eq_mod_safe_ptr_safe_update)\n   apply(fastforce simp: htd_ind_def)\n  apply(fastforce simp: point_eq_mod_safe_def intro!: ptr_safe_mono)\n  done\n\ncontext\nbegin\n\nprivate method m =\n  (clarsimp simp: ptr_retyp_d_eq_snd ptr_retyp_footprint list_map_eq,\n   erule notE,\n   drule intvlD, clarsimp,\n   (rule s_footprintI; assumption?),\n   subst (asm) unat_of_nat,\n   (subst (asm) mod_less; assumption?),\n   subst len_of_addr_card,\n   erule less_trans,\n   simp)\n\nlemma point_eq_mod_safe_ptr_safe_tag:\n  \"\\<lbrakk> d = (hst_htd::'a::heap_state_type \\<Rightarrow> heap_typ_desc); h = hst_mem;\n     m = (\\<lambda>s. hst_htd_update (ptr_retyp (p s)) s);\n     k = (\\<lambda>s. lift_state (h s,d s));\n     htd_ind p \\<rbrakk> \\<Longrightarrow>\n   point_eq_mod_safe {s. ptr_safe ((p s)::'b::mem_type ptr) (d s)} m k\"\n  supply if_split_asm[split]\n  apply(clarsimp simp: point_eq_mod_safe_def point_eq_mod_def ptr_safe_def)\n  apply(subgoal_tac \"(a,b) \\<notin> s_footprint (p (restrict_htd s X))\")\n   prefer 2\n   apply(fastforce simp: restrict_htd_def dest: dom_restrict_s)\n  apply(clarsimp simp: restrict_htd_def  lift_state_def split: s_heap_index.split option.splits)\n  apply (safe; m?)\n    apply(fastforce simp: ptr_retyp_d_eq_fst dest!: intvlD dest: s_footprintI2)\n   apply(fastforce simp: ptr_retyp_d_eq_fst)\n  apply(subst (asm) ptr_retyp_d_eq_snd, clarsimp)\n  done\n\nend\n\nlemma comm_restrict_safe_ptr_safe_tag:\n  fixes d::\"'a::heap_state_type \\<Rightarrow> heap_typ_desc\"\n  assumes\n    fun_d: \"d = hst_htd\" and\n    fun_upd: \"m = (\\<lambda>s. hst_htd_update (ptr_retyp (p s)) s)\" and\n    ind: \"htd_ind p\" and\n    upd: \"\\<And>d d' (s::'a).\n               hst_htd_update (d s) (hst_htd_update (d' s) s) = hst_htd_update ((d s) \\<circ> (d' s)) s\"\n  shows \"comm_restrict_safe {s. ptr_safe ((p s)::'b::mem_type ptr) (d s)} m\"\nproof (simp only: comm_restrict_safe_def comm_restrict_def, auto)\n  fix s X\n  assume \"ptr_safe (p (restrict_htd s X)) (d (restrict_htd s X))\"\n  moreover from ind\n  have p: \"p (restrict_htd s X) = p s\"\n    by (simp add:  restrict_htd_def)\n  ultimately\n  have \"ptr_retyp (p s) (restrict_s (hst_htd s) X) = restrict_s (ptr_retyp (p s) (hst_htd s))  X\"\n    using fun_d\n    apply -\n    apply(rule ext)\n    apply(clarsimp simp: point_eq_mod_safe_def point_eq_mod_def ptr_safe_def restrict_htd_def)\n    apply(case_tac \"x \\<notin> {ptr_val (p s)..+size_of TYPE('b)}\")\n     apply(clarsimp simp: ptr_retyp_d restrict_map_def restrict_s_def)\n     apply(subst ptr_retyp_d; simp)\n    apply(clarsimp simp: ptr_retyp_footprint restrict_map_def restrict_s_def)\n    apply(subst ptr_retyp_footprint, simp)\n    apply(rule conjI)\n     apply(subgoal_tac \"(x,SIndexVal) \\<in> s_footprint (p s)\")\n      apply(fastforce simp: dom_s_def)\n     apply(fastforce dest: intvlD elim: s_footprintI2)\n    apply(rule ext)\n    apply(clarsimp simp: map_add_def list_map_eq)\n    apply(subgoal_tac \"(x,SIndexTyp y) \\<in> s_footprint (p s)\")\n     apply(fastforce simp: dom_s_def split: if_split_asm)\n    apply(drule intvlD, clarsimp)\n    apply(rule s_footprintI; assumption?)\n    apply(metis len_of_addr_card less_trans max_size mod_less word_unat.eq_norm)\n    done\n  hence \"((ptr_retyp (p s) \\<circ> (\\<lambda>x _. x) (restrict_s (hst_htd s) X)::heap_typ_desc \\<Rightarrow> heap_typ_desc) =\n              (\\<lambda>x _. x) (restrict_s (ptr_retyp (p s) (hst_htd s)) X))\"\n    by - (rule ext, simp)\n  moreover from upd have \"hst_htd_update (ptr_retyp (p s))\n        (hst_htd_update ((\\<lambda>x _. x) (restrict_s (hst_htd s) X)) s) =\n         hst_htd_update (((ptr_retyp (p s)) \\<circ> ((\\<lambda>x _. x) (restrict_s (hst_htd s) X)))) s\" .\n  moreover from upd\n  have\n    \"hst_htd_update ((\\<lambda>x _. x) (restrict_s (ptr_retyp (p s) (hst_htd s)) X))\n                    (hst_htd_update (ptr_retyp (p s)) s) =\n     hst_htd_update (((\\<lambda>x _. x) (restrict_s ((ptr_retyp (p s) (hst_htd s))) X)) \\<circ> (ptr_retyp (p s))) s\" .\n  ultimately show \"m (restrict_htd s X) = restrict_htd (m s) X\" using fun_d fun_upd upd p\n    by (simp add: restrict_htd_def o_def)\nqed\n\nlemmas intra_sc = hrs_comm comp_def hrs_htd_update_htd_update\n  point_eq_mod_safe_triv comm_restrict_safe_triv mono_guard_triv2\n  mono_guard_ptr_safe point_eq_mod_safe_ptr_safe_update\n  point_eq_mod_safe_ptr_safe_tag comm_restrict_safe_ptr_safe_tag\n  point_eq_mod_safe_ptr_safe_update_fl\n\ndeclare expr_htd_ind_def [iff]\ndeclare htd_ind_def [iff]\n\nlemma proc_deps_Skip [simp]:\n  \"proc_deps Skip \\<Gamma> = {}\"\n  by (force elim: proc_deps.induct)\n\nlemma proc_deps_Basic [simp]:\n  \"proc_deps (Basic f) \\<Gamma> = {}\"\n  by (force elim: proc_deps.induct)\n\nlemma proc_deps_Spec [simp]:\n  \"proc_deps (Spec r) \\<Gamma> = {}\"\n  by (force elim: proc_deps.induct)\n\nlemma proc_deps_Seq [simp]:\n  \"proc_deps (Seq C D) \\<Gamma> = proc_deps C \\<Gamma> \\<union> proc_deps D \\<Gamma>\"\nproof\n  show \"proc_deps (C;; D) \\<Gamma> \\<subseteq> proc_deps C \\<Gamma> \\<union> proc_deps D \\<Gamma>\"\n    by - (rule, erule proc_deps.induct, auto intro: proc_deps.intros)\nnext\n  show \"proc_deps C \\<Gamma> \\<union> proc_deps D \\<Gamma> \\<subseteq> proc_deps (C;; D) \\<Gamma>\"\n    by auto (erule proc_deps.induct, auto intro: proc_deps.intros)+\nqed\n\nlemma proc_deps_Cond [simp]:\n  \"proc_deps (Cond P C D) \\<Gamma> = proc_deps C \\<Gamma> \\<union> proc_deps D \\<Gamma>\"\nproof\n  show \"proc_deps (Cond P C D) \\<Gamma> \\<subseteq> proc_deps C \\<Gamma> \\<union> proc_deps D \\<Gamma>\"\n    by (rule, erule proc_deps.induct, auto intro: proc_deps.intros)\nnext\n  show \"proc_deps C \\<Gamma> \\<union> proc_deps D \\<Gamma> \\<subseteq> proc_deps (Cond P C D) \\<Gamma>\"\n    by auto (erule proc_deps.induct, auto intro: proc_deps.intros)+\nqed\n\nlemma proc_deps_While [simp]:\n  \"proc_deps (While P C) \\<Gamma> = proc_deps C \\<Gamma>\"\n  by auto (erule proc_deps.induct, auto intro: proc_deps.intros)+\n\nlemma proc_deps_Guard [simp]:\n  \"proc_deps (Guard f P C) \\<Gamma> = proc_deps C \\<Gamma>\"\n  by auto (erule proc_deps.induct, auto intro: proc_deps.intros)+\n\nlemma proc_deps_Throw [simp]:\n  \"proc_deps Throw \\<Gamma> = {}\"\n  by (force elim: proc_deps.induct)\n\nlemma proc_deps_Catch [simp]:\n  \"proc_deps (Catch  C D) \\<Gamma> = proc_deps C \\<Gamma> \\<union> proc_deps D \\<Gamma>\"\nproof\n  show \"proc_deps (Catch C D) \\<Gamma> \\<subseteq> proc_deps C \\<Gamma> \\<union> proc_deps D \\<Gamma>\"\n    by (rule, erule proc_deps.induct, auto intro: proc_deps.intros)\nnext\n  show \"proc_deps C \\<Gamma> \\<union> proc_deps D \\<Gamma> \\<subseteq> proc_deps (Catch C D) \\<Gamma>\"\n    by auto (erule proc_deps.induct, auto intro: proc_deps.intros)+\nqed\n\nlemma proc_deps_Call [simp]:\n  \"proc_deps (Call p) \\<Gamma> = {p} \\<union> (case \\<Gamma> p of Some C \\<Rightarrow>\n      proc_deps C (\\<Gamma>(p := None)) | _ \\<Rightarrow> {})\" (is \"?X = ?Y \\<union> ?Z\")\nproof\n  note proc_deps.intros[intro]\n  show \"?X \\<subseteq> ?Y \\<union> ?Z\"\n    by (rule subsetI, erule proc_deps.induct, fastforce)\n       (rename_tac x D y, case_tac \"x = p\"; fastforce split: option.splits)\nnext\n  show \"?Y \\<union> ?Z \\<subseteq> ?X\"\n  proof (clarsimp, rule)\n    show \"p \\<in> ?X\" by (force intro: proc_deps.intros)\n  next\n    show \"?Z \\<subseteq> ?X\"\n      by (split option.splits, rule, force intro: proc_deps.intros)\n         (clarify, erule proc_deps.induct;\n          force intro: proc_deps.intros split: if_split_asm)\n  qed\nqed\n\nlemma proc_deps_DynCom [simp]:\n  \"proc_deps (DynCom f) \\<Gamma> = \\<Union>{proc_deps (f s) \\<Gamma> | s. True}\"\n  by (rule equalityI; clarsimp; erule proc_deps.induct; force intro: proc_deps.intros)\n\nlemma proc_deps_restrict:\n  \"proc_deps C \\<Gamma> \\<subseteq> proc_deps C (\\<Gamma>(p := None)) \\<union> proc_deps (Call p) \\<Gamma>\"\nproof\n  fix xa\n  assume mem: \"xa \\<in> proc_deps C \\<Gamma>\"\n  hence \"\\<forall>p. xa \\<in> proc_deps C (\\<Gamma>(p := None)) \\<union> proc_deps (Call p) \\<Gamma>\" (is \"?X\")\n  using mem\n  proof induct\n    fix x\n    assume \"x \\<in> intra_deps C\"\n    thus \"\\<forall>p. x \\<in> proc_deps C (\\<Gamma>(p := None)) \\<union> proc_deps (Call p) \\<Gamma>\"\n      by (force intro: proc_deps.intros)\n  next\n    fix D x y\n    assume x:\n      \"x \\<in> proc_deps C \\<Gamma>\"\n      \"x \\<in> proc_deps C \\<Gamma> \\<Longrightarrow> \\<forall>p. x \\<in> proc_deps C (\\<Gamma>(p := None)) \\<union> proc_deps (Call p) \\<Gamma>\"\n      \"\\<Gamma> x = Some D\"\n      \"y \\<in> intra_deps D\"\n      \"y \\<in> proc_deps C \\<Gamma>\"\n    show \"\\<forall>p. y \\<in> proc_deps C (\\<Gamma>(p := None)) \\<union> proc_deps (Call p) \\<Gamma>\"\n    proof clarify\n      fix p\n      assume y: \"y \\<notin> proc_deps (Call p) \\<Gamma>\"\n      show \"y \\<in> proc_deps C (\\<Gamma>(p := None))\"\n      proof (cases \"x=p\")\n        case True with x y show ?thesis\n          by (force intro: proc_deps.intros)\n      next\n        case False with x y show ?thesis\n          by (clarsimp, drule_tac x=p in spec)\n             (auto intro: proc_deps.intros split: option.splits)\n      qed\n    qed\n  qed\n  thus \"xa \\<in> proc_deps C (\\<Gamma>(p := None)) \\<union> proc_deps (Call p) \\<Gamma>\" by simp\nqed\n\nlemma exec_restrict:\n  assumes exec: \"\\<Gamma>' \\<turnstile> \\<langle>C,s\\<rangle> \\<Rightarrow> t\"\n  shows \"\\<And>\\<Gamma> X. \\<lbrakk> \\<Gamma>' = \\<Gamma> |` X; proc_deps C \\<Gamma> \\<subseteq> X \\<rbrakk> \\<Longrightarrow> \\<Gamma> \\<turnstile> \\<langle>C,s\\<rangle> \\<Rightarrow> t\"\nusing exec\nproof induct\n  case (Call p C s t)\n  thus ?case\n    using proc_deps_restrict [of C \\<Gamma> p] by (force intro: exec_other_intros)\nqed (force intro: exec_other_intros)+\n\nlemma exec_restrict2:\n  assumes exec: \"\\<Gamma> \\<turnstile> \\<langle>C,s\\<rangle> \\<Rightarrow> t\"\n  shows \"\\<And>X. proc_deps C \\<Gamma> \\<subseteq> X \\<Longrightarrow> \\<Gamma> |` X \\<turnstile> \\<langle>C,s\\<rangle> \\<Rightarrow> t\"\nusing exec\nproof induct\n  case (Call p C s t) thus ?case\n  using proc_deps_restrict [of C \\<Gamma> p]\n    by (auto intro!: exec_other_intros split: option.splits)\nnext\n  case (DynCom f s t) thus ?case\n    by - (rule exec.intros, simp, blast)\nqed (auto intro: exec_other_intros)\n\nlemma exec_restrict_eq:\n  \"\\<Gamma> |` proc_deps C \\<Gamma> \\<turnstile> \\<langle>C,s\\<rangle> \\<Rightarrow> t = \\<Gamma> \\<turnstile> \\<langle>C,s\\<rangle> \\<Rightarrow> t\"\n  by (fast intro: exec_restrict exec_restrict2)\n\nlemma mem_safe_restrict:\n  \"mem_safe C \\<Gamma> = mem_safe C (\\<Gamma> |` proc_deps C \\<Gamma>)\"\n  by (auto simp: mem_safe_def restrict_safe_def restrict_safe_OK_def\n                 exec_restrict_eq exec_fatal_def\n           split: xstate.splits)\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/c-parser/umm_heap/SepFrame.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926665999540698, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.25720631918841336}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\nsection \"Additional Syntax for Word Bit Operations\"\n\ntheory Word_Syntax\nimports\n  \"~~/src/HOL/Word/WordBitwise\"\n  WordBitwise_Signed\n  Hex_Words\n  Norm_Words\n  Word_Type_Syntax\nbegin\n\ntext \\<open>Additional bit and type syntax that forces word types.\\<close>\n\ntype_synonym word8 = \"8 word\"\ntype_synonym word16 = \"16 word\"\ntype_synonym word32 = \"32 word\"\ntype_synonym word64 = \"64 word\"\n\nlemma len8: \"len_of (x :: 8 itself) = 8\" by simp\nlemma len16: \"len_of (x :: 16 itself) = 16\" by simp\nlemma len32: \"len_of (x :: 32 itself) = 32\" by simp\nlemma len64: \"len_of (x :: 64 itself) = 64\" by simp\n\n\nabbreviation\n  wordNOT  :: \"'a::len0 word \\<Rightarrow> 'a word\"      (\"~~ _\" [70] 71)\nwhere\n  \"~~ x == NOT x\"\n\nabbreviation\n  wordAND  :: \"'a::len0 word \\<Rightarrow> 'a word \\<Rightarrow> 'a word\" (infixr \"&&\" 64)\nwhere\n  \"a && b == a AND b\"\n\nabbreviation\n  wordOR   :: \"'a::len0 word \\<Rightarrow> 'a word \\<Rightarrow> 'a word\" (infixr \"||\"  59)\nwhere\n  \"a || b == a OR b\"\n\nabbreviation\n  wordXOR  :: \"'a::len0 word \\<Rightarrow> 'a word \\<Rightarrow> 'a word\" (infixr \"xor\" 59)\nwhere\n  \"a xor b == a XOR b\"\n\n(* testing for presence of word_bitwise *)\nlemma \"((x :: word32) >> 3) AND 7 = (x AND 56) >> 3\"\n  by word_bitwise\n\n(* FIXME: move to Word distribution *)\nlemma bin_nth_minus_Bit0[simp]:\n  \"0 < n \\<Longrightarrow> bin_nth (numeral (num.Bit0 w)) n = bin_nth (numeral w) (n - 1)\"\n  by (cases n; simp)\n\nlemma bin_nth_minus_Bit1[simp]:\n  \"0 < n \\<Longrightarrow> bin_nth (numeral (num.Bit1 w)) n = bin_nth (numeral w) (n - 1)\"\n  by (cases n; simp)\n\nend\n", "meta": {"author": "z5146542", "repo": "TOR", "sha": "9a82d491288a6d013e0764f68e602a63e48f92cf", "save_path": "github-repos/isabelle/z5146542-TOR", "path": "github-repos/isabelle/z5146542-TOR/TOR-9a82d491288a6d013e0764f68e602a63e48f92cf/checker-verification/autocorres-1.4/lib/Word_Lib/Word_Syntax.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.4804786780479071, "lm_q1q2_score": 0.25710338561202667}}
{"text": "section \\<open>System specification\\<close>\n\ntext \\<open>This section formalizes the CoCon system as an I/O automaton.\nWe call the inputs ``actions''.\\<close>\n\ntheory System_Specification\nimports Prelim\nbegin\n\nsubsection \\<open>System state\\<close>\n\n\ntext \\<open>The superuser of the system is called ``voronkov'',\nas a form acknowledgement for our inspiration from EasyChair\nwhen creating CoCon.\n\\<close>\n\nrecord state =\n  confIDs :: \"confID list\"\n  conf :: \"confID \\<Rightarrow> conf\"\n  (*  *)\n  userIDs :: \"userID list\"\n  pass :: \"userID \\<Rightarrow> password\"\n  user :: \"userID \\<Rightarrow> user\"\n  roles :: \"confID \\<Rightarrow> userID \\<Rightarrow> role list\"\n  (*  *)\n  paperIDs :: \"confID \\<Rightarrow> paperID list\"\n  paper :: \"paperID \\<Rightarrow> paper\"\n  (*  *)\n  pref :: \"userID \\<Rightarrow> paperID \\<Rightarrow> preference\" (* preference, including eventual conflicts *)\n  (*  *)\n  voronkov :: \"userID\"\n  (*  *)\n  news :: \"confID \\<Rightarrow> string list\"\n  phase :: \"confID \\<Rightarrow> phase\" (* the current phase *)\n  (*  *)\n\n\n(* Note: Some of the fields are redundant, e.g., paperIDs can in principle be recovered from \"roles\";\nhowever, this and other redundant fields are used very often, so it is efficient to keep them *)\n\n\n(* Various discriminators (\"is\") and selectors (\"get\") on the database: *)\nabbreviation isPC :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> bool\" (*  program committee (PC) membership *) where\n\"isPC s confID uID \\<equiv> PC \\<in>\\<in> roles s confID uID\"\nabbreviation isChair :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> bool\" (* being one of the conference chairs *)  where\n\"isChair s confID uID \\<equiv> Chair \\<in>\\<in> roles s confID uID\"\nabbreviation isAut :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> paperID \\<Rightarrow> bool\" (*  authorship of a certain paper *) where\n\"isAut s confID uID papID \\<equiv> Aut papID \\<in>\\<in> roles s confID uID\"\ndefinition isAutSome :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> bool\" (*  authorship of some paper *) where\n\"isAutSome s confID uID \\<equiv> list_ex (isAut s confID uID) (paperIDs s confID)\"\n(* all the authors of a given paper: *)\ndefinition authors :: \"state \\<Rightarrow> confID \\<Rightarrow> paperID \\<Rightarrow> userID list\" where\n\"authors s confID papID \\<equiv> filter (\\<lambda> uID. isAut s confID uID papID) (userIDs s)\"\nabbreviation isRevNth :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> paperID \\<Rightarrow> nat \\<Rightarrow> bool\" (*  paper reviewer (nth review) *)\nwhere\n\"isRevNth s confID uID papID n \\<equiv> Rev papID n \\<in>\\<in> roles s confID uID\"\ndefinition isRev :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> paperID \\<Rightarrow> bool\" (*  paper reviewer *) where\n\"isRev s confID uID papID \\<equiv> list_ex (isRevRoleFor papID) (roles s confID uID)\"\n(* Get the reviewer role for a certain triple (user, conference, paper), if any: *)\ndefinition getRevRole :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> paperID \\<Rightarrow> role option\" where\n\"getRevRole s confID uID papID \\<equiv> List.find (isRevRoleFor papID) (roles s confID uID)\"\n(* get the n-th review of a paper *)\ndefinition getNthReview :: \"state \\<Rightarrow> paperID \\<Rightarrow> nat \\<Rightarrow> review\" where\n\"getNthReview s papID n \\<equiv> (reviewsPaper (paper s papID))!n\"\n(* get all the paper IDs (for all conferences) from the system: *)\ndefinition getAllPaperIDs :: \"state \\<Rightarrow> paperID list\" where\n\"getAllPaperIDs s \\<equiv> concat [paperIDs s confID. confID \\<leftarrow> confIDs s]\"\ndefinition getReviewIndex :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> paperID \\<Rightarrow> nat\" where\n\"getReviewIndex s confID uID papID \\<equiv>\n case getRevRole s confID uID papID of Some (Rev papID' n) \\<Rightarrow> n\"\n(* get, for a conference and a paper, the reviews together with the IDs of the reviewers: *)\ndefinition getReviewersReviews :: \"state \\<Rightarrow> confID \\<Rightarrow> paperID \\<Rightarrow> (userID * review) list\" where\n\"getReviewersReviews s confID papID \\<equiv>\n [(uID, getNthReview s papID (getReviewIndex s confID uID papID)).\n    uID \\<leftarrow> userIDs s,\n    isRev s confID uID papID\n ]\"\n\n(* Not used in the implementation: *)\ndefinition isAUT :: \"state \\<Rightarrow> userID \\<Rightarrow> paperID \\<Rightarrow> bool\" where\n\"isAUT s uID papID \\<equiv> \\<exists> confID. isAut s confID uID papID\"\ndefinition isREVNth :: \"state \\<Rightarrow> userID \\<Rightarrow> paperID \\<Rightarrow> nat \\<Rightarrow> bool\" where\n\"isREVNth s uID papID n \\<equiv> \\<exists> confID. isRevNth s confID uID papID n\"\n\n\nlemma isRev_getRevRole:\nassumes \"isRev s confID uID papID\"\nshows \"getRevRole s confID uID papID \\<noteq> None\"\nusing assms list_ex_find unfolding isRev_def getRevRole_def by auto\n\nlemma getRevRole_Some:\nassumes \"getRevRole s confID uID papID = Some role\"\nshows \"\\<exists> n. role = Rev papID n\"\nusing assms unfolding getRevRole_def unfolding find_Some_iff apply (cases role, auto)\nby (metis isRevRoleFor.simps)+\n\nlemma isRev_getRevRole2:\nassumes \"isRev s confID uID papID\"shows \"\\<exists> n. getRevRole s confID uID papID = Some (Rev papID n)\"\nusing assms getRevRole_Some by (cases \"getRevRole s confID uID papID\") (auto simp: isRev_getRevRole)\n\nlemma isRev_imp_isRevNth_getReviewIndex:\nassumes \"isRev s confID uID papID\"\nshows \"isRevNth s confID uID papID (getReviewIndex s confID uID papID)\"\nproof-\n  obtain n where 1: \"getRevRole s confID uID papID = Some (Rev papID n)\"\n  using isRev_getRevRole2[OF assms] by auto\n  hence \"isRevNth s confID uID papID n\"\n  unfolding getRevRole_def unfolding find_Some_iff by auto\n  moreover have \"getReviewIndex s confID uID papID = n\" using 1 unfolding getReviewIndex_def by simp\n  ultimately show ?thesis by auto\nqed\n\n(* nonexecutable, but more useful version of the definition: *)\nlemma isRev_def2:\n\"isRev s confID uID papID \\<longleftrightarrow> (\\<exists> n. isRevNth s confID uID papID n)\" (is \"?A \\<longleftrightarrow> ?B\")\nproof\n  assume ?A thus ?B using isRev_imp_isRevNth_getReviewIndex by blast\nnext\n  assume ?B thus ?A unfolding isRev_def list_ex_iff by force\nqed\n\n(* more precise definition, but not always needed: *)\nlemma isRev_def3:\n\"isRev s confID uID papID \\<longleftrightarrow> isRevNth s confID uID papID (getReviewIndex s confID uID papID)\"\nby (metis isRev_def2 isRev_imp_isRevNth_getReviewIndex)\n\nlemma getFreshPaperID_getAllPaperIDs[simp]:\n  assumes \"confID \\<in>\\<in> confIDs s\"\n  shows \"\\<not> getFreshPaperID (getAllPaperIDs s) \\<in>\\<in> paperIDs s confID\"\n  using assms getFreshPaperID[of \"getAllPaperIDs s\"]\n  by (auto simp: getAllPaperIDs_def)\n\nlemma getRevRole_Some_Rev:\n\"getRevRole s cid uid pid = Some (Rev pid' n) \\<Longrightarrow> pid' = pid\"\nby (metis getRevRole_Some role.inject)\n\nlemma getRevRole_Some_Rev_isRevNth:\n\"getRevRole s cid uid pid = Some (Rev pid' n) \\<Longrightarrow> isRevNth s cid uid pid n\"\n  unfolding getRevRole_def find_Some_iff\n  apply (elim exE)\n  subgoal for i\n    apply(cases \"roles s cid uid ! i\")\n       apply auto\n    by (metis nth_mem)\n  done\n\n(* This assumes that the list of conference IDs has exactly one element: *)\ndefinition IDsOK :: \"state \\<Rightarrow> confID list \\<Rightarrow> userID list \\<Rightarrow> paperID list \\<Rightarrow> bool\"\nwhere\n\"IDsOK s cIDs uIDs papIDs \\<equiv>\n list_all (\\<lambda> confID. confID \\<in>\\<in> confIDs s) cIDs \\<and>\n list_all (\\<lambda> uID. uID \\<in>\\<in> userIDs s) uIDs \\<and>\n list_all (\\<lambda> papID. papID \\<in>\\<in> paperIDs s (hd cIDs)) papIDs\"\n\n\nsubsection \\<open>The actions\\<close>\n\nsubsubsection\\<open>Initialization of the system\\<close>\n\ndefinition istate :: state\nwhere\n\"istate \\<equiv>\n \\<lparr>\n  confIDs = [],\n  conf = (\\<lambda> confID. emptyConf),\n  userIDs = [voronkovUserID],\n  pass = (\\<lambda> uID. emptyPass),\n  user = (\\<lambda> uID. emptyUser),\n  roles = (\\<lambda> confID uID. []),\n  paperIDs = (\\<lambda> confID. []),\n  paper = (\\<lambda> papID. emptyPaper),\n  pref = (\\<lambda> uID papID. NoPref),\n  voronkov = voronkovUserID,\n  news = (\\<lambda> confID. []),\n  phase = (\\<lambda> confID. noPH)\n \\<rparr>\"\n\n\n\nsubsubsection\\<open>Actions unbound by any existing conference (with its phases)\\<close>\n\n(* Create new user (user) in the system: *)\n(* if given user ID already taken, generate a fresh one *)\ndefinition createUser ::  \"state \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> string \\<Rightarrow> string \\<Rightarrow> string \\<Rightarrow> state\"\nwhere\n\"createUser s uID p name info email \\<equiv>\n let uIDs = userIDs s\n in\n s \\<lparr>userIDs := uID # uIDs,\n    user := (user s) (uID := User name info email),\n    pass := (pass s) (uID := p)\\<rparr>\"\n(* the the web interface, one should prompt the user multiple times for entering\n an unused ID *)\n\ndefinition e_createUser :: \"state \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> string \\<Rightarrow> string \\<Rightarrow> string \\<Rightarrow> bool\" where\n\"e_createUser s uID p name info email \\<equiv>\n \\<not> uID \\<in>\\<in> userIDs s\"\n\n(* updates information for user (himself), including password: *)\ndefinition updateUser :: \"state \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> password \\<Rightarrow> string \\<Rightarrow> string \\<Rightarrow> string \\<Rightarrow> state\"\nwhere\n\"updateUser s uID p p' name info email \\<equiv>\n s \\<lparr>user := (user s) (uID := User name info email),\n    pass := (pass s) (uID := p')\\<rparr>\"\n\ndefinition e_updateUser :: \"state \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> password \\<Rightarrow> string \\<Rightarrow> string \\<Rightarrow> string \\<Rightarrow> bool\"\nwhere\n\"e_updateUser s uID p p' name info email \\<equiv>\n IDsOK s [] [uID] [] \\<and> pass s uID = p\"\n\n\n(* read if the current user is the voronkov: *)\ndefinition readAmIVoronkov :: \"state \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> bool\"\nwhere\n\"readAmIVoronkov s uID p \\<equiv>\n uID = voronkov s \"\n\ndefinition e_readAmIVoronkov :: \"state \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> bool\"\nwhere\n\"e_readAmIVoronkov s uID p \\<equiv>\n IDsOK s [] [uID] [] \\<and> pass s uID = p\"\n\n(* Read the name and info of a user (except for password): *)\n(* There are several needs for this primitive action:\n   -- either I read my own info\n   -- or I am an author, and therefore I read the PC members' name and info to declare a conflict\n   -- or I am a chair, and therefore I read all PC members's info to assign papers for reviewing\n   -- or I am an author and need to add coauthors\n*)\ndefinition readUser :: \"state \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> userID \\<Rightarrow> string * string * string\"\nwhere\n\"readUser s uID p uID' \\<equiv>\n case user s uID' of User name info email \\<Rightarrow> (name, info, email)\"\n\ndefinition e_readUser :: \"state \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> userID \\<Rightarrow> bool\"\nwhere\n\"e_readUser s uID p uID' \\<equiv>\n IDsOK s [] [uID,uID'] [] \\<and> pass s uID = p\"\n\n(* Request for a new conference *)\n\n(* The request takes place by creating a new conference with ID assigned as above for users.\nThe conference will remain in the default \"noPH\" phase until aproval.\nThe creator becomes a chair (a fortiori a PC member). *)\ndefinition createConf :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> string \\<Rightarrow> string \\<Rightarrow> state\"\nwhere\n\"createConf s confID uID p name info \\<equiv>\n let confIDs = confIDs s\n in\n s \\<lparr>confIDs := confID # confIDs,\n    conf := (conf s) (confID := Conf name info),\n    roles := fun_upd2 (roles s) confID uID [PC,Chair]\n   \\<rparr>\"\n(* again, in the web interface the user will be prompted repeatedly until he gets it right *)\n\ndefinition e_createConf :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> string \\<Rightarrow> string \\<Rightarrow> bool\"\nwhere\n\"e_createConf s confID uID p name info \\<equiv>\n IDsOK s [] [uID] [] \\<and> pass s uID = p \\<and>\n \\<not> confID \\<in>\\<in> confIDs s\"\n\n(* Read the info of a conference: any user can do it  *)\ndefinition readConf :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> string * string * (role list) * phase\"\nwhere\n\"readConf s confID uID p \\<equiv>\n (nameConf (conf s confID), infoConf (conf s confID),\n  [rl \\<leftarrow> roles s confID uID. \\<not> isRevRole rl], phase s confID)\"\n\ndefinition e_readConf :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> bool\"\nwhere\n\"e_readConf s confID uID p \\<equiv>\n IDsOK s [confID] [uID] [] \\<and> pass s uID = p\"\n\n(* list all conferences: *)\ndefinition listConfs :: \"state \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> confID list\"\nwhere\n\"listConfs s uID p \\<equiv>\n confIDs s\"\n\ndefinition e_listConfs :: \"state \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> bool\"\nwhere\n\"e_listConfs s uID p \\<equiv>\n IDsOK s [] [uID] [] \\<and> pass s uID = p \\<and>\n uID = voronkov s\"\n\n(* list conferences awaiting approval: *)\ndefinition listAConfs :: \"state \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> confID list\"\nwhere\n\"listAConfs s uID p \\<equiv>\n [confID. confID \\<leftarrow> confIDs s, phase s confID = noPH]\"\n\ndefinition e_listAConfs :: \"state \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> bool\"\nwhere\n\"e_listAConfs s uID p \\<equiv>\n IDsOK s [] [uID] [] \\<and> pass s uID = p \\<and>\n uID = voronkov s\"\n\n(* list conferences in the submission phase: any user can see this *)\ndefinition listSConfs :: \"state \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> confID list\"\nwhere\n\"listSConfs s uID p \\<equiv>\n [confID. confID \\<leftarrow> confIDs s, phase s confID = subPH]\"\n\ndefinition e_listSConfs :: \"state \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> bool\"\nwhere\n\"e_listSConfs s uID p \\<equiv>\n IDsOK s [] [uID] [] \\<and> pass s uID = p\"\n\n(* list my conferences: *)\ndefinition listMyConfs :: \"state \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> confID list\"\nwhere\n\"listMyConfs s uID p \\<equiv>\n [confID. confID \\<leftarrow> confIDs s , roles s confID uID \\<noteq> []]\"\n\ndefinition e_listMyConfs :: \"state \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> bool\"\nwhere\n\"e_listMyConfs s uID p \\<equiv>\n IDsOK s [] [uID] [] \\<and> pass s uID = p\"\n\n(* list all users of the system (useful when assigning coauthors to papers): *)\ndefinition listAllUsers :: \"state \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> userID list\"\nwhere\n\"listAllUsers s uID p \\<equiv>\n userIDs s\"\n\ndefinition e_listAllUsers :: \"state \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> bool\"\nwhere\n\"e_listAllUsers s uID p \\<equiv>\n IDsOK s [] [uID] [] \\<and> pass s uID = p\"\n\n(* list all paper IDs of the system (useful whn generating a fresh paper ID): *)\ndefinition listAllPapers :: \"state \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID list\"\nwhere\n\"listAllPapers s uID p \\<equiv>\n getAllPaperIDs s\"\n\ndefinition e_listAllPapers :: \"state \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> bool\"\nwhere\n\"e_listAllPapers s uID p \\<equiv>\n IDsOK s [] [uID] [] \\<and> pass s uID = p\"\n\n\nsubsubsection\\<open>Actions available in the noPH phase\\<close>\n\n(* Approving a new conference should be done by the voronkov, and happens by changing\nthe phase from noPH to setPH.\nThis is an update action: it updates the conference approval status\nNote that, after approval, the voronkov should not have further access to the conference:\nhe can only act if the phase is noPH. *)\ndefinition updateConfA :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> state\"\nwhere\n\"updateConfA s confID uID p \\<equiv>\n s \\<lparr>phase := (phase s) (confID := setPH)\\<rparr>\"\n\ndefinition e_updateConfA :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> bool\"\nwhere\n\"e_updateConfA s confID uID p \\<equiv>\n IDsOK s [confID] [uID] [] \\<and> pass s uID = p \\<and>\n uID = voronkov s \\<and> phase s confID = noPH\"\n\n\nsubsubsection\\<open>Actions available in the setPH phase\\<close>\n\n(* make a user a PC member *)\ndefinition createPC :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> userID \\<Rightarrow> state\"\nwhere\n\"createPC s confID uID p uID' \\<equiv>\n let rls = roles s confID uID'\n in\n s \\<lparr>roles := fun_upd2 (roles s) confID uID' (List.insert PC rls)\\<rparr>\"\n\ndefinition e_createPC :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> userID \\<Rightarrow> bool\"\nwhere\n\"e_createPC s confID uID p uID' \\<equiv>\n let uIDs = userIDs s\n in\n IDsOK s [confID] [uID,uID'] [] \\<and> pass s uID = p \\<and>\n phase s confID = setPH \\<and> isChair s confID uID\"\n\n(* make a user a chair (a fortiori a PC member) *)\ndefinition createChair :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> userID \\<Rightarrow> state\"\nwhere\n\"createChair s confID uID p uID' \\<equiv>\n let rls = roles s confID uID'\n in\n s \\<lparr>roles := fun_upd2 (roles s) confID uID' (List.insert PC (List.insert Chair rls))\\<rparr>\"\n\ndefinition e_createChair :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> userID \\<Rightarrow> bool\"\nwhere\n\"e_createChair s confID uID p uID' \\<equiv>\n let uIDs = userIDs s\n in\n IDsOK s [confID] [uID,uID'] [] \\<and> pass s uID = p \\<and>\n phase s confID = setPH \\<and> isChair s confID uID\"\n\n\nsubsubsection\\<open>Actions available starting from the setPH phase\\<close>\n\ndefinition updatePhase :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> phase \\<Rightarrow> state\" where\n\"updatePhase s confID uID p ph \\<equiv>\n s \\<lparr>phase := (phase s) (confID := ph)\\<rparr>\"\n\ndefinition e_updatePhase :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> phase \\<Rightarrow> bool\" where\n\"e_updatePhase s confID uID p ph \\<equiv>\n IDsOK s [confID] [uID] [] \\<and> pass s uID = p \\<and>\n phase s confID \\<ge> setPH \\<and> phase s confID < closedPH \\<and> isChair s confID uID \\<and>\n ph = SucPH (phase s confID)\"\n(* The phase move is only allowed if the indicated phase is the successor of the current phase.\n   Yet, in the kernel we also require the explicit indication of the phase for being able to track\n   it for verification.  *)\n(* In the web interface, the user is prompted with the question\n\"Are you sure you want to move to the next phase?\" *)\n\n(* Add an event, i.e., undestructively update the news: *)\ndefinition uupdateNews :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> string \\<Rightarrow> state\"\nwhere\n\"uupdateNews s confID uID p ev \\<equiv>\n let evs = news s confID\n in\n s \\<lparr>news := (news s) (confID := ev # evs)\\<rparr>\"\n\ndefinition e_uupdateNews :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> string \\<Rightarrow> bool\"\nwhere\n\"e_uupdateNews s confID uID p ev \\<equiv>\n IDsOK s [confID] [uID] [] \\<and> pass s uID = p \\<and>\n phase s confID \\<ge> setPH \\<and> phase s confID < closedPH \\<and> isChair s confID uID\"\n\ndefinition readNews :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> string list\"\nwhere\n\"readNews s confID uID p \\<equiv>\n news s confID\"\n\ndefinition e_readNews :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> bool\"\nwhere\n\"e_readNews s confID uID p \\<equiv>\n IDsOK s [confID] [uID] [] \\<and> pass s uID = p \\<and>\n phase s confID \\<ge> setPH \\<and> isPC s confID uID\"\n\n(* list the committee members: *)\ndefinition listPC :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> userID list\"\nwhere\n\"listPC s confID uID p \\<equiv>\n [uID. uID \\<leftarrow> userIDs s, isPC s confID uID]\"\n\ndefinition e_listPC :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> bool\"\nwhere\n\"e_listPC s confID uID p \\<equiv>\n IDsOK s [confID] [uID] [] \\<and> pass s uID = p \\<and>\n (phase s confID \\<ge> subPH \\<or> (phase s confID \\<ge> setPH \\<and> isChair s confID uID))\"\n\n(* list the chairs: *)\ndefinition listChair :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> userID list\"\nwhere\n\"listChair s confID uID p \\<equiv>\n [uID. uID \\<leftarrow> userIDs s, isChair s confID uID]\"\n\ndefinition e_listChair :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> bool\"\nwhere\n\"e_listChair s confID uID p \\<equiv>\n IDsOK s [confID] [uID] [] \\<and> pass s uID = p \\<and>\n (phase s confID \\<ge> subPH \\<or> (phase s confID \\<ge> setPH \\<and> isChair s confID uID))\"\n\n\nsubsubsection\\<open>Actions available in the subPH phase\\<close>\n\n(* create new paper: *)\ndefinition createPaper :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> string \\<Rightarrow> string \\<Rightarrow> state\"\nwhere\n\"createPaper s confID uID p papID title abstract \\<equiv>\n let papIDs = paperIDs s confID;\n     rls = roles s confID uID\n in\n s \\<lparr>paperIDs := (paperIDs s) (confID := papID # papIDs),\n    paper := (paper s) (papID := Paper title abstract NoPContent [] (Dis []) []),\n    roles := fun_upd2 (roles s) confID uID (List.insert (Aut papID) rls),\n    pref :=  fun_upd2 (pref s) uID papID Conflict\\<rparr>\"\n(* this contains an update to the preference too, to make sure that a user does not end up\nreviewing his own paper! note that preference can be set even if the author is not a reviewer,\nwhich is OK*)\n\ndefinition e_createPaper :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> string \\<Rightarrow> string \\<Rightarrow> bool\"\nwhere\n\"e_createPaper s confID uID p papID name info \\<equiv>\n IDsOK s [confID] [uID] [] \\<and> pass s uID = p \\<and>\n phase s confID = subPH \\<and>\n \\<not> papID \\<in>\\<in> getAllPaperIDs s\"\n\n(* add author to a paper: only an author can do this *)\ndefinition createAuthor :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> userID \\<Rightarrow> state\"\nwhere\n\"createAuthor s confID uID p papID uID' \\<equiv>\n let rls = roles s confID uID'\n in\n s \\<lparr>roles := fun_upd2 (roles s) confID uID' (List.insert (Aut papID) rls),\n    pref :=  fun_upd2 (pref s) uID' papID Conflict\\<rparr>\"\n(* again, preference is set to Conflict *)\n\ndefinition e_createAuthor :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> userID \\<Rightarrow> bool\"\nwhere\n\"e_createAuthor s confID uID p papID uID' \\<equiv>\n IDsOK s [confID] [uID,uID'] [papID] \\<and> pass s uID = p \\<and>\n phase s confID = subPH \\<and> isAut s confID uID papID \\<and> uID \\<noteq> uID'\"\n\n(* update name (title) and info of paper: *)\ndefinition updatePaperTA :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> string \\<Rightarrow> string \\<Rightarrow> state\"\nwhere\n\"updatePaperTA s confID uID p papID title abstract \\<equiv>\n case paper s papID of Paper title' abstract' pc reviews dis decs \\<Rightarrow>\n s \\<lparr>paper := (paper s) (papID := Paper title abstract pc reviews dis decs)\\<rparr>\"\n\ndefinition e_updatePaperTA :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> string \\<Rightarrow> string \\<Rightarrow> bool\"\nwhere\n\"e_updatePaperTA s confID uID p papID name info \\<equiv>\n IDsOK s [confID] [uID] [papID] \\<and> pass s uID = p \\<and>\n phase s confID = subPH \\<and> isAut s confID uID papID\"\n\n(* upload new version of paper content: *)\ndefinition updatePaperC :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> pcontent \\<Rightarrow> state\"\nwhere\n\"updatePaperC s confID uID p papID pc \\<equiv>\n case paper s papID of Paper title abstract pc' reviews dis decs \\<Rightarrow>\n s \\<lparr>paper := (paper s) (papID := Paper title abstract pc reviews dis decs)\\<rparr>\"\n\ndefinition e_updatePaperC :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> pcontent \\<Rightarrow> bool\"\nwhere\n\"e_updatePaperC s confID uID p papID pc \\<equiv>\n IDsOK s [confID] [uID] [papID] \\<and> pass s uID = p \\<and>\n phase s confID = subPH \\<and> isAut s confID uID papID\"\n\n(* declare conflict of the authored paper with a committee member*)\ndefinition createConflict :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> userID \\<Rightarrow> state\"\nwhere\n\"createConflict s confID uID p papID uID' \\<equiv>\n s \\<lparr>pref := fun_upd2 (pref s) uID' papID Conflict\\<rparr>\"\n\ndefinition e_createConflict :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> userID \\<Rightarrow> bool\"\nwhere\n\"e_createConflict s confID uID p papID uID' \\<equiv>\n IDsOK s [confID] [uID,uID'] [papID] \\<and> pass s uID = p \\<and>\n phase s confID = subPH \\<and> isAut s confID uID papID \\<and> isPC s confID uID'\"\n\n\nsubsubsection\\<open>Actions available starting from the subPH phase\\<close>\n\n(* read a paper's title, abstract and authors: *)\ndefinition readPaperTAA :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow>\n    (string * string *  userID list)\"\nwhere\n\"readPaperTAA s confID uID p papID \\<equiv>\n case paper s papID of Paper title abstract pc reviews dis decs \\<Rightarrow>\n   (title, abstract, [uID. uID \\<leftarrow> userIDs s , isAut s confID uID papID])\"\n\ndefinition e_readPaperTAA :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> bool\"\nwhere\n\"e_readPaperTAA s confID uID p papID \\<equiv>\n IDsOK s [confID] [uID] [papID] \\<and> pass s uID = p \\<and>\n phase s confID \\<ge> subPH \\<and> (isAut s confID uID papID \\<or> isPC s confID uID)\"\n\n(* read a paper's content: *)\ndefinition readPaperC :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> pcontent\"\nwhere\n\"readPaperC s confID uID p papID \\<equiv>\n case paper s papID of Paper title abstract pc reviews dis decs \\<Rightarrow> pc\"\n\ndefinition e_readPaperC :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> bool\"\nwhere\n\"e_readPaperC s confID uID p papID \\<equiv>\n IDsOK s [confID] [uID] [papID] \\<and> pass s uID = p \\<and>\n (\n  phase s confID \\<ge> subPH \\<and> isAut s confID uID papID \\<or>\n  phase s confID \\<ge> bidPH \\<and> isPC s confID uID\n )\"\n\n(* Note that the difference between the enabledness of readPaperTAA and that of readPaperC is\nthat the latter is allowed for the PC members only in the bidding phase.  *)\n\n(* list all papers associated to a conference (with which the committee member does not have conflict): *)\ndefinition listPapers :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID list\"\nwhere\n\"listPapers s confID uID p \\<equiv>\n let paps = paper s in\n [papID. papID \\<leftarrow> paperIDs s confID]\"\n\ndefinition e_listPapers :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> bool\"\nwhere\n\"e_listPapers s confID uID p \\<equiv>\n IDsOK s [confID] [uID] [] \\<and> pass s uID = p \\<and>\n phase s confID \\<ge> subPH \\<and> isPC s confID uID\"\n\n(* list my (authored) papers: *)\ndefinition listMyPapers :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID list\"\nwhere\n\"listMyPapers s confID uID p \\<equiv>\n let paps = paper s in\n [papID. papID \\<leftarrow> paperIDs s confID, isAut s confID uID papID]\"\n\ndefinition e_listMyPapers :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> bool\"\nwhere\n\"e_listMyPapers s confID uID p \\<equiv>\n IDsOK s [confID] [uID] [] \\<and> pass s uID = p \\<and>\n phase s confID \\<ge> subPH\"\n\n\nsubsubsection\\<open>Actions available in the bidPH phase\\<close>\n\n(* update (my) preference: *)\ndefinition updatePref :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> preference \\<Rightarrow> state\"\nwhere\n\"updatePref s confID uID p papID pr \\<equiv>\n s \\<lparr>pref := fun_upd2 (pref s) uID papID pr\\<rparr>\"\n\ndefinition e_updatePref :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> preference \\<Rightarrow> bool\"\nwhere\n\"e_updatePref s confID uID p papID pr \\<equiv>\n IDsOK s [confID] [uID] [papID] \\<and> pass s uID = p \\<and>\n phase s confID = bidPH \\<and> isPC s confID uID \\<and>\n \\<not> isAut s confID uID papID\"\n(* note: if an author of the paper, conflict was marked in the first place,\n   and updating is not allowed *)\n\n\nsubsubsection\\<open>Actions available starting from the bidPH phase\\<close>\n\n(* read (my) preference: *)\ndefinition readPref :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> preference\"\nwhere\n\"readPref s confID uID p papID \\<equiv>\n pref s uID papID\"\n\ndefinition e_readPref :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> bool\"\nwhere\n\"e_readPref s confID uID p papID \\<equiv>\n IDsOK s [confID] [uID] [papID] \\<and> pass s uID = p \\<and>\n phase s confID \\<ge> bidPH \\<and> isPC s confID uID\"\n\n\nsubsubsection\\<open>Actions available in the revPH phase\\<close>\n\n(* read preferences of a committee member (useful for the chair to read the preferences of the\ncommittee members: *)\n\ndefinition readPrefOfPC :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> userID \\<Rightarrow> preference\"\nwhere\n\"readPrefOfPC s confID uID p papID uID' \\<equiv>\n pref s uID' papID\"\n\ndefinition e_readPrefOfPC :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> userID\\<Rightarrow> bool\"\nwhere\n\"e_readPrefOfPC s confID uID p papID uID' \\<equiv>\n IDsOK s [confID] [uID,uID'] [papID] \\<and> pass s uID = p \\<and>\n (phase s confID \\<ge> bidPH \\<and> isChair s confID uID \\<and> isPC s confID uID'\n  \\<or>\n  phase s confID = subPH \\<and> isAut s confID uID papID)\"\n(* unique violation of monotonicity for read actions: an author can read the preferences of the PC chair\n  in the submission phase, but not later, as later they will have been updated by the chairs *)\n\n(* create a review and assign a reviewer: *)\ndefinition createReview :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> userID \\<Rightarrow> state\"\nwhere\n\"createReview s confID uID p papID uID' \\<equiv>\n case paper s papID of Paper title abstract pc reviews dis decs \\<Rightarrow>\n   let rls = roles s confID uID'; n = length (reviewsPaper (paper s papID));\n       reviews' = reviews @ [emptyReview]\n   in\n   s \\<lparr>roles := fun_upd2 (roles s) confID uID' (List.insert (Rev papID n) rls),\n      paper := fun_upd (paper s) papID (Paper title abstract pc reviews' dis decs)\n     \\<rparr>\"\n(* note: the new review is added at the end, in order not to disrupt the indexing of the other reviews *)\n\ndefinition e_createReview :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> userID \\<Rightarrow> bool\"\nwhere\n\"e_createReview s confID uID p papID uID' \\<equiv>\n IDsOK s [confID] [uID,uID'] [papID] \\<and> pass s uID = p \\<and>\n phase s confID = revPH \\<and>\n isChair s confID uID \\<and> pref s uID papID \\<noteq> Conflict \\<and>\n isPC s confID uID' \\<and> \\<not> isRev s confID uID' papID \\<and> pref s uID' papID \\<noteq> Conflict\"\n\n(* update the review that I write: *)\ndefinition updateReview ::\n\"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> nat \\<Rightarrow> rcontent \\<Rightarrow> state\"\nwhere\n\"updateReview s confID uID p papID n rc \\<equiv>\n case paper s papID of Paper title abstract pc reviews dis decs \\<Rightarrow>\n   let review = [rc]; reviews' = list_update reviews n review\n   in\n   s \\<lparr>paper := fun_upd (paper s) papID (Paper title abstract pc reviews' dis decs)\\<rparr>\"\n\ndefinition e_updateReview ::\n\"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> nat \\<Rightarrow> rcontent \\<Rightarrow> bool\"\nwhere\n\"e_updateReview s confID uID p papID n rc \\<equiv>\n IDsOK s [confID] [uID] [papID] \\<and> pass s uID = p \\<and>\n phase s confID = revPH \\<and> isRev s confID uID papID \\<and>\n getReviewIndex s confID uID papID = n\"\n\n\nsubsubsection\\<open>Actions available starting from the revPH phase\\<close>\n\n(* read the review that I write: *)\ndefinition readMyReview :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> nat * review\"\nwhere\n\"readMyReview s confID uID p papID \\<equiv>\n case getRevRole s confID uID papID of\n   Some (Rev papID' n) \\<Rightarrow> (n, getNthReview s papID n)\"\n\ndefinition e_readMyReview :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> bool\"\nwhere\n\"e_readMyReview s confID uID p papID \\<equiv>\n IDsOK s [confID] [uID] [papID] \\<and> pass s uID = p \\<and>\n phase s confID \\<ge> revPH \\<and> isRev s confID uID papID\"\n\n(* list my assigned papers: *)\ndefinition listMyAssignedPapers :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID list\"\nwhere\n\"listMyAssignedPapers s confID uID p \\<equiv>\n let paps = paper s in\n [papID. papID \\<leftarrow> paperIDs s confID, isRev s confID uID papID]\"\n\ndefinition e_listMyAssignedPapers :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> bool\"\nwhere\n\"e_listMyAssignedPapers s confID uID p \\<equiv>\n IDsOK s [confID] [uID] [] \\<and> pass s uID = p \\<and>\n phase s confID \\<ge> revPH \\<and> isPC s confID uID\"\n\n\ndefinition listAssignedReviewers :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> userID list\"\nwhere\n\"listAssignedReviewers s confID uID p papID \\<equiv>\n [uID \\<leftarrow> userIDs s. isRev s confID uID papID]\"\n\ndefinition e_listAssignedReviewers :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> bool\"\nwhere\n\"e_listAssignedReviewers s confID uID p papID \\<equiv>\n IDsOK s [confID] [uID] [papID] \\<and> pass s uID = p \\<and>\n phase s confID \\<ge> revPH \\<and>\n isChair s confID uID \\<and> pref s uID papID \\<noteq> Conflict\"\n\n\nsubsubsection\\<open>Actions available in the disPH phase\\<close>\n\n(* undestructively update the discussion with a comment: *)\ndefinition uupdateDis :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> string \\<Rightarrow> state\"\nwhere\n\"uupdateDis s confID uID p papID comm \\<equiv>\n case paper s papID of Paper title abstract pc reviews (Dis comments) decs \\<Rightarrow>\n   s \\<lparr>paper := fun_upd (paper s) papID (Paper title abstract pc reviews (Dis (comm # comments)) decs)\\<rparr>\"\n\ndefinition e_uupdateDis :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> string \\<Rightarrow> bool\"\nwhere\n\"e_uupdateDis s confID uID p papID comm \\<equiv>\n IDsOK s [confID] [uID] [papID] \\<and> pass s uID = p \\<and>\n phase s confID = disPH \\<and> isPC s confID uID \\<and> pref s uID papID \\<noteq> Conflict\"\n\n(* correct my review during the discussion\n(instance of a undestructive update) *)\ndefinition uupdateReview ::\n\"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> nat \\<Rightarrow> rcontent \\<Rightarrow> state\"\nwhere\n\"uupdateReview s confID uID p papID n rc \\<equiv>\n case paper s papID of Paper title abstract pc reviews dis decs \\<Rightarrow>\n   let review = rc # (reviews ! n); reviews' = list_update reviews n review\n   in\n   s \\<lparr>paper := fun_upd (paper s) papID (Paper title abstract pc reviews' dis decs)\\<rparr>\"\n\ndefinition e_uupdateReview ::\n\"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> nat \\<Rightarrow> rcontent \\<Rightarrow> bool\"\nwhere\n\"e_uupdateReview s confID uID p papID n rc \\<equiv>\n IDsOK s [confID] [uID] [papID] \\<and> pass s uID = p \\<and>\n phase s confID = disPH \\<and> isRev s confID uID papID \\<and>\n getReviewIndex s confID uID papID = n\"\n\n(* update the decision for a paper (again undestructive update) : *)\ndefinition uupdateDec :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> decision \\<Rightarrow> state\"\nwhere\n\"uupdateDec s confID uID p papID dec \\<equiv>\n case paper s papID of Paper title abstract pc reviews dis decs \\<Rightarrow>\n   s \\<lparr>paper := fun_upd (paper s) papID (Paper title abstract pc reviews dis (dec # decs))\\<rparr>\"\n\ndefinition e_uupdateDec :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> decision \\<Rightarrow> bool\"\nwhere\n\"e_uupdateDec s confID uID p papID dec \\<equiv>\n IDsOK s [confID] [uID] [papID] \\<and> pass s uID = p \\<and>\n phase s confID = disPH \\<and> isChair s confID uID \\<and> pref s uID papID \\<noteq> Conflict\"\n\n\nsubsubsection\\<open>Actions available starting from the disPH phase\\<close>\n\n(* read all the reviews to a paper (including all the updates) with the IDs of the reviewers: *)\ndefinition readReviews :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> (userID * review) list\"\nwhere\n\"readReviews s confID uID p papID \\<equiv>\n getReviewersReviews s confID papID\"\n\ndefinition e_readReviews :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> bool\"\nwhere\n\"e_readReviews s confID uID p papID \\<equiv>\n IDsOK s [confID] [uID] [papID] \\<and> pass s uID = p \\<and>\n phase s confID \\<ge> disPH \\<and> isPC s confID uID \\<and> pref s uID papID \\<noteq> Conflict\"\n\n(* read the decisions (i.e., the decision history) for a paper: *)\ndefinition readDecs :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> decision list\"\nwhere\n\"readDecs s confID uID p papID \\<equiv>\n case paper s papID of Paper title abstract pc reviews dis decs \\<Rightarrow> decs\"\n\ndefinition e_readDecs :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> bool\"\nwhere\n\"e_readDecs s confID uID p papID \\<equiv>\n IDsOK s [confID] [uID] [papID] \\<and> pass s uID = p \\<and>\n phase s confID \\<ge> disPH \\<and> isPC s confID uID \\<and> pref s uID papID \\<noteq> Conflict\"\n\n(* read the discussion to a paper: *)\ndefinition readDis :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> string list\"\nwhere\n\"readDis s confID uID p papID \\<equiv>\n case paper s papID of Paper title abstract pc reviews (Dis comments) decs \\<Rightarrow> comments\"\n\ndefinition e_readDis :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> bool\"\nwhere\n\"e_readDis s confID uID p papID \\<equiv>\n IDsOK s [confID] [uID] [papID] \\<and> pass s uID = p \\<and>\n phase s confID \\<ge> disPH \\<and> isPC s confID uID \\<and> pref s uID papID \\<noteq> Conflict\"\n\n\n\nsubsubsection\\<open>Actions available starting from the notifPH phase\\<close>\n\n(* read final reviews to a paper: available to the authors and all non-conflicted PC members *)\ndefinition readFinalReviews :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> review list\"\nwhere\n\"readFinalReviews s confID uID p papID \\<equiv>\n map (\\<lambda> rev. case rev of [] \\<Rightarrow> [(NoExp,NoScore,emptyStr)]\n                        |((exp,score,comm) # rv) \\<Rightarrow> [(exp,score,comm)])\n (reviewsPaper (paper s papID))\"\n\ndefinition e_readFinalReviews :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> bool\"\nwhere\n\"e_readFinalReviews s confID uID p papID \\<equiv>\n IDsOK s [confID] [uID] [papID] \\<and> pass s uID = p \\<and>\n phase s confID \\<ge> notifPH \\<and> (isAut s confID uID papID \\<or> (isPC s confID uID \\<and> pref s uID papID \\<noteq> Conflict))\"\n\n(* read the final decision for a paper available to the authors and all PC members (including conflicted PC members):*)\ndefinition readFinalDec :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> decision\"\nwhere\n\"readFinalDec s confID uID p papID \\<equiv>\n case paper s papID of Paper title abstract pc reviews dis decs \\<Rightarrow>\n   case decs of [] \\<Rightarrow> NoDecision | dec # decs \\<Rightarrow> dec\"\n\ndefinition e_readFinalDec :: \"state \\<Rightarrow> confID \\<Rightarrow> userID \\<Rightarrow> password \\<Rightarrow> paperID \\<Rightarrow> bool\"\nwhere\n\"e_readFinalDec s confID uID p papID \\<equiv>\n IDsOK s [confID] [uID] [papID] \\<and> pass s uID = p \\<and>\n phase s confID \\<ge> notifPH \\<and> (isAut s confID uID papID \\<or> isPC s confID uID)\"\n\n\nsubsection\\<open>The step function\\<close>\n\ndatatype out =\n  outOK | outErr | (* OK and error, outputs for list, update and u-update  actions *)\n  outBool bool|\n  outSTRT \"string * string * string\" | outSTRL \"string list\" | outCONF \"string * string * role list * phase\" |\n  outPREF preference |\n  outCON pcontent |\n  outNREV \"nat * review\" | outREVL \"review list\" | outRREVL \"(userID * review) list\" |\n  outDEC \"decision\" | outDECL \"decision list\" |\n  outCIDL \"confID list\" |   outUIDL \"userID list\" | outPIDL \"paperID list\"|\n  outSTRPAL \"string * string * userID list\"\n\ndatatype cAct =\n  cUser userID password string string string\n |cConf confID userID password string string\n |cPC confID userID password userID\n |cChair confID userID password userID\n |cPaper confID userID password paperID string string\n |cAuthor confID userID password paperID userID\n |cConflict confID userID password paperID userID\n |cReview confID userID password paperID userID\n\nlemmas c_defs =\ne_createUser_def createUser_def\ne_createConf_def createConf_def\ne_createPC_def createPC_def\ne_createChair_def createChair_def\ne_createAuthor_def createAuthor_def\ne_createConflict_def createConflict_def\ne_createPaper_def createPaper_def\ne_createReview_def createReview_def\n\nfun cStep :: \"state \\<Rightarrow> cAct \\<Rightarrow> out * state\" where\n\"cStep s (cUser uID p name info email) =\n (if e_createUser s uID p name info email\n    then (outOK, createUser s uID p name info email)\n    else (outErr, s))\"\n|\n\"cStep s (cConf confID uID p name info) =\n (if e_createConf s confID uID p name info\n    then (outOK, createConf s confID uID p name info)\n    else (outErr, s))\"\n|\n\"cStep s (cPC confID uID p uID') =\n (if e_createPC s confID uID p uID'\n    then (outOK, createPC s confID uID p uID')\n    else (outErr, s))\"\n|\n\"cStep s (cChair confID uID p uID') =\n (if e_createChair s confID uID p uID'\n    then (outOK, createChair s confID uID p uID')\n    else (outErr, s))\"\n|\n\"cStep s (cPaper confID uID p papID name info) =\n (if e_createPaper s confID uID p papID name info\n    then (outOK, createPaper s confID uID p papID name info)\n    else (outErr, s))\"\n|\n\"cStep s (cAuthor confID uID p papID uID') =\n (if e_createAuthor s confID uID p papID uID'\n    then (outOK, createAuthor s confID uID p papID uID')\n    else (outErr, s))\"\n|\n\"cStep s (cConflict confID uID p papID uID') =\n (if e_createConflict s confID uID p papID uID'\n    then (outOK, createConflict s confID uID p papID uID')\n    else (outErr, s))\"\n|\n\"cStep s (cReview confID uID p papID uID') =\n (if e_createReview s confID uID p papID uID'\n    then (outOK, createReview s confID uID p papID uID')\n    else (outErr, s))\"\n\n\ndatatype uAct =\n  uUser userID password password string string string\n |uConfA confID userID password\n |uPhase confID userID password phase\n |uPaperTA confID userID password paperID string string\n |uPaperC confID userID password paperID pcontent\n |uPref confID userID password paperID preference\n |uReview confID userID password paperID nat rcontent\n\nlemmas u_defs =\ne_updateUser_def updateUser_def\ne_updateConfA_def updateConfA_def\ne_updatePhase_def updatePhase_def\ne_updatePaperTA_def updatePaperTA_def\ne_updatePaperC_def updatePaperC_def\ne_updatePref_def updatePref_def\ne_updateReview_def updateReview_def\n\nfun uStep :: \"state \\<Rightarrow> uAct \\<Rightarrow> out * state\" where\n\"uStep s (uUser uID p p' name info email) =\n (if e_updateUser s uID p p' name info email\n    then (outOK, updateUser s uID p p' name info email)\n    else (outErr, s))\"\n|\n\"uStep s (uConfA confID uID p) =\n (if e_updateConfA s confID uID p\n    then (outOK, updateConfA s confID uID p)\n    else (outErr, s))\"\n|\n\"uStep s (uPhase confID uID p ph) =\n (if e_updatePhase s confID uID p ph\n    then (outOK, updatePhase s confID uID p ph)\n    else (outErr, s))\"\n|\n\"uStep s (uPaperTA confID uID p papID name info) =\n (if e_updatePaperTA s confID uID p papID name info\n    then (outOK, updatePaperTA s confID uID p papID name info)\n    else (outErr, s))\"\n|\n\"uStep s (uPaperC confID uID p papID pc) =\n (if e_updatePaperC s confID uID p papID pc\n    then (outOK, updatePaperC s confID uID p papID pc)\n    else (outErr, s))\"\n|\n\"uStep s (uPref confID uID p papID pr) =\n (if e_updatePref s confID uID p papID pr\n    then (outOK, updatePref s confID uID p papID pr)\n    else (outErr, s))\"\n|\n\"uStep s (uReview confID uID p papID n rc) =\n (if e_updateReview s confID uID p papID n rc\n    then (outOK, updateReview s confID uID p papID n rc)\n    else (outErr, s))\"\n\n\ndatatype uuAct =\n  uuNews confID userID password string\n |uuDis confID userID password paperID string\n |uuReview confID userID password paperID nat rcontent\n |uuDec confID userID password paperID decision\n\nlemmas uu_defs =\ne_uupdateNews_def uupdateNews_def\ne_uupdateDis_def uupdateDis_def\ne_uupdateReview_def uupdateReview_def\nuupdateDec_def e_uupdateDec_def\n\nfun uuStep :: \"state \\<Rightarrow> uuAct \\<Rightarrow> out * state\" where\n\"uuStep s (uuNews confID uID p ev) =\n (if e_uupdateNews s confID uID p ev\n    then (outOK, uupdateNews s confID uID p ev)\n    else (outErr, s))\"\n|\n\"uuStep s (uuDis confID uID p papID comm) =\n (if e_uupdateDis s confID uID p papID comm\n    then (outOK, uupdateDis s confID uID p papID comm)\n    else (outErr, s))\"\n|\n\"uuStep s (uuReview confID uID p papID n rc) =\n (if e_uupdateReview s confID uID p papID n rc\n    then (outOK, uupdateReview s confID uID p papID n rc)\n    else (outErr, s))\"\n|\n\"uuStep s (uuDec confID uID p papID dec) =\n (if e_uupdateDec s confID uID p papID dec\n    then (outOK, uupdateDec s confID uID p papID dec)\n    else (outErr, s))\"\n\ndatatype rAct =\n  rAmIVoronkov userID password\n |rUser userID password userID\n |rConf confID userID password\n |rNews confID userID password\n |rPaperTAA confID userID password paperID\n |rPaperC confID userID password paperID\n |rPref confID userID password paperID\n |rMyReview confID userID password paperID\n |rReviews confID userID password paperID\n |rDecs confID userID password paperID\n |rDis confID userID password paperID\n |rFinalReviews confID userID password paperID\n |rFinalDec confID userID password paperID\n |rPrefOfPC confID userID password paperID userID\n\nlemmas r_defs =\n  readAmIVoronkov_def e_readAmIVoronkov_def\n readUser_def e_readUser_def\n readConf_def e_readConf_def\n readNews_def e_readNews_def\n readPaperTAA_def e_readPaperTAA_def\n readPaperC_def e_readPaperC_def\n readPref_def e_readPref_def\n readMyReview_def e_readMyReview_def\n readReviews_def e_readReviews_def\n readDecs_def e_readDecs_def\n readDis_def e_readDis_def\n readFinalReviews_def e_readFinalReviews_def\n readFinalDec_def e_readFinalDec_def\n readPrefOfPC_def e_readPrefOfPC_def\n\nfun rObs :: \"state \\<Rightarrow> rAct \\<Rightarrow> out\" where\n\"rObs s (rAmIVoronkov uID p) =\n (if e_readAmIVoronkov s uID p then outBool (readAmIVoronkov s uID p) else outErr)\"\n|\n\"rObs s (rUser uID p uID') =\n (if e_readUser s uID p uID' then outSTRT (readUser s uID p uID') else outErr)\"\n|\n\"rObs s (rConf confID uID p) =\n (if e_readConf s confID uID p then outCONF (readConf s confID uID p) else outErr)\"\n|\n\"rObs s (rNews confID uID p) =\n (if e_readNews s confID uID p then outSTRL (readNews s confID uID p) else outErr)\"\n|\n\"rObs s (rPaperTAA confID uID p papID) =\n (if e_readPaperTAA s confID uID p papID then outSTRPAL (readPaperTAA s confID uID p papID) else outErr)\"\n|\n\"rObs s (rPaperC confID uID p papID) =\n (if e_readPaperC s confID uID p papID then outCON (readPaperC s confID uID p papID) else outErr)\"\n|\n\"rObs s (rPref confID uID p papID) =\n (if e_readPref s confID uID p papID then outPREF (readPref s confID uID p papID) else outErr)\"\n|\n\"rObs s (rMyReview confID uID p papID) =\n (if e_readMyReview s confID uID p papID then outNREV (readMyReview s confID uID p papID) else outErr)\"\n|\n\"rObs s (rReviews confID uID p papID) =\n (if e_readReviews s confID uID p papID then outRREVL (readReviews s confID uID p papID) else outErr)\"\n|\n\"rObs s (rDecs confID uID p papID) =\n (if e_readDecs s confID uID p papID then outDECL (readDecs s confID uID p papID) else outErr)\"\n|\n\"rObs s (rDis confID uID p papID) =\n (if e_readDis s confID uID p papID then outSTRL (readDis s confID uID p papID) else outErr)\"\n|\n\"rObs s (rFinalReviews confID uID p papID) =\n (if e_readFinalReviews s confID uID p papID then outREVL (readFinalReviews s confID uID p papID) else outErr)\"\n|\n\"rObs s (rFinalDec confID uID p papID) =\n (if e_readFinalDec s confID uID p papID then outDEC (readFinalDec s confID uID p papID) else outErr)\"\n|\n\"rObs s (rPrefOfPC confID uID p papID uID') =\n (if e_readPrefOfPC s confID uID p papID uID' then outPREF (readPrefOfPC s confID uID p papID uID') else outErr)\"\n\ndatatype lAct =\n  lConfs userID password\n |lAConfs userID password\n |lSConfs userID password\n |lMyConfs userID password\n |lAllUsers userID password\n |lAllPapers userID password\n |lPC confID userID password\n |lChair confID userID password\n |lPapers confID userID password\n |lMyPapers confID userID password\n |lMyAssignedPapers confID userID password\n |lAssignedReviewers confID userID password paperID\n\nlemmas l_defs =\n listConfs_def e_listConfs_def\n listAConfs_def e_listAConfs_def\n listSConfs_def e_listSConfs_def\n listMyConfs_def e_listMyConfs_def\n listAllUsers_def e_listAllUsers_def\n listAllPapers_def e_listAllPapers_def\n listPC_def e_listPC_def\n listChair_def e_listChair_def\n listPapers_def e_listPapers_def\n listMyPapers_def e_listMyPapers_def\n listMyAssignedPapers_def e_listMyAssignedPapers_def\n listAssignedReviewers_def e_listAssignedReviewers_def\n\nfun lObs :: \"state \\<Rightarrow> lAct \\<Rightarrow> out\" where\n\"lObs s (lConfs uID p) =\n (if e_listConfs s uID p then outCIDL (listConfs s uID p) else outErr)\"\n|\n\"lObs s (lAConfs uID p) =\n (if e_listAConfs s uID p then outCIDL (listAConfs s uID p) else outErr)\"\n|\n\"lObs s (lSConfs uID p) =\n (if e_listSConfs s uID p then outCIDL (listSConfs s uID p) else outErr)\"\n|\n\"lObs s (lMyConfs uID p) =\n (if e_listMyConfs s uID p then outCIDL (listMyConfs s uID p) else outErr)\"\n|\n\"lObs s (lAllUsers uID p) =\n (if e_listAllUsers s uID p then outUIDL (listAllUsers s uID p) else outErr)\"\n|\n\"lObs s (lAllPapers uID p) =\n (if e_listAllPapers s uID p then outPIDL (listAllPapers s uID p) else outErr)\"\n|\n\"lObs s (lPC confID uID p) =\n (if e_listPC s confID uID p then outUIDL (listPC s confID uID p) else outErr)\"\n|\n\"lObs s (lChair confID uID p) =\n (if e_listChair s confID uID p then outUIDL (listChair s confID uID p) else outErr)\"\n|\n\"lObs s (lPapers confID uID p) =\n (if e_listPapers s confID uID p then outPIDL (listPapers s confID uID p) else outErr)\"\n|\n\"lObs s (lMyPapers confID uID p) =\n (if e_listMyPapers s confID uID p then outPIDL (listMyPapers s confID uID p) else outErr)\"\n|\n\"lObs s (lMyAssignedPapers confID uID p) =\n (if e_listMyAssignedPapers s confID uID p then outPIDL (listMyAssignedPapers s confID uID p) else outErr)\"\n|\n\"lObs s (lAssignedReviewers confID uID p papID) =\n (if e_listAssignedReviewers s confID uID p papID\n   then outUIDL (listAssignedReviewers s confID uID p papID) else outErr)\"\n\ndatatype act =\n(* 3 kinds of effects: creation, update and undestructive update *)\n  Cact cAct | Uact uAct | UUact uuAct |\n(* 2 kinds of observations: reading and listing (the latter mainly printing IDs) *)\n  Ract rAct | Lact lAct\n\nfun step :: \"state \\<Rightarrow> act \\<Rightarrow> out * state\" where\n\"step s (Cact ca) = cStep s ca\"\n|\n\"step s (Uact ua) = uStep s ua\"\n|\n\"step s (UUact uua) = uuStep s uua\"\n|\n\"step s (Ract ra) = (rObs s ra, s)\"\n|\n\"step s (Lact la) = (lObs s la, s)\"\n\nexport_code step istate getFreshPaperID in Scala\n\n\ntext \\<open>Some action selectors, used for verification:\\<close>\n\n(* The user (subject) of an action: *)\nfun cUserOfA :: \"cAct \\<Rightarrow> userID\" where\n\"cUserOfA (cUser uID p name info email) = uID\" (* time when a uID appears is an action of uID itself *)\n|\n\"cUserOfA (cConf confID uID p name info) = uID\"\n|\n\"cUserOfA (cPC confID uID p uID') = uID\"\n|\n\"cUserOfA (cChair confID uID p uID') = uID\"\n|\n\"cUserOfA (cPaper confID uID p papID name info) = uID\"\n|\n\"cUserOfA (cAuthor confID uID p papID uID') = uID\"\n|\n\"cUserOfA (cConflict confID uID p papID uID') = uID\"\n|\n\"cUserOfA (cReview confID uID p papID uID') = uID\"\n\nfun uUserOfA :: \"uAct \\<Rightarrow> userID\" where\n\"uUserOfA (uUser uID p p' name info email) = uID\"\n|\n\"uUserOfA (uConfA confID uID p) = uID\"\n|\n\"uUserOfA (uPhase confID uID p ph) = uID\"\n|\n\"uUserOfA (uPaperTA confID uID p papID name info) = uID\"\n|\n\"uUserOfA (uPaperC confID uID p papID pc) = uID\"\n|\n\"uUserOfA (uPref confID uID p papID pr) = uID\"\n|\n\"uUserOfA (uReview confID uID p papID n rc) = uID\"\n\nfun uuUserOfA :: \"uuAct \\<Rightarrow> userID\" where\n\"uuUserOfA (uuNews confID uID p ev) = uID\"\n|\n\"uuUserOfA (uuDis confID uID p papID comm) = uID\"\n|\n\"uuUserOfA (uuReview confID uID p papID n rc) = uID\"\n|\n\"uuUserOfA (uuDec confID uID p papID dec) = uID\"\n\nfun rUserOfA :: \"rAct \\<Rightarrow> userID\" where\n\"rUserOfA (rAmIVoronkov uID p) = uID\"\n|\n\"rUserOfA (rUser uID p uID') = uID\"\n|\n\"rUserOfA (rConf confID uID p) = uID\"\n|\n\"rUserOfA (rNews confID uID p) = uID\"\n|\n\"rUserOfA (rPaperTAA confID uID p papID) = uID\"\n|\n\"rUserOfA (rPaperC confID uID p papID) = uID\"\n|\n\"rUserOfA (rPref confID uID p papID) = uID\"\n|\n\"rUserOfA (rMyReview confID uID p papID) = uID\"\n|\n\"rUserOfA (rReviews confID uID p papID) = uID\"\n|\n\"rUserOfA (rDecs confID uID p papID) = uID\"\n|\n\"rUserOfA (rDis confID uID p papID) = uID\"\n|\n\"rUserOfA (rFinalReviews confID uID p papID) = uID\"\n|\n\"rUserOfA (rFinalDec confID uID p papID) = uID\"\n|\n\"rUserOfA (rPrefOfPC confID uID p papID uID') = uID\"\n\nfun lUserOfA :: \"lAct \\<Rightarrow> userID\" where\n\"lUserOfA (lConfs uID p) = uID\"\n|\n\"lUserOfA (lAConfs uID p) = uID\"\n|\n\"lUserOfA (lSConfs uID p) = uID\"\n|\n\"lUserOfA (lMyConfs uID p) = uID\"\n|\n\"lUserOfA (lAllUsers uID p) = uID\"\n|\n\"lUserOfA (lAllPapers uID p) = uID\"\n|\n\"lUserOfA (lPC confID uID p) = uID\"\n|\n\"lUserOfA (lChair confID uID p) = uID\"\n|\n\"lUserOfA (lPapers confID uID p) = uID\"\n|\n\"lUserOfA (lMyPapers confID uID p) = uID\"\n|\n\"lUserOfA (lMyAssignedPapers confID uID p) = uID\"\n|\n\"lUserOfA (lAssignedReviewers confID uID p papID) = uID\"\n\nfun userOfA :: \"act \\<Rightarrow> userID\" where\n\"userOfA (Cact ca) = cUserOfA ca\"\n|\n\"userOfA (Uact ua) = uUserOfA ua\"\n|\n\"userOfA (UUact uua) = uuUserOfA uua\"\n|\n\"userOfA (Ract ra) = rUserOfA ra\"\n|\n\"userOfA (Lact la) = lUserOfA la\"\n\n\n(* The conference (framework, context) of an action: *)\nfun cConfOfA :: \"cAct \\<Rightarrow> confID option\" where\n\"cConfOfA (cUser uID p name info email) = None\"\n|\n\"cConfOfA (cConf confID uID p name info) = Some confID\"\n(* time when a confID appears is an action bearing its ID *)\n|\n\"cConfOfA (cPC confID uID p uID') = Some confID\"\n|\n\"cConfOfA (cChair confID uID p uID') = Some confID\"\n|\n\"cConfOfA (cPaper confID uID p papID name info) = Some confID\"\n|\n\"cConfOfA (cAuthor confID uID p papID uID') = Some confID\"\n|\n\"cConfOfA (cConflict confID uID p papID uID') = Some confID\"\n|\n\"cConfOfA (cReview confID uID p papID uID') = Some confID\"\n\nfun uConfOfA :: \"uAct \\<Rightarrow> confID option\" where\n\"uConfOfA (uUser uID p p' name info email) = None\"\n|\n\"uConfOfA (uConfA confID uID p) = Some confID\"\n|\n\"uConfOfA (uPhase confID uID p ph) = Some confID\"\n|\n\"uConfOfA (uPaperTA confID uID p papID name info) = Some confID\"\n|\n\"uConfOfA (uPaperC confID uID p papID pc) = Some confID\"\n|\n\"uConfOfA (uPref confID uID p papID pr) = Some confID\"\n|\n\"uConfOfA (uReview confID uID p papID n rc) = Some confID\"\n\nfun uuConfOfA :: \"uuAct \\<Rightarrow> confID option\" where\n\"uuConfOfA (uuNews confID uID p ev) = Some confID\"\n|\n\"uuConfOfA (uuDis confID uID p papID comm) = Some confID\"\n|\n\"uuConfOfA (uuReview confID uID p papID n rc) = Some confID\"\n|\n\"uuConfOfA (uuDec confID uID p papID dec) = Some confID\"\n\nfun rConfOfA :: \"rAct \\<Rightarrow> confID option\" where\n\"rConfOfA (rAmIVoronkov uID p) = None\"\n|\n\"rConfOfA (rUser uID p uID') = None\"\n|\n\"rConfOfA (rConf confID uID p) = Some confID\"\n|\n\"rConfOfA (rNews confID uID p) = Some confID\"\n|\n\"rConfOfA (rPaperTAA confID uID p papID) = Some confID\"\n|\n\"rConfOfA (rPaperC confID uID p papID) = Some confID\"\n|\n\"rConfOfA (rPref confID uID p papID) = Some confID\"\n|\n\"rConfOfA (rMyReview confID uID p papID) = Some confID\"\n|\n\"rConfOfA (rReviews confID uID p papID) = Some confID\"\n|\n\"rConfOfA (rDecs confID uID p papID) = Some confID\"\n|\n\"rConfOfA (rDis confID uID p papID) = Some confID\"\n|\n\"rConfOfA (rFinalReviews confID uID p papID) = Some confID\"\n|\n\"rConfOfA (rFinalDec confID uID p papID) = Some confID\"\n|\n\"rConfOfA (rPrefOfPC confID uID p papID uID') = Some confID\"\n\n\nfun lConfOfA :: \"lAct \\<Rightarrow> confID option\" where\n\"lConfOfA (lConfs uID p) = None\"\n|\n\"lConfOfA (lAConfs uID p) = None\"\n|\n\"lConfOfA (lSConfs uID p) = None\"\n|\n\"lConfOfA (lMyConfs uID p) = None\"\n|\n\"lConfOfA (lAllUsers uID p) = None\"\n|\n\"lConfOfA (lAllPapers uID p) = None\"\n|\n\"lConfOfA (lPC confID uID p) = Some confID\"\n|\n\"lConfOfA (lChair confID uID p) = Some confID\"\n|\n\"lConfOfA (lPapers confID uID p) = Some confID\"\n|\n\"lConfOfA (lMyPapers confID uID p) = Some confID\"\n|\n\"lConfOfA (lMyAssignedPapers confID uID p) = Some confID\"\n|\n\"lConfOfA (lAssignedReviewers confID uID p papID) = Some confID\"\n\nfun confOfA :: \"act \\<Rightarrow> confID option\" where\n\"confOfA (Cact ca) = cConfOfA ca\"\n|\n\"confOfA (Uact ua) = uConfOfA ua\"\n|\n\"confOfA (UUact uua) = uuConfOfA uua\"\n|\n\"confOfA (Ract ra) = rConfOfA ra\"\n|\n\"confOfA (Lact la) = lConfOfA la\"\n\n\n(* The paper of an action: *)\nfun cPaperOfA :: \"cAct \\<Rightarrow> paperID option\" where\n\"cPaperOfA (cUser uID p name info email) = None\"\n|\n\"cPaperOfA (cPaper confID uID p papID name info) = Some papID\"\n(* time when a paperID appears is an action bearing its ID *)\n|\n\"cPaperOfA (cPC confID uID p uID') = None\"\n|\n\"cPaperOfA (cChair confID uID p uID') = None\"\n|\n\"cPaperOfA (cConf confID uID p name info) = None\"\n|\n\"cPaperOfA (cAuthor confID uID p papID uID') = Some papID\"\n|\n\"cPaperOfA (cConflict confID uID p papID uID') = Some papID\"\n|\n\"cPaperOfA (cReview confID uID p papID uID') = Some papID\"\n\nfun uPaperOfA :: \"uAct \\<Rightarrow> paperID option\" where\n\"uPaperOfA (uUser uID p p' name info email) = None\"\n|\n\"uPaperOfA (uConfA confID uID p) = None\"\n|\n\"uPaperOfA (uPhase confID uID p ph) = None\"\n|\n\"uPaperOfA (uPaperTA confID uID p papID name info) = Some papID\"\n|\n\"uPaperOfA (uPaperC confID uID p papID pc) = Some papID\"\n|\n\"uPaperOfA (uPref confID uID p papID pr) = Some papID\"\n|\n\"uPaperOfA (uReview confID uID p papID n rc) = Some papID\"\n\nfun uuPaperOfA :: \"uuAct \\<Rightarrow> paperID option\" where\n\"uuPaperOfA (uuNews confID uID p ev) = None\"\n|\n\"uuPaperOfA (uuDis confID uID p papID comm) = Some papID\"\n|\n\"uuPaperOfA (uuReview confID uID p papID n rc) = Some papID\"\n|\n\"uuPaperOfA (uuDec confID uID p papID dec) = Some papID\"\n\nfun rPaperOfA :: \"rAct \\<Rightarrow> paperID option\" where\n\"rPaperOfA (rAmIVoronkov uID p) = None\"\n|\n\"rPaperOfA (rUser uID p uID') = None\"\n|\n\"rPaperOfA (rConf confID uID p) = None\"\n|\n\"rPaperOfA (rNews confID uID p) = None\"\n|\n\"rPaperOfA (rPaperTAA confID uID p papID) = Some papID\"\n|\n\"rPaperOfA (rPaperC confID uID p papID) = Some papID\"\n|\n\"rPaperOfA (rPref confID uID p papID) = Some papID\"\n|\n\"rPaperOfA (rMyReview confID uID p papID) = Some papID\"\n|\n\"rPaperOfA (rReviews confID uID p papID) = Some papID\"\n|\n\"rPaperOfA (rDecs confID uID p papID) = Some papID\"\n|\n\"rPaperOfA (rDis confID uID p papID) = Some papID\"\n|\n\"rPaperOfA (rFinalReviews confID uID p papID) = Some papID\"\n|\n\"rPaperOfA (rFinalDec confID uID p papID) = Some papID\"\n|\n\"rPaperOfA (rPrefOfPC confID uID p papID uID') = Some papID\"\n\nfun lPaperOfA :: \"lAct \\<Rightarrow> paperID option\" where\n\"lPaperOfA (lConfs uID p) = None\"\n|\n\"lPaperOfA (lAConfs uID p) = None\"\n|\n\"lPaperOfA (lSConfs uID p) = None\"\n|\n\"lPaperOfA (lMyConfs uID p) = None\"\n|\n\"lPaperOfA (lAllUsers uID p) = None\"\n|\n\"lPaperOfA (lAllPapers uID p) = None\"\n|\n\"lPaperOfA (lPC confID uID p) = None\"\n|\n\"lPaperOfA (lChair confID uID p) = None\"\n|\n\"lPaperOfA (lPapers confID uID p) = None\"\n|\n\"lPaperOfA (lMyPapers confID uID p) = None\"\n|\n\"lPaperOfA (lMyAssignedPapers confID uID p) = None\"\n|\n\"lPaperOfA (lAssignedReviewers confID uID p papID) = Some papID\"\n\nfun paperOfA :: \"act \\<Rightarrow> paperID option\" where\n\"paperOfA (Cact ca) = cPaperOfA ca\"\n|\n\"paperOfA (Uact ua) = uPaperOfA ua\"\n|\n\"paperOfA (UUact uua) = uuPaperOfA uua\"\n|\n\"paperOfA (Ract ra) = rPaperOfA ra\"\n|\n\"paperOfA (Lact la) = lPaperOfA la\"\n\n(* Note: unlike confOfA and paperOfA which may be \"None\", userOfA always returns a user ID.  *)\n\n\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/CoCon/System_Specification.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.2571033856120266}}
{"text": "(*\n * Copyright (C) 2014 NICTA\n * All rights reserved.\n *)\n\n(* Author: David Cock - David.Cock@nicta.com.au *)\n\nheader {* Continuity and Induction for Loops*}\n\ntheory LoopInduction imports Healthiness Continuity begin\n\ntext {* Showing continuity for loops requires a stronger induction principle than we have used\nso far, which in turn relies on the continuity of loops (inductively).  Thus, the proofs are\nintertwined, and broken off from the main set of continuity proofs.  This result is also\nessential in showing the sublinearity of loops. *}\n\ntext {* A loop step is monotonic. *}\nlemma wp_loop_step_mono_trans:\n  fixes body::\"'s prog\"\n  assumes sP: \"sound P\"\n      and hb: \"healthy (wp body)\"\n  shows \"mono_trans (\\<lambda>Q s. \\<guillemotleft> G \\<guillemotright> s * wp body Q s + \\<guillemotleft> \\<N> G \\<guillemotright> s * P s)\"\nproof(intro mono_transI le_funI, simp)\n  fix Q R::\"'s expect\" and s::'s\n  assume sQ: \"sound Q\" and sR: \"sound R\" and le: \"Q \\<tturnstile> R\"\n  hence \"wp body Q \\<tturnstile> wp body R\"\n    by(rule mono_transD[OF healthy_monoD, OF hb])\n  thus \"\\<guillemotleft>G\\<guillemotright> s * wp body Q s \\<le> \\<guillemotleft>G\\<guillemotright> s * wp body R s\"\n    by(auto dest:le_funD intro:mult_left_mono)\nqed\n\ntext {* We can therefore apply the standard fixed-point lemmas to unfold it: *}\nlemma lfp_wp_loop_unfold:\n  fixes body::\"'s prog\"\n  assumes hb: \"healthy (wp body)\"\n      and sP: \"sound P\"\n  shows \"lfp_exp (\\<lambda>Q s. \\<guillemotleft>G\\<guillemotright> s * wp body Q s + \\<guillemotleft>\\<N> G\\<guillemotright> s * P s) =\n         (\\<lambda>s. \\<guillemotleft>G\\<guillemotright> s * wp body (lfp_exp (\\<lambda>Q s. \\<guillemotleft>G\\<guillemotright> s * wp body Q s + \\<guillemotleft>\\<N> G\\<guillemotright> s * P s)) s +\n              \\<guillemotleft>\\<N> G\\<guillemotright> s * P s)\"\nproof(rule lfp_exp_unfold)\n  from assms show \"mono_trans (\\<lambda>Q s. \\<guillemotleft>G\\<guillemotright> s * wp body Q s + \\<guillemotleft>\\<N> G\\<guillemotright> s * P s)\"\n    by(blast intro:wp_loop_step_mono_trans)\n  from assms show \"\\<lambda>s. \\<guillemotleft>G\\<guillemotright> s * wp body (\\<lambda>s. bound_of P) s + \\<guillemotleft>\\<N> G\\<guillemotright> s * P s \\<tturnstile> \\<lambda>s. bound_of P\"\n    by(blast intro:lfp_loop_fp)\n  from sP show \"sound (\\<lambda>s. bound_of P)\"\n    by(auto)\n  fix Q::\"'s expect\"\n  assume \"sound Q\"\n  with assms show \"sound (\\<lambda>s. \\<guillemotleft>G\\<guillemotright> s * wp body Q s + \\<guillemotleft>\\<N> G\\<guillemotright> s * P s)\"\n    by(intro wp_loop_step_sound[unfolded wp_eval, simplified, folded negate_embed], auto)\nqed\n\n\n\n  from uP uwQ have \"wp body Q s \\<le> 1\" \"P s \\<le> 1\" by(auto)\n  hence \"\\<guillemotleft>G\\<guillemotright> s * wp body Q s + \\<guillemotleft>\\<N> G\\<guillemotright> s * P s \\<le> \\<guillemotleft>G\\<guillemotright> s * 1 + \\<guillemotleft>\\<N> G\\<guillemotright> s * 1\"\n    by(blast intro:add_mono mult_left_mono)\n  also have \"... = 1\" by(simp add:negate_embed)\n  finally show \"\\<guillemotleft>G\\<guillemotright> s * wp body Q s + \\<guillemotleft>\\<N> G\\<guillemotright> s * P s \\<le> 1\" .\nqed\n\nlemma lfp_loop_unitary:\n  fixes body::\"'s prog\"\n  assumes hb: \"healthy (wp body)\"\n      and uP: \"unitary P\"\n  shows \"unitary (lfp_exp (\\<lambda>Q s. \\<guillemotleft>G\\<guillemotright> s * wp body Q s + \\<guillemotleft>\\<N> G\\<guillemotright> s * P s))\"\n  using assms by(blast intro:lfp_exp_unitary wp_loop_step_unitary)\n\ntext {* From the lattice structure on transformers, we establish a transfinite induction\n  principle for loops.  We use this to show a number of properties, particularly\n  subdistributivity, for loops.  This proof follows the pattern of lemma lfp\\_ordinal\\_induct\n  in HOL/Inductive. *}\nlemma loop_induct:\n  fixes body::\"'s prog\"\n  assumes hwp:  \"healthy (wp body)\"\n      and hwlp: \"nearly_healthy (wlp body)\"\n      -- \"The body must be healthy, both in strict and liberal semantics.\"\n      and Limit:   \"\\<And>S. \\<lbrakk> \\<forall>x\\<in>S. P (fst x) (snd x); \\<forall>x\\<in>S. feasible (fst x);\n                          \\<forall>x\\<in>S. \\<forall>Q. unitary Q \\<longrightarrow> unitary (snd x Q) \\<rbrakk> \\<Longrightarrow>\n                    P (Sup_trans (fst ` S)) (Inf_utrans (snd ` S))\"\n      -- \"The property holds at limit points.\"\n      and IH:   \"\\<And>t u. \\<lbrakk> P t u; feasible t; \\<And>Q. unitary Q \\<Longrightarrow> unitary (u Q)  \\<rbrakk> \\<Longrightarrow>\n                        P (wp  (body ;; Embed t \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip))\n                          (wlp (body ;; Embed u \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip))\"\n      -- \"The inductive step.  The property is preserved by a single loop iteration.\"\n      and P_equiv: \"\\<And>t t' u u'. \\<lbrakk> P t u; equiv_trans t t'; equiv_utrans u u' \\<rbrakk> \\<Longrightarrow> P t' u'\"\n      -- \"The property must be preserved by equivalence\"\n  shows \"P (wp (do G \\<longrightarrow> body od)) (wlp (do G \\<longrightarrow> body od))\"\n  -- \"The property can refer to both interpretations simultaneously.  The unifier will happily\n  apply the rule to just one or the other, however.\"\nproof(simp add:wp_eval)\n  let \"?X t\" = \"wp (body ;; Embed t \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip)\"\n  let \"?Y t\" = \"wlp (body ;; Embed t \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip)\"\n\n  let ?M = \"{x. P (fst x) (snd x) \\<and>\n                feasible (fst x) \\<and>\n                (\\<forall>Q. unitary Q \\<longrightarrow> unitary (snd x Q)) \\<and>\n                le_trans (fst x) (lfp_trans ?X) \\<and>\n                le_utrans (gfp_trans ?Y) (snd x)}\"\n\n  have fSup: \"feasible (Sup_trans (fst ` ?M))\"\n  proof(intro feasibleI bounded_byI2 nnegI2)\n    fix Q::\"'s expect\" and b::real\n    assume nQ: \"nneg Q\" and bQ: \"bounded_by b Q\"\n    show \"Sup_trans (fst ` ?M) Q \\<tturnstile> \\<lambda>s. b\"\n      unfolding Sup_trans_def\n      using nQ bQ by(auto intro!:Sup_exp_least)\n    show \"\\<lambda>s. 0 \\<tturnstile> Sup_trans (fst ` ?M) Q\"\n    proof(cases)\n      assume empty: \"?M = {}\"\n      show ?thesis by(simp add:Sup_trans_def Sup_exp_def empty)\n    next\n      assume ne: \"?M \\<noteq> {}\"\n      hence \"\\<exists>x. x \\<in> ?M\" by(rule nonempty_witness)\n      then obtain x where xin: \"x \\<in> ?M\" by(rule exE)\n      hence ffx: \"feasible (fst x)\" by(simp)\n      with nQ bQ have \"\\<lambda>s. 0 \\<tturnstile> fst x Q\" by(auto)\n      also from xin have \"fst x Q \\<tturnstile> Sup_trans (fst ` ?M) Q\"\n          apply(intro Sup_trans_upper2[OF imageI _ nQ bQ], assumption)\n          apply(clarsimp, blast intro: sound_nneg[OF feasible_sound] feasible_boundedD)\n          done\n      finally show \"\\<lambda>s. 0 \\<tturnstile> Sup_trans (fst ` ?M) Q\" .\n    qed\n  qed\n\n  have uInf: \"\\<And>P. unitary P \\<Longrightarrow> unitary (Inf_utrans (snd ` ?M) P)\"\n  proof(cases \"?M = {}\")\n    fix P\n    assume empty: \"?M = {}\"\n    show \"?thesis P\" by(simp only:empty, simp add:Inf_utrans_def)\n  next\n    fix P::\"'s expect\"\n    assume uP: \"unitary P\"\n       and ne: \"?M \\<noteq> {}\"\n    show \"?thesis P\"\n    proof(intro unitaryI2 nnegI2 bounded_byI2)\n      from nonempty_witness[OF ne] obtain x where xin: \"x \\<in> ?M\" by(iprover)\n      hence sxin: \"snd x \\<in> snd ` ?M\" by(simp)\n      hence \"le_utrans (Inf_utrans (snd ` ?M)) (snd x)\"\n        by(intro Inf_utrans_lower, auto)\n      with uP\n      have \"Inf_utrans (snd ` ?M) P \\<tturnstile> snd x P\" by(auto)\n      also {\n        from xin uP have \"unitary (snd x P)\" by(simp)\n        hence \"snd x P \\<tturnstile> \\<lambda>s. 1\" by(auto)\n      }\n      finally show \"Inf_utrans (snd ` ?M) P \\<tturnstile> \\<lambda>s. 1\" .\n\n      have \"\\<lambda>s. 0 \\<tturnstile> Inf_trans (snd ` ?M) P\"\n        unfolding Inf_trans_def\n      proof(rule Inf_exp_greatest)\n        from sxin show \"{t P |t. t \\<in> snd ` ?M} \\<noteq> {}\" by(auto)\n        show \"\\<forall>P\\<in>{t P |t. t \\<in> snd ` ?M}. \\<lambda>s. 0 \\<tturnstile> P\"\n        proof(clarsimp)\n          fix t::\"'s trans\"\n          assume \"\\<forall>Q. unitary Q \\<longrightarrow> unitary (t Q)\"\n          with uP have \"unitary (t P)\" by(auto)\n          thus \"\\<lambda>s. 0 \\<tturnstile> t P\" by(auto)\n        qed\n      qed\n      also {\n        from ne have X: \"(snd ` ?M = {}) = False\" by(simp)\n        have \"Inf_trans (snd ` ?M) P = Inf_utrans (snd ` ?M) P\"\n          unfolding Inf_utrans_def by(subst X, simp)\n      }\n      finally show \"\\<lambda>s. 0 \\<tturnstile> Inf_utrans (snd ` ?M) P\" .\n    qed\n  qed\n\n  have wp_loop_mono: \"\\<And>t u. \\<lbrakk> le_trans t u; \\<And>P. sound P \\<Longrightarrow> sound (t P);\n                               \\<And>P. sound P \\<Longrightarrow> sound (u P) \\<rbrakk> \\<Longrightarrow> le_trans (?X t) (?X u)\"\n  proof(intro le_transI le_funI, simp add:wp_eval)\n    fix t u::\"'s trans\" and P::\"'s expect\" and s::'s\n    assume le: \"le_trans t u\"\n       and st: \"\\<And>P. sound P \\<Longrightarrow> sound (t P)\"\n       and su: \"\\<And>P. sound P \\<Longrightarrow> sound (u P)\"\n       and sP: \"sound P\"\n    hence \"sound (t P)\" \"sound (u P)\" by(auto)\n    with healthy_monoD[OF hwp] le sP have \"wp body (t P) \\<tturnstile> wp body (u P)\" by(auto)\n    hence \"wp body (t P) s \\<le> wp body (u P) s\" by(auto)\n    thus \"\\<guillemotleft>G\\<guillemotright> s * wp body (t P) s \\<le> \\<guillemotleft>G\\<guillemotright> s * wp body (u P) s\" by(auto intro:mult_left_mono)\n  qed\n\n  have wlp_loop_mono: \"\\<And>t u. \\<lbrakk> le_utrans t u; \\<And>P. unitary P \\<Longrightarrow> unitary (t P);\n                               \\<And>P. unitary P \\<Longrightarrow> unitary (u P) \\<rbrakk> \\<Longrightarrow> le_utrans (?Y t) (?Y u)\"\n  proof(intro le_utransI le_funI, simp add:wp_eval)\n    fix t u::\"'s trans\" and P::\"'s expect\" and s::'s\n    assume le: \"le_utrans t u\"\n       and ut: \"\\<And>P. unitary P \\<Longrightarrow> unitary (t P)\"\n       and uu: \"\\<And>P. unitary P \\<Longrightarrow> unitary (u P)\"\n       and uP: \"unitary P\"\n    hence \"unitary (t P)\" \"unitary (u P)\" by(auto)\n    with le uP have \"wlp body (t P) \\<tturnstile> wlp body (u P)\"\n      by(auto intro:nearly_healthy_monoD[OF hwlp])\n    hence \"wlp body (t P) s \\<le> wlp body (u P) s\" by(auto)\n    thus \"\\<guillemotleft>G\\<guillemotright> s * wlp body (t P) s \\<le> \\<guillemotleft>G\\<guillemotright> s * wlp body (u P) s\"\n      by(auto intro:mult_left_mono)\n  qed\n\n  from hwp have hX: \"\\<And>t. healthy t \\<Longrightarrow> healthy (?X t)\"\n    by(auto intro:healthy_intros)\n\n  from hwlp have hY: \"\\<And>t. nearly_healthy t \\<Longrightarrow> nearly_healthy (?Y t)\"\n    by(auto intro!:healthy_intros)\n                \n  have PLimit: \"P (Sup_trans (fst ` ?M)) (Inf_utrans (snd ` ?M))\"\n    by(auto intro:Limit)\n\n  have feasible_lfp_loop:\n    \"feasible (lfp_trans ?X)\"\n  proof(intro feasibleI bounded_byI2 nnegI2,\n        simp_all add:wp_Loop1[unfolded wp_eval] soundI2 hwp)\n    fix P::\"'s expect\" and b::real\n    assume bP: \"bounded_by b P\" and nP: \"nneg P\"\n    hence sP: \"sound P\" by(auto)\n    show \"lfp_exp (\\<lambda>Q s. \\<guillemotleft> G \\<guillemotright> s * wp body Q s + \\<guillemotleft> \\<N> G \\<guillemotright> s * P s) \\<tturnstile> \\<lambda>s. b\"\n    proof(intro lfp_exp_lowerbound le_funI)\n      fix s::'s\n      from bP nP have nnb: \"0 \\<le> b\" by(auto)\n      hence \"sound (\\<lambda>s. b)\" \"bounded_by b (\\<lambda>s. b)\" by(auto)\n      with hwp have \"bounded_by b (wp body (\\<lambda>s. b))\" by(auto)\n      with bP have \"wp body (\\<lambda>s. b) s \\<le> b\" \"P s \\<le> b\" by(auto)\n      hence \"\\<guillemotleft>G\\<guillemotright> s * wp body (\\<lambda>s. b) s + \\<guillemotleft>\\<N> G\\<guillemotright> s * P s \\<le> \\<guillemotleft>G\\<guillemotright> s * b + \\<guillemotleft>\\<N> G\\<guillemotright> s * b\"\n        by(auto intro:add_mono mult_left_mono)\n      thus \"\\<guillemotleft>G\\<guillemotright> s * wp body (\\<lambda>s. b) s + \\<guillemotleft>\\<N> G\\<guillemotright> s * P s \\<le> b\"\n        by(simp add:negate_embed algebra_simps)\n      from nnb show \"sound (\\<lambda>s. b)\" by(auto)\n    qed\n    from hwp sP show \"\\<lambda>s. 0 \\<tturnstile> lfp_exp (\\<lambda>Q s. \\<guillemotleft> G \\<guillemotright> s * wp body Q s + \\<guillemotleft> \\<N> G \\<guillemotright> s * P s)\"\n      by(blast intro!:lfp_exp_greatest lfp_loop_fp)\n  qed\n\n  have unitary_gfp:\n    \"\\<And>P. unitary P \\<Longrightarrow> unitary (gfp_trans ?Y P)\"\n  proof(intro unitaryI2 nnegI2 bounded_byI2,\n      simp_all add:wlp_Loop1[unfolded wp_eval] hwlp)\n    fix P::\"'s expect\"\n    assume uP: \"unitary P\"\n    show \"\\<lambda>s. 0 \\<tturnstile> gfp_exp (\\<lambda>Q s. \\<guillemotleft> G \\<guillemotright> s * wlp body Q s + \\<guillemotleft> \\<N> G \\<guillemotright> s * P s)\"\n    proof(rule gfp_exp_upperbound[OF le_funI])\n      fix s::\"'s\"\n      from hwlp uP have \"0 \\<le> wlp body (\\<lambda>s. 0) s\" \"0 \\<le> P s\" by(auto dest!:unitary_sound)\n      thus \"0 \\<le> \\<guillemotleft>G\\<guillemotright> s * wlp body (\\<lambda>s. 0) s + \\<guillemotleft>\\<N> G\\<guillemotright> s * P s\"\n        by(auto intro:add_nonneg_nonneg mult_nonneg_nonneg)\n      show \"unitary (\\<lambda>s. 0)\" by(auto)\n    qed\n    show \"gfp_exp (\\<lambda>Q s. \\<guillemotleft> G \\<guillemotright> s * wlp body Q s + \\<guillemotleft> \\<N> G \\<guillemotright> s * P s) \\<tturnstile> \\<lambda>s. 1\"\n      by(auto intro:gfp_exp_least)\n  qed\n\n  have fX:\n    \"\\<And>t. feasible t \\<Longrightarrow> feasible (?X t)\"\n  proof(intro feasibleI nnegI bounded_byI, simp_all add:wp_eval)\n    fix t::\"'s trans\" and Q::\"'s expect\" and b::real and s::'s\n    assume ft: \"feasible t\" and bQ: \"bounded_by b Q\" and nQ: \"nneg Q\"\n    hence \"nneg (t Q)\" \"bounded_by b (t Q)\" by(auto)\n    moreover hence stQ: \"sound (t Q)\" by(auto)\n    ultimately have \"wp body (t Q) s \\<le> b\" using hwp by(auto)\n    moreover from bQ have \"Q s \\<le> b\" by(auto)\n    ultimately have \"\\<guillemotleft>G\\<guillemotright> s * wp body (t Q) s + (1 - \\<guillemotleft>G\\<guillemotright> s) * Q s \\<le>\n                     \\<guillemotleft>G\\<guillemotright> s * b + (1 - \\<guillemotleft> G \\<guillemotright> s) * b\"\n      by(auto intro:add_mono mult_left_mono)\n    thus \"\\<guillemotleft>G\\<guillemotright> s * wp body (t Q) s + (1 - \\<guillemotleft>G\\<guillemotright> s) * Q s \\<le> b\"\n      by(simp add:algebra_simps)\n\n    from nQ stQ hwp have \"0 \\<le> wp body (t Q) s\" \"0 \\<le> Q s\" by(auto)\n    thus \"0 \\<le> \\<guillemotleft>G\\<guillemotright> s * wp body (t Q) s + (1 - \\<guillemotleft>G\\<guillemotright> s) * Q s\"\n      by(auto intro:add_nonneg_nonneg mult_nonneg_nonneg)\n  qed\n\n  have uY:\n    \"\\<And>t P. (\\<And>P. unitary P \\<Longrightarrow> unitary (t P)) \\<Longrightarrow> unitary P \\<Longrightarrow> unitary (?Y t P)\"\n  proof(intro unitaryI2 nnegI bounded_byI, simp_all add:wp_eval)\n    fix t::\"'s trans\" and P::\"'s expect\" and s::'s\n    assume ut: \"\\<And>P. unitary P \\<Longrightarrow> unitary (t P)\"\n       and uP: \"unitary P\"\n    hence utP: \"unitary (t P)\" by(auto)\n    with hwlp have ubtP: \"unitary (wlp body (t P))\" by(auto)\n    with uP have \"0 \\<le> P s\" \"0 \\<le> wlp body (t P) s\" by(auto)\n    thus \"0 \\<le> \\<guillemotleft>G\\<guillemotright> s * wlp body (t P) s + (1-\\<guillemotleft>G\\<guillemotright> s) * P s\"\n      by(auto intro:add_nonneg_nonneg mult_nonneg_nonneg)\n\n    from uP ubtP have \"P s \\<le> 1\" \"wlp body (t P) s \\<le> 1\" by(auto)\n    hence \"\\<guillemotleft>G\\<guillemotright> s * wlp body (t P) s + (1-\\<guillemotleft>G\\<guillemotright> s) * P s \\<le> \\<guillemotleft>G\\<guillemotright> s * 1 + (1-\\<guillemotleft>G\\<guillemotright> s) * 1\"\n      by(blast intro:add_mono mult_left_mono)\n    also have \"... = 1\" by(simp add:algebra_simps)\n    finally show \"\\<guillemotleft>G\\<guillemotright> s * wlp body (t P) s + (1-\\<guillemotleft>G\\<guillemotright> s) * P s \\<le> 1\" .\n  qed\n\n  have fw_lfp: \"le_trans (Sup_trans (fst ` ?M)) (lfp_trans ?X)\"\n    using feasible_nnegD[OF feasible_lfp_loop]\n    by(intro le_transI[OF Sup_trans_least2], blast+)\n  hence \"le_trans (?X (Sup_trans (fst ` ?M))) (?X (lfp_trans ?X))\"\n    by(auto intro:wp_loop_mono feasible_sound[OF fSup]\n                  feasible_sound[OF feasible_lfp_loop])\n  also have \"equiv_trans ... (lfp_trans ?X)\"\n  proof(rule iffD1[OF equiv_trans_comm, OF lfp_trans_unfold], iprover intro:wp_loop_mono)\n    fix t::\"'s trans\" and P::\"'s expect\"\n    assume st: \"\\<And>Q. sound Q \\<Longrightarrow> sound (t Q)\"\n       and sP: \"sound P\"\n    show \"sound (?X t P)\"\n    proof(intro soundI2 bounded_byI nnegI, simp_all add:wp_eval)\n      fix s::'s\n      from sP st hwp have \"0 \\<le> P s\" \"0 \\<le> wp body (t P) s\" by(auto)\n      thus \"0 \\<le> \\<guillemotleft>G\\<guillemotright> s * wp body (t P) s + (1 - \\<guillemotleft>G\\<guillemotright> s) * P s\"\n        by(blast intro:add_nonneg_nonneg mult_nonneg_nonneg)\n      from sP st have \"bounded_by (bound_of (t P)) (t P)\" by(auto)\n      with sP st hwp have \"bounded_by (bound_of (t P)) (wp body (t P))\" by(auto)\n      hence \"wp body (t P) s \\<le> bound_of (t P)\" by(auto)\n      moreover from sP st hwp have \"P s \\<le> bound_of P\" by(auto)\n      moreover have \"\\<guillemotleft>G\\<guillemotright> s \\<le> 1\" \"1 - \\<guillemotleft>G\\<guillemotright> s \\<le> 1\" by(auto)\n      moreover from sP st hwp have \"0 \\<le> wp body (t P) s\" \"0 \\<le> P s\" by(auto)\n      moreover have \"(0::real) \\<le> 1\" by(simp)\n      ultimately show \"\\<guillemotleft>G\\<guillemotright> s * wp body (t P) s + (1 - \\<guillemotleft>G\\<guillemotright> s) * P s \\<le>\n                       1 * bound_of (t P) + 1 * bound_of P\"\n        by(blast intro:add_mono mult_mono)\n      qed\n    next\n    let \"?fp\" = \"\\<lambda>R s. bound_of R\"\n    show \"le_trans (?X ?fp) ?fp\" by(auto intro:healthy_intros hwp)\n    fix P::\"'s expect\" assume \"sound P\"\n    thus \"sound (?fp P)\" by(auto)\n  qed\n  finally have le_lfp: \"le_trans (?X (Sup_trans (fst ` ?M))) (lfp_trans ?X)\" .\n\n  have fw_gfp: \"le_utrans (gfp_trans ?Y) (Inf_utrans (snd ` ?M))\"\n    by(auto intro:Inf_utrans_greatest unitary_gfp)\n\n  have \"equiv_utrans (gfp_trans ?Y) (?Y (gfp_trans ?Y))\"\n    by(auto intro!:gfp_trans_unfold wlp_loop_mono uY)\n  also from fw_gfp have \"le_utrans (?Y (gfp_trans ?Y)) (?Y (Inf_utrans (snd ` ?M)))\"\n    by(auto intro:wlp_loop_mono uInf unitary_gfp)\n  finally have ge_gfp: \"le_utrans (gfp_trans ?Y) (?Y (Inf_utrans (snd ` ?M)))\" .\n  from PLimit fX uY fSup uInf have \"P (?X (Sup_trans (fst ` ?M))) (?Y (Inf_utrans (snd ` ?M)))\"\n    by(iprover intro:IH)\n  moreover from fSup have \"feasible (?X (Sup_trans (fst ` ?M)))\" by(rule fX)\n  moreover have \"\\<And>P. unitary P \\<Longrightarrow> unitary (?Y (Inf_utrans (snd ` ?M)) P)\"\n    by(auto intro:uY uInf)\n  moreover note le_lfp ge_gfp\n  ultimately have pair_in: \"(?X (Sup_trans (fst ` ?M)), ?Y (Inf_utrans (snd ` ?M))) \\<in> ?M\"\n    by(simp)\n\n  have \"?X (Sup_trans (fst ` ?M)) \\<in> fst ` ?M\"\n    by(rule imageI[OF pair_in, of fst, simplified])\n  hence \"le_trans (?X (Sup_trans (fst ` ?M))) (Sup_trans (fst ` ?M))\"\n  proof(rule le_transI[OF Sup_trans_upper2[where t=\"?X (Sup_trans (fst ` ?M))\"\n                                             and S=\"fst ` ?M\"]])\n    fix P::\"'s expect\"\n    assume sP: \"sound P\"\n    thus \"nneg P\" by(auto)\n    from sP show \"bounded_by (bound_of P) P\" by(auto)\n    from sP show \"\\<forall>u\\<in>fst ` ?M. \\<forall>Q. nneg Q \\<and> bounded_by (bound_of P) Q \\<longrightarrow>\n                                   nneg (u Q) \\<and> bounded_by (bound_of P) (u Q)\"\n      by(auto)\n  qed\n  hence \"le_trans (lfp_trans ?X) (Sup_trans (fst ` ?M))\"\n    by(auto intro:lfp_trans_lowerbound feasible_sound[OF fSup])\n  with fw_lfp have eqt: \"equiv_trans (Sup_trans (fst ` ?M)) (lfp_trans ?X)\"\n    by(rule le_trans_antisym)\n\n  have \"?Y (Inf_utrans (snd ` ?M)) \\<in> snd ` ?M\"\n    by(rule imageI[OF pair_in, of snd, simplified])\n  hence \"le_utrans (Inf_utrans (snd ` ?M)) (?Y (Inf_utrans (snd ` ?M)))\"\n    by(intro Inf_utrans_lower, auto)\n  hence \"le_utrans (Inf_utrans (snd ` ?M)) (gfp_trans ?Y)\"\n    by(blast intro:gfp_trans_upperbound uInf)\n  with fw_gfp have equ: \"equiv_utrans (Inf_utrans (snd ` ?M)) (gfp_trans ?Y)\"\n    by(auto intro:le_utrans_antisym)\n  from PLimit eqt equ show \"P (lfp_trans ?X) (gfp_trans ?Y)\" by(rule P_equiv)\nqed\n\nsubsection {* The Limit of Iterates *}\n\ntext {* The iterates of a loop are its sequence of finite unrollings.  We show shortly that this\nconverges on the least fixed point.  This is enormously useful, as we can appeal to various\nproperties of the finite iterates (which will follow by finite induction), which we can then\ntransfer to the limit. *}\ndefinition iterates :: \"'s prog \\<Rightarrow> ('s \\<Rightarrow> bool) \\<Rightarrow> nat \\<Rightarrow> 's trans\"\nwhere \"iterates body G i = ((\\<lambda>x. wp (body ;; Embed x \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip)) ^^ i) (\\<lambda>P s. 0)\"\n\nlemma iterates_0[simp]:\n  \"iterates body G 0 = (\\<lambda>P s. 0)\"\n  by(simp add:iterates_def)\n\nlemma iterates_Suc[simp]:\n  \"iterates body G (Suc i) = wp (body ;; Embed (iterates body G i) \\<^bsub>\\<guillemotleft>G\\<guillemotright>\\<^esub>\\<oplus> Skip)\"\n  by(simp add:iterates_def)\n\ntext {* All iterates are healthy. *}\nlemma iterates_healthy:\n  \"healthy (wp body) \\<Longrightarrow> healthy (iterates body G i)\"\n  by(induct i, auto intro:healthy_intros)\n\ntext {* The iterates are an ascending chain. *}\nlemma iterates_increasing:\n  fixes body::\"'s prog\"\n  assumes hb: \"healthy (wp body)\"\n  shows \"le_trans (iterates body G i) (iterates body G (Suc i))\"\nproof(induct i)\n  show \"le_trans (iterates body G 0) (iterates body G (Suc 0))\"\n  proof(simp add:iterates_def, rule le_transI)\n    fix P::\"'s expect\"\n    assume \"sound P\"\n    with hb have \"sound (wp (body ;; Embed (\\<lambda>P s. 0) \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip) P)\"\n      by(auto intro!:wp_loop_step_sound)\n    thus \"\\<lambda>s. 0 \\<tturnstile> wp (body ;; Embed (\\<lambda>P s. 0) \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip) P\"\n      by(auto)\n  qed\n\n  fix i\n  assume IH: \"le_trans (iterates body G i) (iterates body G (Suc i))\"\n  have \"equiv_trans (iterates body G (Suc i))\n                    (wp (body ;; Embed (iterates body G i) \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip))\"\n    by(simp)\n  also from iterates_healthy[OF hb]\n  have \"le_trans ... (wp (body ;; Embed (iterates body G (Suc i)) \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip))\"\n    by(blast intro:wp_loop_step_mono[OF hb IH])\n  also have \"equiv_trans ... (iterates body G (Suc (Suc i)))\"\n    by(simp)\n  finally show \"le_trans (iterates body G (Suc i)) (iterates body G (Suc (Suc i)))\" .\nqed\n\nlemma wp_loop_step_bounded:\n  fixes t::\"'s trans\" and Q::\"'s expect\"\n  assumes nQ: \"nneg Q\"\n      and bQ: \"bounded_by b Q\"\n      and ht: \"healthy t\"\n      and hb: \"healthy (wp body)\"\n  shows \"bounded_by b (wp (body ;; Embed t \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip) Q)\"\nproof(rule bounded_byI, simp add:wp_eval)\n  fix s::'s\n  from nQ bQ have sQ: \"sound Q\" by(auto)\n  with bQ ht have \"sound (t Q)\" \"bounded_by b (t Q)\" by(auto)\n  with hb have \"bounded_by b (wp body (t Q))\" by(auto)\n  with bQ have \"wp body (t Q) s \\<le> b\" \"Q s \\<le> b\" by(auto)\n  hence \"\\<guillemotleft>G\\<guillemotright> s * wp body (t Q) s + (1-\\<guillemotleft>G\\<guillemotright> s) * Q s \\<le>\n         \\<guillemotleft>G\\<guillemotright> s * b + (1-\\<guillemotleft>G\\<guillemotright> s) * b\"\n    by(auto intro:add_mono mult_left_mono)\n  also have \"... = b\" by(simp add:algebra_simps)\n  finally show \"\\<guillemotleft>G\\<guillemotright> s * wp body (t Q) s + (1-\\<guillemotleft>G\\<guillemotright> s) * Q s \\<le> b\" .\nqed\n\ntext {* This is the key result: The loop is equivalent to the supremum of its iterates.  This\nproof follows the pattern of lemma continuous\\_lfp in HOL/Library/Continuity. *}\nlemma lfp_iterates:\n  fixes body::\"'s prog\"\n  assumes hb: \"healthy (wp body)\"\n      and cb: \"bd_cts (wp body)\"\n  shows \"equiv_trans (wp (do G \\<longrightarrow> body od)) (Sup_trans (range (iterates body G)))\"\n        (is \"equiv_trans ?X ?Y\")\nproof(rule le_trans_antisym)\n  let ?F = \"\\<lambda>x. wp (body ;; Embed x \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip)\"\n  let ?bot = \"\\<lambda>(P::'s \\<Rightarrow> real) s::'s. 0::real\"\n\n  have HF: \"\\<And>i. healthy ((?F ^^ i) ?bot)\"\n  proof -\n    fix i from hb show \"(?thesis i)\"\n      by(induct i, simp_all add:healthy_intros)\n  qed\n\n  from iterates_healthy[OF hb]\n  have \"\\<And>i. feasible (iterates body G i)\" by(auto)\n  hence fSup: \"feasible (Sup_trans (range (iterates body G)))\"\n    by(auto intro:feasible_Sup_trans)\n\n  {\n    fix i\n    have \"le_trans ((?F ^^ i) ?bot) ?X\"\n    proof(induct i)\n      show \"le_trans ((?F ^^ 0) ?bot) ?X\"\n      proof(simp, intro le_transI)\n        fix P::\"'s expect\"\n        assume \"sound P\"\n        with hb healthy_wp_loop\n        have \"sound (wp (\\<mu> x. body ;; x \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip) P)\"\n          by(auto)\n        thus \"\\<lambda>s. 0 \\<tturnstile> wp (\\<mu> x. body ;; x \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip) P\"\n          by(auto)\n      qed\n      fix i\n      assume IH: \"le_trans ((?F ^^ i) ?bot) ?X\"\n      have \"equiv_trans ((?F ^^ (Suc i)) ?bot) (?F ((?F ^^ i) ?bot))\" by(simp)\n      also have \"le_trans ... (?F ?X)\"\n      proof(rule wp_loop_step_mono[OF hb IH])\n        fix P::\"'s expect\"\n        assume sP: \"sound P\"\n        with hb healthy_wp_loop\n        show \"sound (wp (\\<mu> x. body ;; x \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip) P)\"\n          by(auto)\n        from sP show \"sound ((?F ^^ i) ?bot P)\"\n          by(rule healthy_sound[OF HF])\n      qed\n      also {\n        from hb have X: \"le_trans (wp (body ;; Embed (\\<lambda>P s. bound_of P) \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip))\n                                 (\\<lambda>P s. bound_of P)\"\n          by(intro le_transI, simp add:wp_eval, auto intro: lfp_loop_fp[unfolded negate_embed])\n        have \"equiv_trans (?F ?X) ?X\"\n        unfolding wp_eval\n        by(intro iffD1[OF equiv_trans_comm, OF lfp_trans_unfold]\n                 wp_loop_step_mono[OF hb] wp_loop_step_sound[OF hb], (blast|rule X)+)\n      }\n      finally show \"le_trans ((?F ^^ (Suc i)) ?bot) ?X\" .\n    qed\n  }\n  hence \"\\<And>i. le_trans (iterates body G i) (wp do G \\<longrightarrow> body od)\"\n    by(simp add:iterates_def)\n  thus \"le_trans ?Y ?X\"\n    by(auto intro!:le_transI[OF Sup_trans_least2] sound_nneg\n                   healthy_sound[OF iterates_healthy, OF hb]\n                   healthy_bounded_byD[OF iterates_healthy, OF hb]\n                   healthy_sound[OF healthy_wp_loop] hb)\n\n  show \"le_trans ?X ?Y\"\n    unfolding wp_eval\n  proof(rule lfp_trans_lowerbound)\n    from hb cb have \"bd_cts_tr ?F\" by(rule cts_wp_loopstep)\n    with iterates_increasing[OF hb] iterates_healthy[OF hb]\n    have \"equiv_trans (?F ?Y) (Sup_trans (range (?F o (iterates body G))))\"\n      by(auto intro!:healthy_feasibleD bd_cts_trD)\n    also have \"le_trans (Sup_trans (range (?F o (iterates body G)))) ?Y\"\n    proof(rule le_transI)\n      fix P::\"'s expect\"\n      assume sP: \"sound P\"\n      show \"(Sup_trans (range (?F o (iterates body G)))) P \\<tturnstile> ?Y P\"\n      proof(rule Sup_trans_least2, clarsimp)\n        show \"\\<forall>u\\<in>range ((\\<lambda>x. wp (body ;; Embed x \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip)) \\<circ> iterates body G).\n              \\<forall>R. nneg R \\<and> bounded_by (bound_of P) R \\<longrightarrow>\n                  nneg (u R) \\<and> bounded_by (bound_of P) (u R)\"\n        proof(clarsimp, intro conjI)\n          fix Q::\"'s expect\" and i\n          assume nQ: \"nneg Q\" and bQ: \"bounded_by (bound_of P) Q\"\n          hence \"sound Q\" by(auto)\n          moreover from iterates_healthy[OF hb]\n          have \"\\<And>P. sound P \\<Longrightarrow> sound (iterates body G i P)\" by(auto)\n          moreover note hb\n          ultimately have \"sound (wp (body ;; Embed (iterates body G i) \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip) Q)\"\n            by(iprover intro:wp_loop_step_sound)\n          thus \"nneg (wp (body ;; Embed (iterates body G i) \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip) Q)\"\n            by(auto)\n          from nQ bQ iterates_healthy[OF hb] hb\n          show \"bounded_by (bound_of P) (wp (body ;; Embed (iterates body G i) \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip) Q)\"\n            by(rule wp_loop_step_bounded)\n        qed\n        from sP show \"nneg P\" \"bounded_by (bound_of P) P\" by(auto)\n      next\n        fix Q::\"'s expect\"\n        assume nQ: \"nneg Q\" and bQ: \"bounded_by (bound_of P) Q\"\n        hence \"sound Q\" by(auto)\n        with fSup have \"sound (Sup_trans (range (iterates body G)) Q)\" by(auto)\n        thus \"nneg (Sup_trans (range (iterates body G)) Q)\" by(auto)\n\n        fix i\n        show \"wp (body ;; Embed (iterates body G i) \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip) Q \\<tturnstile>\n              Sup_trans (range (iterates body G)) Q\"\n        proof(rule Sup_trans_upper2[OF _ _ nQ bQ])\n          from iterates_healthy[OF hb]\n          show \"\\<forall>u\\<in>range (iterates body G).\n                \\<forall>R. nneg R \\<and> bounded_by (bound_of P) R \\<longrightarrow>\n                     nneg (u R) \\<and> bounded_by (bound_of P) (u R)\"\n            by(auto)\n          have \"wp (body ;; Embed (iterates body G i) \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip) = iterates body G (Suc i)\"\n            by(simp)\n          also have \"... \\<in> range (iterates body G)\"\n            by(blast)\n          finally show \"wp (body ;; Embed (iterates body G i) \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip) \\<in>\n                        range (iterates body G)\" .\n        qed\n      qed\n    qed\n    finally show \"le_trans (?F ?Y) ?Y\" .\n\n    fix P::\"'s expect\"\n    assume \"sound P\"\n    with fSup show \"sound (?Y P)\" by(auto)\n  qed\nqed\n\ntext {* Therefore, evaluated at a given point (state), the sequence of iterates gives a sequence\nof real values that converges on that of the loop itself. *}\ncorollary loop_iterates:\n  fixes body::\"'s prog\"\n  assumes hb: \"healthy (wp body)\"\n      and cb: \"bd_cts (wp body)\"\n      and sP: \"sound P\"\n  shows \"(\\<lambda>i. iterates body G i P s) ----> wp (do G \\<longrightarrow> body od) P s\"\nproof -\n  let ?X = \"{f s |f. f \\<in> {t P |t. t \\<in> range (iterates body G)}}\"\n  have closure_Sup: \"Sup ?X \\<in> closure ?X\"\n  proof(rule closure_contains_Sup, simp, clarsimp)\n    fix i\n    from sP have \"bounded_by (bound_of P) P\" by(auto)\n    with iterates_healthy[OF hb] sP have \"\\<And>j. bounded_by (bound_of P) (iterates body G j P)\"\n      by(auto)\n    thus \"iterates body G i P s \\<le> bound_of P\" by(auto)    \n  qed\n\n  have \"(\\<lambda>i. iterates body G i P s) ----> Sup {f s |f. f \\<in> {t P |t. t \\<in> range (iterates body G)}}\"\n  proof(rule LIMSEQ_I)\n    fix r::real assume posr: \"0 < r\"\n    with closure_Sup obtain y where yin: \"y \\<in> ?X\" and ey: \"dist y (Sup ?X) < r\"\n      by(simp only:closure_approachable, blast)\n    from yin obtain i where yit: \"y = iterates body G i P s\" by(auto)\n    {\n      fix j\n      have \"i \\<le> j \\<longrightarrow> le_trans (iterates body G i) (iterates body G j)\"\n      proof(induct j, simp, clarify)\n        fix k\n        assume IH: \"i \\<le> k \\<longrightarrow> le_trans (iterates body G i) (iterates body G k)\"\n           and le: \"i \\<le> Suc k\"\n        show \"le_trans (iterates body G i) (iterates body G (Suc k))\"\n        proof(cases \"i = Suc k\", simp)\n          assume \"i \\<noteq> Suc k\"\n          with le have \"i \\<le> k\" by(auto)\n          with IH have \"le_trans (iterates body G i) (iterates body G k)\" by(auto)\n          also note iterates_increasing[OF hb]\n          finally show \"le_trans (iterates body G i) (iterates body G (Suc k))\" .\n        qed\n      qed\n    }\n    with sP have \"\\<forall>j\\<ge>i. iterates body G i P s \\<le> iterates body G j P s\"\n      by(auto)\n    moreover {\n      from sP have \"bounded_by (bound_of P) P\" by(auto)\n      with iterates_healthy[OF hb] sP have \"\\<And>j. bounded_by (bound_of P) (iterates body G j P)\"\n        by(auto)\n      hence \"\\<And>j. iterates body G j P s \\<le> bound_of P\" by(auto)\n      hence \"\\<And>j. iterates body G j P s \\<le> Sup ?X\"\n        by(intro cSup_upper bdd_aboveI, auto)\n    }\n    ultimately have \"\\<And>j. i \\<le> j \\<Longrightarrow>\n                           norm (iterates body G j P s - Sup ?X) \\<le>\n                           norm (iterates body G i P s - Sup ?X)\"\n      by(auto)\n    also from ey yit have \"norm (iterates body G i P s - Sup ?X) < r\"\n      by(simp add:dist_real_def)\n    finally show \"\\<exists>no. \\<forall>n\\<ge>no. norm (iterates body G n P s -\n                                    Sup {f s |f. f \\<in> {t P |t. t \\<in> range (iterates body G)}}) < r\"\n      by(auto)\n  qed\n  moreover\n  from hb cb sP have \"wp do G \\<longrightarrow> body od P s = Sup_trans (range (iterates body G)) P s\"\n    by(simp add:equiv_transD[OF lfp_iterates])\n  moreover have \"... = Sup {f s |f. f \\<in> {t P |t. t \\<in> range (iterates body G)}}\"\n    by(simp add:Sup_trans_def Sup_exp_def)\n  ultimately show ?thesis by(simp)\nqed\n\ntext {* The iterates themselves are all continuous. *}\nlemma cts_iterates:\n  fixes body::\"'s prog\"\n  assumes hb: \"healthy (wp body)\"\n      and cb: \"bd_cts (wp body)\"\n  shows \"bd_cts (iterates body G i)\"\nproof(induct i, simp_all)\n  have \"range (\\<lambda>(n::nat) (s::'s). 0::real) = {\\<lambda>s. 0::real}\"\n    by(auto)\n  thus \"bd_cts (\\<lambda>P (s::'s). 0)\"\n    by(intro bd_ctsI, simp add:o_def Sup_exp_def)\nnext\n  fix i\n  assume IH: \"bd_cts (iterates body G i)\"\n  thus \"bd_cts (wp (body ;; Embed (iterates body G i) \\<^bsub>\\<guillemotleft> G \\<guillemotright>\\<^esub>\\<oplus> Skip))\"\n    by(blast intro:cts_wp_PC cts_wp_Seq cts_wp_Embed cts_wp_Skip\n                   healthy_intros iterates_healthy cb hb)\nqed\n\ntext {* Therefore so is the loop itself. *}\nlemma cts_wp_loop:\n  fixes body::\"'s prog\"\n  assumes hb: \"healthy (wp body)\"\n      and cb: \"bd_cts (wp body)\"\n  shows \"bd_cts (wp do G \\<longrightarrow> body od)\"\nproof(rule bd_ctsI)\n  fix M::\"nat \\<Rightarrow> 's expect\" and b::real\n  assume chain: \"\\<And>i. M i \\<tturnstile> M (Suc i)\"\n     and sM: \"\\<And>i. sound (M i)\"\n     and bM: \"\\<And>i. bounded_by b (M i)\"\n\n  from sM bM iterates_healthy[OF hb]\n  have \"\\<And>j i. bounded_by b (iterates body G i (M j))\" by(blast)\n  hence iB: \"\\<And>j i s. iterates body G i (M j) s \\<le> b\" by(auto)\n\n  from sM bM have sSup: \"sound (Sup_exp (range M))\"\n    by(auto intro:Sup_exp_sound)\n  with lfp_iterates[OF hb cb]\n  have \"wp do G \\<longrightarrow> body od (Sup_exp (range M)) =\n        Sup_trans (range (iterates body G)) (Sup_exp (range M))\"\n    by(simp add:equiv_transD)\n  also {\n    from chain sM bM\n    have \"\\<And>i. iterates body G i (Sup_exp (range M)) = Sup_exp (range (iterates body G i o M))\"\n      by(blast intro:bd_ctsD cts_iterates[OF hb cb])\n    hence \"{t (Sup_exp (range M)) |t. t \\<in> range (iterates body G)} =\n           {Sup_exp (range (t o M)) |t. t \\<in> range (iterates body G)}\"\n      by(auto intro:sym)\n    hence \"Sup_trans (range (iterates body G)) (Sup_exp (range M)) =\n           Sup_exp {Sup_exp (range (t \\<circ> M)) |t. t \\<in> range (iterates body G)}\"\n      by(simp add:Sup_trans_def)\n  }\n  also {\n    have \"\\<And>s. {f s |f. \\<exists>t. f = (\\<lambda>s. Sup {f s |f. f \\<in> range (t \\<circ> M)}) \\<and>\n                           t \\<in> range (iterates body G)} =\n          range (\\<lambda>i. Sup (range (\\<lambda>j. iterates body G i (M j) s)))\"\n      (is \"\\<And>s. ?X s = ?Y s\")\n    proof(intro antisym subsetI)\n      fix s x\n      assume \"x \\<in> ?X s\"\n      then obtain t where rwx: \"x = Sup {f s |f. f \\<in> range (t \\<circ> M)}\"\n                      and \"t \\<in> range (iterates body G)\" by(auto)\n      then obtain i where \"t = iterates body G i\" by(auto)\n      with rwx have \"x = Sup {f s |f. f \\<in> range (\\<lambda>j. iterates body G i (M j))}\"\n        by(simp add:o_def)\n      moreover have \"{f s |f. f \\<in> range (\\<lambda>j. iterates body G i (M j))} =\n                     range (\\<lambda>j. iterates body G i (M j) s)\" by(auto)\n      ultimately have \"x = Sup (range (\\<lambda>j. iterates body G i (M j) s))\"\n        by(simp)\n      thus \"x \\<in> range (\\<lambda>i. Sup (range (\\<lambda>j. iterates body G i (M j) s)))\"\n        by(auto)\n    next\n      fix s x\n      assume \"x \\<in> ?Y s\"\n      then obtain i where A: \"x = Sup (range (\\<lambda>j. iterates body G i (M j) s))\"\n        by(auto)\n\n      have \"\\<And>s. {f s |f. f \\<in> range (\\<lambda>j. iterates body G i (M j))} =\n            range (\\<lambda>j. iterates body G i (M j) s)\" by(auto)\n      hence B: \"(\\<lambda>s. Sup (range (\\<lambda>j. iterates body G i (M j) s))) =\n             (\\<lambda>s. Sup {f s |f. f \\<in> range (iterates body G i o M)})\"\n        by(simp add:o_def)\n\n      have C: \"iterates body G i \\<in> range (iterates body G)\" by(auto)\n\n      have \"\\<exists>f. x = f s \\<and>\n                (\\<exists>t. f = (\\<lambda>s. Sup {f s |f. f \\<in> range (t \\<circ> M)}) \\<and>\n                     t \\<in> range (iterates body G))\"\n        by(iprover intro:A B C)\n      thus \"x \\<in> ?X s\" by(simp)\n    qed\n    hence \"Sup_exp {Sup_exp (range (t \\<circ> M)) |t. t \\<in> range (iterates body G)} = \n           (\\<lambda>s. Sup (range (\\<lambda>i. Sup (range (\\<lambda>j. iterates body G i (M j) s)))))\"\n      by(simp add:Sup_exp_def)\n  }\n  also have \"(\\<lambda>s. Sup (range (\\<lambda>i. Sup (range (\\<lambda>j. iterates body G i (M j) s))))) =\n             (\\<lambda>s. Sup (range (\\<lambda>(i,j). iterates body G i (M j) s)))\"\n    (is \"?X = ?Y\")\n  proof(rule ext, rule antisym)\n    fix s::'s\n    show \"?Y s \\<le> ?X s\"\n    proof(rule cSup_least, blast, clarify)\n      fix i j::nat\n      from iB have \"iterates body G i (M j) s \\<le> Sup (range (\\<lambda>j. iterates body G i (M j) s))\"\n        by(intro cSup_upper bdd_aboveI, auto)\n      also from iB have \"... \\<le> Sup (range (\\<lambda>i. Sup (range (\\<lambda>j. iterates body G i (M j) s))))\"\n        by(intro cSup_upper cSup_least bdd_aboveI, (blast intro:cSup_least)+)\n      finally show \"iterates body G i (M j) s \\<le>\n                    Sup (range (\\<lambda>i. Sup (range (\\<lambda>j. iterates body G i (M j) s))))\" .\n    qed\n    have \"\\<And>i j. iterates body G i (M j) s \\<le>\n                Sup (range (\\<lambda>(i, j). iterates body G i (M j) s))\"\n      by(rule cSup_upper, auto intro:iB)\n    thus \"?X s \\<le> ?Y s\"\n      by(intro cSup_least, blast, clarify, simp del:Sup_image_eq, blast intro:cSup_least)\n  qed\n  also have \"... = (\\<lambda>s. Sup (range (\\<lambda>j .Sup (range (\\<lambda>i. iterates body G i (M j) s)))))\"\n    (is \"?X = ?Y\")\n  proof(rule ext, rule antisym)\n    fix s::'s\n    have \"\\<And>i j. iterates body G i (M j) s \\<le>\n                Sup (range (\\<lambda>(i, j). iterates body G i (M j) s))\"\n      by(rule cSup_upper, auto intro:iB)\n    thus \"?Y s \\<le> ?X s\"\n      by(intro cSup_least, blast, clarify, simp del:Sup_image_eq, blast intro:cSup_least)\n    show \"?X s \\<le> ?Y s\"\n    proof(rule cSup_least, blast, clarify)\n      fix i j::nat\n      from iB have \"iterates body G i (M j) s \\<le> Sup (range (\\<lambda>i. iterates body G i (M j) s))\"\n        by(intro cSup_upper bdd_aboveI, auto)\n      also from iB have \"... \\<le> Sup (range (\\<lambda>j. Sup (range (\\<lambda>i. iterates body G i (M j) s))))\"\n        by(intro cSup_upper cSup_least bdd_aboveI, blast, blast intro:cSup_least)\n      finally show \"iterates body G i (M j) s \\<le>\n                    Sup (range (\\<lambda>j. Sup (range (\\<lambda>i. iterates body G i (M j) s))))\" .\n    qed\n  qed\n  also {\n    have \"\\<And>s. range (\\<lambda>j. Sup (range (\\<lambda>i. iterates body G i (M j) s))) =\n               {f s |f. f \\<in> range ((\\<lambda>P s. Sup {f s |f. \\<exists>t. f = t P \\<and>\n               t \\<in> range (iterates body G)}) \\<circ> M)}\" (is \"\\<And>s. ?X s = ?Y s\")\n    proof(intro antisym subsetI)\n      fix s x\n      assume \"x \\<in> ?X s\"\n      then obtain j where rwx: \"x = Sup (range (\\<lambda>i. iterates body G i (M j) s))\" by(auto)\n      moreover {\n        have \"\\<And>s. range (\\<lambda>i. iterates body G i (M j) s) =\n                   {f s |f. \\<exists>t. f = t (M j) \\<and> t \\<in> range (iterates body G)}\"\n          by(auto)\n        hence \"(\\<lambda>s. Sup (range (\\<lambda>i. iterates body G i (M j) s))) \\<in>\n              range ((\\<lambda>P s. Sup {f s |f.\n                           \\<exists>t. f = t P \\<and> t \\<in> range (iterates body G)}) \\<circ> M)\"\n          by(simp add:o_def)\n      }\n      ultimately show \"x \\<in> ?Y s\" by(auto)\n    next\n      fix s x\n      assume \"x \\<in> ?Y s\"\n      then obtain P where rwx: \"x = P s\"\n                      and Pin: \"P \\<in> range ((\\<lambda>P s. Sup {f s |f.\n                            \\<exists>t. f = t P \\<and> t \\<in> range (iterates body G)}) \\<circ> M)\"\n        by(auto)\n      then obtain j where \"P = (\\<lambda>s. Sup {f s |f. \\<exists>t. f = t (M j) \\<and>\n                                                 t \\<in> range (iterates body G)})\"\n        by(auto)\n      also {\n        have \"\\<And>s. {f s |f. \\<exists>t. f = t (M j) \\<and> t \\<in> range (iterates body G)} =\n                  range (\\<lambda>i. iterates body G i (M j) s)\" by(auto)\n        hence \"(\\<lambda>s. Sup {f s |f. \\<exists>t. f = t (M j) \\<and> t \\<in> range (iterates body G)}) =\n               (\\<lambda>s. Sup (range (\\<lambda>i. iterates body G i (M j) s)))\"\n          by(simp)\n      }\n      finally have \"x = Sup (range (\\<lambda>i. iterates body G i (M j) s))\"\n        by(simp add:rwx)\n      thus \"x \\<in> ?X s\" by(simp)\n    qed\n    hence \"(\\<lambda>s. Sup (range (\\<lambda>j .Sup (range (\\<lambda>i. iterates body G i (M j) s))))) =\n          Sup_exp (range (Sup_trans (range (iterates body G)) o M))\"\n      by(simp add:Sup_exp_def Sup_trans_def)\n  }\n  also have \"Sup_exp (range (Sup_trans (range (iterates body G)) o M)) =\n             Sup_exp (range (wp do G \\<longrightarrow> body od o M))\"\n    by(simp add:o_def equiv_transD[OF lfp_iterates, OF hb cb, OF sM])\n  finally show \"wp do G \\<longrightarrow> body od (Sup_exp (range M)) =\n                Sup_exp (range (wp do G \\<longrightarrow> body od o M))\" .\nqed\n\nlemmas cts_intros =\n  cts_wp_Abort  cts_wp_Skip\n  cts_wp_Seq    cts_wp_PC\n  cts_wp_DC     cts_wp_Embed\n  cts_wp_Apply  cts_wp_SetDC\n  cts_wp_SetPC  cts_wp_Bind\n  cts_wp_repeat\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/pGCL/LoopInduction.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5350984137988772, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.2571033784876165}}
{"text": "(*  Title:      HOL/Auth/Guard/Guard_Shared.thy\n    Author:     Frederic Blanqui, University of Cambridge Computer Laboratory\n    Copyright   2002  University of Cambridge\n*)\n\nsection\\<open>lemmas on guarded messages for protocols with symmetric keys\\<close>\n\ntheory Guard_Shared imports Guard GuardK \"../Shared\" begin\n\nsubsection\\<open>Extensions to Theory \\<open>Shared\\<close>\\<close>\n\ndeclare initState.simps [simp del]\n\nsubsubsection\\<open>a little abbreviation\\<close>\n\nabbreviation\n  Ciph :: \"agent => msg => msg\" where\n  \"Ciph A X == Crypt (shrK A) X\"\n\nsubsubsection\\<open>agent associated to a key\\<close>\n\ndefinition agt :: \"key => agent\" where\n\"agt K == SOME A. K = shrK A\"\n\nlemma agt_shrK [simp]: \"agt (shrK A) = A\"\nby (simp add: agt_def)\n\nsubsubsection\\<open>basic facts about \\<^term>\\<open>initState\\<close>\\<close>\n\nlemma no_Crypt_in_parts_init [simp]: \"Crypt K X \\<notin> parts (initState A)\"\nby (cases A, auto simp: initState.simps)\n\nlemma no_Crypt_in_analz_init [simp]: \"Crypt K X \\<notin> analz (initState A)\"\nby auto\n\nlemma no_shrK_in_analz_init [simp]: \"A \\<notin> bad\n\\<Longrightarrow> Key (shrK A) \\<notin> analz (initState Spy)\"\nby (auto simp: initState.simps)\n\nlemma shrK_notin_initState_Friend [simp]: \"A \\<noteq> Friend C\n\\<Longrightarrow> Key (shrK A) \\<notin> parts (initState (Friend C))\"\nby (auto simp: initState.simps)\n\nlemma keyset_init [iff]: \"keyset (initState A)\"\nby (cases A, auto simp: keyset_def initState.simps)\n\nsubsubsection\\<open>sets of symmetric keys\\<close>\n\ndefinition shrK_set :: \"key set => bool\" where\n\"shrK_set Ks \\<equiv> \\<forall>K. K \\<in> Ks \\<longrightarrow> (\\<exists>A. K = shrK A)\"\n\nlemma in_shrK_set: \"\\<lbrakk>shrK_set Ks; K \\<in> Ks\\<rbrakk> \\<Longrightarrow> \\<exists>A. K = shrK A\"\nby (simp add: shrK_set_def)\n\nlemma shrK_set1 [iff]: \"shrK_set {shrK A}\"\nby (simp add: shrK_set_def)\n\nlemma shrK_set2 [iff]: \"shrK_set {shrK A, shrK B}\"\nby (simp add: shrK_set_def)\n\nsubsubsection\\<open>sets of good keys\\<close>\n\ndefinition good :: \"key set \\<Rightarrow> bool\" where\n\"good Ks \\<equiv> \\<forall>K. K \\<in> Ks \\<longrightarrow> agt K \\<notin> bad\"\n\nlemma in_good: \"\\<lbrakk>good Ks; K \\<in> Ks\\<rbrakk> \\<Longrightarrow> agt K \\<notin> bad\"\nby (simp add: good_def)\n\nlemma good1 [simp]: \"A \\<notin> bad \\<Longrightarrow> good {shrK A}\"\nby (simp add: good_def)\n\nlemma good2 [simp]: \"\\<lbrakk>A \\<notin> bad; B \\<notin> bad\\<rbrakk> \\<Longrightarrow> good {shrK A, shrK B}\"\nby (simp add: good_def)\n\n\nsubsection\\<open>Proofs About Guarded Messages\\<close>\n\nsubsubsection\\<open>small hack\\<close>\n\nlemma shrK_is_invKey_shrK: \"shrK A = invKey (shrK A)\"\nby simp\n\nlemmas shrK_is_invKey_shrK_substI = shrK_is_invKey_shrK [THEN ssubst]\n\nlemmas invKey_invKey_substI = invKey [THEN ssubst]\n\nlemma \"Nonce n \\<in> parts {X} \\<Longrightarrow> Crypt (shrK A) X \\<in> guard n {shrK A}\"\napply (rule shrK_is_invKey_shrK_substI, rule invKey_invKey_substI)\nby (rule Guard_Nonce, simp+)\n\nsubsubsection\\<open>guardedness results on nonces\\<close>\n\nlemma guard_ciph [simp]: \"shrK A \\<in> Ks \\<Longrightarrow> Ciph A X \\<in> guard n Ks\"\nby (rule Guard_Nonce, simp)\n\nlemma guardK_ciph [simp]: \"shrK A \\<in> Ks \\<Longrightarrow> Ciph A X \\<in> guardK n Ks\"\nby (rule Guard_Key, simp)\n\nlemma Guard_init [iff]: \"Guard n Ks (initState B)\"\nby (induct B, auto simp: Guard_def initState.simps)\n\nlemma Guard_knows_max': \"Guard n Ks (knows_max' C evs)\n\\<Longrightarrow> Guard n Ks (knows_max C evs)\"\nby (simp add: knows_max_def)\n\nlemma Nonce_not_used_Guard_spies [dest]: \"Nonce n \\<notin> used evs\n\\<Longrightarrow> Guard n Ks (spies evs)\"\nby (auto simp: Guard_def dest: not_used_not_known parts_sub)\n\nlemma Nonce_not_used_Guard [dest]: \"\\<lbrakk>evs \\<in> p; Nonce n \\<notin> used evs;\nGets_correct p; one_step p\\<rbrakk> \\<Longrightarrow> Guard n Ks (knows (Friend C) evs)\"\nby (auto simp: Guard_def dest: known_used parts_trans)\n\nlemma Nonce_not_used_Guard_max [dest]: \"\\<lbrakk>evs \\<in> p; Nonce n \\<notin> used evs;\nGets_correct p; one_step p\\<rbrakk> \\<Longrightarrow> Guard n Ks (knows_max (Friend C) evs)\"\nby (auto simp: Guard_def dest: known_max_used parts_trans)\n\nlemma Nonce_not_used_Guard_max' [dest]: \"\\<lbrakk>evs \\<in> p; Nonce n \\<notin> used evs;\nGets_correct p; one_step p\\<rbrakk> \\<Longrightarrow> Guard n Ks (knows_max' (Friend C) evs)\"\napply (rule_tac H=\"knows_max (Friend C) evs\" in Guard_mono)\nby (auto simp: knows_max_def)\n\nsubsubsection\\<open>guardedness results on keys\\<close>\n\nlemma GuardK_init [simp]: \"n \\<notin> range shrK \\<Longrightarrow> GuardK n Ks (initState B)\"\nby (induct B, auto simp: GuardK_def initState.simps)\n\nlemma GuardK_knows_max': \"\\<lbrakk>GuardK n A (knows_max' C evs); n \\<notin> range shrK\\<rbrakk>\n\\<Longrightarrow> GuardK n A (knows_max C evs)\"\nby (simp add: knows_max_def)\n\nlemma Key_not_used_GuardK_spies [dest]: \"Key n \\<notin> used evs\n\\<Longrightarrow> GuardK n A (spies evs)\"\nby (auto simp: GuardK_def dest: not_used_not_known parts_sub)\n\nlemma Key_not_used_GuardK [dest]: \"\\<lbrakk>evs \\<in> p; Key n \\<notin> used evs;\nGets_correct p; one_step p\\<rbrakk> \\<Longrightarrow> GuardK n A (knows (Friend C) evs)\"\nby (auto simp: GuardK_def dest: known_used parts_trans)\n\nlemma Key_not_used_GuardK_max [dest]: \"\\<lbrakk>evs \\<in> p; Key n \\<notin> used evs;\nGets_correct p; one_step p\\<rbrakk> \\<Longrightarrow> GuardK n A (knows_max (Friend C) evs)\"\nby (auto simp: GuardK_def dest: known_max_used parts_trans)\n\nlemma Key_not_used_GuardK_max' [dest]: \"\\<lbrakk>evs \\<in> p; Key n \\<notin> used evs;\nGets_correct p; one_step p\\<rbrakk> \\<Longrightarrow> GuardK n A (knows_max' (Friend C) evs)\"\napply (rule_tac H=\"knows_max (Friend C) evs\" in GuardK_mono)\nby (auto simp: knows_max_def)\n\nsubsubsection\\<open>regular protocols\\<close>\n\ndefinition regular :: \"event list set => bool\" where\n\"regular p \\<equiv> \\<forall>evs A. evs \\<in> p \\<longrightarrow> (Key (shrK A) \\<in> parts (spies evs)) = (A \\<in> bad)\"\n\nlemma shrK_parts_iff_bad [simp]: \"\\<lbrakk>evs \\<in> p; regular p\\<rbrakk> \\<Longrightarrow>\n(Key (shrK A) \\<in> parts (spies evs)) = (A \\<in> bad)\"\nby (auto simp: regular_def)\n\nlemma shrK_analz_iff_bad [simp]: \"\\<lbrakk>evs \\<in> p; regular p\\<rbrakk> \\<Longrightarrow>\n(Key (shrK A) \\<in> analz (spies evs)) = (A \\<in> bad)\"\nby auto\n\nlemma Guard_Nonce_analz: \"\\<lbrakk>Guard n Ks (spies evs); evs \\<in> p;\nshrK_set Ks; good Ks; regular p\\<rbrakk> \\<Longrightarrow> Nonce n \\<notin> analz (spies evs)\"\napply (clarify, simp only: knows_decomp)\napply (drule Guard_invKey_keyset, simp+, safe)\napply (drule in_good, simp)\napply (drule in_shrK_set, simp+, clarify)\napply (frule_tac A=A in shrK_analz_iff_bad)\nby (simp add: knows_decomp)+\n\nlemma GuardK_Key_analz:\n  assumes \"GuardK n Ks (spies evs)\" \"evs \\<in> p\" \"shrK_set Ks\"\n    \"good Ks\" \"regular p\" \"n \\<notin> range shrK\"\n  shows \"Key n \\<notin> analz (spies evs)\"\nproof (rule ccontr)\n  assume \"\\<not> Key n \\<notin> analz (knows Spy evs)\"\n  then have *: \"Key n \\<in> analz (spies' evs \\<union> initState Spy)\"\n    by (simp add: knows_decomp)\n  from \\<open>GuardK n Ks (spies evs)\\<close>\n  have \"GuardK n Ks (spies' evs \\<union> initState Spy)\"\n    by (simp add: knows_decomp)  \n  then have \"GuardK n Ks (spies' evs)\"\n    and \"finite (spies' evs)\" \"keyset (initState Spy)\"\n    by simp_all\n  moreover have \"Key n \\<notin> initState Spy\"\n    using \\<open>n \\<notin> range shrK\\<close> by (simp add: image_iff initState_Spy)\n  ultimately obtain K\n    where \"K \\<in> Ks\" and **: \"Key K \\<in> analz (spies' evs \\<union> initState Spy)\"\n    using * by (auto dest: GuardK_invKey_keyset)\n  from \\<open>K \\<in> Ks\\<close> and \\<open>good Ks\\<close> have \"agt K \\<notin> bad\"\n    by (auto dest: in_good)\n  from \\<open>K \\<in> Ks\\<close> \\<open>shrK_set Ks\\<close> obtain A\n    where \"K = shrK A\"\n    by (auto dest: in_shrK_set)\n  then have \"agt K \\<in> bad\"\n    using ** \\<open>evs \\<in> p\\<close> \\<open>regular p\\<close> shrK_analz_iff_bad [of evs p \"agt K\"]\n    by (simp add: knows_decomp)\n  with \\<open>agt K \\<notin> bad\\<close> show False by simp\nqed\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/Auth/Guard/Guard_Shared.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621765155565326, "lm_q2_score": 0.45713671682749485, "lm_q1q2_score": 0.2569915265990344}}
{"text": "subsection \\<open>1-out-of-4 OT to GMW\\<close>\n\ntext\\<open>We prove security for the gates of the GMW protocol in the semi honest model. We assume security on\n1-out-of-4 OT.\\<close>\n\ntheory GMW imports\n  OT14\nbegin\n\ntype_synonym share_1 = bool \ntype_synonym share_2 = bool\n\ntype_synonym shares_1 = \"bool list\"\ntype_synonym shares_2 = \"bool list\"\n\ntype_synonym msgs_14_OT = \"(bool \\<times> bool \\<times> bool \\<times> bool)\"\ntype_synonym choice_14_OT = \"(bool \\<times> bool)\"\n\ntype_synonym share_wire = \"(share_1 \\<times> share_2)\"\n\nlocale gmw_base =\n  fixes S1_14_OT :: \"msgs_14_OT \\<Rightarrow> unit \\<Rightarrow> 'v_14_OT1 spmf\" \\<comment> \\<open>simulated view for party 1 of OT14\\<close>\n    and R1_14_OT :: \"msgs_14_OT \\<Rightarrow> choice_14_OT \\<Rightarrow> 'v_14_OT1 spmf\" \\<comment> \\<open>real view for party 1 of OT14\\<close>\n    and S2_14_OT :: \"choice_14_OT \\<Rightarrow> bool \\<Rightarrow> 'v_14_OT2 spmf\" \n    and R2_14_OT :: \"msgs_14_OT \\<Rightarrow> choice_14_OT \\<Rightarrow> 'v_14_OT2 spmf\"\n    and protocol_14_OT :: \"msgs_14_OT \\<Rightarrow> choice_14_OT \\<Rightarrow> (unit \\<times> bool) spmf\"\n    and adv_14_OT :: real\n  assumes P1_OT_14_adv_bound: \"sim_det_def.adv_P1 R1_14_OT S1_14_OT funct_14_OT M C D \\<le> adv_14_OT\" \\<comment> \\<open>bound the advantage of party 1 in the 1-out-of-4 OT\\<close>\n    and P2_OT_12_inf_theoretic: \"sim_det_def.perfect_sec_P2 R2_14_OT S2_14_OT funct_14_OT M C\" \\<comment> \\<open>information theoretic security for party 2 in the 1-out-of-4 OT\\<close>\n    and correct_14: \"funct_OT_14 msgs C = protocol_14_OT msgs C\" \\<comment> \\<open>correctness of the 1-out-of-4 OT\\<close>\n    and lossless_R1_14_OT: \"lossless_spmf (R1_14_OT (m1,m2,m3,m4) (c0,c1))\"\n    and lossless_R2_14_OT: \"lossless_spmf (R2_14_OT (m1,m2,m3,m4) (c0,c1))\"\n    and lossless_S1_14_OT: \"lossless_spmf (S1_14_OT (m1,m2,m3,m4) ())\"\n    and lossless_S2_14_OT: \"lossless_spmf (S2_14_OT (c0,c1) b)\"\n    and lossless_protocol_14_OT: \"lossless_spmf (protocol_14_OT S C)\" \n    and lossless_funct_14_OT: \"lossless_spmf (funct_14_OT M C)\"\nbegin\n\nlemma  funct_14: \"funct_OT_14 (m00,m01,m10,m11) (c0,c1) \n                      = return_spmf ((),if c0 then (if c1 then m11 else m10) else (if c1 then m01 else m00))\"\n  by(simp add: funct_OT_14_def)\n\nsublocale OT_14_sim: sim_det_def R1_14_OT S1_14_OT R2_14_OT S2_14_OT funct_14_OT protocol_14_OT\n  unfolding sim_det_def_def \n  by(simp add: lossless_R1_14_OT lossless_S1_14_OT lossless_funct_14_OT lossless_R2_14_OT lossless_S2_14_OT)\n\nlemma inf_th_14_OT_P4: \"R2_14_OT msgs C = (funct_OT_14 msgs C \\<bind> (\\<lambda> (s1, s2). S2_14_OT C s2))\" \n  using P2_OT_12_inf_theoretic sim_det_def.perfect_sec_P2_def OT_14_sim.perfect_sec_P2_def by auto\n\nlemma ass_adv_14_OT: \"\\<bar>spmf (bind_spmf (S1_14_OT msgs ()) (\\<lambda> view. (D view))) True - \n                    spmf (bind_spmf (R1_14_OT msgs (c0,c1)) (\\<lambda> view. (D view))) True \\<bar> \\<le> adv_14_OT\"\n  (is \"?lhs \\<le> adv_14_OT\")\nproof-\n  have \"funct_OT_14 (m0,m1,m2,m3) (c0, c1) \\<bind> (\\<lambda>(o1, o2). S1_14_OT (m0,m1,m2,m3) () \\<bind> D) = S1_14_OT (m0,m1,m2,m3) () \\<bind> D\" \n    for m0 m1 m2 m3 by(simp add: funct_14)\n  hence funct: \"funct_OT_14 msgs (c0, c1) \\<bind> (\\<lambda>(o1, o2). S1_14_OT msgs () \\<bind> D) = S1_14_OT msgs () \\<bind> D\" \n    by (metis prod_cases4)\n  have \"?lhs = \\<bar>spmf (bind_spmf (R1_14_OT msgs (c0,c1)) (\\<lambda> view. (D view))) True \n                  - spmf (bind_spmf (S1_14_OT msgs ()) (\\<lambda> view. (D view))) True\\<bar>\"\n    by linarith\n  hence \"... = \\<bar>(spmf (R1_14_OT msgs (c0,c1) \\<bind> (\\<lambda> view. D view)) True) \n            - spmf (funct_OT_14 msgs (c0,c1) \\<bind> (\\<lambda> (o1, o2). S1_14_OT msgs o1 \\<bind> (\\<lambda> view. D view))) True\\<bar>\" \n    by(simp add: funct)\n  thus ?thesis using P1_OT_14_adv_bound sim_det_def.adv_P1_def \n    by (simp add: OT_14_sim.adv_P1_def abs_minus_commute)\nqed\n\ntext \\<open>The sharing scheme\\<close>\n\ndefinition share :: \"bool \\<Rightarrow> share_wire spmf\"\n  where \"share x = do {\n    a\\<^sub>1 \\<leftarrow> coin_spmf;\n    let b\\<^sub>1 = x \\<oplus> a\\<^sub>1;\n    return_spmf (a\\<^sub>1, b\\<^sub>1)}\" \n\nlemma lossless_share [simp]: \"lossless_spmf (share x)\" \n  by(simp add: share_def)\n\ndefinition reconstruct :: \"(share_1 \\<times> share_2) \\<Rightarrow> bool spmf\"\n  where \"reconstruct shares = do {\n    let (a,b) = shares;\n    return_spmf (a \\<oplus> b)}\"\n\nlemma lossless_reconstruct [simp]: \"lossless_spmf (reconstruct s)\" \n  by(simp add: reconstruct_def split_def)\n\nlemma reconstruct_share : \"(bind_spmf (share x) reconstruct) = (return_spmf x)\"\nproof-\n  have \"y = (y = x) = x\" for y by auto\n  thus ?thesis \n    by(auto simp add: share_def reconstruct_def bind_spmf_const eq_commute)  \nqed\n\nlemma \"(reconstruct (s1,s2) \\<bind> (\\<lambda> rec. share rec \\<bind> (\\<lambda> shares. reconstruct shares))) = return_spmf (s1 \\<oplus> s2)\"\n  apply(simp add: reconstruct_share reconstruct_def share_def)\n  apply(cases s1; cases s2) by(auto simp add: bind_spmf_const)\n\ndefinition xor_evaluate ::  \"bool \\<Rightarrow> bool \\<Rightarrow> bool spmf\"\n  where \"xor_evaluate A B = return_spmf (A \\<oplus> B)\"\n\ndefinition xor_funct :: \"share_wire \\<Rightarrow> share_wire \\<Rightarrow> (bool \\<times> bool) spmf\"\n  where \"xor_funct A B = do {\n    let (a1, b1) = A;\n    let (a2,b2) = B;\n    return_spmf (a1 \\<oplus> a2, b1 \\<oplus> b2)}\"\n\nlemma lossless_xor_funct: \"lossless_spmf (xor_funct A B)\"\n  by(simp add: xor_funct_def split_def)\n\ndefinition xor_protocol :: \"share_wire \\<Rightarrow> share_wire \\<Rightarrow> (bool \\<times> bool) spmf\"\n  where \"xor_protocol A B = do {\n    let (a1, b1) = A;\n    let (a2,b2) = B;\n    return_spmf (a1 \\<oplus> a2, b1 \\<oplus> b2)}\"\n\nlemma lossless_xor_protocol: \"lossless_spmf (xor_protocol A B)\"\n  by(simp add: xor_protocol_def split_def)\n\nlemma share_xor_reconstruct: \n  shows \"share x \\<bind> (\\<lambda> w1. share y \\<bind> (\\<lambda> w2. xor_protocol w1 w2 \n              \\<bind> (\\<lambda> (a, b). reconstruct (a, b)))) = xor_evaluate x y\"\nproof-\n  have \"(ya = (\\<not> yb)) = ((x = (\\<not> ya)) = (y = (\\<not> yb))) = (x = (\\<not> y))\" for ya yb\n    by auto\n  then show ?thesis\n    by(simp add: share_def xor_protocol_def reconstruct_def xor_evaluate_def bind_spmf_const)\nqed\n\ndefinition R1_xor :: \"(bool \\<times> bool) \\<Rightarrow> (bool \\<times> bool) \\<Rightarrow> (bool \\<times> bool) spmf\"\n  where \"R1_xor A B = return_spmf A\"\n\nlemma lossless_R1_xor: \"lossless_spmf (R1_xor A B)\" \n  by(simp add: R1_xor_def)\n\ndefinition S1_xor :: \"(bool \\<times> bool) \\<Rightarrow> bool \\<Rightarrow> (bool \\<times> bool) spmf\"\n  where \"S1_xor A out  = return_spmf A\"\n\nlemma lossless_S1_xor: \"lossless_spmf (S1_xor A out)\" \n  by(simp add: S1_xor_def)\n\nlemma P1_xor_inf_th: \"R1_xor A B = xor_funct A B \\<bind> (\\<lambda> (out1, out2). S1_xor A out1)\"\n  by(simp add: R1_xor_def xor_funct_def S1_xor_def split_def)\n\ndefinition R2_xor :: \"(bool \\<times> bool) \\<Rightarrow> (bool \\<times> bool) \\<Rightarrow> (bool \\<times> bool) spmf\"\n  where \"R2_xor A B = return_spmf B\"\n\nlemma lossless_R2_xor: \"lossless_spmf (R2_xor A B)\" \n  by(simp add: R2_xor_def)\n\ndefinition S2_xor :: \"(bool \\<times> bool) \\<Rightarrow> bool \\<Rightarrow> (bool \\<times> bool) spmf\"\n  where \"S2_xor B out  = return_spmf B\"\n\nlemma lossless_S2_xor: \"lossless_spmf (S2_xor A out)\" \n  by(simp add: S2_xor_def)\n\nlemma P2_xor_inf_th: \"R2_xor A B = xor_funct A B \\<bind> (\\<lambda> (out1, out2). S2_xor B out2)\"\n  by(simp add: R2_xor_def xor_funct_def S2_xor_def split_def)\n\nsublocale xor_sim_det: sim_det_def  R1_xor S1_xor R2_xor S2_xor xor_funct xor_protocol \n  unfolding sim_det_def_def\n  by(simp add: lossless_R1_xor lossless_S1_xor lossless_R2_xor lossless_S2_xor lossless_xor_funct)\n\nlemma \"xor_sim_det.perfect_sec_P1 m1 m2\"\n  by(simp add: xor_sim_det.perfect_sec_P1_def P1_xor_inf_th)\n\nlemma \"xor_sim_det.perfect_sec_P2 m1 m2\"\n  by(simp add: xor_sim_det.perfect_sec_P2_def P2_xor_inf_th)\n\ndefinition and_funct :: \"(share_1 \\<times> share_2) \\<Rightarrow> (share_1 \\<times> share_2) \\<Rightarrow> share_wire spmf\"\n  where \"and_funct A B = do {\n    let (a1, a2) = A;\n    let (b1,b2) = B;\n    \\<sigma> \\<leftarrow> coin_spmf;\n    return_spmf (\\<sigma>, \\<sigma> \\<oplus> ((a1 \\<oplus> b1) \\<and> (a2 \\<oplus> b2)))}\"\n\nlemma lossless_and_funct: \"lossless_spmf (and_funct A B)\"\n  by(simp add: and_funct_def split_def)\n\ndefinition and_evaluate :: \"bool \\<Rightarrow> bool \\<Rightarrow> bool spmf\"\n  where \"and_evaluate A B  = return_spmf (A \\<and> B)\"\n\ndefinition and_protocol :: \"share_wire \\<Rightarrow> share_wire \\<Rightarrow> share_wire spmf\"\n  where \"and_protocol A B = do {\n    let (a1, b1) = A;\n    let (a2,b2) = B;\n    \\<sigma> \\<leftarrow> coin_spmf;\n    let s0 = \\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (b1 \\<oplus> False));   \n    let s1 = \\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (b1 \\<oplus> True));   \n    let s2 = \\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (b1 \\<oplus> False));   \n    let s3 = \\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (b1 \\<oplus> True)); \n    (_, s) \\<leftarrow> protocol_14_OT (s0,s1,s2,s3) (a2,b2);\n    return_spmf (\\<sigma>, s)}\" \n\nlemma lossless_and_protocol: \"lossless_spmf (and_protocol A B)\"\n  by(simp add: and_protocol_def split_def lossless_protocol_14_OT)\n\nlemma and_correct: \"and_protocol (a1, b1) (a2,b2) = and_funct (a1, b1) (a2,b2)\"\n  apply(simp add: and_protocol_def and_funct_def correct_14[symmetric] funct_14)\n  by(cases b2 ; cases b1; cases a1; cases a2; auto)\n\nlemma share_and_reconstruct: \n  shows \"share x \\<bind> (\\<lambda> (a1,a2). share y \\<bind> (\\<lambda> (b1,b2).\n             and_protocol (a1,b1) (a2,b2) \\<bind> (\\<lambda> (a, b). reconstruct (a, b)))) = and_evaluate x y\"\nproof-\n  have \"(yc = (\\<not> (if x = (\\<not> ya) then if snd (snd (ya, x = (\\<not> ya)), snd (yb, y = (\\<not> yb))) then yc \n            = (fst (fst (ya, x = (\\<not> ya)), fst (yb, y = (\\<not> yb))) \\<or> snd (fst (ya, x = (\\<not> ya)), fst (yb, y = (\\<not> yb))))\n                   else yc = (fst (fst (ya, x = (\\<not> ya)), fst (yb, y = (\\<not> yb))) \\<or> \\<not> snd (fst (ya, x = (\\<not> ya)), fst (yb, y = (\\<not> yb))))\n                       else if snd (snd (ya, x = (\\<not> ya)), snd (yb, y = (\\<not> yb))) then yc = (fst (fst (ya, x = (\\<not> ya)), fst (yb, y = (\\<not> yb))) \n                            \\<longrightarrow> snd (fst (ya, x = (\\<not> ya)), fst (yb, y = (\\<not> yb))))\n                                  else yc = (fst (fst (ya, x = (\\<not> ya)), fst (yb, y = (\\<not> yb))) \n                                      \\<longrightarrow> \\<not> snd (fst (ya, x = (\\<not> ya)), fst (yb, y = (\\<not> yb))))))) = (x \\<and> y)\"\n    for yc yb ya by auto\n  then show ?thesis \n    by(auto simp add: share_def reconstruct_def and_protocol_def and_evaluate_def split_def correct_14[symmetric] funct_14 bind_spmf_const Let_def)\nqed\n\ndefinition and_R1 :: \"(share_1 \\<times> share_1) \\<Rightarrow> (share_2 \\<times> share_2) \\<Rightarrow> (((share_1 \\<times> share_1) \\<times> bool \\<times> 'v_14_OT1)  \\<times> (share_1 \\<times> share_2)) spmf\"\n  where \"and_R1 A B = do {\n    let (a1, a2) = A;\n    let (b1,b2) = B;\n    \\<sigma> \\<leftarrow> coin_spmf;\n    let s0 = \\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> False));   \n    let s1 = \\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> True));   \n    let s2 = \\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> False));   \n    let s3 = \\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> True)); \n    V \\<leftarrow> R1_14_OT (s0,s1,s2,s3) (b1,b2);\n    (_, s) \\<leftarrow> protocol_14_OT (s0,s1,s2,s3) (b1,b2);\n    return_spmf (((a1,a2), \\<sigma>, V), (\\<sigma>, s))}\"\n\nlemma lossless_and_R1: \"lossless_spmf (and_R1 A B)\"\n  apply(simp add: and_R1_def split_def lossless_R1_14_OT lossless_protocol_14_OT Let_def)\n  by (metis prod.collapse lossless_R1_14_OT)\n\ndefinition S1_and :: \"(share_1 \\<times> share_1) \\<Rightarrow> bool \\<Rightarrow> (((bool \\<times> bool) \\<times> bool \\<times> 'v_14_OT1)) spmf\"\n  where \"S1_and A \\<sigma> = do {\n    let (a1,a2) = A;\n    let s0 = \\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> False));   \n    let s1 = \\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> True));   \n    let s2 = \\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> False));   \n    let s3 = \\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> True)); \n    V \\<leftarrow> S1_14_OT (s0,s1,s2,s3) ();\n    return_spmf ((a1,a2), \\<sigma>, V)}\"\n\ndefinition out1 :: \"(share_1 \\<times> share_1) \\<Rightarrow> (share_2 \\<times> share_2) \\<Rightarrow> bool \\<Rightarrow> (share_1 \\<times> share_2) spmf\"\n  where \"out1 A B \\<sigma> = do {\n    let (a1,a2) = A;\n    let (b1,b2) = B;\n    return_spmf (\\<sigma>, \\<sigma> \\<oplus> ((a1 \\<oplus> b1) \\<and> (a2 \\<oplus> b2)))}\"\n\ndefinition S1_and' :: \"(share_1 \\<times> share_1) \\<Rightarrow> (share_2 \\<times> share_2) \\<Rightarrow> bool \\<Rightarrow> (((bool \\<times> bool) \\<times> bool \\<times> 'v_14_OT1) \\<times> (share_1 \\<times> share_2)) spmf\"\n  where \"S1_and' A B \\<sigma> = do {\n    let (a1,a2) = A;\n    let (b1,b2) = B;\n    let s0 = \\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> False));   \n    let s1 = \\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> True));   \n    let s2 = \\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> False));   \n    let s3 = \\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> True)); \n    V \\<leftarrow> S1_14_OT (s0,s1,s2,s3) ();\n    return_spmf (((a1,a2), \\<sigma>, V), (\\<sigma>, \\<sigma> \\<oplus> ((a1 \\<oplus> b1) \\<and> (a2 \\<oplus> b2))))}\"\n\nlemma sec_ex_P1_and: \n  shows \"\\<exists> (A :: 'v_14_OT1 \\<Rightarrow> bool \\<Rightarrow> bool spmf).\n          \\<bar>spmf ((and_funct (a1, a2) (b1,b2)) \\<bind> (\\<lambda> (s1, s2). (S1_and' (a1,a2) (b1,b2) s1) \n            \\<bind> (D :: (((bool \\<times> bool) \\<times> bool \\<times> 'v_14_OT1) \\<times> (share_1 \\<times> share_2)) \\<Rightarrow> bool spmf))) True - spmf ((and_R1 (a1, a2) (b1,b2)) \\<bind> D) True\\<bar> =\n              \\<bar>spmf (coin_spmf \\<bind> (\\<lambda> \\<sigma>. S1_14_OT ((\\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> False))), (\\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> True))), (\\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> False))), (\\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> True)))) () \n                \\<bind>  (\\<lambda> view. A view \\<sigma>))) True \n                  - spmf (coin_spmf \\<bind> (\\<lambda> \\<sigma>. R1_14_OT ((\\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> False))), (\\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> True))), (\\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> False))), (\\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> True)))) (b1, b2) \n                    \\<bind> (\\<lambda> view. A view \\<sigma>))) True\\<bar>\"\n  including monad_normalisation\nproof-\n  define A' where \"A' == \\<lambda> view \\<sigma>.  (D (((a1,a2), \\<sigma>, view), (\\<sigma>, \\<sigma> \\<oplus> ((a1 \\<oplus> b1) \\<and> (a2 \\<oplus> b2)))))\" \n  have \"\\<bar>spmf ((and_funct (a1, a2) (b1,b2)) \\<bind> (\\<lambda> (s1, s2). (S1_and' (a1,a2) (b1,b2) s1) \n          \\<bind> (D :: (((bool \\<times> bool) \\<times> bool \\<times> 'v_14_OT1) \\<times> (share_1 \\<times> share_2)) \\<Rightarrow> bool spmf))) True - \n            spmf ((and_R1 (a1, a2) (b1,b2)) \\<bind> (D :: (((bool \\<times> bool) \\<times> bool \\<times> 'v_14_OT1) \\<times> (bool \\<times> bool)) \\<Rightarrow> bool spmf)) True\\<bar> =\n              \\<bar>spmf (coin_spmf \\<bind> (\\<lambda> \\<sigma> :: bool. S1_14_OT ((\\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> False))), (\\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> True))), (\\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> False))), (\\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> True)))) () \n                \\<bind>  (\\<lambda> view. A' view \\<sigma>))) True - spmf (coin_spmf \\<bind> (\\<lambda> \\<sigma>. R1_14_OT ((\\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> False))), (\\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> True))), (\\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> False))), (\\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> True)))) (b1, b2) \n                  \\<bind> (\\<lambda> view. A' view \\<sigma>))) True\\<bar>\"\n    by(auto simp add: S1_and'_def A'_def and_funct_def and_R1_def Let_def split_def correct_14[symmetric] funct_14; cases a1; cases a2; cases b1; cases b2; auto)\n  then show ?thesis by auto\nqed\n\nlemma bound_14_OT:\n  \"\\<bar>spmf (coin_spmf \\<bind> (\\<lambda> \\<sigma>. S1_14_OT ((\\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> False))), (\\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> True))), (\\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> False))), (\\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> True)))) () \n        \\<bind>  (\\<lambda> view. (A :: 'v_14_OT1 \\<Rightarrow> bool \\<Rightarrow> bool spmf) view \\<sigma>))) True - spmf (coin_spmf \\<bind> (\\<lambda> \\<sigma>. R1_14_OT ((\\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> False))), (\\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> True))), (\\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> False))), (\\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> True)))) (b1, b2) \n              \\<bind> (\\<lambda> view. A view \\<sigma>))) True\\<bar> \\<le> adv_14_OT\"\n  (is \"?lhs \\<le> adv_14_OT\")\nproof-\n  have int1: \"integrable (measure_spmf coin_spmf) (\\<lambda>x. spmf (S1_14_OT (x \\<oplus> (a1 \\<oplus> False \\<and> a2 \\<oplus> False), x \\<oplus> (a1 \\<oplus> False \\<and> a2 \\<oplus> True), x \\<oplus> (a1 \\<oplus> True \\<and> a2 \\<oplus> False), x \\<oplus> (a1 \\<oplus> True \\<and> a2 \\<oplus> True)) () \\<bind> (\\<lambda>view. A view x)) True)\"\n    and int2: \"integrable (measure_spmf coin_spmf) (\\<lambda>x. spmf (R1_14_OT (x \\<oplus> (a1 \\<oplus> False \\<and> a2 \\<oplus> False), x \\<oplus> (a1 \\<oplus> False \\<and> a2 \\<oplus> True), x \\<oplus> (a1 \\<oplus> True \\<and> a2 \\<oplus> False), x \\<oplus> (a1 \\<oplus> True \\<and> a2 \\<oplus> True)) (b1, b2) \\<bind> (\\<lambda>view. A view x)) True)\"\n    by(rule measure_spmf.integrable_const_bound[where B=1]; simp add: pmf_le_1)+\n  have \"?lhs = \\<bar>LINT x|measure_spmf coin_spmf.\n        spmf (S1_14_OT (x \\<oplus> (a1 \\<oplus> False \\<and> a2 \\<oplus> False), x \\<oplus> (a1 \\<oplus> False \\<and> a2 \\<oplus> True), x \\<oplus> (a1 \\<oplus> True \\<and> a2 \\<oplus> False), x \\<oplus> (a1 \\<oplus> True \\<and> a2 \\<oplus> True)) () \\<bind> (\\<lambda>view. A view x)) True -\n        spmf (R1_14_OT (x \\<oplus> (a1 \\<oplus> False \\<and> a2 \\<oplus> False), x \\<oplus> (a1 \\<oplus> False \\<and> a2 \\<oplus> True), x \\<oplus> (a1 \\<oplus> True \\<and> a2 \\<oplus> False), x \\<oplus> (a1 \\<oplus> True \\<and> a2 \\<oplus> True)) (b1, b2) \\<bind> (\\<lambda>view. A view x)) True\\<bar>\"\n    apply(subst (1 2) spmf_bind) using int1 int2 by simp\n  also have \"... \\<le> LINT x|measure_spmf coin_spmf. \\<bar>spmf (S1_14_OT (x = (a1 \\<longrightarrow> \\<not> a2), x = (a1 \\<longrightarrow> a2), x = (a1 \\<or> \\<not> a2), x = (a1 \\<or> a2)) () \\<bind> (\\<lambda>view. A view x)) True \n                - spmf (R1_14_OT (x = (a1 \\<longrightarrow> \\<not> a2), x = (a1 \\<longrightarrow> a2), x = (a1 \\<or> \\<not> a2), x = (a1 \\<or> a2)) (b1, b2) \\<bind> (\\<lambda>view. A view x)) True\\<bar>\"\n    by(rule integral_abs_bound[THEN order_trans]; simp add: split_beta)\n  ultimately have \"?lhs \\<le> LINT x|measure_spmf coin_spmf. \\<bar>spmf (S1_14_OT (x = (a1 \\<longrightarrow> \\<not> a2), x = (a1 \\<longrightarrow> a2), x = (a1 \\<or> \\<not> a2), x = (a1 \\<or> a2)) () \\<bind> (\\<lambda>view. A view x)) True \n                - spmf (R1_14_OT (x = (a1 \\<longrightarrow> \\<not> a2), x = (a1 \\<longrightarrow> a2), x = (a1 \\<or> \\<not> a2), x = (a1 \\<or> a2)) (b1, b2) \\<bind> (\\<lambda>view. A view x)) True\\<bar>\"\n    by simp\n  also have \"LINT x|measure_spmf coin_spmf. \\<bar>spmf (S1_14_OT (x = (a1 \\<longrightarrow> \\<not> a2), x = (a1 \\<longrightarrow> a2), x = (a1 \\<or> \\<not> a2), x = (a1 \\<or> a2)) () \\<bind> (\\<lambda>view. A view x)) True \n                - spmf (R1_14_OT (x = (a1 \\<longrightarrow> \\<not> a2), x = (a1 \\<longrightarrow> a2), x = (a1 \\<or> \\<not> a2), x = (a1 \\<or> a2)) (b1, b2) \\<bind> (\\<lambda>view. A view x)) True\\<bar> \\<le> adv_14_OT\"\n    apply(rule integral_mono[THEN order_trans]) \n       apply(rule measure_spmf.integrable_const_bound[where B=2])\n        apply clarsimp\n        apply(rule abs_triangle_ineq4[THEN order_trans])\n        apply(cases a1) apply(cases a2) \n    subgoal for M\n      using pmf_le_1[of \"R1_14_OT (\\<not> M, M, M, M) (b1,b2) \\<bind>  (\\<lambda> view. A view M)\" \"Some True\"]\n        pmf_le_1[of \"S1_14_OT (\\<not> M, M, M, M) () \\<bind>  (\\<lambda> view. A view M)\" \"Some True\"] \n      by simp\n    subgoal for M \n      using pmf_le_1[of \"R1_14_OT  (M, \\<not> M, M, M) (b1,b2) \\<bind>  (\\<lambda> view. A view M)\" \"Some True\"] \n        pmf_le_1[of \"S1_14_OT (M, \\<not> M, M, M) () \\<bind>  (\\<lambda> view. A view M)\" \"Some True\"] \n      by simp\n        apply(cases a2) apply(auto)\n    subgoal for M\n      using pmf_le_1[of \"R1_14_OT  (M, M, \\<not> M, M) (b1,b2) \\<bind>  (\\<lambda> view. A view M)\" \"Some True\"] \n        pmf_le_1[of \"S1_14_OT (M, M, \\<not> M, M) () \\<bind>  (\\<lambda> view. A view M)\" \"Some True\"] \n      by(simp)\n    subgoal for M\n      using pmf_le_1[of \"R1_14_OT  (M, M, M, \\<not> M) (b1,b2) \\<bind>  (\\<lambda> view. A view M)\" \"Some True\"] \n        pmf_le_1[of \"S1_14_OT (M, M, M, \\<not> M) () \\<bind>  (\\<lambda> view. A view M)\" \"Some True\"] \n      by(simp)\n    using ass_adv_14_OT by fast\n  ultimately show ?thesis by simp\nqed\n\nlemma security_and_P1:\n  shows \"\\<bar>spmf ((and_funct (a1, a2) (b1,b2)) \\<bind> (\\<lambda> (s1, s2). (S1_and' (a1,a2) (b1,b2) s1) \n              \\<bind> (D :: (((bool \\<times> bool) \\<times> bool \\<times> 'v_14_OT1) \\<times> (share_1 \\<times> share_2)) \\<Rightarrow> bool spmf))) True - \n                    spmf ((and_R1 (a1, a2) (b1,b2)) \\<bind> D) True\\<bar> \\<le> adv_14_OT\"\nproof-\n  obtain A :: \"'v_14_OT1 \\<Rightarrow> bool \\<Rightarrow> bool spmf\" where A: \n    \"\\<bar>spmf ((and_funct (a1, a2) (b1,b2)) \\<bind> (\\<lambda> (s1, s2). (S1_and' (a1,a2) (b1,b2) s1) \\<bind> D)) True - spmf ((and_R1 (a1, a2) (b1,b2)) \\<bind> D) True\\<bar> =\n       \\<bar>spmf (coin_spmf \\<bind> (\\<lambda> \\<sigma>. S1_14_OT ((\\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> False))), (\\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> True))), (\\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> False))), (\\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> True)))) () \n         \\<bind>  (\\<lambda> view. A view \\<sigma>))) True - spmf (coin_spmf \n           \\<bind> (\\<lambda> \\<sigma>. R1_14_OT ((\\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> False))), (\\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> True))), (\\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> False))), (\\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> True)))) (b1, b2)\n             \\<bind> (\\<lambda> view. A view \\<sigma>))) True\\<bar>\" \n    using sec_ex_P1_and by blast\n  then show ?thesis using bound_14_OT[of \"a1\" \"a2\" \"A\" \"b1\" \"b2\" ] by metis\nqed\n\nlemma security_and_P1':\n  shows \"\\<bar>spmf ((and_R1 (a1, a2) (b1,b2)) \\<bind> D) True - \n           spmf ((and_funct (a1, a2) (b1,b2)) \\<bind> (\\<lambda> (s1, s2). (S1_and' (a1,a2) (b1,b2) s1) \n            \\<bind> (D :: (((bool \\<times> bool) \\<times> bool \\<times> 'v_14_OT1) \\<times> (share_1 \\<times> share_2)) \\<Rightarrow> bool spmf))) True\\<bar> \\<le> adv_14_OT\"\nproof-\n  have \"\\<bar>spmf ((and_R1 (a1, a2) (b1,b2)) \\<bind> D) True - \n          spmf ((and_funct (a1, a2) (b1,b2)) \\<bind> (\\<lambda> (s1, s2). (S1_and' (a1,a2) (b1,b2) s1) \n            \\<bind> (D :: (((bool \\<times> bool) \\<times> bool \\<times> 'v_14_OT1) \\<times> (share_1 \\<times> share_2)) \\<Rightarrow> bool spmf))) True\\<bar> =\n              \\<bar>spmf ((and_funct (a1, a2) (b1,b2)) \\<bind> (\\<lambda> (s1, s2). (S1_and' (a1,a2) (b1,b2) s1) \n                \\<bind> (D :: (((bool \\<times> bool) \\<times> bool \\<times> 'v_14_OT1) \\<times> (share_1 \\<times> share_2)) \\<Rightarrow> bool spmf))) True - \n                  spmf ((and_R1 (a1, a2) (b1,b2)) \\<bind> D) True\\<bar>\" using abs_minus_commute by blast\n  thus ?thesis using security_and_P1 by simp\nqed\n\ndefinition and_R2 :: \"(share_1 \\<times> share_2) \\<Rightarrow> (share_2 \\<times> share_1) \\<Rightarrow> (((bool \\<times> bool) \\<times> 'v_14_OT2) \\<times> (share_1 \\<times> share_2)) spmf\"\n  where \"and_R2 A B = do {\n    let (a1, a2) = A;\n    let (b1,b2) = B;\n    \\<sigma> \\<leftarrow> coin_spmf;\n    let s0 = \\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> False));   \n    let s1 = \\<sigma> \\<oplus> ((a1 \\<oplus> False) \\<and> (a2 \\<oplus> True));   \n    let s2 = \\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> False));   \n    let s3 = \\<sigma> \\<oplus> ((a1 \\<oplus> True) \\<and> (a2 \\<oplus> True)); \n    (_, s) \\<leftarrow> protocol_14_OT (s0,s1,s2,s3) B;\n    V \\<leftarrow> R2_14_OT (s0,s1,s2,s3) B;\n    return_spmf ((B, V), (\\<sigma>, s))}\"\n\nlemma lossless_and_R2: \"lossless_spmf (and_R2 A B)\"\n  apply(simp add: and_R2_def split_def lossless_R2_14_OT lossless_protocol_14_OT Let_def) \n  by (metis lossless_R2_14_OT prod.collapse)\n\ndefinition S2_and :: \"(share_1 \\<times> share_2) \\<Rightarrow> bool \\<Rightarrow> (((bool \\<times> bool) \\<times> 'v_14_OT2)) spmf\"\n  where \"S2_and B s2 =  do {\n    let (a2,b2) = B;\n    V :: 'v_14_OT2 \\<leftarrow> S2_14_OT (a2,b2) s2;\n    return_spmf ((B, V))}\"\n\ndefinition out2 :: \"(share_1 \\<times> share_2) \\<Rightarrow> (share_1 \\<times> share_2) \\<Rightarrow> bool \\<Rightarrow> (share_1 \\<times> share_2) spmf\"\n  where \"out2 B A s2 = do {\n    let (a1, b1) = A;\n    let (a2,b2) = B;\n    let s1 = s2 \\<oplus> ((a1 \\<oplus> a2) \\<and> (b1 \\<oplus> b2));\n    return_spmf (s1, s2)}\"\n\ndefinition S2_and' :: \"(share_1 \\<times> share_2) \\<Rightarrow> (share_1 \\<times> share_2) \\<Rightarrow> bool \\<Rightarrow> (((bool \\<times> bool) \\<times> 'v_14_OT2) \\<times> (share_1 \\<times> share_2)) spmf\"\n  where \"S2_and' B A s2 =  do {\n    let (a1, a2) = A;\n    let (b1,b2) = B;\n    V :: 'v_14_OT2 \\<leftarrow> S2_14_OT B s2;\n    let s1 = s2 \\<oplus> ((a1 \\<oplus> b1) \\<and> (a2 \\<oplus> b2));\n    return_spmf ((B, V), s1, s2)}\"\n\nlemma lossless_S2_and: \"lossless_spmf (S2_and B s2)\"\n  apply(simp add: S2_and_def split_def)\n  by(metis prod.collapse lossless_S2_14_OT) \n\nsublocale and_secret_sharing: sim_non_det_def and_R1 S1_and out1 and_R2 S2_and out2 and_funct .\n\nlemma ideal_S1_and: \"and_secret_sharing.Ideal1 (a1, b1) (a2, b2) s2 = S1_and' (a1, b1) (a2, b2) s2\"\n  by(simp add: Let_def and_secret_sharing.Ideal1_def S1_and'_def split_def out1_def S1_and_def)\n\nlemma and_P2_security: \"and_secret_sharing.perfect_sec_P2 m1 m2\"\nproof-\n  have \"and_R2 (a1, b1) (a2, b2) = and_funct (a1, b1) (a2, b2) \\<bind> (\\<lambda>(s1, s2). and_secret_sharing.Ideal2 (a2, b2) (a1, b1) s2)\"\n    for a1 a2 b1 b2\n    apply(auto simp add: split_def inf_th_14_OT_P4  S2_and'_def and_R2_def and_funct_def Let_def correct_14[symmetric] and_secret_sharing.Ideal2_def S2_and_def out2_def)\n    apply(simp only: funct_14) \n    apply auto\n    by(cases b1;cases b2; cases a1; cases a2; auto) \n  thus ?thesis\n    by(simp add: and_secret_sharing.perfect_sec_P2_def; metis  prod.collapse)\nqed\n\nlemma and_P1_security: \"and_secret_sharing.adv_P1 m1 m2 D \\<le> adv_14_OT\"\nproof-\n  have \"\\<bar>spmf (and_R1 (a1, a2) (b1, b2) \\<bind> D) True -\n            spmf (and_funct (a1, a2) (b1, b2) \\<bind> (\\<lambda>(s1, s2). \n                and_secret_sharing.Ideal1 (a1, a2) (b1, b2) s1 \\<bind> D)) True\\<bar>\n                    \\<le> adv_14_OT\" for a1 a2 b1 b2 \n    using security_and_P1' ideal_S1_and prod.collapse by simp \n  thus ?thesis \n    by(simp add:  and_secret_sharing.adv_P1_def; metis prod.collapse)\nqed\n\ndefinition \"F = {and_evaluate, xor_evaluate}\"\n\nlemma share_reconstruct_xor: \"share x \\<bind> (\\<lambda>(a1, a2). share y \\<bind> (\\<lambda>(b1, b2). \n          xor_protocol (a1, b1) (a2, b2) \\<bind> (\\<lambda>(a, b). \n              reconstruct (a, b)))) = xor_evaluate x y\"\nproof-\n  have \"(((ya = (x = ya)) = (yb = (y = (\\<not> yb))))) = (x = (\\<not> y))\" for ya yb by auto\n  thus ?thesis\n    by(simp add: xor_protocol_def share_def reconstruct_def xor_evaluate_def bind_spmf_const)\nqed\n\nsublocale share_correct: secret_sharing_scheme share reconstruct F .\n\nlemma \"share_correct.sharing_correct input\"\n  by(simp add: share_correct.sharing_correct_def reconstruct_share) \n\nlemma \"share_correct.correct_share_eval input1 input2\"\n  unfolding share_correct.correct_share_eval_def\n  apply(auto simp add: F_def) \n  using share_and_reconstruct apply auto \n  using share_reconstruct_xor by force\n\nend \n\nlocale gmw_asym =\n  fixes S1_14_OT :: \"nat \\<Rightarrow> msgs_14_OT \\<Rightarrow> unit \\<Rightarrow> 'v_14_OT1 spmf\"\n    and R1_14_OT :: \"nat \\<Rightarrow> msgs_14_OT \\<Rightarrow> choice_14_OT \\<Rightarrow> 'v_14_OT1 spmf\"\n    and S2_14_OT :: \"nat \\<Rightarrow> choice_14_OT \\<Rightarrow> bool \\<Rightarrow> 'v_14_OT2 spmf\" \n    and R2_14_OT :: \"nat \\<Rightarrow> msgs_14_OT \\<Rightarrow> choice_14_OT \\<Rightarrow> 'v_14_OT2 spmf\"\n    and protocol_14_OT :: \"nat \\<Rightarrow> msgs_14_OT \\<Rightarrow> choice_14_OT \\<Rightarrow> (unit \\<times> bool) spmf\"\n    and adv_14_OT :: \"nat \\<Rightarrow> real\"\n  assumes gmw_base: \"\\<And> (n::nat). gmw_base (S1_14_OT n) (R1_14_OT n) (S2_14_OT n) (R2_14_OT n) (protocol_14_OT n) (adv_14_OT n)\"\nbegin\n\nsublocale gmw_base \"(S1_14_OT n)\" \"(R1_14_OT n)\" \"(S2_14_OT n)\" \"(R2_14_OT n)\" \"(protocol_14_OT n)\" \"(adv_14_OT n)\"\n  by (simp add: gmw_base)\n\nlemma \"xor_sim_det.perfect_sec_P1 m1 m2\" \n  by (simp add: P1_xor_inf_th xor_sim_det.perfect_sec_P1_def)\n\nlemma \"xor_sim_det.perfect_sec_P2 m1 m2\"\n  by (simp add: P2_xor_inf_th xor_sim_det.perfect_sec_P2_def)\n\nlemma and_P1_adv_negligible:\n  assumes \"negligible (\\<lambda> n. adv_14_OT n)\"\n  shows \"negligible (\\<lambda> n. and_secret_sharing.adv_P1 n m1 m2 D)\" \nproof-\n  have \"and_secret_sharing.adv_P1 n m1 m2 D \\<le> adv_14_OT n\" for n\n    by (simp add: and_P1_security)\n  thus ?thesis \n    using and_secret_sharing.adv_P1_def assms negligible_le by auto\nqed\n\nlemma and_P2_security: \"and_secret_sharing.perfect_sec_P2 n m1 m2\" \n  by (simp add: and_P2_security)\n\nend\n\nend\n\n\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Multi_Party_Computation/GMW.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621765155565327, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.2569915265990344}}
{"text": "(*  Title:       OAWN_Invariants.thy\n    License:     BSD 2-Clause. See LICENSE.\n    Author:      Timothy Bourke\n*)\n\nheader \"Generic open invariants on sequential AWN processes\"\n\ntheory OAWN_Invariants\nimports Invariants OInvariants\n        AWN_Cterms AWN_Labels AWN_Invariants\n        OAWN_SOS\nbegin\n\nsubsection \"Open invariants via labelled control terms\"\n\nlemma oseqp_sos_subterms:\n  assumes \"wellformed \\<Gamma>\"\n      and \"\\<exists>pn. p \\<in> subterms (\\<Gamma> pn)\"\n      and \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n    shows \"\\<exists>pn. p' \\<in> subterms (\\<Gamma> pn)\"\n  using assms\n  proof (induct p)\n    fix p1 p2\n    assume IH1: \"\\<exists>pn. p1 \\<in> subterms (\\<Gamma> pn) \\<Longrightarrow>\n                      ((\\<sigma>, p1), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i \\<Longrightarrow>\n                      \\<exists>pn. p' \\<in> subterms (\\<Gamma> pn)\"\n       and IH2: \"\\<exists>pn. p2 \\<in> subterms (\\<Gamma> pn) \\<Longrightarrow>\n                      ((\\<sigma>, p2), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i \\<Longrightarrow>\n                      \\<exists>pn. p' \\<in> subterms (\\<Gamma> pn)\"\n       and \"\\<exists>pn. p1 \\<oplus> p2 \\<in> subterms (\\<Gamma> pn)\"\n       and \"((\\<sigma>, p1 \\<oplus> p2), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n    from \\<open>\\<exists>pn. p1 \\<oplus> p2 \\<in> subterms (\\<Gamma> pn)\\<close> obtain pn\n                                            where \"p1 \\<in> subterms (\\<Gamma> pn)\"\n                                              and \"p2 \\<in> subterms (\\<Gamma> pn)\" by auto\n    from \\<open>((\\<sigma>, p1 \\<oplus> p2), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\\<close>\n      have \"((\\<sigma>, p1), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\n            \\<or> ((\\<sigma>, p2), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\" by auto\n    thus \"\\<exists>pn. p' \\<in> subterms (\\<Gamma> pn)\"\n    proof\n      assume \"((\\<sigma>, p1), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n      with \\<open>p1 \\<in> subterms (\\<Gamma> pn)\\<close> show ?thesis by (auto intro: IH1)\n    next\n      assume \"((\\<sigma>, p2), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n      with \\<open>p2 \\<in> subterms (\\<Gamma> pn)\\<close> show ?thesis by (auto intro: IH2)\n    qed\n  qed auto\n\nlemma oreachable_subterms:\n  assumes \"wellformed \\<Gamma>\"\n      and \"control_within \\<Gamma> (init A)\"\n      and \"trans A = oseqp_sos \\<Gamma> i\"\n      and \"(\\<sigma>, p) \\<in> oreachable A S U\"\n    shows \"\\<exists>pn. p \\<in> subterms (\\<Gamma> pn)\"\n  using assms(4)\n  proof (induct rule: oreachable_pair_induct)\n    fix \\<sigma> p\n    assume \"(\\<sigma>, p) \\<in> init A\"\n    with \\<open>control_within \\<Gamma> (init A)\\<close> show \"\\<exists>pn. p \\<in> subterms (\\<Gamma> pn)\" ..\n  next\n    fix \\<sigma> p a \\<sigma>' p'\n    assume \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and \"\\<exists>pn. p \\<in> subterms (\\<Gamma> pn)\"\n       and \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A\"\n       and \"S \\<sigma> \\<sigma>' a\"\n    moreover from this(3) and \\<open>trans A = oseqp_sos \\<Gamma> i\\<close>\n      have \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\" by simp\n    ultimately show \"\\<exists>pn. p' \\<in> subterms (\\<Gamma> pn)\"\n    using \\<open>wellformed \\<Gamma>\\<close>\n      by (auto elim: oseqp_sos_subterms)\n  qed\n\nlemma onl_oinvariantI [intro]:\n  assumes init: \"\\<And>\\<sigma> p l. \\<lbrakk> (\\<sigma>, p) \\<in> init A; l \\<in> labels \\<Gamma> p \\<rbrakk> \\<Longrightarrow> P (\\<sigma>, l)\"\n      and other: \"\\<And>\\<sigma> \\<sigma>' p l. \\<lbrakk> (\\<sigma>, p) \\<in> oreachable A S U;\n                                \\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l);\n                                U \\<sigma> \\<sigma>' \\<rbrakk> \\<Longrightarrow> \\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>', l)\"\n      and step: \"\\<And>\\<sigma> p a \\<sigma>' p' l'.\n                   \\<lbrakk> (\\<sigma>, p) \\<in> oreachable A S U;\n                     \\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l);\n                     ((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A;\n                     l' \\<in> labels \\<Gamma> p';\n                     S \\<sigma> \\<sigma>' a \\<rbrakk> \\<Longrightarrow> P (\\<sigma>', l')\"\n    shows \"A \\<Turnstile> (S, U \\<rightarrow>) onl \\<Gamma> P\"\n  proof\n    fix \\<sigma> p\n    assume \"(\\<sigma>, p) \\<in> init A\"\n    hence \"\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l)\" using init by simp\n    thus \"onl \\<Gamma> P (\\<sigma>, p)\" ..\n  next\n    fix \\<sigma> p a \\<sigma>' p'\n    assume rp: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and \"onl \\<Gamma> P (\\<sigma>, p)\"\n       and tr: \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A\"\n       and \"S \\<sigma> \\<sigma>' a\"\n    from \\<open>onl \\<Gamma> P (\\<sigma>, p)\\<close> have \"\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l)\" ..\n    with rp tr \\<open>S \\<sigma> \\<sigma>' a\\<close> have \"\\<forall>l'\\<in>labels \\<Gamma> p'. P (\\<sigma>', l')\" by (auto elim: step)\n    thus \"onl \\<Gamma> P (\\<sigma>', p')\" ..\n  next\n    fix \\<sigma> \\<sigma>' p\n    assume \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and \"onl \\<Gamma> P (\\<sigma>, p)\"\n       and \"U \\<sigma> \\<sigma>'\"\n    from \\<open>onl \\<Gamma> P (\\<sigma>, p)\\<close> have \"\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l)\" by auto\n    with \\<open>(\\<sigma>, p) \\<in> oreachable A S U\\<close> have \"\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>', l)\"\n        using \\<open>U \\<sigma> \\<sigma>'\\<close> by (rule other)\n    thus \"onl \\<Gamma> P (\\<sigma>', p)\" by auto\n  qed\n\nlemma global_oinvariantI [intro]:\n  assumes init: \"\\<And>\\<sigma> p. (\\<sigma>, p) \\<in> init A \\<Longrightarrow> P \\<sigma>\"\n      and other: \"\\<And>\\<sigma> \\<sigma>' p l. \\<lbrakk> (\\<sigma>, p) \\<in> oreachable A S U; P \\<sigma>; U \\<sigma> \\<sigma>' \\<rbrakk> \\<Longrightarrow> P \\<sigma>'\"\n      and step: \"\\<And>\\<sigma> p a \\<sigma>' p'.\n                   \\<lbrakk> (\\<sigma>, p) \\<in> oreachable A S U;\n                     P \\<sigma>;\n                     ((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A;\n                     S \\<sigma> \\<sigma>' a \\<rbrakk> \\<Longrightarrow> P \\<sigma>'\"\n    shows \"A \\<Turnstile> (S, U \\<rightarrow>) (\\<lambda>(\\<sigma>, _). P \\<sigma>)\"\n  proof\n    fix \\<sigma> p\n    assume \"(\\<sigma>, p) \\<in> init A\"\n    thus \"(\\<lambda>(\\<sigma>, _). P \\<sigma>) (\\<sigma>, p)\"\n      by simp (erule init)\n  next\n    fix \\<sigma> p a \\<sigma>' p'\n    assume rp: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and \"(\\<lambda>(\\<sigma>, _). P \\<sigma>) (\\<sigma>, p)\"\n       and tr: \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A\"\n       and \"S \\<sigma> \\<sigma>' a\"\n    from \\<open>(\\<lambda>(\\<sigma>, _). P \\<sigma>) (\\<sigma>, p)\\<close> have \"P \\<sigma>\" by simp\n    with rp have \"P \\<sigma>'\"\n      using tr \\<open>S \\<sigma> \\<sigma>' a\\<close> by (rule step)\n    thus \"(\\<lambda>(\\<sigma>, _). P \\<sigma>) (\\<sigma>', p')\" by simp\n  next\n    fix \\<sigma> \\<sigma>' p\n    assume \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and \"(\\<lambda>(\\<sigma>, _). P \\<sigma>) (\\<sigma>, p)\"\n       and \"U \\<sigma> \\<sigma>'\"\n    hence \"P \\<sigma>'\" by simp (erule other)\n    thus \"(\\<lambda>(\\<sigma>, _). P \\<sigma>) (\\<sigma>', p)\" by simp\n  qed\n\nlemma onl_oinvariantD [dest]:\n  assumes \"A \\<Turnstile> (S, U \\<rightarrow>) onl \\<Gamma> P\"\n      and \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and \"l \\<in> labels \\<Gamma> p\"\n    shows \"P (\\<sigma>, l)\"\n  using assms unfolding onl_def by auto\n\nlemma onl_oinvariant_weakenD [dest]:\n  assumes \"A \\<Turnstile> (S', U' \\<rightarrow>) onl \\<Gamma> P\"\n      and \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and \"l \\<in> labels \\<Gamma> p\"\n      and weakenS: \"\\<And>s s' a. S s s' a \\<Longrightarrow> S' s s' a\"\n      and weakenU: \"\\<And>s s'. U s s' \\<Longrightarrow> U' s s'\"\n    shows \"P (\\<sigma>, l)\"\n  proof -\n    from \\<open>(\\<sigma>, p) \\<in> oreachable A S U\\<close> have \"(\\<sigma>, p) \\<in> oreachable A S' U'\"\n      by (rule oreachable_weakenE)\n         (erule weakenS, erule weakenU)\n    with \\<open>A \\<Turnstile> (S', U' \\<rightarrow>) onl \\<Gamma> P\\<close> show \"P (\\<sigma>, l)\"\n      using \\<open>l \\<in> labels \\<Gamma> p\\<close> ..\n  qed\n\nlemma onl_oinvariant_initD [dest]:\n  assumes invP: \"A \\<Turnstile> (S, U \\<rightarrow>) onl \\<Gamma> P\"\n      and init: \"(\\<sigma>, p) \\<in> init A\"\n      and pnl:  \"l \\<in> labels \\<Gamma> p\"\n    shows \"P (\\<sigma>, l)\"\n  proof -\n    from init have \"(\\<sigma>, p) \\<in> oreachable A S U\" ..\n    with invP show ?thesis using pnl ..\n  qed\n\nlemma onl_oinvariant_sterms:\n  assumes wf: \"wellformed \\<Gamma>\"\n      and il: \"A \\<Turnstile> (S, U \\<rightarrow>) onl \\<Gamma> P\"\n      and rp: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and \"p'\\<in>sterms \\<Gamma> p\"\n      and \"l\\<in>labels \\<Gamma> p'\"\n    shows \"P (\\<sigma>, l)\"\n  proof -\n    from wf \\<open>p'\\<in>sterms \\<Gamma> p\\<close> \\<open>l\\<in>labels \\<Gamma> p'\\<close> have \"l\\<in>labels \\<Gamma> p\"\n      by (rule labels_sterms_labels)\n    with il rp show \"P (\\<sigma>, l)\" ..\n  qed\n\nlemma onl_oinvariant_sterms_weaken:\n  assumes wf: \"wellformed \\<Gamma>\"\n      and il: \"A \\<Turnstile> (S', U' \\<rightarrow>) onl \\<Gamma> P\"\n      and rp: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and \"p'\\<in>sterms \\<Gamma> p\"\n      and \"l\\<in>labels \\<Gamma> p'\"\n      and weakenS: \"\\<And>\\<sigma> \\<sigma>' a. S \\<sigma> \\<sigma>' a \\<Longrightarrow> S' \\<sigma> \\<sigma>' a\"\n      and weakenU: \"\\<And>\\<sigma> \\<sigma>'. U \\<sigma> \\<sigma>' \\<Longrightarrow> U' \\<sigma> \\<sigma>'\"\n    shows \"P (\\<sigma>, l)\"\n  proof -\n    from \\<open>(\\<sigma>, p) \\<in> oreachable A S U\\<close> have \"(\\<sigma>, p) \\<in> oreachable A S' U'\"\n      by (rule oreachable_weakenE)\n         (erule weakenS, erule weakenU)\n    with assms(1-2) show ?thesis using assms(4-5)\n      by (rule onl_oinvariant_sterms)\n  qed\n\nlemma otrans_from_sterms:\n  assumes \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n      and \"wellformed \\<Gamma>\"\n    shows \"\\<exists>p'\\<in>sterms \\<Gamma> p. ((\\<sigma>, p'), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n  using assms by (induction p rule: sterms_pinduct [OF \\<open>wellformed \\<Gamma>\\<close>]) auto\n\nlemma otrans_from_sterms':\n  assumes \"((\\<sigma>, p'), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n      and \"wellformed \\<Gamma>\"\n      and \"p' \\<in> sterms \\<Gamma> p\"\n    shows \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n  using assms by (induction p rule: sterms_pinduct [OF \\<open>wellformed \\<Gamma>\\<close>]) auto\n\nlemma otrans_to_dterms:\n  assumes \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n      and \"wellformed \\<Gamma>\"\n   shows \"\\<forall>r\\<in>sterms \\<Gamma> q. r \\<in> dterms \\<Gamma> p\"\n  using assms by (induction q) auto\n\ntheorem cterms_includes_sterms_of_oseq_reachable:\n  assumes \"wellformed \\<Gamma>\"\n      and \"control_within \\<Gamma> (init A)\"\n      and \"trans A = oseqp_sos \\<Gamma> i\"\n    shows \"\\<Union>(sterms \\<Gamma> ` snd ` oreachable A S U) \\<subseteq> cterms \\<Gamma>\"\n  proof\n    fix qs\n    assume \"qs \\<in> \\<Union>(sterms \\<Gamma> ` snd ` oreachable A S U)\"\n    then obtain \\<xi> and q where  *: \"(\\<xi>, q) \\<in> oreachable A S U\"\n                          and **: \"qs \\<in> sterms \\<Gamma> q\" by auto\n    from * have \"\\<And>x. x \\<in> sterms \\<Gamma> q \\<Longrightarrow> x \\<in> cterms \\<Gamma>\"\n    proof (induction rule: oreachable_pair_induct)\n      fix \\<sigma> p q\n      assume \"(\\<sigma>, p) \\<in> init A\"\n         and \"q \\<in> sterms \\<Gamma> p\"\n      from \\<open>control_within \\<Gamma> (init A)\\<close> and \\<open>(\\<sigma>, p) \\<in> init A\\<close>\n        obtain pn where \"p \\<in> subterms (\\<Gamma> pn)\" by auto\n      with \\<open>wellformed \\<Gamma>\\<close> show \"q \\<in> cterms \\<Gamma>\" using \\<open>q\\<in>sterms \\<Gamma> p\\<close>\n        by (rule subterms_sterms_in_cterms)\n    next\n      fix p \\<sigma> a \\<sigma>' q x\n      assume \"(\\<sigma>, p) \\<in> oreachable A S U\"\n         and IH: \"\\<And>x. x \\<in> sterms \\<Gamma> p \\<Longrightarrow> x \\<in> cterms \\<Gamma>\"\n         and \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A\"\n         and \"x \\<in> sterms \\<Gamma> q\"\n      from this(3) and \\<open>trans A = oseqp_sos \\<Gamma> i\\<close>\n        have step: \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\" by simp\n      from step \\<open>wellformed \\<Gamma>\\<close> obtain ps\n        where ps: \"ps \\<in> sterms \\<Gamma> p\"\n          and step': \"((\\<sigma>, ps), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n        by (rule otrans_from_sterms [THEN bexE])\n      from ps have \"ps \\<in> cterms \\<Gamma>\" by (rule IH)\n      moreover from step' \\<open>wellformed \\<Gamma>\\<close> \\<open>x \\<in> sterms \\<Gamma> q\\<close> have \"x \\<in> dterms \\<Gamma> ps\"\n        by (rule otrans_to_dterms [rule_format])\n      ultimately show \"x \\<in> cterms \\<Gamma>\" by (rule ctermsDI)\n    qed\n    thus \"qs \\<in> cterms \\<Gamma>\" using ** .\n  qed\n\ncorollary oseq_reachable_in_cterms:\n  assumes \"wellformed \\<Gamma>\"\n      and \"control_within \\<Gamma> (init A)\"\n      and \"trans A = oseqp_sos \\<Gamma> i\"\n      and \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and \"p' \\<in> sterms \\<Gamma> p\"\n    shows \"p' \\<in> cterms \\<Gamma>\"\n  using assms(1-3)\n  proof (rule cterms_includes_sterms_of_oseq_reachable [THEN set_mp])\n    from assms(4-5) show \"p' \\<in> \\<Union>(sterms \\<Gamma> ` snd ` oreachable A S U)\"\n      by (auto elim!: rev_bexI)\n  qed\n\nlemma oseq_invariant_ctermI:\n  assumes wf: \"wellformed \\<Gamma>\"\n      and cw: \"control_within \\<Gamma> (init A)\"\n      and sl: \"simple_labels \\<Gamma>\"\n      and sp: \"trans A = oseqp_sos \\<Gamma> i\"\n      and init: \"\\<And>\\<sigma> p l. \\<lbrakk>\n                   (\\<sigma>, p) \\<in> init A;\n                   l\\<in>labels \\<Gamma> p\n                 \\<rbrakk> \\<Longrightarrow> P (\\<sigma>, l)\"\n      and other: \"\\<And>\\<sigma> \\<sigma>' p l. \\<lbrakk>\n                   (\\<sigma>, p) \\<in> oreachable A S U;\n                   l\\<in>labels \\<Gamma> p;\n                   P (\\<sigma>, l);\n                   U \\<sigma> \\<sigma>' \\<rbrakk> \\<Longrightarrow> P (\\<sigma>', l)\"\n      and local: \"\\<And>p l \\<sigma> a q l' \\<sigma>' pp. \\<lbrakk>\n                 p\\<in>cterms \\<Gamma>;\n                 l\\<in>labels \\<Gamma> p;\n                 P (\\<sigma>, l);\n                 ((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i;\n                 ((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A;\n                 l'\\<in>labels \\<Gamma> q;\n                 (\\<sigma>, pp)\\<in>oreachable A S U;\n                 p\\<in>sterms \\<Gamma> pp;\n                 (\\<sigma>', q)\\<in>oreachable A S U;\n                 S \\<sigma> \\<sigma>' a\n               \\<rbrakk> \\<Longrightarrow> P (\\<sigma>', l')\"\n    shows \"A \\<Turnstile> (S, U \\<rightarrow>) onl \\<Gamma> P\"\n  proof\n       fix \\<sigma> p l\n    assume \"(\\<sigma>, p) \\<in> init A\"\n       and *: \"l \\<in> labels \\<Gamma> p\"\n      with init show \"P (\\<sigma>, l)\" by auto\n  next\n       fix \\<sigma> p a \\<sigma>' q l'\n    assume sr: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and pl: \"\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l)\"\n       and tr: \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A\"\n       and A6: \"l' \\<in> labels \\<Gamma> q\"\n       and \"S \\<sigma> \\<sigma>' a\"\n      thus \"P (\\<sigma>', l')\"\n    proof -\n      from sr and tr and \\<open>S \\<sigma> \\<sigma>' a\\<close> have A7: \"(\\<sigma>', q) \\<in> oreachable A S U\"\n        by - (rule oreachable_local')\n      from tr and sp have tr': \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\" by simp\n      then obtain p' where \"p' \\<in> sterms \\<Gamma> p\"\n                       and A4: \"((\\<sigma>, p'), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n        by (blast dest: otrans_from_sterms [OF _ wf])\n      from wf cw sp sr this(1) have A1: \"p'\\<in>cterms \\<Gamma>\"\n        by (rule oseq_reachable_in_cterms)\n      from labels_not_empty [OF wf] obtain ll where A2: \"ll\\<in>labels \\<Gamma> p'\"\n          by blast\n      with \\<open>p'\\<in>sterms \\<Gamma> p\\<close> have \"ll\\<in>labels \\<Gamma> p\"\n        by (rule labels_sterms_labels [OF wf])\n      with pl have A3: \"P (\\<sigma>, ll)\" by simp\n      from sr \\<open>p'\\<in>sterms \\<Gamma> p\\<close>\n        obtain pp where A7: \"(\\<sigma>, pp)\\<in>oreachable A S U\"\n                    and A8: \"p'\\<in>sterms \\<Gamma> pp\"\n        by auto\n      from sr tr \\<open>S \\<sigma> \\<sigma>' a\\<close> have A9: \"(\\<sigma>', q)\\<in>oreachable A S U\"\n        by - (rule oreachable_local')\n      from sp and \\<open>((\\<sigma>, p'), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\\<close>\n        have A5: \"((\\<sigma>, p'), a, (\\<sigma>', q)) \\<in> trans A\" by simp\n      from A1 A2 A3 A4 A5 A6 A7 A8 A9 \\<open>S \\<sigma> \\<sigma>' a\\<close> show ?thesis by (rule local)\n    qed\n  next\n    fix \\<sigma> \\<sigma>' p l\n    assume sr: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and \"\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l)\"\n       and \"U \\<sigma> \\<sigma>'\"\n    show \"\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>', l)\"\n    proof\n      fix l\n      assume \"l\\<in>labels \\<Gamma> p\"\n      with \\<open>\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l)\\<close> have \"P (\\<sigma>, l)\" ..\n      with sr and \\<open>l\\<in>labels \\<Gamma> p\\<close>\n        show \"P (\\<sigma>', l)\" using \\<open>U \\<sigma> \\<sigma>'\\<close> by (rule other)\n    qed\n  qed\n\nlemma oseq_invariant_ctermsI:\n  assumes wf: \"wellformed \\<Gamma>\"\n      and cw: \"control_within \\<Gamma> (init A)\"\n      and sl: \"simple_labels \\<Gamma>\"\n      and sp: \"trans A = oseqp_sos \\<Gamma> i\"\n      and init: \"\\<And>\\<sigma> p l. \\<lbrakk>\n                   (\\<sigma>, p) \\<in> init A;\n                   l\\<in>labels \\<Gamma> p\n                 \\<rbrakk> \\<Longrightarrow> P (\\<sigma>, l)\"\n      and other: \"\\<And>\\<sigma> \\<sigma>' p l. \\<lbrakk>\n                   wellformed \\<Gamma>;\n                   (\\<sigma>, p) \\<in> oreachable A S U;\n                   l\\<in>labels \\<Gamma> p;\n                   P (\\<sigma>, l);\n                   U \\<sigma> \\<sigma>' \\<rbrakk> \\<Longrightarrow> P (\\<sigma>', l)\"\n      and local: \"\\<And>p l \\<sigma> a q l' \\<sigma>' pp pn. \\<lbrakk>\n                 wellformed \\<Gamma>;\n                 p\\<in>ctermsl (\\<Gamma> pn);\n                 not_call p;\n                 l\\<in>labels \\<Gamma> p;\n                 P (\\<sigma>, l);\n                 ((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i;\n                 ((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A;\n                 l'\\<in>labels \\<Gamma> q;\n                 (\\<sigma>, pp)\\<in>oreachable A S U;\n                 p\\<in>sterms \\<Gamma> pp;\n                 (\\<sigma>', q)\\<in>oreachable A S U;\n                 S \\<sigma> \\<sigma>' a\n               \\<rbrakk> \\<Longrightarrow> P (\\<sigma>', l')\"\n    shows \"A \\<Turnstile> (S, U \\<rightarrow>) onl \\<Gamma> P\"\n  proof (rule oseq_invariant_ctermI [OF wf cw sl sp])\n    fix \\<sigma> p l\n    assume \"(\\<sigma>, p) \\<in> init A\"\n       and \"l \\<in> labels \\<Gamma> p\"\n    thus \"P (\\<sigma>, l)\" by (rule init)\n  next\n    fix \\<sigma> \\<sigma>' p l\n    assume \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and \"l \\<in> labels \\<Gamma> p\"\n       and \"P (\\<sigma>, l)\"\n       and \"U \\<sigma> \\<sigma>'\"\n    with wf show \"P (\\<sigma>', l)\" by (rule other)\n  next\n    fix p l \\<sigma> a q l' \\<sigma>' pp\n    assume \"p \\<in> cterms \\<Gamma>\"\n       and otherassms: \"l \\<in> labels \\<Gamma> p\"\n           \"P (\\<sigma>, l)\"\n           \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n           \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A\"\n           \"l' \\<in> labels \\<Gamma> q\"\n           \"(\\<sigma>, pp) \\<in> oreachable A S U\"\n           \"p \\<in> sterms \\<Gamma> pp\"\n           \"(\\<sigma>', q) \\<in> oreachable A S U\"\n           \"S \\<sigma> \\<sigma>' a\"\n    from this(1) obtain pn where \"p \\<in> ctermsl(\\<Gamma> pn)\"\n                             and \"not_call p\"\n      unfolding cterms_def' [OF wf] by auto\n    with wf show \"P (\\<sigma>', l')\"\n      using otherassms by (rule local)\n  qed\n\nsubsection \"Open step invariants via labelled control terms\"\n\nlemma onll_ostep_invariantI [intro]:\n  assumes *: \"\\<And>\\<sigma> p l a \\<sigma>' p' l'. \\<lbrakk> (\\<sigma>, p)\\<in>oreachable A S U;\n                                   ((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A;\n                                   S \\<sigma> \\<sigma>' a;\n                                   l \\<in>labels \\<Gamma> p;\n                                   l'\\<in>labels \\<Gamma> p' \\<rbrakk>\n                                 \\<Longrightarrow> P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n    shows \"A \\<Turnstile>\\<^sub>A (S, U \\<rightarrow>) onll \\<Gamma> P\"\n  proof\n    fix \\<sigma> p \\<sigma>' p' a\n    assume \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A\"\n       and \"S \\<sigma> \\<sigma>' a\"\n    hence \"\\<forall>l\\<in>labels \\<Gamma> p. \\<forall>l'\\<in>labels \\<Gamma> p'. P ((\\<sigma>, l), a, (\\<sigma>', l'))\" by (auto elim!: *)\n    thus \"onll \\<Gamma> P ((\\<sigma>, p), a, (\\<sigma>', p'))\" ..\n  qed\n\nlemma onll_ostep_invariantE [elim]:\n  assumes \"A \\<Turnstile>\\<^sub>A (S, U \\<rightarrow>) onll \\<Gamma> P\"\n      and \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A\"\n      and \"S \\<sigma> \\<sigma>' a\"\n      and lp:  \"l \\<in>labels \\<Gamma> p\"\n      and lp': \"l'\\<in>labels \\<Gamma> p'\"\n    shows \"P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n  proof -\n    from assms(1-4) have \"onll \\<Gamma> P ((\\<sigma>, p), a, (\\<sigma>', p'))\" ..\n    with lp lp' show \"P ((\\<sigma>, l), a, (\\<sigma>', l'))\" by auto\n  qed\n\nlemma onll_ostep_invariantD [dest]:\n  assumes \"A \\<Turnstile>\\<^sub>A (S, U \\<rightarrow>) onll \\<Gamma> P\"\n      and \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A\"\n      and \"S \\<sigma> \\<sigma>' a\"\n    shows \"\\<forall>l\\<in>labels \\<Gamma> p. \\<forall>l'\\<in>labels \\<Gamma> p'. P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n  using assms by auto\n\nlemma onll_ostep_invariant_weakenD [dest]:\n  assumes \"A \\<Turnstile>\\<^sub>A (S', U' \\<rightarrow>) onll \\<Gamma> P\"\n      and \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A\"\n      and \"S' \\<sigma> \\<sigma>' a\"\n      and weakenS: \"\\<And>s s' a. S s s' a \\<Longrightarrow> S' s s' a\"\n      and weakenU: \"\\<And>s s'. U s s' \\<Longrightarrow> U' s s'\"\n    shows \"\\<forall>l\\<in>labels \\<Gamma> p. \\<forall>l'\\<in>labels \\<Gamma> p'. P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n  proof -\n    from \\<open>(\\<sigma>, p) \\<in> oreachable A S U\\<close> have \"(\\<sigma>, p) \\<in> oreachable A S' U'\"\n      by (rule oreachable_weakenE)\n         (erule weakenS, erule weakenU)\n    with \\<open>A \\<Turnstile>\\<^sub>A (S', U' \\<rightarrow>) onll \\<Gamma> P\\<close> show ?thesis\n      using \\<open>((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A\\<close> and \\<open>S' \\<sigma> \\<sigma>' a\\<close> ..\n  qed\n\nlemma onll_ostep_to_invariantI [intro]:\n  assumes sinv: \"A \\<Turnstile>\\<^sub>A (S, U \\<rightarrow>) onll \\<Gamma> Q\"\n      and wf: \"wellformed \\<Gamma>\"\n      and init: \"\\<And>\\<sigma> l p. \\<lbrakk> (\\<sigma>, p) \\<in> init A; l\\<in>labels \\<Gamma> p \\<rbrakk> \\<Longrightarrow> P (\\<sigma>, l)\"\n      and other: \"\\<And>\\<sigma> \\<sigma>' p l.\n                    \\<lbrakk> (\\<sigma>, p) \\<in> oreachable A S U;\n                      l\\<in>labels \\<Gamma> p;\n                      P (\\<sigma>, l);\n                      U \\<sigma> \\<sigma>' \\<rbrakk> \\<Longrightarrow> P (\\<sigma>', l)\"\n      and local: \"\\<And>\\<sigma> p l \\<sigma>' l' a.\n                    \\<lbrakk> (\\<sigma>, p) \\<in> oreachable A S U;\n                      l\\<in>labels \\<Gamma> p;\n                      P (\\<sigma>, l);\n                      Q ((\\<sigma>, l), a, (\\<sigma>', l'));\n                      S \\<sigma> \\<sigma>' a\\<rbrakk> \\<Longrightarrow> P (\\<sigma>', l')\"\n    shows \"A \\<Turnstile> (S, U \\<rightarrow>) onl \\<Gamma> P\"\n  proof\n    fix \\<sigma> p l\n    assume \"(\\<sigma>, p) \\<in> init A\" and \"l\\<in>labels \\<Gamma> p\"\n      thus \"P (\\<sigma>, l)\" by (rule init)\n  next\n    fix \\<sigma> p a \\<sigma>' p' l'\n    assume sr: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and lp: \"\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l)\"\n       and tr: \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> trans A\"\n       and \"S \\<sigma> \\<sigma>' a\"\n       and lp': \"l' \\<in> labels \\<Gamma> p'\"\n      show \"P (\\<sigma>', l')\"\n    proof -\n      from lp obtain l where \"l\\<in>labels \\<Gamma> p\" and \"P (\\<sigma>, l)\"\n        using labels_not_empty [OF wf] by auto\n      from sinv sr tr \\<open>S \\<sigma> \\<sigma>' a\\<close> this(1) lp' have \"Q ((\\<sigma>, l), a, (\\<sigma>', l'))\" ..\n      with sr \\<open>l\\<in>labels \\<Gamma> p\\<close> \\<open>P (\\<sigma>, l)\\<close> show \"P (\\<sigma>', l')\" using \\<open>S \\<sigma> \\<sigma>' a\\<close> by (rule local)\n    qed\n  next\n    fix \\<sigma> \\<sigma>' p l\n    assume \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and \"\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l)\"\n       and \"U \\<sigma> \\<sigma>'\"\n      show \"\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>', l)\"\n    proof\n      fix l\n      assume \"l\\<in>labels \\<Gamma> p\"\n      with \\<open>\\<forall>l\\<in>labels \\<Gamma> p. P (\\<sigma>, l)\\<close> have \"P (\\<sigma>, l)\" ..\n      with \\<open>(\\<sigma>, p) \\<in> oreachable A S U\\<close> and \\<open>l\\<in>labels \\<Gamma> p\\<close>\n      show \"P (\\<sigma>', l)\" using \\<open>U \\<sigma> \\<sigma>'\\<close> by (rule other)\n    qed\n  qed\n\nlemma onll_ostep_invariant_sterms:\n  assumes wf: \"wellformed \\<Gamma>\"\n      and si: \"A \\<Turnstile>\\<^sub>A (S, U \\<rightarrow>) onll \\<Gamma> P\"\n      and sr: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and sos: \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A\"\n      and \"S \\<sigma> \\<sigma>' a\"\n      and \"l'\\<in>labels \\<Gamma> q\"\n      and \"p'\\<in>sterms \\<Gamma> p\"\n      and \"l\\<in>labels \\<Gamma> p'\"\n    shows \"P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n  proof -\n    from wf \\<open>p'\\<in>sterms \\<Gamma> p\\<close> \\<open>l\\<in>labels \\<Gamma> p'\\<close> have \"l\\<in>labels \\<Gamma> p\"\n      by (rule labels_sterms_labels)\n    with si sr sos \\<open>S \\<sigma> \\<sigma>' a\\<close> show \"P ((\\<sigma>, l), a, (\\<sigma>', l'))\" using \\<open>l'\\<in>labels \\<Gamma> q\\<close> ..\n  qed\n\nlemma oseq_step_invariant_sterms:\n  assumes inv: \"A \\<Turnstile>\\<^sub>A (S, U \\<rightarrow>) onll \\<Gamma> P\"\n      and wf: \"wellformed \\<Gamma>\"\n      and sp: \"trans A = oseqp_sos \\<Gamma> i\"\n      and \"l'\\<in>labels \\<Gamma> q\"\n      and sr: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and tr: \"((\\<sigma>, p'), a, (\\<sigma>', q)) \\<in> trans A\"\n      and \"S \\<sigma> \\<sigma>' a\"\n      and \"p'\\<in>sterms \\<Gamma> p\"\n    shows \"\\<forall>l\\<in>labels \\<Gamma> p'. P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n  proof\n    from assms(3, 6) have \"((\\<sigma>, p'), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\" by simp\n    hence \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n      using wf \\<open>p'\\<in>sterms \\<Gamma> p\\<close>  by (rule otrans_from_sterms')\n    with assms(3) have trp: \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A\" by simp\n    fix l assume \"l \\<in> labels \\<Gamma> p'\"\n    with wf inv sr trp \\<open>S \\<sigma> \\<sigma>' a\\<close> \\<open>l'\\<in>labels \\<Gamma> q\\<close> \\<open>p'\\<in>sterms \\<Gamma> p\\<close>\n      show \"P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n        by - (erule(7) onll_ostep_invariant_sterms)\n  qed\n\nlemma oseq_step_invariant_sterms_weaken:\n  assumes inv: \"A \\<Turnstile>\\<^sub>A (S, U \\<rightarrow>) onll \\<Gamma> P\"\n      and wf: \"wellformed \\<Gamma>\"\n      and sp: \"trans A = oseqp_sos \\<Gamma> i\"\n      and \"l'\\<in>labels \\<Gamma> q\"\n      and sr: \"(\\<sigma>, p) \\<in> oreachable A S' U'\"\n      and tr: \"((\\<sigma>, p'), a, (\\<sigma>', q)) \\<in> trans A\"\n      and \"S' \\<sigma> \\<sigma>' a\"\n      and \"p'\\<in>sterms \\<Gamma> p\"\n      and weakenS: \"\\<And>\\<sigma> \\<sigma>' a. S' \\<sigma> \\<sigma>' a \\<Longrightarrow> S \\<sigma> \\<sigma>' a\"\n      and weakenU: \"\\<And>\\<sigma> \\<sigma>'. U' \\<sigma> \\<sigma>' \\<Longrightarrow> U \\<sigma> \\<sigma>'\"\n    shows \"\\<forall>l\\<in>labels \\<Gamma> p'. P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n  proof -\n    from \\<open>S' \\<sigma> \\<sigma>' a\\<close> have \"S \\<sigma> \\<sigma>' a\" by (rule weakenS)\n    from \\<open>(\\<sigma>, p) \\<in> oreachable A S' U'\\<close>\n      have Ir: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n        by (rule oreachable_weakenE)\n           (erule weakenS, erule weakenU)\n    with assms(1-4) show ?thesis\n      using tr \\<open>S \\<sigma> \\<sigma>' a\\<close> \\<open>p'\\<in>sterms \\<Gamma> p\\<close>\n      by (rule oseq_step_invariant_sterms)\n  qed\n\nlemma onll_ostep_invariant_any_sterms:\n  assumes wf: \"wellformed \\<Gamma>\"\n      and si: \"A \\<Turnstile>\\<^sub>A (S, U \\<rightarrow>) onll \\<Gamma> P\"\n      and sr: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n      and sos: \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A\"\n      and \"S \\<sigma> \\<sigma>' a\"\n      and \"l'\\<in>labels \\<Gamma> q\"\n    shows \"\\<forall>p'\\<in>sterms \\<Gamma> p. \\<forall>l\\<in>labels \\<Gamma> p'. P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n  by (intro ballI) (rule onll_ostep_invariant_sterms [OF assms])\n\nlemma oseq_step_invariant_ctermI [intro]:\n  assumes wf: \"wellformed \\<Gamma>\"\n      and cw: \"control_within \\<Gamma> (init A)\"\n      and sl: \"simple_labels \\<Gamma>\"\n      and sp: \"trans A = oseqp_sos \\<Gamma> i\"\n      and local: \"\\<And>p l \\<sigma> a q l' \\<sigma>' pp. \\<lbrakk>\n                   p\\<in>cterms \\<Gamma>;\n                   l\\<in>labels \\<Gamma> p;\n                   ((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i;\n                   ((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A;\n                   l'\\<in>labels \\<Gamma> q;\n                   (\\<sigma>, pp) \\<in> oreachable A S U;\n                   p\\<in>sterms \\<Gamma> pp;\n                   (\\<sigma>', q) \\<in> oreachable A S U;\n                   S \\<sigma> \\<sigma>' a\n                 \\<rbrakk> \\<Longrightarrow> P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n    shows \"A \\<Turnstile>\\<^sub>A (S, U \\<rightarrow>) onll \\<Gamma> P\"\n  proof\n       fix \\<sigma> p l a \\<sigma>' q l'\n    assume sr: \"(\\<sigma>, p) \\<in> oreachable A S U\"\n       and tr: \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A\"\n       and \"S \\<sigma> \\<sigma>' a\"\n       and pl: \"l \\<in> labels \\<Gamma> p\"\n       and A5: \"l' \\<in> labels \\<Gamma> q\"\n    from this(2) and sp have \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\" by simp\n    then obtain p' where \"p' \\<in> sterms \\<Gamma> p\"\n                     and A3: \"((\\<sigma>, p'), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n      by (blast dest: otrans_from_sterms [OF _ wf])\n    from this(2) and sp have A4: \"((\\<sigma>, p'), a, (\\<sigma>', q)) \\<in> trans A\" by simp\n    from wf cw sp sr \\<open>p'\\<in>sterms \\<Gamma> p\\<close> have A1: \"p'\\<in>cterms \\<Gamma>\"\n      by (rule oseq_reachable_in_cterms)\n    from sr \\<open>p'\\<in>sterms \\<Gamma> p\\<close>\n      obtain pp where A6: \"(\\<sigma>, pp)\\<in>oreachable A S U\"\n                  and A7: \"p'\\<in>sterms \\<Gamma> pp\"\n      by auto\n    from sr tr \\<open>S \\<sigma> \\<sigma>' a\\<close> have A8: \"(\\<sigma>', q)\\<in>oreachable A S U\"\n      by - (erule(2) oreachable_local')\n    from wf cw sp sr have \"\\<exists>pn. p \\<in> subterms (\\<Gamma> pn)\"\n      by (rule oreachable_subterms)           \n    with sl wf have \"\\<forall>p'\\<in>sterms \\<Gamma> p. l \\<in> labels \\<Gamma> p'\"\n      using pl by (rule simple_labels_in_sterms)\n    with \\<open>p' \\<in> sterms \\<Gamma> p\\<close> have \"l \\<in> labels \\<Gamma> p'\" by simp\n    with A1 show \"P ((\\<sigma>, l), a, (\\<sigma>', l'))\" using A3 A4 A5 A6 A7 A8 \\<open>S \\<sigma> \\<sigma>' a\\<close>\n      by (rule local)\n  qed\n\nlemma oseq_step_invariant_ctermsI [intro]:\n  assumes wf: \"wellformed \\<Gamma>\"\n      and \"control_within \\<Gamma> (init A)\"\n      and \"simple_labels \\<Gamma>\"\n      and \"trans A = oseqp_sos \\<Gamma> i\"\n      and local: \"\\<And>p l \\<sigma> a q l' \\<sigma>' pp pn. \\<lbrakk>\n                   wellformed \\<Gamma>;\n                   p\\<in>ctermsl (\\<Gamma> pn);\n                   not_call p;\n                   l\\<in>labels \\<Gamma> p;\n                   ((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i;\n                   ((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A;\n                   l'\\<in>labels \\<Gamma> q;\n                   (\\<sigma>, pp) \\<in> oreachable A S U;\n                   p\\<in>sterms \\<Gamma> pp;\n                   (\\<sigma>', q) \\<in> oreachable A S U;\n                   S \\<sigma> \\<sigma>' a\n                 \\<rbrakk> \\<Longrightarrow> P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n    shows \"A \\<Turnstile>\\<^sub>A (S, U \\<rightarrow>) onll \\<Gamma> P\"\n  using assms(1-4) proof (rule oseq_step_invariant_ctermI)\n    fix p l \\<sigma> a q l' \\<sigma>' pp\n    assume \"p \\<in> cterms \\<Gamma>\"\n       and otherassms: \"l \\<in> labels \\<Gamma> p\"\n           \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> oseqp_sos \\<Gamma> i\"\n           \"((\\<sigma>, p), a, (\\<sigma>', q)) \\<in> trans A\"\n           \"l' \\<in> labels \\<Gamma> q\"\n           \"(\\<sigma>, pp) \\<in> oreachable A S U\"\n           \"p \\<in> sterms \\<Gamma> pp\"\n           \"(\\<sigma>', q) \\<in> oreachable A S U\"\n           \"S \\<sigma> \\<sigma>' a\"\n    from this(1) obtain pn where \"p \\<in> ctermsl(\\<Gamma> pn)\"\n                             and \"not_call p\"\n      unfolding cterms_def' [OF wf] by auto\n    with wf show \"P ((\\<sigma>, l), a, (\\<sigma>', l'))\"\n      using otherassms by (rule local)\n qed\n\nlemma open_seqp_action [elim]:\n  assumes \"wellformed \\<Gamma>\"\n      and \"((\\<sigma> i, p), a, (\\<sigma>' i, p')) \\<in> seqp_sos \\<Gamma>\"\n    shows \"((\\<sigma>, p), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n  proof -\n    from assms obtain ps where \"ps\\<in>sterms \\<Gamma> p\"\n                           and \"((\\<sigma> i, ps), a, (\\<sigma>' i, p')) \\<in> seqp_sos \\<Gamma>\"\n      by - (drule trans_from_sterms, auto)\n    thus ?thesis\n    proof (induction p)\n      fix p1 p2\n      assume \"\\<lbrakk> ps \\<in> sterms \\<Gamma> p1; ((\\<sigma> i, ps), a, \\<sigma>' i, p') \\<in> seqp_sos \\<Gamma> \\<rbrakk>\n              \\<Longrightarrow> ((\\<sigma>, p1), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n         and \"\\<lbrakk> ps \\<in> sterms \\<Gamma> p2; ((\\<sigma> i, ps), a, \\<sigma>' i, p') \\<in> seqp_sos \\<Gamma> \\<rbrakk>\n              \\<Longrightarrow> ((\\<sigma>, p2), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n         and \"ps \\<in> sterms \\<Gamma> (p1 \\<oplus> p2)\"\n         and \"((\\<sigma> i, ps), a, (\\<sigma>' i, p')) \\<in> seqp_sos \\<Gamma>\"\n      with assms(1) show \"((\\<sigma>, p1 \\<oplus> p2), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n        by simp (metis oseqp_sos.ochoiceT1 oseqp_sos.ochoiceT2)\n    next\n      fix l fip fmsg p1 p2\n      assume IH1: \"\\<lbrakk> ps \\<in> sterms \\<Gamma> p1; ((\\<sigma> i, ps), a, \\<sigma>' i, p') \\<in> seqp_sos \\<Gamma> \\<rbrakk>\n                    \\<Longrightarrow> ((\\<sigma>, p1), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n         and IH2: \"\\<lbrakk> ps \\<in> sterms \\<Gamma> p2; ((\\<sigma> i, ps), a, \\<sigma>' i, p') \\<in> seqp_sos \\<Gamma> \\<rbrakk>\n                    \\<Longrightarrow> ((\\<sigma>, p2), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n         and \"ps \\<in> sterms \\<Gamma> ({l}unicast(fip, fmsg). p1 \\<triangleright> p2)\"\n         and \"((\\<sigma> i, ps), a, (\\<sigma>' i, p')) \\<in> seqp_sos \\<Gamma>\"\n      from this(3-4) have \"((\\<sigma> i, {l}unicast(fip, fmsg). p1 \\<triangleright> p2), a, (\\<sigma>' i, p')) \\<in> seqp_sos \\<Gamma>\"\n        by simp\n      thus \"((\\<sigma>, {l}unicast(fip, fmsg). p1 \\<triangleright> p2), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n      proof (rule seqp_unicastTE)\n        assume \"a = unicast (fip (\\<sigma> i)) (fmsg (\\<sigma> i))\"\n           and \"\\<sigma>' i = \\<sigma> i\"\n           and \"p' = p1\"\n        thus ?thesis by auto\n      next\n        assume \"a = \\<not>unicast (fip (\\<sigma> i))\"\n           and \"\\<sigma>' i = \\<sigma> i\"\n           and \"p' = p2\"\n        thus ?thesis by auto\n      qed\n    next\n      fix p\n      assume \"ps \\<in> sterms \\<Gamma> (call(p))\"\n         and \"((\\<sigma> i, ps), a, (\\<sigma>' i, p')) \\<in> seqp_sos \\<Gamma>\"\n      with assms(1) have \"((\\<sigma>, ps), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n        by (cases ps) auto\n      with assms(1) \\<open>ps \\<in> sterms \\<Gamma> (call(p))\\<close> have \"((\\<sigma>, \\<Gamma> p), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\"\n        by - (rule otrans_from_sterms', simp_all)\n      thus \"((\\<sigma>, call(p)), a, (\\<sigma>', p')) \\<in> oseqp_sos \\<Gamma> i\" by auto\n    qed auto\n  qed\n\nend\n\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/AWN/OAWN_Invariants.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621765155565326, "lm_q2_score": 0.4571367168274948, "lm_q1q2_score": 0.25699152659903435}}
{"text": "section {*FUNCTION\\_\\_DPDA\\_RNE\\_\\_DPDA\\_REMOVE\\_NEUTRAL\\_EDGES*}\ntheory\n  FUNCTION__DPDA_RNE__DPDA_REMOVE_NEUTRAL_EDGES\n\nimports\n  PRJ_12_04_04_02__ENTRY\n\nbegin\n\ndefinition neutral_edges_removed :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"neutral_edges_removed G \\<equiv>\n  \\<not> (\\<exists>e \\<in> epda_delta G. FB_neutral_edge e)\"\n\ndefinition F_DPDA_RNE__edge__RL :: \"\n  (('state, 'event, 'stack) DT_state_or_edge, 'event, 'stack) epda_step_label\n  \\<Rightarrow> ('state, 'event, 'stack) epda_step_label\"\n  where\n    \"F_DPDA_RNE__edge__RL e \\<equiv>\n  \\<lparr>edge_src = case edge_src e of cons_state_or_edge_old q \\<Rightarrow> q,\n  edge_event = edge_event e,\n  edge_pop = edge_pop e,\n  edge_push = edge_push e,\n  edge_trg = case edge_trg e of cons_state_or_edge_old q \\<Rightarrow> q\\<rparr>\"\n\ndefinition F_DPDA_RNE__conf_old__LR :: \"\n  ('state, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge, 'event, 'stack) epdaS_conf\"\n  where\n    \"F_DPDA_RNE__conf_old__LR c \\<equiv>\n  \\<lparr>epdaS_conf_state = cons_state_or_edge_old (epdaS_conf_state c),\n  epdaS_conf_scheduler = epdaS_conf_scheduler c,\n  epdaS_conf_stack = epdaS_conf_stack c\\<rparr>\"\n\ndefinition F_DPDA_RNE__conf__RL :: \"\n  (('state, 'event, 'stack) DT_state_or_edge, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack) epdaS_conf\"\n  where\n    \"F_DPDA_RNE__conf__RL c \\<equiv>\n  case epdaS_conf_state c of cons_state_or_edge_old q\n  \\<Rightarrow> \\<lparr>epdaS_conf_state = q,\n    epdaS_conf_scheduler = epdaS_conf_scheduler c,\n    epdaS_conf_stack = epdaS_conf_stack c\\<rparr>\n  | cons_state_or_edge_new e\n  \\<Rightarrow> \\<lparr>epdaS_conf_state = edge_trg e,\n    epdaS_conf_scheduler = epdaS_conf_scheduler c,\n    epdaS_conf_stack = drop (Suc 0) (epdaS_conf_stack c)\\<rparr>\"\n\nlemma F_DPDA_RNE__preserves_epda: \"\n  valid_dpda G\n  \\<Longrightarrow> PB \\<notin> epda_gamma G\n  \\<Longrightarrow> valid_epda (F_DPDA_RNE G PB)\"\n  apply(simp add: valid_epda_def valid_pda_def valid_dpda_def F_DPDA_RNE_def)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_def)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(rename_tac xa)(*strict*)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac x)(*strict*)\n   apply(simp add: valid_epda_step_label_def)\n   apply(clarsimp)\n   apply(rename_tac x xa)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_def)\n   apply(erule_tac\n      x=\"xa\"\n      and P=\"\\<lambda>xa. edge_src xa \\<in> epda_states G \\<and> edge_trg xa \\<in> epda_states G \\<and> option_to_set (edge_event xa) \\<subseteq> epda_events G \\<and> edge_pop xa \\<in> may_terminated_by (epda_gamma G) (epda_box G) \\<and> edge_push xa \\<in> may_terminated_by (epda_gamma G) (epda_box G) \\<and> (edge_pop xa \\<in> must_terminated_by (epda_gamma G) (epda_box G)) = (edge_push xa \\<in> must_terminated_by (epda_gamma G) (epda_box G))\"\n      in ballE)\n    apply(rename_tac x xa)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac x xa)(*strict*)\n   apply(clarsimp)\n   apply(erule disjE)\n    apply(rename_tac x xa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac xa)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_1_def)\n    apply(rule conjI)\n     apply(rename_tac xa)(*strict*)\n     apply(simp add: option_to_set_def)\n    apply(rename_tac xa)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac xa)(*strict*)\n     apply(simp add: may_terminated_by_def kleene_star_def append_language_def)\n     apply(clarsimp)\n     apply(rename_tac xa a aa)(*strict*)\n     apply(erule_tac\n      P=\"edge_pop xa = a @ [epda_box G]\"\n      in disjE)\n      apply(rename_tac xa a aa)(*strict*)\n      apply(clarsimp)\n      apply(rule_tac\n      x=\"a\"\n      in exI)\n      apply(force)\n     apply(rename_tac xa a aa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac xa aa)(*strict*)\n     apply(rule_tac\n      x=\"edge_pop xa\"\n      in exI)\n     apply(force)\n    apply(rename_tac xa)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac xa)(*strict*)\n     apply(simp add: may_terminated_by_def kleene_star_def append_language_def)\n     apply(clarsimp)\n     apply(rename_tac xa a aa)(*strict*)\n     apply(erule_tac\n      P=\"edge_pop xa = a @ [epda_box G]\"\n      in disjE)\n      apply(rename_tac xa a aa)(*strict*)\n      apply(clarsimp)\n      apply(rule_tac\n      x=\"PB#a\"\n      in exI)\n      apply(force)\n     apply(rename_tac xa a aa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac xa aa)(*strict*)\n     apply(rule_tac\n      x=\"PB#edge_pop xa\"\n      in exI)\n     apply(force)\n    apply(rename_tac xa)(*strict*)\n    apply(rule order_antisym)\n     apply(rename_tac xa)(*strict*)\n     apply(clarsimp)\n     apply(simp add: must_terminated_by_def kleene_star_def append_language_def)\n     apply(clarsimp)\n    apply(rename_tac xa)(*strict*)\n    apply(clarsimp)\n    apply(simp add: must_terminated_by_def kleene_star_def append_language_def)\n    apply(clarsimp)\n    apply(rename_tac xa a)(*strict*)\n    apply(case_tac a)\n     apply(rename_tac xa a)(*strict*)\n     apply(force)\n    apply(rename_tac xa a aa list)(*strict*)\n    apply(subgoal_tac \"\\<exists>w' x'. a = w' @ [x']\")\n     apply(rename_tac xa a aa list)(*strict*)\n     prefer 2\n     apply(rule NonEmptyListHasTailElem)\n     apply(force)\n    apply(rename_tac xa a aa list)(*strict*)\n    apply(thin_tac \"a=aa#list\")\n    apply(clarsimp)\n    apply(rename_tac xa w' x')(*strict*)\n    apply(case_tac w')\n     apply(rename_tac xa w' x')(*strict*)\n     apply(force)\n    apply(rename_tac xa w' x' a list)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac x xa)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_2_def)\n   apply(simp add: option_to_set_def)\n   apply(simp add: may_terminated_by_def must_terminated_by_def kleene_star_def append_language_def)\n   apply(clarsimp)\n   apply(rename_tac xa a aa)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac xa a aa)(*strict*)\n    apply(rule_tac\n      x=\"[PB]\"\n      in exI)\n    apply(force)\n   apply(rename_tac xa a aa)(*strict*)\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac xa)(*strict*)\n  apply(simp add: F_DPDA_RNE__edge_else_def)\n  apply(simp add: valid_epda_step_label_def)\n  apply(erule_tac\n      x=\"xa\"\n      and P=\"\\<lambda>xa. edge_src xa \\<in> epda_states G \\<and> edge_trg xa \\<in> epda_states G \\<and> option_to_set (edge_event xa) \\<subseteq> epda_events G \\<and> edge_pop xa \\<in> may_terminated_by (epda_gamma G) (epda_box G) \\<and> edge_push xa \\<in> may_terminated_by (epda_gamma G) (epda_box G) \\<and> (edge_pop xa \\<in> must_terminated_by (epda_gamma G) (epda_box G)) = (edge_push xa \\<in> must_terminated_by (epda_gamma G) (epda_box G))\"\n      in ballE)\n   apply(rename_tac xa)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac xa)(*strict*)\n  apply(simp add: may_terminated_by_def must_terminated_by_def kleene_star_def append_language_def)\n  apply(clarsimp)\n  apply(rename_tac xa a aa)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac xa a aa)(*strict*)\n   apply(erule_tac\n      P=\"edge_pop xa = a @ [epda_box G]\"\n      in disjE)\n    apply(rename_tac xa a aa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac xa a aa ab)(*strict*)\n    apply(rule_tac\n      x=\"a\"\n      in exI)\n    apply(clarsimp)\n    apply(rename_tac xa a aa ab x)(*strict*)\n    apply(force)\n   apply(rename_tac xa a aa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac xa aa)(*strict*)\n   apply(rule_tac\n      x=\"edge_pop xa\"\n      in exI)\n   apply(force)\n  apply(rename_tac xa a aa)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac xa a aa)(*strict*)\n   apply(erule_tac\n      P=\"edge_pop xa = a @ [epda_box G]\"\n      in disjE)\n    apply(rename_tac xa a aa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac xa a aa ab)(*strict*)\n    apply(rule_tac\n      x=\"ab\"\n      in exI)\n    apply(clarsimp)\n    apply(rename_tac xa a aa ab x)(*strict*)\n    apply(force)\n   apply(rename_tac xa a aa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac xa aa)(*strict*)\n   apply(rule_tac\n      x=\"edge_push xa\"\n      in exI)\n   apply(force)\n  apply(rename_tac xa a aa)(*strict*)\n  apply(rule order_antisym)\n   apply(rename_tac xa a aa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac xa a aa ab)(*strict*)\n   apply(force)\n  apply(rename_tac xa a aa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac xa a aa ab)(*strict*)\n  apply(force)\n  done\n\nlemma F_DPDA_RNE__preserves_PDA: \"\n  valid_dpda G\n  \\<Longrightarrow> PB \\<notin> epda_gamma G\n  \\<Longrightarrow> valid_pda (F_DPDA_RNE G PB)\"\n  apply(simp add: valid_pda_def)\n  apply(rule conjI)\n   apply(rule F_DPDA_RNE__preserves_epda)\n    apply(force)\n   apply(clarsimp)\n  apply(simp add: valid_epda_def valid_pda_def valid_dpda_def F_DPDA_RNE_def)\n  apply(clarsimp)\n  apply(rename_tac e)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac e)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac e x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_def)\n   apply(erule disjE)\n    apply(rename_tac e x)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_1_def)\n   apply(rename_tac e x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_2_def)\n  apply(rename_tac e)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: F_DPDA_RNE__edge_else_def)\n  done\n\ntheorem F_DPDA_RNE__preserves_read_edges_seperated: \"\n  valid_dpda G\n  \\<Longrightarrow> read_edges_seperated G\n  \\<Longrightarrow> PB \\<notin> epda_gamma G\n  \\<Longrightarrow> read_edges_seperated (F_DPDA_RNE G PB)\"\n  apply(simp add: read_edges_seperated_def F_DPDA_RNE_def)\n  apply(clarsimp)\n  apply(rename_tac e)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac e)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac e x)(*strict*)\n   apply(simp add: strict_executing_edge_def FB_neutral_edge_def FB_executing_edge_def F_DPDA_RNE__edge_then_def)\n   apply(clarsimp)\n   apply(rename_tac e x y)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac e x y)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_1_def)\n   apply(rename_tac e x y)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_2_def)\n  apply(rename_tac e)(*strict*)\n  apply(simp add: strict_executing_edge_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(erule_tac\n      x=\"x\"\n      in ballE)\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: F_DPDA_RNE__edge_else_def)\n  apply(simp add: FB_executing_edge_def)\n  done\n\ntheorem F_DPDA_RNE__produces_neutral_edges_removed: \"\n  valid_dpda G\n  \\<Longrightarrow> PB \\<notin> epda_gamma G\n  \\<Longrightarrow> neutral_edges_removed (F_DPDA_RNE G PB)\"\n  apply(simp add: neutral_edges_removed_def F_DPDA_RNE_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x xa)(*strict*)\n   apply(simp add: FB_neutral_edge_def FB_executing_edge_def F_DPDA_RNE__edge_then_def)\n   apply(clarsimp)\n   apply(erule disjE)\n    apply(rename_tac x xa)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_1_def)\n   apply(rename_tac x xa)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_2_def)\n  apply(rename_tac x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac xa)(*strict*)\n  apply(simp add: F_DPDA_RNE__edge_else_def)\n  apply(simp add: FB_neutral_edge_def)\n  done\n\ndefinition F_DPDA_RNE__relation_structure__LR :: \"\n  ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_structure__LR G1 G2 \\<equiv>\n  valid_dpda G1\n  \\<and> G2 = F_DPDA_RNE G1 (F_FRESH (epda_gamma G1))\"\n\ndefinition F_DPDA_RNE__relation_configuration__LR :: \"\n  ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_configuration__LR G1 G2 c1 c2 \\<equiv>\n  F_DPDA_RNE__relation_structure__LR G1 G2\n  \\<and> c1 \\<in> epdaS.get_accessible_configurations G1\n  \\<and> c2 = F_DPDA_RNE__conf_old__LR c1\"\n\ndefinition F_DPDA_RNE__relation_initial_configuration__LR :: \"\n  ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_initial_configuration__LR G1 G2 c1 c2 \\<equiv>\n  F_DPDA_RNE__relation_structure__LR G1 G2\n  \\<and> c1 \\<in> epdaS_initial_configurations G1\n  \\<and> c2 = F_DPDA_RNE__conf_old__LR c1\"\n\ndefinition F_DPDA_RNE__relation_effect__LR :: \"\n  ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_effect__LR G1 G2 w1 w2 \\<equiv>\n  F_DPDA_RNE__relation_structure__LR G1 G2\n  \\<and> w1 = w2\"\n\nlemma epdaS_epdaS_RNoOp_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs: \"\n  (\\<forall>G1. Ex (F_DPDA_RNE__relation_structure__LR G1) \\<longrightarrow> valid_epda G1)\"\n  apply(clarsimp)\n  apply(rename_tac G1 x)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_structure__LR_def)\n  apply(rename_tac G1)(*strict*)\n  apply(simp add: valid_dpda_def valid_pda_def)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimLR_inst_AX_TSstructure_relation_TSstructure2_belongs: \"\n  (\\<forall>G1 G2. F_DPDA_RNE__relation_structure__LR G1 G2 \\<longrightarrow> valid_epda G2)\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_structure__LR_def)\n  apply(rename_tac G1)(*strict*)\n  apply (rule F_DPDA_RNE__preserves_epda)\n   apply(rename_tac G1)(*strict*)\n   apply(force)\n  apply(rename_tac G1)(*strict*)\n  apply(rule F_FRESH_is_fresh)\n  apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  done\n\ndefinition F_DPDA_RNE__conf_new__LR :: \"\n  ('state, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epda_step_label\n  \\<Rightarrow> 'stack DT_symbol\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf\"\n  where\n    \"F_DPDA_RNE__conf_new__LR c e PB \\<equiv>\n  \\<lparr>epdaS_conf_state = cons_state_or_edge_new e,\n  epdaS_conf_scheduler = epdaS_conf_scheduler c,\n  epdaS_conf_stack = [PB] @ epdaS_conf_stack c\\<rparr>\"\n\ndefinition F_DPDA_RNE__relation_step_simulation__LR :: \"\n  ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epda_step_label\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> ((('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda_step_label, (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_step_simulation__LR G1 G2 c1 e c1' c2 d \\<equiv>\n  if FB_neutral_edge e\n  then d = der3\n    (F_DPDA_RNE__conf_old__LR c1)\n      (F_DPDA_RNE__edge_then_1 e (F_FRESH (epda_gamma G1)))\n    (F_DPDA_RNE__conf_new__LR c1 e (F_FRESH (epda_gamma G1)))\n      (F_DPDA_RNE__edge_then_2 e (F_FRESH (epda_gamma G1)))\n    (F_DPDA_RNE__conf_old__LR c1')\n  else d = der2\n    (F_DPDA_RNE__conf_old__LR c1)\n      (F_DPDA_RNE__edge_else e)\n    (F_DPDA_RNE__conf_old__LR c1')\"\n\ndefinition F_DPDA_RNE__relation_initial_simulation__LR :: \"\n  ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> ((('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda_step_label, (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_initial_simulation__LR G1 G2 c1 d \\<equiv>\n  d = der1 (F_DPDA_RNE__conf_old__LR c1)\"\n\nlemma F_DPDA_RNE__conf_old__LR_preserves_configurations: \"\n  F_DPDA_RNE__relation_structure__LR G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS_configurations G1\n  \\<Longrightarrow> F_DPDA_RNE__conf_old__LR c1 \\<in> epdaS_configurations G2\"\n  apply(simp add: epdaS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac q i s)(*strict*)\n  apply(simp add: F_DPDA_RNE__conf_old__LR_def)\n  apply(simp add: F_DPDA_RNE__relation_structure__LR_def)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RNE_def)\n  apply(force)\n  done\n\nlemma F_DPDA_RNE__conf_old__LR_preserves_initial_configurations: \"\n  F_DPDA_RNE__relation_structure__LR G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS_initial_configurations G1\n  \\<Longrightarrow> F_DPDA_RNE__conf_old__LR c1 \\<in> epdaS_initial_configurations G2\"\n  apply(simp add: epdaS_initial_configurations_def)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RNE__conf_old__LR_def F_DPDA_RNE_def)\n   apply(simp add: F_DPDA_RNE__relation_structure__LR_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RNE__conf_old__LR_def F_DPDA_RNE_def)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RNE__conf_old__LR_def F_DPDA_RNE_def)\n   apply(simp add: F_DPDA_RNE__relation_structure__LR_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RNE__conf_old__LR_def F_DPDA_RNE_def)\n  apply(rule F_DPDA_RNE__conf_old__LR_preserves_configurations)\n   apply(force)\n  apply(force)\n  done\n\nlemma F_DPDA_RNE__conf_old__LR_preserves_marking_configurations: \"\n  F_DPDA_RNE__relation_structure__LR G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS_marking_configurations G1\n  \\<Longrightarrow> F_DPDA_RNE__conf_old__LR c1 \\<in> epdaS_marking_configurations G2\"\n  apply(simp add: epdaS_marking_configurations_def)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RNE__conf_old__LR_def F_DPDA_RNE_def)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RNE__conf_old__LR_def F_DPDA_RNE_def)\n   apply(simp add: F_DPDA_RNE__relation_structure__LR_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RNE__conf_old__LR_def F_DPDA_RNE_def)\n  apply(rule F_DPDA_RNE__conf_old__LR_preserves_configurations)\n   apply(force)\n  apply(force)\n  done\n\nlemma F_DPDA_RNE__initial_simulation_preserves_derivation: \"\n  F_DPDA_RNE__relation_structure__LR G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS_initial_configurations G1\n  \\<Longrightarrow> epdaS.derivation_initial G2 (der1 (F_DPDA_RNE__conf_old__LR c1))\"\n  apply(rule epdaS.derivation_initialI)\n   apply(rule epdaS.der1_is_derivation)\n  apply(clarsimp)\n  apply(rename_tac c)(*strict*)\n  apply(simp add: get_configuration_def der1_def)\n  apply(clarsimp)\n  apply(rule F_DPDA_RNE__conf_old__LR_preserves_initial_configurations)\n   apply(force)\n  apply(force)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimLR_inst_relation_initial_simulation: \"\n  \\<forall>G1 G2. F_DPDA_RNE__relation_structure__LR G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<exists>d2. epdaS.derivation_initial G2 d2 \\<and> F_DPDA_RNE__relation_initial_configuration__LR G1 G2 c1 (the (get_configuration (d2 0))) \\<and> F_DPDA_RNE__relation_initial_simulation__LR G1 G2 c1 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_DPDA_RNE__relation_configuration__LR G1 G2 c1 (the (get_configuration (d2 n))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_initial_simulation__LR_def)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule F_DPDA_RNE__initial_simulation_preserves_derivation)\n    apply(rename_tac G1 G2 c1)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_initial_configuration__LR_def)\n   apply(simp add: get_configuration_def der1_def)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule_tac\n      x=\"0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule der1_maximum_of_domain)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: get_configuration_def der1_def)\n  apply(simp add: F_DPDA_RNE__relation_configuration__LR_def)\n  apply(rule epdaS.initial_configurations_are_get_accessible_configurations)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_structure__LR_def valid_pda_def valid_dpda_def)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(force)\n  done\n\nlemma F_DPDA_RNE__relation_step_simulation__LR_maps_to_derivation: \"\n  F_DPDA_RNE__relation_step_simulation__LR G1 G2 c1 e1 c1' c2 d2\n  \\<Longrightarrow> F_DPDA_RNE__relation_configuration__LR G1 G2 c1 c2\n  \\<Longrightarrow> epdaS_step_relation G1 c1 e1 c1'\n  \\<Longrightarrow> epdaS.derivation G2 d2\"\n  apply(simp add: F_DPDA_RNE__relation_step_simulation__LR_def)\n  apply(case_tac \"FB_neutral_edge e1\")\n   apply(clarsimp)\n   apply(rule epdaS.der3_is_derivation)\n     apply(simp add: F_DPDA_RNE__relation_configuration__LR_def)\n     apply (metis epdaS_epdaS_RNoOp_StateSimLR_inst_AX_TSstructure_relation_TSstructure2_belongs)\n    apply(simp add: epdaS_step_relation_def F_DPDA_RNE__conf_old__LR_def F_DPDA_RNE__edge_then_1_def F_DPDA_RNE__conf_new__LR_def)\n    apply(clarsimp)\n    apply(rename_tac w)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac w)(*strict*)\n     prefer 2\n     apply(simp add: option_to_list_def FB_executing_edge_def)\n    apply(rename_tac w)(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_configuration__LR_def)\n    apply(simp add: F_DPDA_RNE__relation_structure__LR_def F_DPDA_RNE_def)\n    apply(rule_tac\n      x=\"e1\"\n      in bexI_image_disjI1)\n     apply(blast)\n    apply(rename_tac w)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_def)\n    apply(rule disjI1)\n    apply(simp add: F_DPDA_RNE__edge_then_1_def)\n   apply(simp add: epdaS_step_relation_def F_DPDA_RNE__conf_old__LR_def F_DPDA_RNE__edge_then_2_def F_DPDA_RNE__conf_new__LR_def)\n   apply(clarsimp)\n   apply(rename_tac w)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac w)(*strict*)\n    prefer 2\n    apply(simp add: option_to_list_def FB_neutral_edge_def)\n   apply(rename_tac w)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_configuration__LR_def)\n   apply(simp add: F_DPDA_RNE__relation_structure__LR_def F_DPDA_RNE_def)\n   apply(rule_tac\n      x=\"e1\"\n      in bexI_image_disjI1)\n    apply(blast)\n   apply(rename_tac w)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_def)\n   apply(rule disjI2)\n   apply(simp add: F_DPDA_RNE__edge_then_2_def)\n  apply(clarsimp)\n  apply(rule epdaS.der2_is_derivation)\n  apply(simp add: epdaS_step_relation_def F_DPDA_RNE__conf_old__LR_def F_DPDA_RNE__edge_else_def)\n  apply(clarsimp)\n  apply(rename_tac w)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_configuration__LR_def F_DPDA_RNE__relation_structure__LR_def F_DPDA_RNE_def)\n  apply(rule_tac\n      x=\"e1\"\n      in bexI_image_disjI2)\n   apply(blast)\n  apply(rename_tac w)(*strict*)\n  apply(simp add: F_DPDA_RNE__edge_else_def)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimLR_inst_relation_step_simulation: \"\n  (\\<forall>G1 G2. F_DPDA_RNE__relation_structure__LR G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_DPDA_RNE__relation_configuration__LR G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<exists>d2. epdaS.derivation G2 d2 \\<and> epdaS.belongs G2 d2 \\<and> the (get_configuration (d2 0)) = c2 \\<and> F_DPDA_RNE__relation_step_simulation__LR G1 G2 c1 e1 c1' c2 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_DPDA_RNE__relation_configuration__LR G1 G2 c1' (the (get_configuration (d2 n)))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_step_simulation__LR_def)\n  apply(case_tac \"FB_neutral_edge e1\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(clarsimp)\n   apply(rule context_conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(rule F_DPDA_RNE__relation_step_simulation__LR_maps_to_derivation)\n      apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_step_simulation__LR_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(rule epdaS.der3_belongs)\n      apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n      apply (metis epdaS_epdaS_RNoOp_StateSimLR_inst_AX_TSstructure_relation_TSstructure2_belongs)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(rule F_DPDA_RNE__conf_old__LR_preserves_configurations)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_configuration__LR_def)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n    apply (metis (full_types) epdaS_epdaS_RNoOp_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs epdaS.get_accessible_configurations_are_configurations subsetD)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(simp add: der3_def get_configuration_def F_DPDA_RNE__relation_configuration__LR_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule_tac\n      x=\"Suc(Suc 0)\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(rule_tac der3_maximum_of_domain)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_configuration__LR_def)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    prefer 2\n    apply(simp add: der3_def get_configuration_def F_DPDA_RNE__relation_configuration__LR_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule epdaS.der2_preserves_get_accessible_configurations)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     apply (metis epdaS_epdaS_RNoOp_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(rule epdaS.der2_is_derivation)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(clarsimp)\n  apply(rule context_conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule F_DPDA_RNE__relation_step_simulation__LR_maps_to_derivation)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_step_simulation__LR_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule epdaS.der2_belongs_prime)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     apply (metis epdaS_epdaS_RNoOp_StateSimLR_inst_AX_TSstructure_relation_TSstructure2_belongs)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(rule F_DPDA_RNE__conf_old__LR_preserves_configurations)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_configuration__LR_def)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n    apply (metis (full_types) epdaS_epdaS_RNoOp_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs epdaS.get_accessible_configurations_are_configurations subsetD)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(simp add: get_configuration_def der2_def F_DPDA_RNE__relation_configuration__LR_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule der2_maximum_of_domain)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(simp (no_asm) add: get_configuration_def der2_def)\n  apply(simp add: F_DPDA_RNE__relation_configuration__LR_def)\n  apply(rule epdaS.der2_preserves_get_accessible_configurations)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply (metis epdaS_epdaS_RNoOp_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule epdaS.der2_is_derivation)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(force)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms: \"\n  ATS_Simulation_Configuration_Weak_axioms valid_epda epdaS_initial_configurations epda_step_labels epdaS_step_relation valid_epda epdaS_configurations epdaS_initial_configurations epda_step_labels epdaS_step_relation F_DPDA_RNE__relation_configuration__LR F_DPDA_RNE__relation_initial_configuration__LR F_DPDA_RNE__relation_structure__LR F_DPDA_RNE__relation_initial_simulation__LR F_DPDA_RNE__relation_step_simulation__LR\"\n  apply(simp add: ATS_Simulation_Configuration_Weak_axioms_def)\n  apply(simp add: epdaS_epdaS_RNoOp_StateSimLR_inst_relation_initial_simulation epdaS_epdaS_RNoOp_StateSimLR_inst_relation_step_simulation epdaS_epdaS_RNoOp_StateSimLR_inst_AX_TSstructure_relation_TSstructure1_belongs epdaS_epdaS_RNoOp_StateSimLR_inst_AX_TSstructure_relation_TSstructure2_belongs)\n  done\n\ninterpretation \"epdaS_epdaS_RNoOp_StateSimLR\" : ATS_Simulation_Configuration_Weak\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaS_configurations\"\n  (* initial_configurations1 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaS_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaS_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_DPDA_RNE__relation_configuration__LR\"\n  (* relation_initial_configuration *)\n  \"F_DPDA_RNE__relation_initial_configuration__LR\"\n  (* relation_effect *)\n  \"F_DPDA_RNE__relation_effect__LR\"\n  (* relation_TSstructure *)\n  \"F_DPDA_RNE__relation_structure__LR\"\n  (* relation_initial_simulation *)\n  \"F_DPDA_RNE__relation_initial_simulation__LR\"\n  (* relation_step_simulation *)\n  \"F_DPDA_RNE__relation_step_simulation__LR\"\n  apply(simp add: LOCALE_DEFS epda_interpretations)\n  apply(simp add: epdaS_epdaS_RNoOp_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms epdaS_epdaS_RNoOp_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimLR_inst_relation_step_simulation_marking_condition: \"\n  (\\<forall>G1 G2. F_DPDA_RNE__relation_structure__LR G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_DPDA_RNE__relation_configuration__LR G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<forall>d2. F_DPDA_RNE__relation_step_simulation__LR G1 G2 c1 e1 c1' c2 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_DPDA_RNE__relation_initial_configuration__LR G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der2 c1 e1 c1') deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> epdaS_marking_condition G1 (derivation_append deri1 (der2 c1 e1 c1') deri1n) \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_DPDA_RNE__relation_configuration__LR F_DPDA_RNE__relation_initial_simulation__LR F_DPDA_RNE__relation_step_simulation__LR G1 G2 (derivation_append deri1 (der2 c1 e1 c1') deri1n) (Suc deri1n) (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> epdaS_marking_condition G2 (derivation_append deri2 d2 deri2n)))))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: epdaS_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(case_tac \"i\\<le>deri1n\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(subgoal_tac \"deri1 i = Some (pair e c)\")\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n    prefer 2\n    apply(simp add: derivation_append_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(thin_tac \"derivation_append deri1 (der2 c1 e1 c1') deri1n i = Some (pair e c)\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(simp add: epdaS_epdaS_RNoOp_StateSimLR.simulating_derivation_def)\n   apply(clarsimp)\n   apply(simp add: epdaS_epdaS_RNoOp_StateSimLR.simulating_derivation_DEF_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"i\"\n      in allE)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c y)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_configuration__LR_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c y)(*strict*)\n   apply(case_tac y)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c y option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c option b)(*strict*)\n   apply(rename_tac e c)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(rule_tac\n      x=\"f i\"\n      in exI)\n   apply(rule_tac\n      x=\"e\"\n      in exI)\n   apply(rule_tac\n      x=\"c\"\n      in exI)\n   apply(clarsimp)\n   apply(rule_tac\n      t=\"c\"\n      and s=\"F_DPDA_RNE__conf_old__LR ca\"\n      in ssubst)\n    apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n    apply(simp add: F_DPDA_RNE__conf_old__LR_def derivation_append_def get_configuration_def)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(rule F_DPDA_RNE__conf_old__LR_preserves_marking_configurations)\n    apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(subgoal_tac \"i=Suc deri1n\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e c)(*strict*)\n   apply(subgoal_tac \"c=c1'\")\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e c)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e)(*strict*)\n    apply(simp add: epdaS_epdaS_RNoOp_StateSimLR.simulating_derivation_def)\n    apply(simp add: epdaS_epdaS_RNoOp_StateSimLR.simulating_derivation_DEF_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"Suc deri1n\"\n      in allE)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e y)(*strict*)\n    apply(rule_tac\n      x=\"deri2n+n\"\n      in exI)\n    apply(case_tac y)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e y option b)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e option b)(*strict*)\n    apply(rename_tac e c)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n    apply(rule_tac\n      t=\"c\"\n      and s=\"F_DPDA_RNE__conf_old__LR c1'\"\n      in ssubst)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n     apply(simp add: F_DPDA_RNE__relation_configuration__LR_def derivation_append_def get_configuration_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n    apply(rule F_DPDA_RNE__conf_old__LR_preserves_marking_configurations)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e c)(*strict*)\n   apply(simp add: derivation_append_def der2_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(case_tac \"i>Suc deri1n\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(clarsimp)\n  apply(simp add: derivation_append_def der2_def)\n  apply(case_tac \"i-deri1n\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c nat)(*strict*)\n  apply(clarsimp)\n  apply(case_tac nat)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i c)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c nat nata)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimLR_inst_relation_initial_simulation_marking_condition: \"\n  \\<forall>G1 G2. F_DPDA_RNE__relation_structure__LR G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<forall>d2. F_DPDA_RNE__relation_initial_simulation__LR G1 G2 c1 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_DPDA_RNE__relation_initial_configuration__LR G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der1 c1) deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> epdaS_marking_condition G1 (derivation_append deri1 (der1 c1) deri1n) \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_DPDA_RNE__relation_configuration__LR F_DPDA_RNE__relation_initial_simulation__LR F_DPDA_RNE__relation_step_simulation__LR G1 G2 (derivation_append deri1 (der1 c1) deri1n) deri1n (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> epdaS_marking_condition G2 (derivation_append deri2 d2 deri2n))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: epdaS_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(case_tac \"i\\<le>deri1n\")\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(subgoal_tac \"deri1 i = Some (pair e c)\")\n    apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n    prefer 2\n    apply(simp add: derivation_append_def)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(simp add: epdaS_epdaS_RNoOp_StateSimLR.simulating_derivation_def)\n   apply(clarsimp)\n   apply(simp add: epdaS_epdaS_RNoOp_StateSimLR.simulating_derivation_DEF_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"i\"\n      in allE)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c y)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_configuration__LR_def)\n   apply(clarsimp)\n   apply(case_tac y)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c y option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c option b)(*strict*)\n   apply(rename_tac e c)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(rule_tac\n      x=\"f i\"\n      in exI)\n   apply(rule_tac\n      x=\"e\"\n      in exI)\n   apply(rule_tac\n      x=\"c\"\n      in exI)\n   apply(clarsimp)\n   apply(rule_tac\n      t=\"c\"\n      and s=\"F_DPDA_RNE__conf_old__LR ca\"\n      in ssubst)\n    apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n    apply(simp add: F_DPDA_RNE__conf_old__LR_def derivation_append_def get_configuration_def)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(rule F_DPDA_RNE__conf_old__LR_preserves_marking_configurations)\n    apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(subgoal_tac \"i=deri1n\")\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(case_tac \"i>deri1n\")\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(clarsimp)\n  apply(simp add: derivation_append_def der1_def)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimLR_inst_ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms: \"\n  ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms epdaS_initial_configurations epda_step_labels epdaS_step_relation epdaS_marking_condition epdaS_initial_configurations epdaS_step_relation epdaS_marking_condition F_DPDA_RNE__relation_configuration__LR F_DPDA_RNE__relation_initial_configuration__LR F_DPDA_RNE__relation_structure__LR F_DPDA_RNE__relation_initial_simulation__LR F_DPDA_RNE__relation_step_simulation__LR\"\n  apply(simp add: ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms_def)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(rule epdaS_epdaS_RNoOp_StateSimLR.relation_step_simulation_preservation_PROVE2)\n    apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n    prefer 2\n    apply(rename_tac G1 G2 d1' d2')(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(thin_tac \"epdaS_epdaS_RNoOp_StateSimLR.relation_step_simulation_preservation G1 G2 d1' d2'\")\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(metis epdaS_epdaS_RNoOp_StateSimLR_inst_relation_step_simulation_marking_condition)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 d1' d2')(*strict*)\n  apply(rule epdaS_epdaS_RNoOp_StateSimLR.relation_initial_simulation_preservation_PROVE2)\n   apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   prefer 2\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(thin_tac \"epdaS_epdaS_RNoOp_StateSimLR.relation_initial_simulation_preservation G1 G2 d1' d2'\")\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(metis epdaS_epdaS_RNoOp_StateSimLR_inst_relation_initial_simulation_marking_condition)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimLR_inst_relation_step_simulation_marked_effect: \"\n  (\\<forall>G1 G2. F_DPDA_RNE__relation_structure__LR G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_DPDA_RNE__relation_configuration__LR G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<forall>d2. F_DPDA_RNE__relation_step_simulation__LR G1 G2 c1 e1 c1' c2 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_DPDA_RNE__relation_initial_configuration__LR G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der2 c1 e1 c1') deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_DPDA_RNE__relation_configuration__LR F_DPDA_RNE__relation_initial_simulation__LR F_DPDA_RNE__relation_step_simulation__LR G1 G2 (derivation_append deri1 (der2 c1 e1 c1') deri1n) (Suc deri1n) (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> left_total_on (F_DPDA_RNE__relation_effect__LR G1 G2) (epdaS_marked_effect G1 (derivation_append deri1 (der2 c1 e1 c1') deri1n)) (epdaS_marked_effect G2 (derivation_append deri2 d2 deri2n))))))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(rule_tac\n      x=\"a\"\n      in bexI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_effect__LR_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(simp add: epdaS_marked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri2 0 = Some (pair None c)\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c ca)(*strict*)\n   apply(simp add: derivation_append_def F_DPDA_RNE__relation_initial_configuration__LR_def)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n   apply(simp add: F_DPDA_RNE__conf_old__LR_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(rule_tac\n      M=\"G2\"\n      in epdaS.some_position_has_details_at_0)\n  apply (metis epdaS.derivation_initial_is_derivation)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimLR_inst_relation_initial_simulation_marked_effect: \"\n  \\<forall>G1 G2. F_DPDA_RNE__relation_structure__LR G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<forall>d2. F_DPDA_RNE__relation_initial_simulation__LR G1 G2 c1 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_DPDA_RNE__relation_initial_configuration__LR G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der1 c1) deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_DPDA_RNE__relation_configuration__LR F_DPDA_RNE__relation_initial_simulation__LR F_DPDA_RNE__relation_step_simulation__LR G1 G2 (derivation_append deri1 (der1 c1) deri1n) deri1n (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> left_total_on (F_DPDA_RNE__relation_effect__LR G1 G2) (epdaS_marked_effect G1 (derivation_append deri1 (der1 c1) deri1n)) (epdaS_marked_effect G2 (derivation_append deri2 d2 deri2n)))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(rule_tac\n      x=\"a\"\n      in bexI)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_effect__LR_def)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(simp add: epdaS_marked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri2 0 = Some (pair None c)\")\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c ca)(*strict*)\n   apply(simp add: derivation_append_def F_DPDA_RNE__relation_initial_configuration__LR_def)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n   apply(simp add: F_DPDA_RNE__conf_old__LR_def)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(rule_tac\n      M=\"G2\"\n      in epdaS.some_position_has_details_at_0)\n  apply (metis epdaS.derivation_initial_is_derivation)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimLR_inst_ATS_Simulation_Configuration_Weak_Marked_Effect_axioms: \"\n  ATS_Simulation_Configuration_Weak_Marked_Effect_axioms epdaS_initial_configurations epda_step_labels epdaS_step_relation epdaS_marked_effect epdaS_initial_configurations epdaS_step_relation epdaS_marked_effect F_DPDA_RNE__relation_configuration__LR F_DPDA_RNE__relation_initial_configuration__LR F_DPDA_RNE__relation_effect__LR F_DPDA_RNE__relation_structure__LR F_DPDA_RNE__relation_initial_simulation__LR F_DPDA_RNE__relation_step_simulation__LR\"\n  apply(simp add: ATS_Simulation_Configuration_Weak_Marked_Effect_axioms_def)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(rule epdaS_epdaS_RNoOp_StateSimLR.relation_step_simulation_preservation_PROVE2)\n    apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n    prefer 2\n    apply(rename_tac G1 G2 d1' d2')(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(thin_tac \"epdaS_epdaS_RNoOp_StateSimLR.relation_step_simulation_preservation G1 G2 d1' d2'\")\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(metis epdaS_epdaS_RNoOp_StateSimLR_inst_relation_step_simulation_marked_effect)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 d1' d2')(*strict*)\n  apply(rule epdaS_epdaS_RNoOp_StateSimLR.relation_initial_simulation_preservation_PROVE2)\n   apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   prefer 2\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(thin_tac \"epdaS_epdaS_RNoOp_StateSimLR.relation_initial_simulation_preservation G1 G2 d1' d2'\")\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(metis epdaS_epdaS_RNoOp_StateSimLR_inst_relation_initial_simulation_marked_effect)\n  done\n\ninterpretation \"epdaS_epdaS_RNoOp_StateSimLR\" : ATS_Simulation_Configuration_Weak_Marked_Effect\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaS_configurations\"\n  (* initial_configurations1 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaS_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaS_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_DPDA_RNE__relation_configuration__LR\"\n  (* relation_initial_configuration *)\n  \"F_DPDA_RNE__relation_initial_configuration__LR\"\n  (* relation_effect *)\n  \"F_DPDA_RNE__relation_effect__LR\"\n  (* relation_TSstructure *)\n  \"F_DPDA_RNE__relation_structure__LR\"\n  (* relation_initial_simulation *)\n  \"F_DPDA_RNE__relation_initial_simulation__LR\"\n  (* relation_step_simulation *)\n  \"F_DPDA_RNE__relation_step_simulation__LR\"\n  apply(simp add: LOCALE_DEFS epda_interpretations)\n  apply(simp add: epdaS_epdaS_RNoOp_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms epdaS_epdaS_RNoOp_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axioms epdaS_epdaS_RNoOp_StateSimLR_inst_ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms epdaS_epdaS_RNoOp_StateSimLR_inst_ATS_Simulation_Configuration_Weak_Marked_Effect_axioms )\n  done\n\nlemma F_DPDA_RNE__preserves_lang1: \"\n  valid_dpda (G :: ('state, 'event, 'list DT_symbol) epda)\n  \\<Longrightarrow> epdaS.marked_language G \\<subseteq> epdaS.marked_language (F_DPDA_RNE G (F_FRESH (epda_gamma G)))\"\n  apply(rule_tac\n      t=\"epdaS.marked_language G\"\n      and s=\"epdaS.finite_marked_language G\"\n      in subst)\n   apply(rule epdaS.AX_marked_language_finite)\n   apply(simp add: valid_dpda_def valid_pda_def)\n  apply(rule_tac\n      t=\"epdaS.marked_language (F_DPDA_RNE G (F_FRESH (epda_gamma G)))\"\n      and s=\"epdaS.finite_marked_language (F_DPDA_RNE G (F_FRESH (epda_gamma G)))\"\n      in ssubst)\n   apply(rule sym)\n   apply(rule epdaS.AX_marked_language_finite)\n   apply (rule F_DPDA_RNE__preserves_epda)\n    apply(force)\n   apply(rule F_FRESH_is_fresh)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(subgoal_tac \"left_total_on (F_DPDA_RNE__relation_effect__LR SSG1 SSG2) (epdaS.finite_marked_language SSG1) (epdaS.finite_marked_language SSG2)\" for SSG1 SSG2)\n   prefer 2\n   apply(rule_tac\n      ?G1.0=\"G\"\n      in epdaS_epdaS_RNoOp_StateSimLR.ATS_Simulation_Configuration_Weak_Marked_Effect_sound)\n   apply(simp add: F_DPDA_RNE__relation_structure__LR_def)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(erule_tac\n      x=\"x\"\n      in ballE)\n   apply(rename_tac x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x b)(*strict*)\n   prefer 2\n   apply(rename_tac x)(*strict*)\n   apply(force)\n  apply(rename_tac x b)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_effect__LR_def)\n  done\n\ndefinition F_DPDA_RNE__relation_structure__RL :: \"\n  (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_structure__RL G1 G2 \\<equiv>\n  valid_dpda G2\n  \\<and> G1 = F_DPDA_RNE G2 (F_FRESH (epda_gamma G2))\"\n\ndefinition F_DPDA_RNE__relation_configuration__RL :: \"\n  (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_configuration__RL G1 G2 c1 c2 \\<equiv>\n  F_DPDA_RNE__relation_structure__RL G1 G2\n  \\<and> c1 \\<in> epdaS.get_accessible_configurations G1\n  \\<and> c2 = F_DPDA_RNE__conf__RL c1\"\n\ndefinition F_DPDA_RNE__relation_initial_configuration__RL :: \"\n  (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_initial_configuration__RL G1 G2 c1 c2 \\<equiv>\n  F_DPDA_RNE__relation_structure__RL G1 G2\n  \\<and> c1 \\<in> epdaS_initial_configurations G1\n  \\<and> c2 = F_DPDA_RNE__conf__RL c1\"\n\ndefinition F_DPDA_RNE__relation_effect__RL :: \"\n  (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_effect__RL G1 G2 w1 w2 \\<equiv>\n  F_DPDA_RNE__relation_structure__RL G1 G2\n  \\<and> w1 = w2\"\n\nlemma epdaS_epdaS_RNoOp_StateSimRL_inst_AX_TSstructure_relation_TSstructure1_belongs: \"\n  (\\<forall>G1. Ex (F_DPDA_RNE__relation_structure__RL G1) \\<longrightarrow> valid_epda G1)\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n  apply(clarsimp)\n  apply(rename_tac G2)(*strict*)\n  apply(rule F_DPDA_RNE__preserves_epda)\n   apply(rename_tac G2)(*strict*)\n   apply(force)\n  apply(rename_tac G2)(*strict*)\n  apply(rule F_FRESH_is_fresh)\n  apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimRL_inst_AX_TSstructure_relation_TSstructure2_belongs: \"\n  (\\<forall>G1 G2. F_DPDA_RNE__relation_structure__RL G1 G2 \\<longrightarrow> valid_epda G2)\"\n  apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n  apply(clarsimp)\n  apply(rename_tac G2)(*strict*)\n  apply (metis valid_dpda_def valid_pda_def)\n  done\n\ndefinition F_DPDA_RNE__relation_step_simulation__RL :: \"\n  (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event , 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda_step_label\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event , 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) epda_step_label, ('state, 'event, 'stack DT_symbol) epdaS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_step_simulation__RL G1 G2 c1 e c1' c2 d \\<equiv>\n  case edge_trg e of cons_state_or_edge_old q\n  \\<Rightarrow> (case edge_src e of cons_state_or_edge_old q\n    \\<Rightarrow> d = der2\n      (F_DPDA_RNE__conf__RL c1)\n        (F_DPDA_RNE__edge__RL e)\n      (F_DPDA_RNE__conf__RL c1')\n    | cons_state_or_edge_new e\n    \\<Rightarrow> d = der1 (F_DPDA_RNE__conf__RL c1))\n  | cons_state_or_edge_new e\n  \\<Rightarrow> d = der2\n    (F_DPDA_RNE__conf__RL c1)\n      e\n    (F_DPDA_RNE__conf__RL c1')\"\n\ndefinition F_DPDA_RNE__relation_initial_simulation__RL :: \"\n  (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event , 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> (('state, 'event , 'stack DT_symbol) epda_step_label, ('state, 'event , 'stack DT_symbol) epdaS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_initial_simulation__RL G1 G2 c1 d \\<equiv>\n  d = der1 (F_DPDA_RNE__conf__RL c1)\"\n\ndefinition pseudo_box_top :: \"\n  ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event , 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"pseudo_box_top G c \\<equiv>\n  case epdaS_conf_state c of cons_state_or_edge_old q\n  \\<Rightarrow> F_FRESH (epda_gamma G) \\<notin> set (epdaS_conf_stack c)\n  | cons_state_or_edge_new e\n  \\<Rightarrow> \\<exists>w. F_FRESH (epda_gamma G) \\<notin> set w\n    \\<and> [F_FRESH (epda_gamma G)] @ w = epdaS_conf_stack c\"\n\nlemma RNoOp_create_no_pseudo_box_in_the_configuration: \"\n  F_DPDA_RNE__relation_structure__RL G1 G2\n  \\<Longrightarrow> epdaS.derivation_initial G1 d\n  \\<Longrightarrow> d i = Some (pair e c1)\n  \\<Longrightarrow> pseudo_box_top G2 c1\"\n  apply(simp add: pseudo_box_top_def)\n  apply(induct i arbitrary: e c1)\n   apply(rename_tac e c1)(*strict*)\n   apply(simp add: epdaS.derivation_initial_def)\n   apply(clarsimp)\n   apply(rename_tac c1)(*strict*)\n   apply(simp add: epdaS_initial_configurations_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RNE_def)\n   apply(clarsimp)\n   apply(subgoal_tac \"F_FRESH (epda_gamma G2) \\<notin> epda_gamma G2\")\n    apply(rename_tac c1)(*strict*)\n    apply(subgoal_tac \"epda_box G2 \\<in> epda_gamma G2\")\n     apply(rename_tac c1)(*strict*)\n     apply(force)\n    apply(rename_tac c1)(*strict*)\n    apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac c1)(*strict*)\n   apply(rule F_FRESH_is_fresh)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rename_tac i e c1)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d i = Some (pair e1 c1) \\<and> SSd (Suc SSn) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation SSG c1 e2 c2\" for SSd SSn SSG)\n   apply(rename_tac i e c1)(*strict*)\n   prefer 2\n   apply(rule epdaS.step_detail_before_some_position)\n     apply(rename_tac i e c1)(*strict*)\n     apply(simp add: epdaS.derivation_initial_def)\n     apply(force)\n    apply(rename_tac i e c1)(*strict*)\n    apply(force)\n   apply(rename_tac i e c1)(*strict*)\n   apply(force)\n  apply(rename_tac i e c1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i c1 e1 e2 c1a)(*strict*)\n  apply(erule_tac\n      x=\"e1\"\n      in meta_allE)\n  apply(erule_tac\n      x=\"c1a\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(subgoal_tac \"valid_epda_step_label G1 e2\")\n   apply(rename_tac i c1 e1 e2 c1a)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"valid_epda G1\")\n    apply(rename_tac i c1 e1 e2 c1a)(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_structure__RL_def valid_dpda_def valid_pda_def valid_epda_def)\n    apply(clarsimp)\n    apply(simp add: epdaS_step_relation_def)\n   apply(rename_tac i c1 e1 e2 c1a)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n   apply (rule F_DPDA_RNE__preserves_epda)\n    apply(rename_tac i c1 e1 e2 c1a)(*strict*)\n    apply(force)\n   apply(rename_tac i c1 e1 e2 c1a)(*strict*)\n   apply(rule F_FRESH_is_fresh)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rename_tac i c1 e1 e2 c1a)(*strict*)\n  apply(case_tac \"epdaS_conf_state c1\")\n   apply(rename_tac i c1 e1 e2 c1a q)(*strict*)\n   apply(clarsimp)\n   apply(simp add: epdaS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac i c1 e1 e2 c1a q w)(*strict*)\n   apply(case_tac \"edge_src e2\")\n    apply(rename_tac i c1 e1 e2 c1a q w qa)(*strict*)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RNE_def)\n    apply(clarsimp)\n    apply(erule disjE)\n     apply(rename_tac i c1 e1 e2 c1a q w qa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac i c1 e1 e2 c1a q w qa x)(*strict*)\n     apply(simp add: F_DPDA_RNE__edge_then_def)\n     apply(erule disjE)\n      apply(rename_tac i c1 e1 e2 c1a q w qa x)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac i c1 e1 c1a q w qa x)(*strict*)\n      apply(simp add: F_DPDA_RNE__edge_then_1_def)\n     apply(rename_tac i c1 e1 e2 c1a q w qa x)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac i c1 e1 c1a q w qa x)(*strict*)\n     apply(simp add: F_DPDA_RNE__edge_then_2_def)\n    apply(rename_tac i c1 e1 e2 c1a q w qa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i c1 e1 c1a q w qa x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_else_def FB_neutral_edge_def)\n    apply(clarsimp)\n    apply(rename_tac i c1 e1 c1a w x)(*strict*)\n    apply(simp add: valid_epda_step_label_def)\n    apply(clarsimp)\n    apply(subgoal_tac \"F_FRESH (epda_gamma G2) \\<notin> epda_gamma G2\")\n     apply(rename_tac i c1 e1 c1a w x)(*strict*)\n     apply(subgoal_tac \"set (edge_push x) \\<subseteq> epda_gamma G2\")\n      apply(rename_tac i c1 e1 c1a w x)(*strict*)\n      apply(force)\n     apply(rename_tac i c1 e1 c1a w x)(*strict*)\n     apply(rule epda_edge_in_gamma)\n      apply(rename_tac i c1 e1 c1a w x)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n     apply(rename_tac i c1 e1 c1a w x)(*strict*)\n     apply(force)\n    apply(rename_tac i c1 e1 c1a w x)(*strict*)\n    apply(rule F_FRESH_is_fresh)\n    apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext wa)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext wa)(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n    apply(simp add: F_DPDA_RNE_def)\n    apply(clarsimp)\n    apply(erule disjE)\n     apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext wa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext wa x)(*strict*)\n     apply(simp add: F_DPDA_RNE__edge_then_def)\n     apply(erule disjE)\n      apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext wa x)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac i c1 e1 c1a q w epda_step_label_ext wa x)(*strict*)\n      apply(simp add: F_DPDA_RNE__edge_then_1_def)\n     apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext wa x)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac i c1 e1 c1a q w epda_step_label_ext wa x)(*strict*)\n     apply(simp add: F_DPDA_RNE__edge_then_2_def)\n    apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext wa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i c1 e1 c1a q w epda_step_label_ext wa x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_else_def FB_neutral_edge_def)\n   apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext wa)(*strict*)\n   apply(case_tac \"edge_pop e2\")\n    apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext wa)(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_structure__RL_def valid_dpda_def valid_pda_def valid_epda_def)\n    apply(clarsimp)\n    apply(rename_tac i c1 e1 e2 c1a q epda_step_label_ext wa)(*strict*)\n    apply(simp add: F_DPDA_RNE_def)\n    apply(clarsimp)\n    apply(erule disjE)\n     apply(rename_tac i c1 e1 e2 c1a q epda_step_label_ext wa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac i c1 e1 e2 c1a q epda_step_label_ext wa x)(*strict*)\n     apply(simp add: F_DPDA_RNE__edge_then_def)\n     apply(erule disjE)\n      apply(rename_tac i c1 e1 e2 c1a q epda_step_label_ext wa x)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac i c1 e1 c1a q epda_step_label_ext wa x)(*strict*)\n      apply(simp add: F_DPDA_RNE__edge_then_1_def)\n     apply(rename_tac i c1 e1 e2 c1a q epda_step_label_ext wa x)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac i c1 e1 c1a q epda_step_label_ext wa x)(*strict*)\n     apply(simp add: F_DPDA_RNE__edge_then_2_def)\n    apply(rename_tac i c1 e1 e2 c1a q epda_step_label_ext wa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i c1 e1 c1a q epda_step_label_ext wa x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_else_def FB_neutral_edge_def)\n   apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext wa a list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"epdaS_conf_state c1a\")\n   apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext q)(*strict*)\n   apply(clarsimp)\n   apply(simp add: epdaS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext q w)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RNE_def)\n   apply(clarsimp)\n   apply(erule disjE)\n    apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext q w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext q w x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_def)\n    apply(erule disjE)\n     apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext q w x)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac i c1 e1 c1a epda_step_label_ext q w x)(*strict*)\n     apply(simp add: F_DPDA_RNE__edge_then_1_def)\n    apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext q w x)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i c1 e1 c1a epda_step_label_ext q w x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_2_def)\n   apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext q w)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i c1 e1 c1a epda_step_label_ext q w x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_else_def FB_neutral_edge_def)\n  apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext epda_step_label_exta)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext epda_step_label_exta w)(*strict*)\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext epda_step_label_exta w wa)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RNE_def)\n  apply(clarsimp)\n  apply(erule disjE)\n   apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext epda_step_label_exta w wa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext epda_step_label_exta w wa x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_def)\n   apply(erule disjE)\n    apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext epda_step_label_exta w wa x)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i c1 e1 c1a epda_step_label_ext epda_step_label_exta w wa x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_1_def)\n   apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext epda_step_label_exta w wa x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i c1 e1 c1a epda_step_label_ext epda_step_label_exta w wa x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_2_def)\n  apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext epda_step_label_exta w wa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i c1 e1 c1a epda_step_label_ext epda_step_label_exta w wa x)(*strict*)\n  apply(simp add: F_DPDA_RNE__edge_else_def FB_neutral_edge_def)\n  done\n\nlemma RNoOp_create_no_pseudo_box_in_the_configuration_prime: \"\n  F_DPDA_RNE__relation_structure__RL G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS.get_accessible_configurations G1\n  \\<Longrightarrow> pseudo_box_top G2 c1\"\n  apply(simp add: epdaS.get_accessible_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac d i)(*strict*)\n  apply(case_tac \"d i\")\n   apply(rename_tac d i)(*strict*)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d i a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac d i a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i option b)(*strict*)\n  apply(rename_tac e c)\n  apply(rename_tac d i e c)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac d i e)(*strict*)\n  apply(rule RNoOp_create_no_pseudo_box_in_the_configuration)\n    apply(rename_tac d i e)(*strict*)\n    apply(force)+\n  done\n\nlemma F_DPDA_RNE__conf__RL_preserves_configurations: \"\n  F_DPDA_RNE__relation_structure__RL G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS.get_accessible_configurations G1\n  \\<Longrightarrow> c1 \\<in> epdaS_configurations G1\n  \\<Longrightarrow> F_DPDA_RNE__conf__RL c1 \\<in> epdaS_configurations G2\"\n  apply(subgoal_tac \"case (epdaS_conf_state c1) of cons_state_or_edge_old q \\<Rightarrow> (F_FRESH (epda_gamma G2) \\<notin> set (epdaS_conf_stack c1)) | cons_state_or_edge_new e \\<Rightarrow> (\\<exists>w. F_FRESH (epda_gamma G2) \\<notin> set w \\<and> ([F_FRESH (epda_gamma G2)]@w) = epdaS_conf_stack c1)\")\n   apply(simp (no_asm) add: epdaS_configurations_def)\n   apply(case_tac \"epdaS_conf_state c1\")\n    apply(rename_tac q)(*strict*)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RNE__conf__RL_def)\n    apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n    apply(clarsimp)\n    apply(simp add: epdaS_configurations_def)\n    apply(clarsimp)\n    apply(rename_tac q i s)(*strict*)\n    apply(simp add: F_DPDA_RNE_def)\n    apply(rule conjI)\n     apply(rename_tac q i s)(*strict*)\n     apply(erule disjE)\n      apply(rename_tac q i s)(*strict*)\n      apply(force)\n     apply(rename_tac q i s)(*strict*)\n     apply(force)\n    apply(rename_tac q i s)(*strict*)\n    apply(force)\n   apply(rename_tac epda_step_label_ext)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac epda_step_label_ext w)(*strict*)\n   apply(simp add: F_DPDA_RNE__conf__RL_def)\n   apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n   apply(clarsimp)\n   apply(simp add: epdaS_configurations_def)\n   apply(clarsimp)\n   apply(rename_tac epda_step_label_ext w i)(*strict*)\n   apply(simp add: F_DPDA_RNE_def)\n   apply(rule conjI)\n    apply(rename_tac epda_step_label_ext w i)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac epda_step_label_ext w i)(*strict*)\n     apply(force)\n    apply(rename_tac epda_step_label_ext w i)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac w i x)(*strict*)\n    apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"x\"\n      and P=\"\\<lambda>x. valid_epda_step_label G2 x\"\n      in ballE)\n     apply(rename_tac w i x)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac w i x)(*strict*)\n    apply(simp add: valid_epda_step_label_def)\n   apply(rename_tac epda_step_label_ext w i)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac epda_step_label_ext w i x)(*strict*)\n   apply(force)\n  apply(fold pseudo_box_top_def)\n  apply(rule RNoOp_create_no_pseudo_box_in_the_configuration_prime)\n   apply(force)+\n  done\n\nlemma F_DPDA_RNE__conf__RL_preserves_initial_configurations: \"\n  F_DPDA_RNE__relation_structure__RL G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS_initial_configurations G1\n  \\<Longrightarrow> F_DPDA_RNE__conf__RL c1 \\<in> epdaS_initial_configurations G2\"\n  apply(simp add: epdaS_initial_configurations_def)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RNE__conf__RL_def)\n   apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RNE_def)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RNE__conf__RL_def)\n   apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RNE_def)\n  apply(clarsimp)\n  apply(simp add: epdaS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(simp add: F_DPDA_RNE__conf__RL_def F_DPDA_RNE__relation_structure__RL_def F_DPDA_RNE_def)\n  apply(clarsimp)\n  apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimRL_inst_relation_initial_simulation: \"\n  (\\<forall>G1 G2. F_DPDA_RNE__relation_structure__RL G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<exists>d2. epdaS.derivation_initial G2 d2 \\<and> F_DPDA_RNE__relation_initial_configuration__RL G1 G2 c1 (the (get_configuration (d2 0))) \\<and> F_DPDA_RNE__relation_initial_simulation__RL G1 G2 c1 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_DPDA_RNE__relation_configuration__RL G1 G2 c1 (the (get_configuration (d2 n)))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_initial_simulation__RL_def)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule epdaS.derivation_initialI)\n    apply(rename_tac G1 G2 c1)(*strict*)\n    apply(rule epdaS.der1_is_derivation)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: get_configuration_def der1_def)\n   apply(rule F_DPDA_RNE__conf__RL_preserves_initial_configurations)\n    apply(rename_tac G1 G2 c1)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: get_configuration_def der1_def)\n   apply(simp add: F_DPDA_RNE__relation_initial_configuration__RL_def)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule_tac\n      x=\"0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule der1_maximum_of_domain)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: get_configuration_def der1_def)\n  apply(simp add: F_DPDA_RNE__relation_configuration__RL_def)\n  apply(rule epdaS.initial_configurations_are_get_accessible_configurations)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n   apply(rule F_DPDA_RNE__preserves_epda)\n    apply(rename_tac G1 G2 c1)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule F_FRESH_is_fresh)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(force)\n  done\n\nlemma F_DPDA_RNE__relation_step_simulation__RL_maps_to_derivation: \"\n  F_DPDA_RNE__relation_structure__RL G1 G2\n  \\<Longrightarrow> F_DPDA_RNE__relation_step_simulation__RL G1 G2 c1 e1 c1' c2 d2\n  \\<Longrightarrow> F_DPDA_RNE__relation_configuration__RL G1 G2 c1 c2\n  \\<Longrightarrow> epdaS_step_relation G1 c1 e1 c1'\n  \\<Longrightarrow> epdaS.derivation G2 d2\"\n  apply(simp add: F_DPDA_RNE__relation_step_simulation__RL_def)\n  apply(case_tac \"edge_trg e1\")\n   apply(rename_tac q)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"edge_src e1\")\n    apply(rename_tac q qa)(*strict*)\n    apply(clarsimp)\n    apply(rule epdaS.der2_is_derivation)\n    apply(simp add: epdaS_step_relation_def F_DPDA_RNE__conf__RL_def F_DPDA_RNE__edge__RL_def)\n    apply(clarsimp)\n    apply(rename_tac q qa w)(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RNE_def)\n    apply(clarsimp)\n    apply(erule disjE)\n     apply(rename_tac q qa w)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac q qa w x)(*strict*)\n     apply(simp add: F_DPDA_RNE__edge_then_def)\n     apply(erule disjE)\n      apply(rename_tac q qa w x)(*strict*)\n      apply(simp add: F_DPDA_RNE__edge_then_1_def)\n     apply(rename_tac q qa w x)(*strict*)\n     apply(simp add: F_DPDA_RNE__edge_then_2_def)\n    apply(rename_tac q qa w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q qa w x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_else_def)\n    apply(simp add: FB_neutral_edge_def)\n    apply(case_tac x)\n    apply(rename_tac q qa w x edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n    apply(force)\n   apply(rename_tac q epda_step_label_ext)(*strict*)\n   apply(clarsimp)\n   apply(rule epdaS.der1_is_derivation)\n  apply(rename_tac epda_step_label_ext)(*strict*)\n  apply(clarsimp)\n  apply(rule epdaS.der2_is_derivation)\n  apply(rename_tac e)\n  apply(rename_tac e)(*strict*)\n  apply(simp add: epdaS_step_relation_def F_DPDA_RNE__conf__RL_def)\n  apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n  apply(clarsimp)\n  apply(rename_tac e w)(*strict*)\n  apply(simp add: F_DPDA_RNE_def)\n  apply(clarsimp)\n  apply(erule disjE)\n   apply(rename_tac e w)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac e w x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_else_def)\n  apply(rename_tac e w)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac e w x)(*strict*)\n  apply(simp add: F_DPDA_RNE__edge_then_def)\n  apply(erule disjE)\n   apply(rename_tac e w x)(*strict*)\n   prefer 2\n   apply(simp add: F_DPDA_RNE__edge_then_2_def)\n  apply(rename_tac e w x)(*strict*)\n  apply(simp add: F_DPDA_RNE__edge_then_1_def)\n  apply(clarsimp)\n  apply(rename_tac e w)(*strict*)\n  apply(simp add: FB_neutral_edge_def)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimRL_step_relation_step_simulation: \"\n  \\<forall>G1 G2. F_DPDA_RNE__relation_structure__RL G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_DPDA_RNE__relation_configuration__RL G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<exists>d2. epdaS.derivation G2 d2 \\<and> epdaS.belongs G2 d2 \\<and> the (get_configuration (d2 0)) = c2 \\<and> F_DPDA_RNE__relation_step_simulation__RL G1 G2 c1 e1 c1' c2 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_DPDA_RNE__relation_configuration__RL G1 G2 c1' (the (get_configuration (d2 n))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_step_simulation__RL_def)\n  apply(case_tac \"edge_trg e1\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"edge_src e1\")\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(clarsimp)\n    apply(rule context_conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(rule F_DPDA_RNE__relation_step_simulation__RL_maps_to_derivation)\n        apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n        apply(force)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n       prefer 2\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(simp add: F_DPDA_RNE__relation_step_simulation__RL_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(rule epdaS.der2_belongs_prime)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n       apply (metis epdaS_epdaS_RNoOp_StateSimLR.AX_TSstructure_relation_TSstructure1_belongs F_DPDA_RNE__relation_structure__LR_def F_DPDA_RNE__relation_structure__RL_def)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(simp add: F_DPDA_RNE__relation_configuration__RL_def)\n     apply(rule F_DPDA_RNE__conf__RL_preserves_configurations)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(rule_tac\n      A=\"epdaS.get_accessible_configurations G1\"\n      in set_mp)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      apply(rule epdaS.get_accessible_configurations_are_configurations)\n      apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n      apply(rule F_DPDA_RNE__preserves_epda)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      apply(rule F_FRESH_is_fresh)\n      apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply (metis)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(simp add: get_configuration_def der2_def)\n     apply(simp add: F_DPDA_RNE__relation_configuration__RL_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(rule der2_maximum_of_domain)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(simp (no_asm) add: der2_def get_configuration_def)\n    apply(simp add: F_DPDA_RNE__relation_configuration__RL_def)\n    apply(rule_tac\n      ?e1.0=\"e1\"\n      in epdaS.der2_preserves_get_accessible_configurations)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n      apply(rule F_DPDA_RNE__preserves_epda)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      apply(rule F_FRESH_is_fresh)\n      apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(rule epdaS.der2_is_derivation)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n   apply(clarsimp)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n    apply(rule epdaS.der1_is_derivation)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n    apply(rule epdaS.der1_belongs)\n    apply(rule F_DPDA_RNE__conf__RL_preserves_configurations)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n     apply(simp add: F_DPDA_RNE__relation_configuration__RL_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_configuration__RL_def)\n    apply(rule_tac\n      A=\"epdaS.get_accessible_configurations G1\"\n      in set_mp)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n     apply(rule epdaS.get_accessible_configurations_are_configurations)\n     apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n     apply(rule F_DPDA_RNE__preserves_epda)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n     apply(rule F_FRESH_is_fresh)\n     apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n    apply(simp add: der1_def get_configuration_def)\n    apply(simp add: F_DPDA_RNE__relation_configuration__RL_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n   apply(rule_tac\n      x=\"0\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n    apply(rule der1_maximum_of_domain)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n   apply(simp add: der1_def get_configuration_def)\n   apply(simp add: F_DPDA_RNE__relation_configuration__RL_def)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n    apply(rule_tac\n      ?e1.0=\"e1\"\n      in epdaS.der2_preserves_get_accessible_configurations)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n      apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n      apply(rule F_DPDA_RNE__preserves_epda)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n      apply(rule F_FRESH_is_fresh)\n      apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n    apply(rule epdaS.der2_is_derivation)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n   apply(simp add: F_DPDA_RNE__conf__RL_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' q epda_step_label_ext)(*strict*)\n   apply(simp add: epdaS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' q epda_step_label_ext w)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 e1 c1' q epda_step_label_ext w)(*strict*)\n   apply(simp add: F_DPDA_RNE_def epda_step_labels_def)\n   apply(clarsimp)\n   apply(erule disjE)\n    apply(rename_tac G2 c1 e1 c1' q epda_step_label_ext w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G2 c1 e1 c1' q epda_step_label_ext w x)(*strict*)\n    apply(rename_tac G2 c1 e1 c1' q epda_step_label_exta w x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_def)\n    apply(erule disjE)\n     apply(rename_tac G2 c1 e1 c1' q epda_step_label_exta w x)(*strict*)\n     prefer 2\n     apply(simp add: F_DPDA_RNE__edge_then_2_def)\n     apply(simp add: option_to_list_def)\n    apply(rename_tac G2 c1 e1 c1' q epda_step_label_exta w x)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G2 c1 c1' q epda_step_label_exta w x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_1_def)\n   apply(rename_tac G2 c1 e1 c1' q epda_step_label_ext w)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 c1' q epda_step_label_ext w x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_else_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n  apply(clarsimp)\n  apply(rule context_conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n   apply(rule F_DPDA_RNE__relation_step_simulation__RL_maps_to_derivation)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_step_simulation__RL_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n   apply(rule epdaS.der2_belongs_prime)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n     apply (metis epdaS_epdaS_RNoOp_StateSimLR.AX_TSstructure_relation_TSstructure1_belongs F_DPDA_RNE__relation_structure__LR_def F_DPDA_RNE__relation_structure__RL_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_configuration__RL_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext)(*strict*)\n   apply(rule F_DPDA_RNE__conf__RL_preserves_configurations)\n     apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext)(*strict*)\n   apply(rule_tac\n      A=\"epdaS.get_accessible_configurations G1\"\n      in set_mp)\n    apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext)(*strict*)\n    apply(rule epdaS.get_accessible_configurations_are_configurations)\n    apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n    apply(rule F_DPDA_RNE__preserves_epda)\n     apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext)(*strict*)\n    apply(rule F_FRESH_is_fresh)\n    apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n   apply(simp add: get_configuration_def der2_def)\n   apply(simp add: F_DPDA_RNE__relation_configuration__RL_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n  apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n   apply(rule der2_maximum_of_domain)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n  apply(simp (no_asm) add: der2_def get_configuration_def)\n  apply(simp add: F_DPDA_RNE__relation_configuration__RL_def)\n  apply(rule_tac\n      ?e1.0=\"e1\"\n      in epdaS.der2_preserves_get_accessible_configurations)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n    apply(rule F_DPDA_RNE__preserves_epda)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n    apply(rule F_FRESH_is_fresh)\n    apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n  apply(rule epdaS.der2_is_derivation)\n  apply(force)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axioms: \"\n  ATS_Simulation_Configuration_Weak_axioms valid_epda epdaS_initial_configurations epda_step_labels epdaS_step_relation valid_epda epdaS_configurations epdaS_initial_configurations epda_step_labels epdaS_step_relation F_DPDA_RNE__relation_configuration__RL F_DPDA_RNE__relation_initial_configuration__RL F_DPDA_RNE__relation_structure__RL F_DPDA_RNE__relation_initial_simulation__RL F_DPDA_RNE__relation_step_simulation__RL\"\n  apply(simp add: ATS_Simulation_Configuration_Weak_axioms_def epdaS_epdaS_RNoOp_StateSimRL_inst_relation_initial_simulation epdaS_epdaS_RNoOp_StateSimRL_step_relation_step_simulation\n      epdaS_epdaS_RNoOp_StateSimRL_inst_AX_TSstructure_relation_TSstructure1_belongs\n      epdaS_epdaS_RNoOp_StateSimRL_inst_AX_TSstructure_relation_TSstructure2_belongs)\n  done\n\ninterpretation \"epdaS_epdaS_RNoOp_StateSimRL\" : ATS_Simulation_Configuration_Weak\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaS_configurations\"\n  (* initial_configurations1 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaS_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaS_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_DPDA_RNE__relation_configuration__RL\"\n  (* relation_initial_configuration *)\n  \"F_DPDA_RNE__relation_initial_configuration__RL\"\n  (* relation_effect *)\n  \"F_DPDA_RNE__relation_effect__RL\"\n  (* relation_TSstructure *)\n  \"F_DPDA_RNE__relation_structure__RL\"\n  (* relation_initial_simulation *)\n  \"F_DPDA_RNE__relation_initial_simulation__RL\"\n  (* relation_step_simulation *)\n  \"F_DPDA_RNE__relation_step_simulation__RL\"\n  apply(simp add: LOCALE_DEFS epda_interpretations)\n  apply(simp add: epdaS_epdaS_RNoOp_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axioms)\n  done\n\nlemma F_DPDA_RNE__conf__RL_preserves_marking_configurations: \"\n  F_DPDA_RNE__relation_structure__RL G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS_marking_configurations G1\n  \\<Longrightarrow> c1 \\<in> epdaS.get_accessible_configurations G1\n  \\<Longrightarrow> F_DPDA_RNE__conf__RL c1 \\<in> epdaS_marking_configurations G2\"\n  apply(simp add: epdaS_marking_configurations_def)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RNE__conf__RL_def F_DPDA_RNE_def)\n   apply(case_tac \"epdaS_conf_state c1\")\n    apply(rename_tac q)(*strict*)\n    apply(force)\n   apply(rename_tac epda_step_label_ext)(*strict*)\n   apply(force)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RNE__conf__RL_def F_DPDA_RNE_def)\n   apply(case_tac \"epdaS_conf_state c1\")\n    apply(rename_tac q)(*strict*)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RNE__conf__RL_def F_DPDA_RNE_def)\n    apply(clarsimp)\n   apply(rename_tac epda_step_label_ext)(*strict*)\n   apply(case_tac \"epdaS_conf_state c1\")\n    apply(rename_tac epda_step_label_ext q)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac epda_step_label_ext epda_step_label_exta)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac epda_step_label_ext)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RNE__conf__RL_def F_DPDA_RNE_def)\n   apply(clarsimp)\n  apply(rule F_DPDA_RNE__conf__RL_preserves_configurations)\n    apply(force)\n   apply(force)\n  apply(force)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimRL_inst_relation_step_simulation_marking_condition: \"\n  \\<forall>G1 G2. F_DPDA_RNE__relation_structure__RL G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_DPDA_RNE__relation_configuration__RL G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<forall>d2. F_DPDA_RNE__relation_step_simulation__RL G1 G2 c1 e1 c1' c2 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_DPDA_RNE__relation_initial_configuration__RL G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der2 c1 e1 c1') deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> epdaS_marking_condition G1 (derivation_append deri1 (der2 c1 e1 c1') deri1n) \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_DPDA_RNE__relation_configuration__RL F_DPDA_RNE__relation_initial_simulation__RL F_DPDA_RNE__relation_step_simulation__RL G1 G2 (derivation_append deri1 (der2 c1 e1 c1') deri1n) (Suc deri1n) (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> epdaS_marking_condition G2 (derivation_append deri2 d2 deri2n))))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: epdaS_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(case_tac \"i\\<le>deri1n\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(subgoal_tac \"deri1 i = Some (pair e c)\")\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n    prefer 2\n    apply(simp add: derivation_append_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(thin_tac \"derivation_append deri1 (der2 c1 e1 c1') deri1n i = Some (pair e c)\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(simp add: epdaS_epdaS_RNoOp_StateSimRL.simulating_derivation_def)\n   apply(clarsimp)\n   apply(simp add: epdaS_epdaS_RNoOp_StateSimRL.simulating_derivation_DEF_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"i\"\n      in allE)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c y)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_configuration__RL_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c y)(*strict*)\n   apply(case_tac y)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c y option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c option b)(*strict*)\n   apply(rename_tac e c)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(rule_tac\n      x=\"f i\"\n      in exI)\n   apply(rule_tac\n      x=\"e\"\n      in exI)\n   apply(rule_tac\n      x=\"c\"\n      in exI)\n   apply(clarsimp)\n   apply(rule_tac\n      t=\"c\"\n      and s=\"F_DPDA_RNE__conf__RL ca\"\n      in ssubst)\n    apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n    apply(simp add: F_DPDA_RNE__conf__RL_def derivation_append_def get_configuration_def)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(rule F_DPDA_RNE__conf__RL_preserves_marking_configurations)\n     apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(rule_tac\n      t=\"ca\"\n      and s=\"the (get_configuration (derivation_append deri1 (der2 c1 e1 c1') deri1n i))\"\n      in ssubst)\n    apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(simp add: get_configuration_def derivation_append_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(subgoal_tac \"i=Suc deri1n\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e c)(*strict*)\n   apply(subgoal_tac \"c=c1'\")\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e c)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e)(*strict*)\n    apply(simp add: epdaS_epdaS_RNoOp_StateSimRL.simulating_derivation_def)\n    apply(simp add: epdaS_epdaS_RNoOp_StateSimRL.simulating_derivation_DEF_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"Suc deri1n\"\n      in allE)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e y)(*strict*)\n    apply(rule_tac\n      x=\"deri2n+n\"\n      in exI)\n    apply(case_tac y)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e y option b)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e option b)(*strict*)\n    apply(rename_tac e c)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n    apply(rule_tac\n      t=\"c\"\n      and s=\"F_DPDA_RNE__conf__RL c1'\"\n      in ssubst)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n     apply(simp add: F_DPDA_RNE__relation_configuration__RL_def derivation_append_def get_configuration_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n    apply(rule F_DPDA_RNE__conf__RL_preserves_marking_configurations)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n    apply(simp add: epdaS.get_accessible_configurations_def)\n    apply(rule_tac\n      x=\"derivation_append deri1 (der2 c1 e1 c1') deri1n \"\n      in exI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n     apply(rule epdaS.derivation_append_preserves_derivation_initial)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n       apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n       apply (rule F_DPDA_RNE__preserves_epda)\n        apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n        apply(force)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n       apply(rule F_FRESH_is_fresh)\n       apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n     apply(rule epdaS.derivation_append_preserves_derivation)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n       apply (metis epdaS.derivation_initial_is_derivation)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n      apply(rule epdaS.der2_is_derivation)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n     apply(simp add: derivation_append_fit_def)\n     apply(case_tac \"deri1 deri1n\")\n      apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c a)(*strict*)\n     apply(clarsimp)\n     apply(case_tac a)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c a option b)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c option b)(*strict*)\n     apply(simp add: der2_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f ea e c)(*strict*)\n    apply(rule_tac\n      x=\"Suc deri1n\"\n      in exI)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f e c)(*strict*)\n   apply(simp add: get_configuration_def derivation_append_def der2_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(case_tac \"i>Suc deri1n\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(clarsimp)\n  apply(simp add: derivation_append_def der2_def)\n  apply(case_tac \"i-deri1n\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c nat)(*strict*)\n  apply(clarsimp)\n  apply(case_tac nat)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c nat)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i c)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f i e c nat nata)(*strict*)\n  apply(clarsimp)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimRL_inst_relation_initial_simulation_marking_condition: \"\n  \\<forall>G1 G2. F_DPDA_RNE__relation_structure__RL G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<forall>d2. F_DPDA_RNE__relation_initial_simulation__RL G1 G2 c1 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_DPDA_RNE__relation_initial_configuration__RL G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der1 c1) deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> epdaS_marking_condition G1 (derivation_append deri1 (der1 c1) deri1n) \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_DPDA_RNE__relation_configuration__RL F_DPDA_RNE__relation_initial_simulation__RL F_DPDA_RNE__relation_step_simulation__RL G1 G2 (derivation_append deri1 (der1 c1) deri1n) deri1n (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> epdaS_marking_condition G2 (derivation_append deri2 d2 deri2n))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: epdaS_marking_condition_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(case_tac \"i\\<le>deri1n\")\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(subgoal_tac \"deri1 i = Some (pair e c)\")\n    apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n    prefer 2\n    apply(simp add: derivation_append_def)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(simp add: epdaS_epdaS_RNoOp_StateSimRL.simulating_derivation_def)\n   apply(clarsimp)\n   apply(simp add: epdaS_epdaS_RNoOp_StateSimRL.simulating_derivation_DEF_def)\n   apply(clarsimp)\n   apply(erule_tac\n      x=\"i\"\n      in allE)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c y)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_configuration__RL_def)\n   apply(clarsimp)\n   apply(case_tac y)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c y option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c option b)(*strict*)\n   apply(rename_tac e c)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(rule_tac\n      x=\"f i\"\n      in exI)\n   apply(rule_tac\n      x=\"e\"\n      in exI)\n   apply(rule_tac\n      x=\"c\"\n      in exI)\n   apply(clarsimp)\n   apply(rule_tac\n      t=\"c\"\n      and s=\"F_DPDA_RNE__conf__RL ca\"\n      in ssubst)\n    apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n    apply(simp add: F_DPDA_RNE__conf__RL_def derivation_append_def get_configuration_def)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(rule F_DPDA_RNE__conf__RL_preserves_marking_configurations)\n     apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i ea ca e c)(*strict*)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(subgoal_tac \"i=deri1n\")\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(case_tac \"i>deri1n\")\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f i e c)(*strict*)\n  apply(clarsimp)\n  apply(simp add: derivation_append_def der1_def)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimLR_inst_ATS_Simulation_Configuration_WeakRL_COND_axioms: \"\n  ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms epdaS_initial_configurations epda_step_labels epdaS_step_relation epdaS_marking_condition epdaS_initial_configurations epdaS_step_relation epdaS_marking_condition F_DPDA_RNE__relation_configuration__RL F_DPDA_RNE__relation_initial_configuration__RL F_DPDA_RNE__relation_structure__RL F_DPDA_RNE__relation_initial_simulation__RL F_DPDA_RNE__relation_step_simulation__RL\"\n  apply(simp add: ATS_Simulation_Configuration_WeakLR_Marking_Condition_axioms_def)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(rule epdaS_epdaS_RNoOp_StateSimRL.relation_step_simulation_preservation_PROVE2)\n    apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n    prefer 2\n    apply(rename_tac G1 G2 d1' d2')(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(thin_tac \"epdaS_epdaS_RNoOp_StateSimRL.relation_step_simulation_preservation G1 G2 d1' d2'\")\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(metis epdaS_epdaS_RNoOp_StateSimRL_inst_relation_step_simulation_marking_condition)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 d1' d2')(*strict*)\n  apply(rule epdaS_epdaS_RNoOp_StateSimRL.relation_initial_simulation_preservation_PROVE2)\n   apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   prefer 2\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(thin_tac \"epdaS_epdaS_RNoOp_StateSimRL.relation_initial_simulation_preservation G1 G2 d1' d2'\")\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(metis epdaS_epdaS_RNoOp_StateSimRL_inst_relation_initial_simulation_marking_condition)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimRL_inst_relation_step_simulation_marked_effect: \"\n  (\\<forall>G1 G2. F_DPDA_RNE__relation_structure__RL G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_DPDA_RNE__relation_configuration__RL G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<forall>d2. F_DPDA_RNE__relation_step_simulation__RL G1 G2 c1 e1 c1' c2 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_DPDA_RNE__relation_initial_configuration__RL G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der2 c1 e1 c1') deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_DPDA_RNE__relation_configuration__RL F_DPDA_RNE__relation_initial_simulation__RL F_DPDA_RNE__relation_step_simulation__RL G1 G2 (derivation_append deri1 (der2 c1 e1 c1') deri1n) (Suc deri1n) (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> left_total_on (F_DPDA_RNE__relation_effect__RL G1 G2) (epdaS_marked_effect G1 (derivation_append deri1 (der2 c1 e1 c1') deri1n)) (epdaS_marked_effect G2 (derivation_append deri2 d2 deri2n))))))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(rule_tac\n      x=\"a\"\n      in bexI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_effect__RL_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(simp add: epdaS_marked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri2 0 = Some (pair None c)\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c ca)(*strict*)\n   apply(simp add: derivation_append_def F_DPDA_RNE__relation_initial_configuration__RL_def)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n   apply(simp add: F_DPDA_RNE__conf__RL_def)\n   apply(case_tac \"epdaS_conf_state c\")\n    apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c ca q)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c ca epda_step_label_ext)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(rule_tac\n      M=\"G2\"\n      in epdaS.some_position_has_details_at_0)\n  apply (metis epdaS.derivation_initial_is_derivation)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimRL_inst_relation_initial_simulation_marked_effect: \"\n  (\\<forall>G1 G2. F_DPDA_RNE__relation_structure__RL G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<forall>d2. F_DPDA_RNE__relation_initial_simulation__RL G1 G2 c1 d2 \\<longrightarrow> (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow> (\\<forall>deri1. epdaS.derivation_initial G1 deri1 \\<longrightarrow> (\\<forall>deri1n. maximum_of_domain deri1 deri1n \\<longrightarrow> (\\<forall>deri2. epdaS.derivation_initial G2 deri2 \\<longrightarrow> (\\<forall>deri2n. maximum_of_domain deri2 deri2n \\<longrightarrow> F_DPDA_RNE__relation_initial_configuration__RL G1 G2 (the (get_configuration (deri1 0))) (the (get_configuration (deri2 0))) \\<longrightarrow> derivation_append_fit deri1 (der1 c1) deri1n \\<longrightarrow> derivation_append_fit deri2 d2 deri2n \\<longrightarrow> Ex (ATS_Simulation_Configuration_Weak.simulating_derivation F_DPDA_RNE__relation_configuration__RL F_DPDA_RNE__relation_initial_simulation__RL F_DPDA_RNE__relation_step_simulation__RL G1 G2 (derivation_append deri1 (der1 c1) deri1n) deri1n (derivation_append deri2 d2 deri2n) (deri2n + n)) \\<longrightarrow> left_total_on (F_DPDA_RNE__relation_effect__RL G1 G2) (epdaS_marked_effect G1 (derivation_append deri1 (der1 c1) deri1n)) (epdaS_marked_effect G2 (derivation_append deri2 d2 deri2n))))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n x)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(rule_tac\n      x=\"a\"\n      in bexI)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_effect__RL_def)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f a)(*strict*)\n  apply(simp add: epdaS_marked_effect_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. deri2 0 = Some (pair None c)\")\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c ca)(*strict*)\n   apply(simp add: derivation_append_def F_DPDA_RNE__relation_initial_configuration__RL_def)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n   apply(simp add: F_DPDA_RNE__conf__RL_def)\n   apply(case_tac \"epdaS_conf_state c\")\n    apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c ca q)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c ca epda_step_label_ext)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f c)(*strict*)\n  apply(rule_tac\n      M=\"G2\"\n      in epdaS.some_position_has_details_at_0)\n  apply (metis epdaS.derivation_initial_is_derivation)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimLR_inst_ATS_Simulation_Configuration_WeakRL_ACCEPT_axioms: \"\n  ATS_Simulation_Configuration_Weak_Marked_Effect_axioms epdaS_initial_configurations epda_step_labels epdaS_step_relation epdaS_marked_effect epdaS_initial_configurations epdaS_step_relation epdaS_marked_effect F_DPDA_RNE__relation_configuration__RL F_DPDA_RNE__relation_initial_configuration__RL F_DPDA_RNE__relation_effect__RL F_DPDA_RNE__relation_structure__RL F_DPDA_RNE__relation_initial_simulation__RL F_DPDA_RNE__relation_step_simulation__RL\"\n  apply(simp add: ATS_Simulation_Configuration_Weak_Marked_Effect_axioms_def)\n  apply(rule conjI)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(rule epdaS_epdaS_RNoOp_StateSimRL.relation_step_simulation_preservation_PROVE2)\n    apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n    prefer 2\n    apply(rename_tac G1 G2 d1' d2')(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 d1' d2' c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(thin_tac \"epdaS_epdaS_RNoOp_StateSimRL.relation_step_simulation_preservation G1 G2 d1' d2'\")\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   apply(metis epdaS_epdaS_RNoOp_StateSimRL_inst_relation_step_simulation_marked_effect)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 d1' d2')(*strict*)\n  apply(rule epdaS_epdaS_RNoOp_StateSimRL.relation_initial_simulation_preservation_PROVE2)\n   apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n   prefer 2\n   apply(rename_tac G1 G2 d1' d2')(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 d1' d2' c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(thin_tac \"epdaS_epdaS_RNoOp_StateSimRL.relation_initial_simulation_preservation G1 G2 d1' d2'\")\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 d2 n deri1 deri1n deri2 deri2n f)(*strict*)\n  apply(metis epdaS_epdaS_RNoOp_StateSimRL_inst_relation_initial_simulation_marked_effect)\n  done\n\ninterpretation \"epdaS_epdaS_RNoOp_StateSimRL\" : ATS_Simulation_Configuration_Weak_Marked_Effect\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaS_configurations\"\n  (* initial_configurations1 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaS_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaS_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_DPDA_RNE__relation_configuration__RL\"\n  (* relation_initial_configuration *)\n  \"F_DPDA_RNE__relation_initial_configuration__RL\"\n  (* relation_effect *)\n  \"F_DPDA_RNE__relation_effect__RL\"\n  (* relation_TSstructure *)\n  \"F_DPDA_RNE__relation_structure__RL\"\n  (* relation_initial_simulation *)\n  \"F_DPDA_RNE__relation_initial_simulation__RL\"\n  (* relation_step_simulation *)\n  \"F_DPDA_RNE__relation_step_simulation__RL\"\n  apply(simp add: LOCALE_DEFS epda_interpretations)\n  apply(simp add: epdaS_epdaS_RNoOp_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axioms epdaS_epdaS_RNoOp_StateSimLR_inst_ATS_Simulation_Configuration_WeakRL_COND_axioms epdaS_epdaS_RNoOp_StateSimLR_inst_ATS_Simulation_Configuration_WeakRL_ACCEPT_axioms)\n  done\n\nlemma F_DPDA_RNE__preserves_lang2: \"\n  valid_dpda (G :: ('state, 'event, 'stack DT_symbol) epda)\n  \\<Longrightarrow> epdaS.marked_language G \\<supseteq> epdaS.marked_language (F_DPDA_RNE G (F_FRESH (epda_gamma G)))\"\n  apply(rule_tac\n      t=\"epdaS.marked_language G\"\n      and s=\"epdaS.finite_marked_language G\"\n      in subst)\n   apply(rule epdaS.AX_marked_language_finite)\n   apply(simp add: valid_dpda_def valid_pda_def)\n  apply(rule_tac\n      t=\"epdaS.marked_language (F_DPDA_RNE G (F_FRESH (epda_gamma G)))\"\n      and s=\"epdaS.finite_marked_language (F_DPDA_RNE G (F_FRESH (epda_gamma G)))\"\n      in ssubst)\n   apply(rule sym)\n   apply(rule epdaS.AX_marked_language_finite)\n   apply (rule F_DPDA_RNE__preserves_epda)\n    apply(force)\n   apply(rule F_FRESH_is_fresh)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(subgoal_tac \"left_total_on (F_DPDA_RNE__relation_effect__RL SSG1 SSG2) (epdaS.finite_marked_language SSG1) (epdaS.finite_marked_language SSG2)\" for SSG1 SSG2)\n   prefer 2\n   apply(rule_tac\n      ?G2.0=\"G\"\n      in epdaS_epdaS_RNoOp_StateSimRL.ATS_Simulation_Configuration_Weak_Marked_Effect_sound)\n   apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_effect__RL_def)\n  done\n\ntheorem F_DPDA_RNE__preserves_lang: \"\n  valid_dpda G\n  \\<Longrightarrow> epdaS.marked_language G = epdaS.marked_language (F_DPDA_RNE G (F_FRESH (epda_gamma G)))\"\n  apply(rule order_antisym)\n   apply (metis F_DPDA_RNE__preserves_lang1)\n  apply (metis F_DPDA_RNE__preserves_lang2)\n  done\n\nlemma F_DPDA_RNE__conf__RL_reflects_steps2: \"\n  x \\<in> epda_delta G\n  \\<Longrightarrow> epdaS_step_relation (F_DPDA_RNE G PB) c (F_DPDA_RNE__edge_else x) c1\n  \\<Longrightarrow> epdaS_step_relation G (F_DPDA_RNE__conf__RL c) x (F_DPDA_RNE__conf__RL c1)\"\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac w)(*strict*)\n  apply(simp add: F_DPDA_RNE__conf__RL_def F_DPDA_RNE__edge_else_def)\n  done\n\nlemma F_DPDA_RNE__conf__RL_reflects_steps1: \"\n  x \\<in> epda_delta G\n  \\<Longrightarrow> epdaS_step_relation (F_DPDA_RNE G PB) c (F_DPDA_RNE__edge_then_1 x PB) c1\n  \\<Longrightarrow> epdaS_step_relation G (F_DPDA_RNE__conf__RL c) x (F_DPDA_RNE__conf__RL c1)\"\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac w)(*strict*)\n  apply(simp add: F_DPDA_RNE__conf__RL_def F_DPDA_RNE__edge_then_1_def)\n  apply(simp add: F_DPDA_RNE_def)\n  apply(clarsimp)\n  apply(erule disjE)\n   apply(rename_tac w)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac w xa)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_def)\n   apply(erule disjE)\n    apply(rename_tac w xa)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_1_def)\n    apply(clarsimp)\n    apply(rename_tac w)(*strict*)\n    apply(simp add: FB_neutral_edge_def)\n   apply(rename_tac w xa)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_2_def)\n  apply(rename_tac w)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac w xa)(*strict*)\n  apply(simp add: FB_neutral_edge_def F_DPDA_RNE__edge_else_def)\n  done\n\nlemma PseudoBox_is_translated_backwards: \"\n  valid_dpda G2\n  \\<Longrightarrow> e1 \\<in> epda_step_labels (F_DPDA_RNE G2 (F_FRESH (epda_gamma G2)))\n  \\<Longrightarrow> c1' \\<in> epdaS_configurations (F_DPDA_RNE G2 (F_FRESH (epda_gamma G2)))\n  \\<Longrightarrow> epdaS_step_relation (F_DPDA_RNE G2 (F_FRESH (epda_gamma G2))) c1' e1 c1\n  \\<Longrightarrow> pseudo_box_top G2 c1\n  \\<Longrightarrow> pseudo_box_top G2 c1'\"\n  apply(simp add: pseudo_box_top_def)\n  apply(case_tac \"epdaS_conf_state c1'\")\n   apply(rename_tac q)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"epdaS_conf_state c1\")\n    apply(rename_tac q qa)(*strict*)\n    apply(clarsimp)\n    apply(simp add: epdaS_step_relation_def)\n    apply(clarsimp)\n    apply(rename_tac q qa w)(*strict*)\n    apply(simp add: epda_step_labels_def F_DPDA_RNE_def)\n    apply(clarsimp)\n    apply(erule disjE)\n     apply(rename_tac q qa w)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac q qa w x)(*strict*)\n     apply(simp add: F_DPDA_RNE__edge_then_def)\n     apply(simp add: F_DPDA_RNE__edge_then_2_def F_DPDA_RNE__edge_then_1_def)\n     apply(erule disjE)\n      apply(rename_tac q qa w x)(*strict*)\n      apply(force)\n     apply(rename_tac q qa w x)(*strict*)\n     apply(force)\n    apply(rename_tac q qa w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q qa w x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_else_def)\n    apply(clarsimp)\n    apply(rename_tac w x)(*strict*)\n    apply(subgoal_tac \"F_FRESH (epda_gamma G2) \\<in> epda_gamma G2\")\n     apply(rename_tac w x)(*strict*)\n     apply(subgoal_tac \"F_FRESH (epda_gamma G2) \\<notin> epda_gamma G2\")\n      apply(rename_tac w x)(*strict*)\n      apply(force)\n     apply(rename_tac w x)(*strict*)\n     apply(rule F_FRESH_is_fresh)\n     apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n    apply(rename_tac w x)(*strict*)\n    apply(rule_tac\n      A=\"set (edge_pop x)\"\n      in set_mp)\n     apply(rename_tac w x)(*strict*)\n     apply(rule valid_epda_pop_in_gamma)\n      apply(rename_tac w x)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n     apply(rename_tac w x)(*strict*)\n     apply(force)\n    apply(rename_tac w x)(*strict*)\n    apply(force)\n   apply(rename_tac q epda_step_label_ext)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac q epda_step_label_ext w)(*strict*)\n   apply(simp add: epdaS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac q epda_step_label_ext w wa)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_else_def F_DPDA_RNE_def F_DPDA_RNE__edge_then_def F_DPDA_RNE__edge_then_2_def F_DPDA_RNE__edge_then_1_def epda_step_labels_def)\n   apply(rename_tac q epda_step_label_exta w wa)(*strict*)\n   apply(subgoal_tac \"\\<exists>x\\<in> epda_delta G2 \\<inter> Collect FB_neutral_edge. e1 = \\<lparr>edge_src = cons_state_or_edge_old (edge_src x), edge_event = None, edge_pop = edge_pop x, edge_push = F_FRESH (epda_gamma G2) # edge_pop x, edge_trg = cons_state_or_edge_new x\\<rparr> \\<or> e1 = \\<lparr>edge_src = cons_state_or_edge_new x, edge_event = None, edge_pop = [F_FRESH (epda_gamma G2)], edge_push = [], edge_trg = cons_state_or_edge_old (edge_trg x)\\<rparr>\")\n    prefer 2\n    apply(force)\n   apply(rename_tac q epda_step_label_exta w wa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac q epda_step_label_exta w wa x)(*strict*)\n   apply(erule_tac\n      P=\"F_FRESH (epda_gamma G2) \\<in> set (edge_pop e1)\"\n      in disjE)\n    apply(rename_tac q epda_step_label_exta w wa x)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac q epda_step_label_exta w wa x)(*strict*)\n     apply(clarsimp)\n     apply(force)\n    apply(rename_tac q epda_step_label_exta w wa x)(*strict*)\n    apply(rename_tac q epda_step_label_exta w wa x)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac q epda_step_label_exta w wa x)(*strict*)\n     apply(force)\n    apply(rename_tac q epda_step_label_exta w wa x)(*strict*)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(rename_tac epda_step_label_ext)(*strict*)\n  apply(case_tac \"epdaS_conf_state c1\")\n   apply(rename_tac epda_step_label_ext q)(*strict*)\n   apply(clarsimp)\n   apply(simp add: epdaS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac epda_step_label_ext q w)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_else_def F_DPDA_RNE_def F_DPDA_RNE__edge_then_def F_DPDA_RNE__edge_then_2_def F_DPDA_RNE__edge_then_1_def epda_step_labels_def)\n   apply(rename_tac epda_step_label_exta q w)(*strict*)\n   apply(force)\n  apply(rename_tac epda_step_label_ext epda_step_label_exta)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac epda_step_label_ext epda_step_label_exta w)(*strict*)\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac epda_step_label_ext epda_step_label_exta w wa)(*strict*)\n  apply(simp add: F_DPDA_RNE__edge_else_def F_DPDA_RNE_def F_DPDA_RNE__edge_then_def F_DPDA_RNE__edge_then_2_def F_DPDA_RNE__edge_then_1_def epda_step_labels_def)\n  apply(rename_tac epda_step_label_exta epda_step_label_extaa w wa)(*strict*)\n  apply(force)\n  done\n\nlemma F_DPDA_RNE__conf__RL_preserves_configurations2: \"\n  valid_dpda G2\n  \\<Longrightarrow> c1' \\<in> epdaS_configurations (F_DPDA_RNE G2 (F_FRESH (epda_gamma G2)))\n  \\<Longrightarrow> pseudo_box_top G2 c1'\n  \\<Longrightarrow> F_DPDA_RNE__conf__RL c1' \\<in> epdaS_configurations G2\"\n  apply(simp add: F_DPDA_RNE__conf__RL_def epdaS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac q i s)(*strict*)\n  apply(case_tac q)\n   apply(rename_tac q i s qa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i s qa)(*strict*)\n   apply(simp add: pseudo_box_top_def F_DPDA_RNE_def)\n   apply(erule disjE)\n    apply(rename_tac i s qa)(*strict*)\n    prefer 2\n    apply(clarsimp)\n   apply(rename_tac i s qa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i s x xa)(*strict*)\n   apply(force)\n  apply(rename_tac q i s epda_step_label_ext)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i s epda_step_label_ext)(*strict*)\n  apply(simp add: pseudo_box_top_def F_DPDA_RNE_def)\n  apply(clarsimp)\n  apply(rename_tac i epda_step_label_ext w)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac i epda_step_label_ext w)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac i epda_step_label_ext w)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i w x)(*strict*)\n  apply(subgoal_tac \"valid_epda_step_label G2 x\")\n   apply(rename_tac i w x)(*strict*)\n   apply(simp add: valid_epda_step_label_def)\n   apply(clarsimp)\n   apply(rename_tac i w x xa)(*strict*)\n   apply(force)\n  apply(rename_tac i w x)(*strict*)\n  apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  done\n\nlemma F_DPDA_RNE__preserves_epdaS_step_relation: \"\n  c1' \\<in> epdaS_configurations (F_DPDA_RNE G2 (F_FRESH (epda_gamma G2)))\n  \\<Longrightarrow> epdaS_step_relation (F_DPDA_RNE G2 (F_FRESH (epda_gamma G2))) c1' e1 c1\n  \\<Longrightarrow> valid_dpda G2\n  \\<Longrightarrow> c1 \\<in> epdaS_configurations (F_DPDA_RNE G2 (F_FRESH (epda_gamma G2)))\n  \\<Longrightarrow> pseudo_box_top G2 c1'\n  \\<Longrightarrow> pseudo_box_top G2 c1\n  \\<Longrightarrow> edge_trg e1 = cons_state_or_edge_new e\n  \\<Longrightarrow> epdaS_step_relation G2 (F_DPDA_RNE__conf__RL c1') e (F_DPDA_RNE__conf__RL c1)\"\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac w)(*strict*)\n  apply(simp add: F_DPDA_RNE_def)\n  apply(clarsimp)\n  apply(erule disjE)\n   apply(rename_tac w)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac w x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_def)\n   apply(erule disjE)\n    apply(rename_tac w x)(*strict*)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RNE__edge_then_1_def)\n    apply(clarsimp)\n    apply(rename_tac w)(*strict*)\n    apply(simp add: F_DPDA_RNE__conf__RL_def option_to_list_def pseudo_box_top_def FB_neutral_edge_def)\n   apply(rename_tac w x)(*strict*)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RNE__edge_then_2_def)\n  apply(rename_tac w)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac w x)(*strict*)\n  apply(simp add: F_DPDA_RNE__edge_else_def)\n  done\n\ntheorem F_DPDA_RNE__preserves_is_forward_edge_deterministic_accessible: \"\n  valid_dpda (G :: ('state, 'event, 'stack DT_symbol) epda)\n  \\<Longrightarrow> epdaS.is_forward_edge_deterministic_accessible (F_DPDA_RNE G (F_FRESH (epda_gamma G)))\"\n  apply(simp add: epdaS.is_forward_edge_deterministic_accessible_def)\n  apply(clarsimp)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"edge_src e1 = epdaS_conf_state c\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"edge_src e2 = epdaS_conf_state c\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"prefix (option_to_list (edge_event e1)) (epdaS_conf_scheduler c)\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n   apply(simp add: prefix_def)\n   apply(clarsimp)\n   apply(rename_tac c c1 c2 e1 e2 w wa)(*strict*)\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"prefix (option_to_list (edge_event e2)) (epdaS_conf_scheduler c)\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n   apply(simp add: prefix_def)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"prefix (edge_pop e1) (epdaS_conf_stack c)\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n   apply(simp add: prefix_def)\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"prefix (edge_pop e2) (epdaS_conf_stack c)\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n   apply(simp add: prefix_def)\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"e1 \\<in> epda_delta (F_DPDA_RNE G (F_FRESH (epda_gamma G)))\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"e2 \\<in> epda_delta (F_DPDA_RNE G (F_FRESH (epda_gamma G)))\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"epdaS.is_forward_edge_deterministic_accessible G\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   prefer 2\n   apply(simp add: valid_dpda_def)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(simp add: epdaS.is_forward_edge_deterministic_accessible_def)\n  apply(erule_tac\n      x=\"F_DPDA_RNE__conf__RL c\"\n      in ballE)\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   apply(erule_tac\n      x=\"F_DPDA_RNE__conf__RL c1\"\n      in allE)\n   apply(erule_tac\n      x=\"F_DPDA_RNE__conf__RL c2\"\n      in allE)\n   apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G \\<inter> Collect FB_neutral_edge. e1 \\<in> F_DPDA_RNE__edge_then x (F_FRESH (epda_gamma G))) \\<or> (\\<exists>x\\<in> epda_delta G \\<inter> {e. \\<not> FB_neutral_edge e}. e1 = F_DPDA_RNE__edge_else x)\")\n    apply(rename_tac c c1 c2 e1 e2)(*strict*)\n    prefer 2\n    apply(simp add: F_DPDA_RNE_def)\n    apply(blast)\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G \\<inter> Collect FB_neutral_edge. e2 \\<in> F_DPDA_RNE__edge_then x (F_FRESH (epda_gamma G))) \\<or> (\\<exists>x\\<in> epda_delta G \\<inter> {e. \\<not> FB_neutral_edge e}. e2 = F_DPDA_RNE__edge_else x)\")\n    apply(rename_tac c c1 c2 e1 e2)(*strict*)\n    prefer 2\n    apply(simp add: F_DPDA_RNE_def)\n    apply(blast)\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   apply(erule_tac\n      P=\"\\<exists>x\\<in> epda_delta G \\<inter> Collect FB_neutral_edge. e1 \\<in> F_DPDA_RNE__edge_then x (F_FRESH (epda_gamma G))\"\n      in disjE)\n    apply(rename_tac c c1 c2 e1 e2)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c c1 c2 e1 e2 x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_def)\n    apply(erule_tac\n      P=\"e1 = F_DPDA_RNE__edge_then_1 x (F_FRESH (epda_gamma G))\"\n      in disjE)\n     apply(rename_tac c c1 c2 e1 e2 x)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c c1 c2 e2 x)(*strict*)\n     apply(erule disjE)\n      apply(rename_tac c c1 c2 e2 x)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac c c1 c2 e2 x xa)(*strict*)\n      apply(erule disjE)\n       apply(rename_tac c c1 c2 e2 x xa)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac c c1 c2 x xa)(*strict*)\n       apply(erule_tac\n      x=\"x\"\n      in allE)\n       apply(erule_tac\n      x=\"xa\"\n      in allE)\n       apply(erule impE)\n        apply(rename_tac c c1 c2 x xa)(*strict*)\n        prefer 2\n        apply(force)\n       apply(rename_tac c c1 c2 x xa)(*strict*)\n       apply(rule conjI)\n        apply(rename_tac c c1 c2 x xa)(*strict*)\n        apply(rule F_DPDA_RNE__conf__RL_reflects_steps1)\n         apply(rename_tac c c1 c2 x xa)(*strict*)\n         apply(force)\n        apply(rename_tac c c1 c2 x xa)(*strict*)\n        apply(force)\n       apply(rename_tac c c1 c2 x xa)(*strict*)\n       apply(rule F_DPDA_RNE__conf__RL_reflects_steps1)\n        apply(rename_tac c c1 c2 x xa)(*strict*)\n        apply(force)\n       apply(rename_tac c c1 c2 x xa)(*strict*)\n       apply(force)\n      apply(rename_tac c c1 c2 e2 x xa)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac c c1 c2 x xa)(*strict*)\n      apply(simp add: F_DPDA_RNE__edge_then_1_def F_DPDA_RNE__edge_then_2_def epdaS_step_relation_def)\n     apply(rename_tac c c1 c2 e2 x)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c c1 c2 x xa)(*strict*)\n     apply(erule_tac\n      x=\"x\"\n      in allE)\n     apply(erule_tac\n      x=\"xa\"\n      in allE)\n     apply(erule impE)\n      apply(rename_tac c c1 c2 x xa)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac c c1 c2 x xa)(*strict*)\n     apply(rule conjI)\n      apply(rename_tac c c1 c2 x xa)(*strict*)\n      apply(rule F_DPDA_RNE__conf__RL_reflects_steps1)\n       apply(rename_tac c c1 c2 x xa)(*strict*)\n       apply(force)\n      apply(rename_tac c c1 c2 x xa)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 x xa)(*strict*)\n     apply(rule F_DPDA_RNE__conf__RL_reflects_steps2)\n      apply(rename_tac c c1 c2 x xa)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 x xa)(*strict*)\n     apply(force)\n    apply(rename_tac c c1 c2 e1 e2 x)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c c1 c2 e2 x)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac c c1 c2 e2 x)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c c1 c2 e2 x xa)(*strict*)\n     apply(erule disjE)\n      apply(rename_tac c c1 c2 e2 x xa)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac c c1 c2 x xa)(*strict*)\n      apply(simp add: F_DPDA_RNE__edge_then_1_def F_DPDA_RNE__edge_then_2_def epdaS_step_relation_def)\n     apply(rename_tac c c1 c2 e2 x xa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c c1 c2 x xa)(*strict*)\n     apply(simp add: F_DPDA_RNE__edge_then_1_def F_DPDA_RNE__edge_then_2_def epdaS_step_relation_def)\n    apply(rename_tac c c1 c2 e2 x)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c c1 c2 x xa)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_else_def)\n    apply(simp add: F_DPDA_RNE__edge_then_1_def F_DPDA_RNE__edge_then_2_def epdaS_step_relation_def)\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c c1 c2 e2 x)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac c c1 c2 e2 x)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c c1 c2 e2 x xa)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_def)\n    apply(erule disjE)\n     apply(rename_tac c c1 c2 e2 x xa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c c1 c2 x xa)(*strict*)\n     apply(erule_tac\n      x=\"x\"\n      in allE)\n     apply(erule_tac\n      x=\"xa\"\n      in allE)\n     apply(erule impE)\n      apply(rename_tac c c1 c2 x xa)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac c c1 c2 x xa)(*strict*)\n     apply(rule conjI)\n      apply(rename_tac c c1 c2 x xa)(*strict*)\n      apply(rule F_DPDA_RNE__conf__RL_reflects_steps2)\n       apply(rename_tac c c1 c2 x xa)(*strict*)\n       apply(force)\n      apply(rename_tac c c1 c2 x xa)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 x xa)(*strict*)\n     apply(rule F_DPDA_RNE__conf__RL_reflects_steps1)\n      apply(rename_tac c c1 c2 x xa)(*strict*)\n      apply(force)\n     apply(rename_tac c c1 c2 x xa)(*strict*)\n     apply(force)\n    apply(rename_tac c c1 c2 e2 x xa)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_else_def F_DPDA_RNE__edge_then_1_def F_DPDA_RNE__edge_then_2_def epdaS_step_relation_def)\n   apply(rename_tac c c1 c2 e2 x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c c1 c2 x xa)(*strict*)\n   apply(erule_tac\n      x=\"x\"\n      in allE)\n   apply(erule_tac\n      x=\"xa\"\n      in allE)\n   apply(erule impE)\n    apply(rename_tac c c1 c2 x xa)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac c c1 c2 x xa)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac c c1 c2 x xa)(*strict*)\n    apply(rule F_DPDA_RNE__conf__RL_reflects_steps2)\n     apply(rename_tac c c1 c2 x xa)(*strict*)\n     apply(force)\n    apply(rename_tac c c1 c2 x xa)(*strict*)\n    apply(force)\n   apply(rename_tac c c1 c2 x xa)(*strict*)\n   apply(rule F_DPDA_RNE__conf__RL_reflects_steps2)\n    apply(rename_tac c c1 c2 x xa)(*strict*)\n    apply(force)\n   apply(rename_tac c c1 c2 x xa)(*strict*)\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(subgoal_tac \"F_DPDA_RNE__conf__RL c \\<in> epdaS.get_accessible_configurations G\")\n   apply(rename_tac c c1 c2 e1 e2)(*strict*)\n   apply(force)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(thin_tac \"F_DPDA_RNE__conf__RL c \\<notin> epdaS.get_accessible_configurations G\")\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(rule_tac\n      ?c1.0=\"c\"\n      in epdaS_epdaS_RNoOp_StateSimRL.get_accessible_configurations_transfer)\n      apply(rename_tac c c1 c2 e1 e2)(*strict*)\n      apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n     apply(rename_tac c c1 c2 e1 e2)(*strict*)\n     apply (metis (full_types) F_DPDA_RNE__conf__RL_preserves_configurations2 RNoOp_create_no_pseudo_box_in_the_configuration_prime F_DPDA_RNE__relation_structure__RL_def epdaS.get_accessible_configurations_are_configurations2 epdaS_epdaS_RNoOp_StateSimRL.AX_TSstructure_relation_TSstructure1_belongs)\n    apply(rename_tac c c1 c2 e1 e2)(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_configuration__RL_def)\n    apply(simp add: F_DPDA_RNE__relation_structure__RL_def)\n   apply(rename_tac c c1 c2 e1 e2 cA cB)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_configuration__RL_def)\n  apply(rename_tac c c1 c2 e1 e2)(*strict*)\n  apply(force)\n  done\n\nlemma F_DPDA_RNE__preserves_DPDA: \"\n  valid_dpda G\n  \\<Longrightarrow> valid_dpda (F_DPDA_RNE G (F_FRESH (epda_gamma G)))\"\n  apply(simp (no_asm) add: valid_dpda_def)\n  apply(rule conjI)\n   apply(rule F_DPDA_RNE__preserves_PDA)\n    apply(force)\n   apply(rule F_FRESH_is_fresh)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply (metis F_DPDA_RNE__preserves_is_forward_edge_deterministic_accessible)\n  done\n\ndefinition F_DPDA_RNE__edge__RL2 :: \"\n  (('state, 'event, 'stack) DT_state_or_edge, 'event, 'stack) epda_step_label\n  \\<Rightarrow> ('state, 'event, 'stack) epda_step_label\"\n  where\n    \"F_DPDA_RNE__edge__RL2 e \\<equiv>\n  \\<lparr>edge_src = case edge_src e of cons_state_or_edge_old q \\<Rightarrow> q,\n  edge_event = edge_event e,\n  edge_pop = edge_pop e,\n  edge_push = edge_push e,\n  edge_trg = case edge_trg e of cons_state_or_edge_old q \\<Rightarrow> q\\<rparr>\"\n\ndefinition F_DPDA_RNE__conf_old__LR2 :: \"\n  ('state, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> (('state, 'event, 'stack) DT_state_or_edge, 'event, 'stack) epdaS_conf\"\n  where\n    \"F_DPDA_RNE__conf_old__LR2 c \\<equiv>\n  \\<lparr>epdaS_conf_state = cons_state_or_edge_old (epdaS_conf_state c),\n  epdaS_conf_scheduler = epdaS_conf_scheduler c,\n  epdaS_conf_stack = epdaS_conf_stack c\\<rparr>\"\n\ndefinition F_DPDA_RNE__conf__RL2 :: \"\n  (('state, 'event, 'stack) DT_state_or_edge, 'event, 'stack) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack) epdaS_conf\"\n  where\n    \"F_DPDA_RNE__conf__RL2 c \\<equiv>\n  case epdaS_conf_state c of cons_state_or_edge_old q\n  \\<Rightarrow> \\<lparr>epdaS_conf_state = q,\n    epdaS_conf_scheduler = epdaS_conf_scheduler c,\n    epdaS_conf_stack = epdaS_conf_stack c\\<rparr>\n  | cons_state_or_edge_new e\n  \\<Rightarrow> \\<lparr>epdaS_conf_state = edge_src e,\n    epdaS_conf_scheduler = epdaS_conf_scheduler c,\n    epdaS_conf_stack = drop (Suc 0) (epdaS_conf_stack c)\\<rparr>\"\n\ndefinition F_DPDA_RNE__relation_structure__LR2 :: \"\n  ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_structure__LR2 G1 G2 \\<equiv>\n  valid_dpda G1\n  \\<and> G2 = F_DPDA_RNE G1 (F_FRESH (epda_gamma G1))\"\n\ndefinition F_DPDA_RNE__relation_configuration__LR2 :: \"\n  ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_configuration__LR2 G1 G2 c1 c2 \\<equiv>\n  F_DPDA_RNE__relation_structure__LR2 G1 G2\n  \\<and> c1 \\<in> epdaS.get_accessible_configurations G1\n  \\<and> c2 = F_DPDA_RNE__conf_old__LR2 c1\"\n\ndefinition F_DPDA_RNE__relation_initial_configuration__LR2 :: \"\n  ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_initial_configuration__LR2 G1 G2 c1 c2 \\<equiv>\n  F_DPDA_RNE__relation_structure__LR2 G1 G2\n  \\<and> c1 \\<in> epdaS_initial_configurations G1\n  \\<and> c2 = F_DPDA_RNE__conf_old__LR2 c1\"\n\ndefinition F_DPDA_RNE__relation_effect__LR2 :: \"\n  ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_effect__LR2 G1 G2 w1 w2 \\<equiv>\n  F_DPDA_RNE__relation_structure__LR2 G1 G2\n  \\<and> w1 = w2\"\n\nlemma epdaS_epdaS_RNoOp_StateSimLRX_inst_AX_TSstructure_relation_TSstructure1_belongs: \"\n  (\\<forall>G1. Ex (F_DPDA_RNE__relation_structure__LR2 G1) \\<longrightarrow> valid_epda G1)\"\n  apply(clarsimp)\n  apply(rename_tac G1 x)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_structure__LR2_def)\n  apply(clarsimp)\n  apply(rename_tac G1)(*strict*)\n  apply(simp add: valid_dpda_def valid_pda_def)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimLRX_inst_AX_TSstructure_relation_TSstructure2_belongs: \"\n  (\\<forall>G1 G2. F_DPDA_RNE__relation_structure__LR2 G1 G2 \\<longrightarrow> valid_epda G2)\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_structure__LR2_def)\n  apply(clarsimp)\n  apply(rename_tac G1)(*strict*)\n  apply (rule F_DPDA_RNE__preserves_epda)\n   apply(rename_tac G1)(*strict*)\n   apply(force)\n  apply(rename_tac G1)(*strict*)\n  apply(rule F_FRESH_is_fresh)\n  apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  done\n\ndefinition F_DPDA_RNE__conf_new__LR2 :: \"\n  ('state, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epda_step_label\n  \\<Rightarrow> 'stack DT_symbol\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf\"\n  where\n    \"F_DPDA_RNE__conf_new__LR2 c e PB \\<equiv>\n  \\<lparr>epdaS_conf_state = cons_state_or_edge_new e,\n  epdaS_conf_scheduler = epdaS_conf_scheduler c,\n  epdaS_conf_stack = [PB] @ epdaS_conf_stack c\\<rparr>\"\n\ndefinition F_DPDA_RNE__relation_step_simulation__LR2 :: \"\n  ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epda_step_label\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> ((('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda_step_label, (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_step_simulation__LR2 G1 G2 c1 e c1' c2 d \\<equiv>\n  if FB_neutral_edge e\n  then d = der3\n    (F_DPDA_RNE__conf_old__LR2 c1)\n      (F_DPDA_RNE__edge_then_1 e (F_FRESH (epda_gamma G1)))\n    (F_DPDA_RNE__conf_new__LR2 c1 e (F_FRESH (epda_gamma G1)))\n      (F_DPDA_RNE__edge_then_2 e (F_FRESH (epda_gamma G1)))\n    (F_DPDA_RNE__conf_old__LR2 c1')\n  else d = der2\n    (F_DPDA_RNE__conf_old__LR2 c1)\n      (F_DPDA_RNE__edge_else e)\n    (F_DPDA_RNE__conf_old__LR2 c1')\"\n\ndefinition F_DPDA_RNE__relation_initial_simulation__LR2 :: \"\n  ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> ((('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda_step_label, (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_initial_simulation__LR2 G1 G2 c1 d \\<equiv>\n  d = der1 (F_DPDA_RNE__conf_old__LR2 c1)\"\n\nlemma F_DPDA_RNE__conf_old__LR2_preserves_configurations: \"\n  F_DPDA_RNE__relation_structure__LR2 G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS_configurations G1\n  \\<Longrightarrow> F_DPDA_RNE__conf_old__LR2 c1 \\<in> epdaS_configurations G2\"\n  apply(simp add: epdaS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac q i s)(*strict*)\n  apply(simp add: F_DPDA_RNE__conf_old__LR2_def)\n  apply(simp add: F_DPDA_RNE__relation_structure__LR2_def)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RNE_def)\n  apply(force)\n  done\n\nlemma F_DPDA_RNE__conf_old__LR2_preserves_initial_configurations: \"\n  F_DPDA_RNE__relation_structure__LR2 G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS_initial_configurations G1\n  \\<Longrightarrow> F_DPDA_RNE__conf_old__LR2 c1 \\<in> epdaS_initial_configurations G2\"\n  apply(simp add: epdaS_initial_configurations_def)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RNE__conf_old__LR2_def F_DPDA_RNE_def)\n   apply(simp add: F_DPDA_RNE__relation_structure__LR2_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RNE__conf_old__LR2_def F_DPDA_RNE_def)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RNE__conf_old__LR2_def F_DPDA_RNE_def)\n   apply(simp add: F_DPDA_RNE__relation_structure__LR2_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RNE__conf_old__LR2_def F_DPDA_RNE_def)\n  apply(rule F_DPDA_RNE__conf_old__LR2_preserves_configurations)\n   apply(force)\n  apply(force)\n  done\n\nlemma F_DPDA_RNE__conf_old__LR2_preserves_marking_configurations: \"\n  F_DPDA_RNE__relation_structure__LR2 G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS_marking_configurations G1\n  \\<Longrightarrow> F_DPDA_RNE__conf_old__LR2 c1 \\<in> epdaS_marking_configurations G2\"\n  apply(simp add: epdaS_marking_configurations_def)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RNE__conf_old__LR2_def F_DPDA_RNE_def)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RNE__conf_old__LR2_def F_DPDA_RNE_def)\n   apply(simp add: F_DPDA_RNE__relation_structure__LR2_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RNE__conf_old__LR2_def F_DPDA_RNE_def)\n  apply(rule F_DPDA_RNE__conf_old__LR2_preserves_configurations)\n   apply(force)\n  apply(force)\n  done\n\nlemma F_DPDA_RNE__initial_simulation_preserves_derivationX: \"\n  F_DPDA_RNE__relation_structure__LR2 G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS_initial_configurations G1\n  \\<Longrightarrow> epdaS.derivation_initial G2 (der1 (F_DPDA_RNE__conf_old__LR2 c1))\"\n  apply(rule epdaS.derivation_initialI)\n   apply(rule epdaS.der1_is_derivation)\n  apply(clarsimp)\n  apply(rename_tac c)(*strict*)\n  apply(simp add: get_configuration_def der1_def)\n  apply(clarsimp)\n  apply(rule F_DPDA_RNE__conf_old__LR2_preserves_initial_configurations)\n   apply(force)\n  apply(force)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimLR_inst_relation_initial_simulationX: \"\n  \\<forall>G1 G2. F_DPDA_RNE__relation_structure__LR2 G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<exists>d2. epdaS.derivation_initial G2 d2 \\<and> F_DPDA_RNE__relation_initial_configuration__LR2 G1 G2 c1 (the (get_configuration (d2 0))) \\<and> F_DPDA_RNE__relation_initial_simulation__LR2 G1 G2 c1 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_DPDA_RNE__relation_configuration__LR2 G1 G2 c1 (the (get_configuration (d2 n))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_initial_simulation__LR2_def)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule F_DPDA_RNE__initial_simulation_preserves_derivationX)\n    apply(rename_tac G1 G2 c1)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_initial_configuration__LR2_def)\n   apply(simp add: get_configuration_def der1_def)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule_tac\n      x=\"0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule der1_maximum_of_domain)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: get_configuration_def der1_def)\n  apply(simp add: F_DPDA_RNE__relation_configuration__LR2_def)\n  apply(rule epdaS.initial_configurations_are_get_accessible_configurations)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_structure__LR2_def valid_pda_def valid_dpda_def)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(force)\n  done\n\nlemma F_DPDA_RNE__relation_step_simulation__LR2_maps_to_derivation: \"\n  F_DPDA_RNE__relation_step_simulation__LR2 G1 G2 c1 e1 c1' c2 d2\n  \\<Longrightarrow> F_DPDA_RNE__relation_configuration__LR2 G1 G2 c1 c2\n  \\<Longrightarrow> epdaS_step_relation G1 c1 e1 c1'\n  \\<Longrightarrow> epdaS.derivation G2 d2\"\n  apply(simp add: F_DPDA_RNE__relation_step_simulation__LR2_def)\n  apply(case_tac \"FB_neutral_edge e1\")\n   apply(clarsimp)\n   apply(rule epdaS.der3_is_derivation)\n     apply(simp add: F_DPDA_RNE__relation_configuration__LR2_def)\n     apply (metis epdaS_epdaS_RNoOp_StateSimLRX_inst_AX_TSstructure_relation_TSstructure2_belongs)\n    apply(simp add: epdaS_step_relation_def F_DPDA_RNE__conf_old__LR2_def F_DPDA_RNE__edge_then_1_def F_DPDA_RNE__conf_new__LR2_def)\n    apply(clarsimp)\n    apply(rename_tac w)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac w)(*strict*)\n     prefer 2\n     apply(simp add: option_to_list_def FB_executing_edge_def)\n    apply(rename_tac w)(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_configuration__LR2_def)\n    apply(simp add: F_DPDA_RNE__relation_structure__LR2_def F_DPDA_RNE_def)\n    apply(rule_tac\n      x=\"e1\"\n      in bexI_image_disjI1)\n     apply(blast)\n    apply(rename_tac w)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_def)\n    apply(rule disjI1)\n    apply(simp add: F_DPDA_RNE__edge_then_1_def)\n   apply(simp add: epdaS_step_relation_def F_DPDA_RNE__conf_old__LR2_def F_DPDA_RNE__edge_then_2_def F_DPDA_RNE__conf_new__LR2_def)\n   apply(clarsimp)\n   apply(rename_tac w)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac w)(*strict*)\n    prefer 2\n    apply(simp add: option_to_list_def FB_neutral_edge_def)\n   apply(rename_tac w)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_configuration__LR2_def)\n   apply(simp add: F_DPDA_RNE__relation_structure__LR2_def F_DPDA_RNE_def)\n   apply(rule_tac\n      x=\"e1\"\n      in bexI_image_disjI1)\n    apply(blast)\n   apply(rename_tac w)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_def)\n   apply(rule disjI2)\n   apply(simp add: F_DPDA_RNE__edge_then_2_def)\n  apply(clarsimp)\n  apply(rule epdaS.der2_is_derivation)\n  apply(simp add: epdaS_step_relation_def F_DPDA_RNE__conf_old__LR2_def F_DPDA_RNE__edge_else_def)\n  apply(clarsimp)\n  apply(rename_tac w)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_configuration__LR2_def F_DPDA_RNE__relation_structure__LR2_def F_DPDA_RNE_def)\n  apply(rule_tac\n      x=\"e1\"\n      in bexI_image_disjI2)\n   apply(blast)\n  apply(rename_tac w)(*strict*)\n  apply(simp add: F_DPDA_RNE__edge_else_def)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimLR_inst_relation_step_simulationX: \"\n  (\\<forall>G1 G2. F_DPDA_RNE__relation_structure__LR2 G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_DPDA_RNE__relation_configuration__LR2 G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<exists>d2. epdaS.derivation G2 d2 \\<and> epdaS.belongs G2 d2 \\<and> the (get_configuration (d2 0)) = c2 \\<and> F_DPDA_RNE__relation_step_simulation__LR2 G1 G2 c1 e1 c1' c2 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_DPDA_RNE__relation_configuration__LR2 G1 G2 c1' (the (get_configuration (d2 n)))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_step_simulation__LR2_def)\n  apply(case_tac \"FB_neutral_edge e1\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(clarsimp)\n   apply(rule context_conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(rule F_DPDA_RNE__relation_step_simulation__LR2_maps_to_derivation)\n      apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_step_simulation__LR2_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(rule epdaS.der3_belongs)\n      apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n      apply (metis epdaS_epdaS_RNoOp_StateSimLRX_inst_AX_TSstructure_relation_TSstructure2_belongs)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(rule F_DPDA_RNE__conf_old__LR2_preserves_configurations)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_configuration__LR2_def)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n    apply (metis (full_types) epdaS_epdaS_RNoOp_StateSimLRX_inst_AX_TSstructure_relation_TSstructure1_belongs epdaS.get_accessible_configurations_are_configurations subsetD)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(simp add: der3_def get_configuration_def F_DPDA_RNE__relation_configuration__LR2_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule_tac\n      x=\"Suc(Suc 0)\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(rule_tac der3_maximum_of_domain)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_configuration__LR2_def)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    prefer 2\n    apply(simp add: der3_def get_configuration_def F_DPDA_RNE__relation_configuration__LR2_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule epdaS.der2_preserves_get_accessible_configurations)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     apply (metis epdaS_epdaS_RNoOp_StateSimLRX_inst_AX_TSstructure_relation_TSstructure1_belongs)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(rule epdaS.der2_is_derivation)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(clarsimp)\n  apply(rule context_conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule F_DPDA_RNE__relation_step_simulation__LR2_maps_to_derivation)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_step_simulation__LR2_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule epdaS.der2_belongs_prime)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     apply (metis epdaS_epdaS_RNoOp_StateSimLRX_inst_AX_TSstructure_relation_TSstructure2_belongs)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(rule F_DPDA_RNE__conf_old__LR2_preserves_configurations)\n     apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_configuration__LR2_def)\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 e1 c1')(*strict*)\n    apply (metis (full_types) epdaS_epdaS_RNoOp_StateSimLRX_inst_AX_TSstructure_relation_TSstructure1_belongs epdaS.get_accessible_configurations_are_configurations subsetD)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(simp add: get_configuration_def der2_def F_DPDA_RNE__relation_configuration__LR2_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule der2_maximum_of_domain)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(simp (no_asm) add: get_configuration_def der2_def)\n  apply(simp add: F_DPDA_RNE__relation_configuration__LR2_def)\n  apply(rule epdaS.der2_preserves_get_accessible_configurations)\n    apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n    apply (metis epdaS_epdaS_RNoOp_StateSimLRX_inst_AX_TSstructure_relation_TSstructure1_belongs)\n   apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n   apply(rule epdaS.der2_is_derivation)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(force)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axiomsX: \"\n  ATS_Simulation_Configuration_Weak_axioms valid_epda epdaS_initial_configurations epda_step_labels epdaS_step_relation valid_epda epdaS_configurations epdaS_initial_configurations epda_step_labels epdaS_step_relation F_DPDA_RNE__relation_configuration__LR2 F_DPDA_RNE__relation_initial_configuration__LR2 F_DPDA_RNE__relation_structure__LR2 F_DPDA_RNE__relation_initial_simulation__LR2 F_DPDA_RNE__relation_step_simulation__LR2\"\n  apply(simp add: ATS_Simulation_Configuration_Weak_axioms_def)\n  apply(simp add: epdaS_epdaS_RNoOp_StateSimLR_inst_relation_initial_simulationX epdaS_epdaS_RNoOp_StateSimLR_inst_relation_step_simulationX\n      epdaS_epdaS_RNoOp_StateSimLRX_inst_AX_TSstructure_relation_TSstructure1_belongs\n      epdaS_epdaS_RNoOp_StateSimLRX_inst_AX_TSstructure_relation_TSstructure2_belongs)\n  done\n\ninterpretation \"epdaS_epdaS_RNoOp_StateSimLRX\" : ATS_Simulation_Configuration_Weak\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaS_configurations\"\n  (* initial_configurations1 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaS_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaS_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_DPDA_RNE__relation_configuration__LR2\"\n  (* relation_initial_configuration *)\n  \"F_DPDA_RNE__relation_initial_configuration__LR2\"\n  (* relation_effect *)\n  \"F_DPDA_RNE__relation_effect__LR2\"\n  (* relation_TSstructure *)\n  \"F_DPDA_RNE__relation_structure__LR2\"\n  (* relation_initial_simulation *)\n  \"F_DPDA_RNE__relation_initial_simulation__LR2\"\n  (* relation_step_simulation *)\n  \"F_DPDA_RNE__relation_step_simulation__LR2\"\n  apply(simp add: LOCALE_DEFS epda_interpretations)\n  apply(simp add: epdaS_epdaS_RNoOp_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axiomsX epdaS_epdaS_RNoOp_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axiomsX)\n  done\n\ndefinition F_DPDA_RNE__relation_structure__RL2 :: \"\n  (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_structure__RL2 G1 G2 \\<equiv>\n  valid_dpda G2\n  \\<and> G1 = F_DPDA_RNE G2 (F_FRESH (epda_gamma G2))\"\n\ndefinition F_DPDA_RNE__relation_configuration__RL2 :: \"\n  (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_configuration__RL2 G1 G2 c1 c2 \\<equiv>\n  F_DPDA_RNE__relation_structure__RL2 G1 G2\n  \\<and> c1 \\<in> epdaS.get_accessible_configurations G1\n  \\<and> c2 = F_DPDA_RNE__conf__RL2 c1\"\n\ndefinition F_DPDA_RNE__relation_initial_configuration__RL2 :: \"\n  (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_initial_configuration__RL2 G1 G2 c1 c2 \\<equiv>\n  F_DPDA_RNE__relation_structure__RL2 G1 G2\n  \\<and> c1 \\<in> epdaS_initial_configurations G1\n  \\<and> c2 = F_DPDA_RNE__conf__RL2 c1\"\n\ndefinition F_DPDA_RNE__relation_effect__RL2 :: \"\n  (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> 'event list\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_effect__RL2 G1 G2 w1 w2 \\<equiv>\n  F_DPDA_RNE__relation_structure__RL2 G1 G2\n  \\<and> w1 = w2\"\n\nlemma epdaS_epdaS_RNoOp_StateSimRLX_inst_AX_TSstructure_relation_TSstructure1_belongs: \"\n  (\\<forall>G1. Ex (F_DPDA_RNE__relation_structure__RL2 G1) \\<longrightarrow> valid_epda G1)\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n  apply(clarsimp)\n  apply(rename_tac G2)(*strict*)\n  apply(rule F_DPDA_RNE__preserves_epda)\n   apply(rename_tac G2)(*strict*)\n   apply(force)\n  apply(rename_tac G2)(*strict*)\n  apply(rule F_FRESH_is_fresh)\n  apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimRLX_inst_AX_TSstructure_relation_TSstructure2_belongs: \"\n  (\\<forall>G1 G2. F_DPDA_RNE__relation_structure__RL2 G1 G2 \\<longrightarrow> valid_epda G2)\"\n  apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n  apply(clarsimp)\n  apply(rename_tac G2)(*strict*)\n  apply (metis valid_dpda_def valid_pda_def)\n  done\n\ndefinition F_DPDA_RNE__relation_step_simulation__RL2 :: \"\n  (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event , 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda_step_label\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event , 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) epda_step_label, ('state, 'event, 'stack DT_symbol) epdaS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_step_simulation__RL2 G1 G2 c1 e c1' c2 d \\<equiv>\n  case edge_trg e of cons_state_or_edge_old q\n  \\<Rightarrow> (case edge_src e of cons_state_or_edge_old q\n    \\<Rightarrow> d = der2\n      (F_DPDA_RNE__conf__RL2 c1)\n        (F_DPDA_RNE__edge__RL2 e)\n      (F_DPDA_RNE__conf__RL2 c1')\n    | cons_state_or_edge_new e\n    \\<Rightarrow> d = der2\n      (F_DPDA_RNE__conf__RL2 c1)\n        e\n      (F_DPDA_RNE__conf__RL2 c1'))\n  | cons_state_or_edge_new e\n  \\<Rightarrow> d = der1 (F_DPDA_RNE__conf__RL2 c1)\"\n\ndefinition F_DPDA_RNE__relation_initial_simulation__RL2 :: \"\n  (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event , 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epdaS_conf\n  \\<Rightarrow> (('state, 'event , 'stack DT_symbol) epda_step_label, ('state, 'event , 'stack DT_symbol) epdaS_conf) derivation\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__relation_initial_simulation__RL2 G1 G2 c1 d \\<equiv>\n  d = der1 (F_DPDA_RNE__conf__RL2 c1)\"\n\nlemma RNoOp_create_no_pseudo_box_in_the_configurationX: \"\n  F_DPDA_RNE__relation_structure__RL2 G1 G2\n  \\<Longrightarrow> epdaS.derivation_initial G1 d\n  \\<Longrightarrow> d i = Some (pair e c1)\n  \\<Longrightarrow> pseudo_box_top G2 c1\"\n  apply(simp add: pseudo_box_top_def)\n  apply(induct i arbitrary: e c1)\n   apply(rename_tac e c1)(*strict*)\n   apply(simp add: epdaS.derivation_initial_def)\n   apply(clarsimp)\n   apply(rename_tac c1)(*strict*)\n   apply(simp add: epdaS_initial_configurations_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RNE_def)\n   apply(clarsimp)\n   apply(subgoal_tac \"F_FRESH (epda_gamma G2) \\<notin> epda_gamma G2\")\n    apply(rename_tac c1)(*strict*)\n    apply(subgoal_tac \"epda_box G2 \\<in> epda_gamma G2\")\n     apply(rename_tac c1)(*strict*)\n     apply(force)\n    apply(rename_tac c1)(*strict*)\n    apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac c1)(*strict*)\n   apply(rule F_FRESH_is_fresh)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rename_tac i e c1)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d i = Some (pair e1 c1) \\<and> SSd (Suc SSn) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation SSG c1 e2 c2\" for SSd SSn SSG)\n   apply(rename_tac i e c1)(*strict*)\n   prefer 2\n   apply(rule epdaS.step_detail_before_some_position)\n     apply(rename_tac i e c1)(*strict*)\n     apply(simp add: epdaS.derivation_initial_def)\n     apply(force)\n    apply(rename_tac i e c1)(*strict*)\n    apply(force)\n   apply(rename_tac i e c1)(*strict*)\n   apply(force)\n  apply(rename_tac i e c1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i c1 e1 e2 c1a)(*strict*)\n  apply(erule_tac\n      x=\"e1\"\n      in meta_allE)\n  apply(erule_tac\n      x=\"c1a\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(subgoal_tac \"valid_epda_step_label G1 e2\")\n   apply(rename_tac i c1 e1 e2 c1a)(*strict*)\n   prefer 2\n   apply(subgoal_tac \"valid_epda G1\")\n    apply(rename_tac i c1 e1 e2 c1a)(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_structure__RL2_def valid_dpda_def valid_pda_def valid_epda_def)\n    apply(clarsimp)\n    apply(simp add: epdaS_step_relation_def)\n   apply(rename_tac i c1 e1 e2 c1a)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n   apply (rule F_DPDA_RNE__preserves_epda)\n    apply(rename_tac i c1 e1 e2 c1a)(*strict*)\n    apply(force)\n   apply(rename_tac i c1 e1 e2 c1a)(*strict*)\n   apply(rule F_FRESH_is_fresh)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rename_tac i c1 e1 e2 c1a)(*strict*)\n  apply(case_tac \"epdaS_conf_state c1\")\n   apply(rename_tac i c1 e1 e2 c1a q)(*strict*)\n   apply(clarsimp)\n   apply(simp add: epdaS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac i c1 e1 e2 c1a q w)(*strict*)\n   apply(case_tac \"edge_src e2\")\n    apply(rename_tac i c1 e1 e2 c1a q w qa)(*strict*)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RNE_def)\n    apply(clarsimp)\n    apply(erule disjE)\n     apply(rename_tac i c1 e1 e2 c1a q w qa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac i c1 e1 e2 c1a q w qa x)(*strict*)\n     apply(simp add: F_DPDA_RNE__edge_then_def)\n     apply(erule disjE)\n      apply(rename_tac i c1 e1 e2 c1a q w qa x)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac i c1 e1 c1a q w qa x)(*strict*)\n      apply(simp add: F_DPDA_RNE__edge_then_1_def)\n     apply(rename_tac i c1 e1 e2 c1a q w qa x)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac i c1 e1 c1a q w qa x)(*strict*)\n     apply(simp add: F_DPDA_RNE__edge_then_2_def)\n    apply(rename_tac i c1 e1 e2 c1a q w qa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i c1 e1 c1a q w qa x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_else_def FB_neutral_edge_def)\n    apply(clarsimp)\n    apply(rename_tac i c1 e1 c1a w x)(*strict*)\n    apply(simp add: valid_epda_step_label_def)\n    apply(clarsimp)\n    apply(subgoal_tac \"F_FRESH (epda_gamma G2) \\<notin> epda_gamma G2\")\n     apply(rename_tac i c1 e1 c1a w x)(*strict*)\n     apply(subgoal_tac \"set (edge_push x) \\<subseteq> epda_gamma G2\")\n      apply(rename_tac i c1 e1 c1a w x)(*strict*)\n      apply(force)\n     apply(rename_tac i c1 e1 c1a w x)(*strict*)\n     apply(rule epda_edge_in_gamma)\n      apply(rename_tac i c1 e1 c1a w x)(*strict*)\n      apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n     apply(rename_tac i c1 e1 c1a w x)(*strict*)\n     apply(force)\n    apply(rename_tac i c1 e1 c1a w x)(*strict*)\n    apply(rule F_FRESH_is_fresh)\n    apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext wa)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext wa)(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RNE_def)\n    apply(clarsimp)\n    apply(erule disjE)\n     apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext wa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext wa x)(*strict*)\n     apply(simp add: F_DPDA_RNE__edge_then_def)\n     apply(erule disjE)\n      apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext wa x)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac i c1 e1 c1a q w epda_step_label_ext wa x)(*strict*)\n      apply(simp add: F_DPDA_RNE__edge_then_1_def)\n     apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext wa x)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac i c1 e1 c1a q w epda_step_label_ext wa x)(*strict*)\n     apply(simp add: F_DPDA_RNE__edge_then_2_def)\n    apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext wa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i c1 e1 c1a q w epda_step_label_ext wa x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_else_def FB_neutral_edge_def)\n   apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext wa)(*strict*)\n   apply(case_tac \"edge_pop e2\")\n    apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext wa)(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_structure__RL2_def valid_dpda_def valid_pda_def valid_epda_def)\n    apply(clarsimp)\n    apply(rename_tac i c1 e1 e2 c1a q epda_step_label_ext wa)(*strict*)\n    apply(simp add: F_DPDA_RNE_def)\n    apply(clarsimp)\n    apply(erule disjE)\n     apply(rename_tac i c1 e1 e2 c1a q epda_step_label_ext wa)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac i c1 e1 e2 c1a q epda_step_label_ext wa x)(*strict*)\n     apply(simp add: F_DPDA_RNE__edge_then_def)\n     apply(erule disjE)\n      apply(rename_tac i c1 e1 e2 c1a q epda_step_label_ext wa x)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac i c1 e1 c1a q epda_step_label_ext wa x)(*strict*)\n      apply(simp add: F_DPDA_RNE__edge_then_1_def)\n     apply(rename_tac i c1 e1 e2 c1a q epda_step_label_ext wa x)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac i c1 e1 c1a q epda_step_label_ext wa x)(*strict*)\n     apply(simp add: F_DPDA_RNE__edge_then_2_def)\n    apply(rename_tac i c1 e1 e2 c1a q epda_step_label_ext wa)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i c1 e1 c1a q epda_step_label_ext wa x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_else_def FB_neutral_edge_def)\n   apply(rename_tac i c1 e1 e2 c1a q w epda_step_label_ext wa a list)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext)(*strict*)\n  apply(clarsimp)\n  apply(case_tac \"epdaS_conf_state c1a\")\n   apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext q)(*strict*)\n   apply(clarsimp)\n   apply(simp add: epdaS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext q w)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RNE_def)\n   apply(clarsimp)\n   apply(erule disjE)\n    apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext q w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext q w x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_def)\n    apply(erule disjE)\n     apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext q w x)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac i c1 e1 c1a epda_step_label_ext q w x)(*strict*)\n     apply(simp add: F_DPDA_RNE__edge_then_1_def)\n    apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext q w x)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i c1 e1 c1a epda_step_label_ext q w x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_2_def)\n   apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext q w)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i c1 e1 c1a epda_step_label_ext q w x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_else_def FB_neutral_edge_def)\n  apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext epda_step_label_exta)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext epda_step_label_exta w)(*strict*)\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext epda_step_label_exta w wa)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RNE_def)\n  apply(clarsimp)\n  apply(erule disjE)\n   apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext epda_step_label_exta w wa)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext epda_step_label_exta w wa x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_def)\n   apply(erule disjE)\n    apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext epda_step_label_exta w wa x)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac i c1 e1 c1a epda_step_label_ext epda_step_label_exta w wa x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_1_def)\n   apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext epda_step_label_exta w wa x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac i c1 e1 c1a epda_step_label_ext epda_step_label_exta w wa x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_2_def)\n  apply(rename_tac i c1 e1 e2 c1a epda_step_label_ext epda_step_label_exta w wa)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac i c1 e1 c1a epda_step_label_ext epda_step_label_exta w wa x)(*strict*)\n  apply(simp add: F_DPDA_RNE__edge_else_def FB_neutral_edge_def)\n  done\n\nlemma RNoOp_create_no_pseudo_box_in_the_configuration_primeX: \"\n  F_DPDA_RNE__relation_structure__RL2 G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS.get_accessible_configurations G1\n  \\<Longrightarrow> pseudo_box_top G2 c1\"\n  apply(simp add: epdaS.get_accessible_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac d i)(*strict*)\n  apply(case_tac \"d i\")\n   apply(rename_tac d i)(*strict*)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n  apply(rename_tac d i a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac d i a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d i option b)(*strict*)\n  apply(rename_tac e c)\n  apply(rename_tac d i e c)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac d i e)(*strict*)\n  apply(rule RNoOp_create_no_pseudo_box_in_the_configurationX)\n    apply(rename_tac d i e)(*strict*)\n    apply(force)+\n  done\n\nlemma F_DPDA_RNE__conf__RL2_preserves_configurationsX: \"\n  F_DPDA_RNE__relation_structure__RL2 G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS.get_accessible_configurations G1\n  \\<Longrightarrow> c1 \\<in> epdaS_configurations G1\n  \\<Longrightarrow> F_DPDA_RNE__conf__RL2 c1 \\<in> epdaS_configurations G2\"\n  apply(subgoal_tac \"case (epdaS_conf_state c1) of cons_state_or_edge_old q \\<Rightarrow> (F_FRESH (epda_gamma G2) \\<notin> set (epdaS_conf_stack c1)) | cons_state_or_edge_new e \\<Rightarrow> (\\<exists>w. F_FRESH (epda_gamma G2) \\<notin> set w \\<and> ([F_FRESH (epda_gamma G2)]@w) = epdaS_conf_stack c1)\")\n   apply(simp (no_asm) add: epdaS_configurations_def)\n   apply(case_tac \"epdaS_conf_state c1\")\n    apply(rename_tac q)(*strict*)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RNE__conf__RL2_def)\n    apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n    apply(clarsimp)\n    apply(simp add: epdaS_configurations_def)\n    apply(clarsimp)\n    apply(rename_tac q i s)(*strict*)\n    apply(simp add: F_DPDA_RNE_def)\n    apply(rule conjI)\n     apply(rename_tac q i s)(*strict*)\n     apply(erule disjE)\n      apply(rename_tac q i s)(*strict*)\n      apply(force)\n     apply(rename_tac q i s)(*strict*)\n     apply(force)\n    apply(rename_tac q i s)(*strict*)\n    apply(force)\n   apply(rename_tac epda_step_label_ext)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac epda_step_label_ext w)(*strict*)\n   apply(simp add: F_DPDA_RNE__conf__RL2_def)\n   apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n   apply(clarsimp)\n   apply(simp add: epdaS_configurations_def)\n   apply(clarsimp)\n   apply(rename_tac epda_step_label_ext w i)(*strict*)\n   apply(simp add: F_DPDA_RNE_def)\n   apply(rule conjI)\n    apply(rename_tac epda_step_label_ext w i)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac epda_step_label_ext w i)(*strict*)\n     apply(force)\n    apply(rename_tac epda_step_label_ext w i)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac w i x)(*strict*)\n    apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"x\"\n      and P=\"\\<lambda>x. valid_epda_step_label G2 x\"\n      in ballE)\n     apply(rename_tac w i x)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac w i x)(*strict*)\n    apply(simp add: valid_epda_step_label_def)\n   apply(rename_tac epda_step_label_ext w i)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac epda_step_label_ext w i x)(*strict*)\n   apply(force)\n  apply(fold pseudo_box_top_def)\n  apply(rule RNoOp_create_no_pseudo_box_in_the_configuration_primeX)\n   apply(force)+\n  done\n\nlemma F_DPDA_RNE__conf__RL2_preserves_initial_configurations: \"\n  F_DPDA_RNE__relation_structure__RL2 G1 G2\n  \\<Longrightarrow> c1 \\<in> epdaS_initial_configurations G1\n  \\<Longrightarrow> F_DPDA_RNE__conf__RL2 c1 \\<in> epdaS_initial_configurations G2\"\n  apply(simp add: epdaS_initial_configurations_def)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RNE__conf__RL2_def)\n   apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RNE_def)\n  apply(rule conjI)\n   apply(simp add: F_DPDA_RNE__conf__RL2_def)\n   apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_RNE_def)\n  apply(clarsimp)\n  apply(simp add: epdaS_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac i)(*strict*)\n  apply(simp add: F_DPDA_RNE__conf__RL2_def F_DPDA_RNE__relation_structure__RL2_def F_DPDA_RNE_def)\n  apply(clarsimp)\n  apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimRL_inst_relation_initial_simulationX: \"\n  (\\<forall>G1 G2. F_DPDA_RNE__relation_structure__RL2 G1 G2 \\<longrightarrow> (\\<forall>c1. c1 \\<in> epdaS_initial_configurations G1 \\<longrightarrow> (\\<exists>d2. epdaS.derivation_initial G2 d2 \\<and> F_DPDA_RNE__relation_initial_configuration__RL2 G1 G2 c1 (the (get_configuration (d2 0))) \\<and> F_DPDA_RNE__relation_initial_simulation__RL2 G1 G2 c1 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_DPDA_RNE__relation_configuration__RL2 G1 G2 c1 (the (get_configuration (d2 n)))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_initial_simulation__RL2_def)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule epdaS.derivation_initialI)\n    apply(rename_tac G1 G2 c1)(*strict*)\n    apply(rule epdaS.der1_is_derivation)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: get_configuration_def der1_def)\n   apply(rule F_DPDA_RNE__conf__RL2_preserves_initial_configurations)\n    apply(rename_tac G1 G2 c1)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: get_configuration_def der1_def)\n   apply(simp add: F_DPDA_RNE__relation_initial_configuration__RL2_def)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(rule_tac\n      x=\"0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule der1_maximum_of_domain)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(simp add: get_configuration_def der1_def)\n  apply(simp add: F_DPDA_RNE__relation_configuration__RL2_def)\n  apply(rule epdaS.initial_configurations_are_get_accessible_configurations)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n   apply(rule F_DPDA_RNE__preserves_epda)\n    apply(rename_tac G1 G2 c1)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1)(*strict*)\n   apply(rule F_FRESH_is_fresh)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rename_tac G1 G2 c1)(*strict*)\n  apply(force)\n  done\n\nlemma F_DPDA_RNE__relation_step_simulation__RL2_maps_to_derivation: \"\n  F_DPDA_RNE__relation_structure__RL2 G1 G2\n  \\<Longrightarrow> F_DPDA_RNE__relation_step_simulation__RL2 G1 G2 c1 e1 c1' c2 d2\n  \\<Longrightarrow> F_DPDA_RNE__relation_configuration__RL2 G1 G2 c1 c2\n  \\<Longrightarrow> epdaS_step_relation G1 c1 e1 c1'\n  \\<Longrightarrow> epdaS.derivation G2 d2\"\n  apply(simp add: F_DPDA_RNE__relation_step_simulation__RL2_def)\n  apply(case_tac \"edge_trg e1\")\n   apply(rename_tac q)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"edge_src e1\")\n    apply(rename_tac q qa)(*strict*)\n    apply(clarsimp)\n    apply(rule epdaS.der2_is_derivation)\n    apply(simp add: epdaS_step_relation_def F_DPDA_RNE__conf__RL2_def F_DPDA_RNE__edge__RL2_def)\n    apply(clarsimp)\n    apply(rename_tac q qa w)(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RNE_def)\n    apply(clarsimp)\n    apply(erule disjE)\n     apply(rename_tac q qa w)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac q qa w x)(*strict*)\n     apply(simp add: F_DPDA_RNE__edge_then_def)\n     apply(erule disjE)\n      apply(rename_tac q qa w x)(*strict*)\n      apply(simp add: F_DPDA_RNE__edge_then_1_def)\n     apply(rename_tac q qa w x)(*strict*)\n     apply(simp add: F_DPDA_RNE__edge_then_2_def)\n    apply(rename_tac q qa w)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac q qa w x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_else_def)\n    apply(simp add: FB_neutral_edge_def)\n    apply(case_tac x)\n    apply(rename_tac q qa w x edge_srca edge_eventa edge_popa edge_pusha edge_trga)(*strict*)\n    apply(force)\n   apply(rename_tac q epda_step_label_ext)(*strict*)\n   prefer 2\n   apply(rename_tac epda_step_label_ext)(*strict*)\n   apply(clarsimp)\n   apply(rule epdaS.der1_is_derivation)\n  apply(rename_tac q epda_step_label_ext)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac e)\n  apply(rename_tac q e)(*strict*)\n  apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G2 \\<inter> Collect FB_neutral_edge. e1 \\<in> F_DPDA_RNE__edge_then x (F_FRESH (epda_gamma G2))) \\<or> (\\<exists>x\\<in> epda_delta G2 \\<inter> {e. \\<not> FB_neutral_edge e}. e1 = F_DPDA_RNE__edge_else x)\")\n   apply(rename_tac q e)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_step_relation_def)\n   apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n   apply(simp add: F_DPDA_RNE_def)\n   apply(blast)\n  apply(rename_tac q e)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac q e)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac q e x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_def)\n   apply(erule disjE)\n    apply(rename_tac q e x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_1_def)\n   apply(rename_tac q e x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_2_def)\n   apply(clarsimp)\n   apply(rename_tac e)(*strict*)\n   prefer 2\n   apply(rename_tac q e)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_else_def)\n   apply(clarsimp)\n  apply(rename_tac e)(*strict*)\n  apply(simp add: epdaS_step_relation_def)\n  apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RNE_def)\n  apply(rule epdaS.der2_is_derivation)\n  apply(simp add: epdaS_step_relation_def F_DPDA_RNE__conf__RL2_def)\n  apply(rule conjI)\n   apply(rename_tac e)(*strict*)\n   apply(simp add: FB_neutral_edge_def)\n  apply(rename_tac e)(*strict*)\n  apply(clarsimp)\n  apply(erule disjE)\n   apply(rename_tac e)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac e x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_def)\n   apply(erule disjE)\n    apply(rename_tac e x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_1_def)\n   apply(rename_tac e x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_2_def)\n   apply(clarsimp)\n   apply(rename_tac x)(*strict*)\n   prefer 2\n   apply(rename_tac e)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_else_def)\n   apply(blast)\n  apply(rename_tac x)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_configuration__RL2_def)\n  apply(clarsimp)\n  apply(simp add: epdaS.get_accessible_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac x d i)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(case_tac \"d i\")\n   apply(rename_tac x d i)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x d i a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac x d i a option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d i option)(*strict*)\n  apply(case_tac i)\n   apply(rename_tac x d i option)(*strict*)\n   apply(simp add: epdaS.derivation_initial_def)\n   apply(clarsimp)\n   apply(rename_tac x d)(*strict*)\n   apply(simp add: epdaS_initial_configurations_def)\n  apply(rename_tac x d i option nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d option nat)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d nat = Some (pair e1 c1) \\<and> SSd (Suc SSn) = Some (pair (Some e2) c2) \\<and> epdaS_step_relation SSG c1 e2 c2\" for SSd SSn SSG)\n   apply(rename_tac x d option nat)(*strict*)\n   prefer 2\n   apply(rule epdaS.step_detail_before_some_position)\n     apply(rename_tac x d option nat)(*strict*)\n     apply(simp add: epdaS.derivation_initial_def)\n     apply(force)\n    apply(rename_tac x d option nat)(*strict*)\n    apply(force)\n   apply(rename_tac x d option nat)(*strict*)\n   apply(force)\n  apply(rename_tac x d option nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x d nat e1 e2 c1a)(*strict*)\n  apply(simp add: epdaS_step_relation_def)\n  apply(clarsimp)\n  apply(rename_tac x d nat e1 e2 c1a w)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac x d nat e1 e2 c1a w)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x d nat e1 e2 c1a w xa)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_else_def  F_DPDA_RNE__edge_then_def F_DPDA_RNE__edge_then_1_def F_DPDA_RNE__edge_then_2_def FB_neutral_edge_def)\n   apply(rename_tac x d nat e1 e2 c1a w xa)(*strict*)\n   apply(clarsimp)\n   apply(erule disjE)\n    apply(rename_tac x d nat e1 e2 c1a w)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac x d nat e1 e2 c1a w xa)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_else_def  F_DPDA_RNE__edge_then_def F_DPDA_RNE__edge_then_1_def F_DPDA_RNE__edge_then_2_def FB_neutral_edge_def)\n  apply(rename_tac x d nat e1 e2 c1a w xa)(*strict*)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RNE__edge_else_def FB_neutral_edge_def)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimRL_step_relation_step_simulationX: \"\n  \\<forall>G1 G2. F_DPDA_RNE__relation_structure__RL2 G1 G2 \\<longrightarrow> (\\<forall>c1 c2. F_DPDA_RNE__relation_configuration__RL2 G1 G2 c1 c2 \\<longrightarrow> (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow> (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow> (\\<exists>d2. epdaS.derivation G2 d2 \\<and> epdaS.belongs G2 d2 \\<and> the (get_configuration (d2 0)) = c2 \\<and> F_DPDA_RNE__relation_step_simulation__RL2 G1 G2 c1 e1 c1' c2 d2 \\<and> (\\<exists>n. maximum_of_domain d2 n \\<and> F_DPDA_RNE__relation_configuration__RL2 G1 G2 c1' (the (get_configuration (d2 n))))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c2 e1 c1')(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_step_simulation__RL2_def)\n  apply(case_tac \"edge_trg e1\")\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q)(*strict*)\n   apply(clarsimp)\n   apply(case_tac \"edge_src e1\")\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(clarsimp)\n    apply(rule context_conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(rule F_DPDA_RNE__relation_step_simulation__RL2_maps_to_derivation)\n        apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n        apply(force)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n       prefer 2\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(simp add: F_DPDA_RNE__relation_step_simulation__RL2_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(rule epdaS.der2_belongs_prime)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n       apply (metis epdaS_epdaS_RNoOp_StateSimLRX_inst_AX_TSstructure_relation_TSstructure1_belongs F_DPDA_RNE__relation_structure__LR2_def F_DPDA_RNE__relation_structure__RL2_def)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(simp add: F_DPDA_RNE__relation_configuration__RL2_def)\n     apply(rule F_DPDA_RNE__conf__RL2_preserves_configurationsX)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(rule_tac\n      A=\"epdaS.get_accessible_configurations G1\"\n      in set_mp)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      apply(rule epdaS.get_accessible_configurations_are_configurations)\n      apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n      apply(rule F_DPDA_RNE__preserves_epda)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      apply(rule F_FRESH_is_fresh)\n      apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply (metis)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(simp add: get_configuration_def der2_def)\n     apply(simp add: F_DPDA_RNE__relation_configuration__RL2_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n    apply(rule conjI)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(rule der2_maximum_of_domain)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(simp (no_asm) add: der2_def get_configuration_def)\n    apply(simp add: F_DPDA_RNE__relation_configuration__RL2_def)\n    apply(rule_tac\n      ?e1.0=\"e1\"\n      in epdaS.der2_preserves_get_accessible_configurations)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n      apply(rule F_DPDA_RNE__preserves_epda)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n      apply(rule F_FRESH_is_fresh)\n      apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n     apply(rule epdaS.der2_is_derivation)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q qa)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n   prefer 2\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n   apply(clarsimp)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n    apply(rule epdaS.der1_is_derivation)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n    apply(rule epdaS.der1_belongs)\n    apply(rule F_DPDA_RNE__conf__RL2_preserves_configurationsX)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n     apply(simp add: F_DPDA_RNE__relation_configuration__RL2_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_configuration__RL2_def)\n    apply(rule_tac\n      A=\"epdaS.get_accessible_configurations G1\"\n      in set_mp)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n     apply(rule epdaS.get_accessible_configurations_are_configurations)\n     apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n     apply(rule F_DPDA_RNE__preserves_epda)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n     apply(rule F_FRESH_is_fresh)\n     apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n    apply(simp add: der1_def get_configuration_def)\n    apply(simp add: F_DPDA_RNE__relation_configuration__RL2_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n   apply(rule_tac\n      x=\"0\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n    apply(rule der1_maximum_of_domain)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n   apply(simp add: der1_def get_configuration_def)\n   apply(simp add: F_DPDA_RNE__relation_configuration__RL2_def)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n    apply(rule_tac\n      ?e1.0=\"e1\"\n      in epdaS.der2_preserves_get_accessible_configurations)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n      apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n      apply(rule F_DPDA_RNE__preserves_epda)\n       apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n       apply(force)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n      apply(rule F_FRESH_is_fresh)\n      apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n    apply(rule epdaS.der2_is_derivation)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' epda_step_label_ext)(*strict*)\n   apply(simp add: F_DPDA_RNE__conf__RL2_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext)(*strict*)\n   apply(simp add: epdaS_step_relation_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' epda_step_label_ext w)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 e1 c1' epda_step_label_ext w)(*strict*)\n   apply(simp add: F_DPDA_RNE_def epda_step_labels_def)\n   apply(clarsimp)\n   apply(erule disjE)\n    prefer 2\n    apply(rename_tac G2 c1 e1 c1' epda_step_label_ext w)(*strict*)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RNE__edge_else_def)\n   apply(simp add: F_DPDA_RNE__edge_then_def)\n   apply(simp add: F_DPDA_RNE__edge_then_2_def)\n   apply(rename_tac G2 c1 e1 c1' epda_step_label_exta w x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_1_def)\n   apply(simp add: option_to_list_def)\n   apply(rename_tac G2 c1 e1 c1' epda_step_label_ext w)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G2 c1 c1' epda_step_label_ext w x)(*strict*)\n   apply(erule disjE)\n    apply(force)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n  apply(clarsimp)\n  apply(rule context_conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n   apply(rule F_DPDA_RNE__relation_step_simulation__RL2_maps_to_derivation)\n      apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_step_simulation__RL2_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n   apply(rule epdaS.der2_belongs_prime)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n     apply (metis epdaS_epdaS_RNoOp_StateSimLRX_inst_AX_TSstructure_relation_TSstructure1_belongs F_DPDA_RNE__relation_structure__LR2_def F_DPDA_RNE__relation_structure__RL2_def)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n    prefer 2\n    apply(force)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n   apply(simp add: F_DPDA_RNE__relation_configuration__RL2_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' q epda_step_label_ext)(*strict*)\n   apply(rule F_DPDA_RNE__conf__RL2_preserves_configurationsX)\n     apply(rename_tac G1 G2 c1 e1 c1' q epda_step_label_ext)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 e1 c1' q epda_step_label_ext)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 e1 c1' q epda_step_label_ext)(*strict*)\n   apply(rule_tac\n      A=\"epdaS.get_accessible_configurations G1\"\n      in set_mp)\n    apply(rename_tac G1 G2 c1 e1 c1' q epda_step_label_ext)(*strict*)\n    apply(rule epdaS.get_accessible_configurations_are_configurations)\n    apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n    apply(rule F_DPDA_RNE__preserves_epda)\n     apply(rename_tac G1 G2 c1 e1 c1' q epda_step_label_ext)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 e1 c1' q epda_step_label_ext)(*strict*)\n    apply(rule F_FRESH_is_fresh)\n    apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac G1 G2 c1 e1 c1' q epda_step_label_ext)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n   apply(simp add: get_configuration_def der2_def)\n   apply(simp add: F_DPDA_RNE__relation_configuration__RL2_def)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n  apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n   apply(rule der2_maximum_of_domain)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n  apply(simp (no_asm) add: der2_def get_configuration_def)\n  apply(simp add: F_DPDA_RNE__relation_configuration__RL2_def)\n  apply(rule_tac\n      ?e1.0=\"e1\"\n      in epdaS.der2_preserves_get_accessible_configurations)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n    apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n    apply(rule F_DPDA_RNE__preserves_epda)\n     apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n    apply(rule F_FRESH_is_fresh)\n    apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac G1 G2 c1 c2 e1 c1' q epda_step_label_ext)(*strict*)\n  apply(rule epdaS.der2_is_derivation)\n  apply(force)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axiomsX: \"\n  ATS_Simulation_Configuration_Weak_axioms valid_epda epdaS_initial_configurations epda_step_labels epdaS_step_relation valid_epda epdaS_configurations epdaS_initial_configurations epda_step_labels epdaS_step_relation F_DPDA_RNE__relation_configuration__RL2 F_DPDA_RNE__relation_initial_configuration__RL2 F_DPDA_RNE__relation_structure__RL2 F_DPDA_RNE__relation_initial_simulation__RL2 F_DPDA_RNE__relation_step_simulation__RL2\"\n  apply(simp add: ATS_Simulation_Configuration_Weak_axioms_def epdaS_epdaS_RNoOp_StateSimRL_inst_relation_initial_simulationX epdaS_epdaS_RNoOp_StateSimRL_step_relation_step_simulationX epdaS_epdaS_RNoOp_StateSimRLX_inst_AX_TSstructure_relation_TSstructure1_belongs epdaS_epdaS_RNoOp_StateSimRLX_inst_AX_TSstructure_relation_TSstructure2_belongs)\n  done\n\ninterpretation \"epdaS_epdaS_RNoOp_StateSimRLX\" : ATS_Simulation_Configuration_Weak\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaS_configurations\"\n  (* initial_configurations1 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaS_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaS_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_DPDA_RNE__relation_configuration__RL2\"\n  (* relation_initial_configuration *)\n  \"F_DPDA_RNE__relation_initial_configuration__RL2\"\n  (* relation_effect *)\n  \"F_DPDA_RNE__relation_effect__RL2\"\n  (* relation_TSstructure *)\n  \"F_DPDA_RNE__relation_structure__RL2\"\n  (* relation_initial_simulation *)\n  \"F_DPDA_RNE__relation_initial_simulation__RL2\"\n  (* relation_step_simulation *)\n  \"F_DPDA_RNE__relation_step_simulation__RL2\"\n  apply(simp add: LOCALE_DEFS epda_interpretations)\n  apply(simp add: epdaS_epdaS_RNoOp_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axiomsX)\n  done\n\ndefinition RNoOpX_relation_labelsLR :: \"\n  ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epda_step_label\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda_step_label\n  \\<Rightarrow> bool\"\n  where\n    \"RNoOpX_relation_labelsLR G1 G2 e1 e2 \\<equiv>\n  F_DPDA_RNE__relation_structure__LR2 G1 G2\n  \\<and> e1 \\<in> F_DPDA_DRE__revert_F_DPDA_RNE G1 (F_FRESH (epda_gamma G1)) {e2}\"\n\nlemma ATS_Simulation_Configuration_WeakReach_axioms_inst_ATS_Simulation_Configuration_Weak_axioms: \"\n  ATS_Simulation_Configuration_WeakReach_axioms epda_step_labels epdaS_step_relation epdaS_configurations epda_step_labels epdaS_step_relation F_DPDA_RNE__relation_configuration__LR2 F_DPDA_RNE__relation_structure__LR2 F_DPDA_RNE__relation_step_simulation__LR2 RNoOpX_relation_labelsLR\"\n  apply(simp add: ATS_Simulation_Configuration_WeakReach_axioms_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_step_simulation__LR2_def)\n  apply(case_tac \"FB_neutral_edge e1\")\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' n)(*strict*)\n   apply(simp add: RNoOpX_relation_labelsLR_def F_DPDA_DRE__revert_F_DPDA_RNE_def)\n   apply(rule_tac\n      x=\"1\"\n      in exI)\n   apply(simp add: der3_def epda_step_labels_def F_DPDA_RNE__edge_then_def)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1' n)(*strict*)\n  apply(simp add: RNoOpX_relation_labelsLR_def F_DPDA_DRE__revert_F_DPDA_RNE_def)\n  apply(rule_tac\n      x=\"1\"\n      in exI)\n  apply(simp add: der2_def epda_step_labels_def F_DPDA_RNE__edge_then_def)\n  done\n\ninterpretation \"epdaS_epdaS_RNoOp_StateSimLRX\" : ATS_Simulation_Configuration_WeakReach\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaS_configurations\"\n  (* initial_configurations1 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaS_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaS_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_DPDA_RNE__relation_configuration__LR2\"\n  (* relation_initial_configuration *)\n  \"F_DPDA_RNE__relation_initial_configuration__LR2\"\n  (* relation_effect *)\n  \"F_DPDA_RNE__relation_effect__LR2\"\n  (* relation_TSstructure *)\n  \"F_DPDA_RNE__relation_structure__LR2\"\n  (* relation_initial_simulation *)\n  \"F_DPDA_RNE__relation_initial_simulation__LR2\"\n  (* relation_step_simulation *)\n  \"F_DPDA_RNE__relation_step_simulation__LR2\"\n  (* relation_labelsLR *)\n  \"RNoOpX_relation_labelsLR\"\n  apply(simp add: LOCALE_DEFS epda_interpretations)\n  apply(simp add: epdaS_epdaS_RNoOp_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axiomsX epdaS_epdaS_RNoOp_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axiomsX ATS_Simulation_Configuration_WeakReach_axioms_inst_ATS_Simulation_Configuration_Weak_axioms)\n  done\n\ndefinition RNoOpX_relation_labelsRL :: \"\n  (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epda\n  \\<Rightarrow> (('state, 'event, 'stack DT_symbol) DT_state_or_edge, 'event, 'stack DT_symbol) epda_step_label\n  \\<Rightarrow> ('state, 'event, 'stack DT_symbol) epda_step_label\n  \\<Rightarrow> bool\"\n  where\n    \"RNoOpX_relation_labelsRL G2 G1 e2 e1 \\<equiv>\n  F_DPDA_RNE__relation_structure__RL2 G2 G1\n  \\<and> e1 \\<in> F_DPDA_DRE__revert_F_DPDA_RNE G1 (F_FRESH (epda_gamma G1)) {e2}\"\n\nlemma RNoOp_ATS_Simulation_Configuration_WeakReach_axioms_inst_ATS_Simulation_Configuration_WeakRL_axioms: \"\n  ATS_Simulation_Configuration_WeakReach_axioms epda_step_labels epdaS_step_relation epdaS_configurations epda_step_labels epdaS_step_relation F_DPDA_RNE__relation_configuration__RL2 F_DPDA_RNE__relation_structure__RL2 F_DPDA_RNE__relation_step_simulation__RL2 RNoOpX_relation_labelsRL\"\n  apply(simp add: ATS_Simulation_Configuration_WeakReach_axioms_def)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_step_simulation__RL2_def)\n  apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G2 \\<inter> {e. FB_neutral_edge e}. e1 \\<in> F_DPDA_RNE__edge_then x (F_FRESH (epda_gamma G2))) \\<or> (\\<exists>x\\<in> epda_delta G2 \\<inter> {e. (\\<not> FB_neutral_edge e)}. e1 = F_DPDA_RNE__edge_else x)\")\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n   prefer 2\n   apply(simp add: F_DPDA_RNE__edge_then_1_def F_DPDA_RNE__relation_structure__RL2_def F_DPDA_RNE_def epda_step_labels_def)\n   apply(force)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n  apply(erule_tac\n      P=\"\\<exists>x\\<in> epda_delta G2 \\<inter> {e. FB_neutral_edge e}. e1 \\<in> F_DPDA_RNE__edge_then x (F_FRESH (epda_gamma G2))\"\n      in disjE)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' d2 n x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_else_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n   apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n   apply(simp add: der2_def RNoOpX_relation_labelsRL_def F_DPDA_DRE__revert_F_DPDA_RNE_def epda_step_labels_def)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n    apply(rule_tac\n      t=\"epda_delta G2\"\n      and s=\"epda_step_labels G2\"\n      in ssubst)\n     apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n     apply(simp add: epda_step_labels_def)\n    apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n    apply(rule_tac\n      i=\"Suc 0\"\n      in epdaS.belongs_step_labels)\n     apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n    apply(simp add: der2_def)\n   apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n   apply(rule disjI2)\n   apply(simp add: F_DPDA_RNE__edge_else_def F_DPDA_RNE__edge__RL2_def)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_def)\n   apply(erule disjE)\n    apply(rename_tac G1 G2 c1 e1 c1' d2 n x)(*strict*)\n    prefer 2\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c1' d2 n x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_2_def)\n    apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n    apply(simp add: der2_def RNoOpX_relation_labelsRL_def F_DPDA_DRE__revert_F_DPDA_RNE_def epda_step_labels_def)\n    apply(rule disjI1)\n    apply(simp add: F_DPDA_RNE__edge_then_def)\n    apply(rule disjI2)\n    apply(simp add: F_DPDA_RNE__edge_then_2_def)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_1_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n   apply(subgoal_tac \"n=0\")\n    apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"(der1 (F_DPDA_RNE__conf__RL2 c1))\"\n      in epdaS.maximum_of_domainUnique)\n      apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n     apply(rule der1_maximum_of_domain)\n    apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n x)(*strict*)\n  apply(simp add: F_DPDA_RNE__edge_then_def)\n  apply(erule disjE)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n x)(*strict*)\n   prefer 2\n   apply(simp add: F_DPDA_RNE__edge_then_2_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n   apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n   apply(simp add: der2_def RNoOpX_relation_labelsRL_def F_DPDA_DRE__revert_F_DPDA_RNE_def epda_step_labels_def)\n   apply(rule disjI1)\n   apply(simp add: F_DPDA_RNE__edge_then_def)\n   apply(rule disjI2)\n   apply(simp add: F_DPDA_RNE__edge_then_2_def)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c1' d2 n x)(*strict*)\n  apply(simp add: F_DPDA_RNE__edge_then_1_def)\n  apply(subgoal_tac \"n=0\")\n   apply(rename_tac G1 G2 c1 c1' d2 n x)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"(der1 (F_DPDA_RNE__conf__RL2 c1))\"\n      in epdaS.maximum_of_domainUnique)\n     apply(rename_tac G1 G2 c1 c1' d2 n x)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c1' d2 n x)(*strict*)\n    apply(rule der1_maximum_of_domain)\n   apply(rename_tac G1 G2 c1 c1' d2 n x)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c1' d2 n x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n  apply(subgoal_tac \"False\")\n   apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_configuration__RL2_def)\n  apply(clarsimp)\n  apply(thin_tac \"the (get_configuration (der1 (F_DPDA_RNE__conf__RL2 c1') 0)) = F_DPDA_RNE__conf__RL2 c1'\")\n  apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n  apply(thin_tac \"\\<lparr>edge_src = cons_state_or_edge_old (edge_src x), edge_event = None, edge_pop = edge_pop x, edge_push = F_FRESH (epda_gamma G2) # edge_pop x, edge_trg = cons_state_or_edge_new x\\<rparr> \\<in> epda_step_labels G1\")\n  apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n  apply(thin_tac \"maximum_of_domain (der1 (F_DPDA_RNE__conf__RL2 c1')) 0\")\n  apply(thin_tac \"epdaS.belongs G2 (der1 (F_DPDA_RNE__conf__RL2 c1'))\")\n  apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n  apply(thin_tac \"epdaS.derivation G2 (der1 (F_DPDA_RNE__conf__RL2 c1'))\")\n  apply(erule_tac\n      x=\"der2 (F_DPDA_RNE__conf__RL2 c1) x ((F_DPDA_RNE__conf__RL2 c1')\\<lparr>epdaS_conf_state:=edge_trg x\\<rparr>)\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n   apply(simp add: get_configuration_def der2_def der1_def)\n  apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n  apply(erule impE)\n   apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n   apply(rule epdaS.der2_is_derivation)\n   apply(simp add: epdaS_step_relation_def)\n   apply(simp add: F_DPDA_RNE__conf__RL2_def FB_neutral_edge_def)\n   apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n   apply(erule_tac\n      x=\"Suc 0\"\n      in allE)\n   apply(subgoal_tac \"maximum_of_domain (der2 (F_DPDA_RNE__conf__RL2 c1) x (F_DPDA_RNE__conf__RL2 c1'\\<lparr>epdaS_conf_state := edge_trg x\\<rparr>)) (Suc 0)\")\n    apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n   apply(rule der2_maximum_of_domain)\n  apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"Suc 0\"\n      in allE)\n  apply(erule_tac\n      x=\"x\"\n      in allE)\n  apply(erule disjE)\n   apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n   apply(simp add: der2_def)\n  apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n  apply(simp add: RNoOpX_relation_labelsRL_def)\n  apply(simp add: F_DPDA_DRE__revert_F_DPDA_RNE_def)\n  apply(simp add: F_DPDA_RNE__edge_then_def F_DPDA_RNE__edge_then_1_def)\n  done\n\ninterpretation \"epdaS_epdaS_RNoOp_StateSimRLX\" : ATS_Simulation_Configuration_WeakReach\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaS_configurations\"\n  (* initial_configurations1 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaS_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaS_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_DPDA_RNE__relation_configuration__RL2\"\n  (* relation_initial_configuration *)\n  \"F_DPDA_RNE__relation_initial_configuration__RL2\"\n  (* relation_effect *)\n  \"F_DPDA_RNE__relation_effect__RL2\"\n  (* relation_TSstructure *)\n  \"F_DPDA_RNE__relation_structure__RL2\"\n  (* relation_initial_simulation *)\n  \"F_DPDA_RNE__relation_initial_simulation__RL2\"\n  (* relation_step_simulation *)\n  \"F_DPDA_RNE__relation_step_simulation__RL2\"\n  (* relation_labelsRL *)\n  \"RNoOpX_relation_labelsRL\"\n  apply(simp add: LOCALE_DEFS epda_interpretations)\n  apply(simp add: epdaS_epdaS_RNoOp_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axiomsX RNoOp_ATS_Simulation_Configuration_WeakReach_axioms_inst_ATS_Simulation_Configuration_WeakRL_axioms)\n  done\n\ndefinition F_DPDA_RNE__SpecInput :: \"\n  ('state, 'event, 'stack) epda\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__SpecInput G \\<equiv>\n  valid_dpda G\n  \\<and> read_edges_seperated G\"\n\ndefinition F_DPDA_RNE__SpecOutput :: \"\n  ('stateA, 'event, 'stackA) epda\n  \\<Rightarrow> ('stateB, 'event, 'stackB) epda\n  \\<Rightarrow> bool\"\n  where\n    \"F_DPDA_RNE__SpecOutput Gi Go \\<equiv>\n  valid_dpda Go\n  \\<and> epdaS.marked_language Gi = epdaS.marked_language Go\n  \\<and> neutral_edges_removed Go\n  \\<and> read_edges_seperated Go\"\n\nlemma F_DPDA_RNE__SOUND: \"\n  F_DPDA_RNE__SpecInput G\n  \\<Longrightarrow> F_DPDA_RNE__SpecOutput G (F_DPDA_RNE G (F_FRESH (epda_gamma G)))\"\n  apply(simp add: F_DPDA_RNE__SpecInput_def F_DPDA_RNE__SpecOutput_def)\n  apply(rule context_conjI)\n   apply(rule F_DPDA_RNE__preserves_DPDA)\n   apply(force)\n  apply(rule conjI)\n   apply (rule F_DPDA_RNE__preserves_lang)\n   apply(force)\n  apply(rule context_conjI)\n   apply(rule F_DPDA_RNE__produces_neutral_edges_removed)\n    apply(force)\n   apply(rule F_FRESH_is_fresh)\n   apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  apply(rule F_DPDA_RNE__preserves_read_edges_seperated)\n    apply(force)\n   apply(force)\n  apply(rule F_FRESH_is_fresh)\n  apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n  done\n\nlemma F_DPDA_DRE__revert_F_DPDA_RNE_SOUND_scheduled_case: \"\n  F_DPDA_RNE__SpecInput G'\n  \\<Longrightarrow> F_DPDA_DRE__revert_F_DPDA_RNE G' (F_FRESH (epda_gamma G')) (epdaS_accessible_edges (F_DPDA_RNE (G') (F_FRESH (epda_gamma (G'))))) = epdaS_accessible_edges G'\"\n  apply(rule order_antisym)\n   apply(simp add: epdaS_accessible_edges_def)\n   apply(simp add: F_DPDA_DRE__revert_F_DPDA_RNE_def)\n   apply(clarsimp)\n   apply(rename_tac x p d n c)(*strict*)\n   prefer 2\n   apply(simp add: epdaS_accessible_edges_def)\n   apply(simp add: F_DPDA_DRE__revert_F_DPDA_RNE_def)\n   apply(clarsimp)\n   apply(rename_tac x d n c)(*strict*)\n   apply(subgoal_tac \"\\<exists>d2 n2 e2 c2. epdaS.derivation_initial SSG2 d2 \\<and> d2 n2 = Some (pair e2 c2) \\<and> (case SSe1 of None \\<Rightarrow> True | Some e1' \\<Rightarrow> \\<exists>k d2'. epdaS.derivation SSG2 d2' \\<and> the (get_configuration (d2' 0)) = the (get_configuration (d2 n2)) \\<and> (case get_label (derivation_append d2 d2' n2 k) of None \\<Rightarrow> False | Some e2' \\<Rightarrow> RNoOpX_relation_labelsLR SSG1 SSG2 e1' e2'))\" for SSe1 SSG1 SSG2)\n    apply(rename_tac x d n c)(*strict*)\n    prefer 2\n    apply(rule_tac\n      ?G1.0=\"G'\"\n      and ?d1.0=\"d\"\n      and ?G2.0=\"F_DPDA_RNE G' (F_FRESH (epda_gamma G'))\"\n      in epdaS_epdaS_RNoOp_StateSimLRX.ATS_Simulation_Configuration_WeakReach_exists)\n      apply(rename_tac x d n c)(*strict*)\n      apply(simp add: F_DPDA_RNE__relation_structure__LR2_def)\n      apply(simp add: F_DPDA_RNE__SpecInput_def)\n     apply(rename_tac x d n c)(*strict*)\n     apply(force)\n    apply(rename_tac x d n c)(*strict*)\n    apply(force)\n   apply(rename_tac x d n c)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x d n c d2 n2 e2 k c2 d2')(*strict*)\n   apply(case_tac \"(get_label (derivation_append d2 d2' n2 k))\")\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2')(*strict*)\n    apply(force)\n   apply(rename_tac x d n c d2 n2 e2 k c2 d2' a)(*strict*)\n   apply(clarsimp)\n   apply(simp add: get_label_def)\n   apply(rule_tac\n      x=\"a\"\n      in exI)\n   apply(simp add: RNoOpX_relation_labelsLR_def F_DPDA_DRE__revert_F_DPDA_RNE_def)\n   apply(case_tac \"derivation_append d2 d2' n2 k\")\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2' a)(*strict*)\n    apply(force)\n   apply(rename_tac x d n c d2 n2 e2 k c2 d2' a aa)(*strict*)\n   apply(clarsimp)\n   apply(case_tac aa)\n   apply(rename_tac x d n c d2 n2 e2 k c2 d2' a aa option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   apply(subgoal_tac \"\\<exists>c. d2' 0 = Some (pair None c)\")\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    prefer 2\n    apply (metis epdaS.some_position_has_details_at_0)\n   apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   apply(subgoal_tac \"epdaS.derivation_initial (F_DPDA_RNE G' (F_FRESH (epda_gamma G'))) (derivation_append d2 d2' n2)\")\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    prefer 2\n    apply(rule epdaS.derivation_append_preserves_derivation_initial)\n      apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n      apply(rule F_DPDA_RNE__preserves_epda)\n       apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n       apply(simp add: F_DPDA_RNE__SpecInput_def valid_dpda_def valid_pda_def)\n      apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n      apply(rule F_FRESH_is_fresh)\n      apply(simp add: F_DPDA_RNE__SpecInput_def valid_dpda_def valid_pda_def valid_epda_def)\n     apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n     apply(force)\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    apply(rule epdaS.derivation_append_preserves_derivation)\n      apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n      apply(rule epdaS.derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n     apply(force)\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b ca)(*strict*)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   apply(rule context_conjI)\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    apply(rule_tac\n      t=\"epda_delta (F_DPDA_RNE G' (F_FRESH (epda_gamma G')))\"\n      and s=\"epda_step_labels (F_DPDA_RNE G' (F_FRESH (epda_gamma G')))\"\n      in ssubst)\n     apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n     apply(simp add: epda_step_labels_def)\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    apply(rule_tac\n      i=\"k\"\n      and d=\"derivation_append d2 d2' n2\"\n      in epdaS.belongs_step_labels)\n     apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n     apply(rule epdaS.derivation_initial_belongs)\n      apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n      apply(rule F_DPDA_RNE__preserves_epda)\n       apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n       apply(simp add: F_DPDA_RNE__SpecInput_def valid_dpda_def valid_pda_def)\n      apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n      apply(rule F_FRESH_is_fresh)\n      apply(simp add: F_DPDA_RNE__SpecInput_def valid_dpda_def valid_pda_def valid_epda_def)\n     apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n     apply(force)\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    apply(force)\n   apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   apply(rule_tac\n      x=\"derivation_append d2 d2' n2\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    apply(force)\n   apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   apply(rule_tac\n      x=\"k\"\n      in exI)\n   apply(clarsimp)\n  apply(rename_tac x p d n c)(*strict*)\n  apply(subgoal_tac \"\\<exists>d2 n2 e2 c2. epdaS.derivation_initial SSG2 d2 \\<and> d2 n2 = Some (pair e2 c2) \\<and> (case SSe1 of None \\<Rightarrow> True | Some e1' \\<Rightarrow> \\<exists>k d2'. epdaS.derivation SSG2 d2' \\<and> the (get_configuration (d2' 0)) = the (get_configuration (d2 n2)) \\<and> (case get_label (derivation_append d2 d2' n2 k) of None \\<Rightarrow> False | Some e2' \\<Rightarrow> RNoOpX_relation_labelsRL SSG1 SSG2 e1' e2'))\" for SSG2 SSe1 SSG1)\n   apply(rename_tac x p d n c)(*strict*)\n   prefer 2\n   apply(rule_tac\n      ?G2.0=\"G'\"\n      and ?d1.0=\"d\"\n      and ?G1.0=\"F_DPDA_RNE G' (F_FRESH (epda_gamma G'))\"\n      in epdaS_epdaS_RNoOp_StateSimRLX.ATS_Simulation_Configuration_WeakReach_exists)\n     apply(rename_tac x p d n c)(*strict*)\n     apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n     apply(simp add: F_DPDA_RNE__SpecInput_def)\n    apply(rename_tac x p d n c)(*strict*)\n    apply(force)\n   apply(rename_tac x p d n c)(*strict*)\n   apply(force)\n  apply(rename_tac x p d n c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2')(*strict*)\n  apply(case_tac \"(get_label (derivation_append d2 d2' n2 k))\")\n   apply(rename_tac x p d n c d2 n2 e2 k c2 d2')(*strict*)\n   apply(force)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a)(*strict*)\n  apply(clarsimp)\n  apply(simp add: get_label_def)\n  apply(case_tac \"derivation_append d2 d2' n2 k\")\n   apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a)(*strict*)\n   apply(force)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a aa)(*strict*)\n  apply(clarsimp)\n  apply(case_tac aa)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a aa option b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n  apply(subgoal_tac \"\\<exists>c. d2' 0 = Some (pair None c)\")\n   apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   prefer 2\n   apply (metis epdaS.some_position_has_details_at_0)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b ca)(*strict*)\n  apply(simp add: get_configuration_def)\n  apply(clarsimp)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n  apply(subgoal_tac \"epdaS.derivation_initial G' (derivation_append d2 d2' n2)\")\n   apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   prefer 2\n   apply(rule epdaS.derivation_append_preserves_derivation_initial)\n     apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n     apply(simp add: F_DPDA_RNE__SpecInput_def valid_dpda_def valid_pda_def)\n    apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    apply(force)\n   apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   apply(rule epdaS.derivation_append_preserves_derivation)\n     apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n     apply(rule epdaS.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    apply(force)\n   apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n  apply(rule_tac\n      x=\"derivation_append d2 d2' n2\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   apply(force)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n  apply(rule_tac\n      x=\"k\"\n      in exI)\n  apply(clarsimp)\n  apply(simp add: RNoOpX_relation_labelsRL_def)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_DRE__revert_F_DPDA_RNE_def)\n  apply(clarsimp)\n  apply(erule_tac\n      P=\"p \\<in> F_DPDA_RNE__edge_then x (F_FRESH (epda_gamma G'))\"\n      in disjE)\n   apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   apply(erule disjE)\n    apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_def F_DPDA_RNE__edge_then_1_def F_DPDA_RNE__edge_then_2_def)\n    apply(erule_tac\n      P=\"p = \\<lparr>edge_src = cons_state_or_edge_old (edge_src x), edge_event = None, edge_pop = edge_pop x, edge_push = F_FRESH (epda_gamma G') # edge_pop x, edge_trg = cons_state_or_edge_new x\\<rparr>\"\n      in disjE)\n     apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    apply(erule disjE)\n     apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n     apply(clarsimp)\n    apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n    apply(clarsimp)\n   apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_def F_DPDA_RNE__edge_else_def)\n   apply(clarsimp)\n   apply(rename_tac x d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_def F_DPDA_RNE__edge_then_1_def F_DPDA_RNE__edge_then_2_def)\n  apply(rename_tac x p d n c d2 n2 e2 k c2 d2' a b)(*strict*)\n  apply(simp add: F_DPDA_RNE__edge_then_def F_DPDA_RNE__edge_else_def)\n  apply(simp add: F_DPDA_RNE__edge_then_def F_DPDA_RNE__edge_then_1_def F_DPDA_RNE__edge_then_2_def)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimLRRequired__inst__AX_relation_configuration_compatible_with_marking_configurations: \"\n(\\<forall>G1 G2.\n        F_DPDA_RNE__relation_structure__LR2 G1 G2 \\<longrightarrow>\n        (\\<forall>c1 c2.\n            F_DPDA_RNE__relation_configuration__LR2 G1 G2 c1 c2 \\<longrightarrow>\n            c1 \\<in> epdaS_marking_configurations G1 \\<longrightarrow> c2 \\<in> epdaS_marking_configurations G2))\"\n  apply(clarsimp)\n  apply(simp add: epdaS_marking_configurations_def)\n  apply(subgoal_tac \"c2 \\<in> epdaS_configurations G2\")\n   prefer 2\n   apply(simp add: F_DPDA_RNE__relation_configuration__LR2_def)\n   apply(clarsimp)\n   apply (metis F_DPDA_RNE__conf_old__LR2_preserves_configurations)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RNE__relation_structure__LR2_def F_DPDA_RNE_def F_DPDA_RNE__relation_configuration__LR2_def F_DPDA_RNE__conf_old__LR2_def)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimLRRequired__inst__AX_relation_step_simulation_no_reach_marking_with_empty_simulant: \"\n    (\\<forall>G1 G2.\n        F_DPDA_RNE__relation_structure__LR2 G1 G2 \\<longrightarrow>\n        (\\<forall>c1 c2.\n            F_DPDA_RNE__relation_configuration__LR2 G1 G2 c1 c2 \\<longrightarrow>\n            (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow>\n                  (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow>\n                         (\\<forall>d2. F_DPDA_RNE__relation_step_simulation__LR2 G1 G2 c1 e1 c1' c2\n                                d2 \\<longrightarrow>\n                               maximum_of_domain d2 0 \\<longrightarrow>\n                               c1' \\<notin> epdaS_marking_configurations G1)))))\"\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RNE__relation_step_simulation__LR2_def)\n  apply(case_tac \"FB_neutral_edge e1\")\n   apply(clarsimp)\n   apply(simp add: maximum_of_domain_def der1_def der2_def der3_def)\n  apply(simp add: maximum_of_domain_def der1_def der2_def der3_def)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimLRRequired__inst__AX_relation_step_simulationReach: \"\n    (\\<forall>G1 G2.\n        F_DPDA_RNE__relation_structure__LR2 G1 G2 \\<longrightarrow>\n        (\\<forall>c1 c2.\n            F_DPDA_RNE__relation_configuration__LR2 G1 G2 c1 c2 \\<longrightarrow>\n            (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow>\n                  (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow>\n                         (\\<forall>d2. epdaS.derivation G2 d2 \\<longrightarrow>\n                               epdaS.belongs G2 d2 \\<longrightarrow>\n                               the (get_configuration (d2 0)) = c2 \\<longrightarrow>\n                               F_DPDA_RNE__relation_step_simulation__LR2 G1 G2 c1 e1 c1' c2\n                                d2 \\<longrightarrow>\n                               (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow>\n                                    F_DPDA_RNE__relation_configuration__LR2 G1 G2 c1'\n                                     (the (get_configuration (d2 n))) \\<longrightarrow>\n                                    (\\<exists>k e2. (\\<exists>c2. d2 k = Some (pair (Some e2) c2)) \\<and>\n                                            RNoOpX_relation_labelsLR G1 G2 e1 e2) \\<or>\n                                    n = 0 \\<and>\n                                    (\\<exists>e2. Ex (epdaS_step_relation G2 c2 e2) \\<and>\n                                          RNoOpX_relation_labelsLR G1 G2 e1 e2)))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_step_simulation__LR2_def)\n  apply(case_tac \"FB_neutral_edge e1\")\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' n)(*strict*)\n   apply(simp add: RNoOpX_relation_labelsLR_def F_DPDA_DRE__revert_F_DPDA_RNE_def)\n   apply(rule_tac\n      x=\"1\"\n      in exI)\n   apply(simp add: der3_def epda_step_labels_def F_DPDA_RNE__edge_then_def)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1' n)(*strict*)\n  apply(simp add: RNoOpX_relation_labelsLR_def F_DPDA_DRE__revert_F_DPDA_RNE_def)\n  apply(rule_tac\n      x=\"1\"\n      in exI)\n  apply(simp add: der2_def epda_step_labels_def F_DPDA_RNE__edge_then_def)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimLRRequired__inst__ATS_Simulation_Configuration_WeakRequired_axioms: \"\nATS_Simulation_Configuration_WeakRequired_axioms epda_step_labels epdaS_step_relation\n     epdaS_configurations epda_step_labels epdaS_step_relation\n     F_DPDA_RNE__relation_configuration__LR2 F_DPDA_RNE__relation_structure__LR2\n     F_DPDA_RNE__relation_step_simulation__LR2 RNoOpX_relation_labelsLR\n     epdaS_marking_configurations epdaS_marking_configurations\"\n  apply(simp add: ATS_Simulation_Configuration_WeakRequired_axioms_def epdaS_epdaS_RNoOp_StateSimLRRequired__inst__AX_relation_step_simulationReach epdaS_epdaS_RNoOp_StateSimLRRequired__inst__AX_relation_step_simulation_no_reach_marking_with_empty_simulant epdaS_epdaS_RNoOp_StateSimLRRequired__inst__AX_relation_configuration_compatible_with_marking_configurations)\n  done\n\ninterpretation \"epdaS_epdaS_RNoOp_StateSimLRRequired\" : ATS_Simulation_Configuration_WeakRequired\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaS_configurations\"\n  (* initial_configurations1 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaS_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaS_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_DPDA_RNE__relation_configuration__LR2\"\n  (* relation_initial_configuration *)\n  \"F_DPDA_RNE__relation_initial_configuration__LR2\"\n  (* relation_effect *)\n  \"F_DPDA_RNE__relation_effect__LR2\"\n  (* relation_TSstructure *)\n  \"F_DPDA_RNE__relation_structure__LR2\"\n  (* relation_initial_simulation *)\n  \"F_DPDA_RNE__relation_initial_simulation__LR2\"\n  (* relation_step_simulation *)\n  \"F_DPDA_RNE__relation_step_simulation__LR2\"\n  (* relation_labelsLR *)\n  \"RNoOpX_relation_labelsLR\"\n  (* marking_configurations1 *)\n  \"epdaS_marking_configurations\"\n  (* marking_configurations2 *)\n  \"epdaS_marking_configurations\"\n  apply(simp add: LOCALE_DEFS epda_interpretations)\n  apply(simp add: epdaS_epdaS_RNoOp_StateSimLR_inst_ATS_Simulation_Configuration_Weak_axiomsX epdaS_epdaS_RNoOp_StateSimLRRequired__inst__ATS_Simulation_Configuration_WeakRequired_axioms)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimRLRequired__inst__AX_relation_configuration_compatible_with_marking_configurations: \"\n(\\<forall>G1 G2.\n        F_DPDA_RNE__relation_structure__RL2 G1 G2 \\<longrightarrow>\n        (\\<forall>c1 c2.\n            F_DPDA_RNE__relation_configuration__RL2 G1 G2 c1 c2 \\<longrightarrow>\n            c1 \\<in> epdaS_marking_configurations G1 \\<longrightarrow> c2 \\<in> epdaS_marking_configurations G2))\"\n  apply(clarsimp)\n  apply(simp add: epdaS_marking_configurations_def)\n  apply(subgoal_tac \"c2 \\<in> epdaS_configurations G2\")\n   prefer 2\n   apply(simp add: F_DPDA_RNE__relation_configuration__RL2_def)\n   apply(clarsimp)\n   apply (metis (full_types) F_DPDA_RNE__conf__RL2_preserves_configurationsX)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RNE__relation_structure__RL2_def F_DPDA_RNE_def F_DPDA_RNE__relation_configuration__RL2_def F_DPDA_RNE__conf__RL2_def)\n  apply(clarsimp)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimRLRequired__inst__AX_relation_step_simulation_no_reach_marking_with_empty_simulant: \"\n    (\\<forall>G1 G2.\n        F_DPDA_RNE__relation_structure__RL2 G1 G2 \\<longrightarrow>\n        (\\<forall>c1 c2.\n            F_DPDA_RNE__relation_configuration__RL2 G1 G2 c1 c2 \\<longrightarrow>\n            (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow>\n                  (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow>\n                         (\\<forall>d2. F_DPDA_RNE__relation_step_simulation__RL2 G1 G2 c1 e1 c1' c2\n                                d2 \\<longrightarrow>\n                               maximum_of_domain d2 0 \\<longrightarrow>\n                               c1' \\<notin> epdaS_marking_configurations G1)))))\"\n  apply(clarsimp)\n  apply(simp add: F_DPDA_RNE__relation_step_simulation__RL2_def)\n  apply(case_tac \"edge_trg e1\")\n   apply(clarsimp)\n   apply(case_tac \"edge_src e1\")\n    apply(clarsimp)\n    apply(simp add: maximum_of_domain_def der1_def der2_def der3_def)\n   apply(simp add: maximum_of_domain_def der1_def der2_def der3_def)\n  apply(clarsimp)\n  apply(simp add: maximum_of_domain_def der1_def der2_def der3_def)\n  apply(simp add: F_DPDA_RNE__relation_structure__RL2_def F_DPDA_RNE__relation_configuration__RL2_def F_DPDA_RNE_def epdaS_step_relation_def epdaS_marking_configurations_def)\n  apply(clarsimp)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimRLRequired__inst__AX_relation_step_simulationReach: \"\n    (\\<forall>G1 G2.\n        F_DPDA_RNE__relation_structure__RL2 G1 G2 \\<longrightarrow>\n        (\\<forall>c1 c2.\n            F_DPDA_RNE__relation_configuration__RL2 G1 G2 c1 c2 \\<longrightarrow>\n            (\\<forall>e1. e1 \\<in> epda_step_labels G1 \\<longrightarrow>\n                  (\\<forall>c1'. epdaS_step_relation G1 c1 e1 c1' \\<longrightarrow>\n                         (\\<forall>d2. epdaS.derivation G2 d2 \\<longrightarrow>\n                               epdaS.belongs G2 d2 \\<longrightarrow>\n                               the (get_configuration (d2 0)) = c2 \\<longrightarrow>\n                               F_DPDA_RNE__relation_step_simulation__RL2 G1 G2 c1 e1 c1' c2\n                                d2 \\<longrightarrow>\n                               (\\<forall>n. maximum_of_domain d2 n \\<longrightarrow>\n                                    F_DPDA_RNE__relation_configuration__RL2 G1 G2 c1'\n                                     (the (get_configuration (d2 n))) \\<longrightarrow>\n                                    (\\<exists>k e2. (\\<exists>c2. d2 k = Some (pair (Some e2) c2)) \\<and>\n                                            RNoOpX_relation_labelsRL G1 G2 e1 e2) \\<or>\n                                    n = 0 \\<and>\n                                    (\\<exists>e2. Ex (epdaS_step_relation G2 c2 e2) \\<and>\n                                          RNoOpX_relation_labelsRL G1 G2 e1 e2)))))))\"\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_step_simulation__RL2_def)\n  apply(subgoal_tac \"(\\<exists>x\\<in> epda_delta G2 \\<inter> {e. FB_neutral_edge e}. e1 \\<in> F_DPDA_RNE__edge_then x (F_FRESH (epda_gamma G2))) \\<or> (\\<exists>x\\<in> epda_delta G2 \\<inter> {e. (\\<not> FB_neutral_edge e)}. e1 = F_DPDA_RNE__edge_else x)\")\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n   prefer 2\n   apply(simp add: F_DPDA_RNE__edge_then_1_def F_DPDA_RNE__relation_structure__RL2_def F_DPDA_RNE_def epda_step_labels_def)\n   apply(force)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n  apply(erule_tac\n      P=\"\\<exists>x\\<in> epda_delta G2 \\<inter> {e. FB_neutral_edge e}. e1 \\<in> F_DPDA_RNE__edge_then x (F_FRESH (epda_gamma G2))\"\n      in disjE)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n   prefer 2\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' d2 n x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_else_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n   apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n   apply(simp add: der2_def RNoOpX_relation_labelsRL_def F_DPDA_DRE__revert_F_DPDA_RNE_def epda_step_labels_def)\n   apply(rule conjI)\n    apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n    apply(rule_tac\n      t=\"epda_delta G2\"\n      and s=\"epda_step_labels G2\"\n      in ssubst)\n     apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n     apply(simp add: epda_step_labels_def)\n    apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n    apply(rule_tac\n      i=\"Suc 0\"\n      in epdaS.belongs_step_labels)\n     apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n    apply(simp add: der2_def)\n   apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n   apply(rule disjI2)\n   apply(simp add: F_DPDA_RNE__edge_else_def F_DPDA_RNE__edge__RL2_def)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n  apply(erule disjE)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_def)\n   apply(erule disjE)\n    apply(rename_tac G1 G2 c1 e1 c1' d2 n x)(*strict*)\n    prefer 2\n    apply(clarsimp)\n    apply(rename_tac G1 G2 c1 c1' d2 n x)(*strict*)\n    apply(simp add: F_DPDA_RNE__edge_then_2_def)\n    apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n    apply(simp add: der2_def RNoOpX_relation_labelsRL_def F_DPDA_DRE__revert_F_DPDA_RNE_def epda_step_labels_def)\n    apply(rule disjI1)\n    apply(simp add: F_DPDA_RNE__edge_then_def)\n    apply(rule disjI2)\n    apply(simp add: F_DPDA_RNE__edge_then_2_def)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n x)(*strict*)\n   apply(simp add: F_DPDA_RNE__edge_then_1_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n   apply(subgoal_tac \"n=0\")\n    apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n    prefer 2\n    apply(rule_tac\n      d=\"(der1 (F_DPDA_RNE__conf__RL2 c1))\"\n      in epdaS.maximum_of_domainUnique)\n      apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n      apply(force)\n     apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n     apply(rule der1_maximum_of_domain)\n    apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n    apply(force)\n   apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n x)(*strict*)\n  apply(simp add: F_DPDA_RNE__edge_then_def)\n  apply(erule disjE)\n   apply(rename_tac G1 G2 c1 e1 c1' d2 n x)(*strict*)\n   prefer 2\n   apply(simp add: F_DPDA_RNE__edge_then_2_def)\n   apply(clarsimp)\n   apply(rename_tac G1 G2 c1 c1' n x)(*strict*)\n   apply(rule_tac\n      x=\"Suc 0\"\n      in exI)\n   apply(simp add: der2_def RNoOpX_relation_labelsRL_def F_DPDA_DRE__revert_F_DPDA_RNE_def epda_step_labels_def)\n   apply(rule disjI1)\n   apply(simp add: F_DPDA_RNE__edge_then_def)\n   apply(rule disjI2)\n   apply(simp add: F_DPDA_RNE__edge_then_2_def)\n  apply(rename_tac G1 G2 c1 e1 c1' d2 n x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c1' d2 n x)(*strict*)\n  apply(simp add: F_DPDA_RNE__edge_then_1_def)\n  apply(subgoal_tac \"n=0\")\n   apply(rename_tac G1 G2 c1 c1' d2 n x)(*strict*)\n   prefer 2\n   apply(rule_tac\n      d=\"(der1 (F_DPDA_RNE__conf__RL2 c1))\"\n      in epdaS.maximum_of_domainUnique)\n     apply(rename_tac G1 G2 c1 c1' d2 n x)(*strict*)\n     apply(force)\n    apply(rename_tac G1 G2 c1 c1' d2 n x)(*strict*)\n    apply(rule der1_maximum_of_domain)\n   apply(rename_tac G1 G2 c1 c1' d2 n x)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c1' d2 n x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n  apply(subgoal_tac \"False\")\n   apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n   apply(force)\n  apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n  apply(simp add: F_DPDA_RNE__relation_configuration__RL2_def)\n  apply(clarsimp)\n  apply(thin_tac \"the (get_configuration (der1 (F_DPDA_RNE__conf__RL2 c1') 0)) = F_DPDA_RNE__conf__RL2 c1'\")\n  apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n  apply(thin_tac \"\\<lparr>edge_src = cons_state_or_edge_old (edge_src x), edge_event = None, edge_pop = edge_pop x, edge_push = F_FRESH (epda_gamma G2) # edge_pop x, edge_trg = cons_state_or_edge_new x\\<rparr> \\<in> epda_step_labels G1\")\n  apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n  apply(thin_tac \"maximum_of_domain (der1 (F_DPDA_RNE__conf__RL2 c1')) 0\")\n  apply(thin_tac \"epdaS.belongs G2 (der1 (F_DPDA_RNE__conf__RL2 c1'))\")\n  apply(rename_tac G1 G2 c1 c1' x)(*strict*)\n  apply(thin_tac \"epdaS.derivation G2 (der1 (F_DPDA_RNE__conf__RL2 c1'))\")\n  apply(erule_tac x=\"x\" in allE)\n  apply(erule disjE)\n   apply(erule_tac x=\"((F_DPDA_RNE__conf__RL2 c1')\\<lparr>epdaS_conf_state:=edge_trg x\\<rparr>)\" in allE)\n   apply(simp add: F_DPDA_RNE__conf__RL2_def FB_neutral_edge_def)\n   apply(simp add: epdaS_step_relation_def)\n  apply(simp add: RNoOpX_relation_labelsRL_def)\n  apply(simp add: F_DPDA_DRE__revert_F_DPDA_RNE_def)\n  apply(simp add: F_DPDA_RNE__edge_then_def F_DPDA_RNE__edge_then_1_def)\n  done\n\nlemma epdaS_epdaS_RNoOp_StateSimRLRequired__inst__ATS_Simulation_Configuration_WeakRequired_axioms: \"\nATS_Simulation_Configuration_WeakRequired_axioms epda_step_labels epdaS_step_relation\n     epdaS_configurations epda_step_labels epdaS_step_relation\n     F_DPDA_RNE__relation_configuration__RL2 F_DPDA_RNE__relation_structure__RL2\n     F_DPDA_RNE__relation_step_simulation__RL2 RNoOpX_relation_labelsRL\n     epdaS_marking_configurations epdaS_marking_configurations\"\n  apply(simp add: ATS_Simulation_Configuration_WeakRequired_axioms_def\n      epdaS_epdaS_RNoOp_StateSimRLRequired__inst__AX_relation_configuration_compatible_with_marking_configurations\n      epdaS_epdaS_RNoOp_StateSimRLRequired__inst__AX_relation_step_simulation_no_reach_marking_with_empty_simulant\n      epdaS_epdaS_RNoOp_StateSimRLRequired__inst__AX_relation_step_simulationReach\n      )\n  done\n\ninterpretation \"epdaS_epdaS_RNoOp_StateSimRLRequired\" : ATS_Simulation_Configuration_WeakRequired\n  (* TSstructure1 *)\n  \"valid_epda\"\n  (* configurations1 *)\n  \"epdaS_configurations\"\n  (* initial_configurations1 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels1 *)\n  \"epda_step_labels\"\n  (* step_relation1 *)\n  \"epdaS_step_relation\"\n  (* effects1 *)\n  \"epda_effects\"\n  (* marking_condition1 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect1 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect1 *)\n  \"epdaS_unmarked_effect\"\n  (* TSstructure2 *)\n  \"valid_epda\"\n  (* configurations2 *)\n  \"epdaS_configurations\"\n  (* initial_configurations2 *)\n  \"epdaS_initial_configurations\"\n  (* step_labels2 *)\n  \"epda_step_labels\"\n  (* step_relation2 *)\n  \"epdaS_step_relation\"\n  (* effects2 *)\n  \"epda_effects\"\n  (* marking_condition2 *)\n  \"epdaS_marking_condition\"\n  (* marked_effect2 *)\n  \"epdaS_marked_effect\"\n  (* unmarked_effect2 *)\n  \"epdaS_unmarked_effect\"\n  (* relation_configuration *)\n  \"F_DPDA_RNE__relation_configuration__RL2\"\n  (* relation_initial_configuration *)\n  \"F_DPDA_RNE__relation_initial_configuration__RL2\"\n  (* relation_effect *)\n  \"F_DPDA_RNE__relation_effect__RL2\"\n  (* relation_TSstructure *)\n  \"F_DPDA_RNE__relation_structure__RL2\"\n  (* relation_initial_simulation *)\n  \"F_DPDA_RNE__relation_initial_simulation__RL2\"\n  (* relation_step_simulation *)\n  \"F_DPDA_RNE__relation_step_simulation__RL2\"\n  (* relation_labelsRL *)\n  \"RNoOpX_relation_labelsRL\"\n  (* marking_configurations1 *)\n  \"epdaS_marking_configurations\"\n  (* marking_configurations2 *)\n  \"epdaS_marking_configurations\"\n  apply(simp add: LOCALE_DEFS epda_interpretations)\n  apply(simp add: epdaS_epdaS_RNoOp_StateSimRL_inst_ATS_Simulation_Configuration_Weak_axiomsX epdaS_epdaS_RNoOp_StateSimRLRequired__inst__ATS_Simulation_Configuration_WeakRequired_axioms)\n  done\n\nlemma F_DPDA_DRE__revert_F_DPDA_RNE_SOUND_scheduled_case_epdaS_required_edges: \"\n  F_DPDA_RNE__SpecInput G'\n  \\<Longrightarrow> F_DPDA_DRE__revert_F_DPDA_RNE G' (F_FRESH (epda_gamma G')) (epdaS_required_edges (F_DPDA_RNE (G') (F_FRESH (epda_gamma (G'))))) = epdaS_required_edges G'\"\n  apply(rule order_antisym)\n   apply(simp add: epdaS_required_edges_def)\n   apply(clarsimp)\n   apply(simp add: F_DPDA_DRE__revert_F_DPDA_RNE_def)\n   apply(clarsimp)\n   apply(subgoal_tac \"\\<exists>m. n+m=k\")\n    prefer 2\n    apply(rule_tac x=\"k-n\" in exI)\n    apply(force)\n   apply(clarsimp)\n   apply(subgoal_tac \"X\" for X)\n    prefer 2\n    apply(rule_tac ?G1.0=\"F_DPDA_RNE G' (F_FRESH (epda_gamma G'))\" and ?G2.0=\"G'\" and ?n1'=\"n+m\" in epdaS_epdaS_RNoOp_StateSimRLRequired.ATS_Simulation_Configuration_WeakRequired_exists_ALT)\n          apply(simp add: F_DPDA_RNE__relation_structure__RL2_def)\n          apply(simp add: F_DPDA_RNE__SpecInput_def)\n         apply(simp add: F_DPDA_RNE__SpecInput_def)\n         apply(clarsimp)\n         apply (metis epdaS.is_forward_deterministic_accessible_def epdaS_dependency_between_determinism_properties valid_dpda_def valid_pda_def)\n        apply(force)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(clarsimp)\n   apply(rule_tac x=\"d2\" in exI)\n   apply(clarsimp)\n   apply(rule_tac x=\"n2\" in exI)\n   apply(clarsimp)\n   apply(simp add: RNoOpX_relation_labelsRL_def)\n   apply(simp add: F_DPDA_DRE__revert_F_DPDA_RNE_def)\n   apply(clarsimp)\n   apply(rule conjI)\n    prefer 2\n    apply(rule_tac x=\"n2'\" in exI)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RNE__relation_configuration__RL2_def epdaS_marking_configurations_def)\n    apply(subgoal_tac \"X\" for X)\n     prefer 2\n     apply(rule_tac ?c1.0=\"ca\" in\n      F_DPDA_RNE__conf__RL2_preserves_configurationsX)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RNE__conf__RL2_def F_DPDA_RNE_def)\n    apply(case_tac \"epdaS_conf_state ca\")\n     apply(clarsimp)\n    apply(clarsimp)\n   apply(simp add: F_DPDA_RNE_def)\n   apply(erule disjE)\n    apply(clarsimp)\n    apply(simp add: F_DPDA_RNE__SpecInput_def F_DPDA_RNE__edge_then_def F_DPDA_RNE__edge_then_1_def F_DPDA_RNE__edge_then_2_def F_DPDA_RNE__edge_else_def epdaS_marking_configurations_def F_DPDA_RNE__relation_structure__RL2_def F_DPDA_RNE_def F_DPDA_RNE__relation_configuration__RL2_def FB_neutral_edge_def epdaS_configurations_def)\n    apply(clarsimp)\n    apply(force)\n   apply(simp add: F_DPDA_RNE__SpecInput_def F_DPDA_RNE__edge_then_def F_DPDA_RNE__edge_then_1_def F_DPDA_RNE__edge_then_2_def F_DPDA_RNE__edge_else_def epdaS_marking_configurations_def F_DPDA_RNE__relation_structure__RL2_def F_DPDA_RNE_def F_DPDA_RNE__relation_configuration__RL2_def FB_neutral_edge_def epdaS_configurations_def)\n  apply(clarsimp)\n  apply(simp add: epdaS_required_edges_def)\n  apply(clarsimp)\n  apply(simp add: F_DPDA_DRE__revert_F_DPDA_RNE_def)\n  apply(subgoal_tac \"\\<exists>m. n+m=k\")\n   prefer 2\n   apply(rule_tac x=\"k-n\" in exI)\n   apply(force)\n  apply(clarsimp)\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule_tac ?G2.0=\"F_DPDA_RNE G' (F_FRESH (epda_gamma G'))\" and ?G1.0=\"G'\" and ?n1'=\"n+m\" in epdaS_epdaS_RNoOp_StateSimLRRequired.ATS_Simulation_Configuration_WeakRequired_exists_ALT)\n         apply(simp add: F_DPDA_RNE__relation_structure__LR2_def)\n         apply(simp add: F_DPDA_RNE__SpecInput_def)\n        apply(simp add: F_DPDA_RNE__SpecInput_def)\n        apply(clarsimp)\n        apply(simp add: epdaS.is_forward_deterministic_accessible_def)\n        apply(rule conjI)\n         prefer 2\n         apply(rule F_DPDA_RNE__preserves_is_forward_edge_deterministic_accessible)\n         apply(force)\n        apply(rule epdaS_is_forward_target_deterministic_accessible)\n       apply(force)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(rule_tac x=\"e2\" in exI)\n  apply(rule conjI)\n   apply(rule_tac\n      t=\"epda_delta SSX\" \n      and s=\"epda_step_labels SSX\" for SSX\n      in ssubst)\n    apply(simp add: epda_step_labels_def)\n   apply(rule_tac\n      i=\"n2\" and d=\"d2\"\n      in epdaS.belongs_step_labels)\n    prefer 2\n    apply(force)\n   apply(rule epdaS.derivation_initial_belongs)\n    apply(rule F_DPDA_RNE__preserves_epda)\n     apply(simp add: F_DPDA_RNE__SpecInput_def)\n    apply(simp add: F_DPDA_RNE__SpecInput_def)\n    apply(rule F_FRESH_is_fresh)\n    apply(simp add: valid_dpda_def valid_pda_def valid_epda_def)\n   apply(force)\n  apply(rule conjI)\n   apply(rule_tac x=\"d2\" in exI)\n   apply(clarsimp)\n   apply(rule_tac x=\"n2\" in exI)\n   apply(clarsimp)\n   apply(rule_tac x=\"n2'\" in exI)\n   apply(clarsimp)\n   apply (metis (erased, hide_lams) F_DPDA_RNE__relation_configuration__LR2_def epdaS_epdaS_RNoOp_StateSimLRRequired.AX_relation_configuration_compatible_with_marking_configurations)\n  apply(simp add: RNoOpX_relation_labelsLR_def F_DPDA_DRE__revert_F_DPDA_RNE_def)\n  done\n\nend\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_12_04_04_02/FUNCTION__DPDA_RNE__DPDA_REMOVE_NEUTRAL_EDGES.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621765008857981, "lm_q2_score": 0.45713671682749485, "lm_q1q2_score": 0.25699151989250296}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory word_abs_options imports \"AutoCorres.AutoCorres\" begin\n\nexternal_file \"word_abs_options.c\"\ninstall_C_file \"word_abs_options.c\"\n\nautocorres [\n  ts_rules = nondet,\n  unsigned_word_abs = usum2, no_signed_word_abs = isum1\n  ] \"word_abs_options.c\"\n\ncontext word_abs_options begin\n\nlemma \"\\<lbrace> \\<top> \\<rbrace> isum1' (a :: sword32) (b :: sword32) \\<lbrace> \\<lambda>r _. r = a + b \\<rbrace>\"\n  unfolding isum1'_def\n  apply (wp refl)\n  done\n\nlemma \"\\<lbrace> \\<top> \\<rbrace> isum2' (a :: int) (b :: int) \\<lbrace> \\<lambda>r _. r = a + b \\<rbrace>\"\n  unfolding isum2'_def\n  apply (wp refl)\n  done\n\nlemma \"\\<lbrace> \\<top> \\<rbrace> usum1' (a :: word32) (b :: word32) \\<lbrace> \\<lambda>r _. r = a + b \\<rbrace>\"\n  unfolding usum1'_def\n  apply (wp refl)\n  done\n\nlemma \"\\<lbrace> \\<top> \\<rbrace> usum2' (a :: nat) (b :: nat) \\<lbrace> \\<lambda>r _. r = a + b \\<rbrace>\"\n  unfolding usum2'_def\n  apply (wp refl)\n  done\n\nend\n\nend\n", "meta": {"author": "NICTA", "repo": "l4v", "sha": "3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b", "save_path": "github-repos/isabelle/NICTA-l4v", "path": "github-repos/isabelle/NICTA-l4v/l4v-3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b/tools/autocorres/tests/proof-tests/word_abs_options.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.476579651063676, "lm_q1q2_score": 0.25686843524451275}}
{"text": "theory Theorem611\n  imports Complex_Main LearningTheory\nbegin\n\ntext \"This document contains a collection of (mostly failed) attempts at gathering subproofs and\n  important lemmata for theorem 6.11. It may help proving the theorem in the future and serves\n  no other purpose.\"\n\n\n (*measure_pmf.jensens_inequality*)\n\nlemma \"AE x in measure_pmf M. X' x \\<in> UNIV\"\n  by simp\n\nlemma \"convex_on UNIV abs\"\nunfolding convex_on_def\n  apply (simp)\n  by (metis (mono_tags, hide_lams) abs_mult abs_of_nonneg abs_triangle_ineq add.commute mult.commute)\n\nlemma \"integrable (measure_pmf M) abs\"\n  oops\n\n(*for lemma A.3*)\nlemma \"measure_pmf.expectation p (abs \\<circ> f)\n   \\<le> infsetsum (\\<lambda>i. (a::real) * (Suc i) * (measure_pmf.prob p {x. (abs \\<circ> f) x > a * i})) UNIV\"\n  oops\n\nlemma \"abs (infsetsum f A) \\<le> infsetsum (abs \\<circ> f) A\"\n  oops\n\n\n\n\nlemma \"\\<forall>x. f x \\<in> {-1<..<1::real} \\<Longrightarrow> f \\<in> borel_measurable borel\"\n  oops\n\n\nlemma \"\\<forall>x. f x \\<in> {-1<..<1::real} \\<Longrightarrow> simple_function (measure_pmf M) f\"\n  oops\n\nlemma \"\\<forall>x. f x \\<in> {-1<..<1} \\<Longrightarrow> integrable (measure_pmf M) f\"\n  oops\n\nlemma \"emeasure (measure_pmf M) {(y::real) \\<in> space M. id y \\<noteq> 0} \\<noteq> \\<infinity>\"\n  by simp \n\nlemma \"integrable (measure_pmf M) (id::(real\\<Rightarrow>real))\" \n  oops\n\nlemma if_summable: \"f abs_summable_on A \\<Longrightarrow> (\\<lambda>x. if P x then f x else 0) abs_summable_on A\"\n  by (simp add: abs_summable_on_comparison_test)\n\nlemma \"(\\<lambda>x. if h x \\<noteq> f x then pmf D x else 0) abs_summable_on A\"\n  using pmf_abs_summable[of \"D\"] if_summable[of \"pmf D\"] by auto\n\nlemma exp_to_prob: \"measure_pmf.expectation pr (\\<lambda>x. if P x then 1::real else 0)\n     = measure_pmf.prob pr {x. P x}\"\nproof -\n  have \"measure_pmf.expectation pr (\\<lambda>x. if P x then 1::real else 0)\n      = infsetsum (\\<lambda>x. if P x then pmf pr x else 0) UNIV\"\n    by (smt infsetsum_cong mult_cancel_left2 mult_not_zero pmf_expectation_eq_infsetsum)\n  also have \"... = ... - infsetsum (\\<lambda>x. if P x then pmf pr x else 0) {x. \\<not> P x}\"\n    by (smt infsetsum_all_0 mem_Collect_eq)\n  also have \"... = infsetsum (\\<lambda>x. if P x then pmf pr x else 0) (UNIV - {x. \\<not> P x})\"\n    by (simp add: if_summable infsetsum_Diff pmf_abs_summable)\n  also have \"... = infsetsum (\\<lambda>x. if P x then pmf pr x else 0) {x. P x}\"\n  proof -\n    have \"UNIV - {x. \\<not> P x} = {x. P x}\"\n      by blast\n    then show ?thesis by auto\n  qed \n  also have \"... = infsetsum (pmf pr) {x. P x}\"\n    by (smt infsetsum_cong mem_Collect_eq)\n  finally show ?thesis\n    by (simp add: measure_pmf_conv_infsetsum) \nqed\n\nlemma \"((g:: 'c \\<Rightarrow> real) y) * measure_pmf.expectation D f = measure_pmf.expectation D (\\<lambda>x. (g y) * f x)\"\n   by simp\n\nlemma \"measure_pmf.expectation D f - (a::real) = measure_pmf.expectation D (\\<lambda>x. f x - a)\"\nproof -\n  have \"measure_pmf.expectation D f - (a::real) = (\\<Sum>\\<^sub>ax. pmf D x * f x) - (\\<Sum>\\<^sub>ax. pmf D x * a)\"\n    using pmf_expectation_eq_infsetsum infsetsum_pmf_eq_1\n  proof -\n    have \"\\<forall>p. integral\\<^sup>L (count_space (UNIV::'c set)) (pmf p) = 1\"\n      by (metis (no_types) infsetsum_def measure_pmf_UNIV measure_pmf_conv_infsetsum)\n    then show ?thesis sorry\n  qed \n  show ?thesis sorry\nqed\n\n\nlemma assumes \"card I > 0\"\n          and \"(\\<lambda>x. pmf D x * f x) abs_summable_on UNIV\"\n  shows stichprobenmittel: \"measure_pmf.expectation (Pi_pmf I undefined (\\<lambda>_. D)) (\\<lambda>S. sum (f \\<circ> S) I / card I)\n     = measure_pmf.expectation D f\"\nproof -\n(*\n  have \"measure_pmf.expectation (Pi_pmf I undefined (\\<lambda>_. D)) (\\<lambda>S. sum (f \\<circ> S) I / card I)\n      = sum (\\<lambda>_.(measure_pmf.expectation D f)) I / card I\"\n    *)\n  have \"i\\<notin>I \\<Longrightarrow> sum (f \\<circ> S) (insert i I) / (card I + 1) \n      = sum (f \\<circ> S) I / (card I + 1) + (f \\<circ> S) i / (card I + 1)\"\n    sorry\n   (* by (metis add.commute add_divide_distrib assms card.infinite not_less0 sum.insert_if) *)\n      \n  have \"measure_pmf.expectation (Pi_pmf (insert i I) undefined (\\<lambda>_. D)) (\\<lambda>S. sum (f \\<circ> S) (insert i I) / (card I + 1))\n      = measure_pmf.expectation (Pi_pmf (insert i I) undefined (\\<lambda>_. D)) (\\<lambda>S. sum (f \\<circ> S) I / (card I + 1) + f (S i) / (card I + 1))\"\n    \n    sorry\n    show ?thesis sorry\nqed\n\nlemma assumes \"card I > 0\"\n  shows \"measure_pmf.expectation (Pi_pmf I undefined (\\<lambda>_. D)) (\\<lambda>S. sum (\\<lambda>i. if h (S i) \\<noteq> f (S i) then 1::real else 0) I / card I)\n     = measure_pmf.expectation D (\\<lambda>x. if h x \\<noteq> f x then 1::real else 0)\"\n  sorry\n\n(*for Jensens*)\nlemma \"abs (measure_pmf.expectation p f) \\<le> measure_pmf.expectation p (abs \\<circ> f)\"\n  using pmf_expectation_eq_infsetsum abs_triangle_ineq sorry\n\n(*Theorem 6.11*)\nlemma assumes \"set_pmf D \\<subseteq> X\"\n      and \"f ` X = Y\"\n      and \"\\<delta>\\<in>{x.0<x\\<and>x<1}\"\n    shows theorem611: \"measure_pmf.prob (Samples m D f) {S. \\<forall>h\\<in>H. abs(PredErr D f h - TrainErr S {0..<m} h)\n                   \\<le> (4+sqrt(ln(real(growth (2*m)))))/(\\<delta> * sqrt(2*m))} \\<ge> 1 - \\<delta>\"\nproof -\n  (* replace max with sup? *)\n  have \"measure_pmf.expectation (Samples m D f) (\\<lambda>S. (Max(image (\\<lambda>h. abs(PredErr D f h - TrainErr S {0..<m} h)) H)))\n        \\<le> (4+sqrt(ln(real(growth (2*m)))))/(\\<delta> * sqrt(2*m))\" sorry\n (* have \"\\<forall>h\\<in>H. measure_pmf.expectation D (\\<lambda>x. if h x \\<noteq> f x then 1::real else 0) = (\\<Sum>\\<^sub>ax. pmf D x * (\\<lambda>x. if h x \\<noteq> f x then 1::real else 0) x)\"\n    using pmf_expectation_eq_infsetsum by auto\n  have \"\\<forall>h\\<in>H. (\\<Sum>\\<^sub>ax. pmf D x * (\\<lambda>x. if h x \\<noteq> f x then 1::real else 0) x) = (\\<Sum>\\<^sub>ax. (if h x \\<noteq> f x then pmf D x else 0))\"\n    by (smt infsetsum_cong mult_cancel_left1 mult_cancel_right1)\n  have \"\\<forall>h A.(\\<lambda>x. if h x \\<noteq> f x then pmf D x else 0) abs_summable_on A\"\n    using pmf_abs_summable[of \"D\"] if_summable[of \"pmf D\"] by auto\n  then have \"\\<forall>h\\<in>H. infsetsum (\\<lambda>x. if h x \\<noteq> f x then pmf D x else 0) (UNIV - {x. h x = f x})\n        = (\\<Sum>\\<^sub>ax. (if h x \\<noteq> f x then pmf D x else 0)) - infsetsum (\\<lambda>x. if h x \\<noteq> f x then pmf D x else 0) {x. h x = f x}\"\n    by (simp add: infsetsum_Diff)\n  have \"\\<forall>h\\<in>H. infsetsum (\\<lambda>x. if h x \\<noteq> f x then pmf D x else 0) {x. h x = f x} = 0\"\n    by (smt infsetsum_all_0 mem_Collect_eq)\n  have \"\\<forall>h\\<in>H. infsetsum (\\<lambda>x. if h x \\<noteq> f x then pmf D x else 0) (UNIV - {x. h x = f x}) = infsetsum (pmf D) {x. h x \\<noteq> f x}\"\n    by (smt Diff_iff UNIV_I infsetsum_Diff infsetsum_all_0 infsetsum_cong infsetsum_def mem_Collect_eq pmf_abs_summable subsetI)\n      \n*)fix h I\n  have \"PredErr D f h = measure_pmf.expectation D (\\<lambda>x. if h x \\<noteq> f x then 1::real else 0)\"\n    unfolding PredErr_def using exp_to_prob[of D \"(\\<lambda>x. h x \\<noteq> f x)\"]\n    by (smt Collect_cong)\n  moreover assume \"card I > 0\"\n  moreover have \"(\\<lambda>x. pmf D x * (\\<lambda>x. if h x \\<noteq> f x then 1::real else 0) x) abs_summable_on UNIV\"\n    using pmf_abs_summable[of \"D\"] if_summable[of \"pmf D\"]\n    by (smt abs_summable_on_comparison_test mult_cancel_left1 mult_not_zero zero_less_norm_iff)\n  ultimately have \"measure_pmf.expectation (Pi_pmf I undefined (\\<lambda>_. D))\n              (\\<lambda>S. sum (\\<lambda>i. if h (S i) \\<noteq> f (S i) then 1::real else 0) I / card I)\n               = PredErr D f h\"\n    using stichprobenmittel by auto\n  have \"\\<forall>h\\<in>H. (PredErr D f h) = measure_pmf.expectation (Samples m D f) (\\<lambda>S. TrainErr S {0..m} h)\"\n    unfolding PredErr_def TrainErr_def Samples_def \n    sorry\n  show ?thesis sorry\nqed\n", "meta": {"author": "Quickblink", "repo": "verML", "sha": "bb7d4d1e154efb0e5464aa0a41a89f0411a6a0f8", "save_path": "github-repos/isabelle/Quickblink-verML", "path": "github-repos/isabelle/Quickblink-verML/verML-bb7d4d1e154efb0e5464aa0a41a89f0411a6a0f8/Theorem611.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.25686843524451275}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2004         |\n            |                  April 2005               |\n            |                   June 2005  (modified)   |\n            |              September 2005  (modified)   |\n            |                                           |\n            |        CSP-Prover on Isabelle2005         |\n            |               November 2005  (modified)   |\n            |                  April 2006  (modified)   |\n            |                  March 2007  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory CSP_F_op_alpha_par\nimports CSP_F_domain CSP_T_op_alpha_par\nbegin\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite (notick | t = <>)                  *)\n(*                                                                     *)\n(*                  disj_not1: (~ P | Q) = (P --> Q)                   *)\n\ndeclare disj_not1 [simp del]\n\n(*********************************************************\n             Alphabetized Parallel eval\n *********************************************************)\n\nlemma in_failures_Parallel_SKIP_lm1: \n  \"[| Y - insert Tick (Ev ` X) = Z - insert Tick (Ev ` X) ; \n     (Tick ~: Z | Z <= Evset) |]\n   ==> Z - Y <= Ev ` X\"\nby (auto simp add: Evset_def)\n\nlemma in_failures_Parallel_SKIP_lm2: \n  \"Y - insert Tick (Ev ` X) = Z - insert Tick (Ev ` X)  \n   ==> Z - insert Tick Y <= Ev ` X\"\nby (auto)\n\n(* Para SKIP *)\n\nlemma in_failures_Parallel_SKIP:\n  \"(f :f failures(P |[X]| SKIP) M) = \n   (EX u Y Z. f = (u, Y Un Z) & (u, Y) :f failures(P) M & \n              sett(u) Int (Ev ` X) = {} & Z <= Ev ` X)\"\napply (simp add: in_failures)\napply (rule iffI)\n\n(* => *)\n apply (elim conjE exE)\n apply (erule disjE)\n\n (* t = <> *)\n  apply (simp add: par_tr_nil)\n  apply (elim conjE, simp)\n  apply (rule_tac x=\"Y\" in exI)\n  apply (rule_tac x=\"Z - Y\" in exI)\n  apply (simp add: in_failures_Parallel_SKIP_lm1)\n\n (* t = <Tick> *)\n  apply (simp add: par_tr_Tick)\n  apply (elim conjE, simp)\n  apply (case_tac \"Tick ~: Z\")\n\n   apply (rule_tac x=\"Y\" in exI)\n   apply (rule_tac x=\"Z - Y\" in exI)\n   apply (simp add: in_failures_Parallel_SKIP_lm1)\n\n   (* Tick : Z *)\n   apply (rule_tac x=\"insert Tick Y\" in exI)\n   apply (rule_tac x=\"(Z - insert Tick Y)\" in exI)\n   apply (rule conjI, force)\n   apply (simp add: Tick_in_sett)\n   apply (erule exE)\n   apply (rule conjI)\n   apply (simp)\n   apply (rule proc_T2_T3)\n   apply (simp)\n   apply (simp)\n   apply (simp add: in_failures_Parallel_SKIP_lm2)\n\n(* <= *)\n apply (elim conjE exE)\n apply (case_tac \"Tick ~: sett u\")\n\n (* t = <> *)\n  apply (rule_tac x=\"u\" in exI)\n  apply (rule_tac x=\"Y\" in exI)\n  apply (rule_tac x=\"Z Un (Y - {Tick})\" in exI)\n  apply (simp)\n  apply (rule conjI)\n  apply (fast)\n  apply (rule conjI)\n  apply (fast)\n  apply (rule_tac x=\"u\" in exI)\n  apply (rule_tac x=\"<>\" in exI)\n  apply (simp add: par_tr_nil)\n  apply (simp add: Evset_def)\n  apply (force)\n\n (* t = <Tick> *)\n  apply (rule_tac x=\"u\" in exI)\n  apply (rule_tac x=\"Y\" in exI)\n  apply (rule_tac x=\"Z Un Y\" in exI)\n  apply (simp)\n  apply (rule conjI)\n  apply (fast)\n  apply (rule conjI)\n  apply (fast)\n  apply (rule_tac x=\"u\" in exI)\n  apply (rule_tac x=\"<Tick>\" in exI)\n  apply (simp add: par_tr_Tick)\ndone\n\n(*** complement ***)\n\nlemma in_failures_Parallel_SKIP_comp:\n  \"(f :f failures(P |[- X]| SKIP) M) =\n   (EX u Y Z. f = (u, Y Un Z) & (u, Y) :f failures(P) M & \n              sett(u) <= insert Tick (Ev ` X) & Z Int insert Tick (Ev ` X) = {})\"\napply (simp add: in_failures_Parallel_SKIP)\napply (auto)\napply (rule_tac x=\"Y\" in exI)\napply (rule_tac x=\"Z\" in exI)\napply (simp)\napply (rule conjI)\n apply (rule subsetI)\n apply (case_tac \"x : Ev ` (- X)\")\n apply (fast)\n apply (simp add: notin_Ev_set)\n apply (erule disjE, simp)\n apply (force)\napply (force)\n\napply (rule_tac x=\"Y\" in exI)\napply (rule_tac x=\"Z\" in exI)\napply (auto)\napply (case_tac \"x = Tick\", simp)\napply (simp add: not_Tick_to_Ev)\napply (auto)\ndone\n\n(*** Alpha_parallel_evalF ***)\n\nlemma in_failures_Alpha_parallel_lm1:\n  \"[| Tick ~: Za ; Za Int Ev ` X1 = {}; \n      Tick ~: Zb ; Zb Int Ev ` X2 = {};\n      Ya Un Za - insert Tick (Ev ` (X1 Int X2)) =\n      Yb Un Zb - insert Tick (Ev ` (X1 Int X2)) |]\n       ==>\n       (Ya Un Za Un (Yb Un Zb)) Int insert Tick (Ev ` (X1 Un X2)) =\n         (Ya Int insert Tick (Ev ` X1)) Un\n         (Yb Int insert Tick (Ev ` X2))\"\nby (auto)\n\nlemma in_failures_Alpha_parallel_lm2:\n  \"X Int insert Tick (Ev ` (X1 Un X2)) <= Y Un Z\n   ==> X = X Int Ev ` (X1 - X2) Un X Int Y Int insert Tick (Ev ` (X1 Int X2)) Un\n               (X - insert Tick (Ev ` X1)) Un\n               (X Int Ev ` (X2 - X1) Un X Int Z Int insert Tick (Ev ` (X1 Int X2)) Un\n                (X - insert Tick (Ev ` X2)))\"\nby (auto)\n\nlemma in_failures_Alpha_parallel_lm3:\n  \"X Int Ev ` (X1 - X2) Un X Int Y Int insert Tick (Ev ` (X1 Int X2)) Un\n           (X - insert Tick (Ev ` X1)) -\n           insert Tick (Ev ` (X1 Int X2)) =\n           X Int Ev ` (X2 - X1) Un X Int Z Int insert Tick (Ev ` (X1 Int X2)) Un\n           (X - insert Tick (Ev ` X2)) -\n           insert Tick (Ev ` (X1 Int X2))\"\nby (auto)\n\n(* F *)\n\nlemma in_failures_Alpha_parallel:\n  \"(f :f failures(P |[X1,X2]| Q) M) =\n   (EX u X.\n     f = (u, X) &\n     (EX Y Z.\n         X Int insert Tick (Ev ` (X1 Un X2)) =\n         Y Int insert Tick (Ev ` X1) Un Z Int insert Tick (Ev ` X2) &\n         (u rest-tr X1, Y) :f failures(P) M &\n         (u rest-tr X2, Z) :f failures(Q) M & \n          sett u <= insert Tick (Ev ` (X1 Un X2))))\"\napply (simp add: Alpha_parallel_def)\napply (simp add: in_failures_Parallel[of _ _ \"X1 Int X2\"])\napply (simp add: in_failures_Parallel_SKIP_comp)\napply (rule iffI)\n\n(* => *)\n apply (elim conjE exE)\n apply (simp add: par_tr_rest_tr)\n apply (rule_tac x=\"Ya\" in exI, simp)\n apply (rule_tac x=\"Yb\" in exI, simp)\n apply (simp add: in_failures_Alpha_parallel_lm1)\n\n(* <= *)\n apply (elim conjE exE)\n apply (simp)\n apply (rule_tac x=\n   \"(X Int (Ev ` (X1 - X2))) Un \n    (X Int Y Int insert Tick (Ev ` (X1 Int X2))) Un\n    (X - insert Tick (Ev ` X1))\" in exI)\n apply (rule_tac x=\n   \"(X Int (Ev ` (X2 - X1))) Un \n    (X Int Z Int insert Tick (Ev ` (X1 Int X2))) Un\n    (X - insert Tick (Ev ` X2))\" in exI)\n\n(* X = Y' Un Z' *)\n  apply (rule conjI)\n  apply (rule in_failures_Alpha_parallel_lm2)\n  apply (fast)\n\n(* Parallel condition *)\n  apply (rule conjI)\n  apply (simp add: in_failures_Alpha_parallel_lm3)\n\n(* failures *)\n  apply (rule_tac x=\"u rest-tr X1\" in exI)\n  apply (rule_tac x=\"u rest-tr X2\" in exI)\n  apply (simp add: par_tr_rest_tr_if)\n\n  apply (rule conjI)\n   apply (rule_tac x=\n     \"(X Int (Ev ` (X1 - X2))) Un \n      (X Int Y Int insert Tick (Ev ` (X1 Int X2)))\" in exI)\n   apply (rule_tac x= \"(X - insert Tick (Ev ` X1))\" in exI)\n   apply (simp)\n   apply (rule conjI)\n   apply (rule memF_F2)\n   apply (simp)\n   apply (force)\n   apply (force)\n\n   apply (rule_tac x=\n     \"(X Int (Ev ` (X2 - X1))) Un \n      (X Int Z Int insert Tick (Ev ` (X1 Int X2)))\" in exI)\n   apply (rule_tac x= \"(X - insert Tick (Ev ` X2))\" in exI)\n   apply (simp)\n   apply (rule conjI)\n   apply (rule memF_F2)\n   apply (simp)\n   apply (force)\n   apply (force)\ndone\n\n(*** Semantics for alphabetized parallel on F ***)\n\nlemma failures_Alpha_parallel:\n  \"failures(P |[X1,X2]| Q) = (%M.\n   {f. (EX u X. f = (u, X) &\n     (EX Y Z.\n         X Int insert Tick (Ev ` (X1 Un X2)) =\n         Y Int insert Tick (Ev ` X1) Un Z Int insert Tick (Ev ` X2) &\n         (u rest-tr X1, Y) :f failures(P) M &\n         (u rest-tr X2, Z) :f failures(Q) M &\n          sett u <= insert Tick (Ev ` (X1 Un X2))))}f)\"\napply (simp only: in_failures_Alpha_parallel[THEN sym])\napply (simp)\ndone\n\n(****************** to add it again ******************)\n\ndeclare disj_not1   [simp]\n\nend\n", "meta": {"author": "pefribeiro", "repo": "CSP-Prover", "sha": "8967cc482e5695fca4abb52d9dc2cf36b7b7a44e", "save_path": "github-repos/isabelle/pefribeiro-CSP-Prover", "path": "github-repos/isabelle/pefribeiro-CSP-Prover/CSP-Prover-8967cc482e5695fca4abb52d9dc2cf36b7b7a44e/CSP_F/CSP_F_op_alpha_par.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6076631698328917, "lm_q2_score": 0.4225046348141882, "lm_q1q2_score": 0.25674050566027795}}
{"text": "theory Decode_Correct imports MIPS MIPS_Model begin\n\nprimrec not_jb :: \\<open>inst \\<Rightarrow> bool\\<close> where\n  \\<open>not_jb (Inst_ALU_R _ _ _ _) = True\\<close> |\n  \\<open>not_jb (Inst_ALU_I _ _ _ _) = True\\<close> |\n  \\<open>not_jb (Inst_Shift_R _ _ _ _) = True\\<close> |\n  \\<open>not_jb (Inst_Shift_I _ _ _ _) = True\\<close> |\n  \\<open>not_jb (Inst_LUI _ _) = True\\<close> |\n  \\<open>not_jb (Inst_J _) = False\\<close> |\n  \\<open>not_jb (Inst_JAL _) = False\\<close> |\n  \\<open>not_jb (Inst_JR _) = False\\<close> |\n  \\<open>not_jb (Inst_JALR _ _) = False\\<close> |\n  \\<open>not_jb (Inst_Branch _ _ _ _) = False\\<close> |\n  \\<open>not_jb (Inst_Branch1 _ _ _) = False\\<close> |\n  \\<open>not_jb (Inst_Load _ _ _ _ _) = True\\<close> |\n  \\<open>not_jb (Inst_Store _ _ _ _) = True\\<close> |\n  \\<open>not_jb Inst_Undef = False\\<close>\n\nlemma decode_not_jb_next_pc_sel:\n  \\<open>not_jb (mips.decode inst) \\<Longrightarrow> DecodedInst_next_pc_sel (decode inst) = NextPC_NoJump\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0 :: 6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp add: ucast_slice)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nfun is_jump_imm :: \\<open>inst \\<Rightarrow> bool\\<close> where\n  \\<open>is_jump_imm (Inst_J _) = True\\<close> |\n  \\<open>is_jump_imm (Inst_JAL _) = True\\<close> |\n  \\<open>is_jump_imm _ = False\\<close>\n\nlemma decode_jump_imm_pc_sel:\n  \\<open>is_jump_imm (mips.decode inst) \\<Longrightarrow> DecodedInst_next_pc_sel (decode inst) = NextPC_J\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0 :: 6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp add: ucast_slice)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nfun is_jump_reg :: \\<open>inst \\<Rightarrow> bool\\<close> where\n  \\<open>is_jump_reg (Inst_JR _) = True\\<close> |\n  \\<open>is_jump_reg (Inst_JALR _ _) = True\\<close> |\n  \\<open>is_jump_reg _ = False\\<close>\n\nlemma decode_jump_reg_pc_sel:\n  \\<open>is_jump_reg (mips.decode inst) \\<Longrightarrow> DecodedInst_next_pc_sel (decode inst) = NextPC_RS\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0 :: 6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp add: ucast_slice)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nfun br_cond :: \\<open>inst \\<Rightarrow> 2 word option\\<close> where\n  \\<open>br_cond (Inst_Branch EQ _ _ _) = Some CondEQ\\<close> |\n  \\<open>br_cond (Inst_Branch NE _ _ _) = Some CondNE\\<close> |\n  \\<open>br_cond (Inst_Branch1 LEZ _ _) = Some CondLEZ\\<close> |\n  \\<open>br_cond (Inst_Branch1 GTZ _ _) = Some CondGTZ\\<close> |\n  \\<open>br_cond _ = None\\<close>\n\nlemma decode_br_pc_sel:\n  \\<open>br_cond (mips.decode inst) = Some cond \\<Longrightarrow> DecodedInst_next_pc_sel (decode inst) = NextPC_B\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0 :: 6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp add: ucast_slice)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nlemma decode_cond_sel:\n  \\<open>br_cond (mips.decode inst) = Some cond \\<Longrightarrow> DecodedInst_cond_sel (decode inst) = cond\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0 :: 6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp add: ucast_slice)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nprimrec not_ls :: \\<open>inst \\<Rightarrow> bool\\<close> where\n  \\<open>not_ls (Inst_ALU_R _ _ _ _) = True\\<close> |\n  \\<open>not_ls (Inst_ALU_I _ _ _ _) = True\\<close> |\n  \\<open>not_ls (Inst_Shift_R _ _ _ _) = True\\<close> |\n  \\<open>not_ls (Inst_Shift_I _ _ _ _) = True\\<close> |\n  \\<open>not_ls (Inst_LUI _ _) = True\\<close> |\n  \\<open>not_ls (Inst_J _) = True\\<close> |\n  \\<open>not_ls (Inst_JAL _) = True\\<close> |\n  \\<open>not_ls (Inst_JR _) = True\\<close> |\n  \\<open>not_ls (Inst_JALR _ _) = True\\<close> |\n  \\<open>not_ls (Inst_Branch _ _ _ _) = True\\<close> |\n  \\<open>not_ls (Inst_Branch1 _ _ _) = True\\<close> |\n  \\<open>not_ls (Inst_Load _ _ _ _ _) = False\\<close> |\n  \\<open>not_ls (Inst_Store _ _ _ _) = False\\<close> |\n  \\<open>not_ls Inst_Undef = False\\<close>\n\nfun is_ls :: \\<open>inst \\<Rightarrow> bool\\<close> where\n  \\<open>is_ls (Inst_Load _ _ _ _ _) = True\\<close> |\n  \\<open>is_ls (Inst_Store _ _ _ _) = True\\<close> |\n  \\<open>is_ls _ = False\\<close>\n\nlemma decode_not_ls_dm_en:\n  \\<open>not_ls (mips.decode inst) \\<Longrightarrow> \\<not> DecodedInst_dm_en (decode inst)\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0 :: 6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nlemma decode_ls_dm_en:\n  \\<open>is_ls (mips.decode inst) \\<Longrightarrow> DecodedInst_dm_en (decode inst)\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0 :: 6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp add: ucast_slice)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nprimrec read_rs :: \\<open>inst \\<Rightarrow> 5 word\\<close> where\n  \\<open>read_rs (Inst_ALU_R op rd rs rt) = rs\\<close> |\n  \\<open>read_rs (Inst_ALU_I op rd rs imm) = rs\\<close> |\n  \\<open>read_rs (Inst_Shift_R op rd rt rs) = rs\\<close> |\n  \\<open>read_rs (Inst_Shift_I op rd rt shamt) = 0\\<close> |\n  \\<open>read_rs (Inst_LUI _ _) = 0\\<close> |\n  \\<open>read_rs (Inst_J _) = 0\\<close> |\n  \\<open>read_rs (Inst_JAL _) = 0\\<close> |\n  \\<open>read_rs (Inst_JR rs) = rs\\<close> |\n  \\<open>read_rs (Inst_JALR rd rs) = rs\\<close> |\n  \\<open>read_rs (Inst_Branch op rs rt imm) = rs\\<close> |\n  \\<open>read_rs (Inst_Branch1 op rs imm) = rs\\<close> |\n  \\<open>read_rs (Inst_Load sz sign rt rs imm) = rs\\<close> |\n  \\<open>read_rs (Inst_Store sz rt rs imm) = rs\\<close> |\n  \\<open>read_rs Inst_Undef = undefined\\<close>\n\nlemma decode_rf_ra1:\n  \\<open>mips.decode inst \\<noteq> Inst_Undef \\<Longrightarrow> read_rs (mips.decode inst) = rs \\<Longrightarrow> DecodedInst_rf_ra1 (decode inst) = rs\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0 :: 6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp add: ucast_slice)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nprimrec read_rt :: \\<open>inst \\<Rightarrow> 5 word\\<close> where\n  \\<open>read_rt (Inst_ALU_R op rd rs rt) = rt\\<close> |\n  \\<open>read_rt (Inst_ALU_I op rd rs imm) = 0\\<close> |\n  \\<open>read_rt (Inst_Shift_R op rd rt rs) = rt\\<close> |\n  \\<open>read_rt (Inst_Shift_I op rd rt shamt) = rt\\<close> |\n  \\<open>read_rt (Inst_LUI _ _) = 0\\<close> |\n  \\<open>read_rt (Inst_J _) = 0\\<close> |\n  \\<open>read_rt (Inst_JAL _) = 0\\<close> |\n  \\<open>read_rt (Inst_JR rs) = 0\\<close> |\n  \\<open>read_rt (Inst_JALR rd rs) = 0\\<close> |\n  \\<open>read_rt (Inst_Branch op rs rt imm) = rt\\<close> |\n  \\<open>read_rt (Inst_Branch1 op rs imm) = 0\\<close> |\n  \\<open>read_rt (Inst_Load sz sign rt rs imm) = 0\\<close> |\n  \\<open>read_rt (Inst_Store sz rt rs imm) = rt\\<close> |\n  \\<open>read_rt Inst_Undef = undefined\\<close>\n\nlemma decode_rf_ra2:\n  \\<open>mips.decode inst \\<noteq> Inst_Undef \\<Longrightarrow> read_rt (mips.decode inst) = rt \\<Longrightarrow> DecodedInst_rf_ra2 (decode inst) = rt\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0 :: 6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp add: ucast_slice)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nprimrec write_r :: \\<open>inst \\<Rightarrow> 5 word\\<close> where\n  \\<open>write_r (Inst_ALU_R op rd rs rt) = rd\\<close> |\n  \\<open>write_r (Inst_ALU_I op rd rs imm) = rd\\<close> |\n  \\<open>write_r (Inst_Shift_R op rd rt rs) = rd\\<close> |\n  \\<open>write_r (Inst_Shift_I op rd rt shamt) = rd\\<close> |\n  \\<open>write_r (Inst_LUI rd imm) = rd\\<close> |\n  \\<open>write_r (Inst_J imm) = 0\\<close> |\n  \\<open>write_r (Inst_JAL imm) = 31\\<close> |\n  \\<open>write_r (Inst_JR rs) = 0\\<close> |\n  \\<open>write_r (Inst_JALR rd rs) = rd\\<close> |\n  \\<open>write_r (Inst_Branch op rs rt imm) = 0\\<close> |\n  \\<open>write_r (Inst_Branch1 op rs imm) = 0\\<close> |\n  \\<open>write_r (Inst_Load sz sign rt rs imm) = rt\\<close> |\n  \\<open>write_r (Inst_Store sign rt rs imm) = 0\\<close> |\n  \\<open>write_r Inst_Undef = undefined\\<close>\n\nlemma decode_rf_wa:\n  \\<open>mips.decode inst \\<noteq> Inst_Undef \\<Longrightarrow> write_r (mips.decode inst) = r \\<Longrightarrow> DecodedInst_rf_wa (decode inst) = r\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0 :: 6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp add: ucast_slice)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nprimrec convert_alu_op :: \\<open>ALU_op \\<Rightarrow> 4 word\\<close> where\n  \\<open>convert_alu_op OP_ADD  = ALU_ADD\\<close> |\n  \\<open>convert_alu_op OP_SUB  = ALU_SUB\\<close> |\n  \\<open>convert_alu_op OP_AND  = ALU_AND\\<close> |\n  \\<open>convert_alu_op OP_OR   = ALU_OR \\<close> |\n  \\<open>convert_alu_op OP_XOR  = ALU_XOR\\<close> |\n  \\<open>convert_alu_op OP_NOR  = ALU_NOR\\<close> |\n  \\<open>convert_alu_op OP_SLT  = ALU_SLT\\<close> |\n  \\<open>convert_alu_op OP_SLTU = ALU_ULT\\<close>\n\nfun alu_op :: \\<open>inst \\<Rightarrow> ALU_op option\\<close> where\n  \\<open>alu_op (Inst_ALU_R op _ _ _) = Some op\\<close> |\n  \\<open>alu_op (Inst_ALU_I op _ _ _) = Some op\\<close> |\n  \\<open>alu_op (Inst_LUI _ _) = Some OP_ADD\\<close> | (* could be any op satisfying \\<open>0 \\<oplus> x = x\\<close> *)\n  \\<open>alu_op (Inst_Load _ _ _ _ _) = Some OP_ADD\\<close> |\n  \\<open>alu_op (Inst_Store _ _ _ _) = Some OP_ADD\\<close> |\n  \\<open>alu_op _ = None\\<close>\n\nfun shifter_op :: \\<open>inst \\<Rightarrow> shift_op option\\<close> where\n  \\<open>shifter_op (Inst_Shift_R op _ _ _) = Some op\\<close> |\n  \\<open>shifter_op (Inst_Shift_I op _ _ _) = Some op\\<close> |\n  \\<open>shifter_op _ = None\\<close>\n\nfun rf_in_is_alu_out where\n  \\<open>rf_in_is_alu_out (Inst_ALU_R _ _ _ _) = True\\<close> |\n  \\<open>rf_in_is_alu_out (Inst_ALU_I _ _ _ _) = True\\<close> |\n  \\<open>rf_in_is_alu_out (Inst_LUI _ _) = True\\<close> |\n  \\<open>rf_in_is_alu_out _ = False\\<close>\n\nlemma decode_alu_rf_in_sel:\n  \\<open>rf_in_is_alu_out (mips.decode inst) \\<Longrightarrow> DecodedInst_rf_in_sel (decode inst) = ALU_Out\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0::6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp add: ucast_slice)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nlemma decode_shifter_rf_in_sel:\n  \\<open>shifter_op (mips.decode inst) = Some op \\<Longrightarrow> DecodedInst_rf_in_sel (decode inst) = ShifterOut\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0::6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp add: ucast_slice)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nlemma decode_load_rf_in_sel:\n  \\<open>mips.decode inst = Inst_Load sz sign rt rs imm \\<Longrightarrow> DecodedInst_rf_in_sel (decode inst) = DM_Out\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0::6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp add: ucast_slice)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nlemma decode_alu_op:\n  \\<open>alu_op (mips.decode inst) = Some op \\<Longrightarrow> DecodedInst_alu_op (decode inst) = convert_alu_op op\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0 :: 6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp add: ucast_slice)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nlemma decode_ALU_R_alu_b_imm:\n  \\<open>mips.decode inst = Inst_ALU_R op rd rs rt \\<Longrightarrow> \\<not> DecodedInst_alu_b_imm (decode inst)\\<close>\n  apply(simp add: mips.decode_def decode_def Let_def)\n  by unat_arith\n\nfun alu_b_imm :: \\<open>inst \\<Rightarrow> bool\\<close> where\n  \\<open>alu_b_imm (Inst_ALU_I _ _ _ _) = True\\<close> |\n  \\<open>alu_b_imm (Inst_LUI _ _) = True\\<close> |\n  \\<open>alu_b_imm (Inst_Load _ _ _ _ _) = True\\<close> |\n  \\<open>alu_b_imm (Inst_Store _ _ _ _) = True\\<close> |\n  \\<open>alu_b_imm _ = False\\<close>\n\nlemma decode_alu_b_imm:\n  \\<open>alu_b_imm (mips.decode inst) \\<Longrightarrow> DecodedInst_alu_b_imm (decode inst)\\<close>\n  apply(simp add: mips.decode_def decode_def Let_def)\n  by unat_arith\n\nprimrec convert_shift_op :: \\<open>shift_op \\<Rightarrow> 2 word\\<close> where\n  \\<open>convert_shift_op OP_SLL = SHL\\<close> |\n  \\<open>convert_shift_op OP_SRL = LSHR\\<close> |\n  \\<open>convert_shift_op OP_SRA = ASHR\\<close>\n\nlemma decode_shifter_op:\n  \\<open>shifter_op (mips.decode inst) = Some op \\<Longrightarrow> DecodedInst_shifter_op (decode inst) = convert_shift_op op\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0::6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp add: ucast_slice)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nlemma decode_ALU_I_bitwise_imm_ext_method:\n  \\<open>mips.decode inst = Inst_ALU_I op rt rs imm \\<Longrightarrow> is_bitwise_op op \\<Longrightarrow> DecodedInst_imm_ext_method (decode inst) = ZeroExt\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0 :: 6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nlemma decode_ALU_I_non_bitwise_imm_ext_method:\n  \\<open>mips.decode inst = Inst_ALU_I op rt rs imm \\<Longrightarrow> \\<not> is_bitwise_op op \\<Longrightarrow> DecodedInst_imm_ext_method (decode inst) = SignExt\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  done\n\nlemma decode_LUI_imm_ext_method:\n  \\<open>mips.decode inst = Inst_LUI rt imm \\<Longrightarrow> DecodedInst_imm_ext_method (decode inst) = LUI_Ext\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0::6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp add: ucast_slice)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nfun get_imm16 :: \\<open>inst \\<Rightarrow> 16 word option\\<close> where\n  \\<open>get_imm16 (Inst_ALU_I op rd rs imm) = Some imm\\<close> |\n  \\<open>get_imm16 (Inst_Branch op rs rt imm) = Some imm\\<close> |\n  \\<open>get_imm16 (Inst_Branch1 op rs imm) = Some imm\\<close> |\n  \\<open>get_imm16 (Inst_LUI rt imm) = Some imm\\<close> |\n  \\<open>get_imm16 (Inst_Load _ _ _ _ imm) = Some imm\\<close> |\n  \\<open>get_imm16 (Inst_Store _ _ _ imm) = Some imm\\<close> |\n  \\<open>get_imm16 _ = None\\<close>\n\nlemma decode_imm16:\n  \\<open>get_imm16 (mips.decode inst) = Some imm \\<Longrightarrow> ucast inst = imm\\<close>\n  apply(simp add: mips.decode_def)\n  apply(cases \\<open>slice 26 inst = (0::6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nlemma decode_Shift_I_shamt_imm:\n  \\<open>mips.decode inst = Inst_Shift_I op rd rt shamt \\<Longrightarrow> DecodedInst_shamt_imm (decode inst)\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0::6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp add: ucast_slice)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nlemma decode_Shift_I_shamt:\n  \\<open>mips.decode inst = Inst_Shift_I op rd rt shamt \\<Longrightarrow> slice 6 inst = shamt\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0::6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nlemma decode_Shift_R_shamt_imm:\n  \\<open>mips.decode inst = Inst_Shift_R op rd rt rs \\<Longrightarrow> \\<not> DecodedInst_shamt_imm (decode inst)\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0::6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp add: ucast_slice)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nfun is_jr :: \\<open>inst \\<Rightarrow> bool\\<close> where\n  \\<open>is_jr (Inst_JR _) = True\\<close> |\n  \\<open>is_jr (Inst_JALR _ _) = True\\<close> |\n  \\<open>is_jr _ = False\\<close>\n\nlemma decode_jr_next_pc_sel:\n  \\<open>is_jr (mips.decode inst) \\<Longrightarrow> DecodedInst_next_pc_sel (decode inst) = NextPC_RS\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0::6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp add: ucast_slice)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nfun is_jal :: \\<open>inst \\<Rightarrow> bool\\<close> where\n  \\<open>is_jal (Inst_JAL _) = True\\<close> |\n  \\<open>is_jal (Inst_JALR _ _) = True\\<close> |\n  \\<open>is_jal _ = False\\<close>\n\nlemma decode_jal_rf_in_sel:\n  \\<open>is_jal (mips.decode inst) \\<Longrightarrow> DecodedInst_rf_in_sel (decode inst) = PC_plus8\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0 :: 6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp add: ucast_slice)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nfun get_imm26 :: \\<open>inst \\<Rightarrow> 26 word option\\<close> where\n  \\<open>get_imm26 (Inst_J imm) = Some imm\\<close> |\n  \\<open>get_imm26 (Inst_JAL imm) = Some imm\\<close> |\n  \\<open>get_imm26 _ = None\\<close>\n\nlemma decode_imm26:\n  \\<open>get_imm26 (mips.decode inst) = Some imm \\<Longrightarrow> ucast inst = imm\\<close>\n  apply(simp add: mips.decode_def)\n  apply(cases \\<open>slice 26 inst = (0::6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nprimrec convert_mem_req_size where\n  \\<open>convert_mem_req_size BYTE = Byte\\<close> |\n  \\<open>convert_mem_req_size HALF = Half\\<close> |\n  \\<open>convert_mem_req_size WORD = Word\\<close>\n\nfun ls_size where\n  \\<open>ls_size (Inst_Load sz _ _ _ _) = Some sz\\<close> |\n  \\<open>ls_size (Inst_Store sz _ _ _) = Some sz\\<close> |\n  \\<open>ls_size _ = None\\<close>\n\nlemma decode_dm_req_size:\n  \\<open>ls_size (mips.decode inst) = Some sz \\<Longrightarrow> DecodedInst_dm_req_size (decode inst) = convert_mem_req_size sz\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0::6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nterm DecodedInst_dm_ext_sign\nlemma decode_mem_data_sign_ext:\n  \\<open>mips.decode inst = Inst_Load sz sign rt rs imm \\<Longrightarrow> DecodedInst_mem_data_sign_ext (decode inst) = sign\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0::6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nlemma decode_load_dm_wr:\n  \\<open>mips.decode inst = Inst_Load sz sign rt rs imm \\<Longrightarrow> \\<not> DecodedInst_dm_wr (decode inst)\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0 :: 6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nlemma decode_store_dm_wr:\n  \\<open>mips.decode inst = Inst_Store sz rt rs imm \\<Longrightarrow> DecodedInst_dm_wr (decode inst)\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0 :: 6 word)\\<close>; simp)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 2\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 3\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 4\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 6\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 7\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 8\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 9\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x20\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x21\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x22\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x23\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x24\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x25\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x26\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x27\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2a\\<close>; simp add: ucast_slice)\n   apply(cases \\<open>UCAST(32\\<rightarrow>6) inst = 0x2b\\<close>; simp add: ucast_slice)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (32::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (33::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (34::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (36::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (37::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (40::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (41::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (43::6 word)\\<close>; simp)\n  done\n\nlemma decode_ls_imm_ext_method:\n  \\<open>is_ls (mips.decode inst) \\<Longrightarrow> DecodedInst_imm_ext_method (decode inst) = SignExt\\<close>\n  apply(simp add: mips.decode_def decode_def)\n  apply(cases \\<open>slice 26 inst = (0::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (2::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (3::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (4::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (5::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (6::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (7::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (8::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (9::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (10::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (11::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (12::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (13::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (14::6 word)\\<close>; simp)\n  apply(cases \\<open>slice 26 inst = (15::6 word)\\<close>; simp)\n  done\n\nend\n", "meta": {"author": "wildptr", "repo": "vsmips", "sha": "ce076e17e31556ef1a98beb88afa0811c083620c", "save_path": "github-repos/isabelle/wildptr-vsmips", "path": "github-repos/isabelle/wildptr-vsmips/vsmips-ce076e17e31556ef1a98beb88afa0811c083620c/Decode_Correct.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631698328916, "lm_q2_score": 0.4225046348141882, "lm_q1q2_score": 0.2567405056602779}}
{"text": "section {*L\\_ATS\\_Simulation\\_Configuration\\_WeakLRReach*}\ntheory\n  L_ATS_Simulation_Configuration_WeakLRReach\n\nimports\n  L_ATS_Simulation_Configuration_Weak\n\nbegin\n\nlocale ATS_Simulation_Configuration_WeakReach =\n  ATS_Simulation_Configuration_Weak\n  \"TSstructure1 :: 'TSstructure1 \\<Rightarrow> bool\"\n  \"configurations1 :: 'TSstructure1 \\<Rightarrow> 'conf1 set\"\n  \"initial_configurations1 :: 'TSstructure1 \\<Rightarrow> 'conf1 set\"\n  \"step_labels1 :: 'TSstructure1 \\<Rightarrow> 'label1 set\"\n  \"step_relation1 :: 'TSstructure1 \\<Rightarrow> 'conf1 \\<Rightarrow> 'label1 \\<Rightarrow> 'conf1 \\<Rightarrow> bool\"\n  \"effects1 :: 'TSstructure1 \\<Rightarrow> 'event1 set\"\n  \"marking_condition1 :: 'TSstructure1 \\<Rightarrow> ('label1,'conf1)derivation \\<Rightarrow> bool\"\n  \"marked_effect1 :: 'TSstructure1 \\<Rightarrow> ('label1,'conf1)derivation \\<Rightarrow> 'event1 set\"\n  \"unmarked_effect1 :: 'TSstructure1 \\<Rightarrow> ('label1,'conf1)derivation \\<Rightarrow> 'event1 set\"\n  \"TSstructure2 :: 'TSstructure2 \\<Rightarrow> bool\"\n  \"configurations2 :: 'TSstructure2 \\<Rightarrow> 'conf2 set\"\n  \"initial_configurations2 :: 'TSstructure2 \\<Rightarrow> 'conf2 set\"\n  \"step_labels2 :: 'TSstructure2 \\<Rightarrow> 'label2 set\"\n  \"step_relation2 :: 'TSstructure2 \\<Rightarrow> 'conf2 \\<Rightarrow> 'label2 \\<Rightarrow> 'conf2 \\<Rightarrow> bool\"\n  \"effects2 :: 'TSstructure2 \\<Rightarrow> 'event2 set\"\n  \"marking_condition2 :: 'TSstructure2 \\<Rightarrow> ('label2,'conf2)derivation \\<Rightarrow> bool\"\n  \"marked_effect2 :: 'TSstructure2 \\<Rightarrow> ('label2,'conf2)derivation \\<Rightarrow> 'event2 set\"\n  \"unmarked_effect2 :: 'TSstructure2 \\<Rightarrow> ('label2,'conf2)derivation \\<Rightarrow> 'event2 set\"\n  \"relation_configuration :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'conf1 \\<Rightarrow> 'conf2 \\<Rightarrow> bool\"\n  \"relation_initial_configuration :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'conf1 \\<Rightarrow> 'conf2 \\<Rightarrow> bool\"\n  \"relation_effect :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'event1 \\<Rightarrow> 'event2 \\<Rightarrow> bool\"\n  \"relation_TSstructure :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> bool\"\n  \"relation_initial_simulation :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'conf1 \\<Rightarrow> (nat \\<Rightarrow> ('label2, 'conf2) derivation_configuration option) \\<Rightarrow> bool\"\n  \"relation_step_simulation :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'conf1 \\<Rightarrow> 'label1 \\<Rightarrow> 'conf1 \\<Rightarrow> 'conf2 \\<Rightarrow> (nat \\<Rightarrow> ('label2, 'conf2) derivation_configuration option) \\<Rightarrow> bool\"\n  for\n    TSstructure1 configurations1 initial_configurations1 step_labels1 step_relation1 effects1 marking_condition1 marked_effect1 unmarked_effect1 TSstructure2 configurations2 initial_configurations2 step_labels2 step_relation2 effects2 marking_condition2 marked_effect2 unmarked_effect2 relation_configuration relation_initial_configuration relation_effect relation_TSstructure relation_initial_simulation relation_step_simulation\n    +\n\nfixes relation_labelsLR :: \"'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'label1 \\<Rightarrow> 'label2 \\<Rightarrow> bool\"\n\nassumes AX_relation_step_simulationReach: \"\n  relation_TSstructure G1 G2\n  \\<Longrightarrow> relation_configuration G1 G2 c1 c2\n  \\<Longrightarrow> e1 \\<in> step_labels1 G1\n  \\<Longrightarrow> step_relation1 G1 c1 e1 c1'\n  \\<Longrightarrow> GR.derivation G2 d2\n  \\<Longrightarrow> GR.belongs G2 d2\n  \\<Longrightarrow> the(get_configuration(d2 0)) = c2\n  \\<Longrightarrow> relation_step_simulation G1 G2 c1 e1 c1' c2 d2\n  \\<Longrightarrow> maximum_of_domain d2 n\n  \\<Longrightarrow> relation_configuration G1 G2 c1' (the(get_configuration(d2 n)))\n  \\<Longrightarrow> (\\<exists>k e2 c2.\n        d2 k = Some (pair (Some e2) c2)\n        \\<and> relation_labelsLR G1 G2 e1 e2)\n      \\<or> (n=0\n         \\<and> (\\<exists>d2' n2'.\n             GR.derivation G2 d2'\n             \\<and> the(get_configuration(d2' 0)) = c2\n             \\<and> maximum_of_domain d2' n2'\n             \\<and> (\\<exists>k e2 c2.\n                 d2' k = Some (pair (Some e2) c2)\n                 \\<and> relation_labelsLR G1 G2 e1 e2)))\"\n\ncontext ATS_Simulation_Configuration_WeakReach begin\n\nlemma ATS_Simulation_Configuration_WeakReach_simulation_derivation_exists_witness_EXTENDED_Reach: \"\n  relation_TSstructure G1 G2\n  \\<Longrightarrow> GL.derivation_initial G1 d1\n  \\<Longrightarrow> d1 x = Some (pair e1 c1)\n  \\<Longrightarrow> \\<exists>d2 n2 f.\n  GR.derivation_initial G2 d2\n  \\<and> maximum_of_domain d2 n2\n  \\<and> relation_initial_configuration G1 G2 (the (get_configuration (d1 0))) (the (get_configuration (d2 0)))\n  \\<and> relation_configuration G1 G2 c1 (the (get_configuration (d2 n2)))\n  \\<and> simulating_derivation G1 G2 d1 x d2 n2 f\n  \\<and> (\\<forall>i\\<le>x. \\<forall>e1 c1. d1 i = Some (pair e1 c1) \\<longrightarrow> (case e1 of None \\<Rightarrow> True | Some e1' \\<Rightarrow> \\<exists>k d2'.\n  GR.derivation G2 d2'\n  \\<and> the(get_configuration(d2' 0)) = the(get_configuration(d2 (f i)))\n  \\<and> (case ((get_label (derivation_append d2 d2' (f i) k))) of None \\<Rightarrow> False | Some e2' \\<Rightarrow> relation_labelsLR G1 G2 e1' e2')))\"\n  apply(induct x arbitrary: e1 c1)\n   apply(rename_tac e1 c1)(*strict*)\n   apply(clarsimp)\n   apply(subgoal_tac \"c1 \\<in> initial_configurations1 G1\")\n    apply(rename_tac e1 c1)(*strict*)\n    prefer 2\n    apply(simp add: GL.derivation_initial_def)\n   apply(rename_tac e1 c1)(*strict*)\n   apply(subgoal_tac \"\\<exists>d2 n. GR.derivation_initial G2 d2 \\<and> relation_initial_configuration G1 G2 c1 (the(get_configuration(d2 0))) \\<and> relation_initial_simulation G1 G2 c1 d2 \\<and> maximum_of_domain d2 n \\<and> relation_configuration G1 G2 c1 (the(get_configuration(d2 n)))\")\n    apply(rename_tac e1 c1)(*strict*)\n    prefer 2\n    apply(rule AX_relation_initial_simulation)\n     apply(rename_tac e1 c1)(*strict*)\n     apply(force)\n    apply(rename_tac e1 c1)(*strict*)\n    apply(force)\n   apply(rename_tac e1 c1)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac e1 c1 d2 n)(*strict*)\n   apply(rule_tac\n      x=\"d2\"\n      in exI)\n   apply(clarsimp)\n   apply(rule_tac\n      x=\"n\"\n      in exI)\n   apply(clarsimp)\n   apply(rule conjI)\n    apply(rename_tac e1 c1 d2 n)(*strict*)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac e1 c1 d2 n)(*strict*)\n   apply(rule_tac\n      x=\"\\<lambda>x. n\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac e1 c1 d2 n)(*strict*)\n    apply(simp add: simulating_derivation_def)\n    apply(rule conjI)\n     apply(rename_tac e1 c1 d2 n)(*strict*)\n     apply(simp add: simulating_derivation_I_def)\n     apply(rule conjI)\n      apply(rename_tac e1 c1 d2 n)(*strict*)\n      apply(simp add: get_configuration_def)\n      apply (metis GR.derivation_take_id_prime_prime GR.derivation_initial_is_derivation eq_imp_le)\n     apply(rename_tac e1 c1 d2 n)(*strict*)\n     apply(rule conjI)\n      apply(rename_tac e1 c1 d2 n)(*strict*)\n      apply(simp add: maximum_of_domain_def derivation_take_def get_configuration_def)\n     apply(rename_tac e1 c1 d2 n)(*strict*)\n     apply(simp add: maximum_of_domain_def)\n    apply(rename_tac e1 c1 d2 n)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac e1 c1 d2 n)(*strict*)\n     apply(simp add: simulating_derivation_S_def)\n    apply(rename_tac e1 c1 d2 n)(*strict*)\n    apply(simp add: simulating_derivation_DEF_def)\n    apply(rule conjI)\n     apply(rename_tac e1 c1 d2 n)(*strict*)\n     apply(simp add: maximum_of_domain_def)\n    apply(rename_tac e1 c1 d2 n)(*strict*)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac e1 c1 d2 n)(*strict*)\n   apply(simp add: GL.derivation_initial_def)\n  apply(rename_tac x e1 c1)(*strict*)\n  apply(clarsimp)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d1 x = Some (pair e1 c1) \\<and> d1 (Suc x) = Some (pair (Some e2) c2) \\<and> step_relation1 G1 c1 e2 c2\")\n   apply(rename_tac x e1 c1)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc x\"\n      in GL.step_detail_before_some_position)\n     apply(rename_tac x e1 c1)(*strict*)\n     apply(rule GL.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac x e1 c1)(*strict*)\n    apply(simp add: maximum_of_domain_def)\n   apply(rename_tac x e1 c1)(*strict*)\n   apply(force)\n  apply(rename_tac x e1 c1)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x c1 e1a e2 c1a)(*strict*)\n  apply(erule_tac\n      x=\"e1a\"\n      in meta_allE)\n  apply(erule_tac\n      x=\"c1a\"\n      in meta_allE)\n  apply(clarsimp)\n  apply(rename_tac x c1 e1a e2 c1a d2 n2 xa)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac x c1 e1a e2 c1a d2 n2 f)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. d2 n2 = Some (pair e c)\")\n   apply(rename_tac x c1 e1a e2 c1a d2 n2 f)(*strict*)\n   prefer 2\n   apply(rule GR.some_position_has_details_before_max_dom)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f)(*strict*)\n     apply(rule GR.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac x c1 e1a e2 c1a d2 n2 f)(*strict*)\n    apply(force)\n   apply(rename_tac x c1 e1a e2 c1a d2 n2 f)(*strict*)\n   apply(force)\n  apply(rename_tac x c1 e1a e2 c1a d2 n2 f)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x c1 e1a e2 c1a d2 n2 f e c)(*strict*)\n  apply(subgoal_tac \"\\<exists>d2 n. GR.derivation G2 d2 \\<and> GR.belongs G2 d2 \\<and> the(get_configuration(d2 0)) = c \\<and> relation_step_simulation G1 G2 c1a e2 c1 c d2 \\<and> maximum_of_domain d2 n \\<and> relation_configuration G1 G2 c1 (the(get_configuration(d2 n)))\")\n   apply(rename_tac x c1 e1a e2 c1a d2 n2 f e c)(*strict*)\n   prefer 2\n   apply(rule AX_relation_step_simulation)\n      apply(rename_tac x c1 e1a e2 c1a d2 n2 f e c)(*strict*)\n      apply(force)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e c)(*strict*)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac x c1 e1a e2 c1a d2 n2 f e c)(*strict*)\n    apply (metis GL.belongs_step_labels GL.derivation_initial_belongs AX_TSstructure_relation_TSstructure1_belongs)\n   apply(rename_tac x c1 e1a e2 c1a d2 n2 f e c)(*strict*)\n   apply(force)\n  apply(rename_tac x c1 e1a e2 c1a d2 n2 f e c)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n)(*strict*)\n  apply(rule_tac\n      x=\"derivation_append d2 d2a n2\"\n      in exI)\n  apply(subgoal_tac \"\\<exists>c. d2a 0 = Some (pair None c)\")\n   apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n   apply(rule context_conjI)\n    apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n    apply(rule GR.derivation_append_preserves_derivation_initial)\n      apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n      apply (metis AX_TSstructure_relation_TSstructure2_belongs)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n     apply(force)\n    apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n    apply(rule GR.derivation_append_preserves_derivation)\n      apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n      apply (metis GR.derivation_initial_is_derivation)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n     apply(force)\n    apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n    apply(clarsimp)\n    apply(simp add: get_configuration_def)\n   apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n   apply(rule_tac\n      x=\"n2+n\"\n      in exI)\n   apply(rule context_conjI)\n    apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n    apply (metis concat_has_max_dom)\n   apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n   apply(rule context_conjI)\n    apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n    apply(simp add: get_configuration_def derivation_append_def)\n   apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n   apply(rule conjI)\n    apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n    apply(simp add: get_configuration_def derivation_append_def)\n    apply(clarsimp)\n   apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n   apply(rule_tac\n      x=\"\\<lambda>z. if z<Suc x then f z else f x + n\"\n      in exI)\n   apply(rule conjI)\n    apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n    apply(simp add: simulating_derivation_def)\n    apply(rule context_conjI)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n     apply(clarsimp)\n     apply(simp only: simulating_derivation_I_def)\n     apply(erule exE)+\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c d2' na)(*strict*)\n     apply(rule_tac\n      x=\"d2'\"\n      in exI)\n     apply(rule_tac\n      x=\"na\"\n      in exI)\n     apply(rule conjI)\n      apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c d2' na)(*strict*)\n      apply(force)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c d2' na)(*strict*)\n     apply(rule conjI)\n      apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c d2' na)(*strict*)\n      apply(force)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c d2' na)(*strict*)\n     apply(rule conjI)\n      apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c d2' na)(*strict*)\n      apply (metis (erased, hide_lams) GR.derivation_initial_is_derivation derivation_take_def derivation_take_derivation_append_ignore GR.derivation_take_id_prime GR.derivation_take_preserves_derivation_initial GR.maximum_of_domainUnique maximum_of_domain_def)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c d2' na)(*strict*)\n     apply(rule conjI)\n      apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c d2' na)(*strict*)\n      apply(force)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c d2' na)(*strict*)\n     apply (metis (erased, hide_lams) GR.derivation_append_derivation_take GR.derivation_initial_is_derivation derivation_take_def)\n    apply(erule_tac\n      x=\"x\"\n      in allE)\n    apply(erule impE)\n     apply(force)\n    apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n    apply(rule propSym,rule context_conjI)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n     apply(simp add: simulating_derivation_DEF_def)\n     apply(clarsimp)\n     apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i)(*strict*)\n     apply(rule conjI)\n      apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i)(*strict*)\n      apply(clarsimp)\n      apply(erule_tac\n      x=\"i\"\n      in allE)\n      apply(clarsimp)\n      apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i y)(*strict*)\n      apply(subgoal_tac \"f i \\<le> f x\")\n       apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i y)(*strict*)\n       prefer 2\n       apply(rule_tac\n      d=\"d2\"\n      in GR.allPreMaxDomSome_prime)\n         apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i y)(*strict*)\n         prefer 3\n         apply(force)\n        apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i y)(*strict*)\n        apply(rule GR.derivation_initial_is_derivation)\n        apply(force)\n       apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i y)(*strict*)\n       apply(force)\n      apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i y)(*strict*)\n      apply(simp add: derivation_append_def)\n     apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c)(*strict*)\n     apply(erule disjE)\n      apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c)(*strict*)\n      apply(simp add: derivation_append_def maximum_of_domain_def)\n     apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c)(*strict*)\n     apply(subgoal_tac \"get_configuration(derivation_append d2 d2a (f x) (f x + n)) = get_configuration(d2a n)\")\n      apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c)(*strict*)\n      apply(simp add: get_configuration_def)\n     apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c)(*strict*)\n     apply(simp add: derivation_append_def)\n     apply(clarsimp)\n     apply(rename_tac x c1 e1a e2 c1a d2 f e d2a c)(*strict*)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n    apply(simp add: simulating_derivation_S_def)\n    apply(erule conjE)+\n    apply(rule allI)\n    apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i)(*strict*)\n    apply(case_tac \"i<x\")\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i)(*strict*)\n     apply(rule conjI)\n      apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i)(*strict*)\n     apply(rule impI)\n     apply(thin_tac \"i<x\")\n     apply(erule_tac\n      x=\"i\"\n      in allE)\n     apply(erule impE)\n      apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i)(*strict*)\n      apply(force)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i)(*strict*)\n     apply(rule allI)+\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i ei ci ei' ci')(*strict*)\n     apply(rule impI)\n     apply(erule_tac\n      x=\"ei\"\n      in allE)\n     apply(erule_tac\n      x=\"ci\"\n      in allE)\n     apply(erule_tac\n      x=\"ei'\"\n      in allE)\n     apply(erule_tac\n      x=\"ci'\"\n      in allE)\n     apply(erule impE)\n      apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i ei ci ei' ci')(*strict*)\n      apply(force)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i ei ci ei' ci')(*strict*)\n     apply(erule exE)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i ei ci ei' ci' d2')(*strict*)\n     apply(rule_tac\n      x=\"d2'\"\n      in exI)\n     apply(subgoal_tac \"f i \\<le> n2\")\n      apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i ei ci ei' ci' d2')(*strict*)\n      prefer 2\n      apply(simp add: simulating_derivation_DEF_def)\n      apply(clarsimp)\n      apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i ei ci ei' ci' na)(*strict*)\n      apply(erule_tac\n      x=\"i\"\n      and P=\"\\<lambda>i. i \\<le> x \\<longrightarrow> (\\<exists>y. d2 (f i) = Some y) \\<and> relation_configuration G1 G2 (the (get_configuration (d1 i))) (the (get_configuration (d2 (f i))))\"\n      in allE)\n      apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i ei ci ei' ci' na)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i ei ci ei' ci' na y)(*strict*)\n      apply(rule_tac\n      d=\"d2\"\n      in GR.allPreMaxDomSome_prime)\n        apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i ei ci ei' ci' na y)(*strict*)\n        prefer 3\n        apply(force)\n       apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i ei ci ei' ci' na y)(*strict*)\n       apply(rule GR.derivation_initial_is_derivation)\n       apply(force)\n      apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i ei ci ei' ci' na y)(*strict*)\n      apply(force)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i ei ci ei' ci' d2')(*strict*)\n     apply(rule_tac\n      t=\"derivation_append d2 d2a n2 (f i)\"\n      and s=\"d2 (f i)\"\n      in ssubst)\n      apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i ei ci ei' ci' d2')(*strict*)\n      apply(simp add: derivation_append_def get_configuration_def)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i ei ci ei' ci' d2')(*strict*)\n     apply(rule conjI)\n      apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i ei ci ei' ci' d2')(*strict*)\n      apply(force)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i ei ci ei' ci' d2')(*strict*)\n     apply(erule conjE)+\n     apply(erule exE)+\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i ei ci ei' ci' d2' na)(*strict*)\n     apply(erule conjE)+\n     apply(rule_tac\n      x=\"na\"\n      in exI)\n     apply(rule conjI)\n      apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i ei ci ei' ci' d2' na)(*strict*)\n      apply(force)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i ei ci ei' ci' d2' na)(*strict*)\n     apply(rule conjI)\n      apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i ei ci ei' ci' d2' na)(*strict*)\n      apply(force)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i ei ci ei' ci' d2' na)(*strict*)\n     apply(subgoal_tac \"f i+na \\<le> n2\")\n      apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i ei ci ei' ci' d2' na)(*strict*)\n      prefer 2\n      apply(simp add: simulating_derivation_DEF_def)\n      apply(clarsimp)\n      apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i ei ci ei' ci' na)(*strict*)\n      apply(erule_tac\n      x=\"Suc i\"\n      and P=\"\\<lambda>i. i \\<le> x \\<longrightarrow> (\\<exists>y. d2 (f i) = Some y) \\<and> relation_configuration G1 G2 (the (get_configuration (d1 i))) (the (get_configuration (d2 (f i))))\"\n      in allE)\n      apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i ei ci ei' ci' na)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i ei ci ei' ci' na y)(*strict*)\n      apply(rule_tac\n      d=\"d2\"\n      in GR.allPreMaxDomSome_prime)\n        apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i ei ci ei' ci' na y)(*strict*)\n        prefer 3\n        apply(force)\n       apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i ei ci ei' ci' na y)(*strict*)\n       apply(rule GR.derivation_initial_is_derivation)\n       apply(force)\n      apply(rename_tac x c1 e1a e2 c1a d2 f e d2a n c i ei ci ei' ci' na y)(*strict*)\n      apply(force)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i ei ci ei' ci' d2' na)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i ei ci ei' ci' na)(*strict*)\n     apply(rule ext)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i ei ci ei' ci' na xa)(*strict*)\n     apply(simp add: derivation_take_def derivation_drop_def derivation_append_def)\n    apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i)(*strict*)\n    apply(rule conjI)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i)(*strict*)\n     apply(force)\n    apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i)(*strict*)\n    apply(rule impI)\n    apply(rule impI)\n    apply(subgoal_tac \"i=x\")\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i)(*strict*)\n     prefer 2\n     apply(force)\n    apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i)(*strict*)\n    apply(thin_tac \"\\<not> i < x\")\n    apply(thin_tac \"\\<not> i < x\")\n    apply(thin_tac \"i < Suc x\")\n    apply(rule allI)+\n    apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c i ei ci ei' ci')(*strict*)\n    apply(rule impI)\n    apply(clarsimp)\n    apply(rename_tac x d2 n2 f e d2a n c ei ci ei' ci')(*strict*)\n    apply(subgoal_tac \"f x=n2\")\n     apply(rename_tac x d2 n2 f e d2a n c ei ci ei' ci')(*strict*)\n     prefer 2\n     apply(simp add: simulating_derivation_DEF_def)\n    apply(rename_tac x d2 n2 f e d2a n c ei ci ei' ci')(*strict*)\n    apply(clarsimp)\n    apply(rename_tac x d2 f e d2a n c ei ci ei' ci')(*strict*)\n    apply(rule_tac\n      t=\"(the (get_configuration (derivation_append d2 d2a (f x) (f x))))\"\n      and s=\"(the (get_configuration (Some (pair None c))))\"\n      in ssubst)\n     apply(rename_tac x d2 f e d2a n c ei ci ei' ci')(*strict*)\n     apply(simp add: get_configuration_def derivation_append_def)\n    apply(rename_tac x d2 f e d2a n c ei ci ei' ci')(*strict*)\n    apply(rule_tac\n      t=\"derivation_take (derivation_drop (derivation_append d2 d2a (f x)) (f x)) n\"\n      and s=\"d2a\"\n      in ssubst)\n     apply(rename_tac x d2 f e d2a n c ei ci ei' ci')(*strict*)\n     apply(rule ext)\n     apply(rename_tac x d2 f e d2a n c ei ci ei' ci' xa)(*strict*)\n     apply(simp add: derivation_take_def derivation_drop_def derivation_append_def)\n     apply(simp add: get_configuration_def)\n     apply(clarsimp)\n     apply (metis GR.allPreMaxDomSome_prime)\n    apply(rename_tac x d2 f e d2a n c ei ci ei' ci')(*strict*)\n    apply(rule conjI)\n     apply(rename_tac x d2 f e d2a n c ei ci ei' ci')(*strict*)\n     apply(force)\n    apply(rename_tac x d2 f e d2a n c ei ci ei' ci')(*strict*)\n    apply(force)\n   apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n   prefer 2\n   apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n)(*strict*)\n   apply (metis GR.some_position_has_details_at_0)\n  apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n  apply(subgoal_tac \"(\\<exists>k e2' c2'. d2a k = Some (pair (Some e2') c2') \\<and> relation_labelsLR G1 G2 e2 e2') \\<or> (n=0 \\<and> (\\<exists>d2' n2'. GR.derivation G2 d2' \\<and> the(get_configuration(d2' 0)) = SSc \\<and> maximum_of_domain d2' n2' \\<and> (\\<exists>k e2' c2'. d2' k = Some (pair (Some e2') c2' ) \\<and> relation_labelsLR G1 G2 e2 e2')))\" for SSc)\n   apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n   prefer 2\n   apply(rule AX_relation_step_simulationReach)\n            apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n            apply(force)\n           apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n           prefer 2\n           apply (metis GL.belongs_step_labels GL.derivation_initial_belongs AX_TSstructure_relation_TSstructure1_belongs)\n          apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n          prefer 2\n          apply(force)\n         apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n         apply(force)\n        apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n        apply(force)\n       apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n       apply(simp add: get_configuration_def)\n      apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n      apply(simp add: get_configuration_def)\n     apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n     apply(simp add: get_configuration_def)\n    apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n    apply(force)\n   apply(rename_tac x c1 e1a e2 c1a d2 n2 f e d2a n c)(*strict*)\n   apply(force)\n  apply(rule allI)\n  apply(case_tac \"i\\<le>x\")\n   apply(erule_tac x=\"i\" in allE)\n   apply(clarsimp)\n   apply(case_tac e1)\n    apply(force)\n   apply(clarsimp)\n   apply(erule disjE)\n    apply(clarsimp)\n    apply(subgoal_tac \"f i\\<le>n2\")\n     apply(rule_tac x=\"k\" in exI)\n     apply(rule_tac x=\"d2'\" in exI)\n     apply(clarsimp)\n     apply(rule conjI)\n      apply(simp add: get_configuration_def derivation_append_def get_label_def)\n     apply(simp add: get_configuration_def derivation_append_def get_label_def)\n     apply(rule conjI)\n      apply(force)\n     apply(force)\n    apply(simp add: simulating_derivation_def simulating_derivation_DEF_def)\n    apply(clarsimp)\n    apply (metis GR.allPreMaxDomSome_prime GR.derivation_initial_is_derivation option.distinct(1))\n   apply(clarsimp)\n   apply(subgoal_tac \"f i\\<le>n2\")\n    apply(case_tac \"k\\<le>f i\")\n     apply(rule_tac x=\"k\" in exI)\n     apply(rule_tac x=\"d2'\" in exI)\n     apply(clarsimp)\n     apply(rule conjI)\n      apply(simp add: get_configuration_def derivation_append_def get_label_def)\n     apply(simp add: get_configuration_def derivation_append_def get_label_def)\n    apply(rule_tac x=\"k\" in exI)\n    apply(rule_tac x=\"d2'\" in exI)\n    apply(clarsimp)\n    apply(rule conjI)\n     apply(simp add: get_configuration_def derivation_append_def get_label_def)\n    apply(simp add: get_configuration_def derivation_append_def get_label_def)\n   apply(simp add: simulating_derivation_def simulating_derivation_DEF_def)\n   apply(clarsimp)\n   apply (metis GR.allPreMaxDomSome_prime GR.derivation_initial_is_derivation option.distinct(1))\n  apply(rule impI)\n  apply(subgoal_tac \"i=Suc x\")\n   prefer 2\n   apply(force)\n  apply(erule_tac x=\"x\" in allE)\n  apply(clarsimp)\n  apply(subgoal_tac \"n2= f x\")\n   prefer 2\n   apply(simp add: simulating_derivation_def simulating_derivation_DEF_def)\n  apply(clarsimp)\n  apply(erule disjE)\n   apply(clarsimp)\n   apply(rule_tac\n      x=\"f x+k\"\n      in exI)\n   apply(rule_tac\n      x=\"der1 (the (get_configuration (derivation_append d2 d2a (f x) ((f x) + n))))\"\n      in exI)\n   apply(rule conjI)\n    apply(rule GR.der1_is_derivation)\n   apply(rule conjI)\n    apply(simp add: der1_def get_configuration_def get_label_def derivation_append_def)\n   apply(simp add: get_configuration_def get_label_def derivation_append_def)\n   apply(case_tac k)\n    apply(clarsimp)\n   apply(clarsimp)\n   apply(case_tac n)\n    apply(clarsimp)\n    apply(subgoal_tac \"False\")\n     apply(force)\n    apply (metis GR.derivationNoFromNone_prime GR.noSomeAfterMaxDom less_Suc_eq_0_disj)\n   apply(clarsimp)\n   apply(simp add: der1_def)\n   apply(subgoal_tac \"nat>nata\")\n    prefer 2\n    apply(force)\n   apply(clarsimp)\n   apply(rule_tac\n      m=\"Suc nat\"\n      and d=\"d2a\"\n      in GR.no_some_beyond_maximum_of_domain)\n      apply(force)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(clarsimp)\n  apply(rule_tac\n      x=\"f x+k\"\n      in exI)\n  apply(rule_tac\n      x=\"d2'\"\n      in exI)\n  apply(clarsimp)\n  apply(rule conjI)\n   apply(simp add: get_configuration_def)\n   apply(simp add: derivation_append_def)\n  apply(simp add: derivation_append_def)\n  apply(case_tac k)\n   apply(clarsimp)\n   apply (metis GR.initialNotEdgeSome_prime)\n  apply(clarsimp)\n  apply(simp add: get_label_def)\n  done\n\nlemma ATS_Simulation_Configuration_WeakReach_simulation_derivation_exists_witness: \"\n  relation_TSstructure G1 G2\n  \\<Longrightarrow> GL.derivation_initial G1 d1\n  \\<Longrightarrow> d1 x = Some (pair e1 c1)\n  \\<Longrightarrow> \\<exists>d2 n2 f.\n  GR.derivation_initial G2 d2\n  \\<and> maximum_of_domain d2 n2\n  \\<and> relation_initial_configuration G1 G2 (the (get_configuration (d1 0))) (the (get_configuration (d2 0)))\n  \\<and> relation_configuration G1 G2 c1 (the (get_configuration (d2 n2)))\n  \\<and> simulating_derivation G1 G2 d1 x d2 n2 f\n  \\<and> (case e1 of None \\<Rightarrow> True | Some e1' \\<Rightarrow> \\<exists>k d2'.\n  GR.derivation G2 d2'\n  \\<and> the(get_configuration(d2' 0)) = the(get_configuration(d2 n2))\n  \\<and> (case ((get_label (derivation_append d2 d2' n2 k))) of None \\<Rightarrow> False | Some e2' \\<Rightarrow> relation_labelsLR G1 G2 e1' e2'))\"\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule ATS_Simulation_Configuration_WeakReach_simulation_derivation_exists_witness_EXTENDED_Reach)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(erule exE)+\n  apply(rule_tac x=\"d2\" in exI)\n  apply(rule_tac x=\"n2\" in exI)\n  apply(rule_tac x=\"f\" in exI)\n  apply(clarsimp)\n  apply(erule_tac x=\"x\" in allE)\n  apply(clarsimp)\n  apply(case_tac e1)\n   apply(force)\n  apply(clarsimp)\n  apply(rule_tac x=\"k\" in exI)\n  apply(rule_tac x=\"d2'\" in exI)\n  apply(clarsimp)\n  apply(subgoal_tac \"n2=f x\")\n   apply(clarsimp)\n  apply(simp add: simulating_derivation_def simulating_derivation_DEF_def)\n  done\n\ntheorem ATS_Simulation_Configuration_WeakReach_exists: \"\n  relation_TSstructure G1 G2\n  \\<Longrightarrow> GL.derivation_initial G1 d1\n  \\<Longrightarrow> d1 x = Some (pair e1 c1)\n  \\<Longrightarrow> \\<exists>d2 n2 e2 c2.\n  GR.derivation_initial G2 d2\n  \\<and> d2 n2 = Some (pair e2 c2)\n  \\<and> (case e1 of None \\<Rightarrow> True\n    | Some e1' \\<Rightarrow>\n      \\<exists>k d2'.\n      GR.derivation G2 d2'\n      \\<and> the(get_configuration(d2' 0)) = the(get_configuration(d2 n2))\n      \\<and> (case ((get_label (derivation_append d2 d2' n2 k))) of\n          None \\<Rightarrow> False\n          | Some e2' \\<Rightarrow> relation_labelsLR G1 G2 e1' e2'))\"\n  apply(subgoal_tac \"\\<exists>d2 n2 f. GR.derivation_initial G2 d2 \\<and> maximum_of_domain d2 n2 \\<and> relation_initial_configuration G1 G2 (the (get_configuration (d1 0))) (the (get_configuration (d2 0))) \\<and> relation_configuration G1 G2 c1 (the (get_configuration (d2 n2))) \\<and> simulating_derivation G1 G2 d1 x d2 n2 f \\<and> (case e1 of None \\<Rightarrow> True | Some e1' \\<Rightarrow> \\<exists>k d2'. GR.derivation G2 d2' \\<and> the(get_configuration(d2' 0)) = the(get_configuration(d2 n2)) \\<and> (case ((get_label (derivation_append d2 d2' n2 k))) of None \\<Rightarrow> False | Some e2' \\<Rightarrow> relation_labelsLR G1 G2 e1' e2'))\")\n   prefer 2\n   apply(rule ATS_Simulation_Configuration_WeakReach_simulation_derivation_exists_witness)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(erule exE)+\n  apply(rename_tac d2 n2 f)(*strict*)\n  apply(erule conjE)+\n  apply(case_tac e1)\n   apply(rename_tac d2 n2 f)(*strict*)\n   apply(clarsimp)\n   apply(rule_tac\n      x=\"d2\"\n      in exI)\n   apply(clarsimp)\n   apply(simp add: maximum_of_domain_def)\n   apply(clarsimp)\n   apply(rename_tac d2 n2 f y)(*strict*)\n   apply(case_tac y)\n   apply(rename_tac d2 n2 f y option b)(*strict*)\n   apply(force)\n  apply(rename_tac d2 n2 f a)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d2 n2 f a k d2')(*strict*)\n  apply(rule_tac\n      x=\"d2\"\n      in exI)\n  apply(clarsimp)\n  apply(rule_tac\n      x=\"n2\"\n      in exI)\n  apply(rule conjI)\n   apply(rename_tac d2 n2 f a k d2')(*strict*)\n   apply(simp add: maximum_of_domain_def)\n   apply(clarsimp)\n   apply(rename_tac d2 n2 f a k d2' y)(*strict*)\n   apply(case_tac y)\n   apply(rename_tac d2 n2 f a k d2' y option b)(*strict*)\n   apply(force)\n  apply(rename_tac d2 n2 f a k d2')(*strict*)\n  apply(rule_tac\n      x=\"k\"\n      in exI)\n  apply(rule_tac\n      x=\"d2'\"\n      in exI)\n  apply(clarsimp)\n  done\n\ntheorem ATS_Simulation_Configuration_WeakReach_exists_ALT: \"\n  relation_TSstructure G1 G2\n  \\<Longrightarrow> GL.derivation_initial G1 d1\n  \\<Longrightarrow> d1 x = Some (pair (Some e1) c1)\n  \\<Longrightarrow> \\<exists>d2 n2 e2 c2.\n  GR.derivation_initial G2 d2\n  \\<and> d2 n2 = Some (pair (Some e2) c2)\n  \\<and> relation_labelsLR G1 G2 e1 e2\"\n  apply(subgoal_tac \"X\" for X)\n   prefer 2\n   apply(rule ATS_Simulation_Configuration_WeakReach_exists)\n     apply(force)\n    apply(force)\n   apply(force)\n  apply(erule exE)+\n  apply(rename_tac d2 n2 e2 c2)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d2 n2 e2 c2 k d2')(*strict*)\n  apply(rule_tac x=\"derivation_append d2 d2' n2\" in exI)\n  apply(rule conjI)\n   apply(rename_tac d2 n2 e2 c2 k d2')(*strict*)\n   apply(rule GR.derivation_append_preserves_derivation_initial)\n     apply(rename_tac d2 n2 e2 c2 k d2')(*strict*)\n     apply (metis AX_TSstructure_relation_TSstructure2_belongs)\n    apply(rename_tac d2 n2 e2 c2 k d2')(*strict*)\n    apply(force)\n   apply(rename_tac d2 n2 e2 c2 k d2')(*strict*)\n   apply(rule GR.derivation_append_preserves_derivation)\n     apply(rename_tac d2 n2 e2 c2 k d2')(*strict*)\n     apply(simp add: GR.derivation_initial_def)\n    apply(rename_tac d2 n2 e2 c2 k d2')(*strict*)\n    apply(force)\n   apply(rename_tac d2 n2 e2 c2 k d2')(*strict*)\n   apply(clarsimp)\n   apply(simp add: get_configuration_def)\n   apply(case_tac \"d2' 0\")\n    apply(rename_tac d2 n2 e2 c2 k d2')(*strict*)\n    apply(clarsimp)\n    apply(rename_tac d2 n2 e2 k d2')(*strict*)\n    apply(simp add: GR.derivation_def GR.derivation_initial_def)\n    apply(clarsimp)\n    apply(erule_tac x=\"0\" in allE)+\n    apply(clarsimp)\n   apply(rename_tac d2 n2 e2 c2 k d2' a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d2 n2 e2 k d2' a)(*strict*)\n   apply(case_tac a)\n   apply(rename_tac d2 n2 e2 k d2' a option conf)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d2 n2 e2 k d2' option conf)(*strict*)\n   apply(case_tac option)\n    apply(rename_tac d2 n2 e2 k d2' option conf)(*strict*)\n    apply(force)\n   apply(rename_tac d2 n2 e2 k d2' option conf a)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac d2 n2 e2 k d2' conf a)(*strict*)\n   apply(simp add: GR.derivation_def GR.derivation_initial_def)\n   apply(clarsimp)\n   apply(erule_tac x=\"0\" in allE)+\n   apply(clarsimp)\n  apply(rename_tac d2 n2 e2 c2 k d2')(*strict*)\n  apply(rule_tac x=\"k\" in exI)\n  apply(simp add: get_label_def)\n  apply(case_tac \"derivation_append d2 d2' n2 k\")\n   apply(rename_tac d2 n2 e2 c2 k d2')(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d2 n2 e2 c2 k d2' a)(*strict*)\n  apply(clarsimp)\n  apply(case_tac a)\n  apply(rename_tac d2 n2 e2 c2 k d2' a option conf)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac d2 n2 e2 c2 k d2' option conf)(*strict*)\n  apply(case_tac option)\n   apply(rename_tac d2 n2 e2 c2 k d2' option conf)(*strict*)\n   apply(clarsimp)\n  apply(rename_tac d2 n2 e2 c2 k d2' option conf a)(*strict*)\n  apply(clarsimp)\n  done\n\nend\n\nend\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_06_06/L_ATS_Simulation_Configuration_WeakLRReach.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6076631556226292, "lm_q2_score": 0.42250463481418826, "lm_q1q2_score": 0.2567404996563762}}
{"text": "\n(*  Title:      Jinja/JVM/JVMExecInstrInductive.thy\n    Author:     Susannah Mansky\n    2018, UIUC\n*)\n\nsection {* Inductive Program Execution in the JVM *}\n\ntheory JVMExecInstrInductive\nimports JVMExec\nbegin\n\ndatatype step_input = StepI instr | StepC cname | StepT addr\n\n\ninductive exec_step_ind :: \"[step_input, jvm_prog, heap, val list, val list,\n                  cname, mname, pc, init_call_status, frame list, sheap,jvm_state] \\<Rightarrow> bool\"\nwhere\n  exec_step_ind_Load:\n\"exec_step_ind (StepI (Load n)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n   (None, h, ((loc ! n) # stk, loc, C\\<^sub>0, M\\<^sub>0, Suc pc, ics)#frs, sh)\"\n\n| exec_step_ind_Store:\n\"exec_step_ind (StepI (Store n)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n   (None, h, (tl stk, loc[n:=hd stk], C\\<^sub>0, M\\<^sub>0, Suc pc, ics)#frs, sh)\"\n\n| exec_step_ind_Push:\n\"exec_step_ind (StepI (Push v)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n   (None, h, (v # stk, loc, C\\<^sub>0, M\\<^sub>0, Suc pc, ics)#frs, sh)\"\n\n|  exec_step_ind_NewOOM_Called:\n\"new_Addr h = None\n  \\<Longrightarrow> exec_step_ind (StepI (New C)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc Called frs sh\n   (\\<lfloor>addr_of_sys_xcpt OutOfMemory\\<rfloor>, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, No_ics)#frs, sh)\"\n\n|  exec_step_ind_NewOOM_Done:\n\"\\<lbrakk> sh C = Some(obj, Done); new_Addr h = None; ics \\<noteq> Called \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (New C)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n   (\\<lfloor>addr_of_sys_xcpt OutOfMemory\\<rfloor>, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n|  exec_step_ind_New_Called:\n\"new_Addr h = Some a\n  \\<Longrightarrow> exec_step_ind (StepI (New C)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc Called frs sh\n   (None, h(a\\<mapsto>blank P C), (Addr a#stk, loc, C\\<^sub>0, M\\<^sub>0, Suc pc, No_ics)#frs, sh)\"\n\n|  exec_step_ind_New_Done:\n\"\\<lbrakk> sh C = Some(obj, Done); new_Addr h = Some a; ics \\<noteq> Called \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (New C)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n   (None, h(a\\<mapsto>blank P C), (Addr a#stk, loc, C\\<^sub>0, M\\<^sub>0, Suc pc, ics)#frs, sh)\"\n\n|  exec_step_ind_New_Init:\n\"\\<lbrakk> \\<forall>obj. sh C \\<noteq> Some(obj, Done); ics \\<noteq> Called \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (New C)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n   (None, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, Calling C)#frs, sh)\"\n\n| exec_step_ind_Getfield_Null:\n\"hd stk = Null\n  \\<Longrightarrow> exec_step_ind (StepI (Getfield F C)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n   (\\<lfloor>addr_of_sys_xcpt NullPointer\\<rfloor>, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Getfield_NoField:\n\"\\<lbrakk> v = hd stk; (D,fs) = the(h(the_Addr v)); v \\<noteq> Null; \\<not>(\\<exists>t b. P \\<turnstile> D has F,b:t in C) \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (Getfield F C)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n   (\\<lfloor>addr_of_sys_xcpt NoSuchFieldError\\<rfloor>, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Getfield_Static:\n\"\\<lbrakk> v = hd stk; (D,fs) = the(h(the_Addr v)); v \\<noteq> Null; P \\<turnstile> D has F,Static:t in C \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (Getfield F C)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n   (\\<lfloor>addr_of_sys_xcpt IncompatibleClassChangeError\\<rfloor>, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Getfield:\n\"\\<lbrakk> v = hd stk; (D,fs) = the(h(the_Addr v)); (D',b,t) = field P C F; v \\<noteq> Null;\n   P \\<turnstile> D has F,NonStatic:t in C \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (Getfield F C)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n   (None, h, (the(fs(F,C))#(tl stk), loc, C\\<^sub>0, M\\<^sub>0, pc+1, ics)#frs, sh)\"\n\n| exec_step_ind_Getstatic_NoField:\n\"\\<not>(\\<exists>t b. P \\<turnstile> C has F,b:t in D)\n  \\<Longrightarrow> exec_step_ind (StepI (Getstatic C F D)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (\\<lfloor>addr_of_sys_xcpt NoSuchFieldError\\<rfloor>, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Getstatic_NonStatic:\n\"P \\<turnstile> C has F,NonStatic:t in D\n  \\<Longrightarrow> exec_step_ind (StepI (Getstatic C F D)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (\\<lfloor>addr_of_sys_xcpt IncompatibleClassChangeError\\<rfloor>, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Getstatic_Called:\n\"\\<lbrakk> (D',b,t) = field P D F; P \\<turnstile> C has F,Static:t in D;\n   the(sh D') = (sfs,i);\n   v = the (sfs F) \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (Getstatic C F D)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc Called frs sh\n    (None, h, (v#stk, loc, C\\<^sub>0, M\\<^sub>0, Suc pc, No_ics)#frs, sh)\"\n\n| exec_step_ind_Getstatic_Done:\n\"\\<lbrakk> (D',b,t) = field P D F; P \\<turnstile> C has F,Static:t in D;\n   ics \\<noteq> Called; sh D' = Some(sfs,Done);\n   v = the (sfs F) \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (Getstatic C F D)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (None, h, (v#stk, loc, C\\<^sub>0, M\\<^sub>0, Suc pc, ics)#frs, sh)\"\n\n| exec_step_ind_Getstatic_Init:\n\"\\<lbrakk> (D',b,t) = field P D F; P \\<turnstile> C has F,Static:t in D;\n   \\<forall>sfs. sh D' \\<noteq> Some(sfs,Done); ics \\<noteq> Called \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (Getstatic C F D)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (None, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, Calling D')#frs, sh)\"\n\n| exec_step_ind_Putfield_Null:\n\"hd(tl stk) = Null\n  \\<Longrightarrow> exec_step_ind (StepI (Putfield F C)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n  (\\<lfloor>addr_of_sys_xcpt NullPointer\\<rfloor>, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Putfield_NoField:\n\"\\<lbrakk> r = hd(tl stk); a = the_Addr r; (D,fs) = the (h a); r \\<noteq> Null; \\<not>(\\<exists>t b. P \\<turnstile> D has F,b:t in C) \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (Putfield F C)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n  (\\<lfloor>addr_of_sys_xcpt NoSuchFieldError\\<rfloor>, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Putfield_Static:\n\"\\<lbrakk> r = hd(tl stk); a = the_Addr r; (D,fs) = the (h a); r \\<noteq> Null; P \\<turnstile> D has F,Static:t in C \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (Putfield F C)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n  (\\<lfloor>addr_of_sys_xcpt IncompatibleClassChangeError\\<rfloor>, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Putfield:\n\"\\<lbrakk> v = hd stk; r = hd(tl stk); a = the_Addr r; (D,fs) = the (h a); (D',b,t) = field P C F;\n   r \\<noteq> Null; P \\<turnstile> D has F,NonStatic:t in C \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (Putfield F C)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n  (None, h(a \\<mapsto> (D, fs((F,C) \\<mapsto> v))), (tl (tl stk), loc, C\\<^sub>0, M\\<^sub>0, pc+1, ics)#frs, sh)\"\n\n| exec_step_ind_Putstatic_NoField:\n\"\\<not>(\\<exists>t b. P \\<turnstile> C has F,b:t in D)\n  \\<Longrightarrow> exec_step_ind (StepI (Putstatic C F D)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (\\<lfloor>addr_of_sys_xcpt NoSuchFieldError\\<rfloor>, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Putstatic_NonStatic:\n\"P \\<turnstile> C has F,NonStatic:t in D\n  \\<Longrightarrow> exec_step_ind (StepI (Putstatic C F D)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (\\<lfloor>addr_of_sys_xcpt IncompatibleClassChangeError\\<rfloor>, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Putstatic_Called:\n\"\\<lbrakk> (D',b,t) = field P D F; P \\<turnstile> C has F,Static:t in D; the(sh D') = (sfs, i) \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (Putstatic C F D)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc Called frs sh\n    (None, h, (tl stk, loc, C\\<^sub>0, M\\<^sub>0, Suc pc, No_ics)#frs, sh(D':=Some ((sfs(F \\<mapsto> hd stk)), i)))\"\n\n| exec_step_ind_Putstatic_Done:\n\"\\<lbrakk> (D',b,t) = field P D F; P \\<turnstile> C has F,Static:t in D;\n   ics \\<noteq> Called; sh D' = Some (sfs, Done) \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (Putstatic C F D)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (None, h, (tl stk, loc, C\\<^sub>0, M\\<^sub>0, Suc pc, ics)#frs, sh(D':=Some ((sfs(F \\<mapsto> hd stk)), Done)))\"\n\n| exec_step_ind_Putstatic_Init:\n\"\\<lbrakk> (D',b,t) = field P D F; P \\<turnstile> C has F,Static:t in D;\n   \\<forall>sfs. sh D' \\<noteq> Some (sfs, Done); ics \\<noteq> Called \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (Putstatic C F D)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (None, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, Calling D')#frs, sh)\"\n\n| exec_step_ind_Checkcast:\n\"cast_ok P C h (hd stk)\n  \\<Longrightarrow> exec_step_ind (StepI (Checkcast C)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (None, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, Suc pc, ics)#frs, sh)\"\n\n| exec_step_ind_Checkcast_Error:\n\"\\<not>cast_ok P C h (hd stk)\n  \\<Longrightarrow> exec_step_ind (StepI (Checkcast C)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (\\<lfloor>addr_of_sys_xcpt ClassCast\\<rfloor>, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Invoke_Null:\n\"stk!n = Null\n  \\<Longrightarrow> exec_step_ind (StepI (Invoke M n)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (\\<lfloor>addr_of_sys_xcpt NullPointer\\<rfloor>, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Invoke_NoMethod:\n\"\\<lbrakk> r = stk!n; C = fst(the(h(the_Addr r))); r \\<noteq> Null;\n   \\<not>(\\<exists>Ts T m D b. P \\<turnstile> C sees M,b:Ts \\<rightarrow> T = m in D) \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (Invoke M n)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (\\<lfloor>addr_of_sys_xcpt NoSuchMethodError\\<rfloor>, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Invoke_Static:\n\"\\<lbrakk> r = stk!n; C = fst(the(h(the_Addr r)));\n   (D,b,Ts,T,mxs,mxl\\<^sub>0,ins,xt)= method P C M; r \\<noteq> Null;\n   P \\<turnstile> C sees M,Static:Ts \\<rightarrow> T = m in D \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (Invoke M n)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (\\<lfloor>addr_of_sys_xcpt IncompatibleClassChangeError\\<rfloor>, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Invoke:\n\"\\<lbrakk> ps = take n stk; r = stk!n; C = fst(the(h(the_Addr r)));\n   (D,b,Ts,T,mxs,mxl\\<^sub>0,ins,xt)= method P C M; r \\<noteq> Null;\n   P \\<turnstile> C sees M,NonStatic:Ts \\<rightarrow> T = m in D;\n   f' = ([],[r]@(rev ps)@(replicate mxl\\<^sub>0 undefined),D,M,0,No_ics) \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (Invoke M n)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (None, h, f'#(stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Invokestatic_NoMethod:\n\"\\<lbrakk> (D,b,Ts,T,mxs,mxl\\<^sub>0,ins,xt)= method P C M; \\<not>(\\<exists>Ts T m D b. P \\<turnstile> C sees M,b:Ts \\<rightarrow> T = m in D) \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (Invokestatic C M n)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (\\<lfloor>addr_of_sys_xcpt NoSuchMethodError\\<rfloor>, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Invokestatic_NonStatic:\n\"\\<lbrakk> (D,b,Ts,T,mxs,mxl\\<^sub>0,ins,xt)= method P C M; P \\<turnstile> C sees M,NonStatic:Ts \\<rightarrow> T = m in D \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (Invokestatic C M n)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (\\<lfloor>addr_of_sys_xcpt IncompatibleClassChangeError\\<rfloor>, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Invokestatic_Called:\n\"\\<lbrakk> ps  = take n stk; (D,b,Ts,T,mxs,mxl\\<^sub>0,ins,xt) = method P C M;\n   P \\<turnstile> C sees M,Static:Ts \\<rightarrow> T = m in D;\n   f'  = ([],(rev ps)@(replicate mxl\\<^sub>0 undefined),D,M,0,No_ics) \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (Invokestatic C M n)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc Called frs sh\n    (None, h, f'#(stk, loc, C\\<^sub>0, M\\<^sub>0, pc, No_ics)#frs, sh)\"\n\n| exec_step_ind_Invokestatic_Done:\n\"\\<lbrakk> ps  = take n stk; (D,b,Ts,T,mxs,mxl\\<^sub>0,ins,xt) = method P C M;\n   P \\<turnstile> C sees M,Static:Ts \\<rightarrow> T = m in D;\n   ics \\<noteq> Called; sh D = Some (sfs, Done);\n   f'  = ([],(rev ps)@(replicate mxl\\<^sub>0 undefined),D,M,0,No_ics) \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (Invokestatic C M n)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (None, h, f'#(stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Invokestatic_Init:\n\"\\<lbrakk> (D,b,Ts,T,mxs,mxl\\<^sub>0,ins,xt) = method P C M;\n   P \\<turnstile> C sees M,Static:Ts \\<rightarrow> T = m in D;\n   \\<forall>sfs. sh D \\<noteq> Some (sfs, Done); ics \\<noteq> Called \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepI (Invokestatic C M n)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (None, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, Calling D)#frs, sh)\"\n\n| exec_step_ind_Return_Last_Init:\n \"exec_step_ind (StepI Return) P h stk\\<^sub>0 loc\\<^sub>0 C\\<^sub>0 clinit pc ics [] sh\n    (None, h, [], sh(C\\<^sub>0:=Some(fst(the(sh C\\<^sub>0)), Done)))\"\n\n| exec_step_ind_Return_Last:\n \"M\\<^sub>0 \\<noteq> clinit\n   \\<Longrightarrow> exec_step_ind (StepI Return) P h stk\\<^sub>0 loc\\<^sub>0 C\\<^sub>0 M\\<^sub>0 pc ics [] sh (None, h, [], sh)\"\n\n| exec_step_ind_Return_Init:\n \"\\<lbrakk> (D,b,Ts,T,m) = method P C\\<^sub>0 clinit \\<rbrakk>\n   \\<Longrightarrow> exec_step_ind (StepI Return) P h stk\\<^sub>0 loc\\<^sub>0 C\\<^sub>0 clinit pc ics ((stk',loc',C',m',pc',ics')#frs') sh\n     (None, h, (stk',loc',C',m',pc',ics')#frs', sh(C\\<^sub>0:=Some(fst(the(sh C\\<^sub>0)), Done)))\"\n\n| exec_step_ind_Return_NonStatic:\n \"\\<lbrakk> (D,NonStatic,Ts,T,m) = method P C\\<^sub>0 M\\<^sub>0; M\\<^sub>0 \\<noteq> clinit \\<rbrakk>\n   \\<Longrightarrow> exec_step_ind (StepI Return) P h stk\\<^sub>0 loc\\<^sub>0 C\\<^sub>0 M\\<^sub>0 pc ics ((stk',loc',C',m',pc',ics')#frs') sh\n     (None, h, ((hd stk\\<^sub>0)#(drop (length Ts + 1) stk'),loc',C',m',Suc pc',ics')#frs', sh)\"\n\n| exec_step_ind_Return_Static:\n \"\\<lbrakk> (D,Static,Ts,T,m) = method P C\\<^sub>0 M\\<^sub>0; M\\<^sub>0 \\<noteq> clinit \\<rbrakk>\n   \\<Longrightarrow> exec_step_ind (StepI Return) P h stk\\<^sub>0 loc\\<^sub>0 C\\<^sub>0 M\\<^sub>0 pc ics ((stk',loc',C',m',pc',ics')#frs') sh\n     (None, h, ((hd stk\\<^sub>0)#(drop (length Ts) stk'),loc',C',m',Suc pc',ics')#frs', sh)\"\n\n| exec_step_ind_Pop:\n\"exec_step_ind (StepI Pop) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n  (None, h, (tl stk, loc, C\\<^sub>0, M\\<^sub>0, Suc pc, ics)#frs, sh)\"\n\n| exec_step_ind_IAdd:\n\"exec_step_ind (StepI IAdd) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n  (None, h, (Intg (the_Intg (hd (tl stk)) + the_Intg (hd stk))#(tl (tl stk)), loc, C\\<^sub>0, M\\<^sub>0, Suc pc, ics)#frs, sh)\"\n\n| exec_step_ind_IfFalse_False:\n\"hd stk = Bool False\n  \\<Longrightarrow> exec_step_ind (StepI (IfFalse i)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (None, h, (tl stk, loc, C\\<^sub>0, M\\<^sub>0, nat(int pc+i), ics)#frs, sh)\"\n\n| exec_step_ind_IfFalse_nFalse:\n\"hd stk \\<noteq> Bool False\n  \\<Longrightarrow> exec_step_ind (StepI (IfFalse i)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (None, h, (tl stk, loc, C\\<^sub>0, M\\<^sub>0, Suc pc, ics)#frs, sh)\"\n\n| exec_step_ind_CmpEq:\n\"exec_step_ind (StepI CmpEq) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (None, h, (Bool (hd (tl stk) = hd stk) # tl (tl stk), loc, C\\<^sub>0, M\\<^sub>0, Suc pc, ics)#frs, sh)\"\n\n| exec_step_ind_Goto:\n\"exec_step_ind (StepI (Goto i)) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n   (None, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, nat(int pc+i), ics)#frs, sh)\"\n\n| exec_step_ind_Throw:\n\"hd stk \\<noteq> Null\n  \\<Longrightarrow> exec_step_ind (StepI Throw) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (\\<lfloor>the_Addr (hd stk)\\<rfloor>, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Throw_Null:\n\"hd stk = Null\n  \\<Longrightarrow> exec_step_ind (StepI Throw) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (\\<lfloor>addr_of_sys_xcpt NullPointer\\<rfloor>, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Init_None_Called:\n\"\\<lbrakk> sh C = None; ics = Called \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepC C) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (None, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, Calling C)#frs, sh(C := Some (sblank P C, Prepared)))\"\n\n| exec_step_ind_Init_None_nCalled:\n\"\\<lbrakk> sh C = None; ics \\<noteq> Called \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepC C) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (None, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ICalling C)#frs, sh(C := Some (sblank P C, Prepared)))\"\n\n| exec_step_ind_Init_Done:\n\"sh C = Some (sfs, Done)\n  \\<Longrightarrow> exec_step_ind (StepC C) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (None, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Init_Processing:\n\"sh C = Some (sfs, Processing)\n  \\<Longrightarrow> exec_step_ind (StepC C) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (None, h, (stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Init_Error:\n\"\\<lbrakk> sh C = Some (sfs, Error); (stk',loc',D',M',pc',ics') = create_init_frame P C \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepC C) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (None, h, (stk',loc',D',M',pc',Throwing (addr_of_sys_xcpt NoClassDefFoundError))\n                            #(stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh)\"\n\n| exec_step_ind_Init_Prepared_Object:\n\"\\<lbrakk> sh C = Some (sfs, Prepared);\n   sh' = sh(C:=Some(fst(the(sh C)), Processing));\n   C = Object \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepC C) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (None, h, create_init_frame P C#(stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh')\"\n\n| exec_step_ind_Init_Prepared_nObject:\n\"\\<lbrakk> sh C = Some (sfs, Prepared); (stk',loc',C',m',pc',ics') = create_init_frame P C;\n   sh' = sh(C:=Some(fst(the(sh C)), Processing));\n   C \\<noteq> Object; D = fst(the(class P C)) \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepC C) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh\n    (None, h, (stk',loc',C',m',pc',ICalling D)#(stk, loc, C\\<^sub>0, M\\<^sub>0, pc, ics)#frs, sh')\"\n\n| exec_step_ind_InitThrow_Init:\n\"ics' \\<noteq> Called\n  \\<Longrightarrow> exec_step_ind (StepT a) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics ((stk',loc',C',clinit,pc',ics')#frs') sh\n    (None, h, (stk',loc',C',clinit,pc',Throwing a)#frs', (sh(C\\<^sub>0:=Some(fst(the(sh C\\<^sub>0)), Error))))\"\n\n| exec_step_ind_InitThrow_Called:\n\"exec_step_ind (StepT a) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics ((stk',loc',C',m',pc',Called)#frs') sh\n    (\\<lfloor>a\\<rfloor>, h, (stk',loc',C',m',pc',No_ics)#frs', (sh(C\\<^sub>0:=Some(fst(the(sh C\\<^sub>0)), Error))))\"\n\n| exec_step_ind_InitThrow_Other:\n\"\\<lbrakk> ics' \\<noteq> Called; m' \\<noteq> clinit \\<rbrakk>\n  \\<Longrightarrow> exec_step_ind (StepT a) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics ((stk',loc',C',m',pc',ics')#frs') sh\n    (\\<lfloor>a\\<rfloor>, h, (stk',loc',C',m',pc',ics')#frs', (sh(C\\<^sub>0:=Some(fst(the(sh C\\<^sub>0)), Error))))\"\n\n| exec_step_ind_InitThrow_Last:\n\"exec_step_ind (StepT a) P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics [] sh\n    (\\<lfloor>a\\<rfloor>, h, [], (sh(C\\<^sub>0:=Some(fst(the(sh C\\<^sub>0)), Error))))\"\n\n(** ******* **)\n\ninductive_cases exec_step_ind_cases [cases set]:\n \"exec_step_ind (StepI (Load n)) P h stk loc C M pc ics frs sh \\<sigma>\"\n \"exec_step_ind (StepI (Store n)) P h stk loc C M pc ics frs sh \\<sigma>\"\n \"exec_step_ind (StepI (Push v)) P h stk loc C M pc ics frs sh \\<sigma>\"\n \"exec_step_ind (StepI (New C)) P h stk loc C M pc ics frs sh \\<sigma>\"\n \"exec_step_ind (StepI (Getfield F C)) P h stk loc C M pc ics frs sh \\<sigma>\"\n \"exec_step_ind (StepI (Getstatic C F D)) P h stk loc C M pc ics frs sh \\<sigma>\"\n \"exec_step_ind (StepI (Putfield F C)) P h stk loc C M pc ics frs sh \\<sigma>\"\n \"exec_step_ind (StepI (Putstatic C F D)) P h stk loc C M pc ics frs sh \\<sigma>\"\n \"exec_step_ind (StepI (Checkcast C)) P h stk loc C M pc ics frs sh \\<sigma>\"\n \"exec_step_ind (StepI (Invoke M n)) P h stk loc C M pc ics frs sh \\<sigma>\"\n \"exec_step_ind (StepI (Invokestatic C M n)) P h stk loc C M pc ics frs sh \\<sigma>\"\n \"exec_step_ind (StepI Return) P h stk loc C M pc ics frs sh \\<sigma>\"\n \"exec_step_ind (StepI Pop) P h stk loc C M pc ics frs sh \\<sigma>\"\n \"exec_step_ind (StepI IAdd) P h stk loc C M pc ics frs sh \\<sigma>\"\n \"exec_step_ind (StepI (IfFalse i)) P h stk loc C M pc ics frs sh \\<sigma>\"\n \"exec_step_ind (StepI CmpEq) P h stk loc C M pc ics frs sh \\<sigma>\"\n \"exec_step_ind (StepI (Goto i)) P h stk loc C M pc ics frs sh \\<sigma>\"\n \"exec_step_ind (StepI Throw) P h stk loc C M pc ics frs sh \\<sigma>\"\n \"exec_step_ind (StepC C) P h stk loc C M pc ics frs sh \\<sigma>\"\n \"exec_step_ind (StepT a) P h stk loc C M pc ics frs sh \\<sigma>\"\n\n(* HERE: MOVE *)\nfun exec_step_input :: \"[jvm_prog, cname, mname, pc, init_call_status]\n   \\<Rightarrow> step_input \\<times> init_call_status\" where\n\"exec_step_input P C M pc (Calling C') = (StepC C', Called)\" |\n\"exec_step_input P C M pc (ICalling C') = (StepC C', No_ics)\" |\n\"exec_step_input P C M pc (Throwing a) = (StepT a, Throwing a)\" |\n\"exec_step_input P C M pc ics = (StepI (instrs_of P C M ! pc), ics)\"\n\nlemma exec_step_imp_exec_step_ind:\nassumes \"exec_step P h stk loc C M pc ics frs sh = (xp', h', frs', sh')\"\n  and \"exec_step_input P C M pc ics = (si, ics')\"\nshows \"exec_step_ind si P h stk loc C M pc ics' frs sh (xp', h', frs', sh')\"\nproof(cases si)\n  case (StepT a)\n  then have exec_Throwing: \n    \"exec_Throwing a P h stk loc C M pc (Throwing a) frs sh = (xp', h', frs', sh')\"\n    \"ics = ics'\" using assms by(cases ics, auto)+\n  then obtain stk' loc' C' m' pc' ics' where lets: \"(stk',loc',C',m',pc',ics') = hd frs\"\n     by(cases \"hd frs\", simp)\n  then show ?thesis using exec_step_ind_InitThrow_Init exec_step_ind_InitThrow_Called\n    exec_step_ind_InitThrow_Other exec_step_ind_InitThrow_Last StepT exec_Throwing\n   by(cases frs; cases \"m' = clinit\"; cases ics', auto)\nnext\n  case (StepC C1)\n  obtain D b Ts T m where lets: \"method P C1 clinit = (D,b,Ts,T,m)\" by(cases \"method P C1 clinit\")\n  then obtain mxs mxl\\<^sub>0 ins xt where m: \"m = (mxs,mxl\\<^sub>0,ins,xt)\" by(cases m)\n  show ?thesis\n  proof(cases \"sh C1\")\n    case None then show ?thesis\n     using exec_step_ind_Init_None_Called exec_step_ind_Init_None_nCalled StepC assms\n       by(cases ics, auto)\n  next\n    case (Some a)\n    then obtain sfs i where sfsi: \"a = (sfs,i)\" by(cases a)\n    then show ?thesis using exec_step_ind_Init_Done exec_step_ind_Init_Processing\n    exec_step_ind_Init_Error m lets Some StepC assms\n    proof(cases i)\n      case Prepared\n      show ?thesis\n      using exec_step_ind_Init_Prepared_Object[where P=P] exec_step_ind_Init_Prepared_nObject\n       sfsi m lets Prepared Some StepC assms by(cases ics, auto split: if_split_asm)\n    qed(cases ics, auto)+\n  qed\nnext\n  case (StepI i)\n  then have exec_instr: \"exec_instr i P h stk loc C M pc ics' frs sh = (xp', h', frs', sh')\"\n    \"ics = ics'\" using assms by(cases ics, auto)+\n  show ?thesis\n  proof(cases i)\n    case (Load x1) then show ?thesis using exec_instr exec_step_ind_Load StepI by auto\n  next\n    case (Store x2) then show ?thesis using exec_instr exec_step_ind_Store StepI by auto\n  next\n    case (Push x3) then show ?thesis using exec_instr exec_step_ind_Push StepI by auto\n  next\n    case (New C1)\n    then obtain sfs i where sfsi: \"the(sh C1) = (sfs,i)\" by(cases \"the(sh C1)\")\n    then show ?thesis using exec_step_ind_New_Called exec_step_ind_NewOOM_Called\n       exec_step_ind_New_Done exec_step_ind_NewOOM_Done\n       exec_step_ind_New_Init sfsi New StepI exec_instr by(cases ics; cases i, auto)\n  next\n    case (Getfield F1 C1)\n    then obtain D fs D' b t where lets: \"the(h(the_Addr (hd stk))) = (D,fs)\"\n      \"field P C1 F1 = (D',b,t)\" by(cases \"the(h(the_Addr (hd stk)))\", cases \"field P C1 F1\")\n    then have \"\\<And>b' t'. P \\<turnstile> D has F1,b':t' in C1 \\<Longrightarrow> (D', b, t) = (C1, b', t')\"\n      using field_def2 has_field_idemp has_field_sees by fastforce\n    then show ?thesis using exec_step_ind_Getfield_Null exec_step_ind_Getfield_NoField\n       exec_step_ind_Getfield_Static lets Getfield StepI exec_instr\n      by(cases b, auto split: if_split_asm) (metis Suc_eq_plus1 exec_step_ind_Getfield)+\n  next\n    case (Getstatic C1 F1 D1)\n    then obtain D' b t where lets: \"field P D1 F1 = (D',b,t)\" by(cases \"field P D1 F1\")\n    then have field: \"\\<And>b' t'. P \\<turnstile> C1 has F1,b':t' in D1 \\<Longrightarrow> (D', b, t) = (D1, b', t')\"\n      using field_def2 has_field_idemp has_field_sees by fastforce\n    show ?thesis\n    proof(cases b)\n      case NonStatic then show ?thesis\n       using exec_step_ind_Getstatic_NoField exec_step_ind_Getstatic_NonStatic\n        field lets Getstatic exec_instr StepI by(auto split: if_split_asm) fastforce\n    next\n      case Static show ?thesis\n      proof(cases \"ics = Called\")\n        case True then show ?thesis using exec_step_ind_Getstatic_NoField\n          exec_step_ind_Getstatic_Called exec_step_ind_Getstatic_Init\n          Static field lets Getstatic exec_instr StepI\n         by(cases \"the(sh D1)\", cases ics, auto split: if_split_asm) metis\n      next\n        case False\n        then have nCalled: \"ics \\<noteq> Called\" by simp\n        show ?thesis\n        proof(cases \"sh D1\")\n          case None\n          then have nDone: \"\\<forall>sfs. sh D1 \\<noteq> Some(sfs, Done)\" by simp\n          then show ?thesis using exec_step_ind_Getstatic_NoField\n            exec_step_ind_Getstatic_Init[where sh=sh, OF _ _ nDone nCalled]\n            field lets None False Static Getstatic exec_instr StepI\n           by(cases ics, auto split: if_split_asm) metis+\n        next\n          case (Some a)\n          then obtain sfs i where sfsi: \"a=(sfs,i)\" by(cases a)\n          show ?thesis using exec_step_ind_Getstatic_NoField\n            exec_step_ind_Getstatic_Init sfsi False Static Some field lets Getstatic exec_instr\n          proof(cases \"i = Done\")\n            case True then show ?thesis using exec_step_ind_Getstatic_NoField\n              exec_step_ind_Getstatic_Done[OF _ _ nCalled] exec_step_ind_Getstatic_Init\n              sfsi False Static Some field lets Getstatic exec_instr StepI\n             by(cases ics, auto split: if_split_asm) metis+\n          next\n            case nD: False\n            then have nDone: \"\\<forall>sfs. sh D1 \\<noteq> Some(sfs, Done)\" using sfsi Some by simp\n            show ?thesis using nD\n            proof(cases i)\n              case Processing then show ?thesis using exec_step_ind_Getstatic_NoField\n                exec_step_ind_Getstatic_Init[where sh=sh, OF _ _ nDone nCalled]\n                sfsi False Static Some field lets Getstatic exec_instr StepI\n               by(cases ics, auto split: if_split_asm) metis+\n            next\n              case Prepared then show ?thesis using exec_step_ind_Getstatic_NoField\n                exec_step_ind_Getstatic_Init[where sh=sh, OF _ _ nDone nCalled]\n                sfsi False Static Some field lets Getstatic exec_instr StepI\n               by(cases ics, auto split: if_split_asm) metis+\n            next\n              case Error then show ?thesis using exec_step_ind_Getstatic_NoField\n                exec_step_ind_Getstatic_Init[where sh=sh, OF _ _ nDone nCalled]\n                sfsi False Static Some field lets Getstatic exec_instr StepI\n               by(cases ics, auto split: if_split_asm) metis+\n            qed(simp)\n          qed\n        qed\n      qed\n    qed\n  next\n    case (Putfield F1 C1)\n    then obtain D fs D' b t where lets: \"the(h(the_Addr (hd(tl stk)))) = (D,fs)\"\n      \"field P C1 F1 = (D',b,t)\" by(cases \"the(h(the_Addr (hd(tl stk))))\", cases \"field P C1 F1\")\n    then have \"\\<And>b' t'. P \\<turnstile> D has F1,b':t' in C1 \\<Longrightarrow> (D', b, t) = (C1, b', t')\"\n      using field_def2 has_field_idemp has_field_sees by fastforce\n    then show ?thesis using exec_step_ind_Putfield_Null exec_step_ind_Putfield_NoField\n       exec_step_ind_Putfield_Static lets Putfield exec_instr StepI\n      by(cases b, auto split: if_split_asm) (metis Suc_eq_plus1 exec_step_ind_Putfield)+\n  next\n    case (Putstatic C1 F1 D1)\n    then obtain D' b t where lets: \"field P D1 F1 = (D',b,t)\" by(cases \"field P D1 F1\")\n    then have field: \"\\<And>b' t'. P \\<turnstile> C1 has F1,b':t' in D1 \\<Longrightarrow> (D', b, t) = (D1, b', t')\"\n      using field_def2 has_field_idemp has_field_sees by fastforce\n    show ?thesis\n    proof(cases b)\n      case NonStatic then show ?thesis\n       using exec_step_ind_Putstatic_NoField exec_step_ind_Putstatic_NonStatic\n        field lets Putstatic exec_instr StepI by(auto split: if_split_asm) fastforce\n    next\n      case Static show ?thesis\n      proof(cases \"ics = Called\")\n        case True then show ?thesis using exec_step_ind_Putstatic_NoField\n          exec_step_ind_Putstatic_Called exec_step_ind_Putstatic_Init\n          Static field lets Putstatic exec_instr StepI\n         by(cases \"the(sh D1)\", cases ics, auto split: if_split_asm) metis\n      next\n        case False\n        then have nCalled: \"ics \\<noteq> Called\" by simp\n        show ?thesis\n        proof(cases \"sh D1\")\n          case None\n          then have nDone: \"\\<forall>sfs. sh D1 \\<noteq> Some(sfs, Done)\" by simp\n          then show ?thesis using exec_step_ind_Putstatic_NoField\n            exec_step_ind_Putstatic_Init[where sh=sh, OF _ _ nDone nCalled]\n            field lets None False Static Putstatic exec_instr StepI\n           by(cases ics, auto split: if_split_asm) metis+\n        next\n          case (Some a)\n          then obtain sfs i where sfsi: \"a=(sfs,i)\" by(cases a)\n          show ?thesis using exec_step_ind_Putstatic_NoField\n            exec_step_ind_Putstatic_Init sfsi False Static Some field lets Putstatic exec_instr\n          proof(cases \"i = Done\")\n            case True then show ?thesis using exec_step_ind_Putstatic_NoField\n              exec_step_ind_Putstatic_Done[OF _ _ nCalled] exec_step_ind_Putstatic_Init\n              sfsi False Static Some field lets Putstatic exec_instr StepI\n             by(cases ics, auto split: if_split_asm) metis+\n          next\n            case nD: False\n            then have nDone: \"\\<forall>sfs. sh D1 \\<noteq> Some(sfs, Done)\" using sfsi Some by simp\n            show ?thesis using nD\n            proof(cases i)\n              case Processing then show ?thesis using exec_step_ind_Putstatic_NoField\n                exec_step_ind_Putstatic_Init[where sh=sh, OF _ _ nDone nCalled]\n                sfsi False Static Some field lets Putstatic exec_instr StepI\n               by(cases ics, auto split: if_split_asm) metis+\n            next\n              case Prepared then show ?thesis using exec_step_ind_Putstatic_NoField\n                exec_step_ind_Putstatic_Init[where sh=sh, OF _ _ nDone nCalled]\n                sfsi False Static Some field lets Putstatic exec_instr StepI\n               by(cases ics, auto split: if_split_asm) metis+\n            next\n              case Error then show ?thesis using exec_step_ind_Putstatic_NoField\n                exec_step_ind_Putstatic_Init[where sh=sh, OF _ _ nDone nCalled]\n                sfsi False Static Some field lets Putstatic exec_instr StepI\n               by(cases ics, auto split: if_split_asm) metis+\n            qed(simp)\n          qed\n        qed\n      qed\n    qed\n  next\n    case (Checkcast x9) then show ?thesis\n     using exec_step_ind_Checkcast exec_step_ind_Checkcast_Error exec_instr StepI\n       by(auto split: if_split_asm)\n  next\n    case (Invoke M1 n) show ?thesis\n    proof(cases \"stk!n = Null\")\n      case True then show ?thesis using exec_step_ind_Invoke_Null Invoke exec_instr StepI\n       by clarsimp\n    next\n      case False\n      let ?C = \"cname_of h (the_Addr (stk ! n))\"\n      obtain D b Ts T m where method: \"method P ?C M1 = (D,b,Ts,T,m)\" by(cases \"method P ?C M1\")\n      then obtain mxs mxl\\<^sub>0 ins xt where \"m = (mxs,mxl\\<^sub>0,ins,xt)\" by(cases m)\n      then show ?thesis using exec_step_ind_Invoke_NoMethod\n        exec_step_ind_Invoke_Static exec_step_ind_Invoke method False Invoke exec_instr StepI\n       by(cases b; auto split: if_split_asm)\n    qed\n  next\n    case (Invokestatic C1 M1 n)\n    obtain D b Ts T m where lets: \"method P C1 M1 = (D,b,Ts,T,m)\" by(cases \"method P C1 M1\")\n    then obtain mxs mxl\\<^sub>0 ins xt where m: \"m = (mxs,mxl\\<^sub>0,ins,xt)\" by(cases m)\n    have method: \"\\<And>b' Ts' t' m' D'. P \\<turnstile> C1 sees M1,b':Ts' \\<rightarrow> t' = m' in D'\n     \\<Longrightarrow> (D,b,Ts,T,m) = (D',b',Ts',t',m')\" using lets by auto\n    show ?thesis\n    proof(cases b)\n      case NonStatic then show ?thesis\n       using exec_step_ind_Invokestatic_NoMethod exec_step_ind_Invokestatic_NonStatic\n        m method lets Invokestatic exec_instr StepI  by(auto split: if_split_asm)\n    next\n      case Static show ?thesis\n      proof(cases \"ics = Called\")\n        case True then show ?thesis using exec_step_ind_Invokestatic_NoMethod\n          exec_step_ind_Invokestatic_Called exec_step_ind_Invokestatic_Init\n          Static m method lets Invokestatic exec_instr StepI\n         by(cases ics, auto split: if_split_asm)\n      next\n        case False\n        then have nCalled: \"ics \\<noteq> Called\" by simp\n        show ?thesis\n        proof(cases \"sh D\")\n          case None\n          then have nDone: \"\\<forall>sfs. sh D \\<noteq> Some(sfs, Done)\" by simp\n          show ?thesis using exec_step_ind_Invokestatic_NoMethod\n            exec_step_ind_Invokestatic_Init[where sh=sh, OF _ _ nDone nCalled]\n            method m lets None False Static Invokestatic exec_instr StepI\n           by(cases ics, auto split: if_split_asm)\n        next\n          case (Some a)\n          then obtain sfs i where sfsi: \"a=(sfs,i)\" by(cases a)\n          show ?thesis using exec_step_ind_Invokestatic_NoMethod\n            exec_step_ind_Invokestatic_Init sfsi False Static Some method lets Invokestatic exec_instr\n          proof(cases \"i = Done\")\n            case True then show ?thesis using exec_step_ind_Invokestatic_NoMethod\n              exec_step_ind_Invokestatic_Done[OF _ _ _ nCalled] exec_step_ind_Invokestatic_Init\n              sfsi False Static Some m method lets Invokestatic exec_instr StepI\n             by(cases ics, auto split: if_split_asm)\n          next\n            case nD: False\n            then have nDone: \"\\<forall>sfs. sh D \\<noteq> Some(sfs, Done)\" using sfsi Some by simp\n            show ?thesis using nD\n            proof(cases i)\n              case Processing then show ?thesis using exec_step_ind_Invokestatic_NoMethod\n                exec_step_ind_Invokestatic_Init[where sh=sh, OF _ _ nDone nCalled]\n                sfsi False Static Some m method lets Invokestatic exec_instr StepI\n               by(cases ics, auto split: if_split_asm)\n            next\n              case Prepared then show ?thesis using exec_step_ind_Invokestatic_NoMethod\n                exec_step_ind_Invokestatic_Init[where sh=sh, OF _ _ nDone nCalled]\n                sfsi False Static Some m method lets Invokestatic exec_instr StepI\n               by(cases ics, auto split: if_split_asm)\n            next\n              case Error then show ?thesis using exec_step_ind_Invokestatic_NoMethod\n                exec_step_ind_Invokestatic_Init[where sh=sh, OF _ _ nDone nCalled]\n                sfsi False Static Some m method lets Invokestatic exec_instr StepI\n               by(cases ics, auto split: if_split_asm)\n            qed(simp)\n          qed\n        qed\n      qed\n    qed\n  next\n    case Return\n    obtain D b Ts T m where method: \"method P C M = (D,b,Ts,T,m)\" by(cases \"method P C M\")\n    then obtain mxs mxl\\<^sub>0 ins xt where \"m = (mxs,mxl\\<^sub>0,ins,xt)\" by(cases m)\n    then show ?thesis using exec_step_ind_Return_Last_Init exec_step_ind_Return_Last\n      exec_step_ind_Return_Init exec_step_ind_Return_NonStatic exec_step_ind_Return_Static\n       method Return exec_instr StepI\n      by(cases b; cases frs; cases \"M = clinit\"; cases ics, auto split: if_split_asm)\n  next\n    case Pop then show ?thesis using exec_instr StepI exec_step_ind_Pop by auto\n  next\n    case IAdd then show ?thesis using exec_instr StepI exec_step_ind_IAdd by auto\n  next\n    case (Goto x15) then show ?thesis using exec_instr StepI exec_step_ind_Goto by auto\n  next\n    case CmpEq then show ?thesis using exec_instr StepI exec_step_ind_CmpEq by auto\n  next\n    case (IfFalse x17) then show ?thesis using exec_instr StepI exec_step_ind_IfFalse_nFalse\n    proof(cases \"hd stk\")\n      case (Bool b) then show ?thesis using exec_step_ind_IfFalse_False\n       exec_step_ind_IfFalse_nFalse IfFalse exec_instr StepI by(cases b, auto)\n    qed(auto)\n  next\n    case Throw then show ?thesis\n     using exec_instr StepI exec_step_ind_Throw exec_step_ind_Throw_Null\n       by(cases \"hd stk = Null\", auto)\n  qed\nqed\n\nlemma exec_step_ind_imp_exec_step:\nassumes \"exec_step_ind si P h stk loc C M pc ics' frs sh (xp', h', frs', sh')\"\nshows \"\\<And>ics. exec_step_input P C M pc ics = (si, ics')\n \\<Longrightarrow> exec_step P h stk loc C M pc ics frs sh = (xp', h', frs', sh')\"\nusing assms\nproof(induct rule: exec_step_ind.induct)\n  case (exec_step_ind_NewOOM_Done sh C obj h ics P stk loc C\\<^sub>0 M\\<^sub>0 pc frs)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_New_Done sh C obj h a ics P stk loc C\\<^sub>0 M\\<^sub>0 pc frs)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_New_Init sh C ics P h stk loc C\\<^sub>0 M\\<^sub>0 pc frs)\n  then show ?case by(cases \"snd(the(sh C))\"; cases ics, auto)\nnext\n  case (exec_step_ind_Getfield_NoField v stk D fs h P F C loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases \"the (h (the_Addr (hd stk)))\", cases ics, auto)\nnext\n  case (exec_step_ind_Getfield_Static v stk D fs h P F t C loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case\n   by(cases \"the (h (the_Addr (hd stk)))\", cases \"field P C F\", cases \"fst(snd(field P C F))\",\n      cases ics, auto dest: has_field_sees[OF has_field_idemp])\nnext\n  case (exec_step_ind_Getfield v stk D fs h D' b t P C F loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases \"the (h (the_Addr (hd stk)))\", cases \"field P C F\",\n                     cases ics, auto) (fastforce dest: has_field_sees[OF has_field_idemp])+\nnext\n  case (exec_step_ind_Getstatic_NonStatic P C F t D h stk loc C\\<^sub>0 M\\<^sub>0 pc ics1 frs sh)\n  then show ?case by(cases \"field P D F\", cases \"fst(snd(field P D F))\";\n                     cases ics, auto) (fastforce dest: has_field_sees[OF has_field_idemp])+\nnext\n  case (exec_step_ind_Getstatic_Called D' b t P D F C ics ics' v h stk loc C\\<^sub>0 M\\<^sub>0 pc frs)\n  then show ?case by(cases \"field P D F\", cases \"fst(snd(field P D F))\",\n                     cases ics, auto) (fastforce dest: has_field_sees[OF has_field_idemp])+\nnext\n  case (exec_step_ind_Getstatic_Done D' b t P D F C ics sh sfs v h stk loc C\\<^sub>0 M\\<^sub>0 pc frs)\n  then show ?case by(cases \"field P D F\", cases \"fst(snd(field P D F))\"; cases ics,\n                     auto dest: has_field_sees[OF has_field_idemp])\nnext\n  case (exec_step_ind_Getstatic_Init D' b t P D F C sh ics h stk loc C\\<^sub>0 M\\<^sub>0 pc frs)\n  then show ?case\n   by(cases \"field P D F\", cases \"fst(snd(field P D F))\"; cases ics; cases \"snd(the(sh D'))\",\n      auto dest: has_field_sees[OF has_field_idemp])\nnext\n  case (exec_step_ind_Putfield_NoField r stk a D fs h P F C loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases \"the (h (the_Addr (hd(tl stk))))\", cases ics, auto)\nnext\n  case (exec_step_ind_Putfield_Static r stk a D fs h P F t C loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case\n   by(cases \"the (h (the_Addr (hd(tl stk))))\", cases \"field P C F\", cases \"fst(snd(field P C F))\",\n      cases ics, auto dest: has_field_sees[OF has_field_idemp])\nnext\n  case (exec_step_ind_Putfield v stk r a D fs h D' b t P C F loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases \"the (h (the_Addr (hd(tl stk))))\", cases \"field P C F\",\n                     cases ics, auto) (fastforce dest: has_field_sees[OF has_field_idemp])+\nnext\n  case (exec_step_ind_Putstatic_NonStatic P C F t D h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases \"field P D F\", cases \"fst(snd(field P D F))\";\n                     cases ics, auto) (fastforce dest: has_field_sees[OF has_field_idemp])+\nnext\n  case (exec_step_ind_Putstatic_Called D' b t P D F C sh sfs i h stk loc C\\<^sub>0 M\\<^sub>0 pc frs ics')\n  then show ?case by(cases \"field P D F\", cases \"fst(snd(field P D F))\",\n                     cases ics', auto dest: has_field_sees[OF has_field_idemp])\nnext\n  case (exec_step_ind_Putstatic_Done D' b t P D F C ics sh sfs h stk loc C\\<^sub>0 M\\<^sub>0 pc frs)\n  then show ?case by(cases \"field P D F\", cases \"fst(snd(field P D F))\"; cases ics,\n                     auto dest: has_field_sees[OF has_field_idemp])\nnext\n  case (exec_step_ind_Putstatic_Init D' b t P D F C sh ics h stk loc C\\<^sub>0 M\\<^sub>0 pc frs)\n  then show ?case\n   by(cases \"field P D F\", cases \"fst(snd(field P D F))\"; cases ics; cases \"snd(the(sh D'))\",\n      auto dest: has_field_sees[OF has_field_idemp])\nnext\n  case (exec_step_ind_Invoke ps n stk r C h D b Ts T mxs mxl\\<^sub>0 ins xt P M m f' loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, fastforce+)\nnext\n  case (exec_step_ind_Invokestatic_Called ps n stk D b Ts T mxs mxl\\<^sub>0 ins xt P C M m ics ics' sh)\n  then show ?case by(cases ics, fastforce+)\nnext\n  case (exec_step_ind_Invokestatic_Done ps n stk D b Ts T mxs mxl\\<^sub>0 ins xt P C M m ics sh sfs f')\n  then show ?case by(cases ics, auto) fastforce+\nnext\n  case (exec_step_ind_Invokestatic_Init D b Ts T mxs mxl\\<^sub>0 ins xt P C M m sh ics n h stk loc C\\<^sub>0 M\\<^sub>0 pc frs)\n  then show ?case by(cases ics; cases \"snd(the(sh D))\", auto) fastforce+\nnext\n  case (exec_step_ind_Return_Last ics P h stk\\<^sub>0 loc\\<^sub>0 C\\<^sub>0 M\\<^sub>0 pc sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Return_NonStatic D Ts T m P C\\<^sub>0 M\\<^sub>0 ics h stk\\<^sub>0 loc\\<^sub>0 pc stk' loc' C' m' pc' ics' frs' sh)\n  then show ?case by(cases \"method P C\\<^sub>0 M\\<^sub>0\", cases ics, auto)\nnext\n  case (exec_step_ind_Return_Static D Ts T m P C\\<^sub>0 M\\<^sub>0 ics h stk\\<^sub>0 loc\\<^sub>0 pc stk' loc' C' m' pc' ics' frs' sh)\n  then show ?case by(cases \"method P C\\<^sub>0 M\\<^sub>0\", cases ics, auto)\nnext\n  case (exec_step_ind_IfFalse_nFalse stk i P h loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases \"hd stk\"; cases ics, auto)\nnext\n  case (exec_step_ind_Throw_Null stk P h loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases \"hd stk\"; cases ics, auto)\nnext\n  case (exec_step_ind_Init_None_nCalled sh C ics P h stk loc C\\<^sub>0 M\\<^sub>0 pc frs)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Init_Error sh C sfs stk' loc' D' M' pc' ics' P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs)\n  then show ?case by(cases \"method P C clinit\", cases ics, auto)\nnext\n  case (exec_step_ind_Init_Prepared_nObject sh C sfs stk' loc' C' m' pc' ics' P sh' D h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs)\n  then show ?case by(cases \"method P C clinit\", cases ics, auto)\nnext\n  case (exec_step_ind_InitThrow_Other ics' a P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics stk' loc' C' m' pc' frs' sh)\n  then show ?case by(cases ics; cases ics', auto)\nnext\n  case (exec_step_ind_InitThrow_Init ics' a P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics stk' loc' C' pc' frs' sh)\n  then show ?case by(cases ics'; cases ics, auto)\nnext\n  case (exec_step_ind_InitThrow_Called a P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics stk' loc' C' m' pc' frs' sh ics')\n  then show ?case by(cases ics', auto)\n(***)\nnext\n  case (exec_step_ind_Load n P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Store n P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Push v P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_NewOOM_Called h C P stk loc C\\<^sub>0 M\\<^sub>0 pc frs sh ics')\n  then show ?case by(cases ics', auto)\nnext\n  case (exec_step_ind_New_Called h a C P stk loc C\\<^sub>0 M\\<^sub>0 pc frs sh ics')\n  then show ?case by(cases ics', auto)\nnext\n  case (exec_step_ind_Getfield_Null stk F C P h loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Getstatic_NoField P C F D h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Putfield_Null stk F C P h loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Putstatic_NoField P C F D h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Checkcast P C h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Checkcast_Error P C h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Invoke_Null stk n M P h loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Invoke_NoMethod r stk n C h P M loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Invoke_Static r stk n C h D b Ts T mxs mxl\\<^sub>0 ins xt P M m loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Invokestatic_NoMethod D b Ts T mxs mxl\\<^sub>0 ins xt P C M n h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Invokestatic_NonStatic D b Ts T mxs mxl\\<^sub>0 ins xt P C M m n h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Return_Last_Init P h stk\\<^sub>0 loc\\<^sub>0 C\\<^sub>0 M\\<^sub>0 pc sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Return_Init D b Ts T m P C\\<^sub>0 M\\<^sub>0 h stk\\<^sub>0 loc\\<^sub>0 pc stk' loc' C' m' pc' ics' frs' sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Pop P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_IAdd P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_IfFalse_False stk i P h loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_CmpEq P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Goto i P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Throw stk a P h loc C\\<^sub>0 M\\<^sub>0 pc ics frs sh)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Init_None_Called sh C ics P h stk loc C\\<^sub>0 M\\<^sub>0 pc frs)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Init_Done sh C sfs P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Init_Processing sh C sfs P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_Init_Prepared_Object sh C sfs sh' P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics frs)\n  then show ?case by(cases ics, auto)\nnext\n  case (exec_step_ind_InitThrow_Last a P h stk loc C\\<^sub>0 M\\<^sub>0 pc ics sh)\n  then show ?case by(cases ics, auto)\nqed\n\nlemma exec_step_ind_equiv:\n \"exec_step_input P C M pc ics = (si, ics')\n  \\<Longrightarrow> exec_step P h stk loc C M pc ics frs sh = (xp', h', frs', sh')\n    = exec_step_ind si P h stk loc C M pc ics' frs sh (xp', h', frs', sh')\"\n using exec_step_imp_exec_step_ind exec_step_ind_imp_exec_step by meson\n\nend\n", "meta": {"author": "susannahej", "repo": "jinja-dci", "sha": "0969fa2c5966204b326395763d7a375e7dc6badf", "save_path": "github-repos/isabelle/susannahej-jinja-dci", "path": "github-repos/isabelle/susannahej-jinja-dci/jinja-dci-0969fa2c5966204b326395763d7a375e7dc6badf/JVM/JVMExecInstrInductive.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6187804337438501, "lm_q2_score": 0.41489884579676883, "lm_q1q2_score": 0.25673128776194737}}
{"text": "(*\n(C) Copyright Andreas Viktor Hess, DTU, 2015-2020\n\nAll Rights Reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\n- Redistributions of source code must retain the above copyright\n  notice, this list of conditions and the following disclaimer.\n\n- Redistributions in binary form must reproduce the above copyright\n  notice, this list of conditions and the following disclaimer in the\n  documentation and/or other materials provided with the distribution.\n\n- Neither the name of the copyright holder nor the names of its\n  contributors may be used to endorse or promote products\n  derived from this software without specific prior written\n  permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\nLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\nA PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\nOWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\nLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\nTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n*)\n\n(*  Title:      Typed_Model.thy\n    Author:     Andreas Viktor Hess, DTU\n*)\n\nsection \\<open>The Typed Model\\<close>\ntheory Typed_Model\nimports Lazy_Intruder\nbegin\n\ntext \\<open>Term types\\<close>\ntype_synonym ('f,'v) term_type = \"('f,'v) term\"\n\ntext \\<open>Constructors for term types\\<close>\nabbreviation (input) TAtom::\"'v \\<Rightarrow> ('f,'v) term_type\" where\n  \"TAtom a \\<equiv> Var a\"\n\nabbreviation (input) TComp::\"['f, ('f,'v) term_type list] \\<Rightarrow> ('f,'v) term_type\" where\n  \"TComp f T \\<equiv> Fun f T\"\n\n\ntext \\<open>\n  The typed model extends the intruder model with a typing function \\<open>\\<Gamma>\\<close> that assigns types to terms.\n\\<close>\nlocale typed_model = intruder_model arity public Ana\n  for arity::\"'fun \\<Rightarrow> nat\"\n    and public::\"'fun \\<Rightarrow> bool\"\n    and Ana::\"('fun,'var) term \\<Rightarrow> (('fun,'var) term list \\<times> ('fun,'var) term list)\"\n  +\n  fixes \\<Gamma>::\"('fun,'var) term \\<Rightarrow> ('fun,'atom::finite) term_type\"\n  assumes const_type: \"\\<And>c. arity c = 0 \\<Longrightarrow> \\<exists>a. \\<forall>T. \\<Gamma> (Fun c T) = TAtom a\"\n    and fun_type: \"\\<And>f T. arity f > 0 \\<Longrightarrow> \\<Gamma> (Fun f T) = TComp f (map \\<Gamma> T)\"\n    and infinite_typed_consts: \"\\<And>a. infinite {c. \\<Gamma> (Fun c []) = TAtom a \\<and> public c}\"\n    and \\<Gamma>_wf: \"\\<And>t f T. TComp f T \\<sqsubseteq> \\<Gamma> t \\<Longrightarrow> arity f > 0\"\n              \"\\<And>x. wf\\<^sub>t\\<^sub>r\\<^sub>m (\\<Gamma> (Var x))\"\n    and no_private_funs[simp]: \"\\<And>f. arity f > 0 \\<Longrightarrow> public f\"\nbegin\n\nsubsection \\<open>Definitions\\<close>\ntext \\<open>The set of atomic types\\<close>\nabbreviation \"\\<TT>\\<^sub>a \\<equiv> UNIV::('atom set)\"\n\ntext \\<open>Well-typed substitutions\\<close>\ndefinition wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t where\n  \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma> \\<equiv> (\\<forall>v. \\<Gamma> (Var v) = \\<Gamma> (\\<sigma> v))\"\n\ntext \\<open>The set of sub-message patterns (SMP)\\<close>\ninductive_set SMP::\"('fun,'var) terms \\<Rightarrow> ('fun,'var) terms\" for M where\n  MP[intro]: \"t \\<in> M \\<Longrightarrow> t \\<in> SMP M\"\n| Subterm[intro]: \"\\<lbrakk>t \\<in> SMP M; t' \\<sqsubseteq> t\\<rbrakk> \\<Longrightarrow> t' \\<in> SMP M\"\n| Substitution[intro]: \"\\<lbrakk>t \\<in> SMP M; wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>; wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\\<rbrakk> \\<Longrightarrow> (t \\<cdot> \\<delta>) \\<in> SMP M\"\n| Ana[intro]: \"\\<lbrakk>t \\<in> SMP M; Ana t = (K,T); k \\<in> set K\\<rbrakk> \\<Longrightarrow> k \\<in> SMP M\"\n\ntext \\<open>\n  Type-flaw resistance for sets:\n  Unifiable sub-message patterns must have the same type (unless they are variables)\n\\<close>\ndefinition tfr\\<^sub>s\\<^sub>e\\<^sub>t where\n  \"tfr\\<^sub>s\\<^sub>e\\<^sub>t M \\<equiv> (\\<forall>s \\<in> SMP M - (Var`\\<V>). \\<forall>t \\<in> SMP M - (Var`\\<V>). (\\<exists>\\<delta>. Unifier \\<delta> s t) \\<longrightarrow> \\<Gamma> s = \\<Gamma> t)\"\n\ntext \\<open>\n  Type-flaw resistance for strand steps:\n  - The terms in a satisfiable equality step must have the same types\n  - Inequality steps must satisfy the conditions of the \"inequality lemma\"\\<close>\nfun tfr\\<^sub>s\\<^sub>t\\<^sub>p where\n  \"tfr\\<^sub>s\\<^sub>t\\<^sub>p (Equality a t t') = ((\\<exists>\\<delta>. Unifier \\<delta> t t') \\<longrightarrow> \\<Gamma> t = \\<Gamma> t')\"\n| \"tfr\\<^sub>s\\<^sub>t\\<^sub>p (Inequality X F) = (\n      (\\<forall>x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F - set X. \\<exists>a. \\<Gamma> (Var x) = TAtom a) \\<or>\n      (\\<forall>f T. Fun f T \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F) \\<longrightarrow> T = [] \\<or> (\\<exists>s \\<in> set T. s \\<notin> Var ` set X)))\"\n| \"tfr\\<^sub>s\\<^sub>t\\<^sub>p _ = True\"\n\ntext \\<open>\n  Type-flaw resistance for strands:\n  - The set of terms in strands must be type-flaw resistant\n  - The steps of strands must be type-flaw resistant\n\\<close>\ndefinition tfr\\<^sub>s\\<^sub>t where\n  \"tfr\\<^sub>s\\<^sub>t S \\<equiv> tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t S) \\<and> list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n\n\nsubsection \\<open>Small Lemmata\\<close>\nlemma tfr\\<^sub>s\\<^sub>t\\<^sub>p_list_all_alt_def:\n  \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S \\<longleftrightarrow>\n    ((\\<forall>a t t'. Equality a t t' \\<in> set S \\<and> (\\<exists>\\<delta>. Unifier \\<delta> t t') \\<longrightarrow> \\<Gamma> t = \\<Gamma> t') \\<and>\n    (\\<forall>X F. Inequality X F \\<in> set S \\<longrightarrow> \n      (\\<forall>x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F - set X. \\<exists>a. \\<Gamma> (Var x) = TAtom a)\n    \\<or> (\\<forall>f T. Fun f T \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F) \\<longrightarrow> T = [] \\<or> (\\<exists>s \\<in> set T. s \\<notin> Var ` set X))))\"\n  (is \"?P S \\<longleftrightarrow> ?Q S\")\nproof\n  show \"?P S \\<Longrightarrow> ?Q S\"\n  proof (induction S)\n    case (Cons x S) thus ?case by (cases x) auto\n  qed simp\n\n  show \"?Q S \\<Longrightarrow> ?P S\"\n  proof (induction S)\n    case (Cons x S) thus ?case by (cases x) auto\n  qed simp\nqed\n\n\nlemma \\<Gamma>_wf': \"wf\\<^sub>t\\<^sub>r\\<^sub>m t \\<Longrightarrow> wf\\<^sub>t\\<^sub>r\\<^sub>m (\\<Gamma> t)\"\nproof (induction t)\n  case (Fun f T)\n  hence *: \"arity f = length T\" \"\\<And>t. t \\<in> set T \\<Longrightarrow> wf\\<^sub>t\\<^sub>r\\<^sub>m (\\<Gamma> t)\" unfolding wf\\<^sub>t\\<^sub>r\\<^sub>m_def by auto\n  { assume \"arity f = 0\" hence ?case using const_type[of f] by auto }\n  moreover\n  { assume \"arity f > 0\" hence ?case using fun_type[of f] * by force }\n  ultimately show ?case by auto \nqed (metis \\<Gamma>_wf(2))\n\nlemma fun_type_inv: assumes \"\\<Gamma> t = TComp f T\" shows \"arity f > 0\" \"public f\"\nusing \\<Gamma>_wf(1)[of f T t] assms by simp_all\n\nlemma fun_type_inv_wf: assumes \"\\<Gamma> t = TComp f T\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" shows \"arity f = length T\"\nusing \\<Gamma>_wf'[OF assms(2)] assms(1) unfolding wf\\<^sub>t\\<^sub>r\\<^sub>m_def by auto\n\nlemma const_type_inv: \"\\<Gamma> (Fun c X) = TAtom a \\<Longrightarrow> arity c = 0\"\nby (rule ccontr, simp add: fun_type)\n\nlemma const_type_inv_wf: assumes \"\\<Gamma> (Fun c X) = TAtom a\" and \"wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun c X)\" shows \"X = []\"\nby (metis assms const_type_inv length_0_conv subtermeqI' wf\\<^sub>t\\<^sub>r\\<^sub>m_def)\n\nlemma const_type': \"\\<forall>c \\<in> \\<C>. \\<exists>a \\<in> \\<TT>\\<^sub>a. \\<forall>X. \\<Gamma> (Fun c X) = TAtom a\" using const_type by simp\nlemma fun_type': \"\\<forall>f \\<in> \\<Sigma>\\<^sub>f. \\<forall>X. \\<Gamma> (Fun f X) = TComp f (map \\<Gamma> X)\" using fun_type by simp\n\nlemma infinite_public_consts[simp]: \"infinite {c. public c \\<and> arity c = 0}\"\nproof -\n  fix a::'atom\n  define A where \"A \\<equiv> {c. \\<Gamma> (Fun c []) = TAtom a \\<and> public c}\"\n  define B where \"B \\<equiv> {c. public c \\<and> arity c = 0}\"\n\n  have \"arity c = 0\" when c: \"c \\<in> A\" for c\n    using c const_type_inv unfolding A_def by blast\n  hence \"A \\<subseteq> B\" unfolding A_def B_def by blast\n  hence \"infinite B\"\n    using infinite_typed_consts[of a, unfolded A_def[symmetric]]\n    by (metis infinite_super)\n  thus ?thesis unfolding B_def by blast\nqed\n\nlemma infinite_fun_syms[simp]:\n  \"infinite {c. public c \\<and> arity c > 0} \\<Longrightarrow> infinite \\<Sigma>\\<^sub>f\"\n  \"infinite \\<C>\" \"infinite \\<C>\\<^sub>p\\<^sub>u\\<^sub>b\" \"infinite (UNIV::'fun set)\"\nby (metis \\<Sigma>\\<^sub>f_unfold finite_Collect_conjI,\n    metis infinite_public_consts finite_Collect_conjI,\n    use infinite_public_consts \\<C>pub_unfold in \\<open>force simp add: Collect_conj_eq\\<close>,\n    metis UNIV_I finite_subset subsetI infinite_public_consts(1))\n\nlemma id_univ_proper_subset[simp]: \"\\<Sigma>\\<^sub>f \\<subset> UNIV\" \"(\\<exists>f. arity f > 0) \\<Longrightarrow> \\<C> \\<subset> UNIV\"\nby (metis finite.emptyI inf_top.right_neutral top.not_eq_extremum disjoint_fun_syms\n          infinite_fun_syms(2) inf_commute)\n   (metis top.not_eq_extremum UNIV_I const_arity_eq_zero less_irrefl)\n\nlemma exists_fun_notin_funs_term: \"\\<exists>f::'fun. f \\<notin> funs_term t\"\nby (metis UNIV_eq_I finite_fun_symbols infinite_fun_syms(4))\n\nlemma exists_fun_notin_funs_terms:\n  assumes \"finite M\" shows \"\\<exists>f::'fun. f \\<notin> \\<Union>(funs_term ` M)\"\nby (metis assms finite_fun_symbols infinite_fun_syms(4) ex_new_if_finite finite_UN)\n\nlemma exists_notin_funs\\<^sub>s\\<^sub>t: \"\\<exists>f. f \\<notin> funs\\<^sub>s\\<^sub>t (S::('fun,'var) strand)\"\nby (metis UNIV_eq_I finite_funs\\<^sub>s\\<^sub>t infinite_fun_syms(4))\n\nlemma infinite_typed_consts': \"infinite {c. \\<Gamma> (Fun c []) = TAtom a \\<and> public c \\<and> arity c = 0}\"\nproof -\n  { fix c assume \"\\<Gamma> (Fun c []) = TAtom a\" \"public c\"\n    hence \"arity c = 0\" using const_type[of c] fun_type[of c \"[]\"] by auto\n  } hence \"{c. \\<Gamma> (Fun c []) = TAtom a \\<and> public c \\<and> arity c = 0} =\n           {c. \\<Gamma> (Fun c []) = TAtom a \\<and> public c}\"\n    by auto\n  thus \"infinite {c. \\<Gamma> (Fun c []) = TAtom a \\<and> public c \\<and> arity c = 0}\"\n    using infinite_typed_consts[of a] by metis\nqed\n\nlemma atypes_inhabited: \"\\<exists>c. \\<Gamma> (Fun c []) = TAtom a \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun c []) \\<and> public c \\<and> arity c = 0\"\nproof -\n  obtain c where \"\\<Gamma> (Fun c []) = TAtom a\" \"public c\" \"arity c = 0\"\n    using infinite_typed_consts'(1)[of a] not_finite_existsD by blast\n  thus ?thesis using const_type_inv[OF \\<open>\\<Gamma> (Fun c []) = TAtom a\\<close>] unfolding wf\\<^sub>t\\<^sub>r\\<^sub>m_def by auto\nqed\n\nlemma atype_ground_term_ex: \"\\<exists>t. fv t = {} \\<and> \\<Gamma> t = TAtom a \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\nusing atypes_inhabited[of a] by force\n\nlemma fun_type_id_eq: \"\\<Gamma> (Fun f X) = TComp g Y \\<Longrightarrow> f = g\"\nby (metis const_type fun_type neq0_conv \"term.inject\"(2) \"term.simps\"(4))\n\nlemma fun_type_length_eq: \"\\<Gamma> (Fun f X) = TComp g Y \\<Longrightarrow> length X = length Y\"\nby (metis fun_type fun_type_id_eq fun_type_inv(1) length_map term.inject(2))\n\nlemma type_ground_inhabited: \"\\<exists>t'. fv t' = {} \\<and> \\<Gamma> t = \\<Gamma> t'\"\nproof -\n  { fix \\<tau>::\"('fun, 'atom) term_type\" assume \"\\<And>f T. Fun f T \\<sqsubseteq> \\<tau> \\<Longrightarrow> 0 < arity f\"\n    hence \"\\<exists>t'. fv t' = {} \\<and> \\<tau> = \\<Gamma> t'\"\n    proof (induction \\<tau>)\n      case (Fun f T)\n      hence \"arity f > 0\" by auto\n    \n      from Fun.IH Fun.prems(1) have \"\\<exists>Y. map \\<Gamma> Y = T \\<and> (\\<forall>x \\<in> set Y. fv x = {})\"\n      proof (induction T)\n        case (Cons x X)\n        hence \"\\<And>g Y. Fun g Y \\<sqsubseteq> Fun f X \\<Longrightarrow> 0 < arity g\" by auto\n        hence \"\\<exists>Y. map \\<Gamma> Y = X \\<and> (\\<forall>x\\<in>set Y. fv x = {})\" using Cons by auto\n        moreover have \"\\<exists>t'. fv t' = {} \\<and> x = \\<Gamma> t'\" using Cons by auto\n        ultimately obtain y Y where\n            \"fv y = {}\" \"\\<Gamma> y = x\" \"map \\<Gamma> Y = X\" \"\\<forall>x\\<in>set Y. fv x = {}\" \n          using Cons by moura\n        hence \"map \\<Gamma> (y#Y) = x#X \\<and> (\\<forall>x\\<in>set (y#Y). fv x = {})\" by auto\n        thus ?case by meson \n      qed simp\n      then obtain Y where \"map \\<Gamma> Y = T\" \"\\<forall>x \\<in> set Y. fv x = {}\" by metis\n      hence \"fv (Fun f Y) = {}\" \"\\<Gamma> (Fun f Y) = TComp f T\" using fun_type[OF \\<open>arity f > 0\\<close>] by auto\n      thus ?case by (metis exI[of \"\\<lambda>t. fv t = {} \\<and> \\<Gamma> t = TComp f T\" \"Fun f Y\"])\n    qed (metis atype_ground_term_ex)\n  }\n  thus ?thesis by (metis \\<Gamma>_wf(1))\nqed\n\nlemma type_wfttype_inhabited:\n  assumes \"\\<And>f T. Fun f T \\<sqsubseteq> \\<tau> \\<Longrightarrow> 0 < arity f\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m \\<tau>\"\n  shows \"\\<exists>t. \\<Gamma> t = \\<tau> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\nusing assms\nproof (induction \\<tau>)\n  case (Fun f Y)\n  have IH: \"\\<exists>t. \\<Gamma> t = y \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m t\" when y: \"y \\<in> set Y \" for y\n  proof -\n    have \"wf\\<^sub>t\\<^sub>r\\<^sub>m y\"\n      using Fun y unfolding wf\\<^sub>t\\<^sub>r\\<^sub>m_def\n      by (metis Fun_param_is_subterm term.le_less_trans) \n    moreover have \"Fun g Z \\<sqsubseteq> y \\<Longrightarrow> 0 < arity g\" for g Z\n      using Fun y by auto\n    ultimately show ?thesis using Fun.IH[OF y] by auto\n  qed\n\n  from Fun have \"arity f = length Y\" \"arity f > 0\" unfolding wf\\<^sub>t\\<^sub>r\\<^sub>m_def by force+\n  moreover from IH have \"\\<exists>X. map \\<Gamma> X = Y \\<and> (\\<forall>x \\<in> set X. wf\\<^sub>t\\<^sub>r\\<^sub>m x)\"\n    by (induct Y, simp_all, metis list.simps(9) set_ConsD)\n  ultimately show ?case by (metis fun_type length_map wf_trmI)\nqed (use atypes_inhabited wf\\<^sub>t\\<^sub>r\\<^sub>m_def in blast)\n\nlemma type_pgwt_inhabited: \"wf\\<^sub>t\\<^sub>r\\<^sub>m t \\<Longrightarrow> \\<exists>t'. \\<Gamma> t = \\<Gamma> t' \\<and> public_ground_wf_term t'\"\nproof -\n  assume \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\n  { fix \\<tau> assume \"\\<Gamma> t = \\<tau>\"\n    hence \"\\<exists>t'. \\<Gamma> t = \\<Gamma> t' \\<and> public_ground_wf_term t'\" using \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m t\\<close>\n    proof (induction \\<tau> arbitrary: t)\n      case (Var a t)\n      then obtain c where \"\\<Gamma> t = \\<Gamma> (Fun c [])\" \"arity c = 0\" \"public c\"\n        using const_type_inv[of _ \"[]\" a] infinite_typed_consts(1)[of a]  not_finite_existsD\n        by force\n      thus ?case using PGWT[OF \\<open>public c\\<close>, of \"[]\"] by auto\n    next\n      case (Fun f Y t)\n      have *: \"arity f > 0\" \"public f\" \"arity f = length Y\"\n        using fun_type_inv[OF \\<open>\\<Gamma> t = TComp f Y\\<close>] fun_type_inv_wf[OF \\<open>\\<Gamma> t = TComp f Y\\<close> \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m t\\<close>]\n        by auto\n      have \"\\<And>y. y \\<in> set Y \\<Longrightarrow> \\<exists>t'. y = \\<Gamma> t' \\<and> public_ground_wf_term t'\"\n        using Fun.prems(1) Fun.IH \\<Gamma>_wf(1)[of _ _ t] \\<Gamma>_wf'[OF \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m t\\<close>] type_wfttype_inhabited\n        by (metis Fun_param_is_subterm term.order_trans wf_trm_subtermeq) \n      hence \"\\<exists>X. map \\<Gamma> X = Y \\<and> (\\<forall>x \\<in> set X. public_ground_wf_term x)\"\n        by (induct Y, simp_all, metis list.simps(9) set_ConsD)\n      then obtain X where X: \"map \\<Gamma> X = Y\" \"\\<And>x. x \\<in> set X \\<Longrightarrow> public_ground_wf_term x\" by moura\n      hence \"arity f = length X\" using *(3) by auto\n      have \"\\<Gamma> t = \\<Gamma> (Fun f X)\" \"public_ground_wf_term (Fun f X)\"\n        using fun_type[OF *(1), of X] Fun.prems(1) X(1) apply simp\n        using PGWT[OF *(2) \\<open>arity f = length X\\<close> X(2)] by metis\n      thus ?case by metis\n    qed\n  }\n  thus ?thesis using \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m t\\<close> by auto\nqed\n\nlemma pgwt_type_map: \n  assumes \"public_ground_wf_term t\"\n  shows \"\\<Gamma> t = TAtom a \\<Longrightarrow> \\<exists>f. t = Fun f []\" \"\\<Gamma> t = TComp g Y \\<Longrightarrow> \\<exists>X. t = Fun g X \\<and> map \\<Gamma> X = Y\"\nproof -\n  let ?A = \"\\<Gamma> t = TAtom a \\<longrightarrow> (\\<exists>f. t = Fun f [])\"\n  let ?B = \"\\<Gamma> t = TComp g Y \\<longrightarrow> (\\<exists>X. t = Fun g X \\<and> map \\<Gamma> X = Y)\"\n  have \"?A \\<and> ?B\"\n  proof (cases \"\\<Gamma> t\")\n    case (Var a)\n    obtain f X where \"t = Fun f X\" \"arity f = length X\"\n      using pgwt_fun[OF assms(1)] pgwt_arity[OF assms(1)] by fastforce+\n    thus ?thesis using const_type_inv \\<open>\\<Gamma> t = TAtom a\\<close> by auto\n  next\n    case (Fun g Y)\n    obtain f X where *: \"t = Fun f X\" using pgwt_fun[OF assms(1)] by force\n    hence \"f = g\" \"map \\<Gamma> X = Y\"\n      using fun_type_id_eq \\<open>\\<Gamma> t = TComp g Y\\<close> fun_type[OF fun_type_inv(1)[OF \\<open>\\<Gamma> t = TComp g Y\\<close>]]\n      by fastforce+\n    thus ?thesis using *(1) \\<open>\\<Gamma> t = TComp g Y\\<close> by auto \n  qed\n  thus \"\\<Gamma> t = TAtom a \\<Longrightarrow> \\<exists>f. t = Fun f []\" \"\\<Gamma> t = TComp g Y \\<Longrightarrow> \\<exists>X. t = Fun g X \\<and> map \\<Gamma> X = Y\"\n    by auto\nqed \n\nlemma wt_subst_Var[simp]: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t Var\" by (metis wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def)\n\nlemma wt_subst_trm: \"(\\<And>v. v \\<in> fv t \\<Longrightarrow> \\<Gamma> (Var v) = \\<Gamma> (\\<theta> v)) \\<Longrightarrow> \\<Gamma> t = \\<Gamma> (t \\<cdot> \\<theta>)\"\nproof (induction t)\n  case (Fun f X)\n  hence *: \"\\<And>x. x \\<in> set X \\<Longrightarrow> \\<Gamma> x = \\<Gamma> (x \\<cdot> \\<theta>)\" by auto\n  show ?case\n  proof (cases \"f \\<in> \\<Sigma>\\<^sub>f\")\n    case True\n    hence \"\\<forall>X. \\<Gamma> (Fun f X) = TComp f (map \\<Gamma> X)\" using fun_type' by auto\n    thus ?thesis using * by auto\n  next\n    case False\n    hence \"\\<exists>a \\<in> \\<TT>\\<^sub>a. \\<forall>X. \\<Gamma> (Fun f X) = TAtom a\" using const_type' by auto\n    thus ?thesis by auto\n  qed\nqed auto\n\nlemma wt_subst_trm': \"\\<lbrakk>wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma>; \\<Gamma> s = \\<Gamma> t\\<rbrakk> \\<Longrightarrow> \\<Gamma> (s \\<cdot> \\<sigma>) = \\<Gamma> (t \\<cdot> \\<sigma>)\"\nby (metis wt_subst_trm wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def)\n\nlemma wt_subst_trm'': \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma> \\<Longrightarrow> \\<Gamma> t = \\<Gamma> (t \\<cdot> \\<sigma>)\"\nby (metis wt_subst_trm wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def)\n\nlemma wt_subst_compose:\n  assumes \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" shows \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t (\\<theta> \\<circ>\\<^sub>s \\<delta>)\"\nproof -\n  have \"\\<And>v. \\<Gamma> (\\<theta> v) = \\<Gamma> (\\<theta> v \\<cdot> \\<delta>)\" using wt_subst_trm \\<open>wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\\<close> unfolding wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def by metis\n  moreover have \"\\<And>v. \\<Gamma> (Var v) = \\<Gamma> (\\<theta> v)\" using \\<open>wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\\<close> unfolding wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def by metis\n  ultimately have \"\\<And>v. \\<Gamma> (Var v) = \\<Gamma> (\\<theta> v \\<cdot> \\<delta>)\" by metis\n  thus ?thesis unfolding wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def subst_compose_def by metis\nqed\n\nlemma wt_subst_TAtom_Var_cases:\n  assumes \\<theta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n  and x: \"\\<Gamma> (Var x) = TAtom a\"\n  shows \"(\\<exists>y. \\<theta> x = Var y) \\<or> (\\<exists>c. \\<theta> x = Fun c [])\"\nproof (cases \"(\\<exists>y. \\<theta> x = Var y)\")\n  case False\n  then obtain c T where c: \"\\<theta> x = Fun c T\"\n    by (cases \"\\<theta> x\") simp_all\n  hence \"wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun c T)\"\n    using \\<theta>(2) by fastforce\n  hence \"T = []\"\n    using const_type_inv_wf[of c T a] x c wt_subst_trm''[OF \\<theta>(1), of \"Var x\"]\n    by fastforce\n  thus ?thesis\n    using c by blast\nqed simp\n\nlemma wt_subst_TAtom_fv:\n  assumes \\<theta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"\\<forall>x. wf\\<^sub>t\\<^sub>r\\<^sub>m (\\<theta> x)\"\n  and \"\\<forall>x \\<in> fv t - X. \\<exists>a. \\<Gamma> (Var x) = TAtom a\"\n  shows \"\\<forall>x \\<in> fv (t \\<cdot> \\<theta>) - fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<theta> ` X). \\<exists>a. \\<Gamma> (Var x) = TAtom a\"\nusing assms(3)\nproof (induction t)\n  case (Var x) thus ?case\n  proof (cases \"x \\<in> X\")\n    case False\n    with Var obtain a where \"\\<Gamma> (Var x) = TAtom a\" by moura\n    hence *: \"\\<Gamma> (\\<theta> x) = TAtom a\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m (\\<theta> x)\" using \\<theta> unfolding wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def by auto\n    show ?thesis\n    proof (cases \"\\<theta> x\")\n      case (Var y) thus ?thesis using * by auto\n    next\n      case (Fun f T)\n      hence \"T = []\" using * const_type_inv[of f T a] unfolding wf\\<^sub>t\\<^sub>r\\<^sub>m_def by auto\n      thus ?thesis using Fun by auto\n    qed\n  qed auto\nqed fastforce\n\nlemma wt_subst_TAtom_subterms_subst:\n  assumes \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"\\<forall>x \\<in> fv t. \\<exists>a. \\<Gamma> (Var x) = TAtom a\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (\\<theta> ` fv t)\"\n  shows \"subterms (t \\<cdot> \\<theta>) = subterms t \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\"\nusing assms(2,3)\nproof (induction t)\n  case (Var x)\n  obtain a where a: \"\\<Gamma> (Var x) = TAtom a\" using Var.prems(1) by moura\n  hence \"\\<Gamma> (\\<theta> x) = TAtom a\" using wt_subst_trm''[OF assms(1), of \"Var x\"] by simp\n  hence \"(\\<exists>y. \\<theta> x = Var y) \\<or> (\\<exists>c. \\<theta> x = Fun c [])\"\n    using const_type_inv_wf Var.prems(2) by (cases \"\\<theta> x\") auto\n  thus ?case by auto\nnext\n  case (Fun f T)\n  have \"subterms (t \\<cdot> \\<theta>) = subterms t \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\" when \"t \\<in> set T\" for t\n    using that Fun.prems(1,2) Fun.IH[OF that]\n    by auto\n  thus ?case by auto\nqed\n\nlemma wt_subst_TAtom_subterms_set_subst: \n  assumes \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"\\<forall>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t M. \\<exists>a. \\<Gamma> (Var x) = TAtom a\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (\\<theta> ` fv\\<^sub>s\\<^sub>e\\<^sub>t M)\"\n  shows \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>) = subterms\\<^sub>s\\<^sub>e\\<^sub>t M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\"\nproof\n  show \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>) \\<subseteq> subterms\\<^sub>s\\<^sub>e\\<^sub>t M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\"\n  proof\n    fix t assume \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>)\"\n    then obtain s where s: \"s \\<in> M\" \"t \\<in> subterms (s \\<cdot> \\<theta>)\" by auto\n    thus \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\"\n      using assms(2,3) wt_subst_TAtom_subterms_subst[OF assms(1), of s]\n      by auto\n  qed\n\n  show \"subterms\\<^sub>s\\<^sub>e\\<^sub>t M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta> \\<subseteq> subterms\\<^sub>s\\<^sub>e\\<^sub>t (M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>)\"\n  proof\n    fix t assume \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\"\n    then obtain s where s: \"s \\<in> M\" \"t \\<in> subterms s \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\" by auto\n    thus \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>)\"\n      using assms(2,3) wt_subst_TAtom_subterms_subst[OF assms(1), of s]\n      by auto\n  qed\nqed\n\nlemma wt_subst_subst_upd:\n  assumes \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\"\n    and \"\\<Gamma> (Var x) = \\<Gamma> t\"\n  shows \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t (\\<theta>(x := t))\"\nusing assms unfolding wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def\nby (metis fun_upd_other fun_upd_same)\n\nlemma wt_subst_const_fv_type_eq:\n  assumes \"\\<forall>x \\<in> fv t. \\<exists>a. \\<Gamma> (Var x) = TAtom a\"\n    and \\<delta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\"\n  shows \"\\<forall>x \\<in> fv (t \\<cdot> \\<delta>). \\<exists>y \\<in> fv t. \\<Gamma> (Var x) = \\<Gamma> (Var y)\"\nusing assms(1)\nproof (induction t)\n  case (Var x)\n  then obtain a where a: \"\\<Gamma> (Var x) = TAtom a\" by moura\n  show ?case\n  proof (cases \"\\<delta> x\")\n    case (Fun f T)\n    hence \"wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f T)\" \"\\<Gamma> (Fun f T) = TAtom a\"\n      using a wt_subst_trm''[OF \\<delta>(1), of \"Var x\"] \\<delta>(2) by fastforce+\n    thus ?thesis using const_type_inv_wf Fun by fastforce\n  qed (use a wt_subst_trm''[OF \\<delta>(1), of \"Var x\"] in simp)\nqed fastforce\n\nlemma TComp_term_cases:\n  assumes \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"\\<Gamma> t = TComp f T\"\n  shows \"(\\<exists>v. t = Var v) \\<or> (\\<exists>T'. t = Fun f T' \\<and> T = map \\<Gamma> T' \\<and> T' \\<noteq> [])\"\nproof (cases \"\\<exists>v. t = Var v\")\n  case False\n  then obtain T' where T': \"t = Fun f T'\" \"T = map \\<Gamma> T'\"\n    using assms fun_type[OF fun_type_inv(1)[OF assms(2)]] fun_type_id_eq\n    by (cases t) force+\n  thus ?thesis using assms fun_type_inv(1) fun_type_inv_wf by fastforce\nqed metis\n\nlemma TAtom_term_cases:\n  assumes \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"\\<Gamma> t = TAtom \\<tau>\"\n  shows \"(\\<exists>v. t = Var v) \\<or> (\\<exists>f. t = Fun f [])\"\nusing assms const_type_inv unfolding wf\\<^sub>t\\<^sub>r\\<^sub>m_def by (cases t) auto\n\nlemma subtermeq_imp_subtermtypeeq:\n  assumes \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"s \\<sqsubseteq> t\"\n  shows \"\\<Gamma> s \\<sqsubseteq> \\<Gamma> t\"\nusing assms(2,1)\nproof (induction t)\n  case (Fun f T) thus ?case\n  proof (cases \"s = Fun f T\")\n    case False\n    then obtain x where x: \"x \\<in> set T\" \"s \\<sqsubseteq> x\" using Fun.prems(1) by auto\n    hence \"wf\\<^sub>t\\<^sub>r\\<^sub>m x\" using wf_trm_subtermeq[OF Fun.prems(2)] Fun_param_is_subterm[of _ T f] by auto\n    hence \"\\<Gamma> s \\<sqsubseteq> \\<Gamma> x\" using Fun.IH[OF x] by simp\n    moreover have \"arity f > 0\" using x fun_type_inv_wf Fun.prems\n      by (metis length_pos_if_in_set term.order_refl wf\\<^sub>t\\<^sub>r\\<^sub>m_def)\n    ultimately show ?thesis using x Fun.prems fun_type[of f T] by auto\n  qed simp\nqed simp\n\nlemma subterm_funs_term_in_type:\n  assumes \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"Fun f T \\<sqsubseteq> t\" \"\\<Gamma> (Fun f T) = TComp f (map \\<Gamma> T)\"\n  shows \"f \\<in> funs_term (\\<Gamma> t)\"\nusing assms(2,1,3)\nproof (induction t)\n  case (Fun f' T')\n  hence [simp]: \"wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f T)\" by (metis wf_trm_subtermeq)\n  { fix a assume \\<tau>: \"\\<Gamma> (Fun f' T') = TAtom a\"\n    hence \"Fun f T = Fun f' T'\" using Fun TAtom_term_cases subtermeq_Var_const by metis\n    hence False using Fun.prems(3) \\<tau> by simp\n  }\n  moreover\n  { fix g S assume \\<tau>: \"\\<Gamma> (Fun f' T') = TComp g S\"\n    hence \"g = f'\" \"S = map \\<Gamma> T'\"\n      using Fun.prems(2) fun_type_id_eq[OF \\<tau>] fun_type[OF fun_type_inv(1)[OF \\<tau>]]\n      by auto\n    hence \\<tau>': \"\\<Gamma> (Fun f' T') = TComp f' (map \\<Gamma> T')\" using \\<tau> by auto\n    hence \"g \\<in> funs_term (\\<Gamma> (Fun f' T'))\" using \\<tau> by auto\n    moreover {\n      assume \"Fun f T \\<noteq> Fun f' T'\"\n      then obtain x where \"x \\<in> set T'\" \"Fun f T \\<sqsubseteq> x\" using Fun.prems(1) by auto\n      hence \"f \\<in> funs_term (\\<Gamma> x)\"\n        using Fun.IH[OF _ _ _ Fun.prems(3), of x] wf_trm_subtermeq[OF \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f' T')\\<close>, of x]\n        by force\n      moreover have \"\\<Gamma> x \\<in> set (map \\<Gamma> T')\" using \\<tau>' \\<open>x \\<in> set T'\\<close> by auto\n      ultimately have \"f \\<in> funs_term (\\<Gamma> (Fun f' T'))\" using \\<tau>' by auto\n    }\n    ultimately have ?case by (cases \"Fun f T = Fun f' T'\") (auto simp add: \\<open>g = f'\\<close>)\n  }\n  ultimately show ?case by (cases \"\\<Gamma> (Fun f' T')\") auto\nqed simp\n\nlemma wt_subst_fv_termtype_subterm:\n  assumes \"x \\<in> fv (\\<theta> y)\"\n    and \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\"\n    and \"wf\\<^sub>t\\<^sub>r\\<^sub>m (\\<theta> y)\"\n  shows \"\\<Gamma> (Var x) \\<sqsubseteq> \\<Gamma> (Var y)\"\nusing subtermeq_imp_subtermtypeeq[OF assms(3) var_is_subterm[OF assms(1)]]\n      wt_subst_trm''[OF assms(2), of \"Var y\"]\nby auto\n\nlemma wt_subst_fv\\<^sub>s\\<^sub>e\\<^sub>t_termtype_subterm:\n  assumes \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<theta> ` Y)\"\n    and \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\"\n    and \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n  shows \"\\<exists>y \\<in> Y. \\<Gamma> (Var x) \\<sqsubseteq> \\<Gamma> (Var y)\"\nusing wt_subst_fv_termtype_subterm[OF _ assms(2), of x] assms(1,3)\nby fastforce\n\nlemma funs_term_type_iff:\n  assumes t: \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\n    and f: \"arity f > 0\"\n  shows \"f \\<in> funs_term (\\<Gamma> t) \\<longleftrightarrow> (f \\<in> funs_term t \\<or> (\\<exists>x \\<in> fv t. f \\<in> funs_term (\\<Gamma> (Var x))))\"\n    (is \"?P t \\<longleftrightarrow> ?Q t\")\nusing t\nproof (induction t)\n  case (Fun g T)\n  hence IH: \"?P s \\<longleftrightarrow> ?Q s\" when \"s \\<in> set T\" for s\n    using that wf_trm_subterm[OF _ Fun_param_is_subterm]\n    by blast\n  have 0: \"arity g = length T\" using Fun.prems unfolding wf\\<^sub>t\\<^sub>r\\<^sub>m_def by auto\n  show ?case\n  proof (cases \"f = g\")\n    case True thus ?thesis using fun_type[OF f] by simp\n  next\n    case False\n    have \"?P (Fun g T) \\<longleftrightarrow> (\\<exists>s \\<in> set T. ?P s)\"\n    proof\n      assume *: \"?P (Fun g T)\"\n      hence \"\\<Gamma> (Fun g T) = TComp g (map \\<Gamma> T)\"\n        using const_type[of g] fun_type[of g] by force\n      thus \"\\<exists>s \\<in> set T. ?P s\" using False * by force\n    next\n      assume *: \"\\<exists>s \\<in> set T. ?P s\"\n      hence \"\\<Gamma> (Fun g T) = TComp g (map \\<Gamma> T)\"\n        using 0 const_type[of g] fun_type[of g] by force\n      thus \"?P (Fun g T)\" using False * by force\n    qed\n    thus ?thesis using False f IH by auto\n  qed\nqed simp\n\nlemma funs_term_type_iff':\n  assumes M: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s M\"\n    and f: \"arity f > 0\"\n  shows \"f \\<in> \\<Union>(funs_term ` \\<Gamma> ` M) \\<longleftrightarrow>\n        (f \\<in> \\<Union>(funs_term ` M) \\<or> (\\<exists>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t M. f \\<in> funs_term (\\<Gamma> (Var x))))\" (is \"?A \\<longleftrightarrow> ?B\")\nproof\n  assume ?A\n  then obtain t where \"t \\<in> M\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"f \\<in> funs_term (\\<Gamma> t)\" using M by moura\n  thus ?B using funs_term_type_iff[OF _ f, of t] by auto\nnext\n  assume ?B\n  then obtain t where \"t \\<in> M\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"f \\<in> funs_term t \\<or> (\\<exists>x \\<in> fv t. f \\<in> funs_term (\\<Gamma> (Var x)))\"\n    using M by auto\n  thus ?A using funs_term_type_iff[OF _ f, of t] by blast\nqed\n\nlemma Ana_subterm_type:\n  assumes \"Ana t = (K,M)\"\n    and \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\n    and \"m \\<in> set M\"\n  shows \"\\<Gamma> m \\<sqsubseteq> \\<Gamma> t\"\nproof -\n  have \"m \\<sqsubseteq> t\" using Ana_subterm[OF assms(1)] assms(3) by auto\n  thus ?thesis using subtermeq_imp_subtermtypeeq[OF assms(2)] by simp\nqed\n\nlemma wf_trm_TAtom_subterms:\n  assumes \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"\\<Gamma> t = TAtom \\<tau>\"\n  shows \"subterms t = {t}\"\nusing assms const_type_inv unfolding wf\\<^sub>t\\<^sub>r\\<^sub>m_def by (cases t) force+\n\nlemma wf_trm_TComp_subterm:\n  assumes \"wf\\<^sub>t\\<^sub>r\\<^sub>m s\" \"t \\<sqsubset> s\"\n  obtains f T where \"\\<Gamma> s = TComp f T\"\nproof (cases s)\n  case (Var x) thus ?thesis using \\<open>t \\<sqsubset> s\\<close> by simp\nnext\n  case (Fun g S)\n  hence \"length S > 0\" using assms Fun_subterm_inside_params[of t g S] by auto\n  hence \"arity g > 0\" by (metis \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m s\\<close> \\<open>s = Fun g S\\<close> term.order_refl wf\\<^sub>t\\<^sub>r\\<^sub>m_def) \n  thus ?thesis using fun_type \\<open>s = Fun g S\\<close> that by auto\nqed\n\nlemma SMP_empty[simp]: \"SMP {} = {}\"\nproof (rule ccontr)\n  assume \"SMP {} \\<noteq> {}\"\n  then obtain t where \"t \\<in> SMP {}\" by auto\n  thus False by (induct t rule: SMP.induct) auto\nqed\n\nlemma SMP_I:\n  assumes \"s \\<in> M\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"t \\<sqsubseteq> s \\<cdot> \\<delta>\" \"\\<And>v. wf\\<^sub>t\\<^sub>r\\<^sub>m (\\<delta> v)\"\n  shows \"t \\<in> SMP M\"\nusing SMP.Substitution[OF SMP.MP[OF assms(1)] assms(2)] SMP.Subterm[of \"s \\<cdot> \\<delta>\" M t] assms(3,4)\nby (cases \"t = s \\<cdot> \\<delta>\") simp_all\n\nlemma SMP_wf_trm:\n  assumes \"t \\<in> SMP M\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s M\"\n  shows \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\nusing assms(1)\nby (induct t rule: SMP.induct)\n   (use assms(2) in blast,\n    use wf_trm_subtermeq in blast,\n    use wf_trm_subst in blast,\n    use Ana_keys_wf' in blast)\n\nlemma SMP_ikI[intro]: \"t \\<in> ik\\<^sub>s\\<^sub>t S \\<Longrightarrow> t \\<in> SMP (trms\\<^sub>s\\<^sub>t S)\" by force\n\nlemma MP_setI[intro]: \"x \\<in> set S \\<Longrightarrow> trms\\<^sub>s\\<^sub>t\\<^sub>p x \\<subseteq> trms\\<^sub>s\\<^sub>t S\" by force\n\nlemma SMP_setI[intro]: \"x \\<in> set S \\<Longrightarrow> trms\\<^sub>s\\<^sub>t\\<^sub>p x \\<subseteq> SMP (trms\\<^sub>s\\<^sub>t S)\" by force\n\nlemma SMP_subset_I:\n  assumes M: \"\\<forall>t \\<in> M. \\<exists>s \\<delta>. s \\<in> N \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> t = s \\<cdot> \\<delta>\"\n  shows \"SMP M \\<subseteq> SMP N\"\nproof\n  fix t show \"t \\<in> SMP M \\<Longrightarrow> t \\<in> SMP N\"\n  proof (induction t rule: SMP.induct)\n    case (MP t)\n    then obtain s \\<delta> where s: \"s \\<in> N\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\" \"t = s \\<cdot> \\<delta>\"\n      using M by moura\n    show ?case using SMP_I[OF s(1,2), of \"s \\<cdot> \\<delta>\"] s(3,4) wf_trm_subst_range_iff by fast\n  qed (auto intro!: SMP.Substitution[of _ N])\nqed\n\nlemma SMP_union: \"SMP (A \\<union> B) = SMP A \\<union> SMP B\"\nproof\n  show \"SMP (A \\<union> B) \\<subseteq> SMP A \\<union> SMP B\"\n  proof\n    fix t assume \"t \\<in> SMP (A \\<union> B)\"\n    thus \"t \\<in> SMP A \\<union> SMP B\" by (induct rule: SMP.induct) blast+\n  qed\n\n  { fix t assume \"t \\<in> SMP A\" hence \"t \\<in> SMP (A \\<union> B)\" by (induct rule: SMP.induct) blast+ }\n  moreover { fix t assume \"t \\<in> SMP B\" hence \"t \\<in> SMP (A \\<union> B)\" by (induct rule: SMP.induct) blast+ }\n  ultimately show \"SMP A \\<union> SMP B \\<subseteq> SMP (A \\<union> B)\" by blast\nqed\n\nlemma SMP_append[simp]: \"SMP (trms\\<^sub>s\\<^sub>t (S@S')) = SMP (trms\\<^sub>s\\<^sub>t S) \\<union> SMP (trms\\<^sub>s\\<^sub>t S')\" (is \"?A = ?B\")\nusing SMP_union by simp\n\nlemma SMP_mono: \"A \\<subseteq> B \\<Longrightarrow> SMP A \\<subseteq> SMP B\"\nproof -\n  assume \"A \\<subseteq> B\"\n  then obtain C where \"B = A \\<union> C\" by moura\n  thus \"SMP A \\<subseteq> SMP B\" by (simp add: SMP_union)\nqed\n\nlemma SMP_Union: \"SMP (\\<Union>m \\<in> M. f m) = (\\<Union>m \\<in> M. SMP (f m))\"\nproof\n  show \"SMP (\\<Union>m\\<in>M. f m) \\<subseteq> (\\<Union>m\\<in>M. SMP (f m))\"\n  proof\n    fix t assume \"t \\<in> SMP (\\<Union>m\\<in>M. f m)\"\n    thus \"t \\<in> (\\<Union>m\\<in>M. SMP (f m))\" by (induct t rule: SMP.induct) force+\n  qed\n  show \"(\\<Union>m\\<in>M. SMP (f m)) \\<subseteq> SMP (\\<Union>m\\<in>M. f m)\"\n  proof\n    fix t assume \"t \\<in> (\\<Union>m\\<in>M. SMP (f m))\"\n    then obtain m where \"m \\<in> M\" \"t \\<in> SMP (f m)\" by moura\n    thus \"t \\<in> SMP (\\<Union>m\\<in>M. f m)\" using SMP_mono[of \"f m\" \"\\<Union>m\\<in>M. f m\"] by auto\n  qed\nqed\n\nlemma SMP_singleton_ex:\n  \"t \\<in> SMP M \\<Longrightarrow> (\\<exists>m \\<in> M. t \\<in> SMP {m})\"\n  \"m \\<in> M \\<Longrightarrow> t \\<in> SMP {m} \\<Longrightarrow> t \\<in> SMP M\"\nusing SMP_Union[of \"\\<lambda>t. {t}\" M] by auto\n\nlemma SMP_Cons: \"SMP (trms\\<^sub>s\\<^sub>t (x#S)) = SMP (trms\\<^sub>s\\<^sub>t [x]) \\<union> SMP (trms\\<^sub>s\\<^sub>t S)\"\nusing SMP_append[of \"[x]\" S] by auto\n\nlemma SMP_Nil[simp]: \"SMP (trms\\<^sub>s\\<^sub>t []) = {}\" \nproof -\n  { fix t assume \"t \\<in> SMP (trms\\<^sub>s\\<^sub>t [])\" hence False by induct auto }\n  thus ?thesis by blast\nqed\n\nlemma SMP_subset_union_eq: assumes \"M \\<subseteq> SMP N\" shows \"SMP N = SMP (M \\<union> N)\"\nproof -\n  { fix t assume \"t \\<in> SMP (M \\<union> N)\" hence \"t \\<in> SMP N\"\n      using assms by (induction rule: SMP.induct) blast+\n  }\n  thus ?thesis using SMP_union by auto\nqed\n\nlemma SMP_subterms_subset: \"subterms\\<^sub>s\\<^sub>e\\<^sub>t M \\<subseteq> SMP M\"\nproof\n  fix t assume \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t M\"\n  then obtain m where \"m \\<in> M\" \"t \\<sqsubseteq> m\" by auto\n  thus \"t \\<in> SMP M\" using SMP_I[of _ _ Var] by auto\nqed\n\nlemma SMP_SMP_subset: \"N \\<subseteq> SMP M \\<Longrightarrow> SMP N \\<subseteq> SMP M\"\nby (metis SMP_mono SMP_subset_union_eq Un_commute Un_upper2)\n\nlemma wt_subst_rm_vars: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<Longrightarrow> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t (rm_vars X \\<delta>)\"\nusing rm_vars_dom unfolding wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def by auto\n\nlemma wt_subst_SMP_subset:\n  assumes \"trms\\<^sub>s\\<^sub>t S \\<subseteq> SMP S'\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\"\n  shows \"trms\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>t \\<delta>) \\<subseteq> SMP S'\"\nproof\n  fix t assume *: \"t \\<in> trms\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>t \\<delta>)\"\n  show \"t \\<in> SMP S'\" using trm_strand_subst_cong(2)[OF *]\n  proof\n    assume \"\\<exists>t'. t = t' \\<cdot> \\<delta> \\<and> t' \\<in> trms\\<^sub>s\\<^sub>t S\"\n    thus \"t \\<in> SMP S'\" using assms SMP.Substitution by auto\n  next\n    assume \"\\<exists>X F. Inequality X F \\<in> set S \\<and> (\\<exists>t'\\<in>trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F. t = t' \\<cdot> rm_vars (set X) \\<delta>)\"\n    then obtain X F t' where **:\n        \"Inequality X F \\<in> set S\" \"t'\\<in>trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F\" \"t = t' \\<cdot> rm_vars (set X) \\<delta>\"\n      by force\n    then obtain s where s: \"s \\<in> trms\\<^sub>s\\<^sub>t\\<^sub>p (Inequality X F)\" \"t = s \\<cdot> rm_vars (set X) \\<delta>\" by moura\n    hence \"s \\<in> SMP (trms\\<^sub>s\\<^sub>t S)\" using **(1) by force\n    hence \"t \\<in> SMP (trms\\<^sub>s\\<^sub>t S)\"\n      using SMP.Substitution[OF _ wt_subst_rm_vars[OF assms(2)] wf_trms_subst_rm_vars'[OF assms(3)]]\n      unfolding s(2) by blast\n    thus \"t \\<in> SMP S'\" by (metis SMP_union SMP_subset_union_eq UnCI assms(1))\n  qed\nqed\n\nlemma MP_subset_SMP: \"\\<Union>(trms\\<^sub>s\\<^sub>t\\<^sub>p ` set S) \\<subseteq> SMP (trms\\<^sub>s\\<^sub>t S)\" \"trms\\<^sub>s\\<^sub>t S \\<subseteq> SMP (trms\\<^sub>s\\<^sub>t S)\" \"M \\<subseteq> SMP M\"\nby auto\n\nlemma SMP_fun_map_snd_subset: \"SMP (trms\\<^sub>s\\<^sub>t (map Send X)) \\<subseteq> SMP (trms\\<^sub>s\\<^sub>t [Send (Fun f X)])\"\nproof\n  fix t assume \"t \\<in> SMP (trms\\<^sub>s\\<^sub>t (map Send X))\" thus \"t \\<in> SMP (trms\\<^sub>s\\<^sub>t [Send (Fun f X)])\"\n  proof (induction t rule: SMP.induct)\n    case (MP t)\n    hence \"t \\<in> set X\" by auto\n    hence \"t \\<sqsubset> Fun f X\" by (metis subtermI')\n    thus ?case using SMP.Subterm[of \"Fun f X\" \"trms\\<^sub>s\\<^sub>t [Send (Fun f X)]\" t] using SMP.MP by auto\n  qed blast+\nqed\n\nlemma SMP_wt_subst_subset:\n  assumes \"t \\<in> SMP (M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>)\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<I>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<I>)\"\n  shows \"t \\<in> SMP M\"\nusing assms wf_trm_subst_range_iff[of \\<I>] by (induct t rule: SMP.induct) blast+\n\nlemma SMP_wt_instances_subset:\n  assumes \"\\<forall>t \\<in> M. \\<exists>s \\<in> N. \\<exists>\\<delta>. t = s \\<cdot> \\<delta> \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\"\n    and \"t \\<in> SMP M\"\n  shows \"t \\<in> SMP N\"\nproof -\n  obtain m where m: \"m \\<in> M\" \"t \\<in> SMP {m}\" using SMP_singleton_ex(1)[OF assms(2)] by blast\n  then obtain n \\<delta> where n: \"n \\<in> N\" \"m = n \\<cdot> \\<delta>\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\"\n    using assms(1) by fast\n\n  have \"t \\<in> SMP (N \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>)\" using n(1,2) SMP_singleton_ex(2)[of m \"N \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>\", OF _ m(2)] by fast\n  thus ?thesis using SMP_wt_subst_subset[OF _ n(3,4)] by blast\nqed\n\nlemma SMP_consts:\n  assumes \"\\<forall>t \\<in> M. \\<exists>c. t = Fun c []\"\n    and \"\\<forall>t \\<in> M. Ana t = ([], [])\"\n  shows \"SMP M = M\"\nproof\n  show \"SMP M \\<subseteq> M\"\n  proof\n    fix t show \"t \\<in> SMP M \\<Longrightarrow> t \\<in> M\"\n      apply (induction t rule: SMP.induct)\n      by (use assms in auto)\n  qed\nqed auto\n\nlemma SMP_subterms_eq:\n  \"SMP (subterms\\<^sub>s\\<^sub>e\\<^sub>t M) = SMP M\"\nproof\n  show \"SMP M \\<subseteq> SMP (subterms\\<^sub>s\\<^sub>e\\<^sub>t M)\" using SMP_mono[of M \"subterms\\<^sub>s\\<^sub>e\\<^sub>t M\"] by blast\n  show \"SMP (subterms\\<^sub>s\\<^sub>e\\<^sub>t M) \\<subseteq> SMP M\"\n  proof\n    fix t show \"t \\<in> SMP (subterms\\<^sub>s\\<^sub>e\\<^sub>t M) \\<Longrightarrow> t \\<in> SMP M\" by (induction t rule: SMP.induct) blast+\n  qed\nqed\n\nlemma SMP_funs_term:\n  assumes t: \"t \\<in> SMP M\" \"f \\<in> funs_term t \\<or> (\\<exists>x \\<in> fv t. f \\<in> funs_term (\\<Gamma> (Var x)))\"\n    and f: \"arity f > 0\"\n    and M: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s M\"\n    and Ana_f: \"\\<And>s K T. Ana s = (K,T) \\<Longrightarrow> f \\<in> \\<Union>(funs_term ` set K) \\<Longrightarrow> f \\<in> funs_term s\"\n  shows \"f \\<in> \\<Union>(funs_term ` M) \\<or> (\\<exists>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t M. f \\<in> funs_term (\\<Gamma> (Var x)))\"\nusing t\nproof (induction t rule: SMP.induct)\n  case (Subterm t t')\n  thus ?case by (metis UN_I vars_iff_subtermeq funs_term_subterms_eq(1) term.order_trans)\nnext\n  case (Substitution t \\<delta>)\n  show ?case\n    using M SMP_wf_trm[OF Substitution.hyps(1)] wf_trm_subst[of \\<delta> t, OF Substitution.hyps(3)]\n          funs_term_type_iff[OF _ f] wt_subst_trm''[OF Substitution.hyps(2), of t]\n          Substitution.prems Substitution.IH\n    by metis\nnext\n  case (Ana t K T t')\n  thus ?case\n    using Ana_f[OF Ana.hyps(2)] Ana_keys_fv[OF Ana.hyps(2)]\n    by fastforce\nqed auto\n\nlemma id_type_eq:\n  assumes \"\\<Gamma> (Fun f X) = \\<Gamma> (Fun g Y)\"\n  shows \"f \\<in> \\<C> \\<Longrightarrow> g \\<in> \\<C>\" \"f \\<in> \\<Sigma>\\<^sub>f \\<Longrightarrow> g \\<in> \\<Sigma>\\<^sub>f\"\nusing assms const_type' fun_type' id_union_univ(1)\nby (metis UNIV_I UnE \"term.distinct\"(1))+\n\n\n\nlemma fun_type_arg_cong':\n  assumes \"f \\<in> \\<Sigma>\\<^sub>f\" \"g \\<in> \\<Sigma>\\<^sub>f\" \"\\<Gamma> (Fun f (X@x#X')) = \\<Gamma> (Fun g (Y@y#Y'))\" \"length X = length Y\"\n  shows \"\\<Gamma> x = \\<Gamma> y\"\nusing assms\nproof (induction X arbitrary: Y)\n  case Nil thus ?case using fun_type_arg_cong(1)[of f g x X' y Y'] by auto\nnext\n  case (Cons x' X Y'')\n  then obtain y' Y where \"Y'' = y'#Y\" by (metis length_Suc_conv)\n  hence \"\\<Gamma> (Fun f (X@x#X')) = \\<Gamma> (Fun g (Y@y#Y'))\" \"length X = length Y\"\n    using Cons.prems(3,4) fun_type_arg_cong(2)[OF Cons.prems(1,2), of x' \"X@x#X'\"] by auto\n  thus ?thesis using Cons.IH[OF Cons.prems(1,2)] by auto\nqed\n\nlemma fun_type_param_idx: \"\\<Gamma> (Fun f T) = Fun g S \\<Longrightarrow> i < length T \\<Longrightarrow> \\<Gamma> (T ! i) = S ! i\"\nby (metis fun_type fun_type_id_eq fun_type_inv(1) nth_map term.inject(2))\n\nlemma fun_type_param_ex:\n  assumes \"\\<Gamma> (Fun f T) = Fun g (map \\<Gamma> S)\" \"t \\<in> set S\"\n  shows \"\\<exists>s \\<in> set T. \\<Gamma> s = \\<Gamma> t\"\nusing fun_type_length_eq[OF assms(1)] length_map[of \\<Gamma> S] assms(2)\n      fun_type_param_idx[OF assms(1)] nth_map in_set_conv_nth\nby metis\n\nlemma tfr_stp_all_split:\n  \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (x#S) \\<Longrightarrow> list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p [x]\"\n  \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (x#S) \\<Longrightarrow> list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n  \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (S@S') \\<Longrightarrow> list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n  \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (S@S') \\<Longrightarrow> list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S'\"\n  \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (S@x#S') \\<Longrightarrow> list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (S@S')\"\nby fastforce+\n\nlemma tfr_stp_all_append:\n  assumes \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\" \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S'\"\n  shows \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (S@S')\"\nusing assms by fastforce\n\nlemma tfr_stp_all_wt_subst_apply:\n  assumes \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\"\n    and \\<theta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n           \"bvars\\<^sub>s\\<^sub>t S \\<inter> range_vars \\<theta> = {}\"\n  shows \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (S \\<cdot>\\<^sub>s\\<^sub>t \\<theta>)\"\nusing assms(1,4)\nproof (induction S)\n  case (Cons x S)\n  hence IH: \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (S \\<cdot>\\<^sub>s\\<^sub>t \\<theta>)\"\n    using tfr_stp_all_split(2)[of x S]\n    unfolding range_vars_alt_def by fastforce\n  thus ?case\n  proof (cases x)\n    case (Equality a t t')\n    hence \"(\\<exists>\\<delta>. Unifier \\<delta> t t') \\<longrightarrow> \\<Gamma> t = \\<Gamma> t'\" using Cons.prems by auto\n    hence \"(\\<exists>\\<delta>. Unifier \\<delta> (t \\<cdot> \\<theta>) (t' \\<cdot> \\<theta>)) \\<longrightarrow> \\<Gamma> (t \\<cdot> \\<theta>) = \\<Gamma> (t' \\<cdot> \\<theta>)\"\n      by (metis Unifier_comp' wt_subst_trm'[OF assms(2)])\n    moreover have \"(x#S) \\<cdot>\\<^sub>s\\<^sub>t \\<theta> = Equality a (t \\<cdot> \\<theta>) (t' \\<cdot> \\<theta>)#(S \\<cdot>\\<^sub>s\\<^sub>t \\<theta>)\"\n      using \\<open>x = Equality a t t'\\<close> by auto\n    ultimately show ?thesis using IH by auto\n  next\n    case (Inequality X F)\n    let ?\\<sigma> = \"rm_vars (set X) \\<theta>\"\n    let ?G = \"F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ?\\<sigma>\"\n\n    let ?P = \"\\<lambda>F X. \\<forall>x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F - set X. \\<exists>a. \\<Gamma> (Var x) = TAtom a\"\n    let ?Q = \"\\<lambda>F X.\n      \\<forall>f T. Fun f T \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F) \\<longrightarrow> T = [] \\<or> (\\<exists>s \\<in> set T. s \\<notin> Var ` set X)\"\n\n    have 0: \"set X \\<inter> range_vars ?\\<sigma> = {}\"\n      using Cons.prems(2) Inequality rm_vars_img_subset[of \"set X\"]\n      by (auto simp add: subst_domain_def range_vars_alt_def)\n\n    have 1: \"?P F X \\<or> ?Q F X\" using Inequality Cons.prems by simp\n\n    have 2: \"fv\\<^sub>s\\<^sub>e\\<^sub>t (?\\<sigma> ` set X) = set X\" by auto\n\n    have \"?P ?G X\" when \"?P F X\" using that\n    proof (induction F)\n      case (Cons g G)\n      obtain t t' where g: \"g = (t,t')\" by (metis surj_pair)\n      \n      have \"\\<forall>x \\<in> (fv (t \\<cdot> ?\\<sigma>) \\<union> fv (t' \\<cdot> ?\\<sigma>)) - set X. \\<exists>a. \\<Gamma> (Var x) = Var a\"\n      proof -\n        have *: \"\\<forall>x \\<in> fv t - set X. \\<exists>a. \\<Gamma> (Var x) = Var a\"\n               \"\\<forall>x \\<in> fv t' - set X. \\<exists>a. \\<Gamma> (Var x) = Var a\"\n          using g Cons.prems by simp_all\n\n        have **: \"\\<forall>x. wf\\<^sub>t\\<^sub>r\\<^sub>m (?\\<sigma> x)\"\n          using \\<theta>(2) wf_trm_subst_range_iff[of \\<theta>] wf_trm_subst_rm_vars'[of \\<theta> _ \"set X\"] by simp\n\n        show ?thesis\n          using wt_subst_TAtom_fv[OF wt_subst_rm_vars[OF \\<theta>(1)] ** *(1)]\n                wt_subst_TAtom_fv[OF wt_subst_rm_vars[OF \\<theta>(1)] ** *(2)]\n                wt_subst_trm'[OF wt_subst_rm_vars[OF \\<theta>(1), of \"set X\"]] 2\n          by blast\n      qed\n      moreover have \"\\<forall>x\\<in>fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ?\\<sigma>) - set X. \\<exists>a. \\<Gamma> (Var x) = Var a\"\n        using Cons by auto\n      ultimately show ?case using g by (auto simp add: subst_apply_pairs_def)\n    qed (simp add: subst_apply_pairs_def)\n    hence \"?P ?G X \\<or> ?Q ?G X\"\n      using 1 ineq_subterm_inj_cond_subst[OF 0, of \"trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F\"] trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_subst[of F ?\\<sigma>]\n      by presburger\n    moreover have \"(x#S) \\<cdot>\\<^sub>s\\<^sub>t \\<theta> = Inequality X (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ?\\<sigma>)#(S \\<cdot>\\<^sub>s\\<^sub>t \\<theta>)\"\n      using \\<open>x = Inequality X F\\<close> by auto\n    ultimately show ?thesis using IH by simp\n  qed auto\nqed simp\n\nlemma tfr_stp_all_same_type:\n  \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (S@Equality a t t'#S') \\<Longrightarrow> Unifier \\<delta> t t' \\<Longrightarrow> \\<Gamma> t = \\<Gamma> t'\"\nby force+\n\nlemma tfr_subset:\n  \"\\<And>A B. tfr\\<^sub>s\\<^sub>e\\<^sub>t (A \\<union> B) \\<Longrightarrow> tfr\\<^sub>s\\<^sub>e\\<^sub>t A\"\n  \"\\<And>A B. tfr\\<^sub>s\\<^sub>e\\<^sub>t B \\<Longrightarrow> A \\<subseteq> B \\<Longrightarrow> tfr\\<^sub>s\\<^sub>e\\<^sub>t A\"\n  \"\\<And>A B. tfr\\<^sub>s\\<^sub>e\\<^sub>t B \\<Longrightarrow> SMP A \\<subseteq> SMP B \\<Longrightarrow> tfr\\<^sub>s\\<^sub>e\\<^sub>t A\"\nproof -\n  show 1: \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (A \\<union> B) \\<Longrightarrow> tfr\\<^sub>s\\<^sub>e\\<^sub>t A\" for A B\n    using SMP_union[of A B] unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by simp\n\n  fix A B assume B: \"tfr\\<^sub>s\\<^sub>e\\<^sub>t B\"\n\n  show \"A \\<subseteq> B \\<Longrightarrow> tfr\\<^sub>s\\<^sub>e\\<^sub>t A\"\n  proof -\n    assume \"A \\<subseteq> B\"\n    then obtain C where \"B = A \\<union> C\" by moura\n    thus ?thesis using B 1 by blast\n  qed\n\n  show \"SMP A \\<subseteq> SMP B \\<Longrightarrow> tfr\\<^sub>s\\<^sub>e\\<^sub>t A\"\n  proof -\n    assume \"SMP A \\<subseteq> SMP B\"\n    then obtain C where \"SMP B = SMP A \\<union> C\" by moura\n    thus ?thesis using B unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by blast\n  qed\nqed\n\nlemma tfr_empty[simp]: \"tfr\\<^sub>s\\<^sub>e\\<^sub>t {}\"\nunfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by simp\n\nlemma tfr_consts_mono:\n  assumes \"\\<forall>t \\<in> M. \\<exists>c. t = Fun c []\"\n    and \"\\<forall>t \\<in> M. Ana t = ([], [])\"\n    and \"tfr\\<^sub>s\\<^sub>e\\<^sub>t N\"\n  shows \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (N \\<union> M)\"\nproof -\n  { fix s t\n    assume *: \"s \\<in> SMP (N \\<union> M) - range Var\" \"t \\<in> SMP (N \\<union> M) - range Var\" \"\\<exists>\\<delta>. Unifier \\<delta> s t\"\n    hence **: \"is_Fun s\" \"is_Fun t\" \"s \\<in> SMP N \\<or> s \\<in> M\" \"t \\<in> SMP N \\<or> t \\<in> M\"\n      using assms(3) SMP_consts[OF assms(1,2)] SMP_union[of N M] by auto\n    moreover have \"\\<Gamma> s = \\<Gamma> t\" when \"s \\<in> SMP N\" \"t \\<in> SMP N\"\n      using that assms(3) *(3) **(1,2) unfolding tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by blast\n    moreover have \"\\<Gamma> s = \\<Gamma> t\" when st: \"s \\<in> M\" \"t \\<in> M\"\n    proof -\n      obtain c d where \"s = Fun c []\" \"t = Fun d []\" using st assms(1) by moura\n      hence \"s = t\" using *(3) by fast\n      thus ?thesis by metis\n    qed\n    moreover have \"\\<Gamma> s = \\<Gamma> t\" when st: \"s \\<in> SMP N\" \"t \\<in> M\"\n    proof -\n      obtain c where \"t = Fun c []\" using st assms(1) by moura\n      hence \"s = t\" using *(3) **(1,2) by auto\n      thus ?thesis by metis\n    qed\n    moreover have \"\\<Gamma> s = \\<Gamma> t\" when st: \"s \\<in> M\" \"t \\<in> SMP N\"\n    proof -\n      obtain c where \"s = Fun c []\" using st assms(1) by moura\n      hence \"s = t\" using *(3) **(1,2) by auto\n      thus ?thesis by metis\n    qed\n    ultimately have \"\\<Gamma> s = \\<Gamma> t\" by metis\n  } thus ?thesis by (metis tfr\\<^sub>s\\<^sub>e\\<^sub>t_def)\nqed\n\nlemma dual\\<^sub>s\\<^sub>t_tfr\\<^sub>s\\<^sub>t\\<^sub>p: \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S \\<Longrightarrow> list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (dual\\<^sub>s\\<^sub>t S)\"\nproof (induction S)\n  case (Cons x S)\n  have \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\" using Cons.prems by simp\n  hence IH: \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p (dual\\<^sub>s\\<^sub>t S)\" using Cons.IH by metis\n  from Cons show ?case\n  proof (cases x)\n    case (Equality a t t')\n    hence \"(\\<exists>\\<delta>. Unifier \\<delta> t t') \\<Longrightarrow> \\<Gamma> t = \\<Gamma> t'\" using Cons by auto\n    thus ?thesis using Equality IH by fastforce\n  next\n    case (Inequality X F)\n    have \"set (dual\\<^sub>s\\<^sub>t (x#S)) = insert x (set (dual\\<^sub>s\\<^sub>t S))\" using Inequality by auto\n    moreover have \"(\\<forall>x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F - set X. \\<exists>a. \\<Gamma> (Var x) = Var a) \\<or>\n            (\\<forall>f T. Fun f T \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F) \\<longrightarrow> T = [] \\<or> (\\<exists>s \\<in> set T. s \\<notin> Var ` set X))\" \n      using Cons.prems Inequality by auto\n    ultimately show ?thesis using Inequality IH by auto\n  qed auto\nqed simp\n\nlemma subst_var_inv_wt:\n  assumes \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\"\n  shows \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t (subst_var_inv \\<delta> X)\"\nusing assms f_inv_into_f[of _ \\<delta> X]\nunfolding wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def subst_var_inv_def\nby presburger\n\nlemma subst_var_inv_wf_trms:\n  \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range (subst_var_inv \\<delta> X))\"\nusing f_inv_into_f[of _ \\<delta> X]\nunfolding wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def subst_var_inv_def\nby auto\n\nlemma unify_list_wt_if_same_type:\n  assumes \"Unification.unify E B = Some U\" \"\\<forall>(s,t) \\<in> set E. wf\\<^sub>t\\<^sub>r\\<^sub>m s \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m t \\<and> \\<Gamma> s = \\<Gamma> t\"\n  and \"\\<forall>(v,t) \\<in> set B. \\<Gamma> (Var v) = \\<Gamma> t\"\n  shows \"\\<forall>(v,t) \\<in> set U. \\<Gamma> (Var v) = \\<Gamma> t\"\nusing assms\nproof (induction E B arbitrary: U rule: Unification.unify.induct)\n  case (2 f X g Y E B U)\n  hence \"wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f X)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun g Y)\" \"\\<Gamma> (Fun f X) = \\<Gamma> (Fun g Y)\" by auto\n\n  from \"2.prems\"(1) obtain E' where *: \"decompose (Fun f X) (Fun g Y) = Some E'\"\n    and [simp]: \"f = g\" \"length X = length Y\" \"E' = zip X Y\"\n    and **: \"Unification.unify (E'@E) B = Some U\"\n    by (auto split: option.splits)\n  \n  have \"\\<forall>(s,t) \\<in> set E'. wf\\<^sub>t\\<^sub>r\\<^sub>m s \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m t \\<and> \\<Gamma> s = \\<Gamma> t\"\n  proof -\n    { fix s t assume \"(s,t) \\<in> set E'\"\n      then obtain X' X'' Y' Y'' where \"X = X'@s#X''\" \"Y = Y'@t#Y''\" \"length X' = length Y'\"\n        using zip_arg_subterm_split[of s t X Y] \\<open>E' = zip X Y\\<close> by metis\n      hence \"\\<Gamma> (Fun f (X'@s#X'')) = \\<Gamma> (Fun g (Y'@t#Y''))\" by (metis \\<open>\\<Gamma> (Fun f X) = \\<Gamma> (Fun g Y)\\<close>)\n      \n      from \\<open>E' = zip X Y\\<close> have \"\\<forall>(s,t) \\<in> set E'. s \\<sqsubset> Fun f X \\<and> t \\<sqsubset> Fun g Y\"\n        using zip_arg_subterm[of _ _ X Y] by blast\n      with \\<open>(s,t) \\<in> set E'\\<close> have \"wf\\<^sub>t\\<^sub>r\\<^sub>m s\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\n        using wf_trm_subterm \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f X)\\<close> \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun g Y)\\<close> by (blast,blast)\n      moreover have \"f \\<in> \\<Sigma>\\<^sub>f\"\n      proof (rule ccontr)\n        assume \"f \\<notin> \\<Sigma>\\<^sub>f\"\n        hence \"f \\<in> \\<C>\" \"arity f = 0\" using const_arity_eq_zero[of f] by simp_all\n        thus False using \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f X)\\<close> * \\<open>(s,t) \\<in> set E'\\<close> unfolding wf\\<^sub>t\\<^sub>r\\<^sub>m_def by auto\n      qed\n      hence \"\\<Gamma> s = \\<Gamma> t\"\n        using fun_type_arg_cong' \\<open>f \\<in> \\<Sigma>\\<^sub>f\\<close> \\<open>\\<Gamma> (Fun f (X'@s#X'')) = \\<Gamma> (Fun g (Y'@t#Y''))\\<close>\n              \\<open>length X' = length Y'\\<close> \\<open>f = g\\<close>\n        by metis\n      ultimately have \"wf\\<^sub>t\\<^sub>r\\<^sub>m s\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"\\<Gamma> s = \\<Gamma> t\" by metis+\n    }\n    thus ?thesis by blast\n  qed\n  moreover have \"\\<forall>(s,t) \\<in> set E. wf\\<^sub>t\\<^sub>r\\<^sub>m s \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m t \\<and> \\<Gamma> s = \\<Gamma> t\" using \"2.prems\"(2) by auto\n  ultimately show ?case using \"2.IH\"[OF * ** _ \"2.prems\"(3)] by fastforce\nnext\n  case (3 v t E B U)\n  hence \"\\<Gamma> (Var v) = \\<Gamma> t\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" by auto\n  hence \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t (subst v t)\"\n      and *: \"\\<forall>(v, t) \\<in> set ((v,t)#B). \\<Gamma> (Var v) = \\<Gamma> t\"\n             \"\\<And>t t'. (t,t') \\<in> set E \\<Longrightarrow> \\<Gamma> t = \\<Gamma> t'\"\n    using \"3.prems\"(2,3) unfolding wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def subst_def by auto\n\n  show ?case\n  proof (cases \"t = Var v\")\n    assume \"t = Var v\" thus ?case using 3 by auto\n  next\n    assume \"t \\<noteq> Var v\"\n    hence \"v \\<notin> fv t\" using \"3.prems\"(1) by auto\n    hence **: \"Unification.unify (subst_list (subst v t) E) ((v, t)#B) = Some U\"\n      using Unification.unify.simps(3)[of v t E B] \"3.prems\"(1) \\<open>t \\<noteq> Var v\\<close> by auto\n    \n    have \"\\<forall>(s, t) \\<in> set (subst_list (subst v t) E). wf\\<^sub>t\\<^sub>r\\<^sub>m s \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\n      using wf_trm_subst_singleton[OF _ \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m t\\<close>] \"3.prems\"(2)\n      unfolding subst_list_def subst_def by auto\n    moreover have \"\\<forall>(s, t) \\<in> set (subst_list (subst v t) E). \\<Gamma> s = \\<Gamma> t\"\n      using *(2)[THEN wt_subst_trm'[OF \\<open>wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t (subst v t)\\<close>]] by (simp add: subst_list_def)\n    ultimately show ?thesis using \"3.IH\"(2)[OF \\<open>t \\<noteq> Var v\\<close> \\<open>v \\<notin> fv t\\<close> ** _ *(1)] by auto\n  qed\nnext\n  case (4 f X v E B U)\n  hence \"\\<Gamma> (Var v) = \\<Gamma> (Fun f X)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f X)\" by auto\n  hence \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t (subst v (Fun f X))\"\n      and *: \"\\<forall>(v, t) \\<in> set ((v,(Fun f X))#B). \\<Gamma> (Var v) = \\<Gamma> t\"\n             \"\\<And>t t'. (t,t') \\<in> set E \\<Longrightarrow> \\<Gamma> t = \\<Gamma> t'\"\n    using \"4.prems\"(2,3) unfolding wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def subst_def by auto\n\n  have \"v \\<notin> fv (Fun f X)\" using \"4.prems\"(1) by force\n  hence **: \"Unification.unify (subst_list (subst v (Fun f X)) E) ((v, (Fun f X))#B) = Some U\"\n    using Unification.unify.simps(3)[of v \"Fun f X\" E B] \"4.prems\"(1) by auto\n  \n  have \"\\<forall>(s, t) \\<in> set (subst_list (subst v (Fun f X)) E). wf\\<^sub>t\\<^sub>r\\<^sub>m s \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\n    using wf_trm_subst_singleton[OF _ \\<open>wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun f X)\\<close>] \"4.prems\"(2)\n    unfolding subst_list_def subst_def by auto\n  moreover have \"\\<forall>(s, t) \\<in> set (subst_list (subst v (Fun f X)) E). \\<Gamma> s = \\<Gamma> t\"\n    using *(2)[THEN wt_subst_trm'[OF \\<open>wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t (subst v (Fun f X))\\<close>]] by (simp add: subst_list_def)\n  ultimately show ?case using \"4.IH\"[OF \\<open>v \\<notin> fv (Fun f X)\\<close> ** _ *(1)] by auto\nqed auto\n\nlemma mgu_wt_if_same_type:\n  assumes \"mgu s t = Some \\<sigma>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m s\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"\\<Gamma> s = \\<Gamma> t\"\n  shows \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma>\"\nproof -\n  let ?fv_disj = \"\\<lambda>v t S. \\<not>(\\<exists>(v',t') \\<in> S - {(v,t)}. (insert v (fv t)) \\<inter> (insert v' (fv t')) \\<noteq> {})\"\n\n  from assms(1) obtain \\<sigma>' where \"Unification.unify [(s,t)] [] = Some \\<sigma>'\" \"subst_of \\<sigma>' = \\<sigma>\"\n    by (auto split: option.splits)\n  hence \"\\<forall>(v,t) \\<in> set \\<sigma>'. \\<Gamma> (Var v) = \\<Gamma> t\" \"distinct (map fst \\<sigma>')\"\n    using assms(2,3,4) unify_list_wt_if_same_type unify_list_distinct[of \"[(s,t)]\"] by auto\n  thus \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma>\" using \\<open>subst_of \\<sigma>' = \\<sigma>\\<close> unfolding wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def\n  proof (induction \\<sigma>' arbitrary: \\<sigma> rule: List.rev_induct)\n    case (snoc tt \\<sigma>' \\<sigma>)\n    then obtain v t where tt: \"tt = (v,t)\" by (metis surj_pair)\n    hence \\<sigma>: \"\\<sigma> = subst v t \\<circ>\\<^sub>s subst_of \\<sigma>'\" using snoc.prems(3) by simp\n    \n    have \"\\<forall>(v,t) \\<in> set \\<sigma>'. \\<Gamma> (Var v) = \\<Gamma> t\" \"distinct (map fst \\<sigma>')\" using snoc.prems(1,2) by auto\n    then obtain \\<sigma>'' where \\<sigma>'': \"subst_of \\<sigma>' = \\<sigma>''\" \"\\<forall>v. \\<Gamma> (Var v) = \\<Gamma> (\\<sigma>'' v)\" by (metis snoc.IH)\n    hence \"\\<Gamma> t = \\<Gamma> (t \\<cdot> \\<sigma>'')\" for t using wt_subst_trm by blast\n    hence \"\\<Gamma> (Var v) = \\<Gamma> (\\<sigma>'' v)\" \"\\<Gamma> t = \\<Gamma> (t \\<cdot> \\<sigma>'')\" using \\<sigma>''(2) by auto\n    moreover have \"\\<Gamma> (Var v) = \\<Gamma> t\" using snoc.prems(1) tt by simp\n    moreover have \\<sigma>2: \"\\<sigma> = Var(v := t) \\<circ>\\<^sub>s \\<sigma>'' \" using \\<sigma> \\<sigma>''(1) unfolding subst_def by simp\n    ultimately have \"\\<Gamma> (Var v) = \\<Gamma> (\\<sigma> v)\" unfolding subst_compose_def by simp\n\n    have \"subst_domain (subst v t) \\<subseteq> {v}\" unfolding subst_def by (auto simp add: subst_domain_def)\n    hence *: \"subst_domain \\<sigma> \\<subseteq> insert v (subst_domain \\<sigma>'')\"\n      using tt \\<sigma> \\<sigma>''(1) snoc.prems(2) subst_domain_compose[of _ \\<sigma>'']\n      by (auto simp add: subst_domain_def)\n    \n    have \"v \\<notin> set (map fst \\<sigma>')\" using tt snoc.prems(2) by auto\n    hence \"v \\<notin> subst_domain \\<sigma>''\" using \\<sigma>''(1) subst_of_dom_subset[of \\<sigma>'] by auto\n\n    { fix w assume \"w \\<in> subst_domain \\<sigma>''\"\n      hence \"\\<sigma> w = \\<sigma>'' w\" using \\<sigma>2 \\<sigma>''(1) \\<open>v \\<notin> subst_domain \\<sigma>''\\<close> unfolding subst_compose_def by auto\n      hence \"\\<Gamma> (Var w) = \\<Gamma> (\\<sigma> w)\" using \\<sigma>''(2) by simp\n    }\n    thus ?case using \\<open>\\<Gamma> (Var v) = \\<Gamma> (\\<sigma> v)\\<close> * by force\n  qed simp\nqed\n\nlemma wt_Unifier_if_Unifier:\n  assumes s_t: \"wf\\<^sub>t\\<^sub>r\\<^sub>m s\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"\\<Gamma> s = \\<Gamma> t\"\n    and \\<delta>: \"Unifier \\<delta> s t\"\n  shows \"\\<exists>\\<theta>. Unifier \\<theta> s t \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\nusing mgu_always_unifies[OF \\<delta>] mgu_gives_MGU[THEN MGU_is_Unifier[of s _ t]]\n      mgu_wt_if_same_type[OF _ s_t] mgu_wf_trm[OF _ s_t(1,2)] wf_trm_subst_range_iff\nby fast\n\nend\n\n\nsubsection \\<open>Automatically Proving Type-Flaw Resistance\\<close>\nsubsubsection \\<open>Definitions: Variable Renaming\\<close>\nabbreviation \"max_var t \\<equiv> Max (insert 0 (snd ` fv t))\"\nabbreviation \"max_var_set X \\<equiv> Max (insert 0 (snd ` X))\"\n\ndefinition \"var_rename n v \\<equiv> Var (fst v, snd v + Suc n)\"\ndefinition \"var_rename_inv n v \\<equiv> Var (fst v, snd v - Suc n)\"\n\n\nsubsubsection \\<open>Definitions: Computing a Finite Representation of the Sub-Message Patterns\\<close>\ntext \\<open>A sufficient requirement for a term to be a well-typed instance of another term\\<close>\ndefinition is_wt_instance_of_cond where\n  \"is_wt_instance_of_cond \\<Gamma> t s \\<equiv> (\n    \\<Gamma> t = \\<Gamma> s \\<and> (case mgu t s of\n      None \\<Rightarrow> False\n    | Some \\<delta> \\<Rightarrow> inj_on \\<delta> (fv t) \\<and> (\\<forall>x \\<in> fv t. is_Var (\\<delta> x))))\"\n\ndefinition has_all_wt_instances_of where\n  \"has_all_wt_instances_of \\<Gamma> N M \\<equiv> \\<forall>t \\<in> N. \\<exists>s \\<in> M. is_wt_instance_of_cond \\<Gamma> t s\"\n\ntext \\<open>This function computes a finite representation of the set of sub-message patterns\\<close>\ndefinition SMP0 where\n  \"SMP0 Ana \\<Gamma> M \\<equiv> let\n      f = \\<lambda>t. Fun (the_Fun (\\<Gamma> t)) (map Var (zip (args (\\<Gamma> t)) [0..<length (args (\\<Gamma> t))]));\n      g = \\<lambda>M'. map f (filter (\\<lambda>t. is_Var t \\<and> is_Fun (\\<Gamma> t)) M')@\n               concat (map (fst \\<circ> Ana) M')@concat (map subterms_list M');\n      h = remdups \\<circ> g\n    in while (\\<lambda>A. set (h A) \\<noteq> set A) h M\"\n\ntext \\<open>These definitions are useful to refine an SMP representation set\\<close>\nfun generalize_term where\n  \"generalize_term _ _ n (Var x) = (Var x, n)\"\n| \"generalize_term \\<Gamma> p n (Fun f T) = (let \\<tau> = \\<Gamma> (Fun f T)\n    in if p \\<tau> then (Var (\\<tau>, n), Suc n)\n       else let (T',n') = foldr (\\<lambda>t (S,m). let (t',m') = generalize_term \\<Gamma> p m t in (t'#S,m'))\n                                T ([],n)\n            in (Fun f T', n'))\"\n\ndefinition generalize_terms where\n  \"generalize_terms \\<Gamma> p \\<equiv> map (fst \\<circ> generalize_term \\<Gamma> p 0)\"\n\ndefinition remove_superfluous_terms where\n  \"remove_superfluous_terms \\<Gamma> T \\<equiv>\n    let\n      f = \\<lambda>S t R. \\<exists>s \\<in> set S - R. s \\<noteq> t \\<and> is_wt_instance_of_cond \\<Gamma> t s;\n      g = \\<lambda>S t (U,R). if f S t R then (U, insert t R) else (t#U, R);\n      h = \\<lambda>S. remdups (fst (foldr (g S) S ([],{})))\n    in while (\\<lambda>S. h S \\<noteq> S) h T\"\n\n\nsubsubsection \\<open>Definitions: Checking Type-Flaw Resistance\\<close>\ndefinition is_TComp_var_instance_closed where\n  \"is_TComp_var_instance_closed \\<Gamma> M \\<equiv> \\<forall>x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M). is_Fun (\\<Gamma> (Var x)) \\<longrightarrow>\n      list_ex (\\<lambda>t. is_Fun t \\<and> \\<Gamma> t = \\<Gamma> (Var x) \\<and> list_all is_Var (args t) \\<and> distinct (args t)) M\"\n\ndefinition finite_SMP_representation where\n  \"finite_SMP_representation arity Ana \\<Gamma> M \\<equiv>\n    list_all (wf\\<^sub>t\\<^sub>r\\<^sub>m' arity) M \\<and>\n    has_all_wt_instances_of \\<Gamma> (subterms\\<^sub>s\\<^sub>e\\<^sub>t (set M)) (set M) \\<and>\n    has_all_wt_instances_of \\<Gamma> (\\<Union>((set \\<circ> fst \\<circ> Ana) ` set M)) (set M) \\<and>\n    is_TComp_var_instance_closed \\<Gamma> M\"\n\ndefinition comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t where\n  \"comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t arity Ana \\<Gamma> M \\<equiv>\n    finite_SMP_representation arity Ana \\<Gamma> M \\<and>\n    (let \\<delta> = var_rename (max_var_set (fv\\<^sub>s\\<^sub>e\\<^sub>t (set M)))\n     in \\<forall>s \\<in> set M. \\<forall>t \\<in> set M. is_Fun s \\<and> is_Fun t \\<and> \\<Gamma> s \\<noteq> \\<Gamma> t \\<longrightarrow> mgu s (t \\<cdot> \\<delta>) = None)\"\n\nfun comp_tfr\\<^sub>s\\<^sub>t\\<^sub>p where\n  \"comp_tfr\\<^sub>s\\<^sub>t\\<^sub>p \\<Gamma> (\\<langle>_: t \\<doteq> t'\\<rangle>\\<^sub>s\\<^sub>t) = (mgu t t' \\<noteq> None \\<longrightarrow> \\<Gamma> t = \\<Gamma> t')\"\n| \"comp_tfr\\<^sub>s\\<^sub>t\\<^sub>p \\<Gamma> (\\<forall>X\\<langle>\\<or>\\<noteq>: F\\<rangle>\\<^sub>s\\<^sub>t) = (\n    (\\<forall>x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F - set X. is_Var (\\<Gamma> (Var x))) \\<or>\n    (\\<forall>u \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F).\n      is_Fun u \\<longrightarrow> (args u = [] \\<or> (\\<exists>s \\<in> set (args u). s \\<notin> Var ` set X))))\"\n| \"comp_tfr\\<^sub>s\\<^sub>t\\<^sub>p _ _ = True\"\n\ndefinition comp_tfr\\<^sub>s\\<^sub>t where\n  \"comp_tfr\\<^sub>s\\<^sub>t arity Ana \\<Gamma> M S \\<equiv>\n    list_all (comp_tfr\\<^sub>s\\<^sub>t\\<^sub>p \\<Gamma>) S \\<and>\n    list_all (wf\\<^sub>t\\<^sub>r\\<^sub>m' arity) (trms_list\\<^sub>s\\<^sub>t S) \\<and>\n    has_all_wt_instances_of \\<Gamma> (trms\\<^sub>s\\<^sub>t S) (set M) \\<and>\n    comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t arity Ana \\<Gamma> M\"\n\n\nsubsubsection \\<open>Small Lemmata\\<close>\nlemma less_Suc_max_var_set:\n  assumes z: \"z \\<in> X\"\n    and X: \"finite X\"\n  shows \"snd z < Suc (max_var_set X)\"\nproof -\n  have \"snd z \\<in> snd ` X\" using z by simp\n  hence \"snd z \\<le> Max (insert 0 (snd ` X))\" using X by simp\n  thus ?thesis using X by simp\nqed\n\nlemma (in typed_model) finite_SMP_representationD:\n  assumes \"finite_SMP_representation arity Ana \\<Gamma> M\"\n  shows \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (set M)\"\n    and \"has_all_wt_instances_of \\<Gamma> (subterms\\<^sub>s\\<^sub>e\\<^sub>t (set M)) (set M)\"\n    and \"has_all_wt_instances_of \\<Gamma> (\\<Union>((set \\<circ> fst \\<circ> Ana) ` set M)) (set M)\"\n    and \"is_TComp_var_instance_closed \\<Gamma> M\"\nusing assms unfolding finite_SMP_representation_def list_all_iff wf\\<^sub>t\\<^sub>r\\<^sub>m_code by blast+\n\nlemma (in typed_model) is_wt_instance_of_condD:\n  assumes t_instance_s: \"is_wt_instance_of_cond \\<Gamma> t s\"\n  obtains \\<delta> where\n    \"\\<Gamma> t = \\<Gamma> s\" \"mgu t s = Some \\<delta>\"\n    \"inj_on \\<delta> (fv t)\" \"\\<delta> ` (fv t) \\<subseteq> range Var\"\nusing t_instance_s unfolding is_wt_instance_of_cond_def Let_def by (cases \"mgu t s\") fastforce+\n\nlemma (in typed_model) is_wt_instance_of_condD':\n  assumes t_wf_trm: \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\n    and s_wf_trm: \"wf\\<^sub>t\\<^sub>r\\<^sub>m s\"\n    and t_instance_s: \"is_wt_instance_of_cond \\<Gamma> t s\"\n  shows \"\\<exists>\\<delta>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> t = s \\<cdot> \\<delta>\"\nproof -\n  obtain \\<delta> where s:\n      \"\\<Gamma> t = \\<Gamma> s\" \"mgu t s = Some \\<delta>\"\n      \"inj_on \\<delta> (fv t)\" \"\\<delta> ` (fv t) \\<subseteq> range Var\"\n    by (metis is_wt_instance_of_condD[OF t_instance_s])\n\n  have 0: \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m s\" using s(1) t_wf_trm s_wf_trm by auto\n\n  note 1 = mgu_wt_if_same_type[OF s(2) 0 s(1)]\n\n  note 2 = conjunct1[OF mgu_gives_MGU[OF s(2)]]\n\n  show ?thesis\n    using s(1) inj_var_ran_unifiable_has_subst_match[OF 2 s(3,4)]\n          wt_subst_compose[OF 1 subst_var_inv_wt[OF 1, of \"fv t\"]]\n          wf_trms_subst_compose[OF mgu_wf_trms[OF s(2) 0] subst_var_inv_wf_trms[of \\<delta> \"fv t\"]]\n    by auto\nqed\n\nlemma (in typed_model) is_wt_instance_of_condD'':\n  assumes s_wf_trm: \"wf\\<^sub>t\\<^sub>r\\<^sub>m s\"\n    and t_instance_s: \"is_wt_instance_of_cond \\<Gamma> t s\"\n    and t_var: \"t = Var x\"\n  shows \"\\<exists>y. s = Var y \\<and> \\<Gamma> (Var y) = \\<Gamma> (Var x)\"\nproof -\n  obtain \\<delta> where \\<delta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" and s: \"Var x = s \\<cdot> \\<delta>\"\n    using is_wt_instance_of_condD'[OF _ s_wf_trm t_instance_s] t_var by auto\n  obtain y where y: \"s = Var y\" using s by (cases s) auto\n  show ?thesis using wt_subst_trm''[OF \\<delta>] s y by metis\nqed\n\nlemma (in typed_model) has_all_wt_instances_ofD:\n  assumes N_instance_M: \"has_all_wt_instances_of \\<Gamma> N M\"\n    and t_in_N: \"t \\<in> N\"\n  obtains s \\<delta> where\n    \"s \\<in> M\" \"\\<Gamma> t = \\<Gamma> s\" \"mgu t s = Some \\<delta>\"\n    \"inj_on \\<delta> (fv t)\" \"\\<delta> ` (fv t) \\<subseteq> range Var\"\nby (metis t_in_N N_instance_M is_wt_instance_of_condD has_all_wt_instances_of_def)\n\nlemma (in typed_model) has_all_wt_instances_ofD':\n  assumes N_wf_trms: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s N\"\n    and M_wf_trms: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s M\"\n    and N_instance_M: \"has_all_wt_instances_of \\<Gamma> N M\"\n    and t_in_N: \"t \\<in> N\"\n  shows \"\\<exists>\\<delta>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> t \\<in> M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>\"\nusing assms is_wt_instance_of_condD' unfolding has_all_wt_instances_of_def by fast\n\nlemma (in typed_model) has_all_wt_instances_ofD'':\n  assumes N_wf_trms: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s N\"\n    and M_wf_trms: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s M\"\n    and N_instance_M: \"has_all_wt_instances_of \\<Gamma> N M\"\n    and t_in_N: \"Var x \\<in> N\"\n  shows \"\\<exists>y. Var y \\<in> M \\<and> \\<Gamma> (Var y) = \\<Gamma> (Var x)\"\nusing assms is_wt_instance_of_condD'' unfolding has_all_wt_instances_of_def by fast\n  \nlemma (in typed_model) has_all_instances_of_if_subset:\n  assumes \"N \\<subseteq> M\"\n  shows \"has_all_wt_instances_of \\<Gamma> N M\"\nusing assms inj_onI mgu_same_empty\nunfolding has_all_wt_instances_of_def is_wt_instance_of_cond_def\nby (smt option.case_eq_if option.discI option.sel subsetD term.discI(1) term.inject(1))\n\nlemma (in typed_model) SMP_I':\n  assumes N_wf_trms: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s N\"\n    and M_wf_trms: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s M\"\n    and N_instance_M: \"has_all_wt_instances_of \\<Gamma> N M\"\n    and t_in_N: \"t \\<in> N\"\n  shows \"t \\<in> SMP M\"\nusing has_all_wt_instances_ofD'[OF N_wf_trms M_wf_trms N_instance_M t_in_N]\n      SMP.Substitution[OF SMP.MP[of _ M]]\nby blast\n\n\nsubsubsection \\<open>Lemma: Proving Type-Flaw Resistance\\<close>\nlocale typed_model' = typed_model arity public Ana \\<Gamma>\n  for arity::\"'fun \\<Rightarrow> nat\"\n    and public::\"'fun \\<Rightarrow> bool\"\n    and Ana::\"('fun,(('fun,'atom::finite) term_type \\<times> nat)) term\n              \\<Rightarrow> (('fun,(('fun,'atom) term_type \\<times> nat)) term list\n                 \\<times> ('fun,(('fun,'atom) term_type \\<times> nat)) term list)\"\n    and \\<Gamma>::\"('fun,(('fun,'atom) term_type \\<times> nat)) term \\<Rightarrow> ('fun,'atom) term_type\"\n  +\n  assumes \\<Gamma>_Var_fst: \"\\<And>\\<tau> n m. \\<Gamma> (Var (\\<tau>,n)) = \\<Gamma> (Var (\\<tau>,m))\"\n    and Ana_const: \"\\<And>c T. arity c = 0 \\<Longrightarrow> Ana (Fun c T) = ([],[])\"\n    and Ana_subst'_or_Ana_keys_subterm:\n      \"(\\<forall>f T \\<delta> K R. Ana (Fun f T) = (K,R) \\<longrightarrow> Ana (Fun f T \\<cdot> \\<delta>) = (K \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta>,R \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta>)) \\<or>\n       (\\<forall>t K R k. Ana t = (K,R) \\<longrightarrow> k \\<in> set K \\<longrightarrow> k \\<sqsubset> t)\"\nbegin\n\nlemma var_rename_inv_comp: \"t \\<cdot> (var_rename n \\<circ>\\<^sub>s var_rename_inv n) = t\"\nproof (induction t)\n  case (Fun f T)\n  hence \"map (\\<lambda>t. t \\<cdot> var_rename n \\<circ>\\<^sub>s var_rename_inv n) T = T\" by (simp add: map_idI) \n  thus ?case by (metis subst_apply_term.simps(2)) \nqed (simp add: var_rename_def var_rename_inv_def)\n\nlemma var_rename_fv_disjoint:\n  \"fv s \\<inter> fv (t \\<cdot> var_rename (max_var s)) = {}\"\nproof -\n  have 1: \"\\<forall>v \\<in> fv s. snd v \\<le> max_var s\" by simp\n  have 2: \"\\<forall>v \\<in> fv (t \\<cdot> var_rename n). snd v > n\" for n unfolding var_rename_def by (induct t) auto\n  show ?thesis using 1 2 by force\nqed\n\nlemma var_rename_fv_set_disjoint:\n  assumes \"finite M\" \"s \\<in> M\"\n  shows \"fv s \\<inter> fv (t \\<cdot> var_rename (max_var_set (fv\\<^sub>s\\<^sub>e\\<^sub>t M))) = {}\"\nproof -\n  have 1: \"\\<forall>v \\<in> fv s. snd v \\<le> max_var_set (fv\\<^sub>s\\<^sub>e\\<^sub>t M)\" using assms\n  proof (induction M rule: finite_induct)\n    case (insert t M) thus ?case\n    proof (cases \"t = s\")\n      case False\n      hence \"\\<forall>v \\<in> fv s. snd v \\<le> max_var_set (fv\\<^sub>s\\<^sub>e\\<^sub>t M)\" using insert by simp\n      moreover have \"max_var_set (fv\\<^sub>s\\<^sub>e\\<^sub>t M) \\<le> max_var_set (fv\\<^sub>s\\<^sub>e\\<^sub>t (insert t M))\"\n        using insert.hyps(1) insert.prems\n        by force\n      ultimately show ?thesis by auto\n    qed simp\n  qed simp\n\n  have 2: \"\\<forall>v \\<in> fv (t \\<cdot> var_rename n). snd v > n\" for n unfolding var_rename_def by (induct t) auto\n\n  show ?thesis using 1 2 by force\nqed\n\nlemma var_rename_fv_set_disjoint':\n  assumes \"finite M\"\n  shows \"fv\\<^sub>s\\<^sub>e\\<^sub>t M \\<inter> fv\\<^sub>s\\<^sub>e\\<^sub>t (N \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t var_rename (max_var_set (fv\\<^sub>s\\<^sub>e\\<^sub>t M))) = {}\"\nusing var_rename_fv_set_disjoint[OF assms] by auto\n\nlemma var_rename_is_renaming[simp]:\n  \"subst_range (var_rename n) \\<subseteq> range Var\"\n  \"subst_range (var_rename_inv n) \\<subseteq> range Var\"\nunfolding var_rename_def var_rename_inv_def by auto\n\nlemma var_rename_wt[simp]:\n  \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t (var_rename n)\"\n  \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t (var_rename_inv n)\"\nby (auto simp add: var_rename_def var_rename_inv_def wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def \\<Gamma>_Var_fst)\n\n\n\nlemma var_rename_wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s_range[simp]:\n  \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range (var_rename n))\"\n  \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range (var_rename_inv n))\"\nusing var_rename_is_renaming by fastforce+\n\nlemma Fun_range_case:\n  \"(\\<forall>f T. Fun f T \\<in> M \\<longrightarrow> P f T) \\<longleftrightarrow> (\\<forall>u \\<in> M. case u of Fun f T \\<Rightarrow> P f T | _ \\<Rightarrow> True)\"\n  \"(\\<forall>f T. Fun f T \\<in> M \\<longrightarrow> P f T) \\<longleftrightarrow> (\\<forall>u \\<in> M. is_Fun u \\<longrightarrow> P (the_Fun u) (args u))\"\nby (auto split: \"term.splits\")\n\nlemma is_TComp_var_instance_closedD:\n  assumes x: \"\\<exists>y \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M). \\<Gamma> (Var x) = \\<Gamma> (Var y)\" \"\\<Gamma> (Var x) = TComp f T\"\n    and closed: \"is_TComp_var_instance_closed \\<Gamma> M\"\n  shows \"\\<exists>g U. Fun g U \\<in> set M \\<and> \\<Gamma> (Fun g U) = \\<Gamma> (Var x) \\<and> (\\<forall>u \\<in> set U. is_Var u) \\<and> distinct U\"\nusing assms unfolding is_TComp_var_instance_closed_def list_all_iff list_ex_iff by fastforce\n\nlemma is_TComp_var_instance_closedD':\n  assumes \"\\<exists>y \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M). \\<Gamma> (Var x) = \\<Gamma> (Var y)\" \"TComp f T \\<sqsubseteq> \\<Gamma> (Var x)\"\n    and closed: \"is_TComp_var_instance_closed \\<Gamma> M\"\n    and wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (set M)\"\n  shows \"\\<exists>g U. Fun g U \\<in> set M \\<and> \\<Gamma> (Fun g U) = TComp f T \\<and> (\\<forall>u \\<in> set U. is_Var u) \\<and> distinct U\"\nusing assms(1,2)\nproof (induction \"\\<Gamma> (Var x)\" arbitrary: x)\n  case (Fun g U)\n  note IH = Fun.hyps(1)\n  have g: \"arity g > 0\" \"public g\" using Fun.hyps(2) fun_type_inv[of \"Var x\"] \\<Gamma>_Var_fst by simp_all\n  then obtain V where V:\n      \"Fun g V \\<in> set M\" \"\\<Gamma> (Fun g V) = \\<Gamma> (Var x)\" \"\\<forall>v \\<in> set V. \\<exists>x. v = Var x\"\n      \"distinct V\" \"length U = length V\"\n    using is_TComp_var_instance_closedD[OF Fun.prems(1) Fun.hyps(2)[symmetric] closed(1)]\n    by (metis Fun.hyps(2) fun_type_id_eq fun_type_length_eq is_VarE)\n  hence U: \"U = map \\<Gamma> V\" using fun_type[OF g(1), of V] Fun.hyps(2) by simp\n  hence 1: \"\\<Gamma> v \\<in> set U\" when v: \"v \\<in> set V\" for v using v by simp\n\n  have 2: \"\\<exists>y \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M). \\<Gamma> (Var z) = \\<Gamma> (Var y)\" when z: \"Var z \\<in> set V\" for z\n    using V(1) fv_subset_subterms Fun_param_in_subterms[OF z] by fastforce\n\n  show ?case\n  proof (cases \"TComp f T = \\<Gamma> (Var x)\")\n    case False\n    then obtain u where u: \"u \\<in> set U\" \"TComp f T \\<sqsubseteq> u\"\n      using Fun.prems(2) Fun.hyps(2) by moura\n    then obtain y where y: \"Var y \\<in> set V\" \"\\<Gamma> (Var y) = u\" using U V(3) \\<Gamma>_Var_fst by auto\n    show ?thesis using IH[OF _ 2[OF y(1)]] u y(2) by metis\n  qed (use V in fastforce)\nqed simp\n\nlemma TComp_var_instance_wt_subst_exists:\n  assumes gT: \"\\<Gamma> (Fun g T) = TComp g (map \\<Gamma> U)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun g T)\"\n    and U: \"\\<forall>u \\<in> set U. \\<exists>y. u = Var y\" \"distinct U\"\n  shows \"\\<exists>\\<theta>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>) \\<and> Fun g T = Fun g U \\<cdot> \\<theta>\"\nproof -\n  define the_i where \"the_i \\<equiv> \\<lambda>y. THE x. x < length U \\<and> U ! x = Var y\"\n  define \\<theta> where \\<theta>: \"\\<theta> \\<equiv> \\<lambda>y. if Var y \\<in> set U then T ! the_i y else Var y\"\n\n  have g: \"arity g > 0\" using gT(1,2) fun_type_inv(1) by blast\n\n  have UT: \"length U = length T\" using fun_type_length_eq gT(1) by fastforce\n\n  have 1: \"the_i y < length U \\<and> U ! the_i y = Var y\" when y: \"Var y \\<in> set U\" for y\n    using theI'[OF distinct_Ex1[OF U(2) y]] unfolding the_i_def by simp\n\n  have 2: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\"\n    using \\<theta> 1 gT(1) fun_type[OF g] UT\n    unfolding wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def\n    by (metis (no_types, lifting) nth_map term.inject(2))\n\n  have \"\\<forall>i<length T. U ! i \\<cdot> \\<theta> = T ! i\"\n    using \\<theta> 1 U(1) UT distinct_Ex1[OF U(2)] in_set_conv_nth\n    by (metis (no_types, lifting) subst_apply_term.simps(1))\n  hence \"T = map (\\<lambda>t. t \\<cdot> \\<theta>) U\" by (simp add: UT nth_equalityI)\n  hence 3: \"Fun g T = Fun g U \\<cdot> \\<theta>\" by simp\n\n  have \"subst_range \\<theta> \\<subseteq> set T\" using \\<theta> 1 U(1) UT by (auto simp add: subst_domain_def)\n  hence 4: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\" using gT(2) wf_trm_param by auto\n\n  show ?thesis by (metis 2 3 4)\nqed\n\nlemma TComp_var_instance_closed_has_Var:\n  assumes closed: \"is_TComp_var_instance_closed \\<Gamma> M\"\n    and wf_M: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (set M)\"\n    and wf_\\<delta>x: \"wf\\<^sub>t\\<^sub>r\\<^sub>m (\\<delta> x)\"\n    and y_ex: \"\\<exists>y \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M). \\<Gamma> (Var x) = \\<Gamma> (Var y)\"\n    and t: \"t \\<sqsubseteq> \\<delta> x\"\n    and \\<delta>_wt: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\"\n  shows \"\\<exists>y \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M). \\<Gamma> (Var y) = \\<Gamma> t\"\nproof (cases \"\\<Gamma> (Var x)\")\n  case (Var a)\n  hence \"t = \\<delta> x\"\n    using t wf_\\<delta>x \\<delta>_wt\n    by (metis (full_types) const_type_inv_wf fun_if_subterm subtermeq_Var_const(2) wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def)\n  thus ?thesis using y_ex wt_subst_trm''[OF \\<delta>_wt, of \"Var x\"] by fastforce\nnext\n  case (Fun f T)\n  hence \\<Gamma>_\\<delta>x: \"\\<Gamma> (\\<delta> x) = TComp f T\" using wt_subst_trm''[OF \\<delta>_wt, of \"Var x\"] by auto\n\n  show ?thesis\n  proof (cases \"t = \\<delta> x\")\n    case False\n    hence t_subt_\\<delta>x: \"t \\<sqsubset> \\<delta> x\" using t(1) \\<Gamma>_\\<delta>x by fastforce\n\n    obtain T' where T': \"\\<delta> x = Fun f T'\" using \\<Gamma>_\\<delta>x t_subt_\\<delta>x fun_type_id_eq by (cases \"\\<delta> x\") auto\n    \n    obtain g S where gS: \"Fun g S \\<sqsubseteq> \\<delta> x\" \"t \\<in> set S\" using Fun_ex_if_subterm[OF t_subt_\\<delta>x] by blast\n  \n    have gS_wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m (Fun g S)\" by (rule wf_trm_subtermeq[OF wf_\\<delta>x gS(1)])\n    hence \"arity g > 0\" using gS(2) by (metis length_pos_if_in_set wf_trm_arity) \n    hence gS_\\<Gamma>: \"\\<Gamma> (Fun g S) = TComp g (map \\<Gamma> S)\" using fun_type by blast\n  \n    obtain h U where hU:\n        \"Fun h U \\<in> set M\" \"\\<Gamma> (Fun h U) = Fun g (map \\<Gamma> S)\" \"\\<forall>u \\<in> set U. is_Var u\"\n      using is_TComp_var_instance_closedD'[OF y_ex _ closed wf_M]\n            subtermeq_imp_subtermtypeeq[OF wf_\\<delta>x] gS \\<Gamma>_\\<delta>x Fun gS_\\<Gamma>\n      by metis\n  \n    obtain y where y: \"Var y \\<in> set U\" \"\\<Gamma> (Var y) = \\<Gamma> t\"\n      using hU(3) fun_type_param_ex[OF hU(2) gS(2)] by fast\n  \n    have \"y \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M)\" using hU(1) y(1) by force\n    thus ?thesis using y(2) closed by metis\n  qed (metis y_ex Fun \\<Gamma>_\\<delta>x)\nqed\n\nlemma TComp_var_instance_closed_has_Fun:\n  assumes closed: \"is_TComp_var_instance_closed \\<Gamma> M\"\n    and wf_M: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (set M)\"\n    and wf_\\<delta>x: \"wf\\<^sub>t\\<^sub>r\\<^sub>m (\\<delta> x)\"\n    and y_ex: \"\\<exists>y \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M). \\<Gamma> (Var x) = \\<Gamma> (Var y)\"\n    and t: \"t \\<sqsubseteq> \\<delta> x\"\n    and \\<delta>_wt: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\"\n    and t_\\<Gamma>: \"\\<Gamma> t = TComp g T\"\n    and t_fun: \"is_Fun t\"\n  shows \"\\<exists>m \\<in> set M. \\<exists>\\<theta>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>) \\<and> t = m \\<cdot> \\<theta> \\<and> is_Fun m\"\nproof -\n  obtain T'' where T'': \"t = Fun g T''\" using t_\\<Gamma> t_fun fun_type_id_eq by blast\n\n  have g: \"arity g > 0\" using t_\\<Gamma> fun_type_inv[of t] by simp_all\n\n  have \"TComp g T \\<sqsubseteq> \\<Gamma> (Var x)\" using \\<delta>_wt t t_\\<Gamma>\n    by (metis wf_\\<delta>x subtermeq_imp_subtermtypeeq wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def) \n  then obtain U where U:\n      \"Fun g U \\<in> set M\" \"\\<Gamma> (Fun g U) = TComp g T\" \"\\<forall>u \\<in> set U. \\<exists>y. u = Var y\"\n      \"distinct U\" \"length T'' = length U\"\n    using is_TComp_var_instance_closedD'[OF y_ex _ closed wf_M]\n    by (metis t_\\<Gamma> T'' fun_type_id_eq fun_type_length_eq is_VarE)\n  hence UT': \"T = map \\<Gamma> U\" using fun_type[OF g, of U] by simp\n\n  show ?thesis\n    using TComp_var_instance_wt_subst_exists UT' T'' U(1,3,4) t t_\\<Gamma> wf_\\<delta>x wf_trm_subtermeq\n    by (metis term.disc(2))\nqed\n\nlemma TComp_var_and_subterm_instance_closed_has_subterms_instances:\n  assumes M_var_inst_cl: \"is_TComp_var_instance_closed \\<Gamma> M\"\n    and M_subterms_cl: \"has_all_wt_instances_of \\<Gamma> (subterms\\<^sub>s\\<^sub>e\\<^sub>t (set M)) (set M)\"\n    and M_wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (set M)\"\n    and t: \"t \\<sqsubseteq>\\<^sub>s\\<^sub>e\\<^sub>t set M\"\n    and s: \"s \\<sqsubseteq> t \\<cdot> \\<delta>\"\n    and \\<delta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\"\n  shows \"\\<exists>m \\<in> set M. \\<exists>\\<theta>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>) \\<and> s = m \\<cdot> \\<theta>\"\nusing subterm_subst_unfold[OF s]\nproof\n  assume \"\\<exists>s'. s' \\<sqsubseteq> t \\<and> s = s' \\<cdot> \\<delta>\"\n  then obtain s' where s': \"s' \\<sqsubseteq> t\" \"s = s' \\<cdot> \\<delta>\" by blast\n  then obtain \\<theta> where \\<theta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\" \"s' \\<in> set M \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\"\n    using t has_all_wt_instances_ofD'[OF wf_trms_subterms[OF M_wf] M_wf M_subterms_cl]\n          term.order_trans[of s' t]\n    by blast\n  then obtain m where m: \"m \\<in> set M\" \"s' = m \\<cdot> \\<theta>\" by blast\n\n  have \"s = m \\<cdot> (\\<theta> \\<circ>\\<^sub>s \\<delta>)\" using s'(2) m(2) by simp\n  thus ?thesis\n    using m(1) wt_subst_compose[OF \\<theta>(1) \\<delta>(1)] wf_trms_subst_compose[OF \\<theta>(2) \\<delta>(2)] by blast\nnext\n  assume \"\\<exists>x \\<in> fv t. s \\<sqsubset> \\<delta> x\"\n  then obtain x where x: \"x \\<in> fv t\" \"s \\<sqsubset> \\<delta> x\" \"s \\<sqsubseteq> \\<delta> x\" by blast\n\n  note 0 = TComp_var_instance_closed_has_Var[OF M_var_inst_cl M_wf]\n  note 1 = has_all_wt_instances_ofD''[OF wf_trms_subterms[OF M_wf] M_wf M_subterms_cl]\n\n  have \\<delta>x_wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m (\\<delta> x)\" and s_wf_trm: \"wf\\<^sub>t\\<^sub>r\\<^sub>m s\"\n    using \\<delta>(2) wf_trm_subterm[OF _ x(2)] by fastforce+\n\n  have x_fv_ex: \"\\<exists>y \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M). \\<Gamma> (Var x) = \\<Gamma> (Var y)\"\n    using x(1) s fv_subset_subterms[OF t] by auto\n\n  obtain y where y: \"y \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M)\" \"\\<Gamma> (Var y) = \\<Gamma> s\"\n    using 0[of \\<delta> x s, OF \\<delta>x_wf x_fv_ex x(3) \\<delta>(1)] by metis\n  then obtain z where z: \"Var z \\<in> set M\" \"\\<Gamma> (Var z) = \\<Gamma> s\"\n    using 1[of y] vars_iff_subtermeq_set[of y \"set M\"] by metis\n\n  define \\<theta> where \"\\<theta> \\<equiv> Var(z := s)::('fun, ('fun, 'atom) term \\<times> nat) subst\"\n\n  have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\" \"s = Var z \\<cdot> \\<theta>\"\n    using z(2) s_wf_trm unfolding \\<theta>_def wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def by force+\n  thus ?thesis using z(1) by blast\nqed\n\ncontext\nbegin\nprivate lemma SMP_D_aux1:\n  assumes \"t \\<in> SMP (set M)\"\n    and closed: \"has_all_wt_instances_of \\<Gamma> (subterms\\<^sub>s\\<^sub>e\\<^sub>t (set M)) (set M)\"\n                \"is_TComp_var_instance_closed \\<Gamma> M\"\n    and wf_M: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (set M)\"\n  shows \"\\<forall>x \\<in> fv t. \\<exists>y \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M). \\<Gamma> (Var y) = \\<Gamma> (Var x)\"\nusing assms(1)\nproof (induction t rule: SMP.induct)\n  case (MP t) show ?case\n  proof\n    fix x assume x: \"x \\<in> fv t\"\n    hence \"Var x \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (set M)\" using MP.hyps vars_iff_subtermeq by fastforce\n    then obtain \\<delta> s where \\<delta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\"\n        and s: \"s \\<in> set M\" \"Var x = s \\<cdot> \\<delta>\"\n      using has_all_wt_instances_ofD'[OF wf_trms_subterms[OF wf_M] wf_M closed(1)] by blast\n    then obtain y where y: \"s = Var y\" by (cases s) auto\n    thus \"\\<exists>y \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M). \\<Gamma> (Var y) = \\<Gamma> (Var x)\"\n      using s wt_subst_trm''[OF \\<delta>(1), of \"Var y\"] by force\n  qed\nnext\n  case (Subterm t t')\n  hence \"fv t' \\<subseteq> fv t\" using subtermeq_vars_subset by auto\n  thus ?case using Subterm.IH by auto\nnext\n  case (Substitution t \\<delta>)\n  note IH = Substitution.IH\n  show ?case\n  proof\n    fix x assume x: \"x \\<in> fv (t \\<cdot> \\<delta>)\"\n    then obtain y where y: \"y \\<in> fv t\" \"\\<Gamma> (Var x) \\<sqsubseteq> \\<Gamma> (Var y)\"\n      using Substitution.hyps(2,3)\n      by (metis subst_apply_img_var subtermeqI' subtermeq_imp_subtermtypeeq\n                vars_iff_subtermeq wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def wf_trm_subst_rangeD)\n    let ?P = \"\\<lambda>x. \\<exists>y \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M). \\<Gamma> (Var y) = \\<Gamma> (Var x)\"\n    show \"?P x\" using y IH\n    proof (induction \"\\<Gamma> (Var y)\" arbitrary: y t)\n      case (Var a)\n      hence \"\\<Gamma> (Var x) = \\<Gamma> (Var y)\" by auto\n      thus ?case using Var(2,4) by auto\n    next\n      case (Fun f T)\n      obtain z where z: \"\\<exists>w \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M). \\<Gamma> (Var z) = \\<Gamma> (Var w)\" \"\\<Gamma> (Var z) = \\<Gamma> (Var y)\"\n        using Fun.prems(1,3) by blast\n      show ?case\n      proof (cases \"\\<Gamma> (Var x) = \\<Gamma> (Var y)\")\n        case True thus ?thesis using Fun.prems by auto\n      next\n        case False\n        then obtain \\<tau> where \\<tau>: \"\\<tau> \\<in> set T\" \"\\<Gamma> (Var x) \\<sqsubseteq> \\<tau>\" using Fun.prems(2) Fun.hyps(2) by auto\n        then obtain U where U:\n            \"Fun f U \\<in> set M\" \"\\<Gamma> (Fun f U) = \\<Gamma> (Var z)\" \"\\<forall>u \\<in> set U. \\<exists>v. u = Var v\" \"distinct U\"\n          using is_TComp_var_instance_closedD'[OF z(1) _ closed(2) wf_M] Fun.hyps(2) z(2)\n          by (metis fun_type_id_eq subtermeqI' is_VarE)\n        hence 1: \"\\<forall>x \\<in> fv (Fun f U). \\<exists>y \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M). \\<Gamma> (Var y) = \\<Gamma> (Var x)\" by force\n\n        have \"arity f > 0\" using U(2) z(2) Fun.hyps(2) fun_type_inv(1) by metis\n        hence \"\\<Gamma> (Fun f U) = TComp f (map \\<Gamma> U)\" using fun_type by auto\n        then obtain u where u: \"Var u \\<in> set U\" \"\\<Gamma> (Var u) = \\<tau>\"\n          using \\<tau>(1) U(2,3) z(2) Fun.hyps(2) by auto\n        show ?thesis\n          using Fun.hyps(1)[of u \"Fun f U\"] u \\<tau> 1\n          by force\n      qed\n    qed\n  qed\nnext\n  case (Ana t K T k)\n  have \"fv k \\<subseteq> fv t\" using Ana_keys_fv[OF Ana.hyps(2)] Ana.hyps(3) by auto\n  thus ?case using Ana.IH by auto\nqed\n\nprivate lemma SMP_D_aux2:\n  fixes t::\"('fun, ('fun, 'atom) term \\<times> nat) term\"\n  assumes t_SMP: \"t \\<in> SMP (set M)\"\n    and t_Var: \"\\<exists>x. t = Var x\"\n    and M_SMP_repr: \"finite_SMP_representation arity Ana \\<Gamma> M\"\n  shows \"\\<exists>m \\<in> set M. \\<exists>\\<delta>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> t = m \\<cdot> \\<delta>\"\nproof -\n  have M_wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (set M)\" \n      and M_var_inst_cl: \"is_TComp_var_instance_closed \\<Gamma> M\"\n      and M_subterms_cl: \"has_all_wt_instances_of \\<Gamma> (subterms\\<^sub>s\\<^sub>e\\<^sub>t (set M)) (set M)\"\n      and M_Ana_cl: \"has_all_wt_instances_of \\<Gamma> (\\<Union>((set \\<circ> fst \\<circ> Ana) ` set M)) (set M)\"\n    using finite_SMP_representationD[OF M_SMP_repr] by blast+\n\n  have M_Ana_wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (\\<Union> ((set \\<circ> fst \\<circ> Ana) ` set M))\"\n  proof\n    fix k assume \"k \\<in> \\<Union>((set \\<circ> fst \\<circ> Ana) ` set M)\"\n    then obtain m where m: \"m \\<in> set M\" \"k \\<in> set (fst (Ana m))\" by force\n    thus \"wf\\<^sub>t\\<^sub>r\\<^sub>m k\" using M_wf Ana_keys_wf'[of m \"fst (Ana m)\" _ k] surjective_pairing by blast\n  qed\n\n  note 0 = has_all_wt_instances_ofD'[OF wf_trms_subterms[OF M_wf] M_wf M_subterms_cl]\n  note 1 = has_all_wt_instances_ofD'[OF M_Ana_wf M_wf M_Ana_cl]\n\n  obtain x y where x: \"t = Var x\" and y: \"y \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M)\" \"\\<Gamma> (Var y) = \\<Gamma> (Var x)\"\n    using t_Var SMP_D_aux1[OF t_SMP M_subterms_cl M_var_inst_cl M_wf] by fastforce\n  then obtain m \\<delta> where m: \"m \\<in> set M\" \"m \\<cdot> \\<delta> = Var y\" and \\<delta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\"\n    using 0[of \"Var y\"] vars_iff_subtermeq_set[of y \"set M\"] by fastforce\n  obtain z where z: \"m = Var z\" using m(2) by (cases m) auto\n\n  define \\<theta> where \"\\<theta> \\<equiv> Var(z := Var x)::('fun, ('fun, 'atom) term \\<times> nat) subst\"\n\n  have \"\\<Gamma> (Var z) = \\<Gamma> (Var x)\" using y(2) m(2) z wt_subst_trm''[OF \\<delta>, of m] by argo\n  hence \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\" unfolding \\<theta>_def wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def by force+\n  moreover have \"t = m \\<cdot> \\<theta>\" using x z unfolding \\<theta>_def by simp\n  ultimately show ?thesis using m(1) by blast\nqed\n\nprivate lemma SMP_D_aux3:\n  assumes hyps: \"t' \\<sqsubseteq> t\" and wf_t: \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" and prems: \"is_Fun t'\"\n    and IH:\n      \"((\\<exists>f. t = Fun f []) \\<and> (\\<exists>m \\<in> set M. \\<exists>\\<delta>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> t = m \\<cdot> \\<delta>)) \\<or>\n       (\\<exists>m \\<in> set M. \\<exists>\\<delta>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> t = m \\<cdot> \\<delta> \\<and> is_Fun m)\"\n    and M_SMP_repr: \"finite_SMP_representation arity Ana \\<Gamma> M\"\n  shows \"((\\<exists>f. t' = Fun f []) \\<and> (\\<exists>m \\<in> set M. \\<exists>\\<delta>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> t' = m \\<cdot> \\<delta>)) \\<or>\n         (\\<exists>m \\<in> set M. \\<exists>\\<delta>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> t' = m \\<cdot> \\<delta> \\<and> is_Fun m)\"\nproof (cases \"\\<exists>f. t = Fun f [] \\<or> t' = Fun f []\")\n  case True\n  have M_wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (set M)\" \n    and M_var_inst_cl: \"is_TComp_var_instance_closed \\<Gamma> M\"\n    and M_subterms_cl: \"has_all_wt_instances_of \\<Gamma> (subterms\\<^sub>s\\<^sub>e\\<^sub>t (set M)) (set M)\"\n    and M_Ana_cl: \"has_all_wt_instances_of \\<Gamma> (\\<Union>((set \\<circ> fst \\<circ> Ana) ` set M)) (set M)\"\n  using finite_SMP_representationD[OF M_SMP_repr] by blast+\n\n  note 0 = has_all_wt_instances_ofD'[OF wf_trms_subterms[OF M_wf] M_wf M_subterms_cl]\n  note 1 = TComp_var_instance_closed_has_Fun[OF M_var_inst_cl M_wf]\n  note 2 = TComp_var_and_subterm_instance_closed_has_subterms_instances[\n            OF M_var_inst_cl M_subterms_cl M_wf]\n\n  have wf_t': \"wf\\<^sub>t\\<^sub>r\\<^sub>m t'\" using hyps wf_t wf_trm_subterm by blast\n\n  obtain c where \"t = Fun c [] \\<or> t' = Fun c []\" using True by moura\n  thus ?thesis\n  proof\n    assume c: \"t' = Fun c []\"\n    show ?thesis\n    proof (cases \"\\<exists>f. t = Fun f []\")\n      case True\n      hence \"t = t'\" using c hyps by force\n      thus ?thesis using IH by fast\n    next\n      case False\n      note F = this\n      then obtain m \\<delta> where m: \"m \\<in> set M\" \"t = m \\<cdot> \\<delta>\"\n          and \\<delta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\"\n        using IH by blast\n\n      show ?thesis using subterm_subst_unfold[OF hyps[unfolded m(2)]]\n      proof\n        assume \"\\<exists>m'. m' \\<sqsubseteq> m \\<and> t' = m' \\<cdot> \\<delta>\"\n        then obtain m' where m': \"m' \\<sqsubseteq> m\" \"t' = m' \\<cdot> \\<delta>\" by moura\n        obtain n \\<theta> where n: \"n \\<in> set M\" \"m' = n \\<cdot> \\<theta>\" and \\<theta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n          using 0[of m'] m(1) m'(1) by blast\n        have \"t' = n \\<cdot> (\\<theta> \\<circ>\\<^sub>s \\<delta>)\" using m'(2) n(2) by auto\n        thus ?thesis\n          using c n(1) wt_subst_compose[OF \\<theta>(1) \\<delta>(1)] wf_trms_subst_compose[OF \\<theta>(2) \\<delta>(2)] by blast\n      next\n        assume \"\\<exists>x \\<in> fv m. t' \\<sqsubset> \\<delta> x\"\n        then obtain x where x: \"x \\<in> fv m\" \"t' \\<sqsubset> \\<delta> x\" \"t' \\<sqsubseteq> \\<delta> x\" by moura\n        have \\<delta>x_wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m (\\<delta> x)\" using \\<delta>(2) by fastforce\n        \n        have x_fv_ex: \"\\<exists>y \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M). \\<Gamma> (Var x) = \\<Gamma> (Var y)\" using x m by auto\n\n        show ?thesis\n        proof (cases \"\\<Gamma> t'\")\n          case (Var a)\n          show ?thesis\n            using c m 2[OF _ hyps[unfolded m(2)] \\<delta>]\n            by fast\n        next\n          case (Fun g S)\n          show ?thesis\n            using c 1[of \\<delta> x t', OF \\<delta>x_wf x_fv_ex x(3) \\<delta>(1) Fun]\n            by blast\n        qed\n      qed\n    qed\n  qed (use IH hyps in simp)\nnext\n  case False\n  note F = False\n  then obtain m \\<delta> where m:\n      \"m \\<in> set M\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"t = m \\<cdot> \\<delta>\" \"is_Fun m\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\"\n    using IH by moura\n  obtain f T where fT: \"t' = Fun f T\" \"arity f > 0\" \"\\<Gamma> t' = TComp f (map \\<Gamma> T)\"\n    using F prems fun_type wf_trm_subtermeq[OF wf_t hyps]\n    by (metis is_FunE length_greater_0_conv subtermeqI' wf\\<^sub>t\\<^sub>r\\<^sub>m_def)\n\n  have closed: \"has_all_wt_instances_of \\<Gamma> (subterms\\<^sub>s\\<^sub>e\\<^sub>t (set M)) (set M)\"\n               \"is_TComp_var_instance_closed \\<Gamma> M\"\n    using M_SMP_repr unfolding finite_SMP_representation_def by metis+\n\n  have M_wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (set M)\" \n    using finite_SMP_representationD[OF M_SMP_repr] by blast\n\n  show ?thesis\n  proof (cases \"\\<exists>x \\<in> fv m. t' \\<sqsubseteq> \\<delta> x\")\n    case True\n    then obtain x where x: \"x \\<in> fv m\" \"t' \\<sqsubseteq> \\<delta> x\" by moura\n    have 1: \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M)\" using m(1) x(1) by auto\n    have 2: \"is_Fun (\\<delta> x)\" using prems x(2) by auto\n    have 3: \"wf\\<^sub>t\\<^sub>r\\<^sub>m (\\<delta> x)\" using m(5) by (simp add: wf_trm_subst_rangeD)\n    have \"\\<not>(\\<exists>f. \\<delta> x = Fun f [])\" using F x(2) by auto\n    hence \"\\<exists>f T. \\<Gamma> (Var x) = TComp f T\" using 2 3 m(2)\n      by (metis (no_types) fun_type is_FunE length_greater_0_conv subtermeqI' wf\\<^sub>t\\<^sub>r\\<^sub>m_def wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def)\n    moreover have \"\\<exists>f T. \\<Gamma> t' = Fun f T\"\n      using False prems wf_trm_subtermeq[OF wf_t hyps]\n      by (metis (no_types) fun_type is_FunE length_greater_0_conv subtermeqI' wf\\<^sub>t\\<^sub>r\\<^sub>m_def)\n    ultimately show ?thesis\n      using TComp_var_instance_closed_has_Fun 1 x(2) m(2) prems closed 3 M_wf\n      by metis\n  next\n    case False\n    then obtain m' where m': \"m' \\<sqsubseteq> m\" \"t' = m' \\<cdot> \\<delta>\" \"is_Fun m'\"\n      using hyps m(3) subterm_subst_not_img_subterm\n      by blast\n    then obtain \\<theta> m'' where \\<theta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\" \"m'' \\<in> set M\" \"m' = m'' \\<cdot> \\<theta>\"\n      using m(1) has_all_wt_instances_ofD'[OF wf_trms_subterms[OF M_wf] M_wf closed(1)] by blast\n    hence t'_m'': \"t' = m'' \\<cdot> \\<theta> \\<circ>\\<^sub>s \\<delta>\" using m'(2) by fastforce\n\n    note \\<theta>\\<delta> = wt_subst_compose[OF \\<theta>(1) m(2)] wf_trms_subst_compose[OF \\<theta>(2) m(5)]\n\n    show ?thesis\n    proof (cases \"is_Fun m''\")\n      case True thus ?thesis using \\<theta>(3,4) m'(2,3) m(4) fT t'_m'' \\<theta>\\<delta> by blast\n    next\n      case False\n      then obtain x where x: \"m'' = Var x\" by moura\n      hence \"\\<exists>y \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M). \\<Gamma> (Var x) = \\<Gamma> (Var y)\" \"t' \\<sqsubseteq> (\\<theta> \\<circ>\\<^sub>s \\<delta>) x\"\n            \"\\<Gamma> (Var x) = Fun f (map \\<Gamma> T)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m ((\\<theta> \\<circ>\\<^sub>s \\<delta>) x)\"\n        using \\<theta>\\<delta> t'_m'' \\<theta>(3) fv_subset[OF \\<theta>(3)] fT(3) subst_apply_term.simps(1)[of x \"\\<theta> \\<circ>\\<^sub>s \\<delta>\"]\n              wt_subst_trm''[OF \\<theta>\\<delta>(1), of \"Var x\"]\n        by (fastforce, blast, argo, fastforce)\n      thus ?thesis\n        using x TComp_var_instance_closed_has_Fun[\n                of M \"\\<theta> \\<circ>\\<^sub>s \\<delta>\" x t' f \"map \\<Gamma> T\", OF closed(2) M_wf _ _ _ \\<theta>\\<delta>(1) fT(3) prems]\n        by blast\n    qed\n  qed\nqed\n\nlemma SMP_D:\n  assumes \"t \\<in> SMP (set M)\" \"is_Fun t\"\n    and M_SMP_repr: \"finite_SMP_representation arity Ana \\<Gamma> M\"\n  shows \"((\\<exists>f. t = Fun f []) \\<and> (\\<exists>m \\<in> set M. \\<exists>\\<delta>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> t = m \\<cdot> \\<delta>)) \\<or>\n         (\\<exists>m \\<in> set M. \\<exists>\\<delta>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> t = m \\<cdot> \\<delta> \\<and> is_Fun m)\"\nproof -\n  have wf_M: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (set M)\"\n      and closed: \"has_all_wt_instances_of \\<Gamma> (subterms\\<^sub>s\\<^sub>e\\<^sub>t (set M)) (set M)\"\n                  \"has_all_wt_instances_of \\<Gamma> (\\<Union>((set \\<circ> fst \\<circ> Ana) ` set M)) (set M)\"\n                  \"is_TComp_var_instance_closed \\<Gamma> M\"\n    using finite_SMP_representationD[OF M_SMP_repr] by blast+\n\n  show ?thesis using assms(1,2)\n  proof (induction t rule: SMP.induct)\n    case (MP t)\n    moreover have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t Var\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range Var)\" \"t = t \\<cdot> Var\" by simp_all\n    ultimately show ?case by blast \n  next\n    case (Subterm t t')\n    hence t_fun: \"is_Fun t\" by auto\n    note * = Subterm.hyps(2) SMP_wf_trm[OF Subterm.hyps(1) wf_M(1)]\n             Subterm.prems Subterm.IH[OF t_fun] M_SMP_repr\n    show ?case by (rule SMP_D_aux3[OF *])\n  next\n    case (Substitution t \\<delta>)\n    have wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" by (metis Substitution.hyps(1) wf_M(1) SMP_wf_trm)\n    hence wf': \"wf\\<^sub>t\\<^sub>r\\<^sub>m (t \\<cdot> \\<delta>)\" using Substitution.hyps(3) wf_trm_subst by blast\n    show ?case\n    proof (cases \"\\<Gamma> t\")\n      case (Var a)\n      hence 1: \"\\<Gamma> (t \\<cdot> \\<delta>) = TAtom a\" using Substitution.hyps(2) by (metis wt_subst_trm'') \n      then obtain c where c: \"t \\<cdot> \\<delta> = Fun c []\"\n        using TAtom_term_cases[OF wf' 1] Substitution.prems by fastforce\n      hence \"(\\<exists>x. t = Var x) \\<or> t = t \\<cdot> \\<delta>\" by (cases t) auto\n      thus ?thesis\n      proof\n        assume t_Var: \"\\<exists>x. t = Var x\"\n        then obtain x where x: \"t = Var x\" \"\\<delta> x = Fun c []\" \"\\<Gamma> (Var x) = TAtom a\"\n          using c 1 wt_subst_trm''[OF Substitution.hyps(2), of t] by force\n        \n        obtain m \\<theta> where m: \"m \\<in> set M\" \"t = m \\<cdot> \\<theta>\" and \\<theta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n          using SMP_D_aux2[OF Substitution.hyps(1) t_Var M_SMP_repr] by moura\n\n        have \"m \\<cdot> (\\<theta> \\<circ>\\<^sub>s \\<delta>) = Fun c []\" using c m(2) by auto\n        thus ?thesis\n          using c m(1) wt_subst_compose[OF \\<theta>(1) Substitution.hyps(2)]\n                wf_trms_subst_compose[OF \\<theta>(2) Substitution.hyps(3)]\n          by metis\n      qed (use c Substitution.IH in auto)\n    next\n      case (Fun f T)\n      hence 1: \"\\<Gamma> (t \\<cdot> \\<delta>) = TComp f T\" using Substitution.hyps(2) by (metis wt_subst_trm'')\n      have 2: \"\\<not>(\\<exists>f. t = Fun f [])\" using Fun TComp_term_cases[OF wf] by auto\n      obtain T'' where T'': \"t \\<cdot> \\<delta> = Fun f T''\"\n        using 1 2 fun_type_id_eq Fun Substitution.prems\n        by fastforce\n      have f: \"arity f > 0\" \"public f\" using fun_type_inv[OF 1] by metis+\n  \n      show ?thesis\n      proof (cases t)\n        case (Fun g U)\n        then obtain m \\<theta> where m:\n            \"m \\<in> set M\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"t = m \\<cdot> \\<theta>\" \"is_Fun m\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n          using Substitution.IH Fun 2 by moura\n        have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t (\\<theta> \\<circ>\\<^sub>s \\<delta>)\" \"t \\<cdot> \\<delta> = m \\<cdot> (\\<theta> \\<circ>\\<^sub>s \\<delta>)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range (\\<theta> \\<circ>\\<^sub>s \\<delta>))\"\n          using wt_subst_compose[OF m(2) Substitution.hyps(2)] m(3)\n                wf_trms_subst_compose[OF m(5) Substitution.hyps(3)]\n          by auto\n        thus ?thesis using m(1,4) by metis\n      next\n        case (Var x)\n        then obtain y where y: \"y \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M)\" \"\\<Gamma> (Var y) = \\<Gamma> (Var x)\"\n          using SMP_D_aux1[OF Substitution.hyps(1) closed(1,3) wf_M] Fun\n          by moura\n        hence 3: \"\\<Gamma> (Var y) = TComp f T\" using Var Fun \\<Gamma>_Var_fst by simp\n        \n        obtain h V where V:\n            \"Fun h V \\<in> set M\" \"\\<Gamma> (Fun h V) = \\<Gamma> (Var y)\" \"\\<forall>u \\<in> set V. \\<exists>z. u = Var z\" \"distinct V\"\n          by (metis is_VarE is_TComp_var_instance_closedD[OF _ 3 closed(3)] y(1))\n        moreover have \"length T'' = length V\" using 3 V(2) fun_type_length_eq 1 T'' by metis\n        ultimately have TV: \"T = map \\<Gamma> V\"\n          by (metis fun_type[OF f(1)] 3 fun_type_id_eq term.inject(2))\n  \n        obtain \\<theta> where \\<theta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\" \"t \\<cdot> \\<delta> = Fun h V \\<cdot> \\<theta>\"\n          using TComp_var_instance_wt_subst_exists 1 3 T'' TV V(2,3,4) wf'\n          by (metis fun_type_id_eq)\n  \n        have 9: \"\\<Gamma> (Fun h V) = \\<Gamma> (\\<delta> x)\" using y(2) Substitution.hyps(2) V(2) 1 3 Var by auto\n  \n        show ?thesis using Var \\<theta> 9 V(1) by force\n      qed\n    qed\n  next\n    case (Ana t K T k)\n    have 1: \"is_Fun t\" using Ana.hyps(2,3) by auto\n    then obtain f U where U: \"t = Fun f U\" by moura\n  \n    have 2: \"fv k \\<subseteq> fv t\" using Ana_keys_fv[OF Ana.hyps(2)] Ana.hyps(3) by auto\n  \n    have wf_t: \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\"\n      using SMP_wf_trm[OF Ana.hyps(1)] wf\\<^sub>t\\<^sub>r\\<^sub>m_code wf_M\n      by auto\n    hence wf_k: \"wf\\<^sub>t\\<^sub>r\\<^sub>m k\"\n      using Ana_keys_wf'[OF Ana.hyps(2)] wf\\<^sub>t\\<^sub>r\\<^sub>m_code Ana.hyps(3)\n      by auto\n  \n    have wf_M_keys: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (\\<Union>((set \\<circ> fst \\<circ> Ana) ` set M))\"\n    proof\n      fix t assume \"t \\<in> (\\<Union>((set \\<circ> fst \\<circ> Ana) ` set M))\"\n      then obtain s where s: \"s \\<in> set M\" \"t \\<in> (set \\<circ> fst \\<circ> Ana) s\" by blast\n      obtain K R where KR: \"Ana s = (K,R)\" by (metis surj_pair)\n      hence \"t \\<in> set K\" using s(2) by simp\n      thus \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" using Ana_keys_wf'[OF KR] wf_M s(1) by blast\n    qed\n  \n    show ?case using Ana_subst'_or_Ana_keys_subterm\n    proof\n      assume \"\\<forall>t K T k. Ana t = (K, T) \\<longrightarrow> k \\<in> set K \\<longrightarrow> k \\<sqsubset> t\"\n      hence *: \"k \\<sqsubseteq> t\" using Ana.hyps(2,3) by auto\n      show ?thesis by (rule SMP_D_aux3[OF * wf_t Ana.prems Ana.IH[OF 1] M_SMP_repr])\n    next\n      assume Ana_subst':\n          \"\\<forall>f T \\<delta> K M. Ana (Fun f T) = (K, M) \\<longrightarrow> Ana (Fun f T \\<cdot> \\<delta>) = (K \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta>, M \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta>)\"\n  \n      have \"arity f > 0\" using Ana_const[of f U] U Ana.hyps(2,3) by fastforce\n      hence \"U \\<noteq> []\" using wf_t U unfolding wf\\<^sub>t\\<^sub>r\\<^sub>m_def by force\n      then obtain m \\<delta> where m: \"m \\<in> set M\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\" \"t = m \\<cdot> \\<delta>\" \"is_Fun m\"\n        using Ana.IH[OF 1] U by auto\n      hence \"Ana (t \\<cdot> \\<delta>) = (K \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta>,T \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta>)\" using Ana_subst' U Ana.hyps(2) by auto\n      obtain Km Tm where Ana_m: \"Ana m = (Km,Tm)\" by moura\n      hence \"Ana (m \\<cdot> \\<delta>) = (Km \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta>,Tm \\<cdot>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<delta>)\"\n        using Ana_subst' U m(4) is_FunE[OF m(5)] Ana.hyps(2)\n        by metis\n      then obtain km where km: \"km \\<in> set Km\" \"k = km \\<cdot> \\<delta>\" using Ana.hyps(2,3) m(4) by auto\n      then obtain \\<theta> km' where \\<theta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n          and km': \"km' \\<in> set M\" \"km = km' \\<cdot> \\<theta>\"\n        using Ana_m m(1) has_all_wt_instances_ofD'[OF wf_M_keys wf_M closed(2), of km] by force\n  \n      have k\\<theta>\\<delta>: \"k = km' \\<cdot> \\<theta> \\<circ>\\<^sub>s \\<delta>\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t (\\<theta> \\<circ>\\<^sub>s \\<delta>)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range (\\<theta> \\<circ>\\<^sub>s \\<delta>))\"\n        using km(2) km' wt_subst_compose[OF \\<theta>(1) m(2)] wf_trms_subst_compose[OF \\<theta>(2) m(3)]\n        by auto\n  \n      show ?case\n      proof (cases \"is_Fun km'\")\n        case True thus ?thesis using k\\<theta>\\<delta> km'(1) by blast\n      next\n        case False\n        note F = False\n        then obtain x where x: \"km' = Var x\" by auto\n        hence 3: \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M)\" using fv_subset[OF km'(1)] by auto\n        obtain kf kT where kf: \"k = Fun kf kT\" using Ana.prems by auto\n        show ?thesis\n        proof (cases \"kT = []\")\n          case True thus ?thesis using k\\<theta>\\<delta>(1) k\\<theta>\\<delta>(2) k\\<theta>\\<delta>(3) kf km'(1) by blast\n        next\n          case False\n          hence 4: \"arity kf > 0\" using wf_k kf TAtom_term_cases const_type by fastforce\n          then obtain kT' where kT': \"\\<Gamma> k = TComp kf kT'\" by (simp add: fun_type kf) \n          then obtain V where V:\n              \"Fun kf V \\<in> set M\" \"\\<Gamma> (Fun kf V) = \\<Gamma> (Var x)\" \"\\<forall>u \\<in> set V. \\<exists>v. u = Var v\"\n              \"distinct V\" \"is_Fun (Fun kf V)\"\n            using is_TComp_var_instance_closedD[OF _ _ closed(3), of x]\n                  x m(2) k\\<theta>\\<delta>(1) 3 wt_subst_trm''[OF k\\<theta>\\<delta>(2)]\n            by (metis fun_type_id_eq term.disc(2) is_VarE)\n          have 5: \"kT' = map \\<Gamma> V\"\n            using fun_type[OF 4] x kT' k\\<theta>\\<delta> m(2) V(2)\n            by (metis term.inject(2) wt_subst_trm'')\n          thus ?thesis\n            using TComp_var_instance_wt_subst_exists wf_k kf 4 V(3,4) kT' V(1,5)\n            by metis\n        qed\n      qed\n    qed\n  qed\nqed\n\nlemma SMP_D':\n  fixes M\n  defines \"\\<delta> \\<equiv> var_rename (max_var_set (fv\\<^sub>s\\<^sub>e\\<^sub>t (set M)))\"\n  assumes M_SMP_repr: \"finite_SMP_representation arity Ana \\<Gamma> M\"\n    and s: \"s \\<in> SMP (set M)\" \"is_Fun s\" \"\\<nexists>f. s = Fun f []\"\n    and t: \"t \\<in> SMP (set M)\" \"is_Fun t\" \"\\<nexists>f. t = Fun f []\"\n  obtains \\<sigma> s0 \\<theta> t0\n  where \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<sigma>)\" \"s0 \\<in> set M\" \"is_Fun s0\" \"s = s0 \\<cdot> \\<sigma>\" \"\\<Gamma> s = \\<Gamma> s0\"\n    and \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\" \"t0 \\<in> set M\" \"is_Fun t0\" \"t = t0 \\<cdot> \\<delta> \\<cdot> \\<theta>\" \"\\<Gamma> t = \\<Gamma> t0\"\nproof -\n  obtain \\<sigma> s0 where\n      s0: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<sigma>)\" \"s0 \\<in> set M\" \"s = s0 \\<cdot> \\<sigma>\" \"is_Fun s0\"\n    using s(3) SMP_D[OF s(1,2) M_SMP_repr] unfolding \\<delta>_def by metis\n\n  obtain \\<theta> t0 where t0:\n      \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\" \"t0 \\<in> set M\" \"t = t0 \\<cdot> \\<delta> \\<cdot> \\<theta>\" \"is_Fun t0\"\n    using t(3) SMP_D[OF t(1,2) M_SMP_repr] var_rename_wt'[of _ t]\n          wf_trms_subst_compose_Var_range(1)[OF _ var_rename_is_renaming(2)]\n    unfolding \\<delta>_def by metis\n\n  have \"\\<Gamma> s = \\<Gamma> s0\" \"\\<Gamma> t = \\<Gamma> (t0 \\<cdot> \\<delta>)\" \"\\<Gamma> (t0 \\<cdot> \\<delta>) = \\<Gamma> t0\"\n    using s0 t0 wt_subst_trm'' by (metis, metis, metis \\<delta>_def var_rename_wt(1))\n  thus ?thesis using s0 t0 that by simp\nqed\n\nlemma SMP_D'':\n  fixes t::\"('fun, ('fun, 'atom) term \\<times> nat) term\"\n  assumes t_SMP: \"t \\<in> SMP (set M)\"\n    and M_SMP_repr: \"finite_SMP_representation arity Ana \\<Gamma> M\"\n  shows \"\\<exists>m \\<in> set M. \\<exists>\\<delta>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> t = m \\<cdot> \\<delta>\"\nproof (cases \"(\\<exists>x. t = Var x) \\<or> (\\<exists>c. t = Fun c [])\")\n  case True\n  have M_wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (set M)\" \n      and M_var_inst_cl: \"is_TComp_var_instance_closed \\<Gamma> M\"\n      and M_subterms_cl: \"has_all_wt_instances_of \\<Gamma> (subterms\\<^sub>s\\<^sub>e\\<^sub>t (set M)) (set M)\"\n      and M_Ana_cl: \"has_all_wt_instances_of \\<Gamma> (\\<Union>((set \\<circ> fst \\<circ> Ana) ` set M)) (set M)\"\n    using finite_SMP_representationD[OF M_SMP_repr] by blast+\n\n  have M_Ana_wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (\\<Union> ((set \\<circ> fst \\<circ> Ana) ` set M))\"\n  proof\n    fix k assume \"k \\<in> \\<Union>((set \\<circ> fst \\<circ> Ana) ` set M)\"\n    then obtain m where m: \"m \\<in> set M\" \"k \\<in> set (fst (Ana m))\" by force\n    thus \"wf\\<^sub>t\\<^sub>r\\<^sub>m k\" using M_wf Ana_keys_wf'[of m \"fst (Ana m)\" _ k] surjective_pairing by blast\n  qed\n\n  show ?thesis using True\n  proof\n    assume \"\\<exists>x. t = Var x\"\n    then obtain x y where x: \"t = Var x\" and y: \"y \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (set M)\" \"\\<Gamma> (Var y) = \\<Gamma> (Var x)\"\n      using SMP_D_aux1[OF t_SMP M_subterms_cl M_var_inst_cl M_wf] by fastforce\n    then obtain m \\<delta> where m: \"m \\<in> set M\" \"m \\<cdot> \\<delta> = Var y\" and \\<delta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\"\n      using has_all_wt_instances_ofD'[OF wf_trms_subterms[OF M_wf] M_wf M_subterms_cl, of \"Var y\"]\n            vars_iff_subtermeq_set[of y \"set M\"]\n      by fastforce\n\n    obtain z where z: \"m = Var z\" using m(2) by (cases m) auto\n\n    define \\<theta> where \"\\<theta> \\<equiv> Var(z := Var x)::('fun, ('fun, 'atom) term \\<times> nat) subst\"\n\n    have \"\\<Gamma> (Var z) = \\<Gamma> (Var x)\" using y(2) m(2) z wt_subst_trm''[OF \\<delta>, of m] by argo\n    hence \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\" unfolding \\<theta>_def wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t_def by force+\n    moreover have \"t = m \\<cdot> \\<theta>\" using x z unfolding \\<theta>_def by simp\n    ultimately show ?thesis using m(1) by blast\n  qed (use SMP_D[OF t_SMP _ M_SMP_repr] in blast)\nqed (use SMP_D[OF t_SMP _ M_SMP_repr] in blast)\nend\n\nlemma tfr\\<^sub>s\\<^sub>e\\<^sub>t_if_comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t:\n  assumes \"comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t arity Ana \\<Gamma> M\"\n  shows \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (set M)\"\nproof -\n  let ?\\<delta> = \"var_rename (max_var_set (fv\\<^sub>s\\<^sub>e\\<^sub>t (set M)))\"\n  have M_SMP_repr: \"finite_SMP_representation arity Ana \\<Gamma> M\"\n    by (metis comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t_def assms)\n\n  have M_finite: \"finite (set M)\"\n    using assms card_gt_0_iff unfolding comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t_def by blast\n\n  show ?thesis\n  proof (unfold tfr\\<^sub>s\\<^sub>e\\<^sub>t_def; intro ballI impI)\n    fix s t assume \"s \\<in> SMP (set M) - Var`\\<V>\" \"t \\<in> SMP (set M) - Var`\\<V>\"\n    hence st: \"s \\<in> SMP (set M)\" \"is_Fun s\" \"t \\<in> SMP (set M)\" \"is_Fun t\" by auto\n    have \"\\<not>(\\<exists>\\<delta>. Unifier \\<delta> s t)\" when st_type_neq: \"\\<Gamma> s \\<noteq> \\<Gamma> t\"\n    proof (cases \"\\<exists>f. s = Fun f [] \\<or> t = Fun f []\")\n      case False\n      then obtain \\<sigma> s0 \\<theta> t0 where\n            s0: \"s0 \\<in> set M\" \"is_Fun s0\" \"s = s0 \\<cdot> \\<sigma>\" \"\\<Gamma> s = \\<Gamma> s0\"\n        and t0: \"t0 \\<in> set M\" \"is_Fun t0\" \"t = t0 \\<cdot> ?\\<delta> \\<cdot> \\<theta>\" \"\\<Gamma> t = \\<Gamma> t0\"\n        using SMP_D'[OF M_SMP_repr st(1,2) _ st(3,4)] by metis\n      hence \"\\<not>(\\<exists>\\<delta>. Unifier \\<delta> s0 (t0 \\<cdot> ?\\<delta>))\"\n        using assms mgu_None_is_subst_neq st_type_neq wt_subst_trm''[OF var_rename_wt(1)]\n        unfolding comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t_def Let_def by metis\n      thus ?thesis\n        using vars_term_disjoint_imp_unifier[OF var_rename_fv_set_disjoint[OF M_finite]] s0(1) t0(1)\n        unfolding s0(3) t0(3) by (metis (no_types, opaque_lifting) subst_subst_compose)\n    qed (use st_type_neq st(2,4) in auto)\n    thus \"\\<Gamma> s = \\<Gamma> t\" when \"\\<exists>\\<delta>. Unifier \\<delta> s t\" by (metis that)\n  qed\nqed\n\nlemma tfr\\<^sub>s\\<^sub>e\\<^sub>t_if_comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t':\n  assumes \"let N = SMP0 Ana \\<Gamma> M in set M \\<subseteq> set N \\<and> comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t arity Ana \\<Gamma> N\"\n  shows \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (set M)\"\nby (rule tfr_subset(2)[\n          OF tfr\\<^sub>s\\<^sub>e\\<^sub>t_if_comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t[OF conjunct2[OF assms[unfolded Let_def]]]\n             conjunct1[OF assms[unfolded Let_def]]])\n\nlemma tfr\\<^sub>s\\<^sub>t\\<^sub>p_is_comp_tfr\\<^sub>s\\<^sub>t\\<^sub>p: \"tfr\\<^sub>s\\<^sub>t\\<^sub>p a = comp_tfr\\<^sub>s\\<^sub>t\\<^sub>p \\<Gamma> a\"\nproof (cases a)\n  case (Equality ac t t')\n  thus ?thesis\n    using mgu_always_unifies[of t _ t'] mgu_gives_MGU[of t t']\n    by auto\nnext\n  case (Inequality X F)\n  thus ?thesis\n    using tfr\\<^sub>s\\<^sub>t\\<^sub>p.simps(2)[of X F]\n          comp_tfr\\<^sub>s\\<^sub>t\\<^sub>p.simps(2)[of \\<Gamma> X F]\n          Fun_range_case(2)[of \"subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F)\"] \n    unfolding is_Var_def\n    by auto\nqed auto\n\nlemma tfr\\<^sub>s\\<^sub>t_if_comp_tfr\\<^sub>s\\<^sub>t:\n  assumes \"comp_tfr\\<^sub>s\\<^sub>t arity Ana \\<Gamma> M S\"\n  shows \"tfr\\<^sub>s\\<^sub>t S\"\nunfolding tfr\\<^sub>s\\<^sub>t_def\nproof\n  have comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t_M: \"comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t arity Ana \\<Gamma> M\"\n    using assms unfolding comp_tfr\\<^sub>s\\<^sub>t_def by blast\n  \n  have wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s_M: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (set M)\"\n      and wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s_S: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>t S)\"\n      and S_trms_instance_M: \"has_all_wt_instances_of \\<Gamma> (trms\\<^sub>s\\<^sub>t S) (set M)\"\n    using assms wf\\<^sub>t\\<^sub>r\\<^sub>m_code trms_list\\<^sub>s\\<^sub>t_is_trms\\<^sub>s\\<^sub>t\n    unfolding comp_tfr\\<^sub>s\\<^sub>t_def comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t_def finite_SMP_representation_def list_all_iff\n    by blast+\n\n  show \"tfr\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>t S)\"\n    using tfr_subset(3)[OF tfr\\<^sub>s\\<^sub>e\\<^sub>t_if_comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t[OF comp_tfr\\<^sub>s\\<^sub>e\\<^sub>t_M] SMP_SMP_subset]\n          SMP_I'[OF wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s_S wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s_M S_trms_instance_M]\n    by blast\n\n  have \"list_all (comp_tfr\\<^sub>s\\<^sub>t\\<^sub>p \\<Gamma>) S\" by (metis assms comp_tfr\\<^sub>s\\<^sub>t_def)\n  thus \"list_all tfr\\<^sub>s\\<^sub>t\\<^sub>p S\" by (induct S) (simp_all add: tfr\\<^sub>s\\<^sub>t\\<^sub>p_is_comp_tfr\\<^sub>s\\<^sub>t\\<^sub>p)\nqed\n\nlemma tfr\\<^sub>s\\<^sub>t_if_comp_tfr\\<^sub>s\\<^sub>t':\n  assumes \"comp_tfr\\<^sub>s\\<^sub>t arity Ana \\<Gamma> (SMP0 Ana \\<Gamma> (trms_list\\<^sub>s\\<^sub>t S)) S\"\n  shows \"tfr\\<^sub>s\\<^sub>t S\"\nby (rule tfr\\<^sub>s\\<^sub>t_if_comp_tfr\\<^sub>s\\<^sub>t[OF assms])\n\n\n\nsubsubsection \\<open>Lemmata for Checking Ground SMP (GSMP) Disjointness\\<close>\ncontext\nbegin\nprivate lemma ground_SMP_disjointI_aux1:\n  fixes M::\"('fun, ('fun, 'atom) term \\<times> nat) term set\"\n  assumes f_def: \"f \\<equiv> \\<lambda>M. {t \\<cdot> \\<delta> | t \\<delta>. t \\<in> M \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> fv (t \\<cdot> \\<delta>) = {}}\"\n    and g_def: \"g \\<equiv> \\<lambda>M. {t \\<in> M. fv t = {}}\"\n  shows \"f (SMP M) = g (SMP M)\"\nproof\n  have \"t \\<in> f (SMP M)\" when t: \"t \\<in> SMP M\" \"fv t = {}\" for t\n  proof -\n    define \\<delta> where \"\\<delta> \\<equiv> Var::('fun, ('fun, 'atom) term \\<times> nat) subst\"\n    have \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\" \"t = t \\<cdot> \\<delta>\"\n      using subst_apply_term_empty[of t] that(2) wt_subst_Var wf_trm_subst_range_Var\n      unfolding \\<delta>_def by auto\n    thus ?thesis using SMP.Substitution[OF t(1), of \\<delta>] t(2) unfolding f_def by fastforce\n  qed\n  thus \"g (SMP M) \\<subseteq> f (SMP M)\" unfolding g_def by blast\nqed (use f_def g_def in blast)\n\nprivate lemma ground_SMP_disjointI_aux2:\n  fixes M::\"('fun, ('fun, 'atom) term \\<times> nat) term list\"\n  assumes f_def: \"f \\<equiv> \\<lambda>M. {t \\<cdot> \\<delta> | t \\<delta>. t \\<in> M \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> fv (t \\<cdot> \\<delta>) = {}}\"\n    and M_SMP_repr: \"finite_SMP_representation arity Ana \\<Gamma> M\"\n  shows \"f (set M) = f (SMP (set M))\"\nproof\n  have M_wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (set M)\" \n      and M_var_inst_cl: \"is_TComp_var_instance_closed \\<Gamma> M\"\n      and M_subterms_cl: \"has_all_wt_instances_of \\<Gamma> (subterms\\<^sub>s\\<^sub>e\\<^sub>t (set M)) (set M)\"\n      and M_Ana_cl: \"has_all_wt_instances_of \\<Gamma> (\\<Union>((set \\<circ> fst \\<circ> Ana) ` set M)) (set M)\"\n    using finite_SMP_representationD[OF M_SMP_repr] by blast+\n\n  show \"f (SMP (set M)) \\<subseteq> f (set M)\"\n  proof\n    fix t assume \"t \\<in> f (SMP (set M))\"\n    then obtain s \\<delta> where s: \"t = s \\<cdot> \\<delta>\" \"s \\<in> SMP (set M)\" \"fv (s \\<cdot> \\<delta>) = {}\"\n        and \\<delta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>)\"\n      unfolding f_def by blast\n\n    have t_wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m t\" using SMP_wf_trm[OF s(2) M_wf] s(1) wf_trm_subst[OF \\<delta>(2)] by blast \n\n    obtain m \\<theta> where m: \"m \\<in> set M\" \"s = m \\<cdot> \\<theta>\" and \\<theta>: \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n      using SMP_D''[OF s(2) M_SMP_repr] by blast\n\n    have \"t = m \\<cdot> (\\<theta> \\<circ>\\<^sub>s \\<delta>)\" \"fv (m \\<cdot> (\\<theta> \\<circ>\\<^sub>s \\<delta>)) = {}\" using s(1,3) m(2) by simp_all\n    thus \"t \\<in> f (set M)\"\n      using m(1) wt_subst_compose[OF \\<theta>(1) \\<delta>(1)] wf_trms_subst_compose[OF \\<theta>(2) \\<delta>(2)]\n      unfolding f_def by blast\n  qed\nqed (auto simp add: f_def)\n\nprivate lemma ground_SMP_disjointI_aux3:\n  fixes A B C::\"('fun, ('fun, 'atom) term \\<times> nat) term set\"\n  defines \"P \\<equiv> \\<lambda>t s. \\<exists>\\<delta>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> Unifier \\<delta> t s\"\n  assumes f_def: \"f \\<equiv> \\<lambda>M. {t \\<cdot> \\<delta> | t \\<delta>. t \\<in> M \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> fv (t \\<cdot> \\<delta>) = {}}\"\n    and Q_def: \"Q \\<equiv> \\<lambda>t. intruder_synth' public arity {} t\"\n    and R_def: \"R \\<equiv> \\<lambda>t. \\<exists>u \\<in> C. is_wt_instance_of_cond \\<Gamma> t u\"\n    and AB: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s A\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s B\" \"fv\\<^sub>s\\<^sub>e\\<^sub>t A \\<inter> fv\\<^sub>s\\<^sub>e\\<^sub>t B = {}\"\n    and C: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s C\"\n    and ABC: \"\\<forall>t \\<in> A. \\<forall>s \\<in> B. P t s \\<longrightarrow> (Q t \\<and> Q s) \\<or> (R t \\<and> R s)\"\n  shows \"f A \\<inter> f B \\<subseteq> f C \\<union> {m. {} \\<turnstile>\\<^sub>c m}\"\nproof\n  fix t assume \"t \\<in> f A \\<inter> f B\"\n  then obtain ta tb \\<delta>a \\<delta>b where\n          ta: \"t = ta \\<cdot> \\<delta>a\" \"ta \\<in> A\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>a\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>a)\" \"fv (ta \\<cdot> \\<delta>a) = {}\"\n      and tb: \"t = tb \\<cdot> \\<delta>b\" \"tb \\<in> B\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta>b\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>b)\" \"fv (tb \\<cdot> \\<delta>b) = {}\"\n    unfolding f_def by blast\n\n  have ta_tb_wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m ta\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m tb\" \"fv ta \\<inter> fv tb = {}\" \"\\<Gamma> ta = \\<Gamma> tb\"\n    using ta(1,2) tb(1,2) AB fv_subset_subterms\n          wt_subst_trm''[OF ta(3), of ta] wt_subst_trm''[OF tb(3), of tb]\n    by (fast, fast, blast, simp)\n\n  obtain \\<theta> where \\<theta>: \"Unifier \\<theta> ta tb\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<theta>\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<theta>)\"\n    using vars_term_disjoint_imp_unifier[OF ta_tb_wf(3), of \\<delta>a \\<delta>b]\n          ta(1) tb(1) wt_Unifier_if_Unifier[OF ta_tb_wf(1,2,4)]\n    by blast\n  hence \"(Q ta \\<and> Q tb) \\<or> (R ta \\<and> R tb)\" using ABC ta(2) tb(2) unfolding P_def by blast+\n  thus \"t \\<in> f C \\<union> {m. {} \\<turnstile>\\<^sub>c m}\"\n  proof\n    show \"Q ta \\<and> Q tb \\<Longrightarrow> ?thesis\"\n      using ta(1) pgwt_ground[of ta] pgwt_is_empty_synth[of ta] subst_ground_ident[of ta \\<delta>a]\n      unfolding Q_def f_def intruder_synth_code[symmetric] by simp\n  next\n    assume \"R ta \\<and> R tb\"\n    then obtain ua \\<sigma>a where ua: \"ta = ua \\<cdot> \\<sigma>a\" \"ua \\<in> C\" \"wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<sigma>a\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<sigma>a)\"\n      using \\<theta> ABC ta_tb_wf(1,2) ta(2) tb(2) C is_wt_instance_of_condD'\n      unfolding P_def R_def by metis\n  \n    have \"t = ua \\<cdot> (\\<sigma>a \\<circ>\\<^sub>s \\<delta>a)\" \"fv t = {}\"\n      using ua(1) ta(1,5) tb(1,5) by auto\n    thus ?thesis\n      using ua(2) wt_subst_compose[OF ua(3) ta(3)] wf_trms_subst_compose[OF ua(4) ta(4)]\n      unfolding f_def by blast\n  qed\nqed\n\nlemma ground_SMP_disjointI:\n  fixes A B::\"('fun, ('fun, 'atom) term \\<times> nat) term list\" and C\n  defines \"f \\<equiv> \\<lambda>M. {t \\<cdot> \\<delta> | t \\<delta>. t \\<in> M \\<and> wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> fv (t \\<cdot> \\<delta>) = {}}\"\n    and \"g \\<equiv> \\<lambda>M. {t \\<in> M. fv t = {}}\"\n    and \"Q \\<equiv> \\<lambda>t. intruder_synth' public arity {} t\"\n    and \"R \\<equiv> \\<lambda>t. \\<exists>u \\<in> C. is_wt_instance_of_cond \\<Gamma> t u\"\n  assumes AB_fv_disj: \"fv\\<^sub>s\\<^sub>e\\<^sub>t (set A) \\<inter> fv\\<^sub>s\\<^sub>e\\<^sub>t (set B) = {}\"\n    and A_SMP_repr: \"finite_SMP_representation arity Ana \\<Gamma> A\"\n    and B_SMP_repr: \"finite_SMP_representation arity Ana \\<Gamma> B\"\n    and C_wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s C\"\n    and ABC: \"\\<forall>t \\<in> set A. \\<forall>s \\<in> set B. \\<Gamma> t = \\<Gamma> s \\<and> mgu t s \\<noteq> None \\<longrightarrow> (Q t \\<and> Q s) \\<or> (R t \\<and> R s)\"\n  shows \"g (SMP (set A)) \\<inter> g (SMP (set B)) \\<subseteq> f C \\<union> {m. {} \\<turnstile>\\<^sub>c m}\"\nproof -\n  have AB_wf: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (set A)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (set B)\"\n    using A_SMP_repr B_SMP_repr\n    unfolding finite_SMP_representation_def wf\\<^sub>t\\<^sub>r\\<^sub>m_code list_all_iff\n    by blast+\n\n  let ?P = \"\\<lambda>t s. \\<exists>\\<delta>. wt\\<^sub>s\\<^sub>u\\<^sub>b\\<^sub>s\\<^sub>t \\<delta> \\<and> wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (subst_range \\<delta>) \\<and> Unifier \\<delta> t s\"\n  have ABC': \"\\<forall>t \\<in> set A. \\<forall>s \\<in> set B. ?P t s \\<longrightarrow> (Q t \\<and> Q s) \\<or> (R t \\<and> R s)\"\n    by (metis (no_types) ABC mgu_None_is_subst_neq wt_subst_trm'')\n\n  show ?thesis\n    using ground_SMP_disjointI_aux1[OF f_def g_def, of \"set A\"]\n          ground_SMP_disjointI_aux1[OF f_def g_def, of \"set B\"]\n          ground_SMP_disjointI_aux2[OF f_def A_SMP_repr]\n          ground_SMP_disjointI_aux2[OF f_def B_SMP_repr]\n          ground_SMP_disjointI_aux3[OF f_def Q_def R_def AB_wf AB_fv_disj C_wf ABC']\n    by argo\nqed\n\nend\n\nend\n\nend\n", "meta": {"author": "logicalhacking", "repo": "Stateful_Protocol_Composition_and_Typing", "sha": "34755583e50bc8a2e3eb0f91350c0b8510422a16", "save_path": "github-repos/isabelle/logicalhacking-Stateful_Protocol_Composition_and_Typing", "path": "github-repos/isabelle/logicalhacking-Stateful_Protocol_Composition_and_Typing/Stateful_Protocol_Composition_and_Typing-34755583e50bc8a2e3eb0f91350c0b8510422a16/Stateful_Protocol_Composition_and_Typing/Typed_Model.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.542863297964157, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.25660251101133164}}
{"text": "chapter \\<open>Forward Analysis on DBMs\\<close>\n\ntheory DBM_Operations\n  imports DBM_Basics\nbegin\n\nsection \\<open>Auxiliary\\<close>\n\nlemmas [trans] = finite_subset\n\nlemma finite_vimageI2: \"finite (h -` F)\" if \"finite F\" \"inj_on h {x. h x \\<in> F}\"\nproof -\n  have \"h -` F = h -` F \\<inter> {x. h x \\<in> F}\"\n    by auto\n  from that show ?thesis\n    by(subst \\<open>h -` F = _\\<close>) (rule finite_vimage_IntI[of F h \"{x. h x \\<in> F}\"])\nqed\n\nlemma gt_swap:\n  fixes a b c :: \"'t :: time\"\n  assumes \"c < a + b\"\n  shows \"c < b + a\"\nby (simp add: add.commute assms)\n\nlemma le_swap:\n  fixes a b c :: \"'t :: time\"\n  assumes \"c \\<le> a + b\"\n  shows \"c \\<le> b + a\"\nby (simp add: add.commute assms)\n\nabbreviation clock_numbering :: \"('c \\<Rightarrow> nat) \\<Rightarrow> bool\"\nwhere\n  \"clock_numbering v \\<equiv> \\<forall> c. v c > 0\"\n\nlemma DBM_triv:\n  \"u \\<turnstile>\\<^bsub>v,n\\<^esub> \\<lambda>i j. \\<infinity>\"\n  unfolding DBM_val_bounded_def by (auto simp: dbm_le_def)\n\nsection \\<open>Time Lapse\\<close>\n\ndefinition\n  up :: \"('t::linordered_cancel_ab_semigroup_add) DBM \\<Rightarrow> 't DBM\"\nwhere\n  \"up M \\<equiv>\n    \\<lambda> i j. if i > 0 then if j = 0 then \\<infinity> else min (dbm_add (M i 0) (M 0 j)) (M i j) else M i j\"\n\nlemma dbm_entry_dbm_lt:\n  assumes \"dbm_entry_val u (Some c1) (Some c2) a\" \"a \\<prec> b\"\n  shows \"dbm_entry_val u (Some c1) (Some c2) b\"\nusing assms\nproof (cases, auto, goal_cases)\n  case 1 thus ?case by (cases, auto)\nnext\n  case 2 thus ?case by (cases, auto)\nqed\n\nlemma dbm_entry_dbm_min2:\n  assumes \"dbm_entry_val u None (Some c) (min a b)\"\n  shows \"dbm_entry_val u None (Some c) b\"\nusing dbm_entry_val_mono_2[folded less_eq, OF assms] by auto\n\nlemma dbm_entry_dbm_min3:\n  assumes \"dbm_entry_val u (Some c) None (min a b)\"\n  shows \"dbm_entry_val u (Some c) None b\"\nusing dbm_entry_val_mono_3[folded less_eq, OF assms] by auto\n\nlemma dbm_entry_dbm_min:\n  assumes \"dbm_entry_val u (Some c1) (Some c2) (min a b)\"\n  shows \"dbm_entry_val u (Some c1) (Some c2) b\"\nusing dbm_entry_val_mono_1[folded less_eq, OF assms] by auto\n\nlemma dbm_entry_dbm_min3':\n  assumes \"dbm_entry_val u (Some c) None (min a b)\"\n  shows \"dbm_entry_val u (Some c) None a\"\nusing dbm_entry_val_mono_3[folded less_eq, OF assms] by auto\n\nlemma dbm_entry_dbm_min2':\n  assumes \"dbm_entry_val u None (Some c) (min a b)\"\n  shows \"dbm_entry_val u None (Some c) a\"\nusing dbm_entry_val_mono_2[folded less_eq, OF assms] by auto\n\nlemma dbm_entry_dbm_min':\n  assumes \"dbm_entry_val u (Some c1) (Some c2) (min a b)\"\n  shows \"dbm_entry_val u (Some c1) (Some c2) a\"\nusing dbm_entry_val_mono_1[folded less_eq, OF assms] by auto\n\nlemma DBM_up_complete': \"clock_numbering v \\<Longrightarrow> u \\<in> ([M]\\<^bsub>v,n\\<^esub>)\\<^sup>\\<up> \\<Longrightarrow> u \\<in> [up M]\\<^bsub>v,n\\<^esub>\"\nunfolding up_def DBM_zone_repr_def DBM_val_bounded_def zone_delay_def\nproof (safe, goal_cases)\n  case prems: (2 u d c)\n  hence *: \"dbm_entry_val u None (Some c) (M 0 (v c))\" by auto\n  thus ?case\n  proof (cases, goal_cases)\n    case (1 d')\n    have \"- (u c + d) \\<le> - u c\" using \\<open>d \\<ge> 0\\<close> by simp\n    with 1(2) have \"- (u c + d)\\<le> d'\" by (blast intro: order.trans)\n    thus ?case unfolding cval_add_def using 1 by fastforce\n  next\n    case (2 d')\n    have \"- (u c + d) \\<le> - u c\" using \\<open>d \\<ge> 0\\<close> by simp\n    with 2(2) have \"- (u c + d) < d'\" by (blast intro: order_le_less_trans)\n    thus ?case unfolding cval_add_def using 2 by fastforce\n  qed auto\nnext\n  case prems: (4 u d c1 c2)\n  then have\n    \"dbm_entry_val u (Some c1) None (M (v c1) 0)\" \"dbm_entry_val u None (Some c2) (M 0 (v c2))\"\n  by auto\n  from dbm_entry_val_add_4[OF this] prems have\n    \"dbm_entry_val u (Some c1) (Some c2) (min (dbm_add (M (v c1) 0) (M 0 (v c2))) (M (v c1) (v c2)))\"\n  by (auto split: split_min)\n  with prems(1) show ?case\n  by (cases \"min (dbm_add (M (v c1) 0) (M 0 (v c2))) (M (v c1) (v c2))\", auto simp: cval_add_def)\nqed auto\n\nfun theLe :: \"('t::time) DBMEntry \\<Rightarrow> 't\" where\n  \"theLe (Le d) = d\" |\n  \"theLe (Lt d) = d\" |\n  \"theLe \\<infinity> = 0\"\n\nlemma DBM_up_sound':\n  assumes \"clock_numbering' v n\" \"u \\<in> [up M]\\<^bsub>v,n\\<^esub>\"\n  shows \"u \\<in> ([M]\\<^bsub>v,n\\<^esub>)\\<^sup>\\<up>\"\nunfolding DBM_zone_repr_def zone_delay_def using assms\nproof (clarsimp, goal_cases)\n  case A: 1\n  obtain S_Max_Le where S_Max_Le:\n    \"S_Max_Le = {d - u c | c d. 0 < v c \\<and> v c \\<le> n \\<and> M (v c) 0 = Le d}\"\n  by auto\n  obtain S_Max_Lt where S_Max_Lt:\n    \"S_Max_Lt = {d - u c | c d. 0 < v c \\<and> v c \\<le> n \\<and> M (v c) 0 = Lt d}\"\n  by auto\n  obtain S_Min_Le where S_Min_Le:\n    \"S_Min_Le = {- d - u c| c d. 0 < v c \\<and> v c \\<le> n \\<and> M 0 (v c) = Le d}\"\n  by auto\n  obtain S_Min_Lt where S_Min_Lt:\n    \"S_Min_Lt = {- d - u c | c d. 0 < v c \\<and> v c \\<le> n \\<and> M 0 (v c) = Lt d}\"\n  by auto\n  have \"finite {c. 0 < v c \\<and> v c \\<le> n}\" (is \"finite ?S\")\n  proof -\n    have \"?S \\<subseteq> v -` {1..n}\"\n      by auto\n    also have \"finite \\<dots>\"\n      using assms(1) by (auto intro!: finite_vimageI2 inj_onI)\n    finally show ?thesis .\n  qed\n  then have \"\\<forall> f. finite {(c,b) | c b. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = b}\" by auto\n  moreover have\n    \"\\<forall> f K. {(c,K d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\n    \\<subseteq> {(c,b) | c b. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = b}\"\n  by auto\n  ultimately have 1:\n    \"\\<forall> f K. finite {(c,K d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\" using finite_subset\n  by fast\n  have \"\\<forall> f K. theLe o K = id \\<longrightarrow> finite {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\"\n  proof (safe, goal_cases)\n    case prems: (1 f K)\n    then have\n      \"{(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\n      = (\\<lambda> (c,b). (c, theLe b)) ` {(c,K d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\"\n    proof (auto simp add: pointfree_idE, goal_cases)\n      case (1 a b)\n      then have \"(a, K b) \\<in> {(c, K d) |c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\" by auto\n      moreover from 1(1) have \"theLe (K b) = b\" by (simp add: pointfree_idE)\n      ultimately show ?case by force\n    qed\n    moreover from 1 have\n      \"finite ((\\<lambda> (c,b). (c, theLe b)) ` {(c,K d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d})\"\n    by auto\n    ultimately show ?case by auto\n  qed\n  then have finI:\n    \"\\<And> f g K. theLe o K = id \\<Longrightarrow> finite (g ` {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d})\"\n  by auto\n\n  have\n    \"finite ((\\<lambda>(c,d). - d - u c) ` {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> M 0 (v c) = Le d})\"\n  by (rule finI, auto)\n  moreover have\n    \"S_Min_Le = ((\\<lambda>(c,d). - d - u c) ` {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> M 0 (v c) = Le d})\"\n  using S_Min_Le by auto\n  ultimately have fin_min_le: \"finite S_Min_Le\" by auto\n\n  have\n    \"finite ((\\<lambda>(c,d). - d - u c) ` {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> M 0 (v c) = Lt d})\"\n  by (rule finI, auto)\n  moreover have\n    \"S_Min_Lt = ((\\<lambda>(c,d). - d - u c) ` {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> M 0 (v c) = Lt d})\"\n  using S_Min_Lt by auto\n  ultimately have fin_min_lt: \"finite S_Min_Lt\" by auto\n\n  have \"finite ((\\<lambda>(c,d). d - u c) ` {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> M (v c) 0 = Le d})\"\n  by (rule finI, auto)\n  moreover have\n    \"S_Max_Le = ((\\<lambda>(c,d). d - u c) ` {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> M (v c) 0 = Le d})\"\n  using S_Max_Le by auto\n  ultimately have fin_max_le: \"finite S_Max_Le\" by auto\n\n  have\n    \"finite ((\\<lambda>(c,d). d - u c) ` {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> M (v c) 0 = Lt d})\"\n  by (rule finI, auto)\n  moreover have\n    \"S_Max_Lt = ((\\<lambda>(c,d). d - u c) ` {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> M (v c) 0 = Lt d})\"\n  using S_Max_Lt by auto\n  ultimately have fin_max_lt: \"finite S_Max_Lt\" by auto\n\n  { fix x assume \"x \\<in> S_Min_Le\"\n    hence \"x \\<le> 0\" unfolding S_Min_Le\n    proof (safe, goal_cases)\n      case (1 c d)\n      with A(1) have \"- u c \\<le> d\" unfolding DBM_zone_repr_def DBM_val_bounded_def up_def by auto\n      thus ?case by (simp add: minus_le_iff)\n    qed\n  } note Min_Le_le_0 = this\n  have Min_Lt_le_0: \"x < 0\" if \"x \\<in> S_Min_Lt\" for x using that unfolding S_Min_Lt\n  proof (safe, goal_cases)\n    case (1 c d)\n    with A(1) have \"- u c < d\" unfolding DBM_zone_repr_def DBM_val_bounded_def up_def by auto\n    thus ?case by (simp add: minus_less_iff)\n  qed\n  text \\<open>\n    The following basically all use the same proof.\n    Only the first is not completely identical but nearly identical.\n\\<close>\n  { fix l r assume \"l \\<in> S_Min_Le\" \"r \\<in> S_Max_Le\"\n    with S_Min_Le S_Max_Le have \"l \\<le> r\"\n    proof (safe, goal_cases)\n    case (1 c c' d d')\n      note G1 = this\n      hence *:\"(up M) (v c') (v c) = min (dbm_add (M (v c') 0) (M 0 (v c))) (M (v c') (v c))\"\n      using A unfolding up_def by (auto split: split_min)\n      have \"dbm_entry_val u (Some c') (Some c) ((up M) (v c') (v c))\"\n      using A G1 unfolding DBM_zone_repr_def DBM_val_bounded_def by fastforce\n      hence \"dbm_entry_val u (Some c') (Some c) (dbm_add (M (v c') 0) (M 0 (v c)))\"\n      using dbm_entry_dbm_min' * by auto\n      hence \"u c' - u c \\<le> d' + d\" using G1 by auto\n      hence \"u c' + (- u c - d) \\<le> d'\" by (simp add: add_diff_eq diff_le_eq)\n      hence \"- u c - d \\<le> d' - u c'\" by (simp add: add.commute le_diff_eq)\n      thus ?case by (metis add_uminus_conv_diff uminus_add_conv_diff)\n    qed\n  } note EE = this\n  { fix l r assume \"l \\<in> S_Min_Le\" \"r \\<in> S_Max_Le\"\n    with S_Min_Le S_Max_Le have \"l \\<le> r\"\n    proof (auto, goal_cases)\n    case (1 c c' d d')\n      note G1 = this\n      hence *:\"(up M) (v c') (v c) = min (dbm_add (M (v c') 0) (M 0 (v c))) (M (v c') (v c))\"\n      using A unfolding up_def by (auto split: split_min)\n      have \"dbm_entry_val u (Some c') (Some c) ((up M) (v c') (v c))\"\n      using A G1 unfolding DBM_zone_repr_def DBM_val_bounded_def by fastforce\n      hence \"dbm_entry_val u (Some c') (Some c) (dbm_add (M (v c') 0) (M 0 (v c)))\"\n      using dbm_entry_dbm_min' * by auto\n      hence \"u c' - u c \\<le> d' + d\" using G1 by auto\n      hence \"u c' + (- u c - d) \\<le> d'\" by (simp add: add_diff_eq diff_le_eq)\n      hence \"- u c - d \\<le> d' - u c'\" by (simp add: add.commute le_diff_eq)\n      thus ?case by (metis add_uminus_conv_diff uminus_add_conv_diff)\n    qed\n  } note EE = this\n  { fix l r assume \"l \\<in> S_Min_Lt\" \"r \\<in> S_Max_Le\"\n    with S_Min_Lt S_Max_Le have \"l < r\"\n    proof (auto, goal_cases)\n    case (1 c c' d d')\n      note G1 = this\n      hence *:\"(up M) (v c') (v c) = min (dbm_add (M (v c') 0) (M 0 (v c))) (M (v c') (v c))\"\n      using A unfolding up_def by (auto split: split_min)\n      have \"dbm_entry_val u (Some c') (Some c) ((up M) (v c') (v c))\"\n      using A G1 unfolding DBM_zone_repr_def DBM_val_bounded_def by fastforce\n      hence \"dbm_entry_val u (Some c') (Some c) (dbm_add (M (v c') 0) (M 0 (v c)))\"\n      using dbm_entry_dbm_min' * by auto\n      hence \"u c' - u c < d' + d\" using G1 by auto\n      hence \"u c' + (- u c - d) < d'\" by (simp add: add_diff_eq diff_less_eq)\n      hence \"- u c - d < d' - u c'\" by (simp add: add.commute less_diff_eq)\n      thus ?case by (metis add_uminus_conv_diff uminus_add_conv_diff)\n    qed\n  } note LE = this\n  { fix l r assume \"l \\<in> S_Min_Le\" \"r \\<in> S_Max_Lt\"\n    with S_Min_Le S_Max_Lt have \"l < r\"\n    proof (auto, goal_cases)\n    case (1 c c' d d')\n      note G1 = this\n      hence *:\"(up M) (v c') (v c) = min (dbm_add (M (v c') 0) (M 0 (v c))) (M (v c') (v c))\"\n      using A unfolding up_def by (auto split: split_min)\n      have \"dbm_entry_val u (Some c') (Some c) ((up M) (v c') (v c))\"\n      using A G1 unfolding DBM_zone_repr_def DBM_val_bounded_def by fastforce\n      hence \"dbm_entry_val u (Some c') (Some c) (dbm_add (M (v c') 0) (M 0 (v c)))\"\n      using dbm_entry_dbm_min' * by auto\n      hence \"u c' - u c < d' + d\" using G1 by auto\n      hence \"u c' + (- u c - d) < d'\" by (simp add: add_diff_eq diff_less_eq)\n      hence \"- u c - d < d' - u c'\" by (simp add: add.commute less_diff_eq)\n      thus ?case by (metis add_uminus_conv_diff uminus_add_conv_diff)\n    qed\n  } note EL = this\n  { fix l r assume \"l \\<in> S_Min_Lt\" \"r \\<in> S_Max_Lt\"\n    with S_Min_Lt S_Max_Lt have \"l < r\"\n    proof (auto, goal_cases)\n    case (1 c c' d d')\n      note G1 = this\n      hence *:\"(up M) (v c') (v c) = min (dbm_add (M (v c') 0) (M 0 (v c))) (M (v c') (v c))\"\n      using A unfolding up_def by (auto split: split_min)\n      have \"dbm_entry_val u (Some c') (Some c) ((up M) (v c') (v c))\"\n      using A G1 unfolding DBM_zone_repr_def DBM_val_bounded_def by fastforce\n      hence \"dbm_entry_val u (Some c') (Some c) (dbm_add (M (v c') 0) (M 0 (v c)))\"\n      using dbm_entry_dbm_min' * by auto\n      hence \"u c' - u c < d' + d\" using G1 by auto\n      hence \"u c' + (- u c - d) < d'\" by (simp add: add_diff_eq diff_less_eq)\n      hence \"- u c - d < d' - u c'\" by (simp add: add.commute less_diff_eq)\n      thus ?case by (metis add_uminus_conv_diff uminus_add_conv_diff)\n    qed\n  } note LL = this\n  obtain m where m: \"\\<forall> t \\<in> S_Min_Le. m \\<ge> t\" \"\\<forall> t \\<in> S_Min_Lt. m > t\"\n                    \"\\<forall> t \\<in> S_Max_Le. m \\<le> t\" \"\\<forall> t \\<in> S_Max_Lt. m < t\" \"m \\<le> 0\"\n  proof -\n    assume m:\"(\\<And>m. \\<forall>t\\<in>S_Min_Le. t \\<le> m \\<Longrightarrow>\n          \\<forall>t\\<in>S_Min_Lt. t < m \\<Longrightarrow> \\<forall>t\\<in>S_Max_Le. m \\<le> t \\<Longrightarrow> \\<forall>t\\<in>S_Max_Lt. m < t \\<Longrightarrow> m \\<le> 0 \\<Longrightarrow> thesis)\"\n    let ?min_le = \"Max S_Min_Le\"\n    let ?min_lt = \"Max S_Min_Lt\"\n    let ?max_le = \"Min S_Max_Le\"\n    let ?max_lt = \"Min S_Max_Lt\"\n    show thesis\n    proof (cases \"S_Min_Le = {} \\<and> S_Min_Lt = {}\")\n      case True\n      note T = this\n      show thesis\n      proof (cases \"S_Max_Le = {} \\<and> S_Max_Lt = {}\")\n        case True\n        let ?d' = \"0 :: 't :: time\"\n        show thesis using True T by (intro m[of ?d']) auto\n      next\n        case False\n        let ?d =\n          \"if S_Max_Le \\<noteq> {}\n           then if S_Max_Lt \\<noteq> {} then min ?max_lt ?max_le else ?max_le\n           else ?max_lt\"\n        obtain a :: \"'b\" where a: \"a < 0\" using non_trivial_neg by auto\n        let ?d' = \"min 0 (?d + a)\"\n        { fix x assume \"x \\<in> S_Max_Le\"\n          with fin_max_le a have \"min 0 (Min S_Max_Le + a) \\<le> x\"\n          by (metis Min_le add_le_same_cancel1 le_less_trans less_imp_le min.cobounded2 not_less)\n          then have \"min 0 (Min S_Max_Le + a) \\<le> x\" by auto\n        } note 1 = this\n        { fix x assume x: \"x \\<in> S_Max_Lt\"\n          have \"min 0 (min (Min S_Max_Lt) (Min S_Max_Le) + a) < ?max_lt\"\n          by (meson a add_less_same_cancel1 min.cobounded1 min.strict_coboundedI2 order.strict_trans2)\n          also from fin_max_lt x have \"\\<dots> \\<le> x\" by auto\n          finally have \"min 0 (min (Min S_Max_Lt) (Min S_Max_Le) + a) < x\" .\n        } note 2 = this\n        { fix x assume x: \"x \\<in> S_Max_Le\"\n          have \"min 0 (min (Min S_Max_Lt) (Min S_Max_Le) + a) \\<le> ?max_le\"\n          by (metis le_add_same_cancel1 linear not_le a min_le_iff_disj)\n          also from fin_max_le x have \"\\<dots> \\<le> x\" by auto\n          finally have \"min 0 (min (Min S_Max_Lt) (Min S_Max_Le) + a) \\<le> x\" .\n        } note 3 = this\n        show thesis using False T a 1 2 3\n        proof ((intro m[of ?d']), auto, goal_cases)\n          case 1 then show ?case\n          by (metis Min.coboundedI add_less_same_cancel1 dual_order.strict_trans2 fin_max_lt\n                    min.boundedE not_le)\n        qed\n      qed\n    next\n      case False\n      note F = this\n      show thesis\n      proof (cases \"S_Max_Le = {} \\<and> S_Max_Lt = {}\")\n        case True\n        let ?d' = \"0 :: 't :: time\"\n        show thesis using True Min_Le_le_0 Min_Lt_le_0 by (intro m[of ?d']) auto\n      next\n        case False\n        let ?r =\n          \"if S_Max_Le \\<noteq> {}\n           then if S_Max_Lt \\<noteq> {} then min ?max_lt ?max_le else ?max_le\n           else ?max_lt\"\n        let ?l =\n          \"if S_Min_Le \\<noteq> {}\n           then if S_Min_Lt \\<noteq> {} then max ?min_lt ?min_le else ?min_le\n           else ?min_lt\"\n\n        have 1: \"x \\<le> max ?min_lt ?min_le\" \"x \\<le> ?min_le\" if \"x \\<in> S_Min_Le\" for x\n        using that fin_min_le by (simp add: max.coboundedI2)+\n\n        {\n          fix x y assume x: \"x \\<in> S_Max_Le\" \"y \\<in> S_Min_Lt\"\n          then have \"S_Min_Lt \\<noteq> {}\" by auto\n          from LE[OF Max_in[OF fin_min_lt], OF this, OF x(1)] have \"?min_lt \\<le> x\" by auto\n        } note 3 = this\n\n        have 4: \"?min_le \\<le> x\" if \"x \\<in> S_Max_Le\" \"y \\<in> S_Min_Le\" for x y\n        using EE[OF Max_in[OF fin_min_le], OF _ that(1)] that by auto\n\n        {\n          fix x y assume x: \"x \\<in> S_Max_Lt\" \"y \\<in> S_Min_Lt\"\n          then have \"S_Min_Lt \\<noteq> {}\" by auto\n          from LL[OF Max_in[OF fin_min_lt], OF this, OF x(1)] have \"?min_lt < x\" by auto\n        } note 5 = this\n        {\n          fix x y assume x: \"x \\<in> S_Max_Lt\" \"y \\<in> S_Min_Le\"\n          then have \"S_Min_Le \\<noteq> {}\" by auto\n          from EL[OF Max_in[OF fin_min_le], OF this, OF x(1)] have \"?min_le < x\" by auto\n        } note 6 = this\n        {\n          fix x y assume x: \"y \\<in> S_Min_Le\"\n          then have \"S_Min_Le \\<noteq> {}\" by auto\n          from Min_Le_le_0[OF Max_in[OF fin_min_le], OF this] have \"?min_le \\<le> 0\" by auto\n        } note 7 = this\n        {\n          fix x y assume x: \"y \\<in> S_Min_Lt\"\n          then have \"S_Min_Lt \\<noteq> {}\" by auto\n          from Min_Lt_le_0[OF Max_in[OF fin_min_lt], OF this] have \"?min_lt < 0\" \"?min_lt \\<le> 0\" by auto\n        } note 8 = this\n        show thesis\n        proof (cases \"?l < ?r\")\n          case False\n          then have *: \"S_Max_Le \\<noteq> {}\"\n          proof (auto, goal_cases)\n            case 1\n            with \\<open>\\<not> (S_Max_Le = {} \\<and> S_Max_Lt = {})\\<close> obtain y where y:\"y \\<in> S_Max_Lt\" by auto\n            note 1 = 1 this\n            { fix x y assume A: \"x \\<in> S_Min_Le\" \"y \\<in> S_Max_Lt\"\n                  with EL[OF Max_in[OF fin_min_le] Min_in[OF fin_max_lt]]\n                  have \"Max S_Min_Le < Min S_Max_Lt\" by auto\n            } note ** = this\n            { fix x y assume A: \"x \\<in> S_Min_Lt\" \"y \\<in> S_Max_Lt\"\n                with LL[OF Max_in[OF fin_min_lt] Min_in[OF fin_max_lt]]\n                have \"Max S_Min_Lt < Min S_Max_Lt\" by auto\n            } note *** = this\n            show ?case\n            proof (cases \"S_Min_Le \\<noteq> {}\")\n              case True\n              note T = this\n              show ?thesis\n              proof (cases \"S_Min_Lt \\<noteq> {}\")\n                case True\n                then show False using 1 T True ** *** by auto\n              next\n                case False with 1 T ** show False by auto\n              qed\n            next\n              case False\n              with 1 False *** \\<open>\\<not> (S_Min_Le = {} \\<and> S_Min_Lt = {})\\<close> show ?thesis by auto\n            qed\n          qed\n          { fix x y assume A: \"x \\<in> S_Min_Lt\" \"y \\<in> S_Max_Lt\"\n                with LL[OF Max_in[OF fin_min_lt] Min_in[OF fin_max_lt]]\n                have \"Max S_Min_Lt < Min S_Max_Lt\" by auto\n            } note *** = this\n          { fix x y assume A: \"x \\<in> S_Min_Lt\" \"y \\<in> S_Max_Le\"\n                  with LE[OF Max_in[OF fin_min_lt] Min_in[OF fin_max_le]]\n                  have \"Max S_Min_Lt < Min S_Max_Le\" by auto\n          } note **** = this\n          from F False have **: \"S_Min_Le \\<noteq> {}\"\n          proof (auto, goal_cases)\n            case 1\n            show ?case\n            proof (cases \"S_Max_Le \\<noteq> {}\")\n              case True\n              note T = this\n              show ?thesis\n              proof (cases \"S_Max_Lt \\<noteq> {}\")\n                case True\n                then show False using 1 T True **** *** by auto\n              next\n                case False with 1 T **** show False by auto\n              qed\n            next\n              case False\n              with 1 False *** \\<open>\\<not> (S_Max_Le = {} \\<and> S_Max_Lt = {})\\<close> show ?thesis by auto\n            qed\n          qed\n          {\n            fix x assume x: \"x \\<in> S_Min_Lt\"\n            then have \"x \\<le> ?min_lt\" using fin_min_lt by (simp add: max.coboundedI2)\n            also have \"?min_lt < ?min_le\"\n            proof (rule ccontr, goal_cases)\n              case 1\n              with x ** have 1: \"?l = ?min_lt\" by (auto simp: max.absorb1)\n              have 2: \"?min_lt < ?max_le\" using * ****[OF x] by auto\n              show False\n              proof (cases \"S_Max_Lt = {}\")\n                case False\n                then have \"?min_lt < ?max_lt\" using * ***[OF x] by auto\n                with 1 2 have \"?l < ?r\" by auto\n                with \\<open>\\<not> ?l < ?r\\<close> show False by auto\n              next\n                case True\n                with 1 2 have \"?l < ?r\" by auto\n                with \\<open>\\<not> ?l < ?r\\<close> show False by auto\n              qed\n            qed\n            finally have \"x < max ?min_lt ?min_le\" by (simp add: max.strict_coboundedI2)\n          } note 2 = this\n          show thesis using F False 1 2 3 4 5 6 7 8 * ** by ((intro m[of ?l]), auto)\n        next\n          case True\n          then obtain d where d: \"?l < d\" \"d < ?r\" using dense by auto\n          let ?d' = \"min 0 d\"\n          {\n            fix t assume \"t \\<in> S_Min_Le\"\n            then have \"t \\<le> ?l\" using 1 by auto\n            with d have \"t \\<le> d\" by auto\n          }\n          moreover {\n            fix t assume t: \"t \\<in> S_Min_Lt\"\n            then have \"t \\<le> max ?min_lt ?min_le\" using fin_min_lt by (simp add: max.coboundedI1)\n            with t Min_Lt_le_0 have \"t \\<le> ?l\" using fin_min_lt by auto\n            with d have \"t < d\" by auto\n          }\n          moreover {\n            fix t assume t: \"t \\<in> S_Max_Le\"\n            then have \"min ?max_lt ?max_le \\<le> t\" using fin_max_le by (simp add: min.coboundedI2)\n            then have \"?r \\<le> t\" using fin_max_le t by auto\n            with d have \"d \\<le> t\" by auto\n            then have \"min 0 d \\<le> t\" by (simp add: min.coboundedI2)\n          }\n          moreover {\n            fix t assume t: \"t \\<in> S_Max_Lt\"\n            then have \"min ?max_lt ?max_le \\<le> t\" using fin_max_lt by (simp add: min.coboundedI1)\n            then have \"?r \\<le> t\" using fin_max_lt t by auto\n            with d have \"d < t\" by auto\n            then have \"min 0 d < t\" by (simp add: min.strict_coboundedI2)\n          }\n          ultimately show thesis using Min_Le_le_0 Min_Lt_le_0 by ((intro m[of ?d']), auto)\n        qed\n      qed\n    qed\n  qed\n  obtain u' where \"u' = (u \\<oplus> m)\" by blast\n  hence u': \"u = (u' \\<oplus> (-m))\" unfolding cval_add_def by force\n  have \"DBM_val_bounded v u' M n\" unfolding DBM_val_bounded_def\n  proof (auto, goal_cases)\n    case 1 with A(1,2) show ?case unfolding DBM_zone_repr_def DBM_val_bounded_def up_def by auto\n  next\n    case (3 c)\n    thus ?case\n    proof (cases \"M (v c) 0\", goal_cases)\n      case (1 x1)\n      hence \"m \\<le> x1 - u c\" using m(3) S_Max_Le A(2) by blast\n      hence \"u c + m \\<le> x1\" by (simp add: add.commute le_diff_eq)\n      thus ?case using u' 1(2) unfolding cval_add_def by auto\n    next\n      case (2 x2)\n      hence \"m < x2 - u c\" using m(4) S_Max_Lt A(2) by blast\n      hence \"u c + m < x2\" by (metis add_less_cancel_left diff_add_cancel gt_swap)\n      thus ?case using u' 2(2) unfolding cval_add_def by auto\n    next\n      case 3 thus ?case by auto\n    qed\n  next\n    case (2 c) thus ?case\n    proof (cases \"M 0 (v c)\", goal_cases)\n      case (1 x1)\n      hence \"- x1 - u c \\<le> m\" using m(1) S_Min_Le A(2) by blast\n      hence \"- u c - m \\<le> x1\" using diff_le_eq neg_le_iff_le by fastforce\n      thus ?case using u' 1(2) unfolding cval_add_def by auto\n    next\n      case (2 x2)\n      hence \"- x2  - u c < m\" using m(2) S_Min_Lt A(2) by blast\n      hence \"- u c - m < x2\" using diff_less_eq neg_less_iff_less by fastforce\n      thus ?case using u' 2(2) unfolding cval_add_def by auto\n    next\n      case 3 thus ?case by auto\n    qed\n  next\n    case (4 c1 c2)\n    from A(2) have \"v c1 > 0\" \"v c2 \\<noteq> 0\" by auto\n    then have B: \"(up M) (v c1) (v c2) = min (dbm_add (M (v c1) 0) (M 0 (v c2))) (M (v c1) (v c2))\"\n    unfolding up_def by simp\n\n    show ?case\n    proof (cases \"(dbm_add (M (v c1) 0) (M 0 (v c2))) < (M (v c1) (v c2))\")\n      case False\n      with B have \"(up M) (v c1) (v c2) = M (v c1) (v c2)\" by (auto split: split_min)\n      with A(1) 4 have\n        \"dbm_entry_val u (Some c1) (Some c2) (M (v c1) (v c2))\"\n      unfolding DBM_zone_repr_def unfolding DBM_val_bounded_def by fastforce\n      thus ?thesis using u' by cases (auto simp add: cval_add_def)\n    next\n      case True\n      with B have \"(up M) (v c1) (v c2) = dbm_add (M (v c1) 0) (M 0 (v c2))\" by (auto split: split_min)\n      with A(1) 4 have\n        \"dbm_entry_val u (Some c1) (Some c2) (dbm_add (M (v c1) 0) (M 0 (v c2)))\"\n      unfolding DBM_zone_repr_def unfolding DBM_val_bounded_def by fastforce\n      with True dbm_entry_dbm_lt have\n        \"dbm_entry_val u (Some c1) (Some c2) (M (v c1) (v c2))\"\n      unfolding less by fast\n      thus ?thesis using u' by cases (auto simp add: cval_add_def)\n    qed\n  qed\n  with m(5) u' show ?case by fastforce\nqed\n\n\nsection \\<open>Zone Intersection\\<close>\n\nfun And :: \"('t :: {linordered_cancel_ab_monoid_add}) DBM \\<Rightarrow> 't DBM \\<Rightarrow> 't DBM\" where\n  \"And M1 M2 = (\\<lambda> i j. min (M1 i j) (M2 i j))\"\n\nlemma DBM_and_complete:\n  assumes \"DBM_val_bounded v u M1 n\" \"DBM_val_bounded v u M2 n\"\n  shows \"DBM_val_bounded v u (And M1 M2) n\"\n  using assms unfolding DBM_val_bounded_def by (auto simp: min_def)\n\nlemma DBM_and_sound1:\n  assumes \"DBM_val_bounded v u (And M1 M2) n\"\n  shows \"DBM_val_bounded v u M1 n\"\n  using assms unfolding DBM_val_bounded_def\n  apply safe\n     apply (simp add: less_eq[symmetric]; fail)\n    apply (auto 4 3 intro: dbm_entry_val_mono[folded less_eq])\n  done\n\nlemma DBM_and_sound2:\n  assumes \"DBM_val_bounded v u (And M1 M2) n\"\n  shows \"DBM_val_bounded v u M2 n\"\n  using assms unfolding DBM_val_bounded_def\n  apply safe\n     apply (simp add: less_eq[symmetric]; fail)\n    apply (auto 4 3 intro: dbm_entry_val_mono[folded less_eq])\n  done\n\nlemma And_correct:\n  \"[M1]\\<^bsub>v,n\\<^esub> \\<inter> [M2]\\<^bsub>v,n\\<^esub> = [And M1 M2]\\<^bsub>v,n\\<^esub>\"\n  using DBM_and_sound1 DBM_and_sound2 DBM_and_complete unfolding DBM_zone_repr_def by blast\n\n\nsection \\<open>Clock Reset\\<close>\n\ndefinition\n  DBM_reset :: \"('t :: time) DBM \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> 't \\<Rightarrow> 't DBM \\<Rightarrow> bool\"\nwhere\n  \"DBM_reset M n k d M' \\<equiv>\n    (\\<forall> j \\<le> n. 0 < j \\<and> k \\<noteq> j\\<longrightarrow> M' k j =  \\<infinity> \\<and> M' j k =  \\<infinity>) \\<and> M' k 0 = Le d \\<and> M' 0 k = Le (- d)\n    \\<and> M' k k = M k k\n    \\<and> (\\<forall>i \\<le> n. \\<forall>j \\<le> n.\n        i \\<noteq> k \\<and> j \\<noteq> k \\<longrightarrow> M' i j = min (dbm_add (M i k) (M k j)) (M i j))\"\n\n\nlemma DBM_reset_mono:\n  assumes \"DBM_reset M n k d M'\" \"i \\<le> n\" \"j \\<le> n\" \"i \\<noteq> k\" \"j \\<noteq> k\"\n  shows \"M' i j \\<le> M i j\"\nusing assms unfolding DBM_reset_def by auto\n\nlemma DBM_reset_len_mono:\n  assumes \"DBM_reset M n k d M'\" \"k \\<notin> set xs\" \"i \\<noteq> k\" \"j \\<noteq> k\" \"set (i # j # xs) \\<subseteq> {0..n}\"\n  shows \"len M' i j xs \\<le> len M i j xs\"\nusing assms by (induction xs arbitrary: i) (auto intro: add_mono DBM_reset_mono)\n\nlemma DBM_reset_neg_cycle_preservation:\n  assumes \"DBM_reset M n k d M'\" \"len M i i xs < Le 0\" \"set (k # i # xs) \\<subseteq> {0..n}\"\n  shows \"\\<exists> j. \\<exists> ys. set (j # ys) \\<subseteq> {0..n} \\<and> len M' j j ys < Le 0\"\nproof (cases \"xs = []\")\n  case Nil: True\n  show ?thesis\n  proof (cases \"k = i\")\n    case True\n    with Nil assms have \"len M' i i [] < Le 0\" unfolding DBM_reset_def by auto\n    moreover from assms have \"set (i # []) \\<subseteq> {0..n}\" by auto\n    ultimately show ?thesis by blast\n  next\n    case False\n    with Nil assms DBM_reset_mono have \"len M' i i [] < Le 0\" by fastforce\n    moreover from assms have \"set (i # []) \\<subseteq> {0..n}\" by auto\n    ultimately show ?thesis by blast\n  qed\nnext\n  case False\n  with assms obtain j ys where cycle:\n    \"len M j j ys < Le 0\" \"distinct (j # ys)\" \"j \\<in> set (i # xs)\" \"set ys \\<subseteq> set xs\"\n  by (metis negative_len_shortest neutral)\n  show ?thesis\n  proof (cases \"k \\<in> set (j # ys)\")\n    case False\n    with cycle assms have \"len M' j j ys \\<le> len M j j ys\" by - (rule DBM_reset_len_mono, auto)\n    moreover from cycle assms have \"set (j # ys) \\<subseteq> {0..n}\" by auto\n    ultimately show ?thesis using cycle(1) by fastforce\n  next\n    case True\n    then obtain l where l: \"(l, k) \\<in> set (arcs j j ys)\"\n    proof (cases \"j = k\", goal_cases)\n      case True\n      show ?thesis\n      proof (cases \"ys = []\")\n        case T: True\n        with True show ?thesis by (auto intro: that)\n      next\n        case False\n        then obtain z zs where \"ys = zs @ [z]\" by (metis append_butlast_last_id)\n        from arcs_decomp[OF this] True show ?thesis by (auto intro: that)\n      qed\n    next\n      case False\n      from arcs_set_elem2[OF False True] show ?thesis by (blast intro: that)\n    qed\n    show ?thesis\n    proof (cases \"ys = []\")\n      case False\n      from cycle_rotate_2'[OF False l, of M] cycle(1) obtain zs where rotated:\n        \"len M l l (k # zs) < Le 0\" \"set (l # k # zs) = set (j # ys)\" \"1 + length zs = length ys\"\n      by auto\n      with length_eq_distinct[OF this(2)[symmetric] cycle(2)] have \"distinct (l # k # zs)\" by auto\n      note rotated = rotated(1,2) this\n      from this(2) cycle(3,4) assms(3) have n_bound: \"set (l # k # zs) \\<subseteq> {0..n}\" by auto\n      then have \"l \\<le> n\" by auto\n      show ?thesis\n      proof (cases zs)\n        case Nil\n        with rotated have \"M l k + M k l < Le 0\" \"l \\<noteq> k\"  by auto\n        with assms(1) \\<open>l \\<le> n\\<close> have \"M' l l < Le 0\" unfolding DBM_reset_def add min_def by auto\n        with \\<open>l \\<le> n\\<close> have \"len M' l l [] < Le 0\" \"set [l] \\<subseteq> {0..n}\" by auto\n        then show ?thesis by blast\n      next\n        case (Cons w ws)\n        with n_bound have *: \"set (w # l # ws) \\<subseteq> {0..n}\" by auto\n        from Cons n_bound rotated(3) have \"w \\<le> n\" \"w \\<noteq> k\" \"l \\<noteq> k\" by auto\n        with assms(1) \\<open>l \\<le> n\\<close> have\n          \"M' l w \\<le> M l k + M k w\"\n          unfolding DBM_reset_def add min_def by auto\n        moreover from Cons rotated assms * have\n          \"len M' w l ws \\<le> len M w l ws\"\n          by - (rule DBM_reset_len_mono, auto)\n        ultimately have\n          \"len M' l l zs \\<le> len M l l (k # zs)\"\n          using Cons by (auto intro: add_mono simp add: add.assoc[symmetric])\n        with n_bound rotated(1) show ?thesis by fastforce\n      qed\n    next\n      case T: True\n      with True cycle have \"M j j < Le 0\" \"j = k\" by auto\n      with assms(1) have \"len M' k k [] < Le 0\" unfolding DBM_reset_def by simp\n      moreover from assms(3) have \"set (k # []) \\<subseteq> {0..n}\" by auto\n      ultimately show ?thesis by blast\n    qed\n  qed\nqed\n\ntext \\<open>Implementation of DBM reset\\<close>\n\ndefinition\n  reset :: \"('t::{linordered_cancel_ab_semigroup_add,uminus}) DBM \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> 't \\<Rightarrow> 't DBM\"\nwhere\n  \"reset M n k d =\n    (\\<lambda> i j.\n        if i = k \\<and> j = 0 then Le d\n        else if i = 0 \\<and> j = k then Le (-d)\n        else if i = k \\<and> j \\<noteq> k then \\<infinity>\n        else if i \\<noteq> k \\<and> j = k then \\<infinity>\n        else if i = k \\<and> j = k then M k k\n        else min (dbm_add (M i k) (M k j)) (M i j)\n       )\"\n\nfun\n  reset' ::\n  \"('t::{linordered_cancel_ab_semigroup_add,uminus}) DBM\n  \\<Rightarrow> nat \\<Rightarrow> 'c list \\<Rightarrow> ('c \\<Rightarrow> nat) \\<Rightarrow> 't \\<Rightarrow> 't DBM\"\nwhere\n  \"reset' M n [] v d = M\" |\n  \"reset' M n (c # cs) v d = reset (reset' M n cs v d) n (v c) d\"\n\nlemma DBM_reset_reset:\n  \"0 < k \\<Longrightarrow> k \\<le> n \\<Longrightarrow> DBM_reset M n k d (reset M n k d)\"\nunfolding DBM_reset_def by (auto simp: reset_def)\n\nlemma DBM_reset_complete:\n  assumes \"clock_numbering' v n\" \"v c \\<le> n\" \"DBM_reset M n (v c) d M'\" \"DBM_val_bounded v u M n\"\n  shows \"DBM_val_bounded v (u(c := d)) M' n\"\nunfolding DBM_val_bounded_def using assms\nproof (auto, goal_cases)\n  case 1\n  then have *: \"M 0 0 \\<ge> Le 0\" unfolding DBM_val_bounded_def less_eq by auto\n  from 1 have **: \"M' 0 0 = min (M 0 (v c) + M (v c) 0) (M 0 0)\"\n    unfolding DBM_reset_def add by auto\n  show ?case\n  proof (cases \"M 0 (v c) + M (v c) 0 \\<le> M 0 0\")\n    case False\n    with * ** show ?thesis unfolding min_def less_eq by auto\n  next\n    case True\n    have \"dbm_entry_val u (Some c) (Some c) (M (v c) 0 + M 0 (v c))\"\n      by (metis DBM_val_bounded_def assms(2,4) dbm_entry_val_add_4 add)\n    then have \"M (v c) 0 + M 0 (v c) \\<ge> Le 0\"\n      unfolding less_eq dbm_le_def by (cases \"M (v c) 0 + M 0 (v c)\") auto\n    with True ** have \"M' 0 0 \\<ge> Le 0\" by (simp add: comm)\n    then show ?thesis unfolding less_eq .\n  qed\nnext\n  case (2 c')\n  show ?case\n  proof (cases \"c = c'\")\n    case False\n    hence F:\"v c' \\<noteq> v c\" using 2 by metis\n    hence *:\"M' 0 (v c') = min (dbm_add (M 0 (v c)) (M (v c) (v c'))) (M 0 (v c'))\"\n    using F 2(1,2,4,6) unfolding DBM_reset_def by simp\n    show ?thesis\n    proof (cases \"dbm_add (M 0 (v c)) (M (v c) (v c')) < M 0 (v c')\")\n      case False\n      with * have \"M' 0 (v c') = M 0 (v c')\" by (auto split: split_min)\n      hence \"dbm_entry_val u None (Some c') (M' 0 (v c'))\"\n      using 2(3,6) unfolding DBM_val_bounded_def by auto\n      thus ?thesis using F by cases fastforce+\n    next\n      case True\n      with * have **:\"M' 0 (v c') = dbm_add (M 0 (v c)) (M (v c) (v c'))\" by (auto split: split_min)\n      from 2 have \"dbm_entry_val u None (Some c) (M 0 (v c))\"\n      \"dbm_entry_val u (Some c) (Some c') (M (v c) (v c'))\"\n      unfolding DBM_val_bounded_def by auto\n      thus ?thesis\n      proof (cases, auto simp add: **, goal_cases)\n        case (1 d)\n        note G1 = this\n        from this(2) show ?case\n        proof (cases, goal_cases)\n          case (1 d')\n          from this(2) G1(3) have \"- u c' \\<le> d + d'\"\n          by (metis diff_minus_eq_add less_diff_eq less_le_trans minus_diff_eq minus_le_iff not_le)\n          thus ?case using 1 \\<open>c \\<noteq> c'\\<close> by fastforce\n        next\n          case (2 d')\n          from this(2) G1(3) have \"u c - u c' - u c < d + d'\" using add_le_less_mono by fastforce\n          hence \"- u c' < d + d'\" by simp\n          thus ?case using 2 \\<open>c \\<noteq> c'\\<close> by fastforce\n        next\n          case (3) thus ?case by auto\n        qed\n      next\n        case (2 d)\n        note G2 = this\n        from this(2) show ?case\n        proof (cases, goal_cases)\n          case (1 d')\n          from this(2) G2(3) have \"u c - u c' - u c < d' + d\" using add_le_less_mono by fastforce\n          hence \"- u c' < d' + d\" by simp\n          hence \"- u c' < d + d'\"\n          by (metis (hide_lams, no_types) diff_0_right diff_minus_eq_add minus_add_distrib minus_diff_eq)\n          thus ?case using 1 \\<open>c \\<noteq> c'\\<close> by fastforce\n        next\n          case (2 d')\n          from this(2) G2(3) have \"u c - u c' - u c < d + d'\" using add_strict_mono by fastforce\n          hence \"- u c' < d + d'\" by simp\n          thus ?case using 2 \\<open>c \\<noteq> c'\\<close> by fastforce\n        next\n          case (3) thus ?case by auto\n        qed\n      qed\n    qed\n  next\n    case True\n    with 2 show ?thesis unfolding DBM_reset_def by auto\n  qed\nnext\n  case (3 c')\n  show ?case\n  proof (cases \"c = c'\")\n    case False\n    hence F:\"v c' \\<noteq> v c\" using 3 by metis\n    hence *:\"M' (v c') 0 = min (dbm_add (M (v c') (v c)) (M (v c) 0)) (M (v c') 0)\"\n    using F 3(1,2,4,6) unfolding DBM_reset_def by simp\n    show ?thesis\n    proof (cases \"dbm_add (M (v c') (v c)) (M (v c) 0) < M (v c') 0\")\n      case False\n      with * have \"M' (v c') 0 = M (v c') 0\" by (auto split: split_min)\n      hence \"dbm_entry_val u (Some c') None (M' (v c') 0)\"\n      using 3(3,6) unfolding DBM_val_bounded_def by auto\n      thus ?thesis using F by cases fastforce+\n    next\n      case True\n      with * have **:\"M' (v c') 0 = dbm_add (M (v c') (v c)) (M (v c) 0)\" by (auto split: split_min)\n      from 3 have \"dbm_entry_val u (Some c') (Some c) (M (v c') (v c))\"\n      \"dbm_entry_val u (Some c) None (M (v c) 0)\"\n      unfolding DBM_val_bounded_def by auto\n      thus ?thesis\n      proof (cases, auto simp add: **, goal_cases)\n        case (1 d)\n        note G1 = this\n        from this(2) show ?case\n        proof (cases, goal_cases)\n          case (1 d')\n          from this(2) G1(3) have \"u c' \\<le> d + d'\" using ordered_ab_semigroup_add_class.add_mono\n          by fastforce\n          thus ?case using 1 \\<open>c \\<noteq> c'\\<close> by fastforce\n        next\n          case (2 d')\n          from this(2) G1(3) have \"u c + u c' - u c < d + d'\" using add_le_less_mono by fastforce\n          hence \"u c' < d + d'\" by simp\n          thus ?case using 2 \\<open>c \\<noteq> c'\\<close> by fastforce\n        next\n          case (3) thus ?case by auto\n        qed\n      next\n        case (2 d)\n        note G2 = this\n        from this(2) show ?case\n        proof (cases, goal_cases)\n          case (1 d')\n          from this(2) G2(3) have \"u c + u c' - u c < d' + d\" using add_le_less_mono by fastforce\n          hence \"u c' < d' + d\" by simp\n          hence \"u c' < d + d'\"\n          by (metis (hide_lams, no_types) diff_0_right diff_minus_eq_add minus_add_distrib minus_diff_eq)\n          thus ?case using 1 \\<open>c \\<noteq> c'\\<close> by fastforce\n        next\n          case (2 d')\n          from this(2) G2(3) have \"u c + u c' - u c < d + d'\" using add_strict_mono by fastforce\n          hence \"u c' < d + d'\" by simp\n          thus ?case using 2 \\<open>c \\<noteq> c'\\<close> by fastforce\n        next\n          case 3 thus ?case by auto\n        qed\n      qed\n    qed\n  next\n    case True\n    with 3 show ?thesis unfolding DBM_reset_def by auto\n  qed\nnext\n  case (4 c1 c2)\n  show ?case\n  proof (cases \"c = c1\")\n    case False\n    note F1 = this\n    show ?thesis\n    proof (cases \"c = c2\")\n      case False\n      with F1 4 have F: \"v c \\<noteq> v c1\" \"v c \\<noteq> v c2\" \"v c1 \\<noteq> 0\" \"v c2 \\<noteq> 0\" by force+\n      hence *:\"M' (v c1) (v c2) = min (dbm_add (M (v c1) (v c)) (M (v c) (v c2))) (M (v c1) (v c2))\"\n      using 4(1,2,6,7) unfolding DBM_reset_def by simp\n      show ?thesis\n      proof (cases \"dbm_add (M (v c1) (v c)) (M (v c) (v c2)) < M (v c1) (v c2)\")\n        case False\n        with * have \"M' (v c1) (v c2) = M (v c1) (v c2)\" by (auto split: split_min)\n        hence \"dbm_entry_val u (Some c1) (Some c2) (M' (v c1) (v c2))\"\n        using 4(3,6,7) unfolding DBM_val_bounded_def by auto\n        thus ?thesis using F by cases fastforce+\n      next\n        case True\n        with * have **:\"M' (v c1) (v c2) = dbm_add (M (v c1) (v c)) (M (v c) (v c2))\" by (auto split: split_min)\n        from 4 have \"dbm_entry_val u (Some c1) (Some c) (M (v c1) (v c))\"\n        \"dbm_entry_val u (Some c) (Some c2) (M (v c) (v c2))\" unfolding DBM_val_bounded_def by auto\n        thus ?thesis\n        proof (cases, auto simp add: **, goal_cases)\n          case (1 d)\n          note G1 = this\n          from this(2) show ?case\n          proof (cases, goal_cases)\n            case (1 d')\n            from this(2) G1(3) have \"u c1 - u c2 \\<le> d + d'\"\n            by (metis (hide_lams, no_types) ab_semigroup_add_class.add_ac(1) add_le_cancel_right\n                                  add_left_mono diff_add_cancel dual_order.refl dual_order.trans)\n            thus ?case using 1 \\<open>c \\<noteq> c1\\<close> \\<open>c \\<noteq> c2\\<close> by fastforce\n          next\n            case (2 d')\n            from add_less_le_mono[OF this(2) G1(3)] have \"- u c2 + u c1 < d' + d\" by simp\n            hence \"u c1 - u c2 < d + d'\" by (simp add: add.commute)\n            thus ?case using 2 \\<open>c \\<noteq> c1\\<close> \\<open>c \\<noteq> c2\\<close> by fastforce\n          next\n            case (3) thus ?case by auto\n          qed\n        next\n          case (2 d)\n          note G2 = this\n          from this(2) show ?case\n          proof (cases, goal_cases)\n            case (1 d')\n            with add_less_le_mono[OF G2(3) this(2)] \\<open>c \\<noteq> c1\\<close> \\<open>c \\<noteq> c2\\<close> show ?case\n              by auto\n          next\n            case (2 d')\n            with add_strict_mono[OF this(2) G2(3)] \\<open>c \\<noteq> c1\\<close> \\<open>c \\<noteq> c2\\<close> show ?case\n              by (auto simp: add.commute)\n          next\n            case (3) thus ?case by auto\n          qed\n        qed\n      qed\n    next\n      case True\n      with F1 4 have F: \"v c \\<noteq> v c1\" \"v c1 \\<noteq> 0\" \"v c2 \\<noteq> 0\" by force+\n      thus ?thesis using 4(1,2,4,6,7) True unfolding DBM_reset_def by auto\n    qed\n  next\n    case True\n    note T1 = this\n    show ?thesis\n    proof (cases \"c = c2\")\n      case False\n      with T1 4 have F: \"v c \\<noteq> v c2\" \"v c1 \\<noteq> 0\" \"v c2 \\<noteq> 0\" by force+\n      thus ?thesis using 4(1,2,7) True unfolding DBM_reset_def by auto\n    next\n      case True\n      then have *: \"M' (v c1) (v c1) = M (v c1) (v c1)\"\n      using T1 4 unfolding DBM_reset_def by auto\n      from 4(1,3) True T1 have \"dbm_entry_val u (Some c1) (Some c2) (M (v c1) (v c2))\"\n      unfolding DBM_val_bounded_def by auto\n      then show ?thesis by (cases rule: dbm_entry_val.cases, auto simp: * True[symmetric] T1)\n    qed\n  qed\nqed\n\nlemma DBM_reset_sound_empty:\n  assumes \"clock_numbering' v n\" \"v c \\<le> n\" \"DBM_reset M n (v c) d M'\"\n          \"\\<forall> u . \\<not> DBM_val_bounded v u M' n\"\n  shows \"\\<not> DBM_val_bounded v u M n\"\nusing assms DBM_reset_complete by metis\n\nlemma DBM_reset_diag_preservation:\n  \"\\<forall>k\\<le>n. M k k \\<le> 0 \\<Longrightarrow> DBM_reset M n i d M' \\<Longrightarrow> \\<forall>k\\<le>n. M' k k \\<le> 0\"\n  apply auto\n  apply (case_tac \"k = i\")\n   apply (simp add: DBM_reset_def less[symmetric])\n  apply (case_tac \"k = 0\")\nby (auto simp add: DBM_reset_def less[symmetric] neutral split: split_min)\n\nlemma FW_diag_preservation:\n  \"\\<forall>k\\<le>n. M k k \\<le> 0 \\<Longrightarrow> \\<forall>k\\<le>n. (FW M n) k k \\<le> 0\"\nproof clarify\n  fix k assume A: \"\\<forall>k\\<le>n. M k k \\<le> 0\" \"k \\<le> n\"\n  then have \"M k k \\<le> 0\" by auto\n  with fw_mono[of k n k M n] A show \"FW M n k k \\<le> 0\" by auto\nqed\n\nlemma DBM_reset_not_cyc_free_preservation:\n  assumes \"\\<not> cyc_free M n\" \"DBM_reset M n k d M'\" \"k \\<le> n\"\n  shows \"\\<not> cyc_free M' n\"\nproof -\n  from assms(1) obtain i xs where \"i \\<le> n\" \"set xs \\<subseteq> {0..n}\" \"len M i i xs < Le 0\"\n  unfolding neutral by auto\n  with DBM_reset_neg_cycle_preservation[OF assms(2) this(3)] assms(3) obtain j ys where\n    \"set (j # ys) \\<subseteq> {0..n}\" \"len M' j j ys < Le 0\"\n  by auto\n  then show ?thesis unfolding neutral by force\nqed\n\nlemma DBM_reset_complete_empty':\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering v\" \"k \\<le> n\"\n          \"DBM_reset M n k d M'\" \"\\<forall> u . \\<not> DBM_val_bounded v u M n\"\n  shows \"\\<not> DBM_val_bounded v u M' n\"\nproof -\n  from assms(5) have \"[M]\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\n  from empty_not_cyc_free[OF _ this] have \"\\<not> cyc_free M n\" using assms(2) by auto\n  from DBM_reset_not_cyc_free_preservation[OF this assms(4,3)] have \"\\<not> cyc_free M' n\" by auto\n  then obtain i xs where \"i \\<le> n\" \"set xs \\<subseteq> {0..n}\" \"len M' i i xs < 0\" by auto\n  from DBM_val_bounded_neg_cycle[OF _ this assms(1)] show ?thesis by fast\nqed\n\nlemma DBM_reset_complete_empty:\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering v\"\n          \"DBM_reset (FW M n) n (v c) d M'\" \"\\<forall> u . \\<not> DBM_val_bounded v u (FW M n) n\"\n  shows \"\\<not> DBM_val_bounded v u M' n\"\nproof -\n  note A = assms\n  from A(4) have \"[FW M n]\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\n  with FW_detects_empty_zone[OF A(1), of M] A(2)\n  obtain i where i: \"i \\<le> n\" \"FW M n i i < Le 0\" by blast\n  with A(3,4) have \"M' i i < Le 0\"\n  unfolding DBM_reset_def by (cases \"i = v c\", auto split: split_min)\n  with fw_mono[of i n i M' n] i have \"FW M' n i i < Le 0\" by auto\n  with FW_detects_empty_zone[OF A(1), of M'] A(2) i\n  have \"[FW M' n]\\<^bsub>v,n\\<^esub> = {}\" by auto\n  with FW_zone_equiv[OF A(1)] show ?thesis by (auto simp: DBM_zone_repr_def)\nqed\n\nlemma DBM_reset_complete_empty1:\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering v\"\n          \"DBM_reset (FW M n) n (v c) d M'\" \"\\<forall> u . \\<not> DBM_val_bounded v u M n\"\n  shows \"\\<not> DBM_val_bounded v u M' n\"\nproof -\n  from assms have \"[M]\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\n  with FW_zone_equiv[OF assms(1)] have\n    \"\\<forall> u . \\<not> DBM_val_bounded v u (FW M n) n\"\n  unfolding DBM_zone_repr_def by auto\n  from DBM_reset_complete_empty[OF assms(1-3) this] show ?thesis by auto\nqed\n\ntext \\<open>\n  Lemma \\<open>FW_canonical_id\\<close> allows us to prove correspondences between reset and canonical,\n  like for the two below.\n  Can be left out for the rest because of the triviality of the correspondence.\n\\<close>\n\nlemma DBM_reset_empty'':\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering' v n\" \"v c \\<le> n\"\n          \"DBM_reset M n (v c) d M'\"\n  shows \"[M]\\<^bsub>v,n\\<^esub> = {} \\<longleftrightarrow> [M']\\<^bsub>v,n\\<^esub> = {}\"\nproof\n  assume A: \"[M]\\<^bsub>v,n\\<^esub> = {}\"\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u M n\" unfolding DBM_zone_repr_def by auto\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u M' n\"\n  using DBM_reset_complete_empty'[OF assms(1) _ assms(3,4)] assms(2) by auto\n  thus \"[M']\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\nnext\n  assume \"[M']\\<^bsub>v,n\\<^esub> = {}\"\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u M' n\" unfolding DBM_zone_repr_def by auto\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u M n\" using DBM_reset_sound_empty[OF assms(2-4)] by auto\n  thus \"[M]\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\nqed\n\nlemma DBM_reset_empty:\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering' v n\" \"v c \\<le> n\"\n          \"DBM_reset (FW M n) n (v c) d M'\"\n  shows \"[FW M n]\\<^bsub>v,n\\<^esub> = {} \\<longleftrightarrow> [M']\\<^bsub>v,n\\<^esub> = {}\"\nproof\n  assume A: \"[FW M n]\\<^bsub>v,n\\<^esub> = {}\"\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u (FW M n) n\" unfolding DBM_zone_repr_def by auto\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u M' n\"\n  using DBM_reset_complete_empty[of n v M, OF assms(1) _ assms(4)] assms(2,3) by auto\n  thus \"[M']\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\nnext\n  assume \"[M']\\<^bsub>v,n\\<^esub> = {}\"\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u M' n\" unfolding DBM_zone_repr_def by auto\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u (FW M n) n\" using DBM_reset_sound_empty[OF assms(2-)] by auto\n  thus \"[FW M n]\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\nqed\n\nlemma DBM_reset_empty':\n  assumes \"canonical M n\" \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering' v n\" \"v c \\<le> n\"\n          \"DBM_reset (FW M n) n (v c) d M'\"\n  shows   \"[M]\\<^bsub>v,n\\<^esub> = {} \\<longleftrightarrow> [M']\\<^bsub>v,n\\<^esub> = {}\"\nusing FW_canonical_id[OF assms(1)] DBM_reset_empty[OF assms(2-)] by simp\n\nlemma DBM_reset_sound':\n  assumes \"clock_numbering' v n\" \"v c \\<le> n\" \"DBM_reset M n (v c) d M'\" \"DBM_val_bounded v u M' n\"\n          \"DBM_val_bounded v u'' M n\"\n  obtains d' where  \"DBM_val_bounded v (u(c := d')) M n\"\nusing assms\nproof (auto, goal_cases)\n  case 1\n  note A = this\n  obtain S_Min_Le where S_Min_Le:\n  \"S_Min_Le = {u c' - d | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c') (v c) = Le d}\n               \\<union> {-d | d. M 0 (v c) = Le d}\" by auto\n  obtain S_Min_Lt where S_Min_Lt:\n  \"S_Min_Lt = {u c' - d | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c') (v c) = Lt d}\n              \\<union> {-d | d. M 0 (v c) = Lt d}\" by auto\n  obtain S_Max_Le where S_Max_Le:\n  \"S_Max_Le = {u c' + d | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c) (v c') = Le d}\n              \\<union> {d | d. M (v c) 0 = Le d}\" by auto\n  obtain S_Max_Lt where S_Max_Lt:\n  \"S_Max_Lt = {u c' + d | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c) (v c') = Lt d}\n              \\<union> {d | d. M (v c) 0 = Lt d}\" by auto\n\n  have \"finite {c. 0 < v c \\<and> v c \\<le> n}\" using A(6,7)\n  proof (induction n)\n    case 0\n    then have \"{c. 0 < v c \\<and> v c \\<le> 0} = {}\" by auto\n    then show ?case by (metis finite.emptyI)\n  next\n    case (Suc n)\n    then have \"finite {c. 0 < v c \\<and> v c \\<le> n}\" by auto\n    moreover have \"{c. 0 < v c \\<and> v c \\<le> Suc n} = {c. 0 < v c \\<and> v c \\<le> n} \\<union> {c. v c = Suc n}\" by auto\n    moreover have \"finite {c. v c = Suc n}\"\n    proof (cases \"{c. v c = Suc n} = {}\", auto)\n      fix c assume \"v c = Suc n\"\n      then have \"{c. v c = Suc n} = {c}\" using Suc.prems(2) by auto\n      then show ?thesis by auto\n    qed\n    ultimately show ?case by auto\n  qed\n  then have \"\\<forall> f. finite {(c,b) | c b. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = b}\" by auto\n  moreover have\n    \"\\<forall> f K. {(c,K d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\n    \\<subseteq> {(c,b) | c b. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = b}\"\n  by auto\n  ultimately have B:\n    \"\\<forall> f K. finite {(c,K d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\"\n  using finite_subset by fast\n  have \"\\<forall> f K. theLe o K = id \\<longrightarrow> finite {(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\"\n  proof (auto, goal_cases)\n    case (1 f K)\n    then have\n      \"{(c,d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\n      = (\\<lambda> (c,b). (c, theLe b)) ` {(c,K d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\"\n    proof (auto simp add: pointfree_idE, goal_cases)\n      case (1 a b)\n      then have \"(a, K b) \\<in> {(c, K d) |c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d}\" by auto\n      moreover from 1(1) have \"theLe (K b) = b\" by (simp add: pointfree_idE)\n      ultimately show ?case by force\n    qed\n    moreover from B have\n      \"finite ((\\<lambda> (c,b). (c, theLe b)) ` {(c,K d) | c d. 0 < v c \\<and> v c \\<le> n \\<and> f M (v c) = K d})\"\n    by auto\n    ultimately show ?case by auto\n  qed\n  then have finI:\n    \"\\<And> f g K. theLe o K = id \\<Longrightarrow> finite (g ` {(c',d) | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> f M (v c') = K d})\"\n  by auto\n  have finI1:\n    \"\\<And> f g K. theLe o K = id \\<Longrightarrow> finite (g ` {(c',d) | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> f M (v c') = K d})\"\n  proof goal_cases\n    case (1 f g K)\n    have\n      \"g ` {(c',d) | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> f M (v c') = K d}\n      \\<subseteq> g ` {(c',d) | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> f M (v c') = K d}\"\n    by auto\n    from finite_subset[OF this finI[OF 1, of g f]] show ?case .\n  qed\n  have \"\\<forall> f. finite {b. f M (v c) = b}\" by auto\n  moreover have \"\\<forall> f K. {K d | d. f M (v c) = K d} \\<subseteq> {b. f M (v c) = b}\" by auto\n  ultimately have B: \"\\<forall> f K. finite {K d | d. f M (v c) = K d}\" using finite_subset by fast\n\n  have \"\\<forall> f K. theLe o K = id \\<longrightarrow> finite {d | d. f M (v c) = K d}\"\n  proof (auto, goal_cases)\n    case (1 f K)\n    then have \"{d | d. f M (v c) = K d} = theLe ` {K d | d. f M (v c) = K d}\"\n    proof (auto simp add: pointfree_idE, goal_cases)\n      case (1 x)\n      have \"K x \\<in> {K d |d. K x = K d}\" by auto\n      moreover from 1 have \"theLe (K x) = x\"  by (simp add: pointfree_idE)\n      ultimately show ?case by auto\n    qed\n    moreover from B have \"finite {K d |d. f M (v c) = K d}\" by auto\n    ultimately show ?case by auto\n  qed\n  then have C: \"\\<forall> f g K. theLe o K = id \\<longrightarrow> finite (g ` {d | d. f M (v c) = K d})\" by auto\n  have finI2: \"\\<And> f g K. theLe o K = id \\<Longrightarrow> finite ({g d | d. f M (v c) = K d})\"\n  proof goal_cases\n    case (1 f g K)\n    have \"{g d |d. f M (v c) = K d} = g ` {d | d. f M (v c) = K d}\" by auto\n    with C 1 show ?case by auto\n  qed\n\n  { fix K :: \"'b \\<Rightarrow> 'b DBMEntry\" assume A: \"theLe o K = id\"\n    then have\n      \"finite ((\\<lambda>(c,d). u c - d) ` {(c',d) | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c') (v c) = K d})\"\n    by (intro finI1, auto)\n    moreover have\n      \"{u c' - d |c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c') (v c) = K d}\n      = ((\\<lambda>(c,d). u c - d) ` {(c',d) | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c') (v c) = K d})\"\n    by auto\n    ultimately have \"finite {u c' - d |c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c') (v c) = K d}\"\n    by auto\n    moreover have \"finite {- d |d. M 0 (v c) = K d}\" using A by (intro finI2, auto)\n    ultimately have\n      \"finite ({u c' - d |c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c') (v c) = K d}\n                \\<union> {- d |d. M 0 (v c) = K d})\"\n    by (auto simp: S_Min_Le)\n  } note fin1 = this\n  have fin_min_le: \"finite S_Min_Le\" unfolding S_Min_Le by (rule fin1, auto)\n  have fin_min_lt: \"finite S_Min_Lt\" unfolding S_Min_Lt by (rule fin1, auto)\n\n  { fix K :: \"'b \\<Rightarrow> 'b DBMEntry\" assume A: \"theLe o K = id\"\n    then have \"finite ((\\<lambda>(c,d). u c + d) ` {(c',d) | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c) (v c') = K d})\"\n    by (intro finI1, auto)\n    moreover have\n      \"{u c' + d |c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c) (v c') = K d}\n      = ((\\<lambda>(c,d). u c + d) ` {(c',d) | c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c) (v c') = K d})\"\n    by auto\n    ultimately have \"finite {u c' + d |c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c) (v c') = K d}\"\n    by auto\n    moreover have \"finite {d |d. M (v c) 0 = K d}\" using A by (intro finI2, auto)\n    ultimately have\n      \"finite ({u c' + d |c' d. 0 < v c' \\<and> v c' \\<le> n \\<and> c \\<noteq> c' \\<and> M (v c) (v c') = K d}\n               \\<union> {d |d. M (v c) 0 = K d})\"\n    by (auto simp: S_Min_Le)\n  } note fin2 = this\n  have fin_max_le: \"finite S_Max_Le\" unfolding S_Max_Le by (rule fin2, auto)\n  have fin_max_lt: \"finite S_Max_Lt\" unfolding S_Max_Lt by (rule fin2, auto)\n\n  { fix l r assume \"l \\<in> S_Min_Le\" \"r \\<in> S_Max_Le\"\n    then have \"l \\<le> r\"\n    proof (auto simp: S_Min_Le S_Max_Le, goal_cases)\n      case (1 c1 d1 c2 d2)\n      with A have\n        \"dbm_entry_val u (Some c1) (Some c2) (M' (v c1) (v c2))\"\n      unfolding DBM_val_bounded_def by presburger\n      moreover have\n        \"M' (v c1) (v c2) = min (dbm_add (M (v c1) (v c)) (M (v c) (v c2))) (M (v c1) (v c2))\"\n      using A(3,7) 1 unfolding DBM_reset_def by metis\n      ultimately have\n        \"dbm_entry_val u (Some c1) (Some c2) (dbm_add (M (v c1) (v c)) (M (v c) (v c2)))\"\n      using dbm_entry_dbm_min' by auto\n      with 1 have \"u c1 - u c2 \\<le> d1 + d2\" by auto\n      thus ?case\n      by (metis (hide_lams, no_types) add_diff_cancel_left diff_0_right diff_add_cancel diff_eq_diff_less_eq)\n    next\n      case (2 c' d)\n      with A have\n        \"(\\<forall>i\\<le>n. i \\<noteq> v c \\<and> i > 0 \\<longrightarrow> M' i 0 = min (dbm_add (M i (v c)) (M (v c) 0)) (M i 0))\"\n        \"v c' \\<noteq> v c\"\n      unfolding DBM_reset_def by auto\n      hence \"(M' (v c') 0 = min (dbm_add (M (v c') (v c)) (M (v c) 0)) (M (v c') 0))\"\n      using 2 by blast\n      moreover from A 2 have \"dbm_entry_val u (Some c') None (M' (v c') 0)\"\n      unfolding DBM_val_bounded_def by presburger\n      ultimately have \"dbm_entry_val u (Some c') None (dbm_add (M (v c') (v c)) (M (v c) 0))\"\n      using dbm_entry_dbm_min3' by fastforce\n      with 2 have \"u c' \\<le> d + r\" by auto\n      thus ?case by (metis add_diff_cancel_left add_le_cancel_right diff_0_right diff_add_cancel)\n    next\n      case (3 d c' d')\n      with A have\n        \"(\\<forall>i\\<le>n. i \\<noteq> v c \\<and> i > 0 \\<longrightarrow> M' 0 i = min (dbm_add (M 0 (v c)) (M (v c) i)) (M 0 i))\"\n        \"v c' \\<noteq> v c\"\n      unfolding DBM_reset_def by auto\n      hence \"(M' 0 (v c') = min (dbm_add (M 0 (v c)) (M (v c) (v c'))) (M 0 (v c')))\"\n      using 3 by blast\n      moreover from A 3 have \"dbm_entry_val u None (Some c') (M' 0 (v c'))\"\n      unfolding DBM_val_bounded_def by presburger\n      ultimately have \"dbm_entry_val u None (Some c') (dbm_add (M 0 (v c)) (M (v c) (v c')))\"\n      using dbm_entry_dbm_min2' by fastforce\n      with 3 have \"-u c' \\<le> d + d'\" by auto\n      thus ?case\n      by (metis add_uminus_conv_diff diff_le_eq minus_add_distrib minus_le_iff)\n    next\n      case (4 d)\n      text \\<open>\n        Here is the reason we need the assumption that the zone was not empty before the reset.\n        We cannot deduce anything from the current value of \\<open>c\\<close> itself because we reset it.\n        We can only ensure that we can reset the value of \\<open>c\\<close> by using the value from the\n        alternative assignment.\n        This case is only relevant if the tightest bounds for \\<open>d\\<close> were given by its original\n        lower and upper bounds. If they would overlap, the original zone would be empty.\n      \\<close>\n      from A(2,5) have\n        \"dbm_entry_val u'' None (Some c) (M 0 (v c))\"\n        \"dbm_entry_val u'' (Some c) None (M (v c) 0)\"\n      unfolding DBM_val_bounded_def by auto\n      with 4 have \"- u'' c \\<le> d\" \"u'' c \\<le> r\" by auto\n      thus ?case by (metis minus_le_iff order.trans)\n    qed\n  } note EE = this\n  { fix l r assume \"l \\<in> S_Min_Le\" \"r \\<in> S_Max_Lt\"\n    then have \"l < r\"\n    proof (auto simp: S_Min_Le S_Max_Lt, goal_cases)\n      case (1 c1 d1 c2 d2)\n      with A have \"dbm_entry_val u (Some c1) (Some c2) (M' (v c1) (v c2))\"\n      unfolding DBM_val_bounded_def by presburger\n      moreover have \"M' (v c1) (v c2) = min (dbm_add (M (v c1) (v c)) (M (v c) (v c2))) (M (v c1) (v c2))\"\n      using A(3,7) 1 unfolding DBM_reset_def by metis\n      ultimately have \"dbm_entry_val u (Some c1) (Some c2) (dbm_add (M (v c1) (v c)) (M (v c) (v c2)))\"\n      using dbm_entry_dbm_min' by fastforce\n      with 1 have \"u c1 - u c2 < d1 + d2\" by auto\n      then show ?case by (metis add.assoc add.commute diff_less_eq)\n    next\n      case (2 c' d)\n      with A have\n        \"(\\<forall>i\\<le>n. i \\<noteq> v c \\<and> i > 0 \\<longrightarrow> M' i 0 = min (dbm_add (M i (v c)) (M (v c) 0)) (M i 0))\"\n        \"v c' \\<noteq> v c\"\n      unfolding DBM_reset_def by auto\n      hence \"(M' (v c') 0 = min (dbm_add (M (v c') (v c)) (M (v c) 0)) (M (v c') 0))\"\n      using 2 by blast\n      moreover from A 2 have \"dbm_entry_val u (Some c') None (M' (v c') 0)\"\n      unfolding DBM_val_bounded_def by presburger\n      ultimately have \"dbm_entry_val u (Some c') None (dbm_add (M (v c') (v c)) (M (v c) 0))\"\n      using dbm_entry_dbm_min3' by fastforce\n      with 2 have \"u c' < d + r\" by auto\n      thus ?case by (metis add_less_imp_less_right diff_add_cancel gt_swap)\n    next\n      case (3 d c' da)\n      with A have\n        \"(\\<forall>i\\<le>n. i \\<noteq> v c \\<and> i > 0 \\<longrightarrow> M' 0 i = min (dbm_add (M 0 (v c)) (M (v c) i)) (M 0 i))\"\n        \"v c' \\<noteq> v c\"\n      unfolding DBM_reset_def by auto\n      hence \"(M' 0 (v c') = min (dbm_add (M 0 (v c)) (M (v c) (v c'))) (M 0 (v c')))\"\n      using 3 by blast\n      moreover from A 3 have \"dbm_entry_val u None (Some c') (M' 0 (v c'))\"\n      unfolding DBM_val_bounded_def by presburger\n      ultimately have \"dbm_entry_val u None (Some c') (dbm_add (M 0 (v c)) (M (v c) (v c')))\"\n      using dbm_entry_dbm_min2' by fastforce\n      with 3 have \"-u c' < d + da\" by auto\n      thus ?case by (metis add.commute diff_less_eq uminus_add_conv_diff)\n    next\n      case (4 d)\n      from A(2,5) have\n        \"dbm_entry_val u'' None (Some c) (M 0 (v c))\"\n        \"dbm_entry_val u'' (Some c) None (M (v c) 0)\"\n      unfolding DBM_val_bounded_def by auto\n      with 4 have \"- u'' c \\<le> d\" \"u'' c < r\" by auto\n      thus ?case by (metis minus_le_iff neq_iff not_le order.strict_trans)\n    qed\n  } note EL = this\n  { fix l r assume \"l \\<in> S_Min_Lt\" \"r \\<in> S_Max_Le\"\n    then have \"l < r\"\n    proof (auto simp: S_Min_Lt S_Max_Le, goal_cases)\n      case (1 c1 d1 c2 d2)\n      with A have \"dbm_entry_val u (Some c1) (Some c2) (M' (v c1) (v c2))\"\n      unfolding DBM_val_bounded_def by presburger\n      moreover have \"M' (v c1) (v c2) = min (dbm_add (M (v c1) (v c)) (M (v c) (v c2))) (M (v c1) (v c2))\"\n      using A(3,7) 1 unfolding DBM_reset_def by metis\n      ultimately have \"dbm_entry_val u (Some c1) (Some c2) (dbm_add (M (v c1) (v c)) (M (v c) (v c2)))\"\n      using dbm_entry_dbm_min' by fastforce\n      with 1 have \"u c1 - u c2 < d1 + d2\" by auto\n      thus ?case by (metis add.assoc add.commute diff_less_eq)\n    next\n      case (2 c' d)\n      with A have\n        \"(\\<forall>i\\<le>n. i \\<noteq> v c \\<and> i > 0 \\<longrightarrow> M' i 0 = min (dbm_add (M i (v c)) (M (v c) 0)) (M i 0))\"\n        \"v c' \\<noteq> v c\"\n      unfolding DBM_reset_def by auto\n      hence \"(M' (v c') 0 = min (dbm_add (M (v c') (v c)) (M (v c) 0)) (M (v c') 0))\"\n      using 2 by blast\n      moreover from A 2 have \"dbm_entry_val u (Some c') None (M' (v c') 0)\"\n      unfolding DBM_val_bounded_def by presburger\n      ultimately have \"dbm_entry_val u (Some c') None (dbm_add (M (v c') (v c)) (M (v c) 0))\"\n      using dbm_entry_dbm_min3' by fastforce\n      with 2 have \"u c' < d + r\" by auto\n      thus ?case by (metis add_less_imp_less_right diff_add_cancel gt_swap)\n    next\n      case (3 d c' da)\n      with A have\n        \"(\\<forall>i\\<le>n. i \\<noteq> v c \\<and> i > 0 \\<longrightarrow> M' 0 i = min (dbm_add (M 0 (v c)) (M (v c) i)) (M 0 i))\"\n        \"v c' \\<noteq> v c\"\n      unfolding DBM_reset_def by auto\n      hence \"(M' 0 (v c') = min (dbm_add (M 0 (v c)) (M (v c) (v c'))) (M 0 (v c')))\"\n      using 3 by blast\n      moreover from A 3 have \"dbm_entry_val u None (Some c') (M' 0 (v c'))\"\n      unfolding DBM_val_bounded_def by presburger\n      ultimately have \"dbm_entry_val u None (Some c') (dbm_add (M 0 (v c)) (M (v c) (v c')))\"\n      using dbm_entry_dbm_min2' by fastforce\n      with 3 have \"-u c' < d + da\" by auto\n      thus ?case by (metis add.commute diff_less_eq uminus_add_conv_diff)\n    next\n      case (4 d)\n      from A(2,5) have\n        \"dbm_entry_val u'' None (Some c) (M 0 (v c))\"\n        \"dbm_entry_val u'' (Some c) None (M (v c) 0)\"\n      unfolding DBM_val_bounded_def by auto\n      with 4 have \"- u'' c < d\" \"u'' c \\<le> r\" by auto\n      thus ?case by (meson less_le_trans minus_less_iff)\n    qed\n  } note LE = this\n  { fix l r assume \"l \\<in> S_Min_Lt\" \"r \\<in> S_Max_Lt\"\n    then have \"l < r\"\n    proof (auto simp: S_Min_Lt S_Max_Lt, goal_cases)\n      case (1 c1 d1 c2 d2)\n      with A have \"dbm_entry_val u (Some c1) (Some c2) (M' (v c1) (v c2))\"\n      unfolding DBM_val_bounded_def by presburger\n      moreover have \"M' (v c1) (v c2) = min (dbm_add (M (v c1) (v c)) (M (v c) (v c2))) (M (v c1) (v c2))\"\n      using A(3,7) 1 unfolding DBM_reset_def by metis\n      ultimately have \"dbm_entry_val u (Some c1) (Some c2) (dbm_add (M (v c1) (v c)) (M (v c) (v c2)))\"\n      using dbm_entry_dbm_min' by fastforce\n      with 1 have \"u c1 - u c2 < d1 + d2\" by auto\n      then show ?case by (metis add.assoc add.commute diff_less_eq)\n    next\n      case (2 c' d)\n      with A have\n        \"(\\<forall>i\\<le>n. i \\<noteq> v c \\<and> i > 0\\<longrightarrow> M' i 0 = min (dbm_add (M i (v c)) (M (v c) 0)) (M i 0))\"\n        \"v c' \\<noteq> v c\"\n      unfolding DBM_reset_def by auto\n      hence \"(M' (v c') 0 = min (dbm_add (M (v c') (v c)) (M (v c) 0)) (M (v c') 0))\"\n      using 2 by blast\n      moreover from A 2 have \"dbm_entry_val u (Some c') None (M' (v c') 0)\"\n      unfolding DBM_val_bounded_def by presburger\n      ultimately have \"dbm_entry_val u (Some c') None (dbm_add (M (v c') (v c)) (M (v c) 0))\"\n      using dbm_entry_dbm_min3' by fastforce\n      with 2 have \"u c' < d + r\" by auto\n      thus ?case by (metis add_less_imp_less_right diff_add_cancel gt_swap)\n    next\n      case (3 d c' da)\n      with A have\n        \"(\\<forall>i\\<le>n. i \\<noteq> v c \\<and> i > 0 \\<longrightarrow> M' 0 i = min (dbm_add (M 0 (v c)) (M (v c) i)) (M 0 i))\"\n        \"v c' \\<noteq> v c\"\n      unfolding DBM_reset_def by auto\n      hence \"(M' 0 (v c') = min (dbm_add (M 0 (v c)) (M (v c) (v c'))) (M 0 (v c')))\"\n      using 3 by blast\n      moreover from A 3 have \"dbm_entry_val u None (Some c') (M' 0 (v c'))\"\n      unfolding DBM_val_bounded_def by presburger\n      ultimately have \"dbm_entry_val u None (Some c') (dbm_add (M 0 (v c)) (M (v c) (v c')))\"\n      using dbm_entry_dbm_min2' by fastforce\n      with 3 have \"-u c' < d + da\" by auto\n      thus ?case by (metis ab_group_add_class.ab_diff_conv_add_uminus add.commute diff_less_eq)\n    next\n      case (4 d)\n      from A(2,5) have\n        \"dbm_entry_val u'' None (Some c) (M 0 (v c))\"\n        \"dbm_entry_val u'' (Some c) None (M (v c) 0)\"\n      unfolding DBM_val_bounded_def by auto\n      with 4 have \"- u'' c \\<le> d\" \"u'' c < r\" by auto\n      thus ?case by (metis minus_le_iff neq_iff not_le order.strict_trans)\n    qed\n  } note LL = this\n\n  obtain d' where d':\n    \"\\<forall> t \\<in> S_Min_Le. d' \\<ge> t\" \"\\<forall> t \\<in> S_Min_Lt. d' > t\"\n    \"\\<forall> t \\<in> S_Max_Le. d' \\<le> t\" \"\\<forall> t \\<in> S_Max_Lt. d' < t\"\n  proof -\n    assume m:\n      \"\\<And>d'. \\<lbrakk>\\<forall>t\\<in>S_Min_Le. t \\<le> d'; \\<forall>t\\<in>S_Min_Lt. t < d'; \\<forall>t\\<in>S_Max_Le. d' \\<le> t; \\<forall>t\\<in>S_Max_Lt. d' < t\\<rbrakk>\n        \\<Longrightarrow> thesis\"\n    let ?min_le = \"Max S_Min_Le\"\n    let ?min_lt = \"Max S_Min_Lt\"\n    let ?max_le = \"Min S_Max_Le\"\n    let ?max_lt = \"Min S_Max_Lt\"\n\n    show thesis\n    proof (cases \"S_Min_Le = {} \\<and> S_Min_Lt = {}\")\n      case True\n      note T = this\n      show thesis\n      proof (cases \"S_Max_Le = {} \\<and> S_Max_Lt = {}\")\n        case True\n        let ?d' = \"0 :: 't :: time\"\n        show thesis using True T by (intro m[of ?d']) auto\n      next\n        case False\n        let ?d =\n          \"if S_Max_Le \\<noteq> {}\n           then if S_Max_Lt \\<noteq> {} then min ?max_lt ?max_le else ?max_le\n           else ?max_lt\"\n        obtain a :: \"'b\" where a: \"a < 0\" using non_trivial_neg by auto\n        let ?d' = \"min 0 (?d + a)\"\n        { fix x assume \"x \\<in> S_Max_Le\"\n          with fin_max_le a have \"min 0 (Min S_Max_Le + a) \\<le> x\"\n          by (metis Min.boundedE add_le_same_cancel1 empty_iff less_imp_le min.coboundedI2)\n          then have \"min 0 (Min S_Max_Le + a) \\<le> x\" by auto\n        } note 1 = this\n        { fix x assume x: \"x \\<in> S_Max_Lt\"\n          have \"min 0 (min (Min S_Max_Lt) (Min S_Max_Le) + a) < ?max_lt\"\n          by (meson a add_less_same_cancel1 min.cobounded1 min.strict_coboundedI2 order.strict_trans2)\n          also from fin_max_lt x have \"\\<dots> \\<le> x\" by auto\n          finally have \"min 0 (min (Min S_Max_Lt) (Min S_Max_Le) + a) < x\" .\n        } note 2 = this\n        { fix x assume x: \"x \\<in> S_Max_Le\"\n          have \"min 0 (min (Min S_Max_Lt) (Min S_Max_Le) + a) \\<le> ?max_le\"\n          by (metis le_add_same_cancel1 linear not_le a min_le_iff_disj)\n          also from fin_max_le x have \"\\<dots> \\<le> x\" by auto\n          finally have \"min 0 (min (Min S_Max_Lt) (Min S_Max_Le) + a) \\<le> x\" .\n        } note 3 = this\n        show thesis using False T a 1 2 3\n        proof ((intro m[of ?d']), auto, goal_cases)\n          case 1 then show ?case\n          by (metis Min.coboundedI add_less_same_cancel1 fin_max_lt min.boundedE min.orderE not_less)\n        qed\n      qed\n    next\n      case False\n      note F = this\n      show thesis\n      proof (cases \"S_Max_Le = {} \\<and> S_Max_Lt = {}\")\n        case True\n        let ?l =\n          \"if S_Min_Le \\<noteq> {}\n           then if S_Min_Lt \\<noteq> {} then max ?min_lt ?min_le else ?min_le\n           else ?min_lt\"\n        obtain a :: \"'b\" where \"a < 0\" using non_trivial_neg by blast\n        then have a: \"-a > 0\" using non_trivial_neg by simp\n        then obtain a :: \"'b\" where a: \"a > 0\" by blast\n        let ?d' = \"?l + a\"\n        {\n          fix x assume x: \"x \\<in> S_Min_Le\"\n          then have \"x \\<le> max ?min_lt ?min_le\" \"x \\<le> ?min_le\" using fin_min_le by (simp add: max.coboundedI2)+\n          then have \"x \\<le> max ?min_lt ?min_le + a\" \"x \\<le> ?min_le + a\" using a by (simp add: add_increasing2)+\n        } note 1 = this\n        {\n          fix x assume x: \"x \\<in> S_Min_Lt\"\n          then have \"x \\<le> max ?min_lt ?min_le\" \"x \\<le> ?min_lt\" using fin_min_lt by (simp add: max.coboundedI1)+\n          then have \"x < ?d'\" using a x by (auto simp add: add.commute add_strict_increasing)\n        } note 2 = this\n        show thesis using True F a 1 2 by ((intro m[of ?d']), auto)\n      next\n        case False\n        let ?r =\n          \"if S_Max_Le \\<noteq> {}\n           then if S_Max_Lt \\<noteq> {} then min ?max_lt ?max_le else ?max_le\n           else ?max_lt\"\n        let ?l =\n          \"if S_Min_Le \\<noteq> {}\n           then if S_Min_Lt \\<noteq> {} then max ?min_lt ?min_le else ?min_le\n           else ?min_lt\"\n        have 1: \"x \\<le> max ?min_lt ?min_le\" \"x \\<le> ?min_le\" if \"x \\<in> S_Min_Le\" for x\n        by (simp add: max.coboundedI2 that fin_min_le)+\n        {\n          fix x y assume x: \"x \\<in> S_Max_Le\" \"y \\<in> S_Min_Lt\"\n          then have \"S_Min_Lt \\<noteq> {}\" by auto\n          from LE[OF Max_in[OF fin_min_lt], OF this, OF x(1)] have \"?min_lt \\<le> x\" by auto\n        } note 3 = this\n        {\n          fix x y assume x: \"x \\<in> S_Max_Le\" \"y \\<in> S_Min_Le\"\n          with EE[OF Max_in[OF fin_min_le], OF _ x(1)] have \"?min_le \\<le> x\" by auto\n        } note 4 = this\n        {\n          fix x y assume x: \"x \\<in> S_Max_Lt\" \"y \\<in> S_Min_Lt\"\n          then have \"S_Min_Lt \\<noteq> {}\" by auto\n          from LL[OF Max_in[OF fin_min_lt], OF this, OF x(1)] have \"?min_lt < x\" by auto\n        } note 5 = this\n        {\n          fix x y assume x: \"x \\<in> S_Max_Lt\" \"y \\<in> S_Min_Le\"\n          then have \"S_Min_Le \\<noteq> {}\" by auto\n          from EL[OF Max_in[OF fin_min_le], OF this, OF x(1)] have \"?min_le < x\" by auto\n        } note 6 = this\n\n        show thesis\n        proof (cases \"?l < ?r\")\n          case False\n          then have *: \"S_Max_Le \\<noteq> {}\"\n          proof (auto, goal_cases)\n            case 1\n            with \\<open>\\<not> (S_Max_Le = {} \\<and> S_Max_Lt = {})\\<close> obtain y where y:\"y \\<in> S_Max_Lt\" by auto\n            note 1 = 1 this\n            { fix x y assume A: \"x \\<in> S_Min_Le\" \"y \\<in> S_Max_Lt\"\n                  with EL[OF Max_in[OF fin_min_le] Min_in[OF fin_max_lt]]\n                  have \"Max S_Min_Le < Min S_Max_Lt\" by auto\n            } note ** = this\n            { fix x y assume A: \"x \\<in> S_Min_Lt\" \"y \\<in> S_Max_Lt\"\n                with LL[OF Max_in[OF fin_min_lt] Min_in[OF fin_max_lt]]\n                have \"Max S_Min_Lt < Min S_Max_Lt\" by auto\n            } note *** = this\n            show ?case\n            proof (cases \"S_Min_Le \\<noteq> {}\")\n              case True\n              note T = this\n              show ?thesis\n              proof (cases \"S_Min_Lt \\<noteq> {}\")\n                case True\n                then show False using 1 T True ** *** by auto\n              next\n                case False with 1 T ** show False by auto\n              qed\n            next\n              case False\n              with 1 False *** \\<open>\\<not> (S_Min_Le = {} \\<and> S_Min_Lt = {})\\<close> show ?thesis by auto\n            qed\n          qed\n          { fix x y assume A: \"x \\<in> S_Min_Lt\" \"y \\<in> S_Max_Lt\"\n                with LL[OF Max_in[OF fin_min_lt] Min_in[OF fin_max_lt]]\n                have \"Max S_Min_Lt < Min S_Max_Lt\" by auto\n            } note *** = this\n          { fix x y assume A: \"x \\<in> S_Min_Lt\" \"y \\<in> S_Max_Le\"\n                  with LE[OF Max_in[OF fin_min_lt] Min_in[OF fin_max_le]]\n                  have \"Max S_Min_Lt < Min S_Max_Le\" by auto\n          } note **** = this\n          from F False have **: \"S_Min_Le \\<noteq> {}\"\n          proof (auto, goal_cases)\n            case 1\n            show ?case\n            proof (cases \"S_Max_Le \\<noteq> {}\")\n              case True\n              note T = this\n              show ?thesis\n              proof (cases \"S_Max_Lt \\<noteq> {}\")\n                case True\n                then show False using 1 T True **** *** by auto\n              next\n                case False with 1 T **** show False by auto\n              qed\n            next\n              case False\n              with 1 False *** \\<open>\\<not> (S_Max_Le = {} \\<and> S_Max_Lt = {})\\<close> show ?thesis by auto\n            qed\n          qed\n          {\n            fix x assume x: \"x \\<in> S_Min_Lt\"\n            then have \"x \\<le> ?min_lt\" using fin_min_lt by (simp add: max.coboundedI2)\n            also have \"?min_lt < ?min_le\"\n            proof (rule ccontr, goal_cases)\n              case 1\n              with x ** have 1: \"?l = ?min_lt\" by (auto simp: max.absorb1)\n              have 2: \"?min_lt < ?max_le\" using * ****[OF x] by auto\n              show False\n              proof (cases \"S_Max_Lt = {}\")\n                case False\n                then have \"?min_lt < ?max_lt\" using * ***[OF x] by auto\n                with 1 2 have \"?l < ?r\" by auto\n                with \\<open>\\<not> ?l < ?r\\<close> show False by auto\n              next\n                case True\n                with 1 2 have \"?l < ?r\" by auto\n                with \\<open>\\<not> ?l < ?r\\<close> show False by auto\n              qed\n            qed\n            finally have \"x < max ?min_lt ?min_le\" by (simp add: max.strict_coboundedI2)\n          } note 2 = this\n          show thesis using F False 1 2 3 4 5 6 * ** by ((intro m[of ?l]), auto)\n        next\n          case True\n          then obtain d where d: \"?l < d\" \"d < ?r\" using dense by auto\n          let ?d' = \"d\"\n          {\n            fix t assume \"t \\<in> S_Min_Le\"\n            then have \"t \\<le> ?l\" using 1 by auto\n            with d have \"t \\<le> d\" by auto\n          }\n          moreover {\n            fix t assume t: \"t \\<in> S_Min_Lt\"\n            then have \"t \\<le> max ?min_lt ?min_le\" using fin_min_lt by (simp add: max.coboundedI1)\n            with t have \"t \\<le> ?l\" using fin_min_lt by auto\n            with d have \"t < d\" by auto\n          }\n          moreover {\n            fix t assume t: \"t \\<in> S_Max_Le\"\n            then have \"min ?max_lt ?max_le \\<le> t\" using fin_max_le by (simp add: min.coboundedI2)\n            then have \"?r \\<le> t\" using fin_max_le t by auto\n            with d have \"d \\<le> t\" by auto\n            then have \"d \\<le> t\" by (simp add: min.coboundedI2)\n          }\n          moreover {\n            fix t assume t: \"t \\<in> S_Max_Lt\"\n            then have \"min ?max_lt ?max_le \\<le> t\" using fin_max_lt by (simp add: min.coboundedI1)\n            then have \"?r \\<le> t\" using fin_max_lt t by auto\n            with d have \"d < t\" by auto\n            then have \"d < t\" by (simp add: min.strict_coboundedI2)\n          }\n          ultimately show thesis by ((intro m[of ?d']), auto)\n        qed\n      qed\n    qed\n  qed\n  have \"DBM_val_bounded v (u(c := d')) M n\" unfolding DBM_val_bounded_def\n  proof (auto, goal_cases)\n    case 1\n    with A show ?case unfolding DBM_reset_def DBM_val_bounded_def by auto\n  next\n    case (2 c')\n    show ?case\n    proof (cases \"c = c'\")\n      case False\n      with A(2,7) have \"v c \\<noteq> v c'\" by auto\n      hence *:\"M' 0 (v c') = min (dbm_add (M 0 (v c)) (M (v c) (v c'))) (M 0 (v c'))\"\n      using A(2,3,6,7) 2 unfolding DBM_reset_def by auto\n      from 2 A(2,4) have \"dbm_entry_val u None (Some c') (M' 0 (v c'))\"\n      unfolding DBM_val_bounded_def by auto\n      with dbm_entry_dbm_min2 * have \"dbm_entry_val u None (Some c') (M 0 (v c'))\" by auto\n      thus ?thesis using False by cases auto\n    next\n      case True\n      show ?thesis\n      proof (simp add: True[symmetric], cases \"M 0 (v c)\", goal_cases)\n        case (1 t)\n        hence \"-t \\<in> S_Min_Le\" unfolding S_Min_Le by force\n        hence \"d' \\<ge> -t\" using d' by auto\n        thus ?case using 1 by (auto simp: minus_le_iff)\n      next\n        case (2 t)\n        hence \"-t \\<in> S_Min_Lt\" unfolding S_Min_Lt by force\n        hence \"d' > -t\" using d' by auto\n        thus ?case using 2 by (auto simp: minus_less_iff)\n      next\n        case 3 thus ?case by auto\n      qed\n    qed\n  next\n    case (3 c')\n    show ?case\n    proof (cases \"c = c'\")\n      case False\n      with A(2,7) have \"v c \\<noteq> v c'\" by auto\n      hence *:\"M' (v c') 0 = min (dbm_add (M (v c') (v c)) (M (v c) 0)) (M (v c') 0)\"\n      using A(2,3,6,7) 3 unfolding DBM_reset_def by auto\n      from 3 A(2,4) have \"dbm_entry_val u (Some c') None (M' (v c') 0)\"\n      unfolding DBM_val_bounded_def by auto\n      with dbm_entry_dbm_min3 * have \"dbm_entry_val u (Some c') None (M (v c') 0)\" by auto\n      thus ?thesis using False by cases auto\n    next\n      case True\n      show ?thesis\n      proof (simp add: True[symmetric], cases \"M (v c) 0\", goal_cases)\n        case (1 t)\n        hence \"t \\<in> S_Max_Le\" unfolding S_Max_Le by force\n        hence \"d' \\<le> t\" using d' by auto\n        thus ?case using 1 by (auto simp: minus_le_iff)\n      next\n        case (2 t)\n        hence \"t \\<in> S_Max_Lt\" unfolding S_Max_Lt by force\n        hence \"d' < t\" using d' by auto\n        thus ?case using 2 by (auto simp: minus_less_iff)\n      next\n        case 3 thus ?case by auto\n      qed\n    qed\n  next\n    case (4 c1 c2)\n    show ?case\n    proof (cases \"c = c1\")\n      case False\n      note F1 = this\n      show ?thesis\n      proof (cases \"c = c2\")\n        case False\n        with A(2,6,7) F1 have \"v c \\<noteq> v c1\" \"v c \\<noteq> v c2\" by auto\n        hence *:\"M' (v c1) (v c2) = min (dbm_add (M (v c1) (v c)) (M (v c) (v c2))) (M (v c1) (v c2))\"\n        using A(2,3,6,7) 4 unfolding DBM_reset_def by auto\n        from 4 A(2,4) have \"dbm_entry_val u (Some c1) (Some c2) (M' (v c1) (v c2))\"\n        unfolding DBM_val_bounded_def by auto\n        with dbm_entry_dbm_min * have \"dbm_entry_val u (Some c1) (Some c2) (M (v c1) (v c2))\" by auto\n        thus ?thesis using F1 False by cases auto\n      next\n        case True\n        show ?thesis\n        proof (simp add: True[symmetric], cases \"M (v c1) (v c)\", goal_cases)\n          case (1 t)\n          hence \"u c1 - t \\<in> S_Min_Le\" unfolding S_Min_Le using A F1 4 by blast\n          hence \"d' \\<ge> u c1 - t\" using d' by auto\n          hence \"t + d' \\<ge> u c1\" by (metis le_swap add_le_cancel_right diff_add_cancel)\n          hence \"u c1 - d' \\<le> t\" by (metis add_le_imp_le_right diff_add_cancel)\n          thus ?case using 1 F1 by auto\n        next\n          case (2 t)\n          hence \"u c1 - t \\<in> S_Min_Lt\" unfolding S_Min_Lt using A 4 F1 by blast\n          hence \"d' > u c1 - t\" using d' by auto\n          hence \"d' + t > u c1\" by (metis add_strict_right_mono diff_add_cancel)\n          hence \"u c1 - d' < t\" by (metis gt_swap add_less_cancel_right diff_add_cancel)\n          thus ?case using 2 F1 by auto\n        next\n          case 3 thus ?case by auto\n        qed\n      qed\n    next\n      case True\n      note T = this\n      show ?thesis\n      proof (cases \"c = c2\")\n        case False\n        show ?thesis\n        proof (cases \"M (v c) (v c2)\", goal_cases)\n          case (1 t)\n          hence \"u c2 + t \\<in> S_Max_Le\" unfolding S_Max_Le using A 4 False by blast\n          hence \"d' \\<le> u c2 + t\" using d' by auto\n          hence \"d' - u c2 \\<le> t\"\n          by (metis (hide_lams, no_types) add_diff_cancel_left add_ac(1) add_le_cancel_right\n              add_right_cancel diff_add_cancel)\n          thus ?case using 1 T False by auto\n        next\n          case (2 t)\n          hence \"u c2 + t \\<in> S_Max_Lt\" unfolding S_Max_Lt using A 4 False by blast\n          hence \"d' < u c2 + t\" using d' by auto\n          hence \"d' - u c2 < t\" by (metis gt_swap add_less_cancel_right diff_add_cancel)\n          thus ?case using 2 T False by force\n        next\n          case 3 thus ?case using T by auto\n        qed\n      next\n        case True\n        from A 4 have *:\"dbm_entry_val u'' (Some c1) (Some c1) (M (v c1) (v c1))\"\n        unfolding DBM_val_bounded_def by auto\n        show ?thesis using True T\n        proof (simp add: True T, cases \"M (v c1) (v c1)\", goal_cases)\n          case (1 t)\n          with * have \"0 \\<le> t\" by auto\n          thus ?case using 1 by auto\n        next\n          case (2 t)\n          with * have \"0 < t\" by auto\n          thus ?case using 2 by auto\n        next\n          case 3 thus ?case by auto\n        qed\n      qed\n    qed\n  qed\n  thus ?thesis using A(1) by blast\nqed\n\nlemma DBM_reset_sound2:\n  assumes \"v c \\<le> n\" \"DBM_reset M n (v c) d M'\" \"DBM_val_bounded v u M' n\"\n  shows \"u c = d\"\nusing assms unfolding DBM_val_bounded_def DBM_reset_def\nby fastforce\n\nlemma DBM_reset_sound'':\n  fixes M v c n d\n  defines \"M' \\<equiv> reset M n (v c) d\"\n  assumes \"clock_numbering' v n\" \"v c \\<le> n\" \"DBM_val_bounded v u M' n\"\n          \"DBM_val_bounded v u'' M n\"\n  obtains d' where  \"DBM_val_bounded v (u(c := d')) M n\"\nproof -\n  assume A:\"\\<And>d'. DBM_val_bounded v (u(c := d')) M n \\<Longrightarrow> thesis\"\n  from assms DBM_reset_reset[of \"v c\" n M d]\n  have *:\"DBM_reset M n (v c) d M'\" by (auto simp add: M'_def)\n  with DBM_reset_sound'[of v n c M d M', OF _ _ this] assms obtain d' where\n  \"DBM_val_bounded v (u(c := d')) M n\" by auto\n  with A show thesis by auto\nqed\n\nlemma DBM_reset_sound:\n  fixes M v c n d\n  defines \"M' \\<equiv> reset M n (v c) d\"\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering' v n\" \"v c \\<le> n\"\n          \"u \\<in> [M']\\<^bsub>v,n\\<^esub>\"\n  obtains d' where  \"u(c := d') \\<in>[M]\\<^bsub>v,n\\<^esub>\"\nproof (cases \"[M]\\<^bsub>v,n\\<^esub> = {}\")\n  case False\n  then obtain u' where \"DBM_val_bounded v u' M n\" unfolding DBM_zone_repr_def by auto\n  from DBM_reset_sound''[OF assms(3-4) _ this] assms(1,5) that show ?thesis\n  unfolding DBM_zone_repr_def by auto\nnext\n  case True\n  with DBM_reset_complete_empty'[OF assms(2) _ _ DBM_reset_reset, of \"v c\" M u d] assms show ?thesis\n  unfolding DBM_zone_repr_def by simp\nqed\n\nlemma DBM_reset'_complete':\n  assumes \"DBM_val_bounded v u M n\" \"clock_numbering' v n\" \"\\<forall> c \\<in> set cs. v c \\<le> n\"\n  shows \"\\<exists> u'. DBM_val_bounded v u' (reset' M n cs v d) n\"\nusing assms\nproof (induction cs)\n  case Nil thus ?case by auto\nnext\n  case (Cons c cs)\n  let ?M' = \"reset' M n cs v d\"\n  let ?M'' = \"reset ?M' n (v c) d\"\n  from Cons obtain u' where u': \"DBM_val_bounded v u' ?M' n\" by fastforce\n  from Cons(3,4) have \"0 < v c\" \"v c \\<le> n\" by auto\n  from DBM_reset_reset[OF this] have **: \"DBM_reset ?M' n (v c) d ?M''\" by fast\n  from Cons(4) have \"v c \\<le> n\" by auto\n  from DBM_reset_complete[of v n c ?M' d ?M'', OF Cons(3) this ** u']\n  have \"DBM_val_bounded v (u'(c := d)) (reset (reset' M n cs v d) n (v c) d) n\" by fast\n  thus ?case by auto\nqed\n\nlemma DBM_reset'_complete:\n  assumes \"DBM_val_bounded v u M n\" \"clock_numbering' v n\" \"\\<forall> c \\<in> set cs. v c \\<le> n\"\n  shows \"DBM_val_bounded v ([cs \\<rightarrow> d]u) (reset' M n cs v d) n\"\nusing assms\nproof (induction cs)\n  case Nil thus ?case by auto\nnext\n  case (Cons c cs)\n  let ?M' = \"reset' M n cs v d\"\n  let ?M'' = \"reset ?M' n (v c) d\"\n  from Cons have *: \"DBM_val_bounded v ([cs\\<rightarrow>d]u) (reset' M n cs v d) n\" by fastforce\n  from Cons(3,4) have \"0 < v c\" \"v c \\<le> n\" by auto\n  from DBM_reset_reset[OF this] have **: \"DBM_reset ?M' n (v c) d ?M''\" by fast\n  from Cons(4) have \"v c \\<le> n\" by auto\n  from DBM_reset_complete[of v n c ?M' d ?M'', OF Cons(3) this ** *]\n  have ***:\"DBM_val_bounded v ([c#cs\\<rightarrow>d]u) (reset (reset' M n cs v d) n (v c) d) n\" by simp\n  have \"reset' M n (c#cs) v d = reset (reset' M n cs v d) n (v c) d\" by auto\n  with *** show ?case by presburger\nqed\n\nlemma DBM_reset'_sound_empty:\n  assumes \"clock_numbering' v n\" \"\\<forall>c \\<in> set cs. v c \\<le> n\"\n          \"\\<forall> u . \\<not> DBM_val_bounded v u (reset' M n cs v d) n\"\n  shows \"\\<not> DBM_val_bounded v u M n\"\nusing assms DBM_reset'_complete by metis\n\nfun set_clocks :: \"'c list \\<Rightarrow> 't::time list\\<Rightarrow> ('c,'t) cval \\<Rightarrow> ('c,'t) cval\"\nwhere\n  \"set_clocks [] _ u = u\" |\n  \"set_clocks _ [] u = u\" |\n  \"set_clocks (c#cs) (t#ts) u = (set_clocks cs ts (u(c:=t)))\"\n\nlemma DBM_reset'_sound':\n  fixes M v c n d cs\n  assumes \"clock_numbering' v n\" \"\\<forall> c \\<in> set cs. v c \\<le> n\"\n          \"DBM_val_bounded v u (reset' M n cs v d) n\" \"DBM_val_bounded v u'' M n\"\n  shows \"\\<exists>ts. DBM_val_bounded v (set_clocks cs ts u) M n\"\nusing assms\nproof (induction cs arbitrary: M u)\n  case Nil\n  hence \"DBM_val_bounded v (set_clocks [] [] u) M n\" by auto\n  thus ?case by blast\nnext\n  case (Cons c' cs)\n  let ?M' = \"reset' M n (c' # cs) v d\"\n  let ?M'' = \"reset' M n cs v d\"\n  from DBM_reset'_complete[OF Cons(5) Cons(2)] Cons(3)\n  have u'': \"DBM_val_bounded v ([cs\\<rightarrow>d]u'') ?M'' n\" by fastforce\n  from Cons(3,4) have \"v c' \\<le> n\" \"DBM_val_bounded v u (reset ?M'' n (v c') d) n\" by auto\n  from DBM_reset_sound''[OF Cons(2) this u'']\n  obtain d' where **:\"DBM_val_bounded v (u(c' := d')) ?M'' n\" by blast\n  from Cons.IH[OF Cons.prems(1) _ ** Cons.prems(4)] Cons.prems(2)\n  obtain ts where ts:\"DBM_val_bounded v (set_clocks cs ts (u(c' := d'))) M n\" by fastforce\n  hence \"DBM_val_bounded v (set_clocks (c' # cs) (d'#ts) u) M n\" by auto\n  thus ?case by fast\nqed\n\nlemma DBM_reset'_resets:\n  fixes M v c n d cs\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering' v n\" \"\\<forall> c \\<in> set cs. v c \\<le> n\"\n          \"DBM_val_bounded v u (reset' M n cs v d) n\"\n  shows \"\\<forall>c \\<in> set cs. u c = d\"\nusing assms\nproof (induction cs arbitrary: M u)\n  case Nil thus ?case by auto\nnext\n  case (Cons c' cs)\n  let ?M' = \"reset' M n (c' # cs) v d\"\n  let ?M'' = \"reset' M n cs v d\"\n  from Cons(4,5) have \"v c' \\<le> n\" \"DBM_val_bounded v u (reset ?M'' n (v c') d) n\" by auto\n  from DBM_reset_sound2[OF this(1) _ Cons(5), of ?M'' d] DBM_reset_reset[OF _ this(1), of ?M'' d] Cons(3)\n  have c':\"u c' = d\" by auto\n  from Cons(4,5) have \"v c' \\<le> n\" \"DBM_val_bounded v u (reset ?M'' n (v c') d) n\" by auto\n  with DBM_reset_sound[OF Cons.prems(1,2) this(1)]\n  obtain d' where **:\"DBM_val_bounded v (u(c' := d')) ?M'' n\" unfolding DBM_zone_repr_def by blast\n  from Cons.IH[OF Cons.prems(1,2) _ **] Cons.prems(3) have \"\\<forall>c\\<in>set cs. (u(c' := d')) c = d\" by auto\n  thus ?case using c'\n   apply safe\n   apply (rename_tac c)\n   apply (case_tac \"c = c'\")\n  by auto\nqed\n\nlemma DBM_reset'_resets':\n  fixes M :: \"('t :: time) DBM\" and v c n d cs\n  assumes \"clock_numbering' v n\" \"\\<forall> c \\<in> set cs. v c \\<le> n\" \"DBM_val_bounded v u (reset' M n cs v d) n\"\n          \"DBM_val_bounded v u'' M n\"\n  shows \"\\<forall>c \\<in> set cs. u c = d\"\nusing assms\nproof (induction cs arbitrary: M u)\n  case Nil thus ?case by auto\nnext\n  case (Cons c' cs)\n  let ?M' = \"reset' M n (c' # cs) v d\"\n  let ?M'' = \"reset' M n cs v d\"\n  from DBM_reset'_complete[OF Cons(5) Cons(2)] Cons(3)\n  have u'': \"DBM_val_bounded v ([cs\\<rightarrow>d]u'') ?M'' n\" by fastforce\n  from Cons(3,4) have \"v c' \\<le> n\" \"DBM_val_bounded v u (reset ?M'' n (v c') d) n\" by auto\n  from DBM_reset_sound2[OF this(1) _ Cons(4), of ?M'' d] DBM_reset_reset[OF _ this(1), of ?M'' d] Cons(2)\n  have c':\"u c' = d\" by auto\n  from Cons(3,4) have \"v c' \\<le> n\" \"DBM_val_bounded v u (reset ?M'' n (v c') d) n\" by auto\n  from DBM_reset_sound''[OF Cons(2) this u'']\n  obtain d' where **:\"DBM_val_bounded v (u(c' := d')) ?M'' n\" by blast\n  from Cons.IH[OF Cons.prems(1) _ ** Cons.prems(4)] Cons.prems(2)\n  have \"\\<forall>c\\<in>set cs. (u(c' := d')) c = d\" by auto\n  thus ?case using c'\n   apply safe\n   apply (rename_tac c)\n   apply (case_tac \"c = c'\")\n  by auto\nqed\n\nlemma DBM_reset'_neg_diag_preservation':\n  fixes M :: \"('t :: time) DBM\"\n  assumes \"k\\<le>n\" \"M k k < 0\" \"clock_numbering v\" \"\\<forall> c \\<in> set cs. v c \\<le> n\"\n  shows \"reset' M n cs v d k k < 0\" using assms\nproof (induction cs)\n  case Nil thus ?case by auto\nnext\n  case (Cons c cs)\n  then have IH: \"reset' M n cs v d k k < 0\" by auto\n  from Cons.prems have \"v c > 0\" \"v c \\<le> n\" by auto\n  from DBM_reset_reset[OF this, of \"reset' M n cs v d\" d] \\<open>k \\<le> n\\<close>\n  have \"reset (reset' M n cs v d) n (v c) d k k \\<le> reset' M n cs v d k k\" unfolding DBM_reset_def\n  by (cases \"v c = k\", simp add: less[symmetric], case_tac \"k = 0\", auto simp: less[symmetric])\n  with IH show ?case by auto\nqed\n\nlemma DBM_reset'_complete_empty':\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering' v n\"\n          \"\\<forall> c \\<in> set cs. v c \\<le> n\" \"\\<forall> u . \\<not> DBM_val_bounded v u M n\"\n  shows \"\\<forall> u . \\<not> DBM_val_bounded v u (reset' M n cs v d) n\" using assms\nproof (induction cs)\n  case Nil then show ?case by simp\nnext\n  case (Cons c cs)\n  then have \"\\<forall>u. \\<not> DBM_val_bounded v u (reset' M n cs v d) n\" by auto\n  from Cons.prems(2,3) DBM_reset_complete_empty'[OF Cons.prems(1) _ _ DBM_reset_reset this]\n  show ?case by auto\nqed\n\nlemma DBM_reset'_complete_empty:\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering' v n\"\n          \"\\<forall> c \\<in> set cs. v c \\<le> n\" \"\\<forall> u . \\<not> DBM_val_bounded v u M n\"\n  shows \"\\<forall> u . \\<not> DBM_val_bounded v u (reset' (FW M n) n cs v d) n\" using assms\nproof -\n  note A = assms\n  from A(4) have \"[M]\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\n  with FW_zone_equiv[OF A(1)] have \"[FW M n]\\<^bsub>v,n\\<^esub> = {}\" by auto\n  with FW_detects_empty_zone[OF A(1)] A(2) obtain i where i: \"i \\<le> n\" \"FW M n i i < Le 0\" by blast\n  with DBM_reset'_neg_diag_preservation' A(2,3) have\n    \"reset' (FW M n) n cs v d i i < Le 0\"\n  by (auto simp: neutral)\n  with fw_mono[of i n i \"reset' (FW M n) n cs v d\" n] i\n  have \"FW (reset' (FW M n) n cs v d) n i i < Le 0\" by auto\n  with FW_detects_empty_zone[OF A(1), of \"reset' (FW M n) n cs v d\"] A(2,3) i\n  have \"[FW (reset' (FW M n) n cs v d) n]\\<^bsub>v,n\\<^esub> = {}\" by auto\n  with FW_zone_equiv[OF A(1), of \"reset' (FW M n) n cs v d\"] A(3,4)\n  show ?thesis by (auto simp: DBM_zone_repr_def)\nqed\n\nlemma DBM_reset'_empty':\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering' v n\" \"\\<forall> c \\<in> set cs. v c \\<le> n\"\n  shows \"[M]\\<^bsub>v,n\\<^esub> = {} \\<longleftrightarrow> [reset' (FW M n) n cs v d]\\<^bsub>v,n\\<^esub> = {}\"\nproof\n  let ?M' = \"reset' (FW M n) n cs v d\"\n  assume A: \"[M]\\<^bsub>v,n\\<^esub> = {}\"\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u M n\" unfolding DBM_zone_repr_def by auto\n  with DBM_reset'_complete_empty[OF assms] show \"[?M']\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\nnext\n  let ?M' = \"reset' (FW M n) n cs v d\"\n  assume A: \"[?M']\\<^bsub>v,n\\<^esub> = {}\"\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u ?M' n\" unfolding DBM_zone_repr_def by auto\n  from DBM_reset'_sound_empty[OF assms(2,3) this] have \"\\<forall> u. \\<not> DBM_val_bounded v u (FW M n) n\" by auto\n  with FW_zone_equiv[OF assms(1)] show \"[M]\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\nqed\n\nlemma DBM_reset'_empty:\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering' v n\" \"\\<forall> c \\<in> set cs. v c \\<le> n\"\n  shows \"[M]\\<^bsub>v,n\\<^esub> = {} \\<longleftrightarrow> [reset' M n cs v d]\\<^bsub>v,n\\<^esub> = {}\"\nproof\n  let ?M' = \"reset' M n cs v d\"\n  assume A: \"[M]\\<^bsub>v,n\\<^esub> = {}\"\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u M n\" unfolding DBM_zone_repr_def by auto\n  with DBM_reset'_complete_empty'[OF assms] show \"[?M']\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\nnext\n  let ?M' = \"reset' M n cs v d\"\n  assume A: \"[?M']\\<^bsub>v,n\\<^esub> = {}\"\n  hence \"\\<forall> u . \\<not> DBM_val_bounded v u ?M' n\" unfolding DBM_zone_repr_def by auto\n  from DBM_reset'_sound_empty[OF assms(2,3) this] have \"\\<forall> u. \\<not> DBM_val_bounded v u M n\" by auto\n  with FW_zone_equiv[OF assms(1)] show \"[M]\\<^bsub>v,n\\<^esub> = {}\" unfolding DBM_zone_repr_def by auto\nqed\n\nlemma DBM_reset'_sound:\n  assumes \"\\<forall>k\\<le>n. k > 0 \\<longrightarrow> (\\<exists>c. v c = k)\" \"clock_numbering' v n\"\n    and \"\\<forall>c\\<in>set cs. v c \\<le> n\"\n    and \"u \\<in> [reset' M n cs v d]\\<^bsub>v,n\\<^esub>\"\n  shows \"\\<exists>ts. set_clocks cs ts u \\<in> [M]\\<^bsub>v,n\\<^esub>\"\nproof -\n  from DBM_reset'_empty[OF assms(1-3)] assms(4) obtain u' where \"u' \\<in> [M]\\<^bsub>v,n\\<^esub>\" by blast\n  with DBM_reset'_sound'[OF assms(2,3)] assms(4) show ?thesis unfolding DBM_zone_repr_def by blast\nqed\n\nsection \\<open>Misc Preservation Lemmas\\<close>\n\nlemma get_const_sum[simp]:\n  \"a \\<noteq> \\<infinity> \\<Longrightarrow> b \\<noteq> \\<infinity> \\<Longrightarrow> get_const a \\<in> \\<int> \\<Longrightarrow> get_const b \\<in> \\<int> \\<Longrightarrow> get_const (a + b) \\<in> \\<int>\"\nby (cases a) (cases b, auto simp: add)+\n\nlemma sum_not_inf_dest:\n  assumes \"a + b \\<noteq> (\\<infinity> :: _ DBMEntry)\"\n  shows \"a \\<noteq> (\\<infinity> :: _ DBMEntry) \\<and> b \\<noteq> (\\<infinity> :: _ DBMEntry)\"\nusing assms by (cases a; cases b; simp add: add)\n\nlemma sum_not_inf_int:\n  assumes \"a + b \\<noteq> (\\<infinity> :: _ DBMEntry)\" \"get_const a \\<in> \\<int>\" \"get_const b \\<in> \\<int>\"\n  shows \"get_const (a + b) \\<in> \\<int>\"\nusing assms sum_not_inf_dest by fastforce\n\nlemma int_fw_upd:\n  \"\\<forall> i \\<le> n. \\<forall> j \\<le> n. m i j \\<noteq> \\<infinity> \\<longrightarrow> get_const (m i j) \\<in> \\<int> \\<Longrightarrow> k \\<le> n \\<Longrightarrow> i \\<le> n \\<Longrightarrow> j \\<le> n\n  \\<Longrightarrow> i' \\<le> n \\<Longrightarrow> j' \\<le> n \\<Longrightarrow> (fw_upd m k i j i' j') \\<noteq> \\<infinity>\n  \\<Longrightarrow> get_const (fw_upd m k i j i' j') \\<in> \\<int>\"\nproof (goal_cases)\n  case 1\n  show ?thesis\n  proof (cases \"i = i' \\<and> j = j'\")\n    case True\n    with 1 show ?thesis by (fastforce simp: fw_upd_def upd_def min_def dest: sum_not_inf_dest)\n  next\n    case False\n    with 1 show ?thesis by (auto simp : fw_upd_def upd_def)\n  qed\nqed\n\nabbreviation \"dbm_int M n \\<equiv> \\<forall> i\\<le>n. \\<forall> j\\<le>n. M i j \\<noteq> \\<infinity> \\<longrightarrow> get_const (M i j) \\<in> \\<int>\"\n\nabbreviation \"dbm_int_all M \\<equiv> \\<forall> i. \\<forall> j. M i j \\<noteq> \\<infinity> \\<longrightarrow> get_const (M i j) \\<in> \\<int>\"\n\nlemma dbm_intI:\n  \"dbm_int_all M \\<Longrightarrow> dbm_int M n\"\nby auto\n\nlemma fwi_int_preservation:\n  \"dbm_int (fwi M n k i j) n\" if \"dbm_int M n\" \"k \\<le> n\"\n  apply (induction _ \"(i, j)\" arbitrary: i j rule: wf_induct[of \"less_than <*lex*> less_than\"])\n   apply (auto; fail)\n  subgoal for i j\n    using that\n    by (cases i; cases j) (auto 4 3 dest: sum_not_inf_dest simp:  min_def fw_upd_def upd_def)\n  done\n\nlemma fw_int_preservation:\n  \"dbm_int (fw M n k) n\" if \"dbm_int M n\" \"k \\<le> n\"\n  using \\<open>k \\<le> n\\<close> apply (induction k)\n  using that apply simp\n   apply (rule fwi_int_preservation; auto; fail)\n  using that by (simp) (rule fwi_int_preservation; auto)\n\nlemma FW_int_preservation:\n  assumes \"dbm_int M n\"\n  shows \"dbm_int (FW M n) n\"\n  using fw_int_preservation[OF assms(1)] by auto\n\nlemma FW_int_all_preservation:\n  assumes \"dbm_int_all M\"\n  shows \"dbm_int_all (FW M n)\"\nusing assms\n apply clarify\n subgoal for i j\n apply (cases \"i \\<le> n\")\n apply (cases \"j \\<le> n\")\n by (auto simp: FW_int_preservation[OF dbm_intI[OF assms(1)]] FW_out_of_bounds1 FW_out_of_bounds2)\ndone\n\nlemma And_int_all_preservation[intro]:\n  assumes \"dbm_int_all M1\" \"dbm_int_all M2\"\n  shows \"dbm_int_all (And M1 M2)\"\nusing assms by (auto simp: min_def)\n\nlemma And_int_preservation:\n  assumes \"dbm_int M1 n\" \"dbm_int M2 n\"\n  shows \"dbm_int (And M1 M2) n\"\nusing assms by (auto simp: min_def)\n\nlemma up_int_all_preservation:\n  \"dbm_int_all (M :: (('t :: {time, ring_1}) DBM)) \\<Longrightarrow> dbm_int_all (up M)\"\nunfolding up_def min_def\n apply safe\n apply (case_tac \"i = 0\")\n  apply fastforce\n apply (case_tac \"j = 0\")\n  apply fastforce\n apply auto\nunfolding add[symmetric] by (auto dest: sum_not_inf_dest)\n\nlemma up_int_preservation:\n  \"dbm_int (M :: (('t :: {time, ring_1}) DBM)) n \\<Longrightarrow> dbm_int (up M) n\"\nunfolding up_def min_def\n apply safe\n apply (case_tac \"i = 0\")\n  apply fastforce\n apply (case_tac \"j = 0\")\n  apply fastforce\n apply auto\nunfolding add[symmetric] by (auto dest: sum_not_inf_dest)\n\n(* Definitely a candidate for cleaning *)\nlemma DBM_reset_int_preservation':\n  assumes \"dbm_int M n\" \"DBM_reset M n k d M'\" \"d \\<in> \\<int>\" \"k \\<le> n\"\n  shows \"dbm_int M' n\"\nproof clarify\n  fix i j\n  assume A: \"i \\<le> n\" \"j \\<le> n\" \"M' i j \\<noteq> \\<infinity>\"\n  from assms(2) show \"get_const (M' i j) \\<in> \\<int>\" unfolding DBM_reset_def\n    apply (cases \"i = k\"; cases \"j = k\")\n      apply simp\n      using A assms(1,4) apply presburger\n     apply (cases \"j = 0\")\n      using assms(3) apply simp\n     using A apply simp\n    apply simp\n    apply (cases \"i = 0\")\n      using assms(3) apply simp\n     using A apply simp\n    using A apply simp\n    apply (simp split: split_min, safe)\n    subgoal\n    proof goal_cases\n      case 1\n      then have *: \"M i k + M k j \\<noteq> \\<infinity>\" unfolding add min_def by meson\n      with sum_not_inf_dest have \"M i k \\<noteq> \\<infinity>\" \"M k j \\<noteq> \\<infinity>\" by auto\n      with 1(3,4) assms(1,4) have \"get_const (M i k) \\<in> \\<int>\" \"get_const (M k j) \\<in> \\<int>\" by auto\n      with sum_not_inf_int[folded add, OF *] show ?case unfolding add by auto\n    qed\n    subgoal\n    proof goal_cases\n      case 1\n      then have *: \"M i j \\<noteq> \\<infinity>\" unfolding add min_def by meson\n      with 1(3,4) assms(1,4) show ?case by auto\n    qed\n  done\nqed\n\nlemma DBM_reset_int_preservation:\n  fixes M :: \"('t :: {time,ring_1}) DBM\"\n  assumes \"dbm_int M n\" \"d \\<in> \\<int>\" \"0 < k\" \"k \\<le> n\"\n  shows \"dbm_int (reset M n k d) n\"\nusing assms(3-) DBM_reset_int_preservation'[OF assms(1) DBM_reset_reset assms(2)] by blast\n\nlemma DBM_reset_int_all_preservation:\n  fixes M :: \"('t :: {time,ring_1}) DBM\"\n  assumes \"dbm_int_all M\" \"d \\<in> \\<int>\"\n  shows \"dbm_int_all (reset M n k d)\"\nusing assms\n apply clarify\n subgoal for i j\n   by (cases \"i = k\"; cases \"j = k\";\n       auto simp: reset_def min_def add[symmetric] dest!: sum_not_inf_dest\n       )\ndone\n\nlemma DBM_reset'_int_all_preservation:\n  fixes M :: \"('t :: {time, ring_1}) DBM\"\n  assumes \"dbm_int_all M\" \"d \\<in> \\<int>\"\n  shows \"dbm_int_all (reset' M n cs v d)\" using assms\nby (induction cs) (simp | rule DBM_reset_int_all_preservation)+\n\nlemma DBM_reset'_int_preservation:\n  fixes M :: \"('t :: {time, ring_1}) DBM\"\n  assumes \"dbm_int M n\" \"d \\<in> \\<int>\" \"\\<forall>c. v c > 0\" \"\\<forall> c \\<in> set cs. v c \\<le> n\"\n  shows \"dbm_int (reset' M n cs v d) n\" using assms\nproof (induction cs)\n  case Nil then show ?case by simp\nnext\n  case (Cons c cs)\n  from Cons.IH[OF Cons.prems(1,2,3)] Cons.prems(4) have \"dbm_int (reset' M n cs v d) n\"\n    by fastforce\n  from DBM_reset_int_preservation[OF this Cons.prems(2), of \"v c\"] Cons.prems(3,4) show ?case\n    by auto\nqed\n\nlemma reset_set1:\n  \"\\<forall>c \\<in> set cs. ([cs\\<rightarrow>d]u) c = d\"\nby (induction cs) auto\n\nlemma reset_set11:\n  \"\\<forall>c. c \\<notin> set cs \\<longrightarrow> ([cs\\<rightarrow>d]u) c = u c\"\nby (induction cs) auto\n\nlemma reset_set2:\n  \"\\<forall>c. c \\<notin> set cs \\<longrightarrow> (set_clocks cs ts u)c = u c\"\nproof (induction cs arbitrary: ts u)\n  case Nil then show ?case by auto\nnext\n  case Cons then show ?case\n  proof (cases ts, goal_cases)\n   case Nil then show ?thesis by simp\n  next\n    case (2 a') then show ?case by auto\n  qed\nqed\n\nlemma reset_set:\n  assumes \"\\<forall> c \\<in> set cs. u c = d\"\n  shows \"[cs\\<rightarrow>d](set_clocks cs ts u) = u\"\nproof\n  fix c\n  show \"([cs\\<rightarrow>d]set_clocks cs ts u) c = u c\"\n  proof (cases \"c \\<in> set cs\")\n    case True\n    hence \"([cs\\<rightarrow>d]set_clocks cs ts u) c = d\" using reset_set1 by fast\n    also have \"d = u c\" using assms True by auto\n    finally show ?thesis by auto\n  next\n    case False\n    hence \"([cs\\<rightarrow>d]set_clocks cs ts u) c = set_clocks cs ts u c\" by (simp add: reset_set11)\n    also  with False have \"\\<dots> = u c\" by (simp add: reset_set2)\n    finally show ?thesis by auto\n  qed\nqed\n\n\nsubsection \\<open>Unused theorems\\<close>\n\n\n\nlemma canonical_cyc_free2:\n  \"canonical M n \\<Longrightarrow> cyc_free M n \\<longleftrightarrow> (\\<forall>i \\<le> n. M i i \\<ge> 0)\"\n apply safe\n  apply (simp add: cyc_free_diag_dest')\nusing canonical_cyc_free by blast\n\nlemma DBM_reset'_diag_preservation:\n  fixes M :: \"('t :: time) DBM\"\n  assumes \"\\<forall>k\\<le>n. M k k \\<le> 0\" \"clock_numbering v\" \"\\<forall> c \\<in> set cs. v c \\<le> n\"\n  shows \"\\<forall>k\\<le>n. reset' M n cs v d k k \\<le> 0\" using assms\nproof (induction cs)\n  case Nil thus ?case by auto\nnext\n  case (Cons c cs)\n  then have IH: \"\\<forall>k\\<le>n. reset' M n cs v d k k \\<le> 0\" by auto\n  from Cons.prems have \"v c > 0\" \"v c \\<le> n\" by auto\n  from DBM_reset_diag_preservation[of n \"reset' M n cs v d\", OF IH DBM_reset_reset, of \"v c\", OF this]\n  show ?case by simp\nqed\n\nend\n", "meta": {"author": "wimmers", "repo": "munta", "sha": "62cb1a4a4dbcfcf62c365e90faba15b0012d5a12", "save_path": "github-repos/isabelle/wimmers-munta", "path": "github-repos/isabelle/wimmers-munta/munta-62cb1a4a4dbcfcf62c365e90faba15b0012d5a12/DBM/DBM_Operations.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.25660250401956225}}
{"text": "theory LaunchburyAddBH\nimports LaunchburyCombinedTaggedMap\nbegin                     \n\nnominal_primrec varOf :: \"exp \\<Rightarrow> var option\" where\n  \"varOf (Var x) = Some x\" |\n  \"varOf (Lam [_]. _) = None\" |\n  \"varOf (App e x) = None\" |\n  \"varOf (Let as body) = None\"\n  unfolding eqvt_def varOf_graph_aux_def\n  apply (rule)\n  apply simp_all\n  apply (metis exp_assn.exhaust(1))\n  done\ntermination (eqvt) by lexicographic_order\n\nnominal_primrec dep :: \"exp \\<Rightarrow> var option\" where\n  \"dep (Var x) = Some x\" |\n  \"dep (App e y) = varOf e\" |\n  \"dep (Lam [_]. _) = None\" |\n  \"dep (Let as body) = None\"\n  unfolding eqvt_def dep_graph_aux_def\n  apply (rule)\n  apply simp_all\n  apply (metis exp_assn.exhaust(1))\n  done\ntermination (eqvt) by lexicographic_order\n\nlemma isLam_dep[simp]: \"isLam e \\<Longrightarrow> dep e = None\"\n  by (cases e rule: exp_assn.exhaust(1)) auto\n\nfun depRel :: \"Heap \\<Rightarrow> var \\<Rightarrow> var \\<Rightarrow> bool\" where\n  \"depRel \\<Gamma> x y \\<longleftrightarrow> Option.bind (lookup \\<Gamma> x) dep = Some y\"\n\nlemma depRel_cong':\n  \"lookup \\<Delta> a = lookup \\<Gamma> a \\<Longrightarrow> depRel \\<Gamma> a b \\<Longrightarrow> depRel \\<Delta> a b\"\n  by auto\n\nlemma depRel_cong:\n  \"lookup \\<Gamma> a = lookup \\<Delta> a \\<Longrightarrow> depRel \\<Gamma> a b = depRel \\<Delta> a b\"\n  by auto\n\nlemma depRel_fmap_upd[simp]: \"depRel (\\<Gamma>(x f\\<mapsto>  e)) x y \\<longleftrightarrow> dep e = Some y\"\n  by auto\n\nlemma depRel_fmap_upd_Not[simp]: \"a \\<noteq> x \\<Longrightarrow> depRel (\\<Gamma>(x f\\<mapsto> e)) a b \\<longleftrightarrow> depRel \\<Gamma> a b\"\n  by simp\n\nlemma depRel_dom: \"depRel \\<Gamma> y x \\<Longrightarrow> y \\<in> fdom \\<Gamma>\"\n  by (metis depRel.simps bind_lzero fdomIff option.distinct(1))\n\nlemma depRelTransDom:\n  \"(depRel \\<Gamma>)\\<^sup>+\\<^sup>+ a b \\<Longrightarrow> a \\<in> fdom \\<Gamma>\"\n  by (metis (full_types) depRel_dom tranclpD)\n\nlemma depRel_fmap_upd_trans[simp]: \"lookup \\<Gamma> x = Some e \\<Longrightarrow> dep e = None \\<Longrightarrow> (depRel \\<Gamma>)\\<^sup>+\\<^sup>+ x y \\<longleftrightarrow> False\"\n  by (auto elim: tranclp_induct)\n\ndefinition cycle where \"cycle \\<Gamma> x \\<longleftrightarrow> (depRel \\<Gamma>)\\<^sup>+\\<^sup>+ x x\"\n\nlemma lookup_eq_split: \"lookup (f(a f\\<mapsto> b)) x = Some r \\<longleftrightarrow> ((x = a \\<and> r = b) \\<or> (x \\<noteq> a \\<and> lookup f x = Some r))\"\n  by transfer auto\n\nlemma varOf_Some[dest!]: \"varOf e = Some b \\<Longrightarrow> e = Var b\"\n  by (cases e rule:exp_assn.exhaust(1)) auto\n\nlemma depRelAppE:\n  \"depRel (\\<Gamma>(x f\\<mapsto> App e y)) a b \\<Longrightarrow> x = a \\<and> e = Var b \\<or> x \\<noteq> a \\<and> depRel \\<Gamma> a b\"\n  by (cases \"x=a\") auto\n\nlemma depRelTransIndirect: \n  assumes \"(depRel (\\<Gamma>(x f\\<mapsto> App e y)))\\<^sup>+\\<^sup>+ a b\"\n  assumes \"atom n \\<sharp> \\<Gamma>(x f\\<mapsto> App e y)\"\n  shows \"(depRel (\\<Gamma>(x f\\<mapsto> App (Var n) y)(n f\\<mapsto> e)))\\<^sup>+\\<^sup>+  a b\"\nusing assms\nproof (induction rule:tranclp_trans_induct[consumes 1, case_names base step])\n  case (base a b)\n  note depRel_dom[OF `depRel (\\<Gamma>(x f\\<mapsto> App e y)) a b`]\n  with `atom n \\<sharp> \\<Gamma>(x f\\<mapsto> App e y)`\n  have \"n \\<noteq> a\"  by (metis fresh_fdom)\n\n  from depRelAppE[OF base(1)]\n  show ?case\n  proof(elim conjE disjE)\n    assume \"x = a\" and \"e = Var b\"\n\n    have \"(depRel (\\<Gamma>(a f\\<mapsto> App (Var n) y)(n f\\<mapsto> Var b)))\\<^sup>+\\<^sup>+ a n\" using `n \\<noteq> a` by auto\n    also\n    have \"(depRel (\\<Gamma>(a f\\<mapsto> App (Var n) y)(n f\\<mapsto> Var b)))\\<^sup>+\\<^sup>+ n b\" by auto\n    finally\n    show ?thesis unfolding `x = a` `e = Var b`.\n  next\n    assume \"x \\<noteq> a \" and \"depRel \\<Gamma> a b\"  thus ?thesis using `n \\<noteq> a` by auto\n  qed\n  next\n  case (step a b c)\n    thus ?case by auto\nqed\n\nlemma cycleIndirect: \n  assumes \"cycle (\\<Gamma>(x f\\<mapsto> App e y)) z\"\n  assumes \"atom n \\<sharp> \\<Gamma>(x f\\<mapsto> App e y)\"\n  shows \"cycle (\\<Gamma>(x f\\<mapsto> App (Var n) y)(n f\\<mapsto> e)) z\"\nby (metis depRelTransIndirect cycle_def assms)\n\ninductive validStack :: \"Heap \\<Rightarrow> var \\<Rightarrow> var list \\<Rightarrow> bool\"\n  for \\<Gamma> where\n    ValidStackNil: \"validStack \\<Gamma> x []\"\n  | ValidStackCons: \"(depRel \\<Gamma>)\\<^sup>+\\<^sup>+ y x \\<Longrightarrow> validStack \\<Gamma> y S \\<Longrightarrow> validStack \\<Gamma> x (y#S)\"\n\nlemma validStackIndirect:\n  \"validStack (\\<Gamma>(x f\\<mapsto> App e y)) z S \\<Longrightarrow> atom n \\<sharp> \\<Gamma>(x f\\<mapsto> App e y) \\<Longrightarrow>\n  validStack (\\<Gamma>(x f\\<mapsto> App (Var n) y)(n f\\<mapsto> e)) z S\"\nby (induction z S rule:validStack.induct)\n   (auto intro: ValidStackNil ValidStackCons depRelTransIndirect)\n\nlemma depRel_unique:\n  \"depRel \\<Gamma> a b \\<Longrightarrow> depRel \\<Gamma> a c \\<Longrightarrow> b = c\"\n  by (auto elim!: depRel.cases)\n\nlemma validStack_to_top:\n  \"validStack \\<Gamma> x S \\<Longrightarrow> y \\<in> set S \\<Longrightarrow> (depRel \\<Gamma>)\\<^sup>+\\<^sup>+ y x\"\nby (induction x S rule:validStack.induct) auto\n\nlemma validStack_cycle:\n  \"validStack \\<Gamma> x S \\<Longrightarrow> x \\<in> set S \\<Longrightarrow> cycle \\<Gamma> x\"\nby (metis validStack_to_top cycle_def)\n\nlemma depRel_via:\n  assumes \"(depRel \\<Gamma>)\\<^sup>+\\<^sup>+ a z\"\n  assumes \"depRel \\<Gamma> a b\"\n  shows   \"b = z \\<or> (depRel \\<Gamma>)\\<^sup>+\\<^sup>+ b z\"\nusing assms\nby (induction a z rule:tranclp_trans_induct[consumes 1, case_names base step])\n   (auto dest: depRel_unique tranclp_trans)\n\nlemma validStack_cong:\n  assumes \"validStack \\<Gamma> z S\"\n  assumes cong: \"\\<And> x. (depRel \\<Gamma>)\\<^sup>+\\<^sup>+ x z \\<Longrightarrow> lookup \\<Gamma> x = lookup \\<Delta> x\"\n  shows  \"validStack \\<Delta> z S\"\nusing assms\nproof(induction z S rule:validStack.induct)\n  case (ValidStackNil y) thus ?case by (intro validStack.intros)\nnext\n  case (ValidStackCons y x S)\n  from `(depRel \\<Gamma>)\\<^sup>+\\<^sup>+ y x` ValidStackCons.prems\n  have \"(depRel \\<Delta>)\\<^sup>+\\<^sup>+ y x\"\n  proof (induction y x rule:tranclp_trans_induct[consumes 1, case_names base step])\n    case (base x' y)\n    hence \"lookup \\<Gamma> x' = lookup \\<Delta> x'\" by auto\n    with base(1)\n    have \"depRel \\<Delta> x' y\" by (simp cong: depRel_cong)\n    thus ?case by auto\n  next\n    case step thus ?case by (metis tranclp_trans)\n  qed\n  moreover\n  have \"validStack \\<Delta> y S\"\n  proof(rule ValidStackCons.IH)\n    fix x'\n    assume \"(depRel \\<Gamma>)\\<^sup>+\\<^sup>+ x' y\" with `(depRel \\<Gamma>)\\<^sup>+\\<^sup>+ y x`\n    have \"(depRel \\<Gamma>)\\<^sup>+\\<^sup>+ x' x\" by auto\n    thus \" lookup \\<Gamma> x' = lookup \\<Delta> x'\"\n      by (rule ValidStackCons)\n  qed\n  ultimately\n  show \"validStack \\<Delta> x (y # S)\"\n    by (rule validStack.intros)\nqed\n\n\nlemma cycle_depRel:\n  assumes \"cycle \\<Gamma> x\"\n  assumes \"depRel \\<Gamma> x n\"\n  shows \"cycle \\<Gamma> n\"\nby (metis assms depRel_via cycle_def tranclp.simps)\n\ntheorem\n  assumes \"\\<Gamma> \\<Down>\\<^sup>i\\<^sup>u\\<^sup>b\\<^bsub>x#S\\<^esub> \\<Delta>\"\n  assumes \"validStack \\<Gamma> x S\"\n  shows \"\\<not> cycle \\<Gamma> x\" and  \"validStack \\<Delta> x S\"\n   and add_blackholing: \"\\<Gamma> \\<Down>\\<^sup>i\\<^sup>u\\<^sup>\\<surd>\\<^bsub>x#S\\<^esub> \\<Delta>\"\n  (* The third conclusion does not need the others, but inductive proofs compose so badly. *)\nusing assms\nproof(induction \\<Gamma> i u b \"x#S\" \\<Delta> arbitrary: x S rule:reds.induct )\ncase (Lambda \\<Gamma> x y e i u b S)\n  case 1 show ?case by (auto simp add: cycle_def)\n  case 2 thus ?case .\n  case 3 show ?case using Lambda by (rule reds.Lambda)\nnext\ncase (Application n \\<Gamma> x e y S \\<Theta> z \\<Delta> e' u b)\n  case 2\n    from Application(1) have \"n \\<noteq> x\"  \"n \\<notin> set S\"\n      by (simp_all add: fresh_Pair fresh_at_base fresh_at_base_list)\n    hence \"(depRel (\\<Gamma>(x f\\<mapsto> App (Var n) y)(n f\\<mapsto> e)))\\<^sup>+\\<^sup>+ x n\" by auto\n    moreover\n    from Application(1) have \"atom n \\<sharp> \\<Gamma>(x f\\<mapsto> App e y)\"\n      by (simp add: fresh_Pair fresh_fmap_upd_eq fresh_fmap_delete_subset)\n    with `validStack (\\<Gamma>(x f\\<mapsto> App e y)) x S`\n    have \"validStack (\\<Gamma>(x f\\<mapsto> App (Var n) y)(n f\\<mapsto> e)) x S\" by (rule validStackIndirect)\n    ultimately\n    have IH1: \"validStack (\\<Gamma>(x f\\<mapsto> App (Var n) y)(n f\\<mapsto> e)) n (x # S)\"  by (rule ValidStackCons)\n    hence \"validStack \\<Delta> n (x # S)\" by (rule Application.hyps)\n    hence \"validStack \\<Delta> x S\" by (cases)\n    hence IH2: \"validStack ((fmap_delete n \\<Delta>)(x f\\<mapsto> e'[z::=y])) x S\"\n    proof(rule validStack_cong)\n      from stack_unchanged[OF Application.hyps(8)[OF IH1]] `n \\<noteq> x`\n      have \"lookup \\<Delta> x = Some (App (Var n) y)\"  by auto\n      hence \"depRel \\<Delta> x n\" by auto\n\n      fix x'\n      assume \"(depRel \\<Delta>)\\<^sup>+\\<^sup>+ x' x\"\n      moreover\n      from `lookup \\<Delta> n = Some (Lam [z]. e')`\n      have \"\\<not> (depRel \\<Delta>)\\<^sup>+\\<^sup>+ n x\" by auto\n      moreover\n      hence \"\\<not> (depRel \\<Delta>)\\<^sup>+\\<^sup>+ x x\" using `depRel \\<Delta> x n`\n        by (metis depRel_via)\n      ultimately\n      have \"x' \\<noteq> x\" \"x' \\<noteq> n\" by auto\n      thus \"lookup \\<Delta> x' = lookup (fmap_delete n \\<Delta>(x f\\<mapsto> e'[z::=y])) x'\" by simp\n    qed\n    thus \"validStack \\<Theta> x S\"\n      by (rule Application.hyps)\n  case 1\n    from Application.hyps(6)[OF IH1]\n    show ?case\n    proof(rule contrapos_nn)\n      assume \"cycle (\\<Gamma>(x f\\<mapsto> App e y)) x\"\n      hence \"cycle (\\<Gamma>(x f\\<mapsto> App (Var n) y)(n f\\<mapsto> e)) x\"\n        by (rule cycleIndirect[OF _ `atom n \\<sharp> \\<Gamma>(x f\\<mapsto> App e y)`])\n      thus \"cycle (\\<Gamma>(x f\\<mapsto> App (Var n) y)(n f\\<mapsto> e)) n\" using `n \\<noteq> x`  by (auto elim!: cycle_depRel)\n    qed\n  case 3\n    from Application.hyps(1,2,3,4)\n         Application.hyps(8)[OF IH1]\n         Application.hyps(12)[OF IH2]\n    show ?case by (rule reds.Application)\nnext\ncase (ApplicationInd n \\<Gamma> x e y S z \\<Delta> e' u b \\<Theta>)\ncase 2\n    from ApplicationInd(1) have \"n \\<noteq> x\" by (simp add: fresh_Pair fresh_at_base)\n    hence \"(depRel (\\<Gamma>(x f\\<mapsto> App (Var n) y)(n f\\<mapsto> e)))\\<^sup>+\\<^sup>+ x n\" by auto\n    moreover\n    from ApplicationInd(1) have \"atom n \\<sharp> \\<Gamma>(x f\\<mapsto> App e y)\"\n      by (simp add: fresh_Pair fresh_fmap_upd_eq fresh_fmap_delete_subset)\n    with `validStack (\\<Gamma>(x f\\<mapsto> App e y)) x S`\n    have \"validStack (\\<Gamma>(x f\\<mapsto> App (Var n) y)(n f\\<mapsto> e)) x S\" by (rule validStackIndirect)\n    ultimately\n    have IH1: \"validStack (\\<Gamma>(x f\\<mapsto> App (Var n) y)(n f\\<mapsto> e)) n (x # S)\"  by (rule ValidStackCons)\n    hence \"validStack \\<Delta> n (x # S)\" by (rule ApplicationInd.hyps)\n    hence \"validStack \\<Delta> x S\" by (cases)\n    hence IH2: \"validStack (\\<Delta>(z f\\<mapsto> Var y)(x f\\<mapsto> e')) x S\"\n    proof(rule validStack_cong)\n      from stack_unchanged[OF ApplicationInd.hyps(8)[OF IH1]] `n \\<noteq> x`\n      have \"depRel \\<Delta> x n\" by auto\n\n      fix x'\n      assume as: \"(depRel \\<Delta>)\\<^sup>+\\<^sup>+ x' x\"\n      moreover\n      from `lookup \\<Delta> n = Some (Lam [z]. e')`\n      have \"\\<not> (depRel \\<Delta>)\\<^sup>+\\<^sup>+ n x\" by auto\n      moreover\n      hence \"\\<not> (depRel \\<Delta>)\\<^sup>+\\<^sup>+ x x\" using `depRel \\<Delta> x n`\n        by (metis depRel_via)\n      ultimately\n      have \"x' \\<noteq> x\" \"x' \\<noteq> n\" by auto\n      moreover\n      from as `x' \\<noteq> n`\n      have \"x' \\<in> fdom \\<Delta>\" by (metis (hide_lams, no_types) converse_tranclpE depRel_dom)\n      with ApplicationInd(2)\n      have \"x' \\<noteq> z\" by (auto simp add: fresh_Pair)\n      ultimately\n      show \"lookup \\<Delta> x' =  lookup (\\<Delta>(z f\\<mapsto> Var y)(x f\\<mapsto> e')) x'\" by simp\n    qed\n    thus \"validStack \\<Theta> x S\"\n      by (rule ApplicationInd.hyps)\n  case 1\n    from ApplicationInd.hyps(6)[OF IH1]\n    show ?case\n    proof(rule contrapos_nn)\n      assume \"cycle (\\<Gamma>(x f\\<mapsto> App e y)) x\"\n      hence \"cycle (\\<Gamma>(x f\\<mapsto> App (Var n) y)(n f\\<mapsto> e)) x\"\n        by (rule cycleIndirect[OF _ `atom n \\<sharp> \\<Gamma>(x f\\<mapsto> App e y)`])\n      thus \"cycle (\\<Gamma>(x f\\<mapsto> App (Var n) y)(n f\\<mapsto> e)) n\" using `n \\<noteq> x`\n        by (auto elim!: cycle_depRel)\n    qed\n  case 3\n    from ApplicationInd.hyps(1-4)\n         ApplicationInd.hyps(8)[OF IH1]\n         ApplicationInd.hyps(12)[OF IH2]\n    show ?case by (rule reds.ApplicationInd)\nnext\ncase (Variable y x S \\<Gamma> i \\<Delta>)\n  hence \"y \\<noteq> x\" by simp\n\n  have \"(depRel (\\<Gamma>(x f\\<mapsto> Var y)))\\<^sup>+\\<^sup>+ x y\" by auto \n  moreover\n  assume \"validStack (\\<Gamma>(x f\\<mapsto> Var y)) x S\"\n  ultimately\n  have \"validStack (\\<Gamma>(x f\\<mapsto> Var y)) y (x # S)\"\n    by (rule ValidStackCons)\n  note hyps = Variable(4-6)[OF this]\n\n  from stack_unchanged[OF hyps(3)] `y \\<noteq> x`\n  have \"lookup \\<Delta> x = Some (Var y)\" by simp\n  hence \"depRel \\<Delta> x y\" by auto\n\n  from result_evaluated[OF hyps(3)]\n  have \"isLam (\\<Delta> f! y)\" by simp\n  hence \"\\<not> Domainp (depRel \\<Delta>) y\" apply auto by (metis bind_lunit bind_lzero isLam_dep not_None_eq the.simps)\n\n  from `validStack \\<Delta> y (x # S)` \n  have \"validStack \\<Delta> x S\" by cases\n  thus \"validStack (fmap_copy \\<Delta> y x) x S\"\n  proof (rule validStack_cong)\n    fix x'\n    assume \"(depRel \\<Delta>)\\<^sup>+\\<^sup>+ x' x\"\n    moreover\n    from `\\<not> Domainp (depRel \\<Delta>) y`\n    have \" \\<not>(depRel \\<Delta>)\\<^sup>+\\<^sup>+ y x\" by (metis Domainp.DomainI converse_tranclpE)\n    hence \" \\<not>(depRel \\<Delta>)\\<^sup>+\\<^sup>+ x x\" using `depRel \\<Delta> x y` by (metis depRel_via)\n    ultimately\n    have \"x' \\<noteq> x\" by auto\n    thus \"lookup \\<Delta> x' = lookup (fmap_copy \\<Delta> y x) x'\" by simp\n  qed\n\n  from hyps(1)\n  show \"\\<not> cycle (\\<Gamma>(x f\\<mapsto> Var y)) x\"\n    by (auto elim!: contrapos_nn cycle_depRel)\n\n  from Variable(1-3) \n  show \"\\<Gamma>(x f\\<mapsto> Var y) \\<Down>\\<^sup>i\\<^sup>\\<surd>\\<^sup>\\<surd>\\<^bsub>x # S\\<^esub> fmap_copy \\<Delta> y x\"\n    by (rule reds.Variable)\nnext\ncase (VariableNoBH x \\<Gamma> y i S \\<Delta>)\n  have \"(depRel (\\<Gamma>(x f\\<mapsto> Var y)))\\<^sup>+\\<^sup>+ x y\" by auto \n  moreover\n  assume \"validStack (\\<Gamma>(x f\\<mapsto> Var y)) x S\"\n  ultimately\n  have \"validStack (\\<Gamma>(x f\\<mapsto> Var y)) y (x # S)\"\n    by (rule ValidStackCons)\n  note hyps = VariableNoBH(3-5)[OF this]\n\n  from hyps(1) `(depRel (\\<Gamma>(x f\\<mapsto> Var y)))\\<^sup>+\\<^sup>+ x y`\n  have \"y \\<noteq> x\" by (auto simp add: cycle_def)\n\n  from stack_unchanged[OF hyps(3)] `y \\<noteq> x`\n  have \"lookup \\<Delta> x = Some (Var y)\" by simp\n  hence \"depRel \\<Delta> x y\" by auto\n\n  from result_evaluated[OF hyps(3)]\n  have \"isLam (\\<Delta> f! y)\" by simp\n  hence \"\\<not> Domainp (depRel \\<Delta>) y\" apply auto by (metis bind_lunit bind_lzero isLam_dep not_None_eq the.simps)\n\n  from `validStack \\<Delta> y (x # S)` \n  have \"validStack \\<Delta> x S\" by cases\n  thus \"validStack (fmap_copy \\<Delta> y x) x S\"\n  proof (rule validStack_cong)\n    fix x'\n    assume \"(depRel \\<Delta>)\\<^sup>+\\<^sup>+ x' x\"\n    moreover\n    from `\\<not> Domainp (depRel \\<Delta>) y`\n    have \" \\<not>(depRel \\<Delta>)\\<^sup>+\\<^sup>+ y x\" by (metis Domainp.DomainI converse_tranclpE)\n    hence \" \\<not>(depRel \\<Delta>)\\<^sup>+\\<^sup>+ x x\" using `depRel \\<Delta> x y` by (metis depRel_via)\n    ultimately\n    have \"x' \\<noteq> x\" by auto\n    thus \"lookup \\<Delta> x' = lookup (fmap_copy \\<Delta> y x) x'\" by simp\n  qed\n\n  from hyps(1)\n  show \"\\<not> cycle (\\<Gamma>(x f\\<mapsto> Var y)) x\"\n    by (auto elim!: contrapos_nn cycle_depRel)\n\n  from hyps(1) `validStack (\\<Gamma>(x f\\<mapsto> Var y)) y (x#S)`\n  have \"y \\<notin> set (x # S)\"\n    by (metis validStack_cycle)\n\n  from this VariableNoBH.hyps(1) hyps(3)\n  show \"\\<Gamma>(x f\\<mapsto> Var y) \\<Down>\\<^sup>i\\<^sup>\\<surd>\\<^sup>\\<surd>\\<^bsub>x # S\\<^esub> fmap_copy \\<Delta> y x\"\n    by (rule reds.Variable)\nnext\ncase (Let as \\<Gamma> x S body i u b \\<Delta>)\n  assume \"validStack (\\<Gamma>(x f\\<mapsto> Terms.Let as body)) x S\"\n\n  hence \"validStack (\\<Gamma>(x f\\<mapsto> body) f++ fmap_of (asToHeap as)) x S\"\n  proof (rule validStack_cong)\n    fix x'\n    assume as: \"(depRel (\\<Gamma>(x f\\<mapsto> Terms.Let as body)))\\<^sup>+\\<^sup>+ x' x\"\n    hence \"x' \\<noteq> x\" by auto\n    with as have \"x' \\<in> fdom \\<Gamma>\"\n      by (auto dest:depRelTransDom)\n    with Let(1)\n    have \"atom x' \\<notin> set (bn as)\" by (auto simp add: fresh_star_def fresh_Pair)\n    hence  \"x' \\<notin> fdom (fmap_of (asToHeap as))\" \n      by (metis (full_types) fdom_fmap_of_conv_heapVars imageI set_bn_to_atom_heapVars)\n    with `x' \\<noteq> x`\n    show \"lookup (\\<Gamma>(x f\\<mapsto> Terms.Let as body)) x' =\n        lookup (\\<Gamma>(x f\\<mapsto> body) f++ fmap_of (asToHeap as)) x'\"\n        by simp\n  qed\n  note hyps = Let(4-6)[OF this]\n\n  case 1\n  show ?case by (auto simp add: cycle_def)\n\n  case 2\n  from hyps(2)\n  show ?case.\n\n  case 3\n  note Let(1-2) hyps(3)\n  thus ?case..\nqed\n\nlemma remove_blackholing:\n  assumes \"\\<Gamma> \\<Down>\\<^sup>i\\<^sup>u\\<^sup>\\<surd>\\<^bsub>S\\<^esub> \\<Delta>\"\n  shows \"\\<Gamma> \\<Down>\\<^sup>i\\<^sup>u\\<^sup>b\\<^bsub>S\\<^esub> \\<Delta>\"\nusing assms\napply (cases b, simp)\napply (induction \\<Gamma> i u \"\\<surd>\" S \\<Delta> rule:reds.induct )\napply (blast intro:reds.intros)+\ndone\n\nlemma second_stack_element_unchanged:\n  assumes \"\\<Gamma> \\<Down>\\<^sup>i\\<^sup>u\\<^sup>b\\<^bsub>x#y#S\\<^esub> \\<Delta>\"\n  assumes \"x \\<noteq> y\"\n  assumes \"depRel \\<Gamma> y x\"\n  shows \"lookup \\<Delta> y = lookup \\<Gamma> y\"\nproof-\n  from shorten_stack[OF assms(1), where n = 1]\n  have \"\\<Gamma> \\<Down>\\<^sup>i\\<^sup>u\\<^sup>b\\<^bsub>[x,y]\\<^esub> \\<Delta>\" by simp\n  moreover\n  from assms(3)\n  have \"validStack \\<Gamma> x [y]\" by (fastforce intro: validStack.intros)\n  ultimately\n  have \"\\<Gamma> \\<Down>\\<^sup>i\\<^sup>u\\<^sup>\\<surd>\\<^bsub>[x,y]\\<^esub> \\<Delta>\" by (rule add_blackholing)\n  from stack_unchanged[OF this, where x = y] assms(2)\n  show ?thesis by auto\nqed\n\nlemma Application_x_unchanged:\n  assumes \"\\<Gamma>(x f\\<mapsto> App (Var n) y)(n f\\<mapsto> e) \\<Down>\\<^sup>i\\<^sup>u\\<^sup>b\\<^bsub>n # x # S\\<^esub> \\<Delta>\"\n  and \"n \\<noteq> x\"\n  shows \"lookup \\<Delta> x = Some (App (Var n) y)\"\n  using second_stack_element_unchanged[OF assms] assms(2) by auto\n\nlemma var_not_self:\n  shows  \"\\<not> (\\<Gamma>(x f\\<mapsto> Var x) \\<Down>\\<^sup>i\\<^sup>u\\<^sup>b\\<^bsub>x # S\\<^esub> \\<Delta>)\"\nproof\n  assume \"\\<Gamma>(x f\\<mapsto> Var x) \\<Down>\\<^sup>i\\<^sup>u\\<^sup>b\\<^bsub>x # S\\<^esub> \\<Delta>\"\n  from shorten_stack[OF this, where n = 0]\n  have \"\\<Gamma>(x f\\<mapsto> Var x) \\<Down>\\<^sup>i\\<^sup>u\\<^sup>b\\<^bsub>[x]\\<^esub> \\<Delta>\" by simp\n  hence \"\\<Gamma>(x f\\<mapsto> Var x) \\<Down>\\<^sup>i\\<^sup>u\\<^sup>\\<surd>\\<^bsub>[x]\\<^esub> \\<Delta>\" by (rule add_blackholing[OF _ ValidStackNil])\n  thus False  by cases (auto dest: fmap_upd_eqD1)\nqed\n\nend\n\n", "meta": {"author": "nomeata", "repo": "isa-launchbury", "sha": "2caa8d7d588e218aef1c49f2f327597af06d116e", "save_path": "github-repos/isabelle/nomeata-isa-launchbury", "path": "github-repos/isabelle/nomeata-isa-launchbury/isa-launchbury-2caa8d7d588e218aef1c49f2f327597af06d116e/Scratchpad/LaunchburyAddBH.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632683808533, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.25660249702779286}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      HoarePartial.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection \\<open>Derived Hoare Rules for Partial Correctness\\<close>\n\ntheory HoarePartial imports HoarePartialProps begin\n\nlemma conseq_no_aux:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' c Q',A';\n    \\<forall>s. s \\<in> P \\<longrightarrow> (s\\<in>P' \\<and> (Q' \\<subseteq> Q) \\<and> (A' \\<subseteq> A))\\<rbrakk>\n  \\<Longrightarrow>\n  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule conseq [where P'=\"\\<lambda>Z. P'\" and Q'=\"\\<lambda>Z. Q'\" and A'=\"\\<lambda>Z. A'\"]) auto\n\n\nlemma conseq_exploit_pre:\n             \"\\<lbrakk>\\<forall>s \\<in> P. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s} \\<inter> P) c Q,A\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule Conseq)\n  apply clarify\n  apply (rule_tac x=\"{s} \\<inter> P\" in exI)  \n  apply (rule_tac x=\"Q\" in exI)  \n  apply (rule_tac x=\"A\" in exI)  \n  by simp\n\n\nlemma conseq:\"\\<lbrakk>\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z);\n              \\<forall>s. s \\<in> P \\<longrightarrow> (\\<exists> Z. s\\<in>P' Z \\<and> (Q' Z \\<subseteq> Q) \\<and> (A' Z \\<subseteq> A))\\<rbrakk>\n              \\<Longrightarrow>\n              \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (rule Conseq') blast\n\nlemma Lem: \"\\<lbrakk>\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z);\n             P \\<subseteq> {s. \\<exists> Z. s\\<in>P' Z \\<and> (Q' Z \\<subseteq> Q) \\<and> (A' Z \\<subseteq> A)}\\<rbrakk>\n             \\<Longrightarrow>\n             \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (lem x c) Q,A\"\n  apply (unfold lem_def) \n  apply (erule conseq)\n  apply blast\n  done\n\nlemma LemAnno:\nassumes conseq:  \"P \\<subseteq> {s. \\<exists>Z. s\\<in>P' Z \\<and> \n                     (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> t \\<in> Q) \\<and> (\\<forall>t. t \\<in> A' Z \\<longrightarrow> t \\<in> A)}\"\nassumes lem: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (lem x c) Q,A\"\n  apply (rule Lem [OF lem])\n  using conseq\n  by blast\n\nlemma LemAnnoNoAbrupt:\nassumes conseq:  \"P \\<subseteq>  {s. \\<exists>Z. s\\<in>P' Z \\<and> (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> t \\<in> Q)}\"\nassumes lem: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),{}\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (lem x c) Q,{}\"\n  apply (rule Lem [OF lem])\n  using conseq\n  by blast\n\nlemma TrivPost: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),(A' Z)\n                 \\<Longrightarrow>\n                 \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c UNIV,UNIV\"\napply (rule allI)\napply (erule conseq)\napply auto\ndone\n\nlemma TrivPostNoAbr: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c (Q' Z),{}\n                 \\<Longrightarrow>\n                 \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) c UNIV,{}\"\napply (rule allI)\napply (erule conseq)\napply auto\ndone\n\nlemma conseq_under_new_pre:\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P' c Q',A';\n        \\<forall>s \\<in> P. s \\<in> P' \\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A\\<rbrakk>\n\\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P c Q,A\"\napply (rule conseq)\napply (rule allI)\napply assumption\napply auto\ndone\n\n\n\nlemma DynComConseq:\n  assumes \"P \\<subseteq> {s. \\<exists>P' Q' A'.  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P' (c s) Q',A' \\<and> P \\<subseteq> P' \\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A}\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P DynCom c Q,A\"\n  using assms\n  apply -\n  apply (rule DynCom)\n  apply clarsimp\n  apply (rule Conseq)\n  apply clarsimp\n  apply blast\n  done\n\nlemma SpecAnno: \n assumes consequence: \"P \\<subseteq> {s. (\\<exists> Z. s\\<in>P' Z \\<and> (Q' Z \\<subseteq> Q) \\<and> (A' Z \\<subseteq> A))}\"\n assumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) (c Z) (Q' Z),(A' Z)\"\n assumes bdy_constant:  \"\\<forall>Z. c Z = c undefined\"\n shows   \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (specAnno P' c Q' A') Q,A\"\nproof -\n  from spec bdy_constant\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ((P' Z)) (c undefined) (Q' Z),(A' Z)\"\n    apply - \n    apply (rule allI)\n    apply (erule_tac x=Z in allE)\n    apply (erule_tac x=Z in allE)\n    apply simp\n    done\n  with consequence show ?thesis\n    apply (simp add: specAnno_def)\n    apply (erule conseq)\n    apply blast\n    done\nqed\n\nlemma SpecAnno': \n \"\\<lbrakk>P \\<subseteq> {s.  \\<exists> Z. s\\<in>P' Z \\<and> \n            (\\<forall>t. t \\<in> Q' Z \\<longrightarrow>  t \\<in> Q) \\<and> (\\<forall>t. t \\<in> A' Z \\<longrightarrow> t \\<in>  A)};\n   \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) (c Z) (Q' Z),(A' Z);\n   \\<forall>Z. c Z = c undefined\n  \\<rbrakk> \\<Longrightarrow>\n    \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (specAnno P' c Q' A') Q,A\"\napply (simp only: subset_iff [THEN sym])\napply (erule (1) SpecAnno)\napply assumption\ndone\n\n\nlemma SpecAnnoNoAbrupt: \n \"\\<lbrakk>P \\<subseteq> {s.  \\<exists> Z. s\\<in>P' Z \\<and> \n            (\\<forall>t. t \\<in> Q' Z \\<longrightarrow>  t \\<in> Q)};\n   \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) (c Z) (Q' Z),{};\n   \\<forall>Z. c Z = c undefined\n  \\<rbrakk> \\<Longrightarrow>\n    \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (specAnno P' c Q' (\\<lambda>s. {})) Q,A\"\napply (rule SpecAnno')\napply auto\ndone\n\nlemma Skip: \"P \\<subseteq> Q \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Skip Q,A\"\n  by (rule hoarep.Skip [THEN conseqPre],simp)\n\nlemma Basic: \"P \\<subseteq> {s. (f s) \\<in> Q} \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Basic f) Q,A\"\n  by (rule hoarep.Basic [THEN conseqPre])\n\nlemma BasicCond: \n  \"\\<lbrakk>P \\<subseteq> {s. (b s \\<longrightarrow> f s\\<in>Q) \\<and> (\\<not> b s \\<longrightarrow> g s\\<in>Q)}\\<rbrakk> \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Basic (\\<lambda>s. if b s then f s else g s) Q,A\"\n  apply (rule Basic)\n  apply auto\n  done\n\nlemma Spec: \"P \\<subseteq> {s. (\\<forall>t. (s,t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s,t) \\<in> r)} \n            \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Spec r) Q,A\"\nby (rule hoarep.Spec [THEN conseqPre])\n\nlemma SpecIf: \n  \"\\<lbrakk>P \\<subseteq> {s. (b s \\<longrightarrow> f s \\<in> Q) \\<and> (\\<not> b s \\<longrightarrow> g s \\<in> Q \\<and> h s \\<in> Q)}\\<rbrakk> \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Spec (if_rel b f g h) Q,A\"\n  apply (rule Spec)\n  apply (auto simp add: if_rel_def)\n  done\n\n\nlemma Seq [trans, intro?]: \n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>1 R,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Seq c\\<^sub>1 c\\<^sub>2) Q,A\"\n  by (rule hoarep.Seq)\n\nlemma SeqSwap: \n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c2 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c1 R,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Seq c1 c2) Q,A\"\n  by (rule Seq)\n\nlemma BSeq:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>1 R,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (bseq c\\<^sub>1 c\\<^sub>2) Q,A\"\n  by (unfold bseq_def) (rule Seq)\n\n\nlemma Cond: \n  assumes wp: \"P \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\" \n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P\\<^sub>1 c\\<^sub>1 Q,A\" \n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P\\<^sub>2 c\\<^sub>2 Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) Q,A\"\nproof (rule hoarep.Cond [THEN conseqPre])\n  from deriv_c1 \n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. (s \\<in> b \\<longrightarrow> s \\<in> P\\<^sub>1) \\<and> (s \\<notin> b \\<longrightarrow> s \\<in> P\\<^sub>2)} \\<inter> b) c\\<^sub>1 Q,A\"\n    by (rule conseqPre) blast\nnext\n  from deriv_c2 \n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. (s \\<in> b \\<longrightarrow> s \\<in> P\\<^sub>1) \\<and> (s \\<notin> b \\<longrightarrow> s \\<in> P\\<^sub>2)} \\<inter> - b) c\\<^sub>2 Q,A\"\n    by (rule conseqPre) blast\nnext\n  show \"P \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\" by (rule wp)\nqed \n\n\nlemma CondSwap: \n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P1 c1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P2 c2 Q,A; P \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P2)}\\<rbrakk>\n   \\<Longrightarrow> \n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c1 c2) Q,A\"\n  by (rule Cond)\n\nlemma Cond': \n  \"\\<lbrakk>P \\<subseteq> {s. (b \\<subseteq> P1) \\<and> (- b \\<subseteq> P2)};\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P1 c1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P2 c2 Q,A\\<rbrakk>\n   \\<Longrightarrow> \n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c1 c2) Q,A\"\n  by (rule CondSwap) blast+\n\nlemma CondInv: \n  assumes wp: \"P \\<subseteq> Q\" \n  assumes inv: \"Q \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\" \n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P\\<^sub>1 c\\<^sub>1 Q,A\" \n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P\\<^sub>2 c\\<^sub>2 Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) Q,A\"\nproof -\n  from wp inv\n  have \"P \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\"\n    by blast\n  from Cond [OF this deriv_c1 deriv_c2]\n  show ?thesis .\nqed\n\nlemma CondInv': \n  assumes wp: \"P \\<subseteq> I\" \n  assumes inv: \"I \\<subseteq> {s. (s\\<in>b \\<longrightarrow> s\\<in>P\\<^sub>1) \\<and> (s\\<notin>b \\<longrightarrow> s\\<in>P\\<^sub>2)}\" \n  assumes wp': \"I \\<subseteq> Q\" \n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P\\<^sub>1 c\\<^sub>1 I,A\" \n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P\\<^sub>2 c\\<^sub>2 I,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) Q,A\"\nproof -\n  from CondInv [OF wp inv deriv_c1 deriv_c2]\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c\\<^sub>1 c\\<^sub>2) I,A\".\n  from conseqPost [OF this wp' subset_refl]\n  show ?thesis .\nqed\n    \n\nlemma switchNil:\n  \"P \\<subseteq> Q \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P (switch v []) Q,A\"\n  by (simp add: Skip)\n \nlemma switchCons:\n  \"\\<lbrakk>P \\<subseteq> {s. (v s \\<in> V \\<longrightarrow> s \\<in> P\\<^sub>1) \\<and> (v s \\<notin> V \\<longrightarrow> s \\<in> P\\<^sub>2)}; \n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P\\<^sub>1 c Q,A;\n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P\\<^sub>2 (switch v vs) Q,A\\<rbrakk>\n\\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P (switch v ((V,c)#vs)) Q,A\"\n  by (simp add: Cond)\n\nlemma Guard:\n \"\\<lbrakk>P \\<subseteq> g \\<inter> R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\napply (rule Guard [THEN conseqPre, of _ _ _ _ R])\napply (erule conseqPre)\napply auto\ndone\n\nlemma GuardSwap:\n \"\\<lbrakk> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> g \\<inter> R\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\n  by (rule Guard)\n\nlemma Guarantee:\n \"\\<lbrakk>P \\<subseteq> {s. s \\<in> g \\<longrightarrow> s \\<in> R}; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; f \\<in> F\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\napply (rule Guarantee [THEN conseqPre, of _ _ _ _ _ \"{s. s \\<in> g \\<longrightarrow> s \\<in> R}\"])\napply   assumption\napply  (erule conseqPre)\napply auto\ndone\n\nlemma GuaranteeSwap:\n \"\\<lbrakk> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> {s. s \\<in> g \\<longrightarrow> s \\<in> R}; f \\<in> F\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\n  by (rule Guarantee)\n\nlemma GuardStrip:\n \"\\<lbrakk>P \\<subseteq> R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; f \\<in> F\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\napply (rule Guarantee [THEN conseqPre])\napply auto\ndone\n\nlemma GuardStripSwap:\n \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> R; f \\<in> F\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Guard f g c) Q,A\"\n  by (rule GuardStrip)\n\nlemma GuaranteeStrip:\n \"\\<lbrakk>P \\<subseteq> R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; f \\<in> F\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guaranteeStrip f g c) Q,A\"\n  by (unfold guaranteeStrip_def) (rule GuardStrip)\n\nlemma GuaranteeStripSwap:\n \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> R; f \\<in> F\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guaranteeStrip f g c) Q,A\"\n  by (unfold guaranteeStrip_def) (rule GuardStrip)\n\nlemma GuaranteeAsGuard:\n \"\\<lbrakk>P \\<subseteq> g \\<inter> R; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guaranteeStrip f g c) Q,A\"\n  by (unfold guaranteeStrip_def) (rule Guard)\n\n\nlemma GuaranteeAsGuardSwap:\n \"\\<lbrakk> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c Q,A; P \\<subseteq> g \\<inter> R\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guaranteeStrip f g c) Q,A\"\n  by (rule GuaranteeAsGuard)\n\nlemma GuardsNil:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guards [] c) Q,A\"\n  by simp\n\n\n\nlemma GuardsConsGuaranteeStrip:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P guaranteeStrip f g (guards gs c) Q,A \\<Longrightarrow> \n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guards (guaranteeStripPair f g#gs) c) Q,A\"\n  by (simp add: guaranteeStripPair_def guaranteeStrip_def)\n\nlemma While: \n  assumes P_I: \"P \\<subseteq> I\" \n  assumes deriv_body: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (I \\<inter> b) c I,A\"\n  assumes I_Q: \"I \\<inter> -b \\<subseteq> Q\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnno b I V c) Q,A\"\nproof -\n  from deriv_body P_I I_Q\n  show ?thesis\n    apply (simp add: whileAnno_def)\n    apply (erule conseqPrePost [OF HoarePartialDef.While]) \n    apply simp_all\n    done\nqed\n\ntext \\<open>@{term \"J\"} will be instantiated by tactic with @{term \"gs' \\<inter> I\"} for\n  those guards that are not stripped.\\<close> \nlemma  WhileAnnoG:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guards gs \n                    (whileAnno  b J V (Seq c (guards gs Skip)))) Q,A \n        \\<Longrightarrow> \n        \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnnoG gs b I V c) Q,A\"\n  by (simp add: whileAnnoG_def whileAnno_def while_def)\n\n\ntext \\<open>This form stems from @{term \"strip_guards F (whileAnnoG gs b I V c)\"}\\<close>\n\n\n\n\n\nlemma WhileAnnoGFix:\nassumes whileAnnoFix:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (guards gs \n                (whileAnnoFix  b J V (\\<lambda>Z. (Seq (c Z) (guards gs Skip))))) Q,A\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnnoGFix gs b I V c) Q,A\"\n  using whileAnnoFix\n  by (simp add: whileAnnoGFix_def whileAnnoFix_def while_def)\n\nlemma Bind:\n  assumes adapt: \"P \\<subseteq> {s. s \\<in> P' s}\" \n  assumes c: \"\\<forall>s. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' s) (c (e s)) Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (bind e c) Q,A\" \napply (rule conseq [where P'=\"\\<lambda>Z. {s. s=Z \\<and> s \\<in> P' Z}\" and Q'=\"\\<lambda>Z. Q\" and \nA'=\"\\<lambda>Z. A\"])\napply  (rule allI)\napply  (unfold bind_def)\napply  (rule DynCom)\napply  (rule ballI)\napply  simp\napply  (rule conseqPre)\napply   (rule c [rule_format])\napply  blast\nusing adapt\napply blast\ndone\n\nlemma Block:\nassumes adapt: \"P \\<subseteq> {s. init s \\<in> P' s}\"\nassumes bdy: \"\\<forall>s. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' s) bdy {t. return s t \\<in> R s t},{t. return s t \\<in> A}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (block init bdy return c) Q,A\" \napply (rule conseq [where P'=\"\\<lambda>Z. {s. s=Z \\<and> init s \\<in> P' Z}\" and Q'=\"\\<lambda>Z. Q\" and \nA'=\"\\<lambda>Z. A\"])\nprefer 2\nusing adapt\napply  blast\napply (rule allI)\napply (unfold block_def)\napply (rule DynCom)\napply (rule ballI)\napply clarsimp\napply (rule_tac R=\"{t. return Z t \\<in> R Z t}\" in SeqSwap )\napply  (rule_tac  P'=\"\\<lambda>Z'. {t. t=Z' \\<and> return Z t \\<in> R Z t}\" and \n          Q'=\"\\<lambda>Z'. Q\" and A'=\"\\<lambda>Z'. A\" in conseq)\nprefer 2 apply simp\napply  (rule allI)\napply  (rule DynCom)\napply  (clarsimp)\napply  (rule SeqSwap)\napply   (rule c [rule_format])\napply  (rule Basic)\napply  clarsimp\napply (rule_tac R=\"{t. return Z t \\<in> A}\" in Catch)\napply  (rule_tac R=\"{i. i \\<in> P' Z}\" in Seq)\napply   (rule Basic)\napply   clarsimp\napply  simp\napply  (rule bdy [rule_format])\napply (rule SeqSwap)\napply  (rule Throw)\napply (rule Basic)\napply simp\ndone\n\n\nlemma BlockSwap:\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes bdy: \"\\<forall>s. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' s) bdy {t. return s t \\<in> R s t},{t. return s t \\<in> A}\"\nassumes adapt: \"P \\<subseteq> {s. init s \\<in> P' s}\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (block init bdy return c) Q,A\"\nusing adapt bdy c  \n  by (rule Block)\n\n\nlemma BlockSpec:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' Z \\<and> \n                             (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t) \\<and>\n                             (\\<forall>t. t \\<in> A' Z \\<longrightarrow> return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes bdy: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) bdy (Q' Z),(A' Z)\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (block init bdy return c) Q,A\" \napply (rule conseq [where P'=\"\\<lambda>Z. {s. init s \\<in> P' Z \\<and> \n                             (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t) \\<and>\n                             (\\<forall>t. t \\<in> A' Z \\<longrightarrow> return s t \\<in> A)}\" and Q'=\"\\<lambda>Z. Q\" and \nA'=\"\\<lambda>Z. A\"])\nprefer 2\nusing adapt\napply  blast\napply (rule allI)\napply (unfold block_def)\napply (rule DynCom)\napply (rule ballI)\napply clarsimp\napply (rule_tac R=\"{t. return s t \\<in> R s t}\" in SeqSwap )\napply  (rule_tac  P'=\"\\<lambda>Z'. {t. t=Z' \\<and> return s t \\<in> R s t}\" and \n          Q'=\"\\<lambda>Z'. Q\" and A'=\"\\<lambda>Z'. A\" in conseq)\nprefer 2 apply simp\napply  (rule allI)\napply  (rule DynCom)\napply  (clarsimp)\napply  (rule SeqSwap)\napply   (rule c [rule_format])\napply  (rule Basic)\napply  clarsimp\napply (rule_tac R=\"{t. return s t \\<in> A}\" in Catch)\napply  (rule_tac R=\"{i. i \\<in> P' Z}\" in Seq)\napply   (rule Basic)\napply   clarsimp\napply  simp\napply  (rule conseq [OF bdy])\napply  clarsimp\napply  blast\napply (rule SeqSwap)\napply  (rule Throw)\napply (rule Basic)\napply simp\ndone\n\nlemma Throw: \"P \\<subseteq> A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Throw Q,A\"\n  by (rule hoarep.Throw [THEN conseqPre])\n\nlemmas Catch = hoarep.Catch\nlemma CatchSwap: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,R\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Catch c\\<^sub>1 c\\<^sub>2 Q,A\"\n  by (rule hoarep.Catch)\n\nlemma raise: \"P \\<subseteq> {s. f s \\<in> A} \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P raise f Q,A\"\n  apply (simp add: raise_def)\n  apply (rule Seq)\n  apply  (rule Basic)\n  apply  (assumption)\n  apply (rule Throw)\n  apply (rule subset_refl)\n  done\n\nlemma condCatch: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,((b \\<inter> R) \\<union> (-b \\<inter> A));\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\\<rbrakk> \n                  \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P condCatch c\\<^sub>1 b c\\<^sub>2 Q,A\"\n  apply (simp add: condCatch_def)\n  apply (rule Catch)\n  apply  assumption\n  apply (rule CondSwap)\n  apply   (assumption)\n  apply  (rule hoarep.Throw)\n  apply blast\n  done\n\nlemma condCatchSwap: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A;\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,((b \\<inter> R) \\<union> (-b \\<inter> A))\\<rbrakk> \n                  \\<Longrightarrow>  \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P condCatch c\\<^sub>1 b c\\<^sub>2 Q,A\"\n  by (rule condCatch)\n\n\nlemma ProcSpec:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' Z \\<and> \n                             (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t) \\<and>\n                             (\\<forall>t. t \\<in> A' Z \\<longrightarrow> return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) Call p (Q' Z),(A' Z)\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nusing adapt c p\napply (unfold call_def) \nby (rule BlockSpec)\n\nlemma ProcSpec':\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' Z \\<and> \n                             (\\<forall>t \\<in> Q' Z. return s t \\<in> R s t) \\<and>\n                             (\\<forall>t \\<in> A' Z. return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) Call p (Q' Z),(A' Z)\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule ProcSpec [OF _ c p])\napply (insert adapt)\napply clarsimp\napply (drule (1) subsetD)\napply (clarsimp)\napply (rule_tac x=Z in exI)\napply blast\ndone\n\nlemma ProcSpecNoAbrupt:\n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' Z \\<and> \n                             (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) Call p (Q' Z),{}\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule ProcSpec [OF _ c p])\nusing adapt\napply simp\ndone\n\nlemma FCall:  \n\"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return (\\<lambda>s t. c (result t))) Q,A\n\\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (fcall init p return result c) Q,A\"\n  by (simp add: fcall_def)\n\n\nlemma ProcRec:\n  assumes deriv_bodies:  \n   \"\\<forall>p\\<in>Procs. \n    \\<forall>Z. \\<Gamma>,\\<Theta>\\<union>(\\<Union>p\\<in>Procs. \\<Union>Z. {(P p Z,p,Q p Z,A p Z)})\n        \\<turnstile>\\<^bsub>/F\\<^esub> (P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n  assumes Procs_defined: \"Procs \\<subseteq> dom \\<Gamma>\"\n  shows \"\\<forall>p\\<in>Procs. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>(P p Z) Call p (Q p Z),(A p Z)\"\n  by (intro strip)\n     (rule CallRec' \n     [OF _   Procs_defined deriv_bodies],\n     simp_all)\n\nlemma ProcRec':\n  assumes ctxt: \"\\<Theta>' = \\<Theta>\\<union>(\\<Union>p\\<in>Procs. \\<Union>Z. {(P p Z,p,Q p Z,A p Z)})\"\n  assumes deriv_bodies:  \n   \"\\<forall>p\\<in>Procs. \\<forall>Z. \\<Gamma>,\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> (P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n  assumes Procs_defined: \"Procs \\<subseteq> dom \\<Gamma>\"\n  shows \"\\<forall>p\\<in>Procs. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>(P p Z) Call p (Q p Z),(A p Z)\"\n  using ctxt deriv_bodies\n  apply simp\n  apply (erule ProcRec [OF _ Procs_defined])\n  done\n\n\nlemma ProcRecList:\n  assumes deriv_bodies:  \n   \"\\<forall>p\\<in>set Procs. \n    \\<forall>Z. \\<Gamma>,\\<Theta>\\<union>(\\<Union>p\\<in>set Procs. \\<Union>Z. {(P p Z,p,Q p Z,A p Z)})\n        \\<turnstile>\\<^bsub>/F\\<^esub> (P p Z) (the (\\<Gamma> p)) (Q p Z),(A p Z)\"\n  assumes dist: \"distinct Procs\"\n  assumes Procs_defined: \"set Procs \\<subseteq> dom \\<Gamma>\"\n  shows \"\\<forall>p\\<in>set Procs. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>(P p Z) Call p (Q p Z),(A p Z)\"\n  using deriv_bodies Procs_defined\n  by (rule ProcRec)\n\nlemma  ProcRecSpecs:\n  \"\\<lbrakk>\\<forall>(P,p,Q,A) \\<in> Specs. \\<Gamma>,\\<Theta>\\<union>Specs\\<turnstile>\\<^bsub>/F\\<^esub> P (the (\\<Gamma> p)) Q,A;\n    \\<forall>(P,p,Q,A) \\<in> Specs. p \\<in> dom \\<Gamma>\\<rbrakk>\n  \\<Longrightarrow> \\<forall>(P,p,Q,A) \\<in> Specs. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\napply (auto intro: CallRec)\ndone\n\n\nlemma ProcRec1:\n  assumes deriv_body:  \n   \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<union>(\\<Union>Z. {(P Z,p,Q Z,A Z)})\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) (the (\\<Gamma> p)) (Q Z),(A Z)\"\n  assumes p_defined: \"p \\<in> dom \\<Gamma>\"\n  shows \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) Call p (Q Z),(A Z)\"\nproof -\n  from deriv_body p_defined\n  have \"\\<forall>p\\<in>{p}. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) Call p (Q Z),(A Z)\"\n    by - (rule ProcRec [where A=\"\\<lambda>p. A\" and P=\"\\<lambda>p. P\" and Q=\"\\<lambda>p. Q\"],\n          simp_all)\n  thus ?thesis\n    by simp\nqed\n\nlemma ProcNoRec1:\n  assumes deriv_body:  \n   \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) (the (\\<Gamma> p)) (Q Z),(A Z)\"\n  assumes p_def: \"p \\<in> dom \\<Gamma>\"\n  shows \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) Call p (Q Z),(A Z)\"\nproof -\nfrom deriv_body\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<union>(\\<Union>Z. {(P Z,p,Q Z,A Z)})\n             \\<turnstile>\\<^bsub>/F\\<^esub> (P Z) (the (\\<Gamma> p)) (Q Z),(A Z)\"\n    by (blast intro: hoare_augment_context)\n  from this p_def\n  show ?thesis \n    by (rule ProcRec1)\nqed\n\nlemma ProcBody:\n assumes WP: \"P \\<subseteq> P'\"\n assumes deriv_body: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' body Q,A\" \n assumes body: \"\\<Gamma> p = Some body\"\n shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Call p Q,A\"\napply (rule conseqPre [OF _ WP])\napply (rule ProcNoRec1 [rule_format, where P=\"\\<lambda>Z. P'\" and Q=\"\\<lambda>Z. Q\" and A=\"\\<lambda>Z. A\"]) \napply  (insert body)\napply  simp\napply  (rule hoare_augment_context [OF deriv_body])\napply  blast\napply fastforce\ndone\n\nlemma CallBody:\nassumes adapt: \"P \\<subseteq> {s. init s \\<in> P' s}\"\nassumes bdy: \"\\<forall>s. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' s) body {t. return s t \\<in> R s t},{t. return s t \\<in> A}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes body: \"\\<Gamma> p = Some body\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (unfold call_def)\napply (rule Block [OF adapt _ c])\napply (rule allI)\napply (rule ProcBody [where \\<Gamma>=\\<Gamma>, OF _ bdy [rule_format] body])\napply simp\ndone\n\nlemmas ProcModifyReturn = HoarePartialProps.ProcModifyReturn \nlemmas ProcModifyReturnSameFaults = HoarePartialProps.ProcModifyReturnSameFaults\n\nlemma ProcModifyReturnNoAbr:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes result_conform:\n      \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:  \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} Call p (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nby (rule ProcModifyReturn [OF spec result_conform _ modifies_spec]) simp\n\nlemma ProcModifyReturnNoAbrSameFaults:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes result_conform:\n      \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:  \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call p (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nby (rule ProcModifyReturnSameFaults [OF spec result_conform _ modifies_spec]) simp\n\n\nlemma DynProc: \n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' s Z \\<and>\n                          (\\<forall>t. t \\<in> Q' s Z \\<longrightarrow>  return s t \\<in> R s t) \\<and>\n                          (\\<forall>t. t \\<in> A' s Z \\<longrightarrow> return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>s\\<in> P. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' s Z) Call (p s) (Q' s Z),(A' s Z)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P dynCall init p return c Q,A\"\napply (rule conseq [where P'=\"\\<lambda>Z. {s. s=Z \\<and> s \\<in> P}\"\n  and Q'=\"\\<lambda>Z. Q\" and A'=\"\\<lambda>Z. A\"])\nprefer 2\nusing adapt\napply  blast\napply (rule allI)\napply (unfold dynCall_def call_def block_def)\napply (rule DynCom)\napply clarsimp\napply (rule DynCom)\napply clarsimp\napply (frule in_mono [rule_format, OF adapt])\napply clarsimp\napply (rename_tac Z')\napply (rule_tac R=\"Q' Z Z'\" in Seq)\napply  (rule CatchSwap)\napply   (rule SeqSwap)\napply    (rule Throw) \napply    (rule subset_refl)\napply   (rule Basic)\napply   (rule subset_refl)\napply  (rule_tac R=\"{i. i \\<in> P' Z Z'}\" in Seq)\napply   (rule Basic) \napply   clarsimp\napply  simp\napply  (rule_tac Q'=\"Q' Z Z'\" and A'=\"A' Z Z'\" in conseqPost)\nusing p\napply    clarsimp\napply   simp\napply  clarsimp\napply  (rule_tac  P'=\"\\<lambda>Z''. {t. t=Z'' \\<and> return Z t \\<in> R Z t}\" and \n          Q'=\"\\<lambda>Z''. Q\" and A'=\"\\<lambda>Z''. A\" in conseq)\nprefer 2 apply simp\napply (rule allI)\napply (rule DynCom)\napply clarsimp\napply (rule SeqSwap)\napply  (rule c [rule_format])\napply (rule Basic)\napply clarsimp\ndone\n\nlemma DynProc': \n  assumes adapt: \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' s Z \\<and>\n                          (\\<forall>t \\<in> Q' s Z. return s t \\<in> R s t) \\<and>\n                          (\\<forall>t \\<in> A' s Z. return s t \\<in> A)}\"\n  assumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\n  assumes p: \"\\<forall>s\\<in> P. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' s Z) Call (p s) (Q' s Z),(A' s Z)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P dynCall init p return c Q,A\"\nproof -\n  from adapt have \"P \\<subseteq> {s. \\<exists>Z. init s \\<in> P' s Z \\<and>\n                          (\\<forall>t. t \\<in> Q' s Z \\<longrightarrow>  return s t \\<in> R s t) \\<and>\n                          (\\<forall>t. t \\<in> A' s Z \\<longrightarrow> return s t \\<in> A)}\"\n    by blast\n  from this c p show ?thesis\n    by (rule DynProc)\nqed\n\n\nlemma DynProcStaticSpec: \nassumes adapt: \"P \\<subseteq> {s. s \\<in> S \\<and> (\\<exists>Z. init s \\<in> P' Z  \\<and> \n                            (\\<forall>\\<tau>. \\<tau> \\<in> Q' Z \\<longrightarrow> return s \\<tau> \\<in> R s \\<tau>) \\<and>\n                            (\\<forall>\\<tau>. \\<tau> \\<in> A' Z \\<longrightarrow> return s \\<tau> \\<in> A))}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes spec: \"\\<forall>s\\<in>S. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) Call (p s) (Q' Z),(A' Z)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from adapt have P_S: \"P \\<subseteq> S\"\n    by blast\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> S) (dynCall init p return c) Q,A\"\n    apply (rule DynProc [where P'=\"\\<lambda>s Z. P' Z\" and Q'=\"\\<lambda>s Z. Q' Z\" \n                         and A'=\"\\<lambda>s Z. A' Z\", OF _ c])\n    apply  clarsimp\n    apply  (frule in_mono [rule_format, OF adapt])\n    apply  clarsimp\n    using spec\n    apply clarsimp\n    done\n  thus ?thesis\n    by (rule conseqPre) (insert P_S,blast)\nqed\n\n\nlemma DynProcProcPar: \nassumes adapt: \"P \\<subseteq> {s. p s = q \\<and> (\\<exists>Z. init s \\<in> P' Z  \\<and> \n                            (\\<forall>\\<tau>. \\<tau> \\<in> Q' Z \\<longrightarrow> return s \\<tau> \\<in> R s \\<tau>) \\<and>\n                            (\\<forall>\\<tau>. \\<tau> \\<in> A' Z \\<longrightarrow> return s \\<tau> \\<in> A))}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) Call q (Q' Z),(A' Z)\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\n  apply (rule DynProcStaticSpec [where S=\"{s. p s = q}\",simplified, OF adapt c])\n  using spec\n  apply simp\n  done\n\n\nlemma DynProcProcParNoAbrupt: \nassumes adapt: \"P \\<subseteq> {s. p s = q \\<and> (\\<exists>Z. init s \\<in> P' Z  \\<and> \n                            (\\<forall>\\<tau>. \\<tau> \\<in> Q' Z \\<longrightarrow> return s \\<tau> \\<in> R s \\<tau>))}\"\nassumes c: \"\\<forall>s t. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (R s t) (c s t) Q,A\"\nassumes spec: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P' Z) Call q (Q' Z),{}\"\nshows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -  \n  have \"P \\<subseteq> {s. p s = q \\<and> (\\<exists> Z. init s \\<in> P' Z \\<and> \n                      (\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t) \\<and>\n                      (\\<forall>t. t \\<in> {} \\<longrightarrow> return s t \\<in> A))}\"\n    (is \"P \\<subseteq> ?P'\")\n  proof \n    fix s\n    assume P: \"s\\<in>P\"\n    with adapt obtain Z where\n      Pre: \"p s = q \\<and> init s \\<in> P' Z\" and\n      adapt_Norm: \"\\<forall>\\<tau>. \\<tau> \\<in> Q' Z \\<longrightarrow> return s \\<tau> \\<in> R s \\<tau>\" \n      by blast\n    from  adapt_Norm \n    have \"\\<forall>t. t \\<in> Q' Z \\<longrightarrow> return s t \\<in> R s t\"\n      by auto\n    then\n    show \"s\\<in>?P'\"\n      using Pre by blast\n  qed\n  note P = this\n  show ?thesis\n    apply -\n    apply (rule DynProcStaticSpec [where S=\"{s. p s = q}\",simplified, OF P c])\n    apply (insert spec)\n    apply auto\n    done\nqed\n\n\nlemma DynProcModifyReturnNoAbr: \n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause: \n            \"\\<forall>s \\<in> P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} Call (p s)  (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from ret_nrm_modif\n  have \"\\<forall>s t. t  \\<in> (Modif (init s)) \n        \\<longrightarrow> return' s t = return s t\"\n    by iprover\n  then \n  have ret_nrm_modif': \"\\<forall>s t. t \\<in> (Modif (init s)) \n                      \\<longrightarrow> return' s t = return s t\"\n    by simp\n  have ret_abr_modif': \"\\<forall>s t. t \\<in> {} \n                        \\<longrightarrow> return' s t = return s t\"\n    by simp\n  from to_prove ret_nrm_modif' ret_abr_modif' modif_clause show ?thesis\n    by (rule dynProcModifyReturn)\nqed\n\n\nlemma ProcDynModifyReturnNoAbrSameFaults: \n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause: \n            \"\\<forall>s \\<in> P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} (Call (p s)) (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from ret_nrm_modif\n  have \"\\<forall>s t. t  \\<in> (Modif (init s)) \n        \\<longrightarrow> return' s t = return s t\"\n    by iprover\n  then\n  have ret_nrm_modif': \"\\<forall>s t. t \\<in> (Modif (init s)) \n                      \\<longrightarrow> return' s t = return s t\"\n    by simp\n  have ret_abr_modif': \"\\<forall>s t. t \\<in> {} \n                        \\<longrightarrow> return' s t = return s t\"\n    by simp\n  from to_prove ret_nrm_modif' ret_abr_modif' modif_clause show ?thesis\n    by (rule dynProcModifyReturnSameFaults)\nqed\n\n\nlemma ProcProcParModifyReturn: \n  assumes q: \"P \\<subseteq> {s. p s = q} \\<inter> P'\"\n   \\<comment>\\<open>@{thm[source] DynProcProcPar} introduces the same constraint as first conjunction in \n         @{term P'}, so the vcg can simplify it.\\<close>\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes ret_abr_modif: \"\\<forall>s t. t \\<in> (ModifAbr (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause: \n          \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call q) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from to_prove have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return' c) Q,A\"\n    by (rule conseqPre) blast\n  from this ret_nrm_modif \n       ret_abr_modif \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return c) Q,A\"\n    by (rule dynProcModifyReturn) (insert modif_clause,auto)\n  from this q show ?thesis\n    by (rule conseqPre) \nqed\n\n\nlemma ProcProcParModifyReturnSameFaults: \n  assumes q: \"P \\<subseteq> {s. p s = q} \\<inter> P'\"\n   \\<comment>\\<open>@{thm[source] DynProcProcPar} introduces the same constraint as first conjunction in \n         @{term P'}, so the vcg can simplify it.\\<close>\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes ret_abr_modif: \"\\<forall>s t. t \\<in> (ModifAbr (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause: \n          \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call q (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from to_prove \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return' c) Q,A\"\n    by (rule conseqPre) blast\n  from this ret_nrm_modif \n       ret_abr_modif \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return c) Q,A\"\n    by (rule dynProcModifyReturnSameFaults) (insert modif_clause,auto)\n  from this q show ?thesis\n    by (rule conseqPre) \nqed\n\n\nlemma ProcProcParModifyReturnNoAbr: \n  assumes q: \"P \\<subseteq> {s. p s = q} \\<inter> P'\"\n   \\<comment>\\<open>@{thm[source] DynProcProcParNoAbrupt} introduces the same constraint as \n      first conjunction in @{term P'}, so the vcg can simplify it.\\<close>\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause: \n            \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call q) (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from to_prove have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return' c) Q,A\"\n    by (rule conseqPre) blast\n  from this ret_nrm_modif \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return c) Q,A\"\n    by (rule DynProcModifyReturnNoAbr) (insert modif_clause,auto)\n  from this q show ?thesis\n    by (rule conseqPre) \nqed\n\nlemma ProcProcParModifyReturnNoAbrSameFaults: \n  assumes q: \"P \\<subseteq> {s. p s = q} \\<inter> P'\"\n   \\<comment>\\<open>@{thm[source] DynProcProcParNoAbrupt} introduces the same constraint as \n      first conjunction in @{term P'}, so the vcg can simplify it.\\<close>\n  assumes to_prove: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' (dynCall init p return' c) Q,A\"\n  assumes ret_nrm_modif: \"\\<forall>s t. t \\<in> (Modif (init s)) \n                            \\<longrightarrow> return' s t = return s t\"\n  assumes modif_clause: \n            \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} (Call q) (Modif \\<sigma>),{}\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof -\n  from to_prove have \n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return' c) Q,A\"\n    by (rule conseqPre) blast\n  from this ret_nrm_modif \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> ({s. p s = q} \\<inter> P') (dynCall init p return c) Q,A\"\n    by (rule ProcDynModifyReturnNoAbrSameFaults) (insert modif_clause,auto)\n  from this q show ?thesis\n    by (rule conseqPre) \nqed\n\nlemma MergeGuards_iff: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P merge_guards c Q,A = \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (auto intro: MergeGuardsI MergeGuardsD)\n\nlemma CombineStrip': \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c' Q,A\"\n  assumes deriv_strip_triv: \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/{}\\<^esub> P c'' UNIV,UNIV\"\n  assumes c'': \"c''= mark_guards False (strip_guards (-F) c')\"\n  assumes c: \"merge_guards c = merge_guards (mark_guards False c')\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof -\n  from deriv_strip_triv have deriv_strip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c'' UNIV,UNIV\"\n    by (auto intro: hoare_augment_context)\n  from deriv_strip [simplified c'']\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P (strip_guards (- F) c') UNIV,UNIV\"\n    by (rule MarkGuardsD)\n  with deriv \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c' Q,A\"\n    by (rule CombineStrip)\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P mark_guards False c' Q,A\"\n    by (rule MarkGuardsI)\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P merge_guards (mark_guards False c') Q,A\"\n    by (rule MergeGuardsI)\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P merge_guards c Q,A\"\n    by (simp add: c)\n  thus ?thesis\n    by (rule MergeGuardsD)\nqed\n\nlemma CombineStrip'': \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{True}\\<^esub> P c' Q,A\"\n  assumes deriv_strip_triv: \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/{}\\<^esub> P c'' UNIV,UNIV\"\n  assumes c'': \"c''= mark_guards False (strip_guards ({False}) c')\"\n  assumes c: \"merge_guards c = merge_guards (mark_guards False c')\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P c Q,A\"\n  apply (rule CombineStrip' [OF deriv deriv_strip_triv _ c]) \n  apply (insert c'')\n  apply (subgoal_tac \"- {True} = {False}\")\n  apply auto\n  done\n\nlemma AsmUN:\n  \"(\\<Union>Z. {(P Z, p, Q Z,A Z)}) \\<subseteq> \\<Theta> \n  \\<Longrightarrow> \n  \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) (Call p) (Q Z),(A Z)\"\n  by (blast intro: hoarep.Asm)\n\nlemma augment_context': \n  \"\\<lbrakk>\\<Theta> \\<subseteq> \\<Theta>'; \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P Z)  p (Q Z),(A Z)\\<rbrakk> \n   \\<Longrightarrow> \\<forall>Z. \\<Gamma>,\\<Theta>'\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z)\"\n  by (iprover intro: hoare_augment_context)\n\n\nlemma hoarep_strip: \n \"\\<lbrakk>\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z); F' \\<subseteq> -F\\<rbrakk> \\<Longrightarrow> \n    \\<forall>Z. strip F' \\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z)\"\n  by (iprover intro: hoare_strip_\\<Gamma>)\n\nlemma augment_emptyFaults:\n \"\\<lbrakk>\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^bsub>/{}\\<^esub> (P Z) p (Q Z),(A Z)\\<rbrakk> \\<Longrightarrow> \n    \\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z)\"\n  by (blast intro: augment_Faults)\n\nlemma augment_FaultsUNIV:\n \"\\<lbrakk>\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> (P Z) p (Q Z),(A Z)\\<rbrakk> \\<Longrightarrow> \n    \\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^bsub>/UNIV\\<^esub> (P Z) p (Q Z),(A Z)\"\n  by (blast intro: augment_Faults)\n\nlemma PostConjI [trans]:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c R,B\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\n  by (rule PostConjI)\n\nlemma PostConjI' :\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c R,B\\<rbrakk> \n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\n  by (rule PostConjI) iprover+\n\nlemma PostConjE [consumes 1]: \n  assumes conj: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\" \n  assumes E: \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c R,B\\<rbrakk> \\<Longrightarrow> S\"\n  shows \"S\"\nproof -\n  from conj have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\" by (rule conseqPost) blast+\n  moreover\n  from conj have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c R,B\" by (rule conseqPost) blast+\n  ultimately show \"S\" \n    by (rule E)\nqed\n\n\nsubsection \\<open>Rules for Single-Step Proof \\label{sec:hoare-isar}\\<close>\n\ntext \\<open>\n We are now ready to introduce a set of Hoare rules to be used in\n single-step structured proofs in Isabelle/Isar.  \n\n \\medskip Assertions of Hoare Logic may be manipulated in\n calculational proofs, with the inclusion expressed in terms of sets\n or predicates.  Reversed order is supported as well.\n\\<close>\n\nlemma annotateI [trans]:\n\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P anno Q,A; c = anno\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P c Q,A\" \n  by simp\n\nlemma annotate_normI:\n  assumes deriv_anno: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P anno Q,A\" \n  assumes norm_eq: \"normalize c = normalize anno\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P c Q,A\"\nproof -\n  from NormalizeI [OF deriv_anno] norm_eq\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F \\<^esub>P normalize c Q,A\"\n    by simp\n  from NormalizeD [OF this]\n  show ?thesis .\nqed\n\nlemma annotateWhile:\n\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnnoG gs b I V c) Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (while gs b c) Q,A\"\n  by (simp add: whileAnnoG_def)\n\n\nlemma reannotateWhile:\n\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnnoG gs b I V c) Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnnoG gs b J V c) Q,A\"\n  by (simp add: whileAnnoG_def)\n\nlemma reannotateWhileNoGuard:\n\"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnno b I V c) Q,A\\<rbrakk> \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnno b J V c) Q,A\"\n  by (simp add: whileAnno_def)\n\nlemma [trans] : \"P' \\<subseteq> P \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P' c Q,A\"\n  by (rule conseqPre)\n \nlemma [trans]: \"Q \\<subseteq> Q' \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q',A\"\n  by (rule conseqPost) blast+\n\nlemma [trans]:\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s} c Q,A \\<Longrightarrow> (\\<And>s. P' s \\<longrightarrow> P s) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P' s} c Q,A\"\n  by (rule conseqPre) auto\n\nlemma [trans]:\n    \"(\\<And>s. P' s \\<longrightarrow> P s) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s} c Q,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P' s} c Q,A\"\n  by (rule conseqPre) auto\n\nlemma [trans]:\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P c {s. Q s},A \\<Longrightarrow> (\\<And>s. Q s \\<longrightarrow> Q' s) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P c {s. Q' s},A\"\n  by (rule conseqPost) auto\n\nlemma [trans]:\n    \"(\\<And>s. Q s \\<longrightarrow> Q' s) \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P c {s. Q s},A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub>P c {s. Q' s},A\"\n  by (rule conseqPost) auto\n\nlemma [intro?]: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P Skip P,A\"\n  by (rule Skip) auto\n\nlemma CondInt [trans,intro?]:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> b) c1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> - b) c2 Q,A\\<rbrakk>\n   \\<Longrightarrow>\n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (Cond b c1 c2) Q,A\"\n  by (rule Cond) auto\n \nlemma CondConj [trans, intro?]:\n  \"\\<lbrakk>\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s \\<and> b s} c1 Q,A; \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s \\<and> \\<not> b s} c2 Q,A\\<rbrakk>\n   \\<Longrightarrow> \n   \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s} (Cond {s. b s} c1 c2) Q,A\"\n  by (rule Cond) auto\n \nlemma WhileInvInt [intro?]:\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> b) c P,A \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnno b P V c) (P \\<inter> -b),A\"\n  by (rule While) auto\n\nlemma WhileInt [intro?]:\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> (P \\<inter> b) c P,A \n    \\<Longrightarrow> \n    \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P (whileAnno b {s. undefined} V c) (P \\<inter> -b),A\"\n  by (unfold whileAnno_def) \n     (rule HoarePartialDef.While [THEN conseqPrePost],auto)\n\nlemma WhileInvConj [intro?]:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s \\<and> b s} c {s. P s},A\n  \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s} (whileAnno {s. b s} {s. P s} V c) {s. P s \\<and> \\<not> b s},A\"\n  by (simp add: While Collect_conj_eq Collect_neg_eq)\n\nlemma WhileConj [intro?]:\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s \\<and> b s} c {s. P s},A\n    \\<Longrightarrow> \n\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {s. P s} (whileAnno {s. b s} {s. undefined} V c) {s. P s \\<and> \\<not> b s},A\"\n  by (unfold whileAnno_def) \n     (simp add: HoarePartialDef.While [THEN conseqPrePost] \n      Collect_conj_eq Collect_neg_eq)\n\n(* FIXME: Add rules for guarded while *)\n\nend\n", "meta": {"author": "LVPGroup", "repo": "TimSort", "sha": "16437b6b6e2df9f6d32b2a32be7d0d650d83f980", "save_path": "github-repos/isabelle/LVPGroup-TimSort", "path": "github-repos/isabelle/LVPGroup-TimSort/TimSort-16437b6b6e2df9f6d32b2a32be7d0d650d83f980/Simpl/HoarePartial.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632683808533, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.2566024970277928}}
{"text": "section {*L\\_ATS\\_determHIST\\_SDB*}\ntheory\n  L_ATS_determHIST_SDB\n\nimports\n  L_ATS_determHIST_DB\n  L_ATS_determHIST_SB\n\nbegin\n\nlocale ATS_determHIST_SDB =\n  ATS_SchedF_SDB\n  \"TSstructure :: 'TSstructure \\<Rightarrow> bool\"\n  \"configurations :: 'TSstructure \\<Rightarrow> 'conf set\"\n  \"initial_configurations :: 'TSstructure \\<Rightarrow> 'conf set\"\n  \"step_labels :: 'TSstructure \\<Rightarrow> 'label set\"\n  \"step_relation :: 'TSstructure \\<Rightarrow> 'conf \\<Rightarrow> 'label \\<Rightarrow> 'conf \\<Rightarrow> bool\"\n  \"effects :: 'TSstructure \\<Rightarrow> 'event set\"\n  \"marking_condition :: 'TSstructure \\<Rightarrow> ('label, 'conf) derivation \\<Rightarrow> bool\"\n  \"marked_effect :: 'TSstructure \\<Rightarrow> ('label, 'conf) derivation \\<Rightarrow> 'event set\"\n  \"unmarked_effect :: 'TSstructure \\<Rightarrow> ('label, 'conf) derivation \\<Rightarrow> 'event set\"\n  \"fixed_schedulers :: 'TSstructure \\<Rightarrow> 'fixed_scheduler set\"\n  \"empty_fixed_scheduler :: 'TSstructure \\<Rightarrow> 'fixed_scheduler\"\n  \"fixed_scheduler_extendable :: 'TSstructure \\<Rightarrow> 'fixed_scheduler \\<Rightarrow> bool\"\n  \"get_fixed_scheduler :: 'conf \\<Rightarrow> 'fixed_scheduler\"\n  \"get_fixed_scheduler_DB :: 'TSstructure \\<Rightarrow> ('label, 'conf) derivation \\<Rightarrow> nat \\<Rightarrow> 'fixed_scheduler\"\n  +\n  ATS_determHIST_SB\n  \"TSstructure :: 'TSstructure \\<Rightarrow> bool\"\n  \"configurations :: 'TSstructure \\<Rightarrow> 'conf set\"\n  \"initial_configurations :: 'TSstructure \\<Rightarrow> 'conf set\"\n  \"step_labels :: 'TSstructure \\<Rightarrow> 'label set\"\n  \"step_relation :: 'TSstructure \\<Rightarrow> 'conf \\<Rightarrow> 'label \\<Rightarrow> 'conf \\<Rightarrow> bool\"\n  \"effects :: 'TSstructure \\<Rightarrow> 'event set\"\n  \"marking_condition :: 'TSstructure \\<Rightarrow> ('label, 'conf) derivation \\<Rightarrow> bool\"\n  \"marked_effect :: 'TSstructure \\<Rightarrow> ('label, 'conf) derivation \\<Rightarrow> 'event set\"\n  \"unmarked_effect :: 'TSstructure \\<Rightarrow> ('label, 'conf) derivation \\<Rightarrow> 'event set\"\n  \"histories :: 'TSstructure \\<Rightarrow> 'history set\"\n  \"history_fragments :: 'TSstructure \\<Rightarrow> 'history_fragment set\"\n  \"empty_history :: 'TSstructure \\<Rightarrow> 'history\"\n  \"empty_history_fragment :: 'TSstructure \\<Rightarrow> 'history_fragment\"\n  \"set_history :: 'conf \\<Rightarrow> 'history \\<Rightarrow> 'conf\"\n  \"extend_history :: 'history \\<Rightarrow> 'history_fragment \\<Rightarrow> 'history\"\n  \"join_history_fragments :: 'history_fragment \\<Rightarrow> 'history_fragment \\<Rightarrow> 'history_fragment\"\n  \"get_history :: 'conf \\<Rightarrow> 'history\"\n  \"fixed_schedulers :: 'TSstructure \\<Rightarrow> 'fixed_scheduler set\"\n  \"empty_fixed_scheduler :: 'TSstructure \\<Rightarrow> 'fixed_scheduler\"\n  \"fixed_scheduler_extendable :: 'TSstructure \\<Rightarrow> 'fixed_scheduler \\<Rightarrow> bool\"\n  \"get_fixed_scheduler :: 'conf \\<Rightarrow> 'fixed_scheduler\"\n  +\n  ATS_determHIST_DB\n  \"TSstructure :: 'TSstructure \\<Rightarrow> bool\"\n  \"configurations :: 'TSstructure \\<Rightarrow> 'conf set\"\n  \"initial_configurations :: 'TSstructure \\<Rightarrow> 'conf set\"\n  \"step_labels :: 'TSstructure \\<Rightarrow> 'label set\"\n  \"step_relation :: 'TSstructure \\<Rightarrow> 'conf \\<Rightarrow> 'label \\<Rightarrow> 'conf \\<Rightarrow> bool\"\n  \"effects :: 'TSstructure \\<Rightarrow> 'event set\"\n  \"marking_condition :: 'TSstructure \\<Rightarrow> ('label, 'conf) derivation \\<Rightarrow> bool\"\n  \"marked_effect :: 'TSstructure \\<Rightarrow> ('label, 'conf) derivation \\<Rightarrow> 'event set\"\n  \"unmarked_effect :: 'TSstructure \\<Rightarrow> ('label, 'conf) derivation \\<Rightarrow> 'event set\"\n  \"histories :: 'TSstructure \\<Rightarrow> 'history set\"\n  \"history_fragments :: 'TSstructure \\<Rightarrow> 'history_fragment set\"\n  \"empty_history :: 'TSstructure \\<Rightarrow> 'history\"\n  \"empty_history_fragment :: 'TSstructure \\<Rightarrow> 'history_fragment\"\n  \"set_history :: 'conf \\<Rightarrow> 'history \\<Rightarrow> 'conf\"\n  \"extend_history :: 'history \\<Rightarrow> 'history_fragment \\<Rightarrow> 'history\"\n  \"join_history_fragments :: 'history_fragment \\<Rightarrow> 'history_fragment \\<Rightarrow> 'history_fragment\"\n  \"get_history :: 'conf \\<Rightarrow> 'history\"\n  \"fixed_schedulers :: 'TSstructure \\<Rightarrow> 'fixed_scheduler set\"\n  \"empty_fixed_scheduler :: 'TSstructure \\<Rightarrow> 'fixed_scheduler\"\n  \"fixed_scheduler_extendable :: 'TSstructure \\<Rightarrow> 'fixed_scheduler \\<Rightarrow> bool\"\n  \"get_fixed_scheduler_DB :: 'TSstructure \\<Rightarrow> ('label, 'conf) derivation \\<Rightarrow> nat \\<Rightarrow> 'fixed_scheduler\"\n  for\n    TSstructure configurations initial_configurations step_labels step_relation effects marking_condition marked_effect unmarked_effect fixed_schedulers empty_fixed_scheduler fixed_scheduler_extendable get_fixed_scheduler get_fixed_scheduler_DB histories history_fragments empty_history empty_history_fragment set_history extend_history join_history_fragments get_history\n\ncontext ATS_determHIST_SDB begin\n\nlemma AX_is_forward_edge_deterministic_correspond_DB_SB: \"\n  TSstructure G\n  \\<Longrightarrow> is_forward_edge_deterministicHist_SB_long G = is_forward_edge_deterministicHist_DB_long G\"\n  apply(rule order_antisym)\n   apply(clarsimp)\n   apply(simp add: is_forward_edge_deterministicHist_SB_long_def is_forward_edge_deterministicHist_DB_long_def)\n   apply(clarsimp)\n   apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n   apply(erule_tac\n      x=\"c\"\n      in ballE)\n    apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n    apply(erule_tac\n      x=\"c1\"\n      in allE)\n    apply(erule_tac\n      x=\"c2\"\n      in allE)\n    apply(erule_tac\n      x=\"e1\"\n      in allE)\n    apply(erule_tac\n      x=\"e2\"\n      in allE)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"w1\"\n      in allE)\n    apply(clarsimp)\n    apply(erule_tac\n      x=\"w2\"\n      in allE)\n    apply(clarsimp)\n    apply(subgoal_tac \"(get_fixed_scheduler_DB G (derivation_append d (der2 c e1 c1) n) (Suc n)) = ((get_fixed_scheduler c1))\")\n     apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n     apply(subgoal_tac \"(get_fixed_scheduler_DB G (derivation_append d (der2 c e2 c2) n) (Suc n)) = ((get_fixed_scheduler c2))\")\n      apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n      apply(force)\n     apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n     apply(rule AX_state_based_vs_derivation_based_get_fixed_scheduler)\n       apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n       apply(force)\n      apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n      apply(rule derivation_append_preserves_derivation_initial)\n        apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n        apply(force)\n       apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n       apply(force)\n      apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n      apply(rule derivation_append_preserves_derivation)\n        apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n        apply(rule derivation_initial_is_derivation)\n        apply(force)\n       apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n       apply(rule der2_is_derivation)\n       apply(force)\n      apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n      apply(clarsimp)\n      apply(simp add: get_configuration_def)\n      apply(case_tac \"d n\")\n       apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n       apply(force)\n      apply(rename_tac c d n c1 c2 e1 e2 w1 w2 a)(*strict*)\n      apply(clarsimp)\n      apply(case_tac a)\n      apply(rename_tac c d n c1 c2 e1 e2 w1 w2 a option b)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac c d n c1 c2 e1 e2 w1 w2 option)(*strict*)\n      apply(simp add: der2_def)\n     apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n     apply(simp add: derivation_append_def der2_def)\n    apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n    apply(rule AX_state_based_vs_derivation_based_get_fixed_scheduler)\n      apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n      apply(force)\n     apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n     apply(rule derivation_append_preserves_derivation_initial)\n       apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n       apply(force)\n      apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n      apply(force)\n     apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n     apply(rule derivation_append_preserves_derivation)\n       apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n       apply(rule derivation_initial_is_derivation)\n       apply(force)\n      apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n      apply(rule der2_is_derivation)\n      apply(force)\n     apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n     apply(simp add: get_configuration_def)\n     apply(case_tac \"d n\")\n      apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n      apply(force)\n     apply(rename_tac c d n c1 c2 e1 e2 w1 w2 a)(*strict*)\n     apply(clarsimp)\n     apply(case_tac a)\n     apply(rename_tac c d n c1 c2 e1 e2 w1 w2 a option b)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac c d n c1 c2 e1 e2 w1 w2 option)(*strict*)\n     apply(simp add: der2_def)\n    apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n    apply(simp add: derivation_append_def der2_def)\n   apply(rename_tac c d n c1 c2 e1 e2 w1 w2)(*strict*)\n   apply(simp add: get_accessible_configurations_def)\n  apply(simp add: is_forward_edge_deterministicHist_SB_long_def is_forward_edge_deterministicHist_DB_long_def get_accessible_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n  apply(erule_tac\n      x=\"c\"\n      in allE)\n  apply(erule_tac\n      x=\"d\"\n      in allE)\n  apply(erule_tac\n      x=\"i\"\n      in allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"c1\"\n      in allE)\n  apply(erule_tac\n      x=\"c2\"\n      in allE)\n  apply(erule_tac\n      x=\"e1\"\n      in allE)\n  apply(erule_tac\n      x=\"e2\"\n      in allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"w1\"\n      in allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"w2\"\n      in allE)\n  apply(clarsimp)\n  apply(subgoal_tac \"(get_fixed_scheduler_DB G (derivation_append d (der2 c e1 c1) i) (Suc i)) = ((get_fixed_scheduler c1))\")\n   apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n   apply(subgoal_tac \"(get_fixed_scheduler_DB G (derivation_append d (der2 c e2 c2) i) (Suc i)) = ((get_fixed_scheduler c2))\")\n    apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n    apply(force)\n   apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n   apply(rule AX_state_based_vs_derivation_based_get_fixed_scheduler)\n     apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n     apply(force)\n    apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n    apply(rule derivation_append_preserves_derivation_initial)\n      apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n      apply(force)\n     apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n     apply(force)\n    apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n    apply(rule derivation_append_preserves_derivation)\n      apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n      apply(rule derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n     apply(rule der2_is_derivation)\n     apply(force)\n    apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n    apply(clarsimp)\n    apply(simp add: get_configuration_def)\n    apply(case_tac \"d i\")\n     apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n     apply(force)\n    apply(rename_tac c d c1 c2 e1 e2 i w1 w2 a)(*strict*)\n    apply(clarsimp)\n    apply(case_tac a)\n    apply(rename_tac c d c1 c2 e1 e2 i w1 w2 a option b)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c d c1 c2 e1 e2 i w1 w2 option)(*strict*)\n    apply(simp add: der2_def)\n   apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n   apply(simp add: derivation_append_def der2_def)\n  apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n  apply(rule AX_state_based_vs_derivation_based_get_fixed_scheduler)\n    apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n    apply(force)\n   apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n   apply(rule derivation_append_preserves_derivation_initial)\n     apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n     apply(force)\n    apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n    apply(force)\n   apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n   apply(rule derivation_append_preserves_derivation)\n     apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n     apply(rule derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n    apply(rule der2_is_derivation)\n    apply(force)\n   apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(case_tac \"d i\")\n    apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n    apply(force)\n   apply(rename_tac c d c1 c2 e1 e2 i w1 w2 a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac c d c1 c2 e1 e2 i w1 w2 a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d c1 c2 e1 e2 i w1 w2 option)(*strict*)\n   apply(simp add: der2_def)\n  apply(rename_tac c d c1 c2 e1 e2 i w1 w2)(*strict*)\n  apply(simp add: derivation_append_def der2_def)\n  done\n\nlemma AX_is_forward_target_deterministic_correspond_DB_SB: \"\n  TSstructure G\n  \\<Longrightarrow> is_forward_target_deterministicHist_SB_long G = is_forward_target_deterministicHist_DB_long G\"\n  apply(rule order_antisym)\n   apply(clarsimp)\n   apply(simp add: is_forward_target_deterministicHist_SB_long_def is_forward_target_deterministicHist_DB_long_def)\n   apply(clarsimp)\n   apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n   apply(erule_tac\n      x=\"c\"\n      in ballE)\n    apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n    apply(erule_tac\n      x=\"c1\"\n      in allE)\n    apply(erule_tac\n      x=\"c2\"\n      in allE)\n    apply(erule impE)\n     apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n     apply(rule_tac\n      x=\"e\"\n      in exI)\n     apply(clarsimp)\n     apply(rule_tac\n      x=\"w1\"\n      in exI)\n     apply(clarsimp)\n     apply(rule_tac\n      x=\"w2\"\n      in exI)\n     apply(clarsimp)\n     apply(subgoal_tac \"(get_fixed_scheduler_DB G (derivation_append d (der2 c e c1) n) (Suc n)) = ((get_fixed_scheduler c1))\")\n      apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n      apply(subgoal_tac \"(get_fixed_scheduler_DB G (derivation_append d (der2 c e c2) n) (Suc n)) = ((get_fixed_scheduler c2))\")\n       apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n       apply(force)\n      apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n      apply(rule AX_state_based_vs_derivation_based_get_fixed_scheduler)\n        apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n        apply(force)\n       apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n       apply(rule derivation_append_preserves_derivation_initial)\n         apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n         apply(force)\n        apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n        apply(force)\n       apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n       apply(rule derivation_append_preserves_derivation)\n         apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n         apply(rule derivation_initial_is_derivation)\n         apply(force)\n        apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n        apply(rule der2_is_derivation)\n        apply(force)\n       apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n       apply(clarsimp)\n       apply(simp add: get_configuration_def)\n       apply(case_tac \"d n\")\n        apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n        apply(force)\n       apply(rename_tac c d n c1 c2 e w1 w2 a)(*strict*)\n       apply(clarsimp)\n       apply(case_tac a)\n       apply(rename_tac c d n c1 c2 e w1 w2 a option b)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac c d n c1 c2 e w1 w2 option)(*strict*)\n       apply(simp add: der2_def)\n      apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n      apply(simp add: derivation_append_def der2_def)\n     apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n     apply(rule AX_state_based_vs_derivation_based_get_fixed_scheduler)\n       apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n       apply(force)\n      apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n      apply(rule derivation_append_preserves_derivation_initial)\n        apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n        apply(force)\n       apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n       apply(force)\n      apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n      apply(rule derivation_append_preserves_derivation)\n        apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n        apply(rule derivation_initial_is_derivation)\n        apply(force)\n       apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n       apply(rule der2_is_derivation)\n       apply(force)\n      apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n      apply(simp add: get_configuration_def)\n      apply(case_tac \"d n\")\n       apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n       apply(force)\n      apply(rename_tac c d n c1 c2 e w1 w2 a)(*strict*)\n      apply(clarsimp)\n      apply(case_tac a)\n      apply(rename_tac c d n c1 c2 e w1 w2 a option b)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac c d n c1 c2 e w1 w2 option)(*strict*)\n      apply(simp add: der2_def)\n     apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n     apply(simp add: derivation_append_def der2_def)\n    apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n    apply(force)\n   apply(rename_tac c d n c1 c2 e w1 w2)(*strict*)\n   apply(simp add: get_accessible_configurations_def)\n  apply(simp add: is_forward_target_deterministicHist_SB_long_def is_forward_target_deterministicHist_DB_long_def get_accessible_configurations_def)\n  apply(clarsimp)\n  apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n  apply(erule_tac\n      x=\"c\"\n      in allE)\n  apply(erule_tac\n      x=\"d\"\n      in allE)\n  apply(erule_tac\n      x=\"i\"\n      in allE)\n  apply(clarsimp)\n  apply(erule_tac\n      x=\"c1\"\n      in allE)\n  apply(erule_tac\n      x=\"c2\"\n      in allE)\n  apply(erule impE)\n   apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n   prefer 2\n   apply(force)\n  apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n  apply(rule_tac\n      x=\"e\"\n      in exI)\n  apply(clarsimp)\n  apply(rule_tac\n      x=\"w1\"\n      in exI)\n  apply(clarsimp)\n  apply(rule_tac\n      x=\"w2\"\n      in exI)\n  apply(clarsimp)\n  apply(subgoal_tac \"(get_fixed_scheduler_DB G (derivation_append d (der2 c e c1) i) (Suc i)) = ((get_fixed_scheduler c1))\")\n   apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n   apply(subgoal_tac \"(get_fixed_scheduler_DB G (derivation_append d (der2 c e c2) i) (Suc i)) = ((get_fixed_scheduler c2))\")\n    apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n    apply(force)\n   apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n   apply(rule AX_state_based_vs_derivation_based_get_fixed_scheduler)\n     apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n     apply(force)\n    apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n    apply(rule derivation_append_preserves_derivation_initial)\n      apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n      apply(force)\n     apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n     apply(force)\n    apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n    apply(rule derivation_append_preserves_derivation)\n      apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n      apply(rule derivation_initial_is_derivation)\n      apply(force)\n     apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n     apply(rule der2_is_derivation)\n     apply(force)\n    apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n    apply(simp add: get_configuration_def)\n    apply(case_tac \"d i\")\n     apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n     apply(force)\n    apply(rename_tac c d c1 c2 i e w1 w2 a)(*strict*)\n    apply(clarsimp)\n    apply(case_tac a)\n    apply(rename_tac c d c1 c2 i e w1 w2 a option b)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac c d c1 c2 i e w1 w2 option)(*strict*)\n    apply(simp add: der2_def)\n   apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n   apply(simp add: derivation_append_def der2_def)\n  apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n  apply(rule AX_state_based_vs_derivation_based_get_fixed_scheduler)\n    apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n    apply(force)\n   apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n   apply(rule derivation_append_preserves_derivation_initial)\n     apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n     apply(force)\n    apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n    apply(force)\n   apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n   apply(rule derivation_append_preserves_derivation)\n     apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n     apply(rule derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n    apply(rule der2_is_derivation)\n    apply(force)\n   apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n   apply(simp add: get_configuration_def)\n   apply(case_tac \"d i\")\n    apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n    apply(force)\n   apply(rename_tac c d c1 c2 i e w1 w2 a)(*strict*)\n   apply(clarsimp)\n   apply(case_tac a)\n   apply(rename_tac c d c1 c2 i e w1 w2 a option b)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac c d c1 c2 i e w1 w2 option)(*strict*)\n   apply(simp add: der2_def)\n  apply(rename_tac c d c1 c2 i e w1 w2)(*strict*)\n  apply(simp add: derivation_append_def der2_def)\n  done\n\nlemma is_forward_deterministic_correspond_DB_SB: \"\n  TSstructure G\n  \\<Longrightarrow> is_forward_deterministicHist_SB G = is_forward_deterministicHist_DB G\"\n  apply (metis AX_is_forward_edge_deterministic_correspond_DB_SB AX_is_forward_target_deterministic_correspond_DB_SB is_forward_deterministicHist_DB_def is_forward_deterministicHist_SB_def)\n  done\n\nend\n\nend\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_06_04/L_ATS_determHIST_SDB.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982043529715, "lm_q2_score": 0.3960681662740417, "lm_q1q2_score": 0.25657224691369834}}
{"text": "theory flash110Rev imports flashPub\nbegin\nsection{*Main defintions*}\nlemma NI_FAckVsInv110:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv110 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_InvVsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1VsInv110:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1_HomeVsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_2VsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_GetXVsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_Nak1VsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_Nak2VsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_Nak3VsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_PutX1VsInv110:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv110:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv110:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv110:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv110:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv110:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv110:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv110:  \n  (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv110:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_PutX10VsInv110:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_PutX10_homeVsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_PutX11VsInv110:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_Get_GetVsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Nak1VsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Nak2VsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Nak3VsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Put1VsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Put2VsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Put3VsInv110:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma NI_Local_PutVsInv110:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n     have allCases:\"formEval  ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true ))  s  \\<or>formEval   (neg ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true )) )  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume b1:\"formEval ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true ))  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n\n    moreover\n                       {assume b1:\"formEval  (neg ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true )) )  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_PutXAcksDoneVsInv110:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv110 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_NakVsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Nak_ClearVsInv110:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv110 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_Nak_HomeVsInv110:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv110 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Remote_GetX_NakVsInv110:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_Nak_HomeVsInv110:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Remote_GetX_PutXVsInv110:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_PutX_HomeVsInv110:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Remote_Get_Nak1VsInv110:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Remote_Get_Nak2VsInv110:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Put1VsInv110:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Remote_Get_Put2VsInv110:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_PutVsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_PutXVsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceVsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceHomeVsInv110:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv110 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_ReplaceHomeShrVldVsInv110:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv110 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_ReplaceShrVldVsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ShWbVsInv110:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv110 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_WbVsInv110:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv110 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_GetX_GetX1VsInv110:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv110 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_GetX2VsInv110:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv110 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX1VsInv110:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv110 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX2VsInv110:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv110 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX3VsInv110:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv110 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX4VsInv110:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv110 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_Get_GetVsInv110:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv110 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P3 s\"\n\n         \n        apply(    simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' Home) )  ( Const CACHE_S ))    ( eqn ( IVar ( Para ''CacheState'' Home) )  ( Const CACHE_I ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma PI_Local_Get_PutVsInv110:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv110 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n     have allCases:\"formEval  ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true ))  s  \\<or>formEval   (neg ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true )) )  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume b1:\"formEval ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true ))  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n\n    moreover\n                       {assume b1:\"formEval  (neg ( eqn ( IVar ( Para ''InvMarked'' Home) )  ( Const true )) )  s\"\n\n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))    ( eqn ( IVar ( Para ''procCmd'' Home) )  ( Const NODE_None ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n    }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Local_PutXVsInv110:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv110 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_ReplaceVsInv110:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv110 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Remote_GetVsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_GetXVsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_PutXVsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_ReplaceVsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma StoreVsInv110:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv110 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma StoreHomeVsInv110:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv110 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash110Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5660185351961015, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.25655460727394686}}
{"text": "theory RCU_Lems imports OpSem_ProofRules \"HOL-Hoare_Parallel.OG_Syntax\"\nbegin\n\n\n(*\nlemma d_obs_diff_false [simp]:\n  assumes  \"[x =\\<^sub>t u] \\<sigma>\"\nand \"[x =\\<^sub>t' v] \\<sigma>\"\nand \"u \\<noteq> v\"\nshows \"False\"\n  using assms\n  by (simp add: d_obs_def d_obs_t_def)  \n*)\n\nlemma p_obs_contradiction_2 :\n  assumes \"wfs \\<sigma>\"\n  and \"\\<not> [x \\<approx>\\<^sub>t v] \\<sigma>\"\n  and \" getVW \\<sigma> t' y = w\"\nshows \"\\<not> [x \\<approx>\\<^sub>t v] (read_trans t' b w \\<sigma>)\"\n  using OpSemExtProof.p_obs_contradiction assms(1) assms(2) assms(3) by blast\n\n\nlemma not_p_obs_other_value  :\n  assumes \"wfs \\<sigma>\"\n      and \"\\<not>[x \\<approx>\\<^sub>t u] \\<sigma>\"\n      and \"var w = x\"\n      and \"ts' = getTS \\<sigma> w\"\n      and \"u \\<noteq> v\"\n      and \"t \\<noteq> t'\"\n    shows \"\\<not>[x \\<approx>\\<^sub>t u] (write_trans t' b w v \\<sigma> ts')\"\n  using assms\n  apply simp\n  apply(unfold  write_trans_def rev_app_def update_wa_def update_thrView_def update_modView_def update_mods_def)\n  apply simp\n  apply (unfold p_obs_def)\n  apply safe\n  apply(simp add: value_def)\n\n  apply(case_tac \"a = var w \\<and> ba = getTS \\<sigma> w\", simp_all)\n  apply(simp add: visible_writes_def)\n  unfolding writes_on_def apply clarsimp \n  by blast\n\nlemma c_obs_same_var_read_pres[simp]:\n  assumes \"wfs \\<sigma>\"\nand \" [x = u]\\<lparr>x =\\<^sub>t u\\<rparr> \\<sigma>\"\nand \"w = getVW \\<sigma> t' y\"\nshows \"[x = u]\\<lparr>x =\\<^sub>t u\\<rparr> (read_trans t' b w \\<sigma>)\"\n  using assms\n  apply (case_tac \"x \\<noteq> y\")\n  apply(simp add: c_obs_def visible_writes_def value_def d_obs_def)\n  apply(simp add: read_trans_def rev_app_def)\n  apply(unfold  writes_on_def lastWr_def, simp)\n  apply(simp add: update_wa_def update_thrView_def update_mods_def update_modView_def)\n  apply(case_tac \"x = var (getVW \\<sigma> t y)\", simp_all)\n   apply (simp add: getVW_var)\n  apply safe\n  apply(simp_all add:releasing_def)\n     apply (smt fun_upd_other order.trans ts_oride_def)\n    apply (smt fun_upd_other order.trans ts_oride_def)\n  apply (smt fun_upd_other order.trans ts_oride_def)\n  apply(simp add: c_obs_def visible_writes_def value_def d_obs_def)\n  apply(simp add: read_trans_def  rev_app_def)\n  apply(unfold  writes_on_def lastWr_def, simp)\n  apply(simp add: update_wa_def update_thrView_def update_mods_def update_modView_def)\n  apply safe\n  apply(simp_all add:releasing_def visible_writes_def)\n  apply (smt CollectD dual_order.trans getVW_in_vw ts_oride_same_var visible_writes_def)\n  apply (smt CollectD dual_order.trans getVW_in_vw ts_oride_same_var visible_writes_def)\n  apply (smt CollectD dual_order.trans getVW_in_vw ts_oride_same_var visible_writes_def)\n  apply (smt CollectD dual_order.trans getVW_in_vw ts_oride_same_var visible_writes_def)\n  apply (smt CollectD dual_order.trans getVW_in_vw ts_oride_same_var visible_writes_def)\n  apply (smt CollectD dual_order.trans getVW_in_vw ts_oride_same_var visible_writes_def)\n  by (simp add: getVW_var)+\n\n(*\"x = var w\"*)\nlemma c_obs_same_var_write_pres[simp]:\n  assumes \"wfs \\<sigma>\"\nand \"[x =\\<^sub>t u] \\<sigma>\"\nand \"\\<not> [x \\<approx>\\<^sub>t' u] \\<sigma>\"\nand \"w = getVWNC \\<sigma> t x\" \nand \"ts' = getTS \\<sigma> w\"\nshows \"[x = u]\\<lparr>x =\\<^sub>t' u\\<rparr> (write_trans t b w u \\<sigma> ts')\"\n  using assms\n  apply(simp add: c_obs_def visible_writes_def value_def d_obs_def)\n  apply(simp add: write_trans_def rev_app_def)\n  apply(unfold  writes_on_def lastWr_def, simp)\n  apply(simp add: update_wa_def update_thrView_def update_mods_def update_modView_def)\n  by (metis d_obs_def d_obs_t_def lastWr_visible p_obs_def)\n\n\n\nlemma c_obs_same_var_write_pres_diff[simp]:\n  assumes \"wfs \\<sigma>\"\nand \"[x =\\<^sub>t v] \\<sigma>\"\nand \"\\<not> [x \\<approx>\\<^sub>t' u] \\<sigma>\"\nand \"getVWNC \\<sigma> t x = w\"\nand \"ts' = getTS \\<sigma> w\"\nshows \"[x = u]\\<lparr>x =\\<^sub>t' u\\<rparr> (write_trans t True w u \\<sigma> ts')\"\nproof - \n  from assms have a1: \"[x =\\<^sub>t u] (write_trans t True w u \\<sigma> ts')\"\n    using OpSemExtProof.ext_d_obs_d_obs by blast\n  show ?thesis\n  using assms a1\n  apply(simp add: c_obs_def p_obs_def d_obs_t_def visible_writes_def value_def d_obs_def)\n  apply(simp add: write_trans_def rev_app_def)\n  apply(unfold  writes_on_def lastWr_def, simp)\n  apply(simp add: update_wa_def update_thrView_def update_mods_def update_modView_def)\n  apply safe\n  apply (simp_all add: getVW_var releasing_def)\n         apply auto[2]\n  apply (metis (no_types, lifting) assms(2) d_obs_def d_obs_t_def dual_order.trans getTS_w_greater_tst_w getVWNC_lastWr less_eq_rat_def snd_conv)\n  apply (metis (no_types, lifting) assms(2) d_obs_def d_obs_t_def dual_order.trans getTS_w_greater_tst_w getVWNC_lastWr less_eq_rat_def snd_conv)\n  by blast+\nqed\n\n\n\n\nlemma c_obs_same_var_write_same_var_pres[simp]:\n  assumes \"wfs \\<sigma>\"\nand \" [x = u]\\<lparr>x =\\<^sub>t u\\<rparr> \\<sigma>\"\nand \"w = getVWNC \\<sigma> t' x\"\nand \"ts' = getTS \\<sigma> w\"\nand \"[x =\\<^sub>t' z] \\<sigma>\"\nand \"v \\<noteq> u\"\nand \"z \\<noteq> u\"\nshows \"[x = u]\\<lparr>x =\\<^sub>t u\\<rparr> (write_trans t' b w v \\<sigma> ts')\"\n  using assms\n  apply(simp add: c_obs_def visible_writes_def value_def d_obs_def d_obs_t_def)\n  apply(simp add: write_trans_def  rev_app_def)\n  apply(unfold  writes_on_def lastWr_def, simp)\n  apply(simp add: update_wa_def update_thrView_def update_mods_def update_modView_def)\n  apply(case_tac \"x \\<noteq> var (getVWNC \\<sigma> t' x)\", simp_all)\n   apply (simp add: getVWNC_var)\n  apply(case_tac \"t = t'\", simp_all)\n  apply(simp_all add: releasing_def)\n  apply(intro conjI impI allI)\n  apply (metis (no_types, lifting) assms(5) d_obs_def d_obs_t_def dual_order.strict_trans getVWNC_in_writes_on getVWNC_lastWr getTS_w_greater_tst_w last_write_max2 not_le_imp_less order.not_eq_order_implies_strict) \n  apply (metis (no_types, lifting) assms(5) d_obs_def d_obs_t_def dual_order.strict_trans getVWNC_in_writes_on getVWNC_lastWr getTS_w_greater_tst_w last_write_max2 not_le_imp_less order.not_eq_order_implies_strict)\n  apply (metis (no_types, lifting) assms(5) d_obs_def d_obs_t_def dual_order.strict_trans getVWNC_in_writes_on getVWNC_lastWr getTS_w_greater_tst_w last_write_max2 not_le_imp_less order.not_eq_order_implies_strict)\n  by (metis (no_types, lifting) assms(5) d_obs_def d_obs_t_def dual_order.strict_trans getVWNC_in_writes_on getVWNC_lastWr getTS_w_greater_tst_w last_write_max2 not_le_imp_less order.not_eq_order_implies_strict)\n\n\n\nlemma c_obs_write_diff_var_pres[simp]:\n  assumes \"wfs \\<sigma>\"\nand \" [x = u]\\<lparr>x =\\<^sub>t u\\<rparr> \\<sigma>\"\nand \" y \\<noteq>x\"\nand \"w = getVWNC \\<sigma> t' y\"\nand \"ts' = getTS \\<sigma> w\"\nshows \"[x = u]\\<lparr>x =\\<^sub>t u\\<rparr> (write_trans t' b w v \\<sigma> ts')\"\n  using assms\n  apply(simp add: c_obs_def visible_writes_def value_def d_obs_def d_obs_t_def)\n  apply(simp add: write_trans_def  rev_app_def)\n  apply(unfold  writes_on_def lastWr_def, simp)\n  apply(simp add: update_wa_def update_thrView_def update_mods_def update_modView_def)\n  apply(case_tac \"x \\<noteq> var (getVWNC \\<sigma> t' x)\", simp_all)\n   apply (simp add: getVWNC_var)\n  apply(case_tac \"t = t'\", simp_all)\n  apply(simp_all add: releasing_def)\n   apply(intro conjI impI allI)\n  apply (simp_all add: getVWNC_var) \n  apply (metis fst_conv)\n  apply (smt Collect_cong fst_conv)\n  apply (metis fst_conv)\n  apply (smt Collect_cong fst_conv)\n  by (smt Collect_cong fst_conv)\n\n  \nlemma no_val_maintain:\n  assumes \"wfs \\<sigma>\"\nand \"[\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>\"\nand \"getVWNC \\<sigma> t y = w\"\nand \"y \\<noteq> x\"\nand \"getTS \\<sigma> w = ts'\"\nshows \"[\\<zero>\\<^sub>x u]\\<^sub>i (write_trans t b w v \\<sigma> ts')\"\n  using assms\n  apply(simp add: no_val_def p_vorder_def value_def mo_def init_val_def)\n  apply(elim conjE impE exE)\n  apply (simp add: write_trans_def)\n  apply safe\n   apply(subgoal_tac \"var w = y\", simp)\n  prefer 2\n    apply (simp add: getVWNC_var)\n    apply (simp add: rev_app_def update_wa_def update_mods_def update_thrView_def update_modView_def)\n  apply (unfold writes_on_def, clarsimp)\n    apply metis\n    apply (simp add: rev_app_def update_wa_def update_mods_def update_thrView_def update_modView_def)\n  apply (clarsimp)    \n  by (simp add: getVWNC_var)\n\nlemma d_order_stable:\n  assumes \"wfs \\<sigma>\"\nand \"[i \\<hookrightarrow>\\<^sub>x u] \\<sigma>\"\nshows \"[i \\<hookrightarrow>\\<^sub>x u] (read_trans t' b w \\<sigma>)\"\n  using assms\n  by(simp add: d_vorder_def p_vorder_def value_def)\n\n(*\nlemma dvorder_intro:\n  assumes \"wfs \\<sigma>\"\n    and \"[\\<one>\\<^sub>x u] \\<sigma>\"\n    and \"[\\<zero>\\<^sub>x v]\\<^sub>i \\<sigma>\"\nand \"[x =\\<^sub>t u] \\<sigma>\"\nand \"w = getVWNC \\<sigma> t x\"\nand \"ts' = getTS \\<sigma> w\"\nand \"v \\<noteq> u\"\nand \"i \\<noteq> u\"\nand \"i \\<noteq> v\"\nshows \"[u \\<hookrightarrow>\\<^sub>x v] (write_trans t b w v \\<sigma> ts')\"\n*)\n\nlemma no_val_d_order:\n  assumes \"wfs \\<sigma>\"\nand \"[x =\\<^sub>t i] \\<sigma>\"\nand \"[\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>\"\nand \"getVWNC \\<sigma> t x = w\"\nand \"getTS \\<sigma> w = ts'\"\nand \"u \\<noteq> i\"\nshows \"[i \\<hookrightarrow>\\<^sub>x u] (write_trans t b w u \\<sigma> ts')\"\nproof - \n  have a1: \"[en x i]\\<^sub>t \\<sigma>\"\n  using assms\n  apply(simp add: no_val_def enc_t_def enc_def value_def mo_def init_val_def d_vorder_def d_obs_t_def d_obs_def)\n  by (metis eq_iff less_imp_le sndI wfs_def)  \n  show ?thesis\n  using assms a1\n    apply(subgoal_tac \"var w = x\") \n   defer\n  using getVWNC_var apply blast\n  apply(simp add: d_obs_def no_val_def init_val_def enc_t_def enc_def amo_def d_vorder_def p_vorder_def mo_def d_obs_t_def)\n  apply(intro conjI allI impI)\n  apply (metis w_in_writes_on_var)\n   apply(elim conjE exE)\n   apply (unfold writes_on_def value_def, clarsimp)\n     apply(simp add: write_trans_def rev_app_def update_mods_def update_wa_def update_modView_def update_thrView_def)\n   apply (case_tac \"a = x \\<and> ba = getTS \\<sigma> (getVWNC \\<sigma> t x)\", simp_all)\n  apply (case_tac \"aa = x \\<and> baa = getTS \\<sigma> (getVWNC \\<sigma> t x)\", simp_all)\n  apply (metis dual_order.strict_trans fst_conv getTS_w_greater_tst_w getVWNC_lastWr in_writes_onI last_write_max2 less_linear)\n  apply blast\n   apply(elim conjE exE)\n  apply(simp add: write_trans_def rev_app_def update_mods_def update_wa_def update_modView_def update_thrView_def)\n  by (metis dual_order.strict_trans2 getVWNC_lastWr getts_greater_than leD)\nqed\n\n\n\nlemma d_order_write_twice:\n  assumes \"wfs \\<sigma>\"\nand \"[u \\<hookrightarrow>\\<^sub>x v] \\<sigma>\"\nand \"[x =\\<^sub>t v] \\<sigma>\"\nand \"getVWNC \\<sigma> t x = w\"\nand \"getTS \\<sigma> w = ts'\"\nshows \"[u \\<hookrightarrow>\\<^sub>x v] (write_trans t b w v \\<sigma> ts')\"\n  using assms \n    apply(subgoal_tac \"var w = x\") \n   defer\n  using getVWNC_var apply blast\n  apply(unfold d_obs_def no_val_def init_val_def enc_t_def enc_def amo_def d_vorder_def p_vorder_def mo_def d_obs_t_def)\n  apply(intro conjI allI impI)\n    apply(elim conjE exE)\n  apply (metis writes_on_var)\n   apply (unfold writes_on_def value_def, clarsimp)\n     apply(simp add: write_trans_def rev_app_def update_mods_def update_wa_def update_modView_def update_thrView_def)\n   apply (case_tac \"baa = getTS \\<sigma> (getVWNC \\<sigma> t x)\", simp_all)\n    apply (case_tac \"ba = getTS \\<sigma> (getVWNC \\<sigma> t x)\", simp_all)\n  apply blast \n  apply (metis fst_conv getVWNC_lastWr getts_greater_than less_le_not_le less_trans modView_lte_last neqE own_ModView sndI)\n  apply (case_tac \"ba = getTS \\<sigma> (getVWNC \\<sigma> t x)\", simp_all)\n  apply blast\n  apply(simp add: write_trans_def rev_app_def update_mods_def update_wa_def update_modView_def update_thrView_def)\n  by (metis fst_conv in_writes_onI w_not_in_writes_on)\n\n\nlemma no_val_d_order_one:\n  assumes \"wfs \\<sigma>\"\nand \"[\\<one>\\<^sub>x i] \\<sigma>\"\nand \"[\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma>\"\nand \"getVWNC \\<sigma> t x = w\"\nand \"getTS \\<sigma> w = ts'\"\nand \"u \\<noteq> i\"\nshows \"[i \\<hookrightarrow>\\<^sub>x u] (write_trans t b w u \\<sigma> ts')\"\nproof - \n  have a1: \"[en x i]\\<^sub>t \\<sigma>\"\n  using assms\n  apply(simp add: no_val_def enc_t_def enc_def value_def mo_def init_val_def d_vorder_def)\n  by (metis eq_iff less_imp_le sndI wfs_def)  \n  show ?thesis\n  using assms a1\n    apply(subgoal_tac \"var w = x\") \n   defer\n  using getVWNC_var apply blast\n  apply(simp add: d_obs_def no_val_def init_val_def enc_t_def enc_def amo_def d_vorder_def p_vorder_def mo_def d_obs_t_def)\n  apply(intro conjI allI impI)\n  apply (metis w_in_writes_on_var)\n   apply(elim conjE exE)\n   apply (unfold writes_on_def value_def, clarsimp)\n     apply(simp add: write_trans_def rev_app_def update_mods_def update_wa_def update_modView_def update_thrView_def)\n   apply (case_tac \"a = x \\<and> ba = getTS \\<sigma> (getVWNC \\<sigma> t x)\", simp_all)\n  apply (case_tac \"aa = x \\<and> baa = getTS \\<sigma> (getVWNC \\<sigma> t x)\", simp_all)\n  apply (smt CollectD getTS_w_greater_tst_w getVWNC_in_visible_writes less_le_trans not_le visible_writes_def)\n  apply blast\n   apply(elim conjE exE)\n     apply(simp add: write_trans_def rev_app_def update_mods_def update_wa_def update_modView_def update_thrView_def)\n  by (metis Set.basic_monos(7) getTS_w_greater_tst_w getVWNC_in_visible_writes le_less_trans less_eq_rat_def prod.exhaust_sel visible_writes_in_writes)\nqed\n(*\n  sledgehammer\n  apply (simp add: w_in_writes_on_var)\n  sorry\n     apply (metis dual_order.trans getVWNC_lastWr getTS_w_greater_tst_w last_write_max2 less_eq_rat_def not_less_iff_gr_or_eq)\n  apply (meson w_in_writes_on_var)\n   apply(simp add: value_def)\n     apply(simp add: write_trans_def rev_app_def update_mods_def update_wa_def update_modView_def update_thrView_def)\n  apply(case_tac \"a = x \\<and>\n               ba = getTS \\<sigma> (getVWNC \\<sigma> t x)\", simp)\n  apply(case_tac \"aa = x \\<and>\n               baa = getTS \\<sigma> (getVWNC \\<sigma> t x)\", simp) \n    apply (metis getVWNC_lastWr getts_greater_than last_write_max2)\n  apply simp \n   apply (metis w_in_writes_on_var w_is)\n  apply (simp add: value_def)\n  apply(rule_tac x = x in exI)\n  apply simp\n       apply(simp add: write_trans_def rev_app_def update_mods_def update_wa_def update_modView_def update_thrView_def)\n  by (metis getVWNC_in_writes_on getVWNC_lastWr getts_greater_than w_is)\n*)\n\n(*\n\n       [0 \\<hookrightarrow>\\<^sub>x Suc 0] \\<sigma> xa \\<or> [x =\\<^sub>3 0] \\<sigma> xa \\<Longrightarrow>\n       wfs (\\<sigma> xa) \\<Longrightarrow>\n       w \\<noteq> x \\<Longrightarrow>\n       r xa = Suc 0 \\<Longrightarrow>\n       \\<forall>j. 0 < j \\<and> j \\<noteq> Suc 0 \\<longrightarrow> \\<not> [x \\<approx>\\<^sub>2 j] \\<sigma> xa \\<Longrightarrow>\n       [en x Suc 0]\\<^sub>2 \\<sigma> xa \\<Longrightarrow>\n       j \\<noteq> Suc 0 \\<Longrightarrow>\n       [x \\<approx>\\<^sub>2 j] \\<sigma> xa \\<Longrightarrow> [x =\\<^sub>3 Suc 0] \\<sigma> xa \\<Longrightarrow> False\n*)\n\nlemma d_vorder_not_pobs: \n  assumes \"wfs \\<sigma>\"\nand \"[u \\<hookrightarrow>\\<^sub>x v] \\<sigma>\"\nand \"[en x v]\\<^sub>t \\<sigma>\"\nshows \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  using assms \n  apply(simp add: p_obs_def enc_def enc_t_def d_vorder_def p_vorder_def) \n  by (metis (mono_tags) dual_order.trans leD mem_Collect_eq mo_def snd_conv visible_writes_def writes_on_def)\n\n\nlemma c_obs_pres_write_diff_var_ext_2  :\n  assumes \"wfs \\<sigma>\"\n      and \"[x = u]\\<lparr>y =\\<^sub>t v\\<rparr> \\<sigma>\"\n      and \"getVWNC \\<sigma> t' z = w\"\n      and \"x \\<noteq> z\"\n      and \"y \\<noteq> z\" \n      and \"t \\<noteq> t'\"\n      and \" getTS \\<sigma> w = ts'\"\n    shows \"[x = u]\\<lparr>y =\\<^sub>t v\\<rparr> (write_trans t' b w v' \\<sigma> ts')\"\n  using assms\n  apply(simp add: p_obs_def d_obs_def d_obs_t_def c_obs_def visible_writes_def value_def)\n  apply(intro conjI impI allI, elim conjE)\n    apply (unfold writes_on_def write_trans_def rev_app_def update_wa_def\n        update_mods_def getVWNC_var lastWr_def update_modView_def update_thrView_def value_def, simp)\n    apply safe[1]\n  using getVWNC_var apply (blast+)[3]\n  using getVWNC_var apply (blast+)[3]\n  apply (case_tac \"x = var (getVWNC \\<sigma> t' z) \\<and> ba = getTS \\<sigma> (getVWNC \\<sigma> t' z)\", simp_all)\n  apply (metis eq_fst_iff)\n  apply (metis eq_fst_iff)\n    apply safe[1]\n  using getVWNC_var apply (blast+)[3]\n  apply (case_tac \"x = var (getVWNC \\<sigma> t' z) \\<and> ba = getTS \\<sigma> (getVWNC \\<sigma> t' z)\", simp_all)\n  using getVWNC_var apply (blast+)[2]\n  apply (case_tac \"x = var (getVWNC \\<sigma> t' z) \\<and> ba = getTS \\<sigma> (getVWNC \\<sigma> t' z)\", simp_all)\n  using getVWNC_var apply blast\n  apply (smt Collect_cong fst_conv)\n  apply (case_tac \"x = var (getVWNC \\<sigma> t' z) \\<and> ba = getTS \\<sigma> (getVWNC \\<sigma> t' z)\", simp_all)\n  using getVWNC_var apply blast\n  apply (smt Collect_cong fst_conv getVWNC_var)\n    apply safe[1]\n  using getVWNC_var apply blast\n  apply (case_tac \"x = var (getVWNC \\<sigma> t' z) \\<and> ba = getTS \\<sigma> (getVWNC \\<sigma> t' z)\", simp_all)\n  using getVWNC_var apply blast\n  apply (clarsimp)\n  by (metis (no_types, lifting) Pair_inject fun_upd_same fun_upd_triv fun_upd_twist releasing_def surrey_state.select_convs(4) surrey_state.surjective surrey_state.update_convs(1) surrey_state.update_convs(4) surrey_state.update_convs(5))\n\nend", "meta": {"author": "MSemenyuk", "repo": "PhD_Isabelle", "sha": "179f5d346a721b15940a271323e3487f4ea51338", "save_path": "github-repos/isabelle/MSemenyuk-PhD_Isabelle", "path": "github-repos/isabelle/MSemenyuk-PhD_Isabelle/PhD_Isabelle-179f5d346a721b15940a271323e3487f4ea51338/Amazon Ring Buffer/RCU_Lems.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297746074044134, "lm_q2_score": 0.4073334000459302, "lm_q1q2_score": 0.25652823209663056}}
{"text": "theory flash89Rev imports flashPub\nbegin\nsection{*Main defintions*}\nlemma NI_FAckVsInv89:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n     have allCases:\"formEval   (neg ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const true )) )  s  \\<or>formEval  ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const true ))  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume b1:\"formEval  (neg ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const true )) )  s\"\nhave \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n    }\n\n    moreover\n                       {assume b1:\"formEval ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const true ))  s\"\n\n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''ShWbMsg_Cmd'') )  ( Const SHWB_FAck ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n    }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_InvVsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_InvAck_1VsInv89:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1_HomeVsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_InvAck_2VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_GetXVsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_Nak1VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_Nak2VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_Nak3VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_PutX1VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv89:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10VsInv89:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10_homeVsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX11VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_GetVsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_Get_Nak1VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_Get_Nak2VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_Get_Nak3VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_Get_Put1VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_Get_Put2VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put3VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_PutVsInv89:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_PutXAcksDoneVsInv89:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_NakVsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Nak_ClearVsInv89:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Nak_HomeVsInv89:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Remote_GetX_NakVsInv89:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_Nak_HomeVsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_PutXVsInv89:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_PutX_HomeVsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Nak1VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Nak2VsInv89:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Put1VsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Put2VsInv89:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutVsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                     have allCases:\"formEval  ( eqn ( IVar ( Para ''InvMarked'' iInv2) )  ( Const true ))  s  \\<or>formEval   (neg ( eqn ( IVar ( Para ''InvMarked'' iInv2) )  ( Const true )) )  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume c1:\"formEval ( eqn ( IVar ( Para ''InvMarked'' iInv2) )  ( Const true ))  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1  c1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n\n    moreover\n                       {assume c1:\"formEval  (neg ( eqn ( IVar ( Para ''InvMarked'' iInv2) )  ( Const true )) )  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1  c1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n   ultimately have \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutXVsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv1))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))  )    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Get ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_ReplaceVsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_ReplaceHomeVsInv89:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceHomeShrVldVsInv89:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceShrVldVsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_ShWbVsInv89:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_WbVsInv89:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_GetX1VsInv89:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_GetX2VsInv89:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX1VsInv89:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX2VsInv89:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX3VsInv89:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX4VsInv89:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_Get_GetVsInv89:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv1))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  )    ( eqn ( IVar ( Para ''CacheState'' iInv2) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma PI_Local_Get_PutVsInv89:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_PutXVsInv89:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_ReplaceVsInv89:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_GetVsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma PI_Remote_GetXVsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma PI_Remote_PutXVsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_ReplaceVsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma StoreVsInv89:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma StoreHomeVsInv89:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv89  iInv1  iInv2 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash89Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5467381372136564, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.25630571394485524}}
{"text": "theory List_Less\n  imports\n    \"HOL-Library.List_Lexorder\"\n    \"Isabelle_LLVM.LLVM_DS_Array_List\"\n    \"../Setup\"\n    \"../Separation_Logic_Solver/Methods\"\n    Arl_Ext\n    \"../Bool_Assn_Setup\"\nbegin\n\n\npartial_function (M) list_le'\n  :: \"(8 word, 'l::len2) array_list \\<Rightarrow> (8 word, 'l) array_list \\<Rightarrow> 'l word \\<Rightarrow> 1 word llM\"  where\n  \"list_le' xs ys i =\n  doM {\n    len_left \\<leftarrow> arl_len xs;\n    len_right \\<leftarrow> arl_len ys;\n\n    if i < len_right\n    then if i < len_left\n      then doM {\n        x \\<leftarrow> arl_nth xs i;\n        y \\<leftarrow> arl_nth ys i;\n        le \\<leftarrow> ll_icmp_ult x y;\n        if le = 1\n        then Mreturn ll_True\n        else doM {\n          ge \\<leftarrow> ll_icmp_ult y x;\n          if ge = 1 \n          then Mreturn ll_False\n          else list_le' xs ys (i+1)\n        }\n      }\n      else Mreturn ll_True\n    else Mreturn ll_False\n  }\n\"\n\n\nabbreviation \"string_assn str (stri:: (8 word, 'l::len2) array_list) \\<equiv>\n   \\<up>(LENGTH('l) > 4) ** (EXS ws. \\<upharpoonleft>arl_assn ws stri ** \\<up>(length ws = length str) **\n   \\<up>(\\<forall>i < length str. \\<flat>\\<^sub>punat.assn (str ! i) (ws ! i)))\"\n\n(*\nabbreviation \"string_assn str (stri:: (8 word, 'l::len2) array_list) \\<equiv> arl_elem_assn snat.assn str stri\"\n*)\n\nlemma postfix_le: \n  \"\\<lbrakk>i < length xs; i < length ys\\<rbrakk> \\<Longrightarrow> drop i xs < drop i ys = (xs ! i < ys ! i \\<or> xs ! i = ys ! i \\<and> drop (i+1) xs < drop (i+1) ys)\"  \n  by (auto simp add: drop_Suc_nth)\n\n\nlemma arl_length_snat_bound:  \n  \"pure_part (\\<upharpoonleft>arl_assn xs (xsi :: ('a::llvm_rep, 'l::len2) array_list))\n   \\<Longrightarrow> length xs < 2 ^ (LENGTH('l)-1)\"\n  unfolding arl_assn_def dr_assn_prefix_def mk_assn_def\n  unfolding arl_assn'_def mk_assn_def\n  apply (cases xsi)\n  apply simp\nproof -\n  fix li ci ai\n  assume \"pure_part (\\<lambda>s. \\<exists>c l a. (\\<upharpoonleft>snat.assn l (li::'l word) \\<and>*\n                                    \\<upharpoonleft>snat.assn c (ci::'l word) \\<and>*\n                                    \\<upharpoonleft>narray_assn a ai \\<and>*\n                                    \\<up>(4 < LENGTH('l) \\<and> l \\<le> c \\<and> c = length a \\<and> xs = take l a)) s)\"\n\n  then obtain c l a  where pp: \"pure_part (\\<upharpoonleft>snat.assn l li \\<and>*\n                                    \\<upharpoonleft>snat.assn c ci \\<and>*\n                                    \\<upharpoonleft>narray_assn a ai \\<and>*\n                                    \\<up>(4 < LENGTH('l) \\<and> l \\<le> c \\<and> c = length a \\<and> xs = take l a))\"\n    unfolding pure_part_def\n    by auto\n\n  from pp have \"xs = take l a\"\n    by (auto dest!: pure_part_split_conj)\n\n  hence length_le: \"length xs \\<le> l\" by simp\n\n  from pp have \"\\<flat>\\<^sub>psnat.assn l li\"\n    apply (auto dest!: pure_part_split_conj)\n    by (simp add: snat.assn_def)\n  hence \"l \\<in> snats LENGTH('l)\"\n    by (simp add: snat.assn_def)\n  hence \"l < 2 ^ (LENGTH('l)-1)\"\n    unfolding snats_def by blast\n\n  with length_le show \"length xs < 2 ^ (LENGTH('l) - Suc 0)\" \n    by simp\nqed\n\n\n\n\n\nlemma [simp]: \"i < length xs \\<Longrightarrow> [] < drop i xs\" by simp\n\n\nlemma list_le'_rule:\n  \"\n  llvm_htriple\n  (string_assn xs xsi ** string_assn ys ysi ** \\<upharpoonleft>snat.assn i ii)\n  (list_le' xsi ysi ii)\n  (\\<lambda>r. \\<upharpoonleft>bool.assn (drop i xs < drop i ys) r ** string_assn xs xsi ** string_assn ys ysi )\n\"\nproof(induction \"min (length xs) (length ys) - i\" arbitrary: i ii)\n  case 0\n  then show ?case\n    apply (subst list_le'.simps)\n    apply vcg\n    subgoal by simp (*unreachable recursive path*)\n     apply vcg\n    done\n\nnext\n  case (Suc x)\n  from Suc(2) have precond: \"x = min (length xs) (length ys) - (i+1)\" by simp\n\n  note Suc(1)[OF precond, vcg_rules]\n\n  show ?case\n    apply (subst list_le'.simps)\n    apply vcg\n    subgoal for asf x xa r ra s\n      apply vcg_rl back\n       apply vcg_compat\n       apply (sep isep_intro: pure_pure_asm_prefixI | find_sep)+\n        apply (auto simp add: SOLVE_AUTO_DEFER_def)\n       apply vcg_solve\n       apply vcg \n       apply vcg_compat\n\n       apply (sepE isep_intro: pure_pure_asm_prefixI | find_sep)+\n             apply (auto simp add: postfix_le)\n      apply vcg_solve\n      apply vcg\n      apply vcg_rl back \n       apply vcg_compat\n       apply (sepwith \\<open>auto\\<close> isep_intro: pure_pure_asm_prefixI) \n      apply vcg_solve\n      apply vcg\n      apply vcg_rl\n       apply vcg_compat\n       apply (sepEwith simp isep_intro: pure_pure_asm_prefixI)\n        apply simp_all\n      subgoal \n        unfolding dr_assn_pure_asm_prefix_def snat.assn_def snat_invar_def\n        apply (rule conjI)\n         apply simp_all\n        by (smt (verit) Suc_eq_plus1 less_trans_Suc linorder_not_less msb_unat_big snat_eq_unat(1) unat_1 unat_plus_if' unsigned_less)\n      apply isep_intro_ex\n      apply (sepwith simp)\n      apply vcg_solve+\n      done\n    subgoal by vcg\n    subgoal by vcg\n    done\nqed\n\n\nunbundle monad_syntax_M\n\n\npartial_function (M) list_le''\n  :: \"(8 word, 'l::len2) array_list \\<Rightarrow> (8 word, 'l) array_list \\<Rightarrow> 'l word \\<Rightarrow> 1 word llM\"  where\n  \"list_le'' xs ys i =\n  do {\n    len_left \\<leftarrow> arl_len xs;\n    len_right \\<leftarrow> arl_len ys;\n\n    if i < len_right\n    then if i < len_left\n      then do {\n        x \\<leftarrow> arl_nth xs i;\n        y \\<leftarrow> arl_nth ys i;\n        le \\<leftarrow> ll_icmp_ult x y;\n        if le = 1\n        then return ll_True\n        else do {\n          ge \\<leftarrow> ll_icmp_ult y x;\n          if ge = 1 \n          then return ll_False\n          else do {ip1 \\<leftarrow> ll_add i 1; list_le'' xs ys ip1}\n        }\n      }\n      else return ll_True\n    else return ll_False\n  }\n\"\n\n\nlemmas list_le''.simps[llvm_code]\n\n\nlemma list_le''_rule:\n  \"\n  llvm_htriple\n  (string_assn xs xsi ** string_assn ys ysi ** \\<upharpoonleft>snat.assn i ii)\n  (list_le'' xsi ysi ii)\n  (\\<lambda>r. \\<upharpoonleft>bool.assn (drop i xs < drop i ys) r ** string_assn xs xsi ** string_assn ys ysi )\n\"\nproof(induction \"min (length xs) (length ys) - i\" arbitrary: i ii)\n  case 0\n  then show ?case \n    apply (subst list_le''.simps)\n    apply vcg\n    subgoal by simp (*unreachable recursive path*)\n     apply vcg\n    done\nnext\n  case (Suc x)\n  show ?case\n    apply (subst list_le''.simps)\n    apply vcg\n    subgoal for asf x xa r ra s\n      apply vcg_rl back\n       apply vcg_compat\n       apply (sep isep_intro: pure_pure_asm_prefixI | find_sep)+\n        apply (auto simp add: SOLVE_AUTO_DEFER_def)\n       apply vcg_solve\n       apply vcg\n       apply vcg_compat\n       apply (sepE isep_intro: pure_pure_asm_prefixI | find_sep)+\n             apply (auto simp add: postfix_le)\n      apply vcg_solve\n      apply vcg\n      apply vcg_rl back\n       apply vcg_compat\n       apply (sepwith auto isep_intro: pure_pure_asm_prefixI)\n      apply vcg_solve\n      apply vcg\n      supply Suc(1)[vcg_rules]\n      apply vcg\n      subgoal using Suc(2) by simp\n      apply vcg\n      done\n    subgoal by vcg\n    subgoal by vcg\n    done\nqed\n\n\ndefinition \"list_le xsi ysi \\<equiv> list_le'' xsi ysi 0\"\n\n\nlemmas list_le_def[llvm_code, llvm_inline]\n\n\nlemma list_le_rule:\n  \"\n  llvm_htriple\n  (string_assn xs xsi ** string_assn ys ysi)\n  (list_le xsi ysi)\n  (\\<lambda>r. \\<upharpoonleft>bool.assn (xs < ys) r ** string_assn xs xsi ** string_assn ys ysi )\n\"\n  unfolding list_le_def\n  supply list_le''_rule[vcg_rules]\n  by vcg\n\n\nend", "meta": {"author": "leanderBehr", "repo": "isabelle-llvm-RBT", "sha": "9456c7160d0d190bdb3ac358bc0058d22fb19926", "save_path": "github-repos/isabelle/leanderBehr-isabelle-llvm-RBT", "path": "github-repos/isabelle/leanderBehr-isabelle-llvm-RBT/isabelle-llvm-RBT-9456c7160d0d190bdb3ac358bc0058d22fb19926/LLVM_DS_RBT/Example/List_Less.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5851011397337391, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.25617102833393324}}
{"text": "theory PF_Predicates\n  imports\n  \"../PF_Primitives\"\n  PF_Matching_Ternary\nbegin\nfun all_match :: \"('a \\<Rightarrow> bool) \\<Rightarrow> 'a match_expr  \\<Rightarrow> bool\" where\n\"all_match _ MatchAny = True\" |\n\"all_match P (MatchNot m) = all_match P m\" |\n\"all_match P (MatchAnd m1 m2) = (all_match P m1 \\<and> all_match P m2)\" |\n\"all_match P (Match m) = P m\"\n\ndefinition no_ipv6 :: \"common_primitive match_expr \\<Rightarrow> bool\" where\n\"no_ipv6 mexpr =\nall_match (\\<lambda>m. (case m of\n(Src (Hostspec (Address (IPv6 _)))) \\<Rightarrow> False\n| (Dst (Address (IPv6 _))) \\<Rightarrow> False\n| _ \\<Rightarrow> True)) mexpr\"\n\ndefinition no_af :: \"common_primitive match_expr \\<Rightarrow> bool\" where\n\"no_af mexpr = all_match (\\<lambda>m. (case m of (Address_Family _) \\<Rightarrow> False| _ \\<Rightarrow> True)) mexpr\"\n\ndefinition no_anyhost :: \"common_primitive match_expr \\<Rightarrow> bool\" where\n\"no_anyhost mexpr = all_match (\\<lambda>m. (case m of (Src (Hostspec AnyHost)) \\<Rightarrow> False\n                                              | (Dst AnyHost) \\<Rightarrow> False\n                                              | _ \\<Rightarrow> True)) mexpr\"\n\ndefinition good_match_expr :: \"pfcontext \\<Rightarrow> common_primitive match_expr \\<Rightarrow> bool\" where\n\"good_match_expr ctx mexpr = all_match (good_primitive ctx) mexpr\"\n\nfun all_AnchorRules_P :: \"('a anchor_rule \\<Rightarrow> bool) \\<Rightarrow> 'a ruleset \\<Rightarrow> bool\" where\n\"all_AnchorRules_P P rs = (\\<forall> l \\<in> set rs. (case l of (Anchor r b) \\<Rightarrow> P r \\<and> all_AnchorRules_P P b | _ \\<Rightarrow> True))\"\n\nfun all_AnchorRules_P' :: \"('a anchor_rule \\<Rightarrow> bool) \\<Rightarrow> 'a ruleset \\<Rightarrow> bool\" where\n\"all_AnchorRules_P' _ [] \\<longleftrightarrow> True\" |\n\"all_AnchorRules_P' P ((PfRule r)#ls) \\<longleftrightarrow> all_AnchorRules_P' P ls\" |\n\"all_AnchorRules_P' P ((Anchor r b)#ls) \\<longleftrightarrow> P r \\<and> all_AnchorRules_P' P b \\<and> all_AnchorRules_P' P ls\"\n\nlemma \"all_AnchorRules_P P l= all_AnchorRules_P' P l\"\n  by (induction P l rule: all_AnchorRules_P'.induct) auto\n\nlemma all_AnchorRules_P_append[simp]:\n  \"all_AnchorRules_P P (xs @ ys) \\<longleftrightarrow> all_AnchorRules_P P xs \\<and> all_AnchorRules_P P ys\"\n  by (induction P xs rule: all_AnchorRules_P.induct) auto\n\ndefinition no_anchors' :: \"'a ruleset \\<Rightarrow> bool\" where\n\"no_anchors' rs = all_AnchorRules_P (\\<lambda>r. False) rs\"\n\nlemma no_anchors_no_anchors'_eq:\n \"no_anchors rs \\<longleftrightarrow> no_anchors' rs\"\n  unfolding no_anchors'_def\n  by (induction rs) (auto split:line.splits)\n\n\ndefinition no_unknown_anchors :: \"('a,'p) match_tac \\<Rightarrow> 'a ruleset \\<Rightarrow> bool\" where\n\"no_unknown_anchors \\<gamma> rs = all_AnchorRules_P\n (\\<lambda>r. (\\<forall> p. ternary_ternary_eval (map_match_tac (fst \\<gamma>) p (anchor_rule.get_match r)) \\<noteq> TernaryUnknown))\n rs\"\n\n\nfun all_PfRules_P :: \"('a pf_rule \\<Rightarrow> bool) \\<Rightarrow> 'a ruleset \\<Rightarrow> bool\" where\n\"all_PfRules_P P rs = (\\<forall> l \\<in> set rs. (case l of (PfRule r) \\<Rightarrow> P r | (Anchor r b) \\<Rightarrow> all_PfRules_P P b))\"\n\nfun all_PfRules_P' :: \"('a pf_rule \\<Rightarrow> bool) \\<Rightarrow> 'a ruleset \\<Rightarrow> bool\" where\n\"all_PfRules_P' _ [] \\<longleftrightarrow> True\" |\n\"all_PfRules_P' P ((PfRule r)#ls) \\<longleftrightarrow> P r \\<and> all_PfRules_P' P ls\" |\n\"all_PfRules_P' P ((Anchor r b)#ls) \\<longleftrightarrow> all_PfRules_P' P b \\<and> all_PfRules_P' P ls\"\n\nlemma \"all_PfRules_P P l= all_PfRules_P' P l\"\n  by (induction P l rule: all_PfRules_P'.induct) auto\n\nlemma all_PfRules_P_append[simp]:\n  \"all_PfRules_P P (xs @ ys) \\<longleftrightarrow> all_PfRules_P P xs \\<and> all_PfRules_P P ys\"\n  by (induction P xs rule: all_PfRules_P.induct) auto\n\ndefinition no_match_quick :: \"'a ruleset \\<Rightarrow> bool\" where\n\"no_match_quick rs = all_PfRules_P (\\<lambda>r. \\<not>((pf_rule.get_action r) = ActionMatch \\<and> pf_rule.get_quick r)) rs\"\n\n\ndefinition wf_ruleset :: \"pfcontext \\<Rightarrow> common_primitive ruleset \\<Rightarrow> bool\" where\n\"wf_ruleset ctx rs = (all_PfRules_P (\\<lambda>r. good_match_expr ctx (pf_rule.get_match r)) rs \\<and> all_AnchorRules_P (\\<lambda>a. good_match_expr ctx (anchor_rule.get_match a)) rs)\"\n\nlemma wf_ruleset_append[simp]:\n\"wf_ruleset ctx (xs @ ys) \\<longleftrightarrow> wf_ruleset ctx xs \\<and> wf_ruleset ctx ys\"\n  unfolding wf_ruleset_def\n  using all_PfRules_P_append[of \"(\\<lambda>r. good_match_expr ctx (pf_rule.get_match r))\" xs ys]\n  all_AnchorRules_P_append[of \"(\\<lambda>r. good_match_expr ctx (anchor_rule.get_match r))\" xs ys]\n  by blast\n\ndefinition no_tables :: \"common_primitive match_expr \\<Rightarrow> bool\" where\n\"no_tables mexpr = all_match\n                    (\\<lambda>m. (case m of\n                      (Src (Hostspec (Table _))) \\<Rightarrow> False\n                      |(Dst (Table _)) \\<Rightarrow> False\n                      | _ \\<Rightarrow> True))\n                    mexpr\"\n\ndefinition no_tables_rs :: \"common_primitive ruleset \\<Rightarrow> bool\" where\n\"no_tables_rs = all_PfRules_P (\\<lambda>r. no_tables (pf_rule.get_match r))\"\n\ndefinition normalized_ports :: \"common_primitive match_expr \\<Rightarrow> bool\" where\n\"normalized_ports mexpr =\nall_match\n(\\<lambda>m. (case m of\n(Src_Ports (L4Ports _ (Binary bop))) \\<Rightarrow> is_RangeIncl bop\n| (Src_Ports (L4Ports _ (Unary _))) \\<Rightarrow> False\n| (Dst_Ports (L4Ports _ (Binary bop))) \\<Rightarrow> is_RangeIncl bop\n| (Dst_Ports (L4Ports _ (Unary _))) \\<Rightarrow> False\n| _ \\<Rightarrow> True))\nmexpr\"\n\ndefinition normalized_ports_rs :: \"common_primitive ruleset \\<Rightarrow> bool\" where\n\"normalized_ports_rs = all_PfRules_P (\\<lambda>r. normalized_ports (pf_rule.get_match r))\"\n\ndefinition no_ipv6_rs :: \"common_primitive ruleset \\<Rightarrow> bool\" where\n\"no_ipv6_rs = all_PfRules_P (\\<lambda>r. no_ipv6 (pf_rule.get_match r))\"\n\ndefinition no_af_rs :: \"common_primitive ruleset \\<Rightarrow> bool\" where\n\"no_af_rs = all_PfRules_P (\\<lambda>r. no_af (pf_rule.get_match r))\"\n\ndefinition no_anyhost_rs :: \"common_primitive ruleset \\<Rightarrow> bool\" where\n\"no_anyhost_rs = all_PfRules_P (\\<lambda>r. no_anyhost (pf_rule.get_match r))\"\n\nend", "meta": {"author": "Sohalt", "repo": "pf-verification", "sha": "328f850913723dee6c9f6be069fbbc22a3762354", "save_path": "github-repos/isabelle/Sohalt-pf-verification", "path": "github-repos/isabelle/Sohalt-pf-verification/pf-verification-328f850913723dee6c9f6be069fbbc22a3762354/SemanticsTernary/PF_Predicates.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.640635854839898, "lm_q2_score": 0.3998116407397951, "lm_q1q2_score": 0.25613367224028083}}
{"text": "section \\<open>Generic Block Allocator --- Resoning Setup\\<close>\ntheory Sep_Block_Allocator_RS\nimports Sep_Lift \"../basic/LLVM_Basic_Main\"\nbegin\n\n  lemma list\\<alpha>_at_len: \"list\\<alpha> \\<alpha> xs (length xs) = 0\"\n    by (auto simp: list\\<alpha>_def)\n  \n  lemma list\\<alpha>_gt_len: \"i\\<ge>length xs \\<Longrightarrow> list\\<alpha> \\<alpha> xs i = 0\"\n    by (auto simp: list\\<alpha>_def)\n  \n  lemma list\\<alpha>_snoc: \"list\\<alpha> \\<alpha> (xs@[x]) = 0(length xs := \\<alpha> x) + list\\<alpha> \\<alpha> xs\"\n    apply (rule ext)\n    apply (auto simp: list\\<alpha>_def nth_append)\n    done\n    \n  lemma list\\<alpha>_in_range: \"list\\<alpha> \\<alpha> xs i \\<noteq> 0 \\<Longrightarrow> i<length xs\"\n    by (auto simp: list\\<alpha>_def split: if_splits)\n  \n  lemma list\\<alpha>_in_rangeD: \"list\\<alpha> \\<alpha> xs = x \\<Longrightarrow> x i \\<noteq> 0 \\<Longrightarrow> i<length xs\"\n    by (auto simp: list\\<alpha>_def split: if_splits)\n\n  lemma list\\<alpha>_splitE:\n    assumes \"list\\<alpha> \\<alpha> xs = fun_upd 0 i p + fun_upd f i 0\"  \n    assumes \"p\\<noteq>0\"\n    obtains \"i<length xs\" \"\\<alpha> (xs!i) = p\"\n    using assms \n    by (auto simp: list\\<alpha>_def fun_eq_iff split: if_splits)\n    \n  lemma option\\<alpha>_splitE:  \n    assumes \"option\\<alpha> \\<alpha> v = p\"\n    assumes \"p\\<noteq>0\"\n    obtains x where \"v=Some x\" \"\\<alpha> x = p\"\n    using assms by (cases v) auto\n\n  locale block_allocator2 = block_allocator1 static_err mem_err bload bstore bcheck_addr\n    for static_err :: 'err\n    and mem_err :: 'err\n    and bload :: \"'baddr::this_addr \\<Rightarrow> ('val,_,'block,'err) M\"\n    and bstore :: \"'val \\<Rightarrow> 'baddr \\<Rightarrow> (unit,_,'block,'err) M\"\n    and bcheck_addr :: \"'baddr \\<Rightarrow> (unit,_,'block,'err) M\"\n    \n  + fixes \\<alpha>b :: \"'block \\<Rightarrow> 'ablock::unique_zero_sep_algebra\"\n      and bpto :: \"'val \\<Rightarrow> 'baddr \\<Rightarrow> 'ablock \\<Rightarrow> bool\"\n      and tag_of :: \"'block \\<Rightarrow> 'tag\"\n      and is_complete_tag :: \"'ablock \\<Rightarrow> 'tag \\<Rightarrow> bool\"\n      \n    assumes bload_rule: \"\\<And>x a. htriple \\<alpha>b (bpto x a) (bload a) (\\<lambda>r. \\<up>(r=x) ** bpto x a)\"\n        and bstore_rule: \"\\<And>x xx a. htriple \\<alpha>b (bpto xx a) (bstore x a) (\\<lambda>_. bpto x a)\"\n        and bload_pres_tag: \"\\<And>s a. wlp (bload a) (\\<lambda>_ s'. tag_of s' = tag_of s) s\"\n        and bstore_pres_tag: \"\\<And>s a x. wlp (bstore a x) (\\<lambda>_ s'. tag_of s' = tag_of s) s\"\n        and complete_tag: \n          \"\\<And>f. \\<lbrakk>is_complete_tag ablock (tag_of cblock); ablock ## f; \\<alpha>b cblock = ablock + f\\<rbrakk> \\<Longrightarrow> f=0\"\n        and bpto_notZ: \"\\<And>x a. \\<not>bpto x a 0\"\n  begin\n  \n    definition \\<alpha>tag :: \"'block \\<Rightarrow> 'tag tsa_opt\" where \"\\<alpha>tag blk \\<equiv> TRIV (tag_of blk)\"\n    definition \\<alpha> :: \"'block memory \\<Rightarrow> nat \\<Rightarrow> 'ablock \\<times> 'tag tsa_opt\" \n      where \"\\<alpha> \\<equiv> \\<lambda>MEMORY blocks \\<Rightarrow> list\\<alpha> (option\\<alpha> (\\<lambda>x. (\\<alpha>b x, \\<alpha>tag x))) blocks\"\n    definition pto :: \"'val \\<Rightarrow> 'baddr addr rptr \\<Rightarrow> (nat \\<Rightarrow> 'ablock \\<times> 'tag tsa_opt) \\<Rightarrow> bool\" \n      where \"pto x \\<equiv> \\<lambda>RP_ADDR (ADDR bi ba) \\<Rightarrow> \\<lambda>s. \\<exists>ablk. s=0(bi:=(ablk,0)) \\<and> bpto x ba ablk | _ \\<Rightarrow> sep_false\"\n    \n    definition tag :: \"'tag \\<Rightarrow> 'baddr addr rptr \\<Rightarrow> (nat \\<Rightarrow> 'ablock \\<times> 'tag tsa_opt) \\<Rightarrow> bool\" \n      where \"tag t \\<equiv> \\<lambda>RP_ADDR (ADDR bi ba) \\<Rightarrow> EXACT (0(bi:=(0,TRIV t))) ** \\<up>(ba=this_addr \\<and> t\\<in>range tag_of) | _ \\<Rightarrow> sep_false\"\n    definition block :: \"'ablock \\<Rightarrow> 'baddr addr rptr \\<Rightarrow> (nat \\<Rightarrow> 'ablock \\<times> 'tag tsa_opt) \\<Rightarrow> bool\"\n      where \"block b \\<equiv> \\<lambda>RP_ADDR (ADDR bi ba) \\<Rightarrow> EXACT (0(bi:=(b,0))) ** \\<up>(ba=this_addr) | _ \\<Rightarrow> sep_false\"\n  \n    \n    lemma alloc_rule: \"htriple \\<alpha> \\<box> (alloc b) (\\<lambda>r. block (\\<alpha>b b) r ** tag (tag_of b) r)\"\n      apply (rule htripleI')\n      apply (auto simp: alloc_def wp_def run_simps sep_algebra_simps split: option.splits)\n    proof -\n      fix s :: \"'block memory\"\n      obtain blocks where [simp]: \"s = MEMORY blocks\" by (cases s)\n      \n      show \"\\<exists>p'. p' ## \\<alpha> s \\<and>\n              \\<alpha> (put' memory.the_memory\\<^sub>L (get' memory.the_memory\\<^sub>L s @ [Some b]) s) = p' + \\<alpha> s \\<and>\n              (block (\\<alpha>b b) (RP_ADDR (ADDR (length (get' memory.the_memory\\<^sub>L s)) this_addr)) \\<and>*\n               tag (tag_of b) (RP_ADDR (ADDR (length (get' memory.the_memory\\<^sub>L s)) this_addr)))\n               p'\"\n        apply (rule exI[where x=\"0(length blocks := (\\<alpha>b b, TRIV (tag_of b)))\"]; intro conjI)\n        apply (clarsimp_all simp: \\<alpha>_def block_def tag_def \\<alpha>tag_def sep_algebra_simps list\\<alpha>_at_len)\n        subgoal by (simp add: list\\<alpha>_snoc)\n        subgoal\n          apply (subst EXACT_split[symmetric])\n          apply (auto simp: sep_algebra_simps)\n          done\n        done\n    qed\n  \n    lemma complete_splitE:\n      assumes C: \"is_complete_tag blk t\"\n      assumes DISJ: \"f i ## (blk, TRIV t)\"\n      assumes AEQ: \"list\\<alpha> (option\\<alpha> (\\<lambda>x. (\\<alpha>b x, \\<alpha>tag x))) xs = f + fun_upd 0 i (blk, TRIV t)\"\n      obtains cblk where \n        \"i<length xs\" \"xs!i = Some cblk\" \"blk = \\<alpha>b cblk\" \"t = tag_of cblk\" \"f i = 0\"\n    proof -\n      have [simp]: \"i<length xs\"\n        apply (rule list\\<alpha>_in_rangeD[OF AEQ])\n        apply (auto simp: sep_algebra_simps DISJ)\n        done\n\n      obtain fib fit where [simp]: \"f i = (fib,fit)\"  by (cases \"f i\")\n                \n      from DISJ have [simp]: \"blk ## fib\" \"fit = 0\" \n        by (auto simp: sep_algebra_simps)\n\n              \n      obtain cblk where [simp]: \"xs!i = Some cblk\" \"\\<alpha>b cblk = blk + fib\" \"t = tag_of cblk\"\n        using fun_cong[OF AEQ, of i]\n        apply (cases \"xs!i\")\n        apply (auto simp: list\\<alpha>_def sep_algebra_simps if_splits \\<alpha>tag_def)\n        done\n        \n      from complete_tag[OF C[simplified], of fib, simplified] have [simp]: \"fib=0\" .\n      \n      show ?thesis\n        apply (rule that[of cblk])\n        apply (auto simp: sep_algebra_simps)\n        done\n    qed        \n    \n    lemma free_rule: \"htriple \\<alpha> (block blk a ** tag t a ** \\<up>(is_complete_tag blk t)) (free a) (\\<lambda>_. \\<box>)\"\n      apply (rule htripleI')\n      subgoal for p s f\n        apply (cases s)\n        apply (auto simp: free_def wp_def run_simps sep_algebra_simps split: option.splits addr.splits rptr.splits)\n        apply (auto simp: block_def tag_def sep_algebra_simps pred_lift_extract_simps)\n        apply (all \\<open>subst (asm) EXACT_split[symmetric] sep_disj_fun_def; clarsimp simp: sep_algebra_simps\\<close>)\n        apply (auto simp: \\<alpha>_def sep_algebra_simps merge_fun_singleton split_fun_upd_0)\n        subgoal \n          apply (erule (2) complete_splitE)\n          by auto\n        subgoal \n          apply (erule (2) complete_splitE)\n          by auto\n        subgoal for xs i\n          by (force simp: sep_algebra_simps dest: sep_disj_funD[where x=i] list\\<alpha>_in_rangeD[where i=i])\n        subgoal \n          apply (erule (2) complete_splitE)\n          by auto\n        done  \n      done\n  \n      \n    definition \"block_lifter bi \\<equiv> \\<lparr> \n      sep_lifter.lift = \\<lambda>x. (0(bi:=(x,0))),\n      sep_lifter.project = (\\<lambda>f. fst (f bi)),\n      sep_lifter.carve = (\\<lambda>f. f(bi:=(0,snd (f bi)))),\n      sep_lifter.splittable = (\\<lambda>f. True),\n      sep_lifter.L = lens_of_bi bi,\n      sep_lifter.\\<alpha>b = \\<alpha>,\n      sep_lifter.\\<alpha>s = \\<alpha>b,\n      sep_lifter.tyb = \\<lambda>_. (),\n      sep_lifter.tys = tag_of\n          \\<rparr>\"\n      \n    lemma block_lifter_simps[simp]:      \n      \"sep_lifter.lift (block_lifter bi) = (\\<lambda>x. (0(bi:=(x,0))))\"\n      \"sep_lifter.project (block_lifter bi) = (\\<lambda>f. fst (f bi))\"\n      \"sep_lifter.carve (block_lifter bi) = (\\<lambda>f. f(bi:=(0,snd (f bi))))\"\n      \"sep_lifter.splittable (block_lifter bi) = (\\<lambda>f. True)\"\n      \"sep_lifter.L (block_lifter bi) = lens_of_bi bi\"\n      \"sep_lifter.\\<alpha>b (block_lifter bi) = \\<alpha>\"\n      \"sep_lifter.\\<alpha>s (block_lifter bi) = \\<alpha>b\"\n      \"sep_lifter.tyb (block_lifter bi) = (\\<lambda>_. ())\"\n      \"sep_lifter.tys (block_lifter bi) = tag_of\"\n      unfolding block_lifter_def by auto\n          \n    sublocale block_lifter: sep_lifter \"block_lifter bi\"\n    proof -\n\n      have aux1[intro]: \"a ## fst b \\<Longrightarrow> b ## (a, 0)\" for a b\n        by (cases b) (auto simp: sep_algebra_simps )\n        \n      show \"sep_lifter (block_lifter bi)\"\n        apply unfold_locales\n        apply (auto simp: sep_algebra_simps sep_disj_funD[where x=bi])\n        apply (auto \n          simp: lens_of_bi_def \\<alpha>_def list\\<alpha>_def option\\<alpha>_alt \\<alpha>tag_def sep_algebra_simps\n          split: memory.splits if_splits option.splits\n          del: ext intro!: ext)\n        done  \n    qed    \n       \n    lemma pto_null_eq[simp]: \"pto x RP_NULL = sep_false\" by (auto simp: pto_def)\n    \n    lemma pto_addr_eq[simp]: \"pto x (RP_ADDR (ADDR bi ba)) = block_lifter.lift_assn bi (bpto x ba)\"\n      unfolding pto_def block_lifter.lift_assn_def\n      apply (rule ext)\n      apply (auto simp: sep_algebra_simps)\n      by (metis (no_types, hide_lams) fun_upd_same fun_upd_triv fun_upd_upd prod_Z_lower(1) surjective_pairing zero_fun_def)\n    \n      \n    fun rptr_cases where \"rptr_cases (RP_NULL) = ()\" | \"rptr_cases (RP_ADDR (ADDR _ _)) = ()\"\n    \n    lemma load_rule: \"htriple \\<alpha> (pto x a) (load a) (\\<lambda>r. \\<up>(x=r) ** pto x a)\"\n      unfolding load_def\n      apply (cases a rule: rptr_cases.cases; simp)\n      apply (rule cons_post_rule)\n      apply (rule block_lifter.lift_operation[simplified, OF _ _ bload_rule])\n      apply (simp add: bpto_notZ)\n      apply (rule bload_pres_tag)\n      apply (auto simp: sep_algebra_simps pred_lift_extract_simps)\n      done\n      \n    lemma store_rule: \"htriple \\<alpha> (pto xx a) (store x a) (\\<lambda>_. pto x a)\"  \n      unfolding store_def\n      apply (cases a rule: rptr_cases.cases; simp)\n      apply (rule cons_post_rule)\n      apply (rule block_lifter.lift_operation[simplified, OF _ _ bstore_rule])\n      apply (simp add: bpto_notZ)\n      apply (rule bstore_pres_tag)\n      apply (auto simp: sep_algebra_simps pred_lift_extract_simps)\n      done\n        \n  end\n\n\nsubsection \\<open>Address Arithmetic\\<close>  \n  \n  (*\n    ptr ~ ptr :: bool   same base\n  \n    ptr - ptr :: int    if same base\n    ptr + int :: ptr\n  \n\n    ~ is equivalence relation\n    p ~ p\n    p\\<^sub>1 ~ p\\<^sub>2 \\<longleftrightarrow> p\\<^sub>2 ~ p\\<^sub>1\n    p\\<^sub>1~p\\<^sub>2 \\<and> p\\<^sub>2~p\\<^sub>3 \\<longrightarrow> p\\<^sub>1~p\\<^sub>3 \n        \n    p + i\\<^sub>1 + i\\<^sub>2 = p + (i\\<^sub>1+i\\<^sub>2)\n    p + 0 = p\n    p ~ p+i\n    \n    p\\<^sub>1~p\\<^sub>2 \\<Longrightarrow> p\\<^sub>2 + (p\\<^sub>1-p\\<^sub>2) = p\\<^sub>1\n  *)\n\n  term \"a+b\"\n  \n  class addr_algebra =\n    fixes abase :: \"'a \\<Rightarrow> bool\"\n      and acompat :: \"'a \\<Rightarrow> 'a \\<Rightarrow> bool\" (infix \"~\\<^sub>a\" 50)\n      and adiff :: \"'a \\<Rightarrow> 'a \\<Rightarrow> int\" (infix \"-\\<^sub>a\" 65)\n      and aidx :: \"'a \\<Rightarrow> int \\<Rightarrow> 'a\" (infixl \"+\\<^sub>a\" 65)\n    assumes \n        \\<comment> \\<open>Compatibility is equivalence relation over base pointers\\<close>\n            acompat_equiv: \"part_equivp acompat\"  \n        and acompat_dom: \"a\\<^sub>1 ~\\<^sub>a a\\<^sub>2 \\<Longrightarrow> abase a\\<^sub>1 \\<and> abase a\\<^sub>2\"\n        \n        \\<comment> \\<open>Indexing properties\\<close>\n        and aidx_Z[simp]: \"a +\\<^sub>a 0 = a\" \\<comment> \\<open>Indexing by zero extended to non-base pointers\\<close>\n        and aidx_plus[simp]: \"abase a \\<Longrightarrow> a +\\<^sub>a i\\<^sub>1 +\\<^sub>a i\\<^sub>2 = a +\\<^sub>a (i\\<^sub>1 + i\\<^sub>2)\"\n        and aidx_inj[simp]: \"abase a \\<Longrightarrow> a +\\<^sub>a i = a +\\<^sub>a j \\<longleftrightarrow> i=j\"\n        (*and abase_idx[simp, intro!]: \"abase a \\<Longrightarrow> abase (a +\\<^sub>a i)\"*)\n        and abase_idx[simp]: \"abase (a +\\<^sub>a i) \\<longleftrightarrow> abase a\"\n        \n        \\<comment> \\<open>Difference\\<close>\n        and adiff_same[simp]: \"a -\\<^sub>a a = 0\" \\<comment> \\<open>Reflexive difference extended to non-base pointers\\<close>\n        and aidx_compat[simp]: \"abase a \\<Longrightarrow> a ~\\<^sub>a a+\\<^sub>ai\"\n        and adiff_idx[simp]: \"a ~\\<^sub>a b \\<Longrightarrow> a +\\<^sub>a (b -\\<^sub>a a) = b\"\n        \n  begin\n    lemma acompat_trans[trans]: \"a ~\\<^sub>a b \\<Longrightarrow> b ~\\<^sub>a c \\<Longrightarrow> a ~\\<^sub>a c\"\n      using acompat_equiv by (meson part_equivp_transp)\n  \n    lemma acompat_sym[sym, intro]: \"a ~\\<^sub>a b \\<Longrightarrow> b ~\\<^sub>a a\"\n      using acompat_equiv by (meson part_equivp_symp)\n\n    (*lemma acompat_sym_iff[simp]: \"p~\\<^sub>ap' \\<longleftrightarrow> p'~\\<^sub>ap\"\n      using acompat_sym by auto\n    *)\n      \n        \n    lemma acompat_refl[simp]: \"a ~\\<^sub>a a \\<longleftrightarrow> abase a\"  \n      using acompat_sym acompat_trans local.acompat_dom local.aidx_compat by blast\n      \n    lemma aidx_compat'[simp]: \n      \"abase b \\<Longrightarrow> a ~\\<^sub>a b +\\<^sub>a i  \\<longleftrightarrow> a ~\\<^sub>a b\"  \n      \"abase a \\<Longrightarrow> a +\\<^sub>a i ~\\<^sub>a b \\<longleftrightarrow> a ~\\<^sub>a b\"  \n      using acompat_sym acompat_trans local.aidx_compat by blast+\n      \n    lemma diff_Z_iff_eq[simp]: \"a\\<^sub>1 ~\\<^sub>a a\\<^sub>2 \\<Longrightarrow> a\\<^sub>1 -\\<^sub>a a\\<^sub>2 = 0 \\<longleftrightarrow> a\\<^sub>1=a\\<^sub>2\"  \n      by (metis acompat_sym acompat_trans local.adiff_idx local.adiff_same)\n      \n    lemma diff_Z_iff_eq'[simp]: \"a\\<^sub>2 ~\\<^sub>a a\\<^sub>1 \\<Longrightarrow> a\\<^sub>1 -\\<^sub>a a\\<^sub>2 = 0 \\<longleftrightarrow> a\\<^sub>1=a\\<^sub>2\"  \n      by (metis acompat_sym acompat_trans local.adiff_idx local.adiff_same)\n      \n    lemma adiff_idx'[simp]: \"b ~\\<^sub>a a \\<Longrightarrow> a +\\<^sub>a (b -\\<^sub>a a) = b\"\n      using acompat_sym local.adiff_idx by blast\n      \n\n    lemma idx_diff_distrib[simp]: \"p~\\<^sub>ap' \\<Longrightarrow> (p+\\<^sub>ai)-\\<^sub>ap' = (p-\\<^sub>ap')+i\"\n      by (metis acompat_dom adiff_idx' aidx_compat aidx_inj aidx_plus)\n    lemma idx_diff_distrib'[simp]: \"p'~\\<^sub>ap \\<Longrightarrow> (p+\\<^sub>ai)-\\<^sub>ap' = (p-\\<^sub>ap')+i\"\n      by (metis acompat_dom adiff_idx' aidx_compat aidx_inj aidx_plus)\n    \n    lemma adiff_idx_idx[simp]:\n      \"p~\\<^sub>ap' \\<Longrightarrow> p +\\<^sub>a (p' -\\<^sub>a p + i) = p' +\\<^sub>a i\"\n      \"p'~\\<^sub>ap \\<Longrightarrow> p +\\<^sub>a (p' -\\<^sub>a p + i) = p' +\\<^sub>a i\"\n      apply (metis acompat_dom adiff_idx aidx_plus)\n      by (metis acompat_dom adiff_idx' aidx_plus)\n      \n    lemma acompat_dom'[simp, intro]:\n      \"p~\\<^sub>ap' \\<Longrightarrow> abase p\"\n      \"p~\\<^sub>ap' \\<Longrightarrow> abase p'\"\n      apply (simp_all add: acompat_dom)\n      done\n            \n  end        \n\n  instantiation rptr :: (addr_algebra) addr_algebra begin\n    fun abase_rptr where \"abase_rptr (RP_ADDR a) \\<longleftrightarrow> abase a\" | \"abase_rptr RP_NULL \\<longleftrightarrow> False\"\n\n    lemma abase_rptr_alt: \"abase p \\<longleftrightarrow> (case p of (RP_ADDR a) \\<Rightarrow> abase a | RP_NULL \\<Rightarrow> False)\"\n      by (cases p; simp)\n      \n    fun acompat_rptr where\n      \"acompat_rptr (RP_ADDR a\\<^sub>1) (RP_ADDR a\\<^sub>2) \\<longleftrightarrow> a\\<^sub>1 ~\\<^sub>a a\\<^sub>2\"\n    | \"acompat_rptr _ _ \\<longleftrightarrow> False\"\n    \n    lemma acompat_rptr_alt: \"p\\<^sub>1 ~\\<^sub>a p\\<^sub>2 \\<longleftrightarrow> (case (p\\<^sub>1,p\\<^sub>2) of (RP_ADDR a\\<^sub>1, RP_ADDR a\\<^sub>2) \\<Rightarrow> a\\<^sub>1 ~\\<^sub>a a\\<^sub>2 | _ \\<Rightarrow> False)\"\n      by (cases p\\<^sub>1; cases p\\<^sub>2; simp)\n        \n    fun adiff_rptr where\n      \"adiff_rptr (RP_ADDR a\\<^sub>1) (RP_ADDR a\\<^sub>2) = (a\\<^sub>1 -\\<^sub>a a\\<^sub>2)\"\n    | \"adiff_rptr (RP_NULL) (RP_NULL) = 0\"\n    | \"adiff_rptr _ _ = undefined\"\n\n    lemma adiff_rptr_alt: \"p\\<^sub>1 -\\<^sub>a p\\<^sub>2 = (case (p\\<^sub>1,p\\<^sub>2) of (RP_ADDR a\\<^sub>1, RP_ADDR a\\<^sub>2) \\<Rightarrow> a\\<^sub>1 -\\<^sub>a a\\<^sub>2 | (RP_NULL,RP_NULL) \\<Rightarrow> 0 | _ \\<Rightarrow> undefined)\"\n      by (cases p\\<^sub>1; cases p\\<^sub>2; simp)\n        \n    fun aidx_rptr where\n      \"aidx_rptr (RP_ADDR a) i = RP_ADDR (a +\\<^sub>a i)\"\n    | \"aidx_rptr RP_NULL _ = RP_NULL\"\n\n    lemma aidx_rptr_alt: \"p\\<^sub>1 +\\<^sub>a i = (case p\\<^sub>1 of RP_ADDR a\\<^sub>1 \\<Rightarrow> RP_ADDR (a\\<^sub>1 +\\<^sub>a i) | _ \\<Rightarrow> RP_NULL)\"\n      by (cases p\\<^sub>1; simp)\n        \n    lemma ptr_neq_null_conv: \"p\\<noteq>RP_NULL \\<longleftrightarrow> (\\<exists>a. p=RP_ADDR a)\" by (cases p) (auto)\n    \n    instance\n      apply standard\n      apply (intro part_equivpI sympI transpI)\n      apply (meson acompat_equiv acompat_rptr.simps(1) part_equivp_def)\n      apply (auto \n        simp: acompat_rptr_alt aidx_rptr_alt adiff_rptr_alt acompat_dom\n        split: rptr.splits\n        intro!: sympI transpI reflpI\n        intro: acompat_sym acompat_trans)\n      done\n      \n  end\n  \n  fun rptr_the_block_index where\n    \"rptr_the_block_index (RP_ADDR (ADDR bi _)) = bi\" | \"rptr_the_block_index _ = undefined\"\n  \n  \n  instantiation addr :: (addr_algebra) addr_algebra begin\n    fun abase_addr where \"abase_addr (ADDR bi ba) \\<longleftrightarrow> abase ba\"\n    fun acompat_addr where \"ADDR bi\\<^sub>1 ba\\<^sub>1 ~\\<^sub>a ADDR bi\\<^sub>2 ba\\<^sub>2 \\<longleftrightarrow> bi\\<^sub>1=bi\\<^sub>2 \\<and> ba\\<^sub>1~\\<^sub>aba\\<^sub>2\"\n    fun aidx_addr where \"ADDR bi ba +\\<^sub>a i = ADDR bi (ba +\\<^sub>a i)\"\n    fun adiff_addr where \"ADDR bi\\<^sub>1 ba\\<^sub>1 -\\<^sub>a ADDR bi\\<^sub>2 ba\\<^sub>2 = ba\\<^sub>1 -\\<^sub>a ba\\<^sub>2\"\n    \n    lemma abase_addr_alt: \"abase = (\\<lambda>(ADDR bi ba) \\<Rightarrow> abase ba)\" by (intro ext) (auto split: addr.splits)\n    lemma acomp_addr_alt: \"(~\\<^sub>a) = (\\<lambda>ADDR bi\\<^sub>1 ba\\<^sub>1 \\<Rightarrow> \\<lambda>ADDR bi\\<^sub>2 ba\\<^sub>2 \\<Rightarrow> bi\\<^sub>1=bi\\<^sub>2 \\<and> ba\\<^sub>1~\\<^sub>aba\\<^sub>2)\" by (intro ext) (auto split: addr.splits)\n    lemma aidx_addr_alt: \"(+\\<^sub>a) = (\\<lambda>ADDR bi ba \\<Rightarrow> \\<lambda>i. ADDR bi (ba +\\<^sub>a i))\" by (intro ext) (auto split: addr.splits)\n    lemma adiff_addr_alt: \"(-\\<^sub>a) = (\\<lambda>ADDR bi\\<^sub>1 ba\\<^sub>1 \\<Rightarrow> \\<lambda>ADDR bi\\<^sub>2 ba\\<^sub>2 \\<Rightarrow> ba\\<^sub>1 -\\<^sub>a ba\\<^sub>2)\" by (intro ext) (auto split: addr.splits)\n\n    instance\n      apply standard\n      apply (intro part_equivpI sympI transpI)\n      apply (meson acompat_equiv acompat_addr.simps(1) part_equivp_def)\n      apply (auto \n        simp: abase_addr_alt acomp_addr_alt aidx_addr_alt adiff_addr_alt acompat_dom\n        split: addr.splits \n        intro: acompat_sym acompat_trans) \n      done\n  \n  end\n    \n    \n    \nend\n", "meta": {"author": "lammich", "repo": "isabelle_llvm", "sha": "6be37a9c3cae74a1134dbef2979e312abb5f7f42", "save_path": "github-repos/isabelle/lammich-isabelle_llvm", "path": "github-repos/isabelle/lammich-isabelle_llvm/isabelle_llvm-6be37a9c3cae74a1134dbef2979e312abb5f7f42/thys/vcg/Sep_Block_Allocator_RS.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.640635854839898, "lm_q2_score": 0.399811640739795, "lm_q1q2_score": 0.2561336722402808}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: GPL-2.0-only\n *)\n\ntheory Noninterference_Base_Refinement\nimports Noninterference_Base\n        Noninterference_Base_Alternatives\nbegin\n\n(* we assume the same initial state for both systems *)\nlocale noninterference_refinement =\n   abs?: complete_unwinding_system A s0 dom uwr policy out schedDomain +\n   conc?: noninterference_system C s0 dom uwr policy out schedDomain\n   for A :: \"('a,'s,'e) data_type\"\n   and s0 :: \"'s\"\n   and dom :: \"'e \\<Rightarrow> 's \\<Rightarrow> 'd\"\n   and uwr :: \"'d \\<Rightarrow> ('s \\<times> 's) set\"\n   and policy :: \"('d \\<times> 'd) set\"\n   and out :: \"'d \\<Rightarrow> 's \\<Rightarrow> 'p\"\n   and schedDomain :: \"'d\"\n   and C :: \"('c,'s,'e) data_type\" +\n   assumes refines: \"refines C A\"\n\ncontext noninterference_refinement begin\n\nlemma reachable:\n  \"conc.reachable s \\<Longrightarrow> abs.reachable s\"\n  apply(simp add: conc.reachable_def abs.reachable_def)\n  using refines by (fastforce simp: refines_def)\n\n\nlemma Step:\n  \"conc.Step a \\<subseteq> abs.Step a\"\n  apply(simp add: conc.Step_def abs.Step_def)\n  using refines by(fastforce simp: refines_def)\n\nlemma confidentiality_u_refinement_closed:\n  \"abs.confidentiality_u \\<Longrightarrow> conc.confidentiality_u\"\n  apply(simp add: abs.confidentiality_u_def)\n  apply(subst conc.confidentiality_u_def)\n  apply(blast intro: subsetD[OF Step] reachable)\n  done\n\nlemma confidentiality_u_weak_refinement_closed:\n  \"abs.confidentiality_u_weak \\<Longrightarrow> conc.confidentiality_u_weak\"\n  apply(simp add: abs.confidentiality_u_weak_def)\n  apply(subst conc.confidentiality_u_weak_def)\n  apply(blast intro: subsetD[OF Step] reachable)\n  done\n\nlemma integrity_u_refinement_closed:\n  \"abs.integrity_u \\<Longrightarrow> conc.integrity_u\"\n  apply(simp add: abs.integrity_u_def)\n  apply(subst conc.integrity_u_def)\n  apply(blast intro: subsetD[OF Step] reachable)\n  done\n\n\nlemma xources_subset:\n  \"abs.confidentiality_u \\<Longrightarrow> abs.xources as s u \\<subseteq> conc.xources as s u\"\n  apply(induct as arbitrary: s u)\n   apply(simp add: abs.xources.xources_Nil conc.xources.xources_Nil)\n  apply(simp add: abs.xources.xources_Cons conc.xources.xources_Cons)\n  apply(rule conjI)\n   apply(rule subsetI)\n   apply(rule UnI1)\n   apply(blast dest: subsetD[OF Step])\n  apply(rule subsetI)\n  apply(rule UnI2)\n  apply(blast dest: subsetD[OF Step])\n  done\n\n\nlemma uwr_equiv:\n  \"abs.uwr_equiv s as t bs u \\<Longrightarrow> conc.uwr_equiv s as t bs u\"\n  apply(insert refines)\n  apply(fastforce simp: abs.uwr_equiv_def conc.uwr_equiv_def simp: refines_def dest: subsetD)\n  done\n\nlemma xNonleakage_gen_refinement_closed:\n  \"abs.xNonleakage_gen \\<Longrightarrow> conc.xNonleakage_gen\"\n  apply(frule abs.xNonleakage_gen_confidentiality_u)\n  apply(frule xources_subset)\n  apply(clarsimp simp: abs.xNonleakage_gen_def conc.xNonleakage_gen_def)\n  apply(drule (1) sameFor_subset_dom[OF _ xources_subset])\n  apply(blast dest: reachable uwr_equiv)\n  done\n\nend\n\n\nlocale complete_noninterference_refinement = noninterference_refinement A s0 dom uwr policy out schedDomain C\n   for A :: \"('a,'s,'e) data_type\"\n   and s0 :: \"'s\"\n   and dom :: \"'e \\<Rightarrow> 's \\<Rightarrow> 'd\"\n   and uwr :: \"'d \\<Rightarrow> ('s \\<times> 's) set\"\n   and policy :: \"('d \\<times> 'd) set\"\n   and out :: \"'d \\<Rightarrow> 's \\<Rightarrow> 'p\"\n   and schedDomain :: \"'d\"\n   and C :: \"('c,'s,'e) data_type\" +\n   assumes Step_C: \"Step_system C s0\"\n\nsublocale complete_noninterference_refinement \\<subseteq> conc: complete_unwinding_system C s0 dom uwr policy out schedDomain\n  apply(unfold_locales)\n    using Step_C apply(fastforce simp: Step_system_def)\n   using Step_C apply(fastforce simp: Step_system_def)\n  apply(rule policy_refl)\n  done\n\ncontext complete_noninterference_refinement begin\nlemma Noninfluence_strong_uwr_refinement_closed:\n  \"abs.Noninfluence_strong_uwr \\<Longrightarrow>\n    conc.Noninfluence_strong_uwr\"\n  apply(frule abs.Noninfluence_strong_uwr_confidentiality_u_weak)\n  apply(drule abs.Noninfluence_strong_uwr_integrity_u)\n  apply(drule confidentiality_u_weak_refinement_closed)\n  apply(drule integrity_u_refinement_closed)\n  apply(blast intro: conc.Noninfluence_strong_uwr)\n  done\n\nlemma Nonleakage_gen_refinement_closed:\n  \"abs.Nonleakage_gen \\<Longrightarrow>\n    conc.Nonleakage_gen\"\n  apply(simp add: abs.Nonleakage_gen_equiv_confidentiality_u conc.Nonleakage_gen_equiv_confidentiality_u)\n  apply(erule confidentiality_u_refinement_closed)\n  done\n\nlemma Noninfluence_strong_quasi_refinement_closed:\n  \"\\<lbrakk>abs.confidentiality_u_weak; abs.integrity_u;\n        output_consistent\\<rbrakk> \\<Longrightarrow>\n    conc.Noninfluence_strong\"\n  apply(rule conc.Noninfluence_strong)\n    apply(erule confidentiality_u_weak_refinement_closed)\n   apply assumption\n  apply(erule integrity_u_refinement_closed)\n  done\n\nlemma Noninfluence_strong_uwr_quasi_refinement_closed:\n  \"\\<lbrakk>abs.Noninfluence_strong_uwr;\n        output_consistent\\<rbrakk> \\<Longrightarrow>\n    conc.Noninfluence_strong\"\n  apply(rule conc.Noninfluence_strong)\n    apply(rule confidentiality_u_weak_refinement_closed)\n    apply(erule abs.Noninfluence_strong_uwr_confidentiality_u_weak)\n   apply assumption\n  apply(rule integrity_u_refinement_closed)\n  apply(erule abs.Noninfluence_strong_uwr_integrity_u)\n  done\n\nend\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/proof/infoflow/Noninterference_Base_Refinement.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.665410558746814, "lm_q2_score": 0.3849121444839335, "lm_q1q2_score": 0.2561246051294886}}
{"text": "section\\<open>Contrived Example\\<close>\ntheory Contrived_Example\nimports \n  \"../../Primitive_Matchers/Parser\"\nbegin\n\n(*\n  internal network: 131.159.21.0/24\n  DMZ: 131.159.15.240/28\n  DMZ must not connect to internal\n*)\n\nparse_iptables_save example_fw=\"iptables-save\"\n\nthm example_fw_def\nthm example_fw_FORWARD_default_policy_def\n\n\nlemma \"map common_primitive_rule_toString\n                  (upper_closure (packet_assume_new\n                    (unfold_ruleset_FORWARD example_fw_FORWARD_default_policy\n                      (map_of_string_ipv4 example_fw)))) =\n[''-i lo -j ACCEPT'',\n ''! -i lo -s 127.0.0.0/8 -j DROP'',\n ''-i inteneral -s 131.159.21.0/24 -j ACCEPT'',\n ''-d 131.159.21.0/24 -s 131.159.15.240/28 -j DROP'',\n ''-p tcp -d 131.159.15.240/28 -j ACCEPT'',\n ''-i dmz -p tcp -s 131.159.15.240/28 -j ACCEPT'',\n '' -j DROP'']\" by eval\n\n\nlemma \"map simple_rule_ipv4_toString\n              (to_simple_firewall (upper_closure\n                (optimize_matches abstract_for_simple_firewall\n                  (upper_closure (packet_assume_new\n                    (unfold_ruleset_FORWARD example_fw_FORWARD_default_policy\n                      (map_of_string_ipv4 example_fw))))))) =\n[''ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0 in: lo   '',\n  ''ACCEPT     all  --  131.159.21.0/24            0.0.0.0/0 in: inteneral   '',\n  ''DROP     all  --  131.159.15.240/28            131.159.21.0/24    '',\n  ''ACCEPT     tcp  --  0.0.0.0/0            131.159.15.240/28    '',\n  ''ACCEPT     tcp  --  131.159.15.240/28            0.0.0.0/0 in: dmz   '',\n  ''DROP     all  --  0.0.0.0/0            0.0.0.0/0    '']\" by eval\n\n\nlemma \"map simple_rule_ipv4_toString\n              (to_simple_firewall_without_interfaces ipassmt_generic_ipv4 None (upper_closure\n                (optimize_matches abstract_for_simple_firewall\n                  (upper_closure (packet_assume_new\n                    (unfold_ruleset_FORWARD example_fw_FORWARD_default_policy\n                      (map_of_string_ipv4 example_fw))))))) =\n[''ACCEPT     all  --  127.0.0.0/8            0.0.0.0/0    '',\n  ''ACCEPT     all  --  131.159.21.0/24            0.0.0.0/0    '',\n  ''DROP     all  --  131.159.15.240/28            131.159.21.0/24    '',\n  ''ACCEPT     tcp  --  0.0.0.0/0            131.159.15.240/28    '',\n  ''ACCEPT     tcp  --  131.159.15.240/28            0.0.0.0/0    '',\n  ''DROP     all  --  0.0.0.0/0            0.0.0.0/0    '']\" by eval\n\n\n\nlemma \"access_matrix_pretty_ipv4 parts_connection_ssh\n              (to_simple_firewall_without_interfaces ipassmt_generic_ipv4 None (upper_closure\n                (optimize_matches abstract_for_simple_firewall\n                  (upper_closure (packet_assume_new\n                    (unfold_ruleset_FORWARD example_fw_FORWARD_default_policy\n                      (map_of_string_ipv4 example_fw))))))) =\n([(''131.159.21.0'', ''{131.159.21.0 .. 131.159.21.255}''),\n   (''131.159.15.240'', ''{131.159.15.240 .. 131.159.15.255}''),\n   (''127.0.0.0'', ''{127.0.0.0 .. 127.255.255.255}''),\n   (''0.0.0.0'', ''{0.0.0.0 .. 126.255.255.255} u {128.0.0.0 .. 131.159.15.239} u {131.159.16.0 .. 131.159.20.255} u {131.159.22.0 .. 255.255.255.255}'')],\n\n  [(''131.159.21.0'', ''131.159.21.0''), (''131.159.21.0'', ''131.159.15.240''),\n   (''131.159.21.0'', ''127.0.0.0''), (''131.159.21.0'', ''0.0.0.0''),\n   (''131.159.15.240'', ''131.159.15.240''), (''131.159.15.240'', ''127.0.0.0''),\n   (''131.159.15.240'', ''0.0.0.0''), (''127.0.0.0'', ''131.159.21.0''), (''127.0.0.0'', ''131.159.15.240''),\n   (''127.0.0.0'', ''127.0.0.0''), (''127.0.0.0'', ''0.0.0.0''), (''0.0.0.0'', ''131.159.15.240'')])\"\nby eval\n\n(*\na |-> {131.159.21.0 .. 131.159.21.255}\nb |-> {131.159.15.240 .. 131.159.15.255}\nc |-> {127.0.0.0 .. 127.255.255.255}\nd |-> {0.0.0.0 .. 126.255.255.255} \\<union> {128.0.0.0 .. 131.159.15.239} \\<union> {131.159.16.0 .. 131.159.20.255} \\<union> {131.159.22.0 .. 255.255.255.255}\n\n(a,a)\n(a,b)\n(a,c)\n(a,d)\n(b,b)\n(b,c)\n(b,d)\n(c,a)\n(c,b)\n(c,c)\n(c,d)\n(d,b)\n\n*)\n\nend\n", "meta": {"author": "diekmann", "repo": "Iptables_Semantics", "sha": "e0a2516bd885708fce875023b474ae341cbdee29", "save_path": "github-repos/isabelle/diekmann-Iptables_Semantics", "path": "github-repos/isabelle/diekmann-Iptables_Semantics/Iptables_Semantics-e0a2516bd885708fce875023b474ae341cbdee29/thy/Iptables_Semantics/Examples/Contrived/Contrived_Example.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526368038304, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.25608757770996315}}
{"text": "(*  Title:      HOL/Auth/Guard/Proto.thy\n    Author:     Frederic Blanqui, University of Cambridge Computer Laboratory\n    Copyright   2002  University of Cambridge\n*)\n\nsection\\<open>Other Protocol-Independent Results\\<close>\n\ntheory Proto imports Guard_Public begin\n\nsubsection\\<open>protocols\\<close>\n\ntype_synonym rule = \"event set * event\"\n\nabbreviation\n  msg' :: \"rule => msg\" where\n  \"msg' R == msg (snd R)\"\n\ntype_synonym proto = \"rule set\"\n\ndefinition wdef :: \"proto => bool\" where\n\"wdef p \\<equiv> \\<forall>R k. R \\<in> p \\<longrightarrow> Number k \\<in> parts {msg' R}\n\\<longrightarrow> Number k \\<in> parts (msg`(fst R))\"\n\nsubsection\\<open>substitutions\\<close>\n\nrecord subs =\n  agent   :: \"agent => agent\"\n  nonce :: \"nat => nat\"\n  nb    :: \"nat => msg\"\n  key   :: \"key => key\"\n\nprimrec apm :: \"subs => msg => msg\" where\n  \"apm s (Agent A) = Agent (agent s A)\"\n| \"apm s (Nonce n) = Nonce (nonce s n)\"\n| \"apm s (Number n) = nb s n\"\n| \"apm s (Key K) = Key (key s K)\"\n| \"apm s (Hash X) = Hash (apm s X)\"\n| \"apm s (Crypt K X) = (\nif (\\<exists>A. K = pubK A) then Crypt (pubK (agent s (agt K))) (apm s X)\nelse if (\\<exists>A. K = priK A) then Crypt (priK (agent s (agt K))) (apm s X)\nelse Crypt (key s K) (apm s X))\"\n| \"apm s \\<lbrace>X,Y\\<rbrace> = \\<lbrace>apm s X, apm s Y\\<rbrace>\"\n\nlemma apm_parts: \"X \\<in> parts {Y} \\<Longrightarrow> apm s X \\<in> parts {apm s Y}\"\napply (erule parts.induct, simp_all, blast)\napply (erule parts.Fst)\napply (erule parts.Snd)\nby (erule parts.Body)+\n\nlemma Nonce_apm [rule_format]: \"Nonce n \\<in> parts {apm s X} \\<Longrightarrow>\n(\\<forall>k. Number k \\<in> parts {X} \\<longrightarrow> Nonce n \\<notin> parts {nb s k}) \\<longrightarrow>\n(\\<exists>k. Nonce k \\<in> parts {X} \\<and> nonce s k = n)\"\nby (induct X, simp_all, blast)\n\nlemma wdef_Nonce: \"\\<lbrakk>Nonce n \\<in> parts {apm s X}; R \\<in> p; msg' R = X; wdef p;\nNonce n \\<notin> parts (apm s `(msg `(fst R)))\\<rbrakk> \\<Longrightarrow>\n(\\<exists>k. Nonce k \\<in> parts {X} \\<and> nonce s k = n)\"\napply (erule Nonce_apm, unfold wdef_def)\napply (drule_tac x=R in spec, drule_tac x=k in spec, clarsimp)\napply (drule_tac x=x in bspec, simp)\napply (drule_tac Y=\"msg x\" and s=s in apm_parts, simp)\nby (blast dest: parts_parts)\n\nprimrec ap :: \"subs \\<Rightarrow> event \\<Rightarrow> event\" where\n  \"ap s (Says A B X) = Says (agent s A) (agent s B) (apm s X)\"\n| \"ap s (Gets A X) = Gets (agent s A) (apm s X)\"\n| \"ap s (Notes A X) = Notes (agent s A) (apm s X)\"\n\nabbreviation\n  ap' :: \"subs \\<Rightarrow> rule \\<Rightarrow> event\" where\n  \"ap' s R \\<equiv> ap s (snd R)\"\n\nabbreviation\n  apm' :: \"subs \\<Rightarrow> rule \\<Rightarrow> msg\" where\n  \"apm' s R \\<equiv> apm s (msg' R)\"\n\nabbreviation\n  priK' :: \"subs \\<Rightarrow> agent \\<Rightarrow> key\" where\n  \"priK' s A \\<equiv> priK (agent s A)\"\n\nabbreviation\n  pubK' :: \"subs \\<Rightarrow> agent \\<Rightarrow> key\" where\n  \"pubK' s A \\<equiv> pubK (agent s A)\"\n\nsubsection\\<open>nonces generated by a rule\\<close>\n\ndefinition newn :: \"rule \\<Rightarrow> nat set\" where\n\"newn R \\<equiv> {n. Nonce n \\<in> parts {msg (snd R)} \\<and> Nonce n \\<notin> parts (msg`(fst R))}\"\n\nlemma newn_parts: \"n \\<in> newn R \\<Longrightarrow> Nonce (nonce s n) \\<in> parts {apm' s R}\"\nby (auto simp: newn_def dest: apm_parts)\n\nsubsection\\<open>traces generated by a protocol\\<close>\n\ndefinition ok :: \"event list \\<Rightarrow> rule \\<Rightarrow> subs \\<Rightarrow> bool\" where\n\"ok evs R s \\<equiv> ((\\<forall>x. x \\<in> fst R \\<longrightarrow> ap s x \\<in> set evs)\n\\<and> (\\<forall>n. n \\<in> newn R \\<longrightarrow> Nonce (nonce s n) \\<notin> used evs))\"\n\ninductive_set\n  tr :: \"proto => event list set\"\n  for p :: proto\nwhere\n\n  Nil [intro]: \"[] \\<in> tr p\"\n\n| Fake [intro]: \"\\<lbrakk>evsf \\<in> tr p; X \\<in> synth (analz (spies evsf))\\<rbrakk>\n  \\<Longrightarrow> Says Spy B X # evsf \\<in> tr p\"\n\n| Proto [intro]: \"\\<lbrakk>evs \\<in> tr p; R \\<in> p; ok evs R s\\<rbrakk> \\<Longrightarrow> ap' s R # evs \\<in> tr p\"\n\nsubsection\\<open>general properties\\<close>\n\nlemma one_step_tr [iff]: \"one_step (tr p)\"\napply (unfold one_step_def, clarify)\nby (ind_cases \"ev # evs \\<in> tr p\" for ev evs, auto)\n\ndefinition has_only_Says' :: \"proto => bool\" where\n\"has_only_Says' p \\<equiv> \\<forall>R. R \\<in> p \\<longrightarrow> is_Says (snd R)\"\n\nlemma has_only_Says'D: \"\\<lbrakk>R \\<in> p; has_only_Says' p\\<rbrakk>\n\\<Longrightarrow> (\\<exists>A B X. snd R = Says A B X)\"\nby (unfold has_only_Says'_def is_Says_def, blast)\n\nlemma has_only_Says_tr [simp]: \"has_only_Says' p \\<Longrightarrow> has_only_Says (tr p)\"\nunfolding has_only_Says_def\napply (rule allI, rule allI, rule impI)\napply (erule tr.induct)\napply (auto simp: has_only_Says'_def ok_def)\nby (drule_tac x=a in spec, auto simp: is_Says_def)\n\nlemma has_only_Says'_in_trD: \"\\<lbrakk>has_only_Says' p; list @ ev # evs1 \\<in> tr p\\<rbrakk>\n\\<Longrightarrow> (\\<exists>A B X. ev = Says A B X)\"\nby (drule has_only_Says_tr, auto)\n\nlemma ok_not_used: \"\\<lbrakk>Nonce n \\<notin> used evs; ok evs R s;\n\\<forall>x. x \\<in> fst R \\<longrightarrow> is_Says x\\<rbrakk> \\<Longrightarrow> Nonce n \\<notin> parts (apm s `(msg `(fst R)))\"\napply (unfold ok_def, clarsimp)\napply (drule_tac x=x in spec, drule_tac x=x in spec)\nby (auto simp: is_Says_def dest: Says_imp_spies not_used_not_spied parts_parts)\n\nlemma ok_is_Says: \"\\<lbrakk>evs' @ ev # evs \\<in> tr p; ok evs R s; has_only_Says' p;\nR \\<in> p; x \\<in> fst R\\<rbrakk> \\<Longrightarrow> is_Says x\"\napply (unfold ok_def is_Says_def, clarify)\napply (drule_tac x=x in spec, simp)\napply (subgoal_tac \"one_step (tr p)\")\napply (drule trunc, simp, drule one_step_Cons, simp)\napply (drule has_only_SaysD, simp+)\nby (clarify, case_tac x, auto)\n\nsubsection\\<open>types\\<close>\n\ntype_synonym keyfun = \"rule \\<Rightarrow> subs \\<Rightarrow> nat \\<Rightarrow> event list \\<Rightarrow> key set\"\n\ntype_synonym secfun = \"rule \\<Rightarrow> nat \\<Rightarrow> subs \\<Rightarrow> key set \\<Rightarrow> msg\"\n\nsubsection\\<open>introduction of a fresh guarded nonce\\<close>\n\ndefinition fresh :: \"proto \\<Rightarrow> rule \\<Rightarrow> subs \\<Rightarrow> nat \\<Rightarrow> key set \\<Rightarrow> event list\n\\<Rightarrow> bool\" where\n\"fresh p R s n Ks evs \\<equiv> (\\<exists>evs1 evs2. evs = evs2 @ ap' s R # evs1\n\\<and> Nonce n \\<notin> used evs1 \\<and> R \\<in> p \\<and> ok evs1 R s \\<and> Nonce n \\<in> parts {apm' s R}\n\\<and> apm' s R \\<in> guard n Ks)\"\n\nlemma freshD: \"fresh p R s n Ks evs \\<Longrightarrow> (\\<exists>evs1 evs2.\nevs = evs2 @ ap' s R # evs1 \\<and> Nonce n \\<notin> used evs1 \\<and> R \\<in> p \\<and> ok evs1 R s\n\\<and> Nonce n \\<in> parts {apm' s R} \\<and> apm' s R \\<in> guard n Ks)\"\n  unfolding fresh_def by blast\n\nlemma freshI [intro]: \"\\<lbrakk>Nonce n \\<notin> used evs1; R \\<in> p; Nonce n \\<in> parts {apm' s R};\nok evs1 R s; apm' s R \\<in> guard n Ks\\<rbrakk>\n\\<Longrightarrow> fresh p R s n Ks (list @ ap' s R # evs1)\"\n  unfolding fresh_def by blast\n\nlemma freshI': \"\\<lbrakk>Nonce n \\<notin> used evs1; (l,r) \\<in> p;\nNonce n \\<in> parts {apm s (msg r)}; ok evs1 (l,r) s; apm s (msg r) \\<in> guard n Ks\\<rbrakk>\n\\<Longrightarrow> fresh p (l,r) s n Ks (evs2 @ ap s r # evs1)\"\nby (drule freshI, simp+)\n\nlemma fresh_used: \"\\<lbrakk>fresh p R' s' n Ks evs; has_only_Says' p\\<rbrakk>\n\\<Longrightarrow> Nonce n \\<in> used evs\"\napply (unfold fresh_def, clarify)\napply (drule has_only_Says'D)\nby (auto intro: parts_used_app)\n\nlemma fresh_newn: \"\\<lbrakk>evs' @ ap' s R # evs \\<in> tr p; wdef p; has_only_Says' p;\nNonce n \\<notin> used evs; R \\<in> p; ok evs R s; Nonce n \\<in> parts {apm' s R}\\<rbrakk>\n\\<Longrightarrow> \\<exists>k. k \\<in> newn R \\<and> nonce s k = n\"\napply (drule wdef_Nonce, simp+)\napply (frule ok_not_used, simp+)\napply (clarify, erule ok_is_Says, simp+)\napply (clarify, rule_tac x=k in exI, simp add: newn_def)\napply (clarify, drule_tac Y=\"msg x\" and s=s in apm_parts)\napply (drule ok_not_used, simp+)\nby (clarify, erule ok_is_Says, simp_all)\n\nlemma fresh_rule: \"\\<lbrakk>evs' @ ev # evs \\<in> tr p; wdef p; Nonce n \\<notin> used evs;\nNonce n \\<in> parts {msg ev}\\<rbrakk> \\<Longrightarrow> \\<exists>R s. R \\<in> p \\<and> ap' s R = ev\"\napply (drule trunc, simp, ind_cases \"ev # evs \\<in> tr p\", simp)\nby (drule_tac x=X in in_sub, drule parts_sub, simp, simp, blast+)\n\nlemma fresh_ruleD: \"\\<lbrakk>fresh p R' s' n Ks evs; keys R' s' n evs \\<subseteq> Ks; wdef p;\nhas_only_Says' p; evs \\<in> tr p; \\<forall>R k s. nonce s k = n \\<longrightarrow> Nonce n \\<in> used evs \\<longrightarrow>\nR \\<in> p \\<longrightarrow> k \\<in> newn R \\<longrightarrow> Nonce n \\<in> parts {apm' s R} \\<longrightarrow> apm' s R \\<in> guard n Ks \\<longrightarrow>\napm' s R \\<in> parts (spies evs) \\<longrightarrow> keys R s n evs \\<subseteq> Ks \\<longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\napply (frule fresh_used, simp)\napply (unfold fresh_def, clarify)\napply (drule_tac x=R' in spec)\napply (drule fresh_newn, simp+, clarify)\napply (drule_tac x=k in spec)\napply (drule_tac x=s' in spec)\napply (subgoal_tac \"apm' s' R' \\<in> parts (spies (evs2 @ ap' s' R' # evs1))\")\napply (case_tac R', drule has_only_Says'D, simp, clarsimp)\napply (case_tac R', drule has_only_Says'D, simp, clarsimp)\napply (rule_tac Y=\"apm s' X\" in parts_parts, blast)\nby (rule parts.Inj, rule Says_imp_spies, simp, blast)\n\nsubsection\\<open>safe keys\\<close>\n\ndefinition safe :: \"key set \\<Rightarrow> msg set \\<Rightarrow> bool\" where\n\"safe Ks G \\<equiv> \\<forall>K. K \\<in> Ks \\<longrightarrow> Key K \\<notin> analz G\"\n\nlemma safeD [dest]: \"\\<lbrakk>safe Ks G; K \\<in> Ks\\<rbrakk> \\<Longrightarrow> Key K \\<notin> analz G\"\n  unfolding safe_def by blast\n\nlemma safe_insert: \"safe Ks (insert X G) \\<Longrightarrow> safe Ks G\"\n  unfolding safe_def by blast\n\nlemma Guard_safe: \"\\<lbrakk>Guard n Ks G; safe Ks G\\<rbrakk> \\<Longrightarrow> Nonce n \\<notin> analz G\"\nby (blast dest: Guard_invKey)\n\nsubsection\\<open>guardedness preservation\\<close>\n\ndefinition preserv :: \"proto \\<Rightarrow> keyfun \\<Rightarrow> nat \\<Rightarrow> key set \\<Rightarrow> bool\" where\n\"preserv p keys n Ks \\<equiv> (\\<forall>evs R' s' R s. evs \\<in> tr p \\<longrightarrow>\nGuard n Ks (spies evs) \\<longrightarrow> safe Ks (spies evs) \\<longrightarrow> fresh p R' s' n Ks evs \\<longrightarrow>\nkeys R' s' n evs \\<subseteq> Ks \\<longrightarrow> R \\<in> p \\<longrightarrow> ok evs R s \\<longrightarrow> apm' s R \\<in> guard n Ks)\"\n\nlemma preservD: \"\\<lbrakk>preserv p keys n Ks; evs \\<in> tr p; Guard n Ks (spies evs);\nsafe Ks (spies evs); fresh p R' s' n Ks evs; R \\<in> p; ok evs R s;\nkeys R' s' n evs \\<subseteq> Ks\\<rbrakk> \\<Longrightarrow> apm' s R \\<in> guard n Ks\"\n  unfolding preserv_def by blast\n\nlemma preservD': \"\\<lbrakk>preserv p keys n Ks; evs \\<in> tr p; Guard n Ks (spies evs);\nsafe Ks (spies evs); fresh p R' s' n Ks evs; (l,Says A B X) \\<in> p;\nok evs (l,Says A B X) s; keys R' s' n evs \\<subseteq> Ks\\<rbrakk> \\<Longrightarrow> apm s X \\<in> guard n Ks\"\nby (drule preservD, simp+)\n\nsubsection\\<open>monotonic keyfun\\<close>\n\ndefinition monoton :: \"proto => keyfun => bool\" where\n\"monoton p keys \\<equiv> \\<forall>R' s' n ev evs. ev # evs \\<in> tr p \\<longrightarrow>\nkeys R' s' n evs \\<subseteq> keys R' s' n (ev # evs)\"\n\nlemma monotonD [dest]: \"\\<lbrakk>keys R' s' n (ev # evs) \\<subseteq> Ks; monoton p keys;\nev # evs \\<in> tr p\\<rbrakk> \\<Longrightarrow> keys R' s' n evs \\<subseteq> Ks\"\n  unfolding monoton_def by blast\n\nsubsection\\<open>guardedness theorem\\<close>\n\nlemma Guard_tr [rule_format]: \"\\<lbrakk>evs \\<in> tr p; has_only_Says' p;\npreserv p keys n Ks; monoton p keys; Guard n Ks (initState Spy)\\<rbrakk> \\<Longrightarrow>\nsafe Ks (spies evs) \\<longrightarrow> fresh p R' s' n Ks evs \\<longrightarrow> keys R' s' n evs \\<subseteq> Ks \\<longrightarrow>\nGuard n Ks (spies evs)\"\napply (erule tr.induct)\n(* Nil *)\napply simp\n(* Fake *)\napply (clarify, drule freshD, clarsimp)\napply (case_tac evs2)\n(* evs2 = [] *)\napply (frule has_only_Says'D, simp)\napply (clarsimp, blast)\n(* evs2 = aa # list *)\napply (clarsimp, rule conjI)\napply (blast dest: safe_insert)\n(* X:guard n Ks *)\napply (rule in_synth_Guard, simp, rule Guard_analz)\napply (blast dest: safe_insert)\napply (drule safe_insert, simp add: safe_def)\n(* Proto *)\napply (clarify, drule freshD, clarify)\napply (case_tac evs2)\n(* evs2 = [] *)\napply (frule has_only_Says'D, simp)\napply (frule_tac R=R' in has_only_Says'D, simp)\napply (case_tac R', clarsimp, blast)\n(* evs2 = ab # list *)\napply (frule has_only_Says'D, simp)\napply (clarsimp, rule conjI)\napply (drule Proto, simp+, blast dest: safe_insert)\n(* apm s X:guard n Ks *)\napply (frule Proto, simp+)\napply (erule preservD', simp+)\napply (blast dest: safe_insert)\napply (blast dest: safe_insert)\nby (blast, simp, simp, blast)\n\nsubsection\\<open>useful properties for guardedness\\<close>\n\nlemma newn_neq_used: \"\\<lbrakk>Nonce n \\<in> used evs; ok evs R s; k \\<in> newn R\\<rbrakk>\n\\<Longrightarrow> n \\<noteq> nonce s k\"\nby (auto simp: ok_def)\n\nlemma ok_Guard: \"\\<lbrakk>ok evs R s; Guard n Ks (spies evs); x \\<in> fst R; is_Says x\\<rbrakk>\n\\<Longrightarrow> apm s (msg x) \\<in> parts (spies evs) \\<and> apm s (msg x) \\<in> guard n Ks\"\napply (unfold ok_def is_Says_def, clarify)\napply (drule_tac x=\"Says A B X\" in spec, simp)\nby (drule Says_imp_spies, auto intro: parts_parts)\n\nlemma ok_parts_not_new: \"\\<lbrakk>Y \\<in> parts (spies evs); Nonce (nonce s n) \\<in> parts {Y};\nok evs R s\\<rbrakk> \\<Longrightarrow> n \\<notin> newn R\"\nby (auto simp: ok_def dest: not_used_not_spied parts_parts)\n\nsubsection\\<open>unicity\\<close>\n\ndefinition uniq :: \"proto \\<Rightarrow> secfun \\<Rightarrow> bool\" where\n\"uniq p secret \\<equiv> \\<forall>evs R R' n n' Ks s s'. R \\<in> p \\<longrightarrow> R' \\<in> p \\<longrightarrow>\nn \\<in> newn R \\<longrightarrow> n' \\<in> newn R' \\<longrightarrow> nonce s n = nonce s' n' \\<longrightarrow>\nNonce (nonce s n) \\<in> parts {apm' s R} \\<longrightarrow> Nonce (nonce s n) \\<in> parts {apm' s' R'} \\<longrightarrow>\napm' s R \\<in> guard (nonce s n) Ks \\<longrightarrow> apm' s' R' \\<in> guard (nonce s n) Ks \\<longrightarrow>\nevs \\<in> tr p \\<longrightarrow> Nonce (nonce s n) \\<notin> analz (spies evs) \\<longrightarrow>\nsecret R n s Ks \\<in> parts (spies evs) \\<longrightarrow> secret R' n' s' Ks \\<in> parts (spies evs) \\<longrightarrow>\nsecret R n s Ks = secret R' n' s' Ks\"\n\nlemma uniqD: \"\\<lbrakk>uniq p secret; evs \\<in> tr p; R \\<in> p; R' \\<in> p; n \\<in> newn R; n' \\<in> newn R';\nnonce s n = nonce s' n'; Nonce (nonce s n) \\<notin> analz (spies evs);\nNonce (nonce s n) \\<in> parts {apm' s R}; Nonce (nonce s n) \\<in> parts {apm' s' R'};\nsecret R n s Ks \\<in> parts (spies evs); secret R' n' s' Ks \\<in> parts (spies evs);\napm' s R \\<in> guard (nonce s n) Ks; apm' s' R' \\<in> guard (nonce s n) Ks\\<rbrakk> \\<Longrightarrow>\nsecret R n s Ks = secret R' n' s' Ks\"\n  unfolding uniq_def by blast\n\ndefinition ord :: \"proto \\<Rightarrow> (rule \\<Rightarrow> rule \\<Rightarrow> bool) \\<Rightarrow> bool\" where\n\"ord p inff \\<equiv> \\<forall>R R'. R \\<in> p \\<longrightarrow> R' \\<in> p \\<longrightarrow> \\<not> inff R R' \\<longrightarrow> inff R' R\"\n\nlemma ordD: \"\\<lbrakk>ord p inff; \\<not> inff R R'; R \\<in> p; R' \\<in> p\\<rbrakk> \\<Longrightarrow> inff R' R\"\n  unfolding ord_def by blast\n\ndefinition uniq' :: \"proto \\<Rightarrow> (rule \\<Rightarrow> rule \\<Rightarrow> bool) \\<Rightarrow> secfun \\<Rightarrow> bool\" where\n\"uniq' p inff secret \\<equiv> \\<forall>evs R R' n n' Ks s s'. R \\<in> p \\<longrightarrow> R' \\<in> p \\<longrightarrow>\ninff R R' \\<longrightarrow> n \\<in> newn R \\<longrightarrow> n' \\<in> newn R' \\<longrightarrow> nonce s n = nonce s' n' \\<longrightarrow>\nNonce (nonce s n) \\<in> parts {apm' s R} \\<longrightarrow> Nonce (nonce s n) \\<in> parts {apm' s' R'} \\<longrightarrow>\napm' s R \\<in> guard (nonce s n) Ks \\<longrightarrow> apm' s' R' \\<in> guard (nonce s n) Ks \\<longrightarrow>\nevs \\<in> tr p \\<longrightarrow> Nonce (nonce s n) \\<notin> analz (spies evs) \\<longrightarrow>\nsecret R n s Ks \\<in> parts (spies evs) \\<longrightarrow> secret R' n' s' Ks \\<in> parts (spies evs) \\<longrightarrow>\nsecret R n s Ks = secret R' n' s' Ks\"\n\nlemma uniq'D: \"\\<lbrakk>uniq' p inff secret; evs \\<in> tr p; inff R R'; R \\<in> p; R' \\<in> p; n \\<in> newn R;\nn' \\<in> newn R'; nonce s n = nonce s' n'; Nonce (nonce s n) \\<notin> analz (spies evs);\nNonce (nonce s n) \\<in> parts {apm' s R}; Nonce (nonce s n) \\<in> parts {apm' s' R'};\nsecret R n s Ks \\<in> parts (spies evs); secret R' n' s' Ks \\<in> parts (spies evs);\napm' s R \\<in> guard (nonce s n) Ks; apm' s' R' \\<in> guard (nonce s n) Ks\\<rbrakk> \\<Longrightarrow>\nsecret R n s Ks = secret R' n' s' Ks\"\nby (unfold uniq'_def, blast)\n\nlemma uniq'_imp_uniq: \"\\<lbrakk>uniq' p inff secret; ord p inff\\<rbrakk> \\<Longrightarrow> uniq p secret\"\nunfolding uniq_def\napply (rule allI)+\napply (case_tac \"inff R R'\")\napply (blast dest: uniq'D)\nby (auto dest: ordD uniq'D intro: sym)\n\nsubsection\\<open>Needham-Schroeder-Lowe\\<close>\n\ndefinition a :: agent where \"a == Friend 0\"\ndefinition b :: agent where \"b == Friend 1\"\ndefinition a' :: agent where \"a' == Friend 2\"\ndefinition b' :: agent where \"b' == Friend 3\"\ndefinition Na :: nat where \"Na == 0\"\ndefinition Nb :: nat where \"Nb == 1\"\n\nabbreviation\n  ns1 :: rule where\n  \"ns1 == ({}, Says a b (Crypt (pubK b) \\<lbrace>Nonce Na, Agent a\\<rbrace>))\"\n\nabbreviation\n  ns2 :: rule where\n  \"ns2 == ({Says a' b (Crypt (pubK b) \\<lbrace>Nonce Na, Agent a\\<rbrace>)},\n    Says b a (Crypt (pubK a) \\<lbrace>Nonce Na, Nonce Nb, Agent b\\<rbrace>))\"\n\nabbreviation\n  ns3 :: rule where\n  \"ns3 == ({Says a b (Crypt (pubK b) \\<lbrace>Nonce Na, Agent a\\<rbrace>),\n    Says b' a (Crypt (pubK a) \\<lbrace>Nonce Na, Nonce Nb, Agent b\\<rbrace>)},\n    Says a b (Crypt (pubK b) (Nonce Nb)))\"\n\ninductive_set ns :: proto where\n  [iff]: \"ns1 \\<in> ns\"\n| [iff]: \"ns2 \\<in> ns\"\n| [iff]: \"ns3 \\<in> ns\"\n\nabbreviation (input)\n  ns3a :: event where\n  \"ns3a == Says a b (Crypt (pubK b) \\<lbrace>Nonce Na, Agent a\\<rbrace>)\"\n\nabbreviation (input)\n  ns3b :: event where\n  \"ns3b == Says b' a (Crypt (pubK a) \\<lbrace>Nonce Na, Nonce Nb, Agent b\\<rbrace>)\"\n\ndefinition keys :: \"keyfun\" where\n\"keys R' s' n evs == {priK' s' a, priK' s' b}\"\n\nlemma \"monoton ns keys\"\nby (simp add: keys_def monoton_def)\n\ndefinition secret :: \"secfun\" where\n\"secret R n s Ks ==\n(if R=ns1 then apm s (Crypt (pubK b) \\<lbrace>Nonce Na, Agent a\\<rbrace>)\nelse if R=ns2 then apm s (Crypt (pubK a) \\<lbrace>Nonce Na, Nonce Nb, Agent b\\<rbrace>)\nelse Number 0)\"\n\ndefinition inf :: \"rule => rule => bool\" where\n\"inf R R' == (R=ns1 | (R=ns2 & R'~=ns1) | (R=ns3 & R'=ns3))\"\n\nlemma inf_is_ord [iff]: \"ord ns inf\"\napply (unfold ord_def inf_def)\napply (rule allI)+\napply (rule impI)\napply (simp add: split_paired_all)\nby (rule impI, erule ns.cases, simp_all)+\n\nsubsection\\<open>general properties\\<close>\n\nlemma ns_has_only_Says' [iff]: \"has_only_Says' ns\"\napply (unfold has_only_Says'_def)\napply (rule allI, rule impI)\napply (simp add: split_paired_all)\nby (erule ns.cases, auto)\n\nlemma newn_ns1 [iff]: \"newn ns1 = {Na}\"\nby (simp add: newn_def)\n\nlemma newn_ns2 [iff]: \"newn ns2 = {Nb}\"\nby (auto simp: newn_def Na_def Nb_def)\n\nlemma newn_ns3 [iff]: \"newn ns3 = {}\"\nby (auto simp: newn_def)\n\nlemma ns_wdef [iff]: \"wdef ns\"\nby (auto simp: wdef_def elim: ns.cases)\n\nsubsection\\<open>guardedness for NSL\\<close>\n\nlemma \"uniq ns secret \\<Longrightarrow> preserv ns keys n Ks\"\nunfolding preserv_def\napply (rule allI)+\napply (rule impI, rule impI, rule impI, rule impI, rule impI)\napply (erule fresh_ruleD, simp, simp, simp, simp)\napply (rule allI)+\napply (rule impI, rule impI, rule impI)\napply (simp add: split_paired_all)\napply (erule ns.cases)\n(* fresh with NS1 *)\napply (rule impI, rule impI, rule impI, rule impI, rule impI, rule impI)\napply (erule ns.cases)\n(* NS1 *)\napply clarsimp\napply (frule newn_neq_used, simp, simp)\napply (rule No_Nonce, simp)\n(* NS2 *)\napply clarsimp\napply (frule newn_neq_used, simp, simp)\napply (case_tac \"nonce sa Na = nonce s Na\")\napply (frule Guard_safe, simp)\napply (frule Crypt_guard_invKey, simp)\napply (frule ok_Guard, simp, simp, simp, clarsimp)\napply (frule_tac K=\"pubK' s b\" in Crypt_guard_invKey, simp)\napply (frule_tac R=ns1 and R'=ns1 and Ks=Ks and s=sa and s'=s in uniqD, simp+)\napply (simp add: secret_def, simp add: secret_def, force, force)\napply (simp add: secret_def keys_def, blast)\napply (rule No_Nonce, simp)\n(* NS3 *)\napply clarsimp\napply (case_tac \"nonce sa Na = nonce s Nb\")\napply (frule Guard_safe, simp)\napply (frule Crypt_guard_invKey, simp)\napply (frule_tac x=ns3b in ok_Guard, simp, simp, simp, clarsimp)\napply (frule_tac K=\"pubK' s a\" in Crypt_guard_invKey, simp)\napply (frule_tac R=ns1 and R'=ns2 and Ks=Ks and s=sa and s'=s in uniqD, simp+)\napply (simp add: secret_def, simp add: secret_def, force, force)\napply (simp add: secret_def, rule No_Nonce, simp)\n(* fresh with NS2 *)\napply (rule impI, rule impI, rule impI, rule impI, rule impI, rule impI)\napply (erule ns.cases)\n(* NS1 *)\napply clarsimp\napply (frule newn_neq_used, simp, simp)\napply (rule No_Nonce, simp)\n(* NS2 *)\napply clarsimp\napply (frule newn_neq_used, simp, simp)\napply (case_tac \"nonce sa Nb = nonce s Na\")\napply (frule Guard_safe, simp)\napply (frule Crypt_guard_invKey, simp)\napply (frule ok_Guard, simp, simp, simp, clarsimp)\napply (frule_tac K=\"pubK' s b\" in Crypt_guard_invKey, simp)\napply (frule_tac R=ns2 and R'=ns1 and Ks=Ks and s=sa and s'=s in uniqD, simp+)\napply (simp add: secret_def, simp add: secret_def, force, force)\napply (simp add: secret_def, rule No_Nonce, simp)\n(* NS3 *)\napply clarsimp\napply (case_tac \"nonce sa Nb = nonce s Nb\")\napply (frule Guard_safe, simp)\napply (frule Crypt_guard_invKey, simp)\napply (frule_tac x=ns3b in ok_Guard, simp, simp, simp, clarsimp)\napply (frule_tac K=\"pubK' s a\" in Crypt_guard_invKey, simp)\napply (frule_tac R=ns2 and R'=ns2 and Ks=Ks and s=sa and s'=s in uniqD, simp+)\napply (simp add: secret_def, simp add: secret_def, force, force)\napply (simp add: secret_def keys_def, blast)\napply (rule No_Nonce, simp)\n(* fresh with NS3 *)\nby simp\n\nsubsection\\<open>unicity for NSL\\<close>\n\nlemma \"uniq' ns inf secret\"\napply (unfold uniq'_def)\napply (rule allI)+\napply (simp add: split_paired_all)\napply (rule impI, erule ns.cases)\n(* R = ns1 *)\napply (rule impI, erule ns.cases)\n(* R' = ns1 *)\napply (rule impI, rule impI, rule impI, rule impI)\napply (rule impI, rule impI, rule impI, rule impI)\napply (rule impI, erule tr.induct)\n(* Nil *)\napply (simp add: secret_def)\n(* Fake *)\napply (clarify, simp add: secret_def)\napply (drule notin_analz_insert)\napply (drule Crypt_insert_synth, simp, simp, simp)\napply (drule Crypt_insert_synth, simp, simp, simp, simp)\n(* Proto *)\napply (erule_tac P=\"ok evsa R sa\" in rev_mp)\napply (simp add: split_paired_all)\napply (erule ns.cases)\n(* ns1 *)\napply (clarify, simp add: secret_def)\napply (erule disjE, erule disjE, clarsimp)\napply (drule ok_parts_not_new, simp, simp, simp)\napply (clarify, drule ok_parts_not_new, simp, simp, simp)\n(* ns2 *)\napply (simp add: secret_def)\n(* ns3 *)\napply (simp add: secret_def)\n(* R' = ns2 *)\napply (rule impI, rule impI, rule impI, rule impI)\napply (rule impI, rule impI, rule impI, rule impI)\napply (rule impI, erule tr.induct)\n(* Nil *)\napply (simp add: secret_def)\n(* Fake *)\napply (clarify, simp add: secret_def)\napply (drule notin_analz_insert)\napply (drule Crypt_insert_synth, simp, simp, simp)\napply (drule_tac n=\"nonce s' Nb\" in Crypt_insert_synth, simp, simp, simp, simp)\n(* Proto *)\napply (erule_tac P=\"ok evsa R sa\" in rev_mp)\napply (simp add: split_paired_all)\napply (erule ns.cases)\n(* ns1 *)\napply (clarify, simp add: secret_def)\napply (drule_tac s=sa and n=Na in ok_parts_not_new, simp, simp, simp)\n(* ns2 *)\napply (clarify, simp add: secret_def)\napply (drule_tac s=sa and n=Nb in ok_parts_not_new, simp, simp, simp)\n(* ns3 *)\napply (simp add: secret_def)\n(* R' = ns3 *)\napply simp\n(* R = ns2 *)\napply (rule impI, erule ns.cases)\n(* R' = ns1 *)\napply (simp only: inf_def, blast)\n(* R' = ns2 *)\napply (rule impI, rule impI, rule impI, rule impI)\napply (rule impI, rule impI, rule impI, rule impI)\napply (rule impI, erule tr.induct)\n(* Nil *)\napply (simp add: secret_def)\n(* Fake *)\napply (clarify, simp add: secret_def)\napply (drule notin_analz_insert)\napply (drule_tac n=\"nonce s' Nb\" in Crypt_insert_synth, simp, simp, simp)\napply (drule_tac n=\"nonce s' Nb\" in Crypt_insert_synth, simp, simp, simp, simp)\n(* Proto *)\napply (erule_tac P=\"ok evsa R sa\" in rev_mp)\napply (simp add: split_paired_all)\napply (erule ns.cases)\n(* ns1 *)\napply (simp add: secret_def)\n(* ns2 *)\napply (clarify, simp add: secret_def)\napply (erule disjE, erule disjE, clarsimp, clarsimp)\napply (drule_tac s=sa and n=Nb in ok_parts_not_new, simp, simp, simp)\napply (erule disjE, clarsimp)\napply (drule_tac s=sa and n=Nb in ok_parts_not_new, simp, simp, simp)\nby (simp_all add: secret_def)\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/Auth/Guard/Proto.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5078118791767282, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.2558895393851212}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory L2Opt\nimports L2Defs L2Peephole\nbegin\n\nML {*\nstructure L2FlowThms =\n  Named_Thms (\n    val name = Binding.name \"L2flow\"\n    val description = \"Flow-sensitive optimisations carried out after L2 monadic conversion.\"\n    )\n*}\n\nattribute_setup L2flow = {*\n  Attrib.add_del\n    (Thm.declaration_attribute L2FlowThms.add_thm)\n    (Thm.declaration_attribute L2FlowThms.del_thm) *}\n  \"Peephole optimisations carried out after L2 monadic conversion.\"\n\n(*\n * The monads \"A\" and \"B\" are equivalent under precondition \"P\".\n * Additionally, under this precondition, they always leave the\n * postcondition \"Q\" (normally) or \"E\" (if an exception occurs).\n *)\ndefinition\n  \"monad_equiv P A B Q E \\<equiv> (\\<forall>s. P s \\<longrightarrow> A s = B s) \\<and> \\<lbrace> P \\<rbrace> A \\<lbrace> Q \\<rbrace>, \\<lbrace> E \\<rbrace>\"\n\nlemma monad_equivI [intro]:\n  \"\\<lbrakk> \\<And>s. P s \\<Longrightarrow> A s = B s; \\<lbrace> P \\<rbrace> A \\<lbrace> Q \\<rbrace>, \\<lbrace> E \\<rbrace> \\<rbrakk> \\<Longrightarrow> monad_equiv P A B Q E\"\n  apply (clarsimp simp: monad_equiv_def)\n  done\n\nlemma monad_equiv_eqI [intro]:\n  \"\\<lbrakk> \\<lbrace> P \\<rbrace> A \\<lbrace> Q \\<rbrace>, \\<lbrace> E \\<rbrace> \\<rbrakk> \\<Longrightarrow> monad_equiv P A A Q E\"\n  apply (clarsimp simp: monad_equiv_def)\n  done\n\nlemma monad_equiv_eq:\n    \"monad_equiv (\\<lambda>_. True) A B X Y \\<Longrightarrow> A = B\"\n  apply (rule ext)\n  apply (clarsimp simp: monad_equiv_def)\n  done\n\nlemma monad_equiv_triv [L2flow]:\n    \"monad_equiv P A A (\\<lambda>_ _. \\<exists>s. P s) (\\<lambda>_ _. \\<exists>s. P s)\"\n  apply rule\n  apply wp\n  apply force\n  done\n\nlemma monad_equiv_symmetric:\n  \"monad_equiv P A B X Y = monad_equiv P B A X Y\"\n  apply (clarsimp simp: monad_equiv_def validE_def2 Ball_def split: sum.splits)\n  apply force\n  done\n\nlemma monad_equivD: \"\\<lbrakk> monad_equiv P A B R E; P s \\<rbrakk> \\<Longrightarrow> A s = B s\"\n  apply (clarsimp simp: monad_equiv_def)\n  done\n\n(*\n * Show that under condition \"P\", the values \"A\" and \"B\" are equal.\n *\n * We use this to simplify expressions inside our monads in a (somewhat)\n * controlled fashion.\n *)\ndefinition \"simp_expr P A B \\<equiv> P \\<longrightarrow> A = B\"\n\nlemma simp_expr_triv: \"simp_expr P A A\"\n  apply (clarsimp simp: simp_expr_def)\n  done\n\nlemma simp_expr_P_cong:\n  \"\\<lbrakk> P = P' \\<rbrakk> \\<Longrightarrow> simp_expr P A B = simp_expr P' A B\"\n  apply (clarsimp simp: simp_expr_def)\n  done\n\nlemma simp_expr_rhs_cong [cong]:\n  \"\\<lbrakk> P = P'; P' \\<Longrightarrow> B = B' \\<rbrakk> \\<Longrightarrow> simp_expr P A B = simp_expr P' A B'\"\n  apply (clarsimp simp: simp_expr_def simp_implies_def)\n  done\n\nlemma simp_expr_weaken:\n  \"\\<lbrakk> simp_expr P A B; Q \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> simp_expr Q A B\"\n  apply (clarsimp simp: simp_expr_def)\n  done\n\n(*\n * Monad simplification rules.\n *)\n\nlemma monad_equiv_gets [L2flow]:\n    \"simp_expr True v v' \\<Longrightarrow> monad_equiv P (L2_gets (\\<lambda>s. v s) n) (L2_gets (\\<lambda>s. v' s) n)\n        (\\<lambda>r s. P s \\<and> r = v' s) (\\<lambda>_ _. False)\"\n  apply rule\n   apply (clarsimp simp: L2_defs simp_expr_def)+\n  done\n\nlemma monad_equiv_throw [L2flow]:\n    \"simp_expr True v v' \\<Longrightarrow>\n       monad_equiv P (L2_throw v n) (L2_throw v' n) (\\<lambda>_ _. False) (\\<lambda>r s. P s \\<and> r = v')\"\n  apply (clarsimp simp: monad_equiv_def L2_defs simp_expr_def)\n  apply wp\n  apply force\n  done\n\nlemma monad_equiv_guard:\n    \"\\<lbrakk> \\<And>s. simp_expr (P s) (G s) (G' s) \\<rbrakk> \\<Longrightarrow>\n        monad_equiv P (L2_guard (\\<lambda>s. G s)) (L2_guard (\\<lambda>s. G' s)) (\\<lambda>r s. P s \\<and> G' s \\<and> r = ()) (\\<lambda>_ _. False)\"\n  apply (clarsimp simp: monad_equiv_def L2_defs simp_expr_def)\n  apply rule\n   apply (clarsimp simp: liftE_def guard_def bind_def in_return snd_return)\n  apply wp\n  apply force\n  done\n\n(* We use this weaker form of guard simplification to prevent bound\n * variables being expanded inside of guard statements. *)\nlemma monad_equiv_guard' [L2flow]:\n    \"\\<lbrakk> \\<And>s. simp_expr True (G s) (G' s) \\<rbrakk> \\<Longrightarrow>\n        monad_equiv P (L2_guard G) (L2_guard G') (\\<lambda>r s. P s \\<and> G' s \\<and> r = ()) (\\<lambda>_ _. False)\"\n  apply (rule monad_equiv_guard)\n  apply (rule simp_expr_weaken)\n   apply assumption\n  apply simp\n  done\n\nlemma monad_equiv_guard_False [L2flow]:\n    \"\\<lbrakk> \\<And>s. simp_expr (P s) False (G s) \\<rbrakk>\n          \\<Longrightarrow> monad_equiv P (L2_guard G) (L2_fail) (\\<lambda>_ _. False) (\\<lambda>_ _. False)\"\n  apply (monad_eq simp: L2_defs monad_equiv_def simp_expr_def validE_def2)\n  done\n\nlemma monad_equiv_guard_True [L2flow]:\n    \"\\<lbrakk> \\<And>s. simp_expr (P s) True (G s) \\<rbrakk>\n          \\<Longrightarrow> monad_equiv P (L2_guard G) L2_skip (\\<lambda>r s. P s \\<and> r = ()) (\\<lambda>_ _. False)\"\n  apply (auto simp: L2_defs simp_expr_def guard_def liftE_def return_def returnOk_def bind_def validE_def valid_def)\n  done\n\nlemma monad_equiv_guard_conj [L2flow]:\n    \"\\<lbrakk> monad_equiv P (L2_guard G1) G1' R1 E1;\n       monad_equiv (\\<lambda>s. R1 () s) (L2_guard G2) G2' R2 E2 \\<rbrakk> \\<Longrightarrow>\n        monad_equiv P (L2_guard (\\<lambda>s. G1 s \\<and> G2 s)) (L2_seq G1' (\\<lambda>_. G2')) (\\<lambda>r s. R2 () s) (\\<lambda>_ _. False)\"\n  apply (subst (asm) (1 2) monad_equiv_symmetric)\n  apply (subst monad_equiv_symmetric)\n  apply rule\n   apply (monad_eq simp: L2_defs monad_equiv_def validE_def2 Bex_def Ball_def split: sum.splits)\n   apply fast\n  apply (monad_eq simp: monad_equiv_def L2_defs validE_def2 Ball_def split: sum.splits)\n  apply fast\n  done\n\nlemma monad_equiv_unknown [L2flow]:\n    \"monad_equiv P (L2_unknown name) (L2_unknown name) (\\<lambda>r s. P s) (\\<lambda>_ _. False)\"\n  apply (clarsimp simp: monad_equiv_def L2_defs)\n  apply (wp select_wp)\n  apply force\n  done\n\nlemma monad_equiv_modify [L2flow]:\n    \"\\<lbrakk> \\<And>s. simp_expr True (m s) (m' s) \\<rbrakk> \\<Longrightarrow>\n        monad_equiv P (L2_modify (\\<lambda>s. m s)) (L2_modify (\\<lambda>s. m' s)) (\\<lambda>r s'. \\<exists>s. P s \\<and> m' s = s' \\<and> r = ()) (\\<lambda>_ _. False)\"\n  apply rule\n   apply (clarsimp simp: L2_defs simp_expr_def liftE_def modify_def put_def get_def bind_def)\n  apply (clarsimp simp: L2_defs simp_expr_def)\n  apply force\n  done\n\nlemma monad_equiv_spec [L2flow]:\n    \"\\<lbrakk> \\<And>s s'. simp_expr True ((s, s') \\<in> S) (S' s s') \\<rbrakk> \\<Longrightarrow>\n        monad_equiv P (L2_spec S) (L2_spec ({(s, s'). S' s s'})) (\\<lambda>r s. \\<exists>s. P s) (\\<lambda>_ _. False)\"\n  apply rule\n   apply (clarsimp simp: L2_defs simp_expr_def liftE_def spec_def bind_def)\n  apply (clarsimp simp: L2_defs)\n  apply wp\n  apply force\n  done\n\nlemma monad_equiv_fail [L2flow]:\n    \"monad_equiv P L2_fail L2_fail (\\<lambda>_ _. False) (\\<lambda>_ _. False)\"\n  apply (clarsimp simp: monad_equiv_def L2_defs)\n  done\n\nlemma monad_equiv_condition [L2flow]:\n  \"\\<lbrakk> \\<And>s. simp_expr True (C s) (C' s);\n     monad_equiv (\\<lambda>s. P s \\<and> C' s) L L' QL EL;\n     monad_equiv (\\<lambda>s. P s \\<and> \\<not> C' s) R R' QR ER \\<rbrakk> \\<Longrightarrow>\n   monad_equiv P (L2_condition (\\<lambda>s. C s) L R) (L2_condition (\\<lambda>s. C' s) L' R')\n      (\\<lambda>r s. \\<exists>s. P s) (* Deliberately weak to avoid exponential growth. *)\n      (\\<lambda>r s. \\<exists>s. P s)\"\n  apply rule\n   apply (monad_eq simp: L2_defs monad_equiv_def simp_expr_def split: condition_splits)\n  apply (monad_eq simp: L2_defs monad_equiv_def validE_def2 split: condition_splits sum.splits)\n  apply force\n  done\n\nlemma monad_equiv_condition_True [L2flow]:\n  \"\\<lbrakk> \\<And>s. simp_expr (P s) (C s) True;\n     monad_equiv P L L' QL EL \\<rbrakk> \\<Longrightarrow>\n     monad_equiv P (L2_condition C L R) L' QL EL\"\n  unfolding L2_defs condition_def\n  apply (monad_eq simp: simp_expr_def monad_equiv_def validE_def2 Ball_def split: sum.splits)\n  done\n\nlemma monad_equiv_condition_False [L2flow]:\n  \"\\<lbrakk> \\<And>s. simp_expr (P s) (C s) False;\n     monad_equiv P R R' QR ER \\<rbrakk> \\<Longrightarrow>\n     monad_equiv P (L2_condition C L R) R' QR ER\"\n  unfolding L2_defs condition_def\n  apply (monad_eq simp: simp_expr_def monad_equiv_def validE_def2 Ball_def split: sum.splits)\n  done\n\n(* C-parser sometimes generates boolean expressions like\n     if P then (if P then 1 else 0) else Q\n   This simplifies the branches. *)\nlemma monad_equiv_gets_if [L2flow]:\n   \"\\<lbrakk> \\<And>s. simp_expr (P s) True (b s) \\<rbrakk> \\<Longrightarrow>\n       monad_equiv P (L2_gets (\\<lambda>s. if (b s) then L else R) f)\n                     (L2_gets (\\<lambda>s. L) f) (%r s. P s) (\\<lambda>r s. False)\"\n   \"\\<lbrakk> \\<And>s. simp_expr (P s) False (b s) \\<rbrakk> \\<Longrightarrow>\n       monad_equiv P (L2_gets (\\<lambda>s. if (b s) then L else R) f)\n                     (L2_gets (\\<lambda>s. R) f) (%r s. P s) (\\<lambda>r s. False)\"\n  apply (monad_eq simp: L2_defs simp_expr_def monad_equiv_def\n         validE_def valid_def split: sum.splits)+\n  done\n\nlemma monad_equiv_seq [L2flow]:\n  \"\\<lbrakk> monad_equiv P A A' Q E;\n     \\<And>x. monad_equiv (Q x) (B x) (B' x) (R x) (E2 x) \\<rbrakk> \\<Longrightarrow>\n   monad_equiv P (L2_seq A (\\<lambda>x. B x)) (L2_seq A' (\\<lambda>x. B' x)) (\\<lambda>r s. \\<exists>r'. R r' r s) (\\<lambda>r s. \\<exists>s. P s)\"\n  apply rule\n   apply (clarsimp simp: monad_equiv_def L2_defs simp_expr_def)\n   apply (rule bindE_apply_cong)\n    apply simp\n   apply (clarsimp simp: validE_def valid_def)\n   apply force\n  apply (clarsimp simp: monad_equiv_def L2_defs\n               validE_def valid_def in_bindE simp_expr_def split: sum.splits)\n  apply (erule allE, erule (1) impE)+\n  apply fastforce\n  done\n\nlemma monad_equiv_catch [L2flow]:\n  \"\\<lbrakk> monad_equiv P A A' Q E;\n    \\<And>x. monad_equiv (E x) (B x) (B' x) (Q' x) (E2 x) \\<rbrakk> \\<Longrightarrow>\n   monad_equiv P (L2_catch A (\\<lambda>x. B x)) (L2_catch A' (\\<lambda>x. B' x)) (\\<lambda>r s. \\<exists>s. P s) (\\<lambda>r s. \\<exists>r'. E2 r' r s)\"\n  apply rule\n   apply atomize\n   apply (clarsimp simp: simp_expr_def L2_defs monad_equiv_def)\n   apply (erule allE, erule impE, assumption)\n   apply (clarsimp simp: validE_def2 split: sum.splits)\n   apply (erule allE, erule impE, assumption)\n   apply (rule monad_state_eqI)\n     apply (clarsimp simp: in_handleE')\n     apply force\n    apply (clarsimp simp: in_handleE')\n    apply force\n   apply (fastforce simp: snd_handleE')\n  apply (clarsimp simp: monad_equiv_def L2_defs\n      validE_def valid_def simp_expr_def in_handleE' split: sum.splits)\n  apply (erule allE, erule (1) impE)+\n  apply fastforce\n  done\n\nlemma monad_equiv_cong:\n  \"\\<lbrakk> \\<And>s. P s = P' s;\n     \\<And>s. P s \\<Longrightarrow> A s = A' s;\n     \\<And>s. P s \\<Longrightarrow> B s = B' s;\n     \\<And>s s' r. P s \\<Longrightarrow> Q r s' = Q' r s';\n     \\<And>s s' r. P s \\<Longrightarrow> R r s' = R' r s' \\<rbrakk> \\<Longrightarrow>\n   monad_equiv P A B Q R = monad_equiv P' A' B' Q' R'\"\n  apply atomize\n  apply (clarsimp simp: monad_equiv_def validE_def valid_def split: sum.splits)\n  apply (rule iffI)\n   apply clarsimp\n   apply fastforce\n  apply clarsimp\n  apply fastforce\n  done\n\nlemma monad_equiv_while [L2flow]:\n  assumes cond_simp: \"\\<And>s r. simp_expr True (c r s) (c' r s)\"\n  assumes body_equiv: \"\\<And>r. monad_equiv (\\<lambda>s. (\\<exists>s'. P s') \\<and> c' r s) (B r) (B' r) (Q r) (E r)\"\n  assumes init_simp: \"\\<And>s r. simp_expr True x x'\"\n  shows \"monad_equiv P (L2_while (\\<lambda>r s. c r s) B x n) (L2_while (\\<lambda>r s. c' r s) B' x' n) (\\<lambda>r s. \\<not> c' r s \\<and> (\\<exists>x. P x)) (\\<lambda>r s. \\<exists>x. E x r s)\"\n  apply (insert cond_simp [unfolded simp_expr_def] init_simp [unfolded simp_expr_def])\n  apply rule\n   apply (clarsimp simp: L2_while_def)\n   apply (rule whileLoopE_cong [THEN fun_cong, THEN fun_cong])\n     apply force\n    apply (cut_tac r=r in body_equiv)\n    apply (clarsimp simp: monad_equiv_def)\n    apply (erule allE, erule impE, auto)[1]\n   apply simp\n  apply (clarsimp simp: L2_while_def)\n  apply (rule validE_whileLoopE [where I=\"\\<lambda>r s. \\<exists>s. P s\"])\n    apply force\n   apply (cut_tac r=r in body_equiv)\n   apply (clarsimp simp: validE_def valid_def monad_equiv_def split: sum.splits)\n   apply blast\n  apply simp\n  done\n\nlemma monad_equiv_recguard [L2flow]:\n  \"\\<lbrakk> monad_equiv P B B' Q E \\<rbrakk> \\<Longrightarrow>\n    monad_equiv P (L2_recguard a B) (L2_recguard a B') Q E\"\n  apply rule\n   apply (clarsimp simp: L2_recguard_def monad_equiv_def valid_def validE_def\n        split: sum.splits condition_splits)\n  apply (clarsimp simp: L2_recguard_def monad_equiv_def valid_def validE_def in_fail\n       split: sum.splits condition_splits)\n  done\n\nlemma monad_equiv_unreachable' [L2flow]:\n  \"monad_equiv (\\<lambda>_. False) L (L2_gets (\\<lambda>_. undefined) [''L2Opt_internal_var'']) Q R\"\n  apply (monad_eq simp: monad_equiv_def L2_defs simp_expr_def valid_def validE_def)\n  done\n\nlemma monad_equiv_split [L2flow]:\n  \"\\<lbrakk> \\<And>a b. monad_equiv (P (a, b)) (X a b) (Y a b) (Q a b) (E a b) \\<rbrakk> \\<Longrightarrow>\n    monad_equiv (P x) (case x of (a, b) \\<Rightarrow> X a b) (case x of (a, b) \\<Rightarrow> Y a b)\n          (case x of (a, b) \\<Rightarrow> Q a b) (case x of (a, b) \\<Rightarrow> E a b)\"\n  apply (clarsimp simp: monad_equiv_def validE_def valid_def split_def)\n  done\n\nlemma simp_expr_solve_constant: \"\\<lbrakk> A \\<Longrightarrow> B = C \\<rbrakk> \\<Longrightarrow> simp_expr A B C\"\n  by (clarsimp simp: simp_expr_def)\n\nlemma monad_equiv_weaken_pre':\n  \"\\<lbrakk> \\<And>s. P' s \\<Longrightarrow> P s; monad_equiv P L R Q E \\<rbrakk> \\<Longrightarrow> monad_equiv P' L R Q E\"\n  by (fastforce simp: monad_equiv_def validE_def valid_def)\n\nlemma monad_equiv_weaken_pre'':\n  \"\\<lbrakk> P' \\<equiv> P; monad_equiv P L R Q E \\<rbrakk> \\<Longrightarrow> monad_equiv P' L R Q E\"\n  by (fastforce simp: monad_equiv_def validE_def valid_def)\n\nend\n", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/autocorres/L2Opt.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5039061705290806, "lm_q2_score": 0.5078118642792044, "lm_q1q2_score": 0.2558895318781671}}
{"text": "\nsection \"Algebraic laws for abrupt designs\"\ntheory algebraic_laws_abrupt\nimports algebraic_laws_abrupt_aux\n\nbegin\n(*TODO: add laws for assigns when composed with try catch...*)\nsubsection\"Simpset configuration\"\n\ndeclare urel_comp [uabr_comp]\ndeclare urel_cond [uabr_cond]\n\nsubsection\"Throw\"\n\nlemma throw_cpa_left_zero_true_abr[uabr_comp]:\n  \"(THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; true) = (true)\"\n  by rel_auto\n\nlemma throw_cpa_left_zero_true_lift_abr[uabr_comp]:\n  \"(THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; \\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R) = (\\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R)\"\n  by rel_auto\n\nlemma throw_cpa_left_zero_false_lift_abr[uabr_comp]:\n  \"(THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; \\<lceil>false\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R) = (\\<lceil>false\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R)\"\n  by rel_auto\n\nlemma throw_cpa_left_zero_skip_abr[uabr_comp]:\n  \"(THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; SKIP\\<^sub>A\\<^sub>B\\<^sub>R) = (THROW\\<^sub>A\\<^sub>B\\<^sub>R)\"\n  by rel_auto\n\nlemma throw_cpa_left_zero_assigns_abr[uabr_comp]:\n  \"(THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; \\<langle>\\<sigma>\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R) = (THROW\\<^sub>A\\<^sub>B\\<^sub>R)\"\n  by rel_auto\n\n(*lemma throw_cpa_left_zero_top_abr[uabr_comp]:\n  \"(THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; \\<top>\\<^sub>A\\<^sub>B\\<^sub>R) = (\\<top>\\<^sub>A\\<^sub>B\\<^sub>R)\"\n  by rel_auto*)\n\nlemma not_abrupt_left_zero_throw_abr[uabr_comp]: \n  \"(($x) ;; THROW\\<^sub>A\\<^sub>B\\<^sub>R) = ($x)\" \n  by rel_auto \n\nlemma abrupt_left_zero_throw_abr[uabr_comp]: \n  \"($aburpt ;; THROW\\<^sub>A\\<^sub>B\\<^sub>R) = $aburpt\" \n  by rel_auto \n\nlemma bot_left_zero_throw_abr[uabr_comp]: \n  \"(\\<top>\\<^sub>A\\<^sub>B\\<^sub>R ;; THROW\\<^sub>A\\<^sub>B\\<^sub>R) = (\\<top>\\<^sub>A\\<^sub>B\\<^sub>R)\" \n  by rel_auto\n\n(*lemma throw_abr_idem [uabr_comp]: \n  \"(THROW\\<^sub>A\\<^sub>B\\<^sub>R ;; THROW\\<^sub>A\\<^sub>B\\<^sub>R) = THROW\\<^sub>A\\<^sub>B\\<^sub>R\" \n  by rel_auto*)\n\nlemma throw_abr_right_zero_skip_abr[uabr_comp]: \n  \"(SKIP\\<^sub>A\\<^sub>B\\<^sub>R ;; THROW\\<^sub>A\\<^sub>B\\<^sub>R) = THROW\\<^sub>A\\<^sub>B\\<^sub>R\" \n  by rel_auto \n\n(*lemma assigns_abr_throw_abr_right[uabr_comp]:\n  \"\\<langle>\\<sigma>\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R;; THROW\\<^sub>A\\<^sub>B\\<^sub>R = (C3_abr(\\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<turnstile> ($abrupt\\<acute> \\<and> \\<lceil>\\<langle>\\<sigma>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R)))\"\n  by rel_auto\n\nlemma assigns_abr_throw_abr_right[uabr_comp]:\n  \"\\<langle>\\<sigma>\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R;; THROW\\<^sub>A\\<^sub>B\\<^sub>R = (C3_abr(\\<lceil>\\<sigma>\\<rceil>\\<^sub>s\\<^sub>A\\<^sub>B\\<^sub>R \\<dagger> (\\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<turnstile> ($abrupt\\<acute> \\<and> \\<lceil>II\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R))))\"\n  by rel_auto*)\n\nsubsection\"Skip\"\n\ntext{*In this section we introduce the algebraic laws of programming related to the SKIP\n      statement.*}\n\nlemma true_left_zero_skip_cpa_abr[uabr_comp]:\n  \"(SKIP\\<^sub>A\\<^sub>B\\<^sub>R ;; true) = (true)\"\n  by rel_auto\n\nlemma true_lift_abr_left_zero_skip_abr[uabr_comp]:\n  \"(SKIP\\<^sub>A\\<^sub>B\\<^sub>R ;; \\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R) = (\\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R)\"\n  by rel_auto\n\nlemma false_lift_abr_left_zero_skip_abr[uabr_comp]:\n  \"(SKIP\\<^sub>A\\<^sub>B\\<^sub>R ;; \\<lceil>false\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R) = (\\<lceil>false\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R)\"\n  by rel_auto\n\nlemma skip_abr_left_unit_assigns_abr[uabr_comp]:\n  \"(SKIP\\<^sub>A\\<^sub>B\\<^sub>R ;; \\<langle>\\<sigma>\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R) = (\\<langle>\\<sigma>\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R)\"\n  by rel_auto\n\nlemma skip_abr_top_abr_left_zero[uabr_comp]:\n  \"(SKIP\\<^sub>A\\<^sub>B\\<^sub>R ;; \\<top>\\<^sub>A\\<^sub>B\\<^sub>R) = (\\<top>\\<^sub>A\\<^sub>B\\<^sub>R)\"\n  by rel_auto\n\nlemma skip_abr_abrupt_left_zero[uabr_comp]: \n  \"($x ;; SKIP\\<^sub>A\\<^sub>B\\<^sub>R) = $x\" \n  by rel_auto \n\nlemma skip_abr_bot_left_zero[uabr_comp]: \n  \"(\\<top>\\<^sub>A\\<^sub>B\\<^sub>R ;; SKIP\\<^sub>A\\<^sub>B\\<^sub>R) = (\\<top>\\<^sub>A\\<^sub>B\\<^sub>R)\" \n  by rel_auto\n\nlemma skip_abr_idem [uabr_comp]:\n  \"(SKIP\\<^sub>A\\<^sub>B\\<^sub>R ;; SKIP\\<^sub>A\\<^sub>B\\<^sub>R) = SKIP\\<^sub>A\\<^sub>B\\<^sub>R\"\n  by rel_auto\n\nlemma skip_abr_alpha_eq:\n  \"SKIP\\<^sub>A\\<^sub>B\\<^sub>R = Simpl\\<^sub>A\\<^sub>B\\<^sub>R (\\<not>$abrupt\\<acute> \\<and> ($\\<Sigma>\\<^sub>A\\<^sub>B\\<^sub>R\\<acute> =\\<^sub>u $\\<Sigma>\\<^sub>A\\<^sub>B\\<^sub>R))\"\n  by (simp add: skip_lift_cpa_def skip_abr_def)\n\nlemma simpl_pre_skip_abr_post:\n  \"(Simpl\\<^sub>A\\<^sub>B\\<^sub>R \\<lceil>b\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\\<^sub>< \\<and> SKIP\\<^sub>A\\<^sub>B\\<^sub>R) = (SKIP\\<^sub>A\\<^sub>B\\<^sub>R \\<and> Simpl\\<^sub>A\\<^sub>B\\<^sub>R \\<lceil>b\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\\<^sub>>)\"\n  by rel_auto \n\nlemma simpl_pre_skip_abr_var:\n  fixes x :: \"(bool,  ('b) cpa) uvar\"\n  shows \"(Simpl\\<^sub>A\\<^sub>B\\<^sub>R $x \\<and> SKIP\\<^sub>A\\<^sub>B\\<^sub>R) = (SKIP\\<^sub>A\\<^sub>B\\<^sub>R \\<and> Simpl\\<^sub>A\\<^sub>B\\<^sub>R $x\\<acute>)\"\n  by rel_auto\n\nlemma  skip_abr_post_left_unit[uabr_comp]:\n  \"(S \\<turnstile> (SKIP\\<^sub>A\\<^sub>B\\<^sub>R;; Q)) = (S \\<turnstile> Q)\"\n  apply pred_simp \n  apply rel_simp\n  apply fastforce\ndone\n\nlemma  simpl_post_left_unit[uabr_comp]:\n  \"(S \\<turnstile> (Simpl\\<^sub>A\\<^sub>B\\<^sub>R (\\<not>$abrupt\\<acute> \\<and> \\<lceil>II\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R);; Q)) = (S \\<turnstile> Q)\"\n  apply pred_simp \n  apply rel_simp\n  apply transfer\n  apply auto\ndone\n\n\nsubsection {*Assignment Laws*}\ntext{*In this section we introduce the algebraic laws of programming related to the assignment\n      statement.*}\n\nlemma [urel_cond]:\n  \"S \\<turnstile> (\\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<turnstile> (\\<lceil>R\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<and> $abrupt\\<acute>) ;; P \\<triangleleft> \\<not> $abrupt \\<triangleright> Q) = \n   S \\<turnstile> (\\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<turnstile> (\\<lceil>R\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<and> $abrupt\\<acute>);; Q)\"\n  apply pred_simp\n  apply fastforce \ndone\n\nlemma [urel_cond]:\n  \"S \\<turnstile> (\\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<turnstile> (\\<lceil>R\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<and>  $abrupt\\<acute>) ;; P \\<triangleleft> $abrupt \\<triangleright> Q) = \n   S \\<turnstile> (\\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<turnstile> (\\<lceil>R\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<and>  $abrupt\\<acute>);; P)\"\n  apply pred_simp\n  apply fastforce \ndone\n\nlemma not_abrupt_assigns_abr_L6_left_des[urel_cond]:\n  \"((S \\<turnstile> (\\<langle>a\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R;; (P \\<triangleleft> $abrupt \\<triangleright> Q))) \\<triangleleft> \\<not> $abrupt \\<triangleright> R) = \n   ((S \\<turnstile> (\\<langle>a\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R;; Q)) \\<triangleleft> \\<not> $abrupt \\<triangleright> R)\"\n  unfolding assigns_abr_def \n  apply pred_simp \n  apply fastforce\ndone\n\nlemma abrupt_assigns_abr_L6_left_des[urel_cond]:\n  \"((S \\<turnstile> (\\<langle>a\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R;; (P \\<triangleleft> \\<not> $abrupt \\<triangleright> Q))) \\<triangleleft> $abrupt \\<triangleright> R) = \n   ((S \\<turnstile> (\\<langle>a\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R;; Q)) \\<triangleleft> $abrupt \\<triangleright> R)\"\n  unfolding assigns_abr_def \n  apply pred_simp \n  apply rel_simp\n  apply fastforce\ndone\n\nlemma not_abrupt_assigns_abr_L6_right_des[urel_cond]:\n  \"(R \\<triangleleft> \\<not> $abrupt \\<triangleright> (S \\<turnstile> (\\<langle>a\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R;; (P \\<triangleleft> $abrupt \\<triangleright> Q))) ) = \n   ( R \\<triangleleft> \\<not> $abrupt \\<triangleright> (S \\<turnstile> (\\<langle>a\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R;; P)))\"\n  unfolding assigns_abr_def \n  apply pred_simp \n  apply rel_simp\n  apply fastforce\ndone\n\nlemma abrupt_assigns_abr_L6_right_des[urel_cond]:\n \"( R \\<triangleleft> $abrupt \\<triangleright> (S \\<turnstile> (\\<langle>a\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R;; (P \\<triangleleft> \\<not> $abrupt \\<triangleright> Q))) ) = \n  ( R \\<triangleleft> $abrupt \\<triangleright> (S \\<turnstile> (\\<langle>a\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R;; P)) )\"\n  apply pred_simp \n  apply rel_simp\n  apply fastforce\ndone\n\nlemma not_abrupt_left_assigns_abr_post_des[urel_cond]:\n  \"R \\<triangleleft> \\<not> $abrupt \\<triangleright> (S \\<turnstile> (\\<langle>a\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R;; P))  = \n   R \\<triangleleft> \\<not> $abrupt \\<triangleright> (S \\<turnstile> (\\<lceil>true\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<turnstile> (\\<lceil>II\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<and> $abrupt\\<acute>) ;; P))\"\n  unfolding assigns_abr_def \n  apply pred_simp \n  apply rel_simp\ndone\n\nlemma  not_abrupt_left_throw_abr_post_des[urel_cond]:\n  \"R \\<triangleleft> \\<not> $abrupt \\<triangleright> (S \\<turnstile> (THROW\\<^sub>A\\<^sub>B\\<^sub>R;; P))  = \n   R \\<triangleleft> \\<not> $abrupt \\<triangleright> (S \\<turnstile> ((\\<not>$abrupt) \\<turnstile> (\\<lceil>II\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<and> $abrupt\\<acute>) ;; P))\"  \n  unfolding assigns_abr_def \n  apply pred_simp \n  apply rel_simp\ndone\n\nlemma usubst_abr_cancel [usubst]: \n  assumes 1:\"weak_lens v\" \n  shows \"($v)\\<lbrakk>\\<lceil>expr\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\\<^sub></$v\\<rbrakk>= \\<lceil>expr\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\\<^sub><\"\n  using 1\n  by  rel_auto\n\nlemma usubst_abr_lift_cancel[usubst]: \n  assumes 1:\"weak_lens v\" \n  shows \"\\<lceil>($v)\\<lbrakk>\\<lceil>expr\\<rceil>\\<^sub></$v\\<rbrakk>\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R= \\<lceil>expr\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R\\<^sub><\"\n  using 1\n  by  rel_auto\n\nlemma assigns_abr_id [uabr_simpl]: \"SKIP\\<^sub>A\\<^sub>B\\<^sub>R = \\<langle>id\\<rangle>\\<^sub>A\\<^sub>B\\<^sub>R\"\n  unfolding skip_abr_def assigns_abr_def\n  by (rel_auto)\n\nlemma assign_test[uabr_comp]:\n  assumes 1:\"mwb_lens x\" \n  shows     \"(x \\<Midarrow> \\<guillemotleft>u\\<guillemotright> ;; x \\<Midarrow> \\<guillemotleft>v\\<guillemotright>) = (x \\<Midarrow> \\<guillemotleft>v\\<guillemotright>)\"\n  using 1   \n  by (simp add: usubst uabr_comp )\n\nlemma assign_abr_left_comp_subst[uabr_comp]: \n  \"(x \\<Midarrow> u ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R(\\<lceil>P\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<turnstile> \\<lceil>Q\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R)) = Simpl\\<^sub>A\\<^sub>B\\<^sub>R(\\<lceil>P\\<lbrakk>\\<lceil>u\\<rceil>\\<^sub></$x\\<rbrakk>\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R \\<turnstile> \\<lceil>Q\\<lbrakk>\\<lceil>u\\<rceil>\\<^sub></$x\\<rbrakk>\\<rceil>\\<^sub>A\\<^sub>B\\<^sub>R)\" \n  by (simp add: uabr_comp usubst)\n\nlemma assign_abr_twice[uabr_comp]: \n  assumes \"mwb_lens x\" and  \"x \\<sharp> f\" \n  shows \"(x \\<Midarrow> e ;; x \\<Midarrow> f) = (x \\<Midarrow> f)\" \n  using assms\n  by (simp add: uabr_comp usubst)\n   \nlemma assign_abr_commute:\n  assumes \"x \\<bowtie> y\" \"x \\<sharp> f\" \"y \\<sharp> e\"\n  shows \"(x \\<Midarrow> e ;; y \\<Midarrow> f) = (y \\<Midarrow> f ;; x \\<Midarrow> e)\"\n  using assms\n  by (simp add: uabr_comp usubst usubst_upd_comm)\n\nlemma assign_abr_cond_abr[uabr_comp]: (*needs more laws to be automatic*)\n  fixes x :: \"('a, '\\<alpha>) uvar\"\n  shows \"(x \\<Midarrow> e ;; (bif b then Simpl\\<^sub>A\\<^sub>B\\<^sub>R P else Simpl\\<^sub>A\\<^sub>B\\<^sub>R Q eif)) = \n         (bif (b\\<lbrakk>e/x\\<rbrakk>) then (x \\<Midarrow> e ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R P)  else (x \\<Midarrow> e ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R Q) eif)\"\n  apply (simp add: usubst uabr_comp)\n  apply rel_auto\ndone\n\nlemma assign_c_uop1[uabr_comp]: \n  assumes 1: \"mwb_lens v\"\n  shows \"(v \\<Midarrow> e1 ;; v \\<Midarrow> (uop F (&v))) = (v \\<Midarrow> (uop F e1))\"\n  by (simp add: usubst  uabr_comp assms)\n\nlemma assign_c_bop1[uabr_comp]: \n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\"\n  shows \"(v \\<Midarrow> e1 ;; v \\<Midarrow>(bop bp (&v) e2)) = (v \\<Midarrow> (bop bp e1 e2))\"\n  by (simp add: usubst uabr_comp assms)\n \nlemma assign_c_bop2[uabr_comp]: \n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\"\n  shows \"(v \\<Midarrow> e1 ;; v \\<Midarrow> (bop bp e2 (&v))) = (v \\<Midarrow> (bop bp e2 e1))\"\n  by (simp add: usubst uabr_comp assms)\n\nlemma assign_c_trop1[uabr_comp]: \n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\"\n  shows \"(v \\<Midarrow> e1 ;; v \\<Midarrow> (trop tp (&v) e2 e3)) = \n         (v \\<Midarrow> (trop tp e1 e2 e3))\"\n  by (simp add: usubst uabr_comp assms)\n\nlemma assign_c_trop2[uabr_comp]: \n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\"\n  shows \"(v \\<Midarrow> e1 ;; v \\<Midarrow> (trop tp e2 (&v) e3)) = \n         (v \\<Midarrow> (trop tp e2 e1 e3))\"\n  by (simp add: usubst uabr_comp assms)\n\nlemma assign_c_trop3[uabr_comp]: \n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\"\n  shows \"(v \\<Midarrow> e1 ;; v \\<Midarrow> (trop tp e2 e3 (&v))) = \n         (v \\<Midarrow> (trop tp e2 e3 e1))\"\n  by (simp add: usubst uabr_comp assms)\n\nlemma assign_c_qtop1[uabr_comp]: \n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\" and 4:\"v \\<sharp> e4\"\n  shows \"(v \\<Midarrow> e1 ;; v \\<Midarrow> (qtop tp (&v) e2 e3 e4)) = \n         (v \\<Midarrow> (qtop tp e1 e2 e3 e4))\"\n  by (simp add: usubst uabr_comp assms)\n\nlemma assign_c_qtop2[uabr_comp]: \n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\" and 4:\"v \\<sharp> e4\"\n  shows \"(v \\<Midarrow> e1 ;; v \\<Midarrow> (qtop tp e2 (&v) e3 e4)) = \n         (v \\<Midarrow> (qtop tp e2 e1 e3 e4))\"\n  by (simp add: usubst uabr_comp assms)\n\nlemma assign_c_qtop3[uabr_comp]: \n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\" and 4:\"v \\<sharp> e4\"\n  shows \"(v \\<Midarrow> e1 ;; v \\<Midarrow> (qtop tp e2 e3 (&v) e4)) = \n         (v \\<Midarrow> (qtop tp e2 e3 e1 e4))\"\n  by (simp add: usubst uabr_comp assms)\n\nlemma assign_c_qtop4[uabr_comp]: \n  assumes 1: \"mwb_lens v\" and 2:\"v \\<sharp> e2\" and 3:\"v \\<sharp> e3\" and 4:\"v \\<sharp> e4\"\n  shows \"(v \\<Midarrow> e1 ;; v \\<Midarrow> (qtop tp e2 e3 e4 (&v))) = \n         (v \\<Midarrow> (qtop tp e2 e3 e4 e1))\"\n  by (simp add: usubst uabr_comp assms)\n                   \ntext {*In the sequel we define assignment laws proposed by Hoare*}\n\nlemma assign_abr_vwb_skip_abr[uabr_comp]:\n  assumes 1: \"vwb_lens v\"\n  shows \"(v \\<Midarrow> &v) = SKIP\\<^sub>A\\<^sub>B\\<^sub>R\"\n  by (simp add: assms usubst uabr_simpl)\n\nlemma assign_c_simultaneous:\n  assumes  1: \"vwb_lens var2\"\n  and      2: \"var1 \\<bowtie> var2\"\n  shows \"var1, var2 \\<Midarrow> exp, &var2 = var1 \\<Midarrow> exp\"\n  by (simp add: assms usubst_upd_comm usubst)\n\nlemma assign_c_seq[uabr_comp]:\n  assumes  1: \"vwb_lens var2\"\n  shows\"(var1 \\<Midarrow> exp);; (var2 \\<Midarrow> &var2) = (var1 \\<Midarrow> exp)\"\n  by (simp add: assms usubst uabr_comp)\n\nlemma assign_c_cond_c_uop[uabr_comp]: (*needs more laws to be automatic*)\n  assumes 1: \"weak_lens v\"\n  shows \"bif uop F exp then (v \\<Midarrow> exp ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R C1) else (v \\<Midarrow> exp ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R C2) eif = \n          v \\<Midarrow> exp ;; bif uop F (&v) then Simpl\\<^sub>A\\<^sub>B\\<^sub>R C1 else  Simpl\\<^sub>A\\<^sub>B\\<^sub>R C2 eif\"\n  apply (simp add: assms usubst uabr_comp uabr_simpl )\n  apply pred_simp\n  apply rel_simp\n  apply auto\n  apply (metis assms weak_lens.put_get)+\ndone\n\nlemma assign_c_cond_bop1[uabr_comp]: (*needs more laws to be automatic*)\n  assumes 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\"\n  shows \"bif bop bp exp exp2 then (v \\<Midarrow> exp ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R C1) else (v \\<Midarrow> exp ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R C2) eif = \n          v \\<Midarrow> exp ;; bif bop bp (&v) exp2 then Simpl\\<^sub>A\\<^sub>B\\<^sub>R C1 else Simpl\\<^sub>A\\<^sub>B\\<^sub>R C2 eif\"\n  apply (simp add: assms usubst uabr_comp uabr_simpl )\n  apply pred_simp\n  apply rel_simp\n  apply auto\n  apply (metis assms unrest_upred.rep_eq weak_lens.put_get)+\ndone\n\nlemma assign_c_cond_bop2[uabr_comp]: (*needs more laws to be automatic*)\n  assumes 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\"\n  shows \"bif bop bp exp2 exp then (v \\<Midarrow> exp ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R C1) else (v \\<Midarrow> exp ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R C2) eif = \n          v \\<Midarrow> exp ;; bif bop bp  exp2 (&v) then Simpl\\<^sub>A\\<^sub>B\\<^sub>R C1 else Simpl\\<^sub>A\\<^sub>B\\<^sub>R C2 eif\"\n  apply (simp add: assms usubst uabr_comp uabr_simpl )\n  apply pred_simp\n  apply rel_simp\n  apply auto\n  apply (metis assms unrest_upred.rep_eq weak_lens.put_get)+\ndone\n\nlemma assign_cond_trop1[uabr_comp]: (*needs more laws to be automatic*)\n  assumes 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\"\n  shows \"bif trop bp exp exp2 exp3 then (v \\<Midarrow> exp ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R C1) else (v \\<Midarrow> exp ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R C2) eif = \n         v \\<Midarrow> exp ;; bif trop bp (&v) exp2 exp3 then Simpl\\<^sub>A\\<^sub>B\\<^sub>R C1 else Simpl\\<^sub>A\\<^sub>B\\<^sub>R C2 eif\"\n  apply (simp add: assms usubst uabr_comp uabr_simpl )\n  apply pred_simp\n  apply rel_simp\n  apply auto\n  apply (metis assms unrest_upred.rep_eq weak_lens.put_get)+\ndone\n\nlemma assign_cond_trop2[uabr_comp]: (*needs more laws to be automatic*)\n  assumes 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\"\n  shows \"bif trop bp exp2 exp  exp3 then (v \\<Midarrow> exp ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R C1) else (v \\<Midarrow> exp ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R C2) eif = \n         v \\<Midarrow> exp ;; bif trop bp  exp2 (&v) exp3 then Simpl\\<^sub>A\\<^sub>B\\<^sub>R C1 else Simpl\\<^sub>A\\<^sub>B\\<^sub>R C2 eif\"\n  apply (simp add: assms usubst uabr_comp uabr_simpl )\n  apply pred_simp\n  apply rel_simp\n  apply auto\n  apply (metis assms unrest_upred.rep_eq weak_lens.put_get)+\ndone\n\nlemma assign_cond_trop3[uabr_comp]: (*needs more laws to be automatic*)\n  assumes 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\"\n  shows \"bif trop bp exp2 exp3 exp then (v \\<Midarrow> exp ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R C1) else (v \\<Midarrow> exp ;;Simpl\\<^sub>A\\<^sub>B\\<^sub>R C2) eif = \n         v \\<Midarrow> exp ;; bif trop bp exp2 exp3 (&v)  then Simpl\\<^sub>A\\<^sub>B\\<^sub>R C1 else Simpl\\<^sub>A\\<^sub>B\\<^sub>R C2 eif\"\n  apply (simp add: assms usubst uabr_comp uabr_simpl )\n  apply pred_simp\n  apply rel_simp\n  apply auto\n  apply (metis assms unrest_upred.rep_eq weak_lens.put_get)+\ndone\n\nlemma assign_cond_qtop1[uabr_comp]: (*needs more laws to be automatic*)\n  assumes 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\" and 4: \"v \\<sharp> exp4\"\n  shows \"bif qtop bp exp exp2 exp3 exp4 then (v \\<Midarrow> exp ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R C1) else (v \\<Midarrow> exp ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R C2) eif = \n         v \\<Midarrow> exp ;; bif qtop bp (&v) exp2 exp3 exp4 then Simpl\\<^sub>A\\<^sub>B\\<^sub>R C1 else Simpl\\<^sub>A\\<^sub>B\\<^sub>R C2 eif\"\n  apply (simp add: assms usubst uabr_comp uabr_simpl )\n  apply pred_simp\n  apply rel_simp\n  apply auto\n  apply (metis assms unrest_upred.rep_eq weak_lens.put_get)+\ndone\n\nlemma assign_c_cond_qtop2[uabr_comp]: (*needs more laws to be automatic*)\n  assumes 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\" and 4:\"v \\<sharp> exp4\"\n  shows \"bif qtop bp exp2 exp  exp3 exp4 then (v \\<Midarrow> exp ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R C1) else (v \\<Midarrow> exp ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R C2) eif = \n         v \\<Midarrow> exp ;; bif qtop bp exp2 (&v) exp3 exp4 then Simpl\\<^sub>A\\<^sub>B\\<^sub>R C1 else Simpl\\<^sub>A\\<^sub>B\\<^sub>R C2 eif\"\n  apply (simp add: assms usubst uabr_comp uabr_simpl )\n  apply pred_simp\n  apply rel_simp\n  apply auto\n  apply (metis assms unrest_upred.rep_eq weak_lens.put_get)+\ndone\n\nlemma assign_c_cond_qtop3[uabr_comp]: (*needs more laws to be automatic*)\n  assumes 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\" and 4: \"v \\<sharp> exp4\"\n  shows \"bif qtop bp exp2 exp3 exp exp4 then (v \\<Midarrow> exp ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R C1) else (v \\<Midarrow> exp ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R C2) eif = \n         v \\<Midarrow> exp ;; bif qtop bp exp2  exp3 (&v) exp4 then Simpl\\<^sub>A\\<^sub>B\\<^sub>R C1 else Simpl\\<^sub>A\\<^sub>B\\<^sub>R C2 eif\"\n  apply (simp add: assms usubst uabr_comp uabr_simpl )\n  apply pred_simp\n  apply rel_simp\n  apply auto\n  apply (metis assms unrest_upred.rep_eq weak_lens.put_get)+\ndone\n\nlemma assign_c_cond_qtop4[uabr_comp]: (*needs more laws to be automatic*)\n  assumes 1: \"weak_lens v\" and 2: \"v \\<sharp> exp2\" and 3: \"v \\<sharp> exp3\" and 4: \"v \\<sharp> exp4\"\n  shows \"bif qtop bp exp2 exp3 exp4 exp then (v \\<Midarrow> exp ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R C1) else (v \\<Midarrow> exp ;; Simpl\\<^sub>A\\<^sub>B\\<^sub>R C2) eif = \n         v \\<Midarrow> exp ;; bif qtop bp exp2  exp3 exp4 (&v)  then Simpl\\<^sub>A\\<^sub>B\\<^sub>R C1 else Simpl\\<^sub>A\\<^sub>B\\<^sub>R C2 eif\"\n  apply (simp add: assms usubst uabr_comp uabr_simpl)\n  apply pred_simp\n  apply rel_simp\n  apply auto\n  apply (metis assms unrest_upred.rep_eq weak_lens.put_get)+\ndone\n\nlemma assign_c_cond_If [uabr_cond]: \n  \"(bif bexp then (v \\<Midarrow> exp1) else (v \\<Midarrow> exp2) eif) = \n   (v \\<Midarrow> (exp1 \\<triangleleft> bexp \\<triangleright> exp2))\" \n  by rel_auto\n\nsubsection {*While laws*}\ntext{*In this section we introduce the algebraic laws of programming related to the while\n      statement.*}\n\ntheorem while_unfold:\n  \"while b do P od = (bif b then (P ;; while b do P od) else SKIP\\<^sub>A\\<^sub>B\\<^sub>R eif)\"\nproof -\n  have m:\"mono (\\<lambda>X. bif b then (P ;; X) else SKIP\\<^sub>A\\<^sub>B\\<^sub>R eif)\"\n    by (auto intro: monoI seqr_mono if_mono)\n  have \"(while b do P od) = (\\<nu> X \\<bullet> bif b then (P ;; X) else SKIP\\<^sub>A\\<^sub>B\\<^sub>R eif)\"\n    by (simp add: While_def)\n  also have \"... = (bif b then (P ;; (\\<nu> X \\<bullet> bif b then (P ;; X) else SKIP\\<^sub>A\\<^sub>B\\<^sub>R eif)) else SKIP\\<^sub>A\\<^sub>B\\<^sub>R eif)\"\n    by (subst lfp_unfold,simp_all add:m )\n  also have \"... = (bif b then (P ;; while b do P od) else SKIP\\<^sub>A\\<^sub>B\\<^sub>R eif)\"\n    by (simp add: While_def)\n  finally show ?thesis .\nqed\n\n\n(*lemma while_true:\n  shows \"(while true do P od) = \\<top>\\<^sub>A\\<^sub>B\\<^sub>R\"\n  apply (simp add: While_def alpha)\n  apply (rule antisym)\n  apply (simp_all)\n  apply (rule conjI)\n  apply (rule lfp_lowerbound)\n  apply (simp add: C3_abr_def design_def cond_def)\n  apply rel_auto\n  apply (frule cond_mono)\ndone*)\n\nlemma while_false:\n  shows \"(while false do P od) = SKIP\\<^sub>A\\<^sub>B\\<^sub>R\"\nproof -\n  have \"(while false do P od) = bif false then (P ;; while false do P od) else SKIP\\<^sub>A\\<^sub>B\\<^sub>R eif\" \n    using while_unfold[of _ P] by simp\n  also have \"... = SKIP\\<^sub>A\\<^sub>B\\<^sub>R\" by rel_blast\n  finally show ?thesis . \nqed\n\nlemma while_inv_unfold:\n  \"while b invr p do P od = (bif b then (P ;; while b invr p do P od) else SKIP\\<^sub>A\\<^sub>B\\<^sub>R eif)\"\n  unfolding While_inv_def using while_unfold\n  by auto\n\ntheorem while_bot_unfold:\n  \"while\\<^sub>\\<bottom> b do P od = (bif b then (P ;; while\\<^sub>\\<bottom> b do P od) else SKIP\\<^sub>A\\<^sub>B\\<^sub>R eif)\"\nproof -\n  have m:\"mono (\\<lambda>X. bif b then (P ;; X) else SKIP\\<^sub>A\\<^sub>B\\<^sub>R eif)\"\n    by (auto intro: monoI seqr_mono if_mono)\n  have \"(while\\<^sub>\\<bottom> b do P od) = (\\<mu> X \\<bullet> bif b then (P ;; X) else SKIP\\<^sub>A\\<^sub>B\\<^sub>R eif)\"\n    by (simp add: While_bot_def)\n  also have \"... = (bif b then (P ;; (\\<mu> X \\<bullet> bif b then (P ;; X) else SKIP\\<^sub>A\\<^sub>B\\<^sub>R eif)) else SKIP\\<^sub>A\\<^sub>B\\<^sub>R eif)\"\n    by (subst gfp_unfold, simp_all add: m)\n  also have \"... = (bif b then (P ;; while\\<^sub>\\<bottom> b do P od) else SKIP\\<^sub>A\\<^sub>B\\<^sub>R eif)\"\n    by (simp add: While_bot_def)\n  finally show ?thesis .\nqed\n\nterm \"while\\<^sub>\\<bottom> b do P od\"\n\ntheorem while_bot_false: \"while\\<^sub>\\<bottom> false do P od = SKIP\\<^sub>A\\<^sub>B\\<^sub>R\"\n  by (simp add: While_bot_def mu_const alpha)\n\ntheorem while_bot_true: \"while\\<^sub>\\<bottom> true do P od = (\\<mu> X \\<bullet> (P ;; X))\"\n  by (simp add: While_bot_def alpha)\n\nsubsection {*assume laws*}\n\nlemma assume_twice[uabr_comp]: \"(b\\<^sup>\\<top>\\<^sup>C ;; c\\<^sup>\\<top>\\<^sup>C) = (b \\<and> c)\\<^sup>\\<top>\\<^sup>C\"\n  apply pred_simp \n  apply auto\n  apply (rel_simp)+\n  apply blast\n  apply (rel_simp)+\n  apply (metis (full_types))\ndone\n\nlemma assert_twice[uabr_comp]: \"(b\\<^sub>\\<bottom>\\<^sub>C ;; c\\<^sub>\\<bottom>\\<^sub>C) = (b \\<and> c)\\<^sub>\\<bottom>\\<^sub>C\" \n  apply pred_simp \n  apply auto\n  apply (rel_simp)+\n  apply blast\n  apply (rel_simp)+\n  apply (metis (full_types))\ndone\n\nsubsection {*Try Catch laws*}\n(*see utp_hoare_helper*)\n\n\nend", "meta": {"author": "git-vt", "repo": "orca", "sha": "92bda0f9cfe5cc680b9c405fc38f07a960087a36", "save_path": "github-repos/isabelle/git-vt-orca", "path": "github-repos/isabelle/git-vt-orca/orca-92bda0f9cfe5cc680b9c405fc38f07a960087a36/Archive/Programming-Languages-Semantics/WP11-C-semantics/src/IMP-Lenses/hoare/AlgebraicLaws/Abrupt/algebraic_laws_abrupt.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5078118642792044, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.25588953187816704}}
{"text": "(* \n   Title: Psi-calculi   \n   Author/Maintainer: Jesper Bengtson (jebe@itu.dk), 2012\n*)\ntheory Bisim_Pres\n  imports Bisimulation Sim_Pres\nbegin\n\ncontext env begin\n\nlemma bisimInputPres:\n  fixes \\<Psi>    :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   xvec :: \"name list\"\n  and   N    :: 'a\n\n  assumes \"\\<And>Tvec. length xvec = length Tvec \\<Longrightarrow> \\<Psi> \\<rhd> P[xvec::=Tvec] \\<sim> Q[xvec::=Tvec]\"\n\n  shows \"\\<Psi> \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.P \\<sim> M\\<lparr>\\<lambda>*xvec N\\<rparr>.Q\"\nproof -\n  let ?X = \"{(\\<Psi>, M\\<lparr>\\<lambda>*xvec N\\<rparr>.P, M\\<lparr>\\<lambda>*xvec N\\<rparr>.Q) | \\<Psi> M xvec N P Q. \\<forall>Tvec. length xvec = length Tvec \\<longrightarrow> \\<Psi> \\<rhd> P[xvec::=Tvec] \\<sim> Q[xvec::=Tvec]}\"\n\n  from assms have \"(\\<Psi>, M\\<lparr>\\<lambda>*xvec N\\<rparr>.P, M\\<lparr>\\<lambda>*xvec N\\<rparr>.Q) \\<in> ?X\" by blast\n  thus ?thesis\n  proof(coinduct rule: bisimCoinduct)\n    case(cStatEq \\<Psi> P Q)\n    thus ?case by auto\n  next\n    case(cSim \\<Psi> P Q)\n    thus ?case by(blast intro: inputPres)\n  next\n    case(cExt \\<Psi> P Q \\<Psi>')\n    thus ?case by(blast dest: bisimE)\n  next\n    case(cSym \\<Psi> P Q)\n    thus ?case by(blast dest: bisimE)\n  qed\nqed\n  \nlemma bisimOutputPres:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   M :: 'a\n  and   N :: 'a\n\n  assumes \"\\<Psi> \\<rhd> P \\<sim> Q\"\n\n  shows \"\\<Psi> \\<rhd> M\\<langle>N\\<rangle>.P \\<sim> M\\<langle>N\\<rangle>.Q\"\nproof -\n  let ?X = \"{(\\<Psi>, M\\<langle>N\\<rangle>.P, M\\<langle>N\\<rangle>.Q) | \\<Psi> M N P Q. \\<Psi> \\<rhd> P \\<sim> Q}\"\n  from `\\<Psi> \\<rhd> P \\<sim> Q` have \"(\\<Psi>, M\\<langle>N\\<rangle>.P, M\\<langle>N\\<rangle>.Q) \\<in> ?X\" by auto\n  thus ?thesis\n    by(coinduct rule: bisimCoinduct, auto) (blast intro: outputPres dest: bisimE)+\nqed\n\nlemma bisimCasePres:\n  fixes \\<Psi>   :: 'b\n  and   CsP :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n  and   CsQ :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n\n  assumes \"\\<And>\\<phi> P. (\\<phi>, P) mem CsP \\<Longrightarrow> \\<exists>Q. (\\<phi>, Q) mem CsQ \\<and> guarded Q \\<and> \\<Psi> \\<rhd> P \\<sim> Q\"\n  and     \"\\<And>\\<phi> Q. (\\<phi>, Q) mem CsQ \\<Longrightarrow> \\<exists>P. (\\<phi>, P) mem CsP \\<and> guarded P \\<and> \\<Psi> \\<rhd> P \\<sim> Q\"\n\n  shows \"\\<Psi> \\<rhd> Cases CsP \\<sim> Cases CsQ\"\nproof -\n  let ?X = \"{(\\<Psi>, Cases CsP, Cases CsQ) | \\<Psi> CsP CsQ. (\\<forall>\\<phi> P. (\\<phi>, P) mem CsP \\<longrightarrow> (\\<exists>Q. (\\<phi>, Q) mem CsQ \\<and> guarded Q \\<and> \\<Psi> \\<rhd> P \\<sim> Q)) \\<and>\n                                                     (\\<forall>\\<phi> Q. (\\<phi>, Q) mem CsQ \\<longrightarrow> (\\<exists>P. (\\<phi>, P) mem CsP \\<and> guarded P \\<and> \\<Psi> \\<rhd> P \\<sim> Q))}\"\n  from assms have \"(\\<Psi>, Cases CsP, Cases CsQ) \\<in> ?X\" by auto\n  thus ?thesis\n  proof(coinduct rule: bisimCoinduct)\n    case(cStatEq \\<Psi> P Q)\n    thus ?case by auto\n  next\n    case(cSim \\<Psi> CasesP CasesQ)\n    then obtain CsP CsQ where C1: \"\\<And>\\<phi> Q. (\\<phi>, Q) mem CsQ \\<Longrightarrow> \\<exists>P. (\\<phi>, P) mem CsP \\<and> guarded P \\<and> \\<Psi> \\<rhd> P \\<sim> Q\"\n                          and A: \"CasesP = Cases CsP\" and B: \"CasesQ = Cases CsQ\"\n      by auto\n    note C1\n    moreover have \"\\<And>\\<Psi> P Q. \\<Psi> \\<rhd> P \\<sim> Q \\<Longrightarrow> \\<Psi> \\<rhd> P \\<leadsto>[bisim] Q\" by(rule bisimE)\n    moreover have \"bisim \\<subseteq> ?X \\<union> bisim\" by blast\n    ultimately have \"\\<Psi> \\<rhd> Cases CsP \\<leadsto>[(?X \\<union> bisim)] Cases CsQ\"\n      by(rule casePres)\n    thus ?case using A B by blast\n  next\n    case(cExt \\<Psi> P Q)\n    thus ?case by(blast dest: bisimE)\n  next\n    case(cSym \\<Psi> P Q)\n    thus ?case by(blast dest: bisimE)\n  qed\nqed\n\nlemma bisimResPres:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   x :: name\n  \n  assumes \"\\<Psi> \\<rhd> P \\<sim> Q\"\n  and     \"x \\<sharp> \\<Psi>\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<sim> \\<lparr>\\<nu>x\\<rparr>Q\"\nproof -\n  let ?X = \"{(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>P, \\<lparr>\\<nu>x\\<rparr>Q) | \\<Psi> x P Q. \\<Psi> \\<rhd> P \\<sim> Q \\<and> x \\<sharp> \\<Psi>}\"\n  \n  from assms have \"(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>P, \\<lparr>\\<nu>x\\<rparr>Q) \\<in> ?X\" by auto\n  thus ?thesis\n  proof(coinduct rule: bisimCoinduct)\n    case(cStatEq \\<Psi> xP xQ)\n    from `(\\<Psi>, xP, xQ) \\<in> ?X` obtain x P Q where \"\\<Psi> \\<rhd> P \\<sim> Q\" and \"x \\<sharp> \\<Psi>\" and \"xP = \\<lparr>\\<nu>x\\<rparr>P\" and \"xQ = \\<lparr>\\<nu>x\\<rparr>Q\"\n      by auto\n    moreover from `\\<Psi> \\<rhd> P \\<sim> Q` have PeqQ: \"insertAssertion(extractFrame P) \\<Psi> \\<simeq>\\<^sub>F insertAssertion(extractFrame Q) \\<Psi>\"\n      by(rule bisimE)\n    ultimately show ?case by(auto intro: frameResPres)\n  next\n    case(cSim \\<Psi> xP xQ)\n    from `(\\<Psi>, xP, xQ) \\<in> ?X` obtain x P Q where \"\\<Psi> \\<rhd> P \\<sim> Q\" and \"x \\<sharp> \\<Psi>\" and \"xP = \\<lparr>\\<nu>x\\<rparr>P\" and \"xQ = \\<lparr>\\<nu>x\\<rparr>Q\"\n      by auto\n    from `\\<Psi> \\<rhd> P \\<sim> Q` have \"\\<Psi> \\<rhd> P \\<leadsto>[bisim] Q\" by(rule bisimE)\n    moreover have \"eqvt ?X\"\n      by(force simp add: eqvt_def bisimClosed pt_fresh_bij[OF pt_name_inst, OF at_name_inst])\n    hence \"eqvt(?X \\<union> bisim)\" by auto\n    moreover note `x \\<sharp> \\<Psi>`\n    moreover have \"bisim \\<subseteq> ?X \\<union> bisim\" by auto\n    moreover have \"\\<And>\\<Psi> P Q x. \\<lbrakk>(\\<Psi>, P, Q) \\<in> bisim; x \\<sharp> \\<Psi>\\<rbrakk> \\<Longrightarrow> (\\<Psi>, \\<lparr>\\<nu>x\\<rparr>P, \\<lparr>\\<nu>x\\<rparr>Q) \\<in> ?X \\<union> bisim\"\n      by auto\n    ultimately have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<leadsto>[(?X \\<union> bisim)] \\<lparr>\\<nu>x\\<rparr>Q\"\n      by(rule resPres)\n    with `xP = \\<lparr>\\<nu>x\\<rparr>P` `xQ = \\<lparr>\\<nu>x\\<rparr>Q` show ?case\n      by simp\n  next\n    case(cExt \\<Psi> xP xQ \\<Psi>')\n    from `(\\<Psi>, xP, xQ) \\<in> ?X` obtain x P Q where \"\\<Psi> \\<rhd> P \\<sim> Q\" and \"x \\<sharp> \\<Psi>\" and \"xP = \\<lparr>\\<nu>x\\<rparr>P\" and \"xQ = \\<lparr>\\<nu>x\\<rparr>Q\"\n      by auto\n    obtain y::name where \"y \\<sharp> P\" and \"y \\<sharp> Q\" and \"y \\<sharp> \\<Psi>\" and \"y \\<sharp> \\<Psi>'\"\n     by(generate_fresh \"name\", auto simp add: fresh_prod)\n   from `\\<Psi> \\<rhd> P \\<sim> Q` have \"\\<Psi> \\<otimes> ([(x, y)] \\<bullet> \\<Psi>') \\<rhd> P \\<sim> Q\"\n     by(rule bisimE)\n   hence \"([(x, y)] \\<bullet> (\\<Psi> \\<otimes> ([(x, y)] \\<bullet> \\<Psi>'))) \\<rhd> ([(x, y)] \\<bullet> P) \\<sim> ([(x, y)] \\<bullet> Q)\"\n     by(rule bisimClosed)\n   with `x \\<sharp> \\<Psi>` `y \\<sharp> \\<Psi>` have \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> ([(x, y)] \\<bullet> P) \\<sim> ([(x, y)] \\<bullet> Q)\"\n     by(simp add: eqvts)\n   with `y \\<sharp> \\<Psi>` `y \\<sharp> \\<Psi>'` have \"(\\<Psi> \\<otimes> \\<Psi>', \\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> P), \\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> Q)) \\<in> ?X\"\n     by auto\n   moreover from `y \\<sharp> P` `y \\<sharp> Q` have \"\\<lparr>\\<nu>x\\<rparr>P = \\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> P)\" and \"\\<lparr>\\<nu>x\\<rparr>Q = \\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> Q)\"\n     by(simp add: alphaRes)+\n   ultimately show ?case using `xP = \\<lparr>\\<nu>x\\<rparr>P` `xQ = \\<lparr>\\<nu>x\\<rparr>Q` by simp\n next\n    case(cSym \\<Psi> P Q)\n    thus ?case\n      by(blast dest: bisimE)\n  qed\nqed\n\nlemma bisimResChainPres:\n  fixes \\<Psi>   :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   xvec :: \"name list\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<sim> Q\"\n  and     \"xvec \\<sharp>* \\<Psi>\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>P \\<sim> \\<lparr>\\<nu>*xvec\\<rparr>Q\"\nusing assms\nby(induct xvec) (auto intro: bisimResPres)\n\nlemma bisimParPresAux:\n  fixes \\<Psi>  :: 'b\n  and   \\<Psi>\\<^sub>R :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   Q  :: \"('a, 'b, 'c) psi\"\n  and   R  :: \"('a, 'b, 'c) psi\"\n  and   A\\<^sub>R :: \"name list\"\n  \n  assumes \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q\"\n  and     FrR: \"extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\"\n  and     \"A\\<^sub>R \\<sharp>* \\<Psi>\"\n  and     \"A\\<^sub>R \\<sharp>* P\"\n  and     \"A\\<^sub>R \\<sharp>* Q\"\n\n  shows \"\\<Psi> \\<rhd> P \\<parallel> R \\<sim> Q \\<parallel> R\"\nproof -\n  let ?X = \"{(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> R), \\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> R)) | xvec \\<Psi> P Q R. xvec \\<sharp>* \\<Psi> \\<and> (\\<forall>A\\<^sub>R \\<Psi>\\<^sub>R. (extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle> \\<and> A\\<^sub>R \\<sharp>* \\<Psi> \\<and> A\\<^sub>R \\<sharp>* P \\<and> A\\<^sub>R \\<sharp>* Q) \\<longrightarrow>\n                                                                                          \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q)}\"\n  {\n    fix xvec :: \"name list\"\n    and \\<Psi>    :: 'b \n    and P    :: \"('a, 'b, 'c) psi\"\n    and Q    :: \"('a, 'b, 'c) psi\"\n    and R    :: \"('a, 'b, 'c) psi\"\n\n    assume \"xvec \\<sharp>* \\<Psi>\"\n    and    \"\\<And>A\\<^sub>R \\<Psi>\\<^sub>R. \\<lbrakk>extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>; A\\<^sub>R \\<sharp>* \\<Psi>; A\\<^sub>R \\<sharp>* P; A\\<^sub>R \\<sharp>* Q\\<rbrakk> \\<Longrightarrow> \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q\"\n\n    hence \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> R), \\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> R)) \\<in> ?X\"\n      apply auto\n      by blast\n  }\n\n  note XI = this\n  {\n    fix xvec :: \"name list\"\n    and \\<Psi>    :: 'b \n    and P    :: \"('a, 'b, 'c) psi\"\n    and Q    :: \"('a, 'b, 'c) psi\"\n    and R    :: \"('a, 'b, 'c) psi\"\n    and C    :: \"'d::fs_name\"\n\n    assume \"xvec \\<sharp>* \\<Psi>\"\n    and    A: \"\\<And>A\\<^sub>R \\<Psi>\\<^sub>R. \\<lbrakk>extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>; A\\<^sub>R \\<sharp>* \\<Psi>; A\\<^sub>R \\<sharp>* P; A\\<^sub>R \\<sharp>* Q; A\\<^sub>R \\<sharp>* C\\<rbrakk> \\<Longrightarrow> \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q\"\n\n    from `xvec \\<sharp>* \\<Psi>` have \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> R), \\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> R)) \\<in> ?X\"\n    proof(rule XI)\n      fix A\\<^sub>R \\<Psi>\\<^sub>R\n      assume FrR: \"extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\"\n      obtain p::\"name prm\" where \"(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>\" and \"(p \\<bullet> A\\<^sub>R) \\<sharp>* P\" and \"(p \\<bullet> A\\<^sub>R) \\<sharp>* Q\" and \"(p \\<bullet> A\\<^sub>R) \\<sharp>* R\" and \"(p \\<bullet> A\\<^sub>R) \\<sharp>* C\"\n                             and \"(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>\\<^sub>R\" and S: \"(set p) \\<subseteq> (set A\\<^sub>R) \\<times> (set(p \\<bullet> A\\<^sub>R))\" and \"distinctPerm p\"\n        by(rule_tac c=\"(\\<Psi>, P, Q, R, \\<Psi>\\<^sub>R, C)\" in name_list_avoiding) auto\n      from FrR `(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>\\<^sub>R` S have \"extractFrame R = \\<langle>(p \\<bullet> A\\<^sub>R), p \\<bullet> \\<Psi>\\<^sub>R\\<rangle>\" by(simp add: frameChainAlpha')\n\n      moreover assume \"A\\<^sub>R \\<sharp>* \\<Psi>\"\n      hence \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> \\<Psi>)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n      with `A\\<^sub>R \\<sharp>* \\<Psi>` `(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>` S have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>\" by simp\n      moreover assume \"A\\<^sub>R \\<sharp>* P\"\n      hence \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> P)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n      with `A\\<^sub>R \\<sharp>* P` `(p \\<bullet> A\\<^sub>R) \\<sharp>* P` S have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* P\" by simp\n      moreover assume \"A\\<^sub>R \\<sharp>* Q\"\n      hence \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> Q)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n      with `A\\<^sub>R \\<sharp>* Q` `(p \\<bullet> A\\<^sub>R) \\<sharp>* Q` S have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* Q\" by simp\n      ultimately have \"\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R) \\<rhd> P \\<sim> Q\" using `(p \\<bullet> A\\<^sub>R) \\<sharp>* C` A by blast\n      hence \"(p \\<bullet> (\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R))) \\<rhd> (p \\<bullet> P) \\<sim> (p \\<bullet> Q)\" by(rule bisimClosed)\n      with `A\\<^sub>R \\<sharp>* \\<Psi>` `(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P` `(p \\<bullet> A\\<^sub>R) \\<sharp>* P` `A\\<^sub>R \\<sharp>* Q` `(p \\<bullet> A\\<^sub>R) \\<sharp>* Q` S `distinctPerm p`\n      show \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q\" by(simp add: eqvts)\n    qed\n  }\n  note XI' = this\n\n  have \"eqvt ?X\"\n    apply(auto simp add: eqvt_def)\n    apply(rule_tac x=\"p \\<bullet> xvec\" in exI)\n    apply(rule_tac x=\"p \\<bullet> P\" in exI)\n    apply(rule_tac x=\"p \\<bullet> Q\" in exI)\n    apply(rule_tac x=\"p \\<bullet> R\" in exI)\n    apply(simp add: eqvts)\n    apply(simp add: fresh_star_bij)\n    apply(clarify)\n    apply(erule_tac x=\"(rev p) \\<bullet> A\\<^sub>R\" in allE)\n    apply(erule_tac x=\"(rev p) \\<bullet> \\<Psi>\\<^sub>R\" in allE)\n    apply(drule mp)\n    apply(rule conjI)\n    apply(rule_tac pi=p in pt_bij4[OF pt_name_inst, OF at_name_inst])\n    apply(simp add: eqvts)\n    defer\n    apply(drule_tac p=p in bisimClosed)\n    apply(simp add: eqvts)\n    apply(subst pt_fresh_star_bij[OF pt_name_inst,OF at_name_inst, of p, THEN sym])\n    apply simp\n    apply(subst pt_fresh_star_bij[OF pt_name_inst,OF at_name_inst, of p, THEN sym])\n    apply simp\n    apply(subst pt_fresh_star_bij[OF pt_name_inst,OF at_name_inst, of p, THEN sym])\n    by simp\n\n  moreover have Res: \"\\<And>\\<Psi> P Q x. \\<lbrakk>(\\<Psi>, P, Q) \\<in> ?X \\<union> bisim; x \\<sharp> \\<Psi>\\<rbrakk> \\<Longrightarrow> (\\<Psi>, \\<lparr>\\<nu>x\\<rparr>P, \\<lparr>\\<nu>x\\<rparr>Q) \\<in> ?X \\<union> bisim\"\n  proof -\n    fix \\<Psi> P Q x\n    assume \"(\\<Psi>, P, Q) \\<in> ?X \\<union> bisim\" and \"(x::name) \\<sharp> \\<Psi>\"\n    show \"(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>P, \\<lparr>\\<nu>x\\<rparr>Q) \\<in> ?X \\<union> bisim\"\n    proof(case_tac \"(\\<Psi>, P, Q) \\<in> ?X\")\n      assume \"(\\<Psi>, P, Q) \\<in> ?X\"\n      with `x \\<sharp> \\<Psi>` have \"(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>P, \\<lparr>\\<nu>x\\<rparr>Q) \\<in> ?X\"\n        apply auto\n        by(rule_tac x=\"x#xvec\" in exI) auto\n      thus ?thesis by simp\n    next\n      assume \"\\<not>(\\<Psi>, P, Q) \\<in> ?X\"\n      with `(\\<Psi>, P, Q) \\<in> ?X \\<union> bisim` have \"\\<Psi> \\<rhd> P \\<sim> Q\"\n        by blast\n      hence \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<sim> \\<lparr>\\<nu>x\\<rparr>Q\" using `x \\<sharp> \\<Psi>`\n        by(rule bisimResPres)\n      thus ?thesis\n        by simp\n    qed\n  qed\n\n  have \"(\\<Psi>, P \\<parallel> R, Q \\<parallel> R) \\<in> ?X\" \n  proof -\n    {\n      fix A\\<^sub>R' :: \"name list\"\n      and \\<Psi>\\<^sub>R' :: 'b\n\n      assume FrR': \"extractFrame R = \\<langle>A\\<^sub>R', \\<Psi>\\<^sub>R'\\<rangle>\"\n      and    \"A\\<^sub>R' \\<sharp>* \\<Psi>\"\n      and    \"A\\<^sub>R' \\<sharp>* P\"\n      and    \"A\\<^sub>R' \\<sharp>* Q\"\n\n      obtain p where \"(p \\<bullet> A\\<^sub>R') \\<sharp>* A\\<^sub>R\" and \"(p \\<bullet> A\\<^sub>R') \\<sharp>* \\<Psi>\\<^sub>R'\" and \"(p \\<bullet> A\\<^sub>R') \\<sharp>* \\<Psi>\" and \"(p \\<bullet> A\\<^sub>R') \\<sharp>* P\" and \"(p \\<bullet> A\\<^sub>R') \\<sharp>* Q\"\n                 and Sp: \"(set p) \\<subseteq> (set A\\<^sub>R') \\<times> (set(p \\<bullet> A\\<^sub>R'))\" and \"distinctPerm p\"\n        by(rule_tac c=\"(A\\<^sub>R, \\<Psi>, \\<Psi>\\<^sub>R', P, Q)\" in name_list_avoiding) auto\n            \n      from FrR' `(p \\<bullet> A\\<^sub>R') \\<sharp>*  \\<Psi>\\<^sub>R'` Sp have \"extractFrame R = \\<langle>(p \\<bullet> A\\<^sub>R'), p \\<bullet> \\<Psi>\\<^sub>R'\\<rangle>\"\n        by(simp add: frameChainAlpha eqvts)\n      with FrR `(p \\<bullet> A\\<^sub>R') \\<sharp>* A\\<^sub>R` obtain q::\"name prm\" \n        where Sq: \"set q \\<subseteq> set(p \\<bullet> A\\<^sub>R') \\<times> set A\\<^sub>R\" and \"distinctPerm q\" and \"\\<Psi>\\<^sub>R = q \\<bullet> p \\<bullet> \\<Psi>\\<^sub>R'\"\n        by(force elim: frameChainEq)\n\n      from `\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q` `\\<Psi>\\<^sub>R = q \\<bullet> p \\<bullet> \\<Psi>\\<^sub>R'` have \"\\<Psi> \\<otimes> (q \\<bullet> p \\<bullet> \\<Psi>\\<^sub>R') \\<rhd> P \\<sim> Q\" by simp\n      hence \"(q \\<bullet> (\\<Psi> \\<otimes> (q \\<bullet> p \\<bullet> \\<Psi>\\<^sub>R'))) \\<rhd> (q \\<bullet> P) \\<sim> (q \\<bullet> Q)\" by(rule bisimClosed)\n      with Sq `A\\<^sub>R \\<sharp>* \\<Psi>` `(p \\<bullet> A\\<^sub>R') \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P` `(p \\<bullet> A\\<^sub>R') \\<sharp>* P` `A\\<^sub>R \\<sharp>* Q` `(p \\<bullet> A\\<^sub>R') \\<sharp>* Q` `distinctPerm q`\n      have \"\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R') \\<rhd> P \\<sim> Q\" by(simp add: eqvts)\n      hence \"(p \\<bullet> (\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R'))) \\<rhd> (p \\<bullet> P) \\<sim> (p \\<bullet> Q)\" by(rule bisimClosed)\n      with Sp `A\\<^sub>R' \\<sharp>* \\<Psi>` `(p \\<bullet> A\\<^sub>R') \\<sharp>* \\<Psi>` `A\\<^sub>R' \\<sharp>* P` `(p \\<bullet> A\\<^sub>R') \\<sharp>* P` `A\\<^sub>R' \\<sharp>* Q` `(p \\<bullet> A\\<^sub>R') \\<sharp>* Q` `distinctPerm p`\n      have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R' \\<rhd> P \\<sim> Q\" by(simp add: eqvts)\n    }\n    thus ?thesis\n      apply auto\n      apply(rule_tac x=\"[]\" in exI)\n      by auto blast\n  qed\n  thus ?thesis\n  proof(coinduct rule: bisimCoinduct)\n    case(cStatEq \\<Psi> PR QR)\n    from `(\\<Psi>, PR, QR) \\<in> ?X`\n    obtain xvec P Q R A\\<^sub>R \\<Psi>\\<^sub>R where PFrR: \"PR = \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> R)\" and QFrR: \"QR = \\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> R)\"\n                              and \"xvec \\<sharp>* \\<Psi>\" and FrR: \"extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" and PSimQ: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q\"\n                              and \"A\\<^sub>R \\<sharp>* xvec\" and \"A\\<^sub>R \\<sharp>* \\<Psi>\" and \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* Q\" and \"A\\<^sub>R \\<sharp>* R\"\n      apply auto\n      apply(subgoal_tac \"\\<exists>A\\<^sub>R \\<Psi>\\<^sub>R. extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle> \\<and> A\\<^sub>R \\<sharp>* (xvec, \\<Psi>, P, Q, R)\")\n      apply auto\n      apply(rule_tac F=\"extractFrame R\" and C=\"(xvec, \\<Psi>, P, Q, R)\" in freshFrame)\n      by auto\n\n    obtain A\\<^sub>P \\<Psi>\\<^sub>P where FrP: \"extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\" and \"A\\<^sub>P \\<sharp>* A\\<^sub>R\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R\"\n      by(rule_tac C=\"(\\<Psi>, A\\<^sub>R, \\<Psi>\\<^sub>R)\" in freshFrame) auto\n    obtain A\\<^sub>Q \\<Psi>\\<^sub>Q where FrQ: \"extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\" and \"A\\<^sub>Q \\<sharp>* A\\<^sub>R\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R\"\n      by(rule_tac C=\"(\\<Psi>, A\\<^sub>R, \\<Psi>\\<^sub>R)\" in freshFrame) auto\n    from `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* Q` `A\\<^sub>P \\<sharp>* A\\<^sub>R` `A\\<^sub>Q \\<sharp>* A\\<^sub>R` FrP FrQ have \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P\" and  \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q\"\n      by(force dest: extractFrameFreshChain)+\n    \n    have \"\\<langle>(A\\<^sub>P@A\\<^sub>R), \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<simeq>\\<^sub>F \\<langle>(A\\<^sub>Q@A\\<^sub>R), \\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n    proof -\n      have \"\\<langle>A\\<^sub>P, \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P\\<rangle>\"\n        by(metis frameResChainPres frameNilStatEq Associativity Commutativity AssertionStatEqTrans Composition)\n      moreover from PSimQ have \"insertAssertion(extractFrame P) (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<simeq>\\<^sub>F insertAssertion(extractFrame Q) (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R)\"\n        by(rule bisimE)\n      with FrP FrQ freshCompChain `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R` have \"\\<langle>A\\<^sub>P, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle>\"\n        by auto\n      moreover have \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>Q, \\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n        by(metis frameResChainPres frameNilStatEq Associativity Commutativity AssertionStatEqTrans Composition)\n      ultimately have \"\\<langle>A\\<^sub>P, \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>Q, \\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n        by(blast intro: FrameStatEqTrans)\n      hence \"\\<langle>(A\\<^sub>R@A\\<^sub>P), \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<simeq>\\<^sub>F \\<langle>(A\\<^sub>R@A\\<^sub>Q), \\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n        by(drule_tac frameResChainPres) (simp add: frameChainAppend)\n      thus ?thesis\n        apply(simp add: frameChainAppend)\n        by(metis frameResChainComm FrameStatEqTrans)\n    qed\n    moreover from `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* \\<Psi>` have \"(A\\<^sub>P@A\\<^sub>R) \\<sharp>* \\<Psi>\" by simp\n    moreover from `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* \\<Psi>` have \"(A\\<^sub>Q@A\\<^sub>R) \\<sharp>* \\<Psi>\" by simp\n    ultimately have PFrRQR: \"insertAssertion(extractFrame(P \\<parallel> R)) \\<Psi> \\<simeq>\\<^sub>F insertAssertion(extractFrame(Q \\<parallel> R)) \\<Psi>\"\n      using FrP FrQ FrR `A\\<^sub>P \\<sharp>* A\\<^sub>R` `A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>Q \\<sharp>* A\\<^sub>R` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q`\n      by simp\n      \n    from `xvec \\<sharp>* \\<Psi>` have \"insertAssertion (extractFrame(\\<lparr>\\<nu>*xvec\\<rparr>P \\<parallel> R)) \\<Psi> \\<simeq>\\<^sub>F \\<lparr>\\<nu>*xvec\\<rparr>(insertAssertion (extractFrame(P \\<parallel> R)) \\<Psi>)\"\n      by(rule insertAssertionExtractFrameFresh)\n    moreover from PFrRQR have \"\\<lparr>\\<nu>*xvec\\<rparr>(insertAssertion (extractFrame(P \\<parallel> R)) \\<Psi>) \\<simeq>\\<^sub>F \\<lparr>\\<nu>*xvec\\<rparr>(insertAssertion (extractFrame(Q \\<parallel> R)) \\<Psi>)\"\n      by(induct xvec) (auto intro: frameResPres)\n    moreover from `xvec \\<sharp>* \\<Psi>` have \"\\<lparr>\\<nu>*xvec\\<rparr>(insertAssertion (extractFrame(Q \\<parallel> R)) \\<Psi>) \\<simeq>\\<^sub>F insertAssertion (extractFrame(\\<lparr>\\<nu>*xvec\\<rparr>Q \\<parallel> R)) \\<Psi>\"\n      by(rule FrameStatEqSym[OF insertAssertionExtractFrameFresh])\n    ultimately show ?case using PFrR QFrR\n      by(blast intro: FrameStatEqTrans)\n  next\n    case(cSim \\<Psi> PR QR)\n    {\n      fix \\<Psi> P Q R xvec\n      assume \"\\<And>A\\<^sub>R \\<Psi>\\<^sub>R. \\<lbrakk>extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>; A\\<^sub>R \\<sharp>* \\<Psi>; A\\<^sub>R \\<sharp>* P; A\\<^sub>R \\<sharp>* Q\\<rbrakk> \\<Longrightarrow> \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q\"\n      moreover have \"eqvt bisim\" by simp\n      moreover from `eqvt ?X` have \"eqvt(?X \\<union> bisim)\" by auto\n      moreover from bisimE(1) have \"\\<And>\\<Psi> P Q. \\<Psi> \\<rhd> P \\<sim> Q \\<Longrightarrow> insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P) \\<Psi>\" by(simp add: FrameStatEq_def)\n      moreover note bisimE(2) bisimE(3)\n      moreover \n      {\n        fix \\<Psi> P Q A\\<^sub>R \\<Psi>\\<^sub>R R\n        assume PSimQ: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q\"\n           and FrR: \"extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\"\n           and \"A\\<^sub>R \\<sharp>* \\<Psi>\"\n           and \"A\\<^sub>R \\<sharp>* P\"\n           and \"A\\<^sub>R \\<sharp>* Q\"\n        hence \"(\\<Psi>, P \\<parallel> R, Q \\<parallel> R) \\<in> ?X\"\n        proof -\n          have \"P \\<parallel> R = \\<lparr>\\<nu>*[]\\<rparr>(P \\<parallel> R)\" by simp\n          moreover have \"Q \\<parallel> R = \\<lparr>\\<nu>*[]\\<rparr>(Q \\<parallel> R)\" by simp\n          moreover have \"([]::name list) \\<sharp>* \\<Psi>\" by simp\n          moreover \n          {\n            fix A\\<^sub>R' \\<Psi>\\<^sub>R'\n\n            assume FrR': \"extractFrame R = \\<langle>A\\<^sub>R', \\<Psi>\\<^sub>R'\\<rangle>\"\n               and \"A\\<^sub>R' \\<sharp>* \\<Psi>\"\n               and \"A\\<^sub>R' \\<sharp>* P\"\n               and \"A\\<^sub>R' \\<sharp>* Q\"\n            obtain p where \"(p \\<bullet> A\\<^sub>R') \\<sharp>* A\\<^sub>R\"\n                       and \"(p \\<bullet> A\\<^sub>R') \\<sharp>* \\<Psi>\\<^sub>R'\"\n                       and \"(p \\<bullet> A\\<^sub>R') \\<sharp>* \\<Psi>\"\n                       and \"(p \\<bullet> A\\<^sub>R') \\<sharp>* P\"\n                       and \"(p \\<bullet> A\\<^sub>R') \\<sharp>* Q\"\n                       and S: \"(set p) \\<subseteq> (set A\\<^sub>R') \\<times> (set(p \\<bullet> A\\<^sub>R'))\" and \"distinctPerm p\"\n              by(rule_tac c=\"(A\\<^sub>R, \\<Psi>, \\<Psi>\\<^sub>R', P, Q)\" in name_list_avoiding) auto\n\n\n            from `(p \\<bullet> A\\<^sub>R') \\<sharp>* \\<Psi>\\<^sub>R'` S have \"\\<langle>A\\<^sub>R', \\<Psi>\\<^sub>R'\\<rangle> = \\<langle>p \\<bullet> A\\<^sub>R', p \\<bullet> \\<Psi>\\<^sub>R'\\<rangle>\"\n              by(simp add: frameChainAlpha)\n\n            with FrR' have FrR'': \"extractFrame R = \\<langle>p \\<bullet> A\\<^sub>R', p \\<bullet> \\<Psi>\\<^sub>R'\\<rangle>\" by simp\n            with FrR `(p \\<bullet> A\\<^sub>R') \\<sharp>* A\\<^sub>R`\n            obtain q where \"p \\<bullet> \\<Psi>\\<^sub>R' = (q::name prm) \\<bullet> \\<Psi>\\<^sub>R\" and S': \"set q \\<subseteq> (set A\\<^sub>R) \\<times> set(p \\<bullet> A\\<^sub>R')\" and \"distinctPerm q\"\n              apply auto\n              apply(drule_tac sym) apply simp\n              by(drule_tac frameChainEq) auto\n            from PSimQ have \"(q \\<bullet> (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R)) \\<rhd> (q \\<bullet> P) \\<sim> (q \\<bullet> Q)\"\n              by(rule bisimClosed)\n            with `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* P` `A\\<^sub>R \\<sharp>* Q` `(p \\<bullet> A\\<^sub>R') \\<sharp>* \\<Psi>` `(p \\<bullet> A\\<^sub>R') \\<sharp>* P` `(p \\<bullet> A\\<^sub>R') \\<sharp>* Q` S'\n            have \"\\<Psi> \\<otimes> (q \\<bullet> \\<Psi>\\<^sub>R) \\<rhd> P \\<sim> Q\" by(simp add: eqvts)\n            hence \"(p \\<bullet> (\\<Psi> \\<otimes> (q \\<bullet> \\<Psi>\\<^sub>R))) \\<rhd> (p \\<bullet> P) \\<sim> (p \\<bullet> Q)\" by(rule bisimClosed)\n            with `A\\<^sub>R' \\<sharp>* \\<Psi>` `A\\<^sub>R' \\<sharp>* P` `A\\<^sub>R' \\<sharp>* Q` `(p \\<bullet> A\\<^sub>R') \\<sharp>* \\<Psi>` `(p \\<bullet> A\\<^sub>R') \\<sharp>* P` `(p \\<bullet> A\\<^sub>R') \\<sharp>* Q` S `distinctPerm p` `(p \\<bullet> \\<Psi>\\<^sub>R') = q \\<bullet> \\<Psi>\\<^sub>R` \n            have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R' \\<rhd> P \\<sim> Q\"\n              by(drule_tac sym) (simp add: eqvts)\n          }\n          ultimately show ?thesis\n            by blast\n        qed\n        hence \"(\\<Psi>, P \\<parallel> R, Q \\<parallel> R) \\<in> ?X \\<union> bisim\"\n          by simp\n      }\n      moreover have \"\\<And>\\<Psi> P Q xvec. \\<lbrakk>(\\<Psi>, P, Q) \\<in> ?X \\<union> bisim; (xvec::name list) \\<sharp>* \\<Psi>\\<rbrakk> \\<Longrightarrow> (\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>P, \\<lparr>\\<nu>*xvec\\<rparr>Q) \\<in> ?X \\<union> bisim\"\n      proof -\n        fix \\<Psi> P Q xvec\n        assume \"(\\<Psi>, P, Q) \\<in> ?X \\<union> bisim\"\n        assume \"(xvec::name list) \\<sharp>* \\<Psi>\"\n        thus \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>P, \\<lparr>\\<nu>*xvec\\<rparr>Q) \\<in> ?X \\<union> bisim\"\n        proof(induct xvec)\n          case Nil\n          thus ?case using `(\\<Psi>, P, Q) \\<in> ?X \\<union> bisim` by simp\n        next\n          case(Cons x xvec)\n          thus ?case by(simp only: resChain.simps) (rule_tac Res, auto)\n        qed\n      qed\n      ultimately have \"\\<Psi> \\<rhd> P \\<parallel> R \\<leadsto>[(?X \\<union> bisim)] Q \\<parallel> R\" using statEqBisim\n        by(rule parPres)\n      moreover assume \"(xvec::name list) \\<sharp>* \\<Psi>\"\n      moreover from `eqvt ?X` have \"eqvt(?X \\<union> bisim)\" by auto\n      ultimately have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> R) \\<leadsto>[(?X \\<union> bisim)] \\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> R)\" using Res\n        by(rule_tac resChainPres)\n    }\n    with `(\\<Psi>, PR, QR) \\<in> ?X` show ?case by blast\n  next\n    case(cExt \\<Psi> PR QR \\<Psi>')\n\n    from `(\\<Psi>, PR, QR) \\<in> ?X`\n    obtain xvec P Q R A\\<^sub>R \\<Psi>\\<^sub>R where PFrR: \"PR = \\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> R)\" and QFrR: \"QR = \\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> R)\"\n                               and \"xvec \\<sharp>* \\<Psi>\" and A: \"\\<forall>A\\<^sub>R \\<Psi>\\<^sub>R. (extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle> \\<and> A\\<^sub>R \\<sharp>* \\<Psi> \\<and> A\\<^sub>R \\<sharp>* P \\<and> A\\<^sub>R \\<sharp>* Q) \\<longrightarrow> \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q\"\n      by auto\n    \n    obtain p where \"(p \\<bullet> xvec) \\<sharp>* \\<Psi>\"\n               and \"(p \\<bullet> xvec) \\<sharp>* P\"\n               and \"(p \\<bullet> xvec) \\<sharp>* Q\"\n               and \"(p \\<bullet> xvec) \\<sharp>* R\"\n               and \"(p \\<bullet> xvec) \\<sharp>* \\<Psi>'\"\n               and S: \"(set p) \\<subseteq> (set xvec) \\<times> (set(p \\<bullet> xvec))\" and \"distinctPerm p\"\n      by(rule_tac c=\"(\\<Psi>, P, Q, R, \\<Psi>')\" in name_list_avoiding) auto\n\n    from `(p \\<bullet> xvec) \\<sharp>* P` `(p \\<bullet> xvec) \\<sharp>* R` S have \"\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> R) = \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>(p \\<bullet> (P \\<parallel> R))\"\n      by(subst resChainAlpha) auto\n    hence PRAlpha: \"\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> R) = \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> P) \\<parallel> (p \\<bullet> R))\"\n      by(simp add: eqvts)\n\n    from `(p \\<bullet> xvec) \\<sharp>* Q` `(p \\<bullet> xvec) \\<sharp>* R` S have \"\\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> R) = \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>(p \\<bullet> (Q \\<parallel> R))\"\n      by(subst resChainAlpha) auto\n    hence QRAlpha: \"\\<lparr>\\<nu>*xvec\\<rparr>(Q \\<parallel> R) = \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> Q) \\<parallel> (p \\<bullet> R))\"\n      by(simp add: eqvts)\n\n    from `(p \\<bullet> xvec) \\<sharp>* \\<Psi>` `(p \\<bullet> xvec) \\<sharp>* \\<Psi>'` have \"(\\<Psi> \\<otimes> \\<Psi>', \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> P) \\<parallel> (p \\<bullet> R)), \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> Q) \\<parallel> (p \\<bullet> R))) \\<in> ?X\"\n    proof(rule_tac C2=\"(\\<Psi>, (p \\<bullet> P), (p \\<bullet> Q), R, \\<Psi>', xvec, p \\<bullet> xvec)\" in XI', auto)\n      fix A\\<^sub>R \\<Psi>\\<^sub>R\n      assume FrR: \"extractFrame (p \\<bullet> R) = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" and \"A\\<^sub>R \\<sharp>* \\<Psi>\" and \"A\\<^sub>R \\<sharp>* \\<Psi>'\" and \"A\\<^sub>R \\<sharp>* (p \\<bullet> P)\" and \"A\\<^sub>R \\<sharp>* (p \\<bullet> Q)\"\n      from FrR have \"(p \\<bullet> (extractFrame (p \\<bullet> R))) = (p \\<bullet> \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>)\" by simp\n      with `distinctPerm p` have \"extractFrame R = \\<langle>p \\<bullet> A\\<^sub>R, p \\<bullet> \\<Psi>\\<^sub>R\\<rangle>\" by(simp add: eqvts)\n      moreover from `A\\<^sub>R \\<sharp>* \\<Psi>` have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> \\<Psi>)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n      with `xvec \\<sharp>* \\<Psi>` `(p \\<bullet> xvec) \\<sharp>* \\<Psi>` S have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>\" by simp\n      moreover from `A\\<^sub>R \\<sharp>* (p \\<bullet> P)` have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> p \\<bullet> P)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n      with `distinctPerm p` have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* P\" by simp\n      moreover from `A\\<^sub>R \\<sharp>* (p \\<bullet> Q)` have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> p \\<bullet> Q)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n      with `distinctPerm p` have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* Q\" by simp\n      ultimately have \"\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R) \\<rhd> P \\<sim> Q\" using A by blast\n      hence \"(\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> (p \\<bullet> \\<Psi>') \\<rhd> P \\<sim> Q\" by(rule bisimE)\n      moreover have \"(\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> (p \\<bullet> \\<Psi>') \\<simeq> (\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>')) \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)\"\n        by(metis Associativity Commutativity Composition AssertionStatEqTrans AssertionStatEqSym)\n      ultimately have \"(\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>')) \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R) \\<rhd> P \\<sim> Q\" \n        by(rule statEqBisim)\n      hence \"(p \\<bullet> ((\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>')) \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R))) \\<rhd> (p \\<bullet> P) \\<sim> (p \\<bullet> Q)\"\n        by(rule bisimClosed)\n      with `distinctPerm p` `xvec \\<sharp>* \\<Psi>` `(p \\<bullet> xvec) \\<sharp>* \\<Psi>` S show \"(\\<Psi> \\<otimes> \\<Psi>') \\<otimes> \\<Psi>\\<^sub>R \\<rhd> (p \\<bullet> P) \\<sim> (p \\<bullet> Q)\"\n        by(simp add: eqvts)\n    qed\n    with PFrR QFrR PRAlpha QRAlpha show ?case by simp\n  next\n    case(cSym \\<Psi> PR QR)\n    thus ?case by(blast dest: bisimE)\n  qed\nqed\n\nlemma bisimParPres:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   R :: \"('a, 'b, 'c) psi\"\n  \n  assumes \"\\<Psi> \\<rhd> P \\<sim> Q\"\n\n  shows \"\\<Psi> \\<rhd> P \\<parallel> R \\<sim> Q \\<parallel> R\"\nproof -\n  obtain A\\<^sub>R \\<Psi>\\<^sub>R where \"extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" and \"A\\<^sub>R \\<sharp>* \\<Psi>\" and \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* Q\"\n    by(rule_tac C=\"(\\<Psi>, P, Q)\" in freshFrame) auto\n  moreover from `\\<Psi> \\<rhd> P \\<sim> Q` have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<sim> Q\" by(rule bisimE)\n  ultimately show ?thesis by(rule_tac bisimParPresAux)\nqed\n\nend\n\nend\n\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Psi_Calculi/Bisim_Pres.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5078118642792044, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.25588953187816704}}
{"text": "(*<*) \n\n(* Author: Kyndylan Nienhuis *)\n\ntheory TraceProperties\n\nimports \n  \"CHERI-abstraction.CheriAbstraction\"\n  \"CompartmentAuthority\"\nbegin\n\n(*>*)\nsection \\<open>Trace based security properties\\<close>\n\nsubsection \\<open>Traces\\<close>\n\ntype_synonym Trace = \"AbstractStep list\"\n\nprimrec TracePreservesDomain :: \"Trace \\<Rightarrow> bool\" where\n  \"TracePreservesDomain [] = True\" |\n  \"TracePreservesDomain (h # t) = (PreservesDomain h \\<and> TracePreservesDomain t)\"\n\nlemma TracePreservesDomainE:\n  assumes \"TracePreservesDomain trace\"\n      and \"step \\<in> set trace\"\n  shows \"PreservesDomain step\"\nusing assms\nby (induct trace) auto\n\nprimrec IsTrace :: \"Semantics \\<Rightarrow> state \\<Rightarrow> Trace \\<Rightarrow> state \\<Rightarrow> bool\" where\n  \"IsTrace sem s [] s' = (s = s')\" \n| \"IsTrace sem s (h # t) s' = (\\<exists>x. IsTrace sem s t x \\<and> (h, s') \\<in> sem x)\"\n\ndefinition Traces :: \"Semantics \\<Rightarrow> state \\<Rightarrow> (Trace \\<times> state) set\" where\n  \"Traces sem s = {(trace, s')| trace s'. IsTrace sem s trace s'}\" \n\nlemma Traces_member_simp [simp]:\nshows \"(trace, s') \\<in> Traces sem s = IsTrace sem s trace s'\"\nunfolding Traces_def \nby simp\n\nsubsection \\<open>Transitively valid state\\<close>\n\nlemma TraceInvarianceStateIsValid:\n  assumes abstraction: \"CanBeSimulated sem\"\n      and valid: \"getStateIsValid s\"\n      and trace: \"(trace, s') \\<in> Traces sem s\"\n  shows \"getStateIsValid s'\"\nusing trace\nproof (induct trace arbitrary: s')\n  case Nil\n  thus ?case\n    using valid by simp\nnext\n  case (Cons step trace)\n  then obtain r where r\\<^sub>1: \"(trace, r) \\<in> Traces sem s\"\n                  and r\\<^sub>2: \"(step, s') \\<in> sem r\"\n    by auto\n  show ?case\n    using Cons(1)[OF r\\<^sub>1]\n    using CanBeSimulatedE_ValidState[OF abstraction r\\<^sub>2]\n    by auto\nqed\n\nsubsection \\<open>Transitively available capabilities\\<close>\n\ninductive_set\n  AvailableCaps :: \"state \\<Rightarrow> Capability set\" for s where\n\nReg:\n  \"\\<lbrakk>RegisterIsAlwaysAccessible r;\n    getTag (getCapReg r s)\\<rbrakk> \\<Longrightarrow> \n    getCapReg r s \\<in> AvailableCaps s\"\n\n| Memory:\n  \"\\<lbrakk>cap \\<in> AvailableCaps s;\n    \\<not> getSealed cap;\n    Permit_Load_Capability (getPerms cap);\n    addr \\<in> getTranslateCapAddresses (RegionOfCap cap) LOAD s;\n    getTag (getMemCap addr s)\\<rbrakk> \\<Longrightarrow> \n    getMemCap addr s \\<in> AvailableCaps s\"\n\n| Restrict:\n  \"\\<lbrakk>cap \\<in> AvailableCaps s;\n    cap' \\<le> cap;\n    getTag cap'\\<rbrakk> \\<Longrightarrow> \n    cap' \\<in> AvailableCaps s\"\n\n| Seal:\n  \"\\<lbrakk>cap \\<in> AvailableCaps s;\n    \\<not> getSealed cap;\n    sealer \\<in> AvailableCaps s;\n    \\<not> getSealed sealer;\n    Permit_Seal (getPerms sealer);\n    ucast t \\<in> RegionOfCap sealer\\<rbrakk> \\<Longrightarrow> \n    setType (setSealed (cap, True), t) \\<in> AvailableCaps s\"\n\n| Unseal:\n  \"\\<lbrakk>cap \\<in> AvailableCaps s; \n    getSealed cap;\n    unsealer \\<in> AvailableCaps s;\n    \\<not> getSealed unsealer;\n    Permit_Unseal (getPerms unsealer);\n    ucast (getType cap) \\<in> RegionOfCap unsealer\\<rbrakk> \\<Longrightarrow> \n    setType (setSealed (cap, False), 0) \\<in> AvailableCaps s\"\n\nlemma AvailableCaps_getTag [elim!]:\n  assumes \"cap \\<in> AvailableCaps s\"\n  shows \"getTag cap\"\nusing assms \nby (rule AvailableCaps.induct) auto\n\nlemma AvailableCaps_PCC [intro!]:\n  assumes \"getTag (getPCC s)\"\n  shows \"getPCC s \\<in> AvailableCaps s\"\nusing Reg[where r=RegPCC] assms\nby auto\n\nlemma AvailableCaps_BranchToPCC [intro!]:\n  assumes \"getTag (getBranchToPccCap s)\"\n  shows \"getBranchToPccCap s \\<in> AvailableCaps s\"\nusing Reg[where r=RegBranchToPCC] assms\nby auto\n\nlemma AvailableCaps_BranchDelayPCC [intro!]:\n  assumes tag: \"getTag (getBranchDelayPccCap s)\"\n  shows \"getBranchDelayPccCap s \\<in> AvailableCaps s\"\nusing Reg[where r=RegBranchDelayPCC]\nusing assms\nby auto\n\nlemma AvailableCaps_Capr [intro!]:\n  assumes \"getTag (getCAPR cd s)\"\n  shows \"getCAPR cd s \\<in> AvailableCaps s\"\nusing Reg[where r=\"RegGeneral cd\"]\nusing assms\nby auto\n\nlemma AvailableCaps_DDC [intro!]:\n  assumes \"getTag (getDDC s)\"\n  shows \"getDDC s \\<in> AvailableCaps s\"\nusing Reg[where r=\"RegSpecial 0\"]\nusing assms\nby auto\n\nlemma AvailableCaps_TLSC [intro!]:\n  assumes \"getTag (getTLSC s)\"\n  shows \"getTLSC s \\<in> AvailableCaps s\"\nusing Reg[where r=\"RegSpecial 1\"]\nusing assms\nby auto\n\nlemma AvailableCaps_SCapr [elim]:\n  assumes abstraction: \"CanBeSimulated sem\"\n      and suc: \"(PreserveDomain actions, s') \\<in> sem s\"\n      and action: \"action \\<in> actions\"\n      and reg: \"cd \\<in> SpecialRegisterParameters action\"\n      and no_sys: \"\\<not> Access_System_Registers (getPerms (getPCC s))\"\n      and valid: \"getStateIsValid s\"\n      and tag: \"getTag (getSCAPR cd s)\"\n  shows \"getSCAPR cd s \\<in> AvailableCaps s\"\nproof -\n  have \"RegisterIsAlwaysAccessible (RegSpecial cd)\"\n    unfolding RegisterIsAlwaysAccessible_def\n    using CanBeSimulatedE_SystemRegister[OF abstraction suc _ _ _ _ valid]\n    using reg action no_sys\n    by auto\n  from Reg[OF this]\n  show ?thesis\n    using tag by auto\nqed\n\nlemma AvailableCaps_CapReg [elim]:\n  assumes abstraction: \"CanBeSimulated sem\"\n      and suc: \"(PreserveDomain actions, s') \\<in> sem s\"\n      and action: \"action \\<in> actions\"\n      and reg: \"case r of RegSpecial cd \\<Rightarrow> cd \\<in> SpecialRegisterParameters action | _ \\<Rightarrow> True\"\n      and no_sys: \"\\<not> Access_System_Registers (getPerms (getPCC s))\"\n      and valid: \"getStateIsValid s\"\n      and tag: \"getTag (getCapReg r s)\"\n  shows \"getCapReg r s \\<in> AvailableCaps s\"\nusing assms AvailableCaps_SCapr\nby (cases r) auto\n\nsubsection \\<open>Transitively usable capabilities\\<close>\n\ndefinition TransUsableCaps where\n  \"TransUsableCaps s \\<equiv> {cap. cap \\<in> AvailableCaps s \\<and> \\<not> getSealed cap}\"\n\nlemma TransUsableCapsI [intro]:\n  assumes \"cap \\<in> AvailableCaps s\"\n      and \"\\<not> getSealed cap\"\n  shows \"cap \\<in> TransUsableCaps s\"\nusing assms\nunfolding TransUsableCaps_def\nby simp\n\nlemma TransUsableCapsE [elim!]:\n  assumes \"cap \\<in> TransUsableCaps s\"\n  shows \"getTag cap\"\n    and \"\\<not> getSealed cap\"\n    and \"cap \\<in> AvailableCaps s\"\nusing assms\nunfolding TransUsableCaps_def\nby auto\n\nlemma TransUsableCapsPcc [intro!]:\n  assumes \"getTag (getPCC s)\"\n      and \"\\<not> getSealed (getPCC s)\"\n  shows \"getPCC s \\<in> TransUsableCaps s\"\nusing assms\nby auto\n\nsubsection \\<open>Transitively available permissions\\<close>\n\ndefinition AvailableAuthority :: \"state \\<Rightarrow> CompartmentAuthority\" where\n  \"AvailableAuthority s \\<equiv> GetAuthorityOfCaps (TransUsableCaps s)\"\n\nlemma GetAuthority_AvailableAuthority_le [elim!]:\n  assumes \"cap \\<in> TransUsableCaps s\"\n  shows \"GetAuthority cap \\<le> AvailableAuthority s\"\nunfolding AvailableAuthority_def GetAuthorityOfCaps_def\nusing assms\nby (intro Sup_upper) auto\n\nlemma getPCC_AvailableAuthority_le [intro]:\n  assumes \"getTag (getPCC s)\"\n      and \"\\<not> getSealed (getPCC s)\"\n  shows \"GetAuthority (getPCC s) \\<le> AvailableAuthority s\"\nproof -\n  have \"getPCC s \\<in> TransUsableCaps s\"\n    using assms\n    by auto\n  thus ?thesis by auto\nqed\n\nlemma AvailableCaps_AvailableAuthority_le [elim!]:\n  assumes \"AvailableCaps s \\<subseteq> AvailableCaps s'\"\n  shows \"AvailableAuthority s \\<le> AvailableAuthority s'\"\nunfolding AvailableAuthority_def\nusing assms\nby (intro GetAuthorityOfCaps_subset) auto\n\nlemma SystemRegisterAccess_PCC:\n  assumes abstraction: \"CanBeSimulated sem\"\n      and suc: \"(label, s') \\<in> sem s\"\n      and no_ex: \"label \\<noteq> SwitchDomain RaiseException\" \n      and no_sys: \"\\<not> SystemRegisterAccess (AvailableAuthority s)\"\n      and valid: \"getStateIsValid s\"\n  shows \"\\<not> Access_System_Registers (getPerms (getPCC s))\"\nproof -\n  have valid_pcc: \"getTag (getPCC s)\"  \"\\<not> getSealed (getPCC s)\"\n    using CanBeSimulatedE_Execute[OF abstraction suc no_ex valid]\n    by auto\n  hence \"GetAuthority (getPCC s) \\<le> AvailableAuthority s\" \n    by auto\n  from SystemRegisterAccess_le[OF this]\n  show \"\\<not> Access_System_Registers (getPerms (getPCC s))\"\n    using no_sys valid_pcc\n    by (auto simp: GetAuthority_accessors)\nqed\n\nlemma AvailableAuthority_AddressTranslation:\n  assumes abstraction: \"CanBeSimulated sem\"\n      and no_sys: \"\\<not> SystemRegisterAccess (AvailableAuthority s)\"\n      and valid: \"getStateIsValid s\"\n      and suc: \"(step, s') \\<in> sem s\"\n      and no_ex: \"step \\<noteq> SwitchDomain RaiseException\"\n  shows \"getTranslateAddr a s' = getTranslateAddr a s\"\nproof -\n  have valid_pcc: \"getTag (getPCC s)\"  \"\\<not> getSealed (getPCC s)\"\n    using CanBeSimulatedE_Execute[OF abstraction suc no_ex valid]\n    by auto\n  hence \"GetAuthority (getPCC s) \\<le> AvailableAuthority s\" \n    by auto\n  from SystemRegisterAccess_le[OF this]\n  have \"\\<not> Access_System_Registers (getPerms (getPCC s))\"\n    using no_sys valid_pcc\n    by (auto simp: GetAuthority_accessors)\n  thus ?thesis\n    using CanBeSimulatedE_AddressTranslation[OF abstraction suc no_ex _ valid]\n    by auto\nqed\n\nsubsection \\<open>Readable capabilities\\<close>\n\nlemma ReadableCapsAreAvailable [elim!]:\n  assumes readable: \"cap \\<in> ReadableCaps (AvailableAuthority s) s\"\n  shows \"cap \\<in> AvailableCaps s\"\nproof -\n  obtain loc where [simp]: \"cap = getCap loc s\"\n               and loc: \"loc \\<in> ReadableLocations (AvailableAuthority s) s\"\n    using readable by auto\n  have tag: \"getTag cap\"\n    using readable by auto\n  show ?thesis\n    proof (cases loc)\n      case (LocReg r)\n      hence \"RegisterIsAlwaysAccessible r\"\n        using loc by auto\n      from Reg[OF this]\n      show ?thesis\n        using tag LocReg\n        by auto\n    next\n      case (LocMem a)\n      thus ?thesis\n        using Memory[where addr=a and s=s]\n        using LocMem tag loc\n        unfolding AvailableAuthority_def TransUsableCaps_def\n        by (auto simp: getTranslateCapAddresses_distrib_Union GetAuthority_accessors\n                 split: if_splits)\n    qed\nqed\n\ndefinition InvokableCapsNotUnsealable :: \"CompartmentAuthority \\<Rightarrow> state \\<Rightarrow> bool\" where\n  \"InvokableCapsNotUnsealable perm s \\<equiv>\n   \\<forall>cap\\<in>ReadableCaps perm s.\n   Permit_CCall (getPerms cap) \\<longrightarrow>\n   getSealed cap \\<and>\n   getType cap \\<notin> UnsealableTypes perm\"\n\nlemma InvokableCapsNotUnsealableE [elim]:\n  assumes \"InvokableCapsNotUnsealable perm s\"\n      and \"cap \\<in> ReadableCaps perm s\"\n      and \"Permit_CCall (getPerms cap)\"\n  shows \"getSealed cap\"\n    and \"getType cap \\<notin> UnsealableTypes perm\"\nusing assms\nunfolding InvokableCapsNotUnsealable_def\nby auto\n\nlemma InvokableCapsNotUnsealable_le:\n  assumes \"p \\<le> q\"\n      and \"InvokableCapsNotUnsealable q s\"\n  shows \"InvokableCapsNotUnsealable p s\"\nusing assms(2) \nusing ReadableCaps_le[OF assms(1)]\nusing UnsealableTypes_le[OF assms(1)]\nunfolding InvokableCapsNotUnsealable_def\nby auto\n\nlemma AvailableInvokableCapsAreReadable:\n  assumes available: \"cap \\<in> AvailableCaps s\"\n      and ccall: \"Permit_CCall (getPerms cap)\"\n      and base: \"InvokableCapsNotUnsealable (AvailableAuthority s) s\"\n  shows \"cap \\<in> ReadableCaps (AvailableAuthority s) s\"\nproof -\n  have \"cap \\<in> ReadableCaps (AvailableAuthority s) s \\<and>\n        getSealed cap \\<and> \n        getType cap \\<notin> UnsealableTypes (AvailableAuthority s)\"\n    using available ccall\n    proof induct\n      case (Reg r)\n      hence \"getCapReg r s \\<in> ReadableCaps (AvailableAuthority s) s\"\n        using Reg\n        by (auto intro: ReadableCapsI[where loc=\"LocReg r\"])\n      thus ?case\n        using Reg\n        using InvokableCapsNotUnsealableE[OF base, where cap=\"getCapReg r s\"]\n        by auto\n    next\n      case (Memory cap addr)\n      hence \"cap \\<in> TransUsableCaps s\"\n        by auto\n      note gperm = GetAuthority_AvailableAuthority_le[OF this]\n      have \"addr \\<in> getTranslateCapAddresses (CapLoadableAddresses (GetAuthority cap)) LOAD s\"\n        using Memory AvailableCaps_getTag\n        by (auto simp: GetAuthority_accessors)\n      hence \"addr \\<in> getTranslateCapAddresses (CapLoadableAddresses (AvailableAuthority s)) LOAD s\"\n        using getTranslateCapAddresses_le[OF CapLoadableAddresses_le[OF gperm]]\n        by auto\n      hence \"getMemCap addr s \\<in> ReadableCaps (AvailableAuthority s) s\"\n        using Memory\n        by (auto intro: ReadableCapsI[where loc=\"LocMem addr\"])\n      thus ?case\n        using Memory\n        using InvokableCapsNotUnsealableE[OF base, where cap=\"getMemCap addr s\"]\n        by auto\n    next\n      case (Restrict cap cap')\n      hence \"getPerms cap' \\<le> getPerms cap\"\n        using less_eq_CapabilityE_getPerms\n        by auto\n      hence \"Permit_CCall (getPerms cap)\"\n        unfolding less_eq_Perms_ext_alt\n        using Restrict\n        by auto\n      hence \"getSealed cap\"\n        using Restrict by auto\n      hence \"getSealed cap'\"\n        using less_eq_CapabilityE_getSealed\n        using Restrict by auto\n      hence \"cap' = cap\"\n        using less_eq_CapabilityE_IsSealed\n        using Restrict by auto\n      thus ?case \n        using Restrict\n        by auto\n    next\n      case (Seal cap sealer t)\n      thus ?case by auto\n    next\n      case (Unseal cap unsealer)\n      hence \"unsealer \\<in> TransUsableCaps s\"\n        by auto\n      note gperm = GetAuthority_AvailableAuthority_le[OF this]\n      have \"getType cap \\<in> UnsealableTypes (GetAuthority unsealer)\"\n        using Unseal\n        by (auto simp: GetAuthority_accessors)\n      hence False\n        using UnsealableTypes_le[OF gperm]\n        using Unseal\n        by auto\n      thus ?case by simp\n    qed\n  thus ?thesis\n    by auto\nqed\n\nsubsection \\<open>Closed permissions\\<close>\n\ndefinition PermIsClosed where\n  \"PermIsClosed perm s \\<equiv>\n   \\<forall>cap\\<in>ReadableCaps perm s.\n   (\\<not> getSealed cap \\<or> getType cap \\<in> UnsealableTypes perm) \\<longrightarrow>\n   GetAuthority cap \\<le> perm\"\n\nlemma PermIsClosedE [elim]:\n  assumes \"PermIsClosed perm s\"\n      and \"cap \\<in> ReadableCaps perm s\"\n      and \"getSealed cap \\<Longrightarrow> getType cap \\<in> UnsealableTypes perm\"\n  shows \"GetAuthority cap \\<le> perm\"\nusing assms\nunfolding PermIsClosed_def\nby auto\n\nlemma TransUsableCapsInClosedPerm:\n  assumes closed: \"PermIsClosed perm s\"\n      and usable: \"cap \\<in> TransUsableCaps s\"\n  shows \"GetAuthority cap \\<le> perm\"\nproof -\n  have available: \"cap \\<in> AvailableCaps s\" and\n       type: \"getSealed cap \\<longrightarrow> getType cap \\<in> UnsealableTypes perm\"\n    using usable\n    unfolding TransUsableCaps_def\n    by auto\n  thus ?thesis\n    proof induct\n      case (Reg r)\n      hence \"LocReg r \\<in> ReadableLocations perm s\" \n        by auto\n      thus ?case\n        using Reg \n        using PermIsClosedE[OF closed, OF ReadableCapsI[where loc=\"LocReg r\"]]\n        by auto\n    next\n      case (Memory cap addr)\n      hence \"GetAuthority cap \\<le> perm\"\n        by auto\n      from CapLoadableAddresses_le[OF this]\n      have \"CapLoadableAddresses (GetAuthority cap) \\<subseteq> CapLoadableAddresses perm\"\n        by auto\n      from getTranslateCapAddresses_le[OF this]\n      have \"addr \\<in> getTranslateCapAddresses (CapLoadableAddresses perm) LOAD s\"\n        using Memory AvailableCaps_getTag\n        by (auto simp: GetAuthority_accessors)\n      hence \"LocMem addr \\<in> ReadableLocations perm s\" \n        by auto\n      thus ?case\n        using Memory \n        using PermIsClosedE[OF closed, OF ReadableCapsI[where loc=\"LocMem addr\"]]\n        by auto\n    next\n      case (Restrict cap cap')\n      hence \"GetAuthority cap' \\<le> GetAuthority cap\"\n        by auto\n      thus ?case \n        using less_eq_CapabilityE_getSealed[OF `cap' \\<le> cap`]\n        using less_eq_CapabilityE_getType[OF `cap' \\<le> cap`]\n        using Restrict \n        by auto\n    next\n      case (Seal cap sealer t)\n      thus ?case by simp\n    next\n      case (Unseal cap unsealer)\n      hence \"GetAuthority unsealer \\<le> perm\" \n        by auto\n      from UnsealableTypes_le[OF this]\n      have \"getType cap \\<in> UnsealableTypes perm\"\n        using Unseal \n        by (auto simp: GetAuthority_accessors)\n      thus ?case \n        using Unseal by auto\n    qed\nqed\n\nlemma AvailableAuthorityInClosedPerm:\n  assumes \"PermIsClosed perm s\"\n  shows \"AvailableAuthority s \\<le> perm\"\nusing TransUsableCapsInClosedPerm[OF assms]\nunfolding AvailableAuthority_def GetAuthorityOfCaps_def TransUsableCaps_def\nunfolding Sup_le_iff\nby auto\n\nsubsection \\<open>Monotonicity of available capabilities\\<close>\n\nlemma NewCapsAreAvailable:\n  assumes abstraction: \"CanBeSimulated sem\"\n      and suc: \"(PreserveDomain actions, s') \\<in> sem s\"\n      and no_sys: \"\\<not> Access_System_Registers (getPerms (getPCC s))\"\n      and valid: \"getStateIsValid s\"\n      and tag: \"getTag (getCap loc s')\"\n  shows \"getCap loc s' \\<in> AvailableCaps s \\<or>\n         getCap loc s' = getCap loc s\"\nproof -\n  obtain parentLoc where \"parentLoc \\<in> ProvenanceParents actions loc\"\n    using ProvenanceParentExists by auto\n  thus ?thesis\n    proof (cases rule: ProvenanceCases)\n      case Unchanged\n      hence \"getCap loc s' = getCap loc s\"\n        using CanBeSimulatedE_CapabilityInvariant[OF abstraction suc _ _ valid]\n        by simp\n      thus ?thesis by auto\n    next\n      case (StoreData auth a l)\n      hence \"getMemCap (GetCapAddress a) s' = getMemCap (GetCapAddress a) s\"\n        using CanBeSimulatedE_StoreData[OF abstraction suc _ StoreData(1) valid]\n        using tag\n        by auto\n      thus ?thesis\n        using StoreData\n        by auto\n    next\n      case (RestrictedReg r r')\n      have le: \"getCapReg r' s' \\<le> getCapReg r s\"\n        using RestrictedReg\n        using CanBeSimulatedE_RestrictRegCap[OF abstraction suc _ RestrictedReg(1) valid]\n        by auto\n      have tag_original: \"getTag (getCapReg r s)\"\n        using le tag RestrictedReg by auto\n      have \"getCapReg r s \\<in> AvailableCaps s\"\n        using AvailableCaps_CapReg[OF abstraction suc RestrictedReg(1) _ no_sys valid tag_original]\n        by (cases r) auto\n      from AvailableCaps.Restrict[OF this le]\n      show ?thesis\n        using RestrictedReg tag\n        by auto\n    next\n      case (Loaded auth a cd)\n      have \"LoadCapProp s (PreserveDomain actions) s'\"\n        using CanBeSimulatedE[OF abstraction suc]\n        by auto\n      from LoadCapPropE_mem[OF this _ Loaded(1) valid, where a'=\"ExtendCapAddress a\"]\n      obtain vAddr where \"vAddr \\<in> RegionOfCap (getCapReg auth s)\" \n                         \"getTranslateAddr (vAddr, LOAD) s = Some (ExtendCapAddress a)\"\n        by auto\n      hence le: \"getCAPR cd s' \\<le> getMemCap a s\"\n      and tag_auth: \"getTag (getCapReg auth s)\"\n      and segment: \"a \\<in> getTranslateCapAddresses (RegionOfCap (getCapReg auth s)) LOAD s\"\n      and unsealed: \"\\<not> getSealed (getCapReg auth s)\"\n      and perm: \"Permit_Load_Capability (getPerms (getCapReg auth s))\"\n        using CanBeSimulatedE_LoadCap[OF abstraction suc _ Loaded(1) valid]\n        by auto\n      have auth: \"getCapReg auth s \\<in> AvailableCaps s\"\n        using AvailableCaps_CapReg[OF abstraction suc Loaded(1) _ no_sys valid tag_auth]\n        by (cases auth) auto\n      hence \"getTag (getMemCap a s)\"\n        using le tag Loaded by auto\n      hence \"getMemCap a s \\<in> AvailableCaps s\"\n        using Memory[OF auth unsealed perm segment]\n        by auto\n      from AvailableCaps.Restrict[OF this le]\n      show ?thesis \n        using Loaded tag\n        by auto\n    next\n      case (Stored auth cd a)\n      have le: \"getMemCap a s' \\<le> getCAPR cd s\"\n        using CanBeSimulatedE_StoreCap[OF abstraction suc _ Stored(1) valid]\n        by auto\n      hence \"getTag (getCAPR cd s)\"\n        using tag Stored by auto\n      note AvailableCaps_Capr[OF this]\n      from AvailableCaps.Restrict[OF this le]\n      show ?thesis \n        using Stored tag\n        by auto\n    next\n      case (Sealed auth cd cd')\n      define t :: ObjectType where \n        \"t \\<equiv> ucast (getBase (getCapReg auth s)) + ucast (getOffset (getCapReg auth s))\"\n      have tag_cd: \"getTag (getCAPR cd s)\" \n      and tag_auth: \"getTag (getCapReg auth s)\"\n        using CanBeSimulatedE_SealCap[OF abstraction suc _ Sealed(1) valid]\n        using tag Sealed\n        by auto\n      have \"getCapReg auth s \\<in> AvailableCaps s\"\n        using AvailableCaps_CapReg[OF abstraction suc Sealed(1) _ no_sys valid tag_auth]\n        by (cases auth) auto\n      hence \"setType (setSealed (getCAPR cd s, True), t) \\<in> AvailableCaps s\"\n        using CanBeSimulatedE_SealCap[OF abstraction suc _ Sealed(1) valid]\n        using tag_cd\n        unfolding t_def\n        by (intro AvailableCaps.Seal[where sealer=\"getCapReg auth s\"]) auto\n      thus ?thesis\n        using CanBeSimulatedE_SealCap[OF abstraction suc _ Sealed(1) valid]\n        using Sealed \n        unfolding t_def\n        by auto\n    next\n      case (Unsealed auth cd cd')\n      have tag_cd: \"getTag (getCAPR cd s)\"\n      and tag_auth: \"getTag (getCapReg auth s)\"\n        using TagOfGreaterCap[OF _ tag, where cap'=\"setType (setSealed (getCAPR cd s, False), 0)\"]\n        using CanBeSimulatedE_UnsealCap[OF abstraction suc _ Unsealed(1) valid]\n        using Unsealed\n        by auto\n      have \"getCapReg auth s \\<in> AvailableCaps s\"\n        using AvailableCaps_CapReg[OF abstraction suc Unsealed(1) _ no_sys valid tag_auth]\n        by (cases auth) auto\n      hence \"setType (setSealed (getCAPR cd s, False), 0) \\<in> AvailableCaps s\"\n        using CanBeSimulatedE_UnsealCap[OF abstraction suc _ Unsealed(1) valid]\n        using tag_cd\n        by (intro AvailableCaps.Unseal[where unsealer=\"getCapReg auth s\"]) auto\n      from AvailableCaps.Restrict[OF this _ tag]\n      show ?thesis\n        using CanBeSimulatedE_UnsealCap[OF abstraction suc _ Unsealed(1) valid]\n        using Unsealed\n        by auto\n    qed\nqed\n\nlemma MonotonicityAvailableCaps_Step:\n  assumes abstraction: \"CanBeSimulated sem\"\n      and suc: \"(PreserveDomain actions, s') \\<in> sem s\"\n      and no_sys: \"\\<not> Access_System_Registers (getPerms (getPCC s))\"\n      and valid: \"getStateIsValid s\"\n  shows \"AvailableCaps s' \\<subseteq> AvailableCaps s\"\nproof \n  fix cap\n  assume \"cap \\<in> AvailableCaps s'\"\n  thus \"cap \\<in> AvailableCaps s\"\n    proof (induct rule: AvailableCaps.inducts)\n      case (Reg r)\n      thus ?case\n        using NewCapsAreAvailable[OF abstraction suc no_sys valid, where loc=\"LocReg r\"]\n        using Reg AvailableCaps.Reg\n        by auto\n    next\n      case (Memory cap' a)\n      have \"getTranslateAddr (v, LOAD) s' = getTranslateAddr (v, LOAD) s\" for v\n        using CanBeSimulatedE_AddressTranslation[OF abstraction suc _ no_sys valid]\n        by auto\n      hence \"getTranslateCapAddresses addrs LOAD s' = getTranslateCapAddresses addrs LOAD s\" for addrs\n        unfolding getTranslateCapAddresses_def\n        unfolding getTranslateAddresses_def\n        by simp\n      thus ?case \n        using NewCapsAreAvailable[OF abstraction suc no_sys valid, where loc=\"LocMem a\"]\n        using Memory AvailableCaps.Memory\n        by auto\n    next\n      case Restrict\n      thus ?case\n        using AvailableCaps.Restrict\n        by auto\n    next\n      case Seal\n      thus ?case\n        using AvailableCaps.Seal\n        by auto\n    next\n      case Unseal\n      thus ?case \n        using AvailableCaps.Unseal\n        by auto\n    qed\nqed\n\ntheorem MonotonicityAvailableCaps:\n  assumes abstraction: \"CanBeSimulated sem\"\n      and trace: \"(trace, s') \\<in> Traces sem s\"\n      and intra: \"TracePreservesDomain trace\"\n      and no_sys: \"\\<not> SystemRegisterAccess (AvailableAuthority s)\"\n      and valid: \"getStateIsValid s\"\n  shows \"AvailableCaps s' \\<subseteq> AvailableCaps s\"\nusing trace intra\nproof (induct trace arbitrary: s')\n  case (Cons step trace)\n  then obtain r where r\\<^sub>1: \"(trace, r) \\<in> Traces sem s\"\n                  and r\\<^sub>2: \"(step, s') \\<in> sem r\"\n    by auto\n  have ih: \"AvailableCaps r \\<subseteq> AvailableCaps s\" \n    using Cons(1)[OF r\\<^sub>1]\n    using Cons(3)\n    by simp\n  have intra: \"PreservesDomain step\"\n    using Cons(3) by auto\n  hence no_ex: \"step \\<noteq> SwitchDomain RaiseException\" \n    by auto\n  have valid2: \"getStateIsValid r\"\n    using TraceInvarianceStateIsValid[OF abstraction valid r\\<^sub>1]\n    by auto\n  have no_sys2: \"\\<not> SystemRegisterAccess (AvailableAuthority r)\"\n    using AvailableCaps_AvailableAuthority_le[OF ih]\n    using SystemRegisterAccess_le no_sys \n    by auto\n  have \"\\<not> Access_System_Registers (getPerms (getPCC r))\"\n    using SystemRegisterAccess_PCC[OF abstraction r\\<^sub>2 no_ex no_sys2 valid2]\n    by auto\n  hence \"AvailableCaps s' \\<subseteq> AvailableCaps r\"\n    using MonotonicityAvailableCaps_Step[OF abstraction _ _ valid2, where s'=s']\n    using r\\<^sub>2 intra\n    by (cases step) auto\n  thus ?case\n    using ih by simp\nqed simp\n\ncorollary MonotonicityTransUsableCaps:\n  assumes abstraction: \"CanBeSimulated sem\"\n      and trace: \"(trace, s') \\<in> Traces sem s\"\n      and intra: \"TracePreservesDomain trace\"\n      and no_sys: \"\\<not> SystemRegisterAccess (AvailableAuthority s)\"\n      and valid: \"getStateIsValid s\"\n  shows \"TransUsableCaps s' \\<subseteq> TransUsableCaps s\"\nusing MonotonicityAvailableCaps[OF abstraction trace intra no_sys valid]\nby auto\n\ncorollary MonotonicityAvailableAuthority:\n  assumes abstraction: \"CanBeSimulated sem\"\n      and trace: \"(trace, s') \\<in> Traces sem s\"\n      and intra: \"TracePreservesDomain trace\"\n      and no_sys: \"\\<not> SystemRegisterAccess (AvailableAuthority s)\"\n      and valid: \"getStateIsValid s\"\n  shows \"AvailableAuthority s' \\<le> AvailableAuthority s\"\nusing MonotonicityTransUsableCaps[OF abstraction trace intra no_sys valid]\nunfolding AvailableAuthority_def\nby auto\n\nsubsection \\<open>Invariance of address translation\\<close>\n\nlemma TraceInvarianceAddressTranslation:\n  assumes abstraction: \"CanBeSimulated sem\"\n      and trace: \"(trace, s') \\<in> Traces sem s\"\n      and intra: \"TracePreservesDomain trace\"\n      and no_sys: \"\\<not> SystemRegisterAccess (AvailableAuthority s)\"\n      and valid: \"getStateIsValid s\"\n  shows \"getTranslateAddr addr s' = getTranslateAddr addr s\"\nusing trace intra\nproof (induct trace arbitrary: s')\n  case Nil\n  thus ?case by simp\nnext\n  case (Cons step trace)\n  then obtain r where r\\<^sub>1: \"(trace, r) \\<in> Traces sem s\"\n                  and r\\<^sub>2: \"(step, s') \\<in> sem r\"\n    by auto\n  have intra2: \"TracePreservesDomain trace\"\n    using Cons by auto\n  hence ih: \"getTranslateAddr addr r = getTranslateAddr addr s\"\n    using Cons(1)[OF r\\<^sub>1] \n    by auto\n  have no_ex: \"step \\<noteq> SwitchDomain RaiseException\"\n    using Cons by auto\n  note MonotonicityAvailableAuthority[OF abstraction r\\<^sub>1 intra2 no_sys valid]\n  from SystemRegisterAccess_le[OF this]\n  have no_sys2: \"\\<not> SystemRegisterAccess (AvailableAuthority r)\"\n    using no_sys\n    by auto\n  thus ?case\n    using TraceInvarianceStateIsValid[OF abstraction valid r\\<^sub>1]\n    using AvailableAuthority_AddressTranslation[OF abstraction _ _ r\\<^sub>2 no_ex]\n    using ih\n    by auto\nqed\n\nsubsection \\<open>Invariance of system registers\\<close>\n\nlemma SpecialCapRegisterInvariant_aux:\n  assumes abstraction: \"CanBeSimulated sem\"\n      and no_access: \"\\<not> Access_System_Registers (getPerms (getPCC s))\"\n      and system: \"cd \\<noteq> 0\" \"cd \\<noteq> 1\"\n      and valid: \"getStateIsValid s\"\n      and suc: \"(step, s') \\<in> sem s\"\n      and no_ex: \"step \\<noteq> SwitchDomain RaiseException\"\n  shows \"getSCAPR cd s' = getSCAPR cd s\"\nproof (cases \"PreservesDomain step\")\n  case False\n  then obtain crossing where \"step = SwitchDomain crossing\"\n    by (cases step) auto\n  then obtain cd cd' where \"step = SwitchDomain (InvokeCapability cd cd')\"\n    using no_ex\n    by (cases crossing) auto\n  hence \"(SwitchDomain (InvokeCapability cd cd'), s') \\<in> sem s\"\n    using suc by auto\n  from CanBeSimulatedE_InvokeCap[OF abstraction this _ valid]\n  show ?thesis\n    by auto\nnext\n  case True\n  then obtain actions where \"step = PreserveDomain actions\"\n    by (cases step) auto\n  hence intra_suc: \"(PreserveDomain actions, s') \\<in> sem s\"\n    using suc\n    by auto\n  have \"cd \\<notin> \\<Union> (SpecialRegisterParameters ` actions)\"\n    using CanBeSimulatedE_SystemRegister[OF abstraction intra_suc _ _ system  valid]\n    using no_access\n    by auto\n  hence \"\\<And>prov. prov \\<in> actions \\<Longrightarrow> LocReg (RegSpecial cd) \\<notin> ActionTargets prov\"\n    unfolding SpecialRegisterParameters_def\n    by auto\n  from CanBeSimulatedE_CapabilityInvariant\n       [OF abstraction intra_suc _ this valid]\n  show ?thesis by auto\nqed\n\nlemma SpecialCapRegisterInvariant_intra:\n  assumes abstraction: \"CanBeSimulated sem\"\n      and trace: \"(trace, s') \\<in> Traces sem s\"\n      and intra: \"TracePreservesDomain trace\"\n      and no_access: \"\\<not> SystemRegisterAccess (AvailableAuthority s)\"\n      and system: \"cd \\<noteq> 0\" \"cd \\<noteq> 1\"\n      and valid: \"getStateIsValid s\"\n  shows \"getSCAPR cd s' = getSCAPR cd s\"\nusing trace intra\nproof (induct trace arbitrary: s')\n  case (Cons step trace)\n  then obtain r where r\\<^sub>1: \"(trace, r) \\<in> Traces sem s\"\n                  and r\\<^sub>2: \"(step, s') \\<in> sem r\"\n    by auto\n  have ih: \"getSCAPR cd r = getSCAPR cd s\"\n    using Cons(1)[OF r\\<^sub>1] Cons(3)\n    by auto\n  have valid2: \"getStateIsValid r\"\n    using TraceInvarianceStateIsValid[OF abstraction valid r\\<^sub>1]\n    by auto\n  have no_ex2: \"step \\<noteq> SwitchDomain RaiseException\"\n    using Cons(3)\n    by auto\n  have \"AvailableAuthority r \\<le> AvailableAuthority s\"\n    using MonotonicityAvailableAuthority[OF abstraction r\\<^sub>1 _ no_access valid]\n    using Cons(3)\n    by auto\n  from SystemRegisterAccess_le[OF this]\n  have no_access2: \"\\<not> SystemRegisterAccess (AvailableAuthority r)\"\n    using no_access by auto\n  note pcc = CanBeSimulatedE_Execute[OF abstraction r\\<^sub>2 no_ex2 valid2]\n  hence \"getPCC r \\<in> TransUsableCaps r\"\n    by auto\n  hence \"GetAuthority (getPCC r) \\<le> AvailableAuthority r\"\n    by auto\n  from SystemRegisterAccess_le[OF this]\n  have \"\\<not> SystemRegisterAccess (GetAuthority (getPCC r))\"\n    using no_access2 by auto\n  hence \"\\<not> Access_System_Registers (getPerms (getPCC r))\"\n    using pcc\n    by (auto simp: GetAuthority_accessors)\n  hence \"getSCAPR cd s' = getSCAPR cd r\" \n    using SpecialCapRegisterInvariant_aux[OF abstraction _ system valid2 r\\<^sub>2 no_ex2]\n    by auto\n  thus ?case\n    using ih by auto\nqed simp\n\ntheorem SpecialCapRegisterInvariant:\n  assumes abstraction: \"CanBeSimulated sem\"\n      and trace: \"(step # trace, s') \\<in> Traces sem s\"\n      and intra: \"TracePreservesDomain trace\"\n      and inter: \"\\<not> PreservesDomain step\"\n      and no_access: \"\\<not> SystemRegisterAccess (AvailableAuthority s)\"\n      and system: \"cd \\<noteq> 0\" \"cd \\<noteq> 1\" \n      and non_eppc: \"cd \\<noteq> 31\"\n      and valid: \"getStateIsValid s\"\n  shows \"getSCAPR cd s' = getSCAPR cd s\"\nproof -\n  obtain r where r\\<^sub>1: \"(trace, r) \\<in> Traces sem s\"\n             and r\\<^sub>2: \"(step, s') \\<in> sem r\"\n    using trace by auto\n  obtain crossing where step: \"step = SwitchDomain crossing\"\n    using inter by (cases step) auto\n  have valid2: \"getStateIsValid r\"\n    using TraceInvarianceStateIsValid[OF abstraction valid r\\<^sub>1]\n    by auto\n  have \"getSCAPR cd s' = getSCAPR cd r\"\n    proof (cases crossing)\n      case RaiseException\n      hence \"(SwitchDomain RaiseException, s') \\<in> sem r\"\n        using r\\<^sub>2 step by auto\n      from CanBeSimulatedE_Exception[OF abstraction this _ valid2]\n      have \"getSCAPR cd s' = SignalExceptionSCAPR cd r\"\n        by auto\n      thus ?thesis\n        unfolding SignalExceptionSCAPR_def\n        using non_eppc\n        by auto\n    next\n      case (InvokeCapability cd cd')\n      hence \"(SwitchDomain (InvokeCapability cd cd'), s') \\<in> sem r\"\n        using r\\<^sub>2 step by auto\n      from CanBeSimulatedE_InvokeCap[OF abstraction this _ valid2]\n      show ?thesis by auto\n    qed\n  have \"getSCAPR cd r = getSCAPR cd s\"\n    using SpecialCapRegisterInvariant_intra[OF abstraction r\\<^sub>1 intra no_access system valid]\n    by simp\n  thus ?thesis\n    using `getSCAPR cd s' = getSCAPR cd r`\n    by auto\nqed\n\nsubsection \\<open>Invariance of capabilities in memory\\<close>\n\nlemma MemCapInvariant_intra:\n  assumes abstraction: \"CanBeSimulated sem\"\n      and trace: \"(trace, s') \\<in> Traces sem s\"\n      and intra: \"TracePreservesDomain trace\"\n      and no_access: \"a \\<notin> StorablePhysCapAddresses (AvailableAuthority s) s\"\n      and no_sys: \"\\<not> SystemRegisterAccess (AvailableAuthority s)\"\n      and valid: \"getStateIsValid s\"\n  shows \"getMemCap a s' = getMemCap a s\"\nusing trace intra\nproof (induct trace arbitrary: s')\n  case (Cons step trace)\n  then obtain r where r\\<^sub>1: \"(trace, r) \\<in> Traces sem s\"\n                  and r\\<^sub>2: \"(step, s') \\<in> sem r\"\n    by auto\n  have intra2: \"TracePreservesDomain trace\"\n    using Cons by auto\n  have ih: \"getMemCap a r = getMemCap a s\"\n    using Cons(1)[OF r\\<^sub>1] intra2\n    by auto\n  have valid2: \"getStateIsValid r\"\n    using TraceInvarianceStateIsValid[OF abstraction valid r\\<^sub>1]\n    by auto\n  have no_ex2: \"step \\<noteq> SwitchDomain RaiseException\"\n    using Cons(3)\n    by auto\n  have perms: \"AvailableAuthority r \\<le> AvailableAuthority s\"\n    using MonotonicityAvailableAuthority[OF abstraction r\\<^sub>1 intra2 no_sys valid]\n    by auto\n  from SystemRegisterAccess_le[OF this]\n  have no_sys2: \"\\<not> SystemRegisterAccess (AvailableAuthority r)\"\n    using no_sys by auto\n  have no_sys_pcc: \"\\<not> Access_System_Registers (getPerms (getPCC r))\"\n    using SystemRegisterAccess_PCC[OF abstraction r\\<^sub>2 no_ex2 no_sys2 valid2]\n    by auto\n  have addrTrans: \"getTranslateAddr a r = getTranslateAddr a s\" for a\n    using TraceInvarianceAddressTranslation[OF abstraction r\\<^sub>1 intra2 no_sys valid]\n    by auto\n  from StorablePhysCapAddresses_le[OF perms]\n  have no_access2: \"a \\<notin> StorablePhysCapAddresses (AvailableAuthority r) r\"\n    using getTranslateCapAddresses_eqI_getTranslateAddr[OF addrTrans]\n    using no_access\n    unfolding StorablePhysCapAddresses_def\n    by auto\n  hence \"getMemCap a s' = getMemCap a r\"\n    proof -\n      obtain actions where \"step = PreserveDomain actions\"\n        using Cons(3)\n        by (cases step) auto\n      hence intra_suc: \"(PreserveDomain actions, s') \\<in> sem r\"\n        using r\\<^sub>2\n        by auto\n      have \"\\<not> (\\<exists>action. action \\<in> actions \\<and>\n                        LocMem a \\<in> ActionTargets action)\" \n        proof (clarify)\n          fix action\n          assume action: \"action \\<in> actions\" \n             and target: \"LocMem a \\<in> ActionTargets action\"\n          thus False\n            proof (cases action)\n              case (StoreDataAction auth a' l)\n              hence \"StoreDataAction auth a' l \\<in> actions\"\n                using action \n                by auto\n              note restrict = \n                   CanBeSimulatedE_StoreData[OF abstraction intra_suc _ this valid2]\n              have a: \"a = GetCapAddress a'\"\n                using target StoreDataAction\n                by auto\n              have \"getCapReg auth r \\<in> AvailableCaps r\"\n                using AvailableCaps_CapReg\n                      [OF abstraction intra_suc action _ no_sys_pcc valid2, where r=auth]\n                using restrict StoreDataAction\n                by (cases auth) auto\n              hence \"getCapReg auth r \\<in> TransUsableCaps r\"\n                using restrict \n                by auto\n              hence gperm: \"GetAuthority (getCapReg auth r) \\<le> AvailableAuthority r\"\n                by auto\n              have \"StoreDataProp r (PreserveDomain actions) s'\"\n                using CanBeSimulatedE[OF abstraction intra_suc]\n                by auto\n              from StoreDataPropE_mem\n                   [OF this _ _ valid2, \n                    where a=a' and a'=a' and auth=auth and l=l and actions=actions]\n              obtain vAddr where \"vAddr \\<in> RegionOfCap (getCapReg auth r)\" \n                                 \"getTranslateAddr (vAddr, STORE) r = Some a'\"\n                using action StoreDataAction target restrict\n                by auto\n              hence \"a \\<in> getTranslateCapAddresses (StorableAddresses (GetAuthority (getCapReg auth r))) STORE r\"\n                using a restrict\n                by (auto simp: GetAuthority_accessors \n                         intro: getTranslateCapAddressesI)\n              hence \"a \\<in> getTranslateCapAddresses (StorableAddresses (AvailableAuthority r)) STORE r\"\n                using getTranslateCapAddresses_le[OF StorableAddresses_le[OF gperm]]\n                by auto\n              thus False\n                using no_access2\n                unfolding StorablePhysCapAddresses_def Let_def\n                unfolding getTranslateCapAddresses_distrib_union\n                by simp\n            next\n              case (StoreCapAction auth cd a')\n              hence \"StoreCapAction auth cd a \\<in> actions\"\n                using action target\n                by auto\n              note store = CanBeSimulatedE_StoreCap[OF abstraction intra_suc _ this valid2]\n              have \"getCapReg auth r \\<in> AvailableCaps r\"\n                using AvailableCaps_CapReg\n                      [OF abstraction intra_suc action _ no_sys_pcc valid2, where r=auth]\n                using store StoreCapAction\n                by (cases auth) auto\n              hence \"getCapReg auth r \\<in> TransUsableCaps r\"\n                using store \n                by auto\n              hence gperm: \"GetAuthority (getCapReg auth r) \\<le> AvailableAuthority r\"\n                by auto\n              have \"StoreCapProp r (PreserveDomain actions) s'\"\n                using CanBeSimulatedE[OF abstraction intra_suc]\n                by auto\n              from StoreCapPropE_mem\n                   [OF this _ _ valid2, \n                    where a=a and a'=\"ExtendCapAddress a\" and actions=actions]\n              obtain vAddr where \"vAddr \\<in> RegionOfCap (getCapReg auth r)\" \n                                 \"getTranslateAddr (vAddr, STORE) r = Some (ExtendCapAddress a)\"\n                using action StoreCapAction target\n                by auto\n              from getTranslateCapAddressesI_word_cat[OF this(2) this(1)]\n              have \"a \\<in> getTranslateCapAddresses (StorableAddresses (GetAuthority (getCapReg auth r))) STORE r\"\n                using store\n                unfolding word_size\n                by (auto simp: GetAuthority_accessors\n                         intro: getTranslateCapAddressesI)\n              hence \"a \\<in> getTranslateCapAddresses (StorableAddresses (AvailableAuthority r)) STORE r\"\n                using getTranslateCapAddresses_le[OF StorableAddresses_le[OF gperm]]\n                by auto\n              thus False\n                using no_access2\n                unfolding StorablePhysCapAddresses_def Let_def\n                unfolding getTranslateCapAddresses_distrib_union\n                by simp\n            qed simp_all\n        qed\n      hence \"\\<And>prov. prov \\<in> actions \\<Longrightarrow> LocMem a \\<notin> ActionTargets prov\"\n        by auto\n      from CanBeSimulatedE_CapabilityInvariant[OF abstraction intra_suc _ this valid2]\n      show ?thesis by auto\n    qed\n  thus ?case using ih by auto\nqed simp\n\ntheorem MemCapInvariant:\n  assumes abstraction: \"CanBeSimulated sem\"\n      and trace: \"(step # trace, s') \\<in> Traces sem s\"\n      and intra: \"TracePreservesDomain trace\"\n      and inter: \"\\<not> PreservesDomain step\"\n      and no_access: \"a \\<notin> StorablePhysCapAddresses (AvailableAuthority s) s\"\n      and no_sys: \"\\<not> SystemRegisterAccess (AvailableAuthority s)\"\n      and valid: \"getStateIsValid s\"\n  shows \"getMemCap a s' = getMemCap a s\"\nproof -\n  obtain r where r\\<^sub>1: \"(trace, r) \\<in> Traces sem s\"\n             and r\\<^sub>2: \"(step, s') \\<in> sem r\"\n    using trace by auto\n  obtain crossing where step: \"step = SwitchDomain crossing\"\n    using inter by (cases step) auto\n  have valid2: \"getStateIsValid r\"\n    using TraceInvarianceStateIsValid[OF abstraction valid r\\<^sub>1]\n    by auto\n  have \"getMemCap a s' = getMemCap a r\"\n    proof (cases crossing)\n      case RaiseException\n      hence \"(SwitchDomain RaiseException, s') \\<in> sem r\"\n        using r\\<^sub>2 step by auto\n      from CanBeSimulatedE_Exception[OF abstraction this _ valid2]\n      show ?thesis\n        unfolding getMemCap_def\n        by auto\n    next\n      case (InvokeCapability cd cd')\n      hence \"(SwitchDomain (InvokeCapability cd cd'), s') \\<in> sem r\"\n        using r\\<^sub>2 step by auto\n      from CanBeSimulatedE_InvokeCap[OF abstraction this _ valid2]\n      show ?thesis\n        unfolding getMemCap_def\n        by auto\n    qed\n  have \"getMemCap a r = getMemCap a s\"\n    using MemCapInvariant_intra[OF abstraction r\\<^sub>1 intra no_access no_sys valid]\n    by simp\n  thus ?thesis\n    using `getMemCap a s' = getMemCap a r`\n    by auto\nqed\n\nsubsection \\<open>Invariance of data\\<close>\n\nlemma MemoryInvariant_intra:\n  assumes abstraction: \"CanBeSimulated sem\"\n      and trace: \"(trace, s') \\<in> Traces sem s\"\n      and intra: \"TracePreservesDomain trace\"\n      and no_access: \"a \\<notin> StorablePhysAddresses (AvailableAuthority s) s\"\n      and no_sys: \"\\<not> SystemRegisterAccess (AvailableAuthority s)\"\n      and valid: \"getStateIsValid s\"\n  shows \"getMemByte a s' = getMemByte a s\"\nusing trace intra\nproof (induct trace arbitrary: s')\n  case (Cons step trace)\n  then obtain r where r\\<^sub>1: \"(trace, r) \\<in> Traces sem s\"\n                  and r\\<^sub>2: \"(step, s') \\<in> sem r\"\n    by auto\n  have intra2: \"TracePreservesDomain trace\"\n    using Cons by auto\n  have ih: \"getMemByte a r = getMemByte a s\"\n    using Cons(1)[OF r\\<^sub>1] Cons(3)\n    by auto\n  have valid2: \"getStateIsValid r\"\n    using TraceInvarianceStateIsValid[OF abstraction valid r\\<^sub>1]\n    by auto\n  have no_ex2: \"step \\<noteq> SwitchDomain RaiseException\"\n    using Cons(3)\n    by auto\n  have perms: \"AvailableAuthority r \\<le> AvailableAuthority s\"\n    using MonotonicityAvailableAuthority[OF abstraction r\\<^sub>1 intra2 no_sys valid]\n    by auto\n  from SystemRegisterAccess_le[OF this]\n  have no_sys2: \"\\<not> SystemRegisterAccess (AvailableAuthority r)\"\n    using no_sys by auto\n  have no_sys_pcc: \"\\<not> Access_System_Registers (getPerms (getPCC r))\"\n    using SystemRegisterAccess_PCC[OF abstraction r\\<^sub>2 no_ex2 no_sys2 valid2]\n    by auto\n  have addrTrans: \"getTranslateAddr a r = getTranslateAddr a s\" for a\n    using TraceInvarianceAddressTranslation[OF abstraction r\\<^sub>1 intra2 no_sys valid]\n    by auto\n  from StorablePhysAddresses_le[OF perms]\n  have no_access2: \"a \\<notin> StorablePhysAddresses (AvailableAuthority r) r\"\n    using getTranslateAddresses_eqI_getTranslateAddr[OF addrTrans]\n    using no_access\n    unfolding StorablePhysAddresses_def\n    by auto\n  hence \"getMemByte a s' = getMemByte a r\"\n    proof -\n      obtain actions where \"step = PreserveDomain actions\"\n        using Cons(3)\n        by (cases step) auto\n      hence intra_suc: \"(PreserveDomain actions, s') \\<in> sem r\"\n        using r\\<^sub>2\n        by auto\n      have no_store_data: \n        \"\\<not> (\\<exists>auth a' l. StoreDataAction auth a' l \\<in> actions \\<and> a \\<in> Region a' l)\" \n        proof (clarify)\n          fix auth a' l\n          assume prov: \"StoreDataAction auth a' l \\<in> actions\" \n             and addr: \"a \\<in> Region a' l \"\n          hence \"l \\<noteq> 0\"\n            by auto\n          note store = CanBeSimulatedE_StoreData[OF abstraction intra_suc _ prov valid2]\n          have *: \"a \\<in> getTranslateAddresses (StorableAddresses (GetAuthority (getCapReg auth r))) STORE r\"\n            using store addr\n            by (auto simp: GetAuthority_accessors intro: getTranslateAddressesI)\n          have \"getCapReg auth r \\<in> AvailableCaps r\"\n            using AvailableCaps_CapReg\n                  [OF abstraction intra_suc prov _ no_sys_pcc valid2, where r=auth]\n            using store `l \\<noteq> 0`\n            by (cases auth) auto\n          hence \"getCapReg auth r \\<in> TransUsableCaps r\"\n            using store \n            by auto\n          hence \"GetAuthority (getCapReg auth r) \\<le> AvailableAuthority r\"\n            by auto\n          note StorableAddresses_le[OF this]\n          from getTranslateAddresses_le[OF this]\n          show False\n            using no_access2 *\n            unfolding StorablePhysAddresses_def\n            by auto\n        qed\n      have no_store_cap: \n        \"\\<not> (\\<exists>auth cd a'. StoreCapAction auth cd a' \\<in> actions \\<and> \n                         a \\<in> Region (ExtendCapAddress a') 32)\" \n        proof (clarify)\n          fix auth cd a'\n          assume prov: \"StoreCapAction auth cd a' \\<in> actions\" \n             and addr: \"a \\<in> Region (ExtendCapAddress a') 32\"\n          note store = CanBeSimulatedE_StoreCap[OF abstraction intra_suc _ prov valid2]\n          have *: \"a \\<in> getTranslateAddresses (StorableAddresses (GetAuthority (getCapReg auth r))) STORE r\"\n            using store addr\n            by (auto simp: GetAuthority_accessors intro: getTranslateAddressesI)\n          have \"getCapReg auth r \\<in> AvailableCaps r\"\n            using AvailableCaps_CapReg\n                  [OF abstraction intra_suc prov _ no_sys_pcc valid2, where r=auth]\n            using store\n            by (cases auth) auto\n          hence \"getCapReg auth r \\<in> TransUsableCaps r\"\n            using store \n            by auto\n          hence \"GetAuthority (getCapReg auth r) \\<le> AvailableAuthority r\"\n            by auto\n          note StorableAddresses_le[OF this]\n          from getTranslateAddresses_le[OF this]\n          show False\n            using no_access2 *\n            unfolding StorablePhysAddresses_def\n            by auto\n        qed\n      have \"\\<And>prov. prov \\<in> actions \\<Longrightarrow> a \\<notin> WrittenAddresses prov\"\n        unfolding WrittenAddresses_def\n        using no_store_data no_store_cap\n        by (auto split: DomainAction.splits)\n      from CanBeSimulatedE_MemoryInvariant[OF abstraction intra_suc _ this valid2]\n      show ?thesis \n        by auto\n    qed\n  thus ?case\n    using ih by auto\nqed simp\n\ntheorem MemoryInvariant:\n  assumes abstraction: \"CanBeSimulated sem\"\n      and trace: \"(step # trace, s') \\<in> Traces sem s\"\n      and intra: \"TracePreservesDomain trace\"\n      and inter: \"\\<not> PreservesDomain step\"\n      and no_access: \"a \\<notin> StorablePhysAddresses (AvailableAuthority s) s\"\n      and no_sys: \"\\<not> SystemRegisterAccess (AvailableAuthority s)\"\n      and valid: \"getStateIsValid s\"\n  shows \"getMemByte a s' = getMemByte a s\"\nproof -\n  obtain r where r\\<^sub>1: \"(trace, r) \\<in> Traces sem s\"\n             and r\\<^sub>2: \"(step, s') \\<in> sem r\"\n    using trace by auto\n  obtain crossing where step: \"step = SwitchDomain crossing\"\n    using inter by (cases step) auto\n  have valid2: \"getStateIsValid r\"\n    using TraceInvarianceStateIsValid[OF abstraction valid r\\<^sub>1]\n    by auto\n  have \"getMemByte a s' = getMemByte a r\"\n    proof (cases crossing)\n      case RaiseException\n      hence \"(SwitchDomain RaiseException, s') \\<in> sem r\"\n        using r\\<^sub>2 step by auto\n      from CanBeSimulatedE_Exception[OF abstraction this _ valid2]\n      show ?thesis\n        unfolding getMemByte_def\n        by auto\n    next\n      case (InvokeCapability cd cd')\n      hence \"(SwitchDomain (InvokeCapability cd cd'), s') \\<in> sem r\"\n        using r\\<^sub>2 step by auto\n      from CanBeSimulatedE_InvokeCap[OF abstraction this _ valid2]\n      show ?thesis\n        unfolding getMemByte_def\n        by auto\n    qed\n  have \"getMemByte a r = getMemByte a s\"\n    using MemoryInvariant_intra[OF abstraction r\\<^sub>1 intra no_access no_sys valid]\n    by metis\n  thus ?thesis\n    using `getMemByte a s' = getMemByte a r`\n    by auto\nqed\n\n(*<*)\nend\n(*>*)", "meta": {"author": "CTSRD-CHERI", "repo": "l3-cheri-mips-proofs", "sha": "239c37ad1587caf261501478bbcd1293b9ecb7b7", "save_path": "github-repos/isabelle/CTSRD-CHERI-l3-cheri-mips-proofs", "path": "github-repos/isabelle/CTSRD-CHERI-l3-cheri-mips-proofs/l3-cheri-mips-proofs-239c37ad1587caf261501478bbcd1293b9ecb7b7/properties/TraceProperties.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.658417500561683, "lm_q2_score": 0.3886180267058489, "lm_q1q2_score": 0.2558729098168784}}
{"text": "(* Copyright 2021 (C) Mihails Milehins *)\n\nsection\\<open>Limits and colimits\\<close>\ntheory CZH_UCAT_Limit\n  imports \n    CZH_UCAT_Universal\n    CZH_Elementary_Categories.CZH_ECAT_Cone\n    CZH_Elementary_Categories.CZH_ECAT_Small_Cone\nbegin\n\n\n\nsubsection\\<open>Background\\<close>\n\nnamed_theorems cat_lim_cs_simps\nnamed_theorems cat_lim_cs_intros\n\n\n\nsubsection\\<open>Limit and colimit\\<close>\n\n\nsubsubsection\\<open>Definition and elementary properties\\<close>\n\n\ntext\\<open>\nThe concept of a limit is introduced in Chapter III-4 in\n\\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>; the concept of a colimit is introduced in\nChapter III-3 in \\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>.\n\\<close>\n\nlocale is_cat_limit = is_cat_cone \\<alpha> r \\<JJ> \\<CC> \\<FF> u for \\<alpha> \\<JJ> \\<CC> \\<FF> r u + \n  assumes cat_lim_ua_fo: \"\\<And>u' r'. u' : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC> \\<Longrightarrow>\n    \\<exists>!f'. f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r \\<and> u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f'\"\n\nsyntax \"_is_cat_limit\" :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> bool\"\n  (\\<open>(_ :/ _ <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m _ :/ _ \\<mapsto>\\<mapsto>\\<^sub>C\\<index> _)\\<close> [51, 51, 51, 51, 51] 51)\ntranslations \"u : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \\<rightleftharpoons> \n  \"CONST is_cat_limit \\<alpha> \\<JJ> \\<CC> \\<FF> r u\"\n\nlocale is_cat_colimit = is_cat_cocone \\<alpha> r \\<JJ> \\<CC> \\<FF> u for \\<alpha> \\<JJ> \\<CC> \\<FF> r u +\n  assumes cat_colim_ua_of: \"\\<And>u' r'. u' : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e r' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC> \\<Longrightarrow>\n    \\<exists>!f'. f' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r' \\<and> u' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\"\n\nsyntax \"_is_cat_colimit\" :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> bool\"\n  (\\<open>(_ :/ _ >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m _ :/ _ \\<mapsto>\\<mapsto>\\<^sub>C\\<index> _)\\<close> [51, 51, 51, 51, 51] 51)\ntranslations \"u : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m r : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \\<rightleftharpoons> \n  \"CONST is_cat_colimit \\<alpha> \\<JJ> \\<CC> \\<FF> r u\"\n\n\ntext\\<open>Rules.\\<close>\n\nlemma (in is_cat_limit) is_cat_limit_axioms'[cat_lim_cs_intros]:\n  assumes \"\\<alpha>' = \\<alpha>\" and \"r' = r\" and \"\\<JJ>' = \\<JJ>\" and \"\\<CC>' = \\<CC>\" and \"\\<FF>' = \\<FF>\"\n  shows \"u : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF>' : \\<JJ>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>'\\<^esub> \\<CC>'\"\n  unfolding assms by (rule is_cat_limit_axioms)\n\nmk_ide rf is_cat_limit_def[unfolded is_cat_limit_axioms_def]\n  |intro is_cat_limitI|\n  |dest is_cat_limitD[dest]|\n  |elim is_cat_limitE[elim]|\n\nlemmas [cat_lim_cs_intros] = is_cat_limitD(1)\n\nlemma (in is_cat_colimit) is_cat_colimit_axioms'[cat_lim_cs_intros]:\n  assumes \"\\<alpha>' = \\<alpha>\" and \"r' = r\" and \"\\<JJ>' = \\<JJ>\" and \"\\<CC>' = \\<CC>\" and \"\\<FF>' = \\<FF>\"\n  shows \"u : \\<FF>' >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m r' : \\<JJ>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>'\\<^esub> \\<CC>'\"\n  unfolding assms by (rule is_cat_colimit_axioms)\n\nmk_ide rf is_cat_colimit_def[unfolded is_cat_colimit_axioms_def]\n  |intro is_cat_colimitI|\n  |dest is_cat_colimitD[dest]|\n  |elim is_cat_colimitE[elim]|\n\nlemmas [cat_lim_cs_intros] = is_cat_colimitD(1)\n\n\ntext\\<open>Limits, colimits and universal arrows.\\<close>\n\nlemma (in is_cat_limit) cat_lim_is_universal_arrow_fo:\n  \"universal_arrow_fo (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) r (ntcf_arrow u)\"\nproof(intro is_functor.universal_arrow_foI)\n\n  define \\<beta> where \"\\<beta> = \\<alpha> + \\<omega>\"\n  have \\<beta>: \"\\<Z> \\<beta>\" and \\<alpha>\\<beta>: \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\"\n    by (simp_all add: \\<beta>_def \\<Z>_Limit_\\<alpha>\\<omega> \\<Z>_\\<omega>_\\<alpha>\\<omega> \\<Z>_def \\<Z>_\\<alpha>_\\<alpha>\\<omega>)\n  then interpret \\<beta>: \\<Z> \\<beta> by simp \n\n  show \"\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC> : \\<CC> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<beta>\\<^esub> cat_FUNCT \\<alpha> \\<JJ> \\<CC>\"\n    by \n      (\n        intro \n          \\<beta> \\<alpha>\\<beta>\n          cf_diagonal_is_functor \n          NTDom.HomDom.category_axioms \n          NTDom.HomCod.category_axioms\n      )\n\n  show \"r \\<in>\\<^sub>\\<circ> \\<CC>\\<lparr>Obj\\<rparr>\" by (intro cat_cone_obj)\n  then show \"ntcf_arrow u : \\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> \\<mapsto>\\<^bsub>cat_FUNCT \\<alpha> \\<JJ> \\<CC>\\<^esub> cf_map \\<FF>\"\n    by \n      (\n        cs_concl cs_shallow\n          cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_FUNCT_cs_intros\n      )\n\n  fix r' u' assume prems: \n    \"r' \\<in>\\<^sub>\\<circ> \\<CC>\\<lparr>Obj\\<rparr>\" \"u' : \\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr> \\<mapsto>\\<^bsub>cat_FUNCT \\<alpha> \\<JJ> \\<CC>\\<^esub> cf_map \\<FF>\"\n  from prems(1) have [cat_cs_simps]: \n    \"cf_of_cf_map \\<JJ> \\<CC> (cf_map \\<FF>) = \\<FF>\"\n    \"cf_of_cf_map \\<JJ> \\<CC> (cf_map (cf_const \\<JJ> \\<CC> r')) = cf_const \\<JJ> \\<CC> r'\"\n    by (cs_concl cs_simp: cat_FUNCT_cs_simps cs_intro: cat_cs_intros)+\n  from prems(2,1) have\n    \"u' : cf_map (cf_const \\<JJ> \\<CC> r') \\<mapsto>\\<^bsub>cat_FUNCT \\<alpha> \\<JJ> \\<CC>\\<^esub> cf_map \\<FF>\"\n    by (cs_prems cs_shallow cs_simp: cat_cs_simps)\n  note u'[unfolded cat_cs_simps] = cat_FUNCT_is_arrD[OF this]\n\n  from cat_lim_ua_fo[OF is_cat_coneI[OF u'(1) prems(1)]] obtain f \n    where f: \"f : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r\"\n      and [symmetric, cat_cs_simps]: \n        \"ntcf_of_ntcf_arrow \\<JJ> \\<CC> u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f\"\n      and f_unique: \n        \"\\<lbrakk>\n          f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r;\n          ntcf_of_ntcf_arrow \\<JJ> \\<CC> u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f'\n         \\<rbrakk> \\<Longrightarrow> f' = f\"\n    for f'\n    by metis\n\n  show \"\\<exists>!f'.\n    f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r \\<and>\n    u' = umap_fo (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) r (ntcf_arrow u) r'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\n  proof(intro ex1I conjI; (elim conjE)?)\n    show \"f : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r\" by (rule f)\n    with \\<alpha>\\<beta> cat_cone_obj show u'_def: \n      \"u' = umap_fo (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) r (ntcf_arrow u) r'\\<lparr>ArrVal\\<rparr>\\<lparr>f\\<rparr>\"\n      by \n        (\n          cs_concl\n            cs_simp: u'(2)[symmetric] cat_cs_simps cat_FUNCT_cs_simps \n            cs_intro: cat_cs_intros cat_FUNCT_cs_intros\n        )\n    fix f' assume prems': \n      \"f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r\"\n      \"u' = umap_fo (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) r (ntcf_arrow u) r'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\n    from prems'(2) \\<alpha>\\<beta> f prems' cat_cone_obj have u'_def':\n      \"u' = ntcf_arrow (u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f')\"\n      by\n        (\n          cs_prems\n            cs_simp: cat_cs_simps cat_FUNCT_cs_simps\n            cs_intro: cat_cs_intros cat_FUNCT_cs_intros\n        )\n    from prems'(1) have \"ntcf_of_ntcf_arrow \\<JJ> \\<CC> u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f'\"\n      by \n        (\n          cs_concl \n            cs_simp: cat_FUNCT_cs_simps u'_def' cs_intro: cat_cs_intros\n        )\n    from f_unique[OF prems'(1) this] show \"f' = f\" .\n\n  qed\n\nqed\n\nlemma (in is_cat_cone) cat_cone_is_cat_limit:\n  assumes \"universal_arrow_fo (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) c (ntcf_arrow \\<NN>)\"\n  shows \"\\<NN> : c <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\nproof-\n\n  define \\<beta> where \"\\<beta> = \\<alpha> + \\<omega>\"\n  have \\<beta>: \"\\<Z> \\<beta>\" and \\<alpha>\\<beta>: \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\"\n    by (simp_all add: \\<beta>_def \\<Z>_Limit_\\<alpha>\\<omega> \\<Z>_\\<omega>_\\<alpha>\\<omega> \\<Z>_def \\<Z>_\\<alpha>_\\<alpha>\\<omega>)\n  then interpret \\<beta>: \\<Z> \\<beta> by simp \n\n  show ?thesis\n  proof(intro is_cat_limitI is_cat_cone_axioms)\n    fix u' c' assume prems: \"u' : c' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n\n    interpret u': is_cat_cone \\<alpha> c' \\<JJ> \\<CC> \\<FF> u' by (rule prems)\n\n    from u'.cat_cone_obj have u'_is_arr:\n      \"ntcf_arrow u' : \\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>\\<lparr>ObjMap\\<rparr>\\<lparr>c'\\<rparr> \\<mapsto>\\<^bsub>cat_FUNCT \\<alpha> \\<JJ> \\<CC>\\<^esub> cf_map \\<FF>\"\n      by \n        (\n          cs_concl cs_shallow\n            cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_FUNCT_cs_intros\n        )\n    \n    from is_functor.universal_arrow_foD(3)\n      [\n        OF\n          cf_diagonal_is_functor[\n            OF \\<beta> \\<alpha>\\<beta> NTDom.HomDom.category_axioms NTDom.HomCod.category_axioms\n            ]\n          assms\n          u'.cat_cone_obj\n          u'_is_arr\n      ]\n    obtain f where f: \"f : c' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c\"\n      and u'_def': \"ntcf_arrow u' =\n        umap_fo (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) c (ntcf_arrow \\<NN>) c'\\<lparr>ArrVal\\<rparr>\\<lparr>f\\<rparr>\"\n      and f'_unique:\n        \"\\<lbrakk>\n          f' : c' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c;\n          ntcf_arrow u' =\n            umap_fo (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) c (ntcf_arrow \\<NN>) c'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\n         \\<rbrakk> \\<Longrightarrow> f' = f\"\n      for f'\n      by metis\n\n    from u'_def' \\<alpha>\\<beta> f cat_cone_obj have u'_def: \n      \"u' = \\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f\"\n      by\n        (\n          cs_prems\n            cs_simp: cat_cs_simps cat_FUNCT_cs_simps \n            cs_intro: cat_cs_intros cat_FUNCT_cs_intros\n        )\n    \n    show \"\\<exists>!f'. f' : c' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c \\<and> u' = \\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f'\"\n    proof(intro ex1I conjI; (elim conjE)?, (rule f)?, (rule u'_def)?)\n      fix f'' assume prems': \n        \"f'' : c' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c\" \"u' = \\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f''\"\n      from \\<alpha>\\<beta> prems' have \n        \"ntcf_arrow u' = \n          umap_fo (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) c (ntcf_arrow \\<NN>) c'\\<lparr>ArrVal\\<rparr>\\<lparr>f''\\<rparr>\"\n        by\n          (\n            cs_concl \n              cs_simp: cat_cs_simps cat_FUNCT_cs_simps \n              cs_intro: cat_cs_intros cat_FUNCT_cs_intros\n          )\n      from f'_unique[OF prems'(1) this] show \"f'' = f\".\n    qed\n\n  qed\n  \nqed\n\nlemma (in is_cat_colimit) cat_colim_is_universal_arrow_of:\n  \"universal_arrow_of (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) r (ntcf_arrow u)\"\nproof(intro is_functor.universal_arrow_ofI)\n\n  define \\<beta> where \"\\<beta> = \\<alpha> + \\<omega>\"\n  have \\<beta>: \"\\<Z> \\<beta>\" and \\<alpha>\\<beta>: \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\"\n    by (simp_all add: \\<beta>_def \\<Z>_Limit_\\<alpha>\\<omega> \\<Z>_\\<omega>_\\<alpha>\\<omega> \\<Z>_def \\<Z>_\\<alpha>_\\<alpha>\\<omega>)\n  then interpret \\<beta>: \\<Z> \\<beta> by simp \n\n  show \"\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC> : \\<CC> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<beta>\\<^esub> cat_FUNCT \\<alpha> \\<JJ> \\<CC>\"\n    by \n      (\n        intro \n          \\<beta> \\<alpha>\\<beta>\n          cf_diagonal_is_functor \n          NTDom.HomDom.category_axioms \n          NTDom.HomCod.category_axioms\n      )\n\n  show \"r \\<in>\\<^sub>\\<circ> \\<CC>\\<lparr>Obj\\<rparr>\" by (intro cat_cocone_obj)\n\n  then show \"ntcf_arrow u : cf_map \\<FF> \\<mapsto>\\<^bsub>cat_FUNCT \\<alpha> \\<JJ> \\<CC>\\<^esub> \\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\"\n    by \n      (\n        cs_concl cs_shallow\n          cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_FUNCT_cs_intros\n      )\n\n  fix r' u' assume prems: \n    \"r' \\<in>\\<^sub>\\<circ> \\<CC>\\<lparr>Obj\\<rparr>\" \"u' : cf_map \\<FF> \\<mapsto>\\<^bsub>cat_FUNCT \\<alpha> \\<JJ> \\<CC>\\<^esub> \\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr>\"\n  from prems(1) have [cat_cs_simps]: \n    \"cf_of_cf_map \\<JJ> \\<CC> (cf_map \\<FF>) = \\<FF>\"\n    \"cf_of_cf_map \\<JJ> \\<CC> (cf_map (cf_const \\<JJ> \\<CC> r')) = cf_const \\<JJ> \\<CC> r'\"\n    by (cs_concl cs_simp: cat_FUNCT_cs_simps cs_intro: cat_cs_intros)+\n  from prems(2,1) have\n    \"u' : cf_map \\<FF> \\<mapsto>\\<^bsub>cat_FUNCT \\<alpha> \\<JJ> \\<CC>\\<^esub> cf_map (cf_const \\<JJ> \\<CC> r')\"\n    by (cs_prems cs_shallow cs_simp: cat_cs_simps)\n  note u'[unfolded cat_cs_simps] = cat_FUNCT_is_arrD[OF this]\n\n  from cat_colim_ua_of[OF is_cat_coconeI[OF u'(1) prems(1)]] obtain f \n    where f: \"f : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r'\"\n      and [symmetric, cat_cs_simps]: \n        \"ntcf_of_ntcf_arrow \\<JJ> \\<CC> u' = ntcf_const \\<JJ> \\<CC> f \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\"\n      and f_unique: \n        \"\\<lbrakk>\n          f' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r';\n          ntcf_of_ntcf_arrow \\<JJ> \\<CC> u' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\n         \\<rbrakk> \\<Longrightarrow> f' = f\"\n    for f'\n    by metis\n\n  show \" \\<exists>!f'. \n    f' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r' \\<and> \n    u' = umap_of (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) r (ntcf_arrow u) r'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\n  proof(intro ex1I conjI; (elim conjE)?)\n  \n    show \"f : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r'\" by (rule f)\n    with \\<alpha>\\<beta> cat_cocone_obj show u'_def: \n      \"u' = umap_of (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) r (ntcf_arrow u) r'\\<lparr>ArrVal\\<rparr>\\<lparr>f\\<rparr>\"\n      by \n        (\n          cs_concl\n            cs_simp: u'(2)[symmetric] cat_cs_simps cat_FUNCT_cs_simps \n            cs_intro: cat_cs_intros cat_FUNCT_cs_intros\n        )\n  \n    fix f' assume prems':\n      \"f' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r'\"\n      \"u' = umap_of (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) r (ntcf_arrow u) r'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\n    from prems'(2) \\<alpha>\\<beta> f prems' cat_cocone_obj have u'_def':\n      \"u' = ntcf_arrow (ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u)\"\n      by\n        (\n          cs_prems\n            cs_simp: cat_cs_simps cat_FUNCT_cs_simps\n            cs_intro: cat_cs_intros cat_FUNCT_cs_intros\n        )\n    from prems'(1) have \"ntcf_of_ntcf_arrow \\<JJ> \\<CC> u' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\"\n      by \n        (\n          cs_concl cs_shallow \n            cs_simp: cat_FUNCT_cs_simps u'_def' cs_intro: cat_cs_intros\n        )\n    from f_unique[OF prems'(1) this] show \"f' = f\" .\n\n  qed\n\nqed\n\nlemma (in is_cat_cocone) cat_cocone_is_cat_colimit:\n  assumes \"universal_arrow_of (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) c (ntcf_arrow \\<NN>)\"\n  shows \"\\<NN> : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m c : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\nproof-\n\n  define \\<beta> where \"\\<beta> = \\<alpha> + \\<omega>\"\n  have \\<beta>: \"\\<Z> \\<beta>\" and \\<alpha>\\<beta>: \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\"\n    by (simp_all add: \\<beta>_def \\<Z>_Limit_\\<alpha>\\<omega> \\<Z>_\\<omega>_\\<alpha>\\<omega> \\<Z>_def \\<Z>_\\<alpha>_\\<alpha>\\<omega>)\n  then interpret \\<beta>: \\<Z> \\<beta> by simp \n\n  show ?thesis\n  proof(intro is_cat_colimitI is_cat_cocone_axioms)\n  \n    fix u' c' assume prems: \"u' : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e c' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n\n    interpret u': is_cat_cocone \\<alpha> c' \\<JJ> \\<CC> \\<FF> u' by (rule prems)\n\n    from u'.cat_cocone_obj have u'_is_arr:\n      \"ntcf_arrow u' : cf_map \\<FF> \\<mapsto>\\<^bsub>cat_FUNCT \\<alpha> \\<JJ> \\<CC>\\<^esub> \\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>\\<lparr>ObjMap\\<rparr>\\<lparr>c'\\<rparr>\"\n      by\n        (\n          cs_concl cs_shallow \n            cs_simp: cat_cs_simps cs_intro: cat_cs_intros cat_FUNCT_cs_intros\n        )\n\n    from is_functor.universal_arrow_ofD(3)\n      [\n        OF\n          cf_diagonal_is_functor[\n            OF \\<beta> \\<alpha>\\<beta> NTDom.HomDom.category_axioms NTDom.HomCod.category_axioms\n            ]\n          assms\n          u'.cat_cocone_obj\n          u'_is_arr\n      ]\n    obtain f where f: \"f : c \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c'\"\n      and u'_def': \"ntcf_arrow u' =\n        umap_of (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) c (ntcf_arrow \\<NN>) c'\\<lparr>ArrVal\\<rparr>\\<lparr>f\\<rparr>\"\n      and f'_unique:\n        \"\\<lbrakk>\n          f' : c \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c';\n          ntcf_arrow u' =\n            umap_of (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) c (ntcf_arrow \\<NN>) c'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\n         \\<rbrakk> \\<Longrightarrow> f' = f\"\n      for f'\n      by metis\n\n    from u'_def' \\<alpha>\\<beta> f cat_cocone_obj have u'_def: \n      \"u' = ntcf_const \\<JJ> \\<CC> f \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<NN>\"\n      by\n        (\n          cs_prems\n            cs_simp: cat_cs_simps cat_FUNCT_cs_simps\n            cs_intro: cat_cs_intros cat_FUNCT_cs_intros\n        )\n    \n    show \"\\<exists>!f'. f' : c \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c' \\<and> u' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<NN>\"\n    proof(intro ex1I conjI; (elim conjE)?, (rule f)?, (rule u'_def)?)\n      fix f'' assume prems': \n        \"f'' : c \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c'\" \"u' = ntcf_const \\<JJ> \\<CC> f'' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<NN>\"\n      from \\<alpha>\\<beta> prems' have \n        \"ntcf_arrow u' = \n          umap_of (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) c (ntcf_arrow \\<NN>) c'\\<lparr>ArrVal\\<rparr>\\<lparr>f''\\<rparr>\"\n        by\n          (\n            cs_concl \n              cs_simp: cat_cs_simps cat_FUNCT_cs_simps\n              cs_intro: cat_cs_intros cat_FUNCT_cs_intros\n          )\n      from f'_unique[OF prems'(1) this] show \"f'' = f\".\n    qed\n\n  qed\n  \nqed\n\n\ntext\\<open>Duality.\\<close>\n\nlemma (in is_cat_limit) is_cat_colimit_op:\n  \"op_ntcf u : op_cf \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m r : op_cat \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_cat \\<CC>\"\nproof(intro is_cat_colimitI)\n  show \"op_ntcf u : op_cf \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e r : op_cat \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_cat \\<CC>\"\n    by (cs_concl cs_shallow cs_simp: cs_intro: cat_op_intros)\n  fix u' r' assume prems: \n    \"u' : op_cf \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e r' : op_cat \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_cat \\<CC>\"\n  interpret u': is_cat_cocone \\<alpha> r' \\<open>op_cat \\<JJ>\\<close> \\<open>op_cat \\<CC>\\<close> \\<open>op_cf \\<FF>\\<close> u' \n    by (rule prems)\n  from cat_lim_ua_fo[OF u'.is_cat_cone_op[unfolded cat_op_simps]] obtain f \n    where f: \"f : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r\"\n      and op_u'_def: \"op_ntcf u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f\"\n      and f_unique: \n        \"\\<lbrakk> f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r; op_ntcf u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f' \\<rbrakk> \\<Longrightarrow>\n          f' = f\"\n    for f'\n    by metis\n  from op_u'_def have \"op_ntcf (op_ntcf u') = op_ntcf (u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f)\"\n    by simp\n  from this f have u'_def: \n    \"u' = ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F op_ntcf u\"\n    by (cs_prems cs_simp: cat_op_simps cs_intro: cat_cs_intros)\n  show \"\\<exists>!f'. \n    f' : r \\<mapsto>\\<^bsub>op_cat \\<CC>\\<^esub> r' \\<and> \n    u' = ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F op_ntcf u\"\n  proof(intro ex1I conjI; (elim conjE)?, (unfold cat_op_simps)?)\n    fix f' assume prems': \n      \"f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r\"\n      \"u' = ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F op_ntcf u\"\n    from prems'(2) have \n      \"op_ntcf u' = op_ntcf (ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F op_ntcf u)\"\n      by simp\n    from this prems'(1) have \"op_ntcf u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f'\"\n      by \n        (\n          cs_prems\n            cs_simp: cat_cs_simps cat_op_simps \n            cs_intro: cat_cs_intros cat_op_intros\n        )\n    from f_unique[OF prems'(1) this] show \"f' = f\". \n  qed (intro u'_def f)+\nqed\n\nlemma (in is_cat_limit) is_cat_colimit_op'[cat_op_intros]:\n  assumes \"\\<FF>' = op_cf \\<FF>\" and \"\\<JJ>' = op_cat \\<JJ>\" and \"\\<CC>' = op_cat \\<CC>\"\n  shows \"op_ntcf u : \\<FF>' >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m r : \\<JJ>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>'\"\n  unfolding assms by (rule is_cat_colimit_op)\n\nlemmas [cat_op_intros] = is_cat_limit.is_cat_colimit_op'\n\nlemma (in is_cat_colimit) is_cat_limit_op:\n  \"op_ntcf u : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m op_cf \\<FF> : op_cat \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_cat \\<CC>\"\nproof(intro is_cat_limitI)\n  show \"op_ntcf u : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e op_cf \\<FF> : op_cat \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_cat \\<CC>\"\n    by (cs_concl cs_shallow cs_simp: cs_intro: cat_op_intros)\n  fix u' r' assume prems: \n    \"u' : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e op_cf \\<FF> : op_cat \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_cat \\<CC>\"\n  interpret u': is_cat_cone \\<alpha> r' \\<open>op_cat \\<JJ>\\<close> \\<open>op_cat \\<CC>\\<close> \\<open>op_cf \\<FF>\\<close> u' \n    by (rule prems)\n  from cat_colim_ua_of[OF u'.is_cat_cocone_op[unfolded cat_op_simps]] obtain f \n    where f: \"f : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r'\"\n      and op_u'_def: \"op_ntcf u' = ntcf_const \\<JJ> \\<CC> f \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\"\n      and f_unique: \n        \"\\<lbrakk> f' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r'; op_ntcf u' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u \\<rbrakk> \\<Longrightarrow>\n          f' = f\"\n    for f'\n    by metis\n  from op_u'_def have \"op_ntcf (op_ntcf u') = op_ntcf (ntcf_const \\<JJ> \\<CC> f \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u)\"\n    by simp\n  from this f have u'_def: \n    \"u' = op_ntcf u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f\"\n    by (cs_prems cs_simp: cat_op_simps cs_intro: cat_cs_intros)\n  show \"\\<exists>!f'. \n    f' : r' \\<mapsto>\\<^bsub>op_cat \\<CC>\\<^esub> r \\<and> \n    u' = op_ntcf u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f'\"\n  proof(intro ex1I conjI; (elim conjE)?, (unfold cat_op_simps)?)\n    fix f' assume prems': \n      \"f' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r'\"\n      \"u' = op_ntcf u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f'\"\n    from prems'(2) have \n      \"op_ntcf u' = op_ntcf (op_ntcf u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f')\"\n      by simp\n    from this prems'(1) have \"op_ntcf u' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\"\n      by\n        (\n          cs_prems\n            cs_simp: cat_cs_simps cat_op_simps \n            cs_intro: cat_cs_intros cat_op_intros\n        )\n    from f_unique[OF prems'(1) this] show \"f' = f\". \n  qed (intro u'_def f)+\nqed\n\nlemma (in is_cat_colimit) is_cat_colimit_op'[cat_op_intros]:\n  assumes \"\\<FF>' = op_cf \\<FF>\" and \"\\<JJ>' = op_cat \\<JJ>\" and \"\\<CC>' = op_cat \\<CC>\"\n  shows \"op_ntcf u : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF>' : \\<JJ>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>'\"\n  unfolding assms by (rule is_cat_limit_op)\n\nlemmas [cat_op_intros] = is_cat_colimit.is_cat_colimit_op'\n\n\nsubsubsection\\<open>Universal property\\<close>\n\nlemma (in is_cat_limit) cat_lim_unique_cone':\n  assumes \"u' : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \n    \"\\<exists>!f'. f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r \\<and> (\\<forall>j\\<in>\\<^sub>\\<circ>\\<JJ>\\<lparr>Obj\\<rparr>. u'\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = u\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f')\"\n  by (fold helper_cat_cone_Comp_ntcf_vcomp_iff[OF assms(1)])\n    (intro cat_lim_ua_fo assms)\n\nlemma (in is_cat_limit) cat_lim_unique:\n  assumes \"u' : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"\\<exists>!f'. f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r \\<and> u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f'\"\n  by (intro cat_lim_ua_fo[OF is_cat_limitD(1)[OF assms]])\n\nlemma (in is_cat_limit) cat_lim_unique':\n  assumes \"u' : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \n    \"\\<exists>!f'. f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r \\<and> (\\<forall>j\\<in>\\<^sub>\\<circ>\\<JJ>\\<lparr>Obj\\<rparr>. u'\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = u\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f')\"\n  by (intro cat_lim_unique_cone'[OF is_cat_limitD(1)[OF assms]])\n\nlemma (in is_cat_colimit) cat_colim_unique_cocone:\n  assumes \"u' : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e r' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"\\<exists>!f'. f' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r' \\<and> u' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\"\nproof-\n  interpret u': is_cat_cocone \\<alpha> r' \\<JJ> \\<CC> \\<FF> u' by (rule assms(1))\n  from u'.cat_cocone_obj have op_r': \"r' \\<in>\\<^sub>\\<circ> op_cat \\<CC>\\<lparr>Obj\\<rparr>\"\n    unfolding cat_op_simps by simp\n  from \n    is_cat_limit.cat_lim_ua_fo[\n      OF is_cat_limit_op u'.is_cat_cone_op, folded op_ntcf_ntcf_const\n      ]\n  obtain f' where f': \"f' : r' \\<mapsto>\\<^bsub>op_cat \\<CC>\\<^esub> r\"\n    and [cat_cs_simps]: \n      \"op_ntcf u' = op_ntcf u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F op_ntcf (ntcf_const \\<JJ> \\<CC> f')\"\n    and unique: \n      \"\\<lbrakk>\n        f'' : r' \\<mapsto>\\<^bsub>op_cat \\<CC>\\<^esub> r;\n        op_ntcf u' = op_ntcf u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F op_ntcf (ntcf_const \\<JJ> \\<CC> f'')\n       \\<rbrakk> \\<Longrightarrow> f'' = f'\" \n    for f''\n    by metis\n  show ?thesis\n  proof(intro ex1I conjI; (elim conjE)?)\n    from f' show f': \"f' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r'\" unfolding cat_op_simps by simp\n    show \"u' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\"\n      by (rule eq_op_ntcf_iff[THEN iffD1], insert f')\n        (cs_concl cs_intro: cat_cs_intros cs_simp: cat_cs_simps cat_op_simps)+\n    fix f'' assume prems: \"f'' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r'\" \"u' = ntcf_const \\<JJ> \\<CC> f'' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\"\n    from prems(1) have \"f'' : r' \\<mapsto>\\<^bsub>op_cat \\<CC>\\<^esub> r\" unfolding cat_op_simps by simp\n    moreover from prems(1) have \n      \"op_ntcf u' = op_ntcf u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F op_ntcf (ntcf_const \\<JJ> \\<CC> f'')\"\n      unfolding prems(2)\n      by (cs_concl cs_intro: cat_cs_intros cs_simp: cat_cs_simps cat_op_simps)\n    ultimately show \"f'' = f'\" by (rule unique)\n  qed\nqed\n\nlemma (in is_cat_colimit) cat_colim_unique_cocone':\n  assumes \"u' : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e r' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \n    \"\\<exists>!f'. f' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r' \\<and> (\\<forall>j\\<in>\\<^sub>\\<circ>\\<JJ>\\<lparr>Obj\\<rparr>. u'\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> u\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr>)\"\n  by (fold helper_cat_cocone_Comp_ntcf_vcomp_iff[OF assms(1)])\n    (intro cat_colim_unique_cocone assms)\n\nlemma (in is_cat_colimit) cat_colim_unique:\n  assumes \"u' : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m r' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"\\<exists>!f'. f' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r' \\<and> u' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\"\n  by (intro cat_colim_unique_cocone[OF is_cat_colimitD(1)[OF assms]])\n\nlemma (in is_cat_colimit) cat_colim_unique':\n  assumes \"u' : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m r' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows\n    \"\\<exists>!f'. f' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r' \\<and> (\\<forall>j\\<in>\\<^sub>\\<circ>\\<JJ>\\<lparr>Obj\\<rparr>. u'\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = f' \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> u\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr>)\"\nproof-\n  interpret u': is_cat_colimit \\<alpha> \\<JJ> \\<CC> \\<FF> r' u' by (rule assms(1))\n  show ?thesis\n    by (fold helper_cat_cocone_Comp_ntcf_vcomp_iff[OF u'.is_cat_cocone_axioms])\n      (intro cat_colim_unique assms)\nqed\n\nlemma cat_lim_ex_is_iso_arr:\n  assumes \"u : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"u' : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  obtains f where \"f : r' \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<CC>\\<^esub> r\" and \"u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f\"\nproof-\n  interpret u: is_cat_limit \\<alpha> \\<JJ> \\<CC> \\<FF> r u by (rule assms(1))\n  interpret u': is_cat_limit \\<alpha> \\<JJ> \\<CC> \\<FF> r' u' by (rule assms(2))\n  define \\<beta> where \"\\<beta> = \\<alpha> + \\<omega>\"\n  have \\<beta>: \"\\<Z> \\<beta>\" and \\<alpha>\\<beta>: \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\"\n    by (simp_all add: \\<beta>_def u.\\<Z>_Limit_\\<alpha>\\<omega> u.\\<Z>_\\<omega>_\\<alpha>\\<omega> \\<Z>_def u.\\<Z>_\\<alpha>_\\<alpha>\\<omega>)\n  then interpret \\<beta>: \\<Z> \\<beta> by simp \n  have \\<Delta>: \"\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC> : \\<CC> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<beta>\\<^esub> cat_FUNCT \\<alpha> \\<JJ> \\<CC>\"\n    by \n      (\n        intro \n          \\<beta> \\<alpha>\\<beta>\n          cf_diagonal_is_functor \n          u.NTDom.HomDom.category_axioms \n          u.NTDom.HomCod.category_axioms\n      )\n  then interpret \\<Delta>: is_functor \\<beta> \\<CC> \\<open>cat_FUNCT \\<alpha> \\<JJ> \\<CC>\\<close> \\<open>\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>\\<close> by simp\n  from is_functor.cf_universal_arrow_fo_ex_is_iso_arr[\n    OF \\<Delta> u.cat_lim_is_universal_arrow_fo u'.cat_lim_is_universal_arrow_fo\n    ]\n  obtain f where f: \"f : r' \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<CC>\\<^esub> r\"\n    and u': \"ntcf_arrow u' =\n    umap_fo (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) r (ntcf_arrow u) r'\\<lparr>ArrVal\\<rparr>\\<lparr>f\\<rparr>\"\n    by auto\n  from f have \"f : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r\" by auto\n  from u' this have \"u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f\"\n    by\n      (\n        cs_prems  \n          cs_simp: cat_cs_simps cat_FUNCT_cs_simps\n          cs_intro: cat_cs_intros cat_FUNCT_cs_intros\n      )\n  with f that show ?thesis by simp\nqed\n\nlemma cat_lim_ex_is_iso_arr':\n  assumes \"u : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"u' : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  obtains f where \"f : r' \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<CC>\\<^esub> r\" \n    and \"\\<And>j. j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr> \\<Longrightarrow> u'\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = u\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\"\nproof-\n  interpret u: is_cat_limit \\<alpha> \\<JJ> \\<CC> \\<FF> r u by (rule assms(1))\n  interpret u': is_cat_limit \\<alpha> \\<JJ> \\<CC> \\<FF> r' u' by (rule assms(2))\n  from assms obtain f \n    where iso_f: \"f : r' \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<CC>\\<^esub> r\" and u'_def: \"u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f\"\n    by (rule cat_lim_ex_is_iso_arr)\n  then have f: \"f : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r\" by auto\n  then have \"u'\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = u\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> f\" if \"j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr>\" for j\n    by \n      (\n        intro u.helper_cat_cone_ntcf_vcomp_Comp[\n          OF u'.is_cat_cone_axioms f u'_def that\n          ]\n      )\n  with iso_f that show ?thesis by simp\nqed\n\nlemma cat_colim_ex_is_iso_arr:\n  assumes \"u : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m r : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \n    and \"u' : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m r' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  obtains f where \"f : r \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<CC>\\<^esub> r'\" and \"u' = ntcf_const \\<JJ> \\<CC> f \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\"\nproof-\n  interpret u: is_cat_colimit \\<alpha> \\<JJ> \\<CC> \\<FF> r u by (rule assms(1))\n  interpret u': is_cat_colimit \\<alpha> \\<JJ> \\<CC> \\<FF> r' u' by (rule assms(2))\n  obtain f where f: \"f : r' \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>op_cat \\<CC>\\<^esub> r\"\n    and [cat_cs_simps]: \n      \"op_ntcf u' = op_ntcf u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f\"\n    by \n      (\n        elim cat_lim_ex_is_iso_arr[\n          OF u.is_cat_limit_op u'.is_cat_limit_op\n          ]\n      )\n  from f have iso_f: \"f : r \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<CC>\\<^esub> r'\" unfolding cat_op_simps by simp\n  then have f: \"f : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r'\" by auto\n  have \"u' = ntcf_const \\<JJ> \\<CC> f \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\"\n    by (rule eq_op_ntcf_iff[THEN iffD1], insert f)\n      (cs_concl cs_intro: cat_cs_intros cs_simp: cat_cs_simps cat_op_simps)+\n  from iso_f this that show ?thesis by simp\nqed\n\nlemma cat_colim_ex_is_iso_arr':\n  assumes \"u : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m r : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \n    and \"u' : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m r' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  obtains f where \"f : r \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<CC>\\<^esub> r'\"\n    and \"\\<And>j. j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr> \\<Longrightarrow> u'\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = f \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> u\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr>\"\nproof-\n  interpret u: is_cat_colimit \\<alpha> \\<JJ> \\<CC> \\<FF> r u by (rule assms(1))\n  interpret u': is_cat_colimit \\<alpha> \\<JJ> \\<CC> \\<FF> r' u' by (rule assms(2))\n  from assms obtain f \n    where iso_f: \"f : r \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<CC>\\<^esub> r'\" and u'_def: \"u' = ntcf_const \\<JJ> \\<CC> f \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\"\n    by (rule cat_colim_ex_is_iso_arr)\n  then have f: \"f : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r'\" by auto\n  then have \"u'\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = f \\<circ>\\<^sub>A\\<^bsub>\\<CC>\\<^esub> u\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr>\" if \"j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr>\" for j\n    by \n      (\n        intro u.helper_cat_cocone_ntcf_vcomp_Comp[\n          OF u'.is_cat_cocone_axioms f u'_def that\n          ]\n      )\n  with iso_f that show ?thesis by simp\nqed\n\n\nsubsubsection\\<open>Further properties\\<close>\n\nlemma (in is_cat_limit) cat_lim_is_cat_limit_if_is_iso_arr:\n  assumes \"f : r' \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<CC>\\<^esub> r\"\n  shows \"u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\nproof-\n  note f = is_iso_arrD(1)[OF assms(1)]\n  from f(1) interpret u': is_cat_cone \\<alpha> r' \\<JJ> \\<CC> \\<FF> \\<open>u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f\\<close> \n    by (cs_concl cs_intro: cat_lim_cs_intros cat_cs_intros)\n  define \\<beta> where \"\\<beta> = \\<alpha> + \\<omega>\"\n  have \\<beta>: \"\\<Z> \\<beta>\" and \\<alpha>\\<beta>: \"\\<alpha> \\<in>\\<^sub>\\<circ> \\<beta>\"\n    by (simp_all add: \\<beta>_def \\<Z>_Limit_\\<alpha>\\<omega> \\<Z>_\\<omega>_\\<alpha>\\<omega> \\<Z>_def \\<Z>_\\<alpha>_\\<alpha>\\<omega>)\n  then interpret \\<beta>: \\<Z> \\<beta> by simp \n  show ?thesis\n  proof\n    (\n      intro u'.cat_cone_is_cat_limit, \n      rule is_functor.universal_arrow_fo_if_universal_arrow_fo,\n      rule cf_diagonal_is_functor[OF \\<beta> \\<alpha>\\<beta>],\n      rule NTDom.HomDom.category_axioms,\n      rule NTDom.HomCod.category_axioms,\n      rule cat_lim_is_universal_arrow_fo\n    )\n    show \"f : r' \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<CC>\\<^esub> r\" by (rule assms(1))\n    from \\<alpha>\\<beta> f show\n      \"ntcf_arrow (u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f) =\n        umap_fo (\\<Delta>\\<^sub>C\\<^sub>F \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) r (ntcf_arrow u) r'\\<lparr>ArrVal\\<rparr>\\<lparr>f\\<rparr>\"\n      by\n        (\n          cs_concl\n            cs_simp: cat_cs_simps cat_FUNCT_cs_simps\n            cs_intro: cat_cs_intros cat_FUNCT_cs_intros\n        )\n  qed\nqed\n\nlemma (in is_cat_colimit) cat_colim_is_cat_colimit_if_is_iso_arr:\n  assumes \"f : r \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<CC>\\<^esub> r'\" \n  shows \"ntcf_const \\<JJ> \\<CC> f \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m r' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\nproof-\n  note f = is_iso_arrD[OF assms(1)]\n  from f(1) interpret u': is_cat_cocone \\<alpha> r' \\<JJ> \\<CC> \\<FF> \\<open>ntcf_const \\<JJ> \\<CC> f \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\\<close> \n    by (cs_concl cs_intro: cat_lim_cs_intros cat_cs_intros)\n  from f have [symmetric, cat_op_simps]:\n    \"op_ntcf (ntcf_const \\<JJ> \\<CC> f \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u) =\n      op_ntcf u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f\"\n    by\n      (\n        cs_concl cs_shallow \n          cs_simp: cat_op_simps cs_intro: cat_cs_intros cat_op_intros\n      )\n  show ?thesis\n    by \n      (\n        rule is_cat_limit.is_cat_colimit_op\n          [\n            OF is_cat_limit.cat_lim_is_cat_limit_if_is_iso_arr[\n              OF is_cat_limit_op, unfolded cat_op_simps, OF assms(1)\n              ],\n            unfolded cat_op_simps\n          ]\n      )\nqed\n\nlemma ntcf_cf_comp_is_cat_limit_if_is_iso_functor:\n  assumes \"u : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" and \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"u \\<circ>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>C\\<^sub>F \\<GG> : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> \\<circ>\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\nproof(intro is_cat_limitI)\n  interpret u: is_cat_limit \\<alpha> \\<BB> \\<CC> \\<FF> r u by (rule assms(1)) \n  interpret \\<GG>: is_iso_functor \\<alpha> \\<AA> \\<BB> \\<GG> by (rule assms(2))\n  note [cf_cs_simps] = is_iso_functor_is_iso_arr(2,3)\n  show u\\<GG>: \"u \\<circ>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>C\\<^sub>F \\<GG> : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> \\<circ>\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    by (intro is_cat_coneI)\n      (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n  fix u' r' assume prems: \"u' : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> \\<circ>\\<^sub>C\\<^sub>F \\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  then interpret u': is_cat_cone \\<alpha> r' \\<AA> \\<CC> \\<open>\\<FF> \\<circ>\\<^sub>C\\<^sub>F \\<GG>\\<close> u' by simp\n  have \"u' \\<circ>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>C\\<^sub>F inv_cf \\<GG> : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    by (intro is_cat_coneI)\n      (\n        cs_concl\n          cs_simp: cat_cs_simps cf_cs_simps\n          cs_intro: cat_cs_intros cf_cs_intros\n      )\n  from is_cat_limit.cat_lim_ua_fo[OF assms(1) this] obtain f \n    where f: \"f : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r\"\n      and u'_\\<GG>: \"u' \\<circ>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>C\\<^sub>F inv_cf \\<GG> = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<BB> \\<CC> f\"\n      and f'f:\n        \"\\<lbrakk>\n          f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r; \n          u' \\<circ>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>C\\<^sub>F inv_cf \\<GG> = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<BB> \\<CC> f' \n         \\<rbrakk> \\<Longrightarrow> f' = f\"\n    for f'\n    by metis\n  from u'_\\<GG> have u'_inv\\<GG>_\\<GG>:\n    \"(u' \\<circ>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>C\\<^sub>F inv_cf \\<GG>) \\<circ>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>C\\<^sub>F \\<GG> = (u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<BB> \\<CC> f) \\<circ>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>C\\<^sub>F \\<GG>\"\n    by simp\n  show \"\\<exists>!f'. f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r \\<and> u' = u \\<circ>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>C\\<^sub>F \\<GG> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<AA> \\<CC> f'\"\n  proof(intro ex1I conjI; (elim conjE)?)\n    show \"f : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r\" by (rule f)\n    from u'_inv\\<GG>_\\<GG> f show \"u' = u \\<circ>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>C\\<^sub>F \\<GG> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<AA> \\<CC> f\"\n      by\n        (\n          cs_prems \n            cs_simp:\n              cf_cs_simps cat_cs_simps\n              ntcf_cf_comp_ntcf_cf_comp_assoc \n              ntcf_vcomp_ntcf_cf_comp[symmetric]\n            cs_intro: cat_cs_intros cf_cs_intros\n        )\n    fix f' assume prems:\n      \"f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r\" \"u' = u \\<circ>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>C\\<^sub>F \\<GG> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<AA> \\<CC> f'\"\n    from prems(2) have \n      \"u' \\<circ>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>C\\<^sub>F inv_cf \\<GG> = \n        (u \\<circ>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>C\\<^sub>F \\<GG> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<AA> \\<CC> f') \\<circ>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>C\\<^sub>F inv_cf \\<GG>\"\n      by simp\n    from this f prems(1) have \"u' \\<circ>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>C\\<^sub>F inv_cf \\<GG> = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<BB> \\<CC> f'\"\n      by\n        (\n          cs_prems \n            cs_simp:\n              cat_cs_simps cf_cs_simps\n              ntcf_vcomp_ntcf_cf_comp[symmetric]\n              ntcf_cf_comp_ntcf_cf_comp_assoc\n            cs_intro: cf_cs_intros cat_cs_intros\n        )\n    then show \"f' = f\" by (intro f'f prems(1))\n  qed\nqed\n\nlemma ntcf_cf_comp_is_cat_limit_if_is_iso_functor'[cat_lim_cs_intros]:\n  assumes \"u : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<BB> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \n    and \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"\\<AA>' = \\<FF> \\<circ>\\<^sub>C\\<^sub>F \\<GG>\"\n  shows \"u \\<circ>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>C\\<^sub>F \\<GG> : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<AA>' : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  using assms(1,2) \n  unfolding assms(3)\n  by (rule ntcf_cf_comp_is_cat_limit_if_is_iso_functor)\n\n\n\nsubsection\\<open>Small limit and small colimit\\<close>\n\n\nsubsubsection\\<open>Definition and elementary properties\\<close>\n\n\ntext\\<open>\nThe concept of a limit is introduced in Chapter III-4 in\n\\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>; the concept of a colimit is introduced in\nChapter III-3 in \\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>. The definitions of small\nlimits were tailored for ZFC in HOL.\n\\<close>\n\nlocale is_tm_cat_limit = is_tm_cat_cone \\<alpha> r \\<JJ> \\<CC> \\<FF> u for \\<alpha> \\<JJ> \\<CC> \\<FF> r u + \n  assumes tm_cat_lim_ua_fo: \n    \"\\<And>u' r'. u' : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC> \\<Longrightarrow>\n      \\<exists>!f'. f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r \\<and> u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f'\"\n\nsyntax \"_is_tm_cat_limit\" :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> bool\"\n  (\\<open>(_ :/ _ <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m _ :/ _ \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<index> _)\\<close> [51, 51, 51, 51, 51] 51)\ntranslations \"u : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \\<rightleftharpoons> \n  \"CONST is_tm_cat_limit \\<alpha> \\<JJ> \\<CC> \\<FF> r u\"\n\nlocale is_tm_cat_colimit = is_tm_cat_cocone \\<alpha> r \\<JJ> \\<CC> \\<FF> u for \\<alpha> \\<JJ> \\<CC> \\<FF> r u +\n  assumes tm_cat_colim_ua_of: \n    \"\\<And>u' r'. u' : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e r' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC> \\<Longrightarrow>\n      \\<exists>!f'. f' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r' \\<and> u' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\"\n\nsyntax \"_is_tm_cat_colimit\" :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> bool\"\n  (\\<open>(_ :/ _ >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m _ :/ _ \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<index> _)\\<close> [51, 51, 51, 51, 51] 51)\ntranslations \"u : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m r : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \\<rightleftharpoons> \n  \"CONST is_tm_cat_colimit \\<alpha> \\<JJ> \\<CC> \\<FF> r u\"\n\n\ntext\\<open>Rules.\\<close>\n\nlemma (in is_tm_cat_limit) is_tm_cat_limit_axioms'[cat_lim_cs_intros]:\n  assumes \"\\<alpha>' = \\<alpha>\" and \"r' = r\" and \"\\<JJ>' = \\<JJ>\" and \"\\<CC>' = \\<CC>\" and \"\\<FF>' = \\<FF>\"\n  shows \"u : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF>' : \\<JJ>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>'\\<^esub> \\<CC>'\"\n  unfolding assms by (rule is_tm_cat_limit_axioms)\n\nmk_ide rf is_tm_cat_limit_def[unfolded is_tm_cat_limit_axioms_def]\n  |intro is_tm_cat_limitI|\n  |dest is_tm_cat_limitD[dest]|\n  |elim is_tm_cat_limitE[elim]|\n\nlemmas [cat_lim_cs_intros] = is_tm_cat_limitD(1)\n\nlemma (in is_tm_cat_colimit) is_tm_cat_colimit_axioms'[cat_lim_cs_intros]:\n  assumes \"\\<alpha>' = \\<alpha>\" and \"r' = r\" and \"\\<JJ>' = \\<JJ>\" and \"\\<CC>' = \\<CC>\" and \"\\<FF>' = \\<FF>\"\n  shows \"u : \\<FF>' >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m r' : \\<JJ>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>'\\<^esub> \\<CC>'\"\n  unfolding assms by (rule is_tm_cat_colimit_axioms)\n\nmk_ide rf is_tm_cat_colimit_def[unfolded is_tm_cat_colimit_axioms_def]\n  |intro is_tm_cat_colimitI|\n  |dest is_tm_cat_colimitD[dest]|\n  |elim is_tm_cat_colimitE[elim]|\n\nlemmas [cat_lim_cs_intros] = is_tm_cat_colimitD(1)\n\nlemma is_tm_cat_limitI':\n  assumes \"u : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<And>u' r'. u' : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC> \\<Longrightarrow>\n      \\<exists>!f'. f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r \\<and> u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f'\"\n  shows \"u : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\nproof(rule is_tm_cat_limitI, rule assms(1))\n  interpret is_tm_cat_cone \\<alpha> r \\<JJ> \\<CC> \\<FF> u by (rule assms(1))  \n  fix r' u' assume prems: \"u' : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  then interpret u': is_cat_cone \\<alpha> r' \\<JJ> \\<CC> \\<FF> u' . \n  have \"u' : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    by\n      (\n        intro\n          is_tm_cat_coneI \n          NTCod.is_tm_functor_axioms\n          u'.cat_cone_obj \n          u'.is_ntcf_axioms\n      )\n  then show \"\\<exists>!f'. f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r \\<and> u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f'\"\n    by (rule assms(2))\nqed\n\nlemma is_tm_cat_colimitI':\n  assumes \"u : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e r : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    and \"\\<And>u' r'. u' : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e r' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC> \\<Longrightarrow>\n      \\<exists>!f'. f' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r' \\<and> u' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\"\n  shows \"u : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m r : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\nproof(intro is_tm_cat_colimitI, rule assms(1))\n  interpret is_tm_cat_cocone \\<alpha> r \\<JJ> \\<CC> \\<FF> u by (rule assms(1))\n  fix r' u' assume prems: \"u' : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e r' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  then interpret u': is_cat_cocone \\<alpha> r' \\<JJ> \\<CC> \\<FF> u' . \n  have \"u' : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e r' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    by\n      (\n        intro\n          is_tm_cat_coconeI \n          NTDom.is_tm_functor_axioms\n          u'.cat_cocone_obj \n          u'.is_ntcf_axioms\n      )\n  then show \"\\<exists>!f'. f' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r' \\<and> u' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\"\n    by (rule assms(2))\nqed\n\n\ntext\\<open>Elementary properties.\\<close>\n\nsublocale is_tm_cat_limit \\<subseteq> is_cat_limit\n  by (intro is_cat_limitI, rule is_cat_cone_axioms, rule tm_cat_lim_ua_fo)\n\nsublocale is_tm_cat_colimit \\<subseteq> is_cat_colimit\n  by (intro is_cat_colimitI, rule is_cat_cocone_axioms, rule tm_cat_colim_ua_of)\n\nlemma (in is_cat_limit) cat_lim_is_tm_cat_limit:\n  assumes \"\\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"u : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \nproof(intro is_tm_cat_limitI)\n  interpret \\<FF>: is_tm_functor \\<alpha> \\<JJ> \\<CC> \\<FF> by (rule assms) \n  show \"u : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    by (intro is_tm_cat_coneI assms is_ntcf_axioms cat_cone_obj)\n  fix u' r' assume prems: \"u' : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  show \"\\<exists>!f'. f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r \\<and> u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f'\"\n    by (rule cat_lim_ua_fo[OF prems])\nqed\n\nlemma (in is_cat_colimit) cat_colim_is_tm_cat_colimit:\n  assumes \"\\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  shows \"u : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m r : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \nproof(intro is_tm_cat_colimitI)\n  interpret \\<FF>: is_tm_functor \\<alpha> \\<JJ> \\<CC> \\<FF> by (rule assms) \n  show \"u : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e r : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n    by (intro is_tm_cat_coconeI assms is_ntcf_axioms cat_cocone_obj)\n  fix u' r' assume prems: \"u' : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e r' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n  show \"\\<exists>!f'. f' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r' \\<and> u' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\"\n    by (rule cat_colim_ua_of[OF prems])\nqed\n\n\ntext\\<open>Limits, colimits and universal arrows.\\<close>\n\nlemma (in is_tm_cat_limit) tm_cat_lim_is_universal_arrow_fo:\n  \"universal_arrow_fo (\\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) r (ntcf_arrow u)\"\nproof(intro is_functor.universal_arrow_foI)\n\n  show \"\\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC> : \\<CC> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> cat_Funct \\<alpha> \\<JJ> \\<CC>\"\n    by \n      (\n        intro \n          tm_cf_diagonal_is_functor \n          NTCod.HomDom.tiny_category_axioms\n          NTDom.HomCod.category_axioms\n      )\n\n  show \"r \\<in>\\<^sub>\\<circ> \\<CC>\\<lparr>Obj\\<rparr>\" by (intro cat_cone_obj)\n  then show \"ntcf_arrow u : \\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> \\<mapsto>\\<^bsub>cat_Funct \\<alpha> \\<JJ> \\<CC>\\<^esub> cf_map \\<FF>\"\n    by \n      (\n        cs_concl\n          cs_simp: cat_cs_simps \n          cs_intro: cat_small_cs_intros cat_cs_intros cat_FUNCT_cs_intros\n      )\n\n  fix r' u' assume prems: \n    \"r' \\<in>\\<^sub>\\<circ> \\<CC>\\<lparr>Obj\\<rparr>\" \"u' : \\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr> \\<mapsto>\\<^bsub>cat_Funct \\<alpha> \\<JJ> \\<CC>\\<^esub> cf_map \\<FF>\"\n  from prems(1) have [cat_cs_simps]: \n    \"cf_of_cf_map \\<JJ> \\<CC> (cf_map \\<FF>) = \\<FF>\"\n    \"cf_of_cf_map \\<JJ> \\<CC> (cf_map (cf_const \\<JJ> \\<CC> r')) = cf_const \\<JJ> \\<CC> r'\"\n    by (cs_concl cs_simp: cat_FUNCT_cs_simps cs_intro: cat_cs_intros)+\n  from prems(2,1) have \n    \"u' : cf_map (cf_const \\<JJ> \\<CC> r') \\<mapsto>\\<^bsub>cat_Funct \\<alpha> \\<JJ> \\<CC>\\<^esub> cf_map \\<FF>\"\n    by (cs_prems cs_shallow cs_simp: cat_cs_simps)\n  note u'[unfolded cat_cs_simps] = cat_Funct_is_arrD[OF this]\n\n  from \n    tm_cat_lim_ua_fo[\n      OF is_cat_coneI[OF is_tm_ntcfD(1)[OF u'(1)] prems(1)]\n      ] \n  obtain f \n    where f: \"f : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r\"\n      and [symmetric, cat_cs_simps]: \n        \"ntcf_of_ntcf_arrow \\<JJ> \\<CC> u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f\"\n      and f_unique: \n        \"\\<lbrakk>\n          f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r;\n          ntcf_of_ntcf_arrow \\<JJ> \\<CC> u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f'\n         \\<rbrakk> \\<Longrightarrow> f' = f\"\n    for f'\n    by metis\n\n  show \"\\<exists>!f'.\n    f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r \\<and>\n    u' = umap_fo (\\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) r (ntcf_arrow u) r'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\n  proof(intro ex1I conjI; (elim conjE)?)\n    show \"f : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r\" by (rule f)\n    with cat_cone_obj show u'_def: \n      \"u' = umap_fo (\\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m  \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) r (ntcf_arrow u) r'\\<lparr>ArrVal\\<rparr>\\<lparr>f\\<rparr>\"\n      by \n        (\n          cs_concl \n            cs_simp: u'(2)[symmetric] cat_cs_simps cat_FUNCT_cs_simps \n            cs_intro: cat_small_cs_intros cat_cs_intros cat_FUNCT_cs_intros\n        )\n    fix f' assume prems': \n      \"f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r\"\n      \"u' = umap_fo (\\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) r (ntcf_arrow u) r'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\n    from prems'(2) f prems' cat_cone_obj have u'_def':\n      \"u' = ntcf_arrow (u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f')\"\n      by\n        (\n          cs_prems\n            cs_simp: cat_cs_simps cat_FUNCT_cs_simps\n            cs_intro: cat_small_cs_intros cat_cs_intros cat_FUNCT_cs_intros\n        )\n    from prems'(1) have \"ntcf_of_ntcf_arrow \\<JJ> \\<CC> u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f'\"\n      by (cs_concl cs_simp: cat_FUNCT_cs_simps u'_def' cs_intro: cat_cs_intros)\n    from f_unique[OF prems'(1) this] show \"f' = f\" .\n\n  qed\n\nqed\n\nlemma (in is_tm_cat_cone) tm_cat_cone_is_tm_cat_limit:\n  assumes \"universal_arrow_fo (\\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) c (ntcf_arrow \\<NN>)\"\n  shows \"\\<NN> : c <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\nproof(intro is_tm_cat_limitI' is_tm_cat_cone_axioms)\n\n  fix u' c' assume prems: \"u' : c' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n\n  interpret u': is_tm_cat_cone \\<alpha> c' \\<JJ> \\<CC> \\<FF> u' by (rule prems)\n\n  from u'.tm_cat_cone_obj have u'_is_arr:\n    \"ntcf_arrow u' : \\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>\\<lparr>ObjMap\\<rparr>\\<lparr>c'\\<rparr> \\<mapsto>\\<^bsub>cat_Funct \\<alpha> \\<JJ> \\<CC>\\<^esub> cf_map \\<FF>\"\n    by\n      (\n        cs_concl\n          cs_simp: cat_cs_simps\n          cs_intro: cat_small_cs_intros cat_cs_intros cat_FUNCT_cs_intros\n      )\n\n  from is_functor.universal_arrow_foD(3)\n    [\n      OF\n        tm_cf_diagonal_is_functor[\n          OF NTCod.HomDom.tiny_category_axioms NTDom.HomCod.category_axioms\n          ]\n        assms\n        u'.cat_cone_obj\n        u'_is_arr\n    ]\n  obtain f where f: \"f : c' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c\"\n    and u'_def': \"ntcf_arrow u' =\n      umap_fo (\\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) c (ntcf_arrow \\<NN>) c'\\<lparr>ArrVal\\<rparr>\\<lparr>f\\<rparr>\"\n    and f'_unique:\n      \"\\<lbrakk>\n        f' : c' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c;\n        ntcf_arrow u' =\n          umap_fo (\\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) c (ntcf_arrow \\<NN>) c'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\n       \\<rbrakk> \\<Longrightarrow> f' = f\"\n    for f'\n    by metis\n\n  from u'_def' f cat_cone_obj have u'_def: \"u' = \\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f\"\n    by\n      (\n        cs_prems \n          cs_simp: cat_cs_simps cat_FUNCT_cs_simps \n          cs_intro: cat_small_cs_intros cat_cs_intros cat_FUNCT_cs_intros\n      )\n\n  show \"\\<exists>!f'. f' : c' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c \\<and> u' = \\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f'\"\n  proof(intro ex1I conjI; (elim conjE)?, (rule f)?, (rule u'_def)?)\n    fix f'' assume prems': \n      \"f'' : c' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c\" \"u' = \\<NN> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f''\"\n    from prems' have \n      \"ntcf_arrow u' =\n        umap_fo (\\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) c (ntcf_arrow \\<NN>) c'\\<lparr>ArrVal\\<rparr>\\<lparr>f''\\<rparr>\"\n      by\n        (\n          cs_concl \n            cs_simp: cat_cs_simps cat_FUNCT_cs_simps \n            cs_intro: cat_small_cs_intros cat_cs_intros cat_FUNCT_cs_intros\n        )\n    from f'_unique[OF prems'(1) this] show \"f'' = f\".\n  qed\n\nqed\n\nlemma (in is_tm_cat_colimit) tm_cat_colim_is_universal_arrow_of:\n  \"universal_arrow_of (\\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) r (ntcf_arrow u)\"\nproof(intro is_functor.universal_arrow_ofI)\n\n  show \"\\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC> : \\<CC> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> cat_Funct \\<alpha> \\<JJ> \\<CC>\"\n    by \n      (\n        intro \n          tm_cf_diagonal_is_functor \n          NTDom.HomDom.tiny_category_axioms \n          NTDom.HomCod.category_axioms\n      )\n\n  show \"r \\<in>\\<^sub>\\<circ> \\<CC>\\<lparr>Obj\\<rparr>\" by (intro cat_cocone_obj)\n\n  then show \"ntcf_arrow u : cf_map \\<FF> \\<mapsto>\\<^bsub>cat_Funct \\<alpha> \\<JJ> \\<CC>\\<^esub> \\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\"\n    by \n      (\n        cs_concl cs_shallow\n          cs_simp: cat_cs_simps\n          cs_intro: cat_small_cs_intros cat_cs_intros cat_FUNCT_cs_intros\n      )\n\n  fix r' u' assume prems: \n    \"r' \\<in>\\<^sub>\\<circ> \\<CC>\\<lparr>Obj\\<rparr>\" \"u' : cf_map \\<FF> \\<mapsto>\\<^bsub>cat_Funct \\<alpha> \\<JJ> \\<CC>\\<^esub> \\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr>\"\n  from prems(1) have [cat_cs_simps]: \n    \"cf_of_cf_map \\<JJ> \\<CC> (cf_map \\<FF>) = \\<FF>\"\n    \"cf_of_cf_map \\<JJ> \\<CC> (cf_map (cf_const \\<JJ> \\<CC> r')) = cf_const \\<JJ> \\<CC> r'\"\n    by (cs_concl cs_simp: cat_FUNCT_cs_simps cs_intro: cat_cs_intros)+\n  from prems(2,1) have\n    \"u' : cf_map \\<FF> \\<mapsto>\\<^bsub>cat_Funct \\<alpha> \\<JJ> \\<CC>\\<^esub> cf_map (cf_const \\<JJ> \\<CC> r')\"\n    by (cs_prems cs_shallow cs_simp: cat_cs_simps)\n  note u'[unfolded cat_cs_simps] = cat_Funct_is_arrD[OF this]\n\n  from cat_colim_ua_of[OF is_cat_coconeI[OF is_tm_ntcfD(1)[OF u'(1)] prems(1)]]\n  obtain f \n    where f: \"f : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r'\"\n      and [symmetric, cat_cs_simps]: \n        \"ntcf_of_ntcf_arrow \\<JJ> \\<CC> u' = ntcf_const \\<JJ> \\<CC> f \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\"\n      and f_unique:\n        \"\\<lbrakk>\n          f' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r';\n          ntcf_of_ntcf_arrow \\<JJ> \\<CC> u' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\n         \\<rbrakk> \\<Longrightarrow> f' = f\"\n    for f'\n    by metis\n\n  show \" \\<exists>!f'.\n    f' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r' \\<and>\n    u' = umap_of (\\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) r (ntcf_arrow u) r'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\n  proof(intro ex1I conjI; (elim conjE)?)\n  \n    show \"f : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r'\" by (rule f)\n\n    with cat_cocone_obj show u'_def:\n      \"u' = umap_of (\\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) r (ntcf_arrow u) r'\\<lparr>ArrVal\\<rparr>\\<lparr>f\\<rparr>\"\n      by \n        (\n          cs_concl\n            cs_simp: u'(2)[symmetric] cat_cs_simps cat_FUNCT_cs_simps \n            cs_intro: cat_small_cs_intros cat_cs_intros cat_FUNCT_cs_intros\n        )\n  \n    fix f' assume prems':\n      \"f' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r'\"\n      \"u' = umap_of (\\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) r (ntcf_arrow u) r'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\"\n    from prems'(2) f prems' cat_cocone_obj have u'_def':\n      \"u' = ntcf_arrow (ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u)\"\n      by\n        (\n          cs_prems\n            cs_simp: cat_cs_simps cat_FUNCT_cs_simps\n            cs_intro: cat_small_cs_intros cat_cs_intros cat_FUNCT_cs_intros\n        )\n    from prems'(1) have \"ntcf_of_ntcf_arrow \\<JJ> \\<CC> u' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\"\n      by \n        (\n          cs_concl cs_shallow \n            cs_simp: cat_FUNCT_cs_simps u'_def' cs_intro: cat_cs_intros\n        )\n    from f_unique[OF prems'(1) this] show \"f' = f\" .\n\n  qed\n\nqed\n\nlemma (in is_tm_cat_cocone) tm_cat_cocone_is_tm_cat_colimit:\n  assumes \"universal_arrow_of (\\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) c (ntcf_arrow \\<NN>)\"\n  shows \"\\<NN> : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m c : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\nproof(intro is_tm_cat_colimitI' is_tm_cat_cocone_axioms)\n  \n  fix u' c' assume prems: \"u' : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e c' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\n\n  interpret u': is_tm_cat_cocone \\<alpha> c' \\<JJ> \\<CC> \\<FF> u' by (rule prems)\n\n  from u'.tm_cat_cocone_obj have u'_is_arr:\n    \"ntcf_arrow u' : cf_map \\<FF> \\<mapsto>\\<^bsub>cat_Funct \\<alpha> \\<JJ> \\<CC>\\<^esub> \\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>\\<lparr>ObjMap\\<rparr>\\<lparr>c'\\<rparr>\"\n    by\n      (\n        cs_concl cs_shallow\n          cs_simp: cat_cs_simps\n          cs_intro: cat_small_cs_intros cat_cs_intros cat_FUNCT_cs_intros\n      )\n\n  from is_functor.universal_arrow_ofD(3)\n    [\n      OF\n        tm_cf_diagonal_is_functor[\n          OF NTDom.HomDom.tiny_category_axioms NTDom.HomCod.category_axioms\n          ]\n        assms\n        u'.cat_cocone_obj\n        u'_is_arr\n    ]\n  obtain f where f: \"f : c \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c'\"\n    and u'_def': \"ntcf_arrow u' =\n      umap_of (\\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) c (ntcf_arrow \\<NN>) c'\\<lparr>ArrVal\\<rparr>\\<lparr>f\\<rparr>\"\n    and f'_unique:\n      \"\\<lbrakk>\n        f' : c \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c';\n        ntcf_arrow u' =\n          umap_of (\\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) c (ntcf_arrow \\<NN>) c'\\<lparr>ArrVal\\<rparr>\\<lparr>f'\\<rparr>\n       \\<rbrakk> \\<Longrightarrow> f' = f\"\n    for f'\n    by metis\n\n  from u'_def' f cat_cocone_obj have u'_def: \"u' = ntcf_const \\<JJ> \\<CC> f \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<NN>\"\n    by\n      (\n        cs_prems\n          cs_simp: cat_cs_simps cat_FUNCT_cs_simps\n          cs_intro: cat_small_cs_intros cat_cs_intros cat_FUNCT_cs_intros\n      )\n  \n  show \"\\<exists>!f'. f' : c \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c' \\<and> u' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<NN>\"\n  proof(intro ex1I conjI; (elim conjE)?, (rule f)?, (rule u'_def)?)\n    fix f'' assume prems': \n      \"f'' : c \\<mapsto>\\<^bsub>\\<CC>\\<^esub> c'\" \"u' = ntcf_const \\<JJ> \\<CC> f'' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<NN>\"\n    from prems' have \n      \"ntcf_arrow u' =\n        umap_of (\\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) c (ntcf_arrow \\<NN>) c'\\<lparr>ArrVal\\<rparr>\\<lparr>f''\\<rparr>\"\n      by\n        (\n          cs_concl\n            cs_simp: cat_cs_simps cat_FUNCT_cs_simps\n            cs_intro: cat_small_cs_intros cat_cs_intros cat_FUNCT_cs_intros\n        )\n    from f'_unique[OF prems'(1) this] show \"f'' = f\".\n  qed\n\nqed\n  \n\ntext\\<open>Duality.\\<close>\n\nlemma (in is_tm_cat_limit) is_tm_cat_colimit_op:\n  \"op_ntcf u : op_cf \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m r : op_cat \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> op_cat \\<CC>\"\nproof(intro is_tm_cat_colimitI')\n  show \"op_ntcf u : op_cf \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e r : op_cat \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> op_cat \\<CC>\"\n    by (cs_concl cs_shallow cs_simp: cs_intro: cat_op_intros)\n  fix u' r' assume prems: \n    \"u' : op_cf \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e r' : op_cat \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> op_cat \\<CC>\"\n  interpret u': is_tm_cat_cocone \\<alpha> r' \\<open>op_cat \\<JJ>\\<close> \\<open>op_cat \\<CC>\\<close> \\<open>op_cf \\<FF>\\<close> u' \n    by (rule prems)\n  from tm_cat_lim_ua_fo[OF u'.is_cat_cone_op[unfolded cat_op_simps]] obtain f \n    where f: \"f : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r\"\n      and op_u'_def: \"op_ntcf u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f\"\n      and f_unique: \n        \"\\<lbrakk> f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r; op_ntcf u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f' \\<rbrakk> \\<Longrightarrow>\n          f' = f\"\n    for f'\n    by metis\n  from op_u'_def have \"op_ntcf (op_ntcf u') = op_ntcf (u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f)\"\n    by simp\n  from this f have u'_def: \n    \"u' = ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F op_ntcf u\"\n    by (cs_prems cs_simp: cat_op_simps cs_intro: cat_cs_intros)\n  show \"\\<exists>!f'. \n    f' : r \\<mapsto>\\<^bsub>op_cat \\<CC>\\<^esub> r' \\<and> \n    u' = ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F op_ntcf u\"\n  proof(intro ex1I conjI; (elim conjE)?, (unfold cat_op_simps)?)\n    fix f' assume prems': \n      \"f' : r' \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r\"\n      \"u' = ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F op_ntcf u\"\n    from prems'(2) have \"op_ntcf u' =\n      op_ntcf (ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F op_ntcf u)\"\n      by simp\n    from this prems'(1) have \"op_ntcf u' = u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f'\"\n      by\n        (\n          cs_prems\n            cs_simp: cat_cs_simps cat_op_simps \n            cs_intro: cat_cs_intros cat_op_intros\n        )\n    from f_unique[OF prems'(1) this] show \"f' = f\". \n  qed (intro u'_def f)+\nqed\n\nlemma (in is_tm_cat_limit) is_tm_cat_colimit_op'[cat_op_intros]:\n  assumes \"\\<FF>' = op_cf \\<FF>\" and \"\\<JJ>' = op_cat \\<JJ>\" and \"\\<CC>' = op_cat \\<CC>\"\n  shows \"op_ntcf u : \\<FF>' >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m r : \\<JJ>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>'\"\n  unfolding assms by (rule is_tm_cat_colimit_op)\n\nlemmas [cat_op_intros] = is_tm_cat_limit.is_tm_cat_colimit_op'\n\nlemma (in is_tm_cat_colimit) is_tm_cat_limit_op:\n  \"op_ntcf u : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m op_cf \\<FF> : op_cat \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> op_cat \\<CC>\"\nproof(intro is_tm_cat_limitI')\n  show \"op_ntcf u : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e op_cf \\<FF> : op_cat \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> op_cat \\<CC>\"\n    by (cs_concl cs_shallow cs_simp: cs_intro: cat_op_intros)\n  fix u' r' assume prems: \n    \"u' : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e op_cf \\<FF> : op_cat \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> op_cat \\<CC>\"\n  interpret u': is_tm_cat_cone \\<alpha> r' \\<open>op_cat \\<JJ>\\<close> \\<open>op_cat \\<CC>\\<close> \\<open>op_cf \\<FF>\\<close> u' \n    by (rule prems)\n  from tm_cat_colim_ua_of[OF u'.is_cat_cocone_op[unfolded cat_op_simps]] obtain f \n    where f: \"f : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r'\"\n      and op_u'_def: \"op_ntcf u' = ntcf_const \\<JJ> \\<CC> f \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\"\n      and f_unique: \n        \"\\<lbrakk> f' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r'; op_ntcf u' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u \\<rbrakk> \\<Longrightarrow> f' = f\"\n    for f'\n    by metis\n  from op_u'_def have \"op_ntcf (op_ntcf u') = op_ntcf (ntcf_const \\<JJ> \\<CC> f \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u)\"\n    by simp\n  from this f have u'_def: \n    \"u' = op_ntcf u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f\"\n    by (cs_prems cs_simp: cat_op_simps cs_intro: cat_cs_intros)\n  show \"\\<exists>!f'. \n    f' : r' \\<mapsto>\\<^bsub>op_cat \\<CC>\\<^esub> r \\<and> \n    u' = op_ntcf u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f'\"\n  proof(intro ex1I conjI; (elim conjE)?, (unfold cat_op_simps)?)\n    fix f' assume prems': \n      \"f' : r \\<mapsto>\\<^bsub>\\<CC>\\<^esub> r'\"\n      \"u' = op_ntcf u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f'\"\n    from prems'(2) have \"op_ntcf u' =\n      op_ntcf (op_ntcf u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f')\"\n      by simp\n    from this prems'(1) have \"op_ntcf u' = ntcf_const \\<JJ> \\<CC> f' \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\"\n      by\n        (\n          cs_prems\n            cs_simp: cat_cs_simps cat_op_simps \n            cs_intro: cat_cs_intros cat_op_intros\n        )\n    from f_unique[OF prems'(1) this] show \"f' = f\". \n  qed (intro u'_def f)+\nqed\n\nlemma (in is_tm_cat_colimit) is_tm_cat_colimit_op'[cat_op_intros]:\n  assumes \"\\<FF>' = op_cf \\<FF>\" and \"\\<JJ>' = op_cat \\<JJ>\" and \"\\<CC>' = op_cat \\<CC>\"\n  shows \"op_ntcf u : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF>' : \\<JJ>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>'\"\n  unfolding assms by (rule is_tm_cat_limit_op)\n\nlemmas [cat_op_intros] = is_tm_cat_colimit.is_tm_cat_colimit_op'\n\n\nsubsubsection\\<open>Further properties\\<close>\n\nlemma (in is_tm_cat_limit) tm_cat_lim_is_tm_cat_limit_if_iso_arr:\n  assumes \"f : r' \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<CC>\\<^esub> r\"\n  shows \"u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\nproof-\n  note f = is_iso_arrD(1)[OF assms]\n  from f(1) interpret u': is_tm_cat_cone \\<alpha> r' \\<JJ> \\<CC> \\<FF> \\<open>u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f\\<close> \n    by (cs_concl cs_intro: cat_small_cs_intros cat_cs_intros)\n  show ?thesis\n  proof\n    (\n      intro u'.tm_cat_cone_is_tm_cat_limit,\n      rule is_functor.universal_arrow_fo_if_universal_arrow_fo,\n      rule tm_cf_diagonal_is_functor,\n      rule NTCod.HomDom.tiny_category_axioms,\n      rule NTDom.HomCod.category_axioms,\n      rule tm_cat_lim_is_universal_arrow_fo\n    )\n    show \"f : r' \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<CC>\\<^esub> r\" by (rule assms)\n    from f show \"ntcf_arrow (u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<CC> f) =\n      umap_fo (\\<Delta>\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m \\<alpha> \\<JJ> \\<CC>) (cf_map \\<FF>) r (ntcf_arrow u) r'\\<lparr>ArrVal\\<rparr>\\<lparr>f\\<rparr>\"\n      by\n        (\n          cs_concl\n            cs_simp: cat_cs_simps cat_FUNCT_cs_simps \n            cs_intro: cat_small_cs_intros cat_cs_intros cat_FUNCT_cs_intros\n        )\n  qed\nqed\n\nlemma (in is_tm_cat_colimit) tm_cat_colim_is_tm_cat_colimit_if_iso_arr:\n  assumes \"f : r \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<CC>\\<^esub> r'\"\n  shows \"ntcf_const \\<JJ> \\<CC> f \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>t\\<^sub>m\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m r' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<CC>\"\nproof-\n  note f = is_iso_arrD(1)[OF assms]\n  from f(1) interpret u': \n    is_tm_cat_cocone \\<alpha> r' \\<JJ> \\<CC> \\<FF> \\<open>ntcf_const \\<JJ> \\<CC> f \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u\\<close> \n    by (cs_concl cs_intro: cat_small_cs_intros cat_cs_intros)\n  from f have [symmetric, cat_op_simps]:\n    \"op_ntcf (ntcf_const \\<JJ> \\<CC> f \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F u) =\n      op_ntcf u \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const (op_cat \\<JJ>) (op_cat \\<CC>) f\"\n    by\n      (\n        cs_concl cs_shallow \n          cs_simp: cat_op_simps cs_intro: cat_cs_intros cat_op_intros\n      )\n  show ?thesis\n    by \n      (\n        rule is_tm_cat_limit.is_tm_cat_colimit_op\n          [\n            OF is_tm_cat_limit.tm_cat_lim_is_tm_cat_limit_if_iso_arr[\n              OF is_tm_cat_limit_op, unfolded cat_op_simps, OF assms(1)\n              ],\n            unfolded cat_op_simps\n          ]\n      )\nqed\n\n\n\nsubsection\\<open>Finite limit and finite colimit\\<close>\n\nlocale is_cat_finite_limit = \n  is_cat_limit \\<alpha> \\<JJ> \\<CC> \\<FF> r u + NTDom.HomDom: finite_category \\<alpha> \\<JJ>\n  for \\<alpha> \\<JJ> \\<CC> \\<FF> r u\n\nsyntax \"_is_cat_finite_limit\" :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> bool\"\n  (\\<open>(_ :/ _ <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m\\<^sub>.\\<^sub>f\\<^sub>i\\<^sub>n _ :/ _ \\<mapsto>\\<mapsto>\\<^sub>C\\<index> _)\\<close> [51, 51, 51, 51, 51] 51)\ntranslations \"u : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m\\<^sub>.\\<^sub>f\\<^sub>i\\<^sub>n \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \\<rightleftharpoons> \n  \"CONST is_cat_finite_limit \\<alpha> \\<JJ> \\<CC> \\<FF> r u\"\n\nlocale is_cat_finite_colimit = \n  is_cat_colimit \\<alpha> \\<JJ> \\<CC> \\<FF> r u + NTDom.HomDom: finite_category \\<alpha> \\<JJ>\n  for \\<alpha> \\<JJ> \\<CC> \\<FF> r u\n\nsyntax \"_is_cat_finite_colimit\" :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> bool\"\n  (\\<open>(_ :/ _ >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m\\<^sub>.\\<^sub>f\\<^sub>i\\<^sub>n _ :/ _ \\<mapsto>\\<mapsto>\\<^sub>C\\<index> _)\\<close> [51, 51, 51, 51, 51] 51)\ntranslations \"u : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m\\<^sub>.\\<^sub>f\\<^sub>i\\<^sub>n r : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>\" \\<rightleftharpoons> \n  \"CONST is_cat_finite_colimit \\<alpha> \\<JJ> \\<CC> \\<FF> r u\"\n\n\ntext\\<open>Rules.\\<close>\n\nlemma (in is_cat_finite_limit) is_cat_finite_limit_axioms'[cat_lim_cs_intros]:\n  assumes \"\\<alpha>' = \\<alpha>\" and \"r' = r\" and \"\\<JJ>' = \\<JJ>\" and \"\\<CC>' = \\<CC>\" and \"\\<FF>' = \\<FF>\"\n  shows \"u : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m\\<^sub>.\\<^sub>f\\<^sub>i\\<^sub>n \\<FF>' : \\<JJ>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>'\\<^esub> \\<CC>'\"\n  unfolding assms by (rule is_cat_finite_limit_axioms)\n\nmk_ide rf is_cat_finite_limit_def\n  |intro is_cat_finite_limitI|\n  |dest is_cat_finite_limitD[dest]|\n  |elim is_cat_finite_limitE[elim]|\n\nlemmas [cat_lim_cs_intros] = is_cat_finite_limitD\n\nlemma (in is_cat_finite_colimit) \n  is_cat_finite_colimit_axioms'[cat_lim_cs_intros]:\n  assumes \"\\<alpha>' = \\<alpha>\" and \"r' = r\" and \"\\<JJ>' = \\<JJ>\" and \"\\<CC>' = \\<CC>\" and \"\\<FF>' = \\<FF>\"\n  shows \"u : \\<FF>' >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m\\<^sub>.\\<^sub>f\\<^sub>i\\<^sub>n r' : \\<JJ>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>'\\<^esub> \\<CC>'\"\n  unfolding assms by (rule is_cat_finite_colimit_axioms)\n\nmk_ide rf is_cat_finite_colimit_def[unfolded is_cat_colimit_axioms_def]\n  |intro is_cat_finite_colimitI|\n  |dest is_cat_finite_colimitD[dest]|\n  |elim is_cat_finite_colimitE[elim]|\n\nlemmas [cat_lim_cs_intros] = is_cat_finite_colimitD\n\n\ntext\\<open>Duality.\\<close>\n\nlemma (in is_cat_finite_limit) is_cat_finite_colimit_op:\n  \"op_ntcf u : op_cf \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m\\<^sub>.\\<^sub>f\\<^sub>i\\<^sub>n r : op_cat \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_cat \\<CC>\"\n  by\n    (\n      cs_concl cs_shallow\n        cs_intro: is_cat_finite_colimitI cat_op_intros cat_small_cs_intros\n    )\n\nlemma (in is_cat_finite_limit) is_cat_finite_colimit_op'[cat_op_intros]:\n  assumes \"\\<FF>' = op_cf \\<FF>\" and \"\\<JJ>' = op_cat \\<JJ>\" and \"\\<CC>' = op_cat \\<CC>\"\n  shows \"op_ntcf u : \\<FF>' >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m\\<^sub>.\\<^sub>f\\<^sub>i\\<^sub>n r : \\<JJ>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>'\"\n  unfolding assms by (rule is_cat_finite_colimit_op)\n\nlemmas [cat_op_intros] = is_cat_finite_limit.is_cat_finite_colimit_op'\n\nlemma (in is_cat_finite_colimit) is_cat_finite_limit_op:\n  \"op_ntcf u : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m\\<^sub>.\\<^sub>f\\<^sub>i\\<^sub>n op_cf \\<FF> : op_cat \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_cat \\<CC>\"\n  by \n    (\n      cs_concl cs_shallow \n        cs_intro: is_cat_finite_limitI cat_op_intros cat_small_cs_intros\n    )\n\nlemma (in is_cat_finite_colimit) is_cat_finite_colimit_op'[cat_op_intros]:\n  assumes \"\\<FF>' = op_cf \\<FF>\" and \"\\<JJ>' = op_cat \\<JJ>\" and \"\\<CC>' = op_cat \\<CC>\"\n  shows \"op_ntcf u : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m\\<^sub>.\\<^sub>f\\<^sub>i\\<^sub>n \\<FF>' : \\<JJ>' \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<CC>'\"\n  unfolding assms by (rule is_cat_finite_limit_op)\n\nlemmas [cat_op_intros] = is_cat_finite_colimit.is_cat_finite_colimit_op'\n\n\ntext\\<open>Elementary properties.\\<close>\n\nsublocale is_cat_finite_limit \\<subseteq> is_tm_cat_limit\n  by\n    (\n      intro \n        is_tm_cat_limitI \n        is_tm_cat_coneI \n        is_ntcf_axioms \n        cat_lim_ua_fo \n        cat_cone_obj \n        NTCod.cf_is_tm_functor_if_HomDom_finite_category[\n          OF NTDom.HomDom.finite_category_axioms\n          ]\n    )\n\nsublocale is_cat_finite_colimit \\<subseteq> is_tm_cat_colimit\n  by\n    (\n      intro \n        is_tm_cat_colimitI \n        is_tm_cat_coconeI \n        is_ntcf_axioms \n        cat_colim_ua_of \n        cat_cocone_obj \n        NTDom.cf_is_tm_functor_if_HomDom_finite_category[\n          OF NTDom.HomDom.finite_category_axioms\n          ]\n    )\n\n\n\nsubsection\\<open>Creation of limits\\<close>\n\n\ntext\\<open>See Chapter V-1 in \\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>.\\<close>\n\ndefinition cf_creates_limits :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> bool\"\n  where \"cf_creates_limits \\<alpha> \\<GG> \\<FF> =\n    (\n      \\<forall>\\<tau> b.\n        \\<tau> : b <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<GG> \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<FF>\\<lparr>HomDom\\<rparr> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<GG>\\<lparr>HomCod\\<rparr> \\<longrightarrow>\n        (\n          (\n            \\<exists>!\\<sigma>a. \\<exists>\\<sigma> a. \\<sigma>a = \\<langle>\\<sigma>, a\\<rangle> \\<and>\n              \\<sigma> : a <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<FF>\\<lparr>HomDom\\<rparr> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<FF>\\<lparr>HomCod\\<rparr> \\<and>\n              \\<tau> = \\<GG> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> \\<and>\n              b = \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\n          ) \\<and>\n          (\n            \\<forall>\\<sigma> a.\n              \\<sigma> : a <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<FF>\\<lparr>HomDom\\<rparr> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<FF>\\<lparr>HomCod\\<rparr> \\<longrightarrow>\n              \\<tau> = \\<GG> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> \\<longrightarrow>\n              b = \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<longrightarrow>\n              \\<sigma> : a <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<FF>\\<lparr>HomDom\\<rparr> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<FF>\\<lparr>HomCod\\<rparr>\n          )\n        )\n    )\"\n\n\ntext\\<open>Rules.\\<close>\n\ncontext\n  fixes \\<alpha> \\<JJ> \\<AA> \\<BB> \\<GG> \\<FF>\n  assumes \\<FF>: \"\\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n    and \\<GG>: \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\nbegin\n\ninterpretation \\<FF>: is_functor \\<alpha> \\<JJ> \\<AA> \\<FF> by (rule \\<FF>)\ninterpretation \\<GG>: is_functor \\<alpha> \\<AA> \\<BB> \\<GG> by (rule \\<GG>)\n\nmk_ide rf cf_creates_limits_def[\n  where \\<alpha>=\\<alpha> and \\<FF>=\\<FF> and \\<GG>=\\<GG>, unfolded cat_cs_simps\n  ]\n  |intro cf_creates_limitsI|\n  |dest cf_creates_limitsD'|\n  |elim cf_creates_limitsE'|\n\nend\n\nlemmas cf_creates_limitsD[dest!] = cf_creates_limitsD'[rotated 2]\n  and cf_creates_limitsE[elim!] = cf_creates_limitsE'[rotated 2]\n\nlemma cf_creates_limitsE'':\n  assumes \"cf_creates_limits \\<alpha> \\<GG> \\<FF>\"\n    and \"\\<tau> : b <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<GG> \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"\\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n    and \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  obtains \\<sigma> r where \"\\<sigma> : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n    and \"\\<tau> = \\<GG> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma>\"\n    and \"b = \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\"\nproof-\n  note cflD = cf_creates_limitsD[OF assms]\n  from conjunct1[OF cflD] obtain \\<sigma> r\n    where \\<sigma>: \"\\<sigma> : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n      and \\<tau>_def: \"\\<tau> = \\<GG> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma>\"\n      and b_def: \"b = \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr>\"\n    by metis\n  moreover have \"\\<sigma> : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n    by (rule conjunct2[OF cflD, rule_format, OF \\<sigma> \\<tau>_def b_def])\n  ultimately show ?thesis using that by auto\nqed\n\n\n\nsubsection\\<open>Preservation of limits and colimits\\<close>\n\n\nsubsubsection\\<open>Definitions and elementary properties\\<close>\n\n\ntext\\<open>See Chapter V-4 in \\<^cite>\\<open>\"mac_lane_categories_2010\"\\<close>.\\<close>\n\ndefinition cf_preserves_limits :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> bool\"\n  where \"cf_preserves_limits \\<alpha> \\<GG> \\<FF> =\n    (\n      \\<forall>\\<sigma> a.\n        \\<sigma> : a <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<FF>\\<lparr>HomDom\\<rparr> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<FF>\\<lparr>HomCod\\<rparr> \\<longrightarrow>\n        \\<GG> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<GG> \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<FF>\\<lparr>HomDom\\<rparr> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<GG>\\<lparr>HomCod\\<rparr>\n    )\"\n\ndefinition cf_preserves_colimits :: \"V \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> bool\"\n  where \"cf_preserves_colimits \\<alpha> \\<GG> \\<FF> =\n    (\n      \\<forall>\\<sigma> a.\n        \\<sigma> : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m a : \\<FF>\\<lparr>HomDom\\<rparr> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<FF>\\<lparr>HomCod\\<rparr> \\<longrightarrow>\n        \\<GG> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> : \\<GG> \\<circ>\\<^sub>C\\<^sub>F \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> : \\<FF>\\<lparr>HomDom\\<rparr> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<GG>\\<lparr>HomCod\\<rparr>\n    )\"\n\n\ntext\\<open>Rules.\\<close>\n\ncontext\n  fixes \\<alpha> \\<JJ> \\<AA> \\<BB> \\<GG> \\<FF>\n  assumes \\<FF>: \"\\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n    and \\<GG>: \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\nbegin\n\ninterpretation \\<FF>: is_functor \\<alpha> \\<JJ> \\<AA> \\<FF> by (rule \\<FF>)\ninterpretation \\<GG>: is_functor \\<alpha> \\<AA> \\<BB> \\<GG> by (rule \\<GG>)\n\nmk_ide rf cf_preserves_limits_def[\n  where \\<alpha>=\\<alpha> and \\<FF>=\\<FF> and \\<GG>=\\<GG>, unfolded cat_cs_simps\n  ]\n  |intro cf_preserves_limitsI|\n  |dest cf_preserves_limitsD'|\n  |elim cf_preserves_limitsE'|\n\nmk_ide rf cf_preserves_colimits_def[\n  where \\<alpha>=\\<alpha> and \\<FF>=\\<FF> and \\<GG>=\\<GG>, unfolded cat_cs_simps\n  ]\n  |intro cf_preserves_colimitsI|\n  |dest cf_preserves_colimitsD'|\n  |elim cf_preserves_colimitsE'|\n\nend\n\nlemmas cf_preserves_limitsD[dest!] = cf_preserves_limitsD'[rotated 2]\n  and cf_preserves_limitsE[elim!] = cf_preserves_limitsE'[rotated 2]\n\nlemmas cf_preserves_colimitsD[dest!] = cf_preserves_colimitsD'[rotated 2]\n  and cf_preserves_colimitsE[elim!] = cf_preserves_colimitsE'[rotated 2]\n\n\ntext\\<open>Duality.\\<close>\n\nlemma cf_preserves_colimits_op[cat_op_simps]:\n  assumes \"\\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\" and \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \n    \"cf_preserves_colimits \\<alpha> (op_cf \\<GG>) (op_cf \\<FF>) \\<longleftrightarrow>\n      cf_preserves_limits \\<alpha> \\<GG> \\<FF>\"\nproof\n\n  interpret \\<FF>: is_functor \\<alpha> \\<JJ> \\<AA> \\<FF> by (rule assms(1))\n  interpret \\<GG>: is_functor \\<alpha> \\<AA> \\<BB> \\<GG> by (rule assms(2))\n\n  show \"cf_preserves_limits \\<alpha> \\<GG> \\<FF>\"\n    if \"cf_preserves_colimits \\<alpha> (op_cf \\<GG>) (op_cf \\<FF>)\"\n  proof(rule cf_preserves_limitsI, rule assms(1), rule assms(2))\n    fix \\<sigma> r assume \"\\<sigma> : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n    then interpret \\<sigma>: is_cat_limit \\<alpha> \\<JJ> \\<AA> \\<FF> r \\<sigma> .\n    show \"\\<GG> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<GG> \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n      by \n        (\n          rule is_cat_colimit.is_cat_limit_op\n            [\n              OF cf_preserves_colimitsD\n                [\n                  OF that \\<sigma>.is_cat_colimit_op \\<FF>.is_functor_op \\<GG>.is_functor_op,\n                  folded op_cf_cf_comp op_ntcf_cf_ntcf_comp\n                ],\n              unfolded cat_op_simps\n            ]\n        )\n  qed\n\n  show \"cf_preserves_colimits \\<alpha> (op_cf \\<GG>) (op_cf \\<FF>)\"\n    if \"cf_preserves_limits \\<alpha> \\<GG> \\<FF>\"\n  proof\n    (\n      rule cf_preserves_colimitsI, \n      rule \\<FF>.is_functor_op, \n      rule \\<GG>.is_functor_op, \n      unfold cat_op_simps\n    )\n    fix \\<sigma> r assume \"\\<sigma> : op_cf \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m r : op_cat \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_cat \\<AA>\"\n    then interpret \\<sigma>: is_cat_colimit \\<alpha> \\<open>op_cat \\<JJ>\\<close> \\<open>op_cat \\<AA>\\<close> \\<open>op_cf \\<FF>\\<close> r \\<sigma> . \n    show \"op_cf \\<GG> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> :\n      op_cf \\<GG> \\<circ>\\<^sub>C\\<^sub>F op_cf \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> : op_cat \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_cat \\<BB>\"\n      by \n        (\n          rule is_cat_limit.is_cat_colimit_op\n            [\n              OF cf_preserves_limitsD[\n                OF that \\<sigma>.is_cat_limit_op[unfolded cat_op_simps] assms(1,2)\n                ],\n              unfolded cat_op_simps\n            ]\n        )\n  qed\n\nqed\n\nlemma cf_preserves_limits_op[cat_op_simps]:\n  assumes \"\\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\" and \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \n    \"cf_preserves_limits \\<alpha> (op_cf \\<GG>) (op_cf \\<FF>) \\<longleftrightarrow>\n      cf_preserves_colimits \\<alpha> \\<GG> \\<FF>\"\nproof\n\n  interpret \\<FF>: is_functor \\<alpha> \\<JJ> \\<AA> \\<FF> by (rule assms(1))\n  interpret \\<GG>: is_functor \\<alpha> \\<AA> \\<BB> \\<GG> by (rule assms(2))\n\n  show \"cf_preserves_colimits \\<alpha> \\<GG> \\<FF>\" \n    if \"cf_preserves_limits \\<alpha> (op_cf \\<GG>) (op_cf \\<FF>)\"\n  proof(rule cf_preserves_colimitsI, rule assms(1), rule assms(2))\n    fix \\<sigma> r assume \"\\<sigma> : \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m r : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\" \n    then interpret \\<sigma>: is_cat_colimit \\<alpha> \\<JJ> \\<AA> \\<FF> r \\<sigma> .\n    show \"\\<GG> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> : \\<GG> \\<circ>\\<^sub>C\\<^sub>F \\<FF> >\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>l\\<^sub>i\\<^sub>m \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n      by \n        (\n          rule is_cat_limit.is_cat_colimit_op\n            [\n              OF cf_preserves_limitsD\n                [\n                  OF that \\<sigma>.is_cat_limit_op \\<FF>.is_functor_op \\<GG>.is_functor_op,\n                  folded op_cf_cf_comp op_ntcf_cf_ntcf_comp\n                ],\n              unfolded cat_op_simps\n            ]\n        )\n  qed\n\n  show \"cf_preserves_limits \\<alpha> (op_cf \\<GG>) (op_cf \\<FF>)\"\n    if \"cf_preserves_colimits \\<alpha> \\<GG> \\<FF>\"\n  proof\n    (\n      rule cf_preserves_limitsI, \n      rule \\<FF>.is_functor_op, \n      rule \\<GG>.is_functor_op, \n      unfold cat_op_simps\n    )\n    fix \\<sigma> r assume \"\\<sigma> : r <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m op_cf \\<FF> : op_cat \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_cat \\<AA>\"\n    then interpret \\<sigma>: is_cat_limit \\<alpha> \\<open>op_cat \\<JJ>\\<close> \\<open>op_cat \\<AA>\\<close> \\<open>op_cf \\<FF>\\<close> r \\<sigma> . \n    show \"op_cf \\<GG> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> :\n      \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>r\\<rparr> <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m op_cf \\<GG> \\<circ>\\<^sub>C\\<^sub>F op_cf \\<FF> : op_cat \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_cat \\<BB>\"\n      by \n        (\n          rule is_cat_colimit.is_cat_limit_op\n            [\n              OF cf_preserves_colimitsD[\n                OF that \\<sigma>.is_cat_colimit_op[unfolded cat_op_simps] assms(1,2)\n                ],\n              unfolded cat_op_simps\n            ]\n        )\n  qed\n  \nqed\n\n\nsubsubsection\\<open>Further properties\\<close>\n\nlemma cf_preserves_limits_if_cf_creates_limits:\n  \\<comment>\\<open>See Theorem 2 in Chapter V-4 in \\cite{mac_lane_categories_2010}.\\<close>\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"\\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n    and \"\\<psi> : b <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<GG> \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    and \"cf_creates_limits \\<alpha> \\<GG> \\<FF>\"\n  shows \"cf_preserves_limits \\<alpha> \\<GG> \\<FF>\"\nproof-\n\n  interpret \\<GG>: is_functor \\<alpha> \\<AA> \\<BB> \\<GG> by (rule assms(1))\n  interpret \\<FF>: is_functor \\<alpha> \\<JJ> \\<AA> \\<FF> by (rule assms(2))\n  interpret \\<psi>: is_cat_limit \\<alpha> \\<JJ> \\<BB> \\<open>\\<GG> \\<circ>\\<^sub>C\\<^sub>F \\<FF>\\<close> b \\<psi>\n    by (intro is_cat_limit.cat_lim_is_tm_cat_limit assms(3,4))\n\n  show ?thesis\n  proof\n    (\n      intro cf_preserves_limitsI,\n      rule \\<FF>.is_functor_axioms,\n      rule \\<GG>.is_functor_axioms\n    )\n\n    fix \\<sigma> a assume prems: \"\\<sigma> : a <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n    then interpret \\<sigma>: is_cat_limit \\<alpha> \\<JJ> \\<AA> \\<FF> a \\<sigma> .\n\n    obtain \\<tau> A\n      where \\<tau>: \"\\<tau> : A <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n        and \\<psi>_def: \"\\<psi> = \\<GG> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<tau>\"\n        and b_def: \"b = \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>A\\<rparr>\"\n      by \n        (\n          rule cf_creates_limitsE''\n            [\n              OF \n                assms(4)  \n                \\<psi>.is_cat_limit_axioms\n                \\<FF>.is_functor_axioms\n                \\<GG>.is_functor_axioms\n            ]  \n        )\n    from \\<tau> interpret \\<tau>: is_cat_limit \\<alpha> \\<JJ> \\<AA> \\<FF> A \\<tau> .\n\n    from cat_lim_ex_is_iso_arr[OF \\<tau>.is_cat_limit_axioms prems] obtain f\n      where f: \"f : a \\<mapsto>\\<^sub>i\\<^sub>s\\<^sub>o\\<^bsub>\\<AA>\\<^esub> A\" and \\<sigma>_def: \"\\<sigma> = \\<tau> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<AA> f\"\n      by auto\n\n    note f = f is_iso_arrD(1)[OF f]\n\n    from f(2) have \"\\<GG> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<GG> \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n      by (intro is_cat_coneI)\n        (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n\n    from \\<sigma>_def have \"\\<GG> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> = \\<GG> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F (\\<tau> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<AA> f)\" \n      by simp\n    also from f(2) have \"\\<dots> = \\<psi> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<BB> (\\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr>)\"\n      by (cs_concl_step cf_ntcf_comp_ntcf_vcomp)\n        (\n          cs_concl\n            cs_simp: cat_cs_simps \\<psi>_def[symmetric] cs_intro: cat_cs_intros\n        )\n    finally have \\<GG>\\<sigma>: \"\\<GG> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> = \\<psi> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<BB> (\\<GG>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr>)\" .\n\n    show \"\\<GG> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> : \\<GG>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<GG> \\<circ>\\<^sub>C\\<^sub>F \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n      by \n        (\n          rule \\<psi>.cat_lim_is_cat_limit_if_is_iso_arr\n            [\n              OF \\<GG>.cf_ArrMap_is_iso_arr[OF f(1), folded b_def], \n              folded \\<GG>\\<sigma>\n            ]\n        )\n    \n  qed\n  \nqed\n\n\n\nsubsection\\<open>Continuous and cocontinuous functor\\<close>\n\n\nsubsubsection\\<open>Definition and elementary properties\\<close>\n\ndefinition is_cf_continuous :: \"V \\<Rightarrow> V \\<Rightarrow> bool\"\n  where \"is_cf_continuous \\<alpha> \\<GG> \\<longleftrightarrow>\n    (\\<forall>\\<FF> \\<JJ>. \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<GG>\\<lparr>HomDom\\<rparr> \\<longrightarrow> cf_preserves_limits \\<alpha> \\<GG> \\<FF>)\"\n\ndefinition is_cf_cocontinuous :: \"V \\<Rightarrow> V \\<Rightarrow> bool\"\n  where \"is_cf_cocontinuous \\<alpha> \\<GG> \\<longleftrightarrow>\n    (\\<forall>\\<FF> \\<JJ>. \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<GG>\\<lparr>HomDom\\<rparr> \\<longrightarrow> cf_preserves_colimits \\<alpha> \\<GG> \\<FF>)\"\n\n\ntext\\<open>Rules.\\<close>\n\ncontext\n  fixes \\<alpha> \\<JJ> \\<AA> \\<BB> \\<GG> \\<FF>\n  assumes \\<GG>: \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\nbegin\n\ninterpretation \\<GG>: is_functor \\<alpha> \\<AA> \\<BB> \\<GG> by (rule \\<GG>)\n\nmk_ide rf is_cf_continuous_def[where \\<alpha>=\\<alpha> and \\<GG>=\\<GG>, unfolded cat_cs_simps]\n  |intro is_cf_continuousI|\n  |dest is_cf_continuousD'|\n  |elim is_cf_continuousE'|\n\nmk_ide rf is_cf_cocontinuous_def[where \\<alpha>=\\<alpha> and \\<GG>=\\<GG>, unfolded cat_cs_simps]\n  |intro is_cf_cocontinuousI|\n  |dest is_cf_cocontinuousD'|\n  |elim is_cf_cocontinuousE'|\n\nend\n\nlemmas is_cf_continuousD[dest!] = is_cf_continuousD'[rotated]\n  and is_cf_continuousE[elim!] = is_cf_continuousE'[rotated]\n\nlemmas is_cf_cocontinuousD[dest!] = is_cf_cocontinuousD'[rotated]\n  and is_cf_cocontinuousE[elim!] = is_cf_cocontinuousE'[rotated]\n\n\ntext\\<open>Duality.\\<close>\n\nlemma is_cf_continuous_op[cat_op_simps]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"is_cf_continuous \\<alpha> (op_cf \\<GG>) \\<longleftrightarrow> is_cf_cocontinuous \\<alpha> \\<GG>\"\nproof\n  interpret \\<GG>: is_functor \\<alpha> \\<AA> \\<BB> \\<GG> by (rule assms(1))\n  show \"is_cf_cocontinuous \\<alpha> \\<GG>\" if \"is_cf_continuous \\<alpha> (op_cf \\<GG>)\"\n  proof(intro is_cf_cocontinuousI, rule assms)\n    fix \\<FF> \\<JJ> assume prems': \"\\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n    then interpret \\<FF>: is_functor \\<alpha> \\<JJ> \\<AA> \\<FF> .\n    show \"cf_preserves_colimits \\<alpha> \\<GG> \\<FF>\"\n      by \n        (\n          rule cf_preserves_limits_op\n            [\n              THEN iffD1, \n              OF\n                prems' \n                assms(1) \n                is_cf_continuousD[OF that \\<FF>.is_functor_op \\<GG>.is_functor_op] \n            ]\n        )\n  qed\n  show \"is_cf_continuous \\<alpha> (op_cf \\<GG>)\" if \"is_cf_cocontinuous \\<alpha> \\<GG>\"\n  proof(intro is_cf_continuousI, rule \\<GG>.is_functor_op)\n    fix \\<FF> \\<JJ> assume prems': \"\\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_cat \\<AA>\"\n    then interpret \\<FF>: is_functor \\<alpha> \\<JJ> \\<open>op_cat \\<AA>\\<close> \\<FF> .\n    from that assms have op_op_bundle:\n      \"is_cf_cocontinuous \\<alpha> (op_cf (op_cf \\<GG>))\"\n      \"op_cf (op_cf \\<GG>) : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n      unfolding cat_op_simps .\n    show \"cf_preserves_limits \\<alpha> (op_cf \\<GG>) \\<FF>\"\n      by \n        (\n          rule cf_preserves_colimits_op\n            [\n              THEN iffD1, \n              OF\n                \\<FF>.is_functor_axioms \n                \\<GG>.is_functor_op \n                is_cf_cocontinuousD\n                  [\n                    OF\n                      op_op_bundle(1) \n                      \\<FF>.is_functor_op[unfolded cat_op_simps] \n                      op_op_bundle(2)\n                  ]\n            ]\n        )\n  qed\nqed\n\nlemma is_cf_cocontinuous_op[cat_op_simps]:\n  assumes \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n  shows \"is_cf_cocontinuous \\<alpha> (op_cf \\<GG>) \\<longleftrightarrow> is_cf_continuous \\<alpha> \\<GG>\"\nproof\n  interpret \\<GG>: is_functor \\<alpha> \\<AA> \\<BB> \\<GG> by (rule assms(1))\n  show \"is_cf_continuous \\<alpha> \\<GG>\" if \"is_cf_cocontinuous \\<alpha> (op_cf \\<GG>)\"\n  proof(intro is_cf_continuousI, rule assms)\n    fix \\<FF> \\<JJ> assume prems': \"\\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n    then interpret \\<FF>: is_functor \\<alpha> \\<JJ> \\<AA> \\<FF> .\n    show \"cf_preserves_limits \\<alpha> \\<GG> \\<FF>\"\n      by \n        (\n          rule cf_preserves_colimits_op\n            [\n              THEN iffD1, \n              OF\n                prems' \n                assms(1) \n                is_cf_cocontinuousD[OF that \\<FF>.is_functor_op \\<GG>.is_functor_op] \n            ]\n        )\n  qed\n  show \"is_cf_cocontinuous \\<alpha> (op_cf \\<GG>)\" if \"is_cf_continuous \\<alpha> \\<GG>\"\n  proof(intro is_cf_cocontinuousI, rule \\<GG>.is_functor_op)\n    fix \\<FF> \\<JJ> assume prems': \"\\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> op_cat \\<AA>\"\n    then interpret \\<FF>: is_functor \\<alpha> \\<JJ> \\<open>op_cat \\<AA>\\<close> \\<FF> .\n    from that assms have op_op_bundle:\n      \"is_cf_continuous \\<alpha> (op_cf (op_cf \\<GG>))\"\n      \"op_cf (op_cf \\<GG>) : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n      unfolding cat_op_simps .\n    show \"cf_preserves_colimits \\<alpha> (op_cf \\<GG>) \\<FF>\"\n      by \n        (\n          rule cf_preserves_limits_op\n            [\n              THEN iffD1, \n              OF\n                \\<FF>.is_functor_axioms \n                \\<GG>.is_functor_op \n                is_cf_continuousD\n                  [\n                    OF\n                      op_op_bundle(1) \n                      \\<FF>.is_functor_op[unfolded cat_op_simps] \n                      op_op_bundle(2)\n                  ]\n            ]\n        )\n  qed\nqed\n\n\nsubsubsection\\<open>Category isomorphisms are continuous and cocontinuous\\<close>\n\nlemma (in is_iso_functor) iso_cf_is_cf_continuous: \"is_cf_continuous \\<alpha> \\<FF>\"\nproof(intro is_cf_continuousI)\n  fix \\<JJ> \\<GG> assume prems: \"\\<GG> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n  then interpret \\<GG>: is_functor \\<alpha> \\<JJ> \\<AA> \\<GG> .\n  show \"cf_preserves_limits \\<alpha> \\<FF> \\<GG>\"\n  proof(intro cf_preserves_limitsI)\n    fix a \\<sigma> assume \"\\<sigma> : a <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<GG> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n    then interpret \\<sigma>: is_cat_limit \\<alpha> \\<JJ> \\<AA> \\<GG> a \\<sigma> .\n    show \"\\<FF> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>l\\<^sub>i\\<^sub>m \\<FF> \\<circ>\\<^sub>C\\<^sub>F \\<GG> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n    proof(intro is_cat_limitI)\n      fix r' \\<tau> assume \"\\<tau> : r' <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<FF> \\<circ>\\<^sub>C\\<^sub>F \\<GG> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n      then interpret \\<tau>: is_cat_cone \\<alpha> r' \\<JJ> \\<BB> \\<open>\\<FF> \\<circ>\\<^sub>C\\<^sub>F \\<GG>\\<close> \\<tau> .\n      note [cat_cs_simps] = cf_comp_assoc_helper[\n          where \\<HH>=\\<open>inv_cf \\<FF>\\<close> and \\<GG>=\\<FF> and \\<FF>=\\<GG> and \\<Q>=\\<open>cf_id \\<AA>\\<close>\n          ]\n      have inv_\\<tau>: \"inv_cf \\<FF> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<tau> :\n        inv_cf \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr> <\\<^sub>C\\<^sub>F\\<^sub>.\\<^sub>c\\<^sub>o\\<^sub>n\\<^sub>e \\<GG> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n        by\n          (\n            cs_concl\n              cs_simp: cat_cs_simps cf_cs_simps\n              cs_intro: cat_cs_intros cf_cs_intros\n          )\n      from is_cat_limit.cat_lim_unique_cone'[OF \\<sigma>.is_cat_limit_axioms inv_\\<tau>]\n      obtain f where f: \"f : inv_cf \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr> \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a\"\n        and f_up: \"\\<And>j. j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr> \\<Longrightarrow>\n          (inv_cf \\<FF> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<tau>)\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = \\<sigma>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f\"\n        and f_unique:\n          \"\\<lbrakk>\n            f' : inv_cf \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr> \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a;\n            \\<And>j. j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr> \\<Longrightarrow> \n              (inv_cf \\<FF> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<tau>)\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = \\<sigma>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f'\n          \\<rbrakk> \\<Longrightarrow> f' = f\"\n        for f'\n        by metis\n      have [cat_cs_simps]: \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>\\<sigma>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> = \\<tau>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr>\"\n        if \"j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr>\" for j\n      proof-\n        from f_up[OF that] that have \n          \"inv_cf \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>\\<tau>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr>\\<rparr> = \\<sigma>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f\"\n          by (cs_prems cs_shallow cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n        then have \n          \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>inv_cf \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>\\<tau>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr>\\<rparr>\\<rparr> =\n            \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>\\<sigma>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> f\\<rparr>\"\n          by simp\n        from this that f show ?thesis \n          by \n            (\n              cs_prems cs_shallow \n                cs_simp: cat_cs_simps cf_cs_simps cs_intro: cat_cs_intros\n            ) \n            simp\n      qed\n      show \"\\<exists>!f'.\n        f' : r' \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr> \\<and> \\<tau> = \\<FF> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<BB> f'\"\n      proof(intro ex1I conjI; (elim conjE)?)\n        from f have \n          \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> : \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>inv_cf \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr>\\<rparr> \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n          by (cs_concl cs_shallow cs_intro: cat_cs_intros)\n        then show \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr> : r' \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n          by (cs_prems cs_shallow cs_simp: cf_cs_simps cs_intro: cat_cs_intros)\n        show \"\\<tau> = \\<FF> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<BB> (\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr>)\"\n        proof(rule ntcf_eqI, rule \\<tau>.is_ntcf_axioms)\n          from f show \"\\<FF> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<BB> (\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr>) :\n            cf_const \\<JJ> \\<BB> r' \\<mapsto>\\<^sub>C\\<^sub>F \\<FF> \\<circ>\\<^sub>C\\<^sub>F \\<GG> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\n            by\n              (\n                cs_concl\n                  cs_simp: cat_cs_simps cf_cs_simps cs_intro: cat_cs_intros\n              )\n          then have dom_rhs:\n            \"\\<D>\\<^sub>\\<circ> ((\\<FF> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<BB> (\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr>))\\<lparr>NTMap\\<rparr>) = \n              \\<JJ>\\<lparr>Obj\\<rparr>\"\n            by (cs_concl cs_simp: cat_cs_simps)\n          show \n            \"\\<tau>\\<lparr>NTMap\\<rparr> = (\\<FF> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<BB> (\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr>))\\<lparr>NTMap\\<rparr>\"\n          proof(rule vsv_eqI, unfold \\<tau>.ntcf_NTMap_vdomain dom_rhs)\n            fix j assume \"j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr>\"\n            with f show \"\\<tau>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> =\n              (\\<FF> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<BB> (\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr>))\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr>\"\n              by (cs_concl cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n          qed (cs_concl cs_intro: V_cs_intros cat_cs_intros)+\n        qed simp_all\n        fix f' assume prems': \n          \"f' : r' \\<mapsto>\\<^bsub>\\<BB>\\<^esub> \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>a\\<rparr>\"\n          \"\\<tau> = \\<FF> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<BB> f'\"\n        have \\<tau>j_def: \"\\<tau>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>\\<sigma>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr>\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<BB>\\<^esub> f'\"\n          if \"j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr>\" for j\n        proof-\n          from prems'(2) have\n            \"\\<tau>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = (\\<FF> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<sigma> \\<bullet>\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F ntcf_const \\<JJ> \\<BB> f')\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr>\"\n            by simp\n          from this prems'(1) that show ?thesis\n            by (cs_prems cs_simp: cat_cs_simps cs_intro: cat_cs_intros)\n        qed\n        have \"inv_cf \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> = f\"\n        proof(rule f_unique)\n          from prems'(1) show \n            \"inv_cf \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr> : inv_cf \\<FF>\\<lparr>ObjMap\\<rparr>\\<lparr>r'\\<rparr> \\<mapsto>\\<^bsub>\\<AA>\\<^esub> a\"\n            by\n              (\n                cs_concl \n                  cs_simp: cf_cs_simps cs_intro: cat_cs_intros cf_cs_intros\n              )\n          fix j assume \"j \\<in>\\<^sub>\\<circ> \\<JJ>\\<lparr>Obj\\<rparr>\"\n          from this prems'(1) show \n            \"(inv_cf \\<FF> \\<circ>\\<^sub>C\\<^sub>F\\<^sub>-\\<^sub>N\\<^sub>T\\<^sub>C\\<^sub>F \\<tau>)\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> = \n              \\<sigma>\\<lparr>NTMap\\<rparr>\\<lparr>j\\<rparr> \\<circ>\\<^sub>A\\<^bsub>\\<AA>\\<^esub> inv_cf \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr>\"\n            by\n              (\n                cs_concl \n                  cs_simp: cat_cs_simps cf_cs_simps \\<tau>j_def\n                  cs_intro: cat_cs_intros cf_cs_intros\n              )\n        qed\n        then have \"\\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>inv_cf \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f'\\<rparr>\\<rparr> = \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr>\" by simp\n        from this prems'(1) show \"f' = \\<FF>\\<lparr>ArrMap\\<rparr>\\<lparr>f\\<rparr>\"\n          by \n            (\n              cs_prems cs_shallow \n                cs_simp: cat_cs_simps cf_cs_simps cs_intro: cat_cs_intros\n            )\n      qed\n    qed (cs_concl cs_intro: cat_cs_intros cat_lim_cs_intros)\n  qed (intro prems is_functor_axioms)+\nqed (rule is_functor_axioms)\n\nlemma (in is_iso_functor) iso_cf_is_cf_cocontinuous: \"is_cf_cocontinuous \\<alpha> \\<FF>\"\n  using is_iso_functor.iso_cf_is_cf_continuous[OF is_iso_functor_op] \n  by (cs_prems cs_shallow cs_simp: cat_op_simps cs_intro: cat_cs_intros)\n\n\n\nsubsection\\<open>Tiny-continuous and tiny-cocontinuous functor\\<close>\n\n\nsubsubsection\\<open>Definition and elementary properties\\<close>\n\ndefinition is_tm_cf_continuous :: \"V \\<Rightarrow> V \\<Rightarrow> bool\"\n  where \"is_tm_cf_continuous \\<alpha> \\<GG> =\n    (\\<forall>\\<FF> \\<JJ>. \\<FF> : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<GG>\\<lparr>HomDom\\<rparr> \\<longrightarrow> cf_preserves_limits \\<alpha> \\<GG> \\<FF>)\"\n\n\ntext\\<open>Rules.\\<close>\n\ncontext\n  fixes \\<alpha> \\<JJ> \\<AA> \\<BB> \\<GG> \\<FF>\n  assumes \\<GG>: \"\\<GG> : \\<AA> \\<mapsto>\\<mapsto>\\<^sub>C\\<^bsub>\\<alpha>\\<^esub> \\<BB>\"\nbegin\n\ninterpretation \\<GG>: is_functor \\<alpha> \\<AA> \\<BB> \\<GG> by (rule \\<GG>)\n\nmk_ide rf is_tm_cf_continuous_def[where \\<alpha>=\\<alpha> and \\<GG>=\\<GG>, unfolded cat_cs_simps]\n  |intro is_tm_cf_continuousI|\n  |dest is_tm_cf_continuousD'|\n  |elim is_tm_cf_continuousE'|\n\nend\n\nlemmas is_tm_cf_continuousD[dest!] = is_tm_cf_continuousD'[rotated]\n  and is_tm_cf_continuousE[elim!] = is_tm_cf_continuousE'[rotated]\n\n\ntext\\<open>Elementary properties.\\<close>\n\nlemma (in is_functor) cf_continuous_is_tm_cf_continuous:\n  assumes \"is_cf_continuous \\<alpha> \\<FF>\"\n  shows \"is_tm_cf_continuous \\<alpha> \\<FF>\"\nproof(intro is_tm_cf_continuousI, rule is_functor_axioms)\n  fix \\<FF>' \\<JJ> assume \"\\<FF>' : \\<JJ> \\<mapsto>\\<mapsto>\\<^sub>C\\<^sub>.\\<^sub>t\\<^sub>m\\<^bsub>\\<alpha>\\<^esub> \\<AA>\"\n  then interpret \\<FF>': is_tm_functor \\<alpha> \\<JJ> \\<AA> \\<FF>'.\n  show \"cf_preserves_limits \\<alpha> \\<FF> \\<FF>'\"\n    by \n      (\n        intro is_cf_continuousD[OF assms(1) _ is_functor_axioms], \n        rule \\<FF>'.is_functor_axioms\n      )\nqed\n\ntext\\<open>\\newpage\\<close>\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/CZH_Universal_Constructions/czh_ucategories/CZH_UCAT_Limit.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5117166047041654, "lm_q2_score": 0.5, "lm_q1q2_score": 0.2558583023520827}}
{"text": "theory flash25Rev imports flashPub\nbegin\nsection{*Main defintions*}\nlemma NI_FAckVsInv25:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvVsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_InvAck_1VsInv25:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1_HomeVsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_InvAck_2VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_GetXVsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak1VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak2VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak3VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX1VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv25:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10VsInv25:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10_homeVsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX11VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_GetVsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_PutX ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak1VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak2VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak3VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put1VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put2VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put3VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_PutVsInv25:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_PutXAcksDoneVsInv25:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_NakVsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Nak_ClearVsInv25:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Nak_HomeVsInv25:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Remote_GetX_NakVsInv25:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_Nak_HomeVsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_PutXVsInv25:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_PutX_HomeVsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_GetX ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Nak1VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Nak2VsInv25:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Put1VsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Put2VsInv25:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutVsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutXVsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_ReplaceVsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_ReplaceHomeVsInv25:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceHomeShrVldVsInv25:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceShrVldVsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_ShWbVsInv25:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_WbVsInv25:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_GetX1VsInv25:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_GetX2VsInv25:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX1VsInv25:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX2VsInv25:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX3VsInv25:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX4VsInv25:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_Get_GetVsInv25:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_Get_PutVsInv25:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_PutXVsInv25:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_ReplaceVsInv25:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_GetVsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_GetXVsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_PutXVsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma PI_Remote_ReplaceVsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma StoreVsInv25:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma StoreHomeVsInv25:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv25  iInv1  iInv2 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash25Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5156199157230156, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.25579585854250353}}
{"text": "theory Agent\n  imports Subst_Term\nbegin\n\nnominal_datatype ('term, 'assertion, 'condition) psi = \n  Psi_nil (\"\\<zero>\" 190)\n\n\n| Output \"'term::fs_name\" 'term \"('term, 'assertion::fs_name, 'condition::fs_name) psi\"    (\"_\\<langle>_\\<rangle>._\" [120, 120, 110] 110)\n| Input 'term \"('term, 'assertion, 'condition) input\"                                      (\"_\\<lparr>_\" [120, 120] 110)\n| Case \"(('term, 'assertion, 'condition) psi_case)\"                                         (\"Case _\" [120] 120)\n| Par \"('term, 'assertion, 'condition) psi\" \"('term, 'assertion, 'condition) psi\"          (infixl \"\\<parallel>\" 90)\n| Res \"\\<guillemotleft>name\\<guillemotright>(('term, 'assertion, 'condition) psi)\"                                        (\"\\<lparr>\\<nu>_\\<rparr>_\" [120, 120] 110)\n| Assert 'assertion                                                                        (\"\\<lbrace>_\\<rbrace>\" [120] 120)\n| Bang \"('term, 'assertion, 'condition) psi\"                                               (\"!_\" [110] 110)\n\nand ('term, 'assertion, 'condition) input = \n  Trm 'term \"(('term, 'assertion, 'condition) psi)\"                                        (\"\\<rparr>_._\" [130, 130] 130)\n| Bind \"\\<guillemotleft>name\\<guillemotright>(('term, 'assertion, 'condition) input)\"                                     (\"\\<nu>__\" [120, 120] 120)\n\nand ('term, 'assertion, 'condition) psi_case = \n  Empty_case                                                                                (\"\\<bottom>\\<^sub>c\" 120)\n| Cond 'condition \"(('term, 'assertion, 'condition) psi)\"\n                  \"(('term, 'assertion, 'condition) psi_case)\"                              (\"\\<box> _ \\<Rightarrow> _ _ \" [120, 120, 120] 120)\n\nlemma psi_fresh_set[simp]:\n  fixes X :: \"name set\"\n  and   M :: \"'a::fs_name\"\n  and   N :: 'a\n  and   P :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n  and   I :: \"('a, 'b, 'c) input\"\n  and   C :: \"('a, 'b, 'c) psi_case\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   x :: name\n  and   \\<Psi> :: 'b\n  and   \\<Phi> :: 'c\n\n  shows \"X \\<sharp>* (M\\<langle>N\\<rangle>.P) = (X \\<sharp>* M \\<and> X \\<sharp>* N \\<and> X \\<sharp>* P)\"\n  and   \"X \\<sharp>* M\\<lparr>I = (X \\<sharp>* M \\<and> X \\<sharp>* I)\"\n  and   \"X \\<sharp>* Case C = X \\<sharp>* C\"\n  and   \"X \\<sharp>* (P \\<parallel> Q) = (X \\<sharp>* P \\<and> X \\<sharp>* Q)\"\n  and   \"X \\<sharp>* \\<lparr>\\<nu>x\\<rparr>P = (X \\<sharp>* [x].P)\"\n  and   \"X \\<sharp>* \\<lbrace>\\<Psi>\\<rbrace> = X \\<sharp>* \\<Psi>\"\n  and   \"X \\<sharp>* !P = X \\<sharp>* P\"\n  and   \"X \\<sharp>* \\<zero>\"\n  and   \"X \\<sharp>* Trm N P = (X \\<sharp>* N \\<and> X \\<sharp>* P)\"\n  and   \"X \\<sharp>* Bind x I = X \\<sharp>* ([x].I)\"\n\n  and   \"X \\<sharp>* \\<bottom>\\<^sub>c\"\n  and   \"X \\<sharp>* \\<box> \\<Phi> \\<Rightarrow> P C = (X \\<sharp>* \\<Phi> \\<and> X \\<sharp>* P \\<and> X \\<sharp>* C)\"\nby(auto simp add: fresh_star_def psi.fresh)+\n\nlemma psi_fresh_vec[simp]:\n  fixes xvec :: \"name list\"\n\n  shows \"xvec \\<sharp>* (M\\<langle>N\\<rangle>.P) = (xvec \\<sharp>* M \\<and> xvec \\<sharp>* N \\<and> xvec \\<sharp>* P)\"\n  and   \"xvec \\<sharp>* M\\<lparr>I = (xvec \\<sharp>* M \\<and> xvec \\<sharp>* I)\"\n  and   \"xvec \\<sharp>* Case C = xvec \\<sharp>* C\"\n  and   \"xvec \\<sharp>* (P \\<parallel> Q) = (xvec \\<sharp>* P \\<and> xvec \\<sharp>* Q)\"\n  and   \"xvec \\<sharp>* \\<lparr>\\<nu>x\\<rparr>P = (xvec \\<sharp>* [x].P)\"\n  and   \"xvec \\<sharp>* \\<lbrace>\\<Psi>\\<rbrace> = xvec \\<sharp>* \\<Psi>\"\n  and   \"xvec \\<sharp>* !P = xvec \\<sharp>* P\"\n  and   \"xvec \\<sharp>* \\<zero>\"\n\n  and   \"xvec \\<sharp>* Trm N P = (xvec \\<sharp>* N \\<and> xvec \\<sharp>* P)\"\n  and   \"xvec \\<sharp>* Bind x I = xvec \\<sharp>* ([x].I)\"\n\n  and   \"xvec \\<sharp>* \\<bottom>\\<^sub>c\"\n  and   \"xvec \\<sharp>* \\<box> \\<Phi> \\<Rightarrow> P C = (xvec \\<sharp>* \\<Phi> \\<and> xvec \\<sharp>* P \\<and> xvec \\<sharp>* C)\"\nby(auto simp add: fresh_star_def)\n\nfun psi_cases :: \"('c::fs_name \\<times> ('a::fs_name, 'b::fs_name, 'c) psi) list \\<Rightarrow> ('a, 'b, 'c) psi_case\"\nwhere \n  base: \"psi_cases [] = \\<bottom>\\<^sub>c\"\n| step: \"psi_cases ((\\<Phi>, P)#xs) = Cond \\<Phi> P (psi_cases xs)\"\n\nlemma psi_cases_eqvt[eqvt]:\n  fixes p  :: \"name prm\"\n  and   Cs :: \"('c::fs_name \\<times> ('a::fs_name, 'b::fs_name, 'c) psi) list\"\n\n  shows \"(p \\<bullet> (psi_cases Cs)) = psi_cases(p \\<bullet> Cs)\"\nby(induct Cs) auto\n\nlemma psi_cases_fresh[simp]:\n  fixes x  :: name\n  and   Cs :: \"('c::fs_name \\<times> ('a::fs_name, 'b::fs_name, 'c) psi) list\"\n  \n  shows \"x \\<sharp> psi_cases Cs = x \\<sharp> Cs\"\nby(induct Cs)\n  (auto simp add: fresh_list_nil fresh_list_cons)\n\nlemma psi_cases_fresh_chain[simp]:\n  fixes xvec :: \"name list\"\n  and   Cs :: \"('c::fs_name \\<times> ('a::fs_name, 'b::fs_name, 'c) psi) list\"\n  and   Xs   :: \"name set\"\n  \n  shows \"(xvec \\<sharp>* psi_cases Cs) = xvec \\<sharp>* Cs\"\n  and   \"(Xs \\<sharp>* psi_cases Cs) = Xs \\<sharp>* Cs\"\nby(auto simp add: fresh_star_def)\n\nabbreviation\n  psi_cases_judge (\"Cases _\" [80] 80) where \"Cases Cs \\<equiv> Case(psi_cases Cs)\"\n\nfun res_chain :: \"name list \\<Rightarrow> ('a::fs_name, 'b::fs_name, 'c::fs_name) psi \\<Rightarrow> ('a, 'b, 'c) psi\"\nwhere\n  res_chainbase: \"res_chain [] P = P\"\n| res_chainstep: \"res_chain (x#xs) P = \\<lparr>\\<nu>x\\<rparr>(res_chain xs P)\"\n\nnotation res_chain (\"\\<lparr>\\<nu>*_\\<rparr>_\" [80, 80] 80)\n\nlemma res_chain_eqvt[eqvt]:\n  fixes perm :: \"name prm\"\n  and   lst  :: \"name list\"\n  and   P    :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi\"\n  \n  shows \"perm \\<bullet> (\\<lparr>\\<nu>*xvec\\<rparr>P) = \\<lparr>\\<nu>*(perm \\<bullet> xvec)\\<rparr>(perm \\<bullet> P)\"\nby(induct_tac xvec, auto)\n\nlemma res_chain_supp:\n  fixes xvec :: \"name list\"\n  and   P    :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi\"\n\n  shows \"supp(\\<lparr>\\<nu>*xvec\\<rparr>P) = (supp P) - set xvec\"\nby(induct xvec) (auto simp add: psi.supp abs_supp)\n\nlemma res_chain_fresh: \n  fixes x    :: name\n  and   xvec :: \"name list\"\n  and   P    :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi\"\n\n  shows \"x \\<sharp> \\<lparr>\\<nu>*xvec\\<rparr>P = (x \\<in> set xvec \\<or> x \\<sharp> P)\"\nby (induct xvec) (simp_all add: abs_fresh)\n\nlemma res_chain_fresh_set: \n  fixes Xs   :: \"name set\"\n  and   xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  and   P    :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi\"\n\n  shows \"Xs \\<sharp>* (\\<lparr>\\<nu>*xvec\\<rparr>P) = (\\<forall>x\\<in>Xs. x \\<in> set xvec \\<or> x \\<sharp> P)\"\n  and   \"yvec \\<sharp>* (\\<lparr>\\<nu>*xvec\\<rparr>P) = (\\<forall>x\\<in>(set yvec). x \\<in> set xvec \\<or> x \\<sharp> P)\"\nby (simp add: fresh_star_def res_chain_fresh)+\n\nlemma res_chain_fresh_simps[simp]:\n  fixes Xs   :: \"name set\"\n  and   xvec :: \"name list\"\n  and   P    :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi\"\n  and   yvec :: \"name list\"\n\n  shows \"Xs \\<sharp>* xvec \\<Longrightarrow> Xs \\<sharp>* (\\<lparr>\\<nu>*xvec\\<rparr>P) = (Xs \\<sharp>* P)\"\n  and   \"yvec \\<sharp>* xvec \\<Longrightarrow> yvec \\<sharp>* (\\<lparr>\\<nu>*xvec\\<rparr>P) = (yvec \\<sharp>* P)\"\n  and   \"xvec \\<sharp>* (\\<lparr>\\<nu>*xvec\\<rparr>P)\"\napply(simp add: res_chain_fresh_set) apply(force simp add: fresh_star_def name_list_supp fresh_def)\napply(simp add: res_chain_fresh_set) apply(force simp add: fresh_star_def name_list_supp fresh_def)\nby(simp add: res_chain_fresh_set)\n  \nlemma res_chain_alpha:\n  fixes p    :: \"name prm\"\n  and   xvec :: \"name list\"\n  and   P    :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi\"\n\n  assumes xvec_freshP: \"(p \\<bullet> xvec) \\<sharp>* P\"\n  and     S: \"set p \\<subseteq> set xvec \\<times> set (p \\<bullet> xvec)\"\n\n  shows \"\\<lparr>\\<nu>*xvec\\<rparr>P = \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>(p \\<bullet> P)\"\nproof -\n  note pt_name_inst at_name_inst S\n  moreover have \"set xvec \\<sharp>* (\\<lparr>\\<nu>*xvec\\<rparr>P)\"\n    by (simp add: res_chain_fresh_set)\n  moreover from xvec_freshP have \"set (p \\<bullet> xvec) \\<sharp>* (\\<lparr>\\<nu>*xvec\\<rparr>P)\"\n    by (simp add: res_chain_fresh_set) (simp add: fresh_star_def)\n  ultimately have \"\\<lparr>\\<nu>*xvec\\<rparr>P = p \\<bullet> (\\<lparr>\\<nu>*xvec\\<rparr>P)\"\n    by (rule_tac pt_freshs_freshs [symmetric])\n  then show ?thesis by(simp add: eqvts)\nqed\n\nlemma res_chain_append:\n  fixes xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  and   P    :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi\"\n  \n  shows \"\\<lparr>\\<nu>*(xvec@yvec)\\<rparr>P = \\<lparr>\\<nu>*xvec\\<rparr>(\\<lparr>\\<nu>*yvec\\<rparr>P)\"\nby(induct xvec) auto\n\nlemma res_chain_simps[dest]:\n  fixes xvec :: \"name list\"\n  and   P    :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   Q'   :: \"('a, 'b, 'c) psi\"\n\n  shows \"((\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q)) = P' \\<parallel> Q') \\<Longrightarrow> (P = P' \\<and> Q = Q')\"\n  and   \"(P \\<parallel> Q = \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> Q')) \\<Longrightarrow> (P = P' \\<and> Q = Q')\"\nby(case_tac xvec, simp_all add: psi.inject)+\n\nfun input_chain :: \"name list \\<Rightarrow> 'a::fs_name \\<Rightarrow> ('a, 'b::fs_name, 'c::fs_name) psi \\<Rightarrow> ('a, 'b, 'c) input\"\nwhere\n  input_chainbase: \"input_chain [] N P = \\<rparr>(N).P\"\n| input_chainstep: \"input_chain (x#xs) N P = \\<nu> x (input_chain xs N P)\"\n\nabbreviation\n  input_chain_judge (\"_\\<lparr>\\<lambda>*_ _\\<rparr>._\" [80, 80, 80, 80] 80) where \"M\\<lparr>\\<lambda>*xvec N\\<rparr>.P \\<equiv> M\\<lparr>(input_chain xvec N P)\"\n\nlemma input_chain_eqvt[eqvt]:\n  fixes p    :: \"name prm\"\n  and   xvec :: \"name list\"\n  and   N    :: \"'a::fs_name\"\n  and   P    :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n  \n  shows \"p \\<bullet> (input_chain xvec N P) = input_chain (p \\<bullet> xvec) (p \\<bullet> N) (p \\<bullet> P)\"\nby(induct_tac xvec) auto\n\nlemma input_chain_fresh: \n  fixes x    :: name\n  and   xvec :: \"name list\"\n  and   N    :: \"'a::fs_name\"\n  and   P    :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n\n  shows \"x \\<sharp> (input_chain xvec N P) = (x \\<in> set xvec \\<or> (x \\<sharp> N \\<and> x \\<sharp> P))\"\nby (induct xvec) (simp_all add: abs_fresh)\n\nlemma induct_chain_simps[simp]:\n  fixes xvec :: \"name list\"\n  and   N    :: \"'a::fs_name\"\n  and   P    :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n\n  shows \"xvec \\<sharp>* (input_chain xvec N P)\"\nby(induct xvec) (auto simp add: abs_fresh abs_fresh_star fresh_star_def)\n\nlemma input_chain_fresh_set: \n  fixes Xs   :: \"name set\"\n  and   xvec :: \"name list\"\n  and   N    :: \"'a::fs_name\"\n  and   P    :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n\n  shows \"Xs \\<sharp>* (input_chain xvec N P) = (\\<forall>x\\<in>Xs. x \\<in> set xvec \\<or> (x \\<sharp> N \\<and> x \\<sharp> P))\"\nby (simp add: fresh_star_def input_chain_fresh)\n\nlemma input_chain_alpha:\n  fixes p  :: \"name prm\"\n  and   Xs :: \"name set\"\n  and   Ys :: \"name set\"\n\n  assumes Xs_freshP: \"Xs \\<sharp>* (input_chain xvec N P)\"\n  and     Ys_freshN: \"Ys \\<sharp>* N\"\n  and     Ys_freshP: \"Ys \\<sharp>* P\"\n  and     S: \"set p \\<subseteq> Xs \\<times> Ys\"\n\n  shows \"(input_chain xvec N P) = (input_chain (p \\<bullet> xvec) (p \\<bullet> N) (p \\<bullet> P))\"\nproof -\n  note pt_name_inst at_name_inst Xs_freshP S\n  moreover from Ys_freshN Ys_freshP have \"Ys \\<sharp>* (input_chain xvec N P)\"\n    by (simp add: input_chain_fresh_set) (simp add: fresh_star_def)\n  ultimately have \"(input_chain xvec N P) = p \\<bullet> (input_chain xvec N P)\"\n    by (rule_tac pt_freshs_freshs [symmetric])\n  then show ?thesis by(simp add: eqvts)\nqed\n\nlemma input_chain_alpha':\n  fixes p    :: \"name prm\"\n  and   xvec :: \"name list\"\n  and   N    :: \"'a::fs_name\"\n  and   P    :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n\n  assumes xvec_freshP: \"(p \\<bullet> xvec) \\<sharp>* P\"\n  and     xvec_freshN: \"(p \\<bullet> xvec) \\<sharp>* N\"\n  and     S: \"set p \\<subseteq> set xvec \\<times> set (p \\<bullet> xvec)\"\n\n  shows \"(input_chain xvec N P) = (input_chain (p \\<bullet> xvec) (p \\<bullet> N) (p \\<bullet> P))\"\nproof -\n  note pt_name_inst at_name_inst S\n  moreover have \"set xvec \\<sharp>* (input_chain xvec N P)\"\n    by (simp add: input_chain_fresh_set)\n  ultimately show ?thesis using xvec_freshN xvec_freshP \n    by(rule_tac input_chain_alpha) (simp add: fresh_star_def)+\nqed\n\nlemma alpha_res:\n  fixes M :: \"'a::fs_name\"\n  and   x :: name\n  and   P :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n  and   y :: name\n\n  assumes y_freshP: \"y \\<sharp> P\"\n\n  shows \"\\<lparr>\\<nu>x\\<rparr>P = \\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> P)\"\nproof(cases \"x = y\")\n  assume \"x=y\"\n  thus ?thesis by simp\nnext\n  assume \"x \\<noteq> y\"\n  with y_freshP show ?thesis\n    by(perm_simp add: psi.inject alpha calc_atm fresh_left)\nqed\n\nlemma alpha_input:\n  fixes x :: name\n  and   I :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) input\"\n  and   c :: name\n\n  assumes A1: \"c \\<sharp> I\"\n\n  shows \"\\<nu> x I = \\<nu> c([(x, c)] \\<bullet> I)\"\nproof(cases \"x = c\")\n  assume \"x=c\"\n  thus ?thesis by simp\nnext\n  assume \"x \\<noteq> c\"\n  with A1 show ?thesis\n    by(perm_simp add: input.inject alpha calc_atm fresh_left)\nqed\n\nlemma input_chain_length_eq:\n  fixes xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  and   M    :: \"'a::fs_name\"\n  and   P    :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n\n  assumes \"length xvec = length yvec\"\n  and     \"xvec \\<sharp>* yvec\"\n  and     \"distinct yvec\"\n  and     \"yvec \\<sharp>* M\"\n  and     \"yvec \\<sharp>* P\"\n\n  obtains N Q where \"input_chain xvec M P = input_chain yvec N Q\"\nproof -\n  assume \"\\<And>N Q. input_chain xvec M P = input_chain yvec N Q \\<Longrightarrow> thesis\"\n  moreover obtain n where \"n = length xvec\" by auto\n  with assms have \"\\<exists>N Q. input_chain xvec M P = input_chain yvec N Q\"\n  proof(induct n arbitrary: xvec yvec M P)\n    case 0\n    thus ?case by auto\n  next\n    case(Suc n xvec yvec M P)\n    from `Suc n = length xvec`\n    obtain x xvec' where \"xvec = x#xvec'\" and \"length xvec' = n\"\n      by(case_tac xvec) auto\n    with `length xvec = length yvec`\n    obtain y yvec' where \"yvec = y#yvec'\" by(case_tac yvec) auto\n    from `yvec = y#yvec'` `xvec=x#xvec'` `xvec \\<sharp>* yvec` `distinct yvec` `length xvec = length yvec` `yvec \\<sharp>* M` `yvec \\<sharp>* P`\n    have \"length xvec' = length yvec'\" and \"xvec' \\<sharp>* yvec'\" and \"distinct yvec'\" and \"yvec' \\<sharp>* M\" and \"yvec' \\<sharp>* P\"\n      by simp+\n    then obtain N Q where Eq: \"input_chain xvec' M P = input_chain yvec' N Q\" using `length xvec' = n`\n      by(drule_tac Suc) auto\n    moreover from `distinct yvec` `yvec = y#yvec'` have \"y \\<sharp> yvec'\" by auto\n    moreover from `xvec \\<sharp>* yvec` `xvec = x#xvec'` `yvec=y#yvec'` have \"x \\<noteq> y\" and \"x \\<sharp> yvec'\"\n      by auto\n    moreover from `yvec \\<sharp>* M` `yvec \\<sharp>* P` `yvec = y#yvec'` have \"y \\<sharp> M\" and \"y \\<sharp> P\" by auto\n    hence \"y \\<sharp> input_chain xvec' M P\" by(simp add: input_chain_fresh)\n    with Eq have \"y \\<sharp> input_chain yvec' N Q\" by(simp add: input_chain_fresh)\n    ultimately have \"\\<nu> x (input_chain xvec' M P) = \\<nu> y (input_chain yvec' ([(x, y)] \\<bullet> N) ([(x, y)] \\<bullet> Q))\"\n      by(simp add: input.inject alpha' eqvts name_swap)\n    thus ?case using `xvec = x#xvec'` `yvec=y#yvec'` by force\n  qed\n  ultimately show ?thesis\n    by blast\nqed\n\nlemma input_chain_eq:\n  fixes xvec :: \"name list\"\n  and   M    :: \"'a::fs_name\"\n  and   P    :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n  and   yvec :: \"name list\"\n  and   N    :: 'a\n  and   Q    :: \"('a, 'b, 'c) psi\"\n\n  assumes \"input_chain xvec M P = input_chain yvec N Q\"\n  and     \"xvec \\<sharp>* yvec\"\n  and     \"distinct xvec\"\n  and     \"distinct yvec\"\n\n  obtains p where \"(set p) \\<subseteq> (set xvec) \\<times> set (p \\<bullet> xvec)\" and \"distinct_perm p\" and \"yvec = p \\<bullet> xvec\" and \"N = p \\<bullet> M\" and \"Q = p \\<bullet> P\"\nproof -\n  assume \"\\<And>p. \\<lbrakk>set p \\<subseteq> set xvec \\<times> set (p \\<bullet> xvec); distinct_perm p; yvec = p \\<bullet> xvec; N = p \\<bullet> M; Q = p \\<bullet> P\\<rbrakk> \\<Longrightarrow> thesis\"\n  moreover obtain n where \"n = length xvec\" by auto\n  with assms have \"\\<exists>p. (set p) \\<subseteq> (set xvec) \\<times> set (yvec) \\<and> distinct_perm p \\<and>  yvec = p \\<bullet> xvec \\<and> N = p \\<bullet> M \\<and> Q = p \\<bullet> P\"\n  proof(induct n arbitrary: xvec yvec M N P Q)\n    case(0 xvec yvec M N P Q)\n    have Eq: \"input_chain xvec M P = input_chain yvec N Q\" by fact\n    from `0 = length xvec` have \"xvec = []\" by auto\n    moreover with Eq have \"yvec = []\"\n      by(case_tac yvec) auto\n    ultimately show ?case using Eq\n      by(simp add: input.inject)\n  next\n    case(Suc n xvec yvec M N P Q)\n    from `Suc n = length xvec`\n    obtain x xvec' where \"xvec = x#xvec'\" and \"length xvec' = n\"\n      by(case_tac xvec) auto\n    from `input_chain xvec M P = input_chain yvec N Q` `xvec = x # xvec'`\n    obtain y yvec' where \"input_chain (x#xvec') M P = input_chain (y#yvec') N Q\"\n      and \"yvec = y#yvec'\"\n      by(case_tac yvec) auto\n    hence EQ: \"\\<nu> x (input_chain xvec' M P) = \\<nu> y (input_chain yvec' N Q)\"\n      by simp\n    from `xvec = x#xvec'` `yvec=y#yvec'` `xvec \\<sharp>* yvec`\n    have \"x \\<noteq> y\" and \"xvec' \\<sharp>* yvec'\" and \"x \\<sharp> yvec'\" and \"y \\<sharp> xvec'\"\n      by(auto simp add: fresh_list_cons)\n    from `distinct xvec` `distinct yvec` `xvec=x#xvec'` `yvec=y#yvec'` have \"x \\<sharp> xvec'\" and \"y \\<sharp> yvec'\" and \"distinct xvec'\" and \"distinct yvec'\"\n      by simp+\n    have IH: \"\\<And>xvec yvec M N P Q. \\<lbrakk>input_chain xvec (M::'a) (P::('a, 'b, 'c) psi) = input_chain yvec (N::'a) (Q::('a, 'b, 'c) psi); xvec \\<sharp>* yvec; distinct xvec; distinct yvec; n = length xvec\\<rbrakk> \\<Longrightarrow> \\<exists>p. (set p) \\<subseteq> (set xvec) \\<times> (set yvec) \\<and> distinct_perm p \\<and>  yvec = p \\<bullet> xvec \\<and> N = p \\<bullet> M \\<and> Q = p \\<bullet> P\"\n      by fact\n    from EQ `x \\<noteq> y`  `x \\<sharp> yvec'` `y \\<sharp> yvec'` have \"input_chain xvec' M P = input_chain yvec' ([(x, y)] \\<bullet> N) ([(x, y)] \\<bullet> Q)\"\n      by(simp add: input.inject alpha eqvts)\n    with `xvec' \\<sharp>* yvec'` `distinct xvec'` `distinct yvec'` `length xvec' = n` IH\n    obtain p where S: \"(set p) \\<subseteq> (set xvec') \\<times> (set yvec')\" and \"distinct_perm p\" and \"yvec' = p \\<bullet> xvec'\" and \"([(x, y)] \\<bullet> N) = p \\<bullet> M\" and \"([(x, y)] \\<bullet> Q) = p \\<bullet> P\"\n      by metis\n    from S have \"set((x, y)#p) \\<subseteq> set(x#xvec') \\<times> set(y#yvec')\" by auto\n    moreover from `x \\<sharp> xvec'` `x \\<sharp> yvec'` `y \\<sharp> xvec'` `y \\<sharp> yvec'` S have \"x \\<sharp> p\" and \"y \\<sharp> p\"\n      apply(induct p)\n      by(auto simp add: fresh_list_nil fresh_list_cons fresh_prod name_list_supp) (auto simp add: fresh_def) \n\n    with S `distinct_perm p` `x \\<noteq> y` have \"distinct_perm((x, y)#p)\" by auto\n    moreover from `yvec' = p \\<bullet> xvec'` `x \\<sharp> p` `y \\<sharp> p` `x \\<sharp> xvec'` `y \\<sharp> xvec'` have \"(y#yvec') = ((x, y)#p) \\<bullet> (x#xvec')\"\n      by(simp add: calc_atm fresh_chain_simps)\n    moreover from `([(x, y)] \\<bullet> N) = p \\<bullet> M` have \"([(x, y)] \\<bullet> [(x, y)] \\<bullet> N) = [(x, y)] \\<bullet> p \\<bullet> M\"\n      by(simp add: pt_bij)\n    hence \"N = ((x, y)#p) \\<bullet> M\" by simp\n    moreover from `([(x, y)] \\<bullet> Q) = p \\<bullet> P` have \"([(x, y)] \\<bullet> [(x, y)] \\<bullet> Q) = [(x, y)] \\<bullet> p \\<bullet> P\"\n      by(simp add: pt_bij)\n    hence \"Q = ((x, y)#p) \\<bullet> P\" by simp\n    ultimately show ?case using `xvec=x#xvec'` `yvec=y#yvec'`\n      by blast\n  qed\n  ultimately show ?thesis by blast\nqed\n\nlemma input_chain_eq_length:\n  fixes xvec :: \"name list\"\n  and   M    :: \"'a::fs_name\"\n  and   P    :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n  and   yvec :: \"name list\"\n  and   N    :: 'a\n  and   Q    :: \"('a, 'b, 'c) psi\"\n\n  assumes \"input_chain xvec M P = input_chain yvec N Q\"\n\n  shows \"length xvec = length yvec\"\nproof -\n  obtain n where \"n = length xvec\" by auto\n  with assms show ?thesis\n  proof(induct n arbitrary: xvec yvec M P N Q)\n    case(0 xvec yvec M P N Q)\n    from `0 = length xvec` have \"xvec = []\" by auto\n    moreover with `input_chain xvec M P = input_chain yvec N Q` have \"yvec = []\"\n      by(case_tac yvec) auto\n    ultimately show ?case by simp\n  next\n    case(Suc n xvec yvec M P N Q)\n    from `Suc n = length xvec`\n    obtain x xvec' where \"xvec = x#xvec'\" and \"length xvec' = n\"\n      by(case_tac xvec) auto\n    from `input_chain xvec M P = input_chain yvec N Q` `xvec = x # xvec'`\n    obtain y yvec' where \"input_chain (x#xvec') M P = input_chain (y#yvec') N Q\"\n      and \"yvec = y#yvec'\"\n      by(case_tac yvec) auto\n    hence EQ: \"\\<nu> x (input_chain xvec' M P) = \\<nu> y (input_chain yvec' N Q)\"\n      by simp\n    have IH: \"\\<And>xvec yvec M P N Q. \\<lbrakk>input_chain xvec (M::'a) (P::('a, 'b, 'c) psi) = input_chain yvec N Q; n = length xvec\\<rbrakk> \\<Longrightarrow> length xvec = length yvec\"\n      by fact\n    show ?case\n    proof(case_tac \"x = y\")\n      assume \"x = y\"\n      with EQ have \"input_chain xvec' M P = input_chain yvec' N Q\"\n\tby(simp add: alpha input.inject)\n      with IH `length xvec' = n` have \"length xvec' = length yvec'\"\n\tby blast\n      with `xvec = x#xvec'` `yvec=y#yvec'`\n      show ?case by simp\n    next\n      assume \"x \\<noteq> y\"\n      with EQ have \"input_chain xvec' M P = input_chain ([(x, y)] \\<bullet> yvec') ([(x, y)] \\<bullet> N) ([(x, y)] \\<bullet> Q)\"\n\tby(simp add: alpha input.inject eqvts)\n      with IH `length xvec' = n` have \"length xvec' = length ([(x, y)] \\<bullet> yvec')\"\n\tby blast\n      hence \"length xvec' = length yvec'\"\n\tby simp\n      with `xvec = x#xvec'` `yvec=y#yvec'`\n      show ?case by simp\n    qed\n  qed\nqed\n\nlemma alpha_input_chain:\n  fixes yvec :: \"name list\"\n  and   xvec :: \"name list\"\n  and   M    :: \"'a::fs_name\"\n  and   P    :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n\n  assumes \"length xvec = length yvec\"\n  and     \"yvec \\<sharp>* M\"\n  and     \"yvec \\<sharp>* P\"\n  and     \"yvec \\<sharp>* xvec\"\n  and     \"distinct yvec\"\n\n  shows \"input_chain xvec M P = input_chain yvec ([xvec yvec] \\<bullet>\\<^sub>v M) ([xvec yvec] \\<bullet>\\<^sub>v P)\"\nusing assms\nproof(induct rule: compose_perm_induct)\n  case c_base\n  show ?case by simp\nnext\n  case(c_step x xvec y yvec)\n  thus ?case \n    apply auto\n    by(subst alpha_input[of y]) (auto simp add: input_chain_fresh eqvts)\nqed\n\nlemma input_chain_inject[simp]:\n\n  shows \"(input_chain xvec M P = input_chain xvec N Q) = ((M = N) \\<and> (P = Q))\"\nby(induct xvec) (auto simp add: input.inject alpha)\n\nlemma alpha_input_distinct:\n  fixes xvec :: \"name list\"\n  and   M    :: \"'a::fs_name\"\n  and   P    :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n  and   yvec :: \"name list\"\n  and   N    :: 'a\n  and   Q    :: \"('a, 'b, 'c) psi\"\n\n  assumes Eq: \"input_chain xvec M P = input_chain yvec N Q\"\n  and     xvec_dist: \"distinct xvec\"\n  and     Mem: \"\\<And>x. x \\<in> set xvec \\<Longrightarrow> x \\<in> supp M\"\n  and     xvec_freshyvec: \"xvec \\<sharp>* yvec\"\n  and     xvec_freshN: \"xvec \\<sharp>* N\"\n  and     xvec_freshQ: \"xvec \\<sharp>* Q\"\n\n  shows \"distinct yvec\"\nproof -\n  from Eq have \"length xvec = length yvec\"\n    by(rule input_chain_eq_length)\n  with assms show ?thesis\n  proof(induct n==\"length xvec\" arbitrary: xvec yvec N Q rule: nat.induct)\n    case(zero xvec yvec N Q)\n    thus ?case by simp\n  next\n    case(Suc n xvec yvec N Q)\n    have L: \"length xvec = length yvec\" and \"Suc n = length xvec\" by fact+\n    then obtain x xvec' y yvec' where x_eq: \"xvec = x#xvec'\" and y_eq: \"yvec = y#yvec'\"\n                                  and L': \"length xvec' = length yvec'\"\n      by(cases xvec, auto, cases yvec, auto)\n    have xvec_freshyvec: \"xvec \\<sharp>* yvec\" and xvec_dist: \"distinct xvec\" by fact+\n    with x_eq y_eq have xineqy: \"x \\<noteq> y\" and xvec'_freshyvec': \"xvec' \\<sharp>* yvec'\"\n                  and xvec'_dist: \"distinct xvec'\" and x_freshxvec': \"x \\<sharp> xvec'\"\n                  and x_freshyvec': \"x \\<sharp> yvec'\" and y_freshxvec': \"y \\<sharp> xvec'\"\n      by(auto simp add: fresh_list_cons)\n    have Eq: \"input_chain xvec M P = input_chain yvec N Q\" by fact\n    with x_eq y_eq xineqy have Eq': \"input_chain xvec' M P = input_chain ([(x, y)] \\<bullet> yvec') ([(x, y)] \\<bullet> N) ([(x, y)] \\<bullet> Q)\"\n      by(simp add: input.inject alpha eqvts) \n    moreover have Mem:\"\\<And>x. x \\<in> set xvec \\<Longrightarrow> x \\<in> supp M\" by fact\n    with x_eq have \"\\<And>x. x \\<in> set xvec' \\<Longrightarrow> x \\<in> supp M\" by simp\n    moreover have xvec_freshN: \"xvec \\<sharp>* N\" by fact\n    with x_eq x_freshxvec' y_freshxvec' have \"xvec' \\<sharp>* ([(x, y)] \\<bullet> N)\" by simp\n    moreover have xvec_freshQ: \"xvec \\<sharp>* Q\" by fact\n    with x_eq x_freshxvec' y_freshxvec' have \"xvec' \\<sharp>* ([(x, y)] \\<bullet> Q)\" by simp\n    moreover have \"Suc n = length xvec\" by fact\n    with x_eq have \"n = length xvec'\" by simp\n    moreover from xvec'_freshyvec' x_freshxvec' y_freshxvec' have \"xvec' \\<sharp>* ([(x, y)] \\<bullet> yvec')\"\n      by simp\n    moreover from L' have \"length xvec' = length([(x, y)] \\<bullet> yvec')\" by simp\n    moreover have \"\\<And>xvec yvec N Q.\n                   \\<lbrakk>n = length xvec; input_chain xvec (M::'a) (P::('a, 'b, 'c) psi) = input_chain yvec N Q; distinct xvec; \\<And>x. x \\<in> set xvec \\<Longrightarrow> x \\<in> supp M; xvec \\<sharp>* yvec;\n                    xvec \\<sharp>* N; xvec \\<sharp>* Q; length xvec = length yvec\\<rbrakk>\n                    \\<Longrightarrow> distinct yvec\" by fact\n    ultimately have \"distinct([(x, y)] \\<bullet> yvec')\" using xvec'_dist\n      by blast\n    hence \"distinct yvec'\" by simp\n    from Mem x_eq have x_suppM: \"x \\<in> supp M\" by simp\n    from L xvec_freshyvec xvec_dist xvec_freshN xvec_freshQ\n    have \"input_chain yvec N Q = input_chain xvec ([yvec xvec] \\<bullet>\\<^sub>v N) ([yvec xvec] \\<bullet>\\<^sub>v Q)\"\n      by(simp add: alpha_input_chain)\n    with Eq have \"M = [yvec xvec] \\<bullet>\\<^sub>v N\"  by auto\n    with x_eq y_eq have \"M = [(y, x)] \\<bullet> [yvec' xvec'] \\<bullet>\\<^sub>v N\"\n      by simp\n    with x_suppM have y_suppN: \"y \\<in> supp([yvec' xvec'] \\<bullet>\\<^sub>v N)\"\n      by(drule_tac pi=\"[(x, y)]\" in pt_set_bij2[OF pt_name_inst, OF at_name_inst])\n        (simp add: calc_atm eqvts name_swap)\n    have \"y \\<sharp> yvec'\"\n    proof(simp add: fresh_def, rule notI)\n      assume \"y \\<in> supp yvec'\"\n      hence \"y mem yvec'\"\n\tby(induct yvec') (auto simp add: supp_list_nil supp_list_cons supp_atm)\n      moreover from xvec_freshN x_eq x_freshxvec' have \"xvec' \\<sharp>* N\" by simp\n      ultimately have \"y \\<sharp> [yvec' xvec'] \\<bullet>\\<^sub>v  N\" using L' xvec'_freshyvec' xvec'_dist\n\tby(force intro: fresh_chain_perm simp add: fresh_chain_sym)\n      with y_suppN show \"False\" by(simp add: fresh_def)\n    qed\n    with `distinct yvec'`  y_eq show ?case by simp\n  qed\nqed\n\nlemma psi_cases_inject[simp]:\n  fixes CsP  :: \"('c::fs_name \\<times> ('a::fs_name, 'b::fs_name, 'c) psi) list\"\n  and   CsQ  :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n\n  shows \"(psi_cases CsP = psi_cases CsQ) = (CsP = CsQ)\"\nproof(induct CsP arbitrary: CsQ)\n  case(Nil CsQ)\n  thus ?case by(case_tac CsQ) (auto)\nnext\n  case(Cons a CsP CsQ)\n  thus ?case\n    by(case_tac a, case_tac CsQ) (clarsimp simp add: psi_case.inject)+\nqed\n\nlemma cases_inject[simp]:\n  fixes CsP :: \"('c::fs_name \\<times> ('a::fs_name, 'b::fs_name, 'c) psi) list\"\n  and   CsQ :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n\n  shows \"(Cases CsP = Cases CsQ) = (CsP = CsQ)\"\napply(induct CsP)\napply(auto simp add: psi_case.inject)\napply(case_tac CsQ)\napply(simp add: psi_case.inject psi.inject)\napply(force simp add: psi_case.inject psi.inject)\napply(case_tac CsQ)\napply(force simp add: psi_case.inject psi.inject)\napply(auto simp add: psi_case.inject psi.inject)\napply(simp only: psi_cases.simps[symmetric])\napply(simp only: psi_cases_inject)\napply simp\napply(case_tac CsQ)\nby(auto simp add: psi_case.inject psi.inject)\n\nnominal_primrec\n  guarded :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi \\<Rightarrow> bool\"\n  and guarded'  :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) input \\<Rightarrow> bool\"\n  and guarded'' :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi_case \\<Rightarrow> bool\"\n\nwhere\n  \"guarded (\\<zero>) = True\"\n| \"guarded (M\\<langle>N\\<rangle>.P) = True\"\n| \"guarded (M\\<lparr>I) = True\"\n| \"guarded (Case C) = guarded'' C\"\n| \"guarded (P \\<parallel> Q) = ((guarded P) \\<and> (guarded Q))\"\n| \"guarded (\\<lparr>\\<nu>x\\<rparr>P) = (guarded P)\"\n| \"guarded (\\<lbrace>\\<Psi>\\<rbrace>) = False\"\n| \"guarded (!P) = guarded P\"\n\n| \"guarded' (Trm M P) = False\"\n| \"guarded' (\\<nu> y I) = False\"\n\n| \"guarded'' (\\<bottom>\\<^sub>c) = True\"\n| \"guarded'' (\\<box>\\<phi> \\<Rightarrow> P C) = (guarded P \\<and> guarded'' C)\"\napply(finite_guess)+\napply(rule TrueI)+\nby(fresh_guess add: fresh_bool)+\n\nlemma guarded_eqvt[eqvt]:\n  fixes p    :: \"name prm\"\n  and   P    :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi\"\n  and   I    :: \"('a, 'b, 'c) input\"\n  and   C    :: \"('a, 'b, 'c) psi_case\"\n\n  shows \"(p \\<bullet> (guarded P)) = guarded (p \\<bullet> P)\"\n  and   \"(p \\<bullet> (guarded' I)) = guarded' (p \\<bullet> I)\"\n  and   \"(p \\<bullet> (guarded'' C)) = guarded'' (p \\<bullet> C)\"\nby(nominal_induct P and I and C rule: psi_input_psi_case.strong_inducts)\n  (simp add: eqvts)+\n\nlemma guarded_closed[simp]:\n  fixes P :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi\"\n  and   p :: \"name prm\"\n\n  assumes \"guarded P\"\n\n  shows \"guarded(p \\<bullet> P)\"\nproof -\n  from `guarded P` have \"p \\<bullet> (guarded P)\"\n    by(simp add: perm_bool)\n  thus ?thesis by(simp add: eqvts)\nqed\n\nlocale subst_psi =\n  subst_term: strong_subst_type subst_term +\n  subst_assert: subst_type subst_assert +\n  subst_cond: subst_type subst_cond\n\n  for subst_term :: \"('a::fs_name) \\<Rightarrow> name list \\<Rightarrow> 'a::fs_name list \\<Rightarrow> 'a\"\n  and subst_assert :: \"('b::fs_name) \\<Rightarrow> name list \\<Rightarrow> 'a::fs_name list \\<Rightarrow> 'b\"\n  and subst_cond :: \"('c::fs_name) \\<Rightarrow> name list \\<Rightarrow> 'a::fs_name list \\<Rightarrow> 'c\"\nbegin\n\nnominal_primrec \n    subs   :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi \\<Rightarrow> name list \\<Rightarrow> 'a list \\<Rightarrow> ('a, 'b, 'c) psi\"\nand subs'  :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) input \\<Rightarrow> name list \\<Rightarrow> 'a list \\<Rightarrow> ('a, 'b, 'c) input\"\nand subs'' :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi_case \\<Rightarrow> name list \\<Rightarrow> 'a list  \\<Rightarrow> ('a, 'b, 'c) psi_case\"\n\nwhere\n  \"subs (\\<zero>) xvec Tvec = \\<zero>\"\n| \"(subs (M\\<langle>N\\<rangle>.P) xvec Tvec) = (subst_term M xvec Tvec)\\<langle>(subst_term N xvec Tvec)\\<rangle>.(subs P xvec Tvec)\"\n| \"(subs (M\\<lparr>I) xvec Tvec) = (subst_term M xvec Tvec)\\<lparr>(subs' I xvec Tvec)\"\n\n| \"(subs (Case C) xvec Tvec) = (Case (subs'' C xvec Tvec))\"\n| \"(subs (P \\<parallel> Q) xvec Tvec) = (subs P xvec Tvec) \\<parallel> (subs Q xvec Tvec)\"\n| \"\\<lbrakk>y \\<sharp> xvec; y \\<sharp> Tvec\\<rbrakk> \\<Longrightarrow> (subs (\\<lparr>\\<nu>y\\<rparr>P) xvec Tvec) = \\<lparr>\\<nu>y\\<rparr>(subs P xvec Tvec)\"\n| \"(subs (\\<lbrace>\\<Psi>\\<rbrace>) xvec Tvec) = \\<lbrace>(subst_assert \\<Psi> xvec Tvec)\\<rbrace>\"\n| \"(subs (!P) xvec Tvec) = !(subs P xvec Tvec)\"\n\n| \"(subs' ((Trm M P)::('a::fs_name, 'b::fs_name, 'c::fs_name) input) xvec Tvec) = (\\<rparr>(subst_term M xvec Tvec).(subs P xvec Tvec))\"\n| \"\\<lbrakk>y \\<sharp> xvec; y \\<sharp> Tvec\\<rbrakk> \\<Longrightarrow> (subs' (\\<nu> y I) xvec Tvec) = (\\<nu> y (subs' I xvec Tvec))\"\n\n| \"(subs'' (\\<bottom>\\<^sub>c::('a::fs_name, 'b::fs_name, 'c::fs_name) psi_case) xvec Tvec) = \\<bottom>\\<^sub>c\"\n| \"(subs'' (\\<box>\\<Phi> \\<Rightarrow> P C) xvec Tvec) = (\\<box>(subst_cond \\<Phi> xvec Tvec) \\<Rightarrow> (subs P xvec Tvec) (subs'' C xvec Tvec))\"\napply(finite_guess add: subst_term.fs subst_assert.fs subst_cond.fs)+\napply(rule TrueI)+\napply(simp add: abs_fresh)\napply(simp add: abs_fresh)\napply(simp add: abs_fresh)\napply(rule supports_fresh[of \"supp(xvec, Tvec)\"])\napply(force simp add: perm_fun_def eqvts fresh_def[symmetric] supports_def)\napply(simp add: fs_name1)\napply(simp add: fresh_def[symmetric])\napply(rule supports_fresh[of \"supp(xvec, Tvec)\"])\napply(force simp add: perm_fun_def eqvts fresh_def[symmetric] supports_def)\napply(simp add: fs_name1)\napply(simp add: fresh_def[symmetric])\napply(fresh_guess)+\napply(rule supports_fresh[of \"supp(xvec, Tvec)\"])\napply(force simp add: perm_fun_def eqvts fresh_def[symmetric] supports_def)\napply(simp add: fs_name1)\napply(simp add: fresh_def[symmetric])\napply(fresh_guess)+\napply(rule supports_fresh[of \"supp(xvec, Tvec)\"])\napply(force simp add: perm_fun_def eqvts fresh_def[symmetric] supports_def)\napply(simp add: fs_name1)\napply(simp add: fresh_def[symmetric])\napply(fresh_guess)+\napply(rule supports_fresh[of \"supp(xvec, Tvec)\"])\napply(force simp add: perm_fun_def eqvts fresh_def[symmetric] supports_def)\napply(simp add: fs_name1)\napply(simp add: fresh_def[symmetric])\napply(fresh_guess)\napply(rule supports_fresh[of \"supp(xvec, Tvec)\"])\napply(force simp add: perm_fun_def eqvts fresh_def[symmetric] supports_def)\napply(simp add: fs_name1)\napply(simp add: fresh_def[symmetric])\napply(rule supports_fresh[of \"supp(xvec, Tvec)\"])\napply(force simp add: perm_fun_def eqvts fresh_def[symmetric] supports_def)\napply(simp add: fs_name1)\napply(simp add: fresh_def[symmetric])\napply(fresh_guess)+\napply(rule supports_fresh[of \"supp(xvec, Tvec)\"])\napply(force simp add: perm_fun_def eqvts fresh_def[symmetric] supports_def)\napply(simp add: fs_name1)\napply(simp add: fresh_def[symmetric])\napply(fresh_guess)+\napply(rule supports_fresh[of \"supp(xvec, Tvec)\"])\napply(force simp add: perm_fun_def eqvts fresh_def[symmetric] supports_def)\napply(simp add: fs_name1)\napply(simp add: fresh_def[symmetric])\napply(fresh_guess)+\napply(rule supports_fresh[of \"supp(xvec, Tvec)\"])\napply(force simp add: perm_fun_def eqvts fresh_def[symmetric] supports_def)\napply(simp add: fs_name1)\napply(simp add: fresh_def[symmetric])\ndone\n\nlemma subst_eqvt[eqvt]:\n  fixes p    :: \"name prm\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   xvec :: \"name list\"\n  and   Tvec :: \"'a list\"\n  and   I    :: \"('a, 'b, 'c) input\"\n  and   C    :: \"('a, 'b, 'c) psi_case\"\n\n  shows \"(p \\<bullet> (subs P xvec Tvec)) = subs (p \\<bullet> P) (p \\<bullet> xvec) (p \\<bullet> Tvec)\"\n  and   \"(p \\<bullet> (subs' I xvec Tvec)) = subs' (p \\<bullet> I) (p \\<bullet> xvec) (p \\<bullet> Tvec)\"\n  and   \"(p \\<bullet> (subs'' C xvec Tvec)) = subs'' (p \\<bullet> C) (p \\<bullet> xvec) (p \\<bullet> Tvec)\"\napply(nominal_induct P and I and C avoiding: xvec Tvec rule: psi_input_psi_case.strong_inducts)\napply(auto simp add: eqvts)\napply(drule_tac pi=p in pt_fresh_bij1[OF pt_name_inst, OF at_name_inst])\napply(drule_tac pi=p in pt_fresh_bij1[OF pt_name_inst, OF at_name_inst])\napply simp\napply(drule_tac pi=p in pt_fresh_bij1[OF pt_name_inst, OF at_name_inst])\napply(drule_tac pi=p in pt_fresh_bij1[OF pt_name_inst, OF at_name_inst])\nby simp\n(*\nlemma subst1:\n  fixes xvec :: \"name list\"\n  and   Tvec :: \"'a list\"\n  and   x    :: name\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   I    :: \"('a, 'b, 'c) input\"\n  and   C    :: \"('a, 'b, 'c) psi_case\"\n\n  assumes \"length xvec = length Tvec\"\n  and     \"distinct xvec\"\n  and     \"x \\<sharp> xvec\"\n\n  shows \"x \\<sharp> (subs P xvec Tvec) \\<Longrightarrow> x \\<sharp> P\"\n  and   \"x \\<sharp> (subs' I xvec Tvec) \\<Longrightarrow> x \\<sharp> I\"\n  and   \"x \\<sharp> (subs'' C xvec Tvec) \\<Longrightarrow> x \\<sharp> C\"\nusing assms\nby(nominal_induct P and I and C avoiding: xvec Tvec rule: psi_input_psi_case.strong_inducts)\n  (auto intro: subst_term.subst1 subst_cond.subst1 subst_assert.subst1 simp add: abs_fresh)\n\nlemma subst1_chain:\n  fixes xvec :: \"name list\"\n  and   Tvec :: \"'a list\"\n  and   Xs   :: \"name set\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   I    :: \"('a, 'b, 'c) input\"\n  and   C    :: \"('a, 'b, 'c) psi_case\"\n\n  assumes \"length xvec = length Tvec\"\n  and     \"distinct xvec\"\n  and     \"Xs \\<sharp>* xvec\"\n\n  shows \"Xs \\<sharp>* (subs P xvec Tvec) \\<Longrightarrow> Xs \\<sharp>* P\"\n  and   \"Xs \\<sharp>* (subs' I xvec Tvec) \\<Longrightarrow> Xs \\<sharp>* I\"\n  and   \"Xs \\<sharp>* (subs'' C xvec Tvec) \\<Longrightarrow> Xs \\<sharp>* C\"\nusing assms\nby(auto intro: subst1 simp add: fresh_star_def)\n*)\nlemma subst2[intro]:\n  fixes xvec :: \"name list\"\n  and   Tvec :: \"'a list\"\n  and   x    :: name\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   I    :: \"('a, 'b, 'c) input\"\n  and   C    :: \"('a, 'b, 'c) psi_case\"\n\n  assumes \"x \\<sharp> Tvec\"\n  and     \"x \\<sharp> xvec\"\n\n  shows \"x \\<sharp> P \\<Longrightarrow> x \\<sharp> (subs P xvec Tvec)\"\n  and   \"x \\<sharp> I \\<Longrightarrow> x \\<sharp> (subs' I xvec Tvec)\"\n  and   \"x \\<sharp> C \\<Longrightarrow> x \\<sharp> (subs'' C xvec Tvec)\"\nusing assms\nby(nominal_induct P and I and C avoiding: xvec Tvec rule: psi_input_psi_case.strong_inducts)\n  (auto intro: subst_term.subst2 subst_cond.subst2 subst_assert.subst2 simp add: abs_fresh)\n\nlemma subst2_chain[intro]:\n  fixes xvec :: \"name list\"\n  and   Tvec :: \"'a list\"\n  and   Xs   :: \"name set\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   I    :: \"('a, 'b, 'c) input\"\n  and   C    :: \"('a, 'b, 'c) psi_case\"\n\n  assumes \"Xs \\<sharp>* xvec\"\n  and     \"Xs \\<sharp>* Tvec\"\n\n  shows \"Xs \\<sharp>* P \\<Longrightarrow> Xs \\<sharp>* (subs P xvec Tvec)\"\n  and   \"Xs \\<sharp>* I \\<Longrightarrow> Xs \\<sharp>* (subs' I xvec Tvec)\"\n  and   \"Xs \\<sharp>* C \\<Longrightarrow> Xs \\<sharp>* (subs'' C xvec Tvec)\"\nusing assms\nby(auto intro: subst2 simp add: fresh_star_def)\n(*\nlemma subst4:\n  fixes xvec :: \"name list\"\n  and   Tvec :: \"'a list\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   I    :: \"('a ,'b, 'c) input\"\n  and   C    :: \"('a, 'b, 'c) psi_case\"\n\n  assumes \"length xvec = length Tvec\"\n  and     \"distinct xvec\"\n\n  shows \"\\<lbrakk>xvec \\<sharp>* P\\<rbrakk> \\<Longrightarrow> (subs P xvec Tvec) = P\"\n  and   \"\\<lbrakk>xvec \\<sharp>* I\\<rbrakk> \\<Longrightarrow> (subs' I xvec Tvec) = I\"\n  and   \"\\<lbrakk>xvec \\<sharp>* C\\<rbrakk> \\<Longrightarrow> (subs'' C xvec Tvec) = C\"\nusing assms\nby(nominal_induct P and I and C avoiding: xvec Tvec rule: psi_input_psi_case.strong_inducts)\n  (auto intro: subst_term.subst4 subst_cond.subst4 subst_assert.subst4 simp add: psi.inject input.inject psi_case.inject)\n\nlemma subst5:\n  fixes xvec  :: \"name list\"\n  and   Tvec  :: \"'a list\"\n  and   yvec  :: \"name list\"\n  and   Tvec' :: \"'a list\"\n  and   P     :: \"('a, 'b, 'c) psi\"\n  and   I     :: \"('a ,'b, 'c) input\"\n  and   C     :: \"('a, 'b, 'c) psi_case\"\n\n  assumes \"length xvec = length Tvec\"\n  and     \"distinct xvec\"\n  and     \"length yvec = length Tvec'\"\n  and     \"distinct yvec\"\n  and     \"yvec \\<sharp>* xvec\"\n  and     \"yvec \\<sharp>* Tvec\"\n\n  shows \"(subs P (xvec@yvec) (Tvec@Tvec')) = subs (subs P xvec Tvec) yvec Tvec'\"\n  and   \"(subs' I (xvec@yvec) (Tvec@Tvec')) = subs' (subs' I xvec Tvec) yvec Tvec'\"\n  and   \"(subs'' C (xvec@yvec) (Tvec@Tvec')) = subs'' (subs'' C xvec Tvec) yvec Tvec'\"\nusing assms\nby(nominal_induct P and I and C avoiding: xvec Tvec yvec Tvec' rule: psi_input_psi_case.strong_inducts)\n  (auto intro: subst_term.subst5 subst_cond.subst5 subst_assert.subst5 simp add: psi.inject input.inject psi_case.inject fresh_list_append)\n*)\nlemma renaming:\n  fixes xvec :: \"name list\"\n  and   Tvec :: \"'a list\"\n  and   p    :: \"name prm\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   I    :: \"('a ,'b, 'c) input\"\n  and   C    :: \"('a, 'b, 'c) psi_case\"\n\n  assumes \"length xvec = length Tvec\"\n  and     \"set p \\<subseteq> set xvec \\<times> set (p \\<bullet> xvec)\"\n  and     \"distinct_perm p\"\n\n  shows \"\\<lbrakk>(p \\<bullet> xvec) \\<sharp>* P\\<rbrakk> \\<Longrightarrow> (subs P xvec Tvec) = subs (p \\<bullet> P) (p \\<bullet> xvec) Tvec\"\n  and   \"\\<lbrakk>(p \\<bullet> xvec) \\<sharp>* I\\<rbrakk> \\<Longrightarrow> (subs' I xvec Tvec) = subs' (p \\<bullet> I) (p \\<bullet> xvec) Tvec\"\n  and   \"\\<lbrakk>(p \\<bullet> xvec) \\<sharp>* C\\<rbrakk> \\<Longrightarrow> (subs'' C xvec Tvec) = subs'' (p \\<bullet> C) (p \\<bullet> xvec) Tvec\"\nusing assms\nby(nominal_induct P and I and C avoiding: xvec p Tvec rule: psi_input_psi_case.strong_inducts)\n  (auto intro: subst_term.renaming subst_cond.renaming subst_assert.renaming simp add: fresh_chain_simps psi.inject input.inject psi_case.inject)\n\nlemma subst4_chain:\n  fixes xvec :: \"name list\"\n  and   Tvec :: \"'a list\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   I    :: \"('a, 'b, 'c) input\"\n  and   C    :: \"('a, 'b, 'c) psi_case\"\n\n  assumes \"length xvec = length Tvec\"\n  and     \"distinct xvec\"\n  and     \"xvec \\<sharp>* Tvec\"\n\n  shows \"xvec \\<sharp>* (subs P xvec Tvec)\"\n  and   \"xvec \\<sharp>* (subs' I xvec Tvec)\"\n  and   \"xvec \\<sharp>* (subs'' C xvec Tvec)\"\nusing assms\nby(nominal_induct P and I and C avoiding: xvec Tvec rule: psi_input_psi_case.strong_inducts)\n  (auto intro: subst_term.subst4_chain subst_cond.subst4_chain subst_assert.subst4_chain simp add: abs_fresh)\n(*\nlemma subst_empty[simp]:\n  fixes P    :: \"('a, 'b, 'c) psi\"\n  and   I    :: \"('a, 'b, 'c) input\"\n  and   C    :: \"('a, 'b, 'c) psi_case\"\n\n  shows \"(subs P [] []) = P\"\n  and   \"(subs' I [] []) = I\"\n  and   \"(subs'' C [] []) = C\"\nusing assms\nby(nominal_induct P and I and C rule: psi_input_psi_case.strong_inducts) auto\n*)\nlemma guarded_subst[simp]:\n  fixes P    :: \"('a, 'b, 'c) psi\"\n  and   I    :: \"('a, 'b, 'c) input\"\n  and   C    :: \"('a, 'b, 'c) psi_case\"\n  and   xvec :: \"name list\"\n  and   Tvec :: \"'a list\"\n\n  shows \"guarded P \\<Longrightarrow> guarded(subs P xvec Tvec)\"\n  and   \"guarded' I \\<Longrightarrow> guarded'(subs' I xvec Tvec)\"\n  and   \"guarded'' C \\<Longrightarrow> guarded''(subs'' C xvec Tvec)\"\nby(nominal_induct P and I and C avoiding: xvec Tvec rule: psi_input_psi_case.strong_inducts) auto\n\ndefinition seq_subs :: \"('a, 'b, 'c) psi \\<Rightarrow> (name list \\<times> 'a list) list \\<Rightarrow> ('a, 'b, 'c) psi\" (\"_[<_>]\" [80, 80] 130)\n  where \"P[<\\<sigma>>] \\<equiv> foldl (\\<lambda>Q. \\<lambda>(xvec, Tvec). subs Q xvec Tvec) P \\<sigma>\"\n\ndefinition seq_subs' :: \"('a, 'b, 'c) input \\<Rightarrow> (name list \\<times> 'a list) list \\<Rightarrow> ('a, 'b, 'c) input\" \n  where \"seq_subs' I \\<sigma> \\<equiv> foldl (\\<lambda>Q. \\<lambda>(xvec, Tvec). subs' Q xvec Tvec) I \\<sigma>\"\n\ndefinition seq_subs'' :: \"('a, 'b, 'c) psi_case \\<Rightarrow> (name list \\<times> 'a list) list \\<Rightarrow> ('a, 'b, 'c) psi_case\"\n  where \"seq_subs'' C \\<sigma> \\<equiv> foldl (\\<lambda>Q. \\<lambda>(xvec, Tvec). subs'' Q xvec Tvec) C \\<sigma>\"\n\nlemma subst_input_chain[simp]:\n  fixes xvec :: \"name list\"\n  and   N    :: \"'a\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   yvec :: \"name list\"\n  and   Tvec :: \"'a list\"\n\n  assumes \"xvec \\<sharp>* yvec\"\n  and     \"xvec \\<sharp>* Tvec\"\n\n  shows \"subs' (input_chain xvec N P) yvec Tvec = input_chain xvec (subst_term N yvec Tvec) (subs P yvec Tvec)\"\nusing assms\nby(induct xvec) (auto simp add: psi.inject)\n\nfun case_list_subst :: \"('c \\<times> ('a, 'b, 'c) psi) list \\<Rightarrow> name list \\<Rightarrow> 'a list \\<Rightarrow> ('c \\<times> ('a, 'b, 'c) psi) list\"\nwhere\n  \"case_list_subst [] _ _ = []\"\n| \"case_list_subst ((\\<phi>, P)#Cs) xvec Tvec = (subst_cond \\<phi> xvec Tvec, (subs P xvec Tvec))#(case_list_subst Cs xvec Tvec)\"\n\nlemma subst_cases[simp]:\n  fixes Cs   :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n  and   xvec :: \"name list\"\n  and   Tvec :: \"'a list\"\n\n  shows \"subs (Cases Cs) xvec Tvec = Cases(case_list_subst Cs xvec Tvec)\"\nby(induct Cs) (auto simp add: psi.inject)\n\nlemma subst_cases'[simp]:\n  fixes Cs   :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n  and   xvec :: \"name list\"\n  and   Tvec :: \"'a list\"\n\n  shows \"(subs'' (psi_cases Cs) xvec Tvec) = psi_cases(case_list_subst Cs xvec Tvec)\"\nby(induct Cs) auto\n\nlemma seq_subst_simps[simp]:\n  shows \"seq_subs (\\<zero>) \\<sigma> = \\<zero>\"\n  and   \"(seq_subs (M\\<langle>N\\<rangle>.P) \\<sigma>) = (subst_term.seq_subst M \\<sigma>)\\<langle>(subst_term.seq_subst N \\<sigma>)\\<rangle>.(seq_subs P \\<sigma>)\"\n  and   \"(seq_subs (M\\<lparr>I) \\<sigma>) = (subst_term.seq_subst M \\<sigma>)\\<lparr>(seq_subs' I \\<sigma>)\"\n\n  and   \"(seq_subs (Case C) \\<sigma>) = (Case (seq_subs'' C \\<sigma>))\"\n  and   \"(seq_subs (P \\<parallel> Q) \\<sigma>) = (seq_subs P \\<sigma>) \\<parallel> (seq_subs Q \\<sigma>)\"\n  and   \"\\<lbrakk>y \\<sharp> \\<sigma>\\<rbrakk> \\<Longrightarrow> (seq_subs (\\<lparr>\\<nu>y\\<rparr>P) \\<sigma>) = \\<lparr>\\<nu>y\\<rparr>(seq_subs P \\<sigma>)\"\n  and   \"(seq_subs (\\<lbrace>\\<Psi>\\<rbrace>) \\<sigma>) = \\<lbrace>(subst_assert.seq_subst \\<Psi> \\<sigma>)\\<rbrace>\"\n  and   \"(seq_subs (!P) \\<sigma>) = !(seq_subs P \\<sigma>)\"\n  \n  and   \"(seq_subs' ((Trm M P)::('a::fs_name, 'b::fs_name, 'c::fs_name) input) \\<sigma>) = (\\<rparr>(subst_term.seq_subst M \\<sigma>).(seq_subs P \\<sigma>))\"\n  and   \"\\<lbrakk>y \\<sharp> \\<sigma>\\<rbrakk> \\<Longrightarrow> (seq_subs' (\\<nu> y I) \\<sigma>) = (\\<nu> y (seq_subs' I \\<sigma>))\"\n  \n  and   \"(seq_subs'' (\\<bottom>\\<^sub>c::('a::fs_name, 'b::fs_name, 'c::fs_name) psi_case) \\<sigma>) = \\<bottom>\\<^sub>c\"\n  and   \"(seq_subs'' (\\<box>\\<Phi> \\<Rightarrow> P C) \\<sigma>) = (\\<box>(subst_cond.seq_subst \\<Phi> \\<sigma>) \\<Rightarrow> (seq_subs P \\<sigma>) (seq_subs'' C \\<sigma>))\"\nby(induct \\<sigma> arbitrary: M N P I C Q \\<Psi> \\<Phi>, auto simp add: seq_subs_def seq_subs'_def seq_subs''_def)\n\nlemma seq_subs_nil[simp]:\n  \"seq_subs P [] = P\"\nby(simp add: seq_subs_def)\n\nlemma seq_subs_cons[simp]:\n  shows \"seq_subs P ((xvec, Tvec)#\\<sigma>) = seq_subs(subs P xvec Tvec) \\<sigma>\"\n  by(simp add: seq_subs_def)\n\nlemma seq_subs_term_append[simp]:\n  shows \"seq_subs P (\\<sigma>@\\<sigma>') = seq_subs (seq_subs P \\<sigma>) \\<sigma>'\"\nby(induct \\<sigma>) (auto simp add: seq_subs_def)\n\nfun case_list_seq_subst :: \"('c \\<times> ('a, 'b, 'c) psi) list \\<Rightarrow> (name list \\<times> 'a list) list \\<Rightarrow> ('c \\<times> ('a, 'b, 'c) psi) list\"\nwhere\n  \"case_list_seq_subst [] _ = []\"\n| \"case_list_seq_subst ((\\<phi>, P)#Cs) \\<sigma> = (subst_cond.seq_subst \\<phi> \\<sigma>, (seq_subs P \\<sigma>))#(case_list_seq_subst Cs \\<sigma>)\"\n\nlemma seq_subst_cases[simp]:\n  fixes Cs :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n  and   \\<sigma>  :: \"(name list \\<times> 'a list) list\"\n\n  shows \"seq_subs (Cases Cs) \\<sigma> = Cases(case_list_seq_subst Cs \\<sigma>)\"\nby(induct Cs) (auto simp add: psi.inject)\n\nlemma seq_subst_cases'[simp]:\n  fixes Cs :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n  and   \\<sigma>  :: \"(name list \\<times> 'a list) list\"\n\n  shows \"(seq_subs'' (psi_cases Cs) \\<sigma>) = psi_cases(case_list_seq_subst Cs \\<sigma>)\"\nby(induct Cs) auto\n\nlemma seq_subst_eqvt[eqvt]:\n  fixes P :: \"('a, 'b, 'c) psi\"\n  and   \\<sigma> :: \"(name list \\<times> 'a list) list\"\n  and   p :: \"name prm\"\n\n  shows \"(p \\<bullet> (P[<\\<sigma>>])) = (p \\<bullet> P)[<(p \\<bullet> \\<sigma>)>]\"\nby(induct \\<sigma> arbitrary: P) (auto simp add: eqvts seq_subs_def)\n\n\nlemma guarded_seq_subst:\n  assumes \"guarded P\"\n\n  shows \"guarded(seq_subs P \\<sigma>)\"\nusing assms\n  by(induct \\<sigma> arbitrary: P) (auto dest: guarded_subst)\n\nend\n\nlemma inter_eqvt:\n  shows \"(pi::name prm) \\<bullet> ((X::name set) \\<inter> Y) = (pi \\<bullet> X) \\<inter> (pi \\<bullet> Y)\"\nby(auto simp add: perm_set_def perm_bij)\n\nlemma delete_eqvt:\n  fixes p :: \"name prm\"\n  and   X :: \"name set\"\n  and   Y :: \"name set\"\n\n  shows \"p \\<bullet> (X - Y) = (p \\<bullet> X) - (p \\<bullet> Y)\"\nby(auto simp add: perm_set_def perm_bij)\n\nlemma perm_singleton[simp]:\n  shows \"(p::name prm) \\<bullet> {(x::name)} = {p \\<bullet> x}\"\nby(auto simp add: perm_set_def)\n\nend", "meta": {"author": "IlmariReissumies", "repo": "newpsi", "sha": "201517d55b6ed1632a5bff2a585367278b5bc67b", "save_path": "github-repos/isabelle/IlmariReissumies-newpsi", "path": "github-repos/isabelle/IlmariReissumies-newpsi/newpsi-201517d55b6ed1632a5bff2a585367278b5bc67b/Agent.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.25559067413455916}}
{"text": "theory IICF_List_List\nimports \n  \"../../Sepref\"\nbegin\n\n\n  context begin\n    private abbreviation (input) \"LR A \\<equiv> \\<langle>\\<langle>A\\<rangle>list_rel\\<rangle>list_rel\"\n\n    sepref_decl_op list_list_lempty: \"\\<lambda>n. replicate n []\" :: \"nat_rel \\<rightarrow> LR A\" .\n    sepref_decl_op list_list_push_back: \"\\<lambda>xss i x. xss[i:=xss!i@[x]]\" \n      :: \"[\\<lambda>((xss,i),_). i<length xss]\\<^sub>f (LR A \\<times>\\<^sub>r nat_rel) \\<times>\\<^sub>r A \\<rightarrow> LR A\" .\n\n    sepref_decl_op list_list_pop_back: \"\\<lambda>xss i. (last (xss!i), xss[i:=butlast (xss!i)])\" \n      :: \"[\\<lambda>(xss,i). i<length xss \\<and> xss!i\\<noteq>[]]\\<^sub>f (LR A \\<times>\\<^sub>r nat_rel)\\<rightarrow> A \\<times>\\<^sub>r LR A\" \n      unfolding conv_to_is_Nil short_circuit_conv\n      by parametricity\n      \n    sepref_decl_op list_list_upd: \"\\<lambda>xss i j x. xss[i:=(xss!i)[j:=x]]\" \n      :: \"[\\<lambda>(((xss,i),j),x). i<length xss \\<and> j<length (xss!i)]\\<^sub>f (((LR A \\<times>\\<^sub>r nat_rel) \\<times>\\<^sub>r nat_rel) \\<times>\\<^sub>r A) \\<rightarrow> LR A\" \n      unfolding short_circuit_conv\n      by parametricity\n      \n    sepref_decl_op list_list_idx: \"\\<lambda>xss i j. xss!i!j\" :: \"[\\<lambda>((xss,i),j). i<length xss \\<and> j<length (xss!i)]\\<^sub>f ((LR A \\<times>\\<^sub>r nat_rel) \\<times>\\<^sub>r nat_rel) \\<rightarrow> A\" \n      unfolding short_circuit_conv\n      by parametricity\n    \n    sepref_decl_op list_list_llen: \"\\<lambda>xss i. length (xss!i)\" :: \"[\\<lambda>(xss,i). i<length xss]\\<^sub>f LR A \\<times>\\<^sub>r nat_rel \\<rightarrow> nat_rel\" .\n    (* TODO: list_list is a proper subtype of list. So share operations! length, empty, ... *)\n    sepref_decl_op list_list_len: \"length :: _ list list \\<Rightarrow> _\" :: \"LR A \\<rightarrow> nat_rel\" .\n    \n    sepref_decl_op list_list_take: \"\\<lambda>xss i l. (xss[i:=take l (xss!i)])\" \n      :: \"[\\<lambda>((xss,i),l). i<length xss \\<and> l\\<le>length (xss!i)]\\<^sub>f ((LR A \\<times>\\<^sub>r nat_rel) \\<times>\\<^sub>r nat_rel)\\<rightarrow> LR A\" \n      unfolding conv_to_is_Nil short_circuit_conv\n      by parametricity\n    \n  end\n\n  locale list_list_custom_empty = \n    fixes rel empty PRE and op_custom_empty :: \"nat \\<Rightarrow> 'a list list\"\n    assumes customize_hnr_aux: \"(empty,(RETURN o (op_list_list_lempty::nat \\<Rightarrow> 'a list list))) \\<in> [PRE]\\<^sub>a snat_assn\\<^sup>k \\<rightarrow> rel\"\n    assumes op_custom_empty_def: \"op_custom_empty = op_list_list_lempty\"\n  begin\n    sepref_register op_custom_empty :: \"nat \\<Rightarrow> 'c list list\"\n  \n    lemma fold_custom_empty:\n      \"replicate n [] = op_custom_empty n\"\n      \"op_list_list_lempty = op_custom_empty\"\n      \"mop_list_list_lempty n = RETURN (op_custom_empty n)\"\n      unfolding op_custom_empty_def by simp_all\n  \n    lemmas custom_hnr[sepref_fr_rules] = customize_hnr_aux[folded op_custom_empty_def]\n  end\n\n\n  text \\<open>Fold lemmas for manual folding.\\<close>\n  (* TODO: Why not use interface and op-id for that? *)\n  lemma fold_op_list_list_push_back: \"xss[i:=xss!i@[x]] = op_list_list_push_back xss i x\" by simp\n  lemma fold_op_list_list_pop_back: \"(last (xss!i), xss[i:=butlast (xss!i)]) = op_list_list_pop_back xss i\" by simp\n  lemma fold_op_list_list_upd: \"xss[i:=(xss!i)[j:=x]] = op_list_list_upd xss i j x\" by simp\n  lemma fold_op_list_list_idx: \"xs!i!j = op_list_list_idx xs i j\" by simp\n  lemma fold_op_list_list_llen: \"length (xs!i) = op_list_list_llen xs i\" by simp\n  lemma fold_op_list_list_take: \"xss[i:=take n (xss!i)] = op_list_list_take xss i n\" by simp\n\n  lemmas fold_op_list_list = \n    fold_op_list_list_push_back\n    fold_op_list_list_pop_back \n    fold_op_list_list_upd\n    fold_op_list_list_idx\n    fold_op_list_list_llen\n    fold_op_list_list_take  \n  \nend\n", "meta": {"author": "lammich", "repo": "isabelle_llvm", "sha": "6be37a9c3cae74a1134dbef2979e312abb5f7f42", "save_path": "github-repos/isabelle/lammich-isabelle_llvm", "path": "github-repos/isabelle/lammich-isabelle_llvm/isabelle_llvm-6be37a9c3cae74a1134dbef2979e312abb5f7f42/thys/sepref/IICF/Intf/IICF_List_List.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.25559067413455916}}
{"text": "theory flash7Rev imports flashPub\nbegin\nsection{*Main defintions*}\n\n\nlemma lemmaOnPtrAtGetX[intro]:\n  assumes  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n    and a5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_GetX )) s\" and\n    a6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2)) s \" and\n    a7:\"\\<forall>f. f \\<in> (invariants   N) \\<longrightarrow> formEval f s \"\n shows  \"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n proof(rule ccontr)\n  assume b0:\"\\<not>formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n  have b1:\"formEval (inv2 iInv1 iInv2) s\"\n    apply(cut_tac a7)\n    \n    apply(drule_tac x=\"inv2  iInv1 iInv2\" in spec)\n    apply(cut_tac a7 a2 a3 a4,simp)\n    done\n with b0 a5 a6 show False\n  by auto\nqed  \n\n\n\nlemma lemmaOnPtrAtGet[intro]:\n  assumes  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n    and a5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get )) s\" and\n    a6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2)) s \" and\n    a7:\"\\<forall>f. f \\<in> (invariants   N) \\<longrightarrow> formEval f s \"\n shows  \"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n proof(rule ccontr)\n  assume b0:\"\\<not>formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n  have b1:\"formEval (inv3 iInv1 iInv2) s\"\n    apply(cut_tac a7)\n    \n    apply(drule_tac x=\"inv3  iInv1 iInv2\" in spec)\n    apply(cut_tac a7 a2 a3 a4,simp)\n    done\n with b0 a5 a6 show False\n  by auto\nqed  \n\nlemma lemmaOnPtr1[intro]:\n  assumes  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n    and a5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get )) s\" and\n    a6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2)) s \" and\n    a7:\"\\<forall>f. f \\<in> (invariants   N) \\<longrightarrow> formEval f s \" and\n    b2:\"iInv1' \\<le> N\" and  b3:\"iInv2' \\<le> N\" and  b4:\"iInv1'~=iInv2'  \" \n    and b5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1') )  ( Const UNI_Get )) s\" and\n    b6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1') )   (Const iInv2')) s \" and\n    b7:\"iInv2\\<noteq>iInv2'\"\n shows False\n proof -\n  have c1:\"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n    by(metis a2 a3 a4 a5 a6 a7 lemmaOnPtrAtGet)\n  have c2:\"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2') )  s\"\n    by(metis b2 b3 b4 b5 b6 a7 lemmaOnPtrAtGet)\n with c1 b7  show False\n  by auto\nqed  \n\n\nlemma lemmaOnPtr2[intro]:\n  assumes  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n    and a5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_GetX )) s\" and\n    a6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2)) s \" and\n    a7:\"\\<forall>f. f \\<in> (invariants   N) \\<longrightarrow> formEval f s \" and\n    b2:\"iInv1' \\<le> N\" and  b3:\"iInv2' \\<le> N\" and  b4:\"iInv1'~=iInv2'  \" \n    and b5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1') )  ( Const UNI_GetX )) s\" and\n    b6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1') )   (Const iInv2')) s \" and\n    b7:\"iInv2\\<noteq>iInv2'\"\n shows False\n proof -\n  have c1:\"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n    by(metis a2 a3 a4 a5 a6 a7 lemmaOnPtrAtGetX)\n  have c2:\"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2') )  s\"\n    by(metis b2 b3 b4 b5 b6 a7 lemmaOnPtrAtGetX)\n with c1 b7  show False\n  by auto\nqed \n\n\nlemma lemmaOnPtr3[intro]:\n  assumes  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n    and a5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get )) s\" and\n    a6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2)) s \" and\n    a7:\"\\<forall>f. f \\<in> (invariants   N) \\<longrightarrow> formEval f s \" and\n    b2:\"iInv1' \\<le> N\" and  b3:\"iInv2' \\<le> N\" and  b4:\"iInv1'~=iInv2'  \" \n    and b5:\"formEval ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1') )  ( Const UNI_GetX )) s\" and\n    b6:\"formEval   ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1') )   (Const iInv2')) s \" and\n    b7:\"iInv2\\<noteq>iInv2'\"\n shows False\n proof -\n  have c1:\"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2) )  s\"\n    by(metis a2 a3 a4 a5 a6 a7 lemmaOnPtrAtGet)\n  have c2:\"formEval ( eqn ( IVar ( Global ''Dir_HeadPtr'') )   (Const iInv2') )  s\"\n    by(metis b2 b3 b4 b5 b6 a7 lemmaOnPtrAtGetX)\n with c1 b7  show False\n  by auto\nqed      \n     \n\nabbreviation N::\"nat\"   where   \"N\\<equiv> M\"\nlemma NI_FAckVsInv7:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_InvVsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_InvAck_1VsInv7:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1_HomeVsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_InvAck_2VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_GetXVsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak1VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak2VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak3VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX1VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv7:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10VsInv7:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10_homeVsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX11VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_GetVsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''ShWbMsg_Cmd'') )  ( Const SHWB_FAck ))    ( eqn ( IVar ( Global ''Dir_Pending'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak1VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak2VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak3VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put1VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put2VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put3VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_PutVsInv7:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_PutXAcksDoneVsInv7:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_NakVsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Nak_ClearVsInv7:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Nak_HomeVsInv7:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_NakVsInv7:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_Nak_HomeVsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Remote_GetX_PutXVsInv7Aux:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule'' s (inv7  iInv1  iInv2 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      \n      have \"invHoldForRule3' s (inv7  iInv1  iInv2 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" \n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n     then have \"?P3 s\"\n       by(rule weak3)\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n       have \"invHoldForRule3' s (inv7  iInv1  iInv2 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" \n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Para ''CacheState'' iRule2) )  ( Const CACHE_E ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n\n       then have \"?P3 s\"\n        by(rule weak3)\n        \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"invHoldForRule3' s (inv7  iInv1  iInv2 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n      then have \"?P3 s\"\n        by(rule weak3)\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  \n        have \"invHoldForRule3' s (inv7  iInv1  iInv2 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( andForm ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_Get ))    ( eqn ( IVar ( Para ''UniMsg_proc'' iRule1) )   (Const iInv2))  )    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iRule1) )  ( Const UNI_GetX ))  )    ( eqn ( IVar ( Para ''UniMsg_proc'' iInv1) )   (Const iInv2))  ) ) \" in exI,auto)\n \n        \n        done\n      then have \"?P3 s\"\n        by(rule weak3)\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P3 s\"\n                  proof( unfold invHoldForRule3''_def,simp only:Let_def,( rule impI)+,                   rule ccontr)\n                   assume c1:\"\\<forall>f'. f' \\<in> invariants N \\<longrightarrow> formEval f' s\" and c2:\"formEval (pre (NI_Remote_GetX_PutX iRule1 iRule2)) s \"\n                    and c3:\"\\<not> formEval (substFormByStatement (inv7 iInv1 iInv2) (act (NI_Remote_GetX_PutX iRule1 iRule2))) s\"\n                   have d1:\" formEval (eqn (IVar (Para ''UniMsg_Cmd'' iInv1)) (Const UNI_Get)) s\" by(cut_tac b1 c2 c3, auto)\n                   have d2:\"formEval (eqn (IVar (Para ''UniMsg_Cmd'' iRule1)) (Const UNI_GetX)) s\" by(cut_tac b1 c2 c3, auto)\n                   have d3:\"formEval (eqn (IVar (Para ''UniMsg_proc'' iInv1)) (Const iInv2)) s\"  by(cut_tac b1 c2 c3, auto)\n                   have d4:\"formEval (eqn (IVar (Para ''UniMsg_proc'' iRule1)) (Const iRule2)) s\"  by(cut_tac b1 c2 c3, auto)\n                    show False thm lemmaOnPtr2\n                    apply(cut_tac a1 a2 a3 a4 a5 a6 b1 c1 c2 c3 d1 d2 d3 d4,blast )\n                    done\n                   qed\n   \n \n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_PutXVsInv7:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")\nby (metis NI_Remote_GetX_PutXVsInv7Aux a2 a3 a4 a5 a6 local.a1 strengthEn)   \n \nlemma NI_Remote_GetX_PutX_HomeVsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Remote_Get_Nak1VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Remote_Get_Nak2VsInv7:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Put1VsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Remote_Get_Put2VsInv7:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutVsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutXVsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_ReplaceVsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_ReplaceHomeVsInv7:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceHomeShrVldVsInv7:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceShrVldVsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_ShWbVsInv7:  \n  (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n  fix s \n \n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_WbVsInv7:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_GetX1VsInv7:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_GetX2VsInv7:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX1VsInv7:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX2VsInv7:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX3VsInv7:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX4VsInv7:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_Get_GetVsInv7:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_Get_PutVsInv7:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_PutXVsInv7:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_ReplaceVsInv7:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_GetVsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_GetXVsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_PutXVsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma PI_Remote_ReplaceVsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma StoreVsInv7:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma StoreHomeVsInv7:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv7  iInv1  iInv2 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash7Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.25559067413455916}}
{"text": "section \\<open> Circus State Machine Semantics \\<close>\n\ntheory Circus_SM_Semantics\n  imports \"RoboChart.RoboChart\" Actions\nbegin recall_syntax\n\nsubsection \\<open> Alphabet \\<close>\n\nalphabet robochart_ctrl =\n  rc_ctrl :: ID \n\ntype_synonym 's rcst = \"'s robochart_ctrl_scheme\"\ntype_synonym ('s, 'e) RoboAction = \"('s robochart_ctrl_scheme, 'e) Actions.Action\"\ntype_synonym 's RoboPred = \"'s robochart_ctrl_scheme upred\"\n\ntranslations\n  (type) \"'s rcst\" <= (type) \"'s robochart_ctrl_scheme\"\n  (type) \"('s, 'e) RoboAction\" <= (type) \"('s rcst, 'e) Action\"\n  (type) \"'s RoboPred\" <= (type) \"'s rcst upred\"\n\nabbreviation \"rc_state \\<equiv> robochart_ctrl.more\\<^sub>L\"\n\nnotation rc_state (\"\\<^bold>r\")\n\nsyntax\n  \"_svid_rc_state\"  :: \"svid\" (\"\\<^bold>r\")\n\ntranslations\n  \"_svid_rc_state\" == \"CONST rc_state\"\n  \"_svid_dot \\<^bold>r x\" <= \"x ;\\<^sub>L \\<^bold>r\"\n\ntype_synonym ('s, 'e) RTransition = \"('s upred, ('s, 'e) Action, unit) STransition\"\ntype_synonym ('s, 'e) RNode = \"('s upred, ('s, 'e) Action, unit) SNode\"\ntype_synonym ('s, 'e) RStateMachine = \"('s upred, ('s, 'e) Action, unit) SStateMachine\"\n\nsubsection \\<open> State Machine Semantics \\<close>\n\nnamed_theorems sm_sem\n\nabbreviation \"trigger_semantics t \\<equiv> \n  (case tn_trigger t of \n    Some e \\<Rightarrow> e | \n    None \\<Rightarrow> skip)\"\n\ndefinition tn_condition :: \"('s, 'e) RTransition \\<Rightarrow> 's upred\" where\n[sm_sem]: \"tn_condition t = case_option true_upred id (tn_cond t)\"\n\ndefinition tn_action :: \"('s, 'e) RTransition \\<Rightarrow> ('s, 'e) Action\" where\n[sm_sem]: \"tn_action t = case_option skip id (tn_act t)\"\n\nno_utp_lift tn_condition\n\ndefinition tr_semantics :: \"('s, 'e) RTransition \\<Rightarrow> (unit, 'e) chan \\<Rightarrow> ('s, 'e) RoboAction\" (\"\\<lbrakk>_\\<rbrakk>\\<^sub>T\") where\n[sm_sem]: \"tr_semantics t \\<epsilon> \\<equiv> \n  let tsem = trigger_semantics t ; tn_action t\n  in\n  tn_condition t \\<oplus>\\<^sub>p rc_state \\<^bold>& \n  rc_state:[if productive tsem then tsem else tsem ; sync \\<epsilon>]\\<^sub>A\\<^sup>+ ; rc_ctrl := \\<guillemotleft>tn_target t\\<guillemotright>\"\n\ndefinition [sm_sem]: \"n_entry_sem n = case_option skip id (n_entry n)\"\n\ndefinition [sm_sem]: \"n_exit_sem n = case_option skip id (n_exit n)\"\n\ndefinition node_semantics ::  \n  \"('s, 'e) RStateMachine \\<Rightarrow> (unit, 'e) chan \\<Rightarrow> ('s, 'e) RNode \\<Rightarrow> ('s, 'e) RoboAction\" (\"_;_ \\<turnstile> \\<lbrakk>_\\<rbrakk>\\<^sub>N\" [10,0,0] 10) where\n[sm_sem]: \"node_semantics M \\<epsilon> node  = \n  (rc_state:[n_entry_sem node]\\<^sub>A\\<^sup>+ ;\n   (foldr (\\<box>) (map (\\<lambda> t. \\<lbrakk>t\\<rbrakk>\\<^sub>T \\<epsilon>) (the (Tmap\\<^bsub>M\\<^esub> (n_name node)))) stop) ;\n   rc_state:[n_exit_sem node]\\<^sub>A\\<^sup>+)\"\n\ndataspace stm_context =\n  channels null_event :: unit \n\ncontext stm_context\nbegin\n\nnotation null_event (\"\\<epsilon>\")\n\nend\n\ndefinition sm_semantics :: \"('st, 'ch) RStateMachine \\<Rightarrow> _ \\<Rightarrow> ('st, 'ch) RoboAction\" (\"\\<lbrakk>_\\<rbrakk>\\<^sub>M\") where\n[sm_sem]:\n\"sm_semantics M null_event =\n    (rc_ctrl := \\<guillemotleft>sm_initial M\\<guillemotright> ;\n    iteration (map (\\<lambda> n. (&rc_ctrl =\\<^sub>u \\<guillemotleft>n_name n\\<guillemotright>, M;null_event \\<turnstile> \\<lbrakk>n\\<rbrakk>\\<^sub>N)) (sm_inters M)))\"\n\nlemma tr_semantics_subst_ctrl: \"[&rc_ctrl \\<mapsto>\\<^sub>s \\<guillemotleft>k\\<guillemotright>] \\<dagger> (\\<lbrakk>a\\<rbrakk>\\<^sub>T null_event) = \\<lbrakk>a\\<rbrakk>\\<^sub>T null_event\"\n  by (simp add: tr_semantics_def action_simp action_subst usubst unrest frame_asubst Let_unfold)\n\nlemma tr_choice_subst_ctrl:\n  \"[&rc_ctrl \\<mapsto>\\<^sub>s \\<guillemotleft>k\\<guillemotright>] \\<dagger> foldr (\\<box>) (map (\\<lambda>t. \\<lbrakk>t\\<rbrakk>\\<^sub>T null_event) ts) stop = foldr (\\<box>) (map (\\<lambda>t. \\<lbrakk>t\\<rbrakk>\\<^sub>T null_event) ts) stop\"\n  by (induct ts, simp_all add: action_simp action_subst usubst tr_semantics_subst_ctrl)\n\nlemma sm_semantics_subst_ctrl:\n  \"[&rc_ctrl \\<mapsto>\\<^sub>s \\<guillemotleft>k\\<guillemotright>] \\<dagger> node_semantics M null_event node = node_semantics M null_event node\"\n  by (simp add: node_semantics_def action_simp action_subst frame_asubst tr_choice_subst_ctrl unrest)\n\n(* Tests *)\n\ndefinition \"circus_predT stT = Type @{type_name upred} [stT]\"\ndefinition \"circus_actionT stT evT = Type @{type_name Action} [stT, evT]\"\ndefinition \"circus_probT stT = @{typ unit}\"\ndefinition \"actionN = STR ''action''\"\n\ndefinition \"action_eq = \n  mk_equals (free actionN) (const @{const_name sm_semantics} $ free machineN $ free STR ''null_event'')\"\n\ndefinition \"add_stm_context smd = \n  smd\\<lparr> uses := STR ''stm_context'' # uses smd \\<rparr>\"\n\ncode_reflect RC_Circus_Semantics\n  functions circus_predT circus_actionT circus_probT action_eq add_stm_context\n\nsetup \\<open>\n  let open RC_Compiler; open RC_Circus_Semantics; open Specification\n    val cont = snd o definition NONE [] [] ((Binding.empty, []), action_eq)\n    val circus_types = RCTypes_ext (circus_predT, @{nonterminal utp_expr}, circus_actionT, @{nonterminal \"raction\"}, circus_probT, @{nonterminal utp_expr}, ())\n    val circus_semantics = \n      stm_sem_update (K (context_Stm_Semantics cont o add_stm_context)) null_RCSem_Proc\n      |> rctypes_update (K circus_types)\n  in\n    Stm_Sem.put circus_semantics\n  end\n\\<close>\n\nlemma entry_basic_Node [simp]: \"n_entry_sem (basic_Node n) = skip\"\n  by (simp add: n_entry_sem_def basic_Node_def)\n\nlemma exit_basic_Node [simp]: \"n_exit_sem (basic_Node n) = skip\"\n  by (simp add: n_exit_sem_def basic_Node_def)\n\nlemma basic_Node_sem:\n  \"(M;\\<epsilon> \\<turnstile> \\<lbrakk>basic_Node n\\<rbrakk>\\<^sub>N) = foldr (\\<box>) (map (\\<lambda>t. \\<lbrakk>t\\<rbrakk>\\<^sub>T \\<epsilon>) (the (Tmap\\<^bsub>M\\<^esub> n))) stop\"\n  by (simp add: node_semantics_def action_simp)\n\nend", "meta": {"author": "isabelle-utp", "repo": "RoboChart-Isabelle", "sha": "4d7306d6791c195c081a918e5e249c3a9712be5c", "save_path": "github-repos/isabelle/isabelle-utp-RoboChart-Isabelle", "path": "github-repos/isabelle/isabelle-utp-RoboChart-Isabelle/RoboChart-Isabelle-4d7306d6791c195c081a918e5e249c3a9712be5c/Semantics/Circus_Semantics/Circus_SM_Semantics.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.25559067413455916}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2005         |\n            |               December 2005  (modified)   |\n            |                  April 2006  (modified)   |\n            |                  March 2007  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory CSP_T_law_step_ext\nimports CSP_T_law_basic\nbegin\n\n(*****************************************************************\n\n         1. step laws\n         2.\n         3. \n         4. \n\n *****************************************************************)\n\n(*********************************************************\n             Parallel expansion & distribution\n *********************************************************)\n\nlemma cspT_Parallel_Timeout_split:\n  \"((? :Y -> Pf) [> P) |[X]| ((? :Z -> Qf) [> Q) =T[M,M]\n     (? x:((X Int Y Int Z) Un (Y - X) Un (Z - X))\n         -> IF (x : X) THEN (Pf x |[X]| Qf x)\n               ELSE IF (x : Y & x : Z) THEN ((Pf x |[X]| ((? x:Z -> Qf x) [> Q))\n                                        |~| (((? x:Y -> Pf x) [> P) |[X]| Qf x))\n               ELSE IF (x : Y) THEN (Pf x |[X]| ((? x:Z -> Qf x) [> Q))\n               ELSE (((? x:Y -> Pf x) [> P) |[X]| Qf x))\n     [> (((P |[X]| ((? :Z -> Qf) [> Q)) |~|\n         (((? :Y -> Pf) [> P) |[X]| Q)))\"\napply (fold Timeout_def)\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_traces_Timeout in_traces)\n apply (elim conjE exE disjE)\n apply (simp_all)\n  apply (force)\n  apply (force)\n  apply (force)\n  apply (force)\n\n  apply (simp add: par_tr_head_Ev_Ev)\n  apply (elim conjE exE disjE)\n\n   apply (simp)\n   apply (rule disjI1)\n   apply (rule_tac x=\"c\" in exI)\n   apply (rule_tac x=\"v\" in exI)\n   apply (force)\n\n   apply (simp)\n   apply (rule disjI1)\n   apply (rule_tac x=\"c\" in exI)\n   apply (rule_tac x=\"v\" in exI)\n   apply (force)\n\n   apply (simp)\n   apply (rule disjI1)\n   apply (rule_tac x=\"c\" in exI)\n   apply (rule_tac x=\"v\" in exI)\n   apply (force)\n\n  apply (force)\n  apply (force)\n  apply (force)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_traces_Timeout in_traces)\n apply (elim conjE exE disjE)\n apply (simp_all)\n\n  apply (simp add: in_traces)\n  apply (elim conjE exE)\n  apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n  apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n  apply (simp add: par_tr_head)\n\n  apply (simp add: in_traces_IF)\n  apply (case_tac \"a : Z\")\n\n  (* a : Z *)\n   apply (simp add: in_traces_Timeout in_traces)\n   apply (elim conjE exE disjE)\n   apply (simp_all)\n\n    apply (simp add: par_tr_nil_right)\n    apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n    apply (rule_tac x=\"<>\" in exI)\n    apply (simp add: par_tr_nil_right)\n    apply (force)\n\n    apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n    apply (rule_tac x=\"ta\" in exI)\n    apply (simp add: par_tr_head)\n\n    apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n    apply (rule_tac x=\"ta\" in exI)\n    apply (simp add: par_tr_head)\n\n    apply (rule_tac x=\"sa\" in exI)\n    apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n    apply (simp add: par_tr_head)\n\n    apply (rule_tac x=\"sa\" in exI)\n    apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n    apply (simp add: par_tr_head)\n\n    apply (rule_tac x=\"sa\" in exI)\n    apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n    apply (simp add: par_tr_head)\n\n  (* a ~: Z *)\n   apply (simp add: in_traces_Timeout in_traces)\n   apply (elim conjE exE disjE)\n\n    apply (simp add: par_tr_nil_right)\n    apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n    apply (rule_tac x=\"<>\" in exI)\n    apply (simp add: par_tr_nil_right)\n    apply (force)\n\n    apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n    apply (rule_tac x=\"ta\" in exI)\n    apply (simp add: par_tr_head)\n\n    apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n    apply (rule_tac x=\"ta\" in exI)\n    apply (simp add: par_tr_head)\n\n  apply (simp add: in_traces_IF)\n  apply (case_tac \"a : Y\")\n\n  (* a : Y *)\n   apply (simp add: in_traces_Timeout in_traces)\n   apply (elim conjE exE disjE)\n   apply (simp_all)\n\n    apply (simp add: par_tr_nil_right)\n    apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n    apply (rule_tac x=\"<>\" in exI)\n    apply (simp add: par_tr_nil_right)\n    apply (force)\n\n    apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n    apply (rule_tac x=\"ta\" in exI)\n    apply (simp add: par_tr_head)\n\n    apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n    apply (rule_tac x=\"ta\" in exI)\n    apply (simp add: par_tr_head)\n\n    apply (rule_tac x=\"sa\" in exI)\n    apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n    apply (simp add: par_tr_head)\n\n    apply (rule_tac x=\"sa\" in exI)\n    apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n    apply (simp add: par_tr_head)\n\n    apply (rule_tac x=\"sa\" in exI)\n    apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n    apply (simp add: par_tr_head)\n\n  (* a ~:Y *)\n   apply (simp add: in_traces_Timeout in_traces)\n   apply (elim conjE exE disjE)\n\n    apply (simp add: par_tr_nil_left)\n    apply (rule_tac x=\"<>\" in exI)\n    apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n    apply (simp add: par_tr_nil_left)\n    apply (force)\n\n    apply (rule_tac x=\"sa\" in exI)\n    apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n    apply (simp add: par_tr_head)\n\n    apply (rule_tac x=\"sa\" in exI)\n    apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n    apply (simp add: par_tr_head)\n\n  (* *)\n  apply (force)\n  apply (force)\n  apply (force)\n  apply (force)\n  apply (force)\n  apply (force)\ndone\n\n(*********************************************************\n            Parallel expansion & distribution 2\n *********************************************************)\n\nlemma cspT_Parallel_Timeout_input_l: \n  \"((? :Y -> Pf) [> P) |[X]| (? :Z -> Qf) =T[M,M]\n     (? x:((X Int Y Int Z) Un (Y - X) Un (Z - X))\n         -> IF (x : X) THEN (Pf x |[X]| Qf x)\n               ELSE IF (x : Y & x : Z) THEN ((Pf x |[X]| (? x:Z -> Qf x))\n                                        |~| (((? x:Y -> Pf x) [> P) |[X]| Qf x))\n               ELSE IF (x : Y) THEN (Pf x |[X]| (? x:Z -> Qf x))\n               ELSE (((? x:Y -> Pf x) [> P) |[X]| Qf x))\n     [> (((P |[X]| (? :Z -> Qf))))\"\napply (fold Timeout_def)\napply (simp add: cspT_semantics)\napply (rule order_antisym)\n\n(* => *)\n apply (rule)\n apply (simp add: in_traces_Timeout in_traces)\n apply (elim conjE exE disjE)\n apply (simp_all)\n\n  apply (simp add: par_tr_nil_left)\n  apply (rule disjI1)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"sa\" in exI)\n  apply (elim conjE)\n  apply (simp add: image_iff)\n  apply (case_tac \"a:Y\")\n   apply (simp)\n   apply (rule disjI2)\n   apply (rule_tac x=\"<>\" in exI)\n   apply (rule_tac x=\"sa\" in exI)\n   apply (simp add: par_tr_nil_left)\n\n   apply (simp)\n   apply (rule_tac x=\"<>\" in exI)\n   apply (rule_tac x=\"sa\" in exI)\n   apply (simp add: par_tr_nil_left)\n\n  apply (simp add: par_tr_nil_right)\n  apply (rule disjI1)\n  apply (rule_tac x=\"a\" in exI)\n  apply (rule_tac x=\"sa\" in exI)\n  apply (elim conjE)\n  apply (simp add: image_iff)\n  apply (case_tac \"a:Z\")\n   apply (simp)\n   apply (rule disjI1)\n   apply (rule_tac x=\"sa\" in exI)\n   apply (rule_tac x=\"<>\" in exI)\n   apply (simp add: par_tr_nil_right)\n\n   apply (simp)\n   apply (rule_tac x=\"sa\" in exI)\n   apply (rule_tac x=\"<>\" in exI)\n   apply (simp add: par_tr_nil_right)\n\n  apply (force)\n\n  apply (simp add: par_tr_head_Ev_Ev)\n  apply (elim conjE exE disjE)\n\n   apply (simp)\n   apply (rule disjI1)\n   apply (rule_tac x=\"c\" in exI)\n   apply (rule_tac x=\"v\" in exI)\n   apply (force)\n\n   apply (simp)\n   apply (rule disjI1)\n   apply (rule_tac x=\"c\" in exI)\n   apply (rule_tac x=\"v\" in exI)\n   apply (force)\n\n   apply (simp)\n   apply (rule disjI1)\n   apply (rule_tac x=\"c\" in exI)\n   apply (rule_tac x=\"v\" in exI)\n   apply (force)\n\n  apply (force)\n\n(* <= *)\n apply (rule)\n apply (simp add: in_traces_Timeout in_traces)\n apply (elim conjE exE disjE)\n apply (simp_all)\n\n  apply (simp add: in_traces)\n  apply (elim conjE exE)\n  apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n  apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n  apply (simp add: par_tr_head)\n\n  apply (simp add: in_traces_IF)\n  apply (case_tac \"a : Z\")\n\n  (* a : Z *)\n   apply (simp add: in_traces_Timeout in_traces)\n   apply (elim conjE exE disjE)\n   apply (simp_all)\n\n    apply (simp add: par_tr_nil_right)\n    apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n    apply (rule_tac x=\"<>\" in exI)\n    apply (simp add: par_tr_nil_right)\n    apply (force)\n\n    apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n    apply (rule_tac x=\"ta\" in exI)\n    apply (simp add: par_tr_head)\n\n    apply (rule_tac x=\"<>\" in exI)\n    apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n    apply (simp add: par_tr_head)\n\n    apply (rule_tac x=\"<Ev aa> ^^^ sb\" in exI)\n    apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n    apply (simp add: par_tr_head)\n\n    apply (rule_tac x=\"sa\" in exI)\n    apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n    apply (simp add: par_tr_head)\n\n  (* a ~: Z *)\n   apply (simp add: in_traces_Timeout in_traces)\n   apply (elim conjE exE disjE)\n\n    apply (simp add: par_tr_nil_right)\n    apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n    apply (rule_tac x=\"<>\" in exI)\n    apply (simp add: par_tr_nil_right)\n    apply (force)\n\n    apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n    apply (rule_tac x=\"ta\" in exI)\n    apply (simp add: par_tr_head)\n\n  apply (simp add: in_traces_IF)\n  apply (case_tac \"a : Y\")\n\n  (* a : Y *)\n   apply (simp add: in_traces_Timeout in_traces)\n   apply (elim conjE exE disjE)\n   apply (simp_all)\n\n    apply (simp add: par_tr_nil_right)\n    apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n    apply (rule_tac x=\"<>\" in exI)\n    apply (simp add: par_tr_nil_right)\n    apply (force)\n\n    apply (rule_tac x=\"<Ev a> ^^^ sa\" in exI)\n    apply (rule_tac x=\"ta\" in exI)\n    apply (simp add: par_tr_head)\n\n    apply (simp add: par_tr_nil_left)\n    apply (rule_tac x=\"<>\" in exI)\n    apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n    apply (simp add: par_tr_nil_left)\n    apply (force)\n\n    apply (rule_tac x=\"<Ev aa> ^^^ sb\" in exI)\n    apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n    apply (simp add: par_tr_head)\n\n    apply (rule_tac x=\"sa\" in exI)\n    apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n    apply (simp add: par_tr_head)\n\n  (* a ~:Y *)\n   apply (simp add: in_traces_Timeout in_traces)\n   apply (elim conjE exE disjE)\n\n    apply (simp add: par_tr_nil_left)\n    apply (rule_tac x=\"<>\" in exI)\n    apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n    apply (simp add: par_tr_nil_left)\n    apply (force)\n\n    apply (rule_tac x=\"sa\" in exI)\n    apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n    apply (simp add: par_tr_head)\n\n    apply (rule_tac x=\"sa\" in exI)\n    apply (rule_tac x=\"<Ev a> ^^^ ta\" in exI)\n    apply (simp add: par_tr_head)\n\n  (* *)\n  apply (force)\n  apply (force)\ndone\n\nlemma cspT_Parallel_Timeout_input_r: \n  \"(? :Y -> Pf) |[X]| ((? :Z -> Qf) [> Q) =T[M,M]\n     (? x:((X Int Y Int Z) Un (Y - X) Un (Z - X))\n         -> IF (x : X) THEN (Pf x |[X]| Qf x)\n               ELSE IF (x : Y & x : Z) THEN ((Pf x |[X]| ((? x:Z -> Qf x) [> Q))\n                                        |~| ((? x:Y -> Pf x) |[X]| Qf x))\n               ELSE IF (x : Y) THEN (Pf x |[X]| ((? x:Z -> Qf x) [> Q))\n               ELSE ((? x:Y -> Pf x) |[X]| Qf x))\n     [> ((((? :Y -> Pf) |[X]| Q)))\"\napply (rule cspT_rw_left)\napply (rule cspT_commut)\n\napply (rule cspT_rw_left)\napply (rule cspT_Parallel_Timeout_input_l)\n\napply (rule cspT_decompo)\napply (rule cspT_decompo)\napply (rule cspT_decompo)\napply (force)\n\napply (case_tac \"a : X\")\napply (simp)\napply (rule cspT_rw_left)\napply (rule cspT_IF)\napply (rule cspT_rw_right)\napply (rule cspT_IF)\napply (rule cspT_commut)\n\napply (simp)\napply (rule cspT_rw_left)\napply (rule cspT_IF)\napply (rule cspT_rw_right)\napply (rule cspT_IF)\n\napply (case_tac \"(a : Z & a : Y)\")\napply (simp)\napply (rule cspT_rw_left)\napply (rule cspT_IF)\napply (rule cspT_rw_right)\napply (rule cspT_IF)\n\napply (rule cspT_rw_left)\napply (rule cspT_commut)\napply (rule cspT_decompo)\napply (rule cspT_rw_left)\napply (rule cspT_commut)\napply (simp)\napply (rule cspT_rw_left)\napply (rule cspT_commut)\napply (simp)\n\napply (simp (no_asm_simp))\napply (rule cspT_rw_left)\napply (rule cspT_IF)\napply (subgoal_tac \"~(a : Y & a : Z)\")\napply (simp (no_asm_simp))\napply (rule cspT_rw_right)\napply (rule cspT_IF)\n\napply (case_tac \"a : Z\")\napply (simp)\napply (rule cspT_rw_left)\napply (rule cspT_IF)\napply (rule cspT_rw_right)\napply (rule cspT_IF)\napply (rule cspT_commut)\napply (simp)\napply (rule cspT_rw_left)\napply (rule cspT_IF)\napply (rule cspT_rw_right)\napply (rule cspT_IF)\napply (rule cspT_commut)\n\napply (fast)\napply (simp)\napply (rule cspT_commut)\ndone\n\nlemmas cspT_Parallel_Timeout_input = \n       cspT_Parallel_Timeout_input_l\n       cspT_Parallel_Timeout_input_r\n\n(*** cspT_step_ext ***)\n\nlemmas cspT_step_ext = cspT_Parallel_Timeout_split\n                       cspT_Parallel_Timeout_input\n\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/CSP_T/CSP_T_law_step_ext.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.25559067413455916}}
{"text": "(*  Title:      HOL/Bali/Type.thy\n    Author:     David von Oheimb\n*)\n\nsubsection \\<open>Java types\\<close>\n\ntheory Type imports Name begin\n\ntext \\<open>\nsimplifications:\n\\begin{itemize}\n\\item only the most important primitive types\n\\item the null type is regarded as reference type\n\\end{itemize}\n\\<close>\n\ndatatype prim_ty        \\<comment> \\<open>primitive type, cf. 4.2\\<close>\n        = Void          \\<comment> \\<open>result type of void methods\\<close>\n        | Boolean\n        | Integer\n\n\ndatatype ref_ty         \\<comment> \\<open>reference type, cf. 4.3\\<close>\n        = NullT         \\<comment> \\<open>null type, cf. 4.1\\<close>\n        | IfaceT qtname \\<comment> \\<open>interface type\\<close>\n        | ClassT qtname \\<comment> \\<open>class type\\<close>\n        | ArrayT ty     \\<comment> \\<open>array type\\<close>\n\nand ty                  \\<comment> \\<open>any type, cf. 4.1\\<close>\n        = PrimT prim_ty \\<comment> \\<open>primitive type\\<close>\n        | RefT  ref_ty  \\<comment> \\<open>reference type\\<close>\n\nabbreviation \"NT == RefT NullT\"\nabbreviation \"Iface I == RefT (IfaceT I)\"\nabbreviation \"Class C == RefT (ClassT C)\"\nabbreviation Array :: \"ty \\<Rightarrow> ty\"  (\"_.[]\" [90] 90)\n  where \"T.[] == RefT (ArrayT T)\"\n\ndefinition\n  the_Class :: \"ty \\<Rightarrow> qtname\"\n  where \"the_Class T = (SOME C. T = Class C)\" (** primrec not possible here **)\n \nlemma the_Class_eq [simp]: \"the_Class (Class C)= C\"\nby (auto simp add: the_Class_def)\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/Bali/Type.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.588889130767832, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.2555669675777183}}
{"text": "section \\<open> Experiment in creating Circus with a Refusal Testing Semantics \\<close>\n\ntheory utp_rcircus\n  imports Refusal_Tests \"UTP1-Reactive-Designs.utp_rea_designs\"\nbegin\n\nrecall_syntax\n\nsubsection \\<open> Refusal Syntax\\<close>\n\nsyntax\n  \"_urmember\"     :: \"logic \\<Rightarrow> logic \\<Rightarrow> logic\"  (\"(_/ \\<in>\\<^sup>\\<R> _)\" [51, 51] 50)\n  \"_urnot_member\" :: \"logic \\<Rightarrow> logic \\<Rightarrow> logic\"  (\"(_/ \\<notin>\\<^sup>\\<R> _)\" [51, 51] 50)\n  \"_urevevent\"    :: \"logic \\<Rightarrow> logic\" (\"revent\\<^sub>u'(_')\")\n\nterm not_upred\n\ntranslations \n  \"(x \\<in>\\<^sup>\\<R> A)\" == \"CONST bop (CONST rmember) x A\"\n  \"(x \\<notin>\\<^sup>\\<R> A)\" == \"CONST not_upred (x \\<in>\\<^sup>\\<R> A)\"\n  \"revent\\<^sub>u(a)\" == \"CONST uop CONST revent a\"\n\nsubsection \\<open> Refusal Circus Alphabet \\<close>\n\nalphabet ('\\<sigma>, '\\<phi>) rcsp_vars = \"('\\<phi> list, '\\<sigma>) rsp_vars\" +\n  rref :: \"'\\<phi> refusal\"\n\n\ntype_synonym ('\\<sigma>,'\\<phi>) raction  = \"('\\<sigma>,'\\<phi>) rcsp_vars hrel\"\n  \ntext \\<open> There is some slight imprecision with the translations, in that we don't bother to check\n  if the trace event type and refusal set event types are the same. Essentially this is because\n  its very difficult to construct processes where this would be the case. However, it may\n  be better to add a proper ML print translation in the future. \\<close>\n  \nsubsection \\<open> Basic laws \\<close>\n\nlemma R2c_tr_ext: \"R2c (U($tr\\<acute> = $tr @ [\\<lceil>a\\<rceil>\\<^sub>S\\<^sub><])) = U($tr\\<acute> = $tr @ [\\<lceil>a\\<rceil>\\<^sub>S\\<^sub><])\"\n  by (rel_auto)\n\nlemma circus_alpha_bij_lens:\n  \"bij_lens ({$ok,$ok\\<acute>,$wait,$wait\\<acute>,$tr,$tr\\<acute>,$st,$st\\<acute>,$rref,$rref\\<acute>}\\<^sub>\\<alpha> :: _ \\<Longrightarrow> ('s,'e) rcsp_vars \\<times> ('s,'e) rcsp_vars)\"\n  by (unfold_locales, lens_simp+)\n\nsubsection \\<open> Unrestriction laws \\<close>\n\nlemma pre_unrest_ref [unrest]: \"$rref \\<sharp> P \\<Longrightarrow> $rref \\<sharp> pre\\<^sub>R(P)\"\n  by (simp add: pre\\<^sub>R_def unrest)\n\nlemma peri_unrest_ref [unrest]: \"$rref \\<sharp> P \\<Longrightarrow> $rref \\<sharp> peri\\<^sub>R(P)\"\n  by (simp add: peri\\<^sub>R_def unrest)\n\nlemma post_unrest_ref [unrest]: \"$rref \\<sharp> P \\<Longrightarrow> $rref \\<sharp> post\\<^sub>R(P)\"\n  by (simp add: post\\<^sub>R_def unrest)\n\nlemma cmt_unrest_ref [unrest]: \"$rref \\<sharp> P \\<Longrightarrow> $rref \\<sharp> cmt\\<^sub>R(P)\"\n  by (simp add: cmt\\<^sub>R_def unrest)\n\nlemma st_lift_unrest_ref' [unrest]: \"$rref\\<acute> \\<sharp> \\<lceil>b\\<rceil>\\<^sub>S\\<^sub><\"\n  by (rel_auto)\n\nlemma RHS_design_ref_unrest [unrest]:\n  \"\\<lbrakk>$rref \\<sharp> P; $rref \\<sharp> Q \\<rbrakk> \\<Longrightarrow> $rref \\<sharp> (\\<^bold>R\\<^sub>s(P \\<turnstile> Q))\\<lbrakk>false/$wait\\<rbrakk>\"\n  by (simp add: RHS_def R1_def R2c_def R2s_def R3h_def design_def usubst unrest)\n\nlemma R1_ref_unrest [unrest]: \"$rref \\<sharp> P \\<Longrightarrow> $rref \\<sharp> R1(P)\"\n  by (simp add: R1_def unrest)\n\nlemma R2c_ref_unrest [unrest]: \"$rref \\<sharp> P \\<Longrightarrow> $rref \\<sharp> R2c(P)\"\n  by (simp add: R2c_def unrest)\n\nlemma R1_ref'_unrest [unrest]: \"$rref\\<acute> \\<sharp> P \\<Longrightarrow> $rref\\<acute> \\<sharp> R1(P)\"\n  by (simp add: R1_def unrest)\n\nlemma R2c_ref'_unrest [unrest]: \"$rref\\<acute> \\<sharp> P \\<Longrightarrow> $rref\\<acute> \\<sharp> R2c(P)\"\n  by (simp add: R2c_def unrest)\n\nlemma R2s_notin_rref': \"R2s(\\<lceil>\\<guillemotleft>x\\<guillemotright>\\<rceil>\\<^sub>S\\<^sub>< \\<notin>\\<^sup>\\<R> $rref\\<acute>) = (\\<lceil>\\<guillemotleft>x\\<guillemotright>\\<rceil>\\<^sub>S\\<^sub>< \\<notin>\\<^sup>\\<R> $rref\\<acute>)\"\n  by (pred_auto)\n\nlemma unrest_circus_alpha:\n  fixes P :: \"('e, 't) raction\"\n  assumes \n    \"$ok \\<sharp> P\" \"$ok\\<acute> \\<sharp> P\" \"$wait \\<sharp> P\" \"$wait\\<acute> \\<sharp> P\" \"$tr \\<sharp> P\" \n    \"$tr\\<acute> \\<sharp> P\" \"$st \\<sharp> P\" \"$st\\<acute> \\<sharp> P\" \"$rref \\<sharp> P\" \"$rref\\<acute> \\<sharp> P\"\n  shows \"\\<Sigma> \\<sharp> P\"\n  by (rule bij_lens_unrest_all[OF circus_alpha_bij_lens], simp add: unrest assms)\n\nlemma unrest_all_circus_vars:\n  fixes P :: \"('s, 'e) raction\"\n  assumes \"$ok \\<sharp> P\" \"$ok\\<acute> \\<sharp> P\" \"$wait \\<sharp> P\" \"$wait\\<acute> \\<sharp> P\" \"$rref \\<sharp> P\" \"\\<Sigma> \\<sharp> r'\" \"\\<Sigma> \\<sharp> s\" \"\\<Sigma> \\<sharp> s'\" \"\\<Sigma> \\<sharp> t\" \"\\<Sigma> \\<sharp> t'\"\n  shows \"\\<Sigma> \\<sharp> [$rref\\<acute> \\<mapsto>\\<^sub>s r', $st \\<mapsto>\\<^sub>s s, $st\\<acute> \\<mapsto>\\<^sub>s s', $tr \\<mapsto>\\<^sub>s t, $tr\\<acute> \\<mapsto>\\<^sub>s t'] \\<dagger> P\"\n  using assms\n  by (simp add: bij_lens_unrest_all_eq[OF circus_alpha_bij_lens] unrest_plus_split plus_vwb_lens)\n     (simp add: unrest usubst closure)\n\nlemma unrest_all_circus_vars_st_st':\n  fixes P :: \"('s, 'e) raction\"\n  assumes \"$ok \\<sharp> P\" \"$ok\\<acute> \\<sharp> P\" \"$wait \\<sharp> P\" \"$wait\\<acute> \\<sharp> P\" \"$rref \\<sharp> P\" \"$rref\\<acute> \\<sharp> P\" \"\\<Sigma> \\<sharp> s\" \"\\<Sigma> \\<sharp> s'\" \"\\<Sigma> \\<sharp> t\" \"\\<Sigma> \\<sharp> t'\"\n  shows \"\\<Sigma> \\<sharp> [$st \\<mapsto>\\<^sub>s s, $st\\<acute> \\<mapsto>\\<^sub>s s', $tr \\<mapsto>\\<^sub>s t, $tr\\<acute> \\<mapsto>\\<^sub>s t'] \\<dagger> P\"\n  using assms\n  by (simp add: bij_lens_unrest_all_eq[OF circus_alpha_bij_lens] unrest_plus_split plus_vwb_lens)\n     (simp add: unrest usubst closure)\n\nlemma unrest_all_circus_vars_st:\n  fixes P :: \"('s, 'e) raction\"\n  assumes \"$ok \\<sharp> P\" \"$ok\\<acute> \\<sharp> P\" \"$wait \\<sharp> P\" \"$wait\\<acute> \\<sharp> P\" \"$rref \\<sharp> P\" \"$rref\\<acute> \\<sharp> P\" \"$st\\<acute> \\<sharp> P\" \"\\<Sigma> \\<sharp> s\" \"\\<Sigma> \\<sharp> t\" \"\\<Sigma> \\<sharp> t'\"\n  shows \"\\<Sigma> \\<sharp> [$st \\<mapsto>\\<^sub>s s, $tr \\<mapsto>\\<^sub>s t, $tr\\<acute> \\<mapsto>\\<^sub>s t'] \\<dagger> P\"\n  using assms\n  by (simp add: bij_lens_unrest_all_eq[OF circus_alpha_bij_lens] unrest_plus_split plus_vwb_lens)\n      (simp add: unrest usubst closure)\n\nlemma unrest_any_circus_var:\n  fixes P :: \"('s, 'e) raction\"\n  assumes \"$ok \\<sharp> P\" \"$ok\\<acute> \\<sharp> P\" \"$wait \\<sharp> P\" \"$wait\\<acute> \\<sharp> P\" \"$rref \\<sharp> P\" \"$rref\\<acute> \\<sharp> P\" \"\\<Sigma> \\<sharp> s\" \"\\<Sigma> \\<sharp> s'\" \"\\<Sigma> \\<sharp> t\" \"\\<Sigma> \\<sharp> t'\"\n  shows \"x \\<sharp> [$st \\<mapsto>\\<^sub>s s, $st\\<acute> \\<mapsto>\\<^sub>s s', $tr \\<mapsto>\\<^sub>s t, $tr\\<acute> \\<mapsto>\\<^sub>s t'] \\<dagger> P\" \n  by (simp add: unrest_all_var unrest_all_circus_vars_st_st' assms)\n\nlemma unrest_any_circus_var_st:\n  fixes P :: \"('s, 'e) raction\"\n  assumes \"$ok \\<sharp> P\" \"$ok\\<acute> \\<sharp> P\" \"$wait \\<sharp> P\" \"$wait\\<acute> \\<sharp> P\" \"$rref \\<sharp> P\" \"$rref\\<acute> \\<sharp> P\" \"$st\\<acute> \\<sharp> P\" \"\\<Sigma> \\<sharp> s\" \"\\<Sigma> \\<sharp> t\" \"\\<Sigma> \\<sharp> t'\"\n  shows \"x \\<sharp> [$st \\<mapsto>\\<^sub>s s, $tr \\<mapsto>\\<^sub>s t, $tr\\<acute> \\<mapsto>\\<^sub>s t'] \\<dagger> P\"\n  by (simp add: unrest_all_var unrest_all_circus_vars_st assms)\n\nsubsection \\<open> Basic Actions \\<close>\n\n\nlemma rref_closure_1 [closure]: \"($tr\\<acute> =\\<^sub>u $tr \\<and> $rref\\<acute> =\\<^sub>u \\<guillemotleft>\\<^bold>\\<bullet>\\<guillemotright>) is RR\"\n  apply (rel_auto)\n  by (simp add: zero_list_def)\n\nlemma rref_closure_2 [closure]: \"$tr\\<acute> =\\<^sub>u $tr \\<and> $st\\<acute> =\\<^sub>u $st is RR\"\n  apply (rel_auto)\n  using minus_zero_eq by blast\n\nlemma rref_closure_3 [closure]: \"($tr\\<acute> =\\<^sub>u $tr \\<and> \\<lceil>a\\<rceil>\\<^sub>S\\<^sub>< \\<notin>\\<^sup>\\<R> $rref\\<acute>) is RR\"\n  by (rel_auto, simp add: zero_list_def)\n  \nlemma rref_closure_4 [closure]: \"(\\<^bold>\\<exists> e \\<bullet> U($tr\\<acute> = $tr @ [\\<guillemotleft>e\\<guillemotright>] \\<and> \\<guillemotleft>revent(e)\\<guillemotright> = \\<lceil>a\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> = $st)) is RR\"\n  by (rel_auto)\n\nlemma rref_closure_5 [closure]: \"(\\<^bold>\\<exists> e \\<bullet> U($tr\\<acute> = $tr @ [\\<guillemotleft>e\\<guillemotright>] \\<and> \\<guillemotleft>revent(e)\\<guillemotright> = \\<lceil>a\\<rceil>\\<^sub>S\\<^sub>< \\<and> $rref\\<acute> = \\<guillemotleft>\\<^bold>\\<bullet>\\<guillemotright>)) is RR\"\n  by (rel_auto)\n\ndefinition Stop :: \"('s, 'e) raction\" where\n[upred_defs, rdes_def]: \"Stop = \\<^bold>R\\<^sub>s(true\\<^sub>r \\<turnstile> ($tr\\<acute> =\\<^sub>u $tr) \\<diamondop> false)\"\n\ndefinition Skip :: \"('s, 'e) raction\" where\n[upred_defs, rdes_def]: \"Skip = \\<^bold>R\\<^sub>s(true\\<^sub>r \\<turnstile> U($tr\\<acute> = $tr \\<and> $rref\\<acute> = \\<^bold>\\<bullet>) \\<diamondop> U($tr\\<acute> = $tr \\<and> $st\\<acute> = $st))\"\n\ndefinition Do :: \"('e, 's) uexpr \\<Rightarrow> ('s, 'e) raction\" where\n[upred_defs, rdes_def]: \n\"Do(a) = \\<^bold>R\\<^sub>s(true\\<^sub>r \\<turnstile> (U($tr\\<acute> = $tr \\<and> \\<lceil>a\\<rceil>\\<^sub>S\\<^sub>< \\<notin>\\<^sup>\\<R> $rref\\<acute>) \\<or> U(\\<exists> e. $tr\\<acute> = $tr @ [\\<guillemotleft>e\\<guillemotright>] \\<and> \\<guillemotleft>revent(e)\\<guillemotright> = \\<lceil>a\\<rceil>\\<^sub>S\\<^sub>< \\<and> $rref\\<acute> = \\<^bold>\\<bullet>))\n                  \\<diamondop> U(\\<exists> e. $tr\\<acute> = $tr @ [\\<guillemotleft>e\\<guillemotright>] \\<and> \\<guillemotleft>revent(e)\\<guillemotright> = \\<lceil>a\\<rceil>\\<^sub>S\\<^sub>< \\<and> $st\\<acute> = $st))\"\n\nlemma \"Skip ;; Stop = Stop\"\n  by (rdes_eq)\n\nlemma \"Skip ;; Chaos = Chaos\"\n  apply (rdes_eq_split)\n    apply (rel_auto)\n  oops -- {* Not true *}\n\nlemma \"Stop ;; Skip = Stop\"\n  by (rdes_eq)\n\nlemma \"Skip ;; Do(a) = Do(a)\"\n  by (rdes_eq)\n\nlemma \"Do(a) ;; Skip = Do(a)\"\n  by (rdes_eq)\n\nlemma \"Stop ;; Do(a) = Stop\"\n  by (rdes_eq)\n\nterm UINF\n\ndefinition ResolveR :: \"'a set \\<Rightarrow> ('a \\<Rightarrow> ('s, 'e) raction) \\<Rightarrow> ('a \\<Rightarrow> ('s, 'e) raction) \\<Rightarrow> ('s, 'e) raction\" where\n\"ResolveR A P Q = (\\<^bold>\\<exists> (e, t) \\<bullet> (\\<Or> i\\<in>A \\<bullet> ((P i)\\<lbrakk>U([]),U([\\<guillemotleft>e\\<guillemotright>]@\\<guillemotleft>t\\<guillemotright>)/$tr,$tr\\<acute>\\<rbrakk>)) \n                          \\<and> (\\<And> i\\<in>A \\<bullet> ((Q i)\\<lbrakk>U([]),U([]),U(\\<guillemotleft>rrefusal(e)\\<guillemotright>)/$tr,$tr\\<acute>,$rref\\<acute>\\<rbrakk>))\n                          \\<and> $tr\\<acute> =\\<^sub>u $tr ^\\<^sub>u \\<guillemotleft>t\\<guillemotright>)\"\n\nsyntax\n  \"_ResolveR\" :: \"pttrn \\<Rightarrow> logic \\<Rightarrow> logic \\<Rightarrow> logic \\<Rightarrow> logic \\<Rightarrow> logic\"   (\"resolve _ \\<in> _ \\<bullet> '(_, _')\" [0, 10] 10)\n\ntranslations\n  \"resolve x \\<in> A \\<bullet> (F, G)\" => \"CONST ResolveR A (\\<lambda> x. F) (\\<lambda> x. G)\"\n\ndefinition \n  \"ExtChoice A P = \\<^bold>R\\<^sub>s((\\<And> i\\<in>A \\<bullet> pre\\<^sub>R(P i)) \\<turnstile> \n                      (R5(\\<And> i\\<in>A \\<bullet> peri\\<^sub>R(P(i))) \\<or> (resolve i\\<in>A \\<bullet> (peri\\<^sub>R(P(i)), peri\\<^sub>R(P(i))))) \\<diamondop> \n                      (R5(\\<Or> i\\<in>A \\<bullet> post\\<^sub>R(P(i))) \\<and> (resolve i\\<in>A \\<bullet> (peri\\<^sub>R(P(i)), post\\<^sub>R(P(i))))))\"\n\nlemma \"ExtChoice {} P = Stop\"\n  by (simp add: ExtChoice_def ResolveR_def rpred, rel_auto)\n\n\nend", "meta": {"author": "isabelle-utp", "repo": "utp-main", "sha": "27bdf3aee6d4fc00c8fe4d53283d0101857e0d41", "save_path": "github-repos/isabelle/isabelle-utp-utp-main", "path": "github-repos/isabelle/isabelle-utp-utp-main/utp-main-27bdf3aee6d4fc00c8fe4d53283d0101857e0d41/theories/rcircus/utp_rcircus.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.2554216220352411}}
{"text": "(* \n   Title: Psi-calculi   \n   Author/Maintainer: Jesper Bengtson (jebe@itu.dk), 2012\n*)\ntheory Weak_Cong_Sim_Pres\n  imports Weak_Sim_Pres Weak_Cong_Simulation\nbegin\n\ncontext env begin\n\nlemma caseWeakSimPres:\n  fixes \\<Psi>    :: 'b\n  and   CsP  :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n  and   Rel  :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   CsQ  :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n  and   M    :: 'a\n  and   N    :: 'a\n\n  assumes PRelQ: \"\\<And>\\<phi> Q. (\\<phi>, Q) mem CsQ \\<Longrightarrow> \\<exists>P. (\\<phi>, P) mem CsP \\<and> guarded P \\<and> Eq \\<Psi> P Q\"\n  and     Sim:   \"\\<And>\\<Psi>' P Q. (\\<Psi>', P, Q) \\<in> Rel \\<Longrightarrow> \\<Psi>' \\<rhd> P \\<leadsto><Rel> Q\"\n  and     EqRel: \"\\<And>\\<Psi>' P Q. Eq \\<Psi>' P Q \\<Longrightarrow> (\\<Psi>', P, Q) \\<in> Rel\"\n  and     EqSim: \"\\<And>\\<Psi>' P Q. Eq \\<Psi>' P Q \\<Longrightarrow> \\<Psi>' \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\n\n  shows \"\\<Psi> \\<rhd> Cases CsP \\<leadsto><Rel> Cases CsQ\"\nproof(induct rule: weakSimI2)\n  case(cAct \\<Psi>' \\<alpha> Q')\n  from \\<open>bn \\<alpha> \\<sharp>* (Cases CsP)\\<close> have \"bn \\<alpha> \\<sharp>* CsP\" by auto\n  from \\<open>\\<Psi> \\<rhd> Cases CsQ \\<longmapsto>\\<alpha> \\<prec> Q'\\<close>\n  show ?case\n  proof(induct rule: caseCases)\n    case(cCase \\<phi> Q)\n    from \\<open>(\\<phi>, Q) mem CsQ\\<close> obtain P where \"(\\<phi>, P) mem CsP\" and \"guarded P\" and \"Eq \\<Psi> P Q\"\n      by(metis PRelQ)\n    from \\<open>Eq \\<Psi> P Q\\<close> have \"\\<Psi> \\<rhd> P \\<leadsto><Rel> Q\" by(metis EqRel Sim)\n    moreover note \\<open>\\<Psi> \\<rhd> Q \\<longmapsto>\\<alpha> \\<prec> Q'\\<close> \\<open>bn \\<alpha> \\<sharp>* \\<Psi>\\<close>\n    moreover from \\<open>bn \\<alpha> \\<sharp>* CsP\\<close> \\<open>(\\<phi>, P) mem CsP\\<close> have \"bn \\<alpha> \\<sharp>* P\" by(auto dest: memFreshChain)\n    ultimately obtain P'' P' where PTrans: \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P''\"\n                               and P''Chain: \"\\<Psi> \\<otimes> \\<Psi>' \\<rhd> P'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" and P'RelQ': \"(\\<Psi> \\<otimes> \\<Psi>', P', Q') \\<in> Rel\"\n      using \\<open>\\<alpha> \\<noteq> \\<tau>\\<close>\n      by(blast dest: weakSimE)\n    note PTrans \\<open>(\\<phi>, P) mem CsP\\<close> \\<open>\\<Psi> \\<turnstile> \\<phi>\\<close> \\<open>guarded P\\<close>\n    moreover from \\<open>guarded Q\\<close> have \"insertAssertion (extractFrame Q) \\<Psi> \\<simeq>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi> \\<otimes> \\<one>\\<rangle>\"\n      by(rule insertGuardedAssertion)\n    hence \"insertAssertion (extractFrame(Cases CsQ)) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame Q) \\<Psi>\"\n      by(auto simp add: FrameStatEq_def)\n    moreover from Identity have \"insertAssertion (extractFrame(Cases CsQ)) \\<Psi> \\<hookrightarrow>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi>\\<rangle>\"\n      by(auto simp add: AssertionStatEq_def)\n    ultimately have \"\\<Psi> : (Cases CsQ) \\<rhd> Cases CsP \\<Longrightarrow>\\<alpha> \\<prec> P''\"\n      by(rule weakCase)\n    with P''Chain P'RelQ' show ?case by blast\n  qed\nnext\n  case(cTau Q')\n  from \\<open>\\<Psi> \\<rhd> Cases CsQ \\<longmapsto>\\<tau> \\<prec> Q'\\<close> show ?case\n  proof(induct rule: caseCases)\n    case(cCase \\<phi> Q)\n    from \\<open>(\\<phi>, Q) mem CsQ\\<close> obtain P where \"(\\<phi>, P) mem CsP\" and \"guarded P\" and \"Eq \\<Psi> P Q\"\n      by(metis PRelQ)\n    from \\<open>Eq \\<Psi> P Q\\<close> \\<open>\\<Psi> \\<rhd> Q \\<longmapsto>\\<tau> \\<prec> Q'\\<close>\n    obtain P' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\" and P'RelQ': \"(\\<Psi>, P', Q') \\<in> Rel\"\n      by(blast dest: EqSim weakCongSimE)\n    from PChain \\<open>(\\<phi>, P) mem CsP\\<close> \\<open>\\<Psi> \\<turnstile> \\<phi>\\<close> \\<open>guarded P\\<close> have \"\\<Psi> \\<rhd> Cases CsP \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n      by(rule tauStepChainCase)\n    hence \"\\<Psi> \\<rhd> Cases CsP \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" by(simp add: trancl_into_rtrancl)\n    with P'RelQ' show ?case by blast\n  qed\nqed\n\nlemma weakCongSimCasePres:\n  fixes \\<Psi>    :: 'b\n  and   CsP  :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n  and   Rel  :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   CsQ  :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n  and   M    :: 'a\n  and   N    :: 'a\n\n  assumes PRelQ: \"\\<And>\\<phi> Q. (\\<phi>, Q) mem CsQ \\<Longrightarrow> \\<exists>P. (\\<phi>, P) mem CsP \\<and> guarded P \\<and> Eq \\<Psi> P Q\"\n  and     EqSim: \"\\<And>\\<Psi>' P Q. Eq \\<Psi>' P Q \\<Longrightarrow> \\<Psi>' \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\n\n  shows \"\\<Psi> \\<rhd> Cases CsP \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Cases CsQ\"\nproof(induct rule: weakCongSimI)\n  case(cTau Q')\n  from \\<open>\\<Psi> \\<rhd> Cases CsQ \\<longmapsto>\\<tau> \\<prec> Q'\\<close> show ?case\n  proof(induct rule: caseCases)\n    case(cCase \\<phi> Q)\n    from \\<open>(\\<phi>, Q) mem CsQ\\<close> obtain P where \"(\\<phi>, P) mem CsP\" and \"guarded P\" and \"Eq \\<Psi> P Q\"\n      by(metis PRelQ)\n    from \\<open>Eq \\<Psi> P Q\\<close> \\<open>\\<Psi> \\<rhd> Q \\<longmapsto>\\<tau> \\<prec> Q'\\<close>\n    obtain P' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\" and P'RelQ': \"(\\<Psi>, P', Q') \\<in> Rel\"\n      by(blast dest: EqSim weakCongSimE)\n    from PChain \\<open>(\\<phi>, P) mem CsP\\<close> \\<open>\\<Psi> \\<turnstile> \\<phi>\\<close> \\<open>guarded P\\<close> have \"\\<Psi> \\<rhd> Cases CsP \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n      by(rule tauStepChainCase)\n    with P'RelQ' show ?case by blast\n  qed\nqed\n\nlemma weakCongSimResPres:\n  fixes \\<Psi>    :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   Rel  :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   x    :: name\n  and   Rel' :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n\n  assumes PSimQ: \"\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\n  and     \"eqvt Rel'\"\n  and     \"x \\<sharp> \\<Psi>\"\n  and     \"Rel \\<subseteq> Rel'\"\n  and     C1: \"\\<And>\\<Psi>' R S x. \\<lbrakk>(\\<Psi>', R, S) \\<in> Rel; x \\<sharp> \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', \\<lparr>\\<nu>x\\<rparr>R, \\<lparr>\\<nu>x\\<rparr>S) \\<in> Rel'\"\n\n  shows   \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<leadsto>\\<guillemotleft>Rel'\\<guillemotright> \\<lparr>\\<nu>x\\<rparr>Q\"\nproof(induct rule: weakCongSimI)\n  case(cTau Q')\n  from \\<open>\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>Q \\<longmapsto>\\<tau> \\<prec> Q'\\<close> have \"x \\<sharp> Q'\" by(auto dest: tauFreshDerivative simp add: abs_fresh) \n  with  \\<open>\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>Q \\<longmapsto>\\<tau> \\<prec> Q'\\<close> \\<open>x \\<sharp> \\<Psi>\\<close> show ?case\n  proof(induct rule: resTauCases)\n    case(cRes Q')\n    from PSimQ \\<open>\\<Psi> \\<rhd> Q \\<longmapsto>\\<tau> \\<prec> Q'\\<close> obtain P' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\" and P'RelQ': \"(\\<Psi>, P', Q') \\<in> Rel\" \n      by(blast dest: weakCongSimE)\n    from PChain \\<open>x \\<sharp> \\<Psi>\\<close> have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<Longrightarrow>\\<^sub>\\<tau> \\<lparr>\\<nu>x\\<rparr>P'\" by(rule tauStepChainResPres)\n    moreover from P'RelQ' \\<open>x \\<sharp> \\<Psi>\\<close> have \"(\\<Psi>, \\<lparr>\\<nu>x\\<rparr>P', \\<lparr>\\<nu>x\\<rparr>Q') \\<in> Rel'\" by(rule C1)\n    ultimately show ?case by blast\n  qed\nqed\n\nlemma weakCongSimResChainPres:\n  fixes \\<Psi>    :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   Rel  :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   xvec :: \"name list\"\n\n  assumes PSimQ: \"\\<Psi> \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\n  and     \"eqvt Rel\"\n  and     \"xvec \\<sharp>* \\<Psi>\"\n  and     C1:    \"\\<And>\\<Psi>' R S xvec. \\<lbrakk>(\\<Psi>', R, S) \\<in> Rel; xvec \\<sharp>* \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', \\<lparr>\\<nu>*xvec\\<rparr>R, \\<lparr>\\<nu>*xvec\\<rparr>S) \\<in> Rel\"\n\n  shows   \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> \\<lparr>\\<nu>*xvec\\<rparr>Q\"\nusing \\<open>xvec \\<sharp>* \\<Psi>\\<close>\nproof(induct xvec)\n  case Nil\n  from PSimQ show ?case by simp\nnext\n  case(Cons x xvec)\n  from \\<open>(x#xvec) \\<sharp>* \\<Psi>\\<close> have \"x \\<sharp> \\<Psi>\" and \"xvec \\<sharp>* \\<Psi>\" by simp+\n  from \\<open>xvec \\<sharp>* \\<Psi> \\<Longrightarrow> \\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> \\<lparr>\\<nu>*xvec\\<rparr>Q\\<close> \\<open>xvec \\<sharp>* \\<Psi>\\<close>\n  have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> \\<lparr>\\<nu>*xvec\\<rparr>Q\" by simp\n  moreover note \\<open>eqvt Rel\\<close> \\<open>x \\<sharp> \\<Psi>\\<close>\n  moreover have \"Rel \\<subseteq> Rel\" by simp\n  moreover have \"\\<And>\\<Psi> P Q x. \\<lbrakk>(\\<Psi>, P, Q) \\<in> Rel; x \\<sharp> \\<Psi>\\<rbrakk> \\<Longrightarrow> (\\<Psi>, \\<lparr>\\<nu>*[x]\\<rparr>P, \\<lparr>\\<nu>*[x]\\<rparr>Q) \\<in> Rel\"\n    by(rule_tac xvec=\"[x]\" in C1) auto\n  hence \"\\<And>\\<Psi> P Q x. \\<lbrakk>(\\<Psi>, P, Q) \\<in> Rel; x \\<sharp> \\<Psi>\\<rbrakk> \\<Longrightarrow> (\\<Psi>, \\<lparr>\\<nu>x\\<rparr>P, \\<lparr>\\<nu>x\\<rparr>Q) \\<in> Rel\"\n    by simp\n  ultimately have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>*xvec\\<rparr>P) \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> \\<lparr>\\<nu>x\\<rparr>(\\<lparr>\\<nu>*xvec\\<rparr>Q)\"\n    by(rule weakCongSimResPres)\n  thus ?case by simp\nqed\n\nlemma weakCongSimParPres:\n  fixes \\<Psi>    :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   Rel  :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   R    :: \"('a, 'b, 'c) psi\"\n  and   Rel' :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  \n  assumes PSimQ: \"\\<And>\\<Psi>'. \\<Psi>' \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\n  and     PSimQ': \"\\<And>\\<Psi>'. \\<Psi>' \\<rhd> P \\<leadsto><Rel> Q\"\n  and     StatImp: \"\\<And>\\<Psi>'. \\<Psi>' \\<rhd> Q \\<lessapprox><Rel> P\"\n\n  and            \"eqvt Rel\"\n  and            \"eqvt Rel'\"\n\n  and     Sym:    \"\\<And>\\<Psi>' S T. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel\\<rbrakk> \\<Longrightarrow> (\\<Psi>', T, S) \\<in> Rel\"\n  and     Ext:    \"\\<And>\\<Psi>' S T \\<Psi>''. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel\\<rbrakk> \\<Longrightarrow> (\\<Psi>' \\<otimes> \\<Psi>'', S, T) \\<in> Rel\"\n\n  and     C1: \"\\<And>\\<Psi>' S T A\\<^sub>U \\<Psi>\\<^sub>U U. \\<lbrakk>(\\<Psi>' \\<otimes> \\<Psi>\\<^sub>U, S, T) \\<in> Rel; extractFrame U = \\<langle>A\\<^sub>U, \\<Psi>\\<^sub>U\\<rangle>; A\\<^sub>U \\<sharp>* \\<Psi>'; A\\<^sub>U \\<sharp>* S; A\\<^sub>U \\<sharp>* T\\<rbrakk> \\<Longrightarrow> (\\<Psi>', S \\<parallel> U, T \\<parallel> U) \\<in> Rel'\"\n  and     C2: \"\\<And>\\<Psi>' S T xvec. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel'; xvec \\<sharp>* \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', \\<lparr>\\<nu>*xvec\\<rparr>S, \\<lparr>\\<nu>*xvec\\<rparr>T) \\<in> Rel'\"\n  and     C3: \"\\<And>\\<Psi>' S T \\<Psi>''. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel; \\<Psi>' \\<simeq> \\<Psi>''\\<rbrakk> \\<Longrightarrow> (\\<Psi>'', S, T) \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> P \\<parallel> R \\<leadsto>\\<guillemotleft>Rel'\\<guillemotright> Q \\<parallel> R\"\nproof(induct rule: weakCongSimI)\n  case(cTau QR)\n  from \\<open>\\<Psi> \\<rhd> Q \\<parallel> R \\<longmapsto>\\<tau> \\<prec> QR\\<close> show ?case\n  proof(induct rule: parTauCases[where C=\"(P, R)\"])\n    case(cPar1 Q' A\\<^sub>R \\<Psi>\\<^sub>R)\n    from \\<open>A\\<^sub>R \\<sharp>* (P, R)\\<close> have \"A\\<^sub>R \\<sharp>* P\"\n      by simp+\n    have FrR: \" extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by fact\n    with \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>A\\<^sub>R \\<sharp>* Q\\<close> have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> Q\"\n      by(rule_tac PSimQ)\n    moreover have QTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>\\<tau> \\<prec> Q'\" by fact\n    ultimately obtain P' where PChain: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\" and P'RelQ': \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, P', Q') \\<in> Rel\"\n      by(rule weakCongSimE)\n    from PChain QTrans \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>A\\<^sub>R \\<sharp>* Q\\<close> have \"A\\<^sub>R \\<sharp>* P'\" and \"A\\<^sub>R \\<sharp>* Q'\"\n      by(force dest: freeFreshChainDerivative tauStepChainFreshChain)+\n    from PChain FrR \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close> have \"\\<Psi> \\<rhd> P \\<parallel> R \\<Longrightarrow>\\<^sub>\\<tau> (P' \\<parallel> R)\"\n      by(rule tauStepChainPar1)\n    moreover from P'RelQ' FrR \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* P'\\<close> \\<open>A\\<^sub>R \\<sharp>* Q'\\<close> have \"(\\<Psi>, P' \\<parallel> R, Q' \\<parallel> R) \\<in> Rel'\" by(rule C1)\n    ultimately show ?case by blast\n  next\n    case(cPar2 R' A\\<^sub>Q \\<Psi>\\<^sub>Q)\n    from \\<open>A\\<^sub>Q \\<sharp>* (P, R)\\<close> have \"A\\<^sub>Q \\<sharp>* P\" and \"A\\<^sub>Q \\<sharp>* R\" by simp+\n    obtain A\\<^sub>P \\<Psi>\\<^sub>P where FrP: \"extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" and \"A\\<^sub>P \\<sharp>* (\\<Psi>, A\\<^sub>Q, \\<Psi>\\<^sub>Q, R)\"\n      by(rule freshFrame)\n    hence \"A\\<^sub>P \\<sharp>* \\<Psi>\" and \"A\\<^sub>P \\<sharp>* A\\<^sub>Q\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q\" and \"A\\<^sub>P \\<sharp>* R\"\n      by simp+\n    \n    have FrQ: \"extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" by fact\n    from \\<open>A\\<^sub>Q \\<sharp>* P\\<close> FrP \\<open>A\\<^sub>P \\<sharp>* A\\<^sub>Q\\<close> have \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P\"\n      by(drule_tac extractFrameFreshChain) auto\n      \n    obtain A\\<^sub>R \\<Psi>\\<^sub>R where FrR: \"extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" and \"A\\<^sub>R \\<sharp>* (\\<Psi>, P, Q, A\\<^sub>Q, A\\<^sub>P, \\<Psi>\\<^sub>Q, \\<Psi>\\<^sub>P, R)\" and \"distinct A\\<^sub>R\"\n      by(rule freshFrame)\n    then have \"A\\<^sub>R \\<sharp>* \\<Psi>\" and \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* Q\" and \"A\\<^sub>R \\<sharp>* A\\<^sub>Q\" and  \"A\\<^sub>R \\<sharp>* A\\<^sub>P\" and  \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q\" and  \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P\"\n          and \"A\\<^sub>R \\<sharp>* R\"\n      by simp+\n    \n    from \\<open>A\\<^sub>Q \\<sharp>* R\\<close>  FrR \\<open>A\\<^sub>R \\<sharp>* A\\<^sub>Q\\<close> have \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R\" by(drule_tac extractFrameFreshChain) auto\n    from \\<open>A\\<^sub>P \\<sharp>* R\\<close> \\<open>A\\<^sub>R \\<sharp>* A\\<^sub>P\\<close> FrR  have \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R\" by(drule_tac extractFrameFreshChain) auto\n    \n    moreover from \\<open>\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>\\<tau> \\<prec> R'\\<close> FrR \\<open>distinct A\\<^sub>R\\<close> \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>A\\<^sub>R \\<sharp>* Q\\<close> \\<open>A\\<^sub>R \\<sharp>* R\\<close>\n    obtain \\<Psi>' A\\<^sub>R' \\<Psi>\\<^sub>R' where \"\\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'\" and FrR': \"extractFrame R' = \\<langle>A\\<^sub>R', \\<Psi>\\<^sub>R'\\<rangle>\"\n                         and \"A\\<^sub>R' \\<sharp>* \\<Psi>\" and \"A\\<^sub>R' \\<sharp>* P\" and \"A\\<^sub>R' \\<sharp>* Q\"\n      by(rule_tac C=\"(\\<Psi>, P, Q, R)\" in expandTauFrame) (assumption | simp)+\n\n    from FrR \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>A\\<^sub>R \\<sharp>* Q\\<close>\n    obtain P' P'' where PChain: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n                    and QimpP': \"insertAssertion(extractFrame Q) (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<hookrightarrow>\\<^sub>F insertAssertion(extractFrame P') (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R)\"\n                    and P'Chain: \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<rhd> P' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\"\n                    and P'RelQ: \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>', P'', Q) \\<in> Rel\"\n      by(metis StatImp weakStatImp_def Sym)\n    obtain A\\<^sub>P' \\<Psi>\\<^sub>P' where FrP': \"extractFrame P' = \\<langle>A\\<^sub>P', \\<Psi>\\<^sub>P'\\<rangle>\" and \"A\\<^sub>P' \\<sharp>* \\<Psi>\" and \"A\\<^sub>P' \\<sharp>* \\<Psi>\\<^sub>R\" and \"A\\<^sub>P' \\<sharp>* \\<Psi>\\<^sub>Q\"\n                      and \"A\\<^sub>P' \\<sharp>* A\\<^sub>Q\" and \"A\\<^sub>P' \\<sharp>* R\" and \"A\\<^sub>P' \\<sharp>* A\\<^sub>R\"\n      by(rule_tac C=\"(\\<Psi>, \\<Psi>\\<^sub>R, \\<Psi>\\<^sub>Q, A\\<^sub>Q, R, A\\<^sub>R)\" in freshFrame) auto\n\n    from PChain P'Chain \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>A\\<^sub>Q \\<sharp>* P\\<close> \\<open>A\\<^sub>R' \\<sharp>* P\\<close> have \"A\\<^sub>Q \\<sharp>* P'\" and \"A\\<^sub>R \\<sharp>* P'\" and \"A\\<^sub>R' \\<sharp>* P'\" and \"A\\<^sub>R' \\<sharp>* P''\"\n      by(force intro: tauChainFreshChain)+\n    from \\<open>A\\<^sub>R \\<sharp>* P'\\<close> \\<open>A\\<^sub>P' \\<sharp>* A\\<^sub>R\\<close> \\<open>A\\<^sub>Q \\<sharp>* P'\\<close> \\<open>A\\<^sub>P' \\<sharp>* A\\<^sub>Q\\<close> FrP' have \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P'\" and \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P'\"\n      by(force dest: extractFrameFreshChain)+\n      \n    from PChain FrR \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close> have \"\\<Psi> \\<rhd> P \\<parallel> R \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P' \\<parallel> R\" by(rule tauChainPar1)\n    moreover have RTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P' \\<rhd> R \\<longmapsto>\\<tau> \\<prec> R'\"\n    proof -\n      have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>\\<tau> \\<prec> R'\" by fact\n      moreover have \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P') \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n      proof -\n        have \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle>\"\n          by(metis frameIntAssociativity Commutativity FrameStatEqTrans frameIntCompositionSym FrameStatEqSym)\n        moreover with FrP' FrQ QimpP' \\<open>A\\<^sub>P' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>Q \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>P' \\<sharp>* \\<Psi>\\<^sub>R\\<close> \\<open>A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R\\<close>\n        have \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P'\\<rangle>\" using freshCompChain\n          by simp\n        moreover have \"\\<langle>A\\<^sub>P', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P'\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P') \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n          by(metis frameIntAssociativity Commutativity FrameStatEqTrans frameIntCompositionSym frameIntAssociativity[THEN FrameStatEqSym])\n        ultimately show ?thesis\n          by(rule FrameStatEqImpCompose)\n      qed\n      ultimately show ?thesis\n        using \\<open>A\\<^sub>P' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>P' \\<sharp>* \\<Psi>\\<^sub>Q\\<close> \\<open>A\\<^sub>Q \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P'\\<close> \\<open>A\\<^sub>P' \\<sharp>* R\\<close> \\<open>A\\<^sub>Q \\<sharp>* R\\<close> \n              \\<open>A\\<^sub>P' \\<sharp>* A\\<^sub>R\\<close> \\<open>A\\<^sub>R \\<sharp>* A\\<^sub>Q\\<close> \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P'\\<close> \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q\\<close> \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P'\\<close> \\<open>A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P'\\<close> FrR \\<open>distinct A\\<^sub>R\\<close>\n        by(force intro: transferTauFrame)\n    qed\n    hence \"\\<Psi> \\<rhd> P' \\<parallel> R \\<longmapsto>\\<tau> \\<prec> (P' \\<parallel> R')\" using FrP' \\<open>A\\<^sub>P' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>P' \\<sharp>* R\\<close>\n      by(rule_tac Par2) auto\n    moreover from P'Chain have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<rhd> P' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\"\n      by(metis tauChainStatEq Associativity)\n    with \\<open>\\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'\\<close> have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R' \\<rhd> P' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" \n      by(rule_tac tauChainStatEq, auto) (metis compositionSym)\n    hence \"\\<Psi> \\<rhd> P' \\<parallel> R' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'' \\<parallel> R'\" using FrR' \\<open>A\\<^sub>R' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R' \\<sharp>* P'\\<close> by(rule_tac tauChainPar1)\n    ultimately have \"\\<Psi> \\<rhd> P \\<parallel> R \\<Longrightarrow>\\<^sub>\\<tau> (P'' \\<parallel> R')\"\n      by(drule_tac tauActTauStepChain) auto\n    \n    moreover from P'RelQ \\<open>\\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R', P'', Q) \\<in> Rel\" by(blast intro: C3 Associativity compositionSym)\n    with FrR' \\<open>A\\<^sub>R' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R' \\<sharp>* P''\\<close> \\<open>A\\<^sub>R' \\<sharp>* Q\\<close> have \"(\\<Psi>, P'' \\<parallel> R', Q \\<parallel> R') \\<in> Rel'\" by(rule_tac C1) \n    ultimately show ?case by blast\n  next\n    case(cComm1 \\<Psi>\\<^sub>R M N Q' A\\<^sub>Q \\<Psi>\\<^sub>Q K xvec R' A\\<^sub>R)\n    have  FrQ: \"extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" by fact\n    from \\<open>A\\<^sub>Q \\<sharp>* (P, R)\\<close> have \"A\\<^sub>Q \\<sharp>* P\" and \"A\\<^sub>Q \\<sharp>* R\" by simp+\n    \n    have  FrR: \"extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by fact\n    from \\<open>A\\<^sub>R \\<sharp>* (P, R)\\<close> have \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* R\" by simp+\n    from \\<open>xvec \\<sharp>* (P, R)\\<close> have \"xvec \\<sharp>* P\" and \"xvec \\<sharp>* R\" by simp+\n    \n    have QTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> Q'\" and RTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> R'\"\n      and MeqK: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> M \\<leftrightarrow>K\" by fact+\n\n    from RTrans FrR \\<open>distinct A\\<^sub>R\\<close> \\<open>A\\<^sub>R \\<sharp>* R\\<close> \\<open>A\\<^sub>R \\<sharp>* xvec\\<close> \\<open>xvec \\<sharp>* R\\<close> \\<open>xvec \\<sharp>* Q\\<close> \\<open>xvec \\<sharp>* \\<Psi>\\<close> \\<open>xvec \\<sharp>* \\<Psi>\\<^sub>Q\\<close> \\<open>A\\<^sub>R \\<sharp>* Q\\<close>\n                    \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q\\<close> \\<open>xvec \\<sharp>* K\\<close> \\<open>A\\<^sub>R \\<sharp>* K\\<close> \\<open>A\\<^sub>R \\<sharp>* R\\<close> \\<open>xvec \\<sharp>* R\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>xvec \\<sharp>* P\\<close>\n                     \\<open>A\\<^sub>Q \\<sharp>* A\\<^sub>R\\<close> \\<open>A\\<^sub>Q \\<sharp>* xvec\\<close> \\<open>A\\<^sub>R \\<sharp>* K\\<close> \\<open>A\\<^sub>R \\<sharp>* N\\<close> \\<open>xvec \\<sharp>* K\\<close> \\<open>distinct xvec\\<close>\n    obtain p \\<Psi>' A\\<^sub>R' \\<Psi>\\<^sub>R' where S: \"set p \\<subseteq> set xvec \\<times> set(p \\<bullet> xvec)\" and FrR': \"extractFrame R' = \\<langle>A\\<^sub>R', \\<Psi>\\<^sub>R'\\<rangle>\"\n                           and \"(p \\<bullet> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'\" and \"A\\<^sub>R' \\<sharp>* Q\" and \"A\\<^sub>R' \\<sharp>* \\<Psi>\" and \"(p \\<bullet> xvec) \\<sharp>* \\<Psi>\"\n                           and \"(p \\<bullet> xvec) \\<sharp>* Q\" and \"(p \\<bullet> xvec) \\<sharp>* \\<Psi>\\<^sub>Q\" and \"(p \\<bullet> xvec) \\<sharp>* K\" and \"(p \\<bullet> xvec) \\<sharp>* R\"\n                           and \"(p \\<bullet> xvec) \\<sharp>* P\" and \"(p \\<bullet> xvec) \\<sharp>* A\\<^sub>Q\" and \"A\\<^sub>R' \\<sharp>* P\" and \"A\\<^sub>R' \\<sharp>* N\"\n      by(rule_tac C=\"(\\<Psi>, Q, \\<Psi>\\<^sub>Q, K, R, P, A\\<^sub>Q)\"  and C'=\"(\\<Psi>, Q, \\<Psi>\\<^sub>Q, K, R, P, A\\<^sub>Q)\" in expandFrame) (assumption | simp)+\n\n    from \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> \\<Psi>)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n    with \\<open>xvec \\<sharp>* \\<Psi>\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* \\<Psi>\\<close> S have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>\" by simp\n    from \\<open>A\\<^sub>R \\<sharp>* P\\<close> have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> P)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n    with \\<open>xvec \\<sharp>* P\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* P\\<close> S have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* P\" by simp\n    from \\<open>A\\<^sub>R \\<sharp>* Q\\<close> have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> Q)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n    with \\<open>xvec \\<sharp>* Q\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* Q\\<close> S have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* Q\" by simp\n    from \\<open>A\\<^sub>R \\<sharp>* R\\<close> have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> R)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n    with \\<open>xvec \\<sharp>* R\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* R\\<close> S have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* R\" by simp\n    from \\<open>A\\<^sub>R \\<sharp>* K\\<close> have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* (p \\<bullet> K)\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n    with \\<open>xvec \\<sharp>* K\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* K\\<close> S have \"(p \\<bullet> A\\<^sub>R) \\<sharp>* K\" by simp\n    \n    from \\<open>A\\<^sub>Q \\<sharp>* xvec\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* A\\<^sub>Q\\<close> \\<open>A\\<^sub>Q \\<sharp>* M\\<close> S have \"A\\<^sub>Q \\<sharp>* (p \\<bullet> M)\" by(simp add: freshChainSimps)\n    from \\<open>A\\<^sub>Q \\<sharp>* xvec\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* A\\<^sub>Q\\<close> \\<open>A\\<^sub>Q \\<sharp>* A\\<^sub>R\\<close> S have \"A\\<^sub>Q \\<sharp>* (p \\<bullet> A\\<^sub>R)\" by(simp add: freshChainSimps)\n    \n    from QTrans S \\<open>xvec \\<sharp>* Q\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* Q\\<close> have \"(p \\<bullet> (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R)) \\<rhd> Q \\<longmapsto> (p \\<bullet> M)\\<lparr>N\\<rparr> \\<prec> Q'\"\n      by(rule_tac inputPermFrameSubject) (assumption | auto simp add: fresh_star_def)+\n    with \\<open>xvec \\<sharp>* \\<Psi>\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* \\<Psi>\\<close> S have QTrans: \"(\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<rhd> Q \\<longmapsto> (p \\<bullet> M)\\<lparr>N\\<rparr> \\<prec> Q'\"\n      by(simp add: eqvts)\n    from FrR have \"(p \\<bullet> extractFrame R) = p \\<bullet> \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by simp\n    with \\<open>xvec \\<sharp>* R\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* R\\<close> S have FrR: \"extractFrame R = \\<langle>(p \\<bullet> A\\<^sub>R), (p \\<bullet> \\<Psi>\\<^sub>R)\\<rangle>\"\n      by(simp add: eqvts)\n    \n    from MeqK have \"(p \\<bullet> (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R)) \\<turnstile> (p \\<bullet> M) \\<leftrightarrow> (p \\<bullet> K)\" by(rule chanEqClosed)\n    with \\<open>xvec \\<sharp>* \\<Psi>\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* \\<Psi>\\<close> \\<open>xvec \\<sharp>* \\<Psi>\\<^sub>Q\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* \\<Psi>\\<^sub>Q\\<close> \\<open>xvec \\<sharp>* K\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* K\\<close> S\n    have MeqK: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R) \\<turnstile> (p \\<bullet> M) \\<leftrightarrow> K\" by(simp add: eqvts)\n    \n    have \"\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R) \\<rhd> P \\<leadsto><Rel> Q\" by(rule PSimQ')\n\n    with QTrans obtain P' P'' where PTrans: \"\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R) : Q \\<rhd> P \\<Longrightarrow>(p \\<bullet> M)\\<lparr>N\\<rparr> \\<prec> P''\"\n                                and P''Chain: \"(\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> \\<Psi>' \\<rhd> P'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n                                and P'RelQ': \"((\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> \\<Psi>', P', Q') \\<in> Rel\"\n      by(fastforce dest: weakSimE)\n    from PTrans QTrans \\<open>A\\<^sub>R' \\<sharp>* P\\<close> \\<open>A\\<^sub>R' \\<sharp>* Q\\<close> \\<open>A\\<^sub>R' \\<sharp>* N\\<close> have \"A\\<^sub>R' \\<sharp>* P''\" and \"A\\<^sub>R' \\<sharp>* Q'\"\n      by(blast dest: weakInputFreshChainDerivative inputFreshChainDerivative)+\n\n    from PTrans obtain P''' where PChain: \"\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R) \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'''\"\n                              and QimpP''': \"insertAssertion (extractFrame Q) (\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P''') (\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R))\"\n                              and P'''Trans: \"\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R) \\<rhd> P''' \\<longmapsto>(p \\<bullet> M)\\<lparr>N\\<rparr> \\<prec> P''\"\n      by(rule weakTransitionE)\n    \n    from PChain \\<open>xvec \\<sharp>* P\\<close> \\<open>(p \\<bullet> A\\<^sub>R) \\<sharp>* P\\<close> \\<open>A\\<^sub>R' \\<sharp>* P\\<close> have \"xvec \\<sharp>* P'''\" and \"(p \\<bullet> A\\<^sub>R) \\<sharp>* P'''\" and \"A\\<^sub>R' \\<sharp>* P'''\"\n      by(force intro: tauChainFreshChain)+\n    from P'''Trans \\<open>A\\<^sub>R' \\<sharp>* P'''\\<close> \\<open>A\\<^sub>R' \\<sharp>* N\\<close> have \"A\\<^sub>R' \\<sharp>* P''\" by(force dest: inputFreshChainDerivative)\n    \n    obtain A\\<^sub>P''' \\<Psi>\\<^sub>P''' where FrP''': \"extractFrame P''' = \\<langle>A\\<^sub>P''', \\<Psi>\\<^sub>P'''\\<rangle>\" and \"A\\<^sub>P''' \\<sharp>* (\\<Psi>, A\\<^sub>Q, \\<Psi>\\<^sub>Q, p \\<bullet> A\\<^sub>R, p \\<bullet> \\<Psi>\\<^sub>R, p \\<bullet> M, N, K, R, P''', xvec)\" and \"distinct A\\<^sub>P'''\"\n      by(rule freshFrame)\n    hence \"A\\<^sub>P''' \\<sharp>* \\<Psi>\" and \"A\\<^sub>P''' \\<sharp>* A\\<^sub>Q\" and \"A\\<^sub>P''' \\<sharp>* \\<Psi>\\<^sub>Q\" and \"A\\<^sub>P''' \\<sharp>* (p \\<bullet> M)\" and \"A\\<^sub>P''' \\<sharp>* R\"\n      and \"A\\<^sub>P''' \\<sharp>* N\" and \"A\\<^sub>P''' \\<sharp>* K\" and \"A\\<^sub>P''' \\<sharp>* (p \\<bullet> A\\<^sub>R)\" and \"A\\<^sub>P''' \\<sharp>* P'''\" and \"A\\<^sub>P''' \\<sharp>* xvec\" and \"A\\<^sub>P''' \\<sharp>* (p \\<bullet> \\<Psi>\\<^sub>R)\"\n      by simp+\n\n    have \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle>\" \n      by(metis frameResChainPres frameNilStatEq Commutativity AssertionStatEqTrans Composition Associativity)\n    moreover with QimpP''' FrP''' FrQ \\<open>A\\<^sub>P''' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>Q \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>P''' \\<sharp>* (p \\<bullet> \\<Psi>\\<^sub>R)\\<close> \\<open>A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R\\<close> \\<open>A\\<^sub>Q \\<sharp>* xvec\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* A\\<^sub>Q\\<close> S\n    have \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P''', (\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> \\<Psi>\\<^sub>P'''\\<rangle>\" using freshCompChain\n      by(simp add: freshChainSimps)\n    moreover have \"\\<langle>A\\<^sub>P''', (\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> \\<Psi>\\<^sub>P'''\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P''', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P''') \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)\\<rangle>\"\n      by(metis frameResChainPres frameNilStatEq Commutativity AssertionStatEqTrans Composition Associativity)\n    ultimately have QImpP''': \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P''', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P''') \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)\\<rangle>\"\n      by(rule FrameStatEqImpCompose)\n      \n    from PChain FrR \\<open>(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>\\<close> \\<open>(p \\<bullet> A\\<^sub>R) \\<sharp>* P\\<close> have \"\\<Psi> \\<rhd> P \\<parallel> R \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''' \\<parallel> R\" by(rule tauChainPar1)\n    moreover from RTrans FrR P'''Trans MeqK QImpP''' FrP''' FrQ \\<open>distinct A\\<^sub>P'''\\<close> \\<open>distinct A\\<^sub>R\\<close> \\<open>A\\<^sub>P''' \\<sharp>* (p \\<bullet> A\\<^sub>R)\\<close> \\<open>A\\<^sub>Q \\<sharp>* (p \\<bullet> A\\<^sub>R)\\<close>\n      \\<open>(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>\\<close> \\<open>(p \\<bullet> A\\<^sub>R) \\<sharp>* P'''\\<close> \\<open>(p \\<bullet> A\\<^sub>R) \\<sharp>* Q\\<close> \\<open>(p \\<bullet> A\\<^sub>R) \\<sharp>* R\\<close> \\<open>(p \\<bullet> A\\<^sub>R) \\<sharp>* K\\<close> \\<open>A\\<^sub>P''' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>P''' \\<sharp>* R\\<close>\n      \\<open>A\\<^sub>P''' \\<sharp>* P'''\\<close> \\<open>A\\<^sub>P''' \\<sharp>* (p \\<bullet> M)\\<close> \\<open>A\\<^sub>Q \\<sharp>* R\\<close>  \\<open>A\\<^sub>Q \\<sharp>* (p \\<bullet> M)\\<close> \n    obtain K' where \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P''' \\<rhd> R \\<longmapsto>K'\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> R'\" and \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P''' \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R) \\<turnstile> (p \\<bullet> M) \\<leftrightarrow> K'\" and \"(p \\<bullet> A\\<^sub>R) \\<sharp>* K'\"\n      by(rule_tac comm1Aux) (assumption | simp)+\n    \n    with P'''Trans FrP''' have \"\\<Psi> \\<rhd> P''' \\<parallel> R \\<longmapsto>\\<tau> \\<prec> \\<lparr>\\<nu>*xvec\\<rparr>(P'' \\<parallel> R')\" using FrR \\<open>(p \\<bullet> A\\<^sub>R) \\<sharp>* \\<Psi>\\<close> \\<open>(p \\<bullet> A\\<^sub>R) \\<sharp>* P'''\\<close> \\<open>(p \\<bullet> A\\<^sub>R) \\<sharp>* R\\<close>\n      \\<open>xvec \\<sharp>* P'''\\<close> \\<open>A\\<^sub>P''' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>P''' \\<sharp>* P'''\\<close> \\<open>A\\<^sub>P''' \\<sharp>* R\\<close> \\<open>A\\<^sub>P''' \\<sharp>* (p \\<bullet> M)\\<close> \\<open>(p \\<bullet> A\\<^sub>R) \\<sharp>* K'\\<close> \\<open>A\\<^sub>P''' \\<sharp>* (p \\<bullet> A\\<^sub>R)\\<close>\n      by(rule_tac Comm1)\n    \n    moreover from P''Chain \\<open>A\\<^sub>R' \\<sharp>* P''\\<close> have \"A\\<^sub>R' \\<sharp>* P'\" by(rule tauChainFreshChain)\n    from \\<open>(p \\<bullet> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'\\<close> have \"(\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> \\<Psi>' \\<simeq> \\<Psi> \\<otimes> \\<Psi>\\<^sub>R'\"\n      by(metis Associativity AssertionStatEqTrans AssertionStatEqSym compositionSym)\n    with P''Chain have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R' \\<rhd> P'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" by(rule tauChainStatEq)\n    hence \"\\<Psi> \\<rhd> P'' \\<parallel> R' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P' \\<parallel> R'\" using FrR' \\<open>A\\<^sub>R' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R' \\<sharp>* P''\\<close> by(rule tauChainPar1)\n    hence \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(P'' \\<parallel> R') \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> R')\" using \\<open>xvec \\<sharp>* \\<Psi>\\<close> by(rule tauChainResChainPres)\n    ultimately have \"\\<Psi> \\<rhd> P \\<parallel> R \\<Longrightarrow>\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> R')\"\n      by(drule_tac tauActTauStepChain) auto\n    moreover from P'RelQ' \\<open>(p \\<bullet> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R', P', Q') \\<in> Rel\"  by(metis C3 Associativity compositionSym)\n    with FrR' \\<open>A\\<^sub>R' \\<sharp>* P'\\<close> \\<open>A\\<^sub>R' \\<sharp>* Q'\\<close> \\<open>A\\<^sub>R' \\<sharp>* \\<Psi>\\<close> have \"(\\<Psi>, P' \\<parallel> R', Q' \\<parallel> R') \\<in> Rel'\" by(rule_tac C1)\n    with \\<open>xvec \\<sharp>* \\<Psi>\\<close> have \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> R'), \\<lparr>\\<nu>*xvec\\<rparr>(Q' \\<parallel> R')) \\<in> Rel'\"\n      by(rule_tac C2)\n    ultimately show ?case by blast\n  next\n    case(cComm2 \\<Psi>\\<^sub>R M xvec N Q' A\\<^sub>Q \\<Psi>\\<^sub>Q K R' A\\<^sub>R)\n    have  FrQ: \"extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" by fact\n    from \\<open>A\\<^sub>Q \\<sharp>* (P, R)\\<close> have \"A\\<^sub>Q \\<sharp>* P\" and \"A\\<^sub>Q \\<sharp>* R\" by simp+\n    \n    have  FrR: \"extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by fact\n    from \\<open>A\\<^sub>R \\<sharp>* (P, R)\\<close> have \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* R\" by simp+\n    from \\<open>xvec \\<sharp>* (P, R)\\<close> have \"xvec \\<sharp>* P\" and \"xvec \\<sharp>* R\" by simp+\n    \n    have QTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'\" and RTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>K\\<lparr>N\\<rparr> \\<prec> R'\"\n     and MeqK: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> M \\<leftrightarrow>K\" by fact+\n\n    from RTrans FrR \\<open>distinct A\\<^sub>R\\<close> \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* R\\<close> \\<open>A\\<^sub>R \\<sharp>* Q'\\<close> \\<open>A\\<^sub>R \\<sharp>* N\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>A\\<^sub>R \\<sharp>* xvec\\<close> \\<open>A\\<^sub>R \\<sharp>* K\\<close>\n    obtain \\<Psi>' A\\<^sub>R' \\<Psi>\\<^sub>R' where  ReqR': \"\\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'\" and FrR': \"extractFrame R' = \\<langle>A\\<^sub>R', \\<Psi>\\<^sub>R'\\<rangle>\" \n                         and \"A\\<^sub>R' \\<sharp>* \\<Psi>\" and \"A\\<^sub>R' \\<sharp>* P\" and \"A\\<^sub>R' \\<sharp>* Q'\" and \"A\\<^sub>R' \\<sharp>* N\" and \"A\\<^sub>R' \\<sharp>* xvec\"\n      by(rule_tac C=\"(\\<Psi>, P, Q', N, xvec)\" and C'=\"(\\<Psi>, P, Q', N, xvec)\" in expandFrame) auto\n    \n    have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<leadsto><Rel> Q\" by(rule PSimQ')\n    \n    with QTrans \\<open>xvec \\<sharp>* \\<Psi>\\<close> \\<open>xvec \\<sharp>* \\<Psi>\\<^sub>R\\<close> \\<open>xvec \\<sharp>* P\\<close>\n    obtain P'' P' where PTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R : Q \\<rhd> P \\<Longrightarrow>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P''\"\n                    and P''Chain: \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<rhd> P'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n                    and P'RelQ': \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>', P', Q') \\<in> Rel\"\n      by(fastforce dest: weakSimE)\n\n    from PTrans obtain P''' where PChain: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'''\"\n                              and QimpP''': \"insertAssertion (extractFrame Q) (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P''') (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R)\"\n                              and P'''Trans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P''' \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P''\"\n      by(rule weakTransitionE)\n      \n    from PChain \\<open>A\\<^sub>R \\<sharp>* P\\<close> have \"A\\<^sub>R \\<sharp>* P'''\" by(rule tauChainFreshChain)\n\n    obtain A\\<^sub>P''' \\<Psi>\\<^sub>P''' where FrP''': \"extractFrame P''' = \\<langle>A\\<^sub>P''', \\<Psi>\\<^sub>P'''\\<rangle>\" and \"A\\<^sub>P''' \\<sharp>* (\\<Psi>, A\\<^sub>Q, \\<Psi>\\<^sub>Q, A\\<^sub>R, \\<Psi>\\<^sub>R, M, N, K, R, P''', xvec)\" and \"distinct A\\<^sub>P'''\"\n      by(rule freshFrame)\n    hence \"A\\<^sub>P''' \\<sharp>* \\<Psi>\" and \"A\\<^sub>P''' \\<sharp>* A\\<^sub>Q\" and \"A\\<^sub>P''' \\<sharp>* \\<Psi>\\<^sub>Q\" and \"A\\<^sub>P''' \\<sharp>* M\" and \"A\\<^sub>P''' \\<sharp>* R\"\n      and \"A\\<^sub>P''' \\<sharp>* N\" and \"A\\<^sub>P''' \\<sharp>* K\" and \"A\\<^sub>P''' \\<sharp>* A\\<^sub>R\" and \"A\\<^sub>P''' \\<sharp>* P'''\" and \"A\\<^sub>P''' \\<sharp>* xvec\" and \"A\\<^sub>P''' \\<sharp>* \\<Psi>\\<^sub>R\"\n      by simp+\n\n    have \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle>\" \n      by(metis frameResChainPres frameNilStatEq Commutativity AssertionStatEqTrans Composition Associativity)\n    moreover with QimpP''' FrP''' FrQ \\<open>A\\<^sub>P''' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>Q \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>P''' \\<sharp>* \\<Psi>\\<^sub>R\\<close> \\<open>A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R\\<close>\n    have \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P''', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P'''\\<rangle>\" using freshCompChain\n      by simp\n    moreover have \"\\<langle>A\\<^sub>P''', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P'''\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P''', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P''') \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n      by(metis frameResChainPres frameNilStatEq Commutativity AssertionStatEqTrans Composition Associativity)\n    ultimately have QImpP''': \"\\<langle>A\\<^sub>Q, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P''', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P''') \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n      by(rule FrameStatEqImpCompose)\n\n    from PChain FrR \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close> have \"\\<Psi> \\<rhd> P \\<parallel> R \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''' \\<parallel> R\" by(rule tauChainPar1)\n    moreover from RTrans FrR P'''Trans MeqK QImpP''' FrP''' FrQ \\<open>distinct A\\<^sub>P'''\\<close> \\<open>distinct A\\<^sub>R\\<close> \\<open>A\\<^sub>P''' \\<sharp>* A\\<^sub>R\\<close> \\<open>A\\<^sub>Q \\<sharp>* A\\<^sub>R\\<close>\n      \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* P'''\\<close> \\<open>A\\<^sub>R \\<sharp>* Q\\<close> \\<open>A\\<^sub>R \\<sharp>* R\\<close> \\<open>A\\<^sub>R \\<sharp>* K\\<close> \\<open>A\\<^sub>P''' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>P''' \\<sharp>* R\\<close>\n      \\<open>A\\<^sub>P''' \\<sharp>* P'''\\<close> \\<open>A\\<^sub>P''' \\<sharp>* M\\<close> \\<open>A\\<^sub>Q \\<sharp>* R\\<close>  \\<open>A\\<^sub>Q \\<sharp>* M\\<close> \\<open>A\\<^sub>R \\<sharp>* xvec\\<close> \\<open>xvec \\<sharp>* M\\<close>\n    obtain K' where \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P''' \\<rhd> R \\<longmapsto>K'\\<lparr>N\\<rparr> \\<prec> R'\" and \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P''' \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> M \\<leftrightarrow> K'\" and \"A\\<^sub>R \\<sharp>* K'\"\n      by(rule_tac comm2Aux) (assumption | simp)+\n    \n    with P'''Trans FrP''' have \"\\<Psi> \\<rhd> P''' \\<parallel> R \\<longmapsto>\\<tau> \\<prec> \\<lparr>\\<nu>*xvec\\<rparr>(P'' \\<parallel> R')\" using FrR \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* P'''\\<close> \\<open>A\\<^sub>R \\<sharp>* R\\<close>\n      \\<open>xvec \\<sharp>* R\\<close> \\<open>A\\<^sub>P''' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>P''' \\<sharp>* P'''\\<close> \\<open>A\\<^sub>P''' \\<sharp>* R\\<close> \\<open>A\\<^sub>P''' \\<sharp>* M\\<close> \\<open>A\\<^sub>R \\<sharp>* K'\\<close> \\<open>A\\<^sub>P''' \\<sharp>* A\\<^sub>R\\<close>\n      by(rule_tac Comm2)\n    moreover from P'''Trans \\<open>A\\<^sub>R \\<sharp>* P'''\\<close> \\<open>A\\<^sub>R \\<sharp>* xvec\\<close> \\<open>xvec \\<sharp>* M\\<close> \\<open>distinct xvec\\<close> have \"A\\<^sub>R \\<sharp>* P''\"\n      by(rule_tac outputFreshChainDerivative) auto\n\n    from PChain \\<open>A\\<^sub>R' \\<sharp>* P\\<close> have \"A\\<^sub>R' \\<sharp>* P'''\" by(rule tauChainFreshChain)\n    with P'''Trans \\<open>xvec \\<sharp>* M\\<close> \\<open>distinct xvec\\<close> have \"A\\<^sub>R' \\<sharp>* P''\" using \\<open>A\\<^sub>R' \\<sharp>* xvec\\<close>\n      by(rule_tac outputFreshChainDerivative) auto\n    \n    with P''Chain have \"A\\<^sub>R' \\<sharp>* P'\" by(rule tauChainFreshChain)\n    from \\<open>\\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<simeq> \\<Psi> \\<otimes> \\<Psi>\\<^sub>R'\"\n      by(metis Associativity AssertionStatEqTrans AssertionStatEqSym compositionSym)\n    with P''Chain have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R' \\<rhd> P'' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" by(rule tauChainStatEq)\n    hence \"\\<Psi> \\<rhd> P'' \\<parallel> R' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P' \\<parallel> R'\" using FrR' \\<open>A\\<^sub>R' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R' \\<sharp>* P''\\<close> \n      by(rule tauChainPar1)\n    hence \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(P'' \\<parallel> R') \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> R')\" \n      using \\<open>xvec \\<sharp>* \\<Psi>\\<close> by(rule tauChainResChainPres)\n    ultimately have \"\\<Psi> \\<rhd> P \\<parallel> R \\<Longrightarrow>\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> R')\" by(drule_tac tauActTauStepChain) auto\n    moreover from P'RelQ' \\<open>\\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R', P', Q') \\<in> Rel\"  by(metis C3 Associativity compositionSym)\n    with FrR' \\<open>A\\<^sub>R' \\<sharp>* P'\\<close> \\<open>A\\<^sub>R' \\<sharp>* Q'\\<close> \\<open>A\\<^sub>R' \\<sharp>* \\<Psi>\\<close> have \"(\\<Psi>, P' \\<parallel> R', Q' \\<parallel> R') \\<in> Rel'\" by(rule_tac C1)\n    with \\<open>xvec \\<sharp>* \\<Psi>\\<close> have \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> R'), \\<lparr>\\<nu>*xvec\\<rparr>(Q' \\<parallel> R')) \\<in> Rel'\"\n      by(rule_tac C2)\n    ultimately show ?case by blast\n  qed\nqed\nno_notation relcomp (infixr \"O\" 75)\n\nlemma weakCongSimBangPres:\n  fixes \\<Psi> :: 'b\n  and   P :: \"('a, 'b, 'c) psi\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   Rel :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Rel' :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Rel'' :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n\n  assumes PEqQ:   \"Eq P Q\"\n  and     PRelQ: \"(\\<Psi>, P, Q) \\<in> Rel\"\n  and     \"guarded P\"\n  and     \"guarded Q\"\n  and     Rel'Rel: \"Rel' \\<subseteq> Rel\"\n  and     FrameParPres: \"\\<And>\\<Psi>' \\<Psi>\\<^sub>U S T U A\\<^sub>U. \\<lbrakk>(\\<Psi>' \\<otimes> \\<Psi>\\<^sub>U, S, T) \\<in> Rel; extractFrame U = \\<langle>A\\<^sub>U, \\<Psi>\\<^sub>U\\<rangle>; A\\<^sub>U \\<sharp>* \\<Psi>'; A\\<^sub>U \\<sharp>* S; A\\<^sub>U \\<sharp>* T\\<rbrakk> \\<Longrightarrow>\n                                            (\\<Psi>', U \\<parallel> S, U \\<parallel> T) \\<in> Rel\"\n  and     C1: \"\\<And>\\<Psi>' S T U. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel; guarded S; guarded T\\<rbrakk> \\<Longrightarrow> (\\<Psi>', U \\<parallel> !S, U \\<parallel> !T) \\<in> Rel''\"\n  and     Closed: \"\\<And>\\<Psi>' S T p. (\\<Psi>', S, T) \\<in> Rel \\<Longrightarrow> ((p::name prm) \\<bullet> \\<Psi>', p \\<bullet> S, p \\<bullet> T) \\<in> Rel\"\n  and     Closed': \"\\<And>\\<Psi>' S T p. (\\<Psi>', S, T) \\<in> Rel' \\<Longrightarrow> ((p::name prm) \\<bullet> \\<Psi>', p \\<bullet> S, p \\<bullet> T) \\<in> Rel'\"\n  and     StatEq: \"\\<And>\\<Psi>' S T \\<Psi>''. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel; \\<Psi>' \\<simeq> \\<Psi>''\\<rbrakk> \\<Longrightarrow> (\\<Psi>'', S, T) \\<in> Rel\"\n  and     StatEq': \"\\<And>\\<Psi>' S T \\<Psi>''. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel'; \\<Psi>' \\<simeq> \\<Psi>''\\<rbrakk> \\<Longrightarrow> (\\<Psi>'', S, T) \\<in> Rel'\"\n  and     Trans: \"\\<And>\\<Psi>' S T U. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel; (\\<Psi>', T, U) \\<in> Rel\\<rbrakk> \\<Longrightarrow> (\\<Psi>', S, U) \\<in> Rel\"\n  and     Trans': \"\\<And>\\<Psi>' S T U. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel'; (\\<Psi>', T, U) \\<in> Rel'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', S, U) \\<in> Rel'\"\n  and     EqSim: \"\\<And>\\<Psi>' S T. Eq S T \\<Longrightarrow> \\<Psi>' \\<rhd> S \\<leadsto>\\<guillemotleft>Rel\\<guillemotright> T\"\n  and     cSim: \"\\<And>\\<Psi>' S T. (\\<Psi>', S, T) \\<in> Rel \\<Longrightarrow> \\<Psi>' \\<rhd> S \\<leadsto><Rel> T\"\n  and     cSym: \"\\<And>\\<Psi>' S T. (\\<Psi>', S, T) \\<in> Rel \\<Longrightarrow> (\\<Psi>', T, S) \\<in> Rel\"\n  and     cSym': \"\\<And>\\<Psi>' S T. (\\<Psi>', S, T) \\<in> Rel' \\<Longrightarrow> (\\<Psi>', T, S) \\<in> Rel'\"\n  and     cExt: \"\\<And>\\<Psi>' S T \\<Psi>''. (\\<Psi>', S, T) \\<in> Rel \\<Longrightarrow> (\\<Psi>' \\<otimes> \\<Psi>'', S, T) \\<in> Rel\"\n  and     cExt': \"\\<And>\\<Psi>' S T \\<Psi>''. (\\<Psi>', S, T) \\<in> Rel' \\<Longrightarrow> (\\<Psi>' \\<otimes> \\<Psi>'', S, T) \\<in> Rel'\"\n  and     ParPres: \"\\<And>\\<Psi>' S T U. (\\<Psi>', S, T) \\<in> Rel \\<Longrightarrow> (\\<Psi>', S \\<parallel> U, T \\<parallel> U) \\<in> Rel\"\n  and     ParPres': \"\\<And>\\<Psi>' S T U. (\\<Psi>', S, T) \\<in> Rel' \\<Longrightarrow> (\\<Psi>', U \\<parallel> S, U \\<parallel> T) \\<in> Rel'\"\n  and     ParPres2: \"\\<And>\\<Psi>' S T. Eq S T \\<Longrightarrow> Eq (S \\<parallel> S) (T \\<parallel> T)\"\n  and     ResPres: \"\\<And>\\<Psi>' S T xvec. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel; xvec \\<sharp>* \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', \\<lparr>\\<nu>*xvec\\<rparr>S, \\<lparr>\\<nu>*xvec\\<rparr>T) \\<in> Rel\"\n  and     ResPres': \"\\<And>\\<Psi>' S T xvec. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel'; xvec \\<sharp>* \\<Psi>'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', \\<lparr>\\<nu>*xvec\\<rparr>S, \\<lparr>\\<nu>*xvec\\<rparr>T) \\<in> Rel'\"\n  and     Assoc: \"\\<And>\\<Psi>' S T U. (\\<Psi>', S \\<parallel> (T \\<parallel> U), (S \\<parallel> T) \\<parallel> U) \\<in> Rel\"\n  and     Assoc': \"\\<And>\\<Psi>' S T U. (\\<Psi>', S \\<parallel> (T \\<parallel> U), (S \\<parallel> T) \\<parallel> U) \\<in> Rel'\"\n  and     ScopeExt: \"\\<And>xvec \\<Psi>' T S. \\<lbrakk>xvec \\<sharp>* \\<Psi>'; xvec \\<sharp>* T\\<rbrakk> \\<Longrightarrow> (\\<Psi>', \\<lparr>\\<nu>*xvec\\<rparr>(S \\<parallel> T), (\\<lparr>\\<nu>*xvec\\<rparr>S) \\<parallel> T) \\<in> Rel\"\n  and     ScopeExt': \"\\<And>xvec \\<Psi>' T S. \\<lbrakk>xvec \\<sharp>* \\<Psi>'; xvec \\<sharp>* T\\<rbrakk> \\<Longrightarrow> (\\<Psi>', \\<lparr>\\<nu>*xvec\\<rparr>(S \\<parallel> T), (\\<lparr>\\<nu>*xvec\\<rparr>S) \\<parallel> T) \\<in> Rel'\"\n  and     Compose: \"\\<And>\\<Psi>' S T U O. \\<lbrakk>(\\<Psi>', S, T) \\<in> Rel; (\\<Psi>', T, U) \\<in> Rel''; (\\<Psi>', U, O) \\<in> Rel'\\<rbrakk> \\<Longrightarrow> (\\<Psi>', S, O) \\<in> Rel''\"\n  and     rBangActE: \"\\<And>\\<Psi>' S \\<alpha> S'. \\<lbrakk>\\<Psi>' \\<rhd> !S \\<longmapsto>\\<alpha> \\<prec> S'; guarded S; bn \\<alpha> \\<sharp>* S; \\<alpha> \\<noteq> \\<tau>; bn \\<alpha> \\<sharp>* subject \\<alpha>\\<rbrakk> \\<Longrightarrow> \\<exists>T. \\<Psi>' \\<rhd> S \\<longmapsto>\\<alpha> \\<prec> T \\<and> (\\<one>, S', T \\<parallel> !S) \\<in> Rel'\"\n  and     rBangTauE: \"\\<And>\\<Psi>' S S'. \\<lbrakk>\\<Psi>' \\<rhd> !S \\<longmapsto>\\<tau> \\<prec> S'; guarded S\\<rbrakk> \\<Longrightarrow> \\<exists>T. \\<Psi>' \\<rhd> S \\<parallel> S \\<longmapsto>\\<tau> \\<prec> T \\<and> (\\<one>, S', T \\<parallel> !S) \\<in> Rel'\"\n  and     rBangTauI: \"\\<And>\\<Psi>' S S'. \\<lbrakk>\\<Psi>' \\<rhd> S \\<parallel> S \\<Longrightarrow>\\<^sub>\\<tau> S'; guarded S\\<rbrakk> \\<Longrightarrow> \\<exists>T. \\<Psi>' \\<rhd> !S \\<Longrightarrow>\\<^sub>\\<tau> T \\<and> (\\<Psi>', T, S' \\<parallel> !S) \\<in> Rel'\"\n  shows \"\\<Psi> \\<rhd> R \\<parallel> !P \\<leadsto>\\<guillemotleft>Rel''\\<guillemotright> R \\<parallel> !Q\"\nproof(induct rule: weakCongSimI)\n  case(cTau RQ')\n  from \\<open>\\<Psi> \\<rhd> R \\<parallel> !Q \\<longmapsto>\\<tau> \\<prec> RQ'\\<close> show ?case\n  proof(induct rule: parTauCases[where C=\"(P, Q, R)\"])\n    case(cPar1 R' A\\<^sub>Q \\<Psi>\\<^sub>Q)\n    from \\<open>extractFrame (!Q) = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\\<close> have \"A\\<^sub>Q = []\" and \"\\<Psi>\\<^sub>Q = SBottom'\" by simp+\n    with \\<open>\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>\\<tau> \\<prec> R'\\<close> \\<open>\\<Psi>\\<^sub>Q = SBottom'\\<close>\n    have \"\\<Psi> \\<rhd> R \\<parallel> !P \\<longmapsto>\\<tau> \\<prec> (R' \\<parallel> !P)\" by(rule_tac Par1) (assumption | simp)+\n    hence \"\\<Psi> \\<rhd> R \\<parallel> !P \\<Longrightarrow>\\<^sub>\\<tau> R' \\<parallel> !P\" by auto\n    moreover from \\<open>(\\<Psi>, P, Q) \\<in> Rel\\<close> have \"(\\<Psi>, R' \\<parallel> !P, R' \\<parallel> !Q) \\<in> Rel''\" using \\<open>guarded P\\<close> \\<open>guarded Q\\<close> \n      by(rule C1)\n    ultimately show ?case by blast\n  next\n    case(cPar2 Q' A\\<^sub>R \\<Psi>\\<^sub>R)\n    from \\<open>A\\<^sub>R \\<sharp>* (P, Q, R)\\<close> have \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* Q\" and \"A\\<^sub>R \\<sharp>* R\" by simp+\n    have FrR: \"extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by fact\n    \n    obtain A\\<^sub>Q \\<Psi>\\<^sub>Q where FrQ: \"extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R\" and \"A\\<^sub>Q \\<sharp>* A\\<^sub>R\"\n      by(rule_tac C=\"(\\<Psi>, \\<Psi>\\<^sub>R, A\\<^sub>R)\" in freshFrame) auto\n    from FrQ \\<open>guarded Q\\<close> have \"\\<Psi>\\<^sub>Q \\<simeq> \\<one>\" and \"supp \\<Psi>\\<^sub>Q = ({}::name set)\" by(blast dest: guardedStatEq)+\n    hence \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>Q\" by(auto simp add: fresh_star_def fresh_def)\n\n    from \\<open>\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !Q \\<longmapsto>\\<tau> \\<prec> Q'\\<close> \\<open>guarded Q\\<close> \n    obtain T where QTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<parallel> Q \\<longmapsto>\\<tau> \\<prec> T\" and \"(\\<one>, Q', T \\<parallel> !Q) \\<in> Rel'\" \n      by(blast dest: rBangTauE)\n    \n    from \\<open>Eq P Q\\<close> have \"Eq (P \\<parallel> P) (Q \\<parallel> Q)\" by(rule ParPres2)\n    with QTrans \n    obtain S where PTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<parallel> P \\<Longrightarrow>\\<^sub>\\<tau> S\" and SRelT: \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, S, T) \\<in> Rel\"\n      by(blast dest: EqSim weakCongSimE)\n    from PTrans \\<open>guarded P\\<close> obtain U where PChain: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !P \\<Longrightarrow>\\<^sub>\\<tau> U\" and \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, U, S \\<parallel> !P) \\<in> Rel'\"\n      by(blast dest: rBangTauI)\n    from PChain \\<open>A\\<^sub>R \\<sharp>* P\\<close> have \"A\\<^sub>R \\<sharp>* U\" by(force dest: tauStepChainFreshChain)\n    from \\<open>\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !P \\<Longrightarrow>\\<^sub>\\<tau> U\\<close> FrR \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close> have \"\\<Psi> \\<rhd> R \\<parallel> !P \\<Longrightarrow>\\<^sub>\\<tau> R \\<parallel> U\"\n      by(rule_tac tauStepChainPar2) auto\n    moreover from PTrans \\<open>A\\<^sub>R \\<sharp>* P\\<close> have \"A\\<^sub>R \\<sharp>* S\" by(force dest: tauStepChainFreshChain)\n    from QTrans \\<open>A\\<^sub>R \\<sharp>* Q\\<close> have \"A\\<^sub>R \\<sharp>* T\" by(force dest: tauFreshChainDerivative)\n    have \"(\\<Psi>, R \\<parallel> U, R \\<parallel> Q') \\<in> Rel''\"\n    proof -\n      from \\<open>(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, U, S \\<parallel> !P) \\<in> Rel'\\<close> Rel'Rel have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, U, S \\<parallel> !P) \\<in> Rel\"\n        by auto\n      hence \"(\\<Psi>, R \\<parallel> U, R \\<parallel> (S \\<parallel> !P)) \\<in> Rel\" using FrR \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* U\\<close> \\<open>A\\<^sub>R \\<sharp>* S\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close>\n        by(rule_tac FrameParPres) auto\n\n      moreover from \\<open>(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, S, T) \\<in> Rel\\<close> FrR \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* S\\<close> \\<open>A\\<^sub>R \\<sharp>* T\\<close> have \"(\\<Psi>, R \\<parallel> S, R \\<parallel> T) \\<in> Rel\"\n        by(rule_tac FrameParPres) auto\n      hence \"(\\<Psi>, R \\<parallel> T, R \\<parallel> S) \\<in> Rel\" by(rule cSym)\n      hence \"(\\<Psi>, (R \\<parallel> T) \\<parallel> !P, (R \\<parallel> S) \\<parallel> !P) \\<in> Rel\" by(rule ParPres)\n      hence \"(\\<Psi>, (R \\<parallel> S) \\<parallel> !P, (R \\<parallel> T) \\<parallel> !P) \\<in> Rel\" by(rule cSym)\n      hence \"(\\<Psi>, R \\<parallel> (S \\<parallel> !P), (R \\<parallel> T) \\<parallel> !P) \\<in> Rel\" by(metis Trans Assoc)\n      ultimately have \"(\\<Psi>, R \\<parallel> U, (R \\<parallel> T) \\<parallel> !P) \\<in> Rel\" by(rule Trans)\n      moreover from \\<open>(\\<Psi>, P, Q) \\<in> Rel\\<close> have \"(\\<Psi>, (R \\<parallel> T) \\<parallel> !P, (R \\<parallel> T) \\<parallel> !Q) \\<in> Rel''\" using \\<open>guarded P\\<close> \\<open>guarded Q\\<close> by(rule C1)\n      moreover from \\<open>(\\<one>, Q', T \\<parallel> !Q) \\<in> Rel'\\<close> have \"(\\<one> \\<otimes> \\<Psi>, Q', T \\<parallel> !Q) \\<in> Rel'\" by(rule cExt')\n      hence \"(\\<Psi>, Q', T \\<parallel> !Q) \\<in> Rel'\" \n        by(rule StatEq') (metis Identity AssertionStatEqSym Commutativity AssertionStatEqTrans)\n      hence \"(\\<Psi>, R \\<parallel> Q', R \\<parallel> (T \\<parallel> !Q)) \\<in> Rel'\" by(rule ParPres')\n      hence \"(\\<Psi>, R \\<parallel> Q', (R \\<parallel> T) \\<parallel> !Q) \\<in> Rel'\" by(metis Trans' Assoc')\n      hence \"(\\<Psi>, (R \\<parallel> T) \\<parallel> !Q, R \\<parallel> Q') \\<in> Rel'\" by(rule cSym')\n      ultimately show ?thesis by(rule_tac Compose)\n    qed\n    ultimately show ?case by blast\n  next\n    case(cComm1 \\<Psi>\\<^sub>Q M N R' A\\<^sub>R \\<Psi>\\<^sub>R K xvec Q' A\\<^sub>Q)\n    from \\<open>A\\<^sub>R \\<sharp>* (P, Q, R)\\<close> have \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* Q\" and \"A\\<^sub>R \\<sharp>* R\" by simp+\n    from \\<open>xvec \\<sharp>* (P, Q, R)\\<close> have \"xvec \\<sharp>* P\" and \"xvec \\<sharp>* Q\" and \"xvec \\<sharp>* R\" by simp+\n    have FrQ: \"extractFrame(!Q) = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" by fact\n    have FrR: \"extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by fact\n    from \\<open>\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> R'\\<close> FrR \\<open>distinct A\\<^sub>R\\<close> \\<open>A\\<^sub>R \\<sharp>* R\\<close> \\<open>A\\<^sub>R \\<sharp>* N\\<close> \\<open>A\\<^sub>R \\<sharp>* xvec\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>A\\<^sub>R \\<sharp>* Q\\<close> \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* M\\<close>\n    obtain A\\<^sub>R' \\<Psi>\\<^sub>R' \\<Psi>' where FrR': \"extractFrame R' = \\<langle>A\\<^sub>R', \\<Psi>\\<^sub>R'\\<rangle>\" and \"\\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'\" and \"A\\<^sub>R' \\<sharp>* xvec\" and \"A\\<^sub>R' \\<sharp>* P\" and \"A\\<^sub>R' \\<sharp>* Q\" and \"A\\<^sub>R' \\<sharp>* \\<Psi>\"\n      by(rule_tac C=\"(\\<Psi>, xvec, P, Q)\" and C'=\"(\\<Psi>, xvec, P, Q)\" in expandFrame) auto\n    from \\<open>(\\<Psi>, P, Q) \\<in> Rel\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, P, Q) \\<in> Rel\" by(rule cExt)\n    moreover from \\<open>\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !Q \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'\\<close> \\<open>guarded Q\\<close> \\<open>xvec \\<sharp>* Q\\<close> \\<open>xvec \\<sharp>* K\\<close>\n    obtain S where QTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> S\" and \"(\\<one>, Q', S \\<parallel> !Q) \\<in> Rel'\"\n      by(fastforce dest: rBangActE)\n    ultimately obtain P' T where PTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R : Q \\<rhd> P \\<Longrightarrow>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\" and P'Chain: \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<rhd> P' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> T\" and \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>', T, S) \\<in> Rel\"\n      using \\<open>xvec \\<sharp>* \\<Psi>\\<close> \\<open>xvec \\<sharp>* \\<Psi>\\<^sub>R\\<close> \\<open>xvec \\<sharp>* P\\<close>\n      by(fastforce dest: cSim weakSimE)\n\n    from PTrans \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>A\\<^sub>R \\<sharp>* xvec\\<close> \\<open>A\\<^sub>R' \\<sharp>* P\\<close> \\<open>A\\<^sub>R' \\<sharp>* xvec\\<close> \\<open>xvec \\<sharp>* K\\<close> \\<open>distinct xvec\\<close>\n    have \"A\\<^sub>R \\<sharp>* P'\" and  \"A\\<^sub>R' \\<sharp>* P'\"\n      by(force dest: weakOutputFreshChainDerivative)+\n    with P'Chain have \"A\\<^sub>R' \\<sharp>* T\" by(force dest: tauChainFreshChain)+\n    from QTrans \\<open>A\\<^sub>R' \\<sharp>* Q\\<close> \\<open>A\\<^sub>R' \\<sharp>* xvec\\<close> \\<open>xvec \\<sharp>* K\\<close> \\<open>distinct xvec\\<close> \n    have \"A\\<^sub>R' \\<sharp>* S\" by(force dest: outputFreshChainDerivative)\n\n    obtain A\\<^sub>Q' \\<Psi>\\<^sub>Q' where FrQ': \"extractFrame Q = \\<langle>A\\<^sub>Q', \\<Psi>\\<^sub>Q'\\<rangle>\" and \"A\\<^sub>Q' \\<sharp>* \\<Psi>\" and \"A\\<^sub>Q' \\<sharp>* \\<Psi>\\<^sub>R\" and \"A\\<^sub>Q' \\<sharp>* A\\<^sub>R\" and \"A\\<^sub>Q' \\<sharp>* M\" and \"A\\<^sub>Q' \\<sharp>* R\" and \"A\\<^sub>Q' \\<sharp>* K\"\n      by(rule_tac C=\"(\\<Psi>, \\<Psi>\\<^sub>R, A\\<^sub>R, K, M, R)\" in freshFrame) auto\n    from FrQ' \\<open>guarded Q\\<close> have \"\\<Psi>\\<^sub>Q' \\<simeq> \\<one>\" and \"supp \\<Psi>\\<^sub>Q' = ({}::name set)\" by(blast dest: guardedStatEq)+\n    hence \"A\\<^sub>Q' \\<sharp>* \\<Psi>\\<^sub>Q'\" by(auto simp add: fresh_star_def fresh_def)\n\n    from PTrans obtain P'' where PChain: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\"\n                             and NilImpP'': \"\\<langle>A\\<^sub>Q', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q'\\<rangle> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P'') (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R)\"\n                             and P''Trans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P'' \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n      using FrQ' \\<open>A\\<^sub>Q' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>Q' \\<sharp>* \\<Psi>\\<^sub>R\\<close> freshCompChain\n      by(drule_tac weakTransitionE) auto\n\n    from PChain have \"\\<Psi> \\<rhd> R \\<parallel> !P \\<Longrightarrow>\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (P' \\<parallel> !P))\"\n    proof(induct rule: tauChainCases)\n      case TauBase\n      from \\<open>\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> R'\\<close> FrQ have \"\\<Psi> \\<otimes> \\<one> \\<rhd> R \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> R'\" by simp\n      moreover note FrR\n      moreover from P''Trans \\<open>P = P''\\<close> have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\" by simp\n      hence \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<one> \\<rhd> P \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\" by(rule statEqTransition) (metis Identity AssertionStatEqSym)\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<parallel> !P \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> (P' \\<parallel> !P)\" using \\<open>xvec \\<sharp>* \\<Psi>\\<close> \\<open>xvec \\<sharp>* \\<Psi>\\<^sub>R\\<close> \\<open>xvec \\<sharp>* P\\<close>\n        by(force intro: Par1)\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !P \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> (P' \\<parallel> !P)\" using \\<open>guarded P\\<close> by(rule Bang)\n      moreover from \\<open>\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M \\<leftrightarrow> K\\<close> FrQ have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<one> \\<turnstile> M \\<leftrightarrow> K\" by simp\n      ultimately have \"\\<Psi> \\<rhd> R \\<parallel> !P \\<longmapsto>\\<tau> \\<prec> \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (P' \\<parallel> !P))\" using \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* R\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>A\\<^sub>R \\<sharp>* M\\<close> \\<open>xvec \\<sharp>* R\\<close>\n        by(force intro: Comm1)\n      thus ?case by(rule tauActTauStepChain)\n    next\n      case TauStep\n      obtain A\\<^sub>P'' \\<Psi>\\<^sub>P'' where FrP'': \"extractFrame P'' = \\<langle>A\\<^sub>P'', \\<Psi>\\<^sub>P''\\<rangle>\" and \"A\\<^sub>P'' \\<sharp>* \\<Psi>\" and \"A\\<^sub>P'' \\<sharp>* K\" and \"A\\<^sub>P'' \\<sharp>* \\<Psi>\\<^sub>R\" and \"A\\<^sub>P'' \\<sharp>* R\" and \"A\\<^sub>P'' \\<sharp>* P''\" and \"A\\<^sub>P'' \\<sharp>* P\"\n                          and \"A\\<^sub>P'' \\<sharp>* A\\<^sub>R\" and \"distinct A\\<^sub>P''\"\n        by(rule_tac C=\"(\\<Psi>, K, A\\<^sub>R, \\<Psi>\\<^sub>R, R, P'', P)\" in freshFrame) auto\n      from PChain \\<open>A\\<^sub>R \\<sharp>* P\\<close> have \"A\\<^sub>R \\<sharp>* P''\" by(drule_tac tauChainFreshChain) auto\n      with FrP'' \\<open>A\\<^sub>P'' \\<sharp>* A\\<^sub>R\\<close> have \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P''\" by(drule_tac extractFrameFreshChain) auto\n      from \\<open>\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P''\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<one> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P''\" by(rule tauStepChainStatEq) (metis Identity AssertionStatEqSym)\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<parallel> !P \\<Longrightarrow>\\<^sub>\\<tau> P'' \\<parallel> !P\" by(rule_tac tauStepChainPar1) auto\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !P \\<Longrightarrow>\\<^sub>\\<tau> P'' \\<parallel> !P\" using \\<open>guarded P\\<close> by(rule tauStepChainBang)\n      hence  \"\\<Psi> \\<rhd> R \\<parallel> !P \\<Longrightarrow>\\<^sub>\\<tau> R \\<parallel> (P'' \\<parallel> !P)\" using FrR \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close>\n        by(rule_tac tauStepChainPar2) auto\n      moreover have \"\\<Psi> \\<rhd> R \\<parallel> (P'' \\<parallel> !P) \\<longmapsto>\\<tau> \\<prec> \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (P' \\<parallel> !P))\"\n      proof -\n        from FrQ \\<open>\\<Psi>\\<^sub>Q' \\<simeq> \\<one>\\<close> \\<open>\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> R'\\<close> have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q' \\<rhd> R \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> R'\"\n          by simp (metis statEqTransition AssertionStatEqSym compositionSym)\n        moreover from P''Trans have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<one> \\<rhd> P'' \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n          by(rule statEqTransition) (metis Identity AssertionStatEqSym)\n        hence P''PTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P'' \\<parallel> !P \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> (P' \\<parallel> !P)\" using \\<open>xvec \\<sharp>* P\\<close>\n          by(rule_tac Par1) auto\n        moreover from FrP'' have FrP''P: \"extractFrame(P'' \\<parallel> !P) = \\<langle>A\\<^sub>P'', \\<Psi>\\<^sub>P'' \\<otimes> \\<one>\\<rangle>\"\n          by auto\n        moreover from FrQ \\<open>\\<Psi>\\<^sub>Q' \\<simeq> \\<one>\\<close> \\<open>\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M \\<leftrightarrow> K\\<close> have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q' \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> M \\<leftrightarrow> K\"\n          by simp (metis statEqEnt Composition AssertionStatEqSym Commutativity)\n        hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q' \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> K \\<leftrightarrow> M\" by(rule chanEqSym)\n        moreover have \"\\<langle>A\\<^sub>Q', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q') \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P'' \\<otimes> \\<one>)) \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n        proof -\n          have \"\\<langle>A\\<^sub>Q', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q') \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>Q', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q'\\<rangle>\"\n            by(rule_tac frameResChainPres, simp)\n              (metis Associativity Commutativity Composition AssertionStatEqTrans AssertionStatEqSym)\n          moreover from NilImpP'' FrQ FrP'' \\<open>A\\<^sub>P'' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>P'' \\<sharp>* \\<Psi>\\<^sub>R\\<close> freshCompChain have \"\\<langle>A\\<^sub>Q', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q'\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P''\\<rangle>\"\n            by auto\n          moreover have \"\\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P''\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<otimes> \\<one>) \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n            by(rule frameResChainPres, simp) \n              (metis Identity AssertionStatEqSym Associativity Commutativity Composition AssertionStatEqTrans)\n          ultimately show ?thesis by(rule FrameStatEqImpCompose)\n        qed\n        ultimately obtain M' where RTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<otimes> \\<one> \\<rhd> R \\<longmapsto>M'\\<lparr>N\\<rparr> \\<prec> R'\" and \"\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P'' \\<otimes> \\<one>) \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> K \\<leftrightarrow> M'\" and \"A\\<^sub>R \\<sharp>* M'\"\n          using FrR FrQ' \\<open>distinct A\\<^sub>R\\<close> \\<open>distinct A\\<^sub>P''\\<close> \\<open>A\\<^sub>P'' \\<sharp>* A\\<^sub>R\\<close> \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* P''\\<close> \\<open>A\\<^sub>R \\<sharp>* Q\\<close> \\<open>A\\<^sub>R \\<sharp>* R\\<close>  \\<open>A\\<^sub>R \\<sharp>* M\\<close> \\<open>A\\<^sub>Q' \\<sharp>* R\\<close> \\<open>A\\<^sub>Q' \\<sharp>* K\\<close> \\<open>A\\<^sub>Q' \\<sharp>* A\\<^sub>R\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>A\\<^sub>P'' \\<sharp>* P\\<close> \\<open>A\\<^sub>R \\<sharp>* xvec\\<close>\n                     \\<open>A\\<^sub>P'' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>P'' \\<sharp>* R\\<close>  \\<open>A\\<^sub>P'' \\<sharp>* P''\\<close> \\<open>A\\<^sub>P'' \\<sharp>* K\\<close> \\<open>xvec \\<sharp>* K\\<close> \\<open>distinct xvec\\<close>\n          by(rule_tac A\\<^sub>Q=\"A\\<^sub>Q'\" and Q=\"Q\" in comm2Aux) (assumption | simp)+\n\n        note RTrans FrR P''PTrans FrP''P\n        moreover from \\<open>\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P'' \\<otimes> \\<one>) \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> K \\<leftrightarrow> M'\\<close> have \"\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P'' \\<otimes> \\<one>) \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> M' \\<leftrightarrow> K\" by(rule chanEqSym)\n        hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>\\<^sub>P'' \\<otimes> \\<one> \\<turnstile> M' \\<leftrightarrow> K\" by(metis statEqEnt Composition AssertionStatEqSym Commutativity)\n        ultimately show ?thesis using \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* R\\<close> \\<open>A\\<^sub>R \\<sharp>* P''\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>A\\<^sub>R \\<sharp>* M'\\<close> \\<open>A\\<^sub>P'' \\<sharp>* A\\<^sub>R\\<close> \\<open>A\\<^sub>P'' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>P'' \\<sharp>* R\\<close> \\<open>A\\<^sub>P'' \\<sharp>* P''\\<close> \\<open>A\\<^sub>P'' \\<sharp>* P\\<close> \\<open>A\\<^sub>P'' \\<sharp>* K\\<close> \\<open>xvec \\<sharp>* R\\<close>\n          by(rule_tac Comm1) (assumption | simp)+\n      qed\n      ultimately show ?thesis\n        by(drule_tac tauActTauStepChain) auto\n    qed\n\n    moreover from P'Chain have \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>') \\<otimes> \\<one> \\<rhd> P' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> T\"\n      by(rule tauChainStatEq) (metis Identity AssertionStatEqSym)\n    hence \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<rhd> P' \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> T \\<parallel> !P\"\n      by(rule_tac tauChainPar1) auto\n    hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<rhd> P' \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> T \\<parallel> !P\"\n      by(rule tauChainStatEq) (metis Associativity)\n    hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R' \\<rhd> P' \\<parallel> !P\\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> T \\<parallel> !P\" using \\<open>\\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'\\<close>\n      by(rule_tac tauChainStatEq) (auto intro: compositionSym)\n    hence \"\\<Psi> \\<rhd> R' \\<parallel> (P' \\<parallel> !P) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> R' \\<parallel> (T \\<parallel> !P)\" using FrR' \\<open>A\\<^sub>R' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R' \\<sharp>* P\\<close> \\<open>A\\<^sub>R' \\<sharp>* P'\\<close>\n      by(rule_tac tauChainPar2) auto\n    hence \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (P' \\<parallel> !P)) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (T \\<parallel> !P))\" using \\<open>xvec \\<sharp>* \\<Psi>\\<close>\n      by(rule tauChainResChainPres)\n    ultimately have \"\\<Psi> \\<rhd> R \\<parallel> !P \\<Longrightarrow>\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (T \\<parallel> !P))\"\n      by auto\n    moreover have \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (T \\<parallel> !P)), \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> Q')) \\<in> Rel''\"\n    proof -\n      from \\<open>((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>', T, S) \\<in> Rel\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>', T, S) \\<in> Rel\"\n        by(rule StatEq) (metis Associativity)\n      hence \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R', T, S) \\<in> Rel\" using \\<open>\\<Psi>\\<^sub>R \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'\\<close>\n        by(rule_tac StatEq) (auto dest: compositionSym)\n\n      with FrR' \\<open>A\\<^sub>R' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R' \\<sharp>* S\\<close> \\<open>A\\<^sub>R' \\<sharp>* T\\<close> have \"(\\<Psi>, R' \\<parallel> T, R' \\<parallel> S) \\<in> Rel\"\n        by(rule_tac FrameParPres) auto\n      hence \"(\\<Psi>, (R' \\<parallel> T) \\<parallel> !P, (R' \\<parallel> S) \\<parallel> !P) \\<in> Rel\" by(rule ParPres)\n      hence \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>((R' \\<parallel> T) \\<parallel> !P), \\<lparr>\\<nu>*xvec\\<rparr>((R' \\<parallel> S) \\<parallel> !P)) \\<in> Rel\" using \\<open>xvec \\<sharp>* \\<Psi>\\<close>\n        by(rule ResPres)\n      hence \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> T) \\<parallel> !P, (\\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> S)) \\<parallel> !P) \\<in> Rel\" using \\<open>xvec \\<sharp>* \\<Psi>\\<close> \\<open>xvec \\<sharp>* P\\<close>\n        by(force intro: Trans ScopeExt)\n      hence \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (T \\<parallel> !P)), (\\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> S)) \\<parallel> !P) \\<in> Rel\" using \\<open>xvec \\<sharp>* \\<Psi>\\<close>\n        by(force intro: Trans ResPres Assoc)\n\n      moreover from \\<open>(\\<Psi>, P, Q) \\<in> Rel\\<close> \\<open>guarded P\\<close> \\<open>guarded Q\\<close> have \"(\\<Psi>, (\\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> S)) \\<parallel> !P, (\\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> S)) \\<parallel> !Q) \\<in> Rel''\"\n        by(rule C1)\n      moreover from \\<open>(\\<one>, Q', S \\<parallel> !Q) \\<in> Rel'\\<close> have \"(\\<one> \\<otimes> \\<Psi>, Q', S \\<parallel> !Q) \\<in> Rel'\" by(rule cExt')\n      hence \"(\\<Psi>, Q', S \\<parallel> !Q) \\<in> Rel'\" \n        by(rule StatEq') (metis Identity AssertionStatEqSym Commutativity AssertionStatEqTrans)\n      hence \"(\\<Psi>, R' \\<parallel> Q', R' \\<parallel> (S \\<parallel> !Q)) \\<in> Rel'\" by(rule ParPres')\n      hence \"(\\<Psi>, R' \\<parallel> Q', (R' \\<parallel> S) \\<parallel> !Q) \\<in> Rel'\" by(metis Trans' Assoc')\n      hence \"(\\<Psi>, (R' \\<parallel> S) \\<parallel> !Q, R' \\<parallel> Q') \\<in> Rel'\" by(rule cSym')\n      hence \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>((R' \\<parallel> S) \\<parallel> !Q), \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> Q')) \\<in> Rel'\" using \\<open>xvec \\<sharp>* \\<Psi>\\<close>\n        by(rule ResPres')\n      hence \"(\\<Psi>, (\\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> S)) \\<parallel> !Q, \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> Q')) \\<in> Rel'\" using \\<open>xvec \\<sharp>* \\<Psi>\\<close> \\<open>xvec \\<sharp>* Q\\<close>\n        by(force intro: Trans' ScopeExt'[THEN cSym'])\n      ultimately show ?thesis by(rule_tac Compose)\n    qed\n    ultimately show ?case by blast\n  next\n    case(cComm2 \\<Psi>\\<^sub>Q M xvec N R' A\\<^sub>R \\<Psi>\\<^sub>R K Q' A\\<^sub>Q)\n    from \\<open>A\\<^sub>R \\<sharp>* (P, Q, R)\\<close> have \"A\\<^sub>R \\<sharp>* P\" and \"A\\<^sub>R \\<sharp>* Q\" and \"A\\<^sub>R \\<sharp>* R\" by simp+\n    from \\<open>xvec \\<sharp>* (P, Q, R)\\<close> have \"xvec \\<sharp>* P\" and \"xvec \\<sharp>* Q\" and \"xvec \\<sharp>* R\" by simp+\n    have FrQ: \"extractFrame(!Q) = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" by fact\n    have FrR: \"extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" by fact\n    from \\<open>\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> R'\\<close> FrR \\<open>distinct A\\<^sub>R\\<close> \\<open>A\\<^sub>R \\<sharp>* R\\<close> \\<open>A\\<^sub>R \\<sharp>* N\\<close> \\<open>A\\<^sub>R \\<sharp>* xvec\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>A\\<^sub>R \\<sharp>* Q\\<close> \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>xvec \\<sharp>* R\\<close> \\<open>xvec \\<sharp>* \\<Psi>\\<close> \\<open>xvec \\<sharp>* P\\<close> \\<open>xvec \\<sharp>* Q\\<close> \\<open>xvec \\<sharp>* M\\<close> \\<open>distinct xvec\\<close> \\<open>A\\<^sub>R \\<sharp>* M\\<close>\n    obtain p A\\<^sub>R' \\<Psi>\\<^sub>R' \\<Psi>' where FrR': \"extractFrame R' = \\<langle>A\\<^sub>R', \\<Psi>\\<^sub>R'\\<rangle>\" and \"(p \\<bullet> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'\" and \"A\\<^sub>R' \\<sharp>* xvec\" and \"A\\<^sub>R' \\<sharp>* P\" and \"A\\<^sub>R' \\<sharp>* Q\" and \"A\\<^sub>R' \\<sharp>* \\<Psi>\" and S: \"set p \\<subseteq> set xvec \\<times> set(p \\<bullet> xvec)\" and \"distinctPerm p\" and \"(p \\<bullet> xvec) \\<sharp>* N\" and \"(p \\<bullet> xvec) \\<sharp>* Q\" and \"(p \\<bullet> xvec) \\<sharp>* R'\" and \"(p \\<bullet> xvec) \\<sharp>* P\" and \"(p \\<bullet> xvec) \\<sharp>* \\<Psi>\" and \"A\\<^sub>R' \\<sharp>* N\" and \"A\\<^sub>R' \\<sharp>* xvec\" and \"A\\<^sub>R' \\<sharp>* (p \\<bullet> xvec)\"\n      by(rule_tac C=\"(\\<Psi>, P, Q)\"  and C'=\"(\\<Psi>, P, Q)\" in expandFrame) (assumption | simp)+\n\n    from \\<open>\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> R'\\<close> S \\<open>(p \\<bullet> xvec) \\<sharp>* N\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* R'\\<close>\n    have  RTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> R \\<longmapsto>M\\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> (p \\<bullet> R')\"\n      by(simp add: boundOutputChainAlpha'' residualInject)\n    from \\<open>(\\<Psi>, P, Q) \\<in> Rel\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R, P, Q) \\<in> Rel\" by(rule cExt)\n    moreover from \\<open>\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !Q \\<longmapsto>K\\<lparr>N\\<rparr> \\<prec> Q'\\<close> S \\<open>(p \\<bullet> xvec) \\<sharp>* Q\\<close> \\<open>xvec \\<sharp>* Q\\<close> \\<open>distinctPerm p\\<close>\n    have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !Q \\<longmapsto>K\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> (p \\<bullet> Q')\" by(rule_tac inputAlpha) auto\n    then obtain S where QTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>K\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> S\" and \"(\\<one>, (p \\<bullet> Q'), S \\<parallel> !Q) \\<in> Rel'\" \n      using \\<open>guarded Q\\<close>\n      by(fastforce dest: rBangActE)\n    ultimately obtain P' T where PTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R : Q \\<rhd> P \\<Longrightarrow>K\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> P'\" \n                             and P'Chain: \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> (p \\<bullet> \\<Psi>') \\<rhd> P' \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> T\" \n                             and \"((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> (p \\<bullet> \\<Psi>'), T, S) \\<in> Rel\"\n      by(fastforce dest: cSim weakSimE)\n\n    from \\<open>A\\<^sub>R' \\<sharp>* N\\<close> \\<open>A\\<^sub>R' \\<sharp>* xvec\\<close> \\<open>A\\<^sub>R' \\<sharp>* (p \\<bullet> xvec)\\<close> S have \"A\\<^sub>R' \\<sharp>* (p \\<bullet> N)\"\n      by(simp add: freshChainSimps)\n    with PTrans \\<open>A\\<^sub>R' \\<sharp>* P\\<close> have \"A\\<^sub>R' \\<sharp>* P'\" by(force dest: weakInputFreshChainDerivative)\n    with P'Chain have \"A\\<^sub>R' \\<sharp>* T\" by(force dest: tauChainFreshChain)+\n    from QTrans \\<open>A\\<^sub>R' \\<sharp>* Q\\<close> \\<open>A\\<^sub>R' \\<sharp>* (p \\<bullet> N)\\<close> have \"A\\<^sub>R' \\<sharp>* S\" by(force dest: inputFreshChainDerivative)\n\n    obtain A\\<^sub>Q' \\<Psi>\\<^sub>Q' where FrQ': \"extractFrame Q = \\<langle>A\\<^sub>Q', \\<Psi>\\<^sub>Q'\\<rangle>\" and \"A\\<^sub>Q' \\<sharp>* \\<Psi>\" and \"A\\<^sub>Q' \\<sharp>* \\<Psi>\\<^sub>R\" and \"A\\<^sub>Q' \\<sharp>* A\\<^sub>R\" and \"A\\<^sub>Q' \\<sharp>* M\" and \"A\\<^sub>Q' \\<sharp>* R\" and \"A\\<^sub>Q' \\<sharp>* K\"\n      by(rule_tac C=\"(\\<Psi>, \\<Psi>\\<^sub>R, A\\<^sub>R, K, M, R)\" in freshFrame) auto\n    from FrQ' \\<open>guarded Q\\<close> have \"\\<Psi>\\<^sub>Q' \\<simeq> \\<one>\" and \"supp \\<Psi>\\<^sub>Q' = ({}::name set)\" by(blast dest: guardedStatEq)+\n    hence \"A\\<^sub>Q' \\<sharp>* \\<Psi>\\<^sub>Q'\" by(auto simp add: fresh_star_def fresh_def)\n\n    from PTrans obtain P'' where PChain: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\"\n                             and NilImpP'': \"\\<langle>A\\<^sub>Q', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q'\\<rangle> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P'') (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R)\"\n                             and P''Trans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P'' \\<longmapsto>K\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> P'\"\n      using FrQ' \\<open>A\\<^sub>Q' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>Q' \\<sharp>* \\<Psi>\\<^sub>R\\<close> freshCompChain\n      by(drule_tac weakTransitionE) auto\n\n    from \\<open>(p \\<bullet> xvec) \\<sharp>* P\\<close> \\<open>xvec \\<sharp>* P\\<close> PChain have \"(p \\<bullet> xvec) \\<sharp>* P''\" and \"xvec \\<sharp>* P''\" \n      by(force dest: tauChainFreshChain)+\n    from \\<open>(p \\<bullet> xvec) \\<sharp>* N\\<close> \\<open>distinctPerm p\\<close> have \"xvec \\<sharp>* (p \\<bullet> N)\"\n      by(subst pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst, where pi=p, symmetric]) simp\n    with P''Trans \\<open>xvec \\<sharp>* P''\\<close> have \"xvec \\<sharp>* P'\" by(force dest: inputFreshChainDerivative)\n    hence \"(p \\<bullet> xvec) \\<sharp>* (p \\<bullet> P')\" by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n\n    from PChain have \"\\<Psi> \\<rhd> R \\<parallel> !P \\<Longrightarrow>\\<^sub>\\<tau> \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> R') \\<parallel> (P' \\<parallel> !P))\"\n    proof(induct rule: tauChainCases)\n      case TauBase\n      from RTrans FrQ have \"\\<Psi> \\<otimes> \\<one> \\<rhd> R \\<longmapsto>M\\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> (p \\<bullet> R')\" by simp\n      moreover note FrR\n      moreover from P''Trans \\<open>P = P''\\<close> have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<longmapsto>K\\<lparr>(p \\<bullet> N)\\<rparr>\\<prec> P'\" by simp\n      hence \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<one> \\<rhd> P \\<longmapsto>K\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> P'\" \n        by(rule statEqTransition) (metis Identity AssertionStatEqSym)\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<parallel> !P \\<longmapsto>K\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> (P' \\<parallel> !P)\" by(force intro: Par1)\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !P \\<longmapsto>K\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> (P' \\<parallel> !P)\" using \\<open>guarded P\\<close> by(rule Bang)\n      moreover from \\<open>\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M \\<leftrightarrow> K\\<close> FrQ have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<one> \\<turnstile> M \\<leftrightarrow> K\" by simp\n      ultimately have \"\\<Psi> \\<rhd> R \\<parallel> !P \\<longmapsto>\\<tau> \\<prec> \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> R') \\<parallel> (P' \\<parallel> !P))\" using \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* R\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>A\\<^sub>R \\<sharp>* M\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* P\\<close>\n        by(force intro: Comm2)\n      thus ?case by(rule tauActTauStepChain)\n    next\n      case TauStep\n      obtain A\\<^sub>P'' \\<Psi>\\<^sub>P'' where FrP'': \"extractFrame P'' = \\<langle>A\\<^sub>P'', \\<Psi>\\<^sub>P''\\<rangle>\" and \"A\\<^sub>P'' \\<sharp>* \\<Psi>\" and \"A\\<^sub>P'' \\<sharp>* K\" and \"A\\<^sub>P'' \\<sharp>* \\<Psi>\\<^sub>R\" and \"A\\<^sub>P'' \\<sharp>* R\" and \"A\\<^sub>P'' \\<sharp>* P''\" and \"A\\<^sub>P'' \\<sharp>* P\"\n                          and \"A\\<^sub>P'' \\<sharp>* A\\<^sub>R\" and \"distinct A\\<^sub>P''\"\n        by(rule_tac C=\"(\\<Psi>, K, A\\<^sub>R, \\<Psi>\\<^sub>R, R, P'', P)\" in freshFrame) auto\n      from PChain \\<open>A\\<^sub>R \\<sharp>* P\\<close> have \"A\\<^sub>R \\<sharp>* P''\" by(drule_tac tauChainFreshChain) auto\n      with FrP'' \\<open>A\\<^sub>P'' \\<sharp>* A\\<^sub>R\\<close> have \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P''\" by(drule_tac extractFrameFreshChain) auto\n      from \\<open>\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P''\\<close> have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<one> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P''\" by(rule tauStepChainStatEq) (metis Identity AssertionStatEqSym)\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P \\<parallel> !P \\<Longrightarrow>\\<^sub>\\<tau> P'' \\<parallel> !P\" by(rule_tac tauStepChainPar1) auto\n      hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> !P \\<Longrightarrow>\\<^sub>\\<tau> P'' \\<parallel> !P\" using \\<open>guarded P\\<close> by(rule tauStepChainBang)\n      hence  \"\\<Psi> \\<rhd> R \\<parallel> !P \\<Longrightarrow>\\<^sub>\\<tau> R \\<parallel> (P'' \\<parallel> !P)\" using FrR \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close>\n        by(rule_tac tauStepChainPar2) auto\n      moreover have \"\\<Psi> \\<rhd> R \\<parallel> (P'' \\<parallel> !P) \\<longmapsto>\\<tau> \\<prec> \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>((p \\<bullet> R') \\<parallel> (P' \\<parallel> !P))\"\n      proof -\n        from FrQ \\<open>\\<Psi>\\<^sub>Q' \\<simeq> \\<one>\\<close> RTrans have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q' \\<rhd> R \\<longmapsto>M\\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> (p \\<bullet> R')\"\n          by simp (metis statEqTransition AssertionStatEqSym compositionSym)\n        moreover from P''Trans have \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<one> \\<rhd> P'' \\<longmapsto>K\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> P'\"\n          by(rule statEqTransition) (metis Identity AssertionStatEqSym)\n        hence P''PTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> P'' \\<parallel> !P \\<longmapsto>K\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> (P' \\<parallel> !P)\"\n          by(rule_tac Par1) auto\n        moreover from FrP'' have FrP''P: \"extractFrame(P'' \\<parallel> !P) = \\<langle>A\\<^sub>P'', \\<Psi>\\<^sub>P'' \\<otimes> \\<one>\\<rangle>\"\n          by auto\n        moreover from FrQ \\<open>\\<Psi>\\<^sub>Q' \\<simeq> \\<one>\\<close> \\<open>\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M \\<leftrightarrow> K\\<close> have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q' \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> M \\<leftrightarrow> K\"\n          by simp (metis statEqEnt Composition AssertionStatEqSym Commutativity)\n        hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q' \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> K \\<leftrightarrow> M\" by(rule chanEqSym)\n        moreover have \"\\<langle>A\\<^sub>Q', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q') \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P'' \\<otimes> \\<one>)) \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n        proof -\n          have \"\\<langle>A\\<^sub>Q', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q') \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>Q', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q'\\<rangle>\"\n            by(rule_tac frameResChainPres, simp)\n              (metis Associativity Commutativity Composition AssertionStatEqTrans AssertionStatEqSym)\n          moreover from NilImpP'' FrQ FrP'' \\<open>A\\<^sub>P'' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>P'' \\<sharp>* \\<Psi>\\<^sub>R\\<close> freshCompChain have \"\\<langle>A\\<^sub>Q', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q'\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P''\\<rangle>\"\n            by auto\n          moreover have \"\\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>P''\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<otimes> \\<one>) \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n            by(rule frameResChainPres, simp) \n              (metis Identity AssertionStatEqSym Associativity Commutativity Composition AssertionStatEqTrans)\n          ultimately show ?thesis by(rule FrameStatEqImpCompose)\n        qed\n        ultimately obtain M' where RTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<otimes> \\<one> \\<rhd> R \\<longmapsto>M'\\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> (p \\<bullet> R')\" and \"\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P'' \\<otimes> \\<one>) \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> K \\<leftrightarrow> M'\" and \"A\\<^sub>R \\<sharp>* M'\"\n          using FrR FrQ' \\<open>distinct A\\<^sub>R\\<close> \\<open>distinct A\\<^sub>P''\\<close> \\<open>A\\<^sub>P'' \\<sharp>* A\\<^sub>R\\<close> \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* P''\\<close> \\<open>A\\<^sub>R \\<sharp>* Q\\<close> \\<open>A\\<^sub>R \\<sharp>* R\\<close>  \\<open>A\\<^sub>R \\<sharp>* M\\<close> \\<open>A\\<^sub>Q' \\<sharp>* R\\<close> \\<open>A\\<^sub>Q' \\<sharp>* K\\<close> \\<open>A\\<^sub>Q' \\<sharp>* A\\<^sub>R\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>A\\<^sub>P'' \\<sharp>* P\\<close>\n                     \\<open>A\\<^sub>P'' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>P'' \\<sharp>* R\\<close>  \\<open>A\\<^sub>P'' \\<sharp>* P''\\<close> \\<open>A\\<^sub>P'' \\<sharp>* K\\<close>\n          by(rule_tac A\\<^sub>Q=\"A\\<^sub>Q'\" and Q=\"Q\" in comm1Aux) (assumption | simp)+\n\n        note RTrans FrR P''PTrans FrP''P\n        moreover from \\<open>\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P'' \\<otimes> \\<one>) \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> K \\<leftrightarrow> M'\\<close> have \"\\<Psi> \\<otimes> (\\<Psi>\\<^sub>P'' \\<otimes> \\<one>) \\<otimes> \\<Psi>\\<^sub>R \\<turnstile> M' \\<leftrightarrow> K\" by(rule chanEqSym)\n        hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>\\<^sub>P'' \\<otimes> \\<one> \\<turnstile> M' \\<leftrightarrow> K\" by(metis statEqEnt Composition AssertionStatEqSym Commutativity)\n        ultimately show ?thesis using \\<open>A\\<^sub>R \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R \\<sharp>* R\\<close> \\<open>A\\<^sub>R \\<sharp>* P''\\<close> \\<open>A\\<^sub>R \\<sharp>* P\\<close> \\<open>A\\<^sub>R \\<sharp>* M'\\<close> \\<open>A\\<^sub>P'' \\<sharp>* A\\<^sub>R\\<close> \\<open>A\\<^sub>P'' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>P'' \\<sharp>* R\\<close> \\<open>A\\<^sub>P'' \\<sharp>* P''\\<close> \\<open>A\\<^sub>P'' \\<sharp>* P\\<close> \\<open>A\\<^sub>P'' \\<sharp>* K\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* P''\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* P\\<close>\n          by(rule_tac Comm2) (assumption | simp)+\n      qed\n      ultimately show ?thesis\n        by(drule_tac tauActTauStepChain) auto\n    qed\n    hence \"\\<Psi> \\<rhd> R \\<parallel> !P \\<Longrightarrow>\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> ((p \\<bullet> P') \\<parallel> !P))\" \n      using \\<open>xvec \\<sharp>* P\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* P\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* (p \\<bullet> P')\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* R'\\<close> S \\<open>distinctPerm p\\<close>\n      by(subst resChainAlpha[where p=p]) auto\n    moreover from P'Chain have \"(p \\<bullet> ((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> (p \\<bullet> \\<Psi>'))) \\<rhd> (p \\<bullet> P') \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> (p \\<bullet> T)\"\n      by(rule tauChainEqvt)\n    with \\<open>xvec \\<sharp>* \\<Psi>\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* \\<Psi>\\<close> S \\<open>distinctPerm p\\<close>\n    have \"(\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> \\<Psi>' \\<rhd> (p \\<bullet> P') \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> (p \\<bullet> T)\" by(simp add: eqvts)\n    hence \"((\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> \\<Psi>') \\<otimes> \\<one> \\<rhd> (p \\<bullet> P') \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> (p \\<bullet> T)\"\n      by(rule tauChainStatEq) (metis Identity AssertionStatEqSym)\n    hence \"(\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> \\<Psi>' \\<rhd> (p \\<bullet> P') \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> (p \\<bullet> T) \\<parallel> !P\"\n      by(rule_tac tauChainPar1) auto\n    hence \"\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<rhd> (p \\<bullet> P') \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> (p \\<bullet> T) \\<parallel> !P\"\n      by(rule tauChainStatEq) (metis Associativity)\n    hence \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R' \\<rhd> (p \\<bullet> P') \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> (p \\<bullet> T) \\<parallel> !P\" using \\<open>(p \\<bullet> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<simeq>  \\<Psi>\\<^sub>R'\\<close>\n      by(rule_tac tauChainStatEq) (auto intro: compositionSym)\n    hence \"\\<Psi> \\<rhd> R' \\<parallel> ((p \\<bullet> P') \\<parallel> !P) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> R' \\<parallel> ((p \\<bullet> T) \\<parallel> !P)\" \n      using FrR' \\<open>A\\<^sub>R' \\<sharp>* \\<Psi>\\<close> \\<open>A\\<^sub>R' \\<sharp>* P\\<close> \\<open>A\\<^sub>R' \\<sharp>* P'\\<close> \\<open>A\\<^sub>R' \\<sharp>* xvec\\<close> \\<open>A\\<^sub>R' \\<sharp>* (p \\<bullet> xvec)\\<close> S\n      by(rule_tac tauChainPar2) (auto simp add: freshChainSimps)\n    hence \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> ((p \\<bullet> P') \\<parallel> !P)) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> ((p \\<bullet> T) \\<parallel> !P))\" using \\<open>xvec \\<sharp>* \\<Psi>\\<close>\n      by(rule tauChainResChainPres)\n    ultimately have \"\\<Psi> \\<rhd> R \\<parallel> !P \\<Longrightarrow>\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> ((p \\<bullet> T) \\<parallel> !P))\"\n      by auto\n    moreover have \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> ((p \\<bullet> T) \\<parallel> !P)), \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> Q')) \\<in> Rel''\"\n    proof -\n      from \\<open>((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> (p \\<bullet> \\<Psi>'), T, S) \\<in> Rel\\<close> \n      have \"(p \\<bullet> ((\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> (p \\<bullet> \\<Psi>')), (p \\<bullet> T), (p \\<bullet> S)) \\<in> Rel\"\n        by(rule Closed)\n      with \\<open>xvec \\<sharp>* \\<Psi>\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* \\<Psi>\\<close> \\<open>distinctPerm p\\<close> S\n      have \"((\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R)) \\<otimes> \\<Psi>', p \\<bullet> T, p \\<bullet> S) \\<in> Rel\"\n        by(simp add: eqvts)\n      hence \"(\\<Psi> \\<otimes> (p \\<bullet> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>', p \\<bullet> T, p \\<bullet> S) \\<in> Rel\"\n        by(rule StatEq) (metis Associativity)\n      hence \"(\\<Psi> \\<otimes> \\<Psi>\\<^sub>R', p \\<bullet> T, p \\<bullet> S) \\<in> Rel\" using \\<open>(p \\<bullet> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>R'\\<close>\n        by(rule_tac StatEq) (auto dest: compositionSym)\n      moreover from \\<open>A\\<^sub>R' \\<sharp>* S\\<close> \\<open>A\\<^sub>R' \\<sharp>* T\\<close> \\<open>A\\<^sub>R' \\<sharp>* xvec\\<close> \\<open>A\\<^sub>R' \\<sharp>* (p \\<bullet> xvec)\\<close> S\n      have \"A\\<^sub>R' \\<sharp>* (p \\<bullet> S)\" and \"A\\<^sub>R' \\<sharp>* (p \\<bullet> T)\"\n        by(simp add: freshChainSimps)+\n      ultimately have \"(\\<Psi>, R' \\<parallel> (p \\<bullet> T), R' \\<parallel> (p \\<bullet> S)) \\<in> Rel\" using FrR' \\<open>A\\<^sub>R' \\<sharp>* \\<Psi>\\<close>\n        by(rule_tac FrameParPres) auto\n      hence \"(\\<Psi>, (R' \\<parallel> (p \\<bullet> T)) \\<parallel> !P, (R' \\<parallel> (p \\<bullet> S)) \\<parallel> !P) \\<in> Rel\" by(rule ParPres)\n      hence \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>((R' \\<parallel> (p \\<bullet> T)) \\<parallel> !P), \\<lparr>\\<nu>*xvec\\<rparr>((R' \\<parallel> (p \\<bullet> S)) \\<parallel> !P)) \\<in> Rel\" \n        using \\<open>xvec \\<sharp>* \\<Psi>\\<close>\n        by(rule ResPres)\n      hence \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (p \\<bullet> T)) \\<parallel> !P, (\\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (p \\<bullet> S))) \\<parallel> !P) \\<in> Rel\" \n        using \\<open>xvec \\<sharp>* \\<Psi>\\<close> \\<open>xvec \\<sharp>* P\\<close>\n        by(force intro: Trans ScopeExt)\n      hence \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> ((p \\<bullet> T) \\<parallel> !P)), (\\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (p \\<bullet> S))) \\<parallel> !P) \\<in> Rel\"\n        using \\<open>xvec \\<sharp>* \\<Psi>\\<close>\n        by(force intro: Trans ResPres Assoc)\n      moreover from \\<open>(\\<Psi>, P, Q) \\<in> Rel\\<close> \\<open>guarded P\\<close> \\<open>guarded Q\\<close> \n      have \"(\\<Psi>, (\\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (p \\<bullet> S))) \\<parallel> !P, (\\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (p \\<bullet> S))) \\<parallel> !Q) \\<in> Rel''\"\n        by(rule C1)\n      moreover from \\<open>(\\<one>, (p \\<bullet> Q'), S \\<parallel> !Q) \\<in> Rel'\\<close> \n      have \"(p \\<bullet> \\<one>, p \\<bullet> p \\<bullet> Q', p \\<bullet> (S \\<parallel> !Q)) \\<in> Rel'\" by(rule Closed')\n      with \\<open>xvec \\<sharp>* Q\\<close> \\<open>(p \\<bullet> xvec) \\<sharp>* Q\\<close> S \\<open>distinctPerm p\\<close> \n        have \"(\\<one>, Q', (p \\<bullet> S) \\<parallel> !Q) \\<in> Rel'\" by(simp add: eqvts)\n      hence \"(\\<one> \\<otimes> \\<Psi>, Q', (p \\<bullet> S) \\<parallel> !Q) \\<in> Rel'\" by(rule cExt')\n      hence \"(\\<Psi>, Q', (p \\<bullet> S) \\<parallel> !Q) \\<in> Rel'\" \n        by(rule StatEq') (metis Identity AssertionStatEqSym Commutativity AssertionStatEqTrans)\n      hence \"(\\<Psi>, R' \\<parallel> Q', R' \\<parallel> ((p \\<bullet> S) \\<parallel> !Q)) \\<in> Rel'\" by(rule ParPres')\n      hence \"(\\<Psi>, R' \\<parallel> Q', (R' \\<parallel> (p \\<bullet> S)) \\<parallel> !Q) \\<in> Rel'\" by(metis Trans' Assoc')\n      hence \"(\\<Psi>, (R' \\<parallel> (p \\<bullet> S)) \\<parallel> !Q, R' \\<parallel> Q') \\<in> Rel'\" by(rule cSym')\n      hence \"(\\<Psi>, \\<lparr>\\<nu>*xvec\\<rparr>((R' \\<parallel> (p \\<bullet> S)) \\<parallel> !Q), \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> Q')) \\<in> Rel'\" using \\<open>xvec \\<sharp>* \\<Psi>\\<close>\n        by(rule ResPres')\n      hence \"(\\<Psi>, (\\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> (p \\<bullet> S))) \\<parallel> !Q, \\<lparr>\\<nu>*xvec\\<rparr>(R' \\<parallel> Q')) \\<in> Rel'\" using \\<open>xvec \\<sharp>* \\<Psi>\\<close> \\<open>xvec \\<sharp>* Q\\<close>\n        by(force intro: Trans' ScopeExt'[THEN cSym'])\n      ultimately show ?thesis by(rule_tac Compose)\n    qed\n    ultimately show ?case by blast\n  qed\nqed\nnotation relcomp (infixr \"O\" 75)\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Psi_Calculi/Weak_Cong_Sim_Pres.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.531209388216861, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.25523478461707483}}
{"text": "section {*L\\_ATS\\_Simulation\\_Configuration\\_WeakLR\\_Marked\\_Effect*}\ntheory\n  L_ATS_Simulation_Configuration_WeakLR_Marked_Effect\n\nimports\n  L_ATS_Simulation_Configuration_WeakLR_Marking_Condition\n\nbegin\n\nlocale ATS_Simulation_Configuration_Weak_Marked_Effect =\n  ATS_Simulation_Configuration_WeakLR_Marking_Condition\n  \"TSstructure1 :: 'TSstructure1 \\<Rightarrow> bool\"\n  \"configurations1 :: 'TSstructure1 \\<Rightarrow> 'conf1 set\"\n  \"initial_configurations1 :: 'TSstructure1 \\<Rightarrow> 'conf1 set\"\n  \"step_labels1 :: 'TSstructure1 \\<Rightarrow> 'label1 set\"\n  \"step_relation1 :: 'TSstructure1 \\<Rightarrow> 'conf1 \\<Rightarrow> 'label1 \\<Rightarrow> 'conf1 \\<Rightarrow> bool\"\n  \"effects1 :: 'TSstructure1 \\<Rightarrow> 'event1 set\"\n  \"marking_condition1 :: 'TSstructure1 \\<Rightarrow> ('label1,'conf1)derivation \\<Rightarrow> bool\"\n  \"marked_effect1 :: 'TSstructure1 \\<Rightarrow> ('label1,'conf1)derivation \\<Rightarrow> 'event1 set\"\n  \"unmarked_effect1 :: 'TSstructure1 \\<Rightarrow> ('label1,'conf1)derivation \\<Rightarrow> 'event1 set\"\n  \"TSstructure2 :: 'TSstructure2 \\<Rightarrow> bool\"\n  \"configurations2 :: 'TSstructure2 \\<Rightarrow> 'conf2 set\"\n  \"initial_configurations2 :: 'TSstructure2 \\<Rightarrow> 'conf2 set\"\n  \"step_labels2 :: 'TSstructure2 \\<Rightarrow> 'label2 set\"\n  \"step_relation2 :: 'TSstructure2 \\<Rightarrow> 'conf2 \\<Rightarrow> 'label2 \\<Rightarrow> 'conf2 \\<Rightarrow> bool\"\n  \"effects2 :: 'TSstructure2 \\<Rightarrow> 'event2 set\"\n  \"marking_condition2 :: 'TSstructure2 \\<Rightarrow> ('label2,'conf2)derivation \\<Rightarrow> bool\"\n  \"marked_effect2 :: 'TSstructure2 \\<Rightarrow> ('label2,'conf2)derivation \\<Rightarrow> 'event2 set\"\n  \"unmarked_effect2 :: 'TSstructure2 \\<Rightarrow> ('label2,'conf2)derivation \\<Rightarrow> 'event2 set\"\n  \"relation_configuration :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'conf1 \\<Rightarrow> 'conf2 \\<Rightarrow> bool\"\n  \"relation_initial_configuration :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'conf1 \\<Rightarrow> 'conf2 \\<Rightarrow> bool\"\n  \"relation_effect :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'event1 \\<Rightarrow> 'event2 \\<Rightarrow> bool\"\n  \"relation_TSstructure :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> bool\"\n  \"relation_initial_simulation :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'conf1 \\<Rightarrow> (nat \\<Rightarrow> ('label2, 'conf2) derivation_configuration option) \\<Rightarrow> bool\"\n  \"relation_step_simulation :: 'TSstructure1 \\<Rightarrow> 'TSstructure2 \\<Rightarrow> 'conf1 \\<Rightarrow> 'label1 \\<Rightarrow> 'conf1 \\<Rightarrow> 'conf2 \\<Rightarrow> (nat \\<Rightarrow> ('label2, 'conf2) derivation_configuration option) \\<Rightarrow> bool\"\n  for\n    TSstructure1 configurations1 initial_configurations1 step_labels1 step_relation1 effects1 marking_condition1 marked_effect1 unmarked_effect1 TSstructure2 configurations2 initial_configurations2 step_labels2 step_relation2 effects2 marking_condition2 marked_effect2 unmarked_effect2 relation_configuration relation_initial_configuration relation_effect relation_TSstructure relation_initial_simulation relation_step_simulation\n    +\n\nassumes AX_relation_step_simulation_preserves_marked_effect: \"\n  relation_step_simulation_preservation G1 G2 d1' d2'\n  \\<Longrightarrow> left_total_on\n        (relation_effect G1 G2)\n        (marked_effect1 G1 d1')\n        (marked_effect2 G2 d2')\"\n\nassumes AX_relation_initial_simulation_preserves_marked_effect: \"\n  relation_initial_simulation_preservation G1 G2 d1' d2'\n  \\<Longrightarrow> left_total_on\n        (relation_effect G1 G2)\n        (marked_effect1 G1 d1')\n        (marked_effect2 G2 d2')\"\n\ncontext ATS_Simulation_Configuration_Weak_Marked_Effect begin\n\ntheorem ATS_Simulation_Configuration_Weak_Marked_Effect_sound: \"\n  relation_TSstructure G1 G2\n  \\<Longrightarrow> left_total_on (relation_effect G1 G2) (GL.finite_marked_language G1) (GR.finite_marked_language G2)\"\n  apply(simp add: left_total_on_def)\n  apply(clarsimp)\n  apply(rename_tac a)(*strict*)\n  apply(simp add: GL.finite_marked_language_def)\n  apply(clarsimp)\n  apply(rename_tac a d x)(*strict*)\n  apply(case_tac x)\n   apply(rename_tac a d x)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac a d)(*strict*)\n   apply(subgoal_tac \"\\<exists>c. d 0 = Some (pair None c)\")\n    apply(rename_tac a d)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac a d c)(*strict*)\n    apply(rename_tac c1)\n    apply(rename_tac a d c1)(*strict*)\n    apply(subgoal_tac \"c1 \\<in> initial_configurations1 G1\")\n     apply(rename_tac a d c1)(*strict*)\n     prefer 2\n     apply(simp add: GL.derivation_initial_def)\n    apply(rename_tac a d c1)(*strict*)\n    apply(subgoal_tac \"\\<exists>d2 n. GR.derivation_initial G2 d2 \\<and> relation_initial_configuration G1 G2 c1 (the(get_configuration(d2 0))) \\<and> relation_initial_simulation G1 G2 c1 d2 \\<and> maximum_of_domain d2 n \\<and> relation_configuration G1 G2 c1 (the(get_configuration(d2 n)))\")\n     apply(rename_tac a d c1)(*strict*)\n     prefer 2\n     apply(rule AX_relation_initial_simulation)\n      apply(rename_tac a d c1)(*strict*)\n      apply(force)\n     apply(rename_tac a d c1)(*strict*)\n     apply(force)\n    apply(rename_tac a d c1)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac a d c1 d2 n)(*strict*)\n    apply(subgoal_tac \"\\<exists>c2. d2 0 = Some (pair None c2)\")\n     apply(rename_tac a d c1 d2 n)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac a d c1 d2 n c2)(*strict*)\n     apply(subgoal_tac \"left_total_on (relation_effect G1 G2) (marked_effect1 G1 (derivation_append (der1 c1) (der1 c1) 0)) (marked_effect2 G2 (derivation_append (der1 (the(get_configuration(d2 0)))) d2 0))\")\n      apply(rename_tac a d c1 d2 n c2)(*strict*)\n      prefer 2\n      apply(rule AX_relation_initial_simulation_preserves_marked_effect)\n      apply(rule_tac\n      ?d1.0=\"der1 c1\"\n      and ?d2.0=\"der1 (the(get_configuration(d2 0)))\"\n      and ?n1.0=\"0\"\n      and ?n2.0=\"0\"\n      and ds=\"d2\"\n      and f=\"\\<lambda>x. n\"\n      in relation_initial_simulation_preservation_PROVE)\n                   apply(rename_tac a d c1 d2 n c2)(*strict*)\n                   prefer 13\n                   apply(force)\n                  apply(rename_tac a d c1 d2 n c2)(*strict*)\n                  prefer 12\n                  apply(force)\n                 apply(rename_tac a d c1 d2 n c2)(*strict*)\n                 apply(force)\n                apply(rename_tac a d c1 d2 n c2)(*strict*)\n                apply(force)\n               apply(rename_tac a d c1 d2 n c2)(*strict*)\n               apply(force)\n              apply(rename_tac a d c1 d2 n c2)(*strict*)\n              apply(force)\n             apply(rename_tac a d c1 d2 n c2)(*strict*)\n             apply(simp add: GL.derivation_initial_def)\n             apply(rule conjI)\n              apply(rename_tac a d c1 d2 n c2)(*strict*)\n              apply(rule GL.der1_is_derivation)\n             apply(rename_tac a d c1 d2 n c2)(*strict*)\n             apply(simp add: der1_def)\n            apply(rename_tac a d c1 d2 n c2)(*strict*)\n            apply(rule der1_maximum_of_domain)\n           apply(rename_tac a d c1 d2 n c2)(*strict*)\n           apply(simp add: GR.derivation_initial_def)\n           apply(rule conjI)\n            apply(rename_tac a d c1 d2 n c2)(*strict*)\n            apply(rule GR.der1_is_derivation)\n           apply(rename_tac a d c1 d2 n c2)(*strict*)\n           apply(simp add: der1_def get_configuration_def)\n          apply(rename_tac a d c1 d2 n c2)(*strict*)\n          apply(rule der1_maximum_of_domain)\n         apply(rename_tac a d c1 d2 n c2)(*strict*)\n         apply(simp add: der1_def get_configuration_def)\n        apply(rename_tac a d c1 d2 n c2)(*strict*)\n        apply(simp add: derivation_append_fit_def der1_def)\n       apply(rename_tac a d c1 d2 n c2)(*strict*)\n       apply(simp add: derivation_append_fit_def der1_def get_configuration_def)\n      apply(rename_tac a d c1 d2 n c2)(*strict*)\n      apply(rule_tac\n      t=\"derivation_append (der1 c1) (der1 c1) 0\"\n      and s=\"der1 c1\"\n      in ssubst)\n       apply(rename_tac a d c1 d2 n c2)(*strict*)\n       apply(rule ext)\n       apply(rename_tac a d c1 d2 n c2 x)(*strict*)\n       apply(simp add: derivation_append_def der1_def)\n      apply(rename_tac a d c1 d2 n c2)(*strict*)\n      apply(rule_tac\n      t=\"derivation_append (der1 (the (get_configuration (d2 0)))) d2 0\"\n      and s=\"d2\"\n      in ssubst)\n       apply(rename_tac a d c1 d2 n c2)(*strict*)\n       apply(rule ext)\n       apply(rename_tac a d c1 d2 n c2 x)(*strict*)\n       apply(simp add: derivation_append_def get_configuration_def der1_def)\n      apply(rename_tac a d c1 d2 n c2)(*strict*)\n      apply(clarsimp)\n      apply(simp add: simulating_derivation_def)\n      apply(rule conjI)\n       apply(rename_tac a d c1 d2 n c2)(*strict*)\n       apply(simp add: simulating_derivation_I_def)\n       apply(simp add: der1_def)\n       apply(simp add: get_configuration_def)\n       apply(rule_tac\n      t=\"derivation_take d2 n\"\n      and s=\"d2\"\n      in ssubst)\n        apply(rename_tac a d c1 d2 n c2)(*strict*)\n        apply(rule ext)\n        apply(rename_tac a d c1 d2 n c2 x)(*strict*)\n        apply(simp add: derivation_take_def)\n        apply(clarsimp)\n        apply(rule sym)\n        apply(rule GR.none_position_after_max_dom)\n          apply(rename_tac a d c1 d2 n c2 x)(*strict*)\n          apply(rule GR.derivation_initial_is_derivation)\n          apply(force)\n         apply(rename_tac a d c1 d2 n c2 x)(*strict*)\n         apply(force)\n        apply(rename_tac a d c1 d2 n c2 x)(*strict*)\n        apply(force)\n       apply(rename_tac a d c1 d2 n c2)(*strict*)\n       apply(rule conjI)\n        apply(rename_tac a d c1 d2 n c2)(*strict*)\n        apply(force)\n       apply(rename_tac a d c1 d2 n c2)(*strict*)\n       apply(rule conjI)\n        apply(rename_tac a d c1 d2 n c2)(*strict*)\n        apply(force)\n       apply(rename_tac a d c1 d2 n c2)(*strict*)\n       apply(simp add: maximum_of_domain_def)\n      apply(rename_tac a d c1 d2 n c2)(*strict*)\n      apply(rule conjI)\n       apply(rename_tac a d c1 d2 n c2)(*strict*)\n       apply(simp add: simulating_derivation_S_def)\n      apply(rename_tac a d c1 d2 n c2)(*strict*)\n      apply(simp add: simulating_derivation_DEF_def)\n      apply(rule conjI)\n       apply(rename_tac a d c1 d2 n c2)(*strict*)\n       apply(simp add: maximum_of_domain_def)\n      apply(rename_tac a d c1 d2 n c2)(*strict*)\n      apply(simp add: get_configuration_def der1_def)\n     apply(rename_tac a d c1 d2 n c2)(*strict*)\n     apply(subgoal_tac \"left_total_on (relation_effect G1 G2) (marked_effect1 G1 d) (marked_effect2 G2 d2)\")\n      apply(rename_tac a d c1 d2 n c2)(*strict*)\n      prefer 2\n      apply(rule_tac\n      t=\"d\"\n      and s=\"derivation_append (der1 c1) (der1 c1) 0\"\n      in ssubst)\n       apply(rename_tac a d c1 d2 n c2)(*strict*)\n       apply(rule ext)\n       apply(rename_tac a d c1 d2 n c2 x)(*strict*)\n       apply(simp add: derivation_append_def der1_def)\n       apply(clarsimp)\n       apply (metis GL.derivation_initial_is_derivation GL.noSomeAfterMaxDom)\n      apply(rename_tac a d c1 d2 n c2)(*strict*)\n      apply(rule_tac\n      t=\"d2\"\n      and s=\"derivation_append (der1 (the (get_configuration (Some (pair None c2))))) d2 0\"\n      in ssubst)\n       apply(rename_tac a d c1 d2 n c2)(*strict*)\n       apply(rule ext)\n       apply(rename_tac a d c1 d2 n c2 x)(*strict*)\n       apply(simp add: derivation_append_def der1_def get_configuration_def)\n      apply(rename_tac a d c1 d2 n c2)(*strict*)\n      apply(force)\n     apply(rename_tac a d c1 d2 n c2)(*strict*)\n     apply(thin_tac \"left_total_on (relation_effect G1 G2) (marked_effect1 G1 (derivation_append (der1 c1) (der1 c1) 0)) (marked_effect2 G2 (derivation_append (der1 (the (get_configuration (d2 0)))) d2 0))\")\n     apply(rename_tac a d c1 d2 n c2)(*strict*)\n     apply(subgoal_tac \"marking_condition2 G2 (derivation_append SSderi2 d2 0)\" for SSderi2)\n      apply(rename_tac a d c1 d2 n c2)(*strict*)\n      prefer 2\n      apply(rule AX_relation_initial_simulation_preserves_marking_condition)\n       apply(rename_tac a d c1 d2 n c2)(*strict*)\n       apply(rule_tac\n      ds=\"d2\"\n      and ?d1.0=\"der1 c1\"\n      and ?d2.0=\"der1 (the(get_configuration(d2 0)))\"\n      and ?n1.0=\"0\"\n      and ?n2.0=\"0\"\n      and f=\"\\<lambda>x. n\"\n      in relation_initial_simulation_preservation_PROVE)\n                    apply(rename_tac a d c1 d2 n c2)(*strict*)\n                    prefer 12\n                    apply(force)\n                   apply(rename_tac a d c1 d2 n c2)(*strict*)\n                   prefer 12\n                   apply(force)\n                  apply(rename_tac a d c1 d2 n c2)(*strict*)\n                  apply(force)\n                 apply(rename_tac a d c1 d2 n c2)(*strict*)\n                 apply(force)\n                apply(rename_tac a d c1 d2 n c2)(*strict*)\n                apply(force)\n               apply(rename_tac a d c1 d2 n c2)(*strict*)\n               apply(force)\n              apply(rename_tac a d c1 d2 n c2)(*strict*)\n              apply(simp add: GL.derivation_initial_def)\n              apply(rule conjI)\n               apply(rename_tac a d c1 d2 n c2)(*strict*)\n               apply(rule GL.der1_is_derivation)\n              apply(rename_tac a d c1 d2 n c2)(*strict*)\n              apply(simp add: der1_def)\n             apply(rename_tac a d c1 d2 n c2)(*strict*)\n             apply(rule der1_maximum_of_domain)\n            apply(rename_tac a d c1 d2 n c2)(*strict*)\n            apply(simp add: GR.derivation_initial_def)\n            apply(rule conjI)\n             apply(rename_tac a d c1 d2 n c2)(*strict*)\n             apply(rule GR.der1_is_derivation)\n            apply(rename_tac a d c1 d2 n c2)(*strict*)\n            apply(simp add: der1_def get_configuration_def)\n           apply(rename_tac a d c1 d2 n c2)(*strict*)\n           apply(rule der1_maximum_of_domain)\n          apply(rename_tac a d c1 d2 n c2)(*strict*)\n          apply(simp add: der1_def get_configuration_def)\n         apply(rename_tac a d c1 d2 n c2)(*strict*)\n         apply(simp add: derivation_append_fit_def der1_def)\n        apply(rename_tac a d c1 d2 n c2)(*strict*)\n        apply(simp add: derivation_append_fit_def der1_def get_configuration_def)\n       apply(rename_tac a d c1 d2 n c2)(*strict*)\n       apply(rule_tac\n      t=\"Some (pair None c2)\"\n      and s=\"d2 0\"\n      in ssubst)\n        apply(rename_tac a d c1 d2 n c2)(*strict*)\n        apply(force)\n       apply(rename_tac a d c1 d2 n c2)(*strict*)\n       apply(rule simulating_derivation_exist_initial)\n           apply(rename_tac a d c1 d2 n c2)(*strict*)\n           apply(force)\n          apply(rename_tac a d c1 d2 n c2)(*strict*)\n          apply(force)\n         apply(rename_tac a d c1 d2 n c2)(*strict*)\n         apply(force)\n        apply(rename_tac a d c1 d2 n c2)(*strict*)\n        apply(force)\n       apply(rename_tac a d c1 d2 n c2)(*strict*)\n       apply(force)\n      apply(rename_tac a d c1 d2 n c2)(*strict*)\n      apply(rule_tac\n      t=\"(derivation_append (der1 c1) (der1 c1) 0)\"\n      and s=\"d\"\n      in ssubst)\n       apply(rename_tac a d c1 d2 n c2)(*strict*)\n       prefer 2\n       apply(force)\n      apply(rename_tac a d c1 d2 n c2)(*strict*)\n      apply(rule ext)\n      apply(rename_tac a d c1 d2 n c2 x)(*strict*)\n      apply(simp add: derivation_append_def der1_def)\n      apply(clarsimp)\n      apply(rule sym)\n      apply(rule GL.none_position_after_max_dom)\n        apply(rename_tac a d c1 d2 n c2 x)(*strict*)\n        apply(rule GL.derivation_initial_is_derivation)\n        apply(force)\n       apply(rename_tac a d c1 d2 n c2 x)(*strict*)\n       apply(force)\n      apply(rename_tac a d c1 d2 n c2 x)(*strict*)\n      apply(force)\n     apply(rename_tac a d c1 d2 n c2)(*strict*)\n     apply(subgoal_tac \"marking_condition2 G2 d2\")\n      apply(rename_tac a d c1 d2 n c2)(*strict*)\n      prefer 2\n      apply(rule_tac\n      t=\"d2\"\n      and s=\"derivation_append (der1 (the (get_configuration (Some (pair None c2))))) d2 0\"\n      in ssubst)\n       apply(rename_tac a d c1 d2 n c2)(*strict*)\n       apply(rule ext)\n       apply(rename_tac a d c1 d2 n c2 x)(*strict*)\n       apply(simp add: derivation_append_def der1_def get_configuration_def)\n      apply(rename_tac a d c1 d2 n c2)(*strict*)\n      apply(force)\n     apply(rename_tac a d c1 d2 n c2)(*strict*)\n     apply(thin_tac \"marking_condition2 G2 (derivation_append (der1 (the (get_configuration (Some (pair None c2))))) d2 0)\")\n     apply(simp add: left_total_on_def)\n     apply(erule_tac\n      x=\"a\"\n      in ballE)\n      apply(rename_tac a d c1 d2 n c2)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac a d c1 d2 n c2 b)(*strict*)\n      apply(rule_tac\n      x=\"b\"\n      in bexI)\n       apply(rename_tac a d c1 d2 n c2 b)(*strict*)\n       apply(force)\n      apply(rename_tac a d c1 d2 n c2 b)(*strict*)\n      apply(simp add: GR.finite_marked_language_def)\n      apply(rule_tac\n      x=\"d2\"\n      in exI)\n      apply(clarsimp)\n      apply(force)\n     apply(rename_tac a d c1 d2 n c2)(*strict*)\n     apply(force)\n    apply(rename_tac a d c1 d2 n)(*strict*)\n    apply (metis GR.derivation_initial_is_derivation GR.some_position_has_details_at_0)\n   apply(rename_tac a d)(*strict*)\n   apply (metis GL.derivation_initial_is_derivation GL.some_position_has_details_at_0)\n  apply(rename_tac a d x nat)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac a d nat)(*strict*)\n  apply(rename_tac x)\n  apply(rename_tac a d x)(*strict*)\n  apply(subgoal_tac \"\\<exists>e1 e2 c1 c2. d x = Some (pair e1 c1) \\<and> d (Suc x) = Some (pair (Some e2) c2) \\<and> step_relation1 G1 c1 e2 c2\")\n   apply(rename_tac a d x)(*strict*)\n   prefer 2\n   apply(rule_tac\n      m=\"Suc x\"\n      in GL.step_detail_before_some_position)\n     apply(rename_tac a d x)(*strict*)\n     apply(rule GL.derivation_initial_is_derivation)\n     apply(force)\n    apply(rename_tac a d x)(*strict*)\n    apply(simp add: maximum_of_domain_def)\n   apply(rename_tac a d x)(*strict*)\n   apply(force)\n  apply(rename_tac a d x)(*strict*)\n  apply(clarsimp)\n  apply(rename_tac a d x e1 e2 c1 c2)(*strict*)\n  apply(rename_tac e0 e1 c1 c1')\n  apply(rename_tac a d x e0 e1 c1 c1')(*strict*)\n  apply(subgoal_tac \"\\<exists>deri2 deri2n f. GR.derivation_initial G2 deri2 \\<and> maximum_of_domain deri2 deri2n \\<and> relation_initial_configuration G1 G2 (the(get_configuration(d 0))) (the(get_configuration(deri2 0))) \\<and> relation_configuration G1 G2 c1 (the(get_configuration(deri2 deri2n))) \\<and> simulating_derivation G1 G2 d x deri2 deri2n f\")\n   apply(rename_tac a d x e0 e1 c1 c1')(*strict*)\n   prefer 2\n   apply(rule ATS_Simulation_Configuration_Weak_simulation_derivation_exists_witness)\n     apply(rename_tac a d x e0 e1 c1 c1')(*strict*)\n     apply(force)\n    apply(rename_tac a d x e0 e1 c1 c1')(*strict*)\n    apply(force)\n   apply(rename_tac a d x e0 e1 c1 c1')(*strict*)\n   apply(force)\n  apply(rename_tac a d x e0 e1 c1 c1')(*strict*)\n  apply(clarsimp)\n  apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n xa)(*strict*)\n  apply(rename_tac f)\n  apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f)(*strict*)\n  apply(subgoal_tac \"\\<exists>e c. deri2 deri2n = Some (pair e c)\")\n   apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e c)(*strict*)\n   apply(rename_tac c2)\n   apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e c2)(*strict*)\n   apply(subgoal_tac \"\\<exists>d2 n. GR.derivation G2 d2 \\<and> GR.belongs G2 d2 \\<and> the(get_configuration(d2 0)) = c2 \\<and> relation_step_simulation G1 G2 c1 e1 c1' c2 d2 \\<and> maximum_of_domain d2 n \\<and> relation_configuration G1 G2 c1' (the(get_configuration(d2 n)))\")\n    apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e c2)(*strict*)\n    prefer 2\n    apply(rule AX_relation_step_simulation)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e c2)(*strict*)\n       apply(force)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e c2)(*strict*)\n      apply(simp add: get_configuration_def)\n     apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e c2)(*strict*)\n     apply (metis GL.belongs_step_labels GL.derivation_initial_belongs AX_TSstructure_relation_TSstructure1_belongs)\n    apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e c2)(*strict*)\n    apply(force)\n   apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e c2)(*strict*)\n   apply(clarsimp)\n   apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n)(*strict*)\n   apply(subgoal_tac \"\\<exists>c2. d2 0 = Some (pair None c2)\")\n    apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n)(*strict*)\n    apply(clarsimp)\n    apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n    apply(subgoal_tac \"left_total_on (relation_effect G1 G2) (marked_effect1 G1 (derivation_append (derivation_take d x) (der2 c1 e1 c1') x)) (marked_effect2 G2 (derivation_append deri2 d2 deri2n))\")\n     apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n     prefer 2\n     apply(rule AX_relation_step_simulation_preserves_marked_effect)\n     apply(rule_tac\n      f=\"\\<lambda>a. if a \\<le> x then f a else f x + n\"\n      in relation_step_simulation_preservation_PROVE)\n                    apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n                    prefer 14\n                    apply(force)\n                   apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n                   prefer 14\n                   apply(force)\n                  apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n                  apply(force)\n                 apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n                 apply(force)\n                apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n                apply (metis GL.belongs_step_labels GL.derivation_initial_belongs AX_TSstructure_relation_TSstructure1_belongs)\n               apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n               apply(force)\n              apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n              apply(simp add: get_configuration_def)\n             apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n             apply(force)\n            apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n            apply (metis GL.derivation_take_preserves_derivation_initial)\n           apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n           apply (metis GL.derivationNoFromNone GL.derivation_initial_is_derivation maximum_of_domain_derivation_take)\n          apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n          apply(force)\n         apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n         apply(force)\n        apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n        apply(simp add: get_configuration_def derivation_take_def)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n       apply(simp add: derivation_append_fit_def derivation_take_def der2_def)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n      apply(simp add: derivation_append_fit_def get_configuration_def)\n     apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n     apply(rule simulating_derivation_exist_step)\n                 apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n                 apply(force)+\n    apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n    apply(subgoal_tac \"left_total_on (relation_effect G1 G2) (marked_effect1 G1 d) (marked_effect2 G2 (derivation_append deri2 d2 deri2n))\")\n     apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n     prefer 2\n     apply(rule_tac\n      t=\"d\"\n      and s=\"(derivation_append (derivation_take d x) (der2 c1 e1 c1') x)\"\n      in ssubst)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n      apply(rule ext)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n      apply(simp add: derivation_append_def derivation_take_def der2_def)\n      apply(case_tac \"xa-x\")\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa nat)(*strict*)\n      apply(clarsimp)\n      apply(case_tac nat)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa nat)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n       apply(subgoal_tac \"Suc x=xa\")\n        apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n        prefer 2\n        apply(force)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n       apply(clarsimp)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa nat nata)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa nata)(*strict*)\n      apply(subgoal_tac \"xa=x+Suc(Suc nata)\")\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa nata)(*strict*)\n       prefer 2\n       apply(force)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa nata)(*strict*)\n      apply(clarsimp)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 nata)(*strict*)\n      apply(rule GL.none_position_after_max_dom)\n        apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 nata)(*strict*)\n        apply(rule GL.derivation_initial_is_derivation)\n        apply(force)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 nata)(*strict*)\n       apply(force)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 nata)(*strict*)\n      apply(force)\n     apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n     apply(force)\n    apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n    apply(thin_tac \"left_total_on (relation_effect G1 G2) (marked_effect1 G1 (derivation_append (derivation_take d x) (der2 c1 e1 c1') x)) (marked_effect2 G2 (derivation_append deri2 d2 deri2n))\")\n    apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n    apply(subgoal_tac \"marking_condition2 G2 (derivation_append deri2 d2 deri2n)\")\n     apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n     prefer 2\n     apply(rule AX_relation_step_simulation_preserves_marking_condition)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n      apply(rule_tac\n      ?d1.0=\"derivation_take d x\"\n      and ?d2.0=\"deri2\"\n      and ?n1.0=\"x\"\n      and ?n2.0=\"deri2n\"\n      and f=\"\\<lambda>a. if a \\<le> x then f a else f x + n\"\n      in relation_step_simulation_preservation_PROVE)\n                     apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n                     prefer 14\n                     apply(force)\n                    apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n                    prefer 14\n                    apply(force)\n                   apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n                   apply(force)\n                  apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n                  prefer 3\n                  apply(force)\n                 apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n                 prefer 2\n                 apply (metis GL.belongs_step_labels GL.derivation_initial_belongs AX_TSstructure_relation_TSstructure1_belongs)\n                apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n                apply(force)\n               apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n               apply(simp add: get_configuration_def)\n              apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n              apply(force)\n             apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n             apply (metis GL.derivation_take_preserves_derivation_initial)\n            apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n            apply (metis GL.derivationNoFromNone GL.derivation_initial_is_derivation maximum_of_domain_derivation_take)\n           apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n           apply(force)\n          apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n          apply(force)\n         apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n         apply(simp add: get_configuration_def derivation_take_def)\n        apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n        apply(simp add: derivation_append_fit_def derivation_take_def der2_def)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n       apply(simp add: derivation_append_fit_def get_configuration_def)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n      apply(rule_tac\n      t=\"derivation_append (derivation_take d x) (der2 c1 e1 c1') x\"\n      and s=\"d\"\n      in ssubst)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n       apply(rule ext)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n       apply(simp add: derivation_append_def derivation_take_def der2_def)\n       apply(case_tac \"xa-x\")\n        apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n        apply(clarsimp)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa nat)(*strict*)\n       apply(clarsimp)\n       apply(case_tac nat)\n        apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa nat)(*strict*)\n        apply(clarsimp)\n        apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n        apply(subgoal_tac \"Suc x=xa\")\n         apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n         prefer 2\n         apply(force)\n        apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n        apply(clarsimp)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa nat nata)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa nata)(*strict*)\n       apply(subgoal_tac \"xa=x+Suc(Suc nata)\")\n        apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa nata)(*strict*)\n        prefer 2\n        apply(force)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa nata)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 nata)(*strict*)\n       apply(rule sym)\n       apply(rule GL.none_position_after_max_dom)\n         apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 nata)(*strict*)\n         apply(rule GL.derivation_initial_is_derivation)\n         apply(force)\n        apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 nata)(*strict*)\n        apply(force)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 nata)(*strict*)\n       apply(force)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n      apply(rule_tac\n      t=\"d\"\n      and s=\"(derivation_append (derivation_take d x) (der2 c1 e1 c1') x)\"\n      in ssubst)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n       apply(rule ext)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n       apply(simp add: der2_def derivation_take_def derivation_append_def)\n       apply(rule conjI)\n        apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n        apply(clarsimp)\n        apply(subgoal_tac \"xa=Suc x\")\n         apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n         prefer 2\n         apply(force)\n        apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n        apply(clarsimp)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n       apply(clarsimp)\n       apply(subgoal_tac \"\\<exists>a. x+Suc a=xa\")\n        apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n        prefer 2\n        apply(rule_tac\n      x=\"xa-x-Suc 0\"\n      in exI)\n        apply(force)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 aa)(*strict*)\n       apply(case_tac aa)\n        apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 aa)(*strict*)\n        apply(force)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 aa nat)(*strict*)\n       apply(clarsimp)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 nat)(*strict*)\n       apply(case_tac \"d (Suc (Suc (x + nat)))\")\n        apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 nat)(*strict*)\n        apply(force)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 nat aa)(*strict*)\n       apply(rule_tac\n      m=\"(Suc (Suc (x + nat)))\"\n      and d=\"d\"\n      in GL.no_some_beyond_maximum_of_domain)\n          apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 nat aa)(*strict*)\n          apply(simp add: GL.derivation_initial_def)\n          apply(force)\n         apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 nat aa)(*strict*)\n         apply(force)\n        apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 nat aa)(*strict*)\n        apply(force)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 nat aa)(*strict*)\n       apply(force)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n      apply(rule simulating_derivation_exist_step)\n                  apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n                  apply(force)\n                 apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n                 apply(force)\n                apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n                apply(force)\n               apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n               apply(force)\n              apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n              apply(force)\n             apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n             apply(force)\n            apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n            apply(force)\n           apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n           apply(force)\n          apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n          apply(force)\n         apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n         apply(force)\n        apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n        apply(force)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n       apply(force)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n      apply(force)\n     apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n     apply(rule_tac\n      t=\"(derivation_append (derivation_take d x) (der2 c1 e1 c1') x)\"\n      and s=\"d\"\n      in ssubst)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n      prefer 2\n      apply(force)\n     apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n     apply(rule ext)\n     apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n     apply(simp add: derivation_take_def derivation_append_def der1_def der2_def)\n     apply(rule conjI)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n      apply(clarsimp)\n      apply(subgoal_tac \"xa=Suc x\")\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n       prefer 2\n       apply(force)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n      apply(clarsimp)\n     apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n     apply(clarsimp)\n     apply(rule sym)\n     apply(rule GL.none_position_after_max_dom)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n       apply(rule GL.derivation_initial_is_derivation)\n       apply(force)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n      apply(force)\n     apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 xa)(*strict*)\n     apply(force)\n    apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n    apply(simp add: left_total_on_def)\n    apply(erule_tac\n      x=\"a\"\n      in ballE)\n     apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n     apply(clarsimp)\n     apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 b)(*strict*)\n     apply(rule_tac\n      x=\"b\"\n      in bexI)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 b)(*strict*)\n      apply(force)\n     apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 b)(*strict*)\n     apply(simp add: GR.finite_marked_language_def)\n     apply(rule_tac\n      x=\"derivation_append deri2 d2 deri2n\"\n      in exI)\n     apply(clarsimp)\n     apply(rule context_conjI)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 b)(*strict*)\n      apply(rule GR.derivation_append_preserves_derivation_initial)\n        apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 b)(*strict*)\n        apply (metis AX_TSstructure_relation_TSstructure2_belongs)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 b)(*strict*)\n       apply(force)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 b)(*strict*)\n      apply(rule GR.derivation_append_preserves_derivation)\n        apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 b)(*strict*)\n        apply(rule GR.derivation_initial_is_derivation)\n        apply(force)\n       apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 b)(*strict*)\n       apply(force)\n      apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 b)(*strict*)\n      apply(clarsimp)\n      apply(simp add: get_configuration_def)\n     apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2 b)(*strict*)\n     apply(rule_tac\n      x=\"deri2n+n\"\n      in exI)\n     apply (metis concat_has_max_dom)\n    apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n c2)(*strict*)\n    apply(force)\n   apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f e d2 n)(*strict*)\n   apply (metis GR.some_position_has_details_at_0)\n  apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f)(*strict*)\n  apply(rule GR.some_position_has_details_before_max_dom)\n    apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f)(*strict*)\n    apply(rule GR.derivation_initial_is_derivation)\n    apply(force)\n   apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f)(*strict*)\n   apply(force)\n  apply(rename_tac a d x e0 e1 c1 c1' deri2 deri2n f)(*strict*)\n  apply(force)\n  done\n\nend\n\nend\n", "meta": {"author": "ControllerSynthesis", "repo": "Isabelle", "sha": "fc776edec292363e49785e5d3a752d9f9cfcf1c9", "save_path": "github-repos/isabelle/ControllerSynthesis-Isabelle", "path": "github-repos/isabelle/ControllerSynthesis-Isabelle/Isabelle-fc776edec292363e49785e5d3a752d9f9cfcf1c9/PRJ_06_06/L_ATS_Simulation_Configuration_WeakLR_Marked_Effect.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6150878555160665, "lm_q2_score": 0.41489884579676883, "lm_q1q2_score": 0.2551992413172257}}
{"text": "section\\<open>The Needham-Schroeder Public-Key Protocol against the General Attacker\\<close>\n\ntheory NS_Public_Bad_GA imports PublicGA begin\n\ninductive_set ns_public :: \"event list set\"\n  where\n\n   Nil:  \"[] \\<in> ns_public\"\n\n | Fake: \"\\<lbrakk>evsf \\<in> ns_public;  X \\<in> synth (analz (knows A evsf))\\<rbrakk>\n          \\<Longrightarrow> Says A B X  # evsf \\<in> ns_public\"\n\n | Reception: \"\\<lbrakk> evsr \\<in> ns_public; Says A B X \\<in> set evsr \\<rbrakk>\n                \\<Longrightarrow> Gets B X # evsr \\<in> ns_public\"\n\n | NS1:  \"\\<lbrakk>evs1 \\<in> ns_public;  Nonce NA \\<notin> used evs1\\<rbrakk>\n          \\<Longrightarrow> Says A B (Crypt (pubEK B) \\<lbrace>Nonce NA, Agent A\\<rbrace>)\n                # evs1  \\<in>  ns_public\"\n\n | NS2:  \"\\<lbrakk>evs2 \\<in> ns_public;  Nonce NB \\<notin> used evs2;\n           Gets B (Crypt (pubEK B) \\<lbrace>Nonce NA, Agent A\\<rbrace>) \\<in> set evs2\\<rbrakk>\n          \\<Longrightarrow> Says B A (Crypt (pubEK A) \\<lbrace>Nonce NA, Nonce NB\\<rbrace>)\n                # evs2  \\<in>  ns_public\"\n\n | NS3:  \"\\<lbrakk>evs3 \\<in> ns_public;\n           Says A  B (Crypt (pubEK B) \\<lbrace>Nonce NA, Agent A\\<rbrace>) \\<in> set evs3;\n           Gets A (Crypt (pubEK A) \\<lbrace>Nonce NA, Nonce NB\\<rbrace>) \\<in> set evs3\\<rbrakk>\n          \\<Longrightarrow> Says A B (Crypt (pubEK B) (Nonce NB)) # evs3 \\<in> ns_public\"\n\n\nlemma NS_no_Notes:\n \"evs \\<in> ns_public \\<Longrightarrow> Notes A X \\<notin> set evs\"\napply (erule ns_public.induct)\napply (simp_all)\ndone\n\ntext\\<open>Confidentiality treatment in separate theory file\\<close>\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Inductive_Confidentiality/GeneralAttacker/NS_Public_Bad_GA.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318479832804, "lm_q2_score": 0.42250463481418826, "lm_q1q2_score": 0.2551640048848337}}
{"text": "(*  Title:      Service_Matrix.thy\n    Authors:    Cornelius Diekmann, Max Haslbeck\n*)\n(*IPPartitioning.thy\n  Original Author: Max Haslbeck, 2015*)\nsection\\<open>Service Matrices\\<close>\ntheory Service_Matrix\nimports \"Common/List_Product_More\"\n        \"Common/IP_Partition_Preliminaries\"\n        \"Common/GroupF\"\n        \"Common/IP_Addr_WordInterval_toString\"\n        \"Primitives/Primitives_toString\"\n        \"SimpleFw_Semantics\"\n        \"../IP_Addresses/WordInterval_Sorted\"\nbegin\n\n\nsubsection\\<open>IP Address Space Partition\\<close>\n\n(* could be generalized more *)\nfun extract_IPSets_generic0\n  :: \"('i::len simple_match \\<Rightarrow> 'i word \\<times> nat) \\<Rightarrow> 'i simple_rule list \\<Rightarrow> ('i wordinterval) list\"\n  where\n  \"extract_IPSets_generic0 _ [] = []\" |\n  \"extract_IPSets_generic0 sel ((SimpleRule m _)#ss) = (ipcidr_tuple_to_wordinterval (sel m)) #\n                                                       (extract_IPSets_generic0 sel ss)\"\n\nlemma extract_IPSets_generic0_length: \"length (extract_IPSets_generic0 sel rs) = length rs\"\n  by(induction rs rule: extract_IPSets_generic0.induct) (simp_all)\n\n\n(*\nThe order in which extract_IPSets returns the collected IP ranges heavily influences the running time\nof the subsequent algorithms.\nFor example:\n1) iterating through the ruleset and collecting all source and destination ips:\n   10:10:49 elapsed time, 38:41:17 cpu time, factor 3.80\n2) iterating through the ruleset and first returning all source ips and iterating again and then return all destination ips:\n   3:39:56 elapsed time, 21:08:34 cpu time, factor 5.76\n\nTo get a more deterministic runtime, we are sorting the output. As a performance optimization, we also remove duplicate entries.\nWe use mergesort_remdups, which does a mergesort (i.e sorts!) and removes duplicates and mergesort_by_rel which does a mergesort\n(without removing duplicates) and allows to specify the relation we use to sort.\nIn theory, the largest ip ranges (smallest prefix length) should be put first, the following evaluation shows that this may not\nbe the fastest solution. The reason might be that access_matrix_pretty_ipv4 picks (almost randomly) one IP from the result and\nthere are fast and slower choices. The faster choices are the ones where the firewall ruleset has a decision very early. \nTherefore, the running time is still a bit unpredictable.\n\nHere is the data:\nmap ipcidr_tuple_to_wordinterval (mergesort_by_rel (\\<lambda> (a1,a2) (b1, b2). (a2, a1) \\<le> (b2, b1)) (mergesort_remdups\n                        ((map (src \\<circ> match_sel) rs) @ (map (dst \\<circ> match_sel) rs))))\n (2:47:04 elapsed time, 17:08:01 cpu time, factor 6.15)\n\n\nmap ipcidr_tuple_to_wordinterval (mergesort_remdups ((map (src \\<circ> match_sel) rs) @ (map (dst \\<circ> match_sel) rs)))\n (2:41:03 elapsed time, 16:56:46 cpu time, factor 6.31)\n\n\nmap ipcidr_tuple_to_wordinterval (mergesort_by_rel (\\<lambda> (a1,a2) (b1, b2). (a2, a1) \\<le> (b2, b1)) (\n                         ((map (src \\<circ> match_sel) rs) @ (map (dst \\<circ> match_sel) rs)))\n (5:52:28 elapsed time, 41:50:10 cpu time, factor 7.12)\n\n\nmap ipcidr_tuple_to_wordinterval (mergesort_by_rel (op \\<le>)\n                         ((map (src \\<circ> match_sel) rs) @ (map (dst \\<circ> match_sel) rs))))\n  (3:10:57 elapsed time, 19:12:25 cpu time, factor 6.03)\n\n\nmap ipcidr_tuple_to_wordinterval (mergesort_by_rel (\\<lambda> (a1,a2) (b1, b2). (a2, a1) \\<le> (b2, b1)) (mergesort_remdups\n                        (extract_src_dst_ips rs [])))\n (2:49:57 elapsed time, 17:10:49 cpu time, factor 6.06)\n\nmap ipcidr_tuple_to_wordinterval ((mergesort_remdups (extract_src_dst_ips rs [])))\n (2:43:44 elapsed time, 16:57:49 cpu time, factor 6.21)\n\nmap ipcidr_tuple_to_wordinterval (mergesort_by_rel (\\<lambda> (a1,a2) (b1, b2). (a2, a1) \\<ge> (b2, b1)) (mergesort_remdups (extract_src_dst_ips rs [])))\n (2:47:37 elapsed time, 16:54:47 cpu time, factor 6.05)\n\nThere is a clear looser: not using mergesort_remdups\nThere is no clear winner. We will just stick to mergesort_remdups.\n\n*)\n\n(*check the the order of mergesort_remdups did not change*)\nlemma \"mergesort_remdups [(1::ipv4addr, 2::nat), (8,0), (8,1), (2,2), (2,4), (1,2), (2,2)] =\n        [(1, 2), (2, 2), (2, 4), (8, 0), (8, 1)]\" by eval\n\n\n(*a tail-recursive implementation*)\nfun extract_src_dst_ips\n  :: \"'i::len simple_rule list \\<Rightarrow> ('i word \\<times> nat) list \\<Rightarrow> ('i word \\<times> nat) list\" where\n  \"extract_src_dst_ips [] ts = ts\" |\n  \"extract_src_dst_ips ((SimpleRule m _)#ss) ts = extract_src_dst_ips ss  (src m # dst m # ts)\"\n\nlemma extract_src_dst_ips_length: \"length (extract_src_dst_ips rs acc) = 2*length rs + length acc\"\nproof(induction rs arbitrary: acc)\ncase (Cons r rs) thus ?case by(cases r, simp)\nqed(simp)\n\ndefinition extract_IPSets\n  :: \"'i::len simple_rule list \\<Rightarrow> ('i wordinterval) list\" where\n  \"extract_IPSets rs \\<equiv> map ipcidr_tuple_to_wordinterval (mergesort_remdups (extract_src_dst_ips rs []))\"\nlemma extract_IPSets:\n  \"set (extract_IPSets rs) = set (extract_IPSets_generic0 src rs) \\<union> set (extract_IPSets_generic0 dst rs)\"\nproof -\n  { fix acc\n    have \"ipcidr_tuple_to_wordinterval ` set (extract_src_dst_ips rs acc) =\n            ipcidr_tuple_to_wordinterval ` set acc \\<union> set (extract_IPSets_generic0 src rs) \\<union>\n            set (extract_IPSets_generic0 dst rs)\"\n    proof(induction rs arbitrary: acc)\n    case (Cons r rs ) thus ?case\n      apply(cases r)\n      apply(simp)\n      by fast\n    qed(simp)\n  } thus ?thesis unfolding extract_IPSets_def by(simp_all add: extract_IPSets_def mergesort_remdups_correct)\nqed\n\nlemma \"(a::nat) div 2 + a mod 2 \\<le> a\" by fastforce\n\nlemma merge_length: \"length (merge l1 l2) \\<le> length l1 + length l2\"\nby(induction l1 l2 rule: merge.induct) auto\n\nlemma merge_list_length: \"length (merge_list as ls) \\<le> length (concat (as @ ls))\"\nproof(induction as ls rule: merge_list.induct)\ncase (5 l1 l2 acc2 ls)\n  have \"length (merge l2 acc2) \\<le> length l2 + length acc2\" using merge_length by blast\n  with 5 show ?case by simp\nqed(simp_all)\n\nlemma mergesort_remdups_length: \"length (mergesort_remdups as) \\<le> length as\"\nunfolding mergesort_remdups_def\nproof -\n  have \"concat ([] @ (map (\\<lambda>x. [x]) as)) = as\" by simp\n  with merge_list_length show \"length (merge_list [] (map (\\<lambda>x. [x]) as)) \\<le> length as\" by metis\nqed\n\nlemma extract_IPSets_length: \"length (extract_IPSets rs) \\<le> 2 * length rs\"\napply(simp add: extract_IPSets_def)\nusing extract_src_dst_ips_length mergesort_remdups_length by (metis add.right_neutral list.size(3)) \n\n\n(*\nexport_code extract_IPSets in SML\nwhy you no work?\n*)\n\n\nlemma extract_equi0:\n  \"set (map wordinterval_to_set (extract_IPSets_generic0 sel rs)) =\n    (\\<lambda>(base,len). ipset_from_cidr base len) ` sel ` match_sel ` set rs\"\n  proof(induction rs)\n  case (Cons r rs) thus ?case\n    apply(cases r, simp)\n    using wordinterval_to_set_ipcidr_tuple_to_wordinterval by fastforce\n  qed(simp)\n\nlemma src_ipPart_motivation:\nfixes   rs\ndefines \"X \\<equiv> (\\<lambda>(base,len). ipset_from_cidr base len) ` src ` match_sel ` set rs\"\nassumes \"\\<forall>A \\<in> X. B \\<subseteq> A \\<or> B \\<inter> A = {}\" and \"s1 \\<in> B\" and \"s2 \\<in> B\"\nshows \"simple_fw rs (p\\<lparr>p_src:=s1\\<rparr>) = simple_fw rs (p\\<lparr>p_src:=s2\\<rparr>)\"\nproof -\n  have \"\\<forall>A \\<in> (\\<lambda>(base,len). ipset_from_cidr base len) ` src ` match_sel ` set rs. B \\<subseteq> A \\<or> B \\<inter> A = {} \\<Longrightarrow> ?thesis\"\n  proof(induction rs)\n    case Nil thus ?case by simp\n  next\n    case (Cons r rs)\n    { fix m\n      from \\<open>s1 \\<in> B\\<close> \\<open>s2 \\<in> B\\<close> have \n        \"B \\<subseteq> (case src m of (x, xa) \\<Rightarrow> ipset_from_cidr x xa) \\<or> B \\<inter> (case src m of (x, xa) \n                      \\<Rightarrow> ipset_from_cidr x xa) = {} \\<Longrightarrow>\n             simple_matches m (p\\<lparr>p_src := s1\\<rparr>) \\<longleftrightarrow> simple_matches m (p\\<lparr>p_src := s2\\<rparr>)\"\n      apply(cases m)\n      apply(rename_tac iiface oiface srca dst proto sports dports)\n      apply(case_tac srca)\n      apply(simp add: simple_matches.simps)\n      by blast\n    } note helper=this\n    from Cons[simplified] show ?case\n     apply(cases r, rename_tac m a)\n     apply(simp)\n     apply(case_tac a)\n      using helper apply force+\n     done\n  qed\n  with assms show ?thesis by blast\nqed\n\n    \nlemma src_ipPart:\n  assumes \"ipPartition (set (map wordinterval_to_set (extract_IPSets_generic0 src rs))) A\"\n          \"B \\<in> A\" \"s1 \\<in> B\" \"s2 \\<in> B\"\n  shows \"simple_fw rs (p\\<lparr>p_src:=s1\\<rparr>) = simple_fw rs (p\\<lparr>p_src:=s2\\<rparr>)\"\nproof -\n  from src_ipPart_motivation[OF _ assms(3) assms(4)]\n  have \"\\<forall>A \\<in> (\\<lambda>(base,len). ipset_from_cidr base len) ` src ` match_sel ` set rs. B \\<subseteq> A \\<or> B \\<inter> A = {} \\<Longrightarrow>\n      simple_fw rs (p\\<lparr>p_src:=s1\\<rparr>) = simple_fw rs (p\\<lparr>p_src:=s2\\<rparr>)\" by fast\n  thus ?thesis using assms(1) assms(2)\n    unfolding ipPartition_def\n    by (metis (full_types) Int_commute extract_equi0)\nqed\n  \n(*basically a copy of src_ipPart*)\nlemma dst_ipPart:\n  assumes \"ipPartition (set (map wordinterval_to_set (extract_IPSets_generic0 dst rs))) A\"\n          \"B \\<in> A\" \"s1 \\<in> B\" \"s2 \\<in> B\"\n  shows \"simple_fw rs (p\\<lparr>p_dst:=s1\\<rparr>) = simple_fw rs (p\\<lparr>p_dst:=s2\\<rparr>)\"\nproof -\n  have \"\\<forall>A \\<in> (\\<lambda>(base,len). ipset_from_cidr base len) ` dst ` match_sel ` set rs. B \\<subseteq> A \\<or> B \\<inter> A = {} \\<Longrightarrow>\n      simple_fw rs (p\\<lparr>p_dst:=s1\\<rparr>) = simple_fw rs (p\\<lparr>p_dst:=s2\\<rparr>)\"\n  proof(induction rs)\n    case Nil thus ?case by simp\n  next\n    case (Cons r rs)\n    { fix m\n      from \\<open>s1 \\<in> B\\<close> \\<open>s2 \\<in> B\\<close> have\n        \"B \\<subseteq> (case dst m of (x, xa) \\<Rightarrow> ipset_from_cidr x xa) \\<or> B \\<inter> (case dst m of (x, xa) \n                  \\<Rightarrow> ipset_from_cidr x xa) = {} \\<Longrightarrow>\n         simple_matches m (p\\<lparr>p_dst := s1\\<rparr>) \\<longleftrightarrow> simple_matches m (p\\<lparr>p_dst := s2\\<rparr>)\"\n          apply(cases m)\n          apply(rename_tac iiface oiface src dsta proto sports dports)\n          apply(case_tac dsta)\n          apply(simp add: simple_matches.simps)\n          by blast\n    } note helper=this\n    from Cons show ?case\n     apply(simp)\n     apply(case_tac r, rename_tac m a)\n     apply(simp)\n     apply(case_tac a)\n      using helper apply force+\n     done\n  qed\n  thus ?thesis using assms(1) assms(2)\n    unfolding ipPartition_def\n    by (metis (full_types) Int_commute extract_equi0)\nqed\n\n\n\n(* OPTIMIZED PARTITIONING *)\n\ndefinition wordinterval_list_to_set :: \"'a::len wordinterval list \\<Rightarrow> 'a::len word set\" where\n  \"wordinterval_list_to_set ws = \\<Union> set (map wordinterval_to_set ws)\"\n\nlemma wordinterval_list_to_set_compressed:\n  \"wordinterval_to_set (wordinterval_compress (foldr wordinterval_union xs Empty_WordInterval)) =\n          wordinterval_list_to_set xs\"\n  proof(induction xs)\n  qed(simp_all add: wordinterval_compress wordinterval_list_to_set_def)\n\nfun partIps :: \"'a::len wordinterval \\<Rightarrow> 'a::len wordinterval list \n                \\<Rightarrow> 'a::len wordinterval list\" where\n  \"partIps _ [] = []\" |\n  \"partIps s (t#ts) = (if wordinterval_empty s then (t#ts) else\n                        (if wordinterval_empty (wordinterval_intersection s t)\n                          then (t#(partIps s ts))\n                          else\n                            (if wordinterval_empty (wordinterval_setminus t s)\n                              then (t#(partIps (wordinterval_setminus s t) ts))\n                              else (wordinterval_intersection t s)#((wordinterval_setminus t s)#\n                                   (partIps (wordinterval_setminus s t) ts)))))\"\n\n\nlemma \"partIps (WordInterval (1::ipv4addr) 1) [WordInterval 0 1] = [WordInterval 1 1, WordInterval 0 0]\" by eval\n\nlemma partIps_length: \"length (partIps s ts) \\<le> (length ts) * 2\"\nproof(induction ts arbitrary: s)\ncase Cons thus ?case \n  apply(simp)\n  using le_Suc_eq by blast\nqed(simp)\n\nfun partitioningIps :: \"'a::len wordinterval list \\<Rightarrow> 'a::len wordinterval list \\<Rightarrow>\n                        'a::len wordinterval list\" where\n  \"partitioningIps [] ts = ts\" |\n  \"partitioningIps (s#ss) ts = partIps s (partitioningIps ss ts)\"\n\n\nlemma partitioningIps_length: \"length (partitioningIps ss ts) \\<le> (2^length ss) * length ts\"\nproof(induction ss)\ncase Nil thus ?case by simp\nnext\ncase (Cons s ss)\n  have \"length (partIps s (partitioningIps ss ts)) \\<le> length (partitioningIps ss ts) * 2\"\n    using partIps_length by fast\n  with Cons show  ?case by force\nqed\n\nlemma partIps_equi: \"map wordinterval_to_set (partIps s ts) = \n    partList4 (wordinterval_to_set s) (map wordinterval_to_set ts)\"\n  proof(induction ts arbitrary: s)\n  qed(simp_all)\n\nlemma partitioningIps_equi: \"map wordinterval_to_set (partitioningIps ss ts)\n       = (partitioning1 (map wordinterval_to_set ss) (map wordinterval_to_set ts))\"\n  apply(induction ss arbitrary: ts)\n   apply(simp; fail)\n  apply(simp add: partIps_equi)\n  done\n\n           \ndefinition getParts :: \"'i::len simple_rule list \\<Rightarrow> 'i wordinterval list\" where\n   \"getParts rs = partitioningIps (extract_IPSets rs) [wordinterval_UNIV]\"\n\nlemma partitioningIps_foldr: \"partitioningIps ss ts = foldr partIps ss ts\"\n  by(induction ss) (simp_all)\n\nlemma getParts_foldr: \"getParts rs = foldr partIps (extract_IPSets rs) [wordinterval_UNIV]\"\n  by(simp add: getParts_def partitioningIps_foldr)\n\nlemma getParts_length: \"length (getParts rs) \\<le> 2^(2 * length rs)\"\nproof -\n  from partitioningIps_length[where ss=\"extract_IPSets rs\" and ts=\"[wordinterval_UNIV]\"] have\n    1: \"length (partitioningIps (extract_IPSets rs) [wordinterval_UNIV]) \\<le> 2 ^ length (extract_IPSets rs)\" by simp\n  from extract_IPSets_length have \"(2::nat) ^ length (extract_IPSets rs) \\<le> 2 ^ (2 * length rs)\" by simp\n  with 1 have \"length (partitioningIps (extract_IPSets rs) [wordinterval_UNIV]) \\<le> 2 ^ (2 * length rs)\" by linarith\n  thus ?thesis by(simp add: getParts_def) \nqed\n\nlemma getParts_ipPartition: \"ipPartition (set (map wordinterval_to_set (extract_IPSets rs)))\n                                         (set (map wordinterval_to_set (getParts rs)))\"\nproof -\n  have hlp_rule: \"{} \\<notin> set (map wordinterval_to_set ts) \\<Longrightarrow> disjoint_list (map wordinterval_to_set ts) \\<Longrightarrow> \n     (wordinterval_list_to_set ss) \\<subseteq> (wordinterval_list_to_set ts) \\<Longrightarrow> \n     ipPartition (set (map wordinterval_to_set ss)) \n                 (set (map wordinterval_to_set (partitioningIps ss ts)))\" for ts ss::\"'a wordinterval list\"\n  by (metis ipPartitioning_helper_opt partitioningIps_equi wordinterval_list_to_set_def)\n  have \"disjoint_list [UNIV]\" by(simp add: disjoint_list_def disjoint_def)\n  have \"ipPartition (set (map wordinterval_to_set ss)) \n                   (set (map wordinterval_to_set (partitioningIps ss [wordinterval_UNIV])))\"\n     for ss::\"'a wordinterval list\"\n  apply(rule hlp_rule)\n    apply(simp_all add: wordinterval_list_to_set_def \\<open>disjoint_list [UNIV]\\<close>)\n  done\n  thus ?thesis\n  unfolding getParts_def by blast\nqed\n\n\nlemma getParts_complete: \"wordinterval_list_to_set (getParts rs) = UNIV\"\n  proof -\n  have \"{} \\<notin> set (map wordinterval_to_set ts) \\<Longrightarrow>\n     (wordinterval_list_to_set ss) \\<subseteq> (wordinterval_list_to_set ts) \\<Longrightarrow> \n     wordinterval_list_to_set (partitioningIps ss ts) = (wordinterval_list_to_set ts)\"\n     for ss ts::\"'a wordinterval list\"\n    using complete_helper by (metis partitioningIps_equi wordinterval_list_to_set_def)\n  hence \"wordinterval_list_to_set (getParts rs) = wordinterval_list_to_set [wordinterval_UNIV]\"\n    unfolding getParts_def by(simp add: wordinterval_list_to_set_def)\n  also have \"\\<dots> = UNIV\" by (simp add: wordinterval_list_to_set_def)\n  finally show ?thesis .\nqed\n\ntheorem getParts_samefw: \n  assumes \"A \\<in> set (map wordinterval_to_set (getParts rs))\" \"s1 \\<in> A\" \"s2 \\<in> A\" \n  shows \"simple_fw rs (p\\<lparr>p_src:=s1\\<rparr>) = simple_fw rs (p\\<lparr>p_src:=s2\\<rparr>) \\<and>\n         simple_fw rs (p\\<lparr>p_dst:=s1\\<rparr>) = simple_fw rs (p\\<lparr>p_dst:=s2\\<rparr>)\"\nproof -\n  let ?X=\"(set (map wordinterval_to_set (getParts rs)))\"\n  from getParts_ipPartition have \"ipPartition (set (map wordinterval_to_set (extract_IPSets rs))) ?X\" .\n  hence \"ipPartition (set (map wordinterval_to_set (extract_IPSets_generic0 src rs))) ?X \\<and>\n         ipPartition (set (map wordinterval_to_set (extract_IPSets_generic0 dst rs))) ?X\"\n    by(simp add: extract_IPSets ipPartitionUnion image_Un)\n  thus ?thesis using assms dst_ipPart src_ipPart by blast\nqed\n\n\nlemma partIps_nonempty: \"ts \\<noteq> [] \\<Longrightarrow> partIps s ts \\<noteq> []\"\n  by(induction ts arbitrary: s) simp_all\nlemma partitioningIps_nonempty: \"ts \\<noteq> [] \\<Longrightarrow> partitioningIps ss ts \\<noteq> []\"\nproof(induction ss arbitrary: ts)\n  case Nil thus ?case by simp\n  next\n  case (Cons s ss) thus ?case\n    apply(cases ts)\n     apply(simp; fail)\n    apply(simp)\n    using partIps_nonempty by blast\nqed\n\n(*\nlemma partIps_nonempty: \"\\<forall>t \\<in> set ts. \\<not> wordinterval_empty t \n       \\<Longrightarrow> {} \\<notin> set (map wordinterval_to_set (partIps s ts))\"\n  apply(induction ts arbitrary: s)\n   apply(simp; fail)\n  apply(simp)\n  by blast\n*)\n\nlemma getParts_nonempty: \"getParts rs \\<noteq> []\" by(simp add: getParts_def partitioningIps_nonempty)\nlemma getParts_nonempty_elems: \"\\<forall>w\\<in>set (getParts rs). \\<not> wordinterval_empty w\"\n  unfolding getParts_def\n  proof -\n    have partitioning_nonempty: \"\\<forall>t \\<in> set ts. \\<not> wordinterval_empty t \\<Longrightarrow>\n      {} \\<notin> set (map wordinterval_to_set (partitioningIps ss ts))\"\n      for ts ss::\"'a wordinterval list\"\n      proof(induction ss arbitrary: ts)\n        case Nil thus ?case by auto\n        case Cons thus ?case by (simp add: partIps_equi partList4_empty)\n      qed\n    have \"\\<forall>t \\<in> set [wordinterval_UNIV].\\<not> wordinterval_empty t\" by(simp)\n    with partitioning_nonempty have\n      \"{} \\<notin> set (map wordinterval_to_set (partitioningIps (extract_IPSets rs) [wordinterval_UNIV]))\" \n      by blast\n    thus \"\\<forall>w\\<in>set (partitioningIps (extract_IPSets rs) [wordinterval_UNIV]). \\<not> wordinterval_empty w\" by auto\n  qed\n\n(* HELPER FUNCTIONS UNIFICATION *)\n\nfun getOneIp :: \"'a::len wordinterval \\<Rightarrow> 'a::len word\" where\n  \"getOneIp (WordInterval b _) = b\" |\n  \"getOneIp (RangeUnion r1 r2) = (if wordinterval_empty r1 then getOneIp r2\n                                                           else getOneIp r1)\"\n\nlemma getOneIp_elem: \"\\<not> wordinterval_empty W \\<Longrightarrow> wordinterval_element (getOneIp W) W\"\n  by (induction W) simp_all\n\nrecord parts_connection = pc_iiface :: string\n                          pc_oiface :: string\n                          pc_proto :: primitive_protocol\n                          pc_sport :: \"16 word\"\n                          pc_dport :: \"16 word\"\n\n\n\n(* SAME FW DEFINITIONS AND PROOFS *)\n\n\n\ndefinition same_fw_behaviour :: \"(*'pkt_ext itself \\<Rightarrow>*) 'i::len word \\<Rightarrow> 'i word \\<Rightarrow> 'i simple_rule list \\<Rightarrow> bool\" where\n  \"same_fw_behaviour (*TYPE('pkt_ext)*) a b rs \\<equiv>\n      \\<forall>(p:: 'i::len simple_packet).\n                simple_fw rs (p\\<lparr>p_src:=a\\<rparr>) = simple_fw rs (p\\<lparr>p_src:=b\\<rparr>) \\<and>\n                simple_fw rs (p\\<lparr>p_dst:=a\\<rparr>) = simple_fw rs (p\\<lparr>p_dst:=b\\<rparr>)\"\n\nlemma getParts_same_fw_behaviour:\n  \"A \\<in> set (map wordinterval_to_set (getParts rs)) \\<Longrightarrow>  s1 \\<in> A \\<Longrightarrow> s2 \\<in> A \\<Longrightarrow> \n   same_fw_behaviour s1 s2 rs\"\n  unfolding same_fw_behaviour_def\n  using getParts_samefw by blast\n\ndefinition \"runFw s d c rs = simple_fw rs \\<lparr>p_iiface=pc_iiface c,p_oiface=pc_oiface c,\n                          p_src=s,p_dst=d,\n                          p_proto=pc_proto c,\n                          p_sport=pc_sport c,p_dport=pc_dport c,\n                          p_tcp_flags={TCP_SYN},\n                          p_payload=''''\\<rparr>\"\n\ntext{*We use @{const runFw} for executable code, but in general, everything applies to generic packets*}\ndefinition runFw_scheme :: \"'i::len word \\<Rightarrow> 'i word \\<Rightarrow> 'b parts_connection_scheme \\<Rightarrow>\n                              ('i, 'a) simple_packet_scheme \\<Rightarrow> 'i simple_rule list \\<Rightarrow> state\"\n  where\n\"runFw_scheme s d c p rs = simple_fw rs\n                        (p\\<lparr>p_iiface:=pc_iiface c,\n                          p_oiface:=pc_oiface c,\n                          p_src:=s,\n                          p_dst:=d,\n                          p_proto:=pc_proto c,\n                          p_sport:=pc_sport c,\n                          p_dport:=pc_dport c\\<rparr>)\"\n\nlemma runFw_scheme: \"runFw s d c rs = runFw_scheme s d c p rs\"\n  apply(simp add: runFw_def runFw_scheme_def)\n  apply(case_tac p)\n  apply(simp)\n  apply(thin_tac _, simp)\nproof(induction rs)\n  case Nil thus ?case by(simp; fail)\nnext\n  case(Cons r rs)\n  obtain m a where r: \"r = SimpleRule m a\" by(cases r) simp\n  from simple_matches_extended_packet[symmetric, of _ \"pc_iiface c\" \"pc_oiface c\"\n                                      s d \"pc_proto c\" \"pc_sport c\" \"pc_dport c\" _ _ _ \"{TCP_SYN}\" \"[]\"]\n  have pext: \"simple_matches m\n   \\<lparr>p_iiface = pc_iiface c, p_oiface = pc_oiface c, p_src = s, p_dst = d, p_proto = pc_proto c, p_sport = pc_sport c, p_dport = pc_dport c,\n      p_tcp_flags = tcp_flags2, p_payload = payload2, \\<dots> = aux\\<rparr> =\n  simple_matches m\n   \\<lparr>p_iiface = pc_iiface c, p_oiface = pc_oiface c, p_src = s, p_dst = d, p_proto = pc_proto c, p_sport = pc_sport c, p_dport = pc_dport c,\n      p_tcp_flags = {TCP_SYN}, p_payload = []\\<rparr>\" for tcp_flags2 payload2 and aux::'c by fast\n  show ?case\n   apply(simp add: r, cases a, simp)\n    using Cons.IH by(simp add: pext)+\nqed \n\n\nlemma has_default_policy_runFw: \"has_default_policy rs \\<Longrightarrow> runFw s d c rs = Decision FinalAllow \\<or> runFw s d c rs = Decision FinalDeny\"\n  by(simp add: runFw_def has_default_policy)\n\ndefinition same_fw_behaviour_one :: \"'i::len word \\<Rightarrow> 'i word \\<Rightarrow> 'a parts_connection_scheme \\<Rightarrow> 'i simple_rule list \\<Rightarrow> bool\" where\n  \"same_fw_behaviour_one ip1 ip2 c rs \\<equiv>\n            \\<forall>d s. runFw ip1 d c rs = runFw ip2 d c rs \\<and> runFw s ip1 c rs = runFw s ip2 c rs\"\n\n\n\ntext\\<open>Is an equivalence relation\\<close>\nlemma same_fw_behaviour_one_equi:\n  \"same_fw_behaviour_one x x c rs\"\n  \"same_fw_behaviour_one x y c rs = same_fw_behaviour_one y x c rs\"\n  \"same_fw_behaviour_one x y c rs \\<and> same_fw_behaviour_one y z c rs \\<Longrightarrow> same_fw_behaviour_one x z c rs\"\n  unfolding same_fw_behaviour_one_def by metis+\n\nlemma same_fw_behaviour_equi:\n  \"same_fw_behaviour x x rs\"\n  \"same_fw_behaviour x y rs = same_fw_behaviour y x rs\"\n  \"same_fw_behaviour x y rs \\<and> same_fw_behaviour y z rs \\<Longrightarrow> same_fw_behaviour x z rs\"\n  unfolding same_fw_behaviour_def by auto\n\nlemma runFw_sameFw_behave: \n       fixes W :: \"'i::len word set set\"\n       shows\n       \"\\<forall>A \\<in> W. \\<forall>a1 \\<in> A. \\<forall>a2 \\<in> A. same_fw_behaviour_one a1 a2 c rs \\<Longrightarrow> \\<Union> W = UNIV \\<Longrightarrow>\n       \\<forall>B \\<in> W. \\<exists>b \\<in> B. runFw ip1 b c rs = runFw ip2 b c rs \\<Longrightarrow>\n       \\<forall>B \\<in> W. \\<exists>b \\<in> B. runFw b ip1 c rs = runFw b ip2 c rs \\<Longrightarrow>\n       same_fw_behaviour_one ip1 ip2 c rs\"\nproof -\n  assume a1: \"\\<forall>A \\<in> W. \\<forall>a1 \\<in> A. \\<forall>a2 \\<in> A. same_fw_behaviour_one a1 a2 c rs\"\n   and a2: \"\\<Union> W = UNIV \"\n   and a3: \"\\<forall>B \\<in> W. \\<exists>b \\<in> B. runFw ip1 b c rs = runFw ip2 b c rs\"\n   and a4: \"\\<forall>B \\<in> W. \\<exists>b \\<in> B. runFw b ip1 c rs = runFw b ip2 c rs\"\n\n   \n  have relation_lem: \"\\<forall>D \\<in> W. \\<forall>d1 \\<in> D. \\<forall>d2 \\<in> D. \\<forall>s. f s d1 = f s d2 \\<Longrightarrow> \\<Union> W = UNIV \\<Longrightarrow>\n                     \\<forall>B \\<in> W. \\<exists>b \\<in> B. f s1 b = f s2 b \\<Longrightarrow>\n                     f s1 d = f s2 d\" for W and f::\"'c \\<Rightarrow> 'b \\<Rightarrow> 'd\" and s1 d s2\n    by (metis UNIV_I Union_iff)\n\n  from a1 have a1':\"\\<forall>A\\<in>W. \\<forall>a1\\<in>A. \\<forall>a2\\<in>A. \\<forall>s. runFw s a1 c rs = runFw s a2 c rs\"\n    unfolding same_fw_behaviour_one_def by fast\n  from relation_lem[OF a1' a2 a3] have s1: \"\\<And> d. runFw ip1 d c rs = runFw ip2 d c rs\" by simp\n\n  from a1 have a1'':\"\\<forall>A\\<in>W. \\<forall>a1\\<in>A. \\<forall>a2\\<in>A. \\<forall>d. runFw a1 d c rs = runFw a2 d c rs\"\n    unfolding same_fw_behaviour_one_def by fast\n  from relation_lem[OF a1'' a2 a4] have s2: \"\\<And> s. runFw s ip1 c rs = runFw s ip2 c rs\" by simp\n  from s1 s2 show \"same_fw_behaviour_one ip1 ip2 c rs\"\n    unfolding same_fw_behaviour_one_def by fast\nqed\n\nlemma sameFw_behave_sets:\n  \"\\<forall>w\\<in>set A. \\<forall>a1 \\<in> w. \\<forall>a2 \\<in> w. same_fw_behaviour_one a1 a2 c rs \\<Longrightarrow>\n   \\<forall>w1\\<in>set A. \\<forall>w2\\<in>set A. \\<exists>a1\\<in>w1. \\<exists>a2\\<in>w2. same_fw_behaviour_one a1 a2 c rs \\<Longrightarrow>\n   \\<forall>w1\\<in>set A. \\<forall>w2\\<in>set A.\n     \\<forall>a1\\<in>w1. \\<forall>a2\\<in>w2. same_fw_behaviour_one a1 a2 c rs\"\nproof -\n  assume a1: \"\\<forall>w\\<in>set A. \\<forall>a1 \\<in> w. \\<forall>a2 \\<in> w. same_fw_behaviour_one a1 a2 c rs\" and\n         \"\\<forall>w1\\<in>set A. \\<forall>w2\\<in>set A. \\<exists>a1\\<in>w1. \\<exists>a2\\<in>w2.  same_fw_behaviour_one a1 a2 c rs\"\n  from this have \"\\<forall>w1\\<in>set A. \\<forall>w2\\<in>set A. \\<exists>a1\\<in>w1. \\<forall>a2\\<in>w2.  same_fw_behaviour_one a1 a2 c rs\"\n    using same_fw_behaviour_one_equi(3) by metis\n  from a1 this show \"\\<forall>w1\\<in>set A. \\<forall>w2\\<in>set A. \\<forall>a1\\<in>w1. \\<forall>a2\\<in>w2. same_fw_behaviour_one a1 a2 c rs\"\n    using same_fw_behaviour_one_equi(3) by metis\nqed\n  \n\n\n\ndefinition groupWIs :: \"parts_connection \\<Rightarrow> 'i::len simple_rule list \\<Rightarrow> 'i wordinterval list list\" where\n  \"groupWIs c rs = (let W = getParts rs in \n                       (let f = (\\<lambda>wi. (map (\\<lambda>d. runFw (getOneIp wi) d c rs) (map getOneIp W),\n                                      map (\\<lambda>s. runFw s (getOneIp wi) c rs) (map getOneIp W))) in\n                       groupF f W))\"\n\n\n\nlemma groupWIs_not_empty: \"groupWIs c rs \\<noteq> []\"\n  proof -\n    have \"getParts rs \\<noteq> []\" by(simp add: getParts_def partitioningIps_nonempty)\n    with groupF_empty have \"\\<And>f. groupF f (getParts rs) \\<noteq> []\" by blast\n    thus ?thesis by(simp add: groupWIs_def Let_def) blast\n  qed\nlemma groupWIs_not_empty_elem: \"V \\<in> set (groupWIs c rs) \\<Longrightarrow> V \\<noteq> []\"\n  by(simp add: groupWIs_def Let_def groupF_empty_elem)\nlemma groupWIs_not_empty_elems: \n  assumes V: \"V \\<in> set (groupWIs c rs)\" and w: \"w \\<in> set V\"\n  shows \"\\<not> wordinterval_empty w\"\n  proof -\n    have \"\\<forall>w\\<in>set (concat (groupWIs c rs)). \\<not> wordinterval_empty w\"\n      apply(subst groupWIs_def)\n      apply(subst Let_def)+\n      apply(subst groupF_concat_set)\n      using getParts_nonempty_elems by blast\n    from this V w show ?thesis by auto\n  qed\n\nlemma groupParts_same_fw_wi0:\n    assumes \"V \\<in> set (groupWIs c rs)\"\n    shows \"\\<forall>w \\<in> set (map wordinterval_to_set V). \\<forall>a1 \\<in> w. \\<forall>a2 \\<in> w. same_fw_behaviour_one a1 a2 c rs\"\nproof -\n  have \"\\<forall>A\\<in>set (map wordinterval_to_set (concat (groupWIs c rs))). \n        \\<forall>a1\\<in>A. \\<forall>a2\\<in>A. same_fw_behaviour_one a1 a2 c rs\"\n    apply(subst groupWIs_def)\n    apply(subst Let_def)+\n    apply(subst set_map)\n    apply(subst groupF_concat_set)\n    using getParts_same_fw_behaviour same_fw_spec by fastforce\n  from this assms show ?thesis by force\nqed\n\nlemma groupWIs_same_fw_not: \"A \\<in> set (groupWIs c rs) \\<Longrightarrow> B \\<in> set (groupWIs c rs) \\<Longrightarrow> \n                            A \\<noteq> B \\<Longrightarrow>\n                             \\<forall>aw \\<in> set (map wordinterval_to_set A).\n                             \\<forall>bw \\<in> set (map wordinterval_to_set B).\n                             \\<forall>a \\<in> aw. \\<forall>b \\<in> bw. \\<not> same_fw_behaviour_one a b c rs\"\nproof -\n  assume asm: \"A \\<in> set (groupWIs c rs)\" \"B \\<in> set (groupWIs c rs)\" \"A \\<noteq> B\"\n  from this have b1: \"\\<forall>aw \\<in> set A. \\<forall>bw \\<in> set B.\n                  (map (\\<lambda>d. runFw (getOneIp aw) d c rs) (map getOneIp (getParts rs)),\n                   map (\\<lambda>s. runFw s (getOneIp aw) c rs) (map getOneIp (getParts rs))) \\<noteq>\n                  (map (\\<lambda>d. runFw (getOneIp bw) d c rs) (map getOneIp (getParts rs)),\n                   map (\\<lambda>s. runFw s (getOneIp bw) c rs) (map getOneIp (getParts rs)))\"\n    apply(simp add: groupWIs_def Let_def)\n    using groupF_nequality by fastforce\n  have same_behave_runFw_not:\n        \"(map (\\<lambda>d. runFw x1 d c rs) W, map (\\<lambda>s. runFw s x1 c rs) W) \\<noteq>\n         (map (\\<lambda>d. runFw x2 d c rs) W, map (\\<lambda>s. runFw s x2 c rs) W) \\<Longrightarrow>\n         \\<not> same_fw_behaviour_one x1 x2 c rs\" for x1 x2 W\n  by (simp add: same_fw_behaviour_one_def) (blast)\n  have \"\\<forall>C \\<in> set (groupWIs c rs). \\<forall>c \\<in> set C. getOneIp c \\<in> wordinterval_to_set c\"\n    apply(simp add: groupWIs_def Let_def)\n    using getParts_nonempty_elems groupF_set getOneIp_elem by fastforce\n  from this b1 asm have\n  \"\\<forall>aw \\<in> set (map wordinterval_to_set A). \\<forall>bw \\<in> set (map wordinterval_to_set B).\n   \\<exists>a \\<in> aw. \\<exists>b \\<in> bw. (map (\\<lambda>d. runFw a d c rs) (map getOneIp (getParts rs)), map (\\<lambda>s. runFw s a c rs) (map getOneIp (getParts rs))) \\<noteq>\n    (map (\\<lambda>d. runFw b d c rs) (map getOneIp (getParts rs)), map (\\<lambda>s. runFw s b c rs) (map getOneIp (getParts rs)))\"\n   by (simp) (blast)\n  from this same_behave_runFw_not asm\n  have \" \\<forall>aw \\<in> set (map wordinterval_to_set A). \\<forall>bw \\<in> set (map wordinterval_to_set B).\n         \\<exists>a \\<in> aw. \\<exists>b \\<in> bw. \\<not> same_fw_behaviour_one a b c rs\" by fast\n  from this groupParts_same_fw_wi0[of A c rs]  groupParts_same_fw_wi0[of B c rs] asm\n  have \"\\<forall>aw \\<in> set (map wordinterval_to_set A).\n        \\<forall>bw \\<in> set (map wordinterval_to_set B).\n        \\<forall>a \\<in> aw. \\<exists>b \\<in> bw. \\<not> same_fw_behaviour_one a b c rs\"\n    apply(simp) using same_fw_behaviour_one_equi(3) by blast\n  from this groupParts_same_fw_wi0[of A c rs]  groupParts_same_fw_wi0[of B c rs] asm\n  show \"\\<forall>aw \\<in> set (map wordinterval_to_set A).\n        \\<forall>bw \\<in> set (map wordinterval_to_set B).\n        \\<forall>a \\<in> aw. \\<forall>b \\<in> bw. \\<not> same_fw_behaviour_one a b c rs\"\n    apply(simp) using same_fw_behaviour_one_equi(3) by fast\nqed\n\n\n\n\n\n(*beginning is copy&paste of previous proof*)\nlemma groupParts_same_fw_wi1:\n  \"V \\<in> set (groupWIs c rs) \\<Longrightarrow> \\<forall>w1 \\<in> set V. \\<forall>w2 \\<in> set V.\n     \\<forall>a1 \\<in> wordinterval_to_set w1. \\<forall>a2 \\<in> wordinterval_to_set w2. same_fw_behaviour_one a1 a2 c rs\"\nproof -\n  assume asm: \"V \\<in> set (groupWIs c rs)\"\n  from getParts_same_fw_behaviour same_fw_spec\n    have b1: \"\\<forall>A \\<in> set (map wordinterval_to_set (getParts rs)) . \\<forall>a1 \\<in> A. \\<forall>a2 \\<in> A.\n              same_fw_behaviour_one a1 a2 c rs\" by fast\n  from getParts_complete have complete: \"\\<Union>set (map wordinterval_to_set (getParts rs)) = UNIV\"\n    by(simp add: wordinterval_list_to_set_def)\n  from getParts_nonempty_elems have nonempty: \"\\<forall>w\\<in>set (getParts rs). \\<not> wordinterval_empty w\" by simp\n\n  { fix W x1 x2\n    assume a1: \"\\<forall>A \\<in> set (map wordinterval_to_set W). \\<forall>a1 \\<in> A. \\<forall>a2 \\<in> A. same_fw_behaviour_one a1 a2 c rs\"\n    and a2: \"wordinterval_list_to_set W = UNIV\"\n    and a3: \"\\<forall>w \\<in> set W. \\<not> wordinterval_empty w\"\n    and a4: \"(map (\\<lambda>d. runFw x1 d c rs) (map getOneIp W), map (\\<lambda>s. runFw s x1 c rs) (map getOneIp W)) =\n             (map (\\<lambda>d. runFw x2 d c rs) (map getOneIp W), map (\\<lambda>s. runFw s x2 c rs) (map getOneIp W))\"\n      from a3 a4 getOneIp_elem\n        have b1: \"\\<forall>B \\<in> set (map wordinterval_to_set W). \\<exists>b \\<in> B. runFw x1 b c rs = runFw x2 b c rs\"\n        by fastforce\n      from a3 a4 getOneIp_elem\n        have b2: \"\\<forall>B \\<in> set (map wordinterval_to_set W). \\<exists>b \\<in> B. runFw b x1 c rs = runFw b x2 c rs\"\n        by fastforce\n      from runFw_sameFw_behave[OF a1 _ b1 b2] a2[unfolded wordinterval_list_to_set_def] have\n        \"same_fw_behaviour_one x1 x2 c rs\" by simp\n  } note same_behave_runFw=this\n\n  from same_behave_runFw[OF b1 getParts_complete nonempty]\n       groupF_equality[of \"(\\<lambda>wi. (map (\\<lambda>d. runFw (getOneIp wi) d c rs) (map getOneIp (getParts rs)),\n                             map (\\<lambda>s. runFw s (getOneIp wi) c rs) (map getOneIp (getParts rs))))\"\n                     \"(getParts rs)\"] asm\n  have b2: \"\\<forall>a1\\<in>set V. \\<forall>a2\\<in>set V. same_fw_behaviour_one (getOneIp a1) (getOneIp a2) c rs\"\n    apply(subst (asm) groupWIs_def)\n    apply(subst (asm) Let_def)+\n    by fast\n  from groupWIs_not_empty_elems asm have \"\\<forall>w \\<in> set V. \\<not> wordinterval_empty w\" by blast\n  from this b2 getOneIp_elem\n    have b3: \"\\<forall>w1\\<in>set (map wordinterval_to_set V). \\<forall>w2\\<in>set (map wordinterval_to_set V). \n           \\<exists>ip1\\<in> w1. \\<exists>ip2\\<in>w2.\n           same_fw_behaviour_one ip1 ip2 c rs\" by (simp) (blast)\n  from groupParts_same_fw_wi0 asm \n    have \"\\<forall>A\\<in>set (map wordinterval_to_set V). \\<forall>a1\\<in> A. \\<forall>a2\\<in> A. same_fw_behaviour_one a1 a2 c rs\" \n    by metis\n  from sameFw_behave_sets[OF this b3]\n  show \"\\<forall>w1 \\<in> set V. \\<forall>w2 \\<in> set V.\n   \\<forall>a1 \\<in> wordinterval_to_set w1. \\<forall>a2 \\<in> wordinterval_to_set w2. same_fw_behaviour_one a1 a2 c rs\"\n  by force\nqed\n\nlemma groupParts_same_fw_wi2: \"V \\<in> set (groupWIs c rs) \\<Longrightarrow>\n                               \\<forall>ip1 \\<in> wordinterval_list_to_set V.\n                               \\<forall>ip2 \\<in> wordinterval_list_to_set V.\n                               same_fw_behaviour_one ip1 ip2 c rs\"\n  using groupParts_same_fw_wi0 groupParts_same_fw_wi1\n  apply (simp add: wordinterval_list_to_set_def)\n  by fast\n\nlemma groupWIs_same_fw_not2: \"A \\<in> set (groupWIs c rs) \\<Longrightarrow> B \\<in> set (groupWIs c rs) \\<Longrightarrow> \n                                A \\<noteq> B \\<Longrightarrow>\n                                \\<forall>ip1 \\<in> wordinterval_list_to_set A.\n                                \\<forall>ip2 \\<in> wordinterval_list_to_set B.\n                                \\<not> same_fw_behaviour_one ip1 ip2 c rs\"\n  apply(simp add: wordinterval_list_to_set_def)\n  using groupWIs_same_fw_not by fastforce\n\n(*I like this version -- corny*)\nlemma \"A \\<in> set (groupWIs c rs) \\<Longrightarrow> B \\<in> set (groupWIs c rs) \\<Longrightarrow> \n                \\<exists>ip1 \\<in> wordinterval_list_to_set A.\n                \\<exists>ip2 \\<in> wordinterval_list_to_set B. same_fw_behaviour_one ip1 ip2 c rs\n                \\<Longrightarrow> A = B\"\nusing groupWIs_same_fw_not2 by blast\n\n\nlemma groupWIs_complete: \"(\\<Union>x\\<in> set (groupWIs c rs). wordinterval_list_to_set x) = (UNIV::'i::len word set)\"\n  proof -\n  have \"(\\<Union> y \\<in> (\\<Union>x\\<in> set (groupWIs c rs). set x). wordinterval_to_set y) = (UNIV::'i word set)\"\n    apply(simp add: groupWIs_def Let_def groupF_Union_set)\n    using getParts_complete wordinterval_list_to_set_def by fastforce\n  thus ?thesis by(simp add: wordinterval_list_to_set_def)\nqed\n\n\n(*begin groupWIs1 and groupWIs2 optimization*)\n  definition groupWIs1 :: \"'a parts_connection_scheme \\<Rightarrow> 'i::len simple_rule list \\<Rightarrow> 'i wordinterval list list\" where\n    \"groupWIs1 c rs = (let P = getParts rs in\n                        (let W = map getOneIp P in \n                         (let f = (\\<lambda>wi. (map (\\<lambda>d. runFw (getOneIp wi) d c rs) W,\n                                         map (\\<lambda>s. runFw s (getOneIp wi) c rs) W)) in\n                        map (map fst) (groupF snd (map (\\<lambda>x. (x, f x)) P)))))\"\n  \n  lemma groupWIs_groupWIs1_equi: \"groupWIs1 c rs = groupWIs c rs\"\n    apply(subst groupWIs1_def)\n    apply(subst groupWIs_def)\n  using groupF_tuple by metis\n  \n  definition simple_conn_matches :: \"'i::len simple_match \\<Rightarrow> parts_connection \\<Rightarrow> bool\" where\n      \"simple_conn_matches m c \\<longleftrightarrow>\n        (match_iface (iiface m) (pc_iiface c)) \\<and>\n        (match_iface (oiface m) (pc_oiface c)) \\<and>\n        (match_proto (proto m) (pc_proto c)) \\<and>\n        (simple_match_port (sports m) (pc_sport c)) \\<and>\n        (simple_match_port (dports m) (pc_dport c))\"\n  \n  lemma simple_conn_matches_simple_match_any: \"simple_conn_matches simple_match_any c\"\n    apply(simp add: simple_conn_matches_def)\n    apply(simp add: simple_match_any_def match_ifaceAny)\n    apply(subgoal_tac \"(65535::16 word) = max_word\")\n     apply(simp)\n    by(simp add: max_word_def)\n  \n  lemma has_default_policy_simple_conn_matches:\n    \"has_default_policy rs \\<Longrightarrow> has_default_policy [r\\<leftarrow>rs . simple_conn_matches (match_sel r) c]\"\n    apply(induction rs rule: has_default_policy.induct)\n      apply(simp; fail)\n     apply(simp add: simple_conn_matches_simple_match_any; fail)\n    apply(simp)\n    apply(intro conjI)\n     apply(simp split: if_split_asm; fail)\n    apply(simp add: has_default_policy_fst split: if_split_asm)\n    done\n  \n  \n  lemma filter_conn_fw_lem: \n    \"runFw s d c (filter (\\<lambda>r. simple_conn_matches (match_sel r) c) rs) = runFw s d c rs\"\n    apply(simp add: runFw_def simple_conn_matches_def match_sel_def)\n    apply(induction rs \"\\<lparr>p_iiface = pc_iiface c, p_oiface = pc_oiface c,\n                         p_src = s, p_dst = d, p_proto = pc_proto c, \n                         p_sport = pc_sport c, p_dport = pc_dport c,\n                         p_tcp_flags = {TCP_SYN},p_payload=''''\\<rparr>\"\n          rule: simple_fw.induct)\n    apply(simp add: simple_matches.simps)+\n  done\n  \n  \n  (*performance: despite optimization, this function takes quite long and can be optimized*)\n  definition groupWIs2 :: \"parts_connection \\<Rightarrow> 'i::len simple_rule list \\<Rightarrow> 'i wordinterval list list\" where\n    \"groupWIs2 c rs =  (let P = getParts rs in\n                         (let W = map getOneIp P in \n                         (let filterW = (filter (\\<lambda>r. simple_conn_matches (match_sel r) c) rs) in\n                           (let f = (\\<lambda>wi. (map (\\<lambda>d. runFw (getOneIp wi) d c filterW) W,\n                                           map (\\<lambda>s. runFw s (getOneIp wi) c filterW) W)) in\n                        map (map fst) (groupF snd (map (\\<lambda>x. (x, f x)) P))))))\"\n  \n  lemma groupWIs1_groupWIs2_equi: \"groupWIs2 c rs = groupWIs1 c rs\"\n    by(simp add: groupWIs2_def groupWIs1_def filter_conn_fw_lem)\n  \n  \n  lemma groupWIs_code[code]: \"groupWIs c rs = groupWIs2 c rs\"\n    using groupWIs1_groupWIs2_equi groupWIs_groupWIs1_equi by metis\n(*end groupWIs1 and groupWIs2 optimization*)\n\n\n(*begin groupWIs3 optimization*)\n  fun matching_dsts :: \"'i::len word \\<Rightarrow> 'i simple_rule list \\<Rightarrow> 'i wordinterval \\<Rightarrow> 'i wordinterval\" where\n    \"matching_dsts _ [] _ = Empty_WordInterval\" |\n    \"matching_dsts s ((SimpleRule m Accept)#rs) acc_dropped =\n        (if simple_match_ip (src m) s then\n           wordinterval_union (wordinterval_setminus (ipcidr_tuple_to_wordinterval (dst m)) acc_dropped) (matching_dsts s rs acc_dropped)\n         else\n           matching_dsts s rs acc_dropped)\" |\n    \"matching_dsts s ((SimpleRule m Drop)#rs) acc_dropped =\n        (if simple_match_ip (src m) s then\n           matching_dsts s rs (wordinterval_union (ipcidr_tuple_to_wordinterval (dst m)) acc_dropped)\n         else\n           matching_dsts s rs acc_dropped)\"\n  \n  lemma matching_dsts_pull_out_accu:\n    \"wordinterval_to_set (matching_dsts s rs (wordinterval_union a1 a2)) = wordinterval_to_set (matching_dsts s rs a2) - wordinterval_to_set a1\"\n    apply(induction s rs a2 arbitrary: a1 a2 rule: matching_dsts.induct)\n       apply(simp_all)\n    by blast+\n  \n  (*a copy of matching_dsts*)\n  fun matching_srcs :: \"'i::len word \\<Rightarrow> 'i simple_rule list \\<Rightarrow> 'i wordinterval \\<Rightarrow> 'i wordinterval\" where\n    \"matching_srcs _ [] _ = Empty_WordInterval\" |\n    \"matching_srcs d ((SimpleRule m Accept)#rs) acc_dropped =\n        (if simple_match_ip (dst m) d then\n           wordinterval_union (wordinterval_setminus (ipcidr_tuple_to_wordinterval (src m)) acc_dropped) (matching_srcs d rs acc_dropped)\n         else\n           matching_srcs d rs acc_dropped)\" |\n    \"matching_srcs d ((SimpleRule m Drop)#rs) acc_dropped =\n        (if simple_match_ip (dst m) d then\n           matching_srcs d rs (wordinterval_union (ipcidr_tuple_to_wordinterval (src m)) acc_dropped)\n         else\n           matching_srcs d rs acc_dropped)\"\n  \n  lemma matching_srcs_pull_out_accu:\n    \"wordinterval_to_set (matching_srcs d rs (wordinterval_union a1 a2)) = wordinterval_to_set (matching_srcs d rs a2) - wordinterval_to_set a1\"\n    apply(induction d rs a2 arbitrary: a1 a2 rule: matching_srcs.induct)\n       apply(simp_all)\n    by blast+\n  \n  \n  lemma matching_dsts: \"\\<forall>r \\<in> set rs. simple_conn_matches (match_sel r) c \\<Longrightarrow>\n          wordinterval_to_set (matching_dsts s rs Empty_WordInterval) = {d. runFw s d c rs = Decision FinalAllow}\"\n    proof(induction rs)\n    case Nil thus ?case by (simp add: runFw_def)\n    next\n    case (Cons r rs)\n      obtain m a where r: \"r = SimpleRule m a\" by(cases r, blast)\n      \n      from Cons.prems r have simple_match_ip_Accept: \"\\<And>d. simple_match_ip (src m) s \\<Longrightarrow>\n        runFw s d c (SimpleRule m Accept # rs) = Decision FinalAllow \\<longleftrightarrow> simple_match_ip (dst m) d \\<or> runFw s d c rs = Decision FinalAllow\"\n        by(simp add: simple_conn_matches_def runFw_def simple_matches.simps)\n  \n      { fix d a\n        have \"\\<not> simple_match_ip (src m) s \\<Longrightarrow>\n         runFw s d c (SimpleRule m a # rs) = Decision FinalAllow \\<longleftrightarrow> runFw s d c rs = Decision FinalAllow\"\n        apply(cases a)\n         by(simp add: simple_conn_matches_def runFw_def simple_matches.simps)+\n       } note not_simple_match_ip=this\n  \n      from Cons.prems r have simple_match_ip_Drop: \"\\<And>d. simple_match_ip (src m) s \\<Longrightarrow>\n             runFw s d c (SimpleRule m Drop # rs) = Decision FinalAllow \\<longleftrightarrow> \\<not> simple_match_ip (dst m) d \\<and> runFw s d c rs = Decision FinalAllow\"\n        by(simp add: simple_conn_matches_def runFw_def simple_matches.simps)\n  \n      show ?case\n        proof(cases a)\n        case Accept with r Cons show ?thesis\n         apply(simp, intro conjI impI)\n          apply(simp add: simple_match_ip_Accept wordinterval_to_set_ipcidr_tuple_to_wordinterval_simple_match_ip_set)\n          apply blast\n         apply(simp add: not_simple_match_ip; fail)\n         done\n        next\n        case Drop with r Cons show ?thesis\n          apply(simp,intro conjI impI)\n           apply(simp add: simple_match_ip_Drop matching_dsts_pull_out_accu wordinterval_to_set_ipcidr_tuple_to_wordinterval_simple_match_ip_set)\n           apply blast\n          apply(simp add: not_simple_match_ip; fail)\n         done\n        qed\n    qed\n  lemma matching_srcs: \"\\<forall>r \\<in> set rs. simple_conn_matches (match_sel r) c \\<Longrightarrow>\n          wordinterval_to_set (matching_srcs d rs Empty_WordInterval) = {s. runFw s d c rs = Decision FinalAllow}\"\n    proof(induction rs)\n    case Nil thus ?case by (simp add: runFw_def)\n    next\n    case (Cons r rs)\n      obtain m a where r: \"r = SimpleRule m a\" by(cases r, blast)\n      \n      from Cons.prems r have simple_match_ip_Accept: \"\\<And>s. simple_match_ip (dst m) d \\<Longrightarrow>\n         runFw s d c (SimpleRule m Accept # rs) = Decision FinalAllow \\<longleftrightarrow>\n          simple_match_ip (src m) s \\<or> runFw s d c rs = Decision FinalAllow\"\n        by(simp add: simple_conn_matches_def runFw_def simple_matches.simps)\n  \n      { fix s a\n        have \"\\<not> simple_match_ip (dst m) d \\<Longrightarrow>\n         runFw s d c (SimpleRule m a # rs) = Decision FinalAllow \\<longleftrightarrow> runFw s d c rs = Decision FinalAllow\"\n        apply(cases a)\n         by(simp add: simple_conn_matches_def runFw_def simple_matches.simps)+\n       } note not_simple_match_ip=this\n  \n      from Cons.prems r have simple_match_ip_Drop: \"\\<And>s. simple_match_ip (dst m) d \\<Longrightarrow>\n         runFw s d c (SimpleRule m Drop # rs) = Decision FinalAllow \\<longleftrightarrow>\n          \\<not> simple_match_ip (src m) s \\<and> runFw s d c rs = Decision FinalAllow\"\n        by(simp add: simple_conn_matches_def runFw_def simple_matches.simps)\n  \n      show ?case\n        proof(cases a)\n        case Accept with r Cons show ?thesis\n         apply(simp, intro conjI impI)\n          apply(simp add: simple_match_ip_Accept wordinterval_to_set_ipcidr_tuple_to_wordinterval_simple_match_ip_set)\n          apply blast\n         apply(simp add: not_simple_match_ip; fail)\n         done\n        next\n        case Drop with r Cons show ?thesis\n          apply(simp,intro conjI impI)\n           apply(simp add: simple_match_ip_Drop matching_srcs_pull_out_accu wordinterval_to_set_ipcidr_tuple_to_wordinterval_simple_match_ip_set)\n           apply blast\n          apply(simp add: not_simple_match_ip; fail)\n         done\n        qed\n    qed\n  \n  \n  \n  (*TODO: if we can get wordinterval_element to log runtime ...*)\n  definition groupWIs3_default_policy :: \"parts_connection \\<Rightarrow> 'i::len simple_rule list \\<Rightarrow> 'i wordinterval list list\" where\n    \"groupWIs3_default_policy c rs =  (let P = getParts rs in\n                         (let W = map getOneIp P in \n                         (let filterW = (filter (\\<lambda>r. simple_conn_matches (match_sel r) c) rs) in\n                           (let f = (\\<lambda>wi. let mtch_dsts = (matching_dsts (getOneIp wi) filterW Empty_WordInterval);\n                                              mtch_srcs = (matching_srcs (getOneIp wi) filterW Empty_WordInterval) in \n                                          (map (\\<lambda>d. wordinterval_element d mtch_dsts) W,\n                                           map (\\<lambda>s. wordinterval_element s mtch_srcs) W)) in\n                        map (map fst) (groupF snd (map (\\<lambda>x. (x, f x)) P))))))\"\n  \n  \n  lemma groupWIs3_default_policy_groupWIs2:\n  fixes rs :: \"'i::len simple_rule list\"\n  assumes \"has_default_policy rs\"\n  shows \"groupWIs2 c rs = groupWIs3_default_policy c rs\"\n  proof -\n    { fix filterW s d\n      from matching_dsts[where c=c] have \"filterW = filter (\\<lambda>r. simple_conn_matches (match_sel r) c) rs \\<Longrightarrow>\n           wordinterval_element d (matching_dsts s filterW Empty_WordInterval) \\<longleftrightarrow> runFw s d c filterW = Decision FinalAllow\"\n      by force\n    } note matching_dsts_filterW=this[simplified]\n  \n    { fix filterW s d\n      from matching_srcs[where c=c] have \"filterW = filter (\\<lambda>r. simple_conn_matches (match_sel r) c) rs \\<Longrightarrow>\n            wordinterval_element s (matching_srcs d filterW Empty_WordInterval) \\<longleftrightarrow> runFw s d c filterW = Decision FinalAllow\"\n      by force\n    } note matching_srcs_filterW=this[simplified]\n  \n    { fix W and rs :: \"'i::len simple_rule list\"\n      assume assms': \"has_default_policy rs\"\n      have \"groupF (\\<lambda>wi. (map (\\<lambda>d. runFw (getOneIp wi) d c rs = Decision FinalAllow) (map getOneIp W),\n                           map (\\<lambda>s. runFw s (getOneIp wi) c rs = Decision FinalAllow) (map getOneIp W))) W =\n             groupF (\\<lambda>wi. (map (\\<lambda>d. runFw (getOneIp wi) d c rs) (map getOneIp W),\n                           map (\\<lambda>s. runFw s (getOneIp wi) c rs) (map getOneIp W))) W\"\n      proof -\n        { (*unused fresh generic variables. 'a is used for the tuple already*)\n          fix f1::\"'w \\<Rightarrow> 'u \\<Rightarrow> 'v\" and f2::\" 'w \\<Rightarrow> 'u \\<Rightarrow> 'x\" and x and y and g1::\"'w \\<Rightarrow> 'u \\<Rightarrow> 'y\" and g2::\"'w \\<Rightarrow> 'u \\<Rightarrow> 'z\" and W::\"'u list\"\n            assume 1: \"\\<forall>w \\<in> set W. (f1 x) w = (f1 y) w \\<longleftrightarrow> (f2 x) w =  (f2 y) w\"\n               and 2: \"\\<forall>w \\<in> set W. (g1 x) w = (g1 y) w \\<longleftrightarrow> (g2 x) w =  (g2 y) w\"\n               have \"\n                 ((map (f1 x) W, map (g1 x) W) = (map (f1 y) W, map (g1 y) W)) \n                 \\<longleftrightarrow>\n                 ((map (f2 x) W, map (g2 x) W) = (map (f2 y) W, map (g2 y) W))\"\n          proof -\n            from 1 have p1: \"(map (f1 x) W = map (f1 y) W \\<longleftrightarrow> map (f2 x) W = map (f2 y) W)\" by(induction W)(simp_all)\n            from 2 have p2: \"(map (g1 x) W = map (g1 y) W \\<longleftrightarrow> map (g2 x) W = map (g2 y) W)\" by(induction W)(simp_all)\n            from p1 p2 show ?thesis by fast\n          qed\n        } note map_over_tuples_equal_helper=this\n      \n        show ?thesis\n        apply(rule groupF_cong)\n        apply(intro ballI)\n        apply(rule map_over_tuples_equal_helper)\n         using has_default_policy_runFw[OF assms'] by metis+\n      qed\n    } note has_default_policy_groupF=this[simplified]\n  \n    from assms show ?thesis\n    apply(simp add: groupWIs3_default_policy_def groupWIs_code[symmetric])\n    apply(subst groupF_tuple[symmetric])\n    apply(simp add: Let_def)\n    apply(simp add: matching_srcs_filterW matching_dsts_filterW)\n    apply(subst has_default_policy_groupF)\n     apply(simp add: has_default_policy_simple_conn_matches; fail)\n    apply(simp add: groupWIs_def Let_def filter_conn_fw_lem)\n    done\n  qed\n  \n  \n  definition groupWIs3 :: \"parts_connection \\<Rightarrow> 'i::len simple_rule list \\<Rightarrow> 'i wordinterval list list\" where\n    \"groupWIs3 c rs = (if has_default_policy rs then groupWIs3_default_policy c rs else groupWIs2 c rs)\"\n  \n  lemma groupWIs3: \"groupWIs3 = groupWIs\"\n    by(simp add: fun_eq_iff groupWIs3_def groupWIs_code groupWIs3_default_policy_groupWIs2) \n\n(*end groupWIs3 optimization*)\n\n(*construct partitions. main function!*)\ndefinition build_ip_partition :: \"parts_connection \\<Rightarrow> 'i::len simple_rule list \\<Rightarrow> 'i wordinterval list\" where\n  \"build_ip_partition c rs = map\n    (\\<lambda>xs. wordinterval_sort (wordinterval_compress (foldr wordinterval_union xs Empty_WordInterval)))\n      (groupWIs3 c rs)\"\n\n\ntheorem build_ip_partition_same_fw: \"V \\<in> set (build_ip_partition c rs) \\<Longrightarrow>\n                               \\<forall>ip1::'i::len word \\<in> wordinterval_to_set V.\n                               \\<forall>ip2::'i::len word \\<in> wordinterval_to_set V.\n                               same_fw_behaviour_one ip1 ip2 c rs\"\n  apply(simp add: build_ip_partition_def groupWIs3)\n  using wordinterval_list_to_set_compressed groupParts_same_fw_wi2 wordinterval_sort by blast\n\ntheorem build_ip_partition_same_fw_min: \"A \\<in> set (build_ip_partition c rs) \\<Longrightarrow> B \\<in> set (build_ip_partition c rs) \\<Longrightarrow> \n                                A \\<noteq> B \\<Longrightarrow>\n                                \\<forall>ip1::'i::len word \\<in> wordinterval_to_set A.\n                                \\<forall>ip2::'i::len word \\<in> wordinterval_to_set B.\n                                \\<not> same_fw_behaviour_one ip1 ip2 c rs\"\n  apply(simp add: build_ip_partition_def groupWIs3)\n  using  groupWIs_same_fw_not2 wordinterval_list_to_set_compressed wordinterval_sort by blast\n\ntheorem build_ip_partition_complete: \"(\\<Union>x\\<in>set (build_ip_partition c rs). wordinterval_to_set x) = (UNIV :: 'i::len word set)\"\n  proof -\n  have \"wordinterval_to_set (foldr wordinterval_union x Empty_WordInterval) = (\\<Union>set (map wordinterval_to_set x))\"\n    for x::\"'i wordinterval list\"\n    by(induction x) simp_all\n  thus ?thesis\n  apply(simp add: build_ip_partition_def groupWIs3 wordinterval_compress wordinterval_sort)\n  using groupWIs_complete[simplified wordinterval_list_to_set_def] by simp\n  qed\n\n\n\nlemma build_ip_partition_no_empty_elems: \"wi \\<in> set (build_ip_partition c rs) \\<Longrightarrow> \\<not> wordinterval_empty wi\"\n  proof -\n    assume \"wi \\<in> set (build_ip_partition c rs)\"\n    hence assm: \"wi \\<in> (\\<lambda>xs. wordinterval_sort (wordinterval_compress (foldr wordinterval_union xs Empty_WordInterval))) ` set (groupWIs c rs)\"\n      by(simp add: build_ip_partition_def groupWIs3)\n    from assm obtain wi_orig where 1: \"wi_orig \\<in>  set (groupWIs c rs)\" and\n       2: \"wi = wordinterval_sort (wordinterval_compress (foldr wordinterval_union wi_orig Empty_WordInterval))\" by blast\n    from 1 groupWIs_not_empty_elem have i1: \"wi_orig \\<noteq> []\" by blast\n    from 1 groupWIs_not_empty_elems have i2: \"\\<And>w. w \\<in> set wi_orig \\<Longrightarrow> \\<not> wordinterval_empty w\" by simp\n    from i1 i2 have \"wordinterval_to_set (foldr wordinterval_union wi_orig Empty_WordInterval) \\<noteq> {}\"\n      by(induction wi_orig) simp_all\n    with 2 show ?thesis by(simp add: wordinterval_compress wordinterval_sort)\n  qed\n\n\nlemma build_ip_partition_disjoint: \n      \"V1 \\<in> set (build_ip_partition c rs) \\<Longrightarrow> V2 \\<in> set (build_ip_partition c rs) \\<Longrightarrow>\n       V1 \\<noteq> V2 \\<Longrightarrow>\n        wordinterval_to_set V1 \\<inter> wordinterval_to_set V2 = {}\"\n  by (meson build_ip_partition_same_fw_min int_not_emptyD same_fw_behaviour_one_equi(1))\n\n\nlemma map_wordinterval_to_set_distinct:\n  assumes distinct: \"distinct xs\"\n  and disjoint: \"(\\<forall>x1 \\<in> set xs. \\<forall>x2 \\<in> set xs. x1 \\<noteq> x2 \\<longrightarrow> wordinterval_to_set x1 \\<inter> wordinterval_to_set x2 = {})\" \n  and notempty: \"\\<forall>x \\<in> set xs. \\<not> wordinterval_empty x\"\n  shows \"distinct (map wordinterval_to_set xs)\"\n  proof -\n    have \"\\<not> wordinterval_empty x1 \\<Longrightarrow> \n        wordinterval_to_set x1 \\<inter> wordinterval_to_set x2 = {} \\<Longrightarrow> \n        wordinterval_to_set x1 \\<noteq> wordinterval_to_set x2\" for x1::\"('b::len) wordinterval\" and x2\n      by auto\n    with disjoint notempty have \"(\\<forall>x1 \\<in> set xs. \\<forall>x2 \\<in> set xs. x1 \\<noteq> x2 \\<longrightarrow> wordinterval_to_set x1 \\<noteq> wordinterval_to_set x2)\"\n      by force\n    with distinct show \"distinct (map wordinterval_to_set xs)\"\n    proof(induction xs)\n    case Cons thus ?case by simp fast\n    qed(simp)\n  qed\n\nlemma map_getOneIp_distinct: assumes\n  distinct: \"distinct xs\"\n  and disjoint: \"(\\<forall>x1 \\<in> set xs. \\<forall>x2 \\<in> set xs. x1 \\<noteq> x2 \\<longrightarrow> wordinterval_to_set x1 \\<inter> wordinterval_to_set x2 = {})\" \n  and notempty: \"\\<forall>x \\<in> set xs. \\<not> wordinterval_empty x\"\n  shows \"distinct (map getOneIp xs)\"\n  proof -\n    have \"\\<not> wordinterval_empty x \\<Longrightarrow> \\<not> wordinterval_empty xa \\<Longrightarrow> \n          wordinterval_to_set x \\<inter> wordinterval_to_set xa = {} \\<Longrightarrow> getOneIp x \\<noteq> getOneIp xa\"\n     for x xa::\"'b::len wordinterval\"\n     by(fastforce dest: getOneIp_elem)\n    with disjoint notempty have \"(\\<forall>x1 \\<in> set xs. \\<forall>x2 \\<in> set xs. x1 \\<noteq> x2 \\<longrightarrow> getOneIp x1 \\<noteq> getOneIp x2)\"\n      by metis\n    with distinct show ?thesis\n    proof(induction xs)\n    case Cons thus ?case by simp fast\n    qed(simp)\n  qed\n\n\nlemma getParts_disjoint_list: \"disjoint_list (map wordinterval_to_set (getParts rs))\"\nproof-\n  have disjoint_list_partitioningIps: \n    \"{} \\<notin> set (map wordinterval_to_set ts) \\<Longrightarrow> disjoint_list (map wordinterval_to_set ts) \\<Longrightarrow> \n     (wordinterval_list_to_set ss) \\<subseteq> (wordinterval_list_to_set ts) \\<Longrightarrow>\n     disjoint_list (map wordinterval_to_set (partitioningIps ss ts))\"\n     for ts::\"'a::len wordinterval list\" and ss\n  by (simp add: partitioning1_disjoint_list partitioningIps_equi wordinterval_list_to_set_def)\n  have \"{} \\<notin> set (map wordinterval_to_set [wordinterval_UNIV])\"\n  and \"disjoint_list (map wordinterval_to_set [wordinterval_UNIV])\"\n  and \"wordinterval_list_to_set (extract_IPSets rs) \\<subseteq> wordinterval_list_to_set [wordinterval_UNIV]\"\n    by(simp add: wordinterval_list_to_set_def disjoint_list_def disjoint_def)+\n  thus ?thesis\n  unfolding getParts_def by(rule disjoint_list_partitioningIps)\nqed\n\nlemma build_ip_partition_distinct: \"distinct (map wordinterval_to_set (build_ip_partition c rs))\"\nproof -\n  have  \n  \"(wordinterval_to_set \\<circ> (\\<lambda>xs. wordinterval_sort (wordinterval_compress (foldr wordinterval_union xs Empty_WordInterval)))) ws\n       = \\<Union> set (map wordinterval_to_set ws)\" for ws::\"'a::len wordinterval list\"\n    proof(induction ws)\n    qed(simp_all add: wordinterval_compress wordinterval_sort)\n  hence hlp1: \"map wordinterval_to_set (build_ip_partition c rs) =\n                   map (\\<lambda>x. \\<Union> set (map wordinterval_to_set x)) (groupWIs c rs)\"\n    unfolding build_ip_partition_def groupWIs3 by auto\n\n  --\"generic rule\"\n  have \"\\<forall>x \\<in> set xs. \\<not> wordinterval_empty x \\<Longrightarrow>\n         disjoint_list (map wordinterval_to_set xs) \\<Longrightarrow>\n         distinct (map (\\<lambda>x. \\<Union>set (map wordinterval_to_set x)) (groupF f xs))\"\n         for f::\"'x::len wordinterval \\<Rightarrow> 'y\" and xs::\"'x::len wordinterval list\"\n    proof(induction f xs rule: groupF.induct)\n    case 1 thus ?case by simp\n    next\n    case (2 f x xs)\n      have hlp_internal:\n          \"\\<Union> (set (map (\\<lambda>x. \\<Union> set (map wordinterval_to_set x)) (groupF f xs))) =\n           \\<Union> set (map wordinterval_to_set xs)\" for f::\"'x wordinterval \\<Rightarrow> 'y\" and xs\n      by(induction f xs rule: groupF.induct) (auto)\n\n      from 2(2,3) have \"wordinterval_to_set x \\<inter> \\<Union>(wordinterval_to_set ` set xs) = {}\"\n        by(auto simp add: disjoint_def disjoint_list_def)\n      hence \"\\<not> (wordinterval_to_set x) \\<subseteq> \\<Union>(wordinterval_to_set ` set xs)\" using 2(2) by auto\n      hence \"\\<not> wordinterval_to_set x \\<subseteq> \\<Union>set (map wordinterval_to_set [y\\<leftarrow>xs . f x \\<noteq> f y])\" by auto\n      hence \"\\<not> wordinterval_to_set x \\<union> (\\<Union>x\\<in>{xa \\<in> set xs. f x = f xa}.\n         wordinterval_to_set x) \\<subseteq> \\<Union> (set (map (\\<lambda>x. \\<Union> set (map wordinterval_to_set x)) (groupF f [y\\<leftarrow>xs . f x \\<noteq> f y])))\" \n      unfolding hlp_internal by blast\n      hence g1: \"wordinterval_to_set x \\<union> (\\<Union>x\\<in>{xa \\<in> set xs. f x = f xa}. wordinterval_to_set x)\n        \\<notin> (\\<lambda>x. \\<Union>x\\<in>set x. wordinterval_to_set x) ` set (groupF f [y\\<leftarrow>xs . f x \\<noteq> f y])\" by force\n      \n      from 2(3) have \"distinct (map wordinterval_to_set [y\\<leftarrow>xs . f x \\<noteq> f y])\"\n        by (simp add: disjoint_list_def  distinct_map_filter) \n      moreover from 2 have \"disjoint (wordinterval_to_set ` {xa \\<in> set xs. f x \\<noteq> f xa})\"\n       by(simp add: disjoint_def disjoint_list_def)\n      ultimately have g2: \"distinct (map (\\<lambda>x. \\<Union>x\\<in>set x. wordinterval_to_set x) (groupF f [y\\<leftarrow>xs . f x \\<noteq> f y]))\"\n        using 2(1,2) unfolding disjoint_list_def by(simp)\n\n      from g1 g2 show ?case by simp\n    qed\n    with getParts_disjoint_list getParts_nonempty_elems have\n      \"distinct\n     (map (\\<lambda>x. \\<Union>set (map wordinterval_to_set x))\n       (groupF (\\<lambda>wi. (map (\\<lambda>d. runFw (getOneIp wi) d c rs) (map getOneIp (getParts rs)),\n                      map (\\<lambda>s. runFw s (getOneIp wi) c rs) (map getOneIp (getParts rs))))\n         (getParts rs)))\" by blast\n\n  thus ?thesis unfolding hlp1 groupWIs_def Let_def by presburger\nqed\n\nlemma build_ip_partition_distinct': \"distinct (build_ip_partition c rs)\"\n  using build_ip_partition_distinct distinct_mapI by blast\n\n\nsubsection\\<open>Service Matrix over an IP Address Space Partition\\<close>\n\n\ndefinition simple_firewall_without_interfaces :: \"'i::len simple_rule list \\<Rightarrow> bool\" where\n  \"simple_firewall_without_interfaces rs \\<equiv> \\<forall>m \\<in> match_sel ` set rs. iiface m = ifaceAny \\<and> oiface m = ifaceAny\"\n\nlemma simple_fw_no_interfaces:\n  assumes no_ifaces: \"simple_firewall_without_interfaces rs\"\n  shows \"simple_fw rs p = simple_fw rs (p\\<lparr> p_iiface:= x, p_oiface:= y\\<rparr>)\"\nproof -\n  from no_ifaces have \"\\<forall>r\\<in>set rs. iiface (match_sel r) = ifaceAny \\<and> oiface (match_sel r) = ifaceAny\"\n    by(simp add: simple_firewall_without_interfaces_def)\n  thus ?thesis apply(induction rs p rule:simple_fw.induct)\n     by(simp_all add: simple_matches.simps match_ifaceAny)\nqed\n   \nlemma runFw_no_interfaces:\n  assumes no_ifaces: \"simple_firewall_without_interfaces rs\"\n  shows \"runFw s d c rs = runFw s d (c\\<lparr> pc_iiface:= x, pc_oiface:= y\\<rparr>) rs\"\n  apply(simp add: runFw_def)\n  apply(subst simple_fw_no_interfaces[OF no_ifaces])\n  by(simp)\n\n\n\n(*only defined for simple_firewall_without_interfaces*)\ndefinition access_matrix \n  :: \"parts_connection \\<Rightarrow> 'i::len simple_rule list \\<Rightarrow> ('i word \\<times> 'i wordinterval) list \\<times> ('i word \\<times> 'i word) list\" \n  where\n  \"access_matrix c rs \\<equiv>\n    (let W = build_ip_partition c rs;\n         R = map getOneIp W\n     in\n     (zip R W, [(s, d)\\<leftarrow>all_pairs R. runFw s d c rs = Decision FinalAllow]))\"\n\nlemma access_matrix_nodes_defined:\n      \"(V,E) = access_matrix c rs \\<Longrightarrow> (s, d) \\<in> set E \\<Longrightarrow> s \\<in> dom (map_of V)\" and\n      \"(V,E) = access_matrix c rs \\<Longrightarrow> (s, d) \\<in> set E \\<Longrightarrow> d \\<in> dom (map_of V)\"\n  by(auto simp add: access_matrix_def Let_def all_pairs_def)\n\ntext\\<open>For all the entries @{term E} of the matrix, the access is allowed\\<close>\nlemma \"(V,E) = access_matrix c rs \\<Longrightarrow> (s, d) \\<in> set E \\<Longrightarrow> runFw s d c rs = Decision FinalAllow\"\n  by(auto simp add: access_matrix_def Let_def)\ntext\\<open>However, the entries are only a representation of a whole set of IP addresses. \n      For all IP addresses which the entries represent, the access must be allowed.\\<close>\n\n\n(*TODO: move to generic library*)\nlemma map_of_zip_map: \"map_of (zip (map f rs) rs) k = Some v \\<Longrightarrow> k = f v\"\n  apply(induction rs)\n   apply(simp)\n  apply(simp split: if_split_asm)\n  done\n\nlemma access_matrix_sound: assumes matrix: \"(V,E) = access_matrix c rs\" and\n              repr: \"(s_repr, d_repr) \\<in> set E\" and\n              s_range: \"(map_of V) s_repr = Some s_range\" and s: \"s \\<in> wordinterval_to_set s_range\" and\n              d_range: \"(map_of V) d_repr = Some d_range\" and d: \"d \\<in> wordinterval_to_set d_range\"\n      shows \"runFw s d c rs = Decision FinalAllow\"\n  proof -\n    let ?part=\"(build_ip_partition c rs)\"\n    have V: \"V = (zip (map getOneIp ?part) ?part)\"\n      using matrix by(simp add: access_matrix_def Let_def)\n    (*have \"E = [(s, d)\\<leftarrow>all_pairs (map getOneIp ?part). runFw s d c rs = Decision FinalAllow]\"\n      using matrix by(simp add: access_matrix_def Let_def)\n    with repr have \"(s_repr, d_repr) \\<in> set (all_pairs (map getOneIp ?part))\" by simp\n    hence \"s_repr \\<in> set (map getOneIp ?part)\" and\n          \"d_repr \\<in> set (map getOneIp ?part)\"\n      by(simp add: all_pairs_set)+*)\n    (*from s_range have \"(s_repr, s_range) \\<in> set V\" by (simp add: map_of_SomeD)*)\n\n    from matrix repr have repr_Allow: \"runFw s_repr d_repr c rs = Decision FinalAllow\"\n      by(auto simp add: access_matrix_def Let_def)\n\n    have s_range_in_part: \"s_range \\<in> set ?part\" using V s_range by (fastforce elim: in_set_zipE dest: map_of_SomeD)\n    with build_ip_partition_no_empty_elems have \"\\<not> wordinterval_empty s_range\" by simp\n\n    have d_range_in_part: \"d_range \\<in> set ?part\" using V d_range by (fastforce elim: in_set_zipE dest: map_of_SomeD)\n    with build_ip_partition_no_empty_elems have \"\\<not> wordinterval_empty d_range\" by simp\n\n    from map_of_zip_map V s_range have \"s_repr = getOneIp s_range\" by fast\n    with \\<open>\\<not> wordinterval_empty s_range\\<close> getOneIp_elem wordinterval_element_set_eq \n    have \"s_repr \\<in> wordinterval_to_set s_range\" by blast \n\n    from map_of_zip_map V d_range have \"d_repr = getOneIp d_range\" by fast\n    with \\<open>\\<not> wordinterval_empty d_range\\<close> getOneIp_elem wordinterval_element_set_eq \n    have \"d_repr \\<in> wordinterval_to_set d_range\" by blast \n\n    from s_range_in_part have s_range_in_part': \"s_range \\<in> set (build_ip_partition c rs)\" by simp\n    from d_range_in_part have d_range_in_part': \"d_range \\<in> set (build_ip_partition c rs)\" by simp\n\n    from build_ip_partition_same_fw[OF s_range_in_part', unfolded same_fw_behaviour_one_def] s\n                                                        \\<open>s_repr \\<in> wordinterval_to_set s_range\\<close> have \n      \"\\<forall>d. runFw s_repr d c rs = runFw s d c rs\" by blast\n    with repr_Allow have 1: \"runFw s d_repr c rs = Decision FinalAllow\" by simp\n\n    from build_ip_partition_same_fw[OF d_range_in_part', unfolded same_fw_behaviour_one_def] d\n                                                        \\<open>d_repr \\<in> wordinterval_to_set d_range\\<close> have \n      \"\\<forall>s. runFw s d_repr c rs = runFw s d c rs\" by blast\n    with 1 have 2: \"runFw s d c rs = Decision FinalAllow\" by simp\n    thus ?thesis .\nqed\n\n\nlemma distinct_map_getOneIp_obtain: \"v \\<in> set xs \\<Longrightarrow> distinct (map getOneIp xs) \\<Longrightarrow> \n  \\<exists>s_repr. map_of (zip (map getOneIp xs) xs) s_repr = Some v\"\n  proof(induction xs)\n  case Nil thus ?case by simp\n  next\n  case (Cons x xs)\n    consider \"v = x\" | \"v \\<in> set xs\" using Cons.prems(1) by fastforce\n    thus ?case\n    proof(cases)\n    case 1 thus ?thesis by simp blast\n    next\n    case 2 with Cons.IH Cons.prems(2) obtain s_repr where\n      s_repr: \"map_of (zip (map getOneIp xs) xs) s_repr = Some v\" by force\n      show ?thesis\n      proof(cases \"s_repr \\<noteq> getOneIp x\")\n        case True with Cons.prems s_repr show ?thesis by(rule_tac x=s_repr in exI, simp)\n        next\n        case False with Cons.prems s_repr show ?thesis by(fastforce elim: in_set_zipE)\n      qed\n    qed\n  qed\n\n\nlemma access_matrix_complete:\n      fixes rs :: \"'i::len simple_rule list\"\n      assumes matrix: \"(V,E) = access_matrix c rs\" and\n              allow: \"runFw s d c rs = Decision FinalAllow\"\n      shows \"\\<exists>s_repr d_repr s_range d_range. (s_repr, d_repr) \\<in> set E \\<and>\n              (map_of V) s_repr = Some s_range \\<and> s \\<in> wordinterval_to_set s_range \\<and>\n              (map_of V) d_repr = Some d_range \\<and> d \\<in> wordinterval_to_set d_range\"\n  proof -\n    let ?part=\"(build_ip_partition c rs)\"\n    have V: \"V = zip (map getOneIp ?part) ?part\"\n      using matrix by(simp add: access_matrix_def Let_def)\n    have E: \"E = [(s, d)\\<leftarrow>all_pairs (map getOneIp ?part). runFw s d c rs = Decision FinalAllow]\"\n      using matrix by(simp add: access_matrix_def Let_def)\n\n    have build_ip_partition_obtain:\n      \"\\<exists>V. V \\<in> set (build_ip_partition c rs) \\<and> s \\<in> wordinterval_to_set V\" for s\n      using build_ip_partition_complete by blast\n\n    have distinct_map_getOneIp_build_ip_partition_obtain:\n        \"v \\<in> set (build_ip_partition c rs) \\<Longrightarrow>\n           \\<exists>s_repr. map_of (zip (map getOneIp (build_ip_partition c rs)) (build_ip_partition c rs)) s_repr = Some v\"\n      for v and rs :: \"'i::len simple_rule list\"\n    proof(erule distinct_map_getOneIp_obtain)\n      show \"distinct (map getOneIp (build_ip_partition c rs))\"  \n      apply(rule map_getOneIp_distinct)\n        subgoal using build_ip_partition_distinct' by blast\n       subgoal using build_ip_partition_disjoint build_ip_partition_distinct' by blast\n      subgoal using build_ip_partition_no_empty_elems[simplified] by auto\n      done\n    qed\n\n    from build_ip_partition_obtain obtain s_range where\n      \"s_range \\<in> set ?part\" and \"s \\<in> wordinterval_to_set s_range\" by blast\n    from this distinct_map_getOneIp_build_ip_partition_obtain V obtain s_repr where\n      ex_s1: \"(map_of V) s_repr = Some s_range\" and ex_s2: \"s \\<in> wordinterval_to_set s_range\"\n      by blast\n\n\n    from build_ip_partition_obtain obtain d_range where\n      \"d_range \\<in> set ?part\" and \"d \\<in> wordinterval_to_set d_range\" by blast\n    from this distinct_map_getOneIp_build_ip_partition_obtain V obtain d_repr where\n      ex_d1: \"(map_of V) d_repr = Some d_range\" and ex_d2: \"d \\<in> wordinterval_to_set d_range\"\n      by blast\n\n    have 1: \"s_repr \\<in> getOneIp ` set (build_ip_partition c rs)\"\n      using V \\<open>map_of V s_repr = Some s_range\\<close> by (fastforce elim: in_set_zipE dest: map_of_SomeD)\n    have 2: \"d_repr \\<in> getOneIp ` set (build_ip_partition c rs)\"\n      using V \\<open>map_of V d_repr = Some d_range\\<close> by (fastforce elim: in_set_zipE dest: map_of_SomeD)\n\n    have \"runFw s_repr d_repr c rs = Decision FinalAllow\"\n    proof -\n      have f1: \"(\\<forall>w wa p ss. \\<not> same_fw_behaviour_one w wa (p::parts_connection) ss \\<or>\n              (\\<forall>wb wc. runFw w wb p ss = runFw wa wb p ss \\<and> runFw wc w p ss = runFw wc wa p ss)) \\<and>\n              (\\<forall>w wa p ss. (\\<exists>wb wc. runFw w wb (p::parts_connection) ss \\<noteq> runFw wa wb p ss \\<or> runFw wc w p ss \\<noteq> runFw wc wa p ss) \\<or>\n              same_fw_behaviour_one w wa p ss)\"\n        unfolding same_fw_behaviour_one_def by blast\n      from \\<open>s_range \\<in> set (build_ip_partition c rs)\\<close>  have f2: \"same_fw_behaviour_one s s_repr c rs\"\n        by (metis (no_types) map_of_zip_map V build_ip_partition_no_empty_elems\n            build_ip_partition_same_fw ex_s1 ex_s2 getOneIp_elem wordinterval_element_set_eq)\n      from \\<open>d_range \\<in> set (build_ip_partition c rs)\\<close> have \"same_fw_behaviour_one d_repr d c rs\"\n        by (metis (no_types) map_of_zip_map V build_ip_partition_no_empty_elems\n            build_ip_partition_same_fw ex_d1 ex_d2 getOneIp_elem wordinterval_element_set_eq)\n      with f1 f2 show ?thesis\n        using allow by metis\n    qed\n      \n    hence ex1: \"(s_repr, d_repr) \\<in> set E\" by(simp add: E all_pairs_set 1 2)\n    \n    thus ?thesis using ex1 ex_s1 ex_s2 ex_d1 ex_d2 by blast \nqed\n\n\ntheorem access_matrix:\n      fixes rs :: \"'i::len simple_rule list\"\n      assumes matrix: \"(V,E) = access_matrix c rs\"\n      shows \"(\\<exists>s_repr d_repr s_range d_range. (s_repr, d_repr) \\<in> set E \\<and>\n              (map_of V) s_repr = Some s_range \\<and> s \\<in> wordinterval_to_set s_range \\<and>\n              (map_of V) d_repr = Some d_range \\<and> d \\<in> wordinterval_to_set d_range)\n             \\<longleftrightarrow>\n             runFw s d c rs = Decision FinalAllow\"\nusing matrix access_matrix_sound access_matrix_complete by blast\n\ntext\\<open>\nFor a @{typ \"'i::len simple_rule list\"} and a fixed @{typ parts_connection}, \nwe support to partition the IP address space; for IP addresses of arbitrary length (eg., IPv4, IPv6).\n\nAll members of a partition have the same access rights:\n@{thm build_ip_partition_same_fw [no_vars]}\n\nMinimal:\n@{thm build_ip_partition_same_fw_min [no_vars]}\n\n\nThe resulting access control matrix is sound and complete:\n\n@{thm access_matrix [no_vars]}\n\nTheorem reads: \nFor a fixed connection, you can look up IP addresses (source and destination pairs) in the matrix \nif and only if the firewall accepts this src,dst IP address pair for the fixed connection.\nNote: The matrix is actually a graph (nice visualization!), you need to look up IP addresses \nin the Vertices and check the access of the representants in the edges. If you want to visualize\nthe graph (e.g. with Graphviz or tkiz): The vertices are the node description (i.e. header; \n  @{term \"dom V\"} is the label for each node which will also be referenced in the edges,\n  @{term \"ran V\"} is the human-readable description for each node (i.e. the full IP range it represents)), \nthe edges are the edges. Result looks nice. Theorem also tells us that this visualization is correct.\n\\<close>\n\n\n\n\n(*construct an ip partition and print it in some usable format\n  returns:\n  (vertices, edges) where\n  vertices = (name, list of ip addresses this vertex corresponds to)\n  and edges = (name \\<times> name) list\n\n  Note that the WordInterval is already sorted, which is important for prettyness!\n*)\ntext\\<open>Only defined for @{const simple_firewall_without_interfaces}\\<close>\ndefinition access_matrix_pretty_ipv4\n  :: \"parts_connection \\<Rightarrow> 32 simple_rule list \\<Rightarrow> (string \\<times> string) list \\<times> (string \\<times> string) list\" \n  where\n  \"access_matrix_pretty_ipv4 c rs \\<equiv>\n    if \\<not> simple_firewall_without_interfaces rs then undefined else\n    (let (V,E) = (access_matrix c rs);\n         formatted_nodes =\n              map (\\<lambda>(v_repr, v_range). (ipv4addr_toString v_repr, ipv4addr_wordinterval_toString v_range)) V;\n         formatted_edges =\n              map (\\<lambda>(s,d). (ipv4addr_toString s, ipv4addr_toString d)) E\n     in\n      (formatted_nodes, formatted_edges)\n    )\"\n\ndefinition access_matrix_pretty_ipv4_code\n  :: \"parts_connection \\<Rightarrow> 32 simple_rule list \\<Rightarrow> (string \\<times> string) list \\<times> (string \\<times> string) list\" \n  where\n  \"access_matrix_pretty_ipv4_code c rs \\<equiv>\n    if \\<not> simple_firewall_without_interfaces rs then undefined else\n    (let W = build_ip_partition c rs;\n         R = map getOneIp W;\n         U = all_pairs R\n     in\n     (zip (map ipv4addr_toString R) (map ipv4addr_wordinterval_toString W), \n      map (\\<lambda>(x,y). (ipv4addr_toString x, ipv4addr_toString y)) [(s, d)\\<leftarrow>all_pairs R. runFw s d c rs = Decision FinalAllow]))\"\n\nlemma access_matrix_pretty_ipv4_code[code]: \"access_matrix_pretty_ipv4 = access_matrix_pretty_ipv4_code\"\n  by(simp add: fun_eq_iff access_matrix_pretty_ipv4_def access_matrix_pretty_ipv4_code_def Let_def access_matrix_def map_prod_fun_zip)\n\n\ndefinition access_matrix_pretty_ipv6\n  :: \"parts_connection \\<Rightarrow> 128 simple_rule list \\<Rightarrow> (string \\<times> string) list \\<times> (string \\<times> string) list\" \n  where\n  \"access_matrix_pretty_ipv6 c rs \\<equiv>\n    if \\<not> simple_firewall_without_interfaces rs then undefined else\n    (let (V,E) = (access_matrix c rs);\n         formatted_nodes =\n              map (\\<lambda>(v_repr, v_range). (ipv6addr_toString v_repr, ipv6addr_wordinterval_toString v_range)) V;\n         formatted_edges =\n              map (\\<lambda>(s,d). (ipv6addr_toString s, ipv6addr_toString d)) E\n     in\n      (formatted_nodes, formatted_edges)\n    )\"\n\ndefinition access_matrix_pretty_ipv6_code\n  :: \"parts_connection \\<Rightarrow> 128 simple_rule list \\<Rightarrow> (string \\<times> string) list \\<times> (string \\<times> string) list\" \n  where\n  \"access_matrix_pretty_ipv6_code c rs \\<equiv>\n    if \\<not> simple_firewall_without_interfaces rs then undefined else\n    (let W = build_ip_partition c rs;\n         R = map getOneIp W;\n         U = all_pairs R\n     in\n     (zip (map ipv6addr_toString R) (map ipv6addr_wordinterval_toString W), \n      map (\\<lambda>(x,y). (ipv6addr_toString x, ipv6addr_toString y)) [(s, d)\\<leftarrow>all_pairs R. runFw s d c rs = Decision FinalAllow]))\"\n\nlemma access_matrix_pretty_ipv6_code[code]: \"access_matrix_pretty_ipv6 = access_matrix_pretty_ipv6_code\"\n  by(simp add: fun_eq_iff access_matrix_pretty_ipv6_def access_matrix_pretty_ipv6_code_def Let_def access_matrix_def map_prod_fun_zip)\n\n  \n\ndefinition parts_connection_ssh where\n  \"parts_connection_ssh \\<equiv> \\<lparr>pc_iiface=''1'', pc_oiface=''1'', pc_proto=TCP, pc_sport=10000, pc_dport=22\\<rparr>\"\n\ndefinition parts_connection_http where\n  \"parts_connection_http \\<equiv> \\<lparr>pc_iiface=''1'', pc_oiface=''1'', pc_proto=TCP, pc_sport=10000, pc_dport=80\\<rparr>\"\n\n\ndefinition mk_parts_connection_TCP :: \"16 word \\<Rightarrow> 16 word \\<Rightarrow> parts_connection\" where\n  \"mk_parts_connection_TCP sport dport = \\<lparr>pc_iiface=''1'', pc_oiface=''1'', pc_proto=TCP,\n                               pc_sport=sport, pc_dport=dport\\<rparr>\"\n\nlemma \"mk_parts_connection_TCP 10000 22 = parts_connection_ssh\"\n      \"mk_parts_connection_TCP 10000 80 = parts_connection_http\"\n  by(simp_all add: mk_parts_connection_TCP_def parts_connection_ssh_def parts_connection_http_def)\n\n\nvalue[code] \"partitioningIps [WordInterval (0::ipv4addr) 0] [WordInterval 0 2, WordInterval 0 2]\"\n\n\ntext_raw\\<open>\nHere is an example of a really large and complicated firewall:\n\n\n\\begin{figure}\n\\centering\n\\resizebox{\\linewidth}{!}{%\n\\tikzset{every loop/.style={looseness=1}}\n\\tikzset{myptr/.style={decoration={markings,mark=at position 1 with %\n    {\\arrow[scale=2,>=latex]{>}}},shorten >=0.1cm,shorten <=0.2cm, postaction={decorate}}}%\n\\tikzset{myloop/.style={-to}}%\n\\begin{tikzpicture}\n\\node (m) at (2,-2) {$\\{224.0.0.0 .. 239.255.255.255\\}$};\n\n\\node[align=left] (inet) at (-3,8.5) {$\\{0.0.0.0 .. 126.255.255.255\\} \\cup \\{128.0.0.0 .. 131.159.13.255\\} \\cup $ \\\\ \n\t\t\t\t\t\t\t\t\t $ \\{131.159.16.0 .. 131.159.19.255\\} \\cup \\{131.159.22.0 .. 138.246.253.4\\} \\cup $ \\\\ \n\t\t\t\t\t\t\t\t\t $ \\{138.246.253.11 .. 185.86.231.255\\} \\cup \\{185.86.236.0 .. 188.1.239.85\\} \\cup $ \\\\ \n\t\t\t\t\t\t\t\t\t $ \\{188.1.239.87 .. 188.95.232.63\\} \\cup \\{188.95.232.224 .. 188.95.232.255\\} \\cup $\\\\\n\t\t\t\t\t\t\t\t\t $ \\{188.95.240.0 .. 192.48.106.255\\} \\cup \\{192.48.108.0 .. 223.255.255.255\\} \\cup $\\\\\n\t\t\t\t\t\t\t\t\t $ \\{240.0.0.0 .. 255.255.255.255\\}$};\n\\node[align=left] (internal) at (-5,-10) {$\\{131.159.14.0 .. 131.159.14.7\\} \\cup \\{131.159.14.12 .. 131.159.14.25\\} \\cup $ \\\\ \n$ 131.159.14.27 \\cup \\{131.159.14.29 .. 131.159.14.33\\} \\cup $ \\\\ \n$ \\{131.159.14.38 .. 131.159.14.39\\} \\cup 131.159.14.41 \\cup $ \\\\ \n$ \\{131.159.14.43 .. 131.159.14.51\\} \\cup \\{131.159.14.53 .. 131.159.14.55\\} \\cup $ \\\\ \n$ \\{131.159.14.57 .. 131.159.14.59\\} \\cup \\{131.159.14.61 .. 131.159.14.68\\} \\cup $ \\\\ \n$ 131.159.14.70 .. 131.159.14.82\\} \\cup \\{131.159.14.84 .. 131.159.14.103\\} \\cup $ \\\\ \n$ \\{131.159.14.105 .. 131.159.14.124\\} \\cup \\{131.159.14.126 .. 131.159.14.136\\} \\cup $ \\\\  \n$ \\{131.159.14.138 .. 131.159.14.139\\} \\cup \\{131.159.14.141 .. 131.159.14.144\\} \\cup $ \\\\ \n$ \\{131.159.14.147 .. 131.159.14.154\\} \\cup \\{131.159.14.157 .. 131.159.14.162\\} \\cup $ \\\\ \n$ \\{131.159.14.164 .. 131.159.14.168\\} \\cup \\{131.159.14.170 .. 131.159.14.200\\} \\cup $ \\\\ \n$ \\{131.159.14.202 .. 131.159.14.213\\} \\cup \\{131.159.14.215 .. 131.159.15.4\\} \\cup $ \\\\ \n$ 131.159.15.6 \\cup \\{131.159.15.14 .. 131.159.15.15\\} \\cup $ \\\\ \n$ \\{131.159.15.21 .. 131.159.15.22\\} \\cup 131.159.15.26 \\cup 131.159.15.28 \\cup $ \\\\ \n$ 131.159.15.30 \\cup \\{131.159.15.33 .. 131.159.15.35\\} \\cup $ \\\\ \n$ \\{131.159.15.37 .. 131.159.15.38\\} \\cup 131.159.15.40 \\cup $ \\\\ \n$ \\{131.159.15.45 .. 131.159.15.46\\} \\cup \\{131.159.15.48 .. 131.159.15.49\\} \\cup $ \\\\ \n$ \\{131.159.15.52 .. 131.159.15.55\\} \\cup 131.159.15.57 \\cup 131.159.15.59 \\cup $ \\\\ \n$ \\{131.159.15.61 .. 131.159.15.67\\} \\cup \\{131.159.15.70 .. 131.159.15.196\\} \\cup $ \\\\ \n$ \\{131.159.15.198 .. 131.159.15.227\\} \\cup \\{131.159.15.229 .. 131.159.15.233\\} \\cup $ \\\\ \n$ \\{131.159.15.235 .. 131.159.15.246\\} \\cup \\{131.159.15.250 .. 131.159.15.255\\} \\cup $ \\\\ \n$ \\{131.159.20.0 .. 131.159.20.20\\} \\cup \\{131.159.20.22 .. 131.159.20.28\\} \\cup $ \\\\ \n$ \\{131.159.20.30 .. 131.159.20.35\\} \\cup \\{131.159.20.37 .. 131.159.20.44\\} \\cup $ \\\\ \n$ \\{131.159.20.46 .. 131.159.20.51\\} \\cup \\{131.159.20.53 .. 131.159.20.58\\} \\cup $ \\\\ \n$ \\{131.159.20.60 .. 131.159.20.62\\} \\cup \\{131.159.20.64 .. 131.159.20.70\\} \\cup $ \\\\ \n$ \\{131.159.20.72 .. 131.159.20.73\\} \\cup \\{131.159.20.75 .. 131.159.20.84\\} \\cup $ \\\\ \n$ \\{131.159.20.86 .. 131.159.20.96\\} \\cup \\{131.159.20.98 .. 131.159.20.119\\} \\cup $ \\\\ \n$ \\{131.159.20.121 .. 131.159.20.138\\} \\cup \\{131.159.20.140 .. 131.159.20.149\\} \\cup $ \\\\ \n$ \\{131.159.20.152 .. 131.159.20.154\\} \\cup \\{131.159.20.156 .. 131.159.20.159\\} \\cup $ \\\\ \n$ \\{131.159.20.161 .. 131.159.20.164\\} \\cup \\{131.159.20.167 .. 131.159.20.179\\} \\cup $ \\\\ \n$ \\{131.159.20.181 .. 131.159.20.184\\} \\cup \\{131.159.20.186 .. 131.159.20.199\\} \\cup $ \\\\ \n$ \\{131.159.20.201 .. 131.159.20.232\\} \\cup \\{131.159.20.235 .. 131.159.20.255\\} \\cup $ \\\\ \n$ \\{185.86.232.0 .. 185.86.235.255\\} \\cup \\{188.95.233.0 .. 188.95.233.3\\} \\cup $ \\\\ \n$ \\{188.95.233.5 .. 188.95.233.8\\} \\cup \\{188.95.233.10 .. 188.95.233.255\\} \\cup $ \\\\ \n$ \\{192.48.107.0 .. 192.48.107.255\\}$}; \n\n\\node[align=left] (srvs) at (10,0) {$\\{131.159.14.8 .. 131.159.14.11\\} \\cup 131.159.14.26 \\cup 131.159.14.28 \\cup $ \\\\ \n$ \\{131.159.14.34 .. 131.159.14.37\\} \\cup 131.159.14.40 \\cup 131.159.14.42 \\cup $ \\\\ \n$ 131.159.14.52 \\cup 131.159.14.56 \\cup 131.159.14.60 \\cup 131.159.14.69 \\cup $ \\\\ \n$ 131.159.14.83 \\cup 131.159.14.104 \\cup 131.159.14.125 \\cup 131.159.14.137 \\cup $ \\\\ \n$ 131.159.14.140 \\cup \\{131.159.14.145 .. 131.159.14.146\\} \\cup $ \\\\ \n$ \\{131.159.14.155 .. 131.159.14.156\\} \\cup 131.159.14.163 \\cup 131.159.14.169 \\cup $ \\\\ \n$ 131.159.14.201 \\cup 131.159.14.214 \\cup 131.159.15.5 \\cup $ \\\\ \n$ \\{131.159.15.7 .. 131.159.15.13\\} \\cup \\{131.159.15.16 .. 131.159.15.20\\} \\cup $ \\\\ \n$ \\{131.159.15.23 .. 131.159.15.25\\} \\cup 131.159.15.27 \\cup 131.159.15.29 \\cup $ \\\\ \n$ \\{131.159.15.31 .. 131.159.15.32\\} \\cup 131.159.15.36 \\cup 131.159.15.39 \\cup $ \\\\ \n$ \\{131.159.15.41 .. 131.159.15.44\\} \\cup 131.159.15.47 \\cup 131.159.15.51 \\cup $ \\\\ \n$ 131.159.15.56 \\cup 131.159.15.58 \\cup 131.159.15.60 \\cup $ \\\\ \n$ \\{131.159.15.68 .. 131.159.15.69\\} \\cup 131.159.15.197 \\cup 131.159.15.228 \\cup $ \\\\ \n$ 131.159.15.234 \\cup \\{131.159.15.247 .. 131.159.15.249\\} \\cup 131.159.20.21 \\cup $ \\\\ \n$ 131.159.20.29 \\cup 131.159.20.36 \\cup 131.159.20.45 \\cup 131.159.20.52 \\cup $ \\\\ \n$ 131.159.20.59 \\cup 131.159.20.63 \\cup 131.159.20.71 \\cup 131.159.20.74 \\cup $ \\\\ \n$ 131.159.20.85 \\cup 131.159.20.97 \\cup 131.159.20.120 \\cup 131.159.20.139 \\cup $ \\\\ \n$ \\{131.159.20.150 .. 131.159.20.151\\} \\cup 131.159.20.155 \\cup 131.159.20.160 \\cup $ \\\\ \n$ \\{131.159.20.165 .. 131.159.20.166\\} \\cup 131.159.20.180 \\cup 131.159.20.185 \\cup $ \\\\ \n$ 131.159.20.200 \\cup \\{131.159.20.233 .. 131.159.20.234\\} \\cup $ \\\\ \n$ \\{131.159.21.0 .. 131.159.21.255\\} \\cup \\{188.95.232.192 .. 188.95.232.223\\} \\cup $ \\\\ \n$ 188.95.233.4 \\cup 188.95.233.9 \\cup \\{188.95.234.0 .. 188.95.239.255\\}$}; \n\n\\node[align=left] (ips1) at (-3,-1) {$188.1.239.86 \\cup \\{188.95.232.64 .. 188.95.232.191\\}$};\n\n\\node[align=left] (ips2) at (10,-8) {$\\{138.246.253.6 .. 138.246.253.10\\}$};\n\n\\node[align=left] (ip3) at (5,-6) {$138.246.253.5$};\n\n\\node[align=left] (ip4) at (4.5,-8) {$131.159.15.50$};\n\n\\node[align=left] (l) at (8,-10) {$\\{127.0.0.0 .. 127.255.255.255\\}$};\n\n\n\n\\draw[myloop] (m) to[loop above] (m);\n\\draw[myptr] (m) to (srvs);\n\\draw[myptr] (inet) to (m);\n\\draw[myptr] (inet) to (srvs);\n\\draw[myptr,shorten <=-0.8cm] (internal) to (m);\n\\draw[myptr] (internal) to (inet);\n\\draw[myloop] (internal) to[loop above] (internal);\n\\draw[myptr] (internal) to (srvs);\n\\draw[myptr] (internal) to (ips1);\n\\draw[myptr] (internal) to (ips2);\n\\draw[myptr] (internal) to (ip3);\n\\draw[myptr] (internal) to (ip4);\n\\draw[myptr] (internal) to (l);\n\\draw[myptr] (srvs) to (m);\n\\draw[myptr] (srvs) to (inet);\n\\draw[myptr] (srvs) to (internal);\n\\draw[myloop] (srvs) to[loop above] (srvs);\n\\draw[myptr] (srvs) to (ips1);\n\\draw[myptr] (srvs) to (ips2);\n\\draw[myptr] (srvs) to (ip3);\n\\draw[myptr] (srvs) to (ip4);\n\\draw[myptr] (srvs) to (l);\n\\draw[myptr] (ips1) to (m);\n\\draw[myptr] (ips1) to (inet);\n\\draw[myptr] (ips1) to (internal);\n\\draw[myptr] (ips1) to (srvs);\n\\draw[myloop] (ips1.west) to[loop left] (ips1);\n\\draw[myptr] (ips1) to (ips2);\n\\draw[myptr] (ips1) to (ip3);\n\\draw[myptr] (ips1) to (ip4);\n\\draw[myptr] (ips1) to (l);\n\\draw[myptr] (ips2) to (m);\n\\draw[myptr] (ips2) to (srvs);\n\\draw[myptr] (ips2) to (ip4);\n\\draw[myptr] (ip3) to (m);\n\\draw[myptr] (ip3) to (internal);\n\\draw[myptr] (ip3) to (srvs);\n\\draw[myptr] (ip3) to (ip4);\n\\draw[myptr] (ip4) to (m);\n\\draw[myptr] (ip4) to (inet);\n\\draw[myptr] (ip4) to (internal);\n\\draw[myptr] (ip4) to (srvs);\n\\draw[myptr] (ip4) to (ips1);\n\\draw[myptr] (ip4) to (ips2);\n\\draw[myptr] (ip4) to (ip3);\n\\draw[myloop] (ip4) to[loop below] (ip4);\n\\draw[myptr] (ip4) to (l);\n\n\\end{tikzpicture}%\n}\n\\caption{TUM ssh Service Matrix}\n\\label{fig:tumssh}\n\\end{figure}\n\n\\<close>\n\n\nend                            \n", "meta": {"author": "diekmann", "repo": "Iptables_Semantics", "sha": "e0a2516bd885708fce875023b474ae341cbdee29", "save_path": "github-repos/isabelle/diekmann-Iptables_Semantics", "path": "github-repos/isabelle/diekmann-Iptables_Semantics/Iptables_Semantics-e0a2516bd885708fce875023b474ae341cbdee29/thy/Simple_Firewall/Service_Matrix.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953651858117, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.255064113699008}}
{"text": "theory Simulation_Graphs_TA\n  imports Simulation_Graphs DBM_Zone_Semantics Approx_Beta\nbegin\n\nsection \\<open>Instantiation of Simulation Locales\\<close>\n\ninductive step_trans ::\n  \"('a, 'c, 't, 's) ta \\<Rightarrow> 's \\<Rightarrow> ('c, ('t::time)) cval \\<Rightarrow> (('c, 't) cconstraint \\<times> 'a \\<times> 'c list)\n  \\<Rightarrow> 's \\<Rightarrow> ('c, 't) cval \\<Rightarrow> bool\"\n(\"_ \\<turnstile>\\<^sub>t \\<langle>_, _\\<rangle> \\<rightarrow>\\<^bsub>_\\<^esub> \\<langle>_, _\\<rangle>\" [61,61,61] 61)\nwhere\n  \"\\<lbrakk>A \\<turnstile> l \\<longrightarrow>\\<^bsup>g,a,r\\<^esup> l'; u \\<turnstile> g; u' \\<turnstile> inv_of A l'; u' = [r \\<rightarrow> 0]u\\<rbrakk>\n  \\<Longrightarrow> (A \\<turnstile>\\<^sub>t \\<langle>l, u\\<rangle> \\<rightarrow>\\<^bsub>(g,a,r)\\<^esub> \\<langle>l', u'\\<rangle>)\"\n\ninductive step_trans' ::\n  \"('a, 'c, 't, 's) ta \\<Rightarrow> 's \\<Rightarrow> ('c, ('t::time)) cval \\<Rightarrow> ('c, 't) cconstraint \\<times> 'a \\<times> 'c list\n  \\<Rightarrow> 's \\<Rightarrow> ('c, 't) cval \\<Rightarrow> bool\"\n(\"_ \\<turnstile>'' \\<langle>_, _\\<rangle> \\<rightarrow>\\<^bsup>_\\<^esup> \\<langle>_, _\\<rangle>\" [61,61,61,61] 61)\nwhere\n  step': \"A \\<turnstile> \\<langle>l, u\\<rangle> \\<rightarrow>\\<^bsup>d\\<^esup> \\<langle>l', u'\\<rangle> \\<Longrightarrow> A \\<turnstile>\\<^sub>t \\<langle>l', u'\\<rangle> \\<rightarrow>\\<^bsub>t\\<^esub> \\<langle>l'', u''\\<rangle> \\<Longrightarrow> A \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow>\\<^bsup>t\\<^esup> \\<langle>l'', u''\\<rangle>\"\n\ninductive step_trans_z ::\n  \"('a, 'c, 't, 's) ta \\<Rightarrow> 's \\<Rightarrow> ('c, ('t::time)) zone\n  \\<Rightarrow> (('c, 't) cconstraint \\<times> 'a \\<times> 'c list) action \\<Rightarrow> 's \\<Rightarrow> ('c, 't) zone \\<Rightarrow> bool\"\n(\"_ \\<turnstile> \\<langle>_, _\\<rangle> \\<leadsto>\\<^bsup>_\\<^esup> \\<langle>_, _\\<rangle>\" [61,61,61,61] 61)\nwhere\n  step_trans_t_z:\n  \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>\\<tau>\\<^esup> \\<langle>l, Z\\<^sup>\\<up> \\<inter> {u. u \\<turnstile> inv_of A l}\\<rangle>\" |\n  step_trans_a_z:\n  \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>\\<upharpoonleft>(g,a,r)\\<^esup> \\<langle>l', zone_set (Z \\<inter> {u. u \\<turnstile> g}) r \\<inter> {u. u \\<turnstile> inv_of A l'}\\<rangle>\"\n  if \"A \\<turnstile> l \\<longrightarrow>\\<^bsup>g,a,r\\<^esup> l'\"\n\ninductive step_trans_z' ::\n  \"('a, 'c, 't, 's) ta \\<Rightarrow> 's \\<Rightarrow> ('c, ('t::time)) zone \\<Rightarrow> (('c, 't) cconstraint \\<times> 'a \\<times> 'c list)\n  \\<Rightarrow> 's \\<Rightarrow> ('c, 't) zone \\<Rightarrow> bool\"\n(\"_ \\<turnstile>'' \\<langle>_, _\\<rangle> \\<leadsto>\\<^bsup>_\\<^esup> \\<langle>_, _\\<rangle>\" [61,61,61,61] 61)\nwhere\n  step_trans_z':\n  \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>\\<tau>\\<^esup> \\<langle>l, Z'\\<rangle> \\<Longrightarrow> A \\<turnstile> \\<langle>l, Z'\\<rangle> \\<leadsto>\\<^bsup>\\<upharpoonleft>t\\<^esup> \\<langle>l', Z''\\<rangle> \\<Longrightarrow> A \\<turnstile>' \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>t\\<^esup> \\<langle>l', Z''\\<rangle>\"\n\nlemmas [intro] =\n  step_trans.intros\n  step_trans'.intros\n  step_trans_z.intros\n  step_trans_z'.intros\n\ncontext\n  notes [elim!]  =\n    step.cases step_t.cases\n    step_trans.cases step_trans'.cases step_trans_z.cases step_trans_z'.cases\nbegin\n\nlemma step_trans_t_z_sound:\n  \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>\\<tau>\\<^esup> \\<langle>l',Z'\\<rangle> \\<Longrightarrow> \\<forall> u' \\<in> Z'. \\<exists> u \\<in> Z. \\<exists> d.  A \\<turnstile> \\<langle>l, u\\<rangle> \\<rightarrow>\\<^bsup>d\\<^esup> \\<langle>l',u'\\<rangle>\"\n  by (auto 4 5 simp: zone_delay_def zone_set_def)\n\nlemma step_trans_a_z_sound:\n  \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>\\<upharpoonleft>t\\<^esup> \\<langle>l',Z'\\<rangle> \\<Longrightarrow> \\<forall> u' \\<in> Z'. \\<exists> u \\<in> Z. \\<exists> d.  A \\<turnstile>\\<^sub>t \\<langle>l, u\\<rangle> \\<rightarrow>\\<^bsub>t\\<^esub> \\<langle>l',u'\\<rangle>\"\n  by (auto 4 4 simp: zone_delay_def zone_set_def)\n\nlemma step_trans_a_z_complete:\n  \"A \\<turnstile>\\<^sub>t \\<langle>l, u\\<rangle> \\<rightarrow>\\<^bsub>t\\<^esub> \\<langle>l', u'\\<rangle> \\<Longrightarrow> u \\<in> Z \\<Longrightarrow> \\<exists> Z'. A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>\\<upharpoonleft>t\\<^esup> \\<langle>l', Z'\\<rangle> \\<and> u' \\<in> Z'\"\n  by (auto 4 4 simp: zone_delay_def zone_set_def elim!: step_a.cases)\n\nlemma step_trans_t_z_complete:\n  \"A \\<turnstile> \\<langle>l, u\\<rangle> \\<rightarrow>\\<^bsup>d\\<^esup> \\<langle>l', u'\\<rangle> \\<Longrightarrow> u \\<in> Z \\<Longrightarrow> \\<exists> Z'. A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>\\<tau>\\<^esup> \\<langle>l', Z'\\<rangle> \\<and> u' \\<in> Z'\"\n  by (auto 4 4 simp: zone_delay_def zone_set_def elim!: step_a.cases)\n\nlemma step_trans_t_z_iff:\n  \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>\\<tau>\\<^esup> \\<langle>l', Z'\\<rangle> = A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsub>\\<tau>\\<^esub> \\<langle>l', Z'\\<rangle>\"\n  by auto\n\n\n\nlemma step_trans_a_z_exact:\n  \"u' \\<in> Z'\" if \"A \\<turnstile>\\<^sub>t \\<langle>l, u\\<rangle> \\<rightarrow>\\<^bsub>t\\<^esub> \\<langle>l', u'\\<rangle>\" \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>\\<upharpoonleft>t\\<^esup> \\<langle>l', Z'\\<rangle>\" \"u \\<in> Z\"\n  using that by (auto 4 4 simp: zone_delay_def zone_set_def)\n\nlemma step_trans_t_z_exact:\n  \"u' \\<in> Z'\" if \"A \\<turnstile> \\<langle>l, u\\<rangle> \\<rightarrow>\\<^bsup>d\\<^esup> \\<langle>l', u'\\<rangle>\" \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>\\<tau>\\<^esup> \\<langle>l', Z'\\<rangle>\" \"u \\<in> Z\"\n  using that by (auto simp: zone_delay_def)\n\nlemma step_trans_z'_exact:\n  \"u' \\<in> Z'\" if \"A \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow>\\<^bsup>t\\<^esup> \\<langle>l', u'\\<rangle>\" \"A \\<turnstile>' \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>t\\<^esup> \\<langle>l', Z'\\<rangle>\" \"u \\<in> Z\"\n  using that by (auto 4 4 simp: zone_delay_def zone_set_def)\n\nlemma step_trans_z_step_z_action:\n  \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsub>\\<upharpoonleft>a\\<^esub> \\<langle>l',Z'\\<rangle>\" if \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>\\<upharpoonleft>(g,a,r)\\<^esup> \\<langle>l', Z'\\<rangle>\"\n  using that by auto\n\nlemma step_trans_z_step_z:\n  \"\\<exists> a. A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsub>a\\<^esub> \\<langle>l',Z'\\<rangle>\" if \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>t\\<^esup> \\<langle>l', Z'\\<rangle>\"\n  using that by auto\n\nlemma step_z_step_trans_z_action:\n  \"\\<exists> g r. A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>\\<upharpoonleft>(g,a,r)\\<^esup> \\<langle>l', Z'\\<rangle>\" if \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsub>\\<upharpoonleft>a\\<^esub> \\<langle>l',Z'\\<rangle>\"\n  using that by (auto 4 4)\n\nlemma step_z_step_trans_z:\n  \"\\<exists> t. A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>t\\<^esup> \\<langle>l', Z'\\<rangle>\" if \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsub>a\\<^esub> \\<langle>l',Z'\\<rangle>\"\n  using that by cases auto\n\nend (* Automation *)\n\nlemma step_z'_step_trans_z':\n  \"\\<exists> t. A \\<turnstile>' \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>t\\<^esup> \\<langle>l', Z''\\<rangle>\" if \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto> \\<langle>l', Z''\\<rangle>\"\n  using that unfolding step_z'_def\n  by (auto dest!: step_z_step_trans_z_action simp: step_trans_t_z_iff[symmetric])\n\nlemma step_trans_z'_step_z':\n  \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto> \\<langle>l', Z''\\<rangle>\" if \"A \\<turnstile>' \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>t\\<^esup> \\<langle>l', Z''\\<rangle>\"\n  using that unfolding step_z'_def\n  by (auto elim!: step_trans_z'.cases dest!: step_trans_z_step_z_action simp: step_trans_t_z_iff)\n\nlemma step_trans_z_determ:\n  \"Z1 = Z2\" if \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>t\\<^esup> \\<langle>l', Z1\\<rangle>\" \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>t\\<^esup> \\<langle>l', Z2\\<rangle>\"\n  using that by (auto elim!: step_trans_z.cases)\n\nlemma step_trans_z'_determ:\n  \"Z1 = Z2\" if \"A \\<turnstile>' \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>t\\<^esup> \\<langle>l', Z1\\<rangle>\" \"A \\<turnstile>' \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>t\\<^esup> \\<langle>l', Z2\\<rangle>\"\n  using that by (auto elim!: step_trans_z'.cases step_trans_z.cases)\n\nlemma (in Alpha_defs) step_trans_z_V: \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>t\\<^esup> \\<langle>l',Z'\\<rangle> \\<Longrightarrow> Z \\<subseteq> V \\<Longrightarrow> Z' \\<subseteq> V\"\n  by (induction rule: step_trans_z.induct; blast intro!: reset_V le_infI1 up_V)\n\nsubsection \\<open>Additional Lemmas on Regions\\<close>\n\ncontext AlphaClosure\nbegin\n\ninductive step_trans_r ::\n  \"('a, 'c, t, 's) ta \\<Rightarrow> _ \\<Rightarrow> 's \\<Rightarrow> ('c, t) zone \\<Rightarrow> (('c, t) cconstraint \\<times> 'a \\<times> 'c list) action\n  \\<Rightarrow> 's \\<Rightarrow> ('c, t) zone \\<Rightarrow> bool\"\n(\"_,_ \\<turnstile> \\<langle>_, _\\<rangle> \\<leadsto>\\<^bsup>_\\<^esup> \\<langle>_, _\\<rangle>\" [61,61,61,61,61] 61)\nwhere\n  step_trans_t_r:\n  \"A,\\<R> \\<turnstile> \\<langle>l,R\\<rangle> \\<leadsto>\\<^bsup>\\<tau>\\<^esup> \\<langle>l,R'\\<rangle>\" if\n  \"valid_abstraction A X (\\<lambda> x. real o k x)\" \"R \\<in> \\<R> l\" \"R' \\<in> Succ (\\<R> l) R\" \"R' \\<subseteq> \\<lbrace>inv_of A l\\<rbrace>\" |\n  step_trans_a_r:\n  \"A,\\<R> \\<turnstile> \\<langle>l,R\\<rangle> \\<leadsto>\\<^bsup>\\<upharpoonleft>(g,a,r)\\<^esup> \\<langle>l', R'\\<rangle>\" if\n  \"valid_abstraction A X (\\<lambda> x. real o k x)\" \"A \\<turnstile> l \\<longrightarrow>\\<^bsup>g,a,r\\<^esup> l'\" \"R \\<in> \\<R> l\"\n  \"R \\<subseteq> \\<lbrace>g\\<rbrace>\" \"region_set' R r 0 \\<subseteq> R'\" \"R' \\<subseteq> \\<lbrace>inv_of A l'\\<rbrace>\" \"R' \\<in> \\<R> l'\"\n\nlemmas [intro] = step_trans_r.intros\n\nlemma step_trans_t_r_iff[simp]:\n  \"A,\\<R> \\<turnstile> \\<langle>l,R\\<rangle> \\<leadsto>\\<^bsup>\\<tau>\\<^esup> \\<langle>l',R'\\<rangle> = A,\\<R> \\<turnstile> \\<langle>l,R\\<rangle> \\<leadsto>\\<^bsub>\\<tau>\\<^esub> \\<langle>l',R'\\<rangle>\"\n  by (auto elim!: step_trans_r.cases)\n\nlemma step_trans_r_step_r_action:\n  \"A,\\<R> \\<turnstile> \\<langle>l,R\\<rangle> \\<leadsto>\\<^bsub>\\<upharpoonleft>a\\<^esub> \\<langle>l',R'\\<rangle>\" if \"A,\\<R> \\<turnstile> \\<langle>l,R\\<rangle> \\<leadsto>\\<^bsup>\\<upharpoonleft>(g,a,r)\\<^esup> \\<langle>l',R'\\<rangle>\"\n  using that by (auto elim: step_trans_r.cases)\n\nlemma step_r_step_trans_r_action:\n  \"\\<exists> g r. A,\\<R> \\<turnstile> \\<langle>l,R\\<rangle> \\<leadsto>\\<^bsup>\\<upharpoonleft>(g,a,r)\\<^esup> \\<langle>l',R'\\<rangle>\" if \"A,\\<R> \\<turnstile> \\<langle>l,R\\<rangle> \\<leadsto>\\<^bsub>\\<upharpoonleft>a\\<^esub> \\<langle>l',R'\\<rangle>\"\n  using that by (auto elim: step_trans_r.cases)\n\ninductive step_trans_r' ::\n  \"('a, 'c, t, 's) ta \\<Rightarrow> _ \\<Rightarrow> 's \\<Rightarrow> ('c, t) zone \\<Rightarrow> ('c, t) cconstraint \\<times> 'a \\<times> 'c list\n  \\<Rightarrow> 's \\<Rightarrow> ('c, t) zone \\<Rightarrow> bool\"\n(\"_,_ \\<turnstile>'' \\<langle>_, _\\<rangle> \\<leadsto>\\<^bsup>_\\<^esup> \\<langle>_, _\\<rangle>\" [61,61,61,61,61] 61)\nwhere\n  \"A,\\<R> \\<turnstile>' \\<langle>l,R\\<rangle> \\<leadsto>\\<^bsup>t\\<^esup> \\<langle>l',R''\\<rangle>\" if \"A,\\<R> \\<turnstile> \\<langle>l,R\\<rangle> \\<leadsto>\\<^bsup>\\<tau>\\<^esup> \\<langle>l,R'\\<rangle>\" \"A,\\<R> \\<turnstile> \\<langle>l,R'\\<rangle> \\<leadsto>\\<^bsup>\\<upharpoonleft>t\\<^esup> \\<langle>l', R''\\<rangle>\"\n\nlemma step_trans_r'_step_r':\n  \"A,\\<R> \\<turnstile> \\<langle>l,R\\<rangle> \\<leadsto>\\<^sub>a \\<langle>l',R'\\<rangle>\" if \"A,\\<R> \\<turnstile>' \\<langle>l,R\\<rangle> \\<leadsto>\\<^bsup>(g,a,r)\\<^esup> \\<langle>l',R'\\<rangle>\"\n  using that by cases (auto dest: step_trans_r_step_r_action intro!: step_r'.intros)\n\nlemma step_r'_step_trans_r':\n  \"\\<exists> g r. A,\\<R> \\<turnstile>' \\<langle>l,R\\<rangle> \\<leadsto>\\<^bsup>(g,a,r)\\<^esup> \\<langle>l',R'\\<rangle>\" if \"A,\\<R> \\<turnstile> \\<langle>l,R\\<rangle> \\<leadsto>\\<^sub>a \\<langle>l',R'\\<rangle>\"\n  using that by cases (auto dest: step_r_step_trans_r_action intro!: step_trans_r'.intros)\n\nlemma step_trans_a_r_sound:\n  assumes \"A,\\<R> \\<turnstile> \\<langle>l, R\\<rangle> \\<leadsto>\\<^bsup>\\<upharpoonleft>a\\<^esup> \\<langle>l',R'\\<rangle>\"\n  shows \"\\<forall> u \\<in> R. \\<exists> u' \\<in> R'. A \\<turnstile>\\<^sub>t \\<langle>l, u\\<rangle> \\<rightarrow>\\<^bsub>a\\<^esub> \\<langle>l',u'\\<rangle>\"\nusing assms proof cases\n  case A: (step_trans_a_r g a r)\n  show ?thesis\n  unfolding A(1) proof\n    fix u assume \"u \\<in> R\"\n    from \\<open>u \\<in> R\\<close> A have \"u \\<turnstile> g\" \"[r\\<rightarrow>0]u \\<turnstile> inv_of A l'\" \"[r\\<rightarrow>0]u \\<in> R'\"\n      unfolding region_set'_def ccval_def by auto\n    with A show \"\\<exists>u'\\<in>R'. A \\<turnstile>\\<^sub>t \\<langle>l, u\\<rangle> \\<rightarrow>\\<^bsub>(g,a,r)\\<^esub> \\<langle>l',u'\\<rangle>\"\n      by auto\n  qed\nqed\n\nlemma step_trans_r'_sound:\n  assumes \"A,\\<R> \\<turnstile>' \\<langle>l, R\\<rangle> \\<leadsto>\\<^bsup>t\\<^esup> \\<langle>l', R'\\<rangle>\"\n  shows \"\\<forall>u\\<in>R. \\<exists>u'\\<in>R'. A \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow>\\<^bsup>t\\<^esup> \\<langle>l', u'\\<rangle>\"\n  using assms by cases (auto 6 0 dest!: step_trans_a_r_sound step_t_r_sound)\n\nend (* Alpha Closure *)\n\ncontext AlphaClosure\nbegin\n\ncontext\n  fixes l l' :: 's and A :: \"('a, 'c, t, 's) ta\"\n  assumes valid_abstraction: \"valid_abstraction A X k\"\nbegin\n\ninterpretation alpha: AlphaClosure_global _ \"k l\" \"\\<R> l\" by standard (rule finite)\n\n\ninterpretation alpha': AlphaClosure_global _ \"k l'\" \"\\<R> l'\" by standard (rule finite)\nlemma [simp]: \"alpha'.cla = cla l'\" unfolding alpha'.cla_def cla_def ..\n\nlemma regions_poststable1:\n  assumes\n    \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>a\\<^esup> \\<langle>l',Z'\\<rangle>\" \"Z \\<subseteq> V\" \"R' \\<in> \\<R> l'\" \"R' \\<inter> Z' \\<noteq> {}\"\n  shows \"\\<exists> R \\<in> \\<R> l. A,\\<R> \\<turnstile> \\<langle>l,R\\<rangle> \\<leadsto>\\<^bsup>a\\<^esup> \\<langle>l',R'\\<rangle> \\<and> R \\<inter> Z \\<noteq> {}\"\nusing assms proof (induction A \\<equiv> A l \\<equiv> l _ _ l' \\<equiv> l' _rule: step_trans_z.induct)\n  case A: (step_trans_t_z Z)\n  from \\<open>R' \\<inter> (Z\\<^sup>\\<up> \\<inter> {u. u \\<turnstile> inv_of A l}) \\<noteq> {}\\<close> obtain u d where u:\n    \"u \\<in> Z\" \"u \\<oplus> d \\<in> R'\" \"u \\<oplus> d \\<turnstile> inv_of A l\" \"0 \\<le> d\"\n    unfolding zone_delay_def by blast+\n  with alpha.closure_subs[OF A(2)] obtain R where R1: \"u \\<in> R\" \"R \\<in> \\<R> l\"\n    by (simp add: cla_def) blast\n  from \\<open>Z \\<subseteq> V\\<close> \\<open>u \\<in> Z\\<close> have \"\\<forall>x\\<in>X. 0 \\<le> u x\" unfolding V_def by fastforce\n  from region_cover'[OF this] have R: \"[u]\\<^sub>l \\<in> \\<R> l\" \"u \\<in> [u]\\<^sub>l\" by auto\n  from SuccI2[OF \\<R>_def' this(2,1) \\<open>0 \\<le> d\\<close> HOL.refl] u(2) have v'1:\n    \"[u \\<oplus> d]\\<^sub>l \\<in> Succ (\\<R> l) ([u]\\<^sub>l)\" \"[u \\<oplus> d]\\<^sub>l \\<in> \\<R> l\"\n    by auto\n  from alpha.regions_closed'_spec[OF R(1,2) \\<open>0 \\<le> d\\<close>] have v'2: \"u \\<oplus> d \\<in> [u \\<oplus> d]\\<^sub>l\" by simp\n  from valid_abstraction have\n    \"\\<forall>(x, m)\\<in>clkp_set A l. m \\<le> real (k l x) \\<and> x \\<in> X \\<and> m \\<in> \\<nat>\"\n    by (auto elim!: valid_abstraction.cases)\n  then have\n    \"\\<forall>(x, m)\\<in>collect_clock_pairs (inv_of A l). m \\<le> real (k l x) \\<and> x \\<in> X \\<and> m \\<in> \\<nat>\"\n    unfolding clkp_set_def collect_clki_def inv_of_def by fastforce\n  from ccompatible[OF this, folded \\<R>_def'] v'1(2) v'2 u(2,3) have\n    \"[u \\<oplus> d]\\<^sub>l \\<subseteq> \\<lbrace>inv_of A l\\<rbrace>\"\n    unfolding ccompatible_def ccval_def by auto\n  from\n    alpha.valid_regions_distinct_spec[OF v'1(2) _ v'2 \\<open>u \\<oplus> d \\<in> R'\\<close>] \\<open>R' \\<in> _\\<close> \\<open>l = l'\\<close>\n    alpha.region_unique_spec[OF R1]\n  have \"[u \\<oplus> d]\\<^sub>l = R'\" \"[u]\\<^sub>l = R\" by auto\n  from valid_abstraction \\<open>R \\<in> _\\<close> \\<open>_ \\<in> Succ (\\<R> l) _\\<close> \\<open>_ \\<subseteq> \\<lbrace>inv_of A l\\<rbrace>\\<close> have\n    \"A,\\<R> \\<turnstile> \\<langle>l, R\\<rangle> \\<leadsto>\\<^bsub>\\<tau>\\<^esub> \\<langle>l, R'\\<rangle>\"\n    by (auto simp: comp_def \\<open>[u \\<oplus> d]\\<^sub>l = R'\\<close> \\<open>_ = R\\<close>)\n  with \\<open>l = l'\\<close> \\<open>R \\<in> _\\<close> \\<open>u \\<in> R\\<close> \\<open>u \\<in> Z\\<close> show ?case by - (rule bexI[where x = R]; auto)\nnext\n  case A: (step_trans_a_z g a r Z)\n  from A(4) obtain u v' where\n    \"u \\<in> Z\" and v': \"v' = [r\\<rightarrow>0]u\" \"u \\<turnstile> g\" \"v' \\<turnstile> inv_of A l'\" \"v' \\<in> R'\"\n    unfolding zone_set_def by blast\n  from \\<open>u \\<in> Z\\<close> alpha.closure_subs[OF A(2)] A(1) obtain u' R where u':\n    \"u \\<in> R\" \"u' \\<in> R\" \"R \\<in> \\<R> l\"\n    by (simp add: cla_def) blast\n  then have \"\\<forall>x\\<in>X. 0 \\<le> u x\" unfolding \\<R>_def by fastforce\n  from region_cover'[OF this] have \"[u]\\<^sub>l \\<in> \\<R> l\" \"u \\<in> [u]\\<^sub>l\" by auto\n  have *:\n    \"[u]\\<^sub>l \\<subseteq> \\<lbrace>g\\<rbrace>\" \"region_set' ([u]\\<^sub>l) r 0 \\<subseteq> [[r\\<rightarrow>0]u]\\<^sub>l'\"\n    \"[[r\\<rightarrow>0]u]\\<^sub>l' \\<in> \\<R> l'\" \"[[r\\<rightarrow>0]u]\\<^sub>l' \\<subseteq> \\<lbrace>inv_of A l'\\<rbrace>\"\n  proof -\n    from valid_abstraction have \"collect_clkvt (trans_of A) \\<subseteq> X\"\n      \"\\<forall> l g a r l' c. A \\<turnstile> l \\<longrightarrow>\\<^bsup>g,a,r\\<^esup> l' \\<and> c \\<notin> set r \\<longrightarrow> k l' c \\<le> k l c\"\n      by (auto elim: valid_abstraction.cases)\n    with A(1) have \"set r \\<subseteq> X\" \"\\<forall>y. y \\<notin> set r \\<longrightarrow> k l' y \\<le> k l y\"\n      unfolding collect_clkvt_def by (auto 4 8)\n    with\n      region_set_subs[\n        of _ X \"k l\" _ 0, where k' = \"k l'\", folded \\<R>_def, OF \\<open>[u]\\<^sub>l \\<in> \\<R> l\\<close> \\<open>u \\<in> [u]\\<^sub>l\\<close> finite\n        ]\n    show \"region_set' ([u]\\<^sub>l) r 0 \\<subseteq> [[r\\<rightarrow>0]u]\\<^sub>l'\" \"[[r\\<rightarrow>0]u]\\<^sub>l' \\<in> \\<R> l'\" by auto\n    from valid_abstraction have *:\n      \"\\<forall>l. \\<forall>(x, m)\\<in>clkp_set A l. m \\<le> real (k l x) \\<and> x \\<in> X \\<and> m \\<in> \\<nat>\"\n      by (fastforce elim: valid_abstraction.cases)+\n    with A(1) have \"\\<forall>(x, m)\\<in>collect_clock_pairs g. m \\<le> real (k l x) \\<and> x \\<in> X \\<and> m \\<in> \\<nat>\"\n      unfolding clkp_set_def collect_clkt_def by fastforce\n    from \\<open>u \\<in> [u]\\<^sub>l\\<close> \\<open>[u]\\<^sub>l \\<in> \\<R> l\\<close> ccompatible[OF this, folded \\<R>_def] \\<open>u \\<turnstile> g\\<close> show \"[u]\\<^sub>l \\<subseteq> \\<lbrace>g\\<rbrace>\"\n      unfolding ccompatible_def ccval_def by blast\n    have **: \"[r\\<rightarrow>0]u \\<in> [[r\\<rightarrow>0]u]\\<^sub>l'\"\n      using \\<open>R' \\<in> \\<R> l'\\<close> \\<open>v' \\<in> R'\\<close> alpha'.region_unique_spec v'(1) by blast\n    from * have\n      \"\\<forall>(x, m)\\<in>collect_clock_pairs (inv_of A l'). m \\<le> real (k l' x) \\<and> x \\<in> X \\<and> m \\<in> \\<nat>\"\n      unfolding inv_of_def clkp_set_def collect_clki_def by fastforce\n    from ** \\<open>[[r\\<rightarrow>0]u]\\<^sub>l' \\<in> \\<R> l'\\<close> ccompatible[OF this, folded \\<R>_def] \\<open>v' \\<turnstile> _\\<close> show\n      \"[[r\\<rightarrow>0]u]\\<^sub>l' \\<subseteq> \\<lbrace>inv_of A l'\\<rbrace>\"\n      unfolding ccompatible_def ccval_def \\<open>v' = _\\<close> by blast\n  qed\n  from * \\<open>v' = _\\<close> \\<open>u \\<in> [u]\\<^sub>l\\<close> have \"v' \\<in> [[r\\<rightarrow>0]u]\\<^sub>l'\" unfolding region_set'_def by auto\n  from alpha'.valid_regions_distinct_spec[OF *(3) \\<open>R' \\<in> \\<R> l'\\<close> \\<open>v' \\<in> [[r\\<rightarrow>0]u]\\<^sub>l'\\<close> \\<open>v' \\<in> R'\\<close>]\n  have \"[[r\\<rightarrow>0]u]\\<^sub>l' = R'\" .\n  from alpha.region_unique_spec[OF u'(1,3)] have \"[u]\\<^sub>l = R\" by auto\n  from A valid_abstraction \\<open>R \\<in> _\\<close> * have \"A,\\<R> \\<turnstile> \\<langle>l, R\\<rangle> \\<leadsto>\\<^bsup>\\<upharpoonleft>(g,a,r)\\<^esup> \\<langle>l', R'\\<rangle>\"\n    by (auto simp: comp_def \\<open>_ = R'\\<close> \\<open>_ = R\\<close>)\n  with \\<open>R \\<in> _\\<close> \\<open>u \\<in> R\\<close> \\<open>u \\<in> Z\\<close> show ?case by - (rule bexI[where x = R]; auto)\nqed\n\nlemma regions_poststable':\n  assumes\n    \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsub>a\\<^esub> \\<langle>l',Z'\\<rangle>\" \"Z \\<subseteq> V\" \"R' \\<in> \\<R> l'\" \"R' \\<inter> Z' \\<noteq> {}\"\n  shows \"\\<exists> R \\<in> \\<R> l. A,\\<R> \\<turnstile> \\<langle>l,R\\<rangle> \\<leadsto>\\<^bsub>a\\<^esub> \\<langle>l',R'\\<rangle> \\<and> R \\<inter> Z \\<noteq> {}\"\n  using assms\n  by (cases a)\n     (auto dest!: regions_poststable1 dest: step_trans_r_step_r_action step_z_step_trans_z_action\n           simp: step_trans_t_z_iff[symmetric]\n     )\n\nend (* End of context for fixed locations *)\n\nlemma regions_poststable2:\n  assumes valid_abstraction: \"valid_abstraction A X k\"\n  and prems: \"A \\<turnstile>' \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>a\\<^esup> \\<langle>l',Z'\\<rangle>\" \"Z \\<subseteq> V\" \"R' \\<in> \\<R> l'\" \"R' \\<inter> Z' \\<noteq> {}\"\n    shows \"\\<exists> R \\<in> \\<R> l. A,\\<R> \\<turnstile>' \\<langle>l,R\\<rangle> \\<leadsto>\\<^bsup>a\\<^esup> \\<langle>l',R'\\<rangle> \\<and> R \\<inter> Z \\<noteq> {}\"\nusing prems(1) proof (cases)\n  case steps: (step_trans_z' Z1)\n  with prems have \"Z1 \\<subseteq> V\"\n    by (blast dest: step_trans_z_V)\n  from regions_poststable1[OF valid_abstraction steps(2) \\<open>Z1 \\<subseteq> V\\<close> prems(3,4)] obtain R1 where R1:\n    \"R1 \\<in> \\<R> l\" \"A,\\<R> \\<turnstile> \\<langle>l, R1\\<rangle> \\<leadsto>\\<^bsup>\\<upharpoonleft>a\\<^esup> \\<langle>l', R'\\<rangle>\" \"R1 \\<inter> Z1 \\<noteq> {}\"\n    by auto\n  from regions_poststable1[OF valid_abstraction steps(1) \\<open>Z \\<subseteq> V\\<close> R1(1,3)] obtain R where\n    \"R\\<in>\\<R> l\" \"A,\\<R> \\<turnstile> \\<langle>l, R\\<rangle> \\<leadsto>\\<^bsup>\\<tau>\\<^esup> \\<langle>l, R1\\<rangle>\" \"R \\<inter> Z \\<noteq> {}\"\n    by auto\n  with R1(2) show ?thesis\n    by (auto intro: step_trans_r'.intros)\nqed\n\ntext \\<open>\n  Poststability of Closures:\n  For every transition in the zone graph and each region in the closure of the resulting zone,\n  there exists a similar transition in the region graph.\n\\<close>\nlemma regions_poststable:\n  assumes valid_abstraction: \"valid_abstraction A X k\"\n  and A:\n    \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsub>\\<tau>\\<^esub> \\<langle>l',Z'\\<rangle>\" \"A \\<turnstile> \\<langle>l', Z'\\<rangle> \\<leadsto>\\<^bsub>\\<upharpoonleft>a\\<^esub> \\<langle>l'',Z''\\<rangle>\"\n    \"Z \\<subseteq> V\" \"R'' \\<in> \\<R> l''\" \"R'' \\<inter> Z'' \\<noteq> {}\"\n  shows \"\\<exists> R \\<in> \\<R> l. A,\\<R> \\<turnstile> \\<langle>l,R\\<rangle> \\<leadsto>\\<^sub>a \\<langle>l'',R''\\<rangle> \\<and> R \\<inter> Z \\<noteq> {}\"\nproof -\n  from A(1) \\<open>Z \\<subseteq> V\\<close> have \"Z' \\<subseteq> V\" by (rule step_z_V)\n  from A(1) have [simp]: \"l' = l\" by auto\n  from regions_poststable'[OF valid_abstraction A(2) \\<open>Z' \\<subseteq> V\\<close> \\<open>R'' \\<in> _\\<close> \\<open>R'' \\<inter> Z'' \\<noteq> {}\\<close>] obtain R'\n    where R': \"R'\\<in>\\<R> l'\" \"A,\\<R> \\<turnstile> \\<langle>l', R'\\<rangle> \\<leadsto>\\<^bsub>\\<upharpoonleft>a\\<^esub> \\<langle>l'', R''\\<rangle>\" \"R' \\<inter> Z' \\<noteq> {}\"\n    by auto\n  from regions_poststable'[OF valid_abstraction A(1) \\<open>Z \\<subseteq> V\\<close> R'(1,3)] obtain R where\n    \"R \\<in> \\<R> l\" \"A,\\<R> \\<turnstile> \\<langle>l, R\\<rangle> \\<leadsto>\\<^bsub>\\<tau>\\<^esub> \\<langle>l, R'\\<rangle>\" \"R \\<inter> Z \\<noteq> {}\"\n    by auto\n  with R'(2) show ?thesis by - (rule bexI[where x = \"R\"]; auto intro: step_r'.intros)\nqed\n\nlemma step_t_r_loc:\n  \"l' = l\" if \"A,\\<R> \\<turnstile> \\<langle>l, R\\<rangle> \\<leadsto>\\<^bsub>\\<tau>\\<^esub> \\<langle>l', R'\\<rangle>\"\n  using that by cases auto\n\nlemma \\<R>_V:\n  \"u \\<in> V\" if \"R \\<in> \\<R> l\" \"u \\<in> R\"\n  using that unfolding \\<R>_def V_def by auto\n\nlemma step_r'_complete:\n  assumes \"A \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow> \\<langle>l',u'\\<rangle>\" \"valid_abstraction A X (\\<lambda> x. real o k x)\" \"u \\<in> V\"\n  shows \"\\<exists> a R'. u' \\<in> R' \\<and> A,\\<R> \\<turnstile> \\<langle>l, [u]\\<^sub>l\\<rangle> \\<leadsto>\\<^sub>a \\<langle>l',R'\\<rangle>\"\n  using assms\n  apply cases\n  apply (drule step_t_r_complete, (rule assms; fail), simp add: V_def)\n  apply clarify\n  apply (frule step_a_r_complete)\n  by (auto dest: step_t_r_loc simp: \\<R>_def simp: region_unique intro!: step_r'.intros)\n\nlemma step_r_\\<R>:\n  \"R' \\<in> \\<R> l'\" if \"A,\\<R> \\<turnstile> \\<langle>l, R\\<rangle> \\<leadsto>\\<^bsub>a\\<^esub> \\<langle>l', R'\\<rangle>\"\n  using that by (auto elim: step_r.cases)\n\nlemma step_r'_\\<R>:\n  \"R' \\<in> \\<R> l'\" if \"A,\\<R> \\<turnstile> \\<langle>l, R\\<rangle> \\<leadsto>\\<^sub>a \\<langle>l', R'\\<rangle>\"\n  using that by (auto intro: step_r_\\<R> elim: step_r'.cases)\n\nend (* End of Alpha Closure *)\n\ncontext Regions\nbegin\n\nlemma closure_parts_mono:\n  \"{R \\<in> \\<R> l. R \\<inter> Z \\<noteq> {}} \\<subseteq> {R \\<in> \\<R> l. R \\<inter> Z' \\<noteq> {}}\" if \"Closure\\<^sub>\\<alpha>\\<^sub>,\\<^sub>l Z \\<subseteq> Closure\\<^sub>\\<alpha>\\<^sub>,\\<^sub>l Z'\"\nproof (clarify, goal_cases)\n  case prems: (1 R)\n  with that have \"R \\<subseteq> Closure\\<^sub>\\<alpha>\\<^sub>,\\<^sub>l Z'\"\n    unfolding cla_def by auto\n  from \\<open>_ \\<noteq> {}\\<close> obtain u where \"u \\<in> R\" \"u \\<in> Z\" by auto\n  with \\<open>R \\<subseteq> _\\<close> obtain R' where \"R' \\<in> \\<R> l\" \"u \\<in> R'\" \"R' \\<inter> Z' \\<noteq> {}\" unfolding cla_def by force\n  from \\<R>_regions_distinct[OF \\<R>_def' this(1,2) \\<open>R \\<in> _\\<close>] \\<open>u \\<in> R\\<close> have \"R = R'\" by auto\n  with \\<open>R' \\<inter> Z' \\<noteq> {}\\<close> \\<open>R \\<inter> Z' = {}\\<close> show ?case by simp\nqed\n\nlemma closure_parts_id:\n  \"{R \\<in> \\<R> l. R \\<inter> Z \\<noteq> {}} = {R \\<in> \\<R> l. R \\<inter> Z' \\<noteq> {}}\" if\n  \"Closure\\<^sub>\\<alpha>\\<^sub>,\\<^sub>l Z = Closure\\<^sub>\\<alpha>\\<^sub>,\\<^sub>l Z'\"\n  using closure_parts_mono that by blast\n\nparagraph \\<open>More lemmas on regions\\<close>\n\n(* XXX All of these should be considered for moving into the locales for global sets of regions *)\ncontext\n  fixes l' :: 's\nbegin\n\ninterpretation regions: Regions_global _ _ _ \"k l'\"\n  by standard (rule finite clock_numbering not_in_X non_empty)+\n\ncontext\n  fixes A :: \"('a, 'c, t, 's) ta\"\n  assumes valid_abstraction: \"valid_abstraction A X k\"\nbegin\n\nlemmas regions_poststable = regions_poststable[OF valid_abstraction]\n\nlemma clkp_set_clkp_set1:\n  \"\\<exists> l. (c, x) \\<in> clkp_set A l\" if \"(c, x) \\<in> Timed_Automata.clkp_set A\"\n  using that\n  unfolding Timed_Automata.clkp_set_def Closure.clkp_set_def\n  unfolding Timed_Automata.collect_clki_def Closure.collect_clki_def\n  unfolding Timed_Automata.collect_clkt_def Closure.collect_clkt_def\n  by fastforce\n\nlemma clkp_set_clkp_set2:\n  \"(c, x) \\<in> Timed_Automata.clkp_set A\" if \"(c, x) \\<in> clkp_set A l\" for l\n  using that\n  unfolding Timed_Automata.clkp_set_def Closure.clkp_set_def\n  unfolding Timed_Automata.collect_clki_def Closure.collect_clki_def\n  unfolding Timed_Automata.collect_clkt_def Closure.collect_clkt_def\n  by fastforce\n\nlemma clock_numbering_le: \"\\<forall>c\\<in>clk_set A. v c \\<le> n\"\nproof\n  fix c assume \"c \\<in> clk_set A\"\n  then have \"c \\<in> X\"\n  proof (safe, clarsimp, goal_cases)\n    case (1 x)\n    then obtain l where \"(c, x) \\<in> clkp_set A l\" by (auto dest: clkp_set_clkp_set1)\n    with valid_abstraction show \"c \\<in> X\" by (auto elim!: valid_abstraction.cases)\n  next\n    case 2\n    with valid_abstraction show \"c \\<in> X\" by (auto elim!: valid_abstraction.cases)\n  qed\n  with clock_numbering show \"v c \\<le> n\" by auto\nqed\n\nlemma beta_alpha_step:\n  \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsub>\\<alpha>(a)\\<^esub> \\<langle>l', Closure\\<^sub>\\<alpha>\\<^sub>,\\<^sub>l' Z'\\<rangle>\" if \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsub>\\<beta>(a)\\<^esub> \\<langle>l', Z'\\<rangle>\" \"Z \\<in> V'\"\nproof -\n  from that obtain Z1' where Z1': \"Z' = Approx\\<^sub>\\<beta> l' Z1'\" \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsub>a\\<^esub> \\<langle>l', Z1'\\<rangle>\"\n    by (clarsimp elim!: step_z_beta.cases)\n  with \\<open>Z \\<in> V'\\<close> have \"Z1' \\<in> V'\"\n    using valid_abstraction clock_numbering_le by (auto intro: step_z_V')\n  let ?alpha = \"Closure\\<^sub>\\<alpha>\\<^sub>,\\<^sub>l' Z1'\" and ?beta = \"Closure\\<^sub>\\<alpha>\\<^sub>,\\<^sub>l' (Approx\\<^sub>\\<beta> l' Z1')\"\n  have \"?beta \\<subseteq> ?alpha\"\n    using regions.approx_\\<beta>_closure_\\<alpha>'[OF \\<open>Z1' \\<in> V'\\<close>] regions.alpha_interp.closure_involutive\n    by (auto 4 3 dest: regions.alpha_interp.cla_mono)\n  moreover have \"?alpha \\<subseteq> ?beta\"\n    by (intro regions.alpha_interp.cla_mono[simplified] regions.beta_interp.apx_subset)\n  ultimately have \"?beta = ?alpha\" ..\n  with Z1' show ?thesis by auto\nqed\n\nlemma beta_alpha_region_step:\n  \"\\<exists> a. \\<exists> R \\<in> \\<R> l. R \\<inter> Z \\<noteq> {} \\<and> A,\\<R> \\<turnstile> \\<langle>l, R\\<rangle> \\<leadsto>\\<^sub>a \\<langle>l', R'\\<rangle>\" if\n  \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^sub>\\<beta> \\<langle>l', Z'\\<rangle>\" \"Z \\<in> V'\" \"R' \\<in> \\<R> l'\" \"R' \\<inter> Z' \\<noteq> {}\"\nproof -\n  from that(1) obtain l'' a Z'' where steps:\n    \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsub>\\<tau>\\<^esub> \\<langle>l'', Z''\\<rangle>\" \"A \\<turnstile> \\<langle>l'', Z''\\<rangle> \\<leadsto>\\<^bsub>\\<beta>(\\<upharpoonleft>a)\\<^esub> \\<langle>l', Z'\\<rangle>\"\n    unfolding step_z_beta'_def by metis\n  with \\<open>Z \\<in> V'\\<close> steps(1) have \"Z'' \\<in> V'\"\n    using valid_abstraction clock_numbering_le by (blast intro: step_z_V')\n  from beta_alpha_step[OF steps(2) this] have \"A \\<turnstile> \\<langle>l'', Z''\\<rangle> \\<leadsto>\\<^bsub>\\<alpha>\\<upharpoonleft>a\\<^esub> \\<langle>l', Closure\\<^sub>\\<alpha>\\<^sub>,\\<^sub>l'(Z')\\<rangle>\" .\n  from step_z_alpha.cases[OF this] obtain Z1 where Z1:\n    \"A \\<turnstile> \\<langle>l'', Z''\\<rangle> \\<leadsto>\\<^bsub>\\<upharpoonleft>a\\<^esub> \\<langle>l', Z1\\<rangle>\" \"Closure\\<^sub>\\<alpha>\\<^sub>,\\<^sub>l'(Z') = Closure\\<^sub>\\<alpha>\\<^sub>,\\<^sub>l'(Z1)\"\n    by metis\n  from closure_parts_id[OF this(2)] that(3,4) have \"R' \\<inter> Z1 \\<noteq> {}\" by blast\n  from regions_poststable[OF steps(1) Z1(1) _ \\<open>R' \\<in> _\\<close> this] \\<open>Z \\<in> V'\\<close> show ?thesis\n    by (auto dest: V'_V)\nqed\n\nlemmas step_z_beta'_V' = step_z_beta'_V'[OF valid_abstraction clock_numbering_le]\n\nlemma step_trans_z'_closure_subs:\n  assumes\n    \"A \\<turnstile>' \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>t\\<^esup> \\<langle>l', Z'\\<rangle>\" \"Z \\<subseteq> V\" \"\\<forall> R \\<in> \\<R> l. R \\<inter> Z \\<noteq> {} \\<longrightarrow> R \\<inter> W \\<noteq> {}\"\n  shows\n    \"\\<exists> W'. A \\<turnstile>' \\<langle>l, W\\<rangle> \\<leadsto>\\<^bsup>t\\<^esup> \\<langle>l', W'\\<rangle> \\<and> (\\<forall> R \\<in> \\<R> l'. R \\<inter> Z' \\<noteq> {} \\<longrightarrow> R \\<inter> W' \\<noteq> {})\"\nproof -\n  from assms(1) obtain W' where step: \"A \\<turnstile>' \\<langle>l, W\\<rangle> \\<leadsto>\\<^bsup>t\\<^esup> \\<langle>l', W'\\<rangle>\"\n    by (auto elim!: step_trans_z.cases step_trans_z'.cases)\n  have \"R' \\<inter> W' \\<noteq> {}\" if \"R' \\<in> \\<R> l'\" \"R' \\<inter> Z' \\<noteq> {}\" for R'\n  proof -\n    from regions_poststable2[OF valid_abstraction assms(1) _ that] \\<open>Z \\<subseteq> V\\<close> obtain R where R:\n      \"R\\<in>\\<R> l\" \"A,\\<R> \\<turnstile>' \\<langle>l, R\\<rangle> \\<leadsto>\\<^bsup>t\\<^esup> \\<langle>l', R'\\<rangle>\" \"R \\<inter> Z \\<noteq> {}\"\n      by auto\n    with assms(3) obtain u where \"u \\<in> R\" \"u \\<in> W\"\n      by auto\n    with step_trans_r'_sound[OF R(2)] obtain u' where \"u' \\<in> R'\" \"A \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow>\\<^bsup>t\\<^esup> \\<langle>l', u'\\<rangle>\"\n      by auto\n    with step_trans_z'_exact[OF this(2) step \\<open>u \\<in> W\\<close>] show ?thesis\n      by auto\n  qed\n  with step show ?thesis\n    by auto\nqed\n\nlemma step_trans_z'_closure_eq:\n  assumes\n    \"A \\<turnstile>' \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsup>t\\<^esup> \\<langle>l', Z'\\<rangle>\" \"Z \\<subseteq> V\" \"W \\<subseteq> V\" \"\\<forall> R \\<in> \\<R> l. R \\<inter> Z \\<noteq> {} \\<longleftrightarrow> R \\<inter> W \\<noteq> {}\"\n  shows\n    \"\\<exists> W'. A \\<turnstile>' \\<langle>l, W\\<rangle> \\<leadsto>\\<^bsup>t\\<^esup> \\<langle>l', W'\\<rangle> \\<and> (\\<forall> R \\<in> \\<R> l'. R \\<inter> Z' \\<noteq> {} \\<longleftrightarrow> R \\<inter> W' \\<noteq> {})\"\nproof -\n  from assms(4) have *:\n    \"\\<forall> R \\<in> \\<R> l. R \\<inter> Z \\<noteq> {} \\<longrightarrow> R \\<inter> W \\<noteq> {}\" \"\\<forall> R \\<in> \\<R> l. R \\<inter> W \\<noteq> {} \\<longrightarrow> R \\<inter> Z \\<noteq> {}\"\n    by auto\n  from step_trans_z'_closure_subs[OF assms(1,2) *(1)] obtain W' where W':\n    \"A \\<turnstile>' \\<langle>l, W\\<rangle> \\<leadsto>\\<^bsup>t\\<^esup> \\<langle>l', W'\\<rangle>\" \"(\\<forall>R\\<in>\\<R> l'. R \\<inter> Z' \\<noteq> {} \\<longrightarrow> R \\<inter> W' \\<noteq> {})\"\n    by auto\n  with step_trans_z'_closure_subs[OF W'(1) \\<open>W \\<subseteq> V\\<close> *(2)] assms(1) show ?thesis\n    by (fastforce dest: step_trans_z'_determ)\nqed\n\nlemma step_z'_closure_subs:\n  assumes \n    \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto> \\<langle>l', Z'\\<rangle>\" \"Z \\<subseteq> V\" \"\\<forall> R \\<in> \\<R> l. R \\<inter> Z \\<noteq> {} \\<longrightarrow> R \\<inter> W \\<noteq> {}\"\n  shows\n    \"\\<exists> W'. A \\<turnstile> \\<langle>l, W\\<rangle> \\<leadsto> \\<langle>l', W'\\<rangle> \\<and> (\\<forall> R \\<in> \\<R> l'. R \\<inter> Z' \\<noteq> {} \\<longrightarrow> R \\<inter> W' \\<noteq> {})\"\n  using assms(1)\n  by (auto\n      dest: step_trans_z'_step_z'\n      dest!: step_z'_step_trans_z' step_trans_z'_closure_subs[OF _ assms(2,3)]\n     )\n\nend (* Context for automaton *)\n\nlemma apx_finite:\n  \"finite {Approx\\<^sub>\\<beta> l' Z | Z. Z \\<subseteq> V}\" (is \"finite ?S\")\nproof -\n  have \"finite regions.\\<R>\\<^sub>\\<beta>\"\n    by (simp add: regions.beta_interp.finite_\\<R>)\n  then have \"finite {S. S \\<subseteq> regions.\\<R>\\<^sub>\\<beta>}\"\n    by auto\n  then have \"finite {\\<Union> S | S. S \\<subseteq> regions.\\<R>\\<^sub>\\<beta>}\"\n    by auto\n  moreover have \"?S \\<subseteq> {\\<Union> S | S. S \\<subseteq> regions.\\<R>\\<^sub>\\<beta>}\"\n    by (auto dest!: regions.beta_interp.apx_in)\n  ultimately show ?thesis by (rule finite_subset[rotated])\nqed\n\nlemmas apx_subset = regions.beta_interp.apx_subset\n\nlemma step_z_beta'_empty:\n  \"Z' = {}\" if \"A \\<turnstile> \\<langle>l, {}\\<rangle> \\<leadsto>\\<^sub>\\<beta> \\<langle>l', Z'\\<rangle>\"\n  using that\n  by (auto\n      elim!: step_z.cases\n      simp: step_z_beta'_def regions.beta_interp.apx_empty zone_delay_def zone_set_def\n     )\n\nend (* End of context for fixed location *)\n\nlemma step_z_beta'_complete:\n  assumes \"A \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow> \\<langle>l', u'\\<rangle>\" \"u \\<in> Z\" \"Z \\<subseteq> V\"\n  shows \"\\<exists> Z'. A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^sub>\\<beta> \\<langle>l', Z'\\<rangle> \\<and> u' \\<in> Z'\"\nproof -\n  from assms(1) obtain l'' u'' d a where steps:\n    \"A \\<turnstile> \\<langle>l, u\\<rangle> \\<rightarrow>\\<^bsup>d\\<^esup> \\<langle>l'', u''\\<rangle>\" \"A \\<turnstile> \\<langle>l'', u''\\<rangle> \\<rightarrow>\\<^bsub>a\\<^esub> \\<langle>l', u'\\<rangle>\"\n    by (force elim!: step'.cases)\n  then obtain Z'' where\n    \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^bsub>\\<tau>\\<^esub> \\<langle>l'', Z''\\<rangle>\" \"u'' \\<in> Z''\"\n    by (meson \\<open>u \\<in> Z\\<close> step_t_z_complete)\n  moreover with steps(2) obtain Z' where\n    \"A \\<turnstile> \\<langle>l'', Z''\\<rangle> \\<leadsto>\\<^bsub>\\<upharpoonleft>a\\<^esub> \\<langle>l', Z'\\<rangle>\" \"u' \\<in> Z'\"\n    by (meson \\<open>u'' \\<in> Z''\\<close> step_a_z_complete)\n  ultimately show ?thesis\n    unfolding step_z_beta'_def using \\<open>Z \\<subseteq> V\\<close> apx_subset by blast\nqed\n\nend (* End of Regions *)\n\n\nsubsection \\<open>Instantiation of Double Simulation\\<close>\n\nsubsection \\<open>Auxiliary Definitions\\<close>\n\ndefinition state_set :: \"('a, 'c, 'time, 's) ta \\<Rightarrow> 's set\" where\n  \"state_set A \\<equiv> fst ` (fst A) \\<union> (snd o snd o snd o snd) ` (fst A)\"\n\nlemma finite_trans_of_finite_state_set:\n  \"finite (state_set A)\" if \"finite (trans_of A)\"\n  using that unfolding state_set_def trans_of_def by auto\n\nlemma state_setI1:\n  \"l \\<in> state_set A\" if \"A \\<turnstile> l \\<longrightarrow>\\<^bsup>g,a,r\\<^esup> l'\"\n  using that unfolding state_set_def trans_of_def image_def by (auto 4 4)\n\nlemma state_setI2:\n  \"l' \\<in> state_set A\" if \"A \\<turnstile> l \\<longrightarrow>\\<^bsup>g,a,r\\<^esup> l'\"\n  using that unfolding state_set_def trans_of_def image_def by (auto 4 4)\n\nlemma (in AlphaClosure) step_r'_state_set:\n  \"l' \\<in> state_set A\" if \"A,\\<R> \\<turnstile> \\<langle>l, R\\<rangle> \\<leadsto>\\<^sub>a \\<langle>l', R'\\<rangle>\"\n  using that by (blast intro: state_setI2 elim: step_r'.cases)\n\nlemma (in Regions) step_z_beta'_state_set2:\n  \"l' \\<in> state_set A\" if \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^sub>\\<beta> \\<langle>l', Z'\\<rangle>\"\n  using that unfolding step_z_beta'_def by (force simp: state_set_def trans_of_def)\n\nsubsection \\<open>Instantiation\\<close>\n\nlocale Regions_TA = Regions X _ _  k for X :: \"'c set\" and k :: \"'s \\<Rightarrow> 'c \\<Rightarrow> nat\" +\n  fixes A :: \"('a, 'c, t, 's) ta\"\n  assumes valid_abstraction: \"valid_abstraction A X k\"\n    and finite_state_set: \"finite (state_set A)\"\nbegin\n\n(* XXX Bundle this? *)\nno_notation Regions_Beta.part (\"[_]\\<^sub>_\" [61,61] 61)\nnotation part'' (\"[_]\\<^sub>_\" [61,61] 61)\n\n(* XXX Move *)\nlemma step_z_beta'_state_set1:\n  \"l \\<in> state_set A\" if \"A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^sub>\\<beta> \\<langle>l', Z'\\<rangle>\"\n  using that unfolding step_z_beta'_def by (force simp: state_set_def trans_of_def)\n\nsublocale sim: Double_Simulation_paired\n  \"\\<lambda> (l, u) (l', u'). A \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow> \\<langle>l', u'\\<rangle>\"  \\<comment> \\<open>Concrete step relation\\<close>\n  \"\\<lambda> (l, Z) (l', Z'). \\<exists> a. A,\\<R> \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^sub>a \\<langle>l', Z'\\<rangle> \\<and> Z' \\<noteq> {}\"\n  \\<comment> \\<open>Step relation for the first abstraction layer\\<close>\n  \"\\<lambda> (l, R). l \\<in> state_set A \\<and> R \\<in> \\<R> l\" \\<comment> \\<open>Valid states of the first abstraction layer\\<close>\n  \"\\<lambda> (l, Z) (l', Z'). A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^sub>\\<beta> \\<langle>l', Z'\\<rangle> \\<and> Z' \\<noteq> {}\"\n  \\<comment> \\<open>Step relation for the second abstraction layer\\<close>\n  \"\\<lambda> (l, Z). l \\<in> state_set A \\<and> Z \\<in> V' \\<and> Z \\<noteq> {}\" \\<comment> \\<open>Valid states of the second abstraction layer\\<close>\nproof (standard, goal_cases)\n  case (1 S T)\n  then show ?case\n    by (auto dest!: step_r'_sound)\nnext\n  case prems: (2 R' l' Z' l Z)\n  from prems(3) have \"l \\<in> state_set A\"\n    by (blast intro: step_z_beta'_state_set1)\n  from prems show ?case\n    unfolding Double_Simulation_paired_Defs.closure'_def\n    by (blast dest: beta_alpha_region_step[OF valid_abstraction] step_z_beta'_state_set1)\nnext\n  case prems: (3 l R R')\n  then show ?case\n    using \\<R>_regions_distinct[OF \\<R>_def'] by auto\nnext\n  case 4\n  have *: \"finite (\\<R> l)\" for l\n    unfolding \\<R>_def by (intro finite_\\<R> finite)\n  have\n    \"{(l, R). l \\<in> state_set A \\<and> R \\<in> \\<R> l} = (\\<Union> l \\<in> state_set A. ((\\<lambda> R. (l, R)) ` {R. R \\<in> \\<R> l}))\"\n    by auto\n  also have \"finite \\<dots>\"\n    by (auto intro: finite_UN_I[OF finite_state_set] *)\n  finally show ?case by auto\nnext\n  case (5 l Z)\n  then show ?case\n    apply safe\n    subgoal for u\n      using region_cover'[of u l] by (auto dest!: V'_V, auto simp: V_def)\n    done\nqed\n\nsublocale Graph_Defs\n  \"\\<lambda> (l, Z) (l', Z'). A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^sub>\\<beta> \\<langle>l', Z'\\<rangle> \\<and> Z' \\<noteq> {}\" .\n\nlemmas step_z_beta'_V' = step_z_beta'_V'[OF valid_abstraction]\n\nlemma step_r'_complete_spec:\n  assumes \"A \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow> \\<langle>l',u'\\<rangle>\" \"u \\<in> V\"\n  shows \"\\<exists> a R'. u' \\<in> R' \\<and> A,\\<R> \\<turnstile> \\<langle>l, [u]\\<^sub>l\\<rangle> \\<leadsto>\\<^sub>a \\<langle>l',R'\\<rangle>\"\n  using assms valid_abstraction by (auto simp: comp_def V_def intro!: step_r'_complete)\n\nend (* Regions TA *)\n\n\nsubsection \\<open>Büchi Runs\\<close>\n\nlocale Regions_TA_Start_State = Regions_TA _ _ _ _ _ A for A :: \"('a, 'c, t, 's) ta\" +\n  fixes l\\<^sub>0 :: \"'s\" and Z\\<^sub>0 :: \"('c, t) zone\"\n  assumes start_state: \"l\\<^sub>0 \\<in> state_set A\" \"Z\\<^sub>0 \\<in> V'\" \"Z\\<^sub>0 \\<noteq> {}\"\nbegin\n\ndefinition \"a\\<^sub>0 = from_R l\\<^sub>0 Z\\<^sub>0\"\n\nsublocale sim_complete': Double_Simulation_Finite_Complete_paired\n  \"\\<lambda> (l, u) (l', u'). A \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow> \\<langle>l', u'\\<rangle>\"  \\<comment> \\<open>Concrete step relation\\<close>\n  \"\\<lambda> (l, Z) (l', Z'). \\<exists> a. A,\\<R> \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^sub>a \\<langle>l', Z'\\<rangle> \\<and> Z' \\<noteq> {}\"\n  \\<comment> \\<open>Step relation for the first abstraction layer\\<close>\n  \"\\<lambda> (l, R). l \\<in> state_set A \\<and> R \\<in> \\<R> l\" \\<comment> \\<open>Valid states of the first abstraction layer\\<close>\n  \"\\<lambda> (l, Z) (l', Z'). A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^sub>\\<beta> \\<langle>l', Z'\\<rangle> \\<and> Z' \\<noteq> {}\"\n  \\<comment> \\<open>Step relation for the second abstraction layer\\<close>\n  \"\\<lambda> (l, Z). l \\<in> state_set A \\<and> Z \\<in> V' \\<and> Z \\<noteq> {}\" \\<comment> \\<open>Valid states of the second abstraction layer\\<close>\n  l\\<^sub>0 Z\\<^sub>0\nproof (standard, goal_cases)\n  case (1 x y S)\n  \\<comment> \\<open>Completeness\\<close>\n  then show ?case\n    by (force dest: step_z_beta'_complete[rotated 2, OF V'_V])\nnext\n  case 4\n  \\<comment> \\<open>Finiteness\\<close>\n  (* XXX *)\n  have *: \"Z \\<in> V'\" if \"A \\<turnstile> \\<langle>l\\<^sub>0, Z\\<^sub>0\\<rangle> \\<leadsto>\\<^sub>\\<beta>* \\<langle>l, Z\\<rangle>\" for l Z\n    using that start_state step_z_beta'_V' by (induction rule: rtranclp_induct2) blast+\n  have \"Z \\<in> {Approx\\<^sub>\\<beta> l Z | Z. Z \\<subseteq> V} \\<or> (l, Z) = (l\\<^sub>0, Z\\<^sub>0)\"\n    if \"reaches (l\\<^sub>0, Z\\<^sub>0) (l, Z)\" for l Z\n    using that proof (induction rule: rtranclp_induct2)\n    case refl\n    then show ?case\n      by simp\n  next\n    case prems: (step l Z l' Z')\n    from prems(1) have \"A \\<turnstile> \\<langle>l\\<^sub>0, Z\\<^sub>0\\<rangle> \\<leadsto>\\<^sub>\\<beta>* \\<langle>l, Z\\<rangle>\"\n      by induction (auto intro: rtranclp_trans)\n    then have \"Z \\<in> V'\"\n      by (rule *)\n    with prems show ?case\n      unfolding step_z_beta'_def using start_state(2) by (auto 0 1 dest!: V'_V elim!: step_z_V)\n  qed\n  then have \"{(l, Z). reaches (l\\<^sub>0, Z\\<^sub>0) (l, Z) \\<and> l \\<in> state_set A \\<and> Z \\<in> V' \\<and> Z \\<noteq> {}}\n    \\<subseteq> {(l, Z) | l Z. l \\<in> state_set A \\<and> Z \\<in> {Approx\\<^sub>\\<beta> l Z | Z. Z \\<subseteq> V}} \\<union> {(l\\<^sub>0, Z\\<^sub>0)}\"\n    by auto\n  also have \"finite \\<dots>\" (is \"finite ?S\")\n  proof -\n    have \"?S = {(l\\<^sub>0, Z\\<^sub>0)} \\<union> \\<Union> ((\\<lambda> l. (\\<lambda> Z. (l, Z)) ` {Approx\\<^sub>\\<beta> l Z | Z. Z \\<subseteq> V}) ` (state_set A))\"\n      by blast\n    also have \"finite \\<dots>\"\n      by (blast intro: apx_finite finite_state_set)\n    finally show ?thesis .\n  qed\n  finally show ?case\n    by simp\nnext\n  case prems: (2 a a')\n  then show ?case\n    by (auto intro: step_z_beta'_V' step_z_beta'_state_set2)\nnext\n  case 3\n  from start_state show ?case unfolding a\\<^sub>0_def by (auto simp: from_R_fst)\nqed\n\nsublocale sim_complete_bisim': Double_Simulation_Finite_Complete_Bisim_Cover_paired\n  \"\\<lambda> (l, u) (l', u'). A \\<turnstile>' \\<langle>l, u\\<rangle> \\<rightarrow> \\<langle>l', u'\\<rangle>\"  \\<comment> \\<open>Concrete step relation\\<close>\n  \"\\<lambda> (l, Z) (l', Z'). \\<exists> a. A,\\<R> \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^sub>a \\<langle>l', Z'\\<rangle> \\<and> Z' \\<noteq> {}\"\n  \\<comment> \\<open>Step relation for the first abstraction layer\\<close>\n  \"\\<lambda> (l, R). l \\<in> state_set A \\<and> R \\<in> \\<R> l\" \\<comment> \\<open>Valid states of the first abstraction layer\\<close>\n  \"\\<lambda> (l, Z) (l', Z'). A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^sub>\\<beta> \\<langle>l', Z'\\<rangle> \\<and> Z' \\<noteq> {}\"\n  \\<comment> \\<open>Step relation for the second abstraction layer\\<close>\n  \"\\<lambda> (l, Z). l \\<in> state_set A \\<and> Z \\<in> V' \\<and> Z \\<noteq> {}\" \\<comment> \\<open>Valid states of the second abstraction layer\\<close>\n  l\\<^sub>0 Z\\<^sub>0\nproof (standard, goal_cases)\n  case (1 l x l' y S)\n  then show ?case\n    apply clarify\n    apply (drule step_r'_complete_spec, (auto intro: \\<R>_V; fail))\n    by (auto simp: \\<R>_def region_unique)\nnext\n  case (2 l S l' T)\n  then show ?case\n    by (auto simp add: step_r'_state_set step_r'_\\<R>)\nnext\n  case prems: (3 l Z u)\n  then show ?case\n    using region_cover'[of u l] by (auto dest!: V'_V simp: V_def)+\nqed\n\nsubsection \\<open>State Formulas\\<close>\n\ncontext\n  fixes P :: \"'s \\<Rightarrow> bool\" \\<comment> \\<open>The state property we want to check\\<close>\nbegin\n\ndefinition \"\\<phi> = P o fst\"\n\nparagraph \\<open>State formulas are compatible with closures.\\<close>\n\nparagraph \\<open>Runs satisfying a formula all the way long\\<close>\n\ninterpretation G\\<^sub>\\<phi>: Graph_Start_Defs\n  \"\\<lambda> (l, Z) (l', Z'). A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^sub>\\<beta> \\<langle>l', Z'\\<rangle> \\<and> Z' \\<noteq> {} \\<and> P l'\" \"(l\\<^sub>0, Z\\<^sub>0)\" .\n\ntheorem Alw_ev_mc1:\n  \"(\\<forall>x\\<^sub>0\\<in>a\\<^sub>0. sim.sim.Alw_ev (Not \\<circ> \\<phi>) x\\<^sub>0) \\<longleftrightarrow> \\<not> (P l\\<^sub>0 \\<and> (\\<exists>a. G\\<^sub>\\<phi>.reachable a \\<and> G\\<^sub>\\<phi>.reaches1 a a))\"\n  using sim_complete_bisim'.Alw_ev_mc1\n  unfolding G\\<^sub>\\<phi>.reachable_def a\\<^sub>0_def sim_complete_bisim'.\\<psi>_def \\<phi>_def\n  by auto\n\nend (* Context for State Formula *)\n\nsubsection \\<open>Leads-To Properties\\<close>\n\ncontext\n  fixes P Q :: \"'s \\<Rightarrow> bool\" \\<comment> \\<open>The state properties we want to check\\<close>\nbegin\n\ndefinition \"\\<psi> = Q o fst\"\n\ninterpretation G\\<^sub>\\<psi>: Graph_Defs\n  \"\\<lambda> (l, Z) (l', Z'). A \\<turnstile> \\<langle>l, Z\\<rangle> \\<leadsto>\\<^sub>\\<beta> \\<langle>l', Z'\\<rangle> \\<and> Z' \\<noteq> {} \\<and> Q l'\" .\n\ntheorem leadsto_mc1:\n  \"(\\<forall>x\\<^sub>0\\<in>a\\<^sub>0. sim.sim.leadsto (\\<phi> P) (Not \\<circ> \\<psi>) x\\<^sub>0) \\<longleftrightarrow>\n   (\\<nexists>x. reaches (l\\<^sub>0, Z\\<^sub>0) x \\<and> P (fst x) \\<and> Q (fst x) \\<and> (\\<exists>a. G\\<^sub>\\<psi>.reaches x a \\<and> G\\<^sub>\\<psi>.reaches1 a a))\"\n  if \"\\<forall>x\\<^sub>0\\<in>a\\<^sub>0. \\<not> sim.sim.deadlock x\\<^sub>0\"\nproof -\n  from that have *: \"\\<forall>x\\<^sub>0\\<in>Z\\<^sub>0. \\<not> sim.sim.deadlock (l\\<^sub>0, x\\<^sub>0)\"\n    unfolding a\\<^sub>0_def by auto\n  show ?thesis\n    using sim_complete_bisim'.leadsto_mc1[OF *, symmetric, of P Q]\n    unfolding \\<psi>_def \\<phi>_def sim_complete_bisim'.\\<phi>'_def sim_complete_bisim'.\\<psi>_def a\\<^sub>0_def\n    by (auto dest: from_R_D from_R_loc)\nqed\n\nend (* Context for State Formulae *)\n\nlemma from_R_reaches:\n  assumes \"sim.sim.Steps.reaches (from_R l\\<^sub>0 Z\\<^sub>0) b\"\n  obtains l Z where \"b = from_R l Z\"\n  using assms by cases (fastforce simp: sim.A2'_def dest!: from_R_R_of)+\n\nlemma ta_reaches_ex_iff:\n  assumes compatible:\n    \"\\<And>l u u' R.\n      u \\<in> R \\<Longrightarrow> u' \\<in> R \\<Longrightarrow> R \\<in> \\<R> l \\<Longrightarrow> l \\<in> state_set A \\<Longrightarrow> P (l, u) = P (l, u')\"\n  shows\n    \"(\\<exists> x\\<^sub>0 \\<in> a\\<^sub>0. \\<exists> l u. sim.sim.reaches x\\<^sub>0 (l, u) \\<and> P (l, u)) \\<longleftrightarrow>\n     (\\<exists> l Z. \\<exists> u \\<in> Z. reaches (l\\<^sub>0, Z\\<^sub>0) (l, Z) \\<and> P (l, u))\"\nproof -\n  have *: \"(\\<exists>x\\<^sub>0 \\<in> a\\<^sub>0. \\<exists> l u. sim.sim.reaches x\\<^sub>0 (l, u) \\<and> P (l, u))\n    \\<longleftrightarrow> (\\<exists>y. \\<exists>x\\<^sub>0\\<in>from_R l\\<^sub>0 Z\\<^sub>0. sim.sim.reaches x\\<^sub>0 y \\<and> P y)\"\n    unfolding a\\<^sub>0_def by auto\n  show ?thesis\n    unfolding *\n    apply (subst sim_complete_bisim'.sim_reaches_equiv)\n    subgoal\n      by (simp add: start_state)\n    apply (subst sim_complete_bisim'.reaches_ex'[of P])\n    unfolding a\\<^sub>0_def\n     apply clarsimp\n    subgoal\n      unfolding sim.P1'_def by (clarsimp simp: fst_simp) (metis R_ofI compatible fst_conv)\n    apply safe\n     apply (rule from_R_reaches, assumption)\n    using from_R_fst by (force intro: from_R_val)+\nqed\n\nlemma ta_reaches_all_iff:\n  assumes compatible:\n    \"\\<And>l u u' R.\n      u \\<in> R \\<Longrightarrow> u' \\<in> R \\<Longrightarrow> R \\<in> \\<R> l \\<Longrightarrow> l \\<in> state_set A \\<Longrightarrow> P (l, u) = P (l, u')\"\n  shows\n    \"(\\<forall> x\\<^sub>0 \\<in> a\\<^sub>0. \\<forall> l u. sim.sim.reaches x\\<^sub>0 (l, u) \\<longrightarrow> P (l, u)) \\<longleftrightarrow>\n     (\\<forall> l Z. reaches (l\\<^sub>0, Z\\<^sub>0) (l, Z) \\<longrightarrow> (\\<forall> u \\<in> Z. P (l, u)))\"\nproof -\n  have *: \"(\\<forall>x\\<^sub>0 \\<in> a\\<^sub>0. \\<forall> l u. sim.sim.reaches x\\<^sub>0 (l, u) \\<longrightarrow> P (l, u))\n    \\<longleftrightarrow> (\\<forall>y. \\<forall>x\\<^sub>0\\<in>from_R l\\<^sub>0 Z\\<^sub>0. sim.sim.reaches x\\<^sub>0 y \\<longrightarrow> P y)\"\n    unfolding a\\<^sub>0_def by auto\n  show ?thesis\n    unfolding *\n    apply (subst sim_complete_bisim'.sim_reaches_equiv)\n    subgoal\n      by (simp add: start_state)\n    apply (subst sim_complete_bisim'.reaches_all''[of P])\n    unfolding a\\<^sub>0_def\n     apply clarsimp\n    subgoal\n      unfolding sim.P1'_def by (clarsimp simp: fst_simp) (metis R_ofI compatible fst_conv)\n    apply auto\n    apply (rule from_R_reaches, assumption)\n    using from_R_fst by (force intro: from_R_val)+\nqed\n\nend (* Reachability Problem precompiled *)\n\nend (* Theory *)", "meta": {"author": "wimmers", "repo": "munta", "sha": "62cb1a4a4dbcfcf62c365e90faba15b0012d5a12", "save_path": "github-repos/isabelle/wimmers-munta", "path": "github-repos/isabelle/wimmers-munta/munta-62cb1a4a4dbcfcf62c365e90faba15b0012d5a12/TA/Simulation_Graphs_TA.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.476579651063676, "lm_q1q2_score": 0.25501702239959184}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      XVcgEx.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2006-2008 Norbert Schirmer\nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection \"Examples for Parallel Assignments\"\n\ntheory XVcgEx\nimports \"../XVcg\"\n\nbegin\n\nrecord \"globals\" =\n  \"G_'\"::\"nat\"\n  \"H_'\"::\"nat\"\n\nrecord 'g vars = \"'g state\" +\n  A_' :: nat\n  B_' :: nat\n  C_' :: nat\n  I_' :: nat\n  M_' :: nat\n  N_' :: nat\n  R_' :: nat\n  S_' :: nat\n  Arr_' :: \"nat list\"\n  Abr_':: string\n\nterm \"BASIC\n         \\<acute>A :== x,\n         \\<acute>B :== y\n      END\"\n\nterm \"BASIC\n         \\<acute>G :== \\<acute>H,\n         \\<acute>H :== \\<acute>G\n      END\"\n\nterm \"BASIC\n        LET (x,y) = (\\<acute>A,b);\n            z = \\<acute>B\n        IN \\<acute>A :== x,\n           \\<acute>G :== \\<acute>A + y + z\n      END\"\n\n\nlemma \"\\<Gamma>\\<turnstile> \\<lbrace>\\<acute>A = 0\\<rbrace>\n      \\<lbrace>\\<acute>A < 0\\<rbrace> \\<longmapsto> BASIC\n       LET (a,b,c) = foo \\<acute>A\n       IN\n            \\<acute>A :== a,\n            \\<acute>B :== b,\n            \\<acute>C :== c\n      END\n      \\<lbrace>\\<acute>A = x \\<and> \\<acute>B = y \\<and> \\<acute>C = c\\<rbrace>\"\napply vcg\noops\n\nlemma \"\\<Gamma>\\<turnstile> \\<lbrace>\\<acute>A = 0\\<rbrace>\n      \\<lbrace>\\<acute>A < 0\\<rbrace> \\<longmapsto> BASIC\n       LET (a,b,c) = foo \\<acute>A\n       IN\n            \\<acute>A :== a,\n            \\<acute>G :== b + \\<acute>B,\n            \\<acute>H :== c\n      END\n      \\<lbrace>\\<acute>A = x \\<and> \\<acute>G = y \\<and> \\<acute>H = c\\<rbrace>\"\napply vcg\noops\n\ndefinition foo:: \"nat \\<Rightarrow> (nat \\<times> nat \\<times> nat)\"\n  where \"foo n = (n,n+1,n+2)\"\n\nlemma \"\\<Gamma>\\<turnstile> \\<lbrace>\\<acute>A = 0\\<rbrace>\n      \\<lbrace>\\<acute>A < 0\\<rbrace> \\<longmapsto> BASIC\n       LET (a,b,c) = foo \\<acute>A\n       IN\n            \\<acute>A :== a,\n            \\<acute>G :== b + \\<acute>B,\n            \\<acute>H :== c\n      END\n      \\<lbrace>\\<acute>A = x \\<and> \\<acute>G = y \\<and> \\<acute>H = c\\<rbrace>\"\napply (vcg add: foo_def snd_conv fst_conv)\noops\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/c-parser/Simpl/ex/XVcgEx.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6619228758499942, "lm_q2_score": 0.3849121444839335, "lm_q1q2_score": 0.2547821536263938}}
{"text": "theory DYNAMIC_Post_Network\n  imports\n    DYNAMIC_Post_ISSUER\n    Post_RECEIVER\n    \"../API_Network\"\n    \"BD_Security_Compositional.Composing_Security_Network\"\nbegin\n\nsubsubsection \\<open>Confidentiality for the N-ary composition\\<close>\n\ntype_synonym ttrans = \"(state, act, out) trans\"\ntype_synonym obs = Post_Observation_Setup_ISSUER.obs\ntype_synonym \"value\" = \"Post.value + Post_RECEIVER.value\"\n\nlemma value_cases:\nfixes v :: \"value\"\nobtains (PVal) pst where \"v = Inl (Post.PVal pst)\"\n      | (PValS) aid pst where \"v = Inl (Post.PValS aid pst)\"\n      | (OVal) ov where \"v = Inl (Post.OVal ov)\"\n      | (PValR) pst where \"v = Inr (Post_RECEIVER.PValR pst)\"\nproof (cases v)\n  case (Inl vl) then show thesis using PVal PValS OVal by (cases vl rule: Post.value.exhaust) auto next\n  case (Inr vr) then show thesis using PValR by (cases vr rule: Post_RECEIVER.value.exhaust) auto\nqed\n\nlocale Post_Network = Network\n+ fixes UIDs :: \"apiID \\<Rightarrow> userID set\"\n  and AID :: \"apiID\" and PID :: \"postID\"\n  assumes AID_in_AIDs: \"AID \\<in> AIDs\"\nbegin\n\nsublocale Iss: Post \"UIDs AID\" PID .\n\nabbreviation \\<phi> :: \"apiID \\<Rightarrow> (state, act, out) trans \\<Rightarrow> bool\"\nwhere \"\\<phi> aid trn \\<equiv> (if aid = AID then Iss.\\<phi> trn else Post_RECEIVER.\\<phi> PID AID trn)\"\n\nabbreviation f :: \"apiID \\<Rightarrow> (state, act, out) trans \\<Rightarrow> value\"\nwhere \"f aid trn \\<equiv> (if aid = AID then Inl (Iss.f trn) else Inr (Post_RECEIVER.f PID AID trn))\"\n\nabbreviation \\<gamma> :: \"apiID \\<Rightarrow> (state, act, out) trans \\<Rightarrow> bool\"\nwhere \"\\<gamma> aid trn \\<equiv> (if aid = AID then Iss.\\<gamma> trn else ObservationSetup_RECEIVER.\\<gamma> (UIDs aid) trn)\"\n\nabbreviation g :: \"apiID \\<Rightarrow> (state, act, out) trans \\<Rightarrow> obs\"\nwhere \"g aid trn \\<equiv> (if aid = AID then Iss.g trn else ObservationSetup_RECEIVER.g PID AID trn)\"\n\nabbreviation T :: \"apiID \\<Rightarrow> (state, act, out) trans \\<Rightarrow> bool\"\n  where \"T aid trn \\<equiv> (if aid = AID then Iss.T trn else Post_RECEIVER.T (UIDs aid) PID AID trn)\"\n\n(* Note that Iss.T is trivially False (since the issuer being dynamic, the trigger\nis incorporated in the bound) so an alternative definition of the composite trigger is:  *)\nlemma T_def:\n\"T aid trn \\<longleftrightarrow> aid \\<noteq> AID \\<and> Post_RECEIVER.T (UIDs aid) PID AID trn\"\nby auto\n\nabbreviation B :: \"apiID \\<Rightarrow> value list \\<Rightarrow> value list \\<Rightarrow> bool\"\nwhere \"B aid vl vl1 \\<equiv>\n  (if aid = AID then list_all isl vl \\<and> list_all isl vl1 \\<and> Iss.B (map projl vl) (map projl vl1)\n   else list_all (Not o isl) vl \\<and> list_all (Not o isl) vl1 \\<and> Post_RECEIVER.B (map projr vl) (map projr vl1))\"\n\nfun comOfV :: \"apiID \\<Rightarrow> value \\<Rightarrow> com\" where\n  \"comOfV aid (Inl (Post.PValS aid' pst)) = (if aid' \\<noteq> aid then Send else Internal)\"\n| \"comOfV aid (Inl (Post.PVal pst)) = Internal\"\n| \"comOfV aid (Inl (Post.OVal ov)) = Internal\"\n| \"comOfV aid (Inr v) = Recv\"\n\nfun tgtNodeOfV :: \"apiID \\<Rightarrow> value \\<Rightarrow> apiID\" where\n  \"tgtNodeOfV aid (Inl (Post.PValS aid' pst)) = aid'\"\n| \"tgtNodeOfV aid (Inl (Post.PVal pst)) = undefined\"\n| \"tgtNodeOfV aid (Inl (Post.OVal ov)) = undefined\"\n| \"tgtNodeOfV aid (Inr v) = AID\"\n\ndefinition syncV :: \"apiID \\<Rightarrow> value \\<Rightarrow> apiID \\<Rightarrow> value \\<Rightarrow> bool\" where\n  \"syncV aid1 v1 aid2 v2 =\n    (\\<exists>pst. aid1 = AID \\<and> v1 = Inl (Post.PValS aid2 pst) \\<and> v2 = Inr (Post_RECEIVER.PValR pst))\"\n\nlemma syncVI: \"syncV AID (Inl (Post.PValS aid' pst)) aid' (Inr (Post_RECEIVER.PValR pst))\"\nunfolding syncV_def by auto\n\nlemma syncVE:\nassumes \"syncV aid1 v1 aid2 v2\"\nobtains pst where \"aid1 = AID\" \"v1 = Inl (Post.PValS aid2 pst)\" \"v2 = Inr (Post_RECEIVER.PValR pst)\"\nusing assms unfolding syncV_def by auto\n\nfun getTgtV where\n  \"getTgtV (Inl (Post.PValS aid pst)) = Inr (Post_RECEIVER.PValR pst)\"\n| \"getTgtV v = v\"\n\nlemma comOfV_AID:\n  \"comOfV AID v = Send \\<longleftrightarrow> isl v \\<and> Iss.isPValS (projl v) \\<and> Iss.tgtAPI (projl v) \\<noteq> AID\"\n  \"comOfV AID v = Recv \\<longleftrightarrow> Not (isl v)\"\nby (cases v rule: value_cases; auto)+\n\nlemmas \\<phi>_defs = Post_RECEIVER.\\<phi>_def2 Iss.\\<phi>_def3\n\nsublocale Net: BD_Security_TS_Network_getTgtV\nwhere istate = \"\\<lambda>_. istate\" and validTrans = validTrans and srcOf = \"\\<lambda>_. srcOf\" and tgtOf = \"\\<lambda>_. tgtOf\"\n  and nodes = AIDs and comOf = comOf and tgtNodeOf = tgtNodeOf\n  and sync = sync and \\<phi> = \\<phi> and f = f and \\<gamma> = \\<gamma> and g = g and T = T and B = B\n  and comOfV = comOfV and tgtNodeOfV = tgtNodeOfV and syncV = syncV\n  and comOfO = comOfO and tgtNodeOfO = tgtNodeOfO and syncO = syncO (*and cmpO = cmpO*)\n  and source = AID and getTgtV = getTgtV\nusing AID_in_AIDs proof (unfold_locales, goal_cases)\n  case (1 nid trn) then show ?case using Iss.validTrans_isCOMact_open[of trn] by (cases trn rule: Iss.\\<phi>.cases) (auto simp: \\<phi>_defs split: prod.splits) next\n  case (2 nid trn) then show ?case using Iss.validTrans_isCOMact_open[of trn] by (cases trn rule: Iss.\\<phi>.cases) (auto simp: \\<phi>_defs split: prod.splits) next\n  case (3 nid trn)\n    interpret Sink: Post_RECEIVER \"UIDs nid\" PID AID .\n    show ?case using 3 by (cases \"(nid,trn)\" rule: tgtNodeOf.cases) (auto split: prod.splits)\nnext\n  case (4 nid trn)\n    interpret Sink: Post_RECEIVER \"UIDs nid\" PID AID .\n    show ?case using 4 by (cases \"(nid,trn)\" rule: tgtNodeOf.cases) (auto split: prod.splits)\nnext\n  case (5 nid1 trn1 nid2 trn2)\n    interpret Sink1: Post_RECEIVER \"UIDs nid1\" PID AID .\n    interpret Sink2: Post_RECEIVER \"UIDs nid2\" PID AID .\n    show ?case using 5 by (elim sync_cases) (auto intro: syncVI)\nnext\n  case (6 nid1 trn1 nid2 trn2)\n    interpret Sink1: Post_RECEIVER \"UIDs nid1\" PID AID .\n    interpret Sink2: Post_RECEIVER \"UIDs nid2\" PID AID .\n    show ?case using 6 by (elim sync_cases) auto\nnext\n  case (7 nid1 trn1 nid2 trn2)\n    interpret Sink1: Post_RECEIVER \"UIDs nid1\" PID AID .\n    interpret Sink2: Post_RECEIVER \"UIDs nid2\" PID AID .\n    show ?case using 7(2,4,6-10)\n      using Iss.validTrans_isCOMact_open[OF 7(2)] Iss.validTrans_isCOMact_open[OF 7(4)]\n      by (elim sync_cases) (auto split: prod.splits, auto simp: sendPost_def)\nnext\n  case (8 nid1 trn1 nid2 trn2)\n    interpret Sink1: Post_RECEIVER \"UIDs nid1\" PID AID .\n    interpret Sink2: Post_RECEIVER \"UIDs nid2\" PID AID .\n    show ?case using 8(2,4,6-10,11,12,13)\n      apply (elim syncO_cases; cases trn1; cases trn2)\n          apply (auto simp: Iss.g_simps ObservationSetup_RECEIVER.g_simps split: prod.splits)\n      apply (auto simp: sendPost_def split: prod.splits elim: syncVE)[]\n      done\nnext\n  case (9 nid trn)\n    then show ?case\n      by (cases \"(nid,trn)\" rule: tgtNodeOf.cases)\n         (auto simp: ObservationSetup_RECEIVER.\\<gamma>.simps)\nnext\n  case (10 nid trn) then show ?case by (cases trn) (auto simp: \\<phi>_defs)\nnext\n  case (11 vSrc nid vn) then show ?case by (cases vSrc rule: value_cases) (auto simp: syncV_def)\nnext\n  case (12 vSrc nid vn) then show ?case by (cases vSrc rule: value_cases) (auto simp: syncV_def)\nqed\n\nlemma list_all_Not_isl_projectSrcV: \"list_all (Not o isl) (Net.projectSrcV aid vlSrc)\"\nproof (induction vlSrc)\n  case (Cons vSrc vlSrc') then show ?case by (cases vSrc rule: value_cases) auto\nqed auto\n\ncontext\nfixes AID' :: apiID\nassumes AID': \"AID' \\<in> AIDs - {AID}\"\nbegin\n\ninterpretation Recv: Post_RECEIVER \"UIDs AID'\" PID AID by unfold_locales\n\nlemma Iss_BC_BO_tgtAPI:\nshows \"(Iss.BC vl vl1 \\<longrightarrow> map Iss.tgtAPI (filter Iss.isPValS vl) =\n                          map Iss.tgtAPI (filter Iss.isPValS vl1)) \\<and>\n       (Iss.BO vl vl1 \\<longrightarrow> map Iss.tgtAPI (filter Iss.isPValS vl) =\n                          map Iss.tgtAPI (filter Iss.isPValS vl1))\"\nby (induction rule: Iss.BC_BO.induct) auto\n\nlemma Iss_B_Recv_B_aux:\nassumes \"list_all isl vl\"\nand \"list_all isl vl1\"\nand \"map Iss.tgtAPI (filter Iss.isPValS (map projl vl)) =\n     map Iss.tgtAPI (filter Iss.isPValS (map projl vl1))\"\nshows \"length (map projr (Net.projectSrcV AID' vl)) = length (map projr (Net.projectSrcV AID' vl1))\"\nusing assms proof (induction vl vl1 rule: list22_induct)\n  case (ConsCons v vl v1 vl1)\n    consider (SendSend) aid pst pst1 where \"v = Inl (Iss.PValS aid pst)\" \"v1 = Inl (Iss.PValS aid pst1)\"\n           | (Internal) \"comOfV AID v = Internal\" \"\\<not>Iss.isPValS (projl v)\"\n           | (Internal1) \"comOfV AID v1 = Internal\" \"\\<not>Iss.isPValS (projl v1)\"\n      using ConsCons(4-6) by (cases v rule: value_cases; cases v1 rule: value_cases) auto\n    then show ?case proof cases\n      case (SendSend) then show ?thesis using ConsCons.IH(1) ConsCons.prems by auto\n    next\n      case (Internal) then show ?thesis using ConsCons.IH(2)[of \"v1 # vl1\"] ConsCons.prems by auto\n    next\n      case (Internal1) then show ?thesis using ConsCons.IH(3)[of \"v # vl\"] ConsCons.prems by auto\n    qed\nqed (auto simp: comOfV_AID)\n\nlemma Iss_B_Recv_B:\nassumes \"B AID vl vl1\"\nshows \"Recv.B (map projr (Net.projectSrcV AID' vl)) (map projr (Net.projectSrcV AID' vl1))\"\nusing assms Iss_B_Recv_B_aux Iss_BC_BO_tgtAPI by (auto simp: Iss.B_def Recv.B_def)\n\nend\n\nlemma map_projl_Inl: \"map (projl o Inl) vl = vl\"\nby (induction vl) auto\n\nlemma these_map_Inl_projl: \"list_all isl vl \\<Longrightarrow> these (map (Some o Inl o projl) vl) = vl\"\nby (induction vl) auto\n\nlemma map_projr_Inr: \"map (projr o Inr) vl = vl\"\nby (induction vl) auto\n\nlemma these_map_Inr_projr: \"list_all (Not o isl) vl \\<Longrightarrow> these (map (Some o Inr o projr) vl) = vl\"\nby (induction vl) auto\n\nsublocale BD_Security_TS_Network_Preserve_Source_Security_getTgtV\nwhere istate = \"\\<lambda>_. istate\" and validTrans = validTrans and srcOf = \"\\<lambda>_. srcOf\" and tgtOf = \"\\<lambda>_. tgtOf\"\n  and nodes = AIDs and comOf = comOf and tgtNodeOf = tgtNodeOf\n  and sync = sync and \\<phi> = \\<phi> and f = f and \\<gamma> = \\<gamma> and g = g and T = T and B = B\n  and comOfV = comOfV and tgtNodeOfV = tgtNodeOfV and syncV = syncV\n  and comOfO = comOfO and tgtNodeOfO = tgtNodeOfO and syncO = syncO (*and cmpO = cmpO*)\n  and source = AID and getTgtV = getTgtV\nproof (unfold_locales, goal_cases)\n  case 1 show ?case using AID_in_AIDs .\nnext\n  case 2\n    interpret Iss': BD_Security_TS_Trans\n      istate System_Specification.validTrans srcOf tgtOf Iss.\\<phi> Iss.f Iss.\\<gamma> Iss.g Iss.T Iss.B\n      istate System_Specification.validTrans srcOf tgtOf Iss.\\<phi> \"\\<lambda>trn. Inl (Iss.f trn)\" Iss.\\<gamma> Iss.g Iss.T \"B AID\"\n      id id Some \"Some o Inl\"\n    proof (unfold_locales, goal_cases)\n      case (11 vl' vl1' tr) then show ?case\n        by (intro exI[of _ \"map projl vl1'\"]) (auto simp: map_projl_Inl these_map_Inl_projl)\n    qed auto\n    show ?case using Iss.secure Iss'.translate_secure by auto\nnext\n  case (3 aid tr vl' vl1)\n    then show ?case\n      using Iss_B_Recv_B[of aid \"(Net.lV AID tr)\" vl1] list_all_Not_isl_projectSrcV\n      by auto\nqed\n\ntheorem secure: \"secure\"\nproof (intro preserve_source_secure ballI)\n  fix aid\n  assume aid: \"aid \\<in> AIDs - {AID}\"\n  interpret Node: Post_RECEIVER \"UIDs aid\" PID AID .\n  interpret Node': BD_Security_TS_Trans\n    istate System_Specification.validTrans srcOf tgtOf Node.\\<phi> Node.f Node.\\<gamma> Node.g Node.T Node.B\n    istate System_Specification.validTrans srcOf tgtOf Node.\\<phi> \"\\<lambda>trn. Inr (Node.f trn)\" Node.\\<gamma> Node.g Node.T \"B aid\"\n    id id Some \"Some o Inr\"\n  proof (unfold_locales, goal_cases)\n    case (11 vl' vl1' tr) then show ?case using aid\n      by (intro exI[of _ \"map projr vl1'\"]) (auto simp: map_projr_Inr these_map_Inr_projr)\n  qed auto\n  show \"Net.lsecure aid\"\n    using aid Node.Post_secure Node'.translate_secure by auto\nqed\n\nend  (* context Post_Network *)\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/CoSMeDis/Post_Confidentiality/DYNAMIC_Post_Network.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.538983220687684, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.2547684625947325}}
{"text": "(* Author: Florian Haftmann, TU Muenchen *)\n\nsection \\<open>Reflecting Pure types into HOL\\<close>\n\ntheory Typerep\nimports String\nbegin\n\ndatatype typerep = Typerep String.literal \"typerep list\"\n\nclass typerep =\n  fixes typerep :: \"'a itself \\<Rightarrow> typerep\"\nbegin\n\ndefinition typerep_of :: \"'a \\<Rightarrow> typerep\" where\n  [simp]: \"typerep_of x = typerep TYPE('a)\"\n\nend\n\nsyntax\n  \"_TYPEREP\" :: \"type => logic\"  (\"(1TYPEREP/(1'(_')))\")\n\nparse_translation \\<open>\n  let\n    fun typerep_tr (*\"_TYPEREP\"*) [ty] =\n          Syntax.const \\<^const_syntax>\\<open>typerep\\<close> $\n            (Syntax.const \\<^syntax_const>\\<open>_constrain\\<close> $ Syntax.const \\<^const_syntax>\\<open>Pure.type\\<close> $\n              (Syntax.const \\<^type_syntax>\\<open>itself\\<close> $ ty))\n      | typerep_tr (*\"_TYPEREP\"*) ts = raise TERM (\"typerep_tr\", ts);\n  in [(\\<^syntax_const>\\<open>_TYPEREP\\<close>, K typerep_tr)] end\n\\<close>\n\ntyped_print_translation \\<open>\n  let\n    fun typerep_tr' ctxt (*\"typerep\"*) \\<^Type>\\<open>fun \\<^Type>\\<open>itself T\\<close> _\\<close>\n            (Const (\\<^const_syntax>\\<open>Pure.type\\<close>, _) :: ts) =\n          Term.list_comb\n            (Syntax.const \\<^syntax_const>\\<open>_TYPEREP\\<close> $ Syntax_Phases.term_of_typ ctxt T, ts)\n      | typerep_tr' _ T ts = raise Match;\n  in [(\\<^const_syntax>\\<open>typerep\\<close>, typerep_tr')] end\n\\<close>\n\nsetup \\<open>\nlet\n\nfun add_typerep tyco thy =\n  let\n    val sorts = replicate (Sign.arity_number thy tyco) \\<^sort>\\<open>typerep\\<close>;\n    val vs = Name.invent_names Name.context \"'a\" sorts;\n    val ty = Type (tyco, map TFree vs);\n    val lhs = \\<^Const>\\<open>typerep ty\\<close> $ Free (\"T\", Term.itselfT ty);\n    val rhs = \\<^Const>\\<open>Typerep\\<close> $ HOLogic.mk_literal tyco\n      $ HOLogic.mk_list \\<^Type>\\<open>typerep\\<close> (map (HOLogic.mk_typerep o TFree) vs);\n    val eq = HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs));\n  in\n    thy\n    |> Class.instantiation ([tyco], vs, \\<^sort>\\<open>typerep\\<close>)\n    |> `(fn lthy => Syntax.check_term lthy eq)\n    |-> (fn eq => Specification.definition NONE [] [] (Binding.empty_atts, eq))\n    |> snd\n    |> Class.prove_instantiation_exit (fn ctxt => Class.intro_classes_tac ctxt [])\n  end;\n\nfun ensure_typerep tyco thy =\n  if not (Sorts.has_instance (Sign.classes_of thy) tyco \\<^sort>\\<open>typerep\\<close>)\n    andalso Sorts.has_instance (Sign.classes_of thy) tyco \\<^sort>\\<open>type\\<close>\n  then add_typerep tyco thy else thy;\n\nin\n\nadd_typerep \\<^type_name>\\<open>fun\\<close>\n#> Typedef.interpretation (Local_Theory.background_theory o ensure_typerep)\n#> Code.type_interpretation ensure_typerep\n\nend\n\\<close>\n\n\n\nlemma [code nbe]:\n  \"HOL.equal (x :: typerep) x \\<longleftrightarrow> True\"\n  by (fact equal_refl)\n\ncode_printing\n  type_constructor typerep \\<rightharpoonup> (Eval) \"Term.typ\"\n| constant Typerep \\<rightharpoonup> (Eval) \"Term.Type/ (_, _)\"\n\ncode_reserved Eval Term\n\nhide_const (open) typerep Typerep\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/Typerep.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.2547684625947325}}
{"text": "section \\<open>Tree to Graph\\<close>\n\ntheory TreeToGraph\n  imports \n    Semantics.IRTreeEval\n    Graph.IRGraph\nbegin\n\nsubsection \\<open>Subgraph to Data-flow Tree\\<close>\n\nfun find_node_and_stamp :: \"IRGraph \\<Rightarrow> (IRNode \\<times> Stamp) \\<Rightarrow> ID option\" where\n  \"find_node_and_stamp g (n,s) =\n     find (\\<lambda>i. kind g i = n \\<and> stamp g i = s) (sorted_list_of_set(ids g))\"\n\nexport_code find_node_and_stamp\n\n(* These kinds of nodes are evaluated during the control flow, so are already in MapState. *)\nfun is_preevaluated :: \"IRNode \\<Rightarrow> bool\" where\n  \"is_preevaluated (InvokeNode n _ _ _ _ _) = True\" |\n  \"is_preevaluated (InvokeWithExceptionNode n _ _ _ _ _ _) = True\" |\n  \"is_preevaluated (NewInstanceNode n _ _ _) = True\" |\n  \"is_preevaluated (LoadFieldNode n _ _ _) = True\" |\n  \"is_preevaluated (SignedDivNode n _ _ _ _ _) = True\" |\n  \"is_preevaluated (SignedRemNode n _ _ _ _ _) = True\" |\n  \"is_preevaluated (ValuePhiNode n _ _) = True\" |\n  \"is_preevaluated _ = False\"\n\n\ninductive\n  rep :: \"IRGraph \\<Rightarrow> ID \\<Rightarrow> IRExpr \\<Rightarrow> bool\" (\"_ \\<turnstile> _ \\<simeq> _\" 55)\n  for g where\n\n  ConstantNode:\n  \"\\<lbrakk>kind g n = ConstantNode c\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> (ConstantExpr c)\" |\n\n  ParameterNode:\n  \"\\<lbrakk>kind g n = ParameterNode i;\n    stamp g n = s\\<rbrakk>\n    \\<Longrightarrow> g  \\<turnstile> n \\<simeq> (ParameterExpr i s)\" |\n\n  ConditionalNode:\n  \"\\<lbrakk>kind g n = ConditionalNode c t f;\n    g \\<turnstile> c \\<simeq> ce;\n    g \\<turnstile> t \\<simeq> te;\n    g \\<turnstile> f \\<simeq> fe\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> (ConditionalExpr ce te fe)\" |\n\n(* Unary nodes *)\n  AbsNode:\n  \"\\<lbrakk>kind g n = AbsNode x;\n    g \\<turnstile> x \\<simeq> xe\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> (UnaryExpr UnaryAbs xe)\" |\n\n  NotNode:\n  \"\\<lbrakk>kind g n = NotNode x;\n    g \\<turnstile> x \\<simeq> xe\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> (UnaryExpr UnaryNot xe)\" |\n\n  NegateNode:\n  \"\\<lbrakk>kind g n = NegateNode x;\n    g \\<turnstile> x \\<simeq> xe\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> (UnaryExpr UnaryNeg xe)\" |\n\n  LogicNegationNode:\n  \"\\<lbrakk>kind g n = LogicNegationNode x;\n    g \\<turnstile> x \\<simeq> xe\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> (UnaryExpr UnaryLogicNegation xe)\" |\n\n(* Binary nodes *)\n  AddNode:\n  \"\\<lbrakk>kind g n = AddNode x y;\n    g \\<turnstile> x \\<simeq> xe;\n    g \\<turnstile> y \\<simeq> ye\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> (BinaryExpr BinAdd xe ye)\" |\n\n  MulNode:\n  \"\\<lbrakk>kind g n = MulNode x y;\n    g \\<turnstile> x \\<simeq> xe;\n    g \\<turnstile> y \\<simeq> ye\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> (BinaryExpr BinMul xe ye)\" |\n\n  SubNode:\n  \"\\<lbrakk>kind g n = SubNode x y;\n    g \\<turnstile> x \\<simeq> xe;\n    g \\<turnstile> y \\<simeq> ye\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> (BinaryExpr BinSub xe ye)\" |\n\n  AndNode:\n  \"\\<lbrakk>kind g n = AndNode x y;\n    g \\<turnstile> x \\<simeq> xe;\n    g \\<turnstile> y \\<simeq> ye\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> (BinaryExpr BinAnd xe ye)\" |\n\n  OrNode:\n  \"\\<lbrakk>kind g n = OrNode x y;\n    g \\<turnstile> x \\<simeq> xe;\n    g \\<turnstile> y \\<simeq> ye\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> (BinaryExpr BinOr xe ye)\" |\n\n  XorNode:\n  \"\\<lbrakk>kind g n = XorNode x y;\n    g \\<turnstile> x \\<simeq> xe;\n    g \\<turnstile> y \\<simeq> ye\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> (BinaryExpr BinXor xe ye)\" |\n\n  ShortCircuitOrNode:\n  \"\\<lbrakk>kind g n = ShortCircuitOrNode x y;\n    g \\<turnstile> x \\<simeq> xe;\n    g \\<turnstile> y \\<simeq> ye\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> (BinaryExpr BinShortCircuitOr xe ye)\" |\n\n  LeftShiftNode:\n  \"\\<lbrakk>kind g n = LeftShiftNode x y;\n    g \\<turnstile> x \\<simeq> xe;\n    g \\<turnstile> y \\<simeq> ye\\<rbrakk>\n   \\<Longrightarrow> g \\<turnstile> n \\<simeq> (BinaryExpr BinLeftShift xe ye)\" |\n\n  RightShiftNode:\n  \"\\<lbrakk>kind g n = RightShiftNode x y;\n    g \\<turnstile> x \\<simeq> xe;\n    g \\<turnstile> y \\<simeq> ye\\<rbrakk>\n   \\<Longrightarrow> g \\<turnstile> n \\<simeq> (BinaryExpr BinRightShift xe ye)\" |\n\n  UnsignedRightShiftNode:\n  \"\\<lbrakk>kind g n = UnsignedRightShiftNode x y;\n    g \\<turnstile> x \\<simeq> xe;\n    g \\<turnstile> y \\<simeq> ye\\<rbrakk>\n   \\<Longrightarrow> g \\<turnstile> n \\<simeq> (BinaryExpr BinURightShift xe ye)\" |\n\n  IntegerBelowNode:\n  \"\\<lbrakk>kind g n = IntegerBelowNode x y;\n    g \\<turnstile> x \\<simeq> xe;\n    g \\<turnstile> y \\<simeq> ye\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> (BinaryExpr BinIntegerBelow xe ye)\" |\n\n  IntegerEqualsNode:\n  \"\\<lbrakk>kind g n = IntegerEqualsNode x y;\n    g \\<turnstile> x \\<simeq> xe;\n    g \\<turnstile> y \\<simeq> ye\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> (BinaryExpr BinIntegerEquals xe ye)\" |\n\n  IntegerLessThanNode:\n  \"\\<lbrakk>kind g n = IntegerLessThanNode x y;\n    g \\<turnstile> x \\<simeq> xe;\n    g \\<turnstile> y \\<simeq> ye\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> (BinaryExpr BinIntegerLessThan xe ye)\" |\n\n(* Convert Nodes *)\n  NarrowNode:\n  \"\\<lbrakk>kind g n = NarrowNode inputBits resultBits x;\n    g \\<turnstile> x \\<simeq> xe\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> (UnaryExpr (UnaryNarrow inputBits resultBits) xe)\" |\n\n  SignExtendNode:\n  \"\\<lbrakk>kind g n = SignExtendNode inputBits resultBits x;\n    g \\<turnstile> x \\<simeq> xe\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> (UnaryExpr (UnarySignExtend inputBits resultBits) xe)\" |\n\n  ZeroExtendNode:\n  \"\\<lbrakk>kind g n = ZeroExtendNode inputBits resultBits x;\n    g \\<turnstile> x \\<simeq> xe\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> (UnaryExpr (UnaryZeroExtend inputBits resultBits) xe)\" |\n\n(* Leaf Node *)\n  LeafNode:\n  \"\\<lbrakk>is_preevaluated (kind g n);\n    stamp g n = s\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> (LeafExpr n s)\" |\n\n(* Ref Node *)\n  RefNode:\n  \"\\<lbrakk>kind g n = RefNode n';\n    g \\<turnstile> n' \\<simeq> e\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> n \\<simeq> e\"\n\ncode_pred (modes: i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool as exprE) rep .\n\n\ninductive\n  replist :: \"IRGraph \\<Rightarrow> ID list \\<Rightarrow> IRExpr list \\<Rightarrow> bool\" (\"_ \\<turnstile> _ \\<simeq>\\<^sub>L _\" 55)\n  for g where\n\n  RepNil:\n  \"g \\<turnstile> [] \\<simeq>\\<^sub>L []\" |\n\n  RepCons:\n  \"\\<lbrakk>g \\<turnstile> x \\<simeq> xe;\n    g \\<turnstile> xs \\<simeq>\\<^sub>L xse\\<rbrakk>\n    \\<Longrightarrow> g \\<turnstile> x#xs \\<simeq>\\<^sub>L xe#xse\"\n\ncode_pred (modes: i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool as exprListE) replist .\n\ndefinition wf_term_graph :: \"MapState \\<Rightarrow> Params \\<Rightarrow> IRGraph \\<Rightarrow> ID \\<Rightarrow> bool\" where\n  \"wf_term_graph m p g n = (\\<exists> e. (g \\<turnstile> n \\<simeq> e) \\<and> (\\<exists> v. ([m, p] \\<turnstile> e \\<mapsto> v)))\"\n\nvalues \"{t. eg2_sq \\<turnstile> 4 \\<simeq> t}\"\n\ninductive_cases ConstantNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (ConstantExpr c)\"\ninductive_cases ParameterNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (ParameterExpr i s)\"\ninductive_cases ConditionalNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (ConditionalExpr ce te fe)\"\ninductive_cases AbsNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (UnaryExpr UnaryAbs xe)\"\ninductive_cases NotNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (UnaryExpr UnaryNot xe)\"\ninductive_cases NegateNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (UnaryExpr UnaryNeg xe)\"\ninductive_cases LogicNegationNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (UnaryExpr UnaryLogicNegation xe)\"\ninductive_cases AddNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (BinaryExpr BinAdd xe ye)\"\ninductive_cases MulNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (BinaryExpr BinMul xe ye)\"\ninductive_cases SubNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (BinaryExpr BinSub xe ye)\"\ninductive_cases AndNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (BinaryExpr BinAnd xe ye)\"\ninductive_cases OrNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (BinaryExpr BinOr xe ye)\"\ninductive_cases XorNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (BinaryExpr BinXor xe ye)\"\ninductive_cases ShortCircuitOrE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (BinaryExpr BinShortCircuitOr xe ye)\"\ninductive_cases LeftShiftNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (BinaryExpr BinLeftShift xe ye)\"\ninductive_cases RightShiftNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (BinaryExpr BinRightShift xe ye)\"\ninductive_cases UnsignedRightShiftNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (BinaryExpr BinURightShift xe ye)\"\ninductive_cases IntegerBelowNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (BinaryExpr BinIntegerBelow xe ye)\"\ninductive_cases IntegerEqualsNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (BinaryExpr BinIntegerEquals xe ye)\"\ninductive_cases IntegerLessThanNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (BinaryExpr BinIntegerLessThan xe ye)\"\ninductive_cases NarrowNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (UnaryExpr (UnaryNarrow ib rb) xe)\"\ninductive_cases SignExtendNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (UnaryExpr (UnarySignExtend ib rb) xe)\"\ninductive_cases ZeroExtendNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (UnaryExpr (UnaryZeroExtend ib rb) xe)\"\ninductive_cases LeafNodeE[elim!]:\\<^marker>\\<open>tag invisible\\<close>\n  \"g \\<turnstile> n \\<simeq> (LeafExpr n s)\"\n\n(* group those forward rules into a named set *)\nlemmas RepE\\<^marker>\\<open>tag invisible\\<close> = \n  ConstantNodeE\n  ParameterNodeE\n  ConditionalNodeE\n  AbsNodeE\n  NotNodeE\n  NegateNodeE\n  LogicNegationNodeE\n  AddNodeE\n  MulNodeE\n  SubNodeE\n  AndNodeE\n  OrNodeE\n  XorNodeE\n  ShortCircuitOrE\n  LeftShiftNodeE\n  RightShiftNodeE\n  UnsignedRightShiftNodeE\n  IntegerBelowNodeE\n  IntegerEqualsNodeE\n  IntegerLessThanNodeE\n  NarrowNodeE\n  SignExtendNodeE\n  ZeroExtendNodeE\n  LeafNodeE\n\n\nsubsection \\<open>Data-flow Tree to Subgraph\\<close>\n\nfun unary_node :: \"IRUnaryOp \\<Rightarrow> ID \\<Rightarrow> IRNode\" where\n  \"unary_node UnaryAbs v = AbsNode v\" |\n  \"unary_node UnaryNot v = NotNode v\" |\n  \"unary_node UnaryNeg v = NegateNode v\" |\n  \"unary_node UnaryLogicNegation v = LogicNegationNode v\" |\n  \"unary_node (UnaryNarrow ib rb) v = NarrowNode ib rb v\" |\n  \"unary_node (UnarySignExtend ib rb) v = SignExtendNode ib rb v\" |\n  \"unary_node (UnaryZeroExtend ib rb) v = ZeroExtendNode ib rb v\"\n\n\n(* Creates the appropriate IRNode for a given binary operator. *)\nfun bin_node :: \"IRBinaryOp \\<Rightarrow> ID \\<Rightarrow> ID \\<Rightarrow> IRNode\" where\n  \"bin_node BinAdd x y = AddNode x y\" |\n  \"bin_node BinMul x y = MulNode x y\" |\n  \"bin_node BinSub x y = SubNode x y\" |\n  \"bin_node BinAnd x y = AndNode x y\" |\n  \"bin_node BinOr  x y = OrNode x y\" |\n  \"bin_node BinXor x y = XorNode x y\" |\n  \"bin_node BinShortCircuitOr x y = ShortCircuitOrNode x y\" |\n  \"bin_node BinLeftShift x y = LeftShiftNode x y\" |\n  \"bin_node BinRightShift x y = RightShiftNode x y\" |\n  \"bin_node BinURightShift x y = UnsignedRightShiftNode x y\" |\n  \"bin_node BinIntegerEquals x y = IntegerEqualsNode x y\" |\n  \"bin_node BinIntegerLessThan x y = IntegerLessThanNode x y\" |\n  \"bin_node BinIntegerBelow x y = IntegerBelowNode x y\"\n\n\n\ninductive fresh_id :: \"IRGraph \\<Rightarrow> ID \\<Rightarrow> bool\" where\n  \"n \\<notin> ids g \\<Longrightarrow> fresh_id g n\"\n\ncode_pred fresh_id .\n\n(* This generates a specific fresh ID (max+1), in a code-friendly way. *)\nfun get_fresh_id :: \"IRGraph \\<Rightarrow> ID\" where\n(* Previous attempts - cannot generate code due to nat not Enum. \n  \"get_fresh_id g = 100\"\n  \"get_fresh_id g = (ffold max (0::nat) (f_ids g))\"\n  \"get_fresh_id g = fst(last(as_list g))\"\n  \"get_fresh_id g = last(sorted_list_of_set (dom (Rep_IRGraph g)))\"\n*)\n  \"get_fresh_id g = last(sorted_list_of_set(ids g)) + 1\"\n\nexport_code get_fresh_id\n(* these examples return 6 and 7 respectively *)\nvalue \"get_fresh_id eg2_sq\"\nvalue \"get_fresh_id (add_node 6 (ParameterNode 2, default_stamp) eg2_sq)\"\n\n(* Second version of tree insertion into graph:\n\n      g \\<triangleleft> expr \\<leadsto> (g',n) re-inserts expr into g and returns the new root n.\n\n   This means that we can try to re-use existing nodes by finding node IDs bottom-up.\n*)\ninductive\n  unrep :: \"IRGraph \\<Rightarrow> IRExpr \\<Rightarrow> (IRGraph \\<times> ID) \\<Rightarrow> bool\" (\"_ \\<oplus> _ \\<leadsto> _\" 55)\n   where\n\n  ConstantNodeSame:\n  \"\\<lbrakk>find_node_and_stamp g (ConstantNode c, constantAsStamp c) = Some n\\<rbrakk>\n    \\<Longrightarrow> g \\<oplus> (ConstantExpr c) \\<leadsto> (g, n)\" |\n\n  ConstantNodeNew:\n  \"\\<lbrakk>find_node_and_stamp g (ConstantNode c, constantAsStamp c) = None;\n    n = get_fresh_id g;\n    g' = add_node n (ConstantNode c, constantAsStamp c) g \\<rbrakk>\n    \\<Longrightarrow> g \\<oplus> (ConstantExpr c) \\<leadsto> (g', n)\" |\n\n  ParameterNodeSame:\n  \"\\<lbrakk>find_node_and_stamp g (ParameterNode i, s) = Some n\\<rbrakk>\n    \\<Longrightarrow> g \\<oplus> (ParameterExpr i s) \\<leadsto> (g, n)\" |\n\n  ParameterNodeNew:\n  \"\\<lbrakk>find_node_and_stamp g (ParameterNode i, s) = None;\n    n = get_fresh_id g;\n    g' = add_node n (ParameterNode i, s) g\\<rbrakk>\n    \\<Longrightarrow> g \\<oplus> (ParameterExpr i s) \\<leadsto> (g', n)\" |\n\n  ConditionalNodeSame:\n  \"\\<lbrakk>find_node_and_stamp g4 (ConditionalNode c t f, s') = Some n;\n    g \\<oplus> ce \\<leadsto> (g2, c);\n    g2 \\<oplus> te \\<leadsto> (g3, t);\n    g3 \\<oplus> fe \\<leadsto> (g4, f);\n    s' = meet (stamp g4 t) (stamp g4 f)\\<rbrakk>\n    \\<Longrightarrow> g \\<oplus> (ConditionalExpr ce te fe) \\<leadsto> (g4, n)\" |\n\n  ConditionalNodeNew:\n  \"\\<lbrakk>find_node_and_stamp g4 (ConditionalNode c t f, s') = None;\n    g \\<oplus> ce \\<leadsto> (g2, c);\n    g2 \\<oplus> te \\<leadsto> (g3, t);\n    g3 \\<oplus> fe \\<leadsto> (g4, f);\n    s' = meet (stamp g4 t) (stamp g4 f);\n    n = get_fresh_id g4;\n    g' = add_node n (ConditionalNode c t f, s') g4\\<rbrakk>\n    \\<Longrightarrow> g \\<oplus> (ConditionalExpr ce te fe) \\<leadsto> (g', n)\" |\n\n  UnaryNodeSame:\n  \"\\<lbrakk>find_node_and_stamp g2 (unary_node op x, s') = Some n;\n    g \\<oplus> xe \\<leadsto> (g2, x);\n    s' = stamp_unary op (stamp g2 x)\\<rbrakk>\n    \\<Longrightarrow> g \\<oplus> (UnaryExpr op xe) \\<leadsto> (g2, n)\" |\n\n  UnaryNodeNew:\n  \"\\<lbrakk>find_node_and_stamp g2 (unary_node op x, s') = None;\n    g \\<oplus> xe \\<leadsto> (g2, x);\n    s' = stamp_unary op (stamp g2 x);\n    n = get_fresh_id g2;\n    g' = add_node n (unary_node op x, s') g2\\<rbrakk>\n    \\<Longrightarrow> g \\<oplus> (UnaryExpr op xe) \\<leadsto> (g', n)\" |\n\n  BinaryNodeSame:\n  \"\\<lbrakk>find_node_and_stamp g3 (bin_node op x y, s') = Some n;\n    g \\<oplus> xe \\<leadsto> (g2, x);\n    g2 \\<oplus> ye \\<leadsto> (g3, y);\n    s' = stamp_binary op (stamp g3 x) (stamp g3 y)\\<rbrakk>\n    \\<Longrightarrow> g \\<oplus> (BinaryExpr op xe ye) \\<leadsto> (g3, n)\" |\n\n  BinaryNodeNew:\n  \"\\<lbrakk>find_node_and_stamp g3 (bin_node op x y, s') = None;\n    g \\<oplus> xe \\<leadsto> (g2, x);\n    g2 \\<oplus> ye \\<leadsto> (g3, y);\n    s' = stamp_binary op (stamp g3 x) (stamp g3 y);\n    n = get_fresh_id g3;\n    g' = add_node n (bin_node op x y, s') g3\\<rbrakk>\n    \\<Longrightarrow> g \\<oplus> (BinaryExpr op xe ye) \\<leadsto> (g', n)\" |\n\n  AllLeafNodes:\n  \"\\<lbrakk>stamp g n = s;\n    is_preevaluated (kind g n)\\<rbrakk>\n    \\<Longrightarrow> g \\<oplus> (LeafExpr n s) \\<leadsto> (g, n)\"\n\n(*  UnrepNil:\n  \"g \\<triangleleft>\\<^sub>L [] \\<leadsto> (g, [])\" |\n\n(* TODO: this will fail for [xe,ye] where they are not equal.\n         Figure out how to generate code for this?\n*)\n  UnrepCons:\n  \"\\<lbrakk>g \\<triangleleft> xe \\<leadsto> (g2, x);\n    g2 \\<triangleleft>\\<^sub>L xes \\<leadsto> (g3, xs)\\<rbrakk>\n    \\<Longrightarrow> g \\<triangleleft>\\<^sub>L (xe#xes) \\<leadsto> (g3, x#xs)\"*)\n\ncode_pred (modes: i \\<Rightarrow> i \\<Rightarrow> o \\<Rightarrow> bool as unrepE)\n(*\n  [show_steps,show_mode_inference,show_intermediate_results] \n*)  unrep .\n\ntext_raw \\<open>\\Snip{unrepRules}%\n\\begin{center}\n@{thm[mode=Rule] unrep.ConstantNodeSame [no_vars]}\\\\[8px]\n@{thm[mode=Rule] unrep.ConstantNodeNew [no_vars]}\\\\[8px]\n@{thm[mode=Rule] unrep.ParameterNodeSame [no_vars]}\\\\[8px]\n@{thm[mode=Rule] unrep.ParameterNodeNew [no_vars]}\\\\[8px]\n@{thm[mode=Rule] unrep.ConditionalNodeSame [no_vars]}\\\\[8px]\n@{thm[mode=Rule] unrep.ConditionalNodeNew [no_vars]}\\\\[8px]\n@{thm[mode=Rule] unrep.BinaryNodeSame [no_vars]}\\\\[8px]\n@{thm[mode=Rule] unrep.BinaryNodeNew [no_vars]}\\\\[8px]\n@{thm[mode=Rule] unrep.UnaryNodeSame [no_vars]}\\\\[8px]\n@{thm[mode=Rule] unrep.UnaryNodeNew [no_vars]}\\\\[8px]\n@{thm[mode=Rule] unrep.AllLeafNodes [no_vars]}\\\\[8px]\n\\end{center}\n\\EndSnip\\<close>\n\n(*\ninstantiation IRGraph :: equal begin\n\ndefinition \"(g1 = g2) \\<longleftrightarrow> \n              (f_ids g1 = f_ids g2 \\<and>\n               (\\<forall>n. (n \\<in> ids g1 \\<Longrightarrow> (Rep_IRGraph g1 n = Rep_IRGraph g2 n))))\"\ninstance proof \n  fix x y :: IRGraph\n  show \"x = y \\<longleftrightarrow> x \\<le> y \\<and> \\<not> (y \\<le> x)\" by (simp add: equiv_exprs_def; auto)\n  show \"x \\<le> x\" by simp\n  show \"x \\<le> y \\<Longrightarrow> y \\<le> z \\<Longrightarrow> x \\<le> z\" by simp \nqed\nend\n*)\n\nvalues \"{(n, g) . (eg2_sq \\<oplus> sq_param0 \\<leadsto> (g, n))}\"\n\n\nsubsection \\<open>Lift Data-flow Tree Semantics\\<close>\n\ndefinition encodeeval :: \"IRGraph \\<Rightarrow> MapState \\<Rightarrow> Params \\<Rightarrow> ID \\<Rightarrow> Value \\<Rightarrow> bool\" \n  (\"[_,_,_] \\<turnstile> _ \\<mapsto> _\" 50)\n  where\n  \"encodeeval g m p n v = (\\<exists> e. (g \\<turnstile> n \\<simeq> e) \\<and> ([m,p] \\<turnstile> e \\<mapsto> v))\"\n\n\nsubsection \\<open>Graph Refinement\\<close>\n\ndefinition graph_represents_expression :: \"IRGraph \\<Rightarrow> ID \\<Rightarrow> IRExpr \\<Rightarrow> bool\" \n  (\"_ \\<turnstile> _ \\<unlhd> _\" 50)\n  where\n  \"(g \\<turnstile> n \\<unlhd> e) = (\\<exists>e' . (g \\<turnstile> n \\<simeq> e') \\<and> (e' \\<le> e))\"\n\ndefinition graph_refinement :: \"IRGraph \\<Rightarrow> IRGraph \\<Rightarrow> bool\" where\n  \"graph_refinement g\\<^sub>1 g\\<^sub>2 = \n        ((ids g\\<^sub>1 \\<subseteq> ids g\\<^sub>2) \\<and>\n        (\\<forall> n . n \\<in> ids g\\<^sub>1 \\<longrightarrow> (\\<forall>e. (g\\<^sub>1 \\<turnstile> n \\<simeq> e) \\<longrightarrow> (g\\<^sub>2 \\<turnstile> n \\<unlhd> e))))\"\n\nlemma graph_refinement:\n  \"graph_refinement g1 g2 \\<Longrightarrow> (\\<forall>n m p v. n \\<in> ids g1 \\<longrightarrow> ([g1, m, p] \\<turnstile> n \\<mapsto> v) \\<longrightarrow> ([g2, m, p] \\<turnstile> n \\<mapsto> v))\"\n  by (meson encodeeval_def graph_refinement_def graph_represents_expression_def le_expr_def)\n\nsubsection \\<open>Maximal Sharing\\<close>\n\ndefinition maximal_sharing:\n  \"maximal_sharing g = (\\<forall> n\\<^sub>1 n\\<^sub>2 . n\\<^sub>1 \\<in> true_ids g \\<and> n\\<^sub>2 \\<in> true_ids g \\<longrightarrow> \n      (\\<forall> e. (g \\<turnstile> n\\<^sub>1 \\<simeq> e) \\<and> (g \\<turnstile> n\\<^sub>2 \\<simeq> e) \\<and> (stamp g n\\<^sub>1 = stamp g n\\<^sub>2) \\<longrightarrow> n\\<^sub>1 = n\\<^sub>2))\"\n\nend", "meta": {"author": "uqcyber", "repo": "veriopt-releases", "sha": "4ffab3c91bbd699772889dbf263bb6d2582256d7", "save_path": "github-repos/isabelle/uqcyber-veriopt-releases", "path": "github-repos/isabelle/uqcyber-veriopt-releases/veriopt-releases-4ffab3c91bbd699772889dbf263bb6d2582256d7/Semantics/TreeToGraph.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5813030906443133, "lm_q2_score": 0.43782349911420193, "lm_q1q2_score": 0.2545081531917933}}
{"text": "theory RedSafeAppLemma\n  imports RedSafeCV RedSafeCase SafeSubTPX\nbegin\n    \n    (* ##### sares *)\n  \nlemma sares_lam_helper: \"\\<lbrakk> well_typed env delta r_s1 e2 tau (diff_use_env (comp_use_env r_s3 r_exa) (comp_use_env rxa (lift_use_env rx2 r)))\n      (diff_use_env (comp_use_env rxa rx2) (comp_use_env rxa (lift_use_env rx2 r))); non_prim_env env \\<rbrakk> \\<Longrightarrow>\n  well_typed env delta r_s1 e2 tau (diff_use_env (comp_use_env r_s3 r_exa) (comp_use_env rxa (lift_use_env rx2 r))) (app_req rxa rx2 r tau empty_use_env)\"\n  apply (simp add: app_req_def)\n  apply (auto)\n   apply (rule_tac rx=\"diff_use_env (comp_use_env rxa rx2) (comp_use_env rxa (lift_use_env rx2 r))\" in prim_type_no_req)\n     apply (auto)\n  apply (cut_tac r=\"comp_use_env rxa (lift_use_env rx2 r)\" in comp_empty_use_env2)\n  apply (auto)\n  done \n\nlemma sares_fix_case: \"\\<lbrakk>well_typed_state s1 env delta; sub_use_env s1 r_f; app_red_exp FixApp (s1, AppExp (ConstExp FixConst) x62) ax (s2, e2);\n        e1 = AppExp (ConstExp FixConst) x62; well_typed env delta r_s2a x62 t1 r_s3 rx2;\n        leq_use_env r_s2 (diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)); (*safe_use_lift rx2 r; safe_type t1 r;*)\n        leq_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_s3; disj_use_env rx1 (lift_use_env rx2 r); leq_use_env rx r_s2; leq_use_env r_ex r_s1;\n        leq_use_env (app_req rx1 rx2 r tau r_ex) rx; leq_use_env r_s2a r_s1; leq_use_env rx1 r_s2a;\n        FunTy t1 tau r a = pure_fun (pure_fun t t (req_type t)) t Prim; fun_ty t; unlim t; leq_use_env r_s1 r_f \\<rbrakk>\n       \\<Longrightarrow> \\<exists>g_ax. well_typed (red_env env g_ax) (red_delta delta g_ax) (exp_red_use_env r_s1 g_ax) e2 tau (end_red_use_env r_s2 g_ax) (end_red_use_env rx g_ax) \\<and>\n                  well_typed_state s2 (red_env env g_ax) (red_delta delta g_ax) \\<and>\n                  sub_use_env s2 (exp_red_use_env r_f g_ax) \\<and> safe_act s1 (infl_use_env r_f r_s2) g_ax \\<and> corr_act ax g_ax\"\n  apply (case_tac x62)\n       apply (auto)\n  apply (case_tac ax)\n    apply (auto)\n  apply (simp add: pure_fun_def)\n  apply (auto)\n    (* - prelim: rxa is weak *)\n  apply (case_tac \"\\<not> weak_use_env rxa\")\n   apply (simp add: aff_use_env_def)\n   apply (case_tac \"req_type tau\")\n     apply (simp add: unlim_def)\n    apply (simp)\n   apply (simp add: null_use_env_def)\n   apply (simp add: weak_use_env_def)\n  apply (rule_tac x=\"NoResAct\" in exI)\n  apply (auto)\n    (* e2 = x52 (Fix (\\<lambda> x51. x52)). We can type the external app as: <<r_s1>> x52 <<r_s2a, rx1>> (Fix (\\<lambda> x51. x52)) <<r_s3, rx2>>\n      We can type the internal app as: <<r_s2a>> Fix <<r_s2a, {}>> (\\<lambda> x51. x52) <<r_s2a, rxa>>\n    *)\n  apply (rule_tac ?r_s2.0=\"diff_use_env (diff_use_env r_s2a (comp_use_env rxa (lift_use_env rxa UsePerm))) (comp_use_env rx2 (comp_use_env r_exa r_ex))\" and\n        rx=\"diff_use_env (diff_use_env (comp_use_env rxa rxa) (comp_use_env rxa (lift_use_env rxa UsePerm))) (comp_use_env rx2 (comp_use_env r_exa r_ex))\" in well_typed_simul_end_perm)\n     apply (rule_tac well_typed_diff_end_perm)\n      apply (rule_tac t=\"tau\" and ?rx1.0=\"rxa\" and r_s'=\"r_s'\" and r_end=\"r_end\" and ?e1.0=\"x62a\" and x=\"x61\" and\n          ?r_s2.0=\"r_s2a\" and ?r_s3.0=\"r_s2a\" and e'=\"AppExp (ConstExp FixConst) (LamExp x61 x62a)\" in safe_subst_type_preserve_x)\n               apply (auto)\n         apply (rule_tac x=\"FunTy tau tau UsePerm (req_type tau)\" in exI)\n         apply (rule_tac x=\"UsePerm\" in exI)\n         apply (auto)\n          apply (simp add: pure_fun_def)\n         apply (rule_tac x=\"r_s2a\" in exI)\n         apply (auto)\n          apply (rule_tac id_leq_use_env)\n         apply (rule_tac x=\"empty_use_env\" in exI)\n         apply (auto)\n          apply (rule_tac leq_empty_use_env)\n         apply (case_tac \"\\<not> weak_use_env empty_use_env\")\n          apply (simp add: weak_use_env_def)\n          apply (simp add: empty_use_env_def)\n         apply (rule_tac x=\"rxa\" in exI)\n         apply (rule_tac x=\"r_s2a\" in exI)\n         apply (auto)\n          apply (rule_tac x=\"rxa\" in exI)\n          apply (auto)\n          apply (rule_tac x=\"empty_use_env\" in exI)\n          apply (auto)\n            apply (rule_tac rhs_weak_leq_use_env)\n             apply (auto)\n            apply (rule_tac id_leq_use_env)\n           apply (rule_tac leq_empty_use_env)\n          apply (rule_tac self_diff_leq_use_env)\n         apply (rule_tac x=\"empty_use_env\" in exI)\n         apply (auto)\n              apply (rule_tac rhs_weak_leq_use_env)\n               apply (rule_tac dist_weak_comp_use_env)\n                apply (rule_tac dist_weak_comp_use_env)\n                 apply (auto)(*\n              apply (simp add: aff_use_env_def)\n              apply (simp add: weak_use_env_def)*)\n              apply (rule_tac id_leq_use_env)(*\n             apply (simp add: aff_use_env_def)\n             apply (case_tac \"req_type tau\")\n               apply (simp add: unlim_def)\n              apply (simp add: weak_use_env_def)\n             apply (simp add: null_use_env_def)*)\n            apply (rule_tac dist_comp_leq_use_env)\n             apply (rule_tac leq_empty_use_env)\n            apply (simp)\n           apply (rule_tac disj_empty_use_env2)\n          apply (rule_tac leq_empty_use_env)\n         apply (simp add: app_req_def)\n         apply (auto)\n          apply (rule_tac leq_empty_use_env)\n         apply (rule_tac diff_leq_use_env)\n         apply (rule_tac dist_comp_leq_use_env)\n          apply (rule_tac leq_empty_use_env)\n         apply (rule_tac id_leq_use_env)\n        apply (rule_tac wts_well_formed_delta)\n        apply (auto)\n       apply (rule_tac r_sb=\"r_s2a\" in trans_leq_use_env)\n        apply (auto)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (auto)\n     apply (simp add: weak_use_env_def)\n     apply (simp add: aff_use_env_def)\n     apply (simp add: disj_use_env_def)\n     apply (simp add: mini_disj_use_env_def)\n    (* diff correctness *)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac r_sb=\"comp_use_env rx1 rx2\" in trans_leq_use_env)\n       apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n        apply (rule_tac r_sb=\"diff_use_env r_s2a r_exa\" in trans_leq_use_env)\n         apply (rule_tac diff_leq_use_env)\n         apply (simp_all)\n      apply (rule_tac self_comp_leq_use_env2)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac r_sb=\"r_s2a\" in trans_leq_use_env)\n       apply (auto)\n    (* prove bound shifts were valid. to show that r_s2 (the only end perm bound) is lower than r_s2a - rxa (our proposed bound),\n        we use the fact that r_s2 \\<le> r_s3 - rx2, and whatever is not removed by rx2 was already removed by r_exa from r_s2a.  *)\n    apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 rx2) r_ex)\" in trans_leq_use_env)\n     apply (rule_tac r_sb=\"diff_use_env (diff_use_env r_s2a r_exa) (comp_use_env (comp_use_env rx1 rx2) r_ex)\" in trans_leq_use_env)\n      apply (rule_tac lhs_fold_dcl_use_env)\n      apply (rule_tac dist_diff_leq_use_env_gen)\n       apply (rule_tac rhs_weak_leq_use_env)\n        apply (rule_tac dist_weak_comp_use_env)\n         apply (simp_all)\n      apply (rule_tac id_leq_use_env)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac comp_leq_use_env2)\n      apply (rule_tac comp_leq_use_env1)\n      apply (rule_tac self_comp_leq_use_env2)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac self_comp_leq_use_env1)\n     apply (rule_tac comp_leq_use_env2)\n     apply (rule_tac self_comp_leq_use_env2)\n    apply (rule_tac dist_diff_leq_use_env)\n    apply (simp)\n    (* proving the rx bound in the primitive case is predicated on the fact that rxa is null *)\n  apply (simp add: app_req_def)\n  apply (case_tac \"req_type tau = Prim\")\n   apply (case_tac \"\\<not> leq_use_env rxa empty_use_env\")\n    apply (simp add: aff_use_env_def)\n    apply (simp add: null_use_env_def)\n    apply (simp add: leq_use_env_def)\n   apply (rule_tac r_sb=\"empty_use_env\" in trans_leq_use_env)\n    apply (rule_tac leq_empty_use_env)\n   apply (rule_tac diff_leq_use_env)\n   apply (rule_tac diff_leq_use_env)\n   apply (rule_tac dist_comp_leq_use_env)\n    apply (auto)\n    (* otherwise, to show that rx \\<ge> rxa - (rxa + r_exa + r_ex) (our proposed bound). we note that rxa - r_exa \\<le> rx2.\n        rx \\<ge> rx2 - (rx1 + rx2 + r_ex). rx1 is disjoint, rx2 is weak, r_ex is included in our bound *)    \n  apply (rule_tac r_sb=\"diff_use_env (comp_use_env rx1 rx2) (comp_use_env (comp_use_env rx1 rx2) r_ex)\" in trans_leq_use_env)\n   apply (simp)\n  apply (rule_tac r_sb=\"diff_use_env (diff_use_env rxa r_exa) (comp_use_env (comp_use_env rx1 rx2) r_ex)\" in trans_leq_use_env)\n   apply (rule_tac dist_diff_leq_use_env)\n   apply (rule_tac comp_leq_use_env2)\n   apply (simp)\n  apply (rule_tac unroll_dcl_use_env)\n  apply (rule_tac lhs_unroll_dcl_use_env)\n  apply (rule_tac dist_diff_leq_use_env)\n  apply (rule_tac lhs_fold_dcl_use_env)\n  apply (rule_tac lhs_flip_use_env)\n  apply (rule_tac unroll_dcl_use_env)\n  apply (rule_tac dist_diff_leq_use_env)\n  apply (rule_tac disj_diff_leq_use_env)\n   apply (rule_tac r_s=\"rx2\" in disj_leq_use_env2)\n    apply (simp)\n   apply (rule_tac r_sb=\"diff_use_env rxa r_exa\" in trans_leq_use_env)\n    apply (simp)\n   apply (rule_tac dist_diff_leq_use_env)\n   apply (rule_tac diff_leq_use_env)\n   apply (rule_tac dist_comp_leq_use_env)\n    apply (rule_tac id_leq_use_env)\n   apply (rule_tac id_leq_use_env)\n  apply (rule_tac dist_diff_leq_use_env)\n  apply (rule_tac diff_leq_use_env)\n  apply (rule_tac dist_comp_leq_use_env)\n   apply (rule_tac id_leq_use_env)\n  apply (rule_tac id_leq_use_env)\n  apply (simp add: corr_act_def)\n  done\n    \n  \nlemma sares_lam_case: \"\\<lbrakk>well_typed_state s2 env delta; sub_use_env s2  r_f; e1 = AppExp (LamExp x51 x52) x62; well_typed env delta r_s2a x62 t1 r_s3 rx2;\n        leq_use_env r_s2 (diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)); (*safe_use_lift rx2 r; safe_type t1 r;*)\n        leq_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_s3; disj_use_env rx1 (lift_use_env rx2 r); leq_use_env rx r_s2; leq_use_env r_ex r_s1;\n        leq_use_env (app_req rx1 rx2 r tau r_ex) rx; ax = NoAct; well_typed (add_env env (Var x51) t1) delta (add_use_env rxa (Var x51) r) x52 tau r_s' r_end; is_value x62;\n        aff_use_env rxa a; safe_subst_exp x52 x51 x62 e2; s1 = s2; leq_use_env rxa r_s1; leq_use_env r_s2a (diff_use_env r_s1 r_exa); leq_use_env rx1 r_s2a;\n        leq_use_env r_exa r_s1; leq_use_env (diff_use_env rxa r_exa) rx1; leq_use_env r_s1 r_f \\<rbrakk>\n       \\<Longrightarrow> \\<exists>g_ax. well_typed (red_env env g_ax) (red_delta delta g_ax) (exp_red_use_env r_s1 g_ax) e2 tau (end_red_use_env r_s2 g_ax) (end_red_use_env rx g_ax) \\<and>\n                  well_typed_state s2 (red_env env g_ax) (red_delta delta g_ax) \\<and>\n                  sub_use_env s2 (exp_red_use_env r_f g_ax) \\<and> safe_act s2 (infl_use_env r_f r_s2) g_ax \\<and> corr_act ax g_ax\"\n  apply (case_tac ax)\n    apply (auto)\n  apply (rule_tac x=\"NoResAct\" in exI)\n  apply (auto)\n  apply (rule_tac ?r_s2.0=\"diff_use_env (diff_use_env (comp_use_env r_s3 (cut_use_env r_exa)) (comp_use_env rxa (lift_use_env rx2 r))) (comp_use_env r_exa (comp_use_env r_ex rx1))\" and\n      rx=\"diff_use_env (app_req rxa rx2 r tau empty_use_env) (comp_use_env r_exa (comp_use_env r_ex rx1))\" in well_typed_simul_end_perm)\n     apply (rule_tac well_typed_diff_end_perm)\n      apply (rule_tac sares_lam_helper)\n       apply (auto)\n      apply (rule_tac x=\"x51\" and t=\"t1\" and ?rx1.0=\"rxa\" and r=\"r\" and ?e1.0=\"x52\" and r_s'=\"r_s'\" and r_end=\"r_end\"\n    and e'=\"x62\" and ?r_s2.0=\"comp_use_env r_s2a (cut_use_env r_exa)\" and ?r_s3.0=\"comp_use_env r_s3 (cut_use_env r_exa)\" and ?rx2.0=\"rx2\" in safe_subst_type_preserve_x)\n               apply (auto)\n          apply (case_tac x62)\n                 apply (auto)\n            apply (case_tac x3)\n             apply (auto)\n           apply (case_tac x71)\n                 apply (auto)\n           apply (case_tac x1)\n                      apply (auto)\n          apply (rule_tac well_typed_comp_perms_gen)\n           apply (auto)\n          apply (rule_tac r_s=\"r_s1\" in mini_disj_strong_use_env)\n           apply (rule_tac r_sb=\"diff_use_env r_s1 r_exa\" in trans_leq_use_env)\n            apply (rule_tac dist_diff_leq_use_env_gen)\n             apply (rule_tac id_leq_use_env)\n            apply (rule_tac self_cut_leq_use_env)\n           apply (simp)\n          apply (rule_tac strong_cut_use_env)\n         apply (rule_tac wts_well_formed_delta)\n         apply (auto)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (rule_tac r_sb=\"diff_use_env r_s1 r_exa\" in trans_leq_use_env)\n          apply (rule_tac self_diff_leq_use_env)\n         apply (simp)\n        apply (rule_tac cut_leq_use_env)\n        apply (simp)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac st_diff_comp_leq_use_env)\n        apply (rule_tac r_sb=\"diff_use_env rxa r_exa\" in trans_leq_use_env)\n         apply (rule_tac r_sb=\"comp_use_env rx1 (lift_use_env rx2 r)\" in trans_leq_use_env)\n          apply (simp)\n         apply (rule_tac comp_leq_use_env1)\n         apply (simp)\n        apply (rule_tac diff_cut_leq_use_env)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac r_sb=\"comp_use_env rx1 (lift_use_env rx2 r)\" in trans_leq_use_env)\n        apply (rule_tac comp_leq_use_env1)\n        apply (simp)\n       apply (rule_tac self_comp_leq_use_env2)\n    (* the last thing we have to do is show that rxa is disjoint from rx2. the idea is that rxa is contained in rx1 + cut r_exa. *)\n      apply (rule_tac r_s=\"comp_use_env rx1 (cut_use_env r_exa)\" in disj_leq_use_env1)\n       apply (rule_tac disj_comp_use_env1)\n        apply (simp)\n       apply (rule_tac r_s=\"r_s2a\" in disj_leq_use_env2)\n        apply (simp add: disj_use_env_def)\n        apply (auto)\n         apply (rule_tac r_s=\"r_s1\" in swp_mini_disj_use_env)\n         apply (rule_tac r_sb=\"diff_use_env r_s1 r_exa\" in trans_leq_use_env)\n          apply (rule_tac dist_diff_leq_use_env_gen)\n           apply (rule_tac id_leq_use_env)\n          apply (rule_tac self_cut_leq_use_env)\n         apply (simp)\n        apply (rule_tac r_s=\"r_s1\" in mini_disj_strong_use_env)\n         apply (rule_tac r_sb=\"diff_use_env r_s1 r_exa\" in trans_leq_use_env)\n          apply (rule_tac dist_diff_leq_use_env_gen)\n           apply (rule_tac id_leq_use_env)\n          apply (rule_tac self_cut_leq_use_env)\n         apply (simp)\n        apply (rule_tac strong_cut_use_env)\n       apply (rule_tac r_sb=\"comp_use_env rx1 (lift_use_env rx2 r)\" in trans_leq_use_env)\n        apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n         apply (rule_tac well_typed_perm_leq)\n         apply (auto)\n       apply (rule_tac self_comp_leq_use_env2)\n      apply (rule_tac st_diff_comp_leq_use_env)\n      apply (rule_tac r_sb=\"diff_use_env rxa r_exa\" in trans_leq_use_env)\n       apply (simp)\n      apply (rule_tac diff_cut_leq_use_env)\n      apply (rule_tac id_leq_use_env)\n     apply (rule_tac well_typed_state_non_prim_env)\n      apply (auto)\n    (* - proving initial boundary changes *)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (simp)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (simp)\n    apply (rule_tac r_sb=\"r_s2a\" in trans_leq_use_env)\n     apply (rule_tac r_sb=\"diff_use_env r_s1 r_exa\" in trans_leq_use_env)\n      apply (rule_tac self_diff_leq_use_env)\n     apply (auto)\n   (*apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)*)\n   apply (rule_tac r_sb=\"diff_use_env (diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)) r_exa\" in trans_leq_use_env)\n    apply (rule_tac fold_dcl_use_env)\n    apply (rule_tac dist_diff_leq_use_env_gen)\n     apply (rule_tac self_comp_leq_use_env1)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac r_sb=\"comp_use_env rx1 r_exa\" in trans_leq_use_env)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac comp_leq_use_env1)\n        apply (rule_tac comp_leq_use_env1)\n        apply (rule_tac self_comp_leq_use_env1)\n       apply (rule_tac self_comp_leq_use_env2)\n      apply (rule_tac st_diff_comp_leq_use_env)\n      apply (simp)\n     apply (rule_tac comp_leq_use_env1)\n     apply (rule_tac comp_leq_use_env1)\n     apply (rule_tac self_comp_leq_use_env2)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (rule_tac self_comp_leq_use_env2)\n    apply (rule_tac comp_leq_use_env1)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (rule_tac self_comp_leq_use_env2)\n    apply (rule_tac comp_leq_use_env1)\n    apply (rule_tac self_comp_leq_use_env1)\n   apply (rule_tac mini_disj_diff_leq_use_env)\n    apply (simp)\n   apply (rule_tac r_s=\"diff_use_env r_s1 r_exa\" in mini_disj_leq_use_env2)\n    apply (rule_tac mini_disj_diff_use_env)\n   apply (rule_tac r_sb=\"r_s2a\" in trans_leq_use_env)\n    apply (simp)\n   apply (rule_tac diff_leq_use_env)\n   apply (rule_tac well_typed_perm_leq)\n   apply (auto)\n    (* - secondary boundary change. *)\n  apply (simp add: app_req_def)\n  apply (auto)\n   apply (rule_tac diff_leq_use_env)\n   apply (rule_tac leq_empty_use_env)\n  apply (rule_tac r_sb=\"diff_use_env (comp_use_env rx1 rx2) (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n   apply (simp)\n  apply (rule_tac unroll_dcl_use_env)\n  apply (rule_tac lhs_flip_use_env)\n  apply (rule_tac lhs_unroll_dcl_use_env)\n  apply (rule_tac dist_diff_leq_use_env)\n  apply (rule_tac rhs_flip_use_env)\n  apply (rule_tac rhs_unroll_dcl_use_env)\n  apply (rule_tac dist_diff_leq_use_env)\n  apply (rule_tac lhs_fold_dcl_use_env)\n  apply (rule_tac lhs_flip_use_env)\n  apply (rule_tac lhs_unroll_dcl_use_env)\n  apply (rule_tac dist_diff_leq_use_env_gen)\n   apply (rule_tac lhs_dist_dcl_use_env)\n   apply (rule_tac dist_comp_leq_use_env)\n    apply (rule_tac comp_leq_use_env1)\n    apply (simp)\n   apply (rule_tac comp_leq_use_env2)\n   apply (rule_tac self_diff_leq_use_env)\n  apply (rule_tac comp_leq_use_env1)\n  apply (rule_tac self_comp_leq_use_env2)\n  apply (simp add: corr_act_def)\n  done\n    \nlemma empty_infl_use_env: \"infl_use_env r_s r_s = empty_use_env\"    \n  apply (case_tac \"\\<forall> x. infl_use_env r_s r_s x = empty_use_env x\")\n   apply (auto)\n  apply (simp add: infl_use_env_def)\n  apply (simp add: empty_use_env_def)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n  done\n  \nlemma flat_infl_sexp_wp: \"\\<lbrakk> well_typed env delta r_s e tau r_s rx; well_formed_delta env delta; is_value e \\<rbrakk> \\<Longrightarrow> well_typed env delta rx e tau rx rx\"    \n  apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s\" and e=\"e\" and rx=\"rx\" in infl_sexp_wp)\n    apply (auto)\n   apply (rule_tac value_is_sexp)\n   apply (auto)\n  apply (cut_tac r_s=\"r_s\" in empty_infl_use_env)\n  apply (auto)\n  apply (cut_tac r=\"rx\" in comp_empty_use_env2)\n  apply (auto)\n  done\n    \nlemma cancel_strong_leq_use_env: \"\\<lbrakk> strong_use_env r_x \\<rbrakk> \\<Longrightarrow> leq_use_env (diff_use_env r_x r_x) r_s\"    \n  apply (simp add: strong_use_env_def)\n  apply (simp add: leq_use_env_def)\n  apply (simp add: diff_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n  done\n        \nlemma infl_strong_use_env: \"strong_use_env (infl_use_env r_s r_x)\"    \n  apply (simp add: strong_use_env_def)\n  apply (simp add: infl_use_env_def)\n  done\n  \nlemma strong_lift_use_env: \"\\<lbrakk> strong_use_env r_s \\<rbrakk> \\<Longrightarrow> lift_use_env r_s r = r_s\"\n  apply (case_tac \"\\<forall> x. lift_use_env r_s r x = r_s x\")\n   apply (auto)\n  apply (simp add: strong_use_env_def)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac r)\n    apply (auto)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n  done\n(*\nlemma proper_op: \"\\<lbrakk> app_op xop c e \\<rbrakk> \\<Longrightarrow> proper_exp rs_map e\"\n  apply (simp add: proper_exp_def)    \n  apply (case_tac xop)\n       apply (auto)\n  done\n  *)  \nlemma safe_app_red_exp_strict: \"\\<lbrakk> well_typed env delta r_s1 e1 tau r_s2 rx; well_typed_state s1 env delta;\n  sub_use_env s1 r_f; leq_use_env r_s1 r_f; app_red_exp are (s1, e1) ax (s2, e2) \\<rbrakk> \\<Longrightarrow> (\\<exists> g_ax.\n  well_typed (red_env env g_ax) (red_delta delta g_ax) (exp_red_use_env r_s1 g_ax) e2 tau (end_red_use_env r_s2 g_ax) (end_red_use_env rx g_ax) \\<and>\n  (*red_env env ax env' \\<and> *)well_typed_state s2 (red_env env g_ax) (red_delta delta g_ax) \\<and>\n  sub_use_env s2 (exp_red_use_env r_f g_ax) \\<and> safe_act s1 (infl_use_env r_f r_s2) g_ax \\<and> corr_act ax g_ax)\"\n  apply (case_tac are)\n        apply (auto)\n    (* lam case *)\n        apply (rule_tac sares_lam_case)\n                      apply (auto)\n    (* fix-point case *)\n       apply (rule_tac r_s2a=\"r_s2a\" and ?r_s3.0=\"r_s3\" in sares_fix_case)\n                      apply (auto)\n       apply (rule_tac x=\"rxa\" in exI)\n       apply (auto)\n    (* remaining const cases. the idea is that any \"destructive\" uses should have had\n      end perms removes to begin with, so red_use_env should be fine. *)\n      apply (rule_tac ?r_s1.0=\"r_s1\" and ?r_s2.0=\"r_s3\" and ?rx1.0=\"rx1\" and ?rx2.0=\"rx2\" in safe_app_con_case)\n             apply (auto)\n       apply (rule_tac ?r_s1.0=\"r_s2a\" in well_typed_incr_start_perm)\n        apply (auto)(*\n      apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n       apply (rule_tac lhs_unroll_dcl_use_env)\n       apply (rule_tac self_diff_leq_use_env)\n      apply (simp)*)\n    (* op case *)\n     apply (case_tac \"ax \\<noteq> NoAct\")\n      apply (auto)\n     apply (rule_tac x=\"NoResAct\" in exI)\n     apply (auto)\n     apply (rule_tac ?r_s2.0=\"r_s1\" and rx=\"empty_use_env\" in well_typed_simul_end_perm)\n        apply (rule_tac safe_app_op_case)\n         apply (auto)\n      apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_ex)\" in trans_leq_use_env)\n       apply (rule_tac r_sb=\"r_s2a\" in trans_leq_use_env)\n        apply (auto)\n      apply (rule_tac diff_leq_use_env)\n      apply (simp)\n     apply (rule_tac leq_empty_use_env)\n  apply (simp add: corr_act_def)\n    (* if case 1 *)\n    apply (rule_tac x=\"NoResAct\" in exI)\n    apply (case_tac ax)\n      apply (auto)\n    apply (rule_tac ?r_s1.0=\"r_s2a\" in well_typed_incr_start_perm)\n     apply (auto)\n    apply (rule_tac rx=\"rx1\" in well_typed_incr_req) \n      apply (simp)\n     apply (rule_tac self_comp_leq_use_env1)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (rule_tac well_typed_perm_leqx)\n     apply (auto)\n    apply (rule_tac well_typed_perm_leqx)\n     apply (auto)\n  apply (simp add: corr_act_def)\n    (* if case 2 *)\n   apply (rule_tac x=\"NoResAct\" in exI)\n   apply (auto)\n   apply (case_tac ax)\n    apply (auto)\n   apply (rule_tac ?r_s1.0=\"r_s2a\" in well_typed_incr_start_perm)\n    apply (auto)\n  apply (rule_tac rx=\"rx2\" in well_typed_incr_req)\n     apply (simp)\n    apply (rule_tac self_comp_leq_use_env2)\n   apply (rule_tac dist_comp_leq_use_env)\n    apply (rule_tac well_typed_perm_leqx)\n    apply (auto)\n   apply (rule_tac well_typed_perm_leqx)\n   apply (auto)\n  apply (simp add: corr_act_def)\n    (* cv case *)\n  apply (rule_tac sares_cv_case)\n    apply (auto)\n  done   \n\nlemma sares_valid: \"valid_reduct app_red_exp\"\n  apply (simp add: valid_reduct_def)\n  apply (auto)\n  apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s1\" and ?e1.0=\"e1\" and tau=\"tau\" and ?r_s2.0=\"r_s2\" and rx=\"rx\" and\n      ?s1.0=\"s1\" and ax=\"ax\" and ?s2.0=\"s2\" and ?e2.0=\"e2\" in safe_app_red_exp_strict)\n       apply (auto)\n  done\n\n    \nend", "meta": {"author": "dcco", "repo": "perm_lang_thesis", "sha": "81661c97a0c43701c9ec0a75074d9553b2dd0263", "save_path": "github-repos/isabelle/dcco-perm_lang_thesis", "path": "github-repos/isabelle/dcco-perm_lang_thesis/perm_lang_thesis-81661c97a0c43701c9ec0a75074d9553b2dd0263/isa_code/RedSafeAppLemma.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.4687906266262437, "lm_q1q2_score": 0.2544892186908187}}
{"text": "           (*-------------------------------------------*\n            |        CSP-Prover on Isabelle2005         |\n            |              Februaru 2006                |\n            |                 March 2007  (modified)    |\n            |                 August 2007  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory FNF_F_sf_par\nimports FNF_F_sf_induct FNF_F_sf_ext\nbegin\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite UnionT and InterT.                 *)\n(*                  disj_not1: (~ P | Q) = (P --> Q)                   *)\n\ndeclare disj_not1 [simp del]\n\n(*  The following simplification rules are deleted in this theory file *)\n(*       P (if Q then x else y) = ((Q --> P x) & (~ Q --> P y))        *)\n(* Isabelle 2017: split_if --> if_split *)\n\ndeclare if_split  [split del]\n\n(*****************************************************************\n\n         1. full sequentialization for Parallel (P1 |[X]| DIV)\n         2. full sequentialization for Parallel (P1 |[X]| SKIP)\n         3. full sequentialization for Parallel (P1 |[X]| P2)\n\n *****************************************************************)\n\n(*============================================================*\n |                                                            |\n |                Parallel (P |[X]| DIV)                      |\n |                                                            |\n *============================================================*)\n\ndefinition\n  Pfun_Parallel_DIV :: \"'a set => (('p,'a) proc => ('p,'a) proc)\"\n  where\n  Pfun_Parallel_DIV_def :\n    \"Pfun_Parallel_DIV X == (%P1. P1 |[X]| DIV)\"\n  \ndefinition\n  SP_step_Parallel_DIV :: \n   \"'a set => ('a set => ('a => ('p,'a) proc) => ('p,'a) proc => ('a => ('p,'a) proc) => ('p,'a) proc)\"\n  where\n  SP_step_Parallel_DIV_def :\n    \"SP_step_Parallel_DIV X == (%A1 Pf1 Q1 SPf. \n                               (? :(A1-X) -> SPf) [+] DIV)\"\n\ndefinition\n  fsfF_Parallel_DIV :: \"'a set => ('p,'a) proc => ('p,'a) proc\"\n  where\n  fsfF_Parallel_DIV_def :\n    \"fsfF_Parallel_DIV X == (%P1. \n       (fsfF_induct1 (Pfun_Parallel_DIV X)\n                     (SP_step_Parallel_DIV X) P1))\"\n\n(*------------------------------------------------------------*\n |                        in fsfF_proc                        |\n *------------------------------------------------------------*)\n\nlemma fsfF_Parallel_DIV_in:\n    \"P1 : fsfF_proc\n     ==> fsfF_Parallel_DIV X P1 : fsfF_proc\"\napply (simp add: fsfF_Parallel_DIV_def)\napply (rule fsfF_induct1_in)\napply (simp_all add: SP_step_Parallel_DIV_def\n                     fsfF_proc.intros)\ndone\n\n(*------------------------------------------------------------*\n |             syntactical transformation to fsfF             |\n *------------------------------------------------------------*)\n\nlemma cspF_fsfF_Parallel_DIV_eqF:\n    \"P1 |[X]| DIV =F fsfF_Parallel_DIV X P1\"\napply (simp add: fsfF_Parallel_DIV_def)\napply (rule cspF_rw_right)\napply (rule cspF_fsfF_induct1_eqF[THEN cspF_sym])\napply (simp_all add: Pfun_Parallel_DIV_def\n                     SP_step_Parallel_DIV_def)\napply (rule cspF_Dist_nonempty, simp)\n\napply (rule cspF_rw_left)\napply (rule cspF_SKIP_or_DIV_or_STOP_Parallel_Ext_choice)\napply (simp)\napply (rule cspF_rw_left)\napply (rule cspF_SKIP_DIV)\napply (simp)\napply (rule cspF_decompo | rule cspF_reflex | simp)+\ndone\n\n(*============================================================*\n |                                                            |\n |                Parallel (P |[X]| SKIP)                     |\n |                                                            |\n *============================================================*)\n\ndefinition\n  Pfun_Parallel_SKIP :: \"'a set => (('p,'a) proc => ('p,'a) proc)\"\n  where\n  Pfun_Parallel_SKIP_def :\n    \"Pfun_Parallel_SKIP X == (%P1. P1 |[X]| SKIP)\"\n  \ndefinition\n  SP_step_Parallel_SKIP :: \n   \"'a set => ('a set => ('a => ('p,'a) proc) => ('p,'a) proc => \n     ('a => ('p,'a) proc) => ('p,'a) proc)\"\n  where\n  SP_step_Parallel_SKIP_def :\n    \"SP_step_Parallel_SKIP X == (%A1 Pf1 Q1 SPf.\n                                (? :(A1-X) -> SPf) [+] Q1)\"\n\ndefinition\n  fsfF_Parallel_SKIP  :: \"'a set => ('p,'a) proc => ('p,'a) proc\"\n  where\n  fsfF_Parallel_SKIP_def :\n    \"fsfF_Parallel_SKIP X == (%P1. \n       (fsfF_induct1 (Pfun_Parallel_SKIP X)\n                     (SP_step_Parallel_SKIP X) P1))\"\n\n(*------------------------------------------------------------*\n |                        in fsfF_proc                        |\n *------------------------------------------------------------*)\n\nlemma fsfF_Parallel_SKIP_in:\n    \"P1 : fsfF_proc\n     ==> fsfF_Parallel_SKIP X P1 : fsfF_proc\"\napply (simp add: fsfF_Parallel_SKIP_def)\napply (rule fsfF_induct1_in)\napply (simp_all add: SP_step_Parallel_SKIP_def\n                     fsfF_proc.intros)\ndone\n\n(*------------------------------------------------------------*\n |             syntactical transformation to fsfF             |\n *------------------------------------------------------------*)\n\nlemma cspF_fsfF_Parallel_SKIP_eqF:\n    \"P1 |[X]| SKIP =F fsfF_Parallel_SKIP X P1\"\napply (simp add: fsfF_Parallel_SKIP_def)\napply (rule cspF_rw_right)\napply (rule cspF_fsfF_induct1_eqF[THEN cspF_sym])\napply (simp_all add: Pfun_Parallel_SKIP_def\n                     SP_step_Parallel_SKIP_def)\n\napply (rule cspF_Dist_nonempty, simp)\n\napply (rule cspF_rw_left)\napply (rule cspF_SKIP_or_DIV_or_STOP_Parallel_Ext_choice)\napply (simp)\napply (simp)\napply (rule cspF_decompo | rule cspF_reflex | simp)+\ndone\n\n(*============================================================*\n |                                                            |\n |              Parallel (P |[X]| SKIP or DIV)                |\n |                                                            |\n *============================================================*)\n\ndefinition\n  fsfF_Parallel_SKIP_DIV  :: \"'a set => ('p,'a) proc => ('p,'a) proc => ('p,'a) proc\"\n\nwhere\n  fsfF_Parallel_SKIP_DIV_def :\n    \"fsfF_Parallel_SKIP_DIV X P1 P2 ==\n        if (P2 = SKIP) then fsfF_Parallel_SKIP X P1\n        else if (P2 = DIV) then fsfF_Parallel_DIV X P1\n        else (P1 |[X]| P2)\"\n\n(*------------------------------------------------------------*\n |                        in fsfF_proc                        |\n *------------------------------------------------------------*)\n\nlemma fsfF_Parallel_SKIP_DIV_in:\n    \"[| P1 : fsfF_proc ; P2 = SKIP | P2 = DIV |]\n     ==> fsfF_Parallel_SKIP_DIV X P1 P2 : fsfF_proc\"\napply (simp add: fsfF_Parallel_SKIP_DIV_def)\napply (erule disjE)\napply (simp add: fsfF_Parallel_SKIP_in)\napply (simp add: fsfF_Parallel_DIV_in)\ndone\n\n(*------------------------------------------------------------*\n |             syntactical transformation to fsfF             |\n *------------------------------------------------------------*)\n\nlemma cspF_fsfF_Parallel_SKIP_DIV_eqF:\n    \"P1 |[X]| P2 =F fsfF_Parallel_SKIP_DIV X P1 P2\"\napply (simp add: fsfF_Parallel_SKIP_DIV_def)\napply (simp split: if_split)\napply (intro conjI impI)\napply (simp add: cspF_fsfF_Parallel_DIV_eqF)\napply (simp add: cspF_fsfF_Parallel_SKIP_eqF)\ndone\n\nlemmas cspF_fsfF_Parallel_SKIP_DIV_eqF_sym =\n       cspF_fsfF_Parallel_SKIP_DIV_eqF[THEN cspF_sym]\n\n(*============================================================*\n |                                                            |\n |            Genaralized Parallel (P |[X]| Q)                |\n |                                                            |\n *============================================================*)\n\ndefinition\n  Pfun_Parallel :: \"'a set => (('p,'a) proc => ('p,'a) proc => ('p,'a) proc)\"\n  where\n  Pfun_Parallel_def :\n    \"Pfun_Parallel X == (%P1 P2. P1 |[X]| P2)\"\n  \ndefinition\n  SP_step_Parallel :: \n   \"'a set => \n    ('a set => ('a => ('p,'a) proc) => ('p,'a) proc => \n     'a set => ('a => ('p,'a) proc) => ('p,'a) proc => \n    ('a => ('p,'a) proc) => ('a => ('p,'a) proc) => ('a => ('p,'a) proc) => ('p,'a) proc)\"\n  where\n  SP_step_Parallel_def :\n    \"SP_step_Parallel X == (%A1 Pf1 Q1 A2 Pf2 Q2 SPf SPf1 SPf2. \n    (if (Q1 = STOP & Q2 = STOP) then\n     ((? a:((X Int A1 Int A2) Un (A1 - X) Un (A2 - X))\n          -> (if (a : X) then (SPf a)\n                 else if (a : A1 & a : A2)\n                      then ((SPf1 a) |~|seq (SPf2 a))\n                 else if (a : A1) then (SPf1 a)\n                 else (SPf2 a))) [+] STOP)\n    else if (Q1 = STOP) then\n    (((? a:((X Int A1 Int A2) Un (A1 - X) Un (A2 - X))\n        -> (if (a : X) then (SPf a)\n               else if (a : A1 & a : A2)\n                    then ((SPf1 a) |~|seq (SPf2 a))\n               else if (a : A1) then (SPf1 a)\n               else (SPf2 a))) [+] STOP)\n     [>seq\n     (fsfF_Parallel_SKIP_DIV X (((? :A1 -> Pf1) [+] Q1)) Q2))\n\n    else if (Q2 = STOP) then\n    (((? a:((X Int A1 Int A2) Un (A1 - X) Un (A2 - X))\n        -> (if (a : X) then (SPf a)\n               else if (a : A1 & a : A2)\n                    then ((SPf1 a) |~|seq (SPf2 a))\n               else if (a : A1) then (SPf1 a)\n               else (SPf2 a))) [+] STOP)\n     [>seq\n     (fsfF_Parallel_SKIP_DIV X (((? :A2 -> Pf2) [+] Q2)) Q1))\n\n   else\n    (((? a:((X Int A1 Int A2) Un (A1 - X) Un (A2 - X))\n        -> (if (a : X) then (SPf a)\n               else if (a : A1 & a : A2)\n                    then ((SPf1 a) |~|seq (SPf2 a))\n               else if (a : A1) then (SPf1 a)\n               else (SPf2 a))) [+] STOP)\n     [>seq\n     ((fsfF_Parallel_SKIP_DIV X \n             (((? :A2 -> Pf2) [+] Q2)) Q1) |~|seq\n      (fsfF_Parallel_SKIP_DIV X \n             (((? :A1 -> Pf1) [+] Q1)) Q2)))))\"\n\ndefinition\n  fsfF_Parallel  :: \"('p,'a) proc => 'a set => ('p,'a) proc => ('p,'a) proc\"\n                          (\"(1_ /|[_]|seq _)\" [76,0,77] 76)\n  where\n  fsfF_Parallel_def :\n    \"P1 |[X]|seq P2 == \n       (fsfF_induct2 (Pfun_Parallel X) (SP_step_Parallel X) P1 P2)\"\n\n(*------------------------------------------------------------*\n |                        in fsfF_proc                        |\n *------------------------------------------------------------*)\n\nlemma fsfF_Parallel_in_lm:\n  \"[| ALL a:A1. Pf1 a : fsfF_proc; \n      ALL a:A2. Pf2 a : fsfF_proc; \n      ALL a:A1 Int A2. SPf a : fsfF_proc;\n      ALL a:A1. SPf1 a : fsfF_proc; \n      ALL a:A2. SPf2 a : fsfF_proc;\n      Q1 = SKIP | Q1 = DIV | Q1 = STOP; Q2 = SKIP | Q2 = DIV | Q2 = STOP |]\n   ==> SP_step_Parallel X A1 Pf1 Q1 A2 Pf2 Q2 SPf SPf1 SPf2 : fsfF_proc\"\napply (simp_all add: SP_step_Parallel_def)\n\n(* Q1 = STOP & Q2 = STOP *)\napply (case_tac \"Q1 = STOP & Q2 = STOP\")\napply (simp)\napply (rule fsfF_proc.intros)\napply (rule ballI)\napply (simp split: if_split)\napply (intro conjI ballI impI)\napply (simp_all)\napply (simp add: fsfF_Int_choice_in)\n\n(* Q1 = STOP *)\napply (subgoal_tac \"~ (Q1 = STOP & Q2 = STOP)\")\napply (simp (no_asm_simp))\napply (case_tac \"Q1 = STOP\")\napply (simp)\napply (rule fsfF_Timeout_in)\n\napply (rule fsfF_proc.intros)\napply (rule ballI)\napply (simp split: if_split)\napply (intro conjI ballI impI)\napply (simp_all)\napply (simp add: fsfF_Int_choice_in)\napply (rule fsfF_Parallel_SKIP_DIV_in)\n\napply (simp add: fsfF_proc.intros)\napply (simp)\n\n(* Q2 = STOP *)\napply (case_tac \"Q2 = STOP\")\napply (simp)\napply (rule fsfF_Timeout_in)\n\napply (rule fsfF_proc.intros)\napply (rule ballI)\napply (simp split: if_split)\napply (intro conjI ballI impI)\napply (simp_all)\napply (simp add: fsfF_Int_choice_in)\napply (rule fsfF_Parallel_SKIP_DIV_in)\napply (simp add: fsfF_proc.intros)\napply (simp)\n\n(* Q1 = SKIP | DIV , Q2 = SKIP | DIV *)\napply (rule fsfF_Timeout_in)\n\napply (rule fsfF_proc.intros)\napply (rule ballI)\napply (simp split: if_split)\napply (intro conjI ballI impI)\napply (simp_all)\napply (simp add: fsfF_Int_choice_in)\n\napply (rule fsfF_Int_choice_in)\napply (rule fsfF_Parallel_SKIP_DIV_in)\napply (simp add: fsfF_proc.intros)\napply (simp)\n\napply (rule fsfF_Parallel_SKIP_DIV_in)\napply (simp add: fsfF_proc.intros)\napply (simp)\ndone\n\n(*------------------------------------*\n |                 in                 |\n *------------------------------------*)\n\nlemma fsfF_Parallel_in:\n    \"[| P1 : fsfF_proc ; P2 : fsfF_proc |]\n     ==> P1 |[X]|seq P2 : fsfF_proc\"\napply (simp add: fsfF_Parallel_def)\napply (rule fsfF_induct2_in)\napply (simp_all)\napply (simp add: fsfF_Parallel_in_lm)\ndone\n\n(*------------------------------------------------------------*\n |             syntactical transformation to fsfF             |\n *------------------------------------------------------------*)\n\nlemma cspF_fsfF_Parallel_eqF:\n    \"P1 |[X]| P2 =F P1 |[X]|seq P2\"\napply (simp add: fsfF_Parallel_def)\napply (rule cspF_rw_right)\napply (rule cspF_fsfF_induct2_eqF[THEN cspF_sym])\napply (simp_all add: Pfun_Parallel_def)\napply (rule cspF_Dist_nonempty, simp)\napply (rule cspF_Dist_nonempty, simp)\n\napply (simp add: SP_step_Parallel_def)\n\n(* Q1 = STOP & Q2 = STOP *)\napply (case_tac \"Q1 = STOP & Q2 = STOP\")\napply (simp)\n\napply (rule cspF_rw_right)\napply (rule cspF_unit)\n\napply (rule cspF_rw_left)\napply (rule cspF_decompo)\napply (simp)\napply (rule cspF_unit)\napply (rule cspF_unit)\n\napply (rule cspF_rw_left)\napply (rule cspF_step)\napply (rule cspF_decompo)\napply (simp)\n\napply (simp split: if_split)\napply (intro conjI impI)\napply (simp)\n\napply (rule cspF_rw_left, rule cspF_IF)+\n\napply (rule cspF_rw_right)\napply (rule cspF_fsfF_Int_choice_eqF[THEN cspF_sym])\n\n apply (rule cspF_decompo)\n apply (rule cspF_decompo)\n apply (simp)\n apply (simp)\n apply (rule cspF_rw_right)\n apply (rule cspF_unit)\n apply (rule cspF_reflex)\n\n apply (rule cspF_decompo)\n apply (simp)\n apply (simp)\n apply (rule cspF_rw_right)\n apply (rule cspF_unit)\n apply (rule cspF_reflex)\n apply (rule cspF_reflex)\n\napply (rule cspF_rw_left, rule cspF_IF)+\napply (rule cspF_rw_right)\n apply (rule cspF_decompo)\n apply (simp)\n apply (rule cspF_reflex)\n apply (rule cspF_unit)\n apply (rule cspF_reflex)\n\napply (rule cspF_rw_left, rule cspF_IF)+\napply (rule cspF_rw_right)\n apply (rule cspF_decompo)\n apply (simp)\n apply (rule cspF_unit)\n apply (rule cspF_reflex)\n apply (rule cspF_reflex)\n\napply (rule cspF_rw_left, rule cspF_IF)+\napply (rule cspF_rw_right)\n apply (rule cspF_decompo)\n apply (simp)\n apply (rule cspF_unit)\n apply (rule cspF_reflex)\n apply (rule cspF_reflex)\n\n(* Q1 = STOP *)\napply (simp (no_asm_simp))\napply (case_tac \"Q1 = STOP\")\napply (simp)\n\napply (rule cspF_rw_left)\napply (rule cspF_decompo)\napply (simp)\napply (rule cspF_Ext_choice_unit)\napply (rule cspF_reflex)\n\napply (rule cspF_rw_left)\napply (rule cspF_SKIP_or_DIV_resolve)\napply (fast)\n\napply (rule cspF_rw_right)\napply (rule cspF_fsfF_Timeout_eqF[THEN cspF_sym])\napply (rule cspF_decompo)\napply (rule cspF_decompo)\n\napply (rule cspF_rw_right)\napply (rule cspF_unit)\napply (rule cspF_decompo)\napply (simp)\n\n(* IF --> if *)\napply (simp split: if_split)\napply (intro conjI impI)\napply (simp)\n\napply (rule cspF_rw_left, rule cspF_IF)+\napply (rule cspF_rw_right)\napply (rule cspF_fsfF_Int_choice_eqF[THEN cspF_sym])\n\n apply (rule cspF_decompo)\n apply (simp)\n apply (rule cspF_rw_right)\n apply (rule cspF_decompo)\n apply (simp)\n apply (rule cspF_unit)\n apply (rule cspF_reflex)\n apply (rule cspF_reflex)\n\napply (rule cspF_rw_left, rule cspF_IF)+\n apply (rule cspF_reflex)\n\napply (rule cspF_rw_left, rule cspF_IF)+\napply (rule cspF_rw_right)\n apply (rule cspF_decompo)\n apply (simp)\n apply (rule cspF_unit)\n apply (rule cspF_reflex)\n apply (rule cspF_reflex)\n\napply (rule cspF_rw_left, rule cspF_IF)+\napply (rule cspF_rw_right)\n apply (rule cspF_decompo)\n apply (simp)\n apply (rule cspF_unit)\n apply (rule cspF_reflex)\n apply (rule cspF_reflex)\n\napply (rule cspF_reflex)\n\napply (rule cspF_rw_right)\napply (rule cspF_fsfF_Parallel_SKIP_DIV_eqF[THEN cspF_sym])\napply (rule cspF_rw_right)\n apply (rule cspF_decompo)\n apply (simp)\n apply (rule cspF_unit)\n apply (rule cspF_reflex)\n apply (rule cspF_reflex)\n\n(* Q2 = STOP *)\napply (case_tac \"Q2 = STOP\")\napply (simp)\n\napply (rule cspF_rw_left)\napply (rule cspF_decompo)\napply (simp)\napply (rule cspF_reflex)\napply (rule cspF_unit)\n\napply (rule cspF_rw_left)\napply (rule cspF_SKIP_or_DIV_resolve)\napply (simp)\napply (rule cspF_rw_right)\napply (rule cspF_fsfF_Timeout_eqF[THEN cspF_sym])\napply (rule cspF_decompo)\napply (rule cspF_decompo)\n\napply (rule cspF_rw_right)\napply (rule cspF_unit)\napply (rule cspF_decompo)\napply (simp)\n\n(* IF --> if *)\napply (simp split: if_split)\napply (intro conjI impI)\napply (simp)\n\napply (rule cspF_rw_left, rule cspF_IF)+\napply (rule cspF_rw_right)\napply (rule cspF_fsfF_Int_choice_eqF[THEN cspF_sym])\n\n apply (rule cspF_decompo)\n apply (rule cspF_rw_right)\n apply (rule cspF_decompo)\n apply (simp)\n apply (rule cspF_reflex)\n apply (rule cspF_unit)\n apply (rule cspF_reflex)\n apply (rule cspF_reflex)\n\napply (rule cspF_rw_left, rule cspF_IF)+\napply (rule cspF_rw_right)\n apply (rule cspF_decompo)\n apply (simp)\n apply (rule cspF_reflex)\n apply (rule cspF_unit)\n apply (rule cspF_reflex)\n\napply (rule cspF_rw_left, rule cspF_IF)+\n apply (rule cspF_reflex)\n\napply (rule cspF_rw_left, rule cspF_IF)+\n apply (rule cspF_reflex)\n\napply (rule cspF_reflex)\n\napply (rule cspF_rw_right)\napply (rule cspF_fsfF_Parallel_SKIP_DIV_eqF[THEN cspF_sym])\napply (rule cspF_rw_right)\n apply (rule cspF_decompo)\n apply (simp)\n apply (rule cspF_unit)\n apply (rule cspF_reflex)\n apply (rule cspF_commut)\n\n(* DIV or SKIP *)\napply (simp)\n\napply (rule cspF_rw_left)\napply (rule cspF_SKIP_or_DIV_resolve)\napply (simp)\napply (simp)\napply (rule cspF_rw_right)\napply (rule cspF_fsfF_Timeout_eqF[THEN cspF_sym])\napply (rule cspF_decompo)\napply (rule cspF_decompo)\n\napply (rule cspF_rw_right)\napply (rule cspF_unit)\napply (rule cspF_decompo)\napply (simp)\n\n(* IF --> if *)\napply (simp split: if_split)\napply (intro conjI impI)\napply (simp)\n\napply (rule cspF_rw_left, rule cspF_IF)+\napply (rule cspF_rw_right)\napply (rule cspF_fsfF_Int_choice_eqF[THEN cspF_sym])\napply (rule cspF_reflex)\n\napply (rule cspF_rw_left, rule cspF_IF)+\napply (rule cspF_reflex)\n\napply (rule cspF_rw_left, rule cspF_IF)+\napply (rule cspF_reflex)\n\napply (rule cspF_rw_left, rule cspF_IF)+\napply (rule cspF_reflex)\n\napply (rule cspF_reflex)\n\napply (rule cspF_rw_right)\napply (rule cspF_fsfF_Int_choice_eqF[THEN cspF_sym])\napply (rule cspF_decompo)\n\n apply (rule cspF_rw_right)\n apply (rule cspF_fsfF_Parallel_SKIP_DIV_eqF[THEN cspF_sym])\n apply (rule cspF_commut)\n apply (rule cspF_rw_right)\n apply (rule cspF_fsfF_Parallel_SKIP_DIV_eqF[THEN cspF_sym])\n apply (rule cspF_reflex)\n\n(* congruence *)\n\napply (simp add: SP_step_Parallel_def)\n\napply (simp split: if_split)\napply (intro conjI impI)\n\napply (rule cspF_decompo, simp)\napply (rule cspF_decompo, simp)\napply (simp split: if_split)\napply (intro conjI impI)\napply (simp_all)\napply (rule cspF_rw_left, rule cspF_fsfF_Int_choice_eqF[THEN cspF_sym])\napply (rule cspF_rw_right, rule cspF_fsfF_Int_choice_eqF[THEN cspF_sym])\napply (rule cspF_decompo)\napply (simp_all)\n\napply (rule cspF_rw_left,  rule cspF_fsfF_Timeout_eqF[THEN cspF_sym])\napply (rule cspF_rw_right, rule cspF_fsfF_Timeout_eqF[THEN cspF_sym])\napply (rule cspF_Timeout_cong)\napply (rule cspF_decompo, simp)\napply (rule cspF_decompo, simp)\napply (simp split: if_split)\napply (intro conjI impI)\napply (simp_all)\napply (rule cspF_rw_left, rule cspF_fsfF_Int_choice_eqF[THEN cspF_sym])\napply (rule cspF_rw_right, rule cspF_fsfF_Int_choice_eqF[THEN cspF_sym])\napply (rule cspF_decompo)\napply (simp_all)\n\napply (rule cspF_rw_left,  rule cspF_fsfF_Timeout_eqF[THEN cspF_sym])\napply (rule cspF_rw_right, rule cspF_fsfF_Timeout_eqF[THEN cspF_sym])\napply (rule cspF_Timeout_cong)\napply (rule cspF_decompo, simp)\napply (rule cspF_decompo, simp)\napply (simp split: if_split)\napply (intro conjI impI)\napply (simp_all)\napply (rule cspF_rw_left, rule cspF_fsfF_Int_choice_eqF[THEN cspF_sym])\napply (rule cspF_rw_right, rule cspF_fsfF_Int_choice_eqF[THEN cspF_sym])\napply (rule cspF_decompo)\napply (simp_all)\n\napply (rule cspF_rw_left,  rule cspF_fsfF_Timeout_eqF[THEN cspF_sym])\napply (rule cspF_rw_right, rule cspF_fsfF_Timeout_eqF[THEN cspF_sym])\napply (rule cspF_Timeout_cong)\napply (rule cspF_decompo, simp)\napply (rule cspF_decompo, simp)\napply (simp split: if_split)\napply (intro conjI impI)\napply (simp_all)\napply (rule cspF_rw_left, rule cspF_fsfF_Int_choice_eqF[THEN cspF_sym])\napply (rule cspF_rw_right, rule cspF_fsfF_Int_choice_eqF[THEN cspF_sym])\napply (rule cspF_decompo)\napply (simp_all)\ndone\n\n(****************** to add them again ******************)\n\ndeclare if_split    [split]\ndeclare disj_not1   [simp]\n\nend\n", "meta": {"author": "yoshinao-isobe", "repo": "CSP-Prover", "sha": "806fbe330d7e23279675a2eb351e398cb8a6e0a8", "save_path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover", "path": "github-repos/isabelle/yoshinao-isobe-CSP-Prover/CSP-Prover-806fbe330d7e23279675a2eb351e398cb8a6e0a8/FNF_F/FNF_F_sf_par.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6187804478040616, "lm_q2_score": 0.41111086923216794, "lm_q1q2_score": 0.2543873677605979}}
{"text": "(*  Title:       CoreC++\n    Author:      Daniel Wasserrab\n    Maintainer:  Daniel Wasserrab <wasserra at fmi.uni-passau.de>\n\n    Based on the Jinja theory J/WellTypeRT.thy by Tobias Nipkow \n*)\n\nsection \\<open>Runtime Well-typedness\\<close>\n\ntheory WellTypeRT imports WellType begin\n\n\nsubsection \\<open>Run time types\\<close>\n\nprimrec typeof_h :: \"prog \\<Rightarrow> heap \\<Rightarrow> val \\<Rightarrow> ty option\" (\"_ \\<turnstile> typeof\\<^bsub>_\\<^esub>\") where\n  \"P \\<turnstile> typeof\\<^bsub>h\\<^esub> Unit     = Some Void\"\n| \"P \\<turnstile> typeof\\<^bsub>h\\<^esub> Null     = Some NT\"\n| \"P \\<turnstile> typeof\\<^bsub>h\\<^esub> (Bool b) = Some Boolean\"\n| \"P \\<turnstile> typeof\\<^bsub>h\\<^esub> (Intg i) = Some Integer\"\n| \"P \\<turnstile> typeof\\<^bsub>h\\<^esub> (Ref r)  = (case h (the_addr (Ref r)) of None \\<Rightarrow> None \n                            | Some(C,S) \\<Rightarrow> (if Subobjs P C (the_path(Ref r)) then\n                                   Some(Class(last(the_path(Ref r))))\n                                            else None))\"\n\n\nlemma type_eq_type: \"typeof v = Some T \\<Longrightarrow> P \\<turnstile> typeof\\<^bsub>h\\<^esub> v = Some T\"\nby(induct v)auto\n\nlemma typeof_Void [simp]: \"P \\<turnstile> typeof\\<^bsub>h\\<^esub> v = Some Void \\<Longrightarrow> v = Unit\"\nby(induct v,auto split:if_split_asm)\n\nlemma typeof_NT [simp]: \"P \\<turnstile> typeof\\<^bsub>h\\<^esub> v = Some NT \\<Longrightarrow> v = Null\"\nby(induct v,auto split:if_split_asm)\n\nlemma typeof_Boolean [simp]: \"P \\<turnstile> typeof\\<^bsub>h\\<^esub> v = Some Boolean \\<Longrightarrow> \\<exists>b. v = Bool b\"\nby(induct v,auto split:if_split_asm)\n\nlemma typeof_Integer [simp]: \"P \\<turnstile> typeof\\<^bsub>h\\<^esub> v = Some Integer \\<Longrightarrow> \\<exists>i. v = Intg i\"\nby(induct v,auto split:if_split_asm)\n\nlemma typeof_Class_Subo: \n\"P \\<turnstile> typeof\\<^bsub>h\\<^esub> v = Some (Class C) \\<Longrightarrow> \n\\<exists>a Cs D S. v = Ref(a,Cs) \\<and> h a = Some(D,S) \\<and> Subobjs P D Cs \\<and> last Cs = C\"\nby(induct v,auto split:if_split_asm)\n\nsubsection \\<open>The rules\\<close>\n\ninductive\n  WTrt :: \"[prog,env,heap,expr,     ty     ] \\<Rightarrow> bool\"\n        (\"_,_,_ \\<turnstile> _ : _\"   [51,51,51]50)\n  and WTrts :: \"[prog,env,heap,expr list,ty list] \\<Rightarrow> bool\"\n        (\"_,_,_ \\<turnstile> _ [:] _\" [51,51,51]50)\n  for P :: prog\nwhere\n  \n  WTrtNew:\n  \"is_class P C  \\<Longrightarrow> \n  P,E,h \\<turnstile> new C : Class C\"\n\n| WTrtDynCast:\n  \"\\<lbrakk> P,E,h \\<turnstile> e : T; is_refT T; is_class P C \\<rbrakk>\n  \\<Longrightarrow> P,E,h \\<turnstile> Cast C e : Class C\"\n\n| WTrtStaticCast:\n  \"\\<lbrakk> P,E,h \\<turnstile> e : T; is_refT T; is_class P C \\<rbrakk>\n  \\<Longrightarrow> P,E,h \\<turnstile> \\<lparr>C\\<rparr>e : Class C\"\n\n| WTrtVal:\n  \"P \\<turnstile> typeof\\<^bsub>h\\<^esub> v = Some T \\<Longrightarrow>\n  P,E,h \\<turnstile> Val v : T\"\n\n| WTrtVar:\n  \"E V = Some T \\<Longrightarrow>\n  P,E,h \\<turnstile> Var V : T\"\n\n| WTrtBinOp:\n  \"\\<lbrakk> P,E,h \\<turnstile> e\\<^sub>1 : T\\<^sub>1;  P,E,h \\<turnstile> e\\<^sub>2 : T\\<^sub>2;\n     case bop of Eq \\<Rightarrow> T = Boolean\n               | Add \\<Rightarrow> T\\<^sub>1 = Integer \\<and> T\\<^sub>2 = Integer \\<and> T = Integer \\<rbrakk>\n  \\<Longrightarrow> P,E,h \\<turnstile> e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2 : T\"\n\n| WTrtLAss:\n  \"\\<lbrakk> E V = Some T;  P,E,h \\<turnstile> e : T'; P \\<turnstile> T' \\<le> T \\<rbrakk>\n  \\<Longrightarrow> P,E,h \\<turnstile> V:=e : T\"\n\n| WTrtFAcc:\n\"\\<lbrakk>P,E,h \\<turnstile> e : Class C; Cs \\<noteq> []; P \\<turnstile> C has least F:T via Cs \\<rbrakk>\n  \\<Longrightarrow> P,E,h \\<turnstile> e\\<bullet>F{Cs} : T\"\n\n| WTrtFAccNT:\n  \"P,E,h \\<turnstile> e : NT \\<Longrightarrow> P,E,h \\<turnstile> e\\<bullet>F{Cs} : T\"\n\n| WTrtFAss:\n\"\\<lbrakk>P,E,h \\<turnstile> e\\<^sub>1 : Class C; Cs \\<noteq> [];\n  P \\<turnstile> C has least F:T via Cs; P,E,h \\<turnstile> e\\<^sub>2 : T'; P \\<turnstile> T' \\<le> T \\<rbrakk>\n  \\<Longrightarrow> P,E,h \\<turnstile> e\\<^sub>1\\<bullet>F{Cs}:=e\\<^sub>2 : T\"\n\n| WTrtFAssNT:\n  \"\\<lbrakk> P,E,h \\<turnstile> e\\<^sub>1 : NT; P,E,h \\<turnstile> e\\<^sub>2 : T'; P \\<turnstile> T' \\<le> T \\<rbrakk>\n  \\<Longrightarrow> P,E,h \\<turnstile> e\\<^sub>1\\<bullet>F{Cs}:=e\\<^sub>2 : T\"\n\n| WTrtCall:\n  \"\\<lbrakk> P,E,h \\<turnstile> e : Class C;  P \\<turnstile> C has least M = (Ts,T,m) via Cs;\n     P,E,h \\<turnstile> es [:] Ts'; P \\<turnstile> Ts' [\\<le>] Ts \\<rbrakk>\n  \\<Longrightarrow> P,E,h \\<turnstile> e\\<bullet>M(es) : T\" \n\n| WTrtStaticCall:\n  \"\\<lbrakk> P,E,h \\<turnstile> e : Class C'; P \\<turnstile> Path C' to C unique;\n     P \\<turnstile> C has least M = (Ts,T,m) via Cs; \n     P,E,h \\<turnstile> es [:] Ts'; P \\<turnstile> Ts' [\\<le>] Ts \\<rbrakk>\n  \\<Longrightarrow> P,E,h \\<turnstile> e\\<bullet>(C::)M(es) : T\"\n\n| WTrtCallNT:\n  \"\\<lbrakk>P,E,h \\<turnstile> e : NT; P,E,h \\<turnstile> es [:] Ts\\<rbrakk> \\<Longrightarrow> P,E,h \\<turnstile> Call e Copt M es : T\"\n\n| WTrtBlock:\n  \"\\<lbrakk>P,E(V\\<mapsto>T),h \\<turnstile> e : T'; is_type P T\\<rbrakk> \\<Longrightarrow> \n  P,E,h \\<turnstile> {V:T; e} : T'\"\n\n| WTrtSeq:\n  \"\\<lbrakk> P,E,h \\<turnstile> e\\<^sub>1 : T\\<^sub>1;  P,E,h \\<turnstile> e\\<^sub>2 : T\\<^sub>2 \\<rbrakk>  \\<Longrightarrow>  P,E,h \\<turnstile> e\\<^sub>1;;e\\<^sub>2 : T\\<^sub>2\"\n\n| WTrtCond:\n  \"\\<lbrakk> P,E,h \\<turnstile> e : Boolean;  P,E,h \\<turnstile> e\\<^sub>1 : T;  P,E,h \\<turnstile> e\\<^sub>2 : T \\<rbrakk>\n  \\<Longrightarrow> P,E,h \\<turnstile> if (e) e\\<^sub>1 else e\\<^sub>2 : T\"\n\n| WTrtWhile:\n  \"\\<lbrakk> P,E,h \\<turnstile> e : Boolean;  P,E,h \\<turnstile> c : T \\<rbrakk>\n  \\<Longrightarrow>  P,E,h \\<turnstile> while(e) c : Void\"\n\n| WTrtThrow:\n  \"\\<lbrakk>P,E,h \\<turnstile> e : T'; is_refT T'\\<rbrakk>  \n \\<Longrightarrow>  P,E,h \\<turnstile> throw e : T\"\n\n\n| WTrtNil:\n\"P,E,h \\<turnstile> [] [:] []\"\n\n| WTrtCons:\n \"\\<lbrakk> P,E,h \\<turnstile> e : T;  P,E,h \\<turnstile> es [:] Ts \\<rbrakk> \\<Longrightarrow>  P,E,h \\<turnstile> e#es [:] T#Ts\"\n\n\n\n\ndeclare\n  WTrt_WTrts.intros[intro!]\n  WTrtNil[iff]\ndeclare\n  WTrtFAcc[rule del] WTrtFAccNT[rule del]\n  WTrtFAss[rule del] WTrtFAssNT[rule del]\n  WTrtCall[rule del] WTrtCallNT[rule del]\n\nlemmas WTrt_induct = WTrt_WTrts.induct [split_format (complete)]\n  and WTrt_inducts = WTrt_WTrts.inducts [split_format (complete)]\n\n\nsubsection\\<open>Easy consequences\\<close>\n\ninductive_simps [iff]:\n  \"P,E,h \\<turnstile> [] [:] Ts\"\n  \"P,E,h \\<turnstile> e#es [:] T#Ts\"\n  \"P,E,h \\<turnstile> (e#es) [:] Ts\"\n  \"P,E,h \\<turnstile> Val v : T\"\n  \"P,E,h \\<turnstile> Var V : T\"\n  \"P,E,h \\<turnstile> e\\<^sub>1;;e\\<^sub>2 : T\\<^sub>2\"\n  \"P,E,h \\<turnstile> {V:T; e} : T'\"\n\n\n\n\napply(induct_tac es\\<^sub>1)\n apply simp\napply clarsimp\napply(erule thin_rl)\napply (rule iffI)\n apply clarsimp\n apply(rule exI)+\n apply(rule conjI)\n  prefer 2 apply blast\n apply simp\napply fastforce\ndone\n\n\n\ninductive_cases WTrt_elim_cases[elim!]:\n  \"P,E,h \\<turnstile> new C : T\"\n  \"P,E,h \\<turnstile> Cast C e : T\"\n  \"P,E,h \\<turnstile> \\<lparr>C\\<rparr>e : T\"\n  \"P,E,h \\<turnstile> e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2 : T\"\n  \"P,E,h \\<turnstile> V:=e : T\"\n  \"P,E,h \\<turnstile> e\\<bullet>F{Cs} : T\"\n  \"P,E,h \\<turnstile> e\\<bullet>F{Cs} := v : T\"\n  \"P,E,h \\<turnstile> e\\<bullet>M(es) : T\"\n  \"P,E,h \\<turnstile> e\\<bullet>(C::)M(es) : T\"\n  \"P,E,h \\<turnstile> if (e) e\\<^sub>1 else e\\<^sub>2 : T\"\n  \"P,E,h \\<turnstile> while(e) c : T\"\n  \"P,E,h \\<turnstile> throw e : T\"\n\n\nsubsection\\<open>Some interesting lemmas\\<close>\n\n\nlemma WTrts_Val[simp]:\n \"\\<And>Ts. (P,E,h \\<turnstile> map Val vs [:] Ts) = (map (\\<lambda>v. (P \\<turnstile> typeof\\<^bsub>h\\<^esub>) v) vs = map Some Ts)\"\n\napply(induct vs)\n apply fastforce\napply(case_tac Ts)\n apply simp\napply simp\ndone\n\n\n\n\n\n\nlemma WTrt_env_mono:\n  \"P,E,h \\<turnstile> e : T \\<Longrightarrow> (\\<And>E'. E \\<subseteq>\\<^sub>m E' \\<Longrightarrow> P,E',h \\<turnstile> e : T)\" and\n  \"P,E,h \\<turnstile> es [:] Ts \\<Longrightarrow> (\\<And>E'. E \\<subseteq>\\<^sub>m E' \\<Longrightarrow> P,E',h \\<turnstile> es [:] Ts)\"\n\napply(induct rule: WTrt_inducts)\napply(simp add: WTrtNew)\napply(fastforce simp: WTrtDynCast)\napply(fastforce simp: WTrtStaticCast)\napply(fastforce simp: WTrtVal)\napply(simp add: WTrtVar map_le_def dom_def)\napply(fastforce simp add: WTrtBinOp)\napply (force simp:map_le_def)\napply(fastforce simp: WTrtFAcc)\napply(simp add: WTrtFAccNT)\napply(fastforce simp: WTrtFAss)\napply(fastforce simp: WTrtFAssNT)\napply(fastforce simp: WTrtCall)\napply(fastforce simp: WTrtStaticCall)\napply(fastforce simp: WTrtCallNT)\napply(fastforce simp: map_le_def)\napply(fastforce)\napply(fastforce simp: WTrtCond)\napply(fastforce simp: WTrtWhile)\napply(fastforce simp: WTrtThrow)\napply(simp add: WTrtNil)\napply(simp add: WTrtCons)\ndone\n\n\nlemma WT_implies_WTrt: \"P,E \\<turnstile> e :: T \\<Longrightarrow> P,E,h \\<turnstile> e : T\"\nand WTs_implies_WTrts: \"P,E \\<turnstile> es [::] Ts \\<Longrightarrow> P,E,h \\<turnstile> es [:] Ts\"\n\nproof(induct rule: WT_WTs_inducts)\n  case WTVal thus ?case by (fastforce dest:type_eq_type)\nnext\n  case WTBinOp thus ?case by (fastforce split:bop.splits)\nnext\n  case WTFAcc thus ?case\n    by(fastforce intro!:WTrtFAcc dest:Subobjs_nonempty \n                  simp:LeastFieldDecl_def FieldDecls_def)\nnext\n  case WTFAss thus ?case\n    by(fastforce intro!:WTrtFAss dest:Subobjs_nonempty\n                  simp:LeastFieldDecl_def FieldDecls_def)\nnext\n  case WTCall thus ?case by (fastforce intro:WTrtCall)\nqed (auto simp del:fun_upd_apply)\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Evaluation/CoreC++/WellTypeRT.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185205547239, "lm_q2_score": 0.4493926344647596, "lm_q1q2_score": 0.25436455410793307}}
{"text": "(*  Title:      HOL/Bali/Type.thy\n    Author:     David von Oheimb\n*)\n\nsubsection \\<open>Java types\\<close>\n\ntheory Type imports Name begin\n\ntext \\<open>\nsimplifications:\n\\begin{itemize}\n\\item only the most important primitive types\n\\item the null type is regarded as reference type\n\\end{itemize}\n\\<close>\n\ndatatype prim_ty        \\<comment>\\<open>primitive type, cf. 4.2\\<close>\n        = Void          \\<comment>\\<open>result type of void methods\\<close>\n        | Boolean\n        | Integer\n\n\ndatatype ref_ty         \\<comment>\\<open>reference type, cf. 4.3\\<close>\n        = NullT         \\<comment>\\<open>null type, cf. 4.1\\<close>\n        | IfaceT qtname \\<comment>\\<open>interface type\\<close>\n        | ClassT qtname \\<comment>\\<open>class type\\<close>\n        | ArrayT ty     \\<comment>\\<open>array type\\<close>\n\nand ty                  \\<comment>\\<open>any type, cf. 4.1\\<close>\n        = PrimT prim_ty \\<comment>\\<open>primitive type\\<close>\n        | RefT  ref_ty  \\<comment>\\<open>reference type\\<close>\n\nabbreviation \"NT == RefT NullT\"\nabbreviation \"Iface I == RefT (IfaceT I)\"\nabbreviation \"Class C == RefT (ClassT C)\"\nabbreviation Array :: \"ty \\<Rightarrow> ty\"  (\"_.[]\" [90] 90)\n  where \"T.[] == RefT (ArrayT T)\"\n\ndefinition\n  the_Class :: \"ty \\<Rightarrow> qtname\"\n  where \"the_Class T = (SOME C. T = Class C)\" (** primrec not possible here **)\n \nlemma the_Class_eq [simp]: \"the_Class (Class C)= C\"\nby (auto simp add: the_Class_def)\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/HOL/Bali/Type.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331462646255, "lm_q2_score": 0.4263215925474903, "lm_q1q2_score": 0.25427232876364536}}
{"text": "theory JVMCFG_wf imports JVMInterpretation \"../StaticInter/CFGExit_wf\" begin\n\ninductive_set Def :: \"wf_jvmprog \\<Rightarrow> cfg_node \\<Rightarrow> var set\"\n  for P :: \"wf_jvmprog\"\n  and n :: \"cfg_node\"\nwhere\n  Def_Main_Heap:\n  \"n = (ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Return)\n  \\<Longrightarrow> Heap \\<in> Def P n\"\n| Def_Main_Exception:\n  \"n = (ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Return)\n  \\<Longrightarrow> Exception \\<in> Def P n\"\n| Def_Main_Stack_0:\n  \"n = (ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Return)\n  \\<Longrightarrow> Stack 0 \\<in> Def P n\"\n| Def_Load:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Enter);\n  C \\<noteq> ClassMain P;\n  instrs_of (PROG P) C M ! pc = Load idx;\n  i = stkLength (P, C, M) pc\\<rbrakk>\n  \\<Longrightarrow> Stack i \\<in> Def P n\"\n| Def_Store:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Enter);\n  C \\<noteq> ClassMain P;\n  instrs_of (PROG P) C M ! pc = Store idx \\<rbrakk>\n  \\<Longrightarrow> Local idx \\<in> Def P n\"\n| Def_Push:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Enter);\n  C \\<noteq> ClassMain P;\n  instrs_of (PROG P) C M ! pc = Push v;\n  i = stkLength (P, C, M) pc \\<rbrakk>\n  \\<Longrightarrow> Stack i \\<in> Def P n\"\n| Def_IAdd:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Enter);\n  C \\<noteq> ClassMain P;\n  instrs_of (PROG P) C M ! pc = IAdd;\n  i = stkLength (P, C, M) pc - 2 \\<rbrakk>\n  \\<Longrightarrow> Stack i \\<in> Def P n\"\n| Def_CmpEq:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Enter);\n  C \\<noteq> ClassMain P;\n  instrs_of (PROG P) C M ! pc = CmpEq;\n  i = stkLength (P, C, M) pc - 2 \\<rbrakk>\n  \\<Longrightarrow> Stack i \\<in> Def P n\"\n| Def_New_Heap:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Normal);\n  C \\<noteq> ClassMain P;\n  instrs_of (PROG P) C M ! pc = New Cl \\<rbrakk>\n  \\<Longrightarrow> Heap \\<in> Def P n\"\n| Def_New_Stack:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Normal);\n  C \\<noteq> ClassMain P;\n  instrs_of (PROG P) C M ! pc = New Cl;\n  i = stkLength (P, C, M) pc \\<rbrakk>\n  \\<Longrightarrow> Stack i \\<in> Def P n\"\n| Def_Exception:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Exceptional pco nt);\n  C \\<noteq> ClassMain P \\<rbrakk>\n  \\<Longrightarrow> Exception \\<in> Def P n\"\n| Def_Exception_handle:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Enter);\n  C \\<noteq> ClassMain P;\n  i = stkLength (P, C, M) pc' - 1 \\<rbrakk>\n  \\<Longrightarrow> Stack i \\<in> Def P n\"\n| Def_Exception_handle_return:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Return);\n  C \\<noteq> ClassMain P;\n  i = stkLength (P, C, M) pc' - 1 \\<rbrakk>\n  \\<Longrightarrow> Stack i \\<in> Def P n\"\n| Def_Getfield:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Normal);\n  C \\<noteq> ClassMain P;\n  instrs_of (PROG P) C M ! pc = Getfield Cl Fd;\n  i = stkLength (P, C, M) pc - 1 \\<rbrakk>\n  \\<Longrightarrow> Stack i \\<in> Def P n\"\n| Def_Putfield:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Normal);\n  C \\<noteq> ClassMain P;\n  instrs_of (PROG P) C M ! pc = Putfield Cl Fd \\<rbrakk>\n  \\<Longrightarrow> Heap \\<in> Def P n\"\n| Def_Invoke_Return_Heap:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Return);\n  C \\<noteq> ClassMain P;\n  instrs_of (PROG P) C M ! pc = Invoke M' n' \\<rbrakk>\n  \\<Longrightarrow> Heap \\<in> Def P n\"\n| Def_Invoke_Return_Exception:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Return);\n  C \\<noteq> ClassMain P;\n  instrs_of (PROG P) C M ! pc = Invoke M' n' \\<rbrakk>\n  \\<Longrightarrow> Exception \\<in> Def P n\"\n| Def_Invoke_Return_Stack:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Return);\n  C \\<noteq> ClassMain P;\n  instrs_of (PROG P) C M ! pc = Invoke M' n';\n  i = stkLength (P, C, M) (Suc pc) - 1 \\<rbrakk>\n  \\<Longrightarrow> Stack i \\<in> Def P n\"\n| Def_Invoke_Call_Heap:\n  \"\\<lbrakk> n = (C, M, None, Enter);\n  C \\<noteq> ClassMain P \\<rbrakk>\n  \\<Longrightarrow> Heap \\<in> Def P n\"\n| Def_Invoke_Call_Local:\n  \"\\<lbrakk> n = (C, M, None, Enter);\n  C \\<noteq> ClassMain P;\n  i < locLength (P, C, M) 0 \\<rbrakk>\n  \\<Longrightarrow> Local i \\<in> Def P n\"\n| Def_Return:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Enter);\n  C \\<noteq> ClassMain P;\n  instrs_of (PROG P) C M ! pc = instr.Return \\<rbrakk>\n  \\<Longrightarrow> Stack 0 \\<in> Def P n\"\n\ninductive_set Use :: \"wf_jvmprog \\<Rightarrow> cfg_node \\<Rightarrow> var set\"\n  for P :: \"wf_jvmprog\"\n  and n :: \"cfg_node\"\nwhere\n  Use_Main_Heap:\n  \"n = (ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Normal)\n  \\<Longrightarrow> Heap \\<in> Use P n\"\n| Use_Load:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Enter);\n  C \\<noteq> ClassMain P;\n  instrs_of (PROG P) C M ! pc = Load idx \\<rbrakk>\n  \\<Longrightarrow> Local idx \\<in> Use P n\"\n| Use_Enter_Stack:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Enter);\n  C \\<noteq> ClassMain P;\n  case (instrs_of (PROG P) C M ! pc)\n    of Store n' \\<Rightarrow> d = 1\n    | Getfield F Cl \\<Rightarrow> d = 1\n    | Putfield F Cl \\<Rightarrow> d = 2\n    | Checkcast Cl \\<Rightarrow> d = 1\n    | Invoke M' n' \\<Rightarrow> d = Suc n'\n    | IAdd \\<Rightarrow> d \\<in> {1, 2}\n    | IfFalse i \\<Rightarrow> d = 1\n    | CmpEq \\<Rightarrow> d \\<in> {1 , 2}\n    | Throw \\<Rightarrow> d = 1\n    | instr.Return \\<Rightarrow> d = 1\n    | _ \\<Rightarrow> False;\n  i = stkLength (P, C, M) pc - d \\<rbrakk>\n  \\<Longrightarrow> Stack i \\<in> Use P n\"\n| Use_Enter_Local:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Enter);\n  C \\<noteq> ClassMain P;\n  instrs_of (PROG P) C M ! pc = Load n' \\<rbrakk>\n  \\<Longrightarrow> Local n' \\<in> Use P n\"\n| Use_Enter_Heap:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Enter);\n  C \\<noteq> ClassMain P;\n  case (instrs_of (PROG P) C M ! pc)\n    of New Cl \\<Rightarrow> True\n    | Checkcast Cl \\<Rightarrow> True\n    | Throw \\<Rightarrow> True\n    | _ \\<Rightarrow> False \\<rbrakk>\n  \\<Longrightarrow> Heap \\<in> Use P n\"\n| Use_Normal_Heap:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Normal);\n  C \\<noteq> ClassMain P;\n  case (instrs_of (PROG P) C M ! pc)\n    of New Cl \\<Rightarrow> True\n    | Getfield F Cl \\<Rightarrow> True\n    | Putfield F Cl \\<Rightarrow> True\n    | Invoke M' n' \\<Rightarrow> True\n    | _ \\<Rightarrow> False \\<rbrakk>\n  \\<Longrightarrow> Heap \\<in> Use P n\"\n| Use_Normal_Stack:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Normal);\n  C \\<noteq> ClassMain P;\n  case (instrs_of (PROG P) C M ! pc)\n    of Getfield F Cl \\<Rightarrow> d = 1\n    | Putfield F Cl \\<Rightarrow> d \\<in> {1, 2}\n    | Invoke M' n' \\<Rightarrow> d > 0 \\<and> d \\<le> Suc n'\n    | _ \\<Rightarrow> False;\n  i = stkLength (P, C, M) pc - d \\<rbrakk>\n  \\<Longrightarrow> Stack i \\<in> Use P n\"\n| Use_Return_Heap:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Return);\n  instrs_of (PROG P) C M ! pc = Invoke M' n' \\<or> C = ClassMain P \\<rbrakk>\n  \\<Longrightarrow> Heap \\<in> Use P n\"\n| Use_Return_Stack:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Return);\n  (instrs_of (PROG P) C M ! pc = Invoke M' n' \\<and> i = stkLength (P, C, M) (Suc pc) - 1) \\<or>\n  (C = ClassMain P \\<and> i = 0) \\<rbrakk>\n  \\<Longrightarrow> Stack i \\<in> Use P n\"\n| Use_Return_Exception:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Return);\n  instrs_of (PROG P) C M ! pc = Invoke M' n' \\<or> C = ClassMain P \\<rbrakk>\n  \\<Longrightarrow> Exception \\<in> Use P n\"\n| Use_Exceptional_Stack:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Exceptional opc' nt);\n  case (instrs_of (PROG P) C M ! pc)\n    of Throw \\<Rightarrow> True\n    | _ \\<Rightarrow> False;\n  i = stkLength (P, C, M) pc - 1 \\<rbrakk>\n  \\<Longrightarrow> Stack i \\<in> Use P n\"\n| Use_Exceptional_Exception:\n  \"\\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Exceptional \\<lfloor>pc'\\<rfloor> Return);\n  instrs_of (PROG P) C M ! pc = Invoke M' n' \\<rbrakk>\n  \\<Longrightarrow> Exception \\<in> Use P n\"\n| Use_Method_Leave_Exception:\n  \"\\<lbrakk> n = (C, M, None, Return);\n  C \\<noteq> ClassMain P \\<rbrakk>\n  \\<Longrightarrow> Exception \\<in> Use P n\"\n| Use_Method_Leave_Heap:\n  \"\\<lbrakk> n = (C, M, None, Return);\n  C \\<noteq> ClassMain P \\<rbrakk>\n  \\<Longrightarrow> Heap \\<in> Use P n\"\n| Use_Method_Leave_Stack:\n  \"\\<lbrakk> n = (C, M, None, Return);\n  C \\<noteq> ClassMain P \\<rbrakk>\n  \\<Longrightarrow> Stack 0 \\<in> Use P n\"\n| Use_Method_Entry_Heap:\n  \"\\<lbrakk> n = (C, M, None, Enter);\n  C \\<noteq> ClassMain P \\<rbrakk>\n  \\<Longrightarrow> Heap \\<in> Use P n\"\n| Use_Method_Entry_Local:\n  \"\\<lbrakk> n = (C, M, None, Enter);\n  C \\<noteq> ClassMain P;\n  i < locLength (P, C, M) 0 \\<rbrakk>\n  \\<Longrightarrow> Local i \\<in> Use P n\"\n\nfun ParamDefs :: \"wf_jvmprog \\<Rightarrow> cfg_node \\<Rightarrow> var list\"\nwhere\n  \"ParamDefs P (C, M, \\<lfloor>pc\\<rfloor>, Return) = [Heap, Stack (stkLength (P, C, M) (Suc pc) - 1), Exception]\"\n  | \"ParamDefs P (C, M, opc, nt) = []\"\n\nfunction ParamUses :: \"wf_jvmprog \\<Rightarrow> cfg_node \\<Rightarrow> var set list\"\nwhere\n  \"ParamUses P (ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Normal) = [{Heap},{}]\"\n  |\n  \"M \\<noteq> MethodMain P \\<or> opc \\<noteq> \\<lfloor>0\\<rfloor> \\<or> nt \\<noteq> Normal\n  \\<Longrightarrow> ParamUses P (ClassMain P, M, opc, nt) = []\"\n  |\n  \"C \\<noteq> ClassMain P\n  \\<Longrightarrow> ParamUses P (C, M, opc, nt) = (case opc of None \\<Rightarrow> []\n  | \\<lfloor>pc\\<rfloor> \\<Rightarrow> (case nt of Normal \\<Rightarrow> (case (instrs_of (PROG P) C M ! pc) of\n      Invoke M' n \\<Rightarrow> (\n          {Heap} # rev (map (\\<lambda>n. {Stack (stkLength (P, C, M) pc - (Suc n))}) [0..<n + 1])\n      )\n      | _ \\<Rightarrow> [])\n    | _ \\<Rightarrow> []\n    )\n  )\"\n  by atomize_elim auto\ntermination by lexicographic_order\n\nlemma in_set_ParamDefsE:\n  \"\\<lbrakk> V \\<in> set (ParamDefs P n);\n  \\<And>C M pc. \\<lbrakk> n = (C, M, \\<lfloor>pc\\<rfloor>, Return);\n         V \\<in> {Heap, Stack (stkLength (P, C, M) (Suc pc) - 1), Exception} \\<rbrakk> \\<Longrightarrow> thesis \\<rbrakk>\n  \\<Longrightarrow> thesis\"\n  by (cases \"(P, n)\" rule: ParamDefs.cases) auto\n\nlemma in_set_ParamUsesE:\n  assumes V_in_ParamUses: \"V \\<in> \\<Union>(set (ParamUses P n))\"\n  obtains \"n = (ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Normal)\" and \"V = Heap\"\n  | C M pc M' n' i where \"n = (C, M, \\<lfloor>pc\\<rfloor>, Normal)\" and \"instrs_of (PROG P) C M ! pc = Invoke M' n'\"\n    and \"V = Heap \\<or> V = Stack (stkLength (P, C, M) pc - Suc i)\" and \"i < Suc n'\" and \"C \\<noteq> ClassMain P\"\nproof (cases \"(P, n)\" rule: ParamUses.cases)\n  case 1 with V_in_ParamUses that show ?thesis by clarsimp\nnext\n  case 2 with V_in_ParamUses that show ?thesis by clarsimp\nnext\n  case (3 C P M pc nt)\n  with V_in_ParamUses that show ?thesis\n    using [[simproc del: list_to_set_comprehension]]\n    by (cases nt, auto) (rename_tac a b, case_tac \"instrs_of (PROG P) C M ! a\", simp_all, fastforce)\nqed\n\nlemma sees_method_fun_wf:\n  assumes \"PROG P \\<turnstile> D sees M': Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in D\"\n  and \"(D, D', fs, ms) \\<in> set (PROG P)\"\n  and \"(M', Ts', T', mxs', mxl\\<^sub>0', is', xt') \\<in> set ms\"\n  shows \"Ts = Ts' \\<and> T = T' \\<and> mxs = mxs' \\<and> mxl\\<^sub>0 = mxl\\<^sub>0' \\<and> is = is' \\<and> xt = xt'\"\nproof -\n  from distinct_class_names [of P] \\<open>(D, D', fs, ms) \\<in> set (PROG P)\\<close>\n  have \"class (PROG P) D = \\<lfloor>(D', fs, ms)\\<rfloor>\"\n    by (fastforce intro: map_of_SomeI simp: class_def)\n  moreover with distinct_method_names have \"distinct_fst ms\"\n    by fastforce\n  ultimately show ?thesis using\n    \\<open>PROG P \\<turnstile> D sees M': Ts\\<rightarrow>T = (mxs, mxl\\<^sub>0, is, xt) in D\\<close>\n    \\<open>(M', Ts', T', mxs', mxl\\<^sub>0', is', xt') \\<in> set ms\\<close>\n    by (fastforce dest: visible_method_exists map_of_SomeD distinct_fst_isin_same_fst\n      simp: distinct_fst_is_distinct_fst)\nqed\n\ninterpretation JVMCFG_wf:\n  CFG_wf  \"sourcenode\" \"targetnode\" \"kind\" \"valid_edge (P, C0, Main)\"\n  \"(ClassMain P, MethodMain P, None, Enter)\"\n  \"(\\<lambda>(C, M, pc, type). (C, M))\" \"get_return_edges P\"\n  \"((ClassMain P, MethodMain P),[],[]) # procs (PROG P)\"\n  \"(ClassMain P, MethodMain P)\"\n  \"Def P\" \"Use P\" \"ParamDefs P\" \"ParamUses P\"\n  for P C0 Main\nproof (unfold_locales)\n  show \"Def P (ClassMain P, MethodMain P, None, Enter) = {} \\<and>\n    Use P (ClassMain P, MethodMain P, None, Enter) = {}\"\n    by (fastforce elim: Def.cases Use.cases)\nnext\n  fix a Q r p fs ins outs\n  assume \"valid_edge (P, C0, Main) a\"\n    and \"kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\"\n    and params: \"(p, ins, outs) \\<in> set (((ClassMain P, MethodMain P), [], []) # procs (PROG P))\"\n  hence \"(P, C0, Main) \\<turnstile> sourcenode a -Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\\<rightarrow> targetnode a\"\n    by (simp add: valid_edge_def)\n  from this params show \"length (ParamUses P (sourcenode a)) = length ins\"\n  proof cases\n    case Main_Call\n    with params show ?thesis\n      by auto (erule in_set_procsE, auto dest: sees_method_idemp sees_method_fun)\n  next\n    case (CFG_Invoke_Call C M pc M' n ST LT D' Ts T mxs mxl0 \"is\" xt D Q' paramDefs)\n    hence [simp]: \"Q' = Q\" and [simp]: \"r = (C, M, pc)\" and [simp]: \"p = (D, M')\"\n      and [simp]: \"fs = paramDefs\"\n      by simp_all\n    from CFG_Invoke_Call obtain T' mxs' mpc' xt' where\n      \"PROG P,T',mxs',mpc',xt' \\<turnstile> instrs_of (PROG P) C M ! pc,pc :: TYPING P C M\"\n      by (blast dest: reachable_node_impl_wt_instr)\n    moreover from \\<open>PROG P \\<turnstile> D' sees M': Ts\\<rightarrow>T = (mxs, mxl0, is, xt) in D\\<close>\n    have \"PROG P \\<turnstile> D sees M': Ts\\<rightarrow>T = (mxs, mxl0, is, xt) in D\"\n      by -(drule sees_method_idemp)\n    with params have \"PROG P \\<turnstile> D sees M': Ts\\<rightarrow>T=(mxs, mxl0, is, xt) in D\"\n      and \"ins = Heap # map Local [0..<Suc (length Ts)]\"\n      by (fastforce elim: in_set_procsE dest: sees_method_fun)+\n    ultimately show ?thesis using CFG_Invoke_Call\n      by (fastforce dest: sees_method_fun list_all2_lengthD simp: min_def)\n  qed simp_all\nnext\n  fix a\n  assume \"valid_edge (P, C0, Main) a\"\n  thus \"distinct (ParamDefs P (targetnode a))\"\n    by (clarsimp simp: valid_edge_def) (erule JVMCFG.cases, auto)\nnext\n  fix a Q' p f' ins outs\n  assume \"valid_edge (P, C0, Main) a\"\n    and \"kind a = Q'\\<hookleftarrow>\\<^bsub>p\\<^esub>f'\"\n    and params: \"(p, ins, outs) \\<in> set (((ClassMain P, MethodMain P), [], []) # procs (PROG P))\"\n  hence \"(P, C0, Main) \\<turnstile> sourcenode a -Q'\\<hookleftarrow>\\<^bsub>p\\<^esub>f'\\<rightarrow> targetnode a\"\n    by (simp add: valid_edge_def)\n  from this params\n  show \"length (ParamDefs P (targetnode a)) = length outs\"\n    by cases (auto elim: in_set_procsE)\nnext\n  fix n V\n  assume params: \"V \\<in> set (ParamDefs P n)\"\n    and vn: \"CFG.valid_node sourcenode targetnode (valid_edge (P, C0, Main)) n\"\n  then obtain ek n'\n    where ve:\"valid_edge (P, C0, Main) (n, ek, n') \\<or> valid_edge (P, C0, Main) (n', ek, n)\"\n    by (fastforce simp: JVMCFG_Interpret.valid_node_def)\n  from params obtain C M pc where [simp]: \"n = (C, M, \\<lfloor>pc\\<rfloor>, Return)\"\n    and V: \"V \\<in> {Heap, Stack (stkLength (P, C, M) (Suc pc) - 1), Exception}\"\n    by (blast elim: in_set_ParamDefsE)\n  from ve show \"V \\<in> Def P n\"\n  proof\n    assume \"valid_edge (P, C0, Main) (n, ek, n')\"\n    thus ?thesis unfolding valid_edge_def\n    proof cases\n      case Main_Return_to_Exit with V show ?thesis\n        by (auto intro: Def_Main_Heap Def_Main_Stack_0 Def_Main_Exception simp: stkLength_def)\n    next\n      case CFG_Invoke_Return_Check_Normal with V show ?thesis\n        by (fastforce intro: Def_Invoke_Return_Heap\n          Def_Invoke_Return_Stack Def_Invoke_Return_Exception)\n    next\n      case CFG_Invoke_Return_Check_Exceptional with V show ?thesis\n        by (fastforce intro: Def_Invoke_Return_Heap\n          Def_Invoke_Return_Stack Def_Invoke_Return_Exception)\n    next\n      case CFG_Invoke_Return_Exceptional_prop with V show ?thesis\n        by (fastforce intro: Def_Invoke_Return_Heap\n          Def_Invoke_Return_Stack Def_Invoke_Return_Exception)\n    qed simp_all\n  next\n    assume \"valid_edge (P, C0, Main) (n', ek, n)\"\n    thus ?thesis unfolding valid_edge_def\n    proof cases\n      case Main_Call_LFalse with V show ?thesis\n        by (auto intro: Def_Main_Heap Def_Main_Stack_0 Def_Main_Exception simp: stkLength_def)\n    next\n      case CFG_Invoke_False with V show ?thesis\n        by (fastforce intro: Def_Invoke_Return_Heap\n          Def_Invoke_Return_Stack Def_Invoke_Return_Exception)\n    next\n      case CFG_Return_from_Method with V show ?thesis\n        by (fastforce elim!: JVMCFG.cases intro!: Def_Main_Stack_0\n          intro: Def_Main_Heap Def_Main_Exception Def_Invoke_Return_Heap\n          Def_Invoke_Return_Exception Def_Invoke_Return_Stack simp: stkLength_def)\n    qed simp_all\n  qed\nnext\n  fix a Q r p fs ins outs V\n  assume ve: \"valid_edge (P, C0, Main) a\"\n    and kind: \"kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\"\n    and params: \"(p, ins, outs) \\<in> set (((ClassMain P, MethodMain P), [], []) # procs (PROG P))\"\n    and V: \"V \\<in> set ins\"\n  from params V obtain D fs ms Ts T mb where \"class (PROG P) (fst p) = \\<lfloor>(D, fs, ms)\\<rfloor>\"\n    and \"method\": \"PROG P \\<turnstile> (fst p) sees (snd p): Ts\\<rightarrow>T = mb in (fst p)\"\n    and ins: \"ins = Heap # map Local [0..<Suc (length Ts)]\"\n    by (cases p) (fastforce elim: in_set_procsE)\n  from ve kind show \"V \\<in> Def P (targetnode a)\" unfolding valid_edge_def\n  proof cases\n    case (Main_Call T' mxs mxl0 \"is\" xt D' initParams)\n    with kind have \"PROG P \\<turnstile> D' sees Main: []\\<rightarrow>T' = (mxs, mxl0, is, xt) in D'\"\n      and [simp]: \"p = (D', Main)\"\n      by (auto dest: sees_method_idemp)\n    with \"method\" have [simp]: \"Ts = []\" and [simp]: \"T' = T\" and [simp]: \"mb = (mxs, mxl0, is, xt)\"\n      by (fastforce dest: sees_method_fun)+\n    from Main_Call ins V show ?thesis\n      by (fastforce intro!: Def_Invoke_Call_Heap Def_Invoke_Call_Local\n        dest: sees_method_idemp wt_jvm_prog_impl_wt_start[OF wf_jvmprog_is_wf_typ]\n        simp: locLength_def wt_start_def)\n  next\n    case (CFG_Invoke_Call C M pc M' n ST LT D' Ts' T' mxs mxl0 \"is\" xt D'')\n    with kind have \"PROG P \\<turnstile> D'' sees M': Ts'\\<rightarrow>T' = (mxs, mxl0, is, xt) in D''\"\n      and [simp]: \"p = (D'', M')\"\n      by (auto dest: sees_method_idemp)\n    with \"method\" have [simp]: \"Ts' = Ts\" and [simp]: \"T' = T\" and [simp]: \"mb = (mxs, mxl0, is, xt)\"\n      by (fastforce dest: sees_method_fun)+\n    from CFG_Invoke_Call ins V show ?thesis\n      by (fastforce intro!: Def_Invoke_Call_Local Def_Invoke_Call_Heap\n        dest: sees_method_idemp wt_jvm_prog_impl_wt_start[OF wf_jvmprog_is_wf_typ] list_all2_lengthD\n        simp: locLength_def min_def wt_start_def)\n  qed simp_all\nnext\n  fix a Q r p fs\n  assume \"valid_edge (P, C0, Main) a\" and \"kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\"\n  thus \"Def P (sourcenode a) = {}\" unfolding valid_edge_def\n    by cases (auto elim: Def.cases)\nnext\n  fix n V\n  assume \"CFG.valid_node sourcenode targetnode (valid_edge (P, C0, Main)) n\"\n    and V: \"V \\<in> \\<Union>(set (ParamUses P n))\"\n  then obtain ek n'\n    where ve:\"valid_edge (P, C0, Main) (n, ek, n') \\<or> valid_edge (P, C0, Main) (n', ek, n)\"\n    by (fastforce simp: JVMCFG_Interpret.valid_node_def)\n  from V obtain C M pc M' n'' i where\n    V: \"n = (ClassMain P, MethodMain P, \\<lfloor>0\\<rfloor>, Normal) \\<and> V = Heap \\<or>\n    n = (C, M, \\<lfloor>pc\\<rfloor>, Normal) \\<and> instrs_of (PROG P) C M ! pc = Invoke M' n'' \\<and>\n      (V = Heap \\<or> V = Stack (stkLength (P, C, M) pc - Suc i)) \\<and> i < Suc n'' \\<and> C \\<noteq> ClassMain P\"\n    by -(erule in_set_ParamUsesE, fastforce+)\n  from ve show \"V \\<in> Use P n\"\n  proof\n    assume \"valid_edge (P, C0, Main) (n, ek, n')\"\n    from this V show ?thesis unfolding valid_edge_def\n    proof cases\n      case Main_Call_LFalse with V show ?thesis by (fastforce intro: Use_Main_Heap)\n    next\n      case Main_Call with V show ?thesis by (fastforce intro: Use_Main_Heap)\n    next\n      case CFG_Invoke_Call with V show ?thesis\n        by (fastforce intro: Use_Normal_Heap Use_Normal_Stack [where d=\"Suc i\"])\n    next\n      case CFG_Invoke_False with V show ?thesis\n        by (fastforce intro: Use_Normal_Heap Use_Normal_Stack [where d=\"Suc i\"])\n    qed simp_all\n  next\n    assume \"valid_edge (P, C0, Main) (n', ek, n)\"\n    from this V show ?thesis unfolding valid_edge_def\n    proof cases\n      case Main_to_Call with V show ?thesis by (fastforce intro: Use_Main_Heap)\n    next\n      case CFG_Invoke_Check_NP_Normal with V show ?thesis\n        by (fastforce intro: Use_Normal_Heap Use_Normal_Stack [where d=\"Suc i\"])\n    qed simp_all\n  qed\nnext\n  fix a Q p f ins outs V\n  assume \"valid_edge (P, C0, Main) a\"\n    and \"kind a = Q\\<hookleftarrow>\\<^bsub>p\\<^esub>f\"\n    and \"(p, ins, outs) \\<in> set (((ClassMain P, MethodMain P), [], []) # procs (PROG P))\"\n    and \"V \\<in> set outs\"\n  thus \"V \\<in> Use P (sourcenode a)\" unfolding valid_edge_def\n    by (cases, simp_all)\n  (fastforce elim: in_set_procsE\n    intro: Use_Method_Leave_Heap Use_Method_Leave_Stack Use_Method_Leave_Exception)\nnext\n  fix a V s\n  assume ve: \"valid_edge (P, C0, Main) a\"\n    and V_notin_Def: \"V \\<notin> Def P (sourcenode a)\"\n    and ik: \"intra_kind (kind a)\"\n    and pred: \"JVMCFG_Interpret.pred (kind a) s\"\n  show \"JVMCFG_Interpret.state_val\n    (CFG.transfer (((ClassMain P, MethodMain P), [], []) # procs (PROG P)) (kind a) s) V\n    = JVMCFG_Interpret.state_val s V\"\n  proof (cases s)\n    case Nil\n    thus ?thesis by simp\n  next\n    case [simp]: Cons\n    with ve V_notin_Def ik pred show ?thesis unfolding valid_edge_def\n    proof cases\n      case CFG_Load with V_notin_Def show ?thesis by (fastforce intro: Def_Load)\n    next case CFG_Store with V_notin_Def show ?thesis by (fastforce intro: Def_Store)\n    next case CFG_Push with V_notin_Def show ?thesis by (fastforce intro: Def_Push)\n    next case CFG_IAdd with V_notin_Def show ?thesis by (fastforce intro: Def_IAdd)\n    next case CFG_CmpEq with V_notin_Def show ?thesis by (fastforce intro: Def_CmpEq)\n    next case CFG_New_Update with V_notin_Def show ?thesis\n        by (fastforce intro: Def_New_Heap Def_New_Stack)\n    next case CFG_New_Exceptional_prop with V_notin_Def show ?thesis\n        by (fastforce intro: Def_Exception)\n    next case CFG_New_Exceptional_handle with V_notin_Def show ?thesis\n        by (fastforce intro: Def_Exception Def_Exception_handle)\n    next case CFG_Getfield_Update with V_notin_Def show ?thesis\n        by (fastforce intro: Def_Getfield split: prod.split)\n    next case CFG_Getfield_Exceptional_prop with V_notin_Def show ?thesis\n        by (fastforce intro: Def_Exception)\n    next case CFG_Getfield_Exceptional_handle with V_notin_Def show ?thesis\n        by (fastforce intro: Def_Exception Def_Exception_handle)\n    next case CFG_Putfield_Update with V_notin_Def show ?thesis\n        by (fastforce intro: Def_Putfield split: prod.split)\n    next case CFG_Putfield_Exceptional_prop with V_notin_Def show ?thesis\n        by (fastforce intro: Def_Exception)\n    next case CFG_Putfield_Exceptional_handle with V_notin_Def show ?thesis\n        by (fastforce intro: Def_Exception Def_Exception_handle)\n    next case CFG_Checkcast_Exceptional_prop with V_notin_Def show ?thesis\n        by (fastforce intro: Def_Exception)\n    next case CFG_Checkcast_Exceptional_handle with V_notin_Def show ?thesis\n        by (fastforce intro: Def_Exception Def_Exception_handle)\n    next case CFG_Throw_prop with V_notin_Def show ?thesis by (fastforce intro: Def_Exception)\n    next case CFG_Throw_handle with V_notin_Def show ?thesis\n        by (fastforce intro: Def_Exception Def_Exception_handle)\n    next case CFG_Invoke_NP_prop with V_notin_Def show ?thesis by (fastforce intro: Def_Exception)\n    next case CFG_Invoke_NP_handle with V_notin_Def show ?thesis\n        by (fastforce intro: Def_Exception Def_Exception_handle)\n    next case CFG_Invoke_Return_Exceptional_handle with V_notin_Def show ?thesis\n        by (fastforce intro: Def_Exception_handle_return Def_Exception)\n    next case CFG_Return with V_notin_Def show ?thesis by (fastforce intro: Def_Return)\n    qed (simp_all add: intra_kind_def)\n  qed\nnext\n  fix a s s'\n  assume ve: \"valid_edge (P, C0, Main) a\"\n    and use_Eq: \"\\<forall>V\\<in>Use P (sourcenode a). JVMCFG_Interpret.state_val s V\n    = JVMCFG_Interpret.state_val s' V\"\n    and ik: \"intra_kind (kind a)\"\n    and pred_s: \"JVMCFG_Interpret.pred (kind a) s\"\n    and pred_s': \"JVMCFG_Interpret.pred (kind a) s'\"\n  then obtain cfs C M pc cs cfs' C' M' pc' cs' where [simp]: \"s = (cfs, (C, M, pc)) # cs\"\n    and [simp]: \"s' = (cfs', (C', M', pc')) # cs'\"\n    by (cases s, fastforce) (cases s', fastforce+)\n  from ve show \"\\<forall>V\\<in>Def P (sourcenode a).\n             JVMCFG_Interpret.state_val\n              (CFG.transfer (((ClassMain P, MethodMain P), [], []) # procs (PROG P)) (kind a) s) V =\n             JVMCFG_Interpret.state_val\n              (CFG.transfer (((ClassMain P, MethodMain P), [], []) # procs (PROG P)) (kind a) s') V\"\n    unfolding valid_edge_def\n  proof cases\n    case Main_Call with ik show ?thesis by (simp add: intra_kind_def)\n  next case Main_Return_to_Exit with use_Eq show ?thesis\n      by (fastforce elim: Def.cases intro: Use_Return_Heap Use_Return_Exception Use_Return_Stack)\n  next case Method_LFalse with use_Eq show ?thesis\n      by (fastforce elim: Def.cases intro: Use_Method_Entry_Heap Use_Method_Entry_Local) \n  next case Method_LTrue with use_Eq show ?thesis\n      by (fastforce elim: Def.cases intro: Use_Method_Entry_Heap Use_Method_Entry_Local)\n  next case CFG_Load with use_Eq show ?thesis\n      by (fastforce elim: Def.cases intro: Use_Enter_Local)\n  next case CFG_Store with use_Eq show ?thesis\n      by (fastforce elim: Def.cases intro: Use_Enter_Stack)\n  next case (CFG_IAdd C M pc)\n    hence \"Stack (stkLength (P, C, M) pc - 1) \\<in> Use P (sourcenode a)\"\n      and \"Stack (stkLength (P, C, M) pc - 2) \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Enter_Stack)+\n    with use_Eq CFG_IAdd show ?thesis by (auto elim!: Def.cases)\n  next case (CFG_CmpEq C  M pc)\n    hence \"Stack (stkLength (P, C, M) pc - 1) \\<in> Use P (sourcenode a)\"\n      and \"Stack (stkLength (P, C, M) pc - 2) \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Enter_Stack)+\n    with use_Eq CFG_CmpEq show ?thesis by (auto elim!: Def.cases)\n  next case CFG_New_Update\n    hence \"Heap \\<in> Use P (sourcenode a)\" by (fastforce intro: Use_Normal_Heap)\n    with use_Eq CFG_New_Update show ?thesis by (fastforce elim: Def.cases)\n  next case (CFG_Getfield_Update C  M pc)\n    hence \"Heap \\<in> Use P (sourcenode a)\"\n      and \"Stack (stkLength (P, C, M) pc - 1) \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Normal_Heap Use_Normal_Stack)+\n    with use_Eq CFG_Getfield_Update show ?thesis by (auto elim!: Def.cases split: prod.split)\n  next case (CFG_Putfield_Update C  M pc)\n    hence \"Heap \\<in> Use P (sourcenode a)\"\n      and \"Stack (stkLength (P, C, M) pc - 1) \\<in> Use P (sourcenode a)\"\n      and \"Stack (stkLength (P, C, M) pc - 2) \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Normal_Heap Use_Normal_Stack)+\n    with use_Eq CFG_Putfield_Update show ?thesis by (auto elim!: Def.cases split: prod.split)\n  next case (CFG_Throw_prop C  M pc)\n    hence \"Stack (stkLength (P, C, M) pc - 1) \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Exceptional_Stack)\n    with use_Eq CFG_Throw_prop show ?thesis by (fastforce elim: Def.cases)\n  next case (CFG_Throw_handle C  M pc)\n    hence \"Stack (stkLength (P, C, M) pc - 1) \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Exceptional_Stack)\n    with use_Eq CFG_Throw_handle show ?thesis by (fastforce elim: Def.cases)\n  next case CFG_Invoke_Call with ik show ?thesis by (simp add: intra_kind_def)\n  next case CFG_Invoke_Return_Check_Normal with use_Eq show ?thesis\n      by (fastforce elim: Def.cases intro: Use_Return_Heap Use_Return_Exception Use_Return_Stack)\n  next case CFG_Invoke_Return_Check_Exceptional with use_Eq show ?thesis\n      by (fastforce elim: Def.cases intro: Use_Return_Heap Use_Return_Exception Use_Return_Stack)\n  next case CFG_Invoke_Return_Exceptional_handle with use_Eq show ?thesis\n      by (fastforce elim: Def.cases intro: Use_Exceptional_Exception)\n  next case CFG_Invoke_Return_Exceptional_prop with use_Eq show ?thesis\n      by (fastforce elim: Def.cases intro: Use_Return_Heap Use_Return_Exception Use_Return_Stack)\n  next case CFG_Return with use_Eq show ?thesis\n      by (fastforce elim!: Def.cases intro: Use_Enter_Stack)\n  next case CFG_Return_from_Method with ik show ?thesis by (simp add: intra_kind_def)\n  qed (fastforce elim: Def.cases)+\nnext\n  fix a s s'\n  assume ve: \"valid_edge (P, C0, Main) a\"\n    and pred: \"JVMCFG_Interpret.pred (kind a) s\"\n    and \"snd (hd s) = snd (hd s')\"\n    and use_Eq: \"\\<forall>V\\<in>Use P (sourcenode a).\n           JVMCFG_Interpret.state_val s V = JVMCFG_Interpret.state_val s' V\"\n    and \"length s = length s'\"\n  then obtain cfs C M pc cs cfs' cs' where [simp]: \"s = (cfs, (C, M, pc)) # cs\"\n    and [simp]: \"s' = (cfs', (C, M, pc)) # cs'\" and length_cs: \"length cs = length cs'\"\n    by (cases s, fastforce) (cases s', fastforce+)\n  from ve pred show \"JVMCFG_Interpret.pred (kind a) s'\"\n    unfolding valid_edge_def\n  proof cases\n    case Main_Call_LFalse with pred show ?thesis by simp\n  next case Main_Call with pred use_Eq show ?thesis by simp\n  next case Method_LTrue with pred use_Eq show ?thesis by simp\n  next case CFG_Goto with pred use_Eq show ?thesis by simp\n  next case (CFG_IfFalse_False C  M pc)\n    hence \"Stack (stkLength (P, C, M) pc - 1) \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Enter_Stack)\n    with use_Eq CFG_IfFalse_False pred show ?thesis by fastforce\n  next case (CFG_IfFalse_True C  M pc)\n    hence \"Stack (stkLength (P, C, M) pc - 1) \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Enter_Stack)\n    with pred use_Eq CFG_IfFalse_True show ?thesis by fastforce\n  next case CFG_New_Check_Normal\n    hence \"Heap \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Enter_Heap)\n    with pred use_Eq CFG_New_Check_Normal show ?thesis by fastforce\n  next case CFG_New_Check_Exceptional \n    hence \"Heap \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Enter_Heap)\n    with pred use_Eq CFG_New_Check_Exceptional show ?thesis by fastforce\n  next case (CFG_Getfield_Check_Normal C  M pc)\n    hence \"Stack (stkLength (P, C, M) pc - 1) \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Enter_Stack)\n    with pred use_Eq CFG_Getfield_Check_Normal show ?thesis by fastforce\n  next case (CFG_Getfield_Check_Exceptional C  M pc)\n    hence \"Stack (stkLength (P, C, M) pc - 1) \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Enter_Stack)\n    with pred use_Eq CFG_Getfield_Check_Exceptional  show ?thesis by fastforce\n  next case (CFG_Putfield_Check_Normal C  M pc)\n    hence \"Stack (stkLength (P, C, M) pc - 2) \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Enter_Stack)\n    with pred use_Eq CFG_Putfield_Check_Normal show ?thesis by fastforce\n  next case (CFG_Putfield_Check_Exceptional C  M pc)\n    hence \"Stack (stkLength (P, C, M) pc - 2) \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Enter_Stack)\n    with pred use_Eq CFG_Putfield_Check_Exceptional show ?thesis by fastforce\n  next case (CFG_Checkcast_Check_Normal C  M pc)\n    hence \"Stack (stkLength (P, C, M) pc - 1) \\<in> Use P (sourcenode a)\"\n      and \"Heap \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Enter_Stack Use_Enter_Heap)+\n    with pred use_Eq CFG_Checkcast_Check_Normal show ?thesis by fastforce\n  next case (CFG_Checkcast_Check_Exceptional C  M pc)\n    hence \"Stack (stkLength (P, C, M) pc - 1) \\<in> Use P (sourcenode a)\"\n      and \"Heap \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Enter_Stack Use_Enter_Heap)+\n    with pred use_Eq CFG_Checkcast_Check_Exceptional show ?thesis by fastforce\n  next case (CFG_Throw_Check C  M pc)\n    hence \"Stack (stkLength (P, C, M) pc - 1) \\<in> Use P (sourcenode a)\"\n      and \"Heap \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Enter_Stack Use_Enter_Heap)+\n    with pred use_Eq CFG_Throw_Check show ?thesis by fastforce\n  next case (CFG_Invoke_Check_NP_Normal C  M pc M' n)\n    hence \"Stack (stkLength (P, C, M) pc - (Suc n)) \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Enter_Stack)\n    with pred use_Eq CFG_Invoke_Check_NP_Normal show ?thesis by fastforce\n  next case (CFG_Invoke_Check_NP_Exceptional C  M pc M' n)\n    hence \"Stack (stkLength (P, C, M) pc - (Suc n)) \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Enter_Stack)\n    with pred use_Eq CFG_Invoke_Check_NP_Exceptional show ?thesis by fastforce\n  next case (CFG_Invoke_Call C  M pc M' n)\n    hence \"Stack (stkLength (P, C, M) pc - (Suc n)) \\<in> Use P (sourcenode a)\"\n      and \"Heap \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Normal_Heap Use_Normal_Stack)+\n    with pred use_Eq CFG_Invoke_Call show ?thesis by fastforce\n  next case CFG_Invoke_Return_Check_Normal\n    hence \"Exception \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Return_Exception)\n    with pred use_Eq CFG_Invoke_Return_Check_Normal show ?thesis by fastforce\n  next case CFG_Invoke_Return_Check_Exceptional\n    hence \"Exception \\<in> Use P (sourcenode a)\" and \"Heap \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Return_Exception Use_Return_Heap)+\n    with pred use_Eq CFG_Invoke_Return_Check_Exceptional show ?thesis by fastforce\n  next case CFG_Invoke_Return_Exceptional_prop\n    hence \"Exception \\<in> Use P (sourcenode a)\" and \"Heap \\<in> Use P (sourcenode a)\"\n      by (fastforce intro: Use_Return_Exception Use_Return_Heap)+\n    with pred use_Eq CFG_Invoke_Return_Exceptional_prop show ?thesis by fastforce\n  next case CFG_Return_from_Method with pred length_cs show ?thesis by clarsimp\n  qed auto\nnext\n  fix a Q r p fs ins outs\n  assume \"valid_edge (P, C0, Main) a\"\n    and kind: \"kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\"\n    and params: \"(p, ins, outs) \\<in> set (((ClassMain P, MethodMain P), [], []) # procs (PROG P))\"\n  thus \"length fs = length ins\" unfolding valid_edge_def\n  proof cases\n    case (Main_Call  T mxs mxl0 \"is\" xt D)\n    with kind params have [simp]: \"p = (D, Main)\"\n      and \"PROG P \\<turnstile> D sees Main: []\\<rightarrow>T = (mxs, mxl0, is, xt) in D\"\n      and \"ins = Heap # map Local [0..<Suc 0]\"\n      by (auto elim!: in_set_procsE dest: sees_method_fun sees_method_idemp)\n    with Main_Call kind show ?thesis\n      by auto\n  next\n    case (CFG_Invoke_Call C  M pc M' n ST LT D' Ts T mxs mxl0 \"is\" xt D)\n    with kind params have [simp]: \"p = (D, M')\"\n      and \"PROG P \\<turnstile> D' sees M': Ts\\<rightarrow>T = (mxs, mxl0, is, xt) in D\"\n      and \"ins = Heap # map Local [0..<Suc (length Ts)]\"\n      by (auto elim!: in_set_procsE dest: sees_method_fun sees_method_idemp)\n    moreover with \\<open>(P, C0, Main) \\<turnstile> \\<Rightarrow>(C, M, \\<lfloor>pc\\<rfloor>, Normal)\\<close> \\<open>C \\<noteq> ClassMain P\\<close>\n      \\<open>instrs_of (PROG P) C M ! pc = Invoke M' n\\<close> \\<open>TYPING P C M ! pc = \\<lfloor>(ST, LT)\\<rfloor>\\<close>\n      \\<open>ST ! n = Class D'\\<close> have \"n = length Ts\"\n      by (fastforce dest!: reachable_node_impl_wt_instr dest: sees_method_fun list_all2_lengthD)\n    ultimately show ?thesis using CFG_Invoke_Call kind by auto\n  qed simp_all\nnext\n  fix a Q r p fs a' Q' r' p' fs' s s'\n  assume ve_a: \"valid_edge (P, C0, Main) a\"\n    and kind_a: \"kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\"\n    and ve_a': \"valid_edge (P, C0, Main) a'\"\n    and kind_a': \"kind a' = Q':r'\\<hookrightarrow>\\<^bsub>p'\\<^esub>fs'\"\n    and src: \"sourcenode a = sourcenode a'\"\n    and pred_s: \"JVMCFG_Interpret.pred (kind a) s\"\n    and pred_s': \"JVMCFG_Interpret.pred (kind a') s\"\n  then obtain cfs C M pc cs cfs' C' M' pc' cs' \n    where [simp]: \"s = (cfs, (C, M, pc)) # cs\" \n    by (cases s) fastforce+\n  with ve_a kind_a show \"a = a'\" unfolding valid_edge_def\n  proof cases\n    case Main_Call with ve_a' kind_a' src pred_s pred_s' show ?thesis unfolding valid_edge_def\n      by (cases a, cases a') (fastforce elim: JVMCFG.cases dest: sees_method_fun)\n  next\n    case CFG_Invoke_Call\n    note invoke_call1 = this\n    from ve_a' kind_a' show ?thesis unfolding valid_edge_def\n    proof cases\n      case Main_Call with CFG_Invoke_Call src have False by simp\n      thus ?thesis by simp\n    next\n      case CFG_Invoke_Call with src invoke_call1 show ?thesis\n        by clarsimp (cases a, cases a', fastforce dest: sees_method_fun)\n    qed simp_all\n  qed simp_all\nnext\n  fix a Q r p fs i ins outs s s'\n  assume ve: \"valid_edge (P, C0, Main) a\"\n    and kind: \"kind a = Q:r\\<hookrightarrow>\\<^bsub>p\\<^esub>fs\"\n    and \"i < length ins\"\n    and \"(p, ins, outs) \\<in> set (((ClassMain P, MethodMain P), [], []) # procs (PROG P))\"\n    and \"JVMCFG_Interpret.pred (kind a) s\"\n    and \"JVMCFG_Interpret.pred (kind a) s'\"\n    and use_Eq: \"\\<forall>V\\<in>ParamUses P (sourcenode a) ! i.\n           JVMCFG_Interpret.state_val s V = JVMCFG_Interpret.state_val s' V\"\n  then obtain cfs C M pc cs cfs' C' M' pc' cs' where [simp]: \"s = (cfs, (C, M, pc)) # cs\"\n    and [simp]: \"s' = (cfs', (C', M', pc')) # cs'\"\n    by (cases s, fastforce) (cases s', fastforce+)\n  from ve kind\n  show \"JVMCFG_Interpret.params fs (JVMCFG_Interpret.state_val s) ! i =\n          JVMCFG_Interpret.params fs (JVMCFG_Interpret.state_val s') ! i\"\n    unfolding valid_edge_def\n  proof cases\n    case Main_Call with kind use_Eq \\<open>i < length ins\\<close> show ?thesis\n      by (cases i) auto\n  next\n    case CFG_Invoke_Call\n    { fix P C M pc n st st' i\n      have \"\\<forall>V\\<in>rev (map (\\<lambda>n. {Stack (stkLength (P, C, M) pc - Suc n)}) [0..<n]) ! i. st V = st' V\n        \\<Longrightarrow> JVMCFG_Interpret.params\n        (rev (map (\\<lambda>i s. s (Stack (stkLength (P, C, M) pc - Suc i))) [0..<n])) st ! i =\n        JVMCFG_Interpret.params\n        (rev (map (\\<lambda>i s. s (Stack (stkLength (P, C, M) pc - Suc i))) [0..<n])) st' ! i\"\n        by (induct n arbitrary: i) (simp, case_tac i, auto)\n    }\n    note stack_params = this\n    from CFG_Invoke_Call kind use_Eq \\<open>i < length ins\\<close> show ?thesis\n      by (cases i, auto) (case_tac nat, auto intro: stack_params)\n  qed simp_all\nnext\n  fix a Q' p f' ins outs vmap vmap'\n  assume \"valid_edge (P, C0, Main) a\"\n    and \"kind a = Q'\\<hookleftarrow>\\<^bsub>p\\<^esub>f'\"\n    and \"(p, ins, outs) \\<in> set (((ClassMain P, MethodMain P), [], []) # procs (PROG P))\"\n  thus \"f' vmap vmap' = vmap'(ParamDefs P (targetnode a) [:=] map vmap outs)\"\n    unfolding valid_edge_def\n    by (cases, simp_all) (fastforce elim: in_set_procsE simp: fun_upd_twist)\nnext\n  fix a a'\n  { fix P n f n' e n''\n    assume \"P \\<turnstile> n -\\<Up>f\\<rightarrow> n'\" and \"P \\<turnstile> n -e\\<rightarrow> n''\"\n    hence \"e = \\<Up>f \\<and> n' = n''\"\n      by cases (simp_all, (fastforce elim: JVMCFG.cases)+)\n  }\n  note upd_det = this\n  { fix P n Q n' Q' n'' s\n    assume \"P \\<turnstile> n -(Q)\\<^sub>\\<surd>\\<rightarrow> n'\" and edge': \"P \\<turnstile> n -(Q')\\<^sub>\\<surd>\\<rightarrow> n''\" and trg: \"n' \\<noteq> n''\"\n    hence \"(Q s \\<longrightarrow> \\<not> Q' s) \\<and> (Q' s \\<longrightarrow> \\<not> Q s)\"\n    proof cases\n      case CFG_Throw_Check with edge' trg show ?thesis by cases fastforce+\n    qed (simp_all, (fastforce elim: JVMCFG.cases)+)\n  }\n  note pred_det = this\n  assume \"valid_edge (P, C0, Main) a\"\n    and ve': \"valid_edge (P, C0, Main) a'\"\n    and src: \"sourcenode a = sourcenode a'\"\n    and trg: \"targetnode a \\<noteq> targetnode a'\"\n    and \"intra_kind (kind a)\"\n    and \"intra_kind (kind a')\"\n  thus \"\\<exists>Q Q'. kind a = (Q)\\<^sub>\\<surd> \\<and> kind a' = (Q')\\<^sub>\\<surd> \\<and> (\\<forall>s. (Q s \\<longrightarrow> \\<not> Q' s) \\<and> (Q' s \\<longrightarrow> \\<not> Q s))\"\n    unfolding valid_edge_def intra_kind_def\n    by (auto dest: upd_det pred_det)\nqed\n\ninterpretation JVMCFGExit_wf :\n  CFGExit_wf \"sourcenode\" \"targetnode\" \"kind\" \"valid_edge (P, C0, Main)\"\n  \"(ClassMain P, MethodMain P, None, Enter)\"\n  \"(\\<lambda>(C, M, pc, type). (C, M))\" \"get_return_edges P\"\n  \"((ClassMain P, MethodMain P),[],[]) # procs (PROG P)\"\n  \"(ClassMain P, MethodMain P)\"\n  \"(ClassMain P, MethodMain P, None, Return)\"\n  \"Def P\" \"Use P\" \"ParamDefs P\" \"ParamUses P\"\nproof\n  show \"Def P (ClassMain P, MethodMain P, None, nodeType.Return) = {} \\<and>\n    Use P (ClassMain P, MethodMain P, None, nodeType.Return) = {}\"\n    by (fastforce elim: Def.cases Use.cases)\nqed\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/HRB-Slicing/JinjaVM_Inter/JVMCFG_wf.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331462646254, "lm_q2_score": 0.4263215925474903, "lm_q1q2_score": 0.2542723287636453}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: GPL-2.0-only\n *)\n\ntheory DomainSepInv\nimports\n  \"ArchIpc_AC\" (* for transfer_caps_loop_pres_dest lec_valid_cap' set_simple_ko_get_tcb thread_set_tcb_fault_update_valid_mdb *)\n  \"Monads.WPBang\"\nbegin\n\ntext \\<open>\n  We define and prove an invariant that is necessary to achieve domain\n  separation on seL4. In its strongest form, we require that all IRQs, other than\n  those for the timer, are inactive, and that no IRQControl or\n  IRQHandler caps are present (to prevent any inactive IRQs from becoming\n  active in the future).\n\n  It always requires that there are no domain caps.\n\\<close>\n\ntext \\<open>\n  When @{term irqs} is @{term False} we require that non-timer IRQs are off permanently.\n\\<close>\ndefinition domain_sep_inv :: \"bool \\<Rightarrow> 'a :: state_ext state \\<Rightarrow> 'b :: state_ext state \\<Rightarrow> bool\" where\n  \"domain_sep_inv irqs st s \\<equiv>\n    (\\<forall>slot. \\<not> cte_wp_at ((=) DomainCap) slot s) \\<and>\n    (irqs \\<or> (\\<forall>irq slot. \\<not> cte_wp_at ((=) IRQControlCap) slot s\n                      \\<and> \\<not> cte_wp_at ((=) (IRQHandlerCap irq)) slot s\n                      \\<and> interrupt_states s irq \\<noteq> IRQSignal\n                      \\<and> interrupt_states s irq \\<noteq> IRQReserved\n                      \\<and> interrupt_states s = interrupt_states st))\"\n\ndefinition domain_sep_inv_cap where\n  \"domain_sep_inv_cap irqs cap \\<equiv> case cap of\n     IRQControlCap \\<Rightarrow> irqs\n   | IRQHandlerCap irq \\<Rightarrow> irqs\n   | DomainCap \\<Rightarrow> False\n   | _ \\<Rightarrow> True\"\n\nlemma cte_wp_at_not_domain_sep_inv_cap:\n  \"cte_wp_at (not domain_sep_inv_cap irqs) slot s \\<longleftrightarrow>\n   ((irqs \\<longrightarrow> False) \\<and>\n    (\\<not> irqs \\<longrightarrow> (cte_wp_at ((=) IRQControlCap) slot s \\<or>\n                 (\\<exists> irq. cte_wp_at ((=) (IRQHandlerCap irq)) slot s)))) \\<or>\n   cte_wp_at ((=) DomainCap) slot s\"\n  apply (rule iffI)\n   apply (drule cte_wp_at_norm)\n   apply clarsimp\n   apply (case_tac c, simp_all add: domain_sep_inv_cap_def pred_neg_def)\n   apply (auto elim: cte_wp_at_weakenE split: if_splits)\n  done\n\nlemma domain_sep_inv_def2:\n  \"domain_sep_inv irqs st s =\n    ((\\<forall>slot. \\<not> cte_wp_at ((=) DomainCap) slot s) \\<and>\n     (irqs \\<or> (\\<forall>irq slot. \\<not> cte_wp_at ((=) IRQControlCap) slot s\n                       \\<and> \\<not> cte_wp_at ((=) (IRQHandlerCap irq)) slot s)) \\<and>\n     (irqs \\<or> (\\<forall>irq. interrupt_states s irq \\<noteq> IRQSignal\n                  \\<and> interrupt_states s irq \\<noteq> IRQReserved\n                  \\<and> interrupt_states s = interrupt_states st)))\"\n  by (fastforce simp: domain_sep_inv_def)\n\nlemma domain_sep_inv_wp:\n  assumes nctrl:\n    \"\\<And>slot. \\<lbrace>(\\<lambda>s. \\<not> cte_wp_at (not domain_sep_inv_cap irqs) slot s) and P\\<rbrace>\n             f\n             \\<lbrace>\\<lambda>_ s. \\<not> cte_wp_at (not domain_sep_inv_cap irqs) slot s\\<rbrace>\"\n  assumes irq_pres:\n    \"\\<And>P. \\<not> irqs \\<Longrightarrow> \\<lbrace>(\\<lambda>s. P (interrupt_states s)) and R\\<rbrace>\n                     f\n                     \\<lbrace>\\<lambda>_ s. P (interrupt_states s)\\<rbrace>\"\n  shows\n    \"\\<lbrace>domain_sep_inv irqs st and P and (\\<lambda>s. irqs \\<or> R s)\\<rbrace>\n     f\n     \\<lbrace>\\<lambda>_. domain_sep_inv irqs st\\<rbrace>\"\n  apply (clarsimp simp: domain_sep_inv_def2 valid_def)\n  apply (subst conj_assoc[symmetric])\n  apply (rule conjI)\n   apply (rule conjI)\n    apply (intro allI)\n    apply (erule use_valid[OF _ hoare_strengthen_post[OF nctrl]])\n     apply (fastforce simp: cte_wp_at_not_domain_sep_inv_cap)\n    apply (fastforce simp: cte_wp_at_not_domain_sep_inv_cap)\n   apply (fastforce elim!: use_valid[OF _ hoare_strengthen_post[OF nctrl]]\n                     simp: cte_wp_at_not_domain_sep_inv_cap)\n  apply (case_tac \"irqs\")\n   apply blast\n  apply (rule disjI2)\n  apply simp\n  apply (intro allI conjI)\n    apply (erule_tac P1=\"\\<lambda>x. x irq \\<noteq> IRQSignal\" in use_valid[OF _ irq_pres], assumption)\n    apply blast\n   apply (erule use_valid[OF _ irq_pres], assumption)\n   apply blast\n  apply (erule use_valid[OF _ irq_pres], assumption)\n  apply blast\n  done\n\nlemma domain_sep_inv_triv:\n  assumes cte_pres: \"\\<And>P slot. \\<lbrace>\\<lambda>s. \\<not> cte_wp_at P slot s\\<rbrace> f \\<lbrace>\\<lambda>_ s. \\<not> cte_wp_at P slot s\\<rbrace>\"\n  assumes irq_pres: \"\\<And>P. \\<lbrace>\\<lambda>s. P (interrupt_states s)\\<rbrace> f \\<lbrace>\\<lambda>_ s. P (interrupt_states s)\\<rbrace>\"\n  shows \"\\<lbrace>domain_sep_inv irqs st\\<rbrace> f \\<lbrace>\\<lambda>_. domain_sep_inv irqs st\\<rbrace>\"\n  apply (rule domain_sep_inv_wp[where P=\"\\<top>\" and R=\"\\<top>\", simplified])\n  apply (rule cte_pres, rule irq_pres)\n  done\n\nlemma domain_sep_inv_arch_state_update[simp]:\n  \"domain_sep_inv irqs st (s\\<lparr>arch_state := blah\\<rparr>) = domain_sep_inv irqs st s\"\n  by (simp add: domain_sep_inv_def)\n\nlemma domain_sep_inv_machine_state_update[simp]:\n  \"domain_sep_inv irqs st (s\\<lparr>machine_state := X\\<rparr>) = domain_sep_inv irqs st s\"\n  by (simp add: domain_sep_inv_def)\n\nlemma detype_interrupts_states[simp]:\n  \"interrupt_states (detype S s) = interrupt_states s\"\n  by (simp add: detype_def)\n\nlemma detype_domain_sep_inv[simp]:\n  \"domain_sep_inv irqs st s \\<longrightarrow> domain_sep_inv irqs st (detype S s)\"\n  by (fastforce simp: domain_sep_inv_def)\n\nlemma domain_sep_inv_detype_lift:\n  \"\\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>rv. domain_sep_inv irqs st\\<rbrace> \\<Longrightarrow>\n   \\<lbrace>P\\<rbrace> f \\<lbrace>\\<lambda>rv s. domain_sep_inv irqs st (detype S s)\\<rbrace>\"\n  by (strengthen detype_domain_sep_inv, assumption)\n\ncrunch domain_sep_inv[wp]: set_extra_badge \"domain_sep_inv irqs st\"\n\n(* FIXME: following 3 lemmas clagged from FinalCaps *)\nlemma set_cap_neg_cte_wp_at_other_helper':\n  \"\\<lbrakk> oslot \\<noteq> slot; ko_at (TCB x) (fst oslot) s;\n     tcb_cap_cases (snd oslot) = Some (ogetF, osetF, orestr);\n     kheap (s\\<lparr>kheap := kheap s(fst oslot \\<mapsto> TCB (osetF (\\<lambda> x. cap) x))\\<rparr>) (fst slot) = Some (TCB tcb);\n     tcb_cap_cases (snd slot) = Some (getF, setF, restr); P (getF tcb) \\<rbrakk>\n     \\<Longrightarrow> cte_wp_at P slot s\"\n  apply (case_tac \"fst oslot = fst slot\")\n   apply (rule cte_wp_at_tcbI)\n     apply (fastforce split: if_splits simp: obj_at_def)\n    apply assumption\n   apply (fastforce split: if_splits simp: tcb_cap_cases_def dest: prod_eqI)\n  apply (rule cte_wp_at_tcbI)\n    apply (fastforce split: if_splits simp: obj_at_def)\n   apply assumption\n  apply assumption\n  done\n\nlemma set_cap_neg_cte_wp_at_other_helper:\n  \"\\<lbrakk> \\<not> cte_wp_at P slot s; oslot \\<noteq> slot; ko_at (TCB x) (fst oslot) s;\n     tcb_cap_cases (snd oslot) = Some (getF, setF, restr) \\<rbrakk>\n     \\<Longrightarrow> \\<not> cte_wp_at P slot (s\\<lparr>kheap := kheap s(fst oslot \\<mapsto> TCB (setF (\\<lambda> x. cap) x))\\<rparr>)\"\n  apply (rule notI)\n  apply (erule cte_wp_atE)\n   apply (fastforce elim: notE intro: cte_wp_at_cteI split: if_splits)\n  apply (fastforce elim: notE intro: set_cap_neg_cte_wp_at_other_helper')\n  done\n\nlemma set_cap_neg_cte_wp_at_other:\n  \"oslot \\<noteq> slot \\<Longrightarrow> set_cap cap oslot \\<lbrace>\\<lambda>s. \\<not> cte_wp_at P slot s\\<rbrace>\"\n  unfolding set_cap_def\n  apply (wp set_object_wp get_object_wp | wpc | simp add: split_def)+\n  apply (intro allI impI conjI)\n       apply (rule notI)\n       apply (erule cte_wp_atE)\n        apply (fastforce split: if_splits dest: prod_eqI elim: notE intro: cte_wp_at_cteI simp: obj_at_def)\n       apply (fastforce split: if_splits elim: notE intro: cte_wp_at_tcbI)\n      apply (auto dest: set_cap_neg_cte_wp_at_other_helper)\n  done\n\nlemma set_cap_neg_cte_wp_at:\n  \"\\<lbrace>\\<lambda>s. \\<not> cte_wp_at P slot s \\<and> \\<not> P capa\\<rbrace>\n   set_cap capa slota\n   \\<lbrace>\\<lambda>_ s. \\<not> cte_wp_at P slot s\\<rbrace>\"\n  apply (case_tac \"slot = slota\")\n   apply simp\n   apply (simp add: set_cap_def set_object_def)\n   apply (rule hoare_pre)\n    apply (wp get_object_wp | wpc)+\n   apply (fastforce elim: cte_wp_atE intro: cte_wp_at_cteI cte_wp_at_tcbI)\n  apply (rule hoare_pre)\n   apply (rule set_cap_neg_cte_wp_at_other, simp+)\n  done\n\nlemma domain_sep_inv_cap_IRQControlCap:\n  \"\\<lbrakk> domain_sep_inv_cap irqs cap; \\<not> irqs \\<rbrakk> \\<Longrightarrow> cap \\<noteq> IRQControlCap\"\n  by (auto simp: domain_sep_inv_cap_def)\n\nlemma domain_sep_inv_cap_IRQHandlerCap:\n  \"\\<lbrakk> domain_sep_inv_cap irqs cap; \\<not> irqs \\<rbrakk> \\<Longrightarrow> cap \\<noteq> IRQHandlerCap irq\"\n  by (auto simp: domain_sep_inv_cap_def)\n\nlemma set_cap_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and K (domain_sep_inv_cap irqs cap)\\<rbrace>\n   set_cap cap slot\n   \\<lbrace>\\<lambda>_. domain_sep_inv irqs st\\<rbrace>\"\n  apply (rule hoare_gen_asm)\n  apply (rule hoare_pre)\n   apply (rule domain_sep_inv_wp)\n   apply (wp set_cap_neg_cte_wp_at | simp add: pred_neg_def | blast)+\n  done\n\nlemma cte_wp_at_domain_sep_inv_cap:\n  \"\\<lbrakk> domain_sep_inv irqs st s; cte_wp_at ((=) cap) slot s \\<rbrakk>\n     \\<Longrightarrow> domain_sep_inv_cap irqs cap\"\n  apply (case_tac slot)\n  apply (auto simp: domain_sep_inv_def domain_sep_inv_cap_def split: cap.splits)\n  done\n\nlemma weak_derived_irq_handler:\n  \"weak_derived (IRQHandlerCap irq) cap \\<Longrightarrow> cap = (IRQHandlerCap irq)\"\n  by (auto simp: weak_derived_def copy_of_def same_object_as_def split: cap.splits if_splits)\n\n(* FIXME: move to CSpace_AI *)\nlemma weak_derived_DomainCap:\n  \"weak_derived c' c \\<Longrightarrow> (c' = DomainCap) = (c = DomainCap)\"\n  apply (clarsimp simp: weak_derived_def)\n  apply (erule disjE)\n   apply (clarsimp simp: copy_of_def split: if_split_asm)\n   apply (auto simp: is_cap_simps same_object_as_def\n              split: cap.splits)[1]\n  apply simp\n  done\n\nlemma cte_wp_at_weak_derived_domain_sep_inv_cap:\n  \"\\<lbrakk> domain_sep_inv irqs st s; cte_wp_at (weak_derived cap) slot s \\<rbrakk>\n     \\<Longrightarrow> domain_sep_inv_cap irqs cap\"\n  apply (cases slot)\n  apply (force simp: domain_sep_inv_def domain_sep_inv_cap_def\n              split: cap.splits\n               dest: cte_wp_at_norm weak_derived_irq_handler weak_derived_DomainCap)\n  done\n\nlemma is_derived_IRQHandlerCap:\n  \"is_derived m src (IRQHandlerCap irq) cap \\<Longrightarrow> (cap = IRQHandlerCap irq)\"\n  apply (clarsimp simp: is_derived_def)\n  apply (case_tac cap, simp_all add: is_cap_simps cap_master_cap_def)\n  done\n\n(* FIXME: move to CSpace_AI *)\nlemma DomainCap_is_derived:\n  \"is_derived m src DomainCap cap \\<Longrightarrow> cap = DomainCap\"\n  by (auto simp: is_derived_def is_reply_cap_def is_master_reply_cap_def cap_master_cap_def\n          split: cap.splits)\n\nlemma cte_wp_at_is_derived_domain_sep_inv_cap:\n  \"\\<lbrakk> domain_sep_inv irqs st s; cte_wp_at (is_derived (cdt s) slot cap) slot s \\<rbrakk>\n     \\<Longrightarrow> domain_sep_inv_cap irqs cap\"\n  apply (cases slot)\n  apply (fastforce simp: domain_sep_inv_def domain_sep_inv_cap_def\n                  split: cap.splits\n                   dest: cte_wp_at_norm DomainCap_is_derived is_derived_IRQHandlerCap)\n  done\n\nlemma domain_sep_inv_exst_update[simp]:\n  \"domain_sep_inv irqs st (trans_state f s) = domain_sep_inv irqs st s\"\n  by (simp add: domain_sep_inv_def)\n\nlemma domain_sep_inv_is_original_cap_update[simp]:\n  \"domain_sep_inv irqs st (s\\<lparr>is_original_cap := X\\<rparr>) = domain_sep_inv irqs st s\"\n  by (simp add: domain_sep_inv_def)\n\nlemma domain_sep_inv_cdt_update[simp]:\n  \"domain_sep_inv irqs st (s\\<lparr>cdt := X\\<rparr>) = domain_sep_inv irqs st s\"\n  by (simp add: domain_sep_inv_def)\n\ncrunch domain_sep_inv[wp]: update_cdt \"domain_sep_inv irqs st\"\n\nlemma set_untyped_cap_as_full_domain_sep_inv[wp]:\n  \"set_untyped_cap_as_full a b c \\<lbrace>domain_sep_inv irqs st\\<rbrace>\"\n  apply (clarsimp simp: set_untyped_cap_as_full_def)\n  apply (rule hoare_pre)\n   apply (rule set_cap_domain_sep_inv)\n  apply (case_tac a, simp_all add: domain_sep_inv_cap_def)\n  done\n\nlemma cap_insert_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and (\\<lambda>s. cte_wp_at (is_derived (cdt s) slot cap) slot s)\\<rbrace>\n   cap_insert cap slot dest_slot\n   \\<lbrace>\\<lambda>_. domain_sep_inv irqs st \\<rbrace>\"\n  apply (simp add: cap_insert_def)\n  apply (wpsimp wp: set_cap_domain_sep_inv get_cap_wp set_original_wp dxo_wp_weak)\n  apply (blast dest: cte_wp_at_is_derived_domain_sep_inv_cap)\n  done\n\nlemma domain_sep_inv_cap_NullCap[simp]:\n  \"domain_sep_inv_cap irqs NullCap\"\n  by (simp add: domain_sep_inv_cap_def)\n\nlemma cap_move_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and (\\<lambda>s. cte_wp_at (weak_derived cap) slot s)\\<rbrace>\n   cap_move cap slot dest_slot\n   \\<lbrace>\\<lambda>_. domain_sep_inv irqs st \\<rbrace>\"\n  apply (simp add: cap_move_def)\n  apply (wpsimp wp: set_cap_domain_sep_inv get_cap_wp set_original_wp dxo_wp_weak)\n  apply (blast dest: cte_wp_at_weak_derived_domain_sep_inv_cap)\n  done\n\nlemma set_irq_state_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and (\\<lambda>s. stt = interrupt_states s irq)\\<rbrace>\n   set_irq_state stt irq\n   \\<lbrace>\\<lambda>_. domain_sep_inv irqs st\\<rbrace>\"\n  apply (simp add: set_irq_state_def)\n  apply (wp | simp add: do_machine_op_def | wpc)+\n  done\n\n\nlocale DomainSepInv_1 =\n  fixes state_ext_t :: \"'state_ext :: state_ext itself\"\n  assumes arch_finalise_cap_domain_sep_inv[wp]:\n    \"arch_finalise_cap c x \\<lbrace>\\<lambda>s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  and arch_post_cap_deletion_domain_sep_inv[wp]:\n    \"arch_post_cap_deletion acap \\<lbrace>\\<lambda>s :: det_ext state. domain_sep_inv irqs st s\\<rbrace>\"\n  and init_arch_objects_domain_sep_inv[wp]:\n    \"init_arch_objects typ ptr n sz refs \\<lbrace>\\<lambda>s :: det_ext state. domain_sep_inv irqs st s\\<rbrace>\"\n  and prepare_thread_delete_domain_sep_inv[wp]:\n    \"prepare_thread_delete t \\<lbrace>\\<lambda>s :: det_ext state. domain_sep_inv irqs st s\\<rbrace>\"\n  and arch_finalise_cap_rv:\n    \"\\<lbrace>\\<lambda>_. P (NullCap,NullCap)\\<rbrace> arch_finalise_cap c x \\<lbrace>\\<lambda>rv s :: det_ext state. P rv\\<rbrace>\"\nbegin\n\nlemma deleted_irq_handler_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and K irqs\\<rbrace>\n   deleted_irq_handler irq\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  apply (rule hoare_gen_asm)\n  apply (simp add: deleted_irq_handler_def set_irq_state_def)\n  apply wp\n  apply (simp add: domain_sep_inv_def)\n  done\n\nlemma empty_slot_domain_sep_inv:\n  \"\\<lbrace>\\<lambda>s. domain_sep_inv irqs st s \\<and> (\\<not> irqs \\<longrightarrow> b = NullCap)\\<rbrace>\n   empty_slot a b\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  unfolding empty_slot_def post_cap_deletion_def\n  by (wpsimp wp: get_cap_wp set_cap_domain_sep_inv set_original_wp dxo_wp_weak\n                 static_imp_wp deleted_irq_handler_domain_sep_inv)\n\nend\n\n\nlemma set_simple_ko_neg_cte_wp_at[wp]:\n  \"set_simple_ko f a b \\<lbrace>\\<lambda>s. \\<not> cte_wp_at P slot s\\<rbrace>\"\n  apply (simp add: set_simple_ko_def)\n  apply (wp set_object_wp_strong get_object_wp\n         | simp add: partial_inv_def a_type_def split: kernel_object.splits)+\n  apply (case_tac \"a = fst slot\")\n   apply (clarsimp split: kernel_object.splits)\n   apply (fastforce elim: cte_wp_atE simp: obj_at_def)\n  apply (fastforce elim: cte_wp_atE intro: cte_wp_at_cteI cte_wp_at_tcbI)\n  done\n\ncrunch domain_sep_inv[wp]: set_simple_ko \"domain_sep_inv irqs st\"\n  (wp: domain_sep_inv_triv)\n\nlemma set_thread_state_neg_cte_wp_at[wp]:\n  \"set_thread_state a b \\<lbrace>\\<lambda>s. \\<not> cte_wp_at P slot s\\<rbrace>\"\n  apply (simp add: set_thread_state_def)\n  apply (wp set_object_wp get_object_wp dxo_wp_weak| simp)+\n  apply (case_tac \"a = fst slot\")\n   apply (clarsimp split: kernel_object.splits)\n   apply (erule notE)\n   apply (erule cte_wp_atE)\n    apply (fastforce simp: obj_at_def)\n   apply (drule get_tcb_SomeD)\n   apply (rule cte_wp_at_tcbI)\n     apply simp\n    apply assumption\n   apply (fastforce simp: tcb_cap_cases_def split: if_splits)\n  apply (fastforce elim: cte_wp_atE intro: cte_wp_at_cteI cte_wp_at_tcbI)\n  done\n\nlemma set_bound_notification_neg_cte_wp_at[wp]:\n  \"set_bound_notification a b \\<lbrace>\\<lambda>s. \\<not> cte_wp_at P slot s\\<rbrace>\"\n  apply (simp add: set_bound_notification_def)\n  apply (wp set_object_wp get_object_wp dxo_wp_weak| simp)+\n  apply (case_tac \"a = fst slot\")\n   apply (clarsimp split: kernel_object.splits)\n   apply (erule notE)\n   apply (erule cte_wp_atE)\n    apply (fastforce simp: obj_at_def)\n   apply (drule get_tcb_SomeD)\n   apply (rule cte_wp_at_tcbI)\n     apply simp\n    apply assumption\n   apply (fastforce simp: tcb_cap_cases_def split: if_splits)\n  apply (fastforce elim: cte_wp_atE intro: cte_wp_at_cteI cte_wp_at_tcbI)\n  done\n\ncrunch domain_sep_inv[wp]: set_thread_state, set_bound_notification, get_bound_notification \"domain_sep_inv irqs st\"\n  (wp: domain_sep_inv_triv)\n\nlemma thread_set_tcb_fault_update_neg_cte_wp_at[wp]:\n  \"thread_set (tcb_fault_update blah) t \\<lbrace>\\<lambda>s. \\<not> cte_wp_at P slot s\\<rbrace>\"\n  apply (simp add: thread_set_def)\n  apply (wp set_object_wp get_object_wp | simp)+\n  apply (case_tac \"t = fst slot\")\n   apply (clarsimp split: kernel_object.splits)\n   apply (erule notE)\n   apply (erule cte_wp_atE)\n    apply (fastforce simp: obj_at_def)\n   apply (drule get_tcb_SomeD)\n   apply (rule cte_wp_at_tcbI)\n     apply simp\n    apply assumption\n   apply (fastforce simp: tcb_cap_cases_def split: if_splits)\n  apply (fastforce elim: cte_wp_atE intro: cte_wp_at_cteI cte_wp_at_tcbI)\n  done\n\nlemma thread_set_tcb_fault_update_domain_sep_inv[wp]:\n  \"thread_set (tcb_fault_update blah) t \\<lbrace>domain_sep_inv irqs st\\<rbrace>\"\n  by (wp domain_sep_inv_triv)\n\ncrunch domain_sep_inv[wp]: as_user \"domain_sep_inv irqs st\"\n  (wp: domain_sep_inv_triv)\n\nlemma get_cap_domain_sep_inv_cap:\n  \"\\<lbrace>domain_sep_inv irqs st\\<rbrace> get_cap cap \\<lbrace>\\<lambda>rv s. domain_sep_inv_cap irqs rv\\<rbrace>\"\n  by (wpsimp wp: get_cap_wp simp: cte_wp_at_domain_sep_inv_cap)\n\ncrunch domain_sep_inv[wp]: cap_swap_for_delete \"domain_sep_inv irqs st\"\n  (wp: get_cap_domain_sep_inv_cap dxo_wp_weak simp: crunch_simps ignore: cap_swap_ext)\n\nlemma preemption_point_domain_sep_inv[wp]:\n  \"preemption_point \\<lbrace>domain_sep_inv irqs st\\<rbrace>\"\n  by (wp preemption_point_inv | simp)+\n\n\ncontext DomainSepInv_1 begin\n\ncrunches cap_delete_one\n  for domain_sep_inv[wp]: \"\\<lambda>s. domain_sep_inv irqs  (st :: 'state_ext state) (s :: det_ext state)\"\n  (wp: mapM_x_wp' unless_wp dxo_wp_weak simp: crunch_simps)\n\nlemma reply_cancel_ipc_domain_sep_inv[wp]:\n  \"\\<lbrace>domain_sep_inv irqs st\\<rbrace>\n   reply_cancel_ipc t\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs  (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  apply (simp add: reply_cancel_ipc_def)\n  apply (wp select_wp)\n  apply (rule hoare_strengthen_post[OF thread_set_tcb_fault_update_domain_sep_inv])\n  apply auto\n  done\n\ncrunches finalise_cap\n  for domain_sep_inv[wp]: \"\\<lambda>s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\"\n  (wp: dxo_wp_weak)\n\nlemma finalise_cap_domain_sep_inv_cap:\n  \"\\<lbrace>\\<lambda>s. domain_sep_inv_cap irqs cap\\<rbrace>\n   finalise_cap cap b\n   \\<lbrace>\\<lambda>rv s :: det_ext state. domain_sep_inv_cap irqs (fst rv)\\<rbrace>\"\n  including no_pre\n  apply (case_tac cap)\n             apply (wp | simp add: o_def split del: if_split  split: cap.splits\n                       | fastforce split: if_splits simp: domain_sep_inv_cap_def)+\n    apply (rule hoare_pre, wp, fastforce)\n   apply (rule hoare_pre, simp, wp, fastforce simp: domain_sep_inv_cap_def)\n  apply (wpc | wp arch_finalise_cap_rv | simp)+\n  done\n\nlemma finalise_cap_returns_NullCap:\n  \"\\<lbrace>\\<lambda>s. domain_sep_inv_cap irqs cap\\<rbrace>\n   finalise_cap cap b\n   \\<lbrace>\\<lambda>rv s :: det_ext state. \\<not> irqs \\<longrightarrow> snd rv = NullCap\\<rbrace>\"\n  apply (case_tac cap)\n  by (wpsimp wp: arch_finalise_cap_rv simp: o_def domain_sep_inv_cap_def split_del: if_split)+\n\nlemma rec_del_domain_sep_inv':\n  notes drop_spec_valid[wp_split del] drop_spec_validE[wp_split del]\n         rec_del.simps[simp del]\n  shows\n  \"s \\<turnstile> \\<lbrace>domain_sep_inv irqs st\\<rbrace>\n       rec_del call\n       \\<lbrace>\\<lambda>rv s. (case call of (FinaliseSlotCall x y) \\<Rightarrow> (y \\<or> fst rv) \\<longrightarrow> \\<not> irqs \\<longrightarrow> snd rv = NullCap\n                                                | _ \\<Rightarrow> True) \\<and>\n               domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>,\n       \\<lbrace>\\<lambda>_. domain_sep_inv irqs st\\<rbrace>\"\n  proof (induct s arbitrary: rule: rec_del.induct, simp_all only: rec_del_fails hoare_fail_any)\n  case (1 slot exposed s) show ?case\n    apply (simp add: split_def rec_del.simps)\n    apply (wpsimp wp: empty_slot_domain_sep_inv\n                      drop_spec_validE[OF returnOk_wp]\n                      drop_spec_validE[OF liftE_wp])\n    apply (rule spec_strengthen_postE[OF \"1.hyps\"])\n    apply fastforce\n    done\n  next\n  case (2 slot exposed s) show ?case\n    apply (simp add: rec_del.simps split del: if_split)\n    apply (rule hoare_pre_spec_validE)\n     apply (wp drop_spec_validE[OF returnOk_wp] drop_spec_validE[OF liftE_wp] set_cap_domain_sep_inv\n            | simp add: split_def split del: if_split)+\n           apply (rule spec_strengthen_postE)\n            apply (rule \"2.hyps\", fastforce+)\n          apply (rule drop_spec_validE, (wp preemption_point_inv| simp)+)[1]\n         apply simp\n         apply (rule spec_strengthen_postE)\n          apply (rule \"2.hyps\", fastforce+)\n         apply (wp  finalise_cap_domain_sep_inv_cap get_cap_wp\n                   finalise_cap_returns_NullCap\n                   drop_spec_validE[OF liftE_wp] set_cap_domain_sep_inv\n               |simp split del: if_split\n               |wp (once) hoare_drop_imps)+\n    apply (blast dest: cte_wp_at_domain_sep_inv_cap)\n    done\n  next\n  case (3 ptr bits n slot s) show ?case\n    apply (simp add: rec_del.simps)\n    apply (wp drop_spec_validE[OF returnOk_wp] drop_spec_validE[OF liftE_wp])\n    apply (rule hoare_pre_spec_validE)\n    apply (wp drop_spec_validE[OF assertE_wp])\n    apply (fastforce)\n    done\n  next\n  case (4 ptr bits n slot s) show ?case\n    apply (simp add: rec_del.simps)\n    apply (wp drop_spec_validE[OF returnOk_wp] drop_spec_validE[OF liftE_wp] set_cap_domain_sep_inv\n              drop_spec_validE[OF assertE_wp] get_cap_wp | simp)+\n    apply (rule spec_strengthen_postE[OF \"4.hyps\"])\n     apply (simp add: returnOk_def return_def)\n    apply (clarsimp simp: domain_sep_inv_cap_def)\n    done\n  qed\n\nlemma rec_del_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st\\<rbrace>\n   rec_del call\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  apply (rule validE_valid)\n  apply (rule use_spec)\n  apply (rule spec_strengthen_postE[OF rec_del_domain_sep_inv'])\n  by fastforce\n\ncrunches cap_delete\n  for domain_sep_inv[wp]: \"\\<lambda>s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\"\n\nlemma cap_revoke_domain_sep_inv':\n  notes drop_spec_valid[wp_split del] drop_spec_validE[wp_split del]\n  shows\n  \"s \\<turnstile> \\<lbrace> domain_sep_inv irqs st\\<rbrace>\n   cap_revoke slot\n   \\<lbrace> \\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>, \\<lbrace> \\<lambda>_. domain_sep_inv irqs st\\<rbrace>\"\n  proof(induct rule: cap_revoke.induct[where ?a1.0=s])\n  case (1 slot s)\n  show ?case\n  apply (subst cap_revoke.simps)\n  apply (rule hoare_pre_spec_validE)\n   apply (wp \"1.hyps\")\n           apply (wp spec_valid_conj_liftE2 | simp)+\n           apply (wp drop_spec_validE[OF valid_validE[OF preemption_point_domain_sep_inv]]\n                    drop_spec_validE[OF valid_validE[OF cap_delete_domain_sep_inv]]\n                    drop_spec_validE[OF assertE_wp] drop_spec_validE[OF returnOk_wp]\n                    drop_spec_validE[OF liftE_wp] select_wp\n                | simp | wp (once) hoare_drop_imps)+\n  done\nqed\n\nlemmas cap_revoke_domain_sep_inv[wp] = use_spec(2)[OF cap_revoke_domain_sep_inv']\n\nend\n\n\nlemma cap_move_cte_wp_at_other:\n  \"\\<lbrace>cte_wp_at P slot and K (slot \\<noteq> dest_slot \\<and> slot \\<noteq> src_slot)\\<rbrace>\n   cap_move cap src_slot dest_slot\n   \\<lbrace>\\<lambda>_. cte_wp_at P slot\\<rbrace>\"\n  unfolding cap_move_def\n  by (wpsimp wp: set_cdt_cte_wp_at set_cap_cte_wp_at' dxo_wp_weak static_imp_wp set_original_wp)\n\nlemma cte_wp_at_weak_derived_ReplyCap:\n  \"cte_wp_at ((=) (ReplyCap x False R)) slot s\n   \\<Longrightarrow> cte_wp_at (weak_derived (ReplyCap x False R)) slot s\"\n  apply (erule cte_wp_atE)\n   apply (rule cte_wp_at_cteI)\n      apply assumption\n     apply assumption\n    apply assumption\n   apply simp\n  apply (rule cte_wp_at_tcbI)\n  apply auto\n  done\n\nlemma thread_set_tcb_registers_caps_merge_default_tcb_neg_cte_wp_at[wp]:\n  \"thread_set (tcb_registers_caps_merge default_tcb) word \\<lbrace>\\<lambda>s. \\<not> cte_wp_at P slot s\\<rbrace>\"\n  unfolding thread_set_def\n  apply (wp set_object_wp | simp)+\n  apply (case_tac \"word = fst slot\")\n   apply (clarsimp split: kernel_object.splits)\n   apply (erule notE)\n   apply (erule cte_wp_atE)\n    apply (fastforce simp: obj_at_def)\n   apply (drule get_tcb_SomeD)\n   apply (rule cte_wp_at_tcbI)\n     apply simp\n    apply assumption\n   apply (clarsimp simp: tcb_cap_cases_def tcb_registers_caps_merge_def split: if_splits)\n  apply (fastforce elim: cte_wp_atE intro: cte_wp_at_cteI cte_wp_at_tcbI)\n  done\n\nlemma thread_set_tcb_registers_caps_merge_default_tcb_domain_sep_inv[wp]:\n  \"thread_set (tcb_registers_caps_merge default_tcb) word \\<lbrace>domain_sep_inv irqs st\\<rbrace>\"\n  by (wp domain_sep_inv_triv)\n\nlemma cancel_badged_sends_domain_sep_inv[wp]:\n  \"cancel_badged_sends epptr badge \\<lbrace>domain_sep_inv irqs st\\<rbrace>\"\n  apply (simp add: cancel_badged_sends_def)\n  apply (wpsimp wp: dxo_wp_weak mapM_wp | simp add: filterM_mapM | wp (once) hoare_drop_imps)+\n  done\n\nlemma create_cap_domain_sep_inv[wp]:\n  \"create_cap tp sz p dev slot \\<lbrace>domain_sep_inv irqs st\\<rbrace>\"\n  apply (simp add: create_cap_def)\n  apply (rule hoare_pre)\n  apply (wp set_cap_domain_sep_inv dxo_wp_weak | wpc | simp)+\n  apply clarsimp\n  apply (case_tac tp, simp_all add: domain_sep_inv_cap_def)\n  done\n\nlemma retype_region_neg_cte_wp_at_not_domain_sep_inv_cap:\n  \"retype_region  base n sz ty dev \\<lbrace>\\<lambda>s. \\<not> cte_wp_at (not domain_sep_inv_cap irqs) slot s\\<rbrace>\"\n  apply (rule hoare_pre)\n   apply (simp only: retype_region_def retype_addrs_def foldr_upd_app_if fun_app_def K_bind_def)\n   apply (wp dxo_wp_weak | simp)+\n  apply clarsimp\n  apply (case_tac \"fst slot \\<in> (\\<lambda>p. ptr_add base (p * 2 ^ obj_bits_api ty sz)) ` {0..<n}\")\n   apply clarsimp\n   apply (erule cte_wp_atE)\n    apply (clarsimp simp: default_object_def empty_cnode_def\n                   split: apiobject_type.splits if_splits)\n   apply (clarsimp simp: default_object_def default_tcb_def tcb_cap_cases_def\n                  split: apiobject_type.splits if_splits)\n  apply (fastforce elim: cte_wp_atE intro: cte_wp_at_tcbI cte_wp_at_cteI)\n  done\n\nlemma retype_region_domain_sep_inv[wp]:\n  \"retype_region base n sz tp dev \\<lbrace>domain_sep_inv irqs st\\<rbrace>\"\n  apply (rule domain_sep_inv_wp[where P=\"\\<top>\" and R=\"\\<top>\", simplified])\n   apply (rule retype_region_neg_cte_wp_at_not_domain_sep_inv_cap)\n  apply wp\n  done\n\nlemma domain_sep_inv_cap_UntypedCap[simp]:\n  \"domain_sep_inv_cap irqs (UntypedCap dev base sz n)\"\n  by (simp add: domain_sep_inv_cap_def)\n\ncrunch domain_sep_inv[wp]: delete_objects \"domain_sep_inv irqs st\"\n  (wp: domain_sep_inv_detype_lift)\n\n\ncontext DomainSepInv_1 begin\n\ncrunches finalise_slot, invoke_untyped, send_signal\n  for domain_sep_inv[wp]: \"\\<lambda>s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\"\n  (wp: crunch_wps mapME_x_inv_wp simp: crunch_simps mapM_x_def_bak)\n\nlemma invoke_cnode_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and valid_cnode_inv ci\\<rbrace>\n   invoke_cnode ci\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  unfolding invoke_cnode_def\n  apply (case_tac ci)\n        apply (wp cap_insert_domain_sep_inv cap_move_domain_sep_inv | simp split del: if_split)+\n     apply (rule hoare_pre)\n      apply (wpsimp wp: cap_move_domain_sep_inv cap_move_cte_wp_at_other get_cap_wp,\n             blast dest: cte_wp_at_weak_derived_domain_sep_inv_cap)+\n   apply (wpsimp wp: cap_move_domain_sep_inv get_cap_wp)\n   apply (fastforce dest:  cte_wp_at_weak_derived_ReplyCap)\n  apply (wp | simp | wpc | rule hoare_pre)+\n  done\n\nend\n\n\nlemma perform_page_invocation_domain_sep_inv_get_cap_helper:\n  \"\\<lbrace>\\<top>\\<rbrace> get_cap blah \\<lbrace>\\<lambda>rv s. domain_sep_inv_cap irqs (ArchObjectCap (F rv))\\<rbrace>\"\n  apply (simp add: domain_sep_inv_cap_def)\n  apply (rule wp_post_taut)\n  done\n\nlemma set_object_tcb_context_update_neg_cte_wp_at:\n  \"\\<lbrace>\\<lambda>s. \\<not> cte_wp_at P slot s \\<and> obj_at ((=) (TCB tcb)) ptr s\\<rbrace>\n   set_object ptr (TCB (tcb\\<lparr>tcb_arch := arch_tcb_context_set X (arch_tcb tcb)\\<rparr>))\n   \\<lbrace>\\<lambda>_ s. \\<not> cte_wp_at P slot s\\<rbrace>\"\n  apply (wp set_object_wp)\n  apply clarsimp\n  apply (case_tac \"ptr = fst slot\")\n   apply (erule cte_wp_atE)\n    apply (fastforce simp: obj_at_def)\n   apply (erule notE)\n   apply (clarsimp simp: obj_at_def)\n   apply (rule cte_wp_at_tcbI)\n      apply simp\n     apply (fastforce)\n    apply (fastforce simp: tcb_cap_cases_def split: if_splits)\n  apply (fastforce elim: cte_wp_atE intro: cte_wp_at_cteI cte_wp_at_tcbI)\n  done\n\nlemma set_object_tcb_arch_update_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and obj_at ((=) (TCB tcb)) ptr\\<rbrace>\n   set_object ptr (TCB (tcb\\<lparr>tcb_arch := arch\\<rparr>))\n   \\<lbrace>\\<lambda>_. domain_sep_inv irqs st\\<rbrace>\"\n  apply (wp set_object_wp)\n  apply (simp add: domain_sep_inv_def fun_upd_def cte_wp_at_caps_of_state)\n  apply (fastforce simp: caps_of_state_after_update obj_at_def tcb_cap_cases_def)\n  done\n\nlemma dxo_domain_sep_inv[wp]:\n  \"do_extended_op eop \\<lbrace>domain_sep_inv irqs st\\<rbrace>\"\n  by (simp | wp dxo_wp_weak)+\n\ncrunch domain_sep_inv[wp]: copy_mrs, set_message_info, set_mrs \"domain_sep_inv irqs st\"\n  (wp: crunch_wps set_object_tcb_arch_update_domain_sep_inv simp: crunch_simps ignore: set_object)\n\nlemma cap_insert_domain_sep_inv':\n  \"\\<lbrace>domain_sep_inv irqs st and K (domain_sep_inv_cap irqs cap)\\<rbrace>\n   cap_insert cap slot dest_slot\n   \\<lbrace>\\<lambda>_. domain_sep_inv irqs st\\<rbrace>\"\n  apply (simp add: cap_insert_def)\n  apply (wp set_cap_domain_sep_inv get_cap_wp dxo_wp_weak | simp split del: if_split)+\n  done\n\nlemma domain_sep_inv_cap_max_free_index_update[simp]:\n  \"domain_sep_inv_cap irqs (max_free_index_update cap) =\n   domain_sep_inv_cap irqs cap\"\n  by (simp add: max_free_index_def free_index_update_def split: cap.splits)\n\nlemma domain_sep_inv_cap_ArchObjectCap[simp]:\n  \"domain_sep_inv_cap irqs (ArchObjectCap arch_cap)\"\n  by (simp add: domain_sep_inv_cap_def)\n\n\nlocale DomainSepInv_2 = DomainSepInv_1 state_ext_t\n  for state_ext_t :: \"'state_ext :: state_ext itself\" +\n  assumes arch_switch_to_thread_domain_sep_inv[wp]:\n    \"arch_switch_to_thread t \\<lbrace>\\<lambda>s :: det_ext state. domain_sep_inv irqs (st :: 'state_ext state) s\\<rbrace>\"\n  and arch_switch_to_idle_thread_domain_sep_inv[wp]:\n    \"arch_switch_to_idle_thread \\<lbrace>\\<lambda>s :: det_ext state. domain_sep_inv irqs st s\\<rbrace>\"\n  and arch_activate_idle_thread_domain_sep_inv[wp]:\n    \"arch_activate_idle_thread t \\<lbrace>\\<lambda>s :: det_ext state. domain_sep_inv irqs st s\\<rbrace>\"\n  and arch_mask_irq_signal_domain_sep_inv[wp]:\n    \"arch_mask_irq_signal irq \\<lbrace>\\<lambda>s :: det_ext state. domain_sep_inv irqs st s\\<rbrace>\"\n  and arch_derive_cap_domain_sep_inv[wp]:\n    \"\\<lbrace>\\<top>\\<rbrace> arch_derive_cap acap \\<lbrace>\\<lambda>rv s :: det_ext state. domain_sep_inv_cap irqs rv\\<rbrace>,-\"\n  and arch_post_modify_registers_domain_sep_inv[wp]:\n    \"arch_post_modify_registers cur x31 \\<lbrace>\\<lambda>s :: det_ext state. domain_sep_inv irqs st s\\<rbrace>\"\n  and arch_perform_invocation_domain_sep_inv[wp]:\n    \"\\<lbrace>domain_sep_inv irqs st and valid_arch_inv ai\\<rbrace>\n     arch_perform_invocation ai\n     \\<lbrace>\\<lambda>_ s :: det_ext state. domain_sep_inv irqs st s\\<rbrace>\"\n  and arch_invoke_irq_handler_domain_sep_inv[wp]:\n    \"arch_invoke_irq_handler ihi \\<lbrace>\\<lambda>s :: det_ext state. domain_sep_inv irqs st s\\<rbrace>\"\n  and arch_invoke_irq_control_domain_sep_inv:\n    \"\\<lbrace>domain_sep_inv irqs st and arch_irq_control_inv_valid ivk\\<rbrace>\n     arch_invoke_irq_control ivk\n     \\<lbrace>\\<lambda>_ s :: det_ext state. domain_sep_inv irqs st s\\<rbrace>\"\n  and handle_arch_fault_reply_domain_sep_inv[wp]:\n    \"handle_arch_fault_reply vmf thread x y \\<lbrace>\\<lambda>s :: det_ext state. domain_sep_inv irqs st s\\<rbrace>\"\n  and handle_hypervisor_fault_domain_sep_inv[wp]:\n    \"handle_hypervisor_fault t hf_t \\<lbrace>\\<lambda>s :: det_ext state. domain_sep_inv irqs st s\\<rbrace>\"\n  and handle_vm_fault_domain_sep_inv[wp]:\n    \"handle_vm_fault t vmf_t \\<lbrace>\\<lambda>s :: det_ext state. domain_sep_inv irqs st s\\<rbrace>\"\n  and handle_reserved_irq_domain_sep_inv[wp]:\n    \"handle_reserved_irq irq \\<lbrace>\\<lambda>s :: det_ext state. domain_sep_inv irqs st s\\<rbrace>\"\nbegin\n\n(* when i is AckIRQ the preconditions here contradict each other, which\n   is why this lemma is true *)\nlemma invoke_irq_handler_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and irq_handler_inv_valid i\\<rbrace>\n   invoke_irq_handler i\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  apply (case_tac i)\n    apply (wp cap_insert_domain_sep_inv' | simp)+\n   apply (rename_tac irq cap cslot_ptr s)\n   apply (case_tac cap, simp_all add: domain_sep_inv_cap_def)[1]\n  apply (wp | clarsimp)+\n  done\n\n(* similarly, the preconditions here tend to contradict one another *)\nlemma invoke_control_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and irq_control_inv_valid i\\<rbrace>\n    invoke_irq_control i\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  including no_pre\n  apply (case_tac i)\n   apply (case_tac irqs)\n    apply (wp cap_insert_domain_sep_inv' | simp )+\n    apply (simp add: set_irq_state_def, wp, simp)\n    apply (fastforce simp: domain_sep_inv_def domain_sep_inv_cap_def)\n   apply (fastforce simp: valid_def domain_sep_inv_def)\n  apply simp\n  apply (wp arch_invoke_irq_control_domain_sep_inv)\n  done\n\nlemma derive_cap_domain_sep_inv_cap:\n  \"\\<lbrace>\\<lambda>s. domain_sep_inv_cap irqs cap\\<rbrace>\n   derive_cap slot cap\n   \\<lbrace>\\<lambda>rv s :: det_ext state. domain_sep_inv_cap irqs rv\\<rbrace>,-\"\n  apply (simp add: derive_cap_def)\n  apply (rule hoare_pre)\n  apply (wp | wpc | simp add: )+\n  apply auto\n  done\n\nend\n\n\ncrunch domain_sep_inv[wp]: receive_signal, complete_signal \"domain_sep_inv irqs st\"\n\nlemma domain_sep_inv_cap_ReplyCap[simp]:\n  \"domain_sep_inv_cap irqs (ReplyCap param_a param_b param_c)\"\n  by (simp add: domain_sep_inv_cap_def)\n\nlemma setup_caller_cap_domain_sep_inv[wp]:\n  \"\\<lbrace>domain_sep_inv irqs st\\<rbrace>\n   setup_caller_cap a b c\n   \\<lbrace>\\<lambda>_. domain_sep_inv irqs st\\<rbrace>\"\n  apply (simp add: setup_caller_cap_def split del:if_split)\n  apply (wp cap_insert_domain_sep_inv' | simp)+\n  done\n\nlemma transfer_caps_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and valid_objs and valid_mdb\n        and (\\<lambda> s. (\\<forall>x\\<in>set caps.\n               s \\<turnstile> fst x) \\<and>\n              (\\<forall>x\\<in>set caps.\n               cte_wp_at\n                (\\<lambda>cp. fst x \\<noteq> NullCap \\<longrightarrow>\n                      cp = fst x)\n                (snd x) s \\<and>\n               real_cte_at (snd x) s))\\<rbrace>\n  transfer_caps mi caps endpoint receiver receive_buffer\n  \\<lbrace>\\<lambda>_. domain_sep_inv irqs st\\<rbrace>\"\n  unfolding transfer_caps_def\n  apply (wpsimp wp: transfer_caps_loop_pres_dest cap_insert_domain_sep_inv\n                    hoare_vcg_all_lift hoare_vcg_imp_lift)\n  apply (fastforce elim: cte_wp_at_weakenE)\n  done\n\n\ncontext DomainSepInv_2 begin\n\nlemma do_normal_transfer_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and valid_objs and valid_mdb\\<rbrace>\n   do_normal_transfer sender send_buffer ep badge grant receiver recv_buffer\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  unfolding do_normal_transfer_def\n  by (wp transfer_caps_domain_sep_inv hoare_vcg_ball_lift lec_valid_cap' | simp)+\n\ncrunches do_fault_transfer\n  for domain_sep_inv[wp]: \"\\<lambda>s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\"\n\nlemma do_ipc_transfer_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and valid_objs and valid_mdb\\<rbrace>\n   do_ipc_transfer sender ep badge grant receiver\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  unfolding do_ipc_transfer_def\n  apply (wp do_normal_transfer_domain_sep_inv hoare_vcg_all_lift | wpc | wp (once) hoare_drop_imps)+\n  apply clarsimp\n  done\n\nlemma send_ipc_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and valid_objs and valid_mdb and\n    sym_refs \\<circ> state_refs_of\\<rbrace>\n   send_ipc block call badge can_grant can_grant_reply thread epptr\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  unfolding send_ipc_def\n  apply (wp setup_caller_cap_domain_sep_inv hoare_vcg_if_lift | wpc | simp split del:if_split)+\n        apply (rule_tac Q=\"\\<lambda> r s. domain_sep_inv irqs st s\" in hoare_strengthen_post)\n         apply (wp do_ipc_transfer_domain_sep_inv dxo_wp_weak | wpc | simp)+\n     apply (wp (once) hoare_drop_imps)\n     apply (wp get_simple_ko_wp)+\n  apply clarsimp\n  apply (fastforce simp: valid_objs_def valid_obj_def obj_at_def ep_q_refs_of_def\n                         a_type_def ep_redux_simps neq_Nil_conv valid_ep_def\n                   elim: ep_queued_st_tcb_at split: list.splits)\n  done\n\nlemma receive_ipc_base_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and valid_objs and valid_mdb and\n    sym_refs \\<circ> state_refs_of and ko_at (Endpoint ep) epptr \\<rbrace>\n   receive_ipc_base aag receiver ep epptr rights is_blocking\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  apply (clarsimp cong: endpoint.case_cong thread_get_def get_thread_state_def)\n  apply (wp setup_caller_cap_domain_sep_inv dxo_wp_weak | wpc | simp split del: if_split)+\n        apply (rule_tac Q=\"\\<lambda> r s. domain_sep_inv irqs st s\" in hoare_strengthen_post)\n         apply (wp do_ipc_transfer_domain_sep_inv hoare_vcg_all_lift | wpc | simp)+\n     apply (wpsimp wp: hoare_vcg_imp_lift[OF set_simple_ko_get_tcb, unfolded disj_not1]\n                       hoare_vcg_all_lift get_simple_ko_wp\n                 simp: a_type_def do_nbrecv_failed_transfer_def)+\n  apply (fastforce simp: valid_objs_def valid_obj_def obj_at_def\n                         ep_redux_simps neq_Nil_conv valid_ep_def\n                  split: list.splits)\n  done\n\nlemma receive_ipc_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and valid_objs and valid_mdb and sym_refs \\<circ> state_refs_of\\<rbrace>\n   receive_ipc receiver cap is_blocking\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  unfolding receive_ipc_def\n  apply (simp add: receive_ipc_def split: cap.splits, clarsimp)\n  apply (rule hoare_seq_ext[OF _ get_simple_ko_sp])\n  apply (rule hoare_seq_ext[OF _ gbn_sp])\n  apply (case_tac ntfnptr, simp)\n   apply (wp receive_ipc_base_domain_sep_inv get_simple_ko_wp | simp split: if_split option.splits)+\n  done\n\nlemma send_fault_ipc_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and valid_objs and sym_refs \\<circ> state_refs_of\n                           and valid_mdb and K (valid_fault fault)\\<rbrace>\n   send_fault_ipc thread fault\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  unfolding send_fault_ipc_def\n  apply (rule hoare_gen_asm)+\n  apply (wp send_ipc_domain_sep_inv thread_set_valid_objs thread_set_tcb_fault_update_valid_mdb\n            thread_set_refs_trivial thread_set_obj_at_impossible hoare_vcg_ex_lift\n         | wpc | simp add: Let_def split_def lookup_cap_def valid_tcb_fault_update)+\n     apply (wpe get_cap_inv[where P=\"domain_sep_inv irqs st and valid_objs and valid_mdb\n                                                            and sym_refs o state_refs_of\"])\n     apply (wp | simp)+\n  done\n\ncrunches do_reply_transfer, handle_fault, reply_from_kernel, restart\n  for domain_sep_inv[wp]: \"\\<lambda>s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\"\n  (wp: handle_arch_fault_reply_domain_sep_inv dxo_wp_weak crunch_wps ignore: thread_set)\n\nend\n\ncrunch domain_sep_inv[wp]: setup_reply_master \"domain_sep_inv irqs st\"\n  (wp: crunch_wps simp: crunch_simps)\n\nlemma thread_set_tcb_ipc_buffer_update_neg_cte_wp_at[wp]:\n  \"thread_set (tcb_ipc_buffer_update f) t \\<lbrace>\\<lambda>s. \\<not> cte_wp_at P slot s\\<rbrace>\"\n  unfolding thread_set_def\n  apply (wp set_object_wp | simp)+\n  apply (case_tac \"t = fst slot\")\n   apply (clarsimp split: kernel_object.splits)\n   apply (erule notE)\n   apply (erule cte_wp_atE)\n    apply (fastforce simp: obj_at_def)\n   apply (drule get_tcb_SomeD)\n   apply (rule cte_wp_at_tcbI)\n     apply simp\n    apply assumption\n   apply (fastforce simp: tcb_cap_cases_def split: if_splits)\n  apply (fastforce elim: cte_wp_atE intro: cte_wp_at_cteI cte_wp_at_tcbI)\n  done\n\nlemma thread_set_tcb_ipc_buffer_update_domain_sep_inv[wp]:\n  \"thread_set (tcb_ipc_buffer_update f) t \\<lbrace>domain_sep_inv irqs st\\<rbrace>\"\n  by (rule domain_sep_inv_triv; wp)\n\nlemma thread_set_tcb_fault_handler_update_neg_cte_wp_at[wp]:\n  \"thread_set (tcb_fault_handler_update f) t \\<lbrace>\\<lambda>s. \\<not> cte_wp_at P slot s\\<rbrace>\"\n  unfolding thread_set_def\n  apply (wp set_object_wp | simp)+\n  apply (case_tac \"t = fst slot\")\n   apply (clarsimp split: kernel_object.splits)\n   apply (erule notE)\n   apply (erule cte_wp_atE)\n    apply (fastforce simp: obj_at_def)\n   apply (drule get_tcb_SomeD)\n   apply (rule cte_wp_at_tcbI)\n     apply simp\n    apply assumption\n   apply (fastforce simp: tcb_cap_cases_def split: if_splits)\n  apply (fastforce elim: cte_wp_atE intro: cte_wp_at_cteI cte_wp_at_tcbI)\n  done\n\nlemma thread_set_tcb_fault_handler_update_domain_sep_inv[wp]:\n  \"thread_set (tcb_fault_handler_update f) t \\<lbrace>domain_sep_inv irqs st\\<rbrace>\"\n  by (rule domain_sep_inv_triv; wp)\n\nlemma thread_set_tcb_tcb_mcpriority_update_neg_cte_wp_at[wp]:\n  \"thread_set (tcb_mcpriority_update f) t \\<lbrace>\\<lambda>s. \\<not> cte_wp_at P slot s\\<rbrace>\"\n  unfolding thread_set_def\n  apply (wp set_object_wp | simp)+\n  apply (case_tac \"t = fst slot\")\n   apply (clarsimp split: kernel_object.splits)\n   apply (erule notE)\n   apply (erule cte_wp_atE)\n    apply (fastforce simp: obj_at_def)\n   apply (drule get_tcb_SomeD)\n   apply (rule cte_wp_at_tcbI)\n     apply simp\n    apply assumption\n   apply (fastforce simp: tcb_cap_cases_def split: if_splits)\n  apply (fastforce elim: cte_wp_atE intro: cte_wp_at_cteI cte_wp_at_tcbI)\n  done\n\nlemma thread_set_tcb_tcp_mcpriority_update_domain_sep_inv[wp]:\n  \"thread_set (tcb_mcpriority_update f) t \\<lbrace>domain_sep_inv irqs st\\<rbrace>\"\n  by (rule domain_sep_inv_triv; wp)\n\nlemma same_object_as_domain_sep_inv_cap:\n  \"\\<lbrakk> same_object_as a cap; domain_sep_inv_cap irqs cap \\<rbrakk>\n     \\<Longrightarrow> domain_sep_inv_cap irqs a\"\n  apply (case_tac a, simp_all add: same_object_as_def domain_sep_inv_cap_def)\n  apply (case_tac cap, simp_all)\n  done\n\nlemma checked_cap_insert_domain_sep_inv:\n  \"check_cap_at a b (check_cap_at c d (cap_insert a b e)) \\<lbrace>domain_sep_inv irqs st\\<rbrace>\"\n  apply (wp get_cap_wp cap_insert_domain_sep_inv' | simp add: check_cap_at_def)+\n  apply clarsimp\n  apply (drule_tac cap=cap in cte_wp_at_domain_sep_inv_cap)\n   apply assumption\n  apply (erule (1) same_object_as_domain_sep_inv_cap)\n  done\n\ncrunch domain_sep_inv[wp]: bind_notification,reschedule_required \"domain_sep_inv irqs st\"\n\nlemma set_mcpriority_domain_sep_inv[wp]:\n  \"set_mcpriority tcb_ref mcp \\<lbrace>domain_sep_inv irqs st\\<rbrace>\"\n  unfolding set_mcpriority_def by wp\n\nlemma invoke_domain_domain_set_inv:\n  \"invoke_domain word1 word2 \\<lbrace>domain_sep_inv irqs st\\<rbrace>\"\n  apply (simp add: invoke_domain_def)\n  apply (wp dxo_wp_weak | simp)+\n  done\n\n\ncontext DomainSepInv_2 begin\n\nlemma invoke_tcb_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and tcb_inv_wf tinv\\<rbrace>\n   invoke_tcb tinv\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  apply (case_tac tinv)\n         apply ((wp restart_domain_sep_inv hoare_vcg_if_lift mapM_x_wp[OF _ subset_refl]\n                 | wpc | simp split del: if_split add: check_cap_at_def | clarsimp)+)[3]\n      defer\n      apply ((wp | simp)+)[2]\n    (* just NotificationControl and ThreadControl left *)\n    apply (rename_tac option)\n    apply (case_tac option)\n     apply  ((wp | simp)+)[1]\n    apply (simp add: split_def cong: option.case_cong)\n    apply (wp checked_cap_insert_domain_sep_inv hoare_vcg_all_lift_R hoare_vcg_all_lift\n              hoare_vcg_const_imp_lift_R cap_delete_domain_sep_inv cap_delete_deletes\n              dxo_wp_weak cap_delete_valid_cap cap_delete_cte_at static_imp_wp\n           | wpc | strengthen\n           | simp add: option_update_thread_def emptyable_def tcb_cap_cases_def\n                       tcb_cap_valid_def tcb_at_st_tcb_at\n                  del: set_priority_extended.dxo_eq)+\n  done\n\nlemma perform_invocation_domain_sep_inv':\n  \"\\<lbrace>domain_sep_inv irqs st and valid_invocation iv and valid_objs\n                           and valid_mdb and sym_refs \\<circ> state_refs_of\\<rbrace>\n   perform_invocation block call iv\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  apply (case_tac iv)\n           apply (wp send_ipc_domain_sep_inv invoke_tcb_domain_sep_inv\n                     invoke_cnode_domain_sep_inv invoke_control_domain_sep_inv\n                     invoke_irq_handler_domain_sep_inv arch_perform_invocation_domain_sep_inv\n                     invoke_domain_domain_set_inv\n                  | simp add: split_def | blast)+\n  done\n\nlemma perform_invocation_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and valid_invocation iv and invs\\<rbrace>\n   perform_invocation block call iv\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  apply (rule hoare_weaken_pre[OF perform_invocation_domain_sep_inv'])\n  apply auto\n  done\n\nlemma handle_invocation_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and invs and ct_active\\<rbrace>\n   handle_invocation calling blocking\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  apply (simp add: handle_invocation_def ts_Restart_case_helper\n                   split_def liftE_liftM_liftME liftME_def bindE_assoc)\n  apply (wp syscall_valid perform_invocation_domain_sep_inv set_thread_state_runnable_valid_sched\n         | simp split del: if_split)+\n        apply (rule_tac E=\"\\<lambda>ft. domain_sep_inv irqs st and valid_objs and sym_refs \\<circ> state_refs_of\n                                                       and valid_mdb and (\\<lambda>y. valid_fault ft)\"\n                    and R=\"Q\" and Q=Q for Q in hoare_post_impErr)\n         apply (wp | simp | clarsimp)+\n      apply (rule_tac E=\"\\<lambda>ft. domain_sep_inv irqs st and valid_objs and sym_refs \\<circ> state_refs_of and\n                              valid_mdb and (\\<lambda>y. valid_fault (CapFault x False ft))\"\n                  and R=\"Q\" and Q=Q for Q in hoare_post_impErr)\n        apply (wp lcs_ex_cap_to2 | clarsimp)+\n  apply (auto intro: st_tcb_ex_cap simp: ct_in_state_def)\n  done\n\nlemma handle_send_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and invs and ct_active\\<rbrace>\n   handle_send a\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  apply (simp add: handle_send_def)\n  apply (wp handle_invocation_domain_sep_inv)\n  done\n\nlemma handle_call_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and invs and ct_active\\<rbrace>\n   handle_call\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  apply (simp add: handle_call_def)\n  apply (wp handle_invocation_domain_sep_inv)\n  done\n\nlemma handle_reply_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and invs\\<rbrace>\n   handle_reply\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  apply (simp add: handle_reply_def)\n  apply (wp get_cap_wp | wpc)+\n  apply auto\n  done\n\ncrunches delete_caller_cap\n  for domain_sep_inv[wp]: \"\\<lambda>s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\"\n\nend\n\n\n(* FIXME: clagged from Syscall_AC *)\nlemma lookup_slot_for_thread_cap_fault:\n  \"\\<lbrace>invs\\<rbrace> lookup_slot_for_thread t s -, \\<lbrace>\\<lambda>f s. valid_fault (CapFault x y f)\\<rbrace>\"\n  apply (simp add: lookup_slot_for_thread_def)\n  apply (wp resolve_address_bits_valid_fault2)\n  apply clarsimp\n  apply (erule (1) invs_valid_tcb_ctable)\n  done\n\nlemma domain_sep_inv_cur_thread_update[simp]:\n  \"domain_sep_inv irqs st (s\\<lparr>cur_thread := X\\<rparr>) = domain_sep_inv irqs st s\"\n  apply (simp add: domain_sep_inv_def)\n  done\n\nlemma (in is_extended') domain_sep_inv[wp]: \"I (domain_sep_inv irqs st)\" by (rule lift_inv, simp)\n\n\ncontext DomainSepInv_2 begin\n\nlemma handle_recv_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and invs\\<rbrace>\n   handle_recv is_blocking\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  apply (simp add: handle_recv_def Let_def lookup_cap_def split_def)\n  apply (wp hoare_vcg_all_lift lookup_slot_for_thread_cap_fault receive_ipc_domain_sep_inv\n            delete_caller_cap_domain_sep_inv get_cap_wp get_simple_ko_wp\n         | wpc | simp\n         | (rule_tac Q=\"\\<lambda>rv. invs and (\\<lambda>s. cur_thread s = thread)\" in hoare_strengthen_post, wp,\n            clarsimp simp: invs_valid_objs invs_sym_refs))+\n     apply (rule_tac Q'=\"\\<lambda>r s. domain_sep_inv irqs st s \\<and> invs s \\<and>\n                               tcb_at thread s \\<and> thread = cur_thread s\" in hoare_post_imp_R)\n      apply wp\n     apply ((clarsimp simp add: invs_valid_objs invs_sym_refs\n             | intro impI allI conjI\n             | rule cte_wp_valid_cap caps_of_state_cteD\n             | fastforce simp:  valid_fault_def)+)[1]\n    apply (wp delete_caller_cap_domain_sep_inv | simp add: split_def cong: conj_cong)+\n    apply (wp | simp add: invs_valid_objs invs_mdb invs_sym_refs tcb_at_invs)+\n  done\n\ncrunches handle_interrupt, activate_thread, choose_thread\n  for domain_sep_inv[wp]: \"\\<lambda>s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\"\n  (wp: dxo_wp_weak crunch_wps)\n\nlemma handle_event_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and invs and (\\<lambda>s. ev \\<noteq> Interrupt \\<longrightarrow> ct_active s)\\<rbrace>\n   handle_event ev\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state)\\<rbrace>\"\n  apply (case_tac ev, simp_all)\n      apply (rule hoare_pre)\n       apply (wpsimp wp: handle_send_domain_sep_inv handle_call_domain_sep_inv\n                         handle_recv_domain_sep_inv handle_reply_domain_sep_inv hy_inv\n              | simp add: invs_valid_objs invs_mdb invs_sym_refs valid_fault_def)+\n     apply (rule_tac E=\"\\<lambda>rv s. domain_sep_inv irqs (st :: 'state_ext state) (s :: det_ext state) \\<and>\n                               invs s \\<and> valid_fault rv\" and R=\"Q\" and Q=Q for Q in hoare_post_impErr)\n     apply (wp | simp add: invs_valid_objs invs_mdb invs_sym_refs valid_fault_def | auto)+\n  done\n\nlemma schedule_domain_sep_inv:\n  \"(schedule :: (unit,det_ext) s_monad) \\<lbrace>domain_sep_inv irqs (st :: 'state_ext state)\\<rbrace>\"\n  apply (simp add: schedule_def allActiveTCBs_def)\n  apply (wp add: alternative_wp select_wp  guarded_switch_to_lift hoare_drop_imps\n            del: ethread_get_wp\n         | wpc | clarsimp simp: get_thread_state_def thread_get_def trans_state_update'[symmetric]\n                                schedule_choose_new_thread_def)+\n  done\n\nlemma call_kernel_domain_sep_inv:\n  \"\\<lbrace>domain_sep_inv irqs st and invs and (\\<lambda>s. ev \\<noteq> Interrupt \\<longrightarrow> ct_active s)\\<rbrace>\n   call_kernel ev :: (unit,det_ext) s_monad\n   \\<lbrace>\\<lambda>_ s. domain_sep_inv irqs (st :: 'state_ext state) s\\<rbrace>\"\n  apply (simp add: call_kernel_def)\n  apply (wp handle_interrupt_domain_sep_inv handle_event_domain_sep_inv schedule_domain_sep_inv\n         | simp)+\n  done\n\nend\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/proof/access-control/DomainSepInv.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5964331319177487, "lm_q2_score": 0.42632159254749036, "lm_q1q2_score": 0.254272322647262}}
{"text": "theory Discussion_NCPC\nimports \"../Observation_Setup\" Discussion_Value_Setup \"Bounded_Deducibility_Security.Compositional_Reasoning\"\nbegin\n\nsubsection \\<open>Confidentiality protection from non-PC-members\\<close>\n\ntext \\<open>We verify the following property:\n\n\\ \\\\\nA group of users UIDs learn\nnothing about the various updates of a paper's discussion\n(i.e., about the comments being posted on a paper by the PC members)\n(save for the non-existence of any edit)\nunless/until a user in UIDs becomes a PC member in the paper's conference having no conflict with that paper\nand the conference moves to the discussion phase.\n\n\\ \\\\\n\\<close>\n\nfun T :: \"(state,act,out) trans \\<Rightarrow> bool\" where\n\"T (Trans _ _ ou s') =\n (\\<exists> uid \\<in> UIDs. \\<exists> cid.\n    PID \\<in>\\<in> paperIDs s' cid \\<and> isPC s' cid uid \\<and> pref s' uid PID \\<noteq> Conflict \\<and> phase s' cid \\<ge> disPH\n )\"\n\ndeclare T.simps [simp del]\n\ndefinition B :: \"value list \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"B vl vl1 \\<equiv> vl \\<noteq> []\"\n\ninterpretation BD_Security_IO where\nistate = istate and step = step and\n\\<phi> = \\<phi> and f = f and \\<gamma> = \\<gamma> and g = g and T = T and B = B\ndone\n\nlemma reachNT_non_isPC_isChair:\nassumes \"reachNT s\" and \"uid \\<in> UIDs\"\nshows\n\"(PID \\<in>\\<in> paperIDs s cid \\<and> isPC s cid uid \\<and> phase s cid \\<ge> disPH \\<longrightarrow> pref s uid PID = Conflict) \\<and>\n (PID \\<in>\\<in> paperIDs s cid \\<and> isChair s cid uid \\<and> phase s cid \\<ge> disPH \\<longrightarrow> pref s uid PID = Conflict)\"\n  using assms\n  apply induct\n   apply (auto simp: istate_def)[]\n  apply(intro conjI)\n  subgoal for trn apply(cases trn, auto simp: T.simps reachNT_reach)[] .\n  by (metis T.elims(3) isChair_isPC reachNT_reach reach.Step tgtOf_simps)\n\n\nlemma T_\\<phi>_\\<gamma>:\nassumes 1: \"reachNT s\" and 2: \"step s a = (ou,s')\" \"\\<phi> (Trans s a ou s')\"\nshows \"\\<not> \\<gamma> (Trans s a ou s')\"\nusing reachNT_non_isPC_isChair[OF 1] 2 unfolding \\<phi>_def2\nby (fastforce simp add: uu_defs)\n\n(* major *) lemma eqExcPID_step_out:\nassumes s's1': \"eqExcPID s s1\"\nand step: \"step s a = (ou,s')\" and step1: \"step s1 a = (ou1,s1')\"\nand sT: \"reachNT s\" and s1: \"reach s1\"\nand PID: \"PID \\<in>\\<in> paperIDs s cid\"\nand UIDs: \"userOfA a \\<in> UIDs\"\nshows \"ou = ou1\"\nproof-\n  note Inv = reachNT_non_isPC_isChair[OF sT UIDs]\n  note eqs = eqExcPID_imp[OF s's1']\n  note eqs' = eqExcPID_imp1[OF s's1']\n  note s = reachNT_reach[OF sT]\n\n  note simps[simp] = c_defs u_defs uu_defs r_defs l_defs Paper_dest_conv eqExcPID_def eeqExcPID_def eqExcD\n  note * = step step1 eqs eqs' s s1 PID UIDs paperIDs_equals[OF s] Inv\n\n  show ?thesis\n  proof (cases a)\n    case (Cact x1)\n    then show ?thesis using * by (cases x1) auto\n  next\n    case (Uact x2)\n    then show ?thesis using * by (cases x2) auto\n  next\n    case (UUact x3)\n    then show ?thesis using * by (cases x3) auto\n  next\n    case (Ract x4)\n    show ?thesis\n    proof (cases x4)\n      case (rMyReview x81 x82 x83 x84)\n      then show ?thesis using * Ract by (auto simp add: getNthReview_def)\n    next\n      case (rReviews x91 x92 x93 x94)\n      then show ?thesis using * Ract by (clarsimp; metis eqExcPID_imp2 s's1')\n    next\n      case (rDis x111 x112 x113 x114)\n      then show ?thesis using * Ract by (clarsimp; metis discussion.inject)\n    qed (use * Ract in auto)\n  next\n    case (Lact x5)\n    then show ?thesis using * by (cases x5; auto; presburger)\n  qed\nqed\n\ndefinition \\<Delta>1 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>1 s vl s1 vl1 \\<equiv>\n (\\<forall> cid. PID \\<in>\\<in> paperIDs s cid \\<longrightarrow> phase s cid < disPH) \\<and> s = s1 \\<and> B vl vl1\"\n\n(* main difference from the Paper_Confidentiality/Aut_PC: need to assume\nthat there are means to produce vl1 via iaction when disPH has been reached;\nif not, this yields and exit *)\ndefinition \\<Delta>2 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>2 s vl s1 vl1 \\<equiv>\n \\<exists> cid uid.\n    PID \\<in>\\<in> paperIDs s cid \\<and> phase s cid = disPH \\<and>\n    isPC s cid uid \\<and> pref s uid PID \\<noteq> Conflict\n    \\<and> eqExcPID s s1\"\n\ndefinition \\<Delta>3 :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>3 s vl s1 vl1 \\<equiv>\n \\<exists> cid. PID \\<in>\\<in> paperIDs s cid \\<and> phase s cid > disPH \\<and> eqExcPID s s1 \\<and> vl1 = []\"\n\ndefinition \\<Delta>e :: \"state \\<Rightarrow> value list \\<Rightarrow> state \\<Rightarrow> value list \\<Rightarrow> bool\" where\n\"\\<Delta>e s vl s1 vl1 \\<equiv>\n vl \\<noteq> [] \\<and>\n (\\<exists> cid. PID \\<in>\\<in> paperIDs s cid \\<and> phase s cid \\<ge> disPH \\<and>\n         \\<not> (\\<exists> uid. isPC s cid uid \\<and> pref s uid PID \\<noteq> Conflict)\n )\"\n\nlemma init_\\<Delta>1:\nassumes B: \"B vl vl1\"\nshows \"\\<Delta>1 istate vl istate vl1\"\nusing B unfolding \\<Delta>1_def B_def istate_def by auto\n\nlemma unwind_cont_\\<Delta>1: \"unwind_cont \\<Delta>1 {\\<Delta>1,\\<Delta>2,\\<Delta>e}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>1 s vl s1 vl1 \\<or> \\<Delta>2 s vl s1 vl1 \\<or> \\<Delta>e s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \"\\<Delta>1 s vl s1 vl1\"\n  hence rs: \"reach s\" and ss1: \"s1 = s\" and vl: \"vl \\<noteq> []\"\n  and PID_ph: \"\\<And> cid. PID \\<in>\\<in> paperIDs s cid \\<Longrightarrow> phase s cid < disPH\"\n  using reachNT_reach unfolding \\<Delta>1_def B_def by auto\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof-\n    have ?react proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\"  let ?trn1 = \"Trans s1 a ou s'\"\n      assume step: \"step s a = (ou, s')\" and T: \"\\<not> T ?trn\" and c: \"consume ?trn vl vl'\"\n      have \\<phi>: \"\\<not> \\<phi> ?trn\"\n      proof (cases a)\n        case (UUact x3)\n        then show ?thesis\n          using step PID_ph\n          by (cases x3; fastforce simp: uu_defs)\n      qed auto\n      hence vl': \"vl' = vl\" using c unfolding consume_def by auto\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n      proof-\n        have ?match proof\n          show \"validTrans ?trn1\" unfolding ss1 using step by simp\n        next\n          show \"consume ?trn1 vl1 vl1\" unfolding consume_def ss1 using \\<phi> by auto\n        next\n          show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n        next\n          assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\" unfolding ss1 by simp\n        next\n          show \"?\\<Delta> s' vl' s' vl1\"\n          proof(cases \"\\<exists> cid. PID \\<in>\\<in> paperIDs s cid\")\n            case False note PID = False\n            have ph_PID': \"\\<And> cid. PID \\<in>\\<in> paperIDs s' cid \\<Longrightarrow> phase s' cid < disPH\" using PID step rs\n            subgoal apply(cases a)\n              subgoal for x1 apply(cases x1) apply(fastforce simp: c_defs)+ .\n              subgoal for x2 apply(cases x2) apply(fastforce simp: u_defs)+ .\n              subgoal for x3 apply(cases x3) apply(fastforce simp: uu_defs)+ .\n              by auto\n            done\n            hence \"\\<Delta>1 s' vl' s' vl1\" unfolding \\<Delta>1_def B_def vl' using ph_PID' vl by auto\n            thus ?thesis by auto\n          next\n            case True then obtain CID where PID: \"PID \\<in>\\<in> paperIDs s CID\" by auto\n            hence ph: \"phase s CID < disPH\" (is \"?ph < _\") using PID_ph by auto\n            show ?thesis\n            proof(cases \"phase s' CID < disPH\")\n              case True note ph' = True\n              show ?thesis proof(cases \"PID \\<in>\\<in> paperIDs s' CID\")\n                case False\n                hence \"\\<Delta>1 s' vl' s' vl1\" unfolding \\<Delta>1_def B_def vl' using vl ph' apply auto\n                by (metis PID paperIDs_mono step)(* safety crucially used *)\n                thus ?thesis by auto\n              next\n                case True\n                hence \"\\<Delta>1 s' vl' s' vl1\" unfolding \\<Delta>1_def B_def vl' using vl ph' apply auto\n                by (metis reach_PairI paperIDs_equals rs step) (* safety crucially used *)\n                thus ?thesis by auto\n              qed\n            next\n              case False\n              hence ph': \"phase s' CID = disPH \\<and> PID \\<in>\\<in> paperIDs s' CID\"\n              using PID ph step rs\n              subgoal apply(cases a)\n                subgoal for x1 apply(cases x1) apply(fastforce simp: c_defs)+ .\n                subgoal for x2 apply(cases x2) apply(fastforce simp: u_defs)+ .\n                subgoal for x3 apply(cases x3) apply(fastforce simp: uu_defs)+ .\n              by auto\n            done\n              show ?thesis\n              proof(cases \"\\<exists>uid. isPC s' CID uid \\<and> pref s' uid PID \\<noteq> Conflict\")\n                case True\n                hence \"\\<Delta>2 s' vl' s' vl1\" unfolding \\<Delta>2_def vl' using vl ph' by auto\n                thus ?thesis by auto\n              next\n                case False\n                hence \"\\<Delta>e s' vl' s' vl1\" unfolding \\<Delta>e_def vl' using vl ph' by auto\n                thus ?thesis by auto\n              qed\n            qed\n          qed\n        qed\n        thus ?thesis by simp\n      qed\n    qed\n    thus ?thesis using vl by auto\n  qed\nqed\n\nlemma unwind_cont_\\<Delta>2: \"unwind_cont \\<Delta>2 {\\<Delta>2,\\<Delta>3,\\<Delta>e}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>2 s vl s1 vl1 \\<or> \\<Delta>3 s vl s1 vl1 \\<or> \\<Delta>e s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \"\\<Delta>2 s vl s1 vl1\"\n  then obtain CID uid where uid: \"isPC s CID uid\" \"pref s uid PID \\<noteq> Conflict\"\n  and rs: \"reach s\" and ph: \"phase s CID = disPH\" (is \"?ph = _\")\n  and PID: \"PID \\<in>\\<in> paperIDs s CID\" and ss1: \"eqExcPID s s1\"\n  using reachNT_reach unfolding \\<Delta>2_def by auto\n  hence uid_notin: \"uid \\<notin> UIDs\" using ph reachNT_non_isPC_isChair[OF rsT] by force\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof(cases vl1)\n    case (Cons v1 vl1') note vl1 = Cons\n    have uid1: \"isPC s1 CID uid\" \"pref s1 uid PID \\<noteq> Conflict\"\n    using ss1 uid unfolding eqExcPID_def by auto\n    define a1 where \"a1 \\<equiv> UUact (uuDis CID uid (pass s uid) PID v1)\"\n    obtain s1' ou1 where step1: \"step s1 a1 = (ou1,s1')\" by (metis prod.exhaust)\n    let ?trn1 = \"Trans s1 a1 ou1 s1'\"\n    have s1s1': \"eqExcPID s1 s1'\" using a1_def step1 UUact_uuDis_step_eqExcPID by auto\n    have ss1': \"eqExcPID s s1'\" using eqExcPID_trans[OF ss1 s1s1'] .\n    hence many_s1': \"PID \\<in>\\<in> paperIDs s1' CID\" \"isPC s1' CID uid\"\n    \"pref s1' uid PID \\<noteq> Conflict\" \"phase s1' CID = disPH\"\n    \"pass s1' uid = pass s uid\"\n    using uid PID ph unfolding eqExcPID_def by auto\n    hence more_s1': \"uid \\<in>\\<in> userIDs s1'\" \"CID \\<in>\\<in> confIDs s1'\"\n    by (metis paperIDs_confIDs reach_PairI roles_userIDs rs1 step1 many_s1'(1))+\n    have f: \"f ?trn1 = v1\" unfolding a1_def by simp\n    have rs1': \"reach s1'\" using rs1 step1 by (auto intro: reach_PairI)\n    have ou1: \"ou1 = outOK\"\n    using step1 uid1 ph unfolding a1_def by (auto simp add: uu_defs many_s1' more_s1')\n    have ?iact proof\n      show \"step s1 a1 = (ou1,s1')\" by fact\n    next\n      show \\<phi>: \"\\<phi> ?trn1\" using ou1 unfolding a1_def by simp\n      thus \"consume ?trn1 vl1 vl1'\" using f unfolding consume_def vl1 by simp\n    next\n      show \"\\<not> \\<gamma> ?trn1\" by (simp add: a1_def uid_notin)\n    next\n      have \"\\<Delta>2 s vl s1' vl1'\" unfolding \\<Delta>2_def using ph PID ss1' uid by auto\n      thus \"?\\<Delta> s vl s1' vl1'\" by simp\n    qed\n    thus ?thesis by auto\n  next\n    case Nil note vl1 = Nil\n    have ?react proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\"\n      let ?ph' = \"phase s' CID\"\n      assume step: \"step s a = (ou, s')\" and T: \"\\<not> T ?trn\" and c: \"consume ?trn vl vl'\"\n      have PID': \"PID \\<in>\\<in> paperIDs s' CID\" using PID rs by (metis paperIDs_mono step)\n      have uid': \"isPC s' CID uid \\<and> pref s' uid PID \\<noteq> Conflict\"\n      using uid step rs ph PID pref_Conflict_disPH isPC_persistent by auto\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n      proof(cases \"\\<phi> ?trn\")\n        case False note \\<phi> = False\n        have vl: \"vl' = vl\" using c \\<phi> unfolding consume_def by (cases vl) auto\n        obtain ou1 and s1' where step1: \"step s1 a = (ou1,s1')\" by (metis prod.exhaust)\n        let ?trn1 = \"Trans s1 a ou1 s1'\"\n        have s's1': \"eqExcPID s' s1'\" using eqExcPID_step[OF ss1 step step1] .\n        have \\<phi>1: \"\\<not> \\<phi> ?trn1\" using \\<phi> unfolding eqExcPID_step_\\<phi>[OF ss1 step step1] .\n        have ?match proof\n          show \"validTrans ?trn1\" using step1 by simp\n        next\n          show \"consume ?trn1 vl1 vl1\" unfolding consume_def using \\<phi>1 by auto\n        next\n          show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n        next\n          assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\"\n          using eqExcPID_step_out[OF ss1 step step1 rsT rs1 PID] by simp\n        next\n          show \"?\\<Delta> s' vl' s1' vl1\"\n          proof(cases \"?ph' = disPH\")\n            case True\n            hence \"\\<Delta>2 s' vl' s1' vl1\" using PID' s's1' uid' unfolding \\<Delta>2_def by auto\n            thus ?thesis by auto\n          next\n            case False hence \"?ph' > disPH\"\n            using ph rs step by (metis le_less phase_increases)\n            hence \"\\<Delta>3 s' vl' s1' vl1\" using s's1' PID' unfolding \\<Delta>3_def vl1 by auto\n            thus ?thesis by auto\n          qed\n        qed\n        thus ?thesis by simp\n      next\n        case True note \\<phi> = True\n        have s's: \"eqExcPID s' s\" using eqExcPID_sym[OF \\<phi>_step_eqExcPID[OF \\<phi> step]] .\n        have s's1: \"eqExcPID s' s1\" using eqExcPID_trans[OF s's ss1] .\n        have ?ignore proof\n          show \"\\<not> \\<gamma> ?trn\" using T_\\<phi>_\\<gamma> \\<phi> rsT step by auto\n        next\n          show \"?\\<Delta> s' vl' s1 vl1\"\n          proof(cases \"?ph' = disPH\")\n            case True\n            hence \"\\<Delta>2 s' vl' s1 vl1\" using s's1 PID' uid' unfolding \\<Delta>2_def by auto\n            thus ?thesis by auto\n          next\n            case False hence \"?ph' > disPH\"\n            using ph rs step by (metis le_less phase_increases)\n            hence \"\\<Delta>3 s' vl' s1 vl1\" using s's1 PID' unfolding \\<Delta>3_def vl1 by auto\n            thus ?thesis by auto\n          qed\n        qed\n        thus ?thesis by auto\n      qed\n    qed\n    thus ?thesis using vl1 by auto\n  qed\nqed\n\nlemma unwind_cont_\\<Delta>3: \"unwind_cont \\<Delta>3 {\\<Delta>3,\\<Delta>e}\"\nproof(rule, simp)\n  let ?\\<Delta> = \"\\<lambda>s vl s1 vl1. \\<Delta>3 s vl s1 vl1 \\<or> \\<Delta>e s vl s1 vl1\"\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \"\\<Delta>3 s vl s1 vl1\"\n  then obtain CID where rs: \"reach s\" and ph: \"phase s CID > disPH\" (is \"?ph < _\")\n  and PID: \"PID \\<in>\\<in> paperIDs s CID\"\n  and ss1: \"eqExcPID s s1\" and vl1: \"vl1 = []\"\n  using reachNT_reach unfolding \\<Delta>3_def by auto\n  show \"iaction ?\\<Delta> s vl s1 vl1 \\<or>\n        ((vl = [] \\<longrightarrow> vl1 = []) \\<and> reaction ?\\<Delta> s vl s1 vl1)\" (is \"?iact \\<or> (_ \\<and> ?react)\")\n  proof-\n    have \"?react\"\n    proof\n      fix a :: act and ou :: out and s' :: state and vl'\n      let ?trn = \"Trans s a ou s'\"\n      let ?ph' = \"phase s' CID\"\n      assume step: \"step s a = (ou, s')\" and T: \"\\<not> T ?trn\" and c: \"consume ?trn vl vl'\"\n      have PID': \"PID \\<in>\\<in> paperIDs s' CID\" using PID rs by (metis paperIDs_mono step)\n      have ph': \"phase s' CID > disPH\" using ph rs by (meson less_le_trans local.step phase_increases)\n      show \"match ?\\<Delta> s s1 vl1 a ou s' vl' \\<or> ignore ?\\<Delta> s s1 vl1 a ou s' vl'\" (is \"?match \\<or> ?ignore\")\n      proof-\n        have \\<phi>: \"\\<not> \\<phi> ?trn\" using ph step unfolding \\<phi>_def2 apply (auto simp: uu_defs)\n        using PID less_not_refl2 paperIDs_equals rs by blast (* safety crucialy used *)\n        have vl: \"vl' = vl\" using c \\<phi> unfolding consume_def by (cases vl) auto\n        obtain ou1 and s1' where step1: \"step s1 a = (ou1,s1')\" by (metis prod.exhaust)\n        let ?trn1 = \"Trans s1 a ou1 s1'\"\n        have s's1': \"eqExcPID s' s1'\" using eqExcPID_step[OF ss1 step step1] .\n        have \\<phi>1: \"\\<not> \\<phi> ?trn1\" using \\<phi> unfolding eqExcPID_step_\\<phi>[OF ss1 step step1] .\n        have ?match proof\n          show \"validTrans ?trn1\" using step1 by simp\n        next\n          show \"consume ?trn1 vl1 vl1\" unfolding consume_def using \\<phi>1 by auto\n        next\n          show \"\\<gamma> ?trn = \\<gamma> ?trn1\" unfolding ss1 by simp\n        next\n          assume \"\\<gamma> ?trn\" thus \"g ?trn = g ?trn1\"\n          using eqExcPID_step_out[OF ss1 step step1 rsT rs1 PID] by simp\n        next\n          have \"\\<Delta>3 s' vl' s1' vl1\" using ph' PID' s's1' unfolding \\<Delta>3_def vl1 by auto\n          thus \"?\\<Delta> s' vl' s1' vl1\" by simp\n        qed\n        thus ?thesis by simp\n      qed\n    qed\n    thus ?thesis using vl1 by simp\n  qed\nqed\n\n(* Exit arguments: *)\ndefinition K1exit where\n\"K1exit cid s \\<equiv>\n (PID \\<in>\\<in> paperIDs s cid \\<and> phase s cid \\<ge> disPH \\<and>\n  \\<not> (\\<exists> uid. isPC s cid uid \\<and> pref s uid PID \\<noteq> Conflict))\"\n\nlemma invarNT_K1exit: \"invarNT (K1exit cid)\"\nunfolding invarNT_def apply (safe dest!: reachNT_reach)\n  subgoal for _ a apply(cases a)\n    subgoal for x1 apply(cases x1) apply (fastforce simp add: c_defs K1exit_def geq_noPH_confIDs)+ .\n    subgoal for x2\n      apply(cases x2)\n            apply (fastforce simp add: u_defs K1exit_def paperIDs_equals)\n           apply (fastforce simp add: u_defs K1exit_def paperIDs_equals)\n          apply (fastforce simp add: u_defs K1exit_def paperIDs_equals)\n         apply (fastforce simp add: u_defs K1exit_def paperIDs_equals)\n        apply (fastforce simp add: u_defs K1exit_def paperIDs_equals)\n        subgoal for x61 apply(cases \"x61 = cid\")\n           apply (fastforce simp add: u_defs K1exit_def paperIDs_equals)+ .\n        apply (fastforce simp add: u_defs K1exit_def paperIDs_equals) .\n    subgoal for x3 apply(cases x3) apply (fastforce simp add: uu_defs K1exit_def)+ .\n    by auto\n  done\n\nlemma noVal_K1exit: \"noVal (K1exit cid) v\"\napply(rule no\\<phi>_noVal)\nunfolding no\\<phi>_def apply safe\n  subgoal for _ a apply(cases a)\n        apply (fastforce simp add: c_defs K1exit_def)\n       apply (fastforce simp add: c_defs K1exit_def)\n    subgoal for x3\n      apply(cases x3) apply (auto simp add: uu_defs K1exit_def)\n      apply (metis paperIDs_equals reachNT_reach) (* crucial use of safety *) .\n    by auto\n  done\n\nlemma unwind_exit_\\<Delta>e: \"unwind_exit \\<Delta>e\"\nproof\n  fix s s1 :: state and vl vl1 :: \"value list\"\n  assume rsT: \"reachNT s\" and rs1: \"reach s1\" and \\<Delta>e: \"\\<Delta>e s vl s1 vl1\"\n  hence vl: \"vl \\<noteq> []\" using reachNT_reach unfolding \\<Delta>e_def by auto\n  then obtain CID where \"K1exit CID s\" using \\<Delta>e unfolding K1exit_def \\<Delta>e_def by auto\n  thus \"vl \\<noteq> [] \\<and> exit s (hd vl)\" apply(simp add: vl)\n  by (metis rsT exitI2 invarNT_K1exit noVal_K1exit)\nqed\n\ntheorem secure: secure\napply(rule unwind_decomp3_secure[of \\<Delta>1 \\<Delta>2 \\<Delta>e \\<Delta>3])\nusing\ninit_\\<Delta>1\nunwind_cont_\\<Delta>1 unwind_cont_\\<Delta>2 unwind_cont_\\<Delta>3\nunwind_exit_\\<Delta>e\nby auto\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/CoCon/Discussion_Confidentiality/Discussion_NCPC.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.25417942598742943}}
{"text": "(*  Title:      HOL/Auth/n_mutualEx_lemma_inv__3_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mutualEx Protocol Case Study*} \n\ntheory n_mutualEx_lemma_inv__3_on_rules imports n_mutualEx_lemma_on_inv__3\nbegin\nsection{*All lemmas on causal relation between inv__3*}\nlemma lemma_inv__3_on_rules:\n  assumes b1: \"r \\<in> rules N\" and b2: \"(\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__3  p__Inv0 p__Inv1)\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have c1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n  apply (cut_tac b1, auto) done\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_TryVsinv__3) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_CritVsinv__3) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_ExitVsinv__3) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_IdleVsinv__3) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "lyj238Gmail", "repo": "newParaVerifier", "sha": "5c2d49bf8e6c46c60efa53c98b0ba5c577d59618", "save_path": "github-repos/isabelle/lyj238Gmail-newParaVerifier", "path": "github-repos/isabelle/lyj238Gmail-newParaVerifier/newParaVerifier-5c2d49bf8e6c46c60efa53c98b0ba5c577d59618/examples/n_mutualEx/n_mutualEx_lemma_inv__3_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6859494421679929, "lm_q2_score": 0.37022540649291935, "lm_q1q2_score": 0.25395591106023646}}
{"text": "(*  Title:      HOL/Auth/n_mutualExOnI_lemma_inv__4_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mutualExOnI Protocol Case Study*} \n\ntheory n_mutualExOnI_lemma_inv__4_on_rules imports n_mutualExOnI_lemma_on_inv__4\nbegin\nsection{*All lemmas on causal relation between inv__4*}\nlemma lemma_inv__4_on_rules:\n  assumes b1: \"r \\<in> rules N\" and b2: \"(\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__4  p__Inv0 p__Inv1)\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have c1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n  apply (cut_tac b1, auto) done\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_TryVsinv__4) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_CritVsinv__4) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_ExitVsinv__4) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_IdleVsinv__4) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "lyj238Gmail", "repo": "newParaVerifier", "sha": "5c2d49bf8e6c46c60efa53c98b0ba5c577d59618", "save_path": "github-repos/isabelle/lyj238Gmail-newParaVerifier", "path": "github-repos/isabelle/lyj238Gmail-newParaVerifier/newParaVerifier-5c2d49bf8e6c46c60efa53c98b0ba5c577d59618/examples/n_mutualExOnI/n_mutualExOnI_lemma_inv__4_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6859494421679929, "lm_q2_score": 0.3702253925955866, "lm_q1q2_score": 0.2539559015273688}}
{"text": "(*  Title:      JinjaDCI/J/WellTypeRT.thy\n\n    Author:     Tobias Nipkow, Susannah Mansky\n    Copyright   2003 Technische Universitaet Muenchen, 2019-20 UIUC\n\n    Based on the Jinja theory J/WellTypeRT.thy by Tobias Nipkow\n*)\n\nsection \\<open> Runtime Well-typedness \\<close>\n\ntheory WellTypeRT\nimports WellType\nbegin\n\ninductive\n  WTrt :: \"J_prog \\<Rightarrow> heap \\<Rightarrow> sheap \\<Rightarrow> env \\<Rightarrow> expr \\<Rightarrow> ty \\<Rightarrow> bool\"\n  and WTrts :: \"J_prog \\<Rightarrow> heap \\<Rightarrow> sheap \\<Rightarrow> env \\<Rightarrow> expr list \\<Rightarrow> ty list \\<Rightarrow> bool\"\n  and WTrt2 :: \"[J_prog,env,heap,sheap,expr,ty] \\<Rightarrow> bool\"\n        (\"_,_,_,_ \\<turnstile> _ : _\"   [51,51,51,51]50)\n  and WTrts2 :: \"[J_prog,env,heap,sheap,expr list, ty list] \\<Rightarrow> bool\"\n        (\"_,_,_,_ \\<turnstile> _ [:] _\" [51,51,51,51]50)\n  for P :: J_prog and h :: heap and sh :: sheap\nwhere\n  \n  \"P,E,h,sh \\<turnstile> e : T \\<equiv> WTrt P h sh E e T\"\n| \"P,E,h,sh \\<turnstile> es[:]Ts \\<equiv> WTrts P h sh E es Ts\"\n\n| WTrtNew:\n  \"is_class P C  \\<Longrightarrow>\n  P,E,h,sh \\<turnstile> new C : Class C\"\n\n| WTrtCast:\n  \"\\<lbrakk> P,E,h,sh \\<turnstile> e : T; is_refT T; is_class P C \\<rbrakk>\n  \\<Longrightarrow> P,E,h,sh \\<turnstile> Cast C e : Class C\"\n\n| WTrtVal:\n  \"typeof\\<^bsub>h\\<^esub> v = Some T \\<Longrightarrow>\n  P,E,h,sh \\<turnstile> Val v : T\"\n\n| WTrtVar:\n  \"E V = Some T  \\<Longrightarrow>\n  P,E,h,sh \\<turnstile> Var V : T\"\n\n| WTrtBinOpEq:\n  \"\\<lbrakk> P,E,h,sh \\<turnstile> e\\<^sub>1 : T\\<^sub>1;  P,E,h,sh \\<turnstile> e\\<^sub>2 : T\\<^sub>2 \\<rbrakk>\n  \\<Longrightarrow> P,E,h,sh \\<turnstile> e\\<^sub>1 \\<guillemotleft>Eq\\<guillemotright> e\\<^sub>2 : Boolean\"\n\n| WTrtBinOpAdd:\n  \"\\<lbrakk> P,E,h,sh \\<turnstile> e\\<^sub>1 : Integer;  P,E,h,sh \\<turnstile> e\\<^sub>2 : Integer \\<rbrakk>\n  \\<Longrightarrow> P,E,h,sh \\<turnstile> e\\<^sub>1 \\<guillemotleft>Add\\<guillemotright> e\\<^sub>2 : Integer\"\n\n| WTrtLAss:\n  \"\\<lbrakk> E V = Some T;  P,E,h,sh \\<turnstile> e : T';  P \\<turnstile> T' \\<le> T \\<rbrakk>\n   \\<Longrightarrow> P,E,h,sh \\<turnstile> V:=e : Void\"\n\n| WTrtFAcc:\n  \"\\<lbrakk> P,E,h,sh \\<turnstile> e : Class C; P \\<turnstile> C has F,NonStatic:T in D \\<rbrakk> \\<Longrightarrow>\n  P,E,h,sh \\<turnstile> e\\<bullet>F{D} : T\"\n\n| WTrtFAccNT:\n  \"P,E,h,sh \\<turnstile> e : NT \\<Longrightarrow>\n  P,E,h,sh \\<turnstile> e\\<bullet>F{D} : T\"\n\n| WTrtSFAcc:\n  \"\\<lbrakk> P \\<turnstile> C has F,Static:T in D \\<rbrakk> \\<Longrightarrow>\n  P,E,h,sh \\<turnstile> C\\<bullet>\\<^sub>sF{D} : T\"\n\n| WTrtFAss:\n  \"\\<lbrakk> P,E,h,sh \\<turnstile> e\\<^sub>1 : Class C;  P \\<turnstile> C has F,NonStatic:T in D; P,E,h,sh \\<turnstile> e\\<^sub>2 : T\\<^sub>2;  P \\<turnstile> T\\<^sub>2 \\<le> T \\<rbrakk>\n  \\<Longrightarrow> P,E,h,sh \\<turnstile> e\\<^sub>1\\<bullet>F{D}:=e\\<^sub>2 : Void\"\n\n| WTrtFAssNT:\n  \"\\<lbrakk> P,E,h,sh \\<turnstile> e\\<^sub>1:NT; P,E,h,sh \\<turnstile> e\\<^sub>2 : T\\<^sub>2 \\<rbrakk>\n  \\<Longrightarrow> P,E,h,sh \\<turnstile> e\\<^sub>1\\<bullet>F{D}:=e\\<^sub>2 : Void\"\n\n| WTrtSFAss:\n  \"\\<lbrakk> P,E,h,sh \\<turnstile> e\\<^sub>2 : T\\<^sub>2; P \\<turnstile> C has F,Static:T in D; P \\<turnstile> T\\<^sub>2 \\<le> T \\<rbrakk>\n  \\<Longrightarrow> P,E,h,sh \\<turnstile> C\\<bullet>\\<^sub>sF{D}:=e\\<^sub>2 : Void\"\n\n| WTrtCall:\n  \"\\<lbrakk> P,E,h,sh \\<turnstile> e : Class C; P \\<turnstile> C sees M,NonStatic:Ts \\<rightarrow> T = (pns,body) in D;\n     P,E,h,sh \\<turnstile> es [:] Ts'; P \\<turnstile> Ts' [\\<le>] Ts \\<rbrakk>\n  \\<Longrightarrow> P,E,h,sh \\<turnstile> e\\<bullet>M(es) : T\"\n\n| WTrtCallNT:\n  \"\\<lbrakk> P,E,h,sh \\<turnstile> e : NT; P,E,h,sh \\<turnstile> es [:] Ts \\<rbrakk>\n  \\<Longrightarrow> P,E,h,sh \\<turnstile> e\\<bullet>M(es) : T\"\n\n| WTrtSCall:\n  \"\\<lbrakk> P \\<turnstile> C sees M,Static:Ts \\<rightarrow> T = (pns,body) in D;\n     P,E,h,sh \\<turnstile> es [:] Ts'; P \\<turnstile> Ts' [\\<le>] Ts;\n     M = clinit \\<longrightarrow> sh D = \\<lfloor>(sfs,Processing)\\<rfloor> \\<and> es = map Val vs \\<rbrakk>\n  \\<Longrightarrow> P,E,h,sh \\<turnstile> C\\<bullet>\\<^sub>sM(es) : T\"\n\n| WTrtBlock:\n  \"P,E(V\\<mapsto>T),h,sh \\<turnstile> e : T'  \\<Longrightarrow>\n  P,E,h,sh \\<turnstile> {V:T; e} : T'\"\n\n| WTrtSeq:\n  \"\\<lbrakk> P,E,h,sh \\<turnstile> e\\<^sub>1:T\\<^sub>1;  P,E,h,sh \\<turnstile> e\\<^sub>2:T\\<^sub>2 \\<rbrakk>\n  \\<Longrightarrow> P,E,h,sh \\<turnstile> e\\<^sub>1;;e\\<^sub>2 : T\\<^sub>2\"\n\n| WTrtCond:\n  \"\\<lbrakk> P,E,h,sh \\<turnstile> e : Boolean;  P,E,h,sh \\<turnstile> e\\<^sub>1:T\\<^sub>1;  P,E,h,sh \\<turnstile> e\\<^sub>2:T\\<^sub>2;\n     P \\<turnstile> T\\<^sub>1 \\<le> T\\<^sub>2 \\<or> P \\<turnstile> T\\<^sub>2 \\<le> T\\<^sub>1; P \\<turnstile> T\\<^sub>1 \\<le> T\\<^sub>2 \\<longrightarrow> T = T\\<^sub>2; P \\<turnstile> T\\<^sub>2 \\<le> T\\<^sub>1 \\<longrightarrow> T = T\\<^sub>1 \\<rbrakk>\n  \\<Longrightarrow> P,E,h,sh \\<turnstile> if (e) e\\<^sub>1 else e\\<^sub>2 : T\"\n\n| WTrtWhile:\n  \"\\<lbrakk> P,E,h,sh \\<turnstile> e : Boolean;  P,E,h,sh \\<turnstile> c:T \\<rbrakk>\n  \\<Longrightarrow>  P,E,h,sh \\<turnstile> while(e) c : Void\"\n\n| WTrtThrow:\n  \"\\<lbrakk> P,E,h,sh \\<turnstile> e : T\\<^sub>r; is_refT T\\<^sub>r \\<rbrakk> \\<Longrightarrow>\n  P,E,h,sh \\<turnstile> throw e : T\"\n\n| WTrtTry:\n  \"\\<lbrakk> P,E,h,sh \\<turnstile> e\\<^sub>1 : T\\<^sub>1;  P,E(V \\<mapsto> Class C),h,sh \\<turnstile> e\\<^sub>2 : T\\<^sub>2; P \\<turnstile> T\\<^sub>1 \\<le> T\\<^sub>2 \\<rbrakk>\n  \\<Longrightarrow> P,E,h,sh \\<turnstile> try e\\<^sub>1 catch(C V) e\\<^sub>2 : T\\<^sub>2\"\n\n| WTrtInit:\n  \"\\<lbrakk> P,E,h,sh \\<turnstile> e : T; \\<forall>C' \\<in> set (C#Cs). is_class P C'; \\<not>sub_RI e;\n     \\<forall>C' \\<in> set (tl Cs). \\<exists>sfs. sh C' = \\<lfloor>(sfs,Processing)\\<rfloor>;\n     b \\<longrightarrow> (\\<forall>C' \\<in> set Cs. \\<exists>sfs. sh C' = \\<lfloor>(sfs,Processing)\\<rfloor>);\n     distinct Cs; supercls_lst P Cs \\<rbrakk>\n  \\<Longrightarrow> P,E,h,sh \\<turnstile> INIT C (Cs, b) \\<leftarrow> e : T\"\n\n| WTrtRI:\n  \"\\<lbrakk> P,E,h,sh \\<turnstile> e : T; P,E,h,sh \\<turnstile> e' : T'; \\<forall>C' \\<in> set (C#Cs). is_class P C'; \\<not>sub_RI e';\n     \\<forall>C' \\<in> set (C#Cs). not_init C' e;\n     \\<forall>C' \\<in> set Cs. \\<exists>sfs. sh C' = \\<lfloor>(sfs,Processing)\\<rfloor>;\n     \\<exists>sfs. sh C = \\<lfloor>(sfs, Processing)\\<rfloor> \\<or> (sh C = \\<lfloor>(sfs, Error)\\<rfloor> \\<and> e = THROW NoClassDefFoundError);\n     distinct (C#Cs); supercls_lst P (C#Cs) \\<rbrakk>\n  \\<Longrightarrow> P,E,h,sh \\<turnstile> RI(C, e);Cs \\<leftarrow> e' : T'\"\n\n\\<comment> \\<open>well-typed expression lists\\<close>\n\n| WTrtNil:\n  \"P,E,h,sh \\<turnstile> [] [:] []\"\n\n| WTrtCons:\n  \"\\<lbrakk> P,E,h,sh \\<turnstile> e : T;  P,E,h,sh \\<turnstile> es [:] Ts \\<rbrakk>\n  \\<Longrightarrow>  P,E,h,sh \\<turnstile> e#es [:] T#Ts\"\n\n(*<*)\ndeclare WTrt_WTrts.intros[intro!] WTrtNil[iff]\ndeclare\n  WTrtFAcc[rule del] WTrtFAccNT[rule del] WTrtSFAcc[rule del]\n  WTrtFAss[rule del] WTrtFAssNT[rule del] WTrtSFAss[rule del]\n  WTrtCall[rule del] WTrtCallNT[rule del] WTrtSCall[rule del]\n\nlemmas WTrt_induct = WTrt_WTrts.induct [split_format (complete)]\n  and WTrt_inducts = WTrt_WTrts.inducts [split_format (complete)]\n(*>*)\n\n\nsubsection\\<open>Easy consequences\\<close>\n\n\n\nlemma [iff]: \"(P,E,h,sh \\<turnstile> e#es [:] T#Ts) = (P,E,h,sh \\<turnstile> e : T \\<and> P,E,h,sh \\<turnstile> es [:] Ts)\"\n(*<*)by(rule iffI) (auto elim: WTrts.cases)(*>*)\n\nlemma [iff]: \"(P,E,h,sh \\<turnstile> (e#es) [:] Ts) =\n  (\\<exists>U Us. Ts = U#Us \\<and> P,E,h,sh \\<turnstile> e : U \\<and> P,E,h,sh \\<turnstile> es [:] Us)\"\n(*<*)by(rule iffI) (auto elim: WTrts.cases)(*>*)\n\n\n\nlemma [iff]: \"P,E,h,sh \\<turnstile> Val v : T = (typeof\\<^bsub>h\\<^esub> v = Some T)\"\n(*<*)proof(rule iffI) qed (auto elim: WTrt.cases)(*>*)\n\nlemma [iff]: \"P,E,h,sh \\<turnstile> Var v : T = (E v = Some T)\"\n(*<*)proof(rule iffI) qed (auto elim: WTrt.cases)(*>*)\n\nlemma [iff]: \"P,E,h,sh \\<turnstile> e\\<^sub>1;;e\\<^sub>2 : T\\<^sub>2 = (\\<exists>T\\<^sub>1. P,E,h,sh \\<turnstile> e\\<^sub>1:T\\<^sub>1 \\<and> P,E,h,sh \\<turnstile> e\\<^sub>2:T\\<^sub>2)\"\n(*<*)proof(rule iffI) qed (auto elim: WTrt.cases)(*>*)\n\nlemma [iff]: \"P,E,h,sh \\<turnstile> {V:T; e} : T'  =  (P,E(V\\<mapsto>T),h,sh \\<turnstile> e : T')\"\n(*<*)proof(rule iffI) qed (auto elim: WTrt.cases)(*>*)\n\n(*<*)\ninductive_cases WTrt_elim_cases[elim!]:\n  \"P,E,h,sh \\<turnstile> v :=e : T\"\n  \"P,E,h,sh \\<turnstile> if (e) e\\<^sub>1 else e\\<^sub>2 : T\"\n  \"P,E,h,sh \\<turnstile> while(e) c : T\"\n  \"P,E,h,sh \\<turnstile> throw e : T\"\n  \"P,E,h,sh \\<turnstile> try e\\<^sub>1 catch(C V) e\\<^sub>2 : T\"\n  \"P,E,h,sh \\<turnstile> Cast D e : T\"\n  \"P,E,h,sh \\<turnstile> e\\<bullet>F{D} : T\"\n  \"P,E,h,sh \\<turnstile> C\\<bullet>\\<^sub>sF{D} : T\"\n  \"P,E,h,sh \\<turnstile> e\\<bullet>F{D} := v : T\"\n  \"P,E,h,sh \\<turnstile> C\\<bullet>\\<^sub>sF{D} := v : T\"\n  \"P,E,h,sh \\<turnstile> e\\<^sub>1 \\<guillemotleft>bop\\<guillemotright> e\\<^sub>2 : T\"\n  \"P,E,h,sh \\<turnstile> new C : T\"\n  \"P,E,h,sh \\<turnstile> e\\<bullet>M{D}(es) : T\"\n  \"P,E,h,sh \\<turnstile> C\\<bullet>\\<^sub>sM{D}(es) : T\"\n  \"P,E,h,sh \\<turnstile> INIT C (Cs,b) \\<leftarrow> e : T\"\n  \"P,E,h,sh \\<turnstile> RI(C,e);Cs \\<leftarrow> e' : T\"\n(*>*)\n\nsubsection\\<open>Some interesting lemmas\\<close>\n\nlemma WTrts_Val[simp]:\n \"\\<And>Ts. (P,E,h,sh \\<turnstile> map Val vs [:] Ts) = (map (typeof\\<^bsub>h\\<^esub>) vs = map Some Ts)\"\n(*<*)\nproof(induct vs)\n  case (Cons a vs)\n  then show ?case by(case_tac Ts; simp)\nqed simp\n(*>*)\n\n\n\n\n\nlemma WTrt_env_mono:\n  \"P,E,h,sh \\<turnstile> e : T \\<Longrightarrow> (\\<And>E'. E \\<subseteq>\\<^sub>m E' \\<Longrightarrow> P,E',h,sh \\<turnstile> e : T)\" and\n  \"P,E,h,sh \\<turnstile> es [:] Ts \\<Longrightarrow> (\\<And>E'. E \\<subseteq>\\<^sub>m E' \\<Longrightarrow> P,E',h,sh \\<turnstile> es [:] Ts)\"\n(*<*)\nproof(induct rule: WTrt_inducts)\n  case WTrtVar then show ?case by(simp add: map_le_def dom_def)\nnext\n  case WTrtLAss then show ?case by(force simp:map_le_def)\nqed(fastforce intro: WTrt_WTrts.intros)+\n(*>*)\n\n\nlemma WTrt_hext_mono: \"P,E,h,sh \\<turnstile> e : T \\<Longrightarrow> h \\<unlhd> h' \\<Longrightarrow> P,E,h',sh \\<turnstile> e : T\"\nand WTrts_hext_mono: \"P,E,h,sh \\<turnstile> es [:] Ts \\<Longrightarrow> h \\<unlhd> h' \\<Longrightarrow> P,E,h',sh \\<turnstile> es [:] Ts\"\n(*<*)\nproof(induct rule: WTrt_inducts)\n  case WTrtVal then show ?case by(simp add: hext_typeof_mono)\nqed(fastforce intro: WTrt_WTrts.intros)+\n(*>*)\n\nlemma WTrt_shext_mono: \"P,E,h,sh \\<turnstile> e : T \\<Longrightarrow> sh \\<unlhd>\\<^sub>s sh' \\<Longrightarrow> \\<not>sub_RI e \\<Longrightarrow> P,E,h,sh' \\<turnstile> e : T\"\nand WTrts_shext_mono: \"P,E,h,sh \\<turnstile> es [:] Ts \\<Longrightarrow> sh \\<unlhd>\\<^sub>s sh' \\<Longrightarrow> \\<not>sub_RIs es \\<Longrightarrow> P,E,h,sh' \\<turnstile> es [:] Ts\"\n(*<*)\nby(induct rule: WTrt_inducts)\n  (auto simp add: WTrt_WTrts.intros)\n(*>*)\n\nlemma WTrt_hext_shext_mono: \"P,E,h,sh \\<turnstile> e : T\n   \\<Longrightarrow> h \\<unlhd> h' \\<Longrightarrow> sh \\<unlhd>\\<^sub>s sh' \\<Longrightarrow> \\<not>sub_RI e \\<Longrightarrow> P,E,h',sh' \\<turnstile> e : T\"\n by(auto intro: WTrt_hext_mono WTrt_shext_mono)\n\nlemma WTrts_hext_shext_mono: \"P,E,h,sh \\<turnstile> es [:] Ts\n   \\<Longrightarrow> h \\<unlhd> h' \\<Longrightarrow> sh \\<unlhd>\\<^sub>s sh' \\<Longrightarrow> \\<not>sub_RIs es \\<Longrightarrow> P,E,h',sh' \\<turnstile> es [:] Ts\"\n by(auto intro: WTrts_hext_mono WTrts_shext_mono)\n\n\nlemma WT_implies_WTrt: \"P,E \\<turnstile> e :: T \\<Longrightarrow> P,E,h,sh \\<turnstile> e : T\"\nand WTs_implies_WTrts: \"P,E \\<turnstile> es [::] Ts \\<Longrightarrow> P,E,h,sh \\<turnstile> es [:] Ts\"\n(*<*)\nproof(induct rule: WT_WTs_inducts)\n  case WTVal then show ?case by(fastforce dest: typeof_lit_typeof)\nnext\n  case WTFAcc\n  then show ?case by(fastforce simp: WTrtFAcc has_visible_field)\nnext\n  case WTSFAcc\n  then show ?case by(fastforce simp: WTrtSFAcc has_visible_field)\nnext\n  case WTFAss\n  then show ?case by(fastforce simp: WTrtFAss dest: has_visible_field)\nnext\n  case WTSFAss\n  then show ?case by(fastforce simp: WTrtSFAss dest: has_visible_field)\nqed(fastforce intro: WTrt_WTrts.intros)+\n(*>*)\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/JinjaDCI/J/WellTypeRT.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5851011542032312, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.25392305595957}}
{"text": "theory IICF_MS_Array_List\nimports \n  \"../Intf/IICF_List\" \n  Separation_Logic_Imperative_HOL.Array_Blit\n  Separation_Logic_Imperative_HOL.Default_Insts\nbegin\n\n  type_synonym 'a ms_array_list = \"'a Heap.array \\<times> nat\"\n\n  definition \"is_ms_array_list ms l \\<equiv> \\<lambda>(a,n). \\<exists>\\<^sub>Al'. a \\<mapsto>\\<^sub>a l' * \\<up>(n \\<le> length l' \\<and> l = take n l' \\<and> ms=length l')\"\n\n  lemma is_ms_array_list_prec[safe_constraint_rules]: \"precise (is_ms_array_list ms)\"\n    unfolding is_ms_array_list_def[abs_def]\n    apply(rule preciseI)\n    apply(simp split: prod.splits) \n  \tusing preciseD snga_prec by fastforce\n\n  definition \"marl_empty_sz maxsize \\<equiv> do {\n    a \\<leftarrow> Array.new maxsize default;\n    return (a,0)\n  }\"\n\n  definition \"marl_append \\<equiv> \\<lambda>(a,n) x. do {\n      a \\<leftarrow> Array.upd n x a;\n      return (a,n+1)\n  }\"\n\n  definition marl_length :: \"'a::heap ms_array_list \\<Rightarrow> nat Heap\" where\n    \"marl_length \\<equiv> \\<lambda>(a,n). return (n)\"\n\n  definition marl_is_empty :: \"'a::heap ms_array_list \\<Rightarrow> bool Heap\" where\n    \"marl_is_empty \\<equiv> \\<lambda>(a,n). return (n=0)\"\n\n  definition marl_last :: \"'a::heap ms_array_list \\<Rightarrow> 'a Heap\" where\n    \"marl_last \\<equiv> \\<lambda>(a,n). do {\n      Array.nth a (n - 1)\n    }\"\n\n  definition marl_butlast :: \"'a::heap ms_array_list \\<Rightarrow> 'a ms_array_list Heap\" where\n    \"marl_butlast \\<equiv> \\<lambda>(a,n). do {\n      return (a,n - 1)\n    }\"\n\n  definition marl_get :: \"'a::heap ms_array_list \\<Rightarrow> nat \\<Rightarrow> 'a Heap\" where\n    \"marl_get \\<equiv> \\<lambda>(a,n) i. Array.nth a i\"\n\n  definition marl_set :: \"'a::heap ms_array_list \\<Rightarrow> nat \\<Rightarrow> 'a \\<Rightarrow> 'a ms_array_list Heap\" where\n    \"marl_set \\<equiv> \\<lambda>(a,n) i x. do { a \\<leftarrow> Array.upd i x a; return (a,n)}\"\n\n  lemma marl_empty_sz_rule[sep_heap_rules]: \"< emp > marl_empty_sz N <is_ms_array_list N []>\"\n    by (sep_auto simp: marl_empty_sz_def is_ms_array_list_def)\n\n  lemma marl_append_rule[sep_heap_rules]: \"length l < N \\<Longrightarrow>\n    < is_ms_array_list N l a > \n      marl_append a x \n    <\\<lambda>a. is_ms_array_list N (l@[x]) a >\\<^sub>t\"  \n    by (sep_auto \n      simp: marl_append_def is_ms_array_list_def take_update_last \n      split: prod.splits)\n    \n  lemma marl_length_rule[sep_heap_rules]: \"\n    <is_ms_array_list N l a> \n      marl_length a\n    <\\<lambda>r. is_ms_array_list N l a * \\<up>(r=length l)>\"\n    by (sep_auto simp: marl_length_def is_ms_array_list_def)\n    \n  lemma marl_is_empty_rule[sep_heap_rules]: \"\n    <is_ms_array_list N l a> \n      marl_is_empty a\n    <\\<lambda>r. is_ms_array_list N l a * \\<up>(r\\<longleftrightarrow>(l=[]))>\"\n    by (sep_auto simp: marl_is_empty_def is_ms_array_list_def)\n\n  lemma marl_last_rule[sep_heap_rules]: \"\n    l\\<noteq>[] \\<Longrightarrow>\n    <is_ms_array_list N l a> \n      marl_last a\n    <\\<lambda>r. is_ms_array_list N l a * \\<up>(r=last l)>\"\n    by (sep_auto simp: marl_last_def is_ms_array_list_def last_take_nth_conv)\n    \n  lemma marl_butlast_rule[sep_heap_rules]: \"\n    l\\<noteq>[] \\<Longrightarrow>\n    <is_ms_array_list N l a> \n      marl_butlast a\n    <is_ms_array_list N (butlast l)>\\<^sub>t\"\n    by (sep_auto \n      split: prod.splits\n      simp: marl_butlast_def is_ms_array_list_def butlast_take)\n\n  lemma marl_get_rule[sep_heap_rules]: \"\n    i<length l \\<Longrightarrow>\n    <is_ms_array_list N l a> \n      marl_get a i\n    <\\<lambda>r. is_ms_array_list N l a * \\<up>(r=l!i)>\"\n    by (sep_auto simp: marl_get_def is_ms_array_list_def split: prod.split)\n\n  lemma marl_set_rule[sep_heap_rules]: \"\n    i<length l \\<Longrightarrow>\n    <is_ms_array_list N l a> \n      marl_set a i x\n    <is_ms_array_list N (l[i:=x])>\"\n    by (sep_auto simp: marl_set_def is_ms_array_list_def split: prod.split)\n\n  definition \"marl_assn N A \\<equiv> hr_comp (is_ms_array_list N) (\\<langle>the_pure A\\<rangle>list_rel)\"\n  lemmas [safe_constraint_rules] = CN_FALSEI[of is_pure \"marl_assn N A\" for N A]\n\ncontext \n  notes [fcomp_norm_unfold] = marl_assn_def[symmetric]\n  notes [intro!] = hfrefI hn_refineI[THEN hn_refine_preI]\n  notes [simp] = pure_def hn_ctxt_def invalid_assn_def\nbegin  \n\n  definition [simp]: \"op_marl_empty_sz (N::nat) \\<equiv> op_list_empty\"\n  context fixes N :: nat begin\n    sepref_register \"PR_CONST (op_marl_empty_sz N)\"\n  end\n\n  \n\n  lemma marl_fold_custom_empty_sz: \n    \"op_list_empty = op_marl_empty_sz N\"\n    \"mop_list_empty = RETURN (op_marl_empty_sz N)\"\n    \"[] = op_marl_empty_sz N\"\n    by auto\n\n  lemma marl_empty_hnr_aux: \"(uncurry0 (marl_empty_sz N), uncurry0 (RETURN op_list_empty)) \\<in> unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a is_ms_array_list N\"\n    by sep_auto\n  lemmas marl_empty_hnr = marl_empty_hnr_aux[FCOMP op_list_empty.fref[of \"the_pure A\" for A]]\n  lemmas marl_empty_hnr_mop = marl_empty_hnr[FCOMP mk_mop_rl0_np[OF mop_list_empty_alt]]\n\n  lemma marl_empty_sz_hnr[sepref_fr_rules]:\n    \"(uncurry0 (marl_empty_sz N), uncurry0 (RETURN (PR_CONST (op_marl_empty_sz N)))) \\<in> unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a marl_assn N A\"\n    using marl_empty_hnr\n    by simp\n\n  lemma marl_append_hnr_aux: \"(uncurry marl_append,uncurry (RETURN oo op_list_append)) \\<in> [\\<lambda>(l,_). length l<N]\\<^sub>a ((is_ms_array_list N)\\<^sup>d *\\<^sub>a id_assn\\<^sup>k) \\<rightarrow> is_ms_array_list N\"\n    by sep_auto\n  lemmas marl_append_hnr[sepref_fr_rules] = marl_append_hnr_aux[FCOMP op_list_append.fref]\n  lemmas marl_append_hnr_mop[sepref_fr_rules] = marl_append_hnr[FCOMP mk_mop_rl2_np[OF mop_list_append_alt]]\n\n  lemma marl_length_hnr_aux: \"(marl_length,RETURN o op_list_length) \\<in> (is_ms_array_list N)\\<^sup>k \\<rightarrow>\\<^sub>a nat_assn\"\n    by sep_auto\n  lemmas marl_length_hnr[sepref_fr_rules] = marl_length_hnr_aux[FCOMP op_list_length.fref[of \"the_pure A\" for A]]\n  lemmas marl_length_hnr_mop[sepref_fr_rules] = marl_length_hnr[FCOMP mk_mop_rl1_np[OF mop_list_length_alt]]\n\n  lemma marl_is_empty_hnr_aux: \"(marl_is_empty,RETURN o op_list_is_empty) \\<in> (is_ms_array_list N)\\<^sup>k \\<rightarrow>\\<^sub>a bool_assn\"\n    by sep_auto\n  lemmas marl_is_empty_hnr[sepref_fr_rules] = marl_is_empty_hnr_aux[FCOMP op_list_is_empty.fref[of \"the_pure A\" for A]]\n  lemmas marl_is_empty_hnr_mop[sepref_fr_rules] = marl_is_empty_hnr[FCOMP mk_mop_rl1_np[OF mop_list_is_empty_alt]]\n\n  lemma marl_last_hnr_aux: \"(marl_last,RETURN o op_list_last) \\<in> [\\<lambda>x. x\\<noteq>[]]\\<^sub>a (is_ms_array_list N)\\<^sup>k \\<rightarrow> id_assn\"\n    by sep_auto\n  lemmas marl_last_hnr[sepref_fr_rules] = marl_last_hnr_aux[FCOMP op_list_last.fref]\n  lemmas marl_last_hnr_mop[sepref_fr_rules] = marl_last_hnr[FCOMP mk_mop_rl1[OF mop_list_last_alt]]\n\n  lemma marl_butlast_hnr_aux: \"(marl_butlast,RETURN o op_list_butlast) \\<in> [\\<lambda>x. x\\<noteq>[]]\\<^sub>a (is_ms_array_list N)\\<^sup>d \\<rightarrow> (is_ms_array_list N)\"\n    by sep_auto\n  lemmas marl_butlast_hnr[sepref_fr_rules] = marl_butlast_hnr_aux[FCOMP op_list_butlast.fref[of \"the_pure A\" for A]]\n  lemmas marl_butlast_hnr_mop[sepref_fr_rules] = marl_butlast_hnr[FCOMP mk_mop_rl1[OF mop_list_butlast_alt]]\n\n  lemma marl_get_hnr_aux: \"(uncurry marl_get,uncurry (RETURN oo op_list_get)) \\<in> [\\<lambda>(l,i). i<length l]\\<^sub>a ((is_ms_array_list N)\\<^sup>k *\\<^sub>a nat_assn\\<^sup>k) \\<rightarrow> id_assn\"\n    by sep_auto\n  lemmas marl_get_hnr[sepref_fr_rules] = marl_get_hnr_aux[FCOMP op_list_get.fref]\n  lemmas marl_get_hnr_mop[sepref_fr_rules] = marl_get_hnr[FCOMP mk_mop_rl2[OF mop_list_get_alt]]\n\n  lemma marl_set_hnr_aux: \"(uncurry2 marl_set,uncurry2 (RETURN ooo op_list_set)) \\<in> [\\<lambda>((l,i),_). i<length l]\\<^sub>a ((is_ms_array_list N)\\<^sup>d *\\<^sub>a nat_assn\\<^sup>k *\\<^sub>a id_assn\\<^sup>k) \\<rightarrow> (is_ms_array_list N)\"\n    by sep_auto\n  lemmas marl_set_hnr[sepref_fr_rules] = marl_set_hnr_aux[FCOMP op_list_set.fref]\n  lemmas marl_set_hnr_mop[sepref_fr_rules] = marl_set_hnr[FCOMP mk_mop_rl3[OF mop_list_set_alt]]\n\nend\n\ncontext\n  fixes N :: nat\n  assumes N_sz: \"N>10\"\nbegin\n\nschematic_goal \"hn_refine (emp) (?c::?'c Heap) ?\\<Gamma>' ?R (do {\n  let x = op_marl_empty_sz N;\n  RETURN (x@[1::nat])\n})\"  \n  using N_sz\n  by sepref\n\nend\n\nschematic_goal \"hn_refine (emp) (?c::?'c Heap) ?\\<Gamma>' ?R (do {\n  let x = op_list_empty;\n  RETURN (x@[1::nat])\n})\"  \n  apply (subst marl_fold_custom_empty_sz[where N=10])\n  apply sepref\n  done\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Evaluation/Refine_Imperative_HOL/IICF/Impl/IICF_MS_Array_List.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.25392142869728274}}
{"text": "section\\<open>Least Upper Bound\\<close>\ntext\\<open>The simplest way to merge a pair of transitions with identical outputs and updates is to\nsimply take the least upper bound of their \\emph{guards}. This theory presents several variants on\nthis theme.\\<close>\n\ntheory Least_Upper_Bound\n  imports \"../Inference\"\nbegin\n\nfun literal_args :: \"'a gexp \\<Rightarrow> bool\" where\n  \"literal_args (Bc v) = False\" |\n  \"literal_args (Eq (V _) (L _)) = True\" |\n  \"literal_args (In _ _) = True\" |\n  \"literal_args (Eq _ _) = False\" |\n  \"literal_args (Gt va v) = False\" |\n  \"literal_args (Nor v va) = (literal_args v \\<and> literal_args va)\"\n\nlemma literal_args_eq:\n  \"literal_args (Eq a b) \\<Longrightarrow> \\<exists>v l. a = (V v) \\<and> b = (L l)\"\n  apply (cases a)\n     apply simp\n      apply (cases b)\n  by auto\n\ndefinition \"all_literal_args t = (\\<forall>g \\<in> set (Guards t). literal_args g)\"\n\nfun merge_in_eq :: \"vname \\<Rightarrow> value \\<Rightarrow> vname gexp list \\<Rightarrow> vname gexp list\" where\n  \"merge_in_eq v l [] = [Eq (V v) (L l)]\" |\n  \"merge_in_eq v l ((Eq (V v') (L l'))#t) = (if v = v' \\<and> l \\<noteq> l' then (In v [l, l'])#t else (Eq (V v') (L l'))#(merge_in_eq v l t))\" |\n  \"merge_in_eq v l ((In v' l')#t) = (if v = v' then (In v (remdups (l#l')))#t else (In v' l')#(merge_in_eq v l t))\" |\n  \"merge_in_eq v l (h#t) = h#(merge_in_eq v l t)\"\n\nfun merge_in_in :: \"vname \\<Rightarrow> value list \\<Rightarrow> vname gexp list \\<Rightarrow> vname gexp list\" where\n  \"merge_in_in v l [] = [In v l]\" |\n  \"merge_in_in v l ((Eq (V v') (L l'))#t) = (if v = v' then (In v (List.insert l' l))#t else (Eq (V v') (L l'))#(merge_in_in v l t))\" |\n  \"merge_in_in v l ((In v' l')#t) = (if v = v' then (In v (List.union l l'))#t else (In v' l')#(merge_in_in v l t))\" |\n  \"merge_in_in v l (h#t) = h#(merge_in_in v l t)\"\n\nfun merge_guards :: \"vname gexp list \\<Rightarrow> vname gexp list \\<Rightarrow> vname gexp list\" where\n  \"merge_guards [] g2 = g2\" |\n  \"merge_guards ((Eq (V v) (L l))#t) g2 =  merge_guards t (merge_in_eq v l g2)\" |\n  \"merge_guards ((In v l)#t) g2 = merge_guards t (merge_in_in v l g2)\" |\n  \"merge_guards (h#t) g2 = h#(merge_guards t g2)\"\n\ntext\\<open>The ``least upper bound'' (lob) heuristic simply disjoins the guards of two transitions with\nidentical outputs and updates.\\<close>\ndefinition lob_aux :: \"transition \\<Rightarrow> transition \\<Rightarrow> transition option\" where\n  \"lob_aux t1 t2 = (if Outputs t1 = Outputs t2 \\<and> Updates t1 = Updates t2 \\<and> all_literal_args t1 \\<and> all_literal_args t2 then\n      Some \\<lparr>Label = Label t1, Arity = Arity t1, Guards = remdups (merge_guards (Guards t1) (Guards t2)), Outputs = Outputs t1, Updates = Updates t1\\<rparr>\n     else None)\"\n\nfun lob :: update_modifier where\n  \"lob t1ID t2ID s new _ old _ = (let\n     t1 = (get_by_ids new t1ID);\n     t2 = (get_by_ids new t2ID) in\n     case lob_aux t1 t2 of\n       None \\<Rightarrow> None |\n       Some lob_t \\<Rightarrow>\n           Some (replace_transitions new [(t1ID, lob_t), (t2ID, lob_t)])\n   )\"\n\nlemma lob_aux_some: \"Outputs t1 = Outputs t2 \\<Longrightarrow>\n       Updates t1 = Updates t2 \\<Longrightarrow>\n       all_literal_args t1 \\<Longrightarrow>\n       all_literal_args t2 \\<Longrightarrow>\n       Label t = Label t1 \\<Longrightarrow>\n       Arity t = Arity t1 \\<Longrightarrow>\n       Guards t = remdups (merge_guards (Guards t1) (Guards t2)) \\<Longrightarrow>\n       Outputs t = Outputs t1 \\<Longrightarrow>\n       Updates t = Updates t1 \\<Longrightarrow>\n       lob_aux t1 t2 = Some t\"\n  by (simp add: lob_aux_def)\n\nfun has_corresponding :: \"vname gexp \\<Rightarrow> vname gexp list \\<Rightarrow> bool\" where\n  \"has_corresponding g [] = False\" |\n  \"has_corresponding (Eq (V v) (L l)) ((Eq (V v') (L l'))#t) = (if v = v' \\<and> l = l' then True else has_corresponding (Eq (V v) (L l)) t)\" |\n  \"has_corresponding (In v' l') ((Eq (V v) (L l))#t) = (if v = v' \\<and> l \\<in> set l' then True else has_corresponding (In v' l') t)\" |\n  \"has_corresponding (In v l) ((In v' l')#t) = (if v = v' \\<and> set l' \\<subseteq> set l then True else has_corresponding (In v l) t)\" |\n  \"has_corresponding g (h#t) = has_corresponding g t\"\n\nlemma no_corresponding_bc: \"\\<not>has_corresponding (Bc x1) G1\"\n  apply (induct G1)\n  by auto\n\nlemma no_corresponding_gt: \"\\<not>has_corresponding (Gt x1 y1) G1\"\n  apply (induct G1)\n  by auto\n\nlemma no_corresponding_nor: \"\\<not>has_corresponding (Nor x1 y1) G1\"\n  apply (induct G1)\n  by auto\n\nlemma has_corresponding_eq: \"has_corresponding (Eq x21 x22) G1 \\<Longrightarrow> (Eq x21 x22) \\<in> set G1\"\nproof(induct G1)\n  case (Cons a G1)\n  then show ?case\n    apply (cases a)\n        apply simp\n    subgoal for x21a x22a\n      apply (case_tac \"x21a\")\n          apply simp\n         apply (case_tac \"x22a\")\n             apply clarify\n             apply simp\n             apply (case_tac \"x21\")\n                 apply simp\n                apply (case_tac \"x22\")\n                    apply (metis has_corresponding.simps(2))\n      by auto\n    by auto\nqed auto\n\nlemma has_corresponding_In: \"has_corresponding (In v l) G1 \\<Longrightarrow> (\\<exists>l'. (In v l') \\<in> set G1 \\<and> set l' \\<subseteq> set l) \\<or> (\\<exists>l' \\<in> set l. (Eq (V v) (L l')) \\<in> set G1)\"\nproof(induct G1)\n  case (Cons a G1)\n  then show ?case\n    apply (cases a)\n        apply simp\n       defer\n       apply simp\n      apply simp\n      defer\n      apply simp\n     apply simp\n    subgoal for x21 x22 apply (case_tac x21)\n          apply simp\n         apply (case_tac x22)\n             apply fastforce\n            apply simp+\n      done\n    by metis\nqed auto\n\nlemma gval_each_one: \"g \\<in> set G \\<Longrightarrow> apply_guards G s \\<Longrightarrow> gval g s = true\"\n  using apply_guards_cons apply_guards_rearrange by blast\n\nlemma has_corresponding_apply_guards:\n  \"\\<forall>g\\<in>set G2. has_corresponding g G1 \\<Longrightarrow>\n   apply_guards G1 s \\<Longrightarrow>\n   apply_guards G2 s\"\nproof(induct G2)\n  case (Cons a G2)\n  then show ?case\n    apply (cases a)\n        apply (simp add: no_corresponding_bc)\n       apply simp\n       apply (metis (full_types) has_corresponding_eq append_Cons append_self_conv2 apply_guards_append apply_guards_rearrange)\n      apply (simp add: no_corresponding_gt)\n     apply simp\n    subgoal for v l\n      apply (insert has_corresponding_In[of v l G1])\n      apply simp\n      apply (erule disjE)\n       apply clarsimp\n      subgoal for l'\n        apply (insert apply_guards_rearrange[of \"In v l'\" G1 s])\n        apply simp\n        apply (simp only: apply_guards_cons[of \"In v l\" G2])\n        apply (simp only: apply_guards_cons[of \"In v l'\" G1])\n        apply simp\n        apply (cases \"s v\")\n         apply simp\n        by force\n      apply clarsimp\n      subgoal for l'\n        apply (insert apply_guards_rearrange[of \"Eq (V v) (L l')\" G1 s])\n        apply simp\n        apply (simp only: apply_guards_cons[of \"In v l\" G2])\n        apply (simp only: apply_guards_cons[of \"Eq (V v) (L l')\" G1])\n        apply (cases \"s v\")\n         apply simp\n        apply simp\n        using trilean.distinct(1) by presburger\n      done\n    by (simp add: no_corresponding_nor)\nqed auto\n\nlemma correspondence_subsumption:\n  \"Label t1 = Label t2 \\<Longrightarrow>\n   Arity t1 = Arity t2 \\<Longrightarrow>\n   Outputs t1 = Outputs t2 \\<Longrightarrow>\n   Updates t1 = Updates t2 \\<Longrightarrow>\n   \\<forall>g \\<in> set (Guards t2). has_corresponding g (Guards t1) \\<Longrightarrow>\n   subsumes t2 c t1\"\n  by (simp add: can_take_def can_take_transition_def has_corresponding_apply_guards subsumption)\n\ndefinition \"is_lob t1 t2 = (\n  Label t1 = Label t2 \\<and>\n  Arity t1 = Arity t2 \\<and>\n  Outputs t1 = Outputs t2 \\<and>\n  Updates t1 = Updates t2 \\<and>\n  (\\<forall>g \\<in> set (Guards t2). has_corresponding g (Guards t1)))\"\n\nlemma is_lob_direct_subsumption:\n  \"is_lob t1 t2 \\<Longrightarrow> directly_subsumes e1 e2 s s' t2 t1\"\n  apply (rule subsumes_in_all_contexts_directly_subsumes)\n  by (simp add: is_lob_def correspondence_subsumption)\n\nfun has_distinguishing :: \"vname gexp \\<Rightarrow> vname gexp list \\<Rightarrow> bool\" where\n  \"has_distinguishing g [] = False\" |\n  \"has_distinguishing (Eq (V v) (L l)) ((Eq (V v') (L l'))#t) = (if v = v' \\<and> l \\<noteq> l' then True else has_distinguishing (Eq (V v) (L l)) t)\" |\n  \"has_distinguishing (In (I v') l') ((Eq (V (I v)) (L l))#t) = (if v = v' \\<and> l \\<notin> set l' then True else has_distinguishing (In (I v') l') t)\" |\n  \"has_distinguishing (In (I v) l) ((In (I v') l')#t) = (if v = v' \\<and> set l' \\<supset> set l then True else has_distinguishing (In (I v) l) t)\" |\n  \"has_distinguishing g (h#t) = has_distinguishing g t\"\n\nlemma has_distinguishing: \"has_distinguishing g G \\<Longrightarrow> (\\<exists>v l. g = (Eq (V v) (L l))) \\<or> (\\<exists>v l. g = In v l)\"\nproof(induct G)\n  case (Cons a G)\n  then show ?case\n    apply (cases g)\n         apply simp\n        apply (case_tac x21)\n           apply simp\n          apply (case_tac x22)\n    by auto\nqed auto\n\nlemma has_distinguishing_Eq: \"has_distinguishing (Eq (V v) (L l)) G \\<Longrightarrow> \\<exists>l'. (Eq (V v) (L l')) \\<in> set G \\<and> l \\<noteq> l'\"\nproof (induct G)\n  case (Cons a G)\n  then show ?case\n    apply (cases a)\n         apply simp\n        apply (case_tac x21)\n           apply simp\n          apply (case_tac x22)\n             apply (metis has_distinguishing.simps(2) list.set_intros(1) list.set_intros(2))\n    by auto\nqed auto\n\nlemma ex_mutex: \"Eq (V v) (L l) \\<in> set G1 \\<Longrightarrow>\n       Eq (V v) (L l') \\<in> set G2 \\<Longrightarrow>\n       l \\<noteq> l' \\<Longrightarrow>\n       apply_guards G1 s \\<Longrightarrow>\n       \\<not> apply_guards G2 s\"\n  apply (simp add: apply_guards_def Bex_def)\n  apply (rule_tac x=\"Eq (V v) (L l')\" in exI)\n  apply simp\n  apply (case_tac \"s v\")\n  by auto\n\nlemma has_distinguishing_In:\n  \"has_distinguishing (In v l) G \\<Longrightarrow>\n   (\\<exists>l' i. v = I i \\<and> Eq (V v) (L l') \\<in> set G \\<and> l' \\<notin> set l) \\<or> (\\<exists>l' i. v = I i \\<and> In v l' \\<in> set G \\<and> set l' \\<supset> set l)\"\nproof(induct G)\n  case (Cons a G)\n  then show ?case\n    apply (case_tac v)\n    subgoal for x\n      apply simp\n      apply (cases a)\n          apply simp\n      subgoal for x21 x22\n        apply (case_tac x21)\n            apply simp\n           apply (case_tac x22)\n               apply (case_tac x2)\n                apply fastforce\n               apply simp+\n        done\n      subgoal by simp\n      subgoal for x41\n        apply (case_tac x41)\n         apply (simp, metis)\n        by auto\n      by auto\n    by auto\nqed auto\n\nlemma Eq_apply_guards:\n  \"Eq (V v) (L l) \\<in> set G1 \\<Longrightarrow>\n   apply_guards G1 s \\<Longrightarrow>\n   s v = Some l\"\n  apply (simp add: apply_guards_rearrange)\n  apply (simp add: apply_guards_cons)\n  apply (cases \"s v\")\n   apply simp\n  apply simp\n  using trilean.distinct(1) by presburger\n\nlemma In_neq_apply_guards:\n  \"In v l \\<in> set G2 \\<Longrightarrow>\n   Eq (V v) (L l') \\<in> set G1 \\<Longrightarrow>\n   l' \\<notin> set l \\<Longrightarrow>\n   apply_guards G1 s \\<Longrightarrow>\n   \\<not>apply_guards G2 s\"\nproof(induct G1)\n  case (Cons a G1)\n  then show ?case\n    apply (simp add: apply_guards_def Bex_def)\n    apply (rule_tac x=\"In v l\" in exI)\n    using Eq_apply_guards[of v l' \"a#G1\" s]\n    by (simp add: Cons.prems(4) image_iff)\nqed auto\n\nlemma In_apply_guards: \"In v l \\<in> set G1 \\<Longrightarrow> apply_guards G1 s \\<Longrightarrow> \\<exists>v' \\<in> set l. s v = Some v'\"\n  apply (simp add: apply_guards_rearrange)\n  apply (simp add: apply_guards_cons)\n  apply (cases \"s v\")\n   apply simp\n  apply simp\n  by (meson image_iff trilean.simps(2))\n\nlemma input_not_constrained_aval_swap_inputs:\n  \"\\<not> aexp_constrains a (V (I v)) \\<Longrightarrow>\n   aval a (join_ir i c) = aval a (join_ir (list_update i v x) c)\"\n  apply(induct a rule: aexp_induct_separate_V_cases)\n       apply simp\n      apply (metis aexp_constrains.simps(2) aval.simps(2) input2state_nth input2state_out_of_bounds join_ir_def length_list_update not_le nth_list_update_neq vname.simps(5))\n  using join_ir_def by auto\n\nlemma input_not_constrained_gval_swap_inputs:\n  \"\\<not> gexp_constrains a (V (I v)) \\<Longrightarrow>\n   gval a (join_ir i c) = gval a (join_ir (i[v := x]) c)\"\nproof(induct a)\n  case (Bc x)\n  then show ?case\n    by (metis (full_types) gval.simps(1) gval.simps(2))\nnext\n  case (Eq x1a x2)\n  then show ?case\n    using input_not_constrained_aval_swap_inputs by auto\nnext\n  case (Gt x1a x2)\n  then show ?case\n    using input_not_constrained_aval_swap_inputs by auto\nnext\n  case (In x1a x2)\n  then show ?case\n    apply simp\n    apply (case_tac \"join_ir i c x1a\")\n     apply (case_tac \"join_ir (i[v := x]) c x1a\")\n      apply simp\n     apply (metis In.prems aval.simps(2) gexp_constrains.simps(5) input_not_constrained_aval_swap_inputs option.discI)\n    apply (case_tac \"join_ir (i[v := x]) c x1a\")\n     apply (metis In.prems aval.simps(2) gexp_constrains.simps(5) input_not_constrained_aval_swap_inputs option.discI)\n    by (metis In.prems aval.simps(2) gexp_constrains.simps(5) input_not_constrained_aval_swap_inputs)\nqed auto\n\nlemma test_aux: \"\\<forall>g\\<in>set (removeAll (In (I v) l) G1). \\<not> gexp_constrains g (V (I v)) \\<Longrightarrow>\n      apply_guards G1 (join_ir i c) \\<Longrightarrow>\n      x \\<in> set l \\<Longrightarrow>\n      apply_guards G1 (join_ir (i[v := x]) c)\"\nproof(induct G1)\n  case (Cons a G1)\n  then show ?case\n    apply (simp only: apply_guards_cons)\n    apply (case_tac \"a = In (I v) l\")\n     apply simp\n     apply (case_tac \"join_ir i c (I v)\")\n      apply simp\n     apply (case_tac \"join_ir (i[v := x]) c (I v)\")\n      apply (metis join_ir_nth le_less_linear length_list_update list_update_beyond option.discI)\n     apply simp\n     apply (metis join_ir_nth le_less_linear length_list_update list_update_beyond nth_list_update_eq option.inject trilean.distinct(1))\n    apply (case_tac \"join_ir (i[v := x]) c (I v)\")\n     apply (metis join_ir_nth le_less_linear length_list_update list_update_beyond option.discI)\n    apply simp\n    using input_not_constrained_gval_swap_inputs by auto\nqed auto\n\nlemma test:\n  assumes\n    p1: \"In (I v) l \\<in> set G2\" and\n    p2: \"In (I v) l' \\<in> set G1\" and\n    p3: \"x \\<in> set l'\" and\n    p4: \"x \\<notin> set l\" and\n    p5: \"apply_guards G1 (join_ir i c)\" and\n    p6: \"length i = a\" and\n    p7: \"\\<forall>g \\<in> set (removeAll (In (I v) l') G1). \\<not> gexp_constrains g (V (I v))\"\n  shows \"\\<exists>i. length i = a \\<and> apply_guards G1 (join_ir i c) \\<and> (length i = a \\<longrightarrow> \\<not> apply_guards G2 (join_ir i c))\"\n  apply (rule_tac x=\"list_update i v x\" in exI)\n  apply standard\n   apply (simp add: p6)\n  apply standard\n  using p3 p5 p7 test_aux apply blast\n  using p1 p4\n  apply (simp add: apply_guards_rearrange)\n  apply (simp add: apply_guards_cons join_ir_def)\n  apply (case_tac \"input2state (i[v := x]) $ v\")\n   apply simp\n  apply simp\n  by (metis input2state_nth input2state_within_bounds length_list_update nth_list_update_eq option.inject)\n\ndefinition get_Ins :: \"vname gexp list \\<Rightarrow> (nat \\<times> value list) list\" where\n  \"get_Ins G = map (\\<lambda>g. case g of (In (I v) l) \\<Rightarrow> (v, l)) (filter (\\<lambda>g. case g of (In (I _) _ ) \\<Rightarrow> True | _ \\<Rightarrow> False) G)\"\n\nlemma get_Ins_Cons_equiv: \"\\<nexists>v l. a = In (I v) l \\<Longrightarrow> get_Ins (a # G) = get_Ins G\"\n  apply (simp add: get_Ins_def)\n  apply (cases a)\n       apply simp+\n   apply (metis (full_types) vname.exhaust vname.simps(6))\n  by simp\n\nlemma Ball_Cons: \"(\\<forall>x \\<in> set (a#l). P x) = (P a \\<and> (\\<forall>x \\<in> set l. P x))\"\n  by simp\n\nlemma In_in_get_Ins: \"(In (I v) l \\<in> set G) = ((v, l) \\<in> set (get_Ins G))\"\nproof(induct G)\n  case Nil\n  then show ?case\n    by (simp add: get_Ins_def)\nnext\n  case (Cons a G)\n  then show ?case\n    apply (simp add: get_Ins_def)\n    apply (cases a)\n        apply simp+\n    subgoal for x by (case_tac x, auto)\n    apply auto\n    done\nqed\n\ndefinition \"check_get_Ins G = (\\<forall>(v, l') \\<in> set (get_Ins G). \\<forall>g \\<in> set (removeAll (In (I v) l') G). \\<not> gexp_constrains g (V (I v)))\"\n\nlemma no_Ins: \"[] = get_Ins G \\<Longrightarrow> set G - {In (I i) l} = set G\"\nproof(induct G)\n  case (Cons a G)\n  then show ?case\n    apply (cases a)\n        apply (simp add: get_Ins_Cons_equiv insert_Diff_if)+\n    subgoal for x41 x42\n      apply (case_tac x41)\n       apply simp\n       apply (metis In_in_get_Ins equals0D list.set(1) list.set_intros(1))\n      apply (simp add: get_Ins_Cons_equiv)\n      done\n    by (simp add: get_Ins_Cons_equiv insert_Diff_if)\nqed auto\n\nlemma test2: \"In (I i) l \\<in> set (Guards t2) \\<Longrightarrow>\n       In (I i) l' \\<in> set (Guards t1) \\<Longrightarrow>\n       length ia = Arity t1 \\<Longrightarrow>\n       apply_guards (Guards t1) (join_ir ia c) \\<Longrightarrow>\n       x \\<in> set l' \\<Longrightarrow>\n       x \\<notin> set l \\<Longrightarrow>\n       \\<forall>(v, l')\\<in>insert (0, []) (set (get_Ins (Guards t1))). \\<forall>g\\<in>set (removeAll (In (I v) l') (Guards t1)). \\<not> gexp_constrains g (V (I v)) \\<Longrightarrow>\n       Arity t1 = Arity t2 \\<Longrightarrow>\n       \\<exists>i. length i = Arity t2 \\<and> apply_guards (Guards t1) (join_ir i c) \\<and> (length i = Arity t2 \\<longrightarrow> \\<not> apply_guards (Guards t2) (join_ir i c))\"\n  using test[of i l \"Guards t2\" l' \"Guards t1\" x ia  c \"Arity t2\"]\n  apply simp\n  apply (case_tac \"\\<forall>g\\<in>set (Guards t1) - {In (I i) l'}. \\<not> gexp_constrains g (V (I i))\")\n   apply simp\n  apply simp\n  using In_in_get_Ins by blast\n\nlemma distinguishing_subsumption:\n  assumes\n    p1: \"\\<exists>g \\<in> set (Guards t2). has_distinguishing g (Guards t1)\" and\n    p2: \"Arity t1 = Arity t2\" and\n    p3: \"\\<exists>i. can_take_transition t1 i c\" and\n    p4: \"(\\<forall>(v, l') \\<in> insert (0, []) (set (get_Ins (Guards t1))). \\<forall>g \\<in> set (removeAll (In (I v) l') (Guards t1)). \\<not> gexp_constrains g (V (I v)))\"\n  shows\n   \"\\<not> subsumes t2 c t1\"\nproof-\n  show ?thesis\n    apply (rule bad_guards)\n    apply (simp add: can_take_transition_def can_take_def p2)\n    apply (insert p1, simp add: Bex_def)\n    apply (erule exE)\n    apply (case_tac \"\\<exists>v l. x = (Eq (V v) (L l))\")\n     apply (metis can_take_def can_take_transition_def ex_mutex p2 p3 has_distinguishing_Eq)\n    apply (case_tac \"\\<exists>v l. x = In v l\")\n     defer\n    using has_distinguishing apply blast\n    apply clarify\n    apply (case_tac \"\\<exists>l' i. v = I i \\<and> Eq (V v) (L l') \\<in> set (Guards t1) \\<and> l' \\<notin> set l\")\n     apply (metis In_neq_apply_guards can_take_def can_take_transition_def p2 p3)\n    apply (case_tac \"(\\<exists>l' i. v = I i \\<and> In v l' \\<in> set (Guards t1) \\<and> set l' \\<supset> set l)\")\n     defer\n    using has_distinguishing_In apply blast\n    apply simp\n    apply (erule conjE)\n    apply (erule exE)+\n    apply (erule conjE)\n    apply (insert p3, simp only: can_take_transition_def can_take_def)\n    apply (case_tac \"\\<exists>x. x \\<in> set l' \\<and> x \\<notin> set l\")\n    apply (erule exE)+\n    apply (erule conjE)+\n    apply (insert p4 p2)\n    using test2\n     apply blast\n    by auto\nqed\n\ndefinition \"lob_distinguished t1 t2 = (\n(\\<exists>g \\<in> set (Guards t2). has_distinguishing g (Guards t1)) \\<and>\nArity t1 = Arity t2 \\<and>\n(\\<forall>(v, l') \\<in> insert (0, []) (set (get_Ins (Guards t1))). \\<forall>g \\<in> set (removeAll (In (I v) l') (Guards t1)). \\<not> gexp_constrains g (V (I v))))\"\n\nlemma must_be_another:\n  \"1 < size (fset_of_list b) \\<Longrightarrow>\n   x \\<in> set b \\<Longrightarrow>\n   \\<exists>x' \\<in> set b. x \\<noteq> x'\"\nproof(induct b)\n  case (Cons a b)\n  then show ?case\n    apply (simp add: Bex_def)\n    by (metis List.finite_set One_nat_def card.insert card_gt_0_iff card_mono fset_of_list.rep_eq insert_absorb le_0_eq less_nat_zero_code less_numeral_extra(4) not_less_iff_gr_or_eq set_empty2 subsetI)\nqed auto\n\nlemma another_swap_inputs:\n  \"apply_guards G (join_ir i c) \\<Longrightarrow>\n  filter (\\<lambda>g. gexp_constrains g (V (I a))) G = [In (I a) b] \\<Longrightarrow>\n  xa \\<in> set b \\<Longrightarrow>\n  apply_guards G (join_ir (i[a := xa]) c)\"\nproof(induct G)\n  case (Cons g G)\n  then show ?case\n    apply (simp add: apply_guards_cons)\n    apply (case_tac \"gexp_constrains g (V (I a))\")\n     defer\n    using input_not_constrained_gval_swap_inputs apply auto[1]\n     apply simp\n    apply (case_tac \"join_ir i c (I a) \\<in> Some ` set b\")\n     defer\n     apply simp\n    apply clarify\n    apply standard\n    using apply_guards_def input_not_constrained_gval_swap_inputs\n      apply (simp add: filter_empty_conv)\n      apply (case_tac \"join_ir i c (I a)\")\n       apply simp\n      apply (case_tac \"join_ir (i[a := xa]) c (I a)\")\n       apply simp\n       apply (metis image_eqI trilean.distinct(1))\n      apply simp\n      apply (metis image_eqI trilean.distinct(1))\n     apply (case_tac \"join_ir i c (I a)\")\n      apply simp\n     apply simp\n     apply (metis image_eqI trilean.distinct(1))\n    apply (case_tac \"join_ir i c (I a)\")\n     apply simp\n    apply (case_tac \"join_ir (i[a := xa]) c (I a)\")\n     apply simp\n     apply (metis join_ir_nth le_less_linear length_list_update list_update_beyond option.discI)\n    apply simp\n    apply standard\n     apply (metis (no_types, lifting) Cons.hyps Cons.prems(2) filter_empty_conv removeAll_id set_ConsD test_aux)\n    by (metis in_these_eq join_ir_nth le_less_linear length_list_update list_update_beyond nth_list_update_eq these_image_Some_eq)\nqed auto\n\nlemma lob_distinguished_2_not_subsumes:\n  \"\\<exists>(i, l) \\<in> set (get_Ins (Guards t2)). filter (\\<lambda>g. gexp_constrains g (V (I i))) (Guards t2) = [(In (I i) l)] \\<and>\n    (\\<exists>l' \\<in> set l. i < Arity t1 \\<and> Eq (V (I i)) (L l') \\<in> set (Guards t1) \\<and> size (fset_of_list l) > 1) \\<Longrightarrow>\n   Arity t1 = Arity t2 \\<Longrightarrow>\n   \\<exists>i. can_take_transition t2 i c \\<Longrightarrow>\n   \\<not> subsumes t1 c t2\"\n  apply (rule bad_guards)\n  apply simp\n  apply (simp add: can_take_def can_take_transition_def Bex_def)\n  apply clarify\n  apply (case_tac \"\\<exists>x' \\<in> set b. x \\<noteq> x'\")\n   defer\n   apply (simp add: must_be_another)\n  apply (simp add: Bex_def)\n  apply (erule exE)\n  apply (rule_tac x=\"list_update i a xa\" in exI)\n  apply simp\n  apply standard\n   apply (simp add: another_swap_inputs)\n  by (metis Eq_apply_guards input2state_nth join_ir_def length_list_update nth_list_update_eq option.inject vname.simps(5))\n\ndefinition \"lob_distinguished_2 t1 t2 =\n  (\\<exists>(i, l) \\<in> set (get_Ins (Guards t2)). filter (\\<lambda>g. gexp_constrains g (V (I i))) (Guards t2) = [(In (I i) l)] \\<and>\n    (\\<exists>l' \\<in> set l. i < Arity t1 \\<and> Eq (V (I i)) (L l') \\<in> set (Guards t1) \\<and> size (fset_of_list l) > 1) \\<and>\n  Arity t1 = Arity t2)\"\n\nlemma lob_distinguished_3_not_subsumes:\n  \"\\<exists>(i, l) \\<in> set (get_Ins (Guards t2)). filter (\\<lambda>g. gexp_constrains g (V (I i))) (Guards t2) = [(In (I i) l)] \\<and>\n    (\\<exists>(i', l') \\<in> set (get_Ins (Guards t1)). i = i' \\<and> set l' \\<subset> set l) \\<Longrightarrow>\n   Arity t1 = Arity t2 \\<Longrightarrow>\n   \\<exists>i. can_take_transition t2 i c \\<Longrightarrow>\n   \\<not> subsumes t1 c t2\"\n  apply (rule bad_guards)\n  apply simp\n  apply (simp add: can_take_def can_take_transition_def Bex_def)\n  apply (erule exE)+\n  apply (erule conjE)+\n  apply (erule exE)+\n  apply (erule conjE)+\n  apply (case_tac \"\\<exists>x. x \\<in> set b \\<and> x \\<notin> set ba\")\n   defer\n  apply auto[1]\n  apply (erule exE)+\n  apply (erule conjE)+\n  apply (rule_tac x=\"list_update i a x\" in exI)\n  apply simp\n  apply standard\n  using another_swap_inputs apply blast\n  by (metis In_apply_guards In_in_get_Ins input2state_not_None input2state_nth join_ir_def nth_list_update_eq option.distinct(1) option.inject vname.simps(5))\n\n\ndefinition \"lob_distinguished_3 t1 t2 = (\\<exists>(i, l) \\<in> set (get_Ins (Guards t2)). filter (\\<lambda>g. gexp_constrains g (V (I i))) (Guards t2) = [(In (I i) l)] \\<and>\n    (\\<exists>(i', l') \\<in> set (get_Ins (Guards t1)). i = i' \\<and> set l' \\<subset> set l) \\<and>\n   Arity t1 = Arity t2)\"\n\nfun is_In :: \"'a gexp \\<Rightarrow> bool\" where\n  \"is_In (In _ _) = True\" |\n  \"is_In _ = False\"\n\ntext\\<open>The ``greatest upper bound'' (gob) heuristic is similar to \\texttt{lob} but applies a more\nintellegent approach to guard merging.\\<close>\n\ndefinition gob_aux :: \"transition \\<Rightarrow> transition \\<Rightarrow> transition option\" where\n  \"gob_aux t1 t2 = (if Outputs t1 = Outputs t2 \\<and> Updates t1 = Updates t2 \\<and> all_literal_args t1 \\<and> all_literal_args t2 then\n      Some \\<lparr>Label = Label t1, Arity = Arity t1, Guards = remdups (filter (Not \\<circ> is_In) (merge_guards (Guards t1) (Guards t2))), Outputs = Outputs t1, Updates = Updates t1\\<rparr>\n     else None)\"\n\nfun gob :: update_modifier where\n  \"gob t1ID t2ID s new _ old _ = (let\n     t1 = (get_by_ids new t1ID);\n     t2 = (get_by_ids new t2ID) in\n     case gob_aux t1 t2 of\n       None \\<Rightarrow> None |\n       Some gob_t \\<Rightarrow>\n           Some (replace_transitions new [(t1ID, gob_t), (t2ID, gob_t)])\n   )\"\n\ntext\\<open>The ``Gung Ho'' heuristic simply drops the guards of both transitions, making them identical.\\<close>\ndefinition gung_ho_aux :: \"transition \\<Rightarrow> transition \\<Rightarrow> transition option\" where\n  \"gung_ho_aux t1 t2 = (if Outputs t1 = Outputs t2 \\<and> Updates t1 = Updates t2 \\<and> all_literal_args t1 \\<and> all_literal_args t2 then\n      Some \\<lparr>Label = Label t1, Arity = Arity t1, Guards = [], Outputs = Outputs t1, Updates = Updates t1\\<rparr>\n     else None)\"\n\nfun gung_ho :: update_modifier where\n  \"gung_ho t1ID t2ID s new _ old _ = (let\n     t1 = (get_by_ids new t1ID);\n     t2 = (get_by_ids new t2ID) in\n     case gung_ho_aux t1 t2 of\n       None \\<Rightarrow> None |\n       Some gob_t \\<Rightarrow>\n           Some (replace_transitions new [(t1ID, gob_t), (t2ID, gob_t)])\n   )\"\n\n\n\nlemma guard_subset_eq_outputs_updates_direct_subsumption:\n  \"Label t1 = Label t2 \\<Longrightarrow>\n   Arity t1 = Arity t2 \\<Longrightarrow>\n   Outputs t1 = Outputs t2 \\<Longrightarrow>\n   Updates t1 = Updates t2 \\<Longrightarrow>\n   set (Guards t2) \\<subseteq> set (Guards t1) \\<Longrightarrow>\n   directly_subsumes m1 m2 s1 s2 t2 t1\"\n  apply (rule subsumes_in_all_contexts_directly_subsumes)\n  by (simp add: guard_subset_eq_outputs_updates_subsumption)\n\nlemma unconstrained_input:\n  \"\\<forall>g\\<in>set G. \\<not> gexp_constrains g (V (I i)) \\<Longrightarrow>\n   apply_guards G (join_ir ia c) \\<Longrightarrow>\n   apply_guards G (join_ir (ia[i := x']) c)\"\nproof(induct G)\n  case (Cons a G)\n  then show ?case\n    apply (simp add: apply_guards_cons)\n    using input_not_constrained_gval_swap_inputs[of a i ia c x']\n    by simp\nqed auto\n\nlemma each_input_guarded_once_cons:\n   \"\\<forall>i\\<in>\\<Union> (enumerate_gexp_inputs ` set (a # G)). length (filter (\\<lambda>g. gexp_constrains g (V (I i))) (a # G)) \\<le> 1 \\<Longrightarrow>\n    \\<forall>i\\<in>\\<Union> (enumerate_gexp_inputs ` set G). length (filter (\\<lambda>g. gexp_constrains g (V (I i))) G) \\<le> 1\"\n  apply (simp add: Ball_def)\n  apply clarify\nproof -\n  fix x :: nat and xa :: \"vname gexp\"\n  assume a1: \"\\<forall>x. (x \\<in> enumerate_gexp_inputs a \\<longrightarrow> length (if gexp_constrains a (V (I x)) then a # filter (\\<lambda>g. gexp_constrains g (V (I x))) G else filter (\\<lambda>g. gexp_constrains g (V (I x))) G) \\<le> 1) \\<and> ((\\<exists>xa\\<in>set G. x \\<in> enumerate_gexp_inputs xa) \\<longrightarrow> length (if gexp_constrains a (V (I x)) then a # filter (\\<lambda>g. gexp_constrains g (V (I x))) G else filter (\\<lambda>g. gexp_constrains g (V (I x))) G) \\<le> 1)\"\n  assume a2: \"xa \\<in> set G\"\n  assume \"x \\<in> enumerate_gexp_inputs xa\"\n  then have \"if gexp_constrains a (V (I x)) then length (a # filter (\\<lambda>g. gexp_constrains g (V (I x))) G) \\<le> 1 else length (filter (\\<lambda>g. gexp_constrains g (V (I x))) G) \\<le> 1\"\n    using a2 a1 by fastforce\n  then show \"length (filter (\\<lambda>g. gexp_constrains g (V (I x))) G) \\<le> 1\"\n    by (metis (no_types) impossible_Cons le_cases order.trans)\nqed\n\nlemma literal_args_can_take:\n  \"\\<forall>g\\<in>set G. \\<exists>i v s. g = Eq (V (I i)) (L v) \\<or> g = In (I i) s \\<and> s \\<noteq> [] \\<Longrightarrow>\n   \\<forall>i\\<in>\\<Union> (enumerate_gexp_inputs ` set G). i < a \\<Longrightarrow>\n   \\<forall>i\\<in>\\<Union> (enumerate_gexp_inputs ` set G). length (filter (\\<lambda>g. gexp_constrains g (V (I i))) G) \\<le> 1 \\<Longrightarrow>\n   \\<exists>i. length i = a \\<and> apply_guards G (join_ir i c)\"\nproof(induct G)\n  case Nil\n  then show ?case\n    using Ex_list_of_length\n    by auto\nnext\n  case (Cons a G)\n  then show ?case\n    apply simp\n    apply (case_tac \"\\<forall>y\\<in>set G. \\<forall>i\\<in>enumerate_gexp_inputs y. length (filter (\\<lambda>g. gexp_constrains g (V (I i))) G) \\<le> 1\")\n     defer\n    using each_input_guarded_once_cons apply auto[1]\n    apply (simp add: ball_Un)\n    apply clarsimp\n    apply (induct a)\n        apply simp\n       apply simp\n    subgoal for x2 i ia\n      apply (case_tac x2)\n          apply (rule_tac x=\"list_update i ia x1\" in exI)\n          apply (simp add: apply_guards_cons unconstrained_input filter_empty_conv)\n         apply simp+\n      done\n      apply simp\n    subgoal for _ x2 i ia\n      apply (case_tac x2)\n       apply simp\n      subgoal for aa\n        apply (rule_tac x=\"list_update i ia aa\" in exI)\n        apply (simp add: apply_guards_cons unconstrained_input filter_empty_conv)\n        done\n      done\n    by simp\nqed\n\nlemma \"(SOME x'. x' \\<noteq> (v::value)) \\<noteq> v\"\nproof(induct v)\n  case (Num x)\n  then show ?case\n    by (metis (full_types) someI_ex value.simps(4))\nnext\n  case (Str x)\n  then show ?case\n    by (metis (full_types) someI_ex value.simps(4))\nqed\n\nlemma opposite_gob_subsumption: \"\\<forall>g \\<in> set (Guards t1). \\<exists>i v s. g = Eq (V (I i)) (L v) \\<or> (g = In (I i) s \\<and> s \\<noteq> []) \\<Longrightarrow>\n       \\<forall>g \\<in> set (Guards t2). \\<exists>i v s. g = Eq (V (I i)) (L v) \\<or> (g = In (I i) s \\<and> s \\<noteq> []) \\<Longrightarrow>\n       \\<exists> i. \\<exists>v. Eq (V (I i)) (L v) \\<in> set (Guards t1) \\<and>\n         (\\<forall>g \\<in> set (Guards t2). \\<not> gexp_constrains g (V (I i))) \\<Longrightarrow>\n       Arity t1 = Arity t2 \\<Longrightarrow>\n       \\<forall>i \\<in> enumerate_inputs t2. i < Arity t2 \\<Longrightarrow>\n       \\<forall>i \\<in> enumerate_inputs t2. length (filter (\\<lambda>g. gexp_constrains g (V (I i))) (Guards t2)) \\<le> 1 \\<Longrightarrow>\n       \\<not> subsumes t1 c t2\"\n  apply (rule bad_guards)\n  apply (simp add: enumerate_inputs_def can_take_transition_def can_take_def Bex_def)\n  using literal_args_can_take[of \"Guards t2\" \"Arity t2\" c]\n  apply simp\n  apply clarify\n  subgoal for i ia v\n    apply (rule_tac x=\"list_update ia i (Eps (\\<lambda>x'. x' \\<noteq> v))\" in exI)\n    apply simp\n    apply standard\n     apply (simp add: apply_guards_def)\n    using input_not_constrained_gval_swap_inputs apply simp\n    apply (simp add: apply_guards_def Bex_def)\n    apply (rule_tac x=\"Eq (V (I i)) (L v)\" in exI)\n    apply (simp add: join_ir_def)\n    apply (case_tac \"input2state (ia[i := SOME x'. x' \\<noteq> v]) $ i\")\n     apply simp\n    apply simp\n    apply (case_tac \"i < length ia\")\n     apply (simp add: input2state_nth)\n     apply (case_tac v)\n      apply (metis (mono_tags) someI_ex value.simps(4))\n     apply (metis (mono_tags) someI_ex value.simps(4))\n    by (metis input2state_within_bounds length_list_update)\n  done\n\nfun is_lit_eq :: \"vname gexp \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"is_lit_eq (Eq (V (I i)) (L v)) i' = (i = i')\" |\n  \"is_lit_eq _ _ = False\"\n\nlemma \"(\\<exists>v. Eq (V (I i)) (L v) \\<in> set G) = (\\<exists>g \\<in> set G. is_lit_eq g i)\"\n  by (metis is_lit_eq.elims(2) is_lit_eq.simps(1))\n\nfun is_lit_eq_general :: \"vname gexp \\<Rightarrow> bool\" where\n  \"is_lit_eq_general (Eq (V (I _)) (L _)) = True\" |\n  \"is_lit_eq_general _ = False\"\n\nfun is_input_in :: \"vname gexp \\<Rightarrow> bool\" where\n  \"is_input_in (In (I i) s) = (s \\<noteq> [])\" |\n  \"is_input_in _ = False\"\n\ndefinition \"opposite_gob t1 t2 = (\n       (\\<forall>g \\<in> set (Guards t1). is_lit_eq_general g \\<or> is_input_in g) \\<and>\n       (\\<forall>g \\<in> set (Guards t2). is_lit_eq_general g \\<or> is_input_in g) \\<and>\n       (\\<exists> i \\<in> (enumerate_inputs t1 \\<union> enumerate_inputs t2). (\\<exists>g \\<in> set (Guards t1). is_lit_eq g i) \\<and>\n         (\\<forall>g \\<in> set (Guards t2). \\<not> gexp_constrains g (V (I i)))) \\<and>\n       Arity t1 = Arity t2 \\<and>\n       (\\<forall>i \\<in> enumerate_inputs t2. i < Arity t2) \\<and>\n       (\\<forall>i \\<in> enumerate_inputs t2. length (filter (\\<lambda>g. gexp_constrains g (V (I i))) (Guards t2)) \\<le> 1))\"\n\nlemma \"is_lit_eq_general g \\<or> is_input_in g \\<Longrightarrow>\n       \\<exists>i v s. g = Eq (V (I i)) (L v) \\<or> g = In (I i) s \\<and> s \\<noteq> []\"\n  by (meson is_input_in.elims(2) is_lit_eq_general.elims(2))\n\nlemma opposite_gob_directly_subsumption:\n  \"opposite_gob t1 t2 \\<Longrightarrow> \\<not> subsumes t1 c t2\"\n  apply (rule opposite_gob_subsumption)\n  unfolding opposite_gob_def\n       apply (meson is_input_in.elims(2) is_lit_eq_general.elims(2))+\n     apply (metis is_lit_eq.elims(2))\n  by auto\n\nfun get_in :: \"'a gexp \\<Rightarrow> ('a \\<times> value list) option\" where\n  \"get_in (In v s) = Some (v, s)\" |\n  \"get_in _ = None\"\n\nlemma not_subset_not_in: \"(\\<not> s1 \\<subseteq> s2) = (\\<exists>i. i \\<in> s1 \\<and> i \\<notin> s2)\"\n  by auto\n\nlemma get_in_is: \"(get_in x = Some (v, s1)) = (x = In v s1)\"\n  by (induct x, auto)\n\nlemma gval_rearrange:\n  \"g \\<in> set G \\<Longrightarrow>\n   gval g s = true \\<Longrightarrow>\n   apply_guards (removeAll g G) s \\<Longrightarrow>\n   apply_guards G s\"\nproof(induct G)\n  case (Cons a G)\n  then show ?case\n    apply (simp only: apply_guards_cons)\n    apply standard\n     apply (metis apply_guards_cons removeAll.simps(2))\n    by (metis apply_guards_cons removeAll.simps(2) removeAll_id)\nqed auto\n\nlemma singleton_list: \"(length l = 1) = (\\<exists>e. l = [e])\"\n  by (induct l, auto)\n\nlemma remove_restricted:\n  \"g \\<in> set G \\<Longrightarrow>\n   gexp_constrains g (V v) \\<Longrightarrow>\n   restricted_once v G \\<Longrightarrow>\n   not_restricted v (removeAll g G)\"\n  apply (simp add: restricted_once_def not_restricted_def singleton_list)\n  apply clarify\n  subgoal for e \n    apply (case_tac \"e = g\")\n     defer\n     apply (metis (no_types, lifting) DiffE Diff_insert_absorb Set.set_insert empty_set filter.simps(2) filter_append in_set_conv_decomp insert_iff list.set(2))\n    apply (simp add: filter_empty_conv)\n  proof -\n    fix e :: \"'a gexp\"\n    assume \"filter (\\<lambda>g. gexp_constrains g (V v)) G = [g]\"\n    then have \"{g \\<in> set G. gexp_constrains g (V v)} = {g}\"\n      by (metis (no_types) empty_set list.simps(15) set_filter)\n    then show \"\\<forall>g\\<in>set G - {g}. \\<not> gexp_constrains g (V v)\"\n      by blast\n  qed\n  done\n\nlemma unrestricted_input_swap:\n  \"not_restricted (I i) G \\<Longrightarrow>\n   apply_guards G (join_ir iaa c) \\<Longrightarrow>\n   apply_guards (removeAll g G) (join_ir (iaa[i := ia]) c)\"\nproof(induct G)\n  case (Cons a G)\n  then show ?case\n    apply (simp add: apply_guards_cons not_restricted_def)\n    apply safe\n      apply (meson neq_Nil_conv)\n     apply (metis input_not_constrained_gval_swap_inputs list.distinct(1))\n    by (metis list.distinct(1))\nqed auto\n\nlemma apply_guards_remove_restricted:\n  \"g \\<in> set G \\<Longrightarrow>\n   gexp_constrains g (V (I i)) \\<Longrightarrow>\n   restricted_once (I i) G \\<Longrightarrow>\n   apply_guards G (join_ir iaa c) \\<Longrightarrow>\n   apply_guards (removeAll g G) (join_ir (iaa[i := ia]) c)\"\nproof(induct G)\n  case (Cons a G)\n  then show ?case\n    apply simp\n    apply safe\n      apply (rule unrestricted_input_swap)\n       apply (simp add: not_restricted_def restricted_once_def)\n      apply (meson apply_guards_subset set_subset_Cons)\n     apply (simp add: apply_guards_rearrange not_restricted_def restricted_once_def unrestricted_input_swap)\n    by (metis apply_guards_cons filter.simps(2) filter_empty_conv input_not_constrained_gval_swap_inputs list.inject restricted_once_def singleton_list)\nqed auto\n\nlemma In_swap_inputs:\n  \"In (I i) s2 \\<in> set G \\<Longrightarrow>\n   restricted_once (I i) G \\<Longrightarrow>\n   ia \\<in> set s2 \\<Longrightarrow>\n   apply_guards G (join_ir iaa c) \\<Longrightarrow>\n   apply_guards G (join_ir (iaa[i := ia]) c)\"\n  using apply_guards_remove_restricted[of \"In (I i) s2\" G i iaa c ia]\n  apply simp\n  apply (rule gval_rearrange[of \"In (I i) s2\"])\n    apply simp\n   apply (metis filter_empty_conv gval_each_one input_not_constrained_gval_swap_inputs length_0_conv not_restricted_def remove_restricted test_aux)\n  by blast\n\ndefinition these :: \"'a option list \\<Rightarrow> 'a list\" where\n  \"these as = map (\\<lambda>x. case x of Some y \\<Rightarrow> y) (filter (\\<lambda>x. x \\<noteq> None) as)\"\n\nlemma these_cons: \"these (a#as) = (case a of None \\<Rightarrow> these as | Some x \\<Rightarrow> x#(these as))\"\n  apply (cases a)\n   apply (simp add: these_def)\n  by (simp add: these_def)\n\ndefinition get_ins :: \"vname gexp list \\<Rightarrow> (nat \\<times> value list) list\" where\n  \"get_ins g = map (\\<lambda>(v, s). case v of I i \\<Rightarrow> (i, s)) (filter (\\<lambda>(v, _). case v of I _ \\<Rightarrow> True | R _ \\<Rightarrow> False) (these (map get_in g)))\"\n\nlemma in_get_ins:\n  \"(I x1a, b) \\<in> set (these (map get_in G)) \\<Longrightarrow>\n   In (I x1a) b \\<in> set G\"\nproof(induct G)\n  case Nil\n  then show ?case\n    by (simp add: these_def)\nnext\n  case (Cons a G)\n  then show ?case\n    apply simp\n    apply (simp add: these_cons)\n    apply (cases a)\n    by auto\nqed\n\nlemma restricted_head: \"\\<forall>v. restricted_once v (Eq (V x2) (L x1) # G) \\<or> not_restricted v (Eq (V x2) (L x1) # G) \\<Longrightarrow>\n      not_restricted x2 G\"\n  apply (erule_tac x=x2 in allE)\n  by (simp add: restricted_once_def not_restricted_def)\n\nfun atomic :: \"'a gexp \\<Rightarrow> bool\" where\n  \"atomic (Eq (V _) (L _)) = True\" |\n  \"atomic (In _ _) = True\" |\n  \"atomic _ = False\"\n\nlemma restricted_max_once_cons: \"\\<forall>v. restricted_once v (g#gs) \\<or> not_restricted v (g#gs) \\<Longrightarrow>\n       \\<forall>v. restricted_once v gs \\<or> not_restricted v gs\"\n  apply (simp add: restricted_once_def not_restricted_def)\n  apply safe\n  subgoal for v \n    by (erule_tac x=v in allE)\n      (metis (mono_tags, lifting) list.distinct(1) list.inject singleton_list)\n  done\n\nlemma not_restricted_swap_inputs:\n  \"not_restricted (I x1a) G \\<Longrightarrow>\n   apply_guards G (join_ir i r) \\<Longrightarrow>\n   apply_guards G (join_ir (i[x1a := x1]) r)\"\nproof(induct G)\n  case (Cons a G)\n  then show ?case\n    apply (simp add: apply_guards_cons not_restricted_cons)\n    using input_not_constrained_gval_swap_inputs by auto\nqed auto\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Extended_Finite_State_Machine_Inference/heuristics/Least_Upper_Bound.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES\n\n", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.25392142869728274}}
{"text": "theory GallopA\n  imports \"Simpl/Vcg\" Main \"~~/src/HOL/Library/Code_Target_Numeral\" \"TimSortLemma\" \"TimSortProc\"\nbegin\n\n\n\nlemma (in gallop_left_impl) gallop_left_modifies:\n  shows\n  \"\\<forall> \\<sigma>. \\<Gamma>\\<turnstile> {\\<sigma>} \\<acute>ret:== PROC gallop_left(\\<acute>key, \\<acute>array, \\<acute>base, \\<acute>len, \\<acute>hint)\n            {t. t may_only_modify_globals \\<sigma> in []}\"\n  apply (hoare_rule HoarePartial.ProcRec1)\n  apply (vcg spec=modifies)\n  done\n\nlemma (in gallop_right_impl) gallop_right_modifies:\n  shows\n  \"\\<forall> \\<sigma>. \\<Gamma>\\<turnstile> {\\<sigma>} \\<acute>ret:== PROC gallop_right(\\<acute>key, \\<acute>array, \\<acute>base, \\<acute>len, \\<acute>hint)\n            {t. t may_only_modify_globals \\<sigma> in []}\"\n  apply (hoare_rule HoarePartial.ProcNoRec1)\n  apply (vcg spec=modifies)\n  done\n\nlemma (in merge_lo_impl) merge_lo_modifies:\n  shows\n  \"\\<forall> \\<sigma>. \\<Gamma>\\<turnstile> {\\<sigma>} PROC merge_lo(\\<acute>base1, \\<acute>len1, \\<acute>base2, \\<acute>len2)\n            {t. t may_only_modify_globals \\<sigma> in [a]}\"\n  apply (hoare_rule HoarePartial.ProcNoRec1)\n  apply (vcg spec=modifies)\n  done\n\nlemma (in merge_hi_impl) merge_hi_modifies:\n  shows\n  \"\\<forall> \\<sigma>. \\<Gamma>\\<turnstile> {\\<sigma>} PROC merge_hi(\\<acute>base1, \\<acute>len1, \\<acute>base2, \\<acute>len2)\n            {t. t may_only_modify_globals \\<sigma> in [a]}\"\n  apply (hoare_rule HoarePartial.ProcNoRec1)\n  apply (vcg spec=modifies)\n  done\n\nlemma (in gallop_left_impl) gallop_left_spec:\n  shows\n  \"\\<forall>\\<sigma>. \\<Gamma>\\<turnstile> \\<lbrace> \\<sigma>. \\<acute>array\\<noteq>[] \\<and> \\<acute>base\\<ge>0 \\<and> \\<acute>len>0 \\<and> \\<acute>hint<\\<acute>len \\<and> \\<acute>base+\\<acute>len\\<le>length \\<acute>array\\<rbrace>\n  \\<acute>ret :== PROC gallop_left(\\<acute>key, \\<acute>array, \\<acute>base, \\<acute>len, \\<acute>hint)\n  \\<lbrace> \\<acute>ret \\<ge>0 \\<and> \\<acute>ret \\<le>\\<acute>len \\<and> \\<acute>len = \\<^bsup>\\<sigma>\\<^esup>len\\<rbrace>\"\n  apply (hoare_rule HoarePartial.ProcNoRec1)\n  apply (hoare_rule anno=\"\n          \\<acute>last_ofs :== 0;; \\<acute>ofs :== 1;;\n            IF \\<acute>array ! (\\<acute>base + \\<acute>hint) < \\<acute>key\n            THEN \\<acute>max_ofs :== \\<acute>len - \\<acute>hint;;\n              WHILE \\<acute>ofs < \\<acute>max_ofs \\<and> \\<acute>array ! (\\<acute>base + \\<acute>hint + \\<acute>ofs) < \\<acute>key \n              INV \\<lbrace> \\<acute>ofs>0 \\<and> \\<acute>last_ofs\\<ge>0 \\<and> \\<acute>last_ofs<\\<acute>ofs \\<and> \\<acute>last_ofs<\\<acute>max_ofs \\<and>\n                    \\<acute>base = \\<^bsup>\\<sigma>\\<^esup>base \\<and> \\<acute>len = \\<^bsup>\\<sigma>\\<^esup>len \\<and> \\<acute>hint = \\<^bsup>\\<sigma>\\<^esup>hint \\<and> \\<acute>hint<\\<acute>len \\<and>\n                    \\<acute>max_ofs = \\<acute>len-\\<acute>hint \\<rbrace>\n              DO \\<acute>last_ofs :== \\<acute>ofs;; \\<acute>ofs :== \\<acute>ofs + \\<acute>ofs + 1 OD;;\n              IF \\<acute>max_ofs < \\<acute>ofs THEN \\<acute>ofs :== \\<acute>max_ofs FI;; \\<acute>last_ofs :== \\<acute>last_ofs + \\<acute>hint + 1;; \\<acute>ofs :== \\<acute>ofs + \\<acute>hint\n            ELSE \\<acute>max_ofs :== \\<acute>hint + 1;;\n              WHILE \\<acute>ofs < \\<acute>max_ofs \\<and> \\<acute>key \\<le> \\<acute>array ! (\\<acute>base + \\<acute>hint - \\<acute>ofs) \n              INV \\<lbrace> \\<acute>ofs>0 \\<and> \\<acute>last_ofs\\<ge>0 \\<and> \\<acute>last_ofs<\\<acute>ofs \\<and> \\<acute>last_ofs<\\<acute>max_ofs \\<and>\n                    \\<acute>base = \\<^bsup>\\<sigma>\\<^esup>base \\<and>  \\<acute>len = \\<^bsup>\\<sigma>\\<^esup>len \\<and> \\<acute>hint = \\<^bsup>\\<sigma>\\<^esup>hint \\<and> \\<acute>hint<\\<acute>len \\<rbrace>\n              DO \\<acute>last_ofs :== \\<acute>ofs;; \\<acute>ofs :== \\<acute>ofs + \\<acute>ofs + 1 OD;;\n              IF \\<acute>max_ofs < \\<acute>ofs THEN \\<acute>ofs :== \\<acute>max_ofs FI;; \\<acute>tmp_gallop :== \\<acute>last_ofs;; \\<acute>last_ofs :== \\<acute>hint + 1 - \\<acute>ofs;;\n              \\<acute>ofs :== \\<acute>hint - \\<acute>tmp_gallop\n            FI;;\n            WHILE \\<acute>last_ofs < \\<acute>ofs \n            INV \\<lbrace> \\<acute>last_ofs\\<ge>0 \\<and> \\<acute>last_ofs\\<le>\\<acute>ofs \\<and> \\<acute>ofs\\<le>\\<acute>len \\<and>\n                  \\<acute>last_ofs \\<le> (\\<acute>ofs+\\<acute>last_ofs)div 2 \\<and> \\<acute>ofs \\<ge> (\\<acute>ofs+\\<acute>last_ofs)div 2 \\<and>\n                  \\<acute>len = \\<^bsup>\\<sigma>\\<^esup>len \\<and> \\<acute>base = \\<^bsup>\\<sigma>\\<^esup>base \\<rbrace>\n            DO \\<acute>mid :== (\\<acute>ofs + \\<acute>last_ofs) div 2;; IF \\<acute>array ! (\\<acute>base + \\<acute>mid) < \\<acute>key THEN \\<acute>last_ofs :== \\<acute>mid + 1 ELSE \\<acute>ofs :== \\<acute>mid FI OD;;\n            \\<acute>ret :== \\<acute>ofs\n        \" in HoarePartial.annotateI)\n  apply vcg\n  by auto \n  \n\nlemma (in gallop_right_impl) gallop_right_spec:\n  shows\n  \"\\<forall>\\<sigma>. \\<Gamma>\\<turnstile> \\<lbrace> \\<sigma>. \\<acute>array\\<noteq>[] \\<and> \\<acute>base\\<ge>0 \\<and> \\<acute>len>0 \\<and> \\<acute>hint<\\<acute>len \\<and> \\<acute>base+\\<acute>len\\<le>length \\<acute>array\\<rbrace>\n  \\<acute>ret :== PROC gallop_right(\\<acute>key, \\<acute>array, \\<acute>base, \\<acute>len, \\<acute>hint)\n  \\<lbrace> \\<acute>ret \\<ge>0 \\<and> \\<acute>ret \\<le>\\<acute>len \\<and> \\<acute>len = \\<^bsup>\\<sigma>\\<^esup>len\\<rbrace>\"\n  apply (hoare_rule HoarePartial.ProcNoRec1)\n  apply (hoare_rule anno=\"\n         \\<acute>last_ofs :== 0;; \\<acute>ofs :== 1;;\n            IF \\<acute>key < \\<acute>array ! (\\<acute>base + \\<acute>hint)\n            THEN \\<acute>max_ofs :== \\<acute>hint + 1;;\n              WHILE \\<acute>ofs < \\<acute>max_ofs \\<and> \\<acute>key < \\<acute>array ! (\\<acute>base + \\<acute>hint - \\<acute>ofs)\n              INV \\<lbrace> \\<acute>ofs>0 \\<and> \\<acute>last_ofs\\<ge>0 \\<and> \\<acute>last_ofs<\\<acute>ofs \\<and> \\<acute>last_ofs<\\<acute>max_ofs \\<and>\n                    \\<acute>base = \\<^bsup>\\<sigma>\\<^esup>base \\<and>  \\<acute>len = \\<^bsup>\\<sigma>\\<^esup>len \\<and> \\<acute>hint = \\<^bsup>\\<sigma>\\<^esup>hint \\<and> \\<acute>hint<\\<acute>len\n                    \\<rbrace> \n              DO \\<acute>last_ofs :== \\<acute>ofs;; \\<acute>ofs :== \\<acute>ofs + \\<acute>ofs + 1 OD;;\n              IF \\<acute>max_ofs < \\<acute>ofs THEN \\<acute>ofs :== \\<acute>max_ofs FI;;\n              \\<acute>tmp_gallop :== \\<acute>last_ofs;; \\<acute>last_ofs :== \\<acute>hint + 1 - \\<acute>ofs;;\n              \\<acute>ofs :== \\<acute>hint - \\<acute>tmp_gallop\n            ELSE \\<acute>max_ofs :== \\<acute>len - \\<acute>hint;;\n              WHILE \\<acute>ofs < \\<acute>max_ofs \\<and> \\<acute>array ! (\\<acute>base + \\<acute>hint + \\<acute>ofs) \\<le> \\<acute>key\n              INV \\<lbrace> \\<acute>ofs>0 \\<and> \\<acute>last_ofs\\<ge>0 \\<and> \\<acute>last_ofs<\\<acute>ofs \\<and> \\<acute>last_ofs<\\<acute>max_ofs \\<and>\n                    \\<acute>base = \\<^bsup>\\<sigma>\\<^esup>base \\<and> \\<acute>len = \\<^bsup>\\<sigma>\\<^esup>len \\<and> \\<acute>hint = \\<^bsup>\\<sigma>\\<^esup>hint \\<and> \\<acute>hint<\\<acute>len \\<and>\n                    \\<acute>max_ofs = \\<acute>len-\\<acute>hint \\<rbrace> \n              DO \\<acute>last_ofs :== \\<acute>ofs;; \\<acute>ofs :== \\<acute>ofs + \\<acute>ofs + 1 OD;;\n              IF \\<acute>max_ofs < \\<acute>ofs THEN \\<acute>ofs :== \\<acute>max_ofs FI;;\n              \\<acute>last_ofs :== \\<acute>last_ofs + \\<acute>hint + 1;; \\<acute>ofs :== \\<acute>ofs + \\<acute>hint\n            FI;;\n            WHILE \\<acute>last_ofs < \\<acute>ofs \n            INV \\<lbrace> \\<acute>last_ofs\\<ge>0 \\<and> \\<acute>last_ofs\\<le>\\<acute>ofs \\<and> \\<acute>ofs\\<le>\\<acute>len \\<and>\n                  \\<acute>last_ofs \\<le> (\\<acute>ofs+\\<acute>last_ofs)div 2 \\<and> \\<acute>ofs \\<ge> (\\<acute>ofs+\\<acute>last_ofs)div 2 \\<and>\n                  \\<acute>len = \\<^bsup>\\<sigma>\\<^esup>len \\<and> \\<acute>base = \\<^bsup>\\<sigma>\\<^esup>base \\<rbrace>\n            DO \\<acute>mid :== (\\<acute>ofs + \\<acute>last_ofs) div 2;;\n               IF \\<acute>key < \\<acute>array ! (\\<acute>base + \\<acute>mid) THEN \\<acute>ofs :== \\<acute>mid\n               ELSE \\<acute>last_ofs :== \\<acute>mid+1 FI \n            OD;;\n            \\<acute>ret :== \\<acute>ofs\n      \" in HoarePartial.annotateI)\n   apply vcg\n   by auto  \n\n\n\n lemma (in merge_lo_impl) merge_lo_spec:\n  shows\n  \"\\<forall>\\<sigma>. \\<Gamma>\\<turnstile> \\<lbrace> \\<sigma>. \\<acute>base1\\<ge>0 \\<and> \\<acute>len1>0 \\<and> \\<acute>len2>0 \\<and> \\<acute>len1\\<le>\\<acute>len2 \\<and> \n          (\\<acute>base1+\\<acute>len1 = \\<acute>base2) \\<and> (\\<acute>base2+\\<acute>len2 \\<le> length \\<acute>a)\\<rbrace>\n  PROC merge_lo(\\<acute>base1, \\<acute>len1, \\<acute>base2, \\<acute>len2)\n  \\<lbrace>length \\<acute>a = length \\<^bsup>\\<sigma>\\<^esup>a\\<rbrace>\"\n  apply (hoare_rule HoarePartial.ProcNoRec1)\n  apply (hoare_rule anno=\"\n      TRY\n  \\<acute>tmp :== replicate \\<acute>len1 (0::int);;\n  \\<acute>tmp :== list_copy \\<acute>tmp (0::nat) \\<acute>a \\<acute>base1 \\<acute>len1;;\n  \\<acute>cursor1 :== 0;;\n  \\<acute>cursor2 :==\\<acute>base2;;\n  \\<acute>dest :== \\<acute>base1;;\n  \\<acute>a!\\<acute>dest :== \\<acute>a!\\<acute>cursor2;;\n  \\<acute>dest :== \\<acute>dest+1;;\n  \\<acute>cursor2 :== \\<acute>cursor2+1;;\n  \\<acute>len2 :== \\<acute>len2-1;;\n  \\<acute>min_gallop :== \\<acute>global_min_gallop;;(* need to add min gallop to globals var *)\n  IF \\<acute>len2=0 THEN \\<acute>a :== list_copy \\<acute>a \\<acute>dest \\<acute>tmp \\<acute>cursor1 \\<acute>len1;; THROW FI;;\n  IF \\<acute>len1=1 THEN \\<acute>a :== list_copy \\<acute>a \\<acute>dest \\<acute>a \\<acute>cursor2 \\<acute>len2;; \\<acute>a!(\\<acute>dest+\\<acute>len2):== \\<acute>tmp!\\<acute>cursor1;;THROW FI;;\n  TRY\n    WHILE True \n    INV \\<lbrace> \\<acute>cursor1\\<ge>0 \\<and> \\<acute>cursor2\\<ge>\\<acute>base2 \\<and>\n          \\<acute>len1>1 \\<and> \\<acute>len2>0 \\<and>\n           \\<acute>cursor1+\\<acute>len1 = \\<^bsup>\\<sigma>\\<^esup>len1 \\<and>\n           \\<acute>cursor2+\\<acute>len2 = \\<acute>base2+\\<^bsup>\\<sigma>\\<^esup>len2 \\<and>\n           \\<acute>dest+\\<acute>len1 = \\<acute>cursor2 \\<and>\n           \\<acute>base1 = \\<^bsup>\\<sigma>\\<^esup>base1 \\<and>\n           \\<acute>base2 = \\<^bsup>\\<sigma>\\<^esup>base2 \\<and>\n           length \\<acute>tmp = \\<^bsup>\\<sigma>\\<^esup>len1 \\<and>\n           length \\<acute>a = length \\<^bsup>\\<sigma>\\<^esup>a \\<and>\n           (\\<^bsup>\\<sigma>\\<^esup>base2+\\<^bsup>\\<sigma>\\<^esup>len2 \\<le> length \\<^bsup>\\<sigma>\\<^esup>a) \\<rbrace>\n    DO\n      \\<acute>count1 :== 0;;\n      \\<acute>count2 :== 0;;\n      WHILE (\\<acute>count1 < \\<acute>min_gallop & \\<acute>count2 < \\<acute>min_gallop)\n      INV \\<lbrace> \\<acute>cursor1\\<ge>0 \\<and> \\<acute>cursor2\\<ge>\\<acute>base2 \\<and>\n       \\<acute>len1>1 \\<and> \\<acute>len2>0 \\<and>\n       \\<acute>cursor1+\\<acute>len1 = \\<^bsup>\\<sigma>\\<^esup>len1 \\<and>\n       \\<acute>cursor2+\\<acute>len2 = \\<acute>base2+\\<^bsup>\\<sigma>\\<^esup>len2 \\<and>\n       \\<acute>dest+\\<acute>len1 = \\<acute>cursor2 \\<and>\n       \\<acute>base1 = \\<^bsup>\\<sigma>\\<^esup>base1 \\<and>\n       \\<acute>base2 = \\<^bsup>\\<sigma>\\<^esup>base2 \\<and>\n       length \\<acute>tmp = \\<^bsup>\\<sigma>\\<^esup>len1 \\<and>\n       length \\<acute>a = length \\<^bsup>\\<sigma>\\<^esup>a \\<and>\n       (\\<^bsup>\\<sigma>\\<^esup>base2+\\<^bsup>\\<sigma>\\<^esup>len2 \\<le> length \\<^bsup>\\<sigma>\\<^esup>a) \\<rbrace>\n      DO\n        IF \\<acute>a!\\<acute>cursor2 < \\<acute>tmp!\\<acute>cursor1\n        THEN\n          \\<acute>a!\\<acute>dest :== \\<acute>a!\\<acute>cursor2;;\n          \\<acute>dest :== \\<acute>dest+1;;\n          \\<acute>cursor2 :== \\<acute>cursor2+1;;\n          \\<acute>count2 :== \\<acute>count2+1;;\n          \\<acute>count1 :== 0;;\n          \\<acute>len2 :== \\<acute>len2-1;;\n          IF \\<acute>len2 = 0 THEN THROW FI\n        ELSE\n          \\<acute>a!\\<acute>dest :== \\<acute>tmp!\\<acute>cursor1;;\n          \\<acute>dest :== \\<acute>dest+1;;\n          \\<acute>cursor1 :== \\<acute>cursor1+1;;\n          \\<acute>count1 :== \\<acute>count1+1;;\n          \\<acute>count2 :== 0;;\n          \\<acute>len1 :== \\<acute>len1-1;;\n          IF \\<acute>len1 = 1 THEN THROW FI\n        FI\n      OD;;\n      WHILE (\\<acute>count1 \\<ge> \\<acute>global_min_gallop | \\<acute>count2 \\<ge> \\<acute>global_min_gallop)\n      INV \\<lbrace> \\<acute>cursor1\\<ge>0 \\<and> \\<acute>cursor2\\<ge>\\<acute>base2 \\<and>\n      \\<acute>len1>1 \\<and> \\<acute>len2>0 \\<and>\n      \\<acute>cursor1+\\<acute>len1 = \\<^bsup>\\<sigma>\\<^esup>len1 \\<and>\n      \\<acute>cursor2+\\<acute>len2 = \\<acute>base2+\\<^bsup>\\<sigma>\\<^esup>len2 \\<and>\n      \\<acute>dest+\\<acute>len1 = \\<acute>cursor2 \\<and>\n      \\<acute>base1 = \\<^bsup>\\<sigma>\\<^esup>base1 \\<and>\n      \\<acute>base2 = \\<^bsup>\\<sigma>\\<^esup>base2 \\<and>\n      length \\<acute>tmp = \\<^bsup>\\<sigma>\\<^esup>len1 \\<and>\n      length \\<acute>a = length \\<^bsup>\\<sigma>\\<^esup>a \\<and>\n      (\\<^bsup>\\<sigma>\\<^esup>base2+\\<^bsup>\\<sigma>\\<^esup>len2 \\<le> length \\<^bsup>\\<sigma>\\<^esup>a) \\<rbrace>\n      DO\n        \\<acute>count1 :== CALL gallop_right(\\<acute>a!\\<acute>cursor2, \\<acute>tmp, \\<acute>cursor1, \\<acute>len1, 0);;\n        IF \\<acute>count1 \\<noteq> 0\n        THEN\n          \\<acute>a :== list_copy \\<acute>a \\<acute>dest \\<acute>tmp \\<acute>cursor1 \\<acute>count1;;\n          \\<acute>dest :== \\<acute>dest+\\<acute>count1;;\n          \\<acute>cursor1 :== \\<acute>cursor1+\\<acute>count1;;\n          \\<acute>len1 :== \\<acute>len1-\\<acute>count1;;\n          IF \\<acute>len1\\<le>1 THEN THROW FI\n        FI;;\n        \\<acute>a!\\<acute>dest :== \\<acute>a!\\<acute>cursor2;;\n        \\<acute>dest :== \\<acute>dest+1;;\n        \\<acute>cursor2 :== \\<acute>cursor2+1;;\n        \\<acute>len2 :== \\<acute>len2-1;;\n        IF \\<acute>len2 = 0 THEN THROW FI;;\n\n        \\<acute>count2 :== CALL gallop_left(\\<acute>tmp!\\<acute>cursor1, \\<acute>a, \\<acute>cursor2, \\<acute>len2, 0);;\n        IF \\<acute>count2 \\<noteq> 0\n        THEN\n          \\<acute>a :== list_copy \\<acute>a \\<acute>dest \\<acute>a \\<acute>cursor2 \\<acute>count2;;\n          \\<acute>dest :== \\<acute>dest+\\<acute>count2;;\n          \\<acute>cursor2 :== \\<acute>cursor2+\\<acute>count2;;\n          \\<acute>len2 :== \\<acute>len2-\\<acute>count2;;\n          IF \\<acute>len2 = 0 THEN THROW FI\n        FI;;\n        \\<acute>a!\\<acute>dest :== \\<acute>tmp!\\<acute>cursor1;;\n        \\<acute>dest :== \\<acute>dest+1;;\n        \\<acute>cursor1 :== \\<acute>cursor1+1;;\n        \\<acute>len1 :== \\<acute>len1-1;;\n        IF \\<acute>len1 = 1 THEN THROW FI;;\n        \\<acute>min_gallop :== \\<acute>min_gallop-1\n      OD;;\n      IF \\<acute>min_gallop < 0 THEN \\<acute>min_gallop :== 0 FI;;\n      \\<acute>min_gallop :== \\<acute>min_gallop + 2\n    OD\n  CATCH\n  Skip\n  END;;\n  IF \\<acute>len1 = 1\n  THEN \\<acute>a :== list_copy \\<acute>a \\<acute>dest \\<acute>a \\<acute>cursor2 \\<acute>len2;;\\<acute>a!(\\<acute>dest+\\<acute>len2) :== \\<acute>tmp!\\<acute>cursor1\n  ELSE IF \\<acute>len1 = 0\n       THEN Skip\n       ELSE \\<acute>a :== list_copy \\<acute>a \\<acute>dest \\<acute>tmp \\<acute>cursor1 \\<acute>len1 \n       FI\n  FI\nCATCH\nSkip\nEND\" in HoarePartial.annotateI)\n apply vcg\n         apply (simp_all add:Suc_lessI)\n   apply (auto simp add:list_copy_def)\ndone \n\n\n\n\nlemma (in merge_hi_impl) merge_hi_spec:\n  shows\n  \"\\<forall>\\<sigma>. \\<Gamma>\\<turnstile> \\<lbrace> \\<sigma>. \\<acute>base1\\<ge>0 \\<and> \\<acute>len1>0 \\<and> \\<acute>len2>0 \\<and> \\<acute>len1\\<ge>\\<acute>len2 \\<and> \n          (\\<acute>base1+\\<acute>len1 = \\<acute>base2) \\<and> (\\<acute>base2+\\<acute>len2 \\<le> length \\<acute>a)\\<rbrace>\n  PROC merge_hi(\\<acute>base1, \\<acute>len1, \\<acute>base2, \\<acute>len2)\n  \\<lbrace>length \\<acute>a = length \\<^bsup>\\<sigma>\\<^esup>a \\<rbrace>\"\n  apply (hoare_rule HoarePartial.ProcNoRec1)\n  apply (hoare_rule anno=\"\n                TRY\n  \\<acute>tmp :== replicate \\<acute>len2 (0::int);;\n  \\<acute>tmp :== list_copy \\<acute>tmp (0::nat) \\<acute>a \\<acute>base2 \\<acute>len2;;\n  \\<acute>cursor1 :== \\<acute>base1+\\<acute>len1-1;;\n  \\<acute>cursor2 :==\\<acute>len2-1;;\n  \\<acute>dest :== \\<acute>base2+\\<acute>len2-1;;\n  \\<acute>a!\\<acute>dest :== \\<acute>a!\\<acute>cursor1;;\n  \\<acute>dest :== \\<acute>dest-1;;\n  \\<acute>cursor1 :== \\<acute>cursor1-1;;\n  \\<acute>len1 :== \\<acute>len1-1;;\n  \\<acute>min_gallop :== \\<acute>global_min_gallop;;(* need to add min gallop to globals var *)\n  IF \\<acute>len1=0 THEN \\<acute>a :== list_copy \\<acute>a (\\<acute>dest-(\\<acute>len2-1)) \\<acute>tmp 0 \\<acute>len2;; THROW FI;;\n  IF \\<acute>len2=1 \n  THEN \n    \\<acute>dest :== \\<acute>dest-\\<acute>len1;;\n    \\<acute>cursor1 :== \\<acute>cursor1-\\<acute>len1;;\n    \\<acute>a :== list_copy \\<acute>a (\\<acute>dest+1) \\<acute>a (\\<acute>cursor1+1) \\<acute>len1;; \n    \\<acute>a!\\<acute>dest:== \\<acute>tmp!\\<acute>cursor2;;\n    THROW \n  FI;;\n  TRY\n    WHILE True \n    INV \\<lbrace> \\<acute>len1>0 \\<and> \\<acute>len1<\\<^bsup>\\<sigma>\\<^esup>len1 \\<and>\n       \\<acute>len2>1 \\<and> \\<acute>len2\\<le>\\<^bsup>\\<sigma>\\<^esup>len2 \\<and>\n       \\<acute>cursor1+1=\\<acute>base1+\\<acute>len1 \\<and>\n       \\<acute>cursor2+1=\\<acute>len2 \\<and>\n       \\<acute>dest=\\<acute>cursor1+\\<acute>len2 \\<and>\n       \\<acute>base1 = \\<^bsup>\\<sigma>\\<^esup>base1 \\<and>\n       \\<acute>base2 = \\<^bsup>\\<sigma>\\<^esup>base2 \\<and>\n       length \\<acute>tmp = \\<^bsup>\\<sigma>\\<^esup>len2 \\<and>\n       length \\<acute>a = length \\<^bsup>\\<sigma>\\<^esup>a \\<and>\n       (\\<^bsup>\\<sigma>\\<^esup>base2+\\<^bsup>\\<sigma>\\<^esup>len2 \\<le> length \\<^bsup>\\<sigma>\\<^esup>a) \\<and>\n       (\\<^bsup>\\<sigma>\\<^esup>base1+\\<^bsup>\\<sigma>\\<^esup>len1 = \\<^bsup>\\<sigma>\\<^esup>base2) \\<and>\n       length \\<acute>a = length \\<^bsup>\\<sigma>\\<^esup>a \\<and>\n       (\\<^bsup>\\<sigma>\\<^esup>base2+\\<^bsup>\\<sigma>\\<^esup>len2 \\<le> length \\<^bsup>\\<sigma>\\<^esup>a)\\<rbrace>\n    DO\n      \\<acute>count1 :== 0;;\n      \\<acute>count2 :== 0;;\n      WHILE (\\<acute>count1 < \\<acute>min_gallop & \\<acute>count2 < \\<acute>min_gallop)\n      INV \\<lbrace> \\<acute>len1>0 \\<and> \\<acute>len1<\\<^bsup>\\<sigma>\\<^esup>len1 \\<and>\n      \\<acute>len2>1 \\<and> \\<acute>len2\\<le>\\<^bsup>\\<sigma>\\<^esup>len2 \\<and>\n       \\<acute>cursor1+1=\\<acute>base1+\\<acute>len1 \\<and>\n       \\<acute>cursor2+1=\\<acute>len2 \\<and>\n       \\<acute>dest=\\<acute>cursor1+\\<acute>len2 \\<and>\n       \\<acute>base1 = \\<^bsup>\\<sigma>\\<^esup>base1 \\<and>\n       \\<acute>base2 = \\<^bsup>\\<sigma>\\<^esup>base2 \\<and>\n       length \\<acute>tmp = \\<^bsup>\\<sigma>\\<^esup>len2 \\<and>\n       length \\<acute>a = length \\<^bsup>\\<sigma>\\<^esup>a \\<and>\n       (\\<^bsup>\\<sigma>\\<^esup>base2+\\<^bsup>\\<sigma>\\<^esup>len2 \\<le> length \\<^bsup>\\<sigma>\\<^esup>a) \\<and>\n       (\\<^bsup>\\<sigma>\\<^esup>base1+\\<^bsup>\\<sigma>\\<^esup>len1 = \\<^bsup>\\<sigma>\\<^esup>base2)\\<and>\n       length \\<acute>a = length \\<^bsup>\\<sigma>\\<^esup>a \\<and>\n       (\\<^bsup>\\<sigma>\\<^esup>base2+\\<^bsup>\\<sigma>\\<^esup>len2 \\<le> length \\<^bsup>\\<sigma>\\<^esup>a) \\<rbrace>\n      DO\n        IF \\<acute>tmp!\\<acute>cursor2 < \\<acute>a!\\<acute>cursor1\n        THEN\n          \\<acute>a!\\<acute>dest :== \\<acute>a!\\<acute>cursor1;;\n          \\<acute>dest :== \\<acute>dest-1;;\n          \\<acute>cursor1 :== \\<acute>cursor1-1;;\n          \\<acute>count1 :== \\<acute>count1+1;;\n          \\<acute>count2 :== 0;;\n          \\<acute>len1 :== \\<acute>len1-1;;\n          IF \\<acute>len1 = 0 THEN THROW FI\n        ELSE\n          \\<acute>a!\\<acute>dest :== \\<acute>tmp!\\<acute>cursor2;;\n          \\<acute>dest :== \\<acute>dest-1;;\n          \\<acute>cursor2 :== \\<acute>cursor2-1;;\n          \\<acute>count2 :== \\<acute>count2+1;;\n          \\<acute>count1 :== 0;;\n          \\<acute>len2 :== \\<acute>len2-1;;\n          IF \\<acute>len2 = 1 THEN THROW FI\n        FI\n      OD;;\n      WHILE (\\<acute>count1 \\<ge> \\<acute>global_min_gallop | \\<acute>count2 \\<ge> \\<acute>global_min_gallop)\n      INV \\<lbrace> \\<acute>len1>0 \\<and> \\<acute>len1<\\<^bsup>\\<sigma>\\<^esup>len1 \\<and>\n       \\<acute>len2>1 \\<and> \\<acute>len2\\<le>\\<^bsup>\\<sigma>\\<^esup>len2 \\<and>\n       \\<acute>cursor1+1=\\<acute>base1+\\<acute>len1 \\<and>\n       \\<acute>cursor2+1=\\<acute>len2 \\<and>\n       \\<acute>dest=\\<acute>cursor1+\\<acute>len2 \\<and>\n       \\<acute>base1 = \\<^bsup>\\<sigma>\\<^esup>base1 \\<and>\n       \\<acute>base2 = \\<^bsup>\\<sigma>\\<^esup>base2 \\<and>\n       length \\<acute>tmp = \\<^bsup>\\<sigma>\\<^esup>len2 \\<and>\n       length \\<acute>a = length \\<^bsup>\\<sigma>\\<^esup>a \\<and>\n       (\\<^bsup>\\<sigma>\\<^esup>base2+\\<^bsup>\\<sigma>\\<^esup>len2 \\<le> length \\<^bsup>\\<sigma>\\<^esup>a) \\<and>\n       (\\<^bsup>\\<sigma>\\<^esup>base1+\\<^bsup>\\<sigma>\\<^esup>len1 = \\<^bsup>\\<sigma>\\<^esup>base2) \\<and>\n       length \\<acute>a = length \\<^bsup>\\<sigma>\\<^esup>a \\<and>\n       (\\<^bsup>\\<sigma>\\<^esup>base2+\\<^bsup>\\<sigma>\\<^esup>len2 \\<le> length \\<^bsup>\\<sigma>\\<^esup>a) \\<rbrace>\n      DO\n        \\<acute>count_tmp :==  CALL gallop_right(\\<acute>tmp!\\<acute>cursor2, \\<acute>a, \\<acute>base1, \\<acute>len1, \\<acute>len1-1);;\n        \\<acute>count1 :== \\<acute>len1 - \\<acute>count_tmp;;\n        IF \\<acute>count1 \\<noteq> 0\n        THEN\n          \\<acute>dest :== \\<acute>dest-\\<acute>count1;;\n          \\<acute>cursor1 :== \\<acute>cursor1-\\<acute>count1;;\n          \\<acute>len1 :== \\<acute>len1-\\<acute>count1;;\n          \\<acute>a :== list_copy \\<acute>a (\\<acute>dest+1) \\<acute>a (\\<acute>cursor1+1) \\<acute>count1;;\n          IF \\<acute>len1=0 THEN THROW FI\n        FI;;\n        \\<acute>a!\\<acute>dest :== \\<acute>tmp!\\<acute>cursor2;;\n        \\<acute>dest :== \\<acute>dest-1;;\n        \\<acute>cursor2 :== \\<acute>cursor2-1;;\n        \\<acute>len2 :== \\<acute>len2-1;;\n        IF \\<acute>len2 = 1 THEN THROW FI;;\n\n        \\<acute>count_tmp :== CALL gallop_left(\\<acute>a!\\<acute>cursor1, \\<acute>tmp, 0, \\<acute>len2, (\\<acute>len2-1));;\n        \\<acute>count2 :== \\<acute>len2 - \\<acute>count_tmp;;\n        IF \\<acute>count2 \\<noteq> 0\n        THEN\n          \\<acute>dest :== \\<acute>dest-\\<acute>count2;;\n          \\<acute>cursor2 :== \\<acute>cursor2-\\<acute>count2;;\n          \\<acute>len2 :== \\<acute>len2-\\<acute>count2;;\n          \\<acute>a :== list_copy \\<acute>a (\\<acute>dest+1) \\<acute>tmp (\\<acute>cursor2+1) \\<acute>count2;;\n          IF \\<acute>len2 \\<le> 1 THEN THROW FI\n        FI;;\n        \\<acute>a!\\<acute>dest :== \\<acute>a!\\<acute>cursor1;;\n        \\<acute>dest :== \\<acute>dest-1;;\n        \\<acute>cursor1 :== \\<acute>cursor1-1;;\n        \\<acute>len1 :== \\<acute>len1-1;;\n        IF \\<acute>len1 = 0 THEN THROW FI;;\n        \\<acute>min_gallop :== \\<acute>min_gallop-1\n      OD;;\n      IF \\<acute>min_gallop < 0 THEN \\<acute>min_gallop :== 0 FI;;\n      \\<acute>min_gallop :== \\<acute>min_gallop + 2\n    OD\n  CATCH\n  Skip\n  END;;\n  IF \\<acute>len2 = 1\n  THEN \n    \\<acute>dest :== \\<acute>dest-\\<acute>len1;;\n    \\<acute>cursor1 :== \\<acute>cursor1-\\<acute>len1;;\n    \\<acute>a :== list_copy \\<acute>a (\\<acute>dest+1) \\<acute>a (\\<acute>cursor1+1) \\<acute>len1;;\n    \\<acute>a!\\<acute>dest :== \\<acute>tmp!\\<acute>cursor2\n  ELSE IF \\<acute>len2 = 0\n       THEN Skip\n       ELSE \\<acute>a :== list_copy \\<acute>a (\\<acute>dest-(\\<acute>len2-1)) \\<acute>tmp 0 \\<acute>len2 \n       FI\n  FI\nCATCH\nSkip\nEND\"\n        in HoarePartial.annotateI) \n   apply vcg \n    apply (simp_all)\n    apply (auto simp add:Suc_diff_Suc)\n  done \n\n\nend", "meta": {"author": "LVPGroup", "repo": "TimSort", "sha": "16437b6b6e2df9f6d32b2a32be7d0d650d83f980", "save_path": "github-repos/isabelle/LVPGroup-TimSort", "path": "github-repos/isabelle/LVPGroup-TimSort/TimSort-16437b6b6e2df9f6d32b2a32be7d0d650d83f980/GallopA.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.5039061705290805, "lm_q2_score": 0.5039061705290805, "lm_q1q2_score": 0.25392142869728274}}
{"text": "theory Coinductive\n  imports Main \"HOL-Library.BNF_Corec\" \"ext/ext_BigStepSimple\"\nbegin\n\ncodatatype 'a stream = SCons (shd: 'a) (stl: \"'a stream\")\n\ntype_synonym 'a strace = \"'a trace_block stream\"\n\ntype_synonym 'a stassn = \"'a strace \\<Rightarrow> bool\"\n\nsubsection \\<open>Combining two traces\\<close>\n\ntext \\<open>Whether two rdy_infos from different processes are compatible.\\<close>\nfun compat_rdy :: \"rdy_info \\<Rightarrow> rdy_info \\<Rightarrow> bool\" where\n  \"compat_rdy (r11, r12) (r21, r22) = (r11 \\<inter> r22 = {} \\<and> r12 \\<inter> r21 = {})\"\n\ntext \\<open>Merge two rdy infos\\<close>\nfun merge_rdy :: \"rdy_info \\<Rightarrow> rdy_info \\<Rightarrow> rdy_info\" where\n  \"merge_rdy (r11, r12) (r21, r22) = (r11 \\<union> r21, r12 \\<union> r22)\"\n\nlemma WaitBlk_eq_combine:\n  assumes \"WaitBlk d1 p1 rdy1 = WaitBlk d1' p1' rdy1'\"\n    and \"WaitBlk d1 p2 rdy2 = WaitBlk d1' p2' rdy2'\"\n   shows \"WaitBlk d1 (\\<lambda>\\<tau>. ParState (p1 \\<tau>) (p2 \\<tau>)) (merge_rdy rdy1 rdy2) =\n          WaitBlk d1' (\\<lambda>\\<tau>. ParState (p1' \\<tau>) (p2' \\<tau>)) (merge_rdy rdy1' rdy2')\"\nproof -\n  have a1: \"d1 = d1'\" \"rdy1 = rdy1'\" \"rdy2 = rdy2'\"\n    using assms WaitBlk_cong by blast+\n  have a2: \"\\<And>t. 0 \\<le> t \\<Longrightarrow> t \\<le> d1 \\<Longrightarrow> p1 t = p1' t\"\n    using assms(1) WaitBlk_cong2 by blast\n  have a3: \"\\<And>t. 0 \\<le> t \\<Longrightarrow> t \\<le> d1 \\<Longrightarrow> p2 t = p2' t\"\n    using assms(2) WaitBlk_cong2 by blast\n  show ?thesis\n  proof (cases d1)\n    case (real r)\n    have b: \"d1' = ereal r\"\n      using real a1(1) by auto\n    show ?thesis\n      unfolding real b apply (auto simp add: WaitBlk_simps)\n       apply (rule ext) apply auto\n      subgoal for x apply (rule a2) by (auto simp add: real)\n      subgoal for x apply (rule a3) by (auto simp add: real)\n      using a1 by auto\n  next\n    case PInf\n    have b: \"d1' = \\<infinity>\"\n      using PInf a1 by auto\n    show ?thesis\n      unfolding PInf b infinity_ereal_def\n      apply (auto simp: WaitBlk_simps)\n       apply (rule ext) apply auto\n      subgoal for x apply (rule a2) by (auto simp add: PInf)\n      subgoal for x apply (rule a3) by (auto simp add: PInf)\n      using a1 by auto\n  next\n    case MInf\n    have b: \"d1' = - \\<infinity>\"\n      using MInf a1 by auto\n    show ?thesis\n      unfolding MInf b\n      by (auto simp: a1 WaitBlk_simps)\n  qed\nqed\n\ncoinductive combine_blocks :: \"cname set \\<Rightarrow> 'a strace \\<Rightarrow> 'a strace \\<Rightarrow> 'a strace \\<Rightarrow> bool\" where\n  \\<comment> \\<open>Paired communication\\<close>\n  combine_blocks_pair1:\n  \"ch \\<in> comms \\<Longrightarrow>\n   combine_blocks comms blks1 blks2 blks \\<Longrightarrow>\n   combine_blocks comms (SCons (InBlock ch v) blks1) (SCons (OutBlock ch v) blks2)\n                  (SCons (IOBlock ch v) blks)\"\n| combine_blocks_pair2:\n  \"ch \\<in> comms \\<Longrightarrow>\n   combine_blocks comms blks1 blks2 blks \\<Longrightarrow>\n   combine_blocks comms (SCons (OutBlock ch v) blks1) (SCons (InBlock ch v) blks2)\n                  (SCons (IOBlock ch v) blks)\"\n\n  \\<comment> \\<open>Paired communication\\<close>\n| combine_blocks_unpair1:\n  \"ch \\<notin> comms \\<Longrightarrow>\n   combine_blocks comms blks1 blks2 blks \\<Longrightarrow>\n   combine_blocks comms (SCons (CommBlock ch_type ch v) blks1) blks2\n                  (SCons (CommBlock ch_type ch v) blks)\"\n| combine_blocks_unpair2:\n  \"ch \\<notin> comms \\<Longrightarrow>\n   combine_blocks comms blks1 blks2 blks \\<Longrightarrow>\n   combine_blocks comms blks1 (SCons (CommBlock ch_type ch v) blks2)\n                  (SCons (CommBlock ch_type ch v) blks)\"\n\n  \\<comment> \\<open>Wait\\<close>\n| combine_blocks_wait:\n  \"combine_blocks comms blks1 blks2 blks \\<Longrightarrow>\n   compat_rdy rdy1 rdy2 \\<Longrightarrow>\n   hist = (\\<lambda>\\<tau>. ParState ((\\<lambda>x::real. hist1 x) \\<tau>) ((\\<lambda>x::real. hist2 x) \\<tau>)) \\<Longrightarrow>\n   rdy = merge_rdy rdy1 rdy2 \\<Longrightarrow>\n   combine_blocks comms (SCons (WaitBlk t (\\<lambda>x::real. hist1 x) rdy1) blks1)\n                        (SCons (WaitBlk t (\\<lambda>x::real. hist2 x) rdy2) blks2)\n                        (SCons (WaitBlk t hist rdy) blks)\"\n\nlemma combine_blocks_waitE:\n  \"combine_blocks comms (SCons (WaitBlk d1 p1 rdy1) blks1)\n                        (SCons (WaitBlk d2 p2 rdy2) blks2) blks \\<Longrightarrow>\n   (\\<And>blks'. d1 = d2 \\<Longrightarrow>\n             compat_rdy rdy1 rdy2 \\<Longrightarrow>\n             blks = SCons (WaitBlk d1 (\\<lambda>t. ParState (p1 t) (p2 t))\n                             (merge_rdy rdy1 rdy2)) blks' \\<Longrightarrow>\n            combine_blocks comms blks1 blks2 blks' \\<Longrightarrow> P) \\<Longrightarrow> P\"\nproof (induction rule: combine_blocks.cases)\n  case (combine_blocks_wait comms' blks1' blks2' blks' rdy1' rdy2' hist hist1 hist2 rdy t)\n  have a1: \"blks1 = blks1'\" \"blks2 = blks2'\"\n       \"WaitBlk d1 p1 rdy1 = WaitBlk t hist1 rdy1'\"\n       \"WaitBlk d2 p2 rdy2 = WaitBlk t hist2 rdy2'\"\n    using combine_blocks_wait(2,3) by auto\n  have a2: \"d1 = d2\" \"rdy1 = rdy1'\" \"rdy2 = rdy2'\" \"d1 = t\" \"d2 = t\"\n    using WaitBlk_cong a1(3,4) by blast+\n  have a3: \"WaitBlk d1 p2 rdy2 = WaitBlk t hist2 rdy2'\"\n    using a2 a1(4) by auto\n  have a4: \"WaitBlk d1 (\\<lambda>\\<tau>. ParState (p1 \\<tau>) (p2 \\<tau>)) (merge_rdy rdy1 rdy2) =\n            WaitBlk t (\\<lambda>\\<tau>. ParState (hist1 \\<tau>) (hist2 \\<tau>)) (merge_rdy rdy1' rdy2')\"\n    using WaitBlk_eq_combine[OF a1(3) a3] by auto\n  show ?case\n    using combine_blocks_wait a1 a2 a4 by auto\nqed (auto)\n\nlemma combine_blocks_waitCommE:\n  assumes \"ch \\<in> comms\"\n  shows\n    \"combine_blocks comms (SCons (WaitBlk d1 p1 rdy1) blks1)\n                          (SCons (CommBlock ch_type ch v) blks2) blks \\<Longrightarrow> P\"\n  apply (induction rule: combine_blocks.cases)\n  using assms by auto\n\nlemma combine_blocks_waitCommE':\n  assumes \"ch \\<in> comms\"\n  shows\n    \"combine_blocks comms (SCons (CommBlock ch_type ch v) blks1) \n                          (SCons (WaitBlk d1 p1 rdy1) blks2) blks \\<Longrightarrow> P\"\n  apply (induction rule: combine_blocks.cases)\n  using assms by auto\n\nlemma combine_blocks_waitCommE2:\n  assumes \"ch \\<notin> comms\"\n  shows\n    \"combine_blocks comms (SCons (WaitBlk d1 p1 rdy1) blks1)\n                          (SCons (CommBlock ch_type ch v) blks2) blks \\<Longrightarrow>\n     (\\<And>blks'. blks = SCons (CommBlock ch_type ch v) blks' \\<Longrightarrow>\n              combine_blocks comms (SCons (WaitBlk d1 p1 rdy1) blks1) blks2 blks' \\<Longrightarrow> P) \\<Longrightarrow> P\"\nproof (induction rule: combine_blocks.cases)\n  case (combine_blocks_unpair2 ch' comms' blks1' blks2' blks' ch_type' v')\n  have a1: \"blks2 = blks2'\" \"CommBlock ch_type ch v = CommBlock ch_type' ch' v'\"\n    using combine_blocks_unpair2(3) by auto\n  have a2: \"ch_type = ch_type'\" \"ch = ch'\" \"v = v'\"\n    using a1 by auto\n  show ?case\n    using combine_blocks_unpair2 a1 a2 by auto\nqed (auto simp: assms)\n\nlemma combine_blocks_waitCommE2':\n  assumes \"ch \\<notin> comms\"\n  shows\n    \"combine_blocks comms (SCons (CommBlock ch_type ch v) blks1)\n                          (SCons (WaitBlk d1 p1 rdy1) blks2) blks \\<Longrightarrow>\n     (\\<And>blks'. blks = SCons (CommBlock ch_type ch v) blks' \\<Longrightarrow>\n              combine_blocks comms blks1 (SCons (WaitBlk d1 p1 rdy1) blks2)  blks' \\<Longrightarrow> P) \\<Longrightarrow> P\"\nproof (induction rule: combine_blocks.cases)\n  case (combine_blocks_unpair2 ch' comms' blks1' blks2' blks' ch_type' v')\n  have a1: \"blks2 = blks2'\" \"CommBlock ch_type ch v = CommBlock ch_type' ch' v'\"\n    using combine_blocks_unpair2(3) by auto\n  have a2: \"ch_type = ch_type'\" \"ch = ch'\" \"v = v'\"\n    using a1 by auto\n  show ?case\n    using combine_blocks_unpair2 a1 a2 by auto\nqed (auto simp: assms)\n\nlemma combine_blocks_pairE:\n  assumes \"ch1 \\<in> comms\"\n    and \"ch2 \\<in> comms\"\n  shows \"combine_blocks comms (SCons (CommBlock ch_type1 ch1 v1) blks1) (SCons (CommBlock ch_type2 ch2 v2) blks2) blks \\<Longrightarrow>\n    (\\<And>blks'. ch1 = ch2 \\<Longrightarrow> v1 = v2 \\<Longrightarrow> (ch_type1 = In \\<and> ch_type2 = Out \\<or> ch_type1 = Out \\<and> ch_type2 = In) \\<Longrightarrow>\n   blks = SCons (IOBlock ch1 v1) blks' \\<Longrightarrow> combine_blocks comms blks1 blks2 blks' \\<Longrightarrow> P) \\<Longrightarrow> P\"\n  by (induct rule: combine_blocks.cases, auto simp:assms)\n\nlemma combine_blocks_unpairE1:\n  assumes \"ch1 \\<notin> comms \"\n    and \"ch2 \\<in> comms \"\n  shows \"combine_blocks comms (SCons (CommBlock ch_type1 ch1 v1) blks1) (SCons (CommBlock ch_type2 ch2 v2) blks2) blks \\<Longrightarrow>\n   (\\<And>blks'. blks = SCons (CommBlock ch_type1 ch1 v1) blks' \\<Longrightarrow>\n           combine_blocks comms blks1 (SCons (CommBlock ch_type2 ch2 v2) blks2) blks' \\<Longrightarrow> P) \\<Longrightarrow> P\"\n  by (induct rule: combine_blocks.cases, auto simp:assms)\n\nlemma combine_blocks_unpairE1':\n  assumes \"ch1 \\<in> comms\"  \n  and \"ch2 \\<notin> comms\"\nshows \"combine_blocks comms (SCons (CommBlock ch_type1 ch1 v1) blks1) (SCons (CommBlock ch_type2 ch2 v2) blks2) blks \\<Longrightarrow>\n   (\\<And>blks'. blks = SCons (CommBlock ch_type2 ch2 v2) blks' \\<Longrightarrow>\n           combine_blocks comms (SCons (CommBlock ch_type1 ch1 v1) blks1) blks2 blks' \\<Longrightarrow> P) \\<Longrightarrow> P\"\n  apply (induct rule: combine_blocks.cases)\n  using assms by auto\n\nlemma combine_blocks_unpairE2:\n  assumes \"ch1 \\<notin> comms\" \n    and \" ch2 \\<notin> comms\"\n  shows \"combine_blocks comms (SCons (CommBlock ch_type1 ch1 v1) blks1) (SCons (CommBlock ch_type2 ch2 v2 ) blks2) blks \\<Longrightarrow>\n   (\\<And>blks'. blks = SCons (CommBlock ch_type1 ch1 v1) blks' \\<Longrightarrow>\n           combine_blocks comms blks1 (SCons (CommBlock ch_type2 ch2 v2) blks2) blks' \\<Longrightarrow> P) \\<Longrightarrow>\n   (\\<And>blks'. blks = SCons (CommBlock ch_type2 ch2 v2) blks' \\<Longrightarrow>\n           combine_blocks comms (SCons (CommBlock ch_type1 ch1 v1) blks1) blks2 blks' \\<Longrightarrow> P) \\<Longrightarrow> P\"\n  by (induct rule: combine_blocks.cases, auto simp add:assms)\n\ntype_synonym tid = real\n\ndatatype status =\n  WAIT | READY | RUNNING\n\n\ndatatype estate =\n  Sch (pool:\"(real \\<times> tid) list\") (run_now:tid) (run_prior:real)\n| Task (status:status) (entered:nat) (task_prior:real)\n| None\n\n\nfun sched_push :: \"tid \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate\" where\n  \"sched_push t (Sch p rn rp) s = Sch (p @ [(s (CHR ''p''), t)]) rn rp\"\n| \"sched_push t (Task st ent tp) s = undefined\"\n| \"sched_push t None s = undefined\"\n\nfun sched_assign :: \"tid \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate\" where\n  \"sched_assign t (Sch p rn rp) s = Sch p t (s (CHR ''p''))\"\n| \"sched_assign t (Task st ent tp) s = undefined\"\n| \"sched_assign t None s = undefined\"\n\nfun get_max_default :: \"real \\<times> tid \\<Rightarrow> (real \\<times> tid) list \\<Rightarrow> real \\<times> tid\" where\n  \"get_max_default (prior, t) [] = (prior, t)\"\n| \"get_max_default (prior, t) ((prior2, t2) # rest) =\n    (if prior \\<ge> prior2 then\n       get_max_default (prior, t) rest\n     else\n       get_max_default (prior2, t2) rest)\"\n\nfun get_max :: \"(real \\<times> tid) list \\<Rightarrow> real \\<times> tid\" where\n  \"get_max [] = (-1, -1)\"\n| \"get_max ((prior, t) # rest) = get_max_default (prior, t) rest\"\n\nfun del_proc :: \"(real \\<times> tid) list \\<Rightarrow> tid \\<Rightarrow> (real \\<times> tid) list\" where\n  \"del_proc [] t = []\"\n| \"del_proc ((prior, t) # rest) t2 =\n    (if t = t2 then rest\n     else (prior, t) # del_proc rest t)\"\n\nfun sched_get_max :: \"estate \\<Rightarrow> state \\<Rightarrow> estate\" where\n  \"sched_get_max (Sch p rn rp) s =\n    (let (prior, t) = get_max p in Sch (del_proc p t) t prior)\"\n| \"sched_get_max (Task st ent tp) s = undefined\"\n| \"sched_get_max None s = undefined\"\n\nfun sched_clear :: \"estate \\<Rightarrow> state \\<Rightarrow> estate\" where\n  \"sched_clear (Sch p rn rp) s = Sch [] (-1) (-1)\"\n| \"sched_clear (Task st ent tp) s = undefined\"\n| \"sched_clear None s = undefined\"\n\nfun sched_del_proc :: \"tid \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate\" where\n  \"sched_del_proc t (Sch p rn rp) s = Sch (del_proc p t) rn rp\"\n| \"sched_del_proc t (Task st ent tp) s = undefined\"\n| \"sched_del_proc t None s = undefined\"\n\ndefinition req_ch :: \"tid \\<Rightarrow> string\" where\n  \"req_ch tid = (\n    if tid = 1 then ''reqProcessor1''\n    else if tid = 2 then ''reqProcessor2''\n    else if tid = 3 then ''reqProcessor3''\n    else undefined)\"\n\ndefinition preempt_ch :: \"tid \\<Rightarrow> string\" where\n  \"preempt_ch tid = (\n    if tid = 1 then ''preempt1''\n    else if tid = 2 then ''preempt2''\n    else if tid = 3 then ''preempt3''\n    else undefined)\"\n\ndefinition run_ch :: \"tid \\<Rightarrow> string\" where\n  \"run_ch tid = (\n    if tid = 1 then ''run1''\n    else if tid = 2 then ''run2''\n    else if tid = 3 then ''run3''\n    else undefined)\"\n\ndefinition free_ch :: \"tid \\<Rightarrow> string\" where\n  \"free_ch tid = (\n    if tid = 1 then ''free1''\n    else if tid = 2 then ''free2''\n    else if tid = 3 then ''free3''\n    else undefined)\"\n\ndefinition exit_ch :: \"tid \\<Rightarrow> string\" where\n  \"exit_ch tid = (\n    if tid = 1 then ''exit1''\n    else if tid = 2 then ''exit2''\n    else if tid = 3 then ''exit3''\n    else undefined)\"\n\ndefinition dispatch_ch :: \"tid \\<Rightarrow> string\" where\n  \"dispatch_ch tid = (\n    if tid = 1 then ''dis1''\n    else if tid = 2 then ''dis2''\n    else if tid = 3 then ''dis3''\n    else undefined)\"\n\ncoinductive dispatch_assn :: \"tid \\<Rightarrow> state \\<Rightarrow> estate stassn\" where\n  \"init_t' = start_s (CHR ''t'') \\<Longrightarrow>\n   init_t' < 0.045 \\<Longrightarrow>\n   wt \\<le> 0.045 - init_t' \\<Longrightarrow>\n   blk1 = WaitBlk (ereal wt) (\\<lambda>t. EState (None, start_s(CHR ''t'' := init_t' + t))) ({}, {}) \\<Longrightarrow>\n   dispatch_assn i (start_s(CHR ''t'' := init_t' + wt)) rest \\<Longrightarrow>\n   dispatch_assn i start_s (SCons blk1 rest)\"\n| \"init_t' = start_s (CHR ''t'') \\<Longrightarrow>\n   init_t' = 0.045 \\<Longrightarrow>\n   blk1 = OutBlock (dispatch_ch i) 0 \\<Longrightarrow>\n   dispatch_assn i (start_s(CHR ''t'' := 0)) rest \\<Longrightarrow>\n   dispatch_assn i start_s (SCons blk1 rest)\"\nthm dispatch_assn.coinduct\nthm dispatch_assn.cases\n\ncoinductive task_assn :: \"tid \\<Rightarrow> string \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate stassn\" where\n  \"start_es = Task WAIT ent tp \\<Longrightarrow>\n   wt > 0 \\<Longrightarrow>\n   blk1 = WaitBlk (ereal wt) (\\<lambda>_. EState (start_es, start_s)) ({}, {dispatch_ch i}) \\<Longrightarrow>\n   task_assn i ''p1'' start_es start_s rest \\<Longrightarrow>\n   task_assn i ''p1'' start_es start_s (SCons blk1 rest)\"\n| \"start_es = Task WAIT ent tp \\<Longrightarrow>\n   blk1 = InBlock (dispatch_ch i) 0 \\<Longrightarrow>\n   task_assn i ''p2'' (Task READY 0 tp) (start_s(CHR ''t'' := 0)) rest \\<Longrightarrow>\n   task_assn i ''p1'' start_es start_s (SCons blk1 rest)\"\n| \"start_es = Task READY ent tp \\<Longrightarrow>\n   blk1 = OutBlock (req_ch i) tp \\<Longrightarrow>\n   task_assn i ''p3'' start_es start_s rest \\<Longrightarrow>\n   task_assn i ''p2'' start_es start_s (SCons blk1 rest)\"\n| \"start_es = Task READY ent tp \\<Longrightarrow>\n   init_t = start_s (CHR ''t'') \\<Longrightarrow>\n   init_t < 0.045 \\<Longrightarrow>\n   wt \\<le> 0.045 - init_t \\<Longrightarrow>\n   blk1 = WaitBlk (ereal wt) (\\<lambda>t. EState (start_es, start_s(CHR ''t'' := init_t + t))) ({}, {run_ch i}) \\<Longrightarrow>\n   task_assn i ''p3'' start_es (start_s(CHR ''t'' := init_t + wt)) rest \\<Longrightarrow>\n   task_assn i ''p3'' start_es start_s (SCons blk1 rest)\"\n| \"start_es = Task READY ent tp \\<Longrightarrow>\n   init_t = start_s (CHR ''t'') \\<Longrightarrow>\n   init_t = 0.045 \\<Longrightarrow>\n   blk1 = OutBlock (exit_ch i) 0 \\<Longrightarrow>\n   task_assn i ''p1'' start_es start_s rest \\<Longrightarrow>\n   task_assn i ''p3'' start_es start_s (SCons blk1 rest)\"\n| \"start_es = Task READY 0 tp \\<Longrightarrow>\n   blk1 = InBlock (run_ch i) 0 \\<Longrightarrow>\n   task_assn i ''p4'' (Task RUNNING 1 tp) (start_s(CHR ''c'' := 0)) rest \\<Longrightarrow>\n   task_assn i ''p3'' start_es start_s (SCons blk1 rest)\"\n| \"start_es = Task READY 1 tp \\<Longrightarrow>\n   blk1 = InBlock (run_ch i) 0 \\<Longrightarrow>\n   task_assn i ''p4'' (Task RUNNING 1 tp) start_s rest \\<Longrightarrow>\n   task_assn i ''p3'' start_es start_s (SCons blk1 rest)\"\n| \"start_es = Task RUNNING 1 tp \\<Longrightarrow>\n   init_t = start_s (CHR ''t'') \\<Longrightarrow>\n   init_c = start_s (CHR ''c'') \\<Longrightarrow>\n   wt \\<le> 0.045 - init_t \\<Longrightarrow>\n   wt \\<le> 0.01 - init_c \\<Longrightarrow>\n   wt > 0 \\<Longrightarrow>\n   blk1 = WaitBlk (ereal wt)\n      (\\<lambda>t. EState (start_es, start_s(CHR ''t'' := init_t + t,\n                                     CHR ''c'' := init_c + t))) ({}, {preempt_ch i}) \\<Longrightarrow>\n   task_assn i ''p4'' start_es (start_s(CHR ''t'' := init_t + wt,\n                                        CHR ''c'' := init_c + wt)) rest \\<Longrightarrow>\n   task_assn i ''p4'' start_es start_s (SCons blk1 rest)\"\n| \"start_es = Task RUNNING 1 tp \\<Longrightarrow>\n   blk1 = InBlock (preempt_ch i) 0 \\<Longrightarrow>\n   task_assn i ''p2'' (Task READY 1 tp) start_s rest \\<Longrightarrow>\n   task_assn i ''p4'' start_es start_s (SCons blk1 rest)\"\n| \"start_es = Task RUNNING 1 tp \\<Longrightarrow>\n   init_t = start_s (CHR ''t'') \\<Longrightarrow>\n   init_c = start_s (CHR ''c'') \\<Longrightarrow>\n   init_c = 0.01 \\<or> init_t = 0.045 \\<Longrightarrow>\n   blk1 = OutBlock (free_ch i) 0 \\<Longrightarrow>\n   task_assn i ''p1'' (Task READY 1 tp) start_s rest \\<Longrightarrow>\n   task_assn i ''p4'' start_es start_s (SCons blk1 rest)\"\n\ncoinductive task_dis_assn :: \"tid \\<Rightarrow> string \\<Rightarrow> state \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate stassn\" where\n  \"start_es = Task WAIT ent tp \\<Longrightarrow>\n   init_t' = dis_s (CHR ''t'') \\<Longrightarrow>\n   init_t' < 0.045 \\<Longrightarrow>\n   wt \\<le> 0.045 - init_t' \\<Longrightarrow>\n   blk1 = WaitBlk (ereal wt) (\\<lambda>t. ParState\n      (EState (None, dis_s(CHR ''t'' := init_t' + t)))\n      (EState (start_es, task_s))) ({}, {dispatch_ch i}) \\<Longrightarrow>\n   task_dis_assn i ''p1'' (dis_s(CHR ''t'' := init_t' + wt)) start_es task_s rest \\<Longrightarrow>\n   task_dis_assn i ''p1'' dis_s start_es task_s (SCons blk1 rest)\"\n| \"start_es = Task WAIT ent tp \\<Longrightarrow>\n   init_t' = dis_s (CHR ''t'') \\<Longrightarrow>\n   init_t' = 0.045 \\<Longrightarrow>\n   blk1 = IOBlock (dispatch_ch i) 0 \\<Longrightarrow>\n   task_dis_assn i ''p2'' (dis_s(CHR ''t'' := 0)) (Task READY 0 tp) (task_s(CHR ''t'' := 0)) rest \\<Longrightarrow>\n   task_dis_assn i ''p1'' dis_s start_es task_s (SCons blk1 rest)\"\n| \"start_es = Task READY ent tp \\<Longrightarrow>\n   blk1 = OutBlock (req_ch i) tp \\<Longrightarrow>\n   task_dis_assn i ''p3'' dis start_es task_s rest \\<Longrightarrow>\n   task_dis_assn i ''p2'' dis start_es task_s (SCons blk1 rest)\"\n| \"start_es = Task READY ent tp \\<Longrightarrow>\n   init_t = task_s (CHR ''t'') \\<Longrightarrow>\n   init_t' = dis_s (CHR ''t'') \\<Longrightarrow>\n   wt \\<le> 0.045 - init_t \\<Longrightarrow>\n   wt \\<le> 0.045 - init_t' \\<Longrightarrow>\n   blk1 = WaitBlk (ereal wt) (\\<lambda>t. ParState\n      (EState (None, dis_t(CHR ''t'' := init_t' + t)))\n      (EState (start_es, task_s(CHR ''t'' := init_t + t)))) ({}, {run_ch i}) \\<Longrightarrow>\n   task_dis_assn i ''p3'' (dis_s(CHR ''t'' := init_t' + wt))\n      start_es (task_s(CHR ''t'' := init_t + wt)) rest \\<Longrightarrow>\n   task_dis_assn i ''p3'' dis_s start_es task_s (SCons blk1 rest)\"\n| \"start_es = Task READY ent tp \\<Longrightarrow>\n   init_t = task_s (CHR ''t'') \\<Longrightarrow>\n   init_t = 0.045 \\<Longrightarrow>\n   blk1 = OutBlock (exit_ch i) 0 \\<Longrightarrow>\n   task_dis_assn i ''p1'' dis_s start_es task_s rest \\<Longrightarrow>\n   task_dis_assn i ''p3'' dis_s start_es task_s (SCons blk1 rest)\"\n| \"start_es = Task READY 0 tp \\<Longrightarrow>\n   blk1 = InBlock (run_ch i) 0 \\<Longrightarrow>\n   task_dis_assn i ''p4'' dis_s (Task RUNNING 1 tp) (task_s(CHR ''c'' := 0)) rest \\<Longrightarrow>\n   task_dis_assn i ''p3'' dis_s start_es task_s (SCons blk1 rest)\"\n| \"start_es = Task READY 1 tp \\<Longrightarrow>\n   blk1 = InBlock (run_ch i) 0 \\<Longrightarrow>\n   task_dis_assn i ''p4'' dis_s (Task RUNNING 1 tp) task_s rest \\<Longrightarrow>\n   task_dis_assn i ''p3'' dis_s start_es task_s (SCons blk1 rest)\"\n| \"start_es = Task RUNNING 1 tp \\<Longrightarrow>\n   init_t = task_s (CHR ''t'') \\<Longrightarrow>\n   init_c = task_s (CHR ''c'') \\<Longrightarrow>\n   init_t' = dis_s (CHR ''t'') \\<Longrightarrow>\n   wt \\<le> 0.045 - init_t \\<Longrightarrow>\n   wt \\<le> 0.01 - init_c \\<Longrightarrow>\n   wt \\<le> 0.045 - init_t' \\<Longrightarrow>\n   wt > 0 \\<Longrightarrow>\n   blk1 = WaitBlk (ereal wt) (\\<lambda>t. ParState\n      (EState (None, dis_s(CHR ''t'' := init_t' + t)))\n      (EState (start_es, task_s(CHR ''t'' := init_t + t, CHR ''c'' := init_c + t))))\n      ({}, {preempt_ch i}) \\<Longrightarrow>\n   task_dis_assn i ''p4'' (dis_s(CHR ''t'' := init_t' + wt)) start_es (task_s(CHR ''t'' := init_t + wt,\n                                                 CHR ''c'' := init_c + wt)) rest \\<Longrightarrow>\n   task_dis_assn i ''p4'' dis_s start_es task_s (SCons blk1 rest)\"\n| \"start_es = Task RUNNING 1 tp \\<Longrightarrow>\n   blk1 = InBlock (preempt_ch i) 0 \\<Longrightarrow>\n   task_dis_assn i ''p2'' dis_s (Task READY 1 tp) task_s rest \\<Longrightarrow>\n   task_dis_assn i ''p4'' dis_s start_es task_s (SCons blk1 rest)\"\n| \"start_es = Task RUNNING 1 tp \\<Longrightarrow>\n   init_t = task_s (CHR ''t'') \\<Longrightarrow>\n   init_c = task_s (CHR ''c'') \\<Longrightarrow>\n   init_c = 0.01 \\<or> init_t = 0.045 \\<Longrightarrow>\n   blk1 = OutBlock (free_ch i) 0 \\<Longrightarrow>\n   task_dis_assn i ''p1'' dis_s (Task READY 1 tp) task_s rest \\<Longrightarrow>\n   task_dis_assn i ''p4'' dis_s start_es task_s (SCons blk1 rest)\"\nthm task_dis_assn.coinduct\n\ntheorem combine_task_dis:\n  assumes \"i \\<in> {1,2,3}\"\n  shows\n    \"dispatch_assn i dis_s blks1 \\<Longrightarrow>\n     task_assn i pc start_es task_s blks2 \\<Longrightarrow>\n     combine_blocks {dispatch_ch i} blks1 blks2 blks \\<Longrightarrow>\n     task_dis_assn i pc dis_s start_es task_s blks\"\nproof (coinduction arbitrary: pc dis_s start_es task_s blks1 blks2 blks rule: task_dis_assn.coinduct)\n  have comm_in: \"dispatch_ch i \\<in> {dispatch_ch i}\"\n    by auto\n  have req_not_in: \"req_ch i \\<notin> {dispatch_ch i}\"\n    unfolding req_ch_def dispatch_ch_def\n    using assms by auto\n  have exit_not_in: \"exit_ch i \\<notin> {dispatch_ch i}\"\n    unfolding exit_ch_def dispatch_ch_def\n    using assms by auto\n  have run_not_in: \"run_ch i \\<notin> {dispatch_ch i}\"\n    unfolding run_ch_def dispatch_ch_def\n    using assms by auto\n  have preempt_not_in: \"preempt_ch i \\<notin> {dispatch_ch i}\"\n    unfolding preempt_ch_def dispatch_ch_def\n    using assms by auto\n  have free_not_in: \"free_ch i \\<notin> {dispatch_ch i}\"\n    unfolding free_ch_def dispatch_ch_def\n    using assms by auto\n  case task_dis_assn\n  from task_dis_assn(1) show ?case\n  proof (cases rule: dispatch_assn.cases)\n    case (1 init_t' wt1 blk1' rest1)\n    note d1 = 1\n    from task_dis_assn(2) show ?thesis\n    proof (cases rule: task_assn.cases)\n      case (1 ent' tp' wt2 blk2' rest2)\n      note t1 = 1\n      obtain rest where rest:\n        \"ereal wt1 = ereal wt2\"\n        \"blks = SCons (WaitBlk (ereal wt1) (\\<lambda>t. ParState\n            (EState (estate.None, dis_s(CHR ''t'' := init_t' + t)))\n            (EState (start_es, task_s))) (merge_rdy ({}, {}) ({}, {dispatch_ch i}))) rest\"\n        \"combine_blocks {dispatch_ch i} rest1 rest2 rest\"\n        using task_dis_assn(3)[unfolded d1(1) t1(2) d1(5) t1(5)]\n        apply (elim combine_blocks_waitE) by blast\n      then show ?thesis\n        using d1 t1 by auto\n    next\n      case (2 ent tp blk2' rest2)\n      note t2 = 2\n      from task_dis_assn(3)[unfolded d1(1) t2(2) d1(5) t2(4)]\n      show ?thesis\n        by (elim combine_blocks_waitCommE[OF comm_in])\n    next\n      case (3 ent tp blk2' rest2)\n      note t3 = 3\n      obtain rest where rest:\n        \"blks = SCons (OutBlock (req_ch i) tp) rest\"\n        \"combine_blocks {dispatch_ch i}\n          (SCons (WaitBlk (ereal wt1) (\\<lambda>t. EState (estate.None, dis_s(CHR ''t'' := init_t' + t)))\n                          ({}, {})) rest1)\n          rest2 rest\"\n        using task_dis_assn(3)[unfolded d1(1) t3(2) d1(5) t3(4)]\n        apply (elim combine_blocks_waitCommE2[OF req_not_in]) by blast\n      then show ?thesis\n        using t3 d1 task_dis_assn(1) by auto\n    next\n      case (4 ent' tp' init_t2 wt2 blk2' rest2)\n      note t4 = 4\n      obtain rest where\n        \"ereal wt1 = ereal wt2\"\n        \"blks = SCons (WaitBlk (ereal wt1) (\\<lambda>t. ParState\n            (EState (estate.None, dis_s(CHR ''t'' := init_t' + t)))\n            (EState (start_es, task_s(CHR ''t'' := init_t2 + t))))\n            (merge_rdy ({}, {}) ({}, {run_ch i}))) rest\"\n        \"combine_blocks {dispatch_ch i} rest1 rest2 rest\"\n        using task_dis_assn(3)[unfolded d1(1) t4(2) d1(5) t4(7)]\n        apply (elim combine_blocks_waitE) by blast\n      then show ?thesis\n        using t4 d1 by auto\n    next\n      case (5 ent tp init_t blk2' rest2)\n      note t5 = 5\n      obtain rest where rest:\n        \"blks = SCons (OutBlock (exit_ch i) 0) rest\"\n        \"combine_blocks {dispatch_ch i}\n          (SCons (WaitBlk (ereal wt1) (\\<lambda>t. EState (estate.None, dis_s(CHR ''t'' := init_t' + t)))\n                          ({}, {})) rest1)\n          rest2 rest\"\n        using task_dis_assn(3)[unfolded d1(1) t5(2) d1(5) t5(6)]\n        apply (elim combine_blocks_waitCommE2[OF exit_not_in]) by blast\n      then show ?thesis\n        using t5 d1 task_dis_assn(1) by auto\n    next\n      case (6 tp blk2' rest2)\n      note t6 = 6\n      obtain rest where rest:\n        \"blks = SCons (InBlock (run_ch i) 0) rest\"\n        \"combine_blocks {dispatch_ch i}\n          (SCons (WaitBlk (ereal wt1) (\\<lambda>t. EState (estate.None, dis_s(CHR ''t'' := init_t' + t)))\n                          ({}, {})) rest1)\n          rest2 rest\"\n        using task_dis_assn(3)[unfolded d1(1) t6(2) d1(5) t6(4)]\n        apply (elim combine_blocks_waitCommE2[OF run_not_in]) by blast\n      then show ?thesis\n        using t6 d1 task_dis_assn(1) by auto\n    next\n      case (7 tp blk1 rest2)\n      note t7 = 7      \n      obtain rest where rest:\n        \"blks = SCons (InBlock (run_ch i) 0) rest\"\n        \"combine_blocks {dispatch_ch i}\n          (SCons (WaitBlk (ereal wt1) (\\<lambda>t. EState (estate.None, dis_s(CHR ''t'' := init_t' + t)))\n                          ({}, {})) rest1)\n          rest2 rest\"\n        using task_dis_assn(3)[unfolded d1(1) t7(2) d1(5) t7(4)]\n        apply (elim combine_blocks_waitCommE2[OF run_not_in]) by blast\n      then show ?thesis\n        using t7 d1 task_dis_assn(1) by auto\n    next\n      case (8 tp init_t init_c wt2 blk2' rest2)\n      note t8 = 8\n      thm d1\n      obtain rest where rest:\n        \"ereal wt1 = ereal wt2\"\n        \"blks = SCons (WaitBlk (ereal wt1) (\\<lambda>t. ParState\n            (EState (estate.None, dis_s(CHR ''t'' := init_t' + t)))\n            (EState (start_es, task_s(CHR ''t'' := init_t + t, CHR ''c'' := init_c + t)))) (merge_rdy ({}, {}) ({}, {preempt_ch i}))) rest\"\n        \"combine_blocks {dispatch_ch i} rest1 rest2 rest\"\n        using task_dis_assn(3) [unfolded d1(1) d1(5) t8(2) t8(9)]\n        apply (elim combine_blocks_waitE) by blast\n      then show ?thesis using d1 t8 by auto\n    next\n      case (9 tp blk2' rest2)\n      note t9 = 9\n      thm d1\n      obtain rest where rest:\n        \"blks = SCons (InBlock (preempt_ch i) 0) rest\"\n        \"combine_blocks {dispatch_ch i}\n          (SCons (WaitBlk (ereal wt1) (\\<lambda>t. EState (estate.None, dis_s(CHR ''t'' := init_t' + t)))\n                          ({}, {})) rest1)\n          rest2 rest\"\n        using task_dis_assn(3)[unfolded d1(1) t9(2) d1(5) t9(4)]\n        apply (elim combine_blocks_waitCommE2[OF preempt_not_in]) by blast\n      then show ?thesis\n        using d1 t9 task_dis_assn by auto\n    next\n      case (10 tp init_t init_c blk2' rest2)\n      note t10 = 10\n      obtain rest where rest:\n        \"blks = SCons (OutBlock (free_ch i) 0) rest\"\n        \"combine_blocks {dispatch_ch i}\n          (SCons (WaitBlk (ereal wt1) (\\<lambda>t. EState (estate.None, dis_s(CHR ''t'' := init_t' + t)))\n                          ({}, {})) rest1)\n          rest2 rest\"\n        using task_dis_assn(3)[unfolded d1(1) t10(2) d1(5) t10(7)]\n        apply (elim combine_blocks_waitCommE2[OF free_not_in]) by blast\n      then show ?thesis\n        using d1 t10 task_dis_assn by auto\n    qed\n  next\n    case (2 init_t' blk1' rest1)\n    note d2 = 2\n    from task_dis_assn(2) show ?thesis\n    proof (cases rule: task_assn.cases)\n      case (1 ent tp wt blk2' rest2)\n      note t1 = 1\n      from task_dis_assn(3)[unfolded d2(1) t1(2) d2(4) t1(5)]\n      show ?thesis\n        by (elim combine_blocks_waitCommE'[OF comm_in])\n    next\n      case (2 ent tp blk2' rest2)\n      note t2 = 2\n      obtain rest where rest:\n        \"blks = SCons (IOBlock (dispatch_ch i) 0) rest\"\n        \"combine_blocks {dispatch_ch i}\n          rest1 rest2 rest\"\n        using task_dis_assn(3)[unfolded d2(1,4) t2(2,4)]\n        apply(elim combine_blocks_pairE[OF comm_in comm_in]) by blast\n      then show ?thesis \n        using d2 t2 task_dis_assn by auto\n    next\n      case (3 ent tp blk2' rest2)\n      note t3=3\n      obtain rest where rest:\n        \"blks = SCons (OutBlock (req_ch i) tp) rest\"\n        \"combine_blocks {dispatch_ch i}\n          (SCons (OutBlock (dispatch_ch i) 0) rest1)\n          rest2 rest\"\n        using task_dis_assn(3) [unfolded d2(1,4) t3(2,4)]\n        apply(elim combine_blocks_unpairE1'[OF comm_in req_not_in]) by blast\n      then show ?thesis \n        using task_dis_assn d2 t3 by auto\n    next\n      case (4 ent tp init_t wt blk1 rest)\n      note t4 = 4\n      from task_dis_assn(3)[unfolded d2(1,4) t4(2,7)]\n      show ?thesis \n        by (elim combine_blocks_waitCommE'[OF comm_in])\n    next\n      case (5 ent tp init_t blk2' rest2)\n      note t5 = 5\n      obtain rest where rest:\n        \"blks = SCons (OutBlock (exit_ch i) 0) rest\"\n        \"combine_blocks {dispatch_ch i}\n          (SCons (OutBlock (dispatch_ch i) 0) rest1)\n          rest2 rest\"\n        using task_dis_assn(3) [unfolded d2(1,4) t5(2,6)]\n        apply(elim combine_blocks_unpairE1'[OF comm_in exit_not_in]) by blast\n      then show ?thesis using task_dis_assn d2 t5 by auto\n    next\n      case (6 tp blk2' rest2)\n      note t6 = 6\n      obtain rest where rest:\n        \"blks = SCons (InBlock (run_ch i) 0) rest\"\n        \"combine_blocks {dispatch_ch i}\n          (SCons (OutBlock (dispatch_ch i) 0) rest1)\n          rest2 rest\"\n        using task_dis_assn(3) [unfolded d2(1,4) t6(2,4)]\n        apply(elim combine_blocks_unpairE1'[OF comm_in run_not_in]) by blast\n      then show ?thesis using task_dis_assn d2 t6 by auto\n    next\n      case (7 tp blk2' rest2)\n      note t7 = 7\n      obtain rest where rest:\n        \"blks = SCons (InBlock (run_ch i) 0) rest\"\n        \"combine_blocks {dispatch_ch i}\n          (SCons (OutBlock (dispatch_ch i) 0) rest1)\n          rest2 rest\"\n        using task_dis_assn(3) [unfolded d2(1,4) t7(2,4)]\n        apply(elim combine_blocks_unpairE1'[OF comm_in run_not_in]) by blast\n      then show ?thesis using task_dis_assn d2 t7 by auto\n    next\n      case (8 tp init_t init_c wt blk1 rest)\n      note t8 = 8\n      from task_dis_assn(3)[unfolded d2(1,4) t8(2,9)]\n      show ?thesis \n        by (elim combine_blocks_waitCommE'[OF comm_in])\n    next\n      case (9 tp blk2' rest2)\n      note t9 = 9\n      obtain rest where rest:\n        \"blks = SCons (InBlock (preempt_ch i) 0) rest\"\n        \"combine_blocks {dispatch_ch i}\n          (SCons (OutBlock (dispatch_ch i) 0) rest1)\n          rest2 rest\"\n        using task_dis_assn(3) [unfolded d2(1,4) t9(2,4)]\n        apply(elim combine_blocks_unpairE1'[OF comm_in preempt_not_in]) by blast\n      then show ?thesis using task_dis_assn d2 t9 by auto\n    next\n      case (10 tp init_t init_c blk2' rest2)\n      note t10 = 10\n      obtain rest where rest:\n        \"blks = SCons (OutBlock (free_ch i) 0) rest\"\n        \"combine_blocks {dispatch_ch i}\n          (SCons (OutBlock (dispatch_ch i) 0) rest1)\n          rest2 rest\"\n        using task_dis_assn(3) [unfolded d2(1,4) t10(2,7)]\n        apply(elim combine_blocks_unpairE1'[OF comm_in free_not_in]) by blast\n      then show ?thesis using task_dis_assn d2 t10 by auto\n    qed\nqed\nqed\n\ndefinition sch :: \"estate proc\" where\n\"sch = EChoice \n[((req_ch 1)[?]CHR ''p'',\n        (CHR ''i'' ::= (\\<lambda>_ . 1));\n         IF (\\<lambda> (a,s) . run_prior a \\<ge> s (CHR ''p'')) \n           THEN Basic (sched_push 1) \n           ELSE (IF (\\<lambda> (a,s) . run_now a \\<noteq> -1) \n                   THEN (Cm (preempt_ch 1 [!] (\\<lambda>_. 0))) \n                   ELSE Skip \n                 FI);\n                 Basic (sched_assign 1); \n                 Cm (run_ch 1[!](\\<lambda>_ . 0)) \n         FI),\n ((free_ch 1)[?]CHR ''F'',\n        (CHR ''i'' ::= (\\<lambda>_ . 1));\n         IF (\\<lambda> (a,s) . length (pool a) > 0) \n           THEN (Basic (sched_get_max) ; Cm (run_ch 1[!](\\<lambda>_ . 0))) \n           ELSE Basic sched_clear \n         FI),\n ((exit_ch 1)[?]CHR ''E'',\n        (CHR ''i'' ::= (\\<lambda>_ . 1)); \n         Basic (sched_del_proc 1)),\n ((req_ch 2)[?]CHR ''p'',\n        (CHR ''i'' ::= (\\<lambda>_ . 2));\n         IF (\\<lambda> (a,s) . run_prior a \\<ge> s (CHR ''p'')) \n           THEN Basic (sched_push 2) \n           ELSE (IF (\\<lambda> (a,s) . run_now a \\<noteq> -1) \n                   THEN (Cm (preempt_ch 2 [!] (\\<lambda>_. 0))) \n                   ELSE Skip \n                 FI);\n                 Basic (sched_assign 2); \n                 Cm (run_ch 2[!](\\<lambda>_ . 0)) \n         FI),\n ((free_ch 2)[?]CHR ''F'',\n        (CHR ''i'' ::= (\\<lambda>_ . 2));\n         IF (\\<lambda> (a,s) . length (pool a) > 0) \n           THEN (Basic (sched_get_max) ; Cm (run_ch 2[!](\\<lambda>_ . 0))) \n           ELSE Basic sched_clear \n         FI),\n ((exit_ch 2)[?]CHR ''E'',\n        (CHR ''i'' ::= (\\<lambda>_ . 2)); \n         Basic (sched_del_proc 2)),\n ((req_ch 3)[?]CHR ''p'',\n        (CHR ''i'' ::= (\\<lambda>_ . 3));\n         IF (\\<lambda> (a,s) . run_prior a \\<ge> s (CHR ''p'')) \n           THEN Basic (sched_push 3) \n           ELSE (IF (\\<lambda> (a,s) . run_now a \\<noteq> -1) \n                   THEN (Cm (preempt_ch 3 [!] (\\<lambda>_. 0))) \n                   ELSE Skip \n                 FI);\n                 Basic (sched_assign 3); \n                 Cm (run_ch 3[!](\\<lambda>_ . 0)) \n         FI),\n ((free_ch 3)[?]CHR ''F'',\n        (CHR ''i'' ::= (\\<lambda>_ . 3));\n         IF (\\<lambda> (a,s) . length (pool a) > 0) \n           THEN (Basic (sched_get_max) ; Cm (run_ch 3[!](\\<lambda>_ . 0))) \n           ELSE Basic sched_clear \n         FI),\n ((exit_ch 3)[?]CHR ''E'',\n        (CHR ''i'' ::= (\\<lambda>_ . 3)); \n         Basic (sched_del_proc 3))]\"\n\n\ncoinductive sch_assn :: \"string \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate stassn\" where\n  \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   wt > 0 \\<Longrightarrow>\n   blk1 = WaitBlk (ereal wt) (\\<lambda>_. EState (sch_es, sch_s)) ({}, image req_ch {1,2,3} \\<union> image free_ch {1,2,3} \\<union> image exit_ch {1,2,3}) \\<Longrightarrow>\n   sch_assn ''q0'' sch_es sch_s rest \\<Longrightarrow>\n   sch_assn ''q0'' sch_es sch_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   blk1 = InBlock (req_ch i) prior \\<Longrightarrow>\n   i \\<in> {1,2,3}\\<Longrightarrow>\n   sch_assn ''q1'' sch_es (sch_s(CHR ''p'' := prior, CHR ''i'' := i)) rest \\<Longrightarrow>\n   sch_assn ''q0'' sch_es sch_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   i = sch_s CHR ''i'' \\<Longrightarrow>\n   prior = sch_s CHR ''p'' \\<Longrightarrow>\n   r_prior \\<ge> prior \\<Longrightarrow>\n   sch_assn ''q0'' (sched_push i sch_es sch_s) sch_s rest \\<Longrightarrow>\n   sch_assn ''q1'' sch_es sch_s rest\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   i = sch_s CHR ''i'' \\<Longrightarrow>\n   prior = sch_s CHR ''p'' \\<Longrightarrow>\n   r_prior < prior \\<Longrightarrow>\n   r_now \\<noteq> -1 \\<Longrightarrow>\n   blk1 = OutBlock (preempt_ch r_now) 0 \\<Longrightarrow>\n   sch_assn ''q2'' sch_es  sch_s rest \\<Longrightarrow>\n   sch_assn ''q1'' sch_es sch_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   i = sch_s CHR ''i'' \\<Longrightarrow>\n   prior = sch_s CHR ''p'' \\<Longrightarrow>\n   r_prior < prior \\<Longrightarrow>\n   r_now = -1 \\<Longrightarrow>\n   sch_assn ''q2'' sch_es sch_s rest \\<Longrightarrow>\n   sch_assn ''q1'' sch_es sch_s rest\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   i = sch_s CHR ''i'' \\<Longrightarrow>\n   prior = sch_s CHR ''p'' \\<Longrightarrow>\n   blk1 = OutBlock (run_ch i) 0 \\<Longrightarrow>\n   sch_assn ''q0'' (sched_assign i sch_es sch_s) sch_s rest \\<Longrightarrow>\n   sch_assn ''q2'' sch_es sch_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   blk1 = InBlock (free_ch i) 0 \\<Longrightarrow>\n   sch_assn ''q3'' sch_es (sch_s(CHR ''i'' := i)) rest \\<Longrightarrow>\n   sch_assn ''q0'' sch_es sch_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   length p > 0 \\<Longrightarrow>\n   blk1 = OutBlock (run_ch (snd (get_max p))) 0 \\<Longrightarrow>\n   sch_assn ''q0'' (sched_get_max sch_es sch_s) sch_s rest \\<Longrightarrow>\n   sch_assn ''q3'' sch_es sch_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   length p = 0 \\<Longrightarrow>\n   sch_assn ''q0'' (sched_clear sch_es sch_s) sch_s rest \\<Longrightarrow>\n   sch_assn ''q3'' sch_es sch_s rest\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   blk1 = InBlock (exit_ch i) 0 \\<Longrightarrow>\n   sch_assn ''q4'' sch_es (sch_s(CHR ''i'' := i)) rest \\<Longrightarrow>\n   sch_assn ''q0'' sch_es sch_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   sch_assn ''q0'' (sched_del_proc (sch_s CHR ''i'') sch_es sch_s) sch_s rest \\<Longrightarrow>\n   sch_assn ''q4'' sch_es sch_s rest\"\n\n\n\ncoinductive sch_task_dis_assn :: \"tid \\<Rightarrow> string \\<Rightarrow> string \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> state \\<Rightarrow> estate \\<Rightarrow> state \\<Rightarrow> estate stassn\" where\n  \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task WAIT ent tp \\<Longrightarrow>\n   init_t' = dis_s (CHR ''t'') \\<Longrightarrow>\n   init_t' < 0.045 \\<Longrightarrow>\n   wt \\<le> 0.045 - init_t' \\<Longrightarrow>\n   blk1 = WaitBlk (ereal wt) (\\<lambda>t. ParState (EState (sch_es, sch_s))(ParState\n      (EState (None, dis_s(CHR ''t'' := init_t' + t)))\n      (EState (start_es, task_s)))) \n       ({}, {dispatch_ch i} \\<union> image req_ch {1,2,3} \\<union> image free_ch {1,2,3} \\<union> image exit_ch {1,2,3}) \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p1'' sch_es sch_s (dis_s(CHR ''t'' := init_t' + wt)) start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p1'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task WAIT ent tp \\<Longrightarrow>\n   j \\<noteq> i \\<Longrightarrow>\n   blk1 = InBlock (req_ch j) prior \\<Longrightarrow>\n   sch_task_dis_assn i ''q1'' ''p1'' sch_es (sch_s(CHR ''p'' := prior, CHR ''i'' := j)) dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p1'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task WAIT ent tp \\<Longrightarrow>\n   j = sch_s CHR ''i'' \\<Longrightarrow>\n   j \\<noteq> i \\<Longrightarrow>\n   prior = sch_s CHR ''p'' \\<Longrightarrow>\n   r_prior \\<ge> prior \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p1'' (sched_push j sch_es sch_s) sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q1'' ''p1'' sch_es sch_s dis_s start_es task_s rest\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task WAIT ent tp \\<Longrightarrow>\n   j = sch_s CHR ''i'' \\<Longrightarrow>\n   j \\<noteq> i \\<Longrightarrow>\n   prior = sch_s CHR ''p'' \\<Longrightarrow>\n   r_prior < prior \\<Longrightarrow>\n   r_now \\<noteq> -1 \\<Longrightarrow>\n   blk1 = OutBlock (preempt_ch r_now) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q2'' ''p1'' sch_es sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q1'' ''p1'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task WAIT ent tp \\<Longrightarrow>\n   j = sch_s CHR ''i'' \\<Longrightarrow>\n   j \\<noteq> i \\<Longrightarrow>\n   prior = sch_s CHR ''p'' \\<Longrightarrow>\n   r_prior < prior \\<Longrightarrow>\n   r_now = -1 \\<Longrightarrow>\n   sch_task_dis_assn i ''q2'' ''p1'' sch_es sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q1'' ''p1'' sch_es sch_s dis_s start_es task_s rest\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task WAIT ent tp \\<Longrightarrow>\n   j = sch_s CHR ''i'' \\<Longrightarrow>\n   j \\<noteq> i \\<Longrightarrow>\n   prior = sch_s CHR ''p'' \\<Longrightarrow>\n   blk1 = OutBlock (run_ch j) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p1'' (sched_assign i sch_es sch_s) sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q2'' ''p1'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task WAIT ent tp \\<Longrightarrow>\n   j \\<noteq> i \\<Longrightarrow>\n   blk1 = InBlock (free_ch j) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q3'' ''p1'' sch_es (sch_s(CHR ''i'' := j)) dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p1'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task WAIT ent tp \\<Longrightarrow>\n   length p > 0 \\<Longrightarrow>\n   blk1 = OutBlock (run_ch (snd (get_max p))) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p1'' (sched_get_max sch_es sch_s) sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q3'' ''p1'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task WAIT ent tp \\<Longrightarrow>\n   length p = 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p1'' (sched_clear sch_es sch_s) sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q3'' ''p1'' sch_es sch_s dis_s start_es task_s rest\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task WAIT ent tp \\<Longrightarrow>\n   j \\<noteq> i \\<Longrightarrow>\n   blk1 = InBlock (exit_ch j) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q4'' ''p1'' sch_es (sch_s(CHR ''i'' := j)) dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p1'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task WAIT ent tp \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p1'' (sched_del_proc (sch_s CHR ''i'') sch_es sch_s) sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q4'' ''p1'' sch_es sch_s dis_s start_es task_s rest\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task WAIT ent tp \\<Longrightarrow>\n   init_t' = dis_s (CHR ''t'') \\<Longrightarrow>\n   init_t' = 0.045 \\<Longrightarrow>\n   blk1 = IOBlock (dispatch_ch i) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p2'' sch_es sch_s (dis_s(CHR ''t'' := 0)) (Task READY 0 tp) (task_s(CHR ''t'' := 0)) rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p1'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   blk1 = IOBlock (req_ch i) prior \\<Longrightarrow>\n   start_es = Task READY ent tp \\<Longrightarrow>\n   blk1 = OutBlock (req_ch i) tp \\<Longrightarrow>\n   sch_task_dis_assn i ''q1'' ''p3'' sch_es (sch_s(CHR ''p'' := prior, CHR ''i'' := i)) dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p2'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY ent tp \\<Longrightarrow>\n   i = sch_s CHR ''i'' \\<Longrightarrow>\n   r_prior \\<ge> sch_s CHR ''p'' \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p3'' (sched_push i sch_es sch_s) sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q1'' ''p3'' sch_es sch_s dis_s start_es task_s rest\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY ent tp \\<Longrightarrow>\n   init_t = task_s (CHR ''t'') \\<Longrightarrow>\n   init_t' = dis_s (CHR ''t'') \\<Longrightarrow>\n   wt \\<le> 0.045 - init_t \\<Longrightarrow>\n   wt \\<le> 0.045 - init_t' \\<Longrightarrow>\n   blk1 = WaitBlk (ereal wt) (\\<lambda>t. ParState (EState (sch_es,sch_s))(ParState\n      (EState (None, dis_t(CHR ''t'' := init_t' + t)))\n      (EState (start_es, task_s(CHR ''t'' := init_t + t))))) ({}, {run_ch i} \\<union> image req_ch {1,2,3} \\<union> image free_ch {1,2,3} \\<union> image exit_ch {1,2,3}) \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p3'' sch_es sch_s (dis_s(CHR ''t'' := init_t' + wt))\n      start_es (task_s(CHR ''t'' := init_t + wt)) rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p3'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY ent tp \\<Longrightarrow>\n   j \\<noteq> i \\<Longrightarrow>\n   blk1 = InBlock (req_ch j) prior \\<Longrightarrow>\n   sch_task_dis_assn i ''q1'' ''p3'' sch_es (sch_s(CHR ''p'' := prior, CHR ''i'' := j)) dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p3'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY ent tp \\<Longrightarrow>\n   j = sch_s CHR ''i'' \\<Longrightarrow>\n   j \\<noteq> i \\<Longrightarrow>\n   prior = sch_s CHR ''p'' \\<Longrightarrow>\n   r_prior \\<ge> prior \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p3'' (sched_push j sch_es sch_s) sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q1'' ''p3'' sch_es sch_s dis_s start_es task_s rest\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY ent tp \\<Longrightarrow>\n   j = sch_s CHR ''i'' \\<Longrightarrow>\n   j \\<noteq> i \\<Longrightarrow>\n   prior = sch_s CHR ''p'' \\<Longrightarrow>\n   r_prior < prior \\<Longrightarrow>\n   r_now \\<noteq> -1 \\<Longrightarrow>\n   blk1 = OutBlock (preempt_ch r_now) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q2'' ''p3'' sch_es sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q1'' ''p3'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY ent tp \\<Longrightarrow>\n   j = sch_s CHR ''i'' \\<Longrightarrow>\n   j \\<noteq> i \\<Longrightarrow>\n   prior = sch_s CHR ''p'' \\<Longrightarrow>\n   r_prior < prior \\<Longrightarrow>\n   r_now = -1 \\<Longrightarrow>\n   sch_task_dis_assn i ''q2'' ''p3'' sch_es sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q1'' ''p3'' sch_es sch_s dis_s start_es task_s rest\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY ent tp \\<Longrightarrow>\n   j = sch_s CHR ''i'' \\<Longrightarrow>\n   j \\<noteq> i \\<Longrightarrow>\n   prior = sch_s CHR ''p'' \\<Longrightarrow>\n   blk1 = OutBlock (run_ch j) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p3'' (sched_assign j sch_es sch_s) sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q2'' ''p3'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY ent tp \\<Longrightarrow>\n   j \\<noteq> i \\<Longrightarrow>\n   blk1 = InBlock (free_ch j) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q3'' ''p3'' sch_es (sch_s(CHR ''i'' := j)) dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p3'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY ent tp \\<Longrightarrow>\n   length p > 0 \\<Longrightarrow>\n   snd (get_max p) \\<noteq> i \\<Longrightarrow>\n   blk1 = OutBlock (run_ch (snd (get_max p))) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p3'' (sched_get_max sch_es sch_s) sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q3'' ''p3'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n(*  \nTask READY 0 tp   and   Task READY 1 tp\n*)\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY ent tp \\<Longrightarrow>\n   length p > 0 \\<Longrightarrow>\n   snd (get_max p) = i \\<Longrightarrow>\n   blk1 = IOBlock (run_ch i) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p4'' (sched_get_max sch_es sch_s) sch_s dis_s (Task RUNNING 1 tp) task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q3'' ''p3'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n(* length p must be greater than 0\n*)\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   length p = 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p3'' (sched_clear sch_es sch_s) sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q3'' ''p3'' sch_es sch_s dis_s start_es task_s rest\"\n\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY ent tp \\<Longrightarrow>\n   j \\<noteq> i \\<Longrightarrow>\n   blk1 = InBlock (exit_ch j) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q4'' ''p3'' sch_es (sch_s(CHR ''i'' := j)) dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p3'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY ent tp \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p3'' (sched_del_proc (sch_s CHR ''i'') sch_es sch_s) sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q4'' ''p3'' sch_es sch_s dis_s start_es task_s rest\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY ent tp \\<Longrightarrow>\n   init_t = task_s (CHR ''t'') \\<Longrightarrow>\n   init_t = 0.045 \\<Longrightarrow>\n   blk1 = IOBlock (exit_ch i) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q4'' ''p1'' sch_es sch_s dis_s (Task WAIT ent tp) task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p3'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY ent tp \\<Longrightarrow>\n   i = sch_s CHR ''i'' \\<Longrightarrow>\n   r_prior < sch_s CHR ''p'' \\<Longrightarrow>\n   r_now \\<noteq> -1 \\<Longrightarrow>\n   blk1 = OutBlock (preempt_ch r_now) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q2'' ''p3'' sch_es sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q1'' ''p3'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY ent tp \\<Longrightarrow>\n   i = sch_s CHR ''i'' \\<Longrightarrow>\n   r_prior < sch_s CHR ''p'' \\<Longrightarrow>\n   r_now = -1 \\<Longrightarrow>\n   sch_task_dis_assn i ''q2'' ''p3'' sch_es sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q1'' ''p3'' sch_es sch_s dis_s start_es task_s rest\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   i = sch_s CHR ''i'' \\<Longrightarrow>\n   start_es = Task READY 0 tp \\<Longrightarrow>\n   blk1 = IOBlock (run_ch i) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p4'' (sched_assign i sch_es sch_s) sch_s dis_s (Task RUNNING 1 tp) (task_s(CHR ''c'' := 0)) rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q2'' ''p3'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   i = sch_s CHR ''i'' \\<Longrightarrow>\n   start_es = Task READY 1 tp \\<Longrightarrow>\n   blk1 = IOBlock (run_ch i) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p4'' (sched_assign i sch_es sch_s) sch_s dis_s (Task RUNNING 1 tp) task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q2'' ''p3'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task RUNNING 1 tp \\<Longrightarrow>\n   init_t = task_s (CHR ''t'') \\<Longrightarrow>\n   init_c = task_s (CHR ''c'') \\<Longrightarrow>\n   init_t' = dis_s (CHR ''t'') \\<Longrightarrow>\n   wt \\<le> 0.045 - init_t \\<Longrightarrow>\n   wt \\<le> 0.01 - init_c \\<Longrightarrow>\n   wt \\<le> 0.045 - init_t' \\<Longrightarrow>\n   wt > 0 \\<Longrightarrow>\n   blk1 = WaitBlk (ereal wt) (\\<lambda>t. ParState (EState (sch_es, sch_s)) (ParState\n      (EState (None, dis_s(CHR ''t'' := init_t' + t)))\n      (EState (start_es, task_s(CHR ''t'' := init_t + t, CHR ''c'' := init_c + t)))))\n      ({}, {preempt_ch i}\\<union> image req_ch {1,2,3} \\<union> image free_ch {1,2,3} \\<union> image exit_ch {1,2,3}) \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p4'' sch_es sch_s (dis_s(CHR ''t'' := init_t' + wt)) start_es (task_s(CHR ''t'' := init_t + wt,\n                                                 CHR ''c'' := init_c + wt)) rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p4'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task RUNNING 1 tp \\<Longrightarrow>\n   init_t = task_s (CHR ''t'') \\<Longrightarrow>\n   init_c = task_s (CHR ''c'') \\<Longrightarrow>\n   init_c = 0.01 \\<or> init_t = 0.045 \\<Longrightarrow>\n   blk1 = IOBlock (free_ch i) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q3'' ''p1'' sch_es (sch_s(CHR ''i'' := i)) dis_s (Task READY 1 tp) task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p4'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task RUNNING 1 tp \\<Longrightarrow>\n   j \\<noteq> i \\<Longrightarrow>\n   blk1 = InBlock (req_ch j) prior \\<Longrightarrow>\n   sch_task_dis_assn i ''q1'' ''p4'' sch_es (sch_s(CHR ''p'' := prior, CHR ''i'' := j)) dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p4'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task RUNNING 1 tp \\<Longrightarrow>\n   j = sch_s CHR ''i'' \\<Longrightarrow>\n   j \\<noteq> i \\<Longrightarrow>\n   prior = sch_s CHR ''p'' \\<Longrightarrow>\n   r_prior \\<ge> prior \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p4'' (sched_push j sch_es sch_s) sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q1'' ''p4'' sch_es sch_s dis_s start_es task_s rest\"\n\n(* \nr_now = i, r_prior = tp\n*)\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task RUNNING 1 tp \\<Longrightarrow>\n   j = sch_s CHR ''i'' \\<Longrightarrow>\n   j \\<noteq> i \\<Longrightarrow>   \n   prior = sch_s CHR ''p'' \\<Longrightarrow>\n   r_prior < prior \\<Longrightarrow>\n   blk1 = IOBlock (preempt_ch i) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q2'' ''p2'' sch_es sch_s dis_s (Task READY 1 tp) task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q1'' ''p4'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY 1 tp \\<Longrightarrow>\n   j = sch_s CHR ''i'' \\<Longrightarrow>\n   j \\<noteq> i \\<Longrightarrow>\n   prior = sch_s CHR ''p'' \\<Longrightarrow>\n   blk1 = OutBlock (run_ch j) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p2'' (sched_assign j sch_es sch_s) sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q2'' ''p2'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY 1 tp \\<Longrightarrow>\n   j \\<noteq> i \\<Longrightarrow>\n   blk1 = InBlock (free_ch j) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q3'' ''p4'' sch_es (sch_s(CHR ''i'' := j)) dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p4'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY 1 tp  \\<Longrightarrow>\n   length p > 0 \\<Longrightarrow>\n   blk1 = OutBlock (run_ch (snd (get_max p))) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p4'' (sched_get_max sch_es sch_s) sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q3'' ''p4'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY 1 tp \\<Longrightarrow>\n   length p = 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p4'' (sched_clear sch_es sch_s) sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q3'' ''p4'' sch_es sch_s dis_s start_es task_s rest\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY 1 tp \\<Longrightarrow>\n   j \\<noteq> i \\<Longrightarrow>\n   blk1 = InBlock (exit_ch j) 0 \\<Longrightarrow>\n   sch_task_dis_assn i ''q4'' ''p4'' sch_es (sch_s(CHR ''i'' := j)) dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p4'' sch_es sch_s dis_s start_es task_s (SCons blk1 rest)\"\n| \"sch_es = Sch p r_now r_prior \\<Longrightarrow>\n   start_es = Task READY 1 tp \\<Longrightarrow>\n   sch_task_dis_assn i ''q0'' ''p4'' (sched_del_proc (sch_s CHR ''i'') sch_es sch_s) sch_s dis_s start_es task_s rest \\<Longrightarrow>\n   sch_task_dis_assn i ''q4'' ''p4'' sch_es sch_s dis_s start_es task_s rest\"\n\n\ntheorem combine_sch_task_dis:\n  assumes \"i \\<in> {1,2,3}\"\n  shows \"sch_assn qc sch_es sch_s blks1 \\<Longrightarrow>\n         task_dis_assn i pc dis_s start_es task_s blks2 \\<Longrightarrow>\n         combine_blocks {req_ch i, run_ch i, free_ch i, preempt_ch i, exit_ch i} blks1 blks2 blks \\<Longrightarrow>\n         sch_task_dis_assn i qc pc sch_es sch_s dis_s start_es task_s blks\"\nproof (coinduction arbitrary: qc pc sch_es sch_s dis_s start_es task_s blks1 blks2 blks rule: sch_task_dis_assn.coinduct)\n  have comm_in_req:\"req_ch i \\<in> {req_ch i, run_ch i, free_ch i, preempt_ch i, exit_ch i}\"\n    by auto\n  have comm_in_exit:\"exit_ch i \\<in> {req_ch i, run_ch i, free_ch i, preempt_ch i, exit_ch i}\"\n    by auto\n  have comm_in_run:\"run_ch i \\<in> {req_ch i, run_ch i, free_ch i, preempt_ch i, exit_ch i}\"\n    by auto\n  have comm_in_preempt:\"preempt_ch i \\<in> {req_ch i, run_ch i, free_ch i, preempt_ch i, exit_ch i}\"\n    by auto\n  have comm_in_free:\"free_ch i \\<in> {req_ch i, run_ch i, free_ch i, preempt_ch i, exit_ch i}\"\n    by auto\n  have comm_not_in_dis:\"dispatch_ch i \\<notin> {req_ch i, run_ch i, free_ch i, preempt_ch i, exit_ch i}\"\n    apply(auto simp add: dispatch_ch_def req_ch_def run_ch_def free_ch_def preempt_ch_def exit_ch_def)\n    using assms by auto\n  case sch_task_dis_assn\n  from sch_task_dis_assn(1) \n  show ?case\n  proof (cases rule: sch_assn.cases)\n    case (1 p r_now r_prior wt1 blk1 rest1)\n    note s1 = 1\n    from sch_task_dis_assn(2) \n    show ?thesis \n    proof (cases rule : task_dis_assn.cases)\n      case (1 ent tp init_t' wt2 blk2 rest2)\n      note t1 = 1\n      obtain rest where rest:   \n        \"ereal wt1 = ereal wt2\"\n        \"blks = SCons (WaitBlk (ereal wt1) (\\<lambda>t. ParState (EState (sch_es, sch_s)) \n        (ParState (EState (None, dis_s(CHR ''t'' := init_t' + t))) (EState (start_es, task_s))))\n            ({}, {dispatch_ch i} \\<union> req_ch ` {1, 2, 3} \\<union> free_ch ` {1, 2, 3} \\<union> exit_ch ` {1, 2, 3})) rest\"\n        \"combine_blocks {req_ch i, run_ch i, free_ch i, preempt_ch i, exit_ch i} rest1 rest2 rest\"\n        using sch_task_dis_assn(3)[unfolded s1(2,5) t1(2,7)]\n        apply (elim combine_blocks_waitE)\n        by (smt merge_rdy.simps sup_assoc sup_commute sup_idem)\n      then show ?thesis using s1 t1 sch_task_dis_assn by auto\n    next\n      case (2 ent tp init_t' blk2 rest2)\n      note t2 = 2\n        obtain rest where rest:   \n        \"blks = SCons (IOBlock (dispatch_ch i) 0) rest\"\n        \"combine_blocks {req_ch i, run_ch i, free_ch i, preempt_ch i, exit_ch i} blks1 rest2 rest\"\n          using sch_task_dis_assn(3)[unfolded s1(2,5) t2(2,6)]\n          apply(simp add: s1(2,5) t2(2,6))\n          apply(elim combine_blocks_waitCommE2[OF comm_not_in_dis]) by blast\n      then show ?thesis using s1 t2 sch_task_dis_assn by auto\n    next\n      case (3 ent tp blk1 rest)\n      note t3 = 3\n      from sch_task_dis_assn(3)[unfolded s1(2,5) t3(2,4)]\n      show ?thesis by(elim combine_blocks_waitCommE[OF comm_in_req])\n    next\n      case (4 ent tp init_t init_t' wt2 blk2 dis_s rest2)\n      note t4 = 4\n      obtain rest where \n        \"ereal wt1 = ereal wt2\"\n        \"blks = SCons (WaitBlk (ereal wt1) (\\<lambda>t. ParState (EState (sch_es, sch_s)) \n        (ParState (EState (None, dis_s(CHR ''t'' := init_t' + t))) (EState (start_es, task_s(CHR ''t'' := init_t + t)))))\n            ({}, {run_ch i} \\<union> req_ch ` {1, 2, 3} \\<union> free_ch ` {1, 2, 3} \\<union> exit_ch ` {1, 2, 3})) rest\"\n        \"combine_blocks {req_ch i, run_ch i, free_ch i, preempt_ch i, exit_ch i} rest1 rest2 rest\"\n        using sch_task_dis_assn(3)[unfolded s1(2,5) t4(2,8)]\n        apply (elim combine_blocks_waitE) \n        by (smt (verit, ccfv_threshold) Un_insert_left Un_insert_right merge_rdy.simps sup_bot.left_neutral sup_bot_right)\n        then show ?thesis using s1 t4 sch_task_dis_assn by auto\n    next\n      case (5 ent tp init_t blk1 rest)\n      note t5 = 5\n      from sch_task_dis_assn(3)[unfolded s1(2,5) t5(2,6)]\n      show ?thesis by(elim combine_blocks_waitCommE[OF comm_in_exit])\n    next\n      case (6 tp blk1 rest)\n      note t6 = 6\n      from sch_task_dis_assn(3)[unfolded s1(2,5) t6(2,4)]\n      show ?thesis by(elim combine_blocks_waitCommE[OF comm_in_run])\n    next\n      case (7 tp blk1 rest)\n      note t7 = 7\n      from sch_task_dis_assn(3)[unfolded s1(2,5) t7(2,4)]\n      show ?thesis by(elim combine_blocks_waitCommE[OF comm_in_run])\n    next\n      case (8 tp init_t init_c init_t' wt2 blk2 rest2)\n      note t8 = 8\n      obtain rest where \n        \"ereal wt1 = ereal wt2\"\n        \"blks = SCons (WaitBlk (ereal wt1) (\\<lambda>t. ParState (EState (sch_es, sch_s)) \n        (ParState (EState (None, dis_s(CHR ''t'' := init_t' + t))) (EState (start_es, task_s(CHR ''t'' := init_t + t, CHR ''c'' := init_c + t)))))\n            ({}, {preempt_ch i} \\<union> req_ch ` {1, 2, 3} \\<union> free_ch ` {1, 2, 3} \\<union> exit_ch ` {1, 2, 3})) rest\"\n        \"combine_blocks {req_ch i, run_ch i, free_ch i, preempt_ch i, exit_ch i} rest1 rest2 rest\"\n        using sch_task_dis_assn(3)[unfolded s1(2,5) t8(2,11)]\n        apply (elim combine_blocks_waitE) \n        by (simp add: insert_commute)\n      then show ?thesis using s1 t8 sch_task_dis_assn by auto\n    next\n      case (9 tp blk1 rest)\n      note t9 = 9\n      from sch_task_dis_assn(3)[unfolded s1(2,5) t9(2,4)]\n      show ?thesis by(elim combine_blocks_waitCommE[OF comm_in_preempt])\n    next\n      case (10 tp init_t init_c blk1 rest)\n      note t10 =10\n      from sch_task_dis_assn(3)[unfolded s1(2,5) t10(2,7)]\n      show ?thesis by(elim combine_blocks_waitCommE[OF comm_in_free])\n    qed\n  next\n    case (2 p r_now r_prior blk1 j prior rest1)\n    note s2 = 2\n    from sch_task_dis_assn(2) \n    show ?thesis \n    proof (cases rule : task_dis_assn.cases)\n      case (1 ent tp init_t' wt blk2 rest2)\n      note t1 = 1\n      show ?thesis\n      proof (cases \"j = i\")\n        case True\n        from sch_task_dis_assn(3)[unfolded s2(2,4) t1(2,7) True]\n        show ?thesis by(elim combine_blocks_waitCommE'[OF comm_in_req])\n      next\n        case False\n        then have comm_not_in:\"(req_ch j) \\<notin> {req_ch i, run_ch i, free_ch i, preempt_ch i, exit_ch i}\"\n          apply(simp add: dispatch_ch_def req_ch_def run_ch_def free_ch_def preempt_ch_def exit_ch_def)\n          using assms s2(5) by auto \n        obtain rest where rest:\n        \"blks = SCons (InBlock (req_ch j) prior) rest\"\n        \"combine_blocks {req_ch i, run_ch i, free_ch i, preempt_ch i, exit_ch i} rest1 blks2 rest\"\n          using sch_task_dis_assn(3)[unfolded s2(2,4) t1(2,7)]\n          apply(simp add: t1(2,7))\n          apply(elim combine_blocks_waitCommE2'[OF comm_not_in]) by auto\n        show ?thesis \n         apply(rule disjI2)\n          apply(rule disjI1)\n          apply(rule exI[where x=\"sch_es\"])\n          apply(rule exI[where x=\"pool sch_es\"])\n          apply(rule exI[where x=\"run_now sch_es\"])\n          apply(rule exI[where x=\"run_prior sch_es\"])\n          apply(rule exI[where x=\"start_es\"])\n          apply(rule exI[where x=\"entered start_es\"])\n          apply(rule exI[where x=\"task_prior start_es\"])\n          apply(rule exI[where x=\"j\"])\n          apply(rule exI[where x=\"i\"])\n          apply(rule exI[where x=\"(InBlock (req_ch j) prior)\"])\n          apply(rule exI[where x=\"prior\"])\n          apply(rule exI[where x=\"sch_s\"])\n          apply(rule exI[where x=\"dis_s\"])\n          apply(rule exI[where x=\"task_s\"])\n          apply(rule exI[where x=\"rest\"])\n          apply(intro conjI)\n          apply(rule refl, simp add: s2 t1)+\n          using t1 apply simp\n          apply(rule refl)+\n          using rest apply simp\n          using s2 apply simp\n          using t1 apply simp\n          using False apply simp\n          apply(rule refl)\n          apply(rule disjI1)\n          apply(rule exI[where x=\"''q1''\"])\n          apply(rule exI[where x=\"''p1''\"])\n          apply(rule exI[where x=\"sch_es\"])\n          apply(rule exI[where x=\"sch_s(CHR ''p'' := prior, CHR ''i'' := j)\"])\n          apply(rule exI[where x=\"dis_s\"])\n          apply(rule exI[where x=\"start_es\"])\n          apply(rule exI[where x=\"task_s\"])\n          apply(rule exI[where x=\"rest1\"])\n          apply(rule exI[where x=\"blks2\"])\n          apply(rule exI[where x=\"rest\"])\n          apply(intro conjI)\n          apply(rule refl)+\n          using s2 apply simp\n          using sch_task_dis_assn t1 apply simp\n          using rest apply simp\n          done\n      qed\n    next\n      case (2 ent tp init_t' blk2 rest2)\n      note t2 = 2\n      show ?thesis \n      proof (cases \" j = i\")\n        case True\n        obtain rest where\n          \"blks = SCons (IOBlock (dispatch_ch i) 0) rest\"\n          \"combine_blocks {req_ch i, run_ch i, free_ch i, preempt_ch i, exit_ch i} blks1 rest2 rest\"\n          using sch_task_dis_assn(3)[unfolded s2(2,4) t2(2,6) True]\n          apply (simp add: s2(2,4) t2(2,6) True)\n          apply(elim combine_blocks_unpairE1'[OF comm_in_req comm_not_in_dis]) by blast\n        then show ?thesis using sch_task_dis_assn s2 t2 True by auto\n      next\n        case False\n        then have comm_not_in:\"(req_ch j) \\<notin> {req_ch i, run_ch i, free_ch i, preempt_ch i, exit_ch i}\"\n          apply(simp add: dispatch_ch_def req_ch_def run_ch_def free_ch_def preempt_ch_def exit_ch_def)\n          using assms s2(5) by auto \n        obtain rest where\n          \"blks = SCons (InBlock (req_ch j) prior) rest\"\n          \"combine_blocks {req_ch i, run_ch i, free_ch i, preempt_ch i, exit_ch i} rest1 blks2 rest\"\n          using sch_task_dis_assn(3)[unfolded s2(2,4) t2(2,6)]\n          apply (simp add: s2(2,4) t2(2,6))\n          apply(elim combine_blocks_unpairE2[OF comm_not_in comm_not_in_dis]) \n        then show ?thesis sorry\n      qed\n\n    next\n      case (3 ent tp blk1 rest)\n      then show ?thesis sorry\n    next\n      case (4 ent tp init_t init_t' wt blk1 dis_t rest)\n      then show ?thesis sorry\n    next\n      case (5 ent tp init_t blk1 rest)\n      then show ?thesis sorry\n    next\n      case (6 tp blk1 rest)\n      then show ?thesis sorry\n    next\n      case (7 tp blk1 rest)\n      then show ?thesis sorry\n    next\n      case (8 tp init_t init_c init_t' wt blk1 rest)\n      then show ?thesis sorry\n    next\n      case (9 tp blk1 rest)\n      then show ?thesis sorry\n    next\n      case (10 tp init_t init_c blk1 rest)\n      then show ?thesis sorry\n    qed\n  next\n    case (3 p r_now r_prior i prior)\n    then show ?thesis sorry\n  next\n    case (4 p r_now r_prior i prior blk1 rest)\n    then show ?thesis sorry\n  next\n    case (5 p r_now r_prior i prior)\n    then show ?thesis sorry\n  next\n    case (6 p r_now r_prior i prior blk1 rest)\n    then show ?thesis sorry\n  next\n    case (7 p r_now r_prior blk1 i rest)\n    then show ?thesis sorry\n  next\n    case (8 p r_now r_prior blk1 rest)\n    then show ?thesis sorry\n  next\n    case (9 p r_now r_prior)\n    then show ?thesis sorry\n  next\n    case (10 p r_now r_prior blk1 i rest)\n    then show ?thesis sorry\n  next\n    case (11 p r_now r_prior)\n    then show ?thesis sorry\n  qed\nqed\n\nend\n", "meta": {"author": "bzhan", "repo": "mars", "sha": "d10e489a8ddf128a4cbac13291efdece458d732d", "save_path": "github-repos/isabelle/bzhan-mars", "path": "github-repos/isabelle/bzhan-mars/mars-d10e489a8ddf128a4cbac13291efdece458d732d/lunarlander_sl/Coinductive.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5078118642792043, "lm_q2_score": 0.5, "lm_q1q2_score": 0.25390593213960216}}
{"text": "theory Buchberger_Timings\n  imports Groebner_Bases.Buchberger_Examples Print\nbegin\n\nsubsection \\<open>Scalar Polynomials\\<close>\n\nfunction trd_aux_punit_print where\n  \"trd_aux_punit_print to fs p r (i::nat) (j::nat) =\n    (if is_zero p then\n      print (i, j) r\n    else\n      case find_adds_punit to fs (lt_punit to p) of\n        None   \\<Rightarrow> trd_aux_punit_print to fs (tail_punit to p) (plus_monomial_less r (lc_punit to p) (lt_punit to p)) (Suc i) j\n      | Some f \\<Rightarrow> trd_aux_punit_print to fs\n                    (timing (tail_punit to p - monom_mult_punit (lc_punit to p / lc_punit to f) (lt_punit to p - lt_punit to f) (tail_punit to f)))\n                    (print (lc_punit to p / lc_punit to f) r)\n                    i (Suc j)\n    )\"\n  by auto\ntermination sorry\n\nlemma compute_trd_punit [code]: \"trd_punit to fs p = trd_aux_punit to fs p (change_ord to 0)\"\n  by (simp add: punit'.punit.trd_def change_ord_def)\n\ndefinition \"product_crit_punit_print to =\n  (\\<lambda>gs bs ps data p q. if product_crit_punit to gs bs ps data p q then (print ''prod'' True) else False)\"\n\ndefinition \"chain_ncrit_punit_print to =\n  (\\<lambda>data gs bs hs ps q_in_bs p q. if chain_ncrit_punit to data gs bs hs ps q_in_bs p q then (print ''nchain'' True) else False)\"\n\ndefinition \"chain_ocrit_punit_print to =\n  (\\<lambda>data hs ps p q. if chain_ocrit_punit to data hs ps p q then (print ''ochain'' True) else False)\"\n\ndefinition \"trdsp_punit_timing to = (\\<lambda>bs p. timing_lbl ''trdsp'' (trd_punit to bs (spoly_punit to (fst (fst p)) (fst (snd p)))))\"\n\ndefinition \"trdsp_punit_print to = (\\<lambda>bs p. (let res = trd_punit to bs (spoly_punit to (fst (fst p)) (fst (snd p))) in if res = 0 then print ''0'' res else res))\"\n\ndefinition \"add_pairs_punit_timing =\n  (\\<lambda>np icrit ncrit ocrit comb gs bs ps hs data.\n      timing_lbl ''ap''\n        (let ps1 = apply_ncrit_punit ncrit data gs bs hs (apply_icrit_punit icrit data gs bs hs (np gs bs hs data));\n             ps2 = apply_ocrit_punit ocrit data hs ps1 ps in comb (map snd [x\\<leftarrow>ps1 . \\<not> fst x]) ps2))\"\n\ndefinition \"add_pairs_punit_print =\n  (\\<lambda>np icrit ncrit ocrit comb gs bs ps hs data.\n      (let ps0 = np gs bs hs data;\n           ps1 = apply_ncrit_punit ncrit data gs bs hs (apply_icrit_punit icrit data gs bs hs ps0);\n           ps2 = apply_ocrit_punit ocrit data hs ps1 ps;\n           ps3 = [x\\<leftarrow>ps1 . \\<not> fst x] in print ((length ps + length ps0) - (length ps2 + length ps3)) (comb (map snd ps3) ps2)))\"\n\ndefinition \"add_basis_sorted_print =\n  (\\<lambda>rel gs bs ns data. (if length ns = 0 then (\\<lambda>_ x. x) else print) (length bs + length ns, map (card_keys \\<circ> fst) ns) (merge_wrt (rel data) bs ns))\"\n\ndefinition \"add_basis_sorted_timing =\n  (\\<lambda>rel gs bs ns data. timing_lbl ''ab'' (merge_wrt (rel data) bs ns))\"\n\ndefinition \"gb_sel_punit_print =\n  (\\<lambda>_ _ ps _. print (length ps) (if List.null ps then [] else [hd ps]))\"\n\nlemma product_crit_punit_print [simp]: \"product_crit_punit_print = product_crit_punit\"\n  by (rule ext, simp add: product_crit_punit_print_def)\n\nlemma chain_ncrit_punit_print [simp]: \"chain_ncrit_punit_print = chain_ncrit_punit\"\n  by (rule ext, simp add: chain_ncrit_punit_print_def)\n\nlemma chain_ocrit_punit_print [simp]: \"chain_ocrit_punit_print = chain_ocrit_punit\"\n  by (rule ext, simp add: chain_ocrit_punit_print_def)\n\n\n(*\nlemma gb_sel_punit_print [code_abbrev]: \"gb_sel_punit_print = gb_sel_punit\"\n  apply (simp add: gb_sel_punit_print_def Let_def) sorry\n*)\n\n(*\nlemma discard_red_cp_punit_timing [code_abbrev]: \"discard_red_cp_punit_timing = discard_red_cp_punit\"\n  sorry\n\nlemma add_pairs_sorted_punit_timing [code_abbrev]: \"add_pairs_sorted_punit_timing = add_pairs_sorted_punit\"\n  sorry\n\nlemma add_basis_sorted_timing [code_abbrev]: \"add_basis_sorted_timing = add_basis_sorted\"\n  sorry\n*)\n\n(*\nlemma add_pairs_punit_canon_print [code_abbrev]: \"add_pairs_punit_print = add_pairs_punit\"\n  sorry\n*)\n\n(*\nlemma add_basis_sorted_print [code_abbrev]: \"add_basis_sorted_print = add_basis_sorted\"\n  sorry\n*)\n\n(*\nlemma trd_punit_print [code_abbrev]: \"trd_punit_print = trd_punit\"\n  sorry\n*)\n\n(*\nlemma compute_trd_punit [code]: \"trd_punit fs p = trd_aux_punit_print fs p 0 0 0\"\n  sorry\n*)\n\n(*\nlemma trdsp_punit_timing [code_abbrev]: \"trdsp_punit_timing = trdsp_punit\"\n  sorry\n*)\n\n(*\nlemma trdsp_punit_print [code_abbrev]: \"trdsp_punit_print = trdsp_punit\"\n  sorry\n*)\n\nvalue [code] \"timing (length (gb_punit DRLEX (map (\\<lambda>p. (p, ())) ((eco DRLEX 8)::(_ \\<Rightarrow>\\<^sub>0 rat) list)) ()))\"\n\nend (* theory *)\n", "meta": {"author": "amaletzk", "repo": "Isabelle-Groebner", "sha": "34e25806ec60a4bee8f21b038eeaaf1065d9f6d0", "save_path": "github-repos/isabelle/amaletzk-Isabelle-Groebner", "path": "github-repos/isabelle/amaletzk-Isabelle-Groebner/Isabelle-Groebner-34e25806ec60a4bee8f21b038eeaaf1065d9f6d0/Buchberger_Timings.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526514141571, "lm_q2_score": 0.44552953503957266, "lm_q1q2_score": 0.2538861868256171}}
{"text": "theory flash4Rev imports flashPub\nbegin\nsection{*Main defintions*}\nlemma NI_FAckVsInv4:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvVsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_InvAck_1VsInv4:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3 a4 a5 a6,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1_HomeVsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_InvAck_2VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_GetX_GetXVsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak1VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak2VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak3VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX1VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv4:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10VsInv4:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10_homeVsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX11VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''Dir_local'') )  ( Const true ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_GetVsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Local_Get_Nak1VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak2VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak3VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put1VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put2VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put3VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_PutVsInv4:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_PutXAcksDoneVsInv4:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_NakVsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Nak_ClearVsInv4:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Nak_HomeVsInv4:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_NakVsInv4:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_Nak_HomeVsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Remote_GetX_PutXVsInv4:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  a5  a6  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iRule2) )  ( Const CACHE_E ))    ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_PutX_HomeVsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Nak1VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_Remote_Get_Nak2VsInv4:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Put1VsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Put2VsInv4:  \n    (*Rule2VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iInv2 \\<le> N\" and  a5:\"iInv1~=iInv2  \" and  a6:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>iRule2=iInv2)   \\<or>(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>(iRule1=iInv2\\<and>iRule2=iInv1)   \\<or>(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  a5  a6  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>iRule2=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 )\\<and>(iRule2~=iInv1 \\<and>iRule2~=iInv2 ))\"\n\n                  have \"?P1 s \\<or> ?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  a5  a6  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutVsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                     have allCases:\"formEval  ( eqn ( IVar ( Para ''InvMarked'' iInv1) )  ( Const true ))  s  \\<or>formEval   (neg ( eqn ( IVar ( Para ''InvMarked'' iInv1) )  ( Const true )) )  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume c1:\"formEval ( eqn ( IVar ( Para ''InvMarked'' iInv1) )  ( Const true ))  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1  c1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n\n    moreover\n                       {assume c1:\"formEval  (neg ( eqn ( IVar ( Para ''InvMarked'' iInv1) )  ( Const true )) )  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1  c1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n   ultimately have \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutXVsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  a3  a4  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv2) )  ( Const UNI_PutX ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_PutX ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_ReplaceVsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_ReplaceHomeVsInv4:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceHomeShrVldVsInv4:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceShrVldVsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma NI_ShWbVsInv4:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_WbVsInv4:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_GetX1VsInv4:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_GetX2VsInv4:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX1VsInv4:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX2VsInv4:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX3VsInv4:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_GetX_PutX4VsInv4:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_Get_GetVsInv4:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_Get_PutVsInv4:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_PutXVsInv4:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Local_ReplaceVsInv4:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_GetVsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_GetXVsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_PutXVsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>(iRule1=iInv2)   \\<or>((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"(iRule1=iInv2)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 \\<and>iRule1~=iInv2 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_ReplaceVsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma StoreVsInv4:  \n    (*Rule1VsPInv2*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" and  a3:\"iInv2 \\<le> N\" and  a4:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1  a2  a3  a4 , auto)\n lemma StoreHomeVsInv4:  \n    (*Rule0VsPInv2*)\n  assumes   a1:\"iInv1 \\<le> N\" and  a2:\"iInv2 \\<le> N\" and  a3:\"iInv1~=iInv2  \" \n\n  shows  \"invHoldForRule' s (inv4  iInv1  iInv2 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3, auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash4Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5698526368038304, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.253886180316285}}
{"text": "theory Std_to_Inca_compiler\n  imports Std_to_Inca_simulation\n    \"VeriComp.Compiler\"\nbegin\n\n\nsubsection \\<open>Compilation of function definitions\\<close>\n\nfun compile_instr where\n  \"compile_instr (Std.IPush d) = Inca.IPush d\" |\n  \"compile_instr Std.IPop = Inca.IPop\" |\n  \"compile_instr (Std.IGet n) = Inca.IGet n\" |\n  \"compile_instr (Std.ISet n) = Inca.ISet n\" |\n  \"compile_instr (Std.ILoad x) = Inca.ILoad x\" |\n  \"compile_instr (Std.IStore x) = Inca.IStore x\" |\n  \"compile_instr (Std.IOp op) = Inca.IOp op\" |\n  \"compile_instr (Std.ICJump l\\<^sub>t l\\<^sub>f) = Inca.ICJump l\\<^sub>t l\\<^sub>f\" |\n  \"compile_instr (Std.ICall f) = Inca.ICall f\" |\n  \"compile_instr Std.IReturn = Inca.IReturn\"\n\nfun compile_fundef where\n  \"compile_fundef (Fundef [] _ _ _) = None\" |\n  \"compile_fundef (Fundef bblocks ar ret locals) =\n    Some (Fundef (map_ran (\\<lambda>_. map compile_instr) bblocks) ar ret locals)\"\n\ncontext std_inca_simulation begin\n\nlemma lambda_eq_eq[simp]: \"(\\<lambda>x y. y = x) = (=)\"\n  apply (intro ext)\n  by blast\n\nlemma norm_compile_instr:\n  \"norm_instr (compile_instr instr) = instr\"\nby (cases instr) auto\n\nlemma rel_compile_fundef:\n  assumes \"compile_fundef fd1 = Some fd2\"\n  shows \"rel_fundef (=) norm_eq fd1 fd2\"\n  using assms\nproof (cases rule: compile_fundef.elims)\n  case (2 x xs ar)\n  then show ?thesis\n    by (auto intro: list.rel_refl\n        simp: const_eq_if_conv list.rel_map norm_compile_instr map_ran_def case_prod_beta\n          rel_prod_sel)\nqed simp_all\n\nlemma rel_fundef_imp_fundef_ok_iff:\n  assumes \"rel_fundef (=) norm_eq fd1 fd2\"\n  shows \"wf_fundef fd1 \\<longleftrightarrow> wf_fundef fd2\"\n  unfolding wf_fundef_def\n  using assms\n  by (auto simp: list_all2_rel_prod_conv list.rel_eq elim: fundef.rel_cases)\n\nlemma rel_fundefs_imp_wf_fundefs_iff:\n  assumes rel_f_g: \"rel_fundefs f g\"\n  shows \"wf_fundefs f \\<longleftrightarrow> wf_fundefs g\"\nproof (rule iffI)\n  assume \"wf_fundefs f\" show \"wf_fundefs g\"\n  proof (rule wf_fundefsI)\n    fix x fd\n    assume \"g x = Some fd\" thus \"wf_fundef fd\"\n      using \\<open>wf_fundefs f\\<close>\n      by (meson rel_f_g rel_fundef_imp_fundef_ok_iff rel_fundefs_Some2 wf_fundefs_imp_wf_fundef)\n  qed\nnext\n  show \"wf_fundefs g \\<Longrightarrow> wf_fundefs f\"\n    using rel_f_g\n    by (meson rel_fundef_imp_fundef_ok_iff rel_fundefs_Some1 wf_fundefs_imp_wf_fundef wf_fundefsI)\nqed\n\nlemma compile_fundef_wf:\n  assumes \"compile_fundef fd = Some fd'\"\n  shows \"wf_fundef fd'\"\n  using assms\nproof (cases rule: compile_fundef.elims)\n  case (2 x xs ar)\n  then show ?thesis\n    by (simp add: const_eq_if_conv wf_fundef_def map_ran_Cons_sel)\nqed simp_all\n\n\nsubsection \\<open>Compilation of function environments\\<close>\n\ndefinition compile_env where\n  \"compile_env e \\<equiv>\n    Some Sinca.Fenv.from_list \\<diamondop> ap_map_list (ap_map_prod Some compile_fundef) (Fstd_to_list e)\"\n\nlemma compile_env_imp_rel_option:\n  assumes \"compile_env F1 = Some F2\"\n  shows \"rel_option (\\<lambda>fd1 fd2. compile_fundef fd1 = Some fd2) (Fstd_get F1 f) (Finca_get F2 f)\"\nproof -\n  from assms(1) obtain xs where\n    ap_map_list_F1: \"ap_map_list (ap_map_prod Some compile_fundef) (Fstd_to_list F1) = Some xs\" and\n    F2_def: \"F2 = Sinca.Fenv.from_list xs\"\n    by (auto simp add: compile_env_def ap_option_eq_Some_conv)\n\n  show ?thesis\n    unfolding F2_def Sinca.Fenv.from_list_correct[symmetric]\n    unfolding Sinca.Fenv.from_list_correct\n    unfolding Sstd.Fenv.to_list_correct[symmetric]\n    using ap_map_list_F1\n    by (simp add: ap_map_list_ap_map_prod_imp_rel_option_map_of)\nqed\n\nlemma Finca_get_compile:\n  assumes compile_F1: \"compile_env F1 = Some F2\"\n  shows \"Finca_get F2 f = Fstd_get F1 f \\<bind> compile_fundef\"\n  using compile_env_imp_rel_option[OF assms(1), of f]\n  by (auto elim!: option.rel_cases)\n\nlemma compile_env_rel_fundefs:\n  assumes \"compile_env F1 = Some F2\"\n  shows \"rel_fundefs (Fstd_get F1) (Finca_get F2)\"\n  unfolding rel_fundefs_def\nproof (rule allI)\n  fix f\n  show \"rel_option (rel_fundef (=) norm_eq) (Fstd_get F1 f) (Finca_get F2 f)\"\n    using compile_env_imp_rel_option[OF assms(1), of f]\n    by (auto elim!: option.rel_cases intro: rel_compile_fundef)\nqed\n\nlemma compile_env_imp_wf_fundefs2:\n  assumes \"compile_env F1 = Some F2\"\n  shows \"wf_fundefs (Finca_get F2)\"\n  unfolding Finca_get_compile[OF assms(1)]\n  by (auto simp: bind_eq_Some_conv intro!: wf_fundefsI intro: compile_fundef_wf)\n\n\nsubsection \\<open>Compilation of programs\\<close>\n\nfun compile where\n  \"compile (Prog F1 H f) = Some Prog \\<diamondop> compile_env F1 \\<diamondop> Some H \\<diamondop> Some f\"\n\ntheorem compile_load:\n  assumes\n    compile_p1: \"compile p1 = Some p2\" and\n    load: \"Sinca.load p2 s2\"\n  shows \"\\<exists>s1. Sstd.load p1 s1 \\<and> match s1 s2\"\nproof (cases p1)\n  case (Prog F1 H main)\n  with assms(1) obtain F2 where\n    compile_F1: \"compile_env F1 = Some F2\" and\n    p2_def: \"p2 = Prog F2 H main\"\n    by (auto simp: ap_option_eq_Some_conv)\n\n  show ?thesis\n    using assms(2) unfolding p2_def Sinca.load_def\n  proof (cases _ _ _ s2 rule: load.cases)\n    case (1 fd2)\n    from 1 obtain fd1 where\n      F1_main: \"Fstd_get F1 main = Some fd1\" and compile_fd1: \"compile_fundef fd1 = Some fd2\"\n      using Finca_get_compile[OF compile_F1] by (auto simp: bind_eq_Some_conv)\n\n    note rel_fd1_fd2 = rel_compile_fundef[OF compile_fd1]\n    hence first_label_fd1_fd2: \"fst (hd (body fd1)) = fst (hd (body fd2))\"\n      using 1\n      by (auto elim!: fundef.rel_cases dest: list_all2_rel_prod_fst_hd)\n\n    have bodies_fd1_fd2: \"body fd1 = [] \\<longleftrightarrow> body fd2 = []\"\n      using rel_fundef_body_length[OF rel_fd1_fd2]\n      by auto\n\n    let ?s1 = \"State F1 H [allocate_frame main fd1 [] uninitialized]\"\n\n    show ?thesis\n    proof (intro exI conjI)\n      show \"Sstd.load p1 ?s1\"\n        unfolding Prog\n        using 1 F1_main rel_fd1_fd2 bodies_fd1_fd2\n        by (auto simp: rel_fundef_arities Sstd.load_def intro!: load.intros)\n    next\n      note rel_F1_F2 = compile_env_rel_fundefs[OF compile_F1]\n      moreover have \"wf_fundefs (Fstd_get F1)\"\n      proof (rule wf_fundefsI)\n        fix f fd1\n        assume \"Fstd_get F1 f = Some fd1\"\n        then show \"wf_fundef fd1\"\n          by (metis (mono_tags, lifting) Finca_get_compile bind.bind_lunit compile_F1\n              rel_F1_F2 compile_fundef_wf rel_fundef_imp_fundef_ok_iff\n              rel_fundefs_Some1)\n      qed\n      ultimately show \"match ?s1 s2\"\n        unfolding 1\n        using rel_fd1_fd2\n        by (auto simp: allocate_frame_def first_label_fd1_fd2 rel_fundef_locals\n            intro: match.intros)\n    qed\n  qed\nqed\n\nsublocale std_to_inca_compiler:\n  compiler where\n    step1 = Sstd.step and final1 = \"final Fstd_get Std.IReturn\" and load1 = \"Sstd.load\" and\n    step2 = Sinca.step and final2 = \"final Finca_get Inca.IReturn\" and load2 = \"Sinca.load\" and\n    order = \"\\<lambda>_ _. False\" and match = \"\\<lambda>_. match\" and compile = compile\n  using compile_load\n  by unfold_locales  auto\n\n\nsubsection \\<open>Completeness of compilation\\<close>\n\nlemma compile_fundef_complete:\n  assumes \"wf_fundef fd1\"\n  shows \"\\<exists>fd2. compile_fundef fd1 = Some fd2\"\nproof (cases fd1)\n  case (Fundef bbs ar)\n  then obtain bb bbs' where bbs_def: \"bbs = bb # bbs'\"\n    using assms(1) by (cases bbs; auto)\n  show ?thesis\n    using assms\n    unfolding Fundef bbs_def\n    by simp\nqed\n\nlemma compile_env_complete:\n  assumes wf_F1: \"wf_fundefs (Fstd_get F1)\"\n  shows \"\\<exists>F2. compile_env F1 = Some F2\"\nproof -\n  show ?thesis\n    using wf_F1\n    by (auto simp: compile_env_def ap_option_eq_Some_conv ap_map_prod_eq_Some_conv\n        intro!: ex_ap_map_list_eq_SomeI Sstd.Fenv.to_list_list_allI compile_fundef_complete\n        intro: wf_fundefs_imp_wf_fundef)\nqed\n\ntheorem compile_complete:\n  assumes wf_p1: \"wf_prog Fstd_get p1\"\n  shows \"\\<exists>p2. compile p1 = Some p2\"\nproof (cases p1)\n  case (Prog x1 x2 x3)\n  then show ?thesis\n    using wf_p1 unfolding wf_prog_def\n    by (auto dest: compile_env_complete)\nqed\n\ntheorem compile_load_forward:\n  assumes\n    wf_p1: \"wf_prog Fstd_get p1\" and load_p1: \"Sstd.load p1 s1\"\n  shows \"\\<exists>p2 s2. compile p1 = Some p2 \\<and> Sinca.load p2 s2 \\<and> match s1 s2\"\nproof -\n  from load_p1 obtain F1 H main fd1 where\n    p1_def: \"p1 = Prog F1 H main\" and\n    s1_def: \"s1 = Global.state.State F1 H [allocate_frame main fd1 [] uninitialized]\" and\n    F1_main: \"Fstd_get F1 main = Some fd1\" and\n    arity_fd1: \"arity fd1 = 0\"\n    by (auto simp: Sstd.load_def elim: load.cases)\n\n  obtain F2 where compile_F1: \"compile_env F1 = Some F2\"\n    using wf_p1[unfolded p1_def wf_prog_def, simplified]\n    using compile_env_complete[of F1]\n    by auto\n\n  obtain fd2 where\n    F2_main: \"Finca_get F2 main = Some fd2\" and compile_fd1: \"compile_fundef fd1 = Some fd2\"\n    using compile_env_imp_rel_option[OF compile_F1, of main]\n    unfolding F1_main option_rel_Some1\n    by auto\n\n  hence rel_fd1_fd2: \"rel_fundef (=) norm_eq fd1 fd2\"\n    using rel_compile_fundef by auto\n\n  note wf_fd2 = compile_fundef_wf[OF compile_fd1]\n\n  let ?s2 = \"State F2 H [allocate_frame main fd2 [] uninitialized]\"\n\n  show ?thesis\n  proof (intro exI conjI)\n    show \"compile p1 = Some (Prog F2 H main)\"\n      by (simp add: p1_def compile_F1)\n  next\n    show \"Sinca.load (Prog F2 H main) ?s2\"\n      using F2_main arity_fd1\n      using rel_fundef_arities[OF rel_fd1_fd2]\n      using compile_fundef_wf[OF compile_fd1]\n      by (auto simp: wf_fundef_def Sinca.load_def intro: load.intros)\n  next\n    have \"fst (hd (body fd1)) = fst (hd (body fd2))\"\n      using rel_fd1_fd2 wf_fd2\n      by (auto simp add: fundef.rel_sel wf_fundef_def list_all2_rel_prod_fst_hd)\n    moreover have \"wf_fundefs (Fstd_get F1)\"\n      using compile_env_imp_wf_fundefs2[OF compile_F1]\n      using compile_env_rel_fundefs[OF compile_F1, THEN rel_fundefs_imp_wf_fundefs_iff]\n      by simp\n    ultimately show \"match s1 ?s2\"\n      unfolding s1_def\n      using rel_fd1_fd2 compile_env_rel_fundefs[OF compile_F1]\n      by (auto simp: allocate_frame_def rel_fundef_locals intro!: match.intros)\n  qed\nqed\n\nend\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Interpreter_Optimizations/Std_to_Inca_compiler.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5117166047041654, "lm_q2_score": 0.49609382947091946, "lm_q1q2_score": 0.2538594500315461}}
{"text": "(*  Title:      Jinja/J/SmallTypeSafe.thy\n\n    Author:     Tobias Nipkow\n    Copyright   2003 Technische Universitaet Muenchen\n*)\n\nheader {* \\isaheader{Type Safety Proof} *}\n\ntheory TypeSafe\nimports Progress JWellForm\nbegin\n\nsubsection{*Basic preservation lemmas*}\n\ntext{* First two easy preservation lemmas. *}\n\ntheorem red_preserves_hconf:\n  \"P \\<turnstile> \\<langle>e,(h,l)\\<rangle> \\<rightarrow> \\<langle>e',(h',l')\\<rangle> \\<Longrightarrow> (\\<And>T E. \\<lbrakk> P,E,h \\<turnstile> e : T; P \\<turnstile> h \\<surd> \\<rbrakk> \\<Longrightarrow> P \\<turnstile> h' \\<surd>)\"\nand reds_preserves_hconf:\n  \"P \\<turnstile> \\<langle>es,(h,l)\\<rangle> [\\<rightarrow>] \\<langle>es',(h',l')\\<rangle> \\<Longrightarrow> (\\<And>Ts E. \\<lbrakk> P,E,h \\<turnstile> es [:] Ts; P \\<turnstile> h \\<surd> \\<rbrakk> \\<Longrightarrow> P \\<turnstile> h' \\<surd>)\"\n(*<*)\nproof (induct rule:red_reds_inducts)\n  case (RedNew h a C FDTs h' l)\n  have new: \"new_Addr h = Some a\" and fields: \"P \\<turnstile> C has_fields FDTs\"\n   and h': \"h' = h(a\\<mapsto>(C, init_fields FDTs))\"\n   and hconf: \"P \\<turnstile> h \\<surd>\" by fact+\n  from new have None: \"h a = None\" by(rule new_Addr_SomeD)\n  moreover have \"P,h \\<turnstile> (C,init_fields FDTs) \\<surd>\"\n    using fields by(rule oconf_init_fields)\n  ultimately show \"P \\<turnstile> h' \\<surd>\" using h' by(fast intro: hconf_new[OF hconf])\nnext\n  case (RedFAss h a C fs F D v l)\n  let ?fs' = \"fs((F,D)\\<mapsto>v)\"\n  have hconf: \"P \\<turnstile> h \\<surd>\" and ha: \"h a = Some(C,fs)\"\n   and wt: \"P,E,h \\<turnstile> addr a\\<bullet>F{D}:=Val v : T\" by fact+\n  from wt ha obtain TF Tv where typeofv: \"typeof\\<^bsub>h\\<^esub> v = Some Tv\"\n    and has: \"P \\<turnstile> C has F:TF in D\"\n    and sub: \"P \\<turnstile> Tv \\<le> TF\" by auto\n  have \"P,h \\<turnstile> (C, ?fs') \\<surd>\"\n  proof (rule oconf_fupd[OF has])\n    show \"P,h \\<turnstile> (C, fs) \\<surd>\" using hconf ha by(simp add:hconf_def)\n    show \"P,h \\<turnstile> v :\\<le> TF\" using sub typeofv by(simp add:conf_def)\n  qed\n  with hconf ha show \"P \\<turnstile> h(a\\<mapsto>(C, ?fs')) \\<surd>\"  by (rule hconf_upd_obj)\nqed auto\n(*>*)\n\n\ntheorem red_preserves_lconf:\n  \"P \\<turnstile> \\<langle>e,(h,l)\\<rangle> \\<rightarrow> \\<langle>e',(h',l')\\<rangle> \\<Longrightarrow>\n  (\\<And>T E. \\<lbrakk> P,E,h \\<turnstile> e:T; P,h \\<turnstile> l (:\\<le>) E \\<rbrakk> \\<Longrightarrow> P,h' \\<turnstile> l' (:\\<le>) E)\"\nand reds_preserves_lconf:\n  \"P \\<turnstile> \\<langle>es,(h,l)\\<rangle> [\\<rightarrow>] \\<langle>es',(h',l')\\<rangle> \\<Longrightarrow>\n  (\\<And>Ts E. \\<lbrakk> P,E,h \\<turnstile> es[:]Ts; P,h \\<turnstile> l (:\\<le>) E \\<rbrakk> \\<Longrightarrow> P,h' \\<turnstile> l' (:\\<le>) E)\"\n(*<*)\nproof(induct rule:red_reds_inducts)\n  case RedNew thus ?case\n    by(fast intro:lconf_hext red_hext_incr[OF red_reds.RedNew])\nnext\n  case RedLAss thus ?case by(fastforce elim: lconf_upd simp:conf_def)\nnext\n  case RedFAss thus ?case\n    by(fast intro:lconf_hext red_hext_incr[OF red_reds.RedFAss])\nnext\n  case (InitBlockRed e h l V v e' h' l' v' T T')\n  have red: \"P \\<turnstile> \\<langle>e, (h, l(V\\<mapsto>v))\\<rangle> \\<rightarrow> \\<langle>e',(h', l')\\<rangle>\"\n   and IH: \"\\<And>T E . \\<lbrakk> P,E,h \\<turnstile> e:T; P,h \\<turnstile> l(V\\<mapsto>v) (:\\<le>) E \\<rbrakk>\n                     \\<Longrightarrow> P,h' \\<turnstile> l' (:\\<le>) E\"\n   and l'V: \"l' V = Some v'\" and lconf: \"P,h \\<turnstile> l (:\\<le>) E\"\n   and wt: \"P,E,h \\<turnstile> {V:T := Val v; e} : T'\" by fact+\n  from lconf_hext[OF lconf red_hext_incr[OF red]]\n  have \"P,h' \\<turnstile> l (:\\<le>) E\" .\n  moreover from IH lconf wt have \"P,h' \\<turnstile> l' (:\\<le>) E(V\\<mapsto>T)\"\n    by(auto simp del: fun_upd_apply simp: fun_upd_same lconf_upd2 conf_def)\n  ultimately show \"P,h' \\<turnstile> l'(V := l V) (:\\<le>) E\"\n    by (fastforce simp:lconf_def split:split_if_asm)\nnext\n  case (BlockRedNone e h l V e' h' l' T T')\n  have red: \"P \\<turnstile> \\<langle>e,(h, l(V := None))\\<rangle> \\<rightarrow> \\<langle>e',(h', l')\\<rangle>\"\n   and IH: \"\\<And>E T. \\<lbrakk> P,E,h \\<turnstile> e : T; P,h \\<turnstile> l(V:=None) (:\\<le>) E \\<rbrakk>\n                   \\<Longrightarrow> P,h' \\<turnstile> l' (:\\<le>) E\"\n   and lconf: \"P,h \\<turnstile> l (:\\<le>) E\" and wt: \"P,E,h \\<turnstile> {V:T; e} : T'\" by fact+\n  from lconf_hext[OF lconf red_hext_incr[OF red]]\n  have \"P,h' \\<turnstile> l (:\\<le>) E\" .\n  moreover have \"P,h' \\<turnstile> l' (:\\<le>) E(V\\<mapsto>T)\"\n    by(rule IH, insert lconf wt, auto simp:lconf_def)\n  ultimately show \"P,h' \\<turnstile> l'(V := l V) (:\\<le>) E\"\n    by (fastforce simp:lconf_def split:split_if_asm)\nnext\n  case (BlockRedSome e h l V e' h' l' v T T')\n  have red: \"P \\<turnstile> \\<langle>e,(h, l(V := None))\\<rangle> \\<rightarrow> \\<langle>e',(h', l')\\<rangle>\"\n   and IH: \"\\<And>E T. \\<lbrakk>P,E,h \\<turnstile> e : T; P,h \\<turnstile> l(V:=None) (:\\<le>) E\\<rbrakk>\n                   \\<Longrightarrow> P,h' \\<turnstile> l' (:\\<le>) E\"\n   and lconf: \"P,h \\<turnstile> l (:\\<le>) E\" and wt: \"P,E,h \\<turnstile> {V:T; e} : T'\" by fact+\n  from lconf_hext[OF lconf red_hext_incr[OF red]]\n  have \"P,h' \\<turnstile> l (:\\<le>) E\" .\n  moreover have \"P,h' \\<turnstile> l' (:\\<le>) E(V\\<mapsto>T)\"\n    by(rule IH, insert lconf wt, auto simp:lconf_def)\n  ultimately show \"P,h' \\<turnstile> l'(V := l V) (:\\<le>) E\"\n    by (fastforce simp:lconf_def split:split_if_asm)\nqed auto\n(*>*)\n\n\ntext{* Preservation of definite assignment more complex and requires a\nfew lemmas first. *}\n\n\n\n\nlemma red_lA_incr: \"P \\<turnstile> \\<langle>e,(h,l)\\<rangle> \\<rightarrow> \\<langle>e',(h',l')\\<rangle> \\<Longrightarrow> \\<lfloor>dom l\\<rfloor> \\<squnion> \\<A> e \\<sqsubseteq>  \\<lfloor>dom l'\\<rfloor> \\<squnion> \\<A> e'\"\nand reds_lA_incr: \"P \\<turnstile> \\<langle>es,(h,l)\\<rangle> [\\<rightarrow>] \\<langle>es',(h',l')\\<rangle> \\<Longrightarrow> \\<lfloor>dom l\\<rfloor> \\<squnion> \\<A>s es \\<sqsubseteq>  \\<lfloor>dom l'\\<rfloor> \\<squnion> \\<A>s es'\"\n(*<*)\napply(induct rule:red_reds_inducts)\napply(simp_all del:fun_upd_apply add:hyperset_defs)\napply auto\napply(blast dest:red_lcl_incr)+\ndone\n(*>*)\n\n\ntext{* Now preservation of definite assignment. *}\n\nlemma assumes wf: \"wf_J_prog P\"\nshows red_preserves_defass:\n  \"P \\<turnstile> \\<langle>e,(h,l)\\<rangle> \\<rightarrow> \\<langle>e',(h',l')\\<rangle> \\<Longrightarrow> \\<D> e \\<lfloor>dom l\\<rfloor> \\<Longrightarrow> \\<D> e' \\<lfloor>dom l'\\<rfloor>\"\nand \"P \\<turnstile> \\<langle>es,(h,l)\\<rangle> [\\<rightarrow>] \\<langle>es',(h',l')\\<rangle> \\<Longrightarrow> \\<D>s es \\<lfloor>dom l\\<rfloor> \\<Longrightarrow> \\<D>s es' \\<lfloor>dom l'\\<rfloor>\"\n(*<*)\nproof (induct rule:red_reds_inducts)\n  case BinOpRed1 thus ?case by (auto elim!: D_mono[OF red_lA_incr])\nnext\n  case FAssRed1 thus ?case by (auto elim!: D_mono[OF red_lA_incr])\nnext\n  case CallObj thus ?case by (auto elim!: Ds_mono[OF red_lA_incr])\nnext\n  case RedCall thus ?case\n    apply (auto dest!:sees_wf_mdecl[OF wf] simp:wf_mdecl_def elim!:D_mono')\n    by(auto simp:hyperset_defs)\nnext\n  case InitBlockRed thus ?case\n    by(auto simp:hyperset_defs elim!:D_mono' simp del:fun_upd_apply)\nnext\n  case BlockRedNone thus ?case\n    by(auto simp:hyperset_defs elim!:D_mono' simp del:fun_upd_apply)\nnext\n  case BlockRedSome thus ?case\n    by(auto simp:hyperset_defs elim!:D_mono' simp del:fun_upd_apply)\nnext\n  case SeqRed thus ?case by (auto elim!: D_mono[OF red_lA_incr])\nnext\n  case CondRed thus ?case by (auto elim!: D_mono[OF red_lA_incr])\nnext\n  case TryRed thus ?case\n    by (fastforce dest:red_lcl_incr intro:D_mono' simp:hyperset_defs)\nnext\n  case ListRed1 thus ?case by (auto elim!: Ds_mono[OF red_lA_incr])\nnext\n  case RedWhile thus ?case by(auto simp:hyperset_defs elim!:D_mono')\nqed (auto simp:hyperset_defs)\n(*>*)\n\n\ntext{* Combining conformance of heap and local variables: *}\n\ndefinition sconf :: \"J_prog \\<Rightarrow> env \\<Rightarrow> state \\<Rightarrow> bool\"   (\"_,_ \\<turnstile> _ \\<surd>\"   [51,51,51]50)\nwhere\n  \"P,E \\<turnstile> s \\<surd>  \\<equiv>  let (h,l) = s in P \\<turnstile> h \\<surd> \\<and> P,h \\<turnstile> l (:\\<le>) E\"\n\nlemma red_preserves_sconf:\n  \"\\<lbrakk> P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow> \\<langle>e',s'\\<rangle>; P,E,hp s \\<turnstile> e : T; P,E \\<turnstile> s \\<surd> \\<rbrakk> \\<Longrightarrow> P,E \\<turnstile> s' \\<surd>\"\n(*<*)\nby(fastforce intro:red_preserves_hconf red_preserves_lconf\n            simp add:sconf_def)\n(*>*)\n\nlemma reds_preserves_sconf:\n  \"\\<lbrakk> P \\<turnstile> \\<langle>es,s\\<rangle> [\\<rightarrow>] \\<langle>es',s'\\<rangle>; P,E,hp s \\<turnstile> es [:] Ts; P,E \\<turnstile> s \\<surd> \\<rbrakk> \\<Longrightarrow> P,E \\<turnstile> s' \\<surd>\"\n(*<*)\nby(fastforce intro:reds_preserves_hconf reds_preserves_lconf\n            simp add:sconf_def)\n(*>*)\n\n\nsubsection \"Subject reduction\"\n\nlemma wt_blocks:\n \"\\<And>E. \\<lbrakk> length Vs = length Ts; length vs = length Ts \\<rbrakk> \\<Longrightarrow>\n       (P,E,h \\<turnstile> blocks(Vs,Ts,vs,e) : T) =\n       (P,E(Vs[\\<mapsto>]Ts),h \\<turnstile> e:T \\<and> (\\<exists>Ts'. map (typeof\\<^bsub>h\\<^esub>) vs = map Some Ts' \\<and> P \\<turnstile> Ts' [\\<le>] Ts))\"\n(*<*)\napply(induct Vs Ts vs e rule:blocks_induct)\napply (force simp add:rel_list_all2_Cons2)\napply simp_all\ndone\n(*>*)\n\n\n\n\n\ncorollary subject_reduction:\n  \"\\<lbrakk> wf_J_prog P; P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow> \\<langle>e',s'\\<rangle>; P,E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> e:T \\<rbrakk>\n  \\<Longrightarrow> \\<exists>T'. P,E,hp s' \\<turnstile> e':T' \\<and> P \\<turnstile> T' \\<le> T\"\n(*<*)by(cases s, cases s', fastforce dest:subject_reduction2)(*>*)\n\ncorollary subjects_reduction:\n  \"\\<lbrakk> wf_J_prog P; P \\<turnstile> \\<langle>es,s\\<rangle> [\\<rightarrow>] \\<langle>es',s'\\<rangle>; P,E \\<turnstile> s \\<surd>; P,E,hp s \\<turnstile> es[:]Ts \\<rbrakk>\n  \\<Longrightarrow> \\<exists>Ts'. P,E,hp s' \\<turnstile> es'[:]Ts' \\<and> P \\<turnstile> Ts' [\\<le>] Ts\"\n(*<*)by(cases s, cases s', fastforce dest:subjects_reduction2)(*>*)\n\n\nsubsection {* Lifting to @{text\"\\<rightarrow>*\"} *}\n\ntext{* Now all these preservation lemmas are first lifted to the transitive\nclosure \\dots *}\n\nlemma Red_preserves_sconf:\nassumes wf: \"wf_J_prog P\" and Red: \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle>\"\nshows \"\\<And>T. \\<lbrakk> P,E,hp s \\<turnstile> e : T; P,E \\<turnstile> s \\<surd> \\<rbrakk> \\<Longrightarrow> P,E \\<turnstile> s' \\<surd>\"\n(*<*)\nusing Red\nproof (induct rule:converse_rtrancl_induct2)\n  case refl show ?case by fact\nnext\n  case step thus ?case\n    by(blast intro:red_preserves_sconf dest: subject_reduction[OF wf])\nqed\n(*>*)\n\n\nlemma Red_preserves_defass:\nassumes wf: \"wf_J_prog P\" and reds: \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle>\"\nshows \"\\<D> e \\<lfloor>dom(lcl s)\\<rfloor> \\<Longrightarrow> \\<D> e' \\<lfloor>dom(lcl s')\\<rfloor>\"\nusing reds\nproof (induct rule:converse_rtrancl_induct2)\n  case refl thus ?case .\nnext\n  case (step e s e' s') thus ?case\n    by(cases s,cases s')(auto dest:red_preserves_defass[OF wf])\nqed\n\n\nlemma Red_preserves_type:\nassumes wf: \"wf_J_prog P\" and Red: \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle>\"\nshows \"!!T. \\<lbrakk> P,E \\<turnstile> s\\<surd>; P,E,hp s \\<turnstile> e:T \\<rbrakk>\n    \\<Longrightarrow> \\<exists>T'. P \\<turnstile> T' \\<le> T \\<and> P,E,hp s' \\<turnstile> e':T'\"\n(*<*)\nusing Red\nproof (induct rule:converse_rtrancl_induct2)\n  case refl thus ?case by blast\nnext\n  case step thus ?case\n    by(blast intro:widen_trans red_preserves_sconf\n             dest:subject_reduction[OF wf])\nqed\n(*>*)\n\n\nsubsection {* Lifting to @{text\"\\<Rightarrow>\"} *}\n\ntext{* \\dots and now to the big step semantics, just for fun. *}\n\nlemma eval_preserves_sconf:\n  \"\\<lbrakk> wf_J_prog P; P \\<turnstile> \\<langle>e,s\\<rangle> \\<Rightarrow> \\<langle>e',s'\\<rangle>; P,E \\<turnstile> e::T; P,E \\<turnstile> s\\<surd> \\<rbrakk> \\<Longrightarrow> P,E \\<turnstile> s'\\<surd>\"\n(*<*)\nby(blast intro:Red_preserves_sconf big_by_small WT_implies_WTrt wf_prog_wwf_prog)\n(*>*)\n\n\n\n\n\nsubsection \"The final polish\"\n\ntext{* The above preservation lemmas are now combined and packed nicely. *}\n\ndefinition wf_config :: \"J_prog \\<Rightarrow> env \\<Rightarrow> state \\<Rightarrow> expr \\<Rightarrow> ty \\<Rightarrow> bool\"   (\"_,_,_ \\<turnstile> _ : _ \\<surd>\"   [51,0,0,0,0]50)\nwhere\n  \"P,E,s \\<turnstile> e:T \\<surd>  \\<equiv>  P,E \\<turnstile> s \\<surd> \\<and> P,E,hp s \\<turnstile> e:T\"\n\ntheorem Subject_reduction: assumes wf: \"wf_J_prog P\"\nshows \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow> \\<langle>e',s'\\<rangle> \\<Longrightarrow> P,E,s \\<turnstile> e : T \\<surd>\n       \\<Longrightarrow> \\<exists>T'. P,E,s' \\<turnstile> e' : T' \\<surd> \\<and> P \\<turnstile> T' \\<le> T\"\n(*<*)\nby(force simp add: wf_config_def\n   elim:red_preserves_sconf dest:subject_reduction[OF wf])\n(*>*)\n\n\ntheorem Subject_reductions:\nassumes wf: \"wf_J_prog P\" and reds: \"P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle>\"\nshows \"\\<And>T. P,E,s \\<turnstile> e:T \\<surd> \\<Longrightarrow> \\<exists>T'. P,E,s' \\<turnstile> e':T' \\<surd> \\<and> P \\<turnstile> T' \\<le> T\"\n(*<*)\nusing reds\nproof (induct rule:converse_rtrancl_induct2)\n  case refl thus ?case by blast\nnext\n  case step thus ?case\n    by(blast dest:Subject_reduction[OF wf] intro:widen_trans)\nqed\n(*>*)\n\n\ncorollary Progress: assumes wf: \"wf_J_prog P\"\nshows \"\\<lbrakk> P,E,s  \\<turnstile> e : T \\<surd>; \\<D> e \\<lfloor>dom(lcl s)\\<rfloor>; \\<not> final e \\<rbrakk> \\<Longrightarrow> \\<exists>e' s'. P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow> \\<langle>e',s'\\<rangle>\"\n(*<*)\nusing progress[OF wf_prog_wwf_prog[OF wf]]\nby(auto simp:wf_config_def sconf_def)\n(*>*)\n\n\ncorollary TypeSafety:\n  \"\\<lbrakk> wf_J_prog P; P,E \\<turnstile> s \\<surd>; P,E \\<turnstile> e::T; \\<D> e \\<lfloor>dom(lcl s)\\<rfloor>;\n     P \\<turnstile> \\<langle>e,s\\<rangle> \\<rightarrow>* \\<langle>e',s'\\<rangle>; \\<not>(\\<exists>e'' s''. P \\<turnstile> \\<langle>e',s'\\<rangle> \\<rightarrow> \\<langle>e'',s''\\<rangle>) \\<rbrakk>\n \\<Longrightarrow> (\\<exists>v. e' = Val v \\<and> P,hp s' \\<turnstile> v :\\<le> T) \\<or>\n      (\\<exists>a. e' = Throw a \\<and> a \\<in> dom(hp s'))\"\n(*<*)\napply(subgoal_tac \" P,E,s \\<turnstile> e:T \\<surd>\")\n prefer 2\n apply(fastforce simp:wf_config_def dest:WT_implies_WTrt)\napply(frule (2) Subject_reductions)\napply(erule exE conjE)+\napply(frule (2) Red_preserves_defass)\napply(subgoal_tac \"final e'\")\n prefer 2\n apply(blast dest: Progress)\napply (fastforce simp:wf_config_def final_def conf_def dest: Progress)\ndone\n(*>*)\n\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Jinja/J/TypeSafe.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5506073655352404, "lm_q2_score": 0.46101677931231594, "lm_q1q2_score": 0.2538392343246956}}
{"text": "(******************************************************************************)\n(* Project: The Isabelle/UTP Proof System                                     *)\n(* File: fmi_export.thy                                                       *)\n(* Authors: Frank Zeyda and Simon Foster (University of York, UK)             *)\n(* Emails: frank.zeyda@york.ac.uk and simon.foster@york.ac.uk                 *)\n(******************************************************************************)\n(* LAST REVIEWED: 18 Sep 2017 *)\n\nsection {* FMI {\\Circus} Model *}\n\ntheory fmi_export\nimports fmi\n  \"../theories/utp_circus_prefix\"\nbegin recall_syntax\n\ndeclare [[syntax_ambiguity_warning = false]]\n\nsubsection {* Preliminaries *}\n\ntext {* The below cause ambiguities wrt their CSP definitions. *}\n\nhide_const utp_cml.Skip\nhide_const utp_cml.Stop\n\n(*\ntext {* I believe the following adjustments are not required anymore. *}\n\nsyntax\n  \"_csp_sync\" :: \"logic \\<Rightarrow> logic \\<Rightarrow> logic\" (\"_ \\<rightarrow>\\<^sub>u _\" [81, 80] 80)\n*)\n\ntext {* Undeclaring Simon's prefix notation (need to parse \\<open>Interaction\\<close>. *}\n\npurge_syntax\n  \"_output_prefix\" :: \"('a, '\\<sigma>) uexpr \\<Rightarrow> prefix_elem'\" (\"!'(_')\")\n  \"_output_prefix\" :: \"('a, '\\<sigma>) uexpr \\<Rightarrow> prefix_elem'\" (\".'(_')\")\n\nsubsection {* Lists as Tables *}\n\ntype_synonym ('a, 'b) table = \"('a \\<times> 'b) list\"\n\nfun lookup :: \"('a \\<times> 'b) list \\<Rightarrow> 'a \\<Rightarrow> 'b\" where\n\"lookup ((x, y) # t) v = (if v = x then y else (lookup t x))\" |\n\"lookup [] x = undefined\"\n\nsyntax \"_ulookup\" ::\n  \"('a \\<times> 'b, '\\<sigma>) uexpr \\<Rightarrow> ('a, '\\<sigma>) uexpr \\<Rightarrow> ('b, '\\<sigma>) uexpr\" (\"lookup\\<^sub>u\")\n\ntranslations \"lookup\\<^sub>u t x\" \\<rightleftharpoons> \"(CONST bop) (CONST lookup) t x\"\n\nsubsection {* Instantiations *}\n\ntext {*\n  The instantiations below are unsafe since the type @{typ uval} may actually\n  have a higher cardinality than the continuum, depending on what HOL types we\n  inject into it! This is why I decided to adopt a shallow state model for the\n  \\<open>Interaction\\<close> process. (An alternative would be to adopt an axiomatic model,\n  which requires some remaining more work on integrating axiomatic variables.)\n  Strictly speaking, axiomatic values are probably not needed since the only\n  types that FMI 2.0 allows to be exchanged between FMUs are Real, Integer,\n  String and Boolean, all of which can be injected into the deep model, too.\n*}\n\ninstance uval     ::        \"{continuum, two}\" sorry\ninstance uvar_ext :: (type) \"{continuum, two}\" sorry\n\nsubsection {* {\\Circus} Constructs *}\n\nsyntax \"_if_then_else\" ::\n  \"'a upred \\<Rightarrow> ('a, 'b) urel \\<Rightarrow> ('a, 'b) urel \\<Rightarrow> ('a, 'b) urel\"\n    (\"(if\\<^sub>\\<C> (_)/ then\\<^sub>\\<C> (_)/ else\\<^sub>\\<C> (_))\" [0, 0, 10] 10)\n\ntranslations \"if\\<^sub>\\<C> b then\\<^sub>\\<C> P else\\<^sub>\\<C> Q\" \\<rightleftharpoons> \"P \\<triangleleft> b \\<triangleright>\\<^sub>r Q\"\n\nsubsection {* \\<open>Timer\\<close> Process *}\n\ntext {*\n  A problem with the {\\Circus} process encoding below is that, currently, it\n  is not possible to write mixed prefixes with both inputs and outputs. Hence,\n  I had to use a trick converting everything into a single input prefix. That\n  input imposes constraints so that some parts of the communication effectively\n  behave like outputs. A second issue is that, referring to page 16 of D2.2d,\n  we see that the @{text AllowGetsAndSets} action is actually parametric. My\n  translation currently does not support parametric actions; hence I adopted\n  a solution that encodes procedure parameters by local variables. Due to the\n  proper treatment of scope by Isabelle/UTP, we generally get away with this.\n  Both issues can thus be overcome; an integration of syntax translations that\n  conceal the manual adjustments done below is pending work.\n*}\n\ntext {* \\todo{Write the same process as below with axiomatic variables.} *}\n\ndefinition\n\"process TimerOld1(ct::TIME('\\<tau>), hc::NZTIME('\\<tau>), tN::TIME('\\<tau>)) \\<triangleq> begin\n  state(vstore)\n  Step =\n    (tm:setT?(t : \\<guillemotleft>t \\<le> tN\\<guillemotright>) \\<rightarrow>\\<^sub>\\<C> (<currentTime> := \\<guillemotleft>t\\<guillemotright>) ;; Step) \\<box>\n    (tm:updateSS?(ss : true) \\<rightarrow>\\<^sub>\\<C> (<stepSize> := \\<guillemotleft>ss\\<guillemotright>) ;; Step) \\<box>\n    (tm:step![out]((&<currentTime>, &<stepSize>)\\<^sub>u) \\<rightarrow>\\<^sub>\\<C>\n      (<currentTime::'\\<tau>> :=\n        min\\<^sub>u(&<currentTime> + \\<section>(&<stepSize::'\\<tau> pos>), \\<guillemotleft>tN\\<guillemotright>)) ;; Step) \\<box>\n    ((&<currentTime> =\\<^sub>u \\<guillemotleft>tN\\<guillemotright>) &\\<^sub>u tm:endc \\<rightarrow>\\<^sub>\\<C> Stop)\n  \\<bullet> (<currentTime>, <stepSize> := \\<guillemotleft>ct\\<guillemotright>, \\<guillemotleft>hc\\<guillemotright>) ;; Step\nend\"\n\ndefinition\n\"process TimerOld2(ct::TIME('\\<tau>), hc::NZTIME('\\<tau>), tN::TIME('\\<tau>)) \\<triangleq> begin\n  state(vstore)\n  Step =\n    (tm:setT?(t : \\<guillemotleft>t \\<le> tN\\<guillemotright>) \\<rightarrow>\\<^sub>\\<C> (<currentTime> := \\<guillemotleft>t\\<guillemotright>) ;; Step) \\<box>\n    (tm:updateSS?(ss) \\<rightarrow>\\<^sub>\\<C> (<stepSize> := \\<guillemotleft>ss\\<guillemotright>) ;; Step) \\<box>\n    (tm:step![out\\<^sub>1]($<currentTime>)![out\\<^sub>2]($<stepSize>) \\<rightarrow>\\<^sub>\\<C>\n      (<currentTime::'\\<tau>> :=\n        min\\<^sub>u(&<currentTime> + \\<section>(&<stepSize::'\\<tau> pos>), \\<guillemotleft>tN\\<guillemotright>)) ;; Step) \\<box>\n    ((&<currentTime> =\\<^sub>u \\<guillemotleft>tN\\<guillemotright>) &\\<^sub>u tm:endc \\<rightarrow>\\<^sub>\\<C> Stop)\n  \\<bullet> (<currentTime>, <stepSize> := \\<guillemotleft>ct\\<guillemotright>, \\<guillemotleft>hc\\<guillemotright>) ;; Step\nend\"\n\nsubsubsection {* \\<open>Interaction\\<close> Process *}\n\ntext {*\n  Note that I changed the type of @{text rinps} with respect to the tentative\n  model given in the deliverable D2.2d. That is, instead of using the partial\n  function type @{typ \"FMI2COMP \\<rightharpoonup> (VAR \\<rightharpoonup> VAL)\"} for @{text rinps}, I decided\n  to use the list @{typ \"((FMI2COMP \\<times> VAR) \\<times> VAL) list\"}. This is (currently)\n  a technicality since there are issues with using function types in prefixes,\n  to do with Simon's embedding of shallow variables. Using lists circumvents\n  the issue for and ought not limit generality since we may reasonably assume\n  that the port-dependency graph is a finite relation.\n*}\n\ntext {* Process State: \\<open>rinps :: (port \\<times> VAL) list\\<close>. *}\n\ndefinition\n\"process InteractionOld \\<triangleq> begin\n  state(vstore)\n  Instantiation = (;; i : FMUs \\<bullet>\n    fmi:fmi2Instantiate?\\<^sub>u(i_sc : \\<pi>\\<^sub>1(\\<guillemotleft>i_sc\\<guillemotright>) =\\<^sub>u \\<guillemotleft>i\\<guillemotright>) \\<rightarrow> Skip) and\n\n  InstantiationMode =\n    (if\\<^sub>\\<C> \\<guillemotleft>parameters = []\\<guillemotright> then\\<^sub>\\<C>\n      (;; i : FMUs \\<bullet>\n        fmi:fmi2SetUpExperiment?\\<^sub>u(i_startTime_stopTimeDefined_stopTime_st :\n          \\<pi>\\<^sub>1(\\<guillemotleft>i_startTime_stopTimeDefined_stopTime_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>i\\<guillemotright> \\<and>\n          \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<guillemotleft>i_startTime_stopTimeDefined_stopTime_st\\<guillemotright>)) =\\<^sub>u \\<guillemotleft>startTime\\<guillemotright> \\<and>\n          \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<guillemotleft>i_startTime_stopTimeDefined_stopTime_st\\<guillemotright>))) =\\<^sub>u \\<guillemotleft>stopTimeDefined\\<guillemotright> \\<and>\n          \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<guillemotleft>i_startTime_stopTimeDefined_stopTime_st\\<guillemotright>)))) =\\<^sub>u \\<guillemotleft>stopTime\\<guillemotright>)\n            \\<rightarrow> Skip) ;;\n      (;; i : FMUs \\<bullet>\n        fmi:fmi2EnterInitializationMode?\\<^sub>u(i_st : \\<pi>\\<^sub>1(\\<guillemotleft>i_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>i\\<guillemotright>) \\<rightarrow> Skip)\n    else\\<^sub>\\<C>\n      (;; i_x_v : parameters \\<bullet>\n        fmi:fmi2Set?\\<^sub>u(i_x_v_st :\n          \\<pi>\\<^sub>1(\\<guillemotleft>i_x_v_st\\<guillemotright>) =\\<^sub>u \\<pi>\\<^sub>1(\\<guillemotleft>i_x_v\\<guillemotright>) \\<and>\n          \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v_st\\<guillemotright>)) =\\<^sub>u \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v\\<guillemotright>)) \\<and>\n          \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v_st\\<guillemotright>))) =\\<^sub>u \\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v\\<guillemotright>))) \\<rightarrow> Skip) ;;\n      (;; i : FMUs \\<bullet>\n        fmi:fmi2SetUpExperiment?\\<^sub>u(i_startTime_stopTimeDefined_stopTime_st :\n          \\<pi>\\<^sub>1(\\<guillemotleft>i_startTime_stopTimeDefined_stopTime_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>i\\<guillemotright> \\<and>\n          \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<guillemotleft>i_startTime_stopTimeDefined_stopTime_st\\<guillemotright>)) =\\<^sub>u \\<guillemotleft>startTime\\<guillemotright> \\<and>\n          \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<guillemotleft>i_startTime_stopTimeDefined_stopTime_st\\<guillemotright>))) =\\<^sub>u \\<guillemotleft>stopTimeDefined\\<guillemotright> \\<and>\n          \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<guillemotleft>i_startTime_stopTimeDefined_stopTime_st\\<guillemotright>)))) =\\<^sub>u \\<guillemotleft>stopTime\\<guillemotright>)\n            \\<rightarrow> Skip) ;;\n      (;; i : FMUs \\<bullet>\n        fmi:fmi2EnterInitializationMode?\\<^sub>u(i_st : \\<pi>\\<^sub>1(\\<guillemotleft>i_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>i\\<guillemotright>) \\<rightarrow> Skip)) and\n\n  InitializationMode =\n    (if\\<^sub>\\<C> \\<guillemotleft>initialValues = []\\<guillemotright> then\\<^sub>\\<C>\n      (;; i : FMUs \\<bullet>\n        fmi:fmi2ExitInitializationMode?\\<^sub>u(i_st : \\<pi>\\<^sub>1(\\<guillemotleft>i_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>i\\<guillemotright>) \\<rightarrow> Skip)\n    else\\<^sub>\\<C>\n      (;; i_x_v : initialValues \\<bullet>\n        fmi:fmi2Set?\\<^sub>u(i_x_v_st :\n          \\<pi>\\<^sub>1(\\<guillemotleft>i_x_v_st\\<guillemotright>) =\\<^sub>u \\<pi>\\<^sub>1(\\<guillemotleft>i_x_v\\<guillemotright>) \\<and>\n          \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v_st\\<guillemotright>)) =\\<^sub>u \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v\\<guillemotright>)) \\<and>\n          \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v_st\\<guillemotright>))) =\\<^sub>u \\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v\\<guillemotright>))) \\<rightarrow> Skip) ;;\n      (;; i : FMUs \\<bullet>\n        fmi:fmi2ExitInitializationMode?\\<^sub>u(i_st : \\<pi>\\<^sub>1(\\<guillemotleft>i_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>i\\<guillemotright>) \\<rightarrow> Skip)) and\n\n  Terminated = (;; i : FMUs \\<bullet>\n    fmi:fmi2Terminate?\\<^sub>u(i_st : \\<pi>\\<^sub>1(\\<guillemotleft>i_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>i\\<guillemotright>) \\<rightarrow>\n    fmi:fmi2FreeInstance?\\<^sub>u(i_st : \\<pi>\\<^sub>1(\\<guillemotleft>i_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>i\\<guillemotright>) \\<rightarrow> Skip) ;;\n    ctr:endsimulation \\<rightarrow>\\<^sub>u Skip and\n\n  TakeOutputs = <rinp::(port \\<times> VAL) list> := \\<langle>\\<rangle> ;;\n    (;; out : outputs \\<bullet> fmi:fmi2Get?\\<^sub>u(i_x_v_st :\n      \\<pi>\\<^sub>1(\\<guillemotleft>i_x_v_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>FMU out\\<guillemotright> \\<and>\n      \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v_st\\<guillemotright>)) =\\<^sub>u \\<guillemotleft>name out\\<guillemotright>) \\<rightarrow>\n        (;; inp : pdg out \\<bullet>\n          <rinp> := &<rinp> ^\\<^sub>u \\<langle>(\\<guillemotleft>inp\\<guillemotright>, \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(&i_x_v_st))))\\<^sub>u\\<rangle>)) and\n\n  DistributeInputs = (;; inp : inputs \\<bullet>\n    fmi:fmi2Set?\\<^sub>u(i_x_v_st :\n      \\<pi>\\<^sub>1(\\<guillemotleft>i_x_v_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>FMU inp\\<guillemotright> \\<and>\n      \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v_st\\<guillemotright>)) =\\<^sub>u \\<guillemotleft>name inp\\<guillemotright> \\<and>\n      \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v_st\\<guillemotright>))) =\\<^sub>u (lookup\\<^sub>u $<rinp> \\<guillemotleft>inp\\<guillemotright>)) \\<rightarrow> Skip) and\n\n  Step = (;; i : [0..(length FMUs)] \\<bullet>\n    (if (i::int) = 0 then\n      ctr:stepToComplete \\<rightarrow>\\<^sub>u\n        (fmi:fmi2DoStep?\\<^sub>u(i_t_hc_st :\n          \\<pi>\\<^sub>1(\\<guillemotleft>i_t_hc_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>nth FMUs 1\\<guillemotright> \\<and>\n          \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<guillemotleft>i_t_hc_st\\<guillemotright>)) =\\<^sub>u $<t> \\<and>\n          \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<guillemotleft>i_t_hc_st\\<guillemotright>))) =\\<^sub>u $<hc>) \\<rightarrow> Skip)\n    else if (i::int) < (length FMUs) then\n      (\\<mu> X \\<bullet>\n        (fmi:fmi2GetBooleanStatusfmi2Terminated?\\<^sub>u(i_b_st :\n          \\<pi>\\<^sub>1(\\<guillemotleft>i_b_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>nth FMUs (nat i)\\<guillemotright>) \\<rightarrow> X) \\<box>\n        (fmi:fmi2GetMaxStepSize?\\<^sub>u(i_t_st :\n          \\<pi>\\<^sub>1(\\<guillemotleft>i_t_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>nth FMUs (nat i)\\<guillemotright>) \\<rightarrow> X)) \\<box>\n        (fmi:fmi2DoStep?\\<^sub>u(i_t_hc_st :\n          \\<pi>\\<^sub>1(\\<guillemotleft>i_t_hc_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>nth FMUs (nat (i+1))\\<guillemotright> \\<and>\n          \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<guillemotleft>i_t_hc_st\\<guillemotright>)) =\\<^sub>u $<t> \\<and>\n          \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<guillemotleft>i_t_hc_st\\<guillemotright>))) =\\<^sub>u $<hc>) \\<rightarrow> Skip)\n    else\n      (\\<mu> X \\<bullet>\n        (fmi:fmi2GetBooleanStatusfmi2Terminated?\\<^sub>u(i_b_st :\n          \\<pi>\\<^sub>1(\\<guillemotleft>i_b_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>nth FMUs (nat i)\\<guillemotright>) \\<rightarrow> X) \\<box>\n        (fmi:fmi2GetMaxStepSize?\\<^sub>u(i_t_st :\n          \\<pi>\\<^sub>1(\\<guillemotleft>i_t_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>nth FMUs (nat i)\\<guillemotright>) \\<rightarrow> X)) \\<box>\n        (ctr:stepAnalysed \\<rightarrow>\\<^sub>u Skip))) and\n\n  slaveInitialized =\n    (tm:endc \\<rightarrow>\\<^sub>u Terminated) \\<box>\n    (tm:step?\\<^sub>u(t_hc : true) \\<rightarrow>\n      (* Used local variables to pass action parameters! *)\n      (<t>, <hc> := \\<pi>\\<^sub>1(&t_hc), \\<pi>\\<^sub>2(&t_hc)) ;;\n      TakeOutputs ;; DistributeInputs ;; Step) and\n\n  NextStep =\n    (tm:updateSS?\\<^sub>u(d : true) \\<rightarrow> NextStep) \\<box>\n    (tm:setT?\\<^sub>u(t : true) \\<rightarrow> NextStep) \\<box>\n    (slaveInitialized ;; NextStep) \\<box>\n    (Terminated)\n\n  \\<bullet> Instantiation ;; InstantiationMode ;; InitializationMode ;; slaveInitialized\nend\"\n\ntheorem \"P InteractionOld\"\napply (unfold InteractionOld_def)\napply (simp add: circus_syntax Let_def)\noops\n\ntext {* A simplified definition of the same (?) process is given below. *}\n\ndefinition\n\"process InteractionSimplified \\<triangleq> begin\n  state(vstore)\n  Instantiation = (;; i : FMUs \\<bullet>\n    fmi:fmi2Instantiate?\\<^sub>u(i_sc : \\<pi>\\<^sub>1(\\<guillemotleft>i_sc\\<guillemotright>) =\\<^sub>u \\<guillemotleft>i\\<guillemotright>) \\<rightarrow> Skip) and\n\n  InstantiationMode =\n    (;; i_x_v : parameters \\<bullet>\n      fmi:fmi2Set?\\<^sub>u(i_x_v_st :\n        \\<pi>\\<^sub>1(\\<guillemotleft>i_x_v_st\\<guillemotright>) =\\<^sub>u \\<pi>\\<^sub>1(\\<guillemotleft>i_x_v\\<guillemotright>) \\<and>\n        \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v_st\\<guillemotright>)) =\\<^sub>u \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v\\<guillemotright>)) \\<and>\n        \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v_st\\<guillemotright>))) =\\<^sub>u \\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v\\<guillemotright>))) \\<rightarrow> Skip) ;;\n    (;; i : FMUs \\<bullet>\n      fmi:fmi2SetUpExperiment?\\<^sub>u(i_startTime_stopTimeDefined_stopTime_st :\n        \\<pi>\\<^sub>1(\\<guillemotleft>i_startTime_stopTimeDefined_stopTime_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>i\\<guillemotright> \\<and>\n        \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<guillemotleft>i_startTime_stopTimeDefined_stopTime_st\\<guillemotright>)) =\\<^sub>u \\<guillemotleft>startTime\\<guillemotright> \\<and>\n        \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<guillemotleft>i_startTime_stopTimeDefined_stopTime_st\\<guillemotright>))) =\\<^sub>u \\<guillemotleft>stopTimeDefined\\<guillemotright> \\<and>\n        \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<guillemotleft>i_startTime_stopTimeDefined_stopTime_st\\<guillemotright>)))) =\\<^sub>u \\<guillemotleft>stopTime\\<guillemotright>)\n          \\<rightarrow> Skip) ;;\n    (;; i : FMUs \\<bullet>\n      fmi:fmi2EnterInitializationMode?\\<^sub>u(i_st : \\<pi>\\<^sub>1(\\<guillemotleft>i_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>i\\<guillemotright>) \\<rightarrow> Skip) and\n\n  InitializationMode =\n    (;; i_x_v : initialValues \\<bullet>\n      fmi:fmi2Set?\\<^sub>u(i_x_v_st :\n        \\<pi>\\<^sub>1(\\<guillemotleft>i_x_v_st\\<guillemotright>) =\\<^sub>u \\<pi>\\<^sub>1(\\<guillemotleft>i_x_v\\<guillemotright>) \\<and>\n        \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v_st\\<guillemotright>)) =\\<^sub>u \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v\\<guillemotright>)) \\<and>\n        \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v_st\\<guillemotright>))) =\\<^sub>u \\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v\\<guillemotright>))) \\<rightarrow> Skip) ;;\n    (;; i : FMUs \\<bullet>\n      fmi:fmi2ExitInitializationMode?\\<^sub>u(i_st : \\<pi>\\<^sub>1(\\<guillemotleft>i_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>i\\<guillemotright>) \\<rightarrow> Skip) and\n\n  Terminated = (;; i : FMUs \\<bullet>\n    fmi:fmi2Terminate?\\<^sub>u(i_st : \\<pi>\\<^sub>1(\\<guillemotleft>i_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>i\\<guillemotright>) \\<rightarrow>\n    fmi:fmi2FreeInstance?\\<^sub>u(i_st : \\<pi>\\<^sub>1(\\<guillemotleft>i_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>i\\<guillemotright>) \\<rightarrow> Skip) ;;\n    ctr:endsimulation \\<rightarrow>\\<^sub>u Skip and\n\n  TakeOutputs = <rinp::(port \\<times> VAL) list> := \\<langle>\\<rangle> ;;\n    (;; out : outputs \\<bullet> fmi:fmi2Get?\\<^sub>u(i_x_v_st :\n      \\<pi>\\<^sub>1(\\<guillemotleft>i_x_v_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>FMU out\\<guillemotright> \\<and>\n      \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v_st\\<guillemotright>)) =\\<^sub>u \\<guillemotleft>name out\\<guillemotright>) \\<rightarrow>\n        (;; inp : pdg out \\<bullet>\n          <rinp> := &<rinp> ^\\<^sub>u \\<langle>(\\<guillemotleft>inp\\<guillemotright>, \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(&i_x_v_st))))\\<^sub>u\\<rangle>)) and\n\n  DistributeInputs = (;; inp : inputs \\<bullet>\n    fmi:fmi2Set?\\<^sub>u(i_x_v_st :\n      \\<pi>\\<^sub>1(\\<guillemotleft>i_x_v_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>FMU inp\\<guillemotright> \\<and>\n      \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v_st\\<guillemotright>)) =\\<^sub>u \\<guillemotleft>name inp\\<guillemotright> \\<and>\n      \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<guillemotleft>i_x_v_st\\<guillemotright>))) =\\<^sub>u (lookup\\<^sub>u $<rinp> \\<guillemotleft>inp\\<guillemotright>)) \\<rightarrow> Skip) and\n\n  Step = (;; i : [0..(length FMUs)] \\<bullet>\n    (if (i::int) = 0 then\n      ctr:stepToComplete \\<rightarrow>\\<^sub>u\n        (fmi:fmi2DoStep?\\<^sub>u(i_t_hc_st :\n          \\<pi>\\<^sub>1(\\<guillemotleft>i_t_hc_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>nth FMUs 1\\<guillemotright> \\<and>\n          \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<guillemotleft>i_t_hc_st\\<guillemotright>)) =\\<^sub>u $<t> \\<and>\n          \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<guillemotleft>i_t_hc_st\\<guillemotright>))) =\\<^sub>u $<hc>) \\<rightarrow> Skip)\n    else if (i::int) < (length FMUs) then\n      (\\<mu> X \\<bullet>\n        (fmi:fmi2GetBooleanStatusfmi2Terminated?\\<^sub>u(i_b_st :\n          \\<pi>\\<^sub>1(\\<guillemotleft>i_b_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>nth FMUs (nat i)\\<guillemotright>) \\<rightarrow> X) \\<box>\n        (fmi:fmi2GetMaxStepSize?\\<^sub>u(i_t_st :\n          \\<pi>\\<^sub>1(\\<guillemotleft>i_t_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>nth FMUs (nat i)\\<guillemotright>) \\<rightarrow> X)) \\<box>\n        (fmi:fmi2DoStep?\\<^sub>u(i_t_hc_st :\n          \\<pi>\\<^sub>1(\\<guillemotleft>i_t_hc_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>nth FMUs (nat (i+1))\\<guillemotright> \\<and>\n          \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<guillemotleft>i_t_hc_st\\<guillemotright>)) =\\<^sub>u $<t> \\<and>\n          \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<pi>\\<^sub>2(\\<guillemotleft>i_t_hc_st\\<guillemotright>))) =\\<^sub>u $<hc>) \\<rightarrow> Skip)\n    else\n      (\\<mu> X \\<bullet>\n        (fmi:fmi2GetBooleanStatusfmi2Terminated?\\<^sub>u(i_b_st :\n          \\<pi>\\<^sub>1(\\<guillemotleft>i_b_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>nth FMUs (nat i)\\<guillemotright>) \\<rightarrow> X) \\<box>\n        (fmi:fmi2GetMaxStepSize?\\<^sub>u(i_t_st :\n          \\<pi>\\<^sub>1(\\<guillemotleft>i_t_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>nth FMUs (nat i)\\<guillemotright>) \\<rightarrow> X)) \\<box>\n        (ctr:stepAnalysed \\<rightarrow>\\<^sub>u Skip))) and\n\n  slaveInitialized =\n    (tm:endc \\<rightarrow>\\<^sub>u Terminated) \\<box>\n    (tm:step?\\<^sub>u(t_hc : true) \\<rightarrow>\n      (* Used local variables to pass action parameters! *)\n      (<t>, <hc> := \\<pi>\\<^sub>1(&t_hc), \\<pi>\\<^sub>2(&t_hc)) ;;\n      TakeOutputs ;; DistributeInputs ;; Step) and\n\n  NextStep =\n    (tm:updateSS?\\<^sub>u(d : true) \\<rightarrow> NextStep) \\<box>\n    (tm:setT?\\<^sub>u(t : true) \\<rightarrow> NextStep) \\<box>\n    (slaveInitialized ;; NextStep) \\<box>\n    (Terminated)\n\n  \\<bullet> Instantiation ;; InstantiationMode ;; InitializationMode ;; slaveInitialized\nend\"\n\ndefinition\n\"process InteractionNew \\<triangleq> begin\n  state(vstore)\n  Instantiation = (;; i : FMUs \\<bullet>\n    fmi:fmi2Instantiate.[out\\<^sub>1](\\<guillemotleft>i\\<guillemotright>)?(sc) \\<rightarrow>\\<^sub>\\<C> Skip) and\n\n  InstantiationMode =\n    (;; (i, x, v) : parameters \\<bullet>\n      fmi:fmi2Set![out\\<^sub>1](\\<guillemotleft>i\\<guillemotright>)![out\\<^sub>2](\\<guillemotleft>x\\<guillemotright>)![out\\<^sub>3](\\<guillemotleft>v\\<guillemotright>)?(st) \\<rightarrow>\\<^sub>\\<C> Skip) ;;\n    (;; i : FMUs \\<bullet>\n      fmi:fmi2SetUpExperiment![out\\<^sub>1](\\<guillemotleft>i\\<guillemotright>)![out\\<^sub>2](\\<guillemotleft>startTime\\<guillemotright>)\n        ![out\\<^sub>3](\\<guillemotleft>stopTimeDefined\\<guillemotright>)![out\\<^sub>4](\\<guillemotleft>stopTime\\<guillemotright>)?(st) \\<rightarrow>\\<^sub>\\<C> Skip) ;;\n    (;; i : FMUs \\<bullet>\n      fmi:fmi2EnterInitializationMode.[out\\<^sub>1](\\<guillemotleft>i\\<guillemotright>)?(sc) \\<rightarrow>\\<^sub>\\<C> Skip) and\n\n  InitializationMode =\n    (;; (i, x, v) : initialValues \\<bullet>\n      fmi:fmi2Set![out\\<^sub>1](\\<guillemotleft>i\\<guillemotright>)![out\\<^sub>2](\\<guillemotleft>x\\<guillemotright>)![out\\<^sub>3](\\<guillemotleft>v\\<guillemotright>)?(st) \\<rightarrow>\\<^sub>\\<C> Skip) ;;\n    (;; i : FMUs \\<bullet>\n      fmi:fmi2ExitInitializationMode![out\\<^sub>1](\\<guillemotleft>i\\<guillemotright>)?(sc) \\<rightarrow>\\<^sub>\\<C> Skip) and\n\n  Terminated =\n    (;; i : FMUs \\<bullet>\n      fmi:fmi2Terminate.[out\\<^sub>1](\\<guillemotleft>i\\<guillemotright>)?(sc) \\<rightarrow>\\<^sub>\\<C>\n      fmi:fmi2FreeInstance.[out\\<^sub>1](\\<guillemotleft>i\\<guillemotright>)?(sc) \\<rightarrow>\\<^sub>\\<C> Skip) ;;\n    ctr:endsimulation \\<rightarrow>\\<^sub>\\<C> Skip and\n\n  TakeOutputs = <rinp::(port \\<times> VAL) list> := \\<langle>\\<rangle> ;;\n    (;; out : outputs \\<bullet>\n      fmi:fmi2Get.[out\\<^sub>1](\\<guillemotleft>FMU out\\<guillemotright>).[out\\<^sub>2](\\<guillemotleft>name out\\<guillemotright>)?(v)?(st) \\<rightarrow>\\<^sub>\\<C>\n        (;; inp : pdg out \\<bullet> <rinp> := &<rinp> ^\\<^sub>u \\<langle>(\\<guillemotleft>inp\\<guillemotright>, \\<guillemotleft>v\\<guillemotright>)\\<^sub>u\\<rangle>)) and\n\n  DistributeInputs = (;; inp : inputs \\<bullet>\n    fmi:fmi2Set.[out\\<^sub>1](\\<guillemotleft>FMU inp\\<guillemotright>).[out\\<^sub>2](\\<guillemotleft>name inp\\<guillemotright>)\n      ![out\\<^sub>3](lookup\\<^sub>u $<rinp> \\<guillemotleft>inp\\<guillemotright>)?(st) \\<rightarrow>\\<^sub>\\<C> Skip) and\n\n  Step = (;; i : [0..(length FMUs)] \\<bullet>\n    (if (i::int) = 0 then\n      ctr:stepToComplete \\<rightarrow>\\<^sub>\\<C>\n        (fmi:fmi2DoStep.[out\\<^sub>1](\\<guillemotleft>FMUs!0\\<guillemotright>).[out\\<^sub>2]($<t>).[out\\<^sub>3]($<hc>)?(st) \\<rightarrow>\\<^sub>\\<C> Skip)\n    else if (i::int) < (length FMUs) then\n      (\\<mu> X \\<bullet>\n        (fmi:fmi2GetBooleanStatusfmi2Terminated.[out\\<^sub>1](\\<guillemotleft>FMUs!(nat (i-1))\\<guillemotright>)?(b)?(st) \\<rightarrow>\\<^sub>\\<C> X) \\<box>\n        (fmi:fmi2GetMaxStepSize.[out\\<^sub>1](\\<guillemotleft>FMUs!(nat (i-1))\\<guillemotright>)?(t)?(st) \\<rightarrow>\\<^sub>\\<C> X)) \\<box>\n        (fmi:fmi2DoStep.[out\\<^sub>1](\\<guillemotleft>FMUs!(nat i)\\<guillemotright>).[out\\<^sub>2]($<t>).[out\\<^sub>3]($<hc>)?(st) \\<rightarrow>\\<^sub>\\<C> Skip)\n    else\n      (\\<mu> X \\<bullet>\n        (fmi:fmi2GetBooleanStatusfmi2Terminated.[out\\<^sub>1](\\<guillemotleft>FMUs!(nat (i-1))\\<guillemotright>)?(b)?(st) \\<rightarrow>\\<^sub>\\<C> X) \\<box>\n        (fmi:fmi2GetMaxStepSize.[out\\<^sub>1](\\<guillemotleft>FMUs!(nat (i-1))\\<guillemotright>)?(t)?(st) \\<rightarrow>\\<^sub>\\<C> X)) \\<box>\n        (ctr:stepAnalysed \\<rightarrow>\\<^sub>\\<C> Skip))) and\n\n  slaveInitialized =\n    (tm:endc \\<rightarrow>\\<^sub>\\<C> Terminated) \\<box>\n    (tm:step?(t)?(hc) \\<rightarrow>\\<^sub>\\<C>\n      (* We use local variables to pass action parameters! *)\n      (<t>, <hc> := \\<guillemotleft>t\\<guillemotright>, \\<guillemotleft>hc\\<guillemotright>) ;;\n      TakeOutputs ;; DistributeInputs ;; Step) and\n\n  NextStep =\n    (tm:updateSS?(d) \\<rightarrow>\\<^sub>\\<C> NextStep) \\<box>\n    (tm:setT?(t) \\<rightarrow>\\<^sub>\\<C> NextStep) \\<box>\n    (slaveInitialized ;; NextStep) \\<box>\n    (Terminated)\n\n  \\<bullet> Instantiation ;; InstantiationMode ;; InitializationMode ;; slaveInitialized\nend\"\n\ntheorem \"P InteractionNew\"\napply (unfold InteractionNew_def)\napply (simp add: circus_syntax Let_def)\noops\n\nsubsubsection {* \\<open>FMUStatesManager\\<close> Process *}\n\ndefinition\n\"process FMUStatesManagerOld1(i::FMI2COMP) \\<triangleq> begin\n  state(vstore)\n  AllowsGetsAndSets =\n    (fmi:fmi2GetFMUState?\\<^sub>u(i_s_st : \\<pi>\\<^sub>1(\\<guillemotleft>i_s_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>i\\<guillemotright>) \\<rightarrow>\n      (<s> := \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(&i_s_st)) ;; AllowsGetsAndSets)) \\<box>\n    (fmi:fmi2SetFMUState?\\<^sub>u(i_s_st : \\<pi>\\<^sub>1(\\<guillemotleft>i_s_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>i\\<guillemotright> \\<and> \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(\\<guillemotleft>i_s_st\\<guillemotright>)) =\\<^sub>u $<s>) \\<rightarrow>\n      (<s> := \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(&i_s_st)) ;; AllowsGetsAndSets)) and\n  AllowAGet =\n    (fmi:fmi2GetFMUState?\\<^sub>u(i_s_st : \\<pi>\\<^sub>1(\\<guillemotleft>i_s_st\\<guillemotright>) =\\<^sub>u \\<guillemotleft>i\\<guillemotright>) \\<rightarrow>\n      (<s> := \\<pi>\\<^sub>1(\\<pi>\\<^sub>2(&i_s_st)) ;; AllowsGetsAndSets))\n  \\<bullet> fmi:fmi2Instantiate?\\<^sub>u(i_b : \\<pi>\\<^sub>1(\\<guillemotleft>i_b\\<guillemotright>) =\\<^sub>u \\<guillemotleft>i\\<guillemotright>) \\<rightarrow> AllowAGet\nend\"\n\ndefinition\n\"process FMUStatesManagerOld2(i::FMI2COMP) \\<triangleq> begin\n  state(vstore)\n  AllowsGetsAndSets =\n    (fmi:fmi2GetFMUState![out](\\<guillemotleft>i\\<guillemotright>)?(s)?(st) \\<rightarrow>\\<^sub>\\<C> (<s> := \\<guillemotleft>s\\<guillemotright>) ;; AllowsGetsAndSets) \\<box>\n    (fmi:fmi2SetFMUState![out\\<^sub>1](\\<guillemotleft>i\\<guillemotright>)![out\\<^sub>2](&<s>) \\<rightarrow>\\<^sub>\\<C> AllowsGetsAndSets) and\n  AllowAGet =\n    (fmi:fmi2GetFMUState![out](\\<guillemotleft>i\\<guillemotright>)?(s)?(st) \\<rightarrow>\\<^sub>\\<C> (<s> := \\<guillemotleft>s\\<guillemotright>) ;; AllowsGetsAndSets)\n  \\<bullet> fmi:fmi2Instantiate![out](\\<guillemotleft>i\\<guillemotright>)?(b) \\<rightarrow>\\<^sub>\\<C> AllowAGet\nend\"\n\nsubsection {* Proof Experiments *}\n\nterm \"setT!\\<^sub>u(\\<guillemotleft>0\\<guillemotright>) \\<rightarrow> SKIP\"\nterm \"InputCSP setT x\"\nterm \"\\<lceil>''x''\\<rceil>\\<^sub>d\"\nterm \"(dvar_lens \\<lceil>''x''\\<rceil>\\<^sub>d)\"\nterm \"\\<lceil>''x''\\<rceil>\\<^sub>d\\<up>\"\nterm \"InputCircus setT (\\<lceil>''x''\\<rceil>\\<^sub>d\\<up>)\"\nend", "meta": {"author": "isabelle-utp", "repo": "utp-main", "sha": "27bdf3aee6d4fc00c8fe4d53283d0101857e0d41", "save_path": "github-repos/isabelle/isabelle-utp-utp-main", "path": "github-repos/isabelle/isabelle-utp-utp-main/utp-main-27bdf3aee6d4fc00c8fe4d53283d0101857e0d41/fmi/fmi_export.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5156199157230156, "lm_q2_score": 0.49218813572079556, "lm_q1q2_score": 0.25378200506022475}}
{"text": "(*<*)\ntheory Monitor\n  imports\n    Formula\n    Optimized_Join\n    \"MFOTL_Monitor.Abstract_Monitor\"\n    \"HOL-Library.While_Combinator\"\n    \"HOL-Library.Mapping\"\n    \"Deriving.Derive\"\n    \"Generic_Join.Generic_Join_Correctness\"\nbegin\n(*>*)\n\nsection \\<open>Generic monitoring algorithm\\<close>\n\ntext \\<open>The algorithm defined here abstracts over the implementation of the temporal operators.\\<close>\n\nsubsection \\<open>Monitorable formulas\\<close>\n\ndefinition \"mmonitorable \\<phi> \\<longleftrightarrow> safe_formula \\<phi> \\<and> Formula.future_bounded \\<phi>\"\ndefinition \"mmonitorable_regex b g r \\<longleftrightarrow> safe_regex b g r \\<and> Regex.pred_regex Formula.future_bounded r\"\n\ndefinition is_simple_eq :: \"Formula.trm \\<Rightarrow> Formula.trm \\<Rightarrow> bool\" where\n  \"is_simple_eq t1 t2 = (Formula.is_Const t1 \\<and> (Formula.is_Const t2 \\<or> Formula.is_Var t2) \\<or>\n    Formula.is_Var t1 \\<and> Formula.is_Const t2)\"\n\nfun mmonitorable_exec :: \"Formula.formula \\<Rightarrow> bool\" where\n  \"mmonitorable_exec (Formula.Eq t1 t2) = is_simple_eq t1 t2\"\n| \"mmonitorable_exec (Formula.Neg (Formula.Eq (Formula.Var x) (Formula.Var y))) = (x = y)\"\n| \"mmonitorable_exec (Formula.Pred e ts) = list_all (\\<lambda>t. Formula.is_Var t \\<or> Formula.is_Const t) ts\"\n| \"mmonitorable_exec (Formula.Let p \\<phi> \\<psi>) = ({0..<Formula.nfv \\<phi>} \\<subseteq> Formula.fv \\<phi> \\<and> mmonitorable_exec \\<phi> \\<and> mmonitorable_exec \\<psi>)\"\n| \"mmonitorable_exec (Formula.Neg \\<phi>) = (fv \\<phi> = {} \\<and> mmonitorable_exec \\<phi>)\"\n| \"mmonitorable_exec (Formula.Or \\<phi> \\<psi>) = (fv \\<phi> = fv \\<psi> \\<and> mmonitorable_exec \\<phi> \\<and> mmonitorable_exec \\<psi>)\"\n| \"mmonitorable_exec (Formula.And \\<phi> \\<psi>) = (mmonitorable_exec \\<phi> \\<and>\n    (safe_assignment (fv \\<phi>) \\<psi> \\<or> mmonitorable_exec \\<psi> \\<or>\n      fv \\<psi> \\<subseteq> fv \\<phi> \\<and> (is_constraint \\<psi> \\<or> (case \\<psi> of Formula.Neg \\<psi>' \\<Rightarrow> mmonitorable_exec \\<psi>' | _ \\<Rightarrow> False))))\"\n| \"mmonitorable_exec (Formula.Ands l) = (let (pos, neg) = partition mmonitorable_exec l in\n    pos \\<noteq> [] \\<and> list_all mmonitorable_exec (map remove_neg neg) \\<and>\n    \\<Union>(set (map fv neg)) \\<subseteq> \\<Union>(set (map fv pos)))\"\n| \"mmonitorable_exec (Formula.Exists \\<phi>) = (mmonitorable_exec \\<phi>)\"\n| \"mmonitorable_exec (Formula.Agg y \\<omega> b f \\<phi>) = (mmonitorable_exec \\<phi> \\<and>\n    y + b \\<notin> Formula.fv \\<phi> \\<and> {0..<b} \\<subseteq> Formula.fv \\<phi> \\<and> Formula.fv_trm f \\<subseteq> Formula.fv \\<phi>)\"\n| \"mmonitorable_exec (Formula.Prev I \\<phi>) = (mmonitorable_exec \\<phi>)\"\n| \"mmonitorable_exec (Formula.Next I \\<phi>) = (mmonitorable_exec \\<phi>)\"\n| \"mmonitorable_exec (Formula.Since \\<phi> I \\<psi>) = (Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi> \\<and>\n    (mmonitorable_exec \\<phi> \\<or> (case \\<phi> of Formula.Neg \\<phi>' \\<Rightarrow> mmonitorable_exec \\<phi>' | _ \\<Rightarrow> False)) \\<and> mmonitorable_exec \\<psi>)\"\n| \"mmonitorable_exec (Formula.Until \\<phi> I \\<psi>) = (Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi> \\<and> right I \\<noteq> \\<infinity> \\<and>\n    (mmonitorable_exec \\<phi> \\<or> (case \\<phi> of Formula.Neg \\<phi>' \\<Rightarrow> mmonitorable_exec \\<phi>' | _ \\<Rightarrow> False)) \\<and> mmonitorable_exec \\<psi>)\"\n| \"mmonitorable_exec (Formula.MatchP I r) = Regex.safe_regex Formula.fv (\\<lambda>g \\<phi>. mmonitorable_exec \\<phi> \\<or> (g = Lax \\<and> (case \\<phi> of Formula.Neg \\<phi>' \\<Rightarrow> mmonitorable_exec \\<phi>' | _ \\<Rightarrow> False))) Past Strict r\"\n| \"mmonitorable_exec (Formula.MatchF I r) = (Regex.safe_regex Formula.fv (\\<lambda>g \\<phi>. mmonitorable_exec \\<phi> \\<or> (g = Lax \\<and> (case \\<phi> of Formula.Neg \\<phi>' \\<Rightarrow> mmonitorable_exec \\<phi>' | _ \\<Rightarrow> False))) Futu Strict r \\<and> right I \\<noteq> \\<infinity>)\"\n| \"mmonitorable_exec _ = False\"\n\nlemma cases_Neg_iff:\n  \"(case \\<phi> of formula.Neg \\<psi> \\<Rightarrow> P \\<psi> | _ \\<Rightarrow> False) \\<longleftrightarrow> (\\<exists>\\<psi>. \\<phi> = formula.Neg \\<psi> \\<and> P \\<psi>)\"\n  by (cases \\<phi>) auto\n\nlemma safe_formula_mmonitorable_exec: \"safe_formula \\<phi> \\<Longrightarrow> Formula.future_bounded \\<phi> \\<Longrightarrow> mmonitorable_exec \\<phi>\"\nproof (induct \\<phi> rule: safe_formula.induct)\n  case (8 \\<phi> \\<psi>)\n  then show ?case\n    unfolding safe_formula.simps future_bounded.simps mmonitorable_exec.simps\n    by (auto simp: cases_Neg_iff)\nnext\n  case (9 \\<phi> \\<psi>)\n  then show ?case\n    unfolding safe_formula.simps future_bounded.simps mmonitorable_exec.simps\n    by (auto simp: cases_Neg_iff)\nnext\n  case (10 l)\n  from \"10.prems\"(2) have bounded: \"Formula.future_bounded \\<phi>\" if \"\\<phi> \\<in> set l\" for \\<phi>\n    using that by (auto simp: list.pred_set)\n  obtain poss negs where posnegs: \"(poss, negs) = partition safe_formula l\" by simp\n  obtain posm negm where posnegm: \"(posm, negm) = partition mmonitorable_exec l\" by simp\n  have \"set poss \\<subseteq> set posm\"\n  proof (rule subsetI)\n    fix x assume \"x \\<in> set poss\"\n    then have \"x \\<in> set l\" \"safe_formula x\" using posnegs by simp_all\n    then have \"mmonitorable_exec x\" using \"10.hyps\"(1) bounded by blast\n    then show \"x \\<in> set posm\" using \\<open>x \\<in> set poss\\<close> posnegm posnegs by simp\n  qed\n  then have \"set negm \\<subseteq> set negs\" using posnegm posnegs by auto\n  obtain \"poss \\<noteq> []\" \"list_all safe_formula (map remove_neg negs)\"\n    \"(\\<Union>x\\<in>set negs. fv x) \\<subseteq> (\\<Union>x\\<in>set poss. fv x)\"\n    using \"10.prems\"(1) posnegs by simp\n  then have \"posm \\<noteq> []\" using \\<open>set poss \\<subseteq> set posm\\<close> by auto\n  moreover have \"list_all mmonitorable_exec (map remove_neg negm)\"\n  proof -\n    let ?l = \"map remove_neg negm\"\n    have \"\\<And>x. x \\<in> set ?l \\<Longrightarrow> mmonitorable_exec x\"\n    proof -\n      fix x assume \"x \\<in> set ?l\"\n      then obtain y where \"y \\<in> set negm\" \"x = remove_neg y\" by auto\n      then have \"y \\<in> set negs\" using \\<open>set negm \\<subseteq> set negs\\<close> by blast\n      then have \"safe_formula x\"\n        unfolding \\<open>x = remove_neg y\\<close> using \\<open>list_all safe_formula (map remove_neg negs)\\<close>\n        by (simp add: list_all_def)\n      show \"mmonitorable_exec x\"\n      proof (cases \"\\<exists>z. y = Formula.Neg z\")\n        case True\n        then obtain z where \"y = Formula.Neg z\" by blast\n        then show ?thesis\n          using \"10.hyps\"(2)[OF posnegs refl] \\<open>x = remove_neg y\\<close> \\<open>y \\<in> set negs\\<close> posnegs bounded\n            \\<open>safe_formula x\\<close> by fastforce\n      next\n        case False\n        then have \"remove_neg y = y\" by (cases y) simp_all\n        then have \"y = x\" unfolding \\<open>x = remove_neg y\\<close> by simp\n        show ?thesis\n          using \"10.hyps\"(1) \\<open>y \\<in> set negs\\<close> posnegs \\<open>safe_formula x\\<close> unfolding \\<open>y = x\\<close>\n          by auto\n      qed\n    qed\n    then show ?thesis by (simp add: list_all_iff)\n  qed\n  moreover have \"(\\<Union>x\\<in>set negm. fv x) \\<subseteq> (\\<Union>x\\<in>set posm. fv x)\"\n    using \\<open>\\<Union> (fv ` set negs) \\<subseteq> \\<Union> (fv ` set poss)\\<close> \\<open>set poss \\<subseteq> set posm\\<close> \\<open>set negm \\<subseteq> set negs\\<close>\n    by fastforce\n  ultimately show ?case using posnegm by simp\nnext\n  case (15 \\<phi> I \\<psi>)\n  then show ?case\n    unfolding safe_formula.simps future_bounded.simps mmonitorable_exec.simps\n    by (auto simp: cases_Neg_iff)\nnext\n  case (16 \\<phi> I \\<psi>)\n  then show ?case\n    unfolding safe_formula.simps future_bounded.simps mmonitorable_exec.simps\n    by (auto simp: cases_Neg_iff)\nnext\n  case (17 I r)\n  then show ?case\n    by (auto elim!: safe_regex_mono[rotated] simp: cases_Neg_iff regex.pred_set)\nnext\n  case (18 I r)\n  then show ?case\n    by (auto elim!: safe_regex_mono[rotated] simp: cases_Neg_iff regex.pred_set)\nqed (auto simp add: is_simple_eq_def list.pred_set)\n\nlemma safe_assignment_future_bounded: \"safe_assignment X \\<phi> \\<Longrightarrow> Formula.future_bounded \\<phi>\"\n  unfolding safe_assignment_def by (auto split: formula.splits)\n\nlemma is_constraint_future_bounded: \"is_constraint \\<phi> \\<Longrightarrow> Formula.future_bounded \\<phi>\"\n  by (induction rule: is_constraint.induct) simp_all\n\nlemma mmonitorable_exec_mmonitorable: \"mmonitorable_exec \\<phi> \\<Longrightarrow> mmonitorable \\<phi>\"\nproof (induct \\<phi> rule: mmonitorable_exec.induct)\n  case (7 \\<phi> \\<psi>)\n  then show ?case\n    unfolding mmonitorable_def mmonitorable_exec.simps safe_formula.simps\n    by (auto simp: cases_Neg_iff intro: safe_assignment_future_bounded is_constraint_future_bounded)\nnext\n  case (8 l)\n  obtain poss negs where posnegs: \"(poss, negs) = partition safe_formula l\" by simp\n  obtain posm negm where posnegm: \"(posm, negm) = partition mmonitorable_exec l\" by simp\n  have pos_monitorable: \"list_all mmonitorable_exec posm\" using posnegm by (simp add: list_all_iff)\n  have neg_monitorable: \"list_all mmonitorable_exec (map remove_neg negm)\"\n    using \"8.prems\" posnegm by (simp add: list_all_iff)\n  have \"set posm \\<subseteq> set poss\"\n    using \"8.hyps\"(1) posnegs posnegm unfolding mmonitorable_def by auto\n  then have \"set negs \\<subseteq> set negm\"\n    using posnegs posnegm by auto\n\n  have \"poss \\<noteq> []\" using \"8.prems\" posnegm \\<open>set posm \\<subseteq> set poss\\<close> by auto\n  moreover have \"list_all safe_formula (map remove_neg negs)\"\n    using neg_monitorable \"8.hyps\"(2)[OF posnegm refl] \\<open>set negs \\<subseteq> set negm\\<close>\n    unfolding mmonitorable_def by (auto simp: list_all_iff)\n  moreover have \"\\<Union> (fv ` set negm) \\<subseteq> \\<Union> (fv ` set posm)\"\n    using \"8.prems\" posnegm by simp\n  then have \"\\<Union> (fv ` set negs) \\<subseteq> \\<Union> (fv ` set poss)\"\n    using \\<open>set posm \\<subseteq> set poss\\<close> \\<open>set negs \\<subseteq> set negm\\<close> by fastforce\n  ultimately have \"safe_formula (Formula.Ands l)\" using posnegs by simp\n  moreover have \"Formula.future_bounded (Formula.Ands l)\"\n  proof -\n    have \"list_all Formula.future_bounded posm\"\n      using pos_monitorable \"8.hyps\"(1) posnegm unfolding mmonitorable_def\n      by (auto elim!: list.pred_mono_strong)\n    moreover have fnegm: \"list_all Formula.future_bounded (map remove_neg negm)\"\n      using neg_monitorable \"8.hyps\"(2) posnegm unfolding mmonitorable_def\n      by (auto elim!: list.pred_mono_strong)\n    then have \"list_all Formula.future_bounded negm\"\n    proof -\n      have \"\\<And>x. x \\<in> set negm \\<Longrightarrow> Formula.future_bounded x\"\n      proof -\n        fix x assume \"x \\<in> set negm\"\n        have \"Formula.future_bounded (remove_neg x)\" using fnegm \\<open>x \\<in> set negm\\<close> by (simp add: list_all_iff)\n        then show \"Formula.future_bounded x\" by (cases x) auto\n      qed\n      then show ?thesis by (simp add: list_all_iff)\n    qed\n    ultimately have \"list_all Formula.future_bounded l\" using posnegm by (auto simp: list_all_iff)\n    then show ?thesis by (auto simp: list_all_iff)\n  qed\n  ultimately show ?case unfolding mmonitorable_def ..\nnext\n  case (13 \\<phi> I \\<psi>)\n  then show ?case\n    unfolding mmonitorable_def mmonitorable_exec.simps safe_formula.simps\n    by (fastforce simp: cases_Neg_iff)\nnext\n  case (14 \\<phi> I \\<psi>)\n  then show ?case\n    unfolding mmonitorable_def mmonitorable_exec.simps safe_formula.simps\n    by (fastforce simp: one_enat_def cases_Neg_iff)\nnext\n  case (15 I r)\n  then show ?case\n    by (auto elim!: safe_regex_mono[rotated] dest: safe_regex_safe[rotated]\n        simp: mmonitorable_regex_def mmonitorable_def cases_Neg_iff regex.pred_set)\nnext\n  case (16 I r)\n  then show ?case\n    by (auto 0 3 elim!: safe_regex_mono[rotated] dest: safe_regex_safe[rotated]\n        simp: mmonitorable_regex_def mmonitorable_def cases_Neg_iff regex.pred_set)\nqed (auto simp add: mmonitorable_def mmonitorable_regex_def is_simple_eq_def one_enat_def list.pred_set)\n\nlemma monitorable_formula_code[code]: \"mmonitorable \\<phi> = mmonitorable_exec \\<phi>\"\n  using mmonitorable_exec_mmonitorable safe_formula_mmonitorable_exec mmonitorable_def\n  by blast\n\nsubsection \\<open>Handling regular expressions\\<close>\n\ndatatype mregex =\n  MSkip nat\n  | MTestPos nat\n  | MTestNeg nat\n  | MPlus mregex mregex\n  | MTimes mregex mregex\n  | MStar mregex\n\nprimrec ok where\n  \"ok _ (MSkip n) = True\"\n| \"ok m (MTestPos n) = (n < m)\"\n| \"ok m (MTestNeg n) = (n < m)\"\n| \"ok m (MPlus r s) = (ok m r \\<and> ok m s)\"\n| \"ok m (MTimes r s) = (ok m r \\<and> ok m s)\"\n| \"ok m (MStar r) = ok m r\"\n\nprimrec from_mregex where\n  \"from_mregex (MSkip n) _ = Regex.Skip n\"\n| \"from_mregex (MTestPos n) \\<phi>s = Regex.Test (\\<phi>s ! n)\"\n| \"from_mregex (MTestNeg n) \\<phi>s = (if safe_formula (Formula.Neg (\\<phi>s ! n))\n    then Regex.Test (Formula.Neg (Formula.Neg (Formula.Neg (\\<phi>s ! n))))\n    else Regex.Test (Formula.Neg (\\<phi>s ! n)))\"\n| \"from_mregex (MPlus r s) \\<phi>s = Regex.Plus (from_mregex r \\<phi>s) (from_mregex s \\<phi>s)\"\n| \"from_mregex (MTimes r s) \\<phi>s = Regex.Times (from_mregex r \\<phi>s) (from_mregex s \\<phi>s)\"\n| \"from_mregex (MStar r) \\<phi>s = Regex.Star (from_mregex r \\<phi>s)\"\n\nprimrec to_mregex_exec where\n  \"to_mregex_exec (Regex.Skip n) xs = (MSkip n, xs)\"\n| \"to_mregex_exec (Regex.Test \\<phi>) xs = (if safe_formula \\<phi> then (MTestPos (length xs), xs @ [\\<phi>])\n     else case \\<phi> of Formula.Neg \\<phi>' \\<Rightarrow> (MTestNeg (length xs), xs @ [\\<phi>']) | _ \\<Rightarrow> (MSkip 0, xs))\"\n| \"to_mregex_exec (Regex.Plus r s) xs =\n     (let (mr, ys) = to_mregex_exec r xs; (ms, zs) = to_mregex_exec s ys\n     in (MPlus mr ms, zs))\"\n| \"to_mregex_exec (Regex.Times r s) xs =\n     (let (mr, ys) = to_mregex_exec r xs; (ms, zs) = to_mregex_exec s ys\n     in (MTimes mr ms, zs))\"\n| \"to_mregex_exec (Regex.Star r) xs =\n     (let (mr, ys) = to_mregex_exec r xs in (MStar mr, ys))\"\n\nprimrec shift where\n  \"shift (MSkip n) k = MSkip n\"\n| \"shift (MTestPos i) k = MTestPos (i + k)\"\n| \"shift (MTestNeg i) k = MTestNeg (i + k)\"\n| \"shift (MPlus r s) k = MPlus (shift r k) (shift s k)\"\n| \"shift (MTimes r s) k = MTimes (shift r k) (shift s k)\"\n| \"shift (MStar r) k = MStar (shift r k)\"\n\nprimrec to_mregex where\n  \"to_mregex (Regex.Skip n) = (MSkip n, [])\"\n| \"to_mregex (Regex.Test \\<phi>) = (if safe_formula \\<phi> then (MTestPos 0, [\\<phi>])\n     else case \\<phi> of Formula.Neg \\<phi>' \\<Rightarrow> (MTestNeg 0, [\\<phi>']) | _ \\<Rightarrow> (MSkip 0, []))\"\n| \"to_mregex (Regex.Plus r s) =\n     (let (mr, ys) = to_mregex r; (ms, zs) = to_mregex s\n     in (MPlus mr (shift ms (length ys)), ys @ zs))\"\n| \"to_mregex (Regex.Times r s) =\n     (let (mr, ys) = to_mregex r; (ms, zs) = to_mregex s\n     in (MTimes mr (shift ms (length ys)), ys @ zs))\"\n| \"to_mregex (Regex.Star r) =\n     (let (mr, ys) = to_mregex r in (MStar mr, ys))\"\n\nlemma shift_0: \"shift r 0 = r\"\n  by (induct r) auto\n\nlemma shift_shift: \"shift (shift r k) j = shift r (k + j)\"\n  by (induct r) auto\n\nlemma to_mregex_to_mregex_exec:\n  \"case to_mregex r of (mr, \\<phi>s) \\<Rightarrow> to_mregex_exec r xs = (shift mr (length xs), xs @ \\<phi>s)\"\n  by (induct r arbitrary: xs)\n    (auto simp: shift_shift ac_simps split: formula.splits prod.splits)\n\nlemma to_mregex_to_mregex_exec_Nil[code]: \"to_mregex r = to_mregex_exec r []\"\n  using to_mregex_to_mregex_exec[where xs=\"[]\" and r = r] by (auto simp: shift_0)\n\nlemma ok_mono: \"ok m mr \\<Longrightarrow> m \\<le> n \\<Longrightarrow> ok n mr\"\n  by (induct mr) auto\n\nlemma from_mregex_cong: \"ok m mr \\<Longrightarrow> (\\<forall>i < m. xs ! i = ys ! i) \\<Longrightarrow> from_mregex mr xs = from_mregex mr ys\"\n  by (induct mr) auto\n\nlemma not_Neg_cases:\n  \"(\\<forall>\\<psi>. \\<phi> \\<noteq> Formula.Neg \\<psi>) \\<Longrightarrow> (case \\<phi> of formula.Neg \\<psi> \\<Rightarrow> f \\<psi> | _ \\<Rightarrow> x) = x\"\n  by (cases \\<phi>) auto\n\nlemma to_mregex_exec_ok:\n  \"to_mregex_exec r xs = (mr, ys) \\<Longrightarrow> \\<exists>zs. ys = xs @ zs \\<and> set zs = atms r \\<and> ok (length ys) mr\"\nproof (induct r arbitrary: xs mr ys)\n  case (Skip x)\n  then show ?case by (auto split: if_splits prod.splits simp: atms_def elim: ok_mono)\nnext\n  case (Test x)\n  show ?case proof (cases \"\\<exists>x'. x = Formula.Neg x'\")\n    case True\n    with Test show ?thesis by (auto split: if_splits prod.splits simp: atms_def elim: ok_mono)\n  next\n    case False\n    with Test show ?thesis by (auto split: if_splits prod.splits simp: atms_def not_Neg_cases elim: ok_mono)\n  qed\nnext\n  case (Plus r1 r2)\n  then show ?case by (fastforce split: if_splits prod.splits formula.splits simp: atms_def elim: ok_mono)\nnext\n  case (Times r1 r2)\n  then show ?case by (fastforce split: if_splits prod.splits formula.splits simp: atms_def elim: ok_mono)\nnext\n  case (Star r)\n  then show ?case by (auto split: if_splits prod.splits simp: atms_def elim: ok_mono)\nqed\n\nlemma ok_shift: \"ok (i + m) (Monitor.shift r i) \\<longleftrightarrow> ok m r\"\n  by (induct r) auto\n\nlemma to_mregex_ok: \"to_mregex r = (mr, ys) \\<Longrightarrow> set ys = atms r \\<and> ok (length ys) mr\"\nproof (induct r arbitrary: mr ys)\n  case (Skip x)\n  then show ?case by (auto simp: atms_def elim: ok_mono split: if_splits prod.splits)\nnext\n  case (Test x)\n  show ?case proof (cases \"\\<exists>x'. x = Formula.Neg x'\")\n    case True\n    with Test show ?thesis by (auto split: if_splits prod.splits simp: atms_def elim: ok_mono)\n  next\n    case False\n    with Test show ?thesis by (auto split: if_splits prod.splits simp: atms_def not_Neg_cases elim: ok_mono)\n  qed\nnext\n  case (Plus r1 r2)\n  then show ?case by (fastforce simp: ok_shift atms_def elim: ok_mono split: if_splits prod.splits)\nnext\n  case (Times r1 r2)\n  then show ?case by (fastforce simp: ok_shift atms_def elim: ok_mono split: if_splits prod.splits)\nnext\n  case (Star r)\n  then show ?case by (auto simp: atms_def elim: ok_mono split: if_splits prod.splits)\nqed\n\nlemma from_mregex_shift: \"from_mregex (shift r (length xs)) (xs @ ys) = from_mregex r ys\"\n  by (induct r) (auto simp: nth_append)\n\nlemma from_mregex_to_mregex: \"safe_regex m g r \\<Longrightarrow> case_prod from_mregex (to_mregex r) = r\"\n  by (induct r rule: safe_regex.induct)\n    (auto dest: to_mregex_ok intro!: from_mregex_cong simp: nth_append from_mregex_shift cases_Neg_iff\n      split: prod.splits modality.splits)\n\nlemma from_mregex_eq: \"safe_regex m g r \\<Longrightarrow> to_mregex r = (mr, \\<phi>s) \\<Longrightarrow> from_mregex mr \\<phi>s = r\"\n  using from_mregex_to_mregex[of m g r] by auto\n\nlemma from_mregex_to_mregex_exec: \"safe_regex m g r \\<Longrightarrow> case_prod from_mregex (to_mregex_exec r xs) = r\"\nproof (induct r arbitrary: xs rule: safe_regex_induct)\n  case (Plus b g r s)\n  from Plus(3) Plus(1)[of xs] Plus(2)[of \"snd (to_mregex_exec r xs)\"] show ?case\n    by (auto split: prod.splits simp: nth_append dest: to_mregex_exec_ok\n        intro!: from_mregex_cong[where m = \"length (snd (to_mregex_exec r xs))\"])\nnext\n  case (TimesF g r s)\n  from TimesF(3) TimesF(2)[of xs] TimesF(1)[of \"snd (to_mregex_exec r xs)\"] show ?case\n    by (auto split: prod.splits simp: nth_append dest: to_mregex_exec_ok\n        intro!: from_mregex_cong[where m = \"length (snd (to_mregex_exec r xs))\"])\nnext\n  case (TimesP g r s)\n  from TimesP(3) TimesP(1)[of xs] TimesP(2)[of \"snd (to_mregex_exec r xs)\"] show ?case\n    by (auto split: prod.splits simp: nth_append dest: to_mregex_exec_ok\n        intro!: from_mregex_cong[where m = \"length (snd (to_mregex_exec r xs))\"])\nnext\n  case (Star b g r)\n  from Star(2) Star(1)[of xs] show ?case\n    by (auto split: prod.splits)\nqed (auto split: prod.splits simp: cases_Neg_iff)\n\n\nderive linorder mregex\n\nsubsubsection \\<open>LPD\\<close>\n\ndefinition saturate where\n  \"saturate f = while (\\<lambda>S. f S \\<noteq> S) f\"\n\nlemma saturate_code[code]:\n  \"saturate f S = (let S' = f S in if S' = S then S else saturate f S')\"\n  unfolding saturate_def Let_def\n  by (subst while_unfold) auto\n\ndefinition \"MTimesL r S = MTimes r ` S\"\ndefinition \"MTimesR R s = (\\<lambda>r. MTimes r s) ` R\"\n\nprimrec LPD where\n  \"LPD (MSkip n) = (case n of 0 \\<Rightarrow> {} | Suc m \\<Rightarrow> {MSkip m})\"\n| \"LPD (MTestPos \\<phi>) = {}\"\n| \"LPD (MTestNeg \\<phi>) = {}\"\n| \"LPD (MPlus r s) = (LPD r \\<union> LPD s)\"\n| \"LPD (MTimes r s) = MTimesR (LPD r) s \\<union> LPD s\"\n| \"LPD (MStar r) = MTimesR (LPD r) (MStar r)\"\n\nprimrec LPDi where\n  \"LPDi 0 r = {r}\"\n| \"LPDi (Suc i) r = (\\<Union>s \\<in> LPD r. LPDi i s)\"\n\nlemma LPDi_Suc_alt: \"LPDi (Suc i) r = (\\<Union>s \\<in> LPDi i r. LPD s)\"\n  by (induct i arbitrary: r) fastforce+\n\ndefinition \"LPDs r = (\\<Union>i. LPDi i r)\"\n\nlemma LPDs_refl: \"r \\<in> LPDs r\"\n  by (auto simp: LPDs_def intro: exI[of _ 0])\nlemma LPDs_trans: \"r \\<in> LPD s \\<Longrightarrow> s \\<in> LPDs t \\<Longrightarrow> r \\<in> LPDs t\"\n  by (force simp: LPDs_def LPDi_Suc_alt simp del: LPDi.simps intro: exI[of _ \"Suc _\"])\n\nlemma LPDi_Test:\n  \"LPDi i (MSkip 0) \\<subseteq> {MSkip 0}\"\n  \"LPDi i (MTestPos \\<phi>) \\<subseteq> {MTestPos \\<phi>}\"\n  \"LPDi i (MTestNeg \\<phi>) \\<subseteq> {MTestNeg \\<phi>}\"\n  by (induct i) auto\n\nlemma LPDs_Test:\n  \"LPDs (MSkip 0) \\<subseteq> {MSkip 0}\"\n  \"LPDs (MTestPos \\<phi>) \\<subseteq> {MTestPos \\<phi>}\"\n  \"LPDs (MTestNeg \\<phi>) \\<subseteq> {MTestNeg \\<phi>}\"\n  unfolding LPDs_def using LPDi_Test by blast+\n\nlemma LPDi_MSkip: \"LPDi i (MSkip n) \\<subseteq> MSkip ` {i. i \\<le> n}\"\n  by (induct i arbitrary: n) (auto dest: set_mp[OF LPDi_Test(1)] simp: le_Suc_eq split: nat.splits)\n\nlemma LPDs_MSkip: \"LPDs (MSkip n) \\<subseteq> MSkip ` {i. i \\<le> n}\"\n  unfolding LPDs_def using LPDi_MSkip by auto\n\nlemma LPDi_Plus: \"LPDi i (MPlus r s) \\<subseteq> {MPlus r s} \\<union> LPDi i r \\<union> LPDi i s\"\n  by (induct i arbitrary: r s) auto\n\nlemma LPDs_Plus: \"LPDs (MPlus r s) \\<subseteq> {MPlus r s} \\<union> LPDs r \\<union> LPDs s\"\n  unfolding LPDs_def using LPDi_Plus[of _ r s] by auto\n\nlemma LPDi_Times:\n  \"LPDi i (MTimes r s) \\<subseteq> {MTimes r s} \\<union> MTimesR (\\<Union>j \\<le> i. LPDi j r) s \\<union> (\\<Union>j \\<le> i. LPDi j s)\"\nproof (induct i arbitrary: r s)\n  case (Suc i)\n  show ?case\n    by (fastforce simp: MTimesR_def dest: bspec[of _ _ \"Suc _\"] dest!: set_mp[OF Suc])\nqed simp\n\nlemma LPDs_Times: \"LPDs (MTimes r s) \\<subseteq> {MTimes r s} \\<union> MTimesR (LPDs r) s \\<union> LPDs s\"\n  unfolding LPDs_def using LPDi_Times[of _ r s] by (force simp: MTimesR_def)\n\nlemma LPDi_Star: \"j \\<le> i \\<Longrightarrow> LPDi j (MStar r) \\<subseteq> {MStar r} \\<union> MTimesR (\\<Union>j \\<le> i. LPDi j r) (MStar r)\"\nproof (induct i arbitrary: j r)\n  case (Suc i)\n  from Suc(2) show ?case\n    by (auto 0 5 simp: MTimesR_def image_iff le_Suc_eq\n        dest: bspec[of _ _ \"Suc 0\"] bspec[of _ _ \"Suc _\"] set_mp[OF Suc(1)] dest!: set_mp[OF LPDi_Times])\nqed simp\n\nlemma LPDs_Star: \"LPDs (MStar r) \\<subseteq> {MStar r} \\<union> MTimesR (LPDs r) (MStar r)\"\n  unfolding LPDs_def using LPDi_Star[OF order_refl, of _ r] by (force simp: MTimesR_def)\n\nlemma finite_LPDs: \"finite (LPDs r)\"\nproof (induct r)\n  case (MSkip n)\n  then show ?case by (intro finite_subset[OF LPDs_MSkip]) simp\nnext\n  case (MTestPos \\<phi>)\n  then show ?case by (intro finite_subset[OF LPDs_Test(2)]) simp\nnext\n  case (MTestNeg \\<phi>)\n  then show ?case by (intro finite_subset[OF LPDs_Test(3)]) simp\nnext\n  case (MPlus r s)\n  then show ?case by (intro finite_subset[OF LPDs_Plus]) simp\nnext\n  case (MTimes r s)\n  then show ?case by (intro finite_subset[OF LPDs_Times]) (simp add: MTimesR_def)\nnext\n  case (MStar r)\n  then show ?case by (intro finite_subset[OF LPDs_Star]) (simp add: MTimesR_def)\nqed\n\ncontext begin\n\nprivate abbreviation (input) \"addLPD r \\<equiv> \\<lambda>S. insert r S \\<union> Set.bind (insert r S) LPD\"\n\nprivate lemma mono_addLPD: \"mono (addLPD r)\"\n  unfolding mono_def Set.bind_def by auto\n\nprivate lemma LPDs_aux1: \"lfp (addLPD r) \\<subseteq> LPDs r\"\n  by (rule lfp_induct[OF mono_addLPD], auto intro: LPDs_refl LPDs_trans simp: Set.bind_def)\n\nprivate lemma LPDs_aux2: \"LPDi i r \\<subseteq> lfp (addLPD r)\"\nproof (induct i)\n  case 0\n  then show ?case\n    by (subst lfp_unfold[OF mono_addLPD]) auto\nnext\n  case (Suc i)\n  then show ?case\n    by (subst lfp_unfold[OF mono_addLPD]) (auto simp: LPDi_Suc_alt simp del: LPDi.simps)\nqed\n\nlemma LPDs_alt: \"LPDs r = lfp (addLPD r)\"\n  using LPDs_aux1 LPDs_aux2 by (force simp: LPDs_def)\n\nlemma LPDs_code[code]:\n  \"LPDs r = saturate (addLPD r) {}\"\n  unfolding LPDs_alt saturate_def\n  by (rule lfp_while[OF mono_addLPD _ finite_LPDs, of r]) (auto simp: LPDs_refl LPDs_trans Set.bind_def)\n\nend\n\nsubsubsection \\<open>RPD\\<close>\n\nprimrec RPD where\n  \"RPD (MSkip n) = (case n of 0 \\<Rightarrow> {} | Suc m \\<Rightarrow> {MSkip m})\"\n| \"RPD (MTestPos \\<phi>) = {}\"\n| \"RPD (MTestNeg \\<phi>) = {}\"\n| \"RPD (MPlus r s) = (RPD r \\<union> RPD s)\"\n| \"RPD (MTimes r s) = MTimesL r (RPD s) \\<union> RPD r\"\n| \"RPD (MStar r) = MTimesL (MStar r) (RPD r)\"\n\nprimrec RPDi where\n  \"RPDi 0 r = {r}\"\n| \"RPDi (Suc i) r = (\\<Union>s \\<in> RPD r. RPDi i s)\"\n\nlemma RPDi_Suc_alt: \"RPDi (Suc i) r = (\\<Union>s \\<in> RPDi i r. RPD s)\"\n  by (induct i arbitrary: r) fastforce+\n\ndefinition \"RPDs r = (\\<Union>i. RPDi i r)\"\n\nlemma RPDs_refl: \"r \\<in> RPDs r\"\n  by (auto simp: RPDs_def intro: exI[of _ 0])\nlemma RPDs_trans: \"r \\<in> RPD s \\<Longrightarrow> s \\<in> RPDs t \\<Longrightarrow> r \\<in> RPDs t\"\n  by (force simp: RPDs_def RPDi_Suc_alt simp del: RPDi.simps intro: exI[of _ \"Suc _\"])\n\nlemma RPDi_Test:\n  \"RPDi i (MSkip 0) \\<subseteq> {MSkip 0}\"\n  \"RPDi i (MTestPos \\<phi>) \\<subseteq> {MTestPos \\<phi>}\"\n  \"RPDi i (MTestNeg \\<phi>) \\<subseteq> {MTestNeg \\<phi>}\"\n  by (induct i) auto\n\nlemma RPDs_Test:\n  \"RPDs (MSkip 0) \\<subseteq> {MSkip 0}\"\n  \"RPDs (MTestPos \\<phi>) \\<subseteq> {MTestPos \\<phi>}\"\n  \"RPDs (MTestNeg \\<phi>) \\<subseteq> {MTestNeg \\<phi>}\"\n  unfolding RPDs_def using RPDi_Test by blast+\n\nlemma RPDi_MSkip: \"RPDi i (MSkip n) \\<subseteq> MSkip ` {i. i \\<le> n}\"\n  by (induct i arbitrary: n) (auto dest: set_mp[OF RPDi_Test(1)] simp: le_Suc_eq split: nat.splits)\n\nlemma RPDs_MSkip: \"RPDs (MSkip n) \\<subseteq> MSkip ` {i. i \\<le> n}\"\n  unfolding RPDs_def using RPDi_MSkip by auto\n\nlemma RPDi_Plus: \"RPDi i (MPlus r s) \\<subseteq> {MPlus r s} \\<union> RPDi i r \\<union> RPDi i s\"\n  by (induct i arbitrary: r s) auto\n\nlemma RPDi_Suc_RPD_Plus:\n  \"RPDi (Suc i) r \\<subseteq> RPDs (MPlus r s)\"\n  \"RPDi (Suc i) s \\<subseteq> RPDs (MPlus r s)\"\n  unfolding RPDs_def by (force intro!: exI[of _ \"Suc i\"])+\n\nlemma RPDs_Plus: \"RPDs (MPlus r s) \\<subseteq> {MPlus r s} \\<union> RPDs r \\<union> RPDs s\"\n  unfolding RPDs_def using RPDi_Plus[of _ r s] by auto\n\nlemma RPDi_Times:\n  \"RPDi i (MTimes r s) \\<subseteq> {MTimes r s} \\<union> MTimesL r (\\<Union>j \\<le> i. RPDi j s) \\<union> (\\<Union>j \\<le> i. RPDi j r)\"\nproof (induct i arbitrary: r s)\n  case (Suc i)\n  show ?case\n    by (fastforce simp: MTimesL_def dest: bspec[of _ _ \"Suc _\"] dest!: set_mp[OF Suc])\nqed simp\n\nlemma RPDs_Times: \"RPDs (MTimes r s) \\<subseteq> {MTimes r s} \\<union> MTimesL r (RPDs s) \\<union> RPDs r\"\n  unfolding RPDs_def using RPDi_Times[of _ r s] by (force simp: MTimesL_def)\n\nlemma RPDi_Star: \"j \\<le> i \\<Longrightarrow> RPDi j (MStar r) \\<subseteq> {MStar r} \\<union> MTimesL (MStar r) (\\<Union>j \\<le> i. RPDi j r)\"\nproof (induct i arbitrary: j r)\n  case (Suc i)\n  from Suc(2) show ?case\n    by (auto 0 5 simp: MTimesL_def image_iff le_Suc_eq\n        dest: bspec[of _ _ \"Suc 0\"] bspec[of _ _ \"Suc _\"] set_mp[OF Suc(1)] dest!: set_mp[OF RPDi_Times])\nqed simp\n\nlemma RPDs_Star: \"RPDs (MStar r) \\<subseteq> {MStar r} \\<union> MTimesL (MStar r) (RPDs r)\"\n  unfolding RPDs_def using RPDi_Star[OF order_refl, of _ r] by (force simp: MTimesL_def)\n\nlemma finite_RPDs: \"finite (RPDs r)\"\nproof (induct r)\n  case MSkip\n  then show ?case by (intro finite_subset[OF RPDs_MSkip]) simp\nnext\n  case (MTestPos \\<phi>)\n  then show ?case by (intro finite_subset[OF RPDs_Test(2)]) simp\nnext\n  case (MTestNeg \\<phi>)\n  then show ?case by (intro finite_subset[OF RPDs_Test(3)]) simp\nnext\n  case (MPlus r s)\n  then show ?case by (intro finite_subset[OF RPDs_Plus]) simp\nnext\n  case (MTimes r s)\n  then show ?case by (intro finite_subset[OF RPDs_Times]) (simp add: MTimesL_def)\nnext\n  case (MStar r)\n  then show ?case by (intro finite_subset[OF RPDs_Star]) (simp add: MTimesL_def)\nqed\n\ncontext begin\n\nprivate abbreviation (input) \"addRPD r \\<equiv> \\<lambda>S. insert r S \\<union> Set.bind (insert r S) RPD\"\n\nprivate lemma mono_addRPD: \"mono (addRPD r)\"\n  unfolding mono_def Set.bind_def by auto\n\nprivate lemma RPDs_aux1: \"lfp (addRPD r) \\<subseteq> RPDs r\"\n  by (rule lfp_induct[OF mono_addRPD], auto intro: RPDs_refl RPDs_trans simp: Set.bind_def)\n\nprivate lemma RPDs_aux2: \"RPDi i r \\<subseteq> lfp (addRPD r)\"\nproof (induct i)\n  case 0\n  then show ?case\n    by (subst lfp_unfold[OF mono_addRPD]) auto\nnext\n  case (Suc i)\n  then show ?case\n    by (subst lfp_unfold[OF mono_addRPD]) (auto simp: RPDi_Suc_alt simp del: RPDi.simps)\nqed\n\nlemma RPDs_alt: \"RPDs r = lfp (addRPD r)\"\n  using RPDs_aux1 RPDs_aux2 by (force simp: RPDs_def)\n\nlemma RPDs_code[code]:\n  \"RPDs r = saturate (addRPD r) {}\"\n  unfolding RPDs_alt saturate_def\n  by (rule lfp_while[OF mono_addRPD _ finite_RPDs, of r]) (auto simp: RPDs_refl RPDs_trans Set.bind_def)\n\nend\n\nsubsection \\<open>The executable monitor\\<close>\n\ntype_synonym ts = nat\n\ntype_synonym 'a mbuf2 = \"'a table list \\<times> 'a table list\"\ntype_synonym 'a mbufn = \"'a table list list\"\ntype_synonym 'a msaux = \"(ts \\<times> 'a table) list\"\ntype_synonym 'a muaux = \"(ts \\<times> 'a table \\<times> 'a table) list\"\ntype_synonym 'a mr\\<delta>aux = \"(ts \\<times> (mregex, 'a table) mapping) list\"\ntype_synonym 'a ml\\<delta>aux = \"(ts \\<times> 'a table list \\<times> 'a table) list\"\n\ndatatype mconstraint = MEq | MLess | MLessEq\n\nrecord args =\n  args_ivl :: \\<I>\n  args_n :: nat\n  args_L :: \"nat set\"\n  args_R :: \"nat set\"\n  args_pos :: bool\n\ndatatype (dead 'msaux, dead 'muaux) mformula =\n  MRel \"event_data table\"\n  | MPred Formula.name \"Formula.trm list\"\n  | MLet Formula.name nat \"('msaux, 'muaux) mformula\" \"('msaux, 'muaux) mformula\"\n  | MAnd \"nat set\" \"('msaux, 'muaux) mformula\" bool \"nat set\" \"('msaux, 'muaux) mformula\" \"event_data mbuf2\"\n  | MAndAssign \"('msaux, 'muaux) mformula\" \"nat \\<times> Formula.trm\"\n  | MAndRel \"('msaux, 'muaux) mformula\" \"Formula.trm \\<times> bool \\<times> mconstraint \\<times> Formula.trm\"\n  | MAnds \"nat set list\" \"nat set list\" \"('msaux, 'muaux) mformula list\" \"event_data mbufn\"\n  | MOr \"('msaux, 'muaux) mformula\" \"('msaux, 'muaux) mformula\" \"event_data mbuf2\"\n  | MNeg \"('msaux, 'muaux) mformula\"\n  | MExists \"('msaux, 'muaux) mformula\"\n  | MAgg bool nat Formula.agg_op nat \"Formula.trm\" \"('msaux, 'muaux) mformula\"\n  | MPrev \\<I> \"('msaux, 'muaux) mformula\" bool \"event_data table list\" \"ts list\"\n  | MNext \\<I> \"('msaux, 'muaux) mformula\" bool \"ts list\"\n  | MSince args \"('msaux, 'muaux) mformula\" \"('msaux, 'muaux) mformula\" \"event_data mbuf2\" \"ts list\" \"'msaux\"\n  | MUntil args \"('msaux, 'muaux) mformula\" \"('msaux, 'muaux) mformula\" \"event_data mbuf2\" \"ts list\" \"'muaux\"\n  | MMatchP \\<I> \"mregex\" \"mregex list\" \"('msaux, 'muaux) mformula list\" \"event_data mbufn\" \"ts list\" \"event_data mr\\<delta>aux\"\n  | MMatchF \\<I> \"mregex\" \"mregex list\" \"('msaux, 'muaux) mformula list\" \"event_data mbufn\" \"ts list\" \"event_data ml\\<delta>aux\"\n\nrecord ('msaux, 'muaux) mstate =\n  mstate_i :: nat\n  mstate_m :: \"('msaux, 'muaux) mformula\"\n  mstate_n :: nat\n\nfun eq_rel :: \"nat \\<Rightarrow> Formula.trm \\<Rightarrow> Formula.trm \\<Rightarrow> event_data table\" where\n  \"eq_rel n (Formula.Const x) (Formula.Const y) = (if x = y then unit_table n else empty_table)\"\n| \"eq_rel n (Formula.Var x) (Formula.Const y) = singleton_table n x y\"\n| \"eq_rel n (Formula.Const x) (Formula.Var y) = singleton_table n y x\"\n| \"eq_rel n _ _ = undefined\"\n\nlemma regex_atms_size: \"x \\<in> regex.atms r \\<Longrightarrow> size x < regex.size_regex size r\"\n  by (induct r) auto\n\nlemma atms_size:\n  assumes \"x \\<in> atms r\"\n  shows \"size x < Regex.size_regex size r\"\nproof -\n  { fix y assume \"y \\<in> regex.atms r\" \"case y of formula.Neg z \\<Rightarrow> x = z | _ \\<Rightarrow> False\"\n    then have \"size x < Regex.size_regex size r\"\n      by (cases y rule: formula.exhaust) (auto dest: regex_atms_size)\n  }\n  with assms show ?thesis\n    unfolding atms_def\n    by (auto split: formula.splits dest: regex_atms_size)\nqed\n\ndefinition init_args :: \"\\<I> \\<Rightarrow> nat \\<Rightarrow> nat set \\<Rightarrow> nat set \\<Rightarrow> bool \\<Rightarrow> args\" where\n  \"init_args I n L R pos = \\<lparr>args_ivl = I, args_n = n, args_L = L, args_R = R, args_pos = pos\\<rparr>\"\n\nlocale msaux =\n  fixes valid_msaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'msaux \\<Rightarrow> event_data msaux \\<Rightarrow> bool\"\n    and init_msaux :: \"args \\<Rightarrow> 'msaux\"\n    and add_new_ts_msaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'msaux \\<Rightarrow> 'msaux\"\n    and join_msaux :: \"args \\<Rightarrow> event_data table \\<Rightarrow> 'msaux \\<Rightarrow> 'msaux\"\n    and add_new_table_msaux :: \"args \\<Rightarrow> event_data table \\<Rightarrow> 'msaux \\<Rightarrow> 'msaux\"\n    and result_msaux :: \"args \\<Rightarrow> 'msaux \\<Rightarrow> event_data table\"\n  assumes valid_init_msaux: \"L \\<subseteq> R \\<Longrightarrow>\n    valid_msaux (init_args I n L R pos) 0 (init_msaux (init_args I n L R pos)) []\"\n  assumes valid_add_new_ts_msaux: \"valid_msaux args cur aux auxlist \\<Longrightarrow> nt \\<ge> cur \\<Longrightarrow>\n    valid_msaux args nt (add_new_ts_msaux args nt aux)\n    (filter (\\<lambda>(t, rel). enat (nt - t) \\<le> right (args_ivl args)) auxlist)\"\n  assumes valid_join_msaux: \"valid_msaux args cur aux auxlist \\<Longrightarrow>\n    table (args_n args) (args_L args) rel1 \\<Longrightarrow>\n    valid_msaux args cur (join_msaux args rel1 aux)\n    (map (\\<lambda>(t, rel). (t, join rel (args_pos args) rel1)) auxlist)\"\n  assumes valid_add_new_table_msaux: \"valid_msaux args cur aux auxlist \\<Longrightarrow>\n    table (args_n args) (args_R args) rel2 \\<Longrightarrow>\n    valid_msaux args cur (add_new_table_msaux args rel2 aux)\n    (case auxlist of\n      [] => [(cur, rel2)]\n    | ((t, y) # ts) \\<Rightarrow> if t = cur then (t, y \\<union> rel2) # ts else (cur, rel2) # auxlist)\"\n    and valid_result_msaux: \"valid_msaux args cur aux auxlist \\<Longrightarrow> result_msaux args aux =\n    foldr (\\<union>) [rel. (t, rel) \\<leftarrow> auxlist, left (args_ivl args) \\<le> cur - t] {}\"\n\nfun check_before :: \"\\<I> \\<Rightarrow> ts \\<Rightarrow> (ts \\<times> 'a \\<times> 'b) \\<Rightarrow> bool\" where\n  \"check_before I dt (t, a, b) \\<longleftrightarrow> enat t + right I < enat dt\"\n\nfun proj_thd :: \"('a \\<times> 'b \\<times> 'c) \\<Rightarrow> 'c\" where\n  \"proj_thd (t, a1, a2) = a2\"\n\ndefinition update_until :: \"args \\<Rightarrow> event_data table \\<Rightarrow> event_data table \\<Rightarrow> ts \\<Rightarrow> event_data muaux \\<Rightarrow> event_data muaux\" where\n  \"update_until args rel1 rel2 nt aux =\n    (map (\\<lambda>x. case x of (t, a1, a2) \\<Rightarrow> (t, if (args_pos args) then join a1 True rel1 else a1 \\<union> rel1,\n      if mem (nt - t) (args_ivl args) then a2 \\<union> join rel2 (args_pos args) a1 else a2)) aux) @\n    [(nt, rel1, if left (args_ivl args) = 0 then rel2 else empty_table)]\"\n\nlemma map_proj_thd_update_until: \"map proj_thd (takeWhile (check_before (args_ivl args) nt) auxlist) =\n  map proj_thd (takeWhile (check_before (args_ivl args) nt) (update_until args rel1 rel2 nt auxlist))\"\nproof (induction auxlist)\n  case Nil\n  then show ?case by (simp add: update_until_def)\nnext\n  case (Cons a auxlist)\n  then show ?case\n    by (cases \"right (args_ivl args)\") (auto simp add: update_until_def split: if_splits prod.splits)\nqed\n\nfun eval_until :: \"\\<I> \\<Rightarrow> ts \\<Rightarrow> event_data muaux \\<Rightarrow> event_data table list \\<times> event_data muaux\" where\n  \"eval_until I nt [] = ([], [])\"\n| \"eval_until I nt ((t, a1, a2) # aux) = (if t + right I < nt then\n    (let (xs, aux) = eval_until I nt aux in (a2 # xs, aux)) else ([], (t, a1, a2) # aux))\"\n\nlemma eval_until_length:\n  \"eval_until I nt auxlist = (res, auxlist') \\<Longrightarrow> length auxlist = length res + length auxlist'\"\n  by (induction I nt auxlist arbitrary: res auxlist' rule: eval_until.induct)\n    (auto split: if_splits prod.splits)\n\nlemma eval_until_res: \"eval_until I nt auxlist = (res, auxlist') \\<Longrightarrow>\n  res = map proj_thd (takeWhile (check_before I nt) auxlist)\"\n  by (induction I nt auxlist arbitrary: res auxlist' rule: eval_until.induct)\n    (auto split: prod.splits)\n\nlemma eval_until_auxlist': \"eval_until I nt auxlist = (res, auxlist') \\<Longrightarrow>\n  auxlist' = drop (length res) auxlist\"\n  by (induction I nt auxlist arbitrary: res auxlist' rule: eval_until.induct)\n    (auto split: if_splits prod.splits)\n\nlocale muaux =\n  fixes valid_muaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'muaux \\<Rightarrow> event_data muaux \\<Rightarrow> bool\"\n    and init_muaux :: \"args \\<Rightarrow> 'muaux\"\n    and add_new_muaux :: \"args \\<Rightarrow> event_data table \\<Rightarrow> event_data table \\<Rightarrow> ts \\<Rightarrow> 'muaux \\<Rightarrow> 'muaux\"\n    and length_muaux :: \"args \\<Rightarrow> 'muaux \\<Rightarrow> nat\"\n    and eval_muaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'muaux \\<Rightarrow> event_data table list \\<times> 'muaux\"\n  assumes valid_init_muaux: \"L \\<subseteq> R \\<Longrightarrow>\n    valid_muaux (init_args I n L R pos) 0 (init_muaux (init_args I n L R pos)) []\"\n  assumes valid_add_new_muaux: \"valid_muaux args cur aux auxlist \\<Longrightarrow>\n    table (args_n args) (args_L args) rel1 \\<Longrightarrow>\n    table (args_n args) (args_R args) rel2 \\<Longrightarrow>\n    nt \\<ge> cur \\<Longrightarrow>\n    valid_muaux args nt (add_new_muaux args rel1 rel2 nt aux)\n    (update_until args rel1 rel2 nt auxlist)\"\n  assumes valid_length_muaux: \"valid_muaux args cur aux auxlist \\<Longrightarrow> length_muaux args aux = length auxlist\"\n  assumes valid_eval_muaux: \"valid_muaux args cur aux auxlist \\<Longrightarrow> nt \\<ge> cur \\<Longrightarrow>\n    eval_muaux args nt aux = (res, aux') \\<Longrightarrow> eval_until (args_ivl args) nt auxlist = (res', auxlist') \\<Longrightarrow>\n    res = res' \\<and> valid_muaux args cur aux' auxlist'\"\n\nlocale maux = msaux valid_msaux init_msaux add_new_ts_msaux join_msaux add_new_table_msaux result_msaux +\n  muaux valid_muaux init_muaux add_new_muaux length_muaux eval_muaux\n  for valid_msaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'msaux \\<Rightarrow> event_data msaux \\<Rightarrow> bool\"\n    and init_msaux :: \"args \\<Rightarrow> 'msaux\"\n    and add_new_ts_msaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'msaux \\<Rightarrow> 'msaux\"\n    and join_msaux :: \"args \\<Rightarrow> event_data table \\<Rightarrow> 'msaux \\<Rightarrow> 'msaux\"\n    and add_new_table_msaux :: \"args \\<Rightarrow> event_data table \\<Rightarrow> 'msaux \\<Rightarrow> 'msaux\"\n    and result_msaux :: \"args \\<Rightarrow> 'msaux \\<Rightarrow> event_data table\"\n    and valid_muaux :: \"args \\<Rightarrow> ts \\<Rightarrow> 'muaux \\<Rightarrow> event_data muaux \\<Rightarrow> bool\"\n    and init_muaux :: \"args \\<Rightarrow> 'muaux\"\n    and add_new_muaux :: \"args \\<Rightarrow> event_data table \\<Rightarrow> event_data table \\<Rightarrow> ts \\<Rightarrow> 'muaux \\<Rightarrow> 'muaux\"\n    and length_muaux :: \"args \\<Rightarrow> 'muaux \\<Rightarrow> nat\"\n    and eval_muaux :: \"args \\<Rightarrow> nat \\<Rightarrow> 'muaux \\<Rightarrow> event_data table list \\<times> 'muaux\"\n\nfun split_assignment :: \"nat set \\<Rightarrow> Formula.formula \\<Rightarrow> nat \\<times> Formula.trm\" where\n  \"split_assignment X (Formula.Eq t1 t2) = (case (t1, t2) of\n      (Formula.Var x, Formula.Var y) \\<Rightarrow> if x \\<in> X then (y, t1) else (x, t2)\n    | (Formula.Var x, _) \\<Rightarrow> (x, t2)\n    | (_, Formula.Var y) \\<Rightarrow> (y, t1))\"\n| \"split_assignment _ _ = undefined\"\n\nfun split_constraint :: \"Formula.formula \\<Rightarrow> Formula.trm \\<times> bool \\<times> mconstraint \\<times> Formula.trm\" where\n  \"split_constraint (Formula.Eq t1 t2) = (t1, True, MEq, t2)\"\n| \"split_constraint (Formula.Less t1 t2) = (t1, True, MLess, t2)\"\n| \"split_constraint (Formula.LessEq t1 t2) = (t1, True, MLessEq, t2)\"\n| \"split_constraint (Formula.Neg (Formula.Eq t1 t2)) = (t1, False, MEq, t2)\"\n| \"split_constraint (Formula.Neg (Formula.Less t1 t2)) = (t1, False, MLess, t2)\"\n| \"split_constraint (Formula.Neg (Formula.LessEq t1 t2)) = (t1, False, MLessEq, t2)\"\n| \"split_constraint _ = undefined\"\n\nfunction (in maux) (sequential) minit0 :: \"nat \\<Rightarrow> Formula.formula \\<Rightarrow> ('msaux, 'muaux) mformula\" where\n  \"minit0 n (Formula.Neg \\<phi>) = (if fv \\<phi> = {} then MNeg (minit0 n \\<phi>) else MRel empty_table)\"\n| \"minit0 n (Formula.Eq t1 t2) = MRel (eq_rel n t1 t2)\"\n| \"minit0 n (Formula.Pred e ts) = MPred e ts\"\n| \"minit0 n (Formula.Let p \\<phi> \\<psi>) = MLet p (Formula.nfv \\<phi>) (minit0 (Formula.nfv \\<phi>) \\<phi>) (minit0 n \\<psi>)\"\n| \"minit0 n (Formula.Or \\<phi> \\<psi>) = MOr (minit0 n \\<phi>) (minit0 n \\<psi>) ([], [])\"\n| \"minit0 n (Formula.And \\<phi> \\<psi>) = (if safe_assignment (fv \\<phi>) \\<psi> then\n      MAndAssign (minit0 n \\<phi>) (split_assignment (fv \\<phi>) \\<psi>)\n    else if safe_formula \\<psi> then\n      MAnd (fv \\<phi>) (minit0 n \\<phi>) True (fv \\<psi>) (minit0 n \\<psi>) ([], [])\n    else if is_constraint \\<psi> then\n      MAndRel (minit0 n \\<phi>) (split_constraint \\<psi>)\n    else (case \\<psi> of Formula.Neg \\<psi> \\<Rightarrow>\n      MAnd (fv \\<phi>) (minit0 n \\<phi>) False (fv \\<psi>) (minit0 n \\<psi>) ([], [])))\"\n| \"minit0 n (Formula.Ands l) = (let (pos, neg) = partition safe_formula l in\n    let mpos = map (minit0 n) pos in\n    let mneg = map (minit0 n) (map remove_neg neg) in\n    let vpos = map fv pos in\n    let vneg = map fv neg in\n    MAnds vpos vneg (mpos @ mneg) (replicate (length l) []))\"\n| \"minit0 n (Formula.Exists \\<phi>) = MExists (minit0 (Suc n) \\<phi>)\"\n| \"minit0 n (Formula.Agg y \\<omega> b f \\<phi>) = MAgg (fv \\<phi> \\<subseteq> {0..<b}) y \\<omega> b f (minit0 (b + n) \\<phi>)\"\n| \"minit0 n (Formula.Prev I \\<phi>) = MPrev I (minit0 n \\<phi>) True [] []\"\n| \"minit0 n (Formula.Next I \\<phi>) = MNext I (minit0 n \\<phi>) True []\"\n| \"minit0 n (Formula.Since \\<phi> I \\<psi>) = (if safe_formula \\<phi>\n    then MSince (init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) True) (minit0 n \\<phi>) (minit0 n \\<psi>) ([], []) [] (init_msaux (init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) True))\n    else (case \\<phi> of\n      Formula.Neg \\<phi> \\<Rightarrow> MSince (init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) False) (minit0 n \\<phi>) (minit0 n \\<psi>) ([], []) [] (init_msaux (init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) False))\n    | _ \\<Rightarrow> undefined))\"\n| \"minit0 n (Formula.Until \\<phi> I \\<psi>) = (if safe_formula \\<phi>\n    then MUntil (init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) True) (minit0 n \\<phi>) (minit0 n \\<psi>) ([], []) [] (init_muaux (init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) True))\n    else (case \\<phi> of\n      Formula.Neg \\<phi> \\<Rightarrow> MUntil (init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) False) (minit0 n \\<phi>) (minit0 n \\<psi>) ([], []) [] (init_muaux (init_args I n (Formula.fv \\<phi>) (Formula.fv \\<psi>) False))\n    | _ \\<Rightarrow> undefined))\"\n| \"minit0 n (Formula.MatchP I r) =\n    (let (mr, \\<phi>s) = to_mregex r\n    in MMatchP I mr (sorted_list_of_set (RPDs mr)) (map (minit0 n) \\<phi>s) (replicate (length \\<phi>s) []) [] [])\"\n| \"minit0 n (Formula.MatchF I r) =\n    (let (mr, \\<phi>s) = to_mregex r\n    in MMatchF I mr (sorted_list_of_set (LPDs mr)) (map (minit0 n) \\<phi>s) (replicate (length \\<phi>s) []) [] [])\"\n| \"minit0 n _ = undefined\"\n  by pat_completeness auto\ntermination (in maux)\n  by (relation \"measure (\\<lambda>(_, \\<phi>). size \\<phi>)\")\n    (auto simp: less_Suc_eq_le size_list_estimation' size_remove_neg\n      dest!: to_mregex_ok[OF sym] atms_size)\n\ndefinition (in maux) minit :: \"Formula.formula \\<Rightarrow> ('msaux, 'muaux) mstate\" where\n  \"minit \\<phi> = (let n = Formula.nfv \\<phi> in \\<lparr>mstate_i = 0, mstate_m = minit0 n \\<phi>, mstate_n = n\\<rparr>)\"\n\ndefinition (in maux) minit_safe where\n  \"minit_safe \\<phi> = (if mmonitorable_exec \\<phi> then minit \\<phi> else undefined)\"\n\nfun mprev_next :: \"\\<I> \\<Rightarrow> event_data table list \\<Rightarrow> ts list \\<Rightarrow> event_data table list \\<times> event_data table list \\<times> ts list\" where\n  \"mprev_next I [] ts = ([], [], ts)\"\n| \"mprev_next I xs [] = ([], xs, [])\"\n| \"mprev_next I xs [t] = ([], xs, [t])\"\n| \"mprev_next I (x # xs) (t # t' # ts) = (let (ys, zs) = mprev_next I xs (t' # ts)\n    in ((if mem (t' - t) I then x else empty_table) # ys, zs))\"\n\nfun mbuf2_add :: \"event_data table list \\<Rightarrow> event_data table list \\<Rightarrow> event_data mbuf2 \\<Rightarrow> event_data mbuf2\" where\n  \"mbuf2_add xs' ys' (xs, ys) = (xs @ xs', ys @ ys')\"\n\nfun mbuf2_take :: \"(event_data table \\<Rightarrow> event_data table \\<Rightarrow> 'b) \\<Rightarrow> event_data mbuf2 \\<Rightarrow> 'b list \\<times> event_data mbuf2\" where\n  \"mbuf2_take f (x # xs, y # ys) = (let (zs, buf) = mbuf2_take f (xs, ys) in (f x y # zs, buf))\"\n| \"mbuf2_take f (xs, ys) = ([], (xs, ys))\"\n\nfun mbuf2t_take :: \"(event_data table \\<Rightarrow> event_data table \\<Rightarrow> ts \\<Rightarrow> 'b \\<Rightarrow> 'b) \\<Rightarrow> 'b \\<Rightarrow>\n    event_data mbuf2 \\<Rightarrow> ts list \\<Rightarrow> 'b \\<times> event_data mbuf2 \\<times> ts list\" where\n  \"mbuf2t_take f z (x # xs, y # ys) (t # ts) = mbuf2t_take f (f x y t z) (xs, ys) ts\"\n| \"mbuf2t_take f z (xs, ys) ts = (z, (xs, ys), ts)\"\n\nlemma size_list_length_diff1: \"xs \\<noteq> [] \\<Longrightarrow> [] \\<notin> set xs \\<Longrightarrow>\n  size_list (\\<lambda>xs. length xs - Suc 0) xs < size_list length xs\"\nproof (induct xs)\n  case (Cons x xs)\n  then show ?case\n    by (cases xs) auto\nqed simp\n\nfun mbufn_add :: \"event_data table list list \\<Rightarrow> event_data mbufn \\<Rightarrow> event_data mbufn\" where\n  \"mbufn_add xs' xs = List.map2 (@) xs xs'\"\n\nfunction mbufn_take :: \"(event_data table list \\<Rightarrow> 'b \\<Rightarrow> 'b) \\<Rightarrow> 'b \\<Rightarrow> event_data mbufn \\<Rightarrow> 'b \\<times> event_data mbufn\" where\n  \"mbufn_take f z buf = (if buf = [] \\<or> [] \\<in> set buf then (z, buf)\n    else mbufn_take f (f (map hd buf) z) (map tl buf))\"\n  by pat_completeness auto\ntermination by (relation \"measure (\\<lambda>(_, _, buf). size_list length buf)\")\n    (auto simp: comp_def Suc_le_eq size_list_length_diff1)\n\nfun mbufnt_take :: \"(event_data table list \\<Rightarrow> ts \\<Rightarrow> 'b \\<Rightarrow> 'b) \\<Rightarrow>\n    'b \\<Rightarrow> event_data mbufn \\<Rightarrow> ts list \\<Rightarrow> 'b \\<times> event_data mbufn \\<times> ts list\" where\n  \"mbufnt_take f z buf ts =\n    (if [] \\<in> set buf \\<or> ts = [] then (z, buf, ts)\n    else mbufnt_take f (f (map hd buf) (hd ts) z) (map tl buf) (tl ts))\"\n\nfun match :: \"Formula.trm list \\<Rightarrow> event_data list \\<Rightarrow> (nat \\<rightharpoonup> event_data) option\" where\n  \"match [] [] = Some Map.empty\"\n| \"match (Formula.Const x # ts) (y # ys) = (if x = y then match ts ys else None)\"\n| \"match (Formula.Var x # ts) (y # ys) = (case match ts ys of\n      None \\<Rightarrow> None\n    | Some f \\<Rightarrow> (case f x of\n        None \\<Rightarrow> Some (f(x \\<mapsto> y))\n      | Some z \\<Rightarrow> if y = z then Some f else None))\"\n| \"match _ _ = None\"\n\nfun meval_trm :: \"Formula.trm \\<Rightarrow> event_data tuple \\<Rightarrow> event_data\" where\n  \"meval_trm (Formula.Var x) v = the (v ! x)\"\n| \"meval_trm (Formula.Const x) v = x\"\n| \"meval_trm (Formula.Plus x y) v = meval_trm x v + meval_trm y v\"\n| \"meval_trm (Formula.Minus x y) v = meval_trm x v - meval_trm y v\"\n| \"meval_trm (Formula.UMinus x) v = - meval_trm x v\"\n| \"meval_trm (Formula.Mult x y) v = meval_trm x v * meval_trm y v\"\n| \"meval_trm (Formula.Div x y) v = meval_trm x v div meval_trm y v\"\n| \"meval_trm (Formula.Mod x y) v = meval_trm x v mod meval_trm y v\"\n| \"meval_trm (Formula.F2i x) v = EInt (integer_of_event_data (meval_trm x v))\"\n| \"meval_trm (Formula.I2f x) v = EFloat (double_of_event_data (meval_trm x v))\"\n\ndefinition eval_agg :: \"nat \\<Rightarrow> bool \\<Rightarrow> nat \\<Rightarrow> Formula.agg_op \\<Rightarrow> nat \\<Rightarrow> Formula.trm \\<Rightarrow>\n  event_data table \\<Rightarrow> event_data table\" where\n  \"eval_agg n g0 y \\<omega> b f rel = (if g0 \\<and> rel = empty_table\n    then singleton_table n y (eval_agg_op \\<omega> {})\n    else (\\<lambda>k.\n      let group = Set.filter (\\<lambda>x. drop b x = k) rel;\n        M = (\\<lambda>y. (y, ecard (Set.filter (\\<lambda>x. meval_trm f x = y) group))) ` meval_trm f ` group\n      in k[y:=Some (eval_agg_op \\<omega> M)]) ` (drop b) ` rel)\"\n\ndefinition (in maux) update_since :: \"args \\<Rightarrow> event_data table \\<Rightarrow> event_data table \\<Rightarrow> ts \\<Rightarrow>\n  'msaux \\<Rightarrow> event_data table \\<times> 'msaux\" where\n  \"update_since args rel1 rel2 nt aux =\n    (let aux0 = join_msaux args rel1 (add_new_ts_msaux args nt aux);\n         aux' = add_new_table_msaux args rel2 aux0\n    in (result_msaux args aux', aux'))\"\n\ndefinition \"lookup = Mapping.lookup_default empty_table\"\n\nfun \\<epsilon>_lax where\n  \"\\<epsilon>_lax guard \\<phi>s (MSkip n) = (if n = 0 then guard else empty_table)\"\n| \"\\<epsilon>_lax guard \\<phi>s (MTestPos i) = join guard True (\\<phi>s ! i)\"\n| \"\\<epsilon>_lax guard \\<phi>s (MTestNeg i) = join guard False (\\<phi>s ! i)\"\n| \"\\<epsilon>_lax guard \\<phi>s (MPlus r s) = \\<epsilon>_lax guard \\<phi>s r \\<union> \\<epsilon>_lax guard \\<phi>s s\"\n| \"\\<epsilon>_lax guard \\<phi>s (MTimes r s) = join (\\<epsilon>_lax guard \\<phi>s r) True (\\<epsilon>_lax guard \\<phi>s s)\"\n| \"\\<epsilon>_lax guard \\<phi>s (MStar r) = guard\"\n\nfun r\\<epsilon>_strict where\n  \"r\\<epsilon>_strict n \\<phi>s (MSkip m) = (if m = 0 then unit_table n else empty_table)\"\n| \"r\\<epsilon>_strict n \\<phi>s (MTestPos i) = \\<phi>s ! i\"\n| \"r\\<epsilon>_strict n \\<phi>s (MTestNeg i) = (if \\<phi>s ! i = empty_table then unit_table n else empty_table)\"\n| \"r\\<epsilon>_strict n \\<phi>s (MPlus r s) = r\\<epsilon>_strict n \\<phi>s r \\<union> r\\<epsilon>_strict n \\<phi>s s\"\n| \"r\\<epsilon>_strict n \\<phi>s (MTimes r s) = \\<epsilon>_lax (r\\<epsilon>_strict n \\<phi>s r) \\<phi>s s\"\n| \"r\\<epsilon>_strict n \\<phi>s (MStar r) = unit_table n\"\n\nfun l\\<epsilon>_strict where\n  \"l\\<epsilon>_strict n \\<phi>s (MSkip m) = (if m = 0 then unit_table n else empty_table)\"\n| \"l\\<epsilon>_strict n \\<phi>s (MTestPos i) = \\<phi>s ! i\"\n| \"l\\<epsilon>_strict n \\<phi>s (MTestNeg i) = (if \\<phi>s ! i = empty_table then unit_table n else empty_table)\"\n| \"l\\<epsilon>_strict n \\<phi>s (MPlus r s) = l\\<epsilon>_strict n \\<phi>s r \\<union> l\\<epsilon>_strict n \\<phi>s s\"\n| \"l\\<epsilon>_strict n \\<phi>s (MTimes r s) = \\<epsilon>_lax (l\\<epsilon>_strict n \\<phi>s s) \\<phi>s r\"\n| \"l\\<epsilon>_strict n \\<phi>s (MStar r) = unit_table n\"\n\nfun r\\<delta> :: \"(mregex \\<Rightarrow> mregex) \\<Rightarrow> (mregex, 'a table) mapping \\<Rightarrow> 'a table list \\<Rightarrow> mregex \\<Rightarrow> 'a table\"  where\n  \"r\\<delta> \\<kappa> X \\<phi>s (MSkip n) = (case n of 0 \\<Rightarrow> empty_table | Suc m \\<Rightarrow> lookup X (\\<kappa> (MSkip m)))\"\n| \"r\\<delta> \\<kappa> X \\<phi>s (MTestPos i) = empty_table\"\n| \"r\\<delta> \\<kappa> X \\<phi>s (MTestNeg i) = empty_table\"\n| \"r\\<delta> \\<kappa> X \\<phi>s (MPlus r s) = r\\<delta> \\<kappa> X \\<phi>s r \\<union> r\\<delta> \\<kappa> X \\<phi>s s\"\n| \"r\\<delta> \\<kappa> X \\<phi>s (MTimes r s) = r\\<delta> (\\<lambda>t. \\<kappa> (MTimes r t)) X \\<phi>s s \\<union> \\<epsilon>_lax (r\\<delta> \\<kappa> X \\<phi>s r) \\<phi>s s\"\n| \"r\\<delta> \\<kappa> X \\<phi>s (MStar r) = r\\<delta> (\\<lambda>t. \\<kappa> (MTimes (MStar r) t)) X \\<phi>s r\"\n\nfun l\\<delta> :: \"(mregex \\<Rightarrow> mregex) \\<Rightarrow> (mregex, 'a table) mapping \\<Rightarrow> 'a table list \\<Rightarrow> mregex \\<Rightarrow> 'a table\" where\n  \"l\\<delta> \\<kappa> X \\<phi>s (MSkip n) = (case n of 0 \\<Rightarrow> empty_table | Suc m \\<Rightarrow> lookup X (\\<kappa> (MSkip m)))\"\n| \"l\\<delta> \\<kappa> X \\<phi>s (MTestPos i) = empty_table\"\n| \"l\\<delta> \\<kappa> X \\<phi>s (MTestNeg i) = empty_table\"\n| \"l\\<delta> \\<kappa> X \\<phi>s (MPlus r s) = l\\<delta> \\<kappa> X \\<phi>s r \\<union> l\\<delta> \\<kappa> X \\<phi>s s\"\n| \"l\\<delta> \\<kappa> X \\<phi>s (MTimes r s) = l\\<delta> (\\<lambda>t. \\<kappa> (MTimes t s)) X \\<phi>s r \\<union> \\<epsilon>_lax (l\\<delta> \\<kappa> X \\<phi>s s) \\<phi>s r\"\n| \"l\\<delta> \\<kappa> X \\<phi>s (MStar r) = l\\<delta> (\\<lambda>t. \\<kappa> (MTimes t (MStar r))) X \\<phi>s r\"\n\nlift_definition mrtabulate :: \"mregex list \\<Rightarrow> (mregex \\<Rightarrow> 'b table) \\<Rightarrow> (mregex, 'b table) mapping\"\n  is \"\\<lambda>ks f. (map_of (List.map_filter (\\<lambda>k. let fk = f k in if fk = empty_table then None else Some (k, fk)) ks))\" .\n\nlemma lookup_tabulate:\n  \"distinct xs \\<Longrightarrow> lookup (mrtabulate xs f) x = (if x \\<in> set xs then f x else empty_table)\"\n  unfolding lookup_default_def lookup_def\n  by transfer (auto simp: Let_def map_filter_def map_of_eq_None_iff o_def image_image dest!: map_of_SomeD\n      split: if_splits option.splits)\n\ndefinition update_matchP :: \"nat \\<Rightarrow> \\<I> \\<Rightarrow> mregex \\<Rightarrow> mregex list \\<Rightarrow> event_data table list \\<Rightarrow> ts \\<Rightarrow>\n  event_data mr\\<delta>aux \\<Rightarrow> event_data table \\<times> event_data mr\\<delta>aux\" where\n  \"update_matchP n I mr mrs rels nt aux =\n    (let aux = (case [(t, mrtabulate mrs (\\<lambda>mr.\n        r\\<delta> id rel rels mr \\<union> (if t = nt then r\\<epsilon>_strict n rels mr else {}))).\n      (t, rel) \\<leftarrow> aux, enat (nt - t) \\<le> right I]\n      of [] \\<Rightarrow> [(nt, mrtabulate mrs (r\\<epsilon>_strict n rels))]\n      | x # aux' \\<Rightarrow> (if fst x = nt then x # aux'\n                     else (nt, mrtabulate mrs (r\\<epsilon>_strict n rels)) # x # aux'))\n    in (foldr (\\<union>) [lookup rel mr. (t, rel) \\<leftarrow> aux, left I \\<le> nt - t] {}, aux))\"\n\ndefinition update_matchF_base where\n  \"update_matchF_base n I mr mrs rels nt =\n     (let X = mrtabulate mrs (l\\<epsilon>_strict n rels)\n     in ([(nt, rels, if left I = 0 then lookup X mr else empty_table)], X))\"\n\ndefinition update_matchF_step where\n  \"update_matchF_step I mr mrs nt = (\\<lambda>(t, rels', rel) (aux', X).\n     (let Y = mrtabulate mrs (l\\<delta> id X rels')\n     in ((t, rels', if mem (nt - t) I then rel \\<union> lookup Y mr else rel) # aux', Y)))\"\n\ndefinition update_matchF :: \"nat \\<Rightarrow> \\<I> \\<Rightarrow> mregex \\<Rightarrow> mregex list \\<Rightarrow> event_data table list \\<Rightarrow> ts \\<Rightarrow> event_data ml\\<delta>aux \\<Rightarrow> event_data ml\\<delta>aux\" where\n  \"update_matchF n I mr mrs rels nt aux =\n     fst (foldr (update_matchF_step I mr mrs nt) aux (update_matchF_base n I mr mrs rels nt))\"\n\nfun eval_matchF :: \"\\<I> \\<Rightarrow> mregex \\<Rightarrow> ts \\<Rightarrow> event_data ml\\<delta>aux \\<Rightarrow> event_data table list \\<times> event_data ml\\<delta>aux\" where\n  \"eval_matchF I mr nt [] = ([], [])\"\n| \"eval_matchF I mr nt ((t, rels, rel) # aux) = (if t + right I < nt then\n    (let (xs, aux) = eval_matchF I mr nt aux in (rel # xs, aux)) else ([], (t, rels, rel) # aux))\"\n\nprimrec map_split where\n  \"map_split f [] = ([], [])\"\n| \"map_split f (x # xs) =\n    (let (y, z) = f x; (ys, zs) = map_split f xs\n    in (y # ys, z # zs))\"\n\nfun eval_assignment :: \"nat \\<times> Formula.trm \\<Rightarrow> event_data tuple \\<Rightarrow> event_data tuple\" where\n  \"eval_assignment (x, t) y = (y[x:=Some (meval_trm t y)])\"\n\nfun eval_constraint0 :: \"mconstraint \\<Rightarrow> event_data \\<Rightarrow> event_data \\<Rightarrow> bool\" where\n  \"eval_constraint0 MEq x y = (x = y)\"\n| \"eval_constraint0 MLess x y = (x < y)\"\n| \"eval_constraint0 MLessEq x y = (x \\<le> y)\"\n\nfun eval_constraint :: \"Formula.trm \\<times> bool \\<times> mconstraint \\<times> Formula.trm \\<Rightarrow> event_data tuple \\<Rightarrow> bool\" where\n  \"eval_constraint (t1, p, c, t2) x = (eval_constraint0 c (meval_trm t1 x) (meval_trm t2 x) = p)\"\n\nprimrec (in maux) meval :: \"nat \\<Rightarrow> ts \\<Rightarrow> Formula.database \\<Rightarrow> ('msaux, 'muaux) mformula \\<Rightarrow>\n    event_data table list \\<times> ('msaux, 'muaux) mformula\" where\n  \"meval n t db (MRel rel) = ([rel], MRel rel)\"\n| \"meval n t db (MPred e ts) = (map (\\<lambda>X. (\\<lambda>f. Table.tabulate f 0 n) ` Option.these\n    (match ts ` X)) (case Mapping.lookup db e of None \\<Rightarrow> [{}] | Some xs \\<Rightarrow> xs), MPred e ts)\"\n| \"meval n t db (MLet p m \\<phi> \\<psi>) =\n    (let (xs, \\<phi>) = meval m t db \\<phi>; (ys, \\<psi>) = meval n t (Mapping.update p (map (image (map the)) xs) db) \\<psi>\n    in (ys, MLet p m \\<phi> \\<psi>))\"\n| \"meval n t db (MAnd A_\\<phi> \\<phi> pos A_\\<psi> \\<psi> buf) =\n    (let (xs, \\<phi>) = meval n t db \\<phi>; (ys, \\<psi>) = meval n t db \\<psi>;\n      (zs, buf) = mbuf2_take (\\<lambda>r1 r2. bin_join n A_\\<phi> r1 pos A_\\<psi> r2) (mbuf2_add xs ys buf)\n    in (zs, MAnd A_\\<phi> \\<phi> pos A_\\<psi> \\<psi> buf))\"\n| \"meval n t db (MAndAssign \\<phi> conf) =\n    (let (xs, \\<phi>) = meval n t db \\<phi> in (map (\\<lambda>r. eval_assignment conf ` r) xs, MAndAssign \\<phi> conf))\"\n| \"meval n t db (MAndRel \\<phi> conf) =\n    (let (xs, \\<phi>) = meval n t db \\<phi> in (map (Set.filter (eval_constraint conf)) xs, MAndRel \\<phi> conf))\"\n| \"meval n t db (MAnds A_pos A_neg L buf) =\n    (let R = map (meval n t db) L in\n    let buf = mbufn_add (map fst R) buf in\n    let (zs, buf) = mbufn_take (\\<lambda>xs zs. zs @ [mmulti_join n A_pos A_neg xs]) [] buf in\n    (zs, MAnds A_pos A_neg (map snd R) buf))\"\n| \"meval n t db (MOr \\<phi> \\<psi> buf) =\n    (let (xs, \\<phi>) = meval n t db \\<phi>; (ys, \\<psi>) = meval n t db \\<psi>;\n      (zs, buf) = mbuf2_take (\\<lambda>r1 r2. r1 \\<union> r2) (mbuf2_add xs ys buf)\n    in (zs, MOr \\<phi> \\<psi> buf))\"\n| \"meval n t db (MNeg \\<phi>) =\n    (let (xs, \\<phi>) = meval n t db \\<phi> in (map (\\<lambda>r. (if r = empty_table then unit_table n else empty_table)) xs, MNeg \\<phi>))\"\n| \"meval n t db (MExists \\<phi>) =\n    (let (xs, \\<phi>) = meval (Suc n) t db \\<phi> in (map (\\<lambda>r. tl ` r) xs, MExists \\<phi>))\"\n| \"meval n t db (MAgg g0 y \\<omega> b f \\<phi>) =\n    (let (xs, \\<phi>) = meval (b + n) t db \\<phi> in (map (eval_agg n g0 y \\<omega> b f) xs, MAgg g0 y \\<omega> b f \\<phi>))\"\n| \"meval n t db (MPrev I \\<phi> first buf nts) =\n    (let (xs, \\<phi>) = meval n t db \\<phi>;\n      (zs, buf, nts) = mprev_next I (buf @ xs) (nts @ [t])\n    in (if first then empty_table # zs else zs, MPrev I \\<phi> False buf nts))\"\n| \"meval n t db (MNext I \\<phi> first nts) =\n    (let (xs, \\<phi>) = meval n t db \\<phi>;\n      (xs, first) = (case (xs, first) of (_ # xs, True) \\<Rightarrow> (xs, False) | a \\<Rightarrow> a);\n      (zs, _, nts) = mprev_next I xs (nts @ [t])\n    in (zs, MNext I \\<phi> first nts))\"\n| \"meval n t db (MSince args \\<phi> \\<psi> buf nts aux) =\n    (let (xs, \\<phi>) = meval n t db \\<phi>; (ys, \\<psi>) = meval n t db \\<psi>;\n      ((zs, aux), buf, nts) = mbuf2t_take (\\<lambda>r1 r2 t (zs, aux).\n        let (z, aux) = update_since args r1 r2 t aux\n        in (zs @ [z], aux)) ([], aux) (mbuf2_add xs ys buf) (nts @ [t])\n    in (zs, MSince args \\<phi> \\<psi> buf nts aux))\"\n| \"meval n t db (MUntil args \\<phi> \\<psi> buf nts aux) =\n    (let (xs, \\<phi>) = meval n t db \\<phi>; (ys, \\<psi>) = meval n t db \\<psi>;\n      (aux, buf, nts) = mbuf2t_take (add_new_muaux args) aux (mbuf2_add xs ys buf) (nts @ [t]);\n      (zs, aux) = eval_muaux args (case nts of [] \\<Rightarrow> t | nt # _ \\<Rightarrow> nt) aux\n    in (zs, MUntil args \\<phi> \\<psi> buf nts aux))\"\n| \"meval n t db (MMatchP I mr mrs \\<phi>s buf nts aux) =\n    (let (xss, \\<phi>s) = map_split id (map (meval n t db) \\<phi>s);\n      ((zs, aux), buf, nts) = mbufnt_take (\\<lambda>rels t (zs, aux).\n        let (z, aux) = update_matchP n I mr mrs rels t aux\n        in (zs @ [z], aux)) ([], aux) (mbufn_add xss buf) (nts @ [t])\n    in (zs, MMatchP I mr mrs \\<phi>s buf nts aux))\"\n| \"meval n t db (MMatchF I mr mrs \\<phi>s buf nts aux) =\n    (let (xss, \\<phi>s) = map_split id (map (meval n t db) \\<phi>s);\n      (aux, buf, nts) = mbufnt_take (update_matchF n I mr mrs) aux (mbufn_add xss buf) (nts @ [t]);\n      (zs, aux) = eval_matchF I mr (case nts of [] \\<Rightarrow> t | nt # _ \\<Rightarrow> nt) aux\n    in (zs, MMatchF I mr mrs \\<phi>s buf nts aux))\"\n\ndefinition (in maux) mstep :: \"Formula.database \\<times> ts \\<Rightarrow> ('msaux, 'muaux) mstate \\<Rightarrow> (nat \\<times> event_data table) list \\<times> ('msaux, 'muaux) mstate\" where\n  \"mstep tdb st =\n     (let (xs, m) = meval (mstate_n st) (snd tdb) (fst tdb) (mstate_m st)\n     in (List.enumerate (mstate_i st) xs,\n      \\<lparr>mstate_i = mstate_i st + length xs, mstate_m = m, mstate_n = mstate_n st\\<rparr>))\"\n\nsubsection \\<open>Verdict delay\\<close>\n\ncontext fixes \\<sigma> :: Formula.trace begin\n\nfun progress :: \"(Formula.name \\<rightharpoonup> nat) \\<Rightarrow> Formula.formula \\<Rightarrow> nat \\<Rightarrow> nat\" where\n  \"progress P (Formula.Pred e ts) j = (case P e of None \\<Rightarrow> j | Some k \\<Rightarrow> k)\"\n| \"progress P (Formula.Let p \\<phi> \\<psi>) j = progress (P(p \\<mapsto> progress P \\<phi> j)) \\<psi> j\"\n| \"progress P (Formula.Eq t1 t2) j = j\"\n| \"progress P (Formula.Less t1 t2) j = j\"\n| \"progress P (Formula.LessEq t1 t2) j = j\"\n| \"progress P (Formula.Neg \\<phi>) j = progress P \\<phi> j\"\n| \"progress P (Formula.Or \\<phi> \\<psi>) j = min (progress P \\<phi> j) (progress P \\<psi> j)\"\n| \"progress P (Formula.And \\<phi> \\<psi>) j = min (progress P \\<phi> j) (progress P \\<psi> j)\"\n| \"progress P (Formula.Ands l) j = (if l = [] then j else Min (set (map (\\<lambda>\\<phi>. progress P \\<phi> j) l)))\"\n| \"progress P (Formula.Exists \\<phi>) j = progress P \\<phi> j\"\n| \"progress P (Formula.Agg y \\<omega> b f \\<phi>) j = progress P \\<phi> j\"\n| \"progress P (Formula.Prev I \\<phi>) j = (if j = 0 then 0 else min (Suc (progress P \\<phi> j)) j)\"\n| \"progress P (Formula.Next I \\<phi>) j = progress P \\<phi> j - 1\"\n| \"progress P (Formula.Since \\<phi> I \\<psi>) j = min (progress P \\<phi> j) (progress P \\<psi> j)\"\n| \"progress P (Formula.Until \\<phi> I \\<psi>) j =\n    Inf {i. \\<forall>k. k < j \\<and> k \\<le> min (progress P \\<phi> j) (progress P \\<psi> j) \\<longrightarrow> \\<tau> \\<sigma> i + right I \\<ge> \\<tau> \\<sigma> k}\"\n| \"progress P (Formula.MatchP I r) j = min_regex_default (progress P) r j\"\n| \"progress P (Formula.MatchF I r) j =\n    Inf {i. \\<forall>k. k < j \\<and> k \\<le> min_regex_default (progress P) r j \\<longrightarrow> \\<tau> \\<sigma> i + right I \\<ge> \\<tau> \\<sigma> k}\"\n\ndefinition \"progress_regex P = min_regex_default (progress P)\"\n\ndeclare progress.simps[simp del]\nlemmas progress_simps[simp] = progress.simps[folded progress_regex_def[THEN fun_cong, THEN fun_cong]]\n\nend\n\ndefinition \"pred_mapping Q = pred_fun (\\<lambda>_. True) (pred_option Q)\"\ndefinition \"rel_mapping Q = rel_fun (=) (rel_option Q)\"\n\nlemma pred_mapping_alt: \"pred_mapping Q P = (\\<forall>p \\<in> dom P. Q (the (P p)))\"\n  unfolding pred_mapping_def pred_fun_def option.pred_set dom_def\n  by (force split: option.splits)\n\nlemma rel_mapping_alt: \"rel_mapping Q P P' = (dom P = dom P' \\<and> (\\<forall>p \\<in> dom P. Q (the (P p)) (the (P' p))))\"\n  unfolding rel_mapping_def rel_fun_def rel_option_iff dom_def\n  by (force split: option.splits)\n\nlemma rel_mapping_map_upd[simp]: \"Q x y \\<Longrightarrow> rel_mapping Q P P' \\<Longrightarrow> rel_mapping Q (P(p \\<mapsto> x)) (P'(p \\<mapsto> y))\"\n  by (auto simp: rel_mapping_alt)\n\nlemma pred_mapping_map_upd[simp]: \"Q x \\<Longrightarrow> pred_mapping Q P \\<Longrightarrow> pred_mapping Q (P(p \\<mapsto> x))\"\n  by (auto simp: pred_mapping_alt)\n\nlemma pred_mapping_empty[simp]: \"pred_mapping Q Map.empty\"\n  by (auto simp: pred_mapping_alt)\n\nlemma pred_mapping_mono: \"pred_mapping Q P \\<Longrightarrow> Q \\<le> R \\<Longrightarrow> pred_mapping R P\"\n  by (auto simp: pred_mapping_alt)\n\nlemma pred_mapping_mono_strong: \"pred_mapping Q P \\<Longrightarrow>\n  (\\<And>p. p \\<in> dom P \\<Longrightarrow> Q (the (P p)) \\<Longrightarrow> R (the (P p))) \\<Longrightarrow> pred_mapping R P\"\n  by (auto simp: pred_mapping_alt)\n\nlemma progress_mono_gen: \"j \\<le> j' \\<Longrightarrow> rel_mapping (\\<le>) P P' \\<Longrightarrow> progress \\<sigma> P \\<phi> j \\<le> progress \\<sigma> P' \\<phi> j'\"\nproof (induction \\<phi> arbitrary: P P')\n  case (Pred e ts)\n  then show ?case\n    by (force simp: rel_mapping_alt dom_def split: option.splits)\nnext\n  case (Ands l)\n  then show ?case\n    by (auto simp: image_iff intro!: Min.coboundedI[THEN order_trans])\nnext\n  case (Until \\<phi> I \\<psi>)\n  from Until(1,2)[of P P'] Until.prems show ?case\n    by (cases \"right I\")\n      (auto dest: trans_le_add1[OF \\<tau>_mono] intro!: cInf_superset_mono)\nnext\n  case (MatchF I r)\n  from MatchF(1)[of _ P P'] MatchF.prems show ?case\n    by (cases \"right I\"; cases \"regex.atms r = {}\")\n      (auto 0 3 simp: Min_le_iff progress_regex_def dest: trans_le_add1[OF \\<tau>_mono]\n        intro!: cInf_superset_mono elim!: less_le_trans order_trans)\nqed (force simp: Min_le_iff progress_regex_def split: option.splits)+\n\nlemma rel_mapping_reflp: \"reflp Q \\<Longrightarrow> rel_mapping Q P P\"\n  by (auto simp: rel_mapping_alt reflp_def)\n\nlemmas progress_mono = progress_mono_gen[OF _ rel_mapping_reflp[unfolded reflp_def], simplified]\n\nlemma progress_le_gen: \"pred_mapping (\\<lambda>x. x \\<le> j) P \\<Longrightarrow> progress \\<sigma> P \\<phi> j \\<le> j\"\nproof (induction \\<phi> arbitrary: P)\n  case (Pred e ts)\n  then show ?case\n    by (auto simp: pred_mapping_alt dom_def split: option.splits)\nnext\n  case (Ands l)\n  then show ?case\n    by (auto simp: image_iff intro!: Min.coboundedI[where a=\"progress \\<sigma> P (hd l) j\", THEN order_trans])\nnext\n  case (Until \\<phi> I \\<psi>)\n  then show ?case\n    by (cases \"right I\")\n      (auto intro: trans_le_add1[OF \\<tau>_mono] intro!: cInf_lower)\nnext\n  case (MatchF I r)\n  then show ?case\n    by (cases \"right I\")\n      (auto intro: trans_le_add1[OF \\<tau>_mono] intro!: cInf_lower)\nqed (force simp: Min_le_iff progress_regex_def split: option.splits)+\n\nlemma progress_le: \"progress \\<sigma> Map.empty \\<phi> j \\<le> j\"\n  using progress_le_gen[of _ Map.empty] by auto\n\nlemma progress_0_gen[simp]:\n  \"pred_mapping (\\<lambda>x. x = 0) P \\<Longrightarrow> progress \\<sigma> P \\<phi> 0 = 0\"\n  using progress_le_gen[of 0 P] by auto\n\nlemma progress_0[simp]:\n  \"progress \\<sigma> Map.empty \\<phi> 0 = 0\"\n  by (auto simp: pred_mapping_alt)\n\ndefinition max_mapping :: \"('b \\<Rightarrow> 'a option) \\<Rightarrow> ('b \\<Rightarrow> 'a option) \\<Rightarrow> 'b \\<Rightarrow> ('a :: linorder) option\" where\n  \"max_mapping P P' x = (case (P x, P' x) of\n    (None, None) \\<Rightarrow> None\n  | (Some x, None) \\<Rightarrow> None\n  | (None, Some x) \\<Rightarrow> None\n  | (Some x, Some y) \\<Rightarrow> Some (max x y))\"\n\ndefinition Max_mapping :: \"('b \\<Rightarrow> 'a option) set \\<Rightarrow> 'b \\<Rightarrow> ('a :: linorder) option\" where\n  \"Max_mapping Ps x = (if (\\<forall>P \\<in> Ps. P x \\<noteq> None) then Some (Max ((\\<lambda>P. the (P x)) ` Ps)) else None)\"\n\nlemma dom_max_mapping[simp]: \"dom (max_mapping P1 P2) = dom P1 \\<inter> dom P2\"\n  unfolding max_mapping_def by (auto split: option.splits)\n\nlemma dom_Max_mapping[simp]: \"dom (Max_mapping X) = (\\<Inter>P \\<in> X. dom P)\"\n  unfolding Max_mapping_def by (auto split: if_splits)\n\nlemma Max_mapping_coboundedI:\n  assumes \"finite X\" \"\\<forall>Q \\<in> X. dom Q = dom P\" \"P \\<in> X\"\n  shows \"rel_mapping (\\<le>) P (Max_mapping X)\"\n  unfolding rel_mapping_alt\nproof (intro conjI ballI)\n  from assms(3) have \"X \\<noteq> {}\" by auto\n  then show \"dom P = dom (Max_mapping X)\" using assms(2) by auto\nnext\n  fix p\n  assume \"p \\<in> dom P\"\n  with assms show \"the (P p) \\<le> the (Max_mapping X p)\"\n    by (force simp add: Max_mapping_def intro!: Max.coboundedI imageI)\nqed\n\nlemma rel_mapping_trans: \"P OO Q \\<le> R \\<Longrightarrow>\n  rel_mapping P P1 P2 \\<Longrightarrow> rel_mapping Q P2 P3 \\<Longrightarrow> rel_mapping R P1 P3\"\n  by (force simp: rel_mapping_alt dom_def set_eq_iff)\n\nabbreviation range_mapping :: \"nat \\<Rightarrow> nat \\<Rightarrow> ('b \\<Rightarrow> nat option) \\<Rightarrow> bool\" where\n  \"range_mapping i j P \\<equiv> pred_mapping (\\<lambda>x. i \\<le> x \\<and> x \\<le> j) P\"\n\nlemma range_mapping_relax:\n  \"range_mapping i j P \\<Longrightarrow> i' \\<le> i \\<Longrightarrow> j' \\<ge> j \\<Longrightarrow> range_mapping i' j' P\"\n  by (auto simp: pred_mapping_alt dom_def set_eq_iff max_mapping_def split: option.splits)\n\nlemma range_mapping_max_mapping[simp]:\n  \"range_mapping i j1 P1 \\<Longrightarrow> range_mapping i j2 P2 \\<Longrightarrow> range_mapping i (max j1 j2) (max_mapping P1 P2)\"\n  by (auto simp: pred_mapping_alt dom_def set_eq_iff max_mapping_def split: option.splits)\n\nlemma range_mapping_Max_mapping[simp]:\n  \"finite X \\<Longrightarrow> X \\<noteq> {} \\<Longrightarrow> \\<forall>x\\<in>X. range_mapping i (j x) (P x) \\<Longrightarrow> range_mapping i (Max (j ` X)) (Max_mapping (P ` X))\"\n  by (force simp: pred_mapping_alt Max_mapping_def dom_def image_iff\n      intro!: Max_ge_iff[THEN iffD2] split: if_splits)\n\nlemma pred_mapping_le:\n  \"pred_mapping ((\\<le>) i) P1 \\<Longrightarrow> rel_mapping (\\<le>) P1 P2 \\<Longrightarrow> pred_mapping ((\\<le>) (i :: nat)) P2\"\n  by (force simp: rel_mapping_alt pred_mapping_alt dom_def set_eq_iff)\n\nlemma pred_mapping_le':\n  \"pred_mapping ((\\<le>) j) P1 \\<Longrightarrow> i \\<le> j \\<Longrightarrow> rel_mapping (\\<le>) P1 P2 \\<Longrightarrow> pred_mapping ((\\<le>) (i :: nat)) P2\"\n  by (force simp: rel_mapping_alt pred_mapping_alt dom_def set_eq_iff)\n\nlemma max_mapping_cobounded1: \"dom P1 \\<subseteq> dom P2 \\<Longrightarrow> rel_mapping (\\<le>) P1 (max_mapping P1 P2)\"\n  unfolding max_mapping_def rel_mapping_alt by (auto simp: dom_def split: option.splits)\n\nlemma max_mapping_cobounded2: \"dom P2 \\<subseteq> dom P1 \\<Longrightarrow> rel_mapping (\\<le>) P2 (max_mapping P1 P2)\"\n  unfolding max_mapping_def rel_mapping_alt by (auto simp: dom_def split: option.splits)\n\nlemma max_mapping_fun_upd2[simp]:\n  \"(max_mapping P1 (P2(p := y)))(p \\<mapsto> x) = (max_mapping P1 P2)(p \\<mapsto> x)\"\n  by (auto simp: max_mapping_def)\n\nlemma rel_mapping_max_mapping_fun_upd: \"dom P2 \\<subseteq> dom P1 \\<Longrightarrow> p \\<in> dom P2 \\<Longrightarrow> the (P2 p) \\<le> y \\<Longrightarrow>\n  rel_mapping (\\<le>) P2 ((max_mapping P1 P2)(p \\<mapsto> y))\"\n  by (auto simp: rel_mapping_alt max_mapping_def split: option.splits)\n\nlemma progress_ge_gen: \"Formula.future_bounded \\<phi> \\<Longrightarrow>\n   \\<exists>P j. dom P = S \\<and> range_mapping i j P \\<and> i \\<le> progress \\<sigma> P \\<phi> j\"\nproof (induction \\<phi> arbitrary: i S)\n  case (Pred e ts)\n  then show ?case\n    by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some i else None\"])\n      (auto split: option.splits if_splits simp: rel_mapping_alt pred_mapping_alt dom_def)\nnext\n  case (Let p \\<phi> \\<psi>)\n  from Let.prems obtain P2 j2 where P2: \"dom P2 = insert p S\" \"range_mapping i j2 P2\"\n    \"i \\<le> progress \\<sigma> P2 \\<psi> j2\"\n    by (atomize_elim, intro Let(2)) (force simp: pred_mapping_alt rel_mapping_alt dom_def)+\n  from Let.prems obtain P1 j1 where P1: \"dom P1 = S\" \"range_mapping (the (P2 p)) j1 P1\"\n    \"the (P2 p) \\<le> progress \\<sigma> P1 \\<phi> j1\"\n    by (atomize_elim, intro Let(1)) auto\n  let ?P12 = \"max_mapping P1 P2\"\n  from P1 P2 have le1: \"progress \\<sigma> P1 \\<phi> j1 \\<le> progress \\<sigma> (?P12(p := P1 p)) \\<phi> (max j1 j2)\"\n    by (intro progress_mono_gen) (auto simp: rel_mapping_alt max_mapping_def)\n  from P1 P2 have le2: \"progress \\<sigma> P2 \\<psi> j2 \\<le> progress \\<sigma> (?P12(p \\<mapsto> progress \\<sigma> P1 \\<phi> j1)) \\<psi> (max j1 j2)\"\n    by (intro progress_mono_gen) (auto simp: rel_mapping_alt max_mapping_def)\n  show ?case\n    unfolding progress.simps\n  proof (intro exI[of _ \"?P12(p := P1 p)\"] exI[of _ \"max j1 j2\"] conjI)\n    show \"dom (?P12(p := P1 p)) = S\"\n      using P1 P2 by (auto simp: dom_def max_mapping_def)\n  next\n    show \"range_mapping i (max j1 j2) (?P12(p := P1 p))\"\n      using P1 P2 by (force simp add: pred_mapping_alt dom_def max_mapping_def split: option.splits)\n  next\n    have \"i \\<le> progress \\<sigma> P2 \\<psi> j2\" by fact\n    also have \"... \\<le> progress \\<sigma> (?P12(p \\<mapsto> progress \\<sigma> P1 \\<phi> j1)) \\<psi> (max j1 j2)\"\n      using le2 by blast\n    also have \"... \\<le> progress \\<sigma> ((?P12(p := P1 p))(p\\<mapsto>progress \\<sigma> (?P12(p := P1 p)) \\<phi> (max j1 j2))) \\<psi> (max j1 j2)\"\n      by (auto intro!: progress_mono_gen simp: le1 rel_mapping_alt)\n    finally show \"i \\<le> ...\" .\n  qed\nnext\n  case (Eq _ _)\n  then show ?case\n    by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some i else None\"]) (auto split: if_splits simp: pred_mapping_alt)\nnext\n  case (Less _ _)\n  then show ?case\n    by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some i else None\"]) (auto split: if_splits simp: pred_mapping_alt)\nnext\n  case (LessEq _ _)\n  then show ?case\n    by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some i else None\"]) (auto split: if_splits simp: pred_mapping_alt)\nnext\n  case (Or \\<phi>1 \\<phi>2)\n  from Or(3) obtain P1 j1 where P1: \"dom P1 = S\" \"range_mapping i j1 P1\"  \"i \\<le> progress \\<sigma> P1 \\<phi>1 j1\"\n    using Or(1)[of S i] by auto\n  moreover\n  from Or(3) obtain P2 j2 where P2: \"dom P2 = S\" \"range_mapping i j2 P2\" \"i \\<le> progress \\<sigma> P2 \\<phi>2 j2\"\n    using Or(2)[of S i] by auto\n  ultimately have \"i \\<le> progress \\<sigma> (max_mapping P1 P2) (Formula.Or \\<phi>1 \\<phi>2) (max j1 j2)\"\n    by (auto 0 3 elim!: order.trans[OF _ progress_mono_gen] intro: max_mapping_cobounded1 max_mapping_cobounded2)\n  with P1 P2 show ?case by (intro exI[of _ \"max_mapping P1 P2\"] exI[of _ \"max j1 j2\"]) auto\nnext\n  case (And \\<phi>1 \\<phi>2)\n  from And(3) obtain P1 j1 where P1: \"dom P1 = S\" \"range_mapping i j1 P1\"  \"i \\<le> progress \\<sigma> P1 \\<phi>1 j1\"\n    using And(1)[of S i] by auto\n  moreover\n  from And(3) obtain P2 j2 where P2: \"dom P2 = S\" \"range_mapping i j2 P2\" \"i \\<le> progress \\<sigma> P2 \\<phi>2 j2\"\n    using And(2)[of S i] by auto\n  ultimately have \"i \\<le> progress \\<sigma> (max_mapping P1 P2) (Formula.And \\<phi>1 \\<phi>2) (max j1 j2)\"\n    by (auto 0 3 elim!: order.trans[OF _ progress_mono_gen] intro: max_mapping_cobounded1 max_mapping_cobounded2)\n  with P1 P2 show ?case by (intro exI[of _ \"max_mapping P1 P2\"] exI[of _ \"max j1 j2\"]) auto\nnext\n  case (Ands l)\n  show ?case proof (cases \"l = []\")\n    case True\n    then show ?thesis\n      by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some i else None\"])\n        (auto split: if_splits simp: pred_mapping_alt)\n  next\n    case False\n    then obtain \\<phi> where \"\\<phi> \\<in> set l\" by (cases l) auto\n    from Ands.prems have \"\\<forall>\\<phi>\\<in>set l. Formula.future_bounded \\<phi>\"\n      by (simp add: list.pred_set)\n    { fix \\<phi>\n      assume \"\\<phi> \\<in> set l\"\n      with Ands.prems obtain P j where \"dom P = S\" \"range_mapping i j P\" \"i \\<le> progress \\<sigma> P \\<phi> j\"\n        by (atomize_elim, intro Ands(1)[of \\<phi> S i]) (auto simp: list.pred_set)\n      then have \"\\<exists>Pj. dom (fst Pj) = S \\<and> range_mapping i (snd Pj) (fst Pj) \\<and> i \\<le> progress \\<sigma> (fst Pj) \\<phi> (snd Pj)\"\n        (is \"\\<exists>Pj. ?P Pj\")\n        by (intro exI[of _ \"(P, j)\"]) auto\n    }\n    then have \"\\<forall>\\<phi>\\<in>set l. \\<exists>Pj. dom (fst Pj) = S \\<and> range_mapping i (snd Pj) (fst Pj) \\<and> i \\<le> progress \\<sigma> (fst Pj) \\<phi> (snd Pj)\"\n      (is \"\\<forall>\\<phi>\\<in>set l. \\<exists>Pj. ?P Pj \\<phi>\")\n      by blast\n    with Ands(1) Ands.prems False have \"\\<exists>Pjf. \\<forall>\\<phi>\\<in>set l. ?P (Pjf \\<phi>) \\<phi>\"\n      by (auto simp: Ball_def intro: choice)\n    then obtain Pjf where Pjf: \"\\<forall>\\<phi>\\<in>set l. ?P (Pjf \\<phi>) \\<phi>\" ..\n    define Pf where \"Pf = fst o Pjf\"\n    define jf where \"jf = snd o Pjf\"\n    have *: \"dom (Pf \\<phi>) = S\" \"range_mapping i (jf \\<phi>) (Pf \\<phi>)\" \"i \\<le> progress \\<sigma> (Pf \\<phi>) \\<phi> (jf \\<phi>)\"\n      if \"\\<phi> \\<in> set l\" for \\<phi>\n      using Pjf[THEN bspec, OF that] unfolding Pf_def jf_def by auto\n    with False show ?thesis\n      unfolding progress.simps eq_False[THEN iffD2, OF False] if_False\n      by ((subst Min_ge_iff; simp add: False),\n          intro exI[where x=\"MAX \\<phi>\\<in>set l. jf \\<phi>\"] exI[where x=\"Max_mapping (Pf ` set l)\"]\n          conjI ballI order.trans[OF *(3) progress_mono_gen] Max_mapping_coboundedI)\n        (auto simp: False *[OF \\<open>\\<phi> \\<in> set l\\<close>] \\<open>\\<phi> \\<in> set l\\<close>)\n  qed\nnext\n  case (Exists \\<phi>)\n  then show ?case by simp\nnext\n  case (Prev I \\<phi>)\n  then obtain P j where \"dom P = S\" \"range_mapping i j P\" \"i \\<le> progress \\<sigma> P \\<phi> j\"\n    by (atomize_elim, intro Prev(1)) (auto simp: pred_mapping_alt dom_def)\n  with Prev(2) have\n    \"dom P = S \\<and> range_mapping i (max i j) P \\<and> i \\<le> progress \\<sigma> P (formula.Prev I \\<phi>) (max i j)\"\n    by (auto simp: le_Suc_eq max_def pred_mapping_alt split: if_splits\n        elim: order.trans[OF _ progress_mono])\n  then show ?case by blast\nnext\n  case (Next I \\<phi>)\n  then obtain P j where \"dom P = S\" \"range_mapping (Suc i) j P\" \"Suc i \\<le> progress \\<sigma> P \\<phi> j\"\n    by (atomize_elim, intro Next(1)) (auto simp: pred_mapping_alt dom_def)\n  then show ?case\n    by (intro exI[of _ P] exI[of _ j]) (auto 0 3 simp: pred_mapping_alt dom_def)\nnext\n  case (Since \\<phi>1 I \\<phi>2)\n  from Since(3) obtain P1 j1 where P1: \"dom P1 = S\" \"range_mapping i j1 P1\"  \"i \\<le> progress \\<sigma> P1 \\<phi>1 j1\"\n    using Since(1)[of S i] by auto\n  moreover\n  from Since(3) obtain P2 j2 where P2: \"dom P2 = S\" \"range_mapping i j2 P2\" \"i \\<le> progress \\<sigma> P2 \\<phi>2 j2\"\n    using Since(2)[of S i] by auto\n  ultimately have \"i \\<le> progress \\<sigma> (max_mapping P1 P2) (Formula.Since \\<phi>1 I \\<phi>2) (max j1 j2)\"\n    by (auto elim!: order.trans[OF _ progress_mono_gen] simp: max_mapping_cobounded1 max_mapping_cobounded2)\n  with P1 P2 show ?case by (intro exI[of _ \"max_mapping P1 P2\"] exI[of _ \"max j1 j2\"])\n      (auto elim!: pred_mapping_le intro: max_mapping_cobounded1)\nnext\n  case (Until \\<phi>1 I \\<phi>2)\n  from Until.prems obtain b where [simp]: \"right I = enat b\"\n    by (cases \"right I\") (auto)\n  obtain i' where \"i < i'\" and \"\\<tau> \\<sigma> i + b + 1 \\<le> \\<tau> \\<sigma> i'\"\n    using ex_le_\\<tau>[where x=\"\\<tau> \\<sigma> i + b + 1\"] by (auto simp add: less_eq_Suc_le)\n  then have 1: \"\\<tau> \\<sigma> i + b < \\<tau> \\<sigma> i'\" by simp\n  from Until.prems obtain P1 j1 where P1: \"dom P1 = S\" \"range_mapping (Suc i') j1 P1\" \"Suc i' \\<le> progress \\<sigma> P1 \\<phi>1 j1\"\n    by (atomize_elim, intro Until(1)) (auto simp: pred_mapping_alt dom_def)\n  from Until.prems obtain P2 j2 where P2: \"dom P2 = S\" \"range_mapping (Suc i') j2 P2\" \"Suc i' \\<le> progress \\<sigma> P2 \\<phi>2 j2\"\n    by (atomize_elim, intro Until(2)) (auto simp: pred_mapping_alt dom_def)\n  let ?P12 = \"max_mapping P1 P2\"\n  have \"i \\<le> progress \\<sigma> ?P12 (Formula.Until \\<phi>1 I \\<phi>2) (max j1 j2)\"\n    unfolding progress.simps\n  proof (intro cInf_greatest, goal_cases nonempty greatest)\n    case nonempty\n    then show ?case\n      by (auto simp: trans_le_add1[OF \\<tau>_mono] intro!: exI[of _ \"max j1 j2\"])\n  next\n    case (greatest x)\n    from P1(2,3) have \"i' < j1\"\n      by (auto simp: less_eq_Suc_le intro!: progress_le_gen elim!: order.trans pred_mapping_mono_strong)\n    then have \"i' < max j1 j2\" by simp\n    have \"progress \\<sigma> P1 \\<phi>1 j1 \\<le> progress \\<sigma> ?P12 \\<phi>1 (max j1 j2)\"\n      using P1(1) P2(1) by (auto intro!: progress_mono_gen max_mapping_cobounded1)\n    moreover have \"progress \\<sigma> P2 \\<phi>2 j2 \\<le> progress \\<sigma> ?P12 \\<phi>2 (max j1 j2)\"\n      using P1(1) P2(1) by (auto intro!: progress_mono_gen max_mapping_cobounded2)\n    ultimately have \"i' \\<le> min (progress \\<sigma> ?P12 \\<phi>1 (max j1 j2)) (progress \\<sigma> ?P12 \\<phi>2 (max j1 j2))\"\n      using P1(3) P2(3) by simp\n    with greatest \\<open>i' < max j1 j2\\<close> have \"\\<tau> \\<sigma> i' \\<le> \\<tau> \\<sigma> x + b\"\n      by simp\n    with 1 have \"\\<tau> \\<sigma> i < \\<tau> \\<sigma> x\" by simp\n    then show ?case by (auto dest!: less_\\<tau>D)\n  qed\n  with P1 P2 \\<open>i < i'\\<close> show ?case\n    by (intro exI[of _ \"max_mapping P1 P2\"] exI[of _ \"max j1 j2\"]) (auto simp: range_mapping_relax)\nnext\n  case (MatchP I r)\n  then show ?case\n  proof (cases \"regex.atms r = {}\")\n    case True\n    with MatchP.prems show ?thesis\n      unfolding progress.simps\n      by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some i else None\"] exI[of _ i])\n        (auto split: if_splits simp: pred_mapping_alt regex.pred_set)\n  next\n    case False\n    define pick where \"pick = (\\<lambda>\\<phi>. SOME Pj. dom (fst Pj) = S \\<and> range_mapping i (snd Pj) (fst Pj) \\<and>\n       i \\<le> progress \\<sigma> (fst Pj) \\<phi> (snd Pj))\"\n    let ?pickP = \"fst o pick\" let ?pickj = \"snd o pick\"\n    from MatchP have pick: \"\\<phi> \\<in> regex.atms r \\<Longrightarrow> dom (?pickP \\<phi>) = S \\<and>\n      range_mapping i (?pickj \\<phi>) (?pickP \\<phi>) \\<and> i \\<le> progress \\<sigma> (?pickP \\<phi>) \\<phi> (?pickj \\<phi>)\" for \\<phi>\n      unfolding pick_def o_def future_bounded.simps regex.pred_set\n      by (intro someI_ex[where P = \"\\<lambda>Pj. dom (fst Pj) = S \\<and> range_mapping i (snd Pj) (fst Pj) \\<and>\n         i \\<le> progress \\<sigma> (fst Pj) \\<phi> (snd Pj)\"]) auto\n    with False show ?thesis\n      unfolding progress.simps\n      by (intro exI[of _ \"Max_mapping (?pickP ` regex.atms r)\"] exI[of _ \"Max (?pickj ` regex.atms r)\"])\n        (auto simp: Max_mapping_coboundedI\n          order_trans[OF pick[THEN conjunct2, THEN conjunct2] progress_mono_gen])\n  qed\nnext\n  case (MatchF I r)\n  from MatchF.prems obtain b where [simp]: \"right I = enat b\"\n    by auto\n  obtain i' where i': \"i < i'\" \"\\<tau> \\<sigma> i + b + 1 \\<le> \\<tau> \\<sigma> i'\"\n    using ex_le_\\<tau>[where x=\"\\<tau> \\<sigma> i + b + 1\"] by (auto simp add: less_eq_Suc_le)\n  then have 1: \"\\<tau> \\<sigma> i + b < \\<tau> \\<sigma> i'\" by simp\n  have ix: \"i \\<le> x\" if \"\\<tau> \\<sigma> i' \\<le> b + \\<tau> \\<sigma> x\" \"b + \\<tau> \\<sigma> i < \\<tau> \\<sigma> i'\" for x\n    using less_\\<tau>D[of \\<sigma> i] that less_le_trans by fastforce\n  show ?case\n  proof (cases \"regex.atms r = {}\")\n    case True\n    with MatchF.prems i' ix show ?thesis\n      unfolding progress.simps\n      by (intro exI[of _ \"\\<lambda>e. if e \\<in> S then Some (Suc i') else None\"] exI[of _ \"Suc i'\"])\n        (auto split: if_splits simp: pred_mapping_alt regex.pred_set add.commute less_Suc_eq\n          intro!: cInf_greatest dest!: spec[of _ i'] less_imp_le[THEN \\<tau>_mono, of _ i' \\<sigma>])\n  next\n    case False\n    then obtain \\<phi> where \\<phi>: \"\\<phi> \\<in> regex.atms r\" by auto\n    define pick where \"pick = (\\<lambda>\\<phi>. SOME Pj. dom (fst Pj) = S \\<and> range_mapping (Suc i') (snd Pj) (fst Pj) \\<and>\n      Suc i' \\<le> progress \\<sigma> (fst Pj) \\<phi> (snd Pj))\"\n    define pickP where \"pickP = fst o pick\" define pickj where \"pickj = snd o pick\"\n    from MatchF have pick: \"\\<phi> \\<in> regex.atms r \\<Longrightarrow> dom (pickP \\<phi>) = S \\<and>\n    range_mapping (Suc i') (pickj \\<phi>) (pickP \\<phi>) \\<and> Suc i' \\<le> progress \\<sigma> (pickP \\<phi>) \\<phi> (pickj \\<phi>)\" for \\<phi>\n      unfolding pick_def o_def future_bounded.simps regex.pred_set pickj_def pickP_def\n      by (intro someI_ex[where P = \"\\<lambda>Pj. dom (fst Pj) = S \\<and> range_mapping (Suc i') (snd Pj) (fst Pj) \\<and>\n       Suc i' \\<le> progress \\<sigma> (fst Pj) \\<phi> (snd Pj)\"]) auto\n    let ?P = \"Max_mapping (pickP ` regex.atms r)\" let ?j = \"Max (pickj ` regex.atms r)\"\n    from pick[OF \\<phi>] False \\<phi> have \"Suc i' \\<le> ?j\"\n      by (intro order_trans[OF pick[THEN conjunct2, THEN conjunct2], OF \\<phi>] order_trans[OF progress_le_gen])\n        (auto simp: Max_ge_iff dest: range_mapping_relax[of _ _ _ 0, OF _ _ order_refl, simplified])\n    moreover\n    note i' 1 ix\n    moreover\n    from MatchF.prems have \"Regex.pred_regex Formula.future_bounded r\"\n      by auto\n    ultimately show ?thesis using \\<tau>_mono[of _ ?j \\<sigma>] less_\\<tau>D[of \\<sigma> i] pick False\n      by (intro exI[of _ \"?j\"]  exI[of _ \"?P\"])\n        (auto 0 3 intro!: cInf_greatest\n          order_trans[OF le_SucI[OF order_refl] order_trans[OF pick[THEN conjunct2, THEN conjunct2] progress_mono_gen]]\n          range_mapping_Max_mapping[OF _ _ ballI[OF range_mapping_relax[of \"Suc i'\" _ _ i, OF _ _ order_refl]]]\n          simp: ac_simps Suc_le_eq trans_le_add2 Max_mapping_coboundedI progress_regex_def\n          dest: spec[of _ \"i'\"] spec[of _ ?j])\n  qed\nqed (auto split: option.splits)\n\nlemma progress_ge: \"Formula.future_bounded \\<phi> \\<Longrightarrow> \\<exists>j. i \\<le> progress \\<sigma> Map.empty \\<phi> j\"\n  using progress_ge_gen[of \\<phi> \"{}\" i \\<sigma>]\n  by auto\n\n\n\nlemma progress_time_conv:\n  assumes \"\\<forall>i<j. \\<tau> \\<sigma> i = \\<tau> \\<sigma>' i\"\n  shows \"progress \\<sigma> P \\<phi> j = progress \\<sigma>' P \\<phi> j\"\n  using assms proof (induction \\<phi> arbitrary: P)\n  case (Until \\<phi>1 I \\<phi>2)\n  have *: \"i \\<le> j - 1 \\<longleftrightarrow> i < j\" if \"j \\<noteq> 0\" for i\n    using that by auto\n  with Until show ?case\n  proof (cases \"right I\")\n    case (enat b)\n    then show ?thesis\n    proof (cases \"j\")\n      case (Suc n)\n      with enat * Until show ?thesis\n        using \\<tau>_mono[THEN trans_le_add1]\n        by (auto 8 0\n            intro!: box_equals[OF arg_cong[where f=Inf]\n              cInf_restrict_nat[symmetric, where x=n] cInf_restrict_nat[symmetric, where x=n]])\n    qed simp\n  qed simp\nnext\n  case (MatchF I r)\n  have *: \"i \\<le> j - 1 \\<longleftrightarrow> i < j\" if \"j \\<noteq> 0\" for i\n    using that by auto\n  with MatchF show ?case using \\<tau>_mono[THEN trans_le_add1]\n    by (cases \"right I\"; cases j)\n      ((auto 6 0 simp: progress_le_gen progress_regex_def intro!: box_equals[OF arg_cong[where f=Inf]\n            cInf_restrict_nat[symmetric, where x=\"j-1\"] cInf_restrict_nat[symmetric, where x=\"j-1\"]]) [])+\nqed (auto simp: progress_regex_def)\n\nlemma Inf_UNIV_nat: \"(Inf UNIV :: nat) = 0\"\n  by (simp add: cInf_eq_minimum)\n\nlemma progress_prefix_conv:\n  assumes \"prefix_of \\<pi> \\<sigma>\" and \"prefix_of \\<pi> \\<sigma>'\"\n  shows \"progress \\<sigma> P \\<phi> (plen \\<pi>) = progress \\<sigma>' P \\<phi> (plen \\<pi>)\"\n  using assms by (auto intro: progress_time_conv \\<tau>_prefix_conv)\n\nlemma bounded_rtranclp_mono:\n  fixes n :: \"'x :: linorder\"\n  assumes \"\\<And>i j. R i j \\<Longrightarrow> j < n \\<Longrightarrow> S i j\" \"\\<And>i j. R i j \\<Longrightarrow> i \\<le> j\"\n  shows \"rtranclp R i j \\<Longrightarrow> j < n \\<Longrightarrow> rtranclp S i j\"\nproof (induct rule: rtranclp_induct)\n  case (step y z)\n  then show ?case\n    using assms(1,2)[of y z]\n    by (auto elim!: rtrancl_into_rtrancl[to_pred, rotated])\nqed auto\n\nlemma sat_prefix_conv_gen:\n  assumes \"prefix_of \\<pi> \\<sigma>\" and \"prefix_of \\<pi> \\<sigma>'\"\n  shows \"i < progress \\<sigma> P \\<phi> (plen \\<pi>) \\<Longrightarrow> dom V = dom V' \\<Longrightarrow> dom P = dom V \\<Longrightarrow>\n    pred_mapping (\\<lambda>x. x \\<le> plen \\<pi>) P \\<Longrightarrow>\n    (\\<And>p i \\<phi>. p \\<in> dom V \\<Longrightarrow> i < the (P p) \\<Longrightarrow> the (V p) i = the (V' p) i) \\<Longrightarrow>\n    Formula.sat \\<sigma> V v i \\<phi> \\<longleftrightarrow> Formula.sat \\<sigma>' V' v i \\<phi>\"\nproof (induction \\<phi> arbitrary: P V V' v i)\n  case (Pred e ts)\n  from Pred.prems(1,4) have \"i < plen \\<pi>\"\n    by (blast intro!: order.strict_trans2 progress_le_gen)\n  show ?case proof (cases \"V e\")\n    case None\n    then have \"V' e = None\" using \\<open>dom V = dom V'\\<close> by auto\n    with None \\<Gamma>_prefix_conv[OF assms(1,2) \\<open>i < plen \\<pi>\\<close>] show ?thesis by simp\n  next\n    case (Some a)\n    obtain a' where \"V' e = Some a'\" using Some \\<open>dom V = dom V'\\<close> by auto\n    then have \"i < the (P e)\"\n      using Pred.prems(1-3) by (auto split: option.splits)\n    then have \"the (V e) i = the (V' e) i\"\n      using Some by (intro Pred.prems(5)) (simp_all add: domI)\n    with Some \\<open>V' e = Some a'\\<close> show ?thesis by simp\n  qed\nnext\n  case (Let p \\<phi> \\<psi>)\n  let ?V = \"\\<lambda>V \\<sigma>. (V(p \\<mapsto> \\<lambda>i. {v. length v = Formula.nfv \\<phi> \\<and> Formula.sat \\<sigma> V v i \\<phi>}))\"\n  show ?case unfolding sat.simps proof (rule Let.IH(2))\n    from Let.prems show \"i < progress \\<sigma> (P(p \\<mapsto> progress \\<sigma> P \\<phi> (plen \\<pi>))) \\<psi> (plen \\<pi>)\"\n      by simp\n    from Let.prems show \"dom (?V V \\<sigma>) = dom (?V V' \\<sigma>')\"\n      by simp\n    from Let.prems show \"dom (P(p \\<mapsto> progress \\<sigma> P \\<phi> (plen \\<pi>))) = dom (?V V \\<sigma>)\"\n      by simp\n    from Let.prems show \"pred_mapping (\\<lambda>x. x \\<le> plen \\<pi>) (P(p \\<mapsto> progress \\<sigma> P \\<phi> (plen \\<pi>)))\"\n      by (auto intro!: pred_mapping_map_upd elim!: progress_le_gen)\n  next\n    fix p' i \\<phi>'\n    assume 1: \"p' \\<in> dom (?V V \\<sigma>)\" and 2: \"i < the ((P(p \\<mapsto> progress \\<sigma> P \\<phi> (plen \\<pi>))) p')\"\n    show \"the (?V V \\<sigma> p') i = the (?V V' \\<sigma>' p') i\" proof (cases \"p' = p\")\n      case True\n      with Let 2 show ?thesis by auto\n    next\n      case False\n      with 1 2 show ?thesis by (auto intro!: Let.prems(5))\n    qed\n  qed\nnext\n  case (Eq t1 t2)\n  show ?case by simp\nnext\n  case (Neg \\<phi>)\n  then show ?case by simp\nnext\n  case (Or \\<phi>1 \\<phi>2)\n  then show ?case by auto\nnext\n  case (Ands l)\n  from Ands.prems have \"\\<forall>\\<phi>\\<in>set l. i < progress \\<sigma> P \\<phi> (plen \\<pi>)\"\n    by (cases l) simp_all\n  with Ands show ?case unfolding sat_Ands by blast\nnext\n  case (Exists \\<phi>)\n  then show ?case by simp\nnext\n  case (Prev I \\<phi>)\n  with \\<tau>_prefix_conv[OF assms(1,2)] show ?case\n    by (cases i) (auto split: if_splits)\nnext\n  case (Next I \\<phi>)\n  then have \"Suc i < plen \\<pi>\"\n    by (auto intro: order.strict_trans2[OF _ progress_le_gen[of _ P \\<sigma> \\<phi>]])\n  with Next.prems \\<tau>_prefix_conv[OF assms(1,2)] show ?case\n    unfolding sat.simps\n    by (intro conj_cong Next) auto\nnext\n  case (Since \\<phi>1 I \\<phi>2)\n  then have \"i < plen \\<pi>\"\n    by (auto elim!: order.strict_trans2[OF _ progress_le_gen])\n  with Since.prems \\<tau>_prefix_conv[OF assms(1,2)] show ?case\n    unfolding sat.simps\n    by (intro conj_cong ex_cong ball_cong Since) auto\nnext\n  case (Until \\<phi>1 I \\<phi>2)\n  from Until.prems obtain b where right[simp]: \"right I = enat b\"\n    by (cases \"right I\") (auto simp add: Inf_UNIV_nat)\n  from Until.prems obtain j where \"\\<tau> \\<sigma> i + b + 1 \\<le> \\<tau> \\<sigma> j\"\n    \"j \\<le> progress \\<sigma> P \\<phi>1 (plen \\<pi>)\" \"j \\<le> progress \\<sigma> P \\<phi>2 (plen \\<pi>)\"\n    by atomize_elim (auto 0 4 simp add: less_eq_Suc_le not_le intro: Suc_leI dest: spec[of _ \"i\"]\n        dest!: le_cInf_iff[THEN iffD1, rotated -1])\n  then have 1: \"k < progress \\<sigma> P \\<phi>1 (plen \\<pi>)\" and 2: \"k < progress \\<sigma> P \\<phi>2 (plen \\<pi>)\"\n    if \"\\<tau> \\<sigma> k \\<le> \\<tau> \\<sigma> i + b\" for k\n    using that by (fastforce elim!: order.strict_trans2[rotated] intro: less_\\<tau>D[of \\<sigma>])+\n  have 3: \"k < plen \\<pi>\" if \"\\<tau> \\<sigma> k \\<le> \\<tau> \\<sigma> i + b\" for k\n    using 1[OF that] Until(6) by (auto simp only: less_eq_Suc_le order.trans[OF _ progress_le_gen])\n\n  from Until.prems have \"i < progress \\<sigma>' P (Formula.Until \\<phi>1 I \\<phi>2) (plen \\<pi>)\"\n    unfolding progress_prefix_conv[OF assms(1,2)] by blast\n  then obtain j where \"\\<tau> \\<sigma>' i + b + 1 \\<le> \\<tau> \\<sigma>' j\"\n    \"j \\<le> progress \\<sigma>' P \\<phi>1 (plen \\<pi>)\" \"j \\<le> progress \\<sigma>' P \\<phi>2 (plen \\<pi>)\"\n    by atomize_elim (auto 0 4 simp add: less_eq_Suc_le not_le intro: Suc_leI dest: spec[of _ \"i\"]\n        dest!: le_cInf_iff[THEN iffD1, rotated -1])\n  then have 11: \"k < progress \\<sigma> P \\<phi>1 (plen \\<pi>)\" and 21: \"k < progress \\<sigma> P \\<phi>2 (plen \\<pi>)\"\n    if \"\\<tau> \\<sigma>' k \\<le> \\<tau> \\<sigma>' i + b\" for k\n    unfolding progress_prefix_conv[OF assms(1,2)]\n    using that by (fastforce elim!: order.strict_trans2[rotated] intro: less_\\<tau>D[of \\<sigma>'])+\n  have 31: \"k < plen \\<pi>\" if \"\\<tau> \\<sigma>' k \\<le> \\<tau> \\<sigma>' i + b\" for k\n    using 11[OF that] Until(6) by (auto simp only: less_eq_Suc_le order.trans[OF _ progress_le_gen])\n  show ?case unfolding sat.simps\n  proof ((intro ex_cong iffI; elim conjE), goal_cases LR RL)\n    case (LR j)\n    with Until(1)[OF 1] Until(2)[OF 2] \\<tau>_prefix_conv[OF assms(1,2) 3] Until.prems show ?case\n      by (auto 0 4 simp: le_diff_conv add.commute dest: less_imp_le order.trans[OF \\<tau>_mono, rotated])\n  next\n    case (RL j)\n    with Until(1)[OF 11] Until(2)[OF 21] \\<tau>_prefix_conv[OF assms(1,2) 31] Until.prems show ?case\n      by (auto 0 4 simp: le_diff_conv add.commute dest: less_imp_le order.trans[OF \\<tau>_mono, rotated])\n  qed\nnext\n  case (MatchP I r)\n  then have \"i < plen \\<pi>\"\n    by (force simp: pred_mapping_alt elim!: order.strict_trans2[OF _ progress_le_gen])\n  with MatchP.prems \\<tau>_prefix_conv[OF assms(1,2)] show ?case\n    unfolding sat.simps\n    by (intro ex_cong conj_cong match_cong_strong MatchP) (auto simp: progress_regex_def split: if_splits)\nnext\n  case (MatchF I r)\n  from MatchF.prems obtain b where right[simp]: \"right I = enat b\"\n    by (cases \"right I\") (auto simp add: Inf_UNIV_nat)\n  show ?case\n  proof (cases \"regex.atms r = {}\")\n    case True\n    from MatchF.prems(1) obtain j where \"\\<tau> \\<sigma> i + b + 1 \\<le> \\<tau> \\<sigma> j\" \"j \\<le> plen \\<pi>\"\n      by atomize_elim (auto 0 4 simp add: less_eq_Suc_le not_le dest!: le_cInf_iff[THEN iffD1, rotated -1])\n    then have 1: \"k < plen \\<pi>\" if \"\\<tau> \\<sigma> k \\<le> \\<tau> \\<sigma> i + b\" for k\n      by (meson \\<tau>_mono discrete not_le order.strict_trans2 that)\n    from MatchF.prems have \"i < progress \\<sigma>' P (Formula.MatchF I r) (plen \\<pi>)\"\n      unfolding progress_prefix_conv[OF assms(1,2)] by blast\n    then obtain j where \"\\<tau> \\<sigma>' i + b + 1 \\<le> \\<tau> \\<sigma>' j\" \"j \\<le> plen \\<pi>\"\n      by atomize_elim (auto 0 4 simp add: less_eq_Suc_le not_le dest!: le_cInf_iff[THEN iffD1, rotated -1])\n    then have 2: \"k < plen \\<pi>\" if \"\\<tau> \\<sigma>' k \\<le> \\<tau> \\<sigma>' i + b\" for k\n      by (meson \\<tau>_mono discrete not_le order.strict_trans2 that)\n    from MatchF.prems(1,4) True show ?thesis\n      unfolding sat.simps conj_commute[of \"left I \\<le> _\" \"_ \\<le> _\"]\n    proof (intro ex_cong conj_cong match_cong_strong, goal_cases left right sat)\n      case (left j)\n      then show ?case\n        by (intro iffI)\n          ((subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 1, symmetric]; auto elim: order.trans[OF \\<tau>_mono, rotated]),\n            (subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 2]; auto elim: order.trans[OF \\<tau>_mono, rotated]))\n    next\n      case (right j)\n      then show ?case\n        by (intro iffI)\n          ((subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 2, symmetric]; auto elim: order.trans[OF \\<tau>_mono, rotated]),\n            (subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 2]; auto elim: order.trans[OF \\<tau>_mono, rotated]))\n    qed auto\n  next\n    case False\n    from MatchF.prems(1) False obtain j where \"\\<tau> \\<sigma> i + b + 1 \\<le> \\<tau> \\<sigma> j\" \"(\\<forall>x\\<in>regex.atms r. j \\<le> progress \\<sigma> P x (plen \\<pi>))\"\n      by atomize_elim (auto 0 6 simp add: less_eq_Suc_le not_le progress_regex_def\n        dest!: le_cInf_iff[THEN iffD1, rotated -1])\n    then have 1: \"\\<phi> \\<in> regex.atms r \\<Longrightarrow> k < progress \\<sigma> P \\<phi> (plen \\<pi>)\" if \"\\<tau> \\<sigma> k \\<le> \\<tau> \\<sigma> i + b\" for k \\<phi>\n      using that\n      by (fastforce elim!: order.strict_trans2[rotated] intro: less_\\<tau>D[of \\<sigma>])\n    then have 2: \"k < plen \\<pi>\" if \"\\<tau> \\<sigma> k \\<le> \\<tau> \\<sigma> i + b\" \"regex.atms r \\<noteq> {}\" for k\n      using that\n      by (fastforce intro: order.strict_trans2[OF _ progress_le_gen[OF MatchF(5), of \\<sigma>], of k])\n\n    from MatchF.prems have \"i < progress \\<sigma>' P (Formula.MatchF I r) (plen \\<pi>)\"\n      unfolding progress_prefix_conv[OF assms(1,2)] by blast\n    with False obtain j where \"\\<tau> \\<sigma>' i + b + 1 \\<le> \\<tau> \\<sigma>' j\" \"(\\<forall>x\\<in>regex.atms r. j \\<le> progress \\<sigma>' P x (plen \\<pi>))\"\n      by atomize_elim (auto 0 6 simp add: less_eq_Suc_le not_le progress_regex_def\n        dest!: le_cInf_iff[THEN iffD1, rotated -1])\n    then have 11:  \"\\<phi> \\<in> regex.atms r \\<Longrightarrow> k < progress \\<sigma> P \\<phi> (plen \\<pi>)\" if \"\\<tau> \\<sigma>' k \\<le> \\<tau> \\<sigma>' i + b\" for k \\<phi>\n      using that using progress_prefix_conv[OF assms(1,2)]\n      by (auto 0 3 elim!: order.strict_trans2[rotated] intro: less_\\<tau>D[of \\<sigma>'])\n    have 21: \"k < plen \\<pi>\" if \"\\<tau> \\<sigma>' k \\<le> \\<tau> \\<sigma>' i + b\" for k\n      using 11[OF that(1)] False by (fastforce intro: order.strict_trans2[OF _ progress_le_gen[OF MatchF(5), of \\<sigma>], of k])\n    show ?thesis unfolding sat.simps conj_commute[of \"left I \\<le> _\" \"_ \\<le> _\"]\n    proof ((intro ex_cong conj_cong match_cong_strong MatchF(1)[OF _ _ MatchF(3-6)]; assumption?), goal_cases right left progress)\n      case (right j)\n      with False show ?case\n        by (intro iffI)\n          ((subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 2, symmetric]; auto elim: order.trans[OF \\<tau>_mono, rotated]),\n            (subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 21]; auto elim: order.trans[OF \\<tau>_mono, rotated]))\n    next\n      case (left j)\n      with False show ?case unfolding right enat_ord_code le_diff_conv add.commute[of b]\n        by (intro iffI)\n          ((subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 21, symmetric]; auto elim: order.trans[OF \\<tau>_mono, rotated]),\n            (subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 21]; auto elim: order.trans[OF \\<tau>_mono, rotated]))\n    next\n      case (progress j k z)\n      with False show ?case unfolding right enat_ord_code le_diff_conv add.commute[of b]\n        by (elim 1[rotated])\n          (subst (1 2) \\<tau>_prefix_conv[OF assms(1,2) 21]; auto elim!: order.trans[OF \\<tau>_mono, rotated])\n    qed\n  qed\nqed auto\n\nlemma sat_prefix_conv:\n  assumes \"prefix_of \\<pi> \\<sigma>\" and \"prefix_of \\<pi> \\<sigma>'\"\n  shows \"i < progress \\<sigma> Map.empty \\<phi> (plen \\<pi>) \\<Longrightarrow>\n    Formula.sat \\<sigma> Map.empty v i \\<phi> \\<longleftrightarrow> Formula.sat \\<sigma>' Map.empty v i \\<phi>\"\n  by (erule sat_prefix_conv_gen[OF assms]) auto\n\nlemma progress_remove_neg[simp]: \"progress \\<sigma> P (remove_neg \\<phi>) j = progress \\<sigma> P \\<phi> j\"\n  by (cases \\<phi>) simp_all\n\nlemma safe_progress_get_and: \"safe_formula \\<phi> \\<Longrightarrow>\n  Min ((\\<lambda>\\<phi>. progress \\<sigma> P \\<phi> j) ` set (get_and_list \\<phi>)) = progress \\<sigma> P \\<phi> j\"\n  by (induction \\<phi> rule: get_and_list.induct) auto\n\nlemma progress_convert_multiway: \"safe_formula \\<phi> \\<Longrightarrow> progress \\<sigma> P (convert_multiway \\<phi>) j = progress \\<sigma> P \\<phi> j\"\nproof (induction \\<phi> arbitrary: P rule: safe_formula_induct)\n  case (And_safe \\<phi> \\<psi>)\n  let ?c = \"convert_multiway (Formula.And \\<phi> \\<psi>)\"\n  let ?c\\<phi> = \"convert_multiway \\<phi>\"\n  let ?c\\<psi> = \"convert_multiway \\<psi>\"\n  have c_eq: \"?c = Formula.Ands (get_and_list ?c\\<phi> @ get_and_list ?c\\<psi>)\"\n    using And_safe by simp\n  from \\<open>safe_formula \\<phi>\\<close> have \"safe_formula ?c\\<phi>\" by (rule safe_convert_multiway)\n  moreover from \\<open>safe_formula \\<psi>\\<close> have \"safe_formula ?c\\<psi>\" by (rule safe_convert_multiway)\n  ultimately show ?case\n    unfolding c_eq\n    using And_safe.IH\n    by (auto simp: get_and_nonempty Min.union safe_progress_get_and)\nnext\n  case (And_Not \\<phi> \\<psi>)\n  let ?c = \"convert_multiway (Formula.And \\<phi> (Formula.Neg \\<psi>))\"\n  let ?c\\<phi> = \"convert_multiway \\<phi>\"\n  let ?c\\<psi> = \"convert_multiway \\<psi>\"\n  have c_eq: \"?c = Formula.Ands (Formula.Neg ?c\\<psi> # get_and_list ?c\\<phi>)\"\n    using And_Not by simp\n  from \\<open>safe_formula \\<phi>\\<close> have \"safe_formula ?c\\<phi>\" by (rule safe_convert_multiway)\n  moreover from \\<open>safe_formula \\<psi>\\<close> have \"safe_formula ?c\\<psi>\" by (rule safe_convert_multiway)\n  ultimately show ?case\n    unfolding c_eq\n    using And_Not.IH\n    by (auto simp: get_and_nonempty Min.union safe_progress_get_and)\nnext\n  case (MatchP I r)\n  from MatchP show ?case\n    unfolding progress.simps regex.map convert_multiway.simps regex.set_map image_image\n    by (intro if_cong arg_cong[of _ _ Min] image_cong)\n      (auto 0 4 simp: atms_def elim!: disjE_Not2 dest: safe_regex_safe_formula)\nnext\n  case (MatchF I r)\n  from MatchF show ?case\n    unfolding progress.simps regex.map convert_multiway.simps regex.set_map image_image\n    by (intro if_cong arg_cong[of _ _ Min] arg_cong[of _ _ Inf] arg_cong[of _ _ \"(\\<le>) _\"]\n      image_cong Collect_cong all_cong1 imp_cong conj_cong image_cong)\n      (auto 0 4 simp: atms_def elim!: disjE_Not2 dest: safe_regex_safe_formula)\nqed auto\n\n\nsubsection \\<open>Specification\\<close>\n\ndefinition pprogress :: \"Formula.formula \\<Rightarrow> Formula.prefix \\<Rightarrow> nat\" where\n  \"pprogress \\<phi> \\<pi> = (THE n. \\<forall>\\<sigma>. prefix_of \\<pi> \\<sigma> \\<longrightarrow> progress \\<sigma> Map.empty \\<phi> (plen \\<pi>) = n)\"\n\nlemma pprogress_eq: \"prefix_of \\<pi> \\<sigma> \\<Longrightarrow> pprogress \\<phi> \\<pi> = progress \\<sigma> Map.empty \\<phi> (plen \\<pi>)\"\n  unfolding pprogress_def using progress_prefix_conv\n  by blast\n\nlocale future_bounded_mfodl =\n  fixes \\<phi> :: Formula.formula\n  assumes future_bounded: \"Formula.future_bounded \\<phi>\"\n\nsublocale future_bounded_mfodl \\<subseteq> sliceable_timed_progress \"Formula.nfv \\<phi>\" \"Formula.fv \\<phi>\" \"relevant_events \\<phi>\"\n  \"\\<lambda>\\<sigma> v i. Formula.sat \\<sigma> Map.empty v i \\<phi>\" \"pprogress \\<phi>\"\nproof (unfold_locales, goal_cases)\n  case (1 x)\n  then show ?case by (simp add: fvi_less_nfv)\nnext\n  case (2 v v' \\<sigma> i)\n  then show ?case by (simp cong: sat_fv_cong[rule_format])\nnext\n  case (3 v S \\<sigma> i)\n  then show ?case\n    using sat_slice_iff[symmetric] by simp\nnext\n  case (4 \\<pi> \\<pi>')\n  moreover obtain \\<sigma> where \"prefix_of \\<pi>' \\<sigma>\"\n    using ex_prefix_of ..\n  moreover have \"prefix_of \\<pi> \\<sigma>\"\n    using prefix_of_antimono[OF \\<open>\\<pi> \\<le> \\<pi>'\\<close> \\<open>prefix_of \\<pi>' \\<sigma>\\<close>] .\n  ultimately show ?case\n    by (simp add: pprogress_eq plen_mono progress_mono)\nnext\n  case (5 \\<sigma> x)\n  obtain j where \"x \\<le> progress \\<sigma> Map.empty \\<phi> j\"\n    using future_bounded progress_ge by blast\n  then have \"x \\<le> pprogress \\<phi> (take_prefix j \\<sigma>)\"\n    by (simp add: pprogress_eq[of _ \\<sigma>])\n  then show ?case by force\nnext\n  case (6 \\<pi> \\<sigma> \\<sigma>' i v)\n  then have \"i < progress \\<sigma> Map.empty \\<phi> (plen \\<pi>)\"\n    by (simp add: pprogress_eq)\n  with 6 show ?case\n    using sat_prefix_conv by blast\nnext\n  case (7 \\<pi> \\<pi>')\n  then have \"plen \\<pi> = plen \\<pi>'\"\n    by transfer (simp add: list_eq_iff_nth_eq)\n  moreover obtain \\<sigma> \\<sigma>' where \"prefix_of \\<pi> \\<sigma>\" \"prefix_of \\<pi>' \\<sigma>'\"\n    using ex_prefix_of by blast+\n  moreover have \"\\<forall>i < plen \\<pi>. \\<tau> \\<sigma> i = \\<tau> \\<sigma>' i\"\n    using 7 calculation\n    by transfer (simp add: list_eq_iff_nth_eq)\n  ultimately show ?case\n    by (simp add: pprogress_eq progress_time_conv)\nqed\n\nlocale verimon_spec =\n  fixes \\<phi> :: Formula.formula\n  assumes monitorable: \"mmonitorable \\<phi>\"\n\nsublocale verimon_spec \\<subseteq> future_bounded_mfodl\n  using monitorable by unfold_locales (simp add: mmonitorable_def)\n\n\nsubsection \\<open>Correctness\\<close>\n\nsubsubsection \\<open>Invariants\\<close>\n\ndefinition wf_mbuf2 :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> (nat \\<Rightarrow> event_data table \\<Rightarrow> bool) \\<Rightarrow> (nat \\<Rightarrow> event_data table \\<Rightarrow> bool) \\<Rightarrow>\n    event_data mbuf2 \\<Rightarrow> bool\" where\n  \"wf_mbuf2 i ja jb P Q buf \\<longleftrightarrow> i \\<le> ja \\<and> i \\<le> jb \\<and> (case buf of (xs, ys) \\<Rightarrow>\n    list_all2 P [i..<ja] xs \\<and> list_all2 Q [i..<jb] ys)\"\n\ninductive list_all3 :: \"('a \\<Rightarrow> 'b \\<Rightarrow> 'c \\<Rightarrow> bool) \\<Rightarrow> 'a list \\<Rightarrow> 'b list \\<Rightarrow> 'c list \\<Rightarrow> bool\" for P :: \"('a \\<Rightarrow> 'b \\<Rightarrow> 'c \\<Rightarrow> bool)\" where\n  \"list_all3 P [] [] []\"\n| \"P a1 a2 a3 \\<Longrightarrow> list_all3 P q1 q2 q3 \\<Longrightarrow> list_all3 P (a1 # q1) (a2 # q2) (a3 # q3)\"\n\nlemma list_all3_list_all2D: \"list_all3 P xs ys zs \\<Longrightarrow>\n  (length xs = length ys \\<and> list_all2 (case_prod P) (zip xs ys) zs)\"\n  by (induct xs ys zs rule: list_all3.induct) auto\n\nlemma list_all2_list_all3I: \"length xs = length ys \\<Longrightarrow> list_all2 (case_prod P) (zip xs ys) zs \\<Longrightarrow>\n  list_all3 P xs ys zs\"\n  by (induct xs ys arbitrary: zs rule: list_induct2)\n    (auto simp: list_all2_Cons1 intro: list_all3.intros)\n\nlemma list_all3_list_all2_eq: \"list_all3 P xs ys zs \\<longleftrightarrow>\n  (length xs = length ys \\<and> list_all2 (case_prod P) (zip xs ys) zs)\"\n  using list_all2_list_all3I list_all3_list_all2D by blast\n\nlemma list_all3_mapD: \"list_all3 P (map f xs) (map g ys) (map h zs) \\<Longrightarrow>\n  list_all3 (\\<lambda>x y z. P (f x) (g y) (h z)) xs ys zs\"\n  by (induct \"map f xs\" \"map g ys\" \"map h zs\" arbitrary: xs ys zs rule: list_all3.induct)\n    (auto intro: list_all3.intros)\n\nlemma list_all3_mapI: \"list_all3 (\\<lambda>x y z. P (f x) (g y) (h z)) xs ys zs \\<Longrightarrow>\n  list_all3 P (map f xs) (map g ys) (map h zs)\"\n  by (induct xs ys zs rule: list_all3.induct)\n    (auto intro: list_all3.intros)\n\nlemma list_all3_map_iff: \"list_all3 P (map f xs) (map g ys) (map h zs) \\<longleftrightarrow>\n  list_all3 (\\<lambda>x y z. P (f x) (g y) (h z)) xs ys zs\"\n  using list_all3_mapD list_all3_mapI by blast\n\nlemmas list_all3_map =\n  list_all3_map_iff[where g=id and h=id, unfolded list.map_id id_apply]\n  list_all3_map_iff[where f=id and h=id, unfolded list.map_id id_apply]\n  list_all3_map_iff[where f=id and g=id, unfolded list.map_id id_apply]\n\nlemma list_all3_conv_all_nth:\n  \"list_all3 P xs ys zs =\n  (length xs = length ys \\<and> length ys = length zs \\<and> (\\<forall>i < length xs. P (xs!i) (ys!i) (zs!i)))\"\n  by (auto simp add: list_all3_list_all2_eq list_all2_conv_all_nth)\n\nlemma list_all3_refl [intro?]:\n  \"(\\<And>x. x \\<in> set xs \\<Longrightarrow> P x x x) \\<Longrightarrow> list_all3 P xs xs xs\"\n  by (simp add: list_all3_conv_all_nth)\n\ndefinition wf_mbufn :: \"nat \\<Rightarrow> nat list \\<Rightarrow> (nat \\<Rightarrow> event_data table \\<Rightarrow> bool) list \\<Rightarrow> event_data mbufn \\<Rightarrow> bool\" where\n  \"wf_mbufn i js Ps buf \\<longleftrightarrow> list_all3 (\\<lambda>P j xs. i \\<le> j \\<and> list_all2 P [i..<j] xs) Ps js buf\"\n\ndefinition wf_mbuf2' :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> event_data list set \\<Rightarrow>\n  Formula.formula \\<Rightarrow> Formula.formula \\<Rightarrow> event_data mbuf2 \\<Rightarrow> bool\" where\n  \"wf_mbuf2' \\<sigma> P V j n R \\<phi> \\<psi> buf \\<longleftrightarrow> wf_mbuf2 (min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j))\n    (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)\n    (\\<lambda>i. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>))\n    (\\<lambda>i. qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>)) buf\"\n\ndefinition wf_mbufn' :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> event_data list set \\<Rightarrow>\n  Formula.formula Regex.regex \\<Rightarrow> event_data mbufn \\<Rightarrow> bool\" where\n  \"wf_mbufn' \\<sigma>  P V j n R r buf \\<longleftrightarrow> (case to_mregex r of (mr, \\<phi>s) \\<Rightarrow>\n    wf_mbufn (progress_regex \\<sigma> P r j) (map (\\<lambda>\\<phi>. progress \\<sigma> P \\<phi> j) \\<phi>s)\n    (map (\\<lambda>\\<phi> i. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>)) \\<phi>s)\n    buf)\"\n\nlemma wf_mbuf2'_UNIV_alt: \"wf_mbuf2' \\<sigma> P V j n UNIV \\<phi> \\<psi> buf \\<longleftrightarrow> (case buf of (xs, ys) \\<Rightarrow>\n  list_all2 (\\<lambda>i. wf_table n (Formula.fv \\<phi>) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>))\n    [min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j) ..< (progress \\<sigma> P \\<phi> j)] xs \\<and>\n  list_all2 (\\<lambda>i. wf_table n (Formula.fv \\<psi>) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>))\n    [min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j) ..< (progress \\<sigma> P \\<psi> j)] ys)\"\n  unfolding wf_mbuf2'_def wf_mbuf2_def\n  by (simp add: mem_restr_UNIV[THEN eqTrueI, abs_def] split: prod.split)\n\ndefinition wf_ts :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> Formula.formula \\<Rightarrow> Formula.formula \\<Rightarrow> ts list \\<Rightarrow> bool\" where\n  \"wf_ts \\<sigma> P j \\<phi> \\<psi> ts \\<longleftrightarrow> list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)..<j] ts\"\n\ndefinition wf_ts_regex :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> Formula.formula Regex.regex \\<Rightarrow> ts list \\<Rightarrow> bool\" where\n  \"wf_ts_regex \\<sigma> P j r ts \\<longleftrightarrow> list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [progress_regex \\<sigma> P r j..<j] ts\"\n\nabbreviation \"Sincep pos \\<phi> I \\<psi> \\<equiv> Formula.Since (if pos then \\<phi> else Formula.Neg \\<phi>) I \\<psi>\"\n\ndefinition (in msaux) wf_since_aux :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> event_data list set \\<Rightarrow> args \\<Rightarrow>\n  Formula.formula \\<Rightarrow> Formula.formula \\<Rightarrow> 'msaux \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"wf_since_aux \\<sigma> V R args \\<phi> \\<psi> aux ne \\<longleftrightarrow> Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi> \\<and> (\\<exists>cur auxlist. valid_msaux args cur aux auxlist \\<and>\n    cur = (if ne = 0 then 0 else \\<tau> \\<sigma> (ne - 1)) \\<and>\n    sorted_wrt (\\<lambda>x y. fst x > fst y) auxlist \\<and>\n    (\\<forall>t X. (t, X) \\<in> set auxlist \\<longrightarrow> ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne - 1) \\<and> \\<tau> \\<sigma> (ne - 1) - t \\<le> right (args_ivl args) \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      qtable (args_n args) (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne-1) (Sincep (args_pos args) \\<phi> (point (\\<tau> \\<sigma> (ne - 1) - t)) \\<psi>)) X) \\<and>\n    (\\<forall>t. ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne - 1) \\<and> \\<tau> \\<sigma> (ne - 1) - t \\<le> right (args_ivl args) \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<longrightarrow>\n      (\\<exists>X. (t, X) \\<in> set auxlist)))\"\n\ndefinition wf_matchP_aux :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> event_data list set \\<Rightarrow>\n    \\<I> \\<Rightarrow> Formula.formula Regex.regex \\<Rightarrow> event_data mr\\<delta>aux \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"wf_matchP_aux \\<sigma> V n R I r aux ne \\<longleftrightarrow> sorted_wrt (\\<lambda>x y. fst x > fst y) aux \\<and>\n    (\\<forall>t X. (t, X) \\<in> set aux \\<longrightarrow> ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne-1) \\<and> \\<tau> \\<sigma> (ne-1) - t \\<le> right I \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      (case to_mregex r of (mr, \\<phi>s) \\<Rightarrow>\n      (\\<forall>ms \\<in> RPDs mr. qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne-1)\n         (Formula.MatchP (point (\\<tau> \\<sigma> (ne-1) - t)) (from_mregex ms \\<phi>s)))\n         (lookup X ms)))) \\<and>\n    (\\<forall>t. ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne-1) \\<and> \\<tau> \\<sigma> (ne-1) - t \\<le> right I \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<longrightarrow>\n      (\\<exists>X. (t, X) \\<in> set aux))\"\n\nlemma qtable_mem_restr_UNIV: \"qtable n A(mem_restr UNIV) Q X = wf_table n A Q X\"\n  unfolding qtable_def by auto\n\nlemma (in msaux) wf_since_aux_UNIV_alt:\n  \"wf_since_aux \\<sigma> V UNIV args \\<phi> \\<psi> aux ne \\<longleftrightarrow> Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi> \\<and> (\\<exists>cur auxlist. valid_msaux args cur aux auxlist \\<and>\n    cur = (if ne = 0 then 0 else \\<tau> \\<sigma> (ne - 1)) \\<and>\n    sorted_wrt (\\<lambda>x y. fst x > fst y) auxlist \\<and>\n    (\\<forall>t X. (t, X) \\<in> set auxlist \\<longrightarrow> ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne - 1) \\<and> \\<tau> \\<sigma> (ne - 1) - t \\<le> right (args_ivl args) \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      wf_table (args_n args) (Formula.fv \\<psi>)\n          (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne - 1) (Sincep (args_pos args) \\<phi> (point (\\<tau> \\<sigma> (ne - 1) - t)) \\<psi>)) X) \\<and>\n    (\\<forall>t. ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne - 1) \\<and> \\<tau> \\<sigma> (ne - 1) - t \\<le> right (args_ivl args) \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<longrightarrow>\n      (\\<exists>X. (t, X) \\<in> set auxlist)))\"\n  unfolding wf_since_aux_def qtable_mem_restr_UNIV ..\n\ndefinition wf_until_auxlist :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> event_data list set \\<Rightarrow> bool \\<Rightarrow>\n    Formula.formula \\<Rightarrow> \\<I> \\<Rightarrow> Formula.formula \\<Rightarrow> event_data muaux \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> auxlist ne \\<longleftrightarrow>\n    list_all2 (\\<lambda>x i. case x of (t, r1, r2) \\<Rightarrow> t = \\<tau> \\<sigma> i \\<and>\n      qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. if pos then (\\<forall>k\\<in>{i..<ne+length auxlist}. Formula.sat \\<sigma> V (map the v) k \\<phi>)\n          else (\\<exists>k\\<in>{i..<ne+length auxlist}. Formula.sat \\<sigma> V (map the v) k \\<phi>)) r1 \\<and>\n      qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. (\\<exists>j. i \\<le> j \\<and> j < ne + length auxlist \\<and> mem (\\<tau> \\<sigma> j - \\<tau> \\<sigma> i) I \\<and>\n          Formula.sat \\<sigma> V (map the v) j \\<psi> \\<and>\n          (\\<forall>k\\<in>{i..<j}. if pos then Formula.sat \\<sigma> V (map the v) k \\<phi> else \\<not> Formula.sat \\<sigma> V (map the v) k \\<phi>))) r2)\n      auxlist [ne..<ne+length auxlist]\"\n\ndefinition (in muaux) wf_until_aux :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> event_data list set \\<Rightarrow> args \\<Rightarrow>\n  Formula.formula \\<Rightarrow> Formula.formula \\<Rightarrow> 'muaux \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"wf_until_aux \\<sigma> V R args \\<phi> \\<psi> aux ne \\<longleftrightarrow> Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi> \\<and>\n    (\\<exists>cur auxlist. valid_muaux args cur aux auxlist \\<and>\n      cur = (if ne + length auxlist = 0 then 0 else \\<tau> \\<sigma> (ne + length auxlist - 1)) \\<and>\n      wf_until_auxlist \\<sigma> V (args_n args) R (args_pos args) \\<phi> (args_ivl args) \\<psi> auxlist ne)\"\n\nlemma (in muaux) wf_until_aux_UNIV_alt:\n  \"wf_until_aux \\<sigma> V UNIV args \\<phi> \\<psi> aux ne \\<longleftrightarrow> Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi> \\<and>\n    (\\<exists>cur auxlist. valid_muaux args cur aux auxlist \\<and>\n      cur = (if ne + length auxlist = 0 then 0 else \\<tau> \\<sigma> (ne + length auxlist - 1)) \\<and>\n      list_all2 (\\<lambda>x i. case x of (t, r1, r2) \\<Rightarrow> t = \\<tau> \\<sigma> i \\<and>\n      wf_table (args_n args) (Formula.fv \\<phi>) (\\<lambda>v. if (args_pos args)\n          then (\\<forall>k\\<in>{i..<ne+length auxlist}. Formula.sat \\<sigma> V (map the v) k \\<phi>)\n          else (\\<exists>k\\<in>{i..<ne+length auxlist}. Formula.sat \\<sigma> V (map the v) k \\<phi>)) r1 \\<and>\n      wf_table (args_n args) (Formula.fv \\<psi>) (\\<lambda>v. \\<exists>j. i \\<le> j \\<and> j < ne + length auxlist \\<and> mem (\\<tau> \\<sigma> j - \\<tau> \\<sigma> i) (args_ivl args) \\<and>\n          Formula.sat \\<sigma> V (map the v) j \\<psi> \\<and>\n          (\\<forall>k\\<in>{i..<j}. if (args_pos args) then Formula.sat \\<sigma> V (map the v) k \\<phi> else \\<not> Formula.sat \\<sigma> V (map the v) k \\<phi>)) r2)\n      auxlist [ne..<ne+length auxlist])\"\n  unfolding wf_until_aux_def wf_until_auxlist_def qtable_mem_restr_UNIV ..\n\ndefinition wf_matchF_aux :: \"Formula.trace \\<Rightarrow> _ \\<Rightarrow> nat \\<Rightarrow> event_data list set \\<Rightarrow>\n    \\<I> \\<Rightarrow> Formula.formula Regex.regex \\<Rightarrow> event_data ml\\<delta>aux \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> bool\" where\n  \"wf_matchF_aux \\<sigma> V n R I r aux ne k \\<longleftrightarrow> (case to_mregex r of (mr, \\<phi>s) \\<Rightarrow>\n      list_all2 (\\<lambda>x i. case x of (t, rels, rel) \\<Rightarrow> t = \\<tau> \\<sigma> i \\<and>\n        list_all2 (\\<lambda>\\<phi>. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v.\n          Formula.sat \\<sigma> V (map the v) i \\<phi>)) \\<phi>s rels \\<and>\n        qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v. (\\<exists>j. i \\<le> j \\<and> j < ne + length aux + k \\<and> mem (\\<tau> \\<sigma> j - \\<tau> \\<sigma> i) I \\<and>\n          Regex.match (Formula.sat \\<sigma> V (map the v)) r i j)) rel)\n    aux [ne..<ne+length aux])\"\n\ndefinition wf_matchF_invar where\n  \"wf_matchF_invar \\<sigma> V n R I r st i =\n     (case st of (aux, Y) \\<Rightarrow> aux \\<noteq> [] \\<and> wf_matchF_aux \\<sigma> V n R I r aux i 0 \\<and>\n     (case to_mregex r of (mr, \\<phi>s) \\<Rightarrow> \\<forall>ms \\<in> LPDs mr.\n       qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v.\n         Regex.match (Formula.sat \\<sigma> V (map the v)) (from_mregex ms \\<phi>s) i (i + length aux - 1)) (lookup Y ms)))\"\n\ndefinition lift_envs' :: \"nat \\<Rightarrow> event_data list set \\<Rightarrow> event_data list set\" where\n  \"lift_envs' b R = (\\<lambda>(xs,ys). xs @ ys) ` ({xs. length xs = b} \\<times> R)\"\n\nfun formula_of_constraint :: \"Formula.trm \\<times> bool \\<times> mconstraint \\<times> Formula.trm \\<Rightarrow> Formula.formula\" where\n  \"formula_of_constraint (t1, True, MEq, t2) = Formula.Eq t1 t2\"\n| \"formula_of_constraint (t1, True, MLess, t2) = Formula.Less t1 t2\"\n| \"formula_of_constraint (t1, True, MLessEq, t2) = Formula.LessEq t1 t2\"\n| \"formula_of_constraint (t1, False, MEq, t2) = Formula.Neg (Formula.Eq t1 t2)\"\n| \"formula_of_constraint (t1, False, MLess, t2) = Formula.Neg (Formula.Less t1 t2)\"\n| \"formula_of_constraint (t1, False, MLessEq, t2) = Formula.Neg (Formula.LessEq t1 t2)\"\n\ninductive (in maux) wf_mformula :: \"Formula.trace \\<Rightarrow> nat \\<Rightarrow> _ \\<Rightarrow> _ \\<Rightarrow>\n  nat \\<Rightarrow> event_data list set \\<Rightarrow> ('msaux, 'muaux) mformula \\<Rightarrow> Formula.formula \\<Rightarrow> bool\"\n  for \\<sigma> j where\n    Eq: \"is_simple_eq t1 t2 \\<Longrightarrow>\n    \\<forall>x\\<in>Formula.fv_trm t1. x < n \\<Longrightarrow> \\<forall>x\\<in>Formula.fv_trm t2. x < n \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MRel (eq_rel n t1 t2)) (Formula.Eq t1 t2)\"\n  | neq_Var: \"x < n \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MRel empty_table) (Formula.Neg (Formula.Eq (Formula.Var x) (Formula.Var x)))\"\n  | Pred: \"\\<forall>x\\<in>Formula.fv (Formula.Pred e ts). x < n \\<Longrightarrow>\n    \\<forall>t\\<in>set ts. Formula.is_Var t \\<or> Formula.is_Const t \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MPred e ts) (Formula.Pred e ts)\"\n  | Let: \"wf_mformula \\<sigma> j P V m UNIV \\<phi> \\<phi>' \\<Longrightarrow>\n    wf_mformula \\<sigma> j (P(p \\<mapsto> progress \\<sigma> P \\<phi>' j))\n      (V(p \\<mapsto> \\<lambda>i. {v. length v = m \\<and> Formula.sat \\<sigma> V v i \\<phi>'})) n R \\<psi> \\<psi>' \\<Longrightarrow>\n    {0..<m} \\<subseteq> Formula.fv \\<phi>' \\<Longrightarrow> b \\<le> m \\<Longrightarrow> m = Formula.nfv \\<phi>' \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MLet p m \\<phi> \\<psi>) (Formula.Let p \\<phi>' \\<psi>')\"\n  | And: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow> wf_mformula \\<sigma> j P V n R \\<psi> \\<psi>' \\<Longrightarrow>\n    if pos then \\<chi> = Formula.And \\<phi>' \\<psi>'\n      else \\<chi> = Formula.And \\<phi>' (Formula.Neg \\<psi>') \\<and> Formula.fv \\<psi>' \\<subseteq> Formula.fv \\<phi>' \\<Longrightarrow>\n    wf_mbuf2' \\<sigma> P V j n R \\<phi>' \\<psi>' buf \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MAnd (fv \\<phi>') \\<phi> pos (fv \\<psi>') \\<psi> buf) \\<chi>\"\n  | AndAssign: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow>\n    x < n \\<Longrightarrow> x \\<notin> Formula.fv \\<phi>' \\<Longrightarrow> Formula.fv_trm t \\<subseteq> Formula.fv \\<phi>' \\<Longrightarrow> (x, t) = conf \\<Longrightarrow>\n    \\<psi>' = Formula.Eq (Formula.Var x) t \\<or> \\<psi>' = Formula.Eq t (Formula.Var x) \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MAndAssign \\<phi> conf) (Formula.And \\<phi>' \\<psi>')\"\n  | AndRel: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow>\n    \\<psi>' = formula_of_constraint conf \\<Longrightarrow>\n    (let (t1, _, _, t2) = conf in Formula.fv_trm t1 \\<union> Formula.fv_trm t2 \\<subseteq> Formula.fv \\<phi>') \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MAndRel \\<phi> conf) (Formula.And \\<phi>' \\<psi>')\"\n  | Ands: \"list_all2 (\\<lambda>\\<phi> \\<phi>'. wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>') l (l_pos @ map remove_neg l_neg) \\<Longrightarrow>\n    wf_mbufn (progress \\<sigma> P (Formula.Ands l') j) (map (\\<lambda>\\<psi>. progress \\<sigma> P \\<psi> j) (l_pos @ map remove_neg l_neg)) (map (\\<lambda>\\<psi> i.\n      qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>)) (l_pos @ map remove_neg l_neg)) buf \\<Longrightarrow>\n    (l_pos, l_neg) = partition safe_formula l' \\<Longrightarrow>\n    l_pos \\<noteq> [] \\<Longrightarrow>\n    list_all safe_formula (map remove_neg l_neg) \\<Longrightarrow>\n    A_pos = map fv l_pos \\<Longrightarrow>\n    A_neg = map fv l_neg \\<Longrightarrow>\n    \\<Union>(set A_neg) \\<subseteq> \\<Union>(set A_pos) \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MAnds A_pos A_neg l buf) (Formula.Ands l')\"\n  | Or: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow> wf_mformula \\<sigma> j P V n R \\<psi> \\<psi>' \\<Longrightarrow>\n    Formula.fv \\<phi>' = Formula.fv \\<psi>' \\<Longrightarrow>\n    wf_mbuf2' \\<sigma> P V j n R \\<phi>' \\<psi>' buf \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MOr \\<phi> \\<psi> buf) (Formula.Or \\<phi>' \\<psi>')\"\n  | Neg: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow> Formula.fv \\<phi>' = {} \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MNeg \\<phi>) (Formula.Neg \\<phi>')\"\n  | Exists: \"wf_mformula \\<sigma> j P V (Suc n) (lift_envs R) \\<phi> \\<phi>' \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MExists \\<phi>) (Formula.Exists \\<phi>')\"\n  | Agg: \"wf_mformula \\<sigma> j P V (b + n) (lift_envs' b R) \\<phi> \\<phi>' \\<Longrightarrow>\n    y < n \\<Longrightarrow>\n    y + b \\<notin> Formula.fv \\<phi>' \\<Longrightarrow>\n    {0..<b} \\<subseteq> Formula.fv \\<phi>' \\<Longrightarrow>\n    Formula.fv_trm f \\<subseteq> Formula.fv \\<phi>' \\<Longrightarrow>\n    g0 = (Formula.fv \\<phi>' \\<subseteq> {0..<b}) \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MAgg g0 y \\<omega> b f \\<phi>) (Formula.Agg y \\<omega> b f \\<phi>')\"\n  | Prev: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow>\n    first \\<longleftrightarrow> j = 0 \\<Longrightarrow>\n    list_all2 (\\<lambda>i. qtable n (Formula.fv \\<phi>') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>'))\n      [min (progress \\<sigma> P \\<phi>' j) (j-1)..<progress \\<sigma> P \\<phi>' j] buf \\<Longrightarrow>\n    list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [min (progress \\<sigma> P \\<phi>' j) (j-1)..<j] nts \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MPrev I \\<phi> first buf nts) (Formula.Prev I \\<phi>')\"\n  | Next: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow>\n    first \\<longleftrightarrow> progress \\<sigma> P \\<phi>' j = 0 \\<Longrightarrow>\n    list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [progress \\<sigma> P \\<phi>' j - 1..<j] nts \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MNext I \\<phi> first nts) (Formula.Next I \\<phi>')\"\n  | Since: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow> wf_mformula \\<sigma> j P V n R \\<psi> \\<psi>' \\<Longrightarrow>\n    if args_pos args then \\<phi>'' = \\<phi>' else \\<phi>'' = Formula.Neg \\<phi>' \\<Longrightarrow>\n    safe_formula \\<phi>'' = args_pos args \\<Longrightarrow>\n    args_ivl args = I \\<Longrightarrow>\n    args_n args = n \\<Longrightarrow>\n    args_L args = Formula.fv \\<phi>' \\<Longrightarrow>\n    args_R args = Formula.fv \\<psi>' \\<Longrightarrow>\n    Formula.fv \\<phi>' \\<subseteq> Formula.fv \\<psi>' \\<Longrightarrow>\n    wf_mbuf2' \\<sigma> P V j n R \\<phi>' \\<psi>' buf \\<Longrightarrow>\n    wf_ts \\<sigma> P j \\<phi>' \\<psi>' nts \\<Longrightarrow>\n    wf_since_aux \\<sigma> V R args \\<phi>' \\<psi>' aux (progress \\<sigma> P (Formula.Since \\<phi>'' I \\<psi>') j) \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MSince args \\<phi> \\<psi> buf nts aux) (Formula.Since \\<phi>'' I \\<psi>')\"\n  | Until: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow> wf_mformula \\<sigma> j P V n R \\<psi> \\<psi>' \\<Longrightarrow>\n    if args_pos args then \\<phi>'' = \\<phi>' else \\<phi>'' = Formula.Neg \\<phi>' \\<Longrightarrow>\n    safe_formula \\<phi>'' = args_pos args \\<Longrightarrow>\n    args_ivl args = I \\<Longrightarrow>\n    args_n args = n \\<Longrightarrow>\n    args_L args = Formula.fv \\<phi>' \\<Longrightarrow>\n    args_R args = Formula.fv \\<psi>' \\<Longrightarrow>\n    Formula.fv \\<phi>' \\<subseteq> Formula.fv \\<psi>' \\<Longrightarrow>\n    wf_mbuf2' \\<sigma> P V j n R \\<phi>' \\<psi>' buf \\<Longrightarrow>\n    wf_ts \\<sigma> P j \\<phi>' \\<psi>' nts \\<Longrightarrow>\n    wf_until_aux \\<sigma> V R args \\<phi>' \\<psi>' aux (progress \\<sigma> P (Formula.Until \\<phi>'' I \\<psi>') j) \\<Longrightarrow>\n    progress \\<sigma> P (Formula.Until \\<phi>'' I \\<psi>') j + length_muaux args aux = min (progress \\<sigma> P \\<phi>' j) (progress \\<sigma> P \\<psi>' j) \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MUntil args \\<phi> \\<psi> buf nts aux) (Formula.Until \\<phi>'' I \\<psi>')\"\n  | MatchP: \"(case to_mregex r of (mr', \\<phi>s') \\<Rightarrow>\n      list_all2 (wf_mformula \\<sigma> j P V n R) \\<phi>s \\<phi>s' \\<and> mr = mr') \\<Longrightarrow>\n    mrs = sorted_list_of_set (RPDs mr) \\<Longrightarrow>\n    safe_regex Past Strict r \\<Longrightarrow>\n    wf_mbufn' \\<sigma> P V j n R r buf \\<Longrightarrow>\n    wf_ts_regex \\<sigma> P j r nts \\<Longrightarrow>\n    wf_matchP_aux \\<sigma> V n R I r aux (progress \\<sigma> P (Formula.MatchP I r) j) \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MMatchP I mr mrs \\<phi>s buf nts aux) (Formula.MatchP I r)\"\n  | MatchF: \"(case to_mregex r of (mr', \\<phi>s') \\<Rightarrow>\n      list_all2 (wf_mformula \\<sigma> j P V n R) \\<phi>s \\<phi>s' \\<and> mr = mr') \\<Longrightarrow>\n    mrs = sorted_list_of_set (LPDs mr) \\<Longrightarrow>\n    safe_regex Futu Strict r \\<Longrightarrow>\n    wf_mbufn' \\<sigma> P V j n R r buf \\<Longrightarrow>\n    wf_ts_regex \\<sigma> P j r nts \\<Longrightarrow>\n    wf_matchF_aux \\<sigma> V n R I r aux (progress \\<sigma> P (Formula.MatchF I r) j) 0 \\<Longrightarrow>\n    progress \\<sigma> P (Formula.MatchF I r) j + length aux = progress_regex \\<sigma> P r j \\<Longrightarrow>\n    wf_mformula \\<sigma> j P V n R (MMatchF I mr mrs \\<phi>s buf nts aux) (Formula.MatchF I r)\"\n\ndefinition (in maux) wf_mstate :: \"Formula.formula \\<Rightarrow> Formula.prefix \\<Rightarrow> event_data list set \\<Rightarrow> ('msaux, 'muaux) mstate \\<Rightarrow> bool\" where\n  \"wf_mstate \\<phi> \\<pi> R st \\<longleftrightarrow> mstate_n st = Formula.nfv \\<phi> \\<and> (\\<forall>\\<sigma>. prefix_of \\<pi> \\<sigma> \\<longrightarrow>\n    mstate_i st = progress \\<sigma> Map.empty \\<phi> (plen \\<pi>) \\<and>\n    wf_mformula \\<sigma> (plen \\<pi>) Map.empty Map.empty (mstate_n st) R (mstate_m st) \\<phi>)\"\n\n\nsubsubsection \\<open>Initialisation\\<close>\n\n\nlemma wf_mbuf2'_0: \"pred_mapping (\\<lambda>x. x = 0) P \\<Longrightarrow> wf_mbuf2' \\<sigma> P V 0 n R \\<phi> \\<psi> ([], [])\"\n  unfolding wf_mbuf2'_def wf_mbuf2_def by simp\n\nlemma wf_mbufn'_0: \"to_mregex r = (mr, \\<phi>s) \\<Longrightarrow> pred_mapping (\\<lambda>x. x = 0) P \\<Longrightarrow> wf_mbufn' \\<sigma> P V 0 n R r (replicate (length \\<phi>s) [])\"\n  unfolding wf_mbufn'_def wf_mbufn_def map_replicate_const[symmetric]\n  by (auto simp: list_all3_map intro: list_all3_refl simp: Min_eq_iff progress_regex_def)\n\nlemma wf_ts_0: \"wf_ts \\<sigma> P 0 \\<phi> \\<psi> []\"\n  unfolding wf_ts_def by simp\n\nlemma wf_ts_regex_0: \"wf_ts_regex \\<sigma> P 0 r []\"\n  unfolding wf_ts_regex_def by simp\n\nlemma (in msaux) wf_since_aux_Nil: \"Formula.fv \\<phi>' \\<subseteq> Formula.fv \\<psi>' \\<Longrightarrow>\n  wf_since_aux \\<sigma> V R (init_args I n (Formula.fv \\<phi>') (Formula.fv \\<psi>') b) \\<phi>' \\<psi>' (init_msaux (init_args I n (Formula.fv \\<phi>') (Formula.fv \\<psi>') b)) 0\"\n  unfolding wf_since_aux_def by (auto intro!: valid_init_msaux)\n\nlemma (in muaux) wf_until_aux_Nil: \"Formula.fv \\<phi>' \\<subseteq> Formula.fv \\<psi>' \\<Longrightarrow>\n  wf_until_aux \\<sigma> V R (init_args I n (Formula.fv \\<phi>') (Formula.fv \\<psi>') b) \\<phi>' \\<psi>' (init_muaux (init_args I n (Formula.fv \\<phi>') (Formula.fv \\<psi>') b)) 0\"\n  unfolding wf_until_aux_def wf_until_auxlist_def by (auto intro: valid_init_muaux)\n\nlemma wf_matchP_aux_Nil: \"wf_matchP_aux \\<sigma> V n R I r [] 0\"\n  unfolding wf_matchP_aux_def by simp\n\nlemma wf_matchF_aux_Nil: \"wf_matchF_aux \\<sigma> V n R I r [] 0 k\"\n  unfolding wf_matchF_aux_def by simp\n\nlemma fv_regex_alt: \"safe_regex m g r \\<Longrightarrow> Formula.fv_regex r = (\\<Union>\\<phi> \\<in> atms r. Formula.fv \\<phi>)\"\n  unfolding fv_regex_alt atms_def\n  by (auto 0 3 dest: safe_regex_safe_formula)\n\nlemmas to_mregex_atms =\n  to_mregex_ok[THEN conjunct1, THEN equalityD1, THEN set_mp, rotated]\n\nlemma (in maux) wf_minit0: \"safe_formula \\<phi> \\<Longrightarrow> \\<forall>x\\<in>Formula.fv \\<phi>. x < n \\<Longrightarrow>\n  pred_mapping (\\<lambda>x. x = 0) P \\<Longrightarrow>\n  wf_mformula \\<sigma> 0 P V n R (minit0 n \\<phi>) \\<phi>\"\nproof (induction arbitrary: n R P V rule: safe_formula_induct)\n  case (Eq_Const c d)\n  then show ?case\n    by (auto simp add: is_simple_eq_def simp del: eq_rel.simps intro!: wf_mformula.Eq)\nnext\n  case (Eq_Var1 c x)\n  then show ?case\n    by (auto simp add: is_simple_eq_def simp del: eq_rel.simps intro!: wf_mformula.Eq)\nnext\n  case (Eq_Var2 c x)\n  then show ?case\n    by (auto simp add: is_simple_eq_def simp del: eq_rel.simps intro!: wf_mformula.Eq)\nnext\n  case (neq_Var x y)\n  then show ?case by (auto intro!: wf_mformula.neq_Var)\nnext\n  case (Pred e ts)\n  then show ?case by (auto intro!: wf_mformula.Pred)\nnext\n  case (Let p \\<phi> \\<psi>)\n  with fvi_less_nfv show ?case\n    by (auto simp: pred_mapping_alt dom_def intro!: wf_mformula.Let Let(4,5))\nnext\n  case (And_assign \\<phi> \\<psi>)\n  then have 1: \"\\<forall>x\\<in>fv \\<psi>. x < n\" by simp\n  from 1 \\<open>safe_assignment (fv \\<phi>) \\<psi>\\<close>\n  obtain x t where\n    \"x < n\" \"x \\<notin> fv \\<phi>\" \"fv_trm t \\<subseteq> fv \\<phi>\"\n    \"\\<psi> = Formula.Eq (Formula.Var x) t \\<or> \\<psi> = Formula.Eq t (Formula.Var x)\"\n    unfolding safe_assignment_def by (force split: formula.splits trm.splits)\n  with And_assign show ?case\n    by (auto intro!: wf_mformula.AndAssign split: trm.splits)\nnext\n  case (And_safe \\<phi> \\<psi>)\n  then show ?case by (auto intro!: wf_mformula.And wf_mbuf2'_0)\nnext\n  case (And_constraint \\<phi> \\<psi>)\n  from \\<open>fv \\<psi> \\<subseteq> fv \\<phi>\\<close> \\<open>is_constraint \\<psi>\\<close>\n  obtain t1 p c t2 where\n    \"(t1, p, c, t2) = split_constraint \\<psi>\"\n    \"formula_of_constraint (split_constraint \\<psi>) = \\<psi>\"\n    \"fv_trm t1 \\<union> fv_trm t2 \\<subseteq> fv \\<phi>\"\n    by (induction rule: is_constraint.induct) auto\n  with And_constraint show ?case\n    by (auto 0 3 intro!: wf_mformula.AndRel)\nnext\n  case (And_Not \\<phi> \\<psi>)\n  then show ?case by (auto intro!: wf_mformula.And wf_mbuf2'_0)\nnext\n  case (Ands l pos neg)\n  note posneg = \"Ands.hyps\"(1)\n  let ?wf_minit = \"\\<lambda>x. wf_mformula \\<sigma> 0 P V n R (minit0 n x)\"\n  let ?pos = \"filter safe_formula l\"\n  let ?neg = \"filter (Not \\<circ> safe_formula) l\"\n  have \"list_all2 ?wf_minit ?pos pos\"\n    using Ands.IH(1) Ands.prems posneg by (auto simp: list_all_iff intro!: list.rel_refl_strong)\n  moreover have \"list_all2 ?wf_minit (map remove_neg ?neg) (map remove_neg neg)\"\n    using Ands.IH(2) Ands.prems posneg by (auto simp: list.rel_map list_all_iff intro!: list.rel_refl_strong)\n  moreover have \"list_all3 (\\<lambda>_ _ _. True) (?pos @ map remove_neg ?neg) (?pos @ map remove_neg ?neg) l\"\n    by (auto simp: list_all3_conv_all_nth comp_def sum_length_filter_compl)\n  moreover have \"l \\<noteq> [] \\<Longrightarrow> (MIN \\<phi>\\<in>set l. (0 :: nat)) = 0\"\n    by (cases l) (auto simp: Min_eq_iff)\n  ultimately show ?case using Ands.hyps Ands.prems(2)\n    by (auto simp: wf_mbufn_def list_all3_map list.rel_map map_replicate_const[symmetric] subset_eq\n        map_map[symmetric] map_append[symmetric] simp del: map_map map_append\n        intro!: wf_mformula.Ands list_all2_appendI)\nnext\n  case (Neg \\<phi>)\n  then show ?case by (auto intro!: wf_mformula.Neg)\nnext\n  case (Or \\<phi> \\<psi>)\n  then show ?case by (auto intro!: wf_mformula.Or wf_mbuf2'_0)\nnext\n  case (Exists \\<phi>)\n  then show ?case by (auto simp: fvi_Suc_bound intro!: wf_mformula.Exists)\nnext\n  case (Agg y \\<omega> b f \\<phi>)\n  then show ?case by (auto intro!: wf_mformula.Agg Agg.IH fvi_plus_bound)\nnext\n  case (Prev I \\<phi>)\n  thm wf_mformula.Prev[where P=P]\n  then show ?case by (auto intro!: wf_mformula.Prev)\nnext\n  case (Next I \\<phi>)\n  then show ?case by (auto intro!: wf_mformula.Next)\nnext\n  case (Since \\<phi> I \\<psi>)\n  then show ?case\n    using wf_since_aux_Nil\n    by (auto simp add: init_args_def intro!: wf_mformula.Since wf_mbuf2'_0 wf_ts_0)\nnext\n  case (Not_Since \\<phi> I \\<psi>)\n  then show ?case\n    using wf_since_aux_Nil\n    by (auto simp add: init_args_def intro!: wf_mformula.Since wf_mbuf2'_0 wf_ts_0)\nnext\n  case (Until \\<phi> I \\<psi>)\n  then show ?case\n    using valid_length_muaux[OF valid_init_muaux[OF Until(1)]] wf_until_aux_Nil\n    by (auto simp add: init_args_def simp del: progress_simps intro!: wf_mformula.Until wf_mbuf2'_0 wf_ts_0)\nnext\n  case (Not_Until \\<phi> I \\<psi>)\n  then show ?case\n    using valid_length_muaux[OF valid_init_muaux[OF Not_Until(1)]] wf_until_aux_Nil\n    by (auto simp add: init_args_def simp del: progress_simps intro!: wf_mformula.Until wf_mbuf2'_0 wf_ts_0)\nnext\n  case (MatchP I r)\n  then show ?case\n    by (auto simp: list.rel_map fv_regex_alt simp del: progress_simps split: prod.split\n        intro!: wf_mformula.MatchP list.rel_refl_strong wf_mbufn'_0 wf_ts_regex_0 wf_matchP_aux_Nil\n        dest!: to_mregex_atms)\nnext\n  case (MatchF I r)\n  then show ?case\n    by (auto simp: list.rel_map fv_regex_alt progress_le Min_eq_iff progress_regex_def\n        simp del: progress_simps split: prod.split\n        intro!: wf_mformula.MatchF list.rel_refl_strong wf_mbufn'_0 wf_ts_regex_0 wf_matchF_aux_Nil\n        dest!: to_mregex_atms)\nqed\n\nlemma (in maux) wf_mstate_minit: \"safe_formula \\<phi> \\<Longrightarrow> wf_mstate \\<phi> pnil R (minit \\<phi>)\"\n  unfolding wf_mstate_def minit_def Let_def\n  by (auto intro!: wf_minit0 fvi_less_nfv)\n\n\nsubsubsection \\<open>Evaluation\\<close>\n\nlemma match_wf_tuple: \"Some f = match ts xs \\<Longrightarrow>\n  wf_tuple n (\\<Union>t\\<in>set ts. Formula.fv_trm t) (Table.tabulate f 0 n)\"\n  by (induction ts xs arbitrary: f rule: match.induct)\n    (fastforce simp: wf_tuple_def split: if_splits option.splits)+\n\nlemma match_fvi_trm_None: \"Some f = match ts xs \\<Longrightarrow> \\<forall>t\\<in>set ts. x \\<notin> Formula.fv_trm t \\<Longrightarrow> f x = None\"\n  by (induction ts xs arbitrary: f rule: match.induct) (auto split: if_splits option.splits)\n\nlemma match_fvi_trm_Some: \"Some f = match ts xs \\<Longrightarrow> t \\<in> set ts \\<Longrightarrow> x \\<in> Formula.fv_trm t \\<Longrightarrow> f x \\<noteq> None\"\n  by (induction ts xs arbitrary: f rule: match.induct) (auto split: if_splits option.splits)\n\nlemma match_eval_trm: \"\\<forall>t\\<in>set ts. \\<forall>i\\<in>Formula.fv_trm t. i < n \\<Longrightarrow> Some f = match ts xs \\<Longrightarrow>\n    map (Formula.eval_trm (Table.tabulate (\\<lambda>i. the (f i)) 0 n)) ts = xs\"\nproof (induction ts xs arbitrary: f rule: match.induct)\n  case (3 x ts y ys)\n  from 3(1)[symmetric] 3(2,3) show ?case\n    by (auto 0 3 dest: match_fvi_trm_Some sym split: option.splits if_splits intro!: eval_trm_fv_cong)\nqed (auto split: if_splits)\n\nlemma wf_tuple_tabulate_Some: \"wf_tuple n A (Table.tabulate f 0 n) \\<Longrightarrow> x \\<in> A \\<Longrightarrow> x < n \\<Longrightarrow> \\<exists>y. f x = Some y\"\n  unfolding wf_tuple_def by auto\n\nlemma ex_match: \"wf_tuple n (\\<Union>t\\<in>set ts. Formula.fv_trm t) v \\<Longrightarrow>\n  \\<forall>t\\<in>set ts. (\\<forall>x\\<in>Formula.fv_trm t. x < n) \\<and> (Formula.is_Var t \\<or> Formula.is_Const t) \\<Longrightarrow>\n  \\<exists>f. match ts (map (Formula.eval_trm (map the v)) ts) = Some f \\<and> v = Table.tabulate f 0 n\"\nproof (induction ts \"map (Formula.eval_trm (map the v)) ts\" arbitrary: v rule: match.induct)\n  case (3 x ts y ys)\n  then show ?case\n  proof (cases \"x \\<in> (\\<Union>t\\<in>set ts. Formula.fv_trm t)\")\n    case True\n    with 3 show ?thesis\n      by (auto simp: insert_absorb dest!: wf_tuple_tabulate_Some meta_spec[of _ v])\n  next\n    case False\n    with 3(3,4) have\n      *: \"map (Formula.eval_trm (map the v)) ts = map (Formula.eval_trm (map the (v[x := None]))) ts\"\n      by (auto simp: wf_tuple_def nth_list_update intro!: eval_trm_fv_cong)\n    from False 3(2-4) obtain f where\n      \"match ts (map (Formula.eval_trm (map the v)) ts) = Some f\" \"v[x := None] = Table.tabulate f 0 n\"\n      unfolding *\n      by (atomize_elim, intro 3(1)[of \"v[x := None]\"])\n        (auto simp: wf_tuple_def nth_list_update intro!: eval_trm_fv_cong)\n    moreover from False this have \"f x = None\" \"length v = n\"\n      by (auto dest: match_fvi_trm_None[OF sym] arg_cong[of _ _ length])\n    ultimately show ?thesis using 3(3)\n      by (auto simp: list_eq_iff_nth_eq wf_tuple_def)\n  qed\nqed (auto simp: wf_tuple_def intro: nth_equalityI)\n\nlemma eq_rel_eval_trm: \"v \\<in> eq_rel n t1 t2 \\<Longrightarrow> is_simple_eq t1 t2 \\<Longrightarrow>\n  \\<forall>x\\<in>Formula.fv_trm t1 \\<union> Formula.fv_trm t2. x < n \\<Longrightarrow>\n  Formula.eval_trm (map the v) t1 = Formula.eval_trm (map the v) t2\"\n  by (cases t1; cases t2) (simp_all add: is_simple_eq_def singleton_table_def split: if_splits)\n\nlemma in_eq_rel: \"wf_tuple n (Formula.fv_trm t1 \\<union> Formula.fv_trm t2) v \\<Longrightarrow>\n  is_simple_eq t1 t2 \\<Longrightarrow>\n  Formula.eval_trm (map the v) t1 = Formula.eval_trm (map the v) t2 \\<Longrightarrow>\n  v \\<in> eq_rel n t1 t2\"\n  by (cases t1; cases t2)\n    (auto simp: is_simple_eq_def singleton_table_def wf_tuple_def unit_table_def\n      intro!: nth_equalityI split: if_splits)\n\nlemma table_eq_rel: \"is_simple_eq t1 t2 \\<Longrightarrow>\n  table n (Formula.fv_trm t1 \\<union> Formula.fv_trm t2) (eq_rel n t1 t2)\"\n  by (cases t1; cases t2; simp add: is_simple_eq_def)\n\nlemma wf_tuple_Suc_fviD: \"wf_tuple (Suc n) (Formula.fvi b \\<phi>) v \\<Longrightarrow> wf_tuple n (Formula.fvi (Suc b) \\<phi>) (tl v)\"\n  unfolding wf_tuple_def by (simp add: fvi_Suc nth_tl)\n\nlemma table_fvi_tl: \"table (Suc n) (Formula.fvi b \\<phi>) X \\<Longrightarrow> table n (Formula.fvi (Suc b) \\<phi>) (tl ` X)\"\n  unfolding table_def by (auto intro: wf_tuple_Suc_fviD)\n\nlemma wf_tuple_Suc_fvi_SomeI: \"0 \\<in> Formula.fvi b \\<phi> \\<Longrightarrow> wf_tuple n (Formula.fvi (Suc b) \\<phi>) v \\<Longrightarrow>\n  wf_tuple (Suc n) (Formula.fvi b \\<phi>) (Some x # v)\"\n  unfolding wf_tuple_def\n  by (auto simp: fvi_Suc less_Suc_eq_0_disj)\n\nlemma wf_tuple_Suc_fvi_NoneI: \"0 \\<notin> Formula.fvi b \\<phi> \\<Longrightarrow> wf_tuple n (Formula.fvi (Suc b) \\<phi>) v \\<Longrightarrow>\n  wf_tuple (Suc n) (Formula.fvi b \\<phi>) (None # v)\"\n  unfolding wf_tuple_def\n  by (auto simp: fvi_Suc less_Suc_eq_0_disj)\n\nlemma qtable_project_fv: \"qtable (Suc n) (fv \\<phi>) (mem_restr (lift_envs R)) P X \\<Longrightarrow>\n    qtable n (Formula.fvi (Suc 0) \\<phi>) (mem_restr R)\n      (\\<lambda>v. \\<exists>x. P ((if 0 \\<in> fv \\<phi> then Some x else None) # v)) (tl ` X)\"\n  using neq0_conv by (fastforce simp: image_iff Bex_def fvi_Suc elim!: qtable_cong dest!: qtable_project)\n\nlemma mem_restr_lift_envs'_append[simp]:\n  \"length xs = b \\<Longrightarrow> mem_restr (lift_envs' b R) (xs @ ys) = mem_restr R ys\"\n  unfolding mem_restr_def lift_envs'_def\n  by (auto simp: list_all2_append list.rel_map intro!: exI[where x=\"map the xs\"] list.rel_refl)\n\nlemma nth_list_update_alt: \"xs[i := x] ! j = (if i < length xs \\<and> i = j then x else xs ! j)\"\n  by auto\n\nlemma wf_tuple_upd_None: \"wf_tuple n A xs \\<Longrightarrow> A - {i} = B \\<Longrightarrow> wf_tuple n B (xs[i:=None])\"\n  unfolding wf_tuple_def\n  by (auto simp: nth_list_update_alt)\n\nlemma mem_restr_upd_None: \"mem_restr R xs \\<Longrightarrow> mem_restr R (xs[i:=None])\"\n  unfolding mem_restr_def\n  by (auto simp: list_all2_conv_all_nth nth_list_update_alt)\n\nlemma mem_restr_dropI: \"mem_restr (lift_envs' b R) xs \\<Longrightarrow> mem_restr R (drop b xs)\"\n  unfolding mem_restr_def lift_envs'_def\n  by (auto simp: append_eq_conv_conj list_all2_append2)\n\nlemma mem_restr_dropD:\n  assumes \"b \\<le> length xs\" and \"mem_restr R (drop b xs)\"\n  shows \"mem_restr (lift_envs' b R) xs\"\nproof -\n  let ?R = \"\\<lambda>a b. a \\<noteq> None \\<longrightarrow> a = Some b\"\n  from assms(2) obtain v where \"v \\<in> R\" and \"list_all2 ?R (drop b xs) v\"\n    unfolding mem_restr_def ..\n  show ?thesis unfolding mem_restr_def proof\n    have \"list_all2 ?R (take b xs) (map the (take b xs))\"\n      by (auto simp: list.rel_map intro!: list.rel_refl)\n    moreover note \\<open>list_all2 ?R (drop b xs) v\\<close>\n    ultimately have \"list_all2 ?R (take b xs @ drop b xs) (map the (take b xs) @ v)\"\n      by (rule list_all2_appendI)\n    then show \"list_all2 ?R xs (map the (take b xs) @ v)\" by simp\n    show \"map the (take b xs) @ v \\<in> lift_envs' b R\"\n      unfolding lift_envs'_def using assms(1) \\<open>v \\<in> R\\<close> by auto\n  qed\nqed\n\nlemma wf_tuple_append: \"wf_tuple a {x \\<in> A. x < a} xs \\<Longrightarrow>\n  wf_tuple b {x - a | x. x \\<in> A \\<and> x \\<ge> a} ys \\<Longrightarrow>\n  wf_tuple (a + b) A (xs @ ys)\"\n  unfolding wf_tuple_def by (auto simp: nth_append eq_diff_iff)\n\nlemma wf_tuple_map_Some: \"length xs = n \\<Longrightarrow> {0..<n} \\<subseteq> A \\<Longrightarrow> wf_tuple n A (map Some xs)\"\n  unfolding wf_tuple_def by auto\n\nlemma wf_tuple_drop: \"wf_tuple (b + n) A xs \\<Longrightarrow> {x - b | x. x \\<in> A \\<and> x \\<ge> b} = B \\<Longrightarrow>\n  wf_tuple n B (drop b xs)\"\n  unfolding wf_tuple_def by force\n\nlemma ecard_image: \"inj_on f A \\<Longrightarrow> ecard (f ` A) = ecard A\"\n  unfolding ecard_def by (auto simp: card_image dest: finite_imageD)\n\nlemma meval_trm_eval_trm: \"wf_tuple n A x \\<Longrightarrow> fv_trm t \\<subseteq> A \\<Longrightarrow> \\<forall>i\\<in>A. i < n \\<Longrightarrow>\n    meval_trm t x = Formula.eval_trm (map the x) t\"\n  unfolding wf_tuple_def\n  by (induction t) simp_all\n\nlemma list_update_id: \"xs ! i = z \\<Longrightarrow> xs[i:=z] = xs\"\n  by (induction xs arbitrary: i) (auto split: nat.split)\n\nlemma qtable_wf_tupleD: \"qtable n A P Q X \\<Longrightarrow> \\<forall>x\\<in>X. wf_tuple n A x\"\n  unfolding qtable_def table_def by blast\n\nlemma qtable_eval_agg:\n  assumes inner: \"qtable (b + n) (Formula.fv \\<phi>) (mem_restr (lift_envs' b R))\n      (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>) rel\"\n    and n: \"\\<forall>x\\<in>Formula.fv (Formula.Agg y \\<omega> b f \\<phi>). x < n\"\n    and fresh: \"y + b \\<notin> Formula.fv \\<phi>\"\n    and b_fv: \"{0..<b} \\<subseteq> Formula.fv \\<phi>\"\n    and f_fv: \"Formula.fv_trm f \\<subseteq> Formula.fv \\<phi>\"\n    and g0: \"g0 = (Formula.fv \\<phi> \\<subseteq> {0..<b})\"\n  shows \"qtable n (Formula.fv (Formula.Agg y \\<omega> b f \\<phi>)) (mem_restr R)\n      (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (Formula.Agg y \\<omega> b f \\<phi>)) (eval_agg n g0 y \\<omega> b f rel)\"\n    (is \"qtable _ ?fv _ ?Q ?rel'\")\nproof -\n  define M where \"M = (\\<lambda>v. {(x, ecard Zs) | x Zs.\n      Zs = {zs. length zs = b \\<and> Formula.sat \\<sigma> V (zs @ v) i \\<phi> \\<and> Formula.eval_trm (zs @ v) f = x} \\<and>\n      Zs \\<noteq> {}})\"\n  have f_fvi: \"Formula.fvi_trm b f \\<subseteq> Formula.fvi b \\<phi>\"\n    using f_fv by (auto simp: fvi_trm_iff_fv_trm[where b=b] fvi_iff_fv[where b=b])\n  show ?thesis proof (cases \"g0 \\<and> rel = empty_table\")\n    case True\n    then have [simp]: \"Formula.fvi b \\<phi> = {}\"\n      by (auto simp: g0 fvi_iff_fv(1)[where b=b])\n    then have [simp]: \"Formula.fvi_trm b f = {}\"\n      using f_fvi by auto\n    show ?thesis proof (rule qtableI)\n      show \"table n ?fv ?rel'\" by (simp add: eval_agg_def True)\n    next\n      fix v\n      assume \"wf_tuple n ?fv v\" \"mem_restr R v\"\n      have \"\\<not> Formula.sat \\<sigma> V (zs @ map the v) i \\<phi>\" if [simp]: \"length zs = b\" for zs\n      proof -\n        let ?zs = \"map2 (\\<lambda>z i. if i \\<in> Formula.fv \\<phi> then Some z else None) zs [0..<b]\"\n        have \"wf_tuple b {x \\<in> fv \\<phi>. x < b} ?zs\"\n          by (simp add: wf_tuple_def)\n        then have \"wf_tuple (b + n) (Formula.fv \\<phi>) (?zs @ v[y:=None])\"\n          using \\<open>wf_tuple n ?fv v\\<close> True\n          by (auto simp: g0 intro!: wf_tuple_append wf_tuple_upd_None)\n        then have \"\\<not> Formula.sat \\<sigma> V (map the (?zs @ v[y:=None])) i \\<phi>\"\n          using True \\<open>mem_restr R v\\<close>\n          by (auto simp del: map_append dest!: in_qtableI[OF inner, rotated -1]\n              intro!: mem_restr_upd_None)\n        also have \"Formula.sat \\<sigma> V (map the (?zs @ v[y:=None])) i \\<phi> \\<longleftrightarrow> Formula.sat \\<sigma> V (zs @ map the v) i \\<phi>\"\n          using True by (auto simp: g0 nth_append intro!: sat_fv_cong)\n        finally show ?thesis .\n      qed\n      then have M_empty: \"M (map the v) = {}\"\n        unfolding M_def by blast\n      show \"Formula.sat \\<sigma> V (map the v) i (Formula.Agg y \\<omega> b f \\<phi>)\"\n        if \"v \\<in> eval_agg n g0 y \\<omega> b f rel\"\n        using M_empty True that n\n        by (simp add: M_def eval_agg_def g0 singleton_table_def)\n      have \"v \\<in> singleton_table n y (the (v ! y))\" \"length v = n\"\n        using \\<open>wf_tuple n ?fv v\\<close> unfolding wf_tuple_def singleton_table_def\n        by (auto simp add: tabulate_alt map_nth\n            intro!: trans[OF map_cong[where g=\"(!) v\", simplified nth_map, OF refl], symmetric])\n      then show \"v \\<in> eval_agg n g0 y \\<omega> b f rel\"\n        if \"Formula.sat \\<sigma> V (map the v) i (Formula.Agg y \\<omega> b f \\<phi>)\"\n        using M_empty True that n\n        by (simp add: M_def eval_agg_def g0)\n    qed\n  next\n    case non_default_case: False\n    have union_fv: \"{0..<b} \\<union> (\\<lambda>x. x + b) ` Formula.fvi b \\<phi> = fv \\<phi>\"\n      using b_fv\n      by (auto simp: fvi_iff_fv(1)[where b=b] intro!: image_eqI[where b=x and x=\"x - b\" for x])\n    have b_n: \"\\<forall>x\\<in>fv \\<phi>. x < b + n\"\n    proof\n      fix x assume \"x \\<in> fv \\<phi>\"\n      show \"x < b + n\" proof (cases \"x \\<ge> b\")\n        case True\n        with \\<open>x \\<in> fv \\<phi>\\<close> have \"x - b \\<in> ?fv\"\n          by (simp add: fvi_iff_fv(1)[where b=b])\n        then show ?thesis using n f_fvi by (auto simp: Un_absorb2)\n      qed simp\n    qed\n\n    define M' where \"M' = (\\<lambda>k. let group = Set.filter (\\<lambda>x. drop b x = k) rel;\n        images = meval_trm f ` group\n      in (\\<lambda>y. (y, ecard (Set.filter (\\<lambda>x. meval_trm f x = y) group))) ` images)\"\n    have M'_M: \"M' (drop b x) = M (map the (drop b x))\" if \"x \\<in> rel\" \"mem_restr (lift_envs' b R) x\" for x\n    proof -\n      from that have wf_x: \"wf_tuple (b + n) (fv \\<phi>) x\"\n        by (auto elim!: in_qtableE[OF inner])\n      then have wf_zs_x: \"wf_tuple (b + n) (fv \\<phi>) (map Some zs @ drop b x)\"\n        if \"length zs = b\" for zs\n        using that b_fv\n        by (auto intro!: wf_tuple_append wf_tuple_map_Some wf_tuple_drop)\n      have 1: \"(length zs = b \\<and> Formula.sat \\<sigma> V (zs @ map the (drop b x)) i \\<phi> \\<and>\n          Formula.eval_trm (zs @ map the (drop b x)) f = y) \\<longleftrightarrow>\n        (\\<exists>a. a \\<in> rel \\<and> take b a = map Some zs \\<and> drop b a = drop b x \\<and> meval_trm f a = y)\"\n        (is \"?A \\<longleftrightarrow> (\\<exists>a. ?B a)\") for y zs\n      proof (intro iffI conjI)\n        assume ?A\n        then have \"?B (map Some zs @ drop (length zs) x)\"\n          using in_qtableI[OF inner wf_zs_x] \\<open>mem_restr (lift_envs' b R) x\\<close>\n            meval_trm_eval_trm[OF wf_zs_x f_fv b_n]\n          by (auto intro!: mem_restr_dropI)\n        then show \"\\<exists>a. ?B a\" ..\n      next\n        assume \"\\<exists>a. ?B a\"\n        then obtain a where \"?B a\" ..\n        then have \"a \\<in> rel\" and a_eq: \"a = map Some zs @ drop b x\"\n          using append_take_drop_id[of b a] by auto\n        then have \"length a = b + n\"\n          using inner unfolding qtable_def table_def\n          by (blast intro!: wf_tuple_length)\n        then show \"length zs = b\"\n          using wf_tuple_length[OF wf_x] unfolding a_eq by simp\n        then have \"mem_restr (lift_envs' b R) a\"\n          using \\<open>mem_restr _ x\\<close> unfolding a_eq by (auto intro!: mem_restr_dropI)\n        then show \"Formula.sat \\<sigma> V (zs @ map the (drop b x)) i \\<phi>\"\n          using in_qtableE[OF inner \\<open>a \\<in> rel\\<close>]\n          by (auto simp: a_eq sat_fv_cong[THEN iffD1, rotated -1])\n        from \\<open>?B a\\<close> show \"Formula.eval_trm (zs @ map the (drop b x)) f = y\"\n          using meval_trm_eval_trm[OF wf_zs_x f_fv b_n, OF \\<open>length zs = b\\<close>]\n          unfolding a_eq by simp\n      qed\n      have 2: \"map Some (map the (take b a)) = take b a\" if \"a \\<in> rel\" for a\n        using that b_fv inner[THEN qtable_wf_tupleD]\n        unfolding table_def wf_tuple_def\n        by (auto simp: list_eq_iff_nth_eq)\n      have 3: \"ecard {zs. \\<exists>a. a \\<in> rel \\<and> take b a = map Some zs \\<and> drop b a = drop b x \\<and> P a} =\n        ecard {a. a \\<in> rel \\<and> drop b a = drop b x \\<and> P a}\" (is \"ecard ?A = ecard ?B\") for P\n      proof -\n        have \"ecard ?A = ecard ((\\<lambda>zs. map Some zs @ drop b x) ` ?A)\"\n          by (auto intro!: ecard_image[symmetric] inj_onI)\n        also have \"(\\<lambda>zs. map Some zs @ drop b x) ` ?A = ?B\"\n          by (subst (1 2) eq_commute) (auto simp: image_iff, metis \"2\" append_take_drop_id)\n        finally show ?thesis .\n      qed\n      show ?thesis\n        unfolding M_def M'_def\n        by (auto simp: non_default_case Let_def image_def Set.filter_def 1 3, metis \"2\")\n    qed\n    have drop_lift: \"mem_restr (lift_envs' b R) x\" if \"x \\<in> rel\" \"mem_restr R ((drop b x)[y:=z])\" for x z\n    proof -\n      have \"(drop b x)[y:=None] = (drop b x)[y:=drop b x ! y]\" proof -\n        from \\<open>x \\<in> rel\\<close> have \"drop b x ! y = None\"\n          using fresh n inner[THEN qtable_wf_tupleD]\n          by (simp add: add.commute wf_tuple_def)\n        then show ?thesis by simp\n      qed\n      then have \"(drop b x)[y:=None] = drop b x\" by simp\n      moreover from \\<open>x \\<in> rel\\<close> have \"length x = b + n\"\n        using inner[THEN qtable_wf_tupleD]\n        by (simp add: wf_tuple_def)\n      moreover from that(2) have \"mem_restr R ((drop b x)[y:=z, y:=None])\"\n        by (rule mem_restr_upd_None)\n      ultimately show ?thesis\n        by (auto intro!: mem_restr_dropD)\n    qed\n\n    {\n      fix v\n      assume \"mem_restr R v\"\n      have \"v \\<in> (\\<lambda>k. k[y:=Some (eval_agg_op \\<omega> (M' k))]) ` drop b ` rel \\<longleftrightarrow>\n          v \\<in> (\\<lambda>k. k[y:=Some (eval_agg_op \\<omega> (M (map the k)))]) ` drop b ` rel\"\n        (is \"v \\<in> ?A \\<longleftrightarrow> v \\<in> ?B\")\n      proof\n        assume \"v \\<in> ?A\"\n        then obtain v' where *: \"v' \\<in> rel\" \"v = (drop b v')[y:=Some (eval_agg_op \\<omega> (M' (drop b v')))]\"\n          by auto\n        then have \"M' (drop b v') = M (map the (drop b v'))\"\n          using \\<open>mem_restr R v\\<close> by (auto intro!: M'_M drop_lift)\n        with * show \"v \\<in> ?B\" by simp\n      next\n        assume \"v \\<in> ?B\"\n        then obtain v' where *: \"v' \\<in> rel\" \"v = (drop b v')[y:=Some (eval_agg_op \\<omega> (M (map the (drop b v'))))]\"\n          by auto\n        then have \"M (map the (drop b v')) = M' (drop b v')\"\n          using \\<open>mem_restr R v\\<close> by (auto intro!: M'_M[symmetric] drop_lift)\n        with * show \"v \\<in> ?A\" by simp\n      qed\n      then have \"v \\<in> eval_agg n g0 y \\<omega> b f rel \\<longleftrightarrow> v \\<in> (\\<lambda>k. k[y:=Some (eval_agg_op \\<omega> (M (map the k)))]) ` drop b ` rel\"\n        by (simp add: non_default_case eval_agg_def M'_def Let_def)\n    }\n    note alt = this\n\n    show ?thesis proof (rule qtableI)\n      show \"table n ?fv ?rel'\"\n        using inner[THEN qtable_wf_tupleD] n f_fvi\n        by (auto simp: eval_agg_def non_default_case table_def wf_tuple_def Let_def nth_list_update\n            fvi_iff_fv[where b=b] add.commute)\n    next\n      fix v\n      assume \"wf_tuple n ?fv v\" \"mem_restr R v\"\n      then have length_v: \"length v = n\" by (simp add: wf_tuple_def)\n\n      show \"Formula.sat \\<sigma> V (map the v) i (Formula.Agg y \\<omega> b f \\<phi>)\"\n        if \"v \\<in> eval_agg n g0 y \\<omega> b f rel\"\n      proof -\n        from that obtain v' where \"v' \\<in> rel\"\n          \"v = (drop b v')[y:=Some (eval_agg_op \\<omega> (M (map the (drop b v'))))]\"\n          using alt[OF \\<open>mem_restr R v\\<close>] by blast\n        then have length_v': \"length v' = b + n\"\n          using inner[THEN qtable_wf_tupleD]\n          by (simp add: wf_tuple_def)\n        have \"Formula.sat \\<sigma> V (map the v') i \\<phi>\"\n          using \\<open>v' \\<in> rel\\<close> \\<open>mem_restr R v\\<close>\n          by (auto simp: \\<open>v = _\\<close> elim!: in_qtableE[OF inner] intro!: drop_lift \\<open>v' \\<in> rel\\<close>)\n        then have \"Formula.sat \\<sigma> V (map the (take b v') @ map the v) i \\<phi>\"\n        proof (rule sat_fv_cong[THEN iffD1, rotated], intro ballI)\n          fix x\n          assume \"x \\<in> fv \\<phi>\"\n          then have \"x \\<noteq> y + b\" using fresh by blast\n          moreover have \"x < length v'\"\n            using \\<open>x \\<in> fv \\<phi>\\<close> b_n by (simp add: length_v')\n          ultimately show \"map the v' ! x = (map the (take b v') @ map the v) ! x\"\n            by (auto simp: \\<open>v = _\\<close> nth_append)\n        qed\n        then have 1: \"M (map the v) \\<noteq> {}\" by (force simp: M_def length_v')\n\n        have \"y < length (drop b v')\" using n by (simp add: length_v')\n        moreover have \"Formula.sat \\<sigma> V (zs @ map the v) i \\<phi> \\<longleftrightarrow>\n          Formula.sat \\<sigma> V (zs @ map the (drop b v')) i \\<phi>\" if \"length zs = b\" for zs\n        proof (intro sat_fv_cong ballI)\n          fix x\n          assume \"x \\<in> fv \\<phi>\"\n          then have \"x \\<noteq> y + b\" using fresh by blast\n          moreover have \"x < length v'\"\n            using \\<open>x \\<in> fv \\<phi>\\<close> b_n by (simp add: length_v')\n          ultimately show \"(zs @ map the v) ! x = (zs @ map the (drop b v')) ! x\"\n            by (auto simp: \\<open>v = _\\<close> that nth_append)\n        qed\n        moreover have \"Formula.eval_trm (zs @ map the v) f =\n          Formula.eval_trm (zs @ map the (drop b v')) f\" if \"length zs = b\" for zs\n        proof (intro eval_trm_fv_cong ballI)\n          fix x\n          assume \"x \\<in> fv_trm f\"\n          then have \"x \\<noteq> y + b\" using f_fv fresh by blast\n          moreover have \"x < length v'\"\n            using \\<open>x \\<in> fv_trm f\\<close> f_fv b_n by (auto simp: length_v')\n          ultimately show \"(zs @ map the v) ! x = (zs @ map the (drop b v')) ! x\"\n            by (auto simp: \\<open>v = _\\<close> that nth_append)\n        qed\n        ultimately have \"map the v ! y = eval_agg_op \\<omega> (M (map the v))\"\n          by (simp add: M_def \\<open>v = _\\<close> conj_commute cong: conj_cong)\n        with 1 show ?thesis by (auto simp: M_def)\n      qed\n\n      show \"v \\<in> eval_agg n g0 y \\<omega> b f rel\"\n        if sat_Agg: \"Formula.sat \\<sigma> V (map the v) i (Formula.Agg y \\<omega> b f \\<phi>)\"\n      proof -\n        obtain zs where \"length zs = b\" and \"map Some zs @ v[y:=None] \\<in> rel\"\n        proof (cases \"fv \\<phi> \\<subseteq> {0..<b}\")\n          case True\n          with non_default_case have \"rel \\<noteq> empty_table\" by (simp add: g0)\n          then obtain x where \"x \\<in> rel\" by auto\n          have \"(\\<forall>i < n. (v[y:=None]) ! i = None)\"\n            using True \\<open>wf_tuple n ?fv v\\<close> f_fv\n            by (fastforce simp: wf_tuple_def fvi_iff_fv[where b=b] fvi_trm_iff_fv_trm[where b=b])\n          moreover have x: \"(\\<forall>i < n. drop b x ! i = None) \\<and> length x = b + n\"\n            using True \\<open>x \\<in> rel\\<close> inner[THEN qtable_wf_tupleD] f_fv\n            by (auto simp: wf_tuple_def)\n          ultimately have \"v[y:=None] = drop b x\"\n            unfolding list_eq_iff_nth_eq by (auto simp: length_v)\n          with \\<open>x \\<in> rel\\<close> have \"take b x @ v[y:=None] \\<in> rel\" by simp\n          moreover have \"map (Some \\<circ> the) (take b x) = take b x\"\n            using True \\<open>x \\<in> rel\\<close> inner[THEN qtable_wf_tupleD] b_fv\n            by (subst map_cong[where g=id, OF refl]) (auto simp: wf_tuple_def in_set_conv_nth)\n          ultimately have \"map Some (map the (take b x)) @ v[y:=None] \\<in> rel\" by simp\n          then show thesis using x[THEN conjunct2] by (fastforce intro!: that[rotated])\n        next\n          case False\n          with sat_Agg obtain zs where \"length zs = b\" and \"Formula.sat \\<sigma> V (zs @ map the v) i \\<phi>\"\n            by auto\n          then have \"Formula.sat \\<sigma> V (zs @ map the (v[y:=None])) i \\<phi>\"\n            using fresh\n            by (auto simp: map_update not_less nth_append elim!: sat_fv_cong[THEN iffD1, rotated]\n                intro!: nth_list_update_neq[symmetric])\n          then have \"map Some zs @ v[y:=None] \\<in> rel\"\n            using b_fv f_fv fresh\n            by (auto intro!: in_qtableI[OF inner] wf_tuple_append wf_tuple_map_Some\n                wf_tuple_upd_None \\<open>wf_tuple n ?fv v\\<close> mem_restr_upd_None \\<open>mem_restr R v\\<close>\n                simp: \\<open>length zs = b\\<close> set_eq_iff fvi_iff_fv[where b=b] fvi_trm_iff_fv_trm[where b=b])\n              force+\n          with that \\<open>length zs = b\\<close> show thesis by blast\n        qed\n        then have 1: \"v[y:=None] \\<in> drop b ` rel\" by (intro image_eqI) auto\n\n        have y_length: \"y < length v\" using n by (simp add: length_v)\n        moreover have \"Formula.sat \\<sigma> V (zs @ map the (v[y:=None])) i \\<phi> \\<longleftrightarrow>\n          Formula.sat \\<sigma> V (zs @ map the v) i \\<phi>\" if \"length zs = b\" for zs\n        proof (intro sat_fv_cong ballI)\n          fix x\n          assume \"x \\<in> fv \\<phi>\"\n          then have \"x \\<noteq> y + b\" using fresh by blast\n          moreover have \"x < b + length v\"\n            using \\<open>x \\<in> fv \\<phi>\\<close> b_n by (simp add: length_v)\n          ultimately show \"(zs @ map the (v[y:=None])) ! x = (zs @ map the v) ! x\"\n            by (auto simp: that nth_append)\n        qed\n        moreover have \"Formula.eval_trm (zs @ map the (v[y:=None])) f =\n          Formula.eval_trm (zs @ map the v) f\" if \"length zs = b\" for zs\n        proof (intro eval_trm_fv_cong ballI)\n          fix x\n          assume \"x \\<in> fv_trm f\"\n          then have \"x \\<noteq> y + b\" using f_fv fresh by blast\n          moreover have \"x < b + length v\"\n            using \\<open>x \\<in> fv_trm f\\<close> f_fv b_n by (auto simp: length_v)\n          ultimately show \"(zs @ map the (v[y:=None])) ! x = (zs @ map the v) ! x\"\n            by (auto simp: that nth_append)\n        qed\n        ultimately have \"map the v ! y = eval_agg_op \\<omega> (M (map the (v[y:=None])))\"\n          using sat_Agg by (simp add: M_def cong: conj_cong) (simp cong: rev_conj_cong)\n        then have 2: \"v ! y = Some (eval_agg_op \\<omega> (M (map the (v[y:=None]))))\"\n          using \\<open>wf_tuple n ?fv v\\<close> y_length by (auto simp add: wf_tuple_def)\n        show ?thesis\n          unfolding alt[OF \\<open>mem_restr R v\\<close>]\n          by (rule image_eqI[where x=\"v[y:=None]\"]) (use 1 2 in \\<open>auto simp: y_length list_update_id\\<close>)\n      qed\n    qed\n  qed\nqed\n\nlemma mprev: \"mprev_next I xs ts = (ys, xs', ts') \\<Longrightarrow>\n  list_all2 P [i..<j'] xs \\<Longrightarrow> list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [i..<j] ts \\<Longrightarrow> i \\<le> j' \\<Longrightarrow> i < j \\<Longrightarrow>\n  list_all2 (\\<lambda>i X. if mem (\\<tau> \\<sigma> (Suc i) - \\<tau> \\<sigma> i) I then P i X else X = empty_table)\n    [i..<min j' (j-1)] ys \\<and>\n  list_all2 P [min j' (j-1)..<j'] xs' \\<and>\n  list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [min j' (j-1)..<j] ts'\"\nproof (induction I xs ts arbitrary: i ys xs' ts' rule: mprev_next.induct)\n  case (1 I ts)\n  then have \"min j' (j-1) = i\" by auto\n  with 1 show ?case by auto\nnext\n  case (3 I v v' t)\n  then have \"min j' (j-1) = i\" by (auto simp: list_all2_Cons2 upt_eq_Cons_conv)\n  with 3 show ?case by auto\nnext\n  case (4 I x xs t t' ts)\n  from 4(1)[of \"tl ys\" xs' ts' \"Suc i\"] 4(2-6) show ?case\n    by (auto simp add: list_all2_Cons2 upt_eq_Cons_conv Suc_less_eq2\n        elim!: list.rel_mono_strong split: prod.splits if_splits)\nqed simp\n\nlemma mnext: \"mprev_next I xs ts = (ys, xs', ts') \\<Longrightarrow>\n  list_all2 P [Suc i..<j'] xs \\<Longrightarrow> list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [i..<j] ts \\<Longrightarrow> Suc i \\<le> j' \\<Longrightarrow> i < j \\<Longrightarrow>\n  list_all2 (\\<lambda>i X. if mem (\\<tau> \\<sigma> (Suc i) - \\<tau> \\<sigma> i) I then P (Suc i) X else X = empty_table)\n    [i..<min (j'-1) (j-1)] ys \\<and>\n  list_all2 P [Suc (min (j'-1) (j-1))..<j'] xs' \\<and>\n  list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [min (j'-1) (j-1)..<j] ts'\"\nproof (induction I xs ts arbitrary: i ys xs' ts' rule: mprev_next.induct)\n  case (1 I ts)\n  then have \"min (j' - 1) (j-1) = i\" by auto\n  with 1 show ?case by auto\nnext\n  case (3 I v v' t)\n  then have \"min (j' - 1) (j-1) = i\" by (auto simp: list_all2_Cons2 upt_eq_Cons_conv)\n  with 3 show ?case by auto\nnext\n  case (4 I x xs t t' ts)\n  from 4(1)[of \"tl ys\" xs' ts' \"Suc i\"] 4(2-6) show ?case\n    by (auto simp add: list_all2_Cons2 upt_eq_Cons_conv Suc_less_eq2\n        elim!: list.rel_mono_strong split: prod.splits if_splits) (* slow 10 sec *)\nqed simp\n\nlemma in_foldr_UnI: \"x \\<in> A \\<Longrightarrow> A \\<in> set xs \\<Longrightarrow> x \\<in> foldr (\\<union>) xs {}\"\n  by (induction xs) auto\n\nlemma in_foldr_UnE: \"x \\<in> foldr (\\<union>) xs {} \\<Longrightarrow> (\\<And>A. A \\<in> set xs \\<Longrightarrow> x \\<in> A \\<Longrightarrow> P) \\<Longrightarrow> P\"\n  by (induction xs) auto\n\nlemma sat_the_restrict: \"fv \\<phi> \\<subseteq> A \\<Longrightarrow> Formula.sat \\<sigma> V (map the (restrict A v)) i \\<phi> = Formula.sat \\<sigma> V (map the v) i \\<phi>\"\n  by (rule sat_fv_cong) (auto intro!: map_the_restrict)\n\nlemma eps_the_restrict: \"fv_regex r \\<subseteq> A \\<Longrightarrow> Regex.eps (Formula.sat \\<sigma> V (map the (restrict A v))) i r = Regex.eps (Formula.sat \\<sigma> V (map the v)) i r\"\n  by (rule eps_fv_cong) (auto intro!: map_the_restrict)\n\nlemma sorted_wrt_filter[simp]: \"sorted_wrt R xs \\<Longrightarrow> sorted_wrt R (filter P xs)\"\n  by (induct xs) auto\n\nlemma concat_map_filter[simp]:\n  \"concat (map f (filter P xs)) = concat (map (\\<lambda>x. if P x then f x else []) xs)\"\n  by (induct xs) auto\n\nlemma map_filter_alt:\n  \"map f (filter P xs) = concat (map (\\<lambda>x. if P x then [f x] else []) xs)\"\n  by (induct xs) auto\n\nlemma (in maux) update_since:\n  assumes pre: \"wf_since_aux \\<sigma> V R args \\<phi> \\<psi> aux ne\"\n    and qtable1: \"qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne \\<phi>) rel1\"\n    and qtable2: \"qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne \\<psi>) rel2\"\n    and result_eq: \"(rel, aux') = update_since args rel1 rel2 (\\<tau> \\<sigma> ne) aux\"\n    and fvi_subset: \"Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi>\"\n    and args_ivl: \"args_ivl args = I\"\n    and args_n: \"args_n args = n\"\n    and args_L: \"args_L args = Formula.fv \\<phi>\"\n    and args_R: \"args_R args = Formula.fv \\<psi>\"\n    and args_pos: \"args_pos args = pos\"\n  shows \"wf_since_aux \\<sigma> V R args \\<phi> \\<psi> aux' (Suc ne)\"\n    and \"qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne (Sincep pos \\<phi> I \\<psi>)) rel\"\nproof -\n  let ?wf_tuple = \"\\<lambda>v. wf_tuple n (Formula.fv \\<psi>) v\"\n  note sat.simps[simp del]\n  from pre[unfolded wf_since_aux_def] obtain cur auxlist where aux: \"valid_msaux args cur aux auxlist\"\n    \"sorted_wrt (\\<lambda>x y. fst y < fst x) auxlist\"\n    \"\\<And>t X. (t, X) \\<in> set auxlist \\<Longrightarrow> ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne - 1) \\<and> \\<tau> \\<sigma> (ne - 1) - t \\<le> right I \\<and>\n      (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      qtable n (fv \\<psi>) (mem_restr R)\n        (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne - 1) (Sincep pos \\<phi> (point (\\<tau> \\<sigma> (ne - 1) - t)) \\<psi>)) X\"\n    \"\\<And>t. ne \\<noteq> 0 \\<Longrightarrow> t \\<le> \\<tau> \\<sigma> (ne - 1) \\<Longrightarrow> \\<tau> \\<sigma> (ne - 1) - t \\<le> right I \\<Longrightarrow> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<Longrightarrow>\n      (\\<exists>X. (t, X) \\<in> set auxlist)\"\n    and cur_def:\n    \"cur = (if ne = 0 then 0 else \\<tau> \\<sigma> (ne - 1))\"\n    unfolding args_ivl args_n args_pos by blast\n  from pre[unfolded wf_since_aux_def] have fv_sub: \"Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi>\" by simp\n\n  define aux0 where \"aux0 = join_msaux args rel1 (add_new_ts_msaux args (\\<tau> \\<sigma> ne) aux)\"\n  define auxlist0 where \"auxlist0 = [(t, join rel pos rel1). (t, rel) \\<leftarrow> auxlist, \\<tau> \\<sigma> ne - t \\<le> right I]\"\n  have tabL: \"table (args_n args) (args_L args) rel1\"\n    using qtable1[unfolded qtable_def] unfolding args_n[symmetric] args_L[symmetric] by simp\n  have cur_le: \"cur \\<le> \\<tau> \\<sigma> ne\"\n    unfolding cur_def by auto\n  have valid0: \"valid_msaux args (\\<tau> \\<sigma> ne) aux0 auxlist0\" unfolding aux0_def auxlist0_def\n    using valid_join_msaux[OF valid_add_new_ts_msaux[OF aux(1)], OF cur_le tabL]\n    by (auto simp: args_ivl args_pos cur_def map_filter_alt split_beta cong: map_cong)\n  from aux(2) have sorted_auxlist0: \"sorted_wrt (\\<lambda>x y. fst x > fst y) auxlist0\"\n    unfolding auxlist0_def\n    by (induction auxlist) (auto simp add: sorted_wrt_append)\n  have in_auxlist0_1: \"(t, X) \\<in> set auxlist0 \\<Longrightarrow> ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> (ne-1) \\<and> \\<tau> \\<sigma> ne - t \\<le> right I \\<and>\n      (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. (Formula.sat \\<sigma> V (map the v) (ne-1) (Sincep pos \\<phi> (point (\\<tau> \\<sigma> (ne-1) - t)) \\<psi>) \\<and>\n        (if pos then Formula.sat \\<sigma> V (map the v) ne \\<phi> else \\<not> Formula.sat \\<sigma> V (map the v) ne \\<phi>))) X\" for t X\n    unfolding auxlist0_def using fvi_subset\n    by (auto 0 1 elim!: qtable_join[OF _ qtable1] simp: sat_the_restrict dest!: aux(3))\n  then have in_auxlist0_le_\\<tau>: \"(t, X) \\<in> set auxlist0 \\<Longrightarrow> t \\<le> \\<tau> \\<sigma> ne\" for t X\n    by (meson \\<tau>_mono diff_le_self le_trans)\n  have in_auxlist0_2: \"ne \\<noteq> 0 \\<Longrightarrow> t \\<le> \\<tau> \\<sigma> (ne-1) \\<Longrightarrow> \\<tau> \\<sigma> ne - t \\<le> right I \\<Longrightarrow> \\<exists>i. \\<tau> \\<sigma> i = t \\<Longrightarrow>\n    \\<exists>X. (t, X) \\<in> set auxlist0\" for t\n  proof -\n    fix t\n    assume \"ne \\<noteq> 0\" \"t \\<le> \\<tau> \\<sigma> (ne-1)\" \"\\<tau> \\<sigma> ne - t \\<le> right I\" \"\\<exists>i. \\<tau> \\<sigma> i = t\"\n    then obtain X where \"(t, X) \\<in> set auxlist\"\n      by (atomize_elim, intro aux(4))\n        (auto simp: gr0_conv_Suc elim!: order_trans[rotated] intro!: diff_le_mono \\<tau>_mono)\n    with \\<open>\\<tau> \\<sigma> ne - t \\<le> right I\\<close> have \"(t, join X pos rel1) \\<in> set auxlist0\"\n      unfolding auxlist0_def by (auto elim!: bexI[rotated] intro!: exI[of _ X])\n    then show \"\\<exists>X. (t, X) \\<in> set auxlist0\"\n      by blast\n  qed\n  have auxlist0_Nil: \"auxlist0 = [] \\<Longrightarrow> ne = 0 \\<or> ne \\<noteq> 0 \\<and> (\\<forall>t. t \\<le> \\<tau> \\<sigma> (ne-1) \\<and> \\<tau> \\<sigma> ne - t \\<le> right I \\<longrightarrow>\n        (\\<nexists>i. \\<tau> \\<sigma> i = t))\"\n    using in_auxlist0_2 by (auto)\n\n  have aux'_eq: \"aux' = add_new_table_msaux args rel2 aux0\"\n    using result_eq unfolding aux0_def update_since_def Let_def by simp\n  define auxlist' where\n    auxlist'_eq: \"auxlist' = (case auxlist0 of\n      [] \\<Rightarrow> [(\\<tau> \\<sigma> ne, rel2)]\n    | x # auxlist' \\<Rightarrow> (if fst x = \\<tau> \\<sigma> ne then (fst x, snd x \\<union> rel2) # auxlist' else (\\<tau> \\<sigma> ne, rel2) # x # auxlist'))\"\n  have tabR: \"table (args_n args) (args_R args) rel2\"\n    using qtable2[unfolded qtable_def] unfolding args_n[symmetric] args_R[symmetric] by simp\n  have valid': \"valid_msaux args (\\<tau> \\<sigma> ne) aux' auxlist'\"\n    unfolding aux'_eq auxlist'_eq using valid_add_new_table_msaux[OF valid0 tabR]\n    by (auto simp: not_le split: list.splits option.splits if_splits)\n  have sorted_auxlist': \"sorted_wrt (\\<lambda>x y. fst x > fst y) auxlist'\"\n    unfolding auxlist'_eq\n    using sorted_auxlist0 in_auxlist0_le_\\<tau> by (cases auxlist0) fastforce+\n  have in_auxlist'_1: \"t \\<le> \\<tau> \\<sigma> ne \\<and> \\<tau> \\<sigma> ne - t \\<le> right I \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne (Sincep pos \\<phi> (point (\\<tau> \\<sigma> ne - t)) \\<psi>)) X\"\n    if auxlist': \"(t, X) \\<in> set auxlist'\" for t X\n  proof (cases auxlist0)\n    case Nil\n    with auxlist' show ?thesis\n      unfolding auxlist'_eq using qtable2 auxlist0_Nil\n      by (auto simp: zero_enat_def[symmetric] sat_Since_rec[where i=ne]\n          dest: spec[of _ \"\\<tau> \\<sigma> (ne-1)\"] elim!: qtable_cong[OF _ refl])\n  next\n    case (Cons a as)\n    show ?thesis\n    proof (cases \"t = \\<tau> \\<sigma> ne\")\n      case t: True\n      show ?thesis\n      proof (cases \"fst a = \\<tau> \\<sigma> ne\")\n        case True\n        with auxlist' Cons t have \"X = snd a \\<union> rel2\"\n          unfolding auxlist'_eq using sorted_auxlist0 by (auto split: if_splits)\n        moreover from in_auxlist0_1[of \"fst a\" \"snd a\"] Cons have \"ne \\<noteq> 0\"\n          \"fst a \\<le> \\<tau> \\<sigma> (ne - 1)\" \"\\<tau> \\<sigma> ne - fst a \\<le> right I\" \"\\<exists>i. \\<tau> \\<sigma> i = fst a\"\n          \"qtable n (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne - 1)\n            (Sincep pos \\<phi> (point (\\<tau> \\<sigma> (ne - 1) - fst a)) \\<psi>) \\<and> (if pos then Formula.sat \\<sigma> V (map the v) ne \\<phi>\n              else \\<not> Formula.sat \\<sigma> V (map the v) ne \\<phi>)) (snd a)\"\n          by (auto simp: True[symmetric] zero_enat_def[symmetric])\n        ultimately show ?thesis using qtable2 t True\n          by (auto simp: sat_Since_rec[where i=ne] sat.simps(6) elim!: qtable_union)\n      next\n        case False\n        with auxlist' Cons t have \"X = rel2\"\n          unfolding auxlist'_eq using sorted_auxlist0 in_auxlist0_le_\\<tau>[of \"fst a\" \"snd a\"] by (auto split: if_splits)\n        with auxlist' Cons t False show ?thesis\n          unfolding auxlist'_eq using qtable2 in_auxlist0_2[of \"\\<tau> \\<sigma> (ne-1)\"] in_auxlist0_le_\\<tau>[of \"fst a\" \"snd a\"] sorted_auxlist0\n          by (auto simp: sat_Since_rec[where i=ne] sat.simps(3) zero_enat_def[symmetric] enat_0_iff not_le\n              elim!: qtable_cong[OF _ refl] dest!: le_\\<tau>_less meta_mp)\n      qed\n    next\n      case False\n      with auxlist' Cons have \"(t, X) \\<in> set auxlist0\"\n        unfolding auxlist'_eq by (auto split: if_splits)\n      then have \"ne \\<noteq> 0\" \"t \\<le> \\<tau> \\<sigma> (ne - 1)\" \"\\<tau> \\<sigma> ne - t \\<le> right I\" \"\\<exists>i. \\<tau> \\<sigma> i = t\"\n        \"qtable n (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne - 1) (Sincep pos \\<phi> (point (\\<tau> \\<sigma> (ne - 1) - t)) \\<psi>) \\<and>\n           (if pos then Formula.sat \\<sigma> V (map the v) ne \\<phi> else \\<not> Formula.sat \\<sigma> V (map the v) ne \\<phi>)) X\"\n        using in_auxlist0_1 by blast+\n      with False auxlist' Cons show ?thesis\n        unfolding auxlist'_eq using qtable2\n        by (fastforce simp: sat_Since_rec[where i=ne] sat.simps(6)\n            diff_diff_right[where i=\"\\<tau> \\<sigma> ne\" and j=\"\\<tau> \\<sigma> _ + \\<tau> \\<sigma> ne\" and k=\"\\<tau> \\<sigma> (ne - 1)\",\n              OF trans_le_add2, simplified] elim!: qtable_cong[OF _ refl] order_trans dest: le_\\<tau>_less)\n    qed\n  qed\n\n  have in_auxlist'_2: \"\\<exists>X. (t, X) \\<in> set auxlist'\" if \"t \\<le> \\<tau> \\<sigma> ne\" \"\\<tau> \\<sigma> ne - t \\<le> right I\" \"\\<exists>i. \\<tau> \\<sigma> i = t\" for t\n  proof (cases \"t = \\<tau> \\<sigma> ne\")\n    case True\n    then show ?thesis\n    proof (cases auxlist0)\n      case Nil\n      with True show ?thesis unfolding auxlist'_eq by (simp add: zero_enat_def[symmetric])\n    next\n      case (Cons a as)\n      with True show ?thesis unfolding auxlist'_eq\n        by (cases \"fst a = \\<tau> \\<sigma> ne\") (auto simp: zero_enat_def[symmetric])\n    qed\n  next\n    case False\n    with that have \"ne \\<noteq> 0\"\n      using le_\\<tau>_less neq0_conv by blast\n    moreover from False that have  \"t \\<le> \\<tau> \\<sigma> (ne-1)\"\n      by (metis One_nat_def Suc_leI Suc_pred \\<tau>_mono diff_is_0_eq' order.antisym neq0_conv not_le)\n    ultimately obtain X where \"(t, X) \\<in> set auxlist0\" using \\<open>\\<tau> \\<sigma> ne - t \\<le> right I\\<close> \\<open>\\<exists>i. \\<tau> \\<sigma> i = t\\<close>\n      using \\<tau>_mono[of \"ne - 1\" \"ne\" \\<sigma>] by (atomize_elim, cases \"right I\") (auto intro!: in_auxlist0_2 simp del: \\<tau>_mono)\n    then show ?thesis unfolding auxlist'_eq using False \\<open>\\<tau> \\<sigma> ne - t \\<le> right I\\<close>\n      by (auto intro: exI[of _ X] split: list.split)\n  qed\n\n  show \"wf_since_aux \\<sigma> V R args \\<phi> \\<psi> aux' (Suc ne)\"\n    unfolding wf_since_aux_def args_ivl args_n args_pos\n    by (auto simp add: fv_sub dest: in_auxlist'_1 intro: sorted_auxlist' in_auxlist'_2\n        intro!: exI[of _ auxlist'] valid')\n\n  have \"rel = result_msaux args aux'\"\n    using result_eq by (auto simp add: update_since_def Let_def)\n  with valid' have rel_eq: \"rel = foldr (\\<union>) [rel. (t, rel) \\<leftarrow> auxlist', left I \\<le> \\<tau> \\<sigma> ne - t] {}\"\n    by (auto simp add: args_ivl valid_result_msaux\n        intro!: arg_cong[where f = \"\\<lambda>x. foldr (\\<union>) (concat x) {}\"] split: option.splits)\n  have rel_alt: \"rel = (\\<Union>(t, rel) \\<in> set auxlist'. if left I \\<le> \\<tau> \\<sigma> ne - t then rel else empty_table)\"\n    unfolding rel_eq\n    by (auto elim!: in_foldr_UnE bexI[rotated] intro!: in_foldr_UnI)\n  show \"qtable n (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne (Sincep pos \\<phi> I \\<psi>)) rel\"\n    unfolding rel_alt\n  proof (rule qtable_Union[where Qi=\"\\<lambda>(t, X) v.\n    left I \\<le> \\<tau> \\<sigma> ne - t \\<and> Formula.sat \\<sigma> V (map the v) ne (Sincep pos \\<phi> (point (\\<tau> \\<sigma> ne - t)) \\<psi>)\"],\n        goal_cases finite qtable equiv)\n    case (equiv v)\n    show ?case\n    proof (rule iffI, erule sat_Since_point, goal_cases left right)\n      case (left j)\n      then show ?case using in_auxlist'_2[of \"\\<tau> \\<sigma> j\", OF _ _ exI, OF _ _ refl] by auto\n    next\n      case right\n      then show ?case by (auto elim!: sat_Since_pointD dest: in_auxlist'_1)\n    qed\n  qed (auto dest!: in_auxlist'_1 intro!: qtable_empty)\nqed\n\nlemma fv_regex_from_mregex:\n  \"ok (length \\<phi>s) mr \\<Longrightarrow> fv_regex (from_mregex mr \\<phi>s) \\<subseteq> (\\<Union>\\<phi> \\<in> set \\<phi>s. fv \\<phi>)\"\n  by (induct mr) (auto simp: Bex_def in_set_conv_nth)+\n\nlemma qtable_\\<epsilon>_lax:\n  assumes \"ok (length \\<phi>s) mr\"\n    and \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>) rel) \\<phi>s rels\"\n    and \"fv_regex (from_mregex mr \\<phi>s) \\<subseteq> A\" and \"qtable n A (mem_restr R) Q guard\"\n  shows \"qtable n A (mem_restr R)\n   (\\<lambda>v. Regex.eps (Formula.sat \\<sigma> V (map the v)) i (from_mregex mr \\<phi>s) \\<and> Q v) (\\<epsilon>_lax guard rels mr)\"\n  using assms\nproof (induct mr)\n  case (MPlus mr1 mr2)\n  from MPlus(3-6) show ?case\n    by (auto intro!: qtable_union[OF MPlus(1,2)])\nnext\n  case (MTimes mr1 mr2)\n  then have \"fv_regex (from_mregex mr1 \\<phi>s) \\<subseteq> A\" \"fv_regex (from_mregex mr2 \\<phi>s) \\<subseteq> A\"\n    using fv_regex_from_mregex[of \\<phi>s mr1] fv_regex_from_mregex[of \\<phi>s mr2] by (auto simp: subset_eq)\n  with MTimes(3-6) show ?case\n    by (auto simp: eps_the_restrict restrict_idle intro!: qtable_join[OF MTimes(1,2)])\nqed (auto split: prod.splits if_splits simp: qtable_empty_iff list_all2_conv_all_nth\n    in_set_conv_nth restrict_idle sat_the_restrict\n    intro: in_qtableI qtableI elim!: qtable_join[where A=A and C=A])\n\nlemma nullary_qtable_cases: \"qtable n {} P Q X \\<Longrightarrow> (X = empty_table \\<or> X = unit_table n)\"\n  by (simp add: qtable_def table_empty)\n\nlemma qtable_empty_unit_table:\n  \"qtable n {} R P empty_table \\<Longrightarrow> qtable n {} R (\\<lambda>v. \\<not> P v) (unit_table n)\"\n  by (auto intro: qtable_unit_table simp add: qtable_empty_iff)\n\nlemma qtable_unit_empty_table:\n  \"qtable n {} R P (unit_table n) \\<Longrightarrow> qtable n {} R (\\<lambda>v. \\<not> P v) empty_table\"\n  by (auto intro!: qtable_empty elim: in_qtableE simp add: wf_tuple_empty unit_table_def)\n\nlemma qtable_nonempty_empty_table:\n  \"qtable n {} R P X \\<Longrightarrow> x \\<in> X \\<Longrightarrow> qtable n {} R (\\<lambda>v. \\<not> P v) empty_table\"\n  by (frule nullary_qtable_cases) (auto dest: qtable_unit_empty_table)\n\n\nlemma qtable_r\\<epsilon>_strict:\n  assumes \"safe_regex Past Strict (from_mregex mr \\<phi>s)\" \"ok (length \\<phi>s) mr\" \"A = fv_regex (from_mregex mr \\<phi>s)\"\n    and \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>) rel) \\<phi>s rels\"\n  shows \"qtable n A (mem_restr R) (\\<lambda>v. Regex.eps (Formula.sat \\<sigma> V (map the v)) i (from_mregex mr \\<phi>s)) (r\\<epsilon>_strict n rels mr)\"\n  using assms\nproof (hypsubst, induct Past Strict \"from_mregex mr \\<phi>s\" arbitrary: mr rule: safe_regex_induct)\n  case (Skip n)\n  then show ?case\n    by (cases mr) (auto simp: qtable_empty_iff qtable_unit_table split: if_splits)\nnext\n  case (Test \\<phi>)\n  then show ?case\n    by (cases mr) (auto simp: list_all2_conv_all_nth qtable_empty_unit_table\n        dest!: qtable_nonempty_empty_table split: if_splits)\nnext\n  case (Plus r s)\n  then show ?case\n    by (cases mr) (fastforce intro: qtable_union split: if_splits)+\nnext\n  case (TimesP r s)\n  then show ?case\n    by (cases mr) (auto intro: qtable_cong[OF qtable_\\<epsilon>_lax] split: if_splits)+\nnext\n  case (Star r)\n  then show ?case\n    by (cases mr) (auto simp: qtable_unit_table split: if_splits)\nqed\n\nlemma qtable_l\\<epsilon>_strict:\n  assumes \"safe_regex Futu Strict (from_mregex mr \\<phi>s)\" \"ok (length \\<phi>s) mr\" \"A = fv_regex (from_mregex mr \\<phi>s)\"\n    and \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>) rel) \\<phi>s rels\"\n  shows \"qtable n A (mem_restr R) (\\<lambda>v. Regex.eps (Formula.sat \\<sigma> V (map the v)) i (from_mregex mr \\<phi>s)) (l\\<epsilon>_strict n rels mr)\"\n  using assms\nproof (hypsubst, induct Futu Strict \"from_mregex mr \\<phi>s\" arbitrary: mr rule: safe_regex_induct)\n  case (Skip n)\n  then show ?case\n    by (cases mr) (auto simp: qtable_empty_iff qtable_unit_table split: if_splits)\nnext\n  case (Test \\<phi>)\n  then show ?case\n    by (cases mr) (auto simp: list_all2_conv_all_nth qtable_empty_unit_table\n        dest!: qtable_nonempty_empty_table split: if_splits)\nnext\n  case (Plus r s)\n  then show ?case\n    by (cases mr) (fastforce intro: qtable_union split: if_splits)+\nnext\n  case (TimesF r s)\n  then show ?case\n    by (cases mr) (auto intro: qtable_cong[OF qtable_\\<epsilon>_lax] split: if_splits)+\nnext\n  case (Star r)\n  then show ?case\n    by (cases mr) (auto simp: qtable_unit_table split: if_splits)\nqed\n\nlemma rtranclp_False: \"(\\<lambda>i j. False)\\<^sup>*\\<^sup>* = (=)\"\nproof -\n  have \"(\\<lambda>i j. False)\\<^sup>*\\<^sup>* i j \\<Longrightarrow> i = j\" for i j :: 'a\n    by (induct i j rule: rtranclp.induct) auto\n  then show ?thesis\n    by (auto intro: exI[of _ 0])\nqed\n\ninductive ok_rctxt for \\<phi>s where\n  \"ok_rctxt \\<phi>s id id\"\n| \"ok_rctxt \\<phi>s \\<kappa> \\<kappa>' \\<Longrightarrow> ok_rctxt \\<phi>s (\\<lambda>t. \\<kappa> (MTimes mr t)) (\\<lambda>t. \\<kappa>' (Regex.Times (from_mregex mr \\<phi>s) t))\"\n\nlemma ok_rctxt_swap: \"ok_rctxt \\<phi>s \\<kappa> \\<kappa>' \\<Longrightarrow> from_mregex (\\<kappa> mr) \\<phi>s = \\<kappa>' (from_mregex mr \\<phi>s)\"\n  by (induct \\<kappa> \\<kappa>' arbitrary: mr rule: ok_rctxt.induct) auto\n\nlemma ok_rctxt_cong: \"ok_rctxt \\<phi>s \\<kappa> \\<kappa>' \\<Longrightarrow> Regex.match (Formula.sat \\<sigma> V v) r = Regex.match (Formula.sat \\<sigma> V v) s \\<Longrightarrow>\n  Regex.match (Formula.sat \\<sigma> V v) (\\<kappa>' r) i j = Regex.match (Formula.sat \\<sigma> V v) (\\<kappa>' s) i j\"\n  by (induct \\<kappa> \\<kappa>' arbitrary: r s rule: ok_rctxt.induct) simp_all\n\nlemma qtable_r\\<delta>\\<kappa>:\n  assumes \"ok (length \\<phi>s) mr\" \"fv_regex (from_mregex mr \\<phi>s) \\<subseteq> A\"\n    and \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) j \\<phi>) rel) \\<phi>s rels\"\n    and \"ok_rctxt \\<phi>s \\<kappa> \\<kappa>'\"\n    and \"\\<forall>ms \\<in> \\<kappa> ` RPD mr. qtable n A (mem_restr R) (\\<lambda>v. Q (map the v) (from_mregex ms \\<phi>s)) (lookup rel ms)\"\n  shows \"qtable n A (mem_restr R)\n  (\\<lambda>v. \\<exists>s \\<in> Regex.rpd\\<kappa> \\<kappa>' (Formula.sat \\<sigma> V (map the v)) j (from_mregex mr \\<phi>s). Q (map the v) s)\n  (r\\<delta> \\<kappa> rel rels mr)\"\n  using assms\nproof (induct mr arbitrary: \\<kappa> \\<kappa>')\n  case MSkip\n  then show ?case\n    by (auto simp: rtranclp_False ok_rctxt_swap qtable_empty_iff\n        elim!: qtable_cong[OF _ _ ok_rctxt_cong[of _ \\<kappa> \\<kappa>']] split: nat.splits)\nnext\n  case (MPlus mr1 mr2)\n  from MPlus(3-7) show ?case\n    by (auto intro!: qtable_union[OF MPlus(1,2)])\nnext\n  case (MTimes mr1 mr2)\n  from MTimes(3-7) show ?case\n    by (auto intro!: qtable_union[OF MTimes(2) qtable_\\<epsilon>_lax[OF _ _ _ MTimes(1)]]\n        elim!: ok_rctxt.intros(2) simp: MTimesL_def Ball_def)\nnext\n  case (MStar mr)\n  from MStar(2-6) show ?case\n    by (auto intro!: qtable_cong[OF MStar(1)] intro: ok_rctxt.intros simp: MTimesL_def Ball_def)\nqed (auto simp: qtable_empty_iff)\n\nlemmas qtable_r\\<delta> = qtable_r\\<delta>\\<kappa>[OF _ _ _ ok_rctxt.intros(1), unfolded rpd\\<kappa>_rpd image_id id_apply]\n\ninductive ok_lctxt for \\<phi>s where\n  \"ok_lctxt \\<phi>s id id\"\n| \"ok_lctxt \\<phi>s \\<kappa> \\<kappa>' \\<Longrightarrow> ok_lctxt \\<phi>s (\\<lambda>t. \\<kappa> (MTimes t mr)) (\\<lambda>t. \\<kappa>' (Regex.Times t (from_mregex mr \\<phi>s)))\"\n\nlemma ok_lctxt_swap: \"ok_lctxt \\<phi>s \\<kappa> \\<kappa>' \\<Longrightarrow> from_mregex (\\<kappa> mr) \\<phi>s = \\<kappa>' (from_mregex mr \\<phi>s)\"\n  by (induct \\<kappa> \\<kappa>' arbitrary: mr rule: ok_lctxt.induct) auto\n\nlemma ok_lctxt_cong: \"ok_lctxt \\<phi>s \\<kappa> \\<kappa>' \\<Longrightarrow> Regex.match (Formula.sat \\<sigma> V v) r = Regex.match (Formula.sat \\<sigma> V v) s \\<Longrightarrow>\n  Regex.match (Formula.sat \\<sigma> V v) (\\<kappa>' r) i j = Regex.match (Formula.sat \\<sigma> V v) (\\<kappa>' s) i j\"\n  by (induct \\<kappa> \\<kappa>' arbitrary: r s rule: ok_lctxt.induct) simp_all\n\nlemma qtable_l\\<delta>\\<kappa>:\n  assumes \"ok (length \\<phi>s) mr\" \"fv_regex (from_mregex mr \\<phi>s) \\<subseteq> A\"\n    and \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) j \\<phi>) rel) \\<phi>s rels\"\n    and \"ok_lctxt \\<phi>s \\<kappa> \\<kappa>'\"\n    and \"\\<forall>ms \\<in> \\<kappa> ` LPD mr. qtable n A (mem_restr R) (\\<lambda>v. Q (map the v) (from_mregex ms \\<phi>s)) (lookup rel ms)\"\n  shows \"qtable n A (mem_restr R)\n  (\\<lambda>v. \\<exists>s \\<in> Regex.lpd\\<kappa> \\<kappa>' (Formula.sat \\<sigma> V (map the v)) j (from_mregex mr \\<phi>s). Q (map the v) s)\n  (l\\<delta> \\<kappa> rel rels mr)\"\n  using assms\nproof (induct mr arbitrary: \\<kappa> \\<kappa>')\n  case MSkip\n  then show ?case\n    by (auto simp: rtranclp_False ok_lctxt_swap qtable_empty_iff\n        elim!: qtable_cong[OF _ _ ok_rctxt_cong[of _ \\<kappa> \\<kappa>']] split: nat.splits)\nnext\n  case (MPlus mr1 mr2)\n  from MPlus(3-7) show ?case\n    by (auto intro!: qtable_union[OF MPlus(1,2)])\nnext\n  case (MTimes mr1 mr2)\n  from MTimes(3-7) show ?case\n    by (auto intro!: qtable_union[OF MTimes(1) qtable_\\<epsilon>_lax[OF _ _ _ MTimes(2)]]\n        elim!: ok_lctxt.intros(2) simp: MTimesR_def Ball_def)\nnext\n  case (MStar mr)\n  from MStar(2-6) show ?case\n    by (auto intro!: qtable_cong[OF MStar(1)] intro: ok_lctxt.intros simp: MTimesR_def Ball_def)\nqed (auto simp: qtable_empty_iff)\n\nlemmas qtable_l\\<delta> = qtable_l\\<delta>\\<kappa>[OF _ _ _ ok_lctxt.intros(1), unfolded lpd\\<kappa>_lpd image_id id_apply]\n\nlemma RPD_fv_regex_le:\n  \"ms \\<in> RPD mr \\<Longrightarrow> fv_regex (from_mregex ms \\<phi>s) \\<subseteq> fv_regex (from_mregex mr \\<phi>s)\"\n  by (induct mr arbitrary: ms) (auto simp: MTimesL_def split: nat.splits)+\n\nlemma RPD_safe: \"safe_regex Past g (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> RPD mr \\<Longrightarrow> safe_regex Past g (from_mregex ms \\<phi>s)\"\nproof (induct Past g \"from_mregex mr \\<phi>s\" arbitrary: mr ms rule: safe_regex_induct)\n  case Skip\n  then show ?case\n    by (cases mr) (auto split: nat.splits)\nnext\n  case (Test g \\<phi>)\n  then show ?case\n    by (cases mr) auto\nnext\n  case (Plus g r s mrs)\n  then show ?case\n  proof (cases mrs)\n    case (MPlus mr ms)\n    with Plus(3-5) show ?thesis\n      by (auto dest!: Plus(1,2))\n  qed auto\nnext\n  case (TimesP g r s mrs)\n  then show ?case\n  proof (cases mrs)\n    case (MTimes mr ms)\n    with TimesP(3-5) show ?thesis\n      by (cases g) (auto 0 4 simp: MTimesL_def dest: RPD_fv_regex_le TimesP(1,2))\n  qed auto\nnext\n  case (Star g r)\n  then show ?case\n  proof (cases mr)\n    case (MStar x6)\n    with Star(2-4) show ?thesis\n      by (cases g) (auto 0 4 simp: MTimesL_def dest: RPD_fv_regex_le\n          elim!: safe_cosafe[rotated] dest!: Star(1))\n  qed auto\nqed\n\nlemma RPDi_safe: \"safe_regex Past g (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> RPDi n mr ==> safe_regex Past g (from_mregex ms \\<phi>s)\"\n  by (induct n arbitrary: ms mr) (auto dest: RPD_safe)\n\nlemma RPDs_safe: \"safe_regex Past g (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> RPDs mr ==> safe_regex Past g (from_mregex ms \\<phi>s)\"\n  unfolding RPDs_def by (auto dest: RPDi_safe)\n\nlemma RPD_safe_fv_regex: \"safe_regex Past Strict (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> RPD mr \\<Longrightarrow> fv_regex (from_mregex ms \\<phi>s) = fv_regex (from_mregex mr \\<phi>s)\"\nproof (induct Past Strict \"from_mregex mr \\<phi>s\" arbitrary: mr rule: safe_regex_induct)\n  case (Skip n)\n  then show ?case\n    by (cases mr) (auto split: nat.splits)\nnext\n  case (Test \\<phi>)\n  then show ?case\n    by (cases mr) auto\nnext\n  case (Plus r s)\n  then show ?case\n    by (cases mr) auto\nnext\n  case (TimesP r s)\n  then show ?case\n    by (cases mr) (auto 0 3 simp: MTimesL_def dest: RPD_fv_regex_le split: modality.splits)\nnext\n  case (Star r)\n  then show ?case\n    by (cases mr) (auto 0 3 simp: MTimesL_def dest: RPD_fv_regex_le)\nqed\n\nlemma RPDi_safe_fv_regex: \"safe_regex Past Strict (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> RPDi n mr ==> fv_regex (from_mregex ms \\<phi>s) = fv_regex (from_mregex mr \\<phi>s)\"\n  by (induct n arbitrary: ms mr) (auto 5 0 dest: RPD_safe_fv_regex RPD_safe)\n\nlemma RPDs_safe_fv_regex: \"safe_regex Past Strict (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> RPDs mr ==> fv_regex (from_mregex ms \\<phi>s) = fv_regex (from_mregex mr \\<phi>s)\"\n  unfolding RPDs_def by (auto dest: RPDi_safe_fv_regex)\n\nlemma RPD_ok: \"ok m mr \\<Longrightarrow> ms \\<in> RPD mr \\<Longrightarrow> ok m ms\"\nproof (induct mr arbitrary: ms)\n  case (MPlus mr1 mr2)\n  from MPlus(3,4) show ?case\n    by (auto elim: MPlus(1,2))\nnext\n  case (MTimes mr1 mr2)\n  from MTimes(3,4) show ?case\n    by (auto elim: MTimes(1,2) simp: MTimesL_def)\nnext\n  case (MStar mr)\n  from MStar(2,3) show ?case\n    by (auto elim: MStar(1) simp: MTimesL_def)\nqed (auto split: nat.splits)\n\nlemma RPDi_ok: \"ok m mr \\<Longrightarrow> ms \\<in> RPDi n mr \\<Longrightarrow> ok m ms\"\n  by (induct n arbitrary: ms mr) (auto intro: RPD_ok)\n\nlemma RPDs_ok: \"ok m mr \\<Longrightarrow> ms \\<in> RPDs mr \\<Longrightarrow> ok m ms\"\n  unfolding RPDs_def by (auto intro: RPDi_ok)\n\nlemma LPD_fv_regex_le:\n  \"ms \\<in> LPD mr \\<Longrightarrow> fv_regex (from_mregex ms \\<phi>s) \\<subseteq> fv_regex (from_mregex mr \\<phi>s)\"\n  by (induct mr arbitrary: ms) (auto simp: MTimesR_def split: nat.splits)+\n\nlemma LPD_safe: \"safe_regex Futu g (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> LPD mr ==> safe_regex Futu g (from_mregex ms \\<phi>s)\"\nproof (induct Futu g \"from_mregex mr \\<phi>s\" arbitrary: mr ms rule: safe_regex_induct)\n  case Skip\n  then show ?case\n    by (cases mr) (auto split: nat.splits)\nnext\n  case (Test g \\<phi>)\n  then show ?case\n    by (cases mr) auto\nnext\n  case (Plus g r s mrs)\n  then show ?case\n  proof (cases mrs)\n    case (MPlus mr ms)\n    with Plus(3-5) show ?thesis\n      by (auto dest!: Plus(1,2))\n  qed auto\nnext\n  case (TimesF g r s mrs)\n  then show ?case\n  proof (cases mrs)\n    case (MTimes mr ms)\n    with TimesF(3-5) show ?thesis\n      by (cases g) (auto 0 4 simp: MTimesR_def dest: LPD_fv_regex_le split: modality.splits dest: TimesF(1,2))\n  qed auto\nnext\n  case (Star g r)\n  then show ?case\n  proof (cases mr)\n    case (MStar x6)\n    with Star(2-4) show ?thesis\n      by (cases g) (auto 0 4 simp: MTimesR_def dest: LPD_fv_regex_le\n          elim!: safe_cosafe[rotated] dest!: Star(1))\n  qed auto\nqed\n\nlemma LPDi_safe: \"safe_regex Futu g (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> LPDi n mr ==> safe_regex Futu g (from_mregex ms \\<phi>s)\"\n  by (induct n arbitrary: ms mr) (auto dest: LPD_safe)\n\nlemma LPDs_safe: \"safe_regex Futu g (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> LPDs mr ==> safe_regex Futu g (from_mregex ms \\<phi>s)\"\n  unfolding LPDs_def by (auto dest: LPDi_safe)\n\nlemma LPD_safe_fv_regex: \"safe_regex Futu Strict (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> LPD mr ==> fv_regex (from_mregex ms \\<phi>s) = fv_regex (from_mregex mr \\<phi>s)\"\nproof (induct Futu Strict \"from_mregex mr \\<phi>s\" arbitrary: mr rule: safe_regex_induct)\n  case Skip\n  then show ?case\n    by (cases mr) (auto split: nat.splits)\nnext\n  case (Test \\<phi>)\n  then show ?case\n    by (cases mr) auto\nnext\n  case (Plus r s)\n  then show ?case\n    by (cases mr) auto\nnext\n  case (TimesF r s)\n  then show ?case\n    by (cases mr) (auto 0 3 simp: MTimesR_def dest: LPD_fv_regex_le split: modality.splits)\nnext\n  case (Star r)\n  then show ?case\n    by (cases mr) (auto 0 3 simp: MTimesR_def dest: LPD_fv_regex_le)\nqed\n\nlemma LPDi_safe_fv_regex: \"safe_regex Futu Strict (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> LPDi n mr ==> fv_regex (from_mregex ms \\<phi>s) = fv_regex (from_mregex mr \\<phi>s)\"\n  by (induct n arbitrary: ms mr) (auto 5 0 dest: LPD_safe_fv_regex LPD_safe)\n\nlemma LPDs_safe_fv_regex: \"safe_regex Futu Strict (from_mregex mr \\<phi>s) \\<Longrightarrow>\n  ms \\<in> LPDs mr ==> fv_regex (from_mregex ms \\<phi>s) = fv_regex (from_mregex mr \\<phi>s)\"\n  unfolding LPDs_def by (auto dest: LPDi_safe_fv_regex)\n\nlemma LPD_ok: \"ok m mr \\<Longrightarrow> ms \\<in> LPD mr \\<Longrightarrow> ok m ms\"\nproof (induct mr arbitrary: ms)\n  case (MPlus mr1 mr2)\n  from MPlus(3,4) show ?case\n    by (auto elim: MPlus(1,2))\nnext\n  case (MTimes mr1 mr2)\n  from MTimes(3,4) show ?case\n    by (auto elim: MTimes(1,2) simp: MTimesR_def)\nnext\n  case (MStar mr)\n  from MStar(2,3) show ?case\n    by (auto elim: MStar(1) simp: MTimesR_def)\nqed (auto split: nat.splits)\n\nlemma LPDi_ok: \"ok m mr \\<Longrightarrow> ms \\<in> LPDi n mr \\<Longrightarrow> ok m ms\"\n  by (induct n arbitrary: ms mr) (auto intro: LPD_ok)\n\nlemma LPDs_ok: \"ok m mr \\<Longrightarrow> ms \\<in> LPDs mr \\<Longrightarrow> ok m ms\"\n  unfolding LPDs_def by (auto intro: LPDi_ok)\n\nlemma update_matchP:\n  assumes pre: \"wf_matchP_aux \\<sigma> V n R I r aux ne\"\n    and safe: \"safe_regex Past Strict r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (RPDs mr)\"\n    and qtables: \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne \\<phi>) rel) \\<phi>s rels\"\n    and result_eq: \"(rel, aux') = update_matchP n I mr mrs rels (\\<tau> \\<sigma> ne) aux\"\n  shows \"wf_matchP_aux \\<sigma> V n R I r aux' (Suc ne)\"\n    and \"qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne (Formula.MatchP I r)) rel\"\nproof -\n  let ?wf_tuple = \"\\<lambda>v. wf_tuple n (Formula.fv_regex r) v\"\n  let ?update = \"\\<lambda>rel t. mrtabulate mrs (\\<lambda>mr.\n    r\\<delta> id rel rels mr \\<union> (if t = \\<tau> \\<sigma> ne then r\\<epsilon>_strict n rels mr else {}))\"\n  note sat.simps[simp del]\n\n  define aux0 where \"aux0 = [(t, ?update rel t). (t, rel) \\<leftarrow> aux, enat (\\<tau> \\<sigma> ne - t) \\<le> right I]\"\n  have sorted_aux0: \"sorted_wrt (\\<lambda>x y. fst x > fst y) aux0\"\n    using pre[unfolded wf_matchP_aux_def, THEN conjunct1]\n    unfolding aux0_def\n    by (induction aux) (auto simp add: sorted_wrt_append)\n  { fix ms\n    assume \"ms \\<in> RPDs mr\"\n    then have \"fv_regex (from_mregex ms \\<phi>s) = fv_regex r\"\n      \"safe_regex Past Strict (from_mregex ms \\<phi>s)\" \"ok (length \\<phi>s) ms\" \"RPD ms \\<subseteq> RPDs mr\"\n      using safe RPDs_safe RPDs_safe_fv_regex mr from_mregex_to_mregex RPDs_ok to_mregex_ok RPDs_trans\n      by fastforce+\n  } note * = this\n  have **: \"\\<tau> \\<sigma> ne - (\\<tau> \\<sigma> i + \\<tau> \\<sigma> ne - \\<tau> \\<sigma> (ne - Suc 0)) = \\<tau> \\<sigma> (ne - Suc 0) - \\<tau> \\<sigma> i\" for i\n    by (metis (no_types, lifting) Nat.diff_diff_right \\<tau>_mono add.commute add_diff_cancel_left diff_le_self le_add2 order_trans)\n  have ***: \"\\<tau> \\<sigma> i = \\<tau> \\<sigma> ne\"\n    if  \"\\<tau> \\<sigma> ne \\<le> \\<tau> \\<sigma> i\" \"\\<tau> \\<sigma> i \\<le> \\<tau> \\<sigma> (ne - Suc 0)\" \"ne > 0\" for i\n    by (metis (no_types, lifting) Suc_pred \\<tau>_mono diff_le_self le_\\<tau>_less le_antisym not_less_eq that)\n  then have in_aux0_1: \"(t, X) \\<in> set aux0 \\<Longrightarrow> ne \\<noteq> 0 \\<and> t \\<le> \\<tau> \\<sigma> ne \\<and> \\<tau> \\<sigma> ne - t \\<le> right I \\<and>\n      (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n      (\\<forall>ms\\<in>RPDs mr. qtable n (fv_regex r) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne\n         (Formula.MatchP (point (\\<tau> \\<sigma> ne - t)) (from_mregex ms \\<phi>s))) (lookup X ms))\" for t X\n    unfolding aux0_def using safe mr mrs\n    by (auto simp: lookup_tabulate map_of_map_restrict restrict_map_def finite_RPDs * ** RPDs_trans diff_le_mono2\n        intro!: sat_MatchP_rec[of \\<sigma> _ _ ne, THEN iffD2]\n        qtable_union[OF qtable_r\\<delta>[OF _ _ qtables] qtable_r\\<epsilon>_strict[OF _ _ _ qtables],\n          of ms \"fv_regex r\" \"\\<lambda>v r. Formula.sat \\<sigma> V v (ne - Suc 0) (Formula.MatchP (point 0) r)\" _ ms for ms]\n        qtable_cong[OF qtable_r\\<delta>[OF _ _ qtables],\n          of ms \"fv_regex r\" \"\\<lambda>v r. Formula.sat \\<sigma> V v (ne - Suc 0) (Formula.MatchP (point (\\<tau> \\<sigma> (ne - Suc 0) - \\<tau> \\<sigma> i)) r)\"\n          _ _  \"(\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne (Formula.MatchP (point (\\<tau> \\<sigma> ne - \\<tau> \\<sigma> i))  (from_mregex ms \\<phi>s)))\" for ms i]\n        dest!: assms(1)[unfolded wf_matchP_aux_def, THEN conjunct2, THEN conjunct1, rule_format]\n        sat_MatchP_rec[\"of\" \\<sigma> _ _ ne, THEN iffD1]\n        elim!: bspec order.trans[OF _ \\<tau>_mono] bexI[rotated] split: option.splits if_splits) (* slow 7 sec *)\n  then have in_aux0_le_\\<tau>: \"(t, X) \\<in> set aux0 \\<Longrightarrow> t \\<le> \\<tau> \\<sigma> ne\" for t X\n    by (meson \\<tau>_mono diff_le_self le_trans)\n  have in_aux0_2: \"ne \\<noteq> 0 \\<Longrightarrow> t \\<le> \\<tau> \\<sigma> (ne-1) \\<Longrightarrow> \\<tau> \\<sigma> ne - t \\<le> right I \\<Longrightarrow> \\<exists>i. \\<tau> \\<sigma> i = t \\<Longrightarrow>\n    \\<exists>X. (t, X) \\<in> set aux0\" for t\n  proof -\n    fix t\n    assume \"ne \\<noteq> 0\" \"t \\<le> \\<tau> \\<sigma> (ne-1)\" \"\\<tau> \\<sigma> ne - t \\<le> right I\" \"\\<exists>i. \\<tau> \\<sigma> i = t\"\n    then obtain X where \"(t, X) \\<in> set aux\"\n      by (atomize_elim, intro assms(1)[unfolded wf_matchP_aux_def, THEN conjunct2, THEN conjunct2, rule_format])\n        (auto simp: gr0_conv_Suc elim!: order_trans[rotated] intro!: diff_le_mono \\<tau>_mono)\n    with \\<open>\\<tau> \\<sigma> ne - t \\<le> right I\\<close> have \"(t, ?update X t) \\<in> set aux0\"\n      unfolding aux0_def by (auto simp: id_def elim!: bexI[rotated] intro!: exI[of _ X])\n    then show \"\\<exists>X. (t, X) \\<in> set aux0\"\n      by blast\n  qed\n  have aux0_Nil: \"aux0 = [] \\<Longrightarrow> ne = 0 \\<or> ne \\<noteq> 0 \\<and> (\\<forall>t. t \\<le> \\<tau> \\<sigma> (ne-1) \\<and> \\<tau> \\<sigma> ne - t \\<le> right I \\<longrightarrow>\n        (\\<nexists>i. \\<tau> \\<sigma> i = t))\"\n    using in_aux0_2 by (cases \"ne = 0\") (auto)\n\n  have aux'_eq: \"aux' = (case aux0 of\n      [] \\<Rightarrow> [(\\<tau> \\<sigma> ne, mrtabulate mrs (r\\<epsilon>_strict n rels))]\n    | x # aux' \\<Rightarrow> (if fst x = \\<tau> \\<sigma> ne then x # aux'\n       else (\\<tau> \\<sigma> ne, mrtabulate mrs (r\\<epsilon>_strict n rels)) # x # aux'))\"\n    using result_eq unfolding aux0_def update_matchP_def Let_def by simp\n  have sorted_aux': \"sorted_wrt (\\<lambda>x y. fst x > fst y) aux'\"\n    unfolding aux'_eq\n    using sorted_aux0 in_aux0_le_\\<tau> by (cases aux0) (fastforce)+\n\n  have in_aux'_1: \"t \\<le> \\<tau> \\<sigma> ne \\<and> \\<tau> \\<sigma> ne - t \\<le> right I \\<and> (\\<exists>i. \\<tau> \\<sigma> i = t) \\<and>\n     (\\<forall>ms\\<in>RPDs mr. qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v.\n        Formula.sat \\<sigma> V (map the v) ne (Formula.MatchP (point (\\<tau> \\<sigma> ne - t)) (from_mregex ms \\<phi>s))) (lookup X ms))\"\n    if aux': \"(t, X) \\<in> set aux'\" for t X\n  proof (cases aux0)\n    case Nil\n    with aux' show ?thesis\n      unfolding aux'_eq using safe mrs qtables aux0_Nil *\n      by (auto simp: zero_enat_def[symmetric] sat_MatchP_rec[where i=ne]\n          lookup_tabulate finite_RPDs split: option.splits\n          intro!: qtable_cong[OF qtable_r\\<epsilon>_strict]\n          dest: spec[of _ \"\\<tau> \\<sigma> (ne-1)\"])\n  next\n    case (Cons a as)\n    show ?thesis\n    proof (cases \"t = \\<tau> \\<sigma> ne\")\n      case t: True\n      show ?thesis\n      proof (cases \"fst a = \\<tau> \\<sigma> ne\")\n        case True\n        with aux' Cons t have \"X = snd a\"\n          unfolding aux'_eq using sorted_aux0 by auto\n        moreover from in_aux0_1[of \"fst a\" \"snd a\"] Cons have \"ne \\<noteq> 0\"\n          \"fst a \\<le> \\<tau> \\<sigma> ne\" \"\\<tau> \\<sigma> ne - fst a \\<le> right I\" \"\\<exists>i. \\<tau> \\<sigma> i = fst a\"\n          \"\\<forall>ms \\<in> RPDs mr. qtable n (fv_regex r) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne\n            (Formula.MatchP (point (\\<tau> \\<sigma> ne - fst a)) (from_mregex ms \\<phi>s))) (lookup (snd a) ms)\"\n          by auto\n        ultimately show ?thesis using t True\n          by auto\n      next\n        case False\n        with aux' Cons t have \"X = mrtabulate mrs (r\\<epsilon>_strict n rels)\"\n          unfolding aux'_eq using sorted_aux0 in_aux0_le_\\<tau>[of \"fst a\" \"snd a\"] by auto\n        with aux' Cons t False show ?thesis\n          unfolding aux'_eq using safe mrs qtables * in_aux0_2[of \"\\<tau> \\<sigma> (ne-1)\"] in_aux0_le_\\<tau>[of \"fst a\" \"snd a\"] sorted_aux0\n          by (auto simp: sat_MatchP_rec[where i=ne] zero_enat_def[symmetric] enat_0_iff not_le\n              lookup_tabulate finite_RPDs split: option.splits\n              intro!: qtable_cong[OF qtable_r\\<epsilon>_strict] dest!: le_\\<tau>_less meta_mp)\n      qed\n    next\n      case False\n      with aux' Cons have \"(t, X) \\<in> set aux0\"\n        unfolding aux'_eq by (auto split: if_splits)\n      then have \"ne \\<noteq> 0\" \"t \\<le> \\<tau> \\<sigma> ne\" \"\\<tau> \\<sigma> ne - t \\<le> right I\" \"\\<exists>i. \\<tau> \\<sigma> i = t\"\n        \"\\<forall>ms \\<in> RPDs mr. qtable n (fv_regex r) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne\n          (Formula.MatchP (point (\\<tau> \\<sigma> ne - t)) (from_mregex ms \\<phi>s))) (lookup X ms)\"\n        using in_aux0_1 by blast+\n      with False aux' Cons show ?thesis\n        unfolding aux'_eq by auto\n    qed\n  qed\n\n  have in_aux'_2: \"\\<exists>X. (t, X) \\<in> set aux'\" if \"t \\<le> \\<tau> \\<sigma> ne\" \"\\<tau> \\<sigma> ne - t \\<le> right I\" \"\\<exists>i. \\<tau> \\<sigma> i = t\" for t\n  proof (cases \"t = \\<tau> \\<sigma> ne\")\n    case True\n    then show ?thesis\n    proof (cases aux0)\n      case Nil\n      with True show ?thesis unfolding aux'_eq by simp\n    next\n      case (Cons a as)\n      with True show ?thesis unfolding aux'_eq using eq_fst_iff[of t a]\n        by (cases \"fst a = \\<tau> \\<sigma> ne\") auto\n    qed\n  next\n    case False\n    with that have \"ne \\<noteq> 0\"\n      using le_\\<tau>_less neq0_conv by blast\n    moreover from False that have  \"t \\<le> \\<tau> \\<sigma> (ne-1)\"\n      by (metis One_nat_def Suc_leI Suc_pred \\<tau>_mono diff_is_0_eq' order.antisym neq0_conv not_le)\n    ultimately obtain X where \"(t, X) \\<in> set aux0\" using \\<open>\\<tau> \\<sigma> ne - t \\<le> right I\\<close> \\<open>\\<exists>i. \\<tau> \\<sigma> i = t\\<close>\n      by atomize_elim (auto intro!: in_aux0_2)\n    then show ?thesis unfolding aux'_eq using False\n      by (auto intro: exI[of _ X] split: list.split)\n  qed\n\n  show \"wf_matchP_aux \\<sigma> V n R I r aux' (Suc ne)\"\n    unfolding wf_matchP_aux_def using mr\n    by (auto dest: in_aux'_1 intro: sorted_aux' in_aux'_2)\n\n  have rel_eq: \"rel = foldr (\\<union>) [lookup rel mr. (t, rel) \\<leftarrow> aux', left I \\<le> \\<tau> \\<sigma> ne - t] {}\"\n    unfolding aux'_eq aux0_def\n    using result_eq by (simp add: update_matchP_def Let_def)\n  have rel_alt: \"rel = (\\<Union>(t, rel) \\<in> set aux'. if left I \\<le> \\<tau> \\<sigma> ne - t then lookup rel mr else empty_table)\"\n    unfolding rel_eq\n    by (auto elim!: in_foldr_UnE bexI[rotated] intro!: in_foldr_UnI)\n  show \"qtable n (fv_regex r) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) ne (Formula.MatchP I r)) rel\"\n    unfolding rel_alt\n  proof (rule qtable_Union[where Qi=\"\\<lambda>(t, X) v.\n    left I \\<le> \\<tau> \\<sigma> ne - t \\<and> Formula.sat \\<sigma> V (map the v) ne (Formula.MatchP (point (\\<tau> \\<sigma> ne - t)) r)\"],\n        goal_cases finite qtable equiv)\n    case (equiv v)\n    show ?case\n    proof (rule iffI, erule sat_MatchP_point, goal_cases left right)\n      case (left j)\n      then show ?case using in_aux'_2[of \"\\<tau> \\<sigma> j\", OF _ _ exI, OF _ _ refl] by auto\n    next\n      case right\n      then show ?case by (auto elim!: sat_MatchP_pointD dest: in_aux'_1)\n    qed\n  qed (auto dest!: in_aux'_1 intro!: qtable_empty dest!: bspec[OF _ RPDs_refl]\n      simp: from_mregex_eq[OF safe mr])\nqed\n\nlemma length_update_until: \"length (update_until args rel1 rel2 nt aux) = Suc (length aux)\"\n  unfolding update_until_def by simp\n\nlemma wf_update_until_auxlist:\n  assumes pre: \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> auxlist ne\"\n    and qtable1: \"qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne + length auxlist) \\<phi>) rel1\"\n    and qtable2: \"qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne + length auxlist) \\<psi>) rel2\"\n    and fvi_subset: \"Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi>\"\n    and args_ivl: \"args_ivl args = I\"\n    and args_n: \"args_n args = n\"\n    and args_pos: \"args_pos args = pos\"\n  shows \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> (update_until args rel1 rel2 (\\<tau> \\<sigma> (ne + length auxlist)) auxlist) ne\"\n  unfolding wf_until_auxlist_def length_update_until\n  unfolding update_until_def list.rel_map add_Suc_right upt.simps eqTrueI[OF le_add1] if_True\nproof (rule list_all2_appendI, unfold list.rel_map, goal_cases old new)\n  case old\n  show ?case\n  proof (rule list.rel_mono_strong[OF assms(1)[unfolded wf_until_auxlist_def]]; safe, goal_cases mono1 mono2)\n    case (mono1 i X Y v)\n    then show ?case\n      by (fastforce simp: args_ivl args_n args_pos sat_the_restrict less_Suc_eq\n          elim!: qtable_join[OF _ qtable1] qtable_union[OF _ qtable1])\n  next\n    case (mono2 i X Y v)\n    then show ?case using fvi_subset\n      by (auto 0 3 simp: args_ivl args_n args_pos sat_the_restrict less_Suc_eq split: if_splits\n          elim!: qtable_union[OF _ qtable_join_fixed[OF qtable2]]\n          elim: qtable_cong[OF _ refl] intro: exI[of _ \"ne + length auxlist\"]) (* slow 8 sec*)\n  qed\nnext\n  case new\n  then show ?case\n    by (auto intro!: qtable_empty qtable1 qtable2[THEN qtable_cong] exI[of _ \"ne + length auxlist\"]\n        simp: args_ivl args_n args_pos less_Suc_eq zero_enat_def[symmetric])\nqed\n\nlemma (in muaux) wf_update_until:\n  assumes pre: \"wf_until_aux \\<sigma> V R args \\<phi> \\<psi> aux ne\"\n    and qtable1: \"qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne + length_muaux args aux) \\<phi>) rel1\"\n    and qtable2: \"qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne + length_muaux args aux) \\<psi>) rel2\"\n    and fvi_subset: \"Formula.fv \\<phi> \\<subseteq> Formula.fv \\<psi>\"\n    and args_ivl: \"args_ivl args = I\"\n    and args_n: \"args_n args = n\"\n    and args_L: \"args_L args = Formula.fv \\<phi>\"\n    and args_R: \"args_R args = Formula.fv \\<psi>\"\n    and args_pos: \"args_pos args = pos\"\n  shows \"wf_until_aux \\<sigma> V R args \\<phi> \\<psi> (add_new_muaux args rel1 rel2 (\\<tau> \\<sigma> (ne + length_muaux args aux)) aux) ne \\<and>\n      length_muaux args (add_new_muaux args rel1 rel2 (\\<tau> \\<sigma> (ne + length_muaux args aux)) aux) = Suc (length_muaux args aux)\"\nproof -\n  from pre obtain cur auxlist where valid_aux: \"valid_muaux args cur aux auxlist\" and\n    cur: \"cur = (if ne + length auxlist = 0 then 0 else \\<tau> \\<sigma> (ne + length auxlist - 1))\" and\n    pre_list: \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> auxlist ne\"\n    unfolding wf_until_aux_def args_ivl args_n args_pos by auto\n  have length_aux: \"length_muaux args aux = length auxlist\"\n    using valid_length_muaux[OF valid_aux] .\n  define nt where \"nt \\<equiv> \\<tau> \\<sigma> (ne + length_muaux args aux)\"\n  have nt_mono: \"cur \\<le> nt\"\n    unfolding cur nt_def length_aux by simp\n  define auxlist' where \"auxlist' \\<equiv> update_until args rel1 rel2 (\\<tau> \\<sigma> (ne + length auxlist)) auxlist\"\n  have length_auxlist': \"length auxlist' = Suc (length auxlist)\"\n    unfolding auxlist'_def by (auto simp add: length_update_until)\n  have tab1: \"table (args_n args) (args_L args) rel1\"\n    using qtable1 unfolding args_n[symmetric] args_L[symmetric] by (auto simp add: qtable_def)\n  have tab2: \"table (args_n args) (args_R args) rel2\"\n    using qtable2 unfolding args_n[symmetric] args_R[symmetric] by (auto simp add: qtable_def)\n  have fv_sub: \"fv \\<phi> \\<subseteq> fv \\<psi>\"\n    using pre unfolding wf_until_aux_def by auto\n  moreover have valid_add_new_auxlist: \"valid_muaux args nt (add_new_muaux args rel1 rel2 nt aux) auxlist'\"\n    using valid_add_new_muaux[OF valid_aux tab1 tab2 nt_mono]\n    unfolding auxlist'_def nt_def length_aux .\n  moreover have \"length_muaux args (add_new_muaux args rel1 rel2 nt aux) = Suc (length_muaux args aux)\"\n    using valid_length_muaux[OF valid_add_new_auxlist] unfolding length_auxlist' length_aux[symmetric] .\n  moreover have \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> auxlist' ne\"\n    using wf_update_until_auxlist[OF pre_list qtable1[unfolded length_aux] qtable2[unfolded length_aux] fv_sub args_ivl args_n args_pos]\n    unfolding auxlist'_def .\n  moreover have \"\\<tau> \\<sigma> (ne + length auxlist) = (if ne + length auxlist' = 0 then 0 else \\<tau> \\<sigma> (ne + length auxlist' - 1))\"\n    unfolding cur length_auxlist' by auto\n  ultimately show ?thesis\n    unfolding wf_until_aux_def nt_def length_aux args_ivl args_n args_pos by fast\nqed\n\nlemma length_update_matchF_base:\n  \"length (fst (update_matchF_base I mr mrs nt entry st)) = Suc 0\"\n  by (auto simp: Let_def update_matchF_base_def)\n\nlemma length_update_matchF_step:\n  \"length (fst (update_matchF_step I mr mrs nt entry st)) = Suc (length (fst st))\"\n  by (auto simp: Let_def update_matchF_step_def split: prod.splits)\n\nlemma length_foldr_update_matchF_step:\n  \"length (fst (foldr (update_matchF_step I mr mrs nt) aux base)) = length aux + length (fst base)\"\n  by (induct aux arbitrary: base) (auto simp: Let_def length_update_matchF_step)\n\nlemma length_update_matchF: \"length (update_matchF n I mr mrs rels nt aux) = Suc (length aux)\"\n  unfolding update_matchF_def update_matchF_base_def length_foldr_update_matchF_step\n  by (auto simp: Let_def)\n\nlemma wf_update_matchF_base_invar:\n  assumes safe: \"safe_regex Futu Strict r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (LPDs mr)\"\n    and qtables: \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) j \\<phi>) rel) \\<phi>s rels\"\n  shows \"wf_matchF_invar \\<sigma> V n R I r (update_matchF_base n I mr mrs rels (\\<tau> \\<sigma> j)) j\"\nproof -\n  have from_mregex: \"from_mregex mr \\<phi>s = r\"\n    using safe mr using from_mregex_eq by blast\n  { fix ms\n    assume \"ms \\<in> LPDs mr\"\n    then have \"fv_regex (from_mregex ms \\<phi>s) = fv_regex r\"\n      \"safe_regex Futu Strict (from_mregex ms \\<phi>s)\" \"ok (length \\<phi>s) ms\" \"LPD ms \\<subseteq> LPDs mr\"\n      using safe LPDs_safe LPDs_safe_fv_regex mr from_mregex_to_mregex LPDs_ok to_mregex_ok LPDs_trans\n      by fastforce+\n  } note * = this\n  show ?thesis\n    unfolding wf_matchF_invar_def wf_matchF_aux_def update_matchF_base_def mr prod.case Let_def mrs\n    using safe\n    by (auto simp: * from_mregex qtables qtable_empty_iff zero_enat_def[symmetric]\n        lookup_tabulate finite_LPDs eps_match less_Suc_eq LPDs_refl\n        intro!: qtable_cong[OF qtable_l\\<epsilon>_strict[where \\<phi>s=\\<phi>s]] intro: qtables exI[of _ j]\n        split: option.splits)\nqed\n\nlemma Un_empty_table[simp]: \"rel \\<union> empty_table = rel\" \"empty_table \\<union> rel = rel\"\n  unfolding empty_table_def by auto\n\nlemma wf_matchF_invar_step:\n  assumes wf: \"wf_matchF_invar \\<sigma> V n R I r st (Suc i)\"\n    and safe: \"safe_regex Futu Strict r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (LPDs mr)\"\n    and qtables: \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>) rel) \\<phi>s rels\"\n    and rel: \"qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v. (\\<exists>j. i \\<le> j \\<and> j < i + length (fst st) \\<and> mem (\\<tau> \\<sigma> j - \\<tau> \\<sigma> i) I \\<and>\n          Regex.match (Formula.sat \\<sigma> V (map the v)) r i j)) rel\"\n    and entry: \"entry = (\\<tau> \\<sigma> i, rels, rel)\"\n    and nt: \"nt = \\<tau> \\<sigma> (i + length (fst st))\"\n  shows \"wf_matchF_invar \\<sigma> V n R I r (update_matchF_step I mr mrs nt entry st) i\"\nproof -\n  have from_mregex: \"from_mregex mr \\<phi>s = r\"\n    using safe mr using from_mregex_eq by blast\n  { fix ms\n    assume \"ms \\<in> LPDs mr\"\n    then have \"fv_regex (from_mregex ms \\<phi>s) = fv_regex r\"\n      \"safe_regex Futu Strict (from_mregex ms \\<phi>s)\" \"ok (length \\<phi>s) ms\" \"LPD ms \\<subseteq> LPDs mr\"\n      using safe LPDs_safe LPDs_safe_fv_regex mr from_mregex_to_mregex LPDs_ok to_mregex_ok LPDs_trans\n      by fastforce+\n  } note * = this\n  { fix aux X ms\n    assume \"st = (aux, X)\" \"ms \\<in> LPDs mr\"\n    with wf mr have \"qtable n (fv_regex r) (mem_restr R)\n      (\\<lambda>v. Regex.match (Formula.sat \\<sigma> V (map the v)) (from_mregex ms \\<phi>s) i (i + length aux))\n      (l\\<delta> (\\<lambda>x. x) X rels ms)\"\n      by (intro qtable_cong[OF qtable_l\\<delta>[where \\<phi>s=\\<phi>s and A=\"fv_regex r\" and\n              Q=\"\\<lambda>v r. Regex.match (Formula.sat \\<sigma> V v) r (Suc i) (i + length aux)\", OF _ _ qtables]])\n        (auto simp: wf_matchF_invar_def * LPDs_trans lpd_match[of i] elim!: bspec)\n  } note l\\<delta> = this\n  have \"lookup (mrtabulate mrs f) ms = f ms\" if \"ms \\<in> LPDs mr\" for ms and f :: \"mregex \\<Rightarrow> 'a table\"\n    using that mrs  by (fastforce simp: lookup_tabulate finite_LPDs split: option.splits)+\n  then show ?thesis\n    using wf mr mrs entry nt LPDs_trans\n    by (auto 0 3 simp: Let_def wf_matchF_invar_def update_matchF_step_def wf_matchF_aux_def mr * LPDs_refl\n        list_all2_Cons1 append_eq_Cons_conv upt_eq_Cons_conv Suc_le_eq qtables\n        lookup_tabulate finite_LPDs id_def l\\<delta> from_mregex less_Suc_eq\n        intro!: qtable_union[OF rel l\\<delta>] qtable_cong[OF rel]\n        intro: exI[of _ \"i + length _\"]\n        split: if_splits prod.splits)\nqed\n\nlemma wf_update_matchF_invar:\n  assumes pre: \"wf_matchF_aux \\<sigma> V n R I r aux ne (length (fst st) - 1)\"\n    and wf: \"wf_matchF_invar \\<sigma> V n R I r st (ne + length aux)\"\n    and safe: \"safe_regex Futu Strict r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (LPDs mr)\"\n    and j: \"j = ne + length aux + length (fst st) - 1\"\n  shows \"wf_matchF_invar \\<sigma> V n R I r (foldr (update_matchF_step I mr mrs (\\<tau> \\<sigma> j)) aux st) ne\"\n  using pre wf unfolding j\nproof (induct aux arbitrary: ne)\n  case (Cons entry aux)\n  from Cons(1)[of \"Suc ne\"] Cons(2,3) show ?case\n    unfolding foldr.simps o_apply\n    by (intro wf_matchF_invar_step[where rels = \"fst (snd entry)\" and rel = \"snd (snd entry)\"])\n      (auto simp: safe mr mrs wf_matchF_aux_def wf_matchF_invar_def list_all2_Cons1 append_eq_Cons_conv\n        Suc_le_eq upt_eq_Cons_conv length_foldr_update_matchF_step add.assoc split: if_splits)\nqed simp\n\n\nlemma wf_update_matchF:\n  assumes pre: \"wf_matchF_aux \\<sigma> V n R I r aux ne 0\"\n    and safe: \"safe_regex Futu Strict r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (LPDs mr)\"\n    and nt: \"nt = \\<tau> \\<sigma> (ne + length aux)\"\n    and qtables: \"list_all2 (\\<lambda>\\<phi> rel. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) (ne + length aux) \\<phi>) rel) \\<phi>s rels\"\n  shows \"wf_matchF_aux \\<sigma> V n R I r (update_matchF n I mr mrs rels nt aux) ne 0\"\n  unfolding update_matchF_def using wf_update_matchF_base_invar[OF safe mr mrs qtables, of I]\n  unfolding nt\n  by (intro wf_update_matchF_invar[OF _ _ safe mr mrs, unfolded wf_matchF_invar_def split_beta, THEN conjunct2, THEN conjunct1])\n    (auto simp: length_update_matchF_base wf_matchF_invar_def update_matchF_base_def Let_def pre)\n\nlemma wf_until_aux_Cons: \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> (a # aux) ne \\<Longrightarrow>\n  wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> aux (Suc ne)\"\n  unfolding wf_until_auxlist_def\n  by (simp add: upt_conv_Cons del: upt_Suc cong: if_cong)\n\nlemma wf_matchF_aux_Cons: \"wf_matchF_aux \\<sigma> V n R I r (entry # aux) ne i \\<Longrightarrow>\n  wf_matchF_aux \\<sigma> V n R I r aux (Suc ne) i\"\n  unfolding wf_matchF_aux_def\n  by (simp add: upt_conv_Cons del: upt_Suc cong: if_cong split: prod.splits)\n\nlemma wf_until_aux_Cons1: \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> ((t, a1, a2) # aux) ne \\<Longrightarrow> t = \\<tau> \\<sigma> ne\"\n  unfolding wf_until_auxlist_def\n  by (simp add: upt_conv_Cons del: upt_Suc)\n\nlemma wf_matchF_aux_Cons1: \"wf_matchF_aux \\<sigma> V n R I r ((t, rels, rel) # aux) ne i \\<Longrightarrow> t = \\<tau> \\<sigma> ne\"\n  unfolding wf_matchF_aux_def\n  by (simp add: upt_conv_Cons del: upt_Suc split: prod.splits)\n\nlemma wf_until_aux_Cons3: \"wf_until_auxlist \\<sigma> V n R pos \\<phi> I \\<psi> ((t, a1, a2) # aux) ne \\<Longrightarrow>\n  qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. (\\<exists>j. ne \\<le> j \\<and> j < Suc (ne + length aux) \\<and> mem (\\<tau> \\<sigma> j - \\<tau> \\<sigma> ne) I \\<and>\n    Formula.sat \\<sigma> V (map the v) j \\<psi> \\<and> (\\<forall>k\\<in>{ne..<j}. if pos then Formula.sat \\<sigma> V (map the v) k \\<phi> else \\<not> Formula.sat \\<sigma> V (map the v) k \\<phi>))) a2\"\n  unfolding wf_until_auxlist_def\n  by (simp add: upt_conv_Cons del: upt_Suc)\n\nlemma wf_matchF_aux_Cons3: \"wf_matchF_aux \\<sigma> V n R I r ((t, rels, rel) # aux) ne i \\<Longrightarrow>\n  qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v. (\\<exists>j. ne \\<le> j \\<and> j < Suc (ne + length aux + i) \\<and> mem (\\<tau> \\<sigma> j - \\<tau> \\<sigma> ne) I \\<and>\n    Regex.match (Formula.sat \\<sigma> V (map the v)) r ne j)) rel\"\n  unfolding wf_matchF_aux_def\n  by (simp add: upt_conv_Cons del: upt_Suc split: prod.splits)\n\nlemma upt_append: \"a \\<le> b \\<Longrightarrow> b \\<le> c \\<Longrightarrow> [a..<b] @ [b..<c] = [a..<c]\"\n  by (metis le_Suc_ex upt_add_eq_append)\n\nlemma wf_mbuf2_add:\n  assumes \"wf_mbuf2 i ja jb P Q buf\"\n    and \"list_all2 P [ja..<ja'] xs\"\n    and \"list_all2 Q [jb..<jb'] ys\"\n    and \"ja \\<le> ja'\" \"jb \\<le> jb'\"\n  shows \"wf_mbuf2 i ja' jb' P Q (mbuf2_add xs ys buf)\"\n  using assms unfolding wf_mbuf2_def\n  by (auto 0 3 simp: list_all2_append2 upt_append dest: list_all2_lengthD\n      intro: exI[where x=\"[i..<ja]\"] exI[where x=\"[ja..<ja']\"]\n      exI[where x=\"[i..<jb]\"] exI[where x=\"[jb..<jb']\"] split: prod.splits)\n\nlemma wf_mbufn_add:\n  assumes \"wf_mbufn i js Ps buf\"\n    and \"list_all3 list_all2 Ps (List.map2 (\\<lambda>j j'. [j..<j']) js js') xss\"\n    and \"list_all2 (\\<le>) js js'\"\n  shows \"wf_mbufn i js' Ps (mbufn_add xss buf)\"\n  unfolding wf_mbufn_def list_all3_conv_all_nth\nproof safe\n  show \"length Ps = length js'\" \"length js' = length (mbufn_add xss buf)\"\n    using assms unfolding wf_mbufn_def list_all3_conv_all_nth list_all2_conv_all_nth by auto\nnext\n  fix k assume k: \"k < length Ps\"\n  then show \"i \\<le> js' ! k\"\n    using assms unfolding wf_mbufn_def list_all3_conv_all_nth list_all2_conv_all_nth\n    by (auto 0 4 dest: spec[of _ i])\n  from k have \" [i..<js' ! k] =  [i..<js ! k] @ [js ! k ..<js' ! k]\" and\n    \"length [i..<js ! k] = length (buf ! k)\"\n    using assms(1,3) unfolding wf_mbufn_def list_all3_conv_all_nth list_all2_conv_all_nth\n    by (auto simp: upt_append)\n  with k show \"list_all2 (Ps ! k) [i..<js' ! k] (mbufn_add xss buf ! k)\"\n    using assms[unfolded wf_mbufn_def list_all3_conv_all_nth]\n    by (auto simp add: list_all2_append)\nqed\n\nlemma mbuf2_take_eqD:\n  assumes \"mbuf2_take f buf = (xs, buf')\"\n    and \"wf_mbuf2 i ja jb P Q buf\"\n  shows \"wf_mbuf2 (min ja jb) ja jb P Q buf'\"\n    and \"list_all2 (\\<lambda>i z. \\<exists>x y. P i x \\<and> Q i y \\<and> z = f x y) [i..<min ja jb] xs\"\n  using assms unfolding wf_mbuf2_def\n  by (induction f buf arbitrary: i xs buf' rule: mbuf2_take.induct)\n    (fastforce simp add: list_all2_Cons2 upt_eq_Cons_conv min_absorb1 min_absorb2 split: prod.splits)+\n\nlemma list_all3_Nil[simp]:\n  \"list_all3 P xs ys [] \\<longleftrightarrow> xs = [] \\<and> ys = []\"\n  \"list_all3 P xs [] zs \\<longleftrightarrow> xs = [] \\<and> zs = []\"\n  \"list_all3 P [] ys zs \\<longleftrightarrow> ys = [] \\<and> zs = []\"\n  unfolding list_all3_conv_all_nth by auto\n\nlemma list_all3_Cons:\n  \"list_all3 P xs ys (z # zs) \\<longleftrightarrow> (\\<exists>x xs' y ys'. xs = x # xs' \\<and> ys = y # ys' \\<and> P x y z \\<and> list_all3 P xs' ys' zs)\"\n  \"list_all3 P xs (y # ys) zs \\<longleftrightarrow> (\\<exists>x xs' z zs'. xs = x # xs' \\<and> zs = z # zs' \\<and> P x y z \\<and> list_all3 P xs' ys zs')\"\n  \"list_all3 P (x # xs) ys zs \\<longleftrightarrow> (\\<exists>y ys' z zs'. ys = y # ys' \\<and> zs = z # zs' \\<and> P x y z \\<and> list_all3 P xs ys' zs')\"\n  unfolding list_all3_conv_all_nth\n  by (auto simp: length_Suc_conv Suc_length_conv nth_Cons split: nat.splits)\n\nlemma list_all3_mono_strong: \"list_all3 P xs ys zs \\<Longrightarrow>\n  (\\<And>x y z. x \\<in> set xs \\<Longrightarrow> y \\<in> set ys \\<Longrightarrow> z \\<in> set zs \\<Longrightarrow> P x y z \\<Longrightarrow> Q x y z) \\<Longrightarrow>\n  list_all3 Q xs ys zs\"\n  by (induct xs ys zs rule: list_all3.induct) (auto intro: list_all3.intros)\n\ndefinition Mini where\n  \"Mini i js = (if js = [] then i else Min (set js))\"\n\nlemma wf_mbufn_in_set_Mini:\n  assumes \"wf_mbufn i js Ps buf\"\n  shows \"[] \\<in> set buf \\<Longrightarrow> Mini i js = i\"\n  unfolding in_set_conv_nth\nproof (elim exE conjE)\n  fix k\n  have \"i \\<le> j\" if \"j \\<in> set js\" for j\n    using that assms unfolding wf_mbufn_def list_all3_conv_all_nth in_set_conv_nth by auto\n  moreover assume \"k < length buf\" \"buf ! k = []\"\n  ultimately show ?thesis using assms\n    unfolding Mini_def wf_mbufn_def list_all3_conv_all_nth\n    by (auto 0 4 dest!: spec[of _ k] intro: Min_eqI simp: in_set_conv_nth)\nqed\n\nlemma wf_mbufn_notin_set:\n  assumes \"wf_mbufn i js Ps buf\"\n  shows \"[] \\<notin> set buf \\<Longrightarrow> j \\<in> set js \\<Longrightarrow> i < j\"\n  using assms unfolding wf_mbufn_def list_all3_conv_all_nth\n  by (cases \"i \\<in> set js\") (auto intro: le_neq_implies_less simp: in_set_conv_nth)\n\nlemma wf_mbufn_map_tl:\n  \"wf_mbufn i js Ps buf \\<Longrightarrow> [] \\<notin> set buf \\<Longrightarrow> wf_mbufn (Suc i) js Ps (map tl buf)\"\n  by (auto simp: wf_mbufn_def list_all3_map Suc_le_eq\n      dest: rel_funD[OF tl_transfer]  elim!: list_all3_mono_strong le_neq_implies_less)\n\nlemma list_all3_list_all2I: \"list_all3 (\\<lambda>x y z. Q x z) xs ys zs \\<Longrightarrow> list_all2 Q xs zs\"\n  by (induct xs ys zs rule: list_all3.induct) auto\n\nlemma mbuf2t_take_eqD:\n  assumes \"mbuf2t_take f z buf nts = (z', buf', nts')\"\n    and \"wf_mbuf2 i ja jb P Q buf\"\n    and \"list_all2 R [i..<j] nts\"\n    and \"ja \\<le> j\" \"jb \\<le> j\"\n  shows \"wf_mbuf2 (min ja jb) ja jb P Q buf'\"\n    and \"list_all2 R [min ja jb..<j] nts'\"\n  using assms unfolding wf_mbuf2_def\n  by (induction f z buf nts arbitrary: i z' buf' nts' rule: mbuf2t_take.induct)\n    (auto simp add: list_all2_Cons2 upt_eq_Cons_conv less_eq_Suc_le min_absorb1 min_absorb2\n      split: prod.split)\n\nlemma wf_mbufn_take:\n  assumes \"mbufn_take f z buf = (z', buf')\"\n    and \"wf_mbufn i js Ps buf\"\n  shows \"wf_mbufn (Mini i js) js Ps buf'\"\n  using assms unfolding wf_mbufn_def\nproof (induction f z buf arbitrary: i z' buf' rule: mbufn_take.induct)\n  case rec: (1 f z buf)\n  show ?case proof (cases \"buf = []\")\n    case True\n    with rec.prems show ?thesis by simp\n  next\n    case nonempty: False\n    show ?thesis proof (cases \"[] \\<in> set buf\")\n      case True\n      from rec.prems(2) have \"\\<forall>j\\<in>set js. i \\<le> j\"\n        by (auto simp: in_set_conv_nth list_all3_conv_all_nth)\n      moreover from True rec.prems(2) have \"i \\<in> set js\"\n        by (fastforce simp: in_set_conv_nth list_all3_conv_all_nth list_all2_iff)\n      ultimately have \"Mini i js = i\"\n        unfolding Mini_def\n        by (auto intro!: antisym[OF Min.coboundedI Min.boundedI])\n      with rec.prems nonempty True show ?thesis by simp\n    next\n      case False\n      from nonempty rec.prems(2) have \"Mini i js = Mini (Suc i) js\"\n        unfolding Mini_def by auto\n      show ?thesis\n        unfolding \\<open>Mini i js = Mini (Suc i) js\\<close>\n      proof (rule rec.IH)\n        show \"\\<not> (buf = [] \\<or> [] \\<in> set buf)\" using nonempty False by simp\n        show \"list_all3 (\\<lambda>P j xs. Suc i \\<le> j \\<and> list_all2 P [Suc i..<j] xs) Ps js (map tl buf)\"\n          using False rec.prems(2)\n          by (auto simp: list_all3_map elim!: list_all3_mono_strong dest: list.rel_sel[THEN iffD1])\n        show \"mbufn_take f (f (map hd buf) z) (map tl buf) = (z', buf')\"\n          using nonempty False rec.prems(1) by simp\n      qed\n    qed\n  qed\nqed\n\nlemma mbufnt_take_eqD:\n  assumes \"mbufnt_take f z buf nts = (z', buf', nts')\"\n    and \"wf_mbufn i js Ps buf\"\n    and \"list_all2 R [i..<j] nts\"\n    and \"\\<And>k. k \\<in> set js \\<Longrightarrow> k \\<le> j\"\n    and \"k = Mini (i + length nts) js\"\n  shows \"wf_mbufn k js Ps buf'\"\n    and \"list_all2 R [k..<j] nts'\"\n  using assms(1-4) unfolding assms(5)\nproof (induction f z buf nts arbitrary: i z' buf' nts' rule: mbufnt_take.induct)\n  case IH: (1 f z buf nts)\n  note mbufnt_take.simps[simp del]\n  case 1\n  then have *: \"list_all2 R [Suc i..<j] (tl nts)\"\n    by (auto simp: list.rel_sel[of R \"[i..<j]\" nts, simplified])\n  from 1 show ?case\n    using wf_mbufn_in_set_Mini[OF 1(2)]\n    by (subst (asm) mbufnt_take.simps)\n      (force simp: Mini_def wf_mbufn_def split: if_splits prod.splits elim!: list_all3_mono_strong\n        dest!: IH(1)[rotated, OF _ wf_mbufn_map_tl[OF 1(2)] *])\n  case 2\n  then have *: \"list_all2 R [Suc i..<j] (tl nts)\"\n    by (auto simp: list.rel_sel[of R \"[i..<j]\" nts, simplified])\n  have [simp]: \"Suc (i + (length nts - Suc 0)) = i + length nts\" if \"nts \\<noteq> []\"\n    using that by (fastforce simp flip: length_greater_0_conv)\n  with 2 show ?case\n    using wf_mbufn_in_set_Mini[OF 2(2)] wf_mbufn_notin_set[OF 2(2)]\n    by (subst (asm) mbufnt_take.simps) (force simp: Mini_def wf_mbufn_def\n        dest!: IH(2)[rotated, OF _ wf_mbufn_map_tl[OF 2(2)] *]\n        split: if_splits prod.splits)\nqed\n\nlemma mbuf2t_take_induct[consumes 5, case_names base step]:\n  assumes \"mbuf2t_take f z buf nts = (z', buf', nts')\"\n    and \"wf_mbuf2 i ja jb P Q buf\"\n    and \"list_all2 R [i..<j] nts\"\n    and \"ja \\<le> j\" \"jb \\<le> j\"\n    and \"U i z\"\n    and \"\\<And>k x y t z. i \\<le> k \\<Longrightarrow> Suc k \\<le> ja \\<Longrightarrow> Suc k \\<le> jb \\<Longrightarrow>\n      P k x \\<Longrightarrow> Q k y \\<Longrightarrow> R k t \\<Longrightarrow> U k z \\<Longrightarrow> U (Suc k) (f x y t z)\"\n  shows \"U (min ja jb) z'\"\n  using assms unfolding wf_mbuf2_def\n  by (induction f z buf nts arbitrary: i z' buf' nts' rule: mbuf2t_take.induct)\n    (auto simp add: list_all2_Cons2 upt_eq_Cons_conv less_eq_Suc_le min_absorb1 min_absorb2\n      elim!: arg_cong2[of _ _ _ _ U, OF _ refl, THEN iffD1, rotated] split: prod.split)\n\nlemma list_all2_hdD:\n  assumes \"list_all2 P [i..<j] xs\" \"xs \\<noteq> []\"\n  shows \"P i (hd xs)\" \"i < j\"\n  using assms unfolding list_all2_conv_all_nth\n  by (auto simp: hd_conv_nth intro: zero_less_diff[THEN iffD1] dest!: spec[of _ 0])\n\nlemma mbufn_take_induct[consumes 3, case_names base step]:\n  assumes \"mbufn_take f z buf = (z', buf')\"\n    and \"wf_mbufn i js Ps buf\"\n    and \"U i z\"\n    and \"\\<And>k xs z. i \\<le> k \\<Longrightarrow> Suc k \\<le> Mini i js \\<Longrightarrow>\n      list_all2 (\\<lambda>P x. P k x) Ps xs \\<Longrightarrow> U k z \\<Longrightarrow> U (Suc k) (f xs z)\"\n  shows \"U (Mini i js) z'\"\n  using assms unfolding wf_mbufn_def\nproof (induction f z buf arbitrary: i z' buf' rule: mbufn_take.induct)\n  case rec: (1 f z buf)\n  show ?case proof (cases \"buf = []\")\n    case True\n    with rec.prems show ?thesis unfolding Mini_def by simp\n  next\n    case nonempty: False\n    show ?thesis proof (cases \"[] \\<in> set buf\")\n      case True\n      from rec.prems(2) have \"\\<forall>j\\<in>set js. i \\<le> j\"\n        by (auto simp: in_set_conv_nth list_all3_conv_all_nth)\n      moreover from True rec.prems(2) have \"i \\<in> set js\"\n        by (fastforce simp: in_set_conv_nth list_all3_conv_all_nth list_all2_iff)\n      ultimately have \"Mini i js = i\"\n        unfolding Mini_def\n        by (auto intro!: antisym[OF Min.coboundedI Min.boundedI])\n      with rec.prems nonempty True show ?thesis by simp\n    next\n      case False\n      with nonempty rec.prems(2) have more: \"Suc i \\<le> Mini i js\"\n        using diff_is_0_eq not_le unfolding Mini_def\n        by (fastforce simp: in_set_conv_nth list_all3_conv_all_nth list_all2_iff)\n      then have \"Mini i js = Mini (Suc i) js\" unfolding Mini_def by auto\n      show ?thesis\n        unfolding \\<open>Mini i js = Mini (Suc i) js\\<close>\n      proof (rule rec.IH)\n        show \"\\<not> (buf = [] \\<or> [] \\<in> set buf)\" using nonempty False by simp\n        show \"mbufn_take f (f (map hd buf) z) (map tl buf) = (z', buf')\"\n          using nonempty False rec.prems by simp\n        show \"list_all3 (\\<lambda>P j xs. Suc i \\<le> j \\<and> list_all2 P [Suc i..<j] xs) Ps js (map tl buf)\"\n          using False rec.prems\n          by (auto simp: list_all3_map elim!: list_all3_mono_strong dest: list.rel_sel[THEN iffD1])\n        show \"U (Suc i) (f (map hd buf) z)\"\n          using more False rec.prems\n          by (auto 0 4 simp: list_all3_map intro!: rec.prems(4) list_all3_list_all2I\n              elim!: list_all3_mono_strong dest: list.rel_sel[THEN iffD1])\n        show \"\\<And>k xs z. Suc i \\<le> k \\<Longrightarrow> Suc k \\<le> Mini (Suc i) js \\<Longrightarrow>\n          list_all2 (\\<lambda>P. P k) Ps xs \\<Longrightarrow> U k z \\<Longrightarrow> U (Suc k) (f xs z)\"\n          by (rule rec.prems(4)) (auto simp: Mini_def)\n      qed\n    qed\n  qed\nqed\n\nlemma mbufnt_take_induct[consumes 5, case_names base step]:\n  assumes \"mbufnt_take f z buf nts = (z', buf', nts')\"\n    and \"wf_mbufn i js Ps buf\"\n    and \"list_all2 R [i..<j] nts\"\n    and \"\\<And>k. k \\<in> set js \\<Longrightarrow> k \\<le> j\"\n    and \"U i z\"\n    and \"\\<And>k xs t z. i \\<le> k \\<Longrightarrow> Suc k \\<le> Mini j js \\<Longrightarrow>\n      list_all2 (\\<lambda>P x. P k x) Ps xs \\<Longrightarrow> R k t \\<Longrightarrow> U k z \\<Longrightarrow> U (Suc k) (f xs t z)\"\n  shows \"U (Mini (i + length nts) js) z'\"\n  using assms\nproof (induction f z buf nts arbitrary: i z' buf' nts' rule: mbufnt_take.induct)\n  case (1 f z buf nts)\n  then have *: \"list_all2 R [Suc i..<j] (tl nts)\"\n    by (auto simp: list.rel_sel[of R \"[i..<j]\" nts, simplified])\n  note mbufnt_take.simps[simp del]\n  from 1(2-6) have \"i = Min (set js)\" if \"js \\<noteq> []\" \"nts = []\"\n    using that unfolding wf_mbufn_def using wf_mbufn_in_set_Mini[OF 1(3)]\n    by (fastforce simp: Mini_def list_all3_Cons neq_Nil_conv)\n  with 1(2-7) list_all2_hdD[OF 1(4)] show ?case\n    unfolding wf_mbufn_def using wf_mbufn_in_set_Mini[OF 1(3)] wf_mbufn_notin_set[OF 1(3)]\n    by (subst (asm) mbufnt_take.simps)\n      (auto simp add: Mini_def list.rel_map Suc_le_eq\n        elim!: arg_cong2[of _ _ _ _ U, OF _ refl, THEN iffD1, rotated]\n        list_all3_mono_strong[THEN list_all3_list_all2I[of _ _ js]] list_all2_hdD\n        dest!: 1(1)[rotated, OF _ wf_mbufn_map_tl[OF 1(3)] * _ 1(7)] split: prod.split if_splits)\nqed\n\nlemma mbuf2_take_add':\n  assumes eq: \"mbuf2_take f (mbuf2_add xs ys buf) = (zs, buf')\"\n    and pre: \"wf_mbuf2' \\<sigma> P V j n R \\<phi> \\<psi> buf\"\n    and rm: \"rel_mapping (\\<le>) P P'\"\n    and xs: \"list_all2 (\\<lambda>i. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>))\n      [progress \\<sigma> P \\<phi> j..<progress \\<sigma> P' \\<phi> j'] xs\"\n    and ys: \"list_all2 (\\<lambda>i. qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>))\n      [progress \\<sigma> P \\<psi> j..<progress \\<sigma> P' \\<psi> j'] ys\"\n    and \"j \\<le> j'\"\n  shows \"wf_mbuf2' \\<sigma> P' V j' n R \\<phi> \\<psi> buf'\"\n    and \"list_all2 (\\<lambda>i Z. \\<exists>X Y.\n      qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>) X \\<and>\n      qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>) Y \\<and>\n      Z = f X Y)\n      [min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)..<min (progress \\<sigma> P' \\<phi> j') (progress \\<sigma> P' \\<psi> j')] zs\"\n  using pre rm unfolding wf_mbuf2'_def\n  by (force intro!: mbuf2_take_eqD[OF eq] wf_mbuf2_add[OF _ xs ys] progress_mono_gen[OF \\<open>j \\<le> j'\\<close> rm])+\n\nlemma mbuf2t_take_add':\n  assumes eq: \"mbuf2t_take f z (mbuf2_add xs ys buf) nts = (z', buf', nts')\"\n    and bounded: \"pred_mapping (\\<lambda>x. x \\<le> j) P\" \"pred_mapping (\\<lambda>x. x \\<le> j') P'\"\n    and rm: \"rel_mapping (\\<le>) P P'\"\n    and pre_buf: \"wf_mbuf2' \\<sigma> P V j n R \\<phi> \\<psi> buf\"\n    and pre_nts: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)..<j'] nts\"\n    and xs: \"list_all2 (\\<lambda>i. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>))\n      [progress \\<sigma> P \\<phi> j..<progress \\<sigma> P' \\<phi> j'] xs\"\n    and ys: \"list_all2 (\\<lambda>i. qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>))\n      [progress \\<sigma> P \\<psi> j..<progress \\<sigma> P' \\<psi> j'] ys\"\n    and \"j \\<le> j'\"\n  shows \"wf_mbuf2' \\<sigma> P' V j' n R \\<phi> \\<psi> buf'\"\n    and \"wf_ts \\<sigma> P' j' \\<phi> \\<psi> nts'\"\n  using pre_buf pre_nts bounded rm unfolding wf_mbuf2'_def wf_ts_def\n  by (auto intro!: mbuf2t_take_eqD[OF eq] wf_mbuf2_add[OF _ xs ys] progress_mono_gen[OF \\<open>j \\<le> j'\\<close> rm]\n      progress_le_gen)\n\nlemma ok_0_atms: \"ok 0 mr \\<Longrightarrow> regex.atms (from_mregex mr []) = {}\"\n  by (induct mr) auto\n\nlemma ok_0_progress: \"ok 0 mr \\<Longrightarrow> progress_regex \\<sigma> P (from_mregex mr []) j = j\"\n  by (drule ok_0_atms) (auto simp: progress_regex_def)\n\nlemma atms_empty_atms: \"safe_regex m g r \\<Longrightarrow> atms r = {} \\<longleftrightarrow> regex.atms r = {}\"\n  by (induct r rule: safe_regex_induct) (auto split: if_splits simp: cases_Neg_iff)\n\nlemma atms_empty_progress: \"safe_regex m g r \\<Longrightarrow> atms r = {} \\<Longrightarrow> progress_regex \\<sigma> P r j = j\"\n  by (drule atms_empty_atms) (auto simp: progress_regex_def)\n\nlemma to_mregex_empty_progress: \"safe_regex m g r \\<Longrightarrow> to_mregex r = (mr, []) \\<Longrightarrow>\n  progress_regex \\<sigma> P r j = j\"\n  using from_mregex_eq ok_0_progress to_mregex_ok atms_empty_atms by fastforce\n\nlemma progress_regex_le: \"pred_mapping (\\<lambda>x. x \\<le> j) P \\<Longrightarrow> progress_regex \\<sigma> P r j \\<le> j\"\n  by (auto intro!: progress_le_gen simp: Min_le_iff progress_regex_def)\n\nlemma Neg_acyclic: \"formula.Neg x = x \\<Longrightarrow> P\"\n  by (induct x) auto\n\nlemma case_Neg_in_iff: \"x \\<in> (case y of formula.Neg \\<phi>' \\<Rightarrow> {\\<phi>'} | _ \\<Rightarrow> {}) \\<longleftrightarrow> y = formula.Neg x\"\n  by (cases y) auto\n\nlemma atms_nonempty_progress:\n  \"safe_regex m g r \\<Longrightarrow> atms r \\<noteq> {} \\<Longrightarrow> (\\<lambda>\\<phi>. progress \\<sigma> P \\<phi> j) ` atms r = (\\<lambda>\\<phi>. progress \\<sigma> P \\<phi> j) ` regex.atms r\"\n  by (frule atms_empty_atms; simp)\n    (auto 0 3 simp: atms_def image_iff case_Neg_in_iff elim!: disjE_Not2 dest: safe_regex_safe_formula)\n\nlemma to_mregex_nonempty_progress: \"safe_regex m g r \\<Longrightarrow> to_mregex r = (mr, \\<phi>s) \\<Longrightarrow> \\<phi>s \\<noteq> [] \\<Longrightarrow>\n  progress_regex \\<sigma> P r j = (MIN \\<phi>\\<in>set \\<phi>s. progress \\<sigma> P \\<phi> j)\"\n  using atms_nonempty_progress to_mregex_ok unfolding progress_regex_def by fastforce\n\nlemma to_mregex_progress: \"safe_regex m g r \\<Longrightarrow> to_mregex r = (mr, \\<phi>s) \\<Longrightarrow>\n  progress_regex \\<sigma> P r j = (if \\<phi>s = [] then j else (MIN \\<phi>\\<in>set \\<phi>s. progress \\<sigma> P \\<phi> j))\"\n  using to_mregex_nonempty_progress to_mregex_empty_progress unfolding progress_regex_def by auto\n\nlemma mbufnt_take_add':\n  assumes eq: \"mbufnt_take f z (mbufn_add xss buf) nts = (z', buf', nts')\"\n    and bounded: \"pred_mapping (\\<lambda>x. x \\<le> j) P\" \"pred_mapping (\\<lambda>x. x \\<le> j') P'\"\n    and rm: \"rel_mapping (\\<le>) P P'\"\n    and safe: \"safe_regex m g r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and pre_buf: \"wf_mbufn' \\<sigma> P V j n R r buf\"\n    and pre_nts: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [progress_regex \\<sigma> P r j..<j'] nts\"\n    and xss: \"list_all3 list_all2\n     (map (\\<lambda>\\<phi> i. qtable n (fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>)) \\<phi>s)\n     (map2 upt (map (\\<lambda>\\<phi>. progress \\<sigma> P \\<phi> j) \\<phi>s) (map (\\<lambda>\\<phi>. progress \\<sigma> P' \\<phi> j') \\<phi>s)) xss\"\n    and \"j \\<le> j'\"\n  shows \"wf_mbufn' \\<sigma> P' V j' n R r buf'\"\n    and \"wf_ts_regex \\<sigma> P' j' r nts'\"\n  using pre_buf pre_nts bounded rm mr safe xss \\<open>j \\<le> j'\\<close>  unfolding wf_mbufn'_def wf_ts_regex_def\n  using atms_empty_progress[of m g r] to_mregex_ok[OF mr]\n  by (auto 0 3 simp: list.rel_map to_mregex_empty_progress to_mregex_nonempty_progress Mini_def\n      intro: progress_mono_gen[OF \\<open>j \\<le> j'\\<close> rm] list.rel_refl_strong progress_le_gen\n      dest: list_all2_lengthD elim!: mbufnt_take_eqD[OF eq wf_mbufn_add])\n\nlemma mbuf2t_take_add_induct'[consumes 6, case_names base step]:\n  assumes eq: \"mbuf2t_take f z (mbuf2_add xs ys buf) nts = (z', buf', nts')\"\n    and bounded: \"pred_mapping (\\<lambda>x. x \\<le> j) P\" \"pred_mapping (\\<lambda>x. x \\<le> j') P'\"\n    and rm: \"rel_mapping (\\<le>) P P'\"\n    and pre_buf: \"wf_mbuf2' \\<sigma> P V j n R \\<phi> \\<psi> buf\"\n    and pre_nts: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)..<j'] nts\"\n    and xs: \"list_all2 (\\<lambda>i. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>))\n      [progress \\<sigma> P \\<phi> j..<progress \\<sigma> P' \\<phi> j'] xs\"\n    and ys: \"list_all2 (\\<lambda>i. qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>))\n      [progress \\<sigma> P \\<psi> j..<progress \\<sigma> P' \\<psi> j'] ys\"\n    and \"j \\<le> j'\"\n    and base: \"U (min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)) z\"\n    and step: \"\\<And>k X Y z. min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j) \\<le> k \\<Longrightarrow>\n      Suc k \\<le> progress \\<sigma> P' \\<phi> j' \\<Longrightarrow> Suc k \\<le> progress \\<sigma> P' \\<psi> j' \\<Longrightarrow>\n      qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) k \\<phi>) X \\<Longrightarrow>\n      qtable n (Formula.fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) k \\<psi>) Y \\<Longrightarrow>\n      U k z \\<Longrightarrow> U (Suc k) (f X Y (\\<tau> \\<sigma> k) z)\"\n  shows \"U (min (progress \\<sigma> P' \\<phi> j') (progress \\<sigma> P' \\<psi> j')) z'\"\n  using pre_buf pre_nts bounded rm unfolding wf_mbuf2'_def\n  by (blast intro!: mbuf2t_take_induct[OF eq] wf_mbuf2_add[OF _ xs ys] progress_mono_gen[OF \\<open>j \\<le> j'\\<close> rm]\n      progress_le_gen base step)\n\nlemma mbufnt_take_add_induct'[consumes 6, case_names base step]:\n  assumes eq: \"mbufnt_take f z (mbufn_add xss buf) nts = (z', buf', nts')\"\n    and bounded: \"pred_mapping (\\<lambda>x. x \\<le> j) P\" \"pred_mapping (\\<lambda>x. x \\<le> j') P'\"\n    and rm: \"rel_mapping (\\<le>) P P'\"\n    and safe: \"safe_regex m g r\"\n    and mr: \"to_mregex r = (mr, \\<phi>s)\"\n    and pre_buf: \"wf_mbufn' \\<sigma> P V j n R r buf\"\n    and pre_nts: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [progress_regex \\<sigma> P r j..<j'] nts\"\n    and xss: \"list_all3 list_all2\n     (map (\\<lambda>\\<phi> i. qtable n (fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>)) \\<phi>s)\n     (map2 upt (map (\\<lambda>\\<phi>. progress \\<sigma> P \\<phi> j) \\<phi>s) (map (\\<lambda>\\<phi>. progress \\<sigma> P' \\<phi> j') \\<phi>s)) xss\"\n    and \"j \\<le> j'\"\n    and base: \"U (progress_regex \\<sigma> P r j) z\"\n    and step: \"\\<And>k Xs z. progress_regex \\<sigma> P r j \\<le> k \\<Longrightarrow> Suc k \\<le> progress_regex \\<sigma> P' r j' \\<Longrightarrow>\n      list_all2 (\\<lambda>\\<phi>. qtable n (Formula.fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) k \\<phi>)) \\<phi>s Xs \\<Longrightarrow>\n      U k z \\<Longrightarrow> U (Suc k) (f Xs (\\<tau> \\<sigma> k) z)\"\n  shows \"U (progress_regex \\<sigma> P' r j') z'\"\n  using pre_buf pre_nts bounded rm \\<open>j \\<le> j'\\<close> to_mregex_progress[OF safe mr, of \\<sigma> P' j'] to_mregex_empty_progress[OF safe, of mr \\<sigma> P j] base\n  unfolding wf_mbufn'_def mr prod.case\n  by (fastforce dest!: mbufnt_take_induct[OF eq wf_mbufn_add[OF _ xss] pre_nts, of U]\n      simp: list.rel_map le_imp_diff_is_add ac_simps Mini_def\n      intro: progress_mono_gen[OF \\<open>j \\<le> j'\\<close> rm] list.rel_refl_strong progress_le_gen\n      intro!: base step  dest: list_all2_lengthD split: if_splits)\n\nlemma progress_Until_le: \"progress \\<sigma> P (Formula.Until \\<phi> I \\<psi>) j \\<le> min (progress \\<sigma> P \\<phi> j) (progress \\<sigma> P \\<psi> j)\"\n  by (cases \"right I\") (auto simp: trans_le_add1 intro!: cInf_lower)\n\nlemma progress_MatchF_le: \"progress \\<sigma> P (Formula.MatchF I r) j \\<le> progress_regex \\<sigma> P r j\"\n  by (cases \"right I\") (auto simp: trans_le_add1 progress_regex_def intro!: cInf_lower)\n\nlemma list_all2_upt_Cons: \"P a x \\<Longrightarrow> list_all2 P [Suc a..<b] xs \\<Longrightarrow> Suc a \\<le> b \\<Longrightarrow>\n  list_all2 P [a..<b] (x # xs)\"\n  by (simp add: list_all2_Cons2 upt_eq_Cons_conv)\n\nlemma list_all2_upt_append: \"list_all2 P [a..<b] xs \\<Longrightarrow> list_all2 P [b..<c] ys \\<Longrightarrow>\n  a \\<le> b \\<Longrightarrow> b \\<le> c \\<Longrightarrow> list_all2 P [a..<c] (xs @ ys)\"\n  by (induction xs arbitrary: a) (auto simp add: list_all2_Cons2 upt_eq_Cons_conv)\n\nlemma list_all3_list_all2_conv: \"list_all3 R xs xs ys = list_all2 (\\<lambda>x. R x x) xs ys\"\n  by (auto simp: list_all3_conv_all_nth list_all2_conv_all_nth)\n\nlemma map_split_map: \"map_split f (map g xs) = map_split (f o g) xs\"\n  by (induct xs) auto\n\nlemma map_split_alt: \"map_split f xs = (map (fst o f) xs, map (snd o f) xs)\"\n  by (induct xs) (auto split: prod.splits)\n\nlemma fv_formula_of_constraint: \"fv (formula_of_constraint (t1, p, c, t2)) = fv_trm t1 \\<union> fv_trm t2\"\n  by (induction \"(t1, p, c, t2)\" rule: formula_of_constraint.induct) simp_all\n\nlemma (in maux) wf_mformula_wf_set: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>' \\<Longrightarrow> wf_set n (Formula.fv \\<phi>')\"\n  unfolding wf_set_def\nproof (induction rule: wf_mformula.induct)\n  case (AndRel P V n R \\<phi> \\<phi>' \\<psi>' conf)\n  then show ?case by (auto simp: fv_formula_of_constraint dest!: subsetD)\nnext\n  case (Ands P V n R l l_pos l_neg l' buf A_pos A_neg)\n  from Ands.IH have \"\\<forall>\\<phi>'\\<in>set (l_pos @ map remove_neg l_neg). \\<forall>x\\<in>fv \\<phi>'. x < n\"\n    by (simp add: list_all2_conv_all_nth all_set_conv_all_nth[of \"_ @ _\"] del: set_append)\n  then have \"\\<forall>\\<phi>'\\<in>set (l_pos @ l_neg). \\<forall>x\\<in>fv \\<phi>'. x < n\"\n    by (auto dest: bspec[where x=\"remove_neg _\"])\n  then show ?case using Ands.hyps(2) by auto\nnext\n  case (Agg P V b n R \\<phi> \\<phi>' y f g0 \\<omega>)\n  then have \"Formula.fvi_trm b f \\<subseteq> Formula.fvi b \\<phi>'\"\n    by (auto simp: fvi_trm_iff_fv_trm[where b=b] fvi_iff_fv[where b=b])\n  with Agg show ?case by (auto 0 3 simp: Un_absorb2 fvi_iff_fv[where b=b])\nnext\n  case (MatchP r P V n R \\<phi>s mr mrs buf nts I aux)\n  then obtain \\<phi>s' where conv: \"to_mregex r = (mr, \\<phi>s')\" by blast\n  with MatchP have \"\\<forall>\\<phi>'\\<in>set \\<phi>s'. \\<forall>x\\<in>fv \\<phi>'. x < n\"\n    by (simp add: list_all2_conv_all_nth all_set_conv_all_nth[of \\<phi>s'])\n  with conv show ?case\n    by (simp add: to_mregex_ok[THEN conjunct1] fv_regex_alt[OF \\<open>safe_regex _ _ r\\<close>])\nnext\n  case (MatchF r  P V n R \\<phi>s mr mrs buf nts I aux)\n  then obtain \\<phi>s' where conv: \"to_mregex r = (mr, \\<phi>s')\" by blast\n  with MatchF have \"\\<forall>\\<phi>'\\<in>set \\<phi>s'. \\<forall>x\\<in>fv \\<phi>'. x < n\"\n    by (simp add: list_all2_conv_all_nth all_set_conv_all_nth[of \\<phi>s'])\n  with conv show ?case\n    by (simp add: to_mregex_ok[THEN conjunct1] fv_regex_alt[OF \\<open>safe_regex _ _ r\\<close>])\nqed (auto simp: fvi_Suc split: if_splits)\n\nlemma qtable_mmulti_join:\n  assumes pos: \"list_all3 (\\<lambda>A Qi X. qtable n A P Qi X \\<and> wf_set n A) A_pos Q_pos L_pos\"\n    and neg: \"list_all3 (\\<lambda>A Qi X. qtable n A P Qi X \\<and> wf_set n A) A_neg Q_neg L_neg\"\n    and C_eq: \"C = \\<Union>(set A_pos)\" and L_eq: \"L = L_pos @ L_neg\"\n    and \"A_pos \\<noteq> []\" and fv_subset: \"\\<Union>(set A_neg) \\<subseteq> \\<Union>(set A_pos)\"\n    and restrict_pos: \"\\<And>x. wf_tuple n C x \\<Longrightarrow> P x \\<Longrightarrow> list_all (\\<lambda>A. P (restrict A x)) A_pos\"\n    and restrict_neg: \"\\<And>x. wf_tuple n C x \\<Longrightarrow> P x \\<Longrightarrow> list_all (\\<lambda>A. P (restrict A x)) A_neg\"\n    and Qs: \"\\<And>x. wf_tuple n C x \\<Longrightarrow> P x \\<Longrightarrow> Q x \\<longleftrightarrow>\n      list_all2 (\\<lambda>A Qi. Qi (restrict A x)) A_pos Q_pos \\<and>\n      list_all2 (\\<lambda>A Qi. \\<not> Qi (restrict A x)) A_neg Q_neg\"\n  shows \"qtable n C P Q (mmulti_join n A_pos A_neg L)\"\nproof (rule qtableI)\n  from pos have 1: \"list_all2 (\\<lambda>A X. table n A X \\<and> wf_set n A) A_pos L_pos\"\n    by (simp add: list_all3_conv_all_nth list_all2_conv_all_nth qtable_def)\n  moreover from neg have \"list_all2 (\\<lambda>A X. table n A X \\<and> wf_set n A) A_neg L_neg\"\n    by (simp add: list_all3_conv_all_nth list_all2_conv_all_nth qtable_def)\n  ultimately have L: \"list_all2 (\\<lambda>A X. table n A X \\<and> wf_set n A) (A_pos @ A_neg) (L_pos @ L_neg)\"\n    by (rule list_all2_appendI)\n  note in_join_iff = mmulti_join_correct[OF \\<open>A_pos \\<noteq> []\\<close> L]\n  from 1 have take_eq: \"take (length A_pos) (L_pos @ L_neg) = L_pos\"\n    by (auto dest!: list_all2_lengthD)\n  from 1 have drop_eq: \"drop (length A_pos) (L_pos @ L_neg) = L_neg\"\n    by (auto dest!: list_all2_lengthD)\n\n  note mmulti_join.simps[simp del]\n  show \"table n C (mmulti_join n A_pos A_neg L)\"\n    unfolding C_eq L_eq table_def by (simp add: in_join_iff)\n  show \"Q x\" if \"x \\<in> mmulti_join n A_pos A_neg L\" \"wf_tuple n C x\" \"P x\" for x\n    using that(2,3)\n  proof (rule Qs[THEN iffD2, OF _ _ conjI])\n    have pos': \"list_all2 (\\<lambda>A. (\\<in>) (restrict A x)) A_pos L_pos\"\n      and neg': \"list_all2 (\\<lambda>A. (\\<notin>) (restrict A x)) A_neg L_neg\"\n      using that(1) unfolding L_eq in_join_iff take_eq drop_eq by simp_all\n    show \"list_all2 (\\<lambda>A Qi. Qi (restrict A x)) A_pos Q_pos\"\n      using pos pos' restrict_pos that(2,3)\n      by (simp add: list_all3_conv_all_nth list_all2_conv_all_nth list_all_length qtable_def)\n    have fv_subset': \"\\<And>i. i < length A_neg \\<Longrightarrow> A_neg ! i \\<subseteq> C\"\n      using fv_subset unfolding C_eq by (auto simp: Sup_le_iff)\n    show \"list_all2 (\\<lambda>A Qi. \\<not> Qi (restrict A x)) A_neg Q_neg\"\n      using neg neg' restrict_neg that(2,3)\n      by (auto simp: list_all3_conv_all_nth list_all2_conv_all_nth list_all_length qtable_def\n          wf_tuple_restrict_simple[OF _ fv_subset'])\n  qed\n  show \"x \\<in> mmulti_join n A_pos A_neg L\" if \"wf_tuple n C x\" \"P x\" \"Q x\" for x\n    unfolding L_eq in_join_iff take_eq drop_eq\n  proof (intro conjI)\n    from that have pos': \"list_all2 (\\<lambda>A Qi. Qi (restrict A x)) A_pos Q_pos\"\n      and neg': \"list_all2 (\\<lambda>A Qi. \\<not> Qi (restrict A x)) A_neg Q_neg\"\n      using Qs[THEN iffD1] by auto\n    show \"wf_tuple n (\\<Union>A\\<in>set A_pos. A) x\"\n      using \\<open>wf_tuple n C x\\<close> unfolding C_eq by simp\n    show \"list_all2 (\\<lambda>A. (\\<in>) (restrict A x)) A_pos L_pos\"\n      using pos pos' restrict_pos that(1,2)\n      by (simp add: list_all3_conv_all_nth list_all2_conv_all_nth list_all_length qtable_def\n          C_eq wf_tuple_restrict_simple[OF _ Sup_upper])\n    show \"list_all2 (\\<lambda>A. (\\<notin>) (restrict A x)) A_neg L_neg\"\n      using neg neg' restrict_neg that(1,2)\n      by (auto simp: list_all3_conv_all_nth list_all2_conv_all_nth list_all_length qtable_def)\n  qed\nqed\n\nlemma nth_filter: \"i < length (filter P xs) \\<Longrightarrow>\n  (\\<And>i'. i' < length xs \\<Longrightarrow> P (xs ! i') \\<Longrightarrow> Q (xs ! i')) \\<Longrightarrow> Q (filter P xs ! i)\"\n  by (metis (lifting) in_set_conv_nth set_filter mem_Collect_eq)\n\nlemma nth_partition: \"i < length xs \\<Longrightarrow>\n  (\\<And>i'. i' < length (filter P xs) \\<Longrightarrow> Q (filter P xs ! i')) \\<Longrightarrow>\n  (\\<And>i'. i' < length (filter (Not \\<circ> P) xs) \\<Longrightarrow> Q (filter (Not \\<circ> P) xs ! i')) \\<Longrightarrow> Q (xs ! i)\"\n  by (metis (no_types, lifting) in_set_conv_nth set_filter mem_Collect_eq comp_apply)\n\nlemma qtable_bin_join:\n  assumes \"qtable n A P Q1 X\" \"qtable n B P Q2 Y\" \"\\<not> b \\<Longrightarrow> B \\<subseteq> A\" \"C = A \\<union> B\"\n    \"\\<And>x. wf_tuple n C x \\<Longrightarrow> P x \\<Longrightarrow> P (restrict A x) \\<and> P (restrict B x)\"\n    \"\\<And>x. b \\<Longrightarrow> wf_tuple n C x \\<Longrightarrow> P x \\<Longrightarrow> Q x \\<longleftrightarrow> Q1 (restrict A x) \\<and> Q2 (restrict B x)\"\n    \"\\<And>x. \\<not> b \\<Longrightarrow> wf_tuple n C x \\<Longrightarrow> P x \\<Longrightarrow> Q x \\<longleftrightarrow> Q1 (restrict A x) \\<and> \\<not> Q2 (restrict B x)\"\n  shows \"qtable n C P Q (bin_join n A X b B Y)\"\n  using qtable_join[OF assms] bin_join_table[of n A X B Y b] assms(1,2)\n  by (auto simp add: qtable_def)\n\nlemma restrict_update: \"y \\<notin> A \\<Longrightarrow> y < length x \\<Longrightarrow> restrict A (x[y:=z]) = restrict A x\"\n  unfolding restrict_def by (auto simp add: nth_list_update)\n\nlemma qtable_assign:\n  assumes \"qtable n A P Q X\"\n    \"y < n\" \"insert y A = A'\" \"y \\<notin> A\"\n    \"\\<And>x'. wf_tuple n A' x' \\<Longrightarrow> P x' \\<Longrightarrow> P (restrict A x')\"\n    \"\\<And>x. wf_tuple n A x \\<Longrightarrow> P x \\<Longrightarrow> Q x \\<Longrightarrow> Q' (x[y:=Some (f x)])\"\n    \"\\<And>x'. wf_tuple n A' x' \\<Longrightarrow> P x' \\<Longrightarrow> Q' x' \\<Longrightarrow> Q (restrict A x') \\<and> x' ! y = Some (f (restrict A x'))\"\n  shows \"qtable n A' P Q' ((\\<lambda>x. x[y:=Some (f x)]) ` X)\" (is \"qtable _ _ _ _ ?Y\")\nproof (rule qtableI)\n  from assms(1) have \"table n A X\" unfolding qtable_def by simp\n  then show \"table n A' ?Y\"\n    unfolding table_def wf_tuple_def using assms(2,3)\n    by (auto simp: nth_list_update)\nnext\n  fix x'\n  assume \"x' \\<in> ?Y\" \"wf_tuple n A' x'\" \"P x'\"\n  then obtain x where \"x \\<in> X\" and x'_eq: \"x' = x[y:=Some (f x)]\" by blast\n  then have \"wf_tuple n A x\"\n    using assms(1) unfolding qtable_def table_def by blast\n  then have \"y < length x\" using assms(2) by (simp add: wf_tuple_def)\n  with \\<open>wf_tuple n A x\\<close> have \"restrict A x' = x\"\n    unfolding x'_eq by (simp add: restrict_update[OF assms(4)] restrict_idle)\n  with \\<open>wf_tuple n A' x'\\<close> \\<open>P x'\\<close> have \"P x\"\n    using assms(5) by blast\n  with \\<open>wf_tuple n A x\\<close> \\<open>x \\<in> X\\<close> have \"Q x\"\n    using assms(1) by (elim in_qtableE)\n  with \\<open>wf_tuple n A x\\<close> \\<open>P x\\<close> show \"Q' x'\"\n    unfolding x'_eq by (rule assms(6))\nnext\n  fix x'\n  assume \"wf_tuple n A' x'\" \"P x'\" \"Q' x'\"\n  then have \"wf_tuple n A (restrict A x')\"\n    using assms(3) by (auto intro!: wf_tuple_restrict_simple)\n  moreover have \"P (restrict A x')\"\n    using \\<open>wf_tuple n A' x'\\<close> \\<open>P x'\\<close> by (rule assms(5))\n  moreover have \"Q (restrict A x')\" and y: \"x' ! y = Some (f (restrict A x'))\"\n    using \\<open>wf_tuple n A' x'\\<close> \\<open>P x'\\<close> \\<open>Q' x'\\<close> by (auto dest!: assms(7))\n  ultimately have \"restrict A x' \\<in> X\" by (intro in_qtableI[OF assms(1)])\n  moreover have \"x' = (restrict A x')[y:=Some (f (restrict A x'))]\"\n    using y assms(2,3) \\<open>wf_tuple n A (restrict A x')\\<close> \\<open>wf_tuple n A' x'\\<close>\n    by (auto simp: list_eq_iff_nth_eq wf_tuple_def nth_list_update nth_restrict)\n  ultimately show \"x' \\<in> ?Y\" by simp\nqed\n\nlemma sat_the_update: \"y \\<notin> fv \\<phi> \\<Longrightarrow> Formula.sat \\<sigma> V (map the (x[y:=z])) i \\<phi> = Formula.sat \\<sigma> V (map the x) i \\<phi>\"\n  by (rule sat_fv_cong) (metis map_update nth_list_update_neq)\n\nlemma progress_constraint: \"progress \\<sigma> P (formula_of_constraint c) j = j\"\n  by (induction rule: formula_of_constraint.induct) simp_all\n\nlemma qtable_filter:\n  assumes \"qtable n A P Q X\"\n    \"\\<And>x. wf_tuple n A x \\<Longrightarrow> P x \\<Longrightarrow> Q x \\<and> R x \\<longleftrightarrow> Q' x\"\n  shows \"qtable n A P Q' (Set.filter R X)\" (is \"qtable _ _ _ _ ?Y\")\nproof (rule qtableI)\n  from assms(1) have \"table n A X\"\n    unfolding qtable_def by simp\n  then show \"table n A ?Y\"\n    unfolding table_def wf_tuple_def by simp\nnext\n  fix x\n  assume \"x \\<in> ?Y\" \"wf_tuple n A x\" \"P x\"\n  with assms show \"Q' x\" by (auto elim!: in_qtableE)\nnext\n  fix x\n  assume \"wf_tuple n A x\" \"P x\" \"Q' x\"\n  with assms show \"x \\<in> Set.filter R X\" by (auto intro!: in_qtableI)\nqed\n\nlemma eval_constraint_sat_eq: \"wf_tuple n A x \\<Longrightarrow> fv_trm t1 \\<subseteq> A \\<Longrightarrow> fv_trm t2 \\<subseteq> A \\<Longrightarrow>\n  \\<forall>i\\<in>A. i < n \\<Longrightarrow> eval_constraint (t1, p, c, t2) x =\n    Formula.sat \\<sigma> V (map the x) i (formula_of_constraint (t1, p, c, t2))\"\n  by (induction \"(t1, p, c, t2)\" rule: formula_of_constraint.induct)\n    (simp_all add: meval_trm_eval_trm)\n\ndeclare progress_le_gen[simp]\n\ndefinition \"wf_envs \\<sigma> j P P' V db =\n  (dom V = dom P \\<and>\n   Mapping.keys db = dom P \\<union> {p. p \\<in> fst ` \\<Gamma> \\<sigma> j} \\<and>\n   rel_mapping (\\<le>) P P' \\<and>\n   pred_mapping (\\<lambda>i. i \\<le> j) P \\<and>\n   pred_mapping (\\<lambda>i. i \\<le> Suc j) P' \\<and>\n   (\\<forall>p \\<in> Mapping.keys db - dom P. the (Mapping.lookup db p) = [{ts. (p, ts) \\<in> \\<Gamma> \\<sigma> j}]) \\<and>\n   (\\<forall>p \\<in> dom P. list_all2 (\\<lambda>i X. X = the (V p) i) [the (P p)..<the (P' p)] (the (Mapping.lookup db p))))\"\n\n\nlift_definition mk_db :: \"(Formula.name \\<times> event_data list) set \\<Rightarrow> Formula.database\" is\n  \"\\<lambda>X p. (if p \\<in> fst ` X then Some [{ts. (p, ts) \\<in> X}] else None)\" .\n\nlemma wf_envs_mk_db: \"wf_envs \\<sigma> j Map.empty Map.empty Map.empty (mk_db (\\<Gamma> \\<sigma> j))\"\n  unfolding wf_envs_def mk_db_def\n  by transfer (force split: if_splits simp: image_iff rel_mapping_alt)\n\nlemma wf_envs_update:\n  assumes wf_envs: \"wf_envs \\<sigma> j P P' V db\"\n    and m_eq: \"m = Formula.nfv \\<phi>\"\n    and in_fv: \"{0 ..< m} \\<subseteq> fv \\<phi>\"\n    and xs: \"list_all2 (\\<lambda>i. qtable m (Formula.fv \\<phi>) (mem_restr UNIV) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>))\n      [progress \\<sigma> P \\<phi> j..<progress \\<sigma> P' \\<phi> (Suc j)] xs\"\n  shows \"wf_envs \\<sigma> j (P(p \\<mapsto> progress \\<sigma> P \\<phi> j)) (P'(p \\<mapsto> progress \\<sigma> P' \\<phi> (Suc j)))\n    (V(p \\<mapsto> \\<lambda>i. {v. length v = m \\<and> Formula.sat \\<sigma> V v i \\<phi>}))\n    (Mapping.update p (map (image (map the)) xs) db)\"\n  unfolding wf_envs_def\nproof (intro conjI ballI, goal_cases)\n  case 3\n  from assms show ?case\n    by (auto simp: wf_envs_def pred_mapping_alt progress_le progress_mono_gen\n        intro!: rel_mapping_map_upd)\nnext\n  case (6 p')\n  with assms show ?case by (cases \"p' \\<in> dom P\") (auto simp: wf_envs_def lookup_update')\nnext\n  case (7 p')\n  from xs in_fv have \"list_all2 (\\<lambda>x y. map the ` y = {v. length v = m \\<and> Formula.sat \\<sigma> V v x \\<phi>})\n      [progress \\<sigma> P \\<phi> j..<progress \\<sigma> P' \\<phi> (Suc j)] xs\"\n    by (elim list.rel_mono_strong) (auto 0 3 simp: wf_tuple_def nth_append\n      elim!: in_qtableE in_qtableI intro!: image_eqI[where x=\"map Some _\"])\n  moreover have \"list_all2 (\\<lambda>i X. X = the (V p') i) [the (P p')..<the (P' p')] (the (Mapping.lookup db p'))\"\n    if \"p \\<noteq> p'\"\n  proof -\n    from that 7 have \"p' \\<in> dom P\" by simp\n    with wf_envs show ?thesis by (simp add: wf_envs_def)\n  qed\n  ultimately show ?case\n    by (simp add: list.rel_map image_iff lookup_update')\nqed (use assms in \\<open>auto simp: wf_envs_def\\<close>)\n\nlemma wf_envs_P_simps[simp]:\n   \"wf_envs \\<sigma> j P P' V db \\<Longrightarrow> pred_mapping (\\<lambda>i. i \\<le> j) P\"\n   \"wf_envs \\<sigma> j P P' V db \\<Longrightarrow> pred_mapping (\\<lambda>i. i \\<le> Suc j) P'\"\n   \"wf_envs \\<sigma> j P P' V db \\<Longrightarrow> rel_mapping (\\<le>) P P'\"\n  unfolding wf_envs_def by auto\n\nlemma wf_envs_progress_le[simp]:\n   \"wf_envs \\<sigma> j P P' V db \\<Longrightarrow> progress \\<sigma> P \\<phi> j \\<le> j\"\n   \"wf_envs \\<sigma> j P P' V db \\<Longrightarrow> progress \\<sigma> P' \\<phi> (Suc j) \\<le> Suc j\"\n  unfolding wf_envs_def by auto\n\nlemma wf_envs_progress_regex_le[simp]:\n   \"wf_envs \\<sigma> j P P' V db \\<Longrightarrow> progress_regex \\<sigma> P r j \\<le> j\"\n   \"wf_envs \\<sigma> j P P' V db \\<Longrightarrow> progress_regex \\<sigma> P' r (Suc j) \\<le> Suc j\"\n  unfolding wf_envs_def by (auto simp: progress_regex_le)\n\nlemma wf_envs_progress_mono[simp]:\n   \"wf_envs \\<sigma> j P P' V db \\<Longrightarrow> a \\<le> b \\<Longrightarrow> progress \\<sigma> P \\<phi> a \\<le> progress \\<sigma> P' \\<phi> b\"\n  unfolding wf_envs_def\n  by (auto simp: progress_mono_gen)\n\nlemma qtable_wf_tuple_cong: \"qtable n A P Q X \\<Longrightarrow> A = B \\<Longrightarrow> (\\<And>v. wf_tuple n A v \\<Longrightarrow> P v \\<Longrightarrow> Q v = Q' v) \\<Longrightarrow> qtable n B P Q' X\"\n  unfolding qtable_def table_def by blast\n\nlemma (in maux) meval:\n  assumes \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>'\" \"wf_envs \\<sigma> j P P' V db\"\n  shows \"case meval n (\\<tau> \\<sigma> j) db \\<phi> of (xs, \\<phi>\\<^sub>n) \\<Rightarrow> wf_mformula \\<sigma> (Suc j) P' V n R \\<phi>\\<^sub>n \\<phi>' \\<and>\n    list_all2 (\\<lambda>i. qtable n (Formula.fv \\<phi>') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>'))\n    [progress \\<sigma> P \\<phi>' j..<progress \\<sigma> P' \\<phi>' (Suc j)] xs\"\n  using assms\nproof (induction \\<phi> arbitrary: db P P' V n R \\<phi>')\n  case (MRel rel)\n  then show ?case\n    by (cases rule: wf_mformula.cases)\n      (auto simp add: ball_Un intro: wf_mformula.intros table_eq_rel eq_rel_eval_trm\n        in_eq_rel qtable_empty qtable_unit_table intro!: qtableI)\nnext\n  case (MPred e ts)\n  then show ?case\n  proof (cases \"e \\<in> dom P\")\n    case True\n    with MPred(2) have \"e \\<in> Mapping.keys db\" \"e \\<in> dom P'\" \"e \\<in> dom V\"\n      \"list_all2 (\\<lambda>i X. X = the (V e) i) [the (P e)..<the (P' e)]\n         (the (Mapping.lookup db e))\" unfolding wf_envs_def rel_mapping_alt by blast+\n    with MPred(1) True show ?thesis\n      by (cases rule: wf_mformula.cases)\n        (fastforce intro!: wf_mformula.Pred qtableI bexI[where P=\"\\<lambda>x. _ = tabulate x 0 n\", OF refl]\n        elim!: list.rel_mono_strong bexI[rotated] dest: ex_match\n        simp: list.rel_map table_def match_wf_tuple in_these_eq match_eval_trm image_iff\n          list.map_comp keys_dom_lookup)\n  next\n    note MPred(1)\n    moreover\n    case False\n    moreover\n    from False MPred(2) have \"e \\<notin> dom P'\" \"e \\<notin> dom V\"\n      unfolding wf_envs_def rel_mapping_alt by auto\n    moreover\n    from False MPred(2) have *: \"e \\<in> fst ` \\<Gamma> \\<sigma> j \\<longleftrightarrow> e \\<in> Mapping.keys db\"\n      unfolding wf_envs_def by auto\n    from False MPred(2) have\n      \"e \\<in> Mapping.keys db \\<Longrightarrow> Mapping.lookup db e = Some [{ts. (e, ts) \\<in> \\<Gamma> \\<sigma> j}]\"\n      unfolding wf_envs_def keys_dom_lookup by (metis Diff_iff domD option.sel)\n    with * have \"(case Mapping.lookup db e of None \\<Rightarrow> [{}] | Some xs \\<Rightarrow> xs) = [{ts. (e, ts) \\<in> \\<Gamma> \\<sigma> j}]\"\n      by (cases \"e \\<in> fst ` \\<Gamma> \\<sigma> j\") (auto simp: image_iff keys_dom_lookup split: option.splits)\n    ultimately show ?thesis\n      by (cases rule: wf_mformula.cases)\n        (fastforce intro!: wf_mformula.Pred qtableI bexI[where P=\"\\<lambda>x. _ = tabulate x 0 n\", OF refl]\n        elim!: list.rel_mono_strong bexI[rotated] dest: ex_match\n        simp: list.rel_map table_def match_wf_tuple in_these_eq match_eval_trm image_iff list.map_comp)\n  qed\nnext\n  case (MLet p m \\<phi>1 \\<phi>2)\n  from MLet.prems(1) obtain \\<phi>1' \\<phi>2' where Let: \"\\<phi>' = Formula.Let p \\<phi>1' \\<phi>2'\" and\n    1: \"wf_mformula \\<sigma> j P V m UNIV \\<phi>1 \\<phi>1'\" and\n    fv: \"m = Formula.nfv \\<phi>1'\" \"{0..<m} \\<subseteq> fv \\<phi>1'\" and\n    2: \"wf_mformula \\<sigma> j (P(p \\<mapsto> progress \\<sigma> P \\<phi>1' j))\n      (V(p \\<mapsto> \\<lambda>i. {v. length v = m \\<and> Formula.sat \\<sigma> V v i \\<phi>1'}))\n      n R \\<phi>2 \\<phi>2'\"\n    by (cases rule: wf_mformula.cases) auto\n  obtain xs \\<phi>1_new where e1: \"meval m (\\<tau> \\<sigma> j) db \\<phi>1 = (xs, \\<phi>1_new)\" and\n      wf1: \"wf_mformula \\<sigma> (Suc j) P' V m UNIV \\<phi>1_new \\<phi>1'\" and\n      res1: \"list_all2 (\\<lambda>i. qtable m (fv \\<phi>1') (mem_restr UNIV) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>1'))\n       [progress \\<sigma> P \\<phi>1' j..<progress \\<sigma> P' \\<phi>1' (Suc j)] xs\"\n    using MLet(1)[OF 1(1) MLet.prems(2)] by (auto simp: eqTrueI[OF mem_restr_UNIV, abs_def])\n  from MLet(2)[OF 2 wf_envs_update[OF MLet.prems(2) fv res1]] wf1 e1 fv\n  show ?case unfolding Let\n    by (auto simp: fun_upd_def intro!: wf_mformula.Let)\nnext\n  case (MAnd A_\\<phi> \\<phi> pos A_\\<psi> \\<psi> buf)\n  from MAnd.prems show ?case\n    by (cases rule: wf_mformula.cases)\n      (auto simp: sat_the_restrict simp del: bin_join.simps\n        dest!: MAnd.IH split: if_splits prod.splits intro!: wf_mformula.And qtable_bin_join\n        elim: mbuf2_take_add'(1) list.rel_mono_strong[OF mbuf2_take_add'(2)])\nnext\n  case (MAndAssign \\<phi> conf)\n  from MAndAssign.prems obtain \\<phi>'' x t \\<psi>'' where\n    wf_envs: \"wf_envs \\<sigma> j P P' V db\" and\n    \\<phi>'_eq: \"\\<phi>' = formula.And \\<phi>'' \\<psi>''\" and\n    wf_\\<phi>: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>''\" and\n    \"x < n\" and\n    \"x \\<notin> fv \\<phi>''\" and\n    fv_t_subset: \"fv_trm t \\<subseteq> fv \\<phi>''\" and\n    conf: \"(x, t) = conf\" and\n    \\<psi>''_eqs: \"\\<psi>'' = formula.Eq (trm.Var x) t \\<or> \\<psi>'' = formula.Eq t (trm.Var x)\"\n    by (cases rule: wf_mformula.cases)\n  from wf_\\<phi> wf_envs obtain xs \\<phi>\\<^sub>n where\n    meval_eq: \"meval n (\\<tau> \\<sigma> j) db \\<phi> = (xs, \\<phi>\\<^sub>n)\" and\n    wf_\\<phi>\\<^sub>n: \"wf_mformula \\<sigma> (Suc j) P' V n R \\<phi>\\<^sub>n \\<phi>''\" and\n    xs: \"list_all2 (\\<lambda>i. qtable n (fv \\<phi>'') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>''))\n        [progress \\<sigma> P \\<phi>'' j..<progress \\<sigma> P' \\<phi>'' (Suc j)] xs\"\n    by (auto dest!: MAndAssign.IH)\n  have progress_eqs:\n      \"progress \\<sigma> P \\<phi>' j = progress \\<sigma> P \\<phi>'' j\"\n      \"progress \\<sigma> P' \\<phi>' (Suc j) = progress \\<sigma> P' \\<phi>'' (Suc j)\"\n    using \\<psi>''_eqs wf_envs_progress_le[OF wf_envs] by (auto simp: \\<phi>'_eq)\n\n  show ?case proof (simp add: meval_eq, intro conjI)\n    show \"wf_mformula \\<sigma> (Suc j) P' V n R (MAndAssign \\<phi>\\<^sub>n conf) \\<phi>'\"\n      unfolding \\<phi>'_eq\n      by (rule wf_mformula.AndAssign) fact+\n  next\n    show \"list_all2 (\\<lambda>i. qtable n (fv \\<phi>') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>'))\n        [progress \\<sigma> P \\<phi>' j..<progress \\<sigma> P' \\<phi>' (Suc j)] (map ((`) (eval_assignment conf)) xs)\"\n      unfolding list.rel_map progress_eqs conf[symmetric] eval_assignment.simps\n      using xs\n    proof (rule list.rel_mono_strong)\n      fix i X\n      assume qtable: \"qtable n (fv \\<phi>'') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>'') X\"\n      then show \"qtable n (fv \\<phi>') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<phi>')\n          ((\\<lambda>y. y[x := Some (meval_trm t y)]) ` X)\"\n      proof (rule qtable_assign)\n        show \"x < n\" by fact\n        show \"insert x (fv \\<phi>'') = fv \\<phi>'\"\n          using \\<psi>''_eqs fv_t_subset by (auto simp: \\<phi>'_eq)\n        show \"x \\<notin> fv \\<phi>''\" by fact\n      next\n        fix v\n        assume wf_v: \"wf_tuple n (fv \\<phi>') v\" and \"mem_restr R v\"\n        then show \"mem_restr R (restrict (fv \\<phi>'') v)\" by simp\n\n        assume sat: \"Formula.sat \\<sigma> V (map the v) i \\<phi>'\"\n        then have A: \"Formula.sat \\<sigma> V (map the (restrict (fv \\<phi>'') v)) i \\<phi>''\" (is ?A)\n          by (simp add: \\<phi>'_eq sat_the_restrict)\n        have \"map the v ! x = Formula.eval_trm (map the v) t\"\n          using sat \\<psi>''_eqs by (auto simp: \\<phi>'_eq)\n        also have \"... = Formula.eval_trm (map the (restrict (fv \\<phi>'') v)) t\"\n          using fv_t_subset by (auto simp: map_the_restrict intro!: eval_trm_fv_cong)\n        finally have \"map the v ! x = meval_trm t (restrict (fv \\<phi>'') v)\"\n          using meval_trm_eval_trm[of n \"fv \\<phi>''\" \"restrict (fv \\<phi>'') v\" t]\n            fv_t_subset wf_v wf_mformula_wf_set[unfolded wf_set_def, OF wf_\\<phi>]\n          by (fastforce simp: \\<phi>'_eq intro!: wf_tuple_restrict)\n        then have B: \"v ! x = Some (meval_trm t (restrict (fv \\<phi>'') v))\" (is ?B)\n          using \\<psi>''_eqs wf_v \\<open>x < n\\<close> by (auto simp: wf_tuple_def \\<phi>'_eq)\n        from A B show \"?A \\<and> ?B\" ..\n      next\n        fix v\n        assume wf_v: \"wf_tuple n (fv \\<phi>'') v\" and \"mem_restr R v\"\n          and sat: \"Formula.sat \\<sigma> V (map the v) i \\<phi>''\"\n        let ?v = \"v[x := Some (meval_trm t v)]\"\n        from sat have A: \"Formula.sat \\<sigma> V (map the ?v) i \\<phi>''\"\n          using \\<open>x \\<notin> fv \\<phi>''\\<close> by (simp add: sat_the_update)\n        have \"y \\<in> fv_trm t \\<Longrightarrow> x \\<noteq> y\" for y\n          using fv_t_subset \\<open>x \\<notin> fv \\<phi>''\\<close> by auto\n        then have B: \"Formula.sat \\<sigma> V (map the ?v) i \\<psi>''\"\n          using \\<psi>''_eqs meval_trm_eval_trm[of n \"fv \\<phi>''\" v t] \\<open>x < n\\<close>\n            fv_t_subset wf_v wf_mformula_wf_set[unfolded wf_set_def, OF wf_\\<phi>]\n          by (auto simp: wf_tuple_def map_update intro!: eval_trm_fv_cong)\n        from A B show \"Formula.sat \\<sigma> V (map the ?v) i \\<phi>'\"\n          by (simp add: \\<phi>'_eq)\n      qed\n    qed\n  qed\nnext\n  case (MAndRel \\<phi> conf)\n  from MAndRel.prems show ?case\n    by (cases rule: wf_mformula.cases)\n      (auto simp: progress_constraint progress_le list.rel_map fv_formula_of_constraint\n        Un_absorb2 wf_mformula_wf_set[unfolded wf_set_def] split: prod.splits\n        dest!: MAndRel.IH[where db=db and P=P and P'=P'] eval_constraint_sat_eq[THEN iffD2]\n        intro!: wf_mformula.AndRel\n        elim!: list.rel_mono_strong qtable_filter eval_constraint_sat_eq[THEN iffD1])\nnext\n  case (MAnds A_pos A_neg l buf)\n  note mbufn_take.simps[simp del] mbufn_add.simps[simp del] mmulti_join.simps[simp del]\n\n  from MAnds.prems obtain pos neg l' where\n    wf_l: \"list_all2 (wf_mformula \\<sigma> j P V n R) l (pos @ map remove_neg neg)\" and\n    wf_buf: \"wf_mbufn (progress \\<sigma> P (formula.Ands l') j) (map (\\<lambda>\\<psi>. progress \\<sigma> P \\<psi> j) (pos @ map remove_neg neg))\n      (map (\\<lambda>\\<psi> i. qtable n (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>)) (pos @ map remove_neg neg)) buf\" and\n    posneg: \"(pos, neg) = partition safe_formula l'\" and\n    \"pos \\<noteq> []\" and\n    safe_neg: \"list_all safe_formula (map remove_neg neg)\" and\n    A_eq: \"A_pos = map fv pos\" \"A_neg = map fv neg\" and\n    fv_subset: \"\\<Union> (set A_neg) \\<subseteq> \\<Union> (set A_pos)\" and\n    \"\\<phi>' = Formula.Ands l'\"\n    by (cases rule: wf_mformula.cases) simp\n  have progress_eq: \"progress \\<sigma> P' (formula.Ands l') (Suc j) =\n      Mini (progress \\<sigma> P (formula.Ands l') j) (map (\\<lambda>\\<psi>. progress \\<sigma> P' \\<psi> (Suc j)) (pos @ map remove_neg neg))\"\n    using \\<open>pos \\<noteq> []\\<close> posneg\n    by (auto simp: Mini_def image_Un[symmetric] Collect_disj_eq[symmetric] intro!: arg_cong[where f=Min])\n\n  have join_ok: \"qtable n (\\<Union> (fv ` set l')) (mem_restr R)\n        (\\<lambda>v. list_all (Formula.sat \\<sigma> V (map the v) k) l')\n        (mmulti_join n A_pos A_neg L)\"\n    if args_ok: \"list_all2 (\\<lambda>x. qtable n (fv x) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) k x))\n        (pos @ map remove_neg neg) L\"\n    for k L\n  proof (rule qtable_mmulti_join)\n    let ?ok = \"\\<lambda>A Qi X. qtable n A (mem_restr R) Qi X \\<and> wf_set n A\"\n    let ?L_pos = \"take (length A_pos) L\"\n    let ?L_neg = \"drop (length A_pos) L\"\n    have 1: \"length pos \\<le> length L\"\n      using args_ok by (auto dest!: list_all2_lengthD)\n    show \"list_all3 ?ok A_pos (map (\\<lambda>\\<psi> v. Formula.sat \\<sigma> V (map the v) k \\<psi>) pos) ?L_pos\"\n      using args_ok wf_l unfolding A_eq\n      by (auto simp add: list_all3_conv_all_nth list_all2_conv_all_nth nth_append\n          split: if_splits intro!: wf_mformula_wf_set[of \\<sigma> j P V n R]\n          dest: order.strict_trans2[OF _ 1])\n    from args_ok have prems_neg: \"list_all2 (\\<lambda>\\<psi>. qtable n (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) k (remove_neg \\<psi>))) neg ?L_neg\"\n      by (auto simp: A_eq list_all2_append1 list.rel_map)\n    show \"list_all3 ?ok A_neg (map (\\<lambda>\\<psi> v. Formula.sat \\<sigma> V (map the v) k (remove_neg \\<psi>)) neg) ?L_neg\"\n      using prems_neg wf_l unfolding A_eq\n      by (auto simp add: list_all3_conv_all_nth list_all2_conv_all_nth list_all_length nth_append less_diff_conv\n          split: if_splits intro!: wf_mformula_wf_set[of \\<sigma> j P V n R _ \"remove_neg _\", simplified])\n    show \"\\<Union>(fv ` set l') = \\<Union>(set A_pos)\"\n      using fv_subset posneg unfolding A_eq by auto\n    show \"L = take (length A_pos) L @ drop (length A_pos) L\" by simp\n    show \"A_pos \\<noteq> []\" using \\<open>pos \\<noteq> []\\<close> A_eq by simp\n\n    fix x :: \"event_data tuple\"\n    assume \"wf_tuple n (\\<Union> (fv ` set l')) x\" and \"mem_restr R x\"\n    then show \"list_all (\\<lambda>A. mem_restr R (restrict A x)) A_pos\"\n      and \"list_all (\\<lambda>A. mem_restr R (restrict A x)) A_neg\"\n      by (simp_all add: list.pred_set)\n\n    have \"list_all Formula.is_Neg neg\"\n      using posneg safe_neg\n      by (auto 0 3 simp add: list.pred_map elim!: list.pred_mono_strong\n          intro: formula.exhaust[of \\<psi> \"Formula.is_Neg \\<psi>\" for \\<psi>])\n    then have \"list_all (\\<lambda>\\<psi>. Formula.sat \\<sigma> V (map the v) i (remove_neg \\<psi>) \\<longleftrightarrow>\n      \\<not> Formula.sat \\<sigma> V (map the v) i \\<psi>) neg\" for v i\n      by (fastforce simp: Formula.is_Neg_def elim!: list.pred_mono_strong)\n    then show \"list_all (Formula.sat \\<sigma> V (map the x) k) l' =\n       (list_all2 (\\<lambda>A Qi. Qi (restrict A x)) A_pos\n         (map (\\<lambda>\\<psi> v. Formula.sat \\<sigma> V (map the v) k \\<psi>) pos) \\<and>\n        list_all2 (\\<lambda>A Qi. \\<not> Qi (restrict A x)) A_neg\n         (map (\\<lambda>\\<psi> v. Formula.sat \\<sigma> V (map the v) k\n                       (remove_neg \\<psi>))\n           neg))\"\n      using posneg\n      by (auto simp add: A_eq list_all2_conv_all_nth list_all_length sat_the_restrict\n          elim: nth_filter nth_partition[where P=safe_formula and Q=\"Formula.sat _ _ _ _\"])\n  qed fact\n\n  from MAnds.prems(2) show ?case\n    unfolding \\<open>\\<phi>' = Formula.Ands l'\\<close>\n    by (auto 0 3 simp add: list.rel_map progress_eq map2_map_map list_all3_map\n        list_all3_list_all2_conv list.pred_map\n        simp del: set_append map_append progress_simps split: prod.splits\n        intro!: wf_mformula.Ands[OF _ _ posneg \\<open>pos \\<noteq> []\\<close> safe_neg A_eq fv_subset]\n        list.rel_mono_strong[OF wf_l] wf_mbufn_add[OF wf_buf]\n        list.rel_flip[THEN iffD1, OF list.rel_mono_strong, OF wf_l]\n        list.rel_refl join_ok[unfolded list.pred_set]\n        dest!: MAnds.IH[OF _ _ MAnds.prems(2), rotated]\n        elim!: wf_mbufn_take list_all2_appendI\n        elim: mbufn_take_induct[OF _ wf_mbufn_add[OF wf_buf]])\nnext\n  case (MOr \\<phi> \\<psi> buf)\n  from MOr.prems show ?case\n    by (cases rule: wf_mformula.cases)\n      (auto dest!: MOr.IH split: if_splits prod.splits intro!: wf_mformula.Or qtable_union\n        elim: mbuf2_take_add'(1) list.rel_mono_strong[OF mbuf2_take_add'(2)])\nnext\n  case (MNeg \\<phi>)\n  have *: \"qtable n {} (mem_restr R) (\\<lambda>v. P v) X \\<Longrightarrow>\n    \\<not> qtable n {} (mem_restr R) (\\<lambda>v. \\<not> P v) empty_table \\<Longrightarrow> x \\<in> X \\<Longrightarrow> False\" for P x X\n    using nullary_qtable_cases qtable_unit_empty_table by fastforce\n  from MNeg.prems show ?case\n    by (cases rule: wf_mformula.cases)\n      (auto 0 4 intro!: wf_mformula.Neg dest!: MNeg.IH\n        simp add: list.rel_map\n        dest: nullary_qtable_cases qtable_unit_empty_table intro!: qtable_empty_unit_table\n        elim!: list.rel_mono_strong elim: *)\nnext\n  case (MExists \\<phi>)\n  from MExists.prems show ?case\n    by (cases rule: wf_mformula.cases)\n      (force simp: list.rel_map fvi_Suc sat_fv_cong nth_Cons'\n        intro!: wf_mformula.Exists dest!: MExists.IH qtable_project_fv\n        elim!: list.rel_mono_strong table_fvi_tl qtable_cong sat_fv_cong[THEN iffD1, rotated -1]\n        split: if_splits)+\nnext\n  case (MAgg g0 y \\<omega> b f \\<phi>)\n  from MAgg.prems show ?case\n    using wf_mformula_wf_set[OF MAgg.prems(1), unfolded wf_set_def]\n    by (cases rule: wf_mformula.cases)\n      (auto 0 3 simp add: list.rel_map simp del: sat.simps fvi.simps split: prod.split\n        intro!: wf_mformula.Agg qtable_eval_agg dest!: MAgg.IH elim!: list.rel_mono_strong)\nnext\n  case (MPrev I \\<phi> first buf nts)\n  from MPrev.prems show ?case\n  proof (cases rule: wf_mformula.cases)\n    case (Prev \\<psi>)\n    let ?xs = \"fst (meval n (\\<tau> \\<sigma> j) db \\<phi>)\"\n    let ?\\<phi> = \"snd (meval n (\\<tau> \\<sigma> j) db \\<phi>)\"\n    let ?ls = \"fst (mprev_next I (buf @ ?xs) (nts @ [\\<tau> \\<sigma> j]))\"\n    let ?rs = \"fst (snd (mprev_next I (buf @ ?xs) (nts @ [\\<tau> \\<sigma> j])))\"\n    let ?ts = \"snd (snd (mprev_next I (buf @ ?xs) (nts @ [\\<tau> \\<sigma> j])))\"\n    let ?P = \"\\<lambda>i X. qtable n (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>) X\"\n    let ?min = \"min (progress \\<sigma> P' \\<psi> (Suc j)) (Suc j - 1)\"\n    from Prev MPrev.IH[OF _ MPrev.prems(2), of n R \\<psi>] have IH: \"wf_mformula \\<sigma> (Suc j) P' V n R ?\\<phi> \\<psi>\" and\n      \"list_all2 ?P [progress \\<sigma> P \\<psi> j..<progress \\<sigma> P' \\<psi> (Suc j)] ?xs\" by auto\n    with Prev(4,5) MPrev.prems(2) have \"list_all2 (\\<lambda>i X. if mem (\\<tau> \\<sigma> (Suc i) - \\<tau> \\<sigma> i) I then ?P i X else X = empty_table)\n        [min (progress \\<sigma> P \\<psi> j) (j - 1)..<?min] ?ls \\<and>\n       list_all2 ?P [?min..<progress \\<sigma> P' \\<psi> (Suc j)] ?rs \\<and>\n       list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [?min..<Suc j] ?ts\"\n      by (intro mprev) (auto intro!: list_all2_upt_append list_all2_appendI order.trans[OF min.cobounded1])\n    moreover have \"min (Suc (progress \\<sigma> P \\<psi> j)) j = Suc (min (progress \\<sigma> P \\<psi> j) (j-1))\" if \"j > 0\"\n      using that by auto\n    ultimately show ?thesis using Prev(1,3) MPrev.prems(2) IH\n      by (auto simp: map_Suc_upt[symmetric] upt_Suc[of 0] list.rel_map qtable_empty_iff\n          simp del: upt_Suc elim!: wf_mformula.Prev list.rel_mono_strong\n          split: prod.split if_split_asm)\n  qed\nnext\n  case (MNext I \\<phi> first nts)\n  from MNext.prems show ?case\n  proof (cases rule: wf_mformula.cases)\n    case (Next \\<psi>)\n\n    have min[simp]:\n      \"min (progress \\<sigma> P \\<psi> j - Suc 0) (j - Suc 0) = progress \\<sigma> P \\<psi> j - Suc 0\"\n      \"min (progress \\<sigma> P' \\<psi> (Suc j) - Suc 0) j = progress \\<sigma> P' \\<psi> (Suc j) - Suc 0\"\n      using wf_envs_progress_le[OF MNext.prems(2), of \\<psi>] by auto\n\n    let ?xs = \"fst (meval n (\\<tau> \\<sigma> j) db \\<phi>)\"\n    let ?ys = \"case (?xs, first) of (_ # xs, True) \\<Rightarrow> xs | _ \\<Rightarrow> ?xs\"\n    let ?\\<phi> = \"snd (meval n (\\<tau> \\<sigma> j) db \\<phi>)\"\n    let ?ls = \"fst (mprev_next I ?ys (nts @ [\\<tau> \\<sigma> j]))\"\n    let ?rs = \"fst (snd (mprev_next I ?ys (nts @ [\\<tau> \\<sigma> j])))\"\n    let ?ts = \"snd (snd (mprev_next I ?ys (nts @ [\\<tau> \\<sigma> j])))\"\n    let ?P = \"\\<lambda>i X. qtable n (fv \\<psi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i \\<psi>) X\"\n    let ?min = \"min (progress \\<sigma> P' \\<psi> (Suc j) - 1) (Suc j - 1)\"\n    from Next MNext.IH[OF _ MNext.prems(2), of n R \\<psi>] have IH: \"wf_mformula \\<sigma> (Suc j) P' V  n R ?\\<phi> \\<psi>\"\n      \"list_all2 ?P [progress \\<sigma> P \\<psi> j..<progress \\<sigma> P' \\<psi> (Suc j)] ?xs\" by auto\n    with Next have \"list_all2 (\\<lambda>i X. if mem (\\<tau> \\<sigma> (Suc i) - \\<tau> \\<sigma> i) I then ?P (Suc i) X else X = empty_table)\n        [progress \\<sigma> P \\<psi> j - 1..<?min] ?ls \\<and>\n       list_all2 ?P [Suc ?min..<progress \\<sigma> P' \\<psi> (Suc j)] ?rs \\<and>\n       list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [?min..<Suc j] ?ts\" if \"progress \\<sigma> P \\<psi> j < progress \\<sigma> P' \\<psi> (Suc j)\"\n      using that wf_envs_progress_le[OF MNext.prems(2), of \\<psi>]\n      by (intro mnext) (auto simp: list_all2_Cons2 upt_eq_Cons_conv\n          intro!: list_all2_upt_append list_all2_appendI split: list.splits)\n    then show ?thesis using wf_envs_progress_le[OF MNext.prems(2), of \\<psi>]\n      wf_envs_progress_mono[OF MNext.prems(2), of j \"Suc j\" \\<psi>, simplified] Next IH\n      by (cases \"progress \\<sigma> P' \\<psi> (Suc j) > progress \\<sigma> P \\<psi> j\")\n        (auto 0 3 simp: qtable_empty_iff le_Suc_eq le_diff_conv\n          elim!: wf_mformula.Next list.rel_mono_strong list_all2_appendI\n          split: prod.split list.splits if_split_asm)  (* slow 5 sec*)\n  qed\nnext\n  case (MSince args \\<phi> \\<psi> buf nts aux)\n  note sat.simps[simp del]\n  from MSince.prems obtain \\<phi>'' \\<phi>''' \\<psi>'' I where Since_eq: \"\\<phi>' = Formula.Since \\<phi>''' I \\<psi>''\"\n    and pos: \"if args_pos args then \\<phi>''' = \\<phi>'' else \\<phi>''' = Formula.Neg \\<phi>''\"\n    and pos_eq: \"safe_formula \\<phi>''' = args_pos args\"\n    and \\<phi>: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>''\"\n    and \\<psi>: \"wf_mformula \\<sigma> j P V n R \\<psi> \\<psi>''\"\n    and fvi_subset: \"Formula.fv \\<phi>'' \\<subseteq> Formula.fv \\<psi>''\"\n    and buf: \"wf_mbuf2' \\<sigma> P V j n R \\<phi>'' \\<psi>'' buf\"\n    and nts: \"wf_ts \\<sigma> P j \\<phi>'' \\<psi>'' nts\"\n    and aux: \"wf_since_aux \\<sigma> V R args \\<phi>'' \\<psi>'' aux (progress \\<sigma> P (Formula.Since \\<phi>''' I \\<psi>'') j)\"\n    and args_ivl: \"args_ivl args = I\"\n    and args_n: \"args_n args = n\"\n    and args_L: \"args_L args = Formula.fv \\<phi>''\"\n    and args_R: \"args_R args = Formula.fv \\<psi>''\"\n    by (cases rule: wf_mformula.cases) (auto)\n  have \\<phi>''': \"Formula.fv \\<phi>''' = Formula.fv \\<phi>''\" \"progress \\<sigma> P \\<phi>''' j = progress \\<sigma> P \\<phi>'' j\"\n    \"progress \\<sigma> P' \\<phi>''' j = progress \\<sigma> P' \\<phi>'' j\" for j\n    using pos by (simp_all split: if_splits)\n  from MSince.prems(2) have nts_snoc: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i)\n    [min (progress \\<sigma> P \\<phi>'' j) (progress \\<sigma> P \\<psi>'' j)..<Suc j] (nts @ [\\<tau> \\<sigma> j])\"\n    using nts unfolding wf_ts_def\n    by (auto simp add: wf_envs_progress_le[THEN min.coboundedI1] intro: list_all2_appendI)\n  have update: \"wf_since_aux \\<sigma> V R args \\<phi>'' \\<psi>'' (snd (zs, aux')) (progress \\<sigma> P' (Formula.Since \\<phi>''' I \\<psi>'') (Suc j)) \\<and>\n    list_all2 (\\<lambda>i. qtable n (Formula.fv \\<phi>''' \\<union> Formula.fv \\<psi>'') (mem_restr R)\n      (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (Formula.Since \\<phi>''' I \\<psi>'')))\n      [progress \\<sigma> P (Formula.Since \\<phi>''' I \\<psi>'') j..<progress \\<sigma> P' (Formula.Since \\<phi>''' I \\<psi>'') (Suc j)] (fst (zs, aux'))\"\n    if eval_\\<phi>: \"fst (meval n (\\<tau> \\<sigma> j) db \\<phi>) = xs\"\n      and eval_\\<psi>: \"fst (meval n (\\<tau> \\<sigma> j) db \\<psi>) = ys\"\n      and eq: \"mbuf2t_take (\\<lambda>r1 r2 t (zs, aux).\n        case update_since args r1 r2 t aux of (z, x) \\<Rightarrow> (zs @ [z], x))\n        ([], aux) (mbuf2_add xs ys buf) (nts @ [\\<tau> \\<sigma> j]) = ((zs, aux'), buf', nts')\"\n    for xs ys zs aux' buf' nts'\n    unfolding progress_simps \\<phi>'''\n  proof (rule mbuf2t_take_add_induct'[where j=j and j'=\"Suc j\" and z'=\"(zs, aux')\",\n      OF eq wf_envs_P_simps[OF MSince.prems(2)] buf nts_snoc],\n      goal_cases xs ys _ base step)\n    case xs\n    then show ?case\n      using MSince.IH(1)[OF \\<phi> MSince.prems(2)] eval_\\<phi> by auto\n  next\n    case ys\n    then show ?case\n      using MSince.IH(2)[OF \\<psi> MSince.prems(2)] eval_\\<psi> by auto\n  next\n    case base\n    then show ?case\n      using aux by (simp add: \\<phi>''')\n  next\n    case (step k X Y z)\n    then show ?case\n      using fvi_subset pos\n      by (auto 0 3 simp: args_ivl args_n args_L args_R Un_absorb1\n          elim!: update_since(1) list_all2_appendI dest!: update_since(2)\n          split: prod.split if_splits)\n  qed simp\n  with MSince.IH(1)[OF \\<phi> MSince.prems(2)] MSince.IH(2)[OF \\<psi> MSince.prems(2)] show ?case\n    by (auto 0 3 simp: Since_eq split: prod.split\n        intro: wf_mformula.Since[OF _ _ pos pos_eq args_ivl args_n args_L args_R fvi_subset]\n        elim: mbuf2t_take_add'(1)[OF _ wf_envs_P_simps[OF MSince.prems(2)] buf nts_snoc]\n              mbuf2t_take_add'(2)[OF _ wf_envs_P_simps[OF MSince.prems(2)] buf nts_snoc])\nnext\n  case (MUntil args \\<phi> \\<psi> buf nts aux)\n  note sat.simps[simp del] progress_simps[simp del]\n  from MUntil.prems obtain \\<phi>'' \\<phi>''' \\<psi>'' I where Until_eq: \"\\<phi>' = Formula.Until \\<phi>''' I \\<psi>''\"\n    and pos: \"if args_pos args then \\<phi>''' = \\<phi>'' else \\<phi>''' = Formula.Neg \\<phi>''\"\n    and pos_eq: \"safe_formula \\<phi>''' = args_pos args\"\n    and \\<phi>: \"wf_mformula \\<sigma> j P V n R \\<phi> \\<phi>''\"\n    and \\<psi>: \"wf_mformula \\<sigma> j P V n R \\<psi> \\<psi>''\"\n    and fvi_subset: \"Formula.fv \\<phi>'' \\<subseteq> Formula.fv \\<psi>''\"\n    and buf: \"wf_mbuf2' \\<sigma> P V j n R \\<phi>'' \\<psi>'' buf\"\n    and nts: \"wf_ts \\<sigma> P j \\<phi>'' \\<psi>'' nts\"\n    and aux: \"wf_until_aux \\<sigma> V R args \\<phi>'' \\<psi>'' aux (progress \\<sigma> P (Formula.Until \\<phi>''' I \\<psi>'') j)\"\n    and args_ivl: \"args_ivl args = I\"\n    and args_n: \"args_n args = n\"\n    and args_L: \"args_L args = Formula.fv \\<phi>''\"\n    and args_R: \"args_R args = Formula.fv \\<psi>''\"\n    and length_aux: \"progress \\<sigma> P (Formula.Until \\<phi>''' I \\<psi>'') j + length_muaux args aux =\n      min (progress \\<sigma> P \\<phi>'' j) (progress \\<sigma> P \\<psi>'' j)\"\n    by (cases rule: wf_mformula.cases) (auto)\n  define pos where args_pos: \"pos = args_pos args\"\n  have \\<phi>''': \"progress \\<sigma> P \\<phi>''' j = progress \\<sigma> P \\<phi>'' j\"  \"progress \\<sigma> P' \\<phi>''' j = progress \\<sigma> P' \\<phi>'' j\" for j\n    using pos by (simp_all add: progress.simps split: if_splits)\n  from MUntil.prems(2) have nts_snoc: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i)\n    [min (progress \\<sigma> P \\<phi>'' j) (progress \\<sigma> P \\<psi>'' j)..<Suc j] (nts @ [\\<tau> \\<sigma> j])\"\n    using nts unfolding wf_ts_def\n    by (auto simp add: wf_envs_progress_le[THEN min.coboundedI1] intro: list_all2_appendI)\n  {\n    fix xs ys zs aux' aux'' buf' nts'\n    assume eval_\\<phi>: \"fst (meval n (\\<tau> \\<sigma> j) db \\<phi>) = xs\"\n      and eval_\\<psi>: \"fst (meval n (\\<tau> \\<sigma> j) db \\<psi>) = ys\"\n      and eq1: \"mbuf2t_take (add_new_muaux args) aux (mbuf2_add xs ys buf) (nts @ [\\<tau> \\<sigma> j]) =\n        (aux', buf', nts')\"\n      and eq2: \"eval_muaux args (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # _ \\<Rightarrow> nt) aux' = (zs, aux'')\"\n    define ne where \"ne \\<equiv> progress \\<sigma> P (Formula.Until \\<phi>''' I \\<psi>'') j\"\n    have update1: \"wf_until_aux \\<sigma> V R args \\<phi>'' \\<psi>'' aux' (progress \\<sigma> P (Formula.Until \\<phi>''' I \\<psi>'') j) \\<and>\n      ne + length_muaux args aux' = min (progress \\<sigma> P' \\<phi>''' (Suc j)) (progress \\<sigma> P' \\<psi>'' (Suc j))\"\n      using MUntil.IH(1)[OF \\<phi> MUntil.prems(2)] eval_\\<phi> MUntil.IH(2)[OF \\<psi> MUntil.prems(2)]\n        eval_\\<psi> nts_snoc nts_snoc length_aux aux fvi_subset\n      unfolding \\<phi>'''\n      by (elim mbuf2t_take_add_induct'[where j'=\"Suc j\", OF eq1 wf_envs_P_simps[OF MUntil.prems(2)] buf])\n        (auto simp: args_n args_L args_R ne_def wf_update_until)\n    then obtain cur auxlist' where valid_aux': \"valid_muaux args cur aux' auxlist'\" and\n      cur: \"cur = (if ne + length auxlist' = 0 then 0 else \\<tau> \\<sigma> (ne + length auxlist' - 1))\" and\n      wf_auxlist': \"wf_until_auxlist \\<sigma> V n R pos \\<phi>'' I \\<psi>'' auxlist' (progress \\<sigma> P (Formula.Until \\<phi>''' I \\<psi>'') j)\"\n      unfolding wf_until_aux_def ne_def args_ivl args_n args_pos by auto\n    have length_aux': \"length_muaux args aux' = length auxlist'\"\n      using valid_length_muaux[OF valid_aux'] .\n    have nts': \"wf_ts \\<sigma> P' (Suc j) \\<phi>'' \\<psi>'' nts'\"\n      using MUntil.IH(1)[OF \\<phi> MUntil.prems(2)] eval_\\<phi> MUntil.IH(2)[OF \\<psi> MUntil.prems(2)]\n        MUntil.prems(2) eval_\\<psi> nts_snoc\n      unfolding wf_ts_def\n      by (intro mbuf2t_take_eqD(2)[OF eq1]) (auto intro: wf_mbuf2_add buf[unfolded wf_mbuf2'_def])\n    define zs'' where \"zs'' = fst (eval_until I (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt) auxlist')\"\n    define auxlist'' where \"auxlist'' = snd (eval_until I (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt) auxlist')\"\n    have current_w_le: \"cur \\<le> (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt)\"\n    proof (cases nts')\n      case Nil\n      have p_le: \"min (progress \\<sigma> P' \\<phi>''' (Suc j)) (progress \\<sigma> P' \\<psi>'' (Suc j)) - 1 \\<le> j\"\n        using wf_envs_progress_le[OF MUntil.prems(2)]\n        by (auto simp: min_def le_diff_conv)\n      then show ?thesis\n        unfolding cur conjunct2[OF update1, unfolded length_aux']\n        using Nil by auto\n    next\n      case (Cons nt x)\n      have progress_\\<phi>''': \"progress \\<sigma> P' \\<phi>'' (Suc j) = progress \\<sigma> P' \\<phi>''' (Suc j)\"\n        using pos by (auto simp add: progress.simps split: if_splits)\n      have \"nt = \\<tau> \\<sigma> (min (progress \\<sigma> P' \\<phi>'' (Suc j)) (progress \\<sigma> P' \\<psi>'' (Suc j)))\"\n        using nts'[unfolded wf_ts_def Cons]\n        unfolding list_all2_Cons2 upt_eq_Cons_conv by auto\n      then show ?thesis\n        unfolding cur conjunct2[OF update1, unfolded length_aux'] Cons progress_\\<phi>'''\n        by (auto split: if_splits list.splits intro!: \\<tau>_mono)\n    qed\n    have valid_aux'': \"valid_muaux args cur aux'' auxlist''\"\n      using valid_eval_muaux[OF valid_aux' current_w_le eq2, of zs'' auxlist'']\n      by (auto simp add: args_ivl zs''_def auxlist''_def)\n    have length_aux'': \"length_muaux args aux'' = length auxlist''\"\n      using valid_length_muaux[OF valid_aux''] .\n    have eq2': \"eval_until I (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # _ \\<Rightarrow> nt) auxlist' = (zs, auxlist'')\"\n      using valid_eval_muaux[OF valid_aux' current_w_le eq2, of zs'' auxlist'']\n      by (auto simp add: args_ivl zs''_def auxlist''_def)\n    have length_aux'_aux'': \"length_muaux args aux' = length zs + length_muaux args aux''\"\n      using eval_until_length[OF eq2'] unfolding length_aux' length_aux'' .\n    have \"i \\<le> progress \\<sigma> P' (Formula.Until \\<phi>''' I \\<psi>'') (Suc j) \\<Longrightarrow>\n      wf_until_auxlist \\<sigma> V n R pos \\<phi>'' I \\<psi>'' auxlist' i \\<Longrightarrow>\n      i + length auxlist' = min (progress \\<sigma> P' \\<phi>''' (Suc j)) (progress \\<sigma> P' \\<psi>'' (Suc j)) \\<Longrightarrow>\n      wf_until_auxlist \\<sigma> V n R pos \\<phi>'' I \\<psi>'' auxlist'' (progress \\<sigma> P' (Formula.Until \\<phi>''' I \\<psi>'') (Suc j)) \\<and>\n        i + length zs = progress \\<sigma> P' (Formula.Until \\<phi>''' I \\<psi>'') (Suc j) \\<and>\n        i + length zs + length auxlist'' = min (progress \\<sigma> P' \\<phi>''' (Suc j)) (progress \\<sigma> P' \\<psi>'' (Suc j)) \\<and>\n        list_all2 (\\<lambda>i. qtable n (Formula.fv \\<psi>'') (mem_restr R)\n          (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (Formula.Until (if pos then \\<phi>'' else Formula.Neg \\<phi>'') I \\<psi>'')))\n          [i..<i + length zs] zs\" for i\n      using eq2'\n    proof (induction auxlist' arbitrary: zs auxlist'' i)\n      case Nil\n      then show ?case\n        by (auto dest!: antisym[OF progress_Until_le])\n    next\n      case (Cons a aux')\n      obtain t a1 a2 where \"a = (t, a1, a2)\" by (cases a)\n      from Cons.prems(2) have aux': \"wf_until_auxlist \\<sigma> V n R pos \\<phi>'' I \\<psi>'' aux' (Suc i)\"\n        by (rule wf_until_aux_Cons)\n      from Cons.prems(2) have 1: \"t = \\<tau> \\<sigma> i\"\n        unfolding \\<open>a = (t, a1, a2)\\<close> by (rule wf_until_aux_Cons1)\n      from Cons.prems(2) have 3: \"qtable n (Formula.fv \\<psi>'') (mem_restr R) (\\<lambda>v.\n        (\\<exists>j\\<ge>i. j < Suc (i + length aux') \\<and> mem (\\<tau> \\<sigma> j - \\<tau> \\<sigma> i) I \\<and> Formula.sat \\<sigma> V (map the v) j \\<psi>'' \\<and>\n        (\\<forall>k\\<in>{i..<j}. if pos then Formula.sat \\<sigma> V (map the v) k \\<phi>'' else \\<not> Formula.sat \\<sigma> V (map the v) k \\<phi>''))) a2\"\n        unfolding \\<open>a = (t, a1, a2)\\<close> by (rule wf_until_aux_Cons3)\n      from Cons.prems(3) have Suc_i_aux': \"Suc i + length aux' =\n          min (progress \\<sigma> P' \\<phi>''' (Suc j)) (progress \\<sigma> P' \\<psi>'' (Suc j))\"\n        by simp\n      have \"i \\<ge> progress \\<sigma> P' (Formula.Until \\<phi>''' I \\<psi>'') (Suc j)\"\n        if \"enat (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt) \\<le> enat t + right I\"\n        using that nts' unfolding wf_ts_def progress.simps\n        by (auto simp add: 1 list_all2_Cons2 upt_eq_Cons_conv \\<phi>'''\n            intro!: cInf_lower \\<tau>_mono elim!: order.trans[rotated] simp del: upt_Suc split: if_splits list.splits)\n      moreover\n      have \"Suc i \\<le> progress \\<sigma> P' (Formula.Until \\<phi>''' I \\<psi>'') (Suc j)\"\n        if \"enat t + right I < enat (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt)\"\n      proof -\n        from that obtain m where m: \"right I = enat m\" by (cases \"right I\") auto\n        have \\<tau>_min:  \"\\<tau> \\<sigma> (min j k) = min (\\<tau> \\<sigma> j) (\\<tau> \\<sigma> k)\" for k\n          by (simp add: min_of_mono monoI)\n        have le_progress_iff[simp]: \"(Suc j) \\<le> progress \\<sigma> P' \\<phi> (Suc j) \\<longleftrightarrow> progress \\<sigma> P' \\<phi> (Suc j) = (Suc j)\" for \\<phi>\n          using wf_envs_progress_le[OF MUntil.prems(2), of \\<phi>] by auto\n        have min_Suc[simp]: \"min j (Suc j) = j\" by auto\n        let ?X = \"{i. \\<forall>k. k < Suc j \\<and> k \\<le>min (progress \\<sigma> P' \\<phi>''' (Suc j)) (progress \\<sigma> P' \\<psi>'' (Suc j)) \\<longrightarrow> enat (\\<tau> \\<sigma> k) \\<le> enat (\\<tau> \\<sigma> i) + right I}\"\n        let ?min = \"min j (min (progress \\<sigma> P' \\<phi>'' (Suc j)) (progress \\<sigma> P' \\<psi>'' (Suc j)))\"\n        have \"\\<tau> \\<sigma> ?min \\<le> \\<tau> \\<sigma> j\"\n          by (rule \\<tau>_mono) auto\n        from m have \"?X \\<noteq> {}\"\n          by (auto dest!: \\<tau>_mono[of _ \"progress \\<sigma> P' \\<phi>'' (Suc j)\" \\<sigma>]\n              simp: not_le not_less \\<phi>''' intro!: exI[of _ \"progress \\<sigma> P' \\<phi>'' (Suc j)\"])\n        from m show ?thesis\n          using that nts' unfolding wf_ts_def progress.simps\n          by (intro cInf_greatest[OF \\<open>?X \\<noteq> {}\\<close>])\n            (auto simp: 1 \\<phi>''' not_le not_less list_all2_Cons2 upt_eq_Cons_conv less_Suc_eq\n              simp del: upt_Suc split: list.splits if_splits\n              dest!: spec[of _ \"?min\"] less_le_trans[of \"\\<tau> \\<sigma> i + m\" \"\\<tau> \\<sigma> _\" \"\\<tau> \\<sigma> _ + m\"] less_\\<tau>D)\n      qed\n      moreover have *: \"k < progress \\<sigma> P' \\<psi> (Suc j)\" if\n        \"enat (\\<tau> \\<sigma> i) + right I < enat (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt)\"\n        \"enat (\\<tau> \\<sigma> k - \\<tau> \\<sigma> i) \\<le> right I\" \"\\<psi> = \\<psi>'' \\<or> \\<psi> = \\<phi>''\" for k \\<psi>\n      proof -\n        from that(1,2) obtain m where \"right I = enat m\"\n          \"\\<tau> \\<sigma> i + m < (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt)\" \"\\<tau> \\<sigma> k - \\<tau> \\<sigma> i \\<le> m\"\n          by (cases \"right I\") auto\n        with that(3) nts' progress_le[of \\<sigma> \\<psi>'' \"Suc j\"] progress_le[of \\<sigma> \\<phi>'' \"Suc j\"]\n        show ?thesis\n          unfolding wf_ts_def le_diff_conv\n          by (auto simp: not_le list_all2_Cons2 upt_eq_Cons_conv less_Suc_eq add.commute\n              simp del: upt_Suc split: list.splits if_splits dest!: le_less_trans[of \"\\<tau> \\<sigma> k\"] less_\\<tau>D)\n      qed\n      ultimately show ?case using Cons.prems Suc_i_aux'[simplified]\n        unfolding \\<open>a = (t, a1, a2)\\<close>\n        by (auto simp: \\<phi>''' 1 sat.simps upt_conv_Cons dest!:  Cons.IH[OF _ aux' Suc_i_aux']\n            simp del: upt_Suc split: if_splits prod.splits intro!: iff_exI qtable_cong[OF 3 refl])\n    qed\n    thm this\n    note wf_aux'' = this[OF wf_envs_progress_mono[OF MUntil.prems(2) le_SucI[OF order_refl]]\n      wf_auxlist' conjunct2[OF update1, unfolded ne_def length_aux']]\n    have \"progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j + length auxlist' =\n      progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (Suc j) + length auxlist''\"\n      using wf_aux'' valid_aux'' length_aux'_aux''\n      by (auto simp add: ne_def length_aux' length_aux'')\n    then have \"cur =\n      (if progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (Suc j) + length auxlist'' = 0 then 0\n      else \\<tau> \\<sigma> (progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (Suc j) + length auxlist'' - 1))\"\n      unfolding cur ne_def by auto\n    then have \"wf_until_aux \\<sigma> V R args \\<phi>'' \\<psi>'' aux'' (progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (Suc j)) \\<and>\n      progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j + length zs = progress \\<sigma> P' (formula.Until \\<phi>''' I \\<psi>'') (Suc j) \\<and>\n      progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j + length zs + length_muaux args aux'' = min (progress \\<sigma> P' \\<phi>''' (Suc j)) (progress \\<sigma> P' \\<psi>'' (Suc j)) \\<and>\n      list_all2 (\\<lambda>i. qtable n (fv \\<psi>'') (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (formula.Until (if pos then \\<phi>'' else formula.Neg \\<phi>'') I \\<psi>'')))\n      [progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j..<progress \\<sigma> P (formula.Until \\<phi>''' I \\<psi>'') j + length zs] zs\"\n      using wf_aux'' valid_aux'' fvi_subset\n      unfolding wf_until_aux_def length_aux'' args_ivl args_n args_pos by (auto simp only: length_aux'')\n  }\n  note update = this\n  from MUntil.IH(1)[OF \\<phi> MUntil.prems(2)] MUntil.IH(2)[OF \\<psi> MUntil.prems(2)] pos pos_eq fvi_subset show ?case\n    by (auto 0 4 simp: args_ivl args_n args_pos Until_eq \\<phi>''' progress.simps(6) split: prod.split if_splits\n        dest!: update[OF refl refl, rotated]\n        intro!: wf_mformula.Until[OF _ _ _ _ args_ivl args_n args_L args_R fvi_subset]\n        elim!: list.rel_mono_strong qtable_cong\n        elim: mbuf2t_take_add'(1)[OF _ wf_envs_P_simps[OF MUntil.prems(2)] buf nts_snoc]\n              mbuf2t_take_add'(2)[OF _ wf_envs_P_simps[OF MUntil.prems(2)] buf nts_snoc])\nnext\n  case (MMatchP I mr mrs \\<phi>s buf nts aux)\n  note sat.simps[simp del] mbufnt_take.simps[simp del] mbufn_add.simps[simp del]\n  from MMatchP.prems obtain r \\<psi>s where eq: \"\\<phi>' = Formula.MatchP I r\"\n    and safe: \"safe_regex Past Strict r\"\n    and mr: \"to_mregex r = (mr, \\<psi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (RPDs mr)\"\n    and \\<psi>s: \"list_all2 (wf_mformula \\<sigma> j P V n R) \\<phi>s \\<psi>s\"\n    and buf: \"wf_mbufn' \\<sigma> P V j n R r buf\"\n    and nts: \"wf_ts_regex \\<sigma> P j r nts\"\n    and aux: \"wf_matchP_aux \\<sigma> V n R I r aux (progress \\<sigma> P (Formula.MatchP I r) j)\"\n    by (cases rule: wf_mformula.cases) (auto)\n  have nts_snoc: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i) [progress_regex \\<sigma> P r j..<Suc j] (nts @ [\\<tau> \\<sigma> j])\"\n    using nts unfolding wf_ts_regex_def\n    by (auto simp add: wf_envs_progress_regex_le[OF MMatchP.prems(2)] intro: list_all2_appendI)\n  have update: \"wf_matchP_aux \\<sigma> V n R I r (snd (zs, aux')) (progress \\<sigma> P' (Formula.MatchP I r) (Suc j)) \\<and>\n    list_all2 (\\<lambda>i. qtable n (Formula.fv_regex r) (mem_restr R)\n      (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (Formula.MatchP I r)))\n      [progress \\<sigma> P (Formula.MatchP I r) j..<progress \\<sigma> P' (Formula.MatchP I r) (Suc j)] (fst (zs, aux'))\"\n    if eval: \"map (fst o meval n (\\<tau> \\<sigma> j) db) \\<phi>s = xss\"\n      and eq: \"mbufnt_take (\\<lambda>rels t (zs, aux).\n        case update_matchP n I mr mrs rels t aux of (z, x) \\<Rightarrow> (zs @ [z], x))\n        ([], aux) (mbufn_add xss buf) (nts @ [\\<tau> \\<sigma> j]) = ((zs, aux'), buf', nts')\"\n    for xss zs aux' buf' nts'\n    unfolding progress_simps\n  proof (rule mbufnt_take_add_induct'[where j'=\"Suc j\" and z'=\"(zs, aux')\", OF eq wf_envs_P_simps[OF MMatchP.prems(2)] safe mr buf nts_snoc],\n      goal_cases xss _ base step)\n    case xss\n    then show ?case\n      using eval \\<psi>s\n      by (auto simp: list_all3_map map2_map_map list_all3_list_all2_conv list.rel_map\n          list.rel_flip[symmetric, of _ \\<psi>s \\<phi>s] dest!: MMatchP.IH(1)[OF _ _ MMatchP.prems(2)]\n          elim!: list.rel_mono_strong split: prod.splits)\n  next\n    case base\n    then show ?case\n      using aux by auto\n  next\n    case (step k Xs z)\n    then show ?case\n      by (auto simp: Un_absorb1 mrs safe mr elim!: update_matchP(1) list_all2_appendI\n          dest!: update_matchP(2) split: prod.split)\n  qed simp\n  then show ?case using \\<psi>s\n    by (auto simp: eq mr mrs safe map_split_alt list.rel_flip[symmetric, of _ \\<psi>s \\<phi>s]\n        list_all3_map map2_map_map list_all3_list_all2_conv list.rel_map intro!: wf_mformula.intros\n        elim!: list.rel_mono_strong mbufnt_take_add'(1)[OF _ wf_envs_P_simps[OF MMatchP.prems(2)] safe mr buf nts_snoc]\n        mbufnt_take_add'(2)[OF _ wf_envs_P_simps[OF MMatchP.prems(2)] safe mr buf nts_snoc]\n        dest!: MMatchP.IH[OF _ _ MMatchP.prems(2)] split: prod.splits)\nnext\n  case (MMatchF I mr mrs \\<phi>s buf nts aux)\n  note sat.simps[simp del] mbufnt_take.simps[simp del] mbufn_add.simps[simp del] progress_simps[simp del]\n  from MMatchF.prems obtain r \\<psi>s where eq: \"\\<phi>' = Formula.MatchF I r\"\n    and safe: \"safe_regex Futu Strict r\"\n    and mr: \"to_mregex r = (mr, \\<psi>s)\"\n    and mrs: \"mrs = sorted_list_of_set (LPDs mr)\"\n    and \\<psi>s: \"list_all2 (wf_mformula \\<sigma> j P V n R) \\<phi>s \\<psi>s\"\n    and buf: \"wf_mbufn' \\<sigma> P V j n R r buf\"\n    and nts: \"wf_ts_regex \\<sigma> P j r nts\"\n    and aux: \"wf_matchF_aux \\<sigma> V n R I r aux (progress \\<sigma> P (Formula.MatchF I r) j) 0\"\n    and length_aux: \"progress \\<sigma> P (Formula.MatchF I r) j + length aux = progress_regex \\<sigma> P r j\"\n    by (cases rule: wf_mformula.cases) (auto)\n  have nts_snoc: \"list_all2 (\\<lambda>i t. t = \\<tau> \\<sigma> i)\n    [progress_regex \\<sigma> P r j..<Suc j] (nts @ [\\<tau> \\<sigma> j])\"\n    using nts unfolding wf_ts_regex_def\n    by (auto simp add: wf_envs_progress_regex_le[OF MMatchF.prems(2)] intro: list_all2_appendI)\n  {\n    fix xss zs aux' aux'' buf' nts'\n    assume eval: \"map (fst o meval n (\\<tau> \\<sigma> j) db) \\<phi>s = xss\"\n      and eq1: \"mbufnt_take (update_matchF n I mr mrs) aux (mbufn_add xss buf) (nts @ [\\<tau> \\<sigma> j]) =\n        (aux', buf', nts')\"\n      and eq2: \"eval_matchF I mr (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # _ \\<Rightarrow> nt) aux' = (zs, aux'')\"\n    have update1: \"wf_matchF_aux \\<sigma> V n R I r aux' (progress \\<sigma> P (Formula.MatchF I r) j) 0 \\<and>\n      progress \\<sigma> P (Formula.MatchF I r) j + length aux' = progress_regex \\<sigma> P' r (Suc j)\"\n      using eval nts_snoc nts_snoc length_aux aux \\<psi>s\n      by (elim mbufnt_take_add_induct'[where j'=\"Suc j\", OF eq1 wf_envs_P_simps[OF MMatchF.prems(2)] safe mr buf])\n        (auto simp: length_update_matchF\n          list_all3_map map2_map_map list_all3_list_all2_conv list.rel_map list.rel_flip[symmetric, of _ \\<psi>s \\<phi>s]\n          dest!: MMatchF.IH[OF _ _ MMatchF.prems(2)]\n          elim: wf_update_matchF[OF _ safe mr mrs] elim!: list.rel_mono_strong)\n    from MMatchF.prems(2) have nts': \"wf_ts_regex \\<sigma> P' (Suc j) r nts'\"\n      using eval eval nts_snoc \\<psi>s\n      unfolding wf_ts_regex_def\n      by (intro mbufnt_take_eqD(2)[OF eq1 wf_mbufn_add[where js'=\"map (\\<lambda>\\<phi>. progress \\<sigma> P' \\<phi> (Suc j)) \\<psi>s\",\n              OF buf[unfolded wf_mbufn'_def mr prod.case]]])\n        (auto simp: to_mregex_progress[OF safe mr] Mini_def\n          list_all3_map map2_map_map list_all3_list_all2_conv list.rel_map list.rel_flip[symmetric, of _ \\<psi>s \\<phi>s]\n          list_all2_Cons1 elim!: list.rel_mono_strong intro!: list.rel_refl_strong\n          dest!: MMatchF.IH[OF _ _ MMatchF.prems(2)])\n    have \"i \\<le> progress \\<sigma> P' (Formula.MatchF I r) (Suc j) \\<Longrightarrow>\n      wf_matchF_aux \\<sigma> V n R I r aux' i 0 \\<Longrightarrow>\n      i + length aux' = progress_regex \\<sigma> P' r (Suc j) \\<Longrightarrow>\n      wf_matchF_aux \\<sigma> V n R I r aux'' (progress \\<sigma> P' (Formula.MatchF I r) (Suc j)) 0 \\<and>\n        i + length zs = progress \\<sigma> P' (Formula.MatchF I r) (Suc j) \\<and>\n        i + length zs + length aux'' = progress_regex \\<sigma> P' r (Suc j) \\<and>\n        list_all2 (\\<lambda>i. qtable n (Formula.fv_regex r) (mem_restr R)\n          (\\<lambda>v. Formula.sat \\<sigma> V (map the v) i (Formula.MatchF I r)))\n          [i..<i + length zs] zs\" for i\n      using eq2\n    proof (induction aux' arbitrary: zs aux'' i)\n      case Nil\n      then show ?case by (auto dest!: antisym[OF progress_MatchF_le])\n    next\n      case (Cons a aux')\n      obtain t rels rel where \"a = (t, rels, rel)\" by (cases a)\n      from Cons.prems(2) have aux': \"wf_matchF_aux \\<sigma> V n R I r aux' (Suc i) 0\"\n        by (rule wf_matchF_aux_Cons)\n      from Cons.prems(2) have 1: \"t = \\<tau> \\<sigma> i\"\n        unfolding \\<open>a = (t, rels, rel)\\<close> by (rule wf_matchF_aux_Cons1)\n      from Cons.prems(2) have 3: \"qtable n (Formula.fv_regex r) (mem_restr R) (\\<lambda>v.\n        (\\<exists>j\\<ge>i. j < Suc (i + length aux') \\<and> mem (\\<tau> \\<sigma> j - \\<tau> \\<sigma> i) I \\<and> Regex.match (Formula.sat \\<sigma> V (map the v)) r i j)) rel\"\n        unfolding \\<open>a = (t, rels, rel)\\<close> using wf_matchF_aux_Cons3 by force\n      from Cons.prems(3) have Suc_i_aux': \"Suc i + length aux' = progress_regex \\<sigma> P' r (Suc j)\"\n        by simp\n      have \"i \\<ge> progress \\<sigma> P' (Formula.MatchF I r) (Suc j)\"\n        if \"enat (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt) \\<le> enat t + right I\"\n        using that nts' unfolding wf_ts_regex_def progress_simps\n        by (auto simp add: 1 list_all2_Cons2 upt_eq_Cons_conv\n            intro!: cInf_lower \\<tau>_mono elim!: order.trans[rotated] simp del: upt_Suc split: if_splits list.splits)\n      moreover\n      have \"Suc i \\<le> progress \\<sigma> P' (Formula.MatchF I r) (Suc j)\"\n        if \"enat t + right I < enat (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt)\"\n      proof -\n        from that obtain m where m: \"right I = enat m\" by (cases \"right I\") auto\n        have \\<tau>_min:  \"\\<tau> \\<sigma> (min j k) = min (\\<tau> \\<sigma> j) (\\<tau> \\<sigma> k)\" for k\n          by (simp add: min_of_mono monoI)\n        have le_progress_iff[simp]: \"Suc j \\<le> progress \\<sigma> P' \\<phi> (Suc j) \\<longleftrightarrow> progress \\<sigma> P' \\<phi> (Suc j) = (Suc j)\" for \\<phi>\n          using wf_envs_progress_le[OF MMatchF.prems(2), of \\<phi>] by auto\n        have min_Suc[simp]: \"min j (Suc j) = j\" by auto\n        let ?X = \"{i. \\<forall>k. k < Suc j \\<and> k \\<le> progress_regex \\<sigma> P' r (Suc j) \\<longrightarrow> enat (\\<tau> \\<sigma> k) \\<le> enat (\\<tau> \\<sigma> i) + right I}\"\n        let ?min = \"min j (progress_regex \\<sigma> P' r (Suc j))\"\n        have \"\\<tau> \\<sigma> ?min \\<le> \\<tau> \\<sigma> j\"\n          by (rule \\<tau>_mono) auto\n        from m have \"?X \\<noteq> {}\"\n          by (auto dest!: less_\\<tau>D add_lessD1 simp: not_le not_less)\n        from m show ?thesis\n          using that nts' wf_envs_progress_regex_le[OF MMatchF.prems(2), of r]\n          unfolding wf_ts_regex_def progress_simps\n          by (intro cInf_greatest[OF \\<open>?X \\<noteq> {}\\<close>])\n            (auto simp: 1 not_le not_less list_all2_Cons2 upt_eq_Cons_conv less_Suc_eq\n              simp del: upt_Suc split: list.splits if_splits\n              dest!: spec[of _ \"?min\"] less_le_trans[of \"\\<tau> \\<sigma> i + m\" \"\\<tau> \\<sigma> _\" \"\\<tau> \\<sigma> _ + m\"] less_\\<tau>D)\n      qed\n      moreover have *: \"k < progress_regex \\<sigma> P' r (Suc j)\" if\n        \"enat (\\<tau> \\<sigma> i) + right I < enat (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt)\"\n        \"enat (\\<tau> \\<sigma> k - \\<tau> \\<sigma> i) \\<le> right I\" for k\n      proof -\n        from that(1,2) obtain m where \"right I = enat m\"\n          \"\\<tau> \\<sigma> i + m < (case nts' of [] \\<Rightarrow> \\<tau> \\<sigma> j | nt # x \\<Rightarrow> nt)\" \"\\<tau> \\<sigma> k - \\<tau> \\<sigma> i \\<le> m\"\n          by (cases \"right I\") auto\n        with nts' wf_envs_progress_regex_le[OF MMatchF.prems(2), of r]\n        show ?thesis\n          unfolding wf_ts_regex_def le_diff_conv\n          by (auto simp: not_le list_all2_Cons2 upt_eq_Cons_conv less_Suc_eq add.commute\n              simp del: upt_Suc split: list.splits if_splits dest!: le_less_trans[of \"\\<tau> \\<sigma> k\"] less_\\<tau>D)\n      qed\n      ultimately show ?case using Cons.prems Suc_i_aux'[simplified]\n        unfolding \\<open>a = (t, rels, rel)\\<close>\n        by (auto simp: 1 sat.simps upt_conv_Cons dest!:  Cons.IH[OF _ aux' Suc_i_aux']\n            simp del: upt_Suc split: if_splits prod.splits intro!: iff_exI qtable_cong[OF 3 refl])\n\n    qed\n    note this[OF progress_mono_gen[OF le_SucI, OF order.refl] conjunct1[OF update1] conjunct2[OF update1]]\n  }\n  note update = this[OF refl, rotated]\n  with MMatchF.prems(2) show ?case using \\<psi>s\n    by (auto simp: eq mr mrs safe map_split_alt list.rel_flip[symmetric, of _ \\<psi>s \\<phi>s]\n        list_all3_map map2_map_map list_all3_list_all2_conv list.rel_map intro!: wf_mformula.intros\n        elim!: list.rel_mono_strong mbufnt_take_add'(1)[OF _ wf_envs_P_simps[OF MMatchF.prems(2)] safe mr buf nts_snoc]\n        mbufnt_take_add'(2)[OF _ wf_envs_P_simps[OF MMatchF.prems(2)] safe mr buf nts_snoc]\n        dest!: MMatchF.IH[OF _ _ MMatchF.prems(2)] update split: prod.splits)\nqed\n\n\nsubsubsection \\<open>Monitor step\\<close>\n\nlemma (in maux) wf_mstate_mstep: \"wf_mstate \\<phi> \\<pi> R st \\<Longrightarrow> last_ts \\<pi> \\<le> snd tdb \\<Longrightarrow>\n  wf_mstate \\<phi> (psnoc \\<pi> tdb) R (snd (mstep (map_prod mk_db id tdb) st))\"\n  unfolding wf_mstate_def mstep_def Let_def\n  by (fastforce simp add: progress_mono le_imp_diff_is_add split: prod.splits\n      elim!: prefix_of_psnocE dest: meval[OF _ wf_envs_mk_db] list_all2_lengthD)\n\ndefinition \"flatten_verdicts Vs = (\\<Union> (set (map (\\<lambda>(i, X). (\\<lambda>v. (i, v)) ` X) Vs)))\"\n\nlemma flatten_verdicts_append[simp]:\n  \"flatten_verdicts (Vs @ Us) = flatten_verdicts Vs \\<union> flatten_verdicts Us\"\n  by (induct Vs) (auto simp: flatten_verdicts_def)\n\nlemma (in maux) mstep_output_iff:\n  assumes \"wf_mstate \\<phi> \\<pi> R st\" \"last_ts \\<pi> \\<le> snd tdb\" \"prefix_of (psnoc \\<pi> tdb) \\<sigma>\" \"mem_restr R v\"\n  shows \"(i, v) \\<in> flatten_verdicts (fst (mstep (map_prod mk_db id tdb) st)) \\<longleftrightarrow>\n    progress \\<sigma> Map.empty \\<phi> (plen \\<pi>) \\<le> i \\<and> i < progress \\<sigma> Map.empty \\<phi> (Suc (plen \\<pi>)) \\<and>\n    wf_tuple (Formula.nfv \\<phi>) (Formula.fv \\<phi>) v \\<and> Formula.sat \\<sigma> Map.empty (map the v) i \\<phi>\"\nproof -\n  from prefix_of_psnocE[OF assms(3,2)] have \"prefix_of \\<pi> \\<sigma>\"\n    \"\\<Gamma> \\<sigma> (plen \\<pi>) = fst tdb\" \"\\<tau> \\<sigma> (plen \\<pi>) = snd tdb\" by auto\n  moreover from assms(1) \\<open>prefix_of \\<pi> \\<sigma>\\<close> have \"mstate_n st = Formula.nfv \\<phi>\"\n    \"mstate_i st = progress \\<sigma> Map.empty \\<phi> (plen \\<pi>)\" \"wf_mformula \\<sigma> (plen \\<pi>) Map.empty Map.empty (mstate_n st) R (mstate_m st) \\<phi>\"\n    unfolding wf_mstate_def by blast+\n  moreover from meval[OF \\<open>wf_mformula \\<sigma> (plen \\<pi>) Map.empty Map.empty (mstate_n st) R (mstate_m st) \\<phi>\\<close> wf_envs_mk_db] obtain Vs st' where\n    \"meval (mstate_n st) (\\<tau> \\<sigma> (plen \\<pi>)) (mk_db (\\<Gamma> \\<sigma> (plen \\<pi>))) (mstate_m st) = (Vs, st')\"\n    \"wf_mformula \\<sigma> (Suc (plen \\<pi>))  Map.empty Map.empty (mstate_n st) R st' \\<phi>\"\n    \"list_all2 (\\<lambda>i. qtable (mstate_n st) (fv \\<phi>) (mem_restr R) (\\<lambda>v. Formula.sat \\<sigma> Map.empty (map the v) i \\<phi>))\n      [progress \\<sigma> Map.empty \\<phi> (plen \\<pi>)..<progress \\<sigma> Map.empty \\<phi> (Suc (plen \\<pi>))] Vs\" by blast\n  moreover from this assms(4) have \"qtable (mstate_n st) (fv \\<phi>) (mem_restr R)\n    (\\<lambda>v. Formula.sat \\<sigma> Map.empty (map the v) i \\<phi>) (Vs ! (i - progress \\<sigma> Map.empty \\<phi> (plen \\<pi>)))\"\n    if \"progress \\<sigma> Map.empty \\<phi> (plen \\<pi>) \\<le> i\" \"i < progress \\<sigma> Map.empty \\<phi> (Suc (plen \\<pi>))\"\n    using that by (auto simp: list_all2_conv_all_nth\n        dest!: spec[of _ \"(i - progress \\<sigma> Map.empty \\<phi> (plen \\<pi>))\"])\n  ultimately show ?thesis\n    using assms(4) unfolding mstep_def Let_def flatten_verdicts_def\n    by (auto simp: in_set_enumerate_eq list_all2_conv_all_nth progress_mono le_imp_diff_is_add\n        elim!: in_qtableE in_qtableI intro!: bexI[of _ \"(i, Vs ! (i - progress \\<sigma> Map.empty \\<phi> (plen \\<pi>)))\"])\nqed\n\n\nsubsubsection \\<open>Monitor function\\<close>\n\nlocale verimon = verimon_spec + maux\n\nlemma (in verimon) mstep_mverdicts:\n  assumes wf: \"wf_mstate \\<phi> \\<pi> R st\"\n    and le[simp]: \"last_ts \\<pi> \\<le> snd tdb\"\n    and restrict: \"mem_restr R v\"\n  shows \"(i, v) \\<in> flatten_verdicts (fst (mstep (map_prod mk_db id tdb) st)) \\<longleftrightarrow>\n    (i, v) \\<in> M (psnoc \\<pi> tdb) - M \\<pi>\"\nproof -\n  obtain \\<sigma> where p2: \"prefix_of (psnoc \\<pi> tdb) \\<sigma>\"\n    using ex_prefix_of by blast\n  with le have p1: \"prefix_of \\<pi> \\<sigma>\" by (blast elim!: prefix_of_psnocE)\n  show ?thesis\n    unfolding M_def\n    by (auto 0 3 simp: p2 progress_prefix_conv[OF _ p1] sat_prefix_conv[OF _ p1] not_less\n        pprogress_eq[OF p1] pprogress_eq[OF p2]\n        dest: mstep_output_iff[OF wf le p2 restrict, THEN iffD1] spec[of _ \\<sigma>]\n        mstep_output_iff[OF wf le _ restrict, THEN iffD1] progress_sat_cong[OF p1]\n        intro: mstep_output_iff[OF wf le p2 restrict, THEN iffD2] p1)\nqed\n\ncontext maux\nbegin\n\nprimrec msteps0 where\n  \"msteps0 [] st = ([], st)\"\n| \"msteps0 (tdb # \\<pi>) st =\n    (let (V', st') = mstep (map_prod mk_db id tdb) st; (V'', st'') = msteps0 \\<pi> st' in (V' @ V'', st''))\"\n\nprimrec msteps0_stateless where\n  \"msteps0_stateless [] st = []\"\n| \"msteps0_stateless (tdb # \\<pi>) st = (let (V', st') = mstep (map_prod mk_db id tdb) st in V' @ msteps0_stateless \\<pi> st')\"\n\nlemma msteps0_msteps0_stateless: \"fst (msteps0 w st) = msteps0_stateless w st\"\n  by (induct w arbitrary: st) (auto simp: split_beta)\n\nlift_definition msteps :: \"Formula.prefix \\<Rightarrow> ('msaux, 'muaux) mstate \\<Rightarrow> (nat \\<times> event_data table) list \\<times> ('msaux, 'muaux) mstate\"\n  is msteps0 .\n\nlift_definition msteps_stateless :: \"Formula.prefix \\<Rightarrow> ('msaux, 'muaux) mstate \\<Rightarrow> (nat \\<times> event_data table) list\"\n  is msteps0_stateless .\n\nlemma msteps_msteps_stateless: \"fst (msteps w st) = msteps_stateless w st\"\n  by transfer (rule msteps0_msteps0_stateless)\n\nlemma msteps0_snoc: \"msteps0 (\\<pi> @ [tdb]) st =\n   (let (V', st') = msteps0 \\<pi> st; (V'', st'') = mstep (map_prod mk_db id tdb) st' in (V' @ V'', st''))\"\n  by (induct \\<pi> arbitrary: st) (auto split: prod.splits)\n\nlemma msteps_psnoc: \"last_ts \\<pi> \\<le> snd tdb \\<Longrightarrow> msteps (psnoc \\<pi> tdb) st =\n   (let (V', st') = msteps \\<pi> st; (V'', st'') = mstep (map_prod mk_db id tdb) st' in (V' @ V'', st''))\"\n  by transfer' (auto simp: msteps0_snoc split: list.splits prod.splits if_splits)\n\ndefinition monitor where\n  \"monitor \\<phi> \\<pi> = msteps_stateless \\<pi> (minit_safe \\<phi>)\"\n\nend\n\nlemma Suc_length_conv_snoc: \"(Suc n = length xs) = (\\<exists>y ys. xs = ys @ [y] \\<and> length ys = n)\"\n  by (cases xs rule: rev_cases) auto\n\nlemma (in verimon) wf_mstate_msteps: \"wf_mstate \\<phi> \\<pi> R st \\<Longrightarrow> mem_restr R v \\<Longrightarrow> \\<pi> \\<le> \\<pi>' \\<Longrightarrow>\n  X = msteps (pdrop (plen \\<pi>) \\<pi>') st \\<Longrightarrow> wf_mstate \\<phi> \\<pi>' R (snd X) \\<and>\n  ((i, v) \\<in> flatten_verdicts (fst X)) = ((i, v) \\<in> M \\<pi>' - M \\<pi>)\"\nproof (induct \"plen \\<pi>' - plen \\<pi>\" arbitrary: X st \\<pi> \\<pi>')\n  case 0\n  from 0(1,4,5) have \"\\<pi> = \\<pi>'\"  \"X = ([], st)\"\n    by (transfer; auto)+\n  with 0(2) show ?case unfolding flatten_verdicts_def by simp\nnext\n  case (Suc x)\n  from Suc(2,5) obtain \\<pi>'' tdb where \"x = plen \\<pi>'' - plen \\<pi>\"  \"\\<pi> \\<le> \\<pi>''\"\n    \"\\<pi>' = psnoc \\<pi>'' tdb\" \"pdrop (plen \\<pi>) (psnoc \\<pi>'' tdb) = psnoc (pdrop (plen \\<pi>) \\<pi>'') tdb\"\n    \"last_ts (pdrop (plen \\<pi>) \\<pi>'') \\<le> snd tdb\" \"last_ts \\<pi>'' \\<le> snd tdb\"\n    \"\\<pi>'' \\<le> psnoc \\<pi>'' tdb\"\n  proof (atomize_elim, transfer, elim exE, goal_cases prefix)\n    case (prefix _ _ \\<pi>' _ \\<pi>_tdb)\n    then show ?case\n    proof (cases \\<pi>_tdb rule: rev_cases)\n      case (snoc \\<pi> tdb)\n      with prefix show ?thesis\n        by (intro bexI[of _ \"\\<pi>' @ \\<pi>\"] exI[of _ tdb])\n          (force simp: sorted_append append_eq_Cons_conv split: list.splits if_splits)+\n    qed simp\n  qed\n  with Suc(1)[OF this(1) Suc.prems(1,2) this(2) refl] Suc.prems show ?case\n    unfolding msteps_msteps_stateless[symmetric]\n    by (auto simp: msteps_psnoc split_beta mstep_mverdicts\n        dest: mono_monitor[THEN set_mp, rotated] intro!: wf_mstate_mstep)\nqed\n\nlemma (in verimon) wf_mstate_msteps_stateless:\n  assumes \"wf_mstate \\<phi> \\<pi> R st\" \"mem_restr R v\" \"\\<pi> \\<le> \\<pi>'\"\n  shows \"(i, v) \\<in> flatten_verdicts (msteps_stateless (pdrop (plen \\<pi>) \\<pi>') st) \\<longleftrightarrow> (i, v) \\<in> M \\<pi>' - M \\<pi>\"\n  using wf_mstate_msteps[OF assms refl] unfolding msteps_msteps_stateless by simp\n\nlemma (in verimon) wf_mstate_msteps_stateless_UNIV: \"wf_mstate \\<phi> \\<pi> UNIV st \\<Longrightarrow> \\<pi> \\<le> \\<pi>' \\<Longrightarrow>\n  flatten_verdicts (msteps_stateless (pdrop (plen \\<pi>) \\<pi>') st) = M \\<pi>' - M \\<pi>\"\n  by (auto dest: wf_mstate_msteps_stateless[OF _ mem_restr_UNIV])\n\nlemma (in verimon) mverdicts_Nil: \"M pnil = {}\"\n  by (simp add: M_def pprogress_eq)\n\ncontext maux\nbegin\n\nlemma minit_safe_minit: \"mmonitorable \\<phi> \\<Longrightarrow> minit_safe \\<phi> = minit \\<phi>\"\n  unfolding minit_safe_def monitorable_formula_code by simp\n\nlemma wf_mstate_minit_safe: \"mmonitorable \\<phi> \\<Longrightarrow> wf_mstate \\<phi> pnil R (minit_safe \\<phi>)\"\n  using wf_mstate_minit minit_safe_minit mmonitorable_def by metis\n\nend\n\nlemma (in verimon) monitor_mverdicts: \"flatten_verdicts (monitor \\<phi> \\<pi>) = M \\<pi>\"\n  unfolding monitor_def using monitorable\n  by (subst wf_mstate_msteps_stateless_UNIV[OF wf_mstate_minit_safe, simplified])\n    (auto simp: mmonitorable_def mverdicts_Nil)\n\nsubsection \\<open>Collected correctness results\\<close>\n\ncontext verimon\nbegin\n\ntext \\<open>We summarize the main results proved above.\n\\begin{enumerate}\n\\item The term @{term M} describes semantically the monitor's expected behaviour:\n\\begin{itemize}\n\\item @{thm[source] mono_monitor}: @{thm mono_monitor[no_vars]}\n\\item @{thm[source] sound_monitor}: @{thm sound_monitor[no_vars]}\n\\item @{thm[source] complete_monitor}: @{thm complete_monitor[no_vars]}\n\\item @{thm[source] sliceable_M}: @{thm sliceable_M[no_vars]}\n\\end{itemize}\n\\item The executable monitor's online interface @{term minit_safe} and @{term mstep}\n  preserves the invariant @{term wf_mstate} and produces the the verdicts according\n  to @{term M}:\n\\begin{itemize}\n\\item @{thm[source] wf_mstate_minit_safe}: @{thm wf_mstate_minit_safe[no_vars]}\n\\item @{thm[source] wf_mstate_mstep}: @{thm wf_mstate_mstep[no_vars]}\n\\item @{thm[source] mstep_mverdicts}: @{thm mstep_mverdicts[no_vars]}\n\\end{itemize}\n\\item The executable monitor's offline interface @{term monitor} implements @{term M}:\n\\begin{itemize}\n\\item @{thm[source] monitor_mverdicts}: @{thm monitor_mverdicts[no_vars]}\n\\end{itemize}\n\\end{enumerate}\n\\<close>\n\nend\n\n(*<*)\nend\n(*>*)\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/MFODL_Monitor_Optimized/Monitor.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6654105587468141, "lm_q2_score": 0.38121956625614994, "lm_q1q2_score": 0.25366752458772285}}
{"text": "(*\n    Author:      David Sanan\n    Maintainer:  David Sanan, sanan at ntu edu sg\n    License:     LGPL\n*)\n\n(*  Title:      SmallStepCon.thy\n    Author:     David Sanan, NTU\n\nCopyright (C) 2015-2016 David Sanan \nSome rights reserved, NTU\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection {* Small-Step Semantics and Infinite Computations*} \n\ntheory SmallStepCon imports \"EmbSimpl.SmallStep\" \"SemanticCon\" \n                            \"TerminationCon\"\n                            (* \"Sep_Algebra.Sep_Heap_Instance\" \n                            \"Actions.ActionsSemantics\" *)\nbegin\n\ntext {* The redex of a statement is the substatement, which is actually altered\nby the next step in the small-step semantics.\n*}\nprimrec redex:: \"('s,'p,'f,'e)com \\<Rightarrow> ('s,'p,'f,'e)com\"\nwhere\n\"redex Skip = Skip\" |\n\"redex (Basic f e) = (Basic f e)\" |\n\"redex (Spec r e) = (Spec r e)\" |\n\"redex (Seq c\\<^sub>1 c\\<^sub>2) = redex c\\<^sub>1\" |\n\"redex (Cond b c\\<^sub>1 c\\<^sub>2) = (Cond b c\\<^sub>1 c\\<^sub>2)\" |\n\"redex (While b c) = (While b c)\" |\n\"redex (Call p) = (Call p)\" |\n\"redex (DynCom d) = (DynCom d)\" |\n\"redex (Guard f b c) = (Guard f b c)\" |\n\"redex (Throw) = Throw\" |\n\"redex (Catch c\\<^sub>1 c\\<^sub>2) = redex c\\<^sub>1\" |\n\"redex (Await b c e) = (Await b c e)\"\n\nsubsection {*Small-Step Computation: @{text \"\\<Gamma>\\<turnstile>\\<^sub>c(c, s) \\<rightarrow> (c', s')\"}*}\n\n(* locale localsvars  =     \n  fixes toSeq :: \"(('g \\<times> 'l \\<times> 'l list),'f) xstate \\<Rightarrow> ('s,'f) xstate\"   \n  fixes SegGl :: \"'s \\<Rightarrow> 'g\"\n  fixes SegLo ::\"'s \\<Rightarrow> 'l\"\n\nassumes SeqFault:\"toSeq (Fault f) = Fault f\" and\n        SeqStuck:\"toSeq (Stuck) = Stuck\" and\n        SeqNormal:\"toSeq (Normal (g,l,ls)) = Normal s \\<and> SegGl s = g \\<and> SegLo s = l\" and\n        SeqEq:\"toSeq (Normal (g,l,ls)) = toSeq (Normal (g,l,ls'))\" and\n        SeqEqAbr:\"toSeq (Abrupt (g,l,ls)) = toSeq (Abrupt (g,l,ls'))\" and\n        SeqAbrupt:\"toSeq (Abrupt (g,l,ls)) = Abrupt s \\<and> SegGl s = g \\<and> SegLo s = l\" \nbegin\nprimrec fromSeq ::\"('s, 'f) xstate \\<Rightarrow> 'l list \\<Rightarrow> (('g \\<times> 'l \\<times> 'l list),'f) xstate\"\n  where \"fromSeq (Normal s) locs = Normal (SegGl s, SegLo s, locs)\"\n  |\"fromSeq (Abrupt s) locs = Abrupt (SegGl s, SegLo s, locs)\"\n  |\"fromSeq (Fault f) locs = Fault f\"\n  |\"fromSeq Stuck locs = Stuck\"\n\nlemma ParFault:\"fromSeq (Fault f) ls = Fault f\" and\n      ParStuck:\"fromSeq (Stuck) ls = Stuck\" and\n      ParNormal:\"fromSeq (Normal s) ls = Normal (SegGl s, SegLo s, ls)\" and\n      ParAbrupt:\"fromSeq (Abrupt s) ls = Abrupt (SegGl s, SegLo s, ls)\"\n  by auto\n\nlemma abnormal_from_to:\"\\<forall>s'. s\\<noteq>Normal s' \\<and> s\\<noteq>Abrupt s' \\<Longrightarrow>  fromSeq (toSeq s) x = s\" \n  by (cases s, auto simp add: SeqFault ParFault SeqStuck ParStuck)\n  \nlemma abnormal_to_from:\"\\<forall>s'. s\\<noteq>Normal s' \\<and> s\\<noteq>Abrupt s' \\<Longrightarrow>  toSeq (fromSeq s x) = s\" \n  by (cases s, auto simp add: SeqFault ParFault SeqStuck ParStuck)  \n\nlemma normal_to_from:\"fromSeq (toSeq (Normal (g,l,ls))) x = Normal (g,l,x)\"\n  using SeqNormal ParNormal by (metis (full_types))\n\nlemma normal_from_to:\"toSeq (fromSeq (Normal s) x) = Normal s\"\n  using SeqNormal ParNormal by auto\n\nlemma abrupt_to_from:\"fromSeq (toSeq (Abrupt (g,l,ls))) x = Abrupt (g,l,x)\"\n  using SeqAbrupt ParAbrupt by (metis (full_types))\n\nlemma abrutp_from_to:\"toSeq (fromSeq (Abrupt s) x) = Abrupt s\"\n  using SeqAbrupt ParAbrupt by auto\n\nlemma to_seq_distinct:\n      \"toSeq (Normal s1) \\<noteq>  toSeq (Abrupt  s2) \\<and>\n       toSeq (Normal s1) \\<noteq>  toSeq (Stuck) \\<and>\n       toSeq (Normal s1) \\<noteq>  toSeq (Fault f) \\<and>\n       toSeq (Abrupt s2) \\<noteq> toSeq (Stuck) \\<and>\n       toSeq (Abrupt s2) \\<noteq> toSeq (Fault f) \\<and>\n       toSeq (Stuck) \\<noteq> toSeq (Fault f)\"\n  using  SeqNormal SeqStuck  SeqAbrupt  SeqFault  \n  by (smt prod_cases3 xstate.distinct)+\n\nlemma from_seq_distinct:\n      \"fromSeq (Normal s1) \\<noteq>  fromSeq (Abrupt  s2) \\<and>\n       fromSeq (Normal s1) \\<noteq>  fromSeq (Stuck) \\<and>\n       fromSeq (Normal s1) \\<noteq>  fromSeq (Fault f) \\<and>\n       fromSeq (Abrupt s2) \\<noteq> fromSeq (Stuck) \\<and>\n       fromSeq (Abrupt s2) \\<noteq> fromSeq (Fault f) \\<and>\n       fromSeq (Stuck) \\<noteq> fromSeq (Fault f)\"    \n  using  ParFault ParStuck  ParAbrupt  ParNormal  \n  by (smt prod_cases3 xstate.distinct)+\n\nlemma toSeq_eq:\"(toSeq (Normal (g,l,ls)) = toSeq (Normal (g',l',ls))) =  (g=g' \\<and> l=l')\"\n  by (metis (full_types) SeqNormal)\n\nlemma toSeq_diff:\"(toSeq (Normal (g,l,ls)) \\<noteq> toSeq (Normal (g',l',ls))) =  (g\\<noteq>g' \\<or> l\\<noteq>l')\"\n  using toSeq_eq by auto\n  \nend *)\n          (* and\n          a4:\"\\<forall>i. i \\<notin> id ` (localSet locs) \\<longrightarrow> setLocal i locs loc = locs\" and\n          a5:\"card (localSet locs) \\<le> card (UNIV::'id set)\" and\n          a6:\"\\<forall>i. i \\<notin> id ` (localSet locs) \\<longrightarrow> getLocals locs i = None\" and\n          a7:\"\\<forall>id' id. id \\<noteq> id' \\<longrightarrow> getLocals (setLocal id locs loc) id' = getLocals locs id'\" and\n          a8:\"\\<forall>id1 id2. id1\\<noteq>id2 \\<and> id1 \\<in> id ` (localSet locs) \\<and> id2 \\<in> id ` (localSet locs) \\<longrightarrow> \n                       getLocals locs id1 \\<noteq> getLocals locs id2\" and\n          a9:\"\\<forall>e1 e2. e1 \\<in> (localSet locs) \\<and> e2 \\<in> (localSet locs) \\<and> e1\\<noteq>e2 \\<longrightarrow> id e1 \\<noteq> id e2\" \nbegin \n\n\nend\nrecord g = x1::nat\nrecord l = ids:: nat l1::nat\n\nrecord gl = x1::nat ids::nat l1::nat\ntype_synonym ('l) ls = \"'l list\"\n\ndefinition id1 ::\"l \\<Rightarrow> nat\"\n  where \"id1 ml \\<equiv> l.ids ml\"\n\ndefinition getLocal :: \"gl \\<Rightarrow> l\"\n  where \"getLocal gls \\<equiv> \\<lparr>l.ids = gl.ids gls, l.l1 = gl.l1 gls\\<rparr>\"\n\ndefinition getGlobal :: \"gl \\<Rightarrow> g\"\n  where \"getGlobal gls \\<equiv> \\<lparr>g.x1 = gl.x1 gls\\<rparr>\"\n\ndefinition toSeq :: \"(g\\<times>l) \\<Rightarrow> gl\"\n  where \"toSeq gls \\<equiv> \\<lparr>gl.x1 = (g.x1 (fst gls)), gl.ids = l.ids (snd gls), gl.l1 = l.l1 (snd gls)\\<rparr>\"\n\ndefinition localSet ::\"l ls \\<Rightarrow> l set\"\n  where \"localSet mlocs \\<equiv> set mlocs\"\n\ndefinition getLocals ::\"l ls \\<Rightarrow> nat \\<Rightarrow> l option\"\n  where \"getLocals mlocs idn \\<equiv> find (\\<lambda>l. id1 l = idn) mlocs\"\n\ndefinition setLocal ::\"nat \\<Rightarrow> l ls \\<Rightarrow> l \\<Rightarrow> l ls\"\n  where \"setLocal idn mlocs l \\<equiv> if  find (\\<lambda>l. id1 l = idn) mlocs = None then mlocs\n                                else \n                                 let p = (SOME n. id1 (nth mlocs n) = idn) in\n                                     mlocs[p:= l]\"\n\ninterpretation localsvars getLocal getGlobal toSeq \n  apply (unfold_locales)\n          apply (unfold getLocal_def toSeq_def getGlobal_def)\n  by auto  \n*) \n\ntype_synonym ('s,'p,'f,'e) config = \"('s,'p,'f,'e)com  \\<times> ('s,'f) xstate\"\n\ninductive       \n      \"stepc\"::\"[('s,'p,'f,'e) body,('s,'p,'f,'e) config,('s,'p,'f,'e) config] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>c (_ \\<rightarrow>/ _)\" [81,81,81] 100)  \n  for \\<Gamma>::\"('s,'p,'f,'e) body\"\nwhere\n\n  Basicc: \"\\<Gamma>\\<turnstile>\\<^sub>c(Basic f e,Normal s) \\<rightarrow> (Skip,Normal (f s))\"\n\n| Specc: \"(s,t) \\<in> r \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(Spec r e,Normal s) \\<rightarrow> (Skip,Normal t)\"\n| SpecStuckc: \"\\<forall>t. (s,t) \\<notin> r \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(Spec r e,Normal s) \\<rightarrow> (Skip,Stuck)\"\n\n| Guardc: \"s\\<in>g \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(Guard f g c,Normal s) \\<rightarrow> (c,Normal s)\"\n  \n| GuardFaultc: \"s\\<notin>g \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(Guard f g c,Normal s) \\<rightarrow> (Skip,Fault f)\"\n\n\n| Seqc: \"\\<Gamma>\\<turnstile>\\<^sub>c(c\\<^sub>1,s) \\<rightarrow> (c\\<^sub>1',s')\n        \\<Longrightarrow> \n        \\<Gamma>\\<turnstile>\\<^sub>c(Seq c\\<^sub>1 c\\<^sub>2,s) \\<rightarrow> (Seq c\\<^sub>1' c\\<^sub>2, s')\"\n| SeqSkipc: \"\\<Gamma>\\<turnstile>\\<^sub>c(Seq Skip c\\<^sub>2,s) \\<rightarrow> (c\\<^sub>2, s)\"\n| SeqThrowc: \"\\<Gamma>\\<turnstile>\\<^sub>c(Seq Throw c\\<^sub>2,Normal s) \\<rightarrow> (Throw, Normal s)\"\n\n| CondTruec:  \"s\\<in>b \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(Cond b c\\<^sub>1 c\\<^sub>2,Normal s) \\<rightarrow> (c\\<^sub>1,Normal s)\"\n| CondFalsec: \"s\\<notin>b \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(Cond b c\\<^sub>1 c\\<^sub>2,Normal s) \\<rightarrow> (c\\<^sub>2,Normal s)\"\n\n| WhileTruec: \"\\<lbrakk>s\\<in>b\\<rbrakk> \n              \\<Longrightarrow> \n              \\<Gamma>\\<turnstile>\\<^sub>c(While b c,Normal s) \\<rightarrow> (Seq c (While b c),Normal s)\"\n\n| WhileFalsec: \"\\<lbrakk>s\\<notin>b\\<rbrakk> \n               \\<Longrightarrow> \n               \\<Gamma>\\<turnstile>\\<^sub>c(While b c,Normal s) \\<rightarrow> (Skip,Normal s)\"\n\n\n| Awaitc:  \"\\<lbrakk>s\\<in>b; \\<Gamma>1=\\<Gamma>\\<^sub>\\<not>\\<^sub>a ; \\<Gamma>1\\<turnstile>\\<langle>ca1,Normal s\\<rangle> \\<Rightarrow> t; \n             \\<not>(\\<exists>t'. t = Abrupt t')\\<rbrakk> \\<Longrightarrow> \n            \\<Gamma>\\<turnstile>\\<^sub>c(Await b ca1 e,Normal s) \\<rightarrow> (Skip,t)\"\n\n| AwaitAbruptc: \"\\<lbrakk>s\\<in>b; \\<Gamma>1=\\<Gamma>\\<^sub>\\<not>\\<^sub>a ; \\<Gamma>1\\<turnstile>\\<langle>ca1,Normal s\\<rangle> \\<Rightarrow> t; \n                  t = Abrupt t'\\<rbrakk> \\<Longrightarrow> \n                 \\<Gamma>\\<turnstile>\\<^sub>c(Await b ca1 e,Normal s) \\<rightarrow> (Throw,Normal t')\"\n\n| Callc: \"\\<lbrakk>\\<Gamma> p = Some bdy ; bdy\\<noteq>Call p\\<rbrakk> \\<Longrightarrow>\n         \\<Gamma>\\<turnstile>\\<^sub>c(Call p,Normal s) \\<rightarrow> (bdy,Normal s)\"\n\n| CallUndefinedc: \"\\<Gamma> p=None \\<Longrightarrow>\n         \\<Gamma>\\<turnstile>\\<^sub>c(Call p,Normal s) \\<rightarrow> (Skip,Stuck)\"\n\n| DynComc: \"\\<Gamma>\\<turnstile>\\<^sub>c(DynCom c,Normal s) \\<rightarrow> (c s,Normal s)\"\n\n| Catchc: \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<^sub>c(c\\<^sub>1,s) \\<rightarrow> (c\\<^sub>1',s')\\<rbrakk>\n          \\<Longrightarrow>\n          \\<Gamma>\\<turnstile>\\<^sub>c(Catch c\\<^sub>1 c\\<^sub>2,s) \\<rightarrow> (Catch c\\<^sub>1' c\\<^sub>2,s')\"\n\n| CatchThrowc: \"\\<Gamma>\\<turnstile>\\<^sub>c(Catch Throw c\\<^sub>2,Normal s) \\<rightarrow> (c\\<^sub>2,Normal s)\"\n| CatchSkipc: \"\\<Gamma>\\<turnstile>\\<^sub>c(Catch Skip c\\<^sub>2,s) \\<rightarrow> (Skip,s)\"\n\n| FaultPropc:  \"\\<lbrakk>c\\<noteq>Skip; redex c = c\\<rbrakk> \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(c,Fault f) \\<rightarrow> (Skip,Fault f)\"\n| StuckPropc:  \"\\<lbrakk>c\\<noteq>Skip; redex c = c\\<rbrakk> \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(c,Stuck) \\<rightarrow> (Skip,Stuck)\"\n| AbruptPropc: \"\\<lbrakk>c\\<noteq>Skip; redex c = c\\<rbrakk> \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(c,Abrupt f) \\<rightarrow> (Skip,Abrupt f)\"\n                                                              \nlemmas stepc_induct = stepc.induct [of _ \"(c,s)\" \"(c',s')\", split_format (complete), case_names\nBasicc Specc SpecStuckc Guardc GuardFaultc Seqc SeqSkipc SeqThrowc CondTruec CondFalsec\nWhileTruec WhileFalsec Awaitc AwaitAbruptc Callc CallUndefinedc DynComc Catchc CatchThrowc CatchSkipc\nFaultPropc StuckPropc AbruptPropc, induct set]\n\ninductive_cases stepc_call_skip_normal:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Call p,Normal s) \\<rightarrow> (Skip,s')\"\n\ninductive_cases stepc_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Skip,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Guard f g c,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Basic f e,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Spec r e,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Seq c1 c2,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Cond b c1 c2,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(While b c,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Await b c2 e,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Call p,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(DynCom c,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Throw,s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,s) \\<rightarrow> u\"\n\ninductive_cases stepc_not_normal_elim_cases:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Call p,Abrupt s) \\<rightarrow> (p',s')\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Call p, Fault f) \\<rightarrow> (p',s')\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Call p, Stuck) \\<rightarrow> (p',s')\"\n \n\nlemma Guardc_not_c:\"Guard f g c \\<noteq> c\"\nproof (induct c)\nqed auto\n\nlemma Catch_not_c1:\"Catch c1 c2 \\<noteq> c1\"\nproof (induct c1)\nqed auto\n\nlemma Catch_not_c:\"Catch c1 c2 \\<noteq> c2\"\nproof (induct c2)\nqed auto\n\nlemma seq_not_eq1: \"Seq c1 c2\\<noteq>c1\"\n  by (induct c1) auto\n\nlemma seq_not_eq2: \"Seq c1 c2\\<noteq>c2\"\n  by (induct c2) auto\n\nlemma if_not_eq1: \"Cond b c1 c2 \\<noteq>c1\"\n  by (induct c1) auto\n\nlemma if_not_eq2: \"Cond b c1 c2\\<noteq>c2\"\n  by (induct c2) auto\n\n\nlemmas seq_and_if_not_eq [simp] = seq_not_eq1 seq_not_eq2 \nseq_not_eq1 [THEN not_sym] seq_not_eq2 [THEN not_sym] \nif_not_eq1 if_not_eq2 if_not_eq1 [THEN not_sym] if_not_eq2 [THEN not_sym]\nCatch_not_c1 Catch_not_c Catch_not_c1 [THEN not_sym] Catch_not_c[THEN not_sym] \nGuardc_not_c Guardc_not_c[THEN not_sym]\n\ninductive_cases stepc_elim_cases_Seq_Seq:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Seq c1 c2,s) \\<rightarrow> (Seq c1' c2,s')\" \n\ninductive_cases stepc_elim_cases_Seq_Seq1:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Seq c1 c2,Fault f) \\<rightarrow> (q,s')\" \n\ninductive_cases stepc_elim_cases_Catch_Catch:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,s) \\<rightarrow> (Catch c1' c2,s')\" \n\ninductive_cases stepc_elim_cases_Catch_Catch1:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Seq c1 c2,Fault f) \\<rightarrow> (q,s')\" \n\ninductive_cases stepc_elim_cases_Seq_skip:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Seq Skip c2,s) \\<rightarrow> u\" \n\"\\<Gamma>\\<turnstile>\\<^sub>c(Seq (Guard f g c1) c2,s) \\<rightarrow> u\"\n\n\ninductive_cases stepc_elim_cases_Catch_skip:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch Skip c2,s) \\<rightarrow> u\"\n\ninductive_cases stepc_elim_cases_Await_skip:\n\"\\<Gamma>\\<turnstile>\\<^sub>c (Await b c e, Normal s) \\<rightarrow> (Skip,t)\"\n\ninductive_cases stepc_elim_cases_Await_throw:\n\"\\<Gamma>\\<turnstile>\\<^sub>c (Await b c e, Normal s) \\<rightarrow> (Throw,t)\"\n\ninductive_cases stepc_elim_cases_Catch_throw:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,s) \\<rightarrow> (Throw, Normal s1)\" \n\ninductive_cases stepc_elim_cases_Catch_skip_c2:\n\"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,s) \\<rightarrow> (c2,s)\"\n\ninductive_cases stepc_Normal_elim_cases [cases set]:\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Skip,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Guard f g c,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Basic f e,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Spec r e,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Seq c1 c2,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Cond b c1 c2,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(While b c,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Await b c e,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Call p,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(DynCom c,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Throw,Normal s) \\<rightarrow> u\"\n \"\\<Gamma>\\<turnstile>\\<^sub>c(Catch c1 c2,Normal s) \\<rightarrow> u\"\n\n\ntext \\<open> The final configuration is either of the form @{text \"(Skip,_)\"} for normal\ntermination, or @{term \"(Throw,Normal s)\"} in case the program was started in \na @{term \"Normal\"} state and terminated abruptly. The @{const \"Abrupt\"} state is not used to\nmodel abrupt termination, in contrast to the big-step semantics. Only if the\nprogram starts in an @{const \"Abrupt\"} states it ends in the same @{term \"Abrupt\"}\nstate.\\<close>\n\ndefinition final:: \"('s,'p,'f,'e) config \\<Rightarrow> bool\" where\n\"final cfg \\<equiv> (fst cfg=Skip \\<or> ((fst cfg=Throw) \\<and> (\\<exists>s. snd cfg=Normal s)))\"\n\ndefinition final_valid::\"('s,'p,'f,'e) config \\<Rightarrow> bool\" where\n\"final_valid cfg = ((fst cfg=Skip \\<or> fst cfg=Throw) \\<and> (\\<exists>s. snd cfg=Normal s))\"\n\nabbreviation \n \"stepc_rtrancl\" :: \"[('s,'p,'f,'e) body,('s,'p,'f,'e) config,('s,'p,'f,'e) config] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>c (_ \\<rightarrow>\\<^sup>*/ _)\" [81,81,81] 100)\n where                                \n  \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sup>* cf1 \\<equiv> ((CONST stepc \\<Gamma>))\\<^sup>*\\<^sup>* cf0 cf1\" \n  (* \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sup>* cf1 \\<equiv> (CONST ((stepc \\<Gamma>) \\<union> (step_e \\<Gamma>)))\\<^sup>*\\<^sup>* cf0 cf1\" *)\n\nabbreviation \n \"stepc_trancl\" :: \"[('s,'p,'f,'e) body,('s,'p,'f,'e) config,('s,'p,'f,'e) config] \\<Rightarrow> bool\"\n                                (\"_\\<turnstile>\\<^sub>c (_ \\<rightarrow>\\<^sup>+/ _)\" [81,81,81] 100)\n where\n  \"\\<Gamma>\\<turnstile>\\<^sub>c cf0 \\<rightarrow>\\<^sup>+ cf1 \\<equiv> (CONST stepc \\<Gamma>)\\<^sup>+\\<^sup>+ cf0 cf1\"\n\nlemma \n   assumes step_a: \"\\<Gamma>\\<turnstile>\\<^sub>c(Await b c e, Normal s) \\<rightarrow> (t,u)\"\n   shows step_await_step_c:\"(\\<Gamma>\\<^sub>\\<not>\\<^sub>a)\\<turnstile>(c, Normal s) \\<rightarrow>\\<^sup>* (sequential t,u)\" \nusing step_a\nproof cases\n  fix t1\n  assume\n      \"(t, u) = (Skip, t1)\" \"s \\<in> b\" \"(\\<Gamma>\\<^sub>\\<not>\\<^sub>a)\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> t1\" \"\\<forall>t'. t1 \\<noteq> Abrupt t'\"\n  thus ?thesis \n   by (cases u) \n   (auto intro: exec_impl_steps_Fault exec_impl_steps_Normal exec_impl_steps_Stuck)\nnext\n  fix t1\n  assume \"(t, u) = (Throw, Normal t1)\" \"s \\<in> b\" \"(\\<Gamma>\\<^sub>\\<not>\\<^sub>a)\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> Abrupt t1\"\n  thus ?thesis by (simp add: exec_impl_steps_Normal_Abrupt)\nqed\n\nlemma \n   assumes (* exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" and\n           b: \"s \\<in> b\" and *)\n           step_a: \"\\<Gamma>\\<turnstile>\\<^sub>c(Await b c e, Normal s) \\<rightarrow> u\"\n   shows step_await_final1:\"final u\"\nusing step_a \nproof cases\n  case  (1 t) thus \"final u\"  by (simp add: final_def)\nnext\n  case (2 t)\n  thus \"final u\" by (simp add: exec_impl_steps_Normal_Abrupt final_def)\nqed\n\nlemma step_Abrupt_end: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, s) \\<rightarrow> (c\\<^sub>1', s')\"\n  shows \"s'=Abrupt x \\<Longrightarrow> s=Abrupt x\"\nusing step      \n  by induct auto\n\nlemma step_not_abrupt_end:\n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, s) \\<rightarrow> (c\\<^sub>1', s')\" and \n         not_abr:\"\\<forall>s'. s\\<noteq>Abrupt s'\" and \n         abr:\"\\<exists>s. s' = Abrupt s\"\n  shows \"P\"\nusing step not_abr abr\nby induct auto\n\nlemma step_Stuck_end: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, s) \\<rightarrow> (c\\<^sub>1', s')\"\n  shows \"s'=Stuck \\<Longrightarrow> \n          s=Stuck \\<or> \n          (\\<exists>r x e. redex c\\<^sub>1 = Spec r e \\<and> s=Normal x \\<and> (\\<forall>t. (x,t)\\<notin>r)) \\<or> \n          (\\<exists>p x. redex c\\<^sub>1=  Call p \\<and> s=Normal x \\<and> \\<Gamma> p = None) \\<or>\n          (\\<exists>b c x e.  redex c\\<^sub>1 = Await b c e \\<and> s=Normal x \\<and> x \\<in> b \\<and> (\\<Gamma>\\<^sub>\\<not>\\<^sub>a)\\<turnstile>\\<langle>c,s\\<rangle>\\<Rightarrow>s')\"\nusing step\nby induct auto\n\nlemma step_Fault_end: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, s) \\<rightarrow> (c\\<^sub>1', s')\"\n  shows \"s'=Fault f \\<Longrightarrow> \n          s=Fault f \\<or> \n          (\\<exists>g c x.  redex c\\<^sub>1 = Guard f g c \\<and> s=Normal x \\<and> x \\<notin> g) \\<or>\n          (\\<exists>b c1 x e.  redex c\\<^sub>1 = Await b c1 e \\<and> s=Normal x \\<and> x \\<in> b \\<and> (\\<Gamma>\\<^sub>\\<not>\\<^sub>a)\\<turnstile>\\<langle>c1,s\\<rangle>\\<Rightarrow>s')\"\nusing step \nby induct auto\n\nlemma step_not_Fault_f_end:\n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, s) \\<rightarrow> (c\\<^sub>1', s')\"\n  shows \"s'\\<notin> Fault ` f \\<Longrightarrow> s \\<notin> Fault ` f\"\nusing step \n  by induct auto\n\n(* ************************************************************************ *)\nsubsection {* Structural Properties of Small Step Computations *}\n(* ************************************************************************ *)\nlemma redex_not_Seq: \"redex c = Seq c1 c2 \\<Longrightarrow> P\"\n  apply (induct c)\n  apply auto\n  done\nlemma redex_not_Catch: \"redex c = Catch c1 c2 \\<Longrightarrow> P\"\n  apply (induct c)\n  apply auto\n  done\n\n\n\n\nlemma no_step_final':\n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c cfg \\<rightarrow> cfg'\"\n  shows \"final cfg \\<Longrightarrow> P\"\nusing step\n  by (cases cfg, cases cfg') (auto intro: no_step_final)\n\n\nlemma step_Abrupt:\n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s')\"\n  shows \"\\<And>x. s=Abrupt x \\<Longrightarrow> s'=Abrupt x\"\nusing step\nby (induct) auto\n\nlemma step_Fault: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s')\"\n  shows \"\\<And>f. s=Fault f \\<Longrightarrow> s'=Fault f\"\nusing step\nby (induct) auto\n\nlemma step_Stuck: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s')\"\n  shows \"\\<And>f. s=Stuck \\<Longrightarrow> s'=Stuck\"\nusing step\nby (induct) auto\n\nlemma step_not_normal_not_normal:\n  assumes step:\"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s')\"\n  shows \"\\<forall>s1. s\\<noteq>Normal s1 \\<Longrightarrow> \\<forall>s1. s' \\<noteq> Normal s1\"\nusing step step_Abrupt step_Stuck step_Fault\nby (induct) auto\n\nlemma step_not_normal_s_eq_t:\n  assumes step:\"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', t)\"\n  shows \"\\<forall>s1. s\\<noteq>Normal s1 \\<Longrightarrow> s=t\"\nusing step step_Abrupt step_Stuck step_Fault\nby (induct) auto\n\nlemma SeqSteps: \n  assumes steps: \"\\<Gamma>\\<turnstile>\\<^sub>c cfg\\<^sub>1\\<rightarrow>\\<^sup>* cfg\\<^sub>2\"\n  shows \"\\<And> c\\<^sub>1 s c\\<^sub>1' s'. \\<lbrakk>cfg\\<^sub>1 = (c\\<^sub>1,s);cfg\\<^sub>2=(c\\<^sub>1',s')\\<rbrakk>\n          \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(Seq c\\<^sub>1 c\\<^sub>2,s) \\<rightarrow>\\<^sup>* (Seq c\\<^sub>1' c\\<^sub>2, s')\"\nusing steps\nproof (induct rule: converse_rtranclp_induct [case_names Refl Trans]) \n  case Refl\n  thus ?case\n    by simp\nnext\n  case (Trans cfg\\<^sub>1 cfg'')      \n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c cfg\\<^sub>1 \\<rightarrow> cfg''\" using Trans.hyps(1) by blast\n  have steps: \"\\<Gamma>\\<turnstile>\\<^sub>c cfg'' \\<rightarrow>\\<^sup>* cfg\\<^sub>2\" by fact\n  have cfg\\<^sub>1: \"cfg\\<^sub>1 = (c\\<^sub>1, s)\" and cfg\\<^sub>2: \"cfg\\<^sub>2 = (c\\<^sub>1', s')\"  by fact+\n  obtain c\\<^sub>1'' s'' where cfg'': \"cfg''=(c\\<^sub>1'',s'')\"\n    by (cases cfg'') auto\n  from step cfg\\<^sub>1 cfg'' \n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1,s) \\<rightarrow> (c\\<^sub>1'',s'')\"\n    by simp  \n  hence \"\\<Gamma>\\<turnstile>\\<^sub>c (Seq c\\<^sub>1 c\\<^sub>2,s) \\<rightarrow> (Seq c\\<^sub>1'' c\\<^sub>2,s'')\" by (simp add: Seqc)    \n  also from Trans.hyps (3) [OF cfg'' cfg\\<^sub>2]\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Seq c\\<^sub>1'' c\\<^sub>2, s'') \\<rightarrow>\\<^sup>* (Seq c\\<^sub>1' c\\<^sub>2, s')\" .\n  finally show ?case .\nqed\n\nlemma CatchSteps: \n  assumes steps: \"\\<Gamma>\\<turnstile>\\<^sub>ccfg\\<^sub>1\\<rightarrow>\\<^sup>* cfg\\<^sub>2\"\n  shows \"\\<And> c\\<^sub>1 s c\\<^sub>1' s'. \\<lbrakk>cfg\\<^sub>1 = (c\\<^sub>1,s); cfg\\<^sub>2=(c\\<^sub>1',s')\\<rbrakk>\n          \\<Longrightarrow> \\<Gamma>\\<turnstile>\\<^sub>c(Catch c\\<^sub>1 c\\<^sub>2,s) \\<rightarrow>\\<^sup>* (Catch c\\<^sub>1' c\\<^sub>2, s')\"\nusing steps\nproof (induct rule: converse_rtranclp_induct [case_names Refl Trans])\n  case Refl\n  thus ?case\n    by simp\nnext\n  case (Trans cfg\\<^sub>1 cfg'')\n  have step: \"\\<Gamma>\\<turnstile>\\<^sub>c cfg\\<^sub>1 \\<rightarrow> cfg''\" by fact\n  have steps: \"\\<Gamma>\\<turnstile>\\<^sub>c cfg'' \\<rightarrow>\\<^sup>* cfg\\<^sub>2\" by fact\n  have cfg\\<^sub>1: \"cfg\\<^sub>1 = (c\\<^sub>1, s)\" and cfg\\<^sub>2: \"cfg\\<^sub>2 = (c\\<^sub>1', s')\"  by fact+\n  obtain c\\<^sub>1'' s'' where cfg'': \"cfg''=(c\\<^sub>1'',s'')\"\n    by (cases cfg'') auto\n  from step cfg\\<^sub>1 cfg'' \n  have s: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1,s) \\<rightarrow> (c\\<^sub>1'',s'')\"\n    by simp\n  hence \"\\<Gamma>\\<turnstile>\\<^sub>c (Catch c\\<^sub>1 c\\<^sub>2,s) \\<rightarrow> (Catch c\\<^sub>1'' c\\<^sub>2,s'')\"\n    by (rule stepc.Catchc)\n  also from Trans.hyps (3) [OF cfg'' cfg\\<^sub>2]\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Catch c\\<^sub>1'' c\\<^sub>2, s'') \\<rightarrow>\\<^sup>* (Catch c\\<^sub>1' c\\<^sub>2, s')\" .\n  finally show ?case .      \nqed\n\nlemma steps_Fault: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, Fault f) \\<rightarrow>\\<^sup>* (Skip, Fault f)\"\nproof (induct c)\n  case (Seq c\\<^sub>1 c\\<^sub>2)\n  have steps_c\\<^sub>1: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, Fault f) \\<rightarrow>\\<^sup>* (Skip, Fault f)\" by fact\n  have steps_c\\<^sub>2: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>2, Fault f) \\<rightarrow>\\<^sup>* (Skip, Fault f)\" by fact\n  from SeqSteps [OF steps_c\\<^sub>1 refl refl]\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Seq c\\<^sub>1 c\\<^sub>2, Fault f) \\<rightarrow>\\<^sup>* (Seq Skip c\\<^sub>2, Fault f)\".\n  also\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Seq Skip c\\<^sub>2, Fault f) \\<rightarrow> (c\\<^sub>2, Fault f)\" by (rule SeqSkipc)\n  also note steps_c\\<^sub>2\n  finally show ?case by simp\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have steps_c\\<^sub>1: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, Fault f) \\<rightarrow>\\<^sup>* (Skip, Fault f)\" by fact\n  from CatchSteps [OF steps_c\\<^sub>1 refl refl]\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Catch c\\<^sub>1 c\\<^sub>2, Fault f) \\<rightarrow>\\<^sup>* (Catch Skip c\\<^sub>2, Fault f)\".\n  also\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Catch Skip c\\<^sub>2, Fault f) \\<rightarrow> (Skip, Fault f)\" by (rule CatchSkipc) \n  finally show ?case by simp\nqed (fastforce intro: stepc.intros)+\n\n\nlemma steps_Stuck: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, Stuck) \\<rightarrow>\\<^sup>* (Skip, Stuck)\"\nproof (induct c)\n  case (Seq c\\<^sub>1 c\\<^sub>2)\n  have steps_c\\<^sub>1: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, Stuck) \\<rightarrow>\\<^sup>* (Skip, Stuck)\" by fact\n  have steps_c\\<^sub>2: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>2, Stuck) \\<rightarrow>\\<^sup>* (Skip, Stuck)\" by fact\n  from SeqSteps [OF steps_c\\<^sub>1 refl refl]\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Seq c\\<^sub>1 c\\<^sub>2, Stuck) \\<rightarrow>\\<^sup>* (Seq Skip c\\<^sub>2, Stuck)\".\n  also\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Seq Skip c\\<^sub>2, Stuck) \\<rightarrow> (c\\<^sub>2, Stuck)\" by (rule SeqSkipc)\n  also note steps_c\\<^sub>2\n  finally show ?case by simp\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have steps_c\\<^sub>1: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, Stuck) \\<rightarrow>\\<^sup>* (Skip, Stuck)\" by fact\n  from CatchSteps [OF steps_c\\<^sub>1 refl refl]\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Catch c\\<^sub>1 c\\<^sub>2, Stuck) \\<rightarrow>\\<^sup>* (Catch Skip c\\<^sub>2, Stuck)\" .\n  also\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Catch Skip c\\<^sub>2, Stuck) \\<rightarrow> (Skip, Stuck)\" by (rule CatchSkipc) \n  finally show ?case by simp\nqed (fastforce intro: stepc.intros)+\n\nlemma steps_Abrupt: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, Abrupt s) \\<rightarrow>\\<^sup>* (Skip, Abrupt s)\"\nproof (induct c)\n  case (Seq c\\<^sub>1 c\\<^sub>2)\n  have steps_c\\<^sub>1: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, Abrupt s) \\<rightarrow>\\<^sup>* (Skip, Abrupt s)\" by fact\n  have steps_c\\<^sub>2: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>2, Abrupt s) \\<rightarrow>\\<^sup>* (Skip, Abrupt s)\" by fact\n  from SeqSteps [OF steps_c\\<^sub>1 refl refl]\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Seq c\\<^sub>1 c\\<^sub>2, Abrupt s) \\<rightarrow>\\<^sup>* (Seq Skip c\\<^sub>2, Abrupt s)\".\n  also\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Seq Skip c\\<^sub>2, Abrupt s) \\<rightarrow> (c\\<^sub>2, Abrupt s)\" by (rule SeqSkipc)\n  also note steps_c\\<^sub>2\n  finally show ?case by simp\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have steps_c\\<^sub>1: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, Abrupt s) \\<rightarrow>\\<^sup>* (Skip, Abrupt s)\" by fact\n  from CatchSteps [OF steps_c\\<^sub>1 refl refl]\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Catch c\\<^sub>1 c\\<^sub>2, Abrupt s) \\<rightarrow>\\<^sup>* (Catch Skip c\\<^sub>2, Abrupt s)\".\n  also\n  have \"\\<Gamma>\\<turnstile>\\<^sub>c (Catch Skip c\\<^sub>2, Abrupt s) \\<rightarrow> (Skip, Abrupt s)\" by (rule CatchSkipc) \n  finally show ?case by simp\nqed (fastforce intro: stepc.intros)+\n\nlemma step_Fault_prop: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s')\"\n  shows \"\\<And>f. s=Fault f \\<Longrightarrow> s'=Fault f\"\nusing step\nby (induct) auto\n\nlemma step_Abrupt_prop: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s')\"\n  shows \"\\<And>x. s=Abrupt x \\<Longrightarrow> s'=Abrupt x\"\nusing step\nby (induct) auto\n\nlemma step_Stuck_prop: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s')\"\n  shows \"s=Stuck \\<Longrightarrow> s'=Stuck\"\nusing step\nby (induct) auto\n\nlemma steps_Fault_prop: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sup>* (c', s')\"\n  shows \"s=Fault f \\<Longrightarrow> s'=Fault f\"\nusing step\nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl thus ?case by simp\nnext\n  case (Trans c s c'' s'')\n  thus ?case by (simp add: step_Fault_prop)    \nqed\n\nlemma steps_Abrupt_prop: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sup>* (c', s')\"\n  shows \"s=Abrupt t \\<Longrightarrow> s'=Abrupt t\"\nusing step\nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl thus ?case by simp\nnext\n  case (Trans c s c'' s'')\n  thus ?case\n    by (auto intro: step_Abrupt_prop)\nqed\n\nlemma steps_Stuck_prop: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sup>* (c', s')\"\n  shows \"s=Stuck \\<Longrightarrow> s'=Stuck\"\nusing step\nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl thus ?case by simp   \nnext\n  case (Trans c s c'' s'')\n  thus ?case\n    by (auto intro: step_Stuck_prop)\nqed\n\nlemma step_seq_throw_normal:\nassumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s')\" and\n        c_val: \"c=Seq Throw Q \\<and> c'=Throw\"\nshows \"\\<exists>sa. s=Normal sa\"\nusing step c_val\nproof (cases s)\n  case Normal \n  thus \"\\<exists>sa. s=Normal sa\" by auto\nnext\n  case Abrupt\n  thus \"\\<exists>sa. s=Normal sa\" using step c_val stepc_elim_cases(5)[of \\<Gamma> Throw Q s \"(Throw,s')\"] by auto \nnext \n  case Stuck\n  thus \"\\<exists>sa. s=Normal sa\" using step c_val stepc_elim_cases(5)[of \\<Gamma> Throw Q s \"(Throw,s')\"] by auto\nnext\n  case Fault\n    thus \"\\<exists>sa. s=Normal sa\" using step c_val stepc_elim_cases(5)[of \\<Gamma> Throw Q s \"(Throw,s')\"] by auto\nqed\n\n\nlemma step_catch_throw_normal:\nassumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow> (c', s')\" and\n        c_val: \"c=Catch Throw Q \\<and> c'=Throw\"\nshows \"\\<exists>sa. s=Normal sa\"\nusing step c_val\nproof (cases s)\n  case Normal \n  thus \"\\<exists>sa. s=Normal sa\" by auto\nnext\n  case Abrupt\n  thus \"\\<exists>sa. s=Normal sa\" using step c_val stepc_elim_cases(12)[of \\<Gamma> Throw Q s \"(Throw,s')\"] by auto \nnext \n  case Stuck\n  thus \"\\<exists>sa. s=Normal sa\" using step c_val stepc_elim_cases(12)[of \\<Gamma> Throw Q s \"(Throw,s')\"] by auto\nnext\n  case Fault\n    thus \"\\<exists>sa. s=Normal sa\" using step c_val stepc_elim_cases(12)[of \\<Gamma> Throw Q s \"(Throw,s')\"] by auto\nqed\n\nlemma step_normal_to_normal[rule_format]:\nassumes step:\"\\<Gamma>\\<turnstile>\\<^sub>c (c, s) \\<rightarrow>\\<^sup>* (c', s')\" and\n        sn: \"s = Normal sa\" and\n        finalc':\"(\\<Gamma>\\<turnstile>\\<^sub>c (c', s') \\<rightarrow>\\<^sup>*(c1, s1) \\<and>  (\\<exists>sb. s1 = Normal sb))\"\nshows \" (\\<exists>sc. s'=Normal sc)\"\nusing step sn finalc'                                  \n proof (induct arbitrary: sa rule: converse_rtranclp_induct2 [case_names Refl Trans])\n   case Refl show ?case by (simp add: Refl.prems)              \n next     \n   case (Trans c s c'' s'') thm converse_rtranclpE2 \n     thus ?case\n     proof (cases s'')  \n      case (Abrupt a1) thus ?thesis using finalc' by (metis steps_Abrupt_prop Trans.hyps(2))                \n     next\n      case Stuck thus ?thesis using finalc' by (metis steps_Stuck_prop Trans.hyps(2))          \n     next\n      case Fault thus ?thesis using finalc' by (metis steps_Fault_prop Trans.hyps(2))        \n     next \n      case Normal thus ?thesis using Trans.hyps(3) finalc' by blast \n    qed \nqed\n\nlemma step_spec_skip_normal_normal:\n  assumes a0:\"\\<Gamma>\\<turnstile>\\<^sub>c (c,s)  \\<rightarrow> (c',s')\" and\n          a1:\"c=Spec r e\" and\n          a2: \"s=Normal s1\" and\n          a3: \"c'=Skip\" and\n          a4: \"(\\<exists>t. (s1,t) \\<in> r)\"\n  shows \"\\<exists>s1'. s'=Normal s1'\"\nproof (cases s')  \n  case (Normal u) thus ?thesis by auto\nnext\n  case Stuck \n    have \"\\<forall>f r b p e. \\<not> f\\<turnstile>\\<^sub>c (LanguageCon.com.Spec r e, Normal b) \\<rightarrow> p \\<or> \n            (\\<exists>ba. p = (Skip::('b, 'a, 'c,'d) com, Normal ba) \\<and> (b, ba) \\<in> r) \\<or> \n            p = (Skip, Stuck) \\<and> (\\<forall>ba. (b, ba) \\<notin> r)\"\n      by (meson stepc_Normal_elim_cases(4))\n      thus ?thesis using a0 a1 a2 a4 by blast\nnext\n  case (Fault f) \n  have \"\\<forall>f r b p e. \\<not> f\\<turnstile>\\<^sub>c (LanguageCon.com.Spec r e, Normal b) \\<rightarrow> p \\<or> \n            (\\<exists>ba. p = (Skip::('b, 'a, 'c,'d) com, Normal ba) \\<and> (b, ba) \\<in> r) \\<or> \n            p = (Skip, Stuck) \\<and> (\\<forall>ba. (b, ba) \\<notin> r)\"\n    by (meson stepc_Normal_elim_cases(4))\n    thus ?thesis using a0 a1 a2 a4 by blast                       \nnext\n  have \"\\<forall>f r b p e. \\<not> f\\<turnstile>\\<^sub>c (LanguageCon.com.Spec r e, Normal b) \\<rightarrow> p \\<or> \n        (\\<exists>ba. p = (Skip::('b, 'a, 'c,'d) com, Normal ba) \\<and> (b, ba) \\<in> r) \\<or> \n        p = (Skip, Stuck) \\<and> (\\<forall>ba. (b, ba) \\<notin> r)\"\n    by (meson stepc_Normal_elim_cases(4))\n    thus ?thesis using a0 a1 a2 a4 by blast\nqed\n\n\ntext{* if not Normal not environmental *}\n\n(* \n\nNOTE\nCall always change the program now \n\nlemma no_advance_call_inf:\nassumes a0: \"redex p1 = Call f\" and\n        a1: \"(\\<Gamma> f) = Some (Call f)\" \nshows \"\\<Gamma>\\<turnstile>\\<^sub>c (p1,Normal s) \\<rightarrow> (p1, Normal s)\"\nusing a0 a1\nproof (induct p1)\n  case (Catch) thus ?case by (simp add: Catchc)\nnext\n  case (Seq) thus ?case by (simp add: Seqc)\nnext\n  case (Call) thus ?case\n    by (simp add: Callc) \nqed(auto) *)\n\nlemma no_advance_seq:\nassumes a0: \"P = Seq p1 p2\" and\n        a1: \"\\<Gamma>\\<turnstile>\\<^sub>c (p1,Normal s) \\<rightarrow> (p1, Normal s)\"\nshows \"\\<Gamma>\\<turnstile>\\<^sub>c (P,Normal s) \\<rightarrow> (P, Normal s)\"\nby (simp add: Seqc a0 a1)\n\nlemma no_advance_catch:\nassumes a0: \"P = Catch p1 p2\" and\n        a1: \"\\<Gamma>\\<turnstile>\\<^sub>c (p1,Normal s) \\<rightarrow> (p1, Normal s)\"\nshows \"\\<Gamma>\\<turnstile>\\<^sub>c (P,Normal s) \\<rightarrow> (P, Normal s)\"\nby (simp add: Catchc a0 a1)\n\nlemma call_not_normal_skip_always:\n  assumes a0:\"\\<Gamma>\\<turnstile>\\<^sub>c(Call p,s) \\<rightarrow> (p1,s1)\" and\n          a1:\"\\<forall>sn. s \\<noteq> Normal sn\" and\n          a2:\"p1\\<noteq>Skip\"\n  shows \"P\" \nproof(cases s)\n  case Normal thus ?thesis using a1 by fastforce\nnext\n  case Stuck \n  then have a0:\"\\<Gamma>\\<turnstile>\\<^sub>c(Call p,Stuck) \\<rightarrow> (p1,s1)\" using a0 by auto\n  show ?thesis using  a1 a2 stepc_not_normal_elim_cases(3)[OF a0] by fastforce\nnext\n  case (Fault f) \n  then have a0:\"\\<Gamma>\\<turnstile>\\<^sub>c(Call p,Fault f) \\<rightarrow> (p1,s1)\" using a0 by auto\n  show ?thesis using  a1 a2 stepc_not_normal_elim_cases(2)[OF a0] by fastforce\nnext\n  case (Abrupt a)\n  then have a0:\"\\<Gamma>\\<turnstile>\\<^sub>c(Call p,Abrupt a) \\<rightarrow> (p1,s1)\" using a0 by auto\n  show ?thesis using  a1 a2 stepc_not_normal_elim_cases(1)[OF a0] by fastforce\nqed\n\nlemma call_f_step_not_s_eq_t_false:\n  assumes \n     a0:\"\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow> (Q,t)\" and\n     a1:\"(redex P = Call fn \\<and> \\<Gamma> fn = Some bdy \\<and> s=Normal s' \\<and> ~(s=t)) \\<or>\n         (redex P = Call fn \\<and> \\<Gamma> fn = Some bdy \\<and> s=Normal s' \\<and> s=t \\<and> P=Q \\<and> \\<Gamma> fn \\<noteq> Some (Call fn))\"\n  shows \"False\"\nusing a0 a1\nproof (induct rule:stepc_induct)\nqed(fastforce+,auto)\n\nlemma step_change_p_or_eq_Ns: \n    assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P,Normal s) \\<rightarrow> (Q,s')\"\n    shows  \"\\<not>(P=Q)\"\nusing step\nproof (induct P arbitrary: Q s s')\nqed(fastforce elim: stepc_Normal_elim_cases)+\n\n \nlemma step_change_p_or_eq_s: \n    assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (P,s) \\<rightarrow> (Q,s')\"\n    shows  \"\\<not>(P=Q)\"\nusing step\nproof (induct P arbitrary: Q s s')\nqed (fastforce elim: stepc_elim_cases)+\n\nsubsection \\<open>Lemmas on normalization\\<close>\n\n(* lemma step_sequence_flatten:\n  assumes exec: \"\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow> (Q,t)\" \n  shows \"\\<Gamma>\\<turnstile>\\<^sub>c(sequence Seq (flatten P),s) \\<rightarrow> (sequence Seq (flatten Q),t)\"\nusing exec\nproof (induct rule: stepc_induct)\n  case (Guardc s g f c) thus ?case using stepc.Guardc\n  case (Seqc c1 s c2 s' c2')\n  then have \" \\<Gamma>\\<turnstile>\\<^sub>c (Seq (LanguageCon.sequence LanguageCon.com.Seq (LanguageCon.flatten c1)) c2', s) \\<rightarrow>\n                   (Seq (LanguageCon.sequence LanguageCon.com.Seq (LanguageCon.flatten c2)) c2', s') \" \n    using stepc.Seqc by fastforce    \n  thus ?case sorry\nqed(auto intro:stepc.intros)+\n\nlemma normalice_step:\n  assumes exec:\"\\<Gamma>\\<turnstile>\\<^sub>c(P,s) \\<rightarrow> (Q,t)\" \n  shows  \"\\<Gamma>\\<turnstile>\\<^sub>c( normalizec P,s) \\<rightarrow> (normalizec Q,t)\"\nusing exec\nproof(induct rule:stepc_induct)\n  case (Catchc P s Q t c2)\n    thus ?case\n   *) \n(* qed(auto intro: stepc.intros) *)\n\n\nlemma mod_env_not_component:\nshows    \"\\<not> \\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow> (P, t)\"\nproof \n  assume a3:\"\\<Gamma>\\<turnstile>\\<^sub>c (P, s) \\<rightarrow> (P, t)\"           \n  thus  False using step_change_p_or_eq_s a3 by fastforce\nqed\n\nlemma redex_not_call_seq_catch:\n assumes a0:\"redex P = Call f \\<and> P\\<noteq>Call f\"          \n shows \"\\<exists>p1 p2. P = Seq p1 p2 \\<or> P = Catch p1 p2\"\nusing a0 \nproof(induct P)\nqed(fastforce+)\n\n\nlemma three_elems_list:\n  assumes a1:\"length l > 2\"\n  shows \"\\<exists>a0 a1 a2 l1. l=a0#a1#a2#l1\"\nusing a1 by (metis Cons_nth_drop_Suc One_nat_def Suc_1 Suc_leI add_lessD1 drop_0 length_greater_0_conv list.size(3) not_numeral_le_zero one_add_one)  \n\n\nlemma last_length: \"((a#xs)!(length xs))=last (a#xs)\"\n  by (induct xs) auto\n\nlemma list_eq_if [rule_format]: \n  \"\\<forall>ys. xs=ys \\<longrightarrow> (length xs = length ys) \\<longrightarrow> (\\<forall>i<length xs. xs!i=ys!i)\"\n  by (induct xs) auto\n\n\n\nlemma list_eq: \"(length xs = length ys \\<and> (\\<forall>i<length xs. xs!i=ys!i)) = (xs=ys)\"\napply(rule iffI)\n apply clarify\n apply(erule nth_equalityI)\n apply simp+\ndone\n\nlemma nth_tl: \"\\<lbrakk> ys!0=a; ys\\<noteq>[] \\<rbrakk> \\<Longrightarrow> ys=(a#(tl ys))\"\n  by (cases ys) simp_all\n\nlemma nth_tl_if [rule_format]: \"ys\\<noteq>[] \\<longrightarrow> ys!0=a \\<longrightarrow> P ys \\<longrightarrow> P (a#(tl ys))\"\n  by (induct ys) simp_all\n\nlemma nth_tl_onlyif [rule_format]: \"ys\\<noteq>[] \\<longrightarrow> ys!0=a \\<longrightarrow> P (a#(tl ys)) \\<longrightarrow> P ys\"\n  by (induct ys) simp_all\n\nlemma nth_tl_eq [rule_format]: \"ys\\<noteq>[] \\<longrightarrow> ys!0=a \\<longrightarrow> P (a#(tl ys)) = P ys\"\n  by (induct ys) simp_all\n\nlemma nth_tl_pair: \"\\<lbrakk>p=(u,ys); ys!0=a; ys\\<noteq>[] \\<rbrakk> \\<Longrightarrow> p=(u,(a#(tl ys)))\"\nby (simp add: SmallStepCon.nth_tl)\n\nlemma nth_tl_eq_Pair [rule_format]: \"p=(u,ys) \\<longrightarrow> ys\\<noteq>[] \\<longrightarrow> ys!0=a \\<longrightarrow> P ((u,a#(tl ys))) = P (u,ys)\"\n  by (induct ys) simp_all\n\nlemma tl_zero[rule_format]: \n  \" Suc j<length ys \\<longrightarrow> P (ys!Suc j) \\<longrightarrow> P (tl(ys)!j)\"\n  by (simp add: List.nth_tl)\n\nlemma tl_zero1[rule_format]:\n  \"Suc j<length ys \\<longrightarrow>P (tl(ys)!j) \\<longrightarrow>P (ys!Suc j)\"\n by (simp add: List.nth_tl)\n\nlemma tl_zero_eq [rule_format]:\n  \"Suc j<length ys \\<longrightarrow> (P (tl(ys)!j) = P (ys!Suc j))\"\nby (simp add: List.nth_tl)\n\nlemma tl_zero_eq' :\n   \"\\<forall>j. Suc j<length ys \\<longrightarrow> (P (tl(ys)!j) = P (ys!Suc j))\"\nusing tl_zero_eq by blast\n\nlemma tl_zero_pair:\"i < length ys \\<Longrightarrow> length ys = length zs \\<Longrightarrow>\n       Suc j < length (snd (ys!i)) \\<Longrightarrow>\n       snd (zs!i) = tl (snd (ys!i)) \\<Longrightarrow>        \n       P ((snd (ys!i))!(Suc j)) =\n       P ((snd (zs!i))!j)\"  \n  by (simp add: tl_zero_eq)\n\n\nlemma tl_zero_pair':\"\\<forall>i < length ys. length ys = length zs \\<longrightarrow>\n       Suc j < length (snd (ys!i)) \\<longrightarrow>\n       snd (zs!i) = tl (snd (ys!i)) \\<longrightarrow>        \n       (P ((snd (ys!i))!(Suc j)) =\n       P ((snd (zs!i))!j))\"  \nusing tl_zero_pair by blast\n\nlemma tl_zero_pair2:\"i < length ys \\<Longrightarrow> length ys = length zs \\<Longrightarrow>\n       Suc (Suc j) < length (snd (ys!i)) \\<Longrightarrow>\n       snd (zs!i) = tl (snd (ys!i)) \\<Longrightarrow>        \n       P ((snd (ys!i))!(Suc (Suc j))) ((snd (ys!i))!(Suc j))  =\n       P ((snd (zs!i))!(Suc j)) ((snd (zs!i))!j)\"  \n  by (simp add: tl_zero_eq)\n\nlemma tl_zero_pair2':\"\\<forall>i < length ys. length ys = length zs \\<longrightarrow>\n       Suc (Suc j) < length (snd (ys!i)) \\<longrightarrow>\n       snd (zs!i) = tl (snd (ys!i)) \\<longrightarrow>        \n       P ((snd (ys!i))!(Suc (Suc j))) ((snd (ys!i))!(Suc j))  =\n       P ((snd (zs!i))!(Suc j)) ((snd (zs!i))!j)\"  \nusing tl_zero_pair2  by blast\n\nlemma tl_zero_pair21:\"\\<forall>i < length ys. length ys = length zs \\<longrightarrow>\n       Suc (Suc j) < length (snd (ys!i)) \\<longrightarrow>\n       snd (zs!i) = tl (snd (ys!i)) \\<longrightarrow>        \n       P  ((snd (ys!i))!(Suc j))  ((snd (ys!i))!(Suc (Suc j)))=\n       P ((snd (zs!i))!j) ((snd (zs!i))!(Suc j)) \"\nby (metis SmallStepCon.nth_tl list.size(3) not_less0 nth_Cons_Suc)  \n\nlemma tl_pair:\"Suc (Suc j) < length l \\<Longrightarrow>     \n       l1 = tl l \\<Longrightarrow>\n       P (l!(Suc (Suc j))) (l!(Suc j)) =\n       P (l1!(Suc j)) (l1!j)\"\nby (simp add: tl_zero_eq)\n\nlemma list_as_map: \n  assumes \n     a1:\"length clist > 0\" and \n     a2: \"xs = (map (\\<lambda>x. fst (hd x)) clist)\" and\n     a3: \"ys = (map (\\<lambda>x. tl x) clist)\" and\n     a4: \"\\<forall>i< length clist. length (clist!i) > 0\" and     \n     a5: \"\\<forall>i < length clist. \\<forall>j< length clist. \\<forall>k<length  (clist!i).\n           snd ((clist!i)!k) = snd ((clist!j)!k)\" and\n     a6: \"\\<forall>i < length clist. \\<forall>j< length clist. \n            length (clist!i) = length (clist!j)\" \n     shows \"clist = map (\\<lambda>i. (fst i,snd ((clist!0)!0))#snd i) (zip xs ys)\"\nproof-\n  let ?clist'= \"map (\\<lambda>i. (fst i,snd ((clist!0)!0))#snd i) (zip xs ys)\"\n  have lens:\"length clist = length ?clist'\"  using a2 a3 by auto   \n  have \"(\\<forall>i<length clist. clist ! i = ?clist' ! i)\" \n  proof -\n    {\n      fix i    \n      assume a11:\"i<length clist\"\n      have xs_clist:\"xs!i = fst (hd (clist!i))\" using a2 a11 by auto\n      have ys_clist:\"ys!i = tl (clist ! i)\" using a3 a11 by auto\n      have snd_zero:\"snd (hd (clist!i)) = snd ((clist!0)!0)\" using a5 a4 \n        by (metis (no_types, lifting) a1 a11 hd_conv_nth less_numeral_extra(3) list.size(3))\n      then have \"(\\<lambda>i. (fst i,snd ((clist!0)!0))#snd i) ((zip xs ys)!i) = clist !i\"               \n        proof -\n          have f1: \"length xs = length clist\"\n            using a2 length_map by blast\n          have \"\\<not> (0::nat) < 0\"\n            by (meson less_not_refl)\n          thus ?thesis\n            using f1 by (metis (lifting) a11 a3 a4 \n                         fst_conv length_map list.exhaust_sel \n                         list.size(3) nth_zip prod.collapse \n                         snd_conv snd_zero xs_clist ys_clist)\n        qed      \n      then have \"clist ! i = ?clist' ! i\" using lens a11 by force\n    } \n    thus ?thesis by auto    \n  qed\n  thus ?thesis using lens list_eq by blast\nqed\n\nlemma list_as_map': \n  assumes \n     a1:\"length clist > 0\" and \n     a2: \"xs = (map (\\<lambda>x. hd x) clist)\" and\n     a3: \"ys = (map (\\<lambda>x. tl x) clist)\" and\n     a4: \"\\<forall>i< length clist. length (clist!i) > 0\"\n     shows \"clist = map (\\<lambda>i. (fst i)#snd i) (zip xs ys)\"\nproof-\n  let ?clist'= \"map (\\<lambda>i.(fst i)#snd i) (zip xs ys)\"\n  have lens:\"length clist = length ?clist'\" using a2 a3 by auto  \n  have \"(\\<forall>i<length clist. clist ! i = ?clist' ! i)\" \n  proof -\n    {\n      fix i    \n      assume a11:\"i<length clist\"\n      have xs_clist:\"xs!i = hd (clist!i)\" using a2 a11 by auto\n      have ys_clist:\"ys!i = tl (clist ! i)\" using a3 a11 by auto \n      then have \"(\\<lambda>i. fst i#snd i) ((zip xs ys)!i) = clist !i\"  \n        using xs_clist ys_clist a11 a2 a3 a4 by fastforce  \n      then have \"clist ! i = ?clist' ! i\" using lens a11 by force\n    } \n    thus ?thesis by auto    \n  qed\n  thus ?thesis using lens list_eq by blast\nqed\n\n\nlemma clist_tail: \n  assumes \n    a1:\"length xs = length clist\" and\n    a2: \"ys = (map (\\<lambda>i. (\\<Gamma>,(fst i,s)#snd i)) (zip xs clist))\"\n shows \"\\<forall>i < length ys. tl (snd (ys!i)) = clist!i \"\nusing a1 a2\nproof -   \n   show ?thesis using a2\n   by (simp add: a1)           \nqed   \n\n\nlemma clist_map: \n   assumes \n    a1:\"length xs = length clist\" \n   shows \"clist = map ((\\<lambda>p. tl (snd p)) \\<circ> (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))) (zip xs clist)\"\nproof -\n  have f1: \"map snd (zip xs clist) = clist\"\n    using a1 map_snd_zip by blast\n  have \"map snd (zip xs clist) = map ((\\<lambda>p. tl (snd p)) \\<circ> (\\<lambda>p. (\\<Gamma>, (fst p, s) # snd p))) (zip xs clist)\"\n    by simp\n  thus ?thesis\n    using f1 by presburger\nqed\n\n\nlemma clist_map1: \n   assumes \n    a1:\"length xs = length clist\"     \n   shows \"clist = map (\\<lambda>p. tl (snd p)) (map (\\<lambda>i. (\\<Gamma>,(fst i,s)#snd i)) (zip xs clist))\"\nproof -\n   have \"clist = map ((\\<lambda>p. tl (snd p)) \\<circ> (\\<lambda>i. (\\<Gamma>, (fst i, s) # snd i))) (zip xs clist)\" \n   using a1  clist_map by fastforce\n   thus ?thesis by auto\nqed\n\nlemma clist_map2:\n     \"(clist = map (\\<lambda>p. tl (snd p)) (l::('a \\<times>'b list) list) ) \\<Longrightarrow>\n       clist = map (\\<lambda>p. (snd p)) (map (\\<lambda>p. (fst p, tl (snd p))) (l::('a \\<times>'b list) list)) \"\nby auto\n\nlemma map_snd:\n   assumes a1: \"y = map  (\\<lambda>x. f x) l\"\n   shows   \"y=(map snd (map (\\<lambda>x. (g x, f x)) l)) \"\nby (simp add: assms)\n \nlemmas map_snd_sym = map_snd[THEN sym]\n\nlemma map_snd':\n   shows   \" map  (\\<lambda>x. f x) l=(map snd (map (\\<lambda>x. (g x, f x)) l)) \"\nby simp\n\n\nlemma hd_nth:\n   assumes a1:\"i< length l \\<and> ( length( (l!i)) > 0)\"\n   shows \"f (hd (l!i)) = f (nth (l!i) 0)\"\nusing assms hd_conv_nth by fastforce\n\nlemma map_hd_nth:\n   assumes a1:\"(\\<forall>i <length l. length( (l!i)) > 0)\"\n   shows \"map (\\<lambda>x. f (hd x)) l = map (\\<lambda>x. f (nth (x) 0)) l\"\nproof -  \n   have \"\\<forall>i < length l. (map (\\<lambda>x. f (hd x)) l)!i = f (nth (l!i) 0)\"\n    using hd_nth a1 by auto\n  moreover have \"\\<forall>i < length l. (map (\\<lambda>x. f (nth x 0)) l)!i = f (nth (l!i) 0)\"\n    using hd_nth a1 by auto\n  ultimately have f1:\"\\<forall>i < length l. (map (\\<lambda>x. f (hd x)) l)!i =(map (\\<lambda>x. f (nth x 0)) l)!i \"\n    by auto\n  moreover have f2:\"length (map (\\<lambda>x. f (hd x)) l) = length l\"\n    by auto   \n  moreover have \"length (map (\\<lambda>x. f (nth x 0)) l) = length l\" by auto\n  ultimately show ?thesis using nth_equalityI by metis\nqed\n\nlemma \"i<length clist \\<Longrightarrow> clist!i = (x1,ys) \\<Longrightarrow> ys = (map (\\<lambda>x. (fst (hd (snd x)),s)#tl (snd x)) clist)!i \\<Longrightarrow>\n         ys = (map (\\<lambda>x. (fst x, s)#snd x) \n               (zip (map (\\<lambda>x. fst (hd (snd x))) clist) \n                    (map (\\<lambda>x. tl (snd x)) clist)))!i\"\nproof (induct ys)\n  case Nil thus ?case by auto\nnext\n  case (Cons y ys) \n  have \"\\<forall>n ps f. \\<not> n < length ps \\<or> map f ps ! n = (f (ps ! n::'a \\<times> ('b \\<times> 'c) list)::('b \\<times> 'c) list)\"\n    by force\n  hence \"y # ys = (fst (hd (snd (clist ! i))), s) # tl (snd (clist ! i))\"\n    using Cons.prems(1) Cons.prems(3) by presburger\n  thus ?case\n    using Cons.prems(1) by auto\nqed\n\n\nlemma mapzip_upd:\" length as = length clist  \\<Longrightarrow>\n       (map (\\<lambda>j. (as ! j, sa) # clist ! j) [0..<length as]) =  \n       map (\\<lambda>j. ((fst j, sa)#snd j)) (zip as clist)\"\nproof -    \n    assume a2: \"length as = length clist\"   \n    have \"\\<forall>i < length  (map (\\<lambda>j. (as ! j, sa) # clist ! j) [0..<length as]). (map (\\<lambda>j. (as ! j, sa) # clist ! j) [0..<length as])!i = map (\\<lambda>j. ((fst j, sa)#snd j)) (zip as clist)!i\"  \n     using a2\n      by auto\n  moreover have \"length (map (\\<lambda>j. (as ! j, sa) # clist ! j) [0..<length as]) =\n         length (map (\\<lambda>j. ((fst j, sa)#snd j)) (zip as clist))\"\n     using a2 by auto   \n  ultimately have \"(map (\\<lambda>j. (as ! j, sa) # clist ! j) [0..<length as]) = map (\\<lambda>j. ((fst j, sa)#snd j)) (zip as clist)\"\n     using nth_equalityI by blast\n  thus \"map (\\<lambda>j. (as ! j, sa) # clist ! j) [0..<length as] = \n        map (\\<lambda>j. (fst j, sa) # snd j) (zip as clist) \"\n      by auto\nqed\n\n\n(************************************************************************ *)\n(* subsection {* Equivalence between Small-Step and Big-Step Semantics *} *)\n(* ************************************************************************ *)\n \n(* \n\n?\\<Gamma>\\<turnstile>\\<^sub>c (LanguageCon.com.Seq ?c1.0 ?c2.0, ?s) \\<rightarrow>\n       (LanguageCon.com.Seq ?c1' ?c2.0,\n        ?s') \\<Longrightarrow>\n(?\\<Gamma>\\<turnstile>\\<^sub>c (?c1.0, ?s) \\<rightarrow> (?c1', ?s') \\<Longrightarrow> ?P) \\<Longrightarrow>\n?P\n\nlemma \n   assumes \n           step_a: \"\\<Gamma>\\<turnstile>\\<^sub>c(Await b c, Normal s) \\<rightarrow> (t,u)\"\n   shows step_await_step_c:\"(\\<Gamma>\\<^sub>\\<not>\\<^sub>a)\\<turnstile>(c, Normal s) \\<rightarrow>\\<^sup>* (sequential t,u)\" \nusing step_a\nproof cases\n  fix t1\n  assume\n      \"(t, u) = (Skip, t1)\" \"s \\<in> b\" \"\\<Gamma>\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> t1\" \"\\<forall>t'. t1 \\<noteq> Abrupt t'\"\n  thus ?thesis \n   by (cases u) \n   (auto intro: exec_impl_steps_Fault exec_impl_steps_Normal exec_impl_steps_Stuck)\nnext\n  fix t1\n  assume \"(t, u) = (Throw, Normal t1)\" \"s \\<in> b\" \"\\<Gamma>\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> Abrupt t1\"\n  thus ?thesis by (simp add: exec_impl_steps_Normal_Abrupt)\nqed\n\nlemma \n   assumes (* exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" and\n           b: \"s \\<in> b\" and *)\n           step_a: \"\\<Gamma>\\<turnstile>\\<^sub>c(Await b c, Normal s) \\<rightarrow> u\"\n   shows step_await_final1:\"final u\"\nusing step_a \nproof cases\n  case  (1 t) thus \"final u\"  by (simp add: final_def)\nnext\n  case (2 t)\n  thus \"final u\" by (simp add: exec_impl_steps_Normal_Abrupt final_def)\nqed\n\nlemma step_Abrupt_end: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, s) \\<rightarrow> (c\\<^sub>1', s')\"\n  shows \"s'=Abrupt x \\<Longrightarrow> s=Abrupt x\"\nusing step\nby induct auto\n\n\nlemma step_Stuck_end: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, s) \\<rightarrow> (c\\<^sub>1', s')\"\n  shows \"s'=Stuck \\<Longrightarrow> \n          s=Stuck \\<or> \n          (\\<exists>r x. redex c\\<^sub>1 = Spec r \\<and> s=Normal x \\<and> (\\<forall>t. (x,t)\\<notin>r)) \\<or> \n          (\\<exists>p x. redex c\\<^sub>1=  Call p \\<and> s=Normal x \\<and> \\<Gamma> p = None) \\<or>\n          (\\<exists>b c x.  redex c\\<^sub>1 = Await b c \\<and> s=Normal x \\<and> x \\<in> b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle>\\<Rightarrow>s')\"\nusing step\nby induct auto\n\nlemma step_Fault_end: \n  assumes step: \"\\<Gamma>\\<turnstile>\\<^sub>c (c\\<^sub>1, s) \\<rightarrow> (c\\<^sub>1', s')\"\n  shows \"s'=Fault f \\<Longrightarrow> \n          s=Fault f \\<or> \n          (\\<exists>g c x.  redex c\\<^sub>1 = Guard f g c \\<and> s=Normal x \\<and> x \\<notin> g) \\<or>\n          (\\<exists>b c1 x.  redex c\\<^sub>1 = Await b c1 \\<and> s=Normal x \\<and> x \\<in> b \\<and> \\<Gamma>\\<turnstile>\\<langle>c1,s\\<rangle>\\<Rightarrow>s')\"\nusing step \nby induct auto\n\n\n\n(* ************************************************************************ *)\nsubsection {* Infinite Computations: @{text \"\\<Gamma>\\<turnstile>(c, s) \\<rightarrow> \\<dots>(\\<infinity>)\"}*}\n(* ************************************************************************ *)\n\ndefinition inf_c:: \"('s,'p,'f,'e) body \\<Rightarrow> ('s,'p,'f,'e) config \\<Rightarrow> bool\"\n (\"_\\<turnstile>\\<^sub>c _ \\<rightarrow> \\<dots>'(\\<infinity>')\" [60,80] 100) where\n\"\\<Gamma>\\<turnstile>\\<^sub>c cfg \\<rightarrow> \\<dots>(\\<infinity>) \\<equiv> (\\<exists>f. f (0::nat) = cfg \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>\\<^sub>cf i \\<rightarrow> f (i+1)))\" \n\nlemma not_infI: \"\\<lbrakk>\\<And>f. \\<lbrakk>f 0 = cfg; \\<And>i. \\<Gamma>\\<turnstile>\\<^sub>cf i \\<rightarrow> f (Suc i)\\<rbrakk> \\<Longrightarrow> False\\<rbrakk>  \n                \\<Longrightarrow> \\<not>\\<Gamma>\\<turnstile>\\<^sub>c cfg \\<rightarrow> \\<dots>(\\<infinity>)\"\n  by (auto simp add: inf_c_def)\n\n(* ************************************************************************ *)\nsubsection {* Equivalence between Termination and the Absence of Infinite Computations*}\n(* ************************************************************************ *)\n\n\nlemma step_preserves_termination: \n  assumes step: \"\\<Gamma>\\<turnstile>(c,s) \\<rightarrow> (c',s')\"\n  shows \"\\<Gamma>\\<turnstile>c\\<down>s \\<Longrightarrow> \\<Gamma>\\<turnstile>c'\\<down>s'\"  \nusing step\nproof (induct)\n  case Basic thus ?case by (fastforce intro: terminates.intros)\nnext\n  case Spec thus ?case by (fastforce intro: terminates.intros)\nnext\n  case SpecStuck thus ?case by (fastforce intro: terminates.intros)\nnext\n  case Guard thus ?case \n    by (fastforce intro: terminates.intros elim: terminates_Normal_elim_cases)\nnext\n  case GuardFault thus ?case by (fastforce intro: terminates.intros)\nnext\n  case (Seq c\\<^sub>1 s c\\<^sub>1' s' c\\<^sub>2) thus ?case\n    apply (cases s)\n    apply     (cases s')\n    apply         (fastforce intro: terminates.intros step_extend \n                    elim: terminates_Normal_elim_cases)\n    apply (fastforce intro: terminates.intros dest: step_Abrupt_prop \n      step_Fault_prop step_Stuck_prop)+\n    done\nnext\n  case (SeqSkip c\\<^sub>2 s) \n  thus ?case \n    apply (cases s)\n    apply (fastforce intro: terminates.intros exec.intros\n            elim: terminates_Normal_elim_cases )+\n    done\nnext\n  case (SeqThrow c\\<^sub>2 s) \n  thus ?case \n    by (fastforce intro: terminates.intros exec.intros\n            elim: terminates_Normal_elim_cases )\nnext\n  case CondTrue \n  thus ?case \n    by (fastforce intro: terminates.intros exec.intros\n            elim: terminates_Normal_elim_cases )\nnext\n  case CondFalse \n  thus ?case \n    by (fastforce intro: terminates.intros \n            elim: terminates_Normal_elim_cases )\nnext\n  case WhileTrue\n  thus ?case \n    by (fastforce intro: terminates.intros \n            elim: terminates_Normal_elim_cases )\nnext\n  case WhileFalse \n  thus ?case \n    by (fastforce intro: terminates.intros \n            elim: terminates_Normal_elim_cases )\nnext\n  case Call \n  thus ?case \n    by (fastforce intro: terminates.intros \n            elim: terminates_Normal_elim_cases )\nnext\n  case CallUndefined\n  thus ?case \n    by (fastforce intro: terminates.intros \n            elim: terminates_Normal_elim_cases )\nnext\n  case DynCom\n  thus ?case \n    by (fastforce intro: terminates.intros \n            elim: terminates_Normal_elim_cases )\nnext\n  case (Catch c\\<^sub>1 s c\\<^sub>1' s' c\\<^sub>2) thus ?case\n    apply (cases s)\n    apply     (cases s')\n    apply         (fastforce intro: terminates.intros step_extend \n                    elim: terminates_Normal_elim_cases)\n    apply (fastforce intro: terminates.intros dest: step_Abrupt_prop \n      step_Fault_prop step_Stuck_prop)+\n    done\nnext\n  case CatchThrow\n  thus ?case \n   by (fastforce intro: terminates.intros exec.intros\n            elim: terminates_Normal_elim_cases )\nnext\n  case (CatchSkip c\\<^sub>2 s) \n  thus ?case \n    by (cases s) (fastforce intro: terminates.intros)+\nnext\n  case FaultProp thus ?case by (fastforce intro: terminates.intros)\nnext\n  case StuckProp thus ?case by (fastforce intro: terminates.intros)\nnext\n  case AbruptProp thus ?case by (fastforce intro: terminates.intros)\nnext \n  case Await thus ?case using terminates_Skip' by blast \nnext \n  case AwaitAbrupt thus ?case by (fastforce intro: terminates.intros)\nqed\n\nlemma steps_preserves_termination: \n  assumes steps: \"\\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>* (c',s')\"\n  shows \"\\<Gamma>\\<turnstile>c\\<down>s \\<Longrightarrow> \\<Gamma>\\<turnstile>c'\\<down>s'\"\nusing steps\nproof (induct rule: rtranclp_induct2 [consumes 1, case_names Refl Trans])\n  case Refl thus ?case  .\nnext\n  case Trans\n  thus ?case\n    by (blast dest: step_preserves_termination)\nqed\n\nML {*\n  ML_Thms.bind_thm (\"tranclp_induct2\", Split_Rule.split_rule @{context}\n    (Rule_Insts.read_instantiate @{context}\n      [(((\"a\", 0), Position.none), \"(aa,ab)\"), (((\"b\", 0), Position.none), \"(ba,bb)\")] []\n      @{thm tranclp_induct}));\n*}\n\nthm tranclp_induct2 tranclp_induct\n\nlemma steps_preserves_termination': \n  assumes steps: \"\\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>+ (c',s')\"\n  shows \"\\<Gamma>\\<turnstile>c\\<down>s \\<Longrightarrow> \\<Gamma>\\<turnstile>c'\\<down>s'\"\nusing steps\nproof (induct rule: tranclp_induct2 [consumes 1, case_names Step Trans])\n  case Step thus ?case by (blast intro: step_preserves_termination)\nnext\n  case Trans\n  thus ?case\n    by (blast dest: step_preserves_termination)\nqed\n\n\n\ndefinition head_com:: \"('s,'p,'f,'e) com \\<Rightarrow> ('s,'p,'f,'e) com\"\nwhere\n\"head_com c =\n  (case c of\n     Seq c\\<^sub>1 c\\<^sub>2 \\<Rightarrow> c\\<^sub>1\n   | Catch c\\<^sub>1 c\\<^sub>2 \\<Rightarrow> c\\<^sub>1\n   | _ \\<Rightarrow> c)\"\n\n  \ndefinition head:: \"('s,'p,'f,'e) config \\<Rightarrow> ('s,'p,'f,'e) config\"\n  where \"head cfg = (head_com (fst cfg), snd cfg)\"\n\nlemma le_Suc_cases: \"\\<lbrakk>\\<And>i. \\<lbrakk>i < k\\<rbrakk> \\<Longrightarrow> P i; P k\\<rbrakk> \\<Longrightarrow> \\<forall>i<(Suc k). P i\"\n  apply clarify\n  apply (case_tac \"i=k\")\n  apply auto\n  done\n\nlemma redex_Seq_False: \"\\<And>c' c''. (redex c = Seq c'' c') = False\"\n  by (induct c) auto\n\nlemma redex_Catch_False: \"\\<And>c' c''. (redex c = Catch c'' c') = False\"\n  by (induct c) auto\n\n\nlemma infinite_computation_extract_head_Seq:\n  assumes inf_comp: \"\\<forall>i::nat. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (i+1)\"\n  assumes f_0: \"f 0 = (Seq c\\<^sub>1 c\\<^sub>2,s)\"\n  assumes not_fin: \"\\<forall>i<k. \\<not> final (head (f i))\"\n  shows \"\\<forall>i<k. (\\<exists>c' s'. f (i + 1) = (Seq c' c\\<^sub>2, s')) \\<and>  \n               \\<Gamma>\\<turnstile>head (f i) \\<rightarrow> head (f (i+1))\"\n        (is \"\\<forall>i<k. ?P i\")\nusing not_fin\nproof (induct k)\n  case 0\n  show ?case by simp\nnext\n  case (Suc k)\n  have not_fin_Suc: \n    \"\\<forall>i<Suc k. \\<not> final (head (f i))\" by fact\n  from this[rule_format] have not_fin_k: \n    \"\\<forall>i<k. \\<not> final (head (f i))\" \n    apply clarify\n    apply (subgoal_tac \"i < Suc k\")\n    apply blast\n    apply simp\n    done\n\n  from Suc.hyps [OF this]\n  have hyp: \"\\<forall>i<k. (\\<exists>c' s'. f (i + 1) = (Seq c' c\\<^sub>2, s')) \\<and> \n                   \\<Gamma>\\<turnstile> head (f i) \\<rightarrow> head (f (i + 1))\".\n  show ?case\n  proof (rule le_Suc_cases)\n    fix i \n    assume \"i < k\"\n    then show \"?P i\"\n      by (rule hyp [rule_format])\n  next\n    show \"?P k\"\n    proof -\n      from hyp [rule_format, of \"k - 1\"] f_0\n      obtain c' fs' L' s' where  f_k: \"f k = (Seq c' c\\<^sub>2, s')\"\n        by (cases k) auto\n      from inf_comp [rule_format, of k] f_k\n      have \"\\<Gamma>\\<turnstile>(Seq c' c\\<^sub>2, s') \\<rightarrow> f (k + 1)\"\n        by simp\n      moreover\n      from not_fin_Suc [rule_format, of k] f_k\n      have \"\\<not> final (c',s')\"\n        by (simp add: final_def head_def head_com_def)\n      ultimately\n      obtain c'' s'' where\n         \"\\<Gamma>\\<turnstile>(c', s') \\<rightarrow> (c'', s'')\" and\n         \"f (k + 1) = (Seq c'' c\\<^sub>2, s'')\"\n        by cases (auto simp add: redex_Seq_False final_def)\n      with f_k\n      show ?thesis\n        by (simp add: head_def head_com_def)\n    qed\n  qed\nqed\n\nlemma infinite_computation_extract_head_Catch:\n  assumes inf_comp: \"\\<forall>i::nat. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (i+1)\"\n  assumes f_0: \"f 0 = (Catch c\\<^sub>1 c\\<^sub>2,s)\"\n  assumes not_fin: \"\\<forall>i<k. \\<not> final (head (f i))\"\n  shows \"\\<forall>i<k. (\\<exists>c' s'. f (i + 1) = (Catch c' c\\<^sub>2, s')) \\<and>  \n               \\<Gamma>\\<turnstile>head (f i) \\<rightarrow> head (f (i+1))\"\n        (is \"\\<forall>i<k. ?P i\")\nusing not_fin\nproof (induct k)\n  case 0\n  show ?case by simp\nnext\n  case (Suc k)\n  have not_fin_Suc: \n    \"\\<forall>i<Suc k. \\<not> final (head (f i))\" by fact\n  from this[rule_format] have not_fin_k: \n    \"\\<forall>i<k. \\<not> final (head (f i))\" \n    apply clarify\n    apply (subgoal_tac \"i < Suc k\")\n    apply blast\n    apply simp\n    done\n\n  from Suc.hyps [OF this]\n  have hyp: \"\\<forall>i<k. (\\<exists>c' s'. f (i + 1) = (Catch c' c\\<^sub>2, s')) \\<and> \n                   \\<Gamma>\\<turnstile> head (f i) \\<rightarrow> head (f (i + 1))\".\n  show ?case\n  proof (rule le_Suc_cases)\n    fix i \n    assume \"i < k\"\n    then show \"?P i\"\n      by (rule hyp [rule_format])\n  next\n    show \"?P k\"\n    proof -\n      from hyp [rule_format, of \"k - 1\"] f_0\n      obtain c' fs' L' s' where  f_k: \"f k = (Catch c' c\\<^sub>2, s')\"\n        by (cases k) auto\n      from inf_comp [rule_format, of k] f_k\n      have \"\\<Gamma>\\<turnstile>(Catch c' c\\<^sub>2, s') \\<rightarrow> f (k + 1)\"\n        by simp\n      moreover\n      from not_fin_Suc [rule_format, of k] f_k\n      have \"\\<not> final (c',s')\"\n        by (simp add: final_def head_def head_com_def)\n      ultimately\n      obtain c'' s'' where\n         \"\\<Gamma>\\<turnstile>(c', s') \\<rightarrow> (c'', s'')\" and\n         \"f (k + 1) = (Catch c'' c\\<^sub>2, s'')\"\n        by cases (auto simp add: redex_Catch_False final_def)+\n      with f_k\n      show ?thesis\n        by (simp add: head_def head_com_def)\n    qed\n  qed\nqed\n\nlemma no_inf_Throw: \"\\<not> \\<Gamma>\\<turnstile>(Throw,s) \\<rightarrow> \\<dots>(\\<infinity>)\"\nproof \n  assume \"\\<Gamma>\\<turnstile> (Throw, s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n  then obtain f where\n    step [rule_format]: \"\\<forall>i::nat. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (i+1)\" and\n    f_0: \"f 0 = (Throw, s)\"\n    by (auto simp add: inf_def)\n  from step [of 0, simplified f_0] step [of 1]\n  show False\n    by cases (auto elim: step_elim_cases)\nqed\n\nlemma split_inf_Seq: \n  assumes inf_comp: \"\\<Gamma>\\<turnstile>(Seq c\\<^sub>1 c\\<^sub>2,s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n  shows \"\\<Gamma>\\<turnstile>(c\\<^sub>1,s) \\<rightarrow> \\<dots>(\\<infinity>) \\<or> \n         (\\<exists>s'. \\<Gamma>\\<turnstile>(c\\<^sub>1,s) \\<rightarrow>\\<^sup>* (Skip,s') \\<and> \\<Gamma>\\<turnstile>(c\\<^sub>2,s') \\<rightarrow> \\<dots>(\\<infinity>))\"\nproof -\n  from inf_comp obtain f where\n    step: \"\\<forall>i::nat. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (i+1)\" and\n    f_0: \"f 0 = (Seq c\\<^sub>1 c\\<^sub>2, s)\"\n    by (auto simp add: inf_def)\n  from f_0 have head_f_0: \"head (f 0) = (c\\<^sub>1,s)\" \n    by (simp add: head_def head_com_def)\n  show ?thesis\n  proof (cases \"\\<exists>i. final (head (f i))\")\n    case True\n    def k\\<equiv>\"(LEAST i. final (head (f i)))\"\n    have less_k: \"\\<forall>i<k. \\<not> final (head (f i))\"\n      apply (intro allI impI)\n      apply (unfold k_def)\n      apply (drule not_less_Least)\n      apply auto\n      done\n    from infinite_computation_extract_head_Seq [OF step f_0 this]\n    obtain step_head: \"\\<forall>i<k. \\<Gamma>\\<turnstile> head (f i) \\<rightarrow> head (f (i + 1))\" and\n           conf: \"\\<forall>i<k. (\\<exists>c' s'. f (i + 1) = (Seq c' c\\<^sub>2, s'))\"\n      by blast \n    from True\n    have final_f_k: \"final (head (f k))\"\n      apply -\n      apply (erule exE)\n      apply (drule LeastI)\n      apply (simp add: k_def)\n      done\n    moreover\n    from f_0 conf [rule_format, of \"k - 1\"]\n    obtain c' s' where f_k: \"f k = (Seq c' c\\<^sub>2,s')\"\n      by (cases k) auto\n    moreover\n    from step_head have steps_head: \"\\<Gamma>\\<turnstile>head (f 0) \\<rightarrow>\\<^sup>* head (f k)\"\n    proof (induct k)\n      case 0 thus ?case by simp\n    next\n      case (Suc m)\n      have step: \"\\<forall>i<Suc m. \\<Gamma>\\<turnstile> head (f i) \\<rightarrow> head (f (i + 1))\" by fact\n      hence \"\\<forall>i<m. \\<Gamma>\\<turnstile> head (f i) \\<rightarrow> head (f (i + 1))\"\n        by auto\n      hence \"\\<Gamma>\\<turnstile> head (f 0) \\<rightarrow>\\<^sup>*  head (f m)\"\n        by (rule Suc.hyps)\n      also from step [rule_format, of m]\n      have \"\\<Gamma>\\<turnstile> head (f m) \\<rightarrow> head (f (m + 1))\" by simp\n      finally show ?case by simp\n    qed\n    {\n      assume f_k: \"f k = (Seq Skip c\\<^sub>2, s')\"\n      with steps_head\n      have \"\\<Gamma>\\<turnstile>(c\\<^sub>1,s) \\<rightarrow>\\<^sup>* (Skip,s')\"\n        using head_f_0\n        by (simp add: head_def head_com_def)\n      moreover\n      from step [rule_format, of k] f_k\n      obtain \"\\<Gamma>\\<turnstile>(Seq Skip c\\<^sub>2,s') \\<rightarrow> (c\\<^sub>2,s')\" and\n        f_Suc_k: \"f (k + 1) = (c\\<^sub>2,s')\"\n        by (fastforce elim: step.cases intro: step.intros)\n      def g\\<equiv>\"\\<lambda>i. f (i + (k + 1))\"\n      from f_Suc_k\n      have g_0: \"g 0 = (c\\<^sub>2,s')\"\n        by (simp add: g_def)\n      from step\n      have \"\\<forall>i. \\<Gamma>\\<turnstile>g i \\<rightarrow> g (i + 1)\"\n        by (simp add: g_def)\n      with g_0 have \"\\<Gamma>\\<turnstile>(c\\<^sub>2,s') \\<rightarrow> \\<dots>(\\<infinity>)\"\n        by (auto simp add: inf_def)\n      ultimately\n      have ?thesis\n        by auto\n    }\n    moreover\n    {\n      fix x\n      assume s': \"s'=Normal x\" and f_k: \"f k = (Seq Throw c\\<^sub>2, s')\"\n      from step [rule_format, of k] f_k s'\n      obtain \"\\<Gamma>\\<turnstile>(Seq Throw c\\<^sub>2,s') \\<rightarrow> (Throw,s')\" and\n        f_Suc_k: \"f (k + 1) = (Throw,s')\"\n        by (fastforce elim: step_elim_cases intro: step.intros)\n      def g\\<equiv>\"\\<lambda>i. f (i + (k + 1))\"\n      from f_Suc_k\n      have g_0: \"g 0 = (Throw,s')\"\n        by (simp add: g_def)\n      from step\n      have \"\\<forall>i. \\<Gamma>\\<turnstile>g i \\<rightarrow> g (i + 1)\"\n        by (simp add: g_def)\n      with g_0 have \"\\<Gamma>\\<turnstile>(Throw,s') \\<rightarrow> \\<dots>(\\<infinity>)\"\n        by (auto simp add: inf_def)\n      with no_inf_Throw\n      have ?thesis\n        by auto\n    }\n    ultimately \n    show ?thesis\n      by (auto simp add: final_def head_def head_com_def)\n  next\n    case False\n    then have not_fin: \"\\<forall>i. \\<not> final (head (f i))\"\n      by blast\n    have \"\\<forall>i. \\<Gamma>\\<turnstile>head (f i) \\<rightarrow> head (f (i + 1))\"\n    proof \n      fix k\n      from not_fin \n      have \"\\<forall>i<(Suc k). \\<not> final (head (f i))\"\n        by simp\n      \n      from infinite_computation_extract_head_Seq [OF step f_0 this ]\n      show \"\\<Gamma>\\<turnstile> head (f k) \\<rightarrow> head (f (k + 1))\" by simp\n    qed\n    with head_f_0 have \"\\<Gamma>\\<turnstile>(c\\<^sub>1,s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n      by (auto simp add: inf_def)\n    thus ?thesis\n      by simp\n  qed\nqed\n\nlemma split_inf_Catch: \n  assumes inf_comp: \"\\<Gamma>\\<turnstile>(Catch c\\<^sub>1 c\\<^sub>2,s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n  shows \"\\<Gamma>\\<turnstile>(c\\<^sub>1,s) \\<rightarrow> \\<dots>(\\<infinity>) \\<or> \n         (\\<exists>s'. \\<Gamma>\\<turnstile>(c\\<^sub>1,s) \\<rightarrow>\\<^sup>* (Throw,Normal s') \\<and> \\<Gamma>\\<turnstile>(c\\<^sub>2,Normal s') \\<rightarrow> \\<dots>(\\<infinity>))\"\nproof -\n  from inf_comp obtain f where\n    step: \"\\<forall>i::nat. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (i+1)\" and\n    f_0: \"f 0 = (Catch c\\<^sub>1 c\\<^sub>2, s)\"\n    by (auto simp add: inf_def)\n  from f_0 have head_f_0: \"head (f 0) = (c\\<^sub>1,s)\" \n    by (simp add: head_def head_com_def)\n  show ?thesis\n  proof (cases \"\\<exists>i. final (head (f i))\")\n    case True\n    def k\\<equiv>\"(LEAST i. final (head (f i)))\"\n    have less_k: \"\\<forall>i<k. \\<not> final (head (f i))\"\n      apply (intro allI impI)\n      apply (unfold k_def)\n      apply (drule not_less_Least)\n      apply auto\n      done\n    from infinite_computation_extract_head_Catch [OF step f_0 this]\n    obtain step_head: \"\\<forall>i<k. \\<Gamma>\\<turnstile> head (f i) \\<rightarrow> head (f (i + 1))\" and\n           conf: \"\\<forall>i<k. (\\<exists>c' s'. f (i + 1) = (Catch c' c\\<^sub>2, s'))\"\n      by blast \n    from True\n    have final_f_k: \"final (head (f k))\"\n      apply -\n      apply (erule exE)\n      apply (drule LeastI)\n      apply (simp add: k_def)\n      done\n    moreover\n    from f_0 conf [rule_format, of \"k - 1\"]\n    obtain c' s' where f_k: \"f k = (Catch c' c\\<^sub>2,s')\"\n      by (cases k) auto\n    moreover\n    from step_head have steps_head: \"\\<Gamma>\\<turnstile>head (f 0) \\<rightarrow>\\<^sup>* head (f k)\"\n    proof (induct k)\n      case 0 thus ?case by simp\n    next\n      case (Suc m)\n      have step: \"\\<forall>i<Suc m. \\<Gamma>\\<turnstile> head (f i) \\<rightarrow> head (f (i + 1))\" by fact\n      hence \"\\<forall>i<m. \\<Gamma>\\<turnstile> head (f i) \\<rightarrow> head (f (i + 1))\"\n        by auto\n      hence \"\\<Gamma>\\<turnstile> head (f 0) \\<rightarrow>\\<^sup>*  head (f m)\"\n        by (rule Suc.hyps)\n      also from step [rule_format, of m]\n      have \"\\<Gamma>\\<turnstile> head (f m) \\<rightarrow> head (f (m + 1))\" by simp\n      finally show ?case by simp\n    qed\n    {\n      assume f_k: \"f k = (Catch Skip c\\<^sub>2, s')\"\n      with steps_head\n      have \"\\<Gamma>\\<turnstile>(c\\<^sub>1,s) \\<rightarrow>\\<^sup>* (Skip,s')\"\n        using head_f_0\n        by (simp add: head_def head_com_def)\n      moreover\n      from step [rule_format, of k] f_k\n      obtain \"\\<Gamma>\\<turnstile>(Catch Skip c\\<^sub>2,s') \\<rightarrow> (Skip,s')\" and\n        f_Suc_k: \"f (k + 1) = (Skip,s')\"\n        by (fastforce elim: step.cases intro: step.intros)\n      from step [rule_format, of \"k+1\", simplified f_Suc_k]\n      have ?thesis\n        by (rule no_step_final') (auto simp add: final_def)\n    }\n    moreover\n    {\n      fix x\n      assume s': \"s'=Normal x\" and f_k: \"f k = (Catch Throw c\\<^sub>2, s')\"\n      with steps_head\n      have \"\\<Gamma>\\<turnstile>(c\\<^sub>1,s) \\<rightarrow>\\<^sup>* (Throw,s')\"\n        using head_f_0\n        by (simp add: head_def head_com_def)\n      moreover\n      from step [rule_format, of k] f_k s'\n      obtain \"\\<Gamma>\\<turnstile>(Catch Throw c\\<^sub>2,s') \\<rightarrow> (c\\<^sub>2,s')\" and\n        f_Suc_k: \"f (k + 1) = (c\\<^sub>2,s')\"\n        by (fastforce elim: step_elim_cases intro: step.intros)\n      def g\\<equiv>\"\\<lambda>i. f (i + (k + 1))\"\n      from f_Suc_k\n      have g_0: \"g 0 = (c\\<^sub>2,s')\"\n        by (simp add: g_def)\n      from step\n      have \"\\<forall>i. \\<Gamma>\\<turnstile>g i \\<rightarrow> g (i + 1)\"\n        by (simp add: g_def)\n      with g_0 have \"\\<Gamma>\\<turnstile>(c\\<^sub>2,s') \\<rightarrow> \\<dots>(\\<infinity>)\"\n        by (auto simp add: inf_def)\n      ultimately\n      have ?thesis\n        using s'\n        by auto\n    }\n    ultimately \n    show ?thesis\n      by (auto simp add: final_def head_def head_com_def)\n  next\n    case False\n    then have not_fin: \"\\<forall>i. \\<not> final (head (f i))\"\n      by blast\n    have \"\\<forall>i. \\<Gamma>\\<turnstile>head (f i) \\<rightarrow> head (f (i + 1))\"\n    proof \n      fix k\n      from not_fin \n      have \"\\<forall>i<(Suc k). \\<not> final (head (f i))\"\n        by simp\n      \n      from infinite_computation_extract_head_Catch [OF step f_0 this ]\n      show \"\\<Gamma>\\<turnstile> head (f k) \\<rightarrow> head (f (k + 1))\" by simp\n    qed\n    with head_f_0 have \"\\<Gamma>\\<turnstile>(c\\<^sub>1,s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n      by (auto simp add: inf_def)\n    thus ?thesis\n      by simp\n  qed\nqed\n\nlemma Skip_no_step: \"\\<Gamma>\\<turnstile>(Skip,s) \\<rightarrow> cfg \\<Longrightarrow> P\"\n  apply (erule no_step_final')\n  apply (simp add: final_def)\n  done\n\nlemma not_inf_Stuck: \"\\<not> \\<Gamma>\\<turnstile>(c,Stuck) \\<rightarrow> \\<dots>(\\<infinity>)\"\nproof (induct c)\n  case Skip\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Skip, Stuck)\" \n    from f_step [of 0] f_0\n    show False\n      by (auto elim: Skip_no_step)\n  qed\nnext\n  case (Basic g) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Basic g, Stuck)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Spec r) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Spec r, Stuck)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Seq c\\<^sub>1 c\\<^sub>2)\n  show ?case\n  proof \n    assume \"\\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, Stuck) \\<rightarrow> \\<dots>(\\<infinity>)\"\n    from split_inf_Seq [OF this] Seq.hyps\n    show False\n      by (auto dest: steps_Stuck_prop)\n  qed\nnext\n  case (Cond b c\\<^sub>1 c\\<^sub>2) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Cond b c\\<^sub>1 c\\<^sub>2, Stuck)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (While b c) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (While b c, Stuck)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Call p) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Call p, Stuck)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (DynCom d) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (DynCom d, Stuck)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Guard m g c)\n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Guard m g c, Stuck)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case Throw\n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Throw, Stuck)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  show ?case\n  proof \n    assume \"\\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, Stuck) \\<rightarrow> \\<dots>(\\<infinity>)\"\n    from split_inf_Catch [OF this] Catch.hyps\n    show False\n      by (auto dest: steps_Stuck_prop)\n  qed  \nnext \n  case (Await b c)\n  show ?case \n   proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Await b c, Stuck)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nqed\n\nlemma not_inf_Fault: \"\\<not> \\<Gamma>\\<turnstile>(c,Fault x) \\<rightarrow> \\<dots>(\\<infinity>)\"\nproof (induct c)\n  case Skip\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Skip, Fault x)\" \n    from f_step [of 0] f_0\n    show False\n      by (auto elim: Skip_no_step)\n  qed\nnext\n  case (Basic g) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Basic g, Fault x)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Spec r) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Spec r, Fault x)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Seq c\\<^sub>1 c\\<^sub>2)\n  show ?case\n  proof \n    assume \"\\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, Fault x) \\<rightarrow> \\<dots>(\\<infinity>)\"\n    from split_inf_Seq [OF this] Seq.hyps\n    show False\n      by (auto dest: steps_Fault_prop)\n  qed\nnext\n  case (Cond b c\\<^sub>1 c\\<^sub>2) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Cond b c\\<^sub>1 c\\<^sub>2, Fault x)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (While b c) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (While b c, Fault x)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Call p) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Call p, Fault x)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (DynCom d) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (DynCom d, Fault x)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Guard m g c)\n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Guard m g c, Fault x)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case Throw\n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Throw, Fault x)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  show ?case\n  proof \n    assume \"\\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, Fault x) \\<rightarrow> \\<dots>(\\<infinity>)\"\n    from split_inf_Catch [OF this] Catch.hyps\n    show False\n      by (auto dest: steps_Fault_prop)\n  qed  \nnext\n  case (Await b c) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Await b c, Fault x)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nqed\n\nlemma not_inf_Abrupt: \"\\<not> \\<Gamma>\\<turnstile>(c,Abrupt s) \\<rightarrow> \\<dots>(\\<infinity>)\"\nproof (induct c)\n  case Skip\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Skip, Abrupt s)\" \n    from f_step [of 0] f_0\n    show False\n      by (auto elim: Skip_no_step)\n  qed\nnext\n  case (Basic g) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Basic g, Abrupt s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Spec r) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Spec r, Abrupt s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Seq c\\<^sub>1 c\\<^sub>2)\n  show ?case\n  proof \n    assume \"\\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, Abrupt s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n    from split_inf_Seq [OF this] Seq.hyps\n    show False\n      by (auto dest: steps_Abrupt_prop)\n  qed\nnext\n  case (Cond b c\\<^sub>1 c\\<^sub>2) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Cond b c\\<^sub>1 c\\<^sub>2, Abrupt s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (While b c) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (While b c, Abrupt s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Call p) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Call p, Abrupt s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (DynCom d) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (DynCom d, Abrupt s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Guard m g c)\n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Guard m g c, Abrupt s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case Throw\n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Throw, Abrupt s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  show ?case\n  proof \n    assume \"\\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, Abrupt s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n    from split_inf_Catch [OF this] Catch.hyps\n    show False\n      by (auto dest: steps_Abrupt_prop)\n  qed  \ncase (Await b c) \n  show ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Await b c, Abrupt s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nqed\n\n\ntheorem terminates_impl_no_infinite_computation:\n  assumes termi: \"\\<Gamma>\\<turnstile>c \\<down> s\"\n  shows \"\\<not> \\<Gamma>\\<turnstile>(c,s) \\<rightarrow> \\<dots>(\\<infinity>)\"\nusing termi\nproof (induct)\n  case (Skip s) thus ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Skip, Normal s)\" \n    from f_step [of 0] f_0\n    show False\n      by (auto elim: Skip_no_step)\n  qed\nnext\n  case (Basic g s) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Basic g, Normal s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Spec r s) \n  thus ?case \n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Spec r, Normal s)\" \n    from f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Guard s g c m)\n  have g: \"s \\<in> g\" by fact\n  have hyp: \"\\<not> \\<Gamma>\\<turnstile> (c, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Guard m g c, Normal s)\" \n    from f_step [of 0] f_0  g\n    have \"f 1 = (c,Normal s)\"\n      by (fastforce elim: step_elim_cases)\n    with f_step\n    have \"\\<Gamma>\\<turnstile> (c, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with hyp show False ..\n  qed\nnext\n  case (GuardFault s g m c)\n  have g: \"s \\<notin> g\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Guard m g c, Normal s)\" \n    from g f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Fault c m) \n  thus ?case\n    by (rule not_inf_Fault)\nnext\n  case (Seq c\\<^sub>1 s c\\<^sub>2)\n  show ?case\n  proof \n    assume \"\\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n    from split_inf_Seq [OF this] Seq.hyps\n    show False\n      by (auto intro: steps_Skip_impl_exec)\n  qed\nnext\n  case (CondTrue s b c1 c2)\n  have b: \"s \\<in> b\" by fact\n  have hyp_c1: \"\\<not> \\<Gamma>\\<turnstile> (c1, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Cond b c1 c2, Normal s)\" \n    from b f_step [of 0] f_0\n    have \"f 1 = (c1,Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step\n    have \"\\<Gamma>\\<turnstile> (c1, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with hyp_c1 show False by simp\n  qed    \nnext\n  case (CondFalse s b c2 c1)\n  have b: \"s \\<notin> b\" by fact\n  have hyp_c2: \"\\<not> \\<Gamma>\\<turnstile> (c2, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Cond b c1 c2, Normal s)\" \n    from b f_step [of 0] f_0\n    have \"f 1 = (c2,Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step\n    have \"\\<Gamma>\\<turnstile> (c2, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with hyp_c2 show False by simp\n  qed\nnext    \n  case (WhileTrue s b c)\n  have b: \"s \\<in> b\" by fact\n  have hyp_c: \"\\<not> \\<Gamma>\\<turnstile> (c, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\" by fact\n  have hyp_w: \"\\<forall>s'. \\<Gamma>\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> s' \\<longrightarrow> \n                     \\<Gamma>\\<turnstile>While b c \\<down> s' \\<and> \\<not> \\<Gamma>\\<turnstile> (While b c, s') \\<rightarrow> \\<dots>(\\<infinity>)\" by fact\n  have not_inf_Seq: \"\\<not> \\<Gamma>\\<turnstile> (Seq c (While b c), Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n  proof \n    assume \"\\<Gamma>\\<turnstile> (Seq c (While b c), Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n    from split_inf_Seq [OF this] hyp_c hyp_w show False\n      by (auto intro: steps_Skip_impl_exec)\n  qed\n  show ?case\n  proof \n    assume \"\\<Gamma>\\<turnstile> (While b c, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n    then obtain f where\n      f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\" and\n      f_0: \"f 0 = (While b c, Normal s)\" \n      by (auto simp add: inf_def)\n    from f_step [of 0] f_0 b\n    have \"f 1 = (Seq c (While b c),Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step\n    have \"\\<Gamma>\\<turnstile> (Seq c (While b c), Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with not_inf_Seq show False by simp\n  qed\nnext\n  case (WhileFalse s b c)\n  have b: \"s \\<notin> b\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (While b c, Normal s)\" \n    from b f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Call p bdy s)\n  have bdy: \"\\<Gamma> p = Some bdy\" by fact\n  have hyp: \"\\<not> \\<Gamma>\\<turnstile> (bdy, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Call p, Normal s)\" \n    from bdy f_step [of 0] f_0\n    have \"f 1 = (bdy,Normal s)\"\n      by (auto elim: step_Normal_elim_cases)\n    with f_step\n    have \"\\<Gamma>\\<turnstile> (bdy, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with hyp show False by simp\n  qed    \nnext\n  case (CallUndefined p s)\n  have no_bdy: \"\\<Gamma> p = None\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Call p, Normal s)\" \n    from no_bdy f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nnext\n  case (Stuck c)\n  show ?case\n    by (rule not_inf_Stuck)\nnext\n  case (DynCom c s)\n  have hyp: \"\\<not> \\<Gamma>\\<turnstile> (c s, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (DynCom c, Normal s)\" \n    from f_step [of 0] f_0\n    have \"f (Suc 0) = (c s, Normal s)\"\n      by (auto elim: step_elim_cases)\n    with f_step have \"\\<Gamma>\\<turnstile> (c s, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n      apply (simp add: inf_def)\n      apply (rule_tac x=\"\\<lambda>i. f (Suc i)\" in exI)\n      by simp\n    with hyp\n    show False by simp\n  qed\nnext (\\<Gamma>,c) \\<propto> clist\n  case (Throw s) thus ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Throw, Normal s)\" \n    from f_step [of 0] f_0\n    show False\n      by (auto elim: step_elim_cases)\n  qed  \nnext\n  case (Abrupt c)\n  show ?case\n    by (rule not_inf_Abrupt)\nnext\n  case (Catch c\\<^sub>1 s c\\<^sub>2)\n  show ?case\n  proof \n    assume \"\\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n    from split_inf_Catch [OF this] Catch.hyps\n    show False\n      by (auto intro: steps_Throw_impl_exec)\n  qed\nnext\n  case (AwaitTrue s b c)\n  have b: \"s \\<in> b\" by fact\n  show ?case\n  proof (rule not_infI)\n    fix f\n    assume f_step: \"\\<And>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n    assume f_0: \"f 0 = (Await b c, Normal s)\" \n    from b f_step [of 0] f_0 f_step [of 1]\n    show False\n      by (fastforce elim: Skip_no_step step_elim_cases)\n  qed\nqed\n\n\ndefinition\n termi_call_steps :: \"('s,'p,'f,'e) body \\<Rightarrow> (('s \\<times> 'p) \\<times> ('s \\<times> 'p))set\"\nwhere\n\"termi_call_steps \\<Gamma> =\n {((t,q),(s,p)). \\<Gamma>\\<turnstile>Call p\\<down>Normal s \\<and> \n       (\\<exists>c. \\<Gamma>\\<turnstile>(Call p,Normal s) \\<rightarrow>\\<^sup>+ (c,Normal t) \\<and> redex c = Call q)}\"\n\n\nprimrec subst_redex:: \"('s,'p,'f,'e)com \\<Rightarrow> ('s,'p,'f,'e)com \\<Rightarrow> ('s,'p,'f,'e)com\"\nwhere\n\"subst_redex Skip c = c\" |\n\"subst_redex (Basic f) c = c\" |\n\"subst_redex (Spec r) c = c\" |\n\"subst_redex (Seq c\\<^sub>1 c\\<^sub>2) c  = Seq (subst_redex c\\<^sub>1 c) c\\<^sub>2\" |\n\"subst_redex (Cond b c\\<^sub>1 c\\<^sub>2) c = c\" |\n\"subst_redex (While b c') c = c\" |\n\"subst_redex (Await b c') c = c\" |\n\"subst_redex (Call p) c = c\" |\n\"subst_redex (DynCom d) c = c\" |\n\"subst_redex (Guard f b c') c = c\" |\n\"subst_redex (Throw) c = c\" |\n\"subst_redex (Catch c\\<^sub>1 c\\<^sub>2) c = Catch (subst_redex c\\<^sub>1 c) c\\<^sub>2\"\n\nlemma subst_redex_redex:\n  \"subst_redex c (redex c) = c\"\n  by (induct c) auto\n\nlemma redex_subst_redex: \"redex (subst_redex c r) = redex r\"\n  by (induct c) auto\n  \nlemma step_redex':\n  shows \"\\<Gamma>\\<turnstile>(redex c,s) \\<rightarrow> (r',s') \\<Longrightarrow> \\<Gamma>\\<turnstile>(c,s) \\<rightarrow> (subst_redex c r',s')\"\nby (induct c) (auto intro: step.Seq step.Catch)\n\n\nlemma step_redex:\n  shows \"\\<Gamma>\\<turnstile>(r,s) \\<rightarrow> (r',s') \\<Longrightarrow> \\<Gamma>\\<turnstile>(subst_redex c r,s) \\<rightarrow> (subst_redex c r',s')\"\nby (induct c) (auto intro: step.Seq step.Catch)\n\nlemma steps_redex:\n  assumes steps: \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow>\\<^sup>* (r', s')\"\n  shows \"\\<And>c. \\<Gamma>\\<turnstile>(subst_redex c r,s) \\<rightarrow>\\<^sup>* (subst_redex c r',s')\"\nusing steps\nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl \n  show \"\\<Gamma>\\<turnstile> (subst_redex c r', s') \\<rightarrow>\\<^sup>* (subst_redex c r', s')\"\n    by simp\nnext\n  case (Trans r s r'' s'')\n  have \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow> (r'', s'')\" by fact\n  from step_redex [OF this]\n  have \"\\<Gamma>\\<turnstile> (subst_redex c r, s) \\<rightarrow> (subst_redex c r'', s'')\".\n  also  \n  have \"\\<Gamma>\\<turnstile> (subst_redex c r'', s'') \\<rightarrow>\\<^sup>* (subst_redex c r', s')\" by fact\n  finally show ?case .\nqed\n\nML {*\n  ML_Thms.bind_thm (\"trancl_induct2\", Split_Rule.split_rule @{context}\n    (Rule_Insts.read_instantiate @{context}\n      [(((\"a\", 0), Position.none), \"(aa, ab)\"), (((\"b\", 0), Position.none), \"(ba, bb)\")] []\n      @{thm trancl_induct}));\n*}\n\nlemma steps_redex':\n  assumes steps: \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow>\\<^sup>+ (r', s')\"\n  shows \"\\<And>c. \\<Gamma>\\<turnstile>(subst_redex c r,s) \\<rightarrow>\\<^sup>+ (subst_redex c r',s')\"\nusing steps\nproof (induct rule: tranclp_induct2 [consumes 1,case_names Step Trans])\n  case (Step r' s')\n  have \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow> (r', s')\" by fact\n  then have \"\\<Gamma>\\<turnstile> (subst_redex c r, s) \\<rightarrow> (subst_redex c r', s')\"\n    by (rule step_redex)\n  then show \"\\<Gamma>\\<turnstile> (subst_redex c r, s) \\<rightarrow>\\<^sup>+ (subst_redex c r', s')\"..\nnext\n  case (Trans r' s' r'' s'')\n  have \"\\<Gamma>\\<turnstile> (subst_redex c r, s) \\<rightarrow>\\<^sup>+ (subst_redex c r', s')\" by fact\n  also\n  have \"\\<Gamma>\\<turnstile> (r', s') \\<rightarrow> (r'', s'')\" by fact\n  hence \"\\<Gamma>\\<turnstile> (subst_redex c r', s') \\<rightarrow> (subst_redex c r'', s'')\"\n    by (rule step_redex)\n  finally show \"\\<Gamma>\\<turnstile> (subst_redex c r, s) \\<rightarrow>\\<^sup>+ (subst_redex c r'', s'')\" .\nqed\n\nprimrec seq:: \"(nat \\<Rightarrow> ('s,'p,'f,'e)com) \\<Rightarrow> 'p \\<Rightarrow> nat \\<Rightarrow> ('s,'p,'f,'e)com\"\nwhere\n\"seq c p 0 = Call p\" |\n\"seq c p (Suc i) = subst_redex (seq c p i) (c i)\"\n\n\nlemma renumber':\n  assumes f: \"\\<forall>i. (a,f i) \\<in> r\\<^sup>* \\<and> (f i,f(Suc i)) \\<in> r\" \n  assumes a_b: \"(a,b) \\<in> r\\<^sup>*\" \n  shows \"b = f 0 \\<Longrightarrow> (\\<exists>f. f 0 = a \\<and> (\\<forall>i. (f i, f(Suc i)) \\<in> r))\"\nusing a_b\nproof (induct rule: converse_rtrancl_induct [consumes 1])\n  assume \"b = f 0\"\n  with f show \"\\<exists>f. f 0 = b \\<and> (\\<forall>i. (f i, f (Suc i)) \\<in> r)\"\n    by blast\nnext\n  fix a z\n  assume a_z: \"(a, z) \\<in> r\" and \"(z, b) \\<in> r\\<^sup>*\" \n  assume \"b = f 0 \\<Longrightarrow> \\<exists>f. f 0 = z \\<and> (\\<forall>i. (f i, f (Suc i)) \\<in> r)\"\n         \"b = f 0\"\n  then obtain f where f0: \"f 0 = z\" and seq: \"\\<forall>i. (f i, f (Suc i)) \\<in> r\"\n    by iprover\n  {\n    fix i have \"((\\<lambda>i. case i of 0 \\<Rightarrow> a | Suc i \\<Rightarrow> f i) i, f i) \\<in> r\"\n      using seq a_z f0\n      by (cases i) auto\n  }\n  then\n  show \"\\<exists>f. f 0 = a \\<and> (\\<forall>i. (f i, f (Suc i)) \\<in> r)\"\n    by - (rule exI [where x=\"\\<lambda>i. case i of 0 \\<Rightarrow> a | Suc i \\<Rightarrow> f i\"],simp)\nqed\n\nlemma renumber:\n \"\\<forall>i. (a,f i) \\<in> r\\<^sup>* \\<and> (f i,f(Suc i)) \\<in> r \n \\<Longrightarrow> \\<exists>f. f 0 = a \\<and> (\\<forall>i. (f i, f(Suc i)) \\<in> r)\"\n  by (blast dest:renumber')\n\nlemma lem:\n  \"\\<forall>y. r\\<^sup>+\\<^sup>+ a y \\<longrightarrow> P a \\<longrightarrow> P y \n   \\<Longrightarrow> ((b,a) \\<in> {(y,x). P x \\<and> r x y}\\<^sup>+) = ((b,a) \\<in> {(y,x). P x \\<and> r\\<^sup>+\\<^sup>+ x y})\"\napply(rule iffI)\n apply clarify\n apply(erule trancl_induct)\n  apply blast\n apply(blast intro:tranclp_trans)\napply clarify\napply(erule tranclp_induct)\n apply blast\napply(blast intro:trancl_trans)\ndone\n\ncorollary terminates_impl_no_infinite_trans_computation:\n assumes terminates: \"\\<Gamma>\\<turnstile>c\\<down>s\"\n shows \"\\<not>(\\<exists>f. f 0 = (c,s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow>\\<^sup>+ f(Suc i)))\"\nproof -\n  have \"wf({(y,x). \\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow> y}\\<^sup>+)\"\n  proof (rule wf_trancl)\n    show \"wf {(y, x). \\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow> y}\"\n    proof (simp only: wf_iff_no_infinite_down_chain,clarify,simp)\n      fix f\n      assume \"\\<forall>i. \\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>* f i \\<and> \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n      hence \"\\<exists>f. f (0::nat) = (c,s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i))\"\n        by (rule renumber [to_pred])\n      moreover from terminates_impl_no_infinite_computation [OF terminates]\n      have \"\\<not> (\\<exists>f. f (0::nat) = (c, s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)))\"\n        by (simp add: inf_def)\n      ultimately show False\n        by simp\n    qed\n  qed\n  hence \"\\<not> (\\<exists>f. \\<forall>i. (f (Suc i), f i)\n                 \\<in> {(y, x). \\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow> y}\\<^sup>+)\"\n    by (simp add: wf_iff_no_infinite_down_chain)\n  thus ?thesis\n  proof (rule contrapos_nn)\n    assume \"\\<exists>f. f (0::nat) = (c, s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow>\\<^sup>+ f (Suc i))\"\n    then obtain f where\n      f0: \"f 0 = (c, s)\" and\n      seq: \"\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow>\\<^sup>+ f (Suc i)\"\n      by iprover\n    show \n      \"\\<exists>f. \\<forall>i. (f (Suc i), f i) \\<in> {(y, x). \\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow> y}\\<^sup>+\"\n    proof (rule exI [where x=f],rule allI)\n      fix i\n      show \"(f (Suc i), f i) \\<in> {(y, x). \\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow> y}\\<^sup>+\"\n      proof -   \n        {\n          fix i have \"\\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>* f i\"\n          proof (induct i)\n            case 0 show \"\\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* f 0\"\n              by (simp add: f0)\n          next\n            case (Suc n)\n            have \"\\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* f n\"  by fact\n            with seq show \"\\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* f (Suc n)\"\n              by (blast intro: tranclp_into_rtranclp rtranclp_trans)\n          qed\n        }\n        hence \"\\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>* f i\"\n          by iprover\n        with seq have\n          \"(f (Suc i), f i) \\<in> {(y, x). \\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* x \\<and> \\<Gamma>\\<turnstile>x \\<rightarrow>\\<^sup>+ y}\"\n          by clarsimp\n        moreover \n        have \"\\<forall>y. \\<Gamma>\\<turnstile>f i \\<rightarrow>\\<^sup>+ y\\<longrightarrow>\\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* f i\\<longrightarrow>\\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* y\"\n          by (blast intro: tranclp_into_rtranclp rtranclp_trans)\n        ultimately \n        show ?thesis \n          by (subst lem )\n      qed\n    qed\n  qed\nqed\n\ntheorem wf_termi_call_steps: \"wf (termi_call_steps \\<Gamma>)\"\nproof (simp only: termi_call_steps_def wf_iff_no_infinite_down_chain,\n       clarify,simp)\n  fix f\n  assume inf: \"\\<forall>i. (\\<lambda>(t, q) (s, p).\n                \\<Gamma>\\<turnstile>Call p \\<down> Normal s \\<and>\n                (\\<exists>c. \\<Gamma>\\<turnstile> (Call p, Normal s) \\<rightarrow>\\<^sup>+ (c, Normal t) \\<and> redex c = Call q))\n             (f (Suc i)) (f i)\"\n  def s\\<equiv>\"\\<lambda>i::nat. fst (f i)\" \n  def p\\<equiv>\"\\<lambda>i::nat. snd (f i)::'b\"\n  from inf\n  have inf': \"\\<forall>i. \\<Gamma>\\<turnstile>Call (p i) \\<down> Normal (s i) \\<and>\n               (\\<exists>c. \\<Gamma>\\<turnstile> (Call (p i), Normal (s i)) \\<rightarrow>\\<^sup>+ (c, Normal (s (i+1))) \\<and> \n                    redex c = Call (p (i+1)))\"\n    apply -\n    apply (rule allI)\n    apply (erule_tac x=i in allE)\n    apply (auto simp add: s_def p_def)\n    done\n  show False\n  proof -\n    from inf'\n    have \"\\<exists>c. \\<forall>i. \\<Gamma>\\<turnstile>Call (p i) \\<down> Normal (s i) \\<and>\n               \\<Gamma>\\<turnstile> (Call (p i), Normal (s i)) \\<rightarrow>\\<^sup>+ (c i, Normal (s (i+1))) \\<and> \n                    redex (c i) = Call (p (i+1))\"\n      apply -\n      apply (rule choice)\n      by blast\n    then obtain c where\n      termi_c: \"\\<forall>i. \\<Gamma>\\<turnstile>Call (p i) \\<down> Normal (s i)\" and\n      steps_c: \"\\<forall>i. \\<Gamma>\\<turnstile> (Call (p i), Normal (s i)) \\<rightarrow>\\<^sup>+ (c i, Normal (s (i+1)))\" and\n      red_c:   \"\\<forall>i. redex (c i) = Call (p (i+1))\"\n      by auto\n    def g\\<equiv>\"\\<lambda>i. (seq c (p 0) i,Normal (s i)::('a,'c) xstate)\"\n    from red_c [rule_format, of 0]\n    have \"g 0 = (Call (p 0), Normal (s 0))\"\n      by (simp add: g_def)\n    moreover\n    {\n      fix i\n      have \"redex (seq c (p 0) i) = Call (p i)\"\n        by (induct i) (auto simp add: redex_subst_redex red_c)\n      from this [symmetric]\n      have \"subst_redex (seq c (p 0) i) (Call (p i)) = (seq c (p 0) i)\"\n        by (simp add: subst_redex_redex)\n    } note subst_redex_seq = this\n    have \"\\<forall>i. \\<Gamma>\\<turnstile> (g i) \\<rightarrow>\\<^sup>+ (g (i+1))\"\n    proof \n      fix i\n      from steps_c [rule_format, of i]\n      have \"\\<Gamma>\\<turnstile> (Call (p i), Normal (s i)) \\<rightarrow>\\<^sup>+ (c i, Normal (s (i + 1)))\".\n      from steps_redex' [OF this, of \"(seq c (p 0) i)\"]\n      have \"\\<Gamma>\\<turnstile> (subst_redex (seq c (p 0) i) (Call (p i)), Normal (s i)) \\<rightarrow>\\<^sup>+\n                (subst_redex (seq c (p 0) i) (c i), Normal (s (i + 1)))\" .\n      hence \"\\<Gamma>\\<turnstile> (seq c (p 0) i, Normal (s i)) \\<rightarrow>\\<^sup>+ \n                 (seq c (p 0) (i+1), Normal (s (i + 1)))\"\n        by (simp add: subst_redex_seq)\n      thus \"\\<Gamma>\\<turnstile> (g i) \\<rightarrow>\\<^sup>+ (g (i+1))\"\n        by (simp add: g_def)\n    qed\n    moreover\n    from terminates_impl_no_infinite_trans_computation [OF termi_c [rule_format, of 0]]\n    have \"\\<not> (\\<exists>f. f 0 = (Call (p 0), Normal (s 0)) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile> f i \\<rightarrow>\\<^sup>+ f (Suc i)))\" .\n    ultimately show False\n      by auto\n  qed\nqed\n\n\nlemma no_infinite_computation_implies_wf: \n  assumes not_inf: \"\\<not> \\<Gamma>\\<turnstile> (c, s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n  shows \"wf {(c2,c1). \\<Gamma> \\<turnstile> (c,s) \\<rightarrow>\\<^sup>* c1 \\<and> \\<Gamma> \\<turnstile> c1 \\<rightarrow> c2}\"\nproof (simp only: wf_iff_no_infinite_down_chain,clarify, simp)\n  fix f\n  assume \"\\<forall>i. \\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* f i \\<and> \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)\"\n  hence \"\\<exists>f. f 0 = (c, s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i))\"\n    by (rule renumber [to_pred])\n  moreover from not_inf\n  have \"\\<not> (\\<exists>f. f 0 = (c, s) \\<and> (\\<forall>i. \\<Gamma>\\<turnstile>f i \\<rightarrow> f (Suc i)))\"\n    by (simp add: inf_def)\n  ultimately show False\n    by simp\nqed\n\nlemma not_final_Stuck_step: \"\\<not> final (c,Stuck) \\<Longrightarrow> \\<exists>c' s'. \\<Gamma>\\<turnstile> (c, Stuck) \\<rightarrow> (c',s')\"\nby (induct c) (fastforce intro: step.intros simp add: final_def)+\n\nlemma not_final_Abrupt_step: \n  \"\\<not> final (c,Abrupt s) \\<Longrightarrow> \\<exists>c' s'. \\<Gamma>\\<turnstile> (c, Abrupt s) \\<rightarrow> (c',s')\"\nby (induct c) (fastforce intro: step.intros simp add: final_def)+\n\nlemma not_final_Fault_step: \n  \"\\<not> final (c,Fault f) \\<Longrightarrow> \\<exists>c' s'. \\<Gamma>\\<turnstile> (c, Fault f) \\<rightarrow> (c',s')\"\nby (induct c) (fastforce intro: step.intros simp add: final_def)+\n\nlemma not_final_Normal_step: \n  \"\\<not> final (c,Normal s) \\<and> ((\\<exists>b c1. redex c = Await b c1) \\<longrightarrow> \\<Gamma>\\<turnstile>c \\<down> Normal s) \\<Longrightarrow> \\<exists>c' s'. \\<Gamma>\\<turnstile> (c, Normal s) \\<rightarrow> (c',s')\"\nproof (induct c) \n  case Skip thus ?case by (simp add: final_def)\nnext\n  case Basic thus ?case by (meson step.Basic)\nnext\n  case (Spec r)\n  thus ?case by (meson step.Spec step.SpecStuck)    \nnext\n  case (Seq c\\<^sub>1 c\\<^sub>2)\n  thus ?case by (metis SeqSkip SeqThrow final_def fst_conv redex.simps(4) step.Seq terminates_Normal_elim_cases(5))\nnext\n  case (Cond b c1 c2)\n  show ?case\n    by (cases \"s \\<in> b\") (fastforce intro: step.intros)+\nnext\n  case (While b c)\n  show ?case\n    by (cases \"s \\<in> b\") (fastforce intro: step.intros)+\nnext\n  case (Call p)\n  show ?case\n  by (cases \"\\<Gamma> p\") (fastforce intro: step.intros)+\nnext\n  case DynCom thus ?case by (fastforce intro: step.intros)\nnext\n  case (Guard f g c)\n  show ?case\n    by (cases \"s \\<in> g\") (fastforce intro: step.intros)+\nnext\n  case Throw\n  thus ?case by (fastforce intro: step.intros simp add: final_def)\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  thus ?case\n    by (cases \"final (c\\<^sub>1,Normal s)\") (fastforce intro: step.intros elim: terminates_Normal_elim_cases simp add: final_def)+\nnext\n  case (Await b c) \n  then obtain ba c1 where x:\"(\\<exists>ba c1. redex (Await b c) = Await ba c1)\" by simp\n  then have \"\\<Gamma>\\<turnstile>Await b c \\<down> Normal s\" using x Await.prems by blast \n  also have \"s \\<in> b\" by (meson `\\<Gamma>\\<turnstile>Await b c \\<down> Normal s` terminates_Normal_elim_cases(12))\n  moreover have \"\\<exists>t. \\<Gamma>\\<turnstile>\\<langle>c, Normal s\\<rangle> \\<Rightarrow> t\" by (meson calculation terminates_Normal_elim_cases(12) terminates_implies_exec) \n  ultimately show ?case using AwaitAbrupt  step.Await by fastforce\nqed\n\nlemma final_termi:\n\"final (c,s) \\<Longrightarrow> \\<Gamma>\\<turnstile>c\\<down>s\"\n  by (cases s) (auto simp add: final_def terminates.intros)\n\nlemma split_computation: \nassumes steps: \"\\<Gamma>\\<turnstile> (c, s) \\<rightarrow>\\<^sup>* (c\\<^sub>f, s\\<^sub>f)\"\nassumes not_final: \"\\<not> final (c,s)\"\nassumes final: \"final (c\\<^sub>f,s\\<^sub>f)\"\nshows \"\\<exists>c' s'. \\<Gamma>\\<turnstile> (c, s) \\<rightarrow> (c',s') \\<and> \\<Gamma>\\<turnstile> (c', s') \\<rightarrow>\\<^sup>* (c\\<^sub>f, s\\<^sub>f)\"\nusing steps not_final final\nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl thus ?case by simp\nnext\n  case (Trans c s c' s')\n  thus ?case by auto\nqed\n\n\nlemma wf_implies_termi_reach_step_case:\nassumes hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (c, Normal s) \\<rightarrow> (c', s')\\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" and\n        hyp1:\"(\\<And>b c1. (redex c = Await b c1) \\<Longrightarrow> \\<Gamma>\\<turnstile>c1 \\<down> Normal s \\<and> s\\<in>b)\"\nshows \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\nusing hyp hyp1\nproof (induct c)\n  case Skip show ?case by (fastforce intro: terminates.intros)\nnext\n  case Basic show ?case by (fastforce intro: terminates.intros)\nnext\n  case (Spec r)\n  show ?case\n    by (cases \"\\<exists>t. (s,t)\\<in>r\") (fastforce intro: terminates.intros)+\nnext\n  case (Seq c\\<^sub>1 c\\<^sub>2)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (c', s') \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\"\nusing Seq.prems by blast \n   have hyp': \"(\\<And>b c1. (redex (Seq c\\<^sub>1 c\\<^sub>2)  = Await b c1) \\<Longrightarrow> \\<Gamma>\\<turnstile>c1 \\<down> Normal s \\<and> s\\<in>b)\" by fact \n  show ?case \n  proof (rule terminates.Seq)\n    {\n      fix c' s'\n      assume step_c\\<^sub>1: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow> (c', s')\"      \n      assume red: \"(\\<And>b c1. (redex c\\<^sub>1  = Await b c1) \\<Longrightarrow> \\<Gamma>\\<turnstile>c1 \\<down> Normal s \\<and> s\\<in>b)\"\n      have \"\\<Gamma>\\<turnstile>c' \\<down> s'\"\n      proof -\n        from step_c\\<^sub>1\n        have \"\\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (Seq c' c\\<^sub>2, s')\"\n          by (simp add: step.Seq)          \n        from hyp [OF this]\n        have \"\\<Gamma>\\<turnstile>Seq c' c\\<^sub>2 \\<down> s'\".\n        thus \"\\<Gamma>\\<turnstile>c'\\<down> s'\"\n          by cases auto\n      qed\n    } \n    from Seq.hyps (1) [OF this]\n    show \"\\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s\" using terminates_Skip' by (simp add: hyp') \n  next\n    show \"\\<forall>s'. \\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> s' \\<longrightarrow> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\"\n    proof (intro allI impI)\n      fix s'\n      assume exec_c\\<^sub>1: \"\\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> s'\"\n      show \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\"\n      proof (cases \"final (c\\<^sub>1,Normal s)\")\n        case True\n        hence \"c\\<^sub>1=Skip \\<or> c\\<^sub>1=Throw\"\n          by (simp add: final_def)\n        thus ?thesis\n        proof\n          assume Skip: \"c\\<^sub>1=Skip\"\n          have s1:\"\\<Gamma>\\<turnstile>(Seq Skip c\\<^sub>2,Normal s) \\<rightarrow> (c\\<^sub>2,Normal s) \\<and>\\<not> (\\<exists>b c1. Seq c\\<^sub>1 c\\<^sub>2 = Await b c1)\"\n            by (simp add: step.SeqSkip)          \n          from hyp \n          have \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s\" using local.Skip s1 by blast \n          moreover from exec_c\\<^sub>1 Skip\n          have \"s'=Normal s\"\n            by (auto elim: exec_Normal_elim_cases)\n          ultimately show ?thesis by simp\n        next\n          assume Throw: \"c\\<^sub>1=Throw\"\n          with exec_c\\<^sub>1 have \"s'=Abrupt s\"\n            by (auto elim: exec_Normal_elim_cases)\n          thus ?thesis\n            by auto\n        qed\n      next\n        case False        \n        from exec_impl_steps [OF exec_c\\<^sub>1]\n        obtain c\\<^sub>f t where \n          steps_c\\<^sub>1: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow>\\<^sup>* (c\\<^sub>f, t)\" and\n          fin:\"(case s' of\n                 Abrupt x \\<Rightarrow> c\\<^sub>f = Throw \\<and> t = Normal x\n                | _ \\<Rightarrow> c\\<^sub>f = Skip \\<and> t = s')\"\n          by (fastforce split: xstate.splits)\n        with fin have final: \"final (c\\<^sub>f,t)\"\n          by (cases s') (auto simp add: final_def)\n        from split_computation [OF steps_c\\<^sub>1 False this]\n        obtain c'' s'' where\n          first: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow> (c'', s'')\" and\n          rest: \"\\<Gamma>\\<turnstile> (c'', s'') \\<rightarrow>\\<^sup>* (c\\<^sub>f, t)\" \n          by blast\n        from step.Seq [OF first]\n        have \"\\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (Seq c'' c\\<^sub>2, s'')\" by auto\n        from hyp [OF this]\n        have termi_s'': \"\\<Gamma>\\<turnstile>Seq c'' c\\<^sub>2 \\<down> s''\".\n        show ?thesis\n        proof (cases s'')\n          case (Normal x)\n          from termi_s'' [simplified Normal]\n          have termi_c\\<^sub>2: \"\\<forall>t. \\<Gamma>\\<turnstile> \\<langle>c'',Normal x\\<rangle> \\<Rightarrow> t \\<longrightarrow> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> t\"\n            by cases\n          show ?thesis\n          proof (cases \"\\<exists>x'. s'=Abrupt x'\")\n            case False\n            with fin obtain \"c\\<^sub>f=Skip\" \"t=s'\"\n              by (cases s') auto\n            from steps_Skip_impl_exec [OF rest [simplified this]] Normal\n            have \"\\<Gamma>\\<turnstile> \\<langle>c'',Normal x\\<rangle> \\<Rightarrow> s'\"\n              by simp\n            from termi_c\\<^sub>2 [rule_format, OF this]\n            show \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\" .\n          next\n            case True\n            with fin obtain x' where s': \"s'=Abrupt x'\" and \"c\\<^sub>f=Throw\" \"t=Normal x'\"\n              by auto\n            from steps_Throw_impl_exec [OF rest [simplified this]] Normal \n            have \"\\<Gamma>\\<turnstile> \\<langle>c'',Normal x\\<rangle> \\<Rightarrow> Abrupt x'\"\n              by simp\n            from termi_c\\<^sub>2 [rule_format, OF this] s'\n            show \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\" by simp\n           qed\n        next\n          case (Abrupt x)\n          from steps_Abrupt_prop [OF rest this]\n          have \"t=Abrupt x\" by simp\n          with fin have \"s'=Abrupt x\"\n            by (cases s') auto\n          thus \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\" \n            by auto\n        next\n          case (Fault f)\n          from steps_Fault_prop [OF rest this]\n          have \"t=Fault f\" by simp\n          with fin have \"s'=Fault f\"\n            by (cases s') auto\n          thus \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\" \n            by auto\n        next\n          case Stuck\n          from steps_Stuck_prop [OF rest this]\n          have \"t=Stuck\" by simp\n          with fin have \"s'=Stuck\"\n            by (cases s') auto\n          thus \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\" \n            by auto\n        qed\n      qed\n    qed\n  qed\nnext\n  case (Cond b c\\<^sub>1 c\\<^sub>2)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Cond b c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (c', s') \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\"\nby (simp add: Cond.prems(1)) \n  show ?case\n  proof (cases \"s\\<in>b\") \n    case True\n    then have \"\\<Gamma>\\<turnstile> (Cond b c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (c\\<^sub>1, Normal s) \"\n     by (simp add: step.CondTrue)     \n    from hyp [OF this] have \"\\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s\".\n    with True show ?thesis\n      by (auto intro: terminates.intros)\n  next\n    case False\n    then have \"\\<Gamma>\\<turnstile> (Cond b c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (c\\<^sub>2, Normal s)\"\n      by (simp add: step.CondFalse)\n    from hyp [OF this] have \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s\".\n    with False show ?thesis\n      by (auto intro: terminates.intros)\n  qed\nnext\n  case (While b c)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (While b c, Normal s) \\<rightarrow> (c', s')   \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by fact\n  show ?case\n  proof (cases \"s\\<in>b\") \n    case True\n    then have \"\\<Gamma>\\<turnstile> (While b c, Normal s) \\<rightarrow> (Seq c (While b c), Normal s)\"\n      by (simp add: step.WhileTrue)\n    from hyp [OF this] have \"\\<Gamma>\\<turnstile>(Seq c (While b c)) \\<down> Normal s\".\n    with True show ?thesis\n      by (auto elim: terminates_Normal_elim_cases intro: terminates.intros)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates.intros)\n  qed\nnext\n  case (Call p)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Call p, Normal s) \\<rightarrow> (c', s')  \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by (simp add: Call.prems)\n  show ?case\n  proof (cases \"\\<Gamma> p\")\n    case None\n    thus ?thesis\n      by (auto intro: terminates.intros)\n  next\n    case (Some bdy)\n    then have \"\\<Gamma>\\<turnstile> (Call p, Normal s) \\<rightarrow> (bdy, Normal s)\"\n      by (simp add: step.Call)\n    from hyp [OF this] have \"\\<Gamma>\\<turnstile>bdy \\<down> Normal s\".\n    with Some show ?thesis\n      by (auto intro: terminates.intros)\n  qed\nnext\n  case (DynCom c)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (DynCom c, Normal s) \\<rightarrow> (c', s')  \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by fact\n  have \"\\<Gamma>\\<turnstile> (DynCom c, Normal s) \\<rightarrow> (c s, Normal s)\"\n    by (simp add: step.DynCom)\n  from hyp [OF this] have \"\\<Gamma>\\<turnstile>c s \\<down> Normal s\".\n  then show ?case\n    by (auto intro: terminates.intros)\nnext\n  case (Guard f g c)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Guard f g c, Normal s) \\<rightarrow> (c', s')   \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by fact\n  show ?case\n  proof (cases \"s\\<in>g\")\n    case True\n    then have \"\\<Gamma>\\<turnstile> (Guard f g c, Normal s) \\<rightarrow> (c, Normal s) \"\n      by (simp add: step.Guard) thm step.Guard\n    from hyp [OF this] have \"\\<Gamma>\\<turnstile>c\\<down> Normal s\".\n    with True show ?thesis\n      by (auto intro: terminates.intros)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates.intros)\n  qed\nnext \n  case Throw show ?case by (auto intro: terminates.intros)\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (c', s')   \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by fact\n  have hyp': \"(\\<And>b c1. (redex (Catch c\\<^sub>1 c\\<^sub>2) = Await b c1) \\<Longrightarrow> \\<Gamma>\\<turnstile>c1 \\<down> Normal s \\<and> s\\<in>b)\" by fact\n  show ?case\n  proof (rule terminates.Catch)\n    {\n      fix c' s'\n      assume step_c\\<^sub>1: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow> (c', s')\"\n      assume red: \"(\\<And>b c1. (redex c\\<^sub>1  = Await b c1) \\<Longrightarrow> \\<Gamma>\\<turnstile>c1 \\<down> Normal s \\<and> s\\<in>b)\"\n      have \"\\<Gamma>\\<turnstile>c' \\<down> s'\"\n      proof -\n        from step_c\\<^sub>1\n        have \"\\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (Catch c' c\\<^sub>2, s') \"\n          by (simp add: step.Catch)\n        from hyp [OF this]\n        have \"\\<Gamma>\\<turnstile>Catch c' c\\<^sub>2 \\<down> s'\".\n        thus \"\\<Gamma>\\<turnstile>c'\\<down> s'\"\n          by cases auto\n      qed\n    } \n    from Catch.hyps (1) [OF this]\n    show \"\\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s\" using terminates_Skip' by (simp add: hyp')\n  next  \n    show \"\\<forall>s'. \\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Abrupt s' \\<longrightarrow> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s'\"\n    proof (intro allI impI)\n      fix s'\n      assume exec_c\\<^sub>1: \"\\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Abrupt s'\"\n      show \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s'\"\n      proof (cases \"final (c\\<^sub>1,Normal s)\")\n        case True\n        with exec_c\\<^sub>1\n        have Throw: \"c\\<^sub>1=Throw\"\n          by (auto simp add: final_def elim: exec_Normal_elim_cases)\n        have s1: \"\\<Gamma>\\<turnstile>(Catch Throw c\\<^sub>2,Normal s) \\<rightarrow> (c\\<^sub>2,Normal s)\"\n          by (simp add: step.CatchThrow)\n        from hyp \n        have \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s\" using local.Throw s1 by blast \n        moreover from exec_c\\<^sub>1 Throw\n        have \"s'=s\"\n          by (auto elim: exec_Normal_elim_cases)\n        ultimately show ?thesis by simp\n      next\n        case False\n        from exec_impl_steps [OF exec_c\\<^sub>1]\n        obtain c\\<^sub>f t where \n          steps_c\\<^sub>1: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow>\\<^sup>* (Throw, Normal s')\" \n          by (fastforce split: xstate.splits)\n        from split_computation [OF steps_c\\<^sub>1 False]\n        obtain c'' s'' where\n          first: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow> (c'', s'')\" and\n          rest: \"\\<Gamma>\\<turnstile> (c'', s'') \\<rightarrow>\\<^sup>* (Throw, Normal s')\" \n          by (auto simp add: final_def)\n        from step.Catch [OF first]\n        have \"\\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (Catch c'' c\\<^sub>2, s'')\" by auto\n        from hyp [OF this] \n        have \"\\<Gamma>\\<turnstile>Catch c'' c\\<^sub>2 \\<down> s''\".\n        moreover\n        from steps_Throw_impl_exec [OF rest]\n        have \"\\<Gamma>\\<turnstile> \\<langle>c'',s''\\<rangle> \\<Rightarrow> Abrupt s'\".\n        moreover\n        from rest obtain x where \"s''=Normal x\"\n          by (cases s'')\n             (auto dest: steps_Fault_prop steps_Abrupt_prop steps_Stuck_prop)\n        ultimately show ?thesis\n          by (fastforce elim: terminates_elim_cases)\n      qed\n    qed\n  qed\nnext\n  case (Await b c) \n  have hyp':\"\\<And>ba c1. redex (Await b c) = Await ba c1 \\<Longrightarrow> \\<Gamma>\\<turnstile>c1 \\<down> Normal s \\<and> s \\<in> ba\" by fact \n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Await b c, Normal s) \\<rightarrow> (c', s') \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by (simp add: final_termi step_await_final1)\n  have red:\"redex (Await b c)  = Await b c\" by auto  \n  then have \"\\<And>b1 c1. (redex (Await b c)  = Await b1 c1) \\<Longrightarrow> b1=b \\<and> c1 = c\" by simp\n  then have \" \\<Gamma>\\<turnstile>c \\<down> Normal s \\<and> s \\<in> b\" by (simp add: Await.prems(2))\n  show ?case\n  by (simp add: `\\<Gamma>\\<turnstile>c \\<down> Normal s \\<and> s \\<in> b` terminates.AwaitTrue)      \nqed\n\n\nlemma wf_implies_termi_reach_step_case':\nassumes hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (c, Normal s) \\<rightarrow> (c', s')\\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" and\n        hyp1:\"~(\\<exists>b c1. redex c = Await b c1)\"\nshows \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\nusing hyp hyp1\nproof (induct c)\n  case Skip show ?case by (fastforce intro: terminates.intros)\nnext\n  case Basic show ?case by (fastforce intro: terminates.intros)\nnext\n  case (Spec r)\n  show ?case\n    by (cases \"\\<exists>t. (s,t)\\<in>r\") (fastforce intro: terminates.intros)+\nnext\n  case (Seq c\\<^sub>1 c\\<^sub>2)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (c', s') \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\"\nusing Seq.prems by blast\n  have hyp': \"~(\\<exists>b c1. redex (Seq c\\<^sub>1 c\\<^sub>2) = Await b c1)\" by fact\n  show ?case \n  proof (rule terminates.Seq)\n    {\n      fix c' s'\n      assume step_c\\<^sub>1: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow> (c', s')\"\n      assume red:  \"~(\\<exists>b c1. redex c\\<^sub>1 = Await b c1)\"      \n      have \"\\<Gamma>\\<turnstile>c' \\<down> s'\"\n      proof -\n        from step_c\\<^sub>1\n        have \"\\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (Seq c' c\\<^sub>2, s')\"\n          by (simp add: step.Seq)          \n        from hyp [OF this]\n        have \"\\<Gamma>\\<turnstile>Seq c' c\\<^sub>2 \\<down> s'\".\n        thus \"\\<Gamma>\\<turnstile>c'\\<down> s'\"\n          by cases auto\n      qed\n    } \n    from Seq.hyps (1) [OF this]\n    show \"\\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s\"using hyp' by force \n  next\n    show \"\\<forall>s'. \\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> s' \\<longrightarrow> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\"\n    proof (intro allI impI)\n      fix s'\n      assume exec_c\\<^sub>1: \"\\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> s'\"\n      show \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\"\n      proof (cases \"final (c\\<^sub>1,Normal s)\")\n        case True\n        hence \"c\\<^sub>1=Skip \\<or> c\\<^sub>1=Throw\"\n          by (simp add: final_def)\n        thus ?thesis\n        proof\n          assume Skip: \"c\\<^sub>1=Skip\"\n          have s1:\"\\<Gamma>\\<turnstile>(Seq Skip c\\<^sub>2,Normal s) \\<rightarrow> (c\\<^sub>2,Normal s) \\<and>\\<not> (\\<exists>b c1. Seq c\\<^sub>1 c\\<^sub>2 = Await b c1)\"\n            by (simp add: step.SeqSkip)          \n          from hyp \n          have \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s\" using local.Skip s1 by blast \n          moreover from exec_c\\<^sub>1 Skip\n          have \"s'=Normal s\"\n            by (auto elim: exec_Normal_elim_cases)\n          ultimately show ?thesis by simp\n        next\n          assume Throw: \"c\\<^sub>1=Throw\"\n          with exec_c\\<^sub>1 have \"s'=Abrupt s\"\n            by (auto elim: exec_Normal_elim_cases)\n          thus ?thesis\n            by auto\n        qed\n      next\n        case False        \n        from exec_impl_steps [OF exec_c\\<^sub>1]\n        obtain c\\<^sub>f t where \n          steps_c\\<^sub>1: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow>\\<^sup>* (c\\<^sub>f, t)\" and\n          fin:\"(case s' of\n                 Abrupt x \\<Rightarrow> c\\<^sub>f = Throw \\<and> t = Normal x\n                | _ \\<Rightarrow> c\\<^sub>f = Skip \\<and> t = s')\"\n          by (fastforce split: xstate.splits)\n        with fin have final: \"final (c\\<^sub>f,t)\"\n          by (cases s') (auto simp add: final_def)\n        from split_computation [OF steps_c\\<^sub>1 False this]\n        obtain c'' s'' where\n          first: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow> (c'', s'')\" and\n          rest: \"\\<Gamma>\\<turnstile> (c'', s'') \\<rightarrow>\\<^sup>* (c\\<^sub>f, t)\" \n          by blast\n        from step.Seq [OF first]\n        have \"\\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (Seq c'' c\\<^sub>2, s'')\" by auto\n        from hyp [OF this]\n        have termi_s'': \"\\<Gamma>\\<turnstile>Seq c'' c\\<^sub>2 \\<down> s''\".\n        show ?thesis\n        proof (cases s'')\n          case (Normal x)\n          from termi_s'' [simplified Normal]\n          have termi_c\\<^sub>2: \"\\<forall>t. \\<Gamma>\\<turnstile> \\<langle>c'',Normal x\\<rangle> \\<Rightarrow> t \\<longrightarrow> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> t\"\n            by cases\n          show ?thesis\n          proof (cases \"\\<exists>x'. s'=Abrupt x'\")\n            case False\n            with fin obtain \"c\\<^sub>f=Skip\" \"t=s'\"\n              by (cases s') auto\n            from steps_Skip_impl_exec [OF rest [simplified this]] Normal\n            have \"\\<Gamma>\\<turnstile> \\<langle>c'',Normal x\\<rangle> \\<Rightarrow> s'\"\n              by simp\n            from termi_c\\<^sub>2 [rule_format, OF this]\n            show \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\" .\n          next\n            case True\n            with fin obtain x' where s': \"s'=Abrupt x'\" and \"c\\<^sub>f=Throw\" \"t=Normal x'\"\n              by auto\n            from steps_Throw_impl_exec [OF rest [simplified this]] Normal \n            have \"\\<Gamma>\\<turnstile> \\<langle>c'',Normal x\\<rangle> \\<Rightarrow> Abrupt x'\"\n              by simp\n            from termi_c\\<^sub>2 [rule_format, OF this] s'\n            show \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\" by simp\n           qed\n        next\n          case (Abrupt x)\n          from steps_Abrupt_prop [OF rest this]\n          have \"t=Abrupt x\" by simp\n          with fin have \"s'=Abrupt x\"\n            by (cases s') auto\n          thus \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\" \n            by auto\n        next\n          case (Fault f)\n          from steps_Fault_prop [OF rest this]\n          have \"t=Fault f\" by simp\n          with fin have \"s'=Fault f\"\n            by (cases s') auto\n          thus \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\" \n            by auto\n        next\n          case Stuck\n          from steps_Stuck_prop [OF rest this]\n          have \"t=Stuck\" by simp\n          with fin have \"s'=Stuck\"\n            by (cases s') auto\n          thus \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> s'\" \n            by auto\n        qed\n      qed\n    qed\n  qed\nnext\n  case (Cond b c\\<^sub>1 c\\<^sub>2)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Cond b c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (c', s') \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\"\nby (simp add: Cond.prems(1)) \n  show ?case\n  proof (cases \"s\\<in>b\") \n    case True\n    then have \"\\<Gamma>\\<turnstile> (Cond b c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (c\\<^sub>1, Normal s) \"\n     by (simp add: step.CondTrue)     \n    from hyp [OF this] have \"\\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s\".\n    with True show ?thesis\n      by (auto intro: terminates.intros)\n  next\n    case False\n    then have \"\\<Gamma>\\<turnstile> (Cond b c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (c\\<^sub>2, Normal s)\"\n      by (simp add: step.CondFalse)\n    from hyp [OF this] have \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s\".\n    with False show ?thesis\n      by (auto intro: terminates.intros)\n  qed\nnext\n  case (While b c)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (While b c, Normal s) \\<rightarrow> (c', s')   \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by fact\n  show ?case\n  proof (cases \"s\\<in>b\") \n    case True\n    then have \"\\<Gamma>\\<turnstile> (While b c, Normal s) \\<rightarrow> (Seq c (While b c), Normal s)\"\n      by (simp add: step.WhileTrue)\n    from hyp [OF this] have \"\\<Gamma>\\<turnstile>(Seq c (While b c)) \\<down> Normal s\".\n    with True show ?thesis\n      by (auto elim: terminates_Normal_elim_cases intro: terminates.intros)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates.intros)\n  qed\nnext\n  case (Call p)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Call p, Normal s) \\<rightarrow> (c', s')  \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by (simp add: Call.prems)\n  show ?case\n  proof (cases \"\\<Gamma> p\")\n    case None\n    thus ?thesis\n      by (auto intro: terminates.intros)\n  next\n    case (Some bdy)\n    then have \"\\<Gamma>\\<turnstile> (Call p, Normal s) \\<rightarrow> (bdy, Normal s)\"\n      by (simp add: step.Call)\n    from hyp [OF this] have \"\\<Gamma>\\<turnstile>bdy \\<down> Normal s\".\n    with Some show ?thesis\n      by (auto intro: terminates.intros)\n  qed\nnext\n  case (DynCom c)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (DynCom c, Normal s) \\<rightarrow> (c', s')  \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by fact\n  have \"\\<Gamma>\\<turnstile> (DynCom c, Normal s) \\<rightarrow> (c s, Normal s)\"\n    by (simp add: step.DynCom)\n  from hyp [OF this] have \"\\<Gamma>\\<turnstile>c s \\<down> Normal s\".\n  then show ?case\n    by (auto intro: terminates.intros)\nnext\n  case (Guard f g c)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Guard f g c, Normal s) \\<rightarrow> (c', s')   \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by fact\n  show ?case\n  proof (cases \"s\\<in>g\")\n    case True\n    then have \"\\<Gamma>\\<turnstile> (Guard f g c, Normal s) \\<rightarrow> (c, Normal s) \"\n      by (simp add: step.Guard) thm step.Guard\n    from hyp [OF this] have \"\\<Gamma>\\<turnstile>c\\<down> Normal s\".\n    with True show ?thesis\n      by (auto intro: terminates.intros)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates.intros)\n  qed\nnext \n  case Throw show ?case by (auto intro: terminates.intros)\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have hyp: \"\\<And>c' s'. \\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (c', s')   \\<Longrightarrow> \\<Gamma>\\<turnstile>c' \\<down> s'\" by fact\n  have hyp': \"~(\\<exists>b c1. redex (Catch c\\<^sub>1 c\\<^sub>2) = Await b c1)\" by fact\n  show ?case\n  proof (rule terminates.Catch)\n    {\n      fix c' s'\n      assume step_c\\<^sub>1: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow> (c', s')\"\n      assume red: \"~(\\<exists>b c1. redex c\\<^sub>1  = Await b c1)\"\n      have \"\\<Gamma>\\<turnstile>c' \\<down> s'\"\n      proof -\n        from step_c\\<^sub>1\n        have \"\\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (Catch c' c\\<^sub>2, s') \"\n          by (simp add: step.Catch)\n        from hyp [OF this]\n        have \"\\<Gamma>\\<turnstile>Catch c' c\\<^sub>2 \\<down> s'\".\n        thus \"\\<Gamma>\\<turnstile>c'\\<down> s'\"\n          by cases auto\n      qed\n    } \n    from Catch.hyps (1) [OF this]\n    show \"\\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s\" using hyp' by force\n  next  \n    show \"\\<forall>s'. \\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Abrupt s' \\<longrightarrow> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s'\"\n    proof (intro allI impI)\n      fix s'\n      assume exec_c\\<^sub>1: \"\\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Abrupt s'\"\n      show \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s'\"\n      proof (cases \"final (c\\<^sub>1,Normal s)\")\n        case True\n        with exec_c\\<^sub>1\n        have Throw: \"c\\<^sub>1=Throw\"\n          by (auto simp add: final_def elim: exec_Normal_elim_cases)\n        have s1: \"\\<Gamma>\\<turnstile>(Catch Throw c\\<^sub>2,Normal s) \\<rightarrow> (c\\<^sub>2,Normal s)\"\n          by (simp add: step.CatchThrow)\n        from hyp \n        have \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s\" using local.Throw s1 by blast \n        moreover from exec_c\\<^sub>1 Throw\n        have \"s'=s\"\n          by (auto elim: exec_Normal_elim_cases)\n        ultimately show ?thesis by simp\n      next\n        case False\n        from exec_impl_steps [OF exec_c\\<^sub>1]\n        obtain c\\<^sub>f t where \n          steps_c\\<^sub>1: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow>\\<^sup>* (Throw, Normal s')\" \n          by (fastforce split: xstate.splits)\n        from split_computation [OF steps_c\\<^sub>1 False]\n        obtain c'' s'' where\n          first: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal s) \\<rightarrow> (c'', s'')\" and\n          rest: \"\\<Gamma>\\<turnstile> (c'', s'') \\<rightarrow>\\<^sup>* (Throw, Normal s')\" \n          by (auto simp add: final_def)\n        from step.Catch [OF first]\n        have \"\\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, Normal s) \\<rightarrow> (Catch c'' c\\<^sub>2, s'')\" by auto\n        from hyp [OF this] \n        have \"\\<Gamma>\\<turnstile>Catch c'' c\\<^sub>2 \\<down> s''\".\n        moreover\n        from steps_Throw_impl_exec [OF rest]\n        have \"\\<Gamma>\\<turnstile> \\<langle>c'',s''\\<rangle> \\<Rightarrow> Abrupt s'\".\n        moreover\n        from rest obtain x where \"s''=Normal x\"\n          by (cases s'')\n             (auto dest: steps_Fault_prop steps_Abrupt_prop steps_Stuck_prop)\n        ultimately show ?thesis\n          by (fastforce elim: terminates_elim_cases)\n      qed\n    qed\n  qed\nnext\n  case (Await b c)       \n  show ?case\n  using Await.prems(2) by auto   \nqed\n\n\nlemma Await_finish:\"\\<And>c2 s2 b c. \\<Gamma>\\<turnstile> (Await b c, s1) \\<rightarrow> (c2, s2) \\<Longrightarrow> \\<Gamma>\\<turnstile>c2 \\<down> s2\"\nby (metis Abrupt Fault Stuck final_termi step_await_final1 step_preserves_termination xstate.exhaust)\n\n                                                            \nlemma wf_implies_termi_reach:\nassumes wf: \"wf {(cfg2,cfg1). \\<Gamma> \\<turnstile> (c,s) \\<rightarrow>\\<^sup>* cfg1 \\<and> \\<Gamma> \\<turnstile> cfg1 \\<rightarrow> cfg2}\"\nshows \"\\<And>c1 s1. \\<lbrakk>\\<Gamma> \\<turnstile> (c,s) \\<rightarrow>\\<^sup>* cfg1;  cfg1=(c1,s1)\\<rbrakk>\\<Longrightarrow> \\<Gamma>\\<turnstile>c1\\<down>s1\"\nusing wf \nproof (induct cfg1,simp)\n  fix c1 s1\n  assume reach: \"\\<Gamma>\\<turnstile> (c, s) \\<rightarrow>\\<^sup>* (c1, s1)\"\n  assume hyp_raw: \"\\<And>y c2 s2.\n           \\<lbrakk>\\<Gamma>\\<turnstile> (c1, s1) \\<rightarrow> (c2, s2); \\<Gamma>\\<turnstile> (c, s) \\<rightarrow>\\<^sup>* (c2, s2); y = (c2, s2)\\<rbrakk>\n           \\<Longrightarrow> \\<Gamma>\\<turnstile>c2 \\<down> s2\"\n  have hyp: \"\\<And>c2 s2. \\<Gamma>\\<turnstile> (c1, s1) \\<rightarrow> (c2, s2) \\<Longrightarrow> \\<Gamma>\\<turnstile>c2 \\<down> s2\"\n    apply -\n    apply (rule hyp_raw)\n    apply   assumption\n    using reach \n    apply  simp\n    apply (rule refl)\n    done\n  \n  show \"\\<Gamma>\\<turnstile>c1 \\<down> s1\"\n  proof (cases s1)  \n    case (Normal s1')             \n    with  wf_implies_termi_reach_step_case' [OF hyp [simplified Normal]] \n    show ?thesis\n      by auto\n  qed (auto intro: terminates.intros)\nqed\n\ntheorem no_infinite_computation_impl_terminates:\n  assumes not_inf: \"\\<not> \\<Gamma>\\<turnstile> (c, s) \\<rightarrow> \\<dots>(\\<infinity>)\"\n  shows \"\\<Gamma>\\<turnstile>c\\<down>s\"\nproof -\n  from no_infinite_computation_implies_wf [OF not_inf]\n  have wf: \"wf {(c2, c1). \\<Gamma>\\<turnstile>(c, s) \\<rightarrow>\\<^sup>* c1 \\<and> \\<Gamma>\\<turnstile>c1 \\<rightarrow> c2}\".\n  show ?thesis\n    by (rule wf_implies_termi_reach [OF wf]) auto\nqed\n\ncorollary terminates_iff_no_infinite_computation: \n  \"\\<Gamma>\\<turnstile>c\\<down>s = (\\<not> \\<Gamma>\\<turnstile> (c, s) \\<rightarrow> \\<dots>(\\<infinity>))\"\n  apply (rule)\n  apply  (erule terminates_impl_no_infinite_computation)\n  apply (erule no_infinite_computation_impl_terminates)\n  done\n\n(* ************************************************************************* *)\nsubsection {* Generalised Redexes *} \n(* ************************************************************************* *)\n\ntext {*\nFor an important lemma for the completeness proof of the Hoare-logic for\ntotal correctness we need a generalisation of @{const \"redex\"} that not only\nyield the redex itself but all the enclosing statements as well.\n*}\n\nprimrec redexes:: \"('s,'p,'f,'e)com \\<Rightarrow> ('s,'p,'f,'e)com set\"\nwhere\n\"redexes Skip = {Skip}\" |\n\"redexes (Basic f) = {Basic f}\" |\n\"redexes (Spec r) = {Spec r}\" |\n\"redexes (Seq c\\<^sub>1 c\\<^sub>2) = {Seq c\\<^sub>1 c\\<^sub>2} \\<union> redexes c\\<^sub>1\" |\n\"redexes (Cond b c\\<^sub>1 c\\<^sub>2) = {Cond b c\\<^sub>1 c\\<^sub>2}\" |\n\"redexes (While b c) = {While b c}\" |\n\"redexes (Call p) = {Call p}\" |\n\"redexes (DynCom d) = {DynCom d}\" |\n\"redexes (Guard f b c) = {Guard f b c}\" |\n\"redexes (Throw) = {Throw}\" |\n\"redexes (Catch c\\<^sub>1 c\\<^sub>2) = {Catch c\\<^sub>1 c\\<^sub>2} \\<union> redexes c\\<^sub>1\" |\n\"redexes (Await b c) = {Await b c}\"\n\nlemma root_in_redexes: \"c \\<in> redexes c\"\n  apply (induct c)\n  apply auto\n  done\n\nlemma redex_in_redexes: \"redex c \\<in> redexes c\"\n  apply (induct c)\n  apply auto\n  done\n\nlemma redex_redexes: \"\\<And>c'. \\<lbrakk>c' \\<in> redexes c; redex c' = c'\\<rbrakk> \\<Longrightarrow> redex c = c'\" \n  apply (induct c)\n  apply auto\n  done\n\nlemma step_redexes:\n  shows \"\\<And>r r'. \\<lbrakk>\\<Gamma>\\<turnstile>(r,s) \\<rightarrow> (r',s'); r \\<in> redexes c\\<rbrakk> \n  \\<Longrightarrow> \\<exists>c'. \\<Gamma>\\<turnstile>(c,s) \\<rightarrow> (c',s') \\<and> r' \\<in> redexes c'\"\nproof (induct c)\n  case Skip thus ?case by (fastforce intro: step.intros elim: step_elim_cases)\nnext\n  case Basic thus ?case by (fastforce intro: step.intros elim: step_elim_cases)\nnext\n  case Spec thus ?case by (fastforce intro: step.intros elim: step_elim_cases)\nnext\n  case (Seq c\\<^sub>1 c\\<^sub>2)\n  have \"r \\<in> redexes (Seq c\\<^sub>1 c\\<^sub>2)\" by fact\n  hence r: \"r = Seq c\\<^sub>1 c\\<^sub>2 \\<or> r \\<in> redexes c\\<^sub>1\"\n    by simp\n  have step_r: \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow> (r', s')\" by fact\n  from r show ?case\n  proof \n    assume \"r = Seq c\\<^sub>1 c\\<^sub>2\"\n    with step_r\n    show ?case\n      by (auto simp add: root_in_redexes)\n  next\n    assume r: \"r \\<in> redexes c\\<^sub>1\"\n    from Seq.hyps (1) [OF step_r this] \n    obtain c' where \n      step_c\\<^sub>1: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, s) \\<rightarrow> (c', s')\" and\n      r': \"r' \\<in> redexes c'\"\n      by blast\n    from step.Seq [OF step_c\\<^sub>1]\n    have \"\\<Gamma>\\<turnstile> (Seq c\\<^sub>1 c\\<^sub>2, s) \\<rightarrow> (Seq c' c\\<^sub>2, s')\".\n    with r'\n    show ?case\n      by auto\n  qed\nnext\n  case Cond \n  thus ?case \n    by (fastforce intro: step.intros elim: step_elim_cases simp add: root_in_redexes)\nnext\n  case While \n  thus ?case \n    by (fastforce intro: step.intros elim: step_elim_cases simp add: root_in_redexes)\nnext\n  case Call thus ?case \n    by (fastforce intro: step.intros elim: step_elim_cases simp add: root_in_redexes)\nnext\n  case DynCom thus ?case \n    by (fastforce intro: step.intros elim: step_elim_cases simp add: root_in_redexes)\nnext\n  case Guard thus ?case \n    by (fastforce intro: step.intros elim: step_elim_cases simp add: root_in_redexes)\nnext\n  case Throw thus ?case \n    by (fastforce intro: step.intros elim: step_elim_cases simp add: root_in_redexes)\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have \"r \\<in> redexes (Catch c\\<^sub>1 c\\<^sub>2)\" by fact\n  hence r: \"r = Catch c\\<^sub>1 c\\<^sub>2 \\<or> r \\<in> redexes c\\<^sub>1\"\n    by simp\n  have step_r: \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow> (r', s')\" by fact\n  from r show ?case\n  proof \n    assume \"r = Catch c\\<^sub>1 c\\<^sub>2\"\n    with step_r\n    show ?case\n      by (auto simp add: root_in_redexes)\n  next\n    assume r: \"r \\<in> redexes c\\<^sub>1\"\n    from Catch.hyps (1) [OF step_r this] \n    obtain c' where \n      step_c\\<^sub>1: \"\\<Gamma>\\<turnstile> (c\\<^sub>1, s) \\<rightarrow> (c', s')\" and\n      r': \"r' \\<in> redexes c'\"\n      by blast\n    from step.Catch [OF step_c\\<^sub>1]\n    have \"\\<Gamma>\\<turnstile> (Catch c\\<^sub>1 c\\<^sub>2, s) \\<rightarrow> (Catch c' c\\<^sub>2, s')\".\n    with r'\n    show ?case\n      by auto\n  qed\nnext case (Await b c)  \n     thus ?case \n     by (fastforce intro: step.intros elim: step_elim_cases simp add: root_in_redexes)\nqed \n\nlemma steps_redexes:\n  assumes steps: \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow>\\<^sup>* (r', s')\"\n  shows \"\\<And>c. r \\<in> redexes c \\<Longrightarrow> \\<exists>c'. \\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>* (c',s') \\<and> r' \\<in> redexes c'\"\nusing steps \nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl\n  then\n  show \"\\<exists>c'. \\<Gamma>\\<turnstile> (c, s') \\<rightarrow>\\<^sup>* (c', s') \\<and> r' \\<in> redexes c'\"\n    by auto\nnext\n  case (Trans r s r'' s'')\n  have \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow> (r'', s'')\" \"r \\<in> redexes c\" by fact+\n  from step_redexes [OF this]\n  obtain c' where\n    step: \"\\<Gamma>\\<turnstile> (c, s) \\<rightarrow> (c', s'')\" and\n    r'': \"r'' \\<in> redexes c'\"\n    by blast\n  note step\n  also\n  from Trans.hyps (3) [OF r'']\n  obtain c'' where\n    steps: \"\\<Gamma>\\<turnstile> (c', s'') \\<rightarrow>\\<^sup>* (c'', s')\" and\n    r': \"r' \\<in> redexes c''\"\n    by blast\n  note steps\n  finally\n  show ?case\n    using r'\n    by blast\nqed\n\n\n\nlemma steps_redexes':\n  assumes steps: \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow>\\<^sup>+ (r', s')\"\n  shows \"\\<And>c. r \\<in> redexes c \\<Longrightarrow> \\<exists>c'. \\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>+ (c',s') \\<and> r' \\<in> redexes c'\"\nusing steps \nproof (induct rule: tranclp_induct2 [consumes 1, case_names Step Trans])\n  case (Step r' s' c') \n  have \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow> (r', s')\" \"r \\<in> redexes c'\" by fact+\n  from step_redexes [OF this]\n  show ?case\n    by (blast intro: r_into_trancl)\nnext\n  case (Trans r' s' r'' s'')\n  from Trans obtain c' where\n    steps: \"\\<Gamma>\\<turnstile> (c, s) \\<rightarrow>\\<^sup>+ (c', s')\" and\n    r': \"r' \\<in> redexes c'\"\n    by blast\n  note steps\n  moreover\n  have \"\\<Gamma>\\<turnstile> (r', s') \\<rightarrow> (r'', s'')\" by fact\n  from step_redexes [OF this r'] obtain c'' where\n    step: \"\\<Gamma>\\<turnstile> (c', s') \\<rightarrow> (c'', s'')\" and\n    r'': \"r'' \\<in> redexes c''\"\n    by blast\n  note step\n  finally show ?case\n    using r'' by blast\nqed\n\nlemma step_redexes_Seq:\n  assumes step: \"\\<Gamma>\\<turnstile>(r,s) \\<rightarrow> (r',s')\"\n  assumes Seq: \"Seq r c\\<^sub>2 \\<in> redexes c\"\n  shows \"\\<exists>c'. \\<Gamma>\\<turnstile>(c,s) \\<rightarrow> (c',s') \\<and> Seq r' c\\<^sub>2 \\<in> redexes c'\"\nproof -\n  from step.Seq [OF step]\n  have \"\\<Gamma>\\<turnstile> (Seq r c\\<^sub>2, s) \\<rightarrow> (Seq r' c\\<^sub>2, s')\".\n  from step_redexes [OF this Seq] \n  show ?thesis .\nqed\n\nlemma steps_redexes_Seq:\n  assumes steps: \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow>\\<^sup>* (r', s')\"\n  shows \"\\<And>c. Seq r c\\<^sub>2 \\<in> redexes c \\<Longrightarrow> \n              \\<exists>c'. \\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>* (c',s') \\<and> Seq r' c\\<^sub>2 \\<in> redexes c'\"\nusing steps \nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl\n  then show ?case\n    by (auto)\n\nnext\n  case (Trans r s r'' s'')\n  have \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow> (r'', s'')\" \"Seq r c\\<^sub>2 \\<in> redexes c\" by fact+\n  from step_redexes_Seq [OF this]\n  obtain c' where\n    step: \"\\<Gamma>\\<turnstile> (c, s) \\<rightarrow> (c', s'')\" and\n    r'': \"Seq r'' c\\<^sub>2 \\<in> redexes c'\"\n    by blast\n  note step\n  also\n  from Trans.hyps (3) [OF r'']\n  obtain c'' where\n    steps: \"\\<Gamma>\\<turnstile> (c', s'') \\<rightarrow>\\<^sup>* (c'', s')\" and\n    r': \"Seq r' c\\<^sub>2 \\<in> redexes c''\"\n    by blast\n  note steps\n  finally\n  show ?case\n    using r'\n    by blast\nqed\n\nlemma steps_redexes_Seq':\n  assumes steps: \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow>\\<^sup>+ (r', s')\"\n  shows \"\\<And>c. Seq r c\\<^sub>2 \\<in> redexes c \n             \\<Longrightarrow> \\<exists>c'. \\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>+ (c',s') \\<and> Seq r' c\\<^sub>2 \\<in> redexes c'\"\nusing steps \nproof (induct rule: tranclp_induct2 [consumes 1, case_names Step Trans])\n  case (Step r' s' c') \n  have \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow> (r', s')\" \"Seq r c\\<^sub>2 \\<in> redexes c'\" by fact+\n  from step_redexes_Seq [OF this]\n  show ?case\n    by (blast intro: r_into_trancl)\nnext\n  case (Trans r' s' r'' s'')\n  from Trans obtain c' where\n    steps: \"\\<Gamma>\\<turnstile> (c, s) \\<rightarrow>\\<^sup>+ (c', s')\" and\n    r': \"Seq r' c\\<^sub>2 \\<in> redexes c'\"\n    by blast\n  note steps\n  moreover\n  have \"\\<Gamma>\\<turnstile> (r', s') \\<rightarrow> (r'', s'')\" by fact\n  from step_redexes_Seq [OF this r'] obtain c'' where\n    step: \"\\<Gamma>\\<turnstile> (c', s') \\<rightarrow> (c'', s'')\" and\n    r'': \"Seq r'' c\\<^sub>2 \\<in> redexes c''\"\n    by blast\n  note step\n  finally show ?case\n    using r'' by blast\nqed\n\nlemma step_redexes_Catch:\n  assumes step: \"\\<Gamma>\\<turnstile>(r,s) \\<rightarrow> (r',s')\"\n  assumes Catch: \"Catch r c\\<^sub>2 \\<in> redexes c\"\n  shows \"\\<exists>c'. \\<Gamma>\\<turnstile>(c,s) \\<rightarrow> (c',s') \\<and> Catch r' c\\<^sub>2 \\<in> redexes c'\"\nproof -\n  from step.Catch [OF step]\n  have \"\\<Gamma>\\<turnstile> (Catch r c\\<^sub>2, s) \\<rightarrow> (Catch r' c\\<^sub>2, s')\".\n  from step_redexes [OF this Catch] \n  show ?thesis .\nqed\n\nlemma steps_redexes_Catch:\n  assumes steps: \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow>\\<^sup>* (r', s')\"\n  shows \"\\<And>c. Catch r c\\<^sub>2 \\<in> redexes c \\<Longrightarrow> \n              \\<exists>c'. \\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>* (c',s') \\<and> Catch r' c\\<^sub>2 \\<in> redexes c'\"\nusing steps \nproof (induct rule: converse_rtranclp_induct2 [case_names Refl Trans])\n  case Refl\n  then show ?case\n    by (auto)\n\nnext\n  case (Trans r s r'' s'')\n  have \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow> (r'', s'')\" \"Catch r c\\<^sub>2 \\<in> redexes c\" by fact+\n  from step_redexes_Catch [OF this]\n  obtain c' where\n    step: \"\\<Gamma>\\<turnstile> (c, s) \\<rightarrow> (c', s'')\" and\n    r'': \"Catch r'' c\\<^sub>2 \\<in> redexes c'\"\n    by blast\n  note step\n  also\n  from Trans.hyps (3) [OF r'']\n  obtain c'' where\n    steps: \"\\<Gamma>\\<turnstile> (c', s'') \\<rightarrow>\\<^sup>* (c'', s')\" and\n    r': \"Catch r' c\\<^sub>2 \\<in> redexes c''\"\n    by blast\n  note steps\n  finally\n  show ?case\n    using r'\n    by blast\nqed\n\nlemma steps_redexes_Catch':\n  assumes steps: \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow>\\<^sup>+ (r', s')\"\n  shows \"\\<And>c. Catch r c\\<^sub>2 \\<in> redexes c \n             \\<Longrightarrow> \\<exists>c'. \\<Gamma>\\<turnstile>(c,s) \\<rightarrow>\\<^sup>+ (c',s') \\<and> Catch r' c\\<^sub>2 \\<in> redexes c'\"\nusing steps \nproof (induct rule: tranclp_induct2 [consumes 1, case_names Step Trans])\n  case (Step r' s' c') \n  have \"\\<Gamma>\\<turnstile> (r, s) \\<rightarrow> (r', s')\" \"Catch r c\\<^sub>2 \\<in> redexes c'\" by fact+\n  from step_redexes_Catch [OF this]\n  show ?case\n    by (blast intro: r_into_trancl)\nnext\n  case (Trans r' s' r'' s'')\n  from Trans obtain c' where\n    steps: \"\\<Gamma>\\<turnstile> (c, s) \\<rightarrow>\\<^sup>+ (c', s')\" and\n    r': \"Catch r' c\\<^sub>2 \\<in> redexes c'\"\n    by blast\n  note steps\n  moreover\n  have \"\\<Gamma>\\<turnstile> (r', s') \\<rightarrow> (r'', s'')\" by fact\n  from step_redexes_Catch [OF this r'] obtain c'' where\n    step: \"\\<Gamma>\\<turnstile> (c', s') \\<rightarrow> (c'', s'')\" and\n    r'': \"Catch r'' c\\<^sub>2 \\<in> redexes c''\"\n    by blast\n  note step\n  finally show ?case\n    using r'' by blast\nqed\n\nlemma redexes_subset:\"\\<And>c'. c' \\<in> redexes c \\<Longrightarrow> redexes c' \\<subseteq> redexes c\"\n  by (induct c) auto\n\nlemma redexes_preserves_termination:\n  assumes termi: \"\\<Gamma>\\<turnstile>c\\<down>s\"\n  shows \"\\<And>c'. c' \\<in> redexes c \\<Longrightarrow> \\<Gamma>\\<turnstile>c'\\<down>s\"  \nusing termi\nby induct (auto intro: terminates.intros)\n\n*)\nend", "meta": {"author": "CompSoftVer", "repo": "CSim2", "sha": "b09a4d77ea089168b1805db5204ac151df2b9eff", "save_path": "github-repos/isabelle/CompSoftVer-CSim2", "path": "github-repos/isabelle/CompSoftVer-CSim2/CSim2-b09a4d77ea089168b1805db5204ac151df2b9eff/ConCSimpl/SmallStepCon-david-ThinkPad-X1-Carbon-5th.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6001883592602049, "lm_q2_score": 0.4225046348141882, "lm_q1q2_score": 0.25358236354895963}}
{"text": "(* \n   Title: The pi-calculus   \n   Author/Maintainer: Jesper Bengtson (jebe.dk), 2012\n*)\ntheory Weak_Late_Cong_Subst_Pres\n  imports Weak_Late_Cong_Subst Weak_Late_Cong_Pres\nbegin\n\nlemma tauPres:\n  fixes P :: pi\n  and   Q :: pi\n  \n  assumes \"P \\<simeq>\\<^sup>s Q\"\n\n  shows \"\\<tau>.(P) \\<simeq>\\<^sup>s \\<tau>.(Q)\"\nusing assms\nby(force simp add: substClosed_def Weak_Late_Cong_Pres.tauPres)\n\nlemma inputPres:\n  fixes P :: pi\n  and   Q :: pi\n  and   a :: name\n  and   x :: name\n\n  assumes PeqQ: \"P \\<simeq>\\<^sup>s Q\"\n\n  shows \"a<x>.P \\<simeq>\\<^sup>s a<x>.Q\"\nproof(auto simp add: substClosed_def)\n  fix \\<sigma> :: \"(name \\<times> name) list\"\n  {\n    fix P Q a x \\<sigma>\n    assume \"P \\<simeq>\\<^sup>s Q\"\n    then have \"P[<\\<sigma>>] \\<simeq>\\<^sup>s Q[<\\<sigma>>]\" by(rule partUnfold)\n    then have \"\\<forall>y. (P[<\\<sigma>>])[x::=y] \\<simeq> (Q[<\\<sigma>>])[x::=y]\"\n      apply(auto simp add: substClosed_def)\n      by(erule_tac x=\"[(x, y)]\" in allE) auto\n    moreover assume \"x \\<sharp> \\<sigma>\"\n    ultimately have \"(a<x>.P)[<\\<sigma>>] \\<simeq> (a<x>.Q)[<\\<sigma>>]\" using weakBisimEqvt\n      by(force intro: Weak_Late_Cong_Pres.inputPres)\n  }\n  note Goal = this\n\n  obtain y::name where \"y \\<sharp> P\" and \"y \\<sharp> Q\" and \"y \\<sharp> \\<sigma>\"\n    by(generate_fresh \"name\") auto\n  from \\<open>P \\<simeq>\\<^sup>s Q\\<close> have \"([(x, y)] \\<bullet> P) \\<simeq>\\<^sup>s ([(x, y)] \\<bullet> Q)\" by(rule eqvtI)\n  hence \"(a<y>.([(x, y)] \\<bullet> P))[<\\<sigma>>] \\<simeq> (a<y>.([(x, y)] \\<bullet> Q))[<\\<sigma>>]\" using \\<open>y \\<sharp> \\<sigma>\\<close> by(rule Goal)\n  moreover from \\<open>y \\<sharp> P\\<close> \\<open>y \\<sharp> Q\\<close> have \"a<x>.P = a<y>.([(x, y)] \\<bullet> P)\" and \"a<x>.Q = a<y>.([(x, y)] \\<bullet> Q)\"\n    by(simp add: pi.alphaInput)+\n\n  ultimately show \"(a<x>.P)[<\\<sigma>>] \\<simeq> (a<x>.Q)[<\\<sigma>>]\" by simp\nqed\n\nlemma outputPres:\n  fixes P :: pi\n  and   Q :: pi\n  \n  assumes \"P \\<simeq>\\<^sup>s Q\"\n\n  shows \"a{b}.P \\<simeq>\\<^sup>s a{b}.Q\"\nusing assms\nby(force simp add: substClosed_def Weak_Late_Cong_Pres.outputPres)\n\n\n\n  assumes \"P \\<simeq>\\<^sup>s Q\"\n\n  shows \"[a\\<frown>b]P \\<simeq>\\<^sup>s [a\\<frown>b]Q\"\nusing assms\nby(force simp add: substClosed_def Weak_Late_Cong_Pres.matchPres)\n\nlemma sumPres:\n  fixes P :: pi\n  and   Q :: pi\n  and   R :: pi\n\n  assumes \"P \\<simeq>\\<^sup>s Q\"\n\n  shows \"P \\<oplus> R \\<simeq>\\<^sup>s Q \\<oplus> R\"\nusing assms\nby(force simp add: substClosed_def Weak_Late_Cong_Pres.sumPres)\n\nlemma parPres:\n  fixes P :: pi\n  and   Q :: pi\n  and   R :: pi\n\n  assumes \"P \\<simeq>\\<^sup>s Q\"\n\n  shows \"P \\<parallel> R \\<simeq>\\<^sup>s Q \\<parallel> R\"\nusing assms\nby(force simp add: substClosed_def Weak_Late_Cong_Pres.parPres)\n\n\n\n  assumes PeqQ: \"P \\<simeq>\\<^sup>s Q\"\n  \n  shows \"<\\<nu>x>P \\<simeq>\\<^sup>s <\\<nu>x>Q\"\nproof(auto simp add: substClosed_def)\n  fix s::\"(name \\<times> name) list\"\n\n  have Goal: \"\\<And>P Q x s. \\<lbrakk>P[<s>] \\<leadsto><weakBisim> Q[<s>]; x \\<sharp> s\\<rbrakk> \\<Longrightarrow> (<\\<nu>x>P)[<s>] \\<leadsto><weakBisim> (<\\<nu>x>Q)[<s>]\"\n    by(force intro: Weak_Late_Step_Sim_Pres.resPres Weak_Late_Bisim_Pres.resPres Weak_Late_Bisim.eqvt)\n  \n  have \"\\<exists>c::name. c \\<sharp> (P, Q, s)\"  by(blast intro: name_exists_fresh)\n  then obtain c::name where cFreshP: \"c \\<sharp> P\" and cFreshQ: \"c \\<sharp> Q\" and cFreshs: \"c \\<sharp> s\"\n    by(force simp add: fresh_prod)\n\n  from PeqQ have \"P[<([(x, c)] \\<bullet> s)>] \\<leadsto><weakBisim> Q[<([(x, c)] \\<bullet> s)>]\" and \n                 \"Q[<([(x, c)] \\<bullet> s)>] \\<leadsto><weakBisim> P[<([(x, c)] \\<bullet> s)>]\"\n    by(force simp add: congruenceSubstDef)+\n\n  hence \"([(x, c)] \\<bullet> (P[<([(x, c)] \\<bullet> s)>])) \\<leadsto><weakBisim> ([(x, c)] \\<bullet> (Q[<([(x, c)] \\<bullet> s)>]))\" and \n        \"([(x, c)] \\<bullet> (Q[<([(x, c)] \\<bullet> s)>])) \\<leadsto><weakBisim> ([(x, c)] \\<bullet> (P[<([(x, c)] \\<bullet> s)>]))\"\n    by(blast intro: Weak_Late_Step_Sim.eqvtI Weak_Late_Bisim.eqvt)+\n\n  hence \"([(x, c)] \\<bullet> P)[<s>] \\<leadsto><weakBisim> ([(x, c)] \\<bullet> Q)[<s>]\" and\n        \"([(x, c)] \\<bullet> Q)[<s>] \\<leadsto><weakBisim> ([(x, c)] \\<bullet> P)[<s>]\" by simp+\n\n  with cFreshs have \"(<\\<nu>c>([(x, c)] \\<bullet> P))[<s>] \\<leadsto><weakBisim> (<\\<nu>c>([(x, c)] \\<bullet> Q))[<s>]\" and\n                    \"(<\\<nu>c>([(x, c)] \\<bullet> Q))[<s>] \\<leadsto><weakBisim> (<\\<nu>c>([(x, c)] \\<bullet> P))[<s>]\"\n    by(blast intro: Goal)+\n\n  moreover from cFreshP cFreshQ have \"<\\<nu>x>P = <\\<nu>c>([(x, c)] \\<bullet> P)\" and \"<\\<nu>x>Q = <\\<nu>c>([(x, c)] \\<bullet> Q)\"\n    by(simp add: alphaRes)+\n\n  ultimately show \"(<\\<nu>x>P)[<s>] \\<simeq> (<\\<nu>x>Q)[<s>]\"\n    by(simp add: congruence_def)\nqed\n\nlemma congruenceBang:\n  fixes P :: pi\n  and   Q :: pi\n  \n  assumes \"P \\<simeq>\\<^sup>s Q\"\n\n  shows \"!P \\<simeq>\\<^sup>s !Q\"\nusing assms\nby(force simp add: substClosed_def intro: Weak_Late_Cong_Pres.congruenceBang)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Pi_Calculus/Weak_Late_Cong_Subst_Pres.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.523420348936324, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.25353439273006523}}
{"text": "(*  Title:      HOL/Auth/n_germanSimp_lemma_on_inv__34.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_germanSimp Protocol Case Study*} \n\ntheory n_germanSimp_lemma_on_inv__34 imports n_germanSimp_base\nbegin\nsection{*All lemmas on causal relation between inv__34 and some rule r*}\nlemma n_RecvReqSVsinv__34:\nassumes a1: \"(\\<exists> i. i\\<le>N\\<and>r=n_RecvReqS N i)\" and\na2: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\<or> ?P2 s \\<or> ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\<le>N\\<and>r=n_RecvReqS N i\" apply fastforce done\nfrom a2 obtain p__Inv4 where a2:\"p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\<or>(i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n  assume b1: \"(i=p__Inv4)\"\n  have \"?P1 s\"\n  proof(cut_tac a1 a2 b1, auto) qed\n  then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n  assume b1: \"(i~=p__Inv4)\"\n  have \"?P1 s\"\n  proof(cut_tac a1 a2 b1, auto) qed\n  then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_RecvReqE__part__0Vsinv__34:\nassumes a1: \"(\\<exists> i. i\\<le>N\\<and>r=n_RecvReqE__part__0 N i)\" and\na2: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\<or> ?P2 s \\<or> ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\<le>N\\<and>r=n_RecvReqE__part__0 N i\" apply fastforce done\nfrom a2 obtain p__Inv4 where a2:\"p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\<or>(i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n  assume b1: \"(i=p__Inv4)\"\n  have \"?P1 s\"\n  proof(cut_tac a1 a2 b1, auto) qed\n  then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n  assume b1: \"(i~=p__Inv4)\"\n  have \"?P1 s\"\n  proof(cut_tac a1 a2 b1, auto) qed\n  then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_RecvReqE__part__1Vsinv__34:\nassumes a1: \"(\\<exists> i. i\\<le>N\\<and>r=n_RecvReqE__part__1 N i)\" and\na2: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\<or> ?P2 s \\<or> ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\<le>N\\<and>r=n_RecvReqE__part__1 N i\" apply fastforce done\nfrom a2 obtain p__Inv4 where a2:\"p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\<or>(i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n  assume b1: \"(i=p__Inv4)\"\n  have \"?P1 s\"\n  proof(cut_tac a1 a2 b1, auto) qed\n  then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n  assume b1: \"(i~=p__Inv4)\"\n  have \"?P1 s\"\n  proof(cut_tac a1 a2 b1, auto) qed\n  then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_SendInv__part__0Vsinv__34:\nassumes a1: \"(\\<exists> i. i\\<le>N\\<and>r=n_SendInv__part__0  i)\" and\na2: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\<or> ?P2 s \\<or> ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\<le>N\\<and>r=n_SendInv__part__0  i\" apply fastforce done\nfrom a2 obtain p__Inv4 where a2:\"p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\<or>(i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n  assume b1: \"(i=p__Inv4)\"\n  have \"?P1 s\"\n  proof(cut_tac a1 a2 b1, auto) qed\n  then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n  assume b1: \"(i~=p__Inv4)\"\n  have \"?P2 s\"\n  proof(cut_tac a1 a2 b1, auto) qed\n  then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_SendInv__part__1Vsinv__34:\nassumes a1: \"(\\<exists> i. i\\<le>N\\<and>r=n_SendInv__part__1  i)\" and\na2: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\<or> ?P2 s \\<or> ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\<le>N\\<and>r=n_SendInv__part__1  i\" apply fastforce done\nfrom a2 obtain p__Inv4 where a2:\"p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\<or>(i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n  assume b1: \"(i=p__Inv4)\"\n  have \"?P1 s\"\n  proof(cut_tac a1 a2 b1, auto) qed\n  then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n  assume b1: \"(i~=p__Inv4)\"\n  have \"?P2 s\"\n  proof(cut_tac a1 a2 b1, auto) qed\n  then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_SendInvAckVsinv__34:\nassumes a1: \"(\\<exists> i. i\\<le>N\\<and>r=n_SendInvAck  i)\" and\na2: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\<or> ?P2 s \\<or> ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\<le>N\\<and>r=n_SendInvAck  i\" apply fastforce done\nfrom a2 obtain p__Inv4 where a2:\"p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\<or>(i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n  assume b1: \"(i=p__Inv4)\"\n  have \"?P3 s\"\n  apply (cut_tac a1 a2 b1, simp, rule_tac x=\"(neg (andForm (eqn (IVar (Ident ''CurCmd'')) (Const Empty)) (eqn (IVar (Field (Para (Ident ''Chan2'') p__Inv4) ''Cmd'')) (Const Inv))))\" in exI, auto) done\n  then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n  assume b1: \"(i~=p__Inv4)\"\n  have \"?P2 s\"\n  proof(cut_tac a1 a2 b1, auto) qed\n  then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_RecvInvAckVsinv__34:\nassumes a1: \"(\\<exists> i. i\\<le>N\\<and>r=n_RecvInvAck  i)\" and\na2: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\<or> ?P2 s \\<or> ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\<le>N\\<and>r=n_RecvInvAck  i\" apply fastforce done\nfrom a2 obtain p__Inv4 where a2:\"p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\<or>(i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n  assume b1: \"(i=p__Inv4)\"\n  have \"((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\\<or>((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))\" by auto\n  moreover {\n    assume c1: \"((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\"\n    have \"?P1 s\"\n    proof(cut_tac a1 a2 b1 c1, auto) qed\n    then have \"invHoldForRule s f r (invariants N)\" by auto\n  }\n  moreover {\n    assume c1: \"((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))\"\n    have \"?P1 s\"\n    proof(cut_tac a1 a2 b1 c1, auto) qed\n    then have \"invHoldForRule s f r (invariants N)\" by auto\n  }\n  ultimately have \"invHoldForRule s f r (invariants N)\" by satx\n}\nmoreover {\n  assume b1: \"(i~=p__Inv4)\"\n  have \"((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\\<or>((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))\" by auto\n  moreover {\n    assume c1: \"((formEval (eqn (IVar (Ident ''ExGntd'')) (Const true)) s))\"\n    have \"?P1 s\"\n    proof(cut_tac a1 a2 b1 c1, auto) qed\n    then have \"invHoldForRule s f r (invariants N)\" by auto\n  }\n  moreover {\n    assume c1: \"((formEval (neg (eqn (IVar (Ident ''ExGntd'')) (Const true))) s))\"\n    have \"?P2 s\"\n    proof(cut_tac a1 a2 b1 c1, auto) qed\n    then have \"invHoldForRule s f r (invariants N)\" by auto\n  }\n  ultimately have \"invHoldForRule s f r (invariants N)\" by satx\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_SendGntSVsinv__34:\nassumes a1: \"(\\<exists> i. i\\<le>N\\<and>r=n_SendGntS  i)\" and\na2: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\<or> ?P2 s \\<or> ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\<le>N\\<and>r=n_SendGntS  i\" apply fastforce done\nfrom a2 obtain p__Inv4 where a2:\"p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\<or>(i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n  assume b1: \"(i=p__Inv4)\"\n  have \"?P1 s\"\n  proof(cut_tac a1 a2 b1, auto) qed\n  then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n  assume b1: \"(i~=p__Inv4)\"\n  have \"?P1 s\"\n  proof(cut_tac a1 a2 b1, auto) qed\n  then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_SendGntEVsinv__34:\nassumes a1: \"(\\<exists> i. i\\<le>N\\<and>r=n_SendGntE N i)\" and\na2: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\<or> ?P2 s \\<or> ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\<le>N\\<and>r=n_SendGntE N i\" apply fastforce done\nfrom a2 obtain p__Inv4 where a2:\"p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\<or>(i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n  assume b1: \"(i=p__Inv4)\"\n  have \"?P1 s\"\n  proof(cut_tac a1 a2 b1, auto) qed\n  then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n  assume b1: \"(i~=p__Inv4)\"\n  have \"?P1 s\"\n  proof(cut_tac a1 a2 b1, auto) qed\n  then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_RecvGntSVsinv__34:\nassumes a1: \"(\\<exists> i. i\\<le>N\\<and>r=n_RecvGntS  i)\" and\na2: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\<or> ?P2 s \\<or> ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\<le>N\\<and>r=n_RecvGntS  i\" apply fastforce done\nfrom a2 obtain p__Inv4 where a2:\"p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\<or>(i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n  assume b1: \"(i=p__Inv4)\"\n  have \"?P3 s\"\n  apply (cut_tac a1 a2 b1, simp, rule_tac x=\"(neg (andForm (eqn (IVar (Ident ''ExGntd'')) (Const true)) (eqn (IVar (Field (Para (Ident ''Chan2'') p__Inv4) ''Cmd'')) (Const GntS))))\" in exI, auto) done\n  then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n  assume b1: \"(i~=p__Inv4)\"\n  have \"?P2 s\"\n  proof(cut_tac a1 a2 b1, auto) qed\n  then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_RecvGntEVsinv__34:\nassumes a1: \"(\\<exists> i. i\\<le>N\\<and>r=n_RecvGntE  i)\" and\na2: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4)\"\nshows \"invHoldForRule s f r (invariants N)\" (is \"?P1 s \\<or> ?P2 s \\<or> ?P3 s\")\nproof -\nfrom a1 obtain i where a1:\"i\\<le>N\\<and>r=n_RecvGntE  i\" apply fastforce done\nfrom a2 obtain p__Inv4 where a2:\"p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4\" apply fastforce done\nhave \"(i=p__Inv4)\\<or>(i~=p__Inv4)\" apply (cut_tac a1 a2, auto) done\nmoreover {\n  assume b1: \"(i=p__Inv4)\"\n  have \"?P1 s\"\n  proof(cut_tac a1 a2 b1, auto) qed\n  then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nmoreover {\n  assume b1: \"(i~=p__Inv4)\"\n  have \"?P2 s\"\n  proof(cut_tac a1 a2 b1, auto) qed\n  then have \"invHoldForRule s f r (invariants N)\" by auto\n}\nultimately show \"invHoldForRule s f r (invariants N)\" by satx\nqed\n\nlemma n_StoreVsinv__34:\n  assumes a1: \"\\<exists> i d. i\\<le>N\\<and>d\\<le>N\\<and>r=n_Store  i d\" and\n  a2: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__34  p__Inv4)\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  apply (rule noEffectOnRule, cut_tac a1 a2, auto) done\n  \nend\n", "meta": {"author": "lyj238Gmail", "repo": "newParaVerifier", "sha": "5c2d49bf8e6c46c60efa53c98b0ba5c577d59618", "save_path": "github-repos/isabelle/lyj238Gmail-newParaVerifier", "path": "github-repos/isabelle/lyj238Gmail-newParaVerifier/newParaVerifier-5c2d49bf8e6c46c60efa53c98b0ba5c577d59618/examples/n_germanSimp/n_germanSimp_lemma_on_inv__34.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.25337826650444567}}
{"text": "subsection \\<open>Formulation of a subject-subject communication policy and an information flow \npolicy, and showing both can be derived from subject-object configuration data\\<close>\n\ntheory Step_policies\n  imports Step_configuration\nbegin\n\nsubsubsection \\<open>Specification\\label{sect:policy_specification}\\<close>\n\ntext \\<open>In order to use CISK, we need an information flow policy @{term ifp}\n  relation. \n  We also express a static subject-subject @{term sp_spec_subj_obj} and subject-object @{term sp_spec_subj_subj} access control policy\n  for the implementation of the model. The following locale summarizes\n  all properties we need.\\<close>\n\nlocale policy_axioms =\n  fixes sp_spec_subj_obj :: \"'a \\<Rightarrow> obj_id_t \\<Rightarrow> mode_t \\<Rightarrow> bool\"\n    and sp_spec_subj_subj :: \"'a \\<Rightarrow> 'a \\<Rightarrow> bool\"\n    and ifp :: \"'a \\<Rightarrow> 'a \\<Rightarrow> bool\"\n\n  assumes sp_spec_file_provider: \"\\<forall> p1 p2 f m1 m2 .\n     sp_spec_subj_obj p1 (FILEP f) m1 \\<and>\n     sp_spec_subj_obj p2 (FILEP f) m2 \\<longrightarrow> sp_spec_subj_subj p1 p2\"\n\n  and sp_spec_no_wronly_pages:\n    \"\\<forall> p x . sp_spec_subj_obj p (PAGE x) WRITE \\<longrightarrow> sp_spec_subj_obj p (PAGE x) READ\"\n\n  and ifp_reflexive:\n    \"\\<forall> p . ifp p p\"\n\n  and ifp_compatible_with_sp_spec:\n    \"\\<forall> a b . sp_spec_subj_subj a b \\<longrightarrow> ifp a b \\<and> ifp b a\"\n\n  and ifp_compatible_with_ipc:\n    \"\\<forall> a b c x . (sp_spec_subj_subj a b\n                  \\<and> sp_spec_subj_obj b (PAGE x) WRITE  \\<and> sp_spec_subj_obj c (PAGE x) READ)\n                 \\<longrightarrow> ifp a c\"\nbegin (* empty *) end\n\nsubsubsection \\<open>Derivation\\<close>\n\ntext \\<open>The configuration data only consists of a subject-object policy. \nWe derive the subject-subject policy and the information flow policy from the configuration data and prove that properties we specified in Section~\\ref{sect:policy_specification} are satisfied.\\<close>\n\nlocale abstract_policy_derivation =\n  fixes configuration_subj_obj :: \"'a \\<Rightarrow> obj_id_t \\<Rightarrow> mode_t \\<Rightarrow> bool\"\nbegin\n\n  definition \"sp_spec_subj_obj a x m \\<equiv>\n    configuration_subj_obj a x m \\<or> (\\<exists> y . x = PAGE y \\<and> m = READ \\<and> configuration_subj_obj a x WRITE)\"\n\n  definition \"sp_spec_subj_subj a b \\<equiv>\n    \\<exists> f m1 m2 . sp_spec_subj_obj a (FILEP f) m1 \\<and> sp_spec_subj_obj b (FILEP f) m2\"\n\n  definition \"ifp a b \\<equiv>\n     sp_spec_subj_subj a b\n   \\<or> sp_spec_subj_subj b a\n   \\<or> (\\<exists> c y . sp_spec_subj_subj a c\n            \\<and> sp_spec_subj_obj c (PAGE y) WRITE\n            \\<and> sp_spec_subj_obj b (PAGE y) READ)\n   \\<or> (a = b)\"\n\ntext \\<open>Show that the policies specified in Section~\\ref{sect:policy_specification} can be derived from the configuration and their definitions.\\<close>\n\n  lemma correct:\n    shows \"policy_axioms sp_spec_subj_obj sp_spec_subj_subj ifp\"\n  proof (unfold_locales)\n    show sp_spec_file_provider:\n      \"\\<forall> p1 p2 f m1 m2 .\n           sp_spec_subj_obj p1 (FILEP f) m1 \\<and>\n           sp_spec_subj_obj p2 (FILEP f) m2 \\<longrightarrow> sp_spec_subj_subj p1 p2\"\n      unfolding sp_spec_subj_subj_def by auto\n    show sp_spec_no_wronly_pages:\n      \"\\<forall> p x . sp_spec_subj_obj p (PAGE x) WRITE \\<longrightarrow> sp_spec_subj_obj p (PAGE x) READ\"\n      unfolding sp_spec_subj_obj_def by auto\n    show ifp_reflexive:\n      \"\\<forall> p . ifp p p\"\n      unfolding ifp_def by auto\n    show ifp_compatible_with_sp_spec:\n      \"\\<forall> a b . sp_spec_subj_subj a b \\<longrightarrow> ifp a b \\<and> ifp b a\"\n      unfolding ifp_def by auto\n    show ifp_compatible_with_ipc:\n      \"\\<forall> a b c x . (sp_spec_subj_subj a b\n                  \\<and> sp_spec_subj_obj b (PAGE x) WRITE  \\<and> sp_spec_subj_obj c (PAGE x) READ)\n                 \\<longrightarrow> ifp a c\"\n      unfolding ifp_def by auto\n  qed\nend\n\ntype_synonym sp_subj_subj_t = \"partition_id_t \\<Rightarrow> partition_id_t \\<Rightarrow> bool\"\ntype_synonym sp_subj_obj_t = \"partition_id_t \\<Rightarrow> obj_id_t \\<Rightarrow> mode_t \\<Rightarrow> bool\"\n\ninterpretation Policy: abstract_policy_derivation \"configured_subj_obj\".\ninterpretation Policy_properties: policy_axioms Policy.sp_spec_subj_obj Policy.sp_spec_subj_subj Policy.ifp\n  using Policy.correct by auto\n\nlemma example_how_to_use_properties_in_proofs:\n  shows \"\\<forall> p . Policy.ifp p p\"\n  using Policy_properties.ifp_reflexive by auto\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/CISC-Kernel/step/Step_policies.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.25337826650444567}}
{"text": "(*\n    Author:      David Sanan\n    Maintainer:  David Sanan, sanan at ntu edu sg\n    License:     LGPL\n*)\n\n(*  Title:      XVCGCon.thy\n    Author:     David Sanan, NTU\n\nCopyright (C) 2015-2016 David Sanan \nSome rights reserved, NTU\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\ntheory XVcgCon \nimports VcgSeq\n\nbegin\n\n\ntext {* We introduce a syntactic variant of the let-expression so that we can\nsafely unfold it during verification condition generation. With the new\ntheorem attribute @{text \"vcg_simp\"} we can declare equalities to be used\nby the verification condition generator, while simplifying assertions.\n*}\n\nsyntax\n\"_Let'\" :: \"[letbinds, basicblock] => basicblock\"  (\"(LET (_)/ IN (_))\" 23)\n \ntranslations\n  \"_Let' (_binds b bs) e\"  == \"_Let' b (_Let' bs e)\"\n  \"_Let' (_bind x a) e\"    == \"CONST Let' a (%x. e)\"\n\n\nlemma Let'_unfold : \"Let' x f = f x\"\n  by (simp add: Let'_def Let_def)\n  \nlemma Let'_split_conv: \n  \"(Let' x  (\\<lambda>p. (case_prod (f p) (g p)))) = \n   (Let' x  (\\<lambda>p. (f p) (fst (g p)) (snd (g p))))\"\n  by (simp add: split_def)\n\nend\n", "meta": {"author": "CompSoftVer", "repo": "CSim2", "sha": "b09a4d77ea089168b1805db5204ac151df2b9eff", "save_path": "github-repos/isabelle/CompSoftVer-CSim2", "path": "github-repos/isabelle/CompSoftVer-CSim2/CSim2-b09a4d77ea089168b1805db5204ac151df2b9eff/ConCSimpl/XVcgCon.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736783928749126, "lm_q2_score": 0.44167300566462553, "lm_q1q2_score": 0.2533782600659146}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\n(* Automatic instantiation of an AutoCorres C state space as a separation algebra.\n   FIXME: this is not quite finished. There are some proof tactics missing (see getter_rewrite etc)\n*)\ntheory Auto_Separation_Algebra\nimports \"AutoCorres\" \"Sep_Algebra.Separation_Algebra\"\nkeywords \"sep_instance\" :: thy_goal\nbegin\n\n\nlemmas sep_conj_def = Separation_Algebra.sep_algebra_class.sep_conj_def\n\ninstantiation \"unit\" ::  stronger_sep_algebra\n   begin\n       definition \"zero_unit \\<equiv> ()\"\n       definition \"plus_unit  \\<equiv> (\\<lambda>h2 h2.  ()) :: unit \\<Rightarrow> unit \\<Rightarrow> unit\"\n       definition \"sep_disj_unit \\<equiv>(\\<lambda>h1 h2. True) :: unit \\<Rightarrow> unit \\<Rightarrow> bool\"\n     instance\n apply (standard)\n   apply (clarsimp simp: zero_unit_def plus_unit_def sep_disj_unit_def)+\n done\nend\n\ninstantiation \"bool\" ::  stronger_sep_algebra\n   begin\n       definition \"zero_bool \\<equiv> False\"\n       definition \"plus_bool  \\<equiv> (\\<or>)\"\n       definition \"sep_disj_bool \\<equiv> \\<lambda>p q. p \\<longrightarrow> \\<not>q\"\n     instance\n apply (standard)\n   apply (auto simp: zero_bool_def plus_bool_def sep_disj_bool_def)+\n done\nend\n\n instantiation \"fun\" :: (type,stronger_sep_algebra) stronger_sep_algebra\n begin\n  definition \"zero_fun   \\<equiv> (\\<lambda>x. 0)\"\n  definition \"plus_fun f f'  \\<equiv> (\\<lambda>x. if f x = 0 then f' x else f x)\"\n  definition \"sep_disj_fun   \\<equiv> (\\<lambda>f f'.  \\<forall>x. (f x = 0 \\<or> f' x = 0)) :: ('a \\<Rightarrow> 'b) \\<Rightarrow> ('a \\<Rightarrow> 'b) \\<Rightarrow> bool \"\n instance\n  apply standard\n       apply (fastforce simp: zero_fun_def sep_disj_fun_def plus_fun_def)+\n  apply (clarsimp simp: zero_fun_def sep_disj_fun_def plus_fun_def, safe)\n     apply (fastforce)+\n  done\nend\n\n\nML \\<open>\ntype sep_info =\n{\n  plus_thm : thm option,\n  disj_thm : thm option,\n  zero_thm : thm option,\n  sep_thms : thm list,\n  sep_heap_arrows : (term * thm) Typtab.table,\n  sep_heap_getters : (term * thm) Typtab.table,\n  sep_heap_setters : (term * thm) Typtab.table\n}\n\nfun mk_sep_info (plus_thm : thm option) (disj_thm : thm option) (zero_thm : thm option)\n  (sep_heap_arrows : (term * thm) Typtab.table) (sep_heap_getters :  (term * thm) Typtab.table)\n  ( sep_heap_setters : (term * thm) Typtab.table) (sep_thms : thm list) =\n  {plus_thm = plus_thm,\n   disj_thm = disj_thm,\n   zero_thm = zero_thm,\n   sep_thms = sep_thms,\n   sep_heap_arrows = sep_heap_arrows,\n   sep_heap_getters = sep_heap_getters,\n   sep_heap_setters = sep_heap_setters}\n\\<close>\n\nML \\<open>\n\nfun upd_plus_thm (sep_info : sep_info) plus =\n  {plus_thm = plus,\n   disj_thm = #disj_thm sep_info,\n   zero_thm = #zero_thm sep_info,\n   sep_thms = #sep_thms sep_info,\n   sep_heap_arrows = #sep_heap_arrows sep_info,\n   sep_heap_getters = #sep_heap_getters sep_info,\n   sep_heap_setters = #sep_heap_setters sep_info}\n\nfun upd_disj_thm (sep_info : sep_info) disj =\n  {plus_thm = #plus_thm sep_info,\n   disj_thm = disj,\n   zero_thm = #zero_thm sep_info,\n   sep_thms = #sep_thms sep_info,\n   sep_heap_arrows = #sep_heap_arrows sep_info,\n   sep_heap_getters = #sep_heap_getters sep_info,\n   sep_heap_setters = #sep_heap_setters sep_info}\n\nfun upd_zero_thm (sep_info : sep_info) zero =\n  {plus_thm = #plus_thm sep_info,\n   disj_thm = #disj_thm sep_info,\n   zero_thm = zero,\n   sep_thms = #sep_thms sep_info,\n   sep_heap_arrows = #sep_heap_arrows sep_info,\n   sep_heap_getters = #sep_heap_getters sep_info,\n   sep_heap_setters = #sep_heap_setters sep_info}\n\nfun upd_heap_arrows (sep_info : sep_info) arr =\n  {plus_thm = #plus_thm sep_info,\n   disj_thm = #disj_thm sep_info,\n   zero_thm = #zero_thm sep_info,\n   sep_heap_arrows = arr,\n   sep_thms = #sep_thms sep_info,\n   sep_heap_getters = #sep_heap_getters sep_info,\n   sep_heap_setters = #sep_heap_setters sep_info}\n\nfun upd_heap_getters (sep_info : sep_info) getters =\n  {plus_thm = #plus_thm sep_info,\n   disj_thm = #disj_thm sep_info,\n   zero_thm = #zero_thm sep_info,\n   sep_heap_arrows = #sep_heap_arrows sep_info,\n   sep_heap_getters = getters,\n   sep_thms = #sep_thms sep_info,\n   sep_heap_setters = #sep_heap_setters sep_info}\n\nfun upd_heap_setters (sep_info : sep_info) setters =\n  {plus_thm = #plus_thm sep_info,\n   disj_thm = #disj_thm sep_info,\n   zero_thm = #zero_thm sep_info,\n   sep_thms = #sep_thms sep_info,\n   sep_heap_arrows = #sep_heap_arrows sep_info,\n   sep_heap_getters = #sep_heap_getters sep_info,\n   sep_heap_setters = setters}\n\nfun upd_thms (sep_info : sep_info) thms =\n  {plus_thm = #plus_thm sep_info,\n   disj_thm = #disj_thm sep_info,\n   zero_thm = #zero_thm sep_info,\n   sep_thms = thms,\n   sep_heap_arrows = #sep_heap_arrows sep_info,\n   sep_heap_getters = #sep_heap_getters sep_info,\n   sep_heap_setters = #sep_heap_setters sep_info\n  }\n\n\\<close>\n\nML \\<open>val print_type = dest_Type #> fst\\<close>\n\nML \\<open>fun mk_lifted_globals_record stateT rvals ctxt =\n  let\n      val xs =  rvals\n      val state_t = \"lifted_globals_ext\" |> Syntax.read_term ctxt\n  in\n  betapplys (state_t, xs)\n  |> Syntax.check_term ctxt\nend;\n\\<close>\n\nML \\<open>\nval get_data = HeapInfo.get #> Symtab.lookup;\n\n\\<close>\n\n\nML\\<open>\nfun zero_lifted_globals subT global_types heap_types  =\n  let fun make_zero_heap heap_type = (@{mk_term \"(\\<lambda>(_ :: ?'T ptr). arbitrary_zero :: (?'T))\" ('T)} heap_type)\n      fun make_zero_valid_heap heap_type = (@{mk_term \"(\\<lambda>_. False) ::  ?'T ptr \\<Rightarrow> bool\" ('T)} heap_type)\n      fun make_zero global_type = @{mk_term \"arbitrary_zero :: ?'T\" ('T)} global_type\n  in\n  map make_zero global_types @\n  map make_zero_heap heap_types @\n  map make_zero_valid_heap heap_types @\n  [@{term \"0\\<^sub>? :: 'b\"}] |>\n  mk_lifted_globals_record subT\nend;\n\nval make_conj = @{mk_term \"?P \\<and> ?Q\" (P, Q)}\n\nval make_conj_list = foldr1 make_conj;\n\nfun get_more ctxt t = \"lifted_globals.more\" |> Syntax.read_term ctxt\n\\<close>\n\n\ndeclare [[ML_print_depth=1000]]\n\nML \\<open>\nfun promote subT (Const (str, typ))  =   Const (str, subT --> (typ |> range_type));\n\\<close>\n\nML \\<open>\n\nfun sep_disj_lifted_globals ctxt subT heap_types heap_valid_getters h1 h2 =\nlet\n  fun make_valid_disjoint heap_type  =\n     let val heap_valid_getter = Typtab.lookup heap_valid_getters heap_type |> the |> Const |> promote subT\n         (* val heap_valid_getter' = Const (fst heap_valid_getter, subT  --> (heap_valid_getter |> snd |> range_type)) *)\n     in\n      @{mk_term \"(\\<lambda> l r. ?f l  ## (?f r)) \" (f)} (heap_valid_getter) $ h1 $ h2\n     end;\n  val typ =  subT |> dest_Type |> snd |> hd;\n  val more = get_more ctxt subT\n  (* val more_disjoint = @{mk_term \"\\<lambda>(f :: ?'T => ?'M :: stronger_sep_algebra) (l:: ?'T) (r :: ?'T ).\n               (f l) ## (f r)\" ('T, 'M)} (subT, typ) $ more $ h1 $ h2 *)\n  val is_valid_disjoint = map make_valid_disjoint heap_types\nin\n  make_conj_list is_valid_disjoint\nend;\n\\<close>\n\n\nML \\<open>fun setup_heap_zero stateT heap_type global_types sep_info ctxt  =\nlet\n  val (_, thm, ctxt) = Utils.define_const_args \"zero_lifted_globals_ext\" false (zero_lifted_globals stateT global_types heap_type ctxt) [] ctxt\nin\n  (upd_zero_thm sep_info (SOME thm), ctxt)\nend\\<close>\n\nML \\<open>fun setup_heap_disj stateT heap_types heap_valid_getters sep_info ctxt  =\nlet\n  val term = sep_disj_lifted_globals ctxt stateT heap_types heap_valid_getters (Free (\"s0\", stateT)) (Free (\"s1\", stateT))\n  val (_, thm, ctxt') = Utils.define_const_args \"sep_disj_lifted_globals_ext\" false (term) [(\"s0\", stateT), (\"s1\", stateT)] ctxt\nin\n  (upd_disj_thm sep_info (SOME thm), ctxt')\nend\\<close>\n\n\n\nML\\<open>\nfun plus_lifted_globals ctxt subT global_names global_getters heap_types heap_getters heap_valid_getters h1 h2 =\nlet\n\n fun make_global_plus global_name =\n  let val global_getter = global_name |> Symtab.lookup global_getters |> the |> snd |> promote subT\n\n       in @{mk_term \"\\<lambda>l r. arbitrary_add (?f l) (?f r)\"(f)} global_getter $ h1 $ h2 end;\n\n fun make_heap_plus heap_type  =\n  let val heap_getter = heap_type |> Typtab.lookup heap_getters |> the |> Const |> promote subT\n      val heap_valid_getter = heap_type |> Typtab.lookup heap_valid_getters |> the |> Const |> promote subT\n   in\n   (@{mk_term\n       \"\\<lambda>l r.\n        \\<lambda>x.  if ?valid l x then ?heap l x else if ?valid r x then ?heap r x else\n             arbitrary_add ( ?heap l x) ( ?heap r x) \" (heap, valid)}\n              (heap_getter, heap_valid_getter) $ h1 $ h2)\n  end;\n\n fun make_heap_valid_plus heap_type =\n    let val heap_valid_getter = heap_type |> Typtab.lookup heap_valid_getters |> the |> Const |> promote subT\n    in\n    (@{mk_term \"\\<lambda>l r.\n      (?valid l) + (?valid r)\" (valid)} heap_valid_getter $ h1 $ h2)\n    end;\n val typ =  subT |> dest_Type |> snd |> hd;\n val more = get_more ctxt subT\n\nin\n   map make_global_plus global_names @\n   map make_heap_plus heap_types @\n   map make_heap_valid_plus heap_types  @\n  [(@{mk_term \"\\<lambda>l r.\n               arbitrary_add (?f l) (?f r)\" (f)} (more) $ h1 $ h2)]  |>\n   mk_lifted_globals_record subT\nend;\n\n\\<close>\n\nML \\<open>\nfun setup_heap_plus stateT global_names global_getters heap_types heap_getters heap_valid_getters sep_info ctxt =\nlet\n  val term = (plus_lifted_globals ctxt stateT global_names global_getters heap_types\n              heap_getters heap_valid_getters (Free (\"s0\", stateT)) (Free (\"s1\", stateT)) ctxt)\n  val (_, thm, ctxt') = Utils.define_const_args \"plus_lifted_globals_ext\" false term\n                          [(\"s0\", stateT), (\"s1\", stateT)] ctxt\nin\n  (upd_plus_thm sep_info (SOME thm), ctxt')\nend;\n\n\n\\<close>\n\nML \\<open>\n\n   fun make_arrow stateT heap_type heap_getters heap_valid_getters p v=\n      let\n          val heap_getter = heap_type |> Typtab.lookup heap_getters |> the |> Const\n          val heap_valid  = heap_type |> Typtab.lookup heap_valid_getters |> the |> Const\n        in\n           @{mk_term \"\\<lambda>p v s. ?h s p = v \\<and> ?v' s p\" (h, v')}\n             (heap_getter, heap_valid) $ p $ v\n    end;\n\n    fun split_on _ [] = [] |\n        split_on f (x::xs) = if f x then xs else split_on f xs ;\n\n    filter;\n\n  fun hds s = String.substring (s,0,1)\n\n   fun setup_arrows stateT heap_types heap_getters heap_valid_getters sep_info ctxt =\n    let\n         val (arrowt, _, ctxt') =  Utils.define_const_args \"sep_generic_arrow\" true\n                               (@{mk_term \"undefined :: (?'h ptr => ?'h => ?'T \\<Rightarrow> bool)\" ('T, 'h) } (stateT, @{typ 'h})) [] ctxt\n         val ctxt'' = Local_Theory.notation true Syntax.mode_default\n               [(arrowt, Infixl (Input.string \"\\<mapsto>s\", 50, Position.no_range))] ctxt'\n        fun setup_arrow (heap_type,(sep_info,ctxt)) =\n         let\n          val pointer = (Free (\"p\", Utils.gen_typ @{typ \"'a ptr\"} [heap_type]))\n          val value = (Free (\"v\", heap_type))\n          val term = (make_arrow stateT heap_type heap_getters heap_valid_getters pointer value)\n          val arr_name = \"sep_map_\" ^  HeapLiftBase.name_from_type heap_type\n          val arrow = \"\\<mapsto>\"  ^ (HeapLiftBase.name_from_type heap_type |> hds)\n          val fix = Infixl (Input.string arrow, 50, Position.no_range)\n          val (t , thm, ctxt') = Utils.define_const_args arr_name false term\n               [(\"p\", Utils.gen_typ @{typ \"'a ptr\"} [heap_type]) ,  (\"v\", heap_type) ] ctxt\n          val ctxt'' = Local_Theory.notation true Syntax.mode_default [(t , fix)] ctxt'\n          val genarrowstr = arrowt |> dest_Const |> fst\n          val sep_info = sep_info |> #sep_heap_arrows |> Typtab.update (heap_type, (t,thm)) |> upd_heap_arrows sep_info\n          in\n           (sep_info, ctxt'' |>\n           Local_Theory.declaration {syntax = true, pervasive = false} (K (Adhoc_Overloading.generic_add_overloaded genarrowstr )) |>\n           Local_Theory.declaration {syntax = true, pervasive = false} (K (Adhoc_Overloading.generic_add_variant genarrowstr t)))\n         end;\n      in foldr setup_arrow (sep_info,ctxt'') heap_types\n   end;\n\n\\<close>\n\nML \\<open>Utils.expand_type_abbrevs; @{theory}; Proof_Context.theory_of;\\<close>\n\nML \\<open>fun liberalise_type _ (Type (s,[])) = (s,[]) |> Type |\n          liberalise_type t (Type (s,(xs))) = if (Long_Name.base_name s) = \"lifted_globals_ext\" then\n                                               (Type (s, t :: (tl xs))) else\n                                               (Type (s, map (liberalise_type t) (xs)));\n\\<close>\n\nML \\<open>\n\nfun make_rewrite heap_getters heap_setters heap_type sep_info ctxt =\n     let\n         val heap_getter  = heap_type |> Typtab.lookup heap_getters |> the |> Const\n         val heap_setter  = heap_type |> Typtab.lookup heap_setters |> the |> Const\n         val get_heap_term = @{mk_term \"gets (\\<lambda>s. ?f s p) \" (f)} (heap_getter)\n         val set_heap_term = @{mk_term \"modify (?f (\\<lambda>a. a(p := v)))\" (f)} heap_setter\n         val (t, thy, ctxt) = Utils.define_const_args (\"get_\" ^ (HeapLiftBase.name_from_type heap_type)) false get_heap_term [(\"p\", Utils.gen_typ @{typ \"'a ptr\"} [heap_type])] ctxt\n         val (t', thy', ctxt) = Utils.define_const_args (\"set_\" ^ (HeapLiftBase.name_from_type heap_type)) false set_heap_term [(\"p\", Utils.gen_typ @{typ \"'a ptr\"} [heap_type]), (\"v\", heap_type)] ctxt\n         val localise_term =  @{mk_term \"modify (\\<lambda>s. ?f (\\<lambda>a. a(p:= f s)) (s)) \\<equiv> do v <- gets f; ?g p v od\" (f,g)} (heap_setter, t')\n         val localise_simps = @{thms modify_def gets_def put_def fun_upd_def get_def return_def bind_def }\n         val localise_term' = @{mk_term \"Trueprop (modify (\\<lambda>s. ?f (\\<lambda>a. a(p:= f a s)) s) = do a <- gets (\\<lambda>s. f (?h s) s); ?g p a od)\" (f,h,g)} (heap_setter, heap_getter, t')\n         val prove_localise = force_tac\n                          (ctxt addsimps localise_simps addsimps [thy'])\n         val localise_thm = Goal.prove ctxt [\"f\", \"p\"] [] localise_term (fn _ => prove_localise 1)\n         val localise'_thm = Goal.prove ctxt [\"f\", \"p\"] [] localise_term' (fn _ => prove_localise 1)\n         val sep_info =  sep_info |> #sep_thms |> (fn x => x @ [localise_thm, localise'_thm, Thm.symmetric thy,Thm.symmetric thy']) |> upd_thms sep_info\n         val sep_info =  sep_info |> #sep_heap_getters |> Typtab.update (heap_type, (t,thy)) |> upd_heap_getters sep_info\n         val sep_info =  sep_info |> #sep_heap_setters |> Typtab.update (heap_type, (t',thy')) |> upd_heap_setters sep_info\n    in\n        (sep_info, ctxt)\nend;\n\n\n\\<close>\n\nML \\<open>\nUtils.named_cterm_instantiate;\n\nfun make_struct_rewrite (structs : HeapLiftBase.struct_info list) sep_info ctxt =\n   let\n       val structs = structs |> map #field_info |> List.concat\n       fun make_struct_rewrite_inner strct =\n       let val getter = strct |> #getter\n           val setter = strct |> #setter\n           val getter_rewrite_term = @{mk_term \"Trueprop (gets (\\<lambda>s. ?P (f s) ) =\n                                                          do c <- gets f;\n                                                             return (?P c )\n                                                          od )\" (P)} getter\n           val getter_rewrite_term' = @{mk_term \"Trueprop (gets (\\<lambda>s a. ?P (f s) ) =\n                                                           do c <- gets f;\n                                                           return (\\<lambda>a. ?P c ) od )\" (P)} getter\n           val setter_rewrite_term = @{mk_term \"Trueprop (gets (\\<lambda>s . ?P (f s) (g s)) =\n                                                          do c <- gets f;\n                                                             d <- gets g;\n                                                             return ( ?P c d )\n                                                          od )\" (P)} setter\n          val setter_rewrite_term' = @{mk_term \"Trueprop (gets (\\<lambda>s a . ?P (f s) (g s)) =\n                                               do c <- gets f;\n                                                  d <- gets g;\n                                                  return (\\<lambda>a. ?P c d )\n                                               od )\" (P)} setter\n           val getter_rewrite = Goal.prove ctxt [\"f\"] [] getter_rewrite_term (fn _ => Skip_Proof.cheat_tac ctxt 1) (* FIXME: unfinished *)\n           val getter_rewrite' = Goal.prove ctxt [\"f\"] [] getter_rewrite_term' (fn _ => Skip_Proof.cheat_tac ctxt 1) (* FIXME: unfinished *)\n           val setter_rewrite = Goal.prove ctxt [\"f\", \"g\"] [] setter_rewrite_term (fn _ => Skip_Proof.cheat_tac ctxt 1) (* FIXME: unfinished *)\n           val setter_rewrite' = Goal.prove ctxt [\"f\", \"g\"] [] setter_rewrite_term' (fn _ => Skip_Proof.cheat_tac ctxt 1) (* FIXME: unfinished *)\n       in [setter_rewrite,setter_rewrite', getter_rewrite, getter_rewrite'] end;\n     fun upd_sep_info_list info xs = info |> #sep_thms |> (fn x => x @ xs) |> upd_thms info\n   in map make_struct_rewrite_inner structs |> List.concat |> upd_sep_info_list sep_info\nend;\n\nfun make_rewrites heap_types heap_getters heap_setters structs sep_info ctxt =\n  let\n    val (sep_info, ctxt) = foldr (fn (htype, (info, ctxt)) => (make_rewrite heap_getters heap_setters htype info ctxt) ) (sep_info,ctxt) heap_types\n    val sep_info = (make_struct_rewrite structs sep_info ctxt)\n    val thms= sep_info |> #sep_thms\n  in\n     (sep_info, Utils.define_lemmas \"sep_thms\" thms ctxt |> snd )\nend;\n\\<close>\n\nML \\<open>val myss = ref HOL_basic_ss\\<close>\nML \\<open>val mythm = ref @{thms iffI}\\<close>\n\nML \\<open>fun prove_get_leaf_lemma heap_type ((sep_info : sep_info),  ctxt) =\n          let\n              val (heap_getter, heap_getter_def) = heap_type |> Typtab.lookup (#sep_heap_getters sep_info) |> the\n              val (heap_arrow, heap_arrow_def) = heap_type |> Typtab.lookup (#sep_heap_arrows sep_info) |> the\n              val plus_thm = sep_info |> #plus_thm |> the\n              val proof_term = @{mk_term\n                                 \" Trueprop (\n                                 \\<lbrace>\\<lambda>s. (?arr p x \\<and>* R) s\\<rbrace>\n                                              ?getter p\n                                 \\<lbrace>\\<lambda>rv. pred_conj (?arr p x \\<and>* R) ( K (rv = x))\\<rbrace> )\" (arr,getter)}\n                                (heap_arrow, heap_getter)\n               val thms =  [@{thm sep_conj_def},\n                            @{thm pred_conj_def},\n                            heap_getter_def, heap_arrow_def, plus_thm]\n               val name = heap_getter |> dest_Const |> fst |> Long_Name.base_name\n               fun proof_tac ctxt = fast_force_tac (ctxt addsimps thms)\n               val get_wp = Goal.prove ctxt [\"x\", \"p\",\"R\"] [] proof_term (fn _ => proof_tac ctxt 1)\n       in (sep_info, Utils.define_lemma (name ^ \"_wp\") get_wp ctxt |> snd) end;\\<close>\n\n\nML \\<open>\n      fun prove_update_heap_lemma (heap_arrow, heap_arrow_def) heap_update  ctxt =\n         let val proof_term = @{mk_term \"((?arr p x) s \\<Longrightarrow> (?arr p v) (?heap_update (\\<lambda>s. fun_upd s p v) s))\" (arr,heap_update)} (heap_arrow, heap_update)\n             val proof = clarsimp_tac (ctxt addsimps [heap_arrow_def])\n             in   Goal.prove ctxt [\"x\", \"p\", \"v\",\"s\"] [] proof_term (fn x => proof 1)\n      end;\n\n      fun prove_set_leaf_lemma (heap_type, heap_updater) ((sep_info : sep_info),  ctxt) =\n          let\n              val (heap_setter, heap_setter_def) = heap_type |> Typtab.lookup (#sep_heap_setters sep_info) |> the\n              val (heap_arrow, heap_arrow_def) = heap_type |> Typtab.lookup (#sep_heap_arrows sep_info) |> the\n              val disj_thm = sep_info |> #disj_thm |> the\n              val plus_thm = sep_info |> #plus_thm |> the\n              val proof_term = @{mk_term\n                                 \" Trueprop (\n                                 \\<lbrace>\\<lambda>s. (?arr p x \\<and>* R) s\\<rbrace>\n                                              ?setter p v\n                                 \\<lbrace>\\<lambda>rv. (?arr p v \\<and>* R)\\<rbrace> )\" (arr,setter)}\n                                (heap_arrow, heap_setter)\n               val thms = @{thms fun_upd_def} @ [ heap_arrow_def, disj_thm, plus_thm]\n               val name = heap_setter |> dest_Const |> fst |> Long_Name.base_name\n               val heap_update_lemma = prove_update_heap_lemma (heap_arrow, heap_arrow_def) (heap_updater) ctxt\n               fun proof_tac ctxt = clarsimp_tac (ctxt addsimps [heap_setter_def]) THEN'\n                                    eresolve0_tac [@{thm sep_conjE}] THEN'\n                                    resolve0_tac [@{thm sep_conjI}] THEN'\n                                    eresolve0_tac [heap_update_lemma] THEN'\n                                    fast_force_tac (ctxt) THEN_ALL_NEW\n                                    fast_force_tac (ctxt addsimps thms)\n               val set_wp = Goal.prove ctxt [\"x\", \"p\",\"R\", \"v\"] [] proof_term (fn x =>  proof_tac (#context x) 1 )\n       in (sep_info, Utils.define_lemma (name ^ \"_wp\") set_wp ctxt |> snd) end;\\<close>\n\nML \\<open>\n\nfun prove_get_leaf_lemmas heap_types sep_info ctxt =\n    foldr (uncurry prove_get_leaf_lemma) (sep_info, ctxt) heap_types\n\n\nfun prove_set_leaf_lemmas heap_types sep_info ctxt =\n   foldr (uncurry prove_set_leaf_lemma) (sep_info, ctxt) heap_types\n\n\\<close>\n\nML \\<open>\n   fun force_tac ctxt =\n      SELECT_GOAL\n     (Classical.clarify_tac ctxt 1 THEN\n      IF_UNSOLVED (Simplifier.asm_full_simp_tac ctxt 1) THEN\n      ALLGOALS (Classical.first_best_tac ctxt))\n   fun zipWith (x::xs) (y::ys) f = f x y :: zipWith xs ys f |\n       zipWith _ _ _ = []\n\n    fun tester str thy =\n         let val data = get_data thy str |> the |> #heap_info\n             val typ = data |> #globals_type |> print_type\n             val stateT = data |> #globals_type |> dest_Type ||> (K [@{typ 'b}]) |> Type\n             val heap_types = data |> #heap_getters |> Typtab.dest |> map fst\n             val heap_valid_getters = data |> #heap_valid_getters\n             val heap_getters = data |> #heap_getters\n             val heap_setters = data |> #heap_setters\n             val global_types =  data |> #global_fields |> map (fn (_,_,z) => z)\n             val global_names =  data |> #global_fields |> map (fn (x,_,_) => x)\n             val global_getters = data |> #global_field_getters\n             val structs = data |> #structs |> Symtab.dest |> map snd\n             val sep_info = mk_sep_info NONE NONE NONE Typtab.empty Typtab.empty Typtab.empty []\n             fun tup_list (x : sep_info)\n                            = [x |> #plus_thm |> the,\n                               x |> #zero_thm |> the,\n                               x |> #disj_thm |> the]\n             fun proof_tac thms ctxt =\n                 let\n                     val equality =  Proof_Context.get_thm ctxt \"lifted_globals.equality\" ;\n                     val simpset = ctxt addsimps @{thms sep_add_left_commute sep_disj_commute sep_add_assoc sep_add_commute\n                                                       left_commute zero_fun_def plus_fun_def sep_disj_fun_def zero_bool_def\n                                                       commute} addsimps thms\n                     val intros = [equality, @{thm ext}]\n                  in\n                         Class.standard_intro_classes_tac ctxt [] THEN\n                         ((resolve_tac ctxt intros  ORELSE'\n                           force_tac simpset ) |> REPEAT_ALL_NEW |> TRYALL)\n                end;\n      in thy\n      |>  Class.instantiation ([typ], [(\"'a\", @{sort type})], @{sort stronger_sep_algebra})\n      |>  setup_heap_zero stateT heap_types global_types sep_info\n      |-> setup_heap_disj stateT heap_types heap_valid_getters\n      |-> setup_heap_plus stateT global_names global_getters heap_types heap_getters heap_valid_getters\n      |-> setup_arrows stateT heap_types heap_getters heap_valid_getters\n      |-> make_rewrites heap_types heap_getters heap_setters structs\n      |> (fn (info, ctxt) => (info, (info,ctxt) |> (apfst (tup_list #> proof_tac) #-> Class.prove_instantiation_instance)))\n      |-> prove_get_leaf_lemmas heap_types\n      |-> prove_set_leaf_lemmas (heap_setters |> Typtab.dest |> map (fn x => x ||> Const)) |> snd\n      end;\n\nAdhoc_Overloading.is_overloaded @{context} \"\\<mapsto>\"\n\\<close>\n\nML \\<open>\nval _ =\n  Outer_Syntax.command @{command_keyword \"sep_instance\"} \"instantiate and prove type arity\"\n  (Parse.path >>\n   (fn str =>  tester str |> Toplevel.begin_local_theory true #> Toplevel.end_local_theory));\n\n(* get_data @{theory} \"swap.c\" |> the |> #structs *)\n\\<close>\n\n\n\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/autocorres/Auto_Separation_Algebra.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.25336434606623265}}
{"text": "theory \"Wide_Mouth_Frog_cert_auto\"\nimports\n  \"ESPLogic\"\nbegin\n\n(* section:  Wide Mouthed Frog  *)\n\n(* text: \n  The protocol is modeled after the description in the SPORE library:\n\n    http://www.lsv.ens-cachan.fr/Software/spore/wideMouthedFrog.html\n\n  Timestamps are modelled as fresh numbers that are immediatly made public.\n *)\n\nrole I\nwhere \"I =\n  [ Send ''1_leak'' ( sN ''TimeI'' )\n  , Send ''1'' <| sAV ''I'', sAV ''R'',\n                  PEnc <| sC ''1'', sN ''TimeI'', sAV ''R'', sN ''kIR'' |>\n                       ( sK ''I'' ''S'' )\n               |>\n  ]\"\n\nrole R\nwhere \"R =\n  [ Recv ''2'' <| sMV ''S'', sMV ''I'',\n                  PEnc <| sC ''2'', sMV ''TimeS'', sMV ''I'', sMV ''kIR'' |>\n                       ( PSymK ( sAV ''R'' ) ( sMV ''S'' ) )\n               |>\n  ]\"\n\nrole S\nwhere \"S =\n  [ Recv ''1'' <| sMV ''I'', sMV ''R'',\n                  PEnc <| sC ''1'', sMV ''TimeI'', sMV ''R'', sMV ''kIR'' |>\n                       ( PSymK ( sMV ''I'' ) ( sAV ''S'' ) )\n               |>\n  , Send ''2_leak'' ( sN ''TimeS'' )\n  , Send ''2'' <| sAV ''S'', sMV ''I'',\n                  PEnc <| sC ''2'', sN ''TimeS'', sMV ''I'', sMV ''kIR'' |>\n                       ( PSymK ( sMV ''R'' ) ( sAV ''S'' ) )\n               |>\n  ]\"\n\nprotocol WMF\nwhere \"WMF = { I, R, S }\"\n\nlocale restricted_WMF_state = WMF_state\n\ntype_invariant WMF_msc_typing for WMF\nwhere \"WMF_msc_typing = mk_typing\n  [ ((R, ''I''), (KnownT R_2))\n  , ((S, ''I''), (KnownT S_1))\n  , ((S, ''R''), (KnownT S_1))\n  , ((R, ''S''), (KnownT R_2))\n  , ((S, ''TimeI''), (SumT (KnownT S_1) (NonceT I ''TimeI'')))\n  , ((R, ''TimeS''), (SumT (KnownT R_2) (NonceT S ''TimeS'')))\n  , ((R, ''kIR''), (SumT (KnownT R_2) (NonceT I ''kIR'')))\n  , ((S, ''kIR''), (SumT (KnownT S_1) (NonceT I ''kIR'')))\n  ]\"\n\nsublocale WMF_state < WMF_msc_typing_state\nproof -\n  have \"(t,r,s) : approx WMF_msc_typing\"\n  proof(cases rule: reachable_in_approxI_ext\n        [OF WMF_msc_typing.monoTyp, completeness_cases_rule])\n    case (R_2_I t r s tid0)\n    then interpret state: WMF_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = R_2_I\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (R_2_S t r s tid0)\n    then interpret state: WMF_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = R_2_S\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (R_2_TimeS t r s tid0)\n    then interpret state: WMF_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = R_2_TimeS\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''2'', s(MV ''TimeS'' tid0), s(MV ''I'' tid0),\n               s(MV ''kIR'' tid0)\n            |}\n            ( K ( s(AV ''R'' tid0) ) ( s(MV ''S'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (R_2_kIR t r s tid0)\n    then interpret state: WMF_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = R_2_kIR\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''2'', s(MV ''TimeS'' tid0), s(MV ''I'' tid0),\n               s(MV ''kIR'' tid0)\n            |}\n            ( K ( s(AV ''R'' tid0) ) ( s(MV ''S'' tid0) ) ) \")\n      case (S_2_enc tid1) note_unified facts = this facts\n      thus ?thesis proof(sources! \"\n                       Enc {| LC ''1'', s(MV ''TimeI'' tid1), s(AV ''R'' tid0),\n                              s(MV ''kIR'' tid0)\n                           |}\n                           ( K ( s(MV ''I'' tid0) ) ( s(AV ''S'' tid1) ) ) \")\n      qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (S_1_I t r s tid0)\n    then interpret state: WMF_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = S_1_I\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (S_1_R t r s tid0)\n    then interpret state: WMF_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = S_1_R\n    thus ?case\n    by (fastforce intro: event_predOrdI split: if_splits)\n  next\n    case (S_1_TimeI t r s tid0)\n    then interpret state: WMF_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = S_1_TimeI\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''1'', s(MV ''TimeI'' tid0), s(MV ''R'' tid0),\n               s(MV ''kIR'' tid0)\n            |}\n            ( K ( s(MV ''I'' tid0) ) ( s(AV ''S'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  next\n    case (S_1_kIR t r s tid0)\n    then interpret state: WMF_msc_typing_state t r s\n      by unfold_locales auto\n    note_prefix_closed (state) facts = S_1_kIR\n    thus ?case\n    proof(sources! \"\n        Enc {| LC ''1'', s(MV ''TimeI'' tid0), s(MV ''R'' tid0),\n               s(MV ''kIR'' tid0)\n            |}\n            ( K ( s(MV ''I'' tid0) ) ( s(AV ''S'' tid0) ) ) \")\n    qed (safe?, simp_all?, insert facts, (((fastforce intro: event_predOrdI split: if_splits))+)?)\n  qed\n  thus \"WMF_msc_typing_state t r s\" by unfold_locales auto\nqed\n\ntext{* Prove secrecy of long-term keys. *}\ncontext WMF_state begin\n\n  (* This rule is unsafe in general, but OK here, \n     as we are only reasoning about static compromise. \n  *)\n  lemma static_longterm_key_reveal[dest!]:\n    \"predOrd t (LKR a) e ==> RLKR a : reveals t\"\n    by (auto intro: compr_predOrdI)\n\n  lemma longterm_private_key_secrecy:\n    assumes facts:\n      \"SK m : knows t\"\n      \"RLKR m ~: reveals t\"\n    shows \"False\"\n  using facts by (sources \"SK m\")\n\n  lemma longterm_sym_ud_key_secrecy:\n    assumes facts:\n      \"K m1 m2 : knows t\"\n      \"RLKR m1 ~: reveals t\"\n      \"RLKR m2 ~: reveals t\"\n    shows \"False\"\n  using facts by (sources \"K m1 m2\")\n\n  lemma longterm_sym_bd_key_secrecy:\n    assumes facts:\n      \"Kbd m1 m2 : knows t\"\n      \"RLKR m1 ~: reveals t\"\n      \"RLKR m2 ~: reveals t\"\n      \"m1 : Agent\"\n      \"m2 : Agent\"\n    shows \"False\"\n  proof -\n    from facts \n    have \"KShr (agents {m1, m2}) : knows t\"\n      by (auto simp: Kbd_def)\n    thus ?thesis using facts\n    proof (sources \"KShr (agents {m1, m2})\")\n    qed (auto simp: agents_def Agent_def)\n  qed\n\n  lemmas ltk_secrecy =\n    longterm_sym_ud_key_secrecy\n    longterm_sym_ud_key_secrecy[OF in_knows_predOrd1]\n    longterm_sym_bd_key_secrecy\n    longterm_sym_bd_key_secrecy[OF in_knows_predOrd1]\n    longterm_private_key_secrecy\n    longterm_private_key_secrecy[OF in_knows_predOrd1]\n\nend\n\n(* subsection:  Secrecy Properties  *)\n\nlemma (in restricted_WMF_state) I_kIR_sec:\n  assumes facts:\n    \"roleMap r tid0 = Some I\"\n    \"RLKR(s(AV ''I'' tid0)) ~: reveals t\"\n    \"RLKR(s(AV ''R'' tid0)) ~: reveals t\"\n    \"RLKR(s(AV ''S'' tid0)) ~: reveals t\"\n    \"LN ''kIR'' tid0 : knows t\"\n  shows \"False\"\nusing facts proof(sources! \" LN ''kIR'' tid0 \")\n  case I_1_kIR note_unified facts = this facts\n  thus ?thesis by (auto dest!: ltk_secrecy)\nnext\n  case (S_2_kIR tid1) note_unified facts = this facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''1'', s(MV ''TimeI'' tid1), s(MV ''R'' tid1), LN ''kIR'' tid0\n                       |}\n                       ( K ( s(MV ''I'' tid1) ) ( s(AV ''S'' tid1) ) ) \")\n    case (I_1_enc tid2) note_unified facts = this facts\n    thus ?thesis by (auto dest!: ltk_secrecy)\n  qed (safe?, simp_all?, insert facts, ((((clarsimp, order?) | order | fast))+)?)\nqed (safe?, simp_all?, insert facts, (fastforce+)?)\n\nlemma (in restricted_WMF_state) S_kIR_sec:\n  assumes facts:\n    \"roleMap r tid0 = Some S\"\n    \"RLKR(s(AV ''S'' tid0)) ~: reveals t\"\n    \"RLKR(s(MV ''I'' tid0)) ~: reveals t\"\n    \"RLKR(s(MV ''R'' tid0)) ~: reveals t\"\n    \"( tid0, S_1 ) : steps t\"\n    \"s(MV ''kIR'' tid0) : knows t\"\n  shows \"False\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''1'', s(MV ''TimeI'' tid0), s(MV ''R'' tid0),\n                          s(MV ''kIR'' tid0)\n                       |}\n                       ( K ( s(MV ''I'' tid0) ) ( s(AV ''S'' tid0) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (auto dest!: ltk_secrecy)\n  next\n    case (I_1_enc tid1) note_unified facts = this facts\n    thus ?thesis by (fastforce dest: I_kIR_sec intro: event_predOrdI)\n  qed (safe?, simp_all?, insert facts, (fastforce+)?)\nqed\n\nlemma (in restricted_WMF_state) R_kIR_sec:\n  assumes facts:\n    \"roleMap r tid0 = Some R\"\n    \"RLKR(s(AV ''R'' tid0)) ~: reveals t\"\n    \"RLKR(s(MV ''I'' tid0)) ~: reveals t\"\n    \"RLKR(s(MV ''S'' tid0)) ~: reveals t\"\n    \"( tid0, R_2 ) : steps t\"\n    \"s(MV ''kIR'' tid0) : knows t\"\n  shows \"False\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''2'', s(MV ''TimeS'' tid0), s(MV ''I'' tid0),\n                          s(MV ''kIR'' tid0)\n                       |}\n                       ( K ( s(AV ''R'' tid0) ) ( s(MV ''S'' tid0) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (auto dest!: ltk_secrecy)\n  next\n    case (S_2_enc tid1) note_unified facts = this facts\n    thus ?thesis by (fastforce dest: S_kIR_sec intro: event_predOrdI)\n  qed (safe?, simp_all?, insert facts, (fastforce+)?)\nqed\n\n(* subsection:  Authentication Properties  *)\n\n(* text: \n  The authentication guarantee for the initiator is trivial because it does not\n  receive any confirmation that the responder received the new session-key.\n *)\n\nlemma (in restricted_WMF_state) S_ni_synch:\n  assumes facts:\n    \"roleMap r tid3 = Some S\"\n    \"RLKR(s(AV ''S'' tid3)) ~: reveals t\"\n    \"RLKR(s(MV ''I'' tid3)) ~: reveals t\"\n    \"( tid3, S_1 ) : steps t\"\n  shows\n    \"(?  tid1.\n        roleMap r tid1 = Some I &\n        s(AV ''I'' tid1) = s(MV ''I'' tid3) &\n        s(AV ''R'' tid1) = s(MV ''R'' tid3) &\n        s(AV ''S'' tid1) = s(AV ''S'' tid3) &\n        LN ''TimeI'' tid1 = s(MV ''TimeI'' tid3) &\n        LN ''kIR'' tid1 = s(MV ''kIR'' tid3) &\n        predOrd t (St( tid1, I_1 )) (St( tid3, S_1 )))\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''1'', s(MV ''TimeI'' tid3), s(MV ''R'' tid3),\n                          s(MV ''kIR'' tid3)\n                       |}\n                       ( K ( s(MV ''I'' tid3) ) ( s(AV ''S'' tid3) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (auto dest!: ltk_secrecy)\n  next\n    case (I_1_enc tid4) note_unified facts = this facts\n    thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\n  qed (safe?, simp_all?, insert facts, (fastforce+)?)\nqed\n\nlemma (in restricted_WMF_state) R_ni_synch:\n  assumes facts:\n    \"roleMap r tid2 = Some R\"\n    \"RLKR(s(AV ''R'' tid2)) ~: reveals t\"\n    \"RLKR(s(MV ''I'' tid2)) ~: reveals t\"\n    \"RLKR(s(MV ''S'' tid2)) ~: reveals t\"\n    \"( tid2, R_2 ) : steps t\"\n  shows\n    \"(?  tid1.\n        (?  tid3.\n           roleMap r tid1 = Some I &\n           roleMap r tid3 = Some S &\n           s(AV ''I'' tid1) = s(MV ''I'' tid2) &\n           s(MV ''I'' tid2) = s(MV ''I'' tid3) &\n           s(AV ''R'' tid1) = s(AV ''R'' tid2) &\n           s(AV ''R'' tid2) = s(MV ''R'' tid3) &\n           s(AV ''S'' tid1) = s(MV ''S'' tid2) &\n           s(MV ''S'' tid2) = s(AV ''S'' tid3) &\n           LN ''TimeI'' tid1 = s(MV ''TimeI'' tid3) &\n           s(MV ''TimeS'' tid2) = LN ''TimeS'' tid3 &\n           LN ''kIR'' tid1 = s(MV ''kIR'' tid2) &\n           s(MV ''kIR'' tid2) = s(MV ''kIR'' tid3) &\n           predOrd t (St( tid1, I_1 )) (St( tid3, S_1 )) &\n           predOrd t (St( tid3, S_1 )) (St( tid3, S_2 )) &\n           predOrd t (St( tid3, S_2 )) (St( tid2, R_2 ))))\"\nproof -\n  note_prefix_closed facts = facts\n  thus ?thesis proof(sources! \"\n                   Enc {| LC ''2'', s(MV ''TimeS'' tid2), s(MV ''I'' tid2),\n                          s(MV ''kIR'' tid2)\n                       |}\n                       ( K ( s(AV ''R'' tid2) ) ( s(MV ''S'' tid2) ) ) \")\n    case fake note_unified facts = this facts\n    thus ?thesis by (auto dest!: ltk_secrecy)\n  next\n    case (S_2_enc tid3) note_unified facts = this facts\n    thus ?thesis proof(sources! \"\n                     Enc {| LC ''1'', s(MV ''TimeI'' tid3), s(AV ''R'' tid2),\n                            s(MV ''kIR'' tid2)\n                         |}\n                         ( K ( s(MV ''I'' tid2) ) ( s(AV ''S'' tid3) ) ) \")\n      case fake note_unified facts = this facts\n      thus ?thesis by (auto dest!: ltk_secrecy)\n    next\n      case (I_1_enc tid4) note_unified facts = this facts\n      thus ?thesis by (fastforce intro: event_predOrdI split: if_splits)\n    qed (safe?, simp_all?, insert facts, (fastforce+)?)\n  qed (safe?, simp_all?, insert facts, (fastforce+)?)\nqed\n\nend", "meta": {"author": "meiersi", "repo": "scyther-proof", "sha": "84e42366a46f66f1b090651be3bfaa3497696280", "save_path": "github-repos/isabelle/meiersi-scyther-proof", "path": "github-repos/isabelle/meiersi-scyther-proof/scyther-proof-84e42366a46f66f1b090651be3bfaa3497696280/examples/spore/isabelle-proofs/Wide_Mouth_Frog_cert_auto.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.25336434606623265}}
{"text": "subsection \\<open>IMO 2006 SL - A6\\<close>\n\ntheory IMO_2006_SL_A6\n  imports Complex_Main\nbegin\n\ntheorem IMO_2006_SL_A6:\n  fixes a b c :: real\n  shows \"Min {M. \\<forall> a b c. \\<bar>a * b * (a\\<^sup>2 - b\\<^sup>2) + b * c * (b\\<^sup>2 - c\\<^sup>2) + c * a * (c\\<^sup>2 - a\\<^sup>2)\\<bar> \\<le> M * (a\\<^sup>2 + b\\<^sup>2 + c\\<^sup>2)\\<^sup>2} = (sqrt 2) * 9 / 32\"\n  sorry\n\nend\n", "meta": {"author": "filipmaric", "repo": "IMO", "sha": "9fb602bf4fd5bcb5890361d194a4fb423ac266e2", "save_path": "github-repos/isabelle/filipmaric-IMO", "path": "github-repos/isabelle/filipmaric-IMO/IMO-9fb602bf4fd5bcb5890361d194a4fb423ac266e2/IMO_files/statements/IMO_2006_SL_A6.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6334102775181399, "lm_q2_score": 0.3998116407397951, "lm_q1q2_score": 0.25324480231597646}}
{"text": "(*\n * Copyright 2016, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the GNU General Public License version 2. Note that NO WARRANTY is provided.\n * See \"LICENSE_GPLv2.txt\" for details.\n *\n * @TAG(NICTA_GPL)\n *)\n\ntheory TypeTrackingTyping imports\n  Cogent\nbegin\n\ndatatype type_split_kind = TSK_L | TSK_S | TSK_NS\n\ndatatype typing_tree = TyTrLeaf\n    | TyTrSplit \"type_split_kind option list\" ctx typing_tree ctx typing_tree\n\ntype_synonym tree_ctx = \"typing_tree * ctx\"\n\nfun\n  apply_tsk :: \"type_split_kind option \\<Rightarrow> type option \\<Rightarrow> type option \\<times> type option\"\nwhere\n    \"apply_tsk None t = (None, t)\"\n  | \"apply_tsk (Some TSK_L) t = (t, None)\"\n  | \"apply_tsk (Some TSK_S) t = (t, t)\"\n  | \"apply_tsk (Some TSK_NS) t = (map_option bang t, t)\"\n\nfun\n  follow_typing_tree :: \"tree_ctx \\<Rightarrow> tree_ctx \\<times> tree_ctx\"\nwhere\n  \"follow_typing_tree (TyTrSplit sps xs T1 ys T2, \\<Gamma>)\n    = ((T1, xs @ map (fst o Product_Type.split apply_tsk) (zip sps \\<Gamma>)),\n        (T2, ys @ map (snd o Product_Type.split apply_tsk) (zip sps \\<Gamma>)))\"\n\nfun\n  new_tt_types :: \"tree_ctx \\<Rightarrow> ctx\"\nwhere\n    \"new_tt_types (TyTrSplit sps xs T1 ys T2, \\<Gamma>) = ys\"\n  | \"new_tt_types (TyTrLeaf, v) = []\"\n\nfun\n  follow_typing_tree_triv :: \"tree_ctx \\<Rightarrow> tree_ctx \\<times> tree_ctx\"\nwhere\n  \"follow_typing_tree_triv (TyTrSplit sps xs T1 ys T2, \\<Gamma>) = ((T1, xs @ \\<Gamma>), (T2, ys @ \\<Gamma>))\"\n\ndefinition\n  composite_anormal_expr :: \"'f expr \\<Rightarrow> bool\"\nwhere\n  \"composite_anormal_expr x \\<equiv> case x of Let _ _ \\<Rightarrow> True\n    | LetBang _ _ _ \\<Rightarrow> True\n    | Case _ _ _ _ \\<Rightarrow> True\n    | If _ _ _ \\<Rightarrow> True\n    | Split _ _ \\<Rightarrow> True\n    | Take _ _ _ \\<Rightarrow> True\n    | _ \\<Rightarrow> False\"\n\ndefinition ttsplit_inner :: \"kind env \\<Rightarrow> type_split_kind option list \\<Rightarrow> bool \\<Rightarrow> ctx \\<Rightarrow> ctx \\<Rightarrow> ctx \\<Rightarrow> bool\"\nwhere\n  \"ttsplit_inner K sps kndng \\<Gamma>b \\<Gamma>1 \\<Gamma>2 = (\n          length sps = length \\<Gamma>b\n        \\<and> \\<Gamma>1 = map (\\<lambda> (sp, v). if sp \\<in> {Some TSK_L, Some TSK_S} then v else None)\n                        (zip sps \\<Gamma>b)\n        \\<and> \\<Gamma>2 = map (\\<lambda> (sp, v). if sp = Some TSK_L then None else v)\n                        (zip sps \\<Gamma>b)\n        \\<and> Some TSK_NS \\<notin> set sps\n        \\<and> (\\<forall>t \\<in> set \\<Gamma>b. t \\<noteq> None \\<longrightarrow> kndng \\<longrightarrow> (K \\<turnstile> the t wellformed))\n        \\<and> (\\<forall>i < length \\<Gamma>b. nth sps i = Some TSK_S\n            \\<longrightarrow> nth \\<Gamma>b i \\<noteq> None \\<and> (\\<exists>k. K \\<turnstile> (the (nth \\<Gamma>b i)) :\\<kappa> k \\<and> S \\<in> k)))\"\n\ndefinition ttsplit :: \"kind env \\<Rightarrow> tree_ctx \\<Rightarrow> type_split_kind option list\n        \\<Rightarrow> ctx \\<Rightarrow> tree_ctx \\<Rightarrow> ctx \\<Rightarrow> tree_ctx \\<Rightarrow> bool\"\nwhere\n  \"ttsplit K \\<Gamma> sps xs \\<Gamma>1 ys \\<Gamma>2 =\n    (\\<exists>\\<Gamma>b \\<Gamma>1a \\<Gamma>2a T1 T2. \\<Gamma> = (TyTrSplit sps xs T1 ys T2, \\<Gamma>b)\n        \\<and> \\<Gamma>1 = (T1, xs @ \\<Gamma>1a)\n        \\<and> \\<Gamma>2 = (T2, ys @ \\<Gamma>2a)\n        \\<and> ttsplit_inner K sps True \\<Gamma>b \\<Gamma>1a \\<Gamma>2a)\"\n\nlemma ttsplitI:\n  \"ttsplit_inner K sps True \\<Gamma>b \\<Gamma>1 \\<Gamma>2 \\<Longrightarrow> xs' = xs @ \\<Gamma>1 \\<Longrightarrow> ys' = ys @ \\<Gamma>2\n    \\<Longrightarrow> ttsplit K (TyTrSplit sps xs T1 ys T2, \\<Gamma>b) sps xs (T1, xs') ys (T2, ys')\"\n  by (simp add: ttsplit_def)\n\nlemma forall_less_Suc_eq:\n  \"(\\<forall>j < Suc i. P j) = (P 0 \\<and> (\\<forall>j < i. P (Suc j)))\"\n  by (auto simp add: less_Suc_eq_0_disj)\n\nlemma ttsplit_innerI:\n  \"ttsplit_inner K sps kndng \\<Gamma>b \\<Gamma>1 \\<Gamma>2\n    \\<Longrightarrow> ttsplit_inner K (None # sps) kndng (None # \\<Gamma>b) (None # \\<Gamma>1) (None # \\<Gamma>2)\"\n  \"(kndng \\<Longrightarrow> K \\<turnstile> \\<gamma> :\\<kappa>  k) \\<Longrightarrow> ttsplit_inner K sps kndng \\<Gamma>b \\<Gamma>1 \\<Gamma>2\n    \\<Longrightarrow> ttsplit_inner K (None # sps) kndng (Some \\<gamma> # \\<Gamma>b) (None # \\<Gamma>1) (Some \\<gamma> # \\<Gamma>2)\"\n  \"(kndng \\<Longrightarrow> K \\<turnstile> \\<gamma> :\\<kappa>  k) \\<Longrightarrow> ttsplit_inner K sps kndng \\<Gamma>b \\<Gamma>1 \\<Gamma>2\n    \\<Longrightarrow> ttsplit_inner K (Some TSK_L # sps) kndng (Some \\<gamma> # \\<Gamma>b) (Some \\<gamma> # \\<Gamma>1) (None # \\<Gamma>2)\"\n  \"K \\<turnstile> \\<gamma> :\\<kappa>  k \\<Longrightarrow> S \\<in> k \\<Longrightarrow> ttsplit_inner K sps kndng \\<Gamma>b \\<Gamma>1 \\<Gamma>2\n    \\<Longrightarrow> ttsplit_inner K (Some TSK_S # sps) kndng (Some \\<gamma> # \\<Gamma>b) (Some \\<gamma> # \\<Gamma>1) (Some \\<gamma> # \\<Gamma>2)\"\n  \"ttsplit_inner K [] kndng [] [] []\"  \n  by (auto simp add: ttsplit_inner_def forall_less_Suc_eq)\n\nlemma split_list_zip:\n  \"split K \\<Gamma> \\<Gamma>1 \\<Gamma>2 = (length \\<Gamma>1 = length \\<Gamma> \\<and> length \\<Gamma>2 = length \\<Gamma>\n        \\<and> (\\<forall>(x, (y, z)) \\<in> set (zip \\<Gamma> (zip \\<Gamma>1 \\<Gamma>2)). split_comp K x y z))\"\n  apply (induct \\<Gamma> arbitrary: \\<Gamma>1 \\<Gamma>2)\n   apply (auto elim: split.cases intro: split_empty)[1]\n  apply (rule iffI)\n   apply (erule split.cases, simp, clarsimp)\n  apply (clarsimp simp: length_Suc_conv)\n  apply (rule split_cons, simp+)\n  done\n\nlemma ttsplit_imp_split:\n  \"ttsplit K \\<Gamma> ijs xs \\<Gamma>1 ys \\<Gamma>2 \\<Longrightarrow> (\\<exists>\\<Gamma>1a \\<Gamma>2a. split K (snd \\<Gamma>) \\<Gamma>1a \\<Gamma>2a\n    \\<and> snd \\<Gamma>1 = xs @ \\<Gamma>1a & snd \\<Gamma>2 = ys @ \\<Gamma>2a)\"\n  apply (clarsimp simp: ttsplit_def ttsplit_inner_def split_list_zip set_zip nth_enumerate_eq)\n  apply (case_tac \"\\<Gamma>b ! i\")\n   apply (simp add: split_comp.none)\n  apply (drule bspec, erule nth_mem)\n  apply (drule spec, drule(1) mp)\n  apply (auto intro: split_comp.intros)\n  done\n\nlemma split_imp_ttsplit:\n  \"split K \\<Gamma> \\<Gamma>1 \\<Gamma>2 \\<Longrightarrow> sps = map (\\<lambda>i. if \\<Gamma>1 ! i = None then None\n            else if \\<Gamma>2 ! i = None then Some TSK_L else Some TSK_S) [0 ..< length \\<Gamma>]\n    \\<Longrightarrow> \\<Gamma>1' = xs @ \\<Gamma>1 \\<Longrightarrow> \\<Gamma>2' = ys @ \\<Gamma>2\n    \\<Longrightarrow> ttsplit K (TyTrSplit sps xs tt ys tt2, \\<Gamma>) sps xs\n        (tt, \\<Gamma>1') ys (tt2, \\<Gamma>2')\"\n  apply (clarsimp simp: ttsplit_def ttsplit_inner_def split_list_zip nth_enumerate_eq\n                        all_set_conv_all_nth o_def image_def\n                  cong: if_cong)\n  apply (intro conjI nth_equalityI allI impI, simp_all add: nth_enumerate_eq)\n      apply (force elim!: split_comp.cases)+\n  done\n\ndefinition ttsplit_triv :: \"tree_ctx \\<Rightarrow> ctx \\<Rightarrow> tree_ctx \\<Rightarrow> ctx \\<Rightarrow> tree_ctx \\<Rightarrow> bool\"\nwhere\n  \"ttsplit_triv \\<Gamma> xs \\<Gamma>1 ys \\<Gamma>2 = (\\<exists>ijs \\<Gamma>1a \\<Gamma>2a.\n    fst \\<Gamma> = TyTrSplit ijs xs \\<Gamma>1a ys \\<Gamma>2a \\<and> \\<Gamma>1 = (\\<Gamma>1a, xs @ snd \\<Gamma>) \\<and> \\<Gamma>2 = (\\<Gamma>2a, ys @ snd \\<Gamma>))\"\n\nlemma ttsplit_trivI:\n  \"\\<Gamma>1b = (\\<Gamma>1a, xs @ \\<Gamma>b) \\<Longrightarrow> \\<Gamma>2b = (\\<Gamma>2a, ys @ \\<Gamma>b) \\<Longrightarrow> ttsplit_triv (TyTrSplit ijs xs \\<Gamma>1a ys \\<Gamma>2a, \\<Gamma>b) xs \\<Gamma>1b ys \\<Gamma>2b\"\n  by (simp add: ttsplit_triv_def)\n\ndefinition ttsplit_bang_inner :: \"kind env \\<Rightarrow> type_split_kind option list \\<Rightarrow> ctx \\<Rightarrow> ctx \\<Rightarrow> ctx \\<Rightarrow> bool\"\nwhere\n  \"ttsplit_bang_inner K sps \\<Gamma>b \\<Gamma>1 \\<Gamma>2 = (\n          length sps = length \\<Gamma>b\n        \\<and> \\<Gamma>1 = map (\\<lambda> (sp, v). if sp \\<in> {Some TSK_L, Some TSK_S} then v\n                            else if sp = Some TSK_NS then map_option bang v else None)\n                        (zip sps \\<Gamma>b)\n        \\<and> \\<Gamma>2 = map (\\<lambda> (sp, v). if sp \\<noteq> Some TSK_L then v else None)\n                        (zip sps \\<Gamma>b)\n        \\<and> (\\<forall>i < length \\<Gamma>b. nth sps i \\<noteq> Some TSK_NS \\<and> \\<Gamma>b ! i \\<noteq> None \\<longrightarrow> (\\<exists>k. K \\<turnstile> the (\\<Gamma>b ! i) :\\<kappa> k))\n        \\<and> (\\<forall>i < length \\<Gamma>b. nth sps i = Some TSK_NS \\<longrightarrow> nth \\<Gamma>b i \\<noteq> None) \n        \\<and> (\\<forall>i < length \\<Gamma>b. nth sps i = Some TSK_S\n            \\<longrightarrow> nth \\<Gamma>b i \\<noteq> None \\<and> (\\<exists>k. K \\<turnstile> (the (nth \\<Gamma>b i)) :\\<kappa> k \\<and> S \\<in> k)))\"\n \ndefinition\n  \"ttsplit_bang is sps K \\<Gamma> xs \\<Gamma>1 ys \\<Gamma>2 =\n    (\\<exists>\\<Gamma>b \\<Gamma>1a \\<Gamma>2a T1 T2. \\<Gamma> = (TyTrSplit sps xs T1 ys T2, \\<Gamma>b)\n        \\<and> ttsplit_bang_inner K sps \\<Gamma>b \\<Gamma>1a \\<Gamma>2a\n        \\<and> (\\<forall>i < length \\<Gamma>b. (i \\<in> is) = (nth sps i = Some TSK_NS))\n        \\<and> \\<Gamma>1 = (T1, xs @ \\<Gamma>1a)\n        \\<and> \\<Gamma>2 = (T2, ys @ \\<Gamma>2a))\"\n\nlemma ttsplit_bangI:\n  \"xs' = xs @ \\<Gamma>1a \\<Longrightarrow> ys' = ys @ \\<Gamma>2a\n    \\<Longrightarrow> is = set (map fst (filter (\\<lambda>(i, v). v = Some TSK_NS) (enumerate 0 sps)))\n    \\<Longrightarrow> ttsplit_bang_inner K sps \\<Gamma>b \\<Gamma>1a \\<Gamma>2a\n    \\<Longrightarrow> ttsplit_bang is sps K (TyTrSplit sps xs T1 ys T2, \\<Gamma>b) xs (T1, xs') ys (T2, ys')\"\n  by (simp add: ttsplit_bang_def ttsplit_bang_inner_def in_set_enumerate_eq image_def)\n\nlemma ttsplit_bang_innerI:\n  \"ttsplit_bang_inner K sps \\<Gamma>b \\<Gamma>1 \\<Gamma>2\n    \\<Longrightarrow> ttsplit_bang_inner K (None # sps) (None # \\<Gamma>b) (None # \\<Gamma>1) (None # \\<Gamma>2)\"\n  \"K \\<turnstile> \\<gamma> :\\<kappa>  k \\<Longrightarrow> ttsplit_bang_inner K sps \\<Gamma>b \\<Gamma>1 \\<Gamma>2\n    \\<Longrightarrow> ttsplit_bang_inner K (None # sps) (Some \\<gamma> # \\<Gamma>b) (None # \\<Gamma>1) (Some \\<gamma> # \\<Gamma>2)\"\n  \"K \\<turnstile> \\<gamma> :\\<kappa>  k \\<Longrightarrow> ttsplit_bang_inner K sps \\<Gamma>b \\<Gamma>1 \\<Gamma>2\n    \\<Longrightarrow> ttsplit_bang_inner K (Some TSK_L # sps) (Some \\<gamma> # \\<Gamma>b) (Some \\<gamma> # \\<Gamma>1) (None # \\<Gamma>2)\"\n  \"K \\<turnstile> \\<gamma> :\\<kappa>  k \\<Longrightarrow> S \\<in> k \\<Longrightarrow> ttsplit_bang_inner K sps \\<Gamma>b \\<Gamma>1 \\<Gamma>2\n    \\<Longrightarrow> ttsplit_bang_inner K (Some TSK_S # sps) (Some \\<gamma> # \\<Gamma>b) (Some \\<gamma> # \\<Gamma>1) (Some \\<gamma> # \\<Gamma>2)\"\n  \"K \\<turnstile> \\<gamma> :\\<kappa>  k \\<Longrightarrow> \\<gamma>' = bang \\<gamma> \\<Longrightarrow> ttsplit_bang_inner K sps \\<Gamma>b \\<Gamma>1 \\<Gamma>2\n    \\<Longrightarrow> ttsplit_bang_inner K (Some TSK_NS # sps) (Some \\<gamma> # \\<Gamma>b) (Some \\<gamma>' # \\<Gamma>1) (Some \\<gamma> # \\<Gamma>2)\"\n  \"ttsplit_bang_inner K [] [] [] []\"\n  by (auto simp add: ttsplit_bang_inner_def forall_less_Suc_eq)\n\nlemma Suc_mem_image_pred:\n  \"0 \\<notin> js \\<Longrightarrow> (Suc n \\<in> js) = (n \\<in> pred ` js)\"\n  apply (simp add: image_def pred_def)\n  apply (auto elim: rev_bexI split: nat.split_asm)\n  done\n\nlemma Suc_mem_image_pred_remove:\n  \"(n \\<in> pred ` Set.remove 0 js) = (Suc n \\<in> js)\"\n  by (simp add: Suc_mem_image_pred[symmetric])\n\nlemma split_bang_nth:\n  \"split_bang K is \\<Gamma> \\<Gamma>1 \\<Gamma>2 = (length \\<Gamma>1 = length \\<Gamma> \\<and> length \\<Gamma>2 = length \\<Gamma>\n        \\<and> (\\<forall>i < length \\<Gamma>. if i \\<in> is then \\<Gamma>2 ! i = \\<Gamma> ! i \\<and> \\<Gamma> ! i \\<noteq> None\n                \\<and> \\<Gamma>1 ! i = map_option bang (\\<Gamma> ! i)\n            else split_comp K (\\<Gamma> ! i) (\\<Gamma>1 ! i) (\\<Gamma>2 ! i)))\"\n  apply (induct \\<Gamma> arbitrary: \"is\" \\<Gamma>1 \\<Gamma>2)\n   apply (auto elim: split_bang.cases intro: split_bang_empty)[1]\n  apply (rule iffI)\n   apply (erule split_bang.cases, simp)\n    apply (clarsimp split del: split_if)\n    apply (case_tac i)\n     apply simp\n    apply (simp add: Suc_mem_image_pred split del: split_if cong: if_cong)\n   apply (clarsimp split del: split_if)\n   apply (case_tac i)\n    apply simp\n   apply (simp add: Suc_mem_image_pred_remove split del: split_if cong: if_cong)\n  apply (clarsimp simp: length_Suc_conv forall_less_Suc_eq)\n  apply (frule_tac x=0 in spec, simp(no_asm_use))\n  apply (case_tac \"0 \\<in> is\", simp_all)\n   apply clarsimp\n   apply (erule split_bang_bang, rule refl)\n   apply (simp add: Suc_mem_image_pred_remove split del: split_if cong: if_cong)\n  apply (rule split_bang_cons, (simp_all add: Suc_mem_image_pred split del: split_if cong: if_cong))\n  done\n\nlemma ttsplit_bang_imp_split_bang:\n  \"ttsplit_bang is sps K \\<Gamma> xs \\<Gamma>1 ys \\<Gamma>2 \\<Longrightarrow>\n    (\\<exists>\\<Gamma>1a \\<Gamma>2a. split_bang K is (snd \\<Gamma>) \\<Gamma>1a \\<Gamma>2a\n        \\<and> snd \\<Gamma>1 = xs @ \\<Gamma>1a & snd \\<Gamma>2 = ys @ \\<Gamma>2a)\"\n  apply (clarsimp simp: ttsplit_bang_def ttsplit_bang_inner_def\n                        split_bang_nth nth_enumerate_eq\n              split del: split_if cong: if_cong)\n  apply clarsimp\n  apply (case_tac \"\\<Gamma>b ! i\")\n   apply (simp add: split_comp.none)\n  apply (drule spec, drule(1) mp)+\n  apply (auto intro: split_comp.intros)\n  done\n\nlemma ttsplit_bang_inner_Cons:\n  \"ttsplit_bang_inner K sps \\<Gamma>b \\<Gamma>1 \\<Gamma>2\n    \\<Longrightarrow> ttsplit_bang_inner K [sp] [\\<gamma>] [\\<gamma>1] [\\<gamma>2]\n    \\<Longrightarrow> ttsplit_bang_inner K (sp # sps) (\\<gamma> # \\<Gamma>b) (\\<gamma>1 # \\<Gamma>1) (\\<gamma>2 # \\<Gamma>2)\"\n  by (simp add: ttsplit_bang_inner_def forall_less_Suc_eq)\n\nlemma split_bang_imp_ttsplit:\n  \"split_bang K is \\<Gamma> \\<Gamma>1 \\<Gamma>2\n    \\<Longrightarrow> \\<exists>sps. \\<forall>xs ys \\<Gamma>1' \\<Gamma>2'. (\\<Gamma>1' = xs @ \\<Gamma>1 \\<longrightarrow> \\<Gamma>2' = ys @ \\<Gamma>2\n    \\<longrightarrow> ttsplit_bang is sps K (TyTrSplit sps xs tt ys tt2, \\<Gamma>) xs\n        (tt, \\<Gamma>1') ys (tt2, \\<Gamma>2'))\"\n  apply (clarsimp simp: ttsplit_bang_def)\n  apply (induct rule: split_bang.induct)\n    apply (simp add: ttsplit_bang_def ttsplit_bang_inner_def)\n   apply (clarsimp simp: forall_less_Suc_eq Suc_mem_image_pred)\n   apply (rule exI, rule conjI, erule_tac sp=\"if a = None then None\n        else if b = None then Some TSK_L else Some TSK_S\" in ttsplit_bang_inner_Cons)\n    apply (auto simp: ttsplit_bang_inner_def elim!: split_comp.cases)[1]\n   apply (simp add: Set.remove_def)\n  apply (clarsimp simp: forall_less_Suc_eq Suc_mem_image_pred_remove)\n  apply (rule exI, rule conjI, erule_tac sp=\"Some TSK_NS\" in ttsplit_bang_inner_Cons)\n   apply (simp add: ttsplit_bang_inner_def)\n  apply simp\n  done\n\nlemma split_follow_typing_tree:\n  \"ttsplit K \\<Gamma> sps' xs' \\<Gamma>1 ys' \\<Gamma>2 \\<Longrightarrow> (\\<Gamma>1, \\<Gamma>2) = follow_typing_tree \\<Gamma> \\<and> new_tt_types \\<Gamma> = ys'\"\n  \"ttsplit_triv \\<Gamma> xs' \\<Gamma>1 ys' \\<Gamma>2 \\<Longrightarrow> (\\<Gamma>1, \\<Gamma>2) = follow_typing_tree_triv \\<Gamma> \\<and> new_tt_types \\<Gamma> = ys'\"\n  \"ttsplit_bang is sps' K \\<Gamma> xs' \\<Gamma>1 ys' \\<Gamma>2 \\<Longrightarrow> (\\<Gamma>1, \\<Gamma>2) = follow_typing_tree \\<Gamma> \\<and> new_tt_types \\<Gamma> = ys'\"\n    apply (clarsimp simp: ttsplit_def ttsplit_inner_def ball_conj_distrib[symmetric])\n    apply (case_tac a, simp_all)\n    apply (case_tac aa, simp_all)\n    apply (clarsimp elim!: in_set_zipE)\n   apply (cases \\<Gamma>, clarsimp simp: ttsplit_triv_def)\n  apply (clarsimp simp: ttsplit_bang_def ttsplit_bang_inner_def ball_conj_distrib[symmetric])\n  apply (case_tac a, simp_all)\n  apply (case_tac aa, simp_all)\n  done\n\ninductive ttyping :: \"('f \\<Rightarrow> poly_type) \\<Rightarrow> kind env \\<Rightarrow> tree_ctx \\<Rightarrow> 'f expr \\<Rightarrow> type \\<Rightarrow> bool\" \n          (\"_, _, _ T\\<turnstile> _ : _\" [30,0,0,0,20] 60)\nwhere\n\n  ttyping_default: \"\\<lbrakk> \\<not> composite_anormal_expr x\n                    ; \\<Xi>, K, \\<Gamma> \\<turnstile> x : t\n                    \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, (tt, \\<Gamma>) T\\<turnstile> x : t\"\n\n| ttyping_split  : \"\\<lbrakk> ttsplit K \\<Gamma> ijs [] \\<Gamma>1 [Some t, Some u] \\<Gamma>2\n                   ; \\<Xi>, K, \\<Gamma>1 T\\<turnstile> x : TProduct t u\n                   ; \\<Xi>, K, \\<Gamma>2 T\\<turnstile> y : t'\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> T\\<turnstile> Split x y : t'\" \n\n| ttyping_let    : \"\\<lbrakk> ttsplit K \\<Gamma> ijs [] \\<Gamma>1 [Some t] \\<Gamma>2 \n                   ; \\<Xi>, K, \\<Gamma>1 T\\<turnstile> x : t\n                   ; \\<Xi>, K, \\<Gamma>2 T\\<turnstile> y : u\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> T\\<turnstile> Let x y : u\"\n\n| ttyping_letb   : \"\\<lbrakk> ttsplit_bang is sps K \\<Gamma> [] \\<Gamma>1 [Some t] \\<Gamma>2\n                   ; \\<Xi>, K, \\<Gamma>1 T\\<turnstile> x : t\n                   ; \\<Xi>, K, \\<Gamma>2 T\\<turnstile> y : u\n                   ; K \\<turnstile> t :\\<kappa> k\n                   ; E \\<in> k\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> T\\<turnstile> LetBang is x y : u\"\n\n| ttyping_case   : \"\\<lbrakk> ttsplit K \\<Gamma> ijs [] \\<Gamma>1 [] \\<Gamma>2\n                   ; ttsplit_triv \\<Gamma>2 [Some t] \\<Gamma>3 [Some (TSum (filter (\\<lambda> x. fst x \\<noteq> tag) ts))] \\<Gamma>4\n                   ; \\<Xi>, K, \\<Gamma>1 T\\<turnstile> x : TSum ts\n                   ; (tag, t) \\<in> set ts\n                   ; \\<Xi>, K, \\<Gamma>3 T\\<turnstile> a : u\n                   ; \\<Xi>, K, \\<Gamma>4 T\\<turnstile> b : u\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> T\\<turnstile> Case x tag a b : u\" \n\n| ttyping_if     : \"\\<lbrakk> ttsplit K \\<Gamma> ijs [] \\<Gamma>1 [] \\<Gamma>2\n                   ; ttsplit_triv \\<Gamma>2 [] \\<Gamma>3 [] \\<Gamma>4\n                   ; \\<Xi>, K, \\<Gamma>1 T\\<turnstile> x : TPrim Bool\n                   ; \\<Xi>, K, \\<Gamma>3 T\\<turnstile> a : t\n                   ; \\<Xi>, K, \\<Gamma>4 T\\<turnstile> b : t\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> T\\<turnstile> If x a b : t\"\n\n| ttyping_take   : \"\\<lbrakk> ttsplit K \\<Gamma> ijs [] \\<Gamma>1 [Some t, Some (TRecord (ts [f := (t, taken)]) s)] \\<Gamma>2 \n                   ; \\<Xi>, K, \\<Gamma>1 T\\<turnstile> e : TRecord ts s\n                   ; s \\<noteq> ReadOnly\n                   ; f < length ts\n                   ; ts ! f = (t, False)\n                   ; K \\<turnstile> t :\\<kappa> k\n                   ; S \\<in> k \\<or> taken\n                   ; \\<Xi>, K, \\<Gamma>2 T\\<turnstile> e' : u\n                   \\<rbrakk> \\<Longrightarrow> \\<Xi>, K, \\<Gamma> T\\<turnstile> Take e f e' : u\"\n\n\nlemma ttyping_imp_typing:\nassumes \"\\<Xi>, K, \\<Gamma> T\\<turnstile> e : u\"\nshows   \"\\<Xi>, K, (snd \\<Gamma>) \\<turnstile> e : u\"\nusing assms by ( induct rule: ttyping.induct\n               , auto simp:  ttsplit_triv_def\n                      dest!: ttsplit_imp_split ttsplit_bang_imp_split_bang\n                      intro: typing_typing_all.intros)\n\nlemma typing_imp_ttyping_induct:\nshows \" (\\<Xi>, K, \\<Gamma> \\<turnstile> e : u \\<Longrightarrow> (\\<exists> tt. \\<Xi>, K, (tt, \\<Gamma>) T\\<turnstile> e : u))\"\nand   \" (\\<Xi>, K, \\<Gamma> \\<turnstile>* es : us \\<Longrightarrow> True)\"\nproof (induct rule: typing_typing_all.inducts)\n  \nqed (fastforce intro: ttyping_split[rotated] ttyping_let[rotated] ttyping_letb[rotated]\n                      ttyping_case[rotated 2] ttyping_if[rotated 2] ttyping_take[rotated 2]\n                      ttyping_default typing_typing_all.intros\n            simp: composite_anormal_expr_def ttsplit_triv_def\n            elim: split_imp_ttsplit\n    | metis split_bang_imp_ttsplit ttyping_letb append.simps)+\n\n\nlemma ttyping_eq_typing:\nshows \"\\<Xi>, K, \\<Gamma> \\<turnstile> e : u = (\\<exists> tt. \\<Xi>, K, (tt, \\<Gamma>) T\\<turnstile> e : u)\"\nby (auto dest: ttyping_imp_typing typing_imp_ttyping_induct)\n\nlemma split_type_wellformed:\n  \"K \\<turnstile> \\<Gamma> \\<leadsto> \\<Gamma>1 | \\<Gamma>2 \\<Longrightarrow> Some t \\<in> set \\<Gamma>\n    \\<Longrightarrow> K \\<turnstile>  t wellformed\"\n  by (induct rule: split.induct, auto elim!: split_comp.cases)\n\nlemma split_bang_type_wellformed:\n  \"split_bang K is \\<Gamma> \\<Gamma>1 \\<Gamma>2 \\<Longrightarrow> Some t \\<in> set \\<Gamma>\n    \\<Longrightarrow> Some t \\<in> set \\<Gamma>1 \\<or> Some t \\<in> set \\<Gamma>2 \\<or> K \\<turnstile>  t wellformed\"\n  by (induct arbitrary: \"is\" rule: split_bang.induct,\n    auto elim!: split_comp.cases)\n\nlemma weakening_type_wellformed:\n  \"K \\<turnstile> \\<Gamma> \\<leadsto>w \\<Gamma>' \\<Longrightarrow> Some t \\<in> set \\<Gamma>\n    \\<Longrightarrow> K \\<turnstile>  t wellformed\"\n  apply (clarsimp simp: weakening_def in_set_conv_decomp\n                        list_all2_append1 list_all2_Cons1)\n  apply (erule weakening_comp.cases, auto)\n  done\n\nlemma typing_to_kinding_env:\n  \"\\<Xi>, K, \\<Gamma> \\<turnstile> e : u \\<Longrightarrow> Some t \\<in> set \\<Gamma>\n    \\<Longrightarrow> K \\<turnstile>  t wellformed\"\n  \"\\<Xi>, K, \\<Gamma> \\<turnstile>* es : us \\<Longrightarrow> Some t \\<in> set \\<Gamma>\n    \\<Longrightarrow> K \\<turnstile>  t wellformed\"\n  by (induct rule: typing_typing_all.inducts,\n    auto simp add: Cogent.empty_def\n      dest: split_bang_type_wellformed weakening_type_wellformed split_type_wellformed)\n\nlemma ttyping_type_wellformed:\n  \"\\<lbrakk> \\<Xi>, K, \\<Gamma> T\\<turnstile> x : \\<tau> \\<rbrakk>\n    \\<Longrightarrow> \\<forall>t. Some t \\<in> set (snd \\<Gamma>) \\<longrightarrow> K \\<turnstile>  t wellformed\"\n  by (induct rule: ttyping.induct,\n    auto dest!: ttsplit_imp_split ttsplit_bang_imp_split_bang\n      dest: split_bang_type_wellformed split_type_wellformed typing_to_kinding_env)\n\nend\n", "meta": {"author": "crizkallah", "repo": "cogent", "sha": "cb16e8169d4389e32dc4aecf4eb9f57173264006", "save_path": "github-repos/isabelle/crizkallah-cogent", "path": "github-repos/isabelle/crizkallah-cogent/cogent-cb16e8169d4389e32dc4aecf4eb9f57173264006/cogent/isa/TypeTrackingTyping.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6334102775181399, "lm_q2_score": 0.399811640739795, "lm_q1q2_score": 0.25324480231597646}}
{"text": "(*  Title:      HOL/Auth/n_german_lemma_invs_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_german Protocol Case Study*} \n\ntheory n_german_lemma_invs_on_rules imports n_german_lemma_inv__1_on_rules n_german_lemma_inv__2_on_rules n_german_lemma_inv__3_on_rules n_german_lemma_inv__4_on_rules n_german_lemma_inv__5_on_rules n_german_lemma_inv__6_on_rules n_german_lemma_inv__7_on_rules n_german_lemma_inv__8_on_rules n_german_lemma_inv__9_on_rules n_german_lemma_inv__10_on_rules n_german_lemma_inv__11_on_rules n_german_lemma_inv__12_on_rules n_german_lemma_inv__13_on_rules n_german_lemma_inv__14_on_rules n_german_lemma_inv__15_on_rules n_german_lemma_inv__16_on_rules n_german_lemma_inv__17_on_rules n_german_lemma_inv__18_on_rules n_german_lemma_inv__19_on_rules n_german_lemma_inv__20_on_rules n_german_lemma_inv__21_on_rules n_german_lemma_inv__22_on_rules n_german_lemma_inv__23_on_rules n_german_lemma_inv__24_on_rules n_german_lemma_inv__25_on_rules n_german_lemma_inv__26_on_rules n_german_lemma_inv__27_on_rules n_german_lemma_inv__28_on_rules n_german_lemma_inv__29_on_rules n_german_lemma_inv__30_on_rules n_german_lemma_inv__31_on_rules n_german_lemma_inv__32_on_rules n_german_lemma_inv__33_on_rules n_german_lemma_inv__34_on_rules n_german_lemma_inv__35_on_rules n_german_lemma_inv__36_on_rules n_german_lemma_inv__37_on_rules n_german_lemma_inv__38_on_rules n_german_lemma_inv__39_on_rules n_german_lemma_inv__40_on_rules n_german_lemma_inv__41_on_rules n_german_lemma_inv__42_on_rules n_german_lemma_inv__43_on_rules n_german_lemma_inv__44_on_rules n_german_lemma_inv__45_on_rules n_german_lemma_inv__46_on_rules n_german_lemma_inv__47_on_rules n_german_lemma_inv__48_on_rules n_german_lemma_inv__49_on_rules n_german_lemma_inv__50_on_rules n_german_lemma_inv__51_on_rules\nbegin\nlemma invs_on_rules:\n  assumes a1: \"f \\<in> invariants N\" and a2: \"r \\<in> rules N\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have b1: \"(f=inv__1  )\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__2  p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__3  p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__4  p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__5  p__Inv1 p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__6  p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__7  p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__8  p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__9  p__Inv1 p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__10  p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__11  p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__12  p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__13  p__Inv1 p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__14  p__Inv1 p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__15  p__Inv1 p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__16  p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__17  p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__18  p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__19  p__Inv1 p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__20  p__Inv1 p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__21  p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__22  p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__23  p__Inv1 p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__24  p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__25  p__Inv1 p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__26  p__Inv1 p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__27  p__Inv1 p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__28  p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__29  p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__30  p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__31  p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__32  p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__33  p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__34  p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__35  p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__36  p__Inv1 p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__37  p__Inv1 p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__38  p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__39  p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__40  p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__41  p__Inv1 p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__42  p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__43  p__Inv2)\\<or>\n    (\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__44  p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__45  p__Inv1 p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__46  p__Inv1 p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__47  p__Inv1 p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__48  p__Inv1 p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__49  p__Inv1 p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__50  p__Inv1 p__Inv2)\\<or>\n    (\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__51  p__Inv1 p__Inv2)\"\n  apply (cut_tac a1, auto) done\n    moreover {\n      assume c1: \"(f=inv__1  )\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__1_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__2  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__2_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__3  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__3_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__4  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__4_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__5  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__5_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__6  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__6_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__7  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__7_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__8  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__8_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__9  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__9_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__10  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__10_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__11  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__11_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__12  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__12_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__13  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__13_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__14  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__14_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__15  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__15_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__16  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__16_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__17  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__17_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__18  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__18_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__19  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__19_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__20  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__20_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__21  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__21_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__22  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__22_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__23  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__23_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__24  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__24_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__25  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__25_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__26  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__26_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__27  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__27_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__28  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__28_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__29  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__29_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__30  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__30_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__31  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__31_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__32  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__32_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__33  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__33_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__34  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__34_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__35  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__35_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__36  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__36_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__37  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__37_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__38  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__38_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__39  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__39_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__40  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__40_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__41  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__41_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__42  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__42_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__43  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__43_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv2. p__Inv2\\<le>N\\<and>f=inv__44  p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__44_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__45  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__45_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__46  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__46_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__47  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__47_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__48  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__48_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__49  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__49_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__50  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__50_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv1 p__Inv2. p__Inv1\\<le>N\\<and>p__Inv2\\<le>N\\<and>p__Inv1~=p__Inv2\\<and>f=inv__51  p__Inv1 p__Inv2)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__51_on_rules) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "lyj238Gmail", "repo": "newParaVerifier", "sha": "5c2d49bf8e6c46c60efa53c98b0ba5c577d59618", "save_path": "github-repos/isabelle/lyj238Gmail-newParaVerifier", "path": "github-repos/isabelle/lyj238Gmail-newParaVerifier/newParaVerifier-5c2d49bf8e6c46c60efa53c98b0ba5c577d59618/examples/n_german/n_german_lemma_invs_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.6513548782017745, "lm_q2_score": 0.38861802670584894, "lm_q1q2_score": 0.2531282474520022}}
{"text": "           (*-------------------------------------------*\n            |                DFP package                |\n            |                   June 2005               |\n            |               December 2005  (modified)   |\n            |                                           |\n            |   DFP on CSP-Prover ver.3.0               |\n            |              September 2006  (modified)   |\n            |                  April 2007  (modified)   |\n            |                                           |\n            |        Yoshinao Isobe (AIST JAPAN)        |\n            *-------------------------------------------*)\n\ntheory DFP_Deadlock\nimports DFP_Network\nbegin\n\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite UnionT and InterT.                 *)\n(*                  Union (B ` A) = (UN x:A. B x)                      *)\n(*                  Inter (B ` A) = (INT x:A. B x)                     *)\n(*\ndeclare Union_image_eq [simp del]\ndeclare Inter_image_eq [simp del]\n*)\ndeclare Sup_image_eq [simp del]\ndeclare Inf_image_eq [simp del]\n(*  The following simplification rules are deleted in this theory file *)\n(*  because they unexpectly rewrite (notick | t = []t)                 *)\n(*                                                                     *)\n(*                  disj_not1: (~ P | Q) = (P --> Q)                   *)\n\ndeclare disj_not1 [simp del]\n\n(*****************************************************************\n\n         1. \n         2. \n         3. \n         4. \n\n *****************************************************************)\n\n(*********************************************************\n                    definitions\n *********************************************************)\n\ndefinition\n  DeadlockFree :: \"'a event set => ('p,'a) proc => bool\" \n                                           (\"(0[_]-DeadlockFree _)\" [0,55] 55)\n  where\n  DeadlockFree_def : \n    \"[X]-DeadlockFree P == (ALL s. (Tick ~: sett(s)) --> (s,X) ~:f failures P MF)\"\n\n  (* R is deadlock free with respect to X, thus\n     R can always perform an event in X at least *)\n\ndefinition     \n  DeadlockFreeNetwork :: \"('i,'p,'a) Network => bool\" \n  where\n  DeadlockFreeNetwork_def : \n    \"DeadlockFreeNetwork V == \n     [Ev ` (ALP V)]-DeadlockFree PAR V\"\n\n\n(*** UNIV deadlockfree ***)\n\nsyntax\n  \"@isDeadlockFree\"  :: \"('p,'a) proc => bool\" \n                         (\"_ isDeadlockFree\" [1000] 1000)\n\ntranslations\n  \"P isDeadlockFree\"  == \"[(CONST UNIV)]-DeadlockFree P\"\n\ndefinition\n  isDeadlockStateOf :: \n   \"('i,'a) net_state => ('i,'a) NetworkF => bool\"\n                           (\"(0_ isDeadlockStateOf _)\" [55,55] 55)\n  where\n  isDeadlockStateOf_def : \n   \"sigma isDeadlockStateOf VF == \n                sigma isStateOf VF & \n                Union {((snd sigma) i) |i. i : fst VF}\n                = Ev ` (ALP VF)\"\n\n(*********************************************************\n           isDeadlockStateOf subset alpha\n *********************************************************)\n\nlemma isDeadlockStateOf_subset_alpha1:\n   \"[| (I, FXf) isFailureOf (I, PXf) ; \n       (t, Yf) isDeadlockStateOf (I, FXf) ;\n       i : I ; e : Yf i|]\n    ==> e : (Ev ` (snd (PXf i)))\"\napply (simp add: isDeadlockStateOf_def)\napply (auto simp add: isStateOf_subset_alpha)\ndone\n\nlemma isDeadlockStateOf_subset_alpha2:\n   \"[| (I, FXf) isFailureOf (I, PXf) ; \n       (t, Yf) isDeadlockStateOf (I, FXf) ;\n       i : I ; e : Yf i|]\n    ==> e : (Ev ` (snd (FXf i)))\"\napply (simp add: isDeadlockStateOf_def)\napply (auto simp add: isStateOf_subset_alpha)\ndone\n\nlemmas isDeadlockStateOf_subset_alpha = isDeadlockStateOf_subset_alpha1\n                                        isDeadlockStateOf_subset_alpha2\n\n(*********************************************************\n             Deadlock and Deadlock freedom\n *********************************************************)\n\n(*** Existency ***)\n\nlemma DeadlockState_notDeadlockFree_only_if_lmEX_lm:\n  \"[|  ALL s Y.\n                 (s, Y) : fst (FXf i) -->\n                 (s, Y) :f failures (fst (PXf i)) MF & Y <= Ev ` snd (FXf i);\n        (s rest-tr snd (FXf i), Z) : fst (FXf i);\n              Yf i Int Ev ` snd (FXf i) <= Z |]\n           ==> (s rest-tr snd (FXf i),\n                SOME Z.\n                   (s rest-tr snd (FXf i), Z) : fst (FXf i) &\n                   Yf i Int Ev ` snd (FXf i) <= Z & Z <= Ev ` snd (FXf i))\n               : fst (FXf i) &\n               Yf i Int Ev ` snd (FXf i)\n               <= (SOME Z.\n                      (s rest-tr snd (FXf i), Z) : fst (FXf i) &\n                      Yf i Int Ev ` snd (FXf i) <= Z & Z <= Ev ` snd (FXf i)) &\n               (SOME Z.\n                   (s rest-tr snd (FXf i), Z) : fst (FXf i) &\n                   Yf i Int Ev ` snd (FXf i) <= Z & Z <= Ev ` snd (FXf i))\n               <= Ev ` snd (FXf i)\"\napply (rule someI2[of\n\"(%Z. (s rest-tr snd (FXf i), Z) : fst (FXf i) &\n      Yf i Int Ev ` snd (FXf i) <= Z & Z <= Ev ` snd (FXf i))\" Z])\napply (rule conjI)\napply (simp)\napply (simp)\napply (simp)\ndone\n\nlemma DeadlockState_notDeadlockFree_only_if_lmEX:\n   \"[| (I, FXf) isFailureOf (I, PXf) ;\n       ALL i:I. (s rest-tr (snd (PXf i)), Yf i)\n                :f failures (fst (PXf i)) MF |]\n    ==>\n    EX Zf. ALL i:I. (s rest-tr (snd (FXf i)), Zf i) : fst (FXf i) &\n                    Yf i Int Ev ` snd (FXf i) <= Zf i &\n                    Zf i <= Ev ` snd (FXf i)\"\n apply (rule_tac x=\n   \"(%i. (SOME Z. (s rest-tr (snd (FXf i)), Z) : fst (FXf i) &\n                    Yf i Int Ev ` snd (FXf i) <= Z &\n                    Z <= Ev ` snd (FXf i)))\" in exI)\napply (intro ballI impI)\napply (simp add: isFailureOf_def)\napply (drule_tac x=\"i\" in bspec, simp)\napply (drule_tac x=\"i\" in bspec, simp)\napply (simp add: subseteqEX_restRefusal_iff)\napply (elim conjE exE)\napply (rotate_tac -2)\n\napply (drule_tac x=\"s rest-tr snd (FXf i)\" in spec)\napply (drule_tac x=\"Yf i\" in spec)\napply (simp)\napply (elim conjE exE)\napply (rule DeadlockState_notDeadlockFree_only_if_lmEX_lm)\napply (simp_all)\napply (force)\ndone\n\n(* only if part *)\n       \nlemma DeadlockState_notDeadlockFree_only_if:\n  \"[| I ~= {} ; finite I ; (I,FXf) isFailureOf (I,PXf) ;\n      ~ DeadlockFreeNetwork (I,PXf) |]\n   ==> (EX sigma. (sigma isDeadlockStateOf (I,FXf)))\"\napply (simp add: DeadlockFreeNetwork_def)\napply (simp add: DeadlockFree_def)\napply (simp add: isDeadlockStateOf_def)\napply (subgoal_tac \"Union (snd ` PXf ` I) = {a. EX i:I. a : snd (FXf i)}\")\n                                               (* ... sub 1 *)\n\n apply (elim conjE exE)\n apply (simp add: PAR_def)\n apply (simp add: in_failures_par)\n apply (elim conjE exE)\n\n apply (subgoal_tac \n   \"EX Zf. ALL i:I. (s rest-tr (snd (FXf i)), Zf i) :  fst (FXf i) & \n           ((Yf i) Int (Ev ` snd (FXf i))) <= Zf i &\n           Zf i <= (Ev ` snd (FXf i))\")\n                                               (* ... sub 2 *)\n  apply (elim conjE exE)\n\n apply (rule_tac x=\"s\" in exI)\n apply (rule_tac x=\"Zf\" in exI)\n apply (rule conjI)\n\n  apply (simp add: isStateOf_def)\n  apply (simp add: ALP_def)\n  apply (simp add: subset_insert)\n\n  (* set *)\n  apply (simp add: ALP_def)\n  apply (simp add: isFailureOf_def)\n  apply (simp add: Int_insert_eq)\n  apply (rule)\n   (* <= *)\n   apply (rotate_tac -3)\n   apply (drule sym)\n   apply (simp)\n   apply (rule)\n   apply (simp)\n   apply (elim conjE exE)\n   apply (simp)\n   apply (rotate_tac 1)\n   apply (drule_tac x=\"i\" in bspec, simp)\n   apply (elim conjE)\n\n   apply (rule rev_subsetD)\n   apply (simp)\n   apply (simp)\n   apply (rule order_trans)\n   apply (simp)\n\n   apply (rule)\n   apply (simp add: image_iff)\n   apply (elim conjE bexE)\n   apply (simp)\n   apply (rule_tac x=\"i\" in bexI)\n   apply (simp)\n   apply (simp)\n\n   (* => *)\n   apply (rule)\n   apply (simp)\n   apply (elim conjE bexE exE)\n   apply (simp)\n   apply (rule_tac x=\"Zf i\" in exI)\n   apply (rule conjI)\n   apply (fast)\n\n   apply (elim conjE disjE)\n    apply (drule_tac x=\"i\" in bspec, simp)\n    apply (simp)\n    apply (subgoal_tac \n      \"Tick : Union {(Yf i Int insert Tick (Ev ` snd (PXf i))) |i. i : I}\")\n     apply (rotate_tac 5)\n     apply (drule sym)\n     apply (simp add: image_iff)\n    apply (simp)\n    apply (rule_tac x=\"Yf i Int insert Tick (Ev ` snd (PXf i))\" in exI, simp)\n    apply (rule_tac x=\"i\" in exI, simp)\n\n    apply (rotate_tac -5)\n    apply (drule_tac x=\"i\" in bspec, simp)\n    apply (elim conjE disjE)\n    apply (rule subsetD)\n    apply (simp)\n    apply (fast)\n\n (* sub 2 *)\n apply (simp add: DeadlockState_notDeadlockFree_only_if_lmEX)\n\n(* sub 1 *)\napply (simp add: isFailureOf_def)\napply (auto)\ndone\n\n(*** if part ***)\n\nlemma DeadlockState_notDeadlockFree_if:\n  \"[| I ~= {} ; finite I ; (I,FXf) isFailureOf (I,PXf) ;\n      EX sigma. (sigma isDeadlockStateOf (I,FXf)) |]\n   ==> ~ DeadlockFreeNetwork (I,PXf)\"\napply (simp add: DeadlockFreeNetwork_def)\napply (simp add: DeadlockFree_def)\napply (simp add: isDeadlockStateOf_def)\n\napply (elim conjE exE)\napply (simp add: PAR_def)\n\napply (rule_tac x=\"a\" in exI)\napply (simp add: in_failures_par)\napply (simp add: isStateOf_def ALP_def)\n\napply (elim conjE exE)\napply (rule conjI)\napply (fast)\napply (rule conjI)\n\napply (rule order_trans)\napply (simp)\napply (simp add: isFailureOf_def)\napply (fast)\n\napply (rule_tac x=\"b\" in exI)\napply (rename_tac s Ys)\napply (drule sym)\napply (simp)\napply (subgoal_tac \"Union (snd ` PXf ` I) = {a. EX i:I. a : snd (PXf i)}\")\napply (simp add: Int_insert_eq)\napply (rule conjI)\n apply (rule)\n\n (* <= *)\n  apply (rule)\n   apply (simp add: image_iff)\n   apply (elim conjE exE bexE)\n   apply (simp)\n   apply (subgoal_tac \"x : Ev ` {a. EX i:I. a : snd (FXf i)}\")\n\n    apply (simp)\n    apply (elim conjE exE)\n    apply (rule_tac x=\"Ys ia Int insert Tick (Ev ` snd (PXf ia))\" in exI)\n    apply (rule conjI)\n    apply (fast)\n\n    apply (simp)\n    apply (drule_tac x=\"ia\" in bspec, simp)\n    apply (simp add: isFailureOf_same_alpha)\n    apply (blast)\n\n   apply (simp (no_asm) add: image_iff)\n   apply (rule_tac x=\"xa\" in exI)\n   apply (simp add: isFailureOf_def)\n   apply (force)\n\n (* => *)\n  apply (rule)\n   apply (simp)\n   apply (elim conjE exE)\n   apply (simp add: image_iff)\n   apply (elim disjE conjE exE)\n    apply (drule_tac x=\"i\" in bspec, simp)\n    apply (force)\n\n    apply (elim conjE bexE)\n    apply (rule_tac x=\"xb\" in exI, simp)\n    apply (rule_tac x=\"i\" in bexI)\n    apply (simp)\n    apply (simp)\n\napply (intro ballI)\napply (simp add: isFailureOf_def)\napply (simp add: subseteqEX_restRefusal_iff)\n\napply (auto)\ndone\n\n(*** iff ***)\n\nlemma DeadlockState_notDeadlockFree:\n  \"[| I ~= {} ; finite I ; (I,FXf) isFailureOf (I,PXf) |]\n   ==> (~ DeadlockFreeNetwork (I,PXf)) = \n       (EX sigma. (sigma isDeadlockStateOf (I,FXf)))\"\napply (rule)\napply (rule DeadlockState_notDeadlockFree_only_if, simp_all)\napply (simp add: DeadlockState_notDeadlockFree_if)\ndone\n\n(*** DeadlockFree ***)\n\nlemma DeadlockFree_notDeadlockState:\n  \"[| I ~= {} ; finite I ; (I,FXf) isFailureOf (I,PXf) |]\n   ==> DeadlockFreeNetwork (I,PXf) = \n       (ALL sigma. ~(sigma isDeadlockStateOf (I,FXf)))\"\napply (rule iffI)\napply (rotate_tac -1)\napply (erule contrapos_pp)\napply (simp add: DeadlockState_notDeadlockFree)\napply (rotate_tac -1)\napply (erule contrapos_pp)\napply (simp add: DeadlockState_notDeadlockFree)\ndone\n\n(****************** to add it again ******************)\n\ndeclare disj_not1   [simp]\n(*\ndeclare Union_image_eq [simp]\ndeclare Inter_image_eq [simp]\n*)\ndeclare Sup_image_eq [simp]\ndeclare Inf_image_eq [simp]\nend\n", "meta": {"author": "pefribeiro", "repo": "CSP-Prover", "sha": "8967cc482e5695fca4abb52d9dc2cf36b7b7a44e", "save_path": "github-repos/isabelle/pefribeiro-CSP-Prover", "path": "github-repos/isabelle/pefribeiro-CSP-Prover/CSP-Prover-8967cc482e5695fca4abb52d9dc2cf36b7b7a44e/DFP/DFP_Deadlock.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5583269943353745, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.2530683252493279}}
{"text": "(*  Title:      HOL/HOLCF/IOA/Storage/Correctness.thy\n    Author:     Olaf Müller\n*)\n\nsection \\<open>Correctness Proof\\<close>\n\ntheory Correctness\nimports IOA.SimCorrectness Spec Impl\nbegin\n\ndefault_sort type\n\ndefinition\n  sim_relation :: \"((nat * bool) * (nat set * bool)) set\" where\n  \"sim_relation = {qua. let c = fst qua; a = snd qua ;\n                            k = fst c;   b = snd c;\n                            used = fst a; c = snd a\n                        in\n                        (\\<forall>l\\<in>used. l < k) \\<and> b=c}\"\n\ndeclare split_paired_Ex [simp del]\n\n\n(* Idea: instead of impl_con_lemma do not rewrite impl_ioa, but derive\n         simple lemmas asig_of impl_ioa = impl_sig, trans_of impl_ioa = impl_trans\n   Idea: ?ex. move .. should be generally replaced by a step via a subst tac if desired,\n         as this can be done globally *)\n\nlemma issimulation:\n      \"is_simulation sim_relation impl_ioa spec_ioa\"\napply (simp (no_asm) add: is_simulation_def)\napply (rule conjI)\ntxt \\<open>start states\\<close>\napply (auto)[1]\napply (rule_tac x = \" ({},False) \" in exI)\napply (simp add: sim_relation_def starts_of_def spec_ioa_def impl_ioa_def)\ntxt \\<open>main-part\\<close>\napply (rule allI)+\napply (rule imp_conj_lemma)\napply (rename_tac k b used c k' b' a)\napply (induct_tac \"a\")\napply (simp_all (no_asm) add: sim_relation_def impl_ioa_def impl_trans_def trans_of_def)\napply auto\ntxt \\<open>NEW\\<close>\napply (rule_tac x = \"(used,True)\" in exI)\napply simp\napply (rule transition_is_ex)\napply (simp (no_asm) add: spec_ioa_def spec_trans_def trans_of_def)\ntxt \\<open>LOC\\<close>\napply (rule_tac x = \" (used Un {k},False) \" in exI)\napply (simp add: less_SucI)\napply (rule transition_is_ex)\napply (simp (no_asm) add: spec_ioa_def spec_trans_def trans_of_def)\napply fast\ntxt \\<open>FREE\\<close>\napply (rename_tac nat, rule_tac x = \" (used - {nat},c) \" in exI)\napply simp\napply (rule transition_is_ex)\napply (simp (no_asm) add: spec_ioa_def spec_trans_def trans_of_def)\ndone\n\n\nlemma implementation:\n\"impl_ioa =<| spec_ioa\"\napply (unfold ioa_implements_def)\napply (rule conjI)\napply (simp (no_asm) add: impl_sig_def spec_sig_def impl_ioa_def spec_ioa_def\n  asig_outputs_def asig_of_def asig_inputs_def)\napply (rule trace_inclusion_for_simulations)\napply (simp (no_asm) add: impl_sig_def spec_sig_def impl_ioa_def spec_ioa_def\n  externals_def asig_outputs_def asig_of_def asig_inputs_def)\napply (rule issimulation)\ndone\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/HOLCF/IOA/Storage/Correctness.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318479832805, "lm_q2_score": 0.4186969093556867, "lm_q1q2_score": 0.25286439821206796}}
{"text": "(*  Title:      HOL/Auth/n_deadlock_lemma_invs_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\n(*header{*The n_deadlock Protocol Case Study*}*) \n\ntheory n_deadlock_lemma_invs_on_rules imports n_deadlock_lemma_inv__1_on_rules n_deadlock_lemma_inv__2_on_rules n_deadlock_lemma_inv__3_on_rules n_deadlock_lemma_inv__4_on_rules n_deadlock_lemma_inv__5_on_rules\nbegin\nlemma invs_on_rules:\n  assumes a1: \"f \\<in> invariants N\" and a2: \"r \\<in> rules N\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have b1: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__1  p__Inv3 p__Inv4)\\<or>\n    (\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__2  p__Inv4)\\<or>\n    (\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__3  p__Inv3 p__Inv4)\\<or>\n    (\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__4  p__Inv4)\\<or>\n    (\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__5  p__Inv3 p__Inv4)\"\n  apply (cut_tac a1, auto) done\n    moreover {\n      assume c1: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__1  p__Inv3 p__Inv4)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__1_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__2  p__Inv4)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__2_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__3  p__Inv3 p__Inv4)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__3_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__4  p__Inv4)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__4_on_rules) done\n    }\n\n    moreover {\n      assume c1: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__5  p__Inv3 p__Inv4)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac a2 c1, metis lemma_inv__5_on_rules) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "hongjianjiang", "repo": "paraverif_dafny", "sha": "083d86afb46a847783cb9319d975b3c2ad0afe93", "save_path": "github-repos/isabelle/hongjianjiang-paraverif_dafny", "path": "github-repos/isabelle/hongjianjiang-paraverif_dafny/paraverif_dafny-083d86afb46a847783cb9319d975b3c2ad0afe93/examples/n_deadlock/n_deadlock_lemma_invs_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6039318337259584, "lm_q2_score": 0.41869690935568665, "lm_q1q2_score": 0.25286439224257123}}
{"text": "theory Norm\n  imports Base\nbegin\n\ndefinition Norm where\n  \"Norm \\<Gamma> \\<Gamma>' \\<equiv> \\<Gamma> \\<Longrightarrow>\\<^sub>A \\<Gamma>'\"\n\nlemma normI: \"\\<Gamma> \\<Longrightarrow>\\<^sub>A \\<Gamma>' \\<Longrightarrow> Norm \\<Gamma> \\<Gamma>'\"\n  unfolding Norm_def\n  by simp\n\nmethod normalize uses rules =\n  rule normI, (simp only: star_aci rules)?; rule ent_refl\n             \nend\n", "meta": {"author": "balazstothofficial", "repo": "arrays-in-isabelle", "sha": "9d5dd28b0b3d245dae534d546879045a54b4244f", "save_path": "github-repos/isabelle/balazstothofficial-arrays-in-isabelle", "path": "github-repos/isabelle/balazstothofficial-arrays-in-isabelle/arrays-in-isabelle-9d5dd28b0b3d245dae534d546879045a54b4244f/Norm.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953651858118, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.25284104150788594}}
{"text": "(* \n   Title: Psi-calculi   \n   Author/Maintainer: Jesper Bengtson (jebe@itu.dk), 2012\n*)\ntheory Tau_Chain\n  imports Semantics\nbegin\n\ncontext env begin\n\nabbreviation tauChain :: \"'b \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow> bool\" (\"_ \\<rhd> _ \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> _\" [80, 80, 80] 80)\nwhere \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P' \\<equiv> (P, P') \\<in> {(P, P'). \\<Psi> \\<rhd> P \\<longmapsto>\\<tau> \\<prec> P'}^*\"\n\nabbreviation tauStepChain :: \"'b \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow> bool\" (\"_ \\<rhd> _ \\<Longrightarrow>\\<^sub>\\<tau> _\" [80, 80, 80] 80)\nwhere \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P' \\<equiv> (P, P') \\<in> {(P, P'). \\<Psi> \\<rhd> P \\<longmapsto>\\<tau> \\<prec> P'}^+\"\n\nabbreviation tauContextChain :: \"('a, 'b, 'c) psi \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow> bool\" (\"_ \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> _\" [80, 80] 80)\nwhere \"P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P' \\<equiv> \\<one> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\nabbreviation tauContextStepChain :: \"('a, 'b, 'c) psi \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow> bool\" (\"_ \\<Longrightarrow>\\<^sub>\\<tau> _\" [80, 80] 80)\nwhere \"P \\<Longrightarrow>\\<^sub>\\<tau> P' \\<equiv> \\<one> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n\nlemmas tauChainInduct[consumes 1, case_names TauBase TauStep] = rtrancl.induct[of _ _ \"{(P, P'). \\<Psi> \\<rhd> P \\<longmapsto>\\<tau> \\<prec> P'}\", simplified]\nlemmas tauStepChainInduct[consumes 1, case_names TauBase TauStep] = trancl.induct[of _ _ \"{(P, P'). \\<Psi> \\<rhd> P \\<longmapsto>\\<tau> \\<prec> P'}\", simplified]\n\n\nlemma tauActTauStepChain:\n  fixes \\<Psi> :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<longmapsto>\\<tau> \\<prec> P'\"\n\n  shows \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\"\nusing assms by auto\n\nlemma tauActTauChain:\n  fixes \\<Psi> :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<longmapsto>\\<tau> \\<prec> P'\"\n\n  shows \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\nusing assms by(auto simp add: rtrancl_eq_or_trancl)\n\nlemma tauStepChainEqvt[eqvt]:\n  fixes \\<Psi> :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n  and   p  :: \"name prm\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n\n  shows \"(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P) \\<Longrightarrow>\\<^sub>\\<tau> (p \\<bullet> P')\"\nusing assms\nproof(induct rule: tauStepChainInduct)  \n  case(TauBase P P')\n  hence \"\\<Psi> \\<rhd> P \\<longmapsto>\\<tau> \\<prec> P'\" by simp\n  thus ?case by(force dest: semantics.eqvt simp add: eqvts)\nnext\n  case(TauStep P P' P'')\n  hence \"\\<Psi> \\<rhd> P' \\<longmapsto>\\<tau> \\<prec> P''\" by simp  \n  hence \"(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P') \\<longmapsto>\\<tau> \\<prec> (p \\<bullet> P'')\" by(force dest: semantics.eqvt simp add: eqvts)\n  with `(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P) \\<Longrightarrow>\\<^sub>\\<tau> (p \\<bullet> P')` show ?case\n    by(subst trancl.trancl_into_trancl) auto\nqed\n\nlemma tauChainEqvt[eqvt]:\n  fixes \\<Psi> :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n  and   p  :: \"name prm\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n\n  shows \"(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> (p \\<bullet> P')\"\nusing assms\nby(auto simp add: rtrancl_eq_or_trancl eqvts)\n\nlemma tauStepChainEqvt'[eqvt]:\n  fixes \\<Psi> :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n  and   p  :: \"name prm\"\n\n  shows \"(p \\<bullet> (\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P')) = (p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P) \\<Longrightarrow>\\<^sub>\\<tau> (p \\<bullet> P')\"\napply(auto simp add: eqvts perm_set_def pt_bij[OF pt_name_inst, OF at_name_inst])\nby(drule_tac p=\"rev p\" in tauStepChainEqvt) auto\n\nlemma tauChainEqvt'[eqvt]:\n  fixes \\<Psi> :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n  and   p  :: \"name prm\"\n\n  shows \"(p \\<bullet> (\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P')) = (p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> (p \\<bullet> P')\"\napply(auto simp add: eqvts perm_set_def pt_bij[OF pt_name_inst, OF at_name_inst] rtrancl_eq_or_trancl)\nby(drule_tac p=\"rev p\" in tauStepChainEqvt) auto\n\nlemma tauStepChainFresh:\n  fixes \\<Psi> :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n  and   x  :: name\n\n  assumes \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n  and     \"x \\<sharp> P\"\n\n  shows \"x \\<sharp> P'\"\nusing assms\nby(induct rule: trancl.induct) (auto dest: tauFreshDerivative)\n\nlemma tauChainFresh:\n  fixes \\<Psi> :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n  and   x  :: name\n\n  assumes \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n  and     \"x \\<sharp> P\"\n\n  shows \"x \\<sharp> P'\"\nusing assms\nby(auto simp add: rtrancl_eq_or_trancl intro: tauStepChainFresh)\n\nlemma tauStepChainFreshChain:\n  fixes \\<Psi>    :: 'b\n  and   P     :: \"('a, 'b, 'c) psi\"\n  and   P'    :: \"('a, 'b, 'c) psi\"\n  and   xvec  :: \"name list\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n  and     \"xvec \\<sharp>* P\"\n\n  shows \"xvec \\<sharp>* P'\"\nusing assms\nby(induct xvec) (auto intro: tauStepChainFresh)\n\nlemma tauChainFreshChain:\n  fixes \\<Psi>    :: 'b\n  and   P     :: \"('a, 'b, 'c) psi\"\n  and   P'    :: \"('a, 'b, 'c) psi\"\n  and   xvec  :: \"name list\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n  and     \"xvec \\<sharp>* P\"\n\n  shows \"xvec \\<sharp>* P'\"\nusing assms\nby(induct xvec) (auto intro: tauChainFresh)\n\nlemma tauStepChainCase:\n  fixes \\<Psi>  :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n  and   \\<phi>  :: 'c\n  and   Cs :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n  and     \"(\\<phi>, P) mem Cs\"\n  and     \"\\<Psi> \\<turnstile> \\<phi>\"\n  and     \"guarded P\"\n\n  shows \"\\<Psi> \\<rhd> (Cases Cs) \\<Longrightarrow>\\<^sub>\\<tau> P'\"\nusing assms\nby(induct rule: trancl.induct) (auto intro: Case trancl_into_trancl)\n\nlemma tauStepChainResPres:\n  fixes \\<Psi> :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n  and   x  :: name  \n\n  assumes \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n  and     \"x \\<sharp> \\<Psi>\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<Longrightarrow>\\<^sub>\\<tau> \\<lparr>\\<nu>x\\<rparr>P'\"\nusing assms\nby(induct rule: trancl.induct) (auto dest: Scope trancl_into_trancl)\n\nlemma tauChainResPres:\n  fixes \\<Psi> :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n  and   x  :: name  \n\n  assumes \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n  and     \"x \\<sharp> \\<Psi>\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>x\\<rparr>P'\"\nusing assms\nby(auto simp add: rtrancl_eq_or_trancl intro: tauStepChainResPres)\n\nlemma tauStepChainResChainPres:\n  fixes \\<Psi>    :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   xvec :: \"name list\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n  and     \"xvec \\<sharp>* \\<Psi>\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>P \\<Longrightarrow>\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>P'\"\nusing assms\nby(induct xvec) (auto intro: tauStepChainResPres)\n\nlemma tauChainResChainPres:\n  fixes \\<Psi>    :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   xvec :: \"name list\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n  and     \"xvec \\<sharp>* \\<Psi>\"\n\n  shows \"\\<Psi> \\<rhd> \\<lparr>\\<nu>*xvec\\<rparr>P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>*xvec\\<rparr>P'\"\nusing assms\nby(induct xvec) (auto intro: tauChainResPres)\n\nlemma tauStepChainPar1:\n  fixes \\<Psi>  :: 'b\n  and   \\<Psi>\\<^sub>Q :: 'b\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   P'  :: \"('a, 'b, 'c) psi\"\n  and   Q   :: \"('a, 'b, 'c) psi\"\n  and   A\\<^sub>Q :: \"name list\"\n\n  assumes \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n  and     \"extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\"\n  and     \"A\\<^sub>Q \\<sharp>* \\<Psi>\"\n  and     \"A\\<^sub>Q \\<sharp>* P\"\n\n  shows \"\\<Psi> \\<rhd> P \\<parallel> Q \\<Longrightarrow>\\<^sub>\\<tau> P' \\<parallel> Q\"\nusing assms\nby(induct rule: trancl.induct)  (auto dest: Par1 tauStepChainFreshChain trancl_into_trancl)\n\nlemma tauChainPar1:\n  fixes \\<Psi>  :: 'b\n  and   \\<Psi>\\<^sub>Q :: 'b\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   P'  :: \"('a, 'b, 'c) psi\"\n  and   Q   :: \"('a, 'b, 'c) psi\"\n  and   A\\<^sub>Q :: \"name list\"\n\n  assumes \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n  and     \"extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\"\n  and     \"A\\<^sub>Q \\<sharp>* \\<Psi>\"\n  and     \"A\\<^sub>Q \\<sharp>* P\"\n\n  shows \"\\<Psi> \\<rhd> P \\<parallel> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P' \\<parallel> Q\"\nusing assms\nby(auto simp add: rtrancl_eq_or_trancl intro: tauStepChainPar1)\n\nlemma tauStepChainPar2:\n  fixes \\<Psi>  :: 'b\n  and   \\<Psi>\\<^sub>P :: 'b\n  and   Q   :: \"('a, 'b, 'c) psi\"\n  and   Q'  :: \"('a, 'b, 'c) psi\"\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   A\\<^sub>P :: \"name list\"\n\n  assumes \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<Longrightarrow>\\<^sub>\\<tau> Q'\"\n  and     \"extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\"\n  and     \"A\\<^sub>P \\<sharp>* \\<Psi>\"\n  and     \"A\\<^sub>P \\<sharp>* Q\"\n\n  shows \"\\<Psi> \\<rhd> P \\<parallel> Q \\<Longrightarrow>\\<^sub>\\<tau> P \\<parallel> Q'\"\nusing assms\nby(induct rule: trancl.induct) (auto dest: Par2 trancl_into_trancl tauStepChainFreshChain)\n\nlemma tauChainPar2:\n  fixes \\<Psi>  :: 'b\n  and   \\<Psi>\\<^sub>P :: 'b\n  and   Q   :: \"('a, 'b, 'c) psi\"\n  and   Q'  :: \"('a, 'b, 'c) psi\"\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   A\\<^sub>P :: \"name list\"\n\n  assumes \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q'\"\n  and     \"extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\"\n  and     \"A\\<^sub>P \\<sharp>* \\<Psi>\"\n  and     \"A\\<^sub>P \\<sharp>* Q\"\n\n  shows \"\\<Psi> \\<rhd> P \\<parallel> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P \\<parallel> Q'\"\nusing assms\nby(auto simp add: rtrancl_eq_or_trancl intro: tauStepChainPar2)\n\nlemma tauStepChainBang:\n  fixes \\<Psi>  :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<parallel> !P \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n  and     \"guarded P\"\n\n  shows \"\\<Psi> \\<rhd> !P \\<Longrightarrow>\\<^sub>\\<tau> P'\"\nusing assms\nby(induct x1==\"P \\<parallel> !P\" P' rule: trancl.induct) (auto intro: Bang dest: Bang trancl_into_trancl)\n\nlemma tauStepChainStatEq:\n  fixes \\<Psi>  :: 'b\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   P'  :: \"('a, 'b, 'c) psi\"\n  and   \\<Psi>' :: 'b\n\n  assumes \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n  and     \"\\<Psi> \\<simeq> \\<Psi>'\"\n\n  shows \"\\<Psi>' \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\"\nusing assms\nby(induct rule: trancl.induct) (auto dest: statEqTransition trancl_into_trancl)\n\nlemma tauChainStatEq:\n  fixes \\<Psi>  :: 'b\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   P'  :: \"('a, 'b, 'c) psi\"\n  and   \\<Psi>' :: 'b\n\n  assumes \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n  and     \"\\<Psi> \\<simeq> \\<Psi>'\"\n\n  shows \"\\<Psi>' \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\nusing assms\nby(auto simp add: rtrancl_eq_or_trancl intro: tauStepChainStatEq)\n\ndefinition weakTransition :: \"'b \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow>  ('a, 'b, 'c) psi \\<Rightarrow> 'a action \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow> bool\" (\"_ : _ \\<rhd> _ \\<Longrightarrow>_ \\<prec> _\" [80, 80, 80, 80, 80] 80)\nwhere\n  \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P' \\<equiv> \\<exists>P''. \\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'' \\<and> (insertAssertion (extractFrame Q) \\<Psi>) \\<hookrightarrow>\\<^sub>F (insertAssertion (extractFrame P'') \\<Psi>) \\<and>\n                                          \\<Psi> \\<rhd> P'' \\<longmapsto>\\<alpha> \\<prec> P'\"\n\nlemma weakTransitionI:\n  fixes \\<Psi>   :: 'b\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   P''  :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha>   :: \"'a action\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\"\n  and     \"insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P'') \\<Psi>\"\n  and     \"\\<Psi> \\<rhd> P'' \\<longmapsto>\\<alpha> \\<prec> P'\"\n\n  shows \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P'\"\nusing assms\nby(auto simp add: weakTransition_def)\n\nlemma weakTransitionE:\n  fixes \\<Psi>   :: 'b\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha>    :: \"'a action\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P'\"\n\n  obtains P'' where \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" and \"insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P'') \\<Psi>\"\n                 and \"\\<Psi> \\<rhd> P'' \\<longmapsto>\\<alpha> \\<prec> P'\"\nusing assms\nby(auto simp add: weakTransition_def)\n\nlemma weakTransitionClosed[eqvt]:\n  fixes \\<Psi>   :: 'b\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha>    :: \"'a action\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   p    :: \"name prm\"\n\n  assumes \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P'\"\n\n  shows \"(p \\<bullet> \\<Psi>) : (p \\<bullet> Q) \\<rhd> (p \\<bullet> P) \\<Longrightarrow>(p \\<bullet> \\<alpha>)\\<prec> (p \\<bullet> P')\"\nproof -\n  from assms obtain P'' where \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" and \"insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P'') \\<Psi>\"\n                           and \"\\<Psi> \\<rhd> P'' \\<longmapsto>\\<alpha> \\<prec> P'\"\n    by(rule weakTransitionE)\n\n  from `\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''` have \"(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P) \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> (p \\<bullet> P'')\"\n    by(rule tauChainEqvt)\n  moreover from `insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P'') \\<Psi>` \n  have \"(p \\<bullet> (insertAssertion (extractFrame Q) \\<Psi>)) \\<hookrightarrow>\\<^sub>F (p \\<bullet> (insertAssertion (extractFrame P'') \\<Psi>))\"\n    by(rule FrameStatImpClosed)\n  hence \"insertAssertion (extractFrame(p \\<bullet> Q)) (p \\<bullet> \\<Psi>) \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame(p \\<bullet> P'')) (p \\<bullet> \\<Psi>)\" by(simp add: eqvts)\n  moreover from `\\<Psi> \\<rhd> P'' \\<longmapsto>\\<alpha> \\<prec> P'` have \"(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P'') \\<longmapsto>(p \\<bullet> (\\<alpha> \\<prec> P'))\"\n    by(rule semantics.eqvt)\n  hence \"(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P'') \\<longmapsto>(p \\<bullet> \\<alpha>) \\<prec> (p \\<bullet> P')\" by(simp add: eqvts)\n  ultimately show ?thesis by(rule weakTransitionI)\nqed\n(*\nlemma weakTransitionAlpha:\n  fixes \\<Psi>   :: 'b\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   xvec :: \"name list\"\n  and   N    :: 'a\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   p    :: \"name prm\"\n  and   yvec :: \"name list\"\n\n  assumes PTrans: \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P'\"\n  and     S: \"set p \\<subseteq> set xvec \\<times> set(p \\<bullet> xvec)\"\n  and     \"xvec \\<sharp>* (p \\<bullet> xvec)\"\n  and     \"(p \\<bullet> xvec) \\<sharp>* P\"\n  and     \"(p \\<bullet> xvec) \\<sharp>* N\"\n\n  shows \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>M\\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> (p \\<bullet> P')\"\nproof -\n  from PTrans obtain P'' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" and QeqP'': \"insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P'') \\<Psi>\"\n                           and P''Trans: \"\\<Psi> \\<rhd> P'' \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n    by(rule weakTransitionE)\n\n  note PChain QeqP''\n  moreover from PChain `(p \\<bullet> xvec) \\<sharp>* P` have \"(p \\<bullet> xvec) \\<sharp>* P''\" by(rule tauChainFreshChain)\n  with P''Trans `xvec \\<sharp>* (p \\<bullet> xvec)` `(p \\<bullet> xvec) \\<sharp>* N` have \"(p \\<bullet> xvec) \\<sharp>* P'\"\n    by(force intro: outputFreshChainDerivative)\n  with P''Trans S `(p \\<bullet> xvec) \\<sharp>* N` have \"\\<Psi> \\<rhd> P'' \\<longmapsto>M\\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> (p \\<bullet> P')\"\n    by(simp add: boundOutputChainAlpha'')\n  ultimately show ?thesis by(rule weakTransitionI)\nqed\n*)\nlemma weakOutputAlpha:\n  fixes \\<Psi>   :: 'b\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   xvec :: \"name list\"\n  and   N    :: 'a\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   p    :: \"name prm\"\n  and   yvec :: \"name list\"\n\n  assumes PTrans: \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>M\\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> P'\"\n  and     S: \"set p \\<subseteq> set xvec \\<times> set(p \\<bullet> xvec)\"\n  and     \"distinctPerm p\"\n  and     \"xvec \\<sharp>* P\"\n  and     \"xvec \\<sharp>* (p \\<bullet> xvec)\"\n  and     \"(p \\<bullet> xvec) \\<sharp>* M\"\n  and     \"distinct xvec\"\n\n  shows \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> (p \\<bullet> P')\"\nproof -\n  from PTrans obtain P'' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" and QeqP'': \"insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P'') \\<Psi>\"\n                           and P''Trans: \"\\<Psi> \\<rhd> P'' \\<longmapsto>M\\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> P'\"\n    by(rule weakTransitionE)\n\n\n  note PChain QeqP''\n  moreover from PChain `xvec \\<sharp>* P` have \"xvec \\<sharp>* P''\" by(rule tauChainFreshChain)\n  with P''Trans `xvec \\<sharp>* (p \\<bullet> xvec)` `distinct xvec` `(p \\<bullet> xvec) \\<sharp>* M` have \"xvec \\<sharp>* (p \\<bullet> N)\" and \"xvec \\<sharp>* P'\"\n    by(force intro: outputFreshChainDerivative)+\n  hence \"(p \\<bullet> xvec) \\<sharp>* (p \\<bullet> p \\<bullet> N)\" and \"(p \\<bullet> xvec) \\<sharp>* (p \\<bullet> P')\"\n    by(simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])+\n  with `distinctPerm p` have \"(p \\<bullet> xvec) \\<sharp>* N\" and \"(p \\<bullet> xvec) \\<sharp>* (p \\<bullet> P')\" by simp+\n  with P''Trans S `distinctPerm p` have \"\\<Psi> \\<rhd> P'' \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> (p \\<bullet> P')\"\n    apply(simp add: residualInject)\n    by(subst boundOutputChainAlpha) auto\n    \n  ultimately show ?thesis by(rule weakTransitionI)\nqed\n\nlemma weakFreshDerivative:\n  fixes \\<Psi>   :: 'b\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha>    :: \"'a action\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   x    :: name\n\n  assumes PTrans: \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P'\"\n  and     \"x \\<sharp> P\"\n  and     \"x \\<sharp> \\<alpha>\"\n  and     \"bn \\<alpha> \\<sharp>* subject \\<alpha>\"\n  and     \"distinct(bn \\<alpha>)\"\n\n  shows \"x \\<sharp> P'\"\nproof -\n  from PTrans obtain P'' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" and P''Trans: \"\\<Psi> \\<rhd> P'' \\<longmapsto>\\<alpha> \\<prec> P'\"\n    by(rule weakTransitionE)\n\n  from PChain `x \\<sharp> P` have \"x \\<sharp> P''\" by(rule tauChainFresh)\n  with P''Trans show \"x \\<sharp> P'\" using `x \\<sharp> \\<alpha>` `bn \\<alpha> \\<sharp>* subject \\<alpha>` `distinct(bn \\<alpha>)`\n    by(force intro: freeFreshDerivative)\nqed\n\nlemma weakFreshChainDerivative:\n  fixes \\<Psi>   :: 'b\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha>    :: \"'a action\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   yvec :: \"name list\"\n\n  assumes PTrans: \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P'\"\n  and     \"yvec \\<sharp>* P\"\n  and     \"yvec \\<sharp>* \\<alpha>\"\n  and     \"bn \\<alpha> \\<sharp>* subject \\<alpha>\"\n  and     \"distinct(bn \\<alpha>)\"\n\n  shows \"yvec \\<sharp>* P'\"\nusing assms\nby(induct yvec) (auto intro: weakFreshDerivative)\n\nlemma weakInputFreshDerivative:\n  fixes \\<Psi>   :: 'b\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   N    :: 'a\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   x    :: name\n\n  assumes PTrans: \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>M\\<lparr>N\\<rparr> \\<prec> P'\"\n  and     \"x \\<sharp> P\"\n  and     \"x \\<sharp> N\"\n\n  shows \"x \\<sharp> P'\"\nproof -\n  from PTrans obtain P'' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" and P''Trans: \"\\<Psi> \\<rhd> P'' \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> P'\"\n    by(rule weakTransitionE)\n\n  from PChain `x \\<sharp> P` have \"x \\<sharp> P''\" by(rule tauChainFresh)\n  with P''Trans show \"x \\<sharp> P'\" using `x \\<sharp> N` \n    by(force intro: inputFreshDerivative)\nqed\n\nlemma weakInputFreshChainDerivative:\n  fixes \\<Psi>   :: 'b\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   N    :: 'a\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   xvec :: \"name list\"\n\n  assumes PTrans: \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>M\\<lparr>N\\<rparr> \\<prec> P'\"\n  and     \"xvec \\<sharp>* P\"\n  and     \"xvec \\<sharp>* N\"\n\n  shows \"xvec \\<sharp>* P'\"\nusing assms\nby(induct xvec) (auto intro: weakInputFreshDerivative)\n\nlemma weakOutputFreshDerivative:\n  fixes \\<Psi>   :: 'b\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   xvec :: \"name list\"\n  and   N    :: 'a\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   x    :: name\n\n  assumes PTrans: \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n  and     \"x \\<sharp> P\"\n  and     \"x \\<sharp> xvec\"\n  and     \"xvec \\<sharp>* M\"\n  and     \"distinct xvec\"\n\n  shows \"x \\<sharp> N\"\n  and   \"x \\<sharp> P'\"\nproof -\n  from PTrans obtain P'' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" and P''Trans: \"\\<Psi> \\<rhd> P'' \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n    by(rule weakTransitionE)\n\n  from PChain `x \\<sharp> P` have \"x \\<sharp> P''\" by(rule tauChainFresh)\n  with P''Trans show \"x \\<sharp> N\" and \"x \\<sharp> P'\" using `x \\<sharp> xvec` `xvec \\<sharp>* M` `distinct xvec`\n    by(force intro: outputFreshDerivative)+\nqed\n\nlemma weakOutputFreshChainDerivative:\n  fixes \\<Psi>   :: 'b\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   xvec :: \"name list\"\n  and   N    :: 'a\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   yvec :: \"name list\"\n\n  assumes PTrans: \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n  and     \"yvec \\<sharp>* P\"\n  and     \"xvec \\<sharp>* yvec\"\n  and     \"xvec \\<sharp>* M\"\n  and     \"distinct xvec\"\n\n  shows \"yvec \\<sharp>* N\"\n  and   \"yvec \\<sharp>* P'\"\nproof -\n  from PTrans obtain P'' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" and P''Trans: \"\\<Psi> \\<rhd> P'' \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n    by(rule weakTransitionE)\n\n  from PChain `yvec \\<sharp>* P` have \"yvec \\<sharp>* P''\" by(rule tauChainFreshChain)\n  with P''Trans show \"yvec \\<sharp>* N\" and \"yvec \\<sharp>* P'\" using `xvec \\<sharp>* yvec` `xvec \\<sharp>* M` `distinct xvec`\n    by(force intro: outputFreshChainDerivative)+\nqed\n\nlemma weakOutputPermSubject:\n  fixes \\<Psi>   :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   xvec :: \"name list\"\n  and   N    :: 'a\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   p    :: \"name prm\"\n  and   yvec :: \"name list\"\n  and   zvec :: \"name list\"\n\n  assumes PTrans: \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n  and     S: \"set p \\<subseteq> set yvec \\<times> set zvec\"\n  and     \"yvec \\<sharp>* \\<Psi>\"\n  and     \"zvec \\<sharp>* \\<Psi>\"\n  and     \"yvec \\<sharp>* P\"\n  and     \"zvec \\<sharp>* P\"\n\n  shows \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>(p \\<bullet> M)\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\nproof -\n  from PTrans obtain P'' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" and QeqP'': \"insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P'') \\<Psi>\" \n                            and P''Trans: \"\\<Psi> \\<rhd> P'' \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n    by(rule weakTransitionE)\n\n  from PChain `yvec \\<sharp>* P` `zvec \\<sharp>* P` have \"yvec \\<sharp>* P''\" and \"zvec \\<sharp>* P''\"\n    by(force intro: tauChainFreshChain)+\n\n  note PChain QeqP''\n  moreover from P''Trans S `yvec \\<sharp>* \\<Psi>` `zvec \\<sharp>* \\<Psi>` `yvec \\<sharp>* P''` `zvec \\<sharp>* P''` have \"\\<Psi> \\<rhd> P'' \\<longmapsto>(p \\<bullet> M)\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n    by(rule_tac outputPermSubject) (assumption | auto)\n  ultimately show ?thesis by(rule weakTransitionI)\nqed\n\nlemma weakInputPermSubject:\n  fixes \\<Psi>   :: 'b\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   N    :: 'a\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   p    :: \"name prm\"\n  and   yvec :: \"name list\"\n  and   zvec :: \"name list\"\n\n  assumes PTrans: \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>M\\<lparr>N\\<rparr> \\<prec> P'\"\n  and     S: \"set p \\<subseteq> set yvec \\<times> set zvec\"\n  and     \"yvec \\<sharp>* \\<Psi>\"\n  and     \"zvec \\<sharp>* \\<Psi>\"\n  and     \"yvec \\<sharp>* P\"\n  and     \"zvec \\<sharp>* P\"\n\n  shows \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>(p \\<bullet> M)\\<lparr>N\\<rparr> \\<prec> P'\"\nproof -\n  from PTrans obtain P'' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" and QeqP'': \"insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P'') \\<Psi>\" \n                            and P''Trans: \"\\<Psi> \\<rhd> P'' \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> P'\"\n    by(rule weakTransitionE)\n\n  from PChain `yvec \\<sharp>* P` `zvec \\<sharp>* P` have \"yvec \\<sharp>* P''\" and \"zvec \\<sharp>* P''\"\n    by(force intro: tauChainFreshChain)+\n\n  note PChain QeqP''\n  moreover from P''Trans S `yvec \\<sharp>* \\<Psi>` `zvec \\<sharp>* \\<Psi>` `yvec \\<sharp>* P''` `zvec \\<sharp>* P''` have \"\\<Psi> \\<rhd> P'' \\<longmapsto>(p \\<bullet> M)\\<lparr>N\\<rparr> \\<prec> P'\"\n    by(rule_tac inputPermSubject) auto\n  ultimately show ?thesis by(rule weakTransitionI)\nqed\n\nlemma weakInput:\n  fixes \\<Psi>   :: 'b\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   K    :: 'a\n  and   xvec :: \"name list\"\n  and   N    :: 'a\n  and   Tvec :: \"'a list\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<turnstile> M \\<leftrightarrow> K\"\n  and     \"distinct xvec\" \n  and     \"set xvec \\<subseteq> supp N\"\n  and     \"length xvec = length Tvec\"\n  and     Qeq\\<Psi>: \"insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi> \\<otimes> \\<one>\\<rangle>\"\n\n  shows \"\\<Psi> : Q \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.P \\<Longrightarrow>K\\<lparr>(N[xvec::=Tvec])\\<rparr> \\<prec> P[xvec::=Tvec]\"\nproof -\n  have \"\\<Psi> \\<rhd>  M\\<lparr>\\<lambda>*xvec N\\<rparr>.P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> M\\<lparr>\\<lambda>*xvec N\\<rparr>.P\" by simp\n  moreover from Qeq\\<Psi> have \"insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame(M\\<lparr>\\<lambda>*xvec N\\<rparr>.P)) \\<Psi>\"\n    by auto\n  moreover from assms have \"\\<Psi> \\<rhd> M\\<lparr>\\<lambda>*xvec N\\<rparr>.P \\<longmapsto>K\\<lparr>(N[xvec::=Tvec])\\<rparr> \\<prec> P[xvec::=Tvec]\"\n    by(rule_tac Input)\n  ultimately show ?thesis by(rule weakTransitionI)\nqed\n\nlemma weakOutput:\n  fixes \\<Psi>   :: 'b\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   K    :: 'a\n  and   N    :: 'a\n  and   P    :: \"('a, 'b, 'c) psi\"\n  \n  assumes \"\\<Psi> \\<turnstile> M \\<leftrightarrow> K\"\n  and     Qeq\\<Psi>: \"insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi> \\<otimes> \\<one>\\<rangle>\"\n\n  shows \"\\<Psi> : Q \\<rhd> M\\<langle>N\\<rangle>.P \\<Longrightarrow>K\\<langle>N\\<rangle> \\<prec> P\"\nproof -\n  have \"\\<Psi> \\<rhd>  M\\<langle>N\\<rangle>.P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> M\\<langle>N\\<rangle>.P\" by simp\n  moreover from Qeq\\<Psi> have \"insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame(M\\<langle>N\\<rangle>.P)) \\<Psi>\"\n    by auto\n  moreover have \"insertAssertion (extractFrame(M\\<langle>N\\<rangle>.P)) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame(M\\<langle>N\\<rangle>.P)) \\<Psi>\" by simp\n  moreover from `\\<Psi> \\<turnstile> M \\<leftrightarrow> K` have \"\\<Psi> \\<rhd> M\\<langle>N\\<rangle>.P \\<longmapsto>K\\<langle>N\\<rangle> \\<prec> P\"\n    by(rule Output)\n  ultimately show ?thesis by(rule_tac weakTransitionI) auto\nqed\n\nlemma insertGuardedAssertion:\n  fixes P :: \"('a, 'b, 'c) psi\"\n\n  assumes \"guarded P\"\n\n  shows \"insertAssertion(extractFrame P) \\<Psi> \\<simeq>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi> \\<otimes> \\<one>\\<rangle>\"\nproof -\n  obtain A\\<^sub>P \\<Psi>\\<^sub>P where FrP: \"extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\" by(rule freshFrame)\n  from `guarded P` FrP have \"\\<Psi>\\<^sub>P \\<simeq> \\<one>\" and \"supp \\<Psi>\\<^sub>P = ({}::name set)\"\n    by(blast dest: guardedStatEq)+\n  \n  from FrP `A\\<^sub>P \\<sharp>* \\<Psi>` `\\<Psi>\\<^sub>P \\<simeq> \\<one>` have \"insertAssertion(extractFrame P) \\<Psi> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P, \\<Psi> \\<otimes> \\<one>\\<rangle>\"\n    by simp (metis frameIntCompositionSym)\n  moreover from `A\\<^sub>P \\<sharp>* \\<Psi>` have \"\\<langle>A\\<^sub>P, \\<Psi> \\<otimes> \\<one>\\<rangle> \\<simeq>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi> \\<otimes> \\<one>\\<rangle>\"\n    by(rule_tac frameResFreshChain) auto\n  ultimately show ?thesis by(rule FrameStatEqTrans)\nqed\n  \nlemma weakCase:\n  fixes \\<Psi>   :: 'b \n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha>    :: \"'a action\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   R    :: \"('a, 'b, 'c) psi\"\n\n  assumes PTrans: \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P'\"\n  and     \"(\\<phi>, P) mem CsP\"\n  and     \"\\<Psi> \\<turnstile> \\<phi>\"\n  and     \"guarded P\"\n  and     RImpQ: \"insertAssertion (extractFrame R) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame Q) \\<Psi>\"\n  and     ImpR: \"insertAssertion (extractFrame R) \\<Psi> \\<hookrightarrow>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi>\\<rangle>\"\n\n  shows \"\\<Psi> : R \\<rhd> Cases CsP \\<Longrightarrow>\\<alpha> \\<prec> P'\"\nproof -\n  from PTrans obtain P'' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\"\n                           and QeqP'': \"insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P'') \\<Psi>\"\n                           and P''Trans: \"\\<Psi> \\<rhd> P'' \\<longmapsto>\\<alpha> \\<prec> P'\"\n    by(rule weakTransitionE)\n  show ?thesis\n  proof(case_tac \"P = P''\")\n    assume \"P = P''\"\n    have \"\\<Psi> \\<rhd> Cases CsP \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Cases CsP\" by simp\n    moreover from ImpR AssertionStatEq_def have \"insertAssertion(extractFrame R) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion(extractFrame(Cases CsP)) \\<Psi>\"\n      by(rule_tac FrameStatImpTrans) (auto intro: Identity)+\n\n    moreover from P''Trans `(\\<phi>, P) mem CsP` `\\<Psi> \\<turnstile> \\<phi>` `guarded P` `P = P''` have \"\\<Psi> \\<rhd> Cases CsP \\<longmapsto>\\<alpha> \\<prec> P'\"\n      by(blast intro: Case)\n    ultimately show ?thesis\n      by(rule weakTransitionI)\n  next\n    assume \"P \\<noteq> P''\"\n    with PChain have \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P''\" by(simp add: rtrancl_eq_or_trancl)\n    hence \"\\<Psi> \\<rhd> Cases CsP \\<Longrightarrow>\\<^sub>\\<tau> P''\" using `(\\<phi>, P) mem CsP` `\\<Psi> \\<turnstile> \\<phi>` `guarded P` \n      by(rule tauStepChainCase)\n    hence \"\\<Psi> \\<rhd> Cases CsP \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" by simp\n    moreover from RImpQ QeqP'' have \"insertAssertion(extractFrame R) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion(extractFrame P'') \\<Psi>\"\n      by(rule FrameStatImpTrans)\n    ultimately show ?thesis using P''Trans by(rule weakTransitionI)\n  qed\nqed\n\nlemma weakOpen:\n  fixes \\<Psi>   :: 'b\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  and   N    :: 'a\n  and   P'   :: \"('a, 'b, 'c) psi\"\n\n  assumes PTrans: \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>M\\<lparr>\\<nu>*(xvec@yvec)\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n  and     \"x \\<in> supp N\"\n  and     \"x \\<sharp> \\<Psi>\"\n  and     \"x \\<sharp> M\"\n  and     \"x \\<sharp> xvec\"\n  and     \"x \\<sharp> yvec\"\n\n  shows \"\\<Psi> : \\<lparr>\\<nu>x\\<rparr>Q \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<Longrightarrow>M\\<lparr>\\<nu>*(xvec@x#yvec)\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\nproof -\n  from PTrans obtain P'' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" and QeqP'': \"insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P'') \\<Psi>\"\n                           and P''Trans: \"\\<Psi> \\<rhd> P'' \\<longmapsto>M\\<lparr>\\<nu>*(xvec@yvec)\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n    by(rule weakTransitionE)\n\n  from PChain `x \\<sharp> \\<Psi>` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>x\\<rparr>P''\" by(rule tauChainResPres)\n  moreover from QeqP'' `x \\<sharp> \\<Psi>` have \"insertAssertion (extractFrame(\\<lparr>\\<nu>x\\<rparr>Q)) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame(\\<lparr>\\<nu>x\\<rparr>P'')) \\<Psi>\" by(force intro: frameImpResPres)\n  moreover from P''Trans `x \\<in> supp N` `x \\<sharp> \\<Psi>` `x \\<sharp> M` `x \\<sharp> xvec` `x \\<sharp> yvec` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>P'' \\<longmapsto>M\\<lparr>\\<nu>*(xvec@x#yvec)\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n    by(rule Open)\n  ultimately show ?thesis by(rule weakTransitionI)\nqed\n\nlemma weakScope:\n  fixes \\<Psi>   :: 'b\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha>    :: \"'a action\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n\n  assumes PTrans: \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P'\"\n  and     \"x \\<sharp> \\<Psi>\"\n  and     \"x \\<sharp> \\<alpha>\"\n\n  shows \"\\<Psi> : \\<lparr>\\<nu>x\\<rparr>Q \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<Longrightarrow>\\<alpha> \\<prec> \\<lparr>\\<nu>x\\<rparr>P'\"\nproof -\n  from PTrans obtain P'' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" and QeqP'': \"insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P'') \\<Psi>\"\n                           and P''Trans: \"\\<Psi> \\<rhd> P'' \\<longmapsto>\\<alpha> \\<prec> P'\"\n    by(rule weakTransitionE)\n\n  from PChain `x \\<sharp> \\<Psi>` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> \\<lparr>\\<nu>x\\<rparr>P''\" by(rule tauChainResPres)\n  moreover from QeqP'' `x \\<sharp> \\<Psi>` have \"insertAssertion (extractFrame(\\<lparr>\\<nu>x\\<rparr>Q)) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame(\\<lparr>\\<nu>x\\<rparr>P'')) \\<Psi>\" by(force intro: frameImpResPres)\n  moreover from P''Trans `x \\<sharp> \\<Psi>` `x \\<sharp> \\<alpha>` have \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>P'' \\<longmapsto>\\<alpha> \\<prec> \\<lparr>\\<nu>x\\<rparr>P'\"\n    by(rule Scope)\n  ultimately show ?thesis by(rule weakTransitionI)\nqed\n\n\n\n  assumes PTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q : R \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P'\"\n  and     FrQ: \"extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\"\n  and     \"bn \\<alpha> \\<sharp>* Q\"\n  and     \"A\\<^sub>Q \\<sharp>* \\<Psi>\"\n  and     \"A\\<^sub>Q \\<sharp>* P\"\n  and     \"A\\<^sub>Q \\<sharp>* \\<alpha>\"\n  and     \"A\\<^sub>Q \\<sharp>* R\"\n\n  shows \"\\<Psi> : R \\<parallel> Q \\<rhd> P \\<parallel> Q \\<Longrightarrow>\\<alpha> \\<prec> P' \\<parallel> Q\"\nproof -\n  from PTrans obtain P'' where PChain: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\"\n                           and ReqP'': \"insertAssertion (extractFrame R) (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P'') (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q)\"\n                           and P''Trans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P'' \\<longmapsto>\\<alpha> \\<prec> P'\"\n    by(rule weakTransitionE)\n\n  from PChain `A\\<^sub>Q \\<sharp>* P` have \"A\\<^sub>Q \\<sharp>* P''\" by(rule tauChainFreshChain)\n  from PChain FrQ `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* P` have \"\\<Psi> \\<rhd> P \\<parallel> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'' \\<parallel> Q\" by(rule tauChainPar1)\n  moreover have \"insertAssertion (extractFrame(R \\<parallel> Q)) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame(P'' \\<parallel> Q)) \\<Psi>\"\n  proof -\n    obtain A\\<^sub>R \\<Psi>\\<^sub>R where FrR: \"extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" and \"A\\<^sub>R \\<sharp>* A\\<^sub>Q\" and \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q\" and \"A\\<^sub>R \\<sharp>* \\<Psi>\"\n      by(rule_tac C=\"(A\\<^sub>Q, \\<Psi>\\<^sub>Q, \\<Psi>)\" in freshFrame) auto\n    obtain A\\<^sub>P'' \\<Psi>\\<^sub>P'' where FrP'': \"extractFrame P'' = \\<langle>A\\<^sub>P'', \\<Psi>\\<^sub>P''\\<rangle>\" and \"A\\<^sub>P'' \\<sharp>* A\\<^sub>Q\" and \"A\\<^sub>P'' \\<sharp>* \\<Psi>\\<^sub>Q\" and \"A\\<^sub>P'' \\<sharp>* \\<Psi>\"\n      by(rule_tac C=\"(A\\<^sub>Q, \\<Psi>\\<^sub>Q, \\<Psi>)\" in freshFrame) auto\n\n    from FrR FrP'' `A\\<^sub>Q \\<sharp>* R` `A\\<^sub>Q \\<sharp>* P''` `A\\<^sub>R \\<sharp>* A\\<^sub>Q` `A\\<^sub>P'' \\<sharp>* A\\<^sub>Q` have \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P''\"\n      by(force dest: extractFrameFreshChain)+\n    have \"\\<langle>A\\<^sub>R, \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>\\<^sub>Q\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>R, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n      by(metis frameNilStatEq frameResChainPres Associativity Commutativity Composition AssertionStatEqTrans)\n    moreover from ReqP'' FrR FrP'' `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>P'' \\<sharp>* \\<Psi>` `A\\<^sub>P'' \\<sharp>* \\<Psi>\\<^sub>Q`\n    have \"\\<langle>A\\<^sub>R, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>P''\\<rangle>\" using freshCompChain by auto\n    moreover have \"\\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>P''\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P'', \\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<otimes> \\<Psi>\\<^sub>Q\\<rangle>\"\n      by(metis frameNilStatEq frameResChainPres Associativity Commutativity Composition AssertionStatEqTrans)\n    ultimately have \"\\<langle>A\\<^sub>R, \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>\\<^sub>Q\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P'', \\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<otimes> \\<Psi>\\<^sub>Q\\<rangle>\"\n      by(force dest: FrameStatImpTrans simp add: FrameStatEq_def)\n\n    hence \"\\<langle>(A\\<^sub>R@A\\<^sub>Q), \\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>\\<^sub>Q\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>(A\\<^sub>P''@A\\<^sub>Q), \\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<otimes> \\<Psi>\\<^sub>Q\\<rangle>\"\n      apply(simp add: frameChainAppend)\n      apply(drule_tac xvec=A\\<^sub>Q in frameImpResChainPres)\n      by(metis frameImpChainComm FrameStatImpTrans)\n    with FrR FrQ FrP'' `A\\<^sub>R \\<sharp>* A\\<^sub>Q` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>P'' \\<sharp>* A\\<^sub>Q` `A\\<^sub>P'' \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>Q \\<sharp>* \\<Psi>\\<^sub>P''` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>P'' \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* \\<Psi>` ReqP''\n    show ?thesis by simp\n  qed\n  moreover from P''Trans FrQ `bn \\<alpha> \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* P''` `A\\<^sub>Q \\<sharp>* \\<alpha>` have \"\\<Psi> \\<rhd> P'' \\<parallel> Q \\<longmapsto>\\<alpha> \\<prec> (P' \\<parallel> Q)\"\n    by(rule Par1)  \n  ultimately show ?thesis by(rule weakTransitionI)\nqed\n\nlemma weakPar2:\n  fixes \\<Psi>   :: 'b\n  and   R    :: \"('a, 'b, 'c) psi\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   xvec :: \"name list\"\n  and   N    :: 'a\n  and   Q'   :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   A\\<^sub>P   :: \"name list\"\n  and   \\<Psi>\\<^sub>P  :: 'b\n\n  assumes QTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P : R \\<rhd> Q \\<Longrightarrow>\\<alpha> \\<prec> Q'\"\n  and     FrP: \"extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\"\n  and     \"bn \\<alpha> \\<sharp>* P\"\n  and     \"A\\<^sub>P \\<sharp>* \\<Psi>\"\n  and     \"A\\<^sub>P \\<sharp>* Q\"\n  and     \"A\\<^sub>P \\<sharp>* \\<alpha>\"\n  and     \"A\\<^sub>P \\<sharp>* R\"\n\n  shows \"\\<Psi> : P \\<parallel> R \\<rhd> P \\<parallel> Q \\<Longrightarrow>\\<alpha> \\<prec> P \\<parallel> Q'\"\nproof -\n  from QTrans obtain Q'' where QChain: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> Q''\"\n                           and ReqQ'': \"insertAssertion (extractFrame R) (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame Q'') (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P)\"\n                           and Q''Trans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<rhd> Q'' \\<longmapsto>\\<alpha> \\<prec> Q'\"\n    by(rule weakTransitionE)\n\n  from QChain `A\\<^sub>P \\<sharp>* Q` have \"A\\<^sub>P \\<sharp>* Q''\" by(rule tauChainFreshChain)\n\n  from QChain FrP `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* Q` have \"\\<Psi> \\<rhd> P \\<parallel> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P \\<parallel> Q''\" by(rule tauChainPar2)\n  moreover have \"insertAssertion (extractFrame(P \\<parallel> R)) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame(P \\<parallel> Q'')) \\<Psi>\"\n  proof -\n    obtain A\\<^sub>R \\<Psi>\\<^sub>R where FrR: \"extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\" and \"A\\<^sub>R \\<sharp>* A\\<^sub>P\" and \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P\" and \"A\\<^sub>R \\<sharp>* \\<Psi>\"\n      by(rule_tac C=\"(A\\<^sub>P, \\<Psi>\\<^sub>P, \\<Psi>)\" in freshFrame) auto\n    obtain A\\<^sub>Q'' \\<Psi>\\<^sub>Q'' where FrQ'': \"extractFrame Q'' = \\<langle>A\\<^sub>Q'', \\<Psi>\\<^sub>Q''\\<rangle>\" and \"A\\<^sub>Q'' \\<sharp>* A\\<^sub>P\" and \"A\\<^sub>Q'' \\<sharp>* \\<Psi>\\<^sub>P\" and \"A\\<^sub>Q'' \\<sharp>* \\<Psi>\"\n      by(rule_tac C=\"(A\\<^sub>P, \\<Psi>\\<^sub>P, \\<Psi>)\" in freshFrame) auto\n\n    from FrR FrQ'' `A\\<^sub>P \\<sharp>* R` `A\\<^sub>P \\<sharp>* Q''` `A\\<^sub>R \\<sharp>* A\\<^sub>P` `A\\<^sub>Q'' \\<sharp>* A\\<^sub>P` have \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q''\"\n      by(force dest: extractFrameFreshChain)+\n    have \"\\<langle>A\\<^sub>R, \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>R, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\"\n      by(metis frameNilStatEq frameResChainPres Associativity Commutativity Composition AssertionStatEqTrans)\n\n    moreover from ReqQ'' FrR FrQ'' `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P` `A\\<^sub>Q'' \\<sharp>* \\<Psi>` `A\\<^sub>Q'' \\<sharp>* \\<Psi>\\<^sub>P`\n    have \"\\<langle>A\\<^sub>R, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>Q'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>Q''\\<rangle>\" using freshCompChain by simp\n    moreover have \"\\<langle>A\\<^sub>Q'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P) \\<otimes> \\<Psi>\\<^sub>Q''\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>Q'', \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q''\\<rangle>\"\n      by(metis frameNilStatEq frameResChainPres Associativity Commutativity Composition AssertionStatEqTrans)\n    ultimately have \"\\<langle>A\\<^sub>R, \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>Q'', \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q''\\<rangle>\"\n      by(force dest: FrameStatImpTrans simp add: FrameStatEq_def)\n    hence \"\\<langle>(A\\<^sub>P@A\\<^sub>R), \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>(A\\<^sub>P@A\\<^sub>Q''), \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<Psi>\\<^sub>Q''\\<rangle>\"\n      apply(simp add: frameChainAppend)\n      apply(drule_tac xvec=A\\<^sub>P in frameImpResChainPres)\n      by(metis frameImpChainComm FrameStatImpTrans)\n    with FrR FrP FrQ'' `A\\<^sub>R \\<sharp>* A\\<^sub>P` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>P` `A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>R` `A\\<^sub>Q'' \\<sharp>* A\\<^sub>P` `A\\<^sub>Q'' \\<sharp>* \\<Psi>\\<^sub>P` `A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>Q''` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>Q'' \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* \\<Psi>` ReqQ''\n    show ?thesis by simp\n  qed\n  moreover from Q''Trans FrP `bn \\<alpha> \\<sharp>* P` `A\\<^sub>P \\<sharp>* \\<Psi>` `A\\<^sub>P \\<sharp>* Q''` `A\\<^sub>P \\<sharp>* \\<alpha>` have \"\\<Psi> \\<rhd> P \\<parallel> Q'' \\<longmapsto>\\<alpha> \\<prec> (P \\<parallel> Q')\"\n    by(rule_tac Par2) auto\n  ultimately show ?thesis by(rule weakTransitionI)\nqed\n\nlemma weakComm1:\n  fixes \\<Psi>   :: 'b\n  and   R    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha>    :: \"'a action\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   A\\<^sub>Q   :: \"name list\"\n  and   \\<Psi>\\<^sub>Q   :: 'b\n\n  assumes PTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q : R \\<rhd> P \\<Longrightarrow>M\\<lparr>N\\<rparr> \\<prec> P'\"\n  and     FrR: \"extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\"\n  and     QTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>K\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'\"\n  and     FrQ: \"extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\"\n  and     MeqK: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M \\<leftrightarrow> K\"\n  and     \"A\\<^sub>R \\<sharp>* \\<Psi>\"\n  and     \"A\\<^sub>R \\<sharp>* P\"\n  and     \"A\\<^sub>R \\<sharp>* Q\"\n  and     \"A\\<^sub>R \\<sharp>* R\"\n  and     \"A\\<^sub>R \\<sharp>* M\"\n  and     \"A\\<^sub>R \\<sharp>* A\\<^sub>Q\"\n  and     \"A\\<^sub>Q \\<sharp>* \\<Psi>\"\n  and     \"A\\<^sub>Q \\<sharp>* P\"\n  and     \"A\\<^sub>Q \\<sharp>* Q\"\n  and     \"A\\<^sub>Q \\<sharp>* R\"\n  and     \"A\\<^sub>Q \\<sharp>* K\"\n  and     \"xvec \\<sharp>* P\"\n\n  shows \"\\<Psi> \\<rhd> P \\<parallel> Q \\<Longrightarrow>\\<^sub>\\<tau> (\\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> Q'))\"\nproof -\n  from `extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* P` `A\\<^sub>Q \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* R` `A\\<^sub>Q \\<sharp>* K` `A\\<^sub>R \\<sharp>* A\\<^sub>Q`\n  obtain A\\<^sub>Q' where FrQ': \"extractFrame Q = \\<langle>A\\<^sub>Q', \\<Psi>\\<^sub>Q\\<rangle>\" and \"distinct A\\<^sub>Q'\" and \"A\\<^sub>Q' \\<sharp>* \\<Psi>\" and \"A\\<^sub>Q' \\<sharp>* P\" \n               and \"A\\<^sub>Q' \\<sharp>* Q\" and \"A\\<^sub>Q' \\<sharp>* R\" and \"A\\<^sub>Q' \\<sharp>* K\" and \"A\\<^sub>R \\<sharp>* A\\<^sub>Q'\"\n    by(rule_tac C=\"(\\<Psi>, P, Q, R, K, A\\<^sub>R)\" in distinctFrame) auto\n\n  from PTrans obtain P'' where PChain: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\"\n                           and RimpP'': \"insertAssertion (extractFrame R) (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P'') (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q)\"\n                           and P''Trans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P'' \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> P'\"\n    by(rule weakTransitionE)\n\n  from PChain `A\\<^sub>Q' \\<sharp>* P` have \"A\\<^sub>Q' \\<sharp>* P''\" by(rule tauChainFreshChain)\n  obtain A\\<^sub>P'' \\<Psi>\\<^sub>P'' where FrP'': \"extractFrame P'' = \\<langle>A\\<^sub>P'', \\<Psi>\\<^sub>P''\\<rangle>\" and \"A\\<^sub>P'' \\<sharp>* (\\<Psi>, A\\<^sub>Q', \\<Psi>\\<^sub>Q, A\\<^sub>R, \\<Psi>\\<^sub>R, M, N, K, R, Q, P'', xvec)\" and \"distinct A\\<^sub>P''\"\n    by(rule freshFrame)\n  hence \"A\\<^sub>P'' \\<sharp>* \\<Psi>\" and \"A\\<^sub>P'' \\<sharp>* A\\<^sub>Q'\" and \"A\\<^sub>P'' \\<sharp>* \\<Psi>\\<^sub>Q\" and \"A\\<^sub>P'' \\<sharp>* M\" and \"A\\<^sub>P'' \\<sharp>* R\" and \"A\\<^sub>P'' \\<sharp>* Q\"\n    and \"A\\<^sub>P'' \\<sharp>* N\" and \"A\\<^sub>P'' \\<sharp>* K\" and \"A\\<^sub>P'' \\<sharp>* A\\<^sub>R\" and \"A\\<^sub>P'' \\<sharp>* P''\" and \"A\\<^sub>P'' \\<sharp>* xvec\" and \"A\\<^sub>P'' \\<sharp>* \\<Psi>\\<^sub>R\"\n    by simp+\n  from FrR `A\\<^sub>R \\<sharp>* A\\<^sub>Q'` `A\\<^sub>Q' \\<sharp>* R` have \"A\\<^sub>Q' \\<sharp>* \\<Psi>\\<^sub>R\" by(drule_tac extractFrameFreshChain) auto\n  from FrQ' `A\\<^sub>R \\<sharp>* A\\<^sub>Q'` `A\\<^sub>R \\<sharp>* Q` have \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q\" by(drule_tac extractFrameFreshChain) auto\n  from PChain `xvec \\<sharp>* P` have \"xvec \\<sharp>* P''\" by(force intro: tauChainFreshChain)+\n\n  have \"\\<langle>A\\<^sub>R, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>R, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\" \n    by(metis frameResChainPres frameNilStatEq Commutativity AssertionStatEqTrans Composition Associativity)\n  moreover with RimpP'' FrP'' FrR `A\\<^sub>P'' \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>P'' \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q`\n  have \"\\<langle>A\\<^sub>R, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>P''\\<rangle>\" using freshCompChain\n    by(simp add: freshChainSimps)\n  moreover have \"\\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>P''\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'') \\<otimes> \\<Psi>\\<^sub>Q\\<rangle>\"\n    by(metis frameResChainPres frameNilStatEq Commutativity AssertionStatEqTrans Composition Associativity)\n  ultimately have RImpP'': \"\\<langle>A\\<^sub>R, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'') \\<otimes> \\<Psi>\\<^sub>Q\\<rangle>\"\n    by(rule FrameStatEqImpCompose)\n      \n  from PChain FrQ' `A\\<^sub>Q' \\<sharp>* \\<Psi>` `A\\<^sub>Q' \\<sharp>* P` have \"\\<Psi> \\<rhd> P \\<parallel> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'' \\<parallel> Q\" by(rule tauChainPar1)\n  moreover from QTrans FrR P''Trans MeqK RImpP'' FrP'' FrQ' `distinct A\\<^sub>P''` `distinct A\\<^sub>Q'` `A\\<^sub>P'' \\<sharp>* A\\<^sub>Q'` `A\\<^sub>R \\<sharp>* A\\<^sub>Q'`\n        `A\\<^sub>Q' \\<sharp>* \\<Psi>` `A\\<^sub>Q' \\<sharp>* P''` `A\\<^sub>Q' \\<sharp>* Q` `A\\<^sub>Q' \\<sharp>* R` `A\\<^sub>Q' \\<sharp>* K` `A\\<^sub>P'' \\<sharp>* \\<Psi>` `A\\<^sub>P'' \\<sharp>* R` `A\\<^sub>P'' \\<sharp>* Q`\n        `A\\<^sub>P'' \\<sharp>* P''` `A\\<^sub>P'' \\<sharp>* M` `A\\<^sub>Q \\<sharp>* R` `A\\<^sub>R \\<sharp>* Q` `A\\<^sub>R \\<sharp>* M`\n  obtain K' where \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<rhd> Q \\<longmapsto>K'\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'\" and \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M \\<leftrightarrow> K'\" and \"A\\<^sub>Q' \\<sharp>* K'\"\n    by(rule_tac comm1Aux) (assumption | simp)+\n  with P''Trans FrP'' have \"\\<Psi> \\<rhd> P'' \\<parallel> Q \\<longmapsto>\\<tau> \\<prec> \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> Q')\" using FrQ' `A\\<^sub>Q' \\<sharp>* \\<Psi>` `A\\<^sub>Q' \\<sharp>* P''` `A\\<^sub>Q' \\<sharp>* Q`\n    `xvec \\<sharp>* P''` `A\\<^sub>P'' \\<sharp>* \\<Psi>` `A\\<^sub>P'' \\<sharp>* P''` `A\\<^sub>P'' \\<sharp>* Q` `A\\<^sub>P'' \\<sharp>* M`  `A\\<^sub>P'' \\<sharp>* A\\<^sub>Q'`\n    by(rule_tac Comm1)\n  ultimately show ?thesis\n    by(drule_tac tauActTauStepChain) auto\nqed\n\nlemma weakComm2:\n  fixes \\<Psi>   :: 'b\n  and   R    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha>    :: \"'a action\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   A\\<^sub>Q   :: \"name list\"\n  and   \\<Psi>\\<^sub>Q   :: 'b\n\n  assumes PTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q : R \\<rhd> P \\<Longrightarrow>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n  and     FrR: \"extractFrame R = \\<langle>A\\<^sub>R, \\<Psi>\\<^sub>R\\<rangle>\"\n  and     QTrans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<rhd> Q \\<longmapsto>K\\<lparr>N\\<rparr> \\<prec> Q'\"\n  and     FrQ: \"extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\"\n  and     MeqK: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>R \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M \\<leftrightarrow> K\"\n  and     \"A\\<^sub>R \\<sharp>* \\<Psi>\"\n  and     \"A\\<^sub>R \\<sharp>* P\"\n  and     \"A\\<^sub>R \\<sharp>* Q\"\n  and     \"A\\<^sub>R \\<sharp>* R\"\n  and     \"A\\<^sub>R \\<sharp>* M\"\n  and     \"A\\<^sub>R \\<sharp>* A\\<^sub>Q\"\n  and     \"A\\<^sub>Q \\<sharp>* \\<Psi>\"\n  and     \"A\\<^sub>Q \\<sharp>* P\"\n  and     \"A\\<^sub>Q \\<sharp>* Q\"\n  and     \"A\\<^sub>Q \\<sharp>* R\"\n  and     \"A\\<^sub>Q \\<sharp>* K\"\n  and     \"xvec \\<sharp>* Q\"\n  and     \"xvec \\<sharp>* M\"\n  and     \"xvec \\<sharp>* A\\<^sub>Q\"\n  and     \"xvec \\<sharp>* A\\<^sub>R\"\n\n  shows \"\\<Psi> \\<rhd> P \\<parallel> Q \\<Longrightarrow>\\<^sub>\\<tau> (\\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> Q'))\"\nproof -\n  from `extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* P` `A\\<^sub>Q \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* R` `A\\<^sub>Q \\<sharp>* K` `A\\<^sub>R \\<sharp>* A\\<^sub>Q` `xvec \\<sharp>* A\\<^sub>Q`\n  obtain A\\<^sub>Q' where FrQ': \"extractFrame Q = \\<langle>A\\<^sub>Q', \\<Psi>\\<^sub>Q\\<rangle>\" and \"distinct A\\<^sub>Q'\" and \"A\\<^sub>Q' \\<sharp>* \\<Psi>\" and \"A\\<^sub>Q' \\<sharp>* P\" \n               and \"A\\<^sub>Q' \\<sharp>* Q\" and \"A\\<^sub>Q' \\<sharp>* R\" and \"A\\<^sub>Q' \\<sharp>* K\" and \"A\\<^sub>R \\<sharp>* A\\<^sub>Q'\" and \"A\\<^sub>Q' \\<sharp>* xvec\"\n    by(rule_tac C=\"(\\<Psi>, P, Q, R, K, A\\<^sub>R, xvec)\" in distinctFrame) auto\n\n  from PTrans obtain P'' where PChain: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\"\n                           and RimpP'': \"insertAssertion (extractFrame R) (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P'') (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q)\"\n                           and P''Trans: \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q \\<rhd> P'' \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n    by(rule weakTransitionE)\n\n  from PChain `A\\<^sub>Q' \\<sharp>* P` have \"A\\<^sub>Q' \\<sharp>* P''\" by(rule tauChainFreshChain)\n  obtain A\\<^sub>P'' \\<Psi>\\<^sub>P'' where FrP'': \"extractFrame P'' = \\<langle>A\\<^sub>P'', \\<Psi>\\<^sub>P''\\<rangle>\" and \"A\\<^sub>P'' \\<sharp>* (\\<Psi>, A\\<^sub>Q', \\<Psi>\\<^sub>Q, A\\<^sub>R, \\<Psi>\\<^sub>R, M, N, K, R, Q, P'', xvec)\" and \"distinct A\\<^sub>P''\"\n    by(rule freshFrame)\n  hence \"A\\<^sub>P'' \\<sharp>* \\<Psi>\" and \"A\\<^sub>P'' \\<sharp>* A\\<^sub>Q'\" and \"A\\<^sub>P'' \\<sharp>* \\<Psi>\\<^sub>Q\" and \"A\\<^sub>P'' \\<sharp>* M\" and \"A\\<^sub>P'' \\<sharp>* R\" and \"A\\<^sub>P'' \\<sharp>* Q\"\n    and \"A\\<^sub>P'' \\<sharp>* N\" and \"A\\<^sub>P'' \\<sharp>* K\" and \"A\\<^sub>P'' \\<sharp>* A\\<^sub>R\" and \"A\\<^sub>P'' \\<sharp>* P''\" and \"A\\<^sub>P'' \\<sharp>* xvec\" and \"A\\<^sub>P'' \\<sharp>* \\<Psi>\\<^sub>R\"\n    by simp+\n  from FrR `A\\<^sub>R \\<sharp>* A\\<^sub>Q'` `A\\<^sub>Q' \\<sharp>* R` have \"A\\<^sub>Q' \\<sharp>* \\<Psi>\\<^sub>R\" by(drule_tac extractFrameFreshChain) auto\n  from FrQ' `A\\<^sub>R \\<sharp>* A\\<^sub>Q'` `A\\<^sub>R \\<sharp>* Q` have \"A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q\" by(drule_tac extractFrameFreshChain) auto\n\n  have \"\\<langle>A\\<^sub>R, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>R, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R\\<rangle>\" \n    by(metis frameResChainPres frameNilStatEq Commutativity AssertionStatEqTrans Composition Associativity)\n  moreover with RimpP'' FrP'' FrR `A\\<^sub>P'' \\<sharp>* \\<Psi>` `A\\<^sub>R \\<sharp>* \\<Psi>` `A\\<^sub>P'' \\<sharp>* \\<Psi>\\<^sub>Q` `A\\<^sub>R \\<sharp>* \\<Psi>\\<^sub>Q`\n  have \"\\<langle>A\\<^sub>R, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>R\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>P''\\<rangle>\" using freshCompChain\n    by(simp add: freshChainSimps)\n  moreover have \"\\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q) \\<otimes> \\<Psi>\\<^sub>P''\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'') \\<otimes> \\<Psi>\\<^sub>Q\\<rangle>\"\n    by(metis frameResChainPres frameNilStatEq Commutativity AssertionStatEqTrans Composition Associativity)\n  ultimately have RImpP'': \"\\<langle>A\\<^sub>R, (\\<Psi> \\<otimes> \\<Psi>\\<^sub>R) \\<otimes> \\<Psi>\\<^sub>Q\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P'', (\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'') \\<otimes> \\<Psi>\\<^sub>Q\\<rangle>\"\n    by(rule FrameStatEqImpCompose)\n      \n  from PChain FrQ' `A\\<^sub>Q' \\<sharp>* \\<Psi>` `A\\<^sub>Q' \\<sharp>* P` have \"\\<Psi> \\<rhd> P \\<parallel> Q \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'' \\<parallel> Q\" by(rule tauChainPar1)\n  moreover from QTrans FrR P''Trans MeqK RImpP'' FrP'' FrQ' `distinct A\\<^sub>P''` `distinct A\\<^sub>Q'` `A\\<^sub>P'' \\<sharp>* A\\<^sub>Q'` `A\\<^sub>R \\<sharp>* A\\<^sub>Q'`\n        `A\\<^sub>Q' \\<sharp>* \\<Psi>` `A\\<^sub>Q' \\<sharp>* P''` `A\\<^sub>Q' \\<sharp>* Q` `A\\<^sub>Q' \\<sharp>* R` `A\\<^sub>Q' \\<sharp>* K` `A\\<^sub>P'' \\<sharp>* \\<Psi>` `A\\<^sub>P'' \\<sharp>* R` `A\\<^sub>P'' \\<sharp>* Q`\n        `A\\<^sub>P'' \\<sharp>* P''` `A\\<^sub>P'' \\<sharp>* M` `A\\<^sub>Q \\<sharp>* R` `A\\<^sub>R \\<sharp>* Q` `A\\<^sub>R \\<sharp>* M` `xvec \\<sharp>* A\\<^sub>R` `xvec \\<sharp>* M` `A\\<^sub>Q' \\<sharp>* xvec`\n  obtain K' where \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<rhd> Q \\<longmapsto>K'\\<lparr>N\\<rparr> \\<prec> Q'\" and \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>P'' \\<otimes> \\<Psi>\\<^sub>Q \\<turnstile> M \\<leftrightarrow> K'\" and \"A\\<^sub>Q' \\<sharp>* K'\"\n    by(rule_tac comm2Aux) (assumption | simp)+\n  with P''Trans FrP'' have \"\\<Psi> \\<rhd> P'' \\<parallel> Q \\<longmapsto>\\<tau> \\<prec> \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> Q')\" using FrQ' `A\\<^sub>Q' \\<sharp>* \\<Psi>` `A\\<^sub>Q' \\<sharp>* P''` `A\\<^sub>Q' \\<sharp>* Q`\n    `xvec \\<sharp>* Q` `A\\<^sub>P'' \\<sharp>* \\<Psi>` `A\\<^sub>P'' \\<sharp>* P''` `A\\<^sub>P'' \\<sharp>* Q` `A\\<^sub>P'' \\<sharp>* M`  `A\\<^sub>P'' \\<sharp>* A\\<^sub>Q'`\n    by(rule_tac Comm2)\n  ultimately show ?thesis\n    by(drule_tac tauActTauStepChain) auto\nqed\n\nlemma frameImpIntComposition:\n  fixes \\<Psi>  :: 'b\n  and   \\<Psi>' :: 'b\n  and   A\\<^sub>F :: \"name list\"\n  and   \\<Psi>\\<^sub>F :: 'b\n\n  assumes \"\\<Psi> \\<simeq> \\<Psi>'\"\n\n  shows \"\\<langle>A\\<^sub>F, \\<Psi> \\<otimes> \\<Psi>\\<^sub>F\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>F, \\<Psi>' \\<otimes> \\<Psi>\\<^sub>F\\<rangle>\"\nproof -\n  from assms have \"\\<langle>A\\<^sub>F, \\<Psi> \\<otimes> \\<Psi>\\<^sub>F\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>F, \\<Psi>' \\<otimes> \\<Psi>\\<^sub>F\\<rangle>\" by(rule frameIntComposition)\n  thus ?thesis by(simp add: FrameStatEq_def)\nqed\n\nlemma insertAssertionStatImp:\n  fixes F  :: \"'b frame\"\n  and   \\<Psi>  :: 'b\n  and   G  :: \"'b frame\"\n  and   \\<Psi>' :: 'b\n\n  assumes FeqG: \"insertAssertion F \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion G \\<Psi>\"\n  and     \"\\<Psi> \\<simeq> \\<Psi>'\"\n\n  shows \"insertAssertion F \\<Psi>' \\<hookrightarrow>\\<^sub>F insertAssertion G \\<Psi>'\"\nproof -\n  obtain A\\<^sub>F \\<Psi>\\<^sub>F where FrF: \"F = \\<langle>A\\<^sub>F, \\<Psi>\\<^sub>F\\<rangle>\" and \"A\\<^sub>F \\<sharp>* \\<Psi>\" and \"A\\<^sub>F \\<sharp>* \\<Psi>'\"\n    by(rule_tac C=\"(\\<Psi>, \\<Psi>')\" in freshFrame) auto\n  obtain A\\<^sub>G \\<Psi>\\<^sub>G where FrG: \"G = \\<langle>A\\<^sub>G, \\<Psi>\\<^sub>G\\<rangle>\" and \"A\\<^sub>G \\<sharp>* \\<Psi>\" and \"A\\<^sub>G \\<sharp>* \\<Psi>'\"\n    by(rule_tac C=\"(\\<Psi>, \\<Psi>')\" in freshFrame) auto\n\n  from `\\<Psi> \\<simeq> \\<Psi>'` have \"\\<langle>A\\<^sub>F, \\<Psi>' \\<otimes> \\<Psi>\\<^sub>F\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>F, \\<Psi> \\<otimes> \\<Psi>\\<^sub>F\\<rangle>\" by (metis frameIntComposition FrameStatEqSym)\n  moreover from `\\<Psi> \\<simeq> \\<Psi>'` have \"\\<langle>A\\<^sub>G, \\<Psi> \\<otimes> \\<Psi>\\<^sub>G\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>G, \\<Psi>' \\<otimes> \\<Psi>\\<^sub>G\\<rangle>\" by(rule frameIntComposition)\n  ultimately have \"\\<langle>A\\<^sub>F, \\<Psi>' \\<otimes> \\<Psi>\\<^sub>F\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>G, \\<Psi>' \\<otimes> \\<Psi>\\<^sub>G\\<rangle>\" using FeqG FrF FrG `A\\<^sub>F \\<sharp>* \\<Psi>` `A\\<^sub>G \\<sharp>* \\<Psi>` `\\<Psi> \\<simeq> \\<Psi>'`\n    by(force simp add: FrameStatEq_def dest: FrameStatImpTrans)\n  with FrF FrG `A\\<^sub>F \\<sharp>* \\<Psi>'` `A\\<^sub>G \\<sharp>* \\<Psi>'` show ?thesis by simp\nqed\n\nlemma insertAssertionStatEq:\n  fixes F  :: \"'b frame\"\n  and   \\<Psi>  :: 'b\n  and   G  :: \"'b frame\"\n  and   \\<Psi>' :: 'b\n\n  assumes FeqG: \"insertAssertion F \\<Psi> \\<simeq>\\<^sub>F insertAssertion G \\<Psi>\"\n  and     \"\\<Psi> \\<simeq> \\<Psi>'\"\n\n  shows \"insertAssertion F \\<Psi>' \\<simeq>\\<^sub>F insertAssertion G \\<Psi>'\"\nproof -\n  obtain A\\<^sub>F \\<Psi>\\<^sub>F where FrF: \"F = \\<langle>A\\<^sub>F, \\<Psi>\\<^sub>F\\<rangle>\" and \"A\\<^sub>F \\<sharp>* \\<Psi>\" and \"A\\<^sub>F \\<sharp>* \\<Psi>'\"\n    by(rule_tac C=\"(\\<Psi>, \\<Psi>')\" in freshFrame) auto\n  obtain A\\<^sub>G \\<Psi>\\<^sub>G where FrG: \"G = \\<langle>A\\<^sub>G, \\<Psi>\\<^sub>G\\<rangle>\" and \"A\\<^sub>G \\<sharp>* \\<Psi>\" and \"A\\<^sub>G \\<sharp>* \\<Psi>'\"\n    by(rule_tac C=\"(\\<Psi>, \\<Psi>')\" in freshFrame) auto\n\n  from FeqG FrF FrG `A\\<^sub>F \\<sharp>* \\<Psi>` `A\\<^sub>G \\<sharp>* \\<Psi>` `\\<Psi> \\<simeq> \\<Psi>'`\n  have \"\\<langle>A\\<^sub>F, \\<Psi>' \\<otimes> \\<Psi>\\<^sub>F\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>G, \\<Psi>' \\<otimes> \\<Psi>\\<^sub>G\\<rangle>\"\n    by simp (metis frameIntComposition FrameStatEqTrans FrameStatEqSym)\n  with FrF FrG `A\\<^sub>F \\<sharp>* \\<Psi>'` `A\\<^sub>G \\<sharp>* \\<Psi>'` show ?thesis by simp\nqed\n\nlemma weakTransitionStatEq:\n  fixes \\<Psi>   :: 'b\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha>    :: \"'a action\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   \\<Psi>'  :: 'b\n\n  assumes PTrans: \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P'\"\n  and     \"\\<Psi> \\<simeq> \\<Psi>'\"\n\n  shows \"\\<Psi>' : Q \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P'\"\nproof -\n  from PTrans obtain P'' where PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\"\n                           and QeqP'': \"insertAssertion (extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P'') \\<Psi>\"\n                           and P''Trans: \"\\<Psi> \\<rhd> P'' \\<longmapsto>\\<alpha> \\<prec> P'\"\n    by(rule weakTransitionE)\n\n  from PChain `\\<Psi> \\<simeq> \\<Psi>'` have \"\\<Psi>' \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" by(rule tauChainStatEq)\n  moreover from QeqP'' `\\<Psi> \\<simeq> \\<Psi>'` have \"insertAssertion (extractFrame Q) \\<Psi>' \\<hookrightarrow>\\<^sub>F insertAssertion (extractFrame P'') \\<Psi>'\"\n    by(rule insertAssertionStatImp)\n  moreover from P''Trans `\\<Psi> \\<simeq> \\<Psi>'` have \"\\<Psi>' \\<rhd> P'' \\<longmapsto>\\<alpha> \\<prec> P'\"\n    by(rule statEqTransition)\n  ultimately show ?thesis by(rule weakTransitionI)\nqed\n\nlemma transitionWeakTransition:\n  fixes \\<Psi>   :: 'b\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha>    :: \"'a action\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  \n  assumes \"\\<Psi> \\<rhd> P \\<longmapsto>\\<alpha> \\<prec> P'\"\n  and     \"insertAssertion(extractFrame Q) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion(extractFrame P) \\<Psi>\"\n\n  shows \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P'\"\nusing assms\nby(fastforce intro: weakTransitionI)\n\nlemma weakPar1Guarded:\n  fixes \\<Psi>  :: 'b\n  and   R    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha>    :: \"'a action\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n\n  assumes PTrans: \"\\<Psi> : R \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P'\"\n  and     \"bn \\<alpha> \\<sharp>* Q\"\n  and     \"guarded Q\"\n\n  shows \"\\<Psi> : (R \\<parallel> Q) \\<rhd> P \\<parallel> Q \\<Longrightarrow>\\<alpha> \\<prec> P' \\<parallel> Q\"\nproof -\n  obtain A\\<^sub>Q \\<Psi>\\<^sub>Q where FrQ: \"extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\" and \"A\\<^sub>Q \\<sharp>* P\" and \"A\\<^sub>Q \\<sharp>* \\<alpha>\" and \"A\\<^sub>Q \\<sharp>* R\"\n    by(rule_tac C=\"(\\<Psi>, P, \\<alpha>, R)\" in freshFrame) auto\n  from `guarded Q` FrQ have \"\\<Psi>\\<^sub>Q \\<simeq> \\<one>\" by(blast dest: guardedStatEq)\n  with PTrans have \"\\<Psi> \\<otimes> \\<Psi>\\<^sub>Q : R \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P'\" by(metis weakTransitionStatEq Identity AssertionStatEqSym compositionSym)\n  thus ?thesis using FrQ `bn \\<alpha> \\<sharp>* Q` `A\\<^sub>Q \\<sharp>* \\<Psi>` `A\\<^sub>Q \\<sharp>* P` `A\\<^sub>Q \\<sharp>* \\<alpha>` `A\\<^sub>Q \\<sharp>* R` \n    by(rule weakPar1)\nqed\n\nlemma weakBang:\n  fixes \\<Psi>   :: 'b\n  and   R    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha>    :: \"'a action\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n\n  assumes PTrans: \"\\<Psi> : R \\<rhd> P \\<parallel> !P \\<Longrightarrow>\\<alpha> \\<prec> P'\"\n  and     \"guarded P\"\n\n  shows \"\\<Psi> : R \\<rhd> !P \\<Longrightarrow>\\<alpha> \\<prec> P'\"\nproof -\n  from PTrans obtain P'' where PChain: \"\\<Psi> \\<rhd> P \\<parallel> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\"\n                           and RImpP'': \"insertAssertion(extractFrame R) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion(extractFrame P'') \\<Psi>\"\n                           and P''Trans: \"\\<Psi> \\<rhd> P'' \\<longmapsto>\\<alpha> \\<prec> P'\"\n    by(rule weakTransitionE)\n  moreover obtain A\\<^sub>P \\<Psi>\\<^sub>P where FrP: \"extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" and \"A\\<^sub>P \\<sharp>* \\<Psi>\" by(rule freshFrame)\n  moreover from `guarded P` FrP have \"\\<Psi>\\<^sub>P \\<simeq> \\<one>\" by(blast dest: guardedStatEq)\n  ultimately show ?thesis\n  proof(auto simp add: rtrancl_eq_or_trancl)\n    have \"\\<Psi> \\<rhd> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> !P\" by simp\n    moreover assume RimpP: \"insertAssertion(extractFrame R) \\<Psi> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>P, \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<one>\\<rangle>\"\n    have \"insertAssertion(extractFrame R) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion(extractFrame(!P)) \\<Psi>\"\n    proof -\n      from `\\<Psi>\\<^sub>P \\<simeq> \\<one>` have \"\\<langle>A\\<^sub>P, \\<Psi> \\<otimes> \\<Psi>\\<^sub>P \\<otimes> \\<one>\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P, \\<Psi> \\<otimes> \\<one>\\<rangle>\"\n        by(metis frameIntCompositionSym frameIntAssociativity frameIntCommutativity frameIntIdentity FrameStatEqTrans FrameStatEqSym)\n      moreover from `A\\<^sub>P \\<sharp>* \\<Psi>` have \"\\<langle>A\\<^sub>P, \\<Psi> \\<otimes> \\<one>\\<rangle> \\<simeq>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi> \\<otimes> \\<one>\\<rangle>\"\n        by(force intro: frameResFreshChain)\n      ultimately show ?thesis using RimpP by(auto simp add: FrameStatEq_def dest: FrameStatImpTrans)\n    qed\n    moreover assume \"\\<Psi> \\<rhd> P \\<parallel> !P \\<longmapsto>\\<alpha> \\<prec> P'\"\n    hence \"\\<Psi> \\<rhd> !P \\<longmapsto>\\<alpha> \\<prec> P'\" using `guarded P` by(rule Bang)\n   ultimately show ?thesis by(rule weakTransitionI)\n  next\n    fix P'''\n    assume \"\\<Psi> \\<rhd> P \\<parallel> !P \\<Longrightarrow>\\<^sub>\\<tau>  P''\"\n    hence \"\\<Psi> \\<rhd> !P \\<Longrightarrow>\\<^sub>\\<tau> P''\" using `guarded P` by(rule tauStepChainBang)\n    hence \"\\<Psi> \\<rhd> !P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P''\" by simp\n    moreover assume \"insertAssertion(extractFrame R) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion(extractFrame P'') \\<Psi>\"\n                and \"\\<Psi> \\<rhd> P'' \\<longmapsto>\\<alpha> \\<prec> P'\"\n    ultimately show ?thesis by(rule weakTransitionI)\n  qed\nqed\n\nlemma weakTransitionFrameImp:\n  fixes \\<Psi>   :: 'b\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   xvec :: \"name list\"\n  and   N    :: 'a\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   R    :: \"('a, 'b, 'c) psi\"\n\n  assumes PTrans: \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P'\"\n  and             \"insertAssertion(extractFrame R) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion(extractFrame Q) \\<Psi>\"\n\n  shows \"\\<Psi> : R \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P'\"\nusing assms\nby(auto simp add: weakTransition_def intro: FrameStatImpTrans)\n\nlemma guardedFrameStatEq:\n  fixes P :: \"('a, 'b, 'c) psi\"\n\n  assumes \"guarded P\"\n\n  shows \"extractFrame P \\<simeq>\\<^sub>F \\<langle>\\<epsilon>, \\<one>\\<rangle>\"\nproof -\n  obtain A\\<^sub>P \\<Psi>\\<^sub>P where FrP: \"extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" by(rule freshFrame)\n  from `guarded P` FrP have \"\\<Psi>\\<^sub>P \\<simeq> \\<one>\" by(blast dest: guardedStatEq)\n  hence \"\\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>P, \\<one>\\<rangle>\" by(rule_tac frameResChainPres) auto\n  moreover have \"\\<langle>A\\<^sub>P, \\<one>\\<rangle> \\<simeq>\\<^sub>F \\<langle>\\<epsilon>, \\<one>\\<rangle>\" by(rule_tac frameResFreshChain) auto\n  ultimately show ?thesis using FrP by(force intro: FrameStatEqTrans)\nqed\n\nlemma weakGuardedTransition:\n  fixes \\<Psi>   :: 'b\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   \\<alpha>    :: \"'a action\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   R    :: \"('a, 'b, 'c) psi\"\n\n  assumes PTrans: \"\\<Psi> : Q \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P'\"\n  and    \"guarded Q\"\n\n  shows \"\\<Psi> : \\<zero> \\<rhd> P \\<Longrightarrow>\\<alpha> \\<prec> P'\"\nproof -\n  obtain A\\<^sub>Q \\<Psi>\\<^sub>Q where FrQ: \"extractFrame Q = \\<langle>A\\<^sub>Q, \\<Psi>\\<^sub>Q\\<rangle>\" and \"A\\<^sub>Q \\<sharp>* \\<Psi>\" by(rule freshFrame)\n  moreover from `guarded Q` FrQ have \"\\<Psi>\\<^sub>Q \\<simeq> \\<one>\" by(blast dest: guardedStatEq)\n  hence \"\\<langle>A\\<^sub>Q, \\<Psi> \\<otimes> \\<Psi>\\<^sub>Q\\<rangle> \\<simeq>\\<^sub>F \\<langle>A\\<^sub>Q, \\<Psi> \\<otimes> \\<one>\\<rangle>\" by(metis frameIntCompositionSym)\n  moreover from `A\\<^sub>Q \\<sharp>* \\<Psi>` have \"\\<langle>A\\<^sub>Q, \\<Psi> \\<otimes> \\<one>\\<rangle> \\<simeq>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi> \\<otimes> \\<one>\\<rangle>\" by(rule_tac frameResFreshChain) auto\n  ultimately have \"insertAssertion(extractFrame Q) \\<Psi> \\<simeq>\\<^sub>F insertAssertion (extractFrame (\\<zero>)) \\<Psi>\"\n    using FrQ `A\\<^sub>Q \\<sharp>* \\<Psi>` by simp (blast intro: FrameStatEqTrans)\n  with PTrans show ?thesis by(rule_tac weakTransitionFrameImp) (auto simp add: FrameStatEq_def) \nqed\n\nlemma expandTauChainFrame:\n  fixes \\<Psi> :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n  and   A\\<^sub>P :: \"name list\"\n  and   \\<Psi>\\<^sub>P :: 'b\n  and   C   :: \"'d::fs_name\"\n\n  assumes PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n  and     FrP: \"extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\"\n  and     \"distinct A\\<^sub>P\"\n  and     \"A\\<^sub>P \\<sharp>* P\"\n  and     \"A\\<^sub>P \\<sharp>* C\"\n\n  obtains \\<Psi>' A\\<^sub>P' \\<Psi>\\<^sub>P' where \"extractFrame P' = \\<langle>A\\<^sub>P', \\<Psi>\\<^sub>P'\\<rangle>\" and \"\\<Psi>\\<^sub>P \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>P'\" and \"A\\<^sub>P' \\<sharp>* P'\" and \"A\\<^sub>P' \\<sharp>* C\" and \"distinct A\\<^sub>P'\"\nusing PChain FrP `A\\<^sub>P \\<sharp>* P`\nproof(induct arbitrary: thesis rule: tauChainInduct)\n  case(TauBase P)\n  have \"\\<Psi>\\<^sub>P \\<otimes> SBottom' \\<simeq> \\<Psi>\\<^sub>P\" by(rule Identity)\n  with `extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>` show ?case using `A\\<^sub>P \\<sharp>* P` `A\\<^sub>P \\<sharp>* C` `distinct A\\<^sub>P` by(rule TauBase)\nnext\n  case(TauStep P P' P'')\n  from `extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>` `A\\<^sub>P \\<sharp>* P`\n  obtain \\<Psi>' A\\<^sub>P' \\<Psi>\\<^sub>P' where FrP': \"extractFrame P' = \\<langle>A\\<^sub>P', \\<Psi>\\<^sub>P'\\<rangle>\" and \"\\<Psi>\\<^sub>P \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>P'\"\n                       and \"A\\<^sub>P' \\<sharp>* P'\" and \"A\\<^sub>P' \\<sharp>* C\" and \"distinct A\\<^sub>P'\"\n    by(rule_tac TauStep)\n  from `\\<Psi> \\<rhd> P' \\<longmapsto>\\<tau> \\<prec> P''` FrP' `distinct A\\<^sub>P'` `A\\<^sub>P' \\<sharp>* P'` `A\\<^sub>P' \\<sharp>* C`\n  obtain \\<Psi>'' A\\<^sub>P'' \\<Psi>\\<^sub>P'' where FrP'': \"extractFrame P'' = \\<langle>A\\<^sub>P'', \\<Psi>\\<^sub>P''\\<rangle>\" and \"\\<Psi>\\<^sub>P' \\<otimes> \\<Psi>'' \\<simeq> \\<Psi>\\<^sub>P''\"\n                          and \"A\\<^sub>P'' \\<sharp>* P''\" and \"A\\<^sub>P'' \\<sharp>* C\" and \"distinct A\\<^sub>P''\"\n    by(rule expandTauFrame)\n  from `\\<Psi>\\<^sub>P \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>P'` have \"(\\<Psi>\\<^sub>P \\<otimes> \\<Psi>') \\<otimes> \\<Psi>'' \\<simeq> \\<Psi>\\<^sub>P' \\<otimes> \\<Psi>''\" by(rule Composition)\n  with `\\<Psi>\\<^sub>P' \\<otimes> \\<Psi>'' \\<simeq> \\<Psi>\\<^sub>P''` have \"\\<Psi>\\<^sub>P \\<otimes> \\<Psi>' \\<otimes> \\<Psi>'' \\<simeq> \\<Psi>\\<^sub>P''\"\n    by(metis AssertionStatEqTrans Associativity Commutativity)\n  with FrP'' show ?case using `A\\<^sub>P'' \\<sharp>* P''` `A\\<^sub>P'' \\<sharp>* C` `distinct A\\<^sub>P''`\n    by(rule TauStep)\nqed\n\nlemma frameIntImpComposition:\n  fixes \\<Psi>  :: 'b\n  and   \\<Psi>' :: 'b\n  and   A\\<^sub>F :: \"name list\"\n  and   \\<Psi>\\<^sub>F :: 'b\n\n  assumes \"\\<Psi> \\<simeq> \\<Psi>'\"\n\n  shows \"\\<langle>A\\<^sub>F, \\<Psi> \\<otimes> \\<Psi>\\<^sub>F\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>F, \\<Psi>' \\<otimes> \\<Psi>\\<^sub>F\\<rangle>\"\nusing assms frameIntComposition\nby(simp add: FrameStatEq_def)\n\nlemma tauChainInduct2[consumes 1, case_names TauBase TauStep]:\n  fixes \\<Psi> :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n\n  assumes PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n  and     cBase: \"\\<And>P. Prop P P\"\n  and     cStep: \"\\<And>P P' P''. \\<lbrakk>\\<Psi> \\<rhd> P' \\<longmapsto>\\<tau> \\<prec> P''; \\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'; Prop P P'\\<rbrakk> \\<Longrightarrow> Prop P P''\"\n\n  shows \"Prop P P'\"\nusing assms\nby(rule tauChainInduct)\n\nlemma tauStepChainInduct2[consumes 1, case_names TauBase TauStep]:\n  fixes \\<Psi> :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n\n  assumes PChain: \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'\"\n  and     cBase: \"\\<And>P P'. \\<Psi> \\<rhd> P \\<longmapsto>\\<tau> \\<prec> P' \\<Longrightarrow> Prop P P'\"\n  and     cStep: \"\\<And>P P' P''. \\<lbrakk>\\<Psi> \\<rhd> P' \\<longmapsto>\\<tau> \\<prec> P''; \\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P'; Prop P P'\\<rbrakk> \\<Longrightarrow> Prop P P''\"\n\n  shows \"Prop P P'\"\nusing assms\nby(rule tauStepChainInduct)\n\nlemma weakTransferTauChainFrame:\n  fixes \\<Psi>\\<^sub>F :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n  and   A\\<^sub>P :: \"name list\"\n  and   \\<Psi>\\<^sub>P :: 'b\n  and   A\\<^sub>F :: \"name list\"\n  and   A\\<^sub>G :: \"name list\"\n  and   \\<Psi>\\<^sub>G :: 'b\n\n  assumes PChain: \"\\<Psi>\\<^sub>F \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n  and     FrP: \"extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\"\n  and     \"distinct A\\<^sub>P\"\n  and     FeqG: \"\\<And>\\<Psi>. insertAssertion (\\<langle>A\\<^sub>F, \\<Psi>\\<^sub>F \\<otimes> \\<Psi>\\<^sub>P\\<rangle>) \\<Psi> \\<hookrightarrow>\\<^sub>F insertAssertion (\\<langle>A\\<^sub>G, \\<Psi>\\<^sub>G \\<otimes> \\<Psi>\\<^sub>P\\<rangle>) \\<Psi>\"\n  and     \"A\\<^sub>F \\<sharp>* \\<Psi>\\<^sub>G\"\n  and     \"A\\<^sub>G \\<sharp>* \\<Psi>\"\n  and     \"A\\<^sub>G \\<sharp>* \\<Psi>\\<^sub>F\"\n  and     \"A\\<^sub>F \\<sharp>* A\\<^sub>G\"\n  and     \"A\\<^sub>F \\<sharp>* P\"\n  and     \"A\\<^sub>G \\<sharp>* P\"\n  and     \"A\\<^sub>P \\<sharp>* A\\<^sub>F\"\n  and     \"A\\<^sub>P \\<sharp>* A\\<^sub>G\"\n  and     \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>F\"\n  and     \"A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>G\"\n  and     \"A\\<^sub>P \\<sharp>* P\"\n\n  shows \"\\<Psi>\\<^sub>G \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\nusing PChain FrP `A\\<^sub>F \\<sharp>* P` `A\\<^sub>G \\<sharp>* P` `A\\<^sub>P \\<sharp>* P` \nproof(induct rule: tauChainInduct2)\n  case TauBase\n  thus ?case by simp\nnext\n  case(TauStep P P' P'')\n  have FrP: \"extractFrame P = \\<langle>A\\<^sub>P, \\<Psi>\\<^sub>P\\<rangle>\" by fact\n  then have PChain: \"\\<Psi>\\<^sub>G \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\" using `A\\<^sub>F \\<sharp>* P` `A\\<^sub>G \\<sharp>* P` `A\\<^sub>P \\<sharp>* P` by(rule TauStep)\n  then obtain A\\<^sub>P' \\<Psi>\\<^sub>P' \\<Psi>' where FrP': \"extractFrame P' = \\<langle>A\\<^sub>P', \\<Psi>\\<^sub>P'\\<rangle>\" and \"\\<Psi>\\<^sub>P \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>P'\"\n                            and \"A\\<^sub>P' \\<sharp>* A\\<^sub>F\" and \"A\\<^sub>P' \\<sharp>* A\\<^sub>G\" and \"A\\<^sub>P' \\<sharp>* \\<Psi>\\<^sub>F\" and \"A\\<^sub>P' \\<sharp>* \\<Psi>\\<^sub>G\"\n                            and \"distinct A\\<^sub>P'\"\n                \n    using FrP `distinct A\\<^sub>P` `A\\<^sub>P \\<sharp>* P` `A\\<^sub>P \\<sharp>* A\\<^sub>F` `A\\<^sub>P \\<sharp>* A\\<^sub>G` `A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>F` `A\\<^sub>P \\<sharp>* \\<Psi>\\<^sub>G`\n    by(rule_tac C=\"(A\\<^sub>F, A\\<^sub>G, \\<Psi>\\<^sub>F, \\<Psi>\\<^sub>G)\" in expandTauChainFrame) auto\n\n  from PChain `A\\<^sub>F \\<sharp>* P` `A\\<^sub>G \\<sharp>* P` have \"A\\<^sub>F \\<sharp>* P'\" and \"A\\<^sub>G \\<sharp>* P'\" by(blast dest: tauChainFreshChain)+\n\n  with `A\\<^sub>F \\<sharp>* P` `A\\<^sub>G \\<sharp>* P` `A\\<^sub>P \\<sharp>* A\\<^sub>F` `A\\<^sub>P \\<sharp>* A\\<^sub>G``A\\<^sub>P' \\<sharp>* A\\<^sub>F` `A\\<^sub>P' \\<sharp>* A\\<^sub>G` FrP FrP'\n  have \"A\\<^sub>F \\<sharp>* \\<Psi>\\<^sub>P\" and \"A\\<^sub>G \\<sharp>* \\<Psi>\\<^sub>P\" and \"A\\<^sub>F \\<sharp>* \\<Psi>\\<^sub>P'\" and \"A\\<^sub>G \\<sharp>* \\<Psi>\\<^sub>P'\"\n    by(auto dest: extractFrameFreshChain)\n\n  from FeqG have FeqG: \"insertAssertion (\\<langle>A\\<^sub>F, \\<Psi>\\<^sub>F \\<otimes> \\<Psi>\\<^sub>P\\<rangle>) \\<Psi>' \\<hookrightarrow>\\<^sub>F insertAssertion (\\<langle>A\\<^sub>G, \\<Psi>\\<^sub>G \\<otimes> \\<Psi>\\<^sub>P\\<rangle>) \\<Psi>'\"\n    by blast\n  obtain p::\"name prm\" where \"(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<Psi>\\<^sub>F\" and  \"(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<Psi>\\<^sub>P\" and \"(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<Psi>\\<^sub>P'\" and \"(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<Psi>'\"\n                         and Sp: \"(set p) \\<subseteq> set A\\<^sub>F \\<times> set(p \\<bullet> A\\<^sub>F)\" and \"distinctPerm p\"\n      by(rule_tac xvec=A\\<^sub>F and c=\"(\\<Psi>\\<^sub>F, \\<Psi>\\<^sub>P, \\<Psi>', \\<Psi>\\<^sub>P')\" in name_list_avoiding) auto\n  obtain q::\"name prm\" where \"(q \\<bullet> A\\<^sub>G) \\<sharp>* \\<Psi>\\<^sub>G\" and  \"(q \\<bullet> A\\<^sub>G) \\<sharp>* \\<Psi>\\<^sub>P\" and \"(q \\<bullet> A\\<^sub>G) \\<sharp>* \\<Psi>\\<^sub>P'\" and \"(q \\<bullet> A\\<^sub>G) \\<sharp>* \\<Psi>'\"\n                         and Sq: \"(set q) \\<subseteq> set A\\<^sub>G \\<times> set(q \\<bullet> A\\<^sub>G)\" and \"distinctPerm q\"\n    by(rule_tac xvec=A\\<^sub>G and c=\"(\\<Psi>\\<^sub>G, \\<Psi>\\<^sub>P, \\<Psi>', \\<Psi>\\<^sub>P')\" in name_list_avoiding) auto\n  from `\\<Psi>\\<^sub>P \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>P'` have \"\\<langle>(p \\<bullet> A\\<^sub>F), ((p \\<bullet> \\<Psi>\\<^sub>F) \\<otimes> \\<Psi>\\<^sub>P')\\<rangle> \\<simeq>\\<^sub>F \\<langle>(p \\<bullet> A\\<^sub>F), (p \\<bullet> \\<Psi>\\<^sub>F) \\<otimes> (\\<Psi>\\<^sub>P \\<otimes> \\<Psi>')\\<rangle>\"\n    by(rule frameIntCompositionSym[OF AssertionStatEqSym])\n  hence \"\\<langle>(p \\<bullet> A\\<^sub>F), (p \\<bullet> \\<Psi>\\<^sub>F) \\<otimes> \\<Psi>\\<^sub>P'\\<rangle> \\<simeq>\\<^sub>F \\<langle>(p \\<bullet> A\\<^sub>F), \\<Psi>' \\<otimes> ((p \\<bullet> \\<Psi>\\<^sub>F) \\<otimes> \\<Psi>\\<^sub>P)\\<rangle>\"\n    by(metis frameIntAssociativity FrameStatEqTrans frameIntCommutativity FrameStatEqSym)\n  moreover from FeqG `A\\<^sub>F \\<sharp>* \\<Psi>\\<^sub>P` `(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<Psi>\\<^sub>P` `(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<Psi>\\<^sub>F` `(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<Psi>'` Sp\n  have \"\\<langle>(p \\<bullet> A\\<^sub>F), \\<Psi>' \\<otimes> ((p \\<bullet> \\<Psi>\\<^sub>F) \\<otimes> \\<Psi>\\<^sub>P)\\<rangle> \\<hookrightarrow>\\<^sub>F insertAssertion (\\<langle>A\\<^sub>G, \\<Psi>\\<^sub>G \\<otimes> \\<Psi>\\<^sub>P\\<rangle>) \\<Psi>'\"\n    apply(erule_tac rev_mp) by(subst frameChainAlpha) (auto simp add: eqvts)\n  hence \"\\<langle>(p \\<bullet> A\\<^sub>F), \\<Psi>' \\<otimes> ((p \\<bullet> \\<Psi>\\<^sub>F) \\<otimes> \\<Psi>\\<^sub>P)\\<rangle> \\<hookrightarrow>\\<^sub>F  (\\<langle>(q \\<bullet> A\\<^sub>G), \\<Psi>' \\<otimes> (q \\<bullet> \\<Psi>\\<^sub>G) \\<otimes> \\<Psi>\\<^sub>P\\<rangle>)\"\n    using `A\\<^sub>G \\<sharp>* \\<Psi>\\<^sub>P` `(q \\<bullet> A\\<^sub>G) \\<sharp>* \\<Psi>\\<^sub>P` `(q \\<bullet> A\\<^sub>G) \\<sharp>* \\<Psi>\\<^sub>G` `(q \\<bullet> A\\<^sub>G) \\<sharp>* \\<Psi>'` Sq\n    apply(erule_tac rev_mp) by(subst frameChainAlpha) (auto simp add: eqvts)\n  moreover have \"\\<langle>(q \\<bullet> A\\<^sub>G), \\<Psi>' \\<otimes> ((q \\<bullet> \\<Psi>\\<^sub>G) \\<otimes> \\<Psi>\\<^sub>P)\\<rangle> \\<simeq>\\<^sub>F \\<langle>(q \\<bullet> A\\<^sub>G), (q \\<bullet> \\<Psi>\\<^sub>G) \\<otimes> (\\<Psi>\\<^sub>P \\<otimes> \\<Psi>')\\<rangle>\"\n    by(metis frameIntAssociativity FrameStatEqTrans frameIntCommutativity FrameStatEqSym)\n  hence \"\\<langle>(q \\<bullet> A\\<^sub>G), \\<Psi>' \\<otimes> ((q \\<bullet> \\<Psi>\\<^sub>G) \\<otimes> \\<Psi>\\<^sub>P)\\<rangle> \\<simeq>\\<^sub>F \\<langle>(q \\<bullet> A\\<^sub>G), (q \\<bullet> \\<Psi>\\<^sub>G) \\<otimes> \\<Psi>\\<^sub>P'\\<rangle>\" using `\\<Psi>\\<^sub>P \\<otimes> \\<Psi>' \\<simeq> \\<Psi>\\<^sub>P'`\n    by(blast intro: FrameStatEqTrans frameIntCompositionSym)\n  ultimately have \"\\<langle>(p \\<bullet> A\\<^sub>F), (p \\<bullet> \\<Psi>\\<^sub>F) \\<otimes> \\<Psi>\\<^sub>P'\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>(q \\<bullet> A\\<^sub>G), (q \\<bullet> \\<Psi>\\<^sub>G) \\<otimes> \\<Psi>\\<^sub>P'\\<rangle>\"\n    by(rule FrameStatEqImpCompose)\n  with `A\\<^sub>F \\<sharp>* \\<Psi>\\<^sub>P'` `(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<Psi>\\<^sub>P'` `(p \\<bullet> A\\<^sub>F) \\<sharp>* \\<Psi>\\<^sub>F` Sp have \"\\<langle>A\\<^sub>F, \\<Psi>\\<^sub>F \\<otimes> \\<Psi>\\<^sub>P'\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>(q \\<bullet> A\\<^sub>G), (q \\<bullet> \\<Psi>\\<^sub>G) \\<otimes> \\<Psi>\\<^sub>P'\\<rangle>\"\n    by(subst frameChainAlpha) (auto simp add: eqvts)\n  with `A\\<^sub>G \\<sharp>* \\<Psi>\\<^sub>P'` `(q \\<bullet> A\\<^sub>G) \\<sharp>* \\<Psi>\\<^sub>P'` `(q \\<bullet> A\\<^sub>G) \\<sharp>* \\<Psi>\\<^sub>G` Sq have \"\\<langle>A\\<^sub>F, \\<Psi>\\<^sub>F \\<otimes> \\<Psi>\\<^sub>P'\\<rangle> \\<hookrightarrow>\\<^sub>F \\<langle>A\\<^sub>G, \\<Psi>\\<^sub>G \\<otimes> \\<Psi>\\<^sub>P'\\<rangle>\"\n    by(subst frameChainAlpha) (auto simp add: eqvts)\n  \n  with `\\<Psi>\\<^sub>F \\<rhd> P' \\<longmapsto>\\<tau> \\<prec> P''` FrP' `distinct A\\<^sub>P'`\n       `A\\<^sub>F \\<sharp>* P'` `A\\<^sub>G \\<sharp>* P'` `A\\<^sub>F \\<sharp>* \\<Psi>\\<^sub>G` `A\\<^sub>G \\<sharp>* \\<Psi>\\<^sub>F` `A\\<^sub>P' \\<sharp>* A\\<^sub>F` `A\\<^sub>P' \\<sharp>* A\\<^sub>G` `A\\<^sub>P' \\<sharp>* \\<Psi>\\<^sub>F` `A\\<^sub>P' \\<sharp>* \\<Psi>\\<^sub>G`\n  have \"\\<Psi>\\<^sub>G \\<rhd> P' \\<longmapsto>\\<tau> \\<prec> P''\" by(rule_tac transferTauFrame)\n  with PChain show ?case by(simp add: r_into_rtrancl rtrancl_into_rtrancl)\nqed\n\ncoinductive quiet :: \"('a, 'b, 'c) psi \\<Rightarrow> bool\"\n  where \"\\<lbrakk>\\<forall>\\<Psi>. (insertAssertion (extractFrame P) \\<Psi> \\<simeq>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi>\\<rangle> \\<and> \n              (\\<forall>Rs. \\<Psi> \\<rhd> P \\<longmapsto> Rs \\<longrightarrow> (\\<exists>P'. Rs = \\<tau> \\<prec> P' \\<and> quiet P')))\\<rbrakk> \\<Longrightarrow> quiet P\"\n\nlemma quietFrame:\n  fixes \\<Psi> :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n\n  assumes \"quiet P\"\n\n  shows \"insertAssertion (extractFrame P) \\<Psi> \\<simeq>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi>\\<rangle>\"\nusing assms\nby(erule_tac quiet.cases) force\n  \nlemma quietTransition:\n  fixes \\<Psi> :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   Rs :: \"('a, 'b, 'c) residual\"\n\n  assumes \"quiet P\"\n  and     \"\\<Psi> \\<rhd> P \\<longmapsto> Rs\"\n\n  obtains P' where \"Rs = \\<tau> \\<prec> P'\" and \"quiet P'\"\nusing assms\nby(erule_tac quiet.cases) force\n  \nlemma quietEqvt:\n  fixes P :: \"('a, 'b, 'c) psi\"\n  and   p :: \"name prm\"\n\n  assumes \"quiet P\"\n\n  shows \"quiet(p \\<bullet> P)\"\nproof -\n  let ?X = \"\\<lambda>P. \\<exists>p::name prm. quiet(p \\<bullet> P)\"\n  from assms have \"?X (p \\<bullet> P)\" by(rule_tac x=\"rev p\" in exI) auto\n  thus ?thesis\n    apply coinduct\n    apply(clarify)\n    apply(rule_tac x=x in exI)\n    apply auto\n    apply(drule_tac \\<Psi>=\"p \\<bullet> \\<Psi>\" in quietFrame)\n    apply(drule_tac p=\"rev p\" in FrameStatEqClosed)\n    apply(simp add: eqvts)\n    apply(drule_tac pi=p in semantics.eqvt)\n    apply(erule_tac quietTransition)\n    apply assumption\n    apply(rule_tac x=\"rev p \\<bullet> P'\" in exI)\n    apply auto\n    apply(drule_tac pi=\"rev p\" in pt_bij3)\n    apply(simp add: eqvts)\n    apply(rule_tac x=p in exI)\n    by simp\nqed\n  \n\nlemma quietOutput:\n  fixes \\<Psi>   :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   xvec :: \"name list\"\n  and   N    :: 'a\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  \n  assumes \"\\<Psi> \\<rhd> P \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P'\"\n  and     \"quiet P\"\n\n  shows False\nusing assms\napply(erule_tac quiet.cases)\nby(force simp add: residualInject)\n\nlemma quietInput:\n  fixes \\<Psi> :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   M  :: 'a\n  and   N  :: 'a\n  and   P' :: \"('a, 'b, 'c) psi\"\n  \n  assumes \"\\<Psi> \\<rhd> P \\<longmapsto>M\\<lparr>N\\<rparr> \\<prec> P'\"\n  and     \"quiet P\"\n\n  shows False\nusing assms\nby(erule_tac quiet.cases) (force simp add: residualInject)\n\nlemma quietTau:\n  fixes \\<Psi> :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n  \n  assumes \"\\<Psi> \\<rhd> P \\<longmapsto>\\<tau> \\<prec> P'\"\n  and     \"insertAssertion (extractFrame P) \\<Psi> \\<simeq>\\<^sub>F \\<langle>\\<epsilon>, \\<Psi>\\<rangle>\"\n  and     \"quiet P\"\n\n  shows \"quiet P'\"\nusing assms\nby(erule_tac quiet.cases) (force simp add: residualInject)\n\nlemma tauChainCases[consumes 1, case_names TauBase TauStep]:\n  fixes \\<Psi>  :: 'b\n  and   P  :: \"('a, 'b, 'c) psi\"\n  and   P' :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sup>^\\<^sub>\\<tau> P'\"\n  and     \"P = P' \\<Longrightarrow> Prop\"\n  and     \"\\<Psi> \\<rhd> P \\<Longrightarrow>\\<^sub>\\<tau> P' \\<Longrightarrow> Prop\"\n\n  shows Prop\nusing assms\nby(blast elim: rtranclE dest: rtrancl_into_trancl1)\n\nend\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Psi_Calculi/Tau_Chain.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953651858118, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.25284104150788594}}
{"text": "theory MonadicWhileExample\n  imports \"../Refine_Imperative_HOL/Sepref\"\n    \"NREST.RefineMonadicVCG\"\n    \"../Refine_Imperative_HOL/IICF/IICF\"\n    Complex_Main\n    \"HOL-Decision_Procs.Approximation\"\nbegin\n\n\n\ndefinition \"bodytime = 20+rbt_delete_time_logN (Suc (10))\"\ndefinition Prog :: \"nat set nrest\" where\n  \"Prog = do {  \n          (s::nat set) \\<leftarrow> mop_set_empty 10;\n          (s::nat set) \\<leftarrow> mop_set_insert (\\<lambda>x. rbt_insert_logN (card x + 1)) (1::nat) s;                     \n          monadic_WHILEIE\n              (\\<lambda>s. finite s \\<and> card (s::nat set) \\<le> 10) (\\<lambda>s. card (s::nat set) * (bodytime)) \n             (\\<lambda>s. do { b \\<leftarrow> mop_set_isempty (\\<lambda>_. 10) s; RETURNT (~b) })\n            (\\<lambda>s. do {\n                 x \\<leftarrow> mop_set_pick (\\<lambda>_. 10) s;\n                 mop_set_del (\\<lambda>s'. rbt_delete_time_logN (card s' + 1)) s x\n                }\n              ) (s::nat set) }\"\n\nterm Prog\n\nlemma pff: \"x \\<in> s \\<Longrightarrow> finite s \\<Longrightarrow> card s > 0\"\n  using card_gt_0_iff by blast \n\nlemma mm2_some_leq: \"Some a \\<le> mm2 (Some b) (Some c) \\<longleftrightarrow> (c \\<le> b \\<and> a \\<le> b - c )\"\n  unfolding mm2_def by(auto)\n\n\nlemma F: \"160 *  (\\<lceil>2 * log 2 11\\<rceil> + 1) \\<le> 1991\"\n  by (approximation 10)\nlemma G: \"10 \\<le> 99550 - 8000 * (\\<lceil>2 * log 2 11\\<rceil> + 1)\"\n  by (approximation 10)\n\nlemma z: \"cs \\<le> 10 \\<Longrightarrow> rbt_delete_time_logN (Suc cs) \\<le> rbt_delete_time_logN (Suc 10)\"\n  apply(rule rbt_delete_time_logN_mono) by auto\n\nlemma \"Prog \\<le> SPECT [ {} \\<mapsto> enat 100000 ]\"\n  unfolding Prog_def\n  apply(rule T_specifies_I)\n  apply (vcg'\\<open>-\\<close> rules: mop_set_empty mop_set_insert  mop_set_isempty  )  \n   apply(split if_split) apply clarsimp\n  apply(intro allI impI conjI)\n    apply (vcg'\\<open>-\\<close> rules: mop_set_empty mop_set_pick  mop_set_del ) \n  subgoal  apply (auto simp: card_Diff1_le  dest: pff )\n    apply(simp only: Nat.diff_mult_distrib[symmetric])\n    apply(subst diff_diff_cancel) subgoal by(auto dest: pff)   \n    apply(simp add: bodytime_def )\n    apply(frule z) by simp\n  subgoal  by (auto )  \n  subgoal apply (auto simp: bodytime_def mm2_some_leq rbt_insert_logN_def rbt_delete_time_def btree_del_time_def rbt_delete_time_logN_def rbt_insert_time_def rbt_ins_time_def rbt_absch_def  )\n    subgoal \n      using F by simp\n    subgoal \n      using G by simp\n    done\n  subgoal by simp\n  done\n\n\n\n\n\nsepref_definition remdups_impl is \"uncurry0 (Prog)\" :: \"unit_assn\\<^sup>k \\<rightarrow>\\<^sub>a rbt_set_assn\"\n  unfolding Prog_def monadic_WHILEIE_def monadic_WHILE_aux\n\n  apply sepref_dbg_preproc\n  apply sepref_dbg_cons_init\n  apply sepref_dbg_id \n     apply sepref_dbg_monadify\n     apply sepref_dbg_opt_init                                 \n  apply sepref_dbg_trans_step+ \n  apply sepref_dbg_opt\n  apply sepref_dbg_cons_solve \\<comment> \\<open>Frame rule, recovering the invalidated list \n    or pure elements, propagating recovery over the list structure\\<close>\n  apply sepref_dbg_cons_solve \\<comment> \\<open>Trivial frame rule\\<close>\n  apply sepref_dbg_constraints\n  done\n\n\n\n\n\n\n\nend", "meta": {"author": "maxhaslbeck", "repo": "Sepreftime", "sha": "c1c987b45ec886d289ba215768182ac87b82f20d", "save_path": "github-repos/isabelle/maxhaslbeck-Sepreftime", "path": "github-repos/isabelle/maxhaslbeck-Sepreftime/Sepreftime-c1c987b45ec886d289ba215768182ac87b82f20d/Examples/MonadicWhileExample.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6442251064863697, "lm_q2_score": 0.3923368301671084, "lm_q1q2_score": 0.25275323619293016}}
{"text": "(*  Title:      HOL/Auth/n_mutualExDeadFree_lemma_inv__2_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mutualExDeadFree Protocol Case Study*} \n\ntheory n_mutualExDeadFree_lemma_inv__2_on_rules imports n_mutualExDeadFree_lemma_on_inv__2\nbegin\nsection{*All lemmas on causal relation between inv__2*}\nlemma lemma_inv__2_on_rules:\n  assumes b1: \"r \\<in> rules N\" and b2: \"(\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__2  p__Inv0 p__Inv1)\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have c1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n  apply (cut_tac b1, auto) done\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_TryVsinv__2) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_CritVsinv__2) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_ExitVsinv__2) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_IdleVsinv__2) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "hongjianjiang", "repo": "paraverif_dafny", "sha": "083d86afb46a847783cb9319d975b3c2ad0afe93", "save_path": "github-repos/isabelle/hongjianjiang-paraverif_dafny", "path": "github-repos/isabelle/hongjianjiang-paraverif_dafny/paraverif_dafny-083d86afb46a847783cb9319d975b3c2ad0afe93/examples/n_mutualExDeadFree/n_mutualExDeadFree_lemma_inv__2_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.689305616785446, "lm_q2_score": 0.36658973632215985, "lm_q1q2_score": 0.25269236430276043}}
{"text": "theory \"ToyExamplesBlocks\"\n\nimports \"../Hoare/HoareTripleForBasicBlocks\"\nbegin\n\nlemmas evm_fun_simps = \n  stack_inst_code.simps inst_size_def inst_code.simps \n\nlemmas blocks_simps = build_blocks_def byteListInt_def find_block_def blocks_indexes_def build_basic_blocks_def\n aux_basic_block.simps add_address_def block_pt_def\n\nlemma word_rcat_fixed_simps:\n  fixes x::byte\n  shows\n \"(word_rcat (x#xs) :: w256) =  word_of_int (bin_rcat 8 (map uint (x#xs)))\"\n \"(word_rcat (x#xs) :: 160 word) =  word_of_int (bin_rcat 8 (map uint (x#xs)))\"\n  by (simp add: word_rcat_def)+\n\nlemmas word_rcat_simps = word_rcat_fixed_simps bin_rcat_def bin_cat_def\n\n\nlemmas pure_emp_simps = pure_def pure_sep emp_def emp_sep zero_set_def\n\nlemma word_rcat_eq: \"word_rcat [x] = x\"\n  by (simp add: word_rcat_def bin_rcat_def)\n\nlemma pure_false_simps:\n\"(\\<langle> False \\<rangle> \\<and>* R) = \\<langle> False \\<rangle>\"\n\"(R \\<and>* \\<langle> False \\<rangle>) = \\<langle> False \\<rangle>\"\nby (rule ext, simp add: pure_def sep_conj_def emp_def )+\n\ncontext\nnotes if_split[ split del ] sep_fun_simps[simp del]\ngas_value_simps[simp add] pure_emp_simps[simp add]\nevm_fun_simps[simp add] sep_lc[simp del] sep_conj_first[simp add]\npure_false_simps[simp add]\nbegin\n\n(* Example with a Jumpi and a No block *)\n\ndefinition ex1 where\n\"ex1 = build_blocks [ Stack (PUSH_N [1]), Stack (PUSH_N [8]), Pc JUMPI, Stack (PUSH_N [1]), Misc STOP, Pc JUMPDEST, Stack (PUSH_N [2]), Misc STOP]\"\n\nschematic_goal ex1_val:\n \" ex1 = ?p\"\n by(simp add: ex1_def  word_rcat_simps Let_def dropWhile.simps  blocks_simps next_i_def\n  split:if_splits nat.splits option.splits )\n\nlemmas strengthen_insts =\ninst_strengthen_pre[OF inst_stack[OF inst_push_n]]\ninst_strengthen_pre[OF inst_stack[OF inst_pop]]\ninst_strengthen_pre[OF inst_stack[OF inst_calldataload]]\ninst_strengthen_pre[OF inst_swap]\ninst_strengthen_pre[OF inst_dup]\ninst_strengthen_pre[OF inst_memory[OF inst_mstore]]\ninst_strengthen_pre[OF inst_memory[OF inst_mload]]\ninst_strengthen_pre[OF inst_storage[OF inst_sload]]\ninst_strengthen_pre[OF inst_storage[OF inst_sstore]]\ninst_strengthen_pre[OF inst_info[OF inst_callvalue]]\ninst_strengthen_pre[OF inst_info[OF inst_caller]]\ninst_strengthen_pre[OF inst_info[OF inst_calldatasize]]\ninst_strengthen_pre[OF inst_pc[OF inst_jumpdest]]\ninst_strengthen_pre[OF inst_pc[OF inst_instPC]]\ninst_strengthen_pre[OF inst_misc[OF inst_stop]]\ninst_strengthen_pre[OF inst_misc[OF inst_return_memory]]\ninst_strengthen_pre[OF inst_misc[OF inst_return]]\ninst_strengthen_pre[OF inst_misc[OF inst_suicide]]\ninst_strengthen_pre[OF inst_arith[OF inst_arith_mul]]\ninst_strengthen_pre[OF inst_arith[OF inst_arith_div]]\ninst_strengthen_pre[OF inst_arith[OF inst_arith_mod]]\ninst_strengthen_pre[OF inst_arith[OF inst_arith_add]]\ninst_strengthen_pre[OF inst_arith[OF inst_arith_sub]]\ninst_strengthen_pre[OF inst_arith[OF inst_arith_gt]]\ninst_strengthen_pre[OF inst_arith[OF inst_arith_eq]]\ninst_strengthen_pre[OF inst_arith[OF inst_arith_lt]]\ninst_strengthen_pre[OF inst_arith[OF inst_arith_addmod]]\ninst_strengthen_pre[OF inst_arith[OF inst_arith_mulmod]]\ninst_strengthen_pre[OF inst_arith[OF inst_iszero]]\ninst_strengthen_pre[OF inst_bits[OF inst_bits_not]]\ninst_strengthen_pre[OF inst_bits[OF inst_bits_and]]\ninst_strengthen_pre[OF inst_bits[OF inst_bits_and]]\ninst_strengthen_pre[OF inst_bits[OF inst_bits_or]]\ninst_strengthen_pre[OF inst_bits[OF inst_bits_xor]]\ninst_strengthen_pre[OF inst_bits[OF inst_bits_byte]]\ninst_strengthen_pre[OF inst_unknown]\n\n\nlemma instantiate_emp:\n\"P sd \\<Longrightarrow> (P \\<and>* emp) sd\"\napply(sep_simp simp: emp_sep)\ndone\n\nmethod sep_imp_solve =\nclarsimp;\n(rule conjI),\n  (clarsimp simp add: word_rcat_def)?,\n  (sep_cancel)+,\n  (erule instantiate_emp)?,\n(simp)\n\nmethod sep_imp_solve_cancel_simp =\nclarsimp?;\n(rule conjI),\n  (clarsimp simp add: word_rcat_def)?,\n  (sep_cancel, simp?)+,\n  (erule instantiate_emp)?,\n(simp)\n\nmethod triple_seq_vcg =\n  (rule seq_inst; ((rule strengthen_insts) | triple_seq_vcg)?) |\n  rule seq_empty\n\nmethod triple_jumpi_vcg =\n ((rule blocks_jumpi; (rule refl)?),\n  triple_seq_vcg, (sep_imp_solve_cancel_simp|sep_imp_solve)+); simp add: bin_rcat_def\n\nmethod triple_jump_vcg =\n ((rule blocks_jump; (rule refl)?),\n  triple_seq_vcg, sep_imp_solve+); simp add: bin_rcat_def\n\n\nmethod triple_no_vcg =\n (rule blocks_no; triple_seq_vcg, sep_imp_solve+),\n simp add: word_rcat_simps, sep_cancel+\n\nmethod triple_next_vcg =\n ((rule blocks_next; (rule refl)?),\n  triple_seq_vcg, sep_imp_solve+); simp add: bin_rcat_def;\n  (simp add: word_rcat_simps; sep_cancel+)?\n\n\nmethod triple_vcg =\n (triple_jumpi_vcg |\n  triple_jump_vcg |\n  triple_no_vcg |\n  triple_next_vcg |\n  rule blocks_false_pre)+\n\nthm triple_blocks.intros\n(* For a jumpif that can be solved statically, it works *)\nlemma\n \"\\<exists>rest. triple_blocks net ex1\n(continuing ** stack_height 0 ** program_counter 0 ** gas_pred 1000 ** memory_usage 0)\n(0,the (block_lookup ex1 0))\n(stack 0 (word_rcat [2::byte]) ** rest)\"\n apply(unfold ex1_val)\n apply (simp)\n apply(rule exI)\n  apply triple_vcg\ndone\n\n(* Same example but we put an unknown value and an if in the post condition *)\n(* For a jumpif where we don't know at all which branch to follow, it works *)\ndefinition ex2 where\n\"ex2 x = build_blocks [ Stack (PUSH_N [x]), Stack (PUSH_N [8]), Pc JUMPI, Stack (PUSH_N [1]), Misc STOP, Pc JUMPDEST, Stack (PUSH_N [2]), Misc STOP]\"\n\nschematic_goal ex2_val:\n \" ex2 x = ?p\"\n by(simp add: ex2_def  word_rcat_simps Let_def dropWhile.simps blocks_simps next_i_def\n  split:if_splits nat.splits option.splits )\n\nlemma\n \" \\<exists>rest0 restn0. triple_blocks net (ex2 cond)\n(continuing ** stack_height 0 ** program_counter 0 ** gas_pred 1000 ** memory_usage 0)\n(0, the (block_lookup (ex2 cond) 0))\n(if word_rcat [cond] = (0::256 word) then stack 0 (word_rcat [1::byte]) ** restn0 else stack 0 (word_rcat [2::byte]) ** rest0)\n\"\n apply(unfold ex2_val)\n apply (simp split: if_splits, rule conjI; clarsimp)\n  apply(rule exI, triple_vcg)\n apply(rule exI, triple_vcg)\n apply (clarsimp simp: word_rcat_simps bintrunc_def)\ndone\n\n(* Same example as the previous one but with the unknown value as a precondition *)\n\nlemma\n \"\\<exists>rest. triple_blocks net (ex2 cond)\n(continuing ** stack_height 0 ** program_counter 0 ** gas_pred 1000 ** memory_usage 0 **\n \\<langle> (word_rcat [cond] \\<noteq> (0::256 word)) \\<rangle>)\n(0,the (block_lookup (ex2 cond) 0))\n(stack 0 (word_rcat [2::byte]) ** rest )\n\"\napply(unfold ex2_val)\napply (simp)\napply(rule exI)\napply(triple_vcg)\ndone\n\n(* Example with a Jump and a Next block*)\n\ndefinition ex3 where\n\"ex3 = build_blocks [ Stack (PUSH_N [1]), Stack (PUSH_N [5]), Pc JUMP, Pc JUMPDEST, Stack (PUSH_N [2]), Pc JUMPDEST, Misc STOP]\"\n\nschematic_goal ex3_val:\n \" ex3  = ?p\"\n by(simp add: ex3_def  word_rcat_simps Let_def dropWhile.simps blocks_simps next_i_def\n  split:if_splits nat.splits option.splits )\n\nlemma\n \"\\<exists>rest. triple_blocks net ex3\n(continuing ** stack_height 0 ** program_counter 0 ** gas_pred 1000 ** memory_usage 0)\n(0, the (block_lookup ex3 0))\n(stack 0 (word_rcat [1::byte]) ** stack_height (Suc (Suc 0)) ** stack 1 (word_rcat [2::byte]) ** rest)\n\"\napply(unfold ex3_val)\napply (simp)\napply(rule exI)\napply(triple_vcg)\ndone\nend\n\nend\n", "meta": {"author": "pirapira", "repo": "eth-isabelle", "sha": "d0bb02b3e64a2046a7c9670545d21f10bccd7b27", "save_path": "github-repos/isabelle/pirapira-eth-isabelle", "path": "github-repos/isabelle/pirapira-eth-isabelle/eth-isabelle-d0bb02b3e64a2046a7c9670545d21f10bccd7b27/example/ToyExamplesBlocks.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.626124191181315, "lm_q2_score": 0.40356685373537454, "lm_q1q2_score": 0.25268296988264943}}
{"text": "theory OpSem \nimports Main HOL.Rat \nbegin\n\ntype_synonym TS = rat (* Event *)\ntype_synonym T = nat (* Thread ID *)\ntype_synonym L = nat (*? Ref?*)\ndefinition \"null = (0 :: nat)\"\n\ntype_synonym V = nat\n\n(* bool: release/aquire or relaxed*)\ndatatype action =\n    Read bool L V\n  | Write bool L V\n  | Update L V V\n\nprint_theorems\n\nfun avar :: \"action \\<Rightarrow> L\" where\n    \"avar (Read _ x v) = x\"\n  | \"avar (Write _ x v) = x\"\n  | \"avar (Update x e v) = x\"\n\nfun wr_val :: \"action \\<Rightarrow> V option\" where\n    \"wr_val (Write _ _ v) =  Some v\"\n  | \"wr_val (Update _ _ v) = Some  v\"\n  | \"wr_val _ = None\"\n\nfun rd_val :: \"action \\<Rightarrow> V option\" where\n    \"rd_val (Read _ _ v) = Some v\"\n  | \"rd_val (Update _ v _) = Some v\"\n  | \"rd_val _ = None\"\n\nfun isRA :: \"action \\<Rightarrow> bool\" where\n    \"isRA (Read b _ _) = b\" \n  | \"isRA (Write b _ _) = b\"\n  | \"isRA (Update _ _ _) = True\"\n\nfun isWr :: \"action \\<Rightarrow> bool\" where\n    \"isWr (Read _ _ _) = False\" \n  | \"isWr (Write _ _ _) = True\"\n  | \"isWr (Update _ _ _) = False\"\n\nfun isRd :: \"action \\<Rightarrow> bool\" where\n    \"isRd (Read _ _ _) = True\" \n  | \"isRd (Write _ _ _) = False\"\n  | \"isRd (Update _ _ _) = False\"\n\nfun isUp :: \"action \\<Rightarrow> bool\" where\n    \"isUp (Read _ _ _) = False\" \n  | \"isUp (Write _ _ _) = False\"\n  | \"isUp (Update _ _ _) = True\"\n\n\nabbreviation \"reads a \\<equiv> a \\<in> (dom rd_val)\"\nabbreviation \"writes a \\<equiv> a \\<in> (dom wr_val)\"\n\n\ntype_synonym View = \"L \\<Rightarrow> T\"\n\ntype_synonym event = \"TS \\<times> T \\<times> action\"\n\nabbreviation time_stamp :: \"event \\<Rightarrow> TS\" where \"time_stamp e \\<equiv> fst e\"\nabbreviation tid :: \"event \\<Rightarrow> T\" where \"tid e \\<equiv> fst (snd e)\"\nabbreviation act :: \"event \\<Rightarrow> action\" where \"act e \\<equiv> snd (snd e)\"\n\nabbreviation var :: \"L \\<times> TS \\<Rightarrow> L\" where \"var \\<equiv> fst\"\nabbreviation tst :: \"L \\<times> TS \\<Rightarrow> TS\" where \"tst \\<equiv> snd\"\n\n(*\n\n\nrecord write_record =\n  val :: V\n  is_releasing :: bool\n\nrecord surrey_state =\n  writes :: \"(L \\<times> TS) set\"\n  thrView :: \"T \\<Rightarrow> L \\<Rightarrow> (L \\<times> TS)\"\n  modView :: \"(L \\<times> TS) \\<Rightarrow> L \\<Rightarrow> (L \\<times> TS)\"\n  mods :: \"(L \\<times> TS) \\<Rightarrow> write_record\"\n  write_available :: \"(L \\<times> TS) \\<Rightarrow> bool\" \\<comment> \\<open>rewrite as \"covered\" instead of write_available\\<close>\n\n\ndefinition \"value \\<sigma> w \\<equiv>  val (mods \\<sigma> w)\"\ndefinition \"releasing \\<sigma> w \\<equiv>  is_releasing (mods \\<sigma> w)\"\n\ndefinition \"writes_on \\<sigma> x = {w . var w = x \\<and> w \\<in> writes \\<sigma>}\"\ndefinition \"visible_writes \\<sigma> t x \\<equiv> {w \\<in> writes_on \\<sigma> x . tst(thrView \\<sigma> t x) \\<le> tst w}\" \\<comment> \\<open>is this observable writes?\\<close>\n                                             \n\n\nlemma writes_on_var [simp]: \"w \\<in> writes_on \\<sigma> x \\<Longrightarrow> var w = x\"\n  by (simp add: writes_on_def)\n\nlemma visible_var [simp]: \"w \\<in> visible_writes \\<sigma> t x \\<Longrightarrow> var w = x\"\n  by (auto simp add: visible_writes_def)\n\nlemma visible_writes_in_writes: \"visible_writes \\<sigma> t x \\<subseteq> writes \\<sigma>\"\n  using visible_writes_def writes_on_def by fastforce\n\ndefinition \"valid_fresh_ts \\<sigma> w ts' \\<equiv> tst w < ts' \\<and> (\\<forall> w' \\<in> writes_on \\<sigma> (var w). tst w < tst w' \\<longrightarrow> ts' < tst w')\"\n\ndefinition \"ts_oride m m' x \\<equiv> if tst (m x) \\<le> tst (m' x) then m' x else m x\"\n\ndefinition rev_app :: \"'s \\<Rightarrow> ('s \\<Rightarrow> 't) \\<Rightarrow> 't\" (infixl \";;\" 150)\n  where\n  \"rev_app s f \\<equiv> f s\"\n\n\ndefinition \n  \"update_thrView t nv \\<sigma> \\<equiv> \\<sigma> \\<lparr> thrView := (thrView \\<sigma>)(t := nv)\\<rparr>\"\n\ndefinition \n  \"update_modView w nv \\<sigma> \\<equiv> \\<sigma> \\<lparr> modView := (modView \\<sigma>)(w := nv) \\<rparr>\"\n\ndefinition \n  \"update_mods w nwr \\<sigma> \\<equiv> \\<sigma> \\<lparr> mods := (mods \\<sigma>)(w := nwr)\\<rparr> \\<lparr>writes := writes \\<sigma> \\<union> {w}\\<rparr>\"\n\ndefinition \n  \"update_wa w b \\<sigma> \\<equiv> \\<sigma> \\<lparr> write_available := (write_available \\<sigma>)(w := b)\\<rparr>\"\n\ndefinition \"syncing \\<sigma> w b \\<equiv> releasing \\<sigma> w \\<and> b\"\n\nlemma [simp]: \"syncing \\<sigma> w False = False\"\n  by (simp add: syncing_def)\n\nlemma [simp]: \"syncing \\<sigma> w True = releasing \\<sigma> w\"\n  by (simp add: syncing_def)\n\ndefinition\n  \"read_trans t b w \\<sigma>  \\<equiv>\n       let new_thr_idx = (thrView \\<sigma> t)(var w := w) in\n       let new_thr_idx' = \n             if syncing \\<sigma> w b then ts_oride new_thr_idx (modView \\<sigma> w) else new_thr_idx in\n          \\<sigma> ;; update_thrView t new_thr_idx'\"\n\nlemma [simp]: \"\\<not> syncing \\<sigma> w b \\<Longrightarrow> thrView (read_trans t b w \\<sigma>) t = (thrView \\<sigma> t)(var w := w)\"\n  by (simp add: read_trans_def rev_app_def update_thrView_def)\n\nlemma syncing_thrView_read_trans [simp]: \"syncing \\<sigma> w b \\<Longrightarrow>\n                     thrView (read_trans t b w \\<sigma>) t = ts_oride ((thrView \\<sigma> t)(var w := w)) (modView \\<sigma> w)\"\n  by (simp add: read_trans_def rev_app_def update_thrView_def)\n\n\nlemma [simp]: \"t' \\<noteq> t \\<Longrightarrow> thrView (read_trans t b w \\<sigma>) t' = (thrView \\<sigma> t')\"\n  apply (simp add: read_trans_def rev_app_def update_thrView_def)\n  by (metis fun_upd_other surrey_state.select_convs(2) surrey_state.surjective surrey_state.update_convs(2))\n\nlemma [simp]: \"var w \\<noteq> x \\<Longrightarrow> b = False \\<Longrightarrow> thrView (read_trans t b w \\<sigma>) t x = thrView \\<sigma> t x\"\n  by (simp add: read_trans_def rev_app_def update_thrView_def Let_def ts_oride_def)\n\nlemma [simp]: \"modView (read_trans t b w \\<sigma>) = modView \\<sigma>\"\n  by(simp add: read_trans_def Let_def rev_app_def update_thrView_def)\n\nlemma [simp]: \"mods (read_trans t b w \\<sigma>) = mods \\<sigma>\"\n  by(simp add: read_trans_def Let_def rev_app_def update_thrView_def)\n                                                            \nlemma [simp]: \"write_available (read_trans t b w \\<sigma>) = write_available \\<sigma>\"\n  by(simp add: read_trans_def Let_def rev_app_def update_thrView_def)\n\nlemma [simp]: \"writes (read_trans t b w \\<sigma>) = writes \\<sigma>\"\n  by(simp add: read_trans_def Let_def rev_app_def update_thrView_def)\n\nlemma [simp]: \"writes_on (read_trans t b w \\<sigma>) x = writes_on \\<sigma> x\"\n  apply(unfold writes_on_def)\n  by(simp add: read_trans_def Let_def rev_app_def update_thrView_def)\n\n\nlemma [simp]: \"value (read_trans t False w \\<sigma>) x  = value \\<sigma> x\"\n  apply(unfold value_def)\n  by(simp add: read_trans_def Let_def rev_app_def update_thrView_def)\n\n\ndefinition\n  \"write_trans t b w v \\<sigma> ts' \\<equiv>\n          \\<sigma> ;; update_thrView t ((thrView \\<sigma> t)(var w := (var w, ts'))) \n            ;; update_modView (var w, ts') ((thrView \\<sigma> t)(var w := (var w, ts')))\n            ;; update_mods (var w, ts') \\<lparr> val = v, is_releasing = b\\<rparr> \n            ;; update_wa (var w, ts') True\"\n\n\nlemma [simp]: \"thrView (write_trans t b w v \\<sigma> ts') t = (thrView \\<sigma> t)(var w := (var w, ts'))\"\n  by (simp add: write_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"t' \\<noteq> t \\<Longrightarrow> thrView (write_trans t b w v \\<sigma> ts') t' = (thrView \\<sigma> t')\"\n  by (simp add: write_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"var w' = var w \\<Longrightarrow> tst w' = ts' \\<Longrightarrow> modView (write_trans t b w v \\<sigma> ts') w' = (thrView \\<sigma> t)(var w := (var w, ts'))\"\n  apply (simp add: write_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n  by (metis prod.collapse)\n\nlemma [simp]: \"var w' \\<noteq> var w \\<Longrightarrow> modView (write_trans t b w v \\<sigma> ts') w' = modView \\<sigma> w'\"\n  by (auto simp add: write_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"var w' \\<noteq> var w \\<Longrightarrow> modView (write_trans t b w v \\<sigma> ts') w' y = modView \\<sigma> w' y\"\n  by (auto simp add: write_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"tst w' \\<noteq> ts' \\<Longrightarrow> modView (write_trans t b w v \\<sigma> ts') w' = modView \\<sigma> w'\"\n  by (auto simp add: write_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"var w' = var w \\<Longrightarrow> tst w' = ts' \\<Longrightarrow> mods (write_trans t b w v \\<sigma> ts') w' = \\<lparr> val = v, is_releasing = b\\<rparr>\"\n  apply (simp add: write_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n  by (metis prod.collapse)\n\nlemma [simp]: \"var w' \\<noteq> var w \\<Longrightarrow> mods (write_trans t b w v \\<sigma> ts') w' = mods \\<sigma> w'\"\n  by (auto simp add: write_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"tst w' \\<noteq> ts' \\<Longrightarrow> mods (write_trans t b w v \\<sigma> ts') w' = mods \\<sigma> w'\"\n  by (auto simp add: write_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"var w' = var w \\<Longrightarrow> tst w' = ts' \\<Longrightarrow> write_available (write_trans t b w v \\<sigma> ts') w' = True\"\n  apply (simp add: write_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n  by (metis prod.collapse)\n\nlemma [simp]: \"var w' \\<noteq> var w \\<Longrightarrow>\n                write_available (write_trans t b w v \\<sigma> ts') w' = write_available \\<sigma> w'\"\n  by (auto simp add: write_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"tst w' \\<noteq> ts' \\<Longrightarrow> write_available (write_trans t b w v \\<sigma> ts') w' = write_available \\<sigma> w'\"\n  by (auto simp add: write_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma writes_new_w [simp]: \"writes (write_trans t b w v \\<sigma> ts') = writes \\<sigma> \\<union> {(var w, ts')}\"\n  by(simp add: Let_def rev_app_def\n                   write_trans_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"x = var w \\<Longrightarrow> writes_on (write_trans t b w v \\<sigma> ts') x = writes_on \\<sigma> x \\<union> {(var w, ts')}\"\n  apply(unfold writes_on_def)\n  apply(simp add: read_trans_def Let_def rev_app_def update_thrView_def)\n  using Collect_cong by auto\n\nlemma [simp]: \"y \\<noteq> var w \\<Longrightarrow> writes_on (write_trans t b w v \\<sigma> ts') y = writes_on \\<sigma> y\"\n  apply(unfold writes_on_def)\n  by(auto simp add: read_trans_def Let_def rev_app_def update_thrView_def)\n\nlemma [simp]: \"w \\<in> writes_on \\<sigma> y \\<Longrightarrow>  w \\<in> writes_on (write_trans t b w' v \\<sigma> ts') y\"\n  apply(unfold writes_on_def)\n  by simp\n\n\n\n\ndefinition \"update_trans t w v' \\<sigma> ts' \\<equiv> \n       let new_thr_idx = (thrView \\<sigma> t)(var w := (var w, ts')) in\n         let new_thr_idx' =\n             if releasing \\<sigma> w\n             then\n                 ts_oride new_thr_idx (modView \\<sigma> w) \n             else\n                 new_thr_idx \n             in\n                 \\<sigma> ;; update_thrView t new_thr_idx' \n                   ;; update_modView (var w, ts') new_thr_idx' \\<comment> \\<open>TODO: check this prime on new_thr_idx\\<close> \n                   ;; update_mods (var w, ts') \\<lparr> val = v', is_releasing = True\\<rparr>\n                   ;; update_wa (var w, ts') True\n                   ;; update_wa w False\"\n\n\nlemma [simp]: \"\\<not> releasing \\<sigma> w \\<Longrightarrow>\n                     thrView (update_trans  t w v' \\<sigma> ts') t = (thrView \\<sigma> t)(var w := (var w, ts'))\"\n  by (simp add: Let_def rev_app_def update_modView_def update_mods_def update_thrView_def update_trans_def update_wa_def)\n\nlemma [simp]: \" releasing \\<sigma> w \\<Longrightarrow> \n                  thrView (update_trans  t w v' \\<sigma> ts') t = ts_oride ((thrView \\<sigma> t)(var w := (var w, ts'))) (modView \\<sigma> w)\"\n  by (auto simp add: Let_def update_trans_def update_wa_def rev_app_def update_modView_def update_mods_def update_thrView_def)\n\nlemma [simp]: \"t' \\<noteq> t \\<Longrightarrow> thrView (update_trans  t w v' \\<sigma> ts') t' = (thrView \\<sigma> t')\"\n  by (simp add: Let_def update_trans_def update_wa_def rev_app_def update_modView_def update_mods_def update_thrView_def)\n\n\nlemma [simp]: \"var w' = var w \\<Longrightarrow> tst w' = ts' \\<Longrightarrow>\n             \\<not> releasing \\<sigma> w \\<Longrightarrow> modView (update_trans t w v' \\<sigma> ts') w' = (thrView \\<sigma> t)(var w := (var w, ts'))\"\n  apply (simp add: Let_def update_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n  by (metis prod.collapse)\n\nlemma [simp]: \"var w' = var w \\<Longrightarrow> tst w' = ts' \\<Longrightarrow>\n             releasing \\<sigma> w \\<Longrightarrow> modView (update_trans t w v' \\<sigma> ts') w' = ts_oride ((thrView \\<sigma> t)(var w := (var w, ts'))) (modView \\<sigma> w)\"\n  apply (simp add: Let_def update_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n  by (metis prod.collapse)\n\nlemma [simp]: \"var w' \\<noteq> var w \\<Longrightarrow> modView (update_trans t w v' \\<sigma> ts') w' = modView \\<sigma> w'\"\n  by (auto simp add: Let_def fun_upd_idem_iff fun_upd_twist rev_app_def update_modView_def update_mods_def update_thrView_def update_trans_def update_wa_def)\n  \nlemma [simp]: \"tst w' \\<noteq> ts' \\<Longrightarrow> modView (update_trans t w v' \\<sigma> ts') w' = modView \\<sigma> w'\"\n  by (auto simp add: Let_def update_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"var w' \\<noteq> var w \\<Longrightarrow> mods (update_trans t w v' \\<sigma> ts') w' = mods \\<sigma> w'\"\n  by (auto simp add: Let_def update_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"tst w' \\<noteq> ts' \\<Longrightarrow> mods (update_trans t w v' \\<sigma> ts') w' = mods \\<sigma> w'\"\n  by (auto simp add: Let_def update_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"var w' = var w \\<Longrightarrow> tst w' = ts' \\<Longrightarrow>\n             mods (update_trans t w v' \\<sigma> ts') w' = \\<lparr> val = v', is_releasing = True\\<rparr>\"\n  apply (simp add: Let_def update_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n  by (metis prod.collapse)\n\nlemma [simp]: \"var w' = var w \\<Longrightarrow> tst w' = ts' \\<Longrightarrow> \n       tst w \\<noteq> ts' \\<Longrightarrow> write_available (update_trans t w v' \\<sigma> ts') w'\"\n  apply (auto simp add: Let_def update_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n  by (metis prod.collapse)\n\nlemma [simp]: \"var w' \\<noteq> var w \\<Longrightarrow> write_available (update_trans t w v' \\<sigma> ts') w' = write_available \\<sigma> w'\"\n  by (auto simp add: Let_def update_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"\\<not> write_available (update_trans t w v' \\<sigma> ts') w\"\n  by (simp add: Let_def update_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"tst w' \\<noteq> ts' \\<and> tst w' \\<noteq> tst w \\<Longrightarrow> write_available (update_trans t w v' \\<sigma> ts') w' = write_available \\<sigma> w'\"\n by (auto simp add: Let_def update_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"writes (update_trans t w v' \\<sigma> ts') = writes \\<sigma> \\<union> {(var w, ts')}\"\n by (auto simp add: Let_def update_trans_def rev_app_def update_wa_def update_thrView_def\n                   update_modView_def update_mods_def)\n\nlemma [simp]: \"x = var w \\<Longrightarrow> writes_on (update_trans t w v' \\<sigma> ts') x = writes_on \\<sigma> x \\<union> {(x, ts')}\"\n  apply(unfold writes_on_def)\n  apply(simp add: read_trans_def Let_def rev_app_def update_thrView_def)\n  using Collect_cong by auto\n\nlemma [simp]: \"y \\<noteq> var w \\<Longrightarrow> writes_on (update_trans t w v' \\<sigma> ts') y = writes_on \\<sigma> y\"\n  apply(unfold writes_on_def)\n  by(auto simp add: read_trans_def Let_def rev_app_def update_thrView_def)\n\n\ndefinition step :: \"T \\<Rightarrow> action \\<Rightarrow> surrey_state \\<Rightarrow> surrey_state \\<Rightarrow> bool\"\n  where\n    \"step t a \\<sigma> \\<sigma>'\\<equiv>\n       \\<exists> w. w \\<in> visible_writes \\<sigma> t (avar a) \\<and>\n       (case a of\n         Read b x v \\<Rightarrow>\n           v = value \\<sigma> w \\<and>\n           \\<sigma>' = read_trans t b w \\<sigma>\n       | Write b x v \\<Rightarrow> \\<exists> ts'.\n           write_available \\<sigma> w \\<and> \\<comment> \\<open> TODO: use sets and predicates consistently \\<close>\n           valid_fresh_ts \\<sigma> w ts' \\<and>\n           \\<sigma>' = write_trans t b w v \\<sigma> ts'\n       | Update x v v' \\<Rightarrow> \\<exists> ts'.\n           v = value \\<sigma> w \\<and> \n           write_available \\<sigma> w \\<and>\n           valid_fresh_ts \\<sigma> w ts' \\<and>\n           \\<sigma>' = update_trans t w v' \\<sigma> ts')\n           \"\n\nlemma step_cases:\n       \"step t a \\<sigma> \\<sigma>'\n          \\<Longrightarrow> \n        \\<lbrakk>\\<And> w b x v. \\<sigma>' = read_trans t b w \\<sigma> \\<and> a = Read b x v \\<and> w \\<in> visible_writes \\<sigma> t (avar a) \\<and>\n          v = value \\<sigma> w \\<Longrightarrow> P \\<sigma> (read_trans t b w \\<sigma>)\\<rbrakk>\n         \\<Longrightarrow>\n       \\<lbrakk>\\<And> w b x v ts'. \\<sigma>' = write_trans t b w v \\<sigma> ts' \\<and> a = Write b x v \\<and> w \\<in> visible_writes \\<sigma> t (avar a) \\<and>\n           write_available \\<sigma> w \\<and>\n           valid_fresh_ts \\<sigma> w ts'\n           \\<Longrightarrow> P \\<sigma> (write_trans t b w v \\<sigma> ts') \\<rbrakk>\n         \\<Longrightarrow>\n       \\<lbrakk>\\<And> w x v v' ts'. \\<sigma>' = update_trans t w v' \\<sigma> ts' \\<and> a = Update x v v' \\<and>\n           w \\<in> visible_writes \\<sigma> t (avar a) \\<and>\n           v = value \\<sigma> w \\<and>\n           write_available \\<sigma> w \\<and>\n           valid_fresh_ts \\<sigma> w ts'\n           \\<Longrightarrow> P \\<sigma> (update_trans t w v' \\<sigma> ts')\\<rbrakk>\n  \\<Longrightarrow> P \\<sigma> \\<sigma>'\"\n  apply(simp add: step_def) apply(case_tac a) by auto\n\n\n\ndefinition \"WrX x v \\<equiv> Write False x v\"\ndefinition \"WrR x v \\<equiv> Write True x v\"\ndefinition \"RdX x v \\<equiv> Read False x v\"\ndefinition \"RdA x v \\<equiv> Read True x v\"\n\n\n\nabbreviation WrX_state_abbr:: \" surrey_state \\<Rightarrow> L \\<Rightarrow> V \\<Rightarrow> T \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"_ [_ := _]\\<^sub>_ _\" [100,100,100,100,100])\n  where \"\\<sigma> [x := v]\\<^sub>t \\<sigma>' \\<equiv> step t (WrX x v) \\<sigma> \\<sigma>'\"\n\nabbreviation WrR_state_abbr:: \" surrey_state \\<Rightarrow> L \\<Rightarrow> V \\<Rightarrow> T \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"_ [_ :=\\<^sup>R _]\\<^sub>_ _\" [100,100,100,100,100])\n  where \"\\<sigma> [x :=\\<^sup>R v]\\<^sub>t \\<sigma>' \\<equiv> step t (WrR x v) \\<sigma> \\<sigma>'\"\n\nabbreviation RdX_state_abbr:: \" surrey_state \\<Rightarrow> V \\<Rightarrow> L \\<Rightarrow> T \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"_ [_ \\<leftarrow> _]\\<^sub>_ _\" [100,100,100,100,100])\n  where \"\\<sigma> [r \\<leftarrow> x]\\<^sub>t \\<sigma>' \\<equiv> step t (RdX x r) \\<sigma> \\<sigma>'\"\n\nabbreviation RdA_state_abbr:: \" surrey_state \\<Rightarrow> V \\<Rightarrow> L \\<Rightarrow> T \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"_ [_ \\<leftarrow>\\<^sup>A _]\\<^sub>_ _\" [100,100,100,100,100])\n  where \"\\<sigma> [r \\<leftarrow>\\<^sup>A x]\\<^sub>t \\<sigma>' \\<equiv> step t (RdA x r) \\<sigma> \\<sigma>'\"\n\nabbreviation Up_state_abbr:: \" surrey_state \\<Rightarrow> L \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> T \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"_ RMW[_, _, _]\\<^sub>_ _\" [100,100,100,100,100,100])\n  where \"\\<sigma> RMW[x, u, v]\\<^sub>t \\<sigma>' \\<equiv> step t (Update x u v) \\<sigma> \\<sigma>'\"\n\n\n\n\ndefinition \"initial_state \\<sigma> I \\<equiv>\n                 \\<exists> F . writes \\<sigma> = (\\<lambda>x. (x, F x)) ` UNIV \\<and>\n                       (\\<forall> t x. thrView \\<sigma> t x = (x, F x)) \\<and>\n                       (\\<forall> w x. modView \\<sigma> w x = (x, F x)) \\<and>\n                       (\\<forall> w. mods \\<sigma> w = \\<lparr> val = I (var w), is_releasing = False \\<rparr>) \\<and>\n                       (\\<forall> w. write_available \\<sigma> w = True)\"\n\n(*\ndefinition \"initial_state \\<sigma> I \\<equiv>\n                 \\<exists> F . writes \\<sigma> = {(x, F x) | x. True} \\<and>\n                       (\\<forall> t x. thrView \\<sigma> t x = (x, F x)) \\<and>\n                       (\\<forall> w x. modView \\<sigma> w x = (x, F x)) \\<and>\n                       (\\<forall> w. mods \\<sigma> w = \\<lparr> val = I (var w), is_releasing = False \\<rparr>) \\<and>\n                       (\\<forall> w. write_available \\<sigma> w = True)\"\n*)\n\ndefinition  \"lastWr \\<sigma> x \\<equiv> (x, Max (tst`(writes_on \\<sigma> x)))\" \n\n\ndefinition\n  \"wfs \\<sigma> \\<equiv>\n      (\\<forall> t x. thrView \\<sigma> t x \\<in> writes_on \\<sigma> x) \\<and>\n      (\\<forall> w x. modView \\<sigma> w x \\<in> writes_on \\<sigma> x) \\<and>\n      (\\<forall> x. finite(writes_on \\<sigma> x)) \\<and>\n      (\\<forall> w. w \\<in> writes \\<sigma> \\<longrightarrow> modView \\<sigma> w (var w) = w) \\<and>\n      (\\<forall> w x. w = lastWr \\<sigma> x \\<longrightarrow> write_available \\<sigma> w )\"\n\nlemma initially_write_unique: \n  \"initial_state \\<sigma> I \\<Longrightarrow> w \\<in> writes_on \\<sigma> x \\<Longrightarrow> w' \\<in> writes_on \\<sigma> x \\<Longrightarrow> w = w'\"\n  apply(unfold initial_state_def writes_on_def) by auto\n\n  lemma finite_single_fst_eq: \\<open>finite {w. fst w = x \\<and> (\\<exists>x. w = (x, F\n    x))}\\<close> (is \\<open>finite ?A\\<close>) proof - have \\<open>?A \\<subseteq> {(x, F x)}\\<close> by auto from\n    finite_subset[OF this] show ?thesis by auto qed\n\n  lemma in_writes_onI: \\<open>var w = x \\<Longrightarrow> w \\<in> writes \\<sigma> \\<Longrightarrow> w \\<in> writes_on \\<sigma> x\\<close>\n    unfolding writes_on_def by auto\n\n(*\n  lemma initial_wfs: assumes \"initial_state \\<sigma> I\" shows \"wfs \\<sigma>\" using\n    assms initially_write_unique[OF assms(1)]  \n    \n    apply (auto simp add: wfs_def\n     initial_state_def lastWr_def \n     intro: in_writes_onI)\n\n    sledgehammer\n*)\n  \n(* TODO: do something about SMTs *)\nlemma initial_wfs: \n  assumes \"initial_state \\<sigma> I\"  \n  shows \"wfs \\<sigma>\"\n  apply(simp add: initial_state_def wfs_def)\n  apply(rule conjI) apply (unfold writes_on_def, clarify) \n  apply (metis (mono_tags) UNIV_I assms fst_conv image_eqI initial_state_def) \n  apply(rule conjI)\n  using assms apply (simp add: initial_state_def) \n   apply auto[1] \n  apply rule using initially_write_unique[OF assms] \n  apply (smt Collect_cong empty_iff finite.intros(1) finite.intros(2) insert_compr mem_Collect_eq not_finite_existsD writes_on_def) \n  using assms apply safe\n  apply (simp add: initial_state_def) apply auto[1]\n  using initial_state_def by blast \n\n\n\nlemma allI_case: \"\\<lbrakk>\\<And> y. x \\<noteq> y \\<Longrightarrow> P y\\<rbrakk> \\<Longrightarrow> \\<lbrakk>P x\\<rbrakk> \\<Longrightarrow> \\<forall> y. P y\" by fastforce\n\n\nlemma [simp]: \"wfs \\<sigma> \\<Longrightarrow> writes_on \\<sigma> x \\<noteq> {}\"\n  apply(simp add: wfs_def)\n  by (metis empty_iff)\n\nlemma [simp]: \"wfs \\<sigma> \\<Longrightarrow> finite(writes_on \\<sigma> x)\"\n  by(simp add: wfs_def)\n\nlemma [simp]: \"wfs \\<sigma> \\<Longrightarrow> thrView \\<sigma> t x \\<in> writes_on \\<sigma> x\"\n  by(simp add: wfs_def)\n\nlemma [simp]: \"wfs \\<sigma> \\<Longrightarrow> modView \\<sigma> w x \\<in> writes_on \\<sigma> x\"\n  using wfs_def by blast\n\n\nlemma [simp]: \"wfs \\<sigma> \\<Longrightarrow> modView (read_trans t b w \\<sigma>) w x \\<in> writes_on (read_trans t b w \\<sigma>) x\"\n  by auto\n\nlemma [simp]: \"wfs \\<sigma> \\<Longrightarrow> writes_on \\<sigma> x =  writes_on (read_trans t b w \\<sigma>) x\"\n  by auto\n\n\nlemma own_ModView:\n  assumes \"wfs \\<sigma>\"\n      and \"w \\<in> writes \\<sigma>\"\n    shows \"modView \\<sigma> w (var w) = w\"\n  using assms apply(unfold wfs_def)\n  by blast\n\nlemma ts_oride_same_var:\n  assumes \"wfs \\<sigma>\"\n      and \"x = var w\"\n      and \"w \\<in> visible_writes \\<sigma> t (var w)\"\n    shows \"ts_oride ((thrView \\<sigma> t)(var w := w)) (modView \\<sigma> w) x = w\"\n  apply(simp add: ts_oride_def) apply safe using assms\n  apply (meson own_ModView subsetCE visible_writes_in_writes)\n  using assms(2) apply blast \n  using assms(2) by blast\n\nlemma ts_oride_diff_var:\n  assumes \"wfs \\<sigma>\"\n      and \"x \\<noteq> var w\"\n      and \"w \\<in> visible_writes \\<sigma> t (var w)\"\n    shows \"ts_oride ((thrView \\<sigma> t)(var w := w')) (modView \\<sigma> w) x = ts_oride (thrView \\<sigma> t) (modView \\<sigma> w) x\"\n  apply(simp add: ts_oride_def)\n  using assms(2) by blast\n\nlemma ts_oride_split:\n  assumes \"tst (m' x) \\<le> tst (m x) \\<Longrightarrow> P (m x)\"\n      and \"tst (m x) \\<le> tst (m' x) \\<Longrightarrow> P (m' x)\"\n    shows \"P (ts_oride m m' x)\"\n  apply(simp add: ts_oride_def)\n  by (simp add: assms(1) assms(2))\n\nlemma wr_other_pres_last: \"wfs \\<sigma> \\<Longrightarrow> x \\<noteq> xa \\<Longrightarrow> lastWr (write_trans t ba (x, b) v \\<sigma> ts') xa = lastWr \\<sigma> xa\"\n  by(simp add: lastWr_def)\n\nlemma upd_other_pres_last: \"wfs \\<sigma> \\<Longrightarrow> x \\<noteq> xa \\<Longrightarrow> lastWr (update_trans t (x, b) v \\<sigma> ts') xa = lastWr \\<sigma> xa\"\n  by(simp add: lastWr_def)\n\nlemma last_w_not_last: \"wfs \\<sigma> \\<Longrightarrow> (xa, b) \\<in> visible_writes \\<sigma> t xa \\<Longrightarrow> valid_fresh_ts \\<sigma> (xa,b) ts'  \\<Longrightarrow> b \\<noteq> Max (tst ` writes_on \\<sigma> xa) \\<Longrightarrow> lastWr (write_trans t ba (xa, b) v \\<sigma> ts') xa =  lastWr  \\<sigma> xa \"\n  apply(simp add: visible_writes_def valid_fresh_ts_def)\n  apply(elim conjE)\n  apply(subgoal_tac \"b <  Max (tst ` writes_on \\<sigma> xa)\")\n   defer\n  apply(unfold wfs_def , clarsimp)\n   apply (metis Max_ge finite_imageI image_eqI le_neq_trans snd_conv)\n  apply(subgoal_tac \"tst (lastWr \\<sigma> xa) = Max (tst ` writes_on \\<sigma> xa)\")\n   defer\n   apply (simp add: lastWr_def)\n  apply (simp add: lastWr_def)\n  apply(subgoal_tac \"ts' <  Max (tst ` writes_on \\<sigma> xa)\")\n   defer\n   apply simp\n  apply (metis (mono_tags, lifting) Max_in empty_iff finite_imageI image_iff) \n  by (smt Max_ge Max_in empty_iff finite_imageI finite_insert image_is_empty insert_iff le_neq_trans less_imp_not_less) \n\n\n\nlemma last_w_not_last_upd: \"wfs \\<sigma> \\<Longrightarrow> (xa, b) \\<in> visible_writes \\<sigma> t xa \\<Longrightarrow> valid_fresh_ts \\<sigma> (xa,b) ts'  \\<Longrightarrow> b \\<noteq> Max (tst ` writes_on \\<sigma> xa) \\<Longrightarrow> lastWr (update_trans t (xa, b) v \\<sigma> ts') xa =  lastWr  \\<sigma> xa \"\n  apply(simp add: visible_writes_def valid_fresh_ts_def)\n  apply(elim conjE)\n  apply(subgoal_tac \"b <  Max (tst ` writes_on \\<sigma> xa)\")\n   defer\n  apply(unfold wfs_def, clarsimp)\n   apply (metis Max_ge finite_imageI image_eqI le_neq_trans snd_conv)\n  apply(subgoal_tac \"tst (lastWr \\<sigma> xa) = Max (tst ` writes_on \\<sigma> xa)\")\n  apply (simp add: lastWr_def)\n  apply(subgoal_tac \"ts' <  Max (tst ` writes_on \\<sigma> xa)\")\n   apply (smt Max_ge Max_in dual_order.antisym empty_iff finite_imageI finite_insert image_is_empty insert_iff leD)\n  apply (metis (mono_tags, lifting) Max_in empty_iff finite_imageI image_iff)\n  by (simp add: lastWr_def)\n\nlemma lastWr_w: \"wfs \\<sigma> \\<Longrightarrow> (xa, Max (tst ` writes_on \\<sigma> xa)) \\<in> visible_writes \\<sigma> t xa \\<Longrightarrow> valid_fresh_ts \\<sigma> ((xa, Max (tst ` writes_on \\<sigma> xa))) ts' \\<Longrightarrow>\n    lastWr (write_trans t ba ((xa, Max (tst ` writes_on \\<sigma> xa)))  v \\<sigma> ts') xa = (xa, ts')\"\n  apply(unfold wfs_def)\n  apply clarsimp\n  apply(simp add: valid_fresh_ts_def)\n  apply(elim conjE)\n  apply(simp add: lastWr_def)\n  by (meson Max_ge Max_insert2 dual_order.strict_implies_order dual_order.trans finite_imageI)\n\n\nlemma lastWr_upd: \"wfs \\<sigma> \\<Longrightarrow> (xa, Max (tst ` writes_on \\<sigma> xa)) \\<in> visible_writes \\<sigma> t xa \\<Longrightarrow> valid_fresh_ts \\<sigma> ((xa, Max (tst ` writes_on \\<sigma> xa))) ts' \\<Longrightarrow>\n    lastWr (update_trans t ((xa, Max (tst ` writes_on \\<sigma> xa)))  v \\<sigma> ts') xa = (xa, ts')\"\n  apply(unfold wfs_def)\n  apply clarsimp\n  apply(simp add: valid_fresh_ts_def)\n  apply(elim conjE)\n  apply(simp add: lastWr_def)\n  by (meson Max_ge Max_insert2 dual_order.strict_implies_order dual_order.trans finite_imageI)\n\n(*\nlemmas lastWrdefs [simp] = lastWr_def \n\nlemma finite_writes: \n  assumes \"aa \\<noteq> xa\" \n    and \"finite{w. var w = xa \\<and> w \\<in> surrey_state.writes \\<sigma>}\" \n  shows\n    \"finite{w. var w = xa \\<and>\n              w \\<in> surrey_state.writes (write_trans t ba (aa, b) v \\<sigma> ts')}\"\n using assms apply auto \n  by (smt Collect_cong fst_conv) \n\nlemma wfs_preserved:\n  assumes \"wfs \\<sigma>\"\n      and \"step t a \\<sigma> \\<sigma>'\"\n    shows \"wfs \\<sigma>'\"\n  using assms(1) apply(unfold wfs_def)\n  apply (rule step_cases[OF assms(2)]) \n  apply safe apply clarsimp\n  unfolding writes_on_def apply (simp add: read_trans_def rev_app_def Let_def)\n  apply (intro conjI impI)\n  apply (simp add: ts_oride_def update_thrView_def)\n  apply (simp add: ts_oride_def update_thrView_def)\n  apply clarsimp \n  apply (meson in_mono visible_writes_in_writes)\n  apply (simp add: ts_oride_def update_thrView_def)\n  apply (simp add: ts_oride_def update_thrView_def)\n  apply (meson in_mono visible_writes_in_writes)\n  apply auto[4]\n  unfolding writes_on_def apply (simp add: update_modView_def update_thrView_def update_wa_def update_mods_def write_trans_def rev_app_def Let_def)\n  unfolding writes_on_def apply (simp add: update_modView_def update_thrView_def update_wa_def update_mods_def write_trans_def rev_app_def Let_def)\n  unfolding writes_on_def apply (simp add: visible_writes_def valid_fresh_ts_def update_modView_def update_thrView_def update_wa_def update_mods_def write_trans_def rev_app_def Let_def)\n         apply(case_tac \"xa = aa\") \n          prefer 2 apply (erule_tac x = \"xa\" in allE)+ apply auto [1] using finite_writes \n  apply (smt Collect_cong fst_conv) \n  apply (unfold writes_on_def) apply auto [1] \n  sledgehammer\n  sorry\n*)\n\nlemma wfs_preserved:\n  assumes \"wfs \\<sigma>\"\n      and \"step t a \\<sigma> \\<sigma>'\"\n    shows \"wfs \\<sigma>'\"\n  apply(unfold wfs_def)\n  apply rule defer apply rule defer apply rule defer defer\n    apply clarsimp defer\n    apply clarsimp\n     apply (rule step_cases[OF assms(2)]) apply simp_all\n  using assms(1) wfs_def apply auto[1]\n  apply(case_tac \"var w = aa\")\n       apply(case_tac \"(aa, b) = (x, ts')\") apply simp\n  apply simp \n       apply(case_tac \"b = ts'\") apply simp using assms(1) wfs_def apply blast\n   apply simp apply(case_tac \"var w = x\") apply simp\n  using assms(1) wfs_def apply blast  apply simp\n  using assms(1) wfs_def apply blast\n   apply simp apply(case_tac \"var w = x\") apply simp \n  using assms(1) wfs_def apply blast apply simp\n  using assms(1) wfs_def apply blast\n     apply(case_tac \"var w = aa\") (*********)\n  apply(case_tac \"releasing \\<sigma> w\")\n      apply(case_tac \"(aa, b) = (x, ts')\")\n        apply simp apply (metis assms(1) fun_upd_same ts_oride_def wfs_def)\n       apply(case_tac \"b = ts'\") apply(case_tac \"var w = x\") apply simp\n        apply simp apply(rule ts_oride_split) using assms(1) apply simp\n          using assms(1) apply simp\n          apply(case_tac \"var w = x\") apply simp using assms(1) wfs_def apply blast\n               apply simp using assms(1) wfs_def apply blast\n              apply(case_tac \"(aa, b) = (x, ts')\") apply simp\n          apply simp apply(case_tac \"var w = x\") apply simp using assms(1) wfs_def apply blast\n          apply(case_tac \"b = ts'\")apply simp using assms(1) wfs_def apply blast\n         apply simp using assms(1) wfs_def apply blast\n          apply(case_tac \"var w = x\") apply simp using assms(1) wfs_def apply blast\n             apply simp using assms(1) wfs_def apply blast\n          apply clarsimp apply (rule step_cases[OF assms(2)]) apply simp_all\n          using assms(1) wfs_def apply blast\n             apply(case_tac \"var w = x\") apply simp using assms(1) wfs_def apply blast\n             apply simp using assms(1) wfs_def apply blast\n             apply(case_tac \"var w = x\") apply simp using assms(1) wfs_def apply blast\n            apply simp using assms(1) wfs_def apply blast\n           defer\n          apply (rule step_cases[OF assms(2)])\n            apply(case_tac \"ta = t\") apply(case_tac \"syncing \\<sigma> w b\")\n               apply simp apply(rule ts_oride_split) \n          apply (metis assms(1) fun_upd_apply subsetCE visible_writes_in_writes wfs_def)\n  using assms(1) wfs_def apply blast apply simp \n     apply (metis assms(1) subsetCE visible_writes_in_writes wfs_def)\n    apply simp using assms(1) wfs_def apply blast\n            apply(case_tac \"ta = t\") apply simp\n  using assms(1) wfs_def apply blast\n  apply simp apply(case_tac \"var w = x\") apply simp\n  using assms(1) wfs_def apply blast\n   apply simp using assms(1) wfs_def apply blast\n  apply(case_tac \"ta = t\") apply simp apply(case_tac \"releasing \\<sigma> w\") apply simp\n  apply(case_tac \"var w = x\") apply simp \n     apply (metis assms(1) fun_upd_same ts_oride_def wfs_def)\n  apply simp apply(rule ts_oride_split)\n  using assms(1) apply auto[1] \n  using assms(1) wfs_def apply blast\n  apply simp  \n  using assms(1) wfs_def apply blast\n  apply simp apply(case_tac \"var w = x\") apply simp\n  using assms(1) wfs_def apply blast apply simp\n  using assms(1) wfs_def apply blast\n           apply (rule step_cases[OF assms(2)]) apply simp\n          using assms(1)\n             apply(unfold wfs_def read_trans_def)\n          apply(simp add: rev_app_def Let_def syncing_def)\n             apply(simp add: update_wa_def update_mods_def update_modView_def update_thrView_def ts_oride_def)\n          apply(simp add: lastWr_def)\n             apply(unfold writes_on_def, simp)\n            apply(elim conjE)\n            apply(intro conjI)\n             apply(intro allI impI)\n          apply simp\n          apply (smt fun_upd_def rev_app_def surrey_state.select_convs(3) surrey_state.surjective surrey_state.update_convs(1) surrey_state.update_convs(2) surrey_state.update_convs(3) surrey_state.update_convs(4) surrey_state.update_convs(5) update_modView_def update_mods_def update_thrView_def update_wa_def visible_var write_trans_def)\n          (**)  apply(intro allI impI)\n          apply clarsimp\n             apply(case_tac \"aa \\<noteq> x\")\n          apply(unfold  visible_writes_def writes_on_def)\n             apply simp\n            apply clarsimp\n            apply(case_tac \"x \\<noteq> xa\")\n          using assms(1)\n             apply(simp add: wr_other_pres_last lastWr_def)\n            apply simp\n            apply(case_tac \"b \\<noteq>  Max (tst ` writes_on \\<sigma> xa)\")\n          using assms(1) \n             apply simp\n          apply(subgoal_tac \"(xa, b) \\<in> visible_writes \\<sigma> t xa\")\n              apply (simp add: last_w_not_last)\n              apply(simp add: write_trans_def rev_app_def)\n          apply (simp add:  update_modView_def update_mods_def update_thrView_def update_wa_def)\n          apply(simp add: visible_writes_def)\n\n          apply (metis wfs_def)\n            apply simp    \n          apply(subgoal_tac \"lastWr (write_trans t ba (xa, Max (tst ` writes_on \\<sigma> xa)) v \\<sigma> ts') xa = (xa, ts')\")\n             apply simp   \n          using assms(1)\n          apply(unfold wfs_def)\n          apply clarsimp\n          apply(simp add: valid_fresh_ts_def)\n          apply(elim conjE)\n          apply(simp add: lastWr_def)\n            apply (meson Max_ge Max_insert2 dual_order.strict_implies_order dual_order.trans finite_imageI)\n\n           apply(elim conjE)\n            apply(intro conjI)\n             apply(intro allI impI)\n          apply simp\n            apply (simp add:  rev_app_def Let_def  update_modView_def update_mods_def update_thrView_def update_wa_def  update_trans_def)\n            apply(intro conjI impI)\n          apply(simp add: ts_oride_def)\n          apply (metis assms(1) less_le_not_le own_ModView valid_fresh_ts_def)\n                    apply blast\n          apply blast\n             apply(intro allI impI)\n           apply clarsimp\n           apply(case_tac \"aa \\<noteq> xa\")\n          \n          using assms(1)  \n            apply simp\n            apply(simp add:  upd_other_pres_last lastWr_def)\n           apply clarsimp\n            apply(case_tac \"b \\<noteq>  Max (tst ` writes_on \\<sigma> xa)\")\n          using assms(1) \n             apply simp\n          apply(subgoal_tac \"(xa, b) \\<in> visible_writes \\<sigma> t xa\")\n              apply (simp add: last_w_not_last_upd)\n              apply(simp add: update_trans_def rev_app_def)\n          apply (simp add:  update_modView_def update_mods_def update_thrView_def update_wa_def Let_def)\n          apply(simp add: visible_writes_def)\n          \n          apply (simp add: lastWr_def)\n\n            apply (simp add: lastWr_def visible_writes_def)\n          apply clarsimp\n          apply (metis wfs_def)\n          using assms(1)\n          apply(unfold wfs_def)\n          apply clarsimp\n          apply(simp add: valid_fresh_ts_def)\n          apply(elim conjE)\n            apply(simp add: lastWr_def)\n            apply (elim conjE)\n            apply clarsimp\n              apply(simp add: update_trans_def rev_app_def)\n          apply (simp add:  update_modView_def update_mods_def update_thrView_def update_wa_def Let_def)\n          apply(intro impI conjI)\n          \n          apply (metis (no_types, lifting) Max.coboundedI finite.insertI finite_imageI insertI1 sup.absorb2 sup.strict_order_iff)\n          using assms(1)\n           by simp      \n\n  \n\n\nlemma [simp]: \"var(lastWr \\<sigma> x) = x\" by(simp add: lastWr_def)\n\nlemma last_write_max: \"wfs \\<sigma> \\<Longrightarrow> w \\<in> writes_on \\<sigma> x \\<Longrightarrow> tst w \\<le> tst (lastWr \\<sigma> x)\"\n  by(simp add: lastWr_def)\n\nlemma last_write_write_on [simp]: \"wfs \\<sigma> \\<Longrightarrow>  lastWr \\<sigma> x \\<in> writes_on \\<sigma> x\"\n  apply(simp add: lastWr_def )\n  apply(case_tac \"Max (tst`(writes_on \\<sigma> x)) \\<in> tst`(writes_on \\<sigma> x)\")\n   defer apply simp\n  using writes_on_var by fastforce\n\nlemma lastWr_visible:\n    \"wfs \\<sigma> \\<Longrightarrow> lastWr \\<sigma> x \\<in> visible_writes \\<sigma> t x\"\n  by (metis (no_types, lifting) CollectI last_write_max last_write_write_on visible_writes_def wfs_def)\n\nlemma lastWr_read_pres: \"lastWr (read_trans t b w \\<sigma>) x = lastWr \\<sigma> x\"\n  by(simp add: lastWr_def)\n\nlemma write_to_different_var [simp]: \"wfs \\<sigma> \\<Longrightarrow> var w \\<noteq> x \\<Longrightarrow> lastWr (write_trans t b w v \\<sigma> ts') x = lastWr \\<sigma> x\"\n  by(simp add: lastWr_def)\n\nlemma [simp]: \"wfs \\<sigma> \\<Longrightarrow> w = (lastWr \\<sigma> x) \\<Longrightarrow> valid_fresh_ts \\<sigma> w ts' \\<Longrightarrow>\n                    lastWr (write_trans t b w v \\<sigma> ts') x = (x, ts')\"\n  apply (simp add: valid_fresh_ts_def)\n  by (simp add: lastWr_def max.strict_order_iff)\n\nlemma [simp]: \"wfs \\<sigma> \\<Longrightarrow> w \\<noteq> lastWr \\<sigma> x \\<Longrightarrow> w \\<in> writes_on \\<sigma> x \\<Longrightarrow> valid_fresh_ts \\<sigma> w ts' \\<Longrightarrow>\n                    lastWr (write_trans t b w v \\<sigma> ts') x = lastWr \\<sigma> x\"\n  apply (subst lastWr_def) apply(case_tac \"var w = x\") apply simp_all defer\n   apply (simp add: lastWr_def)\n apply (simp add: valid_fresh_ts_def)\n  by (metis dual_order.order_iff_strict lastWr_def last_write_max last_write_write_on max.absorb2 prod.exhaust_sel sndI writes_on_var)\n\nlemma [simp]: \" wfs \\<sigma> \\<Longrightarrow> var w \\<noteq> x \\<Longrightarrow> value (write_trans t b w v \\<sigma> ts')(lastWr \\<sigma> x) = value \\<sigma> (lastWr \\<sigma> x)\"\n by(simp add: value_def)\n  \n\nlemma [simp]: \"wfs \\<sigma> \\<Longrightarrow> w = lastWr \\<sigma> x \\<Longrightarrow> valid_fresh_ts \\<sigma> w ts' \\<Longrightarrow>lastWr (update_trans t w v' \\<sigma> ts') x = (x, ts')\"\n  apply (subst lastWr_def) apply simp\n  by (simp add: lastWr_def less_eq_rat_def max.absorb1 valid_fresh_ts_def)\n\nlemma [simp]: \"wfs \\<sigma> \\<Longrightarrow> w \\<noteq> lastWr \\<sigma> x \\<Longrightarrow> w \\<in> writes_on \\<sigma> x \\<Longrightarrow> valid_fresh_ts \\<sigma> w ts' \\<Longrightarrow>\n                    lastWr (update_trans t w v' \\<sigma> ts') x = lastWr \\<sigma> x\"\n  apply (subst lastWr_def) apply(case_tac \"var w = x\") apply simp_all\n  by (metis lastWr_def last_write_max last_write_write_on less_eq_rat_def max_def prod.collapse snd_conv valid_fresh_ts_def writes_on_var)\n\nlemma modView_lte_last: \"wfs \\<sigma> \\<Longrightarrow> tst(modView \\<sigma> w x) \\<le> tst(lastWr \\<sigma> x)\"\n  using last_write_max wfs_def by blast\n\n  \n\ndefinition \"p_obs \\<sigma> t x u \\<equiv> \\<exists> w. w \\<in> visible_writes \\<sigma> t x \\<and> u = value \\<sigma> w\" \n\ndefinition \"d_obs \\<sigma> view x u \\<equiv> view x = lastWr \\<sigma> x \\<and> value \\<sigma> (lastWr \\<sigma> x) = u\"\n\ndefinition \"d_obs_t \\<sigma> t x u \\<equiv> d_obs \\<sigma> (thrView \\<sigma> t) x u\"\n\ndefinition \"c_obs \\<sigma> x u t y v \\<equiv> \n              \\<forall> w \\<in> visible_writes \\<sigma> t x. value \\<sigma> w = u \\<longrightarrow>\n                         d_obs \\<sigma> (modView \\<sigma> w) y v \\<and>\n                         releasing \\<sigma> w\"\n\nabbreviation p_obs_abbr:: \"nat  \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow>  surrey_state \\<Rightarrow> bool\" (\"[_ \\<approx>\\<^sub>_ _] _\" [100, 100, 100, 100])\n  where \"[x \\<approx>\\<^sub>t u] \\<sigma> \\<equiv> p_obs \\<sigma> t x u\"\n\nabbreviation d_obs_abbr:: \"nat  \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"[_ =\\<^sub>_ _] _\" [100, 100, 100, 100])\n  where \"[x =\\<^sub>t u] \\<sigma> \\<equiv> d_obs_t \\<sigma> t x u\"\n\nabbreviation c_obs_abbr:: \"nat \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"[_ = _]\\<lparr>_ =\\<^sub>_ _ \\<rparr> _\" [100, 100, 100, 100, 100, 100])\n  where \"[x = u]\\<lparr>y =\\<^sub>t v\\<rparr> \\<sigma> \\<equiv> c_obs \\<sigma> x u t y v\"\n\n\n\n\n\ndefinition \"covered \\<sigma> x \\<equiv> \\<forall> w .  w \\<in> writes_on \\<sigma> x \\<and> write_available \\<sigma> w \\<longrightarrow> w = lastWr \\<sigma> x\"\n\ndefinition \"covered_v \\<sigma> x v \\<equiv> \\<forall> w .  w \\<in> writes_on \\<sigma> x \\<and> write_available \\<sigma> w \\<longrightarrow> w = lastWr \\<sigma> x \\<and> value \\<sigma> w = v\"\n\nabbreviation covered_v_abbr:: \"L \\<Rightarrow> V  \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"cvd[_, _] _\" [100, 100,100])\n  where \"cvd[x, u] \\<sigma> \\<equiv> covered_v \\<sigma> x u\"\n\n\n\n\ndefinition \"mo w w'\\<equiv> var(w) = var(w') \\<and> tst(w) < tst(w')\" \n\ndefinition \"enc \\<sigma> view x u \\<equiv> \\<exists> w . w \\<in> writes_on \\<sigma> x \\<and> tst(w) \\<le> tst(view x) \\<and> value \\<sigma> w = u\"\n\ndefinition \"enc_t \\<sigma> t x u \\<equiv>  enc \\<sigma> (thrView \\<sigma> t) x u\"\n\ndefinition \"p_vorder \\<sigma> u x v \\<equiv> \\<exists> w w'.  w \\<in> writes_on \\<sigma> x  \\<and>  w' \\<in> writes_on \\<sigma> x \\<and>\n                                        value \\<sigma> w = u \\<and> value \\<sigma> w' = v \\<and>\n                                        mo w w' \"\n\ndefinition \"d_vorder \\<sigma> u x v \\<equiv> (\\<forall> w w'.  w \\<in> writes_on \\<sigma> x  \\<and>  w' \\<in> writes_on \\<sigma> x \\<and>\n                                        value \\<sigma> w = u \\<and> value \\<sigma> w' = v \\<longrightarrow>\n                                        mo w w') \\<and> p_vorder \\<sigma> u x v\"\n\ndefinition \"init_val \\<sigma> x v \\<equiv> \n  \\<exists> w . w \\<in> writes_on \\<sigma> x \\<and> \n        (\\<forall>w'\\<in> writes_on \\<sigma> x .  w \\<noteq> w' \\<longrightarrow>  mo w w') \\<and> \n        value \\<sigma> w = v\"\n\ndefinition \"amo \\<sigma> x u \\<equiv> \\<not> p_vorder \\<sigma> u x u\"\n\ndefinition \"no_val \\<sigma> x i u \\<equiv> init_val \\<sigma> x i \\<and> \\<not> p_vorder \\<sigma> i x u\"\n\ndefinition \"last_val \\<sigma> x u i \\<equiv> \n                init_val \\<sigma> x i \\<and> p_vorder \\<sigma> i x u \n                \\<and> (\\<forall> w. w \\<noteq> u \\<longrightarrow> \\<not> p_vorder \\<sigma> u x w)\"\n\n\n\nabbreviation p_vorder_abbr:: \"V  \\<Rightarrow> L \\<Rightarrow> V \\<Rightarrow>  surrey_state \\<Rightarrow> bool\" (\"[_ \\<leadsto>\\<^sub>_ _] _\" [100,100,100,100])\n  where \"[u \\<leadsto>\\<^sub>x v] \\<sigma> \\<equiv> p_vorder \\<sigma> u x v\"\n\nabbreviation d_vorder_abbr:: \"V  \\<Rightarrow> L \\<Rightarrow> V \\<Rightarrow>  surrey_state \\<Rightarrow> bool\" (\"[_ \\<hookrightarrow>\\<^sub>_ _] _\" [100,100,100,100])\n  where \"[u \\<hookrightarrow>\\<^sub>x v] \\<sigma> \\<equiv> d_vorder \\<sigma> u x v\"\n\nabbreviation amo_abbr:: \"L \\<Rightarrow> V \\<Rightarrow>  surrey_state \\<Rightarrow> bool\" (\"[\\<one>\\<^sub>_ _] _\" [100,100,100])\n  where \"[\\<one>\\<^sub>x u] \\<sigma> \\<equiv> amo \\<sigma> x u\"\n\nabbreviation no_abbr:: \"L \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"[\\<zero>\\<^sub>_ _]\\<^sub>_ _\" [100,100,100,100])\n  where \"[\\<zero>\\<^sub>x u]\\<^sub>i \\<sigma> \\<equiv> no_val \\<sigma> x i u\"\n\nabbreviation enc_abbr:: \"L \\<Rightarrow> V \\<Rightarrow> T \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"[en _ _]\\<^sub>_ _\" [100,100,100,100])\n  where \"[en x u]\\<^sub>t \\<sigma> \\<equiv> enc_t \\<sigma> t x u\"\n\nabbreviation last_abbr:: \"L \\<Rightarrow> V \\<Rightarrow> V \\<Rightarrow> T \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"[last _ _ _]\\<^sub>_ _\" [100, 100,100,100,100])\n  where \"[last x i u]\\<^sub>t \\<sigma> \\<equiv> last_val \\<sigma> x u i\"\n\nabbreviation init_abbr:: \"L \\<Rightarrow> V  \\<Rightarrow> surrey_state \\<Rightarrow> bool\" (\"[init _ _] _\" [100, 100,100])\n  where \"[init x v] \\<sigma> \\<equiv> init_val \\<sigma> x v\"\n\n\nlemma d_obs_lastWr_visible: \n  \"wfs \\<sigma> \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma> \\<Longrightarrow> w \\<in> visible_writes \\<sigma> t x \\<Longrightarrow> w = lastWr \\<sigma> x\"\n  apply (simp add: d_obs_def d_obs_t_def lastWr_def visible_writes_def, auto)\n  by (metis dual_order.antisym lastWr_def last_write_max last_write_write_on prod.collapse writes_on_var)\n\n\n\nlemma d_obs_implies_p_obs: \n  \"wfs \\<sigma> \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma> \\<Longrightarrow> [x \\<approx>\\<^sub>t u] \\<sigma>\"\n  apply(simp add: d_obs_t_def d_obs_def p_obs_def) using lastWr_visible\n  by (metis lastWr_def)\n\n\nlemma d_obs_p_obs_agree: \"wfs \\<sigma> \\<Longrightarrow> [x =\\<^sub>t u] \\<sigma> \\<Longrightarrow> [x \\<approx>\\<^sub>t v] \\<sigma> \\<Longrightarrow> u = v\"\n  apply(unfold p_obs_def d_obs_t_def d_obs_def visible_writes_def)apply clarsimp\n  by (metis eq_snd_iff fst_conv lastWr_def last_write_max leD order.not_eq_order_implies_strict writes_on_var)\n\nlemma not_p_obs_implies_c_obs: \"\\<not> [x \\<approx>\\<^sub>t u] \\<sigma> \\<Longrightarrow> [x = u]\\<lparr>y =\\<^sub>t v\\<rparr> \\<sigma>\"\n  by(auto simp add: p_obs_def c_obs_def)\n\nlemma \"[x =\\<^sub>t n] \\<sigma> \\<Longrightarrow> [x =\\<^sub>t' m] \\<sigma> \\<Longrightarrow> m = n\"\n  by (simp add: d_obs_def d_obs_t_def)\n\n\n\n\nend", "meta": {"author": "MSemenyuk", "repo": "PhD_Isabelle", "sha": "179f5d346a721b15940a271323e3487f4ea51338", "save_path": "github-repos/isabelle/MSemenyuk-PhD_Isabelle", "path": "github-repos/isabelle/MSemenyuk-PhD_Isabelle/PhD_Isabelle-179f5d346a721b15940a271323e3487f4ea51338/Amazon Ring Buffer/OpSem.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926665999540697, "lm_q2_score": 0.4263215925474903, "lm_q1q2_score": 0.25266656874212534}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory signed_div\nimports \"../CTranslation\"\nbegin\n\ninstall_C_file \"signed_div.c\"\n\ncontext signed_div\nbegin\n\nlemma f_result:\n  \"\\<Gamma> \\<turnstile> \\<lbrace> True \\<rbrace> \\<acute>ret__int :== CALL f(5, -1) \\<lbrace> \\<acute>ret__int = -5 \\<rbrace>\"\n  apply vcg\n  apply (clarsimp simp: sdiv_word_def sdiv_int_def)\n  done\n\nlemma f_overflow:\n  shows \"\\<lbrakk> a_' s = of_int (- (2^31)); b_' s = -1 \\<rbrakk> \\<Longrightarrow> \\<Gamma> \\<turnstile> \\<langle> Call f_'proc ,Normal s\\<rangle> \\<Rightarrow> Fault SignedArithmetic\"\n  apply (rule exec.Call [where \\<Gamma>=\\<Gamma>, OF f_impl, simplified f_body_def creturn_def])\n  apply (rule exec.CatchMiss)\n  apply (subst exec.simps, clarsimp simp del: word_neq_0_conv simp: sdiv_word_def sdiv_int_def)+\n  apply simp\n  done\n\nlemma g_result:\n  \"\\<Gamma> \\<turnstile> \\<lbrace> True \\<rbrace> \\<acute>ret__int :== CALL g(-5, 10) \\<lbrace> \\<acute>ret__int = -5 \\<rbrace>\"\n  apply vcg\n  apply (clarsimp simp: smod_word_def smod_int_def sdiv_int_def)\n  done\n\nlemma h_result:\n  \"\\<Gamma> \\<turnstile> \\<lbrace> True \\<rbrace> \\<acute>ret__int :== CALL h(5, -1) \\<lbrace> \\<acute>ret__int = 0 \\<rbrace>\"\n  apply vcg\n  apply (simp add: word_div_def uint_word_ariths)\n  done\n\n(* FIXME: f! *)\nlemma i_result:\n  \"\\<Gamma> \\<turnstile> \\<lbrace> True \\<rbrace> \\<acute>ret__int :== CALL f(5, -1) \\<lbrace> \\<acute>ret__int = -5 \\<rbrace>\"\n  apply vcg\n  apply (clarsimp simp: sdiv_word_def sdiv_int_def)\n  done\n\nend\n\nend\n", "meta": {"author": "8l", "repo": "AutoCorres", "sha": "47d800912e6e0d9b1b8009660e8b20c785a2ea8b", "save_path": "github-repos/isabelle/8l-AutoCorres", "path": "github-repos/isabelle/8l-AutoCorres/AutoCorres-47d800912e6e0d9b1b8009660e8b20c785a2ea8b/c-parser/testfiles/signed_div.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621765008857982, "lm_q2_score": 0.44939263446475963, "lm_q1q2_score": 0.25263797876724914}}
{"text": "(*  Title:      JinjaThreads/BV/BVConform.thy\n    Author:     Cornelia Pusch, Gerwin Klein, Andreas Lochbihler\n\nThe invariant for the type safety proof.\n*)\n\nheader {* \\isaheader{BV Type Safety Invariant} *}\n\ntheory BVConform\nimports\n  BVSpec\n  \"../JVM/JVMExec\"\nbegin\n\ncontext JVM_heap_base begin\n\ndefinition confT :: \"'c prog \\<Rightarrow> 'heap \\<Rightarrow> 'addr val \\<Rightarrow> ty err \\<Rightarrow> bool\" (\"_,_ |- _ :<=T _\" [51,51,51,51] 50)\nwhere\n  \"P,h |- v :<=T E \\<equiv> case E of Err \\<Rightarrow> True | OK T \\<Rightarrow> P,h \\<turnstile> v :\\<le> T\"\n\nnotation (xsymbols) \n  confT (\"_,_ \\<turnstile> _ :\\<le>\\<^sub>\\<top> _\" [51,51,51,51] 50)\n\nabbreviation confTs :: \"'c prog \\<Rightarrow> 'heap \\<Rightarrow> 'addr val list \\<Rightarrow> ty\\<^sub>l \\<Rightarrow> bool\"\n            (\"_,_ |- _ [:<=T] _\" [51,51,51,51] 50)\nwhere\n  \"P,h |- vs [:<=T] Ts \\<equiv> list_all2 (confT P h) vs Ts\"\n\nnotation (xsymbols)\n  confTs (\"_,_ \\<turnstile> _ [:\\<le>\\<^sub>\\<top>] _\" [51,51,51,51] 50)\n\ndefinition conf_f :: \"'addr jvm_prog \\<Rightarrow> 'heap \\<Rightarrow> ty\\<^sub>i \\<Rightarrow> 'addr bytecode \\<Rightarrow> 'addr frame \\<Rightarrow> bool\"\nwhere\n  \"conf_f P h \\<equiv> \\<lambda>(ST,LT) is (stk,loc,C,M,pc). P,h \\<turnstile> stk [:\\<le>] ST \\<and> P,h \\<turnstile> loc [:\\<le>\\<^sub>\\<top>] LT \\<and> pc < size is\"\n\nprimrec conf_fs :: \"['addr jvm_prog,'heap,ty\\<^sub>P,mname,nat,ty,'addr frame list] \\<Rightarrow> bool\"\nwhere\n  \"conf_fs P h \\<Phi> M\\<^sub>0 n\\<^sub>0 T\\<^sub>0 [] = True\"\n\n| \"conf_fs P h \\<Phi> M\\<^sub>0 n\\<^sub>0 T\\<^sub>0 (f#frs) =\n  (let (stk,loc,C,M,pc) = f in\n  (\\<exists>ST LT Ts T mxs mxl\\<^sub>0 is xt.\n    \\<Phi> C M ! pc = Some (ST,LT) \\<and> \n    (P \\<turnstile> C sees M:Ts \\<rightarrow> T = \\<lfloor>(mxs,mxl\\<^sub>0,is,xt)\\<rfloor> in C) \\<and>\n    (\\<exists>Ts' T' D m D'.  \n       is!pc = (Invoke M\\<^sub>0 n\\<^sub>0) \\<and> class_type_of' (ST!n\\<^sub>0) = \\<lfloor>D\\<rfloor> \\<and> P \\<turnstile> D sees M\\<^sub>0:Ts' \\<rightarrow> T' = m in D' \\<and> P \\<turnstile> T\\<^sub>0 \\<le> T') \\<and>\n    conf_f P h (ST, LT) is f \\<and> conf_fs P h \\<Phi> M (size Ts) T frs))\"\n\nprimrec conf_xcp :: \"'addr jvm_prog \\<Rightarrow> 'heap \\<Rightarrow> 'addr option \\<Rightarrow> 'addr instr \\<Rightarrow> bool\" where\n  \"conf_xcp P h None i = True\"\n| \"conf_xcp P h \\<lfloor>a\\<rfloor>   i = (\\<exists>D. typeof_addr h a = \\<lfloor>Class_type D\\<rfloor> \\<and> P \\<turnstile> D \\<preceq>\\<^sup>* Throwable \\<and>\n                               (\\<forall>D'. P \\<turnstile> D \\<preceq>\\<^sup>* D' \\<longrightarrow> is_relevant_class i P D'))\"\n\nend\n\ncontext JVM_heap_conf_base begin\n\ndefinition correct_state :: \"[ty\\<^sub>P,'thread_id,('addr, 'heap) jvm_state] \\<Rightarrow> bool\"\n                  (\"_ |- _:_ [ok]\"  [61,0,0] 61)\nwhere\n  \"correct_state \\<Phi> t \\<equiv> \\<lambda>(xp,h,frs).\n        P,h \\<turnstile> t \\<surd>t \\<and> hconf h \\<and> preallocated h \\<and>\n        (case frs of\n             [] \\<Rightarrow> True\n             | (f#fs) \\<Rightarrow> \n             (let (stk,loc,C,M,pc) = f\n              in \\<exists>Ts T mxs mxl\\<^sub>0 is xt \\<tau>.\n                    (P \\<turnstile> C sees M:Ts\\<rightarrow>T = \\<lfloor>(mxs,mxl\\<^sub>0,is,xt)\\<rfloor> in C) \\<and>\n                    \\<Phi> C M ! pc = Some \\<tau> \\<and>\n                    conf_f P h \\<tau> is f \\<and> conf_fs P h \\<Phi> M (size Ts) T fs \\<and>\n                    conf_xcp P h xp (is ! pc) ))\"\n\nnotation (xsymbols)\n correct_state (\"_ \\<turnstile> _:_ \\<surd>\"  [61,0,0] 61)\n\nend\n\ncontext JVM_heap_base begin\n\nlemma conf_f_def2:\n  \"conf_f P h (ST,LT) is (stk,loc,C,M,pc) \\<equiv>\n  P,h \\<turnstile> stk [:\\<le>] ST \\<and> P,h \\<turnstile> loc [:\\<le>\\<^sub>\\<top>] LT \\<and> pc < size is\"\n  by (simp add: conf_f_def)\n\nsection {* Values and @{text \"\\<top>\"} *}\n\nlemma confT_Err [iff]: \"P,h \\<turnstile> x :\\<le>\\<^sub>\\<top> Err\" \n  by (simp add: confT_def)\n\nlemma confT_OK [iff]:  \"P,h \\<turnstile> x :\\<le>\\<^sub>\\<top> OK T = (P,h \\<turnstile> x :\\<le> T)\"\n  by (simp add: confT_def)\n\nlemma confT_cases:\n  \"P,h \\<turnstile> x :\\<le>\\<^sub>\\<top> X = (X = Err \\<or> (\\<exists>T. X = OK T \\<and> P,h \\<turnstile> x :\\<le> T))\"\n  by (cases X) auto\n\nlemma confT_widen [intro?, trans]:\n  \"\\<lbrakk> P,h \\<turnstile> x :\\<le>\\<^sub>\\<top> T; P \\<turnstile> T \\<le>\\<^sub>\\<top> T' \\<rbrakk> \\<Longrightarrow> P,h \\<turnstile> x :\\<le>\\<^sub>\\<top> T'\"\n  by (cases T', auto intro: conf_widen)\n\nend\n\ncontext JVM_heap begin\n\nlemma confT_hext [intro?, trans]:\n  \"\\<lbrakk> P,h \\<turnstile> x :\\<le>\\<^sub>\\<top> T; h \\<unlhd> h' \\<rbrakk> \\<Longrightarrow> P,h' \\<turnstile> x :\\<le>\\<^sub>\\<top> T\"\n  by (cases T) (blast intro: conf_hext)+\n\nend\n\nsection {* Stack and Registers *}\n\ncontext JVM_heap_base begin\n\nlemma confTs_Cons1 [iff]:\n  \"P,h \\<turnstile> x # xs [:\\<le>\\<^sub>\\<top>] Ts = (\\<exists>z zs. Ts = z # zs \\<and> P,h \\<turnstile> x :\\<le>\\<^sub>\\<top> z \\<and> list_all2 (confT P h) xs zs)\"\nby(rule list_all2_Cons1)\n\nlemma confTs_confT_sup:\n  \"\\<lbrakk> P,h \\<turnstile> loc [:\\<le>\\<^sub>\\<top>] LT; n < size LT; LT!n = OK T; P \\<turnstile> T \\<le> T' \\<rbrakk> \n  \\<Longrightarrow> P,h \\<turnstile> (loc!n) :\\<le> T'\"\n  apply (frule list_all2_lengthD)\n  apply (drule list_all2_nthD, simp)\n  apply simp\n  apply (erule conf_widen, assumption+)\n  done\n\nlemma confTs_widen [intro?, trans]:\n  \"P,h \\<turnstile> loc [:\\<le>\\<^sub>\\<top>] LT \\<Longrightarrow> P \\<turnstile> LT [\\<le>\\<^sub>\\<top>] LT' \\<Longrightarrow> P,h \\<turnstile> loc [:\\<le>\\<^sub>\\<top>] LT'\"\n  by (rule list_all2_trans, rule confT_widen)\n\nlemma confTs_map [iff]:\n  \"(P,h \\<turnstile> vs [:\\<le>\\<^sub>\\<top>] map OK Ts) = (P,h \\<turnstile> vs [:\\<le>] Ts)\"\n  by (induct Ts arbitrary: vs) (auto simp add: list_all2_Cons2)\n\nlemma reg_widen_Err [iff]:\n  \"(P \\<turnstile> replicate n Err [\\<le>\\<^sub>\\<top>] LT) = (LT = replicate n Err)\"\n  by (induct n arbitrary: LT) (auto simp add: list_all2_Cons1)\n    \n\n\nend\n\ncontext JVM_heap begin\n\nlemma confTs_hext [intro?]:\n  \"P,h \\<turnstile> loc [:\\<le>\\<^sub>\\<top>] LT \\<Longrightarrow> h \\<unlhd> h' \\<Longrightarrow> P,h' \\<turnstile> loc [:\\<le>\\<^sub>\\<top>] LT\"\n  by (fast elim: list_all2_mono confT_hext)    \n  \nsection {* correct-frames *}\n\ndeclare fun_upd_apply[simp del]\n\nlemma conf_f_hext:\n  \"\\<lbrakk> conf_f P h \\<Phi> M f; h \\<unlhd> h' \\<rbrakk> \\<Longrightarrow> conf_f P h' \\<Phi> M f\"\nby(cases f, cases \\<Phi>, auto simp add: conf_f_def intro: confs_hext confTs_hext)\n\nlemma conf_fs_hext:\n  \"\\<lbrakk> conf_fs P h \\<Phi> M n T\\<^sub>r frs; h \\<unlhd> h' \\<rbrakk> \\<Longrightarrow> conf_fs P h' \\<Phi> M n T\\<^sub>r frs\"\napply (induct frs arbitrary: M n T\\<^sub>r)\n apply simp\napply clarify\napply (simp (no_asm_use))\napply clarify\napply (unfold conf_f_def)\napply (simp (no_asm_use) split: split_if_asm)\napply (fast elim!: confs_hext confTs_hext)+\ndone\n\ndeclare fun_upd_apply[simp]\n\nlemma conf_xcp_hext:\n  \"\\<lbrakk> conf_xcp P h xcp i; h \\<unlhd> h' \\<rbrakk> \\<Longrightarrow> conf_xcp P h' xcp i\"\nby(cases xcp)(auto elim: typeof_addr_hext_mono)\n\nend\n\ncontext JVM_heap_conf_base begin\n\nlemmas defs1 = correct_state_def conf_f_def wt_instr_def eff_def norm_eff_def app_def xcpt_app_def\n\nlemma correct_state_impl_Some_method:\n  \"\\<Phi> \\<turnstile> t: (None, h, (stk,loc,C,M,pc)#frs)\\<surd> \n  \\<Longrightarrow> \\<exists>m Ts T. P \\<turnstile> C sees M:Ts\\<rightarrow>T = \\<lfloor>m\\<rfloor> in C\"\n  by(fastforce simp add: defs1)\n\nend\n\ncontext JVM_heap_conf_base' begin\n\n\n\nend\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/JinjaThreads/BV/BVConform.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621764862150634, "lm_q2_score": 0.4493926344647596, "lm_q1q2_score": 0.252637972174329}}
{"text": "theory Proto_Sepref_Borrow\nimports Sepref\nbegin\n\n  (* Simple-Minded borrowing for sepref.\n  \n    Idea: When we can prove that we have not changed an object abstractly, \n      and its concrete value is still the same, we can reinstantiate it \n      after it has been invalidated.\n      \n  *)\n\n  text \\<open>Operation to reinstantiate dst, by moving source. \n    Implementations will also require a proof that the concrete objects are equal!\n  \\<close>\n  definition \"unborrow src dst \\<equiv> doN {ASSERT (src=dst); RETURN ()}\"\n  sepref_register unborrow\n\n  lemma unborrow_correct[refine_vcg]: \"s=d \\<Longrightarrow> unborrow s d \\<le> SPEC (\\<lambda>r. r=()) (\\<lambda>_. 0)\"\n    unfolding unborrow_def SPEC_def ASSERT_def iASSERT_def apply simp by (auto simp: RETURNT_def)\n  \n  lemma unborrow_rule[sepref_comb_rules]:\n    assumes FRAME: \"\\<Gamma> \\<turnstile> hn_ctxt R src srci ** hn_invalid R dst dsti ** F\"\n    assumes [simp]: \"vassn_tag \\<Gamma> \\<Longrightarrow> srci = dsti\"\n    shows \"hn_refine \\<Gamma> (return ()::unit llM) (hn_invalid R src srci ** hn_ctxt R dst dsti ** F) unit_assn (unborrow$src$dst)\"\n    apply (rule hn_refine_vassn_tagI)\n    apply (rule hn_refine_cons_pre[OF _ FRAME])\n    unfolding unborrow_def apply (simp only: APP_def)\n    apply (rule hn_refineI'')\n    apply (simp add: refine_pw_simps)\n    unfolding hn_ctxt_def invalid_assn_def pure_def\n    by vcg'\n  \n  lemma unborrow_nofail[refine_pw_simps]: \"nofailT (unborrow a b) \\<longleftrightarrow> a=b\" by (auto simp: unborrow_def refine_pw_simps)  \n  \n  \n  text \\<open>Assertion that adds constraint on concrete value. Used to carry through concrete equalities.\\<close>\n  definition \"cnc_assn \\<phi> A a c \\<equiv> \\<up>(\\<phi> c) ** A a c\"\n    \n  lemma norm_ceq_assn[named_ss sepref_frame_normrel]: \"hn_ctxt (cnc_assn \\<phi> A) a c = (\\<up>(\\<phi> c) ** hn_ctxt A a c)\"\n    unfolding hn_ctxt_def cnc_assn_def by simp\n  \n  lemma cnc_assn_prod_conv[named_ss sepref_frame_normrel]:\n    shows \"\\<And>A B \\<phi>. A \\<times>\\<^sub>a cnc_assn \\<phi> B = cnc_assn (\\<phi> o snd) (A\\<times>\\<^sub>aB)\"\n      and \"\\<And>A B \\<phi>. cnc_assn \\<phi> A \\<times>\\<^sub>a B = cnc_assn (\\<phi> o fst) (A\\<times>\\<^sub>aB)\"\n    unfolding cnc_assn_def\n    by (auto simp: sep_algebra_simps fun_eq_iff)\n    \n  (* BEWARE: This only only holds without time, would need to have\n     to add (infinite?) time credits to premise HT  \n\n  text \\<open>Rule to prove a-posteriori constraint (Only useful for simple programs.\n    TODO: More partial Hoare-triples would make this more useful, e.g., \n      we could assume assertions, preconditions, and even termination!\n  )\\<close>    \n  lemma hnr_ceq_assnI:\n    assumes HNR: \"hn_refine \\<Gamma> c \\<Gamma>' R a\"\n    assumes HT: \"llvm_htriple \\<Gamma> c (\\<lambda>x'. \\<up>(\\<phi> x') ** sep_true)\"\n    shows \"hn_refine \\<Gamma> c \\<Gamma>' (cnc_assn \\<phi> R) a\"\n  proof (rule hn_refine_nofailI)\n    assume NF: \"nofailT a\"\n  \n    show ?thesis\n      apply (rule hn_refineI)\n      apply (rule cons_post_rule)\n      apply (rule htriple_conj_pure[OF HNR[THEN hn_refineD[OF _ NF]] HT])\n      apply (auto simp: sep_algebra_simps pred_lift_extract_simps cnc_assn_def)\n      done\n      \n  qed    \n  *)\n\nend\n", "meta": {"author": "lammich", "repo": "isabelle_llvm_time", "sha": "42dd7f59998d76047bb4b6bce76d8f67b53a08b6", "save_path": "github-repos/isabelle/lammich-isabelle_llvm_time", "path": "github-repos/isabelle/lammich-isabelle_llvm_time/isabelle_llvm_time-42dd7f59998d76047bb4b6bce76d8f67b53a08b6/thys/sepref/Proto_Sepref_Borrow.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5813031051514762, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.2522747730686923}}
{"text": "theory IICF_Misc\nimports \"../Sepref\"\nbegin\n\n\n\n\n\ncontext\n  fixes t ::  \"nat\"\nbegin\n  definition \"mop_plus a b =SPECT [a +  b \\<mapsto> t]\"\n\n  lemma mop_plus: \"\\<And>tt. tt \\<le> lst (SPECT [ a +  b \\<mapsto> t]) Q \\<Longrightarrow> tt\n           \\<le> lst (mop_plus a b) Q\" unfolding mop_plus_def by simp \n \n  sepref_register \"mop_plus\" \n  print_theorems \nend \n \n\n \n \nlemma hn_refine_plus[sepref_fr_rules]: \" hn_refine (hn_val Id a' a * hn_val Id b' b)\n           (ureturn (a +  b))\n       (hn_val Id a' a * hn_val Id b' b)\n       (pure Id) (((PR_CONST (mop_plus t)) $ a' $ b'))\"\n  unfolding hn_refine_def apply (auto simp:   mult.assoc  execute_ureturn pure_def hn_ctxt_def)\n  by (auto simp: top_assn_rule zero_enat_def relH_def  mop_plus_def elim: pureD ) \n \ncontext\n  fixes t ::  \"nat\"\nbegin\n  definition \"mop_min a b =SPECT [min a b \\<mapsto> t]\"\n\n  lemma mop_min: \"\\<And>tt. tt \\<le> lst (SPECT [ min a b \\<mapsto> t]) Q \\<Longrightarrow> tt\n           \\<le> lst (mop_min a b) Q\" unfolding mop_min_def by simp \n \n  sepref_register \"mop_min\" \n  print_theorems \nend \n \n\n \n \nlemma hn_refine_min[sepref_fr_rules]: \" hn_refine (hn_val Id a' a * hn_val Id b' b)\n           (ureturn (min a b))\n       (hn_val Id a' a * hn_val Id b' b)\n       (pure Id) (((PR_CONST (mop_min t)) $ a' $ b'))\"\n  unfolding hn_refine_def apply (auto simp:   mult.assoc  execute_ureturn pure_def hn_ctxt_def)\n  by (auto simp: top_assn_rule zero_enat_def relH_def  mop_min_def elim: pureD ) \n \n           \ncontext\n  fixes t ::  \"nat\"\nbegin\n  definition \"mop_swap e =SPECT [prod.swap e \\<mapsto> t]\"\n\n  lemma mop_swap: \"\\<And>tt. tt \\<le> lst (SPECT [ prod.swap e \\<mapsto> t]) Q \\<Longrightarrow> tt\n           \\<le> lst (mop_swap e) Q\" unfolding mop_swap_def by simp \n \n  sepref_register \"mop_swap\" \n  print_theorems \nend \n \n\n \n \nlemma hn_refine_swap[sepref_fr_rules]: \" hn_refine (hn_ctxt (nat_assn \\<times>\\<^sub>a nat_assn) e' e)\n           (ureturn (prod.swap e))\n       (hn_ctxt (nat_assn \\<times>\\<^sub>a nat_assn) e' e)\n       (nat_assn \\<times>\\<^sub>a nat_assn) (((PR_CONST (mop_swap t)) $ e'))\"\n  unfolding hn_refine_def apply (auto simp:      execute_ureturn    )\n   apply (auto simp: top_assn_rule zero_enat_def relH_def prod.swap_def mop_swap_def elim: pureD ) \n  apply(rule exI[where x=0]) apply auto  \n  by (smt BNF_Greatest_Fixpoint.IdD IdI entails_def entails_true hn_ctxt_def mult.left_neutral pure_assn_rule pure_def pure_true)  \n  \n\nend", "meta": {"author": "maxhaslbeck", "repo": "Sepreftime", "sha": "c1c987b45ec886d289ba215768182ac87b82f20d", "save_path": "github-repos/isabelle/maxhaslbeck-Sepreftime", "path": "github-repos/isabelle/maxhaslbeck-Sepreftime/Sepreftime-c1c987b45ec886d289ba215768182ac87b82f20d/Refine_Imperative_HOL/IICF/IICF_Misc.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5813031051514762, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.2522747730686923}}
{"text": "(*  Title:      JinjaThreads/Framework/FWLifting.thy\n    Author:     Andreas Lochbihler\n*)\n\nsection \\<open>Lifting of thread-local properties to the multithreaded case\\<close>\n\ntheory FWLifting\nimports\n  FWWellform\nbegin\n\ntext\\<open>Lifting for properties that only involve thread-local state information and the shared memory.\\<close>\n\ndefinition\n  ts_ok :: \"('t \\<Rightarrow> 'x \\<Rightarrow> 'm \\<Rightarrow> bool) \\<Rightarrow> ('l, 't,'x) thread_info \\<Rightarrow> 'm \\<Rightarrow> bool\"\nwhere\n  \"\\<And>ln. ts_ok P ts m \\<equiv> \\<forall>t. case (ts t) of None \\<Rightarrow> True | \\<lfloor>(x, ln)\\<rfloor> \\<Rightarrow> P t x m\"\n\nlemma ts_okI:\n  \"\\<lbrakk> \\<And>t x ln. ts t = \\<lfloor>(x, ln)\\<rfloor> \\<Longrightarrow> P t x m \\<rbrakk> \\<Longrightarrow> ts_ok P ts m\"\nby(auto simp add: ts_ok_def)\n\nlemma ts_okE:\n  \"\\<lbrakk> ts_ok P ts m; \\<lbrakk> \\<And>t x ln. ts t = \\<lfloor>(x, ln)\\<rfloor> \\<Longrightarrow> P t x m \\<rbrakk> \\<Longrightarrow> Q \\<rbrakk> \\<Longrightarrow> Q\"\nby(auto simp add: ts_ok_def)\n\nlemma ts_okD:\n  \"\\<And>ln. \\<lbrakk> ts_ok P ts m; ts t = \\<lfloor>(x, ln)\\<rfloor> \\<rbrakk> \\<Longrightarrow> P t x m\"\nby(auto simp add: ts_ok_def)\n\nlemma ts_ok_True [simp]:\n  \"ts_ok (\\<lambda>t m x. True) ts m\"\nby(auto intro: ts_okI)\n\nlemma ts_ok_conj:\n  \"ts_ok (\\<lambda>t x m. P t x m \\<and> Q t x m) = (\\<lambda>ts m. ts_ok P ts m \\<and> ts_ok Q ts m)\"\nby(auto intro: ts_okI intro!: ext dest: ts_okD)\n\nlemma ts_ok_mono:\n  \"\\<lbrakk> ts_ok P ts m; \\<And>t x. P t x m \\<Longrightarrow> Q t x m \\<rbrakk> \\<Longrightarrow> ts_ok Q ts m\"\nby(auto intro!: ts_okI dest: ts_okD)\n\ntext\\<open>Lifting for properites, that also require additional data that does not change during execution\\<close>\n\ndefinition\n  ts_inv :: \"('i \\<Rightarrow> 't \\<Rightarrow> 'x \\<Rightarrow> 'm \\<Rightarrow> bool) \\<Rightarrow> ('t \\<rightharpoonup> 'i) \\<Rightarrow> ('l,'t,'x) thread_info \\<Rightarrow> 'm \\<Rightarrow> bool\"\nwhere\n  \"\\<And>ln. ts_inv P I ts m \\<equiv> \\<forall>t. case (ts t) of None \\<Rightarrow> True | \\<lfloor>(x, ln)\\<rfloor> \\<Rightarrow> \\<exists>i. I t = \\<lfloor>i\\<rfloor> \\<and> P i t x m\" \n\nlemma ts_invI:\n  \"\\<lbrakk> \\<And>t x ln. ts t = \\<lfloor>(x, ln)\\<rfloor> \\<Longrightarrow> \\<exists>i. I t = \\<lfloor>i\\<rfloor> \\<and> P i t x m \\<rbrakk> \\<Longrightarrow> ts_inv P I ts m\"\nby(simp add: ts_inv_def)\n\nlemma ts_invE:\n  \"\\<lbrakk> ts_inv P I ts m; \\<forall>t x ln. ts t = \\<lfloor>(x, ln)\\<rfloor> \\<longrightarrow> (\\<exists>i. I t = \\<lfloor>i\\<rfloor> \\<and> P i t x m) \\<Longrightarrow> R \\<rbrakk> \\<Longrightarrow> R\"\nby(auto simp add: ts_inv_def)\n\nlemma ts_invD:\n  \"\\<And>ln. \\<lbrakk> ts_inv P I ts m; ts t = \\<lfloor>(x, ln)\\<rfloor> \\<rbrakk> \\<Longrightarrow> \\<exists>i. I t = \\<lfloor>i\\<rfloor> \\<and> P i t x m\"\nby(auto simp add: ts_inv_def)\n\ntext \\<open>Wellformedness properties for lifting\\<close>\n\ndefinition\n  ts_inv_ok :: \"('l,'t,'x) thread_info \\<Rightarrow> ('t \\<rightharpoonup> 'i) \\<Rightarrow> bool\"\nwhere\n  \"ts_inv_ok ts I \\<equiv> \\<forall>t. ts t = None \\<longleftrightarrow> I t = None\"\n\nlemma ts_inv_okI:\n  \"(\\<And>t. ts t = None \\<longleftrightarrow> I t = None) \\<Longrightarrow> ts_inv_ok ts I\"\nby(clarsimp simp add: ts_inv_ok_def)\n\nlemma ts_inv_okI2:\n  \"(\\<And>t. (\\<exists>v. ts t = \\<lfloor>v\\<rfloor>) \\<longleftrightarrow> (\\<exists>v. I t = \\<lfloor>v\\<rfloor>)) \\<Longrightarrow> ts_inv_ok ts I\"\nby(force simp add: ts_inv_ok_def)\n\nlemma ts_inv_okE:\n  \"\\<lbrakk> ts_inv_ok ts I; \\<forall>t. ts t = None \\<longleftrightarrow> I t = None \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P\"\nby(force simp add: ts_inv_ok_def)\n\nlemma ts_inv_okE2:\n  \"\\<lbrakk> ts_inv_ok ts I; \\<forall>t. (\\<exists>v. ts t = \\<lfloor>v\\<rfloor>) \\<longleftrightarrow> (\\<exists>v. I t = \\<lfloor>v\\<rfloor>) \\<Longrightarrow> P \\<rbrakk> \\<Longrightarrow> P\"\nby(force simp add: ts_inv_ok_def)\n\nlemma ts_inv_okD:\n  \"ts_inv_ok ts I \\<Longrightarrow> (ts t = None) \\<longleftrightarrow> (I t = None)\"\nby(erule ts_inv_okE, blast)\n\nlemma ts_inv_okD2:\n  \"ts_inv_ok ts I \\<Longrightarrow> (\\<exists>v. ts t = \\<lfloor>v\\<rfloor>) \\<longleftrightarrow> (\\<exists>v. I t = \\<lfloor>v\\<rfloor>)\"\nby(erule ts_inv_okE2, blast)\n\nlemma ts_inv_ok_conv_dom_eq:\n  \"ts_inv_ok ts I \\<longleftrightarrow> (dom ts = dom I)\"\nproof -\n  have \"ts_inv_ok ts I \\<longleftrightarrow> (\\<forall>t. ts t = None \\<longleftrightarrow> I t = None)\"\n    unfolding ts_inv_ok_def by blast\n  also have \"\\<dots> \\<longleftrightarrow> (\\<forall>t. t \\<in> - dom ts \\<longleftrightarrow> t \\<in> - dom I)\" by(force)\n  also have \"\\<dots> \\<longleftrightarrow> dom ts = dom I\" by auto\n  finally show ?thesis .\nqed\n\nlemma ts_inv_ok_upd_ts:\n  \"\\<lbrakk> ts t = \\<lfloor>x\\<rfloor>; ts_inv_ok ts I \\<rbrakk> \\<Longrightarrow> ts_inv_ok (ts(t \\<mapsto> x')) I\"\nby(auto dest!: ts_inv_okD intro!: ts_inv_okI split: if_splits)\n\nlemma ts_inv_upd_map_option:\n  assumes \"ts_inv P I ts m\"\n  and \"\\<And>x ln. ts t = \\<lfloor>(x, ln)\\<rfloor> \\<Longrightarrow> P (the (I t)) t (fst (f (x, ln))) m\"\n  shows \"ts_inv P I (ts(t := (map_option f (ts t)))) m\"\nusing assms\nby(fastforce intro!: ts_invI split: if_split_asm dest: ts_invD)\n\nfun upd_inv :: \"('t \\<rightharpoonup> 'i) \\<Rightarrow> ('i \\<Rightarrow> 't \\<Rightarrow> 'x \\<Rightarrow> 'm \\<Rightarrow> bool) \\<Rightarrow> ('t,'x,'m) new_thread_action \\<Rightarrow> ('t \\<rightharpoonup> 'i)\"\nwhere\n  \"upd_inv I P (NewThread t x m) = I(t \\<mapsto> SOME i. P i t x m)\"\n| \"upd_inv I P _ = I\"\n\nfun upd_invs :: \"('t \\<rightharpoonup> 'i) \\<Rightarrow> ('i \\<Rightarrow> 't \\<Rightarrow> 'x \\<Rightarrow> 'm \\<Rightarrow> bool) \\<Rightarrow> ('t,'x,'m) new_thread_action list \\<Rightarrow> ('t \\<rightharpoonup> 'i)\"\nwhere\n  \"upd_invs I P [] = I\"\n| \"upd_invs I P (ta#tas) = upd_invs (upd_inv I P ta) P tas\"\n\nlemma upd_invs_append [simp]:\n  \"upd_invs I P (xs @ ys) = upd_invs (upd_invs I P xs) P ys\"\nby(induct xs arbitrary: I)(auto)\n\nlemma ts_inv_ok_upd_inv':\n \"ts_inv_ok ts I \\<Longrightarrow> ts_inv_ok (redT_updT' ts ta) (upd_inv I P ta)\"\nby(cases ta)(auto intro!: ts_inv_okI elim: ts_inv_okD del: iffI)\n\nlemma ts_inv_ok_upd_invs':\n  \"ts_inv_ok ts I \\<Longrightarrow> ts_inv_ok (redT_updTs' ts tas) (upd_invs I P tas)\"\nproof(induct tas arbitrary: ts I)\n  case Nil thus ?case by simp\nnext\n  case (Cons TA TAS TS I)\n  note IH = \\<open>\\<And>ts I. ts_inv_ok ts I \\<Longrightarrow> ts_inv_ok (redT_updTs' ts TAS) (upd_invs I P TAS)\\<close>\n  note esok = \\<open>ts_inv_ok TS I\\<close>\n  from esok have \"ts_inv_ok (redT_updT' TS TA) (upd_inv I P TA)\"\n    by -(rule ts_inv_ok_upd_inv')\n  hence \"ts_inv_ok (redT_updTs' (redT_updT' TS TA) TAS) (upd_invs (upd_inv I P TA) P TAS)\"\n    by (rule IH)\n  thus ?case by simp\nqed\n\nlemma ts_inv_ok_upd_inv:\n \"ts_inv_ok ts I \\<Longrightarrow> ts_inv_ok (redT_updT ts ta) (upd_inv I P ta)\"\napply(cases ta)\napply(auto intro!: ts_inv_okI elim: ts_inv_okD del: iffI)\ndone\n\nlemma ts_inv_ok_upd_invs:\n  \"ts_inv_ok ts I \\<Longrightarrow> ts_inv_ok (redT_updTs ts tas) (upd_invs I P tas)\"\nproof(induct tas arbitrary: ts I)\n  case Nil thus ?case by simp\nnext\n  case (Cons TA TAS TS I)\n  note IH = \\<open>\\<And>ts I. ts_inv_ok ts I \\<Longrightarrow> ts_inv_ok (redT_updTs ts TAS) (upd_invs I P TAS)\\<close>\n  note esok = \\<open>ts_inv_ok TS I\\<close>\n  from esok have \"ts_inv_ok (redT_updT TS TA) (upd_inv I P TA)\"\n    by -(rule ts_inv_ok_upd_inv)\n  hence \"ts_inv_ok (redT_updTs (redT_updT TS TA) TAS) (upd_invs (upd_inv I P TA) P TAS)\"\n    by (rule IH)\n  thus ?case by simp\nqed\n\nlemma ts_inv_ok_inv_ext_upd_inv:\n  \"\\<lbrakk> ts_inv_ok ts I; thread_ok ts ta \\<rbrakk> \\<Longrightarrow> I \\<subseteq>\\<^sub>m upd_inv I P ta\"\nby(cases ta)(auto intro!: map_le_same_upd dest: ts_inv_okD)\n\nlemma ts_inv_ok_inv_ext_upd_invs:\n  \"\\<lbrakk> ts_inv_ok ts I; thread_oks ts tas\\<rbrakk>\n  \\<Longrightarrow> I \\<subseteq>\\<^sub>m upd_invs I P tas\"\nproof(induct tas arbitrary: ts I)\n  case Nil thus ?case by simp\nnext\n  case (Cons TA TAS TS I)\n  note IH = \\<open>\\<And>ts I. \\<lbrakk> ts_inv_ok ts I; thread_oks ts TAS\\<rbrakk> \\<Longrightarrow> I \\<subseteq>\\<^sub>m upd_invs I P TAS\\<close>\n  note esinv = \\<open>ts_inv_ok TS I\\<close>\n  note cct = \\<open>thread_oks TS (TA # TAS)\\<close>\n  from esinv cct have \"I \\<subseteq>\\<^sub>m upd_inv I P TA\"\n    by(auto intro: ts_inv_ok_inv_ext_upd_inv)\n  also from esinv cct have \"ts_inv_ok (redT_updT' TS TA) (upd_inv I P TA)\"\n    by(auto intro: ts_inv_ok_upd_inv')\n  with cct have \"upd_inv I P TA \\<subseteq>\\<^sub>m upd_invs (upd_inv I P TA) P TAS\"\n    by(auto intro: IH)\n  finally show ?case by simp\nqed\n\nlemma upd_invs_Some:\n  \"\\<lbrakk> thread_oks ts tas; I t = \\<lfloor>i\\<rfloor>; ts t = \\<lfloor>x\\<rfloor> \\<rbrakk> \\<Longrightarrow> upd_invs I Q tas t = \\<lfloor>i\\<rfloor>\"\nproof(induct tas arbitrary: ts I)\n  case Nil thus ?case by simp\nnext\n  case (Cons TA TAS TS I)\n  note IH = \\<open>\\<And>ts I. \\<lbrakk>thread_oks ts TAS; I t = \\<lfloor>i\\<rfloor>; ts t = \\<lfloor>x\\<rfloor>\\<rbrakk> \\<Longrightarrow> upd_invs I Q TAS t = \\<lfloor>i\\<rfloor>\\<close>\n  note cct = \\<open>thread_oks TS (TA # TAS)\\<close>\n  note it = \\<open>I t = \\<lfloor>i\\<rfloor>\\<close>\n  note est = \\<open>TS t = \\<lfloor>x\\<rfloor>\\<close>\n  from cct have cctta: \"thread_ok TS TA\"\n    and ccttas: \"thread_oks (redT_updT' TS TA) TAS\" by auto\n  from cctta it est have \"upd_inv I Q TA t = \\<lfloor>i\\<rfloor>\"\n    by(cases TA, auto)\n  moreover\n  have \"redT_updT' TS TA t = \\<lfloor>x\\<rfloor>\" using cctta est\n    by - (rule redT_updT'_Some) \n  ultimately have \"upd_invs (upd_inv I Q TA) Q TAS t = \\<lfloor>i\\<rfloor>\" using ccttas\n    by -(erule IH)\n  thus ?case by simp\nqed\n\nlemma upd_inv_Some_eq:\n  \"\\<lbrakk> thread_ok ts ta; ts t = \\<lfloor>x\\<rfloor> \\<rbrakk> \\<Longrightarrow> upd_inv I Q ta t = I t\"\nby(cases ta, auto)\n\nlemma upd_invs_Some_eq: \"\\<lbrakk> thread_oks ts tas; ts t = \\<lfloor>x\\<rfloor> \\<rbrakk> \\<Longrightarrow> upd_invs I Q tas t = I t\"\nproof(induct tas arbitrary: ts I)\n  case Nil thus ?case by simp\nnext\n  case (Cons TA TAS TS I)\n  note IH = \\<open>\\<And>ts I. \\<lbrakk>thread_oks ts TAS; ts t = \\<lfloor>x\\<rfloor>\\<rbrakk> \\<Longrightarrow> upd_invs I Q TAS t = I t\\<close>\n  note cct = \\<open>thread_oks TS (TA # TAS)\\<close>\n  note est = \\<open>TS t = \\<lfloor>x\\<rfloor>\\<close>\n  from cct est have \"upd_invs (upd_inv I Q TA) Q TAS t = upd_inv I Q TA t\"\n    apply(clarsimp)\n    apply(erule IH)\n    by(rule redT_updT'_Some)\n  also from cct est have \"\\<dots> = I t\" \n    by(auto elim: upd_inv_Some_eq)\n  finally show ?case by simp\nqed\n\nlemma SOME_new_thread_upd_invs:\n  assumes Qsome: \"Q (SOME i. Q i t x m) t x m\"\n  and nt: \"NewThread t x m \\<in> set tas\"\n  and cct: \"thread_oks ts tas\"\n  shows \"\\<exists>i. upd_invs I Q tas t = \\<lfloor>i\\<rfloor> \\<and> Q i t x m\"\nproof(rule exI[where x=\"SOME i. Q i t x m\"])\n  from nt cct have \"upd_invs I Q tas t = \\<lfloor>SOME i. Q i t x m\\<rfloor>\"\n  proof(induct tas arbitrary: ts I)\n    case Nil thus ?case by simp\n  next\n    case (Cons TA TAS TS I)\n    note IH = \\<open>\\<And>ts I. \\<lbrakk> NewThread t x m \\<in> set TAS; thread_oks ts TAS \\<rbrakk> \\<Longrightarrow> upd_invs I Q TAS t = \\<lfloor>SOME i. Q i t x m\\<rfloor>\\<close>\n    note nt = \\<open>NewThread t x m \\<in> set (TA # TAS)\\<close>\n    note cct = \\<open>thread_oks TS (TA # TAS)\\<close>\n    { assume nt': \"NewThread t x m \\<in> set TAS\"\n      from cct have ?case\n        apply(clarsimp)\n        by(rule IH[OF nt']) }\n    moreover\n    { assume ta: \"TA = NewThread t x m\"\n      with cct have rup: \"redT_updT' TS TA t = \\<lfloor>(undefined, no_wait_locks)\\<rfloor>\"\n        by(simp)\n      from cct have cctta: \"thread_oks (redT_updT' TS TA) TAS\" by simp\n      from ta have \"upd_inv I Q TA t = \\<lfloor>SOME i. Q i t x m\\<rfloor>\"\n        by(simp)\n      hence ?case \n        by(clarsimp simp add: upd_invs_Some_eq[OF cctta, OF rup]) }\n    ultimately show ?case using nt by auto\n  qed\n  with Qsome show \"upd_invs I Q tas t = \\<lfloor>SOME i. Q i t x m\\<rfloor> \\<and> Q (SOME i. Q i t x m) t x m\"\n    by(simp)\nqed\n\nlemma ts_ok_into_ts_inv_const:\n  assumes \"ts_ok P ts m\"\n  obtains I where \"ts_inv (\\<lambda>_. P) I ts m\"\nproof -\n  from assms have \"ts_inv (\\<lambda>_. P) (\\<lambda>t. if t \\<in> dom ts then Some undefined else None) ts m\"\n    by(auto intro!: ts_invI dest: ts_okD)\n  thus thesis by(rule that)\nqed\n\nlemma ts_inv_const_into_ts_ok:\n  \"ts_inv (\\<lambda>_. P) I ts m \\<Longrightarrow> ts_ok P ts m\"\nby(auto intro!: ts_okI dest: ts_invD)\n\nlemma ts_inv_into_ts_ok_Ex:\n  \"ts_inv Q I ts m \\<Longrightarrow> ts_ok (\\<lambda>t x m. \\<exists>i. Q i t x m) ts m\"\nby(rule ts_okI)(blast dest: ts_invD)\n\nlemma ts_ok_Ex_into_ts_inv:\n  \"ts_ok (\\<lambda>t x m. \\<exists>i. Q i t x m) ts m \\<Longrightarrow> \\<exists>I. ts_inv Q I ts m\"\nby(rule exI[where x=\"\\<lambda>t. \\<lfloor>SOME i. Q i t (fst (the (ts t))) m\\<rfloor>\"])(auto 4 4 dest: ts_okD intro: someI intro: ts_invI)\n\nlemma Ex_ts_inv_conv_ts_ok:\n  \"(\\<exists>I. ts_inv Q I ts m) \\<longleftrightarrow> (ts_ok (\\<lambda>t x m. \\<exists>i. Q i t x m) ts m)\"\nby(auto dest: ts_inv_into_ts_ok_Ex ts_ok_Ex_into_ts_inv)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/JinjaThreads/Framework/FWLifting.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185351961015, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.2521779748096991}}
{"text": "\\<^marker>\\<open>creator Alexander Taepper\\<close>\n\ntheory IMP_Minus_To_IMP_Minus_Minus_IMP\n  imports\n    Primitives_IMP_Minus\n    Binary_Arithmetic_IMP\n    IMP_Minus_To_IMP_Minus_Minus_State_Translations_IMP\n    IMP_Minus_To_IMP_Minus_Minus_nat\n    IMP_Minus.Com\nbegin\n\n\nunbundle IMP_Minus_Minus_Com.no_com_syntax\n\n\nsubsection \\<open>Useful Definitions and Lemmas\\<close>\n\n\nsubsection \\<open>map_var_bit_to_var\\<close>\n\nsubsubsection \\<open>map_var_bit_to_var_aux\\<close>\n\nfun map_var_bit_to_var_aux :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> nat\" where \n\"map_var_bit_to_var_aux acc v n = ((var_bit_to_var_nat (prod_encode (v,hd_nat n)))## acc)\"\n\nrecord map_var_bit_to_var_aux_state =\n  map_var_bit_to_var_aux_acc::nat\n  map_var_bit_to_var_aux_v::nat\n  map_var_bit_to_var_aux_n::nat\n  map_var_bit_to_var_aux_ret::nat\n\nabbreviation \"map_var_bit_to_var_aux_prefix \\<equiv> ''map_var_bit_to_var_aux.''\"\nabbreviation \"map_var_bit_to_var_aux_acc_str \\<equiv> ''acc''\"\nabbreviation \"map_var_bit_to_var_aux_v_str \\<equiv> ''v''\"\nabbreviation \"map_var_bit_to_var_aux_n_str \\<equiv> ''n''\"\nabbreviation \"map_var_bit_to_var_aux_ret_str \\<equiv> ''ret''\"\n\n\nfunction map_var_bit_to_var_aux_imp :: \"map_var_bit_to_var_aux_state \\<Rightarrow> map_var_bit_to_var_aux_state\" where \n\"map_var_bit_to_var_aux_imp s = \n(let\n    hd_xs' = map_var_bit_to_var_aux_n s;\n    hd_ret' = 0;\n    hd_state = \\<lparr>hd_xs = hd_xs',\n                hd_ret = hd_ret'\\<rparr>;\n    hd_ret_state = hd_imp hd_state;\n\n    prod_encode_a' = map_var_bit_to_var_aux_v s;\n    prod_encode_b' = hd_ret hd_ret_state;\n    prod_encode_ret' = 0;\n    prod_encode_state = \\<lparr>prod_encode_a = prod_encode_a',\n                         prod_encode_b = prod_encode_b',\n                         prod_encode_ret = prod_encode_ret'\\<rparr>;\n    prod_encode_ret_state = prod_encode_imp prod_encode_state;\n\n    var_bit_to_var_nat_n' = prod_encode_ret prod_encode_ret_state;\n    var_bit_to_var_nat_ret' = 0;\n    var_bit_to_var_nat_state = \\<lparr>var_bit_to_var_nat_n = var_bit_to_var_nat_n',\n                                var_bit_to_var_nat_ret = var_bit_to_var_nat_ret'\\<rparr>;\n    var_bit_to_var_nat_ret_state = var_bit_to_var_nat_imp var_bit_to_var_nat_state;\n\n    cons_h' = var_bit_to_var_nat_ret var_bit_to_var_nat_ret_state;\n    cons_t' = map_var_bit_to_var_aux_acc s;\n    cons_ret' = 0;\n    cons_state = \\<lparr>cons_h = cons_h',\n                  cons_t = cons_t', \n                  cons_ret = cons_ret'\\<rparr>;\n    cons_ret_state = cons_imp cons_state;\n    map_var_bit_to_var_aux_ret' = cons_ret cons_ret_state;\n    \n    tl_xs' = map_var_bit_to_var_aux_n s;\n    tl_ret' = 0;\n    tl_state = \\<lparr>tl_xs = tl_xs', \n                tl_ret = tl_ret'\\<rparr>;\n    tl_ret_state = tl_imp tl_state;\n\n    map_var_bit_to_var_aux_n' = tl_ret tl_ret_state;\n    ret = \\<lparr>map_var_bit_to_var_aux_acc = map_var_bit_to_var_aux_acc s,\n          map_var_bit_to_var_aux_v = map_var_bit_to_var_aux_v s,\n          map_var_bit_to_var_aux_n = map_var_bit_to_var_aux_n',\n          map_var_bit_to_var_aux_ret = map_var_bit_to_var_aux_ret'\\<rparr>\n    in\n     ret)\n    \" by simp+\n    termination\n    apply (relation \"measure map_var_bit_to_var_aux_acc\")\n    apply simp \n    done \n\ndeclare map_var_bit_to_var_aux_imp.simps[simp del]\n\nlemma map_var_bit_to_var_aux_imp_correct[let_function_correctness]:\n\"map_var_bit_to_var_aux_ret (map_var_bit_to_var_aux_imp s) = \n  map_var_bit_to_var_aux (map_var_bit_to_var_aux_acc s) (map_var_bit_to_var_aux_v s) (map_var_bit_to_var_aux_n s)\n  \\<and> map_var_bit_to_var_aux_n (map_var_bit_to_var_aux_imp s) = tl_nat (map_var_bit_to_var_aux_n s)\"\napply (subst map_var_bit_to_var_aux_imp.simps)+\napply (auto simp add: hd_imp_correct prod_encode_imp_correct var_bit_to_var_nat_imp_correct cons_imp_correct\n  tl_imp_correct)\ndone \n\nfunction map_var_bit_to_var_aux_imp_time :: \"nat \\<Rightarrow> map_var_bit_to_var_aux_state \\<Rightarrow> nat\" where \n\"map_var_bit_to_var_aux_imp_time t s = \n(let\n    hd_xs' = map_var_bit_to_var_aux_n s;\n    t = t + 2;\n    hd_ret' = 0;\n    t = t + 2;\n    hd_state = \\<lparr>hd_xs = hd_xs',\n                hd_ret = hd_ret'\\<rparr>;\n    hd_ret_state = hd_imp hd_state;\n    t = t + hd_imp_time 0 hd_state;\n\n    prod_encode_a' = map_var_bit_to_var_aux_v s;\n    t = t + 2;\n    prod_encode_b' = hd_ret hd_ret_state;\n    t = t + 2;\n    prod_encode_ret' = 0;\n    t = t + 2;\n    prod_encode_state = \\<lparr>prod_encode_a = prod_encode_a',\n                         prod_encode_b = prod_encode_b',\n                         prod_encode_ret = prod_encode_ret'\\<rparr>;\n    prod_encode_ret_state = prod_encode_imp prod_encode_state;\n    t = t + prod_encode_imp_time 0 prod_encode_state;\n\n    var_bit_to_var_nat_n' = prod_encode_ret prod_encode_ret_state;\n    t = t + 2;\n    var_bit_to_var_nat_ret' = 0;\n    t = t + 2;\n    var_bit_to_var_nat_state = \\<lparr>var_bit_to_var_nat_n = var_bit_to_var_nat_n',\n                                var_bit_to_var_nat_ret = var_bit_to_var_nat_ret'\\<rparr>;\n    var_bit_to_var_nat_ret_state = var_bit_to_var_nat_imp var_bit_to_var_nat_state;\n    t = t + var_bit_to_var_nat_imp_time 0 var_bit_to_var_nat_state;\n\n    cons_h' = var_bit_to_var_nat_ret var_bit_to_var_nat_ret_state;\n    t = t + 2;\n    cons_t' = map_var_bit_to_var_aux_acc s;\n    t = t + 2;\n    cons_ret' = 0;\n    t = t + 2;\n    cons_state = \\<lparr>cons_h = cons_h',\n                  cons_t = cons_t', \n                  cons_ret = cons_ret'\\<rparr>;\n    cons_ret_state = cons_imp cons_state;\n    t = t + cons_imp_time 0 cons_state;\n    map_var_bit_to_var_aux_ret' = cons_ret cons_ret_state;\n    t = t + 2;\n\n    tl_xs' = map_var_bit_to_var_aux_n s;\n    t = t + 2;\n    tl_ret' = 0;\n    t = t + 2;\n    tl_state = \\<lparr>tl_xs = tl_xs', \n                tl_ret = tl_ret'\\<rparr>;\n    tl_ret_state = tl_imp tl_state;\n    t = t + tl_imp_time 0 tl_state;\n\n    map_var_bit_to_var_aux_n' = tl_ret tl_ret_state;\n    t = t + 2;\n    ret = \\<lparr>map_var_bit_to_var_aux_acc = map_var_bit_to_var_aux_acc s,\n          map_var_bit_to_var_aux_v = map_var_bit_to_var_aux_v s,\n          map_var_bit_to_var_aux_n = map_var_bit_to_var_aux_n',\n          map_var_bit_to_var_aux_ret = map_var_bit_to_var_aux_ret'\\<rparr>\n    in\n     t)\n    \" by auto\n    termination\n    apply (relation \"measure (map_var_bit_to_var_aux_acc \\<circ> snd)\")\n    apply simp \n    done \n\ndeclare map_var_bit_to_var_aux_imp_time.simps[simp del]\n\ndefinition  \"map_var_bit_to_var_aux_IMP_Minus \\<equiv> \n  (hd_prefix @ hd_xs_str) ::= (A (V map_var_bit_to_var_aux_n_str));;\n  (hd_prefix @ hd_ret_str) ::= (A (N 0));;\n  invoke_subprogram hd_prefix hd_IMP_Minus;;\n\n  (prod_encode_prefix @ prod_encode_a_str) ::= (A (V map_var_bit_to_var_aux_v_str));;\n  (prod_encode_prefix @ prod_encode_b_str) ::= (A (V (hd_prefix @ hd_ret_str)));;\n  (prod_encode_prefix @ prod_encode_ret_str) ::= (A (N 0));;\n  invoke_subprogram prod_encode_prefix prod_encode_IMP_Minus;;\n\n  (var_bit_to_var_nat_prefix @ var_bit_to_var_nat_n_str) ::= (A (V (prod_encode_prefix @ prod_encode_ret_str)));;\n  (var_bit_to_var_nat_prefix @ var_bit_to_var_nat_ret_str) ::= (A (N 0));;\n  invoke_subprogram var_bit_to_var_nat_prefix var_bit_to_var_nat_IMP_Minus;;\n\n  (cons_prefix @ cons_h_str) ::= (A (V (var_bit_to_var_nat_prefix @ var_bit_to_var_nat_ret_str)));;\n  (cons_prefix @ cons_t_str) ::= (A (V map_var_bit_to_var_aux_acc_str));;\n  (cons_prefix @ cons_ret_str) ::= (A (N 0));;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n  map_var_bit_to_var_aux_ret_str ::= (A (V (cons_prefix @ cons_ret_str)));;\n\n  (tl_prefix @ tl_xs_str) ::= (A (V map_var_bit_to_var_aux_n_str));;\n  (tl_prefix @ tl_ret_str) ::= (A (N 0));;\n  invoke_subprogram tl_prefix tl_IMP_Minus;;\n\n  map_var_bit_to_var_aux_n_str ::= (A (V (tl_prefix @ tl_ret_str)))\n\"\n\ndefinition \"map_var_bit_to_var_aux_imp_to_HOL_state p s =\n  \\<lparr>map_var_bit_to_var_aux_acc = (s (add_prefix p map_var_bit_to_var_aux_acc_str)),\n  map_var_bit_to_var_aux_v = (s (add_prefix p map_var_bit_to_var_aux_v_str)),\n  map_var_bit_to_var_aux_n = (s (add_prefix p map_var_bit_to_var_aux_n_str)),\n  map_var_bit_to_var_aux_ret = (s (add_prefix p map_var_bit_to_var_aux_ret_str))\\<rparr>\"\n\nlemmas map_var_bit_to_var_aux_state_translators =\n  map_var_bit_to_var_aux_imp_to_HOL_state_def\n  hd_imp_to_HOL_state_def\n  prod_encode_imp_to_HOL_state_def\n  var_bit_to_var_nat_imp_to_HOL_state_def\n  cons_imp_to_HOL_state_def\n  tl_imp_to_HOL_state_def\n\nabbreviation \"map_var_bit_to_var_aux_IMP_vars \\<equiv> {\n  map_var_bit_to_var_aux_acc_str, map_var_bit_to_var_aux_v_str, \n  map_var_bit_to_var_aux_n_str, map_var_bit_to_var_aux_ret_str}\"\n\nlemma map_var_bit_to_var_aux_IMP_Minus_correct_function_ret:\n  \"(invoke_subprogram p map_var_bit_to_var_aux_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p map_var_bit_to_var_aux_ret_str)\n      = map_var_bit_to_var_aux_ret\n          (map_var_bit_to_var_aux_imp (map_var_bit_to_var_aux_imp_to_HOL_state p s))\"\napply (simp only: map_var_bit_to_var_aux_IMP_Minus_def prefix_simps)\napply (erule Seq_E)+\napply (erule  hd_IMP_Minus_correct[where vars=map_var_bit_to_var_aux_IMP_vars])\nsubgoal premises p using p(19) by fastforce\napply (erule  prod_encode_IMP_Minus_correct[where vars=map_var_bit_to_var_aux_IMP_vars])\nsubgoal premises p using p(21) by fastforce\napply (erule  var_bit_to_var_nat_IMP_Minus_correct[where vars=map_var_bit_to_var_aux_IMP_vars])\nsubgoal premises p using p(23) by fastforce\napply (erule  cons_IMP_Minus_correct[where vars=map_var_bit_to_var_aux_IMP_vars])\nsubgoal premises p using p(25) by fastforce\napply (erule  tl_IMP_Minus_correct[where vars=\"map_var_bit_to_var_aux_IMP_vars\"])\nsubgoal premises p using p(27) by fastforce\napply (clarsimp simp add:\n  map_var_bit_to_var_aux_state_translators Let_def map_var_bit_to_var_aux_imp.simps)\nsubgoal premises p\n  using p(10) p(8) p(6) p(4) p(2) by force \ndone \n\nlemma map_var_bit_to_var_aux_IMP_Minus_correct_function_n:\n  \"(invoke_subprogram p map_var_bit_to_var_aux_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p map_var_bit_to_var_aux_n_str)\n      = map_var_bit_to_var_aux_n\n          (map_var_bit_to_var_aux_imp (map_var_bit_to_var_aux_imp_to_HOL_state p s))\"\napply (simp only: map_var_bit_to_var_aux_IMP_Minus_def prefix_simps)\napply (erule Seq_E)+\napply (erule  hd_IMP_Minus_correct[where vars=map_var_bit_to_var_aux_IMP_vars])\nsubgoal premises p using p(19) by fastforce\napply (erule  prod_encode_IMP_Minus_correct[where vars=map_var_bit_to_var_aux_IMP_vars])\nsubgoal premises p using p(21) by fastforce\napply (erule  var_bit_to_var_nat_IMP_Minus_correct[where vars=map_var_bit_to_var_aux_IMP_vars])\nsubgoal premises p using p(23) by fastforce\napply (erule  cons_IMP_Minus_correct[where vars=map_var_bit_to_var_aux_IMP_vars])\nsubgoal premises p using p(25) by fastforce\napply (erule  tl_IMP_Minus_correct[where vars=\"map_var_bit_to_var_aux_IMP_vars\"])\nsubgoal premises p using p(27) by fastforce\napply (clarsimp simp add:\n  map_var_bit_to_var_aux_state_translators Let_def map_var_bit_to_var_aux_imp.simps)\nsubgoal premises p\n  using p(10) p(8) p(6) p(4) p(2) by force \ndone \n\nlemma map_var_bit_to_var_aux_IMP_Minus_correct_effects:\n  \"\\<lbrakk>(invoke_subprogram (p @ map_var_bit_to_var_aux_pref) map_var_bit_to_var_aux_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    v \\<in> vars; \\<not> (prefix map_var_bit_to_var_aux_pref v)\\<rbrakk>\n   \\<Longrightarrow> s (add_prefix p v) = s' (add_prefix p v)\"\n  using com_add_prefix_valid'' com_only_vars prefix_def\n  by blast            \n\n\nlemma map_var_bit_to_var_aux_IMP_Minus_correct_time:\n  \"(invoke_subprogram p map_var_bit_to_var_aux_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = map_var_bit_to_var_aux_imp_time 0 (map_var_bit_to_var_aux_imp_to_HOL_state p s)\"\napply (simp only: map_var_bit_to_var_aux_IMP_Minus_def prefix_simps)\napply (erule Seq_tE)+\napply (erule hd_IMP_Minus_correct[where vars=map_var_bit_to_var_aux_IMP_vars])\nsubgoal premises p using p(37) by fastforce\napply (erule prod_encode_IMP_Minus_correct[where vars=map_var_bit_to_var_aux_IMP_vars])\nsubgoal premises p using p(39) by fastforce\napply (erule var_bit_to_var_nat_IMP_Minus_correct[where vars=map_var_bit_to_var_aux_IMP_vars])\nsubgoal premises p using p(41) by fastforce\napply (erule cons_IMP_Minus_correct[where vars=map_var_bit_to_var_aux_IMP_vars])\nsubgoal premises p using p(43) by fastforce\napply (erule tl_IMP_Minus_correct[where vars=map_var_bit_to_var_aux_IMP_vars])\nsubgoal premises p using p(45) by fastforce\napply (force simp: map_var_bit_to_var_aux_imp_time.simps \n  Let_def map_var_bit_to_var_aux_state_translators)\ndone \n\nlemma map_var_bit_to_var_aux_IMP_Minus_correct[functional_correctness]:\n  \"\\<lbrakk>(invoke_subprogram (p1 @ p2) map_var_bit_to_var_aux_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    \\<And>v. v \\<in> vars \\<Longrightarrow> \\<not> (set p2 \\<subseteq> set v);\n    \\<lbrakk>t = (map_var_bit_to_var_aux_imp_time 0 (map_var_bit_to_var_aux_imp_to_HOL_state (p1 @ p2) s));\n     s' (add_prefix (p1 @ p2) map_var_bit_to_var_aux_ret_str) =\n          map_var_bit_to_var_aux_ret (map_var_bit_to_var_aux_imp\n                                        (map_var_bit_to_var_aux_imp_to_HOL_state (p1 @ p2) s));\n     s' (add_prefix (p1 @ p2) map_var_bit_to_var_aux_n_str) =\n          map_var_bit_to_var_aux_n (map_var_bit_to_var_aux_imp\n                                        (map_var_bit_to_var_aux_imp_to_HOL_state (p1 @ p2) s));\n     \\<And>v. v \\<in> vars \\<Longrightarrow> s (add_prefix p1 v) = s' (add_prefix p1 v)\\<rbrakk>\n   \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  using map_var_bit_to_var_aux_IMP_Minus_correct_function_ret \n  map_var_bit_to_var_aux_IMP_Minus_correct_function_n\n  by (auto simp: map_var_bit_to_var_aux_IMP_Minus_correct_time)\n    (meson map_var_bit_to_var_aux_IMP_Minus_correct_effects set_mono_prefix) \n\nsubsubsection \\<open>map_var_bit_to_var_acc\\<close>\n\nfun map_var_bit_to_var_acc' :: \"nat \\<Rightarrow> nat \\<Rightarrow> nat \\<Rightarrow> nat\" where \n\"map_var_bit_to_var_acc' acc v n = (if n \\<noteq> 0 \n   then (map_var_bit_to_var_acc' ((var_bit_to_var_nat (prod_encode (v,hd_nat n)))## acc) v (tl_nat n))\n   else acc)\"\n\nlemma map_var_bit_to_var_acc'_imp_correct:\n\"map_var_bit_to_var_acc' acc v n = map_var_bit_to_var_acc acc v n\"\nproof (induction n arbitrary: acc v rule: less_induct)\n  case (less x)\n  then show ?case\n  proof(cases x)\n    case (Suc nat)\n    have \"tl_nat x < x\" using Suc\n      by simp\n    then show ?thesis\n      using less by force\n  qed (simp)\nqed\n\nrecord map_var_bit_to_var_acc_state =\n  map_var_bit_to_var_acc_acc::nat\n  map_var_bit_to_var_acc_v::nat\n  map_var_bit_to_var_acc_n::nat\n  map_var_bit_to_var_acc_ret::nat\n\nabbreviation \"map_var_bit_to_var_acc_prefix \\<equiv> ''map_var_bit_to_var_acc.''\"\nabbreviation \"map_var_bit_to_var_acc_acc_str \\<equiv> ''acc''\"\nabbreviation \"map_var_bit_to_var_acc_v_str \\<equiv> ''v''\"\nabbreviation \"map_var_bit_to_var_acc_n_str \\<equiv> ''n''\"\nabbreviation \"map_var_bit_to_var_acc_ret_str \\<equiv> ''ret''\"\n\ndefinition \"map_var_bit_to_var_acc_state_upd s \\<equiv>\n  let\n    map_var_bit_to_var_aux_acc' = map_var_bit_to_var_acc_acc s;\n    map_var_bit_to_var_aux_v' = map_var_bit_to_var_acc_v s;\n    map_var_bit_to_var_aux_n' = map_var_bit_to_var_acc_n s;\n    map_var_bit_to_var_aux_ret' = 0;\n    map_var_bit_to_var_aux_state = \n      \\<lparr>map_var_bit_to_var_aux_acc = map_var_bit_to_var_aux_acc',\n      map_var_bit_to_var_aux_v = map_var_bit_to_var_aux_v',\n      map_var_bit_to_var_aux_n = map_var_bit_to_var_aux_n',\n      map_var_bit_to_var_aux_ret = map_var_bit_to_var_aux_ret'\\<rparr>;\n    map_var_bit_to_var_aux_ret_state = \n        map_var_bit_to_var_aux_imp map_var_bit_to_var_aux_state;\n\n\n    map_var_bit_to_var_acc_acc' = map_var_bit_to_var_aux_ret map_var_bit_to_var_aux_ret_state;\n    map_var_bit_to_var_acc_n' = map_var_bit_to_var_aux_n map_var_bit_to_var_aux_ret_state;\n    ret = \\<lparr>map_var_bit_to_var_acc_acc = map_var_bit_to_var_acc_acc',\n           map_var_bit_to_var_acc_v = map_var_bit_to_var_acc_v s,\n           map_var_bit_to_var_acc_n = map_var_bit_to_var_acc_n',\n           map_var_bit_to_var_acc_ret = map_var_bit_to_var_acc_ret s\\<rparr>\n    in ret\n\"\n\ndefinition \"map_var_bit_to_var_acc_imp_compute_loop_condition s \\<equiv>\n  (let\n    condition = map_var_bit_to_var_acc_n s\n   in condition\n  )\n\"\n\ndefinition \"map_var_bit_to_var_acc_imp_after_loop s \\<equiv>\n  (let\n    map_var_bit_to_var_acc_ret' = map_var_bit_to_var_acc_acc s;\n    ret = \\<lparr>map_var_bit_to_var_acc_acc = map_var_bit_to_var_acc_acc s,\n           map_var_bit_to_var_acc_v = map_var_bit_to_var_acc_v s,\n           map_var_bit_to_var_acc_n = map_var_bit_to_var_acc_n s,\n           map_var_bit_to_var_acc_ret = map_var_bit_to_var_acc_ret'\\<rparr>\n   in ret\n  )\"\n\nlemmas map_var_bit_to_var_acc_imp_subprogram_simps = \n  map_var_bit_to_var_acc_state_upd_def\n  map_var_bit_to_var_acc_imp_compute_loop_condition_def\n  map_var_bit_to_var_acc_imp_after_loop_def\n\nfunction map_var_bit_to_var_acc_imp::\n  \"map_var_bit_to_var_acc_state \\<Rightarrow> map_var_bit_to_var_acc_state\" where\n  \"map_var_bit_to_var_acc_imp s =\n  (if map_var_bit_to_var_acc_imp_compute_loop_condition s \\<noteq> 0\n   then\n    let next_iteration = map_var_bit_to_var_acc_imp (map_var_bit_to_var_acc_state_upd s)\n    in next_iteration\n   else\n    let ret = map_var_bit_to_var_acc_imp_after_loop s\n    in ret\n  )\"\n  by simp+\ntermination \n  apply (relation \"measure map_var_bit_to_var_acc_n\")\n   apply (simp add: map_var_bit_to_var_acc_imp_subprogram_simps \n      map_var_bit_to_var_aux_imp_correct Let_def)+\n  done\n\ndeclare map_var_bit_to_var_acc_imp.simps [simp del]\n\nlemma map_var_bit_to_var_acc_imp_correct[let_function_correctness]:\n  \"map_var_bit_to_var_acc_ret (map_var_bit_to_var_acc_imp s) =\n    map_var_bit_to_var_acc' (map_var_bit_to_var_acc_acc s) \n  (map_var_bit_to_var_acc_v s) (map_var_bit_to_var_acc_n s)\"\n  apply (induction s rule: map_var_bit_to_var_acc_imp.induct)\n  apply (subst map_var_bit_to_var_acc_imp.simps)\n  apply (subst map_var_bit_to_var_acc'.simps)\n  apply (simp del: map_var_bit_to_var_acc'.simps \n              add: map_var_bit_to_var_acc_imp_subprogram_simps Let_def \n                   fst_nat_fst'_nat snd_nat_snd'_nat snd'_imp_correct fst'_imp_correct\n                   map_var_bit_to_var_aux_imp_correct tl_imp_correct)\n  done            \n\ndefinition \"map_var_bit_to_var_acc_state_upd_time t s \\<equiv>\n  let\n    map_var_bit_to_var_aux_acc' = map_var_bit_to_var_acc_acc s;\n    t = t + 2;\n    map_var_bit_to_var_aux_v' = map_var_bit_to_var_acc_v s;\n    t = t + 2;\n    map_var_bit_to_var_aux_n' = map_var_bit_to_var_acc_n s;\n    t = t + 2;\n    map_var_bit_to_var_aux_ret' = 0;\n    t = t + 2;\n    map_var_bit_to_var_aux_state = \n      \\<lparr>map_var_bit_to_var_aux_acc = map_var_bit_to_var_aux_acc',\n      map_var_bit_to_var_aux_v = map_var_bit_to_var_aux_v',\n      map_var_bit_to_var_aux_n = map_var_bit_to_var_aux_n',\n      map_var_bit_to_var_aux_ret = map_var_bit_to_var_aux_ret'\\<rparr>;\n    map_var_bit_to_var_aux_ret_state = \n        map_var_bit_to_var_aux_imp map_var_bit_to_var_aux_state;\n    t = t + map_var_bit_to_var_aux_imp_time 0 map_var_bit_to_var_aux_state;\n\n    map_var_bit_to_var_acc_acc' = map_var_bit_to_var_aux_ret map_var_bit_to_var_aux_ret_state;\n    t = t + 2;\n    map_var_bit_to_var_acc_n' = map_var_bit_to_var_aux_n map_var_bit_to_var_aux_ret_state;\n    t = t + 2;\n    ret = \\<lparr>map_var_bit_to_var_acc_acc = map_var_bit_to_var_acc_acc',\n           map_var_bit_to_var_acc_v = map_var_bit_to_var_acc_v s,\n           map_var_bit_to_var_acc_n = map_var_bit_to_var_acc_n',\n           map_var_bit_to_var_acc_ret = map_var_bit_to_var_acc_ret s\\<rparr>\n  in\n    t\n\"\n\ndefinition \"map_var_bit_to_var_acc_imp_compute_loop_condition_time t s \\<equiv>\n  let\n    condition = map_var_bit_to_var_acc_n s;\n    t = t + 2\n  in\n    t\n\"\n\ndefinition \"map_var_bit_to_var_acc_imp_after_loop_time t s \\<equiv>\n  let\n    map_var_bit_to_var_acc_ret' = map_var_bit_to_var_acc_acc s;\n    t = t + 2;\n    ret = \\<lparr>map_var_bit_to_var_acc_acc = map_var_bit_to_var_acc_acc s,\n           map_var_bit_to_var_acc_v = map_var_bit_to_var_acc_v s,\n           map_var_bit_to_var_acc_n = map_var_bit_to_var_acc_n s,\n           map_var_bit_to_var_acc_ret = map_var_bit_to_var_acc_ret'\\<rparr>\n  in\n    t\n\"\n\nlemmas map_var_bit_to_var_acc_imp_subprogram_time_simps = \n  map_var_bit_to_var_acc_state_upd_time_def\n  map_var_bit_to_var_acc_imp_compute_loop_condition_time_def\n  map_var_bit_to_var_acc_imp_after_loop_time_def\n  map_var_bit_to_var_acc_imp_subprogram_simps\n\nfunction map_var_bit_to_var_acc_imp_time::\n  \"nat \\<Rightarrow> map_var_bit_to_var_acc_state \\<Rightarrow> nat\" where\n  \"map_var_bit_to_var_acc_imp_time t s =\n  map_var_bit_to_var_acc_imp_compute_loop_condition_time 0 s +\n  (if map_var_bit_to_var_acc_imp_compute_loop_condition s \\<noteq> 0\n    then\n      (let\n        t = t + 1;\n        next_iteration =\n          map_var_bit_to_var_acc_imp_time (t + map_var_bit_to_var_acc_state_upd_time 0 s)\n                         (map_var_bit_to_var_acc_state_upd s)\n       in next_iteration)\n    else\n      (let\n        t = t + 2;\n        ret = t + map_var_bit_to_var_acc_imp_after_loop_time 0 s\n       in ret)\n  )\"\n  by auto\ntermination\n  apply (relation \"measure (map_var_bit_to_var_acc_n \\<circ> snd)\")\n  by (auto simp add: map_var_bit_to_var_acc_imp_subprogram_time_simps\n        map_var_bit_to_var_aux_imp_correct Let_def)\n\ndeclare map_var_bit_to_var_acc_imp_time.simps [simp del]            \n\nlemma map_var_bit_to_var_acc_imp_time_acc:\n  \"(map_var_bit_to_var_acc_imp_time (Suc t) s) = Suc (map_var_bit_to_var_acc_imp_time t s)\"\n  by (induction t s rule: map_var_bit_to_var_acc_imp_time.induct)\n    ((subst (1 2) map_var_bit_to_var_acc_imp_time.simps);\n      (simp add: map_var_bit_to_var_acc_state_upd_def))            \n\nlemma map_var_bit_to_var_acc_imp_time_acc_2_aux:\n  \"(map_var_bit_to_var_acc_imp_time t s) = t + (map_var_bit_to_var_acc_imp_time 0 s)\"\n  by (induction t arbitrary: s) (simp add: map_var_bit_to_var_acc_imp_time_acc)+            \n\nlemma map_var_bit_to_var_acc_imp_time_acc_2:\n  \"t \\<noteq> 0 \\<Longrightarrow> (map_var_bit_to_var_acc_imp_time t s) = t + (map_var_bit_to_var_acc_imp_time 0 s)\"\n  by (rule map_var_bit_to_var_acc_imp_time_acc_2_aux)            \n\nlemma map_var_bit_to_var_acc_imp_time_acc_3:\n  \"(map_var_bit_to_var_acc_imp_time (a + b) s) = a + (map_var_bit_to_var_acc_imp_time b s)\"\n  by (induction a arbitrary: b s) (simp add: map_var_bit_to_var_acc_imp_time_acc)+            \n\nabbreviation \"map_var_bit_to_var_acc_while_cond \\<equiv> ''condition''\"\n\ndefinition \"map_var_bit_to_var_acc_IMP_init_while_cond \\<equiv>\n  \\<comment> \\<open>condition = map_var_bit_to_var_acc_n s\\<close>\n  map_var_bit_to_var_acc_while_cond ::= A (V map_var_bit_to_var_acc_n_str)\n\"\n\ndefinition \"map_var_bit_to_var_acc_IMP_loop_body \\<equiv>\n (map_var_bit_to_var_aux_prefix @ map_var_bit_to_var_aux_acc_str)\n   ::= A (V map_var_bit_to_var_acc_acc_str);;\n (map_var_bit_to_var_aux_prefix @ map_var_bit_to_var_aux_v_str)\n   ::= A (V map_var_bit_to_var_acc_v_str);;\n (map_var_bit_to_var_aux_prefix @ map_var_bit_to_var_aux_n_str)\n   ::= A (V map_var_bit_to_var_acc_n_str);;\n (map_var_bit_to_var_aux_prefix @ map_var_bit_to_var_aux_ret_str)\n   ::= A (N 0);;\n invoke_subprogram map_var_bit_to_var_aux_prefix map_var_bit_to_var_aux_IMP_Minus;;\n  \n  (map_var_bit_to_var_acc_acc_str) ::= (A (V (map_var_bit_to_var_aux_prefix \n                                             @ map_var_bit_to_var_aux_ret_str)));;\n  (map_var_bit_to_var_acc_n_str) ::=  (A (V (map_var_bit_to_var_aux_prefix \n                                             @ map_var_bit_to_var_aux_n_str)))\n\"\n\ndefinition \"map_var_bit_to_var_acc_IMP_after_loop \\<equiv>\n  (map_var_bit_to_var_acc_ret_str) ::= (A (V map_var_bit_to_var_acc_acc_str))\n  \\<comment> \\<open>ret = \\<lparr>map_var_bit_to_var_acc_acc = map_var_bit_to_var_acc_acc',\\<close>\n  \\<comment> \\<open>       map_var_bit_to_var_acc_v = map_var_bit_to_var_acc_v',\\<close>\n  \\<comment> \\<open>       map_var_bit_to_var_acc_n = map_var_bit_to_var_acc_n',\\<close>\n  \\<comment> \\<open>       map_var_bit_to_var_acc_ret = map_var_bit_to_var_acc_ret'\\<rparr>\\<close>\n\"\n\ndefinition map_var_bit_to_var_acc_IMP_Minus where\n  \"map_var_bit_to_var_acc_IMP_Minus \\<equiv>\n  map_var_bit_to_var_acc_IMP_init_while_cond;;\n  WHILE map_var_bit_to_var_acc_while_cond \\<noteq>0 DO (\n    map_var_bit_to_var_acc_IMP_loop_body;;\n    map_var_bit_to_var_acc_IMP_init_while_cond\n  );;\n  map_var_bit_to_var_acc_IMP_after_loop\"\n\nabbreviation \"map_var_bit_to_var_acc_IMP_vars\\<equiv>\n  {map_var_bit_to_var_acc_while_cond,\n    map_var_bit_to_var_acc_acc_str, map_var_bit_to_var_acc_v_str,\n  map_var_bit_to_var_acc_n_str,  map_var_bit_to_var_acc_ret_str}\"\n\nlemmas map_var_bit_to_var_acc_IMP_subprogram_simps =\n  map_var_bit_to_var_acc_IMP_init_while_cond_def\n  map_var_bit_to_var_acc_IMP_loop_body_def\n  map_var_bit_to_var_acc_IMP_after_loop_def\n\ndefinition \"map_var_bit_to_var_acc_imp_to_HOL_state p s =\n  \\<lparr>map_var_bit_to_var_acc_acc = (s (add_prefix p map_var_bit_to_var_acc_acc_str)),\n  map_var_bit_to_var_acc_v = (s (add_prefix p map_var_bit_to_var_acc_v_str)),\n  map_var_bit_to_var_acc_n = (s (add_prefix p map_var_bit_to_var_acc_n_str)),\n  map_var_bit_to_var_acc_ret = (s (add_prefix p map_var_bit_to_var_acc_ret_str))\\<rparr>\"\n\nlemmas map_var_bit_to_var_acc_state_translators =\n  map_var_bit_to_var_acc_imp_to_HOL_state_def\n  map_var_bit_to_var_aux_imp_to_HOL_state_def\n\nlemmas map_var_bit_to_var_acc_complete_simps =\n  map_var_bit_to_var_acc_IMP_subprogram_simps\n  map_var_bit_to_var_acc_imp_subprogram_simps\n  map_var_bit_to_var_acc_state_translators\n\nlemma map_var_bit_to_var_acc_IMP_Minus_correct_function:\n  \"(invoke_subprogram p map_var_bit_to_var_acc_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p map_var_bit_to_var_acc_ret_str)\n      = map_var_bit_to_var_acc_ret\n          (map_var_bit_to_var_acc_imp (map_var_bit_to_var_acc_imp_to_HOL_state p s))\"\n  apply(induction \"map_var_bit_to_var_acc_imp_to_HOL_state p s\" arbitrary: s s' t\n    rule: map_var_bit_to_var_acc_imp.induct)\n  apply(subst map_var_bit_to_var_acc_imp.simps)\n  apply(simp only: map_var_bit_to_var_acc_IMP_Minus_def prefix_simps)\n  apply(erule Seq_E)+\n  apply(erule While_tE)\n\n    subgoal \n      apply (simp only: map_var_bit_to_var_acc_IMP_subprogram_simps prefix_simps)\n      apply (clarsimp simp: map_var_bit_to_var_acc_complete_simps) \n      done \n\n  apply(erule Seq_E)+\n  apply(dest_com_gen)\n\n  subgoal\n      apply(simp only: map_var_bit_to_var_acc_IMP_init_while_cond_def prefix_simps)\n      by(fastforce simp add: map_var_bit_to_var_acc_complete_simps)\n\n  subgoal\n      apply(subst (asm) map_var_bit_to_var_acc_IMP_init_while_cond_def)\n      apply(simp only: map_var_bit_to_var_acc_IMP_loop_body_def prefix_simps)\n      apply(erule Seq_E)+\n      apply(erule map_var_bit_to_var_aux_IMP_Minus_correct[where vars = \"map_var_bit_to_var_acc_IMP_vars\"])\n      subgoal premises p using p(12) by fastforce\n      apply (force simp add: map_var_bit_to_var_acc_imp_subprogram_simps \n         map_var_bit_to_var_acc_state_translators Let_def)\n      done \n\n  subgoal\n      apply(simp only: map_var_bit_to_var_acc_IMP_init_while_cond_def prefix_simps\n          map_var_bit_to_var_acc_IMP_loop_body_def)\n      apply(erule Seq_E)+\n      apply(erule map_var_bit_to_var_aux_IMP_Minus_correct[where vars = \"map_var_bit_to_var_acc_IMP_vars\"])\n      subgoal premises p using p(12) by fastforce\n      apply (force simp add: map_var_bit_to_var_acc_imp_subprogram_simps \n         map_var_bit_to_var_acc_state_translators Let_def split: if_splits)\n      done \n  done \n\nlemma map_var_bit_to_var_acc_IMP_Minus_correct_effects:\n  \"\\<lbrakk>(invoke_subprogram (p @ map_var_bit_to_var_acc_pref) map_var_bit_to_var_acc_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    v \\<in> vars; \\<not> (prefix map_var_bit_to_var_acc_pref v)\\<rbrakk>\n   \\<Longrightarrow> s (add_prefix p v) = s' (add_prefix p v)\"\n  using com_add_prefix_valid'' com_only_vars prefix_def\n  by blast            \n\nlemmas map_var_bit_to_var_acc_complete_time_simps =\n  map_var_bit_to_var_acc_imp_subprogram_time_simps\n  map_var_bit_to_var_acc_imp_time_acc\n  map_var_bit_to_var_acc_imp_time_acc_2\n  map_var_bit_to_var_acc_imp_time_acc_3\n  map_var_bit_to_var_acc_state_translators\n\nlemma map_var_bit_to_var_acc_IMP_Minus_correct_time:\n  \"(invoke_subprogram p map_var_bit_to_var_acc_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = map_var_bit_to_var_acc_imp_time 0 (map_var_bit_to_var_acc_imp_to_HOL_state p s)\"\n  apply(induction \"map_var_bit_to_var_acc_imp_to_HOL_state p s\" arbitrary: s s' t\n      rule: map_var_bit_to_var_acc_imp.induct)\n  apply(subst map_var_bit_to_var_acc_imp_time.simps)\n  apply(simp only: map_var_bit_to_var_acc_IMP_Minus_def prefix_simps)\n\n  apply(erule Seq_tE)+\n  apply(erule While_tE_time)\n  subgoal\n    apply(simp only: map_var_bit_to_var_acc_IMP_subprogram_simps prefix_simps\n     map_var_bit_to_var_acc_complete_time_simps Let_def split: if_splits) \n    apply force\n    done \n\n  apply(erule Seq_tE)+\n  apply(simp add: add.assoc)\n  apply(dest_com_gen_time)\n\n  subgoal\n    apply(simp only: map_var_bit_to_var_acc_IMP_init_while_cond_def prefix_simps)\n    by(fastforce simp add: map_var_bit_to_var_acc_complete_simps)\n\n  subgoal\n    apply(subst (asm) map_var_bit_to_var_acc_IMP_init_while_cond_def)\n    apply(simp only: map_var_bit_to_var_acc_IMP_loop_body_def prefix_simps)\n    apply(erule Seq_tE)+\n    apply(erule map_var_bit_to_var_aux_IMP_Minus_correct[where vars = \"map_var_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(21) by fastforce\n    apply (force simp: map_var_bit_to_var_acc_imp_subprogram_time_simps\n        map_var_bit_to_var_acc_state_translators Let_def)\n    done \n\n  subgoal\n    apply(simp only: prefix_simps map_var_bit_to_var_acc_IMP_init_while_cond_def\n        map_var_bit_to_var_acc_IMP_loop_body_def)\n    apply(erule Seq_tE)+\n    apply(erule map_var_bit_to_var_aux_IMP_Minus_correct[where vars = \"map_var_bit_to_var_acc_IMP_vars\"])\n    subgoal premises p using p(21) by fastforce\n    apply (clarsimp simp add: map_var_bit_to_var_acc_complete_time_simps Let_def)\n    subgoal premises p \n      using p(10) \n      by (smt (z3) fun_upd_def list.inject list.simps(3) \n      map_var_bit_to_var_acc_imp_time_acc_2_aux same_append_eq)\n    done  \n  done   \n\nlemma map_var_bit_to_var_acc_IMP_Minus_correct[functional_correctness]:\n  \"\\<lbrakk>(invoke_subprogram (p1 @ p2) map_var_bit_to_var_acc_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    \\<And>v. v \\<in> vars \\<Longrightarrow> \\<not> (set p2 \\<subseteq> set v);\n    \\<lbrakk>t = (map_var_bit_to_var_acc_imp_time 0 (map_var_bit_to_var_acc_imp_to_HOL_state (p1 @ p2) s));\n     s' (add_prefix (p1 @ p2) map_var_bit_to_var_acc_ret_str) =\n          map_var_bit_to_var_acc_ret (map_var_bit_to_var_acc_imp\n                                        (map_var_bit_to_var_acc_imp_to_HOL_state (p1 @ p2) s));\n     \\<And>v. v \\<in> vars \\<Longrightarrow> s (add_prefix p1 v) = s' (add_prefix p1 v)\\<rbrakk>\n   \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  using map_var_bit_to_var_acc_IMP_Minus_correct_function\n  by (auto simp: map_var_bit_to_var_acc_IMP_Minus_correct_time)\n    (meson map_var_bit_to_var_acc_IMP_Minus_correct_effects set_mono_prefix) \n\nsubsubsection \\<open>map_var_bit_to_var_tail\\<close>\nrecord map_var_bit_to_var_tail_state =\nmap_var_bit_to_var_tail_v::nat\nmap_var_bit_to_var_tail_n::nat\nmap_var_bit_to_var_tail_ret::nat \n\nabbreviation \"map_var_bit_to_var_tail_prefix \\<equiv> ''map_var_bit_to_var_tail.''\"\nabbreviation \"map_var_bit_to_var_tail_v_str \\<equiv> ''v''\"\nabbreviation \"map_var_bit_to_var_tail_n_str \\<equiv> ''n''\"\nabbreviation \"map_var_bit_to_var_tail_ret_str \\<equiv> ''ret''\"\n\nfunction map_var_bit_to_var_tail_imp :: \n\"map_var_bit_to_var_tail_state \\<Rightarrow> map_var_bit_to_var_tail_state\"where \n\"map_var_bit_to_var_tail_imp s =\n (let \n   map_var_bit_to_var_acc_acc' = 0;\n   map_var_bit_to_var_acc_v' = map_var_bit_to_var_tail_v s;\n   map_var_bit_to_var_acc_n' = map_var_bit_to_var_tail_n s;\n   map_var_bit_to_var_acc_ret' = 0;\n   map_var_bit_to_var_acc_state = \n     \\<lparr>map_var_bit_to_var_acc_acc = map_var_bit_to_var_acc_acc',\n     map_var_bit_to_var_acc_v = map_var_bit_to_var_acc_v',\n     map_var_bit_to_var_acc_n = map_var_bit_to_var_acc_n',\n     map_var_bit_to_var_acc_ret = map_var_bit_to_var_acc_ret'\\<rparr>;\n  map_var_bit_to_var_acc_ret_state = map_var_bit_to_var_acc_imp map_var_bit_to_var_acc_state;\n\n  reverse_nat_n' = map_var_bit_to_var_acc_ret map_var_bit_to_var_acc_ret_state;\n  reverse_nat_ret' = 0;\n  reverse_nat_state = \\<lparr>reverse_nat_n = reverse_nat_n',\n                       reverse_nat_ret = reverse_nat_ret'\\<rparr>;\n  reverse_nat_ret_state = reverse_nat_imp reverse_nat_state;\n  map_var_bit_to_var_tail_ret' = reverse_nat_ret reverse_nat_ret_state;\n  ret = \\<lparr>map_var_bit_to_var_tail_v = map_var_bit_to_var_tail_v s,\n        map_var_bit_to_var_tail_n = map_var_bit_to_var_tail_n s,\n        map_var_bit_to_var_tail_ret = map_var_bit_to_var_tail_ret'\\<rparr>\n in \n  ret)\" by simp+\n termination \n apply (relation \"measure map_var_bit_to_var_tail_n\")\n apply auto \n done \n\ndeclare map_var_bit_to_var_tail_imp.simps[simp del]\n\nlemma map_var_bit_to_var_tail_imp_correct[let_function_correctness]:\n  \"map_var_bit_to_var_tail_ret (map_var_bit_to_var_tail_imp s)\n    = map_var_bit_to_var_tail (map_var_bit_to_var_tail_v s) (map_var_bit_to_var_tail_n s)\"\napply (subst map_var_bit_to_var_tail_imp.simps)\napply auto\nusing  map_var_bit_to_var_tail_def reverse_nat_imp_correct \nmap_var_bit_to_var_acc_imp_correct map_var_bit_to_var_acc'_imp_correct\nby auto\n\nfunction map_var_bit_to_var_tail_imp_time :: \n\"nat \\<Rightarrow> map_var_bit_to_var_tail_state \\<Rightarrow> nat\"where \n\"map_var_bit_to_var_tail_imp_time t s =\n (let \n   map_var_bit_to_var_acc_acc' = 0;\n   t = t + 2;\n   map_var_bit_to_var_acc_v' = map_var_bit_to_var_tail_v s;\n   t = t + 2;\n   map_var_bit_to_var_acc_n' = map_var_bit_to_var_tail_n s;\n   t = t + 2;\n   map_var_bit_to_var_acc_ret' = 0;\n   t = t + 2;\n   map_var_bit_to_var_acc_state = \n     \\<lparr>map_var_bit_to_var_acc_acc = map_var_bit_to_var_acc_acc',\n     map_var_bit_to_var_acc_v = map_var_bit_to_var_acc_v',\n     map_var_bit_to_var_acc_n = map_var_bit_to_var_acc_n',\n     map_var_bit_to_var_acc_ret = map_var_bit_to_var_acc_ret'\\<rparr>;\n  map_var_bit_to_var_acc_ret_state = map_var_bit_to_var_acc_imp map_var_bit_to_var_acc_state;\n  t = t + map_var_bit_to_var_acc_imp_time 0 map_var_bit_to_var_acc_state;\n\n  reverse_nat_n' = map_var_bit_to_var_acc_ret map_var_bit_to_var_acc_ret_state;\n  t = t + 2;\n  reverse_nat_ret' = 0;\n  t = t + 2;\n  reverse_nat_state = \\<lparr>reverse_nat_n = reverse_nat_n',\n                       reverse_nat_ret = reverse_nat_ret'\\<rparr>;\n  reverse_nat_ret_state = reverse_nat_imp reverse_nat_state;\n  t = t + reverse_nat_imp_time 0 reverse_nat_state;\n  \n  map_var_bit_to_var_tail_ret' = reverse_nat_ret reverse_nat_ret_state;\n  t = t + 2;\n  ret = \\<lparr>map_var_bit_to_var_tail_v = map_var_bit_to_var_tail_v s,\n        map_var_bit_to_var_tail_n = map_var_bit_to_var_tail_n s,\n        map_var_bit_to_var_tail_ret = map_var_bit_to_var_tail_ret'\\<rparr>\n in \n  t)\" by auto\n termination \n apply (relation \"measure (map_var_bit_to_var_tail_n \\<circ> snd)\")\n apply auto \n done \n\ndeclare map_var_bit_to_var_tail_imp_time.simps[simp del]\n\ndefinition \"map_var_bit_to_var_tail_IMP_Minus \\<equiv> \n (map_var_bit_to_var_acc_prefix @ map_var_bit_to_var_acc_acc_str) ::= A (N 0);;\n (map_var_bit_to_var_acc_prefix @ map_var_bit_to_var_acc_v_str) ::= A (V map_var_bit_to_var_tail_v_str);;\n (map_var_bit_to_var_acc_prefix @ map_var_bit_to_var_acc_n_str) ::= A (V map_var_bit_to_var_tail_n_str);;\n (map_var_bit_to_var_acc_prefix @ map_var_bit_to_var_acc_ret_str) ::= A (N 0);;\n invoke_subprogram map_var_bit_to_var_acc_prefix map_var_bit_to_var_acc_IMP_Minus;;\n\n (reverse_nat_prefix @ reverse_nat_n_str) ::= A (V (map_var_bit_to_var_acc_prefix @ map_var_bit_to_var_acc_ret_str));;\n (reverse_nat_prefix @ reverse_nat_ret_str) ::= A (N 0);;\n invoke_subprogram reverse_nat_prefix reverse_nat_IMP_Minus;;\n\n map_var_bit_to_var_tail_ret_str ::= A (V (reverse_nat_prefix @ reverse_nat_ret_str))\n\"\n\nabbreviation \"map_var_bit_to_var_tail_IMP_vars \\<equiv> \n  {map_var_bit_to_var_tail_ret_str, map_var_bit_to_var_tail_n_str, map_var_bit_to_var_tail_v_str}\"\n\ndefinition \"map_var_bit_to_var_tail_imp_to_HOL_state p s = \n\\<lparr>  map_var_bit_to_var_tail_v = (s (add_prefix p map_var_bit_to_var_tail_v_str)),\n  map_var_bit_to_var_tail_n = (s (add_prefix p map_var_bit_to_var_tail_n_str)),\n  map_var_bit_to_var_tail_ret = (s (add_prefix p map_var_bit_to_var_tail_ret_str))\\<rparr>\"\n\nlemmas map_var_bit_to_var_tail_state_translators = \n  map_var_bit_to_var_tail_imp_to_HOL_state_def\n  map_var_bit_to_var_acc_imp_to_HOL_state_def\n  reverse_nat_imp_to_HOL_state_def\n\nlemma map_var_bit_to_var_tail_IMP_Minus_correct_function:\n\"(invoke_subprogram p map_var_bit_to_var_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p map_var_bit_to_var_tail_ret_str)\n      = map_var_bit_to_var_tail_ret\n          (map_var_bit_to_var_tail_imp (map_var_bit_to_var_tail_imp_to_HOL_state p s))\"\napply (simp only: map_var_bit_to_var_tail_IMP_Minus_def prefix_simps)\napply (erule Seq_E)+\napply (erule map_var_bit_to_var_acc_IMP_Minus_correct[where vars=map_var_bit_to_var_tail_IMP_vars])\nsubgoal premises p using p(9) by fastforce\napply (erule reverse_nat_IMP_Minus_correct[where vars=map_var_bit_to_var_tail_IMP_vars])\nsubgoal premises p using p(11) by fastforce\napply (clarsimp simp add: map_var_bit_to_var_tail_state_translators Let_def\n map_var_bit_to_var_tail_imp.simps)\ndone \n\nlemma map_var_bit_to_var_tail_IMP_Minus_correct_effects:\n  \"\\<lbrakk>(invoke_subprogram (p @ map_var_bit_to_var_tail_pref) map_var_bit_to_var_aux_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    v \\<in> vars; \\<not> (prefix map_var_bit_to_var_tail_pref v)\\<rbrakk>\n   \\<Longrightarrow> s (add_prefix p v) = s' (add_prefix p v)\"\n  using com_add_prefix_valid'' com_only_vars prefix_def\n  by blast            \n\n\nlemma map_var_bit_to_var_tail_IMP_Minus_correct_time:\n  \"(invoke_subprogram p map_var_bit_to_var_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = map_var_bit_to_var_tail_imp_time 0 (map_var_bit_to_var_tail_imp_to_HOL_state p s)\"\napply (simp only: map_var_bit_to_var_tail_IMP_Minus_def prefix_simps)\napply (erule Seq_tE)+\napply (erule map_var_bit_to_var_acc_IMP_Minus_correct[where vars=map_var_bit_to_var_tail_IMP_vars])\nsubgoal premises p using p(17) by fastforce\napply (erule reverse_nat_IMP_Minus_correct[where vars=map_var_bit_to_var_aux_IMP_vars])\nsubgoal premises p using p(19) by fastforce\napply (force simp: map_var_bit_to_var_tail_imp_time.simps \n  Let_def map_var_bit_to_var_tail_state_translators)\ndone \n\nlemma map_var_bit_to_var_tail_IMP_Minus_correct[functional_correctness]:\n  \"\\<lbrakk>(invoke_subprogram (p1 @ p2) map_var_bit_to_var_tail_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    \\<And>v. v \\<in> vars \\<Longrightarrow> \\<not> (set p2 \\<subseteq> set v);\n    \\<lbrakk>t = (map_var_bit_to_var_tail_imp_time 0 (map_var_bit_to_var_tail_imp_to_HOL_state (p1 @ p2) s));\n     s' (add_prefix (p1 @ p2) map_var_bit_to_var_tail_ret_str) =\n          map_var_bit_to_var_tail_ret (map_var_bit_to_var_tail_imp\n                                        (map_var_bit_to_var_tail_imp_to_HOL_state (p1 @ p2) s));\n     \\<And>v. v \\<in> vars \\<Longrightarrow> s (add_prefix p1 v) = s' (add_prefix p1 v)\\<rbrakk>\n   \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  using map_var_bit_to_var_tail_IMP_Minus_correct_function \n   map_var_bit_to_var_tail_IMP_Minus_correct_time\n  by (meson com_add_prefix_valid_subset com_only_vars)\n\nsubsection \\<open>push_on_stack\\<close>\nsubsubsection \\<open>push_on_stack_nat\\<close>\nrecord push_on_stack_nat_state =\npush_on_stack_nat_c :: nat\npush_on_stack_nat_n :: nat\npush_on_stack_nat_s :: nat\npush_on_stack_nat_ret :: nat\n\nabbreviation \"push_on_stack_nat_prefix \\<equiv> ''push_on_stack_nat.''\"\nabbreviation \"push_on_stack_nat_c_str \\<equiv> ''push_on_stack_nat_c''\"\nabbreviation \"push_on_stack_nat_n_str \\<equiv> ''push_on_stack_nat_n''\"\nabbreviation \"push_on_stack_nat_s_str \\<equiv> ''push_on_stack_nat_s''\"\nabbreviation \"push_on_stack_nat_ret_str \\<equiv> ''push_on_stack_nat_ret''\"\n\ndefinition \"push_on_stack_nat_imp_to_HOL_state p s \\<equiv>\n  \\<lparr>push_on_stack_nat_c = s (add_prefix p push_on_stack_nat_c_str),\n  push_on_stack_nat_n = s (add_prefix p push_on_stack_nat_n_str),\n  push_on_stack_nat_s = s (add_prefix p push_on_stack_nat_s_str),\n  push_on_stack_nat_ret = s (add_prefix p push_on_stack_nat_ret_str)\\<rparr>\"\n\nabbreviation \"push_on_stack_nat_hd_c \\<equiv> ''push_on_stack_nat_hd_c''\"\nabbreviation \"push_on_stack_nat_cons_n_0 \\<equiv> ''push_on_stack_nat_cons_n_0''\"\nabbreviation \"push_on_stack_nat_nth_nat_ret_one \\<equiv> ''push_on_stack_nat_nth_nat_ret_one''\"\nabbreviation \"push_on_stack_nat_nth_nat_ret_two \\<equiv> ''push_on_stack_nat_nth_nat_ret_two''\"\nabbreviation \"push_on_stack_nat_nth_nat_ret_three \\<equiv> ''push_on_stack_nat_nth_nat_ret_three''\"\nabbreviation \"push_on_stack_nat_cons_res \\<equiv> ''push_on_stack_nat_cons_res''\"\nabbreviation \"push_on_stack_nat_cond_one \\<equiv> ''push_on_stack_nat_cond_one''\"\nabbreviation \"push_on_stack_nat_cond_two \\<equiv> ''push_on_stack_nat_cond_two''\"\nabbreviation \"push_on_stack_nat_cond_three \\<equiv> ''push_on_stack_nat_cond_three''\"\n\nabbreviation \"push_on_stack_nat_IMP_vars \\<equiv> {\n  push_on_stack_nat_c_str, push_on_stack_nat_n_str, push_on_stack_nat_s_str, push_on_stack_nat_ret_str \n}\"\n\n\nlemmas push_on_stack_nat_state_translators =\n  push_on_stack_nat_imp_to_HOL_state_def\n  hd_imp_to_HOL_state_def\n  cons_imp_to_HOL_state_def\n  NOTEQUAL_neq_zero_imp_to_HOL_state_def\n  nth_nat_imp_to_HOL_state_def\n\nparagraph if_eq_zero \n\ndefinition \"push_on_stack_nat_eq_zero s \\<equiv> \n  (let\n  cons_h' = push_on_stack_nat_n s;\n  cons_t' = 0;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  cons_h' = 1;\n  cons_t' = cons_ret cons_ret_state;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  cons_h' = cons_ret cons_ret_state;\n  cons_t' = push_on_stack_nat_s s;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n\n  push_on_stack_nat_ret' = cons_ret cons_ret_state;\n  ret = \\<lparr>push_on_stack_nat_c = push_on_stack_nat_c s,\n        push_on_stack_nat_n = push_on_stack_nat_n s,\n        push_on_stack_nat_s = push_on_stack_nat_s s,\n        push_on_stack_nat_ret = push_on_stack_nat_ret'\\<rparr>\nin\n  ret)\"\n\nlemma push_on_stack_nat_eq_zero_imp_correct[let_function_correctness]:\n  \"push_on_stack_nat_ret (push_on_stack_nat_eq_zero s) = \n    cons (cons 1 (cons (push_on_stack_nat_n s) 0)) (push_on_stack_nat_s s)\"\n  unfolding push_on_stack_nat_eq_zero_def\n  apply (simp add: hd_imp_correct cons_imp_correct Let_def)\n  done \n\ndefinition \"push_on_stack_nat_eq_zero_time t s \\<equiv> \n  (let\n  cons_h' = push_on_stack_nat_n s;\n  t = t + 2;\n  cons_t' = 0;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n\n  cons_h' = 1;\n  t = t + 2;\n  cons_t' = cons_ret cons_ret_state;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n\n  cons_h' = cons_ret cons_ret_state;\n  t = t + 2;\n  cons_t' = push_on_stack_nat_s s;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n\n  push_on_stack_nat_ret' = cons_ret cons_ret_state;\n  t = t + 2;\n  ret = \\<lparr>push_on_stack_nat_c = push_on_stack_nat_c s,\n        push_on_stack_nat_n = push_on_stack_nat_n s,\n        push_on_stack_nat_s = push_on_stack_nat_s s,\n        push_on_stack_nat_ret = push_on_stack_nat_ret'\\<rparr>\nin\n  t)\"\n\ndefinition \"push_on_stack_nat_eq_zero_IMP_Minus \\<equiv> \n (cons_prefix @ cons_h_str) ::= A (V push_on_stack_nat_n_str);;\n (cons_prefix @ cons_t_str) ::= A (N 0);;\n (cons_prefix @ cons_ret_str) ::= A (N 0);;\n invoke_subprogram cons_prefix cons_IMP_Minus;;\n\n (cons_prefix @ cons_h_str) ::= A (N 1);;\n (cons_prefix @ cons_t_str) ::= A (V (cons_prefix @ cons_ret_str));;\n (cons_prefix @ cons_ret_str) ::= A (N 0);;\n invoke_subprogram cons_prefix cons_IMP_Minus;;\n\n (cons_prefix @ cons_h_str) ::= A (V (cons_prefix @ cons_ret_str));;\n (cons_prefix @ cons_t_str) ::= A (V push_on_stack_nat_s_str);;\n (cons_prefix @ cons_ret_str) ::= A (N 0);;\n invoke_subprogram cons_prefix cons_IMP_Minus;;\n push_on_stack_nat_ret_str ::= A (V (cons_prefix @ cons_ret_str))\n\"\n\nlemma push_on_stack_nat_eq_zero_IMP_Minus_correct_function:\n  \"(invoke_subprogram p push_on_stack_nat_eq_zero_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p push_on_stack_nat_ret_str)\n      = push_on_stack_nat_ret\n          (push_on_stack_nat_eq_zero (push_on_stack_nat_imp_to_HOL_state p s))\"\n   apply (subst push_on_stack_nat_eq_zero_def)\n   apply (simp only: push_on_stack_nat_eq_zero_IMP_Minus_def prefix_simps)\n   apply (erule Seq_E)+\n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars])\n   subgoal premises p using p(13) by fastforce \n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars])\n   subgoal premises p using p(15) by fastforce \n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars])\n   subgoal premises p using p(17) by fastforce \n   apply (force simp: \n      push_on_stack_nat_imp_to_HOL_state_def cons_imp_to_HOL_state_def Let_def)\n   done \n\nlemma push_on_stack_nat_eq_zero_IMP_Minus_correct_time:\n  \"(invoke_subprogram p push_on_stack_nat_eq_zero_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = push_on_stack_nat_eq_zero_time 0 (push_on_stack_nat_imp_to_HOL_state p s)\"\n   apply (subst push_on_stack_nat_eq_zero_time_def)\n   apply (simp only: push_on_stack_nat_eq_zero_IMP_Minus_def prefix_simps)\n   apply (erule Seq_tE)+\n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars])\n   subgoal premises p using p(25) by fastforce \n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars])\n   subgoal premises p using p(27) by fastforce \n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars])\n   subgoal premises p using p(29) by fastforce \n   apply (timeit \\<open>force simp:\n      push_on_stack_nat_imp_to_HOL_state_def cons_imp_to_HOL_state_def Let_def\\<close>)\n   done\n\nparagraph if_eq_one\n\ndefinition \"push_on_stack_nat_eq_one s \\<equiv> \n  (let\n  cons_h' = push_on_stack_nat_n s;\n  cons_t' = 0;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  push_on_stack_nat_cons_res = cons_ret cons_ret_state;\n\n  nth_nat_n' = 1;\n  nth_nat_x' = push_on_stack_nat_c s;\n  nth_nat_ret' = 0;\n  nth_nat_state = \\<lparr>nth_nat_n = nth_nat_n', nth_nat_x = nth_nat_x', nth_nat_ret = nth_nat_ret'\\<rparr>;\n  nth_nat_ret_state = nth_nat_imp nth_nat_state;\n  push_on_stack_nat_nth_nat_ret_one = nth_nat_ret nth_nat_ret_state;\n\n  nth_nat_n' = 2;\n  nth_nat_x' = push_on_stack_nat_c s;\n  nth_nat_ret' = 0;\n  nth_nat_state = \\<lparr>nth_nat_n = nth_nat_n', nth_nat_x = nth_nat_x', nth_nat_ret = nth_nat_ret'\\<rparr>;\n  nth_nat_ret_state = nth_nat_imp nth_nat_state;\n\n  cons_h' = nth_nat_ret nth_nat_ret_state;\n  cons_t' = push_on_stack_nat_cons_res;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n\n  cons_h' = push_on_stack_nat_nth_nat_ret_one;\n  cons_t' = cons_ret cons_ret_state;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n\n  cons_h' = 2;\n  cons_t' = cons_ret cons_ret_state;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n\n  cons_h' = cons_ret cons_ret_state;\n  cons_t' = push_on_stack_nat_s s;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n\n  push_on_stack_nat_ret' = cons_ret cons_ret_state;\n  ret = \\<lparr>push_on_stack_nat_c = push_on_stack_nat_c s,\n        push_on_stack_nat_n = push_on_stack_nat_n s,\n        push_on_stack_nat_s = push_on_stack_nat_s s,\n        push_on_stack_nat_ret = push_on_stack_nat_ret'\\<rparr>\nin\n  ret)\"\n\nlemma push_on_stack_nat_eq_one_imp_correct[let_function_correctness]:\n  \"push_on_stack_nat_ret (push_on_stack_nat_eq_one s) = \n    (2## (nth_nat (Suc 0) (push_on_stack_nat_c s)) ## \n     (nth_nat (Suc (Suc 0)) (push_on_stack_nat_c s)) ##\n      (push_on_stack_nat_n s) ## 0)## (push_on_stack_nat_s s)\"\n  unfolding push_on_stack_nat_eq_one_def\n  apply (simp add: nth_nat_imp_correct cons_imp_correct Let_def numeral_2_eq_2)\n  done\n\ndefinition \"push_on_stack_nat_eq_one_time t s \\<equiv> \n  (let\n  cons_h' = push_on_stack_nat_n s;\n  t = t + 2;\n  cons_t' = 0;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n  push_on_stack_nat_cons_res = cons_ret cons_ret_state;\n  t = t + 2;\n\n  nth_nat_n' = 1;\n  t = t + 2;\n  nth_nat_x' = push_on_stack_nat_c s;\n  t = t + 2;\n  nth_nat_ret' = 0;\n  t = t + 2;\n  nth_nat_state = \\<lparr>nth_nat_n = nth_nat_n', nth_nat_x = nth_nat_x', nth_nat_ret = nth_nat_ret'\\<rparr>;\n  nth_nat_ret_state = nth_nat_imp nth_nat_state;\n  t = t + nth_nat_imp_time 0 nth_nat_state;\n  push_on_stack_nat_nth_nat_ret_one = nth_nat_ret nth_nat_ret_state;\n  t = t + 2;\n\n  nth_nat_n' = 2;\n  t = t + 2;\n  nth_nat_x' = push_on_stack_nat_c s;\n  t = t + 2;\n  nth_nat_ret' = 0;\n  t = t + 2;\n  nth_nat_state = \\<lparr>nth_nat_n = nth_nat_n', nth_nat_x = nth_nat_x', nth_nat_ret = nth_nat_ret'\\<rparr>;\n  nth_nat_ret_state = nth_nat_imp nth_nat_state;\n  t = t + nth_nat_imp_time 0 nth_nat_state;\n\n  cons_h' = nth_nat_ret nth_nat_ret_state;\n  t = t + 2;\n  cons_t' = push_on_stack_nat_cons_res;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n\n  cons_h' = push_on_stack_nat_nth_nat_ret_one;\n  t = t + 2;\n  cons_t' = cons_ret cons_ret_state;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n\n  cons_h' = 2;\n  t = t + 2;\n  cons_t' = cons_ret cons_ret_state;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n\n  cons_h' = cons_ret cons_ret_state;\n  t = t + 2;\n  cons_t' = push_on_stack_nat_s s;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n\n  push_on_stack_nat_ret' = cons_ret cons_ret_state;\n  t = t + 2;\n  ret = \\<lparr>push_on_stack_nat_c = push_on_stack_nat_c s,\n        push_on_stack_nat_n = push_on_stack_nat_n s,\n        push_on_stack_nat_s = push_on_stack_nat_s s,\n        push_on_stack_nat_ret = push_on_stack_nat_ret'\\<rparr>\nin\n  t)\"\n\ndefinition \"push_on_stack_nat_eq_one_IMP_Minus \\<equiv>\n  (cons_prefix @ cons_h_str) ::= A (V push_on_stack_nat_n_str);;\n  (cons_prefix @ cons_t_str) ::= A (N 0);;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n  push_on_stack_nat_cons_res ::= A (V (cons_prefix @ cons_ret_str));;\n\n  (nth_nat_prefix @ nth_nat_n_str) ::= A (N 1);;\n  (nth_nat_prefix @ nth_nat_x_str) ::= A (V push_on_stack_nat_c_str);;\n  (nth_nat_prefix @ nth_nat_ret_str) ::= A (N 0);;\n  invoke_subprogram nth_nat_prefix nth_nat_IMP_Minus;;\n  push_on_stack_nat_nth_nat_ret_one ::= A (V (nth_nat_prefix @ nth_nat_ret_str));;\n\n  (nth_nat_prefix @ nth_nat_n_str) ::= A (N 2);;\n  (nth_nat_prefix @ nth_nat_x_str) ::= A (V push_on_stack_nat_c_str);;\n  (nth_nat_prefix @ nth_nat_ret_str) ::= A (N 0);;\n  invoke_subprogram nth_nat_prefix nth_nat_IMP_Minus;;\n\n  (cons_prefix @ cons_h_str) ::= A (V (nth_nat_prefix @ nth_nat_ret_str));;\n  (cons_prefix @ cons_t_str) ::= A (V push_on_stack_nat_cons_res);;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n\n  (cons_prefix @ cons_h_str) ::= A (V push_on_stack_nat_nth_nat_ret_one);;\n  (cons_prefix @ cons_t_str) ::= A (V (cons_prefix @ cons_ret_str));;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n\n  (cons_prefix @ cons_h_str) ::= A (N 2);;\n  (cons_prefix @ cons_t_str) ::= A (V (cons_prefix @ cons_ret_str));;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n\n  (cons_prefix @ cons_h_str) ::= A (V (cons_prefix @ cons_ret_str));;\n  (cons_prefix @ cons_t_str) ::= A (V push_on_stack_nat_s_str);;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n  push_on_stack_nat_ret_str ::= A (V (cons_prefix @ cons_ret_str))\n\"\n\nabbreviation \"push_on_stack_nat_IMP_vars_eq_one \\<equiv> push_on_stack_nat_IMP_vars \n  \\<union> {push_on_stack_nat_nth_nat_ret_one, push_on_stack_nat_cons_res}\"\n\nlemma push_on_stack_nat_eq_one_IMP_Minus_correct_function:\n  \"(invoke_subprogram p push_on_stack_nat_eq_one_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p push_on_stack_nat_ret_str)\n      = push_on_stack_nat_ret\n          (push_on_stack_nat_eq_one (push_on_stack_nat_imp_to_HOL_state p s))\"\n   apply (subst push_on_stack_nat_eq_one_def)\n   apply (simp only: push_on_stack_nat_eq_one_IMP_Minus_def prefix_simps)\n   apply (erule Seq_E)+\n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_one])\n   subgoal premises p using p(31) by fastforce \n   apply (erule nth_nat_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_one])\n   subgoal premises p using p(33) by fastforce \n   apply (erule nth_nat_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_one])\n   subgoal premises p using p(35) by fastforce\n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_one])\n   subgoal premises p using p(37) by fastforce \n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_one])\n   subgoal premises p using p(39) by fastforce \n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_one])\n   subgoal premises p using p(41) by fastforce \n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_one])\n   subgoal premises p using p(43) by fastforce\n   apply (timeit \\<open>force simp:\n      push_on_stack_nat_imp_to_HOL_state_def cons_imp_to_HOL_state_def \n      nth_nat_imp_to_HOL_state_def Let_def\\<close>)\n   done\n\n\nlemma push_on_stack_nat_eq_one_IMP_Minus_correct_time:\n  \"(invoke_subprogram p push_on_stack_nat_eq_one_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = push_on_stack_nat_eq_one_time 0 (push_on_stack_nat_imp_to_HOL_state p s)\"\n  apply (subst push_on_stack_nat_eq_one_time_def)\n  apply (simp only: push_on_stack_nat_eq_one_IMP_Minus_def prefix_simps)\n  apply (erule Seq_tE)+\n  apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_one])\n  subgoal premises p using p(61) by fastforce \n  apply (erule nth_nat_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_one])\n  subgoal premises p using p(63) by fastforce \n  apply (erule nth_nat_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_one])\n  subgoal premises p using p(65) by fastforce\n  apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_one])\n  subgoal premises p using p(67) by fastforce \n  apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_one])\n  subgoal premises p using p(69) by fastforce \n  apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_one])\n  subgoal premises p using p(71) by fastforce \n  apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_one])\n  subgoal premises p using p(73) by fastforce\n  apply (timeit \\<open>force simp: \n      push_on_stack_nat_imp_to_HOL_state_def cons_imp_to_HOL_state_def \n      nth_nat_imp_to_HOL_state_def Let_def\\<close>)\n  done\n\nparagraph if_eq_two\n\ndefinition \"push_on_stack_nat_eq_two s \\<equiv> \n  (let\n  cons_h' = push_on_stack_nat_n s;\n  cons_t' = 0;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  push_on_stack_nat_cons_res = cons_ret cons_ret_state;\n\n  nth_nat_n' = 1;\n  nth_nat_x' = push_on_stack_nat_c s;\n  nth_nat_ret' = 0;\n  nth_nat_state = \\<lparr>nth_nat_n = nth_nat_n', nth_nat_x = nth_nat_x', nth_nat_ret = nth_nat_ret'\\<rparr>;\n  nth_nat_ret_state = nth_nat_imp nth_nat_state;\n  push_on_stack_nat_nth_nat_ret_one = nth_nat_ret nth_nat_ret_state;\n\n  nth_nat_n' = 2;\n  nth_nat_x' = push_on_stack_nat_c s;\n  nth_nat_ret' = 0;\n  nth_nat_state = \\<lparr>nth_nat_n = nth_nat_n', nth_nat_x = nth_nat_x', nth_nat_ret = nth_nat_ret'\\<rparr>;\n  nth_nat_ret_state = nth_nat_imp nth_nat_state;\n\n  cons_h' = nth_nat_ret nth_nat_ret_state;\n  cons_t' = push_on_stack_nat_cons_res;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n\n  cons_h' = push_on_stack_nat_nth_nat_ret_one;\n  cons_t' = cons_ret cons_ret_state;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n\n  cons_h' = 3;\n  cons_t' = cons_ret cons_ret_state;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n\n  cons_h' = cons_ret cons_ret_state;\n  cons_t' = push_on_stack_nat_s s;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n\n  push_on_stack_nat_ret' = cons_ret cons_ret_state;\n  ret = \\<lparr>push_on_stack_nat_c = push_on_stack_nat_c s,\n        push_on_stack_nat_n = push_on_stack_nat_n s,\n        push_on_stack_nat_s = push_on_stack_nat_s s,\n        push_on_stack_nat_ret = push_on_stack_nat_ret'\\<rparr>\nin\n  ret)\"\n\nlemma push_on_stack_nat_eq_two_imp_correct[let_function_correctness]:\n  \"push_on_stack_nat_ret (push_on_stack_nat_eq_two s) = \n    (3## (nth_nat (Suc 0) (push_on_stack_nat_c s)) ## \n     (nth_nat (Suc (Suc 0)) (push_on_stack_nat_c s)) ##\n      (push_on_stack_nat_n s) ## 0)## (push_on_stack_nat_s s)\"\n  unfolding push_on_stack_nat_eq_two_def\n  apply (simp add: nth_nat_imp_correct cons_imp_correct Let_def numeral_2_eq_2)\n  done\n\ndefinition \"push_on_stack_nat_eq_two_time t s \\<equiv> \n  (let\n  cons_h' = push_on_stack_nat_n s;\n  t = t + 2;\n  cons_t' = 0;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n  push_on_stack_nat_cons_res = cons_ret cons_ret_state;\n  t = t + 2;\n\n  nth_nat_n' = 1;\n  t = t + 2;\n  nth_nat_x' = push_on_stack_nat_c s;\n  t = t + 2;\n  nth_nat_ret' = 0;\n  t = t + 2;\n  nth_nat_state = \\<lparr>nth_nat_n = nth_nat_n', nth_nat_x = nth_nat_x', nth_nat_ret = nth_nat_ret'\\<rparr>;\n  nth_nat_ret_state = nth_nat_imp nth_nat_state;\n  t = t + nth_nat_imp_time 0 nth_nat_state;\n  push_on_stack_nat_nth_nat_ret_one = nth_nat_ret nth_nat_ret_state;\n  t = t + 2;\n\n  nth_nat_n' = 2;\n  t = t + 2;\n  nth_nat_x' = push_on_stack_nat_c s;\n  t = t + 2;\n  nth_nat_ret' = 0;\n  t = t + 2;\n  nth_nat_state = \\<lparr>nth_nat_n = nth_nat_n', nth_nat_x = nth_nat_x', nth_nat_ret = nth_nat_ret'\\<rparr>;\n  nth_nat_ret_state = nth_nat_imp nth_nat_state;\n  t = t + nth_nat_imp_time 0 nth_nat_state;\n\n  cons_h' = nth_nat_ret nth_nat_ret_state;\n  t = t + 2;\n  cons_t' = push_on_stack_nat_cons_res;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n\n  cons_h' = push_on_stack_nat_nth_nat_ret_one;\n  t = t + 2;\n  cons_t' = cons_ret cons_ret_state;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n\n  cons_h' = 3;\n  t = t + 2;\n  cons_t' = cons_ret cons_ret_state;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n\n  cons_h' = cons_ret cons_ret_state;\n  t = t + 2;\n  cons_t' = push_on_stack_nat_s s;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n\n  push_on_stack_nat_ret' = cons_ret cons_ret_state;\n  t = t + 2;\n  ret = \\<lparr>push_on_stack_nat_c = push_on_stack_nat_c s,\n        push_on_stack_nat_n = push_on_stack_nat_n s,\n        push_on_stack_nat_s = push_on_stack_nat_s s,\n        push_on_stack_nat_ret = push_on_stack_nat_ret'\\<rparr>\nin\n  t)\"\n\ndefinition \"push_on_stack_nat_eq_two_IMP_Minus \\<equiv>\n  (cons_prefix @ cons_h_str) ::= A (V push_on_stack_nat_n_str);;\n  (cons_prefix @ cons_t_str) ::= A (N 0);;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n  push_on_stack_nat_cons_res ::= A (V (cons_prefix @ cons_ret_str));;\n\n  (nth_nat_prefix @ nth_nat_n_str) ::= A (N 1);;\n  (nth_nat_prefix @ nth_nat_x_str) ::= A (V push_on_stack_nat_c_str);;\n  (nth_nat_prefix @ nth_nat_ret_str) ::= A (N 0);;\n  invoke_subprogram nth_nat_prefix nth_nat_IMP_Minus;;\n  push_on_stack_nat_nth_nat_ret_one ::= A (V (nth_nat_prefix @ nth_nat_ret_str));;\n\n  (nth_nat_prefix @ nth_nat_n_str) ::= A (N 2);;\n  (nth_nat_prefix @ nth_nat_x_str) ::= A (V push_on_stack_nat_c_str);;\n  (nth_nat_prefix @ nth_nat_ret_str) ::= A (N 0);;\n  invoke_subprogram nth_nat_prefix nth_nat_IMP_Minus;;\n\n  (cons_prefix @ cons_h_str) ::= A (V (nth_nat_prefix @ nth_nat_ret_str));;\n  (cons_prefix @ cons_t_str) ::= A (V push_on_stack_nat_cons_res);;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n\n  (cons_prefix @ cons_h_str) ::= A (V push_on_stack_nat_nth_nat_ret_one);;\n  (cons_prefix @ cons_t_str) ::= A (V (cons_prefix @ cons_ret_str));;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n\n  (cons_prefix @ cons_h_str) ::= A (N 3);;\n  (cons_prefix @ cons_t_str) ::= A (V (cons_prefix @ cons_ret_str));;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n\n  (cons_prefix @ cons_h_str) ::= A (V (cons_prefix @ cons_ret_str));;\n  (cons_prefix @ cons_t_str) ::= A (V push_on_stack_nat_s_str);;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n  push_on_stack_nat_ret_str ::= A (V (cons_prefix @ cons_ret_str))\n\"\n\nabbreviation \"push_on_stack_nat_IMP_vars_eq_two \\<equiv> push_on_stack_nat_IMP_vars \n  \\<union> {push_on_stack_nat_nth_nat_ret_one, push_on_stack_nat_cons_res}\"\n\nlemma push_on_stack_nat_eq_two_IMP_Minus_correct_function:\n  \"(invoke_subprogram p push_on_stack_nat_eq_two_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p push_on_stack_nat_ret_str)\n      = push_on_stack_nat_ret\n          (push_on_stack_nat_eq_two (push_on_stack_nat_imp_to_HOL_state p s))\"\n   apply (subst push_on_stack_nat_eq_two_def)\n   apply (simp only: push_on_stack_nat_eq_two_IMP_Minus_def prefix_simps)\n   apply (erule Seq_E)+\n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_two])\n   subgoal premises p using p(31) by fastforce \n   apply (erule nth_nat_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_two])\n   subgoal premises p using p(33) by fastforce \n   apply (erule nth_nat_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_two])\n   subgoal premises p using p(35) by fastforce\n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_two])\n   subgoal premises p using p(37) by fastforce \n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_two])\n   subgoal premises p using p(39) by fastforce \n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_two])\n   subgoal premises p using p(41) by fastforce \n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_two])\n   subgoal premises p using p(43) by fastforce\n   apply (timeit \\<open>force simp:\n      push_on_stack_nat_imp_to_HOL_state_def cons_imp_to_HOL_state_def \n      nth_nat_imp_to_HOL_state_def Let_def\\<close>)\n   done\n\nlemma push_on_stack_nat_eq_two_IMP_Minus_correct_time:\n  \"(invoke_subprogram p push_on_stack_nat_eq_two_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = push_on_stack_nat_eq_two_time 0 (push_on_stack_nat_imp_to_HOL_state p s)\"\n  apply (subst push_on_stack_nat_eq_two_time_def)\n  apply (simp only: push_on_stack_nat_eq_two_IMP_Minus_def prefix_simps)\n  apply (erule Seq_tE)+\n  apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_two])\n  subgoal premises p using p(61) by fastforce \n  apply (erule nth_nat_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_two])\n  subgoal premises p using p(63) by fastforce \n  apply (erule nth_nat_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_two])\n  subgoal premises p using p(65) by fastforce\n  apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_two])\n  subgoal premises p using p(67) by fastforce \n  apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_two])\n  subgoal premises p using p(69) by fastforce \n  apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_two])\n  subgoal premises p using p(71) by fastforce \n  apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_two])\n  subgoal premises p using p(73) by fastforce\n  apply (timeit \\<open>force simp:\n      push_on_stack_nat_imp_to_HOL_state_def cons_imp_to_HOL_state_def \n      nth_nat_imp_to_HOL_state_def Let_def\\<close>)\n  done\n\nparagraph if_else\n\ndefinition \"push_on_stack_nat_else s \\<equiv> \n  (let\n  cons_h' = push_on_stack_nat_n s;\n  cons_t' = 0;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  push_on_stack_nat_cons_res = cons_ret cons_ret_state;\n\n  nth_nat_n' = 1;\n  nth_nat_x' = push_on_stack_nat_c s;\n  nth_nat_ret' = 0;\n  nth_nat_state = \\<lparr>nth_nat_n = nth_nat_n', nth_nat_x = nth_nat_x', nth_nat_ret = nth_nat_ret'\\<rparr>;\n  nth_nat_ret_state = nth_nat_imp nth_nat_state;\n  push_on_stack_nat_nth_nat_ret_one = nth_nat_ret nth_nat_ret_state;\n\n  nth_nat_n' = 2;\n  nth_nat_x' = push_on_stack_nat_c s;\n  nth_nat_ret' = 0;\n  nth_nat_state = \\<lparr>nth_nat_n = nth_nat_n', nth_nat_x = nth_nat_x', nth_nat_ret = nth_nat_ret'\\<rparr>;\n  nth_nat_ret_state = nth_nat_imp nth_nat_state;\n\n  cons_h' = nth_nat_ret nth_nat_ret_state;\n  cons_t' = push_on_stack_nat_cons_res;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n\n  cons_h' = push_on_stack_nat_nth_nat_ret_one;\n  cons_t' = cons_ret cons_ret_state;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n\n  cons_h' = 9;\n  cons_t' = cons_ret cons_ret_state;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n\n  cons_h' = cons_ret cons_ret_state;\n  cons_t' = push_on_stack_nat_s s;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n\n  push_on_stack_nat_ret' = cons_ret cons_ret_state;\n  ret = \\<lparr>push_on_stack_nat_c = push_on_stack_nat_c s,\n        push_on_stack_nat_n = push_on_stack_nat_n s,\n        push_on_stack_nat_s = push_on_stack_nat_s s,\n        push_on_stack_nat_ret = push_on_stack_nat_ret'\\<rparr>\nin\n  ret)\"\n\nlemma push_on_stack_nat_else_imp_correct[let_function_correctness]:\n  \"push_on_stack_nat_ret (push_on_stack_nat_else s) = \n    (9## (nth_nat (Suc 0) (push_on_stack_nat_c s)) ## \n     (nth_nat (Suc (Suc 0)) (push_on_stack_nat_c s)) ##\n      (push_on_stack_nat_n s) ## 0)## (push_on_stack_nat_s s)\"\n  unfolding push_on_stack_nat_else_def\n  apply (simp add: nth_nat_imp_correct cons_imp_correct Let_def numeral_2_eq_2)\n  done\n\ndefinition \"push_on_stack_nat_else_time t s \\<equiv> \n  (let\n  cons_h' = push_on_stack_nat_n s;\n  t = t + 2;\n  cons_t' = 0;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n  push_on_stack_nat_cons_res = cons_ret cons_ret_state;\n  t = t + 2;\n\n  nth_nat_n' = 1;\n  t = t + 2;\n  nth_nat_x' = push_on_stack_nat_c s;\n  t = t + 2;\n  nth_nat_ret' = 0;\n  t = t + 2;\n  nth_nat_state = \\<lparr>nth_nat_n = nth_nat_n', nth_nat_x = nth_nat_x', nth_nat_ret = nth_nat_ret'\\<rparr>;\n  nth_nat_ret_state = nth_nat_imp nth_nat_state;\n  t = t + nth_nat_imp_time 0 nth_nat_state;\n  push_on_stack_nat_nth_nat_ret_one = nth_nat_ret nth_nat_ret_state;\n  t = t + 2;\n\n  nth_nat_n' = 2;\n  t = t + 2;\n  nth_nat_x' = push_on_stack_nat_c s;\n  t = t + 2;\n  nth_nat_ret' = 0;\n  t = t + 2;\n  nth_nat_state = \\<lparr>nth_nat_n = nth_nat_n', nth_nat_x = nth_nat_x', nth_nat_ret = nth_nat_ret'\\<rparr>;\n  nth_nat_ret_state = nth_nat_imp nth_nat_state;\n  t = t + nth_nat_imp_time 0 nth_nat_state;\n\n  cons_h' = nth_nat_ret nth_nat_ret_state;\n  t = t + 2;\n  cons_t' = push_on_stack_nat_cons_res;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n\n  cons_h' = push_on_stack_nat_nth_nat_ret_one;\n  t = t + 2;\n  cons_t' = cons_ret cons_ret_state;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n\n  cons_h' = 9;\n  t = t + 2;\n  cons_t' = cons_ret cons_ret_state;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n\n  cons_h' = cons_ret cons_ret_state;\n  t = t + 2;\n  cons_t' = push_on_stack_nat_s s;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n\n  push_on_stack_nat_ret' = cons_ret cons_ret_state;\n  t = t + 2;\n  ret = \\<lparr>push_on_stack_nat_c = push_on_stack_nat_c s,\n        push_on_stack_nat_n = push_on_stack_nat_n s,\n        push_on_stack_nat_s = push_on_stack_nat_s s,\n        push_on_stack_nat_ret = push_on_stack_nat_ret'\\<rparr>\nin\n  t)\"\n\ndefinition \"push_on_stack_nat_else_IMP_Minus \\<equiv>\n  (cons_prefix @ cons_h_str) ::= A (V push_on_stack_nat_n_str);;\n  (cons_prefix @ cons_t_str) ::= A (N 0);;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n  push_on_stack_nat_cons_res ::= A (V (cons_prefix @ cons_ret_str));;\n\n  (nth_nat_prefix @ nth_nat_n_str) ::= A (N 1);;\n  (nth_nat_prefix @ nth_nat_x_str) ::= A (V push_on_stack_nat_c_str);;\n  (nth_nat_prefix @ nth_nat_ret_str) ::= A (N 0);;\n  invoke_subprogram nth_nat_prefix nth_nat_IMP_Minus;;\n  push_on_stack_nat_nth_nat_ret_one ::= A (V (nth_nat_prefix @ nth_nat_ret_str));;\n\n  (nth_nat_prefix @ nth_nat_n_str) ::= A (N 2);;\n  (nth_nat_prefix @ nth_nat_x_str) ::= A (V push_on_stack_nat_c_str);;\n  (nth_nat_prefix @ nth_nat_ret_str) ::= A (N 0);;\n  invoke_subprogram nth_nat_prefix nth_nat_IMP_Minus;;\n\n  (cons_prefix @ cons_h_str) ::= A (V (nth_nat_prefix @ nth_nat_ret_str));;\n  (cons_prefix @ cons_t_str) ::= A (V push_on_stack_nat_cons_res);;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n\n  (cons_prefix @ cons_h_str) ::= A (V push_on_stack_nat_nth_nat_ret_one);;\n  (cons_prefix @ cons_t_str) ::= A (V (cons_prefix @ cons_ret_str));;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n\n  (cons_prefix @ cons_h_str) ::= A (N 9);;\n  (cons_prefix @ cons_t_str) ::= A (V (cons_prefix @ cons_ret_str));;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n\n  (cons_prefix @ cons_h_str) ::= A (V (cons_prefix @ cons_ret_str));;\n  (cons_prefix @ cons_t_str) ::= A (V push_on_stack_nat_s_str);;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n  push_on_stack_nat_ret_str ::= A (V (cons_prefix @ cons_ret_str))\n\"\n\nabbreviation \"push_on_stack_nat_IMP_vars_else \\<equiv> push_on_stack_nat_IMP_vars \n  \\<union> {push_on_stack_nat_nth_nat_ret_one, push_on_stack_nat_cons_res}\"\n\nlemma push_on_stack_nat_else_IMP_Minus_correct_function:\n  \"(invoke_subprogram p push_on_stack_nat_else_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p push_on_stack_nat_ret_str)\n      = push_on_stack_nat_ret\n          (push_on_stack_nat_else (push_on_stack_nat_imp_to_HOL_state p s))\"\n   apply (subst push_on_stack_nat_else_def)\n   apply (simp only: push_on_stack_nat_else_IMP_Minus_def prefix_simps)\n   apply (erule Seq_E)+\n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_else])\n   subgoal premises p using p(31) by fastforce \n   apply (erule nth_nat_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_else])\n   subgoal premises p using p(33) by fastforce \n   apply (erule nth_nat_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_else])\n   subgoal premises p using p(35) by fastforce\n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_else])\n   subgoal premises p using p(37) by fastforce \n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_else])\n   subgoal premises p using p(39) by fastforce \n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_else])\n   subgoal premises p using p(41) by fastforce \n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_else])\n   subgoal premises p using p(43) by fastforce\n   apply (timeit \\<open>force simp:\n      push_on_stack_nat_imp_to_HOL_state_def cons_imp_to_HOL_state_def \n      nth_nat_imp_to_HOL_state_def Let_def\\<close>)\n   done\n\n\nlemma push_on_stack_nat_else_IMP_Minus_correct_time:\n  \"(invoke_subprogram p push_on_stack_nat_else_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = push_on_stack_nat_else_time 0 (push_on_stack_nat_imp_to_HOL_state p s)\"\n  apply (subst push_on_stack_nat_else_time_def)\n  apply (simp only: push_on_stack_nat_else_IMP_Minus_def prefix_simps)\n  apply (erule Seq_tE)+\n  apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_else])\n  subgoal premises p using p(61) by fastforce \n  apply (erule nth_nat_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_else])\n  subgoal premises p using p(63) by fastforce \n  apply (erule nth_nat_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_else])\n  subgoal premises p using p(65) by fastforce\n  apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_else])\n  subgoal premises p using p(67) by fastforce \n  apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_else])\n  subgoal premises p using p(69) by fastforce \n  apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_else])\n  subgoal premises p using p(71) by fastforce \n  apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_else])\n  subgoal premises p using p(73) by fastforce\n  apply (timeit \\<open>force simp:\n      push_on_stack_nat_imp_to_HOL_state_def cons_imp_to_HOL_state_def \n      nth_nat_imp_to_HOL_state_def Let_def\\<close>)\n  done\n\nparagraph if_eq_three\n\ndefinition \"push_on_stack_nat_eq_three s \\<equiv> \n  (let\n  cons_h' = push_on_stack_nat_n s;\n  cons_t' = 0;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  push_on_stack_nat_cons_res = cons_ret cons_ret_state;\n\n  nth_nat_n' = 1;\n  nth_nat_x' = push_on_stack_nat_c s;\n  nth_nat_ret' = 0;\n  nth_nat_state = \\<lparr>nth_nat_n = nth_nat_n', nth_nat_x = nth_nat_x', nth_nat_ret = nth_nat_ret'\\<rparr>;\n  nth_nat_ret_state = nth_nat_imp nth_nat_state;\n  push_on_stack_nat_nth_nat_ret_one = nth_nat_ret nth_nat_ret_state;\n\n  nth_nat_n' = 2;\n  nth_nat_x' = push_on_stack_nat_c s;\n  nth_nat_ret' = 0;\n  nth_nat_state = \\<lparr>nth_nat_n = nth_nat_n', nth_nat_x = nth_nat_x', nth_nat_ret = nth_nat_ret'\\<rparr>;\n  nth_nat_ret_state = nth_nat_imp nth_nat_state;\n  push_on_stack_nat_nth_nat_ret_two = nth_nat_ret nth_nat_ret_state;\n  \n  nth_nat_n' = 3;\n  nth_nat_x' = push_on_stack_nat_c s;\n  nth_nat_ret' = 0;\n  nth_nat_state = \\<lparr>nth_nat_n = nth_nat_n', nth_nat_x = nth_nat_x', nth_nat_ret = nth_nat_ret'\\<rparr>;\n  nth_nat_ret_state = nth_nat_imp nth_nat_state;\n\n  cons_h' = nth_nat_ret nth_nat_ret_state;\n  cons_t' = push_on_stack_nat_cons_res;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n\n  cons_h' = push_on_stack_nat_nth_nat_ret_two;\n  cons_t' = cons_ret cons_ret_state;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n\n  cons_h' = push_on_stack_nat_nth_nat_ret_one;\n  cons_t' = cons_ret cons_ret_state;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n\n  cons_h' = 6;\n  cons_t' = cons_ret cons_ret_state;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n\n  cons_h' = cons_ret cons_ret_state;\n  cons_t' = push_on_stack_nat_s s;\n  cons_ret' = 0;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n\n  push_on_stack_nat_ret' = cons_ret cons_ret_state;\n  ret = \\<lparr>push_on_stack_nat_c = push_on_stack_nat_c s,\n        push_on_stack_nat_n = push_on_stack_nat_n s,\n        push_on_stack_nat_s = push_on_stack_nat_s s,\n        push_on_stack_nat_ret = push_on_stack_nat_ret'\\<rparr>\nin\n  ret)\"\n\nlemma push_on_stack_nat_eq_three_imp_correct[let_function_correctness]:\n  \"push_on_stack_nat_ret (push_on_stack_nat_eq_three s) = \n    (6## (nth_nat (Suc 0) (push_on_stack_nat_c s)) ## \n     (nth_nat (Suc (Suc 0)) (push_on_stack_nat_c s)) ##\n     (nth_nat (Suc (Suc (Suc 0))) (push_on_stack_nat_c s)) ##\n      (push_on_stack_nat_n s) ## 0)## (push_on_stack_nat_s s)\"\n  unfolding push_on_stack_nat_eq_three_def\n  apply (simp add: nth_nat_imp_correct cons_imp_correct Let_def numeral_2_eq_2 numeral_3_eq_3)\n  done\n\ndefinition \"push_on_stack_nat_eq_three_time t s \\<equiv> \n  (let\n  cons_h' = push_on_stack_nat_n s;\n  t = t + 2;\n  cons_t' = 0;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n  push_on_stack_nat_cons_res = cons_ret cons_ret_state;\n  t = t + 2;\n\n  nth_nat_n' = 1;\n  t = t + 2;\n  nth_nat_x' = push_on_stack_nat_c s;\n  t = t + 2;\n  nth_nat_ret' = 0;\n  t = t + 2;\n  nth_nat_state = \\<lparr>nth_nat_n = nth_nat_n', nth_nat_x = nth_nat_x', nth_nat_ret = nth_nat_ret'\\<rparr>;\n  nth_nat_ret_state = nth_nat_imp nth_nat_state;\n  t = t + nth_nat_imp_time 0 nth_nat_state;\n  push_on_stack_nat_nth_nat_ret_one = nth_nat_ret nth_nat_ret_state;\n  t = t + 2;\n\n  nth_nat_n' = 2;\n  t = t + 2;\n  nth_nat_x' = push_on_stack_nat_c s;\n  t = t + 2;\n  nth_nat_ret' = 0;\n  t = t + 2;\n  nth_nat_state = \\<lparr>nth_nat_n = nth_nat_n', nth_nat_x = nth_nat_x', nth_nat_ret = nth_nat_ret'\\<rparr>;\n  nth_nat_ret_state = nth_nat_imp nth_nat_state;\n  t = t + nth_nat_imp_time 0 nth_nat_state;\n  push_on_stack_nat_nth_nat_ret_two = nth_nat_ret nth_nat_ret_state;\n  t = t + 2;\n  \n  nth_nat_n' = 3;\n  t = t + 2;\n  nth_nat_x' = push_on_stack_nat_c s;\n  t = t + 2;\n  nth_nat_ret' = 0;\n  t = t + 2;\n  nth_nat_state = \\<lparr>nth_nat_n = nth_nat_n', nth_nat_x = nth_nat_x', nth_nat_ret = nth_nat_ret'\\<rparr>;\n  nth_nat_ret_state = nth_nat_imp nth_nat_state;\n  t = t + nth_nat_imp_time 0 nth_nat_state;\n\n  cons_h' = nth_nat_ret nth_nat_ret_state;\n  t = t + 2;\n  cons_t' = push_on_stack_nat_cons_res;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n\n  cons_h' = push_on_stack_nat_nth_nat_ret_two;\n  t = t + 2;\n  cons_t' = cons_ret cons_ret_state;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n\n  cons_h' = push_on_stack_nat_nth_nat_ret_one;\n  t = t + 2;\n  cons_t' = cons_ret cons_ret_state;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n\n  cons_h' = 6;\n  t = t + 2;\n  cons_t' = cons_ret cons_ret_state;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n\n  cons_h' = cons_ret cons_ret_state;\n  t = t + 2;\n  cons_t' = push_on_stack_nat_s s;\n  t = t + 2;\n  cons_ret' = 0;\n  t = t + 2;\n  cons_state = \\<lparr>cons_h = cons_h', cons_t = cons_t', cons_ret = cons_ret'\\<rparr>;\n  cons_ret_state = cons_imp cons_state;\n  t = t + cons_imp_time 0 cons_state;\n\n  push_on_stack_nat_ret' = cons_ret cons_ret_state;\n  t = t + 2;\n  ret = \\<lparr>push_on_stack_nat_c = push_on_stack_nat_c s,\n        push_on_stack_nat_n = push_on_stack_nat_n s,\n        push_on_stack_nat_s = push_on_stack_nat_s s,\n        push_on_stack_nat_ret = push_on_stack_nat_ret'\\<rparr>\nin\n  t)\"\n\ndefinition \"push_on_stack_nat_eq_three_IMP_Minus \\<equiv>\n  (cons_prefix @ cons_h_str) ::= A (V push_on_stack_nat_n_str);;\n  (cons_prefix @ cons_t_str) ::= A (N 0);;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n  push_on_stack_nat_cons_res ::= A (V (cons_prefix @ cons_ret_str));;\n\n  (nth_nat_prefix @ nth_nat_n_str) ::= A (N 1);;\n  (nth_nat_prefix @ nth_nat_x_str) ::= A (V push_on_stack_nat_c_str);;\n  (nth_nat_prefix @ nth_nat_ret_str) ::= A (N 0);;\n  invoke_subprogram nth_nat_prefix nth_nat_IMP_Minus;;\n  push_on_stack_nat_nth_nat_ret_one ::= A (V (nth_nat_prefix @ nth_nat_ret_str));;\n\n  (nth_nat_prefix @ nth_nat_n_str) ::= A (N 2);;\n  (nth_nat_prefix @ nth_nat_x_str) ::= A (V push_on_stack_nat_c_str);;\n  (nth_nat_prefix @ nth_nat_ret_str) ::= A (N 0);;\n  invoke_subprogram nth_nat_prefix nth_nat_IMP_Minus;;\n  push_on_stack_nat_nth_nat_ret_two ::= A (V (nth_nat_prefix @ nth_nat_ret_str));;\n\n  (nth_nat_prefix @ nth_nat_n_str) ::= A (N 3);;\n  (nth_nat_prefix @ nth_nat_x_str) ::= A (V push_on_stack_nat_c_str);;\n  (nth_nat_prefix @ nth_nat_ret_str) ::= A (N 0);;\n  invoke_subprogram nth_nat_prefix nth_nat_IMP_Minus;;\n\n  (cons_prefix @ cons_h_str) ::= A (V (nth_nat_prefix @ nth_nat_ret_str));;\n  (cons_prefix @ cons_t_str) ::= A (V push_on_stack_nat_cons_res);;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n\n  (cons_prefix @ cons_h_str) ::= A (V push_on_stack_nat_nth_nat_ret_two);;\n  (cons_prefix @ cons_t_str) ::= A (V (cons_prefix @ cons_ret_str));;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n\n  (cons_prefix @ cons_h_str) ::= A (V push_on_stack_nat_nth_nat_ret_one);;\n  (cons_prefix @ cons_t_str) ::= A (V (cons_prefix @ cons_ret_str));;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n\n  (cons_prefix @ cons_h_str) ::= A (N 6);;\n  (cons_prefix @ cons_t_str) ::= A (V (cons_prefix @ cons_ret_str));;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n\n  (cons_prefix @ cons_h_str) ::= A (V (cons_prefix @ cons_ret_str));;\n  (cons_prefix @ cons_t_str) ::= A (V push_on_stack_nat_s_str);;\n  (cons_prefix @ cons_ret_str) ::= A (N 0);;\n  invoke_subprogram cons_prefix cons_IMP_Minus;;\n  push_on_stack_nat_ret_str ::= A (V (cons_prefix @ cons_ret_str))\n\"\n\nabbreviation \"push_on_stack_nat_IMP_vars_eq_three \\<equiv> push_on_stack_nat_IMP_vars \n  \\<union> {push_on_stack_nat_nth_nat_ret_one, push_on_stack_nat_nth_nat_ret_two, \n     push_on_stack_nat_cons_res}\"\n\nlemma push_on_stack_nat_eq_three_IMP_Minus_correct_function:\n  \"(invoke_subprogram p push_on_stack_nat_eq_three_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p push_on_stack_nat_ret_str)\n      = push_on_stack_nat_ret\n          (push_on_stack_nat_eq_three (push_on_stack_nat_imp_to_HOL_state p s))\"\n   apply (subst push_on_stack_nat_eq_three_def)\n   apply (simp only: push_on_stack_nat_eq_three_IMP_Minus_def prefix_simps)\n   apply (erule Seq_E)+\n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_three])\n   subgoal premises p using p(40) by fastforce \n   apply (erule nth_nat_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_three])\n   subgoal premises p using p(42) by fastforce \n   apply (erule nth_nat_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_three])\n   subgoal premises p using p(44) by fastforce\n   apply (erule nth_nat_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_three])\n   subgoal premises p using p(46) by fastforce\n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_three])\n   subgoal premises p using p(48) by fastforce \n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_three])\n   subgoal premises p using p(50) by fastforce \n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_three])\n   subgoal premises p using p(52) by fastforce \n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_three])\n   subgoal premises p using p(54) by fastforce\n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_three])\n   subgoal premises p using p(56) by fastforce\n   apply (timeit \\<open>force simp:\n      push_on_stack_nat_imp_to_HOL_state_def cons_imp_to_HOL_state_def \n      nth_nat_imp_to_HOL_state_def Let_def\\<close>)\n   done \n\n\nlemma push_on_stack_nat_eq_three_IMP_Minus_correct_time:\n  \"(invoke_subprogram p push_on_stack_nat_eq_three_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = push_on_stack_nat_eq_three_time 0 (push_on_stack_nat_imp_to_HOL_state p s)\"\n  apply (subst push_on_stack_nat_eq_three_time_def)\n  apply (simp only: push_on_stack_nat_eq_three_IMP_Minus_def prefix_simps)\n  apply (erule Seq_tE)+\n  apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_three])\n   subgoal premises p using p(79) by fastforce \n   apply (erule nth_nat_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_three])\n   subgoal premises p using p(81) by fastforce \n   apply (erule nth_nat_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_three])\n   subgoal premises p using p(83) by fastforce\n   apply (erule nth_nat_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_three])\n   subgoal premises p using p(85) by fastforce\n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_three])\n   subgoal premises p using p(87) by fastforce \n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_three])\n   subgoal premises p using p(89) by fastforce \n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_three])\n   subgoal premises p using p(91) by fastforce \n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_three])\n   subgoal premises p using p(93) by fastforce\n   apply (erule cons_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars_eq_three])\n   subgoal premises p using p(95) by fastforce\n  apply (force simp: \n      push_on_stack_nat_imp_to_HOL_state_def cons_imp_to_HOL_state_def \n      nth_nat_imp_to_HOL_state_def Let_def)\n  done\n\nparagraph separations_of_nested_ifs\n\ndefinition  \"push_on_stack_nat_sub_branch_aux1 s \\<equiv> \n       (let\n          hd_xs' = push_on_stack_nat_c s;\n          hd_ret' = 0;\n          hd_state = \\<lparr>hd_xs = hd_xs', hd_ret = hd_ret'\\<rparr>;\n          hd_ret_state = hd_imp hd_state;\n          push_on_stack_nat_hd_c = hd_ret hd_ret_state;\n          NOTEQUAL_neq_zero_a' = push_on_stack_nat_hd_c;\n          NOTEQUAL_neq_zero_b' = 2;\n          NOTEQUAL_neq_zero_ret' = 0;\n          NOTEQUAL_neq_zero_state = \\<lparr>NOTEQUAL_neq_zero_a = NOTEQUAL_neq_zero_a',\n                                    NOTEQUAL_neq_zero_b = NOTEQUAL_neq_zero_b',\n                                    NOTEQUAL_neq_zero_ret = NOTEQUAL_neq_zero_ret'\\<rparr>;\n          NOTEQUAL_neq_zero_ret_state = NOTEQUAL_neq_zero_imp NOTEQUAL_neq_zero_state;\n          push_on_stack_nat_cond_three = (NOTEQUAL_neq_zero_ret NOTEQUAL_neq_zero_ret_state)\n        in \n          (if push_on_stack_nat_cond_three \\<noteq> 0\n                then push_on_stack_nat_else s\n                else push_on_stack_nat_eq_two s))\"\n\nlemma push_on_stack_nat_sub_branch_aux1_imp_correct:\n  \"push_on_stack_nat_ret (push_on_stack_nat_sub_branch_aux1 s) = \n    (if (hd_nat (push_on_stack_nat_c s)) \\<noteq>2\n           then (9## (nth_nat (Suc 0) (push_on_stack_nat_c s)) ## \n     (nth_nat (Suc (Suc 0)) (push_on_stack_nat_c s)) ##\n      (push_on_stack_nat_n s) ## 0)## (push_on_stack_nat_s s)\n           else (3## (nth_nat (Suc 0) (push_on_stack_nat_c s)) ## \n     (nth_nat (Suc (Suc 0)) (push_on_stack_nat_c s)) ##\n      (push_on_stack_nat_n s) ## 0)## (push_on_stack_nat_s s))\"\n  apply (subst push_on_stack_nat_sub_branch_aux1_def)\n  apply (simp add: NOTEQUAL_neq_zero_imp_correct hd_imp_correct\n   push_on_stack_nat_eq_one_imp_correct push_on_stack_nat_eq_two_imp_correct\n   push_on_stack_nat_else_imp_correct\n   Let_def)\n  done\n\ndefinition \"push_on_stack_nat_sub_branch_aux1_IMP_Minus \\<equiv>\n  (hd_prefix @ hd_xs_str) ::= A (V push_on_stack_nat_c_str);;\n  (hd_prefix @ hd_ret_str) ::= A (N 0);;\n  invoke_subprogram hd_prefix hd_IMP_Minus;;\n  push_on_stack_nat_hd_c ::= A (V (hd_prefix @ hd_ret_str));;\n  (NOTEQUAL_neq_zero_prefix @ NOTEQUAL_neq_zero_a_str) ::= A (V push_on_stack_nat_hd_c);;\n  (NOTEQUAL_neq_zero_prefix @ NOTEQUAL_neq_zero_b_str) ::= A (N 2);;\n  (NOTEQUAL_neq_zero_prefix @ NOTEQUAL_neq_zero_ret_str) ::= A (N 0);;\n  invoke_subprogram NOTEQUAL_neq_zero_prefix NOTEQUAL_neq_zero_IMP_Minus;;\n  push_on_stack_nat_cond_three ::= A (V (NOTEQUAL_neq_zero_prefix @ NOTEQUAL_neq_zero_ret_str));;\n  (IF push_on_stack_nat_cond_three \\<noteq>0\n    THEN push_on_stack_nat_else_IMP_Minus\n    ELSE push_on_stack_nat_eq_two_IMP_Minus)\n  \"\ndefinition \"push_on_stack_nat_sub_branch_aux1_time t s \\<equiv> \n    (let\n       hd_xs' = push_on_stack_nat_c s;\n       t = t + 2;\n       hd_ret' = 0;\n       t = t + 2;\n       hd_state = \\<lparr>hd_xs = hd_xs', hd_ret = hd_ret'\\<rparr>;\n       hd_ret_state = hd_imp hd_state;\n       t = t + hd_imp_time 0 hd_state;\n       push_on_stack_nat_hd_c = hd_ret hd_ret_state;\n       t = t + 2;\n       NOTEQUAL_neq_zero_a' = push_on_stack_nat_hd_c;\n       t = t + 2;\n       NOTEQUAL_neq_zero_b' = 2;\n       t = t + 2;\n       NOTEQUAL_neq_zero_ret' = 0;\n       t = t + 2;\n       NOTEQUAL_neq_zero_state = \\<lparr>NOTEQUAL_neq_zero_a = NOTEQUAL_neq_zero_a',\n                                 NOTEQUAL_neq_zero_b = NOTEQUAL_neq_zero_b',\n                                 NOTEQUAL_neq_zero_ret = NOTEQUAL_neq_zero_ret'\\<rparr>;\n       NOTEQUAL_neq_zero_ret_state = NOTEQUAL_neq_zero_imp NOTEQUAL_neq_zero_state;\n       t = t + NOTEQUAL_neq_zero_imp_time 0 NOTEQUAL_neq_zero_state;\n       push_on_stack_nat_cond_three = (NOTEQUAL_neq_zero_ret NOTEQUAL_neq_zero_ret_state);\n       t = t + 2\n       in (if push_on_stack_nat_cond_three \\<noteq> 0\n                then \n                let\n                 t = t + 1;\n                 t = t + push_on_stack_nat_else_time 0 s\n                in\n                 t\n                else \n                let\n                 t = t + 1;\n                 t = t + push_on_stack_nat_eq_two_time 0 s\n                in\n                 t))\"\n\nlemma push_on_stack_nat_sub_branch_aux1_IMP_Minus_correct_function:\n  \"(invoke_subprogram p push_on_stack_nat_sub_branch_aux1_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p push_on_stack_nat_ret_str)\n      = push_on_stack_nat_ret\n          (push_on_stack_nat_sub_branch_aux1 (push_on_stack_nat_imp_to_HOL_state p s))\"\n  apply (subst push_on_stack_nat_sub_branch_aux1_def)\n  apply (simp only: push_on_stack_nat_sub_branch_aux1_IMP_Minus_def prefix_simps)\n  apply (erule Seq_E)+\n  apply (erule hd_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars])\n  subgoal premises p using p(10) by fastforce\n  apply (erule NOTEQUAL_neq_zero_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars])\n  subgoal premises p using p(12) by fastforce\n  apply (erule If_E)\n    subgoal\n      apply (force dest!: push_on_stack_nat_else_IMP_Minus_correct_function \n      simp: push_on_stack_nat_imp_to_HOL_state_def NOTEQUAL_neq_zero_imp_to_HOL_state_def\n          hd_imp_to_HOL_state_def Let_def)\n    done \n    subgoal\n     apply (force dest!: push_on_stack_nat_eq_two_IMP_Minus_correct_function \n      simp: push_on_stack_nat_imp_to_HOL_state_def NOTEQUAL_neq_zero_imp_to_HOL_state_def\n          hd_imp_to_HOL_state_def Let_def)\n    done\n  done\n\nlemma push_on_stack_nat_sub_branch_aux1_IMP_Minus_correct_time:\n  \"(invoke_subprogram p push_on_stack_nat_sub_branch_aux1_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n    t = push_on_stack_nat_sub_branch_aux1_time 0 \n           (push_on_stack_nat_imp_to_HOL_state p s)\"\n  apply (subst push_on_stack_nat_sub_branch_aux1_time_def)\n  apply (simp only: push_on_stack_nat_sub_branch_aux1_IMP_Minus_def prefix_simps)\n  apply (erule Seq_tE)+\n  apply (erule hd_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars])\n  subgoal premises p using p(19) by fastforce\n  apply (erule NOTEQUAL_neq_zero_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars])\n  subgoal premises p using p(21) by fastforce\n  apply (erule If_tE)\n    subgoal\n      apply (force dest!: push_on_stack_nat_else_IMP_Minus_correct_time\n      simp: push_on_stack_nat_imp_to_HOL_state_def NOTEQUAL_neq_zero_imp_to_HOL_state_def\n          hd_imp_to_HOL_state_def Let_def)\n    done \n    subgoal\n     apply (force dest!: push_on_stack_nat_eq_two_IMP_Minus_correct_time \n      simp: push_on_stack_nat_imp_to_HOL_state_def NOTEQUAL_neq_zero_imp_to_HOL_state_def\n          hd_imp_to_HOL_state_def Let_def)\n    done\n  done\n\n  definition \"push_on_stack_nat_sub_branch_aux2 s \\<equiv> \n    (let\n       hd_xs' = push_on_stack_nat_c s;\n       hd_ret' = 0;\n       hd_state = \\<lparr>hd_xs = hd_xs', hd_ret = hd_ret'\\<rparr>;\n       hd_ret_state = hd_imp hd_state;\n       push_on_stack_nat_hd_c = hd_ret hd_ret_state;\n       NOTEQUAL_neq_zero_a' = push_on_stack_nat_hd_c;\n       NOTEQUAL_neq_zero_b' = 1;\n       NOTEQUAL_neq_zero_ret' = 0;\n       NOTEQUAL_neq_zero_state = \\<lparr>NOTEQUAL_neq_zero_a = NOTEQUAL_neq_zero_a',\n                                 NOTEQUAL_neq_zero_b = NOTEQUAL_neq_zero_b',\n                                 NOTEQUAL_neq_zero_ret = NOTEQUAL_neq_zero_ret'\\<rparr>;\n       NOTEQUAL_neq_zero_ret_state = NOTEQUAL_neq_zero_imp NOTEQUAL_neq_zero_state;\n       push_on_stack_nat_cond_two = (NOTEQUAL_neq_zero_ret NOTEQUAL_neq_zero_ret_state)\n       in (if push_on_stack_nat_cond_two \\<noteq> 0\n          then push_on_stack_nat_sub_branch_aux1 s\n          else push_on_stack_nat_eq_one s))\"\n\n\nlemma push_on_stack_nat_sub_branch_aux2_imp_correct:\n  \"push_on_stack_nat_ret (push_on_stack_nat_sub_branch_aux2 s) = \n    (if (hd_nat (push_on_stack_nat_c s)) \\<noteq>1\n     then (if (hd_nat (push_on_stack_nat_c s)) \\<noteq>2\n           then (9## (nth_nat (Suc 0) (push_on_stack_nat_c s)) ## \n     (nth_nat (Suc (Suc 0)) (push_on_stack_nat_c s)) ##\n      (push_on_stack_nat_n s) ## 0)## (push_on_stack_nat_s s)\n           else (3## (nth_nat (Suc 0) (push_on_stack_nat_c s)) ## \n     (nth_nat (Suc (Suc 0)) (push_on_stack_nat_c s)) ##\n      (push_on_stack_nat_n s) ## 0)## (push_on_stack_nat_s s))\n     else (2## (nth_nat (Suc 0) (push_on_stack_nat_c s)) ## \n     (nth_nat (Suc (Suc 0)) (push_on_stack_nat_c s)) ##\n      (push_on_stack_nat_n s) ## 0)## (push_on_stack_nat_s s))\"\n  apply (subst push_on_stack_nat_sub_branch_aux2_def)\n  apply (simp add: NOTEQUAL_neq_zero_imp_correct hd_imp_correct\n   push_on_stack_nat_eq_one_imp_correct push_on_stack_nat_eq_two_imp_correct\n   push_on_stack_nat_else_imp_correct push_on_stack_nat_sub_branch_aux1_imp_correct\n   Let_def)\n  done\n\ndefinition \"push_on_stack_nat_sub_branch_aux2_IMP_Minus \\<equiv>\n  (hd_prefix @ hd_xs_str) ::= A (V push_on_stack_nat_c_str);;\n  (hd_prefix @ hd_ret_str) ::= A (N 0);;\n  invoke_subprogram hd_prefix hd_IMP_Minus;;\n  push_on_stack_nat_hd_c ::= A (V (hd_prefix @ hd_ret_str));;\n  (NOTEQUAL_neq_zero_prefix @ NOTEQUAL_neq_zero_a_str) ::= A (V push_on_stack_nat_hd_c);;\n  (NOTEQUAL_neq_zero_prefix @ NOTEQUAL_neq_zero_b_str) ::= A (N 1);;\n  (NOTEQUAL_neq_zero_prefix @ NOTEQUAL_neq_zero_ret_str) ::= A (N 0);;\n  invoke_subprogram NOTEQUAL_neq_zero_prefix NOTEQUAL_neq_zero_IMP_Minus;;\n  push_on_stack_nat_cond_two ::= A (V (NOTEQUAL_neq_zero_prefix @ NOTEQUAL_neq_zero_ret_str));;\n  (IF push_on_stack_nat_cond_two \\<noteq>0\n  THEN push_on_stack_nat_sub_branch_aux1_IMP_Minus\n  ELSE push_on_stack_nat_eq_one_IMP_Minus)\"\n\n\nlemma push_on_stack_nat_sub_branch_aux2_IMP_Minus_correct_function:\n  \"(invoke_subprogram p push_on_stack_nat_sub_branch_aux2_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p push_on_stack_nat_ret_str)\n      = push_on_stack_nat_ret\n          (push_on_stack_nat_sub_branch_aux2 (push_on_stack_nat_imp_to_HOL_state p s))\"\n  apply (subst push_on_stack_nat_sub_branch_aux2_def)\n  apply (simp only: push_on_stack_nat_sub_branch_aux2_IMP_Minus_def prefix_simps)\n  apply (erule Seq_E)+\n  apply (erule hd_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars])\n  subgoal premises p using p(10) by fastforce\n  apply (erule NOTEQUAL_neq_zero_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars])\n  subgoal premises p using p(12) by fastforce\n  apply (erule If_E)\n    subgoal \n      apply (force dest!: push_on_stack_nat_sub_branch_aux1_IMP_Minus_correct_function \n      simp: push_on_stack_nat_imp_to_HOL_state_def NOTEQUAL_neq_zero_imp_to_HOL_state_def\n      hd_imp_to_HOL_state_def Let_def)\n    done \n    subgoal \n    apply (force dest!: push_on_stack_nat_eq_one_IMP_Minus_correct_function \n      simp: push_on_stack_nat_imp_to_HOL_state_def NOTEQUAL_neq_zero_imp_to_HOL_state_def\n      hd_imp_to_HOL_state_def Let_def)\n    done\n  done\n\ndefinition \"push_on_stack_nat_sub_branch_aux2_time t s \\<equiv> \n    (let\n       hd_xs' = push_on_stack_nat_c s;\n       t = t + 2;\n       hd_ret' = 0;\n       t = t + 2;\n       hd_state = \\<lparr>hd_xs = hd_xs', hd_ret = hd_ret'\\<rparr>;\n       hd_ret_state = hd_imp hd_state;\n       t = t + hd_imp_time 0 hd_state;\n       push_on_stack_nat_hd_c = hd_ret hd_ret_state;\n       t = t + 2;\n       NOTEQUAL_neq_zero_a' = push_on_stack_nat_hd_c;\n       t = t + 2;\n       NOTEQUAL_neq_zero_b' = 1;\n       t = t + 2;\n       NOTEQUAL_neq_zero_ret' = 0;\n       t = t + 2;\n       NOTEQUAL_neq_zero_state = \\<lparr>NOTEQUAL_neq_zero_a = NOTEQUAL_neq_zero_a',\n                                 NOTEQUAL_neq_zero_b = NOTEQUAL_neq_zero_b',\n                                 NOTEQUAL_neq_zero_ret = NOTEQUAL_neq_zero_ret'\\<rparr>;\n       NOTEQUAL_neq_zero_ret_state = NOTEQUAL_neq_zero_imp NOTEQUAL_neq_zero_state;\n       t = t + NOTEQUAL_neq_zero_imp_time 0 NOTEQUAL_neq_zero_state;\n       push_on_stack_nat_cond_two = (NOTEQUAL_neq_zero_ret NOTEQUAL_neq_zero_ret_state);\n       t = t + 2\n       in (if push_on_stack_nat_cond_two \\<noteq> 0\n          then \n            (let \n             t = t + 1;\n             t = t + push_on_stack_nat_sub_branch_aux1_time 0 s\n            in \n             t)\n          else \n          let \n           t = t + 1;\n           t = t + push_on_stack_nat_eq_one_time 0 s\n          in\n           t))\"\n\nlemma push_on_stack_nat_sub_branch_aux2_IMP_Minus_correct_time:\n  \"(invoke_subprogram p push_on_stack_nat_sub_branch_aux2_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = push_on_stack_nat_sub_branch_aux2_time 0 \n           (push_on_stack_nat_imp_to_HOL_state p s)\"\n  apply (subst push_on_stack_nat_sub_branch_aux2_time_def)\n  apply (simp only: push_on_stack_nat_sub_branch_aux2_IMP_Minus_def prefix_simps)\n  apply (erule Seq_tE)+\n  apply (erule hd_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars])\n  subgoal premises p using p(19) by fastforce\n  apply (erule NOTEQUAL_neq_zero_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars])\n  subgoal premises p using p(21) by fastforce\n  apply (erule If_tE)\n    subgoal \n    apply (force dest!: push_on_stack_nat_sub_branch_aux1_IMP_Minus_correct_time simp:\n            push_on_stack_nat_imp_to_HOL_state_def NOTEQUAL_neq_zero_imp_to_HOL_state_def Let_def\n            hd_imp_to_HOL_state_def)\n    done\n    subgoal \n    apply (force dest!: push_on_stack_nat_eq_one_IMP_Minus_correct_time simp:\n            push_on_stack_nat_imp_to_HOL_state_def NOTEQUAL_neq_zero_imp_to_HOL_state_def Let_def\n            hd_imp_to_HOL_state_def)\n    done\n  done\n\ndefinition \"push_on_stack_nat_sub_branch_aux3 s \\<equiv> \n(let\n  hd_xs' = push_on_stack_nat_c s;\n  hd_ret' = 0;\n  hd_state = \\<lparr>hd_xs = hd_xs', hd_ret = hd_ret'\\<rparr>;\n  hd_ret_state = hd_imp hd_state;\n  push_on_stack_nat_hd_c = hd_ret hd_ret_state;\n  NOTEQUAL_neq_zero_a' = push_on_stack_nat_hd_c;\n  NOTEQUAL_neq_zero_b' = 3;\n  NOTEQUAL_neq_zero_ret' = 0;\n  NOTEQUAL_neq_zero_state = \\<lparr>NOTEQUAL_neq_zero_a = NOTEQUAL_neq_zero_a',\n                            NOTEQUAL_neq_zero_b = NOTEQUAL_neq_zero_b',\n                            NOTEQUAL_neq_zero_ret = NOTEQUAL_neq_zero_ret'\\<rparr>;\n  NOTEQUAL_neq_zero_ret_state = NOTEQUAL_neq_zero_imp NOTEQUAL_neq_zero_state;\n  push_on_stack_nat_cond_one = (NOTEQUAL_neq_zero_ret NOTEQUAL_neq_zero_ret_state)\n in\n  (if push_on_stack_nat_cond_one \\<noteq> 0\n      then (push_on_stack_nat_sub_branch_aux2 s)\n      else push_on_stack_nat_eq_three s))\"\n\nlemma push_on_stack_nat_sub_branch_aux3_imp_correct:\n   \"push_on_stack_nat_ret (push_on_stack_nat_sub_branch_aux3 s) =\n    (if (hd_nat (push_on_stack_nat_c s)) \\<noteq>3 \n    then (if (hd_nat (push_on_stack_nat_c s)) \\<noteq>1\n     then (if (hd_nat (push_on_stack_nat_c s)) \\<noteq>2\n           then (9## (nth_nat (Suc 0) (push_on_stack_nat_c s)) ## \n     (nth_nat (Suc (Suc 0)) (push_on_stack_nat_c s)) ##\n      (push_on_stack_nat_n s) ## 0)## (push_on_stack_nat_s s)\n           else (3## (nth_nat (Suc 0) (push_on_stack_nat_c s)) ## \n     (nth_nat (Suc (Suc 0)) (push_on_stack_nat_c s)) ##\n      (push_on_stack_nat_n s) ## 0)## (push_on_stack_nat_s s))\n     else (2## (nth_nat (Suc 0) (push_on_stack_nat_c s)) ## \n     (nth_nat (Suc (Suc 0)) (push_on_stack_nat_c s)) ##\n      (push_on_stack_nat_n s) ## 0)## (push_on_stack_nat_s s))\n    else (6## (nth_nat (Suc 0) (push_on_stack_nat_c s)) ## \n       (nth_nat (Suc (Suc 0))(push_on_stack_nat_c s)) ## \n       (nth_nat (Suc (Suc (Suc 0))) (push_on_stack_nat_c s)) \n       ## (push_on_stack_nat_n s)  ## 0) ## (push_on_stack_nat_s s)\n    )\"\n  apply (subst push_on_stack_nat_sub_branch_aux3_def)\n  apply (simp add: NOTEQUAL_neq_zero_imp_correct hd_imp_correct\n   push_on_stack_nat_eq_three_imp_correct push_on_stack_nat_sub_branch_aux2_imp_correct\n   Let_def)\n  done\n\ndefinition \"push_on_stack_nat_sub_branch_aux3_IMP_Minus \\<equiv> \n  (hd_prefix @ hd_xs_str) ::= A (V push_on_stack_nat_c_str);;\n  (hd_prefix @ hd_ret_str) ::= A (N 0);;\n  invoke_subprogram hd_prefix hd_IMP_Minus;;\n  push_on_stack_nat_hd_c ::= A (V (hd_prefix @ hd_ret_str));;\n  (NOTEQUAL_neq_zero_prefix @ NOTEQUAL_neq_zero_a_str) ::= A (V push_on_stack_nat_hd_c);;\n  (NOTEQUAL_neq_zero_prefix @ NOTEQUAL_neq_zero_b_str) ::= A (N 3);;\n  (NOTEQUAL_neq_zero_prefix @ NOTEQUAL_neq_zero_ret_str) ::= A (N 0);;\n  invoke_subprogram NOTEQUAL_neq_zero_prefix NOTEQUAL_neq_zero_IMP_Minus;;\n  push_on_stack_nat_cond_one ::= A (V (NOTEQUAL_neq_zero_prefix @ NOTEQUAL_neq_zero_ret_str));;\n  (IF push_on_stack_nat_cond_one \\<noteq>0\n  THEN push_on_stack_nat_sub_branch_aux2_IMP_Minus\n  ELSE push_on_stack_nat_eq_three_IMP_Minus)\"\n\ndefinition \"push_on_stack_nat_sub_branch_aux3_time t s \\<equiv> \n(let\n  hd_xs' = push_on_stack_nat_c s;\n  t = t + 2;\n  hd_ret' = 0;\n  t = t + 2;\n  hd_state = \\<lparr>hd_xs = hd_xs', hd_ret = hd_ret'\\<rparr>;\n  hd_ret_state = hd_imp hd_state;\n  t = t + hd_imp_time 0 hd_state;\n  push_on_stack_nat_hd_c = hd_ret hd_ret_state;\n  t = t + 2;\n  NOTEQUAL_neq_zero_a' = push_on_stack_nat_hd_c;\n  t = t + 2;\n  NOTEQUAL_neq_zero_b' = 3;\n  t = t + 2;\n  NOTEQUAL_neq_zero_ret' = 0;\n  t = t + 2;\n  NOTEQUAL_neq_zero_state = \\<lparr>NOTEQUAL_neq_zero_a = NOTEQUAL_neq_zero_a',\n                            NOTEQUAL_neq_zero_b = NOTEQUAL_neq_zero_b',\n                            NOTEQUAL_neq_zero_ret = NOTEQUAL_neq_zero_ret'\\<rparr>;\n  NOTEQUAL_neq_zero_ret_state = NOTEQUAL_neq_zero_imp NOTEQUAL_neq_zero_state;\n  t = t + NOTEQUAL_neq_zero_imp_time 0 NOTEQUAL_neq_zero_state;\n  push_on_stack_nat_cond_one = (NOTEQUAL_neq_zero_ret NOTEQUAL_neq_zero_ret_state);\n  t = t + 2\n in\n  (if push_on_stack_nat_cond_one \\<noteq> 0\n      then \n        let \n         t = t + 1;\n         t = t + push_on_stack_nat_sub_branch_aux2_time 0 s\n        in t\n      else \n       let \n        t = t + 1;\n        t = t + push_on_stack_nat_eq_three_time 0 s\n        in t))\"\n\nlemma push_on_stack_nat_sub_branch_aux3_IMP_Minus_correct_function:\n  \"(invoke_subprogram p push_on_stack_nat_sub_branch_aux3_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p push_on_stack_nat_ret_str)\n      = push_on_stack_nat_ret\n          (push_on_stack_nat_sub_branch_aux3 (push_on_stack_nat_imp_to_HOL_state p s))\"\n  apply (subst push_on_stack_nat_sub_branch_aux3_def)\n  apply (simp only: push_on_stack_nat_sub_branch_aux3_IMP_Minus_def prefix_simps)\n  apply (erule Seq_E)+\n  apply (erule hd_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars])\n  subgoal premises p using p(10) by fastforce\n  apply (erule NOTEQUAL_neq_zero_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars])\n  subgoal premises p using p(12) by fastforce\n  apply (erule If_E)\n    subgoal \n      apply (force dest!:push_on_stack_nat_sub_branch_aux2_IMP_Minus_correct_function simp:  \n      Let_def hd_imp_to_HOL_state_def NOTEQUAL_neq_zero_imp_to_HOL_state_def push_on_stack_nat_imp_to_HOL_state_def)\n      done\n    subgoal \n    apply (force dest!:push_on_stack_nat_eq_three_IMP_Minus_correct_function simp:  \n      Let_def hd_imp_to_HOL_state_def NOTEQUAL_neq_zero_imp_to_HOL_state_def push_on_stack_nat_imp_to_HOL_state_def)\n    done \n  done \n\nlemma push_on_stack_nat_sub_branch_aux3_IMP_Minus_correct_time:\n  \"(invoke_subprogram p push_on_stack_nat_sub_branch_aux3_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = push_on_stack_nat_sub_branch_aux3_time 0 (push_on_stack_nat_imp_to_HOL_state p s)\"\n  apply (subst push_on_stack_nat_sub_branch_aux3_time_def)\n  apply (simp only: push_on_stack_nat_sub_branch_aux3_IMP_Minus_def prefix_simps)\n  apply (erule Seq_tE)+\n  apply (erule hd_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars])\n  subgoal premises p using p(19) by fastforce\n  apply (erule NOTEQUAL_neq_zero_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars])\n  subgoal premises p using p(21) by fastforce\n  apply (erule If_tE)\n    subgoal \n      apply (force dest!:push_on_stack_nat_sub_branch_aux2_IMP_Minus_correct_time simp:  \n      Let_def hd_imp_to_HOL_state_def NOTEQUAL_neq_zero_imp_to_HOL_state_def push_on_stack_nat_imp_to_HOL_state_def)\n      done\n    subgoal \n    apply (force dest!:push_on_stack_nat_eq_three_IMP_Minus_correct_time simp:  \n      Let_def hd_imp_to_HOL_state_def NOTEQUAL_neq_zero_imp_to_HOL_state_def push_on_stack_nat_imp_to_HOL_state_def)\n    done \n  done \n\ndefinition \"push_on_stack_nat_state_upd s \\<equiv> \n (let\n  hd_xs' = push_on_stack_nat_c s;\n  hd_ret' = 0;\n  hd_state = \\<lparr>hd_xs = hd_xs', hd_ret = hd_ret'\\<rparr>;\n  hd_ret_state = hd_imp hd_state;\n  push_on_stack_nat_hd_c = hd_ret hd_ret_state\n in\n  (if push_on_stack_nat_hd_c \\<noteq> 0\n  then push_on_stack_nat_sub_branch_aux3 s\n  else push_on_stack_nat_eq_zero s)\n  )\"\n\nfunction push_on_stack_nat_imp::\n  \"push_on_stack_nat_state \\<Rightarrow> push_on_stack_nat_state\" where\n  \"push_on_stack_nat_imp s =\n    (let \n      ret = push_on_stack_nat_state_upd s\n    in \n     ret)\"\n  by simp+\ntermination\n  by (relation \"measure (\\<lambda>s. push_on_stack_nat_c s)\") simp\n\ndeclare push_on_stack_nat_imp.simps[simp del]\n\nlemma push_on_stack_nat_imp_correct:\n   \"push_on_stack_nat_ret (push_on_stack_nat_imp s) =\n    push_on_stack_nat (push_on_stack_nat_c s) (push_on_stack_nat_n s) (push_on_stack_nat_s s)\"\n  apply (subst push_on_stack_nat_imp.simps)\n  apply (subst push_on_stack_nat_def)\n  apply (simp add: push_on_stack_nat_state_upd_def hd_imp_correct cons_imp_correct \n   NOTEQUAL_neq_zero_imp_correct \n    push_on_stack_nat_eq_zero_imp_correct\n   push_on_stack_nat_sub_branch_aux3_imp_correct \n   Let_def split: if_splits)  \n  done\n\ndefinition \"push_on_stack_nat_IMP_Minus \\<equiv> \n (hd_prefix @ hd_xs_str) ::= A (V push_on_stack_nat_c_str);;\n (hd_prefix @ hd_ret_str) ::= A (N 0);;\n invoke_subprogram hd_prefix hd_IMP_Minus;;\n push_on_stack_nat_hd_c ::= A (V (hd_prefix @ hd_ret_str));;\n IF push_on_stack_nat_hd_c \\<noteq>0\n  THEN  push_on_stack_nat_sub_branch_aux3_IMP_Minus\n  ELSE push_on_stack_nat_eq_zero_IMP_Minus\"\n\ndefinition \"push_on_stack_nat_state_upd_time t s\\<equiv> \n(let\n  hd_xs' = push_on_stack_nat_c s;\n  t = t + 2;\n  hd_ret' = 0;\n  t = t + 2;\n  hd_state = \\<lparr>hd_xs = hd_xs', hd_ret = hd_ret'\\<rparr>;\n  hd_ret_state = hd_imp hd_state;\n  t = t + hd_imp_time 0 hd_state;\n  push_on_stack_nat_hd_c = hd_ret hd_ret_state;\n  t = t + 2\n in\n  (if push_on_stack_nat_hd_c \\<noteq> 0\n  then \n    let \n     t = t + 1;\n     t = t + push_on_stack_nat_sub_branch_aux3_time 0 s\n    in \n    t \n  else \n   let \n    t = t + 1;\n    t = t + push_on_stack_nat_eq_zero_time 0 s\n   in\n    t)\n  )\"\n\nfunction push_on_stack_nat_imp_time :: \"nat \\<Rightarrow> push_on_stack_nat_state \\<Rightarrow> nat\" where\n  \"push_on_stack_nat_imp_time t s =\n    (let \n      ret = push_on_stack_nat_state_upd_time t s\n    in \n     ret)\"\n  by auto\ntermination\n  by (relation \"measure (\\<lambda>(t, s). push_on_stack_nat_c s)\") simp\n\ndeclare push_on_stack_nat_imp_time.simps[simp del]\n\n\n\nlemma push_on_stack_nat_IMP_Minus_correct_function:\n  \"(invoke_subprogram p push_on_stack_nat_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     s' (add_prefix p push_on_stack_nat_ret_str)\n      = push_on_stack_nat_ret\n          (push_on_stack_nat_imp (push_on_stack_nat_imp_to_HOL_state p s))\"\n  apply (subst push_on_stack_nat_imp.simps)\n  apply (simp only: push_on_stack_nat_IMP_Minus_def prefix_simps)\n  apply (erule Seq_E)+\n  apply (erule hd_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars])\n  subgoal premises p using p(5) by fastforce\n  apply (erule If_E)\n    subgoal \n      apply (force dest!:push_on_stack_nat_sub_branch_aux3_IMP_Minus_correct_function simp:  \n      push_on_stack_nat_state_upd_def Let_def hd_imp_to_HOL_state_def push_on_stack_nat_imp_to_HOL_state_def)\n      done \n    subgoal \n    apply (force dest!:push_on_stack_nat_eq_zero_IMP_Minus_correct_function simp:  \n      push_on_stack_nat_state_upd_def Let_def hd_imp_to_HOL_state_def push_on_stack_nat_imp_to_HOL_state_def)\n    done \n  done \n\nlemma push_on_stack_nat_IMP_Minus_correct_time:\n  \"(invoke_subprogram p push_on_stack_nat_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s' \\<Longrightarrow>\n     t = push_on_stack_nat_imp_time 0 (push_on_stack_nat_imp_to_HOL_state p s)\"\n  apply (subst push_on_stack_nat_imp_time.simps)\n  apply (simp only: push_on_stack_nat_IMP_Minus_def prefix_simps)\n  apply (erule Seq_tE)+\n  apply (erule hd_IMP_Minus_correct[where vars=push_on_stack_nat_IMP_vars])\n  subgoal premises p using p(9) by fastforce\n  apply (erule If_tE)\n    subgoal \n      apply (force dest!:push_on_stack_nat_sub_branch_aux3_IMP_Minus_correct_time\n      simp: push_on_stack_nat_state_upd_time_def \n      Let_def hd_imp_to_HOL_state_def push_on_stack_nat_imp_to_HOL_state_def)\n      done \n    subgoal \n    apply (force dest!:push_on_stack_nat_eq_zero_IMP_Minus_correct_time simp:  \n      push_on_stack_nat_state_upd_time_def Let_def hd_imp_to_HOL_state_def push_on_stack_nat_imp_to_HOL_state_def)\n    done \n  done \n\nlemma push_on_stack_nat_IMP_Minus_correct_effects:\n  \"\\<lbrakk>(invoke_subprogram (p @ push_on_stack_nat_prefix) push_on_stack_nat_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    v \\<in> vars; \\<not> (prefix push_on_stack_nat_prefix v)\\<rbrakk>\n   \\<Longrightarrow> s (add_prefix p v) = s' (add_prefix p v)\"\n  using com_add_prefix_valid'' com_only_vars prefix_def \n  by blast\n\nlemma push_on_stack_nat_IMP_Minus_correct:\n  \"\\<lbrakk>(invoke_subprogram (p1 @ p2) push_on_stack_nat_IMP_Minus, s) \\<Rightarrow>\\<^bsup>t\\<^esup> s';\n    \\<And>v. v \\<in> vars \\<Longrightarrow> \\<not> (set p2 \\<subseteq> set v);\n    \\<lbrakk>t = (push_on_stack_nat_imp_time 0 (push_on_stack_nat_imp_to_HOL_state (p1 @ p2) s));\n     s' (add_prefix (p1 @ p2) push_on_stack_nat_ret_str) =\n          push_on_stack_nat_ret (push_on_stack_nat_imp\n                                        (push_on_stack_nat_imp_to_HOL_state (p1 @ p2) s));\n     \\<And>v. v \\<in> vars \\<Longrightarrow> s (add_prefix p1 v) = s' (add_prefix p1 v)\\<rbrakk>\n   \\<Longrightarrow> P\\<rbrakk> \\<Longrightarrow> P\"\n  using push_on_stack_nat_IMP_Minus_correct_function \n       push_on_stack_nat_IMP_Minus_correct_time\n       push_on_stack_nat_IMP_Minus_correct_effects set_mono_prefix\n  by (smt (verit, ccfv_SIG) com_add_prefix_valid_subset com_only_vars)\n\nend", "meta": {"author": "AlexiosFan", "repo": "BA_NP_Reduction", "sha": "0e37ddc58cb822b0a09b2ce7c15e7b88652e154c", "save_path": "github-repos/isabelle/AlexiosFan-BA_NP_Reduction", "path": "github-repos/isabelle/AlexiosFan-BA_NP_Reduction/BA_NP_Reduction-0e37ddc58cb822b0a09b2ce7c15e7b88652e154c/poly-reductions/Cook_Levin/IMP-_To_SAS+/IMP-_To_IMP--/IMP_Minus_To_IMP_Minus_Minus_IMP.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185351961015, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.2521779748096991}}
{"text": "(*  Title:       X86 instruction semantics and basic block symbolic execution\n    Authors:     Freek Verbeek, Abhijith Bharadwaj, Joshua Bockenek, Ian Roessle, Timmy Weerwag, Binoy Ravindran\n    Year:        2020\n    Maintainer:  Freek Verbeek (freek@vt.edu)\n*)\n\nsection \"Removing superfluous memory writes\"\n\ntheory StateCleanUp\n  imports State \"HOL-Eisbach.Eisbach\"\nbegin\n\n\ndefinition \"assumptions \\<equiv> id\"\n\ntext \\<open>We are going to make schematic theorems of the form:\n      \\[\n        @{term assumptions} ?A \\implies \\ldots \n      \\]\n      The assumptions will be generated on-the-fly. The seemingly weird lemmas below achieves that.\\<close>\n\n\nlemma assumptions_impI:\nassumes \"assumptions (P \\<and> A)\"\n  shows \"P\"\n  using assms\n  by (auto simp add: assumptions_def)\n\nlemma assumptions_conjE:\n  shows \"assumptions (P \\<and> A) \\<longleftrightarrow> P \\<and> assumptions A\"\n  by (auto simp add: assumptions_def)\n\nlemma assumptionsI:\n  shows \"assumptions True\"\n  by (auto simp add: assumptions_def)\n\n\n\ntext \\<open>Consider two consecutive memory updates. If they write to the same memory locations, only one of these\n      need to be kept. We formulate an Eisbach method to that end. \\<close>\n\n\ntext \\<open>Returns true if two states are equal except for a specific memory region.\\<close>\ndefinition eq_except_for_mem :: \"state \\<Rightarrow> state \\<Rightarrow> 64 word \\<Rightarrow> nat \\<Rightarrow> 256 word \\<Rightarrow> bool \\<Rightarrow> bool\"\n  where \"eq_except_for_mem \\<sigma> \\<sigma>' a si v b \\<equiv> \\<sigma> with [\\<lbrakk>a,si\\<rbrakk> :=\\<^sub>m v] = (if b then \\<sigma>' else \\<sigma>' with [\\<lbrakk>a,si\\<rbrakk> :=\\<^sub>m v])\"\n\n\nlemma eefm_start:\n  assumes \"eq_except_for_mem (\\<sigma> with updates) (\\<sigma> with updates') a si v b\"\n  shows \"(\\<sigma> with ((\\<lbrakk>a,si\\<rbrakk> :=\\<^sub>m v)#updates)) = (if b then \\<sigma> with updates' else \\<sigma> with ((\\<lbrakk>a,si\\<rbrakk> :=\\<^sub>m v)#updates'))\"\n  using assms\n  by (auto simp add: eq_except_for_mem_def region_addresses_def state_with_updates.simps(2) state_update.simps)\n\nlemma eefm_clean_mem:\nassumes \"si' \\<le> si\"\n    and \"eq_except_for_mem (\\<sigma> with updates) (\\<sigma> with updates') a si v b\"\n  shows \"eq_except_for_mem (\\<sigma> with ((\\<lbrakk>a,si'\\<rbrakk> :=\\<^sub>m v')#updates)) (\\<sigma> with updates') a si v b\"\n  using assms\n  apply (auto simp add: eq_except_for_mem_def state_with_updates.simps(2) state_update.simps)\n  subgoal\n    apply (cases \"\\<sigma> with updates\";cases \"\\<sigma> with updates'\";cases \"\\<sigma>\")\n    by (auto simp add: override_on_def region_addresses_iff)\n  apply (cases \"\\<sigma> with updates\";cases \"\\<sigma> with updates'\")\n  apply (auto simp add: override_on_def region_addresses_iff)\n  apply (rule ext)\n  apply (auto split: if_splits)\n  by meson\n\nmethod eefm_clean_mem = (rule eefm_clean_mem, (simp (no_asm);fail))\n\n\nlemma eefm_clean_mem_enclosed:\n  assumes \"si < 32\" (* due to 256 words being written to memory *)\n      and \"enclosed a' si' a si\"\n      and \"eq_except_for_mem (\\<sigma> with updates) (\\<sigma> with updates') a' si' v' b\"\n  shows \"eq_except_for_mem (\\<sigma> with ((\\<lbrakk>a,si\\<rbrakk> :=\\<^sub>m v)#updates)) \n                           (\\<sigma> with ((\\<lbrakk>a,si\\<rbrakk> :=\\<^sub>m overwrite (8 * unat (a' - a)) (8 * unat (a' - a) + 8*si') v (v' << unat (a'-a)*8))#updates'))\n                           a' si' v' True\"\nproof(cases b)\n  case True\n  thus ?thesis\n    using assms(3)\n    apply (auto simp add: eq_except_for_mem_def state_with_updates.simps(2) state_update.simps)\n    apply (cases \"\\<sigma> with updates\";cases \"\\<sigma> with updates'\")\n    apply (auto simp add: override_on_def)\n    apply (rule ext)\n    apply (auto)\n\n    apply (rule word_eqI)\n    subgoal premises prems for _ _ _ _ x n\n    proof-\n      have 1: \"unat (x - a) - unat (a' - a) = unat(x - a')\"\n        using address_in_enclosed_region_as_linarith[OF assms(2),of x]\n              address_of_enclosed_region_ge[OF assms(2)]\n              word_le_nat_alt prems(4-5)\n        by (auto simp add: unat_sub_if_size word_size)\n      thus ?thesis\n        using prems address_in_enclosed_region[of a' si' a si x,OF assms(2)] assms(1)\n        by (auto simp add: word_size take_byte_shiftlr_256 nth_take_byte_overwrite)\n    qed\n\n    apply (rule word_eqI)\n    subgoal for _ _ _ _ x n\n      using notin_region_addresses_sub[of x a' si' a]\n      by (auto simp add: word_size nth_take_byte_overwrite)\n    done\nnext\n  case False\n  thus ?thesis\n    using assms(3)\n    apply (auto simp add: eq_except_for_mem_def state_with_updates.simps(2) state_update.simps)\n    apply (cases \"\\<sigma> with updates\";cases \"\\<sigma> with updates'\")\n    apply (auto simp add: override_on_def)\n    apply (rule ext)\n    using enclosed_spec[OF assms(2)]\n    apply (auto)\n\n    subgoal premises prems for _ _ _ _ _ x \n    proof-\n      have 1: \"unat (x - a) - unat (a' - a) = unat(x - a')\"\n        using address_in_enclosed_region_as_linarith[OF assms(2),of x]\n              address_of_enclosed_region_ge[OF assms(2)]\n              word_le_nat_alt prems(6)\n        by (auto simp add: unat_sub_if_size word_size)\n      show ?thesis\n        apply (rule word_eqI)\n        using 1 prems address_in_enclosed_region[of a' si' a si x,OF assms(2)] assms(1)\n        by (auto simp add: word_size take_byte_shiftlr_256 nth_take_byte_overwrite)\n    qed\n\n     subgoal for _ _ _ _ _ x\n       apply (rule word_eqI)\n       using notin_region_addresses_sub[of x a' si' a]\n       by (auto simp add: word_size nth_take_byte_overwrite)\n     by meson\nqed\n\n\nlemmas eefm_clean_mem_enclosed_plus  = eefm_clean_mem_enclosed[OF _ enclosed_plus, simplified]\nlemmas eefm_clean_mem_enclosed_minus_numeral = eefm_clean_mem_enclosed[OF _ enclosed_minus_minus, of _ \"numeral n\" \"numeral m\"] for n m\n\nmethod eefm_clean_mem_enclosed_plus = \n        (rule eefm_clean_mem_enclosed_plus, (\n            (simp (no_asm);fail), (simp (no_asm);fail),\n            (\n             (simp (no_asm_simp);fail) |\n             (rule assumptions_impI[of \"_ + _ < 18446744073709551616\"],simp (no_asm_simp),subst (asm) assumptions_conjE))\n            )\n        )\n\nmethod eefm_clean_mem_enclosed_minus_numeral = \n        (rule eefm_clean_mem_enclosed_minus_numeral, (\n            (simp (no_asm);fail), (simp (no_asm);fail), (simp (no_asm);fail), (simp (no_asm);fail), (simp (no_asm);fail),\n            (\n             (simp (no_asm_simp);fail) |           \n             (rule assumptions_impI[of \"_ \\<le> _\"],simp (no_asm_simp),subst (asm) assumptions_conjE))\n            ) \n        )\n\nlemma eefm_next_mem:\nassumes \"separate a si a' si'\"\n   and \"eq_except_for_mem (\\<sigma> with updates) (\\<sigma> with updates') a si v b\"\n shows \"eq_except_for_mem (\\<sigma> with ((\\<lbrakk>a',si'\\<rbrakk> :=\\<^sub>m v')#updates)) (\\<sigma> with ((\\<lbrakk>a',si'\\<rbrakk> :=\\<^sub>m v')#updates')) a si v b\"\n  using assms\n  apply (auto simp add: eq_except_for_mem_def override_on_def separate_def state_with_updates.simps(2) state_update.simps)\n  apply (cases \"\\<sigma> with updates\";cases \"\\<sigma> with updates'\")\n  apply (auto simp add: override_on_def)\n  apply (rule ext)\n   apply (auto)\n  apply (cases \"\\<sigma> with updates\";cases \"\\<sigma> with updates'\")\n  apply (auto simp add: override_on_def)\n  apply (rule ext)\n  apply (auto)\n  by (metis select_convs(2))\n\nmethod eefm_next_mem =        \n        (rule eefm_next_mem,\n            (  (simp (no_asm_simp) add: separate_simps state_simps; fail) |\n               (rule assumptions_impI[of \"separate _ _ _ _ \"],simp (no_asm_simp),subst (asm) assumptions_conjE))\n        )\n\nlemma eefm_end:\n  shows \"eq_except_for_mem (\\<sigma> with updates) (\\<sigma> with updates) a si v False\"\n  by (auto simp add: eq_except_for_mem_def)\n\n\ntext \\<open>We need a tactic exactly like ``subst'' but that applies to the outer most term.\\<close>\n\nML_file \\<open>MySubst.ML\\<close>\n\n\ntext \\<open>The following method takes a goal with state with symbolic state updates.\n      It first applies @{thm eefm_start}, considering the outer-most memory update to some region $\\llbracket a, si \\rrbracket$.\n      A list @{term updates'} is generated that produces a similar state except for region $\\llbracket a, si \\rrbracket$.\n      The list thus can have fewer updates since any update to a region that is enclosed in region $\\llbracket a, si \\rrbracket$ can be removed.\n      Consecutively, this method applies rules to determine whether a state update can be kept, merged or removed.\n      It may add assumptions to the goal, that assume no overflow.\n\\<close>\n\nmethod clean_up_mem = (\n    mysubst eefm_start,\n    ( eefm_clean_mem | eefm_clean_mem_enclosed_plus | eefm_clean_mem_enclosed_minus_numeral | eefm_next_mem)+,\n    rule eefm_end,\n    simp (no_asm),\n    ((match premises in A[thin]: \"assumptions (?A \\<and> ?B)\" \\<Rightarrow> \\<open>cut_tac A;subst (asm) assumptions_conjE, erule conjE \\<close>)+)?\n  )\n\n\ntext \\<open>The method above applies to one state update. This method can be repeated as long as modifies\n      the goal, as it always makes the goal smaller. The method below repeats a given method until\n      the goal is unchanged. In deterministic fashion (a la the REPEAT\\_DETERM tactic).\\<close>\n\nmethod_setup repeat_until_unchanged = \\<open>\n  Method.text_closure >>\n    (fn text => fn ctxt => fn using => \n          \\<comment> \\<open>parse the method supplied as parameter\\<close>\n      let val ctxt_tac = Method.evaluate_runtime text ctxt using\n          fun repeat_until_unchanged (ctxt,st) = \n            case Seq.pull (ctxt_tac (ctxt,st)) of\n                SOME (Seq.Result (ctxt',st'), _) => \n                  if Thm.eq_thm (st, st') then \n                    Seq.make_results (Seq.succeed (ctxt',st'))\n                  else\n                    repeat_until_unchanged (ctxt',st')\n              | _ => Seq.make_results (Seq.succeed (ctxt,st))\n      in\n        repeat_until_unchanged \n      end)\n\\<close>\n\nmethod clean_up = repeat_until_unchanged clean_up_mem\n\nend", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/X86_Semantics/StateCleanUp.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185351961015, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.2521779748096991}}
{"text": "theory KVS_WAL_ordered_disk\nimports Main Option String\nbegin\n\n(* We model the disk as list of strings. In this preliminary version, we assume a string can be contained in disk slot (ie., a block) *)\ntype_synonym disk = \"string list\" \n\n(* Convenience type which models a list of disk states that could result as an operation on the disk*)\ntype_synonym disk_states = \"disk list\"\n\n(* Usually, the log is a dedicated portion in the disk. In our model, we model it as a separate disk. This pair of data and log portions\nmake up the actual disk*)\nrecord diskpair = data :: disk\n                  log :: disk\n\n(* Convenience type which models a list of diskpairs *)\ntype_synonym diskpairlist = \"diskpair list\"\n\n(* Helper to enumerate disk lists *)\nfun enumdisks :: \"disk list list  => disk list\"\nwhere\n  \"enumdisks [] = []\"\n| \"enumdisks (x#d1) = (x) @ enumdisks d1\"\n\n(* Helper to enumerate diskpair lists *)\nfun enumdiskpairs :: \"diskpair list list  => diskpair list\"\nwhere\n  \"enumdiskpairs [] = []\"\n| \"enumdiskpairs (x#d1) = (x) @ enumdiskpairs d1\"\n\n(* Helper to check if a given element in present in a list *)\nfun list_contains :: \"'a \\<Rightarrow> 'a list \\<Rightarrow> bool\"\nwhere\n\"list_contains item [] = False\" |\n\"list_contains item (first # others) = ((item = first) \\<or> (list_contains item others))\"\n\n(* Log update : This function models how a key value pair is updated on the log *)\n(* Param1: key :: string *)\n(* Param2: value :: string *)\n(* returns: all possible log states :: disk_states *)\n(* There are 3 slots in the log. The first slot contains information about the log itself\n   It can either contain 'N' which means there is a log update currently happening or 'C'\n   which means the log update completed and it is safe to apply the update. Note: We assume\n   the log is cleaned properly (without failures) after applying an update from the log.\n*)\nfun log_update :: \"string \\<Rightarrow> string \\<Rightarrow> disk_states\"\nwhere\n\"log_update key value  = [\n                          [[],[],[]][0:=''N''],\n                          [[],[],[]][0:=''N'',(Suc 0):=key],\n                          [[],[],[]][0:=''N'',(Suc 0):=key,(Suc (Suc 0)):=value],\n                          [[],[],[]][0:=''C'',(Suc 0):=key,(Suc (Suc 0)):=value]\n                         ]\"\n\n\n(* Log recovery : This function models how the log is recovered. *)\n(* Param1: index_to_apply :: nat *)\n(* Param2: data_portion :: disk *)\n(* Param3: log_portion :: disk *)\n(* returns: data_portion :: disk*)\n(* Checks if the first slot in the log is 'C' which means the log update has completed properly.\n   In that case, it applies the update to index_to_apply in the data portion. Note: Recovery itself \n   can crash. This is modelled by function recover_crash *)\nfun recover :: \"nat \\<Rightarrow> disk \\<Rightarrow> disk \\<Rightarrow> disk\"\nwhere\n\"recover idx data_disk log_disk  = (if(log_disk!0 = ''C'')\n                 then data_disk[idx := log_disk!1, (Suc idx) := log_disk!2] else data_disk)\"\n\n(* Log recovery(crashing version) : This function models how the log is recovered. *)\n(* Param1: index_to_apply :: nat *)\n(* Param2: data_portion :: disk *)\n(* Param3: log_portion :: disk *)\n(* returns nothing *)\n(* Checks if the first slot in the log is 'C' which means the log update has completed properly.\n   In that case, it applies the update to index_to_apply in the data portion and marks the first slot as 'D'.\n   Otherwise does nothing *)\n(* returns: all possible disk pairs that would result if the recovery crashes :: diskpairlist *)\nfun recover_crash :: \"nat \\<Rightarrow> disk \\<Rightarrow> disk \\<Rightarrow> diskpairlist\"\nwhere\n\"recover_crash idx data_disk log_disk  = \n                 (if(log_disk!0 = ''C'')\n                 then\n                 [\n                  (| data = data_disk, log = log_disk |),\n                  (| data = data_disk[idx := log_disk!1],\n                                   log = log_disk |),\n                  (| data = data_disk[idx := log_disk!1, (Suc idx) := log_disk!2],\n                                   log = log_disk |),\n                  (| data = data_disk[idx := log_disk!1, (Suc idx) := log_disk!2],\n                                   log = log_disk[0 := ''D''] |)\n                 ]\n                 else \n                 [\n                  (| data = data_disk, log = log_disk |)\n                 ]\n                 )\" \n\n(* Log checkpointing : This function models how the log is checkpointed. *)\n(* Param1: index_to_apply :: nat *)\n(* Param2: data_portion :: disk *)\n(* Param3: log_portion :: disk *)\n(* returns nothing *)\n(* Same as recovery but called during normal operation and not after failures *)\n(* returns: data_portion :: disk*)\nfun checkpoint :: \"nat \\<Rightarrow> disk \\<Rightarrow> disk \\<Rightarrow> disk\"\nwhere\n\"checkpoint idx data_disk log_disk  =(if(log_disk!0 = ''C'')\n                 then data_disk[idx := log_disk!1, (Suc idx) := log_disk!2] else data_disk)\"\n\n(* KV_Put : This function models how our toy key-value store PUT operation works. *)\n(* Param1: key :: string *)\n(* Param1: value :: string *)\n(* Param1: data_portion :: disk *)\n(* Param2: index_to_apply: nat *)\n(* returns all possible disk states that could result on doing this PUT operation :: disk_states *)\nfun kv_put :: \"string \\<Rightarrow> string \\<Rightarrow> disk \\<Rightarrow> nat \\<Rightarrow> disk_states\"\nwhere\n\"kv_put k v current_disk idx= map (checkpoint idx current_disk) (log_update k v)\"\n\n(*Test code*)\nvalue \"log_update ''a'' ''b''\"\nvalue \"enumdisks [ [[''1'',''2''],[''3'',''4''],[''5'',''6'']],  [[''7'',''8''],[''9'',''10''],[''11'',''12'']] ]\"\nvalue \"enumdiskpairs (map (recover_crash 1 [''x'',''y'',''z'']) (log_update ''a'' ''b''))\"\nvalue \"map (recover 1 [''x'',''y'',''z'']) (log_update ''a'' ''b'')\"\nvalue \"map (recover 5 [''1'',''2'',''3'',''4'',''5'',''6'',''7'']) (log_update ''a'' ''b'')\"\nvalue \"enumdiskpairs (map (recover_crash 5 [''1'',''2'',''3'',''4'',''5'',''6'',''7'']) (log_update ''a'' ''b''))\"\n(*End of test code*)\n\n(* Assuming no crashes during recovery, prove that the logging mechanism can atomically update a key value pair\n   on disk *)\ntheorem atomic_recovery_no_crash_theorem:\nshows   \"length d \\<ge> 2 \\<and> (Suc idx) < length d \\<and> (list_contains after (map (recover idx d) (log_update s1 s2))) \\<and> s1\\<noteq>[] \\<and> s2 \\<noteq>[]\n         \\<Longrightarrow>\n         after!idx=d!idx \\<and> after!(Suc idx)=d!(Suc idx)\n         \\<or>\n         after!idx=s1 \\<and> after!(Suc idx)=s2\"\napply(auto)\ndone\n\n(* Assuming crashes during recovery, prove that the logging mechanism can atomically update a key value pair\n   on disk *)\ntheorem atomic_recovery_crash_theorem:\nshows   \"length d \\<ge> 2 \\<and> (Suc idx) < length d  \\<and> ( list_contains after (enumdiskpairs (map (recover_crash idx d) (log_update s1 s2) ) ) )  \\<and> s1\\<noteq>[] \\<and> s2 \\<noteq>[]\n         \\<Longrightarrow>\n         (log after)!0=''D'' \\<Longrightarrow> (data after)!idx=s1 \\<and> (data after)!(Suc idx)=s2\n         \\<and>\n         (log after)!0=''N'' \\<Longrightarrow> (data after)!idx=d!idx \\<and> (data after)!(Suc idx)=d!(Suc idx)\"\napply(auto)\ndone\n\n(* Atomic KV puts *)\ntheorem kv_put_atomic_theorem:\nshows   \"length d \\<ge> 2 \\<and> (Suc idx) < length d  \\<and> (list_contains after (kv_put s1 s2 d idx)) \\<and> s1\\<noteq>[] \\<and> s2 \\<noteq>[]\n         \\<Longrightarrow>\n         after!idx=d!idx \\<and> after!(Suc idx)=d!(Suc idx)\n         \\<or>\n         after!idx=s1 \\<and> after!(Suc idx)=s2\"\napply(auto)\ndone\n", "meta": {"author": "ramanala", "repo": "StorageStackSemantics", "sha": "620fd6fd0703cb4ed1d8cfdea16d1261b4645918", "save_path": "github-repos/isabelle/ramanala-StorageStackSemantics", "path": "github-repos/isabelle/ramanala-StorageStackSemantics/StorageStackSemantics-620fd6fd0703cb4ed1d8cfdea16d1261b4645918/KVS_WAL_ordered_disk.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5660185205547239, "lm_q2_score": 0.44552953503957266, "lm_q1q2_score": 0.25217796828653294}}
{"text": "section \\<open>Dynamic Backward Slice\\<close>\n\ntheory DynSlice imports DependentLiveVariables BitVector \"../Basic/SemanticsCFG\" begin\n\nsubsection \\<open>Backward slice of paths\\<close>\n\ncontext DynPDG begin\n\nfun slice_path :: \"'edge list \\<Rightarrow> bit_vector\"\n  where \"slice_path [] = []\"\n  | \"slice_path (a#as) = (let n' = last(targetnodes (a#as)) in\n                           (sourcenode a -a#as\\<rightarrow>\\<^sub>d* n')#slice_path as)\"\n\n(*<*)declare Let_def [simp](*>*)\n\nlemma slice_path_length:\n  \"length(slice_path as) = length as\"\nby(induct as) auto\n\n\nlemma slice_path_right_Cons:\n  assumes slice:\"slice_path as = x#xs\"\n  obtains a' as' where \"as = a'#as'\" and \"slice_path as' = xs\"\nproof(atomize_elim)\n  from slice show \"\\<exists>a' as'. as = a'#as' \\<and> slice_path as' = xs\"\n    by(induct as) auto\nqed\n\n\nsubsection \\<open>The proof of the fundamental property of (dynamic) slicing\\<close>\n\nfun select_edge_kinds :: \"'edge list \\<Rightarrow> bit_vector \\<Rightarrow> 'state edge_kind list\"\nwhere \"select_edge_kinds [] [] = []\"\n  | \"select_edge_kinds (a#as) (b#bs) = (if b then kind a\n      else (case kind a of \\<Up>f \\<Rightarrow> \\<Up>id | (Q)\\<^sub>\\<surd> \\<Rightarrow> (\\<lambda>s. True)\\<^sub>\\<surd>))#select_edge_kinds as bs\"\n\n\ndefinition slice_kinds :: \"'edge list \\<Rightarrow> 'state edge_kind list\"\n  where \"slice_kinds as = select_edge_kinds as (slice_path as)\"\n\n\nlemma select_edge_kinds_max_bv:\n  \"select_edge_kinds as (replicate (length as) True) = kinds as\"\nby(induct as,auto simp:kinds_def)\n\n\nlemma slice_path_leqs_information_same_Uses:\n  \"\\<lbrakk>n -as\\<rightarrow>* n'; bs \\<preceq>\\<^sub>b bs'; slice_path as = bs;\n    select_edge_kinds as bs = es; select_edge_kinds as bs' = es'; \n    \\<forall>V xs. (V,xs,as) \\<in> dependent_live_vars n' \\<longrightarrow> state_val s V = state_val s' V;\n    preds es' s'\\<rbrakk> \n  \\<Longrightarrow> (\\<forall>V \\<in> Use n'. state_val (transfers es s) V =\n      state_val (transfers es' s') V) \\<and> preds es s\"\nproof(induct bs bs' arbitrary:as es es' n s s' rule:bv_leqs.induct)\n  case 1\n  from \\<open>slice_path as = []\\<close> have \"as = []\" by(cases as) auto\n  with \\<open>select_edge_kinds as [] = es\\<close> \\<open>select_edge_kinds as [] = es'\\<close>\n  have \"es = []\" and \"es' = []\" by simp_all\n  { fix V assume \"V \\<in> Use n'\"\n    hence \"(V,[],[]) \\<in> dependent_live_vars n'\" by(rule dep_vars_Use)\n    with \\<open>\\<forall>V xs. (V,xs,as) \\<in> dependent_live_vars n' \\<longrightarrow>\n                  state_val s V = state_val s' V\\<close> \\<open>V \\<in> Use n'\\<close> \\<open>as = []\\<close>\n    have \"state_val s V = state_val s' V\" by blast }\n  with \\<open>es = []\\<close> \\<open>es' = []\\<close> show ?case by simp\nnext\n  case (2 x xs y ys)\n  note all = \\<open>\\<forall>V xs. (V,xs,as) \\<in> dependent_live_vars n' \\<longrightarrow>\n                     state_val s V = state_val s' V\\<close>\n  note IH = \\<open>\\<And>as es es' n s s'. \\<lbrakk>n -as\\<rightarrow>* n'; xs \\<preceq>\\<^sub>b ys; slice_path as = xs; \n                        select_edge_kinds as xs = es; select_edge_kinds as ys = es';\n                        \\<forall>V xs. (V,xs,as) \\<in> dependent_live_vars n' \\<longrightarrow>\n                                   state_val s V = state_val s' V; \n                           preds es' s'\\<rbrakk>\n            \\<Longrightarrow> (\\<forall>V \\<in> Use n'. state_val (transfers es s) V =\n                state_val (transfers es' s') V) \\<and> preds es s\\<close>\n  from \\<open>x#xs \\<preceq>\\<^sub>b y#ys\\<close> have \"x \\<longrightarrow> y\" and \"xs \\<preceq>\\<^sub>b ys\" by simp_all\n  from \\<open>slice_path as = x#xs\\<close> obtain a' as' where \"as = a'#as'\"\n    and \"slice_path as' = xs\" by(erule slice_path_right_Cons)\n  from \\<open>as = a'#as'\\<close> \\<open>select_edge_kinds as (x#xs) = es\\<close>\n  obtain ex esx where \"es = ex#esx\"\n    and ex:\"ex = (if x then kind a'\n                    else (case kind a' of \\<Up>f \\<Rightarrow> \\<Up>id | (Q)\\<^sub>\\<surd> \\<Rightarrow> (\\<lambda>s. True)\\<^sub>\\<surd>))\"\n    and \"select_edge_kinds as' xs = esx\" by auto\n  from \\<open>as = a'#as'\\<close> \\<open>select_edge_kinds as (y#ys) = es'\\<close> obtain ex' esx' \n    where \"es' = ex'#esx'\"\n    and ex':\"ex' = (if y then kind a'\n                    else (case kind a' of \\<Up>f \\<Rightarrow> \\<Up>id | (Q)\\<^sub>\\<surd> \\<Rightarrow> (\\<lambda>s. True)\\<^sub>\\<surd>))\"\n    and \"select_edge_kinds as' ys = esx'\" by auto\n  from \\<open>n -as\\<rightarrow>* n'\\<close> \\<open>as = a'#as'\\<close> have [simp]:\"n = sourcenode a'\" \n    and \"valid_edge a'\" and \"targetnode a' -as'\\<rightarrow>* n'\"\n    by(auto elim:path_split_Cons)\n  from \\<open>n -as\\<rightarrow>* n'\\<close> \\<open>as = a'#as'\\<close> have \"last(targetnodes as) = n'\"\n    by(fastforce intro:path_targetnode)\n  from \\<open>preds es' s'\\<close> \\<open>es' = ex'#esx'\\<close> have \"pred ex' s'\"\n    and \"preds esx' (transfer ex' s')\" by simp_all\n  show ?case\n  proof(cases \"as' = []\")\n    case True\n    hence [simp]:\"as' = []\" by simp\n    with \\<open>slice_path as' = xs\\<close> \\<open>xs \\<preceq>\\<^sub>b ys\\<close> \n    have [simp]:\"xs = [] \\<and> ys = []\" by auto(cases ys,auto)+\n    with \\<open>select_edge_kinds as' xs = esx\\<close> \\<open>select_edge_kinds as' ys = esx'\\<close>\n    have [simp]:\"esx = []\" and [simp]:\"esx' = []\" by simp_all\n    from True \\<open>targetnode a' -as'\\<rightarrow>* n'\\<close> \n    have [simp]:\"n' = targetnode a'\" by(auto elim:path.cases)\n    show ?thesis\n    proof(cases x)\n      case True\n      with \\<open>x \\<longrightarrow> y\\<close> ex ex' have [simp]:\"ex = kind a' \\<and> ex' = kind a'\" by simp\n      have \"pred ex s\"\n      proof(cases ex)\n        case (Predicate Q)\n        with ex ex' True \\<open>x \\<longrightarrow> y\\<close> have [simp]:\"transfer ex s = s\" \n          and [simp]:\"transfer ex' s' = s'\"\n          by(cases \"kind a'\",auto)+\n        show ?thesis\n        proof(cases \"n -[a']\\<rightarrow>\\<^sub>c\\<^sub>d n'\")\n          case True\n          { fix V' assume \"V' \\<in> Use n\"\n            with True \\<open>valid_edge a'\\<close>\n            have \"(V',[],a'#[]@[]) \\<in> dependent_live_vars n'\"\n              by(fastforce intro:dep_vars_Cons_cdep DynPDG_path_Nil \n                          simp:targetnodes_def)\n            with all \\<open>as = a'#as'\\<close> have \"state_val s V' = state_val s' V'\"\n              by fastforce }\n          with \\<open>pred ex' s'\\<close> \\<open>valid_edge a'\\<close>\n          show ?thesis by(fastforce elim:CFG_edge_Uses_pred_equal)\n        next\n          case False\n          from ex True Predicate have \"kind a' = (Q)\\<^sub>\\<surd>\" by(auto split:if_split_asm)\n          from True \\<open>slice_path as = x#xs\\<close> \\<open>as = a'#as'\\<close> have \"n -[a']\\<rightarrow>\\<^sub>d* n'\"\n            by(auto simp:targetnodes_def)\n          thus ?thesis\n          proof(induct rule:DynPDG_path.cases)\n            case (DynPDG_path_Nil nx)\n            hence False by simp\n            thus ?case by simp\n          next\n            case (DynPDG_path_Append_cdep nx asx n'' asx' nx')\n            from \\<open>[a'] = asx@asx'\\<close> \n            have \"(asx = [a'] \\<and> asx' = []) \\<or> (asx = [] \\<and> asx' = [a'])\"\n              by (cases asx) auto\n            hence False\n            proof\n              assume \"asx = [a'] \\<and> asx' = []\"\n              with \\<open>n'' -asx'\\<rightarrow>\\<^sub>c\\<^sub>d nx'\\<close> show False\n                by(fastforce elim:DynPDG_edge.cases dest:dyn_control_dependence_path)\n            next\n              assume \"asx = [] \\<and> asx' = [a']\"\n              with \\<open>nx -asx\\<rightarrow>\\<^sub>d* n''\\<close> have \"nx = n''\" and \"asx' = [a']\"\n                by(auto intro:DynPDG_empty_path_eq_nodes)\n              with \\<open>n = nx\\<close> \\<open>n' = nx'\\<close> \\<open>n'' -asx'\\<rightarrow>\\<^sub>c\\<^sub>d nx'\\<close> False\n              show False by simp\n            qed\n            thus ?thesis by simp\n          next\n            case (DynPDG_path_Append_ddep nx asx n'' V asx' nx')\n            from \\<open>[a'] = asx@asx'\\<close> \n            have \"(asx = [a'] \\<and> asx' = []) \\<or> (asx = [] \\<and> asx' = [a'])\"\n              by (cases asx) auto\n            thus ?case\n            proof\n              assume \"asx = [a'] \\<and> asx' = []\"\n              with \\<open>n'' -{V}asx'\\<rightarrow>\\<^sub>d\\<^sub>d nx'\\<close> have False\n                by(fastforce elim:DynPDG_edge.cases simp:dyn_data_dependence_def)\n              thus ?thesis by simp\n            next\n              assume \"asx = [] \\<and> asx' = [a']\"\n              with \\<open>nx -asx\\<rightarrow>\\<^sub>d* n''\\<close> have \"nx = n''\"\n                by(simp add:DynPDG_empty_path_eq_nodes)\n              { fix V' assume \"V' \\<in> Use n\"\n                from \\<open>n'' -{V}asx'\\<rightarrow>\\<^sub>d\\<^sub>d nx'\\<close> \\<open>asx = [] \\<and> asx' = [a']\\<close> \\<open>n' = nx'\\<close>\n                have \"(V,[],[]) \\<in> dependent_live_vars n'\"\n                  by(fastforce intro:dep_vars_Use elim:DynPDG_edge.cases\n                    simp:dyn_data_dependence_def)\n                with \\<open>V' \\<in> Use n\\<close> \\<open>n'' -{V}asx'\\<rightarrow>\\<^sub>d\\<^sub>d nx'\\<close> \\<open>asx = [] \\<and> asx' = [a']\\<close>\n                  \\<open>n = nx\\<close> \\<open>nx = n''\\<close> \\<open>n' = nx'\\<close>\n                have \"(V',[],[a']) \\<in> dependent_live_vars n'\"\n                  by(auto elim:dep_vars_Cons_ddep simp:targetnodes_def)\n                with all \\<open>as = a'#as'\\<close> have \"state_val s V' = state_val s' V'\"\n                  by fastforce }\n              with \\<open>pred ex' s'\\<close> \\<open>valid_edge a'\\<close> ex ex' True \\<open>x \\<longrightarrow> y\\<close> show ?thesis\n                by(fastforce elim:CFG_edge_Uses_pred_equal)\n            qed\n          qed\n        qed\n      qed simp\n      { fix V assume \"V \\<in> Use n'\"\n        from \\<open>V \\<in> Use n'\\<close> have \"(V,[],[]) \\<in> dependent_live_vars n'\" \n          by(rule dep_vars_Use)\n        have \"state_val (transfer ex s) V = state_val (transfer ex' s') V\"\n        proof(cases \"n -{V}[a']\\<rightarrow>\\<^sub>d\\<^sub>d n'\")\n          case True\n          hence \"V \\<in> Def n\"\n            by(auto elim:DynPDG_edge.cases simp:dyn_data_dependence_def)\n          have \"\\<And>V. V \\<in> Use n \\<Longrightarrow> state_val s V = state_val s' V\"\n          proof -\n            fix V' assume \"V' \\<in> Use n\"\n            with \\<open>(V,[],[]) \\<in> dependent_live_vars n'\\<close> True\n            have \"(V',[],[a']) \\<in> dependent_live_vars n'\"\n              by(fastforce intro:dep_vars_Cons_ddep simp:targetnodes_def)\n            with all \\<open>as = a'#as'\\<close> show \"state_val s V' = state_val s' V'\" by auto\n          qed\n          with \\<open>valid_edge a'\\<close> \\<open>pred ex' s'\\<close> \\<open>pred ex s\\<close>\n          have \"\\<forall>V \\<in> Def n. state_val (transfer (kind a') s) V =\n                              state_val (transfer (kind a') s') V\"\n            by simp(rule CFG_edge_transfer_uses_only_Use,auto)\n          with \\<open>V \\<in> Def n\\<close> have \"state_val (transfer (kind a') s) V = \n                         state_val (transfer (kind a') s') V\"\n            by simp\n          thus ?thesis by fastforce\n        next\n          case False\n          with \\<open>last(targetnodes as) = n'\\<close> \\<open>as = a'#as'\\<close>\n            \\<open>(V,[],[]) \\<in> dependent_live_vars n'\\<close>\n          have \"(V,[a'],[a']) \\<in> dependent_live_vars n'\"\n            by(fastforce intro:dep_vars_Cons_keep)\n          from \\<open>(V,[a'],[a']) \\<in> dependent_live_vars n'\\<close> all \\<open>as = a'#as'\\<close>\n          have states_eq:\"state_val s V = state_val s' V\"\n            by auto\n          from \\<open>valid_edge a'\\<close> \\<open>V \\<in> Use n'\\<close> False \\<open>pred ex s\\<close>\n          have \"state_val (transfers (kinds [a']) s) V = state_val s V\"\n            apply(auto intro!:no_ddep_same_state path_edge simp:targetnodes_def)\n            apply(simp add:kinds_def)\n            by(case_tac as',auto)\n          moreover\n          from \\<open>valid_edge a'\\<close> \\<open>V \\<in> Use n'\\<close> False \\<open>pred ex' s'\\<close>\n          have \"state_val (transfers (kinds [a']) s') V = state_val s' V\"\n            apply(auto intro!:no_ddep_same_state path_edge simp:targetnodes_def)\n            apply(simp add:kinds_def)\n            by(case_tac as',auto)\n          ultimately show ?thesis using states_eq by(auto simp:kinds_def)\n        qed }\n      hence \"\\<forall>V \\<in> Use n'. state_val (transfer ex s) V = \n                                state_val (transfer ex' s') V\" by simp\n      with \\<open>pred ex s\\<close> \\<open>es = ex#esx\\<close> \\<open>es' = ex'#esx'\\<close> show ?thesis by simp\n    next\n      case False\n      with ex have cases_x:\"ex = (case kind a' of \\<Up>f \\<Rightarrow> \\<Up>id | (Q)\\<^sub>\\<surd> \\<Rightarrow> (\\<lambda>s. True)\\<^sub>\\<surd>)\"\n        by simp\n      from cases_x have \"pred ex s\" by(cases \"kind a'\",auto)\n      show ?thesis\n      proof(cases y)\n        case True\n        with ex' have [simp]:\"ex' = kind a'\" by simp\n        { fix V assume \"V \\<in> Use n'\"\n          from \\<open>V \\<in> Use n'\\<close> have \"(V,[],[]) \\<in> dependent_live_vars n'\"\n            by(rule dep_vars_Use)\n          from \\<open>slice_path as = x#xs\\<close> \\<open>as = a'#as'\\<close> \\<open>\\<not> x\\<close> \n          have \"\\<not> n -[a']\\<rightarrow>\\<^sub>d* n'\" by(simp add:targetnodes_def)\n          hence \"\\<not> n -{V}[a']\\<rightarrow>\\<^sub>d\\<^sub>d n'\" by(fastforce dest:DynPDG_path_ddep)\n          with \\<open>last(targetnodes as) = n'\\<close> \\<open>as = a'#as'\\<close>\n            \\<open>(V,[],[]) \\<in> dependent_live_vars n'\\<close>\n          have \"(V,[a'],[a']) \\<in> dependent_live_vars n'\"\n            by(fastforce intro:dep_vars_Cons_keep)\n          with all \\<open>as = a'#as'\\<close> have \"state_val s V = state_val s' V\" by auto\n          from \\<open>valid_edge a'\\<close> \\<open>V \\<in> Use n'\\<close> \\<open>pred ex' s'\\<close>\n            \\<open>\\<not> n -{V}[a']\\<rightarrow>\\<^sub>d\\<^sub>d n'\\<close> \\<open>last(targetnodes as) = n'\\<close> \\<open>as = a'#as'\\<close>\n          have \"state_val (transfers (kinds [a']) s') V = state_val s' V\"\n            apply(auto intro!:no_ddep_same_state path_edge)\n            apply(simp add:kinds_def)\n            by(case_tac as',auto)\n          with \\<open>state_val s V = state_val s' V\\<close> cases_x\n          have \"state_val (transfer ex s) V =\n                state_val (transfer ex' s') V\"\n            by(cases \"kind a'\",simp_all add:kinds_def) }\n        hence \"\\<forall>V \\<in> Use n'. state_val (transfer ex s) V =\n                           state_val (transfer ex' s') V\" by simp\n        with \\<open>as = a'#as'\\<close> \\<open>es = ex#esx\\<close> \\<open>es' = ex'#esx'\\<close> \\<open>pred ex s\\<close> \n        show ?thesis by simp\n      next\n        case False\n        with ex' have cases_y:\"ex' = (case kind a' of \\<Up>f \\<Rightarrow> \\<Up>id | (Q)\\<^sub>\\<surd> \\<Rightarrow> (\\<lambda>s. True)\\<^sub>\\<surd>)\"\n          by simp\n        with cases_x have [simp]:\"ex = ex'\" by(cases \"kind a'\") auto\n        { fix V assume \"V \\<in> Use n'\"\n          from \\<open>V \\<in> Use n'\\<close> have \"(V,[],[]) \\<in> dependent_live_vars n'\"\n            by(rule dep_vars_Use)\n          from \\<open>slice_path as = x#xs\\<close> \\<open>as = a'#as'\\<close> \\<open>\\<not> x\\<close> \n          have \"\\<not> n -[a']\\<rightarrow>\\<^sub>d* n'\" by(simp add:targetnodes_def)\n          hence no_dep:\"\\<not> n -{V}[a']\\<rightarrow>\\<^sub>d\\<^sub>d n'\" by(fastforce dest:DynPDG_path_ddep)\n          with \\<open>last(targetnodes as) = n'\\<close> \\<open>as = a'#as'\\<close>\n            \\<open>(V,[],[]) \\<in> dependent_live_vars n'\\<close>\n          have \"(V,[a'],[a']) \\<in> dependent_live_vars n'\"\n            by(fastforce intro:dep_vars_Cons_keep)\n          with all \\<open>as = a'#as'\\<close> have \"state_val s V = state_val s' V\" by auto }\n        with \\<open>as = a'#as'\\<close> cases_x \\<open>es = ex#esx\\<close> \\<open>es' = ex'#esx'\\<close> \\<open>pred ex s\\<close>\n        show ?thesis by(cases \"kind a'\",auto)\n      qed\n    qed\n  next\n    case False\n    show ?thesis\n    proof(cases \"\\<forall>V xs. (V,xs,as') \\<in> dependent_live_vars n' \\<longrightarrow>\n                        state_val (transfer ex s) V = state_val (transfer ex' s') V\")\n      case True\n      hence imp':\"\\<forall>V xs. (V,xs,as') \\<in> dependent_live_vars n' \\<longrightarrow>\n                       state_val (transfer ex s) V = state_val (transfer ex' s') V\" .\n      from IH[OF \\<open>targetnode a' -as'\\<rightarrow>* n'\\<close> \\<open>xs \\<preceq>\\<^sub>b ys\\<close> \\<open>slice_path as' = xs\\<close>\n        \\<open>select_edge_kinds as' xs = esx\\<close> \\<open>select_edge_kinds as' ys = esx'\\<close> \n        this \\<open>preds esx' (transfer ex' s')\\<close>]\n      have all':\"\\<forall>V\\<in>Use n'. state_val (transfers esx (transfer ex s)) V =\n                             state_val (transfers esx' (transfer ex' s')) V\"\n        and \"preds esx (transfer ex s)\" by simp_all\n      have \"pred ex s\"\n      proof(cases ex)\n        case (Predicate Q)\n        with \\<open>slice_path as = x#xs\\<close> \\<open>as = a'#as'\\<close> \\<open>last(targetnodes as) = n'\\<close> ex \n        have \"ex = (\\<lambda>s. True)\\<^sub>\\<surd> \\<or> n -a'#as'\\<rightarrow>\\<^sub>d* n'\"\n          by(cases \"kind a'\",auto split:if_split_asm) \n        thus ?thesis\n        proof\n          assume \"ex = (\\<lambda>s. True)\\<^sub>\\<surd>\" thus ?thesis by simp\n        next\n          assume \"n -a'#as'\\<rightarrow>\\<^sub>d* n'\"\n          with \\<open>slice_path as = x#xs\\<close> \\<open>as = a'#as'\\<close> \\<open>last(targetnodes as) = n'\\<close> ex\n          have [simp]:\"ex = kind a'\" by clarsimp\n          with \\<open>x \\<longrightarrow> y\\<close> ex ex' have [simp]:\"ex' = ex\" by(cases x) auto\n          from \\<open>n -a'#as'\\<rightarrow>\\<^sub>d* n'\\<close> show ?thesis\n          proof(induct rule:DynPDG_path_rev_cases)\n            case DynPDG_path_Nil\n            hence False by simp\n            thus ?thesis by simp\n          next\n            case (DynPDG_path_cdep_Append n'' asx asx')\n            from \\<open>n -asx\\<rightarrow>\\<^sub>c\\<^sub>d n''\\<close>have \"asx \\<noteq> []\"\n              by(auto elim:DynPDG_edge.cases dest:dyn_control_dependence_path)\n            with \\<open>n -asx\\<rightarrow>\\<^sub>c\\<^sub>d n''\\<close> \\<open>n'' -asx'\\<rightarrow>\\<^sub>d* n'\\<close> \\<open>a'#as' = asx@asx'\\<close>\n            have cdep:\"\\<exists>as1 as2 n''. n -a'#as1\\<rightarrow>\\<^sub>c\\<^sub>d n'' \\<and> \n                                     n'' -as2\\<rightarrow>\\<^sub>d* n' \\<and> as' = as1@as2\"\n              by(cases asx) auto \n            { fix V assume \"V \\<in> Use n\"\n              with cdep \\<open>last(targetnodes as) = n'\\<close> \\<open>as = a'#as'\\<close>\n              have \"(V,[],as) \\<in> dependent_live_vars n'\"\n                by(fastforce intro:dep_vars_Cons_cdep)\n              with all have \"state_val s V = state_val s' V\" by blast }\n            with \\<open>valid_edge a'\\<close> \\<open>pred ex' s'\\<close>\n            show ?thesis by(fastforce elim:CFG_edge_Uses_pred_equal)\n          next\n            case (DynPDG_path_ddep_Append V n'' asx asx')\n            from \\<open>n -{V}asx\\<rightarrow>\\<^sub>d\\<^sub>d n''\\<close> obtain ai ais where \"asx = ai#ais\"\n              by(cases asx)(auto dest:DynPDG_ddep_edge_CFG_path)\n            with \\<open>n -{V}asx\\<rightarrow>\\<^sub>d\\<^sub>d n''\\<close> have \"sourcenode ai = n\"\n              by(fastforce dest:DynPDG_ddep_edge_CFG_path elim:path.cases)\n            from \\<open>n -{V}asx\\<rightarrow>\\<^sub>d\\<^sub>d n''\\<close> \\<open>asx = ai#ais\\<close>\n            have \"last(targetnodes asx) = n''\"\n              by(fastforce intro:path_targetnode dest:DynPDG_ddep_edge_CFG_path)\n            { fix V' assume \"V' \\<in> Use n\"\n              from \\<open>n -{V}asx\\<rightarrow>\\<^sub>d\\<^sub>d n''\\<close> have \"(V,[],[]) \\<in> dependent_live_vars n''\"\n                by(fastforce elim:DynPDG_edge.cases dep_vars_Use \n                            simp:dyn_data_dependence_def)\n              with \\<open>n'' -asx'\\<rightarrow>\\<^sub>d* n'\\<close> have \"(V,[],[]@asx') \\<in> dependent_live_vars n'\"\n                by(rule dependent_live_vars_dep_dependent_live_vars)\n              have \"(V',[],as) \\<in> dependent_live_vars n'\"\n              proof(cases \"asx' = []\")\n                case True\n                with \\<open>n'' -asx'\\<rightarrow>\\<^sub>d* n'\\<close> have \"n'' = n'\"\n                  by(fastforce intro:DynPDG_empty_path_eq_nodes)\n                with \\<open>n -{V}asx\\<rightarrow>\\<^sub>d\\<^sub>d n''\\<close> \\<open>V' \\<in> Use n\\<close> True \\<open>as = a'#as'\\<close>\n                  \\<open>a'#as' = asx@asx'\\<close>\n                show ?thesis by(fastforce intro:dependent_live_vars_ddep_empty_fst)\n              next\n                case False\n                with \\<open>n -{V}asx\\<rightarrow>\\<^sub>d\\<^sub>d n''\\<close> \\<open>asx = ai#ais\\<close>\n                  \\<open>(V,[],[]@asx') \\<in> dependent_live_vars n'\\<close>\n                have \"(V,ais@[],ais@asx') \\<in> dependent_live_vars n'\"\n                  by(fastforce intro:ddep_dependent_live_vars_keep_notempty)\n                from \\<open>n'' -asx'\\<rightarrow>\\<^sub>d* n'\\<close> False have \"last(targetnodes asx') = n'\"\n                  by -(rule path_targetnode,rule DynPDG_path_CFG_path)\n                with \\<open>(V,ais@[],ais@asx') \\<in> dependent_live_vars n'\\<close>\n                  \\<open>V' \\<in> Use n\\<close> \\<open>n -{V}asx\\<rightarrow>\\<^sub>d\\<^sub>d n''\\<close> \\<open>asx = ai#ais\\<close>\n                  \\<open>sourcenode ai = n\\<close> \\<open>last(targetnodes asx) = n''\\<close> False\n                have \"(V',[],ai#ais@asx') \\<in> dependent_live_vars n'\"\n                  by(fastforce intro:dep_vars_Cons_ddep simp:targetnodes_def)\n                with \\<open>asx = ai#ais\\<close> \\<open>a'#as' = asx@asx'\\<close> \\<open>as = a'#as'\\<close>\n                show ?thesis by simp\n              qed\n              with all have \"state_val s V' = state_val s' V'\" by blast }\n            with \\<open>pred ex' s'\\<close> \\<open>valid_edge a'\\<close>\n            show ?thesis by(fastforce elim:CFG_edge_Uses_pred_equal)\n          qed\n        qed\n      qed simp\n      with all' \\<open>preds esx (transfer ex s)\\<close> \\<open>es = ex#esx\\<close> \\<open>es' = ex'#esx'\\<close>\n      show ?thesis by simp\n    next\n      case False\n      then obtain V' xs' where \"(V',xs',as') \\<in> dependent_live_vars n'\"\n        and \"state_val (transfer ex s) V' \\<noteq> state_val (transfer ex' s') V'\"\n        by auto\n      show ?thesis\n      proof(cases \"n -a'#as'\\<rightarrow>\\<^sub>d* n'\")\n        case True\n        with \\<open>slice_path as = x#xs\\<close> \\<open>as = a'#as'\\<close> \\<open>last(targetnodes as) = n'\\<close> ex\n        have [simp]:\"ex = kind a'\" by clarsimp\n        with \\<open>x \\<longrightarrow> y\\<close> ex ex' have [simp]:\"ex' = ex\" by(cases x) auto\n        { fix V assume \"V \\<in> Use (sourcenode a')\"\n          hence \"(V,[],[]) \\<in> dependent_live_vars (sourcenode a')\"\n            by(rule dep_vars_Use)\n          with \\<open>n -a'#as'\\<rightarrow>\\<^sub>d* n'\\<close> have \"(V,[],[]@a'#as') \\<in> dependent_live_vars n'\"\n            by(fastforce intro:dependent_live_vars_dep_dependent_live_vars)\n          with all \\<open>as = a'#as'\\<close> have \"state_val s V = state_val s' V\"\n            by fastforce }\n        with \\<open>pred ex' s'\\<close> \\<open>valid_edge a'\\<close> have \"pred ex s\"\n          by(fastforce intro:CFG_edge_Uses_pred_equal)\n        show ?thesis\n        proof(cases \"V' \\<in> Def n\")\n          case True\n          with \\<open>state_val (transfer ex s) V' \\<noteq> state_val (transfer ex' s') V'\\<close>\n            \\<open>valid_edge a'\\<close> \\<open>pred ex' s'\\<close> \\<open>pred ex s\\<close>\n            CFG_edge_transfer_uses_only_Use[of a' s s']\n          obtain V'' where \"V'' \\<in> Use n\"\n            and \"state_val s V'' \\<noteq> state_val s' V''\"\n            by auto\n          from True \\<open>(V',xs',as') \\<in> dependent_live_vars n'\\<close>\n            \\<open>targetnode a' -as'\\<rightarrow>* n'\\<close> \\<open>last(targetnodes as) = n'\\<close> \\<open>as = a'#as'\\<close>\n            \\<open>valid_edge a'\\<close> \\<open>n = sourcenode a'\\<close>[THEN sym]\n          have \"n -{V'}a'#xs'\\<rightarrow>\\<^sub>d\\<^sub>d last(targetnodes (a'#xs'))\"\n            by -(drule dependent_live_vars_dependent_edge,\n              auto dest!: dependent_live_vars_dependent_edge \n                   dest:DynPDG_ddep_edge_CFG_path path_targetnode \n                   simp del:\\<open>n = sourcenode a'\\<close>)\n          with \\<open>(V',xs',as') \\<in> dependent_live_vars n'\\<close> \\<open>V'' \\<in> Use n\\<close>\n            \\<open>last(targetnodes as) = n'\\<close> \\<open>as = a'#as'\\<close>\n          have \"(V'',[],as) \\<in> dependent_live_vars n'\" \n            by(fastforce intro:dep_vars_Cons_ddep)\n          with all have \"state_val s V'' = state_val s' V''\" by blast\n          with \\<open>state_val s V'' \\<noteq> state_val s' V''\\<close> have False by simp\n          thus ?thesis by simp\n        next\n          case False\n          with \\<open>valid_edge a'\\<close> \\<open>pred ex s\\<close>\n          have \"state_val (transfer (kind a') s) V' = state_val s V'\"\n            by(fastforce intro:CFG_edge_no_Def_equal)\n          moreover\n          from False \\<open>valid_edge a'\\<close> \\<open>pred ex' s'\\<close>\n          have \"state_val (transfer (kind a') s') V' = state_val s' V'\"\n            by(fastforce intro:CFG_edge_no_Def_equal)\n          ultimately have \"state_val s V' \\<noteq> state_val s' V'\"\n            using \\<open>state_val (transfer ex s) V' \\<noteq> state_val (transfer ex' s') V'\\<close>\n            by simp\n          from False have \"\\<not> n -{V'}a'#xs'\\<rightarrow>\\<^sub>d\\<^sub>d \n                           last(targetnodes (a'#xs'))\"\n            by(auto elim:DynPDG_edge.cases simp:dyn_data_dependence_def)\n          with \\<open>(V',xs',as') \\<in> dependent_live_vars n'\\<close> \\<open>last(targetnodes as) = n'\\<close>\n            \\<open>as = a'#as'\\<close>\n          have \"(V',a'#xs',a'#as') \\<in> dependent_live_vars n'\"\n            by(fastforce intro:dep_vars_Cons_keep)\n          with \\<open>as = a'#as'\\<close> all have \"state_val s V' = state_val s' V'\" by auto\n          with \\<open>state_val s V' \\<noteq> state_val s' V'\\<close> have False by simp\n          thus ?thesis by simp\n        qed\n      next\n        case False\n        { assume \"V' \\<in> Def n\"\n          with \\<open>(V',xs',as') \\<in> dependent_live_vars n'\\<close> \\<open>targetnode a' -as'\\<rightarrow>* n'\\<close>\n            \\<open>valid_edge a'\\<close>\n          have \"n -a'#as'\\<rightarrow>\\<^sub>d* n'\"\n            by -(drule dependent_live_vars_dependent_edge,\n              auto dest:DynPDG_path_ddep DynPDG_path_Append)\n          with False have \"False\" by simp }\n        hence \"V' \\<notin> Def (sourcenode a')\" by fastforce\n        from False \\<open>slice_path as = x#xs\\<close> \\<open>as = a'#as'\\<close>\n          \\<open>last(targetnodes as) = n'\\<close> \\<open>as' \\<noteq> []\\<close>\n        have \"\\<not> x\" by(auto simp:targetnodes_def)\n        with ex have cases:\"ex = (case kind a' of \\<Up>f \\<Rightarrow> \\<Up>id | (Q)\\<^sub>\\<surd> \\<Rightarrow> (\\<lambda>s. True)\\<^sub>\\<surd>)\"\n          by simp\n        have \"state_val s V' \\<noteq> state_val s' V'\"\n        proof(cases y)\n          case True\n          with ex' have [simp]:\"ex' = kind a'\" by simp\n          from \\<open>V' \\<notin> Def (sourcenode a')\\<close> \\<open>valid_edge a'\\<close> \\<open>pred ex' s'\\<close>\n          have states_eq:\"state_val (transfer (kind a') s') V' = state_val s' V'\"\n            by(fastforce intro:CFG_edge_no_Def_equal)\n          from cases have \"state_val s V' = state_val (transfer ex s) V'\"\n            by(cases \"kind a'\") auto\n          with states_eq\n            \\<open>state_val (transfer ex s) V' \\<noteq> state_val (transfer ex' s') V'\\<close>\n          show ?thesis by simp\n        next\n          case False\n          with ex' have \"ex' = (case kind a' of \\<Up>f \\<Rightarrow> \\<Up>id | (Q)\\<^sub>\\<surd> \\<Rightarrow> (\\<lambda>s. True)\\<^sub>\\<surd>)\"\n            by simp\n          with cases have \"state_val s V' = state_val (transfer ex s) V'\"\n            and \"state_val s' V' = state_val (transfer ex' s') V'\"\n            by(cases \"kind a'\",auto)+\n          with \\<open>state_val (transfer ex s) V' \\<noteq> state_val (transfer ex' s') V'\\<close> \n          show ?thesis by simp\n        qed\n        from \\<open>V' \\<notin> Def (sourcenode a')\\<close> \n        have \"\\<not> n -{V'}a'#xs'\\<rightarrow>\\<^sub>d\\<^sub>d last(targetnodes (a'#xs'))\"\n          by(auto elim:DynPDG_edge.cases simp:dyn_data_dependence_def)\n        with \\<open>(V',xs',as') \\<in> dependent_live_vars n'\\<close> \\<open>last(targetnodes as) = n'\\<close>\n          \\<open>as = a'#as'\\<close>\n        have \"(V',a'#xs',a'#as') \\<in> dependent_live_vars n'\"\n          by(fastforce intro:dep_vars_Cons_keep)\n        with \\<open>as = a'#as'\\<close> all have \"state_val s V' = state_val s' V'\" by auto\n        with \\<open>state_val s V' \\<noteq> state_val s' V'\\<close> have False by simp\n        thus ?thesis by simp\n      qed\n    qed\n  qed\nqed simp_all\n\n\ntheorem fundamental_property_of_path_slicing:\n  assumes \"n -as\\<rightarrow>* n'\" and \"preds (kinds as) s\"\n  shows \"(\\<forall>V \\<in> Use n'. state_val (transfers (slice_kinds as) s) V = \n                         state_val (transfers (kinds as) s) V)\" \n  and \"preds (slice_kinds as) s\"\nproof -\n  have \"length as = length (slice_path as)\" by(simp add:slice_path_length)\n  hence \"slice_path as \\<preceq>\\<^sub>b replicate (length as) True\"\n    by(simp add:maximal_element)\n  have \"select_edge_kinds as (replicate (length as) True) = kinds as\"\n    by(rule select_edge_kinds_max_bv)\n  with \\<open>n -as\\<rightarrow>* n'\\<close> \\<open>slice_path as \\<preceq>\\<^sub>b replicate (length as) True\\<close>\n    \\<open>preds (kinds as) s\\<close> \n  have \"(\\<forall>V\\<in>Use n'. state_val (transfers (slice_kinds as) s) V =\n       state_val (transfers (kinds as) s) V) \\<and> preds (slice_kinds as) s\"\n    by -(rule slice_path_leqs_information_same_Uses,simp_all add:slice_kinds_def)\n  thus \"\\<forall>V\\<in>Use n'. state_val (transfers (slice_kinds as) s) V =\n    state_val (transfers (kinds as) s) V\" and \"preds (slice_kinds as) s\"\n    by simp_all\nqed\n\nend\n\n\nsubsection \\<open>The fundamental property of (dynamic) slicing related to the semantics\\<close>\n\nlocale BackwardPathSlice_wf = \n  DynPDG sourcenode targetnode kind valid_edge Entry Def Use state_val Exit \n    dyn_control_dependence +\n  CFG_semantics_wf sourcenode targetnode kind valid_edge Entry sem identifies\n  for sourcenode :: \"'edge \\<Rightarrow> 'node\" and targetnode :: \"'edge \\<Rightarrow> 'node\"\n  and kind :: \"'edge \\<Rightarrow> 'state edge_kind\" and valid_edge :: \"'edge \\<Rightarrow> bool\"\n  and Entry :: \"'node\" (\"'('_Entry'_')\") and Def :: \"'node \\<Rightarrow> 'var set\"\n  and Use :: \"'node \\<Rightarrow> 'var set\" and state_val :: \"'state \\<Rightarrow> 'var \\<Rightarrow> 'val\"\n  and dyn_control_dependence :: \"'node \\<Rightarrow> 'node \\<Rightarrow> 'edge list \\<Rightarrow> bool\" \n    (\"_ controls _ via _\" [51, 0, 0] 1000)\n  and Exit :: \"'node\" (\"'('_Exit'_')\") \n  and sem :: \"'com \\<Rightarrow> 'state \\<Rightarrow> 'com \\<Rightarrow> 'state \\<Rightarrow> bool\" \n    (\"((1\\<langle>_,/_\\<rangle>) \\<Rightarrow>/ (1\\<langle>_,/_\\<rangle>))\" [0,0,0,0] 81)\n  and identifies :: \"'node \\<Rightarrow> 'com \\<Rightarrow> bool\" (\"_ \\<triangleq> _\" [51, 0] 80) \n\nbegin\n\ntheorem fundamental_property_of_path_slicing_semantically:\n  assumes \"n \\<triangleq> c\" and \"\\<langle>c,s\\<rangle> \\<Rightarrow> \\<langle>c',s'\\<rangle>\"\n  obtains n' as where \"n -as\\<rightarrow>* n'\" and \"preds (slice_kinds as) s\" \n  and \"n' \\<triangleq> c'\" \n  and \"\\<forall>V \\<in> Use n'. state_val (transfers (slice_kinds as) s) V = \n                     state_val s' V\"\nproof(atomize_elim)\n  from \\<open>n \\<triangleq> c\\<close> \\<open>\\<langle>c,s\\<rangle> \\<Rightarrow> \\<langle>c',s'\\<rangle>\\<close> obtain n' as where \"n -as\\<rightarrow>* n'\"\n    and \"transfers (kinds as) s = s'\"\n    and \"preds (kinds as) s\"\n    and \"n' \\<triangleq> c'\"\n    by(fastforce dest:fundamental_property)\n  with \\<open>n -as\\<rightarrow>* n'\\<close> \\<open>preds (kinds as) s\\<close> \n  have \"\\<forall>V \\<in> Use n'. state_val (transfers (slice_kinds as) s) V =\n    state_val (transfers (kinds as) s) V\" and \"preds (slice_kinds as) s\"\n    by -(rule fundamental_property_of_path_slicing,simp_all)+\n  with \\<open>transfers (kinds as) s = s'\\<close> have \"\\<forall>V \\<in> Use n'. \n    state_val (transfers (slice_kinds as) s) V =\n    state_val s' V\" by simp\n  with \\<open>n -as\\<rightarrow>* n'\\<close> \\<open>preds (slice_kinds as) s\\<close> \\<open>n' \\<triangleq> c'\\<close>\n  show \"\\<exists>as n'. n -as\\<rightarrow>* n' \\<and> preds (slice_kinds as) s \\<and> n' \\<triangleq> c' \\<and>\n       (\\<forall>V\\<in>Use n'. state_val (transfers (slice_kinds as) s) V = state_val s' V)\"\n    by blast\nqed\n\n\nend\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Slicing/Dynamic/DynSlice.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.546738151984614, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.2520554619551142}}
{"text": "theory flash14Rev imports flashPub\nbegin\nsection{*Main defintions*}\nlemma NI_FAckVsInv14:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_InvVsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_InvAck_1VsInv14:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by(cut_tac a1 a2 a3 a4, auto) \n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto \n qed\n  lemma NI_InvAck_1_HomeVsInv14:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_InvAck_2VsInv14:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Local_GetX_GetXVsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''UniMsg_Cmd'' iInv1) )  ( Const UNI_GetX ))    ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak1VsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak2VsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_Nak3VsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX1VsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv14:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10VsInv14:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX10_homeVsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_GetX_PutX11VsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_GetVsInv14:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Local_Get_Nak1VsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak2VsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Nak3VsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put1VsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put2VsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_Get_Put3VsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Local_PutVsInv14:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_Local_PutXAcksDoneVsInv14:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_NakVsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Nak_ClearVsInv14:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_Nak_HomeVsInv14:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_Remote_GetX_NakVsInv14:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_Nak_HomeVsInv14:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Remote_GetX_PutXVsInv14:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_GetX_PutX_HomeVsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Nak1VsInv14:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_Remote_Get_Nak2VsInv14:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Put1VsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_Get_Put2VsInv14:  \n    (*Rule2VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iInv1 \\<le> N\" and  a4:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))   \\<or>((iRule1~=iInv1 )\\<and>iRule2=iInv1)   \\<or>((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  a3  a4  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1\\<and>(iRule2~=iInv1 ))\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>iRule2=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3  a4  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 )\\<and>(iRule2~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  a3  a4  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutVsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                     have allCases:\"formEval  ( eqn ( IVar ( Para ''InvMarked'' iInv1) )  ( Const true ))  s  \\<or>formEval   (neg ( eqn ( IVar ( Para ''InvMarked'' iInv1) )  ( Const true )) )  s  \"  \n\t                      by auto \n\n    moreover\n                       {assume c1:\"formEval ( eqn ( IVar ( Para ''InvMarked'' iInv1) )  ( Const true ))  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1  c1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n\n    moreover\n                       {assume c1:\"formEval  (neg ( eqn ( IVar ( Para ''InvMarked'' iInv1) )  ( Const true )) )  s\"\n\n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1  c1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n    }\n   ultimately have \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_Remote_PutXVsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma NI_ReplaceVsInv14:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_ReplaceHomeVsInv14:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_ReplaceHomeShrVldVsInv14:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_ReplaceShrVldVsInv14:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma NI_ShWbVsInv14:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma NI_WbVsInv14:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_GetX_GetX1VsInv14:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_GetX_GetX2VsInv14:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_GetX_PutX1VsInv14:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_GetX_PutX2VsInv14:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_GetX_PutX3VsInv14:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_GetX_PutX4VsInv14:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_Get_GetVsInv14:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_Get_PutVsInv14:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_PutXVsInv14:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Local_ReplaceVsInv14:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n lemma PI_Remote_GetVsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_GetXVsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1  a2  b1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Para ''CacheState'' iInv1) )  ( Const CACHE_I ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_PutXVsInv14:  \n  (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have allCases:\"(iRule1=iInv1)   \\<or>((iRule1~=iInv1 ))   \"  \n\t                      by( cut_tac  a1  a2  , auto) \nmoreover\n                {assume b1:\"(iRule1=iInv1)\"\n\n                  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  b1 , auto)\n\n         \n        done\n\n        then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\t                }\nmoreover\n                {assume b1:\"((iRule1~=iInv1 ))\"\n\n                  have \"?P2 s\"\n\n   \n  apply(cut_tac  a1  a2  b1 , auto intro!:forallVars1 simp  add :invHoldForRule2'_def varsOfVar_def)\n       \n  done\n\n  then  have \"?P1 s\\<or> ?P2 s \\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\t                }\n   ultimately show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n\t                         by metis\n\n                     \n\n\n qed\nlemma PI_Remote_ReplaceVsInv14:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma StoreVsInv14:  \n    (*Rule1VsPInv1*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by  (cut_tac  a1  a2 , auto)\n lemma StoreHomeVsInv14:  \n    (*Rule0VsPInv1*)\n  assumes   a1:\"iInv1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv14  iInv1 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n    by (cut_tac  a1 , auto)\n end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash14Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5467381519846138, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.25205546195511414}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\n(* License: BSD, terms see file ./LICENSE *)\n\ntheory Vanilla32_Preliminaries\nimports CTypes\nbegin\n\nsection \"Words and Pointers\"\n\ninstantiation unit :: c_type\nbegin\ninstance ..\nend\n\ndefinition \"unit_tag \\<equiv> TypDesc (TypScalar 1 0\n      (\\<lparr> field_access = (\\<lambda>v bs. [0]), field_update = (\\<lambda>bs v. ())\\<rparr>)) ''unit''\"\n\ndeclare unit_tag_def [simp]\n\noverloading typ_info_unit \\<equiv> typ_info_t begin\n  definition typ_info_unit [simp]: \"typ_info_unit (x::unit itself) \\<equiv> unit_tag\"\nend\n\ninstantiation unit :: mem_type\nbegin\n  definition\n    to_bytes_unit :: \"unit \\<Rightarrow> byte list\" where\n    \"to_bytes_unit a \\<equiv> [0]\"\n\n  definition\n    from_bytes_unit :: \"byte list \\<Rightarrow> unit\" where\n    \"from_bytes_unit bs \\<equiv> ()\"\n\n  definition\n    size_of_unit :: \"unit itself \\<Rightarrow> nat\" where\n    \"size_of_unit x \\<equiv> 0\"\n\n  definition\n    align_of_unit :: \"unit itself \\<Rightarrow> nat\" where\n    \"align_of_unit x \\<equiv> 1\"\n\n  instance\n    apply intro_classes\n    apply (auto simp: size_of_def align_of_def align_field_def addr_card\n                      wf_lf_def fd_cons_desc_def\n                      fd_cons_double_update_def fd_cons_update_access_def\n                      fd_cons_access_update_def fd_cons_length_def)\n  done\nend\n\ndefinition\n  \"bogus_log2lessthree (n::nat) ==\n             if n = 128 then 4\n             else if n = 64 then (3::nat)\n             else if n = 32 then 2\n             else if n = 16 then 1\n             else if n = 8 then 0\n             else undefined\"\ndefinition\n  \"len_exp (x::('a::len) itself) \\<equiv> bogus_log2lessthree (len_of TYPE('a))\"\n\nlemma lx8' [simp] : \"len_exp (x::8 itself) = 0\"\nby (simp add: len_exp_def bogus_log2lessthree_def)\n\nlemma lx16' [simp]: \"len_exp (x::16 itself) = 1\"\nby (simp add: len_exp_def bogus_log2lessthree_def)\n\nlemma lx32' [simp]: \"len_exp (x::32 itself) = 2\"\nby (simp add: len_exp_def bogus_log2lessthree_def)\n\nlemma lx64' [simp]: \"len_exp (x::64 itself) = 3\"\nby (simp add: len_exp_def bogus_log2lessthree_def)\n\nlemma lx_signed' [simp]: \"len_exp (x::('a::len) signed itself) = len_exp (TYPE('a))\"\n  by (simp add: len_exp_def)\n\nclass len8 = len +\n  (* this constraint gives us (in the most convoluted way possible) that we're only\n     interested in words with a length that is divisible by 8 *)\n  assumes len8_bytes: \"len_of TYPE('a::len) = 8 * (2^len_exp TYPE('a))\"\n  (* len8_len class gives us that the words are \\<le> than 128 bits.\n     This is a wacky restriction really, but we're really only interested in words\n     up to 64 bits, so who cares. *)\n  assumes len8_width: \"len_of TYPE('a::len) \\<le> 128\"\nbegin\n\nlemma len8_size:\n  \"len_of TYPE('a) div 8 < addr_card\"\n  apply(subgoal_tac \"len_of TYPE('a) \\<le> 128\")\n   apply(simp add: addr_card)\n  apply(rule len8_width)\n  done\n\nlemma len8_dv8:\n  \"8 dvd len_of TYPE('a)\"\n  by (simp add: len8_bytes)\n\nlemma len8_pow:\n  \"\\<exists>k. len_of TYPE('a) div 8 = 2^k\"\n  by (simp add: len8_bytes)\n\nend\n\nfun\n  nat_to_bin_string :: \"nat \\<Rightarrow> char list\"\n  where\n  ntbs: \"nat_to_bin_string n = (if (n = 0) then ''0'' else (if n mod 2 = 1 then CHR ''1'' else CHR ''0'') # nat_to_bin_string (n div 2))\"\n\ndeclare nat_to_bin_string.simps [simp del]\n\nlemma nat_to_bin_string_simps:\n  \"nat_to_bin_string 0 = ''0''\"\n  \"n > 0 \\<Longrightarrow> nat_to_bin_string n =\n      (if n mod 2 = 1 then CHR ''1'' else CHR ''0'') # nat_to_bin_string (n div 2)\"\n  apply (induct n, auto simp: nat_to_bin_string.simps)\n  done\n\ninstantiation word :: (len8) c_type\nbegin\ninstance ..\nend\n\ninstance signed :: (len8) len8\n  apply intro_classes\n   apply (metis len8_bytes len_exp_def len_signed)\n  apply (metis len8_width len_signed)\n  done\n\nend\n", "meta": {"author": "NICTA", "repo": "l4v", "sha": "3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b", "save_path": "github-repos/isabelle/NICTA-l4v", "path": "github-repos/isabelle/NICTA-l4v/l4v-3c3514fe99082f7b6a6fb8445b8dfc592ff7f02b/tools/c-parser/umm_heap/Vanilla32_Preliminaries.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6187804478040617, "lm_q2_score": 0.40733340004593027, "lm_q1q2_score": 0.2520499436859717}}
{"text": "header{*The Needham-Schroeder Public-Key Protocol against the General Attacker*}\n\ntheory NS_Public_Bad_GA imports PublicGA begin\n\ninductive_set ns_public :: \"event list set\"\n  where\n\n   Nil:  \"[] \\<in> ns_public\"\n\n | Fake: \"\\<lbrakk>evsf \\<in> ns_public;  X \\<in> synth (analz (knows A evsf))\\<rbrakk>\n          \\<Longrightarrow> Says A B X  # evsf \\<in> ns_public\"\n\n | Reception: \"\\<lbrakk> evsr \\<in> ns_public; Says A B X \\<in> set evsr \\<rbrakk>\n                \\<Longrightarrow> Gets B X # evsr \\<in> ns_public\"\n\n | NS1:  \"\\<lbrakk>evs1 \\<in> ns_public;  Nonce NA \\<notin> used evs1\\<rbrakk>\n          \\<Longrightarrow> Says A B (Crypt (pubEK B) \\<lbrace>Nonce NA, Agent A\\<rbrace>)\n                # evs1  \\<in>  ns_public\"\n\n | NS2:  \"\\<lbrakk>evs2 \\<in> ns_public;  Nonce NB \\<notin> used evs2;\n           Gets B (Crypt (pubEK B) \\<lbrace>Nonce NA, Agent A\\<rbrace>) \\<in> set evs2\\<rbrakk>\n          \\<Longrightarrow> Says B A (Crypt (pubEK A) \\<lbrace>Nonce NA, Nonce NB\\<rbrace>)\n                # evs2  \\<in>  ns_public\"\n\n | NS3:  \"\\<lbrakk>evs3 \\<in> ns_public;\n           Says A  B (Crypt (pubEK B) \\<lbrace>Nonce NA, Agent A\\<rbrace>) \\<in> set evs3;\n           Gets A (Crypt (pubEK A) \\<lbrace>Nonce NA, Nonce NB\\<rbrace>) \\<in> set evs3\\<rbrakk>\n          \\<Longrightarrow> Says A B (Crypt (pubEK B) (Nonce NB)) # evs3 \\<in> ns_public\"\n\n\nlemma NS_no_Notes:\n \"evs \\<in> ns_public \\<Longrightarrow> Notes A X \\<notin> set evs\"\napply (erule ns_public.induct)\napply (simp_all)\ndone\n\ntext{*Confidentiality treatment in separate theory file*}\n\nend", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Inductive_Confidentiality/GeneralAttacker/NS_Public_Bad_GA.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6187804337438501, "lm_q2_score": 0.40733340004593027, "lm_q1q2_score": 0.25204993795877795}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      Termination.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\nsection {* Terminating Programs *}\n\ntheory Termination imports Semantic begin\n\nsubsection {* Inductive Characterisation: @{text \"\\<Gamma>\\<turnstile>c\\<down>s\"}*}\n\ninductive \"terminates\"::\"('s,'p,'f) body \\<Rightarrow> ('s,'p,'f) com \\<Rightarrow> ('s,'f) xstate \\<Rightarrow> bool\"\n  (\"_\\<turnstile>_ \\<down> _\" [60,20,60] 89)\n  for  \\<Gamma>::\"('s,'p,'f) body\"\nwhere\n  Skip: \"\\<Gamma>\\<turnstile>Skip \\<down>(Normal s)\"\n\n| Basic: \"\\<Gamma>\\<turnstile>Basic f \\<down>(Normal s)\"\n\n| Spec: \"\\<Gamma>\\<turnstile>Spec r \\<down>(Normal s)\"\n\n| Guard: \"\\<lbrakk>s\\<in>g; \\<Gamma>\\<turnstile>c\\<down>(Normal s)\\<rbrakk> \n          \\<Longrightarrow> \n          \\<Gamma>\\<turnstile>Guard f g c\\<down>(Normal s)\"\n\n| GuardFault: \"s\\<notin>g  \n               \\<Longrightarrow> \n               \\<Gamma>\\<turnstile>Guard f g c\\<down>(Normal s)\"\n\n\n| Fault [intro,simp]: \"\\<Gamma>\\<turnstile>c\\<down>Fault f\" \n\n\n| Seq: \"\\<lbrakk>\\<Gamma>\\<turnstile>c\\<^sub>1\\<down>Normal s; \\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> s' \\<longrightarrow> \\<Gamma>\\<turnstile>c\\<^sub>2\\<down>s'\\<rbrakk>\n        \\<Longrightarrow>\n        \\<Gamma>\\<turnstile>Seq c\\<^sub>1 c\\<^sub>2\\<down>(Normal s)\"\n\n| CondTrue: \"\\<lbrakk>s \\<in> b; \\<Gamma>\\<turnstile>c\\<^sub>1\\<down>(Normal s)\\<rbrakk> \n             \\<Longrightarrow>  \n             \\<Gamma>\\<turnstile>Cond b c\\<^sub>1 c\\<^sub>2\\<down>(Normal s)\"\n\n\n| CondFalse: \"\\<lbrakk>s \\<notin> b; \\<Gamma>\\<turnstile>c\\<^sub>2\\<down>(Normal s)\\<rbrakk> \n             \\<Longrightarrow>  \n             \\<Gamma>\\<turnstile>Cond b c\\<^sub>1 c\\<^sub>2\\<down>(Normal s)\"\n\n\n| WhileTrue: \"\\<lbrakk>s \\<in> b; \\<Gamma>\\<turnstile>c\\<down>(Normal s); \n               \\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> s' \\<longrightarrow> \\<Gamma>\\<turnstile>While b c\\<down>s'\\<rbrakk> \n              \\<Longrightarrow>  \n              \\<Gamma>\\<turnstile>While b c\\<down>(Normal s)\"\n\n| WhileFalse: \"\\<lbrakk>s \\<notin> b\\<rbrakk> \n               \\<Longrightarrow>  \n               \\<Gamma>\\<turnstile>While b c\\<down>(Normal s)\"\n\n| Call:  \"\\<lbrakk>\\<Gamma> p=Some bdy;\\<Gamma>\\<turnstile>bdy\\<down>(Normal s)\\<rbrakk> \n          \\<Longrightarrow> \n          \\<Gamma>\\<turnstile>Call p\\<down>(Normal s)\"\n\n| CallUndefined:  \"\\<lbrakk>\\<Gamma> p = None\\<rbrakk> \n                   \\<Longrightarrow> \n                   \\<Gamma>\\<turnstile>Call p\\<down>(Normal s)\"\n\n| Stuck [intro,simp]: \"\\<Gamma>\\<turnstile>c\\<down>Stuck\"\n \n| DynCom:  \"\\<lbrakk>\\<Gamma>\\<turnstile>(c s)\\<down>(Normal s)\\<rbrakk> \n             \\<Longrightarrow> \n             \\<Gamma>\\<turnstile>DynCom c\\<down>(Normal s)\"\n\n| Throw: \"\\<Gamma>\\<turnstile>Throw\\<down>(Normal s)\"\n\n| Abrupt [intro,simp]: \"\\<Gamma>\\<turnstile>c\\<down>Abrupt s\"\n\n| Catch: \"\\<lbrakk>\\<Gamma>\\<turnstile>c\\<^sub>1\\<down>Normal s; \n           \\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s \\<rangle> \\<Rightarrow> Abrupt s' \\<longrightarrow> \\<Gamma>\\<turnstile>c\\<^sub>2\\<down>Normal s'\\<rbrakk>\n          \\<Longrightarrow>\n          \\<Gamma>\\<turnstile>Catch c\\<^sub>1 c\\<^sub>2\\<down>Normal s\"  \n\n\ninductive_cases terminates_elim_cases [cases set]:\n  \"\\<Gamma>\\<turnstile>Skip \\<down> s\"\n  \"\\<Gamma>\\<turnstile>Guard f g c \\<down> s\"\n  \"\\<Gamma>\\<turnstile>Basic f \\<down> s\"\n  \"\\<Gamma>\\<turnstile>Spec r \\<down> s\"\n  \"\\<Gamma>\\<turnstile>Seq c1 c2 \\<down> s\"\n  \"\\<Gamma>\\<turnstile>Cond b c1 c2 \\<down> s\"\n  \"\\<Gamma>\\<turnstile>While b c \\<down> s\"\n  \"\\<Gamma>\\<turnstile>Call p \\<down> s\"\n  \"\\<Gamma>\\<turnstile>DynCom c \\<down> s\"\n  \"\\<Gamma>\\<turnstile>Throw \\<down> s\"\n  \"\\<Gamma>\\<turnstile>Catch c1 c2 \\<down> s\"\n\ninductive_cases terminates_Normal_elim_cases [cases set]:\n  \"\\<Gamma>\\<turnstile>Skip \\<down> Normal s\"\n  \"\\<Gamma>\\<turnstile>Guard f g c \\<down> Normal s\"\n  \"\\<Gamma>\\<turnstile>Basic f \\<down> Normal s\"\n  \"\\<Gamma>\\<turnstile>Spec r \\<down> Normal s\"\n  \"\\<Gamma>\\<turnstile>Seq c1 c2 \\<down> Normal s\"\n  \"\\<Gamma>\\<turnstile>Cond b c1 c2 \\<down> Normal s\"\n  \"\\<Gamma>\\<turnstile>While b c \\<down> Normal s\"\n  \"\\<Gamma>\\<turnstile>Call p \\<down> Normal s\"\n  \"\\<Gamma>\\<turnstile>DynCom c \\<down> Normal s\"\n  \"\\<Gamma>\\<turnstile>Throw \\<down> Normal s\"\n  \"\\<Gamma>\\<turnstile>Catch c1 c2 \\<down> Normal s\"\n\nlemma terminates_Skip': \"\\<Gamma>\\<turnstile>Skip \\<down> s\"\n  by (cases s) (auto intro: terminates.intros)\n\nlemma terminates_Call_body: \n \"\\<Gamma> p=Some bdy\\<Longrightarrow>\\<Gamma>\\<turnstile>Call  p \\<down>s = \\<Gamma>\\<turnstile>(the (\\<Gamma> p))\\<down>s\"\n  by (cases s)\n     (auto elim: terminates_Normal_elim_cases intro: terminates.intros)\n\nlemma terminates_Normal_Call_body: \n \"p \\<in> dom \\<Gamma> \\<Longrightarrow>\n  \\<Gamma>\\<turnstile>Call p \\<down>Normal s = \\<Gamma>\\<turnstile>(the (\\<Gamma> p))\\<down>Normal s\"\n  by (auto elim: terminates_Normal_elim_cases intro: terminates.intros)\n\nlemma terminates_implies_exec:\n  assumes terminates: \"\\<Gamma>\\<turnstile>c\\<down>s\"\n  shows \"\\<exists>t. \\<Gamma>\\<turnstile>\\<langle>c,s\\<rangle> \\<Rightarrow> t\"\nusing terminates\nproof (induct)\n  case Skip thus ?case by (iprover intro: exec.intros)\nnext\n  case Basic thus ?case by (iprover intro: exec.intros)\nnext\n  case (Spec r s) thus ?case\n    by (cases \"\\<exists>t. (s,t)\\<in> r\") (auto intro: exec.intros)\nnext\n  case Guard thus ?case by (iprover intro: exec.intros)\nnext\n  case GuardFault thus ?case by (iprover intro: exec.intros)\nnext\n  case Fault thus ?case by (iprover intro: exec.intros)\nnext\n  case Seq thus ?case by (iprover intro: exec_Seq')\nnext\n  case CondTrue thus ?case by (iprover intro: exec.intros)\nnext\n  case CondFalse thus ?case by (iprover intro: exec.intros)\nnext\n  case WhileTrue thus ?case by (iprover intro: exec.intros)\nnext\n  case WhileFalse thus ?case by (iprover intro: exec.intros)\nnext\n  case (Call p bdy s) \n  then obtain s' where \n    \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal s \\<rangle> \\<Rightarrow> s'\"\n    by iprover\n  moreover have \"\\<Gamma> p = Some bdy\" by fact\n  ultimately show ?case \n    by (cases s') (iprover intro: exec.intros)+\nnext\n  case CallUndefined thus ?case by (iprover intro: exec.intros)\nnext\n  case Stuck thus ?case by (iprover intro: exec.intros)\nnext\n  case DynCom thus ?case by (iprover intro: exec.intros)\nnext\n  case Throw thus ?case by (iprover intro: exec.intros)\nnext\n  case Abrupt thus ?case by (iprover intro: exec.intros) \nnext\n  case (Catch c1 s c2) \n  then obtain s' where exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow> s'\"\n    by iprover\n  thus ?case\n  proof (cases s')\n    case (Normal s'')\n    with exec_c1 show ?thesis by (auto intro!: exec.intros)\n  next\n    case (Abrupt s'')\n    with exec_c1 Catch.hyps\n    obtain t where \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal s'' \\<rangle> \\<Rightarrow> t\"\n      by auto\n    with exec_c1 Abrupt show ?thesis by (auto intro: exec.intros)\n  next\n    case Fault\n    with exec_c1 show ?thesis by (auto intro!: exec.CatchMiss)\n  next\n    case Stuck\n    with exec_c1 show ?thesis by (auto intro!: exec.CatchMiss)\n  qed\nqed\n\nlemma terminates_block: \n\"\\<lbrakk>\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s);\n  \\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow> \\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\\<rbrakk>\n \\<Longrightarrow> \\<Gamma>\\<turnstile>block init bdy return c \\<down> Normal s\"\napply (unfold block_def)\napply (fastforce intro: terminates.intros elim!: exec_Normal_elim_cases \n        dest!: not_isAbrD)\ndone\n\nlemma terminates_block_elim [cases set, consumes 1]:\nassumes termi: \"\\<Gamma>\\<turnstile>block init bdy return c \\<down> Normal s\"\nassumes e: \"\\<lbrakk>\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s);\n          \\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow> \\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\n         \\<rbrakk> \\<Longrightarrow> P\"\nshows P\nproof -\n  have \"\\<Gamma>\\<turnstile>\\<langle>Basic init,Normal s\\<rangle> \\<Rightarrow> Normal (init s)\"\n    by (auto intro: exec.intros)\n  with termi\n  have \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\"\n    apply (unfold block_def)\n    apply (elim terminates_Normal_elim_cases)\n    by simp\n  moreover\n  {\n    fix t\n    assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\" \n    have \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n    proof -\n      from exec_bdy \n      have \"\\<Gamma>\\<turnstile>\\<langle>Catch (Seq (Basic init) bdy) \n                               (Seq (Basic (return s)) Throw),Normal s\\<rangle> \\<Rightarrow> Normal t\"\n        by (fastforce intro: exec.intros)\n      with termi have \"\\<Gamma>\\<turnstile>DynCom (\\<lambda>t. Seq (Basic (return s)) (c s t)) \\<down> Normal t\"\n        apply (unfold block_def)\n        apply (elim terminates_Normal_elim_cases)\n        by simp\n      thus ?thesis\n        apply (elim terminates_Normal_elim_cases)\n        apply (auto intro: exec.intros)\n        done\n    qed\n  }\n  ultimately show P by (iprover intro: e)\nqed\n\n\nlemma terminates_call: \n\"\\<lbrakk>\\<Gamma> p = Some bdy; \\<Gamma>\\<turnstile>bdy \\<down> Normal (init s);\n  \\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow> \\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\\<rbrakk>\n \\<Longrightarrow> \\<Gamma>\\<turnstile>call init p return c \\<down> Normal s\"\n  apply (unfold call_def)\n  apply (rule terminates_block)\n  apply  (iprover intro: terminates.intros)\n  apply (auto elim: exec_Normal_elim_cases)\n  done\n\nlemma terminates_callUndefined: \n\"\\<lbrakk>\\<Gamma> p = None\\<rbrakk>\n \\<Longrightarrow> \\<Gamma>\\<turnstile>call init p return result \\<down> Normal s\"\n  apply (unfold call_def)\n  apply (rule terminates_block)\n  apply  (iprover intro: terminates.intros)\n  apply (auto elim: exec_Normal_elim_cases)\n  done\n\nlemma terminates_call_elim [cases set, consumes 1]:\nassumes termi: \"\\<Gamma>\\<turnstile>call init p return c \\<down> Normal s\"\nassumes bdy: \"\\<And>bdy. \\<lbrakk>\\<Gamma> p = Some bdy; \\<Gamma>\\<turnstile>bdy \\<down> Normal (init s); \n     \\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow> \\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\\<rbrakk> \\<Longrightarrow> P\"\nassumes undef: \"\\<lbrakk>\\<Gamma> p = None\\<rbrakk> \\<Longrightarrow> P\" \nshows P\napply (cases \"\\<Gamma> p\")\napply  (erule undef)\nusing termi\napply (unfold call_def)\napply (erule terminates_block_elim)\napply (erule terminates_Normal_elim_cases)\napply  simp\napply  (frule (1) bdy)\napply   (fastforce intro: exec.intros)\napply  assumption\napply simp\ndone\n\nlemma terminates_dynCall: \n\"\\<lbrakk>\\<Gamma>\\<turnstile>call init (p s) return c \\<down> Normal s\\<rbrakk>\n \\<Longrightarrow> \\<Gamma>\\<turnstile>dynCall init p return c \\<down> Normal s\"\n  apply (unfold dynCall_def)\n  apply (auto intro: terminates.intros terminates_call)\n  done\n\nlemma terminates_dynCall_elim [cases set, consumes 1]:\nassumes termi: \"\\<Gamma>\\<turnstile>dynCall init p return c \\<down> Normal s\"\nassumes \"\\<lbrakk>\\<Gamma>\\<turnstile>call init (p s) return c \\<down> Normal s\\<rbrakk> \\<Longrightarrow> P\"\nshows P\nusing termi\napply (unfold dynCall_def)\napply (elim terminates_Normal_elim_cases)\napply fact\ndone\n\n\n(* ************************************************************************* *)\nsubsection {* Lemmas about @{const \"sequence\"}, @{const \"flatten\"} and \n @{const \"normalize\"} *}\n(* ************************************************************************ *)\n\nlemma terminates_sequence_app: \n  \"\\<And>s. \\<lbrakk>\\<Gamma>\\<turnstile>sequence Seq xs \\<down> Normal s;\n        \\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>sequence Seq xs,Normal s \\<rangle> \\<Rightarrow> s' \\<longrightarrow>  \\<Gamma>\\<turnstile>sequence Seq ys \\<down> s'\\<rbrakk>\n\\<Longrightarrow> \\<Gamma>\\<turnstile>sequence Seq (xs @ ys) \\<down> Normal s\"\nproof (induct xs)\n  case Nil\n  thus ?case by (auto intro: exec.intros)\nnext\n  case (Cons x xs)\n  have termi_x_xs: \"\\<Gamma>\\<turnstile>sequence Seq (x # xs) \\<down> Normal s\" by fact\n  have termi_ys: \"\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>sequence Seq (x # xs),Normal s \\<rangle> \\<Rightarrow> s' \\<longrightarrow> \\<Gamma>\\<turnstile>sequence Seq ys \\<down> s'\" by fact\n  show ?case\n  proof (cases xs)\n    case Nil\n    with termi_x_xs termi_ys show ?thesis\n      by (cases ys) (auto intro: terminates.intros)\n  next\n    case Cons\n    from termi_x_xs Cons \n    have \"\\<Gamma>\\<turnstile>x \\<down> Normal s\"\n      by (auto elim: terminates_Normal_elim_cases)\n    moreover \n    {\n      fix s'\n      assume exec_x: \"\\<Gamma>\\<turnstile>\\<langle>x,Normal s \\<rangle> \\<Rightarrow> s'\" \n      have \"\\<Gamma>\\<turnstile>sequence Seq (xs @ ys) \\<down> s'\"\n      proof -\n        from exec_x termi_x_xs Cons\n        have termi_xs: \"\\<Gamma>\\<turnstile>sequence Seq xs \\<down> s'\"\n          by (auto elim: terminates_Normal_elim_cases)\n        show ?thesis\n        proof (cases s')\n          case (Normal s'')\n          with exec_x termi_ys Cons \n          have \"\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>sequence Seq xs,Normal s'' \\<rangle> \\<Rightarrow> s' \\<longrightarrow> \\<Gamma>\\<turnstile>sequence Seq ys \\<down> s'\"\n            by (auto intro: exec.intros)\n          from Cons.hyps [OF termi_xs [simplified Normal] this]\n          have \"\\<Gamma>\\<turnstile>sequence Seq (xs @ ys) \\<down> Normal s''\".\n          with Normal show ?thesis by simp\n        next\n          case Abrupt thus ?thesis by (auto intro: terminates.intros)\n        next\n          case Fault thus ?thesis by (auto intro: terminates.intros)\n        next\n          case Stuck thus ?thesis by (auto intro: terminates.intros)\n        qed\n      qed\n    }\n    ultimately show ?thesis\n      using Cons\n      by (auto intro: terminates.intros)\n  qed\nqed\n\nlemma terminates_sequence_appD: \n  \"\\<And>s. \\<Gamma>\\<turnstile>sequence Seq (xs @ ys) \\<down> Normal s\n   \\<Longrightarrow> \\<Gamma>\\<turnstile>sequence Seq xs \\<down> Normal s \\<and>\n       (\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>sequence Seq xs,Normal s \\<rangle> \\<Rightarrow> s' \\<longrightarrow>  \\<Gamma>\\<turnstile>sequence Seq ys \\<down> s')\"\nproof (induct xs)\n  case Nil\n  thus ?case \n    by (auto elim: terminates_Normal_elim_cases exec_Normal_elim_cases \n         intro: terminates.intros)\nnext\n  case (Cons x xs)\n  have termi_x_xs_ys: \"\\<Gamma>\\<turnstile>sequence Seq ((x # xs) @ ys) \\<down> Normal s\" by fact\n  show ?case\n  proof (cases xs)\n    case Nil\n    with termi_x_xs_ys show ?thesis\n      by (cases ys)\n         (auto elim: terminates_Normal_elim_cases exec_Normal_elim_cases \n           intro:  terminates_Skip')\n  next\n    case Cons\n    with termi_x_xs_ys \n    obtain termi_x: \"\\<Gamma>\\<turnstile>x \\<down> Normal s\" and\n           termi_xs_ys: \"\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>x,Normal s \\<rangle> \\<Rightarrow> s' \\<longrightarrow>  \\<Gamma>\\<turnstile>sequence Seq (xs@ys) \\<down> s'\"\n      by (auto elim: terminates_Normal_elim_cases)\n    \n    have \"\\<Gamma>\\<turnstile>Seq x (sequence Seq xs) \\<down> Normal s\"\n    proof (rule terminates.Seq [rule_format])\n      show \"\\<Gamma>\\<turnstile>x \\<down> Normal s\" by (rule termi_x)\n    next\n      fix s'\n      assume exec_x: \"\\<Gamma>\\<turnstile>\\<langle>x,Normal s \\<rangle> \\<Rightarrow> s'\"\n      show \"\\<Gamma>\\<turnstile>sequence Seq xs \\<down> s'\"\n      proof -\n        from termi_xs_ys [rule_format, OF exec_x]\n        have termi_xs_ys': \"\\<Gamma>\\<turnstile>sequence Seq (xs@ys) \\<down> s'\" .\n        show ?thesis\n        proof (cases s')\n          case (Normal s'')\n          from Cons.hyps [OF termi_xs_ys' [simplified Normal]]\n          show ?thesis\n            using Normal by auto\n        next\n          case Abrupt thus ?thesis by (auto intro: terminates.intros)\n        next\n          case Fault thus ?thesis by (auto intro: terminates.intros)\n        next\n          case Stuck thus ?thesis by (auto intro: terminates.intros)\n        qed\n      qed\n    qed\n    moreover\n    {\n      fix s'\n      assume exec_x_xs: \"\\<Gamma>\\<turnstile>\\<langle>Seq x (sequence Seq xs),Normal s \\<rangle> \\<Rightarrow> s'\"\n      have \"\\<Gamma>\\<turnstile>sequence Seq ys \\<down> s'\"\n      proof -\n        from exec_x_xs obtain t where \n          exec_x: \"\\<Gamma>\\<turnstile>\\<langle>x,Normal s \\<rangle> \\<Rightarrow> t\" and\n          exec_xs: \"\\<Gamma>\\<turnstile>\\<langle>sequence Seq xs,t \\<rangle> \\<Rightarrow> s'\"\n          by cases\n        show ?thesis\n        proof (cases t)\n          case (Normal t')\n          with exec_x termi_xs_ys have \"\\<Gamma>\\<turnstile>sequence Seq (xs@ys) \\<down> Normal t'\"\n            by auto\n          from Cons.hyps [OF this] exec_xs Normal\n          show ?thesis\n            by auto\n        next\n          case (Abrupt t')\n          with exec_xs have \"s'=Abrupt t'\"\n            by (auto dest: Abrupt_end)\n          thus ?thesis by (auto intro: terminates.intros)\n        next\n          case (Fault f)\n          with exec_xs have \"s'=Fault f\"\n            by (auto dest: Fault_end)\n          thus ?thesis by (auto intro: terminates.intros)\n        next\n          case Stuck\n          with exec_xs have \"s'=Stuck\"\n            by (auto dest: Stuck_end)\n          thus ?thesis by (auto intro: terminates.intros)\n        qed\n      qed\n    }\n    ultimately show ?thesis\n      using Cons\n      by auto\n  qed\nqed\n\nlemma terminates_sequence_appE [consumes 1]:\n  \"\\<lbrakk>\\<Gamma>\\<turnstile>sequence Seq (xs @ ys) \\<down> Normal s;\n    \\<lbrakk>\\<Gamma>\\<turnstile>sequence Seq xs \\<down> Normal s;\n     \\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>sequence Seq xs,Normal s \\<rangle> \\<Rightarrow> s' \\<longrightarrow>  \\<Gamma>\\<turnstile>sequence Seq ys \\<down> s'\\<rbrakk> \\<Longrightarrow> P\\<rbrakk>\n   \\<Longrightarrow> P\"\n  by (auto dest: terminates_sequence_appD)\n\nlemma terminates_to_terminates_sequence_flatten: \n  assumes termi: \"\\<Gamma>\\<turnstile>c\\<down>s\" \n  shows \"\\<Gamma>\\<turnstile>sequence Seq (flatten c)\\<down>s\" \nusing termi \nby (induct)\n   (auto intro: terminates.intros terminates_sequence_app \n     exec_sequence_flatten_to_exec)\n\nlemma terminates_to_terminates_normalize: \n  assumes termi: \"\\<Gamma>\\<turnstile>c\\<down>s\" \n  shows \"\\<Gamma>\\<turnstile>normalize c\\<down>s\" \nusing termi \nproof induct\n  case Seq\n  thus ?case\n    by (fastforce intro: terminates.intros terminates_sequence_app\n                 terminates_to_terminates_sequence_flatten\n        dest: exec_sequence_flatten_to_exec exec_normalize_to_exec)\nnext\n  case WhileTrue\n  thus ?case\n    by (fastforce intro: terminates.intros terminates_sequence_app\n                 terminates_to_terminates_sequence_flatten\n        dest: exec_sequence_flatten_to_exec exec_normalize_to_exec)\nnext \n  case Catch\n  thus ?case\n    by (fastforce intro: terminates.intros terminates_sequence_app\n                 terminates_to_terminates_sequence_flatten\n        dest: exec_sequence_flatten_to_exec exec_normalize_to_exec)\nqed (auto intro: terminates.intros)\n\nlemma terminates_sequence_flatten_to_terminates: \n  shows \"\\<And>s. \\<Gamma>\\<turnstile>sequence Seq (flatten c)\\<down>s \\<Longrightarrow> \\<Gamma>\\<turnstile>c\\<down>s\" \nproof (induct c)\n  case (Seq c1 c2)\n  have \"\\<Gamma>\\<turnstile>sequence Seq (flatten (Seq c1 c2)) \\<down> s\" by fact\n  hence termi_app: \"\\<Gamma>\\<turnstile>sequence Seq (flatten c1 @ flatten c2) \\<down> s\" by simp\n  show ?case\n  proof (cases s)\n    case (Normal s')\n    have \"\\<Gamma>\\<turnstile>Seq c1 c2 \\<down> Normal s'\"\n    proof (rule terminates.Seq [rule_format])\n      from termi_app [simplified Normal]\n      have \"\\<Gamma>\\<turnstile>sequence Seq (flatten c1) \\<down> Normal s'\"\n        by (cases rule: terminates_sequence_appE)\n      with Seq.hyps\n      show \"\\<Gamma>\\<turnstile>c1 \\<down> Normal s'\"\n        by simp\n    next\n      fix s''\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s' \\<rangle> \\<Rightarrow> s''\"\n      from termi_app [simplified Normal] exec_to_exec_sequence_flatten [OF this]\n      have \"\\<Gamma>\\<turnstile>sequence Seq (flatten c2) \\<down> s''\"\n        by (cases rule: terminates_sequence_appE) auto\n      with Seq.hyps\n      show \"\\<Gamma>\\<turnstile>c2 \\<down> s''\"\n        by simp\n    qed\n    with Normal show ?thesis\n      by simp\n  qed (auto intro: terminates.intros)\nqed (auto intro: terminates.intros)\n\nlemma terminates_normalize_to_terminates: \n  shows \"\\<And>s. \\<Gamma>\\<turnstile>normalize c\\<down>s \\<Longrightarrow> \\<Gamma>\\<turnstile>c\\<down>s\" \nproof (induct c)\n  case Skip thus ?case by (auto intro:  terminates_Skip')\nnext\n  case Basic thus ?case by (cases s) (auto intro: terminates.intros)\nnext\n  case Spec thus ?case by (cases s) (auto intro: terminates.intros)\nnext\n  case (Seq c1 c2)\n  have \"\\<Gamma>\\<turnstile>normalize (Seq c1 c2) \\<down> s\" by fact\n  hence termi_app: \"\\<Gamma>\\<turnstile>sequence Seq (flatten (normalize c1) @ flatten (normalize c2)) \\<down> s\"\n    by simp\n  show ?case\n  proof (cases s)\n    case (Normal s')\n    have \"\\<Gamma>\\<turnstile>Seq c1 c2 \\<down> Normal s'\"\n    proof (rule terminates.Seq [rule_format])\n      from termi_app [simplified Normal]\n      have \"\\<Gamma>\\<turnstile>sequence Seq (flatten (normalize c1))  \\<down> Normal s'\"\n        by (cases rule: terminates_sequence_appE)\n      from terminates_sequence_flatten_to_terminates [OF this] Seq.hyps\n      show \"\\<Gamma>\\<turnstile>c1 \\<down> Normal s'\" \n        by simp\n    next\n      fix s''\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s' \\<rangle> \\<Rightarrow> s''\"\n      from exec_to_exec_normalize [OF this]\n      have \"\\<Gamma>\\<turnstile>\\<langle>normalize c1,Normal s' \\<rangle> \\<Rightarrow> s''\" .\n      from termi_app [simplified Normal] exec_to_exec_sequence_flatten [OF this] \n      have \"\\<Gamma>\\<turnstile>sequence Seq (flatten (normalize c2))  \\<down> s''\"\n        by (cases rule: terminates_sequence_appE) auto\n      from terminates_sequence_flatten_to_terminates [OF this] Seq.hyps\n      show \"\\<Gamma>\\<turnstile>c2 \\<down> s''\" \n        by simp\n    qed\n    with Normal show ?thesis by simp\n  qed (auto intro: terminates.intros)\nnext\n  case (Cond b c1 c2) \n  thus ?case\n    by (cases s)\n       (auto intro: terminates.intros elim!: terminates_Normal_elim_cases)\nnext\n  case (While b c)\n  have \"\\<Gamma>\\<turnstile>normalize (While b c) \\<down> s\" by fact\n  hence termi_norm_w: \"\\<Gamma>\\<turnstile>While b (normalize c) \\<down> s\" by simp\n  {\n    fix t w\n    assume termi_w: \"\\<Gamma>\\<turnstile> w \\<down> t\"\n    have \"w=While b (normalize c) \\<Longrightarrow> \\<Gamma>\\<turnstile>While b c \\<down> t\"\n      using termi_w \n    proof (induct)\n      case (WhileTrue t' b' c')\n      from WhileTrue obtain\n        t'_b: \"t' \\<in> b\" and\n        termi_norm_c: \"\\<Gamma>\\<turnstile>normalize c \\<down> Normal t'\" and\n        termi_norm_w': \"\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>normalize c,Normal t' \\<rangle> \\<Rightarrow> s' \\<longrightarrow> \\<Gamma>\\<turnstile>While b c \\<down> s'\"\n        by auto\n      from While.hyps [OF termi_norm_c]\n      have \"\\<Gamma>\\<turnstile>c \\<down> Normal t'\".\n      moreover\n      from termi_norm_w' \n      have \"\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>c,Normal t' \\<rangle> \\<Rightarrow> s' \\<longrightarrow> \\<Gamma>\\<turnstile>While b c \\<down> s'\"\n        by (auto intro: exec_to_exec_normalize)\n      ultimately show ?case\n        using t'_b\n        by (auto intro: terminates.intros)\n    qed (auto intro: terminates.intros)\n  }\n  from this [OF termi_norm_w]\n  show ?case \n    by auto\nnext\n  case Call thus ?case by simp\nnext\n  case DynCom thus ?case \n    by (cases s) (auto intro: terminates.intros rangeI elim: terminates_Normal_elim_cases)\nnext\n  case Guard thus ?case \n    by (cases s) (auto intro: terminates.intros elim: terminates_Normal_elim_cases)\nnext\n  case Throw thus ?case by (cases s) (auto intro: terminates.intros)\nnext\n  case Catch\n  thus ?case\n    by (cases s) \n       (auto dest: exec_to_exec_normalize elim!: terminates_Normal_elim_cases \n         intro!: terminates.Catch)\nqed\n\nlemma terminates_iff_terminates_normalize:\n\"\\<Gamma>\\<turnstile>normalize c\\<down>s = \\<Gamma>\\<turnstile>c\\<down>s\"\n  by (auto intro: terminates_to_terminates_normalize \n    terminates_normalize_to_terminates)\n\n(* ************************************************************************* *)\nsubsection {* Lemmas about @{const \"strip_guards\"} *}\n(* ************************************************************************* *)\n\nlemma terminates_strip_guards_to_terminates: \"\\<And>s. \\<Gamma>\\<turnstile>strip_guards F c\\<down>s  \\<Longrightarrow> \\<Gamma>\\<turnstile>c\\<down>s\"\nproof (induct c)\n  case Skip thus ?case by simp\nnext\n  case Basic thus ?case by simp\nnext\n  case Spec thus ?case by simp\nnext\n  case (Seq c1 c2)\n  hence \"\\<Gamma>\\<turnstile>Seq (strip_guards F c1) (strip_guards F c2) \\<down> s\" by simp\n  thus \"\\<Gamma>\\<turnstile>Seq c1 c2 \\<down> s\"\n  proof (cases)\n    fix f assume \"s=Fault f\" thus ?thesis by simp\n  next\n    assume \"s=Stuck\" thus ?thesis by simp\n  next\n    fix s' assume \"s=Abrupt s'\" thus ?thesis by simp\n  next\n    fix s'\n    assume s: \"s=Normal s'\"\n    assume \"\\<Gamma>\\<turnstile>strip_guards F c1 \\<down> Normal s'\"\n    hence \"\\<Gamma>\\<turnstile>c1 \\<down> Normal s'\" \n      by (rule Seq.hyps)\n    moreover\n    assume c2: \n      \"\\<forall>s''. \\<Gamma>\\<turnstile>\\<langle>strip_guards F c1,Normal s'\\<rangle> \\<Rightarrow> s'' \\<longrightarrow> \\<Gamma>\\<turnstile>strip_guards F c2\\<down>s''\"\n    {\n      fix s'' assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s' \\<rangle> \\<Rightarrow> s''\"\n      have \" \\<Gamma>\\<turnstile>c2 \\<down> s''\"\n      proof (cases s'')\n        case (Normal s''')\n        with exec_c1\n        have \"\\<Gamma>\\<turnstile>\\<langle>strip_guards F c1,Normal s' \\<rangle> \\<Rightarrow> s''\"\n          by (auto intro: exec_to_exec_strip_guards)\n        with c2\n        show ?thesis\n          by (iprover intro: Seq.hyps)\n      next\n        case (Abrupt s''')\n        with exec_c1\n        have \"\\<Gamma>\\<turnstile>\\<langle>strip_guards F c1,Normal s' \\<rangle> \\<Rightarrow> s''\"\n          by (auto intro: exec_to_exec_strip_guards )\n        with c2\n        show ?thesis\n          by (iprover intro: Seq.hyps)\n      next\n        case Fault thus ?thesis by simp\n      next\n        case Stuck thus ?thesis by simp\n      qed\n    }\n    ultimately show ?thesis\n      using s\n      by (iprover intro: terminates.intros)\n  qed\nnext\n  case (Cond b c1 c2)\n  hence \"\\<Gamma>\\<turnstile>Cond b (strip_guards F c1) (strip_guards F c2) \\<down> s\" by simp\n  thus \"\\<Gamma>\\<turnstile>Cond b c1 c2 \\<down> s\"\n  proof (cases)\n    fix f assume \"s=Fault f\" thus ?thesis by simp\n  next\n    assume \"s=Stuck\" thus ?thesis by simp\n  next\n    fix s' assume \"s=Abrupt s'\" thus ?thesis by simp\n  next\n    fix s'\n    assume \"s'\\<in>b\" \"\\<Gamma>\\<turnstile>strip_guards F c1 \\<down> Normal s'\" \"s = Normal s'\"\n    thus ?thesis\n      by (iprover intro: terminates.intros Cond.hyps)\n  next\n    fix s'\n    assume \"s'\\<notin>b\" \"\\<Gamma>\\<turnstile>strip_guards F c2 \\<down> Normal s'\" \"s = Normal s'\"\n    thus ?thesis\n      by (iprover intro: terminates.intros Cond.hyps)\n  qed\nnext\n  case (While b c)\n  have hyp_c: \"\\<And>s. \\<Gamma>\\<turnstile>strip_guards F c \\<down> s \\<Longrightarrow> \\<Gamma>\\<turnstile>c \\<down> s\" by fact\n  have \"\\<Gamma>\\<turnstile>While b (strip_guards F c) \\<down> s\" using While.prems by simp\n  moreover\n  {\n    fix sw  \n    assume \"\\<Gamma>\\<turnstile>sw\\<down>s\"  \n    then have \"sw=While b (strip_guards F c) \\<Longrightarrow> \n      \\<Gamma>\\<turnstile>While b c \\<down> s\"\n    proof (induct)\n      case (WhileTrue s b' c')\n      have eqs: \"While b' c' = While b (strip_guards F c)\" by fact\n      with `s\\<in>b'` have b: \"s\\<in>b\" by simp\n      from eqs `\\<Gamma>\\<turnstile>c' \\<down> Normal s` have \"\\<Gamma>\\<turnstile>strip_guards F c \\<down> Normal s\"\n        by simp\n      hence term_c: \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n        by (rule hyp_c)\n      moreover\n      {\n        fix t\n        assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> t\"\n        have \"\\<Gamma>\\<turnstile>While b c \\<down> t\"\n        proof (cases t)\n          case Fault\n          thus ?thesis by simp\n        next\n          case Stuck\n          thus ?thesis by simp\n        next\n          case (Abrupt t')\n          thus ?thesis by simp\n        next\n          case (Normal t')\n          with exec_c\n          have \"\\<Gamma>\\<turnstile>\\<langle>strip_guards F c,Normal s \\<rangle> \\<Rightarrow> Normal t'\"\n            by (auto intro: exec_to_exec_strip_guards)\n          with WhileTrue.hyps eqs Normal\n          show ?thesis\n            by fastforce\n        qed\n      }\n      ultimately\n      show ?case\n        using b\n        by (auto intro: terminates.intros)\n    next\n      case WhileFalse thus ?case by (auto intro: terminates.intros)\n    qed simp_all\n  } \n  ultimately show \"\\<Gamma>\\<turnstile>While b c \\<down> s\"\n    by auto\nnext\n  case Call thus ?case by simp\nnext\n  case DynCom thus ?case \n     by (cases s) (auto elim: terminates_Normal_elim_cases intro: terminates.intros rangeI)\nnext\n  case Guard \n  thus ?case\n    by (cases s) (auto elim: terminates_Normal_elim_cases intro: terminates.intros\n                  split: if_split_asm)\nnext\n  case Throw thus ?case by simp\nnext\n  case (Catch c1 c2)\n  hence \"\\<Gamma>\\<turnstile>Catch (strip_guards F c1) (strip_guards F c2) \\<down> s\" by simp\n  thus \"\\<Gamma>\\<turnstile>Catch c1 c2 \\<down> s\"\n  proof (cases)\n    fix f assume \"s=Fault f\" thus ?thesis by simp\n  next\n    assume \"s=Stuck\" thus ?thesis by simp\n  next\n    fix s' assume \"s=Abrupt s'\" thus ?thesis by simp\n  next\n    fix s'\n    assume s: \"s=Normal s'\"\n    assume \"\\<Gamma>\\<turnstile>strip_guards F c1 \\<down> Normal s'\"\n    hence \"\\<Gamma>\\<turnstile>c1 \\<down> Normal s'\" \n      by (rule Catch.hyps)\n    moreover\n    assume c2: \n      \"\\<forall>s''. \\<Gamma>\\<turnstile>\\<langle>strip_guards F c1,Normal s'\\<rangle> \\<Rightarrow> Abrupt s''   \n             \\<longrightarrow> \\<Gamma>\\<turnstile>strip_guards F c2\\<down>Normal s''\"\n    {\n      fix s'' assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s' \\<rangle> \\<Rightarrow> Abrupt s''\"\n      have \" \\<Gamma>\\<turnstile>c2 \\<down> Normal s''\"\n      proof -\n        from exec_c1\n        have \"\\<Gamma>\\<turnstile>\\<langle>strip_guards F c1,Normal s' \\<rangle> \\<Rightarrow> Abrupt s''\"\n          by (auto intro: exec_to_exec_strip_guards)\n        with c2 \n        show ?thesis\n          by (auto intro: Catch.hyps)\n      qed\n    }\n    ultimately show ?thesis\n      using s\n      by (iprover intro: terminates.intros)\n  qed\nqed\n\nlemma terminates_strip_to_terminates:\n  assumes termi_strip: \"strip F \\<Gamma>\\<turnstile>c\\<down>s\"\n  shows \"\\<Gamma>\\<turnstile>c\\<down>s\"\nusing termi_strip\nproof induct\n  case (Seq c1 s c2)\n  have \"\\<Gamma>\\<turnstile>c1 \\<down> Normal s\" by fact\n  moreover\n  {\n    fix s'\n    assume exec: \"\\<Gamma>\\<turnstile> \\<langle>c1,Normal s\\<rangle> \\<Rightarrow> s'\"\n    have \"\\<Gamma>\\<turnstile>c2 \\<down> s'\"\n    proof (cases \"isFault s'\")\n      case True\n      thus ?thesis\n        by (auto elim: isFaultE)\n    next\n      case False\n      from exec_to_exec_strip [OF exec this] Seq.hyps\n      show ?thesis\n        by auto\n    qed\n  }\n  ultimately show ?case\n    by (auto intro: terminates.intros)\nnext\n  case (WhileTrue s b c)\n  have \"\\<Gamma>\\<turnstile>c \\<down> Normal s\" by fact\n  moreover\n  {\n    fix s'\n    assume exec: \"\\<Gamma>\\<turnstile> \\<langle>c,Normal s\\<rangle> \\<Rightarrow> s'\"\n    have \"\\<Gamma>\\<turnstile>While b c \\<down> s'\"\n    proof (cases \"isFault s'\")\n      case True\n      thus ?thesis\n        by (auto elim: isFaultE)\n    next\n      case False\n      from exec_to_exec_strip [OF exec this] WhileTrue.hyps\n      show ?thesis\n        by auto\n    qed\n  }\n  ultimately show ?case\n    by (auto intro: terminates.intros)\nnext\n  case (Catch c1 s c2)\n  have \"\\<Gamma>\\<turnstile>c1 \\<down> Normal s\" by fact\n  moreover\n  {\n    fix s'\n    assume exec: \"\\<Gamma>\\<turnstile> \\<langle>c1,Normal s\\<rangle> \\<Rightarrow> Abrupt s'\"\n    from exec_to_exec_strip [OF exec] Catch.hyps\n    have \"\\<Gamma>\\<turnstile>c2 \\<down> Normal s'\"\n      by auto\n  }\n  ultimately show ?case\n    by (auto intro: terminates.intros)\nnext\n  case Call thus ?case \n    by (auto intro: terminates.intros terminates_strip_guards_to_terminates)\nqed (auto intro: terminates.intros)\n\n(* ************************************************************************* *)\nsubsection {* Lemmas about @{term \"c\\<^sub>1 \\<inter>\\<^sub>g c\\<^sub>2\"} *}\n(* ************************************************************************* *)\n\nlemma inter_guards_terminates: \n  \"\\<And>c c2 s. \\<lbrakk>(c1 \\<inter>\\<^sub>g c2) = Some c; \\<Gamma>\\<turnstile>c1\\<down>s \\<rbrakk>\n        \\<Longrightarrow> \\<Gamma>\\<turnstile>c\\<down>s\"\nproof (induct c1)\n  case Skip thus ?case by (fastforce simp add: inter_guards_Skip)\nnext\n  case (Basic f) thus ?case by (fastforce simp add: inter_guards_Basic)\nnext\n  case (Spec r) thus ?case by (fastforce simp add: inter_guards_Spec)\nnext\n  case (Seq a1 a2)\n  have \"(Seq a1 a2 \\<inter>\\<^sub>g c2) = Some c\" by fact\n  then obtain b1 b2 d1 d2 where\n    c2: \"c2=Seq b1 b2\" and \n    d1: \"(a1 \\<inter>\\<^sub>g b1) = Some d1\" and d2: \"(a2 \\<inter>\\<^sub>g b2) = Some d2\" and\n    c: \"c=Seq d1 d2\"\n    by (auto simp add: inter_guards_Seq)\n  have termi_c1: \"\\<Gamma>\\<turnstile>Seq a1 a2 \\<down> s\" by fact\n  have \"\\<Gamma>\\<turnstile>Seq d1 d2 \\<down> s\"\n  proof (cases s)\n    case Fault thus ?thesis by simp\n  next\n    case Stuck thus ?thesis by simp\n  next\n    case Abrupt thus ?thesis by simp\n  next\n    case (Normal s')\n    note Normal_s = this\n    with d1 termi_c1\n    have \"\\<Gamma>\\<turnstile>d1 \\<down> Normal s'\"\n      by (auto elim: terminates_Normal_elim_cases intro: Seq.hyps)\n    moreover\n    {\n      fix t\n      assume exec_d1: \"\\<Gamma>\\<turnstile>\\<langle>d1,Normal s' \\<rangle> \\<Rightarrow> t\"\n      have \"\\<Gamma>\\<turnstile>d2 \\<down> t\"\n      proof (cases t)\n        case Fault thus ?thesis by simp\n      next\n        case Stuck thus ?thesis by simp\n      next\n        case Abrupt thus ?thesis by simp\n      next\n        case (Normal t')\n        with inter_guards_exec_noFault [OF d1 exec_d1]\n        have \"\\<Gamma>\\<turnstile>\\<langle>a1,Normal s' \\<rangle> \\<Rightarrow> Normal t'\"\n          by simp\n        with termi_c1 Normal_s have \"\\<Gamma>\\<turnstile>a2 \\<down> Normal t'\"\n          by (auto elim: terminates_Normal_elim_cases) \n        with d2 have \"\\<Gamma>\\<turnstile>d2 \\<down> Normal t'\"\n          by (auto intro: Seq.hyps)\n        with Normal show ?thesis by simp  \n      qed\n    }\n    ultimately have \"\\<Gamma>\\<turnstile>Seq d1 d2 \\<down> Normal s'\"\n      by (fastforce intro: terminates.intros)\n    with Normal show ?thesis by simp\n  qed\n  with c show ?case by simp\nnext\n  case Cond thus ?case\n    by - (cases s,\n          auto intro: terminates.intros elim!: terminates_Normal_elim_cases\n               simp add: inter_guards_Cond)\nnext\n  case (While b bdy1)\n  have \"(While b bdy1 \\<inter>\\<^sub>g c2) = Some c\" by fact\n  then obtain bdy2 bdy where\n    c2: \"c2=While b bdy2\" and\n    bdy: \"(bdy1 \\<inter>\\<^sub>g bdy2) = Some bdy\" and\n    c: \"c=While b bdy\"\n    by (auto simp add: inter_guards_While)\n  have \"\\<Gamma>\\<turnstile>While b bdy1 \\<down> s\" by fact\n  moreover\n  {\n    fix s w w1 w2\n    assume termi_w:  \"\\<Gamma>\\<turnstile>w \\<down> s\"\n    assume w: \"w=While b bdy1\"\n    from termi_w w \n    have \"\\<Gamma>\\<turnstile>While b bdy \\<down> s\"    \n    proof (induct)\n      case (WhileTrue s b' bdy1')\n      have eqs: \"While b' bdy1' = While b bdy1\" by fact\n      from WhileTrue have s_in_b: \"s \\<in> b\" by simp\n      from WhileTrue have termi_bdy1: \"\\<Gamma>\\<turnstile>bdy1 \\<down> Normal s\" by simp\n      show ?case\n      proof -\n        from bdy termi_bdy1 \n        have \"\\<Gamma>\\<turnstile>bdy\\<down>(Normal s)\"\n          by (rule While.hyps)\n        moreover\n        {\n          fix t\n          assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal s \\<rangle> \\<Rightarrow> t\" \n          have \"\\<Gamma>\\<turnstile>While b bdy\\<down>t\"\n          proof (cases t)\n            case Fault thus ?thesis by simp\n          next\n            case Stuck thus ?thesis by simp\n          next\n            case Abrupt thus ?thesis by simp\n          next\n            case (Normal t')\n            with inter_guards_exec_noFault [OF bdy exec_bdy]\n            have \"\\<Gamma>\\<turnstile>\\<langle>bdy1,Normal s \\<rangle> \\<Rightarrow> Normal t'\"\n              by simp\n            with WhileTrue have \"\\<Gamma>\\<turnstile>While b bdy \\<down> Normal t'\"\n              by simp\n            with Normal show ?thesis by simp\n          qed\n        }\n        ultimately show ?thesis\n          using s_in_b \n          by (blast intro: terminates.WhileTrue)\n      qed\n    next\n      case WhileFalse thus ?case \n        by (blast intro: terminates.WhileFalse)\n    qed (simp_all)\n  }\n  ultimately\n  show ?case using c by simp\nnext\n  case Call thus ?case by (simp add: inter_guards_Call)\nnext\n  case (DynCom f1) \n  have \"(DynCom f1 \\<inter>\\<^sub>g c2) = Some c\" by fact\n  then obtain f2 f where\n    c2: \"c2=DynCom f2\" and\n    f_defined: \"\\<forall>s. ((f1 s) \\<inter>\\<^sub>g (f2 s)) \\<noteq> None\" and\n    c: \"c=DynCom (\\<lambda>s. the ((f1 s) \\<inter>\\<^sub>g (f2 s)))\"\n    by (auto simp add: inter_guards_DynCom)\n  have termi: \"\\<Gamma>\\<turnstile>DynCom f1 \\<down> s\" by fact\n  show ?case\n  proof (cases s)\n    case Fault thus ?thesis by simp\n  next\n    case Stuck thus ?thesis by simp\n  next\n    case Abrupt thus ?thesis by simp\n  next\n    case (Normal s')\n    from f_defined obtain f where f: \"((f1 s') \\<inter>\\<^sub>g (f2 s')) = Some f\"\n      by auto\n    from Normal termi\n    have \"\\<Gamma>\\<turnstile>f1 s'\\<down> (Normal s')\"\n      by (auto elim: terminates_Normal_elim_cases)\n    from DynCom.hyps f this \n    have \"\\<Gamma>\\<turnstile>f\\<down> (Normal s')\"\n      by blast\n    with c f Normal\n    show ?thesis\n      by (auto intro: terminates.intros)\n  qed\nnext\n  case (Guard f g1 bdy1)\n  have \"(Guard f g1 bdy1 \\<inter>\\<^sub>g c2) = Some c\" by fact\n  then obtain g2 bdy2 bdy where\n    c2: \"c2=Guard f g2 bdy2\" and\n    bdy: \"(bdy1 \\<inter>\\<^sub>g bdy2) = Some bdy\" and\n    c: \"c=Guard f (g1 \\<inter> g2) bdy\"\n    by (auto simp add: inter_guards_Guard)\n  have termi_c1: \"\\<Gamma>\\<turnstile>Guard f g1 bdy1 \\<down> s\" by fact\n  show ?case\n  proof (cases s)\n    case Fault thus ?thesis by simp\n  next\n    case Stuck thus ?thesis by simp\n  next\n    case Abrupt thus ?thesis by simp\n  next\n    case (Normal s')\n    show ?thesis\n    proof (cases \"s' \\<in> g1\")\n      case False\n      with Normal c show ?thesis by (auto intro: terminates.GuardFault)\n    next\n      case True\n      note s_in_g1 = this\n      show ?thesis\n      proof (cases \"s' \\<in> g2\")\n        case False\n        with Normal c show ?thesis by (auto intro: terminates.GuardFault)\n      next\n        case True\n        with termi_c1 s_in_g1 Normal have \"\\<Gamma>\\<turnstile>bdy1 \\<down> Normal s'\"\n          by (auto elim: terminates_Normal_elim_cases)\n        with c bdy Guard.hyps Normal True s_in_g1 \n        show ?thesis by (auto intro: terminates.Guard)\n      qed\n    qed\n  qed\nnext\n  case Throw thus ?case\n    by (auto simp add: inter_guards_Throw)\nnext\n  case (Catch a1 a2)\n  have \"(Catch a1 a2 \\<inter>\\<^sub>g c2) = Some c\" by fact\n  then obtain b1 b2 d1 d2 where\n    c2: \"c2=Catch b1 b2\" and \n    d1: \"(a1 \\<inter>\\<^sub>g b1) = Some d1\" and d2: \"(a2 \\<inter>\\<^sub>g b2) = Some d2\" and\n    c: \"c=Catch d1 d2\"\n    by (auto simp add: inter_guards_Catch)\n  have termi_c1: \"\\<Gamma>\\<turnstile>Catch a1 a2 \\<down> s\" by fact\n  have \"\\<Gamma>\\<turnstile>Catch d1 d2 \\<down> s\"\n  proof (cases s)\n    case Fault thus ?thesis by simp\n  next\n    case Stuck thus ?thesis by simp\n  next\n    case Abrupt thus ?thesis by simp\n  next\n    case (Normal s')\n    note Normal_s = this\n    with d1 termi_c1\n    have \"\\<Gamma>\\<turnstile>d1 \\<down> Normal s'\"\n      by (auto elim: terminates_Normal_elim_cases intro: Catch.hyps)\n    moreover\n    {\n      fix t\n      assume exec_d1: \"\\<Gamma>\\<turnstile>\\<langle>d1,Normal s' \\<rangle> \\<Rightarrow> Abrupt t\"\n      have \"\\<Gamma>\\<turnstile>d2 \\<down> Normal t\"\n      proof -\n        from inter_guards_exec_noFault [OF d1 exec_d1]\n        have \"\\<Gamma>\\<turnstile>\\<langle>a1,Normal s' \\<rangle> \\<Rightarrow> Abrupt t\"\n          by simp\n        with termi_c1 Normal_s have \"\\<Gamma>\\<turnstile>a2 \\<down> Normal t\"\n          by (auto elim: terminates_Normal_elim_cases) \n        with d2 have \"\\<Gamma>\\<turnstile>d2 \\<down> Normal t\"\n          by (auto intro: Catch.hyps)\n        with Normal show ?thesis by simp  \n      qed\n    }\n    ultimately have \"\\<Gamma>\\<turnstile>Catch d1 d2 \\<down> Normal s'\"\n      by (fastforce intro: terminates.intros)\n    with Normal show ?thesis by simp\n  qed\n  with c show ?case by simp\nqed\n\nlemma inter_guards_terminates': \n  assumes c: \"(c1 \\<inter>\\<^sub>g c2) = Some c\" \n  assumes termi_c2: \"\\<Gamma>\\<turnstile>c2\\<down>s\"\n  shows \"\\<Gamma>\\<turnstile>c\\<down>s\"\nproof -\n  from c have \"(c2 \\<inter>\\<^sub>g c1) = Some c\" \n    by (rule inter_guards_sym)\n  from this termi_c2 show ?thesis\n    by (rule inter_guards_terminates)\nqed\n\n(* ************************************************************************* *)\nsubsection {* Lemmas about @{const \"mark_guards\"} *}\n(* ************************************************************************ *)\n\nlemma terminates_to_terminates_mark_guards:\n  assumes termi: \"\\<Gamma>\\<turnstile>c\\<down>s\" \n  shows \"\\<Gamma>\\<turnstile>mark_guards f c\\<down>s\"\nusing termi\nproof (induct)\n  case Skip thus ?case by (fastforce intro: terminates.intros)\nnext\n  case Basic thus ?case by (fastforce intro: terminates.intros)\nnext\n  case Spec thus ?case by (fastforce intro: terminates.intros)\nnext\n  case Guard thus ?case by (fastforce intro: terminates.intros)\nnext\n  case GuardFault thus ?case by (fastforce intro: terminates.intros)\nnext\n  case Fault thus ?case by (fastforce intro: terminates.intros)\nnext\n  case (Seq c1 s c2)\n  have \"\\<Gamma>\\<turnstile>mark_guards f c1 \\<down> Normal s\" by fact\n  moreover \n  {\n    fix t\n    assume exec_mark: \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c1,Normal s \\<rangle> \\<Rightarrow> t\"\n    have \"\\<Gamma>\\<turnstile>mark_guards f c2 \\<down> t\"\n    proof -\n      from exec_mark_guards_to_exec [OF exec_mark] obtain t' where\n        exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow> t'\" and\n        t_Fault: \"isFault t \\<longrightarrow> isFault t'\" and\n        t'_Fault_f: \"t' = Fault f \\<longrightarrow> t' = t\" and\n        t'_Fault: \"isFault t' \\<longrightarrow> isFault t\" and\n        t'_noFault: \"\\<not> isFault t' \\<longrightarrow> t' = t\"\n        by blast\n      show ?thesis\n      proof (cases \"isFault t'\")\n        case True\n        with t'_Fault have \"isFault t\" by simp\n        thus ?thesis\n          by (auto elim: isFaultE)\n      next\n        case False\n        with t'_noFault have \"t'=t\" by simp\n        with exec_c1 Seq.hyps\n        show ?thesis\n          by auto\n      qed\n    qed  \n  }\n  ultimately show ?case\n    by (auto intro: terminates.intros)\nnext\n  case CondTrue thus ?case by (fastforce intro: terminates.intros)\nnext\n  case CondFalse thus ?case by (fastforce intro: terminates.intros)\nnext\n  case (WhileTrue s b c)\n  have s_in_b: \"s \\<in> b\" by fact\n  have \"\\<Gamma>\\<turnstile>mark_guards f c \\<down> Normal s\" by fact\n  moreover \n  {\n    fix t\n    assume exec_mark: \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c,Normal s \\<rangle> \\<Rightarrow> t\"\n    have \"\\<Gamma>\\<turnstile>mark_guards f (While b c) \\<down> t\"\n    proof -\n      from exec_mark_guards_to_exec [OF exec_mark] obtain t' where\n        exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> t'\" and\n        t_Fault: \"isFault t \\<longrightarrow> isFault t'\" and\n        t'_Fault_f: \"t' = Fault f \\<longrightarrow> t' = t\" and\n        t'_Fault: \"isFault t' \\<longrightarrow> isFault t\" and\n        t'_noFault: \"\\<not> isFault t' \\<longrightarrow> t' = t\"\n        by blast\n      show ?thesis\n      proof (cases \"isFault t'\")\n        case True\n        with t'_Fault have \"isFault t\" by simp\n        thus ?thesis\n          by (auto elim: isFaultE)\n      next\n        case False\n        with t'_noFault have \"t'=t\" by simp\n        with exec_c1 WhileTrue.hyps\n        show ?thesis\n          by auto\n      qed\n    qed  \n  }\n  ultimately show ?case\n    by (auto intro: terminates.intros)\nnext\n  case WhileFalse thus ?case by (fastforce intro: terminates.intros)\nnext\n  case Call thus ?case by (fastforce intro: terminates.intros)\nnext\n  case CallUndefined thus ?case by (fastforce intro: terminates.intros)\nnext\n  case Stuck thus ?case by (fastforce intro: terminates.intros)\nnext\n  case DynCom thus ?case by (fastforce intro: terminates.intros)\nnext\n  case Throw thus ?case by (fastforce intro: terminates.intros)\nnext\n  case Abrupt thus ?case by (fastforce intro: terminates.intros)\nnext \n  case (Catch c1 s c2) \n  have \"\\<Gamma>\\<turnstile>mark_guards f c1 \\<down> Normal s\" by fact\n  moreover \n  {\n    fix t\n    assume exec_mark: \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c1,Normal s \\<rangle> \\<Rightarrow> Abrupt t\"\n    have \"\\<Gamma>\\<turnstile>mark_guards f c2 \\<down> Normal t\"\n    proof -\n      from exec_mark_guards_to_exec [OF exec_mark] obtain t' where\n        exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow> t'\" and\n        t'_Fault_f: \"t' = Fault f \\<longrightarrow> t' = Abrupt t\" and\n        t'_Fault: \"isFault t' \\<longrightarrow> isFault (Abrupt t)\" and\n        t'_noFault: \"\\<not> isFault t' \\<longrightarrow> t' = Abrupt t\"\n        by fastforce\n      show ?thesis\n      proof (cases \"isFault t'\")\n        case True\n        with t'_Fault have \"isFault (Abrupt t)\" by simp\n        thus ?thesis by simp\n      next\n        case False\n        with t'_noFault have \"t'=Abrupt t\" by simp\n        with exec_c1 Catch.hyps\n        show ?thesis\n          by auto\n      qed\n    qed  \n  }\n  ultimately show ?case\n    by (auto intro: terminates.intros)\nqed\n\nlemma terminates_mark_guards_to_terminates_Normal:\n  \"\\<And>s. \\<Gamma>\\<turnstile>mark_guards f c\\<down>Normal s \\<Longrightarrow> \\<Gamma>\\<turnstile>c\\<down>Normal s\"\nproof (induct c)\n  case Skip thus ?case by (fastforce intro: terminates.intros)\nnext\n  case Basic thus ?case by (fastforce intro: terminates.intros)\nnext\n  case Spec thus ?case by (fastforce intro: terminates.intros)\nnext\n  case (Seq c1 c2) \n  have \"\\<Gamma>\\<turnstile>mark_guards f (Seq c1 c2) \\<down> Normal s\" by fact\n  then obtain\n    termi_merge_c1: \"\\<Gamma>\\<turnstile>mark_guards f c1 \\<down> Normal s\" and\n    termi_merge_c2: \"\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>mark_guards f c1,Normal s \\<rangle> \\<Rightarrow> s' \\<longrightarrow> \n                           \\<Gamma>\\<turnstile>mark_guards f c2 \\<down> s'\"\n    by (auto elim: terminates_Normal_elim_cases)\n  from termi_merge_c1 Seq.hyps\n  have \"\\<Gamma>\\<turnstile>c1 \\<down> Normal s\" by iprover\n  moreover\n  {\n    fix s'\n    assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow> s'\"\n    have \"\\<Gamma>\\<turnstile> c2 \\<down> s'\"\n    proof (cases \"isFault s'\")\n      case True\n      thus ?thesis by (auto elim: isFaultE)\n    next\n      case False\n      from exec_to_exec_mark_guards [OF exec_c1 False] \n      have \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c1,Normal s \\<rangle> \\<Rightarrow> s'\" .\n      from termi_merge_c2 [rule_format, OF this] Seq.hyps\n      show ?thesis\n        by (cases s') (auto)\n    qed\n  }\n  ultimately show ?case by (auto intro: terminates.intros)\nnext\n  case Cond thus ?case \n    by (fastforce intro: terminates.intros elim: terminates_Normal_elim_cases)\nnext\n  case (While b c)\n  {\n    fix u c'\n    assume termi_c': \"\\<Gamma>\\<turnstile>c' \\<down> Normal u\"\n    assume c': \"c' = mark_guards f (While b c)\"\n    have \"\\<Gamma>\\<turnstile>While b c \\<down> Normal u\"\n      using termi_c' c'\n    proof (induct)\n      case (WhileTrue s b' c')\n      have s_in_b: \"s \\<in> b\" using WhileTrue by simp\n      have \"\\<Gamma>\\<turnstile>mark_guards f c \\<down> Normal s\"\n        using WhileTrue by (auto elim: terminates_Normal_elim_cases)\n      with While.hyps have \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n        by auto\n      moreover\n      have hyp_w: \"\\<forall>w. \\<Gamma>\\<turnstile>\\<langle>mark_guards f c,Normal s \\<rangle> \\<Rightarrow> w \\<longrightarrow> \\<Gamma>\\<turnstile>While b c \\<down> w\"\n        using WhileTrue by simp\n      hence \"\\<forall>w. \\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> w \\<longrightarrow> \\<Gamma>\\<turnstile>While b c \\<down> w\"\n        apply -\n        apply (rule allI)\n        apply (case_tac \"w\")\n        apply (auto dest: exec_to_exec_mark_guards)\n        done\n      ultimately show ?case\n        using s_in_b\n        by (auto intro: terminates.intros)\n    next\n      case WhileFalse thus ?case by (auto intro: terminates.intros) \n    qed auto\n  }\n  with While show ?case by simp\nnext\n  case Call thus ?case \n    by (fastforce intro: terminates.intros )\nnext\n  case DynCom thus ?case \n    by (fastforce intro: terminates.intros elim: terminates_Normal_elim_cases)\nnext\n  case (Guard f g c)\n  thus ?case by (fastforce intro: terminates.intros elim: terminates_Normal_elim_cases)\nnext\n  case Throw thus ?case \n    by (fastforce intro: terminates.intros )\nnext\n  case (Catch c1 c2) \n  have \"\\<Gamma>\\<turnstile>mark_guards f (Catch c1 c2) \\<down> Normal s\" by fact\n  then obtain\n    termi_merge_c1: \"\\<Gamma>\\<turnstile>mark_guards f c1 \\<down> Normal s\" and\n    termi_merge_c2: \"\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>mark_guards f c1,Normal s \\<rangle> \\<Rightarrow> Abrupt s' \\<longrightarrow> \n                           \\<Gamma>\\<turnstile>mark_guards f c2 \\<down> Normal s'\"\n    by (auto elim: terminates_Normal_elim_cases)\n  from termi_merge_c1 Catch.hyps\n  have \"\\<Gamma>\\<turnstile>c1 \\<down> Normal s\" by iprover\n  moreover\n  {\n    fix s'\n    assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow> Abrupt s'\"\n    have \"\\<Gamma>\\<turnstile> c2 \\<down> Normal s'\"\n    proof -\n      from exec_to_exec_mark_guards [OF exec_c1] \n      have \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c1,Normal s \\<rangle> \\<Rightarrow> Abrupt s'\" by simp\n      from termi_merge_c2 [rule_format, OF this] Catch.hyps\n      show ?thesis\n        by iprover\n    qed\n  }\n  ultimately show ?case by (auto intro: terminates.intros)\nqed\n\nlemma terminates_mark_guards_to_terminates:\n  \"\\<Gamma>\\<turnstile>mark_guards f c\\<down>s \\<Longrightarrow> \\<Gamma>\\<turnstile>c\\<down> s\"\n  by (cases s) (auto intro: terminates_mark_guards_to_terminates_Normal)\n\n\n(* ************************************************************************* *)\nsubsection {* Lemmas about @{const \"merge_guards\"} *}\n(* ************************************************************************ *)\n\nlemma terminates_to_terminates_merge_guards:\n  assumes termi: \"\\<Gamma>\\<turnstile>c\\<down>s\" \n  shows \"\\<Gamma>\\<turnstile>merge_guards c\\<down>s\"\nusing termi\nproof (induct)\n  case (Guard s g c f)\n  have s_in_g: \"s \\<in> g\" by fact\n  have termi_merge_c: \"\\<Gamma>\\<turnstile>merge_guards c \\<down> Normal s\" by fact\n  show ?case\n  proof (cases \"\\<exists>f' g' c'. merge_guards c = Guard f' g' c'\")\n    case False\n    hence \"merge_guards (Guard f g c) = Guard f g (merge_guards c)\"\n      by (cases \"merge_guards c\") (auto simp add: Let_def)\n    with s_in_g termi_merge_c show ?thesis\n      by (auto intro: terminates.intros)\n  next\n    case True\n    then obtain f' g' c' where \n      mc: \"merge_guards c = Guard f' g' c'\"\n      by blast\n    show ?thesis\n    proof (cases \"f=f'\")\n      case False\n      with mc have \"merge_guards (Guard f g c) = Guard f g (merge_guards c)\"\n        by (simp add: Let_def)\n      with s_in_g termi_merge_c show ?thesis\n        by (auto intro: terminates.intros)\n    next\n      case True\n      with mc have \"merge_guards (Guard f g c) = Guard f (g \\<inter> g') c'\"\n        by simp\n      with s_in_g mc True termi_merge_c\n      show ?thesis\n        by (cases \"s \\<in> g'\")\n           (auto intro: terminates.intros elim: terminates_Normal_elim_cases)\n    qed\n  qed\nnext\n  case (GuardFault s g f c)\n  have \"s \\<notin> g\" by fact\n  thus ?case\n    by (cases \"merge_guards c\")\n       (auto intro: terminates.intros split: if_split_asm simp add: Let_def)\nqed (fastforce intro: terminates.intros dest: exec_merge_guards_to_exec)+\n\nlemma terminates_merge_guards_to_terminates_Normal:\n  shows \"\\<And>s. \\<Gamma>\\<turnstile>merge_guards c\\<down>Normal s \\<Longrightarrow> \\<Gamma>\\<turnstile>c\\<down>Normal s\"\nproof (induct c)\n  case Skip thus ?case by (fastforce intro: terminates.intros)\nnext\n  case Basic thus ?case by (fastforce intro: terminates.intros)\nnext\n  case Spec thus ?case by (fastforce intro: terminates.intros)\nnext\n  case (Seq c1 c2) \n  have \"\\<Gamma>\\<turnstile>merge_guards (Seq c1 c2) \\<down> Normal s\" by fact\n  then obtain\n    termi_merge_c1: \"\\<Gamma>\\<turnstile>merge_guards c1 \\<down> Normal s\" and\n    termi_merge_c2: \"\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>merge_guards c1,Normal s \\<rangle> \\<Rightarrow> s' \\<longrightarrow> \n                           \\<Gamma>\\<turnstile>merge_guards c2 \\<down> s'\"\n    by (auto elim: terminates_Normal_elim_cases)\n  from termi_merge_c1 Seq.hyps\n  have \"\\<Gamma>\\<turnstile>c1 \\<down> Normal s\" by iprover\n  moreover\n  {\n    fix s'\n    assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow> s'\"\n    have \"\\<Gamma>\\<turnstile> c2 \\<down> s'\"\n    proof -\n      from exec_to_exec_merge_guards [OF exec_c1] \n      have \"\\<Gamma>\\<turnstile>\\<langle>merge_guards c1,Normal s \\<rangle> \\<Rightarrow> s'\" .\n      from termi_merge_c2 [rule_format, OF this] Seq.hyps\n      show ?thesis\n        by (cases s') (auto)\n    qed\n  }\n  ultimately show ?case by (auto intro: terminates.intros)\nnext\n  case Cond thus ?case \n    by (fastforce intro: terminates.intros elim: terminates_Normal_elim_cases)\nnext\n  case (While b c)\n  {\n    fix u c'\n    assume termi_c': \"\\<Gamma>\\<turnstile>c' \\<down> Normal u\"\n    assume c': \"c' = merge_guards (While b c)\"\n    have \"\\<Gamma>\\<turnstile>While b c \\<down> Normal u\"\n      using termi_c' c'\n    proof (induct)\n      case (WhileTrue s b' c')\n      have s_in_b: \"s \\<in> b\" using WhileTrue by simp\n      have \"\\<Gamma>\\<turnstile>merge_guards c \\<down> Normal s\"\n        using WhileTrue by (auto elim: terminates_Normal_elim_cases)\n      with While.hyps have \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n        by auto\n      moreover\n      have hyp_w: \"\\<forall>w. \\<Gamma>\\<turnstile>\\<langle>merge_guards c,Normal s \\<rangle> \\<Rightarrow> w \\<longrightarrow> \\<Gamma>\\<turnstile>While b c \\<down> w\"\n        using WhileTrue by simp\n      hence \"\\<forall>w. \\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> w \\<longrightarrow> \\<Gamma>\\<turnstile>While b c \\<down> w\"\n        by (simp add: exec_iff_exec_merge_guards [symmetric])\n      ultimately show ?case\n        using s_in_b\n        by (auto intro: terminates.intros)\n    next\n      case WhileFalse thus ?case by (auto intro: terminates.intros) \n    qed auto\n  }\n  with While show ?case by simp\nnext\n  case Call thus ?case \n    by (fastforce intro: terminates.intros )\nnext\n  case DynCom thus ?case \n    by (fastforce intro: terminates.intros elim: terminates_Normal_elim_cases)\nnext\n  case (Guard f g c)\n  have termi_merge: \"\\<Gamma>\\<turnstile>merge_guards (Guard f g c) \\<down> Normal s\" by fact\n  show ?case\n  proof (cases \"\\<exists>f' g' c'. merge_guards c = Guard f' g' c'\")\n    case False\n    hence m: \"merge_guards (Guard f g c) = Guard f g (merge_guards c)\"\n      by (cases \"merge_guards c\") (auto simp add: Let_def)\n    from termi_merge Guard.hyps show ?thesis\n      by (simp only: m)\n         (fastforce intro: terminates.intros elim: terminates_Normal_elim_cases)\n  next\n    case True\n    then obtain f' g' c' where \n      mc: \"merge_guards c = Guard f' g' c'\"\n      by blast\n    show ?thesis\n    proof (cases \"f=f'\")\n      case False\n      with mc have m: \"merge_guards (Guard f g c) = Guard f g (merge_guards c)\"\n        by (simp add: Let_def)\n      from termi_merge Guard.hyps show ?thesis\n      by (simp only: m)\n         (fastforce intro: terminates.intros elim: terminates_Normal_elim_cases)\n    next\n      case True\n      with mc have m: \"merge_guards (Guard f g c) = Guard f (g \\<inter> g') c'\"\n        by simp\n      from termi_merge Guard.hyps\n      show ?thesis\n        by (simp only: m mc)\n           (auto intro: terminates.intros elim: terminates_Normal_elim_cases)\n    qed\n  qed\nnext\n  case Throw thus ?case \n    by (fastforce intro: terminates.intros )\nnext\n  case (Catch c1 c2) \n  have \"\\<Gamma>\\<turnstile>merge_guards (Catch c1 c2) \\<down> Normal s\" by fact\n  then obtain\n    termi_merge_c1: \"\\<Gamma>\\<turnstile>merge_guards c1 \\<down> Normal s\" and\n    termi_merge_c2: \"\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>merge_guards c1,Normal s \\<rangle> \\<Rightarrow> Abrupt s' \\<longrightarrow> \n                           \\<Gamma>\\<turnstile>merge_guards c2 \\<down> Normal s'\"\n    by (auto elim: terminates_Normal_elim_cases)\n  from termi_merge_c1 Catch.hyps\n  have \"\\<Gamma>\\<turnstile>c1 \\<down> Normal s\" by iprover\n  moreover\n  {\n    fix s'\n    assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow> Abrupt s'\"\n    have \"\\<Gamma>\\<turnstile> c2 \\<down> Normal s'\"\n    proof -\n      from exec_to_exec_merge_guards [OF exec_c1] \n      have \"\\<Gamma>\\<turnstile>\\<langle>merge_guards c1,Normal s \\<rangle> \\<Rightarrow> Abrupt s'\" .\n      from termi_merge_c2 [rule_format, OF this] Catch.hyps\n      show ?thesis\n        by iprover\n    qed\n  }\n  ultimately show ?case by (auto intro: terminates.intros)\nqed\n\nlemma terminates_merge_guards_to_terminates:\n   \"\\<Gamma>\\<turnstile>merge_guards c\\<down> s \\<Longrightarrow> \\<Gamma>\\<turnstile>c\\<down> s\"\nby (cases s) (auto intro: terminates_merge_guards_to_terminates_Normal)\n\ntheorem terminates_iff_terminates_merge_guards:\n  \"\\<Gamma>\\<turnstile>c\\<down> s = \\<Gamma>\\<turnstile>merge_guards c\\<down> s\"\n  by (iprover intro: terminates_to_terminates_merge_guards \n    terminates_merge_guards_to_terminates)\n\n(* ************************************************************************* *)\nsubsection {* Lemmas about @{term \"c\\<^sub>1 \\<subseteq>\\<^sub>g c\\<^sub>2\"} *}\n(* ************************************************************************ *)\n\nlemma terminates_fewer_guards_Normal:\n  shows \"\\<And>c s. \\<lbrakk>\\<Gamma>\\<turnstile>c'\\<down>Normal s; c \\<subseteq>\\<^sub>g c'; \\<Gamma>\\<turnstile>\\<langle>c',Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\\<rbrakk>\n              \\<Longrightarrow> \\<Gamma>\\<turnstile>c\\<down>Normal s\"\nproof (induct c')\n  case Skip thus ?case by (auto intro: terminates.intros dest: subseteq_guardsD)\nnext\n  case Basic thus ?case by (auto intro: terminates.intros dest: subseteq_guardsD)\nnext\n  case Spec thus ?case by (auto intro: terminates.intros dest: subseteq_guardsD)\nnext\n  case (Seq c1' c2')\n  have termi: \"\\<Gamma>\\<turnstile>Seq c1' c2' \\<down> Normal s\" by fact\n  then obtain \n    termi_c1': \"\\<Gamma>\\<turnstile>c1'\\<down> Normal s\" and\n    termi_c2': \"\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>c1',Normal s \\<rangle> \\<Rightarrow> s' \\<longrightarrow> \\<Gamma>\\<turnstile>c2'\\<down> s'\"\n    by (auto elim: terminates_Normal_elim_cases)\n  have noFault: \"\\<Gamma>\\<turnstile>\\<langle>Seq c1' c2',Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\" by fact\n  hence noFault_c1': \"\\<Gamma>\\<turnstile>\\<langle>c1',Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\"\n    by (auto intro: exec.intros simp add: final_notin_def)\n  have \"c \\<subseteq>\\<^sub>g Seq c1' c2'\" by fact\n  from subseteq_guards_Seq [OF this] obtain c1 c2 where \n    c: \"c = Seq c1 c2\" and\n    c1_c1': \"c1 \\<subseteq>\\<^sub>g c1'\" and\n    c2_c2': \"c2 \\<subseteq>\\<^sub>g c2'\" \n    by blast\n  from termi_c1' c1_c1' noFault_c1'\n  have \"\\<Gamma>\\<turnstile>c1\\<down> Normal s\"\n    by (rule Seq.hyps)\n  moreover\n  {\n    fix t\n    assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow> t\"\n    have \"\\<Gamma>\\<turnstile>c2\\<down> t\"\n    proof -\n      from exec_to_exec_subseteq_guards [OF c1_c1' exec_c1] obtain t' where\n        exec_c1': \"\\<Gamma>\\<turnstile>\\<langle>c1',Normal s \\<rangle> \\<Rightarrow> t'\" and\n        t_Fault: \"isFault t \\<longrightarrow> isFault t'\" and\n        t'_noFault: \"\\<not> isFault t' \\<longrightarrow> t' = t\"\n        by blast\n      show ?thesis\n      proof (cases \"isFault t'\")\n        case True\n        with exec_c1' noFault_c1'\n        have False\n          by (fastforce elim: isFaultE dest: Fault_end simp add: final_notin_def)\n        thus ?thesis ..\n      next\n        case False\n        with t'_noFault have t': \"t'=t\" by simp\n        with termi_c2' exec_c1' \n        have termi_c2': \"\\<Gamma>\\<turnstile>c2'\\<down> t\"\n          by auto\n        show ?thesis\n        proof (cases t)\n          case Fault thus ?thesis by auto\n        next\n          case Abrupt thus ?thesis by auto\n        next\n          case Stuck thus ?thesis by auto\n        next\n          case (Normal u)\n          with noFault exec_c1' t' \n          have \"\\<Gamma>\\<turnstile>\\<langle>c2',Normal u \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\"\n            by (auto intro: exec.intros simp add: final_notin_def)\n          from termi_c2' [simplified Normal] c2_c2' this\n          have \"\\<Gamma>\\<turnstile>c2 \\<down> Normal u\"\n            by (rule Seq.hyps)\n          with Normal exec_c1\n          show ?thesis by simp\n        qed\n      qed\n    qed\n  }\n  ultimately show ?case using c by (auto intro: terminates.intros)\nnext\n  case (Cond b c1' c2')\n  have noFault: \"\\<Gamma>\\<turnstile>\\<langle>Cond b c1' c2',Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\" by fact\n  have termi: \"\\<Gamma>\\<turnstile>Cond b c1' c2' \\<down> Normal s\" by fact\n  have \"c \\<subseteq>\\<^sub>g Cond b c1' c2'\" by fact\n  from subseteq_guards_Cond [OF this] obtain c1 c2 where\n    c: \"c = Cond b c1 c2\" and\n    c1_c1': \"c1 \\<subseteq>\\<^sub>g c1'\" and\n    c2_c2': \"c2 \\<subseteq>\\<^sub>g c2'\" \n    by blast\n  thus ?case \n  proof (cases \"s \\<in> b\")\n    case True\n    with termi have termi_c1': \"\\<Gamma>\\<turnstile>c1' \\<down> Normal s\"\n      by (auto elim: terminates_Normal_elim_cases)\n    from True noFault have \"\\<Gamma>\\<turnstile>\\<langle>c1',Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\"\n      by (auto intro: exec.intros simp add: final_notin_def)\n    from termi_c1' c1_c1' this\n    have \"\\<Gamma>\\<turnstile>c1 \\<down> Normal s\"\n      by (rule Cond.hyps)\n    with True c show ?thesis\n      by (auto intro: terminates.intros)\n  next\n    case False\n    with termi have termi_c2': \"\\<Gamma>\\<turnstile>c2' \\<down> Normal s\"\n      by (auto elim: terminates_Normal_elim_cases)\n    from False noFault have \"\\<Gamma>\\<turnstile>\\<langle>c2',Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\"\n      by (auto intro: exec.intros simp add: final_notin_def)\n    from termi_c2' c2_c2' this\n    have \"\\<Gamma>\\<turnstile>c2 \\<down> Normal s\"\n      by (rule Cond.hyps)\n    with False c show ?thesis\n      by (auto intro: terminates.intros)\n  qed\nnext\n  case (While b c')\n  have noFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c',Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\" by fact\n  have termi: \"\\<Gamma>\\<turnstile>While b c' \\<down> Normal s\" by fact\n  have \"c \\<subseteq>\\<^sub>g While b c'\" by fact\n  from subseteq_guards_While [OF this]\n  obtain c'' where \n    c: \"c = While b c''\" and\n    c''_c': \"c'' \\<subseteq>\\<^sub>g c'\"\n    by blast\n  {\n    fix d u\n    assume termi: \"\\<Gamma>\\<turnstile>d \\<down> u\"\n    assume d: \"d = While b c'\"\n    assume noFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c',u \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\"\n    have \"\\<Gamma>\\<turnstile>While b c'' \\<down> u\"\n    using termi d noFault\n    proof (induct)\n      case (WhileTrue u b' c''')\n      have u_in_b: \"u \\<in> b\" using WhileTrue by simp\n      have termi_c': \"\\<Gamma>\\<turnstile>c' \\<down> Normal u\" using WhileTrue by simp\n      have noFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c',Normal u \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\" using WhileTrue by simp\n      hence noFault_c': \"\\<Gamma>\\<turnstile>\\<langle>c',Normal u \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\" using u_in_b\n        by (auto intro: exec.intros simp add: final_notin_def)\n      from While.hyps [OF termi_c' c''_c' this] \n      have \"\\<Gamma>\\<turnstile>c'' \\<down> Normal u\".\n      moreover\n      from WhileTrue \n      have hyp_w: \"\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>c',Normal u \\<rangle> \\<Rightarrow> s'  \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>While b c',s' \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV \n                        \\<longrightarrow> \\<Gamma>\\<turnstile>While b c'' \\<down> s'\"\n        by simp\n      {\n        fix v\n        assume exec_c'': \"\\<Gamma>\\<turnstile>\\<langle>c'',Normal u \\<rangle> \\<Rightarrow> v\"\n        have \"\\<Gamma>\\<turnstile>While b c'' \\<down> v\"\n        proof - \n          from exec_to_exec_subseteq_guards [OF c''_c' exec_c''] obtain v' where\n            exec_c': \"\\<Gamma>\\<turnstile>\\<langle>c',Normal u \\<rangle> \\<Rightarrow> v'\" and\n            v_Fault: \"isFault v \\<longrightarrow> isFault v'\" and \n            v'_noFault: \"\\<not> isFault v' \\<longrightarrow> v' = v\"\n            by auto\n          show ?thesis\n          proof (cases \"isFault v'\")\n            case True\n            with exec_c' noFault u_in_b\n            have False\n              by (fastforce \n                   simp add: final_notin_def intro: exec.intros elim: isFaultE)\n            thus ?thesis ..\n          next\n            case False\n            with v'_noFault have v': \"v'=v\"\n              by simp\n            with noFault exec_c' u_in_b\n            have \"\\<Gamma>\\<turnstile>\\<langle>While b c',v \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\"\n              by (fastforce simp add: final_notin_def intro: exec.intros)\n            from hyp_w [rule_format, OF exec_c' [simplified v'] this]\n            show \"\\<Gamma>\\<turnstile>While b c'' \\<down> v\" .\n          qed\n        qed\n      }\n      ultimately\n      show ?case using u_in_b \n        by (auto intro: terminates.intros)\n    next\n      case WhileFalse thus ?case by (auto intro: terminates.intros)\n    qed auto\n  }\n  with c noFault termi show ?case\n    by auto\nnext\n  case Call thus ?case by (auto intro: terminates.intros dest: subseteq_guardsD)\nnext\n  case (DynCom C') \n  have termi: \"\\<Gamma>\\<turnstile>DynCom C' \\<down> Normal s\" by fact\n  hence termi_C': \"\\<Gamma>\\<turnstile>C' s \\<down> Normal s\"\n    by cases\n  have noFault: \"\\<Gamma>\\<turnstile>\\<langle>DynCom C',Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\" by fact\n  hence noFault_C': \"\\<Gamma>\\<turnstile>\\<langle>C' s,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\"\n    by (auto intro: exec.intros simp add: final_notin_def)\n  have \"c \\<subseteq>\\<^sub>g DynCom C'\" by fact\n  from subseteq_guards_DynCom [OF this] obtain C where\n    c: \"c = DynCom C\" and\n    C_C': \"\\<forall>s. C s \\<subseteq>\\<^sub>g C' s\"\n    by blast\n  from DynCom.hyps termi_C' C_C' [rule_format] noFault_C'\n  have \"\\<Gamma>\\<turnstile>C s \\<down> Normal s\"\n    by fast\n  with c show ?case\n    by (auto intro: terminates.intros)\nnext \n  case (Guard f' g' c')\n  have noFault: \"\\<Gamma>\\<turnstile>\\<langle>Guard f' g' c',Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\" by fact\n  have termi: \"\\<Gamma>\\<turnstile>Guard f' g' c' \\<down> Normal s\" by fact\n  have \"c \\<subseteq>\\<^sub>g Guard f' g' c'\" by fact\n  hence c_cases: \"(c \\<subseteq>\\<^sub>g c') \\<or> (\\<exists>c''. c = Guard f' g' c'' \\<and> (c'' \\<subseteq>\\<^sub>g c'))\"\n    by (rule subseteq_guards_Guard)\n  thus ?case\n  proof (cases \"s \\<in> g'\")\n    case True\n    note s_in_g' = this\n    with noFault have noFault_c': \"\\<Gamma>\\<turnstile>\\<langle>c',Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\"\n      by (auto simp add: final_notin_def intro: exec.intros)\n    from termi s_in_g' have termi_c': \"\\<Gamma>\\<turnstile>c' \\<down> Normal s\"\n      by cases auto\n    from c_cases show ?thesis\n    proof\n      assume \"c \\<subseteq>\\<^sub>g c'\"\n      from termi_c' this noFault_c'\n      show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\" \n        by (rule Guard.hyps)\n    next\n      assume \"\\<exists>c''. c = Guard f' g' c'' \\<and> (c'' \\<subseteq>\\<^sub>g c')\"\n      then obtain c'' where\n        c: \"c = Guard f' g' c''\" and c''_c': \"c'' \\<subseteq>\\<^sub>g c'\" \n        by blast\n      from termi_c' c''_c' noFault_c'\n      have \"\\<Gamma>\\<turnstile>c'' \\<down> Normal s\" \n        by (rule Guard.hyps)\n      with s_in_g' c\n      show ?thesis\n        by (auto intro: terminates.intros)\n    qed\n  next\n    case False\n    with noFault have False\n      by (auto intro: exec.intros simp add: final_notin_def)\n    thus ?thesis ..\n  qed\nnext\n  case Throw thus ?case by (auto intro: terminates.intros dest: subseteq_guardsD)\nnext\n  case (Catch c1' c2')\n  have termi: \"\\<Gamma>\\<turnstile>Catch c1' c2' \\<down> Normal s\" by fact\n  then obtain \n    termi_c1': \"\\<Gamma>\\<turnstile>c1'\\<down> Normal s\" and\n    termi_c2': \"\\<forall>s'. \\<Gamma>\\<turnstile>\\<langle>c1',Normal s \\<rangle> \\<Rightarrow> Abrupt s' \\<longrightarrow> \\<Gamma>\\<turnstile>c2'\\<down> Normal s'\"\n    by (auto elim: terminates_Normal_elim_cases)\n  have noFault: \"\\<Gamma>\\<turnstile>\\<langle>Catch c1' c2',Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\" by fact\n  hence noFault_c1': \"\\<Gamma>\\<turnstile>\\<langle>c1',Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\"\n    by (fastforce intro: exec.intros simp add: final_notin_def)\n  have \"c \\<subseteq>\\<^sub>g Catch c1' c2'\"  by fact\n  from subseteq_guards_Catch [OF this] obtain c1 c2 where \n    c: \"c = Catch c1 c2\" and\n    c1_c1': \"c1 \\<subseteq>\\<^sub>g c1'\" and\n    c2_c2': \"c2 \\<subseteq>\\<^sub>g c2'\" \n    by blast\n  from termi_c1' c1_c1' noFault_c1'\n  have \"\\<Gamma>\\<turnstile>c1\\<down> Normal s\"\n    by (rule Catch.hyps)\n  moreover\n  {\n    fix t\n    assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow> Abrupt t\"\n    have \"\\<Gamma>\\<turnstile>c2\\<down> Normal t\"\n    proof -\n      from exec_to_exec_subseteq_guards [OF c1_c1' exec_c1] obtain t' where\n        exec_c1': \"\\<Gamma>\\<turnstile>\\<langle>c1',Normal s \\<rangle> \\<Rightarrow> t'\" and\n        t'_noFault: \"\\<not> isFault t' \\<longrightarrow> t' = Abrupt t\"\n        by blast\n      show ?thesis\n      proof (cases \"isFault t'\")\n        case True\n        with exec_c1' noFault_c1'\n        have False\n          by (fastforce elim: isFaultE dest: Fault_end simp add: final_notin_def)\n        thus ?thesis ..\n      next\n        case False\n        with t'_noFault have t': \"t'=Abrupt t\" by simp\n        with termi_c2' exec_c1' \n        have termi_c2': \"\\<Gamma>\\<turnstile>c2'\\<down> Normal t\"\n          by auto\n        with noFault exec_c1' t' \n        have \"\\<Gamma>\\<turnstile>\\<langle>c2',Normal t \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\"\n          by (auto intro: exec.intros simp add: final_notin_def)\n        from termi_c2' c2_c2' this\n        show \"\\<Gamma>\\<turnstile>c2 \\<down> Normal t\"\n          by (rule Catch.hyps)\n      qed\n    qed\n  }\n  ultimately show ?case using c by (auto intro: terminates.intros)\nqed\n\ntheorem terminates_fewer_guards:\n  shows \"\\<lbrakk>\\<Gamma>\\<turnstile>c'\\<down>s; c \\<subseteq>\\<^sub>g c'; \\<Gamma>\\<turnstile>\\<langle>c',s \\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\\<rbrakk>\n         \\<Longrightarrow> \\<Gamma>\\<turnstile>c\\<down>s\"\n  by (cases s) (auto intro: terminates_fewer_guards_Normal)\n\nlemma terminates_noFault_strip_guards:\n  assumes termi: \"\\<Gamma>\\<turnstile>c\\<down>Normal s\"\n  shows \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\\<rbrakk> \\<Longrightarrow> \\<Gamma>\\<turnstile>strip_guards F c\\<down>Normal s\"\nusing termi\nproof (induct)\n  case Skip thus ?case by (auto intro: terminates.intros)\nnext\n  case Basic thus ?case by (auto intro: terminates.intros)\nnext\n  case Spec thus ?case by (auto intro: terminates.intros)\nnext\n  case (Guard s g c f)\n  have s_in_g: \"s \\<in> g\" by fact\n  have \"\\<Gamma>\\<turnstile>c \\<down> Normal s\" by fact\n  have \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\" by fact\n  with s_in_g have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\"\n    by (fastforce simp add: final_notin_def intro: exec.intros)\n  with Guard.hyps have \"\\<Gamma>\\<turnstile>strip_guards F c \\<down> Normal s\" by simp\n  with s_in_g show ?case\n    by (auto intro: terminates.intros)\nnext\n  case GuardFault thus ?case \n    by (auto intro: terminates.intros exec.intros simp add: final_notin_def )\nnext\n  case Fault thus ?case by (auto intro: terminates.intros)\nnext\n  case (Seq c1 s c2) \n  have noFault_Seq: \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\" by fact\n  hence noFault_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\"\n    by (auto simp add: final_notin_def intro: exec.intros)\n  with Seq.hyps have \"\\<Gamma>\\<turnstile>strip_guards F c1 \\<down> Normal s\" by simp\n  moreover\n  {\n    fix s'\n    assume exec_strip_guards_c1: \"\\<Gamma>\\<turnstile>\\<langle>strip_guards F c1,Normal s \\<rangle> \\<Rightarrow> s'\"\n    have \"\\<Gamma>\\<turnstile>strip_guards F c2 \\<down> s'\"\n    proof (cases \"isFault s'\")\n      case True\n      thus ?thesis by (auto elim: isFaultE intro: terminates.intros)\n    next\n      case False\n      with exec_strip_guards_to_exec [OF exec_strip_guards_c1] noFault_c1\n      have \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow> s'\"\n        by (auto simp add: final_notin_def elim!: isFaultE)\n      moreover\n      from this noFault_Seq have \"\\<Gamma>\\<turnstile>\\<langle>c2,s' \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\"\n        by (auto simp add: final_notin_def intro: exec.intros)\n      ultimately show ?thesis\n        using Seq.hyps by simp\n    qed\n  }\n  ultimately show ?case\n    by (auto intro: terminates.intros)\nnext\n  case CondTrue thus ?case\n    by (fastforce intro: terminates.intros exec.intros simp add: final_notin_def ) \nnext\n  case CondFalse thus ?case\n    by (fastforce intro: terminates.intros exec.intros simp add: final_notin_def ) \nnext\n  case (WhileTrue s b c)\n  have s_in_b: \"s \\<in> b\" by fact\n  have noFault_while: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\" by fact\n  with s_in_b have noFault_c: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\"\n    by (auto simp add: final_notin_def intro: exec.intros)\n  with WhileTrue.hyps have \"\\<Gamma>\\<turnstile>strip_guards F c \\<down> Normal s\" by simp\n  moreover\n  {\n    fix s'\n    assume exec_strip_guards_c: \"\\<Gamma>\\<turnstile>\\<langle>strip_guards F c,Normal s \\<rangle> \\<Rightarrow> s'\"\n    have \"\\<Gamma>\\<turnstile>strip_guards F (While b c) \\<down> s'\"\n    proof (cases \"isFault s'\")\n      case True\n      thus ?thesis by (auto elim: isFaultE intro: terminates.intros)\n    next\n      case False\n      with exec_strip_guards_to_exec [OF exec_strip_guards_c] noFault_c\n      have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> s'\"\n        by (auto simp add: final_notin_def elim!: isFaultE)\n      moreover\n      from this s_in_b noFault_while have \"\\<Gamma>\\<turnstile>\\<langle>While b c,s' \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\"\n        by (auto simp add: final_notin_def intro: exec.intros)\n      ultimately show ?thesis\n        using WhileTrue.hyps by simp\n    qed\n  }\n  ultimately show ?case\n    using WhileTrue.hyps by (auto intro: terminates.intros)\nnext\n  case WhileFalse thus ?case by (auto intro: terminates.intros)\nnext\n  case Call thus ?case by (auto intro: terminates.intros)\nnext\n  case CallUndefined thus ?case by (auto intro: terminates.intros)\nnext\n  case Stuck thus ?case by (auto intro: terminates.intros)\nnext\n  case DynCom thus ?case \n    by (auto intro: terminates.intros exec.intros simp add: final_notin_def )\nnext\n  case Throw thus ?case by (auto intro: terminates.intros)\nnext\n  case Abrupt thus ?case by (auto intro: terminates.intros)\nnext\n  case (Catch c1 s c2)\n  have noFault_Catch: \"\\<Gamma>\\<turnstile>\\<langle>Catch c1 c2,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\" by fact\n  hence noFault_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\"\n    by (fastforce simp add: final_notin_def intro: exec.intros)\n  with Catch.hyps have \"\\<Gamma>\\<turnstile>strip_guards F c1 \\<down> Normal s\" by simp\n  moreover\n  {\n    fix s'\n    assume exec_strip_guards_c1: \"\\<Gamma>\\<turnstile>\\<langle>strip_guards F c1,Normal s \\<rangle> \\<Rightarrow> Abrupt s'\"\n    have \"\\<Gamma>\\<turnstile>strip_guards F c2 \\<down> Normal s'\"\n    proof -\n      from exec_strip_guards_to_exec [OF exec_strip_guards_c1] noFault_c1\n      have \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow> Abrupt s'\"\n        by (auto simp add: final_notin_def elim!: isFaultE)\n      moreover\n      from this noFault_Catch have \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal s' \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\"\n        by (auto simp add: final_notin_def intro: exec.intros)\n      ultimately show ?thesis\n        using Catch.hyps by simp\n    qed\n  }\n  ultimately show ?case\n    using Catch.hyps by (auto intro: terminates.intros)\nqed\n\n(* ************************************************************************* *)\nsubsection {* Lemmas about @{const \"strip_guards\"} *}\n(* ************************************************************************* *)\n\nlemma terminates_noFault_strip:\n  assumes termi: \"\\<Gamma>\\<turnstile>c\\<down>Normal s\"\n  shows \"\\<lbrakk>\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\\<rbrakk> \\<Longrightarrow> strip F \\<Gamma>\\<turnstile>c\\<down>Normal s\"\nusing termi\nproof (induct)\n  case Skip thus ?case by (auto intro: terminates.intros)\nnext\n  case Basic thus ?case by (auto intro: terminates.intros)\nnext\n  case Spec thus ?case by (auto intro: terminates.intros)\nnext\n  case (Guard s g c f)\n  have s_in_g: \"s \\<in> g\" by fact\n  have \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\" by fact\n  with s_in_g have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\"\n    by (fastforce simp add: final_notin_def intro: exec.intros)\n  then have \"strip F \\<Gamma>\\<turnstile>c \\<down> Normal s\" by (simp add: Guard.hyps) \n  with s_in_g show ?case\n    by (auto intro: terminates.intros simp del: strip_simp)\nnext\n  case GuardFault thus ?case \n    by (auto intro: terminates.intros exec.intros simp add: final_notin_def )\nnext\n  case Fault thus ?case by (auto intro: terminates.intros)\nnext\n  case (Seq c1 s c2) \n  have noFault_Seq: \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\" by fact\n  hence noFault_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\"\n    by (auto simp add: final_notin_def intro: exec.intros)\n  then have \"strip F \\<Gamma>\\<turnstile>c1 \\<down> Normal s\" by (simp add: Seq.hyps)\n  moreover\n  {\n    fix s'\n    assume exec_strip_c1: \"strip F \\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow> s'\"\n    have \"strip F \\<Gamma>\\<turnstile>c2 \\<down> s'\"\n    proof (cases \"isFault s'\")\n      case True\n      thus ?thesis by (auto elim: isFaultE intro: terminates.intros)\n    next\n      case False\n      with exec_strip_to_exec [OF exec_strip_c1] noFault_c1\n      have \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow> s'\"\n        by (auto simp add: final_notin_def elim!: isFaultE)\n      moreover\n      from this noFault_Seq have \"\\<Gamma>\\<turnstile>\\<langle>c2,s' \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\"\n        by (auto simp add: final_notin_def intro: exec.intros)\n      ultimately show ?thesis\n        using Seq.hyps by (simp del: strip_simp)\n    qed\n  }\n  ultimately show ?case\n    by (fastforce intro: terminates.intros)\nnext\n  case CondTrue thus ?case\n    by (fastforce intro: terminates.intros exec.intros simp add: final_notin_def ) \nnext\n  case CondFalse thus ?case\n    by (fastforce intro: terminates.intros exec.intros simp add: final_notin_def ) \nnext\n  case (WhileTrue s b c)\n  have s_in_b: \"s \\<in> b\" by fact\n  have noFault_while: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\" by fact\n  with s_in_b have noFault_c: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\"\n    by (auto simp add: final_notin_def intro: exec.intros)\n  then have \"strip F \\<Gamma>\\<turnstile>c \\<down> Normal s\" by (simp add: WhileTrue.hyps)\n  moreover\n  {\n    fix s'\n    assume exec_strip_c: \"strip F \\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> s'\"\n    have \"strip F \\<Gamma>\\<turnstile>While b c \\<down> s'\"\n    proof (cases \"isFault s'\")\n      case True\n      thus ?thesis by (auto elim: isFaultE intro: terminates.intros)\n    next\n      case False\n      with exec_strip_to_exec [OF exec_strip_c] noFault_c\n      have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> s'\"\n        by (auto simp add: final_notin_def elim!: isFaultE)\n      moreover\n      from this s_in_b noFault_while have \"\\<Gamma>\\<turnstile>\\<langle>While b c,s' \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\"\n        by (auto simp add: final_notin_def intro: exec.intros)\n      ultimately show ?thesis\n        using WhileTrue.hyps by (simp del: strip_simp)\n    qed\n  }\n  ultimately show ?case\n    using WhileTrue.hyps by (auto intro: terminates.intros simp del: strip_simp)\nnext\n  case WhileFalse thus ?case by (auto intro: terminates.intros)\nnext\n  case (Call p bdy s) \n  have bdy: \"\\<Gamma> p = Some bdy\" by fact\n  have \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\" by fact\n  with bdy have bdy_noFault: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\"\n    by (auto intro: exec.intros simp add: final_notin_def)\n  then have strip_bdy_noFault: \"strip F \\<Gamma>\\<turnstile>\\<langle>bdy,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\"\n    by (auto simp add: final_notin_def dest!: exec_strip_to_exec elim!: isFaultE)\n\n  from bdy_noFault have \"strip F \\<Gamma>\\<turnstile>bdy \\<down> Normal s\" by (simp add: Call.hyps)\n  from terminates_noFault_strip_guards [OF this strip_bdy_noFault]\n  have \"strip F \\<Gamma>\\<turnstile>strip_guards F bdy \\<down> Normal s\".\n  with bdy show ?case\n    by (fastforce intro: terminates.Call)\nnext\n  case CallUndefined thus ?case by (auto intro: terminates.intros)\nnext\n  case Stuck thus ?case by (auto intro: terminates.intros)\nnext\n  case DynCom thus ?case \n    by (auto intro: terminates.intros exec.intros simp add: final_notin_def )\nnext\n  case Throw thus ?case by (auto intro: terminates.intros)\nnext\n  case Abrupt thus ?case by (auto intro: terminates.intros)\nnext\n  case (Catch c1 s c2)\n  have noFault_Catch: \"\\<Gamma>\\<turnstile>\\<langle>Catch c1 c2,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\" by fact\n  hence noFault_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\"\n    by (fastforce simp add: final_notin_def intro: exec.intros)\n  then have \"strip F \\<Gamma>\\<turnstile>c1 \\<down> Normal s\" by (simp add: Catch.hyps)\n  moreover\n  {\n    fix s'\n    assume exec_strip_c1: \"strip F \\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow> Abrupt s'\"\n    have \"strip F \\<Gamma>\\<turnstile>c2 \\<down> Normal s'\"\n    proof -\n      from exec_strip_to_exec [OF exec_strip_c1] noFault_c1\n      have \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow> Abrupt s'\"\n        by (auto simp add: final_notin_def elim!: isFaultE)\n      moreover\n      from this noFault_Catch have \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal s' \\<rangle> \\<Rightarrow>\\<notin>Fault ` F\"\n        by (auto simp add: final_notin_def intro: exec.intros)\n      ultimately show ?thesis\n        using Catch.hyps by (simp del: strip_simp)\n    qed\n  }\n  ultimately show ?case\n    using Catch.hyps by (auto intro: terminates.intros simp del: strip_simp)\nqed\n\n\n(* ************************************************************************* *)\nsubsection {* Miscellaneous *}\n(* ************************************************************************* *)\n\nlemma terminates_while_lemma:\n  assumes termi: \"\\<Gamma>\\<turnstile>w\\<down>fk\" \n  shows \"\\<And>k b c. \\<lbrakk>fk = Normal (f k); w=While b c; \n                       \\<forall>i. \\<Gamma>\\<turnstile>\\<langle>c,Normal (f i) \\<rangle> \\<Rightarrow> Normal (f (Suc i))\\<rbrakk>\n         \\<Longrightarrow> \\<exists>i. f i \\<notin> b\"\nusing termi\nproof (induct)\n  case WhileTrue thus ?case by blast\nnext\n  case WhileFalse thus ?case by blast\nqed simp_all\n\nlemma terminates_while:\n  \"\\<lbrakk>\\<Gamma>\\<turnstile>(While b c)\\<down>Normal (f k);  \n    \\<forall>i. \\<Gamma>\\<turnstile>\\<langle>c,Normal (f i) \\<rangle> \\<Rightarrow> Normal (f (Suc i))\\<rbrakk>\n         \\<Longrightarrow> \\<exists>i. f i \\<notin> b\"\n  by (blast intro: terminates_while_lemma)\n\nlemma wf_terminates_while: \n \"wf {(t,s). \\<Gamma>\\<turnstile>(While b c)\\<down>Normal s \\<and> s\\<in>b \\<and> \n             \\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> Normal t}\"\napply(subst wf_iff_no_infinite_down_chain)\napply(rule notI)\napply clarsimp\napply(insert terminates_while)\napply blast\ndone\n\nlemma terminates_restrict_to_terminates:\n  assumes terminates_res: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile> c \\<down> s\"\n  assumes not_Stuck: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>\\<langle>c,s \\<rangle> \\<Rightarrow>\\<notin>{Stuck}\"\n  shows \"\\<Gamma>\\<turnstile> c \\<down> s\"\nusing terminates_res not_Stuck\nproof (induct)\n  case Skip show ?case by (rule terminates.Skip)\nnext\n  case Basic show ?case by (rule terminates.Basic)\nnext\n  case Spec show ?case by (rule terminates.Spec)\nnext\n  case Guard thus ?case \n    by (auto intro: terminates.Guard dest: notStuck_GuardD)\nnext\n  case GuardFault thus ?case by (auto intro: terminates.GuardFault)\nnext\n  case Fault show ?case by (rule terminates.Fault)\nnext\n  case (Seq c1 s c2) \n  have not_Stuck: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>\\<langle>Seq c1 c2,Normal s \\<rangle> \\<Rightarrow>\\<notin>{Stuck}\" by fact\n  hence c1_notStuck: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow>\\<notin>{Stuck}\"\n    by (rule notStuck_SeqD1)\n  show \"\\<Gamma>\\<turnstile>Seq c1 c2 \\<down> Normal s\"\n  proof (rule terminates.Seq,safe)\n    from c1_notStuck\n    show \"\\<Gamma>\\<turnstile>c1 \\<down> Normal s\"\n      by (rule Seq.hyps)\n  next\n    fix s'\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow> s'\"\n    show \"\\<Gamma>\\<turnstile>c2 \\<down> s'\"\n    proof -\n      from exec_to_exec_restrict [OF exec] obtain t' where\n        exec_res: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow> t'\" and \n        t'_notStuck: \"t' \\<noteq> Stuck \\<longrightarrow> t' = s'\"\n        by blast\n      show ?thesis\n      proof (cases \"t'=Stuck\")\n        case True\n        with c1_notStuck exec_res have \"False\"\n          by (auto simp add: final_notin_def)\n        thus ?thesis ..\n      next\n        case False\n        with t'_notStuck have t': \"t'=s'\" by simp\n        with not_Stuck exec_res\n        have \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>\\<langle>c2,s' \\<rangle> \\<Rightarrow>\\<notin>{Stuck}\"\n          by (auto dest: notStuck_SeqD2) \n        with exec_res t' Seq.hyps\n        show ?thesis\n          by auto\n      qed\n    qed\n  qed\nnext\n  case CondTrue thus ?case \n    by (auto intro: terminates.CondTrue dest: notStuck_CondTrueD)\nnext\n  case CondFalse thus ?case \n    by (auto intro: terminates.CondFalse dest: notStuck_CondFalseD)\nnext\n  case (WhileTrue s b c)\n  have s: \"s \\<in> b\" by fact\n  have not_Stuck: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>\\<langle>While b c,Normal s \\<rangle> \\<Rightarrow>\\<notin>{Stuck}\" by fact\n  with WhileTrue have c_notStuck: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow>\\<notin>{Stuck}\"\n    by (iprover intro:  notStuck_WhileTrueD1)\n  show ?case\n  proof (rule terminates.WhileTrue [OF s],safe)\n    from c_notStuck\n    show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n      by (rule WhileTrue.hyps)\n  next\n    fix s'\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> s'\"\n    show \"\\<Gamma>\\<turnstile>While b c \\<down> s'\"\n    proof -\n      from exec_to_exec_restrict [OF exec] obtain t' where\n        exec_res: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>\\<langle>c,Normal s \\<rangle> \\<Rightarrow> t'\" and \n        t'_notStuck: \"t' \\<noteq> Stuck \\<longrightarrow> t' = s'\"\n        by blast\n      show ?thesis\n      proof (cases \"t'=Stuck\")\n        case True\n        with c_notStuck exec_res have \"False\"\n          by (auto simp add: final_notin_def)\n        thus ?thesis ..\n      next\n        case False\n        with t'_notStuck have t': \"t'=s'\" by simp\n        with not_Stuck exec_res s\n        have \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>\\<langle>While b c,s' \\<rangle> \\<Rightarrow>\\<notin>{Stuck}\"\n          by (auto dest: notStuck_WhileTrueD2) \n        with exec_res t' WhileTrue.hyps\n        show ?thesis\n          by auto\n      qed\n    qed\n  qed\nnext\n  case WhileFalse then show ?case by (iprover intro: terminates.WhileFalse)\nnext\n  case Call thus ?case \n    by (auto intro: terminates.Call dest: notStuck_CallD restrict_SomeD)\nnext\n  case CallUndefined\n  thus ?case\n    by (auto dest: notStuck_CallDefinedD)\nnext\n  case Stuck show ?case by (rule terminates.Stuck)\nnext\n  case DynCom\n  thus ?case\n    by (auto intro: terminates.DynCom dest: notStuck_DynComD)\nnext\n  case Throw show ?case by (rule terminates.Throw)\nnext\n  case Abrupt show ?case by (rule terminates.Abrupt)\nnext\n  case (Catch c1 s c2) \n  have not_Stuck: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>\\<langle>Catch c1 c2,Normal s \\<rangle> \\<Rightarrow>\\<notin>{Stuck}\" by fact\n  hence c1_notStuck: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow>\\<notin>{Stuck}\"\n    by (rule notStuck_CatchD1)\n  show \"\\<Gamma>\\<turnstile>Catch c1 c2 \\<down> Normal s\"\n  proof (rule terminates.Catch,safe)\n    from c1_notStuck\n    show \"\\<Gamma>\\<turnstile>c1 \\<down> Normal s\"\n      by (rule Catch.hyps)\n  next\n    fix s'\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow> Abrupt s'\"\n    show \"\\<Gamma>\\<turnstile>c2 \\<down> Normal s'\"\n    proof -\n      from exec_to_exec_restrict [OF exec] obtain t' where\n        exec_res: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>\\<langle>c1,Normal s \\<rangle> \\<Rightarrow> t'\" and \n        t'_notStuck: \"t' \\<noteq> Stuck \\<longrightarrow> t' = Abrupt s'\"\n        by blast\n      show ?thesis\n      proof (cases \"t'=Stuck\")\n        case True\n        with c1_notStuck exec_res have \"False\"\n          by (auto simp add: final_notin_def)\n        thus ?thesis ..\n      next\n        case False\n        with t'_notStuck have t': \"t'=Abrupt s'\" by simp\n        with not_Stuck exec_res\n        have \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>\\<langle>c2,Normal s' \\<rangle> \\<Rightarrow>\\<notin>{Stuck}\"\n          by (auto dest: notStuck_CatchD2) \n        with exec_res t' Catch.hyps\n        show ?thesis\n          by auto\n      qed\n    qed\n  qed\nqed\n\nend", "meta": {"author": "CompSoftVer", "repo": "CSim2", "sha": "b09a4d77ea089168b1805db5204ac151df2b9eff", "save_path": "github-repos/isabelle/CompSoftVer-CSim2", "path": "github-repos/isabelle/CompSoftVer-CSim2/CSim2-b09a4d77ea089168b1805db5204ac151df2b9eff/ConCSimpl/EmbSimpl/Termination.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6187804337438501, "lm_q2_score": 0.40733340004593027, "lm_q1q2_score": 0.25204993795877795}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\n(*\n * A theoretical framework for reasoning about non-interference\n * of monadic programs.\n *)\n\ntheory EquivValid\nimports Corres_UL\nbegin\n\nsection\\<open>State equivalence validity\\<close>\n\ntext\\<open>\n\nA generalised information flow property.\n\nOften, we read in the entire state, but then only examine part of it.\nThe following property may be used to split up binds whose first part\ndoes this.\n\n@{term \"I\"} is the state relation that holds invariantly.\n\n@{term \"A\"} (also) holds between initial states.\n\n@{term \"B\"} (also) holds between final states.\n\n@{term \"P\"} holds in the initial state for @{term \"f\"}.\n\n@{term \"P'\"} holds in the initial state for @{term \"f'\"}.\n\n\\<close>\n\ndefinition\n  equiv_valid_2 :: \"('s \\<Rightarrow> 's \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> 's \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> 's \\<Rightarrow> bool) \\<Rightarrow> ('b \\<Rightarrow> 'c \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> bool) \\<Rightarrow> ('s,'b) nondet_monad \\<Rightarrow> ('s,'c) nondet_monad \\<Rightarrow> bool\"\nwhere\n  \"equiv_valid_2 I A B R P P' f f' \\<equiv> \\<forall>s t.\n       P s \\<and> P' t \\<and> I s t \\<and> A s t\n     \\<longrightarrow> (\\<forall>(rva, s') \\<in> fst (f s). \\<forall>(rvb, t') \\<in> fst (f' t).\n          R rva rvb \\<and> I s' t' \\<and> B s' t')\"\n\nlemma equiv_valid_2_bind_general:\n  assumes r2: \"\\<And> rv rv'. R' rv rv' \\<Longrightarrow> equiv_valid_2 D B C R (Q rv) (Q' rv') (g rv) (g' rv')\"\n  assumes r1: \"equiv_valid_2 D A B R' P P' f f'\"\n  assumes hoare: \"\\<lbrace> S \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  assumes hoare': \"\\<lbrace> S' \\<rbrace> f' \\<lbrace> Q' \\<rbrace>\"\n  shows \"equiv_valid_2 D A C R (\\<lambda> s. P s \\<and> S s) (\\<lambda> s. P' s \\<and> S' s) (f >>= g) (f' >>= g')\"\n  using assms\n  unfolding bind_def equiv_valid_2_def valid_def\n  apply fastforce\n  done\n\n(* almost all of the time, the second relation doesn't change *)\nlemma equiv_valid_2_bind:\n  assumes r2: \"\\<And> rv rv'. R' rv rv' \\<Longrightarrow> equiv_valid_2 D A A R (Q rv) (Q' rv') (g rv) (g' rv')\"\n  assumes r1: \"equiv_valid_2 D A A R' P P' f f'\"\n  assumes hoare: \"\\<lbrace> S \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  assumes hoare': \"\\<lbrace> S' \\<rbrace> f' \\<lbrace> Q' \\<rbrace>\"\n  shows \"equiv_valid_2 D A A R (\\<lambda> s. P s \\<and> S s) (\\<lambda> s. P' s \\<and> S' s) (f >>= g) (f' >>= g')\"\n  using assms by (blast intro: equiv_valid_2_bind_general)\n\nlemma equiv_valid_2_guard_imp:\n  assumes reads_res: \"equiv_valid_2 D A B R Q Q' f f'\"\n  assumes guard_imp: \"\\<And> s. P s \\<Longrightarrow> Q s\"\n  assumes guard_imp': \"\\<And> s. P' s \\<Longrightarrow> Q' s\"\n  shows \"equiv_valid_2 D A B R P P' f f'\"\n  using assms\n  by (fastforce simp: equiv_valid_2_def)\n\nlemma equiv_valid_2_bind_pre:\n  assumes r2: \"\\<And> rv rv'. R' rv rv' \\<Longrightarrow> equiv_valid_2 D A A R (Q rv) (Q' rv') (g rv) (g' rv')\"\n  assumes r1: \"equiv_valid_2 D A A R' P P' f f'\"\n  assumes hoare: \"\\<lbrace> S \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  assumes hoare': \"\\<lbrace> S' \\<rbrace> f' \\<lbrace> Q' \\<rbrace>\"\n  assumes guard_imp: \"\\<And> s. T s \\<Longrightarrow> P s \\<and> S s\"\n  assumes guard_imp': \"\\<And> s. T' s \\<Longrightarrow> P' s \\<and> S' s\"\n  shows \"equiv_valid_2 D A A R T T' (f >>= g) (f' >>= g')\"\n  using assms by (blast intro: equiv_valid_2_bind[THEN equiv_valid_2_guard_imp])\n\nlemma return_ev2:\n  assumes rel: \"\\<And> s t. \\<lbrakk>P s; P' t; I s t; A s t\\<rbrakk> \\<Longrightarrow> R a b\"\n  shows \"equiv_valid_2 I A A R P P' (return a) (return b)\"\n  by(auto simp: equiv_valid_2_def return_def rel)\n\nlemma equiv_valid_2_liftE:\n  \"equiv_valid_2 D A B R P P' f f' \\<Longrightarrow>\n   equiv_valid_2 D A B (E \\<oplus> R) P P' (liftE f) (liftE f')\"\n  apply(unfold liftE_def)\n  apply(rule equiv_valid_2_guard_imp)\n  apply(rule_tac Q=\"\\<top>\\<top>\" and Q'=\"\\<top>\\<top>\" and R'=R in equiv_valid_2_bind_general)\n       apply(fastforce intro: return_ev2)\n      apply assumption\n     apply(rule wp_post_taut)+\n   by(simp_all)\n\nlemma equiv_valid_2_liftE_bindE_general:\n  assumes r2: \"\\<And> rv rv'. R' rv rv' \\<Longrightarrow> equiv_valid_2 D B C R (Q rv) (Q' rv') (g rv) (g' rv')\"\n  assumes hoare: \"\\<lbrace> S \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  assumes hoare':  \"\\<lbrace> S' \\<rbrace> f' \\<lbrace> Q' \\<rbrace>\"\n  assumes r1: \"equiv_valid_2 D A B R' P P' f f'\"\n  shows \"equiv_valid_2 D A C R (P and S) (P' and S') (liftE f >>=E g) (liftE f' >>=E g')\"\n  apply(unfold bindE_def)\n  apply(rule equiv_valid_2_guard_imp)\n  apply(rule_tac Q=\"\\<lambda> rv. K (\\<forall> v. rv \\<noteq> Inl v) and (\\<lambda> s. \\<forall> v. rv = Inr v \\<longrightarrow> Q v s)\" and Q'=\"\\<lambda> rv. K (\\<forall> v. rv \\<noteq> Inl v) and (\\<lambda> s. \\<forall> v. rv = Inr v \\<longrightarrow> Q' v s)\" in equiv_valid_2_bind_general)\n       prefer 2\n       apply(rule_tac E=\"dc\" in equiv_valid_2_liftE)\n       apply(rule r1)\n      apply(clarsimp simp: lift_def split: sum.split)\n      apply(insert r2, fastforce simp: equiv_valid_2_def)[1]\n     apply(simp add: liftE_def, wp, fastforce intro!: hoare_strengthen_post[OF hoare])\n    apply(simp add: liftE_def, wp, fastforce intro!: hoare_strengthen_post[OF hoare'])\n   by(auto)\n\nlemma equiv_valid_2_liftE_bindE:\n  assumes r2: \"\\<And> rv rv'. R' rv rv' \\<Longrightarrow> equiv_valid_2 D A A R (Q rv) (Q' rv') (g rv) (g' rv')\"\n  assumes hoare: \"\\<lbrace> S \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  assumes hoare':  \"\\<lbrace> S' \\<rbrace> f' \\<lbrace> Q' \\<rbrace>\"\n  assumes r1: \"equiv_valid_2 D A A R' P P' f f'\"\n  shows \"equiv_valid_2 D A A R (P and S) (P' and S') (liftE f >>=E g) (liftE f' >>=E g')\"\n  using assms by(blast intro: equiv_valid_2_liftE_bindE_general)\n\nlemma equiv_valid_2_rvrel_imp:\n  \"\\<lbrakk>equiv_valid_2 I A A R P P' f f'; \\<And> s t. R s t \\<Longrightarrow> R' s t\\<rbrakk> \\<Longrightarrow>\n   equiv_valid_2 I A A R' P P' f f'\"\n  apply(fastforce simp: equiv_valid_2_def)\n  done\n\nsubsection\\<open>Specialised fixed-state state equivalence validity\\<close>\n\ntext\\<open>\n\nFor resolve_address_bits and rec_del: talk about a fixed initial\nstate. Note we only do this for one of the computations; the other\nstate can be constrained by how it is related to this one by @{term\n\"I\"} and so forth.\n\nAlso captures the typical case where the relation between the return\nvalues is equality and the required preconditions are identical.\n\nwp can cope with this.\n\n\\<close>\n\ndefinition\n  spec_equiv_valid :: \"'s \\<Rightarrow> ('s \\<Rightarrow> 's \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> 's \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> 's \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> bool) \\<Rightarrow> ('s,'b) nondet_monad \\<Rightarrow> bool\"\nwhere\n  \"spec_equiv_valid st I A B P f \\<equiv> equiv_valid_2 I A B (=) (P and ((=) st)) P f f\"\n\nabbreviation spec_equiv_valid_inv where\n  \"spec_equiv_valid_inv st I A P f \\<equiv> spec_equiv_valid st I A A P f\"\n\nsubsection\\<open>Specialised state equivalence validity\\<close>\n\ntext\\<open>\n\nMost of the time we deal with the streamlined version.\n\nwp can cope with this too.\n\n\\<close>\n\ndefinition\n  equiv_valid :: \"('s \\<Rightarrow> 's \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> 's \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> 's \\<Rightarrow> bool) \\<Rightarrow> ('s \\<Rightarrow> bool) \\<Rightarrow> ('s,'b) nondet_monad \\<Rightarrow> bool\"\nwhere\n  \"equiv_valid I A B P f \\<equiv> \\<forall>st. spec_equiv_valid st I A B P f\"\n\nlemma equiv_valid_def2:\n  \"equiv_valid I A B P f = equiv_valid_2 I A B (=) P P f f\"\n  by (simp add: equiv_valid_def spec_equiv_valid_def equiv_valid_2_def)\n\nabbreviation equiv_valid_rv where\n  \"equiv_valid_rv I A B R P f \\<equiv> equiv_valid_2 I A B R P P f f\"\n\n(* this is probably way more general than we need for all but a few special cases *)\nlemma bind_ev_general:\n  assumes reads_res_2: \"\\<And>rv. equiv_valid I B C (Q rv) (g rv)\"\n  assumes reads_res_1: \"equiv_valid I A B P' f\"\n  assumes hoare: \"\\<lbrace> P'' \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  shows \"equiv_valid I A C (\\<lambda>s. P' s \\<and> P'' s) (f >>= g)\"\n  unfolding equiv_valid_def2\n  apply (rule equiv_valid_2_bind_general[where R'=\"(=)\"])\n     apply (auto intro: reads_res_1[unfolded equiv_valid_def2] reads_res_2[unfolded equiv_valid_def2])[2]\n   apply (rule hoare)\n  apply (rule hoare)\n  done\n\nlemma bind_ev:\n  assumes reads_res_2: \"\\<And>rv. equiv_valid I A A (Q rv) (g rv)\"\n  assumes reads_res_1: \"equiv_valid I A A P' f\"\n  assumes hoare: \"\\<lbrace> P'' \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  shows \"equiv_valid I A A (\\<lambda>s. P' s \\<and> P'' s) (f >>= g)\"\n  using assms by (blast intro: bind_ev_general)\n\nlemma equiv_valid_guard_imp:\n  assumes reads_res: \"equiv_valid I A B Q f\"\n  assumes guard_imp: \"\\<And> s. P s \\<Longrightarrow> Q s\"\n  shows \"equiv_valid I A B P f\"\n  using assms by (fastforce simp: equiv_valid_def2 equiv_valid_2_def)\n\nlemmas bind_ev_pre = bind_ev[THEN equiv_valid_guard_imp]\n\nlemma gen_asm_ev':\n  assumes \"Q \\<Longrightarrow> equiv_valid D A B P f\"\n  shows \"equiv_valid D A B (P and K Q) f\"\n  using assms by (fastforce simp: equiv_valid_def2 equiv_valid_2_def)\n\ndeclare K_def [simp del]\n\nlemmas gen_asm_ev =\n  gen_asm_ev'[where P=\"\\<top>\", simplified]\n  gen_asm_ev'\n  gen_asm_ev'[simplified K_def, where P=\"\\<top>\", simplified]\n  gen_asm_ev'[simplified K_def]\n\ndeclare K_def [simp]\n\ntext \\<open>\n  This is a further streamlined version that we expect to get the most from\n  automating, and for the most part, we shouldn't need to deal with the\n  extra generality of the properties above.\n\\<close>\nabbreviation equiv_valid_inv where\n  \"equiv_valid_inv I A P f \\<equiv> equiv_valid I A A P f\"\n\nabbreviation equiv_valid_rv_inv where\n  \"equiv_valid_rv_inv I A R P f \\<equiv> equiv_valid_rv I A A R P f\"\n\nlemma get_evrv:\n  \"equiv_valid_rv_inv I A (I And A) \\<top> get\"\n  by(auto simp: equiv_valid_2_def get_def)\n\nlemma equiv_valid_rv_bind_general:\n  assumes ev1:\n  \"equiv_valid_rv I A B W P f\"\n  assumes ev2:\n  \"\\<And> rv rv'. W rv rv' \\<Longrightarrow> equiv_valid_2 I B C R (Q rv) (Q rv') (g rv) (g rv')\"\n  assumes hoare:\n  \"\\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  shows \"equiv_valid_rv I A C R P (f >>= g)\"\n  apply(rule equiv_valid_2_guard_imp)\n  apply(rule equiv_valid_2_bind_general[OF ev2])\n       apply(assumption)\n      apply(rule ev1)\n     apply(rule hoare)\n    apply(rule hoare)\n   apply(simp_all)\n  done\n\nlemma equiv_valid_rv_bind:\n  assumes ev1:\n  \"equiv_valid_rv_inv I A W P f\"\n  assumes ev2:\n  \"\\<And> rv rv'. W rv rv' \\<Longrightarrow> equiv_valid_2 I A A R (Q rv) (Q rv') (g rv) (g rv')\"\n  assumes hoare:\n  \"\\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  shows \"equiv_valid_rv_inv I A R P (f >>= g)\"\n  using assms by(blast intro: equiv_valid_rv_bind_general)\n\nlemma modify_ev2:\n  assumes \"\\<And> s t. \\<lbrakk>I s t; A s t; P s; P' t\\<rbrakk> \\<Longrightarrow> R () () \\<and> I (f s) (f' t) \\<and> B (f s) (f' t)\"\n  shows\n  \"equiv_valid_2 I A B R P P' (modify f) (modify f')\"\n  apply(clarsimp simp: equiv_valid_2_def in_monad)\n  using assms by auto\n\nlemma put_ev2:\n  assumes \"\\<And> s t. \\<lbrakk>I s t; A s t; P s; P' t\\<rbrakk> \\<Longrightarrow> R () () \\<and> I x x' \\<and> B x x'\"\n  shows\n  \"equiv_valid_2 I A B R P P' (put x) (put x')\"\n  apply(clarsimp simp: equiv_valid_2_def in_monad)\n  using assms by auto\n\n\nlemma get_bind_ev2:\n  assumes \"\\<And> rv rv'. \\<lbrakk>I rv rv'; A rv rv'\\<rbrakk> \\<Longrightarrow> equiv_valid_2 I A B R (P and ((=) rv)) (P' and ((=) rv')) (f rv) (f' rv')\"\n  shows \"equiv_valid_2 I A B R P P' (get >>= f) (get >>= f')\"\n  apply(rule equiv_valid_2_guard_imp)\n  apply(rule_tac R'=\"I And A\" in equiv_valid_2_bind_general)\n       apply(rule assms, simp+)\n      apply(rule get_evrv)\n     apply(wp get_sp)+\n   by(auto)\n\n\nlemma return_ev_pre:\n  \"equiv_valid_inv I A P (return x)\"\n  apply (simp add: equiv_valid_def2 return_ev2)\n  done\n\nlemmas return_ev = return_ev_pre[where P=\\<top>]\n\nlemma fail_ev2_l:\n  \"equiv_valid_2 I A B R P P' fail f'\"\n  by(simp add: equiv_valid_2_def fail_def)\n\nlemma fail_ev2_r:\n  \"equiv_valid_2 I A B R P P' f fail\"\n  by(simp add: equiv_valid_2_def fail_def)\n\nlemma fail_ev_pre:\n  \"equiv_valid I A B P fail\"\n  apply (simp add: equiv_valid_def2 fail_ev2_l)\n  done\n\nlemmas fail_ev = fail_ev_pre[where P=\\<top>]\n\nlemma assert_ev2:\n  \"R () () \\<Longrightarrow> equiv_valid_2 I A A R P P' (assert a) (assert b)\"\n  apply(simp add: assert_def fail_ev2_l fail_ev2_r)\n  apply(blast intro: return_ev2)\n  done\n\nlemma liftE_ev:\n  \"equiv_valid I A B P f \\<Longrightarrow> equiv_valid I A B P (liftE f)\"\n  unfolding liftE_def\n  apply (rule bind_ev_general[THEN equiv_valid_guard_imp, OF return_ev _ wp_post_taut])\n  apply fastforce+ (* schematic instantiation *)\n  done\n\nlemma if_ev:\n  assumes \"b \\<Longrightarrow> equiv_valid I A B P f\"\n  assumes \"\\<not> b \\<Longrightarrow> equiv_valid I A B Q g\"\n  shows \"equiv_valid I A B (\\<lambda>s. (b \\<longrightarrow> P s) \\<and> (\\<not>b \\<longrightarrow> Q s)) (if b then f else g)\"\n  apply (clarsimp split: if_split)\n  using assms by blast\n\nlemmas if_ev_pre = equiv_valid_guard_imp[OF if_ev]\n\nlemma assert_ev_pre:\n  \"equiv_valid_inv I A P (assert b)\"\n  apply(simp add: equiv_valid_def2 assert_ev2)\n  done\n\nlemmas assert_ev = assert_ev_pre[where P=\\<top>]\n\nlemma assert_opt_ev:\n  \"equiv_valid_inv I A \\<top> (assert_opt v)\"\n  apply (simp add: assert_opt_def return_ev fail_ev\n            split: option.split)\n  done\n\nlemma assert_opt_ev2:\n  assumes \"\\<And> a a'. \\<lbrakk>v = Some a; v' = Some a'\\<rbrakk> \\<Longrightarrow> R a a'\"\n  shows \"equiv_valid_2 I A A R \\<top> \\<top> (assert_opt v) (assert_opt v')\"\n  apply (simp add: assert_opt_def return_ev fail_ev2_l fail_ev2_r\n            split: option.split)\n  apply(intro allI impI)\n  apply(rule return_ev2)\n  apply(rule assms, assumption+)\n  done\n\nlemma select_f_ev:\n  \"equiv_valid_inv I A (K (det f)) (select_f (f x))\"\n  apply (rule gen_asm_ev)\n  apply (simp add: select_f_def equiv_valid_def2 equiv_valid_2_def det_set_iff)\n  done\n\nlemma gets_evrv:\n  \"equiv_valid_rv_inv I A R (K (\\<forall>s t. I s t \\<and> A s t \\<longrightarrow> R (f s) (f t))) (gets f)\"\n  apply (auto simp: equiv_valid_2_def in_monad)\n  done\n\nlemma gets_evrv':\n  \"equiv_valid_rv_inv I A R (\\<lambda>s. (\\<forall>t. I s t \\<and> A s t \\<longrightarrow> R (f s) (f t))) (gets f)\"\n  apply (auto simp: equiv_valid_2_def in_monad)\n  done\n\nlemma gets_evrv'':\n  \"\\<forall>s t. I s t \\<and> A s t \\<and> P s \\<and> P t \\<longrightarrow> R (f s) (f t) \\<Longrightarrow> equiv_valid_rv_inv I A R P (gets f)\"\n  apply (auto simp: equiv_valid_2_def in_monad)\n  done\n\nlemma equiv_valid_rv_guard_imp:\n  \"\\<lbrakk>equiv_valid_rv I A B R P f; \\<And> s. Q s \\<Longrightarrow> P s\\<rbrakk> \\<Longrightarrow>\n   equiv_valid_rv I A B R Q f\"\n  apply(simp add: equiv_valid_2_def)\n  apply fast\n  done\n\nlemma gets_ev:\n  shows \"equiv_valid_inv I A (\\<lambda> s. \\<forall> s t. I s t \\<and> A s t \\<longrightarrow> f s = f t) (gets f)\"\n  apply (simp add: equiv_valid_def2)\n  apply (auto intro: equiv_valid_rv_guard_imp[OF gets_evrv])\n  done\n\nlemma gets_ev':\n  shows \"equiv_valid_inv I A (\\<lambda> s. \\<forall> t. I s t \\<and> A s t \\<longrightarrow> f s = f t) (gets f)\"\n  apply (simp add: equiv_valid_def2)\n  apply (auto intro: equiv_valid_rv_guard_imp[OF gets_evrv'])\n  done\n\nlemma gets_ev'':\n  \"\\<forall>s t. I s t \\<and> A s t \\<and> P s \\<and> P t \\<longrightarrow> f s = f t \\<Longrightarrow> equiv_valid_inv I A P (gets f)\"\n  apply (simp add: equiv_valid_def2)\n  apply (auto intro: equiv_valid_rv_guard_imp[OF gets_evrv''])\n  done\n\nlemma gets_the_evrv:\n  \"equiv_valid_rv_inv I A R (K (\\<forall>s t. I s t \\<and> A s t \\<longrightarrow> R (the (f s)) (the (f t)))) (gets_the f)\"\n  unfolding gets_the_def\n  apply (rule equiv_valid_rv_bind)\n    apply(rule equiv_valid_rv_guard_imp[OF gets_evrv])\n    apply simp\n   apply(rule assert_opt_ev2)\n   apply simp\n  apply wp\n  done\n\nlemma gets_the_ev:\n  \"equiv_valid_inv I A (K (\\<forall>s t. I s t \\<and> A s t \\<longrightarrow> f s = f t)) (gets_the f)\"\n  unfolding equiv_valid_def2\n  apply(rule equiv_valid_rv_guard_imp[OF gets_the_evrv])\n  by simp\n\nlemma throwError_ev_pre:\n  \"equiv_valid_inv I A P (throwError e)\"\n  by (auto simp: throwError_def return_ev_pre)\n\nlemmas throwError_ev = throwError_ev_pre[where P=\\<top>]\n\nlemma returnOk_ev_pre:\n  \"equiv_valid_inv I A P (returnOk v)\"\n  by (auto simp: returnOk_def return_ev_pre)\n\nlemmas returnOk_ev = returnOk_ev_pre[where P=\\<top>]\n\n(* this seems restrictive, to have the same beginning and ending state relation,\n   however, one suspects that bindE is used usually only in code that doesn't\n   modify the state, so is probably OK.. We'll see *)\nlemma bindE_ev:\n  assumes reads_res_2: \"\\<And> rv. equiv_valid_inv I A (Q rv) (g rv)\"\n  assumes reads_res_1: \"equiv_valid_inv I A P' f\"\n  assumes hoare: \"\\<lbrace> P'' \\<rbrace> f \\<lbrace> Q \\<rbrace>,-\"\n  shows \"equiv_valid_inv I A (\\<lambda>s. P' s \\<and> P'' s) (f >>=E g)\"\n  unfolding bindE_def\n  apply (rule bind_ev)\n    prefer 3\n    apply(rule hoare[unfolded validE_R_def validE_def])\n   apply(simp split: sum.split add: lift_def throwError_ev)\n   apply(blast intro!: reads_res_2)\n  apply(rule reads_res_1)\n  done\n\nlemmas bindE_ev_pre = bindE_ev[THEN equiv_valid_guard_imp]\n\n(* Of course, when we know that progress is always made, we can do better *)\nlemma liftE_bindE_ev_general:\n  assumes r2: \"\\<And> val. equiv_valid I B C (Q val) (g val)\"\n  assumes r1: \"equiv_valid I A B P f\"\n  assumes hoare: \"\\<lbrace> R \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  shows \"equiv_valid I A C (\\<lambda> s. P s \\<and> R s) (liftE f >>=E g)\"\n  apply(simp add: bindE_def)\n  apply(rule_tac Q=\"\\<lambda> rv. K (\\<forall> v. rv \\<noteq> Inl v) and (\\<lambda> s. \\<forall> v. rv = Inr v \\<longrightarrow> Q v s)\" in bind_ev_general)\n    prefer 2\n    apply(rule liftE_ev)\n    apply(rule r1)\n   apply(insert r2, fastforce simp: lift_def split: sum.split simp: equiv_valid_def2 equiv_valid_2_def)[1]\n  apply(insert hoare, fastforce simp: valid_def liftE_def return_def bind_def)\n  done\n\nlemma liftE_bindE_ev:\n  assumes r2: \"\\<And> val. equiv_valid_inv I A (Q val) (g val)\"\n  assumes r1: \"equiv_valid_inv I A P f\"\n  assumes hoare: \"\\<lbrace> R \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  shows \"equiv_valid_inv I A (\\<lambda> s. P s \\<and> R s) (liftE f >>=E g)\"\n  using assms by (blast intro: liftE_bindE_ev_general)\n\nlemmas liftE_bindE_ev_pre = liftE_bindE_ev[THEN equiv_valid_guard_imp]\n\nlemma liftM_ev:\n  assumes reads_res: \"equiv_valid I A B P g\"\n  shows \"equiv_valid I A B P (liftM f g)\"\n  apply (simp add: liftM_def)\n  apply (rule bind_ev_general[THEN equiv_valid_guard_imp, OF return_ev reads_res wp_post_taut])\n  apply simp\n  done\n\nlemma liftME_ev:\n  assumes reads_res: \"equiv_valid_inv I A P g\"\n  shows \"equiv_valid_inv I A P (liftME f g)\"\n  apply(simp add: liftME_def)\n  apply (rule bindE_ev_pre[OF returnOk_ev reads_res])\n  apply (rule hoare_True_E_R)\n  apply fast\n  done\n\nlemma whenE_ev:\n  assumes a: \"b \\<Longrightarrow> equiv_valid_inv I A P m\"\n  shows \"equiv_valid_inv I A (\\<lambda>s. b \\<longrightarrow> P s) (whenE b m)\"\n  unfolding whenE_def by (auto intro: a returnOk_ev_pre)\n\nlemma whenE_throwError_bindE_ev:\n  assumes \"\\<And> rv. \\<not> b \\<Longrightarrow> equiv_valid_inv I A P (g rv)\"\n  shows \"equiv_valid_inv I A P (whenE b (throwError e) >>=E g)\"\n  apply (rule_tac Q=\"\\<lambda> rv. P and (\\<lambda> s. \\<not> b)\" in bindE_ev_pre)\n     apply (rule gen_asm_ev)\n     apply (blast intro: assms)\n    apply (rule whenE_ev)\n    apply (rule throwError_ev)\n   apply (wp whenE_throwError_wp)\n  apply simp\n  done\n\n(* FIXME: trivially generalised *)\nlemma K_bind_ev:\n  \"equiv_valid I A B P f \\<Longrightarrow> equiv_valid I A B P (K_bind f x)\"\n  by simp\n\nsubsection\\<open>wp setup\\<close>\n\nlemmas splits_ev[wp_split] =\n  bind_ev_pre bindE_ev_pre\n  bind_ev bindE_ev\n  if_ev_pre\n  if_ev\n\nlemmas wp_ev[wp] =\n  return_ev_pre\n  return_ev\n  liftE_ev\n  fail_ev_pre\n  fail_ev\n  assert_opt_ev\n  assert_ev\n  gets_ev\n  gets_the_ev\n  returnOk_ev_pre\n  returnOk_ev\n  throwError_ev_pre\n  throwError_ev\n  liftM_ev\n  liftME_ev\n  whenE_ev\n  K_bind_ev\n\nsubsection\\<open>crunch setup\\<close>\n\nlemmas pre_ev =\n  hoare_pre\n  equiv_valid_guard_imp\n\nsubsection\\<open>Tom instantiates wpc\\<close>\n\nlemma wpc_helper_equiv_valid:\n  \"equiv_valid D A B Q f \\<Longrightarrow> wpc_helper (P, P') (Q, Q') (equiv_valid D A B P f)\"\n  using equiv_valid_guard_imp\n  apply (simp add: wpc_helper_def)\n  apply (blast)\n  done\n\nwpc_setup \"\\<lambda>m. equiv_valid D A B Q m\" wpc_helper_equiv_valid\n\nsubsection\\<open>More hoare-like rules\\<close>\n\nlemma mapM_ev_pre:\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A I (m x)\"\n  assumes invariant: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> \\<lbrace> I \\<rbrace> m x \\<lbrace> \\<lambda>_. I \\<rbrace>\"\n  assumes inv_established: \"\\<And> s. P s \\<Longrightarrow> I s\"\n  shows \"equiv_valid_inv D A P (mapM m lst)\"\n  using assms\n  apply(atomize)\n  apply(rule_tac Q=I in equiv_valid_guard_imp)\n  apply(induct lst)\n    apply(simp add: mapM_Nil return_ev_pre)\n   apply(subst mapM_Cons)\n   apply(rule bind_ev_pre[where P''=\"I\"])\n    apply(rule bind_ev[OF return_ev])\n    apply fastforce\n    apply (rule wp_post_taut)\n    apply fastforce+\n  done\n\nlemma mapM_x_ev_pre:\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A I (m x)\"\n  assumes invariant: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> \\<lbrace> I \\<rbrace> m x \\<lbrace> \\<lambda>_. I \\<rbrace>\"\n  assumes inv_established: \"\\<And> s. P s \\<Longrightarrow> I s\"\n  shows \"equiv_valid_inv D A P (mapM_x m lst)\"\n  apply(subst mapM_x_mapM)\n  apply(rule bind_ev_pre[OF return_ev mapM_ev_pre])\n  apply (blast intro: reads_res invariant inv_established wp_post_taut)+\n  done\n\nlemma mapM_ev:\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A I (m x)\"\n  assumes invariant: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> \\<lbrace> I \\<rbrace> m x \\<lbrace> \\<lambda>_. I \\<rbrace>\"\n  shows \"equiv_valid_inv D A I (mapM m lst)\"\n  using assms by (auto intro: mapM_ev_pre)\n\nlemma mapM_x_ev:\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A I (m x)\"\n  assumes invariant: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> \\<lbrace> I \\<rbrace> m x \\<lbrace> \\<lambda>_. I \\<rbrace>\"\n  shows \"equiv_valid_inv D A I (mapM_x m lst)\"\n  using assms by (auto intro: mapM_x_ev_pre)\n\n(* MOVE -- proof clagged from mapM_x_mapM *)\nlemma mapME_x_mapME:\n  \"mapME_x f l = mapME f l >>=E (\\<lambda> y. returnOk ())\"\n  apply (simp add: mapME_x_def sequenceE_x_def mapME_def sequenceE_def)\n  apply (induct l, simp_all add: Let_def bindE_assoc)\n  done\n\nlemma mapME_ev_pre:\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A I (m x)\"\n  assumes invariant: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> \\<lbrace> I \\<rbrace> m x \\<lbrace> \\<lambda>_. I \\<rbrace>,-\"\n  assumes inv_established: \"\\<And> s. P s \\<Longrightarrow> I s\"\n  shows \"equiv_valid_inv D A P (mapME m lst)\"\n  using assms\n  apply(atomize)\n  apply(rule_tac Q=I in equiv_valid_guard_imp)\n  apply(induct lst)\n    apply(simp add: mapME_Nil returnOk_ev_pre)\n   apply(subst mapME_Cons)\n   apply wp\n   apply fastforce\n   apply (rule hoare_True_E_R[where P=\"\\<top>\"])\n   apply fastforce+\n  done\n\nlemma mapME_ev:\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv I A P (m x)\"\n  assumes invariant: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> \\<lbrace> P \\<rbrace> m x \\<lbrace> \\<lambda>_. P \\<rbrace>, -\"\n  shows \"equiv_valid_inv I A P (mapME m lst)\"\n  using assms by (auto intro: mapME_ev_pre)\n\nlemma mapME_x_ev_pre:\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A I (m x)\"\n  assumes invariant: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> \\<lbrace> I \\<rbrace> m x \\<lbrace> \\<lambda>_. I \\<rbrace>,-\"\n  assumes inv_established: \"\\<And> s. P s \\<Longrightarrow> I s\"\n  shows \"equiv_valid_inv D A P (mapME_x m lst)\"\n  unfolding mapME_x_mapME\n  apply (wp assms mapME_ev_pre | simp)+\n  done\n\nlemma mapME_x_ev:\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A I (m x)\"\n  assumes invariant: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> \\<lbrace> I \\<rbrace> m x \\<lbrace> \\<lambda>_. I \\<rbrace>, -\"\n  shows \"equiv_valid_inv D A I (mapME_x m lst)\"\n  using assms by (auto intro: mapME_x_ev_pre)\n\nlemma mapM_ev':\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A (K (P x)) (m x)\"\n  shows \"equiv_valid_inv D A (K (\\<forall>x\\<in>set lst. P x)) (mapM m lst)\"\n  apply(rule mapM_ev)\n  apply(rule equiv_valid_guard_imp[OF reads_res], simp+, wp)\n  done\n\nlemma mapM_x_ev':\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A (K (P x)) (m x)\"\n  shows \"equiv_valid_inv D A (K (\\<forall>x\\<in>set lst. P x)) (mapM_x m lst)\"\n  apply(rule mapM_x_ev)\n  apply(rule equiv_valid_guard_imp[OF reads_res], simp+, wp)\n  done\n\nlemma mapME_ev':\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A (K (P x)) (m x)\"\n  shows \"equiv_valid_inv D A (K (\\<forall>x\\<in>set lst. P x)) (mapME m lst)\"\n  apply(rule mapME_ev)\n  apply(rule equiv_valid_guard_imp[OF reads_res], simp+, wp)\n  done\n\nlemma mapME_x_ev':\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A (K (P x)) (m x)\"\n  shows \"equiv_valid_inv D A (K (\\<forall>x\\<in>set lst. P x)) (mapME_x m lst)\"\n  apply(rule mapME_x_ev)\n  apply(rule equiv_valid_guard_imp[OF reads_res], simp+, wp)\n  done\n\nsubsection\\<open>Rules for the specialised validity\\<close>\n\nlemma use_spec_ev:\n  \"(\\<And>st. spec_equiv_valid st I A B P f) \\<Longrightarrow> equiv_valid I A B P f\"\n  by (simp add: equiv_valid_def)\n\nlemma drop_spec_ev:\n  \"equiv_valid I A B P f \\<Longrightarrow> spec_equiv_valid st I A B P f\"\n  by (simp add: equiv_valid_def)\n\nlemma spec_equiv_valid_guard_imp:\n  assumes reads_res: \"spec_equiv_valid_inv s' I A P' f\"\n  assumes guard_imp: \"\\<And> s. P s \\<Longrightarrow> P' s\"\n  shows \"spec_equiv_valid_inv s' I A P f\"\n  using assms\n  by (fastforce simp: spec_equiv_valid_def equiv_valid_2_def)\n\nlemma bind_spec_ev:\n  assumes reads_res_2: \"\\<And> rv s''. (rv, s'') \\<in> fst (f s') \\<Longrightarrow> spec_equiv_valid_inv s'' I A (Q rv) (g rv)\"\n  assumes reads_res_1: \"spec_equiv_valid_inv s' I A P' f\"\n  assumes hoare: \"\\<lbrace>P''\\<rbrace> f \\<lbrace>Q\\<rbrace>\"\n  shows \"spec_equiv_valid_inv s' I A (\\<lambda>s. P' s \\<and> P'' s) (f >>= g)\"\n  using reads_res_1\n  apply (clarsimp simp: spec_equiv_valid_def equiv_valid_2_def valid_def bind_def split_def)\n  apply (erule_tac x=t in allE)\n  apply clarsimp\n  apply (erule_tac x=\"(a, b)\" in ballE)\n  apply (erule_tac x=\"(ab, bb)\" in ballE)\n  apply clarsimp\n  apply (cut_tac rv=\"ab\" and s''=\"b\" in reads_res_2)\n   apply assumption\n  apply (clarsimp simp: spec_equiv_valid_def equiv_valid_2_def)\n  apply(erule_tac x=bb in allE)\n  using hoare\n  apply (fastforce simp: valid_def)+\n  done\n\nlemma bindE_spec_ev:\n  assumes reads_res_2: \"\\<And> rv s''. (Inr rv, s'') \\<in> fst (f s') \\<Longrightarrow> spec_equiv_valid_inv s'' I A (Q rv) (g rv)\"\n  assumes reads_res_1: \"spec_equiv_valid_inv s' I A P' f\"\n  assumes hoare: \"\\<lbrace>P''\\<rbrace> f \\<lbrace>Q\\<rbrace>,-\"\n  shows \"spec_equiv_valid_inv s' I A (\\<lambda>s. P' s \\<and> P'' s) (f >>=E g)\"\n  unfolding bindE_def\n  apply (rule bind_spec_ev)\n    prefer 3\n    apply(rule hoare[simplified validE_R_def validE_def])\n   apply(simp split: sum.split add: lift_def)\n   apply(rule conjI)\n    apply(fastforce simp: spec_equiv_valid_def throwError_def return_ev2)\n   apply(fastforce simp: reads_res_2)\n  apply(rule reads_res_1)\n  done\n\nlemma if_spec_ev:\n  \"\\<lbrakk> G \\<Longrightarrow> spec_equiv_valid_inv s' I A P f;\n     \\<not> G \\<Longrightarrow> spec_equiv_valid_inv s' I A P' f'\n   \\<rbrakk>  \\<Longrightarrow> spec_equiv_valid_inv s' I A (\\<lambda>s. (G \\<longrightarrow> P s) \\<and> (\\<not> G \\<longrightarrow> P' s)) (if G then f else f')\"\n  by (cases G, simp+)\n\nlemmas splits_spec_ev[wp_split] =\n  drop_spec_ev\n  spec_equiv_valid_guard_imp[OF bind_spec_ev] spec_equiv_valid_guard_imp[OF bindE_spec_ev]\n  bind_spec_ev bindE_spec_ev\n  spec_equiv_valid_guard_imp[OF if_spec_ev] if_spec_ev\n\n(* Miscellaneous rules. *)\n\nlemma assertE_ev[wp]:\n  \"equiv_valid_inv I A \\<top> (assertE b)\"\n  unfolding assertE_def\n  apply wp\n  by simp\n\nlemma equiv_valid_2_bindE:\n  assumes g: \"\\<And>rv rv'. R' rv rv' \\<Longrightarrow>\n      equiv_valid_2 D A A (E \\<oplus> R) (Q rv) (Q' rv') (g rv) (g' rv')\"\n  assumes h1: \"\\<lbrace>S\\<rbrace> f \\<lbrace>Q\\<rbrace>,-\"\n  assumes h2: \"\\<lbrace>S'\\<rbrace> f' \\<lbrace>Q'\\<rbrace>,-\"\n  assumes f: \"equiv_valid_2 D A A (E \\<oplus> R') P P' f f'\"\n  shows \"equiv_valid_2 D A A (E \\<oplus> R) (P and S) (P' and S') (f >>=E g) (f' >>=E g')\"\n  apply(unfold bindE_def)\n  apply(rule equiv_valid_2_guard_imp)\n    apply(rule_tac R'=\"E \\<oplus> R'\" and Q=\"case_sum \\<top>\\<top> Q\" and Q'=\"case_sum \\<top>\\<top> Q'\" and S=S and S'=S' in equiv_valid_2_bind)\n       apply(clarsimp simp: lift_def split: sum.splits)\n       apply(intro impI conjI allI)\n          apply(simp add: throwError_def)\n          apply(rule return_ev2)\n          apply simp\n         apply(simp)\n        apply(simp)\n       apply(fastforce intro: g)\n      apply(rule f)\n     apply(insert h1, fastforce simp: valid_def validE_R_def validE_def split: sum.splits)[1]\n    apply(insert h2, fastforce simp: valid_def validE_R_def validE_def split: sum.splits)[1]\n   by auto\n\nlemma rel_sum_comb_equals:\n  \"((=) \\<oplus> (=)) = (=)\"\n  apply(rule ext)\n  apply(rule ext)\n  apply(rename_tac a b)\n  apply(case_tac a, auto)\n  done\n\ndefinition spec_equiv_valid_2_inv where\n  \"spec_equiv_valid_2_inv s I A R P P' f f' \\<equiv>\n      equiv_valid_2 I A A R (P and ((=) s)) P' f f'\"\n\nlemma spec_equiv_valid_def2:\n  \"spec_equiv_valid s I A A P f =\n   spec_equiv_valid_2_inv s I A (=) P P f f\"\n  apply(simp add: spec_equiv_valid_def spec_equiv_valid_2_inv_def)\n  done\n\nlemma drop_spec_ev2_inv:\n  \"equiv_valid_2 I A A R P P' f f' \\<Longrightarrow>\n   spec_equiv_valid_2_inv s I A R P P' f f'\"\n  apply(simp add: spec_equiv_valid_2_inv_def)\n  apply(erule equiv_valid_2_guard_imp, auto)\n  done\n\nlemma spec_equiv_valid_2_inv_guard_imp:\n  \"\\<lbrakk>spec_equiv_valid_2_inv s I A R Q Q' f f'; \\<And> s. P s \\<Longrightarrow> Q s; \\<And> s. P' s \\<Longrightarrow> Q' s\\<rbrakk> \\<Longrightarrow>\n    spec_equiv_valid_2_inv s I A R P P' f f'\"\n  by(auto simp: spec_equiv_valid_2_inv_def equiv_valid_2_def)\n\nlemma bind_spec_ev2:\n  assumes reads_res_2: \"\\<And> rv s' rv'. \\<lbrakk>(rv, s') \\<in> fst (f s); R' rv rv'\\<rbrakk> \\<Longrightarrow> spec_equiv_valid_2_inv s' I A R (Q rv) (Q' rv') (g rv) (g' rv')\"\n  assumes reads_res_1: \"spec_equiv_valid_2_inv s I A R' P P' f f'\"\n  assumes hoare: \"\\<lbrace>S\\<rbrace> f \\<lbrace>Q\\<rbrace>\"\n  assumes hoare': \"\\<lbrace>S'\\<rbrace> f' \\<lbrace>Q'\\<rbrace>\"\n  shows \"spec_equiv_valid_2_inv s I A R (P and S) (P' and S') (f >>= g) (f' >>= g')\"\n  using reads_res_1\n  apply (clarsimp simp: spec_equiv_valid_2_inv_def equiv_valid_2_def bind_def split_def)\n  apply (erule_tac x=t in allE)\n  apply clarsimp\n  apply (drule_tac x=\"(a, b)\" in bspec, assumption)\n  apply (drule_tac x=\"(ab, bb)\" in bspec, assumption)\n  apply clarsimp\n  apply (cut_tac rv=\"a\" and s'=\"b\" in reads_res_2)\n    apply assumption\n   apply assumption\n  apply (clarsimp simp: spec_equiv_valid_2_inv_def equiv_valid_2_def)\n  apply(drule_tac x=bb in spec)\n  apply clarsimp\n  using hoare hoare'\n  apply (fastforce simp: valid_def)+\n  done\n\nlemma spec_equiv_valid_2_inv_bindE:\n  assumes g: \"\\<And>rv s' rv'. \\<lbrakk>(Inr rv, s') \\<in> fst (f s); R' rv rv'\\<rbrakk> \\<Longrightarrow>\n      spec_equiv_valid_2_inv s' I A (E \\<oplus> R) (Q rv) (Q' rv') (g rv) (g' rv')\"\n  assumes h1: \"\\<lbrace>S\\<rbrace> f \\<lbrace>Q\\<rbrace>,-\"\n  assumes h2: \"\\<lbrace>S'\\<rbrace> f' \\<lbrace>Q'\\<rbrace>,-\"\n  assumes f: \"spec_equiv_valid_2_inv s I A (E \\<oplus> R') P P' f f'\"\n  shows \"spec_equiv_valid_2_inv s I A (E \\<oplus> R) (P and S) (P' and S') (f >>=E g) (f' >>=E g')\"\n  apply(unfold bindE_def)\n  apply(rule spec_equiv_valid_2_inv_guard_imp)\n    apply(rule_tac R'=\"E \\<oplus> R'\" and Q=\"case_sum \\<top>\\<top> Q\" and Q'=\"case_sum \\<top>\\<top> Q'\" and S=S and S'=S' in bind_spec_ev2)\n       apply(clarsimp simp: lift_def split: sum.splits)\n       apply(intro impI conjI allI)\n          apply(simp add: throwError_def)\n          apply(rule drop_spec_ev2_inv[OF return_ev2])\n          apply simp\n         apply(simp)\n        apply(simp)\n       apply(fastforce intro: g)\n      apply(rule f)\n     apply(insert h1, fastforce simp: valid_def validE_R_def validE_def split: sum.splits)[1]\n    apply(insert h2, fastforce simp: valid_def validE_R_def validE_def split: sum.splits)[1]\n   by auto\n\nlemma trancl_subset_equivalence:\n  \"\\<lbrakk>(a, b) \\<in> r'\\<^sup>+; \\<forall>x. (a, x)\\<in>r'\\<^sup>+ \\<longrightarrow> Q x; \\<forall>x y. Q x \\<longrightarrow> ((y, x) \\<in> r) = ((y, x) \\<in> r')\\<rbrakk> \\<Longrightarrow> (a, b) \\<in> r\\<^sup>+\"\n  apply(induct a b rule: trancl.induct)\n   apply(blast)\n  apply(simp)\n  apply(rule_tac b=b in trancl_into_trancl)\n   apply(simp)\n  apply(erule_tac x=c in allE)\n  apply(subgoal_tac \"(a, c) \\<in> r'\\<^sup>+\")\n   apply(auto)\n   done\n\nlemma equiv_valid_rv_gets_compD:\n  \"equiv_valid_rv_inv I A R P (gets (f \\<circ> g)) \\<Longrightarrow>\n   equiv_valid_rv_inv I A (\\<lambda> rv rv'. R (f rv) (f rv')) P (gets g)\"\n  apply(clarsimp simp: equiv_valid_2_def gets_def bind_def return_def get_def)\n  done\n\n\nlemma liftE_ev2:\n  \"equiv_valid_2 I A B R P P' f f' \\<Longrightarrow>\n   equiv_valid_2 I A B (E \\<oplus> R) P P' (liftE f) (liftE f')\"\n  apply(clarsimp simp: liftE_def equiv_valid_2_def bind_def return_def)\n  apply fastforce\n  done\n\nlemma whenE_spec_ev2_inv:\n  assumes a: \"b \\<Longrightarrow> spec_equiv_valid_2_inv s I A R P P' m m'\"\n  assumes r: \"\\<And> x. R x x\"\n  shows \"spec_equiv_valid_2_inv s I A R P P' (whenE b m) (whenE b m')\"\n  unfolding whenE_def\n  apply (auto intro: a simp: returnOk_def intro!: drop_spec_ev2_inv[OF return_ev2] intro: r)\n  done\n\nlemma whenE_spec_ev:\n  assumes a: \"b \\<Longrightarrow> spec_equiv_valid_inv s I A P m\"\n  shows \"spec_equiv_valid_inv s I A P  (whenE b m) \"\n  unfolding whenE_def\n  apply (auto intro: a simp: returnOk_def intro!: drop_spec_ev[OF return_ev_pre])\n  done\n\n\nlemma spec_equiv_valid_2_inv_by_spec_equiv_valid:\n  \"\\<lbrakk>spec_equiv_valid s I A A P f; P' = P; f' = f;\n    (\\<And> a. R a a)\\<rbrakk> \\<Longrightarrow>\n       spec_equiv_valid_2_inv s I A R P P' f f'\"\n  apply(clarsimp simp: spec_equiv_valid_def spec_equiv_valid_2_inv_def)\n  apply(fastforce simp: equiv_valid_2_def)\n  done\n\nlemma mapM_ev'':\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A (P x) (m x)\"\n  assumes inv: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> \\<lbrace> \\<lambda>s. \\<forall>x\\<in>set lst. P x s \\<rbrace> m x \\<lbrace> \\<lambda>_ s. \\<forall>x\\<in>set lst. P x s \\<rbrace>\"\n  shows \"equiv_valid_inv D A (\\<lambda> s. \\<forall>x\\<in>set lst. P x s) (mapM m lst)\"\n  apply(rule mapM_ev)\n  apply(rule equiv_valid_guard_imp[OF reads_res]; simp)\n  apply(wpsimp wp: inv)\n  done\n\nlemma mapM_x_ev'':\n  assumes reads_res: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> equiv_valid_inv D A (P x) (m x)\"\n  assumes inv: \"\\<And> x. x \\<in> set lst \\<Longrightarrow> \\<lbrace> \\<lambda>s. \\<forall>x\\<in>set lst. P x s \\<rbrace> m x \\<lbrace> \\<lambda>_ s. \\<forall>x\\<in>set lst. P x s \\<rbrace>\"\n  shows \"equiv_valid_inv D A (\\<lambda> s. \\<forall>x\\<in>set lst. P x s) (mapM_x m lst)\"\n  apply(rule mapM_x_ev)\n  apply(rule equiv_valid_guard_imp[OF reads_res]; simp)\n  apply(wpsimp wp: inv)\n  done\n\nlemma catch_ev[wp]:\n  assumes ok:\n    \"equiv_valid I A A P f\"\n  assumes err:\n    \"\\<And> e. equiv_valid I A A (E e) (handler e)\"\n  assumes hoare:\n    \"\\<lbrace> P \\<rbrace> f -, \\<lbrace> E \\<rbrace>\"\n  shows\n  \"equiv_valid I A A P (f <catch> handler)\"\n  apply(simp add: catch_def)\n  apply (wp err ok | wpc | simp)+\n   apply(insert hoare[simplified validE_E_def validE_def])[1]\n   apply(simp split: sum.splits)\n  by simp\n\nlemma equiv_valid_rv_trivial:\n  assumes inv: \"\\<And> P. \\<lbrace> P \\<rbrace> f \\<lbrace> \\<lambda>_. P \\<rbrace>\"\n  shows \"equiv_valid_rv_inv I A \\<top>\\<top> \\<top> f\"\n  by(auto simp: equiv_valid_2_def dest: state_unchanged[OF inv])\n\nlemma equiv_valid_2_trivial:\n  assumes inv: \"\\<And> P. \\<lbrace> P \\<rbrace> f \\<lbrace> \\<lambda>_. P \\<rbrace>\"\n  assumes inv': \"\\<And> P. \\<lbrace> P \\<rbrace> f' \\<lbrace> \\<lambda>_. P \\<rbrace>\"\n  shows \"equiv_valid_2 I A A \\<top>\\<top> \\<top> \\<top> f f'\"\n  by(auto simp: equiv_valid_2_def dest: state_unchanged[OF inv] state_unchanged[OF inv'])\n\nlemma gen_asm_ev2_r:\n  \"\\<lbrakk>P' \\<Longrightarrow> equiv_valid_2 I A B R P Q f f'\\<rbrakk> \\<Longrightarrow>\n   equiv_valid_2 I A B R P  (Q and (K P')) f f'\"\n  apply(fastforce simp: equiv_valid_2_def)\n  done\n\nlemma gen_asm_ev2_l:\n  \"\\<lbrakk>P \\<Longrightarrow> equiv_valid_2 I A B R Q P' f f'\\<rbrakk> \\<Longrightarrow>\n   equiv_valid_2 I A B R (Q and (K P)) P' f f'\"\n  apply(fastforce simp: equiv_valid_2_def)\n  done\n\nlemma gen_asm_ev2_r':\n  \"\\<lbrakk>P' \\<Longrightarrow> equiv_valid_2 I A B R P \\<top> f f'\\<rbrakk> \\<Longrightarrow>\n   equiv_valid_2 I A B R P (\\<lambda>s. P') f f'\"\n  apply(fastforce simp: equiv_valid_2_def)\n  done\n\nlemma gen_asm_ev2_l':\n  \"\\<lbrakk>P \\<Longrightarrow> equiv_valid_2 I A B R \\<top> P' f f'\\<rbrakk> \\<Longrightarrow>\n   equiv_valid_2 I A B R (\\<lambda>s. P) P' f f'\"\n  apply(fastforce simp: equiv_valid_2_def)\n  done\n\nlemma equiv_valid_rv_liftE_bindE:\n  assumes ev1:\n  \"equiv_valid_rv_inv I A W P f\"\n  assumes ev2:\n  \"\\<And> rv rv'. W rv rv' \\<Longrightarrow> equiv_valid_2 I A A R (Q rv) (Q rv') (g rv) (g rv')\"\n  assumes hoare:\n  \"\\<lbrace> P \\<rbrace> f \\<lbrace> Q \\<rbrace>\"\n  shows \"equiv_valid_rv_inv I A R P ((liftE f) >>=E g)\"\n  apply(unfold bindE_def)\n  apply(rule_tac Q=\"\\<lambda> rv. K (\\<forall> v. rv \\<noteq> Inl v) and (\\<lambda> s. \\<forall> v. rv = Inr v \\<longrightarrow> Q v s)\" in equiv_valid_rv_bind)\n    apply(rule_tac E=\"dc\" in equiv_valid_2_liftE)\n    apply(rule ev1)\n   apply(clarsimp simp: lift_def split: sum.split)\n   apply(insert ev2, fastforce simp: equiv_valid_2_def)[1]\n  apply(insert hoare, clarsimp simp: valid_def liftE_def bind_def return_def split_def)\n  done\n\nlemma if_evrv:\n  assumes \"b \\<Longrightarrow> equiv_valid_rv_inv I A R P f\"\n  assumes \"\\<not> b \\<Longrightarrow> equiv_valid_rv_inv I A R Q g\"\n  shows \"equiv_valid_rv_inv I A R (\\<lambda>s. (b \\<longrightarrow> P s) \\<and> (\\<not>b \\<longrightarrow> Q s)) (if b then f else g)\"\n  apply (clarsimp split: if_split)\n  using assms by blast\n\nend\n", "meta": {"author": "amblafont", "repo": "AutoCorres", "sha": "a8e96bff9fb22d633ff473401947ca84235d3b73", "save_path": "github-repos/isabelle/amblafont-AutoCorres", "path": "github-repos/isabelle/amblafont-AutoCorres/AutoCorres-a8e96bff9fb22d633ff473401947ca84235d3b73/lib/EquivValid.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5078118642792044, "lm_q2_score": 0.49609382947091957, "lm_q1q2_score": 0.2519223324010374}}
{"text": "theory InferComplete\n  imports InferRange AltLBoundLemma\nbegin\n\n    (* ##### defines specialization properties *)\n  \ndefinition spec_env :: \"nat res_env \\<Rightarrow> pt_env \\<Rightarrow> dir_type_subst \\<Rightarrow> bool\" where\n  \"spec_env env_v env t_subx = (\\<forall> x. case env_v x of\n    None \\<Rightarrow> env x = None\n    | Some a \\<Rightarrow> env x = t_subx a\n  )\"    \n  \nlemma self_spec_env: \"spec_env env_v (dir_subst_tenv t_sub env_v) t_sub\"  \n  apply (simp add: spec_env_def)\n  apply (auto)\n  apply (case_tac \"env_v x\")\n   apply (auto)\n   apply (simp add: dir_subst_tenv_def)\n  apply (simp add: dir_subst_tenv_def)\n  done\n  \nlemma eq_spec_env: \"\\<lbrakk> dir_subst_tenv t_sub env_v = dir_subst_tenv t_sub' env_v \\<rbrakk> \\<Longrightarrow> spec_env env_v (dir_subst_tenv t_sub env_v) t_sub'\"  \n  apply (simp)\n  apply (rule_tac self_spec_env)\n  done    \n    \n    (* #### fresh list lemmas *)\n\nlemma dom_list_set_contain: \"\\<lbrakk> x \\<in> dom_list_set l \\<rbrakk> \\<Longrightarrow> list_contain (dom_list l) x\"    \n  apply (induct l)\n   apply (auto)\n  done\n    \nlemma dom_list_set_use: \"\\<lbrakk> list_contain (dom_list l) x; dom_list_set l \\<subseteq> ds\\<rbrakk> \\<Longrightarrow> x \\<in> ds\"    \n  apply (induct l)\n   apply (auto)\n  done\n  \nlemma append_contain_dom_list: \"\\<lbrakk> list_contain (dom_list (l1 @ l2)) a \\<rbrakk> \\<Longrightarrow> list_contain (dom_list l1) a \\<or> list_contain (dom_list l2) a\"\n  apply (auto)\n  apply (induct l1)\n   apply (auto)\n  done\n\nlemma append_fresh_in_list: \"\\<lbrakk> fresh_in_list (dom_list l1); \\<forall>x. list_contain (dom_list l2) x \\<longrightarrow> \\<not> list_contain (dom_list l1) x;\n  fresh_in_list (dom_list l2) \\<rbrakk> \\<Longrightarrow> fresh_in_list (dom_list (l1 @ l2))\"\n  apply (induct l1)\n   apply (auto)\n  apply (cut_tac a=\"a\" and ?l1.0=\"l1\" and ?l2.0=\"l2\" in append_contain_dom_list)\n   apply (auto)\n  done\n  \nlemma append_fresh_list: \"\\<lbrakk> fresh_list ds (dom_list l1); tsub_dom (dir_list_add_env t_sub l1) ds';\n  fresh_list ds' (dom_list l2); ds \\<subseteq> ds' \\<rbrakk> \\<Longrightarrow> fresh_list ds (dom_list (l1 @ l2))\"\n  apply (simp add: fresh_list_def)\n  apply (auto)\n    (* first we prove that l1 @ l2 is fresh internally *)\n   apply (rule_tac append_fresh_in_list)\n     apply (auto)\n   apply (erule_tac x=\"x\" in allE)\n   apply (erule_tac x=\"x\" in allE)\n   apply (auto)\n   apply (cut_tac l=\"l1\" and ds=\"ds'\" in list_add_dls)\n    apply (auto)\n   apply (cut_tac x=\"x\" and ds=\"ds'\" and l=\"l1\" in dom_list_set_use)\n     apply (auto)\n    (* next we want to prove that if x is in l1 @ l2, x \\<notin> ds *)\n  apply (cut_tac ?l1.0=\"l1\" and ?l2.0=\"l2\" and a=\"x\" in append_contain_dom_list)\n   apply (auto)\n  done    \n    \nlemma add_list_contain: \"\\<lbrakk> list_contain (dom_list l) x \\<rbrakk> \\<Longrightarrow> dir_list_add_env t_sub l x \\<noteq> None\"\n  apply (induct l)\n   apply (auto)\n   apply (simp add: dir_add_env_def)\n  apply (simp add: dir_add_env_def)\n  done\n    \nlemma add_fresh_list: \"\\<lbrakk> fresh_list ds (dom_list l); tsub_dom (dir_list_add_env t_sub l) ds';\n  x \\<notin> ds'; ds \\<subseteq> ds' \\<rbrakk> \\<Longrightarrow> fresh_list ds (dom_list ((x, t) # l))\"    \n  apply (simp add: fresh_list_def)\n  apply (auto)\n  apply (simp add: tsub_dom_def)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (cut_tac t_sub=\"t_sub\" and l=\"l\" and x=\"x\" in add_list_contain)\n   apply (auto)\n  done\n    \nlemma append_fresh_list2: \"\\<lbrakk> fresh_list ds (dom_list l2); tsub_dom (dir_list_add_env t_sub l2) ds';\n  fresh_list ds' (dom_list l1); ds \\<subseteq> ds' \\<rbrakk> \\<Longrightarrow> fresh_list ds (dom_list (l1 @ l2))\"\n  apply (simp add: fresh_list_def)\n  apply (auto)\n    (* first we prove that l1 @ l2 is fresh internally *)\n   apply (rule_tac append_fresh_in_list)\n     apply (auto)\n   apply (erule_tac x=\"x\" in allE)\n   apply (erule_tac x=\"x\" in allE)\n   apply (auto)\n   apply (cut_tac l=\"l2\" and ds=\"ds'\" in list_add_dls)\n    apply (auto)\n   apply (cut_tac x=\"x\" and ds=\"ds'\" and l=\"l2\" in dom_list_set_use)\n     apply (auto)\n    (* next we want to prove that if x is in l1 @ l2, x \\<notin> ds *)\n  apply (cut_tac ?l1.0=\"l1\" and ?l2.0=\"l2\" and a=\"x\" in append_contain_dom_list)\n   apply (auto)\n  done          \n    \n    (* #### unsorted lemmas *)\n    \n    \nlemma add_subst_perm: \"\\<lbrakk> x \\<notin> pvar_set_perm p \\<rbrakk> \\<Longrightarrow> sol_subst_perm (add_use_env p_sub x r) p = sol_subst_perm p_sub p\"        \n  apply (case_tac p)\n    apply (auto)\n  apply (simp add: add_use_env_def)\n  done\n  \nlemma add_subst_permx: \"\\<lbrakk> x \\<notin> pvar_set px \\<rbrakk> \\<Longrightarrow> dir_subst_permx t_sub (add_use_env p_sub x r) px = dir_subst_permx t_sub p_sub px\"    \n  apply (induct px)\n     apply (auto)\n      apply (simp_all add: add_subst_perm)\n  done\n    \nlemma add_psub_leq_use_env: \"\\<lbrakk> pvar_range r_xv ds; x \\<notin> ds; leq_use_env (dir_subst_penv t_sub p_sub r_xv) r_s \\<rbrakk> \\<Longrightarrow>\n  leq_use_env (dir_subst_penv t_sub (add_use_env p_sub x r) r_xv) r_s\"\n  apply (simp add: leq_use_env_def)\n  apply (simp add: dir_subst_penv_def)\n  apply (auto)\n  apply (rule_tac t=\"dir_subst_permx t_sub (add_use_env p_sub x r) (r_xv xa)\"\n      and s=\"dir_subst_permx t_sub p_sub (r_xv xa)\" in subst)\n   apply (case_tac \"x \\<notin> pvar_set (r_xv xa)\")\n    apply (simp add: add_subst_permx)\n   apply (simp add: pvar_range_def)\n   apply (erule_tac x=\"xa\" in allE)\n   apply (auto)\n  done    \n    \nlemma add_psub_use_env: \"\\<lbrakk> pvar_range r_xv ds; x \\<notin> ds \\<rbrakk> \\<Longrightarrow>\n  dir_subst_penv t_sub (add_use_env p_sub x r) r_xv = dir_subst_penv t_sub p_sub r_xv\"    \n  apply (case_tac \"\\<forall> y. dir_subst_penv t_sub (add_use_env p_sub x r) r_xv y = dir_subst_penv t_sub p_sub r_xv y\")  \n   apply (auto)\n  apply (simp add: dir_subst_penv_def)\n  apply (cut_tac t_sub=\"t_sub\" and p_sub=\"p_sub\" and x=\"x\" and px=\"r_xv y\" and r=\"r\" in add_subst_permx)\n   apply (auto)\n  apply (simp add: pvar_range_def)\n  apply (erule_tac x=\"y\" in allE)\n  apply (auto)\n  done\n    \nlemma comp_subst_perm: \"\\<lbrakk> psub_dom p_sub2 ds'; pvar_set_perm p \\<subseteq> ds; ds \\<inter> ds' = {} \\<rbrakk> \\<Longrightarrow>\n  sol_subst_perm (comp_use_env p_sub1 p_sub2) p = sol_subst_perm p_sub1 p\"\n  apply (case_tac p)\n    apply (auto)\n  apply (simp add: comp_use_env_def)\n  apply (simp add: psub_dom_def)\n  apply (erule_tac x=\"x2\" in allE)\n  apply (auto)\n  apply (case_tac \"p_sub1 x2\")\n    apply (auto)\n  done\n\nlemma comp_subst_permx: \"\\<lbrakk> psub_dom p_sub2 ds'; pvar_set px \\<subseteq> ds; ds \\<inter> ds' = {} \\<rbrakk> \\<Longrightarrow>\n  dir_subst_permx t_sub (comp_use_env p_sub1 p_sub2) px = dir_subst_permx t_sub p_sub1 px\"    \n  apply (induct px)\n     apply (auto)\n    apply (simp add: comp_subst_perm)\n   apply (simp add: comp_subst_perm)\n  apply (simp add: comp_subst_perm)\n  done\n    \nlemma comp_psub_leq_use_env1: \"\\<lbrakk> psub_dom p_sub2 ds'; pvar_range r_xv ds; ds \\<inter> ds' = {};\n  leq_use_env (dir_subst_penv t_sub p_sub1 r_xv) r_s \\<rbrakk> \\<Longrightarrow>\n  leq_use_env (dir_subst_penv t_sub (comp_use_env p_sub1 p_sub2) r_xv) r_s\"\n  apply (simp add: leq_use_env_def)\n  apply (simp add: dir_subst_penv_def)\n  apply (auto)\n  apply (rule_tac t=\"dir_subst_permx t_sub (comp_use_env p_sub1 p_sub2) (r_xv x)\"\n      and s=\"dir_subst_permx t_sub p_sub1 (r_xv x)\" in subst)\n   apply (case_tac \"pvar_set (r_xv x) \\<subseteq> ds\")\n    apply (simp add: comp_subst_permx)\n   apply (simp add: pvar_range_def)\n  apply (auto)\n  done\n\nlemma comp_psub_use_env1: \"\\<lbrakk> psub_dom p_sub2 ds'; pvar_range r_xv ds; ds \\<inter> ds' = {} \\<rbrakk> \\<Longrightarrow>\n  dir_subst_penv t_sub (comp_use_env p_sub1 p_sub2) r_xv = dir_subst_penv t_sub p_sub1 r_xv\"    \n  apply (case_tac \"\\<forall> x. dir_subst_penv t_sub (comp_use_env p_sub1 p_sub2) r_xv x = dir_subst_penv t_sub p_sub1 r_xv x\")\n   apply (auto)\n  apply (simp add: dir_subst_penv_def)\n  apply (cut_tac t_sub=\"t_sub\" and ?p_sub1.0=\"p_sub1\" and ?p_sub2.0=\"p_sub2\" and ds=\"ds\" and ds'=\"ds'\" and px=\"r_xv x\" in comp_subst_permx)\n     apply (auto)\n  apply (simp add: pvar_range_def)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  done\n    \nlemma comp_psub_leq_use_env2: \"\\<lbrakk> psub_dom p_sub1 ds'; pvar_range r_xv ds; ds \\<inter> ds' = {};\n  leq_use_env (dir_subst_penv t_sub p_sub2 r_xv) r_s \\<rbrakk> \\<Longrightarrow>\n  leq_use_env (dir_subst_penv t_sub (comp_use_env p_sub1 p_sub2) r_xv) r_s\"\n  apply (cut_tac r_s=\"p_sub1\" and r_x=\"p_sub2\" in comm_comp_use_env)\n  apply (auto)\n  apply (rule_tac comp_psub_leq_use_env1)\n     apply (auto)\n  done\n   \nlemma comp_psub_use_env2: \"\\<lbrakk> psub_dom p_sub2 ds'; pvar_range r_xv ds; ds \\<inter> ds' = {} \\<rbrakk> \\<Longrightarrow>\n  dir_subst_penv t_sub (comp_use_env p_sub2 p_sub1) r_xv = dir_subst_penv t_sub p_sub1 r_xv\"        \n  apply (simp add: comm_comp_use_env)\n  apply (rule_tac comp_psub_use_env1)\n    apply (auto)\n  done\n    \nlemma diff_leq_use_env_rev: \"\\<lbrakk> leq_use_env (diff_use_env r_x r_ex) r_s; leq_use_env r_ex r_s \\<rbrakk> \\<Longrightarrow> leq_use_env r_x r_s\"\n  apply (simp add: leq_use_env_def)\n  apply (simp add: diff_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n   apply (case_tac \"r_s x\")\n     apply (auto)\n   apply (case_tac \"r_ex x\")\n     apply (auto)\n  apply (case_tac \"r_ex x\")\n    apply (auto)\n  done\n    \nlemma dist_union_use_leq: \"\\<lbrakk> leq_perm p r; leq_perm q r \\<rbrakk> \\<Longrightarrow> leq_perm (union_perm p q) r\"    \n  apply (case_tac r)\n    apply (auto)\n   apply (case_tac p)\n     apply (auto)\n   apply (case_tac q)\n     apply (auto)\n  apply (case_tac p)\n    apply (auto)\n   apply (case_tac q)\n     apply (auto)\n  apply (case_tac q)\n    apply (auto)\n  done\n  \nlemma union_use_leq1: \"\\<lbrakk> leq_perm p q \\<rbrakk> \\<Longrightarrow> leq_perm p (union_perm q r)\"    \n  apply (case_tac q)\n    apply (auto)\n   apply (case_tac r)\n     apply (auto)\n   apply (case_tac p)\n     apply (auto)\n  apply (case_tac r)\n    apply (auto)\n  done\n\nlemma union_use_leq2: \"\\<lbrakk> leq_perm p r \\<rbrakk> \\<Longrightarrow> leq_perm p (union_perm q r)\"    \n  apply (case_tac r)\n    apply (auto)\n    apply (case_tac q)\n      apply (auto)\n    apply (case_tac p)\n      apply (auto)\n   apply (case_tac q)\n     apply (auto)\n  apply (case_tac q)\n    apply (auto)\n  done\n    \nlemma dir_add_leq_permx: \"\\<lbrakk> t_sub x = None \\<rbrakk> \\<Longrightarrow> leq_perm (dir_subst_permx t_sub p_sub r) (dir_subst_permx (dir_add_env t_sub x tau) p_sub r)\"    \n  apply (induct r)\n      apply (auto)\n      apply (case_tac \"sol_subst_perm p_sub xa\")\n        apply (auto)\n     apply (simp add: dir_add_env_def)\n     apply (auto)\n     apply (case_tac \"t_sub xa\")\n      apply (auto)\n     apply (case_tac \"as_perm (req_type a)\")\n       apply (auto)\n    apply (rule_tac dist_union_use_leq)\n     apply (rule_tac union_use_leq1)\n     apply (auto)\n    apply (rule_tac union_use_leq2)\n    apply (auto)\n   apply (case_tac \"dir_subst_permx t_sub p_sub r\")\n     apply (auto)\n  apply (case_tac \"dir_subst_permx t_sub p_sub r1\")\n    apply (auto)\n  done\n  \nlemma dir_add_leq_use_env: \"\\<lbrakk> tsub_dom t_sub ds; x \\<notin> ds \\<rbrakk> \\<Longrightarrow> leq_use_env (dir_subst_penv t_sub p_sub r_sv) (dir_subst_penv (dir_add_env t_sub x tau) p_sub r_sv)\"\n  apply (simp add: leq_use_env_def)\n  apply (simp add: dir_subst_penv_def)\n  apply (auto)\n  apply (simp add: tsub_dom_def)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (rule_tac dir_add_leq_permx)\n  apply (simp)\n  done\n  \nlemma dom_list_contain: \"\\<lbrakk> x \\<in> dom_list_set l \\<rbrakk> \\<Longrightarrow> list_contain (dom_list l) x\"    \n  apply (induct l)\n   apply (auto)\n  done\n\nlemma dom_list_contain_rev: \"\\<lbrakk> list_contain (dom_list l) x \\<rbrakk> \\<Longrightarrow> x \\<in> dom_list_set l\"    \n  apply (induct l)\n   apply (auto)\n  done    \n    \nlemma dir_list_add_leq_use_env: \"\\<lbrakk> tsub_dom t_sub ds; fresh_list ds (dom_list l) \\<rbrakk> \\<Longrightarrow>\n  leq_use_env (dir_subst_penv t_sub p_sub r_sv) (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv)\"\n  apply (induct l)\n   apply (auto)\n   apply (rule_tac id_leq_use_env)\n  apply (rule_tac r_sb=\"dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv\" in trans_leq_use_env)\n   apply (rule_tac ds=\"ds \\<union> (dom_list_set l)\" in dir_add_leq_use_env)\n    apply (rule_tac ds=\"ds\" in list_add_tsub_dom)\n      apply (auto)\n    apply (simp add: fresh_list_def)\n    apply (auto)\n   apply (cut_tac x=\"a\" and l=\"l\" in dom_list_contain)\n    apply (simp)\n   apply (simp add: fresh_list_def)\n  apply (simp add: fresh_list_def)\n  done\n   \nlemma dir_list_append_eq_ih: \"dir_list_add_env t_sub (l @ la) a = dir_list_add_env (dir_list_add_env t_sub la) l a\"       \n  apply (induct l)\n   apply (auto)\n  apply (simp add: dir_add_env_def)\n  done\n    \nlemma dir_list_append_eq: \"dir_list_add_env t_sub (l @ la) = dir_list_add_env (dir_list_add_env t_sub la) l\"    \n  apply (case_tac \"\\<forall> a. dir_list_add_env t_sub (l @ la) a = dir_list_add_env (dir_list_add_env t_sub la) l a\")\n   apply (auto)\n  apply (simp add: dir_list_append_eq_ih)\n  done\n    \nlemma ifz_sol_subst_penv: \"\\<lbrakk> p_sub p = NoPerm \\<rbrakk> \\<Longrightarrow> dir_subst_penv t_sub p_sub (ifz_var_env (XPerm (SVar p)) r_sv) = empty_use_env\"    \n  apply (case_tac \"\\<forall> x. dir_subst_penv t_sub p_sub (ifz_var_env (XPerm (SVar p)) r_sv) x = empty_use_env x\")   \n   apply (auto)\n  apply (simp add: dir_subst_penv_def)\n  apply (simp add: ifz_var_env_def)\n  apply (simp add: empty_use_env_def)\n  apply (case_tac \"r_sv x = XPerm (SPerm NoPerm)\")\n   apply (auto)\n  done        \n    \n    (* #### pvar / tvar lemmas *)\n    \nfun pvar_aff where\n  \"pvar_aff (AffConst a) = {}\"\n| \"pvar_aff (AffVar v) = {v}\"    \n  \nfun pvar_type where\n  \"pvar_type IntScheme = {}\"\n  | \"pvar_type BoolScheme = {}\"\n  | \"pvar_type UnitScheme = {}\"\n  | \"pvar_type (VarScheme v) = {}\" \n  | \"pvar_type (ArrayScheme tau) = pvar_type tau\"\n  | \"pvar_type (PairScheme t1 t2 p) = pvar_type t1 \\<union> pvar_type t2 \\<union> pvar_set_perm p\"\n  | \"pvar_type (FunScheme t1 t2 p a) = pvar_type t1 \\<union> pvar_type t2 \\<union> pvar_set_perm p \\<union> pvar_aff a\"\n  | \"pvar_type (ChanScheme tau c_end) = pvar_type tau\"   \n    \nlemma comp_subst_aff: \"\\<lbrakk> psub_dom p_subx ds; pvar_aff a \\<inter> ds = {} \\<rbrakk> \\<Longrightarrow>\n  sol_subst_aff p_sub a = sol_subst_aff (comp_use_env p_sub p_subx) a\"    \n  apply (case_tac a)\n   apply (auto)\n  apply (simp add: psub_dom_def)\n  apply (simp add: comp_use_env_def)\n  apply (erule_tac x=\"x2\" in allE)\n  apply (auto)\n  apply (case_tac \"p_sub x2\")\n    apply (auto)\n  done\n    \nlemma comp_dir_subst_type1: \"\\<lbrakk> dir_subst_type t_sub p_sub tau_v tau;\n  pvar_type tau_v \\<subseteq> ds; psub_dom p_subx ds'; ds \\<inter> ds' = {} \\<rbrakk> \\<Longrightarrow>\n  dir_subst_type t_sub (comp_use_env p_sub p_subx) tau_v tau\"    \n  apply (induct tau_v arbitrary: tau)\n         apply (auto)\n    apply (simp add: comp_subst_perm)\n   apply (simp add: comp_subst_perm)\n  apply (rule_tac comp_subst_aff)\n   apply (auto)\n  done\n\nlemma comp_dir_subst_type2: \"\\<lbrakk> dir_subst_type t_sub p_subx tau_v tau;\n  pvar_type tau_v \\<subseteq> ds; psub_dom p_sub ds'; ds \\<inter> ds' = {} \\<rbrakk> \\<Longrightarrow>\n  dir_subst_type t_sub (comp_use_env p_sub p_subx) tau_v tau\"    \n  apply (cut_tac r_s=\"p_sub\" and r_x=\"p_subx\" in comm_comp_use_env)\n  apply (auto)\n  apply (rule_tac comp_dir_subst_type1)\n     apply (auto)\n  done\n    \nlemma add_subst_aff: \"\\<lbrakk> p \\<notin> pvar_aff a \\<rbrakk> \\<Longrightarrow>\n  sol_subst_aff p_sub a = sol_subst_aff (add_use_env p_sub p r) a\"    \n  apply (case_tac a)\n   apply (auto)\n  apply (simp add: add_use_env_def)\n  done\n    \nlemma add_dir_subst_type: \"\\<lbrakk> dir_subst_type t_sub p_sub tau_v tau; p \\<notin> pvar_type tau_v \\<rbrakk> \\<Longrightarrow>\n  dir_subst_type t_sub (add_use_env p_sub p r) tau_v tau\"\n  apply (induct tau_v arbitrary: tau)\n         apply (auto)\n    apply (simp add: add_subst_perm)\n   apply (simp add: add_subst_perm)\n  apply (rule_tac add_subst_aff)\n  apply (auto)\n  done\n    \nlemma dir_add_subst_permx: \"\\<lbrakk> x \\<notin> tvar_set px \\<rbrakk> \\<Longrightarrow>\n  dir_subst_permx (dir_add_env t_sub x tau) p_sub px = dir_subst_permx t_sub p_sub px\"\n  apply (induct px)\n      apply (auto)\n  apply (simp add: dir_add_env_def)\n  done    \n    \nlemma dir_add_subst_type: \"\\<lbrakk> dir_subst_type t_sub p_sub tau_v tau; x \\<notin> tvar_type tau_v \\<rbrakk> \\<Longrightarrow>\n  dir_subst_type (dir_add_env t_sub x t) p_sub tau_v tau\"\n  apply (induct tau_v arbitrary: tau)\n    apply (auto)\n  apply (simp add: dir_add_env_def)\n  done\n    \nlemma dir_list_add_subst_type: \"\\<lbrakk> dir_subst_type t_sub p_sub tau_v tau; tvar_type tau_v \\<inter> dom_list_set l = {} \\<rbrakk> \\<Longrightarrow>\n  dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau\"\n  apply (induct l arbitrary: tau_v tau)\n   apply (auto)\n  apply (rule_tac dir_add_subst_type)\n    apply (auto)\n  done\n    \nlemma infer_tvar_type: \"\\<lbrakk> infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; sub_range env_v ds \\<rbrakk> \\<Longrightarrow> tvar_type tau_v \\<subseteq> ds'\"    \n  apply (induct e arbitrary: env_v ds tau_v r_sv r_xv r_mv c_list ds')\n        apply (auto)\n    (* const + op case *)\n         apply (case_tac x)\n                     apply (auto)\n                apply (simp_all add: pure_fun_s_def)\n        apply (case_tac x)\n             apply (auto)\n             apply (simp_all add: pure_fun_s_def)\n    (* var case *)\n       apply (simp add: sub_range_def)\n       apply (erule_tac x=\"res_name x\" in allE)\n       apply (auto)\n    (* pair case *)    \n      apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n       apply (simp)\n      apply (cut_tac c=\"x\" and A=\"tvar_type t1\" and B=\"ds2\" in contra_subsetD)\n        apply (auto)\n     apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n       apply (simp)\n      apply (rule_tac infer_x_subset)\n      apply (auto)\n     apply (cut_tac c=\"x\" and A=\"tvar_type t2\" and B=\"ds3\" in contra_subsetD)\n       apply (auto)\n    (* if case *)\n    apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n     apply (simp)\n    apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n      apply (simp)\n     apply (rule_tac infer_x_subset)\n     apply (auto)\n    apply (case_tac \"x \\<in> ds'\")\n     apply (auto)\n    apply (cut_tac c=\"x\" and A=\"tvar_type t2\" and B=\"ds3\" in contra_subsetD)\n      apply (auto)\n    (* lam case *)\n   apply (cut_tac ds=\"insert a ds\" and ds'=\"ds2\" in infer_x_subset)\n    apply (auto)\n  apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and x=\"Var x1a\" and a=\"a\" in add_sub_range)\n   apply (auto)\n  apply (cut_tac c=\"x\" and A=\"tvar_type t2\" and B=\"ds2\" in contra_subsetD)\n    apply (auto)\n  done\n    \nlemma ipvt_const: \"\\<lbrakk>sub_range env_v ds; xa \\<in> pvar_type tau_v; const_scheme x ds tau_v c_list ds'\\<rbrakk> \\<Longrightarrow> xa \\<in> set_diff ds' ds\"   \n  apply (case_tac x)\n              apply (auto)\n               apply (simp_all add: pure_fun_s_def)\n        apply (simp_all add: set_diff_def)\n       apply (simp_all add: fresh_list_def)\n  apply (auto)\n  done\n    \nlemma infer_pvar_type: \"\\<lbrakk> infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; sub_range env_v ds \\<rbrakk> \\<Longrightarrow> pvar_type tau_v \\<subseteq> set_diff ds' ds\"    \n  apply (induct e arbitrary: env_v ds tau_v r_sv r_xv r_mv c_list ds')\n        apply (auto)\n    (* const + op case *)\n          apply (rule_tac ipvt_const)\n            apply (auto)\n         apply (case_tac x)\n              apply (auto)\n              apply (simp_all add: pure_fun_s_def)\n    (* pair case p1. *)\n        apply (simp add: set_diff_def)\n        apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n         apply (simp)\n        apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n         apply (auto)\n       apply (case_tac \"\\<not> pvar_type t1 \\<subseteq> ds2 - ds\")\n        apply (simp add: set_diff_def)\n       apply (auto)\n       apply (case_tac \"x \\<notin> ds2\")\n        apply (auto)\n       apply (case_tac \"x \\<in> ds\")\n        apply (auto)\n       apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n        apply (auto)\n       apply (simp add: set_diff_def)\n       apply (auto)\n    (* pair case p2. *)\n      apply (case_tac \"\\<not> pvar_type t2 \\<subseteq> ds3 - ds2\")\n       apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n         apply (simp)\n        apply (rule_tac infer_x_subset)\n        apply (simp)\n       apply (simp add: set_diff_def)\n      apply (auto)\n      apply (case_tac \"x \\<notin> ds3\")\n       apply (auto)\n      apply (case_tac \"x \\<in> ds2\")\n       apply (auto)\n      apply (simp add: set_diff_def)\n      apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n       apply (auto)\n    (* if case *)\n     apply (case_tac \"\\<not> pvar_type t2 \\<subseteq> ds3 - ds2\")\n      apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n        apply (simp)\n       apply (rule_tac infer_x_subset)\n       apply (simp)\n      apply (simp add: set_diff_def)\n     apply (case_tac \"x \\<notin> ds3\")\n      apply (auto)\n     apply (case_tac \"x \\<in> ds2\")\n      apply (auto)\n     apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n      apply (auto)\n     apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n      apply (auto)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    (* lam case *)\n    apply (cut_tac ds=\"insert a ds\" and ds'=\"ds2\" in infer_x_subset)\n     apply (simp)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (case_tac \"\\<not> pvar_type t2 \\<subseteq> ds2 - (insert a ds)\")\n    apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and x=\"Var x1a\" and a=\"a\" in add_sub_range)\n     apply (simp)\n    apply (simp add: set_diff_def)\n   apply (case_tac \"p \\<notin> ds2\")\n    apply (auto)\n   apply (case_tac \"a \\<in> insert a ds\")\n    apply (auto)\n   apply (simp add: set_diff_def)\n   apply (auto)\n   apply (cut_tac ds=\"insert a ds\" and ds'=\"ds2\" in infer_x_subset)\n    apply (auto)(*\n  apply (cut_tac env_v=\"add_env env_v (Var x1a) a\" and r_sv=\"r_s'\" and ds'=\"ds2\" in infer_s_sub_range)\n   apply (auto)*)\n  apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and x=\"Var x1a\" and a=\"a\" in add_sub_range)\n   apply (auto)\n  apply (cut_tac ds=\"insert a ds\" and ds'=\"ds2\" in infer_x_subset)\n   apply (auto)\n  apply (simp add: set_diff_def)\n  apply (auto)\n   apply (cut_tac c=\"x\" and A=\"pvar_type t2\" and B=\"ds2 - (insert a ds)\" in contra_subsetD)\n     apply (auto)\n  apply (cut_tac c=\"x\" and A=\"pvar_type t2\" and B=\"ds2 - (insert a ds)\" in contra_subsetD)\n    apply (auto)\n  done        \n    \n    (* #### auxiliary lemmas *)\n    \n    (* \n      when we call \"infer\" on an expression, we receive a constraint set representing the set of all possible solutions for well-typedness.\n\n      suppose that an expression is well-typed, and we have a partial solution to the constraint set, solving all permission based constraints,\n        reducing all constraints to just type-based constraints.\n\n      Gamma, P1 |- e: tau, P2, Q \\<and> Infer(Gamma*, X, e) = (tau*, P*, Q*, R*, K, X') \\<and>\n        \\<rho>( P* ) \\<le> P1 \\<and> \\<rho>( tau* ) \\<le> tau \\<and> Gamma* \\<le> Gamma \\<Longrightarrow>\n        (\\<exists> \\<sigma>. \\<sigma> |= \\<rho>(K) \\<and> \\<sigma>( Gamma* ) = Gamma \\<and> \\<sigma>(\\<rho>( tau* )) = tau)\n\n\n      Gamma, P1 |- e: tau, P2, Q \\<and> Infer(Gamma*, X, e) = (tau*, P*, Q*, R*, K, X') \n        Gamma* \\<le> Gamma \\<Longrightarrow>\n        (\\<exists> \\<sigma>. \\<sigma> |~ K \\<and> \\<sigma>( Gamma* ) = Gamma \\<and> \\<sigma>( tau* ) = tau) \n    *)\n\nlemma dir_subst_spec_env_ex: \"\\<lbrakk> spec_env env_v env t_subx \\<rbrakk> \\<Longrightarrow> dir_subst_tenv t_subx env_v = env\"\n  apply (case_tac \"\\<forall> x. dir_subst_tenv t_subx env_v x = env x\")\n   apply (auto)\n  apply (simp add: dir_subst_tenv_def)\n  apply (simp add: spec_env_def)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"env_v x\")\n   apply (auto)\n  done    \n    \nlemma dir_subst_spec_env: \"\\<lbrakk> spec_env env_v env t_subx \\<rbrakk> \\<Longrightarrow> \\<exists>t_sub. dir_subst_tenv t_sub env_v = env\"  \n  apply (rule_tac x=\"t_subx\" in exI)\n  apply (rule_tac dir_subst_spec_env_ex)\n  apply (simp)\n  done\n  \nlemma ivrcc_prim_case: \"\\<lbrakk> spec_env env_v env t_sub; tsub_dom t_sub ds \\<rbrakk> \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds \\<and>\n            fresh_list ds (dom_list l) \\<and> dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and> (\\<exists>p_sub. psub_dom p_sub {})\"    \n  apply (rule_tac x=\"[]\" in exI)\n  apply (auto)\n    apply (simp add: fresh_list_def)\n   apply (rule_tac dir_subst_spec_env_ex)\n   apply (simp)\n  apply (rule_tac x=\"empty_use_env\" in exI)\n  apply (simp add: psub_dom_def)\n  apply (simp add: empty_use_env_def)\n  done\n       \nlemma ivrcc_array_case: \"\\<lbrakk> spec_env env_v env t_sub; sub_range env_v ds; tsub_dom t_sub ds;\n    ta \\<notin> ds; req_type t \\<noteq> Aff \\<rbrakk> \\<Longrightarrow>\n    \\<exists>l. tsub_dom (dir_list_add_env t_sub l) (insert ta ds) \\<and>\n        fresh_list ds (dom_list l) \\<and>\n        dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n        (\\<exists>p_sub. psub_dom p_sub (insert ta ds - ds)) \\<and>\n        dir_list_add_env t_sub l ta = Some t \\<and> (\\<exists>tau_x. dir_list_add_env t_sub l ta = Some tau_x \\<and> aff_leq (req_type tau_x) UsePerm)\"  \n  apply (rule_tac x=\"[(ta, t)]\" in exI)\n  apply (auto)\n       apply (rule_tac add_tsub_dom)\n        apply (rule_tac ds=\"ds\" in subset_tsub_dom)\n         apply (auto)\n      apply (simp add: fresh_list_def)\n     apply (rule_tac ds=\"ds\" in dir_add_eq_env)\n       apply (rule_tac dir_subst_spec_env_ex)\n       apply (auto)\n    apply (rule_tac x=\"empty_use_env\" in exI)\n    apply (rule_tac empty_psub_dom)\n   apply (simp add: dir_add_env_def)\n  apply (rule_tac x=\"t\" in exI)\n  apply (simp add: dir_add_env_def)\n  apply (case_tac \"req_type t\")\n    apply (auto)  \n  done\n    \nlemma ivrcc_chan_case: \"\\<lbrakk> spec_env env_v env t_sub; sub_range env_v ds; tsub_dom t_sub ds; ta \\<notin> ds \\<rbrakk> \\<Longrightarrow>\n  \\<exists>l. tsub_dom (dir_list_add_env t_sub l) (insert ta ds) \\<and>\n                    fresh_list ds (dom_list l) \\<and>\n                    dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and> (\\<exists>p_sub. psub_dom p_sub (insert ta ds - ds)) \\<and> dir_list_add_env t_sub l ta = Some t\"    \n  apply (rule_tac x=\"[(ta, t)]\" in exI)\n  apply (auto)\n      apply (rule_tac add_tsub_dom)\n       apply (rule_tac ds=\"ds\" in subset_tsub_dom)\n        apply (auto)\n     apply (simp add: fresh_list_def)\n    apply (rule_tac dir_add_eq_env)\n      apply (rule_tac dir_subst_spec_env_ex)\n      apply (auto)\n   apply (rule_tac x=\"empty_use_env\" in exI)\n   apply (rule_tac empty_psub_dom)\n  apply (simp add: dir_add_env_def)\n  done\n\nlemma empty_cut_use_env: \"cut_use_env empty_use_env = empty_use_env\"    \n  apply (case_tac \"\\<forall> x. cut_use_env empty_use_env x = empty_use_env x\")\n   apply (auto)\n  apply (simp add: cut_use_env_def)\n  apply (simp add: empty_use_env_def)\n  done\n      \nlemma ivr_const_case: \"\\<lbrakk>spec_env env_v env t_sub; sub_range env_v ds; tsub_dom t_sub ds; tau \\<in> const_type x; const_scheme x ds tau_v c_list ds';\n        leq_use_env (diff_use_env r_s r_ex) r_s; leq_use_env r_x (diff_use_env r_s r_ex)\\<rbrakk>\n       \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \\<and>\n               fresh_list ds (dom_list l) \\<and>\n               dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n               (\\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \\<and>\n                        leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub empty_var_env) r_s \\<and>\n                        leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub empty_var_env) r_ex) r_x \\<and>\n                        leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub empty_var_env)) r_ex \\<and>\n                        dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \\<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list)\"  \n  apply (simp add: empty_leq_var_env)\n  apply (simp add: subst_empty_var_env)\n  apply (simp add: diff_empty_use_env1)\n  apply (simp add: empty_cut_use_env)\n  apply (simp add: leq_empty_use_env)\n  apply (case_tac x)\n              apply (auto)\n              apply (simp_all add: pure_fun_def)\n              apply (simp_all add: pure_fun_s_def)\n              apply (simp_all add: unlim_def)\n              apply (simp_all add: set_diff_def)\n    (* basic cases *)\n              apply (rule_tac ivrcc_prim_case)\n               apply (auto)\n             apply (rule_tac ivrcc_prim_case)\n              apply (auto)\n            apply (rule_tac ivrcc_prim_case)\n             apply (auto)\n    (* fixed point *)\n           apply (case_tac t)\n                 apply (auto)\n           apply (rule_tac x=\"[(t2, x62), (t1, x61)]\" in exI)\n           apply (auto)\n              apply (rule_tac add_tsub_dom)\n               apply (rule_tac add_tsub_dom)\n                apply (rule_tac ds=\"ds\" in subset_tsub_dom)\n                 apply (auto)\n             apply (simp add: fresh_list_def)\n            apply (rule_tac ds=\"ds\" in dir_add_eq_env)\n              apply (rule_tac ds=\"ds\" in dir_add_eq_env)\n                apply (rule_tac dir_subst_spec_env_ex)\n                apply (auto)\n             apply (simp add: fresh_list_def)\n             apply (auto)\n            apply (simp add: fresh_list_def)\n            apply (auto)\n           apply (simp add: dir_add_env_def)\n           apply (auto)\n            apply (simp add: fresh_list_def)\n           apply (rule_tac x=\"add_use_env (add_use_env empty_use_env p x63) q (as_perm x64)\" in exI)\n           apply (auto)\n                apply (rule_tac add_psub_dom)\n                 apply (rule_tac add_psub_dom)\n                  apply (rule_tac empty_psub_dom)\n                 apply (auto)\n                 apply (simp add: fresh_list_def)\n                 apply (auto)\n                apply (simp add: fresh_list_def)\n                apply (auto)\n               apply (simp add: add_use_env_def)\n               apply (simp add: fresh_list_def)\n              apply (simp add: add_use_env_def)\n              apply (simp add: trip_convert)\n             apply (simp add: fresh_list_def)\n             apply (simp add: add_use_env_def)\n            apply (simp add: fresh_list_def)\n            apply (simp add: add_use_env_def)\n            apply (simp add: trip_convert)\n           apply (simp add: add_use_env_def)\n           apply (case_tac x64)\n             apply (auto)\n    (* array cases *)\n          apply (rule_tac ivrcc_array_case)\n              apply (auto)\n         apply (rule_tac ivrcc_array_case)\n             apply (auto)\n        apply (rule_tac ivrcc_array_case)\n            apply (auto)\n       apply (rule_tac ivrcc_array_case)\n           apply (auto)\n    (* unpack *)\n      apply (rule_tac x=\"[(t1a, t1), (t2a, t2), (txa, tx)]\" in exI)\n      apply (auto)\n         apply (rule_tac add_tsub_dom)\n          apply (rule_tac add_tsub_dom)\n           apply (rule_tac add_tsub_dom)\n            apply (rule_tac ds=\"ds\" in subset_tsub_dom)\n             apply (auto)\n        apply (simp add: fresh_list_def)\n       apply (rule_tac ds=\"ds\" in dir_add_eq_env)\n         apply (rule_tac ds=\"ds\" in dir_add_eq_env)\n           apply (rule_tac ds=\"ds\" in dir_add_eq_env)\n             apply (rule_tac dir_subst_spec_env_ex)\n             apply (auto)\n         apply (simp add: fresh_list_def)\n         apply (auto)\n        apply (simp add: fresh_list_def)\n        apply (auto)\n       apply (simp add: fresh_list_def)\n       apply (auto)\n      apply (rule_tac x=\"add_use_env (add_use_env empty_use_env p r) p' r'\" in exI)\n      apply (auto)\n                     apply (rule_tac add_psub_dom)\n                      apply (rule_tac add_psub_dom)\n                      apply (rule_tac empty_psub_dom)\n                      apply (auto)\n                      apply (simp add: fresh_list_def)\n                      apply (auto)\n                     apply (simp add: fresh_list_def)\n                     apply (auto)\n                    apply (simp add: dir_add_env_def)\n                   apply (simp add: dir_add_env_def)\n                   apply (simp add: fresh_list_def)\n                   apply (auto)\n                  apply (simp add: add_use_env_def)\n                  apply (simp add: fresh_list_def)\n                  apply (auto)\n                 apply (simp add: dir_add_env_def)\n                apply (simp add: dir_add_env_def)\n                apply (simp add: fresh_list_def)\n                apply (auto)\n               apply (simp add: dir_add_env_def)\n               apply (simp add: fresh_list_def)\n               apply (auto)\n              apply (simp add: add_use_env_def)\n              apply (simp add: fresh_list_def)\n              apply (auto)\n             apply (simp add: add_use_env_def)\n            apply (simp add: add_use_env_def)\n            apply (simp add: fresh_list_def)\n            apply (auto)\n           apply (simp add: add_use_env_def)\n          apply (simp add: dir_add_env_def)\n          apply (simp add: fresh_list_def)\n          apply (auto)\n         apply (simp add: add_use_env_def)\n        apply (simp add: add_use_env_def)\n        apply (simp add: fresh_list_def)\n        apply (auto)\n       apply (simp add: add_use_env_def)\n       apply (simp add: fresh_list_def)\n       apply (auto)\n      apply (simp add: add_use_env_def)\n      apply (simp add: fresh_list_def)\n      apply (auto)\n    (* simp chan cases *)\n     apply (simp_all add: is_own_def)\n     apply (rule_tac ivrcc_chan_case)\n        apply (auto)\n    apply (rule_tac ivrcc_chan_case)\n       apply (auto)\n   apply (rule_tac ivrcc_chan_case)\n      apply (auto)\n    (* fork *)\n  apply (rule_tac x=\"[]\" in exI)\n  apply (auto)\n     apply (rule_tac ds=\"ds\" in subset_tsub_dom)\n      apply (auto)\n    apply (simp add: fresh_list_def)\n   apply (rule_tac dir_subst_spec_env_ex)\n   apply (auto)\n  apply (rule_tac x=\"add_use_env empty_use_env p (as_perm a)\" in exI)\n  apply (auto)\n   apply (rule_tac add_psub_dom)\n    apply (rule_tac empty_psub_dom)\n   apply (auto)\n  apply (simp add: add_use_env_def)\n  apply (simp add: trip_convert)\n  done\n\nlemma ivr_op_case: \"\\<lbrakk>spec_env env_v env t_sub; sub_range env_v ds'; tsub_dom t_sub ds'; leq_use_env (diff_use_env r_s r_ex) r_s; leq_use_env r_x (diff_use_env r_s r_ex)\\<rbrakk>\n       \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \\<and>\n               fresh_list ds' (dom_list l) \\<and>\n               dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n               (\\<exists>p_sub. psub_dom p_sub (set_diff ds' ds') \\<and>\n                        leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub empty_var_env) r_s \\<and>\n                        leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub empty_var_env) r_ex) r_x \\<and>\n                        leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub empty_var_env)) r_ex \\<and>\n                        dir_subst_type (dir_list_add_env t_sub l) p_sub (op_scheme x) (op_type x))\"\n  apply (rule_tac x=\"[]\" in exI)\n  apply (auto)\n    apply (simp add: fresh_list_def)\n   apply (rule_tac dir_subst_spec_env_ex)\n   apply (simp)\n  apply (rule_tac x=\"empty_use_env\" in exI)\n  apply (simp add: empty_psub_dom)\n  apply (simp add: empty_leq_var_env)\n  apply (simp add: subst_empty_var_env)\n  apply (simp add: diff_empty_use_env1)\n  apply (simp add: empty_cut_use_env)\n  apply (simp add: leq_empty_use_env)\n  apply (case_tac x)\n       apply (auto)\n       apply (simp_all add: pure_fun_def)\n       apply (simp_all add: pure_fun_s_def)\n  done\n\n    (* \n      we want to show that if we subtract EX from our constructed requirements - constructed subtractant,\n          we will end up with a result contained in Q. (that our total construction is minimal).\n        `(X - M) - EX \\<le> Q`\n\n      by induction, our constructed reqs should be less than the real reqs. the key then is to make\n        sure that we are subtracting our \"enough\". both the real subtractant + the artificial subtractant.\n        we can know that we are since EX subtracts more than both of these.\n          (X - M) \\<le> rx  \\<and>  rx - EX' \\<le> Q \\<le> P1 - EX' \\<le> P1 - EX\n    *)\n    \nlemma squish_leq_use_env: \"\\<lbrakk> leq_use_env (diff_use_env r_s r_ex') (diff_use_env r_c r_ex);\n  leq_use_env (diff_use_env r_c r_ex) (diff_use_env r_c r_ex'); leq_use_env r_x r_s; leq_use_env r_s r_c \\<rbrakk> \\<Longrightarrow>\n  leq_use_env (diff_use_env r_x r_ex) (diff_use_env r_s r_ex')\"    \n  apply (simp add: leq_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (simp add: diff_use_env_def)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n    apply (case_tac \"r_ex x\")\n      apply (auto)\n   apply (case_tac \"r_ex x\")\n     apply (auto)\n    apply (case_tac \"r_ex' x\")\n      apply (auto)\n    apply (case_tac \"r_c x\")\n      apply (auto)\n    apply (case_tac \"r_s x\")\n      apply (auto)\n   apply (case_tac \"r_ex' x\")\n     apply (auto)\n   apply (case_tac \"r_c x\")\n     apply (auto)\n   apply (case_tac \"r_s x\")\n     apply (auto)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n  apply (case_tac \"r_c x\")\n    apply (auto)\n  done\n    \nlemma crush_leq_use_env: \"\\<lbrakk> leq_use_env (diff_use_env r_s r_ex) (diff_use_env r_s r_ex'); leq_use_env r_xa r_s;\n  leq_use_env (diff_use_env r_xb r_ex) r_xa \\<rbrakk> \\<Longrightarrow>\n  leq_use_env (diff_use_env r_xb r_ex) (diff_use_env r_xa r_ex')\"\n  apply (simp add: leq_use_env_def)\n  apply (simp add: diff_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_ex x\")\n    apply (auto)\n   apply (case_tac \"r_ex' x\")\n     apply (auto)\n   apply (case_tac \"r_s x\")\n     apply (auto)\n   apply (case_tac \"r_xa x\")\n     apply (auto)\n  apply (case_tac \"r_ex' x\")\n    apply (auto)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n  apply (case_tac \"r_xa x\")\n    apply (auto)\n  done\n\nlemma dist_diff_leq_use_env_rev: \"\\<lbrakk> leq_use_env r_exa r_s; leq_use_env (diff_use_env r_s r_exb) (diff_use_env r_s r_exa) \\<rbrakk> \\<Longrightarrow>\n  leq_use_env (cut_use_env r_exa) r_exb\"\n  apply (simp add: leq_use_env_def)\n  apply (simp add: diff_use_env_def)\n  apply (simp add: cut_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_exa x\")\n    apply (auto)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n  apply (case_tac \"r_exb x\")\n    apply (auto)\n  done\n    \nlemma ivrvc_ineq: \"\\<lbrakk> t_sub b = Some tau_x \\<rbrakk> \\<Longrightarrow>\n  leq_use_env (dir_subst_penv t_sub p_sub (one_var_env (owner_name x) (XType b))) (ereq_use_env (owner_name x) tau_x)\"   \n  apply (simp add: leq_use_env_def)\n  apply (simp add: dir_subst_penv_def)\n  apply (simp add: one_var_env_def)\n  apply (simp add: ereq_use_env_def)\n  apply (simp add: one_use_env_def)\n  apply (simp add: end_req_perm_def)\n  apply (case_tac \"req_type tau_x\")\n    apply (auto)\n  done\n    \nlemma dist_cut_leq_use_env: \"\\<lbrakk> leq_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> leq_use_env (cut_use_env r_x) (cut_use_env r_s)\"    \n  apply (simp add: leq_use_env_def)\n  apply (simp add: cut_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n  done\n    \nlemma rhs_cut_leq_use_env: \"\\<lbrakk> leq_use_env (cut_use_env r_x) r_s \\<rbrakk> \\<Longrightarrow> leq_use_env (cut_use_env r_x) (cut_use_env r_s)\"        \n  apply (simp add: leq_use_env_def)\n  apply (simp add: cut_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n  done\n    \nlemma dist_cut_comp_use_env: \"cut_use_env (comp_use_env r_s r_x) = comp_use_env (cut_use_env r_s) (cut_use_env r_x)\"    \n  apply (case_tac \"\\<forall> x. cut_use_env (comp_use_env r_s r_x) x = comp_use_env (cut_use_env r_s) (cut_use_env r_x) x\")  \n   apply (auto)\n  apply (simp add: cut_use_env_def)\n  apply (simp add: comp_use_env_def)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n    apply (simp_all add: comp_use_env_def)\n   apply (case_tac \"r_x x\")\n     apply (auto)\n    apply (simp_all add: comp_use_env_def)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n  apply (simp add: comp_use_env_def)\n  done\n  \nlemma lhs_dist_cut_leq_use_env: \"\\<lbrakk> leq_use_env (comp_use_env (cut_use_env r_s) (cut_use_env r_x)) r_c \\<rbrakk> \\<Longrightarrow>\n  leq_use_env (cut_use_env (comp_use_env r_s r_x)) r_c\"    \n  apply (simp add: dist_cut_comp_use_env)\n  done\n  \nlemma ivr_var_case: \"\\<lbrakk>spec_env env_v env t_sub; sub_range env_v ds; tsub_dom t_sub ds; env (res_name x) = Some tau; env_v (res_name x) = Some a;\n        env (owner_name x) = Some tau_x; value_req x tau tau_x; env_v (owner_name x) = Some b; leq_use_env (ereq_use_env (owner_name x) tau_x) r_s;\n        leq_use_env (diff_use_env r_s r_ex) (diff_use_env r_s (comp_use_env (ereq_use_env (owner_name x) tau_x) r_exa)); leq_use_env r_x (diff_use_env r_s r_ex);\n        leq_use_env r_exa r_s; leq_use_env (diff_use_env (ereq_use_env (owner_name x) tau_x) (comp_use_env (ereq_use_env (owner_name x) tau_x) r_exa)) r_x\\<rbrakk>\n       \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds \\<and>\n               fresh_list ds (dom_list l) \\<and>\n               dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n               (\\<exists>p_sub. psub_dom p_sub (set_diff ds ds) \\<and>\n                        leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (one_var_env (owner_name x) (XType b))) r_s \\<and>\n                        leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (one_var_env (owner_name x) (XType b))) r_ex) r_x \\<and>\n                        leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (one_var_env (owner_name x) (XType b)))) r_ex \\<and>\n                        dir_list_add_env t_sub l a = Some tau \\<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub (var_val_crn x (VarScheme a) (VarScheme b)))\"    \n  apply (rule_tac x=\"[]\" in exI)\n  apply (auto)\n    apply (simp add: fresh_list_def)\n   apply (rule_tac dir_subst_spec_env_ex)\n   apply (simp)\n  apply (case_tac \"t_sub a \\<noteq> Some tau\")\n   apply (simp add: spec_env_def)\n   apply (erule_tac x=\"res_name x\" in allE)\n   apply (case_tac \"env_v (res_name x)\")\n    apply (auto)\n  apply (case_tac \"t_sub b \\<noteq> Some tau_x\")\n   apply (simp add: spec_env_def)\n   apply (erule_tac x=\"owner_name x\" in allE)\n   apply (case_tac \"env_v (owner_name x)\")\n    apply (auto)\n  apply (cut_tac t_sub=\"t_sub\" and x=\"x\" and b=\"b\" and tau_x=\"tau_x\" in ivrvc_ineq)\n   apply (auto)\n  apply (rule_tac x=\"empty_use_env\" in exI)\n  apply (auto)\n      apply (rule_tac empty_psub_dom)\n     apply (rule_tac r_sb=\"ereq_use_env (owner_name x) tau_x\" in trans_leq_use_env)\n      apply (simp_all)(*\n    apply (rule_tac st_diff_comp_leq_use_env)*)\n    apply (rule_tac r_sb=\"diff_use_env (ereq_use_env (owner_name x) tau_x) (comp_use_env (ereq_use_env (owner_name x) tau_x) r_exa)\" in trans_leq_use_env)\n     apply (simp)\n    apply (rule_tac r_s=\"r_s\" in crush_leq_use_env)\n      apply (simp_all)\n    apply (rule_tac diff_leq_use_env)\n    apply (simp)\n   apply (rule_tac r_sb=\"cut_use_env (comp_use_env (ereq_use_env (owner_name x) tau_x) r_exa)\" in trans_leq_use_env)\n    apply (rule_tac r_s=\"r_s\" in dist_diff_leq_use_env_rev)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (simp_all)\n   apply (rule_tac dist_cut_leq_use_env)\n   apply (rule_tac comp_leq_use_env1)\n   apply (simp)\n  apply (case_tac x)\n   apply (auto)(*\n   apply (rule_tac r_sb=\"diff_use_env (ereq_use_env (owner_name x) tau_x) (comp_use_env (ereq_use_env (owner_name x) tau_x) r_exa)\" in trans_leq_use_env)\n    apply (auto)\n   apply (rule_tac r_c=\"r_s\" in squish_leq_use_env)\n      apply (rule_tac r_sb=\"r_x\" in trans_leq_use_env)\n       apply (auto)*)\n  done\n    \n\nlemma ivrpc_coerce: \"\\<lbrakk> \\<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.\n           \\<lbrakk>well_typed env r_s e tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;\n            sub_range env_v ds; tsub_dom t_sub ds\\<rbrakk>\n           \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \\<and>\n                   fresh_list ds (dom_list l) \\<and>\n                   dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n                   (\\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \\<and>\n                            leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \\<and>\n                            leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \\<and>\n                            leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \\<and>\n                            dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \\<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);\n  well_typed env r_s e tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;\n            sub_range env_v ds; tsub_dom t_sub ds \\<rbrakk> \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \\<and>\n                   fresh_list ds (dom_list l) \\<and>\n                   dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n                   (\\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \\<and>\n                            leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \\<and>\n                            leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \\<and>\n                            leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \\<and>\n                            dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \\<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list)\"    \n  apply (auto)\n  done\n\nlemma sub_snorm_use_env: \"\\<lbrakk> leq_use_env r_exa r_s; leq_use_env r_x (diff_use_env r_s r_exa);\n  \\<forall> x. super_norm_use_env (diff_use_env r_s r_exa) r_x x = diff_use_env (diff_use_env r_s r_exa) r_exb x \\<rbrakk> \\<Longrightarrow>\n  diff_use_env r_s (comp_use_env r_exa r_exb) = super_norm_use_env r_s r_x\"\n  apply (case_tac \"\\<forall> x. diff_use_env r_s (comp_use_env r_exa r_exb) x = super_norm_use_env r_s r_x x\")\n   apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (simp add: leq_use_env_def)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (simp add: super_norm_use_env_def)\n  apply (simp add: diff_use_env_def)\n  apply (simp add: comp_use_env_def)\n  apply (case_tac \"diff_perm (r_s x) (r_exa x) = OwnPerm \\<and> r_x x = NoPerm\")\n   apply (auto)\n    apply (case_tac \"r_exa x\")\n      apply (auto)\n     apply (case_tac \"r_exb x\")\n       apply (auto)\n    apply (case_tac \"r_exb x\")\n      apply (auto)\n   apply (simp add: diff_use_env_def)\n   apply (case_tac \"r_s x = OwnPerm \\<and> r_x x = NoPerm\")\n    apply (auto)\n     apply (case_tac \"r_exa x\")\n       apply (auto)\n    apply (case_tac \"r_exa x\")\n      apply (auto)\n      apply (case_tac \"r_exb x\")\n        apply (auto)\n     apply (case_tac \"r_exb x\")\n       apply (auto)\n    apply (case_tac \"r_s x\")\n      apply (auto)\n   apply (case_tac \"r_exa x\")\n     apply (auto)\n     apply (case_tac \"r_exb x\")\n       apply (auto)\n    apply (case_tac \"r_exb x\")\n      apply (auto)\n   apply (case_tac \"r_x x\")\n     apply (auto)\n  apply (simp add: diff_use_env_def)\n  apply (case_tac \"r_exa x\")\n    apply (auto)\n    apply (case_tac \"r_exb x\")\n      apply (auto)\n   apply (case_tac \"r_exb x\")\n     apply (auto)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n  done\n    \n  \n    \nlemma ivr_induct_format: \"\\<lbrakk> well_typed env r_s1 e1 t1 r_s2 rx1; well_typed env r_s2 e2 t2 r_s3 rx2 \\<rbrakk> \\<Longrightarrow>\n  (\\<exists> r_exa r_exb. leq_use_env r_exa r_s1 \\<and> leq_use_env r_exb (diff_use_env r_s1 r_exa) \\<and>\n  super_norm_use_env r_s1 r_s3 = diff_use_env r_s1 (comp_use_env r_exa r_exb) \\<and>\n  well_typed env r_s1 e1 t1 (diff_use_env r_s1 r_exa) rx1 \\<and>\n  well_typed env (diff_use_env r_s1 r_exa) e2 t2 (diff_use_env (diff_use_env r_s1 r_exa) r_exb) rx2)\"    \n  apply (cut_tac env=\"env\" and e=\"e1\" in well_typed_sstr_end_perm) \n   apply (auto)\n  apply (cut_tac env=\"env\" and r_c=\"super_norm_use_env r_s1 r_s2\" and e=\"e2\" in well_typed_incr_start_perm)\n    apply (auto)\n   apply (rule_tac rhs_snorm_leq_use_env)\n    apply (rule_tac well_typed_perm_leq)\n    apply (auto)\n   apply (rule_tac id_leq_use_env)\n  apply (cut_tac r_s=\"r_s1\" and r_x=\"r_s2\" in snorm_diff_use_env)\n  apply (auto)\n  apply (cut_tac env=\"env\" and ?r_s1.0=\"diff_use_env r_s1 r_ex\" and e=\"e2\" in well_typed_sstr_end_perm)\n   apply (auto)\n  apply (cut_tac r_s=\"diff_use_env r_s1 r_ex\" and r_x=\"r_s3\" in snorm_diff_use_env)\n  apply (auto)\n  apply (rule_tac x=\"r_ex\" in exI)\n  apply (auto)\n  apply (rule_tac x=\"r_exa\" in exI)\n  apply (auto)\n  apply (cut_tac r_s=\"r_s1\" and r_x=\"r_s3\" and r_exa=\"r_ex\" and r_exb=\"r_exa\" in sub_snorm_use_env)\n     apply (auto)\n  apply (rule_tac well_typed_perm_leq)\n  apply (auto)\n  done\n    \nlemma sol_sat_split: \"\\<lbrakk> dir_sol_sat t_sub p_sub cl1; dir_sol_sat t_sub p_sub cl2 \\<rbrakk> \\<Longrightarrow> dir_sol_sat t_sub p_sub (cl1 @ cl2)\"    \n  apply (induct cl1)\n   apply (auto)\n  done\n\nfun tvar_crn where\n  \"tvar_crn (UnifyCrn t1 t2) = (tvar_type t1 \\<union> tvar_type t2)\"\n| \"tvar_crn (MemValCrn tau tau_x) = (tvar_type tau \\<union> tvar_type tau_x)\"\n| \"tvar_crn (LeqCrn px q) = (tvar_set px)\"\n| \"tvar_crn (LeqTypeCrn tau px) = (tvar_type tau)\"\n| \"tvar_crn (DisjCrn px qx) = (tvar_set px \\<union> tvar_set qx)\" \n| \"tvar_crn (SemiDisjCrn px qx) = (tvar_set px \\<union> tvar_set qx)\"\n\nfun tvar_crn_list where\n  \"tvar_crn_list [] = {}\"\n| \"tvar_crn_list (c # c_t) = (tvar_crn c \\<union> tvar_crn_list c_t)\"\n  \nfun pvar_crn where\n  \"pvar_crn (UnifyCrn t1 t2) = (pvar_type t1 \\<union> pvar_type t2)\"\n| \"pvar_crn (MemValCrn tau tau_x) = (pvar_type tau \\<union> pvar_type tau_x)\"\n| \"pvar_crn (LeqCrn px q) = (pvar_set px \\<union> pvar_set_perm q)\"\n| \"pvar_crn (LeqTypeCrn tau px) = (pvar_type tau \\<union> pvar_set_perm px)\"\n| \"pvar_crn (DisjCrn px qx) = (pvar_set px \\<union> pvar_set qx)\" \n| \"pvar_crn (SemiDisjCrn px qx) = (pvar_set px \\<union> pvar_set qx)\"\n\nfun pvar_crn_list where\n  \"pvar_crn_list [] = {}\"\n| \"pvar_crn_list (c # c_t) = (pvar_crn c \\<union> pvar_crn_list c_t)\"\n  \nlemma dir_add_sol_crn: \"\\<lbrakk> dir_sol_crn t_sub p_sub c; x \\<notin> tvar_crn c \\<rbrakk> \\<Longrightarrow> dir_sol_crn (dir_add_env t_sub x tau) p_sub c\"\n  apply (case_tac c)\n       apply (auto)\n               apply (simp_all add: dir_add_subst_permx)\n    apply (rule_tac x=\"tau_x\" in exI)\n    apply (simp add: dir_add_subst_type)\n   apply (rule_tac x=\"t'\" in exI)\n   apply (rule_tac x=\"tx'\" in exI)\n   apply (simp add: dir_add_subst_type)\n  apply (rule_tac x=\"tau_x\" in exI)\n  apply (simp add: dir_add_subst_type)\n  done\n    \nlemma dir_add_sol_sat: \"\\<lbrakk> dir_sol_sat t_sub p_sub c_list; x \\<notin> tvar_crn_list c_list \\<rbrakk> \\<Longrightarrow> dir_sol_sat (dir_add_env t_sub x tau) p_sub c_list\"\n  apply (induct c_list)\n   apply (auto)\n  apply (rule_tac dir_add_sol_crn)\n   apply (auto)\n  done\n\n    (* if we add variables to t_sub, and those variables are fresh from c_list, solution satisfaction is maintained *)\nlemma dir_list_add_sol_sat: \"\\<lbrakk> dir_sol_sat t_sub p_sub c_list; (dom_list_set l) \\<inter> (tvar_crn_list c_list) = {} \\<rbrakk> \\<Longrightarrow>\n  dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list\"\n  apply (induct l)\n   apply (auto)\n  apply (rule_tac dir_add_sol_sat)\n   apply (auto)\n  done\n\nlemma add_psub_sol_crn: \"\\<lbrakk> dir_sol_crn t_sub p_sub c; x \\<notin> pvar_crn c \\<rbrakk> \\<Longrightarrow>\n  dir_sol_crn t_sub (add_use_env p_sub x r) c\"\n  apply (case_tac c)\n       apply (auto)\n               apply (simp_all add: add_subst_permx)\n     apply (rule_tac x=\"tau_x\" in exI)\n     apply (simp add: add_dir_subst_type)\n    apply (rule_tac x=\"t'\" in exI)\n    apply (rule_tac x=\"tx'\" in exI)\n    apply (simp add: add_dir_subst_type)\n   apply (simp add: add_subst_perm)\n  apply (rule_tac x=\"tau_x\" in exI)\n  apply (auto)\n   apply (simp add: add_dir_subst_type)\n  apply (simp add: add_subst_perm)\n  done\n    \nlemma add_psub_sol_sat: \"\\<lbrakk> dir_sol_sat t_sub p_sub c_list; x \\<notin> pvar_crn_list c_list \\<rbrakk> \\<Longrightarrow>\n  dir_sol_sat t_sub (add_use_env p_sub x r) c_list\"\n  apply (induct c_list)\n   apply (auto)\n  apply (simp add: add_psub_sol_crn)\n  done\n \nlemma comp_psub_sol_crn: \"\\<lbrakk> dir_sol_crn t_sub p_sub c; pvar_crn c \\<subseteq> ds; psub_dom p_subx ds'; ds \\<inter> ds' = {} \\<rbrakk> \\<Longrightarrow>\n  dir_sol_crn t_sub (comp_use_env p_sub p_subx) c\"\n  apply (induct c)\n       apply (auto)\n               apply (simp_all add: comp_subst_permx)\n     apply (rule_tac x=\"tau_x\" in exI)\n     apply (simp add: comp_dir_subst_type1)\n    apply (rule_tac x=\"t'\" in exI)\n    apply (rule_tac x=\"tx'\" in exI)\n    apply (simp add: comp_dir_subst_type1)\n   apply (simp add: comp_subst_perm)\n  apply (rule_tac x=\"tau_x\" in exI)\n  apply (simp add: comp_dir_subst_type1)\n  apply (simp add: comp_subst_perm)\n  done\n    \nlemma comp_psub_sol_sat1: \"\\<lbrakk> dir_sol_sat t_sub p_sub c_list; pvar_crn_list c_list \\<subseteq> ds; psub_dom p_subx ds'; ds \\<inter> ds' = {} \\<rbrakk> \\<Longrightarrow>\n  dir_sol_sat t_sub (comp_use_env p_sub p_subx) c_list\"\n  apply (induct c_list)\n   apply (auto)\n  apply (simp add: comp_psub_sol_crn)\n  done\n\nlemma comp_psub_sol_sat2: \"\\<lbrakk> dir_sol_sat t_sub p_sub c_list; pvar_crn_list c_list \\<subseteq> ds; psub_dom p_subx ds'; ds \\<inter> ds' = {} \\<rbrakk> \\<Longrightarrow>\n  dir_sol_sat t_sub (comp_use_env p_subx p_sub) c_list\"\n  apply (simp add: comm_comp_use_env)\n  apply (rule_tac comp_psub_sol_sat1)\n     apply (auto)\n  done\n    \nlemma derive_dom_list_set: \"\\<lbrakk> tsub_dom (dir_list_add_env t_sub l) ds';\n  fresh_list ds (dom_list l) \\<rbrakk> \\<Longrightarrow> dom_list_set l \\<subseteq> set_diff ds' ds\"\n  apply (induct l)\n   apply (auto)\n   apply (simp add: set_diff_def)\n   apply (simp add: tsub_dom_def)\n   apply (simp add: fresh_list_def)\n   apply (simp add: dir_add_env_def)\n  apply (case_tac \"tsub_dom (dir_list_add_env t_sub l) ds'\")\n   apply (case_tac \"fresh_list ds (dom_list l)\")\n    apply (auto)\n   apply (simp add: fresh_list_def)\n  apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and x=\"a\" and ds=\"ds'\" and tau=\"b\" in add_tsub_dom_rev)\n   apply (auto)\n  done\n  \n    (*\nlemma infer_tvar_crn_list: \"\\<lbrakk> infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds' \\<rbrakk> \\<Longrightarrow> tvar_crn_list c_list \\<subseteq> ds'\"      \n  apply (induct e arbitrary: env_v ds tau_v r_sv r_xv r_mv c_list ds')\n        apply (auto)\n    *)\n    \nlemma tvar_clist_split: \"\\<lbrakk> x \\<in> tvar_crn_list (cl1 @ cl2) \\<rbrakk> \\<Longrightarrow> x \\<in> tvar_crn_list cl1 \\<or> x \\<in> tvar_crn_list cl2\"    \n  apply (induct cl1)\n   apply (auto)\n  done    \n    \nlemma tvar_clist_disj: \"\\<lbrakk> x \\<in> tvar_crn_list (disj_crn r_s r_x d); tvar_range r_s ds; tvar_range r_x ds \\<rbrakk> \\<Longrightarrow> x \\<in> ds\"    \n  apply (induct d)\n   apply (auto)\n   apply (simp add: tvar_range_def)\n   apply (erule_tac x=\"a\" in allE)\n   apply (auto)\n  apply (simp add: tvar_range_def)\n  apply (erule_tac x=\"a\" in allE)\n  apply (auto)\n  done\n   \nlemma tvar_clist_semi_disj: \"\\<lbrakk> x \\<in> tvar_crn_list (semi_disj_crn r_s r_x d); tvar_range r_s ds; tvar_range r_x ds \\<rbrakk> \\<Longrightarrow> x \\<in> ds\"    \n  apply (induct d)\n   apply (auto)\n   apply (simp add: tvar_range_def)\n   apply (erule_tac x=\"a\" in allE)\n   apply (auto)\n  apply (simp add: tvar_range_def)\n  apply (erule_tac x=\"a\" in allE)\n  apply (auto)\n  done\n\nlemma tvar_clist_aff: \"\\<lbrakk> x \\<in> tvar_crn_list (aff_crn r_s p d); tvar_range r_s ds; tvar_set_perm p \\<subseteq> ds \\<rbrakk> \\<Longrightarrow> x \\<in> ds\"    \n  apply (induct d)\n   apply (auto)\n  apply (simp add: tvar_range_def)\n  apply (erule_tac x=\"a\" in allE)\n  apply (auto)\n  done    \n    \nlemma pvar_clist_split: \"\\<lbrakk> x \\<in> pvar_crn_list (cl1 @ cl2) \\<rbrakk> \\<Longrightarrow> x \\<in> pvar_crn_list cl1 \\<or> x \\<in> pvar_crn_list cl2\"    \n  apply (induct cl1)\n   apply (auto)\n  done\n    \nlemma pvar_clist_disj: \"\\<lbrakk> x \\<in> pvar_crn_list (disj_crn r_s r_x d); pvar_range r_s ds; pvar_range r_x ds \\<rbrakk> \\<Longrightarrow> x \\<in> ds\"    \n  apply (induct d)\n   apply (auto)\n   apply (simp add: pvar_range_def)\n   apply (erule_tac x=\"a\" in allE)\n   apply (auto)\n  apply (simp add: pvar_range_def)\n  apply (erule_tac x=\"a\" in allE)\n  apply (auto)\n  done\n\nlemma pvar_clist_semi_disj: \"\\<lbrakk> x \\<in> pvar_crn_list (semi_disj_crn r_s r_x d); pvar_range r_s ds; pvar_range r_x ds \\<rbrakk> \\<Longrightarrow> x \\<in> ds\"    \n  apply (induct d)\n   apply (auto)\n   apply (simp add: pvar_range_def)\n   apply (erule_tac x=\"a\" in allE)\n   apply (auto)\n  apply (simp add: pvar_range_def)\n  apply (erule_tac x=\"a\" in allE)\n  apply (auto)\n  done\n\nlemma pvar_clist_aff: \"\\<lbrakk> x \\<in> pvar_crn_list (aff_crn r_s p d); pvar_range r_s ds; pvar_set_perm p \\<subseteq> ds \\<rbrakk> \\<Longrightarrow> x \\<in> ds\"    \n  apply (induct d)\n   apply (auto)\n  apply (simp add: pvar_range_def)\n  apply (erule_tac x=\"a\" in allE)\n  apply (auto)\n  done\n\ndefinition induct_clist where\n  \"induct_clist v_list ds = (v_list \\<subseteq> ds)\"\n    \nlemma infer_tvar_crn_list_ih: \"\\<lbrakk> infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; sub_range env_v ds \\<rbrakk> \\<Longrightarrow> induct_clist (tvar_crn_list c_list) ds'\"    \n  apply (induct e arbitrary: env_v ds tau_v r_sv r_xv r_mv c_list ds')\n        apply (auto)\n    (* const + op case *)\n        apply (simp add: induct_clist_def)\n        apply (case_tac x)\n                    apply (auto)\n       apply (simp add: induct_clist_def)\n    (* var case *)\n      apply (simp add: induct_clist_def)\n      apply (case_tac x)\n       apply (auto)\n       apply (simp add: sub_range_def)\n       apply (erule_tac x=\"Loc x22\" in allE)\n       apply (auto)\n      apply (simp add: sub_range_def)\n      apply (erule_tac x=\"Loc x21\" in allE)\n      apply (auto)\n    (* pair case *)\n     apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n      apply (auto)\n     apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n      apply (auto)\n     apply (cut_tac ds=\"ds\" and ds'=\"ds2\" and env_v=\"env_v\" in subset_sub_range)\n       apply (auto)\n     apply (simp add: induct_clist_def)\n     apply (auto)\n       apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_tvar_type)\n         apply (auto)\n      apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_tvar_type)\n        apply (auto)\n     apply (cut_tac r_sv=\"r_s1\" and r_xv=\"r_x1\" and e=\"e1\" and env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in infer_tvar_range)\n       apply (auto)\n     apply (cut_tac r_sv=\"r_s2\" and r_xv=\"r_x2\" and e=\"e2\" and env_v=\"env_v\" and ds=\"ds2\" and ds'=\"ds3\" in infer_tvar_range)\n       apply (auto)\n     apply (cut_tac r_mv=\"r_m1\" and e=\"e1\" and env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in infer_m_tvar_range)\n       apply (auto)\n     apply (cut_tac r_mv=\"r_m2\" and e=\"e2\" and env_v=\"env_v\" and ds=\"ds2\" and ds'=\"ds3\" in infer_m_tvar_range)\n       apply (auto)\n     apply (cut_tac x=\"x\" and ?cl1.0=\"disj_crn (lift_var_env r_x1 (SVar p)) (lift_var_env r_x2 (SVar p)) d\" and\n        ?cl2.0=\"semi_disj_crn r_m2 r_x1 d @ semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2\" in tvar_clist_split)\n      apply (auto)\n      apply (cut_tac r_s=\"lift_var_env r_x1 (SVar p)\" and r_x=\"lift_var_env r_x2 (SVar p)\" and x=\"x\" and ds=\"insert p ds3\" in tvar_clist_disj)\n         apply (simp)\n        apply (rule_tac lift_tvar_range)\n         apply (rule_tac ds=\"ds2\" in subset_tvar_range)\n          apply (auto)\n      apply (rule_tac lift_tvar_range)\n       apply (rule_tac ds=\"ds3\" in subset_tvar_range)\n        apply (auto)\n     apply (cut_tac x=\"x\" and ?cl1.0=\"semi_disj_crn r_m2 r_x1 d\" and\n        ?cl2.0=\"semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2\" in tvar_clist_split)\n      apply (auto)\n      apply (cut_tac r_s=\"r_m2\" and r_x=\"r_x1\" and x=\"x\" and ds=\"insert p ds3\" in tvar_clist_semi_disj)\n         apply (simp)\n        apply (rule_tac ds=\"ds3\" in subset_tvar_range)\n         apply (auto)\n      apply (rule_tac ds=\"ds2\" in subset_tvar_range)\n       apply (auto)\n     apply (cut_tac x=\"x\" and ?cl1.0=\"semi_disj_crn r_m1 r_s2 d\" and ?cl2.0=\"cl1 @ cl2\" in tvar_clist_split)\n      apply (auto)\n      apply (cut_tac r_s=\"r_m1\" and r_x=\"r_s2\" and x=\"x\" and ds=\"ds3\" in tvar_clist_semi_disj)\n         apply (simp)\n        apply (rule_tac ds=\"ds2\" in subset_tvar_range)\n         apply (auto)\n     apply (cut_tac x=\"x\" and ?cl1.0=\"cl1\" and ?cl2.0=\"cl2\" in tvar_clist_split)\n      apply (auto)\n      apply (cut_tac c=\"x\" and A=\"tvar_crn_list cl1\" and B=\"ds2\" in Set.rev_subsetD)\n        apply (auto)\n     apply (cut_tac c=\"x\" and A=\"tvar_crn_list cl2\" and B=\"ds3\" in Set.rev_subsetD)\n       apply (auto)\n    (* if case *)\n    apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n     apply (auto)\n    apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n     apply (auto)\n    apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n     apply (auto)\n    apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n      apply (auto)\n    apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and ds'=\"ds3\" in subset_sub_range)\n      apply (auto)\n    apply (simp add: induct_clist_def)\n    apply (auto)\n       apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_tvar_type)\n         apply (auto)\n      apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_tvar_type)\n        apply (auto)\n     apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_tvar_type)\n       apply (auto)\n    apply (cut_tac x=\"x\" and ?cl1.0=\"semi_disj_crn r_m1 (comp_var_env r_s2 r_s3) d\" and\n        ?cl2.0=\"cl1 @ cl2 @ cl3\" in tvar_clist_split)\n     apply (auto)\n     apply (cut_tac r_s=\"r_m1\" and r_x=\"comp_var_env r_s2 r_s3\" and x=\"x\" and ds=\"ds'\" in tvar_clist_semi_disj)\n        apply (simp)\n       apply (cut_tac r_mv=\"r_m1\" and e=\"e1\" and env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in infer_m_tvar_range)\n        apply (auto)\n      apply (rule_tac ds=\"ds2\" in subset_tvar_range)\n       apply (auto)\n     apply (rule_tac comp_tvar_range)\n      apply (cut_tac r_sv=\"r_s2\" and e=\"e2\" and env_v=\"env_v\" and ds=\"ds2\" and ds'=\"ds3\" in infer_tvar_range)\n       apply (auto)\n      apply (rule_tac ds=\"ds3\" in subset_tvar_range)\n       apply (auto)\n     apply (cut_tac r_sv=\"r_s3\" and e=\"e3\" and env_v=\"env_v\" and ds=\"ds3\" and ds'=\"ds'\" in infer_tvar_range)\n      apply (auto)\n    apply (cut_tac x=\"x\" and ?cl1.0=\"cl1\" and ?cl2.0=\"cl2 @ cl3\" in tvar_clist_split)\n     apply (auto)\n     apply (cut_tac c=\"x\" and A=\"tvar_crn_list cl1\" and B=\"ds2\" in Set.rev_subsetD)\n       apply (auto)\n    apply (cut_tac x=\"x\" and ?cl1.0=\"cl2\" and ?cl2.0=\"cl3\" in tvar_clist_split)\n     apply (auto)\n     apply (cut_tac c=\"x\" and A=\"tvar_crn_list cl2\" and B=\"ds3\" in Set.rev_subsetD)\n       apply (auto)\n    apply (cut_tac c=\"x\" and A=\"tvar_crn_list cl3\" and B=\"ds'\" in Set.rev_subsetD)\n      apply (auto)\n    (* lam case *)\n   apply (simp add: induct_clist_def)\n   apply (auto)\n    apply (cut_tac r_sv=\"r_s'\" and e=\"e\" and env_v=\"add_env env_v (Var x1a) a\" in infer_tvar_range)\n      apply (auto) \n     apply (rule_tac add_sub_range)\n     apply (simp)\n    apply (simp add: tvar_range_def)\n    apply (erule_tac x=\"Var x1a\" in allE)\n    apply (auto)\n   apply (cut_tac x=\"x\" and ?cl1.0=\"aff_crn (rem_var_env r_s' (Var x1a)) (SVar q) d\" and ?cl2.0=\"cl\" in tvar_clist_split)\n    apply (auto)\n    apply (cut_tac r_s=\"rem_var_env r_s' (Var x1a)\" and x=\"x\" and p=\"SVar q\" and ds=\"insert q ds2\" in tvar_clist_aff)\n       apply (simp)\n      apply (rule_tac rem_tvar_range)\n      apply (rule_tac ds=\"ds2\" in subset_tvar_range)\n       apply (cut_tac r_sv=\"r_s'\" and e=\"e\" and env_v=\"add_env env_v (Var x1a) a\" in infer_tvar_range)\n         apply (auto)\n    apply (cut_tac e=\"e\" and ds=\"insert a ds\" and ds'=\"ds2\" in infer_x_subset)\n     apply (auto)\n    apply (rule_tac add_sub_range)\n    apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and x=\"Var x1a\" and a=\"a\" in add_sub_range)\n    apply (simp_all)\n   apply (cut_tac c=\"x\" and A=\"tvar_crn_list cl\" and B=\"ds2\" in Set.rev_subsetD)\n     apply (auto)\n    (* app case *)\n  apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n   apply (auto)\n  apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n   apply (auto)\n  apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n    apply (cut_tac r_sv=\"r_s1\" and e=\"e1\" and env_v=\"env_v\" in infer_tvar_range)\n      apply (auto)\n  apply (simp add: induct_clist_def)\n  apply (auto)\n    apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_tvar_type)\n      apply (auto)\n   apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_tvar_type)\n     apply (auto)\n  apply (cut_tac x=\"x\" and ?cl1.0=\"disj_crn r_x1 (lift_var_env r_x2 (SVar p)) d\" and\n      ?cl2.0=\"semi_disj_crn r_m2 r_x1 d @ semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2\" in tvar_clist_split)\n   apply (auto)\n   apply (cut_tac r_s=\"r_x1\" and r_x=\"lift_var_env r_x2 (SVar p)\" and x=\"x\" and ds=\"insert p ds3\" in tvar_clist_disj)\n      apply (auto)\n    apply (rule_tac ds=\"ds2\" in subset_tvar_range)\n     apply (cut_tac r_sv=\"r_s1\" and e=\"e1\" and env_v=\"env_v\" in infer_tvar_range)\n       apply (auto)\n   apply (rule_tac lift_tvar_range)\n    apply (auto)\n   apply (rule_tac ds=\"ds3\" in subset_tvar_range)\n    apply (auto)\n   apply (cut_tac r_sv=\"r_s2\" and e=\"e2\" and ds=\"ds2\" and env_v=\"env_v\" in infer_tvar_range)\n     apply (auto)\n  apply (cut_tac x=\"x\" and ?cl1.0=\"semi_disj_crn r_m2 r_x1 d\" and ?cl2.0=\"semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2\" in tvar_clist_split)\n   apply (auto)\n   apply (cut_tac r_s=\"r_m2\" and r_x=\"r_x1\" and x=\"x\" and ds=\"insert p ds3\" in tvar_clist_semi_disj)\n      apply (auto)\n    apply (rule_tac ds=\"ds3\" in subset_tvar_range)\n     apply (auto)\n    apply (rule_tac env_v=\"env_v\" and ds=\"ds2\" in infer_m_tvar_range)\n     apply (auto)\n   apply (rule_tac ds=\"ds2\" in subset_tvar_range)\n    apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and e=\"e1\" in infer_tvar_range)\n     apply (auto)\n  apply (cut_tac x=\"x\" and ?cl1.0=\"semi_disj_crn r_m1 r_s2 d\" and ?cl2.0=\"cl1 @ cl2\" in tvar_clist_split)\n   apply (auto)\n   apply (cut_tac r_s=\"r_m1\" and r_x=\"r_s2\" and x=\"x\" and ds=\"insert p ds3\" in tvar_clist_semi_disj)\n      apply (auto)\n    apply (rule_tac ds=\"ds2\" in subset_tvar_range)\n     apply (auto)\n    apply (rule_tac env_v=\"env_v\" and ds=\"ds\" in infer_m_tvar_range)\n      apply (auto)\n   apply (rule_tac ds=\"ds3\" in subset_tvar_range)\n    apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and e=\"e2\" in infer_tvar_range)\n     apply (auto)\n  apply (cut_tac x=\"x\" and ?cl1.0=\"cl1\" and ?cl2.0=\"cl2\" in tvar_clist_split)\n   apply (auto)\n   apply (cut_tac c=\"x\" and A=\"tvar_crn_list cl1\" and B=\"ds2\" in Set.rev_subsetD)\n     apply (auto)\n  apply (cut_tac c=\"x\" and A=\"tvar_crn_list cl2\" and B=\"ds3\" in Set.rev_subsetD)\n    apply (auto)\n  done\n    \nlemma infer_tvar_crn_list: \"\\<lbrakk> infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; sub_range env_v ds \\<rbrakk> \\<Longrightarrow> tvar_crn_list c_list \\<subseteq> ds'\"      \n  apply (cut_tac env_v=\"env_v\" and e=\"e\" and ds=\"ds\" and ds'=\"ds'\" in infer_tvar_crn_list_ih)\n    apply (auto)\n  apply (simp add: induct_clist_def)\n  apply (auto)\n  done\n    \nlemma infer_pvar_crn_list_ih: \"\\<lbrakk> infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; sub_range env_v ds \\<rbrakk> \\<Longrightarrow> induct_clist (pvar_crn_list c_list) (set_diff ds' ds)\"    \n  apply (induct e arbitrary: env_v ds tau_v r_sv r_xv r_mv c_list ds')\n        apply (auto)\n    (* const + op case *)\n        apply (simp add: induct_clist_def)\n        apply (simp add: set_diff_def)\n        apply (case_tac x)\n                    apply (auto)\n           apply (simp add: fresh_list_def)\n           apply (auto)\n          apply (simp add: fresh_list_def)\n          apply (auto)\n         apply (simp add: fresh_list_def)\n         apply (auto)\n        apply (simp add: fresh_list_def)\n        apply (auto)\n       apply (simp add: induct_clist_def)\n    (* var case *)\n      apply (simp add: induct_clist_def)\n      apply (simp add: set_diff_def)\n      apply (auto)\n      apply (case_tac x)\n       apply (auto)\n    (* pair case *)\n     apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n      apply (auto)\n     apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n      apply (auto)\n     apply (simp add: induct_clist_def)\n     apply (auto)\n        apply (simp add: set_diff_def)\n        apply (auto)\n       apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_pvar_type)\n         apply (auto)\n       apply (simp add: set_diff_def)\n       apply (auto)\n      apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_pvar_type)\n        apply (auto)\n       apply (rule_tac ds=\"ds\" in subset_sub_range)\n        apply (auto)\n      apply (simp add: set_diff_def)\n      apply (auto)\n     apply (cut_tac r_sv=\"r_s1\" and r_xv=\"r_x1\" and e=\"e1\" and env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in infer_s_sub_range)\n      apply (auto)\n     apply (cut_tac r_sv=\"r_s2\" and r_xv=\"r_x2\" and e=\"e2\" and env_v=\"env_v\" and ds=\"ds2\" and ds'=\"ds3\" in infer_s_sub_range)\n      apply (auto)\n     apply (cut_tac r_mv=\"r_m1\" and e=\"e1\" and env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in infer_m_sub_range)\n      apply (auto)\n     apply (cut_tac r_mv=\"r_m2\" and e=\"e2\" and env_v=\"env_v\" and ds=\"ds2\" and ds'=\"ds3\" in infer_m_sub_range)\n      apply (auto)\n     apply (cut_tac x=\"x\" and ?cl1.0=\"disj_crn (lift_var_env r_x1 (SVar p)) (lift_var_env r_x2 (SVar p)) d\" and\n        ?cl2.0=\"semi_disj_crn r_m2 r_x1 d @ semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2\" in pvar_clist_split)\n      apply (auto)\n      apply (cut_tac r_s=\"lift_var_env r_x1 (SVar p)\" and r_x=\"lift_var_env r_x2 (SVar p)\" and x=\"x\" and ds=\"set_diff (insert p ds3) ds\" in pvar_clist_disj)\n         apply (simp)\n        apply (rule_tac lift_pvar_range)\n         apply (rule_tac ds=\"set_diff ds2 ds\" in subset_pvar_range)\n          apply (auto)\n        apply (simp add: set_diff_def)\n        apply (auto)\n       apply (simp add: set_diff_def)\n       apply (auto)\n      apply (rule_tac lift_pvar_range)\n       apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n        apply (auto)\n       apply (simp add: set_diff_def)\n       apply (auto)\n      apply (simp add: set_diff_def)\n      apply (auto)\n     apply (cut_tac x=\"x\" and ?cl1.0=\"semi_disj_crn r_m2 r_x1 d\" and\n        ?cl2.0=\"semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2\" in pvar_clist_split)\n      apply (auto)\n      apply (cut_tac r_s=\"r_m2\" and r_x=\"r_x1\" and x=\"x\" and ds=\"set_diff (insert p ds3) ds\" in pvar_clist_semi_disj)\n         apply (simp)\n        apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n         apply (auto)\n       apply (simp add: set_diff_def)\n       apply (auto)\n      apply (rule_tac ds=\"set_diff ds2 ds\" in subset_pvar_range)\n       apply (auto)\n      apply (simp add: set_diff_def)\n      apply (auto)\n     apply (cut_tac x=\"x\" and ?cl1.0=\"semi_disj_crn r_m1 r_s2 d\" and ?cl2.0=\"cl1 @ cl2\" in pvar_clist_split)\n      apply (auto)\n      apply (cut_tac r_s=\"r_m1\" and r_x=\"r_s2\" and x=\"x\" and ds=\"set_diff (insert p ds3) ds\" in pvar_clist_semi_disj)\n         apply (simp)\n        apply (rule_tac ds=\"set_diff ds2 ds\" in subset_pvar_range)\n         apply (auto)\n       apply (simp add: set_diff_def)\n       apply (auto)\n      apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n       apply (auto)\n      apply (simp add: set_diff_def)\n      apply (auto)\n     apply (cut_tac x=\"x\" and ?cl1.0=\"cl1\" and ?cl2.0=\"cl2\" in pvar_clist_split)\n      apply (auto)\n      apply (case_tac \"x \\<in> set_diff ds2 ds\")\n       apply (simp add: set_diff_def)\n       apply (auto)\n      apply (cut_tac c=\"x\" and A=\"pvar_crn_list cl1\" and B=\"set_diff ds2 ds\" in Set.rev_subsetD)\n        apply (auto)\n     apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n       apply (auto)\n     apply (cut_tac c=\"x\" and A=\"pvar_crn_list cl2\" and B=\"set_diff ds3 ds2\" in Set.rev_subsetD)\n       apply (auto)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    (* if case *)\n    apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n     apply (auto)\n    apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n     apply (auto)\n    apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n     apply (auto)\n    apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n      apply (auto)\n    apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and ds'=\"ds3\" in subset_sub_range)\n      apply (auto)\n    apply (simp add: induct_clist_def)\n    apply (auto)\n       apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_pvar_type)\n         apply (auto)\n       apply (simp add: set_diff_def)\n       apply (auto)\n      apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_pvar_type)\n        apply (auto)\n      apply (simp add: set_diff_def)\n      apply (auto)\n     apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_pvar_type)\n       apply (auto)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (cut_tac x=\"x\" and ?cl1.0=\"semi_disj_crn r_m1 (comp_var_env r_s2 r_s3) d\" and\n        ?cl2.0=\"cl1 @ cl2 @ cl3\" in pvar_clist_split)\n     apply (auto)\n     apply (cut_tac r_s=\"r_m1\" and r_x=\"comp_var_env r_s2 r_s3\" and x=\"x\" and ds=\"set_diff ds' ds\" in pvar_clist_semi_disj)\n        apply (simp)\n       apply (cut_tac r_mv=\"r_m1\" and e=\"e1\" and env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in infer_m_sub_range)\n        apply (auto)\n      apply (rule_tac ds=\"set_diff ds2 ds\" in subset_pvar_range)\n       apply (auto)\n      apply (simp add: set_diff_def)\n      apply (auto)\n     apply (rule_tac comp_pvar_range)\n      apply (cut_tac r_sv=\"r_s2\" and e=\"e2\" and env_v=\"env_v\" and ds=\"ds2\" and ds'=\"ds3\" in infer_s_sub_range)\n       apply (auto)\n      apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n       apply (auto)\n      apply (simp add: set_diff_def)\n      apply (auto)\n     apply (cut_tac r_sv=\"r_s3\" and e=\"e3\" and env_v=\"env_v\" and ds=\"ds3\" and ds'=\"ds'\" in infer_s_sub_range)\n      apply (auto)\n     apply (rule_tac ds=\"set_diff ds' ds3\" in subset_pvar_range)\n      apply (auto)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (cut_tac x=\"x\" and ?cl1.0=\"cl1\" and ?cl2.0=\"cl2 @ cl3\" in pvar_clist_split)\n     apply (auto)\n     apply (cut_tac c=\"x\" and A=\"pvar_crn_list cl1\" and B=\"set_diff ds2 ds\" in Set.rev_subsetD)\n       apply (auto)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (cut_tac x=\"x\" and ?cl1.0=\"cl2\" and ?cl2.0=\"cl3\" in pvar_clist_split)\n     apply (auto)\n     apply (cut_tac c=\"x\" and A=\"pvar_crn_list cl2\" and B=\"set_diff ds3 ds2\" in Set.rev_subsetD)\n       apply (auto)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (cut_tac c=\"x\" and A=\"pvar_crn_list cl3\" and B=\"set_diff ds' ds3\" in Set.rev_subsetD)\n      apply (auto)\n    apply (simp add: set_diff_def)\n    apply (auto)\n    (* lam case *)\n   apply (simp add: induct_clist_def)\n   apply (auto)\n     apply (case_tac \"p \\<in> ds\")\n      apply (cut_tac ds=\"insert a ds\" and ds'=\"ds2\" in infer_x_subset)\n       apply (auto)\n     apply (simp add: set_diff_def)\n    apply (cut_tac r_sv=\"r_s'\" and e=\"e\" and env_v=\"add_env env_v (Var x1a) a\" in infer_s_sub_range)\n     apply (auto)\n    apply (simp add: pvar_range_def)\n    apply (erule_tac x=\"Var x1a\" in allE)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (cut_tac x=\"x\" and ?cl1.0=\"aff_crn (rem_var_env r_s' (Var x1a)) (SVar q) d\" and ?cl2.0=\"cl\" in pvar_clist_split)\n    apply (auto)\n    apply (cut_tac r_s=\"rem_var_env r_s' (Var x1a)\" and x=\"x\" and p=\"SVar q\" and ds=\"set_diff (insert q ds2) ds\" in pvar_clist_aff)\n       apply (simp)\n      apply (rule_tac rem_pvar_range)\n      apply (rule_tac ds=\"set_diff ds2 (insert a ds)\" in subset_pvar_range)\n       apply (cut_tac r_sv=\"r_s'\" and e=\"e\" and env_v=\"add_env env_v (Var x1a) a\" in infer_s_sub_range)\n        apply (auto)\n      apply (simp add: set_diff_def)\n     apply (case_tac \"q \\<in> ds\")\n      apply (cut_tac e=\"e\" and ds=\"insert a ds\" and ds'=\"ds2\" in infer_x_subset)\n       apply (auto)\n     apply (simp add: set_diff_def)\n    apply (simp add: set_diff_def)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and x=\"Var x1a\" and a=\"a\" in add_sub_range)\n    apply (simp)\n   apply (cut_tac c=\"x\" and A=\"pvar_crn_list cl\" and B=\"set_diff ds2 (insert a ds)\" in Set.rev_subsetD)\n     apply (auto)\n   apply (simp add: set_diff_def)\n    (* app case *)\n  apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n   apply (auto)\n  apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n   apply (auto)\n  apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n    apply (cut_tac r_sv=\"r_s1\" and e=\"e1\" and env_v=\"env_v\" in infer_s_sub_range)\n     apply (auto)\n  apply (simp add: induct_clist_def)\n  apply (auto)\n      apply (case_tac \"q \\<in> ds3\")\n       apply (simp add: fresh_list_def)\n       apply (auto)\n      apply (simp add: set_diff_def)\n      apply (auto)\n     apply (case_tac \"p \\<in> ds3\")\n      apply (simp add: fresh_list_def)\n      apply (auto)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_pvar_type)\n      apply (auto)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_pvar_type)\n     apply (auto)\n   apply (simp add: set_diff_def)\n   apply (auto)\n  apply (cut_tac x=\"x\" and ?cl1.0=\"disj_crn r_x1 (lift_var_env r_x2 (SVar p)) d\" and\n      ?cl2.0=\"semi_disj_crn r_m2 r_x1 d @ semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2\" in pvar_clist_split)\n   apply (auto)\n   apply (cut_tac r_s=\"r_x1\" and r_x=\"lift_var_env r_x2 (SVar p)\" and x=\"x\" and ds=\"set_diff (insert p ds3) ds\" in pvar_clist_disj)\n      apply (auto)\n     apply (rule_tac ds=\"set_diff ds2 ds\" in subset_pvar_range)\n      apply (cut_tac r_sv=\"r_s1\" and e=\"e1\" and env_v=\"env_v\" in infer_s_sub_range)\n       apply (auto)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (cut_tac r_sv=\"r_s2\" and e=\"e2\" and env_v=\"env_v\" in infer_s_sub_range)\n     apply (auto)\n    apply (rule_tac lift_pvar_range)\n     apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n      apply (simp)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (case_tac \"p \\<in> ds3\")\n     apply (simp add: fresh_list_def)\n     apply (auto)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (simp add: set_diff_def)\n   apply (auto)\n  apply (cut_tac x=\"x\" and ?cl1.0=\"semi_disj_crn r_m2 r_x1 d\" and\n      ?cl2.0=\"semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2\" in pvar_clist_split)\n   apply (auto)\n   apply (cut_tac r_s=\"r_m2\" and r_x=\"r_x1\" and x=\"x\" and ds=\"set_diff (insert p ds3) ds\" in pvar_clist_semi_disj)\n      apply (auto)\n     apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n      apply (rule_tac infer_m_sub_range)\n      apply (auto)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (rule_tac ds=\"set_diff ds2 ds\" in subset_pvar_range)\n     apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_s_sub_range)\n      apply (auto)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (simp add: set_diff_def)\n   apply (auto)\n  apply (cut_tac x=\"x\" and ?cl1.0=\"semi_disj_crn r_m1 r_s2 d\" and\n      ?cl2.0=\"cl1 @ cl2\" in pvar_clist_split)\n   apply (auto)\n   apply (cut_tac r_s=\"r_m1\" and r_x=\"r_s2\" and x=\"x\" and ds=\"set_diff (insert p ds3) ds\" in pvar_clist_semi_disj)\n      apply (auto)\n     apply (rule_tac ds=\"set_diff ds2 ds\" in subset_pvar_range)\n      apply (rule_tac infer_m_sub_range)\n      apply (auto)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n     apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_s_sub_range)\n      apply (auto)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (simp add: set_diff_def)\n   apply (auto)\n  apply (cut_tac x=\"x\" and ?cl1.0=\"cl1\" and ?cl2.0=\"cl2\" in pvar_clist_split)\n   apply (auto)\n   apply (cut_tac c=\"x\" and A=\"pvar_crn_list cl1\" and B=\"set_diff ds2 ds\" in Set.rev_subsetD)\n     apply (auto)\n   apply (simp add: set_diff_def)\n   apply (auto)\n  apply (cut_tac c=\"x\" and A=\"pvar_crn_list cl2\" and B=\"set_diff ds3 ds2\" in Set.rev_subsetD)\n    apply (auto)\n  apply (simp add: set_diff_def)\n  apply (auto)\n  done\n    \nlemma infer_pvar_crn_list: \"\\<lbrakk> infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; sub_range env_v ds \\<rbrakk> \\<Longrightarrow> pvar_crn_list c_list \\<subseteq> set_diff ds' ds\"    \n  apply (cut_tac env_v=\"env_v\" and e=\"e\" and ds=\"ds\" and ds'=\"ds'\" in infer_pvar_crn_list_ih)\n    apply (auto)\n  apply (simp add: induct_clist_def)\n  apply (auto)\n  done\n    \nlemma sol_sat_disj: \"\\<lbrakk> disj_use_env (dir_subst_penv t_sub p_sub r_s) (dir_subst_penv t_sub p_sub r_x) \\<rbrakk> \\<Longrightarrow> dir_sol_sat t_sub p_sub (disj_crn r_s r_x d)\"    \n  apply (induct d)\n   apply (auto)\n   apply (simp add: disj_use_env_def)\n   apply (simp add: mini_disj_use_env_def)\n   apply (simp add: dir_subst_penv_def)\n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: dir_subst_penv_def)\n  done\n\nlemma sol_sat_mini_disj: \"\\<lbrakk> mini_disj_use_env (dir_subst_penv t_sub p_sub r_s) (dir_subst_penv t_sub p_sub r_x) \\<rbrakk> \\<Longrightarrow>\n  dir_sol_sat t_sub p_sub (semi_disj_crn r_s r_x d)\"    \n  apply (induct d)\n   apply (auto)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: dir_subst_penv_def)\n  done\n  (*\nlemma sol_sat_aff: \"\\<lbrakk> aff_use_env (dir_subst_penv t_sub p_sub r_s) a \\<rbrakk> \\<Longrightarrow> dir_sol_sat t_sub p_sub (aff_crn r_s (SVar p) d)\"    *)\n\nlemma cut_disj_use_env: \"\\<lbrakk> mini_disj_use_env r_x r_s \\<rbrakk> \\<Longrightarrow> disj_use_env r_s (cut_use_env r_x)\"    \n  apply (simp add: disj_use_env_def)\n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: cut_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n  done\n    \nlemma swap_diff_cut_leq_use_env: \"\\<lbrakk> leq_use_env r_x r_s; leq_use_env r_ex (diff_use_env r_s r_x) \\<rbrakk> \\<Longrightarrow>\n  leq_use_env (cut_use_env r_x) (diff_use_env r_s r_ex)\"    \n  apply (simp add: leq_use_env_def)\n  apply (simp add: cut_use_env_def)\n  apply (simp add: diff_use_env_def)\n  apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"r_x x\")\n    apply (auto)\n  apply (case_tac \"r_s x\")\n    apply (auto)\n  apply (case_tac \"r_ex x\")\n    apply (auto)\n  done\n    \nlemma cut_mini_disj_use_env: \"\\<lbrakk> mini_disj_use_env (cut_use_env r_s) r_x \\<rbrakk> \\<Longrightarrow> mini_disj_use_env r_s r_x\"    \n  apply (simp add: mini_disj_use_env_def)\n  apply (simp add: cut_use_env_def)\n  done\n\nlemma ivrpc_main: \"\\<lbrakk>\n        spec_env env_v (dir_subst_tenv (dir_list_add_env t_sub l) env_v) t_sub; sub_range env_v ds; tsub_dom t_sub ds;\n        infer_type env_v ds e1 t1a r_s1 r_x1 r_m1 cl1 ds2; \n        infer_type env_v ds2 e2 t2a r_s2 r_x2 r_m2 cl2 ds3;\n        leq_use_env (lift_use_env rx1 r) r_s3; leq_use_env (lift_use_env rx2 r) r_s3; aff_leq (max_aff (req_type t1) (req_type t2)) r;\n        disj_use_env (lift_use_env rx1 r) (lift_use_env rx2 r); leq_use_env r_s3 r_s;\n        finite_dom (comp_var_env (comp_var_env r_s1 (lift_var_env r_x1 (SVar p))) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))) d;\n        leq_use_env (diff_use_env r_s r_ex) (diff_use_env r_s3 r_exa); p \\<notin> ds3; leq_use_env r_exa r_s;\n        leq_use_env (pair_req (comp_use_env (lift_use_env rx1 r) (lift_use_env rx2 r)) r_exa (PairTy t1 t2 r)) r_x; leq_use_env r_exaa r_s;\n        leq_use_env r_exb (diff_use_env r_s r_exaa); super_norm_use_env r_s r_s3 = diff_use_env r_s (comp_use_env r_exaa r_exb);\n        well_typed (dir_subst_tenv (dir_list_add_env t_sub l) env_v) r_s e1 t1 (diff_use_env r_s r_exaa) rx1;\n        well_typed (dir_subst_tenv (dir_list_add_env t_sub l) env_v) (diff_use_env r_s r_exaa) e2 t2 (diff_use_env (diff_use_env r_s r_exaa) r_exb) rx2;\n        tsub_dom (dir_list_add_env t_sub l) ds2; fresh_list ds (dom_list l); env = dir_subst_tenv (dir_list_add_env t_sub l) env_v;\n        psub_dom p_sub (set_diff ds2 ds); leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_s1) r_s;\n        leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_x1) r_exaa) rx1;\n        leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_m1)) r_exaa; dir_subst_type (dir_list_add_env t_sub l) p_sub t1a t1;\n        dir_sol_sat (dir_list_add_env t_sub l) p_sub cl1; tsub_dom (dir_list_add_env (dir_list_add_env t_sub l) la) ds3; fresh_list ds2 (dom_list la);\n        dir_subst_tenv (dir_list_add_env (dir_list_add_env t_sub l) la) env_v = dir_subst_tenv (dir_list_add_env t_sub l) env_v;\n        psub_dom p_suba (set_diff ds3 ds2); leq_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba r_s2) (diff_use_env r_s r_exaa);\n        leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba r_x2) r_exb) rx2;\n        leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba r_m2)) r_exb;\n        dir_subst_type (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba t2a t2; dir_sol_sat (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba cl2\\<rbrakk>\n       \\<Longrightarrow> \\<exists>la. tsub_dom (dir_list_add_env t_sub la) (insert p ds3) \\<and>\n                fresh_list ds (dom_list la) \\<and>\n                dir_subst_tenv (dir_list_add_env t_sub la) env_v = dir_subst_tenv (dir_list_add_env t_sub l) env_v \\<and>\n                (\\<exists>p_sub. psub_dom p_sub (set_diff (insert p ds3) ds) \\<and>\n                         leq_use_env\n                          (dir_subst_penv (dir_list_add_env t_sub la) p_sub\n                            (comp_var_env (comp_var_env r_s1 (lift_var_env r_x1 (SVar p))) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))))\n                          r_s \\<and>\n                         leq_use_env\n                          (diff_use_env\n                            (dir_subst_penv (dir_list_add_env t_sub la) p_sub\n                              (ifz_var_env (XPerm (SVar p)) (comp_var_env (lift_var_env r_x1 (SVar p)) (lift_var_env r_x2 (SVar p)))))\n                            r_ex)\n                          r_x \\<and>\n                         leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub la) p_sub (comp_var_env r_m1 r_m2))) r_ex \\<and>\n                         dir_subst_type (dir_list_add_env t_sub la) p_sub t1a t1 \\<and>\n                         dir_subst_type (dir_list_add_env t_sub la) p_sub t2a t2 \\<and>\n                         r = p_sub p \\<and>\n                         (\\<exists>tau_x. dir_subst_type (dir_list_add_env t_sub la) p_sub t1a tau_x \\<and> aff_leq (req_type tau_x) (p_sub p)) \\<and>\n                         (\\<exists>tau_x. dir_subst_type (dir_list_add_env t_sub la) p_sub t2a tau_x \\<and> aff_leq (req_type tau_x) (p_sub p)) \\<and>\n                         dir_sol_sat (dir_list_add_env t_sub la) p_sub\n                          (disj_crn (lift_var_env r_x1 (SVar p)) (lift_var_env r_x2 (SVar p)) d @\n                           semi_disj_crn r_m2 r_x1 d @ semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2))\"    \n    (* defining new t_sub *)\n  apply (rule_tac x=\"la @ l\" in exI)\n  apply (auto)\n     apply (rule_tac append_tsub_dom)\n      apply (rule_tac ds=\"ds\" in list_add_tsub_dom)\n        apply (auto)\n       apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n        apply (auto)\n       apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n        apply (auto)\n      apply (cut_tac t_sub=\"t_sub\" and l=\"l\" and ds=\"ds2\" in list_add_dls)\n       apply (auto)\n      apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n       apply (auto)\n     apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and l=\"la\" and ds=\"ds3\" in list_add_dls)\n      apply (auto)\n    apply (rule_tac ds=\"ds\" and ds'=\"ds2\" in append_fresh_list2)\n       apply (auto)\n    apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n     apply (auto)\n   apply (simp add: dir_list_append_eq)\n    (* P* inequality 1 *)\n  apply (case_tac \"\\<not> leq_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_s1) r_s\")\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and l=\"la\" and p_sub=\"add_use_env (comp_use_env p_sub p_suba) p r\"\n                and r_sv=\"r_s1\" and ds=\"ds2\" in dir_list_add_cancel_use_env)\n     apply (auto)\n    apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and e=\"e1\" and ds'=\"ds2\" in infer_tvar_range)\n      apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and e=\"e1\" and ds'=\"ds2\" in infer_s_sub_range)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and p_sub=\"comp_use_env p_sub p_suba\" and r_xv=\"r_s1\" and ds=\"set_diff ds2 ds\" and x=\"p\" and r=\"r\" in add_psub_use_env)\n     apply (auto)\n    apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n     apply (auto)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and ?p_sub1.0=\"p_sub\" and ?p_sub2.0=\"p_suba\" and r_xv=\"r_s1\" and ds=\"set_diff ds2 ds\" in comp_psub_use_env1)\n      apply (auto)\n   apply (simp add: set_diff_def)\n    (* P* inequality 2 *)\n  apply (case_tac \"\\<not> leq_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_s2) (diff_use_env r_s r_exaa)\")\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and e=\"e2\" and ds'=\"ds3\" in infer_s_sub_range)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and p_sub=\"comp_use_env p_sub p_suba\" and r_xv=\"r_s2\" and ds=\"set_diff ds3 ds2\" and x=\"p\" and r=\"r\" in add_psub_use_env)\n     apply (auto)\n    apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n     apply (auto)\n    apply (simp add: set_diff_def)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and ?p_sub1.0=\"p_suba\" and ?p_sub2.0=\"p_sub\" and r_xv=\"r_s2\" and ds=\"set_diff ds3 ds2\" in comp_psub_use_env2)\n      apply (auto)\n   apply (simp add: set_diff_def)   \n    (* X* inequality 1 *)\n  apply (case_tac \"\\<not> leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_x1) r_exaa) rx1\")\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and l=\"la\" and p_sub=\"add_use_env (comp_use_env p_sub p_suba) p r\"\n                and r_sv=\"r_x1\" and ds=\"ds2\" in dir_list_add_cancel_use_env)\n     apply (auto)\n    apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and e=\"e1\" and ds'=\"ds2\" in infer_tvar_range)\n      apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and e=\"e1\" and ds'=\"ds2\" in infer_s_sub_range)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and p_sub=\"comp_use_env p_sub p_suba\" and r_xv=\"r_x1\" and ds=\"set_diff ds2 ds\" and x=\"p\" and r=\"r\" in add_psub_use_env)\n     apply (auto)\n    apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n     apply (auto)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and ?p_sub1.0=\"p_sub\" and ?p_sub2.0=\"p_suba\" and r_xv=\"r_x1\" and ds=\"set_diff ds2 ds\" in comp_psub_use_env1)\n      apply (auto)\n   apply (simp add: set_diff_def) \n    (* X* inequality 2 *)\n  apply (case_tac \"\\<not> leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_x2) r_exb) rx2\")\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and e=\"e2\" and ds'=\"ds3\" in infer_s_sub_range)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and p_sub=\"comp_use_env p_sub p_suba\" and r_xv=\"r_x2\" and ds=\"set_diff ds3 ds2\" and x=\"p\" and r=\"r\" in add_psub_use_env)\n     apply (auto)\n    apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n     apply (auto)\n    apply (simp add: set_diff_def)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and ?p_sub1.0=\"p_suba\" and ?p_sub2.0=\"p_sub\" and r_xv=\"r_x2\" and ds=\"set_diff ds3 ds2\" in comp_psub_use_env2)\n      apply (auto)\n   apply (simp add: set_diff_def)\n    (* M* inequality 1 *)\n  apply (case_tac \"\\<not> leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_m1)) r_exaa\")\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and l=\"la\" and p_sub=\"add_use_env (comp_use_env p_sub p_suba) p r\"\n                and r_sv=\"r_m1\" and ds=\"ds2\" in dir_list_add_cancel_use_env)\n     apply (auto)\n    apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and e=\"e1\" and ds'=\"ds2\" in infer_m_tvar_range)\n      apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and e=\"e1\" and ds'=\"ds2\" in infer_m_sub_range)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and p_sub=\"comp_use_env p_sub p_suba\" and r_xv=\"r_m1\" and ds=\"set_diff ds2 ds\" and x=\"p\" and r=\"r\" in add_psub_use_env)\n     apply (auto)\n    apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n     apply (auto)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and ?p_sub1.0=\"p_sub\" and ?p_sub2.0=\"p_suba\" and r_xv=\"r_m1\" and ds=\"set_diff ds2 ds\" in comp_psub_use_env1)\n      apply (auto)\n   apply (simp add: set_diff_def)\n    (* M* inequality 2 *)\n  apply (case_tac \"\\<not> leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_m2)) r_exb\")\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and e=\"e2\" and ds'=\"ds3\" in infer_m_sub_range)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and p_sub=\"comp_use_env p_sub p_suba\" and r_xv=\"r_m2\" and ds=\"set_diff ds3 ds2\" and x=\"p\" and r=\"r\" in add_psub_use_env)\n     apply (auto)\n    apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n     apply (auto)\n    apply (simp add: set_diff_def)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and ?p_sub1.0=\"p_suba\" and ?p_sub2.0=\"p_sub\" and r_xv=\"r_m2\" and ds=\"set_diff ds3 ds2\" in comp_psub_use_env2)\n      apply (auto)\n   apply (simp add: set_diff_def)\n    (* - prelim: (t_sub, p_sub)(t1a) = t1 *)\n  apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and l=\"la\" and p_sub=\"add_use_env (comp_use_env p_sub p_suba) p r\" and\n      tau_v=\"t1a\" and tau=\"t1\" in dir_list_add_subst_type)\n    apply (rule_tac add_dir_subst_type)\n     apply (rule_tac ds=\"set_diff ds2 ds\" in comp_dir_subst_type1)\n        apply (simp)\n       apply (rule_tac infer_pvar_type)\n        apply (auto)\n     apply (simp add: set_diff_def)\n    apply (cut_tac tau_v=\"t1a\" and ds'=\"ds2\" and ds=\"ds\" in infer_pvar_type)\n      apply (auto)\n    apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n     apply (simp)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (cut_tac x=\"x\" and l=\"la\" in dom_list_contain)\n    apply (simp)\n   apply (cut_tac tau_v=\"t1a\" and ds'=\"ds2\" and ds=\"ds\" in infer_tvar_type)\n     apply (auto)\n   apply (simp add: fresh_list_def)\n   apply (auto)\n    (* - prelim: (t_sub, p_sub)(t2a) = t2 *)\n  apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and p_sub=\"comp_use_env p_sub p_suba\" and p=\"p\" and r=\"r\" and\n      tau_v=\"t2a\" and tau=\"t2\" in add_dir_subst_type)\n    apply (rule_tac ds=\"set_diff ds3 ds2\" in comp_dir_subst_type2)\n       apply (simp)\n      apply (rule_tac infer_pvar_type)\n       apply (auto)\n     apply (rule_tac ds=\"ds\" in subset_sub_range)\n      apply (simp)\n     apply (rule_tac infer_x_subset)\n     apply (simp)\n    apply (simp add: set_diff_def)\n   apply (cut_tac tau_v=\"t2a\" and ds'=\"ds3\" and ds=\"ds2\" in infer_pvar_type)\n     apply (auto)\n    apply (rule_tac ds=\"ds\" in subset_sub_range)\n     apply (simp)\n    apply (rule_tac infer_x_subset)\n    apply (simp)\n   apply (simp add: set_diff_def)\n   apply (auto)\n    (* defining new p_sub *)\n  apply (rule_tac x=\"add_use_env (comp_use_env p_sub p_suba) p r\" in exI)\n  apply (auto)\n    (* - psub domain containment *)\n           apply (rule_tac add_psub_dom)\n            apply (rule_tac comp_psub_dom)\n             apply (rule_tac ds=\"set_diff ds2 ds\" in subset_psub_dom)\n              apply (simp)\n             apply (rule_tac set_diff_subset)\n              apply (auto)\n             apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n              apply (auto)\n            apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_psub_dom)\n             apply (simp)\n            apply (rule_tac set_diff_subset)\n             apply (auto)\n            apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n             apply (auto)\n           apply (simp add: set_diff_def)\n           apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n            apply (auto)\n           apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n            apply (auto)\n    (* - p_sub(r_sv) \\<le> r_s *)\n          apply (rule_tac dist_comp_leq_var_env)\n           apply (simp add: dir_list_append_eq)\n           apply (rule_tac dist_comp_leq_var_env)\n            apply (auto)\n           apply (rule_tac t=\"dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) (lift_var_env r_x1 (SVar p))\"\n            and s=\"lift_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_x1)\n                  (sol_subst_perm (add_use_env (comp_use_env p_sub p_suba) p r) (SVar p))\" in subst)\n            apply (rule_tac lift_sol_subst_penv)\n           apply (auto)\n           apply (case_tac \"add_use_env (comp_use_env p_sub p_suba) p r p \\<noteq> r\")\n            apply (simp add: add_use_env_def)\n           apply (auto)\n           apply (rule_tac r_ex=\"r_exaa\" in diff_leq_use_env_rev)\n            apply (simp add: lift_diff_use_env)\n            apply (rule_tac r_sb=\"lift_use_env rx1 r\" in trans_leq_use_env)\n             apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n              apply (simp_all)\n           apply (rule_tac dist_lift_leq_use_env)\n           apply (simp)\n    (* > part 2. *)\n          apply (simp add: dir_list_append_eq)\n          apply (rule_tac dist_comp_leq_var_env)\n           apply (rule_tac r_sb=\"diff_use_env r_s r_exaa\" in trans_leq_use_env)\n            apply (rule_tac self_diff_leq_use_env)\n           apply (simp)\n          apply (rule_tac t=\"dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) (lift_var_env r_x2 (SVar p))\"\n            and s=\"lift_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_x2)\n                  (sol_subst_perm (add_use_env (comp_use_env p_sub p_suba) p r) (SVar p))\" in subst)\n           apply (rule_tac lift_sol_subst_penv)\n          apply (rule_tac r_ex=\"r_exb\" in diff_leq_use_env_rev)\n           apply (simp add: lift_diff_use_env)\n           apply (rule_tac r_sb=\"lift_use_env rx2 r\" in trans_leq_use_env)\n            apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n             apply (simp_all)\n           apply (case_tac \"add_use_env (comp_use_env p_sub p_suba) p r p \\<noteq> r\")\n            apply (simp add: add_use_env_def)\n           apply (auto)\n           apply (rule_tac dist_lift_leq_use_env)\n           apply (simp)\n          apply (rule_tac r_sb=\"diff_use_env r_s r_exaa\" in trans_leq_use_env)\n           apply (rule_tac self_diff_leq_use_env)\n          apply (simp)\n    (* - p_sub(r_xv) \\<le> r_x. primitive case *)\n        apply (case_tac \"r = NoPerm\")\n         apply (cut_tac t_sub=\"dir_list_add_env t_sub (la @ l)\" and p_sub=\"add_use_env (comp_use_env p_sub p_suba) p r\" and p=\"p\" and\n          r_sv=\"comp_var_env (lift_var_env r_x1 (SVar p)) (lift_var_env r_x2 (SVar p))\" in ifz_sol_subst_penv)\n          apply (auto)\n          apply (simp add: add_use_env_def)\n         apply (rule_tac diff_leq_use_env)\n         apply (rule_tac leq_empty_use_env)\n        apply (simp add: pair_req_def)\n    (* > non-primitive case *)\n         apply (simp add: dir_list_append_eq)\n         apply (case_tac \"as_aff r = Prim\")\n          apply (case_tac r)\n            apply (auto)\n        apply (rule_tac r_sb=\"diff_use_env\n              (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r)\n                (comp_var_env (lift_var_env r_x1 (SVar p)) (lift_var_env r_x2 (SVar p)))) r_ex\" in trans_leq_use_env)\n         apply (simp add: comp_sol_subst_penv)\n         apply (rule_tac lhs_dist_dcl_use_env)\n         apply (rule_tac r_sb=\"diff_use_env (comp_use_env (lift_use_env rx1 r) (lift_use_env rx2 r)) r_exa\" in trans_leq_use_env)\n          apply (simp)\n         apply (rule_tac dist_comp_leq_use_env)\n          apply (rule_tac t=\"dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) (lift_var_env r_x1 (SVar p))\"\n          and s=\"lift_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_x1)\n            (sol_subst_perm (add_use_env (comp_use_env p_sub p_suba) p r) (SVar p))\" in subst)\n           apply (rule_tac lift_sol_subst_penv)\n          apply (rule_tac r_sb=\"diff_use_env (lift_use_env rx1 r) r_exa\" in trans_leq_use_env)\n           apply (rule_tac dist_diff_leq_use_env)\n           apply (rule_tac self_comp_leq_use_env1)\n          apply (simp add: lift_diff_use_env)\n          apply (case_tac \"add_use_env (comp_use_env p_sub p_suba) p r p \\<noteq> r\")\n           apply (simp add: add_use_env_def)\n          apply (simp)\n          apply (rule_tac dist_lift_leq_use_env)\n           apply (rule_tac r_s=\"r_s\" in crush_leq_use_env)\n             apply (rule_tac r_sb=\"diff_use_env r_s3 r_exa\" in trans_leq_use_env)\n              apply (rule_tac dist_diff_leq_use_env)\n              apply (simp_all)\n             apply (rule_tac r_sb=\"lift_use_env rx1 r\" in trans_leq_use_env)\n              apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n               apply (simp_all)\n            apply (rule_tac self_lift_leq_use_env)\n            apply (rule_tac r_sb=\"diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la)\n              (add_use_env (comp_use_env p_sub p_suba) p r) r_x1) r_exaa\" in trans_leq_use_env)\n            apply (simp)\n           apply (rule_tac r_s=\"r_s\" in crush_leq_use_env)\n             apply (rule_tac r_sb=\"super_norm_use_env r_s r_s3\" in trans_leq_use_env)\n              apply (simp)\n              apply (rule_tac dist_diff_leq_use_env_gen)\n               apply (rule_tac id_leq_use_env)\n              apply (rule_tac self_comp_leq_use_env1)\n             apply (rule_tac rhs_snorm_leq_use_env)\n              apply (rule_tac self_diff_leq_use_env)\n             apply (rule_tac r_sb=\"diff_use_env r_s3 r_exa\" in trans_leq_use_env)\n              apply (rule_tac self_diff_leq_use_env)\n             apply (simp)\n            apply (rule_tac r_sb=\"dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la)\n              (add_use_env (comp_use_env p_sub p_suba) p r) r_s1\" in trans_leq_use_env)\n             apply (simp)\n            apply (rule_tac infer_x_leq_use_env)\n            apply (auto)\n           apply (rule_tac self_diff_leq_use_env)\n    (* > transformation proving removal of extra substitutions is sound *)\n    (* > part 2. *)\n         apply (rule_tac t=\"dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) (lift_var_env r_x2 (SVar p))\"\n          and s=\"lift_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_x2)\n            (sol_subst_perm (add_use_env (comp_use_env p_sub p_suba) p r) (SVar p))\" in subst)\n          apply (rule_tac lift_sol_subst_penv)\n         apply (rule_tac rhs_dist_dcl_use_env)\n         apply (rule_tac comp_leq_use_env2)\n         apply (simp add: lift_diff_use_env)\n         apply (case_tac \"add_use_env (comp_use_env p_sub p_suba) p r p \\<noteq> r\")\n          apply (simp add: add_use_env_def)\n         apply (simp)\n         apply (rule_tac dist_lift_leq_use_env)\n          apply (rule_tac r_s=\"r_s\" in crush_leq_use_env)\n            apply (rule_tac r_sb=\"diff_use_env r_s3 r_exa\" in trans_leq_use_env)\n             apply (rule_tac dist_diff_leq_use_env)\n             apply (simp_all)\n            apply (rule_tac r_sb=\"lift_use_env rx2 r\" in trans_leq_use_env)\n             apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n              apply (simp_all)\n           apply (rule_tac self_lift_leq_use_env)\n          apply (rule_tac r_sb=\"diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_x2)\n              r_exb\" in trans_leq_use_env)\n           apply (simp)\n          apply (rule_tac r_s=\"r_s\" in crush_leq_use_env)\n            apply (rule_tac r_sb=\"super_norm_use_env r_s r_s3\" in trans_leq_use_env)\n             apply (simp)\n             apply (rule_tac dist_diff_leq_use_env_gen)\n              apply (rule_tac id_leq_use_env)\n             apply (rule_tac self_comp_leq_use_env2)\n            apply (rule_tac rhs_snorm_leq_use_env)\n             apply (rule_tac self_diff_leq_use_env)\n            apply (rule_tac r_sb=\"diff_use_env r_s3 r_exa\" in trans_leq_use_env)\n             apply (rule_tac self_diff_leq_use_env)\n            apply (simp)\n           apply (rule_tac r_sb=\"dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_s2\" in trans_leq_use_env)\n            apply (rule_tac r_sb=\"diff_use_env r_s r_exaa\" in trans_leq_use_env)\n             apply (rule_tac self_diff_leq_use_env)\n            apply (simp)\n           apply (rule_tac infer_x_leq_use_env)\n           apply (auto)\n          apply (rule_tac self_diff_leq_use_env)\n    (* > finishing the case *)\n        apply (rule_tac dist_diff_leq_use_env)\n        apply (rule_tac if_zero_leq_var_env)\n         apply (rule_tac id_leq_use_env)\n    (* - (t_sub, p_sub)( M1* ) \\<le> EX. r_s - r_ex <= r_s3 <=  r_s1 - (r_exaa + r_exb) *)\n        apply (rule_tac r_sb=\"cut_use_env (comp_use_env r_exaa r_exb)\" in trans_leq_use_env)\n         apply (rule_tac r_s=\"r_s\" in dist_diff_leq_use_env_rev)\n          apply (rule_tac dist_comp_leq_use_env)\n           apply (simp)\n          apply (rule_tac r_sb=\"diff_use_env r_s r_exaa\" in trans_leq_use_env)\n           apply (rule_tac self_diff_leq_use_env)\n          apply (simp)\n         apply (rule_tac r_sb=\"diff_use_env r_s3 r_exa\" in trans_leq_use_env)\n          apply (rule_tac diff_leq_use_env)\n          apply (rule_tac r_sb=\"super_norm_use_env r_s r_s3\" in trans_leq_use_env)\n           apply (simp)\n           apply (rule_tac id_leq_use_env)\n          apply (rule_tac rhs_snorm_leq_use_env)\n           apply (simp)\n          apply (rule_tac id_leq_use_env)\n         apply (simp)\n        apply (rule_tac rhs_cut_leq_use_env)\n        apply (simp add: comp_sol_subst_penv)\n        apply (simp add: dist_cut_comp_use_env)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (rule_tac comp_leq_use_env1)\n         apply (simp add: dir_list_append_eq)\n        apply (rule_tac comp_leq_use_env2)\n        apply (simp add: dir_list_append_eq)\n    (* - type equivalences *)\n       apply (simp add: dir_list_append_eq)\n      apply (simp add: dir_list_append_eq)\n    (* - pair permission *)\n     apply (simp add: add_use_env_def)\n    (* - further type equivalence *)\n    apply (rule_tac x=\"t1\" in exI)\n    apply (simp add: dir_list_append_eq)\n    apply (simp add: add_use_env_def)\n    apply (case_tac \"req_type t2\")\n      apply (auto)\n      apply (case_tac \"req_type t1\")\n        apply (auto)\n      apply (case_tac r)\n        apply (auto)\n     apply (case_tac \"req_type t1\")\n       apply (auto)\n    apply (case_tac \"req_type t1\")\n      apply (simp_all)\n   apply (rule_tac x=\"t2\" in exI)\n   apply (simp add: dir_list_append_eq)\n   apply (simp add: add_use_env_def)\n   apply (case_tac \"req_type t1\")\n     apply (auto)\n     apply (case_tac \"req_type t2\")\n       apply (simp_all)\n     apply (case_tac r)\n       apply (simp_all)\n    apply (case_tac \"req_type t2\")\n      apply (simp_all)\n   apply (case_tac \"req_type t2\")\n     apply (simp_all)\n      (* - solution satisfiability. disjointness *)\n  apply (rule_tac sol_sat_split)\n   apply (rule_tac sol_sat_disj)\n   apply (simp add: dir_list_append_eq)\n   apply (rule_tac r_s=\"comp_use_env (lift_use_env rx1 r) (cut_use_env r_exaa)\" in disj_leq_use_env1)\n    apply (rule_tac r_s=\"comp_use_env (lift_use_env rx2 r) (cut_use_env r_exb)\" in disj_leq_use_env2)\n     apply (rule_tac disj_comp_use_env1)\n      apply (rule_tac disj_comp_use_env2)\n       apply (simp)\n      apply (rule_tac cut_disj_use_env)\n      apply (rule_tac r_s=\"diff_use_env r_s r_exb\" in mini_disj_leq_use_env2)\n       apply (rule_tac mini_disj_diff_use_env)\n      apply (rule_tac r_sb=\"super_norm_use_env r_s r_s3\" in trans_leq_use_env)\n       apply (simp)\n       apply (rule_tac dist_diff_leq_use_env_gen)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac self_comp_leq_use_env2)\n      apply (rule_tac rhs_snorm_leq_use_env2)\n       apply (simp_all)\n     apply (rule_tac disj_comp_use_env2)\n      apply (rule_tac comm_disj_use_env)\n      apply (rule_tac cut_disj_use_env)\n      apply (rule_tac r_s=\"diff_use_env r_s r_exaa\" in mini_disj_leq_use_env2)\n       apply (rule_tac mini_disj_diff_use_env)\n      apply (rule_tac r_sb=\"super_norm_use_env r_s r_s3\" in trans_leq_use_env)\n       apply (simp)\n       apply (rule_tac dist_diff_leq_use_env_gen)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac self_comp_leq_use_env1)\n      apply (rule_tac rhs_snorm_leq_use_env2)\n       apply (simp_all)\n     apply (rule_tac comm_disj_use_env)\n     apply (rule_tac cut_disj_use_env)\n     apply (rule_tac r_s=\"diff_use_env r_s r_exaa\" in mini_disj_leq_use_env2)\n      apply (rule_tac mini_disj_diff_use_env)\n     apply (rule_tac cut_leq_use_env)\n     apply (simp)\n    (* > proving the inequality for r_x2 vs rx2 *)\n    apply (rule_tac st_diff_comp_leq_use_env)\n    apply (rule_tac r_sb=\"diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la)\n      (add_use_env (comp_use_env p_sub p_suba) p r) (lift_var_env r_x2 (SVar p))) r_exb\" in trans_leq_use_env)\n     apply (rule_tac s=\"lift_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_x2)\n         (add_use_env (comp_use_env p_sub p_suba) p r p)\" and\n      t=\"dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) (lift_var_env r_x2 (SVar p))\" in subst)\n      apply (simp add: lift_sol_subst_penvx)\n     apply (simp add: lift_diff_use_env)\n     apply (rule_tac r_sb=\"lift_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la)\n      (add_use_env (comp_use_env p_sub p_suba) p r) r_x2) r_exb) r\" in trans_leq_use_env)\n      apply (rule_tac dist_lift_leq_use_env)\n      apply (simp)(*\n      apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and e=\"e2\" and ds'=\"ds3\" in infer_s_sub_range)\n       apply (auto)\n      apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and p_sub=\"comp_use_env p_sub p_suba\" and\n        r_xv=\"r_x2\" and ds=\"set_diff ds3 ds2\" and x=\"p\" and r=\"r\" in add_psub_use_env)\n           apply (auto)\n       apply (simp add: set_diff_def)\n        apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and ?p_sub1.0=\"p_suba\" and ?p_sub2.0=\"p_sub\" and\n          r_xv=\"r_x2\" and ds=\"set_diff ds3 ds2\" and ds'=\"set_diff ds2 ds\" in comp_psub_use_env2)\n         apply (simp_all)\n       apply (simp add: set_diff_def)\n       apply (auto)*)\n     apply (rule_tac dist_lift_leq_use_env_gen)\n     apply (simp add: add_use_env_def)\n     apply (case_tac r)\n       apply (simp_all)\n    apply (rule_tac dist_diff_leq_use_env_cut)\n     apply (rule_tac id_leq_use_env)\n    apply (rule_tac id_leq_use_env)\n    (* > proving the inequality for r_x1 vs rx1 *)\n    apply (rule_tac st_diff_comp_leq_use_env)\n   apply (rule_tac r_sb=\"diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la)\n      (add_use_env (comp_use_env p_sub p_suba) p r) (lift_var_env r_x1 (SVar p))) r_exaa\" in trans_leq_use_env)\n    apply (rule_tac t=\"dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) (lift_var_env r_x1 (SVar p))\"\n      and s=\"lift_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) (add_use_env (comp_use_env p_sub p_suba) p r) r_x1)\n         (add_use_env (comp_use_env p_sub p_suba) p r p)\" in subst)\n     apply (simp add: lift_sol_subst_penvx)\n    apply (simp add: lift_diff_use_env)\n    apply (rule_tac r_sb=\"lift_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la)\n      (add_use_env (comp_use_env p_sub p_suba) p r) r_x1) r_exaa) r\" in trans_leq_use_env)\n     apply (rule_tac dist_lift_leq_use_env)\n     apply (simp)\n    apply (rule_tac dist_lift_leq_use_env_gen)\n    apply (simp add: add_use_env_def)\n    apply (case_tac r)\n      apply (simp_all)\n   apply (rule_tac dist_diff_leq_use_env_cut)\n    apply (rule_tac id_leq_use_env)\n   apply (rule_tac id_leq_use_env)\n    (* > semi-disjointness 1 *)\n  apply (simp add: dir_list_append_eq)\n  apply (rule_tac sol_sat_split)\n  apply (rule_tac sol_sat_mini_disj)\n   apply (rule_tac cut_mini_disj_use_env)\n   apply (rule_tac r_s=\"r_exb\" in mini_disj_leq_use_env1)\n    apply (rule_tac r_s=\"diff_use_env r_s r_exb\" in mini_disj_leq_use_env2)\n     apply (rule_tac mini_disj_diff_use_env)\n    apply (rule_tac r_sb=\"comp_use_env (diff_use_env r_s r_exb) (cut_use_env r_exaa)\" in trans_leq_use_env)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac id_leq_use_env)\n     apply (rule_tac swap_diff_cut_leq_use_env)\n      apply (simp_all)\n   apply (rule_tac st_diff_comp_leq_use_env)\n   apply (rule_tac r_sb=\"diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la)\n      (add_use_env (comp_use_env p_sub p_suba) p r) r_x1) r_exaa\" in trans_leq_use_env)\n    apply (rule_tac r_sb=\"lift_use_env rx1 r\" in trans_leq_use_env)\n     apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n      apply (rule_tac mini_disj_diff_leq_use_env2)\n       apply (simp)\n      apply (rule_tac r_s=\"diff_use_env r_s r_exb\" in mini_disj_leq_use_env2)\n       apply (rule_tac mini_disj_diff_use_env)\n      apply (rule_tac r_sb=\"super_norm_use_env r_s r_s3\" in trans_leq_use_env)\n       apply (simp)\n       apply (rule_tac dist_diff_leq_use_env_gen)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac self_comp_leq_use_env2)\n      apply (rule_tac rhs_snorm_leq_use_env2)\n       apply (rule_tac id_leq_use_env)\n      apply (simp_all)\n    apply (rule_tac lift_leq_use_env)\n    apply (simp)\n   apply (rule_tac dist_diff_leq_use_env_cut)\n    apply (rule_tac id_leq_use_env)\n   apply (rule_tac id_leq_use_env)\n    (* > semi-disjointness 2 *)\n  apply (rule_tac sol_sat_split)\n   apply (rule_tac sol_sat_mini_disj)\n   apply (rule_tac cut_mini_disj_use_env)\n   apply (rule_tac r_s=\"r_exaa\" in mini_disj_leq_use_env1)\n    apply (rule_tac r_s=\"diff_use_env r_s r_exaa\" in mini_disj_leq_use_env2)\n     apply (rule_tac mini_disj_diff_use_env)\n    apply (simp_all)\n    (* > constraint list 1 correctness *)\n  apply (rule_tac sol_sat_split)\n   apply (cut_tac c_list=\"cl1\" and ds=\"ds\" and ds'=\"ds2\" in infer_tvar_crn_list)\n     apply (auto)\n   apply (cut_tac c_list=\"cl1\" and ds=\"ds\" and ds'=\"ds2\" in infer_pvar_crn_list)\n     apply (auto)\n   apply (rule_tac dir_list_add_sol_sat)\n    apply (rule_tac add_psub_sol_sat)\n     apply (rule_tac ds=\"set_diff ds2 ds\" in comp_psub_sol_sat1)\n        apply (simp_all)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (case_tac \"p \\<in> ds2\")\n     apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n      apply (auto)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (cut_tac x=\"x\" and l=\"la\" in dom_list_set_contain)\n    apply (auto)\n   apply (simp add: fresh_list_def)\n   apply (auto)\n    (* > constraint list 2 correctness *)\n  apply (cut_tac c_list=\"cl2\" and ds=\"ds2\" and ds'=\"ds3\" in infer_pvar_crn_list)\n    apply (auto)\n   apply (rule_tac ds=\"ds\" in subset_sub_range)\n    apply (auto)\n   apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n    apply (auto)\n  apply (rule_tac add_psub_sol_sat)\n   apply (rule_tac ds=\"set_diff ds3 ds2\" in comp_psub_sol_sat2)\n      apply (simp_all)\n   apply (simp add: set_diff_def)\n   apply (auto)\n  apply (case_tac \"p \\<in> ds2\")\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)\n  apply (simp add: set_diff_def)\n  apply (auto)\n  done\n\n    \nlemma ivr_pair_case: \"\\<lbrakk>\\<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.\n           \\<lbrakk>well_typed env r_s e1 tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e1 tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;\n            sub_range env_v ds; tsub_dom t_sub ds\\<rbrakk>\n           \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \\<and>\n                   fresh_list ds (dom_list l) \\<and>\n                   dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n                   (\\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \\<and>\n                            leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \\<and>\n                            leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \\<and>\n                            leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \\<and>\n                            dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \\<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);\n        \\<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.\n           \\<lbrakk>well_typed env r_s e2 tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e2 tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;\n            sub_range env_v ds; tsub_dom t_sub ds\\<rbrakk>\n           \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \\<and>\n                   fresh_list ds (dom_list l) \\<and>\n                   dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n                   (\\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \\<and>\n                            leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \\<and>\n                            leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \\<and>\n                            leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \\<and>\n                            dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \\<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);\n        spec_env env_v env t_sub; sub_range env_v ds; tsub_dom t_sub ds; infer_type env_v ds e1 t1a r_s1 r_x1 r_m1 cl1 ds2; well_typed env r_s e1 t1 r_s2a rx1;\n        infer_type env_v ds2 e2 t2a r_s2 r_x2 r_m2 cl2 ds3; well_typed env r_s2a e2 t2 r_s3 rx2; leq_use_env (lift_use_env rx1 r) r_s3;\n        leq_use_env (lift_use_env rx2 r) r_s3; aff_leq (max_aff (req_type t1) (req_type t2)) r; disj_use_env (lift_use_env rx1 r) (lift_use_env rx2 r);\n        finite_dom (comp_var_env (comp_var_env r_s1 (lift_var_env r_x1 (SVar p))) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))) d;\n        leq_use_env (diff_use_env r_s r_ex) (diff_use_env r_s3 r_exa); leq_use_env r_x (diff_use_env r_s r_ex); p \\<notin> ds3; leq_use_env r_exa r_s;\n        leq_use_env (pair_req (comp_use_env (lift_use_env rx1 r) (lift_use_env rx2 r)) r_exa (PairTy t1 t2 r)) r_x\\<rbrakk>\n       \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) (insert p ds3) \\<and>\n               fresh_list ds (dom_list l) \\<and>\n               dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n               (\\<exists>p_sub. psub_dom p_sub (set_diff (insert p ds3) ds) \\<and>\n                        leq_use_env\n                         (dir_subst_penv (dir_list_add_env t_sub l) p_sub\n                           (comp_var_env (comp_var_env r_s1 (lift_var_env r_x1 (SVar p))) (comp_var_env r_s2 (lift_var_env r_x2 (SVar p)))))\n                         r_s \\<and>\n                        leq_use_env\n                         (diff_use_env\n                           (dir_subst_penv (dir_list_add_env t_sub l) p_sub\n                             (ifz_var_env (XPerm (SVar p)) (comp_var_env (lift_var_env r_x1 (SVar p)) (lift_var_env r_x2 (SVar p)))))\n                           r_ex)\n                         r_x \\<and>\n                        leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (comp_var_env r_m1 r_m2))) r_ex \\<and>\n                        dir_subst_type (dir_list_add_env t_sub l) p_sub t1a t1 \\<and>\n                        dir_subst_type (dir_list_add_env t_sub l) p_sub t2a t2 \\<and>\n                        r = p_sub p \\<and>\n                        (\\<exists>tau_x. dir_subst_type (dir_list_add_env t_sub l) p_sub t1a tau_x \\<and> aff_leq (req_type tau_x) (p_sub p)) \\<and>\n                        (\\<exists>tau_x. dir_subst_type (dir_list_add_env t_sub l) p_sub t2a tau_x \\<and> aff_leq (req_type tau_x) (p_sub p)) \\<and>\n                        dir_sol_sat (dir_list_add_env t_sub l) p_sub\n                         (disj_crn (lift_var_env r_x1 (SVar p)) (lift_var_env r_x2 (SVar p)) d @\n                          semi_disj_crn r_m2 r_x1 d @ semi_disj_crn r_m1 r_s2 d @ cl1 @ cl2))\"\n  apply (cut_tac env=\"env\" and ?e1.0=\"e1\" and ?e2.0=\"e2\" in ivr_induct_format)\n    apply (auto)\n  apply (cut_tac e=\"e1\" and env_v=\"env_v\" and t_sub=\"t_sub\" and ds=\"ds\" in ivrpc_coerce)\n        apply (auto)\n  apply (cut_tac e=\"e2\" and env_v=\"env_v\" and t_sub=\"dir_list_add_env t_sub l\" and ds=\"ds2\" in ivrpc_coerce)\n        apply (auto)\n    apply (rule_tac self_spec_env)\n   apply (rule_tac ds=\"ds\" in subset_sub_range)\n    apply (simp)\n   apply (rule_tac infer_x_subset)\n   apply (auto)\n  apply (rule_tac env_v=\"env_v\" and r_s=\"r_s\" and ?r_s3.0=\"r_s3\" and ?e1.0=\"e1\" and ?e2.0=\"e2\" \n      and ?r_s1.0=\"r_s1\" and ?r_x1.0=\"r_x1\" and ?r_m1.0=\"r_m1\" and ?r_s2.0=\"r_s2\" and ?r_x2.0=\"r_x2\" and ?r_m2.0=\"r_m2\" in ivrpc_main)\n                      apply (auto)\n  apply (rule_tac r_sb=\"r_s2a\" in trans_leq_use_env)\n   apply (rule_tac well_typed_perm_leq)\n   apply (auto)\n  apply (rule_tac well_typed_perm_leq)\n  apply (auto)\n  done \n    \n\nlemma ivric_coerce: \"\\<lbrakk> \\<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.\n           \\<lbrakk>well_typed env r_s e tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;\n            sub_range env_v ds; tsub_dom t_sub ds\\<rbrakk>\n           \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \\<and>\n                   fresh_list ds (dom_list l) \\<and>\n                   dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n                   (\\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \\<and>\n                            leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \\<and>\n                            leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \\<and>\n                            leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \\<and>\n                            dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \\<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);\n    well_typed env r_s e tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;\n            sub_range env_v ds; tsub_dom t_sub ds \\<rbrakk> \\<Longrightarrow>\n  \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \\<and>\n                   fresh_list ds (dom_list l) \\<and>\n                   dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n                   (\\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \\<and>\n                            leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \\<and>\n                            leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \\<and>\n                            leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \\<and>\n                            dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \\<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list)\"    \n  apply (auto)\n  done\n  \nlemma subset_fresh_list: \"\\<lbrakk> ds \\<subseteq> ds'; fresh_list ds' l \\<rbrakk> \\<Longrightarrow> fresh_list ds l\"    \n  apply (simp add: fresh_list_def)\n  apply (auto)\n  done\n\nlemma ivric_main: \"\\<lbrakk> spec_env env_v (dir_subst_tenv (dir_list_add_env t_sub l) env_v) t_sub; sub_range env_v ds; tsub_dom t_sub ds;\n        well_typed (dir_subst_tenv (dir_list_add_env t_sub l) env_v) r_s e1 BoolTy r_s2 rx'; infer_type env_v ds e1 t1 r_s1 r_x1 r_m1 cl1 ds2;\n        well_typed (dir_subst_tenv (dir_list_add_env t_sub l) env_v) r_s2 e2 tau (diff_use_env r_s r_ex) rx1; infer_type env_v ds2 e2 t2 r_s2a r_x2 r_m2 cl2 ds3;\n        well_typed (dir_subst_tenv (dir_list_add_env t_sub l) env_v) r_s2 e3 tau (diff_use_env r_s r_ex) rx2; infer_type env_v ds3 e3 t3 r_s3 r_x3 r_m3 cl3 ds';\n        finite_dom (comp_var_env r_s1 (comp_var_env r_s2a r_s3)) d; super_norm_use_env r_s r_s2 = diff_use_env r_s r_exa; leq_use_env r_exa r_s;\n        tsub_dom (dir_list_add_env t_sub l) ds2; fresh_list ds (dom_list l); env = dir_subst_tenv (dir_list_add_env t_sub l) env_v;\n        psub_dom p_sub (set_diff ds2 ds); leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_s1) r_s;\n        leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_x1) r_exa) rx';\n        leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_m1)) r_exa; dir_subst_type (dir_list_add_env t_sub l) p_sub t1 BoolTy;\n        dir_sol_sat (dir_list_add_env t_sub l) p_sub cl1; tsub_dom (dir_list_add_env (dir_list_add_env t_sub l) la) ds3; fresh_list ds2 (dom_list la);\n        dir_subst_tenv (dir_list_add_env (dir_list_add_env t_sub l) la) env_v = dir_subst_tenv (dir_list_add_env t_sub l) env_v;\n        psub_dom p_suba (set_diff ds3 ds2); leq_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba r_s2a) r_s2;\n        leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba r_x2) r_ex) rx1;\n        leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba r_m2)) r_ex;\n        dir_subst_type (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba t2 tau; dir_sol_sat (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba cl2;\n        tsub_dom (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb) ds'; fresh_list ds3 (dom_list lb);\n        dir_subst_tenv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb) env_v = dir_subst_tenv (dir_list_add_env t_sub l) env_v;\n        psub_dom p_subb (set_diff ds' ds3); leq_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb) p_subb r_s3) r_s2;\n        leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb) p_subb r_x3) r_ex) rx2;\n        leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb) p_subb r_m3)) r_ex;\n        dir_subst_type (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb) p_subb t3 tau;\n        dir_sol_sat (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb) p_subb cl3\\<rbrakk>\n       \\<Longrightarrow> \\<exists>la. tsub_dom (dir_list_add_env t_sub la) ds' \\<and>\n                fresh_list ds (dom_list la) \\<and>\n                dir_subst_tenv (dir_list_add_env t_sub la) env_v = dir_subst_tenv (dir_list_add_env t_sub l) env_v \\<and>\n                (\\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \\<and>\n                         leq_use_env (dir_subst_penv (dir_list_add_env t_sub la) p_sub (comp_var_env r_s1 (comp_var_env r_s2a r_s3))) r_s \\<and>\n                         leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub la) p_sub (comp_var_env r_x2 r_x3)) r_ex) (comp_use_env rx1 rx2) \\<and>\n                         leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub la) p_sub (comp_var_env r_m1 (comp_var_env r_m2 r_m3)))) r_ex \\<and>\n                         dir_subst_type (dir_list_add_env t_sub la) p_sub t2 tau \\<and>\n                         dir_subst_type (dir_list_add_env t_sub la) p_sub t1 BoolTy \\<and>\n                         (\\<exists>tau_x. dir_subst_type (dir_list_add_env t_sub la) p_sub t2 tau_x \\<and> dir_subst_type (dir_list_add_env t_sub la) p_sub t3 tau_x) \\<and>\n                         dir_sol_sat (dir_list_add_env t_sub la) p_sub (semi_disj_crn r_m1 (comp_var_env r_s2a r_s3) d @ cl1 @ cl2 @ cl3))\"\n    (* P* inequality 1 *)\n  apply (case_tac \"\\<not> leq_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb)\n    (comp_use_env p_sub (comp_use_env p_suba p_subb)) r_s1) r_s\")\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and e=\"e1\" and ds'=\"ds2\" in infer_tvar_range)\n     apply (auto)\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and l=\"lb\" and p_sub=\"comp_use_env p_sub (comp_use_env p_suba p_subb)\"\n                and r_sv=\"r_s1\" and ds=\"ds2\" in dir_list_add_cancel_use_env)\n     apply (auto)\n    apply (rule_tac ds'=\"ds3\" in subset_fresh_list)\n     apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and l=\"la\" and p_sub=\"comp_use_env p_sub (comp_use_env p_suba p_subb)\"\n                and r_sv=\"r_s1\" and ds=\"ds2\" in dir_list_add_cancel_use_env)\n    apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and e=\"e1\" and ds'=\"ds2\" in infer_s_sub_range)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and ?p_sub1.0=\"p_sub\" and ?p_sub2.0=\"comp_use_env p_suba p_subb\"\n      and r_xv=\"r_s1\" and ds=\"set_diff ds2 ds\" and ds'=\"set_diff ds' ds2\" in comp_psub_use_env1)\n      apply (auto)\n    apply (rule_tac comp_psub_dom)\n     apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_psub_dom)\n      apply (simp)\n     apply (simp add: set_diff_def)\n    apply (auto)\n    apply (rule_tac ds=\"set_diff ds' ds3\" in subset_psub_dom)\n     apply (simp)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (simp add: set_diff_def)\n    (* P* inequality 2 *)\n  apply (case_tac \"\\<not> leq_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb)\n    (comp_use_env p_sub (comp_use_env p_suba p_subb)) r_s2a) r_s2\")\n   apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n     apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and e=\"e2\" and ds'=\"ds3\" in infer_tvar_range)\n     apply (auto)\n   apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and l=\"lb\" and p_sub=\"comp_use_env p_sub (comp_use_env p_suba p_subb)\"\n                and r_sv=\"r_s2a\" and ds=\"ds3\" in dir_list_add_cancel_use_env)\n     apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and e=\"e2\" and ds'=\"ds3\" in infer_s_sub_range)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and ?p_sub2.0=\"p_sub\" and ?p_sub1.0=\"comp_use_env p_suba p_subb\"\n      and r_xv=\"r_s2a\" and ds'=\"set_diff ds2 ds\" and ds=\"set_diff ds' ds2\" in comp_psub_use_env2)\n      apply (auto)\n     apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n      apply (simp)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (simp add: set_diff_def)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and ?p_sub1.0=\"p_suba\" and ?p_sub2.0=\"p_subb\"\n      and r_xv=\"r_s2a\" and ds=\"set_diff ds3 ds2\" and ds'=\"set_diff ds' ds3\" in comp_psub_use_env1)\n      apply (auto)\n   apply (simp add: set_diff_def)\n    (* P* inequality 3 *)\n  apply (case_tac \"\\<not> leq_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb)\n    (comp_use_env p_sub (comp_use_env p_suba p_subb)) r_s3) r_s2\")\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds3\" and e=\"e3\" and ds'=\"ds'\" in infer_s_sub_range)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb\" and ?p_sub2.0=\"p_sub\" and\n      ?p_sub1.0=\"comp_use_env p_suba p_subb\" and r_xv=\"r_s3\" and ds'=\"set_diff ds2 ds\" and ds=\"set_diff ds' ds2\" in comp_psub_use_env2)\n      apply (auto)\n     apply (rule_tac ds=\"set_diff ds' ds3\" in subset_pvar_range)\n      apply (simp)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (simp add: set_diff_def)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb\" and ?p_sub2.0=\"p_suba\" and ?p_sub1.0=\"p_subb\"\n      and r_xv=\"r_s3\" and ds'=\"set_diff ds3 ds2\" and ds=\"set_diff ds' ds3\" in comp_psub_use_env2)\n      apply (auto)\n   apply (simp add: set_diff_def)\n    (* X* inequality 2 *)\n  apply (case_tac \"\\<not> leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb)\n    (comp_use_env p_sub (comp_use_env p_suba p_subb)) r_x2) r_ex) rx1\")\n   apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n     apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and e=\"e2\" and ds'=\"ds3\" in infer_tvar_range)\n     apply (auto)\n   apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and l=\"lb\" and p_sub=\"comp_use_env p_sub (comp_use_env p_suba p_subb)\"\n                and r_sv=\"r_x2\" and ds=\"ds3\" in dir_list_add_cancel_use_env)\n     apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and e=\"e2\" and ds'=\"ds3\" in infer_s_sub_range)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and ?p_sub2.0=\"p_sub\" and ?p_sub1.0=\"comp_use_env p_suba p_subb\"\n      and r_xv=\"r_x2\" and ds'=\"set_diff ds2 ds\" and ds=\"set_diff ds' ds2\" in comp_psub_use_env2)\n      apply (auto)\n     apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n      apply (simp)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (simp add: set_diff_def)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and ?p_sub1.0=\"p_suba\" and ?p_sub2.0=\"p_subb\"\n      and r_xv=\"r_x2\" and ds=\"set_diff ds3 ds2\" and ds'=\"set_diff ds' ds3\" in comp_psub_use_env1)\n      apply (auto)\n   apply (simp add: set_diff_def)\n    (* X* inequality 3 *)\n  apply (case_tac \"\\<not> leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb)\n    (comp_use_env p_sub (comp_use_env p_suba p_subb)) r_x3) r_ex) rx2\")\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds3\" and e=\"e3\" and ds'=\"ds'\" in infer_s_sub_range)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb\" and ?p_sub2.0=\"p_sub\" and\n      ?p_sub1.0=\"comp_use_env p_suba p_subb\" and r_xv=\"r_x3\" and ds'=\"set_diff ds2 ds\" and ds=\"set_diff ds' ds2\" in comp_psub_use_env2)\n      apply (auto)\n     apply (rule_tac ds=\"set_diff ds' ds3\" in subset_pvar_range)\n      apply (simp)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (simp add: set_diff_def)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb\" and ?p_sub2.0=\"p_suba\" and ?p_sub1.0=\"p_subb\"\n      and r_xv=\"r_x3\" and ds'=\"set_diff ds3 ds2\" and ds=\"set_diff ds' ds3\" in comp_psub_use_env2)\n      apply (auto)\n   apply (simp add: set_diff_def)\n    (* M* inequality 1 *)\n  apply (case_tac \"\\<not> leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb)\n    (comp_use_env p_sub (comp_use_env p_suba p_subb)) r_m1)) r_exa\")\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and e=\"e1\" and ds'=\"ds2\" in infer_m_tvar_range)\n     apply (auto)\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and l=\"lb\" and p_sub=\"comp_use_env p_sub (comp_use_env p_suba p_subb)\"\n                and r_sv=\"r_m1\" and ds=\"ds2\" in dir_list_add_cancel_use_env)\n     apply (auto)\n    apply (rule_tac ds'=\"ds3\" in subset_fresh_list)\n     apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and l=\"la\" and p_sub=\"comp_use_env p_sub (comp_use_env p_suba p_subb)\"\n                and r_sv=\"r_m1\" and ds=\"ds2\" in dir_list_add_cancel_use_env)\n    apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and e=\"e1\" and ds'=\"ds2\" in infer_m_sub_range)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and ?p_sub1.0=\"p_sub\" and ?p_sub2.0=\"comp_use_env p_suba p_subb\"\n      and r_xv=\"r_m1\" and ds=\"set_diff ds2 ds\" and ds'=\"set_diff ds' ds2\" in comp_psub_use_env1)\n      apply (auto)\n    apply (rule_tac comp_psub_dom)\n     apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_psub_dom)\n      apply (simp)\n     apply (simp add: set_diff_def)\n    apply (auto)\n    apply (rule_tac ds=\"set_diff ds' ds3\" in subset_psub_dom)\n     apply (simp)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (simp add: set_diff_def)\n    (* M* inequality 2 *)\n  apply (case_tac \"\\<not> leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb)\n    (comp_use_env p_sub (comp_use_env p_suba p_subb)) r_m2)) r_ex\")\n   apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n     apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and e=\"e2\" and ds'=\"ds3\" in infer_m_tvar_range)\n     apply (auto)\n   apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and l=\"lb\" and p_sub=\"comp_use_env p_sub (comp_use_env p_suba p_subb)\"\n                and r_sv=\"r_m2\" and ds=\"ds3\" in dir_list_add_cancel_use_env)\n     apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and e=\"e2\" and ds'=\"ds3\" in infer_m_sub_range)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and ?p_sub2.0=\"p_sub\" and ?p_sub1.0=\"comp_use_env p_suba p_subb\"\n      and r_xv=\"r_m2\" and ds'=\"set_diff ds2 ds\" and ds=\"set_diff ds' ds2\" in comp_psub_use_env2)\n      apply (auto)\n     apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n      apply (simp)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (simp add: set_diff_def)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and ?p_sub1.0=\"p_suba\" and ?p_sub2.0=\"p_subb\"\n      and r_xv=\"r_m2\" and ds=\"set_diff ds3 ds2\" and ds'=\"set_diff ds' ds3\" in comp_psub_use_env1)\n      apply (auto)\n   apply (simp add: set_diff_def)\n    (* M* inequality 3 *)\n  apply (case_tac \"\\<not> leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb)\n    (comp_use_env p_sub (comp_use_env p_suba p_subb)) r_m3)) r_ex\")\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds3\" and e=\"e3\" and ds'=\"ds'\" in infer_m_sub_range)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb\" and ?p_sub2.0=\"p_sub\" and\n      ?p_sub1.0=\"comp_use_env p_suba p_subb\" and r_xv=\"r_m3\" and ds'=\"set_diff ds2 ds\" and ds=\"set_diff ds' ds2\" in comp_psub_use_env2)\n      apply (auto)\n     apply (rule_tac ds=\"set_diff ds' ds3\" in subset_pvar_range)\n      apply (simp)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (simp add: set_diff_def)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb\" and ?p_sub2.0=\"p_suba\" and ?p_sub1.0=\"p_subb\"\n      and r_xv=\"r_m3\" and ds'=\"set_diff ds3 ds2\" and ds=\"set_diff ds' ds3\" in comp_psub_use_env2)\n      apply (auto)\n   apply (simp add: set_diff_def)\n    (* proving type equivalence for t2 *)\n  apply (case_tac \"\\<not> dir_subst_type (dir_list_add_env t_sub (lb @ la @ l)) (comp_use_env p_sub (comp_use_env p_suba p_subb)) t2 tau\")\n   apply (simp add: dir_list_append_eq)\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n     apply (simp)\n    apply (rule_tac infer_x_subset)\n    apply (simp)\n   apply (cut_tac tau_v=\"t2\" and ds=\"ds2\" and ds'=\"ds3\" in infer_pvar_type)\n     apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and l=\"lb\" and p_sub=\"comp_use_env p_sub (comp_use_env p_suba p_subb)\" and\n        tau_v=\"t2\" and tau=\"tau\" in dir_list_add_subst_type)\n     apply (rule_tac ds=\"set_diff ds' ds2\" in comp_dir_subst_type2)\n        apply (rule_tac ds=\"set_diff ds3 ds2\" in comp_dir_subst_type1)\n           apply (auto)\n      apply (simp add: set_diff_def)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (simp add: set_diff_def)\n   apply (cut_tac x=\"x\" and l=\"lb\" in dom_list_contain)\n    apply (simp)\n   apply (cut_tac tau_v=\"t2\" and ds'=\"ds3\" and ds=\"ds2\" in infer_tvar_type)\n     apply (auto)\n   apply (simp add: fresh_list_def)\n   apply (auto)\n    (* proving type equivalence for t3 *)\n  apply (case_tac \"\\<not> dir_subst_type (dir_list_add_env t_sub (lb @ la @ l)) (comp_use_env p_sub (comp_use_env p_suba p_subb)) t3 tau\")\n   apply (simp add: dir_list_append_eq)\n   apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds3\" in subset_sub_range)\n     apply (auto)\n   apply (cut_tac tau_v=\"t3\" and ds=\"ds3\" and ds'=\"ds'\" in infer_pvar_type)\n     apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) lb\" and\n      p_sub=\"p_sub\" and p_subx=\"comp_use_env p_suba p_subb\" and ds=\"set_diff ds' ds2\" in comp_dir_subst_type2)\n       apply (rule_tac ds=\"set_diff ds' ds3\" in comp_dir_subst_type2)\n          apply (auto)\n     apply (simp add: set_diff_def)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (simp add: set_diff_def)\n  apply (rule_tac x=\"lb @ la @ l\" in exI)\n  apply (auto)\n    (* type subst domain containment *)\n     apply (simp add: dir_list_append_eq)\n    (* freshness of lb, la, l *)\n    apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n     apply (auto)\n    apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n     apply (auto)\n    apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n     apply (auto)\n    apply (rule_tac t_sub=\"t_sub\" and ds=\"ds\" and ds'=\"ds3\" in append_fresh_list2)\n       apply (auto)\n     apply (rule_tac ds=\"ds\" and ds'=\"ds2\" in append_fresh_list2)\n        apply (auto)\n    apply (simp add: dir_list_append_eq)\n    (* tenv equality *)\n   apply (simp add: dir_list_append_eq)\n    (* defining new p_sub *)\n  apply (rule_tac x=\"comp_use_env p_sub (comp_use_env p_suba p_subb)\" in exI)\n  apply (auto)\n    (* p_sub containment *)\n       apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n        apply (auto)\n       apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n        apply (auto)\n       apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n        apply (auto)\n       apply (rule_tac comp_psub_dom)\n        apply (rule_tac ds=\"set_diff ds2 ds\" in subset_psub_dom)\n         apply (simp)\n        apply (rule_tac set_diff_subset)\n         apply (auto)\n       apply (rule_tac comp_psub_dom)\n        apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_psub_dom)\n         apply (simp)\n        apply (rule_tac set_diff_subset)\n         apply (auto)\n       apply (rule_tac ds=\"set_diff ds' ds3\" in subset_psub_dom)\n        apply (simp)\n       apply (rule_tac set_diff_subset)\n        apply (auto)\n    (* initial permission environment containment *)\n      apply (simp add: dir_list_append_eq)\n      apply (simp add: comp_sol_subst_penv)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (simp)\n      apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (simp_all)\n    (* requirements containment *)\n     apply (simp add: dir_list_append_eq)\n     apply (simp add: comp_sol_subst_penv)\n     apply (rule_tac lhs_dist_dcl_use_env)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac comp_leq_use_env1)\n      apply (simp)\n     apply (rule_tac comp_leq_use_env2)\n     apply (simp)\n    (* subtractant containment *)\n    apply (simp add: dir_list_append_eq)\n    apply (simp add: comp_sol_subst_penv)\n    apply (rule_tac lhs_dist_cut_leq_use_env)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (rule_tac r_sb=\"cut_use_env r_exa\" in trans_leq_use_env)\n      apply (rule_tac r_s=\"r_s\" in dist_diff_leq_use_env_rev)\n       apply (simp)\n      apply (rule_tac t=\"diff_use_env r_s r_exa\" and s=\"super_norm_use_env r_s r_s2\" in subst)\n       apply (simp)\n      apply (rule_tac rhs_snorm_leq_use_env2)\n       apply (rule_tac well_typed_perm_leq)\n       apply (simp)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n     apply (rule_tac rhs_cut_leq_use_env)\n     apply (simp)\n    apply (rule_tac lhs_dist_cut_leq_use_env)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (simp_all)\n    (* type equivalence *)\n   apply (simp add: dir_list_append_eq)\n   apply (cut_tac tau_v=\"t1\" and ds=\"ds\" and ds'=\"ds2\" in infer_pvar_type)\n     apply (auto)\n   apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n     apply (simp_all)\n   apply (cut_tac tau_v=\"t1\" and ds'=\"ds2\" and ds=\"ds\" in infer_tvar_type)\n     apply (auto)\n   apply (rule_tac dir_list_add_subst_type)\n    apply (rule_tac dir_list_add_subst_type)\n     apply (rule_tac ds=\"set_diff ds2 ds\" and ds'=\"set_diff ds' ds2\" in comp_dir_subst_type1)\n        apply (simp_all)\n      apply (rule_tac comp_psub_dom)\n       apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_psub_dom)\n        apply (simp)\n       apply (simp add: set_diff_def)\n       apply (auto)\n      apply (rule_tac ds=\"set_diff ds' ds3\" in subset_psub_dom)\n       apply (simp)\n      apply (simp add: set_diff_def)\n      apply (auto)\n     apply (simp add: set_diff_def)\n    apply (cut_tac x=\"x\" and l=\"la\" in dom_list_contain)\n     apply (simp)\n    apply (simp add: fresh_list_def)\n    apply (auto)\n   apply (cut_tac x=\"x\" and l=\"lb\" in dom_list_contain)\n    apply (simp)\n   apply (simp add: fresh_list_def)\n   apply (auto)\n    (* constraint list correctness. disjointness *)\n  apply (simp add: dir_list_append_eq)\n  apply (rule_tac sol_sat_split)\n   apply (rule_tac sol_sat_mini_disj)\n   apply (rule_tac cut_mini_disj_use_env)\n   apply (rule_tac r_s=\"r_exa\" in mini_disj_leq_use_env1)\n    apply (rule_tac r_s=\"diff_use_env r_s r_exa\" in mini_disj_leq_use_env2)\n     apply (rule_tac mini_disj_diff_use_env)\n    apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n     apply (rule_tac t=\"diff_use_env r_s r_exa\" and s=\"super_norm_use_env r_s r_s2\" in subst)\n      apply (simp)\n     apply (rule_tac rhs_snorm_leq_use_env2)\n      apply (rule_tac id_leq_use_env)\n     apply (rule_tac well_typed_perm_leq)\n     apply (auto)\n   apply (simp add: comp_sol_subst_penv)\n   apply (rule_tac dist_comp_leq_use_env)\n    apply (simp_all)\n    (* - constraint list 1 correctness *)\n  apply (rule_tac sol_sat_split)\n   apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac c_list=\"cl1\" and ds=\"ds\" and ds'=\"ds2\" in infer_tvar_crn_list)\n     apply (auto)\n   apply (cut_tac c_list=\"cl1\" and ds=\"ds\" and ds'=\"ds2\" in infer_pvar_crn_list)\n     apply (auto)\n   apply (rule_tac dir_list_add_sol_sat)\n    apply (rule_tac dir_list_add_sol_sat)\n     apply (rule_tac ds=\"set_diff ds2 ds\" and ds'=\"set_diff ds' ds2\" in comp_psub_sol_sat1)\n        apply (simp_all)\n      apply (rule_tac comp_psub_dom)\n       apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_psub_dom)\n        apply (simp)\n       apply (simp add: set_diff_def)\n       apply (auto)\n      apply (rule_tac ds=\"set_diff ds' ds3\" in subset_psub_dom)\n       apply (simp)\n      apply (simp add: set_diff_def)\n      apply (auto)\n     apply (simp add: set_diff_def)\n    apply (cut_tac x=\"x\" and l=\"la\" in dom_list_set_contain)\n     apply (auto)\n    apply (simp add: fresh_list_def)\n    apply (auto)\n   apply (cut_tac x=\"x\" and l=\"lb\" in dom_list_set_contain)\n    apply (auto)\n   apply (simp add: fresh_list_def)\n   apply (auto)\n    (* - constraint list 2 correctness *)\n  apply (rule_tac sol_sat_split)\n   apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n     apply (auto)\n   apply (cut_tac c_list=\"cl2\" and ds=\"ds2\" and ds'=\"ds3\" in infer_tvar_crn_list)\n     apply (auto)\n   apply (cut_tac c_list=\"cl2\" and ds=\"ds2\" and ds'=\"ds3\" in infer_pvar_crn_list)\n     apply (auto)\n   apply (rule_tac dir_list_add_sol_sat)\n    apply (rule_tac ds=\"set_diff ds' ds2\" and ds'=\"set_diff ds2 ds\" in comp_psub_sol_sat2)\n    apply (rule_tac ds=\"set_diff ds3 ds2\" in comp_psub_sol_sat1)\n          apply (simp_all)\n      apply (simp add: set_diff_def)\n      apply (auto)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (simp add: set_diff_def)\n   apply (cut_tac x=\"x\" and l=\"lb\" in dom_list_set_contain)\n    apply (auto)\n   apply (simp add: fresh_list_def)\n   apply (auto)\n    (* - constraint list 3 correctness *)\n   apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds3\" in subset_sub_range)\n     apply (auto)\n   apply (cut_tac c_list=\"cl3\" and ds=\"ds3\" and ds'=\"ds'\" in infer_tvar_crn_list)\n     apply (auto)\n   apply (cut_tac c_list=\"cl3\" and ds=\"ds3\" and ds'=\"ds'\" in infer_pvar_crn_list)\n     apply (auto)\n  apply (rule_tac ds=\"set_diff ds' ds2\" and ds'=\"set_diff ds2 ds\" in comp_psub_sol_sat2)\n     apply (rule_tac ds=\"set_diff ds' ds3\" in comp_psub_sol_sat2)\n        apply (simp_all)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (simp add: set_diff_def)\n   apply (auto)\n  apply (simp add: set_diff_def)\n  done\n    \n    \nlemma ivr_if_case: \"\\<lbrakk>\\<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.\n           \\<lbrakk>well_typed env r_s e1 tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e1 tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;\n            sub_range env_v ds; tsub_dom t_sub ds\\<rbrakk>\n           \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \\<and>\n                   fresh_list ds (dom_list l) \\<and>\n                   dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n                   (\\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \\<and>\n                            leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \\<and>\n                            leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \\<and>\n                            leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \\<and>\n                            dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \\<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);\n        \\<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.\n           \\<lbrakk>well_typed env r_s e2 tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e2 tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;\n            sub_range env_v ds; tsub_dom t_sub ds\\<rbrakk>\n           \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \\<and>\n                   fresh_list ds (dom_list l) \\<and>\n                   dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n                   (\\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \\<and>\n                            leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \\<and>\n                            leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \\<and>\n                            leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \\<and>\n                            dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \\<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);\n        \\<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.\n           \\<lbrakk>well_typed env r_s e3 tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e3 tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;\n            sub_range env_v ds; tsub_dom t_sub ds\\<rbrakk>\n           \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \\<and>\n                   fresh_list ds (dom_list l) \\<and>\n                   dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n                   (\\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \\<and>\n                            leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \\<and>\n                            leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \\<and>\n                            leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \\<and>\n                            dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \\<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);\n        spec_env env_v env t_sub; sub_range env_v ds; tsub_dom t_sub ds; well_typed env r_s e1 BoolTy r_s2 rx'; infer_type env_v ds e1 t1 r_s1 r_x1 r_m1 cl1 ds2;\n        well_typed env r_s2 e2 tau (diff_use_env r_s r_ex) rx1; infer_type env_v ds2 e2 t2 r_s2a r_x2 r_m2 cl2 ds3;\n        well_typed env r_s2 e3 tau (diff_use_env r_s r_ex) rx2; infer_type env_v ds3 e3 t3 r_s3 r_x3 r_m3 cl3 ds';\n        finite_dom (comp_var_env r_s1 (comp_var_env r_s2a r_s3)) d\\<rbrakk>\n       \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \\<and>\n               fresh_list ds (dom_list l) \\<and>\n               dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n               (\\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \\<and>\n                        leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (comp_var_env r_s1 (comp_var_env r_s2a r_s3))) r_s \\<and>\n                        leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (comp_var_env r_x2 r_x3)) r_ex) (comp_use_env rx1 rx2) \\<and>\n                        leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (comp_var_env r_m1 (comp_var_env r_m2 r_m3)))) r_ex \\<and>\n                        dir_subst_type (dir_list_add_env t_sub l) p_sub t2 tau \\<and>\n                        dir_subst_type (dir_list_add_env t_sub l) p_sub t1 BoolTy \\<and>\n                        (\\<exists>tau_x. dir_subst_type (dir_list_add_env t_sub l) p_sub t2 tau_x \\<and> dir_subst_type (dir_list_add_env t_sub l) p_sub t3 tau_x) \\<and>\n                        dir_sol_sat (dir_list_add_env t_sub l) p_sub (semi_disj_crn r_m1 (comp_var_env r_s2a r_s3) d @ cl1 @ cl2 @ cl3))\" \n  apply (cut_tac r_s=\"r_s\" and r_x=\"r_s2\" in snorm_diff_use_env)\n  apply (auto)\n  apply (cut_tac e=\"e1\" and env=\"env\" and env_v=\"env_v\" and t_sub=\"t_sub\" and ds=\"ds\" and r_s=\"r_s\" and r_ex=\"r_exa\" in ivric_coerce)\n        apply (auto)\n   apply (cut_tac env=\"env\" and ?r_s1.0=\"r_s\" and ?r_s2.0=\"r_s2\" and e=\"e1\" in well_typed_sstr_end_perm)\n    apply (auto)\n  apply (cut_tac e=\"e2\" and env=\"dir_subst_tenv (dir_list_add_env t_sub l) env_v\" and env_v=\"env_v\" and\n      t_sub=\"dir_list_add_env t_sub l\" and ds=\"ds2\" and r_s=\"r_s2\" and r_ex=\"r_ex\" in ivric_coerce)\n        apply (auto)\n     apply (rule_tac r_c=\"diff_use_env r_s r_ex\" in well_typed_decr_end_perm)\n       apply (auto)\n      apply (rule_tac dist_diff_leq_use_env)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n     apply (rule_tac mini_disj_diff_leq_use_env2)\n      apply (rule_tac r_sb=\"diff_use_env r_s r_ex\" in trans_leq_use_env)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n      apply (rule_tac well_typed_perm_leqx)\n      apply (auto)\n     apply (rule_tac r_s=\"diff_use_env r_s r_ex\" in mini_disj_leq_use_env2)\n      apply (rule_tac mini_disj_diff_use_env)\n     apply (rule_tac well_typed_perm_leqx)\n     apply (auto)\n    apply (rule_tac self_spec_env)\n   apply (rule_tac ds=\"ds\" in subset_sub_range)\n    apply (simp)\n   apply (rule_tac infer_x_subset)\n   apply (auto)\n  apply (cut_tac e=\"e3\" and env=\"dir_subst_tenv (dir_list_add_env (dir_list_add_env t_sub l) la) env_v\" and env_v=\"env_v\" and\n      t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and ds=\"ds3\" and r_s=\"r_s2\" and r_ex=\"r_ex\" in ivric_coerce)\n        apply (auto)\n     apply (rule_tac r_c=\"diff_use_env r_s r_ex\" in well_typed_decr_end_perm)\n       apply (auto)\n      apply (rule_tac dist_diff_leq_use_env)\n      apply (rule_tac well_typed_perm_leq)\n      apply (auto)\n     apply (rule_tac mini_disj_diff_leq_use_env2)\n      apply (rule_tac r_sb=\"diff_use_env r_s r_ex\" in trans_leq_use_env)\n       apply (rule_tac well_typed_perm_leq)\n       apply (auto)\n      apply (rule_tac well_typed_perm_leqx)\n      apply (auto)\n     apply (rule_tac r_s=\"diff_use_env r_s r_ex\" in mini_disj_leq_use_env2)\n      apply (rule_tac mini_disj_diff_use_env)\n     apply (rule_tac well_typed_perm_leqx)\n     apply (auto)\n    apply (rule_tac eq_spec_env)\n    apply (auto)\n   apply (rule_tac ds=\"ds\" in subset_sub_range)\n    apply (simp)\n   apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)\n  apply (rule_tac env_v=\"env_v\" and r_s=\"r_s\" and ?r_s3.0=\"r_s3\" and ?e1.0=\"e1\" and ?e2.0=\"e2\" and ?e3.0=\"e3\"\n      and ?r_s1.0=\"r_s1\" and ?r_x1.0=\"r_x1\" and ?r_m1.0=\"r_m1\" and ?r_s2.0=\"r_s2\" and ?r_x2.0=\"r_x2\" and ?r_m2.0=\"r_m2\"\n      and ?r_s3.0=\"r_s3\" and ?r_x3.0=\"r_x3\" and ?r_m3.0=\"r_m3\" and t_sub=\"t_sub\" and p_sub=\"p_sub\" and p_suba=\"p_suba\"\n      and p_subb=\"p_subb\" and l=\"l\" and la=\"la\" and lb=\"lb\" and ds=\"ds\" and ?ds2.0=\"ds2\" and ?ds3.0=\"ds3\" and ds'=\"ds'\" in ivric_main)\n                      apply (auto)\n  done\n  \nlemma ivrlc_coerce: \"\\<lbrakk> \\<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.\n           \\<lbrakk>well_typed env r_s e tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;\n            sub_range env_v ds; tsub_dom t_sub ds\\<rbrakk>\n           \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \\<and>\n                   fresh_list ds (dom_list l) \\<and>\n                   dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n                   (\\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \\<and>\n                            leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \\<and>\n                            leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \\<and>\n                            leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \\<and>\n                            dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \\<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);\n    well_typed env r_s e tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;\n            sub_range env_v ds; tsub_dom t_sub ds \\<rbrakk> \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \\<and>\n                   fresh_list ds (dom_list l) \\<and>\n                   dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n                   (\\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \\<and>\n                            leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \\<and>\n                            leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \\<and>\n                            leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \\<and>\n                            dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \\<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list)\"\n  apply (auto)\n  done\n    \nlemma add_spec_env: \"\\<lbrakk> sub_range env_v ds; a \\<notin> ds; spec_env env_v env t_sub \\<rbrakk> \\<Longrightarrow>\n  spec_env (add_env env_v x a) (add_env env x tau) (dir_add_env t_sub a tau)\"    \n  apply (simp add: spec_env_def)\n  apply (simp add: add_env_def)\n  apply (auto)\n   apply (simp add: dir_add_env_def)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (case_tac \"env xa\")\n   apply (case_tac \"env_v xa\")\n    apply (auto)\n    apply (simp add: add_env_def)\n   apply (simp add: add_env_def)\n   apply (simp add: dir_add_env_def)\n   apply (simp add: sub_range_def)\n   apply (erule_tac x=\"xa\" in allE)\n   apply (auto)\n  apply (case_tac \"env_v xa\")\n   apply (auto)\n  apply (simp add: add_env_def)\n  apply (simp add: dir_add_env_def)\n  apply (auto)\n  apply (simp add: sub_range_def)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (auto)\n  done\n\n    (* tau1 <: tau2 indicates that tau1 represents a stricter class of values. ie t1 can be used where t2 is used. *)\nfunction sub_type :: \"p_type \\<Rightarrow> p_type \\<Rightarrow> bool\" where\n  \"sub_type IntTy s = (s = IntTy)\"\n| \"sub_type UnitTy s = (s = UnitTy)\"  \n| \"sub_type BoolTy s = (s = BoolTy)\"  \n| \"sub_type (ArrayTy t) s = (s = ArrayTy t)\"  \n| \"sub_type (PairTy t1 t2 r) s = (s = PairTy t1 t2 r)\"\n| \"sub_type (FunTy t1 t2 r a) s = (case s of\n    FunTy s1 s2 q b \\<Rightarrow> sub_type s1 t1 \\<and> sub_type t2 s2 \\<and> leq_perm q r \\<and> leq_perm (as_perm a) (as_perm b)\n    | sx \\<Rightarrow> False)\"\n| \"sub_type (ChanTy t c_end) s = (s = ChanTy t c_end)\"\nby pat_completeness auto\ntermination\n  apply (rule_tac R=\"measure (\\<lambda> (t, s). max (size t) (size s))\" in local.termination)\n  apply (auto)\n  done\n\nfun weaken_type where \n  \"weaken_type (FunTy t1 t2 r a) s = (case s of\n    FunTy s1 s2 q b \\<Rightarrow> t1 = s1 \\<and> t2 = s2 \\<and> r = q \\<and> leq_perm (as_perm a) (as_perm b)\n    | sx \\<Rightarrow> False)\"\n| \"weaken_type t s = (t = s)\"\n\n  \nlemma dir_list_ex: \"\\<lbrakk> t_sub x = tau; fresh_list ds (dom_list l); x \\<in> ds \\<rbrakk> \\<Longrightarrow> dir_list_add_env t_sub l x = tau\"  \n  apply (induct l)\n   apply (auto)\n  apply (case_tac \"\\<not> fresh_list ds (dom_list l)\")\n   apply (simp add: fresh_list_def)\n  apply (auto)\n  apply (simp add: dir_add_env_def)\n  apply (simp add: fresh_list_def)\n  apply (auto)\n  done\n    \nlemma sol_sat_aff: \"\\<lbrakk> aff_use_env (dir_subst_penv t_sub p_sub r_s) (as_aff (sol_subst_perm p_sub p)) \\<rbrakk> \\<Longrightarrow>\n  dir_sol_sat t_sub p_sub (aff_crn r_s p d)\"    \n  apply (induct d)\n   apply (auto)\n  apply (simp add: dir_subst_penv_def)\n  apply (simp add: aff_use_env_def)\n  apply (case_tac \"sol_subst_perm p_sub p\")\n    apply (auto)\n   apply (simp add: null_use_env_def)\n  apply (simp add: weak_use_env_def)\n  apply (case_tac \"dir_subst_permx t_sub p_sub (r_s a)\")\n    apply (auto)\n  done    \n  \nlemma ivrlc_main: \"\\<lbrakk>\n                spec_env env_v env t_sub; sub_range env_v ds; tsub_dom t_sub ds; infer_type (add_env env_v (Var x1a) a) (insert a ds) e t2 r_s' r_x' r_m' cl ds2;\n                well_typed (add_env env (Var x1a) t1) (add_use_env rx (Var x1a) r) e t2a r_s'a r_end; aff_use_env rx aa; leq_use_env rx r_s;\n                leq_use_env (diff_use_env r_s r_ex) (diff_use_env r_s r_exa); leq_use_env r_x (diff_use_env r_s r_ex); x1a \\<notin> ref_vars e; leq_use_env r_exa r_s;\n                leq_use_env (diff_use_env rx r_exa) r_x; finite_dom (rem_var_env r_s' (Var x1a)) d; a \\<notin> ds; p \\<noteq> q; p \\<notin> ds2; q \\<notin> ds2;\n                tsub_dom (dir_list_add_env (dir_add_env t_sub a t1) l) ds2; fresh_list (insert a ds) (dom_list l);\n                dir_subst_tenv (dir_list_add_env (dir_add_env t_sub a t1) l) (add_env env_v (Var x1a) a) = add_env env (Var x1a) t1;\n                psub_dom p_sub (set_diff ds2 (insert a ds));\n                leq_use_env (dir_subst_penv (dir_list_add_env (dir_add_env t_sub a t1) l) p_sub r_s') (add_use_env rx (Var x1a) r);\n                leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_add_env t_sub a t1) l) p_sub r_x') (add_use_env rx (Var x1a) r))\n                 (diff_use_env r_end (add_use_env rx (Var x1a) r));\n                leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env (dir_add_env t_sub a t1) l) p_sub r_m')) (add_use_env rx (Var x1a) r);\n                dir_subst_type (dir_list_add_env (dir_add_env t_sub a t1) l) p_sub t2 t2a; dir_sol_sat (dir_list_add_env (dir_add_env t_sub a t1) l) p_sub cl\\<rbrakk>\n               \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) (insert p (insert q ds2)) \\<and>\n                       fresh_list ds (dom_list l) \\<and>\n                       dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n                       (\\<exists>p_sub. psub_dom p_sub (set_diff (insert p (insert q ds2)) ds) \\<and>\n                                leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (rem_var_env r_s' (Var x1a))) r_s \\<and>\n                                leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (rem_var_env r_s' (Var x1a))) r_ex) r_x \\<and>\n                                leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub empty_var_env)) r_ex \\<and>\n                                dir_list_add_env t_sub l a = Some t1 \\<and>\n                                dir_subst_type (dir_list_add_env t_sub l) p_sub t2 t2a \\<and>\n                                r = p_sub p \\<and>\n                                aa = as_aff (p_sub q) \\<and>\n                                leq_perm (dir_subst_permx (dir_list_add_env t_sub l) p_sub (r_s' (Var x1a))) (p_sub p) \\<and>\n                                dir_sol_sat (dir_list_add_env t_sub l) p_sub (aff_crn (rem_var_env r_s' (Var x1a)) (SVar q) d @ cl))\"  \n\n    (* defining new type substitution *)\n  apply (rule_tac x=\"l @ [(a, t1)]\" in exI)\n  apply (auto)\n     apply (simp add: dir_list_append_eq)\n     apply (rule_tac ds=\"ds2\" in subset_tsub_dom)\n      apply (auto)\n    apply (rule_tac t_sub=\"t_sub\" and ds'=\"insert a ds\" in append_fresh_list2)\n       apply (simp add: fresh_list_def)\n      apply (auto)\n    apply (rule_tac add_tsub_dom)\n     apply (auto)\n    apply (rule_tac ds=\"ds\" in subset_tsub_dom)\n     apply (auto)\n   apply (cut_tac t_sub=\"t_sub\" and l=\"l @ [(a, t1)]\" and env_v=\"env_v\" and ds=\"ds\" in dir_list_cancel_add_eq_env)\n     apply (simp)\n    apply (rule_tac t_sub=\"t_sub\" and ds'=\"insert a ds \" in append_fresh_list2)\n       apply (simp add: fresh_list_def)\n      apply (auto)\n    apply (rule_tac add_tsub_dom)\n     apply (auto)\n    apply (rule_tac ds=\"ds\" in subset_tsub_dom)\n     apply (auto)\n   apply (rule_tac dir_subst_spec_env_ex)\n   apply (simp)\n    (* prelim: initial permission containment *)\n  apply (case_tac \"\\<not> leq_use_env (dir_subst_penv (dir_list_add_env (dir_add_env t_sub a t1) l) (add_use_env (add_use_env p_sub p r) q (as_perm aa)) r_s')\n    (add_use_env rx (Var x1a) r)\")  \n   apply (cut_tac t_sub=\"dir_list_add_env (dir_add_env t_sub a t1) l\" and p_sub=\"add_use_env p_sub p r\" and\n            r_xv=\"r_s'\" and ds=\"set_diff ds2 (insert a ds)\" and x=\"q\" and r=\"as_perm aa\" in add_psub_use_env)\n     apply (cut_tac ds=\"insert a ds\" and ds'=\"ds2\" in infer_s_sub_range)\n      apply (auto)\n    apply (simp add: set_diff_def)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_add_env t_sub a t1) l\" and p_sub=\"p_sub\" and\n            r_xv=\"r_s'\" and ds=\"set_diff ds2 (insert a ds)\" and x=\"p\" and r=\"r\" in add_psub_use_env)\n     apply (cut_tac ds=\"insert a ds\" and ds'=\"ds2\" in infer_s_sub_range)\n      apply (auto)\n   apply (simp add: set_diff_def)\n    (* defining new permission substitution *)\n  apply (rule_tac x=\"add_use_env (add_use_env p_sub p r) q (as_perm aa)\" in exI)\n  apply (auto)\n    (* p_sub containment *)\n           apply (rule_tac add_psub_dom)\n            apply (rule_tac add_psub_dom)\n             apply (rule_tac ds=\"set_diff ds2 (insert a ds)\" in subset_psub_dom)\n              apply (simp)\n             apply (simp add: set_diff_def)\n             apply (auto)\n            apply (simp add: set_diff_def)\n            apply (cut_tac ds=\"insert a ds\" and ds'=\"ds2\" in infer_x_subset)\n             apply (auto)\n           apply (simp add: set_diff_def)\n           apply (cut_tac ds=\"insert a ds\" and ds'=\"ds2\" in infer_x_subset)\n            apply (auto)\n    (* initial permission containment *)\n          apply (rule_tac r_sb=\"rem_use_env (add_use_env rx (Var x1a) r) (Var x1a)\"  in trans_leq_use_env)\n           apply (rule_tac r=\"r\" in rem_add_leq_use_env)\n           apply (rule_tac dist_add_leq_use_env)\n           apply (simp)\n          apply (simp add: rem_sol_subst_penv)\n          apply (rule_tac dist_rem_leq_use_env)\n          apply (simp add: dir_list_append_eq)\n    (* requirements containment *)\n         apply (rule_tac r_sb=\"diff_use_env rx r_exa\" in trans_leq_use_env)\n          apply (simp)\n         apply (rule_tac r_s=\"r_s\" in crush_leq_use_env)\n           apply (simp_all)\n         apply (rule_tac diff_leq_use_env)\n         apply (simp add: rem_sol_subst_penv)\n         apply (rule_tac r=\"r\" in rem_add_leq_use_env)\n         apply (simp add: dir_list_append_eq)\n         apply (cut_tac t_sub=\"dir_list_add_env (dir_add_env t_sub a t1) l\" and p_sub=\"add_use_env p_sub p r\" and\n            r_xv=\"r_s'\" and ds=\"set_diff ds2 (insert a ds)\" and x=\"q\" and r=\"as_perm aa\" in add_psub_use_env)\n           apply (cut_tac ds=\"insert a ds\" and ds'=\"ds2\" in infer_s_sub_range)\n            apply (auto)\n          apply (simp add: set_diff_def)\n         apply (cut_tac t_sub=\"dir_list_add_env (dir_add_env t_sub a t1) l\" and p_sub=\"p_sub\" and\n            r_xv=\"r_s'\" and ds=\"set_diff ds2 (insert a ds)\" and x=\"p\" and r=\"r\" in add_psub_use_env)\n           apply (cut_tac ds=\"insert a ds\" and ds'=\"ds2\" in infer_s_sub_range)\n            apply (auto)\n         apply (simp add: set_diff_def)\n    (* subtractant containment *)\n        apply (rule_tac cut_leq_use_env)\n        apply (rule_tac empty_leq_var_env)\n    (* proof of a's type *)\n       apply (simp add: dir_list_append_eq)\n       apply (rule_tac ds=\"insert a ds\" in dir_list_ex)\n         apply (simp add: dir_add_env_def)\n        apply (auto)\n    (* correctness for t2 *)\n      apply (simp add: dir_list_append_eq)\n      apply (cut_tac ds=\"insert a ds\" and ds'=\"ds2\" in infer_pvar_type)\n        apply (simp)\n       apply (rule_tac add_sub_range)\n       apply (simp)\n      apply (rule_tac add_dir_subst_type)\n       apply (rule_tac add_dir_subst_type)\n        apply (simp)\n       apply (simp add: set_diff_def)\n       apply (auto)\n      apply (simp add: set_diff_def)\n      apply (auto)\n    (* correctness of p + q *)\n     apply (simp add: add_use_env_def)\n    apply (simp add: add_use_env_def)\n    apply (case_tac aa)\n      apply (auto)\n    (* correctness of p with respect to r_s' *)\n   apply (case_tac \"\\<not> leq_perm ((dir_subst_penv (dir_list_add_env (dir_add_env t_sub a t1) l)\n    (add_use_env (add_use_env p_sub p r) q (as_perm aa)) r_s') (Var x1a)) ((add_use_env rx (Var x1a) r) (Var x1a))\")\n    apply (simp add: leq_use_env_def)\n   apply (simp add: dir_list_append_eq)\n   apply (simp add: add_use_env_def)\n   apply (simp add: dir_subst_penv_def)\n    (* constraint list: affinity *)\n  apply (rule_tac sol_sat_split)\n   apply (rule_tac sol_sat_aff)\n   apply (case_tac \"\\<not> as_aff (sol_subst_perm (add_use_env (add_use_env p_sub p r) q (as_perm aa)) (SVar q)) = aa\")\n    apply (simp add: add_use_env_def)\n    apply (case_tac \"aa\")\n      apply (auto)\n   apply (rule_tac r_s=\"rx\" in aff_leq_use_env)\n    apply (simp)\n   apply (simp add: dir_list_append_eq)\n   apply (simp add: rem_sol_subst_penv)\n   apply (rule_tac rem_add_leq_use_env)\n   apply (simp)\n    (* - sub-constraint list correctness *)\n  apply (cut_tac c_list=\"cl\" and ds=\"insert a ds\" and ds'=\"ds2\" in infer_pvar_crn_list)\n    apply (auto)\n   apply (rule_tac add_sub_range)\n   apply (simp)\n  apply (simp add: dir_list_append_eq)\n  apply (rule_tac add_psub_sol_sat)\n   apply (rule_tac add_psub_sol_sat)\n    apply (simp)\n   apply (simp add: set_diff_def)\n   apply (auto)\n  apply (simp add: set_diff_def)\n  apply (auto)\n  done\n    \nlemma ivr_lam_case: \"\\<lbrakk>\\<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.\n           \\<lbrakk>well_typed env r_s e tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;\n            sub_range env_v ds; tsub_dom t_sub ds\\<rbrakk>\n           \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \\<and>\n                   fresh_list ds (dom_list l) \\<and>\n                   dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n                   (\\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \\<and>\n                            leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \\<and>\n                            leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \\<and>\n                            leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \\<and>\n                            dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \\<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);\n        spec_env env_v env t_sub; sub_range env_v ds; tsub_dom t_sub ds; infer_type (add_env env_v (Var x1a) a) (insert a ds) e t2 r_s' r_x' r_m' cl ds2;\n        well_typed (add_env env (Var x1a) t1) (add_use_env rx (Var x1a) r) e t2a r_s'a r_end; aff_use_env rx aa; leq_use_env rx r_s;\n        leq_use_env (diff_use_env r_s r_ex) (diff_use_env r_s r_exa); leq_use_env r_x (diff_use_env r_s r_ex); x1a \\<notin> ref_vars e; leq_use_env r_exa r_s;\n        leq_use_env (diff_use_env rx r_exa) r_x; finite_dom (rem_var_env r_s' (Var x1a)) d; a \\<notin> ds; p \\<noteq> q; p \\<notin> ds2; q \\<notin> ds2\\<rbrakk>\n       \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) (insert p (insert q ds2)) \\<and>\n               fresh_list ds (dom_list l) \\<and>\n               dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n               (\\<exists>p_sub. psub_dom p_sub (set_diff (insert p (insert q ds2)) ds) \\<and>\n                        leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (rem_var_env r_s' (Var x1a))) r_s \\<and>\n                        leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (rem_var_env r_s' (Var x1a))) r_ex) r_x \\<and>\n                        leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub empty_var_env)) r_ex \\<and>\n                        dir_list_add_env t_sub l a = Some t1 \\<and>\n                        dir_subst_type (dir_list_add_env t_sub l) p_sub t2 t2a \\<and>\n                        r = p_sub p \\<and>\n                        aa = as_aff (p_sub q) \\<and>\n                        leq_perm (dir_subst_permx (dir_list_add_env t_sub l) p_sub (r_s' (Var x1a))) (p_sub p) \\<and>\n                        dir_sol_sat (dir_list_add_env t_sub l) p_sub (aff_crn (rem_var_env r_s' (Var x1a)) (SVar q) d @ cl))\"\n    (* initial induction *)\n  apply (cut_tac env_v=\"add_env env_v (Var x1a) a\" and env=\"add_env env (Var x1a) t1\" and e=\"e\"\n      and r_s=\"add_use_env rx (Var x1a) r\" and r_ex=\"add_use_env rx (Var x1a) r\" and ds=\"insert a ds\" and t_sub=\"dir_add_env t_sub a t1\" in ivrlc_coerce)\n        apply (auto)\n      apply (rule_tac well_typed_end_perm_lbound)\n      apply (auto)\n     apply (rule_tac ds=\"ds\" in add_spec_env)\n       apply (simp_all)\n    apply (rule_tac add_sub_range)\n    apply (simp_all)\n   apply (rule_tac add_tsub_dom)\n    apply (rule_tac ds=\"ds\" in subset_tsub_dom)\n     apply (auto)\n    (* main lemma *)\n  apply (rule_tac ivrlc_main)\n                      apply (auto)\n  done\n    \nlemma add_fresh_list_ex: \"\\<lbrakk> fresh_list ds (dom_list l); tsub_dom (dir_list_add_env t_sub l) ds';\n  x \\<notin> ds'; ds \\<subseteq> ds' \\<rbrakk> \\<Longrightarrow> fresh_list ds (x # (dom_list l))\" \n  apply (cut_tac x=\"x\" and ds=\"ds\" and l=\"l\" and ds'=\"ds'\" in add_fresh_list)\n      apply (auto)\n  done    \n    \nlemma ivrac_coerce: \"\\<lbrakk> \\<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.\n           \\<lbrakk>well_typed env r_s e tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;\n            sub_range env_v ds; tsub_dom t_sub ds\\<rbrakk>\n           \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \\<and>\n                   fresh_list ds (dom_list l) \\<and>\n                   dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n                   (\\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \\<and>\n                            leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \\<and>\n                            leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \\<and>\n                            leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \\<and>\n                            dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \\<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);\n   well_typed env r_s e tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;\n            sub_range env_v ds; tsub_dom t_sub ds  \\<rbrakk> \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \\<and>\n                   fresh_list ds (dom_list l) \\<and>\n                   dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n                   (\\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \\<and>\n                            leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \\<and>\n                            leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \\<and>\n                            leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \\<and>\n                            dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \\<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list)\"    \n  apply (auto)\n  done\n    \nlemma dir_add_cancel_use_env: \"\\<lbrakk> tvar_range r_sv ds; a \\<notin> ds \\<rbrakk> \\<Longrightarrow>\n  dir_subst_penv (dir_add_env t_sub a tau) p_sub r_sv = dir_subst_penv t_sub p_sub r_sv\"\n  apply (case_tac \"\\<forall> x. dir_subst_penv (dir_add_env t_sub a tau) p_sub r_sv x = dir_subst_penv t_sub p_sub r_sv x\")\n   apply (auto)\n  apply (cut_tac t_sub=\"t_sub\" and a=\"a\" and r_sv=\"r_sv\" and tau=\"tau\" in dir_add_cancel_use_env_ih)\n    apply (auto)\n  done    \n    \nlemma ifz_sol_subst_penv_gen: \"\\<lbrakk> dir_subst_permx t_sub p_sub px = NoPerm \\<rbrakk> \\<Longrightarrow> dir_subst_penv t_sub p_sub (ifz_var_env px r_sv) = empty_use_env\"    \n  apply (case_tac \"\\<forall> x. dir_subst_penv t_sub p_sub (ifz_var_env px r_sv) x = empty_use_env x\")   \n   apply (auto)\n  apply (simp add: dir_subst_penv_def)\n  apply (simp add: ifz_var_env_def)\n  apply (simp add: empty_use_env_def)\n  apply (case_tac \"r_sv x = XPerm (SPerm NoPerm)\")\n   apply (auto)\n  done            \n    \nlemma ivrac_main: \"\\<lbrakk>\n        spec_env env_v (dir_subst_tenv (dir_list_add_env t_sub l) env_v) t_sub; sub_range env_v ds; tsub_dom t_sub ds;\n        infer_type env_v ds e1 tau_f r_s1 r_x1 r_m1 cl1 ds2;\n        infer_type env_v ds2 e2 t1a r_s2a r_x2 r_m2 cl2 ds3; leq_use_env r_s3 r_s;\n        leq_use_env (diff_use_env r_s r_ex) (diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_exa));\n        leq_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_s3; disj_use_env rx1 (lift_use_env rx2 r); leq_use_env r_x (diff_use_env r_s r_ex);\n        leq_use_env r_exa r_s; leq_use_env (app_req rx1 rx2 r tau r_exa) r_x;\n        finite_dom (comp_var_env (comp_var_env r_s1 r_x1) (comp_var_env r_s2a (lift_var_env r_x2 (SVar p)))) d; fresh_list ds3 [aa, p, q]; leq_use_env r_exaa r_s;\n        leq_use_env r_exb (diff_use_env r_s r_exaa); super_norm_use_env r_s r_s3 = diff_use_env r_s (comp_use_env r_exaa r_exb);\n        well_typed (dir_subst_tenv (dir_list_add_env t_sub l) env_v) r_s e1 (FunTy t1 tau r a) (diff_use_env r_s r_exaa) rx1;\n        well_typed (dir_subst_tenv (dir_list_add_env t_sub l) env_v) (diff_use_env r_s r_exaa) e2 t1 (diff_use_env (diff_use_env r_s r_exaa) r_exb) rx2;\n        tsub_dom (dir_list_add_env t_sub l) ds2; fresh_list ds (dom_list l); env = dir_subst_tenv (dir_list_add_env t_sub l) env_v;\n        psub_dom p_sub (set_diff ds2 ds); leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_s1) r_s;\n        leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_x1) r_exaa) rx1;\n        leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_m1)) r_exaa;\n        dir_subst_type (dir_list_add_env t_sub l) p_sub tau_f (FunTy t1 tau r a); dir_sol_sat (dir_list_add_env t_sub l) p_sub cl1;\n        tsub_dom (dir_list_add_env (dir_list_add_env t_sub l) la) ds3; fresh_list ds2 (dom_list la);\n        dir_subst_tenv (dir_list_add_env (dir_list_add_env t_sub l) la) env_v = dir_subst_tenv (dir_list_add_env t_sub l) env_v;\n        psub_dom p_suba (set_diff ds3 ds2); leq_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba r_s2a) (diff_use_env r_s r_exaa);\n        leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba r_x2) r_exb) rx2;\n        leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba r_m2)) r_exb;\n        dir_subst_type (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba t1a t1; dir_sol_sat (dir_list_add_env (dir_list_add_env t_sub l) la) p_suba cl2\\<rbrakk>\n       \\<Longrightarrow> \\<exists>la. tsub_dom (dir_list_add_env t_sub la) (insert aa (insert p (insert q ds3))) \\<and>\n                fresh_list ds (dom_list la) \\<and>\n                dir_subst_tenv (dir_list_add_env t_sub la) env_v = dir_subst_tenv (dir_list_add_env t_sub l) env_v \\<and>\n                (\\<exists>p_sub. psub_dom p_sub (set_diff (insert aa (insert p (insert q ds3))) ds) \\<and>\n                         leq_use_env\n                          (dir_subst_penv (dir_list_add_env t_sub la) p_sub\n                            (comp_var_env (comp_var_env r_s1 r_x1) (comp_var_env r_s2a (lift_var_env r_x2 (SVar p)))))\n                          r_s \\<and>\n                         leq_use_env\n                          (diff_use_env\n                            (dir_subst_penv (dir_list_add_env t_sub la) p_sub (ifz_var_env (XType aa) (comp_var_env r_x1 (lift_var_env r_x2 (SVar p))))) r_ex)\n                          r_x \\<and>\n                         leq_use_env\n                          (cut_use_env\n                            (dir_subst_penv (dir_list_add_env t_sub la) p_sub\n                              (comp_var_env (comp_var_env r_m1 r_x1) (comp_var_env r_m2 (lift_var_env r_x2 (SVar p))))))\n                          r_ex \\<and>\n                         dir_list_add_env t_sub la aa = Some tau \\<and>\n                         (\\<exists>tau_x. (\\<exists>t1_x. dir_subst_type (dir_list_add_env t_sub la) p_sub t1a t1_x \\<and>\n                                          (\\<exists>t2_x. dir_list_add_env t_sub la aa = Some t2_x \\<and> tau_x = FunTy t1_x t2_x (p_sub p) (as_aff (p_sub q)))) \\<and>\n                                  dir_subst_type (dir_list_add_env t_sub la) p_sub tau_f tau_x) \\<and>\n                         dir_sol_sat (dir_list_add_env t_sub la) p_sub\n                          (disj_crn r_x1 (lift_var_env r_x2 (SVar p)) d @ semi_disj_crn r_m2 r_x1 d @ semi_disj_crn r_m1 r_s2a d @ cl1 @ cl2))\"\n    (* prelim: type subst domain *)\n  apply (cut_tac t_sub=\"t_sub\" and ?l1.0=\"la\" and ?l2.0=\"l\" and ds=\"ds3\" in append_tsub_dom)\n    apply (rule_tac ds=\"ds\" in list_add_tsub_dom)\n      apply (auto)\n     apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n      apply (auto)\n     apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n      apply (auto)\n    apply (cut_tac t_sub=\"t_sub\" and l=\"l\" and ds=\"ds2\" in list_add_dls)\n     apply (auto)\n    apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n     apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and l=\"la\" and ds=\"ds3\" in list_add_dls)\n    apply (auto)\n    (* defining new t_sub *)\n  apply (rule_tac x=\"[(aa, tau)] @ la @ l\" in exI)\n  apply (auto)\n     apply (rule_tac add_tsub_dom)\n      apply (rule_tac ds=\"ds3\" in subset_tsub_dom)\n       apply (auto)\n    apply (rule_tac t_sub=\"t_sub\" and ds'=\"ds3\" in add_fresh_list_ex)\n       apply (rule_tac ds=\"ds\" and ds'=\"ds2\" in append_fresh_list2)\n          apply (auto)\n      apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n       apply (auto)\n     apply (simp add: fresh_list_def)\n     apply (auto)\n    apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n     apply (auto)\n    apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n     apply (auto)\n   apply (rule_tac ds=\"ds\" in dir_add_eq_env)\n     apply (simp add: dir_list_append_eq)\n    apply (simp)\n   apply (case_tac \"aa \\<in> ds3\")\n    apply (simp add: fresh_list_def)\n    apply (auto)\n   apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)\n    (* p \\<notin> ds3 *)\n  apply (case_tac \"p \\<in> ds3\")\n   apply (simp add: fresh_list_def)\n   apply (auto)\n  apply (case_tac \"aa \\<in> ds3\")\n   apply (simp add: fresh_list_def)\n   apply (auto)\n  apply (case_tac \"q \\<in> ds3\")\n   apply (simp add: fresh_list_def)\n   apply (auto)\n    (* prelim: sub_range env_v ds2 *)\n  apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n    apply (simp)\n   apply (rule_tac infer_x_subset)\n   apply (simp)\n    (* P* inequality 1 *)\n  apply (case_tac \"\\<not> leq_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n      (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_s1) r_s\")\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and e=\"e1\" and ds'=\"ds2\" in infer_tvar_range)\n     apply (auto)\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and a=\"aa\" and tau=\"tau\" and\n      p_sub=\"add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)\" and r_sv=\"r_s1\" and ds=\"ds2\" in dir_add_cancel_use_env)\n     apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and l=\"la\" and p_sub=\"add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)\"\n                and r_sv=\"r_s1\" and ds=\"ds2\" in dir_list_add_cancel_use_env)\n     apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and e=\"e1\" and ds'=\"ds2\" in infer_s_sub_range)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and p_sub=\"add_use_env (comp_use_env p_sub p_suba) p r\" and r_xv=\"r_s1\"\n      and ds=\"set_diff ds2 ds\" and x=\"q\" and r=\"as_perm a\" in add_psub_use_env)\n     apply (auto)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and p_sub=\"comp_use_env p_sub p_suba\" and r_xv=\"r_s1\" and ds=\"set_diff ds2 ds\" and x=\"p\" and r=\"r\" in add_psub_use_env)\n     apply (auto)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and ?p_sub1.0=\"p_sub\" and ?p_sub2.0=\"p_suba\" and r_xv=\"r_s1\" and ds=\"set_diff ds2 ds\" in comp_psub_use_env1)\n      apply (auto)\n   apply (simp add: set_diff_def)\n    (* P* inequality 2 *)\n  apply (case_tac \"\\<not> leq_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n      (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_s2a) (diff_use_env r_s r_exaa)\")\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and e=\"e2\" and ds'=\"ds3\" in infer_s_sub_range)\n    apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and e=\"e2\" and ds'=\"ds3\" in infer_tvar_range)\n     apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and a=\"aa\" and tau=\"tau\" and\n      p_sub=\"add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)\" and r_sv=\"r_s2a\" and ds=\"ds3\" in dir_add_cancel_use_env)\n     apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and p_sub=\"add_use_env (comp_use_env p_sub p_suba) p r\" and\n        r_xv=\"r_s2a\" and ds=\"set_diff ds3 ds2\" and x=\"q\" and r=\"as_perm a\" in add_psub_use_env)\n     apply (auto)\n    apply (simp add: set_diff_def)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and p_sub=\"comp_use_env p_sub p_suba\" and r_xv=\"r_s2a\" and ds=\"set_diff ds3 ds2\" and x=\"p\" and r=\"r\" in add_psub_use_env)\n     apply (auto)\n    apply (simp add: set_diff_def)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and ?p_sub1.0=\"p_suba\" and ?p_sub2.0=\"p_sub\" and r_xv=\"r_s2a\" and ds=\"set_diff ds3 ds2\" in comp_psub_use_env2)\n      apply (auto)\n   apply (simp add: set_diff_def)\n    (* X* inequality 1 *)\n  apply (case_tac \"\\<not> leq_use_env (diff_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n      (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x1) r_exaa) rx1\")\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and e=\"e1\" and ds'=\"ds2\" in infer_tvar_range)\n     apply (auto)\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and a=\"aa\" and tau=\"tau\" and\n      p_sub=\"add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)\" and r_sv=\"r_x1\" and ds=\"ds2\" in dir_add_cancel_use_env)\n     apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and l=\"la\" and r_sv=\"r_x1\" and ds=\"ds2\" and\n      p_sub=\"add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)\" in dir_list_add_cancel_use_env)\n     apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and e=\"e1\" and ds'=\"ds2\" in infer_s_sub_range)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and p_sub=\"add_use_env (comp_use_env p_sub p_suba) p r\" and\n      r_xv=\"r_x1\" and ds=\"set_diff ds2 ds\" and x=\"q\" and r=\"as_perm a\" in add_psub_use_env)\n     apply (auto)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and p_sub=\"comp_use_env p_sub p_suba\" and r_xv=\"r_x1\" and ds=\"set_diff ds2 ds\" and x=\"p\" and r=\"r\" in add_psub_use_env)\n     apply (auto)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and ?p_sub1.0=\"p_sub\" and ?p_sub2.0=\"p_suba\" and r_xv=\"r_x1\" and ds=\"set_diff ds2 ds\" in comp_psub_use_env1)\n      apply (auto)\n   apply (simp add: set_diff_def)\n    (* X* inequality 2 *)\n  apply (case_tac \"\\<not> leq_use_env (diff_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n    (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r_exb) rx2\")\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and e=\"e2\" and ds'=\"ds3\" in infer_s_sub_range)\n    apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and e=\"e2\" and ds'=\"ds3\" in infer_tvar_range)\n     apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and a=\"aa\" and tau=\"tau\" and\n      p_sub=\"add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)\" and r_sv=\"r_x2\" and ds=\"ds3\" in dir_add_cancel_use_env)\n     apply (auto)\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and p_sub=\"add_use_env (comp_use_env p_sub p_suba) p r\" and\n      r_xv=\"r_x2\" and ds=\"set_diff ds3 ds2\" and x=\"q\" and r=\"as_perm a\" in add_psub_use_env)\n     apply (auto)\n    apply (simp add: set_diff_def)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and p_sub=\"comp_use_env p_sub p_suba\" and r_xv=\"r_x2\" and ds=\"set_diff ds3 ds2\" and x=\"p\" and r=\"r\" in add_psub_use_env)\n     apply (auto)\n    apply (simp add: set_diff_def)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and ?p_sub1.0=\"p_suba\" and ?p_sub2.0=\"p_sub\" and r_xv=\"r_x2\" and ds=\"set_diff ds3 ds2\" in comp_psub_use_env2)\n      apply (auto)\n   apply (simp add: set_diff_def)\n    (* M* inequality 1 *)\n  apply (case_tac \"\\<not> leq_use_env (cut_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n    (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_m1)) r_exaa\")\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and e=\"e1\" and ds'=\"ds2\" in infer_m_tvar_range)\n     apply (auto)\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and a=\"aa\" and tau=\"tau\" and\n      p_sub=\"add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)\" and r_sv=\"r_m1\" and ds=\"ds2\" in dir_add_cancel_use_env)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and l=\"la\" and r_sv=\"r_m1\" and ds=\"ds2\" and\n        p_sub=\"add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)\" in dir_list_add_cancel_use_env)\n     apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and e=\"e1\" and ds'=\"ds2\" in infer_m_sub_range)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and p_sub=\"add_use_env (comp_use_env p_sub p_suba) p r\" and\n      r_xv=\"r_m1\" and ds=\"set_diff ds2 ds\" and x=\"q\" and r=\"as_perm a\" in add_psub_use_env)\n     apply (auto)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and p_sub=\"comp_use_env p_sub p_suba\" and r_xv=\"r_m1\" and ds=\"set_diff ds2 ds\" and x=\"p\" and r=\"r\" in add_psub_use_env)\n     apply (auto)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and ?p_sub1.0=\"p_sub\" and ?p_sub2.0=\"p_suba\" and r_xv=\"r_m1\" and ds=\"set_diff ds2 ds\" in comp_psub_use_env1)\n      apply (auto)\n   apply (simp add: set_diff_def)\n    (* M* inequality 2 *)\n  apply (case_tac \"\\<not> leq_use_env (cut_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n    (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_m2)) r_exb\")\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and e=\"e2\" and ds'=\"ds3\" in infer_m_sub_range)\n    apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and e=\"e2\" and ds'=\"ds3\" in infer_m_tvar_range)\n     apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and a=\"aa\" and tau=\"tau\" and\n      p_sub=\"add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)\" and r_sv=\"r_m2\" and ds=\"ds3\" in dir_add_cancel_use_env)\n    apply (auto)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and p_sub=\"add_use_env (comp_use_env p_sub p_suba) p r\" and\n      r_xv=\"r_m2\" and ds=\"set_diff ds3 ds2\" and x=\"q\" and r=\"as_perm a\" in add_psub_use_env)\n     apply (auto)\n    apply (simp add: set_diff_def)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and p_sub=\"comp_use_env p_sub p_suba\" and r_xv=\"r_m2\" and ds=\"set_diff ds3 ds2\" and x=\"p\" and r=\"r\" in add_psub_use_env)\n     apply (auto)\n    apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n     apply (auto)\n    apply (simp add: set_diff_def)\n   apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and ?p_sub1.0=\"p_suba\" and ?p_sub2.0=\"p_sub\" and r_xv=\"r_m2\" and ds=\"set_diff ds3 ds2\" in comp_psub_use_env2)\n      apply (auto)\n   apply (simp add: set_diff_def)\n    (* prelim: (t_sub, p_sub)(tau_f) = FunTy t1 tau r a *)\n  apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and x=\"aa\" and t=\"tau\" and tau_v=\"tau_f\" and\n      p_sub=\"add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)\" and tau=\"FunTy t1 tau r a\" in dir_add_subst_type)\n    apply (rule_tac dir_list_add_subst_type)\n     apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n      apply (simp)\n     apply (cut_tac tau_v=\"tau_f\" and ds'=\"ds2\" and ds=\"ds\" in infer_pvar_type)\n       apply (auto)\n     apply (rule_tac add_dir_subst_type)\n      apply (rule_tac add_dir_subst_type)\n       apply (rule_tac ds=\"set_diff ds2 ds\" in comp_dir_subst_type1)\n          apply (simp)\n         apply (rule_tac infer_pvar_type)\n          apply (auto)\n       apply (simp add: set_diff_def)\n      apply (simp add: set_diff_def)\n      apply (auto)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (cut_tac x=\"x\" and l=\"la\" in dom_list_contain)\n     apply (simp)\n    apply (cut_tac tau_v=\"tau_f\" and ds'=\"ds2\" and ds=\"ds\" in infer_tvar_type)\n      apply (auto)\n    apply (simp add: fresh_list_def)\n    apply (auto)\n   apply (cut_tac tau_v=\"tau_f\" and ds'=\"ds2\" and ds=\"ds\" in infer_tvar_type)\n     apply (auto)\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)  \n    (* prelim: (t_sub, p_sub)(t1a) = t1 *)\n  apply (cut_tac t_sub=\"dir_list_add_env (dir_list_add_env t_sub l) la\" and x=\"aa\" and t=\"tau\" and tau_v=\"t1a\" and\n      p_sub=\"add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)\" and tau=\"t1\" in dir_add_subst_type)\n    apply (rule_tac add_dir_subst_type)\n     apply (rule_tac add_dir_subst_type)\n      apply (rule_tac ds=\"set_diff ds3 ds2\" in comp_dir_subst_type2)\n         apply (simp)\n        apply (rule_tac infer_pvar_type)\n         apply (auto)\n      apply (simp add: set_diff_def)\n     apply (cut_tac tau_v=\"t1a\" and ds'=\"ds3\" and ds=\"ds2\" in infer_pvar_type)\n       apply (auto)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (cut_tac tau_v=\"t1a\" and ds=\"ds2\" and ds'=\"ds3\" in infer_pvar_type)\n      apply (auto)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (cut_tac tau_v=\"t1a\" and ds'=\"ds3\" and ds=\"ds2\" in infer_tvar_type)\n     apply (auto)\n    (* prelim: rewriting of lift r_x2 *)\n  apply (case_tac \"dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n            (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) (lift_var_env r_x2 (SVar p)) \\<noteq>\n        lift_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n            (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r\")\n   apply (cut_tac t_sub=\"dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau\"\n      and p_sub=\"add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)\" and r_s=\"r_x2\" and r=\"SVar p\" in lift_sol_subst_penv)\n   apply (case_tac \"add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a) p \\<noteq> r\")\n    apply (simp add: add_use_env_def)\n    apply (simp add: fresh_list_def)\n   apply (auto)\n    (* prelim: (t_sub, p_sub)( X1* ) \\<le> P1 *)\n  apply (cut_tac r_sc=\"dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n           (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x1\"\n      and r_sb=\"comp_use_env rx1 r_exaa\" and r_sa=\"r_s\" in trans_leq_use_env)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (rule_tac r_sb=\"comp_use_env rx1 (lift_use_env rx2 r)\" in trans_leq_use_env)\n      apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n       apply (simp_all)\n    apply (rule_tac self_comp_leq_use_env1)\n   apply (rule_tac st_diff_comp_leq_use_env)\n   apply (simp)\n    (* prelim: (t_sub, p_sub)(lift( X2* )) \\<le> P1 *)\n  apply (cut_tac r_sc=\"lift_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n          (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r\"\n      and r_sb=\"comp_use_env (lift_use_env rx2 r) r_exb\" and r_sa=\"r_s\" in trans_leq_use_env)\n    apply (rule_tac dist_comp_leq_use_env)\n     apply (rule_tac r_sb=\"comp_use_env rx1 (lift_use_env rx2 r)\" in trans_leq_use_env)\n      apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n       apply (simp_all)\n     apply (rule_tac self_comp_leq_use_env2)\n    apply (rule_tac r_sb=\"diff_use_env r_s r_exaa\" in trans_leq_use_env)\n     apply (rule_tac self_diff_leq_use_env)\n    apply (simp)\n   apply (rule_tac st_diff_comp_leq_use_env)\n   apply (rule_tac t=\"diff_use_env (lift_use_env\n             (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n               (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r) r_exb\" and\n          s=\"lift_use_env (diff_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n               (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r_exb) r\" in subst)\n    apply (simp add: lift_diff_use_env)\n   apply (rule_tac dist_lift_leq_use_env)\n   apply (simp)\n    (* defining new p_sub *)\n  apply (rule_tac x=\"add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)\" in exI)\n  apply (auto)\n    (* p_sub domain containment *)\n        apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n         apply (auto)\n        apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n         apply (auto)\n        apply (rule_tac add_psub_dom)\n         apply (rule_tac add_psub_dom)\n          apply (rule_tac comp_psub_dom)\n           apply (rule_tac ds=\"set_diff ds2 ds\" in subset_psub_dom)\n            apply (simp)\n           apply (rule_tac set_diff_subset)\n            apply (auto)\n          apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_psub_dom)\n           apply (simp)\n          apply (rule_tac set_diff_subset)\n           apply (auto)\n         apply (simp add: set_diff_def)\n         apply (auto)\n        apply (simp add: set_diff_def)\n        apply (auto)\n    (* initial permission containment *)\n       apply (simp add: dir_list_append_eq)\n       apply (simp add: comp_sol_subst_penv)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (simp_all)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac r_sb=\"diff_use_env r_s r_exaa\" in trans_leq_use_env)\n         apply (rule_tac self_diff_leq_use_env)\n        apply (simp_all)\n    (* requirements containment. primitive case *)\n      apply (case_tac \"req_type tau = Prim\")\n       apply (cut_tac t_sub=\"dir_add_env (dir_list_add_env t_sub (la @ l)) aa tau\" and r_sv=\"comp_var_env r_x1 (lift_var_env r_x2 (SVar p))\"\n        and p_sub=\"add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)\" and px=\"XType aa\" in ifz_sol_subst_penv_gen)\n        apply (simp add: dir_add_env_def)\n       apply (auto)\n       apply (rule_tac diff_leq_use_env)\n       apply (rule_tac leq_empty_use_env)\n    (* - non-primitive case *)\n      apply (simp add: app_req_def)\n      apply (simp add: dir_list_append_eq)\n      apply (rule_tac r_sb=\"diff_use_env (comp_use_env rx1 rx2) (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_exa)\" in trans_leq_use_env)\n       apply (simp)\n      apply (rule_tac r_sb=\"diff_use_env (comp_use_env rx1 (lift_use_env rx2 r)) (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_exa)\" in trans_leq_use_env)\n       apply (rule_tac lhs_dist_dcl_use_env)\n       apply (rule_tac rhs_dist_dcl_use_env)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac self_comp_leq_use_env1)\n       apply (rule_tac comp_leq_use_env2)\n       apply (rule_tac unroll_dcl_use_env)\n       apply (rule_tac dist_diff_leq_use_env)\n       apply (rule_tac lhs_flip_use_env)\n       apply (rule_tac rhs_flip_use_env)\n       apply (rule_tac unroll_dcl_use_env)\n       apply (rule_tac dist_diff_leq_use_env)\n       apply (rule_tac spec_diff_lift_leq_use_env)\n      apply (rule_tac r_s=\"r_s\" in crush_leq_use_env)\n        apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_exa)\" in trans_leq_use_env)\n         apply (rule_tac dist_diff_leq_use_env)\n         apply (simp_all)\n        apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n        apply (simp_all)\n      apply (rule_tac r_sb=\"diff_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n        (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) (comp_var_env r_x1 (lift_var_env r_x2 (SVar p)))) r_ex\" in trans_leq_use_env)\n       apply (rule_tac r_sb=\"diff_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n        (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a))\n        (comp_var_env r_x1 (lift_var_env r_x2 (SVar p)))) (comp_use_env r_exaa r_exb)\" in trans_leq_use_env)\n        apply (simp add: comp_sol_subst_penv)\n        apply (rule_tac lhs_dist_dcl_use_env)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (rule_tac comp_leq_use_env1)\n         apply (rule_tac lhs_unroll_dcl_use_env)\n         apply (rule_tac diff_leq_use_env)\n         apply (simp)\n        apply (rule_tac comp_leq_use_env2)\n        apply (rule_tac lhs_flip_use_env)\n        apply (rule_tac lhs_unroll_dcl_use_env)\n        apply (rule_tac diff_leq_use_env)\n       apply (rule_tac t=\"diff_use_env (lift_use_env\n             (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n               (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r) r_exb\" and\n          s=\"lift_use_env (diff_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n               (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r_exb) r\" in subst)\n         apply (simp add: lift_diff_use_env)\n        apply (rule_tac dist_lift_leq_use_env)\n        apply (simp)\n       apply (rule_tac r_s=\"r_s\" in crush_leq_use_env)\n         apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_exa)\" in trans_leq_use_env)\n          apply (rule_tac t=\"diff_use_env r_s (comp_use_env r_exaa r_exb)\" and s=\"super_norm_use_env r_s r_s3\" in subst)\n           apply (simp)\n          apply (rule_tac rhs_snorm_leq_use_env2)\n           apply (rule_tac self_diff_leq_use_env)\n          apply (simp_all)\n        apply (simp add: comp_sol_subst_penv)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (simp_all)\n       apply (rule_tac self_diff_leq_use_env)\n      apply (rule_tac dist_diff_leq_use_env)\n      apply (rule_tac if_zero_leq_var_env)\n      apply (rule_tac id_leq_use_env)\n    (* subtractant containment *)\n     apply (rule_tac r_sb=\"cut_use_env (comp_use_env (comp_use_env rx1 r_exaa) (comp_use_env (lift_use_env rx2 r) r_exb))\" in trans_leq_use_env)\n      apply (rule_tac r_s=\"r_s\" in dist_diff_leq_use_env_rev)\n       apply (rule_tac r_sb=\"comp_use_env r_s (comp_use_env rx1 (lift_use_env rx2 r))\" in trans_leq_use_env)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (rule_tac id_leq_use_env)\n        apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n         apply (simp_all)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (rule_tac comp_leq_use_env2)\n         apply (rule_tac self_comp_leq_use_env1)\n        apply (rule_tac comp_leq_use_env1)\n        apply (simp)\n       apply (rule_tac dist_comp_leq_use_env)\n        apply (rule_tac comp_leq_use_env2)\n        apply (rule_tac self_comp_leq_use_env2)\n       apply (rule_tac comp_leq_use_env1)\n       apply (rule_tac r_sb=\"diff_use_env r_s r_exaa\" in trans_leq_use_env)\n        apply (rule_tac self_diff_leq_use_env)\n       apply (simp)\n      apply (rule_tac r_sb=\"diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_exa)\" in trans_leq_use_env)\n       apply (rule_tac r_sb=\"diff_use_env r_s (comp_use_env (comp_use_env r_exaa r_exb) (comp_use_env rx1 (lift_use_env rx2 r)))\" in trans_leq_use_env)\n        apply (rule_tac dist_diff_leq_use_env_gen)\n         apply (rule_tac id_leq_use_env)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (rule_tac dist_comp_leq_use_env)\n          apply (rule_tac comp_leq_use_env2)\n          apply (rule_tac self_comp_leq_use_env1)\n         apply (rule_tac comp_leq_use_env1)\n         apply (rule_tac self_comp_leq_use_env1)\n        apply (rule_tac dist_comp_leq_use_env)\n         apply (rule_tac comp_leq_use_env2)\n         apply (rule_tac self_comp_leq_use_env2)\n        apply (rule_tac comp_leq_use_env1)\n        apply (rule_tac self_comp_leq_use_env2)\n       apply (rule_tac rhs_unroll_dcl_use_env)\n       apply (rule_tac dist_diff_leq_use_env_gen)\n        apply (rule_tac t=\"diff_use_env r_s (comp_use_env r_exaa r_exb)\" and s=\"super_norm_use_env r_s r_s3\" in subst)\n         apply (simp)\n        apply (rule_tac rhs_snorm_leq_use_env2)\n         apply (rule_tac id_leq_use_env)\n        apply (simp_all)\n      apply (rule_tac self_comp_leq_use_env1)\n     apply (rule_tac rhs_cut_leq_use_env)\n     apply (simp add: dir_list_append_eq)\n     apply (simp add: comp_sol_subst_penv)\n     apply (rule_tac lhs_dist_cut_leq_use_env)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac lhs_dist_cut_leq_use_env)\n      apply (rule_tac dist_comp_leq_use_env)\n       apply (rule_tac comp_leq_use_env1)\n       apply (rule_tac comp_leq_use_env2)\n       apply (simp)\n      apply (rule_tac cut_leq_use_env)\n      apply (rule_tac comp_leq_use_env1)\n      apply (rule_tac st_diff_comp_leq_use_env)\n      apply (simp)\n     apply (rule_tac lhs_dist_cut_leq_use_env)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac comp_leq_use_env2)\n      apply (rule_tac comp_leq_use_env2)\n      apply (simp)\n     apply (rule_tac cut_leq_use_env)\n     apply (rule_tac comp_leq_use_env2)\n     apply (rule_tac st_diff_comp_leq_use_env)\n     apply (rule_tac t=\"diff_use_env (lift_use_env\n             (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n               (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r) r_exb\" and\n          s=\"lift_use_env (diff_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n               (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r_exb) r\" in subst)\n      apply (simp add: lift_diff_use_env)\n     apply (rule_tac dist_lift_leq_use_env)\n     apply (simp)\n    (* correctness of expression type *)\n    apply (simp add: dir_add_env_def)\n    (* correctness of unification constraint *)\n   apply (simp add: dir_list_append_eq)\n   apply (rule_tac x=\"FunTy t1 tau r a\" in exI)\n   apply (auto)\n     apply (simp add: dir_add_env_def)\n    apply (simp add: add_use_env_def)\n    apply (simp add: fresh_list_def)\n   apply (simp add: add_use_env_def)\n   apply (simp add: fresh_list_def)\n   apply (case_tac a)\n     apply (auto)\n    (* correctness of constraints: disjointness *)\n  apply (simp add: dir_list_append_eq)\n  apply (rule_tac sol_sat_split)\n   apply (rule_tac sol_sat_disj)\n   apply (rule_tac r_s=\"comp_use_env rx1 (cut_use_env r_exaa)\" in disj_leq_use_env1)\n    apply (rule_tac r_s=\"comp_use_env (lift_use_env rx2 r) (cut_use_env r_exb)\" in disj_leq_use_env2)\n     apply (rule_tac disj_comp_use_env1)\n      apply (rule_tac disj_comp_use_env2)\n       apply (simp)\n      apply (rule_tac cut_disj_use_env)\n      apply (rule_tac r_s=\"diff_use_env r_s r_exb\" in mini_disj_leq_use_env2)\n       apply (rule_tac mini_disj_diff_use_env)\n      apply (rule_tac r_sb=\"comp_use_env rx1 (lift_use_env rx2 r)\" in trans_leq_use_env)\n       apply (rule_tac r_sb=\"super_norm_use_env r_s r_s3\" in trans_leq_use_env)\n        apply (simp)\n        apply (rule_tac dist_diff_leq_use_env_gen)\n         apply (rule_tac id_leq_use_env)\n        apply (rule_tac self_comp_leq_use_env2)\n       apply (rule_tac rhs_snorm_leq_use_env2)\n        apply (simp_all)\n      apply (rule_tac self_comp_leq_use_env1)\n     apply (rule_tac disj_comp_use_env2)\n      apply (rule_tac comm_disj_use_env)\n      apply (rule_tac cut_disj_use_env)\n      apply (rule_tac r_s=\"diff_use_env r_s r_exaa\" in mini_disj_leq_use_env2)\n       apply (rule_tac mini_disj_diff_use_env)\n      apply (rule_tac r_sb=\"comp_use_env rx1 (lift_use_env rx2 r)\" in trans_leq_use_env)\n       apply (rule_tac r_sb=\"super_norm_use_env r_s r_s3\" in trans_leq_use_env)\n        apply (simp)\n        apply (rule_tac dist_diff_leq_use_env_gen)\n         apply (rule_tac id_leq_use_env)\n        apply (rule_tac self_comp_leq_use_env1)\n       apply (rule_tac rhs_snorm_leq_use_env2)\n        apply (simp_all)\n      apply (rule_tac self_comp_leq_use_env2)\n     apply (rule_tac comm_disj_use_env)\n     apply (rule_tac cut_disj_use_env)\n     apply (rule_tac r_s=\"diff_use_env r_s r_exaa\" in mini_disj_leq_use_env2)\n      apply (rule_tac mini_disj_diff_use_env)\n     apply (rule_tac cut_leq_use_env)\n     apply (simp)\n    apply (rule_tac st_diff_comp_leq_use_env)\n    apply (rule_tac r_sb=\"diff_use_env (lift_use_env\n      (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n      (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r) r_exb\" in trans_leq_use_env)\n     apply (rule_tac t=\"diff_use_env (lift_use_env\n             (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n               (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r) r_exb\" and\n          s=\"lift_use_env (diff_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n               (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x2) r_exb) r\" in subst)\n      apply (simp add: lift_diff_use_env)\n     apply (rule_tac dist_lift_leq_use_env)\n     apply (simp)\n    apply (rule_tac dist_diff_leq_use_env_cut)\n     apply (rule_tac id_leq_use_env)\n    apply (rule_tac id_leq_use_env)\n   apply (rule_tac st_diff_comp_leq_use_env)\n   apply (rule_tac r_sb=\"diff_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n             (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x1) r_exaa\" in trans_leq_use_env)\n    apply (simp)\n   apply (rule_tac dist_diff_leq_use_env_cut)\n    apply (rule_tac id_leq_use_env)\n   apply (rule_tac id_leq_use_env)\n    (* - semi-disjointness 1 *)\n  apply (rule_tac sol_sat_split)\n   apply (rule_tac sol_sat_mini_disj)\n   apply (rule_tac cut_mini_disj_use_env)\n   apply (rule_tac r_s=\"r_exb\" in mini_disj_leq_use_env1)\n    apply (rule_tac r_s=\"diff_use_env r_s r_exb\" in mini_disj_leq_use_env2)\n     apply (rule_tac mini_disj_diff_use_env)\n    apply (rule_tac r_sb=\"comp_use_env (diff_use_env r_s r_exb) (cut_use_env r_exaa)\" in trans_leq_use_env)\n     apply (rule_tac dist_comp_leq_use_env)\n      apply (rule_tac id_leq_use_env)\n     apply (rule_tac swap_diff_cut_leq_use_env)\n      apply (simp_all)\n   apply (rule_tac st_diff_comp_leq_use_env)\n   apply (rule_tac r_sb=\"diff_use_env (dir_subst_penv (dir_add_env (dir_list_add_env (dir_list_add_env t_sub l) la) aa tau)\n      (add_use_env (add_use_env (comp_use_env p_sub p_suba) p r) q (as_perm a)) r_x1) r_exaa\" in trans_leq_use_env)\n    apply (rule_tac r_sb=\"comp_use_env rx1 (lift_use_env rx2 r)\" in trans_leq_use_env)\n     apply (rule_tac r_sb=\"r_s3\" in trans_leq_use_env)\n      apply (rule_tac mini_disj_diff_leq_use_env2)\n       apply (simp)\n      apply (rule_tac r_s=\"diff_use_env r_s r_exb\" in mini_disj_leq_use_env2)\n       apply (rule_tac mini_disj_diff_use_env)\n      apply (rule_tac r_sb=\"super_norm_use_env r_s r_s3\" in trans_leq_use_env)\n       apply (simp)\n       apply (rule_tac dist_diff_leq_use_env_gen)\n        apply (rule_tac id_leq_use_env)\n       apply (rule_tac self_comp_leq_use_env2)\n      apply (rule_tac rhs_snorm_leq_use_env2)\n       apply (rule_tac id_leq_use_env)\n      apply (simp_all)\n    apply (rule_tac comp_leq_use_env1)\n    apply (simp)\n   apply (rule_tac dist_diff_leq_use_env_cut)\n    apply (rule_tac id_leq_use_env)\n   apply (rule_tac id_leq_use_env)\n    (* - semi-disjointness 2 *)\n  apply (rule_tac sol_sat_split)\n   apply (rule_tac sol_sat_mini_disj)\n   apply (rule_tac cut_mini_disj_use_env)\n   apply (rule_tac r_s=\"r_exaa\" in mini_disj_leq_use_env1)\n    apply (rule_tac r_s=\"diff_use_env r_s r_exaa\" in mini_disj_leq_use_env2)\n     apply (rule_tac mini_disj_diff_use_env)\n    apply (simp_all)\n    (* > constraint list 1 correctness *)\n  apply (rule_tac sol_sat_split)\n   apply (cut_tac c_list=\"cl1\" and ds=\"ds\" and ds'=\"ds2\" in infer_tvar_crn_list)\n     apply (auto)\n   apply (cut_tac c_list=\"cl1\" and ds=\"ds\" and ds'=\"ds2\" in infer_pvar_crn_list)\n     apply (auto)\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)\n   apply (rule_tac dir_add_sol_sat)\n    apply (rule_tac dir_list_add_sol_sat)\n     apply (rule_tac add_psub_sol_sat)\n      apply (rule_tac add_psub_sol_sat)\n       apply (rule_tac ds=\"set_diff ds2 ds\" in comp_psub_sol_sat1)\n          apply (simp_all)\n       apply (simp add: set_diff_def)\n       apply (auto)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (cut_tac x=\"x\" and l=\"la\" in dom_list_set_contain)\n    apply (auto)\n   apply (simp add: fresh_list_def)\n   apply (auto)\n    (* > constraint list 2 correctness *)\n  apply (cut_tac c_list=\"cl2\" and ds=\"ds2\" and ds'=\"ds3\" in infer_tvar_crn_list)\n    apply (auto)\n  apply (cut_tac c_list=\"cl2\" and ds=\"ds2\" and ds'=\"ds3\" in infer_pvar_crn_list)\n    apply (auto)\n  apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n   apply (auto)\n  apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n   apply (auto)\n  apply (rule_tac dir_add_sol_sat)\n   apply (rule_tac add_psub_sol_sat)\n    apply (rule_tac add_psub_sol_sat)\n     apply (rule_tac ds=\"set_diff ds3 ds2\" in comp_psub_sol_sat2)\n        apply (simp_all)\n     apply (simp add: set_diff_def)\n     apply (auto)\n   apply (simp add: set_diff_def)\n   apply (auto)\n  apply (simp add: set_diff_def)\n  apply (auto)\n  done\n    \nlemma ivr_app_case: \"\\<lbrakk>\\<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.\n           \\<lbrakk>well_typed env r_s e1 tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e1 tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;\n            sub_range env_v ds; tsub_dom t_sub ds\\<rbrakk>\n           \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \\<and>\n                   fresh_list ds (dom_list l) \\<and>\n                   dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n                   (\\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \\<and>\n                            leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \\<and>\n                            leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \\<and>\n                            leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \\<and>\n                            dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \\<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);\n        \\<And>tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub.\n           \\<lbrakk>well_typed env r_s e2 tau (diff_use_env r_s r_ex) r_x; infer_type env_v ds e2 tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;\n            sub_range env_v ds; tsub_dom t_sub ds\\<rbrakk>\n           \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) ds' \\<and>\n                   fresh_list ds (dom_list l) \\<and>\n                   dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n                   (\\<exists>p_sub. psub_dom p_sub (set_diff ds' ds) \\<and>\n                            leq_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv) r_s \\<and>\n                            leq_use_env (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_xv) r_ex) r_x \\<and>\n                            leq_use_env (cut_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub r_mv)) r_ex \\<and>\n                            dir_subst_type (dir_list_add_env t_sub l) p_sub tau_v tau \\<and> dir_sol_sat (dir_list_add_env t_sub l) p_sub c_list);\n        spec_env env_v env t_sub; sub_range env_v ds; tsub_dom t_sub ds; well_typed env r_s e1 (FunTy t1 tau r a) r_s2 rx1;\n        infer_type env_v ds e1 tau_f r_s1 r_x1 r_m1 cl1 ds2; well_typed env r_s2 e2 t1 r_s3 rx2; infer_type env_v ds2 e2 t1a r_s2a r_x2 r_m2 cl2 ds3;\n        leq_use_env (diff_use_env r_s r_ex) (diff_use_env r_s3 (comp_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_exa));\n        leq_use_env (comp_use_env rx1 (lift_use_env rx2 r)) r_s3; disj_use_env rx1 (lift_use_env rx2 r); leq_use_env r_x (diff_use_env r_s r_ex);\n        leq_use_env r_exa r_s; leq_use_env (app_req rx1 rx2 r tau r_exa) r_x;\n        finite_dom (comp_var_env (comp_var_env r_s1 r_x1) (comp_var_env r_s2a (lift_var_env r_x2 (SVar p)))) d; fresh_list ds3 [aa, p, q]\\<rbrakk>\n       \\<Longrightarrow> \\<exists>l. tsub_dom (dir_list_add_env t_sub l) (insert aa (insert p (insert q ds3))) \\<and>\n               fresh_list ds (dom_list l) \\<and>\n               dir_subst_tenv (dir_list_add_env t_sub l) env_v = env \\<and>\n               (\\<exists>p_sub. psub_dom p_sub (set_diff (insert aa (insert p (insert q ds3))) ds) \\<and>\n                        leq_use_env\n                         (dir_subst_penv (dir_list_add_env t_sub l) p_sub\n                           (comp_var_env (comp_var_env r_s1 r_x1) (comp_var_env r_s2a (lift_var_env r_x2 (SVar p)))))\n                         r_s \\<and>\n                        leq_use_env\n                         (diff_use_env (dir_subst_penv (dir_list_add_env t_sub l) p_sub (ifz_var_env (XType aa) (comp_var_env r_x1 (lift_var_env r_x2 (SVar p)))))\n                           r_ex)\n                         r_x \\<and>\n                        leq_use_env\n                         (cut_use_env\n                           (dir_subst_penv (dir_list_add_env t_sub l) p_sub\n                             (comp_var_env (comp_var_env r_m1 r_x1) (comp_var_env r_m2 (lift_var_env r_x2 (SVar p))))))\n                         r_ex \\<and>\n                        dir_list_add_env t_sub l aa = Some tau \\<and>\n                        (\\<exists>tau_x. (\\<exists>t1_x. dir_subst_type (dir_list_add_env t_sub l) p_sub t1a t1_x \\<and>\n                                         (\\<exists>t2_x. dir_list_add_env t_sub l aa = Some t2_x \\<and> tau_x = FunTy t1_x t2_x (p_sub p) (as_aff (p_sub q)))) \\<and>\n                                 dir_subst_type (dir_list_add_env t_sub l) p_sub tau_f tau_x) \\<and>\n                        dir_sol_sat (dir_list_add_env t_sub l) p_sub\n                         (disj_crn r_x1 (lift_var_env r_x2 (SVar p)) d @ semi_disj_crn r_m2 r_x1 d @ semi_disj_crn r_m1 r_s2a d @ cl1 @ cl2))\" \n  apply (cut_tac env=\"env\" and ?e1.0=\"e1\" and ?e2.0=\"e2\" in ivr_induct_format)\n    apply (auto) \n  apply (cut_tac e=\"e1\" and env_v=\"env_v\" and t_sub=\"t_sub\" and ds=\"ds\" in ivrac_coerce)\n        apply (auto)\n  apply (cut_tac e=\"e2\" and env_v=\"env_v\" and t_sub=\"dir_list_add_env t_sub l\" and ds=\"ds2\" in ivrac_coerce)\n        apply (auto)\n    apply (rule_tac self_spec_env)\n   apply (rule_tac ds=\"ds\" in subset_sub_range)\n    apply (simp)\n   apply (rule_tac infer_x_subset)\n   apply (auto)\n  apply (rule_tac env_v=\"env_v\" and r_s=\"r_s\" and ?r_s3.0=\"r_s3\" and ?e1.0=\"e1\" and ?e2.0=\"e2\" \n      and ?r_s1.0=\"r_s1\" and ?r_x1.0=\"r_x1\" and ?r_m1.0=\"r_m1\" and r_s2a=\"r_s2a\" and ?r_x2.0=\"r_x2\" and ?r_m2.0=\"r_m2\" in ivrac_main)\n                      apply (auto)\n  apply (rule_tac r_sb=\"r_s2\" in trans_leq_use_env)\n   apply (rule_tac well_typed_perm_leq)\n   apply (auto)\n  apply (rule_tac well_typed_perm_leq)\n  apply (auto)\n  done\n    \n    (*\n      [ Gamma, P |- e: tau, P - EX, Q \\<and> Infer(Gamma*, X, e) = (tau*, P*, Q*, R*, K, X') \\<and> \\<sigma>( Gamma* ) = Gamma\n        \\<and> range( Gamma* ) \\<subseteq> X \\<and> dom(\\<sigma>) \\<subseteq> X ] \\<Longrightarrow>\n          (\\<exists> \\<sigma>* \\<sigma>' \\<rho>. \\<sigma>' = \\<sigma> o \\<sigma>* \\<and> dom(\\<sigma>') \\<subseteq> X \\<and> fresh(\\<sigma>*, X) \\<and> \\<sigma>'( Gamma* ) = Gamma\n            \\<and> dom( \\<rho> ) \\<subseteq> X' - X \\<and> (\\<sigma>', \\<rho>)( P* ) \\<le> P \\<and> (\\<sigma>', \\<rho>)( Q* ) - EX \\<le> Q \\<and> (\\<sigma>', \\<rho>)( R* ) \\<le> EX\n            \\<and> (\\<sigma>', \\<rho>)( tau* ) = tau \\<and> (\\<sigma>', \\<rho>) |= K)\n    *)\nlemma ivr_partial: \"\\<lbrakk> well_typed env r_s e tau (diff_use_env r_s r_ex) r_x;\n  infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; spec_env env_v env t_sub;\n  sub_range env_v ds; tsub_dom t_sub ds \\<rbrakk> \\<Longrightarrow>\n  (\\<exists> l t_subx p_sub. t_subx = dir_list_add_env t_sub l \\<and> tsub_dom t_subx ds' \\<and>\n    fresh_list ds (dom_list l) \\<and> dir_subst_tenv t_subx env_v = env \\<and>\n    psub_dom p_sub (set_diff ds' ds) \\<and> leq_use_env (dir_subst_penv t_subx p_sub r_sv) r_s \\<and>\n    leq_use_env (diff_use_env (dir_subst_penv t_subx p_sub r_xv) r_ex) r_x \\<and> leq_use_env (cut_use_env (dir_subst_penv t_subx p_sub r_mv)) r_ex \\<and>\n    dir_subst_type t_subx p_sub tau_v tau \\<and> dir_sol_sat t_subx p_sub c_list)\"  \n  apply (induct e arbitrary: tau r_s r_x r_ex env env_v ds tau_v r_sv r_xv r_mv c_list ds' t_sub)\n        apply (auto)\n    (* const case *)\n        apply (rule_tac ivr_const_case)\n              apply (auto)\n    (* op case *)\n       apply (rule_tac ivr_op_case)\n           apply (auto)\n    (* var case *)\n      apply (rule_tac ivr_var_case)\n                   apply (auto)\n    (* pair case *)\n     apply (rule_tac ivr_pair_case)\n                      apply (auto)\n    (* if case *)\n    apply (rule_tac ivr_if_case)\n                apply (auto)\n    (* lam case *)\n   apply (rule_tac ivr_lam_case)\n                    apply (auto)\n    (* app case *)\n  apply (rule_tac ivr_app_case)\n                  apply (auto)\n  done\n    \nlemma infer_valid_right: \"\\<lbrakk> well_typed empty_env r_s1 e tau r_s2 rx; infer_type empty_env ds e tau_v r_sv r_xv r_mv c_list ds' \\<rbrakk> \\<Longrightarrow> \\<exists> t_sub p_sub. dir_sol_sat t_sub p_sub c_list\"\n  apply (cut_tac env=\"empty_env\" and env_v=\"empty_env\" and e=\"e\" and r_s=\"r_s1\" and r_x=\"diff_use_env rx r_s1\" and r_ex=\"r_s1\" and t_sub=\"empty_env\" in ivr_partial)\n       apply (auto)\n     apply (rule_tac well_typed_end_perm_lbound)\n     apply (simp)\n    apply (simp add: spec_env_def)\n    apply (simp add: empty_env_def)\n   apply (simp add: sub_range_def)\n   apply (simp add: empty_env_def)\n  apply (simp add: tsub_dom_def)\n  apply (simp add: empty_env_def)\n  done\n\nend", "meta": {"author": "anon-ef", "repo": "perm_lang_ef2", "sha": "0fcb6e4c175193cc7b94f297a8aaa605f502d711", "save_path": "github-repos/isabelle/anon-ef-perm_lang_ef2", "path": "github-repos/isabelle/anon-ef-perm_lang_ef2/perm_lang_ef2-0fcb6e4c175193cc7b94f297a8aaa605f502d711/perm_ref/InferComplete.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5078118642792044, "lm_q2_score": 0.4960938294709195, "lm_q1q2_score": 0.2519223324010374}}
{"text": "(*  Title:      Uint.thy\n    Author:     Peter Lammich, TU Munich\n    Author:     Andreas Lochbihler, ETH Zurich\n*)\n\nchapter \\<open>Unsigned words of default size\\<close>\n\ntheory Uint imports\n  Word_Type_Copies\n  Code_Target_Integer_Bit\nbegin\n\ntext \\<open>\n  This theory provides access to words in the target languages of the code generator\n  whose bit width is the default of the target language. To that end, the type \\<open>uint\\<close>\n  models words of width \\<open>dflt_size\\<close>, but \\<open>dflt_size\\<close> is known only to be positive.\n\n  Usage restrictions:\n  Default-size words (type \\<open>uint\\<close>) cannot be used for evaluation, because \n  the results depend on the particular choice of word size in the target language\n  and implementation. Symbolic evaluation has not yet been set up for \\<open>uint\\<close>.\n\\<close>\n\ntext \\<open>The default size type\\<close>\ntypedecl dflt_size\n\ninstantiation dflt_size :: typerep begin\ndefinition \"typerep_class.typerep \\<equiv>  \\<lambda>_ :: dflt_size itself. Typerep.Typerep (STR ''Uint.dflt_size'') []\"\ninstance ..\nend\n\nconsts dflt_size_aux :: \"nat\"\nspecification (dflt_size_aux) dflt_size_aux_g0: \"dflt_size_aux > 0\"\n  by auto\nhide_fact dflt_size_aux_def\n\ninstantiation dflt_size :: len begin\ndefinition \"len_of_dflt_size (_ :: dflt_size itself) \\<equiv> dflt_size_aux\"\ninstance by(intro_classes)(simp add: len_of_dflt_size_def dflt_size_aux_g0)\nend\n\nabbreviation \"dflt_size \\<equiv> len_of (TYPE (dflt_size))\"\n\ncontext includes integer.lifting begin\nlift_definition dflt_size_integer :: integer is \"int dflt_size\" .\ndeclare dflt_size_integer_def[code del]\n  \\<comment> \\<open>The code generator will substitute a machine-dependent value for this constant\\<close>\n\nlemma dflt_size_by_int[code]: \"dflt_size = nat_of_integer dflt_size_integer\"\nby transfer simp\n\nlemma dflt_size[simp]: \n  \"dflt_size > 0\"\n  \"dflt_size \\<ge> Suc 0\"\n  \"\\<not> dflt_size < Suc 0\"\n  using len_gt_0[where 'a=dflt_size]\n  by (simp_all del: len_gt_0)\nend\n\nsection \\<open>Type definition and primitive operations\\<close>\n\ntypedef uint = \\<open>UNIV :: dflt_size word set\\<close> ..\n\nglobal_interpretation uint: word_type_copy Abs_uint Rep_uint\n  using type_definition_uint by (rule word_type_copy.intro)\n\nsetup_lifting type_definition_uint\n\ndeclare uint.of_word_of [code abstype]\n\ndeclare Quotient_uint [transfer_rule]\n\ninstantiation uint :: \\<open>{comm_ring_1, semiring_modulo, equal, linorder}\\<close>\nbegin\n\nlift_definition zero_uint :: uint is 0 .\nlift_definition one_uint :: uint is 1 .\nlift_definition plus_uint :: \\<open>uint \\<Rightarrow> uint \\<Rightarrow> uint\\<close> is \\<open>(+)\\<close> .\nlift_definition uminus_uint :: \\<open>uint \\<Rightarrow> uint\\<close> is uminus .\nlift_definition minus_uint :: \\<open>uint \\<Rightarrow> uint \\<Rightarrow> uint\\<close> is \\<open>(-)\\<close> .\nlift_definition times_uint :: \\<open>uint \\<Rightarrow> uint \\<Rightarrow> uint\\<close> is \\<open>(*)\\<close> .\nlift_definition divide_uint :: \\<open>uint \\<Rightarrow> uint \\<Rightarrow> uint\\<close> is \\<open>(div)\\<close> .\nlift_definition modulo_uint :: \\<open>uint \\<Rightarrow> uint \\<Rightarrow> uint\\<close> is \\<open>(mod)\\<close> .\nlift_definition equal_uint :: \\<open>uint \\<Rightarrow> uint \\<Rightarrow> bool\\<close> is \\<open>HOL.equal\\<close> .\nlift_definition less_eq_uint :: \\<open>uint \\<Rightarrow> uint \\<Rightarrow> bool\\<close> is \\<open>(\\<le>)\\<close> .\nlift_definition less_uint :: \\<open>uint \\<Rightarrow> uint \\<Rightarrow> bool\\<close> is \\<open>(<)\\<close> .\n\nglobal_interpretation uint: word_type_copy_ring Abs_uint Rep_uint\n  by standard (fact zero_uint.rep_eq one_uint.rep_eq\n    plus_uint.rep_eq uminus_uint.rep_eq minus_uint.rep_eq\n    times_uint.rep_eq divide_uint.rep_eq modulo_uint.rep_eq\n    equal_uint.rep_eq less_eq_uint.rep_eq less_uint.rep_eq)+\n\ninstance proof -\n  show \\<open>OFCLASS(uint, comm_ring_1_class)\\<close>\n    by (rule uint.of_class_comm_ring_1)\n  show \\<open>OFCLASS(uint, semiring_modulo_class)\\<close>\n    by (fact uint.of_class_semiring_modulo)\n  show \\<open>OFCLASS(uint, equal_class)\\<close>\n    by (fact uint.of_class_equal)\n  show \\<open>OFCLASS(uint, linorder_class)\\<close>\n    by (fact uint.of_class_linorder)\nqed\n\nend\n\ninstantiation uint :: ring_bit_operations\nbegin\n\nlift_definition bit_uint :: \\<open>uint \\<Rightarrow> nat \\<Rightarrow> bool\\<close> is bit .\nlift_definition not_uint :: \\<open>uint \\<Rightarrow> uint\\<close> is \\<open>Bit_Operations.not\\<close> .\nlift_definition and_uint :: \\<open>uint \\<Rightarrow> uint \\<Rightarrow> uint\\<close> is \\<open>Bit_Operations.and\\<close> .\nlift_definition or_uint :: \\<open>uint \\<Rightarrow> uint \\<Rightarrow> uint\\<close> is \\<open>Bit_Operations.or\\<close> .\nlift_definition xor_uint :: \\<open>uint \\<Rightarrow> uint \\<Rightarrow> uint\\<close> is \\<open>Bit_Operations.xor\\<close> .\nlift_definition mask_uint :: \\<open>nat \\<Rightarrow> uint\\<close> is mask .\nlift_definition push_bit_uint :: \\<open>nat \\<Rightarrow> uint \\<Rightarrow> uint\\<close> is push_bit .\nlift_definition drop_bit_uint :: \\<open>nat \\<Rightarrow> uint \\<Rightarrow> uint\\<close> is drop_bit .\nlift_definition signed_drop_bit_uint :: \\<open>nat \\<Rightarrow> uint \\<Rightarrow> uint\\<close> is signed_drop_bit .\nlift_definition take_bit_uint :: \\<open>nat \\<Rightarrow> uint \\<Rightarrow> uint\\<close> is take_bit .\nlift_definition set_bit_uint :: \\<open>nat \\<Rightarrow> uint \\<Rightarrow> uint\\<close> is Bit_Operations.set_bit .\nlift_definition unset_bit_uint :: \\<open>nat \\<Rightarrow> uint \\<Rightarrow> uint\\<close> is unset_bit .\nlift_definition flip_bit_uint :: \\<open>nat \\<Rightarrow> uint \\<Rightarrow> uint\\<close> is flip_bit .\n\nglobal_interpretation uint: word_type_copy_bits Abs_uint Rep_uint signed_drop_bit_uint\n  by standard (fact bit_uint.rep_eq not_uint.rep_eq and_uint.rep_eq or_uint.rep_eq xor_uint.rep_eq\n    mask_uint.rep_eq push_bit_uint.rep_eq drop_bit_uint.rep_eq signed_drop_bit_uint.rep_eq take_bit_uint.rep_eq\n    set_bit_uint.rep_eq unset_bit_uint.rep_eq flip_bit_uint.rep_eq)+\n\ninstance\n  by (fact uint.of_class_ring_bit_operations)\n\nend\n\nlift_definition uint_of_nat :: \\<open>nat \\<Rightarrow> uint\\<close>\n  is word_of_nat .\n\nlift_definition nat_of_uint :: \\<open>uint \\<Rightarrow> nat\\<close>\n  is unat .\n\nlift_definition uint_of_int :: \\<open>int \\<Rightarrow> uint\\<close>\n  is word_of_int .\n\nlift_definition int_of_uint :: \\<open>uint \\<Rightarrow> int\\<close>\n  is uint .\n\ncontext\n  includes integer.lifting\nbegin\n\nlift_definition Uint :: \\<open>integer \\<Rightarrow> uint\\<close>\n  is word_of_int .\n\nlift_definition integer_of_uint :: \\<open>uint \\<Rightarrow> integer\\<close>\n  is uint .\n\nend\n\nglobal_interpretation uint: word_type_copy_more Abs_uint Rep_uint signed_drop_bit_uint\n  uint_of_nat nat_of_uint uint_of_int int_of_uint Uint integer_of_uint\n  apply standard\n       apply (simp_all add: uint_of_nat.rep_eq nat_of_uint.rep_eq\n         uint_of_int.rep_eq int_of_uint.rep_eq\n         Uint.rep_eq integer_of_uint.rep_eq integer_eq_iff)\n  done\n\ninstantiation uint :: \"{size, msb, lsb, set_bit, bit_comprehension}\"\nbegin\n\nlift_definition size_uint :: \\<open>uint \\<Rightarrow> nat\\<close> is size .\n\nlift_definition msb_uint :: \\<open>uint \\<Rightarrow> bool\\<close> is msb .\nlift_definition lsb_uint :: \\<open>uint \\<Rightarrow> bool\\<close> is lsb .\n\ntext \\<open>Workaround: avoid name space clash by spelling out \\<^text>\\<open>lift_definition\\<close> explicitly.\\<close>\n\ndefinition set_bit_uint :: \\<open>uint \\<Rightarrow> nat \\<Rightarrow> bool \\<Rightarrow> uint\\<close>\n  where set_bit_uint_eq: \\<open>set_bit_uint a n b = (if b then Bit_Operations.set_bit else unset_bit) n a\\<close>\n\ncontext\n  includes lifting_syntax\nbegin\n\nlemma set_bit_uint_transfer [transfer_rule]:\n  \\<open>(cr_uint ===> (=) ===> (\\<longleftrightarrow>) ===> cr_uint) Generic_set_bit.set_bit Generic_set_bit.set_bit\\<close>\n  by (simp only: set_bit_eq [abs_def] set_bit_uint_eq [abs_def]) transfer_prover\n\nend\n\nlift_definition set_bits_uint :: \\<open>(nat \\<Rightarrow> bool) \\<Rightarrow> uint\\<close> is set_bits .\nlift_definition set_bits_aux_uint :: \\<open>(nat \\<Rightarrow> bool) \\<Rightarrow> nat \\<Rightarrow> uint \\<Rightarrow> uint\\<close> is set_bits_aux .\n\nglobal_interpretation uint: word_type_copy_misc Abs_uint Rep_uint signed_drop_bit_uint\n  uint_of_nat nat_of_uint uint_of_int int_of_uint Uint integer_of_uint dflt_size set_bits_aux_uint\n  by (standard; transfer) simp_all\n\ninstance using uint.of_class_bit_comprehension\n  uint.of_class_set_bit uint.of_class_lsb\n  by simp_all standard\n\nend\n\nsection \\<open>Code setup\\<close>\n\ncode_printing code_module Uint \\<rightharpoonup> (SML)\n\\<open>\nstructure Uint : sig\n  val set_bit : Word.word -> IntInf.int -> bool -> Word.word\n  val shiftl : Word.word -> IntInf.int -> Word.word\n  val shiftr : Word.word -> IntInf.int -> Word.word\n  val shiftr_signed : Word.word -> IntInf.int -> Word.word\n  val test_bit : Word.word -> IntInf.int -> bool\nend = struct\n\nfun set_bit x n b =\n  let val mask = Word.<< (0wx1, Word.fromLargeInt (IntInf.toLarge n))\n  in if b then Word.orb (x, mask)\n     else Word.andb (x, Word.notb mask)\n  end\n\nfun shiftl x n =\n  Word.<< (x, Word.fromLargeInt (IntInf.toLarge n))\n\nfun shiftr x n =\n  Word.>> (x, Word.fromLargeInt (IntInf.toLarge n))\n\nfun shiftr_signed x n =\n  Word.~>> (x, Word.fromLargeInt (IntInf.toLarge n))\n\nfun test_bit x n =\n  Word.andb (x, Word.<< (0wx1, Word.fromLargeInt (IntInf.toLarge n))) <> Word.fromInt 0\n\nend; (* struct Uint *)\\<close>\ncode_reserved SML Uint\n\ncode_printing code_module Uint \\<rightharpoonup> (Haskell)\n \\<open>module Uint(Int, Word, dflt_size) where\n\n  import qualified Prelude\n  import Data.Int(Int)\n  import Data.Word(Word)\n  import qualified Data.Bits\n\n  dflt_size :: Prelude.Integer\n  dflt_size = Prelude.toInteger (bitSize_aux (0::Word)) where\n    bitSize_aux :: (Data.Bits.Bits a, Prelude.Bounded a) => a -> Int\n    bitSize_aux = Data.Bits.bitSize\\<close>\n  and (Haskell_Quickcheck)\n \\<open>module Uint(Int, Word, dflt_size) where\n\n  import qualified Prelude\n  import Data.Int(Int)\n  import Data.Word(Word)\n  import qualified Data.Bits\n\n  dflt_size :: Prelude.Int\n  dflt_size = bitSize_aux (0::Word) where\n    bitSize_aux :: (Data.Bits.Bits a, Prelude.Bounded a) => a -> Int\n    bitSize_aux = Data.Bits.bitSize\n\\<close>\ncode_reserved Haskell Uint dflt_size\n\ntext \\<open>\n  OCaml and Scala provide only signed bit numbers, so we use these and \n  implement sign-sensitive operations like comparisons manually.\n\\<close>\n\ncode_printing code_module \"Uint\" \\<rightharpoonup> (OCaml)\n\\<open>module Uint : sig\n  type t = int\n  val dflt_size : Z.t\n  val less : t -> t -> bool\n  val less_eq : t -> t -> bool\n  val set_bit : t -> Z.t -> bool -> t\n  val shiftl : t -> Z.t -> t\n  val shiftr : t -> Z.t -> t\n  val shiftr_signed : t -> Z.t -> t\n  val test_bit : t -> Z.t -> bool\n  val int_mask : int\n  val int32_mask : int32\n  val int64_mask : int64\nend = struct\n\ntype t = int\n\nlet dflt_size = Z.of_int Sys.int_size;;\n\n(* negative numbers have their highest bit set, \n   so they are greater than positive ones *)\nlet less x y =\n  if x<0 then\n    y<0 && x<y\n  else y < 0 || x < y;;\n\nlet less_eq x y =\n  if x < 0 then\n    y < 0 &&  x <= y\n  else y < 0 || x <= y;;\n\nlet set_bit x n b =\n  let mask = 1 lsl (Z.to_int n)\n  in if b then x lor mask\n     else x land (lnot mask);;\n\nlet shiftl x n = x lsl (Z.to_int n);;\n\nlet shiftr x n = x lsr (Z.to_int n);;\n\nlet shiftr_signed x n = x asr (Z.to_int n);;\n\nlet test_bit x n = x land (1 lsl (Z.to_int n)) <> 0;;\n\nlet int_mask =\n  if Sys.int_size < 32 then lnot 0 else 0xFFFFFFFF;;\n\nlet int32_mask = \n  if Sys.int_size < 32 then Int32.pred (Int32.shift_left Int32.one Sys.int_size)\n  else Int32.of_string \"0xFFFFFFFF\";;\n\nlet int64_mask = \n  if Sys.int_size < 64 then Int64.pred (Int64.shift_left Int64.one Sys.int_size)\n  else Int64.of_string \"0xFFFFFFFFFFFFFFFF\";;\n\nend;; (*struct Uint*)\\<close>\ncode_reserved OCaml Uint\n\ncode_printing code_module Uint \\<rightharpoonup> (Scala)\n\\<open>object Uint {\ndef dflt_size : BigInt = BigInt(32)\n\ndef less(x: Int, y: Int) : Boolean =\n  if (x < 0) y < 0 && x < y\n  else y < 0 || x < y\n\ndef less_eq(x: Int, y: Int) : Boolean =\n  if (x < 0) y < 0 && x <= y\n  else y < 0 || x <= y\n\ndef set_bit(x: Int, n: BigInt, b: Boolean) : Int =\n  if (b)\n    x | (1 << n.intValue)\n  else\n    x & (1 << n.intValue).unary_~\n\ndef shiftl(x: Int, n: BigInt) : Int = x << n.intValue\n\ndef shiftr(x: Int, n: BigInt) : Int = x >>> n.intValue\n\ndef shiftr_signed(x: Int, n: BigInt) : Int = x >> n.intValue\n\ndef test_bit(x: Int, n: BigInt) : Boolean =\n  (x & (1 << n.intValue)) != 0\n\n} /* object Uint */\\<close>\ncode_reserved Scala Uint\n\n\ntext \\<open>\n  OCaml's conversion from Big\\_int to int demands that the value fits into a signed integer.\n  The following justifies the implementation.\n\\<close>\n\ncontext\n  includes integer.lifting bit_operations_syntax\nbegin\n\ndefinition wivs_mask :: int where \"wivs_mask = 2^ dflt_size - 1\"\nlift_definition wivs_mask_integer :: integer is wivs_mask .\n\n\ndefinition wivs_shift :: int where \"wivs_shift = 2 ^ dflt_size\"\nlift_definition wivs_shift_integer :: integer is wivs_shift .\nlemma [code]: \"wivs_shift_integer = 2 ^ dflt_size\"\n  by transfer (simp add: wivs_shift_def)\n\ndefinition wivs_index :: nat where \"wivs_index == dflt_size - 1\"\nlift_definition wivs_index_integer :: integer is \"int wivs_index\".\nlemma wivs_index_integer_code[code]: \"wivs_index_integer = dflt_size_integer - 1\"\n  by transfer (simp add: wivs_index_def of_nat_diff)\n\ndefinition wivs_overflow :: int where \"wivs_overflow == 2^ (dflt_size - 1)\"\nlift_definition wivs_overflow_integer :: integer is wivs_overflow .\nlemma [code]: \"wivs_overflow_integer = 2 ^ (dflt_size - 1)\"\n  by transfer (simp add: wivs_overflow_def)\n\ndefinition wivs_least :: int where \"wivs_least == - wivs_overflow\"\nlift_definition wivs_least_integer :: integer is wivs_least .\nlemma [code]: \"wivs_least_integer = - (2 ^ (dflt_size - 1))\"\n  by transfer (simp add: wivs_overflow_def wivs_least_def)\n\ndefinition Uint_signed :: \"integer \\<Rightarrow> uint\" where\n  \"Uint_signed i = (if i < wivs_least_integer \\<or> wivs_overflow_integer \\<le> i then undefined Uint i else Uint i)\"\n\nlemma Uint_code [code]:\n  \"Uint i = \n  (let i' = i AND wivs_mask_integer in \n   if bit i' wivs_index then Uint_signed (i' - wivs_shift_integer) else Uint_signed i')\"\n  including undefined_transfer \n  unfolding Uint_signed_def\n  apply transfer\n  apply (subst word_of_int_via_signed)\n       apply (auto simp add: push_bit_of_1 mask_eq_exp_minus_1 word_of_int_via_signed\n         wivs_mask_def wivs_index_def wivs_overflow_def wivs_least_def wivs_shift_def)\n  done\n\nlemma Uint_signed_code [code]:\n  \"Rep_uint (Uint_signed i) = \n  (if i < wivs_least_integer \\<or> i \\<ge> wivs_overflow_integer then Rep_uint (undefined Uint i) else word_of_int (int_of_integer_symbolic i))\"\n  unfolding Uint_signed_def Uint_def int_of_integer_symbolic_def by(simp add: Abs_uint_inverse)\nend\n\ntext \\<open>\n  Avoid @{term Abs_uint} in generated code, use @{term Rep_uint'} instead. \n  The symbolic implementations for code\\_simp use @{term Rep_uint}.\n\n  The new destructor @{term Rep_uint'} is executable.\n  As the simplifier is given the [code abstract] equations literally, \n  we cannot implement @{term Rep_uint} directly, because that makes code\\_simp loop.\n\n  If code generation raises Match, some equation probably contains @{term Rep_uint} \n  ([code abstract] equations for @{typ uint} may use @{term Rep_uint} because\n  these instances will be folded away.)\n\\<close>\n\ndefinition Rep_uint' where [simp]: \"Rep_uint' = Rep_uint\"\n\nlemma Rep_uint'_code [code]: \"Rep_uint' x = (BITS n. bit x n)\"\n  unfolding Rep_uint'_def by transfer (simp add: set_bits_bit_eq)\n\nlift_definition Abs_uint' :: \"dflt_size word \\<Rightarrow> uint\" is \"\\<lambda>x :: dflt_size word. x\" .\n\nlemma Abs_uint'_code [code]:\n  \"Abs_uint' x = Uint (integer_of_int (uint x))\"\nincluding integer.lifting by transfer simp\n\ndeclare [[code drop: \"term_of_class.term_of :: uint \\<Rightarrow> _\"]]\n\nlemma term_of_uint_code [code]:\n  defines \"TR \\<equiv> typerep.Typerep\" and \"bit0 \\<equiv> STR ''Numeral_Type.bit0''\" \n  shows\n  \"term_of_class.term_of x = \n   Code_Evaluation.App (Code_Evaluation.Const (STR ''Uint.uint.Abs_uint'') (TR (STR ''fun'') [TR (STR ''Word.word'')  [TR (STR ''Uint.dflt_size'') []], TR (STR ''Uint.uint'') []]))\n       (term_of_class.term_of (Rep_uint' x))\"\n  by(simp add: term_of_anything)\n\ntext \\<open>Important:\n  We must prevent the reflection oracle (eval-tac) to \n  use our machine-dependent type.\n\\<close>\n\ncode_printing\n  type_constructor uint \\<rightharpoonup>\n  (SML) \"Word.word\" and\n  (Haskell) \"Uint.Word\" and\n  (OCaml) \"Uint.t\" and\n  (Scala) \"Int\" and\n  (Eval) \"*** \\\"Error: Machine dependent type\\\" ***\" and\n  (Quickcheck) \"Word.word\" \n| constant dflt_size_integer \\<rightharpoonup>\n  (SML) \"(IntInf.fromLarge (Int.toLarge Word.wordSize))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.wordSize\" and\n  (Haskell) \"Uint.dflt'_size\" and\n  (OCaml) \"Uint.dflt'_size\" and\n  (Scala) \"Uint.dflt'_size\"\n| constant Uint \\<rightharpoonup>\n  (SML) \"Word.fromLargeInt (IntInf.toLarge _)\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.fromInt\" and\n  (Haskell) \"(Prelude.fromInteger _ :: Uint.Word)\" and\n  (Haskell_Quickcheck) \"(Prelude.fromInteger (Prelude.toInteger _) :: Uint.Word)\" and\n  (Scala) \"_.intValue\"\n| constant Uint_signed \\<rightharpoonup>\n  (OCaml) \"Z.to'_int\"\n| constant \"0 :: uint\" \\<rightharpoonup>\n  (SML) \"(Word.fromInt 0)\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"(Word.fromInt 0)\" and\n  (Haskell) \"(0 :: Uint.Word)\" and\n  (OCaml) \"0\" and\n  (Scala) \"0\"\n| constant \"1 :: uint\" \\<rightharpoonup>\n  (SML) \"(Word.fromInt 1)\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"(Word.fromInt 1)\" and\n  (Haskell) \"(1 :: Uint.Word)\" and\n  (OCaml) \"1\" and\n  (Scala) \"1\"\n| constant \"plus :: uint \\<Rightarrow> _ \" \\<rightharpoonup>\n  (SML) \"Word.+ ((_), (_))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.+ ((_), (_))\" and\n  (Haskell) infixl 6 \"+\" and\n  (OCaml) \"Pervasives.(+)\" and\n  (Scala) infixl 7 \"+\"\n| constant \"uminus :: uint \\<Rightarrow> _\" \\<rightharpoonup>\n  (SML) \"Word.~\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.~\" and\n  (Haskell) \"negate\" and\n  (OCaml) \"Pervasives.(~-)\" and\n  (Scala) \"!(- _)\"\n| constant \"minus :: uint \\<Rightarrow> _\" \\<rightharpoonup>\n  (SML) \"Word.- ((_), (_))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.- ((_), (_))\" and\n  (Haskell) infixl 6 \"-\" and\n  (OCaml) \"Pervasives.(-)\" and\n  (Scala) infixl 7 \"-\"\n| constant \"times :: uint \\<Rightarrow> _ \\<Rightarrow> _\" \\<rightharpoonup>\n  (SML) \"Word.* ((_), (_))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.* ((_), (_))\" and\n  (Haskell) infixl 7 \"*\" and\n  (OCaml) \"Pervasives.( * )\" and\n  (Scala) infixl 8 \"*\"\n| constant \"HOL.equal :: uint \\<Rightarrow> _ \\<Rightarrow> bool\" \\<rightharpoonup>\n  (SML) \"!((_ : Word.word) = _)\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"!((_ : Word.word) = _)\" and\n  (Haskell) infix 4 \"==\" and\n  (OCaml) \"(Pervasives.(=):Uint.t -> Uint.t -> bool)\" and\n  (Scala) infixl 5 \"==\"\n| class_instance uint :: equal \\<rightharpoonup>\n  (Haskell) -\n| constant \"less_eq :: uint \\<Rightarrow> _ \\<Rightarrow> bool\" \\<rightharpoonup>\n  (SML) \"Word.<= ((_), (_))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.<= ((_), (_))\" and\n  (Haskell) infix 4 \"<=\" and\n  (OCaml) \"Uint.less'_eq\" and\n  (Scala) \"Uint.less'_eq\"\n| constant \"less :: uint \\<Rightarrow> _ \\<Rightarrow> bool\" \\<rightharpoonup>\n  (SML) \"Word.< ((_), (_))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.< ((_), (_))\" and\n  (Haskell) infix 4 \"<\" and\n  (OCaml) \"Uint.less\" and\n  (Scala) \"Uint.less\"\n| constant \"Bit_Operations.not :: uint \\<Rightarrow> _\" \\<rightharpoonup>\n  (SML) \"Word.notb\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.notb\" and\n  (Haskell) \"Data'_Bits.complement\" and\n  (OCaml) \"Pervasives.lnot\" and\n  (Scala) \"_.unary'_~\"\n| constant \"Bit_Operations.and :: uint \\<Rightarrow> _\" \\<rightharpoonup>\n  (SML) \"Word.andb ((_),/ (_))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.andb ((_),/ (_))\" and\n  (Haskell) infixl 7 \"Data_Bits..&.\" and\n  (OCaml) \"Pervasives.(land)\" and\n  (Scala) infixl 3 \"&\"\n| constant \"Bit_Operations.or :: uint \\<Rightarrow> _\" \\<rightharpoonup>\n  (SML) \"Word.orb ((_),/ (_))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.orb ((_),/ (_))\" and\n  (Haskell) infixl 5 \"Data_Bits..|.\" and\n  (OCaml) \"Pervasives.(lor)\" and\n  (Scala) infixl 1 \"|\"\n| constant \"Bit_Operations.xor :: uint \\<Rightarrow> _\" \\<rightharpoonup>\n  (SML) \"Word.xorb ((_),/ (_))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.xorb ((_),/ (_))\" and\n  (Haskell) \"Data'_Bits.xor\" and\n  (OCaml) \"Pervasives.(lxor)\" and\n  (Scala) infixl 2 \"^\"\n\ndefinition uint_divmod :: \"uint \\<Rightarrow> uint \\<Rightarrow> uint \\<times> uint\" where\n  \"uint_divmod x y = \n  (if y = 0 then (undefined ((div) :: uint \\<Rightarrow> _) x (0 :: uint), undefined ((mod) :: uint \\<Rightarrow> _) x (0 :: uint)) \n  else (x div y, x mod y))\"\n\ndefinition uint_div :: \"uint \\<Rightarrow> uint \\<Rightarrow> uint\" \nwhere \"uint_div x y = fst (uint_divmod x y)\"\n\ndefinition uint_mod :: \"uint \\<Rightarrow> uint \\<Rightarrow> uint\" \nwhere \"uint_mod x y = snd (uint_divmod x y)\"\n\nlemma div_uint_code [code]: \"x div y = (if y = 0 then 0 else uint_div x y)\"\nincluding undefined_transfer unfolding uint_divmod_def uint_div_def\nby transfer(simp add: word_div_def)\n\nlemma mod_uint_code [code]: \"x mod y = (if y = 0 then x else uint_mod x y)\"\nincluding undefined_transfer unfolding uint_mod_def uint_divmod_def\nby transfer(simp add: word_mod_def)\n\ndefinition uint_sdiv :: \"uint \\<Rightarrow> uint \\<Rightarrow> uint\"\nwhere [code del]:\n  \"uint_sdiv x y =\n   (if y = 0 then undefined ((div) :: uint \\<Rightarrow> _) x (0 :: uint)\n    else Abs_uint (Rep_uint x sdiv Rep_uint y))\"\n\ndefinition div0_uint :: \"uint \\<Rightarrow> uint\"\nwhere [code del]: \"div0_uint x = undefined ((div) :: uint \\<Rightarrow> _) x (0 :: uint)\"\ndeclare [[code abort: div0_uint]]\n\ndefinition mod0_uint :: \"uint \\<Rightarrow> uint\"\nwhere [code del]: \"mod0_uint x = undefined ((mod) :: uint \\<Rightarrow> _) x (0 :: uint)\"\ndeclare [[code abort: mod0_uint]]\n\ndefinition wivs_overflow_uint :: uint \n  where \"wivs_overflow_uint \\<equiv> push_bit (dflt_size - 1) 1\"\n\nlemma Rep_uint_wivs_overflow_uint_eq:\n  \\<open>Rep_uint wivs_overflow_uint = 2 ^ (dflt_size - Suc 0)\\<close>\n  by (simp add: wivs_overflow_uint_def one_uint.rep_eq push_bit_uint.rep_eq uint.word_of_power push_bit_eq_mult)\n\nlemma wivs_overflow_uint_greater_eq_0:\n  \\<open>wivs_overflow_uint > 0\\<close>\n  apply (simp add: less_uint.rep_eq zero_uint.rep_eq Rep_uint_wivs_overflow_uint_eq)\n  apply transfer\n  apply (simp add: take_bit_push_bit push_bit_eq_mult)\n  done\n\nlemma uint_divmod_code [code]:\n  \"uint_divmod x y =\n  (if wivs_overflow_uint \\<le> y then if x < y then (0, x) else (1, x - y)\n   else if y = 0 then (div0_uint x, mod0_uint x)\n   else let q = push_bit 1 (uint_sdiv (drop_bit 1 x) y);\n            r = x - q * y\n        in if r \\<ge> y then (q + 1, r - y) else (q, r))\"\nproof (cases \\<open>y = 0\\<close>)\n  case True\n  moreover have \\<open>x \\<ge> 0\\<close>\n    by transfer simp\n  moreover note wivs_overflow_uint_greater_eq_0\n  ultimately show ?thesis\n    by (auto simp add: uint_divmod_def div0_uint_def mod0_uint_def not_less)\nnext\n  case False\n  then show ?thesis\n    including undefined_transfer \n    unfolding uint_divmod_def uint_sdiv_def div0_uint_def mod0_uint_def\n      wivs_overflow_uint_def\n    apply transfer\n    apply (simp add: divmod_via_sdivmod push_bit_of_1)\n    done\nqed\n\nlemma uint_sdiv_code [code]:\n  \"Rep_uint (uint_sdiv x y) =\n   (if y = 0 then Rep_uint (undefined ((div) :: uint \\<Rightarrow> _) x (0 :: uint))\n    else Rep_uint x sdiv Rep_uint y)\"\nunfolding uint_sdiv_def by(simp add: Abs_uint_inverse)\n\ntext \\<open>\n  Note that we only need a translation for signed division, but not for the remainder\n  because @{thm uint_divmod_code} computes both with division only.\n\\<close>\n\ncode_printing\n  constant uint_div \\<rightharpoonup>\n  (SML) \"Word.div ((_), (_))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.div ((_), (_))\" and\n  (Haskell) \"Prelude.div\"\n| constant uint_mod \\<rightharpoonup>\n  (SML) \"Word.mod ((_), (_))\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Word.mod ((_), (_))\" and\n  (Haskell) \"Prelude.mod\"\n| constant uint_divmod \\<rightharpoonup>\n  (Haskell) \"divmod\"\n| constant uint_sdiv \\<rightharpoonup>\n  (OCaml) \"Pervasives.('/)\" and\n  (Scala) \"_ '/ _\"\n\ndefinition uint_test_bit :: \"uint \\<Rightarrow> integer \\<Rightarrow> bool\"\nwhere [code del]:\n  \"uint_test_bit x n =\n  (if n < 0 \\<or> dflt_size_integer \\<le> n then undefined (bit :: uint \\<Rightarrow> _) x n\n   else bit x (nat_of_integer n))\"\n\nlemma test_bit_uint_code [code]:\n  \"bit x n \\<longleftrightarrow> n < dflt_size \\<and> uint_test_bit x (integer_of_nat n)\"\n  including undefined_transfer integer.lifting unfolding uint_test_bit_def\n  by (transfer, simp, transfer, simp)\n\nlemma uint_test_bit_code [code]:\n  \"uint_test_bit w n =\n  (if n < 0 \\<or> dflt_size_integer \\<le> n then undefined (bit :: uint \\<Rightarrow> _) w n else bit (Rep_uint w) (nat_of_integer n))\"\n  unfolding uint_test_bit_def by(simp add: bit_uint.rep_eq)\n\ncode_printing constant uint_test_bit \\<rightharpoonup>\n  (SML) \"Uint.test'_bit\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Uint.test'_bit\" and\n  (Haskell) \"Data'_Bits.testBitBounded\" and\n  (OCaml) \"Uint.test'_bit\" and\n  (Scala) \"Uint.test'_bit\"\n\ndefinition uint_set_bit :: \"uint \\<Rightarrow> integer \\<Rightarrow> bool \\<Rightarrow> uint\"\nwhere [code del]:\n  \"uint_set_bit x n b =\n  (if n < 0 \\<or> dflt_size_integer \\<le> n then undefined (set_bit :: uint \\<Rightarrow> _) x n b\n   else set_bit x (nat_of_integer n) b)\"\n\nlemma set_bit_uint_code [code]:\n  \"set_bit x n b = (if n < dflt_size then uint_set_bit x (integer_of_nat n) b else x)\"\n  including undefined_transfer integer.lifting unfolding uint_set_bit_def\n  by (transfer) (auto cong: conj_cong simp add: not_less set_bit_beyond word_size)\n\nlemma uint_set_bit_code [code]:\n  \"Rep_uint (uint_set_bit w n b) = \n  (if n < 0 \\<or> dflt_size_integer \\<le> n then Rep_uint (undefined (set_bit :: uint \\<Rightarrow> _) w n b)\n   else set_bit (Rep_uint w) (nat_of_integer n) b)\"\nincluding undefined_transfer integer.lifting unfolding uint_set_bit_def by transfer simp\n\ncode_printing constant uint_set_bit \\<rightharpoonup>\n  (SML) \"Uint.set'_bit\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Uint.set'_bit\" and\n  (Haskell) \"Data'_Bits.setBitBounded\" and\n  (OCaml) \"Uint.set'_bit\" and\n  (Scala) \"Uint.set'_bit\"\n\ndefinition uint_shiftl :: \"uint \\<Rightarrow> integer \\<Rightarrow> uint\"\nwhere [code del]:\n  \"uint_shiftl x n = (if n < 0 \\<or> dflt_size_integer \\<le> n then undefined (push_bit :: nat \\<Rightarrow> uint \\<Rightarrow> _) x n else push_bit (nat_of_integer n) x)\"\n\nlemma shiftl_uint_code [code]: \"push_bit n x = (if n < dflt_size then uint_shiftl x (integer_of_nat n) else 0)\"\n  including undefined_transfer integer.lifting unfolding uint_shiftl_def\n  by (transfer fixing: n) simp\n\nlemma uint_shiftl_code [code]:\n  \"Rep_uint (uint_shiftl w n) =\n  (if n < 0 \\<or> dflt_size_integer \\<le> n then Rep_uint (undefined (push_bit :: nat \\<Rightarrow> uint \\<Rightarrow> _) w n) else push_bit (nat_of_integer n) (Rep_uint w))\"\n  including undefined_transfer integer.lifting unfolding uint_shiftl_def by transfer simp\n\ncode_printing constant uint_shiftl \\<rightharpoonup>\n  (SML) \"Uint.shiftl\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Uint.shiftl\" and\n  (Haskell) \"Data'_Bits.shiftlBounded\" and\n  (OCaml) \"Uint.shiftl\" and\n  (Scala) \"Uint.shiftl\"\n\ndefinition uint_shiftr :: \"uint \\<Rightarrow> integer \\<Rightarrow> uint\"\nwhere [code del]:\n  \"uint_shiftr x n = (if n < 0 \\<or> dflt_size_integer \\<le> n then undefined (drop_bit :: nat \\<Rightarrow> uint \\<Rightarrow> _) x n else drop_bit (nat_of_integer n) x)\"\n\nlemma shiftr_uint_code [code]: \"drop_bit n x = (if n < dflt_size then uint_shiftr x (integer_of_nat n) else 0)\"\n  including undefined_transfer integer.lifting unfolding uint_shiftr_def\n  by (transfer fixing: n) simp\n\nlemma uint_shiftr_code [code]:\n  \"Rep_uint (uint_shiftr w n) =\n  (if n < 0 \\<or> dflt_size_integer \\<le> n then Rep_uint (undefined (drop_bit :: nat \\<Rightarrow> uint \\<Rightarrow> _) w n) else drop_bit (nat_of_integer n) (Rep_uint w))\"\n  including undefined_transfer integer.lifting unfolding uint_shiftr_def by transfer simp\n\ncode_printing constant uint_shiftr \\<rightharpoonup>\n  (SML) \"Uint.shiftr\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Uint.shiftr\" and\n  (Haskell) \"Data'_Bits.shiftrBounded\" and\n  (OCaml) \"Uint.shiftr\" and\n  (Scala) \"Uint.shiftr\"\n\ndefinition uint_sshiftr :: \"uint \\<Rightarrow> integer \\<Rightarrow> uint\"\nwhere [code del]:\n  \"uint_sshiftr x n =\n  (if n < 0 \\<or> dflt_size_integer \\<le> n then undefined signed_drop_bit_uint n x else signed_drop_bit_uint (nat_of_integer n) x)\"\n\nlemma sshiftr_uint_code [code]:\n  \"signed_drop_bit_uint n x = \n  (if n < dflt_size then uint_sshiftr x (integer_of_nat n) else \n    if bit x wivs_index then -1 else 0)\"\nincluding undefined_transfer integer.lifting unfolding uint_sshiftr_def\nby transfer(simp add: not_less signed_drop_bit_beyond word_size wivs_index_def)\n\nlemma uint_sshiftr_code [code]:\n  \"Rep_uint (uint_sshiftr w n) =\n  (if n < 0 \\<or> dflt_size_integer \\<le> n then Rep_uint (undefined signed_drop_bit_uint n w) else signed_drop_bit (nat_of_integer n) (Rep_uint w))\"\nincluding undefined_transfer integer.lifting unfolding uint_sshiftr_def by transfer simp\n\ncode_printing constant uint_sshiftr \\<rightharpoonup>\n  (SML) \"Uint.shiftr'_signed\" and\n  (Eval) \"(raise (Fail \\\"Machine dependent code\\\"))\" and\n  (Quickcheck) \"Uint.shiftr'_signed\" and\n  (Haskell) \n    \"(Prelude.fromInteger (Prelude.toInteger (Data'_Bits.shiftrBounded (Prelude.fromInteger (Prelude.toInteger _) :: Uint.Int) _)) :: Uint.Word)\" and\n  (OCaml) \"Uint.shiftr'_signed\" and\n  (Scala) \"Uint.shiftr'_signed\"\n\nlemma uint_msb_test_bit: \"msb x \\<longleftrightarrow> bit (x :: uint) wivs_index\"\n  by transfer (simp add: msb_word_iff_bit wivs_index_def)\n\nlemma msb_uint_code [code]: \"msb x \\<longleftrightarrow> uint_test_bit x wivs_index_integer\"\n  apply(simp add: uint_test_bit_def uint_msb_test_bit \n  wivs_index_integer_code dflt_size_integer_def wivs_index_def)\n  by (metis (full_types) One_nat_def dflt_size(2) less_iff_diff_less_0 \n    nat_of_integer_of_nat of_nat_1 of_nat_diff of_nat_less_0_iff wivs_index_def)\n\nlemma uint_of_int_code [code]: \"uint_of_int i = (BITS n. bit i n)\"\n  by transfer (simp add: word_of_int_conv_set_bits)\n\n\nsection \\<open>Quickcheck setup\\<close>\n\ndefinition uint_of_natural :: \"natural \\<Rightarrow> uint\"\nwhere \"uint_of_natural x \\<equiv> Uint (integer_of_natural x)\"\n\ninstantiation uint :: \"{random, exhaustive, full_exhaustive}\" begin\ndefinition \"random_uint \\<equiv> qc_random_cnv uint_of_natural\"\ndefinition \"exhaustive_uint \\<equiv> qc_exhaustive_cnv uint_of_natural\"\ndefinition \"full_exhaustive_uint \\<equiv> qc_full_exhaustive_cnv uint_of_natural\"\ninstance ..\nend\n\ninstantiation uint :: narrowing begin\n\ninterpretation quickcheck_narrowing_samples\n  \"\\<lambda>i. (Uint i, Uint (- i))\" \"0\"\n  \"Typerep.Typerep (STR ''Uint.uint'') []\" .\n\ndefinition \"narrowing_uint d = qc_narrowing_drawn_from (narrowing_samples d) d\"\ndeclare [[code drop: \"partial_term_of :: uint itself \\<Rightarrow> _\"]]\nlemmas partial_term_of_uint [code] = partial_term_of_code\n\ninstance ..\nend\n\nend\n", "meta": {"author": "isabelle-prover", "repo": "mirror-afp-devel", "sha": "c84055551f07621736c3eb6a1ef4fb7e8cc57dd1", "save_path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel", "path": "github-repos/isabelle/isabelle-prover-mirror-afp-devel/mirror-afp-devel-c84055551f07621736c3eb6a1ef4fb7e8cc57dd1/thys/Native_Word/Uint.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6297746213017459, "lm_q2_score": 0.3998116407397951, "lm_q1q2_score": 0.2517912246389341}}
{"text": "(*\n(C) Copyright Andreas Viktor Hess, DTU, 2020\n(C) Copyright Sebastian A. Mödersheim, DTU, 2020\n(C) Copyright Achim D. Brucker, University of Exeter, 2020\n(C) Copyright Anders Schlichtkrull, DTU, 2020\n\nAll Rights Reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\n- Redistributions of source code must retain the above copyright\n  notice, this list of conditions and the following disclaimer.\n\n- Redistributions in binary form must reproduce the above copyright\n  notice, this list of conditions and the following disclaimer in the\n  documentation and/or other materials provided with the distribution.\n\n- Neither the name of the copyright holder nor the names of its\n  contributors may be used to endorse or promote products\n  derived from this software without specific prior written\n  permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\nLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\nA PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\nOWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\nLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\nTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n*)\n\n(*  Title:      Term_Abstraction.thy\n    Author:     Andreas Viktor Hess, DTU\n    Author:     Sebastian A. Mödersheim, DTU\n    Author:     Achim D. Brucker, University of Exeter\n    Author:     Anders Schlichtkrull, DTU\n*)\n\nsection\\<open>Term Abstraction\\<close>\ntheory Term_Abstraction\n  imports Transactions\nbegin\n\nsubsection \\<open>Definitions\\<close>\nfun to_abs (\"\\<alpha>\\<^sub>0\") where\n  \"\\<alpha>\\<^sub>0 [] _ = {}\"\n| \"\\<alpha>\\<^sub>0 ((Fun (Val m) [],Fun (Set s) S)#D) n =\n    (if m = n then insert s (\\<alpha>\\<^sub>0 D n) else \\<alpha>\\<^sub>0 D n)\"\n| \"\\<alpha>\\<^sub>0 (_#D) n = \\<alpha>\\<^sub>0 D n\"\n\nfun abs_apply_term (infixl \"\\<cdot>\\<^sub>\\<alpha>\" 67) where\n  \"Var x \\<cdot>\\<^sub>\\<alpha> \\<alpha> = Var x\"\n| \"Fun (Val n) T \\<cdot>\\<^sub>\\<alpha> \\<alpha> = Fun (Abs (\\<alpha> n)) (map (\\<lambda>t. t \\<cdot>\\<^sub>\\<alpha> \\<alpha>) T)\"\n| \"Fun f T \\<cdot>\\<^sub>\\<alpha> \\<alpha> = Fun f (map (\\<lambda>t. t \\<cdot>\\<^sub>\\<alpha> \\<alpha>) T)\"\n\ndefinition abs_apply_list (infixl \"\\<cdot>\\<^sub>\\<alpha>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t\" 67) where\n  \"M \\<cdot>\\<^sub>\\<alpha>\\<^sub>l\\<^sub>i\\<^sub>s\\<^sub>t \\<alpha> \\<equiv> map (\\<lambda>t. t \\<cdot>\\<^sub>\\<alpha> \\<alpha>) M\"\n\ndefinition abs_apply_terms (infixl \"\\<cdot>\\<^sub>\\<alpha>\\<^sub>s\\<^sub>e\\<^sub>t\" 67) where\n  \"M \\<cdot>\\<^sub>\\<alpha>\\<^sub>s\\<^sub>e\\<^sub>t \\<alpha> \\<equiv> (\\<lambda>t. t \\<cdot>\\<^sub>\\<alpha> \\<alpha>) ` M\"\n\ndefinition abs_apply_pairs (infixl \"\\<cdot>\\<^sub>\\<alpha>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s\" 67) where\n  \"F \\<cdot>\\<^sub>\\<alpha>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<alpha> \\<equiv> map (\\<lambda>(s,t). (s \\<cdot>\\<^sub>\\<alpha> \\<alpha>, t \\<cdot>\\<^sub>\\<alpha> \\<alpha>)) F\"\n\ndefinition abs_apply_strand_step (infixl \"\\<cdot>\\<^sub>\\<alpha>\\<^sub>s\\<^sub>t\\<^sub>p\" 67) where\n  \"s \\<cdot>\\<^sub>\\<alpha>\\<^sub>s\\<^sub>t\\<^sub>p \\<alpha> \\<equiv> (case s of\n    (l,send\\<langle>t\\<rangle>) \\<Rightarrow> (l,send\\<langle>t \\<cdot>\\<^sub>\\<alpha> \\<alpha>\\<rangle>)\n  | (l,receive\\<langle>t\\<rangle>) \\<Rightarrow> (l,receive\\<langle>t \\<cdot>\\<^sub>\\<alpha> \\<alpha>\\<rangle>)\n  | (l,\\<langle>ac: t \\<doteq> t'\\<rangle>) \\<Rightarrow> (l,\\<langle>ac: (t \\<cdot>\\<^sub>\\<alpha> \\<alpha>) \\<doteq> (t' \\<cdot>\\<^sub>\\<alpha> \\<alpha>)\\<rangle>)\n  | (l,insert\\<langle>t,t'\\<rangle>) \\<Rightarrow> (l,insert\\<langle>t \\<cdot>\\<^sub>\\<alpha> \\<alpha>,t' \\<cdot>\\<^sub>\\<alpha> \\<alpha>\\<rangle>)\n  | (l,delete\\<langle>t,t'\\<rangle>) \\<Rightarrow> (l,delete\\<langle>t \\<cdot>\\<^sub>\\<alpha> \\<alpha>,t' \\<cdot>\\<^sub>\\<alpha> \\<alpha>\\<rangle>)\n  | (l,\\<langle>ac: t \\<in> t'\\<rangle>) \\<Rightarrow> (l,\\<langle>ac: (t \\<cdot>\\<^sub>\\<alpha> \\<alpha>) \\<in> (t' \\<cdot>\\<^sub>\\<alpha> \\<alpha>)\\<rangle>)\n  | (l,\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: F'\\<rangle>) \\<Rightarrow> (l,\\<forall>X\\<langle>\\<or>\\<noteq>: (F \\<cdot>\\<^sub>\\<alpha>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<alpha>) \\<or>\\<notin>: (F' \\<cdot>\\<^sub>\\<alpha>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<alpha>)\\<rangle>))\"\n\ndefinition abs_apply_strand (infixl \"\\<cdot>\\<^sub>\\<alpha>\\<^sub>s\\<^sub>t\" 67) where\n  \"S \\<cdot>\\<^sub>\\<alpha>\\<^sub>s\\<^sub>t \\<alpha> \\<equiv> map (\\<lambda>x. x \\<cdot>\\<^sub>\\<alpha>\\<^sub>s\\<^sub>t\\<^sub>p \\<alpha>) S\"\n\n\nsubsection \\<open>Lemmata\\<close>\nlemma to_abs_alt_def:\n  \"\\<alpha>\\<^sub>0 D n = {s. \\<exists>S. (Fun (Val n) [], Fun (Set s) S) \\<in> set D}\"\nby (induct D n rule: to_abs.induct) auto\n\nlemma abs_term_apply_const[simp]:\n  \"is_Val f \\<Longrightarrow> Fun f [] \\<cdot>\\<^sub>\\<alpha> a = Fun (Abs (a (the_Val f))) []\"\n  \"\\<not>is_Val f \\<Longrightarrow> Fun f [] \\<cdot>\\<^sub>\\<alpha> a = Fun f []\"\nby (cases f; auto)+\n\nlemma abs_fv: \"fv (t \\<cdot>\\<^sub>\\<alpha> a) = fv t\"\nby (induct t a rule: abs_apply_term.induct) auto\n\nlemma abs_eq_if_no_Val:\n  assumes \"\\<forall>f \\<in> funs_term t. \\<not>is_Val f\"\n  shows \"t \\<cdot>\\<^sub>\\<alpha> a = t \\<cdot>\\<^sub>\\<alpha> b\"\nusing assms\nproof (induction t)\n  case (Fun f T) thus ?case by (cases f) simp_all\nqed simp\n\n\n\nlemma abs_set_empty[simp]: \"{} \\<cdot>\\<^sub>\\<alpha>\\<^sub>s\\<^sub>e\\<^sub>t \\<alpha> = {}\"\nunfolding abs_apply_terms_def by simp\n\n\n\nlemma abs_set_union: \"(A \\<union> B) \\<cdot>\\<^sub>\\<alpha>\\<^sub>s\\<^sub>e\\<^sub>t a = (A \\<cdot>\\<^sub>\\<alpha>\\<^sub>s\\<^sub>e\\<^sub>t a) \\<union> (B \\<cdot>\\<^sub>\\<alpha>\\<^sub>s\\<^sub>e\\<^sub>t a)\"\nunfolding abs_apply_terms_def\nby auto\n\nlemma abs_subterms: \"subterms (t \\<cdot>\\<^sub>\\<alpha> \\<alpha>) = subterms t \\<cdot>\\<^sub>\\<alpha>\\<^sub>s\\<^sub>e\\<^sub>t \\<alpha>\"\nproof (induction t)\n  case (Fun f T) thus ?case by (cases f) (auto simp add: abs_apply_terms_def)\nqed (simp add: abs_apply_terms_def)\n\nlemma abs_subterms_in: \"s \\<in> subterms t \\<Longrightarrow> s \\<cdot>\\<^sub>\\<alpha> a \\<in> subterms (t \\<cdot>\\<^sub>\\<alpha> a)\"\nproof (induction t)\n  case (Fun f T) thus ?case by (cases f) auto\nqed simp\n\nlemma abs_ik_append: \"(ik\\<^sub>s\\<^sub>s\\<^sub>t (A@B) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I) \\<cdot>\\<^sub>\\<alpha>\\<^sub>s\\<^sub>e\\<^sub>t a = (ik\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I) \\<cdot>\\<^sub>\\<alpha>\\<^sub>s\\<^sub>e\\<^sub>t a \\<union> (ik\\<^sub>s\\<^sub>s\\<^sub>t B \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t I) \\<cdot>\\<^sub>\\<alpha>\\<^sub>s\\<^sub>e\\<^sub>t a\"\nunfolding abs_apply_terms_def ik\\<^sub>s\\<^sub>s\\<^sub>t_def\nby auto\n\nlemma to_abs_in:\n  assumes \"(Fun (Val n) [], Fun (Set s) []) \\<in> set D\"\n  shows \"s \\<in> \\<alpha>\\<^sub>0 D n\"\nusing assms by (induct rule: to_abs.induct) auto\n\nlemma to_abs_empty_iff_notin_db:\n  \"Fun (Val n) [] \\<cdot>\\<^sub>\\<alpha> \\<alpha>\\<^sub>0 D = Fun (Abs {}) [] \\<longleftrightarrow> (\\<nexists>s S. (Fun (Val n) [], Fun (Set s) S) \\<in> set D)\"\nby (simp add: to_abs_alt_def)\n\nlemma to_abs_list_insert:\n  assumes \"Fun (Val n) [] \\<noteq> t\"\n  shows \"\\<alpha>\\<^sub>0 D n = \\<alpha>\\<^sub>0 (List.insert (t,s) D) n\"\nusing assms to_abs_alt_def[of D n] to_abs_alt_def[of \"List.insert (t,s) D\" n]\nby auto\n\nlemma to_abs_list_insert':\n  \"insert s (\\<alpha>\\<^sub>0 D n) = \\<alpha>\\<^sub>0 (List.insert (Fun (Val n) [], Fun (Set s) S) D) n\"\nusing to_abs_alt_def[of D n]\n      to_abs_alt_def[of \"List.insert (Fun (Val n) [], Fun (Set s) S) D\" n]\nby auto\n\nlemma to_abs_list_remove_all:\n  assumes \"Fun (Val n) [] \\<noteq> t\"\n  shows \"\\<alpha>\\<^sub>0 D n = \\<alpha>\\<^sub>0 (List.removeAll (t,s) D) n\"\nusing assms to_abs_alt_def[of D n] to_abs_alt_def[of \"List.removeAll (t,s) D\" n]\nby auto\n\nlemma to_abs_list_remove_all':\n  \"\\<alpha>\\<^sub>0 D n - {s} = \\<alpha>\\<^sub>0 (filter (\\<lambda>d. \\<nexists>S. d = (Fun (Val n) [], Fun (Set s) S)) D) n\"\nusing to_abs_alt_def[of D n]\n      to_abs_alt_def[of \"filter (\\<lambda>d. \\<nexists>S. d = (Fun (Val n) [], Fun (Set s) S)) D\" n]\nby auto\n\nlemma to_abs_db\\<^sub>s\\<^sub>s\\<^sub>t_append:\n  assumes \"\\<forall>u s. insert\\<langle>u, s\\<rangle> \\<in> set B \\<longrightarrow> Fun (Val n) [] \\<noteq> u \\<cdot> \\<I>\"\n    and \"\\<forall>u s. delete\\<langle>u, s\\<rangle> \\<in> set B \\<longrightarrow> Fun (Val n) [] \\<noteq> u \\<cdot> \\<I>\"\n  shows \"\\<alpha>\\<^sub>0 (db'\\<^sub>s\\<^sub>s\\<^sub>t A \\<I> D) n = \\<alpha>\\<^sub>0 (db'\\<^sub>s\\<^sub>s\\<^sub>t (A@B) \\<I> D) n\"\nusing assms\nproof (induction B rule: List.rev_induct)\n  case (snoc b B)\n  hence IH: \"\\<alpha>\\<^sub>0 (db'\\<^sub>s\\<^sub>s\\<^sub>t A \\<I> D) n = \\<alpha>\\<^sub>0 (db'\\<^sub>s\\<^sub>s\\<^sub>t (A@B) \\<I> D) n\" by auto\n  have *: \"\\<forall>u s. b = insert\\<langle>u,s\\<rangle> \\<longrightarrow> Fun (Val n) [] \\<noteq> u \\<cdot> \\<I>\"\n          \"\\<forall>u s. b = delete\\<langle>u,s\\<rangle> \\<longrightarrow> Fun (Val n) [] \\<noteq> u \\<cdot> \\<I>\"\n    using snoc.prems by simp_all\n  show ?case\n  proof (cases b)\n    case (Insert u s)\n    hence **: \"db'\\<^sub>s\\<^sub>s\\<^sub>t (A@B@[b]) \\<I> D = List.insert (u \\<cdot> \\<I>,s \\<cdot> \\<I>) (db'\\<^sub>s\\<^sub>s\\<^sub>t (A@B) \\<I> D)\"\n      using db\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"A@B\" \"[b]\"] by simp\n    have \"Fun (Val n) [] \\<noteq> u \\<cdot> \\<I>\" using *(1) Insert by auto\n    thus ?thesis using IH ** to_abs_list_insert by metis\n  next\n    case (Delete u s)\n    hence **: \"db'\\<^sub>s\\<^sub>s\\<^sub>t (A@B@[b]) \\<I> D = List.removeAll (u \\<cdot> \\<I>,s \\<cdot> \\<I>) (db'\\<^sub>s\\<^sub>s\\<^sub>t (A@B) \\<I> D)\"\n      using db\\<^sub>s\\<^sub>s\\<^sub>t_append[of \"A@B\" \"[b]\"] by simp\n    have \"Fun (Val n) [] \\<noteq> u \\<cdot> \\<I>\" using *(2) Delete by auto\n    thus ?thesis using IH ** to_abs_list_remove_all by metis\n  qed (simp_all add: db\\<^sub>s\\<^sub>s\\<^sub>t_no_upd_append[of \"[b]\" \"A@B\"] IH)\nqed simp\n\nlemma to_abs_neq_imp_db_update:\n  assumes \"\\<alpha>\\<^sub>0 (db\\<^sub>s\\<^sub>s\\<^sub>t A I) n \\<noteq> \\<alpha>\\<^sub>0 (db\\<^sub>s\\<^sub>s\\<^sub>t (A@B) I) n\"\n  shows \"\\<exists>u s. u \\<cdot> I = Fun (Val n) [] \\<and> (insert\\<langle>u,s\\<rangle> \\<in> set B \\<or> delete\\<langle>u,s\\<rangle> \\<in> set B)\"\nproof -\n  { fix D have ?thesis when \"\\<alpha>\\<^sub>0 D n \\<noteq> \\<alpha>\\<^sub>0 (db'\\<^sub>s\\<^sub>s\\<^sub>t B I D) n\" using that\n    proof (induction B I D rule: db'\\<^sub>s\\<^sub>s\\<^sub>t.induct)\n      case 2 thus ?case\n        by (metis db'\\<^sub>s\\<^sub>s\\<^sub>t.simps(2) list.set_intros(1,2) subst_apply_pair_pair to_abs_list_insert)\n    next\n      case 3 thus ?case\n        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)\n    qed simp_all\n  } thus ?thesis using assms by (metis db\\<^sub>s\\<^sub>s\\<^sub>t_append db\\<^sub>s\\<^sub>s\\<^sub>t_def)\nqed\n\nlemma abs_term_subst_eq:\n  fixes \\<delta> \\<theta>::\"(('a,'b,'c) prot_fun, ('d,'e prot_atom) term \\<times> nat) subst\"\n  assumes \"\\<forall>x \\<in> fv t. \\<delta> x \\<cdot>\\<^sub>\\<alpha> a = \\<theta> x \\<cdot>\\<^sub>\\<alpha> b\"\n    and \"\\<nexists>n T. Fun (Val n) T \\<in> subterms t\"\n  shows \"t \\<cdot> \\<delta> \\<cdot>\\<^sub>\\<alpha> a = t \\<cdot> \\<theta> \\<cdot>\\<^sub>\\<alpha> b\"\nusing assms\nproof (induction t)\n  case (Fun f T) thus ?case\n  proof (cases f)\n    case (Val n)\n    hence False using Fun.prems(2) by blast\n    thus ?thesis by metis\n  qed auto\nqed simp\n\nlemma abs_term_subst_eq':\n  fixes \\<delta> \\<theta>::\"(('a,'b,'c) prot_fun, ('d,'e prot_atom) term \\<times> nat) subst\"\n  assumes \"\\<forall>x \\<in> fv t. \\<delta> x \\<cdot>\\<^sub>\\<alpha> a = \\<theta> x\"\n    and \"\\<nexists>n T. Fun (Val n) T \\<in> subterms t\"\n  shows \"t \\<cdot> \\<delta> \\<cdot>\\<^sub>\\<alpha> a = t \\<cdot> \\<theta>\"\nusing assms\nproof (induction t)\n  case (Fun f T) thus ?case\n  proof (cases f)\n    case (Val n)\n    hence False using Fun.prems(2) by blast\n    thus ?thesis by metis\n  qed auto\nqed simp\n\nlemma abs_val_in_funs_term:\n  assumes \"f \\<in> funs_term t\" \"is_Val f\"\n  shows \"Abs (\\<alpha> (the_Val f)) \\<in> funs_term (t \\<cdot>\\<^sub>\\<alpha> \\<alpha>)\"\nusing assms by (induct t \\<alpha> rule: abs_apply_term.induct) auto\n\nend\n", "meta": {"author": "logicalhacking", "repo": "Automated_Stateful_Protocol_Verification", "sha": "e24b8241b56d24240e1227caff737d4af82e12ec", "save_path": "github-repos/isabelle/logicalhacking-Automated_Stateful_Protocol_Verification", "path": "github-repos/isabelle/logicalhacking-Automated_Stateful_Protocol_Verification/Automated_Stateful_Protocol_Verification-e24b8241b56d24240e1227caff737d4af82e12ec/Automated_Stateful_Protocol_Verification/Term_Abstraction.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5156199008363969, "lm_q2_score": 0.48828339529583464, "lm_q1q2_score": 0.2517686358624974}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the GNU General Public License version 2. Note that NO WARRANTY is provided.\n * See \"LICENSE_GPLv2.txt\" for details.\n *\n * @TAG(NICTA_GPL)\n *)\n\ntheory Noninterference_Base\nimports \"../../lib/Simulation\"\nbegin\n\ntext {*\n  Toby's extended noninterference definitions to handle dynamic assignment,\n  that depends on the current state, of\n  the domain that each action is assigned to. This is the gory details\n  reported in the the CPP 2012 paper\n  \\emph{Noninterference for Operating System Kernels}.\n*}\n\nlemma un_eq:\n  \"\\<lbrakk>S = S'; T = T'\\<rbrakk> \\<Longrightarrow> S \\<union> T = S' \\<union> T'\"\n  apply auto\n  done\n\nlemma Un_eq:\n  \"\\<lbrakk>\\<And> x y. \\<lbrakk>x \\<in> xs; y \\<in> ys\\<rbrakk> \\<Longrightarrow> P x = Q y; \\<exists> x. x \\<in> xs; \\<exists> y. y \\<in> ys\\<rbrakk> \\<Longrightarrow> (\\<Union>x\\<in>xs. P x) = (\\<Union>y\\<in>ys. Q y)\"\n  apply auto\n  done\n\nlemma Int_eq:\n  \"\\<lbrakk>\\<And> x y. \\<lbrakk>x \\<in> xs; y \\<in> ys\\<rbrakk> \\<Longrightarrow> P x = Q y; \\<exists> x. x \\<in> xs; \\<exists> y. y \\<in> ys\\<rbrakk> \\<Longrightarrow> (\\<Inter>x\\<in>xs. P x) = (\\<Inter>y\\<in>ys. Q y)\"\n  apply auto\n  done\n\nlemma Un_eq_Int:\n  assumes ex: \"\\<exists> x. x \\<in> xs\"\n  assumes ey: \"\\<exists> y. y \\<in> ys\"\n  assumes a: \"\\<And> x y. \\<lbrakk>x \\<in> xs; y \\<in> ys\\<rbrakk> \\<Longrightarrow> S x = S' y\"\n  shows \"(\\<Union>x\\<in>xs. S x) = (\\<Inter>x\\<in>ys. S' x)\"\n  apply(rule equalityI)\n   apply(clarsimp)\n   apply(drule a, assumption, simp)\n  apply clarsimp\n  apply(insert ex ey)\n  apply clarsimp\n  apply(frule a, assumption)\n  apply fastforce\n  done\n\nprimrec Run :: \"('e \\<Rightarrow> ('s \\<times> 's) set) \\<Rightarrow> 'e list \\<Rightarrow> ('s \\<times> 's) set\" where\n  \"Run Stepf []     = Id\" |\n  \"Run Stepf (a#as) = Stepf a O Run Stepf as\"\n\n\nlemma Run_mid':\n  shows\n  \"\\<forall> s u bs. (s,u) \\<in> Run Stepf (as @ bs)  \\<longrightarrow> (\\<exists> t. (s,t) \\<in> Run Stepf as \\<and> (t,u) \\<in> Run Stepf bs)\"\n  proof(induct as)\n  case Nil show ?case\n   apply(clarsimp)\n   done\n  next\n  case (Cons a as) show ?case\n  apply(clarsimp simp: relcomp_def)\n  apply(drule \"Cons.hyps\"[rule_format])\n  apply fastforce\n  done\nqed\n\nlemma Run_mid:\n  \"(s,u) \\<in> Run Stepf (as @ bs) \\<Longrightarrow> (\\<exists> t. (s,t) \\<in> Run Stepf as \\<and> (t,u) \\<in> Run Stepf bs)\"\n  apply(erule Run_mid'[rule_format])\n  done\n\nlemma Run_trans':\n  \"\\<forall> s t u bs. (s,t) \\<in> Run Stepf as \\<and> (t,u) \\<in> Run Stepf bs \\<longrightarrow> (s,u) \\<in> Run Stepf (as @ bs)\"\n  by (induct_tac as) auto\n\nlemma Run_trans:\n  \"\\<lbrakk>(s,t) \\<in> Run Stepf as; (t,u) \\<in> Run Stepf bs\\<rbrakk> \\<Longrightarrow> (s,u) \\<in> Run Stepf (as @ bs)\"\n  by(blast intro: Run_trans'[rule_format])\n\nlemma Run_app:\n  \"Run Stepf (as @ bs) = (Run Stepf as) O (Run Stepf bs)\"\n  apply(rule equalityI)\n   apply(fastforce dest: Run_mid)\n  apply(fastforce intro: Run_trans)\n  done\n\n(* An ADT with an initial state. *)\nlocale system =\n  fixes A :: \"('a,'s,'e) data_type\"  \n  and s0 :: \"'s\"  (* an initial state *)\n\ncontext system begin\n\n(* State 's' is reachable from the initial state 's0'. *)\ndefinition reachable where\n  \"reachable s \\<equiv> \\<exists> js. s \\<in> execution A s0 js\"\n\ndefinition Step where\n  \"Step a \\<equiv> {(s,s') . s' \\<in> execution A s [a]}\"\n\n(* The system is \"observationally deterministic\": that is, the\n * observable part of the system is always deterministic. *)\ndefinition obs_det where\n  \"obs_det \\<equiv> \\<forall> s js. (\\<exists> s'. execution A s js = {s'})\"\n\nlemma obs_detD:\n  \"obs_det \\<Longrightarrow> \\<exists> s'. execution A s js = {s'}\" by (simp add: obs_det_def)\n\n(* The abstraction/concretisation functions \"Init\"/\"Fin\"\n * don't abstract away information. *)\ndefinition no_abs where\n  \"no_abs \\<equiv> \\<forall> x s as . reachable s \\<longrightarrow> x \\<in> steps (Simulation.Step A) (Init A s) as \\<longrightarrow>  Init A (Fin A x) = {x}\"\n   \nlemma no_absD:\n  \"no_abs \\<Longrightarrow> reachable s \\<Longrightarrow> x \\<in> steps (Simulation.Step A) (Init A s) as \\<Longrightarrow> Init A (Fin A x) = {x}\" by (auto simp: no_abs_def)\n\nend\n\n(*\n * A system that is always enabled.\n *\n * In particular, the system will never be in deadlock, and there\n * is always an enabled transition from every reachable state.\n *)\nlocale enabled_system = system +\n  assumes enabled: \"(\\<exists> js. s \\<in> execution A s0 js) \\<Longrightarrow> \\<exists> s'. s' \\<in> execution A s js\"\n\ncontext enabled_system begin\n\nlemma reachable_enabled:\n  \"reachable s \\<Longrightarrow> \\<exists> s'. s' \\<in> execution A s js\"\n  apply(simp add: reachable_def)\n  apply(erule enabled)\n  done\n\n\nlemma enabled_Step:\n  \"reachable s \\<Longrightarrow> \\<exists> s'. (s,s') \\<in> Step a\"\n  apply(simp add: Step_def, blast intro: reachable_enabled)\n  done\n\n\nend\n\n(* we define the unwinding conditions for systems for which a running\n   a sequence of events is equivalent to performing a sequence of individual\n   steps: one for each event in the sequence in turn  *)\nlocale Step_system = system A s0\n  for A :: \"('a,'s,'e) data_type\" and s0 :: \"'s\"  +\n  assumes reachable_s0: \"reachable s0\"\n  assumes execution_Run: \"reachable s \\<Longrightarrow> execution A s as = {s'. (s,s') \\<in> Run Step as}\"\n\n\ncontext Step_system begin\n\nlemma execution_Run':\n  \"s \\<in> execution A s0 js \\<Longrightarrow> execution A s as = {s'. (s,s') \\<in> Run Step as}\"\n  apply(rule execution_Run)\n  apply(fastforce simp: reachable_def)\n  done\n\nlemma reachable_Run:\n  \"reachable s \\<Longrightarrow> \\<exists>as. (s0,s) \\<in> Run Step as\"\n  apply (clarsimp simp add: reachable_def)\n  apply (cut_tac as=js in execution_Run[OF reachable_s0])\n  apply blast\n  done\n\nlemma Run_reachable:\n  \"\\<exists>as. (s0,s) \\<in> Run Step as \\<Longrightarrow> reachable s\"\n  apply (clarsimp simp add: reachable_def)\n  apply (cut_tac as=as in execution_Run[OF reachable_s0])\n  apply blast\n  done\n\n\nlemma reachable_execution:\n  \"\\<lbrakk>reachable s; s' \\<in> execution A s js\\<rbrakk> \\<Longrightarrow> reachable s'\"\n  apply(clarsimp simp: reachable_def)\n  apply(rule_tac x=\"jsa @ js\" in exI)\n  apply(frule execution_Run'[where s=s and as=js])\n  apply(simp add: execution_Run[where s=s0, simplified reachable_s0])\n  apply(fastforce simp: Run_app)\n  done\n\nlemma reachable_Step:\n  \"\\<lbrakk>reachable s; (s,s') \\<in> Step a\\<rbrakk> \\<Longrightarrow> reachable s'\"\n  apply(erule reachable_execution)\n  apply(simp add: Step_def)\n  done\n\nlemma reachable_induct_helper: assumes a:\n      \"\\<And>s s' a.\n             \\<lbrakk>reachable s; P s;\n              (s, s') \\<in> Step a\\<rbrakk>\n             \\<Longrightarrow> P s'\"\n       shows \"\\<lbrakk>(s0, s1) \\<in> Run Step as; P s0\\<rbrakk>\n         \\<Longrightarrow> P s1\"\n  apply (induct as arbitrary: s1 rule: rev_induct)\n   apply simp\n  apply(fastforce dest: Run_mid intro: a Run_reachable)\n  done\n\nlemma reachable_induct: \"(\\<And>s s' a. reachable s \\<Longrightarrow> (s,s') \\<in> (Step a) \\<Longrightarrow> P s \\<Longrightarrow> P s') \\<Longrightarrow> reachable s1 \\<Longrightarrow> P s0 \\<Longrightarrow> P s1\"\n  apply (drule reachable_Run)\n  apply (elim exE)\n  apply (rule reachable_induct_helper)\n    apply simp+\n  done\n\nend\n\nlocale Init_Fin_system = system A s0\n  for A :: \"('a,'s,'e) data_type\" and s0 :: \"'s\"  +\n  assumes reachable_s0: \"reachable s0\"\n  assumes Fin_Init: \"reachable s \\<Longrightarrow> Fin A ` Init A s = {s}\"\n  assumes Init_Fin: \"reachable s \\<Longrightarrow> x \\<in> steps (Simulation.Step A) (Init A s) as \\<Longrightarrow>  x \\<in> Init A (Fin A x)\"\n  assumes obs_det_or_no_abs: \"obs_det \\<or> no_abs\"\n\n\ncontext Init_Fin_system begin\n\n\nlemma execution_subset_Run:\n  \"reachable s \\<Longrightarrow> execution A s as \\<subseteq> {s'. (s,s') \\<in> Run Step as}\"\n  apply(induct as arbitrary: s rule: rev_induct)\n   apply(simp add: execution_def steps_def Fin_Init)\n  apply(simp add: execution_def steps_def)\n  apply(rule subsetI)\n  apply clarsimp\n  apply(rule Run_trans)\n   apply blast\n  apply(cut_tac x=xc and s=s and as=xs in Init_Fin, (simp add: steps_def)+)\n  apply(clarsimp simp: Step_def execution_def steps_def)\n  apply blast\n  done\n\nlemma Run_subset_execution:\n  \"\\<lbrakk>no_abs; reachable s\\<rbrakk> \\<Longrightarrow> {s'. (s,s') \\<in> Run Step as} \\<subseteq> execution A s as\"\n  apply(induct as arbitrary: s rule: rev_induct)\n   apply(simp add: execution_def steps_def Fin_Init)\n  apply(simp add: execution_def steps_def)\n  apply(rule subsetI)\n  apply clarsimp\n  apply(drule Run_mid)\n  apply clarsimp\n  apply(drule_tac x=s in meta_spec)\n  apply clarsimp\n  apply(drule_tac subsetD)\n   apply blast\n  apply(clarsimp simp: Image_def image_def Step_def execution_def steps_def)\n  apply(rule_tac x=xc in exI)\n  apply clarsimp\n  apply(rule_tac x=xd in bexI)\n   apply assumption\n  apply(drule_tac x=xb in no_absD)\n    apply(simp add: steps_def Image_def)+\n  done\n\nlemma Run_det:\n  \"obs_det \\<Longrightarrow> \\<exists> s'. {s'. (s,s') \\<in> Run Step as} = {s'}\"\n  apply(induct as arbitrary: s rule: rev_induct)\n   apply simp\n  apply(simp add: Run_app relcomp_def)\n  apply(drule_tac x=s in meta_spec)\n  apply clarsimp\n  apply(drule_tac s=s' and js=\"[x]\" in obs_detD)\n  apply (clarsimp simp: Step_def)\n  apply(rule_tac x=\"s'a\" in exI)\n  apply (auto dest: equalityD1)\n  done\n  \nlemma eq:\n  \"\\<lbrakk>S \\<subseteq> T; \\<exists> x. S = {x}; \\<exists> y. T = {y}\\<rbrakk> \\<Longrightarrow> S = T\"\n  apply blast\n  done\n\nlemma execution_Run:\n  \"reachable s \\<Longrightarrow> execution A s as = {s'. (s,s') \\<in> Run Step as}\"\n  apply(rule disjE[OF obs_det_or_no_abs])\n   apply(rule eq)\n     apply(erule execution_subset_Run)\n    apply(erule obs_detD)\n   apply(erule Run_det)\n  apply(rule equalityI)\n   apply(erule execution_subset_Run)\n  apply(erule (1) Run_subset_execution)\n  done\n\nend\n\nlemma Init_Fin_system_Step_system:\n  \"Init_Fin_system A s0 \\<Longrightarrow> Step_system A s0\"\n  apply(unfold_locales)\n   apply(erule Init_Fin_system.reachable_s0)\n  apply(erule (1) Init_Fin_system.execution_Run)\n  done\n\nsublocale Init_Fin_system \\<subseteq> Step_system\n  apply(rule Init_Fin_system_Step_system)\n  apply(unfold_locales)\n  done\n\n(* when Init is the inverse image of Fin, the above assumptions are met by a system\n   for which Fin is injective, or one that appears deterministic to an observer *)\n\nlocale Init_inv_Fin_system = system A s0\n  for A :: \"('a,'s,'e) data_type\" and s0 :: \"'s\" +\n  assumes Fin_Init_s0: \"s0 \\<in> Fin A ` Init A s0\"\n  assumes Init_inv_Fin: \"reachable s \\<Longrightarrow> Init A s = {s'. Fin A s' = s}\"\n  assumes Fin_inj: \"inj (Fin A)\"\n\ncontext Init_inv_Fin_system begin\n\nlemma s0_reachable:\n  \"reachable s0\"\n  apply(simp add: system.reachable_def)\n  apply(rule_tac x=\"[]\" in exI)\n  apply(simp add: execution_def steps_def)\n  apply(simp add: Fin_Init_s0)\n  done\n\nlemma foldl_foldl_Step:\n  \"\\<lbrakk>x \\<in> foldl (\\<lambda>S j. data_type.Step A j `` S) M as; \n   M \\<subseteq> foldl (\\<lambda>S j. data_type.Step A j `` S) B js\\<rbrakk>\n       \\<Longrightarrow> x \\<in> foldl (\\<lambda>S j. data_type.Step A j `` S)\n               (foldl (\\<lambda>S j. data_type.Step A j `` S) B js) as\"\n  apply(induct  as arbitrary: x M js B rule: rev_induct) \n   apply fastforce\n  apply simp\n  apply(erule ImageE)\n  apply(drule_tac x=xb in meta_spec)\n  apply(drule_tac x=M in meta_spec)\n  apply simp\n  apply(drule_tac x=js in meta_spec) \n  apply(drule_tac x=B in meta_spec, simp)\n  apply(blast)\n  done\n\nlemma reachable_Fin:\n  \"\\<lbrakk>reachable s;\n    x \\<in> steps (Simulation.Step A) (Init A s) as\\<rbrakk>\n   \\<Longrightarrow> reachable (Fin A x)\"\n  apply(cut_tac s=s in Init_inv_Fin, assumption)\n  apply(clarsimp simp: reachable_def execution_def steps_def)\n  apply(rule_tac x=\"js@as\" in exI)\n  apply(rule imageI)\n  apply(subgoal_tac \"{s'. Fin A s' = Fin A xa} = {xa}\")\n   apply simp\n   apply(erule foldl_foldl_Step)\n   apply blast\n  apply(blast dest: injD[OF Fin_inj])\n  done\n  \n\nend\n  \n\n\n\nlemma Init_inv_Fin_system_Init_Fin_system:\n  \"Init_inv_Fin_system A s0 \\<Longrightarrow> Init_Fin_system A s0\"\n  apply(unfold_locales)\n     apply(erule Init_inv_Fin_system.s0_reachable)\n    apply(simp add: Init_inv_Fin_system.Init_inv_Fin)\n    apply(simp add: image_def)\n    apply(fastforce simp: system.reachable_def execution_def)\n   apply(cut_tac s=\"Fin A x\" in Init_inv_Fin_system.Init_inv_Fin)\n     apply assumption\n    apply(blast intro: Init_inv_Fin_system.reachable_Fin)\n   apply simp\n  apply(rule disjI2)\n  apply(clarsimp simp: system.no_abs_def)\n  apply(frule Init_inv_Fin_system.Fin_inj)\n  apply(cut_tac s=\"Fin A x\" in Init_inv_Fin_system.Init_inv_Fin)\n    apply assumption\n   apply(blast intro: Init_inv_Fin_system.reachable_Fin)\n  apply simp\n  apply(fastforce dest: injD)\n  done\n\n\nsublocale Init_inv_Fin_system \\<subseteq> Init_Fin_system\n  apply(rule Init_inv_Fin_system_Init_Fin_system)\n  apply(unfold_locales)\n  done\n\n\nlocale noninterference_policy =\n  fixes dom :: \"'e \\<Rightarrow> 's \\<Rightarrow> 'd\"        (* dynamic dom assignment *)\n  fixes uwr :: \"'d \\<Rightarrow> ('s \\<times> 's) set\"\n  fixes policy :: \"('d \\<times> 'd) set\"     (* who can send info to whom *)\n  fixes out :: \"'d \\<Rightarrow> 's \\<Rightarrow> 'p\"        (* observable parts of d in state s *)\n  fixes schedDomain :: \"'d\"\n  assumes uwr_equiv_rel: \"equiv UNIV (uwr u)\"\n  assumes schedIncludesCurrentDom:\n    \"(s,t) \\<in> uwr schedDomain \\<Longrightarrow> dom e s = dom e t\"\n  assumes schedFlowsToAll:\n    \"(schedDomain,d) \\<in> policy\"\n  assumes schedNotGlobalChannel:\n    \"(x,schedDomain) \\<in> policy \\<Longrightarrow> x = schedDomain\"\n\ncontext noninterference_policy begin\n\nabbreviation uwr2 :: \"'s \\<Rightarrow> 'd \\<Rightarrow> 's \\<Rightarrow> bool\" (\"(_/ \\<sim>_\\<sim>/ _)\" [50,100,50] 1000) \nwhere \"s \\<sim>u\\<sim> t \\<equiv> (s,t) \\<in> uwr u\"\n\nabbreviation policy2 :: \"'d \\<Rightarrow> 'd \\<Rightarrow> bool\" (infix \"\\<leadsto>\" 50) where\n\"u \\<leadsto> v \\<equiv> (u,v) \\<in> policy\"\n\nlemma uwr_refl:\n  \"s \\<sim>(u::'d)\\<sim> s\"\n  apply(cut_tac u=u in uwr_equiv_rel)\n  apply(clarsimp simp: equiv_def)\n  apply(blast dest: refl_onD)\n  done\n\nlemma uwr_sym:\n  \"x \\<sim>(u::'d)\\<sim> y \\<Longrightarrow> y \\<sim>u\\<sim> x\"\n  apply(cut_tac u=u in uwr_equiv_rel)\n  apply(clarsimp simp: equiv_def)\n  apply(blast dest: symD)\n  done\n\nlemma uwr_trans:\n  \"\\<lbrakk>x \\<sim>(u::'d)\\<sim> y; y \\<sim>u\\<sim> z\\<rbrakk> \\<Longrightarrow> x \\<sim>u\\<sim> z\"\n  apply(cut_tac u=u in uwr_equiv_rel)\n  apply(clarsimp simp: equiv_def)\n  apply(blast dest: transD)\n  done\n\ndefinition sameFor_dom :: \"'s \\<Rightarrow> 'd set \\<Rightarrow> 's \\<Rightarrow> bool\"  (\"(_/ \\<approx>_\\<approx>/ _)\" [50,100,50] 1000) where\n \"s \\<approx>us\\<approx> t \\<equiv> \\<forall>u\\<in>us. (s,t) \\<in> uwr u\"\n\nlemma sameFor_subset_dom: \"\\<lbrakk>s \\<approx>(x::'d set)\\<approx> t; y \\<subseteq> x\\<rbrakk> \\<Longrightarrow> s \\<approx>y\\<approx> t\"\n  by(fastforce simp: sameFor_dom_def)\n\n\nlemma sameFor_inter_domI: \"s \\<approx>(S::'d set)\\<approx> t \\<Longrightarrow> s \\<approx>(S \\<inter> B)\\<approx> t\"\n  by(auto simp: sameFor_dom_def)\n\n\nlemma sameFor_sym_dom:\n  \"s \\<approx>(S::'d set)\\<approx> t \\<Longrightarrow> t \\<approx>S\\<approx> s\"\n  by(auto simp: sameFor_dom_def uwr_sym)\n\nend\n\nlocale noninterference_system = enabled_system A s0 + noninterference_policy dom uwr policy out schedDomain\n  for A :: \"('a,'s,'e) data_type\" \n  and s0 :: \"'s\"\n  and dom :: \"'e \\<Rightarrow> 's \\<Rightarrow> 'd\"  \n  and uwr :: \"'d \\<Rightarrow> ('s \\<times> 's) set\"\n  and policy :: \"('d \\<times> 'd) set\"\n  and out :: \"'d \\<Rightarrow> 's \\<Rightarrow> 'p\"\n  and schedDomain :: \"'d\"\n\n\n\ncontext noninterference_system begin\n\n(* The set of domains (which carry out actions in the list \"as\") which\n * may influence \"u\", assuming we start in state \"s\". *)\nprimrec  \n sources :: \"'e list \\<Rightarrow> 's \\<Rightarrow> 'd \\<Rightarrow> 'd set\" where\n sources_Nil: \"sources [] s u = {u}\"|\n sources_Cons: \"sources (a#as) s u = (\\<Union>{sources as s' u| s'. (s,s') \\<in> Step a}) \\<union> \n      {w. w = dom a s \\<and> (\\<exists> v s'. dom a s \\<leadsto> v \\<and> (s,s') \\<in> Step a \\<and> v \\<in> sources as s' u)}\"\n\ndeclare sources_Nil [simp del]     \ndeclare sources_Cons [simp del]     \n\n\n  \ndefinition \n  obs_equiv :: \"'s \\<Rightarrow> 'e list \\<Rightarrow> 's \\<Rightarrow> 'e list \\<Rightarrow> 'd \\<Rightarrow> bool\"  \nwhere\n  \"obs_equiv s as t bs d \\<equiv> \\<forall> s' t'. s' \\<in> execution A s as \\<and> t' \\<in> execution A t bs \\<longrightarrow>\n                out d s' = out d t'\"\n\n\ndefinition \n  uwr_equiv :: \"'s \\<Rightarrow> 'e list \\<Rightarrow> 's \\<Rightarrow> 'e list \\<Rightarrow> 'd \\<Rightarrow> bool\"  \nwhere\n  \"uwr_equiv s as t bs d \\<equiv> \\<forall> s' t'. s' \\<in> execution A s as \\<and> t' \\<in> execution A t bs \\<longrightarrow>\n                s' \\<sim>d\\<sim> t'\"\n\n\n\ntext {* Nonleakage *}\ndefinition\n  Nonleakage :: \"bool\" where\n  \"Nonleakage \\<equiv> \\<forall>as s u t. reachable s \\<and> reachable t \\<longrightarrow> \n     s \\<sim>schedDomain\\<sim> t \\<longrightarrow>\n     s \\<approx>(sources as s u)\\<approx> t \\<longrightarrow> obs_equiv s as t as u\"\n\ntext {* A generalisation of Nonleakage. *}\ndefinition Nonleakage_gen :: \"bool\" where\n  \"Nonleakage_gen \\<equiv> \\<forall>as s u t. reachable s \\<and> reachable t \\<longrightarrow>\n     s \\<sim>schedDomain\\<sim> t \\<longrightarrow>\n       s \\<approx>(sources as s u)\\<approx> t \\<longrightarrow> uwr_equiv s as t as u\"\n\n\n\n\nlemma uwr_equiv_sym:\n  \"uwr_equiv s as t bs u \\<Longrightarrow> uwr_equiv t bs s as u\"\n  apply(fastforce simp: uwr_equiv_def uwr_sym)\n  done\n\nlemma uwr_equiv_trans:\n  \"\\<lbrakk>reachable t; uwr_equiv s as t bs x; uwr_equiv t bs u cs x\\<rbrakk> \\<Longrightarrow> uwr_equiv s as u cs x\"\n  apply(clarsimp simp: uwr_equiv_def)\n  apply(cut_tac s=t and js=bs in reachable_enabled)\n   apply assumption\n  apply(blast intro: uwr_trans)\n  done\n\nprimrec gen_purge :: \"('e list \\<Rightarrow> 's \\<Rightarrow> 'd \\<Rightarrow> 'd set) \\<Rightarrow> 'd \\<Rightarrow> 'e list \\<Rightarrow> 's set \\<Rightarrow> 'e list\" \nwhere\n  Nil : \"gen_purge sf u []     ss = []\" |\n  Cons: \"gen_purge sf u (a#as) ss = \n            (if (\\<exists>s\\<in>ss. dom a s \\<in> sf (a#as) s u) then \n               a#gen_purge sf u as (\\<Union>s\\<in>ss. {s'. (s,s') \\<in> Step a})\n             else \n               gen_purge sf u as ss)\"\n\n\n\ndefinition ipurge where\n \"ipurge \\<equiv> gen_purge sources\"\n\nlemma ipurge_Nil:\n  \"ipurge u [] ss = []\"\n  by(auto simp: ipurge_def)\n\nlemma ipurge_Cons: \n  \"ipurge u (a#as) ss = \n     (if (\\<exists> s\\<in>ss. dom a s \\<in> sources (a#as) s u) then \n         a#ipurge u as (\\<Union>s\\<in>ss. {s'. (s,s') \\<in> Step a})\n      else \n         ipurge u as ss)\"\n  by (auto simp: ipurge_def)\n\n\nlemma gen_purge_shortens:\n  \"length (gen_purge sf u as ss) \\<le> length as\"\n  apply(induct as arbitrary: ss)\n   apply(simp)\n  apply(clarsimp)\n  apply(rule le_trans)\n   apply assumption\n  apply simp\n  done\n\n\n\n\nlemma INT_cong':\n  assumes a: \"\\<And> x. Q x \\<Longrightarrow> P x = P' x\"\n  shows\n  \"\\<Inter>{P x|x. Q x} = \\<Inter>{P' x|x. Q x}\"\n  apply (auto simp: a)\n  done\n   \n\ntext {* Standard Noninterfernce *}\n\ndefinition\n  Noninterference :: \"bool\" where\n \"Noninterference \\<equiv>\n  \\<forall> u as s. reachable s \\<longrightarrow> \n         (obs_equiv s as s (ipurge u as {s}) u)\"\n\n\ntext {* Strong Noninterference *}\ndefinition\n  Noninterference_strong :: \"bool\" where\n \"Noninterference_strong \\<equiv>\n  \\<forall> u as bs s. reachable s \\<longrightarrow>\n         (ipurge u as {s}) = (ipurge u bs {s}) \\<longrightarrow>\n         (obs_equiv s as s bs u)\"\n\n\n\nlemma obs_equiv_sym:\n  \"obs_equiv s as t bs u \\<Longrightarrow> obs_equiv t bs s as u\"\n  apply(clarsimp simp: obs_equiv_def)\n  done\n\nlemma obs_equiv_trans:\n  \"\\<lbrakk>reachable t; obs_equiv s as t bs u; obs_equiv t bs x cs u\\<rbrakk> \\<Longrightarrow> obs_equiv s as x cs u\"\n  apply(clarsimp simp: obs_equiv_def)\n  apply(cut_tac s=t and js=bs in reachable_enabled, assumption, blast)\n  done\n\nlemma Noninterference_Noninterference_strong:\n  \"\\<lbrakk>Noninterference\\<rbrakk> \\<Longrightarrow> Noninterference_strong\n\"\n  apply(clarsimp simp: Noninterference_def Noninterference_strong_def)\n  apply(drule_tac x=u in spec)\n  apply(frule_tac x=as in spec, drule_tac x=s in spec)\n  apply(drule_tac x=bs in spec, drule_tac x=s in spec)\n  apply clarsimp\n  apply(rule obs_equiv_trans)\n    apply assumption\n   apply assumption\n  apply(erule obs_equiv_sym)\n  done\n\n\ntext {* Noninfluence -- the combination of Noninterference and \n   Nonleakage. \n\n   We add the assumption about equivalence wrt the scheduler's domain, as\n   is common in e.g. GVW.*}\ndefinition\n  Noninfluence  :: \"bool\" where\n \"Noninfluence \\<equiv>\n  \\<forall> u as s t. reachable s \\<and> reachable t \\<longrightarrow>\n      s \\<approx>(sources as s u)\\<approx> t \\<longrightarrow>  s \\<sim>schedDomain\\<sim> t \\<longrightarrow>\n         obs_equiv s as t (ipurge u as {t}) u\"\n\n\n\n\ndefinition\n  Noninfluence_strong  :: \"bool\" where\n \"Noninfluence_strong \\<equiv>\n  \\<forall> u as bs s t. reachable s  \\<and> reachable t \\<longrightarrow>\n      s \\<approx>(sources as s u)\\<approx> t \\<longrightarrow>  s \\<sim>schedDomain\\<sim> t \\<longrightarrow>\n         ipurge u as {s} = ipurge u bs {s} \\<longrightarrow>\n         obs_equiv s as t bs u\"\n\n\n\n\nlemma notin_policyI:\n  \"\\<lbrakk>dom a s \\<notin> sources (a # list) s u; \\<exists> s'. (s,s') \\<in> Step a \\<and> ua \\<in> sources list s' u\\<rbrakk> \\<Longrightarrow>\n   (dom a s,ua) \\<notin> policy\"\n  apply(clarsimp simp: sources_Cons)\n  done\n\n\nlemma Noninfluence_strong_Noninterference_strong:\n  \"Noninfluence_strong \\<Longrightarrow> Noninterference_strong\"\n  apply(clarsimp simp: Noninfluence_strong_def Noninterference_strong_def)\n  apply(drule_tac x=u in spec, drule_tac x=as in spec, drule_tac x=bs in spec)\n  apply(fastforce simp: sameFor_dom_def uwr_refl)\n  done\n\nlemma Noninfluence_strong_Nonleakage:\n  \"Noninfluence_strong \\<Longrightarrow> Nonleakage\"\n  apply(clarsimp simp: Noninfluence_strong_def Nonleakage_def)\n  done\n\ntext {* This stronger condition is needed\n   to make the induction proof work for Noninterference. It can be viewed\n   as a generalisation of Noninfluence; hence its name here.\n*}\ndefinition\n  Noninfluence_gen :: \"bool\" where\n \"Noninfluence_gen \\<equiv>\n  \\<forall> u as s ts. reachable s \\<and> (\\<forall> t \\<in> ts. reachable t) \\<longrightarrow>\n      (\\<forall>t \\<in> ts. s \\<approx>(sources as s u)\\<approx> t) \\<longrightarrow>  (\\<forall>t \\<in> ts. s \\<sim>schedDomain\\<sim> t) \\<longrightarrow>  \n         (\\<forall>t \\<in> ts. uwr_equiv s as t (ipurge u as ts) u)\"\n\ndefinition\n  Noninfluence_uwr  :: \"bool\" where\n \"Noninfluence_uwr \\<equiv>\n  \\<forall> u as s t. reachable s \\<and> reachable t \\<longrightarrow>\n      s \\<approx>(sources as s u)\\<approx> t \\<longrightarrow>  s \\<sim>schedDomain\\<sim> t \\<longrightarrow>\n         uwr_equiv s as t (ipurge u as {t}) u\"\n\ndefinition\n  Noninfluence_strong_uwr :: \"bool\" where\n \"Noninfluence_strong_uwr \\<equiv>\n  \\<forall> u as bs s t. reachable s  \\<and> reachable t \\<longrightarrow>\n      s \\<approx>(sources as s u)\\<approx> t \\<longrightarrow>  s \\<sim>schedDomain\\<sim> t \\<longrightarrow>\n         ipurge u as {s} = ipurge u bs {s} \\<longrightarrow>\n         uwr_equiv s as t bs u\"\n\n\n\n\ndefinition output_consistent :: \"bool\" where\n  \"output_consistent \\<equiv> \\<forall> u s s'. s \\<sim>u\\<sim> s'  \\<longrightarrow> (out u s = out u s')\"\n\ndefinition confidentiality_u :: \"bool\" where\n  \"confidentiality_u \\<equiv> \\<forall> a u s t.  reachable s \\<and> reachable t \\<longrightarrow>\n    s \\<sim>schedDomain\\<sim> t \\<longrightarrow>\n    ((dom a s \\<leadsto> u) \\<longrightarrow> s \\<sim>dom a s\\<sim> t) \\<longrightarrow> \n      s \\<sim>u\\<sim> t \\<longrightarrow> \n      (\\<forall> s' t'. (s,s') \\<in> Step a \\<and> (t,t') \\<in> Step a \\<longrightarrow>\n        s' \\<sim>u\\<sim> t')\"\n\nlemma no_domain_visible_nondeterminism:\n  \"\\<lbrakk>confidentiality_u; reachable s; (s,s') \\<in> Step a; (s,s'') \\<in> Step a\\<rbrakk> \\<Longrightarrow> s' \\<sim>d\\<sim> s''\"\n  apply(clarsimp simp: confidentiality_u_def)\n  apply(fastforce intro: uwr_refl)\n  done\n\ndefinition integrity_u :: \"bool\" where\n  \"integrity_u \\<equiv> \\<forall> a u s. reachable  s \\<longrightarrow> \n   (dom a s,u) \\<notin> policy  \\<longrightarrow>\n   (\\<forall> s'. (s,s') \\<in> Step a \\<longrightarrow> s \\<sim>u\\<sim> s')\"\n\n(*<*)\n(* integrity_u actually guarantees this (seemingly) stronger condition *)\ndefinition integrity_u_more :: \"bool\" where\n  \"integrity_u_more \\<equiv> \\<forall> a u s. reachable s \\<longrightarrow> \n   (dom a s,u) \\<notin> policy \\<longrightarrow>\n   (\\<forall> s' t. s \\<sim>u\\<sim> t \\<and> (s,s') \\<in> Step a \\<longrightarrow> s' \\<sim>u\\<sim> t)\"\n\nlemma integrity_u_more:\n  \"integrity_u \\<Longrightarrow> integrity_u_more\"\n  apply(clarsimp simp: integrity_u_more_def integrity_u_def)\n  apply(blast dest: uwr_sym uwr_trans)\n  done\n(*>*)\n\nlemma integrity_uD:\n  \"\\<lbrakk>integrity_u; reachable s; (dom a s,u) \\<notin> policy;\n    s \\<sim>u\\<sim> t; (s,s') \\<in> Step a\\<rbrakk> \\<Longrightarrow> \n   s' \\<sim>u\\<sim> t\"\n  apply(drule integrity_u_more)\n  apply(simp add: integrity_u_more_def)\n  done\n\n\n\n\ntext {*\n  A weaker version of @{prop confidentiality_u} that, with\n  @{prop integrity_u}, implies it.\n*}\ndefinition confidentiality_u_weak where\n  \"confidentiality_u_weak \\<equiv> \\<forall> a u s t.  reachable s \\<and> reachable t \\<longrightarrow>\n    s \\<sim>schedDomain\\<sim> t \\<longrightarrow> dom a s \\<leadsto> u \\<longrightarrow> s \\<sim>(dom a s)\\<sim> t \\<longrightarrow> \n      s \\<sim>u\\<sim> t \\<longrightarrow> \n        (\\<forall> s' t'. (s,s') \\<in> Step a \\<and> (t,t') \\<in> Step a \\<longrightarrow> s' \\<sim>u\\<sim> t')\"\n\nlemma confidentiality_u_confidentiality_u_weak:\n  \"confidentiality_u \\<Longrightarrow> confidentiality_u_weak\"\n  apply (simp add: confidentiality_u_def confidentiality_u_weak_def)\n  apply blast\n  done\n\nlemma impCE':\n  \"\\<lbrakk>P \\<longrightarrow> Q; \\<lbrakk>P; Q\\<rbrakk> \\<Longrightarrow> R; \\<not> P \\<Longrightarrow> R\\<rbrakk> \\<Longrightarrow> R\"\n  apply auto\n  done\n\nlemma confidentiality_u_weak:\n  \"\\<lbrakk>confidentiality_u_weak; integrity_u\\<rbrakk> \\<Longrightarrow>\n  confidentiality_u\"\n  apply(clarsimp simp: confidentiality_u_def)\n  apply(erule impCE')\n   apply(subst (asm) confidentiality_u_weak_def, blast)\n  apply(frule integrity_uD, simp+)\n  apply(drule_tac s=t and t=\"s'\" in integrity_uD)\n      apply assumption\n     apply(drule_tac e=a in schedIncludesCurrentDom)\n     apply simp\n    apply(blast intro: uwr_sym)\n   apply assumption\n  apply(erule uwr_sym)\n  done\n\nlemma obs_equivI:\n  \"\\<lbrakk>output_consistent; uwr_equiv s as t bs ob\\<rbrakk> \\<Longrightarrow> obs_equiv s as t bs ob\"\n  apply(clarsimp simp: obs_equiv_def)\n  apply(auto simp: uwr_equiv_def output_consistent_def)\n  done\n\nlemma Noninfluence_uwr_Noninfluence:\n  \"\\<lbrakk>output_consistent; Noninfluence_uwr\\<rbrakk> \\<Longrightarrow> Noninfluence\"\n  apply(clarsimp simp: Noninfluence_def)\n  apply(erule obs_equivI)\n  apply(auto simp: Noninfluence_uwr_def)\n  done\n\nlemma Noninfluence_strong_uwr_Noninfluence_strong:\n  \"\\<lbrakk>output_consistent; Noninfluence_strong_uwr\\<rbrakk> \\<Longrightarrow> Noninfluence_strong\"\n  apply(clarsimp simp: Noninfluence_strong_def)\n  apply(erule obs_equivI)\n  apply(auto simp: Noninfluence_strong_uwr_def)\n  done\n\nlemma sched_equiv_preserved:\n  \"\\<lbrakk>confidentiality_u;  reachable s; reachable t;\n   s \\<sim>schedDomain\\<sim> t; (s,s') \\<in> Step a; (t,t') \\<in> Step a\\<rbrakk> \\<Longrightarrow>\n   s' \\<sim>schedDomain\\<sim> t'\"\n  apply(case_tac \"dom a s = schedDomain\")\n   apply(subst (asm) confidentiality_u_def)\n   apply(drule_tac x=a in spec)\n   apply(drule_tac x=schedDomain in spec)\n   apply(drule_tac x=s in spec)\n   apply(drule_tac x=t in spec)\n   apply simp\n  apply(subst (asm) confidentiality_u_def)\n  apply(blast intro: schedNotGlobalChannel)\n  done\n\nlemma sched_equiv_preserved_left:\n  \"\\<lbrakk>integrity_u; s \\<sim>schedDomain\\<sim> t;\n    dom a s \\<noteq> schedDomain; (s,s') \\<in> Step a; reachable s\\<rbrakk> \\<Longrightarrow> \n    s' \\<sim>schedDomain\\<sim> t\"\n  apply(blast intro: integrity_uD schedNotGlobalChannel)\n  done       \n\nlemma Noninfluence_gen_Noninterference:\n  \"\\<lbrakk>output_consistent; Noninfluence_gen\\<rbrakk> \\<Longrightarrow> Noninterference\"\n  apply(clarsimp simp: Noninterference_def Noninfluence_gen_def)\n  apply(erule_tac x=u in allE)\n  apply(erule_tac x=as in allE)\n  apply(erule_tac x=s in allE)\n  apply(erule_tac x=\"{s}\" in allE)\n  apply(clarsimp simp: sameFor_dom_def uwr_refl)\n  apply(blast intro: obs_equivI)\n  done\n\nlemma Noninfluence_gen_Noninfluence:\n  \"\\<lbrakk>output_consistent; Noninfluence_gen\\<rbrakk> \\<Longrightarrow> Noninfluence\"\n  apply(clarsimp simp: Noninfluence_def Noninfluence_gen_def)\n  apply(erule_tac x=u in allE)\n  apply(erule_tac x=as in allE)\n  apply(erule_tac x=s in allE)\n  apply(erule_tac x=\"{t}\" in allE)\n  apply(blast intro: obs_equivI)\n  done\n\nlemma Noninfluence_gen_Noninfluence_uwr:\n  \"\\<lbrakk>Noninfluence_gen\\<rbrakk> \\<Longrightarrow> Noninfluence_uwr\"\n  apply(clarsimp simp: Noninfluence_uwr_def Noninfluence_gen_def)\n  done\n\nlemma Noninfluence_gen_Noninterference_strong:\n  \"\\<lbrakk>output_consistent; Noninfluence_gen\\<rbrakk> \\<Longrightarrow> Noninterference_strong\"\n  apply(rule Noninterference_Noninterference_strong)\n  apply(blast intro: Noninfluence_gen_Noninterference)\n  done\n\n\nend\n\nlocale enabled_Step_system = enabled_system A s0 + Step_system A s0\n  for A :: \"('a,'s,'e) data_type\" and s0 :: \"'s\" \n\n\n(* we define the unwinding conditions for any system *)\nlocale unwinding_system = enabled_Step_system A s0 +  noninterference_policy dom uwr policy out schedDomain\n  for A :: \"('a,'s,'e) data_type\" \n  and s0 :: \"'s\"\n  and dom :: \"'e \\<Rightarrow> 's \\<Rightarrow> 'd\"  \n  and uwr :: \"'d \\<Rightarrow> ('s \\<times> 's) set\"\n  and policy :: \"('d \\<times> 'd) set\"\n  and out :: \"'d \\<Rightarrow> 's \\<Rightarrow> 'p\"\n  and schedDomain :: \"'d\"\n\nsublocale unwinding_system \\<subseteq> noninterference_system\n  apply(unfold_locales)\n  done\n\ncontext unwinding_system begin\n\n\n\n\nlemma sources_refl:\n  \"reachable s \\<Longrightarrow> u \\<in> sources as s u\"\n  apply(induct as arbitrary: s)\n   apply(simp add: sources_Nil)\n  apply(simp add: sources_Cons)\n  apply(frule_tac a=a in enabled_Step)\n  apply (auto simp: reachable_Step)\n  done\n\n\n\nlemma schedDomain_in_sources_Cons:\n  \"reachable s \\<Longrightarrow> dom a s = schedDomain \\<Longrightarrow> dom a s \\<in> sources (a#as) s u\"\n  apply(unfold sources_Cons)\n  apply(erule ssubst)\n  apply(rule UnI2)\n  apply(clarsimp)\n  apply(rule_tac x=u in exI)\n  apply(safe)\n   apply(rule schedFlowsToAll)\n  apply(frule_tac a=a in enabled_Step)\n  apply(fastforce dest: sources_refl reachable_Step)\n  done\n\n\n\nlemma sources_eq':\n  \"confidentiality_u \\<and> s \\<sim>schedDomain\\<sim> t \\<and> reachable s \\<and> reachable t \\<longrightarrow> sources as s u = sources as t u\"\n  proof (induct as arbitrary: s t)\n  case Nil show ?case\n   apply(simp add: sources_Nil)\n   done\n  next\n  case (Cons a as) show ?case\n  apply(clarsimp simp: sources_Cons)\n  apply(rule un_eq)\n   apply(simp only: Union_eq, simp only: UNION_eq[symmetric])\n   apply(rule Un_eq, clarsimp)\n     apply(metis \"Cons.hyps\"[rule_format] sched_equiv_preserved reachable_Step)\n    apply(fastforce intro: enabled_Step)\n   apply(fastforce intro: enabled_Step)\n  apply(clarsimp simp: schedIncludesCurrentDom)\n  apply(rule Collect_cong)\n  apply(rule conj_cong, rule refl)\n  apply(rule iff_exI)\n  apply(metis \"Cons.hyps\"[rule_format] sched_equiv_preserved reachable_Step enabled_Step)\n  done\n  qed\n\n\nlemma sources_eq:\n  \"\\<lbrakk>confidentiality_u; s \\<sim>schedDomain\\<sim> t; reachable s; reachable t\\<rbrakk> \\<Longrightarrow> \n  sources as s u = sources as t u\"\n  apply(rule sources_eq'[rule_format], simp)\n  done\n\n\nlemma sameFor_sources_dom:\n  \"\\<lbrakk>s \\<approx>(sources (a#as) s u)\\<approx> t; dom a s \\<leadsto> x; x \\<in> sources as s' u; (s,s') \\<in> Step a\\<rbrakk> \\<Longrightarrow>\n   s \\<sim>(dom a s)\\<sim> t\"\n  apply(simp add: sameFor_dom_def)\n  apply(erule bspec)\n  apply(subst sources_Cons)\n  apply(rule UnI2)\n  apply blast\n  done\n\nlemma sources_unwinding_step:\n  \"\\<lbrakk>s \\<approx>(sources (a#as) s u)\\<approx> t; s \\<sim>schedDomain\\<sim> t; confidentiality_u;\n    (s,s') \\<in> Step a; (t,t') \\<in> Step a; reachable s; reachable t\\<rbrakk>  \\<Longrightarrow>\n    s' \\<approx>(sources as s' u)\\<approx> t'\"\n  apply(clarsimp simp: sameFor_dom_def sources_Cons)\n  apply(subst (asm) confidentiality_u_def)\n  apply(drule_tac x=a in spec)\n  apply(drule_tac x=ua in spec)\n  apply(drule_tac x=s in spec)\n  apply(drule_tac x=t in spec)\n  apply(fastforce intro: sameFor_sources_dom)\n  done\n\nlemma ipurge_eq'_helper:\n  \"\\<lbrakk>s \\<in> ss; dom a s \\<in> sources (a # as) s u; \\<forall>s\\<in>ts. dom a s \\<notin> sources (a # as) s u;\n   (\\<forall>s t. s \\<in> ss \\<and> t \\<in> ts \\<longrightarrow> s \\<sim>schedDomain\\<sim> t \\<and> reachable s \\<and> reachable t);  t \\<in> ts; confidentiality_u\\<rbrakk> \\<Longrightarrow>\n  False\"\n  apply(cut_tac s=s and t=t and as=as and u=u in sources_eq, simp+)\n  apply(clarsimp  simp: sources_Cons | safe)+\n  apply(rename_tac s')\n   apply(drule_tac x=t in bspec, simp)\n   apply clarsimp\n   apply(cut_tac s=t in enabled_Step, simp)\n   apply(erule exE, rename_tac t')\n   apply(drule_tac x=\"sources as t' u\" in spec)\n   apply(cut_tac s=s' and t=t' and u=u in sources_eq, simp+)\n      apply(fastforce elim: sched_equiv_preserved)\n     apply(fastforce intro: reachable_Step)\n    apply(fastforce intro: reachable_Step)\n   apply(fastforce simp: schedIncludesCurrentDom)\n  apply(drule_tac x=t in bspec, simp)\n  apply clarsimp\n  apply(rename_tac v s')\n  apply(drule_tac x=v in spec, erule impE, fastforce simp: schedIncludesCurrentDom)\n  apply(cut_tac s=t in enabled_Step[where a=a], simp, clarsimp, rename_tac t')\n  apply(cut_tac s=s' and t=t' and u=u in sources_eq, simp+)\n     apply(fastforce elim: sched_equiv_preserved)\n    apply(fastforce intro: reachable_Step)\n   apply(fastforce intro: reachable_Step)\n  apply(fastforce simp: schedIncludesCurrentDom)\n  done\n  \n  \n\nlemma ipurge_eq':\n  \"(\\<forall> s t. s\\<in>ss \\<and> t\\<in>ts \\<longrightarrow> s \\<sim>schedDomain\\<sim> t \\<and> reachable s \\<and> reachable t) \\<and> (\\<exists> s. s \\<in> ss) \\<and> (\\<exists> t. t \\<in> ts) \\<and> confidentiality_u \\<longrightarrow> ipurge u as ss = ipurge u as ts\"\n  proof (induct as arbitrary: ss ts)\n  case Nil show ?case\n   apply(simp add: ipurge_def)\n   done\n  next\n  case (Cons a as) show ?case\n   apply(clarsimp simp: ipurge_Cons schedIncludesCurrentDom)\n   apply(intro conjI impI)\n      apply(rule \"Cons.hyps\"[rule_format])\n      apply clarsimp\n      apply(metis sched_equiv_preserved reachable_Step enabled_Step)\n     apply clarsimp\n     apply(drule ipurge_eq'_helper, simp+)[1]\n    apply clarsimp\n    apply(drule ipurge_eq'_helper, (simp add: uwr_sym)+)[1]\n   apply(rule \"Cons.hyps\"[rule_format], auto)\n   done  \n  qed\n\nlemma ipurge_eq:\n  \"\\<lbrakk>s \\<sim>schedDomain\\<sim> t; reachable s; reachable t;\n    confidentiality_u\\<rbrakk> \\<Longrightarrow> \n   ipurge u as {s} = ipurge u as {t}\"\n  apply(rule ipurge_eq'[rule_format], simp)\n  done\n\nlemma Noninfluence_uwr_Noninfluence_strong_uwr:\n  \"\\<lbrakk>confidentiality_u; Noninfluence_uwr\\<rbrakk> \\<Longrightarrow> Noninfluence_strong_uwr\"\n  apply(clarsimp simp: Noninfluence_uwr_def Noninfluence_strong_uwr_def)\n  apply(frule_tac s=s and t=t and as=as and u=u in ipurge_eq)\n     apply assumption+\n  apply(frule_tac s=s and t=t and as=bs and u=u in ipurge_eq)\n     apply assumption+\n  apply clarsimp\n  apply(drule_tac x=u in spec)\n  apply(frule_tac x=as in spec)\n  apply(drule_tac x=s in spec, drule_tac x=t in spec)\n  apply(drule_tac x=bs in spec)\n  apply(drule_tac x=t in spec, drule_tac x=t in spec)\n  apply clarsimp\n  apply(rule_tac t=t in uwr_equiv_trans)\n    apply assumption\n   apply assumption\n  apply(rule uwr_equiv_sym)\n  apply(clarsimp simp: sameFor_dom_def uwr_refl)\n  done\n\nlemma Noninfluence_Noninfluence_strong:\n  \"\\<lbrakk>confidentiality_u; Noninfluence\\<rbrakk> \\<Longrightarrow> Noninfluence_strong\"\n  apply(clarsimp simp: Noninfluence_def Noninfluence_strong_def)\n  apply(frule_tac s=s and t=t and as=as and u=u in ipurge_eq)\n     apply assumption+\n  apply(frule_tac s=s and t=t and as=bs and u=u in ipurge_eq)\n     apply assumption+\n  apply clarsimp\n  apply(drule_tac x=u in spec)\n  apply(frule_tac x=as in spec)\n  apply(drule_tac x=s in spec, drule_tac x=t in spec)\n  apply(drule_tac x=bs in spec)\n  apply(drule_tac x=t in spec, drule_tac x=t in spec)\n  apply clarsimp\n  apply(rule_tac t=t in obs_equiv_trans)\n    apply assumption\n   apply assumption\n  apply(rule obs_equiv_sym)\n  apply(clarsimp simp: sameFor_dom_def uwr_refl)\n  done\n\n\nlemma dom_in_sources_Cons:\n  \"\\<lbrakk>confidentiality_u; reachable s; reachable t;\n    s \\<approx>(sources (a#as) s u)\\<approx> t; s \\<sim>schedDomain\\<sim> t;\n    (dom a s \\<in> sources (a#as) s u)\\<rbrakk> \\<Longrightarrow> \n    (dom a t \\<in> sources (a#as) t u)\"\n  apply(subgoal_tac \"dom a s = dom a t\")\n   apply(fastforce dest: sources_eq)\n  apply(blast intro: schedIncludesCurrentDom)\n  done\n\n\n\nlemma uwr_equiv_Cons_bothI:\n   \"\\<lbrakk>reachable s; reachable t;\n     \\<forall> s' t'. (s,s') \\<in> Step a \\<and> (t,t') \\<in> Step b \\<longrightarrow> uwr_equiv s' as t' bs u\\<rbrakk> \\<Longrightarrow>\n    uwr_equiv s (a # as) t (b # bs) u\"\n  apply(clarsimp simp: uwr_equiv_def)\n  apply(clarsimp simp: execution_Run)\n  apply(fastforce simp: execution_Run reachable_Step)\n  done\n\nlemma uwr_equiv_Cons_leftI:\n   \"\\<lbrakk>reachable s; \\<forall> s'. (s,s') \\<in> Step a \\<longrightarrow> uwr_equiv s' as t bs u\\<rbrakk> \\<Longrightarrow>\n    uwr_equiv s (a # as) t bs u\"\n  apply(fastforce simp: uwr_equiv_def execution_Run reachable_Step)\n  done\n\n\nlemma notin_policyI':\n  \"\\<lbrakk>reachable s;\n    dom a s \\<notin> sources (a # list) s u; (s,s') \\<in> Step a; ua \\<in> sources list s' u\\<rbrakk> \\<Longrightarrow>\n   (dom a s,ua) \\<notin> policy\"\n  apply(rule notin_policyI)\n  apply auto\n  done\n\nlemma sources_eq_Step:\n  \"\\<lbrakk>integrity_u; confidentiality_u; reachable s; (s,s') \\<in> Step a; dom a s \\<noteq> schedDomain\\<rbrakk> \\<Longrightarrow>\n   (sources as s' u) = (sources as s u)\"\n  apply(rule sources_eq, simp+)\n    apply(rule_tac t=s and s=s and a=a in sched_equiv_preserved_left, (simp add: uwr_refl reachable_Step)+)\n  done\n  \nlemma sources_equiv_preserved_left:\n  \"\\<lbrakk>integrity_u; confidentiality_u; reachable s; reachable t; s \\<sim>schedDomain\\<sim> t; \n    dom a s \\<notin> sources (a#as) s u; s \\<approx>sources (a#as) s u\\<approx> t; (s,s') \\<in> Step a; dom a s \\<noteq> schedDomain\\<rbrakk> \\<Longrightarrow>\n   s' \\<approx>sources as s' u\\<approx> t\"\n  apply(clarsimp simp: sameFor_dom_def)\n  apply(rename_tac v)\n  apply(case_tac \"(dom a s, v) \\<in> policy\")\n   apply(fastforce simp: sources_Cons)\n  apply(fastforce dest: integrity_uD simp: sources_Cons)\n  done\n\nlemma Noninfluence_gen:\n  \"\\<lbrakk>confidentiality_u; integrity_u\\<rbrakk> \\<Longrightarrow> Noninfluence_gen\"\n  apply(subst Noninfluence_gen_def)\n  apply(intro allI)\n  proof -\n  assume conf: \"confidentiality_u\"\n  assume integ: \"integrity_u\"\n  fix u as s ts\n  show \"reachable s \\<and> Ball ts reachable \\<longrightarrow>\n          Ball ts (sameFor_dom s (sources as s u)) \\<longrightarrow> (\\<forall>t\\<in>ts. s \\<sim>schedDomain\\<sim> t) \\<longrightarrow> (\\<forall>t\\<in>ts. uwr_equiv s as t (ipurge u as ts) u)\"\n    proof(induct as arbitrary: s ts)\n    case Nil\n    show ?case\n      apply(clarsimp simp: sameFor_dom_def ipurge_Nil sources_Nil uwr_equiv_def)\n      apply(clarsimp simp: execution_Run)\n      done\n    next\n    case (Cons a as)\n    show ?case\n  apply(clarsimp simp: ipurge_Cons | safe)+\n   apply(rule uwr_equiv_Cons_bothI)\n     apply assumption\n    apply blast\n   apply(clarify)\n   apply(rename_tac ta tb s' tb')\n   apply(rule Cons.hyps[rule_format])\n      apply(blast intro: reachable_Step)\n     apply(clarsimp)\n     apply(rename_tac tc' tc)\n     using conf apply(rule_tac s=s and t=tc and a=a in sources_unwinding_step, simp+)[1]\n    apply(clarsimp, rename_tac tc' tc)\n    apply(rule sched_equiv_preserved[OF conf], (auto simp: sources_refl))[1]\n   apply blast\n  apply(rename_tac ta)\n  apply(rule uwr_equiv_Cons_leftI, blast)\n  apply(clarsimp, rename_tac s')\n  apply(case_tac \"dom a s = schedDomain\")\n   apply(cut_tac s=s and a=a and as=as and u=u in schedDomain_in_sources_Cons, assumption+)\n   apply(metis schedIncludesCurrentDom sources_eq[OF conf])\n  apply(rule Cons.hyps[rule_format])\n     apply(blast intro: reachable_Step)\n    apply(rename_tac tb)\n    apply(rule_tac a=a in sources_equiv_preserved_left[OF integ conf], simp+)\n       apply(fastforce simp: schedIncludesCurrentDom sources_eq[OF conf])\n      apply blast\n     apply assumption\n    apply assumption\n   apply(rule_tac s=s and a=a in sched_equiv_preserved_left[OF integ], simp+)\n  done\n  qed\n  qed\n\nlemma Nonleakage_gen:\n  \"\\<lbrakk>confidentiality_u\\<rbrakk> \\<Longrightarrow> Nonleakage_gen\"\n  apply(subst Nonleakage_gen_def)\n  apply(rule allI)  \n  apply(induct_tac as)\n   apply(simp add: sources_Nil uwr_equiv_def execution_Run sameFor_dom_def)\n  apply(clarsimp)\n  apply(rule uwr_equiv_Cons_bothI)\n    apply assumption\n   apply assumption\n  apply clarsimp\n  apply(drule_tac x=s' in spec, drule_tac x=u in spec, drule_tac x=t' in spec)\n  apply(clarsimp simp: reachable_Step)\n  apply(erule impE)\n   apply(blast intro: sched_equiv_preserved)\n  apply(erule mp)\n  apply(blast intro: sources_unwinding_step)\n  done\n   \n\n\nlemma Noninterference:\n  \"\\<lbrakk>confidentiality_u_weak; output_consistent; integrity_u\\<rbrakk> \\<Longrightarrow> \n   Noninterference\"\n  apply(rule Noninfluence_gen_Noninterference)\n   apply assumption\n  apply(blast intro: Noninfluence_gen confidentiality_u_weak)\n  done\n\nlemma Noninterference_strong:\n  \"\\<lbrakk>confidentiality_u_weak; output_consistent; integrity_u\\<rbrakk> \\<Longrightarrow> \n   Noninterference_strong\"\n  apply(rule Noninfluence_gen_Noninterference_strong)\n   apply assumption\n  apply(blast intro: Noninfluence_gen confidentiality_u_weak)\n  done\n\n\n\nlemma Noninfluence:\n  \"\\<lbrakk>confidentiality_u_weak; output_consistent; integrity_u\\<rbrakk> \\<Longrightarrow> \n   Noninfluence\"\n  apply(rule Noninfluence_gen_Noninfluence)\n   apply assumption\n  apply(blast intro: Noninfluence_gen confidentiality_u_weak)\n  done\n\nlemma Noninfluence_strong:\n  \"\\<lbrakk>confidentiality_u_weak; output_consistent; integrity_u\\<rbrakk> \\<Longrightarrow> \n   Noninfluence_strong\"\n  apply(rule Noninfluence_Noninfluence_strong)\n   apply(blast intro: confidentiality_u_weak)\n  apply(blast intro: Noninfluence)\n  done\n\n\nlemma Noninfluence_uwr:\n  \"\\<lbrakk>confidentiality_u_weak; integrity_u\\<rbrakk> \\<Longrightarrow> \n   Noninfluence_uwr\"\n  apply(rule Noninfluence_gen_Noninfluence_uwr)\n  apply(blast intro: Noninfluence_gen confidentiality_u_weak)\n  done\n\nlemma Noninfluence_strong_uwr:\n  \"\\<lbrakk>confidentiality_u_weak; integrity_u\\<rbrakk> \\<Longrightarrow> \n   Noninfluence_strong_uwr\"\n  apply(rule Noninfluence_uwr_Noninfluence_strong_uwr)\n   apply(blast intro: confidentiality_u_weak)\n  apply(blast intro: Noninfluence_uwr)\n  done\n\nlemma sources_Step:\n  \"\\<lbrakk>reachable s; (dom a s, u) \\<notin> policy\\<rbrakk> \\<Longrightarrow>\n  sources [a] s u = {u}\"\n  apply(auto simp: sources_Cons sources_Nil enabled_Step dest: enabled_Step)\n  done\n\nlemma sources_Step_2:\n  \"\\<lbrakk>reachable s; (dom a s, u) \\<in> policy\\<rbrakk> \\<Longrightarrow>\n  sources [a] s u = {dom a s,u}\"\n  apply(auto simp: sources_Cons sources_Nil enabled_Step dest: enabled_Step)\n  done\n\nlemma execution_Nil:\n  \"reachable s \\<Longrightarrow> execution A s [] = {s}\"\n  apply(simp add: execution_Run)\n  done\n\nlemma Noninfluence_gen_confidentiality_u_weak:\n  \"Noninfluence_gen \\<Longrightarrow> confidentiality_u_weak\"\n  apply(clarsimp simp: Noninfluence_gen_def confidentiality_u_weak_def)\n  apply(drule_tac x=u in spec, drule_tac x=\"[a]\" in spec)\n  apply(drule_tac x=s in spec, drule_tac x=\"{t}\" in spec)\n  apply(simp add: sources_Step_2 sameFor_dom_def uwr_equiv_def Step_def ipurge_Cons ipurge_Nil split: if_splits add: schedIncludesCurrentDom)\n  done\n\nlemma Noninfluence_strong_uwr_confidentiality_u_weak:\n  \"Noninfluence_strong_uwr \\<Longrightarrow> confidentiality_u_weak\"\n  apply(clarsimp simp: Noninfluence_strong_uwr_def confidentiality_u_weak_def)\n  apply(drule_tac x=u in spec, drule_tac x=\"[a]\" in spec, drule_tac x=\"[a]\" in spec)\n  apply(drule_tac x=s in spec, drule_tac x=t in spec)\n  apply(simp add: sources_Step_2 sameFor_dom_def uwr_equiv_def Step_def)\n  done\n\nlemma Nonleakage_gen_confidentiality_u:\n  \"Nonleakage_gen \\<Longrightarrow> confidentiality_u\"\n  apply(clarsimp simp: Nonleakage_gen_def confidentiality_u_def)\n  apply(drule_tac x=\"[a]\" in spec, drule_tac x=s in spec)\n  apply(drule_tac x=u in spec, drule_tac x=t in spec)\n  apply(case_tac \"dom a s \\<leadsto> u\")\n   apply(simp add: sources_Step_2 uwr_equiv_def sameFor_dom_def Step_def)\n  apply(simp add: sources_Step uwr_equiv_def sameFor_dom_def Step_def)\n  done\n\nlemma Nonleakage_gen_equiv_confidentiality_u:\n  \"Nonleakage_gen = confidentiality_u\"\n  apply(blast intro: Nonleakage_gen_confidentiality_u Nonleakage_gen)\n  done\n\nlemma non_sched_doms_cannot_schedule:\n  \"\\<lbrakk>integrity_u; reachable s; dom a s \\<noteq> schedDomain; (s,s') \\<in> Step a\\<rbrakk> \\<Longrightarrow> s \\<sim>schedDomain\\<sim> s'\"\n  apply(drule_tac u=schedDomain in integrity_uD)\n      apply assumption\n     apply(erule contrapos_nn)\n     apply(erule schedNotGlobalChannel)\n    apply(rule uwr_refl)\n   apply assumption\n  apply(erule uwr_sym)\n  done\n\n\ntext {*\n   In systems with just a single event, @{prop integrity_u} is a very strong\n   condition. It implies that once the scheduler is not\n   running, it can never run again.\n\n   This is one explanation for why seL4 (whose automaton has only a single\n   event) doesn't satisfy @{prop integrity_u}.\n*}\nlemma integrity_u_and_single_event_systems:\n  \"\\<lbrakk>integrity_u; reachable s; dom a s \\<noteq> schedDomain; s' \\<in> execution A s as;\n    \\<forall> y::'e. y = a\\<rbrakk> \\<Longrightarrow> dom e s' \\<noteq> schedDomain\"\n  apply(frule_tac x=e in spec)\n  apply(erule ssubst)\n  apply(rule_tac P=\"\\<lambda>x. x \\<noteq> schedDomain\" in subst[rotated])\n   apply assumption\n  apply(induct as arbitrary: s s' a rule: rev_induct)\n   apply(simp add: execution_Run)\n  apply(simp add: execution_Run)\n  apply(drule Run_mid)\n  apply(erule exE, rename_tac t)\n  apply(drule_tac x=s in meta_spec)\n  apply(drule_tac x=t in meta_spec)\n  apply(drule_tac x=a in meta_spec)\n  apply simp\n  apply(rule schedIncludesCurrentDom)\n  apply(rule non_sched_doms_cannot_schedule)\n     apply assumption\n    apply(rule reachable_execution)\n     apply assumption\n    apply(fastforce simp: execution_Run)\n   apply assumption\n  apply(drule_tac x=x in spec)\n  apply blast\n  done\n\nend\n\n\ntext {* The unwinding conditions are not only sound but also complete *}\nlocale complete_unwinding_system = unwinding_system +\n  assumes  policy_refl:\n  \"(u,u) \\<in> policy\"\n\ncontext complete_unwinding_system begin\n\nlemma Noninfluence_gen_integrity_u:\n  \"Noninfluence_gen \\<Longrightarrow> integrity_u\"\n  apply(clarsimp simp: Noninfluence_gen_def integrity_u_def)\n  apply(drule_tac x=u in spec, drule_tac x=\"[a]\" in spec)\n  apply(drule_tac x=s in spec, drule_tac x=\"{s}\" in spec)\n  apply(simp add: sources_Step sameFor_dom_def uwr_equiv_def Step_def ipurge_Cons ipurge_Nil split: if_splits add: uwr_refl policy_refl execution_Nil uwr_sym)\n  done\n\n\nlemma Noninfluence_strong_uwr_integrity_u: \"Noninfluence_strong_uwr \\<Longrightarrow> integrity_u\"\n  apply(clarsimp simp: Noninfluence_strong_uwr_def integrity_u_def)\n  apply(drule_tac x=u in spec, drule_tac x=\"[a]\" in spec, drule_tac x=\"[]\" in spec)\n  apply(drule_tac x=s in spec, drule_tac x=s in spec)\n  apply(simp add: sources_Step sameFor_dom_def uwr_refl uwr_equiv_def Step_def ipurge_Cons ipurge_Nil split: if_splits)\n   apply(simp add: policy_refl)\n  apply(simp add: execution_Nil)\n  apply(blast intro: uwr_sym)\n  done\n\ntext {*\n   @{prop Noninfluence_gen} actually turns out to be equivalent to @{prop Noninfluence_strong_uwr},\n   when the policy is reflexive. So the two unwinding conditions for integrity\n   and confidentiality actually turn out to be sound and sufficient for the\n   condition we were using them to prove in the first place. \n*}\nlemma Noninfluence_gen_equiv_Noninfluence_strong_uwr:\n  \"Noninfluence_gen = Noninfluence_strong_uwr\"\n  apply(rule iffI)\n   apply(rule Noninfluence_strong_uwr)\n    apply(erule Noninfluence_gen_confidentiality_u_weak)\n   apply(erule Noninfluence_gen_integrity_u)\n  apply(rule Noninfluence_gen)\n   apply(rule confidentiality_u_weak)\n    apply(erule Noninfluence_strong_uwr_confidentiality_u_weak)\n   apply(erule Noninfluence_strong_uwr_integrity_u)+\n  done\n\nend\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/l4v/proof/infoflow/Noninterference_Base.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6477982179521103, "lm_q2_score": 0.3886180267058489, "lm_q1q2_score": 0.2517460651641145}}
{"text": "(*\n * @TAG(OTHER_LGPL)\n *)\n\n(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      ClosureEx.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2006-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\ntheory ClosureEx\nimports \"../Vcg\" \"../Simpl_Heap\" Closure\nbegin\n\n\nrecord globals = \n cnt_' :: \"ref \\<Rightarrow> nat\"\n alloc_' :: \"ref list\"\n free_' :: \"nat\"\nrecord 'g vars = \"'g state\" +\n p_':: ref\n r_':: nat\n n_':: nat\n m_':: nat\n c_':: \"(string \\<times> ref) list \\<times> string\"\n d_':: \"(string \\<times> ref) list \\<times> string\"\n e_':: \"(string \\<times> nat) list \\<times> string\"\n\n\ndefinition \"var\\<^sub>n = [''n''\\<mapsto> (\\<lambda>x. n_'_update (\\<lambda>_. x)),\n                    ''m''\\<mapsto> (\\<lambda>x. m_'_update (\\<lambda>_. x))]\"\ndefinition \"upd\\<^sub>n = gen_upd var\\<^sub>n\"\n\nlemma upd\\<^sub>n_ap: \"upd\\<^sub>n (fst (ap es (es',p))) = upd\\<^sub>n es' \\<circ> upd\\<^sub>n es\"\n  by (simp add: upd\\<^sub>n_def gen_upd_ap)\n\n\nlemma\n\"\\<Gamma>\\<turnstile>\\<lbrace>\\<acute>n=n\\<^sub>0 \\<and> (\\<forall>i j. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>n=i \\<and> \\<acute>m=j\\<rbrace> callClosure upd\\<^sub>n \\<acute>e \\<lbrace>\\<acute>r=i + j\\<rbrace>)\\<rbrace> \n      \\<acute>e :== (ap [(''n'',\\<acute>n)] \\<acute>e) \n   \\<lbrace>\\<forall>j. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>m=j\\<rbrace> callClosure upd\\<^sub>n \\<acute>e \\<lbrace>\\<acute>r=n\\<^sub>0 + j\\<rbrace>\\<rbrace>\"\napply vcg_step\napply clarify\napply (rule ap_closure [where var=var\\<^sub>n, folded upd\\<^sub>n_def])\napply clarsimp\napply (rename_tac s s')\napply (erule_tac x=\"n_' s\" in allE) \napply (erule_tac x=\"m_' s'\" in allE) \napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply (assumption)\napply (simp add: upd\\<^sub>n_def gen_upd_def var\\<^sub>n_def)\ndone\n\n\ndefinition \"var = [''p''\\<mapsto> (\\<lambda>x. p_'_update (\\<lambda>_. x))]\"\ndefinition \"upd = gen_upd var\"\n\nprocedures Inc(p|r) =\n \"\\<acute>p\\<rightarrow>\\<acute>cnt :== \\<acute>p\\<rightarrow>\\<acute>cnt + 1;;\n  \\<acute>r :== \\<acute>p\\<rightarrow>\\<acute>cnt\"\n\nlemma (in Inc_impl)\n \"\\<forall>i p. \\<Gamma>\\<turnstile> \\<lbrace>\\<acute>p\\<rightarrow>\\<acute>cnt = i\\<rbrace> \\<acute>r :== PROC Inc(\\<acute>p) \\<lbrace>\\<acute>r=i+1 \\<and> \\<acute>p\\<rightarrow>\\<acute>cnt = i+1\\<rbrace>\"\n  apply vcg\n  apply simp\n  done\n  \nprocedures (imports Inc_signature) NewCounter(|c) =\n\"\\<acute>p :== NEW 1 [\\<acute>cnt :== 0];;\n \\<acute>c :== ([(''p'',\\<acute>p)],Inc_'proc)\" \n\n\nlocale NewCounter_impl' = NewCounter_impl + Inc_impl\nlemma (in NewCounter_impl')\nshows \n  \"\\<forall>alloc. \\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free\\<rbrace> \\<acute>c :== PROC NewCounter() \n          \\<lbrace>\\<exists>p. p\\<rightarrow>\\<acute>cnt = 0 \\<and>\n               (\\<forall>i. \\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = i\\<rbrace> callClosure upd \\<acute>c \\<lbrace>\\<acute>r=i+1 \\<and> p\\<rightarrow>\\<acute>cnt = i+1\\<rbrace>)\\<rbrace>\"\napply vcg\napply simp\napply (rule_tac x=\"new (set alloc)\" in exI)\napply simp\napply (simp add: callClosure_def)\napply vcg_step\napply vcg_step\napply vcg_step\napply vcg_step\napply (simp add: upd_def var_def gen_upd_def)\ndone\n\nlemma (in NewCounter_impl')\n\nshows \n  \"\\<forall>alloc. \\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free\\<rbrace> \\<acute>c :== PROC NewCounter() \n          \\<lbrace>\\<exists>p. p\\<rightarrow>\\<acute>cnt = 0 \\<and>\n               (\\<forall>i. \\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = i\\<rbrace> callClosure upd \\<acute>c \\<lbrace>\\<acute>r=i+1 \\<and> p\\<rightarrow>\\<acute>cnt = i+1\\<rbrace>)\\<rbrace>\"\napply vcg\napply simp\napply (rule_tac x=\"new (set alloc)\" in exI)\napply simp\napply (simp add: callClosure_def)\napply vcg_step\napply vcg_step\napply vcg_step\napply vcg_step\napply (simp add: upd_def var_def gen_upd_def)\ndone\n\nlemma (in NewCounter_impl')\nshows NewCounter_spec:\n  \"\\<forall>alloc. \\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free \\<and> \\<acute>alloc=alloc\\<rbrace> \\<acute>c :== PROC NewCounter() \n          \\<lbrace>\\<exists>p. p \\<notin> set alloc \\<and> p \\<in> set \\<acute>alloc \\<and> p \\<noteq> Null \\<and> p\\<rightarrow>\\<acute>cnt = 0 \\<and>\n               (\\<forall>i. \\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = i\\<rbrace> callClosure upd \\<acute>c \\<lbrace>\\<acute>r=i+1 \\<and> p\\<rightarrow>\\<acute>cnt = i+1\\<rbrace>)\\<rbrace>\"\napply vcg\napply clarsimp\napply (rule_tac x=\"new (set alloc)\" in exI)\napply simp\napply (simp add: callClosure_def)\napply vcg_step\napply vcg_step\napply vcg_step\napply vcg_step\napply (simp add: upd_def var_def gen_upd_def)\ndone\n\n\n\nlemma \"\\<Gamma>\\<turnstile>\\<lbrace>\\<exists>p. p \\<noteq> Null \\<and> p\\<rightarrow>\\<acute>cnt = i \\<and>\n              (\\<forall>i. \\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = i\\<rbrace> callClosure upd \\<acute>c \\<lbrace>\\<acute>r=i+1 \\<and> p\\<rightarrow>\\<acute>cnt = i+1\\<rbrace>)\\<rbrace>\n           dynCallClosure (\\<lambda>s. s) upd c_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>) \n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>r_' := r_' t\\<rparr>))\n           \\<lbrace>\\<acute>r=i+1\\<rbrace>\"\napply (rule conseq_extract_pre)\napply clarify\napply (rule dynCallClosureFix)\napply (simp only: Ball_def)\nprefer 3\napply (assumption)\nprefer 2\napply vcg_step\napply vcg_step\napply (simp only: simp_thms)\napply clarsimp\ndone\n\nlemma (in NewCounter_impl')\n shows \"\\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free\\<rbrace> \n             \\<acute>c :== CALL NewCounter ();;\n             dynCallClosure (\\<lambda>s. s) upd c_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>) \n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>r_' := r_' t\\<rparr>))\n           \\<lbrace>\\<acute>r=1\\<rbrace>\"\napply vcg_step\napply (rule dynCallClosure)\nprefer 2\napply vcg_step\napply vcg_step\napply vcg_step\napply clarsimp\napply (erule_tac x=0 in allE)\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply (assumption)\napply simp\ndone\n\n\nlemma (in NewCounter_impl')\n shows \"\\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free\\<rbrace> \n             \\<acute>c :== CALL NewCounter ();;\n             dynCallClosure (\\<lambda>s. s) upd c_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>) \n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>r_' := r_' t\\<rparr>));;\n             dynCallClosure (\\<lambda>s. s) upd c_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>) \n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>r_' := r_' t\\<rparr>))\n           \\<lbrace>\\<acute>r=2\\<rbrace>\"\napply vcg_step\napply (rule dynCallClosure)\nprefer 2\napply vcg_step\napply vcg_step\napply vcg_step\napply (rule dynCallClosure)\napply vcg_step\napply vcg_step\napply vcg_step\n\napply clarsimp\napply (subgoal_tac \"\\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = 0\\<rbrace> callClosure upd (c_' t) \\<lbrace>\\<acute>r = Suc 0 \\<and> p\\<rightarrow>\\<acute>cnt = Suc 0\\<rbrace>\")\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply assumption\napply clarsimp\napply (erule_tac x=1 in allE)\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply assumption\napply clarsimp\napply (erule allE)\napply assumption\ndone\n\n\nlemma (in NewCounter_impl')\n shows \"\\<Gamma>\\<turnstile> \\<lbrace>1 \\<le> \\<acute>free\\<rbrace> \n             \\<acute>c :== CALL NewCounter ();;\n             \\<acute>d :== \\<acute>c;;\n             dynCallClosure (\\<lambda>s. s) upd c_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>) \n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>n_' := r_' t\\<rparr>));;\n             dynCallClosure (\\<lambda>s. s) upd d_' (\\<lambda>s t. s\\<lparr>globals := globals t\\<rparr>) \n                         (\\<lambda>s t. Basic (\\<lambda>u. u\\<lparr>m_' := r_' t\\<rparr>));;\n             \\<acute>r :== \\<acute>n + \\<acute>m\n           \\<lbrace>\\<acute>r=3\\<rbrace>\"\n\napply vcg_step\napply vcg_step\napply (rule dynCallClosure)\nprefer 2\napply vcg_step\napply vcg_step\napply vcg_step\napply (rule dynCallClosure)\napply vcg_step\napply vcg_step\napply vcg_step\napply vcg_step\napply clarsimp\napply (subgoal_tac \"\\<Gamma>\\<turnstile> \\<lbrace>p\\<rightarrow>\\<acute>cnt = 0\\<rbrace> callClosure upd (c_' t) \\<lbrace>\\<acute>r = Suc 0 \\<and> p\\<rightarrow>\\<acute>cnt = Suc 0\\<rbrace>\")\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply assumption\napply clarsimp\napply (erule_tac x=1 in allE)\napply (rule exI)\napply (rule exI)\napply (rule conjI)\napply assumption\napply clarsimp\napply (erule allE)\napply assumption\ndone\n\nend\n", "meta": {"author": "crizkallah", "repo": "checker-verification", "sha": "cd5101e57ef70dcdd1680db2de2f08521605bd7c", "save_path": "github-repos/isabelle/crizkallah-checker-verification", "path": "github-repos/isabelle/crizkallah-checker-verification/checker-verification-cd5101e57ef70dcdd1680db2de2f08521605bd7c/autocorres-1.0/c-parser/hoare-package/ex/ClosureEx.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5506073802837477, "lm_q2_score": 0.45713671682749485, "lm_q1q2_score": 0.2517028500839003}}
{"text": "theory Impl_List_Playground_ChairNetwork\nimports \"../TopoS_Impl\"\nbegin\n\n\ntext{*An example of our chair network [simplified]*}\n\nabbreviation \"V\\<equiv>TopoS_Vertices.V\"\n\ntext{*Our access control view on the network*}\n  definition ChairNetwork_empty :: \"vString list_graph\" where\n    \"ChairNetwork_empty \\<equiv> \\<lparr> nodesL = [V ''WebSrv'', V ''FilesSrv'', V ''PrinterBW'',\n                                V ''PrinterColor'', V ''Students'',\n                                V ''Employees'', V ''EReachable'',\n                                V ''Internet''],\n                      edgesL = [] \\<rparr>\"\n  \n  lemma \"valid_list_graph ChairNetwork_empty\" by eval\n\n\nsubsection{*Our security requirements*}\n  subsubsection{*We have a server with confidential data*}\n    definition ConfidentialChairData::\"(vString SecurityInvariant)\" where\n      \"ConfidentialChairData \\<equiv> new_configured_list_SecurityInvariant SINVAR_BLPtrusted_impl.SINVAR_LIB_BLPtrusted \\<lparr> \n          node_properties = [V ''FilesSrv'' \\<mapsto> \\<lparr> privacy_level = 1, trusted = False \\<rparr>,\n                             V ''Employees'' \\<mapsto> \\<lparr> privacy_level = 0, trusted = True \\<rparr>,\n                             V ''EReachable'' \\<mapsto> \\<lparr> privacy_level = 0, trusted = True \\<rparr>], \n          model_global_properties = () \n          \\<rparr>\"\n\n\n  (*\n  subsubsection{*We have a hierarchical printing policy*}\n    definition \"PrintingHierarchy_nodes=[V ''Employees''\\<mapsto> DN (''ColorPrinting''--Leaf, 0),\n                           V ''PrinterColor''\\<mapsto> DN (''ColorPrinting''--''Printer''--Leaf, 0),\n                           V ''Students''\\<mapsto> DN (''ColorPrinting''--''BwPrinting''--Leaf, 0),\n                           V ''PrinterBW''\\<mapsto> DN (''ColorPrinting''--''BwPrinting''--''Printer''--Leaf, 0)]\"\n    definition \"PrintingHierarchy_tree=Department ''ColorPrinting'' [\n              Department ''Printer'' [], \n              Department ''BwPrinting'' [\n                  Department ''Printer'' []]]\"\n    definition PrintingHierarchy::\"vString SecurityInvariant\" where\n      \"PrintingHierarchy \\<equiv> new_configured_list_SecurityInvariant SINVAR_DomainHierarchyNG_impl.SINVAR_LIB_DomainHierarchyNG \\<lparr> \n        node_properties = PrintingHierarchy_nodes,\n        model_global_properties = PrintingHierarchy_tree\n        \\<rparr>\"\n  \n    --\"verify globals, I admit, not very elegant\"\n    lemma \"nm_verify_globals SINVAR_DomainHierarchyNG_impl.SINVAR_LIB_DomainHierarchyNG ChairNetwork_empty \n          (nm_node_props SINVAR_DomainHierarchyNG_impl.SINVAR_LIB_DomainHierarchyNG \\<lparr> node_properties = PrintingHierarchy_nodes, model_global_properties = PrintingHierarchy_tree \\<rparr>) PrintingHierarchy_tree\" by eval\n  *)\n  subsubsection{* The color printer is only accessibly by employees, The black.white printer by employees and students*}\n    definition \"PrintingACL \\<equiv> new_configured_list_SecurityInvariant SINVAR_LIB_CommunicationPartners \\<lparr> \n          node_properties = [V ''PrinterColor'' \\<mapsto> Master [V ''Employees'', V ''EReachable''],\n                             V ''PrinterBW'' \\<mapsto> Master [V ''Employees'', V ''EReachable'', V ''Students''],\n                             V ''Employees'' \\<mapsto> Care,\n                             V ''EReachable'' \\<mapsto> Care,\n                             V ''Students'' \\<mapsto> Care], \n          model_global_properties = () \n          \\<rparr>\"\n\n  subsubsection{* Printers are information sinks *}\n    definition \"PrintingSink \\<equiv> new_configured_list_SecurityInvariant SINVAR_LIB_Sink \\<lparr> \n          node_properties = [V ''PrinterColor'' \\<mapsto> Sink,\n                             V ''PrinterBW'' \\<mapsto> Sink], \n          model_global_properties = () \n          \\<rparr>\"\n\n\n\n  subsubsection{*Students may access each other but are not accessible from the outside*}\n    definition \"StudentSubnet \\<equiv> new_configured_list_SecurityInvariant SINVAR_LIB_SubnetsInGW \\<lparr> \n          node_properties = [V ''Students'' \\<mapsto> Member, V ''Employees'' \\<mapsto> Member, V ''EReachable'' \\<mapsto> InboundGateway], \n          model_global_properties = () \n          \\<rparr>\"\n\n\n  subsubsection{* The files server is only accessibly by employees*}\n    definition \"FilesSrcACL \\<equiv> new_configured_list_SecurityInvariant SINVAR_LIB_CommunicationPartners \\<lparr> \n          node_properties = [V ''FilesSrv'' \\<mapsto> Master [V ''Employees'', V ''EReachable''],\n                             V ''Employees'' \\<mapsto> Care,\n                             V ''EReachable'' \\<mapsto> Care], \n          model_global_properties = () \n          \\<rparr>\"\n\n\n  subsubsection{*emplyees are reachable from the Internet*}\n    (*nothing to do here*)\n\nlemma \"implc_sinvar ConfidentialChairData ChairNetwork_empty\" by eval\nlemma \"implc_sinvar PrintingACL ChairNetwork_empty\" by eval\nlemma \"implc_sinvar PrintingSink ChairNetwork_empty\" by eval\nlemma \"implc_sinvar StudentSubnet ChairNetwork_empty\" by eval\nlemma \"implc_sinvar FilesSrcACL ChairNetwork_empty\" by eval\n\ndefinition \"ChairSecurityRequirements = [ConfidentialChairData, PrintingACL, PrintingSink, StudentSubnet, FilesSrcACL]\"\n\nvalue \"implc_get_offending_flows ChairSecurityRequirements ChairNetwork_empty\"\nvalue \"generate_valid_topology ChairSecurityRequirements ChairNetwork_empty\"\n\nvalue \"List.product (nodesL ChairNetwork_empty) (nodesL ChairNetwork_empty)\"\n\ndefinition \"ChairNetwork = generate_valid_topology ChairSecurityRequirements \n      \\<lparr>nodesL = nodesL ChairNetwork_empty, edgesL = List.product (nodesL ChairNetwork_empty) (nodesL ChairNetwork_empty) \\<rparr>\"\n\nlemma \"all_security_requirements_fulfilled ChairSecurityRequirements ChairNetwork\" by eval\n\nvalue \"ChairNetwork\"\n\nML_val{*\nvizualize_graph @{context} @{term \"ChairSecurityRequirements\"} @{term \"ChairNetwork\"};\n*}\n\n\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Network_Security_Policy_Verification/Examples/Impl_List_Playground_ChairNetwork.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5698526514141571, "lm_q2_score": 0.4416730056646256, "lm_q1q2_score": 0.2516885333360469}}
{"text": "(*\n * Copyright 2014, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the BSD 2-Clause license. Note that NO WARRANTY is provided.\n * See \"LICENSE_BSD2.txt\" for details.\n *\n * @TAG(NICTA_BSD)\n *)\n\ntheory ArraysMemInstance\nimports Arrays CompoundCTypes\nbegin\n\nprimrec\n  array_tag_n :: \"nat \\<Rightarrow> ('a::c_type,'b::finite) array typ_info\"\nwhere\n  atn_base:\n  \"array_tag_n 0 = ((empty_typ_info (typ_name (typ_uinfo_t TYPE('a)) @ ''_array_'' @\n      nat_to_bin_string (CARD('b::finite))))::('a::c_type,'b) array\n          typ_info)\"\n| atn_rec:\n  \"array_tag_n (Suc n) = ((ti_typ_combine TYPE('a::c_type)\n      (\\<lambda>x. index x n) (\\<lambda>x f. update f n x) (replicate n CHR ''1'')\n          (array_tag_n n))::('a,'b::finite) array typ_info)\"\n\ndefinition\n  array_tag :: \"('a::c_type,'b::finite) array itself \\<Rightarrow> ('a,'b) array typ_info\" where\n  \"array_tag t \\<equiv> array_tag_n (CARD('b))\"\n\ninstance array :: (c_type,finite) c_type ..\n\noverloading typ_info_array \\<equiv> typ_info_t begin\ndefinition\n  typ_info_array: \"typ_info_array (w::('a::c_type,'b::finite) array itself) \\<equiv> array_tag w\"\nend\n\nlemma field_names_array_tag_length [rule_format]:\n  \"x \\<in> set (field_names_list (array_tag_n n)) \\<longrightarrow> length x < n\"\napply(induct_tac n)\n apply simp\napply clarsimp\ndone\n\nlemma replicate_mem_field_names_array_tag [simp]:\n  \"replicate n x \\<notin> set (field_names_list (array_tag_n n))\"\napply clarsimp\napply(drule field_names_array_tag_length)\napply simp\ndone\n\nlemma aggregate_array_tag [simp]:\n  \"aggregate (array_tag_n n)\"\napply(case_tac n)\n apply simp+\ndone\n\nlemma wf_desc_array_tag [simp]:\n  \"wf_desc ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info)\"\napply(induct_tac n)\n apply simp+\napply(erule wf_desc_ti_typ_combine)\napply simp\ndone\n\nlemma wf_size_desc_array_tag [simp, rule_format]:\n  \"0 < n \\<longrightarrow> wf_size_desc ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info)\"\napply(induct n)\n apply simp+\napply(case_tac \"n=0\")\n apply simp\napply(rule wf_size_desc_ti_typ_combine)\napply simp\ndone\n\nlemma g_ind_array_tag_udpate [simp]:\n  \"n \\<le> m \\<longrightarrow> n \\<le> CARD('b) \\<longrightarrow>\n      g_ind (lf_set ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info) []) (\\<lambda>x f. update f m x)\"\napply(induct_tac n)\n apply clarsimp+\napply(erule g_ind_ti_typ_combine)\n apply clarsimp+\ndone\n\nlemma fc_array_tag_udpate [simp]:\n  \"n \\<le> m \\<longrightarrow> n \\<le> CARD('b) \\<longrightarrow>\n      fu_commutes (update_ti_t ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info)) (\\<lambda>x f. update f m x)\"\napply(induct_tac n)\n apply clarsimp+\napply(erule fc_ti_typ_combine)\n  apply(clarsimp simp: fg_cons_def)\n apply clarsimp+\ndone\n\nlemma f_ind_array_tag_udpate [simp, rule_format]:\n  \"n \\<le> m \\<longrightarrow> m < CARD('b) \\<longrightarrow>\n      f_ind (\\<lambda>x. index x m) (lf_fd ` lf_set ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info) [])\"\napply(induct_tac n)\n apply clarsimp+\napply(erule f_ind_ti_typ_combine)\n apply clarsimp\napply simp\ndone\n\nlemma fa_fu_g_array_tag_udpate [simp, rule_format]:\n  \"n \\<le> m \\<longrightarrow> m < CARD('b) \\<longrightarrow>\n      fa_ind (lf_fd ` lf_set ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info) []) (\\<lambda>x f. update f m x)\"\napply(induct_tac n)\n apply clarsimp+\napply(erule fa_ind_ti_typ_combine)\napply clarsimp+\ndone\n\nlemma wf_fdp_array_tag [simp, rule_format]:\n  \"n \\<le> CARD('b) \\<longrightarrow>\n      wf_lf (lf_set ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info) [])\"\napply(induct_tac n)\n apply clarsimp+\napply(erule wf_lf_ti_typ_combine)\n      apply simp+\ndone\n\nlemma upd_local_update [simp]:\n  \"upd_local (\\<lambda>x f. update f n x)\"\napply(auto simp: upd_local_def)\napply(subst cart_eq)\napply clarsimp\napply(subst (asm) cart_eq)\napply(drule_tac x=i in spec)\napply clarsimp\napply(case_tac \"i=n\")\n apply simp+\ndone\n\nlemma fu_eq_mask_array_tag [simp, rule_format]:\n  \"n \\<le> CARD('b) \\<longrightarrow> (\\<forall>m. (\\<forall>k v. k < CARD('b) \\<longrightarrow>\n      index ((m v)::('a,'b) array) k = (if n \\<le> k then\n          index (undefined::('a::mem_type,'b::finite) array) k\n          else index v k)) \\<longrightarrow> fu_eq_mask (array_tag_n n) m)\"\napply(induct n)\n apply clarsimp\n apply(rule fu_eq_mask_empty_typ_info)\n apply clarsimp\n apply(subst cart_eq)\n apply simp\napply clarsimp\napply(rule fu_eq_mask_ti_typ_combine)\n     apply(drule_tac x=\"\\<lambda>v. update (m v) n (index undefined n)\" in spec)\n     apply(erule impE)\n      apply clarsimp\n      apply(drule_tac x=k in spec)\n      apply clarsimp\n      apply(case_tac \"k=n\")\n       apply simp\n      apply clarsimp\n     apply(subgoal_tac \"\\<forall>v bs. m (update v n bs) = update (m v) n bs\")\n      apply clarsimp+\n     apply(subst cart_eq)\n     apply clarsimp\n     apply(drule_tac x=i in spec)\n     apply clarsimp\n     apply(case_tac \"i=n\")\n      apply clarsimp+\n     apply(frule_tac x=\"update v n bs\" in spec)\n     apply(drule_tac x=\"v\" in spec)\n     apply clarsimp\n     apply(case_tac \"Suc n \\<le> i\")\n      apply clarsimp+\n    apply(clarsimp simp: fg_cons_def)\n   apply(clarsimp)\n  apply simp\ndone\n\nlemma size_td_array_tag [simp]:\n  \"size_td (((array_tag_n n)::('a,'b::finite) array typ_info)) =\n      n * size_of TYPE('a::c_type)\"\napply(induct_tac n)\n apply simp\napply simp\napply(simp add: size_td_lt_ti_typ_combine size_of_def)\ndone\n\nlemma align_td_array_tag [rule_format]:\n  \"0 < n \\<longrightarrow> align_td ((array_tag_n n)::('a,'b::finite) array typ_info) = (align_td (typ_info_t (TYPE('a::c_type))))\"\napply(induct_tac n)\n apply simp\napply(clarsimp simp: ti_typ_combine_def Let_def)\napply(case_tac \"n = 0\")\n apply(clarsimp simp: align_of_def max_def)+\ndone\n\nlemma align_field_array [simp]:\n  \"align_field ((array_tag_n n)::('a::mem_type,'b::finite) array typ_info)\"\napply(induct_tac n)\n apply simp\napply clarsimp\napply(erule align_field_ti_typ_combine)\napply simp\napply(rule dvd_mult)\napply(subgoal_tac \"align_of TYPE('a) dvd size_of TYPE('a)\")\n apply(simp add: align_of_def)\napply(rule align_size_of)\ndone\n\ninstance array :: (mem_type,finite) mem_type_sans_size\napply intro_classes\n     apply(simp_all add: typ_info_array array_tag_def size_of_def\n                         norm_bytes_def)\n\n apply clarsimp\n apply(rule fu_eq_mask)\n  apply(simp add: size_of_def)\n apply(rule fu_eq_mask_array_tag)\n    apply simp+\n\napply(clarsimp simp: align_of_def typ_info_array array_tag_def)\napply(subst align_td_array_tag)\n apply simp\napply(rule dvd_trans)\n apply(subgoal_tac \"align_of TYPE('a) dvd size_of TYPE('a)\")\n  apply(simp only: align_of_def)\n apply(rule align_size_of)\napply(simp add: size_of_def)\ndone\n\ndeclare atn_base [simp del]\ndeclare atn_rec [simp del]\n\nlemma size_of_array [simp]:\n  \"size_of TYPE(('a,'b::finite) array) = CARD('b) * size_of TYPE('a::c_type)\"\n  by (simp add: size_of_def typ_info_array array_tag_def)\n\nlemma size_td_array:\n  \"size_td (typ_info_t TYPE(('a,'b::finite) array)) = CARD('b) * size_of TYPE('a::c_type)\"\n  by (simp add: size_of_def typ_info_array array_tag_def)\n\nlemma align_td_array:\n  \"2^align_td (typ_info_t TYPE(('a,'b::finite) array)) = align_of TYPE('a::c_type)\"\napply(simp add: align_of_def typ_info_array array_tag_def)\napply(subst align_td_array_tag)\n apply simp+\ndone\n\nend\n", "meta": {"author": "z5146542", "repo": "TOR", "sha": "9a82d491288a6d013e0764f68e602a63e48f92cf", "save_path": "github-repos/isabelle/z5146542-TOR", "path": "github-repos/isabelle/z5146542-TOR/TOR-9a82d491288a6d013e0764f68e602a63e48f92cf/checker-verification/autocorres-1.4/c-parser/umm_heap/ArraysMemInstance.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.519521321952093, "lm_q2_score": 0.48438008427698437, "lm_q1q2_score": 0.2516457817108451}}
{"text": "(*  Title:      HOL/Auth/TLS.thy\n    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory\n    Copyright   1997  University of Cambridge\n\nInductive relation \"tls\" for the TLS (Transport Layer Security) protocol.\nThis protocol is essentially the same as SSL 3.0.\n\nAbstracted from \"The TLS Protocol, Version 1.0\" by Tim Dierks and Christopher\nAllen, Transport Layer Security Working Group, 21 May 1997,\nINTERNET-DRAFT draft-ietf-tls-protocol-03.txt.  Section numbers below refer\nto that memo.\n\nAn RSA cryptosystem is assumed, and X.509v3 certificates are abstracted down\nto the trivial form {A, publicKey(A)}privateKey(Server), where Server is a\nglobal signing authority.\n\nA is the client and B is the server, not to be confused with the constant\nServer, who is in charge of all public keys.\n\nThe model assumes that no fraudulent certificates are present, but it does\nassume that some private keys are to the spy.\n\nREMARK.  The event \"Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace>\" appears in ClientKeyExch,\nCertVerify, ClientFinished to record that A knows M.  It is a note from A to\nherself.  Nobody else can see it.  In ClientKeyExch, the Spy can substitute\nhis own certificate for A's, but he cannot replace A's note by one for himself.\n\nThe Note event avoids a weakness in the public-key model.  Each\nagent's state is recorded as the trace of messages.  When the true client (A)\ninvents PMS, he encrypts PMS with B's public key before sending it.  The model\ndoes not distinguish the original occurrence of such a message from a replay.\nIn the shared-key model, the ability to encrypt implies the ability to\ndecrypt, so the problem does not arise.\n\nProofs would be simpler if ClientKeyExch included A's name within\nCrypt KB (Nonce PMS).  As things stand, there is much overlap between proofs\nabout that message (which B receives) and the stronger event\nNotes A \\<lbrace>Agent B, Nonce PMS\\<rbrace>.\n*)\n\nsection\\<open>The TLS Protocol: Transport Layer Security\\<close>\n\ntheory TLS imports Public \"~~/src/HOL/Library/Nat_Bijection\" begin\n\ndefinition certificate :: \"[agent,key] => msg\" where\n    \"certificate A KA == Crypt (priSK Server) \\<lbrace>Agent A, Key KA\\<rbrace>\"\n\ntext\\<open>TLS apparently does not require separate keypairs for encryption and\nsignature.  Therefore, we formalize signature as encryption using the\nprivate encryption key.\\<close>\n\ndatatype role = ClientRole | ServerRole\n\nconsts\n  (*Pseudo-random function of Section 5*)\n  PRF  :: \"nat*nat*nat => nat\"\n\n  (*Client, server write keys are generated uniformly by function sessionK\n    to avoid duplicating their properties.  They are distinguished by a\n    tag (not a bool, to avoid the peculiarities of if-and-only-if).\n    Session keys implicitly include MAC secrets.*)\n  sessionK :: \"(nat*nat*nat) * role => key\"\n\nabbreviation\n  clientK :: \"nat*nat*nat => key\" where\n  \"clientK X == sessionK(X, ClientRole)\"\n\nabbreviation\n  serverK :: \"nat*nat*nat => key\" where\n  \"serverK X == sessionK(X, ServerRole)\"\n\n\nspecification (PRF)\n  inj_PRF: \"inj PRF\"\n  \\<comment>\\<open>the pseudo-random function is collision-free\\<close>\n   apply (rule exI [of _ \"%(x,y,z). prod_encode(x, prod_encode(y,z))\"])\n   apply (simp add: inj_on_def prod_encode_eq)\n   done\n\nspecification (sessionK)\n  inj_sessionK: \"inj sessionK\"\n  \\<comment>\\<open>sessionK is collision-free; also, no clientK clashes with any serverK.\\<close>\n   apply (rule exI [of _ \n         \"%((x,y,z), r). prod_encode(case_role 0 1 r, \n                           prod_encode(x, prod_encode(y,z)))\"])\n   apply (simp add: inj_on_def prod_encode_eq split: role.split) \n   done\n\naxiomatization where\n  \\<comment>\\<open>sessionK makes symmetric keys\\<close>\n  isSym_sessionK: \"sessionK nonces \\<in> symKeys\" and\n\n  \\<comment>\\<open>sessionK never clashes with a long-term symmetric key  \n     (they don't exist in TLS anyway)\\<close>\n  sessionK_neq_shrK [iff]: \"sessionK nonces \\<noteq> shrK A\"\n\n\ninductive_set tls :: \"event list set\"\n  where\n   Nil:  \\<comment>\\<open>The initial, empty trace\\<close>\n         \"[] \\<in> tls\"\n\n | Fake: \\<comment>\\<open>The Spy may say anything he can say.  The sender field is correct,\n          but agents don't use that information.\\<close>\n         \"[| evsf \\<in> tls;  X \\<in> synth (analz (spies evsf)) |]\n          ==> Says Spy B X # evsf \\<in> tls\"\n\n | SpyKeys: \\<comment>\\<open>The spy may apply @{term PRF} and @{term sessionK}\n                to available nonces\\<close>\n         \"[| evsSK \\<in> tls;\n             {Nonce NA, Nonce NB, Nonce M} <= analz (spies evsSK) |]\n          ==> Notes Spy \\<lbrace> Nonce (PRF(M,NA,NB)),\n                           Key (sessionK((NA,NB,M),role))\\<rbrace> # evsSK \\<in> tls\"\n\n | ClientHello:\n         \\<comment>\\<open>(7.4.1.2)\n           PA represents \\<open>CLIENT_VERSION\\<close>, \\<open>CIPHER_SUITES\\<close> and \\<open>COMPRESSION_METHODS\\<close>.\n           It is uninterpreted but will be confirmed in the FINISHED messages.\n           NA is CLIENT RANDOM, while SID is \\<open>SESSION_ID\\<close>.\n           UNIX TIME is omitted because the protocol doesn't use it.\n           May assume @{term \"NA \\<notin> range PRF\"} because CLIENT RANDOM is \n           28 bytes while MASTER SECRET is 48 bytes\\<close>\n         \"[| evsCH \\<in> tls;  Nonce NA \\<notin> used evsCH;  NA \\<notin> range PRF |]\n          ==> Says A B \\<lbrace>Agent A, Nonce NA, Number SID, Number PA\\<rbrace>\n                # evsCH  \\<in>  tls\"\n\n | ServerHello:\n         \\<comment>\\<open>7.4.1.3 of the TLS Internet-Draft\n           PB represents \\<open>CLIENT_VERSION\\<close>, \\<open>CIPHER_SUITE\\<close> and \\<open>COMPRESSION_METHOD\\<close>.\n           SERVER CERTIFICATE (7.4.2) is always present.\n           \\<open>CERTIFICATE_REQUEST\\<close> (7.4.4) is implied.\\<close>\n         \"[| evsSH \\<in> tls;  Nonce NB \\<notin> used evsSH;  NB \\<notin> range PRF;\n             Says A' B \\<lbrace>Agent A, Nonce NA, Number SID, Number PA\\<rbrace>\n               \\<in> set evsSH |]\n          ==> Says B A \\<lbrace>Nonce NB, Number SID, Number PB\\<rbrace> # evsSH  \\<in>  tls\"\n\n | Certificate:\n         \\<comment>\\<open>SERVER (7.4.2) or CLIENT (7.4.6) CERTIFICATE.\\<close>\n         \"evsC \\<in> tls ==> Says B A (certificate B (pubK B)) # evsC  \\<in>  tls\"\n\n | ClientKeyExch:\n         \\<comment>\\<open>CLIENT KEY EXCHANGE (7.4.7).\n           The client, A, chooses PMS, the PREMASTER SECRET.\n           She encrypts PMS using the supplied KB, which ought to be pubK B.\n           We assume @{term \"PMS \\<notin> range PRF\"} because a clash betweem the PMS\n           and another MASTER SECRET is highly unlikely (even though\n           both items have the same length, 48 bytes).\n           The Note event records in the trace that she knows PMS\n               (see REMARK at top).\\<close>\n         \"[| evsCX \\<in> tls;  Nonce PMS \\<notin> used evsCX;  PMS \\<notin> range PRF;\n             Says B' A (certificate B KB) \\<in> set evsCX |]\n          ==> Says A B (Crypt KB (Nonce PMS))\n              # Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace>\n              # evsCX  \\<in>  tls\"\n\n | CertVerify:\n        \\<comment>\\<open>The optional Certificate Verify (7.4.8) message contains the\n          specific components listed in the security analysis, F.1.1.2.\n          It adds the pre-master-secret, which is also essential!\n          Checking the signature, which is the only use of A's certificate,\n          assures B of A's presence\\<close>\n         \"[| evsCV \\<in> tls;\n             Says B' A \\<lbrace>Nonce NB, Number SID, Number PB\\<rbrace> \\<in> set evsCV;\n             Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evsCV |]\n          ==> Says A B (Crypt (priK A) (Hash\\<lbrace>Nonce NB, Agent B, Nonce PMS\\<rbrace>))\n              # evsCV  \\<in>  tls\"\n\n        \\<comment>\\<open>Finally come the FINISHED messages (7.4.8), confirming PA and PB\n          among other things.  The master-secret is PRF(PMS,NA,NB).\n          Either party may send its message first.\\<close>\n\n | ClientFinished:\n        \\<comment>\\<open>The occurrence of \\<open>Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace>\\<close> stops the\n          rule's applying when the Spy has satisfied the \\<open>Says A B\\<close> by\n          repaying messages sent by the true client; in that case, the\n          Spy does not know PMS and could not send ClientFinished.  One\n          could simply put @{term \"A\\<noteq>Spy\"} into the rule, but one should not\n          expect the spy to be well-behaved.\\<close>\n         \"[| evsCF \\<in> tls;\n             Says A  B \\<lbrace>Agent A, Nonce NA, Number SID, Number PA\\<rbrace>\n               \\<in> set evsCF;\n             Says B' A \\<lbrace>Nonce NB, Number SID, Number PB\\<rbrace> \\<in> set evsCF;\n             Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evsCF;\n             M = PRF(PMS,NA,NB) |]\n          ==> Says A B (Crypt (clientK(NA,NB,M))\n                        (Hash\\<lbrace>Number SID, Nonce M,\n                               Nonce NA, Number PA, Agent A,\n                               Nonce NB, Number PB, Agent B\\<rbrace>))\n              # evsCF  \\<in>  tls\"\n\n | ServerFinished:\n        \\<comment>\\<open>Keeping A' and A'' distinct means B cannot even check that the\n          two messages originate from the same source.\\<close>\n         \"[| evsSF \\<in> tls;\n             Says A' B  \\<lbrace>Agent A, Nonce NA, Number SID, Number PA\\<rbrace>\n               \\<in> set evsSF;\n             Says B  A  \\<lbrace>Nonce NB, Number SID, Number PB\\<rbrace> \\<in> set evsSF;\n             Says A'' B (Crypt (pubK B) (Nonce PMS)) \\<in> set evsSF;\n             M = PRF(PMS,NA,NB) |]\n          ==> Says B A (Crypt (serverK(NA,NB,M))\n                        (Hash\\<lbrace>Number SID, Nonce M,\n                               Nonce NA, Number PA, Agent A,\n                               Nonce NB, Number PB, Agent B\\<rbrace>))\n              # evsSF  \\<in>  tls\"\n\n | ClientAccepts:\n        \\<comment>\\<open>Having transmitted ClientFinished and received an identical\n          message encrypted with serverK, the client stores the parameters\n          needed to resume this session.  The \"Notes A ...\" premise is\n          used to prove \\<open>Notes_master_imp_Crypt_PMS\\<close>.\\<close>\n         \"[| evsCA \\<in> tls;\n             Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evsCA;\n             M = PRF(PMS,NA,NB);\n             X = Hash\\<lbrace>Number SID, Nonce M,\n                       Nonce NA, Number PA, Agent A,\n                       Nonce NB, Number PB, Agent B\\<rbrace>;\n             Says A  B (Crypt (clientK(NA,NB,M)) X) \\<in> set evsCA;\n             Says B' A (Crypt (serverK(NA,NB,M)) X) \\<in> set evsCA |]\n          ==>\n             Notes A \\<lbrace>Number SID, Agent A, Agent B, Nonce M\\<rbrace> # evsCA  \\<in>  tls\"\n\n | ServerAccepts:\n        \\<comment>\\<open>Having transmitted ServerFinished and received an identical\n          message encrypted with clientK, the server stores the parameters\n          needed to resume this session.  The \"Says A'' B ...\" premise is\n          used to prove \\<open>Notes_master_imp_Crypt_PMS\\<close>.\\<close>\n         \"[| evsSA \\<in> tls;\n             A \\<noteq> B;\n             Says A'' B (Crypt (pubK B) (Nonce PMS)) \\<in> set evsSA;\n             M = PRF(PMS,NA,NB);\n             X = Hash\\<lbrace>Number SID, Nonce M,\n                       Nonce NA, Number PA, Agent A,\n                       Nonce NB, Number PB, Agent B\\<rbrace>;\n             Says B  A (Crypt (serverK(NA,NB,M)) X) \\<in> set evsSA;\n             Says A' B (Crypt (clientK(NA,NB,M)) X) \\<in> set evsSA |]\n          ==>\n             Notes B \\<lbrace>Number SID, Agent A, Agent B, Nonce M\\<rbrace> # evsSA  \\<in>  tls\"\n\n | ClientResume:\n         \\<comment>\\<open>If A recalls the \\<open>SESSION_ID\\<close>, then she sends a FINISHED\n             message using the new nonces and stored MASTER SECRET.\\<close>\n         \"[| evsCR \\<in> tls;\n             Says A  B \\<lbrace>Agent A, Nonce NA, Number SID, Number PA\\<rbrace>: set evsCR;\n             Says B' A \\<lbrace>Nonce NB, Number SID, Number PB\\<rbrace> \\<in> set evsCR;\n             Notes A \\<lbrace>Number SID, Agent A, Agent B, Nonce M\\<rbrace> \\<in> set evsCR |]\n          ==> Says A B (Crypt (clientK(NA,NB,M))\n                        (Hash\\<lbrace>Number SID, Nonce M,\n                               Nonce NA, Number PA, Agent A,\n                               Nonce NB, Number PB, Agent B\\<rbrace>))\n              # evsCR  \\<in>  tls\"\n\n | ServerResume:\n         \\<comment>\\<open>Resumption (7.3):  If B finds the \\<open>SESSION_ID\\<close> then he can \n             send a FINISHED message using the recovered MASTER SECRET\\<close>\n         \"[| evsSR \\<in> tls;\n             Says A' B \\<lbrace>Agent A, Nonce NA, Number SID, Number PA\\<rbrace>: set evsSR;\n             Says B  A \\<lbrace>Nonce NB, Number SID, Number PB\\<rbrace> \\<in> set evsSR;\n             Notes B \\<lbrace>Number SID, Agent A, Agent B, Nonce M\\<rbrace> \\<in> set evsSR |]\n          ==> Says B A (Crypt (serverK(NA,NB,M))\n                        (Hash\\<lbrace>Number SID, Nonce M,\n                               Nonce NA, Number PA, Agent A,\n                               Nonce NB, Number PB, Agent B\\<rbrace>)) # evsSR\n                \\<in>  tls\"\n\n | Oops:\n         \\<comment>\\<open>The most plausible compromise is of an old session key.  Losing\n           the MASTER SECRET or PREMASTER SECRET is more serious but\n           rather unlikely.  The assumption @{term \"A\\<noteq>Spy\"} is essential: \n           otherwise the Spy could learn session keys merely by \n           replaying messages!\\<close>\n         \"[| evso \\<in> tls;  A \\<noteq> Spy;\n             Says A B (Crypt (sessionK((NA,NB,M),role)) X) \\<in> set evso |]\n          ==> Says A Spy (Key (sessionK((NA,NB,M),role))) # evso  \\<in>  tls\"\n\n(*\nProtocol goals:\n* M, serverK(NA,NB,M) and clientK(NA,NB,M) will be known only to the two\n     parties (though A is not necessarily authenticated).\n\n* B upon receiving CertVerify knows that A is present (But this\n    message is optional!)\n\n* A upon receiving ServerFinished knows that B is present\n\n* Each party who has received a FINISHED message can trust that the other\n  party agrees on all message components, including PA and PB (thus foiling\n  rollback attacks).\n*)\n\ndeclare Says_imp_knows_Spy [THEN analz.Inj, dest]\ndeclare parts.Body  [dest]\ndeclare analz_into_parts [dest]\ndeclare Fake_parts_insert_in_Un  [dest]\n\n\ntext\\<open>Automatically unfold the definition of \"certificate\"\\<close>\ndeclare certificate_def [simp]\n\ntext\\<open>Injectiveness of key-generating functions\\<close>\ndeclare inj_PRF [THEN inj_eq, iff]\ndeclare inj_sessionK [THEN inj_eq, iff]\ndeclare isSym_sessionK [simp]\n\n\n(*** clientK and serverK make symmetric keys; no clashes with pubK or priK ***)\n\nlemma pubK_neq_sessionK [iff]: \"publicKey b A \\<noteq> sessionK arg\"\nby (simp add: symKeys_neq_imp_neq)\n\ndeclare pubK_neq_sessionK [THEN not_sym, iff]\n\nlemma priK_neq_sessionK [iff]: \"invKey (publicKey b A) \\<noteq> sessionK arg\"\nby (simp add: symKeys_neq_imp_neq)\n\ndeclare priK_neq_sessionK [THEN not_sym, iff]\n\nlemmas keys_distinct = pubK_neq_sessionK priK_neq_sessionK\n\n\nsubsection\\<open>Protocol Proofs\\<close>\n\ntext\\<open>Possibility properties state that some traces run the protocol to the\nend.  Four paths and 12 rules are considered.\\<close>\n\n\n(** These proofs assume that the Nonce_supply nonces\n        (which have the form  @ N. Nonce N \\<notin> used evs)\n    lie outside the range of PRF.  It seems reasonable, but as it is needed\n    only for the possibility theorems, it is not taken as an axiom.\n**)\n\n\ntext\\<open>Possibility property ending with ClientAccepts.\\<close>\nlemma \"[| \\<forall>evs. (@ N. Nonce N \\<notin> used evs) \\<notin> range PRF;  A \\<noteq> B |]\n      ==> \\<exists>SID M. \\<exists>evs \\<in> tls.\n            Notes A \\<lbrace>Number SID, Agent A, Agent B, Nonce M\\<rbrace> \\<in> set evs\"\napply (intro exI bexI)\napply (rule_tac [2] tls.Nil\n                    [THEN tls.ClientHello, THEN tls.ServerHello,\n                     THEN tls.Certificate, THEN tls.ClientKeyExch,\n                     THEN tls.ClientFinished, THEN tls.ServerFinished,\n                     THEN tls.ClientAccepts], possibility, blast+)\ndone\n\n\ntext\\<open>And one for ServerAccepts.  Either FINISHED message may come first.\\<close>\nlemma \"[| \\<forall>evs. (@ N. Nonce N \\<notin> used evs) \\<notin> range PRF; A \\<noteq> B |]\n      ==> \\<exists>SID NA PA NB PB M. \\<exists>evs \\<in> tls.\n           Notes B \\<lbrace>Number SID, Agent A, Agent B, Nonce M\\<rbrace> \\<in> set evs\"\napply (intro exI bexI)\napply (rule_tac [2] tls.Nil\n                    [THEN tls.ClientHello, THEN tls.ServerHello,\n                     THEN tls.Certificate, THEN tls.ClientKeyExch,\n                     THEN tls.ServerFinished, THEN tls.ClientFinished, \n                     THEN tls.ServerAccepts], possibility, blast+)\ndone\n\n\ntext\\<open>Another one, for CertVerify (which is optional)\\<close>\nlemma \"[| \\<forall>evs. (@ N. Nonce N \\<notin> used evs) \\<notin> range PRF;  A \\<noteq> B |]\n       ==> \\<exists>NB PMS. \\<exists>evs \\<in> tls.\n              Says A B (Crypt (priK A) (Hash\\<lbrace>Nonce NB, Agent B, Nonce PMS\\<rbrace>)) \n                \\<in> set evs\"\napply (intro exI bexI)\napply (rule_tac [2] tls.Nil\n                    [THEN tls.ClientHello, THEN tls.ServerHello,\n                     THEN tls.Certificate, THEN tls.ClientKeyExch,\n                     THEN tls.CertVerify], possibility, blast+)\ndone\n\n\ntext\\<open>Another one, for session resumption (both ServerResume and ClientResume).\n  NO tls.Nil here: we refer to a previous session, not the empty trace.\\<close>\nlemma \"[| evs0 \\<in> tls;\n          Notes A \\<lbrace>Number SID, Agent A, Agent B, Nonce M\\<rbrace> \\<in> set evs0;\n          Notes B \\<lbrace>Number SID, Agent A, Agent B, Nonce M\\<rbrace> \\<in> set evs0;\n          \\<forall>evs. (@ N. Nonce N \\<notin> used evs) \\<notin> range PRF;\n          A \\<noteq> B |]\n      ==> \\<exists>NA PA NB PB X. \\<exists>evs \\<in> tls.\n                X = Hash\\<lbrace>Number SID, Nonce M,\n                          Nonce NA, Number PA, Agent A,\n                          Nonce NB, Number PB, Agent B\\<rbrace>  &\n                Says A B (Crypt (clientK(NA,NB,M)) X) \\<in> set evs  &\n                Says B A (Crypt (serverK(NA,NB,M)) X) \\<in> set evs\"\napply (intro exI bexI)\napply (rule_tac [2] tls.ClientHello\n                    [THEN tls.ServerHello,\n                     THEN tls.ServerResume, THEN tls.ClientResume], possibility, blast+)\ndone\n\n\nsubsection\\<open>Inductive proofs about tls\\<close>\n\n\n(** Theorems of the form X \\<notin> parts (spies evs) imply that NOBODY\n    sends messages containing X! **)\n\ntext\\<open>Spy never sees a good agent's private key!\\<close>\nlemma Spy_see_priK [simp]:\n     \"evs \\<in> tls ==> (Key (privateKey b A) \\<in> parts (spies evs)) = (A \\<in> bad)\"\nby (erule tls.induct, force, simp_all, blast)\n\nlemma Spy_analz_priK [simp]:\n     \"evs \\<in> tls ==> (Key (privateKey b A) \\<in> analz (spies evs)) = (A \\<in> bad)\"\nby auto\n\nlemma Spy_see_priK_D [dest!]:\n    \"[|Key (privateKey b A) \\<in> parts (knows Spy evs);  evs \\<in> tls|] ==> A \\<in> bad\"\nby (blast dest: Spy_see_priK)\n\n\ntext\\<open>This lemma says that no false certificates exist.  One might extend the\n  model to include bogus certificates for the agents, but there seems\n  little point in doing so: the loss of their private keys is a worse\n  breach of security.\\<close>\nlemma certificate_valid:\n    \"[| certificate B KB \\<in> parts (spies evs);  evs \\<in> tls |] ==> KB = pubK B\"\napply (erule rev_mp)\napply (erule tls.induct, force, simp_all, blast) \ndone\n\nlemmas CX_KB_is_pubKB = Says_imp_spies [THEN parts.Inj, THEN certificate_valid]\n\n\nsubsubsection\\<open>Properties of items found in Notes\\<close>\n\nlemma Notes_Crypt_parts_spies:\n     \"[| Notes A \\<lbrace>Agent B, X\\<rbrace> \\<in> set evs;  evs \\<in> tls |]\n      ==> Crypt (pubK B) X \\<in> parts (spies evs)\"\napply (erule rev_mp)\napply (erule tls.induct, \n       frule_tac [7] CX_KB_is_pubKB, force, simp_all)\napply (blast intro: parts_insertI)\ndone\n\ntext\\<open>C may be either A or B\\<close>\nlemma Notes_master_imp_Crypt_PMS:\n     \"[| Notes C \\<lbrace>s, Agent A, Agent B, Nonce(PRF(PMS,NA,NB))\\<rbrace> \\<in> set evs;\n         evs \\<in> tls |]\n      ==> Crypt (pubK B) (Nonce PMS) \\<in> parts (spies evs)\"\napply (erule rev_mp)\napply (erule tls.induct, force, simp_all)\ntxt\\<open>Fake\\<close>\napply (blast intro: parts_insertI)\ntxt\\<open>Client, Server Accept\\<close>\napply (blast dest!: Notes_Crypt_parts_spies)+\ndone\n\ntext\\<open>Compared with the theorem above, both premise and conclusion are stronger\\<close>\nlemma Notes_master_imp_Notes_PMS:\n     \"[| Notes A \\<lbrace>s, Agent A, Agent B, Nonce(PRF(PMS,NA,NB))\\<rbrace> \\<in> set evs;\n         evs \\<in> tls |]\n      ==> Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs\"\napply (erule rev_mp)\napply (erule tls.induct, force, simp_all)\ntxt\\<open>ServerAccepts\\<close>\napply blast\ndone\n\n\nsubsubsection\\<open>Protocol goal: if B receives CertVerify, then A sent it\\<close>\n\ntext\\<open>B can check A's signature if he has received A's certificate.\\<close>\nlemma TrustCertVerify_lemma:\n     \"[| X \\<in> parts (spies evs);\n         X = Crypt (priK A) (Hash\\<lbrace>nb, Agent B, pms\\<rbrace>);\n         evs \\<in> tls;  A \\<notin> bad |]\n      ==> Says A B X \\<in> set evs\"\napply (erule rev_mp, erule ssubst)\napply (erule tls.induct, force, simp_all, blast)\ndone\n\ntext\\<open>Final version: B checks X using the distributed KA instead of priK A\\<close>\nlemma TrustCertVerify:\n     \"[| X \\<in> parts (spies evs);\n         X = Crypt (invKey KA) (Hash\\<lbrace>nb, Agent B, pms\\<rbrace>);\n         certificate A KA \\<in> parts (spies evs);\n         evs \\<in> tls;  A \\<notin> bad |]\n      ==> Says A B X \\<in> set evs\"\nby (blast dest!: certificate_valid intro!: TrustCertVerify_lemma)\n\n\ntext\\<open>If CertVerify is present then A has chosen PMS.\\<close>\nlemma UseCertVerify_lemma:\n     \"[| Crypt (priK A) (Hash\\<lbrace>nb, Agent B, Nonce PMS\\<rbrace>) \\<in> parts (spies evs);\n         evs \\<in> tls;  A \\<notin> bad |]\n      ==> Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs\"\napply (erule rev_mp)\napply (erule tls.induct, force, simp_all, blast)\ndone\n\ntext\\<open>Final version using the distributed KA instead of priK A\\<close>\nlemma UseCertVerify:\n     \"[| Crypt (invKey KA) (Hash\\<lbrace>nb, Agent B, Nonce PMS\\<rbrace>)\n           \\<in> parts (spies evs);\n         certificate A KA \\<in> parts (spies evs);\n         evs \\<in> tls;  A \\<notin> bad |]\n      ==> Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs\"\nby (blast dest!: certificate_valid intro!: UseCertVerify_lemma)\n\n\nlemma no_Notes_A_PRF [simp]:\n     \"evs \\<in> tls ==> Notes A \\<lbrace>Agent B, Nonce (PRF x)\\<rbrace> \\<notin> set evs\"\napply (erule tls.induct, force, simp_all)\ntxt\\<open>ClientKeyExch: PMS is assumed to differ from any PRF.\\<close>\napply blast\ndone\n\n\nlemma MS_imp_PMS [dest!]:\n     \"[| Nonce (PRF (PMS,NA,NB)) \\<in> parts (spies evs);  evs \\<in> tls |]\n      ==> Nonce PMS \\<in> parts (spies evs)\"\napply (erule rev_mp)\napply (erule tls.induct, force, simp_all)\ntxt\\<open>Fake\\<close>\napply (blast intro: parts_insertI)\ntxt\\<open>Easy, e.g. by freshness\\<close>\napply (blast dest: Notes_Crypt_parts_spies)+\ndone\n\n\n\n\nsubsubsection\\<open>Unicity results for PMS, the pre-master-secret\\<close>\n\ntext\\<open>PMS determines B.\\<close>\nlemma Crypt_unique_PMS:\n     \"[| Crypt(pubK B)  (Nonce PMS) \\<in> parts (spies evs);\n         Crypt(pubK B') (Nonce PMS) \\<in> parts (spies evs);\n         Nonce PMS \\<notin> analz (spies evs);\n         evs \\<in> tls |]\n      ==> B=B'\"\napply (erule rev_mp, erule rev_mp, erule rev_mp)\napply (erule tls.induct, analz_mono_contra, force, simp_all (no_asm_simp))\ntxt\\<open>Fake, ClientKeyExch\\<close>\napply blast+\ndone\n\n\n(** It is frustrating that we need two versions of the unicity results.\n    But Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> determines both A and B.  Sometimes\n    we have only the weaker assertion Crypt(pubK B) (Nonce PMS), which\n    determines B alone, and only if PMS is secret.\n**)\n\ntext\\<open>In A's internal Note, PMS determines A and B.\\<close>\nlemma Notes_unique_PMS:\n     \"[| Notes A  \\<lbrace>Agent B,  Nonce PMS\\<rbrace> \\<in> set evs;\n         Notes A' \\<lbrace>Agent B', Nonce PMS\\<rbrace> \\<in> set evs;\n         evs \\<in> tls |]\n      ==> A=A' & B=B'\"\napply (erule rev_mp, erule rev_mp)\napply (erule tls.induct, force, simp_all)\ntxt\\<open>ClientKeyExch\\<close>\napply (blast dest!: Notes_Crypt_parts_spies)\ndone\n\n\nsubsection\\<open>Secrecy Theorems\\<close>\n\ntext\\<open>Key compromise lemma needed to prove @{term analz_image_keys}.\n  No collection of keys can help the spy get new private keys.\\<close>\nlemma analz_image_priK [rule_format]:\n     \"evs \\<in> tls\n      ==> \\<forall>KK. (Key(priK B) \\<in> analz (Key`KK Un (spies evs))) =\n          (priK B \\<in> KK | B \\<in> bad)\"\napply (erule tls.induct)\napply (simp_all (no_asm_simp)\n                del: image_insert\n                add: image_Un [THEN sym]\n                     insert_Key_image Un_assoc [THEN sym])\ntxt\\<open>Fake\\<close>\napply spy_analz\ndone\n\n\ntext\\<open>slightly speeds up the big simplification below\\<close>\nlemma range_sessionkeys_not_priK:\n     \"KK <= range sessionK ==> priK B \\<notin> KK\"\nby blast\n\n\ntext\\<open>Lemma for the trivial direction of the if-and-only-if\\<close>\nlemma analz_image_keys_lemma:\n     \"(X \\<in> analz (G Un H)) --> (X \\<in> analz H)  ==>\n      (X \\<in> analz (G Un H))  =  (X \\<in> analz H)\"\nby (blast intro: analz_mono [THEN subsetD])\n\n(** Strangely, the following version doesn't work:\n\\<forall>Z. (Nonce N \\<in> analz (Key`(sessionK`Z) Un (spies evs))) =\n    (Nonce N \\<in> analz (spies evs))\"\n**)\n\nlemma analz_image_keys [rule_format]:\n     \"evs \\<in> tls ==>\n      \\<forall>KK. KK <= range sessionK -->\n              (Nonce N \\<in> analz (Key`KK Un (spies evs))) =\n              (Nonce N \\<in> analz (spies evs))\"\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (safe del: iffI)\napply (safe del: impI iffI intro!: analz_image_keys_lemma)\napply (simp_all (no_asm_simp)               (*faster*)\n                del: image_insert imp_disjL (*reduces blow-up*)\n                add: image_Un [THEN sym]  Un_assoc [THEN sym]\n                     insert_Key_singleton\n                     range_sessionkeys_not_priK analz_image_priK)\napply (simp_all add: insert_absorb)\ntxt\\<open>Fake\\<close>\napply spy_analz\ndone\n\ntext\\<open>Knowing some session keys is no help in getting new nonces\\<close>\nlemma analz_insert_key [simp]:\n     \"evs \\<in> tls ==>\n      (Nonce N \\<in> analz (insert (Key (sessionK z)) (spies evs))) =\n      (Nonce N \\<in> analz (spies evs))\"\nby (simp del: image_insert\n         add: insert_Key_singleton analz_image_keys)\n\n\nsubsubsection\\<open>Protocol goal: serverK(Na,Nb,M) and clientK(Na,Nb,M) remain secure\\<close>\n\n(** Some lemmas about session keys, comprising clientK and serverK **)\n\n\ntext\\<open>Lemma: session keys are never used if PMS is fresh.\n  Nonces don't have to agree, allowing session resumption.\n  Converse doesn't hold; revealing PMS doesn't force the keys to be sent.\n  THEY ARE NOT SUITABLE AS SAFE ELIM RULES.\\<close>\nlemma PMS_lemma:\n     \"[| Nonce PMS \\<notin> parts (spies evs);\n         K = sessionK((Na, Nb, PRF(PMS,NA,NB)), role);\n         evs \\<in> tls |]\n   ==> Key K \\<notin> parts (spies evs) & (\\<forall>Y. Crypt K Y \\<notin> parts (spies evs))\"\napply (erule rev_mp, erule ssubst)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB) \napply (force, simp_all (no_asm_simp))\ntxt\\<open>Fake\\<close>\napply (blast intro: parts_insertI)\ntxt\\<open>SpyKeys\\<close>\napply blast\ntxt\\<open>Many others\\<close>\napply (force dest!: Notes_Crypt_parts_spies Notes_master_imp_Crypt_PMS)+\ndone\n\nlemma PMS_sessionK_not_spied:\n     \"[| Key (sessionK((Na, Nb, PRF(PMS,NA,NB)), role)) \\<in> parts (spies evs);\n         evs \\<in> tls |]\n      ==> Nonce PMS \\<in> parts (spies evs)\"\nby (blast dest: PMS_lemma)\n\nlemma PMS_Crypt_sessionK_not_spied:\n     \"[| Crypt (sessionK((Na, Nb, PRF(PMS,NA,NB)), role)) Y\n           \\<in> parts (spies evs);  evs \\<in> tls |]\n      ==> Nonce PMS \\<in> parts (spies evs)\"\nby (blast dest: PMS_lemma)\n\ntext\\<open>Write keys are never sent if M (MASTER SECRET) is secure.\n  Converse fails; betraying M doesn't force the keys to be sent!\n  The strong Oops condition can be weakened later by unicity reasoning,\n  with some effort.\n  NO LONGER USED: see \\<open>clientK_not_spied\\<close> and \\<open>serverK_not_spied\\<close>\\<close>\nlemma sessionK_not_spied:\n     \"[| \\<forall>A. Says A Spy (Key (sessionK((NA,NB,M),role))) \\<notin> set evs;\n         Nonce M \\<notin> analz (spies evs);  evs \\<in> tls |]\n      ==> Key (sessionK((NA,NB,M),role)) \\<notin> parts (spies evs)\"\napply (erule rev_mp, erule rev_mp)\napply (erule tls.induct, analz_mono_contra)\napply (force, simp_all (no_asm_simp))\ntxt\\<open>Fake, SpyKeys\\<close>\napply blast+\ndone\n\n\ntext\\<open>If A sends ClientKeyExch to an honest B, then the PMS will stay secret.\\<close>\nlemma Spy_not_see_PMS:\n     \"[| Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs;\n         evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad |]\n      ==> Nonce PMS \\<notin> analz (spies evs)\"\napply (erule rev_mp, erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp))\ntxt\\<open>Fake\\<close>\napply spy_analz\ntxt\\<open>SpyKeys\\<close>\napply force\napply (simp_all add: insert_absorb) \ntxt\\<open>ClientHello, ServerHello, ClientKeyExch: mostly freshness reasoning\\<close>\napply (blast dest: Notes_Crypt_parts_spies)\napply (blast dest: Notes_Crypt_parts_spies)\napply (blast dest: Notes_Crypt_parts_spies)\ntxt\\<open>ClientAccepts and ServerAccepts: because @{term \"PMS \\<notin> range PRF\"}\\<close>\napply force+\ndone\n\n\ntext\\<open>If A sends ClientKeyExch to an honest B, then the MASTER SECRET\n  will stay secret.\\<close>\nlemma Spy_not_see_MS:\n     \"[| Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs;\n         evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad |]\n      ==> Nonce (PRF(PMS,NA,NB)) \\<notin> analz (spies evs)\"\napply (erule rev_mp, erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp))\ntxt\\<open>Fake\\<close>\napply spy_analz\ntxt\\<open>SpyKeys: by secrecy of the PMS, Spy cannot make the MS\\<close>\napply (blast dest!: Spy_not_see_PMS)\napply (simp_all add: insert_absorb)\ntxt\\<open>ClientAccepts and ServerAccepts: because PMS was already visible;\n  others, freshness etc.\\<close>\napply (blast dest: Notes_Crypt_parts_spies Spy_not_see_PMS \n                   Notes_imp_knows_Spy [THEN analz.Inj])+\ndone\n\n\n\nsubsubsection\\<open>Weakening the Oops conditions for leakage of clientK\\<close>\n\ntext\\<open>If A created PMS then nobody else (except the Spy in replays)\n  would send a message using a clientK generated from that PMS.\\<close>\nlemma Says_clientK_unique:\n     \"[| Says A' B' (Crypt (clientK(Na,Nb,PRF(PMS,NA,NB))) Y) \\<in> set evs;\n         Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs;\n         evs \\<in> tls;  A' \\<noteq> Spy |]\n      ==> A = A'\"\napply (erule rev_mp, erule rev_mp)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all)\ntxt\\<open>ClientKeyExch\\<close>\napply (blast dest!: PMS_Crypt_sessionK_not_spied)\ntxt\\<open>ClientFinished, ClientResume: by unicity of PMS\\<close>\napply (blast dest!: Notes_master_imp_Notes_PMS \n             intro: Notes_unique_PMS [THEN conjunct1])+\ndone\n\n\ntext\\<open>If A created PMS and has not leaked her clientK to the Spy,\n  then it is completely secure: not even in parts!\\<close>\nlemma clientK_not_spied:\n     \"[| Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs;\n         Says A Spy (Key (clientK(Na,Nb,PRF(PMS,NA,NB)))) \\<notin> set evs;\n         A \\<notin> bad;  B \\<notin> bad;\n         evs \\<in> tls |]\n      ==> Key (clientK(Na,Nb,PRF(PMS,NA,NB))) \\<notin> parts (spies evs)\"\napply (erule rev_mp, erule rev_mp)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp))\ntxt\\<open>ClientKeyExch\\<close>\napply blast \ntxt\\<open>SpyKeys\\<close>\napply (blast dest!: Spy_not_see_MS)\ntxt\\<open>ClientKeyExch\\<close>\napply (blast dest!: PMS_sessionK_not_spied)\ntxt\\<open>Oops\\<close>\napply (blast intro: Says_clientK_unique)\ndone\n\n\nsubsubsection\\<open>Weakening the Oops conditions for leakage of serverK\\<close>\n\ntext\\<open>If A created PMS for B, then nobody other than B or the Spy would\n  send a message using a serverK generated from that PMS.\\<close>\nlemma Says_serverK_unique:\n     \"[| Says B' A' (Crypt (serverK(Na,Nb,PRF(PMS,NA,NB))) Y) \\<in> set evs;\n         Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs;\n         evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad;  B' \\<noteq> Spy |]\n      ==> B = B'\"\napply (erule rev_mp, erule rev_mp)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all)\ntxt\\<open>ClientKeyExch\\<close>\napply (blast dest!: PMS_Crypt_sessionK_not_spied)\ntxt\\<open>ServerResume, ServerFinished: by unicity of PMS\\<close>\napply (blast dest!: Notes_master_imp_Crypt_PMS \n             dest: Spy_not_see_PMS Notes_Crypt_parts_spies Crypt_unique_PMS)+\ndone\n\n\ntext\\<open>If A created PMS for B, and B has not leaked his serverK to the Spy,\n  then it is completely secure: not even in parts!\\<close>\nlemma serverK_not_spied:\n     \"[| Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs;\n         Says B Spy (Key(serverK(Na,Nb,PRF(PMS,NA,NB)))) \\<notin> set evs;\n         A \\<notin> bad;  B \\<notin> bad;  evs \\<in> tls |]\n      ==> Key (serverK(Na,Nb,PRF(PMS,NA,NB))) \\<notin> parts (spies evs)\"\napply (erule rev_mp, erule rev_mp)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp))\ntxt\\<open>Fake\\<close>\napply blast \ntxt\\<open>SpyKeys\\<close>\napply (blast dest!: Spy_not_see_MS)\ntxt\\<open>ClientKeyExch\\<close>\napply (blast dest!: PMS_sessionK_not_spied)\ntxt\\<open>Oops\\<close>\napply (blast intro: Says_serverK_unique)\ndone\n\n\nsubsubsection\\<open>Protocol goals: if A receives ServerFinished, then B is present\n     and has used the quoted values PA, PB, etc.  Note that it is up to A\n     to compare PA with what she originally sent.\\<close>\n\ntext\\<open>The mention of her name (A) in X assures A that B knows who she is.\\<close>\nlemma TrustServerFinished [rule_format]:\n     \"[| X = Crypt (serverK(Na,Nb,M))\n               (Hash\\<lbrace>Number SID, Nonce M,\n                      Nonce Na, Number PA, Agent A,\n                      Nonce Nb, Number PB, Agent B\\<rbrace>);\n         M = PRF(PMS,NA,NB);\n         evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad |]\n      ==> Says B Spy (Key(serverK(Na,Nb,M))) \\<notin> set evs -->\n          Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs -->\n          X \\<in> parts (spies evs) --> Says B A X \\<in> set evs\"\napply (erule ssubst)+\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp))\ntxt\\<open>Fake: the Spy doesn't have the critical session key!\\<close>\napply (blast dest: serverK_not_spied)\ntxt\\<open>ClientKeyExch\\<close>\napply (blast dest!: PMS_Crypt_sessionK_not_spied)\ndone\n\ntext\\<open>This version refers not to ServerFinished but to any message from B.\n  We don't assume B has received CertVerify, and an intruder could\n  have changed A's identity in all other messages, so we can't be sure\n  that B sends his message to A.  If CLIENT KEY EXCHANGE were augmented\n  to bind A's identity with PMS, then we could replace A' by A below.\\<close>\nlemma TrustServerMsg [rule_format]:\n     \"[| M = PRF(PMS,NA,NB);  evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad |]\n      ==> Says B Spy (Key(serverK(Na,Nb,M))) \\<notin> set evs -->\n          Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs -->\n          Crypt (serverK(Na,Nb,M)) Y \\<in> parts (spies evs)  -->\n          (\\<exists>A'. Says B A' (Crypt (serverK(Na,Nb,M)) Y) \\<in> set evs)\"\napply (erule ssubst)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp) add: ex_disj_distrib)\ntxt\\<open>Fake: the Spy doesn't have the critical session key!\\<close>\napply (blast dest: serverK_not_spied)\ntxt\\<open>ClientKeyExch\\<close>\napply (clarify, blast dest!: PMS_Crypt_sessionK_not_spied)\ntxt\\<open>ServerResume, ServerFinished: by unicity of PMS\\<close>\napply (blast dest!: Notes_master_imp_Crypt_PMS \n             dest: Spy_not_see_PMS Notes_Crypt_parts_spies Crypt_unique_PMS)+\ndone\n\n\nsubsubsection\\<open>Protocol goal: if B receives any message encrypted with clientK\n      then A has sent it\\<close>\n\ntext\\<open>ASSUMING that A chose PMS.  Authentication is\n     assumed here; B cannot verify it.  But if the message is\n     ClientFinished, then B can then check the quoted values PA, PB, etc.\\<close>\n\nlemma TrustClientMsg [rule_format]:\n     \"[| M = PRF(PMS,NA,NB);  evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad |]\n      ==> Says A Spy (Key(clientK(Na,Nb,M))) \\<notin> set evs -->\n          Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs -->\n          Crypt (clientK(Na,Nb,M)) Y \\<in> parts (spies evs) -->\n          Says A B (Crypt (clientK(Na,Nb,M)) Y) \\<in> set evs\"\napply (erule ssubst)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp))\ntxt\\<open>Fake: the Spy doesn't have the critical session key!\\<close>\napply (blast dest: clientK_not_spied)\ntxt\\<open>ClientKeyExch\\<close>\napply (blast dest!: PMS_Crypt_sessionK_not_spied)\ntxt\\<open>ClientFinished, ClientResume: by unicity of PMS\\<close>\napply (blast dest!: Notes_master_imp_Notes_PMS dest: Notes_unique_PMS)+\ndone\n\n\nsubsubsection\\<open>Protocol goal: if B receives ClientFinished, and if B is able to\n     check a CertVerify from A, then A has used the quoted\n     values PA, PB, etc.  Even this one requires A to be uncompromised.\\<close>\nlemma AuthClientFinished:\n     \"[| M = PRF(PMS,NA,NB);\n         Says A Spy (Key(clientK(Na,Nb,M))) \\<notin> set evs;\n         Says A' B (Crypt (clientK(Na,Nb,M)) Y) \\<in> set evs;\n         certificate A KA \\<in> parts (spies evs);\n         Says A'' B (Crypt (invKey KA) (Hash\\<lbrace>nb, Agent B, Nonce PMS\\<rbrace>))\n           \\<in> set evs;\n         evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad |]\n      ==> Says A B (Crypt (clientK(Na,Nb,M)) Y) \\<in> set evs\"\nby (blast intro!: TrustClientMsg UseCertVerify)\n\n(*22/9/97: loads in 622s, which is 10 minutes 22 seconds*)\n(*24/9/97: loads in 672s, which is 11 minutes 12 seconds [stronger theorems]*)\n(*29/9/97: loads in 481s, after removing Certificate from ClientKeyExch*)\n(*30/9/97: loads in 476s, after removing unused theorems*)\n(*30/9/97: loads in 448s, after fixing ServerResume*)\n\n(*08/9/97: loads in 189s (pike), after much reorganization,\n           back to 621s on albatross?*)\n\n(*10/2/99: loads in 139s (pike)\n           down to 433s on albatross*)\n\n(*5/5/01: conversion to Isar script\n          loads in 137s (perch)\n          the last ML version loaded in 122s on perch, a 600MHz machine:\n                twice as fast as pike.  No idea why it's so much slower!\n          The Isar script is slower still, perhaps because simp_all simplifies\n          the assumptions be default.\n*)\n\n(*20/11/11: loads in 5.8s elapses time, 9.3s CPU time on dual-core laptop*)\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/HOL/Auth/TLS.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.7217432182679956, "lm_q2_score": 0.3486451353339458, "lm_q1q2_score": 0.2516322620094029}}
{"text": "section \\<open>Computations of PiCore Language\\<close>\n\ntheory PiCore_Computation\nimports PiCore_Semantics\nbegin\n\nsubsection \\<open>Environment transitions\\<close>\n\nlocale event_comp = event ptran petran fin_com\nfor ptran :: \"'Env \\<Rightarrow> (('s,'prog) pconf \\<times> ('s,'prog) pconf) set\" \nand petran :: \"'Env \\<Rightarrow> ('s,'prog) pconf \\<Rightarrow> ('s,'prog) pconf \\<Rightarrow> bool\"  (\"_ \\<turnstile> _ -pe\\<rightarrow> _\" [81,81,81] 80)\nand fin_com :: \"'prog\"\n+\nfixes cpts_p :: \"'Env \\<Rightarrow> ('s,'prog) pconfs set\"\nfixes cpts_of_p :: \"'Env \\<Rightarrow> 'prog \\<Rightarrow> 's \\<Rightarrow> (('s,'prog) pconfs) set\"\n(*assumes cpts_p_simps:\n    \"((\\<exists>P s. aa = [(P, s)]) \\<or>\n     (\\<exists>P t xs s. aa = (P, s) # (P, t) # xs \\<and> \\<Gamma> \\<turnstile> (P, s) -pe\\<rightarrow> (P, t) \\<and> (P, t) # xs \\<in> cpts_p \\<Gamma>) \\<or>\n     (\\<exists>P s Q t xs. aa = (P, s) # (Q, t) # xs \\<and> \\<Gamma> \\<turnstile> (P, s) -c\\<rightarrow> (Q, t) \\<and> (Q, t) # xs \\<in> cpts_p \\<Gamma>)) \\<Longrightarrow> (aa \\<in> cpts_p \\<Gamma>)\"*)\nassumes cpts_p_simps:\n    \"((\\<exists>P s. aa = [(P, s)]) \\<or>\n     (\\<exists>P t xs s. aa = (P, s) # (P, t) # xs \\<and> (P, t) # xs \\<in> cpts_p \\<Gamma>) \\<or>\n     (\\<exists>P s Q t xs. aa = (P, s) # (Q, t) # xs \\<and> \\<Gamma> \\<turnstile> (P, s) -c\\<rightarrow> (Q, t) \\<and> (Q, t) # xs \\<in> cpts_p \\<Gamma>)) \\<Longrightarrow> (aa \\<in> cpts_p \\<Gamma>)\"\nassumes cptn_not_empty [simp]:\"[] \\<notin> cpts_p \\<Gamma>\" \n(* assumes cpts_of_p_def: \"cpts_of_p \\<Gamma> P s \\<equiv> {l. l!0=(P,s) \\<and> l \\<in> cpts_p \\<Gamma>}\" *)\nassumes cpts_of_p_def: \"l!0 = (P,s) \\<and> l \\<in> cpts_p \\<Gamma> \\<Longrightarrow> l \\<in> cpts_of_p \\<Gamma> P s\" \n\nbegin\n\nlemma CptsPOne: \"[(P,s)] \\<in> cpts_p \\<Gamma>\"                      \n  using cpts_p_simps[of \"[(P,s)]\" \\<Gamma>] by auto\n\nlemma CptsPEnv: \"(P, t)#xs \\<in> cpts_p \\<Gamma> \\<Longrightarrow> (P,s)#(P,t)#xs \\<in> cpts_p \\<Gamma>\" \n  using cpts_p_simps[of \"(P, s) # (P, t) # xs\" \\<Gamma>] by auto\n \nlemma CptsPComp: \"\\<lbrakk>\\<Gamma> \\<turnstile> (P,s) -c\\<rightarrow> (Q,t); (Q, t)#xs \\<in> cpts_p \\<Gamma>\\<rbrakk> \\<Longrightarrow> (P,s)#(Q,t)#xs \\<in> cpts_p \\<Gamma>\"\n  using cpts_p_simps[of \"(P, s) # (Q, t) # xs\" \\<Gamma> ] by auto\n\nsubsection \\<open>Sequential computations\\<close>\n\nsubsubsection \\<open>Sequential computations of programs\\<close>\n\n(*\nlemma cptn_not_empty [simp]:\"[] \\<notin> cpts_p \\<Gamma>\" using cpts_p_simps by blast \n*)\n\ninductive\n  eetran :: \"'Env \\<Rightarrow> ('l,'k,'s,'prog) econf \\<Rightarrow> ('l,'k,'s,'prog) econf \\<Rightarrow> bool\"  (\"_ \\<turnstile> _ -ee\\<rightarrow> _\" [81,81,81] 80)\nfor \\<Gamma> :: 'Env\nwhere (*EnvEP: \"\\<Gamma> \\<turnstile> (P, s) -pe\\<rightarrow> (P, t) \\<Longrightarrow> \\<Gamma> \\<turnstile> (P, s, x) -ee\\<rightarrow> (P, t, x)\" |   (* simulate env tran of program*)\n      EnvEE: \"\\<Gamma> \\<turnstile> (P, s, x) -ee\\<rightarrow> (P, s, y)\" (* simulate event entry *)*)\n EnvE: \"\\<Gamma> \\<turnstile> (P, s, x) -ee\\<rightarrow> (P, t, y)\"\n\nlemma eetranE: \"\\<Gamma> \\<turnstile> p -ee\\<rightarrow> p' \\<Longrightarrow> (\\<And>P s t. p = (P, s) \\<Longrightarrow> p' = (P, t) \\<Longrightarrow> Q) \\<Longrightarrow> Q\"\n  by (induct p, induct p', erule eetran.cases, blast)\n\ninductive\n  esetran :: \"'Env \\<Rightarrow> ('l,'k,'s,'prog) esconf \\<Rightarrow> ('l,'k,'s,'prog) esconf \\<Rightarrow> bool\"  (\"_ \\<turnstile> _ -ese\\<rightarrow> _\" [81,81,81] 80)\nwhere\n   EnvES: \"\\<Gamma> \\<turnstile> (P, s, x) -ese\\<rightarrow> (P, t, y)\"\n\nlemma esetranE: \"\\<Gamma> \\<turnstile> p -ese\\<rightarrow> p' \\<Longrightarrow> (\\<And>P s t. p = (P, s) \\<Longrightarrow> p' = (P, t) \\<Longrightarrow> Q) \\<Longrightarrow> Q\"\n  by (induct p, induct p', erule esetran.cases, blast)\n\ninductive\n  pesetran :: \"'Env \\<Rightarrow> ('l,'k,'s,'prog) pesconf \\<Rightarrow> ('l,'k,'s,'prog) pesconf \\<Rightarrow> bool\"  (\"_ \\<turnstile> _ -pese\\<rightarrow> _\" [81,81,81] 80)\nwhere\n  EnvPES: \"\\<Gamma> \\<turnstile> (P, s, x) -pese\\<rightarrow> (P, t, y)\"\n\nlemma pesetranE: \"\\<Gamma> \\<turnstile> p -pese\\<rightarrow> p' \\<Longrightarrow> (\\<And>P s t. p = (P, s) \\<Longrightarrow> p' = (P, t) \\<Longrightarrow> Q) \\<Longrightarrow> Q\"\n  by (induct p, induct p', erule pesetran.cases, blast)\n\nsubsubsection \\<open>Sequential computations of events\\<close>\n\ninductive_set cpts_ev :: \"'Env \\<Rightarrow> ('l,'k,'s,'prog) econfs set\"\nfor \\<Gamma> :: 'Env\nwhere\n  CptsEvOne: \"[(e,s,x)] \\<in> cpts_ev \\<Gamma>\"\n| CptsEvEnv: \"(e, t, x)#xs \\<in> cpts_ev \\<Gamma> \\<Longrightarrow> (e, s, y)#(e, t, x)#xs \\<in> cpts_ev \\<Gamma>\"\n| CptsEvComp: \"\\<lbrakk>\\<Gamma> \\<turnstile> (e1,s,x) -et-ct\\<rightarrow> (e2,t,y); (e2,t,y)#xs \\<in> cpts_ev \\<Gamma>\\<rbrakk> \\<Longrightarrow> (e1,s,x)#(e2,t,y)#xs \\<in> cpts_ev \\<Gamma>\"\n\ndefinition cpts_of_ev :: \"'Env \\<Rightarrow> ('l,'k,'s,'prog) event \\<Rightarrow> 's \\<Rightarrow> ('l,'k,'s,'prog) x \\<Rightarrow> ('l,'k,'s,'prog) econfs set\" where\n  \"cpts_of_ev \\<Gamma> ev s x \\<equiv> {l. l!0=(ev,(s,x)) \\<and> l \\<in> cpts_ev \\<Gamma>}\" \n\nsubsubsection \\<open>Sequential computations of event systems\\<close>\n\ninductive_set cpts_es :: \"'Env \\<Rightarrow> ('l,'k,'s,'prog) esconfs set\"\nfor \\<Gamma> :: 'Env\nwhere\n  CptsEsOne: \"[(es,s,x)] \\<in> cpts_es \\<Gamma>\"\n| CptsEsEnv: \"(es, t, x)#xs \\<in> cpts_es \\<Gamma> \\<Longrightarrow> (es, s, y)#(es, t, x)#xs \\<in> cpts_es \\<Gamma>\"\n| CptsEsComp: \"\\<lbrakk>\\<Gamma> \\<turnstile> (es1,s,x) -es-ct\\<rightarrow> (es2,t,y); (es2,t,y)#xs \\<in> cpts_es \\<Gamma>\\<rbrakk> \\<Longrightarrow> (es1,s,x)#(es2,t,y)#xs \\<in> cpts_es \\<Gamma>\"\n\ndefinition cpts_of_es :: \"'Env \\<Rightarrow> ('l,'k,'s,'prog) esys \\<Rightarrow> 's \\<Rightarrow> ('l,'k,'s,'prog) x \\<Rightarrow> ('l,'k,'s,'prog) esconfs set\" where\n  \"cpts_of_es \\<Gamma> es s x \\<equiv> {l. l!0=(es,s,x) \\<and> l \\<in> cpts_es \\<Gamma>}\" \n\nsubsubsection \\<open>Sequential computations of par event systems\\<close>\n\n\ninductive_set cpts_pes :: \"'Env \\<Rightarrow> ('l,'k,'s,'prog) pesconfs set\"\nfor \\<Gamma> :: 'Env\nwhere\n  CptsPesOne: \"[(pes,s,x)] \\<in> cpts_pes \\<Gamma>\"\n| CptsPesEnv: \"(pes, t, x)#xs \\<in> cpts_pes \\<Gamma> \\<Longrightarrow> (pes, s, y)#(pes, t, x)#xs \\<in> cpts_pes \\<Gamma>\"\n| CptsPesComp: \"\\<lbrakk>\\<Gamma> \\<turnstile> (pes1,s,x) -pes-ct\\<rightarrow> (pes2,t,y); (pes2,t,y)#xs \\<in> cpts_pes \\<Gamma>\\<rbrakk> \\<Longrightarrow> (pes1,s,x)#(pes2,t,y)#xs \\<in> cpts_pes \\<Gamma>\"\n\ndefinition cpts_of_pes :: \"'Env \\<Rightarrow> ('l,'k,'s,'prog) paresys \\<Rightarrow> 's \\<Rightarrow> ('l,'k,'s,'prog) x \\<Rightarrow> ('l,'k,'s,'prog) pesconfs set\" where\n  \"cpts_of_pes \\<Gamma> pes s x \\<equiv> {l. l!0=(pes,s,x) \\<and> l \\<in> cpts_pes \\<Gamma>}\" \n\nsubsection \\<open>Lemmas\\<close>\n(*\nsubsubsection \\<open>Programs\\<close>\n\nlemma tl_in_cptn: \"\\<lbrakk> a#xs \\<in>cpts_p \\<Gamma>; xs\\<noteq>[] \\<rbrakk> \\<Longrightarrow> xs\\<in>cpts_p \\<Gamma>\"\n  by (force elim: cpts_p.cases)\n\nlemma tl_zero[rule_format]: \n  \"P (ys!Suc j) \\<longrightarrow> Suc j<length ys \\<longrightarrow> ys\\<noteq>[] \\<longrightarrow> P (tl(ys)!j)\"\n  by (induct ys) simp_all\n*)\n\nsubsubsection \\<open>Events\\<close>\n\nlemma cpts_e_not_empty [simp]:\"[] \\<notin> cpts_ev \\<Gamma>\"\napply(force elim:cpts_ev.cases)\ndone\n\nlemma eetran_eqconf: \"\\<Gamma> \\<turnstile> (e1, s1, x1) -ee\\<rightarrow> (e2, s2, x2) \\<Longrightarrow> e1 = e2\"\n  apply(rule eetran.cases)\n  apply(simp)+\n  done\n\nlemma eetran_eqconf1: \"\\<Gamma> \\<turnstile> ec1 -ee\\<rightarrow> ec2 \\<Longrightarrow> getspc_e ec1 = getspc_e ec2\"\n  proof -\n    assume a0: \"\\<Gamma> \\<turnstile> ec1 -ee\\<rightarrow> ec2\"\n    then obtain e1 and s1 and x1 and e2 and s2 and x2 where a1: \"ec1 = (e1, s1, x1)\" and a2: \"ec2 = (e2, s2, x2)\"\n      by (meson prod_cases3) \n    then have \"e1 = e2\" using a0 eetran_eqconf by fastforce \n    with a1 show ?thesis by (simp add: a2 getspc_e_def) \n  qed\n\nlemma eqconf_eetran1: \"e1 = e2 \\<Longrightarrow> \\<Gamma> \\<turnstile> (e1, s1, x1) -ee\\<rightarrow> (e2, s2, x2)\"\n  by (simp add: eetran.intros) \n\nlemma eqconf_eetran: \"getspc_e ec1 = getspc_e ec2 \\<Longrightarrow> \\<Gamma> \\<turnstile> ec1 -ee\\<rightarrow> ec2\" \n  proof -\n    assume \"getspc_e ec1 = getspc_e ec2\"\n    then show ?thesis using getspc_e_def eetran.EnvE by (metis eq_fst_iff)\n  qed\n\n\nlemma cpts_ev_sub0: \"\\<lbrakk>el \\<in> cpts_ev \\<Gamma>; Suc 0 < length el\\<rbrakk> \\<Longrightarrow> drop (Suc 0) el \\<in> cpts_ev \\<Gamma>\"\n  apply(rule cpts_ev.cases)\n  apply(simp)+\n  done  \n\nlemma cpts_ev_subi: \"\\<lbrakk>el \\<in> cpts_ev \\<Gamma>; Suc i < length el\\<rbrakk> \\<Longrightarrow> drop (Suc i) el \\<in> cpts_ev \\<Gamma>\"\n  proof -\n    assume p0:\"el \\<in> cpts_ev \\<Gamma>\" and p1:\"Suc i < length el\"\n    have \"\\<forall>el i. el \\<in> cpts_ev \\<Gamma> \\<and> Suc i < length el \\<longrightarrow> drop (Suc i) el \\<in> cpts_ev \\<Gamma>\"\n      proof -\n      {\n        fix el i\n        have \"el \\<in> cpts_ev \\<Gamma> \\<and> Suc i < length el \\<longrightarrow> drop (Suc i) el \\<in> cpts_ev \\<Gamma>\"\n          proof(induct i)\n            case 0 show ?case by (simp add: cpts_ev_sub0) \n          next\n            case (Suc j)\n            assume b0: \"el \\<in> cpts_ev \\<Gamma> \\<and> Suc j < length el \\<longrightarrow> drop (Suc j) el \\<in> cpts_ev \\<Gamma>\"\n            show ?case\n              proof\n                assume c0: \"el \\<in> cpts_ev \\<Gamma> \\<and> Suc (Suc j) < length el\"\n                with b0 have c1: \"drop (Suc j) el \\<in> cpts_ev \\<Gamma>\"\n                  by (simp add: c0 Suc_lessD)                 \n                then show \"drop (Suc (Suc j)) el \\<in> cpts_ev \\<Gamma>\"\n                  using c0 cpts_ev_sub0 by fastforce \n              qed\n          qed\n      }\n      then show ?thesis by auto\n      qed\n    with p0 p1 show ?thesis by auto\n  qed\n  \nlemma notran_confeq0: \"\\<lbrakk>el \\<in> cpts_ev \\<Gamma>; Suc 0 < length el; \\<not> (\\<exists>t. \\<Gamma> \\<turnstile> el ! 0 -et-t\\<rightarrow> el ! 1)\\<rbrakk>\n                      \\<Longrightarrow> getspc_e (el ! 0) = getspc_e (el ! 1)\"\n  apply(simp)\n  apply(rule cpts_ev.cases)\n  apply(simp)+\n  apply(simp add:getspc_e_def)+\n  done\n\nlemma notran_confeqi: \"\\<lbrakk>el \\<in> cpts_ev \\<Gamma>; Suc i < length el; \\<not> (\\<exists>t. \\<Gamma> \\<turnstile> el ! i -et-t\\<rightarrow> el ! Suc i)\\<rbrakk>\n                      \\<Longrightarrow> getspc_e (el ! i) = getspc_e (el ! (Suc i))\"\n  proof -\n    assume p0: \"el \\<in> cpts_ev \\<Gamma>\" and\n           p1: \"Suc i < length el\" and\n           p2: \"\\<not> (\\<exists>t. \\<Gamma> \\<turnstile> el ! i -et-t\\<rightarrow> el ! Suc i)\"\n    have \"\\<forall>el i. el \\<in> cpts_ev \\<Gamma> \\<and>  Suc i < length el \\<and> \\<not> (\\<exists>t. \\<Gamma> \\<turnstile> el ! i -et-t\\<rightarrow> el ! Suc i)\n                \\<longrightarrow> getspc_e (el ! i) = getspc_e (el ! (Suc i))\"\n      proof -\n      {\n        fix el i\n        assume a0: \"el \\<in> cpts_ev \\<Gamma> \\<and>  Suc i < length el \\<and> \\<not> (\\<exists>t. \\<Gamma> \\<turnstile> el ! i -et-t\\<rightarrow> el ! Suc i)\"\n        then have \"getspc_e (el ! i) = getspc_e (el ! (Suc i))\"\n          proof(induct i)\n            case 0 then show ?case\n              using notran_confeq0 by (metis One_nat_def)\n          next\n            case (Suc j)\n            let ?subel = \"drop (Suc j) el\"\n            assume b0: \"el \\<in> cpts_ev \\<Gamma> \\<and> Suc (Suc j) < length el \\<and> \\<not> (\\<exists>t. \\<Gamma> \\<turnstile> el ! Suc j -et-t\\<rightarrow> el ! Suc (Suc j))\"            \n            then have b1: \"?subel \\<in> cpts_ev \\<Gamma>\" by (simp add: Suc_lessD b0 cpts_ev_subi) \n            from b0 have b2: \"Suc 0 < length ?subel\" by auto \n            from b0 have b3: \"\\<not> (\\<exists>t. \\<Gamma> \\<turnstile> ?subel ! 0 -et-t\\<rightarrow> ?subel ! 1)\" by auto\n            with b1 b2 have b3: \"getspc_e (?subel ! 0) = getspc_e (?subel ! 1)\"\n              using notran_confeq0 by blast\n            then show ?case\n              by (metis Cons_nth_drop_Suc One_nat_def Suc_lessD b0 nth_Cons_0 nth_Cons_Suc) \n          qed\n      }\n      then show ?thesis by auto\n      qed\n    with p0 p1 p2 show ?thesis by auto\n  qed\n\nlemma cpts_ev_onemore: \"\\<lbrakk>el \\<in> cpts_ev \\<Gamma>; length el > 0; \\<Gamma> \\<turnstile> el ! (length el - 1) -et-t\\<rightarrow> ec\\<rbrakk> \\<Longrightarrow>\n                          el @ [ec] \\<in> cpts_ev \\<Gamma>\"\n  proof -\n    assume p0: \"el \\<in> cpts_ev \\<Gamma>\"\n      and  p1: \"length el > 0\"\n      and  p2: \"\\<Gamma> \\<turnstile> el ! (length el - 1) -et-t\\<rightarrow> ec\"\n\n    have \"\\<forall>el ec t \\<Gamma>. el \\<in> cpts_ev \\<Gamma> \\<and> length el > 0 \\<and> \\<Gamma> \\<turnstile> el ! (length el - 1) -et-t\\<rightarrow> ec \\<longrightarrow> el @ [ec] \\<in> cpts_ev \\<Gamma>\"\n      proof -\n      {\n        fix el ec t \\<Gamma>\n        assume a0: \"el \\<in> cpts_ev \\<Gamma>\"\n          and  a1: \"length el > 0\"\n          and  a2: \"\\<Gamma> \\<turnstile> el ! (length el - 1) -et-t\\<rightarrow> ec\"\n        from a0 a1 a2 have \"el @ [ec] \\<in> cpts_ev \\<Gamma>\"\n          proof(induct el)\n            case (CptsEvOne e s x) \n            assume b0: \"\\<Gamma> \\<turnstile> [(e, s, x)] ! (length [(e, s, x)] - 1) -et-t\\<rightarrow> ec\"\n            then have \"\\<Gamma> \\<turnstile> (e, s, x) -et-t\\<rightarrow> ec\" by simp\n            then show ?case by (metis append_Cons append_Nil cpts_ev.CptsEvComp \n                  cpts_ev.CptsEvOne surj_pair) \n          next\n            case (CptsEvEnv e s1 x xs s2 y)\n            assume b0: \"(e, s1, x) # xs \\<in> cpts_ev \\<Gamma>\"\n              and  b1: \"0 < length ((e, s1, x) # xs) \\<Longrightarrow>\n                        \\<Gamma> \\<turnstile> ((e, s1, x) # xs) ! (length ((e, s1, x) # xs) - 1) -et-t\\<rightarrow> ec \n                        \\<Longrightarrow> ((e, s1, x) # xs) @ [ec] \\<in> cpts_ev \\<Gamma>\"\n              and  b2: \"0 < length ((e, s2, y) # (e, s1, x) # xs)\"\n              and  b3: \"\\<Gamma> \\<turnstile> ((e, s2, y) # (e, s1, x) # xs) ! (length ((e, s2, y) # (e, s1, x) # xs) - 1) -et-t\\<rightarrow> ec\"\n            then show ?case \n              proof(cases \"xs = []\")\n                assume c0: \"xs = []\"\n                with b3 have \"\\<Gamma> \\<turnstile> (e, s1, x)-et-t\\<rightarrow> ec\" by simp\n                with b1 c0 have \"((e, s1, x) # xs) @ [ec] \\<in> cpts_ev \\<Gamma>\" by simp\n                then show ?thesis by (simp add: cpts_ev.CptsEvEnv) \n              next\n                assume c0: \"xs \\<noteq> []\"\n                with b3 have \"\\<Gamma> \\<turnstile> last xs -et-t\\<rightarrow> ec\" by (simp add: last_conv_nth) \n                with b1 c0 have \"((e, s1, x) # xs) @ [ec] \\<in> cpts_ev \\<Gamma>\" using b3 by auto\n                then show ?thesis by (simp add: cpts_ev.CptsEvEnv) \n              qed\n          next\n            case (CptsEvComp e1 s1 x1 et e2 t1 y1 xs1)\n            assume b0: \"\\<Gamma> \\<turnstile> (e1, s1, x1) -et-et\\<rightarrow> (e2, t1, y1)\"\n              and  b1: \"(e2, t1, y1) # xs1 \\<in> cpts_ev \\<Gamma>\"\n              and  b2: \"0 < length ((e2, t1, y1) # xs1) \\<Longrightarrow>\n                \\<Gamma> \\<turnstile> ((e2, t1, y1) # xs1) ! (length ((e2, t1, y1) # xs1) - 1) -et-t\\<rightarrow> ec \n                  \\<Longrightarrow> ((e2, t1, y1) # xs1) @ [ec] \\<in> cpts_ev \\<Gamma>\"\n              and  b3: \"0 < length ((e1, s1, x1) # (e2, t1, y1) # xs1)\"\n              and  b4: \"\\<Gamma> \\<turnstile> ((e1, s1, x1) # (e2, t1, y1) # xs1) ! (length ((e1, s1, x1) # (e2, t1, y1) # xs1) - 1) -et-t\\<rightarrow> ec\"\n            then show ?case \n              proof(cases \"xs1 = []\")\n                assume c0: \"xs1 = []\"\n                with b4 have \"\\<Gamma> \\<turnstile> (e2, t1, y1)-et-t\\<rightarrow> ec\" by simp\n                with b2 c0 have \"((e2, t1, y1) # xs1) @ [ec] \\<in> cpts_ev \\<Gamma>\" by simp\n                with b0 show ?thesis using cpts_ev.CptsEvComp by fastforce \n              next\n                assume c0: \"xs1 \\<noteq> []\"\n                with b4 have \"\\<Gamma> \\<turnstile> last xs1 -et-t\\<rightarrow> ec\" by (simp add: last_conv_nth)\n                with b2 c0 have \"((e2, t1, y1) # xs1) @ [ec] \\<in> cpts_ev \\<Gamma>\" using b4 by auto \n                then show ?thesis using b0 cpts_ev.CptsEvComp by fastforce \n              qed\n          qed\n      }\n      then show ?thesis by auto\n      qed\n\n    then show \"el @ [ec] \\<in> cpts_ev \\<Gamma>\" using p0 p1 p2 by blast \n  qed\n\nlemma cpts_ev_same: \"\\<lbrakk>length el > 0; \\<forall>i. i < length el \\<longrightarrow> getspc_e (el!i) = es\\<rbrakk> \\<Longrightarrow> el \\<in> cpts_ev \\<Gamma>\"\n  proof -\n    assume p0: \"length el > 0\"\n      and  p1: \"\\<forall>i. i < length el \\<longrightarrow> getspc_e (el!i) = es\"\n    have \"\\<forall>el es. length el > 0 \\<and> (\\<forall>i. i < length el \\<longrightarrow> getspc_e (el!i) = es) \\<longrightarrow> el \\<in> cpts_ev \\<Gamma>\"\n      proof -\n      {\n        fix el es\n        assume a0: \"length (el :: ('l,'k,'s,'prog) econfs) > 0\"\n          and  a1: \"\\<forall>i. i < length el \\<longrightarrow> getspc_e (el!i) = es\"\n        then have \"el \\<in> cpts_ev \\<Gamma>\"\n          proof(induct el)\n            case Nil show ?case using Nil.prems(1) by auto \n          next\n            case (Cons a as)\n            assume b0: \"0 < length as \\<Longrightarrow> \\<forall>i<length as. getspc_e (as ! i) = es \\<Longrightarrow> as \\<in> cpts_ev \\<Gamma>\"\n              and  b1: \"0 < length (a # as)\"\n              and  b2: \"\\<forall>i<length (a # as). getspc_e ((a # as) ! i) = es\"\n            then show ?case\n              proof(cases \"as = []\")\n                assume c0: \"as = []\"\n                then show ?thesis by (metis cpts_ev.CptsEvOne old.prod.exhaust) \n              next\n                assume c0: \"\\<not>(as = [])\"\n                then obtain b and bs where c1: \"as = b # bs\" by (meson neq_Nil_conv) \n                from c0 have \"0 < length as\" by simp\n                with b0 have \"\\<forall>i<length as. getspc_e (as ! i) = es \\<Longrightarrow> as \\<in> cpts_ev \\<Gamma>\" by simp\n                with b2 have \"as \\<in> cpts_ev \\<Gamma>\" by force\n                moreover from b2 have \"getspc_e a = es\" by auto\n                moreover from b2 c1 have \"getspc_e b = es\" by auto\n                ultimately show ?thesis using c1 getspc_e_def by (metis cpts_ev.CptsEvEnv fst_conv prod_cases3) \n              qed\n          qed\n      }\n      then show ?thesis by auto\n      qed\n\n    then show ?thesis using p0 p1 by auto\n  qed\n\nsubsubsection \\<open>Event systems\\<close>\n\n\nlemma cpts_es_not_empty [simp]:\"[] \\<notin> cpts_es \\<Gamma>\"\napply(force elim:cpts_es.cases)\ndone\n\n\nlemma esetran_eqconf: \"\\<Gamma> \\<turnstile> (es1, s1, x1) -ese\\<rightarrow> (es2, s2, x2) \\<Longrightarrow> es1 = es2\"\n  apply(rule esetran.cases)\n  apply(simp)+\n  done\n\nlemma esetran_eqconf1: \"\\<Gamma> \\<turnstile> esc1 -ese\\<rightarrow> esc2 \\<Longrightarrow> getspc_es esc1 = getspc_es esc2\"\n  proof -\n    assume a0: \"\\<Gamma> \\<turnstile> esc1 -ese\\<rightarrow> esc2\"\n    then obtain es1 and s1 and x1 and es2 and s2 and x2 where a1: \"esc1 = (es1, s1, x1)\" and a2: \"esc2 = (es2, s2, x2)\"\n      by (meson prod_cases3) \n    then have \"es1 = es2\" using a0 esetran_eqconf by fastforce \n    with a1 show ?thesis by (simp add: a2 getspc_es_def) \n  qed\n\nlemma eqconf_esetran1: \"es1 = es2 \\<Longrightarrow> \\<Gamma> \\<turnstile> (es1, s1, x1) -ese\\<rightarrow> (es2, s2, x2)\"\n  by (simp add: esetran.intros) \n\n\nlemma eqconf_esetran: \"getspc_es esc1 = getspc_es esc2 \\<Longrightarrow> \\<Gamma> \\<turnstile> esc1 -ese\\<rightarrow> esc2\" \n  proof -\n    assume a0: \"getspc_es esc1 = getspc_es esc2\"\n    (*then show ?thesis using getspc_es_def esetran.EnvES by (metis eq_fst_iff)*)\n    obtain es1 and s1 and x1 where a1: \"esc1 = (es1, s1, x1)\" using prod_cases3 by blast \n    obtain es2 and s2 and x2 where a2: \"esc2 = (es2, s2, x2)\" using prod_cases3 by blast \n    with a0 a1 have \"es1 = es2\" by (simp add:getspc_es_def)\n    with a1 a2 have a3: \"\\<Gamma> \\<turnstile> (es1, s1, x1) -ese\\<rightarrow> (es2, s2, x2)\" by (simp add:eqconf_esetran1)\n    from a3 a1 a2 show ?thesis by simp\n  qed\n\nlemma exist_estran: \"\\<lbrakk>(es1, s1, x1) # (es, s, x) # esl \\<in> cpts_es \\<Gamma>; es1 \\<noteq> es\\<rbrakk> \\<Longrightarrow> (\\<exists>est. \\<Gamma> \\<turnstile> (es1, s1, x1) -es-est\\<rightarrow> (es, s, x))\"\n  apply(rule cpts_es.cases)\n  apply(simp)+\n  by auto\n\nlemma cpts_es_drop0: \"\\<lbrakk>el \\<in> cpts_es \\<Gamma>; Suc 0 < length el\\<rbrakk> \\<Longrightarrow> drop (Suc 0) el \\<in> cpts_es \\<Gamma>\"\n  apply(rule cpts_es.cases)\n  apply(simp)+\n  done  \n\nlemma cpts_es_dropi: \"\\<lbrakk>el \\<in> cpts_es \\<Gamma>; Suc i < length el\\<rbrakk> \\<Longrightarrow> drop (Suc i) el \\<in> cpts_es \\<Gamma>\"\n  proof -\n    assume p0:\"el \\<in> cpts_es \\<Gamma>\" and p1:\"Suc i < length el\"\n    have \"\\<forall>el i. el \\<in> cpts_es \\<Gamma> \\<and> Suc i < length el \\<longrightarrow> drop (Suc i) el \\<in> cpts_es \\<Gamma>\"\n      proof -\n      {\n        fix el i\n        have \"el \\<in> cpts_es \\<Gamma> \\<and> Suc i < length el \\<longrightarrow> drop (Suc i) el \\<in> cpts_es \\<Gamma>\"\n          proof(induct i)\n            case 0 show ?case by (simp add: cpts_es_drop0) \n          next\n            case (Suc j)\n            assume b0: \"el \\<in> cpts_es \\<Gamma> \\<and> Suc j < length el \\<longrightarrow> drop (Suc j) el \\<in> cpts_es \\<Gamma>\"\n            show ?case\n              proof\n                assume c0: \"el \\<in> cpts_es \\<Gamma> \\<and> Suc (Suc j) < length el\"\n                with b0 have c1: \"drop (Suc j) el \\<in> cpts_es \\<Gamma>\"\n                  by (simp add: c0 Suc_lessD)                 \n                then show \"drop (Suc (Suc j)) el \\<in> cpts_es \\<Gamma>\"\n                  using c0 cpts_es_drop0 by fastforce \n              qed\n          qed\n      }\n      then show ?thesis by auto\n      qed\n    with p0 p1 show ?thesis by auto\n  qed\n\n\nlemma cpts_es_dropi2: \"\\<lbrakk>el \\<in> cpts_es \\<Gamma>; i < length el\\<rbrakk> \\<Longrightarrow> drop i el \\<in> cpts_es \\<Gamma>\"\n  using cpts_es_dropi by (metis (no_types, hide_lams) drop_0 lessI less_Suc_eq_0_disj) \n\nlemma cpts_es_take0: \"\\<lbrakk>el \\<in> cpts_es \\<Gamma>; i < length el; el1 = take (Suc i) el; j < length el1\\<rbrakk> \n                        \\<Longrightarrow> drop (length el1 - Suc j) el1 \\<in> cpts_es \\<Gamma>\"\n  proof -\n    assume p0: \"el \\<in> cpts_es \\<Gamma>\"\n      and  p1: \"i < length el\"\n      and  p2: \"el1 = take (Suc i) el\"\n      and  p3: \"j < length el1\"\n    have \"\\<forall>i j. el \\<in> cpts_es \\<Gamma> \\<and> i < length el \\<and> el1 = take (Suc i) el \\<and> j < length el1 \n          \\<longrightarrow> drop (length el1 - Suc j) el1 \\<in> cpts_es \\<Gamma>\"\n      proof -\n      {\n        fix i j\n        assume a0: \"el \\<in> cpts_es \\<Gamma>\"\n          and  a1: \"i < length el\"\n          and  a2: \"el1 = take (Suc i) el\"\n          and  a3: \"j < length el1\"\n        then have \"drop (length el1 - Suc j) el1 \\<in> cpts_es \\<Gamma>\"\n          proof(induct j)\n            case 0 \n            have \"drop (length el1 - Suc 0) el1 = [el ! i]\"\n              by (simp add: a1 a2 take_Suc_conv_app_nth) \n            then show ?case by (metis cpts_es.CptsEsOne old.prod.exhaust) \n          next\n            case (Suc jj)\n            assume b0: \"el \\<in> cpts_es \\<Gamma> \\<Longrightarrow> i < length el \\<Longrightarrow> el1 = take (Suc i) el \n                        \\<Longrightarrow> jj < length el1 \\<Longrightarrow> drop (length el1 - Suc jj) el1 \\<in> cpts_es \\<Gamma>\"\n              and  b1: \"el \\<in> cpts_es \\<Gamma>\"\n              and  b2: \"i < length el\"\n              and  b3: \"el1 = take (Suc i) el\"\n              and  b4: \"Suc jj < length el1\"\n            then have b5: \"drop (length el1 - Suc jj) el1 \\<in> cpts_es \\<Gamma>\"\n              using Suc_lessD by blast \n            let ?el2 = \"drop (Suc i) el\"\n            from a2 have b6: \"el1 @ ?el2 = el\" by simp\n            let ?el1sht = \"drop (length el1 - Suc jj) el1\"\n            let ?el1lng = \"drop (length el1 - Suc (Suc jj)) el1\"\n            let ?elsht = \"drop (length el1 - Suc jj) el\"\n            let ?ellng = \"drop (length el1 - Suc (Suc jj)) el\"\n            from b6 have a7: \"?el1sht @ ?el2 = ?elsht\"\n              by (metis diff_is_0_eq diff_le_self drop_0 drop_append) \n            from b6 have a8: \"?el1lng @ ?el2 = ?ellng\"\n              by (metis (no_types, lifting) a7 append_eq_append_conv diff_is_0_eq' diff_le_self drop_append) \n            have a9: \"?ellng = (el ! (length el1 - Suc (Suc jj))) # ?elsht\"\n              by (metis (no_types, lifting) Cons_nth_drop_Suc Suc_diff_Suc Suc_leI a8 \n                  append_is_Nil_conv b4 diff_diff_cancel drop_all length_drop \n                  list.size(3) not_less old.nat.distinct(2)) \n            from b1 b4 have a10: \"?elsht \\<in> cpts_es \\<Gamma>\"\n              by (metis a7 append_is_Nil_conv b5 cpts_es_dropi2 drop_all not_less)\n            from b1 b4 have a11: \"?ellng \\<in> cpts_es \\<Gamma>\"\n              by (metis a9 cpts_es_dropi2 drop_all list.simps(3) not_less)\n            have a12: \"?el1lng = (el ! (length el1 - Suc (Suc jj))) # ?el1sht\"\n              by (metis (no_types, lifting) Cons_nth_drop_Suc Suc_diff_Suc \n                b4 b6 diff_less gr_implies_not0 length_0_conv length_greater_0_conv \n                nth_append zero_less_Suc)\n            from a11 have \"?el1lng \\<in> cpts_es \\<Gamma>\"\n              proof(induct ?ellng)\n                case CptsEsOne show ?case\n                  using CptsEsOne.hyps a7 a9 by auto \n              next\n                case (CptsEsEnv es1 t1 x1 xs1 s1 y1)\n                assume c0: \"(es1, t1, x1) # xs1 \\<in> cpts_es \\<Gamma>\"\n                  and  c1: \"(es1, t1, x1) # xs1 = drop (length el1 - Suc (Suc jj)) el \\<Longrightarrow>\n                            drop (length el1 - Suc (Suc jj)) el1 \\<in> cpts_es \\<Gamma>\"\n                  and  c2: \"(es1, s1, y1) # (es1, t1, x1) # xs1 = drop (length el1 - Suc (Suc jj)) el\"\n                from c0 have \"(es1, s1, y1) # (es1, t1, x1) # xs1 \\<in> cpts_es \\<Gamma>\"\n                  by (simp add: a11 c2) \n                have c3: \"?el1sht ! 0 = (es1, t1, x1)\" by (metis (no_types, lifting) Suc_leI Suc_lessD a7 \n                        a9 append_eq_Cons_conv b4 c2 diff_diff_cancel length_drop list.inject \n                        list.size(3) nth_Cons_0 old.nat.distinct(2)) \n                then have c4: \"\\<exists>el1sht'. ?el1sht = (es1, t1, x1) # el1sht'\" by (metis Cons_nth_drop_Suc b4 \n                    diff_diff_cancel drop_0 length_drop less_or_eq_imp_le zero_less_Suc) \n                have c5: \"?el1lng = (es1, s1, y1) # ?el1sht\" using a12 a9 c2 by auto \n                \n                with b5 c4 show ?case using cpts_es.CptsEsEnv by fastforce \n              next\n                case (CptsEsComp es1 s1 x1 et es2 t1 y1 xs1)\n                assume c0: \"\\<Gamma> \\<turnstile> (es1, s1, x1) -es-et\\<rightarrow> (es2, t1, y1)\"\n                  and  c1: \"(es2, t1, y1) # xs1 \\<in> cpts_es \\<Gamma>\"\n                  and  c2: \"(es2, t1, y1) # xs1 = drop (length el1 - Suc (Suc jj)) el \n                            \\<Longrightarrow> drop (length el1 - Suc (Suc jj)) el1 \\<in> cpts_es \\<Gamma>\"\n                  and  c3: \"(es1, s1, x1) # (es2, t1, y1) # xs1 = drop (length el1 - Suc (Suc jj)) el\"\n                have c4: \"?el1sht ! 0 = (es2, t1, y1)\" by (metis (no_types, lifting) Suc_leI Suc_lessD a7 \n                        a9 append_eq_Cons_conv b4 c3 diff_diff_cancel length_drop list.inject \n                        list.size(3) nth_Cons_0 old.nat.distinct(2)) \n                then have c5: \"\\<exists>el1sht'. ?el1sht = (es2, t1, y1) # el1sht'\" by (metis Cons_nth_drop_Suc b4 \n                    diff_diff_cancel drop_0 length_drop less_or_eq_imp_le zero_less_Suc) \n                have c6: \"?el1lng = (es1, s1, x1) # ?el1sht\" using a12 a9 c3 by auto\n                with b5 c5  show ?case using c0 cpts_es.CptsEsComp by fastforce \n              qed\n\n            then show ?case by simp\n          qed\n      }\n      then show ?thesis by auto\n      qed\n    then show \"drop (length el1 - Suc j) el1 \\<in> cpts_es \\<Gamma>\"\n      using p0 p1 p2 p3 by blast \n  qed\n\n\nlemma cpts_es_take: \"\\<lbrakk>el \\<in> cpts_es \\<Gamma>; i < length el\\<rbrakk> \\<Longrightarrow> take (Suc i) el \\<in> cpts_es \\<Gamma>\"\n  using cpts_es_take0 gr_implies_not0 by fastforce\n\nlemma cpts_es_seg: \"\\<lbrakk>el \\<in> cpts_es \\<Gamma>; m \\<le> length el; n \\<le> length el; m < n\\<rbrakk> \n                    \\<Longrightarrow> take (n - m) (drop m el) \\<in> cpts_es \\<Gamma>\"\n  proof -\n    assume p0: \"el \\<in> cpts_es \\<Gamma>\"\n      and  p1: \"m \\<le> length el\"\n      and  p2: \"n \\<le> length el\"\n      and  p3: \"m < n\"\n    then have \"drop m el \\<in> cpts_es \\<Gamma>\" \n      using cpts_es_dropi by (metis (no_types, lifting) drop_0 le_0_eq le_SucE less_le_trans zero_induct) \n    then show ?thesis using cpts_es_take\n      by (metis (no_types, lifting) cpts_es_dropi2 drop_take inc_induct \n        leD le_SucE length_take min.absorb2 p0 p1 p2 p3)\n  qed\n\nlemma cpts_es_seg2: \"\\<lbrakk>el \\<in> cpts_es \\<Gamma>; m \\<le> length el; n \\<le> length el; take (n - m) (drop m el) \\<noteq> []\\<rbrakk> \n                    \\<Longrightarrow> take (n - m) (drop m el) \\<in> cpts_es \\<Gamma>\"\n  proof -\n    assume p0: \"el \\<in> cpts_es \\<Gamma>\"\n      and  p1: \"m \\<le> length el\"\n      and  p2: \"n \\<le> length el\"\n      and  p3: \"take (n - m) (drop m el) \\<noteq> []\"\n    from p3 have \"m < n\" by simp\n    then show ?thesis using cpts_es_seg using p0 p1 p2 by blast\n  qed\n\nlemma cpts_es_same: \"\\<lbrakk>length el > 0; \\<forall>i. i < length el \\<longrightarrow> getspc_es (el!i) = es\\<rbrakk> \\<Longrightarrow> el \\<in> cpts_es \\<Gamma>\"\n  proof -\n    assume p0: \"length el > 0\"\n      and  p1: \"\\<forall>i. i < length el \\<longrightarrow> getspc_es (el!i) = es\"\n    have \"\\<forall>el es. length el > 0 \\<and> (\\<forall>i. i < length el \\<longrightarrow> getspc_es (el!i) = es) \\<longrightarrow> el \\<in> cpts_es \\<Gamma>\"\n      proof -\n      {\n        fix el es\n        assume a0: \"length (el :: ('l,'k,'s,'prog) esconf list) > 0\"\n          and  a1: \"\\<forall>i. i < length el \\<longrightarrow> getspc_es (el!i) = es\"\n        then have \"el \\<in> cpts_es \\<Gamma>\"\n          proof(induct el)\n            case Nil show ?case using Nil.prems(1) by auto \n          next\n            case (Cons a as)\n            assume b0: \"0 < length as \\<Longrightarrow> \\<forall>i<length as. getspc_es (as ! i) = es \\<Longrightarrow> as \\<in> cpts_es \\<Gamma>\"\n              and  b1: \"0 < length (a # as)\"\n              and  b2: \"\\<forall>i<length (a # as). getspc_es ((a # as) ! i) = es\"\n            then show ?case\n              proof(cases \"as = []\")\n                assume c0: \"as = []\"\n                then show ?thesis by (metis cpts_es.CptsEsOne old.prod.exhaust) \n              next\n                assume c0: \"\\<not>(as = [])\"\n                then obtain b and bs where c1: \"as = b # bs\" by (meson neq_Nil_conv) \n                from c0 have \"0 < length as\" by simp\n                with b0 have \"\\<forall>i<length as. getspc_es (as ! i) = es \\<Longrightarrow> as \\<in> cpts_es \\<Gamma>\" by simp\n                with b2 have \"as \\<in> cpts_es \\<Gamma>\" by force\n                moreover from b2 have \"getspc_es a = es\" by auto\n                moreover from b2 c1 have \"getspc_es b = es\" by auto\n                ultimately show ?thesis using c1 getspc_es_def by (metis cpts_es.CptsEsEnv fst_conv prod_cases3) \n              qed\n          qed\n      }\n      then show ?thesis by auto\n      qed\n\n    then show ?thesis using p0 p1 by auto\n  qed\n\n\nlemma noevtent_inmid_eq: \n    \"(\\<not> (\\<exists>j. j > 0 \\<and> Suc j < length esl \\<and> getspc_es (esl ! j) = EvtSys es \\<and> getspc_es (esl ! Suc j) \\<noteq> EvtSys es))\n      = (\\<forall>j. j > 0 \\<and> Suc j < length esl \\<longrightarrow> getspc_es (esl ! j) = EvtSys es \\<longrightarrow> getspc_es (esl ! Suc j) = EvtSys es)\"\n      by blast\n\nlemma evtseq_next_in_cpts:\n  \"esl\\<in>cpts_es \\<Gamma> \\<Longrightarrow> \\<forall>i. Suc i < length esl \\<and> getspc_es (esl!i) = EvtSeq e esys\n                       \\<longrightarrow> getspc_es (esl!Suc i) = esys \\<or> (\\<exists>e. getspc_es (esl!Suc i) = EvtSeq e esys)\"\n  proof -\n    assume p0: \"esl\\<in>cpts_es \\<Gamma>\"\n    then show ?thesis\n      proof -\n      {\n        fix i\n        assume a0: \"Suc i < length esl\"\n          and  a1: \"getspc_es (esl!i) = EvtSeq e esys\"\n        let ?esl1 = \"drop i esl\"\n        from p0 a0 have a2: \"?esl1\\<in>cpts_es \\<Gamma>\" by (metis (no_types, hide_lams) Suc_diff_1 Suc_lessD \n              cpts_es_dropi diff_diff_cancel drop_0 length_drop length_greater_0_conv \n              less_or_eq_imp_le list.size(3)) \n        from a0 a1 have \"getspc_es (?esl1!0) = EvtSeq e esys\" by auto \n        then obtain s1 and x1 where a3: \"?esl1!0 = (EvtSeq e esys,s1,x1)\" \n          using getspc_es_def by (metis fst_conv old.prod.exhaust)\n        from a2 a1 have \"getspc_es (?esl1!1) = esys \\<or> (\\<exists>e. getspc_es (?esl1!1) = EvtSeq e esys)\"\n          proof(induct ?esl1)\n            case (CptsEsOne es' s' x')\n            then show ?case by (metis One_nat_def Suc_eq_plus1_left Suc_lessD a0 \n                le_add_diff_inverse2 length_Cons length_drop less_imp_le \n                list.size(3) not_less_iff_gr_or_eq)  \n          next\n            case (CptsEsEnv es' t' x' xs' s' y')\n            assume b0: \"(es', s', y') # (es', t', x') # xs' = drop i esl\"\n              and  b1: \"getspc_es (esl ! i) = EvtSeq e esys\"\n            then have \"es' = EvtSeq e esys\" using getspc_es_def by (metis a3 fst_conv nth_Cons_0)\n            with b0 have \"getspc_es (drop i esl ! 1) = EvtSeq e esys\" using getspc_es_def\n              by (metis One_nat_def fst_conv nth_Cons_0 nth_Cons_Suc) \n            then show ?case by auto\n          next\n            case (CptsEsComp es1' s' x' et' es2' t' y' xs')\n            assume b0: \"\\<Gamma> \\<turnstile> (es1', s', x') -es-et'\\<rightarrow> (es2', t', y')\"\n              and  b1: \"(es1', s', x') # (es2', t', y') # xs' = drop i esl\"\n              and  b2: \"getspc_es (esl ! i) = EvtSeq e esys\"\n            then have b3: \"es1' = EvtSeq e esys\" \n              by (metis Pair_inject a3 nth_Cons_0)\n            from b0 b3 have \"es2' = esys \\<or> (\\<exists>e. es2' = EvtSeq e esys)\" \n              using evtseq_tran_sys_or_seq by simp\n            with b1 show ?case using getspc_es_def\n              by (metis One_nat_def fst_conv nth_Cons_0 nth_Cons_Suc) \n              \n          qed\n\n        then have \"getspc_es (esl!Suc i) = esys \\<or> (\\<exists>e. getspc_es (esl!Suc i) = EvtSeq e esys)\"\n          using a0 by fastforce\n      }\n      then show ?thesis by auto\n      qed\n  qed\n\nlemma evtseq_next_in_cpts_anony:\n  \"esl\\<in>cpts_es \\<Gamma> \\<Longrightarrow> \\<forall>i. Suc i < length esl \\<and> getspc_es (esl!i) = EvtSeq e esys \\<and> is_anonyevt e\n                       \\<longrightarrow> getspc_es (esl!Suc i) = esys \n                        \\<or> (\\<exists>e. getspc_es (esl!Suc i) = EvtSeq e esys \\<and> is_anonyevt e)\"\n  proof -\n    assume p0: \"esl\\<in>cpts_es \\<Gamma>\"\n    then show ?thesis\n      proof -\n      {\n        fix i\n        assume a0: \"Suc i < length esl\"\n          and  a1: \"getspc_es (esl!i) = EvtSeq e esys \\<and> is_anonyevt e\"\n        let ?esl1 = \"drop i esl\"\n        from p0 a0 have a2: \"?esl1\\<in>cpts_es \\<Gamma>\" by (metis (no_types, hide_lams) Suc_diff_1 Suc_lessD \n              cpts_es_dropi diff_diff_cancel drop_0 length_drop length_greater_0_conv \n              less_or_eq_imp_le list.size(3)) \n        from a0 a1 have \"getspc_es (?esl1!0) = EvtSeq e esys\" by auto \n        then obtain s1 and x1 where a3: \"?esl1!0 = (EvtSeq e esys,s1,x1)\" \n          using getspc_es_def by (metis fst_conv old.prod.exhaust)\n        from a2 a1 have \"getspc_es (?esl1!1) = esys \n                        \\<or> (\\<exists>e. getspc_es (?esl1!1) = EvtSeq e esys \\<and> is_anonyevt e)\"\n          proof(induct ?esl1)\n            case (CptsEsOne es' s' x')\n            then show ?case by (metis One_nat_def Suc_eq_plus1_left Suc_lessD a0 \n                le_add_diff_inverse2 length_Cons length_drop less_imp_le \n                list.size(3) not_less_iff_gr_or_eq)  \n          next\n            case (CptsEsEnv es' t' x' xs' s' y')\n            assume b0: \"(es', s', y') # (es', t', x') # xs' = drop i esl\"\n              and  b1: \"getspc_es (esl ! i) = EvtSeq e esys \\<and> is_anonyevt e\"\n            then have \"es' = EvtSeq e esys\" using getspc_es_def by (metis a3 fst_conv nth_Cons_0)\n            with b0 have \"getspc_es (drop i esl ! 1) = EvtSeq e esys \\<and> is_anonyevt e\" \n              using getspc_es_def by (metis One_nat_def b1 fst_conv nth_Cons_0 nth_Cons_Suc)\n            then show ?case by auto\n          next\n            case (CptsEsComp es1' s' x' et' es2' t' y' xs')\n            assume b0: \"\\<Gamma> \\<turnstile> (es1', s', x') -es-et'\\<rightarrow> (es2', t', y')\"\n              and  b1: \"(es1', s', x') # (es2', t', y') # xs' = drop i esl\"\n              and  b2: \"getspc_es (esl ! i) = EvtSeq e esys \\<and> is_anonyevt e\"\n            then have b3: \"es1' = EvtSeq e esys\" \n              by (metis Pair_inject a3 nth_Cons_0)\n            from b0 b3 have \"es2' = esys \\<or> (\\<exists>e. es2' = EvtSeq e esys \\<and> is_anonyevt e)\" \n              using evtseq_tran_sys_or_seq_anony\n              by simp\n            with b1 show ?case using getspc_es_def\n              by (metis One_nat_def fst_conv nth_Cons_0 nth_Cons_Suc) \n              \n          qed\n\n        then have \"getspc_es (esl!Suc i) = esys \n          \\<or> (\\<exists>e. getspc_es (esl!Suc i) = EvtSeq e esys \\<and> is_anonyevt e)\"\n          using a0 by fastforce\n      }\n      then show ?thesis by auto\n      qed\n  qed\n\nlemma evtsys_next_in_cpts:\n  \"esl\\<in>cpts_es \\<Gamma> \\<Longrightarrow> \\<forall>i. Suc i < length esl \\<and> getspc_es (esl!i) = EvtSys es \n                       \\<longrightarrow> getspc_es (esl!Suc i) = EvtSys es \\<or> (\\<exists>e. getspc_es (esl!Suc i) = EvtSeq e (EvtSys es))\"\n  proof -\n    assume p0: \"esl\\<in>cpts_es \\<Gamma>\"\n    then show ?thesis\n      proof -\n      {\n        fix i\n        assume a0: \"Suc i < length esl\"\n          and  a1: \"getspc_es (esl!i) = EvtSys es\"\n        let ?esl1 = \"drop i esl\"\n        from p0 a0 have a2: \"?esl1\\<in>cpts_es \\<Gamma>\" by (metis (no_types, hide_lams) Suc_diff_1 Suc_lessD \n              cpts_es_dropi diff_diff_cancel drop_0 length_drop length_greater_0_conv \n              less_or_eq_imp_le list.size(3)) \n        from a0 a1 have \"getspc_es (?esl1!0) = EvtSys es\" by auto \n        then obtain s1 and x1 where a3: \"?esl1!0 = (EvtSys es,s1,x1)\" \n          using getspc_es_def by (metis fst_conv old.prod.exhaust)\n        from a2 a1 have \"getspc_es (?esl1!1) = EvtSys es \\<or> (\\<exists>e. getspc_es (?esl1!1) = EvtSeq e (EvtSys es))\"\n          proof(induct ?esl1)\n            case (CptsEsOne es' s' x')\n            then show ?case by (metis One_nat_def Suc_eq_plus1_left Suc_lessD a0 \n                le_add_diff_inverse2 length_Cons length_drop less_imp_le \n                list.size(3) not_less_iff_gr_or_eq)  \n          next\n            case (CptsEsEnv es' t' x' xs' s' y')\n            assume b0: \"(es', s', y') # (es', t', x') # xs' = drop i esl\"\n              and  b1: \"getspc_es (esl ! i) = EvtSys es\"\n            then have \"es' = EvtSys es\" using getspc_es_def by (metis a3 fst_conv nth_Cons_0)\n            with b0 have \"getspc_es (drop i esl ! 1) = EvtSys es\" using getspc_es_def\n              by (metis One_nat_def fst_conv nth_Cons_0 nth_Cons_Suc) \n            then show ?case by simp\n          next\n            case (CptsEsComp es1' s' x' et' es2' t' y' xs')\n            assume b0: \"\\<Gamma> \\<turnstile> (es1', s', x') -es-et'\\<rightarrow> (es2', t', y')\"\n              and  b1: \"(es1', s', x') # (es2', t', y') # xs' = drop i esl\"\n              and  b2: \"getspc_es (esl ! i) = EvtSys es\"\n            then have b3: \"es1' = EvtSys es\" \n              by (metis Pair_inject a3 nth_Cons_0)\n            from b0 b3 have \"\\<exists>e. es2' = EvtSeq e (EvtSys es)\" using evtsys_evtent by simp\n            then obtain e where \"es2' = EvtSeq e (EvtSys es)\" by auto\n            with b1 have \"\\<exists>e. getspc_es (drop i esl ! 1) = EvtSeq e (EvtSys es)\" \n              using getspc_es_def by (metis One_nat_def eq_fst_iff nth_Cons_0 nth_Cons_Suc)\n            then show ?case by simp\n          qed\n\n        then have \"getspc_es (esl!Suc i) = EvtSys es \\<or> (\\<exists>e. getspc_es (esl!Suc i) = EvtSeq e (EvtSys es))\"\n          using a0 by fastforce\n      }\n      then show ?thesis by auto\n      qed\n  qed\n\nlemma evtsys_next_in_cpts_anony:\n  \"esl\\<in>cpts_es \\<Gamma> \\<Longrightarrow> \\<forall>i. Suc i < length esl \\<and> getspc_es (esl!i) = EvtSys es \n                       \\<longrightarrow> getspc_es (esl!Suc i) = EvtSys es \n                        \\<or> (\\<exists>e. getspc_es (esl!Suc i) = EvtSeq e (EvtSys es) \\<and> is_anonyevt e)\"\n  proof -\n    assume p0: \"esl\\<in>cpts_es \\<Gamma>\"\n    then show ?thesis\n      proof -\n      {\n        fix i\n        assume a0: \"Suc i < length esl\"\n          and  a1: \"getspc_es (esl!i) = EvtSys es\"\n        let ?esl1 = \"drop i esl\"\n        from p0 a0 have a2: \"?esl1\\<in>cpts_es \\<Gamma>\" by (metis (no_types, hide_lams) Suc_diff_1 Suc_lessD \n              cpts_es_dropi diff_diff_cancel drop_0 length_drop length_greater_0_conv \n              less_or_eq_imp_le list.size(3)) \n        from a0 a1 have \"getspc_es (?esl1!0) = EvtSys es\" by auto \n        then obtain s1 and x1 where a3: \"?esl1!0 = (EvtSys es,s1,x1)\" \n          using getspc_es_def by (metis fst_conv old.prod.exhaust)\n        from a2 a1 have \"getspc_es (?esl1!1) = EvtSys es \n          \\<or> (\\<exists>e. getspc_es (?esl1!1) = EvtSeq e (EvtSys es) \\<and> is_anonyevt e)\"\n          proof(induct ?esl1)\n            case (CptsEsOne es' s' x')\n            then show ?case by (metis One_nat_def Suc_eq_plus1_left Suc_lessD a0 \n                le_add_diff_inverse2 length_Cons length_drop less_imp_le \n                list.size(3) not_less_iff_gr_or_eq)  \n          next\n            case (CptsEsEnv es' t' x' xs' s' y')\n            assume b0: \"(es', s', y') # (es', t', x') # xs' = drop i esl\"\n              and  b1: \"getspc_es (esl ! i) = EvtSys es\"\n            then have \"es' = EvtSys es\" using getspc_es_def by (metis a3 fst_conv nth_Cons_0)\n            with b0 have \"getspc_es (drop i esl ! 1) = EvtSys es\" using getspc_es_def\n              by (metis One_nat_def fst_conv nth_Cons_0 nth_Cons_Suc) \n            then show ?case by simp\n          next\n            case (CptsEsComp es1' s' x' et' es2' t' y' xs')\n            assume b0: \"\\<Gamma> \\<turnstile> (es1', s', x') -es-et'\\<rightarrow> (es2', t', y')\"\n              and  b1: \"(es1', s', x') # (es2', t', y') # xs' = drop i esl\"\n              and  b2: \"getspc_es (esl ! i) = EvtSys es\"\n            then have b3: \"es1' = EvtSys es\" \n              by (metis Pair_inject a3 nth_Cons_0)\n            from b0 b3 have \"\\<exists>e. es2' = EvtSeq e (EvtSys es)\" using evtsys_evtent by simp\n            then obtain e where \"es2' = EvtSeq e (EvtSys es)\" by auto\n            with b0 b1 b3 have \"\\<exists>e. getspc_es (drop i esl ! 1) = EvtSeq e (EvtSys es) \\<and> is_anonyevt e\"\n              using getspc_es_def  by (metis One_nat_def ent_spec2' evtsysent_evtent0 \n                fst_conv is_anonyevt.simps(1) noevtent_notran nth_Cons_0 nth_Cons_Suc) \n              \n            then show ?case by simp\n          qed\n\n        then have \"getspc_es (esl!Suc i) = EvtSys es \n            \\<or> (\\<exists>e. getspc_es (esl!Suc i) = EvtSeq e (EvtSys es) \\<and> is_anonyevt e)\"\n          using a0 by fastforce\n      }\n      then show ?thesis by auto\n      qed\n  qed\n\nlemma evtsys_all_es_in_cpts:\n  \"\\<lbrakk>esl\\<in>cpts_es \\<Gamma>; length esl > 0; getspc_es (esl!0) = EvtSys es \\<rbrakk> \\<Longrightarrow>\n        \\<forall>i. i < length esl \\<longrightarrow> getspc_es (esl!i) = EvtSys es \\<or> (\\<exists>e. getspc_es (esl!i) = EvtSeq e (EvtSys es))\"\n  proof -\n    assume p0: \"esl\\<in>cpts_es \\<Gamma>\"\n      and  p1: \"length esl > 0\"\n      and  p2: \"getspc_es (esl!0) = EvtSys es\"\n    show ?thesis\n      proof -\n      {\n        fix i\n        assume a0: \"i < length esl\"\n        then have \"getspc_es (esl!i) = EvtSys es \\<or> (\\<exists>e. getspc_es (esl!i) = EvtSeq e (EvtSys es))\"\n          proof(induct i)\n            case 0 from p2 show ?case by simp\n          next\n            case (Suc j)\n            assume b0: \"j < length esl \\<Longrightarrow> \n                        getspc_es (esl ! j) = EvtSys es \\<or> (\\<exists>e. getspc_es (esl ! j) = EvtSeq e (EvtSys es))\"\n              and  b1: \"Suc j < length esl\"\n            then have \"getspc_es (esl ! j) = EvtSys es \\<or> (\\<exists>e. getspc_es (esl ! j) = EvtSeq e (EvtSys es))\"\n              by simp\n            then show ?case\n              proof \n                assume c0: \"getspc_es (esl ! j) = EvtSys es\"\n                with p0 b1 show ?thesis using evtsys_next_in_cpts by auto\n              next\n                assume c0: \"\\<exists>e. getspc_es (esl ! j) = EvtSeq e (EvtSys es)\"\n                with p0 b1 show ?thesis using evtseq_next_in_cpts by blast\n              qed\n          qed\n      }\n      then show ?thesis by auto\n      qed\n  qed\n\nlemma evtsys_all_es_in_cpts_anony:\n  \"\\<lbrakk>esl\\<in>cpts_es \\<Gamma>; length esl > 0; getspc_es (esl!0) = EvtSys es \\<rbrakk> \\<Longrightarrow>\n        \\<forall>i. i < length esl \\<longrightarrow> getspc_es (esl!i) = EvtSys es \n            \\<or> (\\<exists>e. getspc_es (esl!i) = EvtSeq e (EvtSys es) \\<and> is_anonyevt e)\"\n  proof -\n    assume p0: \"esl\\<in>cpts_es \\<Gamma>\"\n      and  p1: \"length esl > 0\"\n      and  p2: \"getspc_es (esl!0) = EvtSys es\"\n    show ?thesis\n      proof -\n      {\n        fix i\n        assume a0: \"i < length esl\"\n        then have \"getspc_es (esl!i) = EvtSys es \\<or> (\\<exists>e. getspc_es (esl!i) = EvtSeq e (EvtSys es) \\<and> is_anonyevt e)\"\n          proof(induct i)\n            case 0 from p2 show ?case by simp\n          next\n            case (Suc j)\n            assume b0: \"j < length esl \\<Longrightarrow> \n                        getspc_es (esl ! j) = EvtSys es \n                        \\<or> (\\<exists>e. getspc_es (esl ! j) = EvtSeq e (EvtSys es) \\<and> is_anonyevt e)\"\n              and  b1: \"Suc j < length esl\"\n            then have \"getspc_es (esl ! j) = EvtSys es \n                    \\<or> (\\<exists>e. getspc_es (esl ! j) = EvtSeq e (EvtSys es) \\<and> is_anonyevt e)\"\n              by simp\n            then show ?case\n              proof \n                assume c0: \"getspc_es (esl ! j) = EvtSys es\"\n                with p0 b1 show ?thesis using evtsys_next_in_cpts_anony by auto\n              next\n                assume c0: \"\\<exists>e. getspc_es (esl ! j) = EvtSeq e (EvtSys es) \\<and> is_anonyevt e\"\n                with p0 b1 show ?thesis using evtseq_next_in_cpts_anony by blast\n              qed\n          qed\n      }\n      then show ?thesis by auto\n      qed\n  qed\n\nlemma not_anonyevt_none_in_evtseq:\n    \"\\<lbrakk>esl\\<in>cpts_es \\<Gamma>; esl = (EvtSeq e es,s1,x1)#(es,s2,x2)#xs \\<rbrakk> \\<Longrightarrow> e \\<noteq> AnonyEvent fin_com\"\n  apply(rule cpts_es.cases)\n  apply(simp)+\n  apply (metis Suc_eq_plus1 add.commute add.right_neutral esys.size(3) le_add1 lessI not_le) \n  apply(rule estran.cases)\n  apply(simp)+\n  apply (metis Suc_eq_plus1 add.commute add.right_neutral esys.size(3) le_add1 lessI not_le)\n  apply(rule etran.cases)\n  apply(simp)+\n  prefer 2\n  apply(simp) using ptran_not_none apply auto[1]\n  done\n\nlemma not_anonyevt_none_in_evtseq1:\n    \"\\<lbrakk>esl\\<in>cpts_es \\<Gamma>; length esl > 1; getspc_es (esl!0) = EvtSeq e es;\n      getspc_es (esl!1) = es \\<rbrakk> \\<Longrightarrow> e \\<noteq> AnonyEvent fin_com\"\n  using getspc_es_def not_anonyevt_none_in_evtseq\n    by (metis (no_types, hide_lams) Cons_nth_drop_Suc drop_0 eq_fst_iff less_Suc_eq less_Suc_eq_0_disj less_one)\n\nlemma fst_esys_snd_eseq_exist_evtent:\n    \"\\<lbrakk>esl\\<in>cpts_es \\<Gamma>; esl = (EvtSys es, s, x) # (EvtSeq ev (EvtSys es), s1,x1) # xs\\<rbrakk> \\<Longrightarrow>\n          \\<exists>t. \\<Gamma> \\<turnstile> (EvtSys es, s, x) -es-t\\<rightarrow> (EvtSeq ev (EvtSys es), s1,x1)\"\n  apply(rule cpts_es.cases)\n  apply(simp)+\n  apply blast\n  by blast\n\nlemma fst_esys_snd_eseq_exist_evtent2:\n    \"\\<lbrakk>esl\\<in>cpts_es \\<Gamma>; esl = (EvtSys es, s, x) # (EvtSeq ev (EvtSys es), s1,x1) # xs\\<rbrakk> \\<Longrightarrow>\n          \\<exists>e k. \\<Gamma> \\<turnstile> (EvtSys es, s, x) -es-(EvtEnt (BasicEvent e))\\<sharp>k\\<rightarrow> (EvtSeq ev (EvtSys es), s1,x1)\"\n  apply(rule cpts_es.cases)\n  apply(simp)+\n  apply blast\n  by (metis (no_types, hide_lams) cmd_enable_impl_notesys2 estran_impl_evtentorcmd \n    evtent_is_basicevt fst_conv getspc_es_def nth_Cons_0 nth_Cons_Suc)\n\n  \nlemma fst_esys_snd_eseq_exist: \n  \"\\<lbrakk>esl\\<in>cpts_es \\<Gamma>; length esl \\<ge> 2 \\<and> getspc_es (esl!0) = EvtSys es \\<and> getspc_es (esl!1) \\<noteq> EvtSys es\\<rbrakk>\n    \\<Longrightarrow> \\<exists>s x ev s1 x1 xs. esl = (EvtSys es, s, x) # (EvtSeq ev (EvtSys es), s1,x1) # xs\"\n  proof -\n    assume a0: \"length esl \\<ge> 2 \\<and> getspc_es (esl!0) = EvtSys es \\<and> getspc_es (esl!1) \\<noteq> EvtSys es\"\n      and  c1: \"esl\\<in>cpts_es \\<Gamma>\"\n    from a0 have b0: \"getspc_es (esl!0) = EvtSys es \\<and> getspc_es (esl!1) \\<noteq> EvtSys es\"\n      by (metis (no_types, lifting))\n    \n    from a0 have b1: \"2 \\<le> length esl\" by fastforce \n    moreover from b0 b1 have \"\\<exists>s x. esl!0 = (EvtSys es, s, x)\" using getspc_es_def\n      by (metis eq_fst_iff) \n    moreover have \"\\<exists>ev s1 x1. esl!1 = (EvtSeq ev (EvtSys es), s1,x1)\" using getspc_es_def\n      proof -\n        from c1 a0 b0 have \"\\<exists>ev. getspc_es (esl!1) = EvtSeq ev (EvtSys es)\" \n           by (metis One_nat_def Suc_1 Suc_le_lessD evtsys_next_in_cpts) \n        then show ?thesis using getspc_es_def by (metis fst_conv surj_pair) \n      qed\n    ultimately show ?thesis by (metis (no_types, hide_lams) One_nat_def Suc_1 \n      Suc_n_not_le_n diff_is_0_eq hd_Cons_tl hd_conv_nth length_tl \n      list.size(3) not_numeral_le_zero nth_Cons_Suc order_trans) \n  qed\n\n  \nlemma notevtent_cptses_isenvorcmd: \n  \"\\<lbrakk>esl\\<in>cpts_es \\<Gamma>; length esl \\<ge> 2; \\<not> (\\<exists>e k. \\<Gamma> \\<turnstile> esl ! 0 -es-EvtEnt e\\<sharp>k\\<rightarrow> esl ! 1)\\<rbrakk> \n    \\<Longrightarrow> \\<Gamma> \\<turnstile> esl ! 0 -ese\\<rightarrow> esl ! 1 \\<or> (\\<exists>c k. \\<Gamma> \\<turnstile> esl ! 0 -es-Cmd c\\<sharp>k\\<rightarrow> esl ! 1)\"\n  apply(rule cpts_es.cases)\n  apply simp+\n  apply (simp add: esetran.intros)\n  using estran_impl_evtentorcmd2\n  by (metis One_nat_def nth_Cons_0 nth_Cons_Suc) \n \nlemma only_envtran_to_basicevt:\n  \"esl\\<in>cpts_es \\<Gamma> \\<Longrightarrow> \\<forall>i. Suc i < length esl \\<and> (\\<exists>e. getspc_es (esl!i) = EvtSeq e esys) \n                      \\<and> getspc_es (esl!Suc i) = EvtSeq (BasicEvent e) esys\n                        \\<longrightarrow> getspc_es (esl!i) = EvtSeq (BasicEvent e) esys\"\n  proof -\n    assume p0: \"esl\\<in>cpts_es \\<Gamma>\"\n    then show ?thesis\n      proof -\n      {\n        fix i\n        assume a0: \"Suc i < length esl\"\n          and  a1: \"getspc_es (esl!Suc i) = EvtSeq (BasicEvent e) esys\"\n          and  a00: \"\\<exists>e. getspc_es (esl!i) = EvtSeq e esys\"\n        let ?esl1 = \"drop i esl\"\n        from p0 a0 have a2: \"?esl1\\<in>cpts_es \\<Gamma>\" by (metis (no_types, hide_lams) Suc_diff_1 Suc_lessD \n              cpts_es_dropi diff_diff_cancel drop_0 length_drop length_greater_0_conv \n              less_or_eq_imp_le list.size(3)) \n        from a0 a1 have \"getspc_es (?esl1!1) = EvtSeq (BasicEvent e) esys\" by auto \n        then obtain s1 and x1 where a3: \"?esl1!1 = (EvtSeq (BasicEvent e) esys,s1,x1)\" \n          using getspc_es_def by (metis fst_conv old.prod.exhaust)\n        from a2 a1 have \"getspc_es (?esl1!0) = EvtSeq (BasicEvent e) esys\"\n          proof(induct ?esl1)\n            case (CptsEsOne es' s' x')\n            then show ?case by (metis One_nat_def Suc_eq_plus1_left Suc_lessD a0 \n                le_add_diff_inverse2 length_Cons length_drop less_imp_le \n                list.size(3) not_less_iff_gr_or_eq)  \n          next\n            case (CptsEsEnv es' t' x' xs' s' y')\n            assume b0: \"(es', s', y') # (es', t', x') # xs' = drop i esl\"\n              and  b1: \"getspc_es (esl ! Suc i) = EvtSeq (BasicEvent e) esys\"\n            then have \"es' = EvtSeq (BasicEvent e) esys\" \n              by (metis One_nat_def a3 nth_Cons_0 nth_Cons_Suc prod.inject) \n            with b0 show ?case using getspc_es_def by (metis fst_conv nth_Cons_0) \n          next\n            case (CptsEsComp es1' s' x' et' es2' t' y' xs')\n            assume b0: \"\\<Gamma> \\<turnstile> (es1', s', x') -es-et'\\<rightarrow> (es2', t', y')\"\n              and  b1: \"(es1', s', x') # (es2', t', y') # xs' = drop i esl\"\n              and  b2: \"getspc_es (esl ! Suc i) = EvtSeq (BasicEvent e) esys\"\n            then have b3: \"es2' = EvtSeq (BasicEvent e) esys\"\n              by (metis One_nat_def Pair_inject a3 nth_Cons_0 nth_Cons_Suc) \n            from a00 obtain e' where b4: \"getspc_es (esl ! i) = EvtSeq e' esys\" by auto\n            then have \"es1' = EvtSeq e' esys\"\n              by (metis (no_types, lifting) CptsEsComp.hyps(4) fst_conv getspc_es_def nth_via_drop) \n            with b0 b3 have \"\\<not> (\\<exists>e. es2' = EvtSeq (BasicEvent e) esys)\" \n              using notrans_to_basicevt_insameesys[of \\<Gamma> es1' s' x' et' es2' t' y' esys] by auto\n            with b3 show ?case by blast\n          qed\n      }\n      then show ?thesis by auto\n      qed\n  qed\n\nlemma incpts_es_impl_evnorcomptran:\n  \"esl\\<in>cpts_es \\<Gamma> \\<Longrightarrow> \\<forall>i. Suc i < length esl \\<longrightarrow> \\<Gamma> \\<turnstile> esl ! i -ese\\<rightarrow> esl ! Suc i \\<or> (\\<exists>et. \\<Gamma> \\<turnstile> esl ! i -es-et\\<rightarrow> esl ! Suc i)\" \n  proof -\n    assume p0: \"esl\\<in>cpts_es \\<Gamma>\"\n    {\n      fix i\n      assume a0: \"Suc i < length esl\"\n      let ?esl1 = \"take 2 (drop i esl)\"\n      from a0 p0 have \"take (Suc (Suc i) - i) (drop i esl) \\<in> cpts_es \\<Gamma>\" \n        using cpts_es_seg[of esl \\<Gamma> i \"Suc (Suc i)\"] by simp\n      then have \"?esl1 \\<in> cpts_es \\<Gamma>\" by auto\n      moreover\n      from a0 obtain esc1 and s1 and x1 where a1: \"esl ! i = (esc1,s1,x1)\"\n        using prod_cases3 by blast  \n      moreover\n      from a0 obtain esc2 and s2 and x2 where a2: \"esl ! Suc i = (esc2,s2,x2)\"\n        using prod_cases3 by blast  \n      moreover\n      from a0 have \"esl ! i = ?esl1 ! 0\" by (simp add: Cons_nth_drop_Suc Suc_lessD) \n      moreover\n      from a0 have \"esl ! Suc i = ?esl1 ! 1\" by (simp add: Cons_nth_drop_Suc Suc_lessD) \n      ultimately have \"(esc1, s1, x1)#[(esc2, s2, x2)] \\<in> cpts_es \\<Gamma>\" \n        by (metis Cons_nth_drop_Suc Suc_lessD a0 numeral_2_eq_2 take_0 take_Suc_Cons)\n      then have \"\\<Gamma> \\<turnstile> (esc1, s1, x1) -ese\\<rightarrow> (esc2, s2, x2) \\<or> (\\<exists>et. \\<Gamma> \\<turnstile> (esc1, s1, x1) -es-et\\<rightarrow> (esc2, s2, x2))\"\n        apply(rule cpts_es.cases)\n        apply simp+\n        apply (simp add: esetran.intros)\n        by auto\n      with a1 a2 have \"\\<Gamma> \\<turnstile> esl ! i -ese\\<rightarrow> esl ! Suc i \\<or> (\\<exists>et. \\<Gamma> \\<turnstile> esl ! i -es-et\\<rightarrow> esl ! Suc i)\" by simp\n    }\n    then show ?thesis by auto\n  qed\n\nlemma incpts_es_eseq_not_evtent:\n  \"\\<lbrakk>esl\\<in>cpts_es \\<Gamma>; Suc i < length esl; \\<exists>e esys. getspc_es (esl!i) = EvtSeq e esys \\<and> is_anonyevt e\\<rbrakk> \n    \\<Longrightarrow> \\<not>(\\<exists>e k. t = EvtEnt e \\<and> \\<Gamma> \\<turnstile> esl!i -es-t\\<sharp>k\\<rightarrow> esl!Suc i)\"\n  proof -\n    assume p0: \"esl\\<in>cpts_es \\<Gamma>\"\n      and  a0: \"Suc i < length esl\"\n      and  a1: \"\\<exists>e esys. getspc_es (esl!i) = EvtSeq e esys \\<and> is_anonyevt e\"\n    let ?esl1 = \"drop i esl\"\n    from p0 a0 have a2: \"?esl1\\<in>cpts_es \\<Gamma>\" by (metis (no_types, hide_lams) Suc_diff_1 Suc_lessD \n          cpts_es_dropi diff_diff_cancel drop_0 length_drop length_greater_0_conv \n          less_or_eq_imp_le list.size(3)) \n    from a0 a1 obtain e and esys where a3: \"getspc_es (?esl1!0) = EvtSeq e esys\" by auto \n    then obtain s1 and x1 where a4: \"?esl1!0 = (EvtSeq e esys,s1,x1)\" \n      using getspc_es_def by (metis fst_conv old.prod.exhaust)\n    from a2 a3 have \"\\<not>(\\<exists>e k. t = EvtEnt e \\<and> \\<Gamma> \\<turnstile> ?esl1!0 -es-t\\<sharp>k\\<rightarrow> ?esl1!1)\"\n      proof(induct ?esl1)\n          case (CptsEsOne es' s' x')\n          then show ?case by (metis One_nat_def Suc_eq_plus1_left Suc_lessD a0 \n              le_add_diff_inverse2 length_Cons length_drop less_imp_le \n              list.size(3) not_less_iff_gr_or_eq)  \n        next\n          case (CptsEsEnv es' t' x' xs' s' y')\n          assume b0: \"(es', s', y') # (es', t', x') # xs' = ?esl1\"\n            and  b1: \"getspc_es (?esl1 ! 0) = EvtSeq e esys\"\n          then have \"es' = EvtSeq e esys\"\n            by (metis Pair_inject a4 nth_Cons_0)  \n          with b0 show ?case using getspc_es_def\n            by (metis (mono_tags, lifting) a1 evtseq_no_evtent2 nth_Cons_0 nth_via_drop) \n        next\n          case (CptsEsComp es1' s' x' et' es2' t' y' xs')\n          assume b0: \"\\<Gamma> \\<turnstile> (es1', s', x') -es-et'\\<rightarrow> (es2', t', y')\"\n            and  b1: \"(es1', s', x') # (es2', t', y') # xs' = drop i esl\"\n            and  b2: \"getspc_es (?esl1 ! 0) = EvtSeq e esys\"\n          then have b3: \"es1' = EvtSeq e esys\"\n             by (metis Pair_inject a4 nth_Cons_0)\n          with b0 b1 show ?case using getspc_es_def\n            by (metis (no_types, lifting) a1 evtseq_no_evtent2 nth_Cons_0 nth_via_drop) \n        qed\n        \n    with a0 show ?thesis by (simp add: Cons_nth_drop_Suc Suc_lessD) \n  qed\n\nlemma evtsys_not_eq_in_tran_aux:\"\\<Gamma> \\<turnstile> (P,s,x) -es-est\\<rightarrow> (Q,t,y) \\<Longrightarrow> P \\<noteq> Q\"\n  apply(erule estran.cases)\n  apply (simp add: evt_not_eq_in_tran_aux)\n  apply (simp add: evt_not_eq_in_tran_aux)\n  by (simp add: evtseq_ne_es)\n\nlemma evtsys_not_eq_in_tran_aux1:\"\\<Gamma> \\<turnstile> esc1 -es-est\\<rightarrow> esc2 \\<Longrightarrow> getspc_es esc1 \\<noteq> getspc_es esc2\"\n  proof -\n    assume p0: \"\\<Gamma> \\<turnstile> esc1 -es-est\\<rightarrow> esc2\"\n    obtain es1 and s1 and x1 and es2 and s2 and x2 where a0: \"esc1 = (es1,s1,x1) \\<and> esc2 = (es2,s2,x2)\"\n      by (metis prod.collapse)\n    with p0 have \"es1 \\<noteq> es2\" using evtsys_not_eq_in_tran_aux by simp\n    with a0 show ?thesis by (simp add:getspc_es_def)\n  qed\n\nlemma evtsys_not_eq_in_tran [simp]: \"\\<not> \\<Gamma> \\<turnstile> (P,s,x) -es-est\\<rightarrow> (P,t,y)\"\n  apply clarify\n  apply(drule evtsys_not_eq_in_tran_aux)\n  apply simp\n  done\n\nlemma evtsys_not_eq_in_tran2 [simp]: \"\\<not>(\\<exists>est. \\<Gamma> \\<turnstile> (P,s,x) -es-est\\<rightarrow> (P,t,y))\" by simp\n\nlemma es_tran_not_etran2: \"\\<Gamma> \\<turnstile> (P,s,x) -es-pt\\<rightarrow> (Q,t,y) \\<Longrightarrow> \\<not>(\\<Gamma> \\<turnstile> (P,s,x) -ese\\<rightarrow>(Q,t,y))\"\n  by (metis esetran.cases evtsys_not_eq_in_tran_aux)\n\nlemma es_tran_not_etran1: \"\\<Gamma> \\<turnstile> esc1 -es-pt\\<rightarrow> esc2 \\<Longrightarrow> \\<not>(\\<Gamma> \\<turnstile> esc1 -ese\\<rightarrow>esc2)\"\n  using esetran_eqconf1 evtsys_not_eq_in_tran_aux1 by blast\n\nsubsubsection \\<open>Parallel event systems\\<close>\n\nlemma cpts_pes_not_empty [simp]:\"[] \\<notin> cpts_pes \\<Gamma>\"\napply(force elim:cpts_pes.cases)\ndone\n\nlemma pesetran_eqconf: \"\\<Gamma> \\<turnstile> (es1, s1, x1) -pese\\<rightarrow> (es2, s2, x2) \\<Longrightarrow> es1 = es2\"\n  apply(rule pesetran.cases)\n  apply(simp)+\n  done\n\nlemma pesetran_eqconf1: \"\\<Gamma> \\<turnstile> esc1 -pese\\<rightarrow> esc2 \\<Longrightarrow> getspc esc1 = getspc esc2\"\n  proof -\n    assume a0: \"\\<Gamma> \\<turnstile> esc1 -pese\\<rightarrow> esc2\"\n    then obtain es1 and s1 and x1 and es2 and s2 and x2 where a1: \"esc1 = (es1, s1, x1)\" and a2: \"esc2 = (es2, s2, x2)\"\n      by (meson prod_cases3) \n    then have \"es1 = es2\" using a0 pesetran_eqconf by fastforce \n    with a1 show ?thesis by (simp add: a2 getspc_def) \n  qed\n\nlemma eqconf_pesetran1: \"es1 = es2 \\<Longrightarrow> \\<Gamma> \\<turnstile> (es1, s1, x1) -pese\\<rightarrow> (es2, s2, x2)\"\n  by (simp add: pesetran.intros) \n\n\nlemma eqconf_pesetran: \"getspc esc1 = getspc esc2 \\<Longrightarrow> \\<Gamma> \\<turnstile> esc1 -pese\\<rightarrow> esc2\" \n  proof -\n    assume a0: \"getspc esc1 = getspc esc2\"\n    obtain es1 and s1 and x1 where a1: \"esc1 = (es1, s1, x1)\" using prod_cases3 by blast \n    obtain es2 and s2 and x2 where a2: \"esc2 = (es2, s2, x2)\" using prod_cases3 by blast \n    with a0 a1 have \"es1 = es2\" by (simp add:getspc_def)\n    with a1 a2 have a3: \"\\<Gamma> \\<turnstile> (es1, s1, x1) -pese\\<rightarrow> (es2, s2, x2)\" by (simp add:eqconf_pesetran1)\n    from a3 a1 a2 show ?thesis by simp\n  qed\n\nlemma pestran_cpts_pes: \"\\<lbrakk>\\<Gamma> \\<turnstile> C1 -pes-ct\\<rightarrow> C2; C2#xs \\<in> cpts_pes \\<Gamma>\\<rbrakk> \\<Longrightarrow> C1#C2#xs \\<in> cpts_pes \\<Gamma>\"\n  proof -\n    assume p0: \"\\<Gamma> \\<turnstile> C1 -pes-ct\\<rightarrow> C2\"\n      and  p1: \"C2#xs \\<in> cpts_pes \\<Gamma>\"\n    moreover\n    obtain pes1 and s1 and x1 where \"C1 = (pes1,s1,x1)\"\n      using prod_cases3 by blast \n    moreover\n    obtain pes2 and s2 and x2 where \"C2 = (pes2,s2,x2)\" \n      using prod_cases3 by blast \n    ultimately show ?thesis by (simp add: cpts_pes.CptsPesComp) \n  qed\n\nlemma cpts_pes_onemore: \"\\<lbrakk>el \\<in> cpts_pes \\<Gamma>; (\\<Gamma> \\<turnstile> el ! (length el - 1) -pes-t\\<rightarrow> ec) \\<or> (\\<Gamma> \\<turnstile> el ! (length el - 1) -pese\\<rightarrow> ec)\\<rbrakk> \\<Longrightarrow>\n                          el @ [ec] \\<in> cpts_pes \\<Gamma>\"\n  proof -\n    assume p0: \"el \\<in> cpts_pes \\<Gamma>\"\n      and  p2: \"(\\<Gamma> \\<turnstile> el ! (length el - 1) -pes-t\\<rightarrow> ec) \\<or> (\\<Gamma> \\<turnstile> el ! (length el - 1) -pese\\<rightarrow> ec)\"\n    from p0 have p1: \"el \\<noteq> []\"\n      using cpts_pes.simps by blast\n    have \"\\<forall>el ec t. el \\<in> cpts_pes \\<Gamma> \\<and> ((\\<Gamma> \\<turnstile> el ! (length el - 1) -pes-t\\<rightarrow> ec) \\<or> (\\<Gamma> \\<turnstile> el ! (length el - 1) -pese\\<rightarrow> ec)) \n      \\<longrightarrow> el @ [ec] \\<in> cpts_pes \\<Gamma>\"\n      proof -\n      {\n        fix el ec t\n        assume a0: \"el \\<in> cpts_pes \\<Gamma>\"\n          and  a2: \"(\\<Gamma> \\<turnstile> el ! (length el - 1) -pes-t\\<rightarrow> ec) \\<or> (\\<Gamma> \\<turnstile> el ! (length el - 1) -pese\\<rightarrow> ec)\"\n        then have a1: \"length el > 0\"\n          using cpts_pes.simps by blast\n        from a0 a1 a2 have \"el @ [ec] \\<in> cpts_pes \\<Gamma>\"\n          proof(induct el)\n            case (CptsPesOne e s x) \n            assume b0: \"(\\<Gamma> \\<turnstile> [(e, s, x)] ! (length [(e, s, x)] - 1) -pes-t\\<rightarrow> ec) \n                          \\<or> \\<Gamma> \\<turnstile> [(e, s, x)] ! (length [(e, s, x)] - 1) -pese\\<rightarrow> ec\"\n            then have \"(\\<Gamma> \\<turnstile> (e, s, x) -pes-t\\<rightarrow> ec) \\<or> (\\<Gamma> \\<turnstile> (e, s, x) -pese\\<rightarrow> ec)\" by simp\n            then show ?case  \n              proof\n                assume \"\\<Gamma> \\<turnstile> (e, s, x) -pes-t\\<rightarrow> ec\"\n                then show ?thesis by (metis append_Cons append_Nil \n                    cpts_pes.CptsPesComp cpts_pes.CptsPesOne surj_pair)\n              next\n                assume \"\\<Gamma> \\<turnstile> (e, s, x) -pese\\<rightarrow> ec\"\n                then show ?thesis\n                  by (metis append_Cons append_Nil cpts_pes.CptsPesEnv \n                      cpts_pes.CptsPesOne pesetranE surj_pair) \n              qed\n          next\n            case (CptsPesEnv e s1 x xs s2 y)\n            assume b0: \"(e, s1, x) # xs \\<in> cpts_pes \\<Gamma>\"\n              and  b1: \"0 < length ((e, s1, x) # xs) \\<Longrightarrow>\n                          (\\<Gamma> \\<turnstile> ((e, s1, x) # xs) ! (length ((e, s1, x) # xs) - 1) -pes-t\\<rightarrow> ec) \\<or>\n                          (\\<Gamma> \\<turnstile> ((e, s1, x) # xs) ! (length ((e, s1, x) # xs) - 1) -pese\\<rightarrow> ec) \\<Longrightarrow>\n                          ((e, s1, x) # xs) @ [ec] \\<in> cpts_pes \\<Gamma>\"\n              and  b2: \"0 < length ((e, s2, y) # (e, s1, x) # xs)\"\n              and  b3: \"(\\<Gamma> \\<turnstile> ((e, s2, y) # (e, s1, x) # xs) ! (length ((e, s2, y) # (e, s1, x) # xs) - 1) -pes-t\\<rightarrow> ec) \\<or>\n                        (\\<Gamma> \\<turnstile> ((e, s2, y) # (e, s1, x) # xs) ! (length ((e, s2, y) # (e, s1, x) # xs) - 1) -pese\\<rightarrow> ec)\"\n            then show ?case \n              proof(cases \"xs = []\")\n                assume c0: \"xs = []\"\n                with b3 have \"(\\<Gamma> \\<turnstile> (e, s1, x) -pes-t\\<rightarrow> ec) \\<or> (\\<Gamma> \\<turnstile> (e, s1, x) -pese\\<rightarrow> ec)\" by simp\n                with b1 c0 have \"((e, s1, x) # xs) @ [ec] \\<in> cpts_pes \\<Gamma>\" by simp\n                then show ?thesis by (simp add: cpts_pes.CptsPesEnv) \n              next\n                assume c0: \"xs \\<noteq> []\"\n                with b3 have \"(\\<Gamma> \\<turnstile> last xs -pes-t\\<rightarrow> ec) \\<or> (\\<Gamma> \\<turnstile> last xs -pese\\<rightarrow> ec)\" by (simp add: last_conv_nth) \n                with b1 c0 have \"((e, s1, x) # xs) @ [ec] \\<in> cpts_pes \\<Gamma>\" using b3 by auto\n                then show ?thesis by (simp add: cpts_pes.CptsPesEnv) \n              qed\n          next\n            case (CptsPesComp e1 s1 x1 et e2 t1 y1 xs1)\n            assume b0: \"\\<Gamma> \\<turnstile> (e1, s1, x1) -pes-et\\<rightarrow> (e2, t1, y1)\"\n              and  b1: \"(e2, t1, y1) # xs1 \\<in> cpts_pes \\<Gamma>\"\n              and  b2: \"0 < length ((e2, t1, y1) # xs1) \\<Longrightarrow>\n                        (\\<Gamma> \\<turnstile> ((e2, t1, y1) # xs1) ! (length ((e2, t1, y1) # xs1) - 1) -pes-t\\<rightarrow> ec) \\<or>\n                        (\\<Gamma> \\<turnstile> ((e2, t1, y1) # xs1) ! (length ((e2, t1, y1) # xs1) - 1) -pese\\<rightarrow> ec) \\<Longrightarrow>\n                        ((e2, t1, y1) # xs1) @ [ec] \\<in> cpts_pes \\<Gamma>\"\n              and  b3: \"0 < length ((e1, s1, x1) # (e2, t1, y1) # xs1)\"\n              and  b4: \"(\\<Gamma> \\<turnstile> ((e1, s1, x1) # (e2, t1, y1) # xs1) ! (length ((e1, s1, x1) # (e2, t1, y1) # xs1) - 1) -pes-t\\<rightarrow> ec) \\<or>\n                        \\<Gamma> \\<turnstile> ((e1, s1, x1) # (e2, t1, y1) # xs1) ! (length ((e1, s1, x1) # (e2, t1, y1) # xs1) - 1) -pese\\<rightarrow> ec\"\n            then show ?case \n              proof(cases \"xs1 = []\")\n                assume c0: \"xs1 = []\"\n                with b4 have \"(\\<Gamma> \\<turnstile> (e2, t1, y1) -pes-t\\<rightarrow> ec) \\<or> (\\<Gamma> \\<turnstile> (e2, t1, y1) -pese\\<rightarrow> ec)\" by simp\n                with b2 c0 have \"((e2, t1, y1) # xs1) @ [ec] \\<in> cpts_pes \\<Gamma>\" by simp\n                with b0 show ?thesis using cpts_pes.CptsPesComp by fastforce \n              next\n                assume c0: \"xs1 \\<noteq> []\"\n                with b4 have \"(\\<Gamma> \\<turnstile> last xs1 -pes-t\\<rightarrow> ec) \\<or> (\\<Gamma> \\<turnstile> last xs1 -pese\\<rightarrow> ec)\" by (simp add: last_conv_nth)\n                with b2 c0 have \"((e2, t1, y1) # xs1) @ [ec] \\<in> cpts_pes \\<Gamma>\" using b4 by auto \n                then show ?thesis using b0 cpts_pes.CptsPesComp by fastforce \n              qed\n          qed\n      }\n      then show ?thesis by blast\n      qed\n\n    then show \"el @ [ec] \\<in> cpts_pes \\<Gamma>\" using p0 p1 p2 by blast \n  qed\n\nlemma pes_not_eq_in_tran_aux:\"\\<Gamma> \\<turnstile> (P,s,x) -pes-est\\<rightarrow> (Q,t,y) \\<Longrightarrow> P \\<noteq> Q\"\n  apply(erule pestran.cases)\n  by (metis Pair_inject evtsys_not_eq_in_tran fun_upd_same)\n  \nlemma pes_not_eq_in_tran [simp]: \"\\<not> \\<Gamma> \\<turnstile> (P,s,x) -pes-est\\<rightarrow> (P,t,y)\"\n  apply clarify\n  apply(drule pes_not_eq_in_tran_aux)\n  apply simp\n  done\n\nlemma pes_tran_not_etran1: \"\\<Gamma> \\<turnstile> pes1 -pes-t\\<rightarrow> pes2 \\<Longrightarrow> \\<not>(\\<Gamma> \\<turnstile> pes1 -pese\\<rightarrow>pes2)\"\n  by (metis pes_not_eq_in_tran pesetranE surj_pair)\n\nlemma pes_tran_not_etran2: \"\\<Gamma> \\<turnstile> (P,s,x) -pes-pt\\<rightarrow> (Q,t,y) \\<Longrightarrow> \\<not>(\\<Gamma> \\<turnstile> (P,s,x) -pese\\<rightarrow>(Q,t,y))\"\n  by (simp add: pes_tran_not_etran1)\n  \nlemma incpts_pes_impl_evnorcomptran:\n  \"esl\\<in>cpts_pes \\<Gamma> \\<Longrightarrow> \\<forall>i. Suc i < length esl \\<longrightarrow> \\<Gamma> \\<turnstile> esl ! i -pese\\<rightarrow> esl ! Suc i \\<or> (\\<exists>et. \\<Gamma> \\<turnstile> esl ! i -pes-et\\<rightarrow> esl ! Suc i)\" \n  proof -\n    assume p0: \"esl\\<in>cpts_pes \\<Gamma>\"\n    then show ?thesis\n      proof(induct esl)\n        case (CptsPesOne) show ?case by simp\n      next\n        case (CptsPesEnv pes t x xs s y)\n        assume a0: \"(pes, t, x) # xs \\<in> cpts_pes \\<Gamma>\"\n          and  a1: \"\\<forall>i. Suc i < length ((pes, t, x) # xs) \\<longrightarrow>\n                      \\<Gamma> \\<turnstile> ((pes, t, x) # xs) ! i -pese\\<rightarrow> ((pes, t, x) # xs) ! Suc i \\<or>\n                      (\\<exists>et. \\<Gamma> \\<turnstile> ((pes, t, x) # xs) ! i -pes-et\\<rightarrow> ((pes, t, x) # xs) ! Suc i)\"\n        then show ?case \n          proof -\n          {\n            fix i\n            assume b0: \"Suc i < length ((pes, s, y) # (pes, t, x) # xs)\"\n            have \"\\<Gamma> \\<turnstile> ((pes, s, y) # (pes, t, x) # xs) ! i -pese\\<rightarrow> ((pes, s, y) # (pes, t, x) # xs) ! Suc i \\<or>\n                  (\\<exists>et. \\<Gamma> \\<turnstile> ((pes, s, y) # (pes, t, x) # xs) ! i -pes-et\\<rightarrow> ((pes, s, y) # (pes, t, x) # xs) ! Suc i)\"\n              proof(cases \"i = 0\")\n                assume c0: \"i = 0\"\n                then show ?thesis by (simp add: eqconf_pesetran1 nth_Cons') \n              next\n                assume c0: \"i \\<noteq> 0\"\n                then have \"i > 0\" by auto\n                with a1 b0 show ?thesis by (simp add: length_Cons) \n              qed\n          }\n          then show ?thesis by auto\n          qed\n      next\n        case (CptsPesComp pes1 s x ct pes2 t y xs)\n        assume a0: \"\\<Gamma> \\<turnstile> (pes1, s, x) -pes-ct\\<rightarrow> (pes2, t, y)\"\n          and  a1: \"(pes2, t, y) # xs \\<in> cpts_pes \\<Gamma>\"\n          and  a2: \"\\<forall>i. Suc i < length ((pes2, t, y) # xs) \\<longrightarrow>\n                      \\<Gamma> \\<turnstile> ((pes2, t, y) # xs) ! i -pese\\<rightarrow> ((pes2, t, y) # xs) ! Suc i \\<or>\n                      (\\<exists>et. \\<Gamma> \\<turnstile> ((pes2, t, y) # xs) ! i -pes-et\\<rightarrow> ((pes2, t, y) # xs) ! Suc i)\"\n        then show ?case \n          proof -\n          {\n            fix i\n            assume b0: \"Suc i < length ((pes1, s, x) # (pes2, t, y) # xs)\"\n            have \"\\<Gamma> \\<turnstile> ((pes1, s, x) # (pes2, t, y) # xs) ! i -pese\\<rightarrow> ((pes1, s, x) # (pes2, t, y) # xs) ! Suc i \\<or>\n                  (\\<exists>et. \\<Gamma> \\<turnstile> ((pes1, s, x) # (pes2, t, y) # xs) ! i -pes-et\\<rightarrow> ((pes1, s, x) # (pes2, t, y) # xs) ! Suc i)\"\n              proof(cases \"i = 0\")\n                assume c0: \"i = 0\"\n                with a0 show ?thesis using nth_Cons_0 nth_Cons_Suc by auto \n              next\n                assume c0: \"i \\<noteq> 0\"\n                then have \"i > 0\" by auto\n                with a2 b0 show ?thesis using Suc_inject Suc_less_eq2 Suc_pred \n                  length_Cons nth_Cons_Suc by auto \n              qed\n          }\n          then show ?thesis by auto\n          qed\n      qed\n  qed\n\nlemma cpts_pes_drop0: \"\\<lbrakk>el \\<in> cpts_pes \\<Gamma>; Suc 0 < length el\\<rbrakk> \\<Longrightarrow> drop (Suc 0) el \\<in> cpts_pes \\<Gamma>\"\n  apply(rule cpts_pes.cases)\n  apply(simp)+\n  done  \n\nlemma cpts_pes_dropi: \"\\<lbrakk>el \\<in> cpts_pes \\<Gamma>; Suc i < length el\\<rbrakk> \\<Longrightarrow> drop (Suc i) el \\<in> cpts_pes \\<Gamma>\"\n  proof -\n    assume p0:\"el \\<in> cpts_pes \\<Gamma>\" and p1:\"Suc i < length el\"\n    have \"\\<forall>el i. el \\<in> cpts_pes \\<Gamma> \\<and> Suc i < length el \\<longrightarrow> drop (Suc i) el \\<in> cpts_pes \\<Gamma>\"\n      proof -\n      {\n        fix el i\n        have \"el \\<in> cpts_pes \\<Gamma> \\<and> Suc i < length el \\<longrightarrow> drop (Suc i) el \\<in> cpts_pes \\<Gamma>\"\n          proof(induct i)\n            case 0 show ?case by (simp add: cpts_pes_drop0) \n          next\n            case (Suc j)\n            assume b0: \"el \\<in> cpts_pes \\<Gamma> \\<and> Suc j < length el \\<longrightarrow> drop (Suc j) el \\<in> cpts_pes \\<Gamma>\"\n            show ?case\n              proof\n                assume c0: \"el \\<in> cpts_pes \\<Gamma> \\<and> Suc (Suc j) < length el\"\n                with b0 have c1: \"drop (Suc j) el \\<in> cpts_pes \\<Gamma>\"\n                  by (simp add: c0 Suc_lessD)                 \n                then show \"drop (Suc (Suc j)) el \\<in> cpts_pes \\<Gamma>\"\n                  using c0 cpts_pes_drop0 by fastforce \n              qed\n          qed\n      }\n      then show ?thesis by auto\n      qed\n    with p0 p1 show ?thesis by auto\n  qed\n\nlemma cpts_pes_take0: \"\\<lbrakk>el \\<in> cpts_pes \\<Gamma>; i < length el; el1 = take (Suc i) el; j < length el1\\<rbrakk> \n                        \\<Longrightarrow> drop (length el1 - Suc j) el1 \\<in> cpts_pes \\<Gamma>\"\n  proof -\n    assume p0: \"el \\<in> cpts_pes \\<Gamma>\"\n      and  p1: \"i < length el\"\n      and  p2: \"el1 = take (Suc i) el\"\n      and  p3: \"j < length el1\"\n    have \"\\<forall>i j. el \\<in> cpts_pes \\<Gamma> \\<and> i < length el \\<and> el1 = take (Suc i) el \\<and> j < length el1 \n          \\<longrightarrow> drop (length el1 - Suc j) el1 \\<in> cpts_pes \\<Gamma>\"\n      proof -\n      {\n        fix i j\n        assume a0: \"el \\<in> cpts_pes \\<Gamma>\"\n          and  a1: \"i < length el\"\n          and  a2: \"el1 = take (Suc i) el\"\n          and  a3: \"j < length el1\"\n        then have \"drop (length el1 - Suc j) el1 \\<in> cpts_pes \\<Gamma>\"\n          proof(induct j)\n            case 0 \n            have \"drop (length el1 - Suc 0) el1 = [el ! i]\"\n              by (simp add: a1 a2 take_Suc_conv_app_nth) \n            then show ?case by (metis cpts_pes.CptsPesOne old.prod.exhaust) \n          next\n            case (Suc jj)\n            assume b0: \"el \\<in> cpts_pes \\<Gamma> \\<Longrightarrow> i < length el \\<Longrightarrow> el1 = take (Suc i) el \n                        \\<Longrightarrow> jj < length el1 \\<Longrightarrow> drop (length el1 - Suc jj) el1 \\<in> cpts_pes \\<Gamma>\"\n              and  b1: \"el \\<in> cpts_pes \\<Gamma>\"\n              and  b2: \"i < length el\"\n              and  b3: \"el1 = take (Suc i) el\"\n              and  b4: \"Suc jj < length el1\"\n            then have b5: \"drop (length el1 - Suc jj) el1 \\<in> cpts_pes \\<Gamma>\"\n              using Suc_lessD by blast \n            let ?el2 = \"drop (Suc i) el\"\n            from a2 have b6: \"el1 @ ?el2 = el\" by simp\n            let ?el1sht = \"drop (length el1 - Suc jj) el1\"\n            let ?el1lng = \"drop (length el1 - Suc (Suc jj)) el1\"\n            let ?elsht = \"drop (length el1 - Suc jj) el\"\n            let ?ellng = \"drop (length el1 - Suc (Suc jj)) el\"\n            from b6 have a7: \"?el1sht @ ?el2 = ?elsht\"\n              by (metis diff_is_0_eq diff_le_self drop_0 drop_append) \n            from b6 have a8: \"?el1lng @ ?el2 = ?ellng\"\n              by (metis (no_types, lifting) a7 append_eq_append_conv diff_is_0_eq' diff_le_self drop_append) \n            have a9: \"?ellng = (el ! (length el1 - Suc (Suc jj))) # ?elsht\"\n              by (metis (no_types, lifting) Cons_nth_drop_Suc Suc_diff_Suc Suc_leI a8 \n                  append_is_Nil_conv b4 diff_diff_cancel drop_all length_drop \n                  list.size(3) not_less old.nat.distinct(2)) \n            from b1 b4 have a10: \"?elsht \\<in> cpts_pes \\<Gamma>\"\n              by (metis Suc_diff_Suc a7 append_is_Nil_conv b5 cpts_pes_dropi drop_all not_less)\n            from b1 b4 have a11: \"?ellng \\<in> cpts_pes \\<Gamma>\"\n              by (metis (no_types, lifting) Suc_diff_Suc a9 cpts_pes_dropi diff_is_0_eq \n                  drop_0 drop_all leI list.simps(3))\n            have a12: \"?el1lng = (el ! (length el1 - Suc (Suc jj))) # ?el1sht\"\n              by (metis (no_types, lifting) Cons_nth_drop_Suc Suc_diff_Suc b4 b6 diff_less \n                  gr_implies_not0 length_0_conv length_greater_0_conv nth_append zero_less_Suc)\n            from a11 have \"?el1lng \\<in> cpts_pes \\<Gamma>\"\n              proof(induct ?ellng)\n                case CptsPesOne show ?case\n                  using CptsPesOne.hyps a7 a9 by auto \n              next\n                case (CptsPesEnv es1 t1 x1 xs1 s1 y1)\n                assume c0: \"(es1, t1, x1) # xs1 \\<in> cpts_pes \\<Gamma>\"\n                  and  c1: \"(es1, t1, x1) # xs1 = drop (length el1 - Suc (Suc jj)) el \\<Longrightarrow>\n                            drop (length el1 - Suc (Suc jj)) el1 \\<in> cpts_pes \\<Gamma>\"\n                  and  c2: \"(es1, s1, y1) # (es1, t1, x1) # xs1 = drop (length el1 - Suc (Suc jj)) el\"\n                from c0 have \"(es1, s1, y1) # (es1, t1, x1) # xs1 \\<in> cpts_pes \\<Gamma>\"\n                  by (simp add: a11 c2) \n                have c3: \"?el1sht ! 0 = (es1, t1, x1)\" by (metis (no_types, lifting) Suc_leI Suc_lessD a7 \n                        a9 append_eq_Cons_conv b4 c2 diff_diff_cancel length_drop list.inject \n                        list.size(3) nth_Cons_0 old.nat.distinct(2)) \n                then have c4: \"\\<exists>el1sht'. ?el1sht = (es1, t1, x1) # el1sht'\" by (metis Cons_nth_drop_Suc b4 \n                    diff_diff_cancel drop_0 length_drop less_or_eq_imp_le zero_less_Suc) \n                have c5: \"?el1lng = (es1, s1, y1) # ?el1sht\" using a12 a9 c2 by auto \n                \n                with b5 c4 show ?case using cpts_pes.CptsPesEnv by fastforce \n              next\n                case (CptsPesComp es1 s1 x1 et es2 t1 y1 xs1)\n                assume c0: \"\\<Gamma> \\<turnstile> (es1, s1, x1) -pes-et\\<rightarrow> (es2, t1, y1)\"\n                  and  c1: \"(es2, t1, y1) # xs1 \\<in> cpts_pes \\<Gamma>\"\n                  and  c2: \"(es2, t1, y1) # xs1 = drop (length el1 - Suc (Suc jj)) el \n                            \\<Longrightarrow> drop (length el1 - Suc (Suc jj)) el1 \\<in> cpts_pes \\<Gamma>\"\n                  and  c3: \"(es1, s1, x1) # (es2, t1, y1) # xs1 = drop (length el1 - Suc (Suc jj)) el\"\n                have c4: \"?el1sht ! 0 = (es2, t1, y1)\" by (metis (no_types, lifting) Suc_leI Suc_lessD a7 \n                        a9 append_eq_Cons_conv b4 c3 diff_diff_cancel length_drop list.inject \n                        list.size(3) nth_Cons_0 old.nat.distinct(2)) \n                then have c5: \"\\<exists>el1sht'. ?el1sht = (es2, t1, y1) # el1sht'\" by (metis Cons_nth_drop_Suc b4 \n                    diff_diff_cancel drop_0 length_drop less_or_eq_imp_le zero_less_Suc) \n                have c6: \"?el1lng = (es1, s1, x1) # ?el1sht\" using a12 a9 c3 by auto\n                with b5 c5  show ?case using c0 cpts_pes.CptsPesComp by fastforce \n              qed\n\n            then show ?case by simp\n          qed\n      }\n      then show ?thesis by auto\n      qed\n    then show \"drop (length el1 - Suc j) el1 \\<in> cpts_pes \\<Gamma>\"\n      using p0 p1 p2 p3 by blast \n  qed\n\nlemma cpts_pes_take: \"\\<lbrakk>el \\<in> cpts_pes \\<Gamma>; i < length el\\<rbrakk> \\<Longrightarrow> take (Suc i) el \\<in> cpts_pes \\<Gamma>\"\n  using cpts_pes_take0 gr_implies_not0 by fastforce\n\nlemma cpts_pes_seg: \"\\<lbrakk>el \\<in> cpts_pes \\<Gamma>; m \\<le> length el; n \\<le> length el; m < n\\<rbrakk> \n                    \\<Longrightarrow> take (n - m) (drop m el) \\<in> cpts_pes \\<Gamma>\"\n  proof -\n    assume p0: \"el \\<in> cpts_pes \\<Gamma>\"\n      and  p1: \"m \\<le> length el\"\n      and  p2: \"n \\<le> length el\"\n      and  p3: \"m < n\"\n    then have \"drop m el \\<in> cpts_pes \\<Gamma>\" \n      using cpts_pes_dropi by (metis (no_types, lifting) drop_0 le_0_eq le_SucE less_le_trans zero_induct) \n    then show ?thesis using cpts_pes_take\n      by (smt Suc_diff_Suc diff_diff_cancel diff_less_Suc diff_right_commute length_drop less_le_trans p2 p3)\n  qed\n\nlemma cpts_pes_seg2: \"\\<lbrakk>el \\<in> cpts_pes \\<Gamma>; m \\<le> length el; n \\<le> length el; take (n - m) (drop m el) \\<noteq> []\\<rbrakk> \n                    \\<Longrightarrow> take (n - m) (drop m el) \\<in> cpts_pes \\<Gamma>\"\n  proof -\n    assume p0: \"el \\<in> cpts_pes \\<Gamma>\"\n      and  p1: \"m \\<le> length el\"\n      and  p2: \"n \\<le> length el\"\n      and  p3: \"take (n - m) (drop m el) \\<noteq> []\"\n    from p3 have \"m < n\" by simp\n    then show ?thesis using cpts_pes_seg using p0 p1 p2 by blast\n  qed\n\nsubsection \\<open>Compositionality of the Semantics\\<close>\n\nsubsubsection \\<open>Definition of the conjoin operator\\<close>\n\ndefinition same_length :: \"('l,'k,'s,'prog) pesconfs \\<Rightarrow> ('k \\<Rightarrow> ('l,'k,'s,'prog) esconfs) \\<Rightarrow> bool\" where\n  \"same_length c cs \\<equiv> \\<forall>k. length (cs k) = length c\"\n \ndefinition same_state :: \"('l,'k,'s,'prog) pesconfs \\<Rightarrow> ('k \\<Rightarrow> ('l,'k,'s,'prog) esconfs) \\<Rightarrow> bool\" where\n  \"same_state c cs \\<equiv> \\<forall>k j. j < length c \\<longrightarrow> gets (c!j) = gets_es ((cs k)!j) \\<and> getx (c!j) = getx_es ((cs k)!j)\"\n\ndefinition same_spec :: \"('l,'k,'s,'prog) pesconfs \\<Rightarrow> ('k \\<Rightarrow> ('l,'k,'s,'prog) esconfs) \\<Rightarrow> bool\" where\n  \"same_spec c cs \\<equiv> \\<forall>k j. j < length c \\<longrightarrow> (getspc (c!j)) k = getspc_es ((cs k) ! j)\"\n\ndefinition compat_tran :: \"'Env \\<Rightarrow> ('l,'k,'s,'prog) pesconfs \\<Rightarrow> ('k \\<Rightarrow> ('l,'k,'s,'prog) esconfs) \\<Rightarrow> bool\" where\n  \"compat_tran \\<Gamma> c cs \\<equiv> \\<forall>j. Suc j < length c \\<longrightarrow> \n                              ((\\<exists>t k. (\\<Gamma> \\<turnstile> c!j -pes-(t\\<sharp>k)\\<rightarrow> c!Suc j)) \\<and>\n                              (\\<forall>k t. (\\<Gamma> \\<turnstile> c!j -pes-(t\\<sharp>k)\\<rightarrow> c!Suc j) \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k!j -es-(t\\<sharp>k)\\<rightarrow> cs k! Suc j) \\<and>\n                                      (\\<forall>k'. k' \\<noteq> k \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k'!j -ese\\<rightarrow> cs k'! Suc j))))\n                              \\<or>\n                              ((\\<Gamma> \\<turnstile> (c!j) -pese\\<rightarrow> (c!Suc j)) \\<and> (\\<forall>k. (\\<Gamma> \\<turnstile> ((cs k)!j) -ese\\<rightarrow> ((cs k)! Suc j))))\"\n\ndefinition conjoin :: \"'Env \\<Rightarrow> ('l,'k,'s,'prog) pesconfs \\<Rightarrow> ('k \\<Rightarrow> ('l,'k,'s,'prog) esconfs) \\<Rightarrow> bool\"  (\"_ _ \\<propto> _\" [65,65] 64) where\n  \"\\<Gamma> c \\<propto> cs \\<equiv> (same_length c cs) \\<and> (same_state c cs) \\<and> (same_spec c cs) \\<and> (compat_tran \\<Gamma> c cs)\"\n\nsubsubsection \\<open>Lemmas of conjoin\\<close>\n\nlemma acts_in_conjoin_cpts: \"\\<Gamma> c \\<propto> cs \\<Longrightarrow> \\<forall>i. Suc i < length (cs k) \\<longrightarrow> \\<Gamma> \\<turnstile> ((cs k)!i) -ese\\<rightarrow> ((cs k)! Suc i) \n        \\<or> (\\<exists>e. \\<Gamma> \\<turnstile> ((cs k)!i) -es-(EvtEnt e\\<sharp>k)\\<rightarrow> ((cs k)! Suc i))\n        \\<or> (\\<exists>c. \\<Gamma> \\<turnstile> ((cs k)!i) -es-(Cmd c\\<sharp>k)\\<rightarrow> ((cs k)! Suc i))\"\n  proof -\n    assume p0: \"\\<Gamma> c \\<propto> cs\"\n    {\n      fix i\n      assume a0: \"Suc i < length (cs k)\"\n      from p0 have a1: \"length c = length (cs k)\" by (simp add:conjoin_def same_length_def)\n      from p0 have \"compat_tran \\<Gamma> c cs\" by (simp add:conjoin_def)\n      with a0 a1 have \"(\\<exists>t k. (\\<Gamma> \\<turnstile> c!i -pes-(t\\<sharp>k)\\<rightarrow> c!Suc i) \\<and>\n                          (\\<forall>k t. (\\<Gamma> \\<turnstile> c!i -pes-(t\\<sharp>k)\\<rightarrow> c!Suc i) \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k!i -es-(t\\<sharp>k)\\<rightarrow> cs k! Suc i) \\<and>\n                                  (\\<forall>k'. k' \\<noteq> k \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k'!i -ese\\<rightarrow> cs k'! Suc i))))\n                          \\<or>\n                          ((\\<Gamma> \\<turnstile> (c!i) -pese\\<rightarrow> (c!Suc i)) \\<and> (\\<forall>k. (\\<Gamma> \\<turnstile> ((cs k)!i) -ese\\<rightarrow> ((cs k)! Suc i))))\" \n        by (simp add: compat_tran_def)\n      then have \"\\<Gamma> \\<turnstile> ((cs k)!i) -ese\\<rightarrow> ((cs k)! Suc i) \n              \\<or> (\\<exists>e. \\<Gamma> \\<turnstile> ((cs k)!i) -es-(EvtEnt e\\<sharp>k)\\<rightarrow> ((cs k)! Suc i))\n              \\<or> (\\<exists>c. \\<Gamma> \\<turnstile> ((cs k)!i) -es-(Cmd c\\<sharp>k)\\<rightarrow> ((cs k)! Suc i))\"\n        proof\n          assume b0: \"\\<exists>t k. (\\<Gamma> \\<turnstile> c!i -pes-(t\\<sharp>k)\\<rightarrow> c!Suc i) \\<and>\n                          (\\<forall>k t. (\\<Gamma> \\<turnstile> c!i -pes-(t\\<sharp>k)\\<rightarrow> c!Suc i) \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k!i -es-(t\\<sharp>k)\\<rightarrow> cs k! Suc i) \\<and>\n                                  (\\<forall>k'. k' \\<noteq> k \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k'!i -ese\\<rightarrow> cs k'! Suc i)))\"\n          then obtain t and k1 where b1: \"(\\<Gamma> \\<turnstile> c!i -pes-(t\\<sharp>k1)\\<rightarrow> c!Suc i) \\<and>\n                          (\\<forall>k t. (\\<Gamma> \\<turnstile> c!i -pes-(t\\<sharp>k)\\<rightarrow> c!Suc i) \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k!i -es-(t\\<sharp>k)\\<rightarrow> cs k! Suc i) \\<and>\n                                  (\\<forall>k'. k' \\<noteq> k \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k'!i -ese\\<rightarrow> cs k'! Suc i)))\" by auto\n          then show ?thesis\n            proof(cases \"k = k1\")\n              assume c0: \"k = k1\"\n              with b1 show ?thesis by (meson estran_impl_evtentorcmd2') \n            next\n              assume c0: \"k \\<noteq> k1\"\n              with b1 show ?thesis by auto\n            qed\n        next\n          assume b0: \"(\\<Gamma> \\<turnstile> (c!i) -pese\\<rightarrow> (c!Suc i)) \\<and> (\\<forall>k. (\\<Gamma> \\<turnstile> ((cs k)!i) -ese\\<rightarrow> ((cs k)! Suc i)))\"\n          then show ?thesis by simp\n        qed\n    }\n    then show ?thesis by simp\n  qed\n\nlemma entevt_in_conjoin_cpts: \n  \"\\<lbrakk>\\<Gamma> c \\<propto> cs; Suc i < length (cs k); getspc_es ((cs k)!i) = EvtSys es; \n    getspc_es ((cs k)!Suc i) \\<noteq> EvtSys es \\<rbrakk>\n    \\<Longrightarrow> (\\<exists>e. \\<Gamma> \\<turnstile> ((cs k)!i) -es-(EvtEnt e\\<sharp>k)\\<rightarrow> ((cs k)! Suc i))\"\n  proof -\n    assume p0: \"\\<Gamma> c \\<propto> cs\"\n      and  p1: \"Suc i < length (cs k)\"\n      and  p2: \"getspc_es ((cs k)!i) = EvtSys es\"\n      and  p3: \"getspc_es ((cs k)!Suc i) \\<noteq> EvtSys es\"\n    then have \"\\<Gamma> \\<turnstile> ((cs k)!i) -ese\\<rightarrow> ((cs k)! Suc i) \n        \\<or> (\\<exists>e. \\<Gamma> \\<turnstile> ((cs k)!i) -es-(EvtEnt e\\<sharp>k)\\<rightarrow> ((cs k)! Suc i))\n        \\<or> (\\<exists>c. \\<Gamma> \\<turnstile> ((cs k)!i) -es-(Cmd c\\<sharp>k)\\<rightarrow> ((cs k)! Suc i))\"\n      using acts_in_conjoin_cpts by fastforce \n    then show ?thesis\n      proof\n        assume \"\\<Gamma> \\<turnstile> ((cs k)!i) -ese\\<rightarrow> ((cs k)! Suc i)\"\n        with p2 p3 show ?thesis by (simp add: esetran_eqconf1) \n      next\n        assume \"(\\<exists>e. \\<Gamma> \\<turnstile> cs k ! i -es-EvtEnt e\\<sharp>k\\<rightarrow> cs k ! Suc i) \n              \\<or> (\\<exists>c. \\<Gamma> \\<turnstile> cs k ! i -es-Cmd c\\<sharp>k\\<rightarrow> cs k ! Suc i)\"\n        then show ?thesis \n          proof\n            assume \"\\<exists>e. \\<Gamma> \\<turnstile> cs k ! i -es-EvtEnt e\\<sharp>k\\<rightarrow> cs k ! Suc i\"\n            then show ?thesis by simp\n          next\n            assume \"\\<exists>c. \\<Gamma> \\<turnstile> cs k ! i -es-Cmd c\\<sharp>k\\<rightarrow> cs k ! Suc i\"\n            with p2 p3 show ?thesis \n              by (meson cmd_enable_impl_anonyevt2 esys_not_eseq) \n          qed\n      qed\n  qed\n\nlemma notentevt_in_conjoin_cpts: \n  \"\\<lbrakk>\\<Gamma> c \\<propto> cs; Suc i < length (cs k); \\<not>(getspc_es ((cs k)!i) = EvtSys es \\<and> getspc_es ((cs k)!Suc i) \\<noteq> EvtSys es);\n    \\<forall>i < length (cs k). getspc_es ((cs k) ! i) = EvtSys es \n                        \\<or> (\\<exists>e. is_anonyevt e \\<and> getspc_es ((cs k) ! i) = EvtSeq e (EvtSys es))\\<rbrakk>\n    \\<Longrightarrow> \\<not>(\\<exists>e. \\<Gamma> \\<turnstile> ((cs k)!i) -es-(EvtEnt e\\<sharp>k)\\<rightarrow> ((cs k)! Suc i))\"\n  proof -\n    assume p0: \"\\<Gamma> c \\<propto> cs\"\n      and  p1: \"Suc i < length (cs k)\"\n      and  p2: \"\\<not>(getspc_es ((cs k)!i) = EvtSys es \\<and> getspc_es ((cs k)!Suc i) \\<noteq> EvtSys es)\"\n      and  p3: \"\\<forall>i < length (cs k). getspc_es ((cs k) ! i) = EvtSys es \n                    \\<or> (\\<exists>e. is_anonyevt e \\<and> getspc_es ((cs k) ! i) = EvtSeq e (EvtSys es))\"\n    from p2 have \"getspc_es ((cs k)!i) \\<noteq> EvtSys es \\<or> getspc_es ((cs k)!Suc i) = EvtSys es\" by simp\n    with p3 have \"(\\<exists>e. is_anonyevt e \\<and> getspc_es ((cs k) ! i) = EvtSeq e (EvtSys es)) \n                  \\<or> getspc_es ((cs k)!Suc i) = EvtSys es\"\n      using Suc_lessD p1 by blast\n    then show ?thesis\n      proof\n        assume \"\\<exists>e. is_anonyevt e \\<and> getspc_es ((cs k) ! i) = EvtSeq e (EvtSys es)\"\n        then obtain e1 where \"is_anonyevt e1 \\<and> getspc_es ((cs k) ! i) = EvtSeq e1 (EvtSys es)\" by auto\n        then show ?thesis using evtent_is_basicevt_inevtseq2 by fastforce\n      next\n        assume \"getspc_es ((cs k)!Suc i) = EvtSys es\"\n        then show ?thesis by (metis Suc_lessD evtseq_no_evtent2 evtsys_not_eq_in_tran_aux1 p1 p3) \n      qed\n  qed\n\nlemma take_n_conjoin: \"\\<lbrakk>\\<Gamma> c \\<propto> cs; n \\<le> length c; c1 = take n c; cs1 = (\\<lambda>k. take n (cs k))\\<rbrakk> \n    \\<Longrightarrow> \\<Gamma> c1 \\<propto> cs1\"\n  proof -\n    assume p0: \"\\<Gamma> c \\<propto> cs\"\n      and  p1: \"n \\<le> length c\"\n      and  p2: \"c1 = take n c\"\n      and  p3: \"cs1 = (\\<lambda>k. take n (cs k))\"\n    have a0: \"same_length c1 cs1\" by (metis conjoin_def length_take p0 p2 p3 same_length_def) \n    then have a1: \"\\<forall>k. length (cs1 k) = length c1\" by (simp add:same_length_def)\n    \n    have \"same_state c1 cs1\"\n      proof -\n      {\n        fix k j\n        assume b0: \"j < length c1\"\n        from p1 p3 a1 have b1: \"cs1 k = take n (cs k)\" by simp \n        from p0 have b2[rule_format]: \"\\<forall>k j. j < length c \n              \\<longrightarrow> gets (c!j) = gets_es ((cs k)!j) \\<and> getx (c!j) = getx_es ((cs k)!j)\"\n          by (simp add:conjoin_def same_state_def)\n        from p2 b1 b0 have \"gets (c ! j) = gets (c1 ! j) \\<and> gets_es ((cs k)!j) = gets_es ((cs1 k)!j)\n          \\<and> getx (c!j) = getx (c1!j)\"\n          by (simp add: nth_append)\n        with p1 p2 b1 b2[of j k] b0 have \"gets (c1!j) = gets_es ((cs1 k)!j) \\<and> getx (c1!j) = getx_es ((cs1 k)!j)\"\n          by simp\n      }\n      then show ?thesis by (simp add:same_state_def)\n      qed\n    moreover\n    have \"same_spec c1 cs1\" \n      proof -\n      {\n        fix k j\n        assume b0: \"j < length c1\"\n        from p1 p3 a1 have b1: \"cs1 k = take n (cs k)\" by simp \n        from p0 have b2[rule_format]: \"\\<forall>k j. j < length c \n              \\<longrightarrow> (getspc (c!j)) k = getspc_es ((cs k) ! j)\"\n          by (simp add:conjoin_def same_spec_def)\n        from p2 b1 b0 have \"getspc (c1!j) = getspc (c!j) \n          \\<and> getspc_es ((cs k) ! j) = getspc_es ((cs1 k) ! j)\" \n          by (simp add: nth_append)\n        then have \"(getspc (c1!j)) k = getspc_es ((cs1 k) ! j)\"\n          using b0 b2 p2 by auto \n      }\n      then show ?thesis by (simp add:same_spec_def)\n      qed\n    moreover\n    have \"compat_tran \\<Gamma> c1 cs1\"\n      proof -\n      {\n        fix j\n        assume b0: \"Suc j < length c1\"\n        with p0 p2 have \"((\\<exists>t k. (\\<Gamma> \\<turnstile> c!j -pes-(t\\<sharp>k)\\<rightarrow> c!Suc j)) \\<and>\n                        (\\<forall>k t. (\\<Gamma> \\<turnstile> c!j -pes-(t\\<sharp>k)\\<rightarrow> c!Suc j) \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k!j -es-(t\\<sharp>k)\\<rightarrow> cs k! Suc j) \\<and>\n                                (\\<forall>k'. k' \\<noteq> k \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k'!j -ese\\<rightarrow> cs k'! Suc j))))\n                        \\<or>\n                        ((\\<Gamma> \\<turnstile> (c!j) -pese\\<rightarrow> (c!Suc j)) \\<and> (\\<forall>k. (\\<Gamma> \\<turnstile> ((cs k)!j) -ese\\<rightarrow> ((cs k)! Suc j))))\"\n          by (simp add:conjoin_def compat_tran_def)\n        moreover\n        from p2 b0 have \"c!j = c1!j\" by simp\n        moreover\n        from p2 b0 have \"c!Suc j = c1!Suc j\" by simp\n        moreover\n        from p1 p2 p3 a1 b0 have \"\\<forall>k. cs1 k!j = cs k!j\"\n          by (simp add: Suc_lessD) \n        moreover\n        from p1 p2 p3 a1 b0 have \"\\<forall>k. cs1 k!Suc j = cs k!Suc j\"\n          by (simp add: Suc_lessD) \n        ultimately\n        have \"((\\<exists>t k. (\\<Gamma> \\<turnstile> c1!j -pes-(t\\<sharp>k)\\<rightarrow> c1!Suc j)) \\<and>\n                    (\\<forall>k t. (\\<Gamma> \\<turnstile> c1!j -pes-(t\\<sharp>k)\\<rightarrow> c1!Suc j) \\<longrightarrow> (\\<Gamma> \\<turnstile> cs1 k!j -es-(t\\<sharp>k)\\<rightarrow> cs1 k! Suc j) \\<and>\n                            (\\<forall>k'. k' \\<noteq> k \\<longrightarrow> (\\<Gamma> \\<turnstile> cs1 k'!j -ese\\<rightarrow> cs1 k'! Suc j))))\n                    \\<or>\n                    ((\\<Gamma> \\<turnstile> (c1!j) -pese\\<rightarrow> (c1!Suc j)) \\<and> (\\<forall>k. (\\<Gamma> \\<turnstile> ((cs1 k)!j) -ese\\<rightarrow> ((cs1 k)! Suc j))))\" by simp\n      }\n      then show ?thesis by (simp add:compat_tran_def)\n      qed\n    ultimately show ?thesis by (simp add:conjoin_def a0)\n  qed\n\nlemma drop_n_conjoin: \"\\<lbrakk>\\<Gamma> c \\<propto> cs; n \\<le> length c; c1 = drop n c; cs1 = (\\<lambda>k. drop n (cs k))\\<rbrakk> \n    \\<Longrightarrow> \\<Gamma> c1 \\<propto> cs1\"\n  proof -\n    assume p0: \"\\<Gamma> c \\<propto> cs\"\n      and  p1: \"n \\<le> length c\"\n      and  p2: \"c1 = drop n c\"\n      and  p3: \"cs1 = (\\<lambda>k. drop n (cs k))\"\n    have a0: \"same_length c1 cs1\" by (metis conjoin_def length_drop p0 p2 p3 same_length_def) \n    then have a1: \"\\<forall>k. length (cs1 k) = length c1\" by (simp add:same_length_def)\n    \n    have \"same_state c1 cs1\"\n      proof -\n      {\n        fix k j\n        assume b0: \"j < length c1\"\n        from p1 p3 a1 have b1: \"cs1 k = drop n (cs k)\" by simp \n        from p0 have b2[rule_format]: \"\\<forall>k j. j < length c \n              \\<longrightarrow> gets (c!j) = gets_es ((cs k)!j) \\<and> getx (c!j) = getx_es ((cs k)!j)\"\n          by (simp add:conjoin_def same_state_def)\n        from p2 b1 b0 have \"gets (c ! (n + j)) = gets (c1 ! j) \\<and> gets_es ((cs k)!(n + j)) = gets_es ((cs1 k)!j)\n          \\<and> getx (c!(n + j)) = getx (c1!j)\"\n          proof -\n            have f1: \"n + j \\<le> length c\"\n              using b0 p2 by auto\n            then have \"n + j \\<le> length (cs k)\"\n              by (metis (no_types) conjoin_def p0 same_length_def)\n            then show ?thesis\n              using f1 by (simp add: b1 p2)\n          qed\n          \n        with p1 p2 b1 b2[of \"n + j\" k] b0 have \"gets (c1!j) = gets_es ((cs1 k)!j) \\<and> getx (c1!j) = getx_es ((cs1 k)!j)\"\n          by (smt a1 add_diff_cancel_left' drop_eq_Nil length_drop less_diff_conv2 list.size(3) \n              nat_le_linear nat_neq_iff not_less_zero nth_drop order.asym semiring_normalization_rules(24))\n          \n      }\n      then show ?thesis by (simp add:same_state_def)\n      qed\n    moreover\n    have \"same_spec c1 cs1\" \n      proof -\n      {\n        fix k j\n        assume b0: \"j < length c1\"\n        from p1 p3 a1 have b1: \"cs1 k = drop n (cs k)\" by simp \n        from p0 have b2[rule_format]: \"\\<forall>k j. j < length c \n              \\<longrightarrow> (getspc (c!j)) k = getspc_es ((cs k) ! j)\"\n          by (simp add:conjoin_def same_spec_def)\n        from p2 b1 b0 have \"getspc (c1!j) = getspc (c!(n+j)) \n          \\<and> getspc_es ((cs k) ! (n+j)) = getspc_es ((cs1 k) ! j)\" \n          proof -\n            have f1: \"n + j \\<le> length c\"\n              using b0 p2 by auto\n            then have \"n + j \\<le> length (cs k)\"\n              by (metis (no_types) conjoin_def p0 same_length_def)\n            then show ?thesis\n              using f1 by (simp add: b1 p2)\n          qed\n        then have \"(getspc (c1!j)) k = getspc_es ((cs1 k) ! j)\"\n          using b0 b2 p2 by auto \n      }\n      then show ?thesis by (simp add:same_spec_def)\n      qed\n    moreover\n    have \"compat_tran \\<Gamma> c1 cs1\"\n      proof -\n      {\n        fix j\n        assume b0: \"Suc j < length c1\"\n        with p0 p2 have \"((\\<exists>t k. (\\<Gamma> \\<turnstile> c!(n+j) -pes-(t\\<sharp>k)\\<rightarrow> c!Suc (n+j))) \\<and>\n                        (\\<forall>k t. (\\<Gamma> \\<turnstile> c!(n+j) -pes-(t\\<sharp>k)\\<rightarrow> c!Suc (n+j)) \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k!(n+j) -es-(t\\<sharp>k)\\<rightarrow> cs k! Suc (n+j)) \\<and>\n                                (\\<forall>k'. k' \\<noteq> k \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k'!(n+j) -ese\\<rightarrow> cs k'! Suc (n+j)))))\n                        \\<or>\n                        ((\\<Gamma> \\<turnstile> (c!(n+j)) -pese\\<rightarrow> (c!Suc (n+j))) \\<and> (\\<forall>k. (\\<Gamma> \\<turnstile> ((cs k)!(n+j)) -ese\\<rightarrow> ((cs k)! Suc (n+j)))))\"\n          by (simp add:conjoin_def compat_tran_def)\n        moreover\n        from p2 b0 have \"c!(n+j) = c1!j\" by simp\n        moreover\n        from p2 b0 have \"c!Suc (n+j) = c1!Suc j\" by simp\n        moreover\n        from p1 p2 p3 a1 b0 have \"\\<forall>k. cs1 k!j = cs k!(n+j)\"\n          by (metis drop_eq_Nil length_greater_0_conv less_imp_Suc_add linear nth_drop zero_less_Suc)\n        moreover\n        from p1 p2 p3 a1 b0 have \"\\<forall>k. cs1 k!Suc j = cs k!Suc (n+j)\"\n          by (smt Suc_lessE add_Suc_right drop_eq_Nil length_greater_0_conv linear nth_drop zero_less_Suc)\n        ultimately\n        have \"((\\<exists>t k. (\\<Gamma> \\<turnstile> c1!j -pes-(t\\<sharp>k)\\<rightarrow> c1!Suc j)) \\<and>\n                    (\\<forall>k t. (\\<Gamma> \\<turnstile> c1!j -pes-(t\\<sharp>k)\\<rightarrow> c1!Suc j) \\<longrightarrow> (\\<Gamma> \\<turnstile> cs1 k!j -es-(t\\<sharp>k)\\<rightarrow> cs1 k! Suc j) \\<and>\n                            (\\<forall>k'. k' \\<noteq> k \\<longrightarrow> (\\<Gamma> \\<turnstile> cs1 k'!j -ese\\<rightarrow> cs1 k'! Suc j))))\n                    \\<or>\n                    ((\\<Gamma> \\<turnstile> (c1!j) -pese\\<rightarrow> (c1!Suc j)) \\<and> (\\<forall>k. (\\<Gamma> \\<turnstile> ((cs1 k)!j) -ese\\<rightarrow> ((cs1 k)! Suc j))))\" by simp\n      }\n      then show ?thesis by (simp add:compat_tran_def)\n      qed\n    ultimately show ?thesis by (simp add:conjoin_def a0)\n  qed\n\nlemma conjoin_imp_cptses_k_help: \"\\<lbrakk>c \\<in> cpts_pes \\<Gamma>\\<rbrakk> \\<Longrightarrow> \n      \\<forall>cs k. \\<Gamma> c \\<propto> cs \\<longrightarrow> (cs k \\<in> cpts_es \\<Gamma>)\" \n  proof -\n    assume p0: \"c \\<in> cpts_pes \\<Gamma>\"\n    {\n      fix k\n      from p0 have \"\\<forall>cs. c \\<in> cpts_pes \\<Gamma> \\<and> \\<Gamma> c \\<propto> cs \\<longrightarrow> (cs k \\<in> cpts_es \\<Gamma>)\"\n        proof(induct c)\n          case (CptsPesOne pes s x)\n\n          {\n            fix cs\n            assume a0: \"\\<Gamma> [(pes, s, x)] \\<propto> cs\"\n            then have p3:\"length (cs k) = 1\" by (simp add:conjoin_def same_length_def)\n            from a0 have p5: \"same_spec [(pes, s, x)] cs \\<and> same_state [(pes, s, x)] cs\" by (simp add:conjoin_def)\n            with a0 p3 have \"cs k ! 0  = (pes k, s, x)\" \n              using esconf_trip pesconf_trip same_spec_def same_state_def\n                by (metis One_nat_def length_Cons list.size(3) nth_Cons_0 prod.sel(1) prod.sel(2) zero_less_one) \n            with p3 have \"cs k \\<in> cpts_es \\<Gamma>\"\n              by (metis (no_types, hide_lams) One_nat_def Suc_less_eq cpts_es.CptsEsOne length_0_conv length_Cons neq0_conv neq_Nil_conv prod_cases3)\n          }\n          then show ?case by auto\n        next\n          case (CptsPesEnv pes t x xs s y)\n          assume a0: \"(pes, t, x) # xs \\<in> cpts_pes \\<Gamma>\"\n            and  a1[rule_format]: \"\\<forall>cs. (pes, t, x) # xs \\<in> cpts_pes \\<Gamma> \\<and> \\<Gamma> (pes, t, x) # xs \\<propto> cs \\<longrightarrow> cs k \\<in> cpts_es \\<Gamma>\"\n          {\n            fix cs\n            assume b0: \"(pes, s, y) # (pes, t, x) # xs \\<in> cpts_pes \\<Gamma>\"\n              and  b1: \"\\<Gamma> (pes, s, y) # (pes, t, x) # xs \\<propto> cs\"\n            let ?esl = \"(pes, t, x) # xs\"\n            let ?esllon = \"(pes, s, y) # (pes, t, x) # xs\"\n            let ?cs = \"(\\<lambda>k. drop 1 (cs k))\"\n            from b1 have \"\\<Gamma> ?esl \\<propto> ?cs\" using drop_n_conjoin[of \\<Gamma> ?esllon cs 1 ?esl ?cs] by auto\n            with a0 a1[of ?cs] have b2: \"?cs k \\<in> cpts_es \\<Gamma>\" by simp\n            from b1 have b3: \"cs k ! 0 = (pes k, s, y)\" \n              using conjoin_def[of \\<Gamma> ?esllon cs] same_state_def[of ?esllon cs] same_spec_def[of ?esllon cs]\n                by (metis esconf_trip gets_def getspc_def getx_def length_greater_0_conv \n                  list.simps(3) nth_Cons_0 prod.sel(1) prod.sel(2)) \n\n            from b1 have \"getspc_es (cs k ! 1) = (getspc (?esllon ! 1)) k\" \n              using conjoin_def[of \\<Gamma> ?esllon cs] same_spec_def[of ?esllon cs]\n                by (metis diff_Suc_1 length_Cons zero_less_Suc zero_less_diff) \n            moreover\n            from b1 have \"gets (?esllon ! 1) = gets_es ((cs k)!1) \\<and> getx (?esllon ! 1) = getx_es ((cs k)!1)\"\n              using conjoin_def[of \\<Gamma> ?esllon cs] same_state_def[of ?esllon cs]\n                 diff_Suc_1 length_Cons zero_less_Suc zero_less_diff by fastforce\n            ultimately have \"cs k ! 1 = (pes k, t, x)\" \n              using b0 getspc_def gets_def getx_def\n                by (metis One_nat_def esconf_trip fst_conv nth_Cons_0 nth_Cons_Suc snd_conv) \n            \n            with b2 b3 have \"cs k \\<in> cpts_es \\<Gamma>\" using CptsEsEnv\n              by (metis Cons_nth_drop_Suc One_nat_def Suc_lessD cpts_es_not_empty \n                    drop_0 drop_eq_Nil not_le) \n          }\n          then show ?case by auto\n        next\n          case (CptsPesComp pes1 s y ct pes2 t x xs)\n          assume a0: \"\\<Gamma> \\<turnstile> (pes1, s, y) -pes-ct\\<rightarrow> (pes2, t, x)\"\n            and  a1: \"(pes2, t, x) # xs \\<in> cpts_pes \\<Gamma>\"\n            and  a2[rule_format]: \"\\<forall>cs. (pes2, t, x) # xs \\<in> cpts_pes \\<Gamma> \\<and> \\<Gamma> (pes2, t, x) # xs \\<propto> cs \\<longrightarrow> cs k \\<in> cpts_es \\<Gamma>\"\n          {\n            fix cs\n            assume b0: \"(pes1, s, y) # (pes2, t, x) # xs \\<in> cpts_pes \\<Gamma>\"\n              and  b1: \"\\<Gamma> (pes1, s, y) # (pes2, t, x) # xs \\<propto> cs\"\n            let ?esl = \"(pes2, t, x) # xs\"\n            let ?esllon = \"(pes1, s, y) # (pes2, t, x) # xs\"\n            let ?cs = \"(\\<lambda>k. drop 1 (cs k))\"\n            from b1 have \"\\<Gamma> ?esl \\<propto> ?cs\" using drop_n_conjoin[of \\<Gamma> ?esllon cs 1 ?esl ?cs] by auto\n            with a1 a2[of ?cs] have b2: \"?cs k \\<in> cpts_es \\<Gamma>\" by simp\n            from b1 have b3: \"cs k ! 0 = (pes1 k, s, y)\" \n              using conjoin_def[of \\<Gamma> ?esllon cs] same_state_def[of ?esllon cs] same_spec_def[of ?esllon cs]\n                by (metis esconf_trip gets_def getspc_def getx_def length_greater_0_conv \n                  list.simps(3) nth_Cons_0 prod.sel(1) prod.sel(2)) \n\n            from b1 have \"getspc_es (cs k ! 1) = (getspc (?esllon ! 1)) k\" \n              using conjoin_def[of \\<Gamma> ?esllon cs] same_spec_def[of ?esllon cs]\n                by (metis diff_Suc_1 length_Cons zero_less_Suc zero_less_diff) \n            moreover\n            from b1 have \"gets (?esllon ! 1) = gets_es ((cs k)!1) \\<and> getx (?esllon ! 1) = getx_es ((cs k)!1)\"\n              using conjoin_def[of \\<Gamma> ?esllon cs] same_state_def[of ?esllon cs]\n                 diff_Suc_1 length_Cons zero_less_Suc zero_less_diff by fastforce\n            ultimately have b4: \"cs k ! 1 = (pes2 k, t, x)\" \n              using b0 getspc_def gets_def getx_def\n                by (metis One_nat_def esconf_trip fst_conv nth_Cons_0 nth_Cons_Suc snd_conv) \n            \n            from b1 have \"compat_tran \\<Gamma> ?esllon cs\" by (simp add:conjoin_def)\n            then have \"((\\<exists>t k. (\\<Gamma> \\<turnstile> ?esllon!0 -pes-(t\\<sharp>k)\\<rightarrow> ?esllon!Suc 0)) \\<and>\n                                (\\<forall>k t. (\\<Gamma> \\<turnstile> ?esllon!0 -pes-(t\\<sharp>k)\\<rightarrow> ?esllon!Suc 0) \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k!0 -es-(t\\<sharp>k)\\<rightarrow> cs k! Suc 0) \\<and>\n                                        (\\<forall>k'. k' \\<noteq> k \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k'!0 -ese\\<rightarrow> cs k'! Suc 0))))\n                                \\<or>\n                                ((\\<Gamma> \\<turnstile> (?esllon!0) -pese\\<rightarrow> (?esllon!Suc 0)) \\<and> (\\<forall>k. (\\<Gamma> \\<turnstile> ((cs k)!0) -ese\\<rightarrow> ((cs k)! Suc 0))))\"\n               using compat_tran_def[of \\<Gamma> ?esllon cs] by fastforce\n            then have \"cs k \\<in> cpts_es \\<Gamma>\" \n              proof\n                assume c0: \"(\\<exists>t k. (\\<Gamma> \\<turnstile> ?esllon!0 -pes-(t\\<sharp>k)\\<rightarrow> ?esllon!Suc 0)) \\<and>\n                                (\\<forall>k t. (\\<Gamma> \\<turnstile> ?esllon!0 -pes-(t\\<sharp>k)\\<rightarrow> ?esllon!Suc 0) \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k!0 -es-(t\\<sharp>k)\\<rightarrow> cs k! Suc 0) \\<and>\n                                        (\\<forall>k'. k' \\<noteq> k \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k'!0 -ese\\<rightarrow> cs k'! Suc 0)))\"\n                then obtain t1 and k1 where c1: \"(\\<Gamma> \\<turnstile> ?esllon!0 -pes-(t1\\<sharp>k1)\\<rightarrow> ?esllon!Suc 0)\" by auto\n                with c0 have c2: \"(\\<Gamma> \\<turnstile> cs k1!0 -es-(t1\\<sharp>k1)\\<rightarrow> cs k1! Suc 0) \\<and>\n                                   (\\<forall>k'. k' \\<noteq> k1 \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k'!0 -ese\\<rightarrow> cs k'! Suc 0))\" by auto\n                show ?thesis\n                  proof(cases \"k = k1\")\n                    assume d0: \"k = k1\"\n                    with c2 have \"(\\<Gamma> \\<turnstile> cs k!0 -es-(t1\\<sharp>k)\\<rightarrow> cs k! Suc 0)\" by auto\n                    with b2 b3 b4 show ?thesis using CptsEsComp\n                      by (metis Cons_nth_drop_Suc One_nat_def Suc_lessD cpts_es_not_empty drop_0 drop_eq_Nil not_le)\n                  next\n                    assume d0: \"k \\<noteq> k1\"\n                    with c2 have \"\\<Gamma> \\<turnstile> cs k!0 -ese\\<rightarrow> cs k! Suc 0\" by auto\n                    with b2 b3 b4 show ?thesis using CptsEsEnv\n                      by (metis Cons_nth_drop_Suc One_nat_def Suc_lessD cpts_es_not_empty \n                        drop_0 drop_eq_Nil esetran_eqconf not_le) \n                  qed\n              next\n                assume c0: \"(\\<Gamma> \\<turnstile> (?esllon!0) -pese\\<rightarrow> (?esllon!Suc 0)) \\<and> (\\<forall>k. (\\<Gamma> \\<turnstile> ((cs k)!0) -ese\\<rightarrow> ((cs k)! Suc 0)))\"\n                then have \"\\<Gamma> \\<turnstile> ((cs k)!0) -ese\\<rightarrow> ((cs k)! Suc 0)\" by simp\n                with b2 b3 b4 show ?thesis using CptsEsEnv a0 c0 pes_tran_not_etran1 by fastforce \n              qed\n          }\n          then show ?case by auto\n        qed\n    }\n    with p0 show ?thesis by simp \n  qed\n\nlemma conjoin_imp_cptses_k: \n      \"\\<lbrakk>c \\<in> cpts_of_pes \\<Gamma> pes s x; \\<Gamma> c \\<propto> cs\\<rbrakk> \n        \\<Longrightarrow> cs k \\<in> cpts_of_es \\<Gamma> (pes k) s x\" \n  proof -\n    assume p0: \"c \\<in> cpts_of_pes \\<Gamma> pes s x\"\n      and  p1: \"\\<Gamma> c \\<propto> cs\"\n    from p0 have a1: \"c\\<in>cpts_pes \\<Gamma> \\<and> c!0 = (pes,s,x)\" by (simp add:cpts_of_pes_def)\n    from a1 p1 have \"cs k \\<in> cpts_es \\<Gamma>\" using conjoin_imp_cptses_k_help by auto\n    moreover\n    from p0 p1 have \"cs k ! 0 = (pes k,s,x)\"\n      by (metis a1 conjoin_def cpts_pes_not_empty esconf_trip fst_conv gets_def \n        getspc_def getx_def length_greater_0_conv same_spec_def same_state_def snd_conv) \n    ultimately show ?thesis by (simp add:cpts_of_es_def)\n  qed\n\nsubsubsection \\<open>Semantics is Compositional\\<close>\n\nlemma conjoin_cs_imp_cpt: \"\\<lbrakk>\\<exists>k p. pes k = p; (\\<exists>cs. (\\<forall>k. (cs k) \\<in> cpts_of_es \\<Gamma> (pes k) s x) \\<and> \\<Gamma> c \\<propto> cs)\\<rbrakk>\n                                \\<Longrightarrow> c \\<in> cpts_of_pes \\<Gamma> pes s x\"\n  proof -\n    assume p0: \"\\<exists>cs. (\\<forall>k. (cs k) \\<in> cpts_of_es \\<Gamma> (pes k) s x) \\<and> \\<Gamma> c \\<propto> cs\"\n      and  p1: \"\\<exists>k p. pes k = p\"\n    then obtain cs where \"(\\<forall>k. (cs k) \\<in> cpts_of_es \\<Gamma> (pes k) s x) \\<and> \\<Gamma> c \\<propto> cs\" by auto\n    then have a0: \"(\\<forall>k. (cs k)!0=(pes k,s,x) \\<and> (cs k) \\<in> cpts_es \\<Gamma>) \\<and> \\<Gamma> c \\<propto> cs\" by (simp add:cpts_of_es_def)\n    from p1 obtain p and k where a1: \"pes k = p\" by auto\n\n    from p1 obtain k and p where \"pes k = p\" by auto\n    with a0 have a2: \"(cs k)!0=(pes k,s,x) \\<and> (cs k) \\<in> cpts_es \\<Gamma>\" by auto\n    then have \"(cs k) \\<noteq> []\"  by auto\n    moreover\n    from a0 have \"same_length c cs\" by (simp add:conjoin_def)\n    ultimately have a3: \"c \\<noteq> []\" using same_length_def by force \n\n    have g0: \"c!0 = (pes,s,x)\"\n      proof -\n        from a3 a0 have \"same_spec c cs\" by (simp add:conjoin_def)\n        with a3 have b2: \"\\<forall>k. (getspc (c!0)) k = getspc_es ((cs k) ! 0)\" by (simp add:same_spec_def)\n        with a0 have \"\\<forall>k. (getspc (c!0)) k = pes k\" by (simp add:getspc_es_def)\n        then have b3: \"getspc (c!0) = pes\" by auto\n\n        from a0 have \"same_state c cs\"  by (simp add:conjoin_def)\n        with a3 have \"gets (c!0) = gets_es ((cs k)!0) \\<and> getx (c!0) = getx_es ((cs k)!0)\" \n          by (simp add:same_state_def)\n        with a2 have \"gets (c!0) = s \\<and> getx (c!0) = x\" \n          by (simp add:gets_def getx_def gets_es_def getx_es_def)\n        with b3 show ?thesis using gets_def getx_def getspc_def by (metis prod.collapse)\n      qed\n    have \"\\<forall>i. i > 0 \\<and> i \\<le> length c \\<longrightarrow> take i c \\<in> cpts_pes \\<Gamma>\"\n      proof -\n      {\n        fix i\n        assume b0: \"i > 0 \\<and> i \\<le> length c\"\n        then have \"take i c \\<in> cpts_pes \\<Gamma>\"\n          proof(induct i)\n            case 0 show ?case using \"0.prems\" by auto \n          next\n            case (Suc j)\n            assume c0: \"0 < j \\<and> j \\<le> length c \\<Longrightarrow> take j c \\<in> cpts_pes \\<Gamma>\"\n              and  c1: \"0 < Suc j \\<and> Suc j \\<le> length c\"\n            show ?case\n              proof(cases \"j = 0\")\n                assume d0: \"j = 0\"\n                with c0 show ?case by (simp add: a3 cpts_pes.CptsPesOne g0 hd_conv_nth take_Suc) \n              next\n                assume d0: \"j \\<noteq> 0\"\n                from a0 have d1: \"compat_tran \\<Gamma> c cs\" by (simp add:conjoin_def)\n                then have d2: \"\\<forall>j. Suc j < length c \\<longrightarrow> \n                              (\\<exists>t k. (\\<Gamma> \\<turnstile> c!j -pes-(t\\<sharp>k)\\<rightarrow> c!Suc j) \\<and>\n                              (\\<forall>k t. (\\<Gamma> \\<turnstile> c!j -pes-(t\\<sharp>k)\\<rightarrow> c!Suc j) \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k!j -es-(t\\<sharp>k)\\<rightarrow> cs k! Suc j) \\<and>\n                                      (\\<forall>k'. k' \\<noteq> k \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k'!j -ese\\<rightarrow> cs k'! Suc j))))\n                              \\<or>\n                              ((\\<Gamma> \\<turnstile> (c!j) -pese\\<rightarrow> (c!Suc j)) \\<and> (\\<forall>k. (\\<Gamma> \\<turnstile> ((cs k)!j) -ese\\<rightarrow> ((cs k)! Suc j))))\"\n                  by (simp add:compat_tran_def)\n                \n                from d0 have d3: \"j - 1 \\<ge> 0\" by simp\n                from c1 have d6: \"Suc (j - 1) < length c\" using d0 by auto \n                \n                with d3 have d4: \"(\\<exists>t k. (\\<Gamma> \\<turnstile> c!(j-1) -pes-(t\\<sharp>k)\\<rightarrow> c!Suc (j-1)) \\<and>\n                              (\\<forall>k t. (\\<Gamma> \\<turnstile> c!(j-1) -pes-(t\\<sharp>k)\\<rightarrow> c!Suc (j-1)) \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k!(j-1) -es-(t\\<sharp>k)\\<rightarrow> cs k! Suc (j-1)) \\<and>\n                                      (\\<forall>k'. k' \\<noteq> k \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k'!(j-1) -ese\\<rightarrow> cs k'! Suc (j-1)))))\n                              \\<or>\n                              ((\\<Gamma> \\<turnstile> (c!(j-1)) -pese\\<rightarrow> (c!Suc (j-1))) \\<and> (\\<forall>k. (\\<Gamma> \\<turnstile> ((cs k)!(j-1)) -ese\\<rightarrow> ((cs k)!Suc (j-1)))))\"\n                   using d2 by auto\n                from c0 c1 d0 have d5: \"take j c \\<in> cpts_pes \\<Gamma>\" by auto\n                from d4 show ?case\n                  proof \n                    assume \"(\\<exists>t k. (\\<Gamma> \\<turnstile> c!(j-1) -pes-(t\\<sharp>k)\\<rightarrow> c!Suc (j-1)) \\<and>\n                              (\\<forall>k t. (\\<Gamma> \\<turnstile> c!(j-1) -pes-(t\\<sharp>k)\\<rightarrow> c!Suc (j-1)) \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k!(j-1) -es-(t\\<sharp>k)\\<rightarrow> cs k! Suc (j-1)) \\<and>\n                                      (\\<forall>k'. k' \\<noteq> k \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k'!(j-1) -ese\\<rightarrow> cs k'! Suc (j-1)))))\"\n                    then obtain t and k where e0: \"(\\<Gamma> \\<turnstile> (c!(j-1)) -pes-(t\\<sharp>k)\\<rightarrow> (c!Suc (j-1)))\" by auto\n                    then have \"\\<Gamma> \\<turnstile> ((take j c) ! (length (take j c) - 1)) -pes-(t\\<sharp>k)\\<rightarrow> (c!Suc (j-1))\"\n                      by (metis (no_types, lifting) Suc_diff_1 Suc_leD Suc_lessD \n                        d6 butlast_take c1 d0 length_butlast neq0_conv nth_append_length take_Suc_conv_app_nth) \n                    with d5 have \"(take j c) @ [c!Suc (j-1)] \\<in> cpts_pes \\<Gamma>\" using cpts_pes_onemore by blast\n                    then show ?thesis using d0 d6 take_Suc_conv_app_nth by fastforce\n                  next\n                    assume \"(\\<Gamma> \\<turnstile> (c!(j-1)) -pese\\<rightarrow> (c!Suc (j-1))) \\<and> (\\<forall>k. (\\<Gamma> \\<turnstile> ((cs k)!(j-1)) -ese\\<rightarrow> ((cs k)!Suc (j-1))))\"\n                    then have \"\\<Gamma> \\<turnstile> ((take j c) ! (length (take j c) - 1)) -pese\\<rightarrow> (c!Suc (j-1))\" \n                      by (metis (no_types, lifting) Suc_diff_1 Suc_leD Suc_lessD \n                        d6 butlast_take c1 d0 length_butlast neq0_conv nth_append_length take_Suc_conv_app_nth) \n                    with d5 have \"(take j c) @ [c!Suc (j-1)] \\<in> cpts_pes \\<Gamma>\" using cpts_pes_onemore by blast\n                    then show ?thesis using d0 d6 take_Suc_conv_app_nth by fastforce\n                  qed\n                    \n              qed\n          qed\n      }\n      then show ?thesis by auto\n      qed\n\n    with a3 have g1: \"c\\<in>cpts_pes \\<Gamma>\" by auto\n    from g0 g1 show ?thesis by (simp add:cpts_of_pes_def)\n  qed\n\nlemma comp_tran_env: \"\\<lbrakk>(\\<forall>k. cs k \\<in> cpts_of_es \\<Gamma> (pes k) t1 x1); c = (pes, t1, x1) # xs; c\\<in>cpts_pes \\<Gamma>; \n                        \\<Gamma> c \\<propto> cs; c' = (pes, s1, y1) # (pes, t1, x1) # xs\\<rbrakk> \\<Longrightarrow> \n      compat_tran \\<Gamma> c' (\\<lambda>k. (pes k, s1, y1) # cs k)\"\n  proof -\n    let ?cs' = \"\\<lambda>k. (pes k, s1, y1) # cs k\"\n    assume p0: \"\\<forall>k. cs k \\<in> cpts_of_es \\<Gamma> (pes k) t1 x1\"\n      and  p1: \"c \\<in> cpts_pes \\<Gamma>\"\n      and  p2: \"\\<Gamma> c \\<propto> cs\"\n      and  p3: \"c' = (pes, s1, y1) # (pes, t1, x1) # xs\"\n      and  p4: \"c = (pes, t1, x1) # xs\"\n    from p0 have b3: \"\\<forall>k. cs k \\<in> cpts_es \\<Gamma> \\<and> (cs k)!0 = (pes k,t1,x1)\" by (simp add:cpts_of_es_def)\n    show \"compat_tran \\<Gamma> c' ?cs'\"\n      proof -\n      {\n        fix j\n        assume dd0: \"Suc j < length c'\"\n        have \"(\\<exists>t k. (\\<Gamma> \\<turnstile> (c'!j) -pes-(t\\<sharp>k)\\<rightarrow> (c'!Suc j)) \\<and>\n                      (\\<forall>k t. (\\<Gamma> \\<turnstile> c'!j -pes-(t\\<sharp>k)\\<rightarrow> c'!Suc j) \\<longrightarrow> (\\<Gamma> \\<turnstile> ?cs' k!j -es-(t\\<sharp>k)\\<rightarrow> ?cs' k! Suc j) \\<and>\n                                      (\\<forall>k'. k' \\<noteq> k \\<longrightarrow> (\\<Gamma> \\<turnstile> ?cs' k'!j -ese\\<rightarrow> ?cs' k'! Suc j))))\n                      \\<or>\n                      ((\\<Gamma> \\<turnstile> (c'!j) -pese\\<rightarrow> (c'!Suc j)) \\<and> (\\<forall>k. (\\<Gamma> \\<turnstile> ((?cs' k)!j) -ese\\<rightarrow> ((?cs' k)! Suc j))))\"\n          proof(cases \"j = 0\")\n            assume d0: \"j = 0\"\n            from p3 have \"(\\<Gamma> \\<turnstile> (c'!0) -pese\\<rightarrow> (c'!1))\"\n              by (simp add: pesetran.intros) \n            moreover\n            have \"\\<forall>k. (\\<Gamma> \\<turnstile> ((?cs' k)!0) -ese\\<rightarrow> ((?cs' k)!1))\"\n              by (simp add: b3 esetran.intros) \n            ultimately show ?thesis using d0 by simp\n          next\n            assume d0: \"j \\<noteq> 0\"\n            then have d0_1: \"j > 0\" by simp\n            from p2 have \"compat_tran \\<Gamma> c cs\" by (simp add:conjoin_def)\n            then have d1: \"\\<forall>j. Suc j < length c \\<longrightarrow> \n                              (\\<exists>t k. (\\<Gamma> \\<turnstile> c!j -pes-(t\\<sharp>k)\\<rightarrow> c!Suc j) \\<and>\n                              (\\<forall>k t. (\\<Gamma> \\<turnstile> c!j -pes-(t\\<sharp>k)\\<rightarrow> c!Suc j) \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k!j -es-(t\\<sharp>k)\\<rightarrow> cs k! Suc j) \\<and>\n                                      (\\<forall>k'. k' \\<noteq> k \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k'!j -ese\\<rightarrow> cs k'! Suc j))))\n                              \\<or>\n                              ((\\<Gamma> \\<turnstile> (c!j) -pese\\<rightarrow> (c!Suc j)) \\<and> (\\<forall>k. (\\<Gamma> \\<turnstile> ((cs k)!j) -ese\\<rightarrow> ((cs k)! Suc j))))\"\n               by (simp add:compat_tran_def)\n            from p3 p4 dd0 d0 have d2: \"Suc (j-1) < length c\" by auto\n            let ?j1 = \"j - 1\"\n            from d1 d2 have d3: \"(\\<exists>t k. (\\<Gamma> \\<turnstile> c!(j-1) -pes-(t\\<sharp>k)\\<rightarrow> c!Suc (j-1)) \\<and>\n                              (\\<forall>k t. (\\<Gamma> \\<turnstile> c!(j-1) -pes-(t\\<sharp>k)\\<rightarrow> c!Suc (j-1)) \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k!(j-1) -es-(t\\<sharp>k)\\<rightarrow> cs k! Suc (j-1)) \\<and>\n                                      (\\<forall>k'. k' \\<noteq> k \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k'!(j-1) -ese\\<rightarrow> cs k'! Suc (j-1)))))\n                              \\<or>\n                              ((\\<Gamma> \\<turnstile> (c!(j-1)) -pese\\<rightarrow> (c!Suc (j-1))) \\<and> (\\<forall>k. (\\<Gamma> \\<turnstile> ((cs k)!(j-1)) -ese\\<rightarrow> ((cs k)!Suc (j-1)))))\"\n               by auto\n            from p3 p4 d0 dd0 have d4: \"c'!j = c!(j-1) \\<and> c'!Suc j = c!Suc (j-1)\" by simp\n            have d5: \"(\\<forall>k. (?cs' k) ! j= (cs k)! (j-1)) \\<and> (\\<forall>k. (?cs' k) ! Suc j= (cs k)! Suc (j-1))\" \n              by (simp add: d0_1) \n            with d3 d4 show ?thesis by auto\n          qed\n        \n      }\n      then show ?thesis by (simp add:compat_tran_def)\n      qed\n  qed\n\nlemma comp_tran_pestran: \"\\<lbrakk>(\\<forall>k. cs k \\<in> cpts_of_es \\<Gamma> (pes2 k) t1 x1); c = (pes2, t1, x1) # xs; c\\<in>cpts_pes \\<Gamma>; \n                       \\<Gamma> c \\<propto> cs; c' = (pes1, s1, y1) # (pes2, t1, x1) # xs; \\<Gamma> \\<turnstile> (pes1, s1, y1) -pes-ct\\<rightarrow> (pes2, t1, x1)\\<rbrakk>\n                        \\<Longrightarrow> compat_tran \\<Gamma> c' (\\<lambda>k. (pes1 k, s1, y1) # cs k)\"\n  proof -\n    let ?cs' = \"\\<lambda>k. (pes1 k, s1, y1) # cs k\"\n    assume p0: \"\\<forall>k. cs k \\<in> cpts_of_es \\<Gamma> (pes2 k) t1 x1\"\n      and  p1: \"c \\<in> cpts_pes \\<Gamma>\"\n      and  p2: \"\\<Gamma> c \\<propto> cs\"\n      and  p3: \"c' = (pes1, s1, y1) # (pes2, t1, x1) # xs\"\n      and  p4: \"c = (pes2, t1, x1) # xs\"\n      and  p5: \"\\<Gamma> \\<turnstile> (pes1, s1, y1) -pes-ct\\<rightarrow> (pes2, t1, x1)\"\n    from p0 have b3: \"\\<forall>k. cs k \\<in> cpts_es \\<Gamma> \\<and> (cs k)!0 = (pes2 k,t1,x1)\" by (simp add:cpts_of_es_def)\n    show \"compat_tran \\<Gamma> c' ?cs'\"\n      proof -\n      {\n        fix j\n        assume dd0: \"Suc j < length c'\"\n        have \"(\\<exists>t k. (\\<Gamma> \\<turnstile> (c'!j) -pes-(t\\<sharp>k)\\<rightarrow> (c'!Suc j)) \\<and>\n                      (\\<forall>k t. (\\<Gamma> \\<turnstile> c'!j -pes-(t\\<sharp>k)\\<rightarrow> c'!Suc j) \\<longrightarrow> (\\<Gamma> \\<turnstile> ?cs' k!j -es-(t\\<sharp>k)\\<rightarrow> ?cs' k! Suc j) \\<and>\n                                      (\\<forall>k'. k' \\<noteq> k \\<longrightarrow> (\\<Gamma> \\<turnstile> ?cs' k'!j -ese\\<rightarrow> ?cs' k'! Suc j))))\n                      \\<or>\n                      ((\\<Gamma> \\<turnstile> (c'!j) -pese\\<rightarrow> (c'!Suc j)) \\<and> (\\<forall>k. (\\<Gamma> \\<turnstile> ((?cs' k)!j) -ese\\<rightarrow> ((?cs' k)! Suc j))))\"\n          proof(cases \"j = 0\")\n            assume d0: \"j = 0\"\n            from p5 obtain k and aa where c0: \"ct = (aa\\<sharp>k)\" using get_actk_def by (metis cases) \n            with p5 have \"\\<exists>es'. (\\<Gamma> \\<turnstile> (pes1 k, s1, y1) -es-(aa\\<sharp>k)\\<rightarrow> (es', t1, x1)) \\<and> pes2 = pes1(k:=es')\" \n              using pestran_estran by auto\n            then obtain es' where c1: \"(\\<Gamma> \\<turnstile> (pes1 k, s1, y1) -es-(aa\\<sharp>k)\\<rightarrow> (es', t1, x1)) \\<and> pes2 = pes1(k:=es')\"\n              by auto\n            from b3 have c2: \"cs k \\<in>cpts_es \\<Gamma> \\<and> (cs k)!0 = (pes2 k,t1,x1)\" by auto\n            then obtain xs1 where c4: \"(cs k) = (pes2 k,t1,x1)#xs1\"\n              by (metis cpts_es_not_empty neq_Nil_conv nth_Cons_0) \n            then have c3: \"?cs' k = (pes1 k, s1, y1) # (pes2 k,t1,x1)#xs1\" by simp\n\n            from p3 p5 c0 have g0: \"\\<Gamma> \\<turnstile> (c'!0) -pes-(aa\\<sharp>k)\\<rightarrow> (c'!Suc 0)\" by auto\n            moreover\n            have \"\\<forall>k1 t1. (\\<Gamma> \\<turnstile> c'!0 -pes-(t1\\<sharp>k1)\\<rightarrow> c'!Suc 0) \\<longrightarrow> (\\<Gamma> \\<turnstile> ?cs' k1!0 -es-(t1\\<sharp>k1)\\<rightarrow> ?cs' k1! Suc 0) \\<and>\n                                      (\\<forall>k'. k' \\<noteq> k1 \\<longrightarrow> (\\<Gamma> \\<turnstile> ?cs' k'!0 -ese\\<rightarrow> ?cs' k'! Suc 0))\"\n              proof -\n              {\n                fix k1 t1\n                assume d0: \"\\<Gamma> \\<turnstile> c'!0 -pes-(t1\\<sharp>k1)\\<rightarrow> c'!Suc 0\"\n                with p3 have \"\\<Gamma> \\<turnstile> ?cs' k1!0 -es-(t1\\<sharp>k1)\\<rightarrow> ?cs' k1! Suc 0\"\n                  using b3 fun_upd_apply nth_Cons_0 nth_Cons_Suc pestran_estran by fastforce\n                moreover\n                from d0 have \"\\<forall>k'. k' \\<noteq> k1 \\<longrightarrow> (\\<Gamma> \\<turnstile> ?cs' k'!0 -ese\\<rightarrow> ?cs' k'! Suc 0)\"\n                  using b3 esetran.intros fun_upd_apply nth_Cons_0 nth_Cons_Suc p3 pestran_estran by fastforce\n                ultimately have \"(\\<Gamma> \\<turnstile> c'!0 -pes-(t1\\<sharp>k1)\\<rightarrow> c'!Suc 0) \\<longrightarrow> (\\<Gamma> \\<turnstile> ?cs' k1!0 -es-(t1\\<sharp>k1)\\<rightarrow> ?cs' k1! Suc 0) \\<and>\n                                      (\\<forall>k'. k' \\<noteq> k1 \\<longrightarrow> (\\<Gamma> \\<turnstile> ?cs' k'!0 -ese\\<rightarrow> ?cs' k'! Suc 0))\" by simp\n              }\n              then show ?thesis by auto\n              qed\n            ultimately show ?thesis using d0 by auto\n          next\n            assume d0: \"j \\<noteq> 0\"\n            then have d0_1: \"j > 0\" by simp\n            from p2 have \"compat_tran \\<Gamma> c cs\" by (simp add:conjoin_def)\n            then have d1: \"\\<forall>j. Suc j < length c \\<longrightarrow> \n                              (\\<exists>t k. (\\<Gamma> \\<turnstile> c!j -pes-(t\\<sharp>k)\\<rightarrow> c!Suc j) \\<and>\n                              (\\<forall>k t. (\\<Gamma> \\<turnstile> c!j -pes-(t\\<sharp>k)\\<rightarrow> c!Suc j) \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k!j -es-(t\\<sharp>k)\\<rightarrow> cs k! Suc j) \\<and>\n                                      (\\<forall>k'. k' \\<noteq> k \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k'!j -ese\\<rightarrow> cs k'! Suc j))))\n                              \\<or>\n                              ((\\<Gamma> \\<turnstile> (c!j) -pese\\<rightarrow> (c!Suc j)) \\<and> (\\<forall>k. (\\<Gamma> \\<turnstile> ((cs k)!j) -ese\\<rightarrow> ((cs k)! Suc j))))\"\n               by (simp add:compat_tran_def)\n            from p3 p4 dd0 d0 have d2: \"Suc (j-1) < length c\" by auto\n            with d0 d0_1 d1 have d3: \"(\\<exists>t k. (\\<Gamma> \\<turnstile> c!(j-1) -pes-(t\\<sharp>k)\\<rightarrow> c!Suc (j-1)) \\<and>\n                              (\\<forall>k t. (\\<Gamma> \\<turnstile> c!(j-1) -pes-(t\\<sharp>k)\\<rightarrow> c!Suc (j-1)) \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k!(j-1) -es-(t\\<sharp>k)\\<rightarrow> cs k! Suc (j-1)) \\<and>\n                                      (\\<forall>k'. k' \\<noteq> k \\<longrightarrow> (\\<Gamma> \\<turnstile> cs k'!(j-1) -ese\\<rightarrow> cs k'! Suc (j-1)))))\n                              \\<or>\n                              ((\\<Gamma> \\<turnstile> (c!(j-1)) -pese\\<rightarrow> (c!Suc (j-1))) \\<and> (\\<forall>k. (\\<Gamma> \\<turnstile> ((cs k)!(j-1)) -ese\\<rightarrow> ((cs k)!Suc (j-1)))))\"\n              by blast\n            from p3 p4 d0 dd0 have d4: \"c'!j = c!(j-1) \\<and> c'!Suc j = c!Suc (j-1)\" by simp\n            have d5: \"(\\<forall>k. (?cs' k) ! j= (cs k)! (j-1)) \\<and> (\\<forall>k. (?cs' k) ! Suc j= (cs k)! Suc (j-1))\" \n              by (simp add: d0_1) \n            with d3 d4 show ?thesis by auto\n          qed\n        \n      }\n      then show ?thesis by (simp add:compat_tran_def)\n      qed\n  qed\n\nlemma cpt_imp_exist_conjoin_cs0: \n    \"\\<forall>c. c \\<in> cpts_pes \\<Gamma> \\<longrightarrow>\n                (\\<exists>cs. (\\<forall>k. (cs k) \\<in> cpts_of_es \\<Gamma> ((getspc (c!0)) k) (gets (c!0)) (getx (c!0))) \\<and> \\<Gamma> c \\<propto> cs)\"\n  proof -\n  {\n    fix c\n    assume p0: \"c \\<in> cpts_pes \\<Gamma>\"\n    then have \"\\<exists>cs. (\\<forall>k. (cs k) \\<in> cpts_of_es \\<Gamma> ((getspc (c!0)) k) (gets (c!0)) (getx (c!0))) \\<and> \\<Gamma> c \\<propto> cs\"\n      proof(induct c)\n        case (CptsPesOne pes1 s1 x1)\n        let ?cs = \"\\<lambda>k. [(pes1 k, s1,x1)]\" \n        let ?c = \"[(pes1, s1, x1)]\"\n        have \"\\<forall>k. ?cs k \\<in> cpts_of_es \\<Gamma> (getspc (?c ! 0) k) (gets (?c ! 0)) (getx (?c ! 0))\"\n          proof -\n          {\n            fix k\n            have \"?cs k = [(pes1 k,s1,x1)]\" by simp\n            moreover\n            have \"?cs k \\<in> cpts_es \\<Gamma>\" by (simp add: cpts_es.CptsEsOne) \n            ultimately have \"?cs k \\<in> cpts_of_es \\<Gamma> (pes1 k) s1 x1\" by (simp add: cpts_of_es_def)\n          }\n          then show ?thesis by (simp add: gets_def getspc_def getx_def) \n          qed\n        moreover\n        have \"\\<Gamma> ?c \\<propto> ?cs\"\n          proof -\n            have \"same_length ?c ?cs\" by (simp add: same_length_def) \n            moreover\n            have \"same_state ?c ?cs\" using same_state_def gets_def gets_es_def getx_def getx_es_def\n              by (smt length_Cons less_Suc0 list.size(3) nth_Cons_0 snd_conv) \n            moreover\n            have \"same_spec ?c ?cs\" using same_spec_def getspc_def getspc_es_def\n              by (metis (mono_tags, lifting) fst_conv length_Cons less_Suc0 list.size(3) nth_Cons_0)\n            moreover\n            have \"compat_tran \\<Gamma> ?c ?cs\" by (simp add: compat_tran_def) \n            ultimately show ?thesis by (simp add:conjoin_def)\n          qed\n        ultimately show ?case by auto\n      next\n        case (CptsPesEnv pes1 t1 x1 xs s1 y1)\n        let ?c = \"(pes1, t1, x1) # xs\"\n        assume b0: \"?c\\<in> cpts_pes \\<Gamma>\"\n          and  b1: \"\\<exists>cs. (\\<forall>k. cs k \\<in> cpts_of_es \\<Gamma> (getspc (?c ! 0) k) (gets (?c ! 0))\n                       (getx (?c ! 0))) \\<and> \\<Gamma> ?c \\<propto> cs\"\n        then obtain cs where b2: \"(\\<forall>k. cs k \\<in> cpts_of_es \\<Gamma> (pes1 k) t1 x1) \\<and> \\<Gamma> ?c \\<propto> cs\" \n          using getspc_def gets_def getx_def by (metis fst_conv nth_Cons_0 snd_conv) \n        then have b3: \"\\<forall>k. cs k \\<in> cpts_es \\<Gamma> \\<and> (cs k)!0 = (pes1 k,t1,x1)\" by (simp add:cpts_of_es_def)\n        let ?c' = \"(pes1, s1, y1) # (pes1, t1, x1) # xs\"\n        let ?cs' = \"\\<lambda>k. (pes1 k,s1,y1)#(cs k)\" \n        have g0: \"\\<forall>k. ?cs' k \\<in> cpts_of_es \\<Gamma> (getspc (?c' ! 0) k)  (gets (?c' ! 0)) (getx (?c' ! 0))\" \n          proof -\n          {\n            fix k\n            from b3 have c0: \"cs k \\<in>cpts_es \\<Gamma> \\<and> (cs k)!0 = (pes1 k,t1,x1)\" by auto\n            then obtain xs1 where \"(cs k) = (pes1 k,t1,x1)#xs1\"\n              by (metis cpts_es_not_empty neq_Nil_conv nth_Cons_0) \n            with c0 have c1: \"?cs' k \\<in> cpts_es \\<Gamma>\" by (simp add: cpts_es.CptsEsEnv) \n            then have \"?cs' k \\<in> cpts_of_es \\<Gamma> (getspc (?c' ! 0) k)  (gets (?c' ! 0)) (getx (?c' ! 0))\" \n              by (simp add: cpts_of_es_def gets_def getspc_def getx_def) \n          }\n          then show ?thesis by auto\n          qed\n        from b2 have b4: \"\\<Gamma> ?c \\<propto> cs\" by simp\n        from b1 have g1: \"\\<Gamma> ?c' \\<propto> ?cs'\"\n          proof -\n            from b4 have \"same_length ?c' ?cs'\"\n              by (simp add: conjoin_def same_length_def) \n            moreover\n            have \"same_state ?c' ?cs'\"\n              proof -\n              {\n                fix k' j\n                assume c0: \"j < length ?c'\"\n                have \"gets (?c'!j) = gets_es ((?cs' k')!j) \\<and> getx (?c'!j) = getx_es ((?cs' k')!j)\"\n                  proof(cases \"j = 0\")\n                    assume d0: \"j = 0\"\n                    then show ?thesis by (simp add:gets_def gets_es_def getx_def getx_es_def) \n                  next\n                    assume d0: \"j \\<noteq> 0\"\n                    with b4 show ?thesis using same_state_def gets_def gets_es_def getx_def getx_es_def\n                      using c0 conjoin_def length_Cons less_Suc_eq_0_disj nth_Cons_Suc by fastforce\n                  qed\n              }\n              then show ?thesis by (simp add: same_state_def) \n              qed\n\n            moreover \n            have \"same_spec ?c' ?cs'\"\n              proof -\n              {\n                fix k' j\n                assume c0: \"j < length ?c'\"\n                have \"(getspc (?c'!j)) k' = getspc_es ((?cs' k') ! j)\"\n                  proof(cases \"j = 0\")\n                    assume d0: \"j = 0\"\n                    then show ?thesis by (simp add:getspc_def getspc_es_def) \n                  next\n                    assume d0: \"j \\<noteq> 0\"\n                    with b4 show ?thesis using same_spec_def getspc_def getspc_es_def\n                      by (metis (no_types, lifting) Nat.le_diff_conv2 One_nat_def c0 conjoin_def \n                        less_Suc0 list.size(4) not_less nth_Cons')\n                  qed\n              }\n              then show ?thesis by (simp add: same_spec_def) \n              qed\n            moreover\n            from b0 b2 b4 have \"compat_tran \\<Gamma> ?c' ?cs'\" \n              using comp_tran_env [of cs \\<Gamma> pes1 t1 x1 ?c xs ?c' s1 y1] by simp\n            ultimately show ?thesis by (simp add:conjoin_def)\n          qed\n        from g0 g1 show ?case by auto\n      next\n        case (CptsPesComp pes1 s1 y1 ct pes2 t1 x1 xs)\n        let ?c = \"(pes2, t1, x1) # xs\"\n        assume b0: \"?c\\<in> cpts_pes \\<Gamma>\"\n          and  b1: \"\\<exists>cs. (\\<forall>k. cs k \\<in> cpts_of_es \\<Gamma> (getspc (?c ! 0) k) (gets (?c ! 0))\n                       (getx (?c ! 0))) \\<and> \\<Gamma> ?c \\<propto> cs\"\n          and  b00: \"\\<Gamma> \\<turnstile> (pes1, s1, y1) -pes-ct\\<rightarrow> (pes2, t1, x1)\"\n        then obtain cs where b2: \"(\\<forall>k. cs k \\<in> cpts_of_es \\<Gamma> (pes2 k) t1 x1) \\<and> \\<Gamma> ?c \\<propto> cs\" \n          using getspc_def gets_def getx_def by (metis fst_conv nth_Cons_0 snd_conv) \n        then have b3: \"\\<forall>k. cs k \\<in> cpts_es \\<Gamma> \\<and> (cs k)!0 = (pes2 k,t1,x1)\" by (simp add:cpts_of_es_def)\n        let ?c' = \"(pes1, s1, y1) # (pes2, t1, x1) # xs\"\n        let ?cs' = \"\\<lambda>k. (pes1 k,s1,y1)#(cs k)\" \n        have g0: \"\\<forall>k. ?cs' k \\<in> cpts_of_es \\<Gamma> (getspc (?c' ! 0) k)  (gets (?c' ! 0)) (getx (?c' ! 0))\" \n          proof -\n          {\n            fix k\n            obtain ka and aa where c0: \"ct = (aa\\<sharp>ka)\" using get_actk_def by (metis cases) \n            with b00 have \"\\<exists>es'. (\\<Gamma> \\<turnstile> (pes1 ka, s1, y1) -es-(aa\\<sharp>ka)\\<rightarrow> (es', t1, x1)) \\<and> pes2 = pes1(ka:=es')\" \n              using pestran_estran by auto\n            then obtain es' where c1: \"(\\<Gamma> \\<turnstile> (pes1 ka, s1, y1) -es-(aa\\<sharp>ka)\\<rightarrow> (es', t1, x1)) \\<and> pes2 = pes1(ka:=es')\"\n              by auto\n            from b3 have c2: \"cs k \\<in>cpts_es \\<Gamma> \\<and> (cs k)!0 = (pes2 k,t1,x1)\" by auto\n            then obtain xs1 where c4: \"(cs k) = (pes2 k,t1,x1)#xs1\"\n              by (metis cpts_es_not_empty neq_Nil_conv nth_Cons_0) \n            then have c3: \"?cs' k = (pes1 k, s1, y1) # (pes2 k,t1,x1)#xs1\" by simp\n            have \"?cs' k \\<in> cpts_of_es \\<Gamma> (getspc (?c' ! 0) k)  (gets (?c' ! 0)) (getx (?c' ! 0))\" \n              proof(cases \"k = ka\")\n                assume d0: \"k = ka\"\n                with c1 have \"\\<Gamma> \\<turnstile> (pes1 k, s1, y1) -es-(aa\\<sharp>k)\\<rightarrow> (pes2 k, t1, x1)\" by auto\n                with c2 c3 d0 have \"?cs' k \\<in> cpts_es \\<Gamma>\"\n                  using cpts_es.CptsEsComp by fastforce \n                then show ?thesis by (simp add: cpts_of_es_def gets_def getspc_def getx_def)\n              next\n                assume d0: \"k \\<noteq> ka\"\n                with c1 have \"pes1 k = pes2 k\" by simp\n                with c2 c3 have d1: \"?cs' k \\<in> cpts_es \\<Gamma>\"\n                  by (simp add: cpts_es.CptsEsEnv)  \n                then show ?thesis by (simp add: cpts_of_es_def gets_def getspc_def getx_def) \n              qed\n          }\n          then show ?thesis by auto\n          qed\n        from b2 have b4: \"\\<Gamma> ?c \\<propto> cs\" by simp\n        from b1 have g1: \"\\<Gamma> ?c' \\<propto> ?cs'\"\n          proof -\n            from b4 have \"same_length ?c' ?cs'\"\n              by (simp add: conjoin_def same_length_def) \n            moreover\n            have \"same_state ?c' ?cs'\"\n              proof -\n              {\n                fix k' j\n                assume c0: \"j < length ?c'\"\n                have \"gets (?c'!j) = gets_es ((?cs' k')!j) \\<and> getx (?c'!j) = getx_es ((?cs' k')!j)\"\n                  proof(cases \"j = 0\")\n                    assume d0: \"j = 0\"\n                    then show ?thesis by (simp add:gets_def gets_es_def getx_def getx_es_def) \n                  next \n                    assume d0: \"j \\<noteq> 0\"\n                    with b4 show ?thesis using same_state_def gets_def gets_es_def getx_def getx_es_def\n                      using c0 conjoin_def length_Cons less_Suc_eq_0_disj nth_Cons_Suc by fastforce\n                  qed\n              }\n              then show ?thesis by (simp add: same_state_def) \n              qed\n\n            moreover \n            have \"same_spec ?c' ?cs'\"\n              proof -\n              {\n                fix k' j\n                assume c0: \"j < length ?c'\"\n                have \"(getspc (?c'!j)) k' = getspc_es ((?cs' k') ! j)\"\n                  proof(cases \"j = 0\")\n                    assume d0: \"j = 0\"\n                    then show ?thesis by (simp add:getspc_def getspc_es_def) \n                  next\n                    assume d0: \"j \\<noteq> 0\"\n                    with b4 show ?thesis using same_spec_def getspc_def getspc_es_def\n                      by (metis (no_types, lifting) Nat.le_diff_conv2 One_nat_def Suc_leI c0 conjoin_def \n                        list.size(4) neq0_conv not_less nth_Cons')\n                  qed\n              }\n              then show ?thesis by (simp add: same_spec_def) \n              qed\n            moreover\n            from b0 b00 b2 b4 have \"compat_tran \\<Gamma> ?c' ?cs'\" \n              using comp_tran_pestran [of cs \\<Gamma> pes2 t1 x1 ?c xs ?c' pes1 s1 y1 ct] by simp\n\n            ultimately show ?thesis by (simp add:conjoin_def)\n          qed\n        from g0 g1 show ?case by auto\n      qed\n      \n  }\n  then show ?thesis by (metis (mono_tags, lifting)) \n  qed\n\n\nlemma cpt_imp_exist_conjoin_cs: \"c \\<in> cpts_of_pes \\<Gamma> pes s x\n                \\<Longrightarrow> \\<exists>cs. (\\<forall>k. (cs k) \\<in> cpts_of_es \\<Gamma> (pes k) s x) \\<and> \\<Gamma> c \\<propto> cs\"\n  proof -\n    assume p0: \"c \\<in> cpts_of_pes \\<Gamma> pes s x\"\n    then have \"c!0=(pes,s,x) \\<and> c \\<in> cpts_pes \\<Gamma>\" by (simp add:cpts_of_pes_def)\n    then show ?thesis \n      using cpt_imp_exist_conjoin_cs0 getspc_def gets_def getx_def\n        by (metis fst_conv snd_conv) \n  qed\n\ntheorem par_evtsys_semantics_comp: \n  \"cpts_of_pes \\<Gamma> pes s x = {c. \\<exists>cs. (\\<forall>k. (cs k) \\<in> cpts_of_es \\<Gamma> (pes k) s x) \\<and> \\<Gamma> c \\<propto> cs}\"\n  proof -\n    have \"\\<forall>c. c\\<in>cpts_of_pes \\<Gamma> pes s x \\<longrightarrow> (\\<exists>cs. (\\<forall>k. (cs k) \\<in> cpts_of_es \\<Gamma> (pes k) s x) \\<and> \\<Gamma> c \\<propto> cs)\"\n      proof -\n      {\n        fix c\n        assume a0: \"c\\<in>cpts_of_pes \\<Gamma> pes s x\"\n        then have \"\\<exists>cs. (\\<forall>k. (cs k) \\<in> cpts_of_es \\<Gamma> (pes k) s x) \\<and> \\<Gamma> c \\<propto> cs\"\n          using cpt_imp_exist_conjoin_cs cpts_of_pes_def getx_def mem_Collect_eq prod.sel(2) by fastforce \n      }\n      then show ?thesis by auto\n      qed\n    moreover\n    have \"\\<forall>c. (\\<exists>cs. (\\<forall>k. (cs k) \\<in> cpts_of_es \\<Gamma> (pes k) s x) \\<and> \\<Gamma> c \\<propto> cs) \\<longrightarrow> c\\<in>cpts_of_pes \\<Gamma> pes s x\"\n      proof -\n      {\n        fix c\n        assume a0: \"\\<exists>cs. (\\<forall>k. (cs k) \\<in> cpts_of_es \\<Gamma> (pes k) s x) \\<and> \\<Gamma> c \\<propto> cs\"\n        then have \"c\\<in>cpts_of_pes \\<Gamma> pes s x\"\n          using conjoin_cs_imp_cpt by fastforce \n      }\n      then show ?thesis by auto\n      qed\n    ultimately show ?thesis by auto\n  qed\n\nend\n\nend (*end of theory Computation*)", "meta": {"author": "SunHuan321", "repo": "uc-OS-verification", "sha": "760e159857c4015d6a9e3ccbe9f8247e4518862a", "save_path": "github-repos/isabelle/SunHuan321-uc-OS-verification", "path": "github-repos/isabelle/SunHuan321-uc-OS-verification/uc-OS-verification-760e159857c4015d6a9e3ccbe9f8247e4518862a/PiCore/PiCore_Computation.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5234203489363242, "lm_q2_score": 0.480478678047907, "lm_q1q2_score": 0.25149231732029925}}
{"text": "(*\n\nCopyright (c) 2017, ETH Zurich\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n\n1. Redistributions of source code must retain the above copyright notice, this\n   list of conditions and the following disclaimer.\n2. Redistributions in binary form must reproduce the above copyright notice,\n   this list of conditions and the following disclaimer in the documentation\n   and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\nDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR\nANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\nLOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\nON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n*)\n\n(* ######################################################################### *) \nchapter \"Exception Handler for the MIPS R4600\"\n(* ######################################################################### *)\n\n\n(*<*)\ntheory MipsTLBReplacementHandler\n  imports MipsTLB MipsTLBPageTable \nbegin\n(*>*)\n\ntext \"This is a non-deterministic model of a TLB with replacement handler\n      for the MIPS R4600 TLB model.\"\n\n  \n(* ========================================================================= *)  \nsection \"MIPS TLB + MIPS PageTables\"\n(* ========================================================================= *)    \n  \ntext \"We define the the TLB + page table combinations as a record of a TLB\n      instance and a page table instance where the TLB entries will always \n      be filled based on the entries of the page table.\"\n  \nrecord MipsTLBPT = \n  tlb :: MIPSTLB\n  pte :: MIPSPT\n\n    \n  \n(* ========================================================================= *)  \nsection \"Non-deterministic Exception Handler\"\n(* ========================================================================= *)\n  \ntext \"The non-deterministic replacement handler uses the random write function\n      of the TLB to non-deterministically replace an existing entry with the\n      new one. Note, that this definition alone won't preserve the validity\n      constraints of the TLB as defined in the TLBValid predicate, in\n      particular, when its being invoked with the same ASID and VPN twice.\"  \n            \n  \ndefinition MipsTLBPT_update_tlb :: \"MipsTLBPT \\<Rightarrow> ASID \\<Rightarrow> VPN \\<Rightarrow> MipsTLBPT set\"\n  where \"MipsTLBPT_update_tlb mpt as vpn = \n          {\\<lparr>tlb = t, pte = (pte mpt)\\<rparr> | \n            t. t\\<in> tlbwr (MIPSPT_mk_tlbentry (pte mpt) as vpn) (tlb mpt)}\"\n\n\n(* ========================================================================= *)  \nsection \"Fault Function\"\n(* ========================================================================= *)                                     \n\ntext \"While the update function purely updates the entry, the definition of the\n      fault function effectively simulates a translate attempt and invokes\n      the update function when a refill exception occurs. If an entry is \n      present, then the state of the TLB is not changed. \"\n    \ndefinition MipsTLBPT_fault :: \"MipsTLBPT \\<Rightarrow> ASID \\<Rightarrow> VPN \\<Rightarrow> MipsTLBPT set\"\n  where \"MipsTLBPT_fault  mtlb as vpn = \n      (if MIPSTLB_try_translate (tlb mtlb) as vpn = EXNREFILL then \n          MipsTLBPT_update_tlb mtlb as vpn\n      else {mtlb})\"      \n    \n\ntext \"Therefore we can proof that if the TLB does not throw the refill \n      exception, the faulting function won't change the state of the TLB\n      i.e. the input MipsTLBPT is the same as the output.\"\n    \nlemma MipsTLBPT_fault_no_change:\n  \"\\<forall>vpn as. MIPSTLB_try_translate (tlb m) as vpn \\<noteq> EXNREFILL \\<Longrightarrow>\n            (\\<forall>m2 \\<in> MipsTLBPT_fault m as vpn. m = m2)\"\n  by(simp add: MipsTLBPT_fault_def)\n    \n \n    \n(* ========================================================================= *)  \nsection \"Valid TLB and page tables\"\n(* ========================================================================= *) \n\n  \ntext \"We say that the combination of a TLB and page tables is valid if both, \n      the TLB and the page table are valid and additionally, the TLB must be\n      an instance of the page table.\"  \n  \n(* ------------------------------------------------------------------------- *)  \nsubsection \"Instance\"\n(* ------------------------------------------------------------------------- *)\n\ntext \"A TLB is an instance of a page table if for all entries in the TLB there\n      is a corresponding, equal entry in the page table. In other words, the\n      entry of the TLB must be equal to a created entry from the page table\n      using the very same VPN and ASID.\"\n        \ndefinition MipsTLBPT_is_instance ::  \"MipsTLBPT \\<Rightarrow> bool\"\n  where \"MipsTLBPT_is_instance mt = \n    (\\<forall>i <  (capacity (tlb mt)).  entries (tlb mt) i = \n        MIPSPT_mk_tlbentry (pte mt) (asid (hi (entries (tlb mt) i) ))  \n                                    (vpn2 (hi (entries (tlb mt) i) )))\"\n\n    \n(* ------------------------------------------------------------------------- *)  \nsubsection \"Validity\"\n(* ------------------------------------------------------------------------- *)\n  \ntext \"We therefore can define the validity of a  TLB + PageTable combination\n      as the logic and of the validity of the page tables and the TLB\n      independently, and together with the instance definition from above.\"\n  \ndefinition MipsTLBPT_valid :: \"MipsTLBPT \\<Rightarrow> bool\"\n  where \"MipsTLBPT_valid mt = ((MIPSPT_valid (pte mt)) \n                              \\<and> (TLBValid (tlb mt)) \n                              \\<and> (MipsTLBPT_is_instance mt) )\"   \n\n \n\n        \n\n(* ========================================================================= *)  \nsection \"Translate Function\"\n(* ========================================================================= *)    \n\ntext \"The translation function first faults on the TLB. This has the effect that\n      if the entry is not present, it gets placed in the TLB. Then the translate\n      attempt is made, which results in an empty set if the entry was not valid.\"\n       \n  \ndefinition MipsTLBPT_translate :: \"MipsTLBPT \\<Rightarrow> ASID \\<Rightarrow> VPN \\<Rightarrow> PFN set\"\n  where \"MipsTLBPT_translate  mtlb as vpn = \n    \\<Union>{ MIPSTLB_translate (tlb m) as vpn | m . m \\<in> MipsTLBPT_fault mtlb as vpn}\"\n\n    \nlemma \n  assumes valid : \"MipsTLBPT_valid mtlb\"\n  shows \"MipsTLBPT_translate mtlb as vpn = MIPSPT_translate (pte mtlb) as vpn\"\n oops\n\n\n(* ========================================================================= *)  \nsection \"Translate Function\"\n(* ========================================================================= *)    \n\n  \n\nlemma MipsTLBPT_instance_no_global:\n  assumes  valid: \"MipsTLBPT_valid m\"\n    and inrange : \"i < (capacity (tlb m))\"\n  shows \"\\<not> EntryIsGlobal (entries (tlb m) i)\"  \nproof -\n  from valid have inst :\n      \"MipsTLBPT_is_instance (m)\"\n    by(simp add:MipsTLBPT_valid_def)           \n      \n  from inst inrange have X0:  \"\n        entries (tlb m) i = MIPSPT_mk_tlbentry (pte m) (asid (hi (entries (tlb m) i) ))  \n                                                       (vpn2 (hi (entries (tlb m) i) ))\"\n    by(simp add:MipsTLBPT_is_instance_def)\n  \n  from valid have X1: \"\\<not> EntryIsGlobal (MIPSPT_mk_tlbentry (pte m) (asid (hi (entries (tlb m) i) ))  \n                                                     (vpn2 (hi (entries (tlb m) i) )))\"      \n    by(simp add:MIPSPT_TLBENTRY_not_global MipsTLBPT_valid_def )\n\n  from X0 X1 show ?thesis\n    by(auto)\nqed\n    \nlemma MipsTLBPT_instance_entry_is_4k:\n  assumes  valid: \"MipsTLBPT_valid m\"\n     and inrange : \"i < (capacity (tlb m))\"\n   shows \"(mask (entries (tlb m) i)) = MASK4K\" \nproof -\n  from valid inrange have X0:\n    \"entries (tlb m) i = MIPSPT_mk_tlbentry (pte m) (asid (hi (entries (tlb m) i) ))  \n                                                    (vpn2 (hi (entries (tlb m) i) ))\"\n    by(simp add: MipsTLBPT_valid_def MipsTLBPT_is_instance_def)\n  \n  have X1:\n    \"(mask (MIPSPT_mk_tlbentry (pte m) (asid (hi (entries (tlb m) i) ))  \n                                       (vpn2 (hi (entries (tlb m) i))))) = MASK4K\"\n    by(simp add:MIPSPT_TLBENTRY_mask_is)    \n  \n  from X0 X1 show ?thesis \n    by(auto)\nqed\n      \n\n  \n   \n(* ========================================================================= *)  \nsection \"The Fault Function Preserves Validity\"\n(* ========================================================================= *)    \n\ntext \"Next we proof that whenever the validity condition holds and the ASID/VPN\n      are in the valid ranges then the fault function will result in a valid state.\n      For this purpose we split up the proof into the three conditions and in the\n      end use the lemmas to prove the validity.\"  \n\n(* ------------------------------------------------------------------------- *)   \nsubsection \"Instance Preservation\"  \n(* ------------------------------------------------------------------------- *)     \n   \ntext \"We now show that the fault function will preserve the instance condition\n     of the TLB. For this we split up the proof into two cases, one where the \n     entry is not present (i.e. refill exception condition) and one where the\n     TLB has the entry.\"\n\nlemma MipsTLBT_keeps_instance: \nassumes valid: \" MipsTLBPT_valid mpt \"\n    and inrange: \"vpn < MIPSPT_EntriesMax\"\n    and inrange2: \" ASIDValid as\"\n  shows \"\\<forall>m \\<in> (MipsTLBPT_fault mpt as vpn).  MipsTLBPT_is_instance m\" \nproof cases\n  assume nfault: \"MIPSTLB_try_translate (tlb mpt) as vpn = EXNREFILL\"\n  then show ?thesis \n  proof -\n    from valid have isinstance:\n      \"MipsTLBPT_is_instance mpt\"\n      by(simp add:MipsTLBPT_valid_def)\n        \n    have Z1: \n      \"(\\<And>m i. i <  (capacity (tlb mpt)) \\<Longrightarrow>\n       m = \\<lparr>\n        tlb = \\<lparr>\n          capacity = capacity (tlb mpt), \n          wired = wired (tlb mpt), \n          random = random (tlb mpt), \n          entries = \n            (entries (tlb mpt))(i := MIPSPT_mk_tlbentry (pte mpt) as vpn) \\<rparr>,\n        pte = (pte mpt) \\<rparr>   \\<Longrightarrow> \n      ((entries (tlb m) i = \n          MIPSPT_mk_tlbentry (pte m) (asid (hi (entries (tlb m) i)))  \n                                     (vpn2 (hi (entries (tlb m) i) )))))\"\n      by(auto simp add:MIPSPT_mk_tlbentry_def TLBENTRY.make_def)\n      \n    from nfault have X0:  \n      \"(\\<forall>m \\<in> (MipsTLBPT_fault mpt as vpn).  MipsTLBPT_is_instance m) =\n             (\\<forall>m \\<in> MipsTLBPT_update_tlb mpt as vpn .  MipsTLBPT_is_instance m)\"\n      by(simp add:MipsTLBPT_fault_def)\n    \n    have X1:  \n      \"... = (\\<forall>m\\<in>{\\<lparr>tlb = t, pte = pte mpt\\<rparr> |t. \n          t \\<in> tlbwr (MIPSPT_mk_tlbentry (pte mpt) as vpn) (tlb mpt)}. \n              MipsTLBPT_is_instance m)\"\n      by(simp only:MipsTLBPT_update_tlb_def)\n    \n    have X2:  \n      \"... = (\\<forall>m\\<in>{\\<lparr>tlb = t, pte = pte mpt\\<rparr> |t.\n         t \\<in> {t2 | t2 i. t2= \\<lparr>\n           capacity = capacity (tlb mpt), \n           wired = wired (tlb mpt), \n           random = random (tlb mpt), \n           entries = \n            (entries (tlb mpt))(i := MIPSPT_mk_tlbentry (pte mpt) as vpn)\\<rparr> \\<and>\n             i \\<in> RandomIndexRange (tlb mpt)}}.\n        MipsTLBPT_is_instance m)\"\n      by(auto simp add:tlbwr_def)\n        \n    have X3:  \n      \"... = (\\<forall>i \\<in> RandomIndexRange (tlb mpt). \n        MipsTLBPT_is_instance (\\<lparr>\n         tlb = \\<lparr>\n          capacity = capacity (tlb mpt), \n          wired = wired (tlb mpt), \n          random = random (tlb mpt), \n          entries = \n            (entries (tlb mpt))(i := MIPSPT_mk_tlbentry (pte mpt) as vpn)\\<rparr>, \n         pte = pte mpt\\<rparr>))\"\n      by(auto)\n               \n    from isinstance X0 X1 X2 X3 Z1 show ?thesis \n        by(auto simp add:MipsTLBPT_is_instance_def)\n  qed\nnext\n assume nfault: \"MIPSTLB_try_translate (tlb mpt) as vpn \\<noteq> EXNREFILL\"\n  then show ?thesis \n  proof -\n    from valid have isinstance:\n      \"MipsTLBPT_is_instance mpt\"\n      by(simp add:MipsTLBPT_valid_def)\n    \n    from nfault have X1: \"\\<forall>m \\<in> (MipsTLBPT_fault mpt as vpn). m = mpt\"\n      by(simp add:MipsTLBPT_fault_def)\n    \n    from isinstance X1 show ?thesis \n      by(auto)       \n  qed   \nqed \n\n    \n(* ------------------------------------------------------------------------- *)   \nsubsection \"TLB Valid Preservation\"  \n(* ------------------------------------------------------------------------- *)         \n\ntext \"The next step is to proof that the validity of the TLB is preserved when\n      the fault function replaces an entry. This holds, because the TLB state \n      is only changed when there was no match, which implies that there are\n      no matching entries. We first proof two helper lemmas and then use them\n      to do the proof of the actual lemma.\"\n\n  \n(* ------------------------------------------------------------------------- *)   \nsubsubsection \"Helper Lemmas\"  \n(* ------------------------------------------------------------------------- *)\n\ntext \"We show that if the TLB + page tables are in a valid state and the entry\n      of the TLB matches with the created entry from the page table, then\n      this entry also matches on the VPN that has been used to create it from \n      the page table.\"\n  \nlemma MipsTLBT_EntryMatchVPN_EntryMatchV :\nassumes valid: \"MipsTLBPT_valid mpt \"\n    and inrange: \"i < capacity (tlb mpt)\"\n    and match: \"(EntryVPNMatch (entries (tlb mpt) i) \n                               (MIPSPT_mk_tlbentry (pte mpt) as vpn))\"\n  shows \"(EntryVPNMatchV vpn (entries (tlb mpt) i))\"\nproof -\n    from valid inrange have vpn2even:\n      \"even (vpn2 (hi (entries (tlb mpt) i)))\"\n      by(simp add:MipsTLBPT_valid_def TLBValid_def TLBEntryWellFormed_def \n                  TLBENTRYWellFormed_def TLBENTRYHIWellFormed_def VPN2Valid_def)\n                   \n    have vpn2eve2 : \"even (vpn2 (hi  (MIPSPT_mk_tlbentry (pte mpt) as vpn)))\"\n      by(simp add:MIPSPT_TLBENTRY_vpn2_even)\n                   \n    from valid inrange have mask4k:\n      \"(mask (entries (tlb mpt) i )) = MASK4K\"\n      by(simp add:MipsTLBPT_instance_entry_is_4k)\n      \n    from match have X0:\n      \"(EntryVPNMatch (MIPSPT_mk_tlbentry (pte mpt) as vpn) \n                      (entries (tlb mpt) i))\"\n      by(simp add:EntryVPNMatch_commute)\n    \n    have X1: \n      \"(vpn2 (hi (MIPSPT_mk_tlbentry (pte mpt) as vpn))) \n            = (if (even vpn) then vpn else (vpn -1 ))\"\n      by(simp add:MIPSPT_TLBENTRY_vpn2_is)\n\n    from X0 mask4k vpn2even vpn2eve2  have X2: \n      \"EntryVPNMatchV (vpn2 (hi (MIPSPT_mk_tlbentry (pte mpt) as vpn))) \n                      (entries (tlb mpt) i)\"\n      by(simp add:EntryVPNMatch_alter MIPSPT_TLBENTRY_mask_is)       \n        \n    from X1 X2 have X3:\n      \"EntryVPNMatchV (if (even vpn) then vpn else (vpn - 1)) \n                      (entries (tlb mpt) i)\"\n      by(auto)\n\n    from vpn2even mask4k X3 have X4: \n      \"EntryVPNMatchV (if (even vpn) then vpn else (vpn - 1)) \n                      (entries (tlb mpt) i)\"\n      by(simp add:EntryVPNMatchV_equals_odd)        \n        \n    from vpn2even mask4k X4 X3 show ?thesis \n       by(cases \"even vpn\", simp, simp add:EntryVPNMatchV_equals_odd)\nqed\n\ntext \"Next we show that if an entry does not match on the VPN and ASID then the \n      created entry does not match on the VPN and ASID at the same time.\"  \n    \nlemma MipsTLBT_no_EntryMatch :\nassumes valid: \"MipsTLBPT_valid mpt \"\n    and inrange: \"i<capacity (tlb mpt)\"\n    and nomatch :\" \\<not>EntryMatchVPNASID vpn as (entries (tlb mpt) i)\"\n  shows \"\\<not>(EntryVPNMatch (entries (tlb mpt) i) \n                         (MIPSPT_mk_tlbentry (pte mpt) as vpn) \n        \\<and> EntryASIDMatch (entries (tlb mpt) i) \n                         (MIPSPT_mk_tlbentry (pte mpt) as vpn))\"\nproof cases\n  assume vpnmatch : \"(EntryVPNMatch (entries (tlb mpt) i) \n                     (MIPSPT_mk_tlbentry (pte mpt) as vpn))\"\n  then show ?thesis\n  proof -\n    from vpnmatch valid inrange have X1:\n      \"(EntryVPNMatchV vpn (entries (tlb mpt) i))\"\n      by(simp add:MipsTLBT_EntryMatchVPN_EntryMatchV)\n     \n    from valid have ptvalid : \"MIPSPT_valid (pte mpt)\"\n      by(simp add:MipsTLBPT_valid_def)\n        \n    from nomatch X1 have X0 :\n      \"\\<not> EntryASIDMatchA as (entries (tlb mpt) i)\"\n      by(simp add:EntryMatchVPNASID_def)\n    \n    from valid inrange X0 ptvalid have X2: \n      \"\\<not>EntryASIDMatch (entries (tlb mpt) i) \n                       (MIPSPT_mk_tlbentry (pte mpt) as vpn)\"\n      by(simp add:EntryASIDMatch_def MipsTLBPT_instance_no_global \n                  MIPSPT_TLBENTRY_not_global MIPSPT_TLBENTRY_asid_is \n                  EntryASIDMatchA_def)\n\n    thus ?thesis \n      by(auto)        \n  qed\nnext\n  assume novpnmatch : \n    \"\\<not>(EntryVPNMatch (entries (tlb mpt) i) \n                     (MIPSPT_mk_tlbentry (pte mpt) as vpn))\"\n  then show ?thesis\n    by(auto)\nqed\n  \n  \n(* ------------------------------------------------------------------------- *)   \nsubsubsection \"TLB Valid property is preserved\"  \n(* ------------------------------------------------------------------------- *)\n  \ntext \"Now we proof using the two lemmas above that the fault function always \n      preserves the TLBValid property. We do this by a case distinction, when\n      the entry is not present or when it is.\"   \n  \nlemma MipsTLBT_keeps_TLBValid :\nassumes valid: \"MipsTLBPT_valid mpt \"\n    and inrange: \"vpn < MIPSPT_EntriesMax\"\n    and inrange2: \"ASIDValid as\"\n  shows \"\\<forall>m \\<in> MipsTLBPT_fault mpt as vpn . TLBValid (tlb m)\"\nproof cases\n  assume fault: \"MIPSTLB_try_translate (tlb mpt) as vpn = EXNREFILL\"\n  then show ?thesis\n  proof -  \n  from fault have X0:\n    \"MipsTLBPT_fault mpt as vpn =  \n        {\\<lparr>tlb = t, pte = pte mpt\\<rparr> |t. \n         t \\<in> tlbwr (MIPSPT_mk_tlbentry (pte mpt) as vpn) (tlb mpt)}\"\n    by(simp add:MipsTLBPT_fault_def MipsTLBPT_update_tlb_def)\n         \n  from valid have tlbvalid: \n    \"TLBValid (tlb mpt)\" \n    by(auto simp add:MipsTLBPT_valid_def)\n  \n  from valid have ptvalid :\n    \"MIPSPT_valid (pte mpt)\"\n   by(auto simp add:MipsTLBPT_valid_def)\n      \n  from inrange inrange2 ptvalid have wf:\n    \"TLBENTRYWellFormed (MIPSPT_mk_tlbentry (pte mpt) as vpn)\"\n    by(simp add:MIPSPT_TLBENTRY_wellformed )\n  \n  from fault have nomatch :\n    \"(\\<forall>i<capacity (tlb mpt). \n        \\<not>EntryMatchVPNASID vpn as (entries (tlb mpt) i))\"\n    by(simp add:MIPSTLB_fault_no_match)\n\n  from nomatch ptvalid valid have X1:\n    \"(\\<forall>i<capacity (tlb mpt).\n      \\<not>(EntryVPNMatch (entries (tlb mpt) i) \n                      (MIPSPT_mk_tlbentry (pte mpt) as vpn) \n      \\<and> EntryASIDMatch (entries (tlb mpt) i) \n                       (MIPSPT_mk_tlbentry (pte mpt) as vpn)))\"\n    by(auto simp:MipsTLBT_no_EntryMatch)\n    \n  from ptvalid nomatch X1 have nc:\n    \"TLBEntryNoConflict (MIPSPT_mk_tlbentry (pte mpt) as vpn) (tlb mpt)\" \n    by(auto simp add:TLBEntryNoConflict_def EntryMatch_def)\n      \n  from tlbvalid wf nc X0 show ?thesis\n    by(auto simp:TLBRandomUpdateValid)\n  qed    \nnext\n  assume nfault: \"MIPSTLB_try_translate (tlb mpt) as vpn \\<noteq> EXNREFILL\"\n  then show ?thesis \n  proof -\n    from nfault have X0:\n       \"MipsTLBPT_fault mpt as vpn = {mpt}\"\n      by(simp add:MipsTLBPT_fault_def)\n    \n    from valid have tlbvalid:\n      \"TLBValid (tlb mpt)\"\n      by(simp add:MipsTLBPT_valid_def)\n    \n    from X0 tlbvalid show ?thesis \n      by(auto)\n  qed  \nqed\n  \n\n(* ------------------------------------------------------------------------- *)   \nsubsection \"Page Table Valid Preservation\"  \n(* ------------------------------------------------------------------------- *)       \n\ntext \"Lastly, we show that the fault function preserves the validity of the\n      page table which is trivial given the page tables are not changed.\"\n\nlemma MipsTLBT_keeps_ptvalid:\n  \"\\<And>vpn mpt as. MipsTLBPT_valid mpt \\<Longrightarrow> vpn < MIPSPT_EntriesMax \n           \\<Longrightarrow> \\<forall>m \\<in> MipsTLBPT_fault mpt as vpn .  MIPSPT_valid (pte m)\"       \n  by(simp add:MipsTLBPT_valid_def MipsTLBPT_update_tlb_def \n              MipsTLBPT_fault_def, auto)\n  \n(* ------------------------------------------------------------------------- *)   \nsubsection \"Validity Preservation\"  \n(* ------------------------------------------------------------------------- *)     \n  \ntext \"By using the three lemmas from above, we can show that the fault function\n      preserves the TLBValid, the page table and instance properties and\n      therefore we can show that the validity of the TLB+page table are\n      preserved.\"  \n  \nlemma MipsTLBPT_keeps_valid :\n    assumes valid: \"\\<And>mpt. MipsTLBPT_valid mpt \"\n    and inrange: \"\\<And>vpn. vpn < MIPSPT_EntriesMax\"\n    and inrange2: \"\\<And>as. ASIDValid as\"\n  shows \"\\<And>vpn mpt as.  \\<forall>m \\<in> MipsTLBPT_fault mpt as vpn .  MipsTLBPT_valid m\"\n  apply(subst MipsTLBPT_valid_def)\n  apply(simp add:ball_conj_distrib)\n  apply(simp add:MipsTLBT_keeps_ptvalid valid inrange inrange2 )\n  apply(simp add:MipsTLBT_keeps_instance valid inrange inrange2)\n  apply(simp add:MipsTLBT_keeps_TLBValid valid inrange inrange2 )\n  done\n\n    \n    \n(* ========================================================================= *)  \nsection \"Matching TLB Entries\"\n(* ========================================================================= *)     \n\ntext \"We now show that if the entry matches a particular ASID and VPN then \n      the entry is equal to the created entry. We do a case distinction\n      on the vpn, even and odd. \"\n  \n  \nlemma MipsTLBPT_match_is_equlas_even: \nassumes inrange:  \"i < capacity (tlb mtlb)\"\n    and match: \"EntryMatchVPNASID vpn as (entries (tlb mtlb) i) \"\n    and valid: \"MipsTLBPT_valid mtlb\"\n    and veven : \"even vpn\"\n  shows \"entries (tlb mtlb) i = MIPSPT_mk_tlbentry (pte mtlb) as vpn\"\nproof -\n    \n  from valid have ptvalid :\n    \"MIPSPT_valid (pte mtlb)\"\n    by(simp add:MipsTLBPT_valid_def)       \n  \n  from valid have isinstance :\n    \"MipsTLBPT_is_instance (mtlb)\"\n    by(simp add:MipsTLBPT_valid_def)            \n\n  from valid have tlbvalid :\n    \"TLBValid (tlb mtlb)\"\n    by(simp add:MipsTLBPT_valid_def)       \n        \n  from valid inrange match isinstance have X0: \n    \"(asid (hi (entries (tlb mtlb) i))) = as\"\n    by(simp add:EntryMatchVPNASID_def\n                EntryASIDMatchA_def \n                MipsTLBPT_instance_no_global)\n              \n  from inrange tlbvalid have vpne2ven :\n    \"even (vpn2 (hi (entries (tlb mtlb) i)))\"\n    by(simp add:TLBValid_def TLBEntryWellFormed_def \n                TLBENTRYWellFormed_def \n                TLBENTRYHIWellFormed_def VPN2Valid_def)\n      \n  from veven vpne2ven inrange valid match isinstance have  X1:\n              \"(vpn2 (hi (entries (tlb mtlb) i))) = vpn\"\n    by(auto simp add:EntryMatchVPNASID_def EntryVPNMatchV_def \n                     EntryMin4KVPN_def EntryMax4KVPN_def \n                     MipsTLBPT_instance_entry_is_4k num_4k_pages_def\n                     even_vpn_compare)\n           \n   from isinstance have X3:\n     \"(\\<forall>i <  (capacity (tlb mtlb)).\n        entries (tlb mtlb) i = \n           MIPSPT_mk_tlbentry (pte mtlb) (asid (hi (entries (tlb mtlb) i) ))\n                                         (vpn2 (hi (entries (tlb mtlb) i) )))\"\n     by(simp add:MipsTLBPT_is_instance_def)\n      \n   from X3 inrange have X4 : \n     \"entries (tlb mtlb) i = \n           MIPSPT_mk_tlbentry (pte mtlb) (asid (hi (entries (tlb mtlb) i) ))\n                                         (vpn2 (hi (entries (tlb mtlb) i) ))\"\n     by(auto)\n       \n   from X0 X1 X3 X4 show ?thesis\n     by(auto)\nqed\n\nlemma MipsTLBPT_match_is_equlas_odd: \nassumes inrange:  \"i < capacity (tlb mtlb)\"\n    and match: \"EntryMatchVPNASID vpn as (entries (tlb mtlb) i) \"\n    and valid: \"MipsTLBPT_valid mtlb\"\n    and vodd : \"odd vpn\"\n  shows \"entries (tlb mtlb) i = MIPSPT_mk_tlbentry (pte mtlb) as vpn\"\nproof -\n  from valid have ptvalid :\n    \"MIPSPT_valid (pte mtlb)\"\n    by(simp add:MipsTLBPT_valid_def)       \n  \n  from valid have isinstance :\n    \"MipsTLBPT_is_instance (mtlb)\"\n    by(simp add:MipsTLBPT_valid_def)            \n\n  from valid have tlbvalid :\n    \"TLBValid (tlb mtlb)\"\n    by(simp add:MipsTLBPT_valid_def)       \n        \n  from valid inrange match isinstance have X0: \n    \"(asid (hi (entries (tlb mtlb) i))) = as\"\n    by(simp add:EntryMatchVPNASID_def\n                EntryASIDMatchA_def \n                MipsTLBPT_instance_no_global)\n              \n  from inrange tlbvalid have vpne2ven :\n    \"even (vpn2 (hi (entries (tlb mtlb) i)))\"\n    by(simp add:TLBValid_def TLBEntryWellFormed_def TLBENTRYWellFormed_def \n                TLBENTRYHIWellFormed_def VPN2Valid_def)\n      \n  from vodd vpne2ven inrange valid match isinstance have  X1:\n    \"(vpn2 (hi (entries (tlb mtlb) i))) = (vpn - 1)\"\n    by(auto simp:EntryMatchVPNASID_def EntryVPNMatchV_def EntryMin4KVPN_def \n                 EntryMax4KVPN_def MipsTLBPT_instance_entry_is_4k num_4k_pages_def\n                 even_vpn_compare)\n           \n   from inrange isinstance have X3:\n     \"entries (tlb mtlb) i = \n          MIPSPT_mk_tlbentry (pte mtlb) (asid (hi (entries (tlb mtlb) i) ))\n                                        (vpn2 (hi (entries (tlb mtlb) i) ))\"\n     by(simp add:MipsTLBPT_is_instance_def)\n\n   from vodd have X4:  \n     \"MIPSPT_mk_tlbentry (pte mtlb) as (vpn - 1) \n                  = MIPSPT_mk_tlbentry (pte mtlb) as vpn\"\n     by(simp add:MIPSPT_mk_tlbentry_def)\n       \n   from X0 X1 X3 X4 show ?thesis\n     by(auto)\nqed  \n  \n  \nlemma MipsTLBPT_match_is_equlas: \nassumes inrange:  \"i < capacity (tlb mtlb)\"\n    and match: \"EntryMatchVPNASID vpn as (entries (tlb mtlb) i) \"\n    and valid: \"MipsTLBPT_valid mtlb\"\n  shows \"entries (tlb mtlb) i = MIPSPT_mk_tlbentry (pte mtlb) as vpn\"\nproof cases\n  assume veven: \"even vpn\"\n  then show ?thesis \n    by(simp add:MipsTLBPT_match_is_equlas_even inrange match valid)\nnext\n  assume vodd: \"odd vpn\"\n  then show ?thesis\n    by(simp add:MipsTLBPT_match_is_equlas_odd inrange match valid)\nqed\n  \n  \n(* ========================================================================= *)  \nsection \"Existence of Entry\"\n(* ========================================================================= *)       \n\ntext \"If for a given ASID/VPN the translation attempt does not throw a refill\n      exception then there exist an entry in the TLB that matches the\n      ASID/VPN.\"  \n  \nlemma MipsTLBPT_no_fault_entry_exist :\nassumes valid: \"MipsTLBPT_valid mtlb\"\n    and translates : \"MIPSTLB_try_translate (tlb mtlb) as vpn \\<noteq> EXNREFILL\"\n  shows \"(\\<exists>i < (capacity (tlb mtlb)). \n           (entries (tlb mtlb) i) = (MIPSPT_mk_tlbentry (pte mtlb) as vpn))\"\nproof -\n  from valid have inst:\n    \"MipsTLBPT_is_instance mtlb\"\n    by(simp add:MipsTLBPT_valid_def)\n  from valid have ptvalid :\n    \"MIPSPT_valid (pte mtlb)\"\n    by(simp add:MipsTLBPT_valid_def)\n  from valid have tlbvalid:\n    \"TLBValid (tlb mtlb)\"\n    by(simp add:MipsTLBPT_valid_def)\n   \n  from inst have inst2: \n    \"(\\<forall>i<capacity (tlb mtlb). \n        entries (tlb mtlb) i = \n          MIPSPT_mk_tlbentry (pte mtlb) \n                             (asid (hi (entries (tlb mtlb) i))) \n                             (vpn2 (hi (entries (tlb mtlb) i))))\"\n    by(simp add:MipsTLBPT_is_instance_def)\n  \n  have doesmatch: \n    \"EntryMatchVPNASID vpn as (MIPSPT_mk_tlbentry (pte mtlb) as vpn)\"\n    by(simp add:MIPSPT_TLBENTRY_match)      \n      \n  from translates have matchexist:\n     \"(\\<exists>i<capacity (tlb mtlb). EntryMatchVPNASID vpn as (entries (tlb mtlb) i))\"\n    by(simp add:MIPSTLB_try_translate_exist_match)\n      \n  from valid have X0: \n    \"\\<And>i as vpn. i < capacity (tlb mtlb) \n         \\<and> EntryMatchVPNASID vpn as (entries (tlb mtlb) i) \n            \\<longrightarrow>  entries (tlb mtlb) i = MIPSPT_mk_tlbentry (pte mtlb) as vpn\"\n    by(simp add:MipsTLBPT_match_is_equlas)\n      \n  from matchexist X0 show ?thesis by(auto)  \nqed\n  \n\n(* ========================================================================= *)  \nsection \"No Match implies no Translate\"\n(* ========================================================================= *)         \n\ntext \"For any entry in the TLB other than the one that may match, the\n      translate function will return the empty set.\"\n  \nlemma  MipsTLBPT_Entry_no_match_no_translate:\nassumes inrange: \" i < capacity (tlb mtlb)\"\n    and  valid: \"MipsTLBPT_valid mtlb\"\n    and  inotmatch: \" i \\<noteq> (SOME j. j < (capacity (tlb mtlb)) \n                             \\<and> ((entries (tlb mtlb) j)) = \n                                  (MIPSPT_mk_tlbentry (pte mtlb) as vpn))\"\n  shows \"TLBENTRY_translate (entries (tlb mtlb) i) as vpn = {}\"\nproof cases\n  assume fault: \"MIPSTLB_try_translate (tlb mtlb) as vpn = EXNREFILL\"\n  then show ?thesis \n  proof -\n    from fault inrange have nomatch:\n      \"\\<not>EntryMatchVPNASID vpn as (entries (tlb mtlb) i)\"\n      by(simp add:MIPSTLB_fault_no_match)\n    from nomatch show ?thesis\n      by(simp add:TLBENTRY_translate_def)\n  qed      \nnext\n  assume nofault: \"MIPSTLB_try_translate (tlb mtlb) as vpn \\<noteq> EXNREFILL\"\n  then show ?thesis \n  proof -\n    from valid have tlbvalid:\n      \"TLBValid (tlb mtlb)\"\n      by(simp add:MipsTLBPT_valid_def)\n\n    from valid have inst:\n      \"MipsTLBPT_is_instance mtlb\"        \n      by(simp add:MipsTLBPT_valid_def)\n            \n    have mask4k2: \n       \"(\\<forall>i < (capacity (tlb mtlb)). mask ((entries (tlb mtlb)) i) = MASK4K)\"\n    proof -\n      from inst have Z0:\n        \"(\\<forall>i < capacity (tlb mtlb). mask ((entries (tlb mtlb)) i) = MASK4K) =\n            (\\<forall>i < (capacity (tlb mtlb)). \n                  mask (MIPSPT_mk_tlbentry (pte mtlb) \n                                           (asid (hi (entries (tlb mtlb) i)))\n                                           (vpn2 (hi (entries (tlb mtlb) i))))\n                    = MASK4K)\"\n        by(simp add:MipsTLBPT_is_instance_def)\n          \n      from Z0 show ?thesis \n        by(auto simp:MIPSPT_mk_tlbentry_def TLBENTRY.make_def)\n    qed\n    \n    from nofault  valid have exist:\n      \"(\\<exists>j. j < (capacity (tlb mtlb)) \\<and>\n          (entries (tlb mtlb) j) = (MIPSPT_mk_tlbentry (pte mtlb) as vpn))\"     \n      by(simp add:MipsTLBPT_no_fault_entry_exist)        \n        \n    from exist have match: \n      \"entries (tlb mtlb) \n          (SOME j. j < (capacity (tlb mtlb)) \n             \\<and> ((entries (tlb mtlb) j)) = (MIPSPT_mk_tlbentry (pte mtlb) as vpn))\n           = (MIPSPT_mk_tlbentry (pte mtlb) as vpn)\"\n       by(simp add:some_eq_ex[symmetric])\n    \n     from exist have ir2: \n       \"(SOME j. j < (capacity (tlb mtlb))  \\<and> ((entries (tlb mtlb) j)) \n            = (MIPSPT_mk_tlbentry (pte mtlb) as vpn)) <  (capacity (tlb mtlb))\"\n      by(simp add:some_eq_ex[symmetric])\n          \n    have X0: \n      \"EntryMatchVPNASID vpn as (entries (tlb mtlb) (SOME j. \n          j < (capacity (tlb mtlb)) \\<and> ((entries (tlb mtlb) j)) \n                = (MIPSPT_mk_tlbentry (pte mtlb) as vpn)))\"\n      by(simp add:match MIPSPT_TLBENTRY_match)\n    \n    have X1: \n      \"(SOME j. j < capacity (tlb mtlb) \\<and> entries (tlb mtlb) j \n            = MIPSPT_mk_tlbentry (pte mtlb) as vpn) \\<noteq> i\"\n      by(auto simp add:inotmatch)\n        \n    from tlbvalid inrange ir2 mask4k2 X0 X1 have nomatch :\n      \"\\<not> EntryMatchVPNASID vpn as (entries (tlb mtlb) i)\"\n      by(simp add:TLBValid_implies_no_other_match)\n  \n  from nomatch show ?thesis \n    by(auto simp:TLBENTRY_translate_def)  \n  qed\nqed\n\n(* ========================================================================= *)  \nsection \"Translate Simplification\"\n(* ========================================================================= *)       \n  \ntext \"Next we show the equivalence of the translate function to be equal to \n      directly reading out the entry from the page table.\"  \n  \nlemma MipsTLBPT_translate_is:\n  assumes inrange: \"vpn < MIPSPT_EntriesMax\"\n    and inrange2: \"as < ASIDMax\"\n    and cap: \"capacity (tlb mtlb) > 0\"\n    and  valid: \"MipsTLBPT_valid mtlb\"\n  shows \"MipsTLBPT_translate mtlb as vpn = \n           (if (v ((entry (pte mtlb)) vpn as))\n            then {(pfn ((entry  (pte mtlb)) vpn as))} else {})\" \nproof cases\n  assume fault: \"MIPSTLB_try_translate (tlb mtlb) as vpn = EXNREFILL\"\n  then show ?thesis \n  proof -\n    from valid have tlbvalid : \n      \"TLBValid (tlb mtlb)\"\n      by(simp add:MipsTLBPT_valid_def)\n        \n    from fault have X0: \n      \"MipsTLBPT_translate mtlb as vpn = \n             \\<Union>{MIPSTLB_translate (tlb m) as vpn | m. \n                m \\<in> MipsTLBPT_update_tlb mtlb as vpn}\"\n      by(simp add:MipsTLBPT_translate_def MipsTLBPT_fault_def)\n\n    have X1: \n      \" ... = \\<Union>{MIPSTLB_translate (tlb m) as vpn |m. \n            m \\<in> {\\<lparr>tlb = t, pte = pte mtlb\\<rparr> |t. \n            t \\<in> tlbwr (MIPSPT_mk_tlbentry (pte mtlb) as vpn) (tlb mtlb)}}\"\n      by(simp only:MipsTLBPT_update_tlb_def)\n    \n    have X2: \n      \" ... = \\<Union>{MIPSTLB_translate (tlb m) as vpn |m.\n       \\<exists>t. m = \\<lparr>tlb = t, pte = pte mtlb\\<rparr> \\<and>\n           (\\<exists>i. t = \\<lparr>\n            capacity = capacity (tlb mtlb), \n            wired = wired (tlb mtlb), \n            random = random (tlb mtlb), \n            entries = (entries (tlb mtlb))(\n                i := MIPSPT_mk_tlbentry (pte mtlb) as vpn)\\<rparr>\n         \\<and> i \\<in> RandomIndexRange (tlb mtlb))}\"\n      by(simp add:tlbwr_def)\n    \n    have X3: \n      \"... = \\<Union>{MIPSTLB_translate (tlb m) as vpn |m.\n          \\<exists>i. m = \\<lparr>tlb = \\<lparr>\n              capacity = capacity (tlb mtlb), \n              wired = wired (tlb mtlb), \n              random = random (tlb mtlb), \n              entries = (entries (tlb mtlb))(\n                  i := MIPSPT_mk_tlbentry (pte mtlb) as vpn)\\<rparr>, pte = pte mtlb\\<rparr> \n            \\<and> i \\<in> RandomIndexRange (tlb mtlb)}\"\n      by(auto)\n    \n    have X4: \n      \" ... =  \\<Union>{{pa| pa j. pa \\<in> TLBENTRY_translate (entries (tlb m) j) as vpn \n          \\<and> j < capacity (tlb m)} |m i.\n           m = \\<lparr>tlb = \\<lparr>\n              capacity = capacity (tlb mtlb), \n              wired = wired (tlb mtlb), \n              random = random (tlb mtlb), \n              entries = (entries (tlb mtlb))(\n              i := MIPSPT_mk_tlbentry (pte mtlb) as vpn)\\<rparr>, pte = pte mtlb\\<rparr> \\<and>\n           i \\<in> RandomIndexRange (tlb mtlb)}\"\n      by(simp add:MIPSTLB_translate_def)\n        \n    have X5:\n      \"... = \\<Union>{ {pa| pa j. \n        pa \\<in> TLBENTRY_translate (entries (tlb m) j) as vpn \\<and> j < capacity (tlb m) \\<and> i = j}\n         \\<union> {pa| pa j. pa \\<in> TLBENTRY_translate (entries (tlb m) j) as vpn \\<and> j < capacity (tlb m) \\<and> i \\<noteq> j} | \n  m i.\n       m = \\<lparr>tlb = \\<lparr>\n            capacity = capacity (tlb mtlb), \n            wired = wired (tlb mtlb), \n            random = random (tlb mtlb), \n            entries = (entries (tlb mtlb))(i := MIPSPT_mk_tlbentry (pte mtlb) as vpn)\\<rparr>,\n           pte = pte mtlb\\<rparr> \\<and>\n           i \\<in> RandomIndexRange (tlb mtlb)}\"\n      by(blast)\n    \n    have X6:  \" ... = \\<Union>{ {pa| pa j. pa \\<in> TLBENTRY_translate (MIPSPT_mk_tlbentry (pte mtlb) as vpn) as vpn \\<and> j < capacity (tlb m) \\<and> i = j}\n       \\<union> {pa| pa j. pa \\<in> TLBENTRY_translate (entries (tlb m) j) as vpn \\<and> j < capacity (tlb m) \\<and> i \\<noteq> j} |m i.\n       m = \\<lparr>tlb = \\<lparr>capacity = capacity (tlb mtlb), wired = wired (tlb mtlb), random = random (tlb mtlb),  entries = (entries (tlb mtlb))(i := MIPSPT_mk_tlbentry (pte mtlb) as vpn)\\<rparr>, pte = pte mtlb\\<rparr> \\<and>\n           i \\<in> RandomIndexRange (tlb mtlb)}\"\n      by(auto)\n\n    have X7:   \" ... = \\<Union>{{pa \\<in> TLBENTRY_translate (MIPSPT_mk_tlbentry (pte mtlb) as vpn) as vpn. i < capacity (tlb mtlb)} \\<union>\n       {pa | pa j. j \\<noteq> i \\<and>  j < capacity (tlb mtlb) \\<and> pa \\<in> TLBENTRY_translate (entries (tlb mtlb) j) as vpn} |\n       i. i \\<in> RandomIndexRange (tlb mtlb)}\"\n      by(auto)\n\n     have X8:  \" ... = {pa | pa i. pa \\<in> TLBENTRY_translate (MIPSPT_mk_tlbentry (pte mtlb) as vpn) as vpn \\<and>  i \\<in> RandomIndexRange (tlb mtlb) \\<and> i<capacity (tlb mtlb)} \\<union>\n    {pa. \\<exists>j i. i \\<in> RandomIndexRange (tlb mtlb) \\<and> j \\<noteq> i \\<and> j < capacity (tlb mtlb) \\<and> pa \\<in> TLBENTRY_translate (entries (tlb mtlb) j) as vpn}\"\n       by(auto)\n         \n    from fault have X9:  \" ... =  {pa | pa i. pa \\<in> TLBENTRY_translate (MIPSPT_mk_tlbentry (pte mtlb) as vpn) as vpn \\<and>  i \\<in> RandomIndexRange (tlb mtlb) \\<and> i<capacity (tlb mtlb)}\"\n      by(auto simp add:MIPSTLB_fault_no_translate)\n        \n    have X10: \" ... =  {pa | pa i. pa \\<in> TLBENTRY_translate (MIPSPT_mk_tlbentry (pte mtlb) as vpn) as vpn \\<and> i \\<in> RandomIndexRange (tlb mtlb)}\"\n      by(auto simp:RandomIndex_in_capacity cap)\n\n     from tlbvalid have X11 : \" ... =   (if (v ((entry  (pte mtlb)) vpn as)) then {(pfn ((entry   (pte mtlb)) vpn as))} else {})\"\n       by(auto simp add:MIPSPT_TLBENTRY_translate_is RandomIndexRange_def TLBValid_def)\n   \n   from fault X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 show ?thesis\n     by(auto)\n  qed\nnext\n  assume nofault: \"MIPSTLB_try_translate (tlb mtlb) as vpn \\<noteq> EXNREFILL\"\n  then show ?thesis \n  proof -\n\n    from nofault inrange inrange2 valid have exist:\n          \"(\\<exists>j. j < (capacity (tlb mtlb)) \\<and>\n              (entries (tlb mtlb) j) = (MIPSPT_mk_tlbentry (pte mtlb) as vpn))\"     \n      by(simp add:MipsTLBPT_no_fault_entry_exist)\n     \n    from exist have match: \"\n        entries (tlb mtlb) \n            (SOME j. j < (capacity (tlb mtlb)) \n                \\<and> ((entries (tlb mtlb) j)) = (MIPSPT_mk_tlbentry (pte mtlb) as vpn))\n           = (MIPSPT_mk_tlbentry (pte mtlb) as vpn)\"\n       by(simp add:some_eq_ex[symmetric])\n    \n    from exist have ir2: \" (SOME j. j < (capacity (tlb mtlb)) \n                \\<and> ((entries (tlb mtlb) j)) = (MIPSPT_mk_tlbentry (pte mtlb) as vpn)) <  (capacity (tlb mtlb)) \"\n      by(simp add:some_eq_ex[symmetric])\n    \n    \n    from nofault have X0:  \"MipsTLBPT_translate mtlb as vpn =  MIPSTLB_translate (tlb mtlb) as vpn\"\n      by(simp add:MipsTLBPT_translate_def MipsTLBPT_fault_def)\n\n    have X1 : \" ... =  {pa | pa i.  i < capacity (tlb mtlb) \n                          \\<and> pa \\<in> TLBENTRY_translate (entries (tlb mtlb) i) as vpn}\"\n      by(auto simp add:MIPSTLB_translate_def)\n        \n    have X2 : \" ... = {pa | pa i.  i < capacity (tlb mtlb) \\<and> i = (SOME j. j < (capacity (tlb mtlb)) \n                \\<and> ((entries (tlb mtlb) j)) = (MIPSPT_mk_tlbentry (pte mtlb) as vpn))\n                          \\<and> pa \\<in> TLBENTRY_translate (entries (tlb mtlb) i) as vpn}  \\<union>\n                      {pa | pa i.  i < capacity (tlb mtlb) \\<and> i \\<noteq> (SOME j. j < (capacity (tlb mtlb)) \n                \\<and> ((entries (tlb mtlb) j)) = (MIPSPT_mk_tlbentry (pte mtlb) as vpn))\n                          \\<and> pa \\<in> TLBENTRY_translate (entries (tlb mtlb) i) as vpn}\"\n      by(auto)\n        \n    \n    \n     from match have X3: \" ... =  {pa | pa i.  i < capacity (tlb mtlb) \\<and> i = (SOME j. j < (capacity (tlb mtlb)) \n                \\<and> ((entries (tlb mtlb) j)) = (MIPSPT_mk_tlbentry (pte mtlb) as vpn))\n                          \\<and> pa \\<in> TLBENTRY_translate  (MIPSPT_mk_tlbentry (pte mtlb) as vpn) as vpn}  \\<union>\n                      {pa | pa i.  i < capacity (tlb mtlb) \\<and> i \\<noteq> (SOME j. j < (capacity (tlb mtlb)) \n                \\<and> ((entries (tlb mtlb) j)) = (MIPSPT_mk_tlbentry (pte mtlb) as vpn))\n                          \\<and> pa \\<in> TLBENTRY_translate (entries (tlb mtlb) i) as vpn}\"\n      by(auto)\n    \n    from ir2 have X4:  \" ... =  {pa | pa i. i = (SOME j. j < (capacity (tlb mtlb)) \n                \\<and> ((entries (tlb mtlb) j)) = (MIPSPT_mk_tlbentry (pte mtlb) as vpn))\n                          \\<and> pa \\<in> TLBENTRY_translate  (MIPSPT_mk_tlbentry (pte mtlb) as vpn) as vpn}  \\<union>\n                      {pa | pa i.  i < capacity (tlb mtlb) \\<and> i \\<noteq> (SOME j. j < (capacity (tlb mtlb)) \n                \\<and> ((entries (tlb mtlb) j)) = (MIPSPT_mk_tlbentry (pte mtlb) as vpn))\n                          \\<and> pa \\<in> TLBENTRY_translate (entries (tlb mtlb) i) as vpn}\"\n      by(auto)\n        \n     from valid have X5:  \" ... =  {pa | pa i. i = (SOME j. j < (capacity (tlb mtlb)) \n                \\<and> ((entries (tlb mtlb) j)) = (MIPSPT_mk_tlbentry (pte mtlb) as vpn))\n                          \\<and> pa \\<in> TLBENTRY_translate  (MIPSPT_mk_tlbentry (pte mtlb) as vpn) as vpn}\"\n       by(auto simp add:MipsTLBPT_Entry_no_match_no_translate)\n         \n     have X6: \" ... =   (if (v ((entry (pte mtlb)) vpn as)) then {(pfn ((entry  (pte mtlb)) vpn as))} else {})\"\n       by(simp add:MIPSPT_TLBENTRY_translate_is)\n    \n    \n     from X0 X1 X2 X3 X4 X5 X6 match show ?thesis\n       by(auto)\n  qed\nqed    \n    \nend ", "meta": {"author": "BarrelfishOS", "repo": "Isabelle-hardware-models", "sha": "a638383df9dd8db15805c59efb65724bc919df0a", "save_path": "github-repos/isabelle/BarrelfishOS-Isabelle-hardware-models", "path": "github-repos/isabelle/BarrelfishOS-Isabelle-hardware-models/Isabelle-hardware-models-a638383df9dd8db15805c59efb65724bc919df0a/theories/mipstlb/MipsTLBReplacementHandler.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.523420348936324, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.2514923173202992}}
{"text": "(*\n    Author:      Norbert Schirmer\n    Maintainer:  Norbert Schirmer, norbert.schirmer at web de\n    License:     LGPL\n*)\n\n(*  Title:      HoarePartial.thy\n    Author:     Norbert Schirmer, TU Muenchen\n\nCopyright (C) 2004-2008 Norbert Schirmer \nSome rights reserved, TU Muenchen\n\nThis library is free software; you can redistribute it and/or modify\nit under the terms of the GNU Lesser General Public License as\npublished by the Free Software Foundation; either version 2.1 of the\nLicense, or (at your option) any later version.\n\nThis library is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\nLesser General Public License for more details.\n\nYou should have received a copy of the GNU Lesser General Public\nLicense along with this library; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307\nUSA\n*)\n\nsection {* Properties of Total Correctness Hoare Logic *}\n\ntheory HoareTotalProps imports SmallStep HoareTotalDef HoarePartialProps begin\n\nsubsection {* Soundness *}\n\nlemma hoaret_sound: \n assumes hoare: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nusing hoare\nproof (induct)\n  case (Skip \\<Theta> F P A)\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Skip P,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Skip,Normal s\\<rangle> \\<Rightarrow> t\" \"s \\<in> P\"\n    thus \"t \\<in> Normal ` P \\<union> Abrupt ` A\"\n      by cases auto\n  next\n    fix s show \"\\<Gamma>\\<turnstile>Skip \\<down> Normal s\"\n      by (rule terminates.intros)\n  qed\nnext\n  case (Basic \\<Theta> F f P A)\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. f s \\<in> P} (Basic f) P,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Basic f,Normal s\\<rangle> \\<Rightarrow> t\" \"s \\<in> {s. f s \\<in> P}\"\n    thus \"t \\<in> Normal ` P \\<union> Abrupt ` A\"\n      by cases auto\n  next\n    fix s show \"\\<Gamma>\\<turnstile>Basic f \\<down> Normal s\"\n      by (rule terminates.intros)\n  qed\nnext\n  case (Spec \\<Theta> F r Q A)\n  show \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. (\\<forall>t. (s, t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s, t) \\<in> r)} Spec r Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Spec r ,Normal s\\<rangle> \\<Rightarrow> t\" \n           \"s \\<in> {s. (\\<forall>t. (s, t) \\<in> r \\<longrightarrow> t \\<in> Q) \\<and> (\\<exists>t. (s, t) \\<in> r)}\"\n    thus \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by cases auto\n  next\n    fix s show \"\\<Gamma>\\<turnstile>Spec r \\<down> Normal s\"\n      by (rule terminates.intros)\n  qed\nnext\n  case (Seq \\<Theta> F P c1 R A c2 Q)\n  have valid_c1: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c1 R,A\" by fact\n  have valid_c2: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c2 Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Seq c1 c2 Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal s\\<rangle> \\<Rightarrow> t\" \n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    from exec P obtain r where\n      exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> r\" and exec_c2:  \"\\<Gamma>\\<turnstile>\\<langle>c2,r\\<rangle> \\<Rightarrow> t\"\n      by cases auto\n    with t_notin_F have \"r \\<notin> Fault ` F\"\n      by (auto dest: Fault_end)\n    from valid_c1 ctxt exec_c1 P this\n    have r: \"r \\<in> Normal ` R \\<union> Abrupt ` A\"\n      by (rule cvalidt_postD)\n    show \"t\\<in>Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases r)\n      case (Normal r')\n      with exec_c2 r\n      show \"t\\<in>Normal ` Q \\<union> Abrupt ` A\"\n        apply -\n        apply (rule cvalidt_postD [OF valid_c2 ctxt _ _ t_notin_F])\n        apply auto\n        done\n    next\n      case (Abrupt r')\n      with exec_c2 have \"t=Abrupt r'\"\n        by (auto elim: exec_elim_cases)\n      with Abrupt r show ?thesis\n        by auto\n    next\n      case Fault with r show ?thesis by blast\n    next\n      case Stuck with r show ?thesis by blast\n    qed\n  next\n    fix s \n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s\\<in>P\"\n    show \"\\<Gamma>\\<turnstile>Seq c1 c2 \\<down> Normal s\"\n    proof -\n      from valid_c1 ctxt P\n      have \"\\<Gamma>\\<turnstile>c1\\<down> Normal s\"\n        by (rule cvalidt_termD)\n      moreover\n      {\n        fix r assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> r\"\n        have \"\\<Gamma>\\<turnstile>c2 \\<down> r\"\n        proof (cases r)\n          case (Normal r')\n          with cvalidt_postD [OF valid_c1 ctxt exec_c1 P]\n          have r: \"r\\<in>Normal ` R\"\n            by auto\n          with cvalidt_termD [OF valid_c2 ctxt] exec_c1\n          show \"\\<Gamma>\\<turnstile>c2 \\<down> r\"\n            by auto\n        qed auto        \n      }\n      ultimately show ?thesis\n        by (iprover intro: terminates.intros)\n    qed\n  qed\nnext\n  case (Cond \\<Theta> F P b c1 Q A c2)\n  have valid_c1: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> b) c1 Q,A\" by fact\n  have valid_c2: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P \\<inter> - b) c2 Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Cond b c1 c2 Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow> t\"\n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases \"s\\<in>b\")\n      case True\n      with exec have \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow> t\"\n        by cases auto\n      with P True \n      show ?thesis\n        by - (rule cvalidt_postD [OF valid_c1 ctxt _ _ t_notin_F],auto)\n    next\n      case False\n      with exec P have \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal s\\<rangle> \\<Rightarrow> t\"\n        by cases auto\n      with P False \n      show ?thesis\n        by - (rule cvalidt_postD [OF valid_c2 ctxt _ _ t_notin_F],auto)\n    qed\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s \\<in> P\"\n    thus \"\\<Gamma>\\<turnstile>Cond b c1 c2 \\<down> Normal s\"\n      using cvalidt_termD [OF valid_c1 ctxt] cvalidt_termD [OF valid_c2 ctxt]\n      by (cases \"s \\<in> b\") (auto intro: terminates.intros)\n  qed\nnext\n  case (While r \\<Theta> F P b c A)\n  assume wf: \"wf r\"\n  have valid_c: \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> P \\<inter> b) c ({t. (t, \\<sigma>) \\<in> r} \\<inter> P),A\"\n    using While.hyps by iprover\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (While b c) (P \\<inter> - b),A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume wprems: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow> t\" \"s \\<in> P\" \"t \\<notin> Fault ` F\"\n    from wf\n    have \"\\<And>t. \\<lbrakk>\\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow> t; s \\<in> P; t \\<notin> Fault ` F\\<rbrakk> \n                 \\<Longrightarrow> t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\"\n    proof (induct)\n      fix s t\n      assume hyp: \n        \"\\<And>s' t. \\<lbrakk>(s',s)\\<in>r; \\<Gamma>\\<turnstile>\\<langle>While b c,Normal s'\\<rangle> \\<Rightarrow> t; s' \\<in> P; t \\<notin> Fault ` F\\<rbrakk>\n                 \\<Longrightarrow> t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\"\n      assume exec: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow> t\"\n      assume P: \"s \\<in> P\"\n      assume t_notin_F: \"t \\<notin> Fault ` F\"\n      from exec\n      show \"t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\"\n      proof (cases)\n        fix s'\n        assume b: \"s\\<in>b\"\n        assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> s'\" \n        assume exec_w: \"\\<Gamma>\\<turnstile>\\<langle>While b c,s'\\<rangle> \\<Rightarrow> t\"\n        from exec_w t_notin_F have \"s' \\<notin> Fault ` F\"\n          by (auto dest: Fault_end)\n        from exec_c P b valid_c ctxt this\n        have s': \"s' \\<in> Normal ` ({s'. (s', s) \\<in> r} \\<inter> P) \\<union> Abrupt ` A\"\n          by (auto simp add: cvalidt_def validt_def valid_def)\n        show ?thesis\n        proof (cases s')\n          case Normal \n          with exec_w s' t_notin_F\n          show ?thesis\n            by - (rule hyp,auto)\n        next\n          case Abrupt\n          with exec_w have \"t=s'\"\n            by (auto dest: Abrupt_end)\n          with Abrupt s' show ?thesis\n            by blast\n        next\n          case Fault\n          with exec_w have \"t=s'\"\n            by (auto dest: Fault_end)\n          with Fault s' show ?thesis\n            by blast\n        next\n          case Stuck\n          with exec_w have \"t=s'\"\n            by (auto dest: Stuck_end)\n          with Stuck s' show ?thesis\n            by blast\n        qed\n      next\n        assume \"s\\<notin>b\" \"t=Normal s\" with P show ?thesis by simp\n      qed\n    qed\n    with wprems show \"t \\<in> Normal ` (P \\<inter> - b) \\<union> Abrupt ` A\" by blast\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume \"s \\<in> P\"\n    with wf \n    show \"\\<Gamma>\\<turnstile>While b c \\<down> Normal s\"\n    proof (induct)\n      fix s\n      assume hyp: \"\\<And>s'. \\<lbrakk>(s',s)\\<in>r; s' \\<in> P\\<rbrakk> \n                         \\<Longrightarrow> \\<Gamma>\\<turnstile>While b c \\<down> Normal s'\"\n      assume P: \"s \\<in> P\"\n      show \"\\<Gamma>\\<turnstile>While b c \\<down> Normal s\"\n      proof (cases \"s \\<in> b\")\n        case False with P show ?thesis\n          by (blast intro: terminates.intros)\n      next\n        case True\n        with valid_c P ctxt\n        have \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n          by (simp add: cvalidt_def validt_def)\n        moreover\n        {\n          fix s'\n          assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> s'\"\n          have \"\\<Gamma>\\<turnstile>While b c \\<down> s'\"\n          proof (cases s')\n            case (Normal s'')\n            with exec_c P True valid_c ctxt\n            have s': \"s' \\<in> Normal ` ({s'. (s', s) \\<in> r} \\<inter> P)\"\n              by (fastforce simp add: cvalidt_def validt_def valid_def)\n            then show ?thesis\n              by (blast intro: hyp)\n          qed auto\n        }\n        ultimately\n        show ?thesis\n          by (blast intro: terminates.intros)\n      qed\n    qed\n  qed\nnext\n  case (Guard \\<Theta> F g P c Q A  f)\n  have valid_c: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) Guard f g c Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow> t\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    assume P:\"s \\<in> (g \\<inter> P)\"\n    from exec P have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by cases auto\n    from valid_c ctxt this P t_notin_F\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by (rule cvalidt_postD)\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P:\"s \\<in> (g \\<inter> P)\"\n    thus \"\\<Gamma>\\<turnstile>Guard f g c  \\<down> Normal s\"\n      by (auto intro: terminates.intros cvalidt_termD [OF valid_c ctxt])\n  qed\nnext\n  case (Guarantee f F \\<Theta> g P c Q A)\n  have valid_c: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (g \\<inter> P) c Q,A\" by fact\n  have f_F: \"f \\<in> F\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Guard f g c Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow> t\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    assume P:\"s \\<in> P\"\n    from exec f_F t_notin_F have g: \"s \\<in> g\"\n      by cases auto\n    with P have P': \"s \\<in> g \\<inter> P\"\n      by blast\n    from exec g have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by cases auto\n    from valid_c ctxt this P' t_notin_F\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by (rule cvalidt_postD)\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P:\"s \\<in> P\"\n    thus \"\\<Gamma>\\<turnstile>Guard f g c  \\<down> Normal s\"\n      by (auto intro: terminates.intros cvalidt_termD [OF valid_c ctxt])\n  qed\nnext\n  case (CallRec P p Q A Specs r Specs_wf \\<Theta>  F)\n  have p: \"(P,p,Q,A) \\<in> Specs\"  by fact\n  have wf: \"wf r\" by fact\n  have Specs_wf: \n    \"Specs_wf = (\\<lambda>p \\<tau>. (\\<lambda>(P,q,Q,A). (P \\<inter> {s. ((s, q),\\<tau>,p) \\<in> r},q,Q,A)) ` Specs)\" by fact\n  from CallRec.hyps\n  have valid_body: \n    \"\\<forall>(P, p, Q, A)\\<in>Specs. p \\<in> dom \\<Gamma> \\<and>\n        (\\<forall>\\<tau>. \\<Gamma>,\\<Theta> \\<union> Specs_wf p \\<tau>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) the (\\<Gamma> p) Q,A)\" by auto\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  proof -\n    {\n      fix \\<tau>p \n      assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n      from wf\n      have \"\\<And>\\<tau> p P Q A.  \\<lbrakk>\\<tau>p = (\\<tau>,p); (P,p,Q,A) \\<in> Specs\\<rbrakk> \\<Longrightarrow> \n                  \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> (p))) Q,A\"    \n      proof (induct \\<tau>p rule: wf_induct [rule_format, consumes 1, case_names WF])\n        case (WF \\<tau>p \\<tau> p P Q A)\n        have \\<tau>p: \"\\<tau>p = (\\<tau>, p)\" by fact\n        have p: \"(P, p, Q, A) \\<in> Specs\" by fact\n        {\n          fix q P' Q' A'\n          assume q: \"(P',q,Q',A') \\<in> Specs\"\n          have \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' \\<inter> {s. ((s,q), \\<tau>,p) \\<in> r}) (Call q) Q',A'\"\n          proof (rule validtI)\n            fix s t\n            assume exec_q: \n              \"\\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow> t\"\n            assume Pre: \"s \\<in> P' \\<inter> {s. ((s,q), \\<tau>,p) \\<in> r}\"\n            assume t_notin_F: \"t \\<notin> Fault ` F\"\n            from Pre q \\<tau>p\n            have valid_bdy: \n              \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s} \\<inter> P') the (\\<Gamma> q) Q',A'\"\n              by - (rule WF.hyps, auto)\n            from Pre q\n            have Pre': \"s \\<in> {s} \\<inter> P'\"\n              by auto\n            from exec_q show \"t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n            proof (cases)\n              fix bdy \n              assume bdy: \"\\<Gamma> q = Some bdy\"\n              assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal s\\<rangle> \\<Rightarrow> t\"\n              from valid_bdy [simplified bdy option.sel]  t_notin_F exec_bdy Pre'\n              have \"t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n                by (auto simp add: validt_def valid_def)\n              with Pre q \n              show ?thesis\n                by auto\n            next\n              assume \"\\<Gamma> q = None\"\n              with q valid_body have False by auto\n              thus ?thesis ..\n            qed\n          next\n            fix s\n            assume Pre: \"s \\<in> P' \\<inter> {s. ((s,q), \\<tau>,p) \\<in> r}\"\n            from Pre q \\<tau>p\n            have valid_bdy: \n              \"\\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s} \\<inter> P') (the (\\<Gamma> q)) Q',A'\"\n              by - (rule WF.hyps, auto)\n            from Pre q\n            have Pre': \"s \\<in> {s} \\<inter> P'\"\n              by auto\n            from valid_bdy ctxt Pre'\n            have \"\\<Gamma>\\<turnstile>the (\\<Gamma> q) \\<down> Normal s\"\n              by (auto simp add: validt_def)\n            with valid_body q \n            show \"\\<Gamma>\\<turnstile>Call q\\<down> Normal s\"\n              by (fastforce intro: terminates.Call)\n          qed\n        }\n        hence \"\\<forall>(P, p, Q, A)\\<in>Specs_wf p \\<tau>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Call p Q,A\"\n          by (auto simp add: cvalidt_def Specs_wf)\n        with ctxt have \"\\<forall>(P, p, Q, A)\\<in>\\<Theta> \\<union> Specs_wf p \\<tau>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Call p Q,A\"\n          by auto\n        with p valid_body \n        show \"\\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> p)) Q,A\"\n          by (simp add: cvalidt_def) blast\n      qed\n    }\n    note lem = this\n    have valid_body': \n      \"\\<And>\\<tau>. \\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A \\<Longrightarrow> \n      \\<forall>(P,p,Q,A)\\<in>Specs. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<tau>} \\<inter> P) (the (\\<Gamma> p)) Q,A\"\n      by (auto intro: lem)\n    show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    proof (rule cvalidtI)\n      fix s t\n      assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n      assume exec_call: \"\\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow> t\"\n      assume P: \"s \\<in> P\"\n      assume t_notin_F: \"t \\<notin> Fault ` F\"\n      from exec_call show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      proof (cases)\n        fix bdy \n        assume bdy: \"\\<Gamma> p = Some bdy\"\n        assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal s\\<rangle> \\<Rightarrow> t\"\n        from exec_body bdy p P t_notin_F \n          valid_body' [of \"s\", OF ctxt] \n          ctxt\n        have \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n          apply (simp only: cvalidt_def validt_def valid_def) \n          apply (drule (1) bspec)\n          apply auto\n          done\n        with p P \n        show ?thesis\n          by simp\n      next\n        assume \"\\<Gamma> p = None\"\n        with p valid_body have False by auto\n        thus ?thesis by simp\n      qed\n    next\n      fix s\n      assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n      assume P: \"s \\<in> P\"\n      show \"\\<Gamma>\\<turnstile>Call p \\<down> Normal s\"\n      proof -\n        from ctxt P p valid_body' [of \"s\",OF ctxt]\n        have \"\\<Gamma>\\<turnstile>(the (\\<Gamma> p)) \\<down> Normal s\"\n          by (auto simp add: cvalidt_def validt_def)\n        with valid_body p show ?thesis\n          by (fastforce intro: terminates.Call)\n      qed\n    qed\n  qed\nnext\n  case (DynCom P \\<Theta> F c Q A)\n  hence valid_c: \"\\<forall>s\\<in>P. \\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (c s) Q,A\" by simp\n  show \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P DynCom c Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal s\\<rangle> \\<Rightarrow> t\" \n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    from exec show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases)\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c s,Normal s\\<rangle> \\<Rightarrow> t\"      \n      from cvalidt_postD [OF valid_c [rule_format, OF P] ctxt this P t_notin_F]\n      show ?thesis .\n    qed\n  next\n    fix s \n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s \\<in> P\"\n    show \"\\<Gamma>\\<turnstile>DynCom c \\<down> Normal s\"\n    proof -\n      from cvalidt_termD [OF valid_c [rule_format, OF P] ctxt P]\n      have \"\\<Gamma>\\<turnstile>c s \\<down> Normal s\" .\n      thus ?thesis\n        by (rule terminates.intros)\n    qed\n  qed\nnext\n  case (Throw \\<Theta> F A Q)\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> A Throw Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Throw,Normal s\\<rangle> \\<Rightarrow> t\" \"s \\<in> A\"\n    then show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by cases simp\n  next\n    fix s\n    show \"\\<Gamma>\\<turnstile>Throw \\<down> Normal s\"\n      by (rule terminates.intros)\n  qed\nnext\n  case (Catch \\<Theta> F P c\\<^sub>1 Q R c\\<^sub>2 A)\n  have valid_c1: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,R\" by fact\n  have valid_c2: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> R c\\<^sub>2 Q,A\" by fact\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P Catch c\\<^sub>1 c\\<^sub>2 Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow> t\" \n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    from exec show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof (cases)\n      fix s'\n      assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Abrupt s'\" \n      assume exec_c2: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s'\\<rangle> \\<Rightarrow> t\"\n      from cvalidt_postD [OF valid_c1 ctxt exec_c1 P]\n      have \"Abrupt s' \\<in> Abrupt ` R\"\n        by auto\n      with cvalidt_postD [OF valid_c2 ctxt] exec_c2 t_notin_F\n      show ?thesis\n        by fastforce\n    next\n      assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t\" \n      assume notAbr: \"\\<not> isAbr t\"\n      from cvalidt_postD [OF valid_c1 ctxt exec_c1 P] t_notin_F\n      have \"t \\<in> Normal ` Q \\<union> Abrupt ` R\" .\n      with notAbr\n      show ?thesis\n        by auto\n    qed\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s \\<in> P\"\n    show \"\\<Gamma>\\<turnstile>Catch c\\<^sub>1 c\\<^sub>2 \\<down> Normal s\"  \n    proof -\n      from valid_c1 ctxt P\n      have \"\\<Gamma>\\<turnstile>c\\<^sub>1\\<down> Normal s\"\n        by (rule cvalidt_termD)\n      moreover\n      {\n        fix r assume exec_c1: \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Abrupt r\"\n        from cvalidt_postD [OF valid_c1 ctxt exec_c1 P]\n        have r: \"Abrupt r\\<in>Normal ` Q \\<union> Abrupt ` R\"\n          by auto\n        hence \"Abrupt r\\<in>Abrupt ` R\" by fast\n        with cvalidt_termD [OF valid_c2 ctxt] exec_c1\n        have \"\\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal r\"\n          by fast\n      }\n      ultimately show ?thesis\n        by (iprover intro: terminates.intros)\n    qed\n  qed\nnext\n  case (Conseq P \\<Theta> F c Q A)\n  hence adapt: \n    \"\\<forall>s \\<in> P. (\\<exists>P' Q' A'. (\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A') \\<and> s \\<in> P'\\<and> Q' \\<subseteq> Q \\<and> A' \\<subseteq> A)\" by blast\n  show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  proof (rule cvalidtI)\n    fix s t\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n    assume P: \"s \\<in> P\"\n    assume t_notin_F: \"t \\<notin> Fault ` F\"\n    show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    proof -\n      from adapt [rule_format, OF P]\n      obtain P' and Q' and A' where \n        valid_P'_Q': \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A'\"\n        and weaken: \"s \\<in> P'\" \"Q' \\<subseteq>  Q\" \"A'\\<subseteq> A\"\n        by blast\n      from exec valid_P'_Q' ctxt t_notin_F\n      have P'_Q': \"Normal s \\<in> Normal ` P' \\<longrightarrow> \n        t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n        by (unfold cvalidt_def validt_def valid_def) blast\n      hence \"s \\<in> P' \\<longrightarrow> t \\<in> Normal ` Q' \\<union> Abrupt ` A'\"\n        by blast\n      with weaken \n      show ?thesis\n        by blast\n    qed\n  next\n    fix s\n    assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    assume P: \"s \\<in> P\"\n    show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    proof -\n      from P adapt\n      obtain P' and Q' and  A' where \n        \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P' c Q',A'\"\n        \"s \\<in> P'\"\n        by blast\n      with ctxt\n      show ?thesis\n        by (simp add: cvalidt_def validt_def)\n    qed\n  qed\nnext\n  case (Asm P p Q A \\<Theta> F)\n  assume \"(P, p, Q, A) \\<in> \\<Theta>\"\n  then show \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n    by (auto simp add: cvalidt_def )\nnext\n  case ExFalso thus ?case by iprover\nqed\n\nlemma hoaret_sound':\n\"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (drule hoaret_sound)\n  apply (simp add: cvalidt_def)\n  done\n\ntheorem total_to_partial: \n assumes total: \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" shows \"\\<Gamma>,{}\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from total have \"\\<Gamma>,{}\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (rule hoaret_sound)\n  hence \"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (simp add: cvalidt_def validt_def cvalid_def)\n  thus ?thesis\n    by (rule hoare_complete)\nqed\n\nsubsection {* Completeness *}\n\nlemma MGT_valid:\n\"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \\<Gamma>\\<turnstile>c\\<down>Normal s} c \n    {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t}, {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\nproof (rule validtI) \n  fix s t\n  assume \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n         \"s \\<in> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \\<Gamma>\\<turnstile>c\\<down>Normal s}\"\n         \"t \\<notin> Fault ` F\"\n  thus \"t \\<in> Normal ` {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t} \\<union> \n            Abrupt ` {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    apply (cases t) \n    apply (auto simp add: final_notin_def)\n    done\nnext\n  fix s\n  assume \"s \\<in> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \\<Gamma>\\<turnstile>c\\<down>Normal s}\"\n  thus \"\\<Gamma>\\<turnstile>c\\<down>Normal s\"\n    by blast\nqed\n\ntext {* The consequence rule where the existential @{term Z} is instantiated\nto @{term s}. Usefull in proof of @{text \"MGT_lemma\"}.*}\nlemma ConseqMGT: \n  assumes modif: \"\\<forall>Z::'a. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (P' Z::'a assn) c (Q' Z),(A' Z)\"\n  assumes impl: \"\\<And>s. s \\<in> P \\<Longrightarrow> s \\<in> P' s \\<and> (\\<forall>t. t \\<in> Q' s \\<longrightarrow> t \\<in> Q) \\<and> \n                                            (\\<forall>t. t \\<in> A' s \\<longrightarrow> t \\<in> A)\"\n  shows \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nusing impl \nby - (rule conseq [OF modif],blast)\n\nlemma MGT_implies_complete:\n  assumes MGT: \"\\<forall>Z. \\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                                 \\<Gamma>\\<turnstile>c\\<down>Normal s}\n                              c \n                            {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                            {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  assumes valid: \"\\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" \n  shows \"\\<Gamma>,{} \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  using MGT\n  apply (rule ConseqMGT) \n  apply (insert valid)\n  apply (auto simp add: validt_def valid_def intro!: final_notinI)\n  done\n\nlemma conseq_extract_state_indep_prop: \n  assumes state_indep_prop:\"\\<forall>s \\<in> P. R\" \n  assumes to_show: \"R \\<Longrightarrow> \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule Conseq)\n  apply (clarify)\n  apply (rule_tac x=\"P\" in exI)\n  apply (rule_tac x=\"Q\" in exI)\n  apply (rule_tac x=\"A\" in exI)\n  using state_indep_prop to_show\n  by blast\n\nlemma MGT_lemma:\n  assumes MGT_Calls: \n    \"\\<forall>p \\<in> dom \\<Gamma>. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> \n       {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n           \\<Gamma>\\<turnstile>(Call p)\\<down>Normal s}\n             (Call p)\n       {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n       {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  shows \"\\<And>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                          \\<Gamma>\\<turnstile>c\\<down>Normal s} \n               c \n             {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\nproof (induct c)\n  case Skip\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Skip,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                   \\<Gamma>\\<turnstile>Skip \\<down> Normal s} \n               Skip\n            {t. \\<Gamma>\\<turnstile>\\<langle>Skip,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>Skip,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoaret.Skip [THEN conseqPre])\n       (auto elim: exec_elim_cases simp add: final_notin_def \n             intro: exec.intros terminates.intros)\nnext\n  case (Basic f)\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Basic f,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                 \\<Gamma>\\<turnstile>Basic f \\<down> Normal s} \n                Basic f\n              {t. \\<Gamma>\\<turnstile>\\<langle>Basic f,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Basic f,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoaret.Basic [THEN conseqPre]) \n       (auto elim: exec_elim_cases simp add: final_notin_def \n             intro: exec.intros terminates.intros)\nnext\n  case (Spec r)\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Spec r,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Spec r \\<down> Normal s} \n                Spec r\n              {t. \\<Gamma>\\<turnstile>\\<langle>Spec r,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Spec r,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    apply (rule hoaret.Spec [THEN conseqPre])\n    apply (clarsimp simp add: final_notin_def)\n    apply (case_tac \"\\<exists>t. (Z,t) \\<in> r\")\n    apply (auto elim: exec_elim_cases simp add: final_notin_def intro: exec.intros)\n    done\nnext\n  case (Seq c1 c2) \n  have hyp_c1: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                                \\<Gamma>\\<turnstile>c1\\<down>Normal s}\n                            c1 \n                           {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                           {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" \n    using Seq.hyps by iprover\n  have hyp_c2: \"\\<forall> Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                                 \\<Gamma>\\<turnstile>c2\\<down>Normal s}\n                              c2 \n                            {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                            {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" \n    using Seq.hyps by iprover\n  from hyp_c1 \n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                \\<Gamma>\\<turnstile>Seq c1 c2\\<down>Normal s} c1 \n    {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t \\<and> \\<Gamma>\\<turnstile>\\<langle>c2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n        \\<Gamma>\\<turnstile>c2\\<down>Normal t},\n    {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT)\n       (auto dest: Seq_NoFaultStuckD1 [simplified] Seq_NoFaultStuckD2 [simplified]\n             elim: terminates_Normal_elim_cases \n             intro: exec.intros)\n  thus \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                 \\<Gamma>\\<turnstile>Seq c1 c2\\<down>Normal s} \n                Seq c1 c2\n              {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  proof (rule hoaret.Seq )\n    show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t \\<and>\n                    \\<Gamma>\\<turnstile>\\<langle>c2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \\<Gamma>\\<turnstile>c2 \\<down> Normal t}\n                 c2 \n                {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    proof (rule ConseqMGT [OF hyp_c2],safe)\n      fix r t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal r\" \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal r\\<rangle> \\<Rightarrow> Normal t\"\n      then show \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n        by (rule exec.intros)\n    next\n      fix r t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal r\" \"\\<Gamma>\\<turnstile>\\<langle>c2,Normal r\\<rangle> \\<Rightarrow> Abrupt t\"\n      then show \"\\<Gamma>\\<turnstile>\\<langle>Seq c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n        by (rule exec.intros)\n    qed\n  qed\nnext\n  case (Cond b c1 c2) \n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                         \\<Gamma>\\<turnstile>c1\\<down>Normal s} \n                     c1 \n                   {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                   {t. \\<Gamma>\\<turnstile>\\<langle>c1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" \n    using Cond.hyps by iprover  \n  hence \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                     \\<Gamma>\\<turnstile>(Cond b c1 c2)\\<down>Normal s}\\<inter>b) \n                c1 \n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"  \n    by (rule ConseqMGT)\n       (fastforce simp add: final_notin_def intro: exec.CondTrue \n                 elim: terminates_Normal_elim_cases)\n  moreover\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                               \\<Gamma>\\<turnstile>c2\\<down>Normal s} \n                      c2 \n                    {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                    {t. \\<Gamma>\\<turnstile>\\<langle>c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"  \n    using Cond.hyps by iprover  \n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>(Cond b c1 c2)\\<down>Normal s}\\<inter>-b) \n                c2 \n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" \n    by (rule ConseqMGT)\n       (fastforce simp add: final_notin_def intro: exec.CondFalse \n                 elim: terminates_Normal_elim_cases)\n  ultimately\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n               \\<Gamma>\\<turnstile>(Cond b c1 c2)\\<down>Normal s} \n               (Cond b c1 c2)\n              {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Cond b c1 c2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoaret.Cond)       \nnext\n  case (While b c)\n  let ?unroll = \"({(s,t). s\\<in>b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t})\\<^sup>*\"\n  let ?P' = \"\\<lambda>Z. {t. (Z,t)\\<in>?unroll \\<and> \n                    (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                         \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                             (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)) \\<and>\n                    \\<Gamma>\\<turnstile>(While b c)\\<down>Normal t}\"\n  let ?A = \"\\<lambda>Z. {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  let ?r = \"{(t,s). \\<Gamma>\\<turnstile>(While b c)\\<down>Normal s \\<and> s\\<in>b \\<and> \n                    \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t}\"\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>  \n                  \\<Gamma>\\<turnstile>(While b c)\\<down>Normal s} \n              (While b c)\n              {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  proof (rule ConseqMGT [where ?P'=\"\\<lambda> Z. ?P' Z\" \n                         and ?Q'=\"\\<lambda> Z. ?P' Z \\<inter> - b\"])\n    have wf_r: \"wf ?r\" by (rule wf_terminates_while)\n    show \"\\<forall> Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> (?P' Z) (While b c) (?P' Z \\<inter> - b),(?A Z)\"\n    proof (rule allI, rule hoaret.While [OF wf_r])\n      fix Z\n      from While \n      have hyp_c: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                                  \\<Gamma>\\<turnstile>c\\<down>Normal s}\n                                c\n                              {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                              {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" by iprover\n      show \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> ({\\<sigma>} \\<inter> ?P' Z  \\<inter> b) c \n                       ({t. (t, \\<sigma>) \\<in> ?r} \\<inter> ?P' Z),(?A Z)\"\n      proof (rule allI, rule ConseqMGT [OF hyp_c])\n        fix \\<sigma> s\n        assume  \"s\\<in> {\\<sigma>} \\<inter>  \n                   {t. (Z, t) \\<in> ?unroll \\<and> \n                      (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                           \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                               (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                                    \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)) \\<and>\n                      \\<Gamma>\\<turnstile>(While b c)\\<down>Normal t}\n                   \\<inter> b\"\n        then obtain \n          s_eq_\\<sigma>: \"s=\\<sigma>\" and\n          Z_s_unroll: \"(Z,s) \\<in> ?unroll\" and\n          noabort:\"\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                        \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                            (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)\" and\n          while_term:  \"\\<Gamma>\\<turnstile>(While b c)\\<down>Normal s\" and\n          s_in_b: \"s\\<in>b\" \n          by blast\n        show \"s \\<in> {t. t = s \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                       \\<Gamma>\\<turnstile>c\\<down>Normal t} \\<and>\n        (\\<forall>t. t \\<in> {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t} \\<longrightarrow>\n             t \\<in> {t. (t,\\<sigma>) \\<in> ?r} \\<inter>  \n                 {t. (Z, t) \\<in> ?unroll \\<and> \n                     (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow>  e\\<in>b \n                           \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                              (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)) \\<and> \n                      \\<Gamma>\\<turnstile>(While b c)\\<down>Normal t})  \\<and> \n         (\\<forall>t. t \\<in> {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Abrupt t} \\<longrightarrow>\n             t \\<in> {t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})\"\n          (is \"?C1 \\<and> ?C2 \\<and> ?C3\")\n        proof (intro conjI)\n          from Z_s_unroll noabort s_in_b while_term show ?C1 \n            by (blast elim: terminates_Normal_elim_cases)\n        next\n          {\n            fix t \n            assume s_t: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t\"\n            with s_eq_\\<sigma> while_term s_in_b have \"(t,\\<sigma>) \\<in> ?r\"\n              by blast\n            moreover\n            from Z_s_unroll s_t s_in_b \n            have \"(Z, t) \\<in> ?unroll\"\n              by (blast intro: rtrancl_into_rtrancl)\n            moreover from while_term s_t s_in_b \n            have \"\\<Gamma>\\<turnstile>(While b c)\\<down>Normal t\"\n              by (blast elim: terminates_Normal_elim_cases)\n            moreover note noabort\n            ultimately \n            have \"(t,\\<sigma>) \\<in> ?r \\<and> (Z, t) \\<in> ?unroll \\<and> \n                  (\\<forall>e. (Z,e)\\<in>?unroll \\<longrightarrow> e\\<in>b\n                        \\<longrightarrow> \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                            (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                                  \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)) \\<and>\n                  \\<Gamma>\\<turnstile>(While b c)\\<down>Normal t\"\n              by iprover\n          }\n          then show ?C2 by blast\n        next\n          {\n            fix t\n            assume s_t:  \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Abrupt t\" \n            from Z_s_unroll noabort s_t s_in_b\n            have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n              by blast\n          } thus ?C3 by simp\n        qed\n      qed\n    qed\n  next\n    fix s\n    assume P: \"s \\<in> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>While b c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                       \\<Gamma>\\<turnstile>While b c \\<down> Normal s}\"\n    hence WhileNoFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n      by auto\n    show \"s \\<in> ?P' s \\<and> \n     (\\<forall>t. t\\<in>(?P' s \\<inter> - b)\\<longrightarrow>\n          t\\<in>{t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t})\\<and>\n     (\\<forall>t. t\\<in>?A s \\<longrightarrow> t\\<in>?A Z)\"\n    proof (intro conjI)\n      {\n        fix e\n        assume \"(Z,e) \\<in> ?unroll\" \"e \\<in> b\"\n        from this WhileNoFault\n        have \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n               (\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>Abrupt u \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u)\" (is \"?Prop Z e\")\n        proof (induct rule: converse_rtrancl_induct [consumes 1])\n          assume e_in_b: \"e \\<in> b\"\n          assume WhileNoFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n          with e_in_b WhileNoFault\n          have cNoFault: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n            by (auto simp add: final_notin_def intro: exec.intros)\n          moreover\n          {\n            fix u assume \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow> Abrupt u\"\n            with e_in_b have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal e\\<rangle> \\<Rightarrow> Abrupt u\"\n              by (blast intro: exec.intros)\n          }\n          ultimately\n          show \"?Prop e e\"\n            by iprover\n        next\n          fix Z r\n          assume e_in_b: \"e\\<in>b\" \n          assume WhileNoFault: \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n          assume hyp: \"\\<lbrakk>e\\<in>b;\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\\<rbrakk>\n                       \\<Longrightarrow> ?Prop r e\"\n          assume Z_r:\n            \"(Z, r) \\<in> {(Z, r). Z \\<in> b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal r}\"\n          with WhileNoFault\n          have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n            by (auto simp add: final_notin_def intro: exec.intros)\n          from hyp [OF e_in_b this] obtain\n            cNoFault: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\" and\n            Abrupt_r: \"\\<forall>u. \\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow> Abrupt u \\<longrightarrow> \n                            \\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow> Abrupt u\"\n            by simp\n          \n           {\n            fix u assume \"\\<Gamma>\\<turnstile>\\<langle>c,Normal e\\<rangle> \\<Rightarrow> Abrupt u\"\n            with Abrupt_r have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow> Abrupt u\" by simp\n            moreover from  Z_r obtain\n              \"Z \\<in> b\"  \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal r\"\n              by simp\n            ultimately have \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Abrupt u\"\n              by (blast intro: exec.intros)\n          }\n          with cNoFault show \"?Prop Z e\"\n            by iprover\n        qed\n      }\n      with P show \"s \\<in> ?P' s\"\n        by blast\n    next\n      {\n        fix t\n        assume \"termination\": \"t \\<notin> b\"\n        assume \"(Z, t) \\<in> ?unroll\"\n        hence \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n        proof (induct rule: converse_rtrancl_induct [consumes 1])\n          from \"termination\" \n          show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal t\\<rangle> \\<Rightarrow> Normal t\"\n            by (blast intro: exec.WhileFalse)\n        next\n          fix Z r\n          assume first_body: \n                 \"(Z, r) \\<in> {(s, t). s \\<in> b \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> Normal t}\"\n          assume \"(r, t) \\<in> ?unroll\"\n          assume rest_loop: \"\\<Gamma>\\<turnstile>\\<langle>While b c, Normal r\\<rangle> \\<Rightarrow> Normal t\"\n          show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n          proof -\n            from first_body obtain\n              \"Z \\<in> b\" \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal r\"\n              by fast\n            moreover\n            from rest_loop have\n              \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal r\\<rangle> \\<Rightarrow> Normal t\"\n              by fast\n            ultimately show \"\\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n              by (rule exec.WhileTrue)\n          qed\n        qed\n      }\n      with P\n      show \"(\\<forall>t. t\\<in>(?P' s \\<inter> - b)\n            \\<longrightarrow>t\\<in>{t. \\<Gamma>\\<turnstile>\\<langle>While b c,Normal Z\\<rangle> \\<Rightarrow> Normal t})\"\n        by blast\n    next\n      from P show \"\\<forall>t. t\\<in>?A s \\<longrightarrow> t\\<in>?A Z\"\n        by simp\n    qed\n  qed\nnext\n  case (Call p)\n  from noStuck_Call\n  have \"\\<forall>s \\<in> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>\n                         \\<Gamma>\\<turnstile>Call p\\<down> Normal s}.\n          p \\<in> dom \\<Gamma>\"\n    by (fastforce simp add: final_notin_def)\n  then show ?case\n  proof (rule conseq_extract_state_indep_prop)\n    assume p_defined: \"p \\<in> dom \\<Gamma>\"\n    with MGT_Calls show\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s=Z \\<and> \n                 \\<Gamma>\\<turnstile>\\<langle>Call p ,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\\<and>\n                 \\<Gamma>\\<turnstile>Call  p\\<down>Normal s}\n                (Call p)\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      by (auto)\n  qed\nnext\n  case (DynCom c)\n  have hyp: \n    \"\\<And>s'. \\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c s',Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                       \\<Gamma>\\<turnstile>c s'\\<down>Normal s} c s'\n      {t. \\<Gamma>\\<turnstile>\\<langle>c s',Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c s',Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using DynCom by simp\n  have hyp':\n  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n            \\<Gamma>\\<turnstile>DynCom c\\<down>Normal s} \n         (c Z)\n        {t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT [OF hyp]) \n       (fastforce simp add: final_notin_def intro: exec.intros \n          elim: terminates_Normal_elim_cases)\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>{s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                 \\<Gamma>\\<turnstile>DynCom c\\<down>Normal s}\n                DynCom c\n             {t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>DynCom c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    apply (rule hoaret.DynCom)\n    apply (clarsimp)\n    apply (rule hyp' [simplified])\n    done\nnext\n  case (Guard f g c)\n  have hyp_c: \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                              \\<Gamma>\\<turnstile>c\\<down>Normal s} \n                     c \n                   {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                   {t. \\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Guard by iprover\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Guard f g c\\<down> Normal s} \n                Guard f g c \n              {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n  proof (cases \"f \\<in> F\")\n    case True\n    from hyp_c\n    have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>(g \\<inter> {s. s=Z \\<and> \n                     \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck}\\<union> Fault ` (-F))\\<and>\n                     \\<Gamma>\\<turnstile>Guard f g c\\<down> Normal s})\n                   c\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      apply (rule ConseqMGT)\n      apply (insert True)\n      apply  (auto simp add: final_notin_def intro: exec.intros \n                   elim: terminates_Normal_elim_cases)\n      done\n    from True this\n    show ?thesis\n      by (rule conseqPre [OF Guarantee]) auto\n  next\n    case False\n    from hyp_c\n    have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F \\<^esub>(g \\<inter> {s. s \\<in> g \\<and> s=Z \\<and> \n                     \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck}\\<union> Fault ` (-F))\\<and>\n                     \\<Gamma>\\<turnstile>Guard f g c\\<down> Normal s} )\n                   c\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                 {t. \\<Gamma>\\<turnstile>\\<langle>Guard f g c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      apply (rule ConseqMGT)\n      apply clarify\n      apply (frule Guard_noFaultStuckD [OF _ False])\n      apply  (auto simp add: final_notin_def intro: exec.intros \n                   elim: terminates_Normal_elim_cases)\n      done\n    then show ?thesis\n      apply (rule conseqPre [OF hoaret.Guard])\n      apply clarify\n      apply (frule Guard_noFaultStuckD [OF _ False])\n      apply auto\n      done\n  qed\nnext\n  case Throw\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Throw,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Throw \\<down> Normal s}\n              Throw\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule conseqPre [OF hoaret.Throw]) \n       (blast intro: exec.intros terminates.intros)\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                        \\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s} \n                    c\\<^sub>1\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                   \\<Gamma>\\<turnstile>Catch c\\<^sub>1 c\\<^sub>2 \\<down> Normal s} \n                c\\<^sub>1\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t \\<and> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal t \\<and>\n                   \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))}\"\n    by (rule ConseqMGT)\n       (fastforce intro: exec.intros terminates.intros \n                 elim: terminates_Normal_elim_cases\n                 simp add: final_notin_def)\n  moreover\n  have \n    \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                     \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s} c\\<^sub>2\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                  {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  hence \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow>Abrupt s \\<and> \\<Gamma>\\<turnstile>c\\<^sub>2 \\<down> Normal s \\<and> \n                   \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))} \n               c\\<^sub>2\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      by (rule ConseqMGT)\n         (fastforce intro: exec.intros terminates.intros \n                   simp add: noFault_def')\n  ultimately\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                   \\<Gamma>\\<turnstile>Catch c\\<^sub>1 c\\<^sub>2 \\<down> Normal s} \n                Catch c\\<^sub>1 c\\<^sub>2\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule hoaret.Catch )\nqed\n\n\n\n\n      assume \"Z \\<in> g\"\n      from this have \"\\<Gamma>\\<turnstile>(Guard f g c,Normal Z) \\<rightarrow> (c,Normal Z)\"\n        by (rule step.Guard)\n      from step_redexes [OF this c'] obtain c'' where\n        step: \"\\<Gamma>\\<turnstile> (c', Normal Z) \\<rightarrow> (c'', Normal Z)\"  and c'': \"c \\<in> redexes c''\"\n        by blast\n      note steps also note step \n      finally show \"\\<exists>c'. \\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z) \\<and> c \\<in> redexes c'\"\n        using c'' by blast\n    next\n      fix t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\" \n        \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n      thus \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n        using False\n        by (cases \"Z\\<in> g\") (auto simp add: final_notin_def intro: exec.intros )\n    next\n      fix t\n      assume \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\" \n             \"\\<Gamma>\\<turnstile>\\<langle>c,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n      thus \"\\<Gamma>\\<turnstile>\\<langle>Guard f g c ,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n        using False\n        by (cases \"Z\\<in> g\") (auto simp add: final_notin_def intro: exec.intros )\n    qed\n    then show ?thesis\n      apply (rule conseqPre [OF hoaret.Guard])\n      apply clarify\n      apply (frule Guard_noFaultStuckD [OF _ False])\n      apply auto\n      done\n  qed\nnext\n  case Throw\n  show \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Throw,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                  \\<Gamma>\\<turnstile>Call p\\<down>Normal \\<sigma> \\<and>\n                (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and> Throw \\<in> redexes c')}\n              Throw\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Throw,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule conseqPre [OF hoaret.Throw]) \n       (blast intro: exec.intros terminates.intros)\nnext\n  case (Catch c\\<^sub>1 c\\<^sub>2)\n  have hyp_c1:\n   \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s= Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call p \\<down> Normal \\<sigma> \\<and>\n                (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and> \n                      c\\<^sub>1 \\<in> redexes c')}\n               c\\<^sub>1 \n              {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  have hyp_c2:\n   \"\\<forall>Z. \\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s= Z \\<and> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                     \\<Gamma>\\<turnstile>Call p\\<down> Normal \\<sigma> \\<and>\n                (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal s) \\<and> c\\<^sub>2 \\<in> redexes c')}\n               c\\<^sub>2\n              {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},{t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    using Catch.hyps by iprover\n  have\n    \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n               \\<Gamma>\\<turnstile>Call p\\<down> Normal \\<sigma> \\<and>\n            (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>)\\<rightarrow>\\<^sup>+(c',Normal s) \\<and>\n                   Catch c\\<^sub>1 c\\<^sub>2 \\<in> redexes c')}\n            c\\<^sub>1\n           {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n           {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t \\<and> \n               \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault`(-F)) \\<and> \\<Gamma>\\<turnstile>Call p \\<down> Normal \\<sigma> \\<and>\n               (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal t) \\<and> c\\<^sub>2 \\<in> redexes c')}\"\n  proof (rule ConseqMGT [OF hyp_c1],clarify,safe) \n    assume \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n    thus \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n      by (fastforce simp add: final_notin_def intro: exec.intros)\n  next\n    fix c'\n    assume steps: \"\\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z)\" \n    assume c': \"Catch c\\<^sub>1 c\\<^sub>2 \\<in> redexes c'\"\n    from steps redexes_subset [OF this]\n    show \"\\<exists>c'. \\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z) \\<and> c\\<^sub>1 \\<in> redexes c'\"\n      by (auto iff:  root_in_redexes)\n  next\n    fix t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n    thus \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t\"\n      by (auto intro: exec.intros)\n  next\n    fix t\n    assume \"\\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\" \n      \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n    thus \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F))\"\n      by (auto simp add: final_notin_def intro: exec.intros)\n  next\n    fix c' t\n    assume steps_c': \"\\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal Z)\" \n    assume red: \"Catch c\\<^sub>1 c\\<^sub>2 \\<in> redexes c'\"\n    assume exec_c\\<^sub>1: \"\\<Gamma>\\<turnstile> \\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t\"\n    show \"\\<exists>c'. \\<Gamma>\\<turnstile> (Call p, Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c', Normal t) \\<and> c\\<^sub>2 \\<in> redexes c'\"\n    proof -\n      note steps_c'\n      also\n      from exec_impl_steps_Normal_Abrupt [OF exec_c\\<^sub>1]\n      have \"\\<Gamma>\\<turnstile> (c\\<^sub>1, Normal Z) \\<rightarrow>\\<^sup>* (Throw, Normal t)\".\n      from steps_redexes_Catch [OF this red] \n      obtain c'' where\n        steps_c'': \"\\<Gamma>\\<turnstile> (c', Normal Z) \\<rightarrow>\\<^sup>* (c'', Normal t)\" and\n        Catch: \"Catch Throw c\\<^sub>2 \\<in> redexes c''\"\n        by blast\n      note steps_c''\n      also \n      have step_Catch: \"\\<Gamma>\\<turnstile> (Catch Throw c\\<^sub>2,Normal t) \\<rightarrow> (c\\<^sub>2,Normal t)\"\n        by (rule step.CatchThrow)\n      from step_redexes [OF step_Catch Catch]\n      obtain c''' where\n        step_c''': \"\\<Gamma>\\<turnstile> (c'', Normal t) \\<rightarrow> (c''', Normal t)\" and\n        c2: \"c\\<^sub>2 \\<in> redexes c'''\"\n        by blast\n      note step_c'''\n      finally show ?thesis\n        using c2\n        by blast\n    qed\n  qed\n  moreover\n  have \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {t. \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal Z\\<rangle> \\<Rightarrow> Abrupt t \\<and> \n                  \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal t\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                  \\<Gamma>\\<turnstile>Call p \\<down> Normal \\<sigma> \\<and>\n                  (\\<exists>c'. \\<Gamma>\\<turnstile>(Call p,Normal \\<sigma>) \\<rightarrow>\\<^sup>+ (c',Normal t) \\<and> c\\<^sub>2 \\<in> redexes c')} \n               c\\<^sub>2\n              {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Catch c\\<^sub>1 c\\<^sub>2,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n    by (rule ConseqMGT [OF hyp_c2]) (fastforce intro: exec.intros)\n  ultimately show ?case\n    by (rule hoaret.Catch)\nqed\n\n\ntext {* To prove a procedure implementation correct it suffices to assume\n       only the procedure specifications of procedures that actually\n       occur during evaluation of the body.  \n    *}\n\nlemma Call_lemma:\n assumes A: \n \"\\<forall>q \\<in> dom \\<Gamma>. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> \n                 {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call q\\<down>Normal s \\<and> ((s,q),(\\<sigma>,p)) \\<in> termi_call_steps \\<Gamma>}\n                 (Call q)\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n assumes pdef: \"p \\<in> dom \\<Gamma>\"\n shows \"\\<And>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>  \n              ({\\<sigma>} \\<inter> {s. s=Z \\<and>\\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>  \n                                 \\<Gamma>\\<turnstile>the (\\<Gamma> p)\\<down>Normal s}) \n                 the (\\<Gamma> p) \n              {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (rule conseqPre)\napply (rule Call_lemma' [OF A])\nusing pdef\napply (fastforce intro: terminates.intros tranclp.r_into_trancl [of \"(step \\<Gamma>)\", OF step.Call] root_in_redexes)\ndone\n\nlemma Call_lemma_switch_Call_body:\n assumes \n call: \"\\<forall>q \\<in> dom \\<Gamma>. \\<forall>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> \n                 {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call q,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call q\\<down>Normal s \\<and> ((s,q),(\\<sigma>,p)) \\<in> termi_call_steps \\<Gamma>}\n                 (Call q)\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n                {t. \\<Gamma>\\<turnstile>\\<langle>Call q,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n assumes p_defined: \"p \\<in> dom \\<Gamma>\"\n shows \"\\<And>Z. \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>  \n              ({\\<sigma>} \\<inter> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and>  \n                                 \\<Gamma>\\<turnstile>Call p\\<down>Normal s}) \n                 the (\\<Gamma> p) \n              {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n              {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (simp only: exec_Call_body' [OF p_defined] noFaultStuck_Call_body' [OF p_defined] terminates_Normal_Call_body [OF p_defined])\napply (rule conseqPre)\napply (rule Call_lemma')\napply (rule call)\nusing p_defined\napply (fastforce intro: terminates.intros tranclp.r_into_trancl [of \"(step \\<Gamma>)\", OF step.Call] \nroot_in_redexes)\ndone\n\nlemma MGT_Call:\n\"\\<forall>p \\<in> dom \\<Gamma>. \\<forall>Z. \n  \\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n             \\<Gamma>\\<turnstile>(Call p)\\<down>Normal s}\n           (Call p)\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\napply (intro ballI allI)\napply (rule CallRec' [where Procs=\"dom \\<Gamma>\" and\n    P=\"\\<lambda>p Z. {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                    \\<Gamma>\\<turnstile>Call p\\<down>Normal s}\" and\n    Q=\"\\<lambda>p Z. {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t}\" and\n    A=\"\\<lambda>p Z. {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\" and\n    r=\"termi_call_steps \\<Gamma>\"\n    ]) \napply    simp\napply   simp\napply  (rule wf_termi_call_steps)\napply (intro ballI allI)\napply simp\napply (rule Call_lemma_switch_Call_body [rule_format, simplified])\napply  (rule hoaret.Asm)\napply  fastforce\napply assumption\ndone\n\n\nlemma CollInt_iff: \"{s. P s} \\<inter> {s. Q s} = {s. P s \\<and> Q s}\"\n  by auto\n\nlemma image_Un_conv: \"f ` (\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. {x p Z}) =  (\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. {f (x p Z)})\"\n  by (auto iff: not_None_eq)\n\n\ntext {* Another proof of @{text MGT_Call}, maybe a little more readable *}\nlemma \n\"\\<forall>p \\<in> dom \\<Gamma>. \\<forall>Z. \n  \\<Gamma>,{} \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> {s. s=Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n             \\<Gamma>\\<turnstile>(Call p)\\<down>Normal s}\n           (Call p)\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n          {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\nproof -\n  {\n    fix p Z \\<sigma>\n    assume defined: \"p \\<in> dom \\<Gamma>\"\n    def Specs == \"(\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. \n            {({s. s=Z \\<and> \n              \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n              \\<Gamma>\\<turnstile>Call p\\<down>Normal s},\n             p,\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})})\"\n    def Specs_wf == \"(\\<lambda>p \\<sigma>. (\\<lambda>(P,q,Q,A). \n                       (P \\<inter> {s. ((s,q),\\<sigma>,p) \\<in> termi_call_steps \\<Gamma>}, q, Q, A)) ` Specs)\"\n    have \"\\<Gamma>,Specs_wf p \\<sigma>\n            \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>({\\<sigma>} \\<inter>\n                 {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                  \\<Gamma>\\<turnstile>the (\\<Gamma> p)\\<down>Normal s}) \n                (the (\\<Gamma> p))\n               {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>the (\\<Gamma> p),Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      apply (rule Call_lemma [rule_format, OF _ defined])\n      apply (rule hoaret.Asm)\n      apply (clarsimp simp add: Specs_wf_def Specs_def image_Un_conv)\n      apply (rule_tac x=q in bexI)\n      apply (rule_tac x=Z in exI)\n      apply (clarsimp simp add: CollInt_iff)\n      apply auto\n      done\n    hence \"\\<Gamma>,Specs_wf p \\<sigma>\n            \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub>({\\<sigma>} \\<inter>\n                 {s. s = Z \\<and> \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n                  \\<Gamma>\\<turnstile>Call p\\<down>Normal s}) \n                (the (\\<Gamma> p))\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n               {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t}\"\n      by (simp only: exec_Call_body' [OF defined] \n                   noFaultStuck_Call_body' [OF defined] \n                  terminates_Normal_Call_body [OF defined])\n  } note bdy=this\n  show ?thesis\n    apply (intro ballI allI)\n    apply (rule hoaret.CallRec [where Specs=\"(\\<Union>p\\<in>dom \\<Gamma>. \\<Union>Z. \n            {({s. s=Z \\<and> \n              \\<Gamma>\\<turnstile>\\<langle>Call p,Normal s\\<rangle> \\<Rightarrow>\\<notin>({Stuck} \\<union> Fault ` (-F)) \\<and> \n              \\<Gamma>\\<turnstile>Call p\\<down>Normal s},\n             p,\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Normal t},\n             {t. \\<Gamma>\\<turnstile>\\<langle>Call p,Normal Z\\<rangle> \\<Rightarrow> Abrupt t})})\", \n             OF _ wf_termi_call_steps [of \\<Gamma>] refl])\n    apply fastforce\n    apply clarify\n    apply (rule conjI)\n    apply  fastforce\n    apply (rule allI)\n    apply (simp (no_asm_use) only : Un_empty_left)\n    apply (rule bdy)\n    apply auto\n    done\nqed\n\n\ntheorem hoaret_complete: \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A \\<Longrightarrow> \\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  by (iprover intro: MGT_implies_complete MGT_lemma [OF MGT_Call])\n\nlemma hoaret_complete': \n  assumes cvalid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows  \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (cases \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\")\n  case True\n  hence \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (rule hoaret_complete)\n  thus \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (rule hoaret_augment_context) simp\nnext\n  case False\n  with cvalid\n  show ?thesis\n    by (rule ExFalso)\nqed\n\nsubsection {* And Now: Some Useful Rules *}\n\nsubsubsection {* Modify Return *}\n\nlemma ProcModifyReturn_sound:\n  assumes valid_call: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P call init p return' c Q,A\"\n  assumes valid_modif: \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call p) (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \n  assumes res_modif:\n  \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\n  assumes ret_modifAbr: \n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\n  shows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>call init p return c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from exec\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: exec_call_Normal_elim)\n    fix bdy t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\" \n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> \\<Rightarrow> t\" \n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>(Call p ),Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with res_modif have \"Normal (return' s t') = Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy \n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_call)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\" \n    assume t: \"t = Abrupt (return s t')\"\n    also from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>(Call p),Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_callAbrupt)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy f\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Fault f\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callFault)\n    from cvalidt_postD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Stuck\"  \n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callStuck)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    assume \"\\<Gamma> p = None\" \"t=Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callUndefined)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults)\n  assume P: \"s \\<in> P\"\n  from valid_call ctxt P\n  have call: \"\\<Gamma>\\<turnstile>call init p return' c\\<down> Normal s\"\n    by (rule cvalidt_termD)\n  show \"\\<Gamma>\\<turnstile>call init p return c \\<down> Normal s\"\n  proof (cases \"p \\<in> dom \\<Gamma>\")\n    case True\n    with call obtain bdy where \n      bdy: \"\\<Gamma> p = Some bdy\" and termi_bdy: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\" and \n      termi_c: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>c s t \\<down> Normal (return' s t)\"\n      by cases auto \n    {\n      fix t\n      assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n      hence \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n      proof -\n        from exec_bdy bdy\n        have \"\\<Gamma>\\<turnstile>\\<langle>(Call p ),Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n          by (auto simp add: intro: exec.intros)\n        from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P \n          res_modif\n        have \"return' s t = return s t\"\n          by auto\n        with termi_c exec_bdy show ?thesis by auto\n      qed\n    }\n    with bdy termi_bdy\n    show ?thesis\n      by (iprover intro: terminates_call)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates_callUndefined)\n  qed\nqed\n\nlemma ProcModifyReturn:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes res_modif:\n  \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes ret_modifAbr: \n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:    \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call p) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule hoaret_complete') \napply (rule ProcModifyReturn_sound [where Modif=Modif and ModifAbr=ModifAbr, \n        OF _ _ res_modif ret_modifAbr])\napply (rule hoaret_sound [OF spec])\nusing modifies_spec\napply (blast intro: hoare_sound)\ndone\n\nlemma ProcModifyReturnSameFaults_sound:\n  assumes valid_call: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P call init p return' c Q,A\"\n  assumes valid_modif: \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call p (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \n  assumes res_modif:\n  \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\n  assumes ret_modifAbr: \n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\n  shows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>call init p return c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from exec\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: exec_call_Normal_elim)\n    fix bdy t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\" \n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> \\<Rightarrow> t\" \n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>(Call p) ,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with res_modif have \"Normal (return' s t') = Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy \n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_call)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy t'\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\" \n    assume t: \"t = Abrupt (return s t')\"\n    also \n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call p ,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_callAbrupt)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy f\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Fault f\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callFault)\n    from cvalidt_postD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy\n    assume bdy: \"\\<Gamma> p = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Stuck\"  \n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callStuck)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    assume \"\\<Gamma> p = None\" \"t=Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init p return' c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callUndefined)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  assume P: \"s \\<in> P\"\n  from valid_call ctxt P\n  have call: \"\\<Gamma>\\<turnstile>call init p return' c\\<down> Normal s\"\n    by (rule cvalidt_termD)\n  show \"\\<Gamma>\\<turnstile>call init p return c \\<down> Normal s\"\n  proof (cases \"p \\<in> dom \\<Gamma>\")\n    case True\n    with call obtain bdy where \n      bdy: \"\\<Gamma> p = Some bdy\" and termi_bdy: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\" and \n      termi_c: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>c s t \\<down> Normal (return' s t)\"\n      by cases auto \n    {\n      fix t\n      assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n      hence \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n      proof -\n        from exec_bdy bdy\n        have \"\\<Gamma>\\<turnstile>\\<langle>(Call p ),Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n          by (auto simp add: intro: exec.intros)\n        from cvalidD [OF valid_modif [rule_format, of \"init s\"] ctxt' this] P \n          res_modif\n        have \"return' s t = return s t\"\n          by auto\n        with termi_c exec_bdy show ?thesis by auto\n      qed\n    }\n    with bdy termi_bdy\n    show ?thesis\n      by (iprover intro: terminates_call)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates_callUndefined)\n  qed\nqed\n\nlemma ProcModifyReturnSameFaults:\n  assumes spec: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return' c) Q,A\"\n  assumes res_modif:\n  \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes ret_modifAbr: \n  \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> (return' s t) = (return s t)\"\n  assumes modifies_spec:    \n  \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} (Call p) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (call init p return c) Q,A\"\napply (rule hoaret_complete') \napply (rule ProcModifyReturnSameFaults_sound [where Modif=Modif and ModifAbr=ModifAbr,\n          OF _ _ res_modif ret_modifAbr])\napply (rule hoaret_sound [OF spec])\nusing modifies_spec\napply (blast intro: hoare_sound)\ndone\n\n\nsubsubsection {* DynCall *}\n\n\nlemma dynProcModifyReturn_sound:\nassumes valid_call: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes valid_modif: \n    \"\\<forall>s\\<in>P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call (p s)) (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\nshows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  assume P: \"s \\<in> P\"\n  with valid_modif \n  have valid_modif': \n    \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} (Call (p s)) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n    by blast\n  from exec\n  have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return c,Normal s\\<rangle> \\<Rightarrow> t\"\n    by (cases rule: exec_dynCall_Normal_elim)\n  then show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: exec_call_Normal_elim)\n    fix bdy t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\" \n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> \\<Rightarrow> t\" \n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s),Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: exec.Call)\n    from cvalidD [OF valid_modif' [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with ret_modif have \"Normal (return' s t') = \n      Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_call)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\" \n    assume t: \"t = Abrupt (return s t')\"\n    also from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s) ,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif' [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_callAbrupt)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy f\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Fault f\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callFault)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by blast\n  next\n    fix bdy\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Stuck\"  \n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callStuck)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    fix bdy\n    assume \"\\<Gamma> (p s) = None\" \"t=Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callUndefined)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  then have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/UNIV\\<^esub> P (Call p) Q,A\"\n    by (auto intro: valid_augment_Faults)\n  assume P: \"s \\<in> P\"\n  from valid_call ctxt P\n  have \"\\<Gamma>\\<turnstile>dynCall init p return' c\\<down> Normal s\"\n    by (rule cvalidt_termD)\n  hence call: \"\\<Gamma>\\<turnstile>call init (p s) return' c\\<down> Normal s\"\n    by cases\n  have \"\\<Gamma>\\<turnstile>call init (p s) return c \\<down> Normal s\"\n  proof (cases \"p s \\<in> dom \\<Gamma>\")\n    case True\n    with call obtain bdy where \n      bdy: \"\\<Gamma> (p s) = Some bdy\" and termi_bdy: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\" and \n      termi_c: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>c s t \\<down> Normal (return' s t)\"\n      by cases auto \n    {\n      fix t\n      assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n      hence \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n      proof -\n        from exec_bdy bdy\n        have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s),Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n          by (auto simp add: intro: exec.intros)\n        from cvalidD [OF valid_modif [rule_format, of s \"init s\"] ctxt' this] P \n          ret_modif\n        have \"return' s t = return s t\"\n          by auto\n        with termi_c exec_bdy show ?thesis by auto\n      qed\n    }\n    with bdy termi_bdy\n    show ?thesis\n      by (iprover intro: terminates_call)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates_callUndefined)\n  qed\n  thus \"\\<Gamma>\\<turnstile>dynCall init p return c \\<down> Normal s\"\n    by (iprover intro: terminates_dynCall)\nqed\n\nlemma dynProcModifyReturn:\nassumes dyn_call: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s) \n           \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s) \n                             \\<longrightarrow> return' s t = return s t\"\nassumes modif: \n    \"\\<forall>s \\<in> P. \\<forall>\\<sigma>.  \n       \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/UNIV\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \nshows \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\napply (rule hoaret_complete')\napply (rule dynProcModifyReturn_sound \n        [where Modif=Modif and ModifAbr=ModifAbr,\n            OF hoaret_sound [OF dyn_call] _ ret_modif ret_modifAbr])\napply (intro ballI allI)\napply (rule hoare_sound [OF modif [rule_format]])\napply assumption\ndone\n\nlemma dynProcModifyReturnSameFaults_sound:\nassumes valid_call: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes valid_modif: \n    \"\\<forall>s\\<in>P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta> \\<Turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\nshows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return c,Normal s\\<rangle> \\<Rightarrow> t\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  assume P: \"s \\<in> P\"\n  with valid_modif \n  have valid_modif': \n    \"\\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} (Call (p s)) (Modif \\<sigma>),(ModifAbr \\<sigma>)\"\n    by blast\n  from exec\n  have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return c,Normal s\\<rangle> \\<Rightarrow> t\"\n    by (cases rule: exec_dynCall_Normal_elim)\n  then show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases rule: exec_call_Normal_elim)\n    fix bdy t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\" \n    assume exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c s t',Normal (return s t')\\<rangle> \\<Rightarrow> t\" \n    from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s),Normal (init s)\\<rangle> \\<Rightarrow> Normal t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif' [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> Modif (init s)\"\n      by auto\n    with ret_modif have \"Normal (return' s t') = \n      Normal (return s t')\"\n      by simp\n    with exec_body exec_c bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_call)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy t'\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume exec_body: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\" \n    assume t: \"t = Abrupt (return s t')\"\n    also from exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s)  ,Normal (init s)\\<rangle> \\<Rightarrow> Abrupt t'\"\n      by (auto simp add: intro: exec.intros)\n    from cvalidD [OF valid_modif' [rule_format, of \"init s\"] ctxt' this] P\n    have \"t' \\<in> ModifAbr (init s)\"\n      by auto\n    with ret_modifAbr have \"Abrupt (return s t') = Abrupt (return' s t')\"\n      by simp\n    finally have \"t = Abrupt (return' s t')\" .\n    with exec_body bdy\n    have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (auto intro: exec_callAbrupt)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this] P t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy f\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Fault f\"  and\n      t: \"t = Fault f\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callFault)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from cvalidt_postD [OF valid_call ctxt this P] t t_notin_F\n    show ?thesis\n      by simp\n  next\n    fix bdy\n    assume bdy: \"\\<Gamma> (p s) = Some bdy\"\n    assume \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Stuck\"  \n      \"t = Stuck\"\n    with bdy have \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callStuck)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    fix bdy\n    assume \"\\<Gamma> (p s) = None\" \"t=Stuck\"\n    hence \"\\<Gamma>\\<turnstile>\\<langle>call init (p s) return' c ,Normal s\\<rangle> \\<Rightarrow> t\"\n      by (auto intro: exec_callUndefined)\n    hence \"\\<Gamma>\\<turnstile>\\<langle>dynCall init p return' c,Normal s\\<rangle> \\<Rightarrow> t\" \n      by (rule exec_dynCall)\n    from valid_call ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def)\n  assume P: \"s \\<in> P\"\n  from valid_call ctxt P\n  have \"\\<Gamma>\\<turnstile>dynCall init p return' c\\<down> Normal s\"\n    by (rule cvalidt_termD)\n  hence call: \"\\<Gamma>\\<turnstile>call init (p s) return' c\\<down> Normal s\"\n    by cases\n  have \"\\<Gamma>\\<turnstile>call init (p s) return c \\<down> Normal s\"\n  proof (cases \"p s \\<in> dom \\<Gamma>\")\n    case True\n    with call obtain bdy where \n      bdy: \"\\<Gamma> (p s) = Some bdy\" and termi_bdy: \"\\<Gamma>\\<turnstile>bdy \\<down> Normal (init s)\" and \n      termi_c: \"\\<forall>t. \\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t \\<longrightarrow> \n                    \\<Gamma>\\<turnstile>c s t \\<down> Normal (return' s t)\"\n      by cases auto \n    {\n      fix t\n      assume exec_bdy: \"\\<Gamma>\\<turnstile>\\<langle>bdy,Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n      hence \"\\<Gamma>\\<turnstile>c s t \\<down> Normal (return s t)\"\n      proof -\n        from exec_bdy bdy\n        have \"\\<Gamma>\\<turnstile>\\<langle>Call (p s),Normal (init s)\\<rangle> \\<Rightarrow> Normal t\"\n          by (auto simp add: intro: exec.intros)\n        from cvalidD [OF valid_modif [rule_format, of s \"init s\"] ctxt' this] P \n          ret_modif\n        have \"return' s t = return s t\"\n          by auto\n        with termi_c exec_bdy show ?thesis by auto\n      qed\n    }\n    with bdy termi_bdy\n    show ?thesis\n      by (iprover intro: terminates_call)\n  next\n    case False\n    thus ?thesis\n      by (auto intro: terminates_callUndefined)\n  qed\n  thus \"\\<Gamma>\\<turnstile>dynCall init p return c \\<down> Normal s\"\n    by (iprover intro: terminates_dynCall)\nqed\n\nlemma dynProcModifyReturnSameFaults:\nassumes dyn_call: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P dynCall init p return' c Q,A\"\nassumes ret_modif:\n    \"\\<forall>s t. t \\<in> Modif (init s) \\<longrightarrow> return' s t = return s t\"\nassumes ret_modifAbr: \"\\<forall>s t. t \\<in> ModifAbr (init s) \\<longrightarrow> return' s t = return s t\"\nassumes modif: \n    \"\\<forall>s \\<in> P. \\<forall>\\<sigma>. \\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> {\\<sigma>} Call (p s) (Modif \\<sigma>),(ModifAbr \\<sigma>)\" \nshows \"\\<Gamma>,\\<Theta> \\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (dynCall init p return c) Q,A\"\napply (rule hoaret_complete')\napply (rule dynProcModifyReturnSameFaults_sound \n        [where Modif=Modif and ModifAbr=ModifAbr,\n          OF hoaret_sound [OF dyn_call] _ ret_modif ret_modifAbr])\napply (intro ballI allI)\napply (rule hoare_sound [OF modif [rule_format]])\napply assumption\ndone\n\nsubsubsection {* Conjunction of Postcondition *}\n\nlemma PostConjI_sound:\n  assumes valid_Q: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes valid_R: \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c R,B\"\n  shows \"\\<Gamma>,\\<Theta> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from valid_Q ctxt exec P t_notin_F have \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    by (rule cvalidt_postD)\n  moreover\n  from valid_R ctxt exec P t_notin_F have \"t \\<in> Normal ` R \\<union> Abrupt ` B\"\n    by (rule cvalidt_postD)\n  ultimately show \"t \\<in> Normal ` (Q \\<inter> R) \\<union> Abrupt ` (A \\<inter> B)\"\n    by blast\nnext \n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  from valid_Q ctxt P\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule cvalidt_termD)\nqed\n\nlemma PostConjI:\n  assumes deriv_Q: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\" \n  assumes deriv_R: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c R,B\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> B)\"\napply (rule hoaret_complete')\napply (rule PostConjI_sound)\napply (rule hoaret_sound [OF deriv_Q])\napply (rule hoaret_sound [OF deriv_R])\ndone\n\n\nlemma Merge_PostConj_sound: \n  assumes validF: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes validG: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/G\\<^esub> P' c R,X\"\n  assumes F_G: \"F \\<subseteq> G\"\n  assumes P_P': \"P \\<subseteq> P'\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> X)\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  with F_G have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/G\\<^esub> P (Call p) Q,A\" \n    by (auto intro: validt_augment_Faults)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\" \n  with P_P' have P': \"s \\<in> P'\"\n    by auto\n  assume t_noFault: \"t \\<notin> Fault ` F\"\n  show \"t \\<in> Normal ` (Q \\<inter> R) \\<union> Abrupt ` (A \\<inter> X)\"\n  proof -\n    from cvalidt_postD [OF validF [rule_format] ctxt exec P t_noFault]\n    have \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\n    moreover from this have \"t \\<notin> Fault ` G\"\n      by auto\n    from cvalidt_postD [OF validG [rule_format] ctxt' exec P' this]\n    have \"t \\<in> Normal ` R \\<union> Abrupt ` X\" .\n    ultimately show ?thesis by auto\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  from validF ctxt P\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule cvalidt_termD)\nqed\n\n\n\nlemma Merge_PostConj: \n  assumes validF: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes validG: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/G\\<^esub> P' c R,X\"\n  assumes F_G: \"F \\<subseteq> G\"\n  assumes P_P': \"P \\<subseteq> P'\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c (Q \\<inter> R),(A \\<inter> X)\"\napply (rule hoaret_complete')\napply (rule Merge_PostConj_sound [OF _ _ F_G P_P'])\nusing validF apply (blast intro:hoaret_sound)\nusing validG apply (blast intro:hoaret_sound)\ndone\n\n\nsubsubsection {* Guards and Guarantees *}\n\nlemma SplitGuards_sound:\n  assumes valid_c1: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,A\"\n  assumes valid_c2: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>2 UNIV,UNIV\"\n  assumes c: \"(c\\<^sub>1 \\<inter>\\<^sub>g c\\<^sub>2) = Some c\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto simp add: validt_def) \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\"\n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases t)\n    case Normal\n    with inter_guards_exec_noFault [OF c exec]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t\" by simp\n    from valid_c1 ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    case Abrupt\n    with inter_guards_exec_noFault [OF c exec]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t\" by simp\n    from valid_c1 ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  next\n    case (Fault f)\n    assume t: \"t=Fault f\"\n    with exec inter_guards_exec_Fault [OF c]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Fault f \\<or> \\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow> Fault f\"\n      by auto\n    then show ?thesis\n    proof (cases rule: disjE [consumes 1])\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> Fault f\"\n      from cvalidt_postD [OF valid_c1 ctxt this P] t t_notin_F\n      show ?thesis\n        by blast\n    next\n      assume \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>2,Normal s\\<rangle> \\<Rightarrow> Fault f\"\n      from cvalidD [OF valid_c2 ctxt' this P] t t_notin_F\n      show ?thesis\n        by blast\n    qed\n  next\n    case Stuck\n    with inter_guards_exec_noFault [OF c exec]\n    have \"\\<Gamma>\\<turnstile>\\<langle>c\\<^sub>1,Normal s\\<rangle> \\<Rightarrow> t\" by simp\n    from valid_c1 ctxt this P t_notin_F\n    show ?thesis\n      by (rule cvalidt_postD)\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\"\n  assume P: \"s \\<in> P\"\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n  proof -\n    from valid_c1 ctxt P\n    have \"\\<Gamma>\\<turnstile>c\\<^sub>1 \\<down> Normal s\"\n      by (rule cvalidt_termD)\n    with c show ?thesis\n      by (rule inter_guards_terminates)\n  qed\nqed\n\nlemma SplitGuards: \n  assumes c: \"(c\\<^sub>1 \\<inter>\\<^sub>g c\\<^sub>2) = Some c\" \n  assumes deriv_c1: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c\\<^sub>1 Q,A\" \n  assumes deriv_c2: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c\\<^sub>2 UNIV,UNIV\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule SplitGuards_sound [OF _ _ c])\napply (rule hoaret_sound [OF deriv_c1])\napply (rule hoare_sound [OF deriv_c2])\ndone\n\nlemma CombineStrip_sound:\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes valid_strip: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/{}\\<^esub> P (strip_guards (-F) c) UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n    by (auto simp add: validt_def)\n  from ctxt have ctxt'': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\" \n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases t)\n    case (Normal t')\n    from cvalidt_postD [OF valid ctxt'' exec P] Normal \n    show ?thesis\n      by auto\n  next\n    case (Abrupt t')\n    from cvalidt_postD [OF valid ctxt'' exec P] Abrupt \n    show ?thesis\n      by auto\n  next\n    case (Fault f)\n    show ?thesis\n    proof (cases \"f \\<in> F\")\n      case True\n      hence \"f \\<notin> -F\" by simp\n      with exec Fault\n      have \"\\<Gamma>\\<turnstile>\\<langle>strip_guards (-F) c,Normal s\\<rangle> \\<Rightarrow> Fault f\" \n        by (auto intro: exec_to_exec_strip_guards_Fault)\n      from cvalidD [OF valid_strip ctxt' this P] Fault\n      have False\n        by auto\n      thus ?thesis ..\n    next\n      case False\n      with cvalidt_postD [OF valid ctxt'' exec P] Fault\n      show ?thesis\n        by auto\n    qed\n  next\n    case Stuck\n    from cvalidt_postD [OF valid ctxt'' exec P] Stuck\n    show ?thesis\n      by auto\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  assume P: \"s \\<in> P\"\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n  proof -\n    from valid ctxt' P\n    show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n      by (rule cvalidt_termD)\n  qed\nqed\n\nlemma CombineStrip:\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes deriv_strip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/{}\\<^esub> P (strip_guards (-F) c) UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule CombineStrip_sound)\napply  (iprover intro: hoaret_sound [OF deriv])\napply (iprover intro: hoare_sound [OF deriv_strip])\ndone\n\nlemma GuardsFlip_sound:\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes validFlip: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/-F\\<^esub> P c UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  from ctxt have ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  from ctxt have ctxtFlip: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^bsub>/-F\\<^esub> P (Call p) Q,A\" \n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\" \n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases t)\n    case (Normal t')\n    from cvalidt_postD [OF valid ctxt' exec P] Normal \n    show ?thesis\n      by auto\n  next\n    case (Abrupt t')\n    from cvalidt_postD [OF valid ctxt' exec P] Abrupt \n    show ?thesis\n      by auto\n  next\n    case (Fault f)\n    show ?thesis\n    proof (cases \"f \\<in> F\")\n      case True\n      hence \"f \\<notin> -F\" by simp\n      with cvalidD [OF validFlip ctxtFlip exec P] Fault\n      have False\n        by auto\n      thus ?thesis ..\n    next\n      case False\n      with cvalidt_postD [OF valid ctxt' exec P] Fault\n      show ?thesis\n        by auto\n    qed\n  next\n    case Stuck\n    from cvalidt_postD [OF valid ctxt' exec P] Stuck\n    show ?thesis\n      by auto\n  qed\nnext\n  fix s\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma> \\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\"\n  hence ctxt': \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n    by (auto intro: valid_augment_Faults simp add: validt_def)\n  assume P: \"s \\<in> P\"\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n  proof -\n    from valid ctxt' P\n    show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n      by (rule cvalidt_termD)\n  qed\nqed\n\n\nlemma GuardsFlip: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes derivFlip: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/-F\\<^esub> P c UNIV,UNIV\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule GuardsFlip_sound)\napply  (iprover intro: hoaret_sound [OF deriv])\napply (iprover intro: hoare_sound [OF derivFlip])\ndone\n\nlemma MarkGuardsI_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c,Normal s\\<rangle> \\<Rightarrow> t\" \n  from exec_mark_guards_to_exec [OF exec] obtain t' where\n    exec_c: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t'\" and\n    t'_noFault: \"\\<not> isFault t' \\<longrightarrow> t' = t\"\n    by blast\n  assume P: \"s \\<in> P\" \n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof -\n    from cvalidt_postD [OF valid [rule_format] ctxt exec_c P]\n    have \"t' \\<in> Normal ` Q \\<union> Abrupt ` A\"\n      by blast\n    with t'_noFault\n    show ?thesis\n      by auto\n  qed\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>mark_guards f c \\<down> Normal s\"\n    by (rule terminates_to_terminates_mark_guards)\nqed\n\nlemma MarkGuardsI: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\"\napply (rule hoaret_complete')\napply (rule MarkGuardsI_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\n\nlemma MarkGuardsD_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\" \n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  assume P: \"s \\<in> P\" \n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n  proof (cases \"isFault t\")\n    case True\n    with exec_to_exec_mark_guards_Fault exec\n    obtain f' where \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c,Normal s\\<rangle> \\<Rightarrow> Fault f'\"\n      by (fastforce elim: isFaultE)\n    from cvalidt_postD [OF valid [rule_format] ctxt this P]\n    have False\n      by auto\n    thus ?thesis ..\n  next\n    case False\n    from exec_to_exec_mark_guards [OF exec False]\n    obtain f' where \"\\<Gamma>\\<turnstile>\\<langle>mark_guards f c,Normal s\\<rangle> \\<Rightarrow> t\"\n      by auto\n    from cvalidt_postD [OF valid [rule_format] ctxt this P]\n    show ?thesis\n      by auto\n  qed\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>mark_guards f c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule terminates_mark_guards_to_terminates)\nqed\n\nlemma MarkGuardsD: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P mark_guards f c Q,A\" \n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule MarkGuardsD_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nlemma MergeGuardsI_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P merge_guards c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume exec_merge: \"\\<Gamma>\\<turnstile>\\<langle>merge_guards c,Normal s\\<rangle> \\<Rightarrow> t\"\n  from exec_merge_guards_to_exec [OF exec_merge] \n  have exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" .\n  assume P: \"s \\<in> P\" \n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec P t_notin_F]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>merge_guards c \\<down> Normal s\"\n    by (rule terminates_to_terminates_merge_guards)\nqed\n\nlemma MergeGuardsI: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P merge_guards c Q,A\"\napply (rule hoaret_complete')\napply (rule MergeGuardsI_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nlemma MergeGuardsD_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P merge_guards c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  from exec_to_exec_merge_guards [OF exec] \n  have exec_merge: \"\\<Gamma>\\<turnstile>\\<langle>merge_guards c,Normal s\\<rangle> \\<Rightarrow> t\".\n  assume P: \"s \\<in> P\" \n  assume t_notin_F: \"t \\<notin> Fault ` F\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec_merge P t_notin_F]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>merge_guards c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule terminates_merge_guards_to_terminates)\nqed\n\n\n\n\nlemma SubsetGuards_sound: \n  assumes c_c': \"c \\<subseteq>\\<^sub>g c'\"\n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c' Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  from exec_to_exec_subseteq_guards [OF c_c' exec] obtain t' where\n    exec_c': \"\\<Gamma>\\<turnstile>\\<langle>c',Normal s\\<rangle> \\<Rightarrow> t'\" and\n    t'_noFault: \"\\<not> isFault t' \\<longrightarrow> t' = t\"\n    by blast\n  assume P: \"s \\<in> P\" \n  assume t_noFault: \"t \\<notin> Fault ` {}\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec_c' P] t'_noFault t_noFault\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\"\n    by auto\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have termi_c': \"\\<Gamma>\\<turnstile>c' \\<down> Normal s\".\n  from cvalidt_postD [OF valid ctxt _ P]\n  have noFault_c': \"\\<Gamma>\\<turnstile>\\<langle>c',Normal s\\<rangle> \\<Rightarrow>\\<notin>Fault ` UNIV\"\n    by (auto simp add: final_notin_def)\n  from termi_c' c_c' noFault_c'\n  show \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule terminates_fewer_guards)\nqed\n\nlemma SubsetGuards: \n  assumes c_c': \"c \\<subseteq>\\<^sub>g c'\"\n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c' Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/{}\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule SubsetGuards_sound [OF c_c'])\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nlemma NormalizeD_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n  hence exec_norm: \"\\<Gamma>\\<turnstile>\\<langle>normalize c,Normal s\\<rangle> \\<Rightarrow> t\" \n    by (rule exec_to_exec_normalize)\n  assume P: \"s \\<in> P\" \n  assume noFault: \"t \\<notin> Fault ` F\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec_norm P noFault]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile>normalize c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>c \\<down> Normal s\"\n    by (rule terminates_normalize_to_terminates)\nqed\n\nlemma NormalizeD: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\napply (rule hoaret_complete')\napply (rule NormalizeD_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nlemma NormalizeI_sound: \n  assumes valid: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\nproof (rule cvalidtI)\n  fix s t\n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume \"\\<Gamma>\\<turnstile>\\<langle>normalize c,Normal s\\<rangle> \\<Rightarrow> t\" \n  hence exec: \"\\<Gamma>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow> t\" \n    by (rule exec_normalize_to_exec)\n  assume P: \"s \\<in> P\" \n  assume noFault: \"t \\<notin> Fault ` F\"\n  from cvalidt_postD [OF valid [rule_format] ctxt exec P noFault]\n  show \"t \\<in> Normal ` Q \\<union> Abrupt ` A\".\nnext\n  fix s \n  assume ctxt: \"\\<forall>(P, p, Q, A)\\<in>\\<Theta>. \\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (Call p) Q,A\" \n  assume P: \"s \\<in> P\" \n  from cvalidt_termD [OF valid ctxt P]\n  have \"\\<Gamma>\\<turnstile> c \\<down> Normal s\".\n  thus \"\\<Gamma>\\<turnstile>normalize c \\<down> Normal s\"\n    by (rule terminates_to_terminates_normalize)\nqed\n\nlemma NormalizeI: \n  assumes deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P (normalize c) Q,A\"\napply (rule hoaret_complete')\napply (rule NormalizeI_sound)\napply (iprover intro: hoaret_sound [OF deriv])\ndone\n\nsubsubsection {* Restricting the Procedure Environment *}\n\nlemma validt_restrict_to_validt:\nassumes validt_c: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nshows \"\\<Gamma>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from validt_c\n  have valid_c: \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\" by (simp add: validt_def)\n  hence \"\\<Gamma>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\" by (rule valid_restrict_to_valid)\n  moreover\n  {\n    fix s\n    assume P: \"s \\<in> P\"\n    have \"\\<Gamma>\\<turnstile>c\\<down>Normal s\"\n    proof -\n      from P validt_c have \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>c\\<down>Normal s\"\n        by (auto simp add: validt_def)\n      moreover\n      from P valid_c\n      have \"\\<Gamma>|\\<^bsub>M\\<^esub>\\<turnstile>\\<langle>c,Normal s\\<rangle> \\<Rightarrow>\\<notin>{Stuck}\"\n        by (auto simp add: valid_def  final_notin_def)\n      ultimately show ?thesis\n        by (rule terminates_restrict_to_terminates)\n    qed\n   }\n   ultimately show ?thesis\n     by (auto simp add: validt_def)\nqed\n\n\nlemma augment_procs:\nassumes deriv_c: \"\\<Gamma>|\\<^bsub>M\\<^esub>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nshows \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule hoaret_complete)\n  apply (rule validt_restrict_to_validt)\n  apply (insert hoaret_sound [OF deriv_c])\n  by (simp add: cvalidt_def)\n\nsubsubsection {* Miscellaneous *}\n\nlemma augment_Faults:\nassumes deriv_c: \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nassumes F: \"F \\<subseteq> F'\"\nshows \"\\<Gamma>,{}\\<turnstile>\\<^sub>t\\<^bsub>/F'\\<^esub> P c Q,A\"\n  apply (rule hoaret_complete)\n  apply (rule validt_augment_Faults [OF _ F])\n  apply (insert hoaret_sound [OF deriv_c])\n  by (simp add: cvalidt_def)\n\nlemma TerminationPartial_sound:\n  assumes \"termination\": \"\\<forall>s \\<in> P. \\<Gamma>\\<turnstile>c\\<down>Normal s\"\n  assumes partial_corr: \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nusing \"termination\" partial_corr \nby (auto simp add: cvalidt_def validt_def cvalid_def)\n\nlemma TerminationPartial:\n  assumes partial_deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes \"termination\": \"\\<forall>s \\<in> P. \\<Gamma>\\<turnstile>c\\<down>Normal s\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n  apply (rule hoaret_complete')\n  apply (rule TerminationPartial_sound [OF \"termination\"])\n  apply (rule hoare_sound [OF partial_deriv])\n  done\n\nlemma TerminationPartialStrip:\n  assumes partial_deriv: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  assumes \"termination\": \"\\<forall>s \\<in> P. strip F' \\<Gamma>\\<turnstile>strip_guards F' c\\<down>Normal s\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from \"termination\" have \"\\<forall>s \\<in> P. \\<Gamma>\\<turnstile>c\\<down>Normal s\"\n    by (auto intro: terminates_strip_guards_to_terminates \n      terminates_strip_to_terminates)\n  with partial_deriv\n  show ?thesis\n    by (rule TerminationPartial)\nqed\n\nlemma SplitTotalPartial:\n  assumes termi: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q',A'\"\n  assumes part: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from hoaret_sound [OF termi] hoare_sound [OF part]\n  have \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (fastforce simp add: cvalidt_def validt_def cvalid_def valid_def)\n  thus ?thesis\n    by (rule hoaret_complete')\nqed\n   \nlemma SplitTotalPartial':\n  assumes termi: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/UNIV\\<^esub> P c Q',A'\"\n  assumes part: \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^bsub>/F\\<^esub> P c Q,A\"\n  shows \"\\<Gamma>,\\<Theta>\\<turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\nproof -\n  from hoaret_sound [OF termi] hoare_sound [OF part]\n  have \"\\<Gamma>,\\<Theta>\\<Turnstile>\\<^sub>t\\<^bsub>/F\\<^esub> P c Q,A\"\n    by (fastforce simp add: cvalidt_def validt_def cvalid_def valid_def)\n  thus ?thesis\n    by (rule hoaret_complete')\nqed\n \nend\n", "meta": {"author": "CompSoftVer", "repo": "CSim2", "sha": "b09a4d77ea089168b1805db5204ac151df2b9eff", "save_path": "github-repos/isabelle/CompSoftVer-CSim2", "path": "github-repos/isabelle/CompSoftVer-CSim2/CSim2-b09a4d77ea089168b1805db5204ac151df2b9eff/ConCSimpl/HoareTotalProps.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5234203489363239, "lm_q2_score": 0.48047867804790706, "lm_q1q2_score": 0.25149231732029914}}
{"text": "theory SC11\nimports Main\nbegin\n\n(*\nTODO: need to modify the definition to include RC11 model and RA11 model.\n\nRC11: a. make the SC fence stronger having a total order on all writes.\n      b. WW-merge mistake, too week a sc read/write instead of the acq write.\n         our timed-relaxed memory model will make it stronger to prevent SB and WW-merge\n      c. the way to prevent out-of-thin-air reads is problematic.\n         the requirement for sb \\<union> rf to be acyclic is too strong.\n\nRA11: RA11 is just adding modification order on each location on top of\n      the current acquire/release atomics.\n\n*)\n\ntype_synonym action_id = nat\ntype_synonym thread_id = nat\ntype_synonym location = nat\ntype_synonym avalue = nat\ntype_synonym program = nat\n\n(* 1 - Relational definitions *)\n\ndefinition irrefl where\n\"irrefl S ord = (\\<forall> x \\<in> S . \\<not> ((x,x) \\<in> ord))\"\n\ndefinition trans where\n\"trans S ord = (\\<forall> x \\<in> S . (\\<forall> y \\<in> S . (\\<forall> z \\<in> S. (x,y) \\<in> ord \\<and> (y,z) \\<in> ord \\<longrightarrow> (x,z) \\<in> ord)))\"\n\ndefinition cross where\n\"cross S T = {(s,t) . s \\<in> S \\<and> t \\<in> T}\"\n\ninductive tc' where\na: \"r (x,y) \\<Longrightarrow> tc' r (x,y)\"\n| b: \"\\<lbrakk> tc' r (x,z); tc' r (z,y)\\<rbrakk> \\<Longrightarrow> tc' r (x,y)\"\n\ndefinition tc where\n\"tc r = {(x,y) . (x,y) \\<in> r \\<and> tc' (\\<lambda> (x,y) . (x,y) \\<in> r) (x,y) }\"\n\ndefinition restrict_relation_set where\n\"restrict_relation_set rel s = rel \\<inter> (cross s s)\"\n\ndefinition strict_preorder where\n\"strict_preorder s ord =(irrefl s (ord) \\<and> trans s (ord))\"\n\ndefinition relation_over where\n\"relation_over s rel = (\\<forall> (a,b) \\<in> rel . a \\<in> s \\<and> b \\<in> s)\"\n\ndefinition inj_on where\n\"inj_on f A = (\\<forall> x \\<in> A . (\\<forall> y \\<in> A . f x = f y \\<longrightarrow> x = y))\"\n\ndefinition total_order_over where\n\"total_order_over s ord = (relation_over s ord \\<and> (\\<forall> x \\<in> s . (\\<forall> y \\<in> s . (x,y) \\<in> ord \\<or> (y,x) \\<in> ord \\<or> x = y)))\"\n\ndefinition strict_total_order_over where\n\"strict_total_order_over s ord = (strict_preorder s ord \\<and> total_order_over s ord)\"\n\ndefinition adjacent_less_than where\n\"adjacent_less_than ord s x y = ((x,y) \\<in> ord \\<and> \\<not> (\\<exists> z \\<in> s . (x,z) \\<in> ord \\<and> (z,y) \\<in> ord))\"\n\ndefinition adjacent_less_than_such_that where\n\"adjacent_less_than_such_that pred ord s x y =\n     (pred x \\<and> (x,y) \\<in> ord \\<and> \\<not> (\\<exists> z \\<in> s . pred z \\<and> (x,z) \\<in> ord \\<and> (z,y) \\<in> ord))\"\n\n(* 2 - Action and location types *)\n\ndatatype memory_order =\n    Mo_seq_cst\n  | Mo_relaxed\n  | Mo_release\n  | Mo_acquire\n  | Mo_consume\n  | Mo_acq_rel\n\ndatatype lock_outcome =\n    Success\n  | Blocked\n\ndatatype action =\n    Lock action_id  thread_id  location  lock_outcome\n  | Unlock action_id  thread_id  location\n  | Atomic_load  action_id thread_id memory_order location avalue\n  | Atomic_store action_id thread_id memory_order location avalue\n  | Atomic_rmw action_id thread_id memory_order location avalue avalue\n  | Load action_id thread_id location avalue\n  | Store action_id thread_id location avalue\n  | Fence action_id thread_id memory_order\n  | Blocked_rmw action_id thread_id location\n\nprimrec action_id_of where\n\"action_id_of (Lock aid x y z) = aid\"\n| \"action_id_of (Unlock aid x y) = aid\"\n| \"action_id_of (Atomic_load aid x y u v) = aid\"\n| \"action_id_of (Atomic_store aid x y u v) = aid\"\n| \"action_id_of (Atomic_rmw aid x y z u v) = aid\"\n| \"action_id_of (Load aid x y z) = aid\"\n| \"action_id_of (Store aid x y z) = aid\"\n| \"action_id_of (Fence aid x y) = aid\"\n| \"action_id_of (Blocked_rmw aid x y) = aid\"\n\nprimrec thread_id_of where\n\"thread_id_of (Lock x tid y z) = tid\"\n| \"thread_id_of (Unlock x tid y) = tid\"\n| \"thread_id_of (Atomic_load x tid y u v) = tid\"\n| \"thread_id_of (Atomic_store x tid y u v) = tid\"\n| \"thread_id_of (Atomic_rmw x tid y z u v) = tid\"\n| \"thread_id_of (Load x tid y z) = tid\"\n| \"thread_id_of (Store x tid y z) = tid\"\n| \"thread_id_of (Fence x tid y) = tid\"\n| \"thread_id_of (Blocked_rmw x tid y) = tid\"\n\nfun memory_order_of where\n\"memory_order_of (Atomic_load x y ord u v) = Some ord\"\n| \"memory_order_of (Atomic_store x y ord u v) = Some ord\"\n| \"memory_order_of (Atomic_rmw x y ord z u v) = Some ord\"\n| \"memory_order_of (Fence x y ord) = Some ord\"\n| \"memory_order_of x = None\"\n\nprimrec location_of where\n\"location_of (Lock x tid l z) = Some l\"\n| \"location_of (Unlock x tid l) = Some l\"\n| \"location_of (Atomic_load x tid y l v) = Some l\"\n| \"location_of (Atomic_store x tid y l v) = Some l\"\n| \"location_of (Atomic_rmw x tid y l u v) = Some l\"\n| \"location_of (Load x tid l z) = Some l\"\n| \"location_of (Store x tid l z) = Some l\"\n| \"location_of (Fence x tid y) = None\"\n| \"location_of (Blocked_rmw x tid l) = Some l\"\n\nfun value_read_by where\n\"value_read_by (Atomic_load x tid y l v) = Some v\"\n| \"value_read_by (Atomic_rmw x tid y l u v) = Some v\"\n| \"value_read_by (Load x tid l v) = Some v\"\n| \"value_read_by x = None\"\n\nfun value_written_by where\n \"value_written_by (Atomic_store x tid y l v) = Some v\"\n| \"value_written_by (Atomic_rmw x tid y l u v) = Some v\"\n| \"value_written_by (Store x tid l v) = Some v\"\n| \"value_written_by x = None\"\n\nfun is_lock where\n \"is_lock (Lock x tid l z) = True\"\n| \"is_lock a = False\"\n\nfun is_successful_lock where\n \"is_successful_lock (Lock x tid l Success) = True\"\n| \"is_successful_lock a = False\"\n\nfun is_blocked_lock where\n \"is_blocked_lock (Lock x tid l Blocked) = True\"\n| \"is_blocked_lock a = False\"\n\nfun is_unlock where\n \"is_unlock (Unlock x tid l) = True\"\n| \"is_unlock a = False\"\n\nfun is_atomic_load where\n \"is_atomic_load (Atomic_load x tid y l v) = True\"\n| \"is_atomic_load a = False\"\n\nfun is_atomic_store where\n \"is_atomic_store (Atomic_store x tid y l v) = True\"\n| \"is_atomic_store a = False\"\n\nfun is_atomic_rmw where\n \"is_atomic_rmw (Atomic_rmw x tid y l v u) = True\"\n| \"is_atomic_rmw a = False\"\n\nfun is_blocked_rmw where\n \"is_blocked_rmw (Blocked_rmw x tid y) = True\"\n| \"is_blocked_rmw a = False\"\n\nfun is_load where\n \"is_load (Load x tid y z) = True\"\n| \"is_load a = False\"\n\nfun is_store where\n \"is_store (Store x tid y z) = True\"\n| \"is_store a = False\"\n\nfun is_fence where\n \"is_fence (Fence x y z) = True\"\n| \"is_fence a = False\"\n\nfun is_atomic_action where\n \"is_atomic_action a = (is_atomic_load a \\<or> is_atomic_store a \\<or> is_atomic_rmw a)\"\n\nfun is_read where\n \"is_read a = (is_load a \\<or> is_atomic_load a \\<or> is_atomic_rmw a)\"\n\nfun is_write where\n \"is_write a = (is_store a \\<or> is_atomic_store a \\<or> is_atomic_rmw a)\"\n\n(* It is important to note that seq_cst atomics are both acquires and releases *)\n\nfun is_acquire where\n\"is_acquire a = (case memory_order_of a of \n        Some Mo_acquire \\<Rightarrow> is_read a \\<or> is_fence a\n        | Some Mo_acq_rel \\<Rightarrow> is_read a \\<or> is_fence a\n        | Some Mo_seq_cst \\<Rightarrow> is_read a \\<or> is_fence a\n        | Some Mo_consume \\<Rightarrow> is_fence a\n        | None \\<Rightarrow> is_lock a\n        | _ \\<Rightarrow> False)\"\n\nfun is_consume where\n\"is_consume a = (is_read a \\<and> (memory_order_of a = Some Mo_consume))\"\n\nfun is_release where\n\"is_release a = (case memory_order_of a of \n        Some Mo_acquire \\<Rightarrow> is_write a \\<or> is_fence a\n        | Some Mo_acq_rel \\<Rightarrow> is_write a \\<or> is_fence a\n        | Some Mo_seq_cst \\<Rightarrow> is_write a \\<or> is_fence a\n        | None \\<Rightarrow> is_unlock a\n        | _ \\<Rightarrow> False)\"\n\nfun is_seq_cst where\n\"is_seq_cst a = (memory_order_of a = Some Mo_seq_cst)\"\n\n\n(*   - 2.2 - Location kinds *)\n\ndatatype location_kind =\n    Mutex\n  | Non_atomic\n  | Atomic\n\ndefinition actions_respect_location_kinds where\n\"actions_respect_location_kinds S lk = \n   (\\<forall> a \\<in> S . case location_of a of Some l \\<Rightarrow> \n                  (case lk l of \n                     Mutex \\<Rightarrow> is_lock a \\<or> is_unlock a\n                   | Non_atomic \\<Rightarrow> is_load a \\<or> is_store a\n                   | Atomic \\<Rightarrow> is_store a \\<or> is_atomic_action a \\<or>  is_blocked_rmw a)\n            | None \\<Rightarrow> True)\"\n\nfun is_at_location_kind where\n\"is_at_location_kind lk a lk0 = \n   (case location_of a of Some l \\<Rightarrow> (lk l = lk0)\n             | None \\<Rightarrow> False)\"\n\nfun is_at_mutex_location where\n\"is_at_mutex_location lk a = is_at_location_kind lk a Mutex\"\n\nfun is_at_non_atomic_location where\n\"is_at_non_atomic_location lk a = is_at_location_kind lk a Non_atomic\"\n\nfun is_at_atomic_location where\n\"is_at_atomic_location lk a = is_at_location_kind lk a Atomic\"\n\n(* 3 - The preferred model *)\nrecord opsem_execution_part =\n  actions :: \"action set\"\n  threads :: \"thread_id set\"\n  lk      :: \"location \\<Rightarrow> location_kind\"\n  sb      :: \"(action * action) set\"\n  asw     :: \"(action * action) set\"\n  dd      :: \"(action * action) set\"\n  cd      :: \"(action * action) set\"\n\nrecord witness_execution_part =\n  rf     :: \"(action * action) set\"\n  mo     :: \"(action * action) set\"\n  sc     :: \"(action * action) set\"\n\n(*   - 3.2 - Well formed action *)\n\nfun same_thread where\n\"same_thread a b = (thread_id_of a = thread_id_of b)\"\n\nfun threadwise_relation_over where\n\"threadwise_relation_over s rel = relation_over s rel\"\n\nfun same_location where \n\"same_location a b = (location_of a = location_of b)\"\n\nfun locations_of where\n\"locations_of as = {l . (\\<exists> a . Some l = location_of a \\<and> a \\<in> as)}\"\n\nfun well_formed_action where\n\"well_formed_action a = \n   (case a of Atomic_load x y mem_ord u v \\<Rightarrow>\n       mem_ord = Mo_relaxed \\<or> mem_ord = Mo_acquire \\<or> mem_ord = Mo_seq_cst \\<or> mem_ord = Mo_consume\n      | Atomic_store x y mem_ord u v \\<Rightarrow> mem_ord = Mo_relaxed \\<or> mem_ord = Mo_release \\<or> mem_ord = Mo_seq_cst \n      | Atomic_rmw x y mem_ord z u v \\<Rightarrow> mem_ord = Mo_relaxed \\<or> mem_ord = Mo_release \\<or> mem_ord = Mo_acquire\n                                \\<or> mem_ord = Mo_acq_rel \\<or> mem_ord = Mo_seq_cst \\<or> mem_ord = Mo_consume\n      | _ \\<Rightarrow> True)\"\n\n(*  - 3.3 - Well formed threads *)\nfun well_formed_threads where\n\"well_formed_threads as threads' lk' sb' asw' dd' cd' = \n   (inj_on action_id_of as \\<and>\n      (\\<forall> a \\<in> as . well_formed_action a) \\<and>\n    threadwise_relation_over as sb' \\<and>\n    threadwise_relation_over as dd' \\<and>\n    threadwise_relation_over as cd' \\<and>\n    strict_preorder as sb' \\<and>\n    strict_preorder as dd' \\<and>\n    strict_preorder as cd' \\<and>\n    (\\<forall> a \\<in> as . thread_id_of a \\<in> threads') \\<and>\n    actions_respect_location_kinds as lk' \\<and>\n    dd' \\<subseteq> sb' \\<and>\n    relation_over as asw' \\<and>\n    (\\<forall> a \\<in> as . is_blocked_rmw a \\<or> is_blocked_lock a \\<longrightarrow> \\<not> (\\<exists> b \\<in> as . (a,b) \\<in> sb')))\"\n\n(*   - 3.4 - Consistent locks *)\nfun consistent_locks where\n\"consistent_locks as lo hb = \n   (strict_total_order_over {a . a \\<in> as \\<and> (is_lock a \\<or> is_unlock a)} lo \\<and>\n       restrict_relation_set hb {a . a \\<in> as \\<and> (is_lock a \\<or> is_unlock a)} \\<subseteq> lo \\<and>\n   (\\<forall> (a,c) \\<in> lo. \n      is_successful_lock a \\<and> is_successful_lock c \\<and> same_location a c\n     \\<longrightarrow>\n      (\\<exists> b \\<in> as . same_location a b \\<and> is_unlock b \\<and> (a,b) \\<in> lo \\<and> (b,c) \\<in> lo)))\"\n\n(*  - 3.5 - Well formed reads from mapping *)\nfun well_formed_reads_from_mapping where\n\"well_formed_reads_from_mapping as lk' rf' = \n  (relation_over as rf' \\<and>\n  (\\<forall> a1 \\<in> as . (\\<forall> a2 \\<in> as . (\\<forall> b \\<in> as . \n          (a1,b) \\<in> rf' \\<and> (a2,b) \\<in> rf' \\<longrightarrow> (a1 = a2)))) \\<and>\n   (\\<forall> a \\<in> as . (\\<forall> b \\<in> as . (a,b) \\<in> rf' \\<longrightarrow> \n          same_location a b \\<and> (value_read_by b = value_written_by a) \\<and>\n        \\<not> (a = b) \\<and> \\<not> is_fence a \\<and> \\<not> is_fence b \\<and>\n    \\<not> (is_at_mutex_location lk' a) \\<and> \n       (is_at_non_atomic_location lk' a \\<longrightarrow> is_store a \\<and> is_load b) \\<and>\n       (is_at_atomic_location lk' a \\<longrightarrow>\n          (is_atomic_store a \\<or> is_atomic_rmw a \\<or> is_store a) \\<and> \n           (is_atomic_load b \\<or> is_atomic_rmw b \\<or> is_load b)))))\"\n\n(*   - 3.6 - Happens before *)\nfun rs_element where\n\"rs_element rs_head a =\n    (same_thread a rs_head \\<or> is_atomic_rmw a)\"\n\nfun release_sequence where\n\"release_sequence as lk' mo' a_rel b =\n   (is_at_atomic_location lk' b \\<and>\n    is_release a_rel \\<and>\n    ((b = a_rel) \\<or>\n      (rs_element a_rel b \\<and> (a_rel,b) \\<in> mo' \\<and>\n        (\\<forall> c \\<in> as . ((a_rel,c) \\<in> mo' \\<and> (c,b) \\<in> mo') \\<longrightarrow> rs_element a_rel c))))\"\n\n\nfun release_sequence_set where\n\"release_sequence_set as lk' mo' =\n {(a,b) . a \\<in> as \\<and> b \\<in> as \\<and> release_sequence as lk' mo' a b}\"\n\nfun hypothetical_release_sequence where\n\"hypothetical_release_sequence as lk' mo' a b =\n    (is_at_atomic_location lk' b \\<and>\n    ((b = a) \\<or>\n      ( rs_element a b \\<and> (a,b) \\<in> mo' \\<and> \n        (\\<forall> c \\<in> as . ((a,c) \\<in> mo' \\<and> (c,b) \\<in> mo') \\<longrightarrow> rs_element a c))))\"\n\nfun hypothetical_release_sequence_set where\n\"hypothetical_release_sequence_set as lk' mo' =\n  {(a,b) . a \\<in> as \\<and> b \\<in> as \\<and> hypothetical_release_sequence as lk' mo' a b}\"\n\nfun synchronizes_with where\n\"synchronizes_with as sb' asw' rf' lo rs hrs a b =\n  ((a,b) \\<in> asw' \\<or>\n    ( same_location a b \\<and> a \\<in> as \\<and> b \\<in> as \\<and>\n     ( (is_unlock a \\<and> is_successful_lock b \\<and> (a,b) \\<in> lo) \\<or>\n       ( is_release a \\<and> is_acquire b \\<and> \\<not> (same_thread a b) \\<and>\n          (\\<exists> c \\<in> as . (a,c) \\<in> rs \\<and> (c,b) \\<in> rf' ) ) \\<or>\n        (\\<not> (same_thread a b) \\<and>\n          is_fence a \\<and> is_release a \\<and> is_fence b \\<and> is_acquire b \\<and>\n          (\\<exists> x \\<in> as . (\\<exists> y \\<in> as . same_location x y \\<and>\n              is_atomic_action x \\<and> is_atomic_action y \\<and> is_write x \\<and>\n              (a,x) \\<in> sb' \\<and> (y,b) \\<in> sb' \\<and>\n              (\\<exists> z \\<in> as . (x,z) \\<in> hrs \\<and> (z,y) \\<in> rf')))) \\<or> \n        (\\<not> (same_thread a b) \\<and>\n          is_fence a \\<and> is_release a \\<and> is_atomic_action b \\<and> is_acquire b \\<and>\n          (\\<exists> x \\<in> as . same_location x b \\<and>\n            is_atomic_action x \\<and> is_write x \\<and> (a,x) \\<in> sb' \\<and>\n            (\\<exists> z \\<in> as . (x,z) \\<in> hrs \\<and> (z,b) \\<in> rf' ) ) ) \\<or>\n        (\\<not> (same_thread a b) \\<and>\n          is_atomic_action a \\<and> is_release a \\<and>\n          is_fence b \\<and> is_acquire b \\<and>\n          (\\<exists> x \\<in> as . same_location a x \\<and> is_atomic_action x \\<and>\n            (x,b) \\<in> sb' \\<and>\n            (\\<exists> z \\<in> as . (a,z) \\<in> rs \\<and> (z,x) \\<in> rf' ) ) ))))\"\n\nfun synchronizes_with_set where\n\"synchronizes_with_set as sb' asw' rf' lo rs hrs =\n {(a,b) . a \\<in> as \\<and> b \\<in> as \\<and> synchronizes_with as sb' asw' rf' lo rs hrs a b}\"\n\nfun carries_a_dependency_to_set where\n\"carries_a_dependency_to_set as sb' dd' rf' = tc ( (rf' \\<inter> sb') \\<union> dd')\"\n\nfun dependency_ordered_before where\n\"dependency_ordered_before as rf' rs cad a d =\n    (a \\<in> as \\<and> d \\<in> as \\<and>\n     (\\<exists> b \\<in> as . is_release a \\<and> is_consume b \\<and>\n       (\\<exists> e \\<in> as . (a,e) \\<in> rs \\<and> (e,b) \\<in> rf') \\<and>\n       ( (b,d) \\<in> cad \\<or> (b = d) )))\"\n\nfun dependency_ordered_before_set where\n\"dependency_ordered_before_set as rf' rs cad =\n         {(a,b) . a \\<in> as \\<and> b \\<in> as \\<and> dependency_ordered_before as rf' rs cad a b}\"\n\nfun compose where\n\"compose R1 R2 = { (w,z) . \\<exists> t . (w,t) \\<in> R1 \\<and> (t,z) \\<in> R2}\"\n\nfun inter_thread_happens_before where\n\"inter_thread_happens_before sb' sw dob =\n    tc ((sw \\<union> dob \\<union> (compose sw sb')) \\<union> (compose sb' (sw \\<union> dob \\<union> (compose sw sb'))))\"\n\n\nfun consistent_inter_thread_happens_before where\n\"consistent_inter_thread_happens_before as ithb = irrefl as ithb\"\n\nfun happens_before where\n\"happens_before as sb' ithb = sb' \\<union> ithb\"\n\n(*   - 3.7 - Consistent SC and modification orders *)\n\nfun all_sc_actions where\n\"all_sc_actions as =\n { a . a \\<in> as \\<and> (is_seq_cst a \\<or> is_lock a \\<or> is_unlock a )}\"\n\nfun consistent_sc_order where\n\"consistent_sc_order as mo' sc' hb = \n   (strict_total_order_over (all_sc_actions as) sc' \\<and>\n       (restrict_relation_set hb (all_sc_actions as)) \\<subseteq> sc' \\<and>\n       (restrict_relation_set mo' (all_sc_actions as)) \\<subseteq> sc')\"\n\nfun consistent_modification_order where\n\"consistent_modification_order as lk' sb' mo' hb =\n  ((\\<forall> a \\<in> as . (\\<forall> b \\<in> as . (a,b) \\<in> mo' \\<longrightarrow>\n          (same_location a b \\<and> is_write a \\<and> is_write b))) \\<and>\n   (\\<forall> l \\<in> locations_of as .\n        (case lk' l of Atomic \\<Rightarrow> \n          (strict_total_order_over {a . a \\<in> {a . a \\<in> as \\<and> location_of a = Some l} \\<and> is_write a}\n                      (restrict_relation_set mo' {a . a \\<in> as \\<and> location_of a = Some l})\n           \\<and> restrict_relation_set hb {a . a \\<in> {a . a \\<in> as \\<and> location_of a = Some l} \\<and> is_write a} \\<subseteq> mo')  )))\"\n\n\n(*   - 3.8 - Visible side effects *)\nfun visible_side_effect where\n\"visible_side_effect as hb a b =\n   ((a,b) \\<in> hb \\<and>\n    is_write a \\<and> is_read b \\<and> same_location a b \\<and>\n     \\<not> (\\<exists> c \\<in> as . \\<not> (c = a) \\<and> \\<not> (c = b) \\<and>\n          is_write c \\<and> same_location c b \\<and>\n          (a,c) \\<in> hb \\<and> (c,b) \\<in> hb))\"\n\n\nfun visible_side_effect_set where\n\"visible_side_effect_set as hb =\n    { (a,b) . (a,b) \\<in> hb \\<and> visible_side_effect as hb a b}\"\n\n(*   - 3.9 - Undefined behaviour *)\nfun indeterminate_reads where\n\"indeterminate_reads as rf' =\n    {b . b \\<in> as \\<and> is_read b \\<and> \\<not> (\\<exists> a \\<in> as . (a,b) \\<in> rf')}\"\n\nfun unsequenced_races where\n\"unsequenced_races as sb' =\n{(a,b) . a \\<in> as \\<and> b \\<in> as \\<and> \\<not> (a = b) \\<and> same_location a b \\<and> (is_write a \\<or> is_write b) \\<and>\n          same_thread a b \\<and> \\<not> ((a,b) \\<in> sb' \\<or> (b,a) \\<in> sb')}\"\n\nfun data_races where\n\"data_races as hb =\n{(a,b) . a \\<in> as \\<and> b \\<in> as \\<and> \\<not> a = b \\<and> same_location a b \\<and> (is_write a \\<or> is_write b) \\<and>\n       \\<not> same_thread a b \\<and> \\<not> (is_atomic_action a \\<and> is_atomic_action b) \\<and>\n        \\<not> ((a,b) \\<in> hb \\<or> (b,a) \\<in> hb) }\"\n\nfun data_races' where\n\"data_races' Xo Xw lo =\n (case release_sequence_set (actions Xo) (lk Xo) (mo Xw) of rs \\<Rightarrow>\n   (case hypothetical_release_sequence_set (actions Xo) (lk Xo) (mo Xw) of hrs \\<Rightarrow>\n    (case synchronizes_with_set (actions Xo) (sb Xo) (asw Xo) (rf Xw) lo rs hrs of sw \\<Rightarrow>\n     (case carries_a_dependency_to_set (actions Xo) (sb Xo) (dd Xo) (rf Xw) of cad \\<Rightarrow>\n      (case dependency_ordered_before_set (actions Xo) (rf Xw) rs cad of dob \\<Rightarrow>\n       (case inter_thread_happens_before (sb Xo) sw dob of ithb \\<Rightarrow>\n        (case happens_before (actions Xo) (sb Xo) ithb of hb \\<Rightarrow>\n          data_races (actions Xo) hb)))))))\"\n\nfun good_mutex_use where\n\"good_mutex_use as lk' sb' lo a =\n  (case {a' . a' \\<in> as \\<and> ((is_successful_lock a' \\<or> is_unlock a') \\<and> (location_of a' = location_of a))} of \n  mutexes_at_l \\<Rightarrow> (case restrict_relation_set lo mutexes_at_l of lock_order \\<Rightarrow>\n  ( is_unlock a  \\<longrightarrow> (\\<exists> al \\<in> as .\n              is_successful_lock al \\<and> (location_of al = location_of a) \\<and> (al,a) \\<in> sb' \\<and>\n              adjacent_less_than lock_order as al a ) ) \\<and>\n   ( is_lock a \\<longrightarrow>\n      \\<not> (\\<exists> al \\<in> as .\n          is_successful_lock al \\<and> (location_of a = location_of al) \\<and> same_thread a al \\<and>\n          adjacent_less_than lock_order as al a ))))\"\n\n\nfun bad_mutexes where\n\"bad_mutexes Xo lo =\n  { a . a \\<in> (actions Xo) \\<and> \\<not> (good_mutex_use (actions Xo) (lk Xo) (sb Xo) lo a)}\"\n\nfun undefined_behaviour where\n\"undefined_behaviour Xo Xw =\n  (\\<not> (data_races' Xo Xw (sc Xw) = {}) \\<or>\n  \\<not> (unsequenced_races (actions Xo) (sb Xo) = {}) \\<or>\n  \\<not> (indeterminate_reads (actions Xo) (rf Xw) = {}) \\<or>\n  \\<not> (bad_mutexes Xo (sc Xw) = {}))\"\n\n(*   - 3.10 - Consistent reads from mapping *)\nfun consistent_non_atomic_read_values where\n\"consistent_non_atomic_read_values as lk' rf' vse =\n  (\\<forall> b \\<in> as . (is_read b \\<and> is_at_non_atomic_location lk' b)\n   \\<longrightarrow> (if (\\<exists> a_vse \\<in> as . (a_vse,b) \\<in> vse)\n        then (\\<exists> a_vse \\<in> as . (a_vse,b) \\<in> vse \\<and> (a_vse,b) \\<in> rf')\n        else \\<not> (\\<exists> a \\<in> as . (a,b) \\<in> rf')))\"\n\nfun coherent_memory_use where\n\"coherent_memory_use as lk' rf' mo' hb = \n  ((\\<forall> (x,a) \\<in> rf' .(\\<forall> (y,b) \\<in> rf' .\n      ((a,b) \\<in> hb \\<and> same_location a b \\<and> is_at_atomic_location lk' b) \\<longrightarrow>\n      ((x = y) \\<or> (x,y) \\<in> mo'))) \\<and>\n    (\\<forall> (a,b) \\<in> hb . (\\<forall> c \\<in> as .\n      ((c,b) \\<in> rf' \\<and> is_write a \\<and> same_location a b \\<and> is_at_atomic_location lk' b) \\<longrightarrow>\n      ((c = a) \\<or> (a,c) \\<in> mo'))) \\<and> \n  (\\<forall> (a,b) \\<in> hb . (\\<forall> c \\<in> as .\n      ((c,a) \\<in> rf' \\<and> is_write b \\<and> same_location a b \\<and> is_at_atomic_location lk' a) \\<longrightarrow>\n      ((c,b) \\<in> mo'))))\"\n\nfun rmw_atomicity where\n\"rmw_atomicity as rf' mo' = \n   (\\<forall> (a,b) \\<in> rf' .\n    is_atomic_rmw b \\<longrightarrow> adjacent_less_than mo' as a b)\"\n\nfun sc_reads_restricted where\n\"sc_reads_restricted as rf' sc' mo' hb =\n  (\\<forall> (a,b) \\<in> rf' .\n    is_seq_cst b \\<longrightarrow>\n    (adjacent_less_than_such_that (\\<lambda> c . is_write c \\<and> same_location b c) sc' as a b) \\<or>\n    ( \\<not> (is_seq_cst a) \\<and>\n      (\\<forall> x \\<in> as .\n        (adjacent_less_than_such_that (\\<lambda> c . is_write c \\<and> same_location b c) sc' as x b)\n                     \\<longrightarrow> \\<not> ((a,x) \\<in> hb))))\"\n\n\n\n    (* fence restriction N3291 29.3p4 *)\n    (* fence restriction N3291 29.3p5 *)\n    (* fence restriction N3291 29.3p6 *)\n    (* SC fences impose mo N3291 29.3p7 *)\n(* SC fences impose mo N3291 29.3p7, w collapsed first write*)\n(* SC fences impose mo N3291 29.3p7, w collapsed second write*)\n\nfun sc_fences_heeded where\n\"sc_fences_heeded as sb' rf' sc' mo' = \n  ((\\<forall> a \\<in> as . (\\<forall> (x,b) \\<in> sb' . (\\<forall> y \\<in> as .\n      ( is_write a \\<and> is_fence x \\<and>\n        adjacent_less_than sc' as a x \\<and>\n        is_atomic_action b \\<and> same_location a b \\<and>\n        (y,b) \\<in> rf') \\<longrightarrow>\n      (y = a) \\<or> (a,y) \\<in> mo') )) \\<and>\n   (\\<forall> (a,x) \\<in> sb' . (\\<forall> (y,b) \\<in> rf' .\n      ((is_atomic_action a \\<and> is_write a \\<and>\n        is_fence x \\<and> is_atomic_action b \\<and> (x,b) \\<in> sc' \\<and>\n        same_location a b) \\<longrightarrow>\n      ((y = a) \\<or> (a,y) \\<in> mo')))) \\<and>\n     (\\<forall> (a,x) \\<in> sb' . (\\<forall> (y,b) \\<in> sb' . (\\<forall> z \\<in> as .\n      (is_atomic_action a \\<and> is_write a \\<and>\n        is_fence x \\<and> is_fence y \\<and> (x,y) \\<in> sc' \\<and>\n        is_atomic_action b \\<and> same_location a b \\<and>\n        (z,b) \\<in> rf') \\<longrightarrow>\n             ((z = a) \\<or> (a,z) \\<in> mo')))) \\<and>\n  (\\<forall> (a,x) \\<in> sb' . (\\<forall> (y,b) \\<in> sb' .\n      ( is_atomic_action a \\<and> is_write a \\<and>\n        is_atomic_action b \\<and> is_write b \\<and>\n        is_fence x \\<and> is_fence y \\<and> (x,y) \\<in> sc' \\<and>\n        same_location a b \\<longrightarrow>\n      (a,b) \\<in> mo'))) \\<and>\n    (\\<forall> a \\<in> as . (\\<forall> (y,b) \\<in> sb' .\n      ( is_atomic_action a \\<and> is_write a \\<and>\n        is_fence y \\<and> (a,y) \\<in> sc' \\<and>\n        is_atomic_action b \\<and> is_write b \\<and>\n        same_location a b \\<longrightarrow>\n             (a,b) \\<in> mo'))) \\<and>\n   (\\<forall> (a,x) \\<in> sb' . (\\<forall> b \\<in> as .\n      (is_atomic_action a \\<and> is_write a \\<and>\n        is_fence x \\<and> is_atomic_action b \\<and> is_write b \\<and> (x,b) \\<in> sc' \\<and>\n        same_location a b \\<longrightarrow>\n         (a,b) \\<in> mo'))) )\"\n\nfun no_vsse_consistent_atomic_read_values where\n\"no_vsse_consistent_atomic_read_values as lk' rf' hb vse = \n   (\\<forall> b \\<in> as .\n    (is_read b \\<and> is_at_atomic_location lk' b) \\<longrightarrow>\n      ( if (\\<exists> a_vse \\<in> as . (a_vse,b) \\<in> vse)\n        then (\\<exists> a \\<in> as . (a,b) \\<in> rf' \\<and> \\<not> ((b,a) \\<in> hb))\n        else \\<not> (\\<exists> a \\<in> as . (a,b) \\<in> rf')))\"\n\nfun no_vsse_consistent_reads_from_mapping where\n\"no_vsse_consistent_reads_from_mapping as lk' sb' rf' sc' mo' hb vse =\n   (consistent_non_atomic_read_values as lk' rf' vse \\<and>\n    no_vsse_consistent_atomic_read_values as lk' rf' hb vse \\<and>\n    coherent_memory_use as lk' rf' mo' hb \\<and>\n    rmw_atomicity as rf' mo' \\<and>\n    sc_reads_restricted as rf' sc' mo' hb \\<and>\n    sc_fences_heeded as sb' rf' sc' mo')\"\n\n(* 3.11 - Consistent execution *)\n(* This simplification has ben verified equivalent to the model\n   in section 3 using the HOL theorem prover. It removes the complicated\n   notion of VSSE's, whose force is covered by the coherence requirements.\n   For those looking to work with C or C++ concurrency, this is the preferred model. *)\n\nfun no_vsse_consistent_execution where\n\"no_vsse_consistent_execution Xo Xw = \n   (well_formed_threads (actions Xo) (threads Xo) (lk Xo) (sb Xo) (asw Xo) (dd Xo) (cd Xo) \\<and>\n   (case release_sequence_set (actions Xo) (lk Xo) (mo Xw) of rs \\<Rightarrow>\n     (case hypothetical_release_sequence_set (actions Xo) (lk Xo) (mo Xw) of hrs \\<Rightarrow>\n     (case synchronizes_with_set (actions Xo) (sb Xo) (asw Xo) (rf Xw) (sc Xw) rs hrs of sw \\<Rightarrow>\n     (case carries_a_dependency_to_set (actions Xo) (sb Xo) (dd Xo) (rf Xw) of cad \\<Rightarrow>\n     (case dependency_ordered_before_set (actions Xo) (rf Xw) rs cad of dob \\<Rightarrow>\n     (case inter_thread_happens_before (sb Xo) sw dob of ithb \\<Rightarrow>\n     (case happens_before (actions Xo) (sb Xo) ithb of hb \\<Rightarrow> \n      (case visible_side_effect_set (actions Xo) hb of vse \\<Rightarrow>\n    consistent_locks (actions Xo) (sc Xw) hb \\<and>\n       consistent_inter_thread_happens_before (actions Xo) ithb \\<and>\n        consistent_sc_order (actions Xo) (mo Xw) (sc Xw) hb \\<and>\n         consistent_modification_order (actions Xo) (lk Xo) (sb Xo) (mo Xw) hb \\<and>\n          well_formed_reads_from_mapping (actions Xo) (lk Xo) (rf Xw) \\<and>\n             no_vsse_consistent_reads_from_mapping (actions Xo) (lk Xo) (sb Xo) (rf Xw) (sc Xw) (mo Xw) hb vse)))))))))\"\n\n(*  - 3.12 - Preferred model top level judgement *)\ndefinition no_vsse_cmm where\n\"no_vsse_cmm opsem p = \n    (case { (Xopsem,Xwitness) . opsem p Xopsem \\<and> no_vsse_consistent_execution Xopsem Xwitness}\n            of pre_executions \\<Rightarrow> \n         if (\\<exists> (Xo,Xw) \\<in> pre_executions .  undefined_behaviour Xo Xw)\n             then {(Xo,Xw) . True} else pre_executions)\"\n\n\n(* 4 - Standard C/C++ model *)\n(* The following definitions make up the memory model described by the\n   2011 standard. It was constructed in discussion with the\n   standardisation comittee. *)\n\nfun visible_sequence_of_side_effects_tail where\n\"visible_sequence_of_side_effects_tail as mo' hb vsse_head b = \n   { c . c \\<in> as \\<and> (vsse_head,c) \\<in> mo' \\<and> \\<not> (b,c) \\<in> hb \\<and>\n           (\\<forall> a \\<in> as . (vsse_head,a) \\<in> mo' \\<and> (a,c) \\<in> mo' \\<longrightarrow> \\<not> (b,a) \\<in> hb)}\"\n\n(* visible sequences of side effects have been proven redundant. See the simpler model in section 3. *)\nfun visible_sequence_of_side_effects where\n\"visible_sequence_of_side_effects as lk' mo' hb vsse_head b =\n     (b , if is_at_atomic_location lk' b then\n             {vsse_head} \\<union>\n             visible_sequence_of_side_effects_tail as mo' hb vsse_head b\n           else {})\"\n\nfun visible_sequences_of_side_effects_set where\n\"visible_sequences_of_side_effects_set as lk' mo' hb vse =\n   { (b,bs) . b \\<in> as \\<and> is_at_atomic_location lk' b \\<and> is_read b \\<and>\n        (\\<exists> vsse_head . (b,bs) = visible_sequence_of_side_effects as lk' mo' hb vsse_head b\n        \\<and> vsse_head \\<in> as \\<and> (vsse_head,b) \\<in> vse)}\"\n\nfun consistent_atomic_read_values where\n\"consistent_atomic_read_values as lk' rf' vsses =\n   (\\<forall> b \\<in> as . (is_read b \\<and> is_at_atomic_location lk' b) \\<longrightarrow> \n           ( if (\\<exists> (b',v) \\<in> vsses . b = b')\n        then (\\<exists> (b',v) \\<in> vsses . b = b' \\<and>\n               (\\<exists> c \\<in> v . (c,b) \\<in> rf'))\n        else \\<not> (\\<exists> a \\<in> as . (a,b) \\<in> rf')))\"\n\nfun consistent_reads_from_mapping where \n\"consistent_reads_from_mapping as lk' sb' rf' sc' mo' hb vse vsses =\n   (consistent_non_atomic_read_values as lk' rf' vse \\<and>\n    consistent_atomic_read_values as lk' rf' vsses \\<and>\n    coherent_memory_use as lk' rf' mo' hb \\<and>\n    rmw_atomicity as rf' mo' \\<and>\n    sc_reads_restricted as rf' sc' mo' hb \\<and>\n    sc_fences_heeded as sb' rf' sc' mo')\"\n\nfun consistent_execution where\n\"consistent_execution Xo Xw =\n   (well_formed_threads (actions Xo) (threads Xo) (lk Xo) (sb Xo) (asw Xo) (dd Xo) (cd Xo) \\<and>\n     (case release_sequence_set (actions Xo) (lk Xo) (mo Xw) of rs \\<Rightarrow>\n      (case hypothetical_release_sequence_set (actions Xo) (lk Xo) (mo Xw) of hrs \\<Rightarrow>\n       (case synchronizes_with_set (actions Xo) (sb Xo) (asw Xo) (rf Xw) (sc Xw) rs hrs of sw \\<Rightarrow>\n        (case carries_a_dependency_to_set (actions Xo) (sb Xo) (dd Xo) (rf Xw) of cad \\<Rightarrow>\n         (case dependency_ordered_before_set (actions Xo) (rf Xw) rs cad of dob \\<Rightarrow> \n          (case inter_thread_happens_before (sb Xo) sw dob of ithb \\<Rightarrow>\n           (case happens_before (actions Xo) (sb Xo) ithb of hb \\<Rightarrow> \n            (case visible_side_effect_set (actions Xo) hb of vse \\<Rightarrow>\n             (case visible_sequences_of_side_effects_set (actions Xo) (lk Xo) (mo Xw) hb vse of vsses \\<Rightarrow>\n              consistent_locks (actions Xo) (sc Xw) hb \\<and>\n    consistent_inter_thread_happens_before (actions Xo) ithb \\<and>\n    consistent_sc_order (actions Xo) (mo Xw) (sc Xw) hb \\<and>\n    consistent_modification_order (actions Xo) (lk Xo) (sb Xo) (mo Xw) hb \\<and>\n    well_formed_reads_from_mapping (actions Xo) (lk Xo) (rf Xw) \\<and>\n    consistent_reads_from_mapping (actions Xo) (lk Xo) (sb Xo) (rf Xw) (sc Xw) (mo Xw) hb vse vsses))))))))))\"\n\n(*   - 4.1  - Standard model top level judgement *)\ndefinition cmm where\n\"cmm opsem p = (case { (Xopsem,Xwitness) . opsem p Xopsem \\<and> consistent_execution Xopsem Xwitness}\n       of pre_executions \\<Rightarrow> if (\\<exists> (Xo,Xw) \\<in> pre_executions . undefined_behaviour Xo Xw)\n                             then {(Xo,Xw). True} else pre_executions)\"\n\n\n(* 5 - Model with seperate lock order *)\n(* A version of the no VSSE model with a seperate lock order. *)\nfun no_vsse_seperate_lo_consistent_execution where\n\"no_vsse_seperate_lo_consistent_execution Xo Xw lo =\n   (well_formed_threads (actions Xo) (threads Xo) (lk Xo) (sb Xo) (asw Xo) (dd Xo) (cd Xo) \\<and>\n     (case release_sequence_set (actions Xo) (lk Xo) (mo Xw) of rs \\<Rightarrow>\n      (case hypothetical_release_sequence_set (actions Xo) (lk Xo) (mo Xw) of hrs \\<Rightarrow>\n       (case synchronizes_with_set (actions Xo) (sb Xo) (asw Xo) (rf Xw) lo rs hrs of sw \\<Rightarrow>\n        (case carries_a_dependency_to_set (actions Xo) (sb Xo) (dd Xo) (rf Xw) of cad \\<Rightarrow>\n         (case dependency_ordered_before_set (actions Xo) (rf Xw) rs cad of dob \\<Rightarrow> \n          (case inter_thread_happens_before (sb Xo) sw dob of ithb \\<Rightarrow>\n           (case happens_before (actions Xo) (sb Xo) ithb of hb \\<Rightarrow> \n            (case visible_side_effect_set (actions Xo) hb of vse \\<Rightarrow>\n             (case visible_sequences_of_side_effects_set (actions Xo) (lk Xo) (mo Xw) hb vse of vsses \\<Rightarrow>\n    consistent_locks (actions Xo) lo hb \\<and>\n    consistent_inter_thread_happens_before (actions Xo) ithb \\<and>\n    consistent_sc_order (actions Xo) (mo Xw) (sc Xw) hb \\<and>\n    consistent_modification_order (actions Xo) (lk Xo) (sb Xo) (mo Xw) hb \\<and>\n    well_formed_reads_from_mapping (actions Xo) (lk Xo) (rf Xw) \\<and>\n    no_vsse_consistent_reads_from_mapping (actions Xo) (lk Xo) (sb Xo) (rf Xw) (sc Xw) (mo Xw) hb vse))))))))))\"\n\nfun no_vsse_seperate_lo_undefined_behaviour where\n\"no_vsse_seperate_lo_undefined_behaviour Xo Xw lo =\n  (\\<not> (data_races' Xo Xw lo = {}) \\<or>\n  \\<not> (unsequenced_races (actions Xo) (sb Xo) = {}) \\<or>\n  \\<not> (indeterminate_reads (actions Xo) (rf Xw) = {}) \\<or>\n  \\<not> (bad_mutexes Xo lo = {}))\"\n\n(*  - 5.1  - Seperate lock order top level judgement *)\ndefinition no_vsse_seperate_lo_cmm where\n\"no_vsse_seperate_lo_cmm opsem p = \n   (case { (Xopsem,(Xwitness,lo)).\n      opsem p Xopsem \\<and> no_vsse_seperate_lo_consistent_execution Xopsem Xwitness lo}\n       of pre_executions \\<Rightarrow>\n       if (\\<exists> (Xo,(Xw,lo)) \\<in> pre_executions . no_vsse_seperate_lo_undefined_behaviour Xo Xw lo)\n        then { (Xo,(Xw,lo)) . True } else pre_executions)\"\n\n(* 6 - Model with per-location lock orders *)\n(* This model uses per location lock orders rather than one shared one. *)\nfun multi_lo_consistent_locks where\n\"multi_lo_consistent_locks as lk' lo hb =\n  (case {a . a \\<in> as \\<and> (is_lock a \\<or> is_unlock a)} of mutex_actions \\<Rightarrow>\n    (case restrict_relation_set hb mutex_actions of lo_happens_before \\<Rightarrow>\n      lo_happens_before \\<subseteq> lo \\<and>\n    (\\<forall> (a,c) \\<in> lo . is_successful_lock a \\<and> is_successful_lock c \\<and> same_location a c\n      \\<longrightarrow>  (\\<exists> b \\<in> as . same_location a b \\<and> is_unlock b \\<and> (a,b) \\<in> lo \\<and> (b,c) \\<in> lo)) \\<and>\n   (\\<forall> l \\<in> locations_of as . \n        (case {a . a \\<in> as \\<and>location_of a = Some l} of actions_at_l \\<Rightarrow>\n           (case lk' l of Mutex \\<Rightarrow> strict_total_order_over actions_at_l (restrict_relation_set lo actions_at_l)\n                | _ \\<Rightarrow> Set.is_empty (restrict_relation_set lo actions_at_l))))))\"\n\nfun no_vsse_multi_lo_consistent_execution where\n\"no_vsse_multi_lo_consistent_execution Xo Xw lo =\n   (well_formed_threads (actions Xo) (threads Xo) (lk Xo) (sb Xo) (asw Xo) (dd Xo) (cd Xo) \\<and>\n     (case release_sequence_set (actions Xo) (lk Xo) (mo Xw) of rs \\<Rightarrow>\n      (case hypothetical_release_sequence_set (actions Xo) (lk Xo) (mo Xw) of hrs \\<Rightarrow>\n       (case synchronizes_with_set (actions Xo) (sb Xo) (asw Xo) (rf Xw) lo rs hrs of sw \\<Rightarrow>\n        (case carries_a_dependency_to_set (actions Xo) (sb Xo) (dd Xo) (rf Xw) of cad \\<Rightarrow>\n         (case dependency_ordered_before_set (actions Xo) (rf Xw) rs cad of dob \\<Rightarrow> \n          (case inter_thread_happens_before (sb Xo) sw dob of ithb \\<Rightarrow>\n           (case happens_before (actions Xo) (sb Xo) ithb of hb \\<Rightarrow> \n            (case visible_side_effect_set (actions Xo) hb of vse \\<Rightarrow>\n    multi_lo_consistent_locks (actions Xo) (lk Xo) lo hb \\<and>\n    consistent_inter_thread_happens_before (actions Xo) ithb \\<and>\n    consistent_sc_order (actions Xo) (mo Xw) (sc Xw) hb \\<and>\n    consistent_modification_order (actions Xo) (lk Xo) (sb Xo) (mo Xw) hb \\<and>\n    well_formed_reads_from_mapping (actions Xo) (lk Xo) (rf Xw) \\<and>\n    no_vsse_consistent_reads_from_mapping (actions Xo) (lk Xo) (sb Xo) (rf Xw) (sc Xw) (mo Xw) hb vse)))))))))\"\n\n(*   - 6.1  - per-location lock order top level judgement *)\ndefinition no_vsse_multi_lo_cmm where\n\"no_vsse_multi_lo_cmm opsem p = \n   (case { (Xopsem,(Xwitness,lo)).\n      opsem p Xopsem \\<and> no_vsse_multi_lo_consistent_execution Xopsem Xwitness lo}\n       of pre_executions \\<Rightarrow>\n       if (\\<exists> (Xo,(Xw,lo)) \\<in> pre_executions . no_vsse_seperate_lo_undefined_behaviour Xo Xw lo)\n        then { (Xo,(Xw,lo)) . True } else pre_executions)\"\n\n(* 7 - Model with single step mutex synchronisation *)\n(* This model creates synchronizes-with edges from each unlock to the\n   next lock at the same location, rather than all subsequent ones. *)\nfun lo_single_synchronizes_with where\n\"lo_single_synchronizes_with as sb' asw' rf' lo rs hrs a b = \n  ((a,b) \\<in> asw' \\<or>\n    (same_location a b \\<and> a \\<in> as \\<and> b \\<in> as \\<and>\n     ((is_unlock a \\<and> is_successful_lock b \\<and> (a,b) \\<in> lo \\<and>\n                \\<not> (\\<exists> c \\<in> as . (a,c) \\<in> lo \\<and> (c,b) \\<in> lo)) \\<or>\n     (is_release a \\<and> is_acquire b \\<and> \\<not> (same_thread a b) \\<and>\n          (\\<exists> c \\<in> as . (a,c) \\<in> rs \\<and> (c,b) \\<in>  rf')) \\<or>\n     ( \\<not> (same_thread a b) \\<and>\n          is_fence a \\<and> is_release a \\<and> is_fence b \\<and> is_acquire b \\<and>\n          (\\<exists> x \\<in> as . (\\<exists> y \\<in> as . same_location x y \\<and>\n              is_atomic_action x \\<and> is_atomic_action y \\<and> is_write x \\<and>\n              (a,x) \\<in> sb' \\<and> (y,b) \\<in> sb' \\<and>\n              (\\<exists> z \\<in> as . (x,z) \\<in> hrs \\<and> (z,y) \\<in> rf')))) \\<or>\n    ( \\<not> (same_thread a b) \\<and>\n          is_fence a \\<and> is_release a \\<and> is_atomic_action b \\<and> is_acquire b \\<and>\n          (\\<exists> x \\<in> as . same_location x b \\<and>\n            is_atomic_action x \\<and> is_write x \\<and> (a,x) \\<in> sb' \\<and>\n            (\\<exists> z \\<in> as . (x,z) \\<in> hrs \\<and> (z,b) \\<in> rf'))) \\<or>\n    ( \\<not> (same_thread a b) \\<and>\n          is_atomic_action a \\<and> is_release a \\<and>\n          is_fence b \\<and> is_acquire b \\<and>\n          ( \\<exists> x \\<in> as . same_location a x \\<and> is_atomic_action x \\<and>\n            (x,b) \\<in> sb' \\<and>\n            ( \\<exists> z \\<in> as . (a,z) \\<in> rs \\<and> (z,x) \\<in> rf'))))))\"\n\nfun lo_single_synchronizes_with_set where\n\"lo_single_synchronizes_with_set as sb' asw' rf' lo rs hrs =\n    {(a,b) . a \\<in> as \\<and> b \\<in> as \\<and>\n       lo_single_synchronizes_with as sb' asw' rf' lo rs hrs a b}\"\n\nfun no_vsse_multi_lo_single_sw_consistent_execution where\n\"no_vsse_multi_lo_single_sw_consistent_execution Xo Xw lo =\n   (well_formed_threads (actions Xo) (threads Xo) (lk Xo) (sb Xo) (asw Xo) (dd Xo) (cd Xo) \\<and>\n     (case release_sequence_set (actions Xo) (lk Xo) (mo Xw) of rs \\<Rightarrow>\n      (case hypothetical_release_sequence_set (actions Xo) (lk Xo) (mo Xw) of hrs \\<Rightarrow>\n       (case synchronizes_with_set (actions Xo) (sb Xo) (asw Xo) (rf Xw) lo rs hrs of sw \\<Rightarrow>\n        (case carries_a_dependency_to_set (actions Xo) (sb Xo) (dd Xo) (rf Xw) of cad \\<Rightarrow>\n         (case dependency_ordered_before_set (actions Xo) (rf Xw) rs cad of dob \\<Rightarrow> \n          (case inter_thread_happens_before (sb Xo) sw dob of ithb \\<Rightarrow>\n           (case happens_before (actions Xo) (sb Xo) ithb of hb \\<Rightarrow> \n            (case visible_side_effect_set (actions Xo) hb of vse \\<Rightarrow>\n    multi_lo_consistent_locks (actions Xo) (lk Xo) lo hb \\<and>\n    consistent_inter_thread_happens_before (actions Xo) ithb \\<and>\n    consistent_sc_order (actions Xo) (mo Xw) (sc Xw) hb \\<and>\n    consistent_modification_order (actions Xo) (lk Xo) (sb Xo) (mo Xw) hb \\<and>\n    well_formed_reads_from_mapping (actions Xo) (lk Xo) (rf Xw) \\<and>\n    no_vsse_consistent_reads_from_mapping (actions Xo) (lk Xo) (sb Xo) (rf Xw) (sc Xw) (mo Xw) hb vse)))))))))\"\n\nfun los_single_sw_data_races' where\n\"los_single_sw_data_races' Xo Xw lo = \n    (case release_sequence_set (actions Xo) (lk Xo) (mo Xw) of rs \\<Rightarrow>\n      (case hypothetical_release_sequence_set (actions Xo) (lk Xo) (mo Xw) of hrs \\<Rightarrow>\n       (case lo_single_synchronizes_with_set (actions Xo) (sb Xo) (asw Xo) (rf Xw) lo rs hrs of sw \\<Rightarrow>\n        (case carries_a_dependency_to_set (actions Xo) (sb Xo) (dd Xo) (rf Xw) of cad \\<Rightarrow>\n         (case dependency_ordered_before_set (actions Xo) (rf Xw) rs cad of dob \\<Rightarrow> \n          (case inter_thread_happens_before (sb Xo) sw dob of ithb \\<Rightarrow>\n           (case happens_before (actions Xo) (sb Xo) ithb of hb \\<Rightarrow> \n      data_races (actions Xo) hb)))))))\"\n\nfun no_vsse_multi_lo_single_sw_undefined_behaviour where\n\"no_vsse_multi_lo_single_sw_undefined_behaviour Xo Xw lo = \n   (\\<not> (los_single_sw_data_races' Xo Xw lo = {}) \\<or>\n  \\<not>  (unsequenced_races (actions Xo) (sb Xo) = {}) \\<or>\n  \\<not>  (indeterminate_reads (actions Xo) (rf Xw) = {}) \\<or>\n  \\<not>  (bad_mutexes Xo lo = {}))\"\n\n(*   - 7.1  - single step mutex synchronisation top level judgement *)\ndefinition no_vsse_multi_lo_single_sw_cmm where\n\"no_vsse_multi_lo_single_sw_cmm opsem p = \n   (case { (Xopsem,(Xwitness,lo)).\n      opsem p Xopsem \\<and> no_vsse_multi_lo_single_sw_consistent_execution Xopsem Xwitness lo}\n       of pre_executions \\<Rightarrow>\n       if (\\<exists> (Xo,(Xw,lo)) \\<in> pre_executions . no_vsse_multi_lo_single_sw_undefined_behaviour Xo Xw lo)\n        then { (Xo,(Xw,lo)) . True } else pre_executions)\"\n\n(* 8 - Model simplified for programs without consumes *)\n(* This model is simplified for use with programs that don't use\n   consume memory orders. Happens-before is transitive. *)\n\nfun no_vsse_consume_happens_before where\n\"no_vsse_consume_happens_before sb' sw = tc (sb' \\<union> sw)\"\n\nfun no_vsse_consume_consistent_happens_before where\n\"no_vsse_consume_consistent_happens_before as hb = irrefl as hb\"\n\nfun no_vsse_consume_consistent_execution where\n\"no_vsse_consume_consistent_execution Xo Xw = \n   (well_formed_threads (actions Xo) (threads Xo) (lk Xo) (sb Xo) (asw Xo) (dd Xo) (cd Xo) \\<and>\n     (case release_sequence_set (actions Xo) (lk Xo) (mo Xw) of rs \\<Rightarrow>\n      (case hypothetical_release_sequence_set (actions Xo) (lk Xo) (mo Xw) of hrs \\<Rightarrow>\n       (case synchronizes_with_set (actions Xo) (sb Xo) (asw Xo) (rf Xw) (sc Xw) rs hrs of sw \\<Rightarrow>\n           (case no_vsse_consume_happens_before (sb Xo) sw of hb \\<Rightarrow> \n            (case visible_side_effect_set (actions Xo) hb of vse \\<Rightarrow>\n    consistent_locks (actions Xo) (sc Xw) hb \\<and>\n    no_vsse_consume_consistent_happens_before (actions Xo) hb \\<and>\n    consistent_sc_order (actions Xo) (mo Xw) (sc Xw) hb \\<and>\n    consistent_modification_order (actions Xo) (lk Xo) (sb Xo) (mo Xw) hb \\<and>\n    well_formed_reads_from_mapping (actions Xo) (lk Xo) (rf Xw) \\<and>\n    no_vsse_consistent_reads_from_mapping (actions Xo) (lk Xo) (sb Xo) (rf Xw) (sc Xw) (mo Xw) hb vse))))))\"\n\nfun no_vsse_consume_data_races' where\n\"no_vsse_consume_data_races' Xo Xw lo = \n    (case release_sequence_set (actions Xo) (lk Xo) (mo Xw) of rs \\<Rightarrow>\n      (case hypothetical_release_sequence_set (actions Xo) (lk Xo) (mo Xw) of hrs \\<Rightarrow>\n       (case synchronizes_with_set (actions Xo) (sb Xo) (asw Xo) (rf Xw) lo rs hrs of sw \\<Rightarrow>\n          (case no_vsse_consume_happens_before (sb Xo) sw of hb \\<Rightarrow>\n      data_races (actions Xo) hb))))\"\n\nfun no_vsse_consume_undefined_behaviour where\n\"no_vsse_consume_undefined_behaviour Xo Xw = \n  (\\<not> (no_vsse_consume_data_races' Xo Xw (sc Xw) = {}) \\<or>\n  \\<not> (unsequenced_races   (actions Xo) (sb Xo)  = {}) \\<or>\n  \\<not> (indeterminate_reads (actions Xo) (rf Xw) = {}) \\<or>\n  \\<not> (bad_mutexes Xo (sc Xw) = {}))\"\n\n(*   - 8.1  - No consume top level judgement *)\ndefinition no_vsse_consume_cmm where\n\"no_vsse_consume_cmm opsem p = \n   (case { (Xopsem,Xwitness).\n      opsem p Xopsem \\<and> no_vsse_consume_consistent_execution Xopsem Xwitness}\n       of pre_executions \\<Rightarrow>\n       if (\\<exists> (Xo,Xw) \\<in> pre_executions . no_vsse_consume_undefined_behaviour Xo Xw)\n        then { (Xo,Xw) . True } else pre_executions)\"\n\n(* 9 - Model simplified for programs without consumes or relaxed *)\n(* Without relaxed, can release sequences go? Unfortunately not. This model is NOT equvalent. *)\nfun no_vsse_consume_relaxed_synchronizes_with where\n\"no_vsse_consume_relaxed_synchronizes_with as sb' asw' rf' lo a b = \n   ((a,b) \\<in> asw' \\<or>\n    ( same_location a b \\<and> a \\<in> as \\<and> b \\<in> as \\<and>\n      ((is_unlock a \\<and> is_lock b \\<and> (a,b) \\<in> lo) \\<or>\n        ( is_release a \\<and> is_acquire b \\<and> \\<not> (same_thread a b) \\<and> (a,b) \\<in> rf' ) ) ))\"\n\nfun no_vsse_consume_relaxed_synchronizes_with_set where\n\"no_vsse_consume_relaxed_synchronizes_with_set as sb' asw' rf' lo =\n  {(a,b) . a \\<in> as \\<and> b \\<in> as \\<and> no_vsse_consume_relaxed_synchronizes_with as sb' asw' rf' lo a b}\"\n\nfun no_vsse_consume_relaxed_consistent_execution where\n\"no_vsse_consume_relaxed_consistent_execution Xo Xw = \n   (well_formed_threads (actions Xo) (threads Xo) (lk Xo) (sb Xo) (asw Xo) (dd Xo) (cd Xo) \\<and>\n       (case no_vsse_consume_relaxed_synchronizes_with_set\n                  (actions Xo) (sb Xo) (asw Xo) (rf Xw) (sc Xw) of sw \\<Rightarrow>\n           (case no_vsse_consume_happens_before (sb Xo) sw of hb \\<Rightarrow> \n            (case visible_side_effect_set (actions Xo) hb of vse \\<Rightarrow>\n    consistent_locks (actions Xo) (sc Xw) hb \\<and>\n    no_vsse_consume_consistent_happens_before (actions Xo) hb \\<and>\n    consistent_sc_order (actions Xo) (mo Xw) (sc Xw) hb \\<and>\n    consistent_modification_order (actions Xo) (lk Xo) (sb Xo) (mo Xw) hb \\<and>\n    well_formed_reads_from_mapping (actions Xo) (lk Xo) (rf Xw) \\<and>\n    no_vsse_consistent_reads_from_mapping (actions Xo) (lk Xo) (sb Xo) (rf Xw) (sc Xw) (mo Xw) hb vse))))\"\n\nfun no_vsse_consume_relaxed_data_races' where\n\"no_vsse_consume_relaxed_data_races' Xo Xw lo = \n       (case no_vsse_consume_relaxed_synchronizes_with_set\n                   (actions Xo) (sb Xo) (asw Xo) (rf Xw) lo of sw \\<Rightarrow>\n          (case no_vsse_consume_happens_before (sb Xo) sw of hb \\<Rightarrow>\n      data_races (actions Xo) hb))\"\n\nfun no_vsse_consume_relaxed_undefined_behaviour where\n\"no_vsse_consume_relaxed_undefined_behaviour Xo Xw = \n  (\\<not> (no_vsse_consume_relaxed_data_races' Xo Xw (sc Xw) = {}) \\<or>\n  \\<not> (unsequenced_races   (actions Xo) (sb Xo)  = {}) \\<or>\n  \\<not> (indeterminate_reads (actions Xo) (rf Xw) = {}) \\<or>\n  \\<not> (bad_mutexes Xo (sc Xw) = {}))\"\n\n(*   - 9.1  - No consume or relaxed top level judgement *)\ndefinition no_vsse_consume_relaxed_cmm where\n\"no_vsse_consume_relaxed_cmm opsem p = \n   (case { (Xopsem,Xwitness).\n      opsem p Xopsem \\<and> no_vsse_consume_relaxed_consistent_execution Xopsem Xwitness}\n       of pre_executions \\<Rightarrow>\n       if (\\<exists> (Xo,Xw) \\<in> pre_executions . no_vsse_consume_relaxed_undefined_behaviour Xo Xw)\n        then { (Xo,Xw) . True } else pre_executions)\"\n\n(* 10 - Model simplified for programs without consumes, relaxed, acquires or releases *)\nfun consistent_total_order where\n\"consistent_total_order as sb' asw' tot = \n   (strict_total_order_over as tot \\<and> (sb' \\<subseteq> tot) \\<and> (asw' \\<subseteq> tot))\"\n\nfun tot_consistent_reads_from_mapping where\n\"tot_consistent_reads_from_mapping as lk' rf' tot = \n  (\\<forall> b \\<in> as .\n    (is_read b) \\<longrightarrow>\n     (case { a . a \\<in> as \\<and> (same_location a b) \\<and> is_write a} of writes_at_same_location \\<Rightarrow>\n       if (\\<exists> a \\<in> as .adjacent_less_than \n              (restrict_relation_set tot (writes_at_same_location \\<union> {b})) as a b)\n       then (\\<exists> a \\<in> as .\n          ((a,b) \\<in> rf') \\<and>\n          adjacent_less_than (restrict_relation_set tot (writes_at_same_location \\<union> {b})) as a b)\n       else \\<not> (\\<exists> a \\<in> as . (a,b) \\<in> rf')))\"\n\nfun tot_consistent_execution where\n\"tot_consistent_execution Xo rf' tot = \n   (case restrict_relation_set tot { a . a \\<in> actions Xo \\<and> (is_lock a \\<or> is_unlock a)} of lo \\<Rightarrow> \n      well_formed_threads (actions Xo) (threads Xo) (lk Xo) (sb Xo) (asw Xo) (dd Xo) (cd Xo)\n     \\<and>  consistent_total_order (actions Xo) (sb Xo) (asw Xo) tot\n     \\<and> consistent_locks (actions Xo) lo tot\n     \\<and> tot_consistent_reads_from_mapping (actions Xo) (lk Xo) rf' tot\n     \\<and> well_formed_reads_from_mapping (actions Xo) (lk Xo) rf')\"\n\nfun tot_hb_data_races where\n\"tot_hb_data_races Xo rf' tot =\n   (case tot \\<inter> {(a,b) . a \\<in> (actions Xo) \\<and> b \\<in> (actions Xo) \\<and> is_seq_cst a \\<and>is_seq_cst b} of sc' \\<Rightarrow>\n    (case tot \\<inter> {(a,b) . a \\<in> (actions Xo) \\<and> b \\<in> (actions Xo) \\<and>\n                    (same_location a b) \\<and> is_write a \\<and> is_write b} of mo' \\<Rightarrow>\n     (case no_vsse_consume_relaxed_synchronizes_with_set (actions Xo) (sb Xo) (asw Xo) rf' tot of sw' \\<Rightarrow>\n     (case no_vsse_consume_happens_before (sb Xo) sw' of hb \\<Rightarrow>\n        data_races (actions Xo) hb))))\"\n\nfun tot_data_races where\n\"tot_data_races as tot = \n  { (a,b) . a \\<in> as \\<and> b \\<in> as \\<and>\n       \\<not> (a = b) \\<and> same_location a b \\<and> (is_write a \\<or> is_write b) \\<and>\n        \\<not> (same_thread a b) \\<and>\n        \\<not> (is_atomic_action a \\<and> is_atomic_action b) \\<and>\n        (adjacent_less_than tot as a b \\<or> adjacent_less_than tot as b a) }\"\n\nfun tot_undefined_behaviour where\n\"tot_undefined_behaviour Xo rf' tot = \n  (\\<not> (tot_hb_data_races Xo rf' tot = {}) \\<or>\n  \\<not> (unsequenced_races   (actions Xo) (sb Xo)  = {}) \\<or>\n  \\<not> (indeterminate_reads (actions Xo) rf' = {}) \\<or>\n  \\<not> (bad_mutexes Xo tot = {}))\"\n\n(*   - 10.1  - No consume, relaxed, acquire or release top level judgement *)\ndefinition tot_cmm where\n\"tot_cmm opsem p = \n   (case { (Xopsem,(rf,tot)).\n      opsem p Xopsem \\<and> tot_consistent_execution Xopsem rf tot}\n       of pre_executions \\<Rightarrow>\n       if (\\<exists> (Xo,(rf,tot)) \\<in> pre_executions . tot_undefined_behaviour Xo rf tot)\n        then { (Xo,(rf,tot)) . True } else pre_executions)\"\n\n\n\nend", "meta": {"author": "liyili2", "repo": "timed-relaxed-memory-model", "sha": "6d85bc75d8b04228b3e581b945e3f672395f0c66", "save_path": "github-repos/isabelle/liyili2-timed-relaxed-memory-model", "path": "github-repos/isabelle/liyili2-timed-relaxed-memory-model/timed-relaxed-memory-model-6d85bc75d8b04228b3e581b945e3f672395f0c66/SC11.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6859494550081925, "lm_q2_score": 0.3665897432423098, "lm_q1q2_score": 0.2514620345886556}}
{"text": "(*  Title:      HOL/Auth/n_mutualExOnI_lemma_inv__3_on_rules.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mutualExOnI Protocol Case Study*} \n\ntheory n_mutualExOnI_lemma_inv__3_on_rules imports n_mutualExOnI_lemma_on_inv__3\nbegin\nsection{*All lemmas on causal relation between inv__3*}\nlemma lemma_inv__3_on_rules:\n  assumes b1: \"r \\<in> rules N\" and b2: \"(\\<exists> p__Inv0 p__Inv1. p__Inv0\\<le>N\\<and>p__Inv1\\<le>N\\<and>p__Inv0~=p__Inv1\\<and>f=inv__3  p__Inv0 p__Inv1)\"\n  shows \"invHoldForRule s f r (invariants N)\"\n  proof -\n  have c1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\\<or>\n    (\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n  apply (cut_tac b1, auto) done\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Try  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_TryVsinv__3) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Crit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_CritVsinv__3) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Exit  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_ExitVsinv__3) done\n    }\n\n    moreover {\n      assume d1: \"(\\<exists> i. i\\<le>N\\<and>r=n_Idle  i)\"\n      have \"invHoldForRule s f r (invariants N)\"\n      apply (cut_tac b2 d1, metis n_IdleVsinv__3) done\n    }\n\n  ultimately show \"invHoldForRule s f r (invariants N)\"\n  by satx\nqed\n\nend\n", "meta": {"author": "lyj238Gmail", "repo": "newParaVerifier", "sha": "5c2d49bf8e6c46c60efa53c98b0ba5c577d59618", "save_path": "github-repos/isabelle/lyj238Gmail-newParaVerifier", "path": "github-repos/isabelle/lyj238Gmail-newParaVerifier/newParaVerifier-5c2d49bf8e6c46c60efa53c98b0ba5c577d59618/examples/n_mutualExOnI/n_mutualExOnI_lemma_inv__3_on_rules.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.679178699175393, "lm_q2_score": 0.37022540649291935, "lm_q1q2_score": 0.25144920998354203}}
{"text": "theory TypeTheorems imports gASPFuturesTypeSystem begin\n\nsection{* Induction lemmas *}\nlemma TypeValue_induct_Config:\n\"P,Cn aos futs\\<turnstile>\\<^sub>V v:T \n\\<Longrightarrow> (\\<And>P aos futs n. Prop  P aos futs (ASPInt n) (BType Integer))\n\\<Longrightarrow> (\\<And>P aos futs b. Prop P aos futs (ASPBool b) (BType Boolean))\n\\<Longrightarrow> (\\<And>P aos futs. Prop P aos futs  null (BType AnyObject))\n\\<Longrightarrow> (\\<And> Acts Futs \\<alpha> C' state R Ec Rq P.  (Acts \\<alpha> = Some (AO C' state R Ec Rq) \\<Longrightarrow> Prop P Acts Futs (ActRef \\<alpha>) (BType (TObj C'))))\n\\<Longrightarrow> (\\<And> Acts Futs f T V P. Futs f = Some (T, V) \\<Longrightarrow> Prop P  Acts Futs (FutRef f) (FutType T)) \n\\<Longrightarrow> (\\<And> Acts Futs f T V P. Prop P  Acts Futs (undefined) (FutType AnyObject)) \n\\<Longrightarrow> (\\<And>P T T' aos futs v.  P\\<turnstile>T\\<sqsubseteq>T' \\<Longrightarrow> P,Cn aos futs\\<turnstile>\\<^sub>Vv:T \\<Longrightarrow> Prop P aos futs v T \\<Longrightarrow> Prop P aos futs v T')\n\\<Longrightarrow>Prop P aos futs  v T\"\napply (insert gASPFuturesTypeSystem.TypeValue.induct [of  P \"Cn aos futs\"  v T  \"\\<lambda> x conf y . (Prop x (Conf_AOs conf) (Conf_futs conf) y )\" ])\napply auto\napply (drule meta_impE,auto)\napply(case_tac Config,auto)\ndone\n\nlemma TypeExpression_induct_Config:\n\"P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>Ee:T \\<Longrightarrow>\n    (\\<And>P aos futs \\<Gamma> C v T. P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>Av:T \\<Longrightarrow> Prop P aos futs \\<Gamma> C (At v) T) \\<Longrightarrow>\n    (\\<And>P aos futs \\<Gamma> C e e'. P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>Ae:BType Integer \\<Longrightarrow> P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>Ae':BType Integer \\<Longrightarrow> Prop P aos futs \\<Gamma> C (e+\\<^sub>Ae') (BType Integer)) \\<Longrightarrow> \n    (\\<And>P T T' aos futs \\<Gamma> C e.  P\\<turnstile>T\\<sqsubseteq>T' \\<Longrightarrow> P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>Ee:T \\<Longrightarrow> Prop P aos futs \\<Gamma> C e T \\<Longrightarrow>Prop P  aos futs \\<Gamma> C e T') \n          \\<Longrightarrow> Prop P aos futs  \\<Gamma> C e T\"\napply (insert gASPFuturesTypeSystem.TypeExpression.induct [of  P \"Cn aos futs\" \\<Gamma> C e T  \"\\<lambda> x conf y z t. (Prop x (Conf_AOs conf) (Conf_futs conf) y z t)\" ])\napply clarsimp\n apply (drule meta_impE,auto,case_tac Config,auto)+\ndone\n\nlemma TypeAtom_induct_Config:\n\"P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>Ae:T \\<Longrightarrow>\n    (\\<And>P aos futs \\<Gamma> C v T. P,Cn aos futs\\<turnstile>\\<^sub>Vv:T \\<Longrightarrow> Prop P aos futs \\<Gamma> C (Val v) T) \\<Longrightarrow>\n    (\\<And>P aos futs \\<Gamma> C. Prop P aos futs \\<Gamma> C (Var This) (BType (TObj C))) \\<Longrightarrow> \n    (\\<And>P T T' aos futs \\<Gamma> C x.   \\<Gamma> x = Some T  \\<Longrightarrow> Prop P  aos futs \\<Gamma> C (Var (VarOrThis.Id x)) T) \\<Longrightarrow>\n     (\\<And>P T T' aos futs \\<Gamma> C e.  P\\<turnstile>T\\<sqsubseteq>T' \\<Longrightarrow> P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>Ae:T \\<Longrightarrow> Prop P aos futs \\<Gamma> C e T \\<Longrightarrow>Prop P  aos futs \\<Gamma> C e T')\n          \\<Longrightarrow> Prop P aos futs  \\<Gamma> C e T\"\napply (insert gASPFuturesTypeSystem.TypeAtom.induct [of  P \"Cn aos futs\" \\<Gamma> C e T  \"\\<lambda> x conf y z t. (Prop x (Conf_AOs conf) (Conf_futs conf) y z t)\" ])\napply clarsimp\n apply (drule meta_impE,auto,case_tac Config,auto)+\ndone\n\nlemma TypeStatement_TypeStatementList_induct_Config:\n\"  (\\<And>P aos futs \\<Gamma> C a T x T'. P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>Ra:T \\<Longrightarrow> \\<Gamma> x = Some T' \\<Longrightarrow>  P\\<turnstile>T\\<sqsubseteq>T' \\<Longrightarrow> P1 P aos futs \\<Gamma> C (x =\\<^sub>A a)) \\<Longrightarrow>\n    (\\<And>P C Class m Meth T' aos futs \\<Gamma> e T x. fetchClass P C = Some Class \\<Longrightarrow> fetchMethodInClass Class m = Some Meth \\<Longrightarrow> MRType Meth = T' \\<Longrightarrow> P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>Ee:T \\<Longrightarrow> \\<Gamma> x = Some T' \\<Longrightarrow>  P\\<turnstile>T\\<sqsubseteq>T' \\<Longrightarrow> P1 P aos futs \\<Gamma> C (return e)) \\<Longrightarrow>\n    (\\<And>P aos futs \\<Gamma> C z  sl sl'. P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>Az:BType Boolean \\<Longrightarrow> (P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>L sl)  \\<Longrightarrow> P2 P aos futs \\<Gamma> C sl \\<Longrightarrow> P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>L sl'  \\<Longrightarrow> P2 P aos futs \\<Gamma> C sl' \\<Longrightarrow> P1 P aos futs \\<Gamma> C (IF z THEN sl ELSE sl' )) \\<Longrightarrow>\n    (\\<And>P aos futs \\<Gamma> C. P2 P aos futs \\<Gamma> C []) \\<Longrightarrow>\n    (\\<And>P aos futs \\<Gamma> C s sl. P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>S s  \\<Longrightarrow> P1 P aos futs \\<Gamma> C s \\<Longrightarrow> P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>L sl  \\<Longrightarrow> P2 P aos futs \\<Gamma> C sl \\<Longrightarrow> P2 P aos futs \\<Gamma> C (s ;; sl)) \\<Longrightarrow>\n    ((P,Cn aos futs,\\<Gamma> in x4\\<turnstile>\\<^sub>S x5)  \\<longrightarrow> P1 P aos futs \\<Gamma> x4 x5) \\<and> ((P',Cn aos' futs',\\<Gamma>' in x9\\<turnstile>\\<^sub>L x10)  \\<longrightarrow> P2 P' aos' futs' \\<Gamma>'  x9 x10)\"\napply (insert gASPFuturesTypeSystem.TypeStatement_TypeStatementList.induct [of \"\\<lambda> x conf y z t. (P1 x (Conf_AOs conf) (Conf_futs conf) y z t)\" \"\\<lambda> x conf y z t. (P2 x (Conf_AOs conf) (Conf_futs conf) y z t)\" P \"Cn aos futs\" \\<Gamma> x4 x5 P' \"Cn aos' futs'\" \\<Gamma>' x9 x10])\napply rule\n apply (drule meta_impE,auto,case_tac Config,auto)+\ndone\n\nlemma TypeRhs_induct_Config:\n\"(P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>RR: T)\\<Longrightarrow>\n    (\\<And>P aos futs \\<Gamma> C e T. (P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>Ee:T) \\<Longrightarrow> P1 P aos futs \\<Gamma> C (Expr e) T) \\<Longrightarrow>\n    (\\<And>P aos futs \\<Gamma> C z C' Class m Meth param_types el.\n        (P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>Az:BType (TObj C')) \\<Longrightarrow>\n        fetchClass P C' = Some Class \\<Longrightarrow> fetchMethodInClass Class m = Some Meth \\<Longrightarrow> param_types = map fst (MParams Meth) \\<Longrightarrow> length param_types = length el \\<Longrightarrow> \\<forall>i<length el. (P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>Eel ! i:param_types ! i) \n                  \\<Longrightarrow> P1 P  aos futs \\<Gamma> C (z.\\<^sub>Am(el)) (MakeFutureType (MRType Meth))) \\<Longrightarrow>\n    (\\<And>P C' Class Class_param_types el aos futs \\<Gamma> C. fetchClass P C' = Some Class \\<Longrightarrow> Class_param_types = map fst (ClassParameters Class) \\<Longrightarrow> length Class_param_types = length el \n                  \\<Longrightarrow> \\<forall>i<length el. (P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>E(el ! i):(Class_param_types ! i)) \\<Longrightarrow> P1 P  aos futs \\<Gamma> C (newActive C'(el)) (BType (TObj C'))) \\<Longrightarrow>\n    (\\<And>P aos futs \\<Gamma> C z T. (P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>Az:FutType T) \\<Longrightarrow> P1 P  aos futs \\<Gamma> C (Get z) (BType T)) \\<Longrightarrow> (\\<And>P T T'  aos futs \\<Gamma> C e.  P\\<turnstile>T\\<sqsubseteq>T' \n                  \\<Longrightarrow> P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>Re:T \\<Longrightarrow> P1 P  aos futs \\<Gamma> C e T \\<Longrightarrow> P1 P aos futs \\<Gamma> C e T') \n\\<Longrightarrow> P1 P aos futs \\<Gamma> C R T\"\napply (insert TypeRhs.induct [of  P \"Cn aos futs\" \\<Gamma> C R T \"\\<lambda> x conf y z t. (P1 x (Conf_AOs conf) (Conf_futs conf) y z t)\"])\napply auto\napply (drule meta_impE,auto,case_tac Config,auto)+\ndone\n\nsection{* Basic Lemmas *}\n\nlemma TypeStatementList_TypeStatement[rule_format]: \n\"(P,Config,\\<Gamma> in C \\<turnstile>\\<^sub>L Stl)  \\<longrightarrow> (S \\<in> set Stl\\<longrightarrow> (P,Config,\\<Gamma> in C \\<turnstile>\\<^sub>S S))\"\napply (induct_tac Stl)\n apply clarsimp+\napply (drule TypeStatementList.cases,auto)\ndone\n\nlemma fetchClass_Some_In[rule_format]:\n \"fetchClass (Prog CL Vars Stl) C = Some CLa \\<Longrightarrow> CLa\\<in>set CL\"\nby (unfold fetchClass_def, rule find_Some,auto)\n\nlemma fetchClass_Some_Name[rule_format]:\n \"fetchClass (Prog CL Vars Stl) C = Some CLa \\<Longrightarrow> Name CLa=C\"\nby (unfold fetchClass_def,simp,drule find_Some_P,simp)\n\nlemma fetchMethodInClass_Some:\n \"fetchMethodInClass C m = Some M \\<Longrightarrow> M \\<in> set (Methods C)\"\nby (unfold fetchMethodInClass_def, rule find_Some,auto)\n\n\nsection{* extending set of AOs in config *}\n\nlemma TypeValue_extendconfiguration_AO[rule_format]:\n\"P,Cn AOs Futures\\<turnstile>\\<^sub>Vv:T \\<Longrightarrow> (case AOs \\<alpha> of Some (AO C' st' R' Ec' Rq') \\<Rightarrow> C=C' | None \\<Rightarrow> True) \n    \\<longrightarrow>(P,Cn  (AOs(\\<alpha>\\<mapsto> (AO C state R Ec Rq))) Futures\\<turnstile>\\<^sub>Vv:T)\"\napply (erule TypeValue_induct_Config,auto)\n      apply (rule  \"TypeValue.intros\" )\n     apply (rule  \"TypeValue.intros\" )\n    apply (rule  \"TypeValue.intros\" )\n   apply (case_tac \"\\<alpha>=\\<alpha>'\")\n    apply (rule TypeValue.intros,force)\n   apply (rule TypeValue.intros,force)\n  apply (rule TypeValue.intros,simp)\n apply (rule TypeValue.intros)\napply (rule TypeValue.intros,auto)\ndone\n\nlemma TypeValue_extendconfiguration_AO_lambda[rule_format]:\n\"P,Cn AOs Futures\\<turnstile>\\<^sub>Vv:T \\<Longrightarrow> (case AOs \\<alpha> of Some (AO C' st' R' Ec' Rq') \\<Rightarrow> C=C' | None \\<Rightarrow> True) \n    \\<Longrightarrow>(P,Cn ( (\\<lambda>a. if a = \\<alpha> then Some (AO C state R Ec Rq) else AOs a) ) Futures\\<turnstile>\\<^sub>Vv:T)\"\nby (insert TypeValue_extendconfiguration_AO,simp add: fun_upd_def)\n\nlemma TypeAtom_extendconfiguration_AO[rule_format]:\n\"P,Cn AOs futs,\\<Gamma> in C\\<turnstile>\\<^sub>Az:T \\<Longrightarrow> ((case AOs \\<alpha> of Some (AO C' st' R' Ec' Rq') \\<Rightarrow> C''=C' | None \\<Rightarrow> True) \\<longrightarrow> \n          ( P,Cn (\\<lambda>a. if a = \\<alpha> then Some (AO C'' state R Ec Rq) else AOs a)  futs ,\\<Gamma> in C\\<turnstile>\\<^sub>Az:T))\"\napply (erule  \"TypeAtom_induct_Config\",auto)\n    apply (rule  \"TypeValue.cases\",auto)\n        apply (rule  \"TypeAtom.intros\",(rule  TypeValue_extendconfiguration_AO_lambda)?,(auto)?)+\ndone\n\n\nlemma TypeExpression_extendconfiguration_AO[rule_format]:\n\"P,Cn AOs futs,\\<Gamma> in C\\<turnstile>\\<^sub>Ee:T \\<Longrightarrow> ((case AOs \\<alpha> of Some (AO C' st' R' Ec' Rq') \\<Rightarrow> C''=C' | None \\<Rightarrow> True) \\<longrightarrow> \n          ( P,Cn (\\<lambda>a. if a = \\<alpha> then Some (AO C'' state R Ec Rq) else AOs a)  futs ,\\<Gamma> in C\\<turnstile>\\<^sub>Ee:T))\"\napply (erule  \"TypeExpression_induct_Config\",auto)\n  apply (rule  \"TypeExpression.intros\",(auto)?)+\n  apply (rule  \"TypeAtom_extendconfiguration_AO\",auto)\n apply (rule  \"TypeExpression.intros\",(auto)?)+\n  apply (rule  \"TypeAtom_extendconfiguration_AO\",auto)\n apply (rule  \"TypeAtom_extendconfiguration_AO\",auto)\napply (rule  \"TypeExpression.intros\",auto)\ndone\n\nlemma TypeRhs_extendconfiguration_AO[rule_format]:\n\"P,Cn AOs futs,\\<Gamma> in C\\<turnstile>\\<^sub>Ra:T \\<Longrightarrow> ((case AOs \\<alpha> of Some (AO C' st' R' Ec' Rq') \\<Rightarrow> C''=C' | None \\<Rightarrow> True)\n  \\<longrightarrow>(P,Cn (\\<lambda>a. if a = \\<alpha> then Some (AO C'' state R Ec Rq) else AOs a) futs,\\<Gamma> in C\\<turnstile>\\<^sub>Ra:T))\"\napply (erule  \"TypeRhs_induct_Config\",auto)\n(*5*)\n    apply (rule  \"TypeRhs.intros\",(auto)?)\n    apply (erule TypeExpression_extendconfiguration_AO,auto)\n   apply (rule  \"TypeRhs.intros\",(auto)?)\n    apply (erule TypeAtom_extendconfiguration_AO,auto)\n   apply (rule_tac AOs=aos in TypeExpression_extendconfiguration_AO)\n     apply (drule_tac x=i in spec,auto)\n(*3*)\n  apply (rule  \"TypeRhs.intros\",(auto)?)\n  apply (rule_tac AOs=aos in TypeExpression_extendconfiguration_AO)\n    apply (drule_tac x=i in spec,auto)\n apply (rule  \"TypeRhs.intros\",(auto)?)\n apply (erule TypeAtom_extendconfiguration_AO,force)\napply (rule  \"TypeRhs.intros\",(auto)?)\ndone\n\n\nlemma TypeStatement_extendconfiguration_AO_Pre[rule_format]:\n\" ((P,Cn AOs futs,\\<Gamma> in C \\<turnstile>\\<^sub>S S) \\<longrightarrow> (\\<forall> \\<alpha> X. (case AOs \\<alpha> of Some (AO C' st' R' Ec' Rq') \\<Rightarrow> C''=C' | None \\<Rightarrow> True)\n                    \\<longrightarrow> (P, Cn (AOs(\\<alpha>\\<mapsto>(AO C'' state R Ec Rq))) futs,\\<Gamma> in C \\<turnstile>\\<^sub>S S))) \\<and> \n  ((P, Cn AOs futs,\\<Gamma> in C \\<turnstile>\\<^sub>L Stl) \\<longrightarrow> (\\<forall> \\<alpha> X. (case AOs \\<alpha> of Some (AO C' st' R' Ec' Rq') \\<Rightarrow> C''=C' | None \\<Rightarrow> True)\n                    \\<longrightarrow> (P, Cn (AOs(\\<alpha>\\<mapsto>(AO C'' state R Ec Rq))) futs,\\<Gamma> in C \\<turnstile>\\<^sub>L Stl)))\"\napply (rule TypeStatement_TypeStatementList_induct_Config,auto)\n(*5*)\n    apply (rule  \"TypeStatement_TypeStatementList.intros\",auto)\n    apply (erule_tac AOs=aos in TypeRhs_extendconfiguration_AO,auto)\n   apply (rule \"TypeStatement_TypeStatementList.intros\",force,auto)\n   apply (erule_tac AOs=aos in TypeExpression_extendconfiguration_AO,auto)\n  apply (rule  \"TypeStatement_TypeStatementList.intros\")\n(*5*)\n    apply (erule_tac AOs=aos in TypeAtom_extendconfiguration_AO,auto)\n apply (rule  \"TypeStatement_TypeStatementList.intros\")\napply (rule  \"TypeStatement_TypeStatementList.intros\")\n apply auto\ndone\n\nlemma TypeRequest_extendconfiguration_AO[rule_format]:\n\"P,Cn AOs futs in C\\<turnstile>\\<^sub>Q (f,m,vl) \\<Longrightarrow> ((case AOs \\<alpha> of Some (AO C' st' R' Ec' Rq') \\<Rightarrow> C''=C' | None \\<Rightarrow> True)\n  \\<longrightarrow>(P,Cn (\\<lambda>a. if a = \\<alpha> then Some (AO C'' state R Ec Rq) else AOs a) futs in C\\<turnstile>\\<^sub>Q (f,m,vl)))\"\napply (erule TypeRequest.cases,auto)\napply (rule TypeRequest.intros,auto)\napply (drule_tac x=i in spec)\napply clarsimp\napply (rule_tac TypeValue_extendconfiguration_AO_lambda)\napply auto\ndone\n\n(* GLOBAL LEMMAS *)\nlemma TypeStatement_extendconfiguration_AO:\n\" (P,Cn AOs futs,\\<Gamma> in C \\<turnstile>\\<^sub>S S) \\<Longrightarrow>(case AOs \\<alpha> of Some (AO C' st' R' Ec' Rq') \\<Rightarrow> C''=C' | None \\<Rightarrow> True) \n          \\<Longrightarrow>P, Cn (AOs(\\<alpha>\\<mapsto>(AO C'' state R Ec Rq))) futs,\\<Gamma> in C \\<turnstile>\\<^sub>S S\"\nby (insert TypeStatement_extendconfiguration_AO_Pre, auto)\n\nlemma TypeStatementList_extendconfiguration_AO:\n\" (P,Cn AOs futs,\\<Gamma> in C \\<turnstile>\\<^sub>L Stl) \\<Longrightarrow>(case AOs \\<alpha> of Some (AO C' st' R' Ec' Rq') \\<Rightarrow> C''=C' | None \\<Rightarrow> True) \n          \\<Longrightarrow>P, Cn (AOs(\\<alpha>\\<mapsto>(AO C'' state R Ec Rq))) futs,\\<Gamma> in C \\<turnstile>\\<^sub>L Stl\"\nby (insert TypeStatement_extendconfiguration_AO_Pre, auto)\n\nsection{* extending set of futs in config *}\n\nlemma TypeValue_extendconfiguration_futs[rule_format]:\n\"P,Cn AOs futs\\<turnstile>\\<^sub>Vv:T \\<Longrightarrow>(futs f = None\\<longrightarrow>(P,Cn  AOs  (futs(f\\<mapsto>a))\\<turnstile>\\<^sub>Vv:T))\"\napply (erule TypeValue_induct_Config,auto)\n    apply (rule TypeValue.intros,auto?)+\ndone\nlemma TypeValue_extendconfiguration_futs_lambda[rule_format]:\n\"P,Cn AOs futs\\<turnstile>\\<^sub>Vv:T \\<Longrightarrow>futs f = None\\<Longrightarrow>(P,Cn  AOs  (\\<lambda>a. if a = f then Some Y else futs a)\\<turnstile>\\<^sub>Vv:T)\"\nby (insert TypeValue_extendconfiguration_futs,simp add: fun_upd_def)\n\n\nlemma TypeAtom_extendconfiguration_futs[rule_format]:\n\"P,Cn AOs futs,\\<Gamma> in C\\<turnstile>\\<^sub>Az:T \\<Longrightarrow> futs f = None\\<longrightarrow>( P,Cn AOs (\\<lambda>a. if a = f then Some Y else futs a),\\<Gamma> in C\\<turnstile>\\<^sub>Az:T)\"\napply (erule  \"TypeAtom_induct_Config\",auto)\n    apply (rule  \"TypeValue.cases\",auto)\n        apply (rule  \"TypeAtom.intros\",(rule  TypeValue_extendconfiguration_futs_lambda)?,(auto)?)+\ndone\n\nlemma TypeExpression_extendconfiguration_futs[rule_format]:\n\"P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>Ee:T \\<Longrightarrow> futs f = None\\<longrightarrow>( P,Cn aos (\\<lambda>a. if a = f then Some Y else futs a),\\<Gamma> in C\\<turnstile>\\<^sub>Ee:T)\"\napply (erule  \"TypeExpression_induct_Config\",auto)\n  apply (rule  \"TypeExpression.intros\",(auto)?)+\n  apply (rule  \"TypeAtom_extendconfiguration_futs\",auto)\n apply (rule  \"TypeExpression.intros\",(auto)?)+\n  apply (rule  \"TypeAtom_extendconfiguration_futs\",auto)\n apply (rule  \"TypeAtom_extendconfiguration_futs\",auto)\napply (rule  \"TypeExpression.intros\",auto)\ndone\n\n\nlemma TypeRhs_extendconfiguration_futs[rule_format]:\n\"P,Cn aos futs,\\<Gamma> in C\\<turnstile>\\<^sub>Ra:T \\<Longrightarrow> (futs f = None\\<longrightarrow>(P,Cn aos (\\<lambda>a. if a = f then Some Y else futs a),\\<Gamma> in C\\<turnstile>\\<^sub>Ra:T))\"\napply (erule  \"TypeRhs_induct_Config\",auto)\n(*5*)\n    apply (rule  \"TypeRhs.intros\",(auto)?)\n    apply (erule TypeExpression_extendconfiguration_futs,auto)\n   apply (rule  \"TypeRhs.intros\",(auto)?)\n    apply (erule TypeAtom_extendconfiguration_futs,auto)\n   apply (rule_tac aos=aos in TypeExpression_extendconfiguration_futs)\n     apply (drule_tac x=i in spec,auto)\n(*3*)\n  apply (rule  \"TypeRhs.intros\",(auto)?)\n  apply (rule_tac aos=aos in TypeExpression_extendconfiguration_futs)\n    apply (drule_tac x=i in spec,auto)\n apply (rule  \"TypeRhs.intros\",(auto)?)\n apply (erule TypeAtom_extendconfiguration_futs,force)\napply (rule  \"TypeRhs.intros\",(auto)?)\ndone\n\nlemma TypeStatement_extendconfiguration_futs_Pre[rule_format]:\n\" ((P,Cn AOs futs,\\<Gamma> in C \\<turnstile>\\<^sub>S S) \\<longrightarrow> (\\<forall> f Y. f\\<notin>(dom futs)\\<longrightarrow> (P, Cn AOs (futs(f\\<mapsto>Y)),\\<Gamma> in C \\<turnstile>\\<^sub>S S))) \\<and> \n  ((P, Cn AOs futs,\\<Gamma> in C \\<turnstile>\\<^sub>L Stl) \\<longrightarrow> (\\<forall> f Y. f\\<notin>(dom futs)\\<longrightarrow> (P, Cn AOs (futs(f\\<mapsto>Y)),\\<Gamma> in C \\<turnstile>\\<^sub>L Stl)))\"\napply (rule TypeStatement_TypeStatementList_induct_Config,auto)\n(*5*)\n    apply (rule  \"TypeStatement_TypeStatementList.intros\",auto)\n    apply (erule TypeRhs_extendconfiguration_futs,auto)\n    apply (rotate_tac -1,erule contrapos_pp,force)  \n   apply (rule  \"TypeStatement_TypeStatementList.intros\",auto)\n   apply (erule TypeExpression_extendconfiguration_futs,auto)\n    apply (rotate_tac -1,erule contrapos_pp,force)  \n  apply (rule  \"TypeStatement_TypeStatementList.intros\")\n(*5*)\n    apply (erule TypeAtom_extendconfiguration_futs,auto)\n    apply (rotate_tac -1,erule contrapos_pp,force)\n   apply (drule_tac x=f in spec,auto)+\n apply (rule  \"TypeStatement_TypeStatementList.intros\")\napply (rule  \"TypeStatement_TypeStatementList.intros\")\n apply (drule_tac x=f in spec,auto)+\ndone\n\nlemma TypeRequest_extendconfiguration_futs[rule_format]:\n\"P,Cn AOs futs in C\\<turnstile>\\<^sub>Q (f,m,vl) \\<Longrightarrow> (futs f = None\n  \\<longrightarrow>(P,Cn AOs (\\<lambda>a. if a = f then Some Y else futs a) in C\\<turnstile>\\<^sub>Q (f,m,vl)))\"\nby (erule TypeRequest.cases,auto)\n\n\n(* GLOBAL LEMMAS *)\nlemma TypeStatement_extendconfiguration_futs:\n\" (P,Cn AOs futs,\\<Gamma> in C \\<turnstile>\\<^sub>S S) \\<Longrightarrow>f\\<notin>(dom futs) \\<Longrightarrow>P, Cn AOs (futs(f\\<mapsto>Y)),\\<Gamma> in C \\<turnstile>\\<^sub>S S\"\nby (insert TypeStatement_extendconfiguration_futs_Pre,case_tac Y, simp)\n\nlemma TypeStatementList_extendconfiguration_futs:\n\" (P,Cn AOs futs,\\<Gamma> in C \\<turnstile>\\<^sub>L Stl) \\<Longrightarrow>f\\<notin>(dom futs) \\<Longrightarrow>P, Cn AOs (futs(f\\<mapsto>Y)),\\<Gamma> in C \\<turnstile>\\<^sub>L Stl\"\nby (insert TypeStatement_extendconfiguration_futs_Pre,case_tac Y, simp)\n\n\nsection {* extend AOs and futs *}\nlemma TypeStatement_extendconfiguration:\n\" (P,Cn AOs futs,\\<Gamma> in C \\<turnstile>\\<^sub>S S) \\<Longrightarrow>(case AOs \\<alpha> of Some (AO C' st' R' Ec' Rq') \\<Rightarrow> C''=C' | None \\<Rightarrow> True) \\<Longrightarrow>f\\<notin>(dom futs) \n                \\<Longrightarrow>P, Cn (AOs(\\<alpha>\\<mapsto>(AO C'' state R Ec Rq))) (futs(f\\<mapsto>Y)),\\<Gamma> in C \\<turnstile>\\<^sub>S S\"\nby (insert TypeStatement_extendconfiguration_futs,insert TypeStatement_extendconfiguration_AO, auto)\n\nlemma TypeStatementList_extendconfiguration:\n\" (P,Cn AOs futs,\\<Gamma> in C \\<turnstile>\\<^sub>L Stl) \\<Longrightarrow>(case AOs \\<alpha> of Some (AO C' st' R' Ec' Rq') \\<Rightarrow> C''=C' | None \\<Rightarrow> True) \n                 \\<Longrightarrow>f\\<notin>(dom futs) \\<Longrightarrow>P, Cn (AOs(\\<alpha>\\<mapsto>(AO C'' state R Ec Rq))) (futs(f\\<mapsto>Y)),\\<Gamma> in C \\<turnstile>\\<^sub>L Stl\"\nby (insert TypeStatementList_extendconfiguration_futs,insert TypeStatementList_extendconfiguration_AO, auto)\n\nsection {* compositional lemmas for WT *}\n\nlemma TypeUpdate_AO:  \"P \\<turnstile> Cn AOs Futures  \\<Longrightarrow>\n  (case AOs \\<alpha> of Some (AO C' st' R' Ec' Rq') \\<Rightarrow> C=C' | None \\<Rightarrow> True) \\<Longrightarrow>\n   (\\<exists> CL . (fetchClass P C = Some CL \\<and>\n    (\n     (* check state *)\n     ( (  \\<forall> x v. (state(x) =Some  v \\<longrightarrow> (\\<exists> T . (T,x)\\<in> set (ClassParameters CL) \\<and> (P,Cn (AOs(\\<alpha> \\<mapsto> AO C state R Ec Rq)) Futures\\<turnstile>\\<^sub>V v: T))) ) )\n     (* check request queue*)\n     \\<and> (\\<forall> R'\\<in>set Rq. (P, (Cn (AOs(\\<alpha> \\<mapsto> AO C state R Ec Rq)) Futures) in C \\<turnstile>\\<^sub>Q R' ) )\n     (* check current request*)\n     \\<and> \n     (case R of Some  (f,m,vl) \\<Rightarrow>\n         (\\<exists> Meth. fetchMethodInClass CL m = Some Meth \\<and>\n           (P, Cn (AOs(\\<alpha> \\<mapsto> AO C state R Ec Rq)) Futures in C \\<turnstile>\\<^sub>Q (f,m,vl)) \n           \\<and> (case Ec of (locs,Stl) \\<Rightarrow>  ((  \\<forall> x v. (locs(x) =Some  v \\<longrightarrow> ( (\\<exists> T . (T,x)\\<in> set (LocalVariables Meth) \\<and> (P,Cn (AOs(\\<alpha> \\<mapsto> AO C state R Ec Rq)) Futures\\<turnstile>\\<^sub>V v: T))\n                                            \\<or>(\\<exists> T . (T,x)\\<in> set (MParams Meth) \\<and> (P,Cn (AOs(\\<alpha> \\<mapsto> AO C state R Ec Rq)) Futures\\<turnstile>\\<^sub>V v: T))) )))\n                                    \\<and> ( \\<forall> s\\<in>set Stl. \n             (P,Cn (AOs(\\<alpha> \\<mapsto> AO C state R Ec Rq)) Futures,(BuildTypeEnv (ClassParameters CL))++(BuildTypeEnv (LocalVariables Meth))++(BuildTypeEnv (MParams Meth)) in C \\<turnstile>\\<^sub>S s)\n        )) ) ) )))\n\\<Longrightarrow> P \\<turnstile> Cn (AOs(\\<alpha> \\<mapsto> AO C state R Ec Rq)) Futures \"\napply (clarsimp,auto)\n apply (clarsimp simp: ran_def)\n apply (case_tac \"a = \\<alpha>\",clarsimp)\n(*activity not alpha *)\n apply clarsimp\n apply (case_tac Act,clarsimp)\n apply (drule_tac x= \"(AO x1 x2 x3 (aa, b) x5)\" in spec)\n apply clarsimp\n apply (erule impE,force)\n apply clarsimp\n apply (intro allI conjI)\n(*4*)\n   apply clarsimp\n   apply (drule_tac x=x in spec)+\n   apply (drule_tac x=v in spec)+\n   apply clarsimp\n   apply (rule_tac x=T in exI)\n   apply clarsimp\n   apply (erule TypeValue_extendconfiguration_AO)\n   apply clarsimp\n\n(*3 Q*)\n  apply clarsimp\n  apply (rename_tac a)\n(* one of the pending request *)\n  apply (drule_tac x=\"(ab, ac, a)\" in bspec,simp)\n  apply (erule TypeRequest.cases)\n  apply (rule_tac Meth=Meth in TypeRequest.intros)\n         apply auto\n  apply (drule_tac x=i in spec,clarsimp)\n  apply (rule TypeValue_extendconfiguration_AO)\n   apply clarsimp+\n\n(*2 the current req*)\n apply (case_tac x3,auto) \n  apply (simp add: Fun.fun_upd_def)\n  apply (erule TypeRequest_extendconfiguration_AO)\n  apply auto\n  apply (drule_tac x=x in spec,drule_tac x=v in spec,clarsimp)\n  apply (elim disjE)\n   apply clarsimp\n   apply (rule_tac x=T in exI,clarsimp)\n   apply (erule TypeValue_extendconfiguration_AO,force)\n(*3*)\n  apply clarsimp\n  apply (drule_tac x=T in spec,simp add: MethSignature_def)\n  apply (drule TypeValue_extendconfiguration_AO,force,force)\n\n apply (drule_tac x=x in bspec,auto)\n apply (erule_tac \\<alpha>=\\<alpha> in TypeStatement_extendconfiguration_AO)\n apply simp\n\n(*1 Finally: futures *)\napply (drule_tac x=\"(a,b)\" in bspec)\n apply simp\napply(case_tac b)\n apply auto\napply (erule TypeValue_extendconfiguration_AO)\napply clarsimp\ndone\n\nsection{*Type-empty-config*}\n\nlemma  TypeValue_EmptyConfig_pre: \n  \"(P,Cnf\\<turnstile>\\<^sub>Vv:T) \\<Longrightarrow>(Cnf=EmptyConfig  \\<longrightarrow>(P,Config\\<turnstile>\\<^sub>Vv:T))\"\napply (erule TypeValue.induct,auto)\napply (rule TypeValue.intros)+\napply auto\ndone\nlemma  TypeValue_EmptyConfig: \n  \"(P,EmptyConfig\\<turnstile>\\<^sub>Vv:T) \\<Longrightarrow>(P,Config\\<turnstile>\\<^sub>Vv:T)\"\nby (drule TypeValue_EmptyConfig_pre,auto)\n\nlemma  TypeAtom_EmptyConfig_pre: \n  \"(P,Cnf,\\<Gamma> in C\\<turnstile>\\<^sub>Av:T) \\<Longrightarrow>(Cnf=EmptyConfig  \\<longrightarrow>(P,Config,\\<Gamma> in C\\<turnstile>\\<^sub>Av:T))\"\napply (erule TypeAtom.induct,auto)\napply (rule TypeAtom.intros)\napply (erule TypeValue_EmptyConfig)\napply (rule TypeAtom.intros)\napply (erule TypeAtom.intros)\napply (erule TypeAtom.intros,simp)\ndone\nlemma  TypeAtom_EmptyConfig: \n\"(P,EmptyConfig,\\<Gamma> in C\\<turnstile>\\<^sub>Av:T) \\<Longrightarrow>(P,Config,\\<Gamma> in C\\<turnstile>\\<^sub>Av:T)\"\nby (drule TypeAtom_EmptyConfig_pre,auto)\n\nlemma  TypeExpression_EmptyConfig_pre: \n  \"(P,Cnf,\\<Gamma> in C\\<turnstile>\\<^sub>Ee:T) \\<Longrightarrow>(Cnf=EmptyConfig  \\<longrightarrow>(P,Config,\\<Gamma> in C\\<turnstile>\\<^sub>Ee:T))\"\napply (erule TypeExpression.induct,auto)\napply (rule TypeExpression.intros)\napply (erule TypeAtom_EmptyConfig)\napply (rule TypeExpression.intros)\napply (erule TypeAtom_EmptyConfig)\napply (erule TypeAtom_EmptyConfig)\napply (erule TypeExpression.intros,simp)\ndone\nlemma  TypeExpression_EmptyConfig: \n\"(P,EmptyConfig,\\<Gamma> in C\\<turnstile>\\<^sub>Ee:T) \\<Longrightarrow>(P,Config,\\<Gamma> in C\\<turnstile>\\<^sub>Ee:T)\"\nby (drule TypeExpression_EmptyConfig_pre,auto)\n\nlemma TypeRhs_EmptyConfig_pre:\n\"(P,Cnf,\\<Gamma> in C\\<turnstile>\\<^sub>RR:T) \\<Longrightarrow>(Cnf=EmptyConfig  \\<longrightarrow>(P,Config,\\<Gamma> in C\\<turnstile>\\<^sub>RR:T))\"\napply (drule TypeRhs.induct,auto)\napply (rule TypeRhs.intros)\napply (erule TypeExpression_EmptyConfig)\napply (rule TypeRhs.intros,auto)\napply (erule TypeAtom_EmptyConfig)\napply (drule_tac x=i in spec,simp)\napply (erule TypeExpression_EmptyConfig)\napply (rule TypeRhs.intros,auto)\napply (drule_tac x=i in spec,simp)\napply (erule TypeExpression_EmptyConfig)\napply (rule TypeRhs.intros)\napply (erule TypeAtom_EmptyConfig)\napply (rule TypeRhs.intros,auto)\ndone\nlemma  TypeRhs_EmptyConfig: \n\"(P,EmptyConfig,\\<Gamma> in C\\<turnstile>\\<^sub>RR:T) \\<Longrightarrow>(P,Config,\\<Gamma> in C\\<turnstile>\\<^sub>RR:T)\"\nby (drule TypeRhs_EmptyConfig_pre,auto)\n\nlemma Type_EmptyConfig_Stl_pre: \"((P,Cnf,\\<Gamma> in C \\<turnstile>\\<^sub>S S) \\<longrightarrow>(Cnf=EmptyConfig \\<longrightarrow>(P,Config,\\<Gamma> in C \\<turnstile>\\<^sub>S S))) \\<and>\n                             ((P,Cnf,\\<Gamma> in C \\<turnstile>\\<^sub>L Stl) \\<longrightarrow> (Cnf=EmptyConfig \\<longrightarrow>(P,Config,\\<Gamma> in C \\<turnstile>\\<^sub>L Stl)))\"\napply (rule TypeStatement_TypeStatementList.induct,auto)\napply (rule TypeStatement_TypeStatementList.intros,auto)\napply (erule TypeRhs_EmptyConfig)\napply (rule TypeStatement_TypeStatementList.intros,auto)\napply (erule TypeExpression_EmptyConfig)\napply (rule TypeStatement_TypeStatementList.intros,auto)\napply (erule TypeAtom_EmptyConfig)\napply (rule TypeStatement_TypeStatementList.intros)\napply (rule TypeStatement_TypeStatementList.intros,auto)\ndone\n\nlemma  TypeStl_EmptyConfig: \n\"(P,EmptyConfig,\\<Gamma> in C \\<turnstile>\\<^sub>L Stl) \\<Longrightarrow>(P,Config,\\<Gamma> in C \\<turnstile>\\<^sub>L Stl)\"\nby (insert Type_EmptyConfig_Stl_pre,auto)\n\nlemma Var_in_LocalVariables:\n\"  map_of (zip (map snd (LocalVariables aa)) (map (Initialisation_from_ASPType \\<circ> fst) (LocalVariables aa))) x = Some v \\<Longrightarrow>\n                     (\\<exists>T. (T, x) \\<in> set (LocalVariables aa)\\<and> (P,Config\\<turnstile>\\<^sub>Vv:T))\" \napply (case_tac aa,simp,erule_tac t=aa in ssubst,simp add: atomize_imp)\napply (induct_tac LocalVariables)\n apply (clarsimp )+\napply (rule_tac x=a in exI)\napply (case_tac a,clarsimp)\n\n apply (case_tac x1,unfold Initialisation_from_ASPType_def Initialisation_from_BasicType_def)\n(*5*)\n    apply (clarsimp,rule TypeValue.intros)\n   apply (clarsimp,rule TypeValue.intros)\n  apply (clarsimp,rule TypeValue.intros,rule Subtype.intros(3))\n  apply (rule TypeValue.intros)\n apply (clarsimp,rule TypeValue.intros)\n\napply (case_tac x2)\n(*4*)\n   apply (clarsimp,rule TypeValue.intros,rule Subtype.intros(2))\n   apply (rule TypeValue.intros)\n  apply (clarsimp,rule TypeValue.intros,rule Subtype.intros(2))\n  apply (rule TypeValue.intros)\n apply (clarsimp,rule TypeValue.intros,rule Subtype.intros(2))\n apply (rule TypeValue.intros,rule Subtype.intros(3))\n apply (rule TypeValue.intros)\napply (clarsimp,rule TypeValue.intros,rule Subtype.intros(2))\napply (rule TypeValue.intros)\ndone\n\n\nsection{* Well-typed initial configuraiton *}\n\n\nlemma Initialization_Vars_BasicType: \n\"(map_of (map (\\<lambda> v. (snd v,Initialisation_from_BasicType (fst v))) vl)) x=Some v \n  \\<Longrightarrow> \\<exists>T. ((T,x)\\<in>set vl\\<and> (P,Conf\\<turnstile>\\<^sub>Vv:BType T))\"\napply (auto simp: Initialisation_from_BasicType_def)\napply (drule Map.map_of_SomeD,auto)\napply (rule_tac x=a in exI,auto)\napply (case_tac a,auto)\n(*4*)\n    apply (rule TypeValue.intros)\n   apply (rule TypeValue.intros)\n  apply (subgoal_tac \"P,Conf\\<turnstile>\\<^sub>Vnull:BType AnyObject\")\n   apply (subgoal_tac \"P\\<turnstile>BType AnyObject\\<sqsubseteq>BType (TObj x3)\")\n    apply (erule TypeValue.intros)\n    apply auto\n   apply (rule Subtype.intros)\n  apply (rule TypeValue.intros)\n apply (rule TypeValue.intros)\ndone\n\nlemma Initialization_Vars_ASPType: \n\"(map_of (map (\\<lambda> v. (snd v,Initialisation_from_ASPType (fst v))) vl)) x=Some v \n  \\<Longrightarrow> \\<exists>T. ((T,x)\\<in>set vl\\<and> (P,Conf\\<turnstile>\\<^sub>Vv:T))\"\napply (auto simp: Initialisation_from_ASPType_def)\napply (drule Map.map_of_SomeD,auto)\napply (rule_tac x=a in exI,auto)\napply (case_tac a,auto)\n apply (case_tac x1,auto simp: Initialisation_from_BasicType_def)\n(*5*)\n    apply (rule TypeValue.intros)\n   apply (rule TypeValue.intros)\n  apply (subgoal_tac \"P,Conf\\<turnstile>\\<^sub>Vnull:BType AnyObject\")\n   apply (subgoal_tac \"P\\<turnstile>BType AnyObject\\<sqsubseteq>BType (TObj x3)\")\n    apply (erule TypeValue.intros)\n    apply auto\n   apply (rule Subtype.intros)\n  apply (rule TypeValue.intros)\n apply (rule TypeValue.intros)\napply (case_tac x2,auto simp: Initialisation_from_BasicType_def)\n(*4*)\n   apply (rule TypeValue.intros,rule Subtype.intros(2),rule TypeValue.intros) (*enforce btype<Ftype*)\n  apply (rule TypeValue.intros,rule Subtype.intros(2),rule TypeValue.intros) (*enforce btype<Ftype*)\n apply (subgoal_tac \"P,Conf\\<turnstile>\\<^sub>Vnull:FutType AnyObject\")\n  apply (subgoal_tac \"P\\<turnstile>FutType AnyObject\\<sqsubseteq>FutType (TObj x3)\")\n   apply (erule TypeValue.intros,simp)\n  apply (rule Subtype.intros)\n apply (rule TypeValue.intros,rule Subtype.intros(2),rule TypeValue.intros)\napply (rule TypeValue.intros,rule Subtype.intros(2),rule TypeValue.intros)\ndone\n\n\ntheorem WTinitialconfiguration: \"\\<turnstile>\\<^sub>P Prog  CL Vars Stl \\<Longrightarrow> Prog  ((MainObjClass Vars)#CL) Vars Stl \\<turnstile> InitialConfiguration (Prog  CL Vars Stl)\"\napply (unfold InitialConfiguration_def BuildInitialConfigurationfromVarsStl_def)\napply (auto,unfold Let_def Initialisation_from_ASPType_def fetchClass_def fetchMethodInClass_def MainObjClass_def MainMethodEmptyBody_def,auto)\n apply (intro gASPFuturesTypeSystem.TypeRequest.intros, auto simp: fetchClass_def fetchMethodInClass_def GetBasicType_def )\n apply (rule Initialization_Vars_ASPType)\n apply (simp add: Initialisation_from_ASPType_def)\n(*1*)\napply (rule TypeStatementList_TypeStatement,auto)\napply (unfold BuildTypeEnv_def)\napply (rule_tac AOs=\"empty\"  in TypeStatementList_extendconfiguration)\n  apply (auto)\ndone\n\nsection {* Subject Reduction *}\n\n\n\ntheorem SubjectReduction: \n\"(Prog CL Vars Stl \\<turnstile> Cn aos futs   \\<leadsto> Cn aos' futs') \\<Longrightarrow> (\\<turnstile>\\<^sub>P Prog  CL Vars Stl)\n    \\<longrightarrow> ((Prog CL Vars Stl \\<turnstile> Cn aos futs)  \\<longrightarrow> (Prog CL Vars Stl \\<turnstile> Cn aos' futs'))\"\napply (erule gASPFutures.reduction.induct)\n(* 11 SERVE *)\n apply (case_tac P, rename_tac CL Vars Stl, simp only: Let_def)\n apply (intro impI,rule TypeUpdate_AO)\n   apply clarsimp+\n apply (drule_tac x=\"AO C state None (a, b) ((f, m, vl) # Rq)\" in bspec,force simp: ran_def)\n apply simp\n apply clarify\n apply (rule_tac x=CLa in exI)\n apply clarsimp\n apply (intro conjI,clarsimp)\n  apply (drule_tac x=x in spec, drule_tac x=v in spec)\n  apply clarsimp\n  apply (rule_tac x=T in exI)\n  apply clarsimp\n  apply (erule TypeValue_extendconfiguration_AO,clarsimp)\n(*12*)\n  apply clarsimp\n  apply (rename_tac a b c)\n  apply (drule_tac x=\"(a,b,c)\" in bspec,simp)\n  apply (simp add: fun_upd_def)\n  apply (erule TypeRequest_extendconfiguration_AO)\n  apply force\n(*11*)\n apply (simp add: Bind_def )\n apply (case_tac \"fetchMethodInClass CLa m\",clarsimp)\n apply clarsimp\n apply (intro conjI)\n   apply (simp add: fun_upd_def,erule TypeRequest_extendconfiguration_AO,force)\n(*12 well typed new body! *)\n  apply (simp add: Let_def)\n  apply (case_tac \"length (MParams aa) = length vl\")  \n   apply (drule_tac x=CLa in bspec)\n    apply (erule fetchClass_Some_In)\n\napply (intro allI impI,simp,elim conjE)\napply (rotate_tac 12) (*map_of (zip (map snd (LocalVariables aa)) (map (Initialisation_from_ASPType \\<circ> fst) (MParams aa))) ++ map_of (zip (map snd (MParams aa)) vl) = ac*)\napply (drule sym,simp)\napply (drule Map.map_add_SomeD,elim disjE)\n\napply (rule disjI2)\napply (erule \"TypeRequest.cases\")\napply (drule Map.map_of_SomeD,simp, simp add: set_conv_nth,clarsimp)\napply (drule_tac x=i in spec,simp)\napply (rule_tac x=\"fst (MParams aa ! i)\" in exI)\napply clarsimp\napply (intro conjI)\napply (rule_tac x=\"MParams aa\" in exI)\napply (case_tac \"MethSignature aa\",force)\napply (erule TypeValue_extendconfiguration_AO,force)\n\napply (rule disjI1, elim conjE)\napply (frule Var_in_LocalVariables,clarsimp)\napply (rule_tac x=T in exI,simp)\napply (subgoal_tac \"\nzip (map snd (LocalVariables aa)) (map (Initialisation_from_ASPType \\<circ> fst) (MParams aa))\n=map (\\<lambda>v. (snd v, Initialisation_from_ASPType (fst v))) (LocalVariables aa)\")\napply force\n\napply (simp add: zip_map1)\n\napply clarsimp\n\n   apply (rule_tac Stl=\"Body aa\" in TypeStatementList_TypeStatement)\napply (drule_tac x=CLa in bspec)\napply (erule fetchClass_Some_In)\napply (drule_tac x=aa in bspec)\napply (erule fetchMethodInClass_Some)\napply (rule TypeStl_EmptyConfig)\napply (simp add: BuildTypeEnv_def)\napply (drule fetchClass_Some_Name,clarsimp)\napply (clarsimp simp: Let_def)\napply (case_tac \"length (MParams aa) = length vl\")  \napply force\napply force\n\n(*10 AssignLocal *)\napply (case_tac P, rename_tac CL Vars Stl, simp only: Let_def)\napply (intro impI)\napply (rule TypeUpdate_AO)\napply clarsimp+\napply (drule_tac x=\"(AO C state (Some (a, aa, b)) (locs, x =\\<^sub>A Expr e ;; Stla) Rq)\" in bspec,force simp: ran_def)\napply simp\napply clarify\napply (rule_tac x=CLa in exI)\napply clarsimp\napply (intro conjI,clarsimp)\napply (drule_tac x=xa in spec, drule_tac x=va in spec)\napply clarsimp\napply (rule_tac x=T in exI)\napply clarsimp\napply (erule TypeValue_extendconfiguration_AO,clarsimp)\n(*12*)\napply clarsimp\napply (rename_tac a b c)\napply (drule_tac x=\"(a,b,c)\" in bspec,simp)\napply (simp add: fun_upd_def)\napply (erule TypeRequest_extendconfiguration_AO)\napply force\n(*11*)\napply (simp add: fun_upd_def)\napply (erule TypeRequest_extendconfiguration_AO)\napply force\n(*10*)\napply clarsimp\napply (drule_tac x=xa in bspec,simp)\napply (erule TypeStatement_extendconfiguration_AO)\napply force\n\n(*9 AssignField*)\napply (case_tac P, rename_tac CL Vars Stl, simp only: Let_def)\napply (intro impI)\napply (thin_tac \"x \\<notin> dom locs\")\napply (rule TypeUpdate_AO)\napply clarsimp+\napply (drule_tac x=\"(AO C state (Some (a, aa, b)) (locs, x =\\<^sub>A Expr e ;; Stla) Rq)\" in bspec,force simp: ran_def)\napply simp\napply clarify\napply (rule_tac x=CLa in exI)\napply clarsimp\napply (intro conjI,clarsimp)\napply (intro conjI,clarsimp)\napply (drule_tac x=x in spec, drule_tac x=y in spec)\napply clarsimp\napply (rule_tac x=T in exI)\napply clarsimp\napply (erule TypeValue_extendconfiguration_AO,clarsimp)\n(*12*)\napply clarsimp\napply (rename_tac a b c)\napply (drule_tac x=\"(a,b,c)\" in bspec,simp)\napply (simp add: fun_upd_def)\napply (erule TypeRequest_extendconfiguration_AO)\napply force\n(*11*)\napply (simp add: fun_upd_def)\napply (erule TypeRequest_extendconfiguration_AO)\napply force\n(*10*)\napply clarsimp\napply (drule_tac x=xa in bspec,simp)\napply (erule TypeStatement_extendconfiguration_AO)\napply force\n", "meta": {"author": "lhenrio", "repo": "DFEcplicitFuturesinIsabelle", "sha": "a53fe1cbcabf14481577d37778041f76685417e8", "save_path": "github-repos/isabelle/lhenrio-DFEcplicitFuturesinIsabelle", "path": "github-repos/isabelle/lhenrio-DFEcplicitFuturesinIsabelle/DFEcplicitFuturesinIsabelle-a53fe1cbcabf14481577d37778041f76685417e8/TypeTheorems.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6113819732941511, "lm_q2_score": 0.411110869232168, "lm_q1q2_score": 0.2513457744738366}}
{"text": "(* \n   Title: Psi-calculi   \n   Author/Maintainer: Jesper Bengtson (jebe@itu.dk), 2012\n*)\ntheory Agent\n  imports Subst_Term\nbegin\n\nnominal_datatype ('term, 'assertion, 'condition) psi = \n  PsiNil (\"\\<zero>\" 190)\n\n\n| Output \"'term::fs_name\" 'term \"('term, 'assertion::fs_name, 'condition::fs_name) psi\"    (\"_\\<langle>_\\<rangle>._\" [120, 120, 110] 110)\n| Input 'term \"('term, 'assertion, 'condition) input\"                                      (\"_\\<lparr>_\" [120, 120] 110)\n| Case \"(('term, 'assertion, 'condition) psiCase)\"                                         (\"Case _\" [120] 120)\n| Par \"('term, 'assertion, 'condition) psi\" \"('term, 'assertion, 'condition) psi\"          (infixl \"\\<parallel>\" 90)\n| Res \"\\<guillemotleft>name\\<guillemotright>(('term, 'assertion, 'condition) psi)\"                                        (\"\\<lparr>\\<nu>_\\<rparr>_\" [120, 120] 110)\n| Assert 'assertion                                                                        (\"\\<lbrace>_\\<rbrace>\" [120] 120)\n| Bang \"('term, 'assertion, 'condition) psi\"                                               (\"!_\" [110] 110)\n\nand ('term, 'assertion, 'condition) input = \n  Trm 'term \"(('term, 'assertion, 'condition) psi)\"                                        (\"\\<rparr>_._\" [130, 130] 130)\n| Bind \"\\<guillemotleft>name\\<guillemotright>(('term, 'assertion, 'condition) input)\"                                     (\"\\<nu>__\" [120, 120] 120)\n\nand ('term, 'assertion, 'condition) psiCase = \n  EmptyCase                                                                                (\"\\<bottom>\\<^sub>c\" 120)\n| Cond 'condition \"(('term, 'assertion, 'condition) psi)\"\n                  \"(('term, 'assertion, 'condition) psiCase)\"                              (\"\\<box> _ \\<Rightarrow> _ _ \" [120, 120, 120] 120)\n\nlemma psiFreshSet[simp]:\n  fixes X :: \"name set\"\n  and   M :: \"'a::fs_name\"\n  and   N :: 'a\n  and   P :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n  and   I :: \"('a, 'b, 'c) input\"\n  and   C :: \"('a, 'b, 'c) psiCase\"\n  and   Q :: \"('a, 'b, 'c) psi\"\n  and   x :: name\n  and   \\<Psi> :: 'b\n  and   \\<Phi> :: 'c\n\n  shows \"X \\<sharp>* (M\\<langle>N\\<rangle>.P) = (X \\<sharp>* M \\<and> X \\<sharp>* N \\<and> X \\<sharp>* P)\"\n  and   \"X \\<sharp>* M\\<lparr>I = (X \\<sharp>* M \\<and> X \\<sharp>* I)\"\n  and   \"X \\<sharp>* Case C = X \\<sharp>* C\"\n  and   \"X \\<sharp>* (P \\<parallel> Q) = (X \\<sharp>* P \\<and> X \\<sharp>* Q)\"\n  and   \"X \\<sharp>* \\<lparr>\\<nu>x\\<rparr>P = (X \\<sharp>* [x].P)\"\n  and   \"X \\<sharp>* \\<lbrace>\\<Psi>\\<rbrace> = X \\<sharp>* \\<Psi>\"\n  and   \"X \\<sharp>* !P = X \\<sharp>* P\"\n  and   \"X \\<sharp>* \\<zero>\"\n  and   \"X \\<sharp>* Trm N P = (X \\<sharp>* N \\<and> X \\<sharp>* P)\"\n  and   \"X \\<sharp>* Bind x I = X \\<sharp>* ([x].I)\"\n\n  and   \"X \\<sharp>* \\<bottom>\\<^sub>c\"\n  and   \"X \\<sharp>* \\<box> \\<Phi> \\<Rightarrow> P C = (X \\<sharp>* \\<Phi> \\<and> X \\<sharp>* P \\<and> X \\<sharp>* C)\"\nby(auto simp add: fresh_star_def psi.fresh)+\n\nlemma psiFreshVec[simp]:\n  fixes xvec :: \"name list\"\n\n  shows \"xvec \\<sharp>* (M\\<langle>N\\<rangle>.P) = (xvec \\<sharp>* M \\<and> xvec \\<sharp>* N \\<and> xvec \\<sharp>* P)\"\n  and   \"xvec \\<sharp>* M\\<lparr>I = (xvec \\<sharp>* M \\<and> xvec \\<sharp>* I)\"\n  and   \"xvec \\<sharp>* Case C = xvec \\<sharp>* C\"\n  and   \"xvec \\<sharp>* (P \\<parallel> Q) = (xvec \\<sharp>* P \\<and> xvec \\<sharp>* Q)\"\n  and   \"xvec \\<sharp>* \\<lparr>\\<nu>x\\<rparr>P = (xvec \\<sharp>* [x].P)\"\n  and   \"xvec \\<sharp>* \\<lbrace>\\<Psi>\\<rbrace> = xvec \\<sharp>* \\<Psi>\"\n  and   \"xvec \\<sharp>* !P = xvec \\<sharp>* P\"\n  and   \"xvec \\<sharp>* \\<zero>\"\n\n  and   \"xvec \\<sharp>* Trm N P = (xvec \\<sharp>* N \\<and> xvec \\<sharp>* P)\"\n  and   \"xvec \\<sharp>* Bind x I = xvec \\<sharp>* ([x].I)\"\n\n  and   \"xvec \\<sharp>* \\<bottom>\\<^sub>c\"\n  and   \"xvec \\<sharp>* \\<box> \\<Phi> \\<Rightarrow> P C = (xvec \\<sharp>* \\<Phi> \\<and> xvec \\<sharp>* P \\<and> xvec \\<sharp>* C)\"\nby(auto simp add: fresh_star_def)\n\nfun psiCases :: \"('c::fs_name \\<times> ('a::fs_name, 'b::fs_name, 'c) psi) list \\<Rightarrow> ('a, 'b, 'c) psiCase\"\nwhere \n  base: \"psiCases [] = \\<bottom>\\<^sub>c\"\n| step: \"psiCases ((\\<Phi>, P)#xs) = Cond \\<Phi> P (psiCases xs)\"\n\nlemma psiCasesEqvt[eqvt]:\n  fixes p  :: \"name prm\"\n  and   Cs :: \"('c::fs_name \\<times> ('a::fs_name, 'b::fs_name, 'c) psi) list\"\n\n  shows \"(p \\<bullet> (psiCases Cs)) = psiCases(p \\<bullet> Cs)\"\nby(induct Cs) auto\n\nlemma psiCasesFresh[simp]:\n  fixes x  :: name\n  and   Cs :: \"('c::fs_name \\<times> ('a::fs_name, 'b::fs_name, 'c) psi) list\"\n  \n  shows \"x \\<sharp> psiCases Cs = x \\<sharp> Cs\"\nby(induct Cs)\n  (auto simp add: fresh_list_nil fresh_list_cons)\n\nlemma psiCasesFreshChain[simp]:\n  fixes xvec :: \"name list\"\n  and   Cs :: \"('c::fs_name \\<times> ('a::fs_name, 'b::fs_name, 'c) psi) list\"\n  and   Xs   :: \"name set\"\n  \n  shows \"(xvec \\<sharp>* psiCases Cs) = xvec \\<sharp>* Cs\"\n  and   \"(Xs \\<sharp>* psiCases Cs) = Xs \\<sharp>* Cs\"\nby(auto simp add: fresh_star_def)\n\nabbreviation\n  psiCasesJudge (\"Cases _\" [80] 80) where \"Cases Cs \\<equiv> Case(psiCases Cs)\"\n\nprimrec resChain :: \"name list \\<Rightarrow> ('a::fs_name, 'b::fs_name, 'c::fs_name) psi \\<Rightarrow> ('a, 'b, 'c) psi\" where\n  base: \"resChain [] P = P\"\n| step: \"resChain (x#xs) P = \\<lparr>\\<nu>x\\<rparr>(resChain xs P)\"\n\nnotation resChain (\"\\<lparr>\\<nu>*_\\<rparr>_\" [80, 80] 80)\n\nlemma resChainEqvt[eqvt]:\n  fixes perm :: \"name prm\"\n  and   lst  :: \"name list\"\n  and   P    :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi\"\n  \n  shows \"perm \\<bullet> (\\<lparr>\\<nu>*xvec\\<rparr>P) = \\<lparr>\\<nu>*(perm \\<bullet> xvec)\\<rparr>(perm \\<bullet> P)\"\nby(induct_tac xvec, auto)\n\nlemma resChainSupp:\n  fixes xvec :: \"name list\"\n  and   P    :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi\"\n\n  shows \"supp(\\<lparr>\\<nu>*xvec\\<rparr>P) = (supp P) - set xvec\"\nby(induct xvec) (auto simp add: psi.supp abs_supp)\n\nlemma resChainFresh: \n  fixes x    :: name\n  and   xvec :: \"name list\"\n  and   P    :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi\"\n\n  shows \"x \\<sharp> \\<lparr>\\<nu>*xvec\\<rparr>P = (x \\<in> set xvec \\<or> x \\<sharp> P)\"\nby (induct xvec) (simp_all add: abs_fresh)\n\nlemma resChainFreshSet: \n  fixes Xs   :: \"name set\"\n  and   xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  and   P    :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi\"\n\n  shows \"Xs \\<sharp>* (\\<lparr>\\<nu>*xvec\\<rparr>P) = (\\<forall>x\\<in>Xs. x \\<in> set xvec \\<or> x \\<sharp> P)\"\n  and   \"yvec \\<sharp>* (\\<lparr>\\<nu>*xvec\\<rparr>P) = (\\<forall>x\\<in>(set yvec). x \\<in> set xvec \\<or> x \\<sharp> P)\"\nby (simp add: fresh_star_def resChainFresh)+\n\nlemma resChainFreshSimps[simp]:\n  fixes Xs   :: \"name set\"\n  and   xvec :: \"name list\"\n  and   P    :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi\"\n  and   yvec :: \"name list\"\n\n  shows \"Xs \\<sharp>* xvec \\<Longrightarrow> Xs \\<sharp>* (\\<lparr>\\<nu>*xvec\\<rparr>P) = (Xs \\<sharp>* P)\"\n  and   \"yvec \\<sharp>* xvec \\<Longrightarrow> yvec \\<sharp>* (\\<lparr>\\<nu>*xvec\\<rparr>P) = (yvec \\<sharp>* P)\"\n  and   \"xvec \\<sharp>* (\\<lparr>\\<nu>*xvec\\<rparr>P)\"\napply(simp add: resChainFreshSet) apply(force simp add: fresh_star_def name_list_supp fresh_def)\napply(simp add: resChainFreshSet) apply(force simp add: fresh_star_def name_list_supp fresh_def)\nby(simp add: resChainFreshSet)\n  \nlemma resChainAlpha:\n  fixes p    :: \"name prm\"\n  and   xvec :: \"name list\"\n  and   P    :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi\"\n\n  assumes xvecFreshP: \"(p \\<bullet> xvec) \\<sharp>* P\"\n  and     S: \"set p \\<subseteq> set xvec \\<times> set (p \\<bullet> xvec)\"\n\n  shows \"\\<lparr>\\<nu>*xvec\\<rparr>P = \\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>(p \\<bullet> P)\"\nproof -\n  note pt_name_inst at_name_inst S\n  moreover have \"set xvec \\<sharp>* (\\<lparr>\\<nu>*xvec\\<rparr>P)\"\n    by (simp add: resChainFreshSet)\n  moreover from xvecFreshP have \"set (p \\<bullet> xvec) \\<sharp>* (\\<lparr>\\<nu>*xvec\\<rparr>P)\"\n    by (simp add: resChainFreshSet) (simp add: fresh_star_def)\n  ultimately have \"\\<lparr>\\<nu>*xvec\\<rparr>P = p \\<bullet> (\\<lparr>\\<nu>*xvec\\<rparr>P)\"\n    by (rule_tac pt_freshs_freshs [symmetric])\n  then show ?thesis by(simp add: eqvts)\nqed\n\nlemma resChainAppend:\n  fixes xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  and   P    :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi\"\n  \n  shows \"\\<lparr>\\<nu>*(xvec@yvec)\\<rparr>P = \\<lparr>\\<nu>*xvec\\<rparr>(\\<lparr>\\<nu>*yvec\\<rparr>P)\"\nby(induct xvec) auto\n\nlemma resChainSimps[dest]:\n  fixes xvec :: \"name list\"\n  and   P    :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   P'   :: \"('a, 'b, 'c) psi\"\n  and   Q'   :: \"('a, 'b, 'c) psi\"\n\n  shows \"((\\<lparr>\\<nu>*xvec\\<rparr>(P \\<parallel> Q)) = P' \\<parallel> Q') \\<Longrightarrow> (P = P' \\<and> Q = Q')\"\n  and   \"(P \\<parallel> Q = \\<lparr>\\<nu>*xvec\\<rparr>(P' \\<parallel> Q')) \\<Longrightarrow> (P = P' \\<and> Q = Q')\"\nby(case_tac xvec, simp_all add: psi.inject)+\n\nprimrec inputChain :: \"name list \\<Rightarrow> 'a::fs_name \\<Rightarrow> ('a, 'b::fs_name, 'c::fs_name) psi \\<Rightarrow> ('a, 'b, 'c) input\" where\n  base: \"inputChain [] N P = \\<rparr>(N).P\"\n| step: \"inputChain (x#xs) N P = \\<nu> x (inputChain xs N P)\"\n\nabbreviation\n  inputChainJudge (\"_\\<lparr>\\<lambda>*_ _\\<rparr>._\" [80, 80, 80, 80] 80) where \"M\\<lparr>\\<lambda>*xvec N\\<rparr>.P \\<equiv> M\\<lparr>(inputChain xvec N P)\"\n\nlemma inputChainEqvt[eqvt]:\n  fixes p    :: \"name prm\"\n  and   xvec :: \"name list\"\n  and   N    :: \"'a::fs_name\"\n  and   P    :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n  \n  shows \"p \\<bullet> (inputChain xvec N P) = inputChain (p \\<bullet> xvec) (p \\<bullet> N) (p \\<bullet> P)\"\nby(induct_tac xvec) auto\n\nlemma inputChainFresh: \n  fixes x    :: name\n  and   xvec :: \"name list\"\n  and   N    :: \"'a::fs_name\"\n  and   P    :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n\n  shows \"x \\<sharp> (inputChain xvec N P) = (x \\<in> set xvec \\<or> (x \\<sharp> N \\<and> x \\<sharp> P))\"\nby (induct xvec) (simp_all add: abs_fresh)\n\nlemma inductChainSimps[simp]:\n  fixes xvec :: \"name list\"\n  and   N    :: \"'a::fs_name\"\n  and   P    :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n\n  shows \"xvec \\<sharp>* (inputChain xvec N P)\"\nby(induct xvec) (auto simp add: abs_fresh abs_fresh_star fresh_star_def)\n\nlemma inputChainFreshSet: \n  fixes Xs   :: \"name set\"\n  and   xvec :: \"name list\"\n  and   N    :: \"'a::fs_name\"\n  and   P    :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n\n  shows \"Xs \\<sharp>* (inputChain xvec N P) = (\\<forall>x\\<in>Xs. x \\<in> set xvec \\<or> (x \\<sharp> N \\<and> x \\<sharp> P))\"\nby (simp add: fresh_star_def inputChainFresh)\n\nlemma inputChainAlpha:\n  fixes p  :: \"name prm\"\n  and   Xs :: \"name set\"\n  and   Ys :: \"name set\"\n\n  assumes XsFreshP: \"Xs \\<sharp>* (inputChain xvec N P)\"\n  and     YsFreshN: \"Ys \\<sharp>* N\"\n  and     YsFreshP: \"Ys \\<sharp>* P\"\n  and     S: \"set p \\<subseteq> Xs \\<times> Ys\"\n\n  shows \"(inputChain xvec N P) = (inputChain (p \\<bullet> xvec) (p \\<bullet> N) (p \\<bullet> P))\"\nproof -\n  note pt_name_inst at_name_inst XsFreshP S\n  moreover from YsFreshN YsFreshP have \"Ys \\<sharp>* (inputChain xvec N P)\"\n    by (simp add: inputChainFreshSet) (simp add: fresh_star_def)\n  ultimately have \"(inputChain xvec N P) = p \\<bullet> (inputChain xvec N P)\"\n    by (rule_tac pt_freshs_freshs [symmetric])\n  then show ?thesis by(simp add: eqvts)\nqed\n\nlemma inputChainAlpha':\n  fixes p    :: \"name prm\"\n  and   xvec :: \"name list\"\n  and   N    :: \"'a::fs_name\"\n  and   P    :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n\n  assumes xvecFreshP: \"(p \\<bullet> xvec) \\<sharp>* P\"\n  and     xvecFreshN: \"(p \\<bullet> xvec) \\<sharp>* N\"\n  and     S: \"set p \\<subseteq> set xvec \\<times> set (p \\<bullet> xvec)\"\n\n  shows \"(inputChain xvec N P) = (inputChain (p \\<bullet> xvec) (p \\<bullet> N) (p \\<bullet> P))\"\nproof -\n  note pt_name_inst at_name_inst S\n  moreover have \"set xvec \\<sharp>* (inputChain xvec N P)\"\n    by (simp add: inputChainFreshSet)\n  ultimately show ?thesis using xvecFreshN xvecFreshP \n    by(rule_tac inputChainAlpha) (simp add: fresh_star_def)+\nqed\n\nlemma alphaRes:\n  fixes M :: \"'a::fs_name\"\n  and   x :: name\n  and   P :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n  and   y :: name\n\n  assumes yFreshP: \"y \\<sharp> P\"\n\n  shows \"\\<lparr>\\<nu>x\\<rparr>P = \\<lparr>\\<nu>y\\<rparr>([(x, y)] \\<bullet> P)\"\nproof(cases \"x = y\")\n  assume \"x=y\"\n  thus ?thesis by simp\nnext\n  assume \"x \\<noteq> y\"\n  with yFreshP show ?thesis\n    by(perm_simp add: psi.inject alpha calc_atm fresh_left)\nqed\n\nlemma alphaInput:\n  fixes x :: name\n  and   I :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) input\"\n  and   c :: name\n\n  assumes A1: \"c \\<sharp> I\"\n\n  shows \"\\<nu> x I = \\<nu> c([(x, c)] \\<bullet> I)\"\nproof(cases \"x = c\")\n  assume \"x=c\"\n  thus ?thesis by simp\nnext\n  assume \"x \\<noteq> c\"\n  with A1 show ?thesis\n    by(perm_simp add: input.inject alpha calc_atm fresh_left)\nqed\n\nlemma inputChainLengthEq:\n  fixes xvec :: \"name list\"\n  and   yvec :: \"name list\"\n  and   M    :: \"'a::fs_name\"\n  and   P    :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n\n  assumes \"length xvec = length yvec\"\n  and     \"xvec \\<sharp>* yvec\"\n  and     \"distinct yvec\"\n  and     \"yvec \\<sharp>* M\"\n  and     \"yvec \\<sharp>* P\"\n\n  obtains N Q where \"inputChain xvec M P = inputChain yvec N Q\"\nproof -\n  assume \"\\<And>N Q. inputChain xvec M P = inputChain yvec N Q \\<Longrightarrow> thesis\"\n  moreover obtain n where \"n = length xvec\" by auto\n  with assms have \"\\<exists>N Q. inputChain xvec M P = inputChain yvec N Q\"\n  proof(induct n arbitrary: xvec yvec M P)\n    case 0\n    thus ?case by auto\n  next\n    case(Suc n xvec yvec M P)\n    from \\<open>Suc n = length xvec\\<close>\n    obtain x xvec' where \"xvec = x#xvec'\" and \"length xvec' = n\"\n      by(case_tac xvec) auto\n    with \\<open>length xvec = length yvec\\<close>\n    obtain y yvec' where \"yvec = y#yvec'\" by(case_tac yvec) auto\n    from \\<open>yvec = y#yvec'\\<close> \\<open>xvec=x#xvec'\\<close> \\<open>xvec \\<sharp>* yvec\\<close> \\<open>distinct yvec\\<close> \\<open>length xvec = length yvec\\<close> \\<open>yvec \\<sharp>* M\\<close> \\<open>yvec \\<sharp>* P\\<close>\n    have \"length xvec' = length yvec'\" and \"xvec' \\<sharp>* yvec'\" and \"distinct yvec'\" and \"yvec' \\<sharp>* M\" and \"yvec' \\<sharp>* P\"\n      by simp+\n    then obtain N Q where Eq: \"inputChain xvec' M P = inputChain yvec' N Q\" using \\<open>length xvec' = n\\<close>\n      by(drule_tac Suc) auto\n    moreover from \\<open>distinct yvec\\<close> \\<open>yvec = y#yvec'\\<close> have \"y \\<sharp> yvec'\" by auto\n    moreover from \\<open>xvec \\<sharp>* yvec\\<close> \\<open>xvec = x#xvec'\\<close> \\<open>yvec=y#yvec'\\<close> have \"x \\<noteq> y\" and \"x \\<sharp> yvec'\"\n      by auto\n    moreover from \\<open>yvec \\<sharp>* M\\<close> \\<open>yvec \\<sharp>* P\\<close> \\<open>yvec = y#yvec'\\<close> have \"y \\<sharp> M\" and \"y \\<sharp> P\" by auto\n    hence \"y \\<sharp> inputChain xvec' M P\" by(simp add: inputChainFresh)\n    with Eq have \"y \\<sharp> inputChain yvec' N Q\" by(simp add: inputChainFresh)\n    ultimately have \"\\<nu> x (inputChain xvec' M P) = \\<nu> y (inputChain yvec' ([(x, y)] \\<bullet> N) ([(x, y)] \\<bullet> Q))\"\n      by(simp add: input.inject alpha' eqvts name_swap)\n    thus ?case using \\<open>xvec = x#xvec'\\<close> \\<open>yvec=y#yvec'\\<close> by force\n  qed\n  ultimately show ?thesis\n    by blast\nqed\n\nlemma inputChainEq:\n  fixes xvec :: \"name list\"\n  and   M    :: \"'a::fs_name\"\n  and   P    :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n  and   yvec :: \"name list\"\n  and   N    :: 'a\n  and   Q    :: \"('a, 'b, 'c) psi\"\n\n  assumes \"inputChain xvec M P = inputChain yvec N Q\"\n  and     \"xvec \\<sharp>* yvec\"\n  and     \"distinct xvec\"\n  and     \"distinct yvec\"\n\n  obtains p where \"(set p) \\<subseteq> (set xvec) \\<times> set (p \\<bullet> xvec)\" and \"distinctPerm p\" and \"yvec = p \\<bullet> xvec\" and \"N = p \\<bullet> M\" and \"Q = p \\<bullet> P\"\nproof -\n  assume \"\\<And>p. \\<lbrakk>set p \\<subseteq> set xvec \\<times> set (p \\<bullet> xvec); distinctPerm p; yvec = p \\<bullet> xvec; N = p \\<bullet> M; Q = p \\<bullet> P\\<rbrakk> \\<Longrightarrow> thesis\"\n  moreover obtain n where \"n = length xvec\" by auto\n  with assms have \"\\<exists>p. (set p) \\<subseteq> (set xvec) \\<times> set (yvec) \\<and> distinctPerm p \\<and>  yvec = p \\<bullet> xvec \\<and> N = p \\<bullet> M \\<and> Q = p \\<bullet> P\"\n  proof(induct n arbitrary: xvec yvec M N P Q)\n    case(0 xvec yvec M N P Q)\n    have Eq: \"inputChain xvec M P = inputChain yvec N Q\" by fact\n    from \\<open>0 = length xvec\\<close> have \"xvec = []\" by auto\n    moreover with Eq have \"yvec = []\"\n      by(case_tac yvec) auto\n    ultimately show ?case using Eq\n      by(simp add: input.inject)\n  next\n    case(Suc n xvec yvec M N P Q)\n    from \\<open>Suc n = length xvec\\<close>\n    obtain x xvec' where \"xvec = x#xvec'\" and \"length xvec' = n\"\n      by(case_tac xvec) auto\n    from \\<open>inputChain xvec M P = inputChain yvec N Q\\<close> \\<open>xvec = x # xvec'\\<close>\n    obtain y yvec' where \"inputChain (x#xvec') M P = inputChain (y#yvec') N Q\"\n      and \"yvec = y#yvec'\"\n      by(case_tac yvec) auto\n    hence EQ: \"\\<nu> x (inputChain xvec' M P) = \\<nu> y (inputChain yvec' N Q)\"\n      by simp\n    from \\<open>xvec = x#xvec'\\<close> \\<open>yvec=y#yvec'\\<close> \\<open>xvec \\<sharp>* yvec\\<close>\n    have \"x \\<noteq> y\" and \"xvec' \\<sharp>* yvec'\" and \"x \\<sharp> yvec'\" and \"y \\<sharp> xvec'\"\n      by(auto simp add: fresh_list_cons)\n    from \\<open>distinct xvec\\<close> \\<open>distinct yvec\\<close> \\<open>xvec=x#xvec'\\<close> \\<open>yvec=y#yvec'\\<close> have \"x \\<sharp> xvec'\" and \"y \\<sharp> yvec'\" and \"distinct xvec'\" and \"distinct yvec'\"\n      by simp+\n    have IH: \"\\<And>xvec yvec M N P Q. \\<lbrakk>inputChain xvec (M::'a) (P::('a, 'b, 'c) psi) = inputChain yvec (N::'a) (Q::('a, 'b, 'c) psi); xvec \\<sharp>* yvec; distinct xvec; distinct yvec; n = length xvec\\<rbrakk> \\<Longrightarrow> \\<exists>p. (set p) \\<subseteq> (set xvec) \\<times> (set yvec) \\<and> distinctPerm p \\<and>  yvec = p \\<bullet> xvec \\<and> N = p \\<bullet> M \\<and> Q = p \\<bullet> P\"\n      by fact\n    from EQ \\<open>x \\<noteq> y\\<close>  \\<open>x \\<sharp> yvec'\\<close> \\<open>y \\<sharp> yvec'\\<close> have \"inputChain xvec' M P = inputChain yvec' ([(x, y)] \\<bullet> N) ([(x, y)] \\<bullet> Q)\"\n      by(simp add: input.inject alpha eqvts)\n    with \\<open>xvec' \\<sharp>* yvec'\\<close> \\<open>distinct xvec'\\<close> \\<open>distinct yvec'\\<close> \\<open>length xvec' = n\\<close> IH\n    obtain p where S: \"(set p) \\<subseteq> (set xvec') \\<times> (set yvec')\" and \"distinctPerm p\" and \"yvec' = p \\<bullet> xvec'\" and \"([(x, y)] \\<bullet> N) = p \\<bullet> M\" and \"([(x, y)] \\<bullet> Q) = p \\<bullet> P\"\n      by metis\n    from S have \"set((x, y)#p) \\<subseteq> set(x#xvec') \\<times> set(y#yvec')\" by auto\n    moreover from \\<open>x \\<sharp> xvec'\\<close> \\<open>x \\<sharp> yvec'\\<close> \\<open>y \\<sharp> xvec'\\<close> \\<open>y \\<sharp> yvec'\\<close> S have \"x \\<sharp> p\" and \"y \\<sharp> p\"\n      apply(induct p)\n      by(auto simp add: fresh_list_nil fresh_list_cons fresh_prod name_list_supp) (auto simp add: fresh_def) \n\n    with S \\<open>distinctPerm p\\<close> \\<open>x \\<noteq> y\\<close> have \"distinctPerm((x, y)#p)\" by auto\n    moreover from \\<open>yvec' = p \\<bullet> xvec'\\<close> \\<open>x \\<sharp> p\\<close> \\<open>y \\<sharp> p\\<close> \\<open>x \\<sharp> xvec'\\<close> \\<open>y \\<sharp> xvec'\\<close> have \"(y#yvec') = ((x, y)#p) \\<bullet> (x#xvec')\"\n      by(simp add: calc_atm freshChainSimps)\n    moreover from \\<open>([(x, y)] \\<bullet> N) = p \\<bullet> M\\<close> have \"([(x, y)] \\<bullet> [(x, y)] \\<bullet> N) = [(x, y)] \\<bullet> p \\<bullet> M\"\n      by(simp add: pt_bij)\n    hence \"N = ((x, y)#p) \\<bullet> M\" by simp\n    moreover from \\<open>([(x, y)] \\<bullet> Q) = p \\<bullet> P\\<close> have \"([(x, y)] \\<bullet> [(x, y)] \\<bullet> Q) = [(x, y)] \\<bullet> p \\<bullet> P\"\n      by(simp add: pt_bij)\n    hence \"Q = ((x, y)#p) \\<bullet> P\" by simp\n    ultimately show ?case using \\<open>xvec=x#xvec'\\<close> \\<open>yvec=y#yvec'\\<close>\n      by blast\n  qed\n  ultimately show ?thesis by blast\nqed\n\nlemma inputChainEqLength:\n  fixes xvec :: \"name list\"\n  and   M    :: \"'a::fs_name\"\n  and   P    :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n  and   yvec :: \"name list\"\n  and   N    :: 'a\n  and   Q    :: \"('a, 'b, 'c) psi\"\n\n  assumes \"inputChain xvec M P = inputChain yvec N Q\"\n\n  shows \"length xvec = length yvec\"\nproof -\n  obtain n where \"n = length xvec\" by auto\n  with assms show ?thesis\n  proof(induct n arbitrary: xvec yvec M P N Q)\n    case(0 xvec yvec M P N Q)\n    from \\<open>0 = length xvec\\<close> have \"xvec = []\" by auto\n    moreover with \\<open>inputChain xvec M P = inputChain yvec N Q\\<close> have \"yvec = []\"\n      by(case_tac yvec) auto\n    ultimately show ?case by simp\n  next\n    case(Suc n xvec yvec M P N Q)\n    from \\<open>Suc n = length xvec\\<close>\n    obtain x xvec' where \"xvec = x#xvec'\" and \"length xvec' = n\"\n      by(case_tac xvec) auto\n    from \\<open>inputChain xvec M P = inputChain yvec N Q\\<close> \\<open>xvec = x # xvec'\\<close>\n    obtain y yvec' where \"inputChain (x#xvec') M P = inputChain (y#yvec') N Q\"\n      and \"yvec = y#yvec'\"\n      by(case_tac yvec) auto\n    hence EQ: \"\\<nu> x (inputChain xvec' M P) = \\<nu> y (inputChain yvec' N Q)\"\n      by simp\n    have IH: \"\\<And>xvec yvec M P N Q. \\<lbrakk>inputChain xvec (M::'a) (P::('a, 'b, 'c) psi) = inputChain yvec N Q; n = length xvec\\<rbrakk> \\<Longrightarrow> length xvec = length yvec\"\n      by fact\n    show ?case\n    proof(case_tac \"x = y\")\n      assume \"x = y\"\n      with EQ have \"inputChain xvec' M P = inputChain yvec' N Q\"\n        by(simp add: alpha input.inject)\n      with IH \\<open>length xvec' = n\\<close> have \"length xvec' = length yvec'\"\n        by blast\n      with \\<open>xvec = x#xvec'\\<close> \\<open>yvec=y#yvec'\\<close>\n      show ?case by simp\n    next\n      assume \"x \\<noteq> y\"\n      with EQ have \"inputChain xvec' M P = inputChain ([(x, y)] \\<bullet> yvec') ([(x, y)] \\<bullet> N) ([(x, y)] \\<bullet> Q)\"\n        by(simp add: alpha input.inject eqvts)\n      with IH \\<open>length xvec' = n\\<close> have \"length xvec' = length ([(x, y)] \\<bullet> yvec')\"\n        by blast\n      hence \"length xvec' = length yvec'\"\n        by simp\n      with \\<open>xvec = x#xvec'\\<close> \\<open>yvec=y#yvec'\\<close>\n      show ?case by simp\n    qed\n  qed\nqed\n\nlemma alphaInputChain:\n  fixes yvec :: \"name list\"\n  and   xvec :: \"name list\"\n  and   M    :: \"'a::fs_name\"\n  and   P    :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n\n  assumes \"length xvec = length yvec\"\n  and     \"yvec \\<sharp>* M\"\n  and     \"yvec \\<sharp>* P\"\n  and     \"yvec \\<sharp>* xvec\"\n  and     \"distinct yvec\"\n\n  shows \"inputChain xvec M P = inputChain yvec ([xvec yvec] \\<bullet>\\<^sub>v M) ([xvec yvec] \\<bullet>\\<^sub>v P)\"\nusing assms\nproof(induct rule: composePermInduct)\n  case cBase\n  show ?case by simp\nnext\n  case(cStep x xvec y yvec)\n  thus ?case \n    apply auto\n    by(subst alphaInput[of y]) (auto simp add: inputChainFresh eqvts)\nqed\n\nlemma inputChainInject[simp]:\n\n  shows \"(inputChain xvec M P = inputChain xvec N Q) = ((M = N) \\<and> (P = Q))\"\nby(induct xvec) (auto simp add: input.inject alpha)\n\nlemma alphaInputDistinct:\n  fixes xvec :: \"name list\"\n  and   M    :: \"'a::fs_name\"\n  and   P    :: \"('a, 'b::fs_name, 'c::fs_name) psi\"\n  and   yvec :: \"name list\"\n  and   N    :: 'a\n  and   Q    :: \"('a, 'b, 'c) psi\"\n\n  assumes Eq: \"inputChain xvec M P = inputChain yvec N Q\"\n  and     xvecDist: \"distinct xvec\"\n  and     Mem: \"\\<And>x. x \\<in> set xvec \\<Longrightarrow> x \\<in> supp M\"\n  and     xvecFreshyvec: \"xvec \\<sharp>* yvec\"\n  and     xvecFreshN: \"xvec \\<sharp>* N\"\n  and     xvecFreshQ: \"xvec \\<sharp>* Q\"\n\n  shows \"distinct yvec\"\nproof -\n  from Eq have \"length xvec = length yvec\"\n    by(rule inputChainEqLength)\n  with assms show ?thesis\n  proof(induct n==\"length xvec\" arbitrary: xvec yvec N Q rule: nat.induct)\n    case(zero xvec yvec N Q)\n    thus ?case by simp\n  next\n    case(Suc n xvec yvec N Q)\n    have L: \"length xvec = length yvec\" and \"Suc n = length xvec\" by fact+\n    then obtain x xvec' y yvec' where xEq: \"xvec = x#xvec'\" and yEq: \"yvec = y#yvec'\"\n                                  and L': \"length xvec' = length yvec'\"\n      by(cases xvec, auto, cases yvec, auto)\n    have xvecFreshyvec: \"xvec \\<sharp>* yvec\" and xvecDist: \"distinct xvec\" by fact+\n    with xEq yEq have xineqy: \"x \\<noteq> y\" and xvec'Freshyvec': \"xvec' \\<sharp>* yvec'\"\n                  and xvec'Dist: \"distinct xvec'\" and xFreshxvec': \"x \\<sharp> xvec'\"\n                  and xFreshyvec': \"x \\<sharp> yvec'\" and yFreshxvec': \"y \\<sharp> xvec'\"\n      by(auto simp add: fresh_list_cons)\n    have Eq: \"inputChain xvec M P = inputChain yvec N Q\" by fact\n    with xEq yEq xineqy have Eq': \"inputChain xvec' M P = inputChain ([(x, y)] \\<bullet> yvec') ([(x, y)] \\<bullet> N) ([(x, y)] \\<bullet> Q)\"\n      by(simp add: input.inject alpha eqvts) \n    moreover have Mem:\"\\<And>x. x \\<in> set xvec \\<Longrightarrow> x \\<in> supp M\" by fact\n    with xEq have \"\\<And>x. x \\<in> set xvec' \\<Longrightarrow> x \\<in> supp M\" by simp\n    moreover have xvecFreshN: \"xvec \\<sharp>* N\" by fact\n    with xEq xFreshxvec' yFreshxvec' have \"xvec' \\<sharp>* ([(x, y)] \\<bullet> N)\" by simp\n    moreover have xvecFreshQ: \"xvec \\<sharp>* Q\" by fact\n    with xEq xFreshxvec' yFreshxvec' have \"xvec' \\<sharp>* ([(x, y)] \\<bullet> Q)\" by simp\n    moreover have \"Suc n = length xvec\" by fact\n    with xEq have \"n = length xvec'\" by simp\n    moreover from xvec'Freshyvec' xFreshxvec' yFreshxvec' have \"xvec' \\<sharp>* ([(x, y)] \\<bullet> yvec')\"\n      by simp\n    moreover from L' have \"length xvec' = length([(x, y)] \\<bullet> yvec')\" by simp\n    ultimately have \"distinct([(x, y)] \\<bullet> yvec')\" using xvec'Dist\n      by(rule_tac Suc)\n    hence \"distinct yvec'\" by simp\n    from Mem xEq have xSuppM: \"x \\<in> supp M\" by simp\n    from L xvecFreshyvec xvecDist xvecFreshN xvecFreshQ\n    have \"inputChain yvec N Q = inputChain xvec ([yvec xvec] \\<bullet>\\<^sub>v N) ([yvec xvec] \\<bullet>\\<^sub>v Q)\"\n      by(simp add: alphaInputChain)\n    with Eq have \"M = [yvec xvec] \\<bullet>\\<^sub>v N\"  by auto\n    with xEq yEq have \"M = [(y, x)] \\<bullet> [yvec' xvec'] \\<bullet>\\<^sub>v N\"\n      by simp\n    with xSuppM have ySuppN: \"y \\<in> supp([yvec' xvec'] \\<bullet>\\<^sub>v N)\"\n      by(drule_tac pi=\"[(x, y)]\" in pt_set_bij2[OF pt_name_inst, OF at_name_inst])\n        (simp add: calc_atm eqvts name_swap)\n    have \"y \\<sharp> yvec'\"\n    proof(simp add: fresh_def, rule notI)\n      assume \"y \\<in> supp yvec'\"\n      hence \"y mem yvec'\"\n        by(induct yvec') (auto simp add: supp_list_nil supp_list_cons supp_atm)\n      moreover from xvecFreshN xEq xFreshxvec' have \"xvec' \\<sharp>* N\" by simp\n      ultimately have \"y \\<sharp> [yvec' xvec'] \\<bullet>\\<^sub>v  N\" using L' xvec'Freshyvec' xvec'Dist\n        by(force intro: freshChainPerm simp add: freshChainSym)\n      with ySuppN show \"False\" by(simp add: fresh_def)\n    qed\n    with \\<open>distinct yvec'\\<close>  yEq show ?case by simp\n  qed\nqed\n\nlemma psiCasesInject[simp]:\n  fixes CsP  :: \"('c::fs_name \\<times> ('a::fs_name, 'b::fs_name, 'c) psi) list\"\n  and   CsQ  :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n\n  shows \"(psiCases CsP = psiCases CsQ) = (CsP = CsQ)\"\nproof(induct CsP arbitrary: CsQ)\n  case(Nil CsQ)\n  thus ?case by(case_tac CsQ) (auto)\nnext\n  case(Cons a CsP CsQ)\n  thus ?case\n    by(case_tac a, case_tac CsQ) (clarsimp simp add: psiCase.inject)+\nqed\n\nlemma casesInject[simp]:\n  fixes CsP :: \"('c::fs_name \\<times> ('a::fs_name, 'b::fs_name, 'c) psi) list\"\n  and   CsQ :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n\n  shows \"(Cases CsP = Cases CsQ) = (CsP = CsQ)\"\napply(induct CsP)\napply(auto simp add: psiCase.inject)\napply(case_tac CsQ)\napply(simp add: psiCase.inject psi.inject)\napply(force simp add: psiCase.inject psi.inject)\napply(case_tac CsQ)\napply(force simp add: psiCase.inject psi.inject)\napply(auto simp add: psiCase.inject psi.inject)\napply(simp only: psiCases.simps[symmetric])\napply(simp only: psiCasesInject)\napply simp\napply(case_tac CsQ)\nby(auto simp add: psiCase.inject psi.inject)\n\nnominal_primrec\n  guarded :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi \\<Rightarrow> bool\"\n  and guarded'  :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) input \\<Rightarrow> bool\"\n  and guarded'' :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psiCase \\<Rightarrow> bool\"\n\nwhere\n  \"guarded (\\<zero>) = True\"\n| \"guarded (M\\<langle>N\\<rangle>.P) = True\"\n| \"guarded (M\\<lparr>I) = True\"\n| \"guarded (Case C) = guarded'' C\"\n| \"guarded (P \\<parallel> Q) = ((guarded P) \\<and> (guarded Q))\"\n| \"guarded (\\<lparr>\\<nu>x\\<rparr>P) = (guarded P)\"\n| \"guarded (\\<lbrace>\\<Psi>\\<rbrace>) = False\"\n| \"guarded (!P) = guarded P\"\n\n| \"guarded' (Trm M P) = False\"\n| \"guarded' (\\<nu> y I) = False\"\n\n| \"guarded'' (\\<bottom>\\<^sub>c) = True\"\n| \"guarded'' (\\<box>\\<phi> \\<Rightarrow> P C) = (guarded P \\<and> guarded'' C)\"\napply(finite_guess)+\napply(rule TrueI)+\nby(fresh_guess add: fresh_bool)+\n\nlemma guardedEqvt[eqvt]:\n  fixes p    :: \"name prm\"\n  and   P    :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi\"\n  and   I    :: \"('a, 'b, 'c) input\"\n  and   C    :: \"('a, 'b, 'c) psiCase\"\n\n  shows \"(p \\<bullet> (guarded P)) = guarded (p \\<bullet> P)\"\n  and   \"(p \\<bullet> (guarded' I)) = guarded' (p \\<bullet> I)\"\n  and   \"(p \\<bullet> (guarded'' C)) = guarded'' (p \\<bullet> C)\"\nby(nominal_induct P and I and C rule: psi_input_psiCase.strong_inducts)\n  (simp add: eqvts)+\n\nlemma guardedClosed[simp]:\n  fixes P :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi\"\n  and   p :: \"name prm\"\n\n  assumes \"guarded P\"\n\n  shows \"guarded(p \\<bullet> P)\"\nproof -\n  from \\<open>guarded P\\<close> have \"p \\<bullet> (guarded P)\"\n    by(simp add: perm_bool)\n  thus ?thesis by(simp add: eqvts)\nqed\n\nlocale substPsi =\n  substTerm?: substType substTerm +\n  substAssert?: substType substAssert +\n  substCond?: substType substCond\n\n  for substTerm :: \"('a::fs_name) \\<Rightarrow> name list \\<Rightarrow> 'a::fs_name list \\<Rightarrow> 'a\"\n  and substAssert :: \"('b::fs_name) \\<Rightarrow> name list \\<Rightarrow> 'a::fs_name list \\<Rightarrow> 'b\"\n  and substCond :: \"('c::fs_name) \\<Rightarrow> name list \\<Rightarrow> 'a::fs_name list \\<Rightarrow> 'c\"\nbegin\n\nnominal_primrec \n    subs   :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psi \\<Rightarrow> name list \\<Rightarrow> 'a list \\<Rightarrow> ('a, 'b, 'c) psi\"\nand subs'  :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) input \\<Rightarrow> name list \\<Rightarrow> 'a list \\<Rightarrow> ('a, 'b, 'c) input\"\nand subs'' :: \"('a::fs_name, 'b::fs_name, 'c::fs_name) psiCase \\<Rightarrow> name list \\<Rightarrow> 'a list  \\<Rightarrow> ('a, 'b, 'c) psiCase\"\n\nwhere\n  \"subs (\\<zero>) xvec Tvec = \\<zero>\"\n| \"(subs (M\\<langle>N\\<rangle>.P) xvec Tvec) = (substTerm M xvec Tvec)\\<langle>(substTerm N xvec Tvec)\\<rangle>.(subs P xvec Tvec)\"\n| \"(subs (M\\<lparr>I) xvec Tvec) = (substTerm M xvec Tvec)\\<lparr>(subs' I xvec Tvec)\"\n\n| \"(subs (Case C) xvec Tvec) = (Case (subs'' C xvec Tvec))\"\n| \"(subs (P \\<parallel> Q) xvec Tvec) = (subs P xvec Tvec) \\<parallel> (subs Q xvec Tvec)\"\n| \"\\<lbrakk>y \\<sharp> xvec; y \\<sharp> Tvec\\<rbrakk> \\<Longrightarrow> (subs (\\<lparr>\\<nu>y\\<rparr>P) xvec Tvec) = \\<lparr>\\<nu>y\\<rparr>(subs P xvec Tvec)\"\n| \"(subs (\\<lbrace>\\<Psi>\\<rbrace>) xvec Tvec) = \\<lbrace>(substAssert \\<Psi> xvec Tvec)\\<rbrace>\"\n| \"(subs (!P) xvec Tvec) = !(subs P xvec Tvec)\"\n\n| \"(subs' ((Trm M P)::('a::fs_name, 'b::fs_name, 'c::fs_name) input) xvec Tvec) = (\\<rparr>(substTerm M xvec Tvec).(subs P xvec Tvec))\"\n| \"\\<lbrakk>y \\<sharp> xvec; y \\<sharp> Tvec\\<rbrakk> \\<Longrightarrow> (subs' (\\<nu> y I) xvec Tvec) = (\\<nu> y (subs' I xvec Tvec))\"\n\n| \"(subs'' (\\<bottom>\\<^sub>c::('a::fs_name, 'b::fs_name, 'c::fs_name) psiCase) xvec Tvec) = \\<bottom>\\<^sub>c\"\n| \"(subs'' (\\<box>\\<Phi> \\<Rightarrow> P C) xvec Tvec) = (\\<box>(substCond \\<Phi> xvec Tvec) \\<Rightarrow> (subs P xvec Tvec) (subs'' C xvec Tvec))\"\napply(finite_guess add: substTerm.fs substAssert.fs substCond.fs)+\napply(rule TrueI)+\napply(simp add: abs_fresh)\napply(simp add: abs_fresh)\napply(simp add: abs_fresh)\napply(rule supports_fresh[of \"supp(xvec, Tvec)\"])\napply(force simp add: perm_fun_def eqvts fresh_def[symmetric] supports_def)\napply(simp add: fs_name1)\napply(simp add: fresh_def[symmetric])\napply(rule supports_fresh[of \"supp(xvec, Tvec)\"])\napply(force simp add: perm_fun_def eqvts fresh_def[symmetric] supports_def)\napply(simp add: fs_name1)\napply(simp add: fresh_def[symmetric])\napply(fresh_guess)+\napply(rule supports_fresh[of \"supp(xvec, Tvec)\"])\napply(force simp add: perm_fun_def eqvts fresh_def[symmetric] supports_def)\napply(simp add: fs_name1)\napply(simp add: fresh_def[symmetric])\napply(fresh_guess)+\napply(rule supports_fresh[of \"supp(xvec, Tvec)\"])\napply(force simp add: perm_fun_def eqvts fresh_def[symmetric] supports_def)\napply(simp add: fs_name1)\napply(simp add: fresh_def[symmetric])\napply(fresh_guess)+\napply(rule supports_fresh[of \"supp(xvec, Tvec)\"])\napply(force simp add: perm_fun_def eqvts fresh_def[symmetric] supports_def)\napply(simp add: fs_name1)\napply(simp add: fresh_def[symmetric])\napply(fresh_guess)\napply(rule supports_fresh[of \"supp(xvec, Tvec)\"])\napply(force simp add: perm_fun_def eqvts fresh_def[symmetric] supports_def)\napply(simp add: fs_name1)\napply(simp add: fresh_def[symmetric])\napply(rule supports_fresh[of \"supp(xvec, Tvec)\"])\napply(force simp add: perm_fun_def eqvts fresh_def[symmetric] supports_def)\napply(simp add: fs_name1)\napply(simp add: fresh_def[symmetric])\napply(fresh_guess)+\napply(rule supports_fresh[of \"supp(xvec, Tvec)\"])\napply(force simp add: perm_fun_def eqvts fresh_def[symmetric] supports_def)\napply(simp add: fs_name1)\napply(simp add: fresh_def[symmetric])\napply(fresh_guess)+\napply(rule supports_fresh[of \"supp(xvec, Tvec)\"])\napply(force simp add: perm_fun_def eqvts fresh_def[symmetric] supports_def)\napply(simp add: fs_name1)\napply(simp add: fresh_def[symmetric])\napply(fresh_guess)+\napply(rule supports_fresh[of \"supp(xvec, Tvec)\"])\napply(force simp add: perm_fun_def eqvts fresh_def[symmetric] supports_def)\napply(simp add: fs_name1)\napply(simp add: fresh_def[symmetric])\ndone\n\nlemma substEqvt[eqvt]:\n  fixes p    :: \"name prm\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   xvec :: \"name list\"\n  and   Tvec :: \"'a list\"\n  and   I    :: \"('a, 'b, 'c) input\"\n  and   C    :: \"('a, 'b, 'c) psiCase\"\n\n  shows \"(p \\<bullet> (subs P xvec Tvec)) = subs (p \\<bullet> P) (p \\<bullet> xvec) (p \\<bullet> Tvec)\"\n  and   \"(p \\<bullet> (subs' I xvec Tvec)) = subs' (p \\<bullet> I) (p \\<bullet> xvec) (p \\<bullet> Tvec)\"\n  and   \"(p \\<bullet> (subs'' C xvec Tvec)) = subs'' (p \\<bullet> C) (p \\<bullet> xvec) (p \\<bullet> Tvec)\"\napply(nominal_induct P and I and C avoiding: xvec Tvec rule: psi_input_psiCase.strong_inducts)\napply(auto simp add: eqvts)\napply(drule_tac pi=p in pt_fresh_bij1[OF pt_name_inst, OF at_name_inst])\napply(drule_tac pi=p in pt_fresh_bij1[OF pt_name_inst, OF at_name_inst])\napply simp\napply(drule_tac pi=p in pt_fresh_bij1[OF pt_name_inst, OF at_name_inst])\napply(drule_tac pi=p in pt_fresh_bij1[OF pt_name_inst, OF at_name_inst])\nby simp\n\nlemma subst2[intro]:\n  fixes xvec :: \"name list\"\n  and   Tvec :: \"'a list\"\n  and   x    :: name\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   I    :: \"('a, 'b, 'c) input\"\n  and   C    :: \"('a, 'b, 'c) psiCase\"\n\n  assumes \"x \\<sharp> Tvec\"\n  and     \"x \\<sharp> xvec\"\n\n  shows \"x \\<sharp> P \\<Longrightarrow> x \\<sharp> (subs P xvec Tvec)\"\n  and   \"x \\<sharp> I \\<Longrightarrow> x \\<sharp> (subs' I xvec Tvec)\"\n  and   \"x \\<sharp> C \\<Longrightarrow> x \\<sharp> (subs'' C xvec Tvec)\"\nusing assms\nby(nominal_induct P and I and C avoiding: xvec Tvec rule: psi_input_psiCase.strong_inducts)\n  (auto intro: substTerm.subst2 substCond.subst2 substAssert.subst2 simp add: abs_fresh)\n\nlemma subst2Chain[intro]:\n  fixes xvec :: \"name list\"\n  and   Tvec :: \"'a list\"\n  and   Xs   :: \"name set\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   I    :: \"('a, 'b, 'c) input\"\n  and   C    :: \"('a, 'b, 'c) psiCase\"\n\n  assumes \"Xs \\<sharp>* xvec\"\n  and     \"Xs \\<sharp>* Tvec\"\n\n  shows \"Xs \\<sharp>* P \\<Longrightarrow> Xs \\<sharp>* (subs P xvec Tvec)\"\n  and   \"Xs \\<sharp>* I \\<Longrightarrow> Xs \\<sharp>* (subs' I xvec Tvec)\"\n  and   \"Xs \\<sharp>* C \\<Longrightarrow> Xs \\<sharp>* (subs'' C xvec Tvec)\"\nusing assms\nby(auto intro: subst2 simp add: fresh_star_def)\n\nlemma renaming:\n  fixes xvec :: \"name list\"\n  and   Tvec :: \"'a list\"\n  and   p    :: \"name prm\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   I    :: \"('a ,'b, 'c) input\"\n  and   C    :: \"('a, 'b, 'c) psiCase\"\n\n  assumes \"length xvec = length Tvec\"\n  and     \"set p \\<subseteq> set xvec \\<times> set (p \\<bullet> xvec)\"\n  and     \"distinctPerm p\"\n\n  shows \"\\<lbrakk>(p \\<bullet> xvec) \\<sharp>* P\\<rbrakk> \\<Longrightarrow> (subs P xvec Tvec) = subs (p \\<bullet> P) (p \\<bullet> xvec) Tvec\"\n  and   \"\\<lbrakk>(p \\<bullet> xvec) \\<sharp>* I\\<rbrakk> \\<Longrightarrow> (subs' I xvec Tvec) = subs' (p \\<bullet> I) (p \\<bullet> xvec) Tvec\"\n  and   \"\\<lbrakk>(p \\<bullet> xvec) \\<sharp>* C\\<rbrakk> \\<Longrightarrow> (subs'' C xvec Tvec) = subs'' (p \\<bullet> C) (p \\<bullet> xvec) Tvec\"\nusing assms\nby(nominal_induct P and I and C avoiding: xvec p Tvec rule: psi_input_psiCase.strong_inducts)\n  (auto intro: substTerm.renaming substCond.renaming substAssert.renaming simp add: freshChainSimps psi.inject input.inject psiCase.inject)\n\nlemma subst4Chain:\n  fixes xvec :: \"name list\"\n  and   Tvec :: \"'a list\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   I    :: \"('a, 'b, 'c) input\"\n  and   C    :: \"('a, 'b, 'c) psiCase\"\n\n  assumes \"length xvec = length Tvec\"\n  and     \"distinct xvec\"\n  and     \"xvec \\<sharp>* Tvec\"\n\n  shows \"xvec \\<sharp>* (subs P xvec Tvec)\"\n  and   \"xvec \\<sharp>* (subs' I xvec Tvec)\"\n  and   \"xvec \\<sharp>* (subs'' C xvec Tvec)\"\nusing assms\nby(nominal_induct P and I and C avoiding: xvec Tvec rule: psi_input_psiCase.strong_inducts)\n  (auto intro: substTerm.subst4Chain substCond.subst4Chain substAssert.subst4Chain simp add: abs_fresh)\n\nlemma guardedSubst[simp]:\n  fixes P    :: \"('a, 'b, 'c) psi\"\n  and   I    :: \"('a, 'b, 'c) input\"\n  and   C    :: \"('a, 'b, 'c) psiCase\"\n  and   xvec :: \"name list\"\n  and   Tvec :: \"'a list\"\n\n  assumes \"length xvec = length Tvec\"\n  and     \"distinct xvec\"\n\n  shows \"guarded P \\<Longrightarrow> guarded(subs P xvec Tvec)\"\n  and   \"guarded' I \\<Longrightarrow> guarded'(subs' I xvec Tvec)\"\n  and   \"guarded'' C \\<Longrightarrow> guarded''(subs'' C xvec Tvec)\"\nusing assms\nby(nominal_induct P and I and C avoiding: xvec Tvec rule: psi_input_psiCase.strong_inducts) auto\n\ndefinition seqSubs :: \"('a, 'b, 'c) psi \\<Rightarrow> (name list \\<times> 'a list) list \\<Rightarrow> ('a, 'b, 'c) psi\" (\"_[<_>]\" [80, 80] 130)\n  where \"P[<\\<sigma>>] \\<equiv> foldl (\\<lambda>Q. \\<lambda>(xvec, Tvec). subs Q xvec Tvec) P \\<sigma>\"\n\ndefinition seqSubs' :: \"('a, 'b, 'c) input \\<Rightarrow> (name list \\<times> 'a list) list \\<Rightarrow> ('a, 'b, 'c) input\" \n  where \"seqSubs' I \\<sigma> \\<equiv> foldl (\\<lambda>Q. \\<lambda>(xvec, Tvec). subs' Q xvec Tvec) I \\<sigma>\"\n\ndefinition seqSubs'' :: \"('a, 'b, 'c) psiCase \\<Rightarrow> (name list \\<times> 'a list) list \\<Rightarrow> ('a, 'b, 'c) psiCase\"\n  where \"seqSubs'' C \\<sigma> \\<equiv> foldl (\\<lambda>Q. \\<lambda>(xvec, Tvec). subs'' Q xvec Tvec) C \\<sigma>\"\n\nlemma substInputChain[simp]:\n  fixes xvec :: \"name list\"\n  and   N    :: \"'a\"\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   yvec :: \"name list\"\n  and   Tvec :: \"'a list\"\n\n  assumes \"xvec \\<sharp>* yvec\"\n  and     \"xvec \\<sharp>* Tvec\"\n\n  shows \"subs' (inputChain xvec N P) yvec Tvec = inputChain xvec (substTerm N yvec Tvec) (subs P yvec Tvec)\"\nusing assms\nby(induct xvec) (auto simp add: psi.inject)\n\nfun caseListSubst :: \"('c \\<times> ('a, 'b, 'c) psi) list \\<Rightarrow> name list \\<Rightarrow> 'a list \\<Rightarrow> ('c \\<times> ('a, 'b, 'c) psi) list\"\nwhere\n  \"caseListSubst [] _ _ = []\"\n| \"caseListSubst ((\\<phi>, P)#Cs) xvec Tvec = (substCond \\<phi> xvec Tvec, (subs P xvec Tvec))#(caseListSubst Cs xvec Tvec)\"\n\n\n\n  shows \"subs (Cases Cs) xvec Tvec = Cases(caseListSubst Cs xvec Tvec)\"\nby(induct Cs) (auto simp add: psi.inject)\n\nlemma substCases'[simp]:\n  fixes Cs   :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n  and   xvec :: \"name list\"\n  and   Tvec :: \"'a list\"\n\n  shows \"(subs'' (psiCases Cs) xvec Tvec) = psiCases(caseListSubst Cs xvec Tvec)\"\nby(induct Cs) auto\n\nlemma seqSubstSimps[simp]:\n  shows \"seqSubs (\\<zero>) \\<sigma> = \\<zero>\"\n  and   \"(seqSubs (M\\<langle>N\\<rangle>.P) \\<sigma>) = (substTerm.seqSubst M \\<sigma>)\\<langle>(substTerm.seqSubst N \\<sigma>)\\<rangle>.(seqSubs P \\<sigma>)\"\n  and   \"(seqSubs (M\\<lparr>I) \\<sigma>) = (substTerm.seqSubst M \\<sigma>)\\<lparr>(seqSubs' I \\<sigma>)\"\n\n  and   \"(seqSubs (Case C) \\<sigma>) = (Case (seqSubs'' C \\<sigma>))\"\n  and   \"(seqSubs (P \\<parallel> Q) \\<sigma>) = (seqSubs P \\<sigma>) \\<parallel> (seqSubs Q \\<sigma>)\"\n  and   \"\\<lbrakk>y \\<sharp> \\<sigma>\\<rbrakk> \\<Longrightarrow> (seqSubs (\\<lparr>\\<nu>y\\<rparr>P) \\<sigma>) = \\<lparr>\\<nu>y\\<rparr>(seqSubs P \\<sigma>)\"\n  and   \"(seqSubs (\\<lbrace>\\<Psi>\\<rbrace>) \\<sigma>) = \\<lbrace>(substAssert.seqSubst \\<Psi> \\<sigma>)\\<rbrace>\"\n  and   \"(seqSubs (!P) \\<sigma>) = !(seqSubs P \\<sigma>)\"\n  \n  and   \"(seqSubs' ((Trm M P)::('a::fs_name, 'b::fs_name, 'c::fs_name) input) \\<sigma>) = (\\<rparr>(substTerm.seqSubst M \\<sigma>).(seqSubs P \\<sigma>))\"\n  and   \"\\<lbrakk>y \\<sharp> \\<sigma>\\<rbrakk> \\<Longrightarrow> (seqSubs' (\\<nu> y I) \\<sigma>) = (\\<nu> y (seqSubs' I \\<sigma>))\"\n  \n  and   \"(seqSubs'' (\\<bottom>\\<^sub>c::('a::fs_name, 'b::fs_name, 'c::fs_name) psiCase) \\<sigma>) = \\<bottom>\\<^sub>c\"\n  and   \"(seqSubs'' (\\<box>\\<Phi> \\<Rightarrow> P C) \\<sigma>) = (\\<box>(substCond.seqSubst \\<Phi> \\<sigma>) \\<Rightarrow> (seqSubs P \\<sigma>) (seqSubs'' C \\<sigma>))\"\nby(induct \\<sigma> arbitrary: M N P I C Q \\<Psi> \\<Phi>, auto simp add: seqSubs_def seqSubs'_def seqSubs''_def)\n\nlemma seqSubsNil[simp]:\n  \"seqSubs P [] = P\"\nby(simp add: seqSubs_def)\n\nlemma seqSubsCons[simp]:\n  shows \"seqSubs P ((xvec, Tvec)#\\<sigma>) = seqSubs(subs P xvec Tvec) \\<sigma>\"\n  by(simp add: seqSubs_def)\n\nlemma seqSubsTermAppend[simp]:\n  shows \"seqSubs P (\\<sigma>@\\<sigma>') = seqSubs (seqSubs P \\<sigma>) \\<sigma>'\"\nby(induct \\<sigma>) (auto simp add: seqSubs_def)\n\nfun caseListSeqSubst :: \"('c \\<times> ('a, 'b, 'c) psi) list \\<Rightarrow> (name list \\<times> 'a list) list \\<Rightarrow> ('c \\<times> ('a, 'b, 'c) psi) list\"\nwhere\n  \"caseListSeqSubst [] _ = []\"\n| \"caseListSeqSubst ((\\<phi>, P)#Cs) \\<sigma> = (substCond.seqSubst \\<phi> \\<sigma>, (seqSubs P \\<sigma>))#(caseListSeqSubst Cs \\<sigma>)\"\n\nlemma seqSubstCases[simp]:\n  fixes Cs :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n  and   \\<sigma>  :: \"(name list \\<times> 'a list) list\"\n\n  shows \"seqSubs (Cases Cs) \\<sigma> = Cases(caseListSeqSubst Cs \\<sigma>)\"\nby(induct Cs) (auto simp add: psi.inject)\n\nlemma seqSubstCases'[simp]:\n  fixes Cs :: \"('c \\<times> ('a, 'b, 'c) psi) list\"\n  and   \\<sigma>  :: \"(name list \\<times> 'a list) list\"\n\n  shows \"(seqSubs'' (psiCases Cs) \\<sigma>) = psiCases(caseListSeqSubst Cs \\<sigma>)\"\nby(induct Cs) auto\n\nlemma seqSubstEqvt[eqvt]:\n  fixes P :: \"('a, 'b, 'c) psi\"\n  and   \\<sigma> :: \"(name list \\<times> 'a list) list\"\n  and   p :: \"name prm\"\n\n  shows \"(p \\<bullet> (P[<\\<sigma>>])) = (p \\<bullet> P)[<(p \\<bullet> \\<sigma>)>]\"\nby(induct \\<sigma> arbitrary: P) (auto simp add: eqvts seqSubs_def)\n\nlemma guardedSeqSubst:\n  assumes \"guarded P\"\n  and     \"wellFormedSubst \\<sigma>\"\n\n  shows \"guarded(seqSubs P \\<sigma>)\"\nusing assms\nby(induct \\<sigma> arbitrary: P) (auto dest: guardedSubst)\n\nend\n\nlemma inter_eqvt:\n  shows \"(pi::name prm) \\<bullet> ((X::name set) \\<inter> Y) = (pi \\<bullet> X) \\<inter> (pi \\<bullet> Y)\"\nby(auto simp add: perm_set_def perm_bij)\n\nlemma delete_eqvt:\n  fixes p :: \"name prm\"\n  and   X :: \"name set\"\n  and   Y :: \"name set\"\n\n  shows \"p \\<bullet> (X - Y) = (p \\<bullet> X) - (p \\<bullet> Y)\"\nby(auto simp add: perm_set_def perm_bij)\n\nlemma perm_singleton[simp]:\n  shows \"(p::name prm) \\<bullet> {(x::name)} = {p \\<bullet> x}\"\nby(auto simp add: perm_set_def)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Psi_Calculi/Agent.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.45326184801538616, "lm_q1q2_score": 0.2513203076179137}}
{"text": "(*  Title:      HOL/Hoare/HeapSyntaxAbort.thy\n    Author:     Tobias Nipkow\n    Copyright   2002 TUM\n*)\n\ntheory HeapSyntaxAbort imports Hoare_Logic_Abort Heap begin\n\nsubsection \"Field access and update\"\n\ntext\\<open>Heap update \\<open>p^.h := e\\<close> is now guarded against @{term p}\nbeing Null. However, @{term p} may still be illegal,\ne.g. uninitialized or dangling. To guard against that, one needs a\nmore detailed model of the heap where allocated and free addresses are\ndistinguished, e.g. by making the heap a map, or by carrying the set\nof free addresses around. This is needed anyway as soon as we want to\nreason about storage allocation/deallocation.\\<close>\n\nsyntax\n  \"_refupdate\" :: \"('a \\<Rightarrow> 'b) \\<Rightarrow> 'a ref \\<Rightarrow> 'b \\<Rightarrow> ('a \\<Rightarrow> 'b)\"\n   (\"_/'((_ \\<rightarrow> _)')\" [1000,0] 900)\n  \"_fassign\"  :: \"'a ref => id => 'v => 's com\"\n   (\"(2_^._ :=/ _)\" [70,1000,65] 61)\n  \"_faccess\"  :: \"'a ref => ('a ref \\<Rightarrow> 'v) => 'v\"\n   (\"_^._\" [65,1000] 65)\ntranslations\n  \"_refupdate f r v\" == \"f(CONST addr r := v)\"\n  \"p^.f := e\" => \"(p \\<noteq> CONST Null) \\<rightarrow> (f := _refupdate f p e)\"\n  \"p^.f\" => \"f(CONST addr p)\"\n\n\ndeclare fun_upd_apply[simp del] fun_upd_same[simp] fun_upd_other[simp]\n\n\ntext \"An example due to Suzuki:\"\n\nlemma \"VARS v n\n  {w = Ref w0 & x = Ref x0 & y = Ref y0 & z = Ref z0 &\n   distinct[w0,x0,y0,z0]}\n  w^.v := (1::int); w^.n := x;\n  x^.v := 2; x^.n := y;\n  y^.v := 3; y^.n := z;\n  z^.v := 4; x^.n := z\n  {w^.n^.n^.v = 4}\"\nby vcg_simp\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/HOL/Hoare/HeapSyntaxAbort.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.4532618480153861, "lm_q1q2_score": 0.2513203076179137}}
{"text": "(*\n(C) Copyright Andreas Viktor Hess, DTU, 2018-2020\n\nAll Rights Reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\n- Redistributions of source code must retain the above copyright\n  notice, this list of conditions and the following disclaimer.\n\n- Redistributions in binary form must reproduce the above copyright\n  notice, this list of conditions and the following disclaimer in the\n  documentation and/or other materials provided with the distribution.\n\n- Neither the name of the copyright holder nor the names of its\n  contributors may be used to endorse or promote products\n  derived from this software without specific prior written\n  permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\nLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\nA PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\nOWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\nLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\nTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n*)\n\n(*  Title:      Stateful_Strands.thy\n    Author:     Andreas Viktor Hess, DTU\n*)\n\n\nsection \\<open>Stateful Strands\\<close>\ntheory Stateful_Strands\nimports Strands_and_Constraints\nbegin\n\nsubsection \\<open>Stateful Constraints\\<close>\ndatatype (funs\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p: 'a, vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p: 'b) stateful_strand_step = \n  Send (the_msg: \"('a,'b) term\") (\"send\\<langle>_\\<rangle>\" 80)\n| Receive (the_msg: \"('a,'b) term\") (\"receive\\<langle>_\\<rangle>\" 80)\n| Equality (the_check: poscheckvariant) (the_lhs: \"('a,'b) term\") (the_rhs: \"('a,'b) term\")\n    (\"\\<langle>_: _ \\<doteq> _\\<rangle>\" [80,80])\n| Insert (the_elem_term: \"('a,'b) term\") (the_set_term: \"('a,'b) term\") (\"insert\\<langle>_,_\\<rangle>\" 80)\n| Delete (the_elem_term: \"('a,'b) term\") (the_set_term: \"('a,'b) term\") (\"delete\\<langle>_,_\\<rangle>\" 80)\n| InSet (the_check: poscheckvariant) (the_elem_term: \"('a,'b) term\") (the_set_term: \"('a,'b) term\")\n    (\"\\<langle>_: _ \\<in> _\\<rangle>\" [80,80])\n| NegChecks (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p: \"'b list\")\n    (the_eqs: \"(('a,'b) term \\<times> ('a,'b) term) list\")\n    (the_ins: \"(('a,'b) term \\<times> ('a,'b) term) list\")\n    (\"\\<forall>_\\<langle>\\<or>\\<noteq>: _ \\<or>\\<notin>: _\\<rangle>\" [80,80])\nwhere\n  \"bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Send _) = []\"\n| \"bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Receive _) = []\"\n| \"bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Equality _ _ _) = []\"\n| \"bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Insert _ _) = []\"\n| \"bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Delete _ _) = []\"\n| \"bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (InSet _ _ _) = []\"\n\ntype_synonym ('a,'b) stateful_strand = \"('a,'b) stateful_strand_step list\"\ntype_synonym ('a,'b) dbstatelist = \"(('a,'b) term \\<times> ('a,'b) term) list\"\ntype_synonym ('a,'b) dbstate = \"(('a,'b) term \\<times> ('a,'b) term) set\"\n\nabbreviation\n  \"is_Assignment x \\<equiv> (is_Equality x \\<or> is_InSet x) \\<and> the_check x = Assign\"\n\nabbreviation\n  \"is_Check x \\<equiv> ((is_Equality x \\<or> is_InSet x) \\<and> the_check x = Check) \\<or> is_NegChecks x\"\n\nabbreviation\n  \"is_Update x \\<equiv> is_Insert x \\<or> is_Delete x\"\n\nabbreviation InSet_select (\"select\\<langle>_,_\\<rangle>\") where \"select\\<langle>t,s\\<rangle> \\<equiv> InSet Assign t s\"\nabbreviation InSet_check (\"\\<langle>_ in _\\<rangle>\") where \"\\<langle>t in s\\<rangle> \\<equiv> InSet Check t s\"\nabbreviation Equality_assign (\"\\<langle>_ := _\\<rangle>\") where \"\\<langle>t := s\\<rangle> \\<equiv> Equality Assign t s\"\nabbreviation Equality_check (\"\\<langle>_ == _\\<rangle>\") where \"\\<langle>t == s\\<rangle> \\<equiv> Equality Check t s\"\n\nabbreviation NegChecks_Inequality1 (\"\\<langle>_ != _\\<rangle>\") where\n  \"\\<langle>t != s\\<rangle> \\<equiv> NegChecks [] [(t,s)] []\"\n\nabbreviation NegChecks_Inequality2 (\"\\<forall>_\\<langle>_ != _\\<rangle>\") where\n  \"\\<forall>x\\<langle>t != s\\<rangle> \\<equiv> NegChecks [x] [(t,s)] []\"\n\nabbreviation NegChecks_Inequality3 (\"\\<forall>_,_\\<langle>_ != _\\<rangle>\") where\n  \"\\<forall>x,y\\<langle>t != s\\<rangle> \\<equiv> NegChecks [x,y] [(t,s)] []\"\n\nabbreviation NegChecks_Inequality4 (\"\\<forall>_,_,_\\<langle>_ != _\\<rangle>\") where\n  \"\\<forall>x,y,z\\<langle>t != s\\<rangle> \\<equiv> NegChecks [x,y,z] [(t,s)] []\"\n\nabbreviation NegChecks_NotInSet1 (\"\\<langle>_ not in _\\<rangle>\") where\n  \"\\<langle>t not in s\\<rangle> \\<equiv> NegChecks [] [] [(t,s)]\"\n\nabbreviation NegChecks_NotInSet2 (\"\\<forall>_\\<langle>_ not in _\\<rangle>\") where\n  \"\\<forall>x\\<langle>t not in s\\<rangle> \\<equiv> NegChecks [x] [] [(t,s)]\"\n\nabbreviation NegChecks_NotInSet3 (\"\\<forall>_,_\\<langle>_ not in _\\<rangle>\") where\n  \"\\<forall>x,y\\<langle>t not in s\\<rangle> \\<equiv> NegChecks [x,y] [] [(t,s)]\"\n\nabbreviation NegChecks_NotInSet4 (\"\\<forall>_,_,_\\<langle>_ not in _\\<rangle>\") where\n  \"\\<forall>x,y,z\\<langle>t not in s\\<rangle> \\<equiv> NegChecks [x,y,z] [] [(t,s)]\"\n\nfun trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p where\n  \"trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Send t) = {t}\"\n| \"trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Receive t) = {t}\"\n| \"trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Equality _ t t') = {t,t'}\"\n| \"trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Insert t t') = {t,t'}\"\n| \"trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Delete t t') = {t,t'}\"\n| \"trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (InSet _ t t') = {t,t'}\"\n| \"trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (NegChecks _ F F') = trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F'\"\n\ndefinition trms\\<^sub>s\\<^sub>s\\<^sub>t where \"trms\\<^sub>s\\<^sub>s\\<^sub>t S \\<equiv> \\<Union>(trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p ` set S)\"\ndeclare trms\\<^sub>s\\<^sub>s\\<^sub>t_def[simp]\n\nfun trms_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p where\n  \"trms_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Send t) = [t]\"\n| \"trms_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Receive t) = [t]\"\n| \"trms_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Equality _ t t') = [t,t']\"\n| \"trms_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Insert t t') = [t,t']\"\n| \"trms_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Delete t t') = [t,t']\"\n| \"trms_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (InSet _ t t') = [t,t']\"\n| \"trms_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (NegChecks _ F F') = concat (map (\\<lambda>(t,t'). [t,t']) (F@F'))\"\n\ndefinition trms_list\\<^sub>s\\<^sub>s\\<^sub>t where \"trms_list\\<^sub>s\\<^sub>s\\<^sub>t S \\<equiv> remdups (concat (map trms_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p S))\"\n\ndefinition ik\\<^sub>s\\<^sub>s\\<^sub>t where \"ik\\<^sub>s\\<^sub>s\\<^sub>t A \\<equiv> {t. Receive t \\<in> set A}\"\n\ndefinition bvars\\<^sub>s\\<^sub>s\\<^sub>t::\"('a,'b) stateful_strand \\<Rightarrow> 'b set\" where\n  \"bvars\\<^sub>s\\<^sub>s\\<^sub>t S \\<equiv> \\<Union>(set (map (set \\<circ> bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p) S))\"\n\nfun fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p::\"('a,'b) stateful_strand_step \\<Rightarrow> 'b set\" where\n  \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Send t) = fv t\"\n| \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Receive t) = fv t\"\n| \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Equality _ t t') = fv t \\<union> fv t'\"\n| \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Insert t t') = fv t \\<union> fv t'\"\n| \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Delete t t') = fv t \\<union> fv t'\"\n| \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (InSet _ t t') = fv t \\<union> fv t'\"\n| \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (NegChecks X F F') = fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' - set X\"\n\ndefinition fv\\<^sub>s\\<^sub>s\\<^sub>t::\"('a,'b) stateful_strand \\<Rightarrow> 'b set\" where\n  \"fv\\<^sub>s\\<^sub>s\\<^sub>t S \\<equiv> \\<Union>(set (map fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p S))\"\n\nfun fv_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p where\n  \"fv_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (send\\<langle>t\\<rangle>) = fv_list t\"\n| \"fv_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (receive\\<langle>t\\<rangle>) = fv_list t\"\n| \"fv_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<langle>_: t \\<doteq> s\\<rangle>) = fv_list t@fv_list s\"\n| \"fv_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (insert\\<langle>t,s\\<rangle>) = fv_list t@fv_list s\"\n| \"fv_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (delete\\<langle>t,s\\<rangle>) = fv_list t@fv_list s\"\n| \"fv_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<langle>_: t \\<in> s\\<rangle>) = fv_list t@fv_list s\"\n| \"fv_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: F'\\<rangle>) = filter (\\<lambda>x. x \\<notin> set X) (fv_list\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (F@F'))\"\n\ndefinition fv_list\\<^sub>s\\<^sub>s\\<^sub>t where\n  \"fv_list\\<^sub>s\\<^sub>s\\<^sub>t S \\<equiv> remdups (concat (map fv_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p S))\"\n\ndeclare bvars\\<^sub>s\\<^sub>s\\<^sub>t_def[simp]\ndeclare fv\\<^sub>s\\<^sub>s\\<^sub>t_def[simp]\n\ndefinition vars\\<^sub>s\\<^sub>s\\<^sub>t::\"('a,'b) stateful_strand \\<Rightarrow> 'b set\" where\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t S \\<equiv> \\<Union>(set (map vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p S))\"\n\nabbreviation wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p::\"('a,'b) stateful_strand_step \\<Rightarrow> 'b set\" where\n  \"wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x \\<equiv>\n    case x of\n      NegChecks _ _ _ \\<Rightarrow> {}\n    | Equality Check _ _ \\<Rightarrow> {}\n    | InSet Check _ _ \\<Rightarrow> {}\n    | Delete _ _ \\<Rightarrow> {}\n    | _ \\<Rightarrow> vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x\"\n\ndefinition wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t::\"('a,'b) stateful_strand \\<Rightarrow> 'b set\" where\n  \"wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t S \\<equiv> \\<Union>(set (map wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p S))\"\n\nabbreviation wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p where\n  \"wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x \\<equiv> \n    case x of\n      Send t \\<Rightarrow> fv t\n    | Equality Assign s t \\<Rightarrow> fv s\n    | InSet Assign s t \\<Rightarrow> fv s \\<union> fv t\n    | _ \\<Rightarrow> {}\"\n\ndefinition wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t where\n  \"wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t S \\<equiv> \\<Union>(set (map wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p S))\"\n\nfun wf'\\<^sub>s\\<^sub>s\\<^sub>t::\"'b set \\<Rightarrow> ('a,'b) stateful_strand \\<Rightarrow> bool\" where\n  \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V [] = True\"\n| \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V (Receive t#S) = (fv t \\<subseteq> V \\<and> wf'\\<^sub>s\\<^sub>s\\<^sub>t V S)\"\n| \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V (Send t#S) = wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> fv t) S\"\n| \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V (Equality Assign t t'#S) = (fv t' \\<subseteq> V \\<and> wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> fv t) S)\"\n| \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V (Equality Check _ _#S) = wf'\\<^sub>s\\<^sub>s\\<^sub>t V S\"\n| \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V (Insert t s#S) = (fv t \\<subseteq> V \\<and> fv s \\<subseteq> V \\<and> wf'\\<^sub>s\\<^sub>s\\<^sub>t V S)\"\n| \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V (Delete _ _#S) = wf'\\<^sub>s\\<^sub>s\\<^sub>t V S\"\n| \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V (InSet Assign t s#S) = wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> fv t \\<union> fv s) S\"\n| \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V (InSet Check _ _#S) = wf'\\<^sub>s\\<^sub>s\\<^sub>t V S\"\n| \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V (NegChecks _ _ _#S) = wf'\\<^sub>s\\<^sub>s\\<^sub>t V S\"\n\nabbreviation \"wf\\<^sub>s\\<^sub>s\\<^sub>t S \\<equiv> wf'\\<^sub>s\\<^sub>s\\<^sub>t {} S \\<and> fv\\<^sub>s\\<^sub>s\\<^sub>t S \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t S = {}\"\n\nfun subst_apply_stateful_strand_step::\n  \"('a,'b) stateful_strand_step \\<Rightarrow> ('a,'b) subst \\<Rightarrow> ('a,'b) stateful_strand_step\"\n  (infix \"\\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p\" 51) where\n  \"send\\<langle>t\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta> = send\\<langle>t \\<cdot> \\<theta>\\<rangle>\"\n| \"receive\\<langle>t\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta> = receive\\<langle>t \\<cdot> \\<theta>\\<rangle>\"\n| \"\\<langle>a: t \\<doteq> s\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta> = \\<langle>a: (t \\<cdot> \\<theta>) \\<doteq> (s \\<cdot> \\<theta>)\\<rangle>\"\n| \"\\<langle>a: t \\<in> s\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta> = \\<langle>a: (t \\<cdot> \\<theta>) \\<in> (s \\<cdot> \\<theta>)\\<rangle>\"\n| \"insert\\<langle>t,s\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta> = insert\\<langle>t \\<cdot> \\<theta>, s \\<cdot> \\<theta>\\<rangle>\"\n| \"delete\\<langle>t,s\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta> = delete\\<langle>t \\<cdot> \\<theta>, s \\<cdot> \\<theta>\\<rangle>\"\n| \"\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: G\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta> = \\<forall>X\\<langle>\\<or>\\<noteq>: (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<theta>) \\<or>\\<notin>: (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<theta>)\\<rangle>\"\n\ndefinition subst_apply_stateful_strand::\n  \"('a,'b) stateful_strand \\<Rightarrow> ('a,'b) subst \\<Rightarrow> ('a,'b) stateful_strand\"\n  (infix \"\\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\" 51) where\n  \"S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta> \\<equiv> map (\\<lambda>x. x \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) S\"\n\nfun dbupd\\<^sub>s\\<^sub>s\\<^sub>t::\"('f,'v) stateful_strand \\<Rightarrow> ('f,'v) subst \\<Rightarrow> ('f,'v) dbstate \\<Rightarrow> ('f,'v) dbstate\"\nwhere\n  \"dbupd\\<^sub>s\\<^sub>s\\<^sub>t [] I D = D\"\n| \"dbupd\\<^sub>s\\<^sub>s\\<^sub>t (Insert t s#A) I D = dbupd\\<^sub>s\\<^sub>s\\<^sub>t A I (insert ((t,s) \\<cdot>\\<^sub>p I) D)\"\n| \"dbupd\\<^sub>s\\<^sub>s\\<^sub>t (Delete t s#A) I D = dbupd\\<^sub>s\\<^sub>s\\<^sub>t A I (D - {((t,s) \\<cdot>\\<^sub>p I)})\"\n| \"dbupd\\<^sub>s\\<^sub>s\\<^sub>t (_#A) I D = dbupd\\<^sub>s\\<^sub>s\\<^sub>t A I D\"\n\nfun db'\\<^sub>s\\<^sub>s\\<^sub>t::\"('f,'v) stateful_strand \\<Rightarrow> ('f,'v) subst \\<Rightarrow> ('f,'v) dbstatelist \\<Rightarrow> ('f,'v) dbstatelist\"\nwhere\n  \"db'\\<^sub>s\\<^sub>s\\<^sub>t [] I D = D\"\n| \"db'\\<^sub>s\\<^sub>s\\<^sub>t (Insert t s#A) I D = db'\\<^sub>s\\<^sub>s\\<^sub>t A I (List.insert ((t,s) \\<cdot>\\<^sub>p I) D)\"\n| \"db'\\<^sub>s\\<^sub>s\\<^sub>t (Delete t s#A) I D = db'\\<^sub>s\\<^sub>s\\<^sub>t A I (List.removeAll ((t,s) \\<cdot>\\<^sub>p I) D)\"\n| \"db'\\<^sub>s\\<^sub>s\\<^sub>t (_#A) I D = db'\\<^sub>s\\<^sub>s\\<^sub>t A I D\"\n\ndefinition db\\<^sub>s\\<^sub>s\\<^sub>t where\n  \"db\\<^sub>s\\<^sub>s\\<^sub>t S I \\<equiv> db'\\<^sub>s\\<^sub>s\\<^sub>t S I []\"\n\nfun setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p where\n  \"setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Insert t s) = {(t,s)}\"\n| \"setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Delete t s) = {(t,s)}\"\n| \"setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (InSet _ t s) = {(t,s)}\"\n| \"setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (NegChecks _ _ F') = set F'\"\n| \"setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p _ = {}\"\n\ntext \\<open>The set-operations of a stateful strand\\<close>\ndefinition setops\\<^sub>s\\<^sub>s\\<^sub>t where\n  \"setops\\<^sub>s\\<^sub>s\\<^sub>t S \\<equiv> \\<Union>(setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p ` set S)\"\n\nfun setops_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p where\n  \"setops_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Insert t s) = [(t,s)]\"\n| \"setops_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (Delete t s) = [(t,s)]\"\n| \"setops_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (InSet _ t s) = [(t,s)]\"\n| \"setops_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (NegChecks _ _ F') = F'\"\n| \"setops_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p _ = []\"\n\ntext \\<open>The set-operations of a stateful strand (list variant)\\<close>\ndefinition setops_list\\<^sub>s\\<^sub>s\\<^sub>t where\n  \"setops_list\\<^sub>s\\<^sub>s\\<^sub>t S \\<equiv> remdups (concat (map setops_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p S))\"\n\n\nsubsection \\<open>Small Lemmata\\<close>\nlemma trms_list\\<^sub>s\\<^sub>s\\<^sub>t_is_trms\\<^sub>s\\<^sub>s\\<^sub>t: \"trms\\<^sub>s\\<^sub>s\\<^sub>t S = set (trms_list\\<^sub>s\\<^sub>s\\<^sub>t S)\"\nunfolding trms\\<^sub>s\\<^sub>t_def trms_list\\<^sub>s\\<^sub>s\\<^sub>t_def\nproof (induction S)\n  case (Cons x S) thus ?case by (cases x) auto\nqed simp\n\nlemma setops_list\\<^sub>s\\<^sub>s\\<^sub>t_is_setops\\<^sub>s\\<^sub>s\\<^sub>t: \"setops\\<^sub>s\\<^sub>s\\<^sub>t S = set (setops_list\\<^sub>s\\<^sub>s\\<^sub>t S)\"\nunfolding setops\\<^sub>s\\<^sub>s\\<^sub>t_def setops_list\\<^sub>s\\<^sub>s\\<^sub>t_def\nproof (induction S)\n  case (Cons x S) thus ?case by (cases x) auto\nqed simp\n\nlemma fv_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_is_fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p: \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a = set (fv_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a)\"\nproof (cases a)\n  case (NegChecks X F G) thus ?thesis\n    using fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_append[of F G] fv_list\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_append[of F G]\n          fv_list\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_is_fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s[of \"F@G\"]\n    by auto\nqed (simp_all add: fv_list\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_is_fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s fv_list_is_fv)\n\nlemma fv_list\\<^sub>s\\<^sub>s\\<^sub>t_is_fv\\<^sub>s\\<^sub>s\\<^sub>t: \"fv\\<^sub>s\\<^sub>s\\<^sub>t S = set (fv_list\\<^sub>s\\<^sub>s\\<^sub>t S)\"\nunfolding fv\\<^sub>s\\<^sub>s\\<^sub>t_def fv_list\\<^sub>s\\<^sub>s\\<^sub>t_def by (induct S) (simp_all add: fv_list\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_is_fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p)\n\nlemma trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_finite[simp]: \"finite (trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x)\"\nby (cases x) auto\n\nlemma trms\\<^sub>s\\<^sub>s\\<^sub>t_finite[simp]: \"finite (trms\\<^sub>s\\<^sub>s\\<^sub>t S)\"\nusing trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_finite unfolding trms\\<^sub>s\\<^sub>s\\<^sub>t_def by (induct S) auto\n\nlemma vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_finite[simp]: \"finite (vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x)\"\nby (cases x) auto\n\nlemma vars\\<^sub>s\\<^sub>s\\<^sub>t_finite[simp]: \"finite (vars\\<^sub>s\\<^sub>s\\<^sub>t S)\"\nusing vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_finite unfolding vars\\<^sub>s\\<^sub>s\\<^sub>t_def by (induct S) auto\n\nlemma fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_finite[simp]: \"finite (fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x)\"\nby (cases x) auto\n\nlemma fv\\<^sub>s\\<^sub>s\\<^sub>t_finite[simp]: \"finite (fv\\<^sub>s\\<^sub>s\\<^sub>t S)\"\nusing fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_finite unfolding fv\\<^sub>s\\<^sub>s\\<^sub>t_def by (induct S) auto\n\nlemma bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_finite[simp]: \"finite (set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x))\"\nby (rule finite_set)\n\nlemma bvars\\<^sub>s\\<^sub>s\\<^sub>t_finite[simp]: \"finite (bvars\\<^sub>s\\<^sub>s\\<^sub>t S)\"\nusing bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_finite unfolding bvars\\<^sub>s\\<^sub>s\\<^sub>t_def by (induct S) auto\n\nlemma subst_sst_nil[simp]: \"[] \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta> = []\"\nby (simp add: subst_apply_stateful_strand_def)\n\nlemma db\\<^sub>s\\<^sub>s\\<^sub>t_nil[simp]: \"db\\<^sub>s\\<^sub>s\\<^sub>t [] \\<I> = []\"\nby (simp add: db\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma ik\\<^sub>s\\<^sub>s\\<^sub>t_nil[simp]: \"ik\\<^sub>s\\<^sub>s\\<^sub>t [] = {}\"\nby (simp add: ik\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma ik\\<^sub>s\\<^sub>s\\<^sub>t_append[simp]: \"ik\\<^sub>s\\<^sub>s\\<^sub>t (A@B) = ik\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> ik\\<^sub>s\\<^sub>s\\<^sub>t B\"\n  by (auto simp add: ik\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\n\n\nlemma db\\<^sub>s\\<^sub>s\\<^sub>t_set_is_dbupd\\<^sub>s\\<^sub>s\\<^sub>t: \"set (db'\\<^sub>s\\<^sub>s\\<^sub>t A I D) = dbupd\\<^sub>s\\<^sub>s\\<^sub>t A I (set D)\" (is \"?A = ?B\")\nproof\n  show \"?A \\<subseteq> ?B\"\n  proof\n    fix t s show \"(t,s) \\<in> ?A \\<Longrightarrow> (t,s) \\<in> ?B\" by (induct rule: db'\\<^sub>s\\<^sub>s\\<^sub>t.induct) auto\n  qed\n\n  show \"?B \\<subseteq> ?A\"\n  proof\n    fix t s show \"(t,s) \\<in> ?B \\<Longrightarrow> (t,s) \\<in> ?A\" by (induct arbitrary: D rule: dbupd\\<^sub>s\\<^sub>s\\<^sub>t.induct) auto\n  qed\nqed\n\nlemma dbupd\\<^sub>s\\<^sub>s\\<^sub>t_no_upd:\n  assumes \"\\<forall>a \\<in> set A. \\<not>is_Insert a \\<and> \\<not>is_Delete a\"\n  shows \"dbupd\\<^sub>s\\<^sub>s\\<^sub>t A I D = D\"\nusing assms\nproof (induction A)\n  case (Cons a A) thus ?case by (cases a) auto\nqed simp\n\nlemma db\\<^sub>s\\<^sub>s\\<^sub>t_no_upd:\n  assumes \"\\<forall>a \\<in> set A. \\<not>is_Insert a \\<and> \\<not>is_Delete a\"\n  shows \"db'\\<^sub>s\\<^sub>s\\<^sub>t A I D = D\"\nusing assms\nproof (induction A)\n  case (Cons a A) thus ?case by (cases a) auto\nqed simp\n\nlemma db\\<^sub>s\\<^sub>s\\<^sub>t_no_upd_append:\n  assumes \"\\<forall>b \\<in> set B. \\<not>is_Insert b \\<and> \\<not>is_Delete b\"\n  shows \"db'\\<^sub>s\\<^sub>s\\<^sub>t A = db'\\<^sub>s\\<^sub>s\\<^sub>t (A@B)\"\n  using assms\nproof (induction A)\n  case Nil thus ?case by (simp add: db\\<^sub>s\\<^sub>s\\<^sub>t_no_upd)\nnext\n  case (Cons a A) thus ?case by (cases a) simp_all\nqed\n\nlemma db\\<^sub>s\\<^sub>s\\<^sub>t_append:\n  \"db'\\<^sub>s\\<^sub>s\\<^sub>t (A@B) I D = db'\\<^sub>s\\<^sub>s\\<^sub>t B I (db'\\<^sub>s\\<^sub>s\\<^sub>t A I D)\"\nproof (induction A arbitrary: D)\n  case (Cons a A) thus ?case by (cases a) auto\nqed simp\n\nlemma db\\<^sub>s\\<^sub>s\\<^sub>t_in_cases:\n  assumes \"(t,s) \\<in> set (db'\\<^sub>s\\<^sub>s\\<^sub>t A I D)\"\n  shows \"(t,s) \\<in> set D \\<or> (\\<exists>t' s'. insert\\<langle>t',s'\\<rangle> \\<in> set A \\<and> t = t' \\<cdot> I \\<and> s = s' \\<cdot> I)\"\n  using assms\nproof (induction A arbitrary: D)\n  case (Cons a A) thus ?case by (cases a) fastforce+\nqed simp\n\nlemma db\\<^sub>s\\<^sub>s\\<^sub>t_in_cases':\n  assumes \"(t,s) \\<in> set (db'\\<^sub>s\\<^sub>s\\<^sub>t A I D)\"\n    and \"(t,s) \\<notin> set D\"\n  shows \"\\<exists>B C t' s'. A = B@insert\\<langle>t',s'\\<rangle>#C \\<and> t = t' \\<cdot> I \\<and> s = s' \\<cdot> I \\<and>\n                     (\\<forall>t'' s''. delete\\<langle>t'',s''\\<rangle> \\<in> set C \\<longrightarrow> t \\<noteq> t'' \\<cdot> I \\<or> s \\<noteq> s'' \\<cdot> I)\"\n  using assms(1)\nproof (induction A rule: List.rev_induct)\n  case (snoc a A)\n  note * = snoc db\\<^sub>s\\<^sub>s\\<^sub>t_append[of A \"[a]\" I D]\n  thus ?case\n  proof (cases a)\n    case (Insert t' s')\n    thus ?thesis using * by (cases \"(t,s) \\<in> set (db'\\<^sub>s\\<^sub>s\\<^sub>t A I D)\") force+\n  next\n    case (Delete t' s')\n    hence **: \"t \\<noteq> t' \\<cdot> I \\<or> s \\<noteq> s' \\<cdot> I\" using * by simp\n\n    have \"(t,s) \\<in> set (db'\\<^sub>s\\<^sub>s\\<^sub>t A I D)\" using * Delete by force\n    then obtain B C u v where B:\n        \"A = B@insert\\<langle>u,v\\<rangle>#C\" \"t = u \\<cdot> I\" \"s = v \\<cdot> I\"\n        \"\\<forall>t' s'. delete\\<langle>t',s'\\<rangle> \\<in> set C \\<longrightarrow> t \\<noteq> t' \\<cdot> I \\<or> s \\<noteq> s' \\<cdot> I\"\n      using snoc.IH by moura\n\n    have \"A@[a] = B@insert\\<langle>u,v\\<rangle>#(C@[a])\"\n         \"\\<forall>t' s'. delete\\<langle>t',s'\\<rangle> \\<in> set (C@[a]) \\<longrightarrow> t \\<noteq> t' \\<cdot> I \\<or> s \\<noteq> s' \\<cdot> I\"\n      using B(1,4) Delete ** by auto\n    thus ?thesis using B(2,3) by blast\n  qed force+\nqed (simp add: assms(2))\n\nlemma db\\<^sub>s\\<^sub>s\\<^sub>t_filter:\n  \"db'\\<^sub>s\\<^sub>s\\<^sub>t A I D = db'\\<^sub>s\\<^sub>s\\<^sub>t (filter is_Update A) I D\"\nby (induct A I D rule: db'\\<^sub>s\\<^sub>s\\<^sub>t.induct) simp_all\n\nlemma subst_sst_cons: \"a#A \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta> = (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<delta>)#(A \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)\"\nby (simp add: subst_apply_stateful_strand_def)\n\nlemma subst_sst_snoc: \"A@[a] \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta> = (A \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)@[a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<delta>]\"\nby (simp add: subst_apply_stateful_strand_def)\n\nlemma subst_sst_append[simp]: \"A@B \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta> = (A \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)@(B \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)\"\nby (simp add: subst_apply_stateful_strand_def)\n\nlemma sst_vars_append_subset:\n  \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t (A@B)\" \"bvars\\<^sub>s\\<^sub>s\\<^sub>t A \\<subseteq> bvars\\<^sub>s\\<^sub>s\\<^sub>t (A@B)\"\n  \"fv\\<^sub>s\\<^sub>s\\<^sub>t B \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t (A@B)\" \"bvars\\<^sub>s\\<^sub>s\\<^sub>t B \\<subseteq> bvars\\<^sub>s\\<^sub>s\\<^sub>t (A@B)\"\nby auto\n\nlemma sst_vars_disj_cons[simp]: \"fv\\<^sub>s\\<^sub>s\\<^sub>t (a#A) \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t (a#A) = {} \\<Longrightarrow> fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t A = {}\"\nunfolding fv\\<^sub>s\\<^sub>s\\<^sub>t_def bvars\\<^sub>s\\<^sub>s\\<^sub>t_def by auto\n\nlemma fv\\<^sub>s\\<^sub>s\\<^sub>t_cons_subset[simp]: \"fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t (a#A)\"\nby auto\n\nlemma fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst_cases[simp]:\n  \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (send\\<langle>t\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = fv (t \\<cdot> \\<theta>)\"\n  \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (receive\\<langle>t\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = fv (t \\<cdot> \\<theta>)\"\n  \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<langle>c: t \\<doteq> s\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = fv (t \\<cdot> \\<theta>) \\<union> fv (s \\<cdot> \\<theta>)\"\n  \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (insert\\<langle>t,s\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = fv (t \\<cdot> \\<theta>) \\<union> fv (s \\<cdot> \\<theta>)\"\n  \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (delete\\<langle>t,s\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = fv (t \\<cdot> \\<theta>) \\<union> fv (s \\<cdot> \\<theta>)\"\n  \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<langle>c: t \\<in> s\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = fv (t \\<cdot> \\<theta>) \\<union> fv (s \\<cdot> \\<theta>)\"\n  \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: G\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) =\n    fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<theta>) \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<theta>) - set X\"\nby simp_all\n\nlemma vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_cases[simp]:\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (send\\<langle>t\\<rangle>) = fv t\"\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (receive\\<langle>t\\<rangle>) = fv t\"\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<langle>c: t \\<doteq> s\\<rangle>) = fv t \\<union> fv s\"\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (insert\\<langle>t,s\\<rangle>) = fv t \\<union> fv s\"\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (delete\\<langle>t,s\\<rangle>) = fv t \\<union> fv s\"\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<langle>c: t \\<in> s\\<rangle>) = fv t \\<union> fv s\"\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: G\\<rangle>) = fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G \\<union> set X\" (is ?A)\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<forall>X\\<langle>\\<or>\\<noteq>: [(t,s)] \\<or>\\<notin>: []\\<rangle>) = fv t \\<union> fv s \\<union> set X\" (is ?B)\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<forall>X\\<langle>\\<or>\\<noteq>: [] \\<or>\\<notin>: [(t,s)]\\<rangle>) = fv t \\<union> fv s \\<union> set X\" (is ?C)\nproof\n  show ?A ?B ?C by auto\nqed simp_all\n\nlemma vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst_cases[simp]:\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (send\\<langle>t\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = fv (t \\<cdot> \\<theta>)\"\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (receive\\<langle>t\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = fv (t \\<cdot> \\<theta>)\"\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<langle>c: t \\<doteq> s\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = fv (t \\<cdot> \\<theta>) \\<union> fv (s \\<cdot> \\<theta>)\"\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (insert\\<langle>t,s\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = fv (t \\<cdot> \\<theta>) \\<union> fv (s \\<cdot> \\<theta>)\"\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (delete\\<langle>t,s\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = fv (t \\<cdot> \\<theta>) \\<union> fv (s \\<cdot> \\<theta>)\"\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<langle>c: t \\<in> s\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = fv (t \\<cdot> \\<theta>) \\<union> fv (s \\<cdot> \\<theta>)\"\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: G\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) =\n    fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<theta>) \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<theta>) \\<union> set X\" (is ?A)\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<forall>X\\<langle>\\<or>\\<noteq>: [(t,s)] \\<or>\\<notin>: []\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) =\n    fv (t \\<cdot> rm_vars (set X) \\<theta>) \\<union> fv (s \\<cdot> rm_vars (set X) \\<theta>) \\<union> set X\" (is ?B)\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<forall>X\\<langle>\\<or>\\<noteq>: [] \\<or>\\<notin>: [(t,s)]\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) =\n    fv (t \\<cdot> rm_vars (set X) \\<theta>) \\<union> fv (s \\<cdot> rm_vars (set X) \\<theta>) \\<union> set X\" (is ?C)\nproof\n  show ?A ?B ?C by auto\nqed simp_all\n\nlemma bvars\\<^sub>s\\<^sub>s\\<^sub>t_cons_subset: \"bvars\\<^sub>s\\<^sub>s\\<^sub>t A \\<subseteq> bvars\\<^sub>s\\<^sub>s\\<^sub>t (a#A)\"\nby auto\n\nlemma bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst: \"bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<delta>) = bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a\"\nby (cases a) auto\n\nlemma bvars\\<^sub>s\\<^sub>s\\<^sub>t_subst: \"bvars\\<^sub>s\\<^sub>s\\<^sub>t (A \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>) = bvars\\<^sub>s\\<^sub>s\\<^sub>t A\"\nusing bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst[of _ \\<delta>]\nby (induct A) (simp_all add: subst_apply_stateful_strand_def)\n\nlemma bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_set_cases[simp]:\n  \"set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (send\\<langle>t\\<rangle>)) = {}\"\n  \"set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (receive\\<langle>t\\<rangle>)) = {}\"\n  \"set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<langle>c: t \\<doteq> s\\<rangle>)) = {}\"\n  \"set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (insert\\<langle>t,s\\<rangle>)) = {}\"\n  \"set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (delete\\<langle>t,s\\<rangle>)) = {}\"\n  \"set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<langle>c: t \\<in> s\\<rangle>)) = {}\"\n  \"set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: G\\<rangle>)) = set X\"\nby simp_all\n\n\n\nlemma bvars\\<^sub>s\\<^sub>s\\<^sub>t_NegChecks: \"bvars\\<^sub>s\\<^sub>s\\<^sub>t A = bvars\\<^sub>s\\<^sub>s\\<^sub>t (filter is_NegChecks A)\" \nproof (induction A)\n  case (Cons a A) thus ?case by (cases a) fastforce+\nqed simp\n\nlemma vars\\<^sub>s\\<^sub>s\\<^sub>t_append[simp]: \"vars\\<^sub>s\\<^sub>s\\<^sub>t (A@B) = vars\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> vars\\<^sub>s\\<^sub>s\\<^sub>t B\"\nby (simp add: vars\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma vars\\<^sub>s\\<^sub>s\\<^sub>t_Nil[simp]: \"vars\\<^sub>s\\<^sub>s\\<^sub>t [] = {}\"\nby (simp add: vars\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma vars\\<^sub>s\\<^sub>s\\<^sub>t_Cons: \"vars\\<^sub>s\\<^sub>s\\<^sub>t (a#A) = vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a \\<union> vars\\<^sub>s\\<^sub>s\\<^sub>t A\"\nby (simp add: vars\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma fv\\<^sub>s\\<^sub>s\\<^sub>t_Cons: \"fv\\<^sub>s\\<^sub>s\\<^sub>t (a#A) = fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a \\<union> fv\\<^sub>s\\<^sub>s\\<^sub>t A\"\nunfolding fv\\<^sub>s\\<^sub>s\\<^sub>t_def by simp\n\nlemma bvars\\<^sub>s\\<^sub>s\\<^sub>t_Cons: \"bvars\\<^sub>s\\<^sub>s\\<^sub>t (a#A) = set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a) \\<union> bvars\\<^sub>s\\<^sub>s\\<^sub>t A\"\nunfolding bvars\\<^sub>s\\<^sub>s\\<^sub>t_def by auto\n\nlemma vars\\<^sub>s\\<^sub>s\\<^sub>t_Cons'[simp]:\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t (send\\<langle>t\\<rangle>#A) = vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (send\\<langle>t\\<rangle>) \\<union> vars\\<^sub>s\\<^sub>s\\<^sub>t A\"\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t (receive\\<langle>t\\<rangle>#A) = vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (receive\\<langle>t\\<rangle>) \\<union> vars\\<^sub>s\\<^sub>s\\<^sub>t A\"\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t (\\<langle>a: t \\<doteq> s\\<rangle>#A) = vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<langle>a: t \\<doteq> s\\<rangle>) \\<union> vars\\<^sub>s\\<^sub>s\\<^sub>t A\"\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t (insert\\<langle>t,s\\<rangle>#A) = vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (insert\\<langle>t,s\\<rangle>) \\<union> vars\\<^sub>s\\<^sub>s\\<^sub>t A\"\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t (delete\\<langle>t,s\\<rangle>#A) = vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (delete\\<langle>t,s\\<rangle>) \\<union> vars\\<^sub>s\\<^sub>s\\<^sub>t A\"\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t (\\<langle>a: t \\<in> s\\<rangle>#A) = vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<langle>a: t \\<in> s\\<rangle>) \\<union> vars\\<^sub>s\\<^sub>s\\<^sub>t A\"\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t (\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: G\\<rangle>#A) = vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: G\\<rangle>) \\<union> vars\\<^sub>s\\<^sub>s\\<^sub>t A\"\nby (simp_all add: vars\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_is_fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p:\n  fixes x::\"('a,'b) stateful_strand_step\"\n  shows \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x = fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x \\<union> set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x)\"\nproof (cases x)\n  case (NegChecks X F G) thus ?thesis by (induct F) force+\nqed simp_all\n\nlemma vars\\<^sub>s\\<^sub>s\\<^sub>t_is_fv\\<^sub>s\\<^sub>s\\<^sub>t_bvars\\<^sub>s\\<^sub>s\\<^sub>t:\n  fixes S::\"('a,'b) stateful_strand\"\n  shows \"vars\\<^sub>s\\<^sub>s\\<^sub>t S = fv\\<^sub>s\\<^sub>s\\<^sub>t S \\<union> bvars\\<^sub>s\\<^sub>s\\<^sub>t S\"\nproof (induction S)\n  case (Cons x S) thus ?case\n    using vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_is_fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p[of x]\n    by (auto simp add: vars\\<^sub>s\\<^sub>s\\<^sub>t_def)\nqed simp\n\nlemma vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_NegCheck[simp]:\n  \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: G\\<rangle>) = set X \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G\"\nby (simp_all add: sup_commute sup_left_commute vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_is_fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p)\n\nlemma bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_NegCheck[simp]:\n  \"bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: G\\<rangle>) = X\"\n  \"set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<forall>[]\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: G\\<rangle>)) = {}\"\nby simp_all\n\nlemma fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_NegCheck[simp]:\n  \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: G\\<rangle>) = fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G - set X\"\n  \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<forall>[]\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: G\\<rangle>) = fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G\"\n  \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<langle>t != s\\<rangle>) = fv t \\<union> fv s\"\n  \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<langle>t not in s\\<rangle>) = fv t \\<union> fv s\"\nby simp_all\n\n\n\n\n\nlemma fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_is_subterm_trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p:\n  assumes \"x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a\"\n  shows \"Var x \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a)\"\nusing assms var_is_subterm\nproof (cases a)\n  case (NegChecks X F F')\n  hence \"x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F' - set X\" using assms by simp\n  thus ?thesis using NegChecks var_is_subterm by fastforce\nqed force+\n\nlemma fv\\<^sub>s\\<^sub>s\\<^sub>t_is_subterm_trms\\<^sub>s\\<^sub>s\\<^sub>t: \"x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t A \\<Longrightarrow> Var x \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t A)\"\nproof (induction A)\n  case (Cons a A) thus ?case using fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_is_subterm_trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p by (cases \"x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t A\") auto\nqed simp\n\nlemma var_subterm_trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_is_vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p:\n  assumes \"Var x \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a)\"\n  shows \"x \\<in> vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a\"\nusing assms vars_iff_subtermeq\nproof (cases a)\n  case (NegChecks X F F')\n  hence \"Var x \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F')\" using assms by simp\n  thus ?thesis using NegChecks vars_iff_subtermeq by force\nqed force+\n\nlemma var_subterm_trms\\<^sub>s\\<^sub>s\\<^sub>t_is_vars\\<^sub>s\\<^sub>s\\<^sub>t: \"Var x \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t A) \\<Longrightarrow> x \\<in> vars\\<^sub>s\\<^sub>s\\<^sub>t A\"\nproof (induction A)\n  case (Cons a A)\n  show ?case\n  proof (cases \"Var x \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t A)\")\n    case True thus ?thesis using Cons.IH by (simp add: vars\\<^sub>s\\<^sub>s\\<^sub>t_def)\n  next\n    case False thus ?thesis\n      using Cons.prems var_subterm_trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_is_vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p\n      by (fastforce simp add: vars\\<^sub>s\\<^sub>s\\<^sub>t_def)\n  qed\nqed simp\n\nlemma var_trms\\<^sub>s\\<^sub>s\\<^sub>t_is_vars\\<^sub>s\\<^sub>s\\<^sub>t: \"Var x \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t A \\<Longrightarrow> x \\<in> vars\\<^sub>s\\<^sub>s\\<^sub>t A\"\nby (meson var_subterm_trms\\<^sub>s\\<^sub>s\\<^sub>t_is_vars\\<^sub>s\\<^sub>s\\<^sub>t UN_I term.order_refl)\n\nlemma ik\\<^sub>s\\<^sub>s\\<^sub>t_trms\\<^sub>s\\<^sub>s\\<^sub>t_subset: \"ik\\<^sub>s\\<^sub>s\\<^sub>t A \\<subseteq> trms\\<^sub>s\\<^sub>s\\<^sub>t A\"\nby (force simp add: ik\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma var_subterm_ik\\<^sub>s\\<^sub>s\\<^sub>t_is_vars\\<^sub>s\\<^sub>s\\<^sub>t: \"Var x \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>s\\<^sub>s\\<^sub>t A) \\<Longrightarrow> x \\<in> vars\\<^sub>s\\<^sub>s\\<^sub>t A\"\nusing var_subterm_trms\\<^sub>s\\<^sub>s\\<^sub>t_is_vars\\<^sub>s\\<^sub>s\\<^sub>t ik\\<^sub>s\\<^sub>s\\<^sub>t_trms\\<^sub>s\\<^sub>s\\<^sub>t_subset by fast\n\n\n\n\n\nlemma fv_trms\\<^sub>s\\<^sub>s\\<^sub>t_subset:\n  \"fv\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t S) \\<subseteq> vars\\<^sub>s\\<^sub>s\\<^sub>t S\"\n  \"fv\\<^sub>s\\<^sub>s\\<^sub>t S \\<subseteq> fv\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t S)\"\nproof (induction S)\n  case (Cons x S)\n  have *: \"fv\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t (x#S)) = fv\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x) \\<union> fv\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t S)\"\n          \"fv\\<^sub>s\\<^sub>s\\<^sub>t (x#S) = fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x \\<union> fv\\<^sub>s\\<^sub>s\\<^sub>t S\" \"vars\\<^sub>s\\<^sub>s\\<^sub>t (x#S) = vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x \\<union> vars\\<^sub>s\\<^sub>s\\<^sub>t S\"\n    unfolding trms\\<^sub>s\\<^sub>s\\<^sub>t_def fv\\<^sub>s\\<^sub>s\\<^sub>t_def vars\\<^sub>s\\<^sub>s\\<^sub>t_def\n    by auto\n\n  { case 1\n    show ?case using Cons.IH(1)\n    proof (cases x)\n      case (NegChecks X F G)\n      hence \"trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x = trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G\"\n            \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x = fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G \\<union> set X\"\n        by (simp, meson vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_cases(7))\n      hence \"fv\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x) \\<subseteq> vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x\"\n        using fv_trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_is_fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s[of F] fv_trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_is_fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s[of G]\n        by auto\n      thus ?thesis\n        using Cons.IH(1) *(1,3)\n        by blast\n    qed auto\n  }\n\n  { case 2\n    show ?case using Cons.IH(2)\n    proof (cases x)\n      case (NegChecks X F G)\n      hence \"trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x = trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G\"\n            \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x = (fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G) - set X\"\n        by auto\n      hence \"fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x \\<subseteq> fv\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x)\"\n        using fv_trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_is_fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s[of F] fv_trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_is_fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s[of G]\n        by auto\n      thus ?thesis\n        using Cons.IH(2) *(1,2)\n        by blast\n    qed auto\n  }\nqed simp_all\n\nlemma fv_ik_subset_fv_sst'[simp]: \"fv\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>s\\<^sub>s\\<^sub>t S) \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t S\"\nunfolding ik\\<^sub>s\\<^sub>s\\<^sub>t_def by (induct S) auto\n\nlemma fv_ik_subset_vars_sst'[simp]: \"fv\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>s\\<^sub>s\\<^sub>t S) \\<subseteq> vars\\<^sub>s\\<^sub>s\\<^sub>t S\"\nusing fv_ik_subset_fv_sst' fv_trms\\<^sub>s\\<^sub>s\\<^sub>t_subset by fast\n\nlemma ik\\<^sub>s\\<^sub>s\\<^sub>t_var_is_fv: \"Var x \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (ik\\<^sub>s\\<^sub>s\\<^sub>t A) \\<Longrightarrow> x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t A\"\nby (meson fv_ik_subset_fv_sst'[of A] fv_subset_subterms subsetCE term.set_intros(3))\n\nlemma vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst_cases':\n  assumes x: \"x \\<in> vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (s \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\"\n  shows \"x \\<in> vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p s \\<or> x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<theta> ` vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p s)\"\nusing x vars_term_subst[of _ \\<theta>] vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_cases(1,2,3,4,5,6) vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst_cases(1,2)[of _ \\<theta>]\n      vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst_cases(3,6)[of _ _ _ \\<theta>] vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst_cases(4,5)[of _ _ \\<theta>]\nproof (cases s)\n  case (NegChecks X F G)\n  let ?\\<theta>' = \"rm_vars (set X) \\<theta>\"\n  have \"x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ?\\<theta>') \\<or> x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ?\\<theta>') \\<or> x \\<in> set X\"\n    using vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst_cases(7)[of X F G \\<theta>] x NegChecks by simp\n  hence \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (?\\<theta>' ` fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F) \\<or> x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (?\\<theta>' ` fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G) \\<or> x \\<in> set X\"\n    using fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_subst[of _ ?\\<theta>'] by blast\n  hence \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<theta> ` fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F) \\<or> x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<theta> ` fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G) \\<or> x \\<in> set X\"\n    using rm_vars_fv\\<^sub>s\\<^sub>e\\<^sub>t_subst by fast\n  thus ?thesis\n    using NegChecks vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_cases(7)[of X F G]\n    by auto\nqed simp_all\n\nlemma vars\\<^sub>s\\<^sub>s\\<^sub>t_subst_cases:\n  assumes \"x \\<in> vars\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n  shows \"x \\<in> vars\\<^sub>s\\<^sub>s\\<^sub>t S \\<or> x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<theta> ` vars\\<^sub>s\\<^sub>s\\<^sub>t S)\"\n  using assms\nproof (induction S)\n  case (Cons s S) thus ?case\n  proof (cases \"x \\<in> vars\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\")\n    case False\n    note * = subst_sst_cons[of s S \\<theta>] vars\\<^sub>s\\<^sub>s\\<^sub>t_Cons[of \"s \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>\" \"S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>\"] vars\\<^sub>s\\<^sub>s\\<^sub>t_Cons[of s S]\n    have **: \"x \\<in> vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (s \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\" using Cons.prems False * by simp\n    show ?thesis using vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst_cases'[OF **] * by auto\n  qed (auto simp add: vars\\<^sub>s\\<^sub>s\\<^sub>t_def)\nqed simp\n\nlemma subset_subst_pairs_diff_exists:\n  fixes \\<I>::\"('a,'b) subst\" and D D'::\"('a,'b) dbstate\"\n  shows \"\\<exists>Di. Di \\<subseteq> D \\<and> Di \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I> = (D \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>) - D'\"\nby (metis (no_types, lifting) Diff_subset subset_image_iff)\n\nlemma subset_subst_pairs_diff_exists':\n  fixes \\<I>::\"('a,'b) subst\" and D::\"('a,'b) dbstate\"\n  assumes \"finite D\"\n  shows \"\\<exists>Di. Di \\<subseteq> D \\<and> Di \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<subseteq> {d \\<cdot>\\<^sub>p \\<I>} \\<and> d \\<cdot>\\<^sub>p \\<I> \\<notin> (D - Di) \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\"\nusing assms\nproof (induction D rule: finite_induct)\n  case (insert d' D)\n  then obtain Di where IH: \"Di \\<subseteq> D\" \"Di \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<subseteq> {d \\<cdot>\\<^sub>p \\<I>}\" \"d \\<cdot>\\<^sub>p \\<I> \\<notin> (D - Di) \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" by moura\n  show ?case\n  proof (cases \"d' \\<cdot>\\<^sub>p \\<I> = d \\<cdot>\\<^sub>p \\<I>\")\n    case True\n    hence \"insert d' Di \\<subseteq> insert d' D\" \"insert d' Di \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<subseteq> {d \\<cdot>\\<^sub>p \\<I>}\"\n          \"d \\<cdot>\\<^sub>p \\<I> \\<notin> (insert d' D - insert d' Di) \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" \n      using IH by auto\n    thus ?thesis by metis\n  next\n    case False\n    hence \"Di \\<subseteq> insert d' D\" \"Di \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I> \\<subseteq> {d \\<cdot>\\<^sub>p \\<I>}\"\n          \"d \\<cdot>\\<^sub>p \\<I> \\<notin> (insert d' D - Di) \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<I>\" \n      using IH by auto\n    thus ?thesis by metis\n  qed\nqed simp\n\nlemma stateful_strand_step_subst_inI[intro]:\n  \"send\\<langle>t\\<rangle> \\<in> set A \\<Longrightarrow> send\\<langle>t \\<cdot> \\<theta>\\<rangle> \\<in> set (A \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n  \"receive\\<langle>t\\<rangle> \\<in> set A \\<Longrightarrow> receive\\<langle>t \\<cdot> \\<theta>\\<rangle> \\<in> set (A \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n  \"\\<langle>c: t \\<doteq> s\\<rangle> \\<in> set A \\<Longrightarrow> \\<langle>c: (t \\<cdot> \\<theta>) \\<doteq> (s \\<cdot> \\<theta>)\\<rangle> \\<in> set (A \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n  \"insert\\<langle>t, s\\<rangle> \\<in> set A \\<Longrightarrow> insert\\<langle>t \\<cdot> \\<theta>, s \\<cdot> \\<theta>\\<rangle> \\<in> set (A \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n  \"delete\\<langle>t, s\\<rangle> \\<in> set A \\<Longrightarrow> delete\\<langle>t \\<cdot> \\<theta>, s \\<cdot> \\<theta>\\<rangle> \\<in> set (A \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n  \"\\<langle>c: t \\<in> s\\<rangle> \\<in> set A \\<Longrightarrow> \\<langle>c: (t \\<cdot> \\<theta>) \\<in> (s \\<cdot> \\<theta>)\\<rangle> \\<in> set (A \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n  \"\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: G\\<rangle> \\<in> set A \n    \\<Longrightarrow> \\<forall>X\\<langle>\\<or>\\<noteq>: (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<theta>) \\<or>\\<notin>: (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<theta>)\\<rangle> \\<in> set (A \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n  \"\\<langle>t != s\\<rangle> \\<in> set A \\<Longrightarrow> \\<langle>t \\<cdot> \\<theta> != s \\<cdot> \\<theta>\\<rangle> \\<in> set (A \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\n  \"\\<langle>t not in s\\<rangle> \\<in> set A \\<Longrightarrow> \\<langle>t \\<cdot> \\<theta> not in s \\<cdot> \\<theta>\\<rangle> \\<in> set (A \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\nproof (induction A)\n  case (Cons a A)\n  note * = subst_sst_cons[of a A \\<theta>]\n  { case 1 thus ?case using Cons.IH(1) * by (cases a) auto }\n  { case 2 thus ?case using Cons.IH(2) * by (cases a) auto }\n  { case 3 thus ?case using Cons.IH(3) * by (cases a) auto }\n  { case 4 thus ?case using Cons.IH(4) * by (cases a) auto }\n  { case 5 thus ?case using Cons.IH(5) * by (cases a) auto }\n  { case 6 thus ?case using Cons.IH(6) * by (cases a) auto }\n  { case 7 thus ?case using Cons.IH(7) * by (cases a) auto }\n  { case 8 thus ?case using Cons.IH(8) * by (cases a) auto }\n  { case 9 thus ?case using Cons.IH(9) * by (cases a) auto }\nqed simp_all\n\nlemma stateful_strand_step_cases_subst:\n  \"is_Send a = is_Send (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\"\n  \"is_Receive a = is_Receive (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\"\n  \"is_Equality a = is_Equality (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\"\n  \"is_Insert a = is_Insert (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\"\n  \"is_Delete a = is_Delete (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\"\n  \"is_InSet a = is_InSet (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\"\n  \"is_NegChecks a = is_NegChecks (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\"\n  \"is_Assignment a = is_Assignment (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\"\n  \"is_Check a = is_Check (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\"\n  \"is_Update a = is_Update (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\"\nby (cases a; simp_all)+\n\nlemma stateful_strand_step_subst_inv_cases:\n  \"send\\<langle>t\\<rangle> \\<in> set (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<sigma>) \\<Longrightarrow> \\<exists>t'. t = t' \\<cdot> \\<sigma> \\<and> send\\<langle>t'\\<rangle> \\<in> set S\"\n  \"receive\\<langle>t\\<rangle> \\<in> set (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<sigma>) \\<Longrightarrow> \\<exists>t'. t = t' \\<cdot> \\<sigma> \\<and> receive\\<langle>t'\\<rangle> \\<in> set S\"\n  \"\\<langle>c: t \\<doteq> s\\<rangle> \\<in> set (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<sigma>) \\<Longrightarrow> \\<exists>t' s'. t = t' \\<cdot> \\<sigma> \\<and> s = s' \\<cdot> \\<sigma> \\<and> \\<langle>c: t' \\<doteq> s'\\<rangle> \\<in> set S\"\n  \"insert\\<langle>t,s\\<rangle> \\<in> set (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<sigma>) \\<Longrightarrow> \\<exists>t' s'. t = t' \\<cdot> \\<sigma> \\<and> s = s' \\<cdot> \\<sigma> \\<and> insert\\<langle>t',s'\\<rangle> \\<in> set S\"\n  \"delete\\<langle>t,s\\<rangle> \\<in> set (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<sigma>) \\<Longrightarrow> \\<exists>t' s'. t = t' \\<cdot> \\<sigma> \\<and> s = s' \\<cdot> \\<sigma> \\<and> delete\\<langle>t',s'\\<rangle> \\<in> set S\"\n  \"\\<langle>c: t \\<in> s\\<rangle> \\<in> set (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<sigma>) \\<Longrightarrow> \\<exists>t' s'. t = t' \\<cdot> \\<sigma> \\<and> s = s' \\<cdot> \\<sigma> \\<and> \\<langle>c: t' \\<in> s'\\<rangle> \\<in> set S\"\n  \"\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: G\\<rangle> \\<in> set (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<sigma>) \\<Longrightarrow>\n    \\<exists>F' G'. F = F' \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<sigma> \\<and> G = G' \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<sigma> \\<and>\n            \\<forall>X\\<langle>\\<or>\\<noteq>: F' \\<or>\\<notin>: G'\\<rangle> \\<in> set S\"\nproof (induction S)\n  case (Cons a S)\n  have *: \"x \\<in> set (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<sigma>)\"\n    when \"x \\<in> set (a#S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<sigma>)\" \"x \\<noteq> a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<sigma>\" for x\n    using that by (simp add: subst_apply_stateful_strand_def)\n\n  { case 1 thus ?case using Cons.IH(1)[OF *] by (cases a) auto }\n  { case 2 thus ?case using Cons.IH(2)[OF *] by (cases a) auto }\n  { case 3 thus ?case using Cons.IH(3)[OF *] by (cases a) auto }\n  { case 4 thus ?case using Cons.IH(4)[OF *] by (cases a) auto }\n  { case 5 thus ?case using Cons.IH(5)[OF *] by (cases a) auto }\n  { case 6 thus ?case using Cons.IH(6)[OF *] by (cases a) auto }\n  { case 7 thus ?case using Cons.IH(7)[OF *] by (cases a) auto }\nqed simp_all\n\nlemma stateful_strand_step_fv_subset_cases:\n  \"send\\<langle>t\\<rangle> \\<in> set S \\<Longrightarrow> fv t \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t S\"\n  \"receive\\<langle>t\\<rangle> \\<in> set S \\<Longrightarrow> fv t \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t S\"\n  \"\\<langle>c: t \\<doteq> s\\<rangle> \\<in> set S \\<Longrightarrow> fv t \\<union> fv s \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t S\"\n  \"insert\\<langle>t,s\\<rangle> \\<in> set S \\<Longrightarrow> fv t \\<union> fv s \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t S\"\n  \"delete\\<langle>t,s\\<rangle> \\<in> set S \\<Longrightarrow> fv t \\<union> fv s \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t S\"\n  \"\\<langle>c: t \\<in> s\\<rangle> \\<in> set S \\<Longrightarrow> fv t \\<union> fv s \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t S\"\n  \"\\<forall>X\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: G\\<rangle> \\<in> set S \\<Longrightarrow> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G - set X \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t S\"\nproof (induction S)\n  case (Cons a S)\n  { case 1 thus ?case using Cons.IH(1) by auto }\n  { case 2 thus ?case using Cons.IH(2) by auto }\n  { case 3 thus ?case using Cons.IH(3) by auto }\n  { case 4 thus ?case using Cons.IH(4) by auto }\n  { case 5 thus ?case using Cons.IH(5) by auto }\n  { case 6 thus ?case using Cons.IH(6) by auto }\n  { case 7 thus ?case using Cons.IH(7) by fastforce }\nqed simp_all\n\nlemma trms\\<^sub>s\\<^sub>s\\<^sub>t_nil[simp]:\n  \"trms\\<^sub>s\\<^sub>s\\<^sub>t [] = {}\"\nunfolding trms\\<^sub>s\\<^sub>s\\<^sub>t_def by simp\n\nlemma trms\\<^sub>s\\<^sub>s\\<^sub>t_mono:\n  \"set M \\<subseteq> set N \\<Longrightarrow> trms\\<^sub>s\\<^sub>s\\<^sub>t M \\<subseteq> trms\\<^sub>s\\<^sub>s\\<^sub>t N\"\nby auto\n\nlemma trms\\<^sub>s\\<^sub>s\\<^sub>t_in:\n  assumes \"t \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t S\"\n  shows \"\\<exists>a \\<in> set S. t \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a\"\nusing assms unfolding trms\\<^sub>s\\<^sub>s\\<^sub>t_def by simp\n\nlemma trms\\<^sub>s\\<^sub>s\\<^sub>t_cons: \"trms\\<^sub>s\\<^sub>s\\<^sub>t (a#A) = trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a \\<union> trms\\<^sub>s\\<^sub>s\\<^sub>t A\"\nunfolding trms\\<^sub>s\\<^sub>s\\<^sub>t_def by force\n\nlemma trms\\<^sub>s\\<^sub>s\\<^sub>t_append[simp]: \"trms\\<^sub>s\\<^sub>s\\<^sub>t (A@B) = trms\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> trms\\<^sub>s\\<^sub>s\\<^sub>t B\"\nunfolding trms\\<^sub>s\\<^sub>s\\<^sub>t_def by force\n\nlemma trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst:\n  assumes \"set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a) \\<inter> subst_domain \\<theta> = {}\"\n  shows \"trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\"\nproof (cases a)\n  case (NegChecks X F G)\n  hence \"rm_vars (set X) \\<theta> = \\<theta>\" using assms rm_vars_apply'[of \\<theta> \"set X\"] by auto\n  hence \"trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<theta>) \\<union> trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<theta>)\"\n        \"trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta> = (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>) \\<union> (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>)\"\n    using NegChecks image_Un by simp_all\n  thus ?thesis by (metis trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_subst)\nqed simp_all\n\nlemma trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst':\n  assumes \"\\<not>is_NegChecks a\"\n  shows \"trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\"\nusing assms by (cases a) simp_all\n\nlemma trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst'':\n  fixes t::\"('a,'b) term\" and \\<delta>::\"('a,'b) subst\"\n  assumes \"t \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (b \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<delta>)\"\n  shows \"\\<exists>s \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p b. t = s \\<cdot> rm_vars (set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p b)) \\<delta>\"\nproof (cases \"is_NegChecks b\")\n  case True\n  then obtain X F G where *: \"b = NegChecks X F G\" by (cases b) moura+\n  thus ?thesis using assms trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_subst[of _ \"rm_vars (set X) \\<delta>\"] by auto\nnext\n  case False\n  hence \"trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (b \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<delta>) = trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p b \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t rm_vars (set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p b)) \\<delta>\"\n    using trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst' bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_NegChecks\n    by fastforce\n  thus ?thesis using assms by fast\nqed\n\nlemma trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst''':\n  fixes t::\"('a,'b) term\" and \\<delta> \\<theta>::\"('a,'b) subst\"\n  assumes \"t \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (b \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<delta>) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\"\n  shows \"\\<exists>s \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p b. t = s \\<cdot> rm_vars (set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p b)) \\<delta> \\<circ>\\<^sub>s \\<theta>\"\nproof -\n  obtain s where s: \"s \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (b \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<delta>)\" \"t = s \\<cdot> \\<theta>\" using assms by moura\n  show ?thesis using trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst''[OF s(1)] s(2) by auto\nqed\n\nlemma trms\\<^sub>s\\<^sub>s\\<^sub>t_subst:\n  assumes \"bvars\\<^sub>s\\<^sub>s\\<^sub>t S \\<inter> subst_domain \\<theta> = {}\"\n  shows \"trms\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>) = trms\\<^sub>s\\<^sub>s\\<^sub>t S \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\"\nusing assms\nproof (induction S)\n  case (Cons a S)\n  hence IH: \"trms\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>) = trms\\<^sub>s\\<^sub>s\\<^sub>t S \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\" and *: \"set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a) \\<inter> subst_domain \\<theta> = {}\"\n    by auto\n  show ?case using trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst[OF *] IH by (auto simp add: subst_apply_stateful_strand_def)\nqed simp\n\nlemma trms\\<^sub>s\\<^sub>s\\<^sub>t_subst_cons:\n  \"trms\\<^sub>s\\<^sub>s\\<^sub>t (a#A \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>) = trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<delta>) \\<union> trms\\<^sub>s\\<^sub>s\\<^sub>t (A \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)\"\nusing subst_sst_cons[of a A \\<delta>] trms\\<^sub>s\\<^sub>s\\<^sub>t_cons[of a A] trms\\<^sub>s\\<^sub>s\\<^sub>t_append by simp\n\nlemma (in intruder_model) wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s_trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst:\n  assumes \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>)\"\n  shows \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<delta>))\"\n  using assms\nproof (cases a)\n  case (NegChecks X F G)\n  hence *: \"trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<delta>) =\n              (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<delta>)) \\<union> (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<delta>))\"\n    by simp\n\n  have \"trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta> = (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>) \\<union> (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>)\"\n    using NegChecks image_Un by simp\n  hence \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>)\" \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>)\" using * assms by auto\n  hence \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t rm_vars (set X) \\<delta>)\"\n        \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t rm_vars (set X) \\<delta>)\"\n    using wf_trms_subst_rm_vars[of \\<delta> \"trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F\" \"set X\"]\n          wf_trms_subst_rm_vars[of \\<delta> \"trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G\" \"set X\"]\n    by fast+\n  thus ?thesis\n    using * trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_subst[of _ \"rm_vars (set X) \\<delta>\"]\n    by auto\nqed auto\n\nlemma trms\\<^sub>s\\<^sub>s\\<^sub>t_fv_vars\\<^sub>s\\<^sub>s\\<^sub>t_subset: \"t \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t A \\<Longrightarrow> fv t \\<subseteq> vars\\<^sub>s\\<^sub>s\\<^sub>t A\" \nproof (induction A)\n  case (Cons a A) thus ?case by (cases a) auto\nqed simp\n\nlemma trms\\<^sub>s\\<^sub>s\\<^sub>t_fv_subst_subset:\n  assumes \"t \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t S\" \"subst_domain \\<theta> \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t S = {}\"\n  shows \"fv (t \\<cdot> \\<theta>) \\<subseteq> vars\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\nusing assms\nproof (induction S)\n  case (Cons s S) show ?case\n  proof (cases \"t \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t S\")\n    case True\n    hence \"fv (t \\<cdot> \\<theta>) \\<subseteq> vars\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\" using Cons.IH Cons.prems by auto\n    thus ?thesis using subst_sst_cons[of s S \\<theta>] unfolding vars\\<^sub>s\\<^sub>s\\<^sub>t_def by auto\n  next\n    case False\n    hence *: \"t \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p s\" \"subst_domain \\<theta> \\<inter> set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p s) = {}\" using Cons.prems by auto\n    hence \"fv (t \\<cdot> \\<theta>) \\<subseteq> vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (s \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\"\n    proof (cases s)\n      case (NegChecks X F G)\n      hence **: \"t \\<in> trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<or> t \\<in> trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G\" using *(1) by auto\n      have ***: \"rm_vars (set X) \\<theta> = \\<theta>\" using *(2) NegChecks rm_vars_apply' by auto\n      have \"fv (t \\<cdot> \\<theta>) \\<subseteq> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<theta>) \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<theta>)\"\n        using ** *** trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_fv_subst_subset[of t _ \\<theta>] by auto\n      thus ?thesis using *(2) using NegChecks vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst_cases(7)[of X F G \\<theta>] by blast\n    qed auto\n    thus ?thesis using subst_sst_cons[of s S \\<theta>] unfolding vars\\<^sub>s\\<^sub>s\\<^sub>t_def by auto\n  qed\nqed simp\n\nlemma trms\\<^sub>s\\<^sub>s\\<^sub>t_fv_subst_subset':\n  assumes \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t S)\" \"fv t \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t S = {}\" \"fv (t \\<cdot> \\<theta>) \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t S = {}\"\n  shows \"fv (t \\<cdot> \\<theta>) \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\nusing assms\nproof (induction S)\n  case (Cons s S) show ?case\n  proof (cases \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t S)\")\n    case True\n    hence \"fv (t \\<cdot> \\<theta>) \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\" using Cons.IH Cons.prems by auto\n    thus ?thesis using subst_sst_cons[of s S \\<theta>] unfolding vars\\<^sub>s\\<^sub>s\\<^sub>t_def by auto\n  next\n    case False\n    hence 0: \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p s)\" \"fv t \\<inter> set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p s) = {}\"\n             \"fv (t \\<cdot> \\<theta>) \\<inter> set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p s) = {}\"\n      using Cons.prems by auto\n\n    note 1 = UN_Un UN_insert fv\\<^sub>s\\<^sub>e\\<^sub>t.simps subst_apply_fv_subset subst_apply_fv_unfold\n             subst_apply_term_empty sup_bot.comm_neutral fv_subterms_set fv_subset[OF 0(1)]\n\n    note 2 = subst_apply_fv_union\n\n    have \"fv (t \\<cdot> \\<theta>) \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (s \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\"\n    proof (cases s)\n      case (NegChecks X F G)\n      hence 3: \"t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F) \\<or> t \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G)\" using 0(1) by auto\n      have \"t \\<cdot> rm_vars (set X) \\<theta> = t \\<cdot> \\<theta>\" using 0(2) NegChecks rm_vars_ident[of t] by auto\n      hence \"fv (t \\<cdot> \\<theta>) \\<subseteq> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<theta>) \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<theta>)\"\n        using 3 trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_fv_subst_subset'[of t _ \"rm_vars (set X) \\<theta>\"] by fastforce\n      thus ?thesis using 0(2,3) NegChecks fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst_cases(7)[of X F G \\<theta>] by auto\n    qed (metis (no_types, lifting) 1 trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p.simps(1) fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst_cases(1),\n         metis (no_types, lifting) 1 trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p.simps(2) fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst_cases(2),\n         metis (no_types, lifting) 1 2 trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p.simps(3) fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst_cases(3),\n         metis (no_types, lifting) 1 2 trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p.simps(4) fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst_cases(4),\n         metis (no_types, lifting) 1 2 trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p.simps(5) fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst_cases(5),\n         metis (no_types, lifting) 1 2 trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p.simps(6) fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst_cases(6))\n    thus ?thesis using subst_sst_cons[of s S \\<theta>] unfolding fv\\<^sub>s\\<^sub>s\\<^sub>t_def by auto\n  qed\nqed simp\n\nlemma trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_funs_term_cases:\n  assumes \"t \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (s \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\" \"f \\<in> funs_term t\"\n  shows \"(\\<exists>u \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p s. f \\<in> funs_term u) \\<or> (\\<exists>x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p s. f \\<in> funs_term (\\<theta> x))\"\n  using assms\nproof (cases s)\n  case (NegChecks X F G)\n  hence \"t \\<in> trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<theta>) \\<or> t \\<in> trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<theta>)\"\n    using assms(1) by auto\n  hence \"(\\<exists>u\\<in>trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F. f \\<in> funs_term u) \\<or> (\\<exists>x\\<in>fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F. f \\<in> funs_term (rm_vars (set X) \\<theta> x)) \\<or>\n         (\\<exists>u\\<in>trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G. f \\<in> funs_term u) \\<or> (\\<exists>x\\<in>fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G. f \\<in> funs_term (rm_vars (set X) \\<theta> x))\"\n    using trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_funs_term_cases[OF _ assms(2), of _ \"rm_vars (set X) \\<theta>\"] by meson\n  hence \"(\\<exists>u \\<in> trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G. f \\<in> funs_term u) \\<or>\n         (\\<exists>x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G. f \\<in> funs_term (rm_vars (set X) \\<theta> x))\"\n    by blast\n  thus ?thesis\n  proof\n    assume \"\\<exists>x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G. f \\<in> funs_term (rm_vars (set X) \\<theta> x)\"\n    then obtain x where x: \"x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G\" \"f \\<in> funs_term (rm_vars (set X) \\<theta> x)\"\n      by auto\n    hence \"x \\<notin> set X\" \"rm_vars (set X) \\<theta> x = \\<theta> x\" by auto\n    thus ?thesis using x by (auto simp add: assms NegChecks)\n  qed (auto simp add: assms NegChecks)\nqed (use assms funs_term_subst[of _ \\<theta>] in auto)\n\nlemma trms\\<^sub>s\\<^sub>s\\<^sub>t_funs_term_cases:\n  assumes \"t \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\" \"f \\<in> funs_term t\"\n  shows \"(\\<exists>u \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t S. f \\<in> funs_term u) \\<or> (\\<exists>x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t S. f \\<in> funs_term (\\<theta> x))\"\nusing assms(1)\nproof (induction S)\n  case (Cons s S) thus ?case\n  proof (cases \"t \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\")\n    case False\n    hence \"t \\<in> trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (s \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\" using Cons.prems(1) subst_sst_cons[of s S \\<theta>] trms\\<^sub>s\\<^sub>s\\<^sub>t_cons by auto\n    thus ?thesis using trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_funs_term_cases[OF _ assms(2)] by fastforce\n  qed auto\nqed simp\n\nlemma fv\\<^sub>s\\<^sub>s\\<^sub>t_is_subterm_trms\\<^sub>s\\<^sub>s\\<^sub>t_subst:\n  assumes \"x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t T\"\n    and \"bvars\\<^sub>s\\<^sub>s\\<^sub>t T \\<inter> subst_domain \\<theta> = {}\"\n  shows \"\\<theta> x \\<in> subterms\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t (T \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>))\"\nusing trms\\<^sub>s\\<^sub>s\\<^sub>t_subst[OF assms(2)] subterms_subst_subset'[of \\<theta> \"trms\\<^sub>s\\<^sub>s\\<^sub>t T\"]\n      fv\\<^sub>s\\<^sub>s\\<^sub>t_is_subterm_trms\\<^sub>s\\<^sub>s\\<^sub>t[OF assms(1)]\nby (metis (no_types, lifting) image_iff subset_iff subst_apply_term.simps(1))\n\nlemma fv\\<^sub>s\\<^sub>s\\<^sub>t_subst_fv_subset:\n  assumes \"x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t S\" \"x \\<notin> bvars\\<^sub>s\\<^sub>s\\<^sub>t S\" \"fv (\\<theta> x) \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t S = {}\"\n  shows \"fv (\\<theta> x) \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>)\"\nusing assms\nproof (induction S)\n  case (Cons a S)\n  note 1 = fv_subst_subset[of _ _ \\<theta>]\n  note 2 = subst_apply_fv_union subst_apply_fv_unfold[of _ \\<theta>] fv_subset image_eqI\n  note 3 = fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst_cases\n  note 4 = fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p.simps\n  from Cons show ?case\n  proof (cases \"x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t S\")\n    case False\n    hence 5: \"x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a\" \" fv (\\<theta> x) \\<inter> set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a) = {}\" \"x \\<notin> set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a)\"\n      using Cons.prems by auto\n    hence \"fv (\\<theta> x) \\<subseteq> fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>)\"\n    proof (cases a)\n      case (NegChecks X F G)\n      let ?\\<delta> = \"rm_vars (set X) \\<theta>\"\n      have *: \"x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G\" using NegChecks 5(1) by auto\n      have **: \"fv (\\<theta> x) \\<inter> set X = {}\" using NegChecks 5(2) by simp\n      have ***: \"\\<theta> x = ?\\<delta> x\" using NegChecks 5(3) by auto\n      have \"fv (\\<theta> x) \\<subseteq> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ?\\<delta>) \\<union> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s ?\\<delta>)\"\n        using fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_subst_fv_subset[of x _ ?\\<delta>] * *** by auto\n      thus ?thesis using NegChecks ** by auto\n    qed (metis (full_types) 1 5(1) 3(1) 4(1), metis (full_types) 1 5(1) 3(2) 4(2),\n         metis (full_types) 2 5(1) 3(3) 4(3), metis (full_types) 2 5(1) 3(4) 4(4),\n         metis (full_types) 2 5(1) 3(5) 4(5), metis (full_types) 2 5(1) 3(6) 4(6))\n    thus ?thesis by (auto simp add: subst_sst_cons[of a S \\<theta>])\n  qed (auto simp add: subst_sst_cons[of a S \\<theta>])\nqed simp\n\nlemma (in intruder_model) wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s_trms\\<^sub>s\\<^sub>s\\<^sub>t_subst:\n  assumes \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>)\"\n  shows \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>s\\<^sub>t (A \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>))\"\n  using assms\nproof (induction A)\n  case (Cons a A)\n  hence IH: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>s\\<^sub>t (A \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>))\" and *: \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<delta>)\" by auto\n  have \"wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s (trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<delta>))\" by (rule wf\\<^sub>t\\<^sub>r\\<^sub>m\\<^sub>s_trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst[OF *])\n  thus ?case using IH trms\\<^sub>s\\<^sub>s\\<^sub>t_subst_cons[of a A \\<delta>] by blast\nqed simp\n\nlemma fv\\<^sub>s\\<^sub>s\\<^sub>t_subst_obtain_var:\n  assumes \"x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)\"\n  shows \"\\<exists>y \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t S. x \\<in> fv (\\<delta> y)\"\n  using assms\nproof (induction S)\n  case (Cons s S)\n  hence \"x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>) \\<Longrightarrow> \\<exists>y \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t S. x \\<in> fv (\\<delta> y)\"\n    using bvars\\<^sub>s\\<^sub>s\\<^sub>t_cons_subset[of S s]\n    by blast\n  thus ?case\n  proof (cases \"x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)\")\n    case False\n    hence *: \"x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (s \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<delta>)\"\n      using Cons.prems(1) subst_sst_cons[of s S \\<delta>]\n      by fastforce\n\n    have \"\\<exists>y \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p s. x \\<in> fv (\\<delta> y)\"\n    proof (cases s)\n      case (NegChecks X F G)\n      hence \"x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<delta>) \\<or> x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<delta>)\"\n          and **: \"x \\<notin> set X\"\n        using * by simp_all\n      then obtain y where y: \"y \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<or> y \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G\" \"x \\<in> fv ((rm_vars (set X) \\<delta>) y)\"\n        using fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_subst_obtain_var[of _ _ \"rm_vars (set X) \\<delta>\"]\n        by blast\n      have \"y \\<notin> set X\"\n      proof\n        assume y_in: \"y \\<in> set X\"\n        hence \"(rm_vars (set X) \\<delta>) y = Var y\" by auto\n        hence \"x = y\" using y(2) by simp\n        thus False using ** y_in by metis\n      qed\n      thus ?thesis using NegChecks y by auto\n    qed (use * fv_subst_obtain_var in force)+\n    thus ?thesis by auto\n  qed auto\nqed simp\n\nlemma fv\\<^sub>s\\<^sub>s\\<^sub>t_subst_subset_range_vars_if_subset_domain:\n  assumes \"fv\\<^sub>s\\<^sub>s\\<^sub>t S \\<subseteq> subst_domain \\<sigma>\"\n  shows \"fv\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<sigma>) \\<subseteq> range_vars \\<sigma>\"\nusing assms fv\\<^sub>s\\<^sub>s\\<^sub>t_subst_obtain_var[of _ S \\<sigma>] subst_dom_vars_in_subst[of _ \\<sigma>] subst_fv_imgI[of \\<sigma>]\nby (metis (no_types) in_mono subsetI)\n\nlemma fv\\<^sub>s\\<^sub>s\\<^sub>t_in_fv_trms\\<^sub>s\\<^sub>s\\<^sub>t: \"x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t S \\<Longrightarrow> x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t S)\"\nproof (induction S)\n  case (Cons s S) thus ?case\n  proof (cases \"x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t S\")\n    case False\n    hence *: \"x \\<in> fv\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p s\" using Cons.prems by simp\n    hence \"x \\<in> fv\\<^sub>s\\<^sub>e\\<^sub>t (trms\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p s)\"\n    proof (cases s)\n      case (NegChecks X F G)\n      hence \"x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s F \\<or> x \\<in> fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s G\" using * by simp_all\n      thus ?thesis using * fv\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s_in_fv_trms\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s[of x] NegChecks by auto\n    qed auto\n    thus ?thesis by simp\n  qed simp\nqed simp\n\nlemma stateful_strand_step_subst_comp:\n  assumes \"range_vars \\<delta> \\<inter> set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x) = {}\"\n  shows \"x \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<delta> \\<circ>\\<^sub>s \\<theta> = (x \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<delta>) \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>\"\nproof (cases x)\n  case (NegChecks X F G)\n  hence *: \"range_vars \\<delta> \\<inter> set X = {}\" using assms by simp\n  have \"H \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) (\\<delta> \\<circ>\\<^sub>s \\<theta>) = (H \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<delta>) \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s rm_vars (set X) \\<theta>\" for H\n    using pairs_subst_comp rm_vars_comp[OF *] by (induct H) (auto simp add: subst_apply_pairs_def)\n  thus ?thesis using NegChecks by simp\nqed simp_all\n\nlemma stateful_strand_subst_comp:\n  assumes \"range_vars \\<delta> \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t S = {}\"\n  shows \"S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta> \\<circ>\\<^sub>s \\<theta> = (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>) \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>\"\nusing assms\nproof (induction S)\n  case (Cons s S)\n  hence IH: \"S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta> \\<circ>\\<^sub>s \\<theta> = (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>) \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>\" using Cons by auto\n\n  have \"s \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<delta> \\<circ>\\<^sub>s \\<theta> = (s \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<delta>) \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>\"\n    using Cons.prems stateful_strand_step_subst_comp[of \\<delta> s \\<theta>]\n    unfolding range_vars_alt_def by auto\n  thus ?case using IH by (simp add: subst_apply_stateful_strand_def)\nqed simp\n\nlemma subst_apply_bvars_disj_NegChecks:\n  assumes \"set X \\<inter> subst_domain \\<theta> = {}\"\n  shows \"NegChecks X F G \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta> = NegChecks X (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<theta>) (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<theta>)\"\nproof -\n  have \"rm_vars (set X) \\<theta> = \\<theta>\" using assms rm_vars_apply'[of \\<theta> \"set X\"] by auto\n  thus ?thesis by simp\nqed\n\nlemma subst_apply_NegChecks_no_bvars[simp]:\n  \"\\<forall>[]\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: F'\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta> = \\<forall>[]\\<langle>\\<or>\\<noteq>: (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<theta>) \\<or>\\<notin>: (F' \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<theta>)\\<rangle>\"\n  \"\\<forall>[]\\<langle>\\<or>\\<noteq>: [] \\<or>\\<notin>: F'\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta> = \\<forall>[]\\<langle>\\<or>\\<noteq>: [] \\<or>\\<notin>: (F' \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<theta>)\\<rangle>\"\n  \"\\<forall>[]\\<langle>\\<or>\\<noteq>: F \\<or>\\<notin>: []\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta> = \\<forall>[]\\<langle>\\<or>\\<noteq>: (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<theta>) \\<or>\\<notin>: []\\<rangle>\"\n  \"\\<forall>[]\\<langle>\\<or>\\<noteq>: [] \\<or>\\<notin>: [(t,s)]\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta> = \\<forall>[]\\<langle>\\<or>\\<noteq>: [] \\<or>\\<notin>: ([(t \\<cdot> \\<theta>,s \\<cdot> \\<theta>)])\\<rangle>\" (is ?A)\n  \"\\<forall>[]\\<langle>\\<or>\\<noteq>: [(t,s)] \\<or>\\<notin>: []\\<rangle> \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta> = \\<forall>[]\\<langle>\\<or>\\<noteq>: ([(t \\<cdot> \\<theta>,s \\<cdot> \\<theta>)]) \\<or>\\<notin>: []\\<rangle>\" (is ?B)\nby simp_all\n\nlemma setops\\<^sub>s\\<^sub>s\\<^sub>t_mono:\n  \"set M \\<subseteq> set N \\<Longrightarrow> setops\\<^sub>s\\<^sub>s\\<^sub>t M \\<subseteq> setops\\<^sub>s\\<^sub>s\\<^sub>t N\"\nby (auto simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma setops\\<^sub>s\\<^sub>s\\<^sub>t_nil[simp]: \"setops\\<^sub>s\\<^sub>s\\<^sub>t [] = {}\"\nby (simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma setops\\<^sub>s\\<^sub>s\\<^sub>t_cons[simp]: \"setops\\<^sub>s\\<^sub>s\\<^sub>t (a#A) = setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a \\<union> setops\\<^sub>s\\<^sub>s\\<^sub>t A\"\nby (simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma setops\\<^sub>s\\<^sub>s\\<^sub>t_cons_subset[simp]: \"setops\\<^sub>s\\<^sub>s\\<^sub>t A \\<subseteq> setops\\<^sub>s\\<^sub>s\\<^sub>t (a#A)\"\nusing setops\\<^sub>s\\<^sub>s\\<^sub>t_cons[of a A] by blast\n\nlemma setops\\<^sub>s\\<^sub>s\\<^sub>t_append: \"setops\\<^sub>s\\<^sub>s\\<^sub>t (A@B) = setops\\<^sub>s\\<^sub>s\\<^sub>t A \\<union> setops\\<^sub>s\\<^sub>s\\<^sub>t B\"\nproof (induction A)\n  case (Cons a A) thus ?case by (cases a) (auto simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\nqed (simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_member_iff:\n  \"(t,s) \\<in> setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p x \\<longleftrightarrow>\n    (x = Insert t s \\<or> x = Delete t s \\<or> (\\<exists>ac. x = InSet ac t s) \\<or>\n     (\\<exists>X F F'. x = NegChecks X F F' \\<and> (t,s) \\<in> set F'))\"\nby (cases x) auto\n\nlemma setops\\<^sub>s\\<^sub>s\\<^sub>t_member_iff:\n  \"(t,s) \\<in> setops\\<^sub>s\\<^sub>s\\<^sub>t A \\<longleftrightarrow>\n    (Insert t s \\<in> set A \\<or> Delete t s \\<in> set A \\<or> (\\<exists>ac. InSet ac t s \\<in> set A) \\<or>\n     (\\<exists>X F F'. NegChecks X F F' \\<in> set A \\<and> (t,s) \\<in> set F'))\"\n  (is \"?P \\<longleftrightarrow> ?Q\")\nproof (induction A)\n  case (Cons a A) thus ?case\n  proof (cases \"(t, s) \\<in> setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a\")\n    case True thus ?thesis using setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_member_iff[of t s a] by auto\n  qed auto\nqed simp\n\nlemma setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst:\n  assumes \"set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a) \\<inter> subst_domain \\<theta> = {}\"\n  shows \"setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\"\nproof (cases a)\n  case (NegChecks X F G)\n  hence \"rm_vars (set X) \\<theta> = \\<theta>\" using assms rm_vars_apply'[of \\<theta> \"set X\"] by auto\n  hence \"setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = set (G \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<theta>)\"\n        \"setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<theta> = set G \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\"\n    using NegChecks image_Un by simp_all\n  thus ?thesis by (simp add: subst_apply_pairs_def) \nqed simp_all\n\nlemma setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst':\n  assumes \"\\<not>is_NegChecks a\"\n  shows \"setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<theta>) = setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\"\nusing assms by (cases a) auto\n\n\n\nlemma setops\\<^sub>s\\<^sub>s\\<^sub>t_subst:\n  assumes \"bvars\\<^sub>s\\<^sub>s\\<^sub>t S \\<inter> subst_domain \\<theta> = {}\"\n  shows \"setops\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>) = setops\\<^sub>s\\<^sub>s\\<^sub>t S \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\"\nusing assms\nproof (induction S)\n  case (Cons a S)\n  have \"bvars\\<^sub>s\\<^sub>s\\<^sub>t S \\<inter> subst_domain \\<theta> = {}\" and *: \"set (bvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p a) \\<inter> subst_domain \\<theta> = {}\"\n    using Cons.prems by auto\n  hence IH: \"setops\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<theta>) = setops\\<^sub>s\\<^sub>s\\<^sub>t S \\<cdot>\\<^sub>p\\<^sub>s\\<^sub>e\\<^sub>t \\<theta>\"\n    using Cons.IH by auto\n  show ?case\n    using setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst[OF *] IH unfolding setops\\<^sub>s\\<^sub>s\\<^sub>t_def\n    by (auto simp add: subst_apply_stateful_strand_def)\nqed (simp add: setops\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma setops\\<^sub>s\\<^sub>s\\<^sub>t_subst':\n  fixes p::\"('a,'b) term \\<times> ('a,'b) term\" and \\<delta>::\"('a,'b) subst\"\n  assumes \"p \\<in> setops\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)\"\n  shows \"\\<exists>s \\<in> setops\\<^sub>s\\<^sub>s\\<^sub>t S. \\<exists>X. set X \\<subseteq> bvars\\<^sub>s\\<^sub>s\\<^sub>t S \\<and> p = s \\<cdot>\\<^sub>p rm_vars (set X) \\<delta>\"\nusing assms\nproof (induction S)\n  case (Cons a S)\n  note 0 = setops\\<^sub>s\\<^sub>s\\<^sub>t_cons[of a S] bvars\\<^sub>s\\<^sub>s\\<^sub>t_Cons[of a S]\n  note 1 = setops\\<^sub>s\\<^sub>s\\<^sub>t_cons[of \"a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<delta>\" \"S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>\"] subst_sst_cons[of a S \\<delta>]\n  have \"p \\<in> setops\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>) \\<or> p \\<in> setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<delta>)\" using Cons.prems 1 by auto\n  thus ?case\n  proof\n    assume *: \"p \\<in> setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (a \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p \\<delta>)\"\n    show ?thesis using setops\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p_subst''[OF *] 0 by blast\n  next\n    assume *: \"p \\<in> setops\\<^sub>s\\<^sub>s\\<^sub>t (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)\"\n    show ?thesis using Cons.IH[OF *] 0 by blast\n  qed\nqed simp\n\n\nsubsection \\<open>Stateful Constraint Semantics\\<close>\ncontext intruder_model\nbegin\n\ndefinition negchecks_model where\n  \"negchecks_model (\\<I>::('a,'b) subst) (D::('a,'b) dbstate) X F G \\<equiv>\n      (\\<forall>\\<delta>. subst_domain \\<delta> = set X \\<and> ground (subst_range \\<delta>) \\<longrightarrow> \n              (list_ex (\\<lambda>f. fst f \\<cdot> (\\<delta> \\<circ>\\<^sub>s \\<I>) \\<noteq> snd f \\<cdot> (\\<delta> \\<circ>\\<^sub>s \\<I>)) F \\<or>\n               list_ex (\\<lambda>f. f \\<cdot>\\<^sub>p (\\<delta> \\<circ>\\<^sub>s \\<I>) \\<notin> D) G))\"\n\nfun strand_sem_stateful::\n  \"('fun,'var) terms \\<Rightarrow> ('fun,'var) dbstate \\<Rightarrow> ('fun,'var) stateful_strand \\<Rightarrow> ('fun,'var) subst \\<Rightarrow> bool\"\n  (\"\\<lbrakk>_; _; _\\<rbrakk>\\<^sub>s\")\nwhere\n  \"\\<lbrakk>M; D; []\\<rbrakk>\\<^sub>s = (\\<lambda>\\<I>. True)\"\n| \"\\<lbrakk>M; D; Send t#S\\<rbrakk>\\<^sub>s = (\\<lambda>\\<I>. M \\<turnstile> t \\<cdot> \\<I> \\<and> \\<lbrakk>M; D; S\\<rbrakk>\\<^sub>s \\<I>)\"\n| \"\\<lbrakk>M; D; Receive t#S\\<rbrakk>\\<^sub>s = (\\<lambda>\\<I>. \\<lbrakk>insert (t \\<cdot> \\<I>) M; D; S\\<rbrakk>\\<^sub>s \\<I>)\"\n| \"\\<lbrakk>M; D; Equality _ t t'#S\\<rbrakk>\\<^sub>s = (\\<lambda>\\<I>. t \\<cdot> \\<I> = t' \\<cdot> \\<I> \\<and> \\<lbrakk>M; D; S\\<rbrakk>\\<^sub>s \\<I>)\"\n| \"\\<lbrakk>M; D; Insert t s#S\\<rbrakk>\\<^sub>s = (\\<lambda>\\<I>. \\<lbrakk>M; insert ((t,s) \\<cdot>\\<^sub>p \\<I>) D; S\\<rbrakk>\\<^sub>s \\<I>)\"\n| \"\\<lbrakk>M; D; Delete t s#S\\<rbrakk>\\<^sub>s = (\\<lambda>\\<I>. \\<lbrakk>M; D - {(t,s) \\<cdot>\\<^sub>p \\<I>}; S\\<rbrakk>\\<^sub>s \\<I>)\"\n| \"\\<lbrakk>M; D; InSet _ t s#S\\<rbrakk>\\<^sub>s = (\\<lambda>\\<I>. (t,s) \\<cdot>\\<^sub>p \\<I> \\<in> D \\<and> \\<lbrakk>M; D; S\\<rbrakk>\\<^sub>s \\<I>)\"\n| \"\\<lbrakk>M; D; NegChecks X F F'#S\\<rbrakk>\\<^sub>s = (\\<lambda>\\<I>. negchecks_model \\<I> D X F F' \\<and> \\<lbrakk>M; D; S\\<rbrakk>\\<^sub>s \\<I>)\"\n\n\nlemmas strand_sem_stateful_induct =\n  strand_sem_stateful.induct[case_names Nil ConsSnd ConsRcv ConsEq\n                                        ConsIns ConsDel ConsIn ConsNegChecks]\n\nabbreviation constr_sem_stateful (infix \"\\<Turnstile>\\<^sub>s\" 91) where \"\\<I> \\<Turnstile>\\<^sub>s A \\<equiv> \\<lbrakk>{}; {}; A\\<rbrakk>\\<^sub>s \\<I>\"\n\nlemma stateful_strand_sem_NegChecks_no_bvars:\n  \"\\<lbrakk>M; D; [\\<langle>t not in s\\<rangle>]\\<rbrakk>\\<^sub>s \\<I> \\<Longrightarrow> (t \\<cdot> \\<I>, s \\<cdot> \\<I>) \\<notin> D\"\n  \"\\<lbrakk>M; D; [\\<langle>t != s\\<rangle>]\\<rbrakk>\\<^sub>s \\<I> \\<Longrightarrow> t \\<cdot> \\<I> \\<noteq> s \\<cdot> \\<I>\"\nby (simp_all add: negchecks_model_def empty_dom_iff_empty_subst)\n\nlemma strand_sem_ik_mono_stateful:\n  \"\\<lbrakk>M; D; A\\<rbrakk>\\<^sub>s \\<I> \\<Longrightarrow> \\<lbrakk>M \\<union> M'; D; A\\<rbrakk>\\<^sub>s \\<I>\"\nusing ideduct_mono by (induct A arbitrary: M M' D rule: strand_sem_stateful.induct) force+\n\nlemma strand_sem_append_stateful:\n  \"\\<lbrakk>M; D; A@B\\<rbrakk>\\<^sub>s \\<I> \\<longleftrightarrow> \\<lbrakk>M; D; A\\<rbrakk>\\<^sub>s \\<I> \\<and> \\<lbrakk>M \\<union> (ik\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>); dbupd\\<^sub>s\\<^sub>s\\<^sub>t A \\<I> D; B\\<rbrakk>\\<^sub>s \\<I>\"\n  (is \"?P \\<longleftrightarrow> ?Q \\<and> ?R\")\nproof -\n  have 1: \"?P \\<Longrightarrow> ?Q\" by (induct A rule: strand_sem_stateful.induct) auto\n\n  have 2: \"?P \\<Longrightarrow> ?R\"\n  proof (induction A arbitrary: M D B)\n    case (Cons a A) thus ?case\n    proof (cases a)\n      case (Receive t)\n      have \"insert (t \\<cdot> \\<I>) (M \\<union> (ik\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>)) = M \\<union> (ik\\<^sub>s\\<^sub>s\\<^sub>t (a#A) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>)\"\n           \"dbupd\\<^sub>s\\<^sub>s\\<^sub>t A \\<I> D = dbupd\\<^sub>s\\<^sub>s\\<^sub>t (a#A) \\<I> D\"\n        using Receive by (auto simp add: ik\\<^sub>s\\<^sub>s\\<^sub>t_def)\n      thus ?thesis using Cons Receive by force\n    qed (auto simp add: ik\\<^sub>s\\<^sub>s\\<^sub>t_def)\n  qed (simp add: ik\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\n  have 3: \"?Q \\<Longrightarrow> ?R \\<Longrightarrow> ?P\"\n  proof (induction A arbitrary: M D)\n    case (Cons a A) thus ?case\n    proof (cases a)\n      case (Receive t)\n      have \"insert (t \\<cdot> \\<I>) (M \\<union> (ik\\<^sub>s\\<^sub>s\\<^sub>t A \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>)) = M \\<union> (ik\\<^sub>s\\<^sub>s\\<^sub>t (a#A) \\<cdot>\\<^sub>s\\<^sub>e\\<^sub>t \\<I>)\"\n           \"dbupd\\<^sub>s\\<^sub>s\\<^sub>t A \\<I> D = dbupd\\<^sub>s\\<^sub>s\\<^sub>t (a#A) \\<I> D\"\n        using Receive by (auto simp add: ik\\<^sub>s\\<^sub>s\\<^sub>t_def)\n      thus ?thesis using Cons Receive by simp\n    qed (auto simp add: ik\\<^sub>s\\<^sub>s\\<^sub>t_def)\n  qed (simp add: ik\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\n  show ?thesis by (metis 1 2 3)\nqed\n\nlemma negchecks_model_db_subset:\n  fixes F F'::\"(('a,'b) term \\<times> ('a,'b) term) list\"\n  assumes \"D' \\<subseteq> D\"\n  and \"negchecks_model \\<I> D X F F'\"\n  shows \"negchecks_model \\<I> D' X F F'\"\nproof -\n  have \"list_ex (\\<lambda>f. f \\<cdot>\\<^sub>p \\<delta> \\<circ>\\<^sub>s \\<I> \\<notin> D') F'\"\n    when \"list_ex (\\<lambda>f. f \\<cdot>\\<^sub>p \\<delta> \\<circ>\\<^sub>s \\<I> \\<notin> D) F'\"\n    for \\<delta>::\"('a,'b) subst\"\n    using Bex_set[of F' \"\\<lambda>f. f \\<cdot>\\<^sub>p \\<delta> \\<circ>\\<^sub>s \\<I> \\<notin> D'\"]\n          Bex_set[of F' \"\\<lambda>f. f \\<cdot>\\<^sub>p \\<delta> \\<circ>\\<^sub>s \\<I> \\<notin> D\"]\n          that assms(1)\n    by blast\n  thus ?thesis using assms(2) by (auto simp add: negchecks_model_def)\nqed\n\nlemma negchecks_model_db_supset:\n  fixes F F'::\"(('a,'b) term \\<times> ('a,'b) term) list\"\n  assumes \"D' \\<subseteq> D\"\n    and \"\\<forall>f \\<in> set F'. \\<forall>\\<delta>. subst_domain \\<delta> = set X \\<and> ground (subst_range \\<delta>) \\<longrightarrow> f \\<cdot>\\<^sub>p (\\<delta> \\<circ>\\<^sub>s \\<I>) \\<notin> D - D'\"\n    and \"negchecks_model \\<I> D' X F F'\"\n  shows \"negchecks_model \\<I> D X F F'\"\nproof -\n  have \"list_ex (\\<lambda>f. f \\<cdot>\\<^sub>p \\<delta> \\<circ>\\<^sub>s \\<I> \\<notin> D) F'\"\n    when \"list_ex (\\<lambda>f. f \\<cdot>\\<^sub>p \\<delta> \\<circ>\\<^sub>s \\<I> \\<notin> D') F'\" \"subst_domain \\<delta> = set X \\<and> ground (subst_range \\<delta>)\"\n    for \\<delta>::\"('a,'b) subst\"\n    using Bex_set[of F' \"\\<lambda>f. f \\<cdot>\\<^sub>p \\<delta> \\<circ>\\<^sub>s \\<I> \\<notin> D'\"]\n          Bex_set[of F' \"\\<lambda>f. f \\<cdot>\\<^sub>p \\<delta> \\<circ>\\<^sub>s \\<I> \\<notin> D\"]\n          that assms(1,2)\n    by blast\n  thus ?thesis using assms(3) by (auto simp add: negchecks_model_def)\nqed\n\nlemma negchecks_model_subst:\n  fixes F F'::\"(('a,'b) term \\<times> ('a,'b) term) list\"\n  assumes \"(subst_domain \\<delta> \\<union> range_vars \\<delta>) \\<inter> set X = {}\"\n  shows \"negchecks_model (\\<delta> \\<circ>\\<^sub>s \\<theta>) D X F F' \\<longleftrightarrow> negchecks_model \\<theta> D X (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<delta>) (F' \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<delta>)\"\nproof -\n  have 0: \"\\<sigma> \\<circ>\\<^sub>s (\\<delta> \\<circ>\\<^sub>s \\<theta>) = \\<delta> \\<circ>\\<^sub>s (\\<sigma> \\<circ>\\<^sub>s \\<theta>)\"\n    when \\<sigma>: \"subst_domain \\<sigma> = set X\" \"ground (subst_range \\<sigma>)\" for \\<sigma>\n    by (metis (no_types, lifting) \\<sigma> subst_compose_assoc assms(1) inf_sup_aci(1)\n            subst_comp_eq_if_disjoint_vars sup_inf_absorb range_vars_alt_def)\n\n  { fix \\<sigma>::\"('a,'b) subst\" and t t'\n    assume \\<sigma>: \"subst_domain \\<sigma> = set X\" \"ground (subst_range \\<sigma>)\"\n        and *: \"list_ex (\\<lambda>f. fst f \\<cdot> (\\<sigma> \\<circ>\\<^sub>s (\\<delta> \\<circ>\\<^sub>s \\<theta>)) \\<noteq> snd f \\<cdot> (\\<sigma> \\<circ>\\<^sub>s (\\<delta> \\<circ>\\<^sub>s \\<theta>))) F\"\n    obtain f where f: \"f \\<in> set F\" \"fst f \\<cdot> \\<sigma> \\<circ>\\<^sub>s (\\<delta> \\<circ>\\<^sub>s \\<theta>) \\<noteq> snd f \\<cdot> \\<sigma> \\<circ>\\<^sub>s (\\<delta> \\<circ>\\<^sub>s \\<theta>)\"\n      using * by (induct F) auto\n    hence \"(fst f \\<cdot> \\<delta>) \\<cdot> \\<sigma> \\<circ>\\<^sub>s \\<theta> \\<noteq> (snd f \\<cdot> \\<delta>) \\<cdot> \\<sigma> \\<circ>\\<^sub>s \\<theta>\" using 0[OF \\<sigma>] by simp\n    moreover have \"(fst f \\<cdot> \\<delta>, snd f \\<cdot> \\<delta>) \\<in> set (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<delta>)\"\n      using f(1) by (auto simp add: subst_apply_pairs_def)\n    ultimately have \"list_ex (\\<lambda>f. fst f \\<cdot> (\\<sigma> \\<circ>\\<^sub>s \\<theta>) \\<noteq> snd f \\<cdot> (\\<sigma> \\<circ>\\<^sub>s \\<theta>)) (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<delta>)\"\n      using f(1) Bex_set by fastforce\n  } moreover {\n    fix \\<sigma>::\"('a,'b) subst\" and t t'\n    assume \\<sigma>: \"subst_domain \\<sigma> = set X\" \"ground (subst_range \\<sigma>)\"\n        and *: \"list_ex (\\<lambda>f. f \\<cdot>\\<^sub>p \\<sigma> \\<circ>\\<^sub>s (\\<delta> \\<circ>\\<^sub>s \\<theta>) \\<notin> D) F'\"\n    obtain f where f: \"f \\<in> set F'\" \"f \\<cdot>\\<^sub>p \\<sigma> \\<circ>\\<^sub>s (\\<delta> \\<circ>\\<^sub>s \\<theta>) \\<notin> D\"\n      using * by (induct F') auto\n    hence \"f \\<cdot>\\<^sub>p \\<delta> \\<cdot>\\<^sub>p \\<sigma> \\<circ>\\<^sub>s \\<theta> \\<notin> D\" using 0[OF \\<sigma>] by (metis subst_pair_compose)\n    moreover have \"f \\<cdot>\\<^sub>p \\<delta> \\<in> set (F' \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<delta>)\"\n      using f(1) by (auto simp add: subst_apply_pairs_def)\n    ultimately have \"list_ex (\\<lambda>f. f \\<cdot>\\<^sub>p \\<sigma> \\<circ>\\<^sub>s \\<theta> \\<notin> D) (F' \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<delta>)\"\n      using f(1) Bex_set by fastforce\n  } moreover {\n    fix \\<sigma>::\"('a,'b) subst\" and t t'\n    assume \\<sigma>: \"subst_domain \\<sigma> = set X\" \"ground (subst_range \\<sigma>)\"\n        and *: \"list_ex (\\<lambda>f. fst f \\<cdot> (\\<sigma> \\<circ>\\<^sub>s \\<theta>) \\<noteq> snd f \\<cdot> (\\<sigma> \\<circ>\\<^sub>s \\<theta>)) (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<delta>)\"\n    obtain f where f: \"f \\<in> set (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<delta>)\" \"fst f \\<cdot> \\<sigma> \\<circ>\\<^sub>s \\<theta> \\<noteq> snd f \\<cdot> \\<sigma> \\<circ>\\<^sub>s \\<theta>\"\n      using * by (induct F) (auto simp add: subst_apply_pairs_def)\n    then obtain g where g: \"g \\<in> set F\" \"f = g \\<cdot>\\<^sub>p \\<delta>\" by (auto simp add: subst_apply_pairs_def)\n    have \"fst g \\<cdot> \\<sigma> \\<circ>\\<^sub>s (\\<delta> \\<circ>\\<^sub>s \\<theta>) \\<noteq> snd g \\<cdot> \\<sigma> \\<circ>\\<^sub>s (\\<delta> \\<circ>\\<^sub>s \\<theta>)\"\n      using f(2) g 0[OF \\<sigma>] by (simp add: prod.case_eq_if)\n    hence \"list_ex (\\<lambda>f. fst f \\<cdot> (\\<sigma> \\<circ>\\<^sub>s (\\<delta> \\<circ>\\<^sub>s \\<theta>)) \\<noteq> snd f \\<cdot> (\\<sigma> \\<circ>\\<^sub>s (\\<delta> \\<circ>\\<^sub>s \\<theta>))) F\"\n      using g Bex_set by fastforce\n  } moreover {\n    fix \\<sigma>::\"('a,'b) subst\" and t t'\n    assume \\<sigma>: \"subst_domain \\<sigma> = set X\" \"ground (subst_range \\<sigma>)\"\n        and *: \"list_ex (\\<lambda>f. f \\<cdot>\\<^sub>p (\\<sigma> \\<circ>\\<^sub>s \\<theta>) \\<notin> D) (F' \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<delta>)\"\n    obtain f where f: \"f \\<in> set (F' \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<delta>)\" \"f \\<cdot>\\<^sub>p \\<sigma> \\<circ>\\<^sub>s \\<theta> \\<notin> D\"\n      using * by (induct F') (auto simp add: subst_apply_pairs_def)\n    then obtain g where g: \"g \\<in> set F'\" \"f = g \\<cdot>\\<^sub>p \\<delta>\" by (auto simp add: subst_apply_pairs_def)\n    have \"g \\<cdot>\\<^sub>p \\<sigma> \\<circ>\\<^sub>s (\\<delta> \\<circ>\\<^sub>s \\<theta>) \\<notin> D\"\n      using f(2) g 0[OF \\<sigma>] by (simp add: prod.case_eq_if)\n    hence \"list_ex (\\<lambda>f. f \\<cdot>\\<^sub>p (\\<sigma> \\<circ>\\<^sub>s (\\<delta> \\<circ>\\<^sub>s \\<theta>)) \\<notin> D) F'\"\n      using g Bex_set by fastforce\n  } ultimately show ?thesis using assms unfolding negchecks_model_def by blast\nqed\n\nlemma strand_sem_subst_stateful:\n  fixes \\<delta>::\"('fun,'var) subst\"\n  assumes \"(subst_domain \\<delta> \\<union> range_vars \\<delta>) \\<inter> bvars\\<^sub>s\\<^sub>s\\<^sub>t S = {}\"\n  shows \"\\<lbrakk>M; D; S\\<rbrakk>\\<^sub>s (\\<delta> \\<circ>\\<^sub>s \\<theta>) \\<longleftrightarrow> \\<lbrakk>M; D; S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>\\<rbrakk>\\<^sub>s \\<theta>\"\nproof\n  note [simp] = subst_sst_cons[of _ _ \\<delta>] subst_subst_compose[of _ \\<delta> \\<theta>]\n\n  have \"(subst_domain \\<delta> \\<union> range_vars \\<delta>) \\<inter> (subst_domain \\<gamma> \\<union> range_vars \\<gamma>) = {}\"\n    when \\<delta>: \"(subst_domain \\<delta> \\<union> range_vars \\<delta>) \\<inter> set X = {}\"\n      and \\<gamma>: \"subst_domain \\<gamma> = set X\" \"ground (subst_range \\<gamma>)\"\n    for X and \\<gamma>::\"('fun,'var) subst\"\n    using \\<delta> \\<gamma> unfolding range_vars_alt_def by auto\n  hence 0: \"\\<gamma> \\<circ>\\<^sub>s \\<delta> = \\<delta> \\<circ>\\<^sub>s \\<gamma>\"\n    when \\<delta>: \"(subst_domain \\<delta> \\<union> range_vars \\<delta>) \\<inter> set X = {}\"\n      and \\<gamma>: \"subst_domain \\<gamma> = set X\" \"ground (subst_range \\<gamma>)\"\n    for \\<gamma> X\n    by (metis \\<delta> \\<gamma> subst_comp_eq_if_disjoint_vars)\n\n  show \"\\<lbrakk>M; D; S\\<rbrakk>\\<^sub>s (\\<delta> \\<circ>\\<^sub>s \\<theta>) \\<Longrightarrow> \\<lbrakk>M; D; S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>\\<rbrakk>\\<^sub>s \\<theta>\" using assms\n  proof (induction S arbitrary: M D rule: strand_sem_stateful_induct)\n    case (ConsNegChecks M D X F F' S)\n    hence *: \"\\<lbrakk>M; D; S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>\\<rbrakk>\\<^sub>s \\<theta>\" and **: \"(subst_domain \\<delta> \\<union> range_vars \\<delta>) \\<inter> set X = {}\"\n      unfolding bvars\\<^sub>s\\<^sub>s\\<^sub>t_def negchecks_model_def by (force, auto)\n    have \"negchecks_model (\\<delta> \\<circ>\\<^sub>s \\<theta>) D X F F'\" using ConsNegChecks by auto\n    hence \"negchecks_model \\<theta> D X (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<delta>) (F' \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<delta>)\"\n      using 0[OF **] negchecks_model_subst[OF **] by blast\n    moreover have \"rm_vars (set X) \\<delta> = \\<delta>\" using ConsNegChecks.prems(2) by force\n    ultimately show ?case using * by auto\n  qed simp_all\n\n  show \"\\<lbrakk>M; D; S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>\\<rbrakk>\\<^sub>s \\<theta> \\<Longrightarrow> \\<lbrakk>M; D; S\\<rbrakk>\\<^sub>s (\\<delta> \\<circ>\\<^sub>s \\<theta>)\" using assms\n  proof (induction S arbitrary: M D rule: strand_sem_stateful_induct)\n    case (ConsNegChecks M D X F F' S)\n    have \\<delta>: \"rm_vars (set X) \\<delta> = \\<delta>\" using ConsNegChecks.prems(2) by force\n    hence *: \"\\<lbrakk>M; D; S\\<rbrakk>\\<^sub>s (\\<delta> \\<circ>\\<^sub>s \\<theta>)\" and **: \"(subst_domain \\<delta> \\<union> range_vars \\<delta>) \\<inter> set X = {}\"\n      using ConsNegChecks unfolding bvars\\<^sub>s\\<^sub>s\\<^sub>t_def negchecks_model_def by auto\n    have \"negchecks_model \\<theta> D X (F \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<delta>) (F' \\<cdot>\\<^sub>p\\<^sub>a\\<^sub>i\\<^sub>r\\<^sub>s \\<delta>)\"\n      using ConsNegChecks.prems(1) \\<delta> by (auto simp add: subst_compose_assoc negchecks_model_def)\n    hence \"negchecks_model (\\<delta> \\<circ>\\<^sub>s \\<theta>) D X F F'\"\n      using 0[OF **] negchecks_model_subst[OF **] by blast\n    thus ?case using * by auto\n  qed simp_all\nqed\n\nend\n\n\nsubsection \\<open>Well-Formedness Lemmata\\<close>\nlemma wfvarsocc\\<^sub>s\\<^sub>s\\<^sub>t_subset_wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t[simp]:\n  \"wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t S \\<subseteq> wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t S\"\nby (induction S)\n   (auto simp add: wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t_def wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t_def\n         split: stateful_strand_step.split poscheckvariant.split)\n\nlemma wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t_append: \"wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t (S@S') = wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t S \\<union> wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t S'\"\nby (simp add: wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t_union[simp]:\n  \"wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t (S@T) = wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t S \\<union> wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t T\"\nby (simp add: wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t_singleton:\n  \"wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t [s] = wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p s\"\nby (simp add: wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma wf\\<^sub>s\\<^sub>s\\<^sub>t_prefix[dest]: \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V (S@S') \\<Longrightarrow> wf'\\<^sub>s\\<^sub>s\\<^sub>t V S\"\nby (induct S rule: wf'\\<^sub>s\\<^sub>s\\<^sub>t.induct) auto\n\nlemma wf\\<^sub>s\\<^sub>s\\<^sub>t_vars_mono: \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V S \\<Longrightarrow> wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> W) S\"\nproof (induction S arbitrary: V)\n  case (Cons x S) thus ?case\n  proof (cases x)\n    case (Send t)\n    hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> fv t \\<union> W) S\" using Cons.prems(1) Cons.IH by simp\n    thus ?thesis using Send by (simp add: sup_commute sup_left_commute)\n  next\n    case (Equality a t t')\n    show ?thesis\n    proof (cases a)\n      case Assign\n      hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> fv t \\<union> W) S\" \"fv t' \\<subseteq> V \\<union> W\" using Equality Cons.prems(1) Cons.IH by auto\n      thus ?thesis using Equality Assign by (simp add: sup_commute sup_left_commute)\n    next\n      case Check thus ?thesis using Equality Cons by auto\n    qed\n  next\n    case (InSet a t t')\n    show ?thesis\n    proof (cases a)\n      case Assign\n      hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> fv t \\<union> fv t' \\<union> W) S\" using InSet Cons.prems(1) Cons.IH by auto\n      thus ?thesis using InSet Assign by (simp add: sup_commute sup_left_commute)\n    next\n      case Check thus ?thesis using InSet Cons by auto\n    qed\n  qed auto\nqed simp\n\nlemma wf\\<^sub>s\\<^sub>s\\<^sub>tI[intro]: \"wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t S \\<subseteq> V \\<Longrightarrow> wf'\\<^sub>s\\<^sub>s\\<^sub>t V S\"\nproof (induction S)\n  case (Cons x S) thus ?case\n  proof (cases x)\n    case (Send t)\n    hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V S\" \"V \\<union> fv t = V\"\n      using Cons\n      unfolding wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t_def\n      by auto\n    thus ?thesis using Send by simp\n  next\n    case (Equality a t t')\n    show ?thesis\n    proof (cases a)\n      case Assign\n      hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V S\" \"fv t' \\<subseteq> V\"\n        using Equality Cons \n        unfolding wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t_def\n        by auto\n      thus ?thesis using wf\\<^sub>s\\<^sub>s\\<^sub>t_vars_mono Equality Assign by simp\n    next\n      case Check\n      thus ?thesis\n        using Equality Cons\n        unfolding wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t_def\n        by auto\n    qed\n  next\n    case (InSet a t t')\n    show ?thesis\n    proof (cases a)\n      case Assign\n      hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V S\" \"fv t \\<union> fv t' \\<subseteq> V\"\n        using InSet Cons\n        unfolding wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t_def\n        by auto\n      thus ?thesis using wf\\<^sub>s\\<^sub>s\\<^sub>t_vars_mono InSet Assign by (simp add: Un_assoc) \n    next\n      case Check\n      thus ?thesis\n        using InSet Cons\n        unfolding wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t_def\n        by auto\n    qed\n  qed (simp_all add: wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t_def)\nqed (simp add: wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma wf\\<^sub>s\\<^sub>s\\<^sub>tI'[intro]:\n  assumes \"\\<Union>((\\<lambda>x. case x of\n            Receive t \\<Rightarrow> fv t\n          | Equality Assign _ t' \\<Rightarrow> fv t'\n          | Insert t t' \\<Rightarrow> fv t \\<union> fv t'\n          | _ \\<Rightarrow> {}) ` set S) \\<subseteq> V\"\n  shows \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V S\"\nusing assms\nproof (induction S)\n  case (Cons x S) thus ?case\n  proof (cases x)\n    case (Equality a t t')\n    thus ?thesis using Cons by (cases a) (auto simp add: wf\\<^sub>s\\<^sub>s\\<^sub>t_vars_mono)\n  next\n    case (InSet a t t')\n    thus ?thesis using Cons by (cases a) (auto simp add: wf\\<^sub>s\\<^sub>s\\<^sub>t_vars_mono Un_assoc)\n  qed (simp_all add: wf\\<^sub>s\\<^sub>s\\<^sub>t_vars_mono)\nqed simp\n\nlemma wf\\<^sub>s\\<^sub>s\\<^sub>t_append_exec: \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V (S@S') \\<Longrightarrow> wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t S) S'\"\nproof (induction S arbitrary: V)\n  case (Cons x S V) thus ?case\n  proof (cases x)\n    case (Send t)\n    hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> fv t \\<union> wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t S) S'\" using Cons.prems Cons.IH by simp\n    thus ?thesis using Send unfolding wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t_def by (auto simp add: sup_assoc)\n  next\n    case (Equality a t t') show ?thesis\n    proof (cases a)\n      case Assign\n      hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> fv t \\<union> wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t S) S'\" using Equality Cons.prems Cons.IH by auto\n      thus ?thesis using Equality Assign unfolding wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t_def by (auto simp add: sup_assoc)\n    next\n      case Check\n      hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t S) S'\" using Equality Cons.prems Cons.IH by auto\n      thus ?thesis using Equality Check unfolding wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t_def by (auto simp add: sup_assoc)\n    qed\n  next\n    case (InSet a t t') show ?thesis\n    proof (cases a)\n      case Assign\n      hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> fv t \\<union> fv t' \\<union> wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t S) S'\" using InSet Cons.prems Cons.IH by auto\n      thus ?thesis using InSet Assign unfolding wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t_def by (auto simp add: sup_assoc)\n    next\n      case Check\n      hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t S) S'\" using InSet Cons.prems Cons.IH by auto\n      thus ?thesis using InSet Check unfolding wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t_def by (auto simp add: sup_assoc)\n    qed\n  qed (auto simp add: wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t_def)\nqed (simp add: wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma wf\\<^sub>s\\<^sub>s\\<^sub>t_append:\n  \"wf'\\<^sub>s\\<^sub>s\\<^sub>t X S \\<Longrightarrow> wf'\\<^sub>s\\<^sub>s\\<^sub>t Y T \\<Longrightarrow> wf'\\<^sub>s\\<^sub>s\\<^sub>t (X \\<union> Y) (S@T)\"\nproof (induction X S rule: wf'\\<^sub>s\\<^sub>s\\<^sub>t.induct)\n  case 1 thus ?case by (metis wf\\<^sub>s\\<^sub>s\\<^sub>t_vars_mono Un_commute append_Nil)\nnext\n  case 3 thus ?case by (metis append_Cons Un_commute Un_assoc wf'\\<^sub>s\\<^sub>s\\<^sub>t.simps(3))\nnext\n  case (4 V t t' S)\n  hence *: \"fv t' \\<subseteq> V\" and \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> fv t \\<union> Y) (S @ T)\" by simp_all\n  hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> Y \\<union> fv t) (S @ T)\" by (metis Un_commute Un_assoc)\n  thus ?case using * by auto\nnext\n  case (8 V t t' S)\n  hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> fv t \\<union> fv t' \\<union> Y) (S @ T)\" by simp_all\n  hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> Y \\<union> fv t \\<union> fv t') (S @ T)\" by (metis Un_commute Un_assoc)\n  thus ?case by auto\nqed auto\n\nlemma wf\\<^sub>s\\<^sub>s\\<^sub>t_append_suffix:\n  \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V S \\<Longrightarrow> wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t S' \\<subseteq> wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t S \\<union> V \\<Longrightarrow> wf'\\<^sub>s\\<^sub>s\\<^sub>t V (S@S')\"\nproof (induction V S rule: wf'\\<^sub>s\\<^sub>s\\<^sub>t.induct)\n  case (2 V t S)\n  hence *: \"fv t \\<subseteq> V\" \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V S\" by simp_all\n  hence \"wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t S' \\<subseteq> wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t S \\<union> V\"\n    using \"2.prems\"(2) unfolding wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t_def by auto\n  thus ?case using \"2.IH\" * by simp\nnext\n  case (3 V t S)\n  hence *: \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> fv t) S\" by simp_all\n  hence \"wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t S' \\<subseteq> wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t S \\<union> (V \\<union> fv t)\"\n    using \"3.prems\"(2) unfolding wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t_def by auto\n  thus ?case using \"3.IH\" * by simp\nnext\n  case (4 V t t' S)\n  hence *: \"fv t' \\<subseteq> V\" \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> fv t) S\" by simp_all\n  moreover have \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (\\<langle>t := t'\\<rangle>) = fv t \\<union> fv t'\"\n    by simp\n  moreover have \"wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t (\\<langle>t := t'\\<rangle>#S) = fv t \\<union> fv t' \\<union> wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t S\"\n    unfolding wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t_def by auto\n  ultimately have \"wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t S' \\<subseteq> wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t S \\<union> (V \\<union> fv t)\"\n    using \"4.prems\"(2) by blast\n  thus ?case using \"4.IH\" * by simp\nnext\n  case (6 V t t' S)\n  hence *: \"fv t \\<union> fv t' \\<subseteq> V\" \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V S\" by simp_all\n  moreover have \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (insert\\<langle>t,t'\\<rangle>) = fv t \\<union> fv t'\"\n    by simp\n  moreover have \"wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t (insert\\<langle>t,t'\\<rangle>#S) = fv t \\<union> fv t' \\<union> wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t S\"\n    unfolding wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t_def by auto\n  ultimately have \"wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t S' \\<subseteq> wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t S \\<union> V\"\n    using \"6.prems\"(2) by blast\n  thus ?case using \"6.IH\" * by simp\nnext\n  case (8 V t t' S)\n  hence *: \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> fv t \\<union> fv t') S\" by simp_all\n  moreover have \"vars\\<^sub>s\\<^sub>s\\<^sub>t\\<^sub>p (select\\<langle>t,t'\\<rangle>) = fv t \\<union> fv t'\"\n    by simp\n  moreover have \"wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t (select\\<langle>t,t'\\<rangle>#S) = fv t \\<union> fv t' \\<union> wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t S\"\n    unfolding wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t_def by auto\n  ultimately have \"wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t S' \\<subseteq> wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t S \\<union> (V \\<union> fv t \\<union> fv t')\"\n    using \"8.prems\"(2) by blast\n  thus ?case using \"8.IH\" * by simp\nqed (simp_all add: wf\\<^sub>s\\<^sub>s\\<^sub>tI wfrestrictedvars\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma wf\\<^sub>s\\<^sub>s\\<^sub>t_append_suffix':\n  assumes \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V S\"\n    and \"\\<Union>((\\<lambda>x. case x of\n            Receive t \\<Rightarrow> fv t\n          | Equality Assign _ t' \\<Rightarrow> fv t'\n          | Insert t t' \\<Rightarrow> fv t \\<union> fv t'\n          | _ \\<Rightarrow> {}) ` set S') \\<subseteq> wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t S \\<union> V\"\n  shows \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V (S@S')\"\nusing assms\nby (induction V S rule: wf'\\<^sub>s\\<^sub>s\\<^sub>t.induct)\n   (auto simp add: wf\\<^sub>s\\<^sub>s\\<^sub>tI' wf\\<^sub>s\\<^sub>s\\<^sub>t_vars_mono wfvarsoccs\\<^sub>s\\<^sub>s\\<^sub>t_def)\n\nlemma wf\\<^sub>s\\<^sub>s\\<^sub>t_subst_apply:\n  \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V S \\<Longrightarrow> wf'\\<^sub>s\\<^sub>s\\<^sub>t (fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<delta> ` V)) (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)\"\nproof (induction S arbitrary: V rule: wf'\\<^sub>s\\<^sub>s\\<^sub>t.induct)\n  case (2 V t S)\n  hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V S\" \"fv t \\<subseteq> V\" by simp_all\n  hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<delta> ` V)) (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)\" \"fv (t \\<cdot> \\<delta>) \\<subseteq> fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<delta> ` V)\"\n    using \"2.IH\" subst_apply_fv_subset by simp_all\n  thus ?case by (simp add: subst_apply_stateful_strand_def)\nnext\n  case (3 V t S)\n  hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> fv t) S\" by simp\n  hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<delta> ` (V \\<union> fv t))) (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)\" using \"3.IH\" by metis\n  hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<delta> ` V) \\<union> fv (t \\<cdot> \\<delta>)) (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)\" by (metis subst_apply_fv_union)\n  thus ?case by (simp add: subst_apply_stateful_strand_def)\nnext\n  case (4 V t t' S)\n  hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> fv t) S\" \"fv t' \\<subseteq> V\" by auto\n  hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<delta> ` (V \\<union> fv t))) (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)\" and *: \"fv (t' \\<cdot> \\<delta>) \\<subseteq> fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<delta> ` V)\"\n    using \"4.IH\" subst_apply_fv_subset by force+\n  hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<delta> ` V) \\<union> fv (t \\<cdot> \\<delta>)) (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)\" by (metis subst_apply_fv_union)\n  thus ?case using * by (simp add: subst_apply_stateful_strand_def)\nnext\n  case (6 V t t' S)\n  hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t V S\" \"fv t \\<union> fv t' \\<subseteq> V\" by auto\n  hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<delta> ` V)) (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)\" \"fv (t \\<cdot> \\<delta>) \\<subseteq> fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<delta> ` V)\" \"fv (t' \\<cdot> \\<delta>) \\<subseteq> fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<delta> ` V)\"\n    using \"6.IH\" subst_apply_fv_subset by force+\n  thus ?case by (simp add: sup_assoc subst_apply_stateful_strand_def)\nnext\n  case (8 V t t' S)\n  hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (V \\<union> fv t \\<union> fv t') S\" by auto\n  hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<delta> ` (V \\<union> fv t \\<union> fv t'))) (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)\"\n    using \"8.IH\" subst_apply_fv_subset by force\n  hence \"wf'\\<^sub>s\\<^sub>s\\<^sub>t (fv\\<^sub>s\\<^sub>e\\<^sub>t (\\<delta> ` V) \\<union> fv (t \\<cdot> \\<delta>) \\<union> fv (t' \\<cdot> \\<delta>)) (S \\<cdot>\\<^sub>s\\<^sub>s\\<^sub>t \\<delta>)\" by (metis subst_apply_fv_union)\n  thus ?case by (simp add: subst_apply_stateful_strand_def)\nqed (auto simp add: subst_apply_stateful_strand_def)\n\nend\n", "meta": {"author": "logicalhacking", "repo": "Stateful_Protocol_Composition_and_Typing", "sha": "34755583e50bc8a2e3eb0f91350c0b8510422a16", "save_path": "github-repos/isabelle/logicalhacking-Stateful_Protocol_Composition_and_Typing", "path": "github-repos/isabelle/logicalhacking-Stateful_Protocol_Composition_and_Typing/Stateful_Protocol_Composition_and_Typing-34755583e50bc8a2e3eb0f91350c0b8510422a16/Stateful_Protocol_Composition_and_Typing/Stateful_Strands.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.4532618480153861, "lm_q1q2_score": 0.2513203076179137}}
{"text": "theory No_Alias\n  imports Simpl.Vcg \"Rust-Verification.Rust_Semantics\"\nbegin\n\nrecord no_alias_env = globals_ram +\n  x :: tagged_ref (* locals are represented by owning reference *)\n  ref1 :: tagged_ref\n  ref2 :: tagged_ref\n\ndefinition no_alias_body :: \"(no_alias_env, 'p, rust_error) com\" where\n  \"no_alias_body ==\n    Basic (\\<lambda>s. (let (r, s') = heap_new (int_val 100) s in s'\\<lparr> x := r \\<rparr>));;\n\n    reborrow_stmt Unique x (\\<lambda>s r. s\\<lparr> ref1 := r \\<rparr>);;\n    write_imm ref1 (int_val 200);;\n\n    reborrow_stmt Unique x (\\<lambda>s r. s\\<lparr> ref2 := r \\<rparr>);;\n    write_imm ref2 (int_val 300)\"\n\n(* Termination *)\nlemma \"\\<Gamma> \\<turnstile>\\<^sub>t {s. wf_heap s} no_alias_body {s. True}\"\n  unfolding no_alias_body_def\n  apply vcg_step\n       prefer 2\n       apply vcg_step\n       apply vcg_step\n      apply vcg_step\n     apply vcg_step\n      prefer 2\n      apply vcg_step\n      apply vcg_step\n     apply vcg_step\n    apply vcg_step\n     prefer 2\n     apply vcg_step\n     apply vcg_step\n    apply vcg_step\n   apply vcg_step\n    prefer 2\n    apply vcg_step\n    apply vcg_step\n   apply vcg_step\n  apply vcg_step\n  apply vcg_step\n  by (simp add: Let_def)\n\n(* Termination, by full VCG *)\nlemma \"\\<Gamma> \\<turnstile>\\<^sub>t {s. wf_heap s} no_alias_body {s. True}\"\n  unfolding no_alias_body_def\n  apply vcg\n  by (auto simp: Let_def)\n\n(* Spec of the program *)\nlemma \"\\<Gamma> \\<turnstile>\\<^sub>t\n  {s. wf_heap s}\n  no_alias_body\n  {s. (let p = the_ptr (pointer (x s)) in\n      memory s ! p = int_val 300) \\<and>\n      writable (x s) s \\<and> \\<not>writable (ref1 s) s \\<and> writable (ref2 s) s}\"\n  unfolding no_alias_body_def\n  apply vcg\n  (* This auto takes too long because of the term size *)\n  by (auto simp: Let_def)\n\nend", "meta": {"author": "pandaman64", "repo": "sabi", "sha": "a5de6b33cb0e5b9e6f0e610de0a3536236d1a694", "save_path": "github-repos/isabelle/pandaman64-sabi", "path": "github-repos/isabelle/pandaman64-sabi/sabi-a5de6b33cb0e5b9e6f0e610de0a3536236d1a694/Rustv/Tests/ex/No_Alias.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5544704649604273, "lm_q2_score": 0.4532618480153861, "lm_q1q2_score": 0.2513203076179137}}
{"text": "theory utp_fault_designs\nimports   \"../utp/utp\" utp_designs\nbegin\nsubsection {*Sequential C-program alphabet*}\n\ntext {*In order to record the interaction of a sequential C program with its execution environment, \n       we extend the alphabet of UTP by two additional global state variables:\n      \\begin{itemize}   \n       \\<^item> fault: a variable of type @{typ \"'f option\"} used to record a fault of a given guard is \n         not satisfied.\n       \\<^item> abrupt: a boolean variable used to\n     \\end{itemize}\n\n*}\n\nalphabet 'f cp_vars = des_vars +\n  abrupt:: bool\n  fault :: bool\n  stuck :: bool\n  fault_tr :: \"'f option\"\n  \n  (*wait :: bool*)\n\ndeclare cp_vars.splits [alpha_splits]\n\nsubsubsection {*Alphabet proofs*}\ntext {*\n  The two locale interpretations below are a technicality to improve automatic\n  proof support via the predicate and relational tactics. This is to enable the\n  (re-)interpretation of state spaces to remove any occurrences of lens types\n  after the proof tactics @{method pred_simp} and @{method rel_simp}, or any\n  of their derivatives have been applied. Eventually, it would be desirable to\n  automate both interpretations as part of a custom outer command for defining\n  alphabets.\n*}\n\ninterpretation cp_vars:\n  lens_interp \"\\<lambda> (ok, r) . (ok, abrupt\\<^sub>v r, fault\\<^sub>v r, fault_tr\\<^sub>v r, stuck\\<^sub>v r, more r)\"\napply (unfold_locales)\napply (rule injI)\napply (clarsimp)\ndone\n\ninterpretation cp_vars_rel: lens_interp \"\\<lambda>(ok, ok', r, r').\n  (ok, ok', abrupt\\<^sub>v r, abrupt\\<^sub>v r', fault\\<^sub>v r, fault\\<^sub>v r', fault_tr\\<^sub>v r, fault_tr\\<^sub>v r', stuck\\<^sub>v r, \n   stuck\\<^sub>v r',more r, more r')\"\napply (unfold_locales)\napply (rule injI)\napply (clarsimp)\ndone\n\n\nsubsubsection {*Type lifting*}\n\ntype_synonym ('f, '\\<alpha>) cp = \"('f, '\\<alpha>) cp_vars_scheme des\"\ntype_synonym ('f,'\\<alpha>,'\\<beta>) rel_cp  = \"(('f,'\\<alpha>) cp, ('f,'\\<beta>) cp) rel\"\ntype_synonym ('f,'\\<alpha>) hrel_cp  = \"(('f,'\\<alpha>) cp) hrel\"\n\nsubsubsection {*Syntactic type setup*}\n\ntranslations\n  (type) \"('f,'\\<alpha>) cp\" <= (type) \"('f, '\\<alpha>) cp_vars_scheme des\"\n  (type) \"('f,'\\<alpha>) cp\" <= (type) \"('f, '\\<alpha>) cp_vars_ext des\"\n  (type) \"('f,'\\<alpha>,'\\<beta>) rel_cp\" <= (type) \"(('f,'\\<alpha>) cp, (_,'\\<beta>) cp) rel\"\n\nnotation cp_vars_child_lens\\<^sub>a (\"\\<Sigma>\\<^sub>c\")\nnotation cp_vars_child_lens (\"\\<Sigma>\\<^sub>C\")\n\nsyntax\n  \"_svid_st_alpha\"  :: \"svid\" (\"\\<Sigma>\\<^sub>C\")\n  \"_svid_st_a\"  :: \"svid\" (\"\\<Sigma>\\<^sub>c\")\ntranslations\n  \"_svid_st_alpha\" => \"CONST cp_vars_child_lens\"\n   \"_svid_st_a\" => \"CONST cp_vars_child_lens\\<^sub>a\"\n\nlemma cvars_ord [usubst]:\n  \"$ok \\<prec>\\<^sub>v $ok\\<acute>\" \"$abrupt \\<prec>\\<^sub>v $abrupt\\<acute>\" \"$fault \\<prec>\\<^sub>v $fault\\<acute>\" \"$fault_tr \\<prec>\\<^sub>v $fault_tr\\<acute>\" \"$stuck \\<prec>\\<^sub>v $stuck\\<acute>\" \n  \"$ok \\<prec>\\<^sub>v $abrupt\\<acute>\" \"$ok \\<prec>\\<^sub>v $abrupt\" \"$ok\\<acute> \\<prec>\\<^sub>v $abrupt\\<acute>\" \"$ok\\<acute> \\<prec>\\<^sub>v $abrupt\" \n  \"$ok \\<prec>\\<^sub>v $fault\\<acute>\" \"$ok \\<prec>\\<^sub>v $fault\" \"$ok\\<acute> \\<prec>\\<^sub>v $fault\\<acute>\" \"$ok\\<acute> \\<prec>\\<^sub>v $fault\"\n  \"$ok \\<prec>\\<^sub>v $fault_tr\\<acute>\" \"$ok \\<prec>\\<^sub>v $fault_tr\" \"$ok\\<acute> \\<prec>\\<^sub>v $fault_tr\\<acute>\" \"$ok\\<acute> \\<prec>\\<^sub>v $fault_tr\"\n  \"$ok \\<prec>\\<^sub>v $stuck\\<acute>\" \"$ok \\<prec>\\<^sub>v $stuck\" \"$ok\\<acute> \\<prec>\\<^sub>v $stuck\\<acute>\" \"$ok\\<acute> \\<prec>\\<^sub>v $stuck\"\n  \"$abrupt \\<prec>\\<^sub>v $fault\" \"$abrupt \\<prec>\\<^sub>v $fault\\<acute>\" \"$abrupt\\<acute> \\<prec>\\<^sub>v $fault\" \"$abrupt\\<acute> \\<prec>\\<^sub>v $fault\\<acute>\"\n  \"$abrupt \\<prec>\\<^sub>v $fault_tr\" \"$abrupt \\<prec>\\<^sub>v $fault_tr\\<acute>\" \"$abrupt\\<acute> \\<prec>\\<^sub>v $fault_tr\" \"$abrupt\\<acute> \\<prec>\\<^sub>v $fault_tr\\<acute>\"\n  \"$abrupt \\<prec>\\<^sub>v $stuck\\<acute>\" \"$abrupt \\<prec>\\<^sub>v $stuck\" \"$abrupt\\<acute> \\<prec>\\<^sub>v $stuck\\<acute>\" \"$abrupt\\<acute> \\<prec>\\<^sub>v $stuck\"  \n  \"$fault \\<prec>\\<^sub>v $stuck\\<acute>\" \"$fault \\<prec>\\<^sub>v $stuck\" \"$fault\\<acute> \\<prec>\\<^sub>v $stuck\\<acute>\" \"$fault\\<acute> \\<prec>\\<^sub>v $stuck\"\n  \"$fault_tr \\<prec>\\<^sub>v $stuck\\<acute>\" \"$fault_tr \\<prec>\\<^sub>v $stuck\" \"$fault_tr\\<acute> \\<prec>\\<^sub>v $stuck\\<acute>\" \"$fault_tr\\<acute> \\<prec>\\<^sub>v $stuck\"\n  by (simp_all add: var_name_ord_def)\n\nabbreviation abrupt_f::\"('f, '\\<alpha>, '\\<beta>) rel_cp \\<Rightarrow> ('f, '\\<alpha>, '\\<beta>) rel_cp\"\nwhere \"abrupt_f R \\<equiv> R\\<lbrakk>false/$abrupt\\<rbrakk>\"\n\nabbreviation abrupt_t::\"('f, '\\<alpha>, '\\<beta>) rel_cp \\<Rightarrow> ('f, '\\<alpha>, '\\<beta>) rel_cp\"\nwhere \"abrupt_t R \\<equiv> R\\<lbrakk>true/$abrupt\\<rbrakk>\"\n\nabbreviation fault_f::\"('f, '\\<alpha>, '\\<beta>) rel_cp \\<Rightarrow> ('f, '\\<alpha>, '\\<beta>) rel_cp\"\nwhere \"fault_f R \\<equiv> R\\<lbrakk>false/$fault\\<rbrakk>\"\n\nabbreviation fault_t::\"('f, '\\<alpha>, '\\<beta>) rel_cp \\<Rightarrow> ('f, '\\<alpha>, '\\<beta>) rel_cp\"\nwhere \"fault_t R \\<equiv> R\\<lbrakk>true/$fault\\<rbrakk>\"\n\nabbreviation stuck_f::\"('f, '\\<alpha>, '\\<beta>) rel_cp \\<Rightarrow> ('f, '\\<alpha>, '\\<beta>) rel_cp\"\nwhere \"stuck_f R \\<equiv> R\\<lbrakk>false/$stuck\\<rbrakk>\"\n\nabbreviation stuck_t::\"('f, '\\<alpha>, '\\<beta>) rel_cp \\<Rightarrow> ('f, '\\<alpha>, '\\<beta>) rel_cp\"\nwhere \"stuck_t R \\<equiv> R\\<lbrakk>true/$stuck\\<rbrakk>\"\n\nsyntax\n  \"_abrupt_f\"  :: \"logic \\<Rightarrow> logic\" (\"_\\<^sub>a\\<^sub>f\" [1000] 1000)\n  \"_abrupt_t\"  :: \"logic \\<Rightarrow> logic\" (\"_\\<^sub>a\\<^sub>t\" [1000] 1000)\n  \"_fault_f\"  :: \"logic \\<Rightarrow> logic\" (\"_\\<^sub>f\\<^sub>f\" [1000] 1000)\n  \"_fault_t\"  :: \"logic \\<Rightarrow> logic\" (\"_\\<^sub>f\\<^sub>t\" [1000] 1000)\n  \"_stuck_f\"  :: \"logic \\<Rightarrow> logic\" (\"_\\<^sub>s\\<^sub>f\" [1000] 1000)\n  \"_stuck_t\"  :: \"logic \\<Rightarrow> logic\" (\"_\\<^sub>s\\<^sub>t\" [1000] 1000)\n\ntranslations\n  \"P \\<^sub>a\\<^sub>f\" \\<rightleftharpoons> \"CONST usubst (CONST subst_upd CONST id (CONST ivar CONST abrupt) false) P\"\n  \"P \\<^sub>a\\<^sub>t\" \\<rightleftharpoons> \"CONST usubst (CONST subst_upd CONST id (CONST ivar CONST abrupt) true) P\"\n  \"P \\<^sub>f\\<^sub>f\" \\<rightleftharpoons> \"CONST usubst (CONST subst_upd CONST id (CONST ivar CONST fault) false) P\"\n  \"P \\<^sub>f\\<^sub>t\" \\<rightleftharpoons> \"CONST usubst (CONST subst_upd CONST id (CONST ivar CONST fault) true) P\"\n  \"P \\<^sub>s\\<^sub>f\" \\<rightleftharpoons> \"CONST usubst (CONST subst_upd CONST id (CONST ivar CONST stuck) false) P\"\n  \"P \\<^sub>s\\<^sub>t\" \\<rightleftharpoons> \"CONST usubst (CONST subst_upd CONST id (CONST ivar CONST stuck) true) P\"\n\nsubsection {*UTP-Relations lift and drop*}\n\nabbreviation lift_desr (\"\\<lceil>_\\<rceil>\\<^sub>C\")\nwhere \"\\<lceil>P\\<rceil>\\<^sub>C \\<equiv> P \\<oplus>\\<^sub>p (\\<Sigma>\\<^sub>C \\<times>\\<^sub>L \\<Sigma>\\<^sub>C)\"\n\nabbreviation lift_pre_desr (\"\\<lceil>_\\<rceil>\\<^sub>C\\<^sub><\")\nwhere \"\\<lceil>p\\<rceil>\\<^sub>C\\<^sub>< \\<equiv> \\<lceil>\\<lceil>p\\<rceil>\\<^sub><\\<rceil>\\<^sub>C\"\n\nabbreviation lift_post_desr (\"\\<lceil>_\\<rceil>\\<^sub>C\\<^sub>>\")\nwhere \"\\<lceil>p\\<rceil>\\<^sub>C\\<^sub>> \\<equiv> \\<lceil>\\<lceil>p\\<rceil>\\<^sub>>\\<rceil>\\<^sub>C\"\n\nabbreviation drop_desr (\"\\<lfloor>_\\<rfloor>\\<^sub>C\")\nwhere \"\\<lfloor>P\\<rfloor>\\<^sub>C \\<equiv> P \\<restriction>\\<^sub>p (\\<Sigma>\\<^sub>C \\<times>\\<^sub>L \\<Sigma>\\<^sub>C)\"\n\n\nsubsection {* Reactive lemmas *}\n\nlemma unrest_ok_lift_rea [unrest]:\n  \"$ok \\<sharp> \\<lceil>P\\<rceil>\\<^sub>C\" \"$ok\\<acute> \\<sharp> \\<lceil>P\\<rceil>\\<^sub>C\"\n  by (pred_auto)+\n\nlemma unrest_abrupt_lift_rea [unrest]:\n  \"$abrupt \\<sharp> \\<lceil>P\\<rceil>\\<^sub>C\" \"$abrupt\\<acute> \\<sharp> \\<lceil>P\\<rceil>\\<^sub>C\"\n  by (pred_auto)+\n\nlemma unrest_fault_lift_rea [unrest]:\n  \"$fault \\<sharp> \\<lceil>P\\<rceil>\\<^sub>C\" \"$fault\\<acute> \\<sharp> \\<lceil>P\\<rceil>\\<^sub>C\"\n  by (pred_auto)+\n\nlemma unrest_stuck_lift_rea [unrest]:\n  \"$stuck \\<sharp> \\<lceil>P\\<rceil>\\<^sub>C\" \"$stuck\\<acute> \\<sharp> \\<lceil>P\\<rceil>\\<^sub>C\"\n  by (pred_auto)+\n\nlemma seqr_abrupt_true [usubst]: \"(P ;; Q) \\<^sub>a\\<^sub>t = (P \\<^sub>a\\<^sub>t ;; Q)\"\n  by (rel_auto)\n\nlemma seqr_abrupt_false [usubst]: \"(P ;; Q) \\<^sub>a\\<^sub>f = (P \\<^sub>a\\<^sub>f ;; Q)\"\n  by (rel_auto)\n\nlemma seqr_fault_true [usubst]: \"(P ;; Q) \\<^sub>f\\<^sub>t = (P \\<^sub>f\\<^sub>t ;; Q)\"\n  by (rel_auto)\n\nlemma seqr_fault_false [usubst]: \"(P ;; Q) \\<^sub>f\\<^sub>f = (P \\<^sub>f\\<^sub>f ;; Q)\"\n  by (rel_auto)\n\nlemma seqr_stuck_true [usubst]: \"(P ;; Q) \\<^sub>s\\<^sub>t = (P \\<^sub>s\\<^sub>t ;; Q)\"\n  by (rel_auto)\n\nlemma seqr_stuck_false [usubst]: \"(P ;; Q) \\<^sub>s\\<^sub>f = (P \\<^sub>s\\<^sub>f ;; Q)\"\n  by (rel_auto)\n\nsubsection{*Healthiness conditions*}\n\ntext {*Programs in fault or abrupt or stuck state do not progress*}\ndefinition C3_def [upred_defs]: \n  \"C3(P) = (P \\<triangleleft> \\<not>$abrupt \\<and> \\<not>$fault \\<and> \\<not>$stuck \\<and> $fault_tr =\\<^sub>u \\<guillemotleft>None\\<guillemotright> \\<triangleright> II)\"\n\nsubsection{*Control flow statements*}\n\ntext{*We introduce the known control-flow statements for C. Our semantics is restricted\n      to @{const C3}. In other words It assumes:\n     \\begin{itemize}   \n       \\<^item>  an execution starting from initial stable state ie,@{term \"$ok\"},   \n       \\<^item>  terminates a final state ie,@{term \"$ok\\<acute>\"},\n       \\<^item>  the final state is a normal state ie,\n          @{term \"\\<not>$abrupt\"} and @{term \"$fault_tr =\\<^sub>u \\<guillemotleft>None\\<guillemotright>\"},\n     \\end{itemize}\n    Thus it capture Simpl semantics.\n    *}\n\nabbreviation\n \"Simpl P \\<equiv> C3(\\<lceil>true\\<rceil>\\<^sub>C \\<turnstile> (P))\"\n\ndefinition skip_c :: \"('f,'\\<alpha>) hrel_cp\" (\"SKIP\")\nwhere [urel_defs]:\n  \"SKIP = Simpl (\\<not>$abrupt\\<acute> \\<and> \\<not>$stuck\\<acute> \\<and> \\<not>$fault\\<acute> \\<and> $fault_tr\\<acute> =\\<^sub>u \\<guillemotleft>None\\<guillemotright> \\<and> \\<lceil>II\\<rceil>\\<^sub>C)\"\n\ndefinition stuck_c :: \"('f,'\\<alpha>) hrel_cp\" (\"STUCK\")\nwhere [urel_defs]: \"STUCK = C3($stuck\\<acute>)\"\n\ndefinition assigns_c :: \"'\\<alpha> usubst \\<Rightarrow> ('f,'\\<alpha>) hrel_cp\" (\"\\<langle>_\\<rangle>\\<^sub>C\")\nwhere [urel_defs]: \n  \"assigns_c \\<sigma> =  C3(\\<lceil>true\\<rceil>\\<^sub>C \\<turnstile> (\\<not>$abrupt\\<acute> \\<and> \\<not>$stuck\\<acute> \\<and> \\<not>$fault\\<acute> \\<and> $fault_tr\\<acute> =\\<^sub>u \\<guillemotleft>None\\<guillemotright> \\<and> \\<lceil>\\<langle>\\<sigma>\\<rangle>\\<^sub>a\\<rceil>\\<^sub>C))\"\n\nsubsection{*THROW*}\n\ndefinition throw_c :: \"('f,'\\<alpha>) hrel_cp\" (\"THROW\")\nwhere [urel_defs]: \n  \"THROW = Simpl ($abrupt\\<acute> \\<and> \\<not>$stuck\\<acute> \\<and> \\<not>$fault\\<acute> \\<and> $fault_tr\\<acute> =\\<^sub>u \\<guillemotleft>None\\<guillemotright> \\<and> \\<lceil>II\\<rceil>\\<^sub>C)\"\n\nsubsection{*Conditional*}\n\nabbreviation If_c :: \"'\\<alpha> cond \\<Rightarrow>('f,'\\<alpha>) hrel_cp \\<Rightarrow> ('f,'\\<alpha>) hrel_cp \\<Rightarrow> ('f,'\\<alpha>) hrel_cp\" (\"bif (_)/ then (_) else (_) eif\")where\n  \"If_c b P Q \\<equiv> (P \\<triangleleft> \\<lceil>b\\<rceil>\\<^sub>C\\<^sub>< \\<triangleright> Q)\"\n\nsubsection{*GUARD*}\n\nabbreviation guard_c :: \"'f \\<Rightarrow> '\\<alpha> cond \\<Rightarrow> ('f,'\\<alpha>) hrel_cp\" \nwhere \"guard_c f b \\<equiv>  \n      (bif b then SKIP else (\\<not>$abrupt\\<acute> \\<and> \\<not>$stuck\\<acute> \\<and> $fault\\<acute> \\<and> $fault_tr\\<acute> =\\<^sub>u \\<guillemotleft>Some f\\<guillemotright> \\<and> \\<lceil>II\\<rceil>\\<^sub>C) eif)\"\n\nsubsection{*assert and assume*}\n\ndefinition rassume_c :: \"'\\<alpha> upred \\<Rightarrow> ('f,'\\<alpha>) hrel_cp\" (\"_\\<^sup>\\<top>\\<^sup>C\" [999] 999) where\n[urel_defs]: \"rassume_c c = (bif c then SKIP else \\<top>\\<^sub>D eif)\"\n\ndefinition rassert_c :: \"'\\<alpha> upred \\<Rightarrow> ('f,'\\<alpha>) hrel_cp\" (\"_\\<^sub>\\<bottom>\\<^sub>C\" [999] 999) where\n[urel_defs]: \"rassert_c c = (bif c then SKIP else \\<bottom>\\<^sub>D eif)\"\n\nsubsection{*Exceptions*}\n\nabbreviation catch_c :: \"('f,'\\<alpha>) hrel_cp \\<Rightarrow> ('f,'\\<alpha>) hrel_cp \\<Rightarrow> ('f,'\\<alpha>) hrel_cp\" (\"try (_) catch /(_) end\")\nwhere \"try P catch Q end \\<equiv> (P ;; ((abrupt:== (\\<not> &abrupt) ;;Q) \\<triangleleft> $abrupt \\<triangleright> II))\"\n\nsubsection{*Scoping*}\n\ndefinition block_c (\"bob INIT (_) BODY /(_) RESTORE /(_) RETURN/(_) eob\") where\n[urel_defs]:\n  \"bob INIT init BODY body RESTORE restore RETURN return eob= \n    (Abs_uexpr (\\<lambda>(s, s'). \n     \\<lbrakk>init ;; body ;; Abs_uexpr (\\<lambda>(t, t').\n                       \\<lbrakk>(abrupt:== (\\<not> &abrupt) ;;restore (s, s') (t, t');; THROW) \\<triangleleft> $abrupt \\<triangleright> II;; \n         restore (s, s') (t, t');; return(s, s') (t, t')\\<rbrakk>\\<^sub>e (t, t'))\\<rbrakk>\\<^sub>e (s, s')))\" \n\nsubsection{*Loops*}\npurge_notation while (\"while\\<^sup>\\<top> _ do _ od\")\n\ndefinition While :: \"'\\<alpha> cond \\<Rightarrow> ('f,'\\<alpha>) hrel_cp \\<Rightarrow> ('f,'\\<alpha>) hrel_cp\" (\"while\\<^sup>\\<top> _ do _ od\") where\n\"While b C = (\\<nu> X \\<bullet> bif b then (C ;; X) else SKIP eif)\"\n\npurge_notation while_top (\"while _ do _ od\")\n\nabbreviation While_top :: \"'\\<alpha> cond \\<Rightarrow> ('f,'\\<alpha>) hrel_cp \\<Rightarrow>  ('f,'\\<alpha>) hrel_cp\" (\"while _ do _ od\") where\n\"while b do P od \\<equiv> while\\<^sup>\\<top> b do P od\"\n\npurge_notation while_bot (\"while\\<^sub>\\<bottom> _ do _ od\")\n\ndefinition While_bot :: \"'\\<alpha> cond \\<Rightarrow> ('f,'\\<alpha>) hrel_cp \\<Rightarrow> ('f,'\\<alpha>) hrel_cp\" (\"while\\<^sub>\\<bottom> _ do _ od\") where\n\"while\\<^sub>\\<bottom> b do P od =  (\\<mu> X \\<bullet> bif b then (P ;; X) else SKIP eif)\"\n\nsubsection{*While-loop inv*}\ntext {* While loops with invariant decoration *}\n\npurge_notation while_inv (\"while _ invr _ do _ od\" 70)\n\ndefinition While_inv :: \"'\\<alpha> cond \\<Rightarrow> '\\<alpha> cond \\<Rightarrow> ('f,'\\<alpha>) hrel_cp \\<Rightarrow> ('f,'\\<alpha>) hrel_cp\" (\"while _ invr _ do _ od\" 70) where\n\"while b invr p do S od = while b do S od\"\n\ndeclare While_def [urel_defs]\ndeclare While_inv_def [urel_defs]\ndeclare While_bot_def [urel_defs]\n\n\nsyntax\n  \"_assignmentc\" :: \"svid_list \\<Rightarrow> uexprs \\<Rightarrow> logic\"  (infixr \"\\<Midarrow>\" 55)\n\ntranslations\n  \"_assignmentc xs vs\" => \"CONST assigns_c (_mk_usubst (CONST id) xs vs)\"\n  \"x \\<Midarrow> v\" <= \"CONST assigns_c (CONST subst_upd (CONST id) (CONST svar x) v)\"\n  \"x \\<Midarrow> v\" <= \"CONST assigns_c (CONST subst_upd (CONST id) x v)\"\n  \"x,y \\<Midarrow> u,v\" <= \"CONST assigns_c (CONST subst_upd (CONST subst_upd (CONST id) (CONST svar x) u) (CONST svar y) v)\"\n\nend", "meta": {"author": "git-vt", "repo": "orca", "sha": "92bda0f9cfe5cc680b9c405fc38f07a960087a36", "save_path": "github-repos/isabelle/git-vt-orca", "path": "github-repos/isabelle/git-vt-orca/orca-92bda0f9cfe5cc680b9c405fc38f07a960087a36/Archive/Programming-Languages-Semantics/WP11-C-semantics/src/orca/theories/utp_fault_designs.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.476579651063676, "lm_q1q2_score": 0.2513083247123449}}
{"text": "section \\<open>Equivalence of a Diamond-Shaped Relaying Network and a Cross-Shaped Broadcasting Network\\<close>\n\ntheory \"Network_Equivalences-Diamond-Relaying_Broadcasting\"\n  imports \"Network_Equivalences-Diamond-Foundations\"\nbegin\n\nabbreviation diamond_receiving_and_relaying where\n  \"diamond_receiving_and_relaying r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3 l\\<^sub>0\\<^sub>1 l\\<^sub>0\\<^sub>2 l\\<^sub>1\\<^sub>3 l\\<^sub>2\\<^sub>3 l\\<^sub>3\\<^sub>0 \\<equiv>\n    \\<comment> \\<open>Link 0--1:\\<close> l\\<^sub>0\\<^sub>1 \\<Rightarrow> [r\\<^sub>1, l\\<^sub>1\\<^sub>3] \\<parallel>\n    \\<comment> \\<open>Link 0--2:\\<close> l\\<^sub>0\\<^sub>2 \\<Rightarrow> [r\\<^sub>2, l\\<^sub>2\\<^sub>3] \\<parallel>\n    \\<comment> \\<open>Link 1--3:\\<close> l\\<^sub>1\\<^sub>3 \\<Rightarrow> [r\\<^sub>3, l\\<^sub>3\\<^sub>0] \\<parallel>\n    \\<comment> \\<open>Link 2--3:\\<close> l\\<^sub>2\\<^sub>3 \\<Rightarrow> [r\\<^sub>3, l\\<^sub>3\\<^sub>0] \\<parallel>\n    \\<comment> \\<open>Link 3--0:\\<close> l\\<^sub>3\\<^sub>0 \\<Rightarrow> [r\\<^sub>0, l\\<^sub>0\\<^sub>1, l\\<^sub>0\\<^sub>2]\"\n\nabbreviation diamond  where\n  \"diamond s\\<^sub>0 s\\<^sub>1 s\\<^sub>2 s\\<^sub>3 r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3 \\<equiv>\n    \\<nu> l\\<^sub>0\\<^sub>1 l\\<^sub>0\\<^sub>2 l\\<^sub>1\\<^sub>3 l\\<^sub>2\\<^sub>3 l\\<^sub>3\\<^sub>0. (\n      \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>1) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>2) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>1\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>2\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      diamond_sending s\\<^sub>0 s\\<^sub>1 s\\<^sub>2 s\\<^sub>3 (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      diamond_receiving_and_relaying r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3 (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0)\n    )\"\n\nabbreviation cross where\n  \"cross s\\<^sub>0 s\\<^sub>1 s\\<^sub>2 s\\<^sub>3 r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3 \\<equiv>\n    \\<nu> m. (\n      \\<currency>\\<^sup>* (\\<box> m) \\<parallel>\n      cross_sending s\\<^sub>0 s\\<^sub>1 s\\<^sub>2 s\\<^sub>3 (\\<box> m) \\<parallel>\n      cross_receiving r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3 (\\<box> m)\n    )\"\n\nlemma untangling:\n  shows \"\n    \\<currency>\\<^sup>?r\\<^sub>0 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>1 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>2 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>3 \\<parallel>\n    \\<currency>\\<^sup>*l\\<^sub>0\\<^sub>1 \\<parallel> \\<currency>\\<^sup>*l\\<^sub>0\\<^sub>2 \\<parallel> \\<currency>\\<^sup>*l\\<^sub>1\\<^sub>3 \\<parallel> \\<currency>\\<^sup>*l\\<^sub>2\\<^sub>3 \\<parallel> \\<currency>\\<^sup>*l\\<^sub>3\\<^sub>0 \\<parallel>\n    diamond_receiving_and_relaying r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3 l\\<^sub>0\\<^sub>1 l\\<^sub>0\\<^sub>2 l\\<^sub>1\\<^sub>3 l\\<^sub>2\\<^sub>3 l\\<^sub>3\\<^sub>0\n    \\<approx>\\<^sub>s\n    \\<currency>\\<^sup>?r\\<^sub>0 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>1 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>2 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>3 \\<parallel>\n    \\<currency>\\<^sup>*l\\<^sub>0\\<^sub>1 \\<parallel> \\<currency>\\<^sup>*l\\<^sub>0\\<^sub>2 \\<parallel> \\<currency>\\<^sup>*l\\<^sub>1\\<^sub>3 \\<parallel> \\<currency>\\<^sup>*l\\<^sub>2\\<^sub>3 \\<parallel> \\<currency>\\<^sup>*l\\<^sub>3\\<^sub>0 \\<parallel>\n    diamond_receiving r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3 l\\<^sub>0\\<^sub>1 l\\<^sub>0\\<^sub>2 l\\<^sub>1\\<^sub>3 l\\<^sub>2\\<^sub>3 l\\<^sub>3\\<^sub>0 \\<parallel>\n    initial_core l\\<^sub>0\\<^sub>1 l\\<^sub>0\\<^sub>2 l\\<^sub>1\\<^sub>3 l\\<^sub>2\\<^sub>3 l\\<^sub>3\\<^sub>0\"\n    (is \"?p \\<approx>\\<^sub>s ?q\")\nproof -\n  have \"?p \\<approx>\\<^sub>s\n    \\<comment> \\<open>Link 0--1:\\<close> (\\<currency>\\<^sup>+l\\<^sub>0\\<^sub>1 \\<parallel> \\<Prod>a\\<leftarrow>[r\\<^sub>1, l\\<^sub>1\\<^sub>3]. \\<currency>\\<^sup>?a \\<parallel> l\\<^sub>0\\<^sub>1 \\<Rightarrow> [r\\<^sub>1, l\\<^sub>1\\<^sub>3]) \\<parallel>\n    \\<comment> \\<open>Link 0--2:\\<close> (\\<currency>\\<^sup>+l\\<^sub>0\\<^sub>2 \\<parallel> \\<Prod>a\\<leftarrow>[r\\<^sub>2, l\\<^sub>2\\<^sub>3]. \\<currency>\\<^sup>?a \\<parallel> l\\<^sub>0\\<^sub>2 \\<Rightarrow> [r\\<^sub>2, l\\<^sub>2\\<^sub>3]) \\<parallel>\n    \\<comment> \\<open>Link 1--3:\\<close> (\\<currency>\\<^sup>+l\\<^sub>1\\<^sub>3 \\<parallel> \\<Prod>a\\<leftarrow>[r\\<^sub>3, l\\<^sub>3\\<^sub>0]. \\<currency>\\<^sup>?a \\<parallel> l\\<^sub>1\\<^sub>3 \\<Rightarrow> [r\\<^sub>3, l\\<^sub>3\\<^sub>0]) \\<parallel>\n    \\<comment> \\<open>Link 2--3:\\<close> (\\<currency>\\<^sup>+l\\<^sub>2\\<^sub>3 \\<parallel> \\<Prod>a\\<leftarrow>[r\\<^sub>3, l\\<^sub>3\\<^sub>0]. \\<currency>\\<^sup>?a \\<parallel> l\\<^sub>2\\<^sub>3 \\<Rightarrow> [r\\<^sub>3, l\\<^sub>3\\<^sub>0]) \\<parallel>\n    \\<comment> \\<open>Link 3--0:\\<close> (\\<currency>\\<^sup>+l\\<^sub>3\\<^sub>0 \\<parallel> \\<Prod>a\\<leftarrow>[r\\<^sub>0, l\\<^sub>0\\<^sub>1, l\\<^sub>0\\<^sub>2]. \\<currency>\\<^sup>?a \\<parallel> l\\<^sub>3\\<^sub>0 \\<Rightarrow> [r\\<^sub>0, l\\<^sub>0\\<^sub>1, l\\<^sub>0\\<^sub>2])\"\n    unfolding duploss_def and general_parallel.simps using thorn_simps by equivalence\n  also have \"\\<dots> \\<approx>\\<^sub>s\n    \\<comment> \\<open>Link 0--1:\\<close> (\\<currency>\\<^sup>+l\\<^sub>0\\<^sub>1 \\<parallel> \\<Prod>a\\<leftarrow>[r\\<^sub>1, l\\<^sub>1\\<^sub>3]. \\<currency>\\<^sup>?a \\<parallel> \\<Prod>a\\<leftarrow>[r\\<^sub>1, l\\<^sub>1\\<^sub>3]. l\\<^sub>0\\<^sub>1 \\<rightarrow> a) \\<parallel>\n    \\<comment> \\<open>Link 0--2:\\<close> (\\<currency>\\<^sup>+l\\<^sub>0\\<^sub>2 \\<parallel> \\<Prod>a\\<leftarrow>[r\\<^sub>2, l\\<^sub>2\\<^sub>3]. \\<currency>\\<^sup>?a \\<parallel> \\<Prod>a\\<leftarrow>[r\\<^sub>2, l\\<^sub>2\\<^sub>3]. l\\<^sub>0\\<^sub>2 \\<rightarrow> a) \\<parallel>\n    \\<comment> \\<open>Link 1--3:\\<close> (\\<currency>\\<^sup>+l\\<^sub>1\\<^sub>3 \\<parallel> \\<Prod>a\\<leftarrow>[r\\<^sub>3, l\\<^sub>3\\<^sub>0]. \\<currency>\\<^sup>?a \\<parallel> \\<Prod>a\\<leftarrow>[r\\<^sub>3, l\\<^sub>3\\<^sub>0]. l\\<^sub>1\\<^sub>3 \\<rightarrow> a) \\<parallel>\n    \\<comment> \\<open>Link 2--3:\\<close> (\\<currency>\\<^sup>+l\\<^sub>2\\<^sub>3 \\<parallel> \\<Prod>a\\<leftarrow>[r\\<^sub>3, l\\<^sub>3\\<^sub>0]. \\<currency>\\<^sup>?a \\<parallel> \\<Prod>a\\<leftarrow>[r\\<^sub>3, l\\<^sub>3\\<^sub>0]. l\\<^sub>2\\<^sub>3 \\<rightarrow> a) \\<parallel>\n    \\<comment> \\<open>Link 3--0:\\<close> (\\<currency>\\<^sup>+l\\<^sub>3\\<^sub>0 \\<parallel> \\<Prod>a\\<leftarrow>[r\\<^sub>0, l\\<^sub>0\\<^sub>1, l\\<^sub>0\\<^sub>2]. \\<currency>\\<^sup>?a \\<parallel> \\<Prod>a\\<leftarrow>[r\\<^sub>0, l\\<^sub>0\\<^sub>1, l\\<^sub>0\\<^sub>2]. l\\<^sub>3\\<^sub>0 \\<rightarrow> a)\"\n    using distributor_split by equivalence\n  also have \"\\<dots> \\<approx>\\<^sub>s ?q\"\n    unfolding duploss_def and general_parallel.simps using thorn_simps by equivalence\n  finally show ?thesis .\nqed\n\ntheorem diamond_cross_equivalence:\n  shows \"\n    \\<currency>\\<^sup>?r\\<^sub>0 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>1 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>2 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>3 \\<parallel>\n    diamond s\\<^sub>0 s\\<^sub>1 s\\<^sub>2 s\\<^sub>3 r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3\n    \\<approx>\\<^sub>s\n    \\<currency>\\<^sup>?r\\<^sub>0 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>1 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>2 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>3 \\<parallel>\n    cross s\\<^sub>0 s\\<^sub>1 s\\<^sub>2 s\\<^sub>3 r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3\"\nproof -\n  have \"\n    \\<currency>\\<^sup>?r\\<^sub>0 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>1 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>2 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>3 \\<parallel>\n    \\<langle>0\\<rangle> \\<nu> l\\<^sub>0\\<^sub>1. \\<langle>1\\<rangle> \\<nu> l\\<^sub>0\\<^sub>2. \\<langle>2\\<rangle> \\<nu> l\\<^sub>1\\<^sub>3. \\<langle>3\\<rangle> \\<nu> l\\<^sub>2\\<^sub>3. \\<langle>4\\<rangle> \\<nu> l\\<^sub>3\\<^sub>0. (\n      \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>1) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>2) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>1\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>2\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      diamond_sending s\\<^sub>0 s\\<^sub>1 s\\<^sub>2 s\\<^sub>3 (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      diamond_receiving_and_relaying r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3 (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0)\n    )\n    \\<approx>\\<^sub>s\n    \\<langle>0\\<rangle> \\<nu> l\\<^sub>0\\<^sub>1. \\<langle>1\\<rangle> \\<nu> l\\<^sub>0\\<^sub>2. \\<langle>2\\<rangle> \\<nu> l\\<^sub>1\\<^sub>3. \\<langle>3\\<rangle> \\<nu> l\\<^sub>2\\<^sub>3. \\<langle>4\\<rangle> \\<nu> l\\<^sub>3\\<^sub>0. (\n      diamond_sending s\\<^sub>0 s\\<^sub>1 s\\<^sub>2 s\\<^sub>3 (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      (\n        \\<currency>\\<^sup>?r\\<^sub>0 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>1 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>2 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>3 \\<parallel>\n      \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>1) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>2) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>1\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>2\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n        diamond_receiving_and_relaying r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3 (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0)\n      )\n    )\"\n    using thorn_simps sorry\n    (* FIXME:\n      This goal started to cause problems with the switch to the Þ-calculus. We hope that the\n      \\<^theory_text>\\<open>iprover\\<close>-based equivalence reasoner will be able to solve it.\n    *)\n  also have \"\\<dots> \\<approx>\\<^sub>s\n    \\<langle>0\\<rangle> \\<nu> l\\<^sub>0\\<^sub>1. \\<langle>1\\<rangle> \\<nu> l\\<^sub>0\\<^sub>2. \\<langle>2\\<rangle> \\<nu> l\\<^sub>1\\<^sub>3. \\<langle>3\\<rangle> \\<nu> l\\<^sub>2\\<^sub>3. \\<langle>4\\<rangle> \\<nu> l\\<^sub>3\\<^sub>0. (\n      diamond_sending s\\<^sub>0 s\\<^sub>1 s\\<^sub>2 s\\<^sub>3 (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      (\n        \\<currency>\\<^sup>?r\\<^sub>0 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>1 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>2 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>3 \\<parallel>\n        \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>1) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>2) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>1\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>2\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n        diamond_receiving r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3 (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n        initial_core (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0)\n      )\n    )\"\n    using untangling sorry\n    (* FIXME:\n      This goal started to cause problems with the switch to the Þ-calculus. We hope that the\n      \\<^theory_text>\\<open>iprover\\<close>-based equivalence reasoner will be able to solve it.\n    *)\n  also have \"\\<dots> \\<approx>\\<^sub>s\n    \\<currency>\\<^sup>?r\\<^sub>0 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>1 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>2 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>3 \\<parallel>\n    \\<langle>0\\<rangle> \\<nu> l\\<^sub>0\\<^sub>1. \\<langle>1\\<rangle> \\<nu> l\\<^sub>0\\<^sub>2. \\<langle>2\\<rangle> \\<nu> l\\<^sub>1\\<^sub>3. \\<langle>3\\<rangle> \\<nu> l\\<^sub>2\\<^sub>3. \\<langle>4\\<rangle> \\<nu> l\\<^sub>3\\<^sub>0. (\n      \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>1) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>2) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>1\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>2\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      diamond_sending s\\<^sub>0 s\\<^sub>1 s\\<^sub>2 s\\<^sub>3 (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      diamond_receiving r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3 (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      initial_core (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0)\n    )\"\n    using thorn_simps sorry\n    (* FIXME:\n      This goal started to cause problems with the switch to the Þ-calculus. We hope that the\n      \\<^theory_text>\\<open>iprover\\<close>-based equivalence reasoner will be able to solve it.\n    *)\n  also have \"\\<dots> \\<approx>\\<^sub>s\n    \\<currency>\\<^sup>?r\\<^sub>0 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>1 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>2 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>3 \\<parallel>\n    \\<langle>0\\<rangle> \\<nu> l\\<^sub>0\\<^sub>1. \\<langle>1\\<rangle> \\<nu> l\\<^sub>0\\<^sub>2. \\<langle>2\\<rangle> \\<nu> l\\<^sub>1\\<^sub>3. \\<langle>3\\<rangle> \\<nu> l\\<^sub>2\\<^sub>3. \\<langle>4\\<rangle> \\<nu> l\\<^sub>3\\<^sub>0. (\n      \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>1) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>2) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>1\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>2\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      diamond_sending s\\<^sub>0 s\\<^sub>1 s\\<^sub>2 s\\<^sub>3 (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      diamond_receiving r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3 (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      transformed_core (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0)\n    )\"\n    using core_transformation sorry\n    (* FIXME:\n      This goal started to cause problems with the switch to the Þ-calculus. We hope that the\n      \\<^theory_text>\\<open>iprover\\<close>-based equivalence reasoner will be able to solve it.\n    *)\n  also have \"\\<dots> \\<approx>\\<^sub>s\n    \\<currency>\\<^sup>?r\\<^sub>0 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>1 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>2 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>3 \\<parallel>\n    \\<langle>0\\<rangle> \\<nu> l\\<^sub>0\\<^sub>1. \\<langle>1\\<rangle> \\<nu> l\\<^sub>0\\<^sub>2. \\<langle>2\\<rangle> \\<nu> l\\<^sub>1\\<^sub>3. \\<langle>3\\<rangle> \\<nu> l\\<^sub>2\\<^sub>3. \\<langle>4\\<rangle> \\<nu> l\\<^sub>3\\<^sub>0. (\n      \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>1) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>2) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>1\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>2\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      diamond_sending s\\<^sub>0 s\\<^sub>1 s\\<^sub>2 s\\<^sub>3 (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      (\n        transformed_core (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n        diamond_receiving r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3 (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0)\n      )\n    )\"\n    using thorn_simps sorry\n    (* FIXME:\n      This goal started to cause problems with the switch to the Þ-calculus. We hope that the\n      \\<^theory_text>\\<open>iprover\\<close>-based equivalence reasoner will be able to solve it.\n    *)\n  also have \"\\<dots> \\<approx>\\<^sub>s\n    \\<currency>\\<^sup>?r\\<^sub>0 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>1 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>2 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>3 \\<parallel>\n    \\<langle>0\\<rangle> \\<nu> l\\<^sub>0\\<^sub>1. \\<langle>1\\<rangle> \\<nu> l\\<^sub>0\\<^sub>2. \\<langle>2\\<rangle> \\<nu> l\\<^sub>1\\<^sub>3. \\<langle>3\\<rangle> \\<nu> l\\<^sub>2\\<^sub>3. \\<langle>4\\<rangle> \\<nu> l\\<^sub>3\\<^sub>0. (\n      \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>1) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>2) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>1\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>2\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      diamond_sending s\\<^sub>0 s\\<^sub>1 s\\<^sub>2 s\\<^sub>3 (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      (\n        transformed_core (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n        cross_receiving r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3 (\\<box> l\\<^sub>3\\<^sub>0)\n      )\n    )\"\n    using receiving_collapse sorry\n    (* FIXME:\n      This goal started to cause problems with the switch to the Þ-calculus. We hope that the\n      \\<^theory_text>\\<open>iprover\\<close>-based equivalence reasoner will be able to solve it.\n    *)\n  also have \"\\<dots> \\<approx>\\<^sub>s\n    \\<currency>\\<^sup>?r\\<^sub>0 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>1 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>2 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>3 \\<parallel>\n    \\<langle>0\\<rangle> \\<nu> l\\<^sub>0\\<^sub>1. \\<langle>1\\<rangle> \\<nu> l\\<^sub>0\\<^sub>2. \\<langle>2\\<rangle> \\<nu> l\\<^sub>1\\<^sub>3. \\<langle>3\\<rangle> \\<nu> l\\<^sub>2\\<^sub>3. \\<langle>4\\<rangle> \\<nu> l\\<^sub>3\\<^sub>0. (\n      \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>1) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>2) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>1\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>2\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      cross_receiving r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3 (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      (\n        \\<currency>\\<^sup>* (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n        transformed_core (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n        diamond_sending s\\<^sub>0 s\\<^sub>1 s\\<^sub>2 s\\<^sub>3 (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0)\n      )\n    )\"\n    using thorn_simps sorry\n    (* FIXME:\n      This goal started to cause problems with the switch to the Þ-calculus. We hope that the\n      \\<^theory_text>\\<open>iprover\\<close>-based equivalence reasoner will be able to solve it.\n    *)\n  also have \"\\<dots> \\<approx>\\<^sub>s\n    \\<currency>\\<^sup>?r\\<^sub>0 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>1 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>2 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>3 \\<parallel>\n    \\<langle>0\\<rangle> \\<nu> l\\<^sub>0\\<^sub>1. \\<langle>1\\<rangle> \\<nu> l\\<^sub>0\\<^sub>2. \\<langle>2\\<rangle> \\<nu> l\\<^sub>1\\<^sub>3. \\<langle>3\\<rangle> \\<nu> l\\<^sub>2\\<^sub>3. \\<langle>4\\<rangle> \\<nu> l\\<^sub>3\\<^sub>0. (\n      \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>1) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>2) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>1\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>2\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      cross_receiving r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3 (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      (\n        \\<currency>\\<^sup>* (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n        transformed_core (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n        cross_sending s\\<^sub>0 s\\<^sub>1 s\\<^sub>2 s\\<^sub>3 (\\<box> l\\<^sub>3\\<^sub>0)\n      )\n    )\"\n    using sending_collapse sorry\n    (* FIXME:\n      This goal started to cause problems with the switch to the Þ-calculus. We hope that the\n      \\<^theory_text>\\<open>iprover\\<close>-based equivalence reasoner will be able to solve it.\n    *)\n  also have \"\\<dots> \\<approx>\\<^sub>s\n    \\<currency>\\<^sup>?r\\<^sub>0 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>1 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>2 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>3 \\<parallel>\n    \\<langle>4\\<rangle> \\<nu> l\\<^sub>3\\<^sub>0. (\n      cross_sending s\\<^sub>0 s\\<^sub>1 s\\<^sub>2 s\\<^sub>3 (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      cross_receiving r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3 (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      (\n        \\<currency>\\<^sup>* (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n        \\<langle>0\\<rangle> \\<nu> l\\<^sub>0\\<^sub>1. \\<langle>1\\<rangle> \\<nu> l\\<^sub>0\\<^sub>2. \\<langle>2\\<rangle> \\<nu> l\\<^sub>1\\<^sub>3. \\<langle>3\\<rangle> \\<nu> l\\<^sub>2\\<^sub>3. (\n          \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>1) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>0\\<^sub>2) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>1\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>2\\<^sub>3) \\<parallel> \\<currency>\\<^sup>* (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n          transformed_core (\\<box> l\\<^sub>0\\<^sub>1) (\\<box> l\\<^sub>0\\<^sub>2) (\\<box> l\\<^sub>1\\<^sub>3) (\\<box> l\\<^sub>2\\<^sub>3) (\\<box> l\\<^sub>3\\<^sub>0)\n        )\n      )\n    )\"\n    using thorn_simps sorry\n    (* FIXME:\n      This goal started to cause problems with the switch to the Þ-calculus. We hope that the\n      \\<^theory_text>\\<open>iprover\\<close>-based equivalence reasoner will be able to solve it.\n    *)\n  also have \"\\<dots> \\<approx>\\<^sub>s\n    \\<currency>\\<^sup>?r\\<^sub>0 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>1 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>2 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>3 \\<parallel>\n    \\<langle>4\\<rangle> \\<nu> l\\<^sub>3\\<^sub>0. (\n      cross_sending s\\<^sub>0 s\\<^sub>1 s\\<^sub>2 s\\<^sub>3 (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      cross_receiving r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3 (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      \\<currency>\\<^sup>* (\\<box> l\\<^sub>3\\<^sub>0)\n    )\"\n    unfolding tagged_new_channel_def using core_collapse sorry\n    (* FIXME:\n      This goal started to cause problems with the switch to the Þ-calculus. We hope that the\n      \\<^theory_text>\\<open>iprover\\<close>-based equivalence reasoner will be able to solve it.\n    *)\n  also have \"\\<dots> \\<approx>\\<^sub>s\n    \\<currency>\\<^sup>?r\\<^sub>0 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>1 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>2 \\<parallel> \\<currency>\\<^sup>?r\\<^sub>3 \\<parallel>\n    \\<langle>4\\<rangle> \\<nu> l\\<^sub>3\\<^sub>0. (\n      \\<currency>\\<^sup>* (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      cross_sending s\\<^sub>0 s\\<^sub>1 s\\<^sub>2 s\\<^sub>3 (\\<box> l\\<^sub>3\\<^sub>0) \\<parallel>\n      cross_receiving r\\<^sub>0 r\\<^sub>1 r\\<^sub>2 r\\<^sub>3 (\\<box> l\\<^sub>3\\<^sub>0)\n    )\"\n    using thorn_simps sorry\n    (* FIXME:\n      This goal started to cause problems with the switch to the Þ-calculus. We hope that the\n      \\<^theory_text>\\<open>iprover\\<close>-based equivalence reasoner will be able to solve it.\n    *)\n  finally show ?thesis unfolding tagged_new_channel_def .\nqed\n\nend\n", "meta": {"author": "input-output-hk", "repo": "network-equivalences", "sha": "dedffb052a31ded438928ca44a7ebb2475a792d7", "save_path": "github-repos/isabelle/input-output-hk-network-equivalences", "path": "github-repos/isabelle/input-output-hk-network-equivalences/network-equivalences-dedffb052a31ded438928ca44a7ebb2475a792d7/src/Network_Equivalences-Diamond-Relaying_Broadcasting.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5273165233795671, "lm_q2_score": 0.47657965106367595, "lm_q1q2_score": 0.2513083247123448}}
{"text": "\nsection \\<open>Intuitionistic first-order logic\\<close>\n\ntheory betterFOL\nimports Pure\nbegin\n\nML \\<open>\\<^assert> (not (can ML \\<open>open RunCall\\<close>))\\<close>\nML_file \\<open>~~/src/Tools/misc_legacy.ML\\<close>\nML_file \\<open>~~/src/Provers/splitter.ML\\<close>\nML_file \\<open>~~/src/Provers/hypsubst.ML\\<close>\nML_file \\<open>~~/src/Tools/IsaPlanner/zipper.ML\\<close>\nML_file \\<open>~~/src/Tools/IsaPlanner/isand.ML\\<close>\nML_file \\<open>~~/src/Tools/IsaPlanner/rw_inst.ML\\<close>\nML_file \\<open>~~/src/Provers/quantifier1.ML\\<close>\nML_file \\<open>~~/src/Tools/intuitionistic.ML\\<close>\nML_file \\<open>~~/src/Tools/project_rule.ML\\<close>\nML_file \\<open>~~/src/Tools/atomize_elim.ML\\<close>\n\n\nsubsection \\<open>Syntax and axiomatic basis\\<close>\n\nsetup Pure_Thy.old_appl_syntax_setup\n\nclass \"term\"\ndefault_sort \\<open>term\\<close>\n\ntypedecl o\n\njudgment\n  Trueprop :: \\<open>o \\<Rightarrow> prop\\<close>  (\\<open>(_)\\<close> 5)\n\n\nsubsubsection \\<open>Equality\\<close>\n\naxiomatization\n  eq :: \\<open>['a, 'a] \\<Rightarrow> o\\<close>  (infixl \\<open>=\\<close> 50)\nwhere\n  refl: \\<open>a = a\\<close> and\n  subst: \\<open>a = b \\<Longrightarrow> P(a) \\<Longrightarrow> P(b)\\<close>\n\n\nsubsubsection \\<open>Propositional logic\\<close>\n\naxiomatization\n  False :: \\<open>o\\<close> and\n  conj :: \\<open>[o, o] => o\\<close>  (infixr \\<open>\\<and>\\<close> 35) and\n  disj :: \\<open>[o, o] => o\\<close>  (infixr \\<open>\\<or>\\<close> 30) and\n  imp :: \\<open>[o, o] => o\\<close>  (infixr \\<open>\\<longrightarrow>\\<close> 25)\n\naxiomatization\nwhere\n  mp: \\<open>\\<lbrakk>P \\<longrightarrow> Q; P\\<rbrakk> \\<Longrightarrow> Q\\<close> and\n  a1: \\<open>A \\<longrightarrow> (B \\<longrightarrow> A)\\<close> and\n  a2: \\<open>(A \\<longrightarrow> (B \\<longrightarrow> C))\\<longrightarrow>((A \\<longrightarrow> B)\\<longrightarrow>(A \\<longrightarrow> C))\\<close>\n\ntheorem Ded: \\<open>(P \\<Longrightarrow> Q) \\<Longrightarrow> P \\<longrightarrow> Q\\<close>\n\n(*\n\n  conjI: \\<open>\\<lbrakk>P;  Q\\<rbrakk> \\<Longrightarrow> P \\<and> Q\\<close> and\n  conjunct1: \\<open>P \\<and> Q \\<Longrightarrow> P\\<close> and\n  conjunct2: \\<open>P \\<and> Q \\<Longrightarrow> Q\\<close> and\n\n  disjI1: \\<open>P \\<Longrightarrow> P \\<or> Q\\<close> and\n  disjI2: \\<open>Q \\<Longrightarrow> P \\<or> Q\\<close> and\n  disjE: \\<open>\\<lbrakk>P \\<or> Q; P \\<Longrightarrow> R; Q \\<Longrightarrow> R\\<rbrakk> \\<Longrightarrow> R\\<close> and\n\n  impI: \\<open>(P \\<Longrightarrow> Q) \\<Longrightarrow> P \\<longrightarrow> Q\\<close> and\n  mp: \\<open>\\<lbrakk>P \\<longrightarrow> Q; P\\<rbrakk> \\<Longrightarrow> Q\\<close> and\n\n  FalseE: \\<open>False \\<Longrightarrow> P\\<close>\n*)\n\n", "meta": {"author": "georgydunaev", "repo": "article_isabelle_in_zfc", "sha": "29480bab0a514a1d07a5259dd57fe41e48f3dbeb", "save_path": "github-repos/isabelle/georgydunaev-article_isabelle_in_zfc", "path": "github-repos/isabelle/georgydunaev-article_isabelle_in_zfc/article_isabelle_in_zfc-29480bab0a514a1d07a5259dd57fe41e48f3dbeb/betterFOL.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6224593452091672, "lm_q2_score": 0.4035668537353746, "lm_q1q2_score": 0.251203959524245}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\ntheory signedoverflow\nimports \"CParser.CTranslation\"\nbegin\n\nexternal_file \"signedoverflow.c\"\ninstall_C_file \"signedoverflow.c\"\n\ncontext signedoverflow\nbegin\n\nthm f_body_def\n\n(* painful lemma about sint and word arithmetic results...\nlemma j0: \"\\<Gamma> \\<turnstile> \\<lbrace> True \\<rbrace> Call f_'proc \\<lbrace> \\<acute>ret__int = 0 \\<rbrace>\"\napply vcg\napply simp_all\napply auto\n*)\n\nthm g_body_def\n\nlemma \"\\<Gamma> \\<turnstile> \\<lbrace> True \\<rbrace> \\<acute>ret__int :== CALL g(1) \\<lbrace> \\<acute>ret__int = - 1 \\<rbrace>\"\napply vcg\napply (simp add: word_sle_def)\ndone\n\nlemma \"\\<Gamma> \\<turnstile> \\<lbrace> True \\<rbrace> \\<acute>ret__int :== CALL g(- 2147483648) \\<lbrace> \\<acute>ret__int = - 1 \\<rbrace>\"\napply vcg\napply (simp add: word_sle_def)\ndone\n\nlemma \"\\<Gamma> \\<turnstile> \\<lbrace> True \\<rbrace> \\<acute>ret__int :== CALL g(- 2147483647) \\<lbrace> \\<acute>ret__int = 2147483647 \\<rbrace>\"\napply vcg\napply (simp add: word_sle_def)\ndone\n\nend (* context *)\n\nend (* theory *)\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/tools/c-parser/testfiles/signedoverflow.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5736784074525096, "lm_q2_score": 0.4378234991142019, "lm_q1q2_score": 0.2511698877171206}}
{"text": "theory MainHC\nimports Main\nbegin\n\n-- \"we need full proof object support to use translate_thm later on\"\nML {* proofs := 2 *}\n\ntypes 'a partial = \"'a option\"\n\n(* negation of is_none *)\nprimrec defOp :: \"'a partial => bool\"\nwhere\n\"defOp None = False\" |\n\"defOp (Some x) = True\"\n\ndefinition makeTotal :: \"'a partial => 'a\"\nwhere \"makeTotal == the\"\n\ndefinition makePartial :: \"'a => 'a partial\"\nwhere \"makePartial == Some\"\n\n(* undefined is predefined *)\ndefinition undefinedOp :: \"'a partial\"\nwhere \"undefinedOp == None\"\n\n(* backward compatibility only *)\ndefinition noneOp :: \"'a partial\"\nwhere \"noneOp == undefinedOp\"\n\ndefinition restrictOp :: \"'a partial => bool => 'a partial\"\nwhere \"restrictOp a b == if b then a else undefinedOp\"\n\n(* utilities *)\ndefinition flip :: \"('a => 'b => 'c) => 'b => 'a => 'c\"\nwhere \"flip f a b == f b a\"\n\ndefinition uncurryOp :: \"('a => 'b => 'c) => 'a * 'b => 'c\"\nwhere \"uncurryOp f p == f (fst p) (snd p)\"\n\ndefinition curryOp :: \"('a * 'b => 'c) => 'a => 'b => 'c\"\nwhere \"curryOp f a b == f (a, b)\"\n\n(* map on pairs *)\ndefinition mapFst :: \"('a => 'b) => 'a * 'c => 'b * 'c\"\nwhere \"mapFst f p == (f (fst p), snd p)\"\n\ndefinition mapSnd :: \"('b => 'c) => 'a * 'b => 'a * 'c\"\nwhere \"mapSnd f p == (fst p, f (snd p))\"\n\n(* predefined HasCASL functions *)\ndefinition ifImplOp :: \"bool * bool => bool\"\nwhere \"ifImplOp p == snd p --> fst p\"\n\ndefinition existEqualOp :: \"'a partial => 'a partial => bool\" \n  (\"(_ =e=/ _)\" [50, 51] 50)\nwhere \"existEqualOp a b == defOp a & defOp b & makeTotal a = makeTotal b\"\n\ndefinition exEqualOp :: \"'a partial * 'a partial => bool\"\nwhere \"exEqualOp == uncurryOp existEqualOp\"\n\ndefinition strongEqualOp :: \"'a partial => 'a partial => bool\"\n  (\"(_ =s=/ _)\" [50, 51] 50)\nwhere \"strongEqualOp a b == a = b\"\n\ndefinition whenElseOp :: \"('a partial * bool) * 'a partial => 'a partial\"\nwhere \"whenElseOp t == case t of\n    (p, e) => if snd p then fst p else e\"\n\n(*resOp :: \"'a partial * 'b partial => 'a\"\n\"resOp p == makeTotal (restrictOp (fst p) (defOp (snd p)))\"*)\n\ndefinition resOp :: \"'a partial * 'b partial => 'a partial\"\nwhere  \"resOp p == restrictOp (fst p) (defOp (snd p))\"\n\n\n(* conversions *)\ndefinition lift2partial :: \"('a => 'b partial) => 'a partial => 'b partial\"\nwhere \"lift2partial f s == restrictOp (f (makeTotal s)) (defOp s)\"\n\ndefinition mapPartial :: \"('a => 'b) => 'a partial => 'b partial\"\nwhere \"mapPartial f s == restrictOp (makePartial (f (makeTotal s))) (defOp s)\"\n\ndefinition unpackPartial :: \"(('a => 'b) => 'c => 'd partial)\n            => ('a => 'b) partial => 'c => 'd partial\"\nwhere \"unpackPartial c s a == lift2partial (flip c a) s\"\n\ndefinition unpackBool :: \"(('a => 'b) => 'c => bool)\n            => ('a => 'b) partial => 'c => bool\"\nwhere \"unpackBool c s a == defOp s & c (makeTotal s) a\"\n\ndefinition unpack2partial :: \"(('a => 'b) => 'c => 'd)\n            => ('a => 'b) partial => 'c => 'd partial\"\nwhere \"unpack2partial c s a == mapPartial (flip c a) s\"\n\ndefinition unpack2bool :: \"(('a => 'b) => 'c => 'd)\n            => ('a => 'b) partial => 'c => bool\"\nwhere \"unpack2bool c s a == defOp s\"\n\ndefinition bool2partial :: \"bool => unit partial\"\nwhere \"bool2partial b == restrictOp (makePartial ()) b\"\n\ndefinition liftUnit2unit :: \"('a => 'b) => bool => bool\"\nwhere \"liftUnit2unit f b == b\"\n\ndefinition liftUnit2bool :: \"(unit => bool) => bool => bool\"\nwhere \"liftUnit2bool f b == b & f ()\"\n\ndefinition liftUnit2partial :: \"(unit => 'a partial) => bool => 'a partial\"\nwhere \"liftUnit2partial f b == restrictOp (f ()) b\"\n\ndefinition liftUnit :: \"(unit => 'a) => bool => 'a partial\"\nwhere \"liftUnit f b ==restrictOp (makePartial (f ())) b\"\n\ndefinition lift2unit :: \"('b => 'c) => ('a partial => bool)\"\nwhere \"lift2unit f == defOp\"\n\ndefinition lift2bool :: \"('a => bool) => 'a partial => bool\"\nwhere \"lift2bool f s == defOp s & f (makeTotal s)\"\n\n(* old stuff *)\nprimrec app :: \"('a => 'b option) option => 'a option => 'b option\"\nwhere\n  \"app None a = None\" |\n  \"app (Some f) x = (case x of\n                            None => None\n                          | Some x' => f x')\"\n\nprimrec apt :: \"('a => 'b) option => 'a option => 'b option\"\nwhere\n  \"apt None a = None\" |\n  \"apt (Some f) x = (case x of\n                            None => None\n                          | Some x' => Some (f x'))\"\n\nprimrec pApp :: \"('a => bool) option => 'a option => bool\"\nwhere\n  \"pApp None a = False\" |\n  \"pApp (Some f) x = (case x of\n                             None => False\n                           | Some y => f y)\"\n\nprimrec pair :: \"'a option => 'b option => ('a * 'b) option\"\nwhere\n  \"pair None a = None\" |\n  \"pair (Some x) z = (case z of\n                             None => None\n                           | Some y => Some (x,y))\"\n\nlemma some_inj : \"Some x = Some y ==> x = y\"\napply (auto)\ndone\n\n(* Monad law added by Lutz Schroeder *)\n\nlemma partial_monad_unit1[simp]: \"lift2partial f (makePartial a) = f a\"\napply (simp add: lift2partial_def makePartial_def restrictOp_def makeTotal_def)\ndone\n\nlemma partial_monad_unit2[simp]: \"lift2partial makePartial m = m\"\napply (auto simp add: lift2partial_def makePartial_def restrictOp_def makeTotal_def undefinedOp_def)\napply (case_tac \"m\")\napply (auto)\napply (case_tac \"m\")\napply (auto)\ndone\n\nlemma partial_monad_assoc[simp]:\n  \"lift2partial g (lift2partial f m) =\n  lift2partial (%x. lift2partial g (f x)) m\"\napply (simp add: lift2partial_def makePartial_def restrictOp_def makeTotal_def undefinedOp_def)\ndone\n\nlemma strictness_closure:\n  \"defOp (lift2partial f a) = (defOp (lift2partial f a) & defOp a)\"\napply (simp add: lift2partial_def makePartial_def restrictOp_def makeTotal_def undefinedOp_def)\ndone\n\n(*\n   Identities added by Ewaryst Schulz\n*)\n(* \nlemma defOp_implies_makePartial:\n\"defOp(x :: 'a partial) ==> (EX (y :: 'a). x = makePartial y)\"\n-- \"for isabelle 2009\"\n  by (rule Option.option.exhaust [of x], simp, simp add: exI makePartial_def)\n-- \"for isabelle 2008\"\n by (rule Datatype.option.exhaust [of x], simp, simp add: exI makePartial_def)\n-- \"for both versions:\"\n  sorry\n*)\n\naxioms\n\ndefOp_implies_makePartial:\n\"defOp(x :: 'a partial) ==> (EX (y :: 'a). x = makePartial y)\"\n\n\n-- \"need this to expand a term for application of lemmas\"\nlemma partial_identity: \"!!x. makeTotal(makePartial(x)) = x\"\n  by (simp add: makeTotal_def makePartial_def)\n\nconsts preDefOp :: \"'a partial => bool\"\n\naxioms\n\npreDefOp_atom[simp]: \"preDefOp a = defOp a\"\n\npreDefOp_lift[simp]:\n\"preDefOp (lift2partial f a) = (defOp (lift2partial f a) & preDefOp a)\"\n\n\nend\n", "meta": {"author": "spechub", "repo": "Hets-lib", "sha": "7bed416952e7000e2fa37f0b6071b5291b299b77", "save_path": "github-repos/isabelle/spechub-Hets-lib", "path": "github-repos/isabelle/spechub-Hets-lib/Hets-lib-7bed416952e7000e2fa37f0b6071b5291b299b77/Isabelle/2008/MainHC.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5312093733737563, "lm_q2_score": 0.47268347662043286, "lm_q1q2_score": 0.2510938934196687}}
{"text": "section \\<open>Independence of IMAP Commands\\<close>\n\ntext\\<open>In this section we show that two concurrent operations that reference to the same tag must be \nidentical.\\<close>\n\ntheory\n  \"IMAP-proof-independent\"\n  imports\n    \"IMAP-def\"\n    \"IMAP-proof-helpers\"  \nbegin\n\nlemma (in imap) Broadcast_Expunge_Deliver_prefix_closed:\n  assumes \"xs @ [Broadcast (i, Expunge e mo i)] prefix of j\"\n  shows \"Deliver (mo, Append mo e) \\<in> set xs \\<or> \n    (\\<exists> mo2 . Deliver (mo, Store e mo2 mo) \\<in> set xs)\"\nproof -  \n  obtain y where \"apply_operations xs = Some y\"\n    using assms broadcast_only_valid_msgs by blast\n  moreover hence \"mo \\<in> snd (y e)\"\n    using broadcast_only_valid_msgs[of xs \"(i, Expunge e mo i)\" j] \n      valid_behaviours_def[of y \"(i, Expunge e mo i)\"] assms by auto\n  ultimately show ?thesis\n    using assms Deliver_added_files apply_operations_added_files by blast\nqed\n\nlemma (in imap) Broadcast_Store_Deliver_prefix_closed:\n  assumes \"xs @ [Broadcast (i, Store e mo i)] prefix of j\"\n  shows \"Deliver (mo, Append mo e) \\<in> set xs \\<or> \n    (\\<exists> mo2 . Deliver (mo, Store e mo2 mo) \\<in> set xs)\"\nproof -  \n  obtain y where \"apply_operations xs = Some y\"\n    using assms broadcast_only_valid_msgs by blast\n  moreover hence \"mo \\<in> snd (y e)\"\n    using broadcast_only_valid_msgs[of xs \"(i, Store e mo i)\" j] \n      valid_behaviours_def[of y \"(i, Store e mo i)\"] assms by auto\n  ultimately show ?thesis\n    using assms Deliver_added_files apply_operations_added_files by blast\nqed\n\nlemma (in imap) Deliver_added_ids:\n  assumes \"xs prefix of j\"\n    and \"i \\<in> set (added_ids xs e)\"\n  shows \"Deliver (i, Create i e) \\<in> set xs \\<or> \n    (\\<exists> mo . Deliver (i, Expunge e mo i) \\<in> set xs)\"\n  using assms proof (induct xs rule: rev_induct, clarsimp)\n  case (snoc x xs) thus ?case\n  proof (cases x, force)\n    case X: (Deliver e')\n    moreover obtain a b where \"e' = (a, b)\" by force\n    ultimately show ?thesis\n      using snoc apply (case_tac b; clarify)\n          apply (simp, metis added_ids_Deliver_Create_diff_collapse \n          added_ids_Deliver_Create_same_collapse empty_iff list.set(1) set_ConsD create_id_valid \n          in_set_conv_decomp prefix_of_appendD, force)\n      using append_id_valid apply (simp, metis (no_types, lifting)  prefix_of_appendD, simp, metis \n          Un_iff added_ids_Deliver_Expunge_diff_collapse added_ids_Deliver_Expunge_same_collapse \n          empty_iff expunge_id_valid list.set(1) list.set_intros(1) prefix_of_appendD set_ConsD \n          set_append)\n      by (simp, blast)\n  qed\nqed\n\nlemma (in imap) Broadcast_Deliver_prefix_closed:\n  assumes \"xs @ [Broadcast (r, Delete ix e)] prefix of j\"\n    and \"i \\<in> ix\"\n  shows \"Deliver (i, Create i e) \\<in> set xs \\<or> \n    Deliver (i, Append i e) \\<in> set xs \\<or> \n    (\\<exists> mo . Deliver (i, Expunge e mo i) \\<in> set xs) \\<or> \n    (\\<exists> mo . Deliver (i, Store e mo i) \\<in> set xs)\"\nproof -  \n  obtain y where \"apply_operations xs = Some y\"\n    using assms broadcast_only_valid_msgs by blast\n  moreover hence \"ix = fst (y e) \\<union> snd (y e)\"\n    by (metis (mono_tags, lifting) assms(1) broadcast_only_valid_msgs operation.case(2)\n        option.simps(1) valid_behaviours_def case_prodD)\n  ultimately show ?thesis\n    using assms Deliver_added_ids apply_operations_added_ids\n    by (metis Deliver_added_files Un_iff apply_operations_added_files le_iff_sup prefix_of_appendD)\nqed\n\nlemma (in imap) concurrent_create_delete_independent_technical:\n  assumes \"i \\<in> is\"\n    and \"xs prefix of j\"\n    and \"(i, Create i e) \\<in> set (node_deliver_messages xs)\" \n    and \"(ir, Delete is e) \\<in> set (node_deliver_messages xs)\"\n  shows \"hb (i, Create i e) (ir, Delete is e)\"\nproof -\n  have f1: \"Deliver (i, Create i e) \\<in> set (history j)\"\n    using assms prefix_msg_in_history by blast\n  obtain pre k where P: \"pre@[Broadcast (ir, Delete is e)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast\n  hence f2: \"Deliver (i, Create i e) \\<in> set pre \\<or> \n                  Deliver (i, Append i e) \\<in> set pre \\<or> \n                  (\\<exists> mo . Deliver (i, Expunge e mo i) \\<in> set pre) \\<or> \n                  (\\<exists> mo . Deliver (i, Store e mo i) \\<in> set pre)\"\n    using Broadcast_Deliver_prefix_closed assms by auto\n  have f3: \"Deliver (i, Append i e) \\<notin> set pre\" using f1 P \n    by (metis (full_types) Pair_inject fst_conv network.delivery_has_a_cause network.msg_id_unique \n        network_axioms operation.simps(9) prefix_elem_to_carriers prefix_of_appendD)\n  have f4: \"\\<forall> mo . Deliver (i, Expunge e mo i) \\<notin> set pre\" using f1 P\n    by (metis delivery_has_a_cause fst_conv msg_id_unique old.prod.inject operation.simps(11)\n        prefix_elem_to_carriers prefix_of_appendD)\n  have \"\\<forall> mo . Deliver (i, Store e mo i) \\<notin> set pre\" using f1 P\n    by (metis delivery_has_a_cause fst_conv msg_id_unique old.prod.inject operation.simps(13)\n        prefix_elem_to_carriers prefix_of_appendD) \n  thus ?thesis using f2 f3 f4  P events_in_local_order hb_deliver by blast\nqed\n\nlemma (in imap) concurrent_store_expunge_independent_technical:\n  assumes \"xs prefix of j\"\n    and \"(i, Store e mo i) \\<in> set (node_deliver_messages xs)\" \n    and \"(r, Expunge e i r) \\<in> set (node_deliver_messages xs)\"\n  shows \"hb (i, Store e mo i) (r, Expunge e i r)\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (r, Expunge e i r)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast\n  moreover hence f1: \"Deliver (i, Append i e) \\<in> set pre \\<or> \n  (\\<exists> mo2 . Deliver (i, Store e mo2 i) \\<in> set pre)\"\n    using Broadcast_Expunge_Deliver_prefix_closed assms(1) by auto\n  hence f2: \"Deliver (i, Append i e) \\<notin> set (history k)\"\n    by (metis Pair_inject assms(1) assms(2) fst_conv msg_id_unique network.delivery_has_a_cause \n        network_axioms operation.distinct(17) prefix_msg_in_history)\n  from f1 obtain mo2 :: 'a where\n    \"Deliver (i, Store e mo2 i) \\<in> set (history k)\" using f2\n    using P prefix_elem_to_carriers by blast  \n  hence \"Deliver (i, Store e mo i) \\<in> set (history k)\" using assms f1 f2 P \n    by (metis fst_conv msg_id_unique network.delivery_has_a_cause network_axioms \n        prefix_msg_in_history)    \n  then show ?thesis\n    using hb.intros(2) events_in_local_order f1 f2 P\n    by (metis delivery_has_a_cause fst_conv msg_id_unique node_histories.prefix_of_appendD \n        node_histories_axioms prefix_elem_to_carriers)\nqed\n\nlemma (in imap) concurrent_store_expunge_independent_technical2:\n  assumes \"xs prefix of j\"\n    and \"(i, Store e1 mo2 i) \\<in> set (node_deliver_messages xs)\" \n    and \"(r, Expunge e mo r) \\<in> set (node_deliver_messages xs)\"\n  shows \"mo2 \\<noteq> r\"\nproof -\n  obtain oid :: \"'a \\<times> ('a, 'b) operation \\<Rightarrow> nat\" where\n    oid: \"\\<forall>p n. Deliver p \\<notin> set (history n) \\<or> Broadcast p \\<in> set (history (oid p))\"\n    by (metis (no_types) delivery_has_a_cause)\n  hence f1: \"Broadcast (r, Expunge e mo r) \\<in> set (history (oid (r, Expunge e mo r)))\"\n    using assms(1) assms(3) prefix_msg_in_history by blast\n  obtain k :: \"'a \\<Rightarrow> 'b \\<Rightarrow> ('a \\<times> ('a, 'b) operation) event list \\<Rightarrow> 'a\" where k: \n    \"\\<forall>i e pre. (\\<exists>mo. Deliver (i, Store e mo i) \\<in> set pre) = \n    (Deliver (i, Store e (k i e pre) i) \\<in> set pre)\"\n    by moura\n  obtain pre :: \"nat \\<Rightarrow> ('a \\<times> ('a, 'b) operation) event \\<Rightarrow> ('a \\<times> ('a, 'b) operation) event list\" \n    where pre: \"\\<forall>k op1. (\\<exists>op2. op2 @ [op1] prefix of k) = (pre k op1 @ [op1] prefix of k)\"\n    by moura\n  hence f2: \"\\<forall>e n. e \\<notin> set (history n) \\<or> pre n e @ [e] prefix of n\"\n    using events_before_exist by simp\n  hence f3: \"pre (oid (i, Store e1 mo2 i)) (Broadcast (i, Store e1 mo2 i))\n  prefix of oid (i, Store e1 mo2 i)\"\n    using oid  assms(1) assms(2) prefix_msg_in_history by blast\n  have f4: \"Deliver (r, Append r e1) \\<notin> set (history (oid (i, Store e1 mo2 i)))\"\n    by (metis (no_types) oid f1 fst_conv msg_id_unique old.prod.inject operation.distinct(15))\n  have \"Deliver (r, Store e1 (k r e1 (pre (oid (i, Store e1 mo2 i)) \n  (Broadcast (i, Store e1 mo2 i)))) r) \\<notin> set (history (oid (i, Store e1 mo2 i)))\"\n    by (metis (no_types) oid f1 fst_conv msg_id_unique old.prod.inject operation.distinct(19))\n  thus ?thesis using oid k f2 f3 f4 assms\n    by (metis (no_types, lifting) Broadcast_Store_Deliver_prefix_closed \n        network.prefix_msg_in_history network_axioms prefix_elem_to_carriers)\nqed\n\nlemma (in imap) concurrent_store_delete_independent_technical:\n  assumes \"i \\<in> is\"\n    and \"xs prefix of j\"\n    and \"(i, Store e mo i) \\<in> set (node_deliver_messages xs)\" \n    and \"(ir, Delete is e) \\<in> set (node_deliver_messages xs)\"\n  shows \"hb (i, Store e mo i) (ir, Delete is e)\"\nproof -\n  have f1: \"Deliver (i, Store e mo i) \\<in> set (history j)\" using assms prefix_msg_in_history by auto\n  obtain pre k where P: \"pre@[Broadcast (ir, Delete is e)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast\n  hence f2: \"Deliver (i, Create i e) \\<in> set pre \\<or> \n  Deliver (i, Append i e) \\<in> set pre \\<or>\n  (\\<exists> mo . Deliver (i, Expunge e mo i) \\<in> set pre) \\<or> \n  (\\<exists> mo . Deliver (i, Store e mo i) \\<in> set pre)\"  \n    using Broadcast_Deliver_prefix_closed assms(1) by auto    \n  have f3: \"Deliver (i, Create i e) \\<notin> set pre\" using f1 P \n    by (metis Pair_inject delivery_has_a_cause fst_conv msg_id_unique operation.distinct(7) \n        prefix_elem_to_carriers prefix_of_appendD)\n  have f4: \"Deliver (i, Append i e) \\<notin> set pre\" using f1 P\n    by (metis delivery_has_a_cause fst_conv msg_id_unique operation.distinct(17) \n        prefix_elem_to_carriers prefix_of_appendD prod.inject)\n  have \"\\<forall> mo . Deliver (i, Expunge e mo i) \\<notin> set pre\" using f1 P\n    by (metis Pair_inject delivery_has_a_cause fst_conv msg_id_unique operation.simps(25) \n        prefix_elem_to_carriers prefix_of_appendD)\n  hence \"Deliver (i, Store e mo i) \\<in> set pre\" using f1 f2 f3 f4 P\n    by (metis delivery_has_a_cause fst_conv msg_id_unique node_histories.prefix_of_appendD \n        node_histories_axioms prefix_elem_to_carriers)     \n  thus ?thesis using P events_in_local_order hb_deliver by blast\nqed\n\nlemma (in imap) concurrent_append_delete_independent_technical:\n  assumes \"i \\<in> is\"\n    and \"xs prefix of j\"\n    and \"(i, Append i e) \\<in> set (node_deliver_messages xs)\" \n    and \"(ir, Delete is e) \\<in> set (node_deliver_messages xs)\"\n  shows \"hb (i, Append i e) (ir, Delete is e)\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (ir, Delete is e)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast\n  hence f1: \"Deliver (i, Create i e) \\<in> set pre \\<or> \n  Deliver (i, Append i e) \\<in> set pre \\<or> \n  (\\<exists> mo . Deliver (i, Expunge e mo i) \\<in> set pre) \\<or> \n  (\\<exists> mo . Deliver (i, Store e mo i) \\<in> set pre)\"\n    using Broadcast_Deliver_prefix_closed assms(1) by auto\n  hence \"Deliver (i, Append i e) \\<in> set pre\" using assms P f1\n    by (metis (no_types, hide_lams) delivery_has_a_cause events_in_local_order fst_conv \n        hb_broadcast_exists1 hb_deliver msg_id_unique prefix_msg_in_history)\n  thus ?thesis using P events_in_local_order hb_deliver by blast\nqed\n\nlemma (in imap) concurrent_append_expunge_independent_technical:\n  assumes \"i = mo\"\n    and \"xs prefix of j\"\n    and \"(i, Append i e) \\<in> set (node_deliver_messages xs)\" \n    and \"(r, Expunge e mo r) \\<in> set (node_deliver_messages xs)\"\n  shows \"hb (i, Append i e) (r, Expunge e mo r)\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (r, Expunge e mo r)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast\n  hence f1: \"Deliver (mo, Append mo e) \\<in> set pre \\<or> \n  (\\<exists> mo2 . Deliver (mo, Store e mo2 mo) \\<in> set pre)\"\n    using Broadcast_Expunge_Deliver_prefix_closed assms(1) by auto\n  hence \"(\\<forall> mo2 . Deliver (mo, Store e mo2 mo) \\<notin> set pre)\" using P assms \n  proof -\n    have \"Deliver (mo, Append mo e) \\<in> set (history j)\"\n      using assms(1) assms(2) assms(3) prefix_msg_in_history by blast\n    thus ?thesis\n      by (metis (no_types) P Pair_inject delivery_has_a_cause fst_conv msg_id_unique \n          operation.simps(23) prefix_elem_to_carriers prefix_of_appendD)\n  qed\n  thus ?thesis\n    using hb.intros(2) events_in_local_order assms(1) P f1 by blast\nqed\n\nlemma (in imap) concurrent_append_store_independent_technical:\n  assumes \"i = mo\"\n    and \"xs prefix of j\"\n    and \"(i, Append i e) \\<in> set (node_deliver_messages xs)\" \n    and \"(r, Store e mo r) \\<in> set (node_deliver_messages xs)\"\n  shows \"hb (i, Append i e) (r, Store e mo r)\"\nproof -\n  obtain pre k where pre: \"pre@[Broadcast (r, Store e mo r)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast\n  moreover hence f1: \"Deliver (mo, Append mo e) \\<in> set pre \\<or> \n  (\\<exists> mo2 . Deliver (mo, Store e mo2 mo) \\<in> set pre)\"\n    using Broadcast_Store_Deliver_prefix_closed assms(1) by auto\n  have f2: \"Deliver (i, Append i e) \\<in> set (history j)\"\n    by (meson assms network.prefix_msg_in_history network_axioms)\n  then show ?thesis using assms f1 \n    by (metis  pre delivery_has_a_cause events_in_local_order fst_conv hb_deliver \n        msg_id_unique node_histories.prefix_of_appendD node_histories_axioms \n        prefix_elem_to_carriers)\nqed\n\nlemma (in imap) concurrent_expunge_delete_independent_technical:\n  assumes \"i \\<in> is\"\n    and \"xs prefix of j\"\n    and \"(i, Expunge e mo i) \\<in> set (node_deliver_messages xs)\" \n    and \"(ir, Delete is e) \\<in> set (node_deliver_messages xs)\"\n  shows \"hb (i, Expunge e mo i) (ir, Delete is e)\"\nproof -\n  obtain pre k where pre: \"pre@[Broadcast (ir, Delete is e)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast\n  moreover hence A: \"Deliver (i, Create i e) \\<in> set pre \\<or> \n  Deliver (i, Append i e) \\<in> set pre \\<or> \n  (\\<exists> mo . Deliver (i, Expunge e mo i) \\<in> set pre) \\<or> \n  (\\<exists> mo . Deliver (i, Store e mo i) \\<in> set pre)\"\n    using Broadcast_Deliver_prefix_closed assms(1) by auto      \n  hence \"Deliver (i, Expunge e mo i) \\<in> set pre\" using assms\n  proof -\n    have f1: \"\\<And>e. e \\<notin> set pre \\<or> e \\<in> set (history k)\"\n      using pre prefix_elem_to_carriers by blast\n    have f2: \"Deliver (i, Expunge e mo i) \\<in> set (history j)\"\n      by (meson assms network.prefix_msg_in_history network_axioms)\n    then show ?thesis using f1 A \n      by (metis (no_types, lifting) fst_conv msg_id_unique network.delivery_has_a_cause \n          network_axioms)\n  qed     \n  ultimately show ?thesis\n    using hb.intros(2) events_in_local_order by blast\nqed\n\nlemma (in imap) concurrent_store_store_independent_technical:\n  assumes \"xs prefix of j\"\n    and \"(i, Store e mo i) \\<in> set (node_deliver_messages xs)\" \n    and \"(r, Store e i r) \\<in> set (node_deliver_messages xs)\"\n  shows \"hb (i, Store e mo i) (r, Store e i r)\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (r, Store e i r)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast\n  hence f1: \"\\<forall>e. e \\<notin> set pre \\<or> e \\<in> set (history k)\"\n    using prefix_elem_to_carriers by blast\n  have f2: \"Deliver (i, Append i e) \\<in> set pre \\<or> (\\<exists> mo2 . Deliver (i, Store e mo2 i) \\<in> set pre)\"\n    using Broadcast_Store_Deliver_prefix_closed assms(1) P by auto     \n  hence \"Deliver (i, Store e mo i) \\<in> set pre\" using assms f1 \n    by (metis delivery_has_a_cause fst_conv msg_id_unique prefix_msg_in_history)\n  then show ?thesis\n    using hb.intros(2) events_in_local_order P by blast\nqed\n\nlemma (in imap) expunge_delete_tag_causality:\n  assumes \"i \\<in> is\"\n    and \"xs prefix of j\"\n    and \"(i, Expunge e1 mo i) \\<in> set (node_deliver_messages xs)\" \n    and \"(ir, Delete is e2) \\<in> set (node_deliver_messages xs)\" \n    and \"pre@[Broadcast (ir, Delete is e2)] prefix of k\"\n  shows \"Deliver (i, Expunge e2 mo i) \\<in> set (history k)\"\nproof- \n  have f1: \"Deliver (i, Append i e2) \\<notin> set (history k)\" using assms\n    by (metis fst_conv msg_id_unique network.delivery_has_a_cause network_axioms old.prod.inject \n        operation.distinct(15) prefix_msg_in_history)\n  have f2: \"Deliver (i, Create i e2) \\<notin> set (history k)\" using assms\n    by (metis fst_conv msg_id_unique network.delivery_has_a_cause network_axioms old.prod.inject \n        operation.distinct(5) prefix_msg_in_history)\n  have f3: \"\\<forall> mo. Deliver (i, Store e2 mo i) \\<notin> set (history k)\" using assms\n    by (metis Pair_inject fst_conv msg_id_unique network.delivery_has_a_cause network_axioms \n        operation.simps(25) prefix_msg_in_history)\n  hence \"\\<exists> mo1. Deliver (i, Expunge e2 mo1 i) \\<in> set (history k)\" using assms f1 f2 \n    by (meson imap.Broadcast_Deliver_prefix_closed imap_axioms node_histories.prefix_of_appendD \n        node_histories_axioms prefix_elem_to_carriers)\n  then obtain mo1 :: 'a where\n    \"Deliver (i, Expunge e2 mo1 i) \\<in> set (history k)\" by blast\n  then show ?thesis  using assms f1 f2 f3\n    by (metis fst_conv msg_id_unique network.delivery_has_a_cause network_axioms old.prod.inject \n        operation.inject(4) prefix_msg_in_history)\nqed\n\nlemma (in imap) expunge_delete_ids_imply_messages_same:\n  assumes \"i \\<in> is\"\n    and \"xs prefix of j\"\n    and \"(i, Expunge e1 mo i) \\<in> set (node_deliver_messages xs)\" \n    and \"(ir, Delete is e2) \\<in> set (node_deliver_messages xs)\"\n  shows \"e1 = e2\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (ir, Delete is e2)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast  \n  hence \"Deliver (i, Expunge e2 mo i) \\<in> set (history k)\" using assms expunge_delete_tag_causality\n    by blast\n  then show ?thesis using assms\n    by (metis delivery_has_a_cause fst_conv network.msg_id_unique network_axioms \n        operation.inject(4) prefix_msg_in_history prod.inject)\nqed\n\nlemma (in imap) store_delete_ids_imply_messages_same:\n  assumes \"i \\<in> is\"\n    and \"xs prefix of j\"\n    and \"(i, Store e1 mo i) \\<in> set (node_deliver_messages xs)\" \n    and \"(ir, Delete is e2) \\<in> set (node_deliver_messages xs)\"\n  shows \"e1 = e2\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (ir, Delete is e2)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast \n  have f1: \"Deliver (i, Append i e2) \\<notin> set (history k)\" using assms\n    by (metis fst_conv msg_id_unique network.delivery_has_a_cause network_axioms old.prod.inject \n        operation.distinct(17) prefix_msg_in_history)\n  have f2: \"\\<forall> mo. Deliver (i, Expunge e2 mo i) \\<notin> set (history k)\" using assms\n    by (metis Pair_inject fst_conv msg_id_unique network.delivery_has_a_cause network_axioms \n        operation.distinct(19) prefix_msg_in_history)\n  have f3: \"Deliver (i, Create i e2) \\<notin> set (history k)\" using assms\n    by (metis fst_conv msg_id_unique network.delivery_has_a_cause network_axioms old.prod.inject \n        operation.distinct(8) prefix_msg_in_history)\n  hence \"(\\<exists> mo1. Deliver (i, Store e2 mo1 i) \\<in> set pre)\" using assms P f1 f2 imap_axioms \n    by (meson imap.Broadcast_Deliver_prefix_closed prefix_elem_to_carriers prefix_of_appendD)\n  then obtain mo1 :: 'a where\n    f3: \"Deliver (i, Store e2 mo1 i) \\<in> set pre\" by blast\n  then have f4: \"Deliver (i, Store e2 mo1 i) \\<in> set (history k)\"\n    using P prefix_elem_to_carriers by blast \n  hence \"Deliver (i, Store e2 mo i) \\<in> set pre\" using f2 f3 assms \n    by (metis fst_conv msg_id_unique network.delivery_has_a_cause network_axioms old.prod.inject \n        operation.inject(5) prefix_msg_in_history)\n  moreover have \"Deliver(i, Store e1 mo i) \\<in> set (history j)\"\n    using assms(2) assms(3) prefix_msg_in_history by blast \n  ultimately show ?thesis using f4\n    by (metis delivery_has_a_cause fst_conv msg_id_unique old.prod.inject operation.inject(5))\nqed\n\nlemma (in imap) create_delete_ids_imply_messages_same:\n  assumes \"i \\<in> is\"\n    and \"xs prefix of j\"\n    and \"(i, Create i e1) \\<in> set (node_deliver_messages xs)\" \n    and \"(ir, Delete is e2) \\<in> set (node_deliver_messages xs)\"\n  shows \"e1 = e2\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (ir, Delete is e2)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast\n  have f1: \"Deliver (i, Append i e2) \\<notin> set (history k)\"\n    by (metis assms(2) assms(3) delivery_has_a_cause fst_conv network.msg_id_unique \n        network.prefix_msg_in_history network_axioms operation.distinct(3) prod.inject)\n  have f2: \"\\<forall> mo. Deliver (i, Expunge e2 mo i) \\<notin> set (history k)\"\n    by (metis assms(2) assms(3) fst_conv msg_id_unique network.delivery_has_a_cause network_axioms \n        old.prod.inject operation.distinct(5) prefix_msg_in_history)\n  have f3: \"\\<forall> mo. Deliver (i, Store e2 mo i) \\<notin> set (history k)\"\n    by (metis Pair_inject assms(2) assms(3) delivery_has_a_cause fst_conv msg_id_unique \n        operation.distinct(7) prefix_msg_in_history)\n  hence \"Deliver (i, Create i e2) \\<in> set pre\" using assms P f2 f1 imap_axioms\n    by (meson imap.Broadcast_Deliver_prefix_closed  prefix_elem_to_carriers prefix_of_appendD)\n  then show ?thesis using f1 f2 f3\n    by (metis (no_types, lifting) P assms(2) assms(3) delivery_has_a_cause fst_conv msg_id_unique \n        node_histories.prefix_of_appendD node_histories_axioms old.prod.inject operation.inject(1) \n        prefix_elem_to_carriers prefix_msg_in_history)\nqed\n\nlemma (in imap) append_delete_ids_imply_messages_same:\n  assumes \"i \\<in> is\"\n    and \"xs prefix of j\"\n    and \"(i, Append i e1) \\<in> set (node_deliver_messages xs)\" \n    and \"(ir, Delete is e2) \\<in> set (node_deliver_messages xs)\"\n  shows \"e1 = e2\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (ir, Delete is e2)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast  \n  hence f1: \"\\<And>e. e \\<in> set pre \\<Longrightarrow> e \\<in> set (history k)\" using prefix_elem_to_carriers by blast\n  have f2: \"Deliver (i, Create i e2) \\<notin> set pre\" using P f1\n    by (metis assms(2) assms(3) fst_conv msg_id_unique network.delivery_has_a_cause network_axioms \n        old.prod.inject operation.distinct(3) prefix_msg_in_history)\n  moreover have D1: \"\\<forall> mo. Deliver (i, Expunge e2 mo i) \\<notin> set pre\" using P f1\n    by (metis Pair_inject assms(2) assms(3) fst_conv msg_id_unique network.delivery_has_a_cause \n        network_axioms operation.distinct(15) prefix_msg_in_history)\n  moreover have D2: \"\\<forall> mo. Deliver (i, Store e2 mo i) \\<notin> set pre\" using P f1\n    by (metis Pair_inject assms(2) assms(3) fst_conv msg_id_unique network.delivery_has_a_cause \n        network_axioms operation.simps(23) prefix_msg_in_history)\n  moreover hence \"Deliver (i, Append i e2) \\<in> set pre\" \n    using P D1 D2 f2 assms(1) Broadcast_Deliver_prefix_closed by blast\n  moreover have \"Deliver (i, Append i e1) \\<in> set (history j)\"\n    using assms(2) assms(3) prefix_msg_in_history by blast\n  ultimately show ?thesis using assms \n    by (metis f1 msg_id_unique network.delivery_has_a_cause network_axioms old.prod.inject \n        operation.inject(3) prod.sel(1))\nqed\n\nlemma (in imap) append_expunge_ids_imply_messages_same:\n  assumes \"i = mo\"\n    and \"xs prefix of j\"\n    and \"(i, Append i e1) \\<in> set (node_deliver_messages xs)\" \n    and \"(r, Expunge e2 mo r) \\<in> set (node_deliver_messages xs)\"\n  shows \"e1 = e2\"\nproof -\n  obtain pre k where pre: \"pre@[Broadcast (r, Expunge e2 mo r)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast  \n  moreover hence \"Deliver (mo, Append mo e2) \\<in> set pre \\<or> \n  (\\<exists> mo2 . Deliver (mo, Store e2 mo2 mo) \\<in> set pre)\"\n    using Broadcast_Expunge_Deliver_prefix_closed assms(1)\n    by (meson imap.Broadcast_Deliver_prefix_closed imap_axioms)      \n  hence \"Deliver (i, Append i e2) \\<in> set pre\" using assms\n    by (metis (no_types, lifting) pre delivery_has_a_cause fst_conv hb_broadcast_exists1 \n        msg_id_unique network.hb_deliver network.prefix_msg_in_history network_axioms \n        node_histories.events_in_local_order node_histories_axioms operation.distinct(17) \n        prod.inject)     \n  moreover have \"Deliver (i, Append i e1) \\<in> set (history j)\"\n    using assms(2) assms(3) prefix_msg_in_history by blast\n  ultimately show ?thesis\n    by (metis (no_types, lifting) fst_conv network.delivery_has_a_cause network.msg_id_unique \n        network_axioms operation.inject(3) prefix_elem_to_carriers prefix_of_appendD prod.inject)\nqed\n\nlemma (in imap) append_store_ids_imply_messages_same:\n  assumes \"i = mo\"\n    and \"xs prefix of j\"\n    and \"(i, Append i e1) \\<in> set (node_deliver_messages xs)\" \n    and \"(r, Store e2 mo r) \\<in> set (node_deliver_messages xs)\"\n  shows \"e1 = e2\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (r, Store e2 mo r)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast  \n  moreover hence A: \"Deliver (mo, Append mo e2) \\<in> set pre \\<or> \n  (\\<exists> mo2 . Deliver (mo, Store e2 mo2 mo) \\<in> set pre)\"\n    using Broadcast_Store_Deliver_prefix_closed assms(1)\n    by (meson imap.Broadcast_Deliver_prefix_closed imap_axioms)\n  have f1: \"Deliver (i, Append i e1) \\<in> set (history j)\"\n    using assms(2) assms(3) prefix_msg_in_history by blast\n  hence \"Deliver (i, Append i e2) \\<in> set pre\" using assms P A\n    by (metis Pair_inject assms(1) P delivery_has_a_cause fst_conv msg_id_unique \n        operation.simps(23) prefix_elem_to_carriers prefix_of_appendD)\n  then show ?thesis using f1\n    by (metis P delivery_has_a_cause fst_conv msg_id_unique \n        node_histories.prefix_of_appendD node_histories_axioms operation.inject(3) \n        prefix_elem_to_carriers prod.inject)\nqed\n\nlemma (in imap) expunge_store_ids_imply_messages_same:\n  assumes \"xs prefix of j\"\n    and \"(i, Store e1 mo i) \\<in> set (node_deliver_messages xs)\" \n    and \"(r, Expunge e2 i r) \\<in> set (node_deliver_messages xs)\"\n  shows \"e1 = e2\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (r, Expunge e2 i r)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast \n  hence pprefix: \"pre prefix of k\"\n    using P by blast\n  have A: \"Deliver (i, Append i e2) \\<in> set pre \\<or> \n  (\\<exists> mo2 . Deliver (i, Store e2 mo2 i) \\<in> set pre)\"\n    using Broadcast_Expunge_Deliver_prefix_closed assms(1) P by blast      \n  have \"Deliver (i, Store e2 mo i) \\<in> set pre\" using assms A P\n  proof -\n    obtain op1 :: \"'a \\<times> ('a, 'b) operation \\<Rightarrow> nat\" where\n      f1: \"Broadcast (i, Store e1 mo i) \\<in> set (history (op1 (i, Store e1 mo i)))\"\n      by (meson assms(1) assms(2) delivery_has_a_cause prefix_msg_in_history)\n    then show ?thesis \n      using f1 A pprefix delivery_has_a_cause network.msg_id_unique network_axioms \n        node_histories.prefix_to_carriers node_histories_axioms \n      by fastforce\n  qed\n  moreover have \"Deliver (i, Store e1 mo i) \\<in> set (history j)\"\n    using assms(1) assms(2) prefix_msg_in_history by auto\n  ultimately show ?thesis using assms P\n    by (metis delivery_has_a_cause fst_conv msg_id_unique operation.inject(5) \n        prefix_elem_to_carriers prefix_of_appendD prod.inject) \nqed\n\nlemma (in imap) store_store_ids_imply_messages_same:\n  assumes \"xs prefix of j\"\n    and \"(i, Store e1 mo i) \\<in> set (node_deliver_messages xs)\" \n    and \"(r, Store e2 i r) \\<in> set (node_deliver_messages xs)\"\n  shows \"e1 = e2\"\nproof -\n  obtain pre k where P: \"pre@[Broadcast (r, Store e2 i r)] prefix of k\"\n    using assms delivery_has_a_cause events_before_exist prefix_msg_in_history by blast  \n  moreover hence A: \"Deliver (i, Append i e2) \\<in> set pre \\<or>\n    (\\<exists> mo2 . Deliver (i, Store e2 mo2 i) \\<in> set pre)\"\n    using Broadcast_Store_Deliver_prefix_closed assms(1) by blast\n  have \"\\<forall>e. e \\<notin> set pre \\<or> e \\<in> set (history k)\"\n    using P prefix_elem_to_carriers by auto\n  hence \"Deliver (i, Store e2 mo i) \\<in> set pre\" \n    by (metis A assms(1) assms(2) delivery_has_a_cause fst_conv msg_id_unique \n        operation.distinct(17) operation.inject(5) prefix_msg_in_history prod.inject)\n  moreover have \"Deliver (i, Store e1 mo i) \\<in> set (history j)\"\n    using assms(1) assms(2) prefix_msg_in_history by auto\n  ultimately show ?thesis using assms\n    by (metis Pair_inject delivery_has_a_cause msg_id_unique operation.simps(5) \n        prefix_elem_to_carriers prefix_of_appendD prod.sel(1))\nqed \n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/IMAP-CRDT/IMAP-proof-independent.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5312093585306515, "lm_q2_score": 0.4726834766204328, "lm_q1q2_score": 0.2510938864035783}}
{"text": "theory SINVAR_NoRefl_impl\nimports SINVAR_NoRefl \"../TopoS_Interface_impl\"\nbegin\n\ncode_identifier code_module  SINVAR_NoRefl_impl => (Scala) SINVAR_NoRefl\n\n\nsubsubsection \\<open>SecurityInvariant NoRefl List Implementation\\<close>\n\nfun sinvar :: \"'v list_graph \\<Rightarrow> ('v \\<Rightarrow> node_config) \\<Rightarrow> bool\" where\n  \"sinvar G nP = (\\<forall> (s,r) \\<in> set (edgesL G). s = r \\<longrightarrow> nP s = Refl)\"\n\n\ndefinition NoRefl_offending_list:: \"'v list_graph \\<Rightarrow> ('v \\<Rightarrow> node_config) \\<Rightarrow> ('v \\<times> 'v) list list\" where\n  \"NoRefl_offending_list G nP = (if sinvar G nP then\n    []\n   else \n    [ [e \\<leftarrow> edgesL G. case e of (e1,e2) \\<Rightarrow> e1 = e2 \\<and> nP e1 = NoRefl] ])\"\n\n\n\ndefinition \"NetModel_node_props P = (\\<lambda> i. (case (node_properties P) i of Some property \\<Rightarrow> property | None \\<Rightarrow> SINVAR_NoRefl.default_node_properties))\"\n\n\ndefinition \"NoRefl_eval G P = (wf_list_graph G \\<and>\n  sinvar G (SecurityInvariant.node_props SINVAR_NoRefl.default_node_properties P))\"\n\n\ninterpretation NoRefl_impl:TopoS_List_Impl \n  where default_node_properties=SINVAR_NoRefl.default_node_properties\n  and sinvar_spec=SINVAR_NoRefl.sinvar\n  and sinvar_impl=sinvar\n  and receiver_violation=SINVAR_NoRefl.receiver_violation\n  and offending_flows_impl=NoRefl_offending_list\n  and node_props_impl=NetModel_node_props\n  and eval_impl=NoRefl_eval\n apply(unfold TopoS_List_Impl_def)\n apply(rule conjI)\n  apply(simp add: TopoS_NoRefl list_graph_to_graph_def)\n apply(rule conjI)\n  apply(simp add: list_graph_to_graph_def NoRefl_offending_set NoRefl_offending_set_def NoRefl_offending_list_def)\n apply(rule conjI)\n  apply(simp only: NetModel_node_props_def)\n  apply(metis NoRefl.node_props.simps NoRefl.node_props_eq_node_props_formaldef)\n apply(simp only: NoRefl_eval_def)\n apply(simp add: TopoS_eval_impl_proofrule[OF TopoS_NoRefl])\n apply(simp add: list_graph_to_graph_def)\ndone\n\n\nsubsubsection \\<open>PolEnforcePoint packing\\<close>\n  definition SINVAR_LIB_NoRefl :: \"('v::vertex, node_config) TopoS_packed\" where\n    \"SINVAR_LIB_NoRefl \\<equiv> \n    \\<lparr> nm_name = ''NoRefl'', \n      nm_receiver_violation = SINVAR_NoRefl.receiver_violation,\n      nm_default = SINVAR_NoRefl.default_node_properties, \n      nm_sinvar = sinvar,\n      nm_offending_flows = NoRefl_offending_list, \n      nm_node_props = NetModel_node_props,\n      nm_eval = NoRefl_eval\n      \\<rparr>\"\n  interpretation SINVAR_LIB_NoRefl_interpretation: TopoS_modelLibrary SINVAR_LIB_NoRefl\n      SINVAR_NoRefl.sinvar\n    apply(unfold TopoS_modelLibrary_def SINVAR_LIB_NoRefl_def)\n    apply(rule conjI)\n     apply(simp)\n    apply(simp)\n    by(unfold_locales)\n\ntext \\<open>Examples\\<close>\n\n  definition example_net :: \"nat list_graph\" where\n  \"example_net \\<equiv> \\<lparr> nodesL = [1::nat,2,3], \n    edgesL = [(1,2),(2,2),(2,1),(1,3)] \\<rparr>\"\n  lemma \"wf_list_graph example_net\" by eval\n  \n  definition example_conf where\n  \"example_conf \\<equiv> ((\\<lambda>e. SINVAR_NoRefl.default_node_properties)(2:= Refl))\" \n  \n  lemma \"sinvar example_net example_conf\" by eval\n  lemma \"NoRefl_offending_list example_net (\\<lambda>e. SINVAR_NoRefl.default_node_properties) = [[(2, 2)]]\" by eval\n\n\nhide_const (open) NetModel_node_props\nhide_const (open) sinvar\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Network_Security_Policy_Verification/Security_Invariants/SINVAR_NoRefl_impl.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.2508491276625876}}
{"text": "(*\n * Copyright 2016, NICTA\n *\n * This software may be distributed and modified according to the terms of\n * the GNU General Public License version 2. Note that NO WARRANTY is provided.\n * See \"LICENSE_GPLv2.txt\" for details.\n *\n * @TAG(NICTA_GPL)\n *)\n\ntheory AfsFsopR\nimports\n  \"../adt/BilbyT\"\n  \"../adt/VfsT\"\n  \"../spec/AfsS\"\n  \"../spec/AfsInvS\"\n  \"../spec/OstoreInvS\"\nbegin\n\ntext {*\n Relation between the abstract FS of the correctness\n spec and the FS implemented by the Fsop component relying on\n the object store. \n\nThe object store is a projection from its internal state to a\nmapping from OID to Object (ostore_map).\nEach ostore update is a function update on the ostore_map and can non-deterministically\nbe synchronised to medium. Synchronisation is similar to correctness spec level,\napplying all updates to ostore_map. Refinement proof (fsop_sync/ostore_sync) should be easy.\nEach update should have a matching update at correctness spec level and applying all\nand sequentially applying updates on both AFS and OstoreMap should yield an element\nthat satisfy the relation afs_fsop_sr.\n\n*}\n\ndefinition\n obj_inode_type_to_afs_type :: \"ObjInode\\<^sub>T \\<Rightarrow> afs_inode \\<Rightarrow> afs_inode_type\"\nwhere\n  \"obj_inode_type_to_afs_type i afsinode \\<equiv> (if S_ISREG (ObjInode.mode\\<^sub>f i) then IReg (i_data afsinode) else\n                (if S_ISDIR (ObjInode.mode\\<^sub>f i) then IDir (i_dir afsinode) else\n                 (\\<comment> \\<open> if S_ISLNK (mode<^sub>f i) then \\<close> ILnk (i_path afsinode) \\<comment> \\<open>else\n                   undefined\\<close>)))\" \n\ndefinition\n  obj_inode_to_afs_inode :: \"Obj\\<^sub>T \\<Rightarrow> afs_inode \\<Rightarrow> afs_inode\"\nwhere\n  \"obj_inode_to_afs_inode obj afsinode \\<equiv>\n    (let i = obj_oinode obj in\n     \\<lparr>i_type = obj_inode_type_to_afs_type i afsinode,\n      i_ino = inum_from_obj_id $ ObjInode.id\\<^sub>f i,\n      i_nlink = ObjInode.nlink\\<^sub>f i,\n      i_size = ObjInode.size\\<^sub>f i,\n      i_mtime = ObjInode.mtime_sec\\<^sub>f i,\n      i_ctime = ObjInode.ctime_sec\\<^sub>f i,\n      i_uid = ObjInode.uid\\<^sub>f i,\n      i_gid = ObjInode.gid\\<^sub>f i,\n      i_mode = ObjInode.mode\\<^sub>f i,\n      i_flags = ObjInode.flags\\<^sub>f i\\<rparr>)\"\n      \n\ntext {*\n Relation between a AFS file and a file in the object store.\n A file in the correctness spec corresponds to two type of objects\n stored in the object store:\n  - An inode object where file attributes are stored, including the\n    size (i_data part is irrelevant)\n  - Multiple data objects that contain the data stored in the file.\n    Each data object contains a \"block\" of data of BILBYFS_BLOCK_SIZE\n    bytes. The block index parameter of ObjIdData indicates the index\n    of the block in the file. (Where index i is byte offset\n    i \\<times> BILBYFS_BLOCK_SIZE in the file.)\n    We currently do not allow holes.\n *}\n\ndefinition\n  file_eq :: \"afs_inode \\<Rightarrow> ostore_map \\<Rightarrow> bool\"\nwhere\n \"file_eq file os \\<equiv>\n   (\\<forall>blk_idx blk. (blk_idx < length (i_data file) \\<and> blk = (i_data file) ! blk_idx) \\<longrightarrow>\n     blk = (\\<alpha>wa $ odata\\<^sub>f $ obj_odata $ the $ os $ obj_id_data_mk (i_ino file, of_nat blk_idx)))\"                     \n\ndefinition\n  get_dent_type :: \"afs_map \\<Rightarrow> Ino \\<Rightarrow> U8\"\nwhere\n \"get_dent_type afs ino \\<equiv>\n    (case (i_type $ the $ afs ino) of\n       IReg _ \\<Rightarrow>  bilbyFsItypeReg | IDir _ \\<Rightarrow> bilbyFsItypeDir | ILnk _ \\<Rightarrow> bilbyFsItypeLnk )\"\n\ntext {*\n  Relation between a AFS directory and a directory in the object store.\n  At the correctness spec level directories are a an inode that contains\n  a bunch of attributes and a mapping from name to inode number.\n  At the Fsop level, directories are:\n    - An inode for attributes such as mode, owner...\n    - Multiple directory entry arrays (dentarrs).\n       Each directory entry contains a name, an inode number and a type.\n       The idea is that in order to have a quick lookup for a name in a\n       directory, we address directory entries using a hash of the\n       name they contain. As different names can have the same hash,\n       we group all hash collisions together within an array of directory\n       entry (dentarr).\n       Mapping entries on AFS directories and dentarr objects attached to\n       Fsop directories have to match one another.\n       Additionally, directory entries at Fsop level contain a type\n       attribute which indicates the type of the inode referred by the\n       inode number. This type attribute is a duplicated piece of\n       information also contained in the inode itself, but having\n       it is necessary for performance reason. When listing a directory\n       reading an extra inode for each directory entry would be orders\n       of magnitude slower.\n   *}\n\ndefinition\n  dir_eq :: \"afs_inode \\<Rightarrow> afs_map \\<Rightarrow>ostore_map \\<Rightarrow> bool\"\nwhere\n \"dir_eq dir afs os \\<equiv>\n    (\\<forall>name. \n     (let obj = os $ obj_id_dentarr_mk (i_ino dir, name);\n          entries = stripNone $ \\<alpha>a $ ObjDentarr.entries\\<^sub>f $ obj_odentarr $ the obj in\n      (case i_dir dir $ \\<alpha>wa name of\n        option.Some in_ino \\<Rightarrow>\n         (case obj of\n           option.Some _ \\<Rightarrow>\n            {e \\<in> set entries. ObjDentry.ino\\<^sub>f e = in_ino \\<and> ObjDentry.name\\<^sub>f e = name} =\n              {\\<lparr>ino\\<^sub>f = in_ino, type\\<^sub>f = get_dent_type afs in_ino, nlen\\<^sub>f = u32_to_u16 $ wordarray_length name, name\\<^sub>f = name \\<rparr>} |\n            option.None \\<Rightarrow> False)\n       | option.None \\<Rightarrow>\n           (case obj of\n              option.Some _ \\<Rightarrow>\n                  {e \\<in> set entries. ObjDentry.name\\<^sub>f e = name} = {}\n            | option.None \\<Rightarrow> True))))\"\n\ntext {* Relation between a AFS symlinks and a symlinks in the object store.\n  This relation is quite similar to files except that symbolic links can\n  only use a single data block to store the symbolic link path.\n*}\ndefinition\n  symlink_eq :: \"afs_inode \\<Rightarrow> ostore_map \\<Rightarrow> bool\"\nwhere\n \"symlink_eq symlink os \\<equiv>\n   i_path symlink = (\\<alpha>wa $ odata\\<^sub>f $ obj_odata $ the $ os $ obj_id_data_mk (i_ino symlink, 0))\"\n\ntext {*\n  Domain equivalence ensures that there is an inode in the AFS\n  iff there is an existing inode at Fsop level.\n*}\ndefinition\n  afs_fsop_dom_eq :: \"afs_map \\<Rightarrow> ostore_map \\<Rightarrow> bool\"\nwhere\n \"afs_fsop_dom_eq afs os \\<equiv> dom afs = dom (\\<lambda>ino. os (obj_id_inode_mk ino))\"\n\ntext {*\n  Content equivalence\n*}\ndefinition\n  afs_fsop_content_eq :: \"afs_map \\<Rightarrow> ostore_map \\<Rightarrow> bool\"\nwhere\n \"afs_fsop_content_eq afs os \\<equiv> \n  (\\<forall>ino \\<in> dom afs.\n      let inode = (the $ afs ino);\n          oino = (the $ os $ obj_id_inode_mk ino) in\n          obj_inode_to_afs_inode oino inode = inode \\<and>\n          (case i_type inode of\n             IReg file_data \\<Rightarrow> file_eq inode os |\n             IDir dir \\<Rightarrow> dir_eq inode afs os |\n             ILnk path \\<Rightarrow>  symlink_eq inode os))\"\n\ndefinition\n  afs_fsop_match :: \"afs_map \\<Rightarrow> ostore_map \\<Rightarrow> bool\"\nwhere\n \"afs_fsop_match afs os \\<equiv> afs_fsop_dom_eq afs os \\<and> afs_fsop_content_eq afs os\"\n                                                         \ntext {*\n Definitions useful to describe parameters, pre/post conditions of\n refinement statements\n*}\ndefinition\n vnode_afs_inode_consistency :: \"vnode \\<Rightarrow> afs_inode \\<Rightarrow> bool\"\nwhere\n \"vnode_afs_inode_consistency v i \\<equiv>\n  v_ino v = i_ino i \\<and>\n  v_nlink v = i_nlink i \\<and>\n  v_mtime v = i_mtime i \\<and>\n  v_ctime v = i_ctime i \\<and>\n  v_uid v = i_uid i \\<and>\n  v_gid v = i_gid i \\<and>\n  v_mode v = i_mode i\"\n\ndefinition\n is_valid_vdir :: \"vnode \\<Rightarrow> (Ino \\<rightharpoonup> afs_inode) \\<Rightarrow> bool\"\nwhere\n \"is_valid_vdir vdir afs \\<equiv>\n    v_ino vdir \\<in> dom afs \\<and>\n    (v_mode vdir AND s_IFMT = s_IFDIR) \\<and>\n    afs_inode_is_dir (i_type $ the $ afs $ v_ino vdir) \\<and>\n    vnode_afs_inode_consistency vdir (the $ afs $ v_ino vdir)\"\n\nlemma vdir_dir_consistent:\n \"is_valid_vdir vdir afs \\<Longrightarrow> vnode_afs_inode_consistency vdir (the $ afs $ v_ino vdir)\"\n by (clarsimp simp: is_valid_vdir_def dom_def)\n\nlemma vdir_is_dir:\n \"\\<lbrakk> is_valid_vdir vdir afs \\<rbrakk> \\<Longrightarrow> afs_inode_is_dir (i_type $ the $ afs (v_ino vdir))\"\n  by (clarsimp simp: is_valid_vdir_def)\n\ntext {* Refinement proof of the operation sync. *}\n\ndefinition\n match_afs_data_fs_state :: \"afs_state \\<Rightarrow> FsState\\<^sub>T \\<Rightarrow> bool\"\nwhere\n \"match_afs_data_fs_state afs_data fs_st \\<equiv>\n  a_is_readonly afs_data = (is_ro\\<^sub>f $ fsop_st\\<^sub>f fs_st)\"\n\ndefinition\n afs_fsop_match_step_updates :: \"afs_map \\<Rightarrow> (afs_map \\<Rightarrow> afs_map) list \\<Rightarrow>\n                                 ostore_map \\<Rightarrow> (ostore_map \\<Rightarrow> ostore_map) list \\<Rightarrow> bool\"\nwhere\n \"afs_fsop_match_step_updates afs afs_updates os os_updates \\<equiv>\n     length os_updates = length afs_updates \\<and>\n     (\\<forall>n \\<le> length os_updates.\n        afs_fsop_match (a_afs_updated_n n afs afs_updates)\n                       (apply_n_updates n os os_updates))\"\n\ndefinition\n \"afmsu afs_data os_st \\<equiv> \n   afs_fsop_match_step_updates\n    (a_medium_afs afs_data) (a_medium_updates afs_data) \n    (\\<alpha>_ostore_medium os_st) (\\<alpha>_updates os_st)\"\n\ndefinition\n  \"afs_inv_steps afs \\<equiv>\n    (\\<forall>n \\<le> length (a_medium_updates afs).\n     afs_inv (a_afs_updated_n n (a_medium_afs afs) (a_medium_updates afs)))\"\n\nlemma afs_inv_steps_updated_afsD:\n \"afs_inv_steps afs \\<Longrightarrow> afs_inv (updated_afs afs)\"\n  apply (simp add: updated_afs_def)\n  apply (simp add: afs_inv_steps_def)\n  apply (erule_tac x=\"length (a_medium_updates afs)\" in allE)\n  apply (fastforce simp add: a_afs_updated_def)\n done\n\ntext{* In the success case, we ensure that the updates match and that the on-medium\n states match too. Note that simply applying the updates on both sides and ensuring\n that the resulting states match is not enough, both syncs could have applied a different\n number of updates. *}\ndefinition\n afs_fsop_rel :: \"afs_state \\<Rightarrow> FsState\\<^sub>T \\<Rightarrow> bool\"\nwhere\n \"afs_fsop_rel afs_data fs_st \\<equiv>\n   inv_mount_st (FsState.mount_st\\<^sub>f fs_st) \\<and>\n   afs_inv_steps afs_data \\<and> \n   (let os_st = ostore_st\\<^sub>f fs_st in\n     afmsu afs_data os_st \\<and>\n     inv_ostore (mount_st\\<^sub>f fs_st) os_st \\<and> inv_\\<alpha>_ostore (\\<alpha>_ostore_uptodate os_st) \\<and>\n     match_afs_data_fs_state afs_data fs_st)\"\n\nlemma afs_fsop_rel_inv_ostoreD:\n \"afs_fsop_rel afs_data fs_st \\<Longrightarrow> inv_ostore (mount_st\\<^sub>f fs_st) (ostore_st\\<^sub>f fs_st)\"\n by (clarsimp simp: afs_fsop_rel_def Let_def) \n(*\nlemma afs_fsop_rel_inv_stepD:\n\"afs_fsop_rel afs_data fs_st \\<Longrightarrow> inv_\\<alpha>_step_updates (ostore_st\\<^sub>f fs_st)\"\nby (clarsimp simp: afs_fsop_rel_def Let_def) \n*)\nlemma afs_fsop_rel_inv_\\<alpha>_ostoreD:\n\"afs_fsop_rel afs_data fs_st \\<Longrightarrow>  inv_\\<alpha>_ostore (\\<alpha>_ostore_uptodate (ostore_st\\<^sub>f fs_st))\"\nby (clarsimp simp: afs_fsop_rel_def Let_def) \n\nlemmas afs_fsop_rel_simps = \n  afs_fsop_rel_def \n  match_afs_data_fs_state_def\n  afmsu_def\n  Let_def\n  afs_fsop_match_step_updates_def\n\nend\n", "meta": {"author": "au-ts", "repo": "cogent", "sha": "a1464313bbd1bbfaa5c4e58ab14f669c6d2436a2", "save_path": "github-repos/isabelle/au-ts-cogent", "path": "github-repos/isabelle/au-ts-cogent/cogent-a1464313bbd1bbfaa5c4e58ab14f669c6d2436a2/impl/fs/bilby/proof/refine/AfsFsopR.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5350984286266115, "lm_q2_score": 0.46879062662624377, "lm_q1q2_score": 0.2508491276625876}}
{"text": "theory PetersonLitmus\n  imports Examples \nbegin\n\ndatatype globals = X | Y | T\nrecord aux = S :: bool\n\nlemma thread0:\n  \"FNBEGIN\n    R: (\\<^sup>1\\<lbrakk>X\\<rbrakk> \\<longrightarrow> \\<^sup>2\\<^sup>aS \\<longrightarrow> \\<^sup>1\\<^sup>aS) \\<and> \\<^sup>1\\<lbrakk>X\\<rbrakk> = \\<^sup>2\\<lbrakk>X\\<rbrakk> \\<and> (\\<^sup>2\\<lbrakk>T\\<rbrakk> = \\<^sup>1\\<lbrakk>T\\<rbrakk> \\<or> (\\<^sup>1\\<lbrakk>T\\<rbrakk> \\<and> \\<not> \\<^sup>2\\<lbrakk>T\\<rbrakk> \\<and> (\\<^sup>1\\<lbrakk>X\\<rbrakk> \\<longrightarrow> \\<not>\\<^sup>2\\<^sup>aS)))\n    G: (\\<^sup>1\\<lbrakk>Y\\<rbrakk> \\<longrightarrow> \\<^sup>1\\<^sup>aS \\<longrightarrow> \\<^sup>2\\<^sup>aS) \\<and> \\<^sup>1\\<lbrakk>Y\\<rbrakk> = \\<^sup>2\\<lbrakk>Y\\<rbrakk> \\<and> (\\<^sup>2\\<lbrakk>T\\<rbrakk> = \\<^sup>1\\<lbrakk>T\\<rbrakk> \\<or> (\\<not>\\<^sup>1\\<lbrakk>T\\<rbrakk> \\<and> \\<^sup>2\\<lbrakk>T\\<rbrakk> \\<and> (\\<^sup>1\\<lbrakk>Y\\<rbrakk> \\<longrightarrow> \\<^sup>2\\<^sup>aS)))\n    P: True\n    {\n      \\<lbrakk>X\\<rbrakk> := #True;\n      fence;\n      \\<lbrakk>T\\<rbrakk> := #True :\\<^sub>a \\<^sup>aS := True;\n      fence;\n      \\<^bold>r0 := \\<lbrakk>Y\\<rbrakk> :\\<^sub>a \\<^sup>aS := (\\<^sup>aS \\<and> \\<^sup>0\\<lbrakk>Y\\<rbrakk>);\n      \\<^bold>r1 := \\<lbrakk>T\\<rbrakk>\n    }\n    Q: (\\<^sup>0\\<lbrakk>X\\<rbrakk> \\<and> (\\<^sup>aS \\<longrightarrow> \\<^sup>0\\<^bold>r(0 :: nat) \\<and> \\<^sup>0\\<^bold>r1))\n  FNEND\" \n  apply (unfold fn_valid.simps, intro conjI)\n\n  (* Stability of Q *)\n  apply (auto simp: glb_def step\\<^sub>t_def stable_def)[1]\n\n  (* Wellformedness of R & G *)\n  apply (auto simp: transitive_def reflexive_def)[3]\n\n  (* Guarantees of each atomic action *)\n  apply (auto simp: wp\\<^sub>r_def st_upd_def step_def glb_def aux_upd_def)[1]\n\n  (* WP *)\n  apply simp\n  apply (clarsimp simp: stabilize_def st_upd_def glb_def aux_upd_def rg_def)\n  apply (meson less_numeral_extra(3))\n\n  (* RIF *)\n  apply rif_eval\n  apply (clarsimp simp: expand_points_def checks_def, unfold chk_def)\n  apply (intro allI conjI impI)\n  apply (auto simp: guar_def st_upd_def step_def glb_def aux_upd_def liftg_def)[1]\n  apply (rule wp_split[where ?f=\"\\<lambda>a b. b(Glb T :=\\<^sub>s st a (Glb T), Reg 1 :=\\<^sub>s st a (Reg 1))\"]; clarsimp simp: step\\<^sub>t_def)\n  apply (intro conjI impI state_eq; clarsimp simp add: glb_def; metis rg_def)\n  by (intro conjI impI state_eq; clarsimp simp add: glb_def)\n\nlemma thread1:\n  \"FNBEGIN\n    R: (\\<^sup>1\\<lbrakk>Y\\<rbrakk> \\<longrightarrow> \\<^sup>1\\<^sup>aS \\<longrightarrow> \\<^sup>2\\<^sup>aS) \\<and> \\<^sup>1\\<lbrakk>Y\\<rbrakk> = \\<^sup>2\\<lbrakk>Y\\<rbrakk> \\<and> (\\<^sup>2\\<lbrakk>T\\<rbrakk> = \\<^sup>1\\<lbrakk>T\\<rbrakk> \\<or> (\\<not>\\<^sup>1\\<lbrakk>T\\<rbrakk> \\<and> \\<^sup>2\\<lbrakk>T\\<rbrakk> \\<and> (\\<^sup>1\\<lbrakk>Y\\<rbrakk> \\<longrightarrow> \\<^sup>2\\<^sup>aS)))\n    G: (\\<^sup>1\\<lbrakk>X\\<rbrakk> \\<longrightarrow> \\<^sup>2\\<^sup>aS \\<longrightarrow> \\<^sup>1\\<^sup>aS) \\<and> \\<^sup>1\\<lbrakk>X\\<rbrakk> = \\<^sup>2\\<lbrakk>X\\<rbrakk> \\<and> (\\<^sup>2\\<lbrakk>T\\<rbrakk> = \\<^sup>1\\<lbrakk>T\\<rbrakk> \\<or> (\\<^sup>1\\<lbrakk>T\\<rbrakk> \\<and> \\<not> \\<^sup>2\\<lbrakk>T\\<rbrakk> \\<and> (\\<^sup>1\\<lbrakk>X\\<rbrakk> \\<longrightarrow> \\<not>\\<^sup>2\\<^sup>aS)))\n    P: True\n    {\n      \\<lbrakk>Y\\<rbrakk> := #True;\n      fence;\n      \\<lbrakk>T\\<rbrakk> := #False :\\<^sub>a \\<^sup>aS := False;\n      fence;\n      \\<^bold>r0 := \\<lbrakk>X\\<rbrakk> :\\<^sub>a \\<^sup>aS := (\\<^sup>aS \\<or> \\<not>\\<^sup>0\\<lbrakk>X\\<rbrakk>);\n      \\<^bold>r1 := (!\\<lbrakk>T\\<rbrakk>)\n    }\n    Q: (\\<^sup>0\\<lbrakk>Y\\<rbrakk> \\<and> (\\<not>\\<^sup>aS \\<longrightarrow> \\<^sup>0\\<^bold>r(0 :: nat) \\<and> \\<^sup>0\\<^bold>r1))\n  FNEND\" \n  apply (unfold fn_valid.simps, intro conjI)\n\n  (* Stability of Q *)\n  apply (auto simp: glb_def step\\<^sub>t_def stable_def)[1]\n\n  (* Wellformedness of R & G *)\n  apply (auto simp: transitive_def reflexive_def)[3]\n\n  (* Guarantees of each atomic action *)\n  apply (auto simp: wp\\<^sub>r_def st_upd_def step_def glb_def aux_upd_def)[1]\n\n  (* WP *)\n  apply simp\n  apply (clarsimp simp: stabilize_def st_upd_def glb_def aux_upd_def rg_def c_neg_def)\n  apply (intro conjI impI)\n  prefer 2\n  apply (meson less_numeral_extra(3))\n  apply auto[1]\n\n  (* RIF *)\n  apply rif_eval\n  apply (clarsimp simp: expand_points_def checks_def, unfold chk_def)\n  apply (intro allI conjI impI)\n  apply (auto simp: guar_def st_upd_def step_def glb_def aux_upd_def liftg_def)[1]\n  apply (rule wp_split[where ?f=\"\\<lambda>a b. b(Glb T :=\\<^sub>s st a (Glb T), Reg 1 :=\\<^sub>s st a (Reg 1))\"]; clarsimp simp: c_neg_def step\\<^sub>t_def)\n  apply (intro conjI impI state_eq; clarsimp simp add: glb_def; metis rg_def)\n  by (intro conjI impI state_eq; clarsimp simp add: glb_def)\n\nend", "meta": {"author": "UQ-PAC", "repo": "wmm-rg", "sha": "7eef2f42693cb0723a9a7a75cd7cd6f73f9bdfb2", "save_path": "github-repos/isabelle/UQ-PAC-wmm-rg", "path": "github-repos/isabelle/UQ-PAC-wmm-rg/wmm-rg-7eef2f42693cb0723a9a7a75cd7cd6f73f9bdfb2/SimAsm/Examples/PetersonLitmus.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5774953797290153, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.2506222908122817}}
{"text": "section\\<open>Network Security Policy Verification\\<close>\ntheory Network_Security_Policy_Verification\nimports\n  TopoS_Interface\n  TopoS_Interface_impl\n  TopoS_Library\n  TopoS_Composition_Theory\n  TopoS_Stateful_Policy\n  TopoS_Composition_Theory_impl\n  TopoS_Stateful_Policy_Algorithm\n  TopoS_Stateful_Policy_impl\n  TopoS_Impl\nbegin\n\n\n\nsection\\<open>A small Tutorial\\<close>\n\ntext\\<open>We demonstrate usage of the executable theory.\\<close>\ntext\\<open>Everything that is indented and starts with `Interlude:' summarizes the main correctness proofs and can be skipped if only the implementation is concerned\\<close>\n\nsubsection\\<open>Policy\\<close>\ntext\\<open>The secuity policy is a directed graph.\\<close>\ndefinition policy :: \"nat list_graph\" where\n    \"policy \\<equiv> \\<lparr> nodesL = [1,2,3],\n                edgesL = [(1,2), (2,2), (2,3)] \\<rparr>\"\n\ntext\\<open>It is syntactically well-formed\\<close>\nlemma wf_list_graph_policy: \"wf_list_graph policy\" by eval\n\ntext\\<open>In contrast, this is not a syntactically well-formed graph.\\<close>\nlemma \"\\<not> wf_list_graph \\<lparr> nodesL = [1,2]::nat list, edgesL = [(1,2), (2,2), (2,3)] \\<rparr>\" by eval\n\ntext\\<open>Our @{const policy} has three rules.\\<close>\nlemma \"length (edgesL policy) = 3\" by eval\n\nsubsection\\<open>Security Invariants\\<close>\ntext\\<open>We construct a security invariant. Node @{term \"2::nat\"} has confidential data\\<close>\n\ndefinition BLP_security_levels :: \"nat \\<rightharpoonup> SINVAR_BLPtrusted.node_config\"where\n  \"BLP_security_levels \\<equiv> [2 \\<mapsto> \\<lparr> security_level = 1, trusted = False \\<rparr>]\"\n\ndefinition BLP_m::\"(nat SecurityInvariant)\" where\n    \"BLP_m \\<equiv> new_configured_list_SecurityInvariant SINVAR_LIB_BLPtrusted \\<lparr> \n          node_properties = BLP_security_levels\n          \\<rparr> ''Two has confidential information''\"\n\n\n  text\\<open>Interlude: @{const BLP_m} is a valid implementation of a SecurityInvariant\\<close>\n  definition BLP_m_spec :: \"nat SecurityInvariant_configured option\"where\n    \"BLP_m_spec \\<equiv> new_configured_SecurityInvariant (\n        SINVAR_BLPtrusted.sinvar,\n        SINVAR_BLPtrusted.default_node_properties,\n        SINVAR_BLPtrusted.receiver_violation,\n        SecurityInvariant.node_props SINVAR_BLPtrusted.default_node_properties \\<lparr> \n          node_properties = BLP_security_levels\n        \\<rparr>)\"\n  text\\<open>Fist, we need to show that the formal definition obeys all requirements, @{const new_configured_SecurityInvariant} verifies this. To double check, we manually give the configuration.\\<close>\n  lemma BLP_m_spec: assumes \"nP = (\\<lambda> v. (case BLP_security_levels v of Some c \\<Rightarrow> c | None \\<Rightarrow> SINVAR_BLPtrusted.default_node_properties))\"\n      shows \"BLP_m_spec = Some \\<lparr> \n              c_sinvar = (\\<lambda>G. SINVAR_BLPtrusted.sinvar G nP),\n              c_offending_flows = (\\<lambda>G. SecurityInvariant_withOffendingFlows.set_offending_flows SINVAR_BLPtrusted.sinvar G nP),\n              c_isIFS = SINVAR_BLPtrusted.receiver_violation\n            \\<rparr>\" (is \"BLP_m_spec = Some ?Spec\")\n  proof - \n    have NetModelLib: \"TopoS_modelLibrary SINVAR_LIB_BLPtrusted SINVAR_BLPtrusted.sinvar\"\n    by(unfold_locales)\n    from assms have nP: \"nP = nm_node_props SINVAR_LIB_BLPtrusted \\<lparr> \n              node_properties = BLP_security_levels\n            \\<rparr>\" by(simp add: fun_eq_iff SINVAR_LIB_BLPtrusted_def SINVAR_BLPtrusted_impl.NetModel_node_props_def)\n  \n    have \"BLP_m_spec = new_configured_SecurityInvariant (SINVAR_BLPtrusted.sinvar, SINVAR_BLPtrusted.default_node_properties, SINVAR_BLPtrusted.receiver_violation, nP)\"\n    unfolding BLP_m_spec_def nP by(simp add: SINVAR_BLPtrusted_impl.NetModel_node_props_def SINVAR_LIB_BLPtrusted_def)\n    also with TopoS_modelLibrary_yields_new_configured_SecurityInvariant[OF NetModelLib nP]\n    have \"\\<dots> = Some ?Spec\" by (simp add: SINVAR_LIB_BLPtrusted_def)\n    finally show ?thesis by blast\n  qed\n  lemma valid_reqs_BLP: \"valid_reqs [the BLP_m_spec]\"\n    by(simp add: valid_reqs_def)(metis BLP_m_spec_def BLPtrusted_impl.spec new_configured_SecurityInvariant.simps new_configured_SecurityInvariant_sound option.distinct(1) option.exhaust_sel)\n\n\n  text\\<open>Interlude: While @{const BLP_m} is executable code, we will now show that this executable code complies with its formal definition.\\<close>\n  lemma complies_BLP: \"SecurityInvariant_complies_formal_def BLP_m (the BLP_m_spec)\"\n    unfolding BLP_m_def\n    apply(rule new_configured_list_SecurityInvariant_complies)\n       apply(simp_all add: BLP_m_spec_def)\n     apply(unfold_locales)\n    by(simp add: fun_eq_iff SINVAR_LIB_BLPtrusted_def SINVAR_BLPtrusted_impl.NetModel_node_props_def)\n\n\n\ntext\\<open>We define the list of all security invariants of type @{typ \"nat SecurityInvariant list\"}.\n     The type @{typ nat} is because the policy's nodes are of type @{typ nat}.\\<close>\ndefinition \"security_invariants = [BLP_m]\"\n\n\ntext\\<open>We can see that the policy does not fulfill the security invariants.\\<close>\nlemma \"\\<not> all_security_requirements_fulfilled security_invariants policy\" by eval\n\ntext\\<open>We ask why. Obviously, node 2 leaks confidential data to node 3.\\<close>\nvalue \"implc_get_offending_flows security_invariants policy\"\nlemma \"implc_get_offending_flows security_invariants policy = [[(2, 3)]]\" by eval\n\n  text\\<open>Interlude: the implementation @{const implc_get_offending_flows} corresponds to the formal definition @{const get_offending_flows}\\<close>\n  lemma \"set ` set (implc_get_offending_flows (get_impl [(BLP_m, the BLP_m_spec)]) policy) = get_offending_flows (get_spec [(BLP_m, the BLP_m_spec)]) (list_graph_to_graph policy)\"\n  apply(rule implc_get_offending_flows_complies)\n   by(simp_all add: complies_BLP wf_list_graph_policy)\n  \n\ntext\\<open>\nVisualization of the violation (only in interactive mode)\n\\<close>\nML_val\\<open>\nvisualize_graph @{context} @{term \"security_invariants\"} @{term \"policy\"};\n\\<close>\n\ntext\\<open>Experimental: the config (only one) can be added to the end.\\<close>\nML_val\\<open>\nvisualize_graph_header @{context} @{term \"security_invariants\"} @{term \"policy\"} @{term \"BLP_security_levels\"};\n\\<close>\n\n\ntext\\<open>\nThe policy has a flaw. We throw it away and generate a new one which fulfills the invariants.\n\\<close>\ndefinition \"max_policy = generate_valid_topology security_invariants \\<lparr>nodesL = nodesL policy, edgesL = List.product (nodesL policy) (nodesL policy) \\<rparr>\"\n\n  text\\<open>Interlude: the implementation @{const implc_get_offending_flows} corresponds to the formal definition @{const get_offending_flows}\\<close>\n  thm generate_valid_topology_complies\n\n  text\\<open>Interlude: the formal definition is sound\\<close>\n  thm generate_valid_topology_sound\n\n  text\\<open>Here, it is also complete\\<close>\n  lemma \"wf_graph G \\<Longrightarrow> max_topo [the BLP_m_spec] (TopoS_Composition_Theory.generate_valid_topology [the BLP_m_spec] (fully_connected G))\"\n  apply(rule generate_valid_topology_max_topo[OF valid_reqs_BLP])\n   apply(assumption)\n  apply(simp add: BLP_m_spec)\n  by blast\n\n\ntext\\<open>Calculating the maximum policy\\<close>\nvalue \"max_policy\"\nlemma \"max_policy = \\<lparr>nodesL = [1, 2, 3], edgesL = [(1, 1), (1, 2), (1, 3), (2, 2), (3, 1), (3, 2), (3, 3)]\\<rparr>\" by eval\n\n\ntext\\<open>\nVisualizing the maximum policy (only in interactive mode)\n\\<close>\nML\\<open>\nvisualize_graph @{context} @{term \"security_invariants\"} @{term \"max_policy\"};\n\\<close>\n\ntext\\<open>Of course, all security invariants hold for the maximum policy.\\<close>\nlemma \"all_security_requirements_fulfilled security_invariants max_policy\" by eval\n\n\nsubsection\\<open>A stateful implementation\\<close>\ntext\\<open>We generate a stateful policy\\<close>\ndefinition \"stateful_policy = generate_valid_stateful_policy_IFSACS_2 policy security_invariants\"\n\ntext\\<open>When thinking about it carefully, no flow can be stateful without introducing an information leakage here!\\<close>\nvalue \"stateful_policy\"\nlemma \"stateful_policy = \\<lparr>hostsL = [1, 2, 3], flows_fixL = [(1, 2), (2, 2), (2, 3)], flows_stateL = []\\<rparr>\" by eval\n\n  text\\<open>Interlude: the stateful policy we are computing fulfills all the necessary properties\\<close>\n  thm generate_valid_stateful_policy_IFSACS_2_complies\n\n  (*the individual algorithms fir IFS/ACS return a maximum policy*)\n  thm filter_compliant_stateful_ACS_correct filter_compliant_stateful_ACS_maximal\n  thm filter_IFS_no_violations_correct filter_IFS_no_violations_maximal\n\ntext\\<open>\nVisualizing the stateful policy (only in interactive mode)\n\\<close>\nML_val\\<open>\nvisualize_edges @{context} @{term \"flows_fixL stateful_policy\"} \n    [(\"edge [dir=\\\"arrow\\\", style=dashed, color=\\\"#FF8822\\\", constraint=false]\", @{term \"flows_stateL stateful_policy\"})] \"\"; \n\\<close>\n\n\ntext\\<open>This is how it would look like if @{term \"(3,1)\"} were a stateful flow\\<close>\nML_val\\<open>\nvisualize_edges @{context} @{term \"flows_fixL stateful_policy\"} \n    [(\"edge [dir=\\\"arrow\\\", style=dashed, color=\\\"#FF8822\\\", constraint=false]\", @{term \"[(3::nat,1::nat)]\"})] \"\"; \n\\<close>\n\n\nhide_const policy security_invariants max_policy stateful_policy\n\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Network_Security_Policy_Verification/Network_Security_Policy_Verification.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.577495350642608, "lm_q2_score": 0.43398146480389854, "lm_q1q2_score": 0.25062227818932004}}
{"text": "section \\<open>Instantiate CFG locale with While CFG\\<close>\n\ntheory Interpretation imports \n  WCFG \n  \"../Basic/CFGExit\" \nbegin\n\nsubsection \\<open>Instatiation of the \\<open>CFG\\<close> locale\\<close>\n\nabbreviation sourcenode :: \"w_edge \\<Rightarrow> w_node\"\n  where \"sourcenode e \\<equiv> fst e\"\n\nabbreviation targetnode :: \"w_edge \\<Rightarrow> w_node\"\n  where \"targetnode e \\<equiv> snd(snd e)\"\n\nabbreviation kind :: \"w_edge \\<Rightarrow> state edge_kind\"\n  where \"kind e \\<equiv> fst(snd e)\"\n\n\ndefinition valid_edge :: \"cmd \\<Rightarrow> w_edge \\<Rightarrow> bool\"\n  where \"valid_edge prog a \\<equiv> prog \\<turnstile> sourcenode a -kind a\\<rightarrow> targetnode a\"\n\ndefinition valid_node ::\"cmd \\<Rightarrow> w_node \\<Rightarrow> bool\"\n  where \"valid_node prog n \\<equiv> \n    (\\<exists>a. valid_edge prog a \\<and> (n = sourcenode a \\<or> n = targetnode a))\"\n\n\nlemma While_CFG_aux:\n  \"CFG sourcenode targetnode (valid_edge prog) Entry\"\nproof(unfold_locales)\n  fix a assume \"valid_edge prog a\" and \"targetnode a = (_Entry_)\"\n  obtain nx et nx' where \"a = (nx,et,nx')\" by (cases a) auto\n  with \\<open>valid_edge prog a\\<close> \\<open>targetnode a = (_Entry_)\\<close> \n  have \"prog \\<turnstile> nx -et\\<rightarrow> (_Entry_)\" by(simp add:valid_edge_def)\n  thus False by fastforce\nnext\n  fix a a'\n  assume assms:\"valid_edge prog a\" \"valid_edge prog a'\"\n    \"sourcenode a = sourcenode a'\" \"targetnode a = targetnode a'\"\n  obtain x et y where [simp]:\"a = (x,et,y)\" by (cases a) auto\n  obtain x' et' y' where [simp]:\"a' = (x',et',y')\" by (cases a') auto\n  from assms have \"et = et'\"\n    by(fastforce intro:WCFG_edge_det simp:valid_edge_def)\n  with \\<open>sourcenode a = sourcenode a'\\<close> \\<open>targetnode a = targetnode a'\\<close>\n  show \"a = a'\" by simp\nqed\n\ninterpretation While_CFG:\n  CFG sourcenode targetnode kind \"valid_edge prog\" Entry\n  for prog\n  by(rule While_CFG_aux)\n\n\nlemma While_CFGExit_aux:\n  \"CFGExit sourcenode targetnode kind (valid_edge prog) Entry Exit\"\nproof(unfold_locales)\n  fix a assume \"valid_edge prog a\" and \"sourcenode a = (_Exit_)\"\n  obtain nx et nx' where \"a = (nx,et,nx')\" by (cases a) auto\n  with \\<open>valid_edge prog a\\<close> \\<open>sourcenode a = (_Exit_)\\<close> \n  have \"prog \\<turnstile> (_Exit_) -et\\<rightarrow> nx'\" by(simp add:valid_edge_def)\n  thus False by fastforce\nnext\n  have \"prog \\<turnstile> (_Entry_) -(\\<lambda>s. False)\\<^sub>\\<surd>\\<rightarrow> (_Exit_)\" by(rule WCFG_Entry_Exit)\n  thus \"\\<exists>a. valid_edge prog a \\<and> sourcenode a = (_Entry_) \\<and>\n            targetnode a = (_Exit_) \\<and> kind a = (\\<lambda>s. False)\\<^sub>\\<surd>\"\n    by(fastforce simp:valid_edge_def)\nqed\n\ninterpretation While_CFGExit:\n  CFGExit sourcenode targetnode kind \"valid_edge prog\" Entry Exit\n  for prog\nby(rule While_CFGExit_aux)\n\nend\n", "meta": {"author": "data61", "repo": "PSL", "sha": "2a71eac0db39ad490fe4921a5ce1e4344dc43b12", "save_path": "github-repos/isabelle/data61-PSL", "path": "github-repos/isabelle/data61-PSL/PSL-2a71eac0db39ad490fe4921a5ce1e4344dc43b12/SeLFiE/Example/afp-2020-05-16/thys/Slicing/While/Interpretation.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5389832354982647, "lm_q2_score": 0.46490157137338844, "lm_q1q2_score": 0.25057415312705633}}
{"text": "(*\n  This file contains the update semantics to C correspondence lemmas for word array functions\n*)\ntheory SumRandom_UpdCCorres\n  imports SumRandom_UAbsFun\nbegin\n\ncontext SumRandom begin\n\nsection \"Correspondence Lemmas Between Update Semantics and C\"\n\nsubsection \"random_seed\"\nthm update_sem_init.abs_rel_def\nthm afun_corres abs_rel_def\n\nthm \\<Xi>_def\nlemma  (in update_sem_init) abs_rel_def':\n  \"abs_rel \\<Xi>' srel afun_name \\<xi>' afun_mon\n    = (\\<forall>\\<sigma> st x x' r' w'. (\\<sigma>, st) \\<in> srel \\<and> val_rel x x'\n        \\<and> \\<Xi>', \\<sigma> \\<turnstile> x :u fst (snd (\\<Xi>' afun_name)) \\<langle>r', w'\\<rangle>\n        \\<longrightarrow> \\<lbrace>\\<lambda>s0. s0 = st\\<rbrace> \n              afun_mon x' \n            \\<lbrace>\\<lambda>y' s'. \\<exists>\\<sigma>' y. \\<xi>' afun_name (\\<sigma>, x) (\\<sigma>', y) \\<and> (\\<sigma>',s') \\<in> srel \\<and> val_rel y y'\\<rbrace>!)\" \n  by (fastforce  simp: abs_rel_def validNF_def valid_def no_fail_def)\nfind_theorems name:\"rand'_\"\nthm random_aux_Seed_C_def\nterm rand'\nthm rand_with_seed'_def\n\nlemma \"\\<lbrace> \\<lambda>s. True \\<rbrace> rand' \\<lbrace>\\<lambda>r s. True\\<rbrace>!\" oops\nlemma rand_with_seed_C_spec:\n  \"\\<lbrace>\\<lambda>h. True \\<rbrace> \n    rand_with_seed' x' \n   \\<lbrace>\\<lambda>r h'. True \\<rbrace>!\" \n  unfolding rand_with_seed'_def\n  apply wp \n  sorry\n\nlemma rand_with_seed_abs_rel_0 : \n  \"abs_rel \\<Xi> state_rel ''rand_with_seed'' \\<xi>u0 rand_with_seed'\"\n  apply (clarsimp simp add: abs_rel_def'  )\n\n  apply wpsimp\n  sorry\nlemma rand_with_seed_corres_i: \n\"(\\<And>i \\<gamma> v' \\<Gamma>' \\<sigma> st.\n        i < length \\<gamma> \\<Longrightarrow>\n        val_rel (\\<gamma> ! i) v' \\<Longrightarrow>\n        \\<Gamma>' ! i = Some (fst (snd Random_seed_master_TypeProof.rand_with_seed_type)) \\<Longrightarrow>\n        update_sem_init.corres seed_abs_typing_u seed_abs_repr state_rel\n         (App (AFun ''rand_with_seed'' []) (Var i)) \n         (do x <- rand_with_seed' v';\n               gets (\\<lambda>s. x)\n         od)\n         \\<xi>ui \\<gamma>\n         \\<Xi>\n         \\<Gamma>' \\<sigma> st)\"\n  apply (rule afun_corres)\n     apply (simp add: abs_rel_def \\<Xi>_def)\n     apply clarsimp\n     apply safe\n  \n\n\n\n\nlemma rand_with_seed_corres:\n  \"\\<And>i \\<gamma> v' \\<Gamma>' \\<sigma> st.\n      \\<lbrakk> i < length \\<gamma>; \n        val_rel (\\<gamma> ! i) v'; \n        \\<Gamma>' ! i = option.Some (prod.fst (prod.snd (\\<Xi> ''random_with_seed'')));\n        \\<xi>u ''random_with_seed''= rand_with_seed_u\\<rbrakk> \\<Longrightarrow> \n       update_sem_init.corres \n          seed_abs_typing_u \n          seed_abs_repr \n          state_rel\n          (App (AFun ''random_with_seed'' []) (Var i))\n          (do x <- random_seed_master_pp_inferred.rand_with_seed' v';\n             gets (\\<lambda>s. x)\n           od)\n         \\<xi>0' \\<gamma> \\<Xi> \\<Gamma>' \\<sigma> st\n          \"\n  apply (rule afun_corres)\n\nlemma upd_C_wordarray_put2_corres_gen:\n  \"\\<And>i \\<gamma> v' \\<Gamma>' \\<sigma> st.\n    \\<lbrakk>i < length \\<gamma>; val_rel (\\<gamma> ! i) v'; \\<Gamma>' ! i = option.Some (prod.fst (prod.snd (\\<Xi> ''wordarray_put2_0'')));\n     \\<xi>0' ''wordarray_put2_0'' = upd_wa_put2_0\\<rbrakk>\n    \\<Longrightarrow> update_sem_init.corres wa_abs_typing_u wa_abs_repr (Generated.state_rel wa_abs_repr) (App (AFun ''wordarray_put2_0'' []) (Var i))\n         (do x <- main_pp_inferred.wordarray_put2_0' v';\n             gets (\\<lambda>s. x)\n          od)\n         \\<xi>0' \\<gamma> \\<Xi> \\<Gamma>' \\<sigma> st\"\n  apply (rule absfun_corres; simp?)\n  apply (thin_tac \"\\<Gamma>' ! i = _\")\n  apply (clarsimp simp: abs_fun_rel_def; rename_tac r w)\n  apply (rotate_tac -1)\n  apply (subst (asm) \\<Xi>_def)\n  apply (subst (asm) \\<Xi>_def)\n  apply (clarsimp simp: val_rel_simp wordarray_put2_0_type_def abbreviated_type_defs)\n  apply (erule upd.u_t_recE)\n  apply (erule upd.u_t_r_consE; clarsimp)+\n  apply (erule upd.u_t_primE)+\n  apply (subst (asm) lit_type.simps)+\n  apply clarsimp\n  apply (erule upd.u_t_r_emptyE)\n  apply (erule upd.u_t_p_absE; simp)\n  apply (frule wa_abs_typing_u_elims(1); clarsimp; rename_tac len arr)\n  apply (rule conjI)\n   apply (monad_eq simp: wordarray_put2_0'_def)\n   apply (clarsimp simp: state_rel_def heap_rel_def)\n   apply (erule_tac x = \"t2_C.arr_C v'\" in allE)\n   apply (erule_tac x = \"values_C (heap_WordArray_u32_C st (t2_C.arr_C v')) +\\<^sub>p uint (t2_C.idx_C v')\" in allE)\n   apply (clarsimp simp: heap_rel_ptr_def heap_rel_ptr_w32_def wa_abs_repr_def is_valid_simp type_rel_simp)\n   apply (frule wa_abs_typing_u_elims(5))\n   apply (erule_tac x = \"t2_C.idx_C v'\" in allE)+\n   apply (clarsimp simp: val_rel_simp heap_simp type_rel_simp)\n  apply clarsimp\n  apply (monad_eq simp: upd_wa_put2_0_def)\n  apply (case_tac \"idx_C v' < len\"; clarsimp)\n  apply (rule conjI)\n    apply (monad_eq simp: wordarray_put2_0'_def)\n   apply (clarsimp simp: state_rel_def heap_rel_def heap_rel_ptr_meta heap_rel_ptr_w32_meta)\n   apply (monad_eq simp: wordarray_put2_0'_def)\n   apply (frule_tac p = \"t2_C.arr_C v'\" in all_heap_rel_ptrD; simp?)\n    apply (clarsimp simp: type_rel_simp wa_abs_repr_def)\n   apply (clarsimp simp: val_rel_simp heap_simp is_valid_simp)\n   apply (drule wa_abs_typing_u_elims(5))\n   apply (erule_tac x = \"t2_C.idx_C v'\" in allE; clarsimp)\n   apply (drule_tac upd_h = \"(heap_w32_update \n      (\\<lambda>x. x(values_C (heap_WordArray_u32_C st (t2_C.arr_C v')) +\\<^sub>p uint (idx_C v') := val_C v')) st)\" and\n      x = \"(values_C (heap_WordArray_u32_C st (t2_C.arr_C v'))) +\\<^sub>p uint (idx_C v')\" and\n      uv' = \"UPrim (LU32 (val_C v'))\" and uv = \"UPrim x\"\n      in all_heap_rel_updE; simp?; clarsimp?)\n    apply (clarsimp simp: type_rel_simp)\n   apply (drule_tac upd_h = \"(heap_w32_update\n      (\\<lambda>x. x(values_C (heap_WordArray_u32_C st (t2_C.arr_C v')) +\\<^sub>p uint (idx_C v') := val_C v')) st)\" and\n      x = \"(values_C (heap_WordArray_u32_C st (t2_C.arr_C v'))) +\\<^sub>p uint (idx_C v')\" and\n      uv' = \"UPrim (LU32 (val_C v'))\" and uv = \"UPrim x\"\n      in all_heap_rel_updE; simp?; clarsimp?)\n   apply (rule conjI, clarsimp simp: val_rel_simp)\n   apply clarsimp\n   apply (rule FalseE)\n   apply (cut_tac p = p and q = \"((values_C (heap_WordArray_u32_C st (t2_C.arr_C v'))) +\\<^sub>p uint (idx_C v'))\" in ptr_val_inj)\n   apply (clarsimp simp: ptr_add_def)\n  apply (monad_eq simp: wordarray_put2_0'_def)\n  apply (clarsimp simp: state_rel_def heap_rel_def heap_rel_ptr_meta)\n  apply (frule_tac p = \"t2_C.arr_C v'\" in all_heap_rel_ptrD; simp?)\n   apply (clarsimp simp: type_rel_simp wa_abs_repr_def)\n  apply (clarsimp simp: val_rel_simp heap_simp is_valid_simp)\n  done\n\nlemmas upd_C_wordarray_put2_corres = upd_C_wordarray_put2_corres_gen[rotated -1, of \\<xi>0, simplified fun_eq_iff]\n\nsubsection \"wordarray_length\"\n\nlemma upd_C_wordarray_length_corres_gen:\n\"\\<And>i \\<gamma> v' \\<Gamma>' \\<sigma> st.\n    \\<lbrakk>i < length \\<gamma>; val_rel (\\<gamma> ! i) v'; \\<Gamma>' ! i = option.Some (prod.fst (prod.snd (\\<Xi> ''wordarray_length_0'')));\n     \\<xi>0' ''wordarray_length_0''= upd_wa_length_0\\<rbrakk>\n    \\<Longrightarrow> update_sem_init.corres wa_abs_typing_u wa_abs_repr (Generated.state_rel wa_abs_repr) (App (AFun ''wordarray_length_0'' []) (Var i))\n         (do x <- main_pp_inferred.wordarray_length_0' v';\n             gets (\\<lambda>s. x)\n          od)\n         \\<xi>0' \\<gamma> \\<Xi> \\<Gamma>' \\<sigma> st\"\n  apply (rule absfun_corres; simp?)\n  apply (clarsimp simp: abs_fun_rel_def; rename_tac r w)\n  apply (thin_tac \"\\<Gamma>' ! i = _\")\n  apply (rotate_tac -1)\n  apply (subst (asm) \\<Xi>_def)\n  apply (subst (asm) \\<Xi>_def)\n  apply (clarsimp simp: val_rel_simp wordarray_length_0_type_def)\n  apply (erule upd.u_t_p_absE; simp)\n  apply (frule wa_abs_typing_u_elims(1); clarsimp; rename_tac len arr)\n  apply (rule conjI)\n   apply (monad_eq simp: wordarray_length_0'_def)\n   apply (clarsimp simp: state_rel_def heap_rel_def)\n   apply (erule_tac x = v' in allE)\n   apply (clarsimp simp: heap_rel_ptr_def type_rel_simp wa_abs_repr_def is_valid_simp)\n  apply clarsimp\n  apply (rule_tac x = \\<sigma> in exI)\n  apply (rule conjI)\n   apply (clarsimp simp: upd_wa_length_0_def)\n   apply (monad_eq simp: wordarray_length_0'_def)\n   apply (clarsimp simp: state_rel_def heap_rel_def)\n   apply (erule_tac x = v' in allE)\n   apply (clarsimp simp: heap_rel_ptr_def type_rel_simp wa_abs_repr_def heap_simp val_rel_simp)\n  apply (monad_eq simp: wordarray_length_0'_def)\n  done\n\nlemmas upd_C_wordarray_length_corres = upd_C_wordarray_length_corres_gen[rotated -1, of \\<xi>0, simplified fun_eq_iff]\n\nsubsection \"wordarray_get\"\n\nlemma upd_C_wordarray_get_corres_gen:\n\"\\<And>i \\<gamma> v' \\<Gamma>' \\<sigma> st.\n    \\<lbrakk>i < length \\<gamma>; val_rel (\\<gamma> ! i) v'; \\<Gamma>' ! i = option.Some (prod.fst (prod.snd (\\<Xi> ''wordarray_get_0'')));\n     \\<xi>0' ''wordarray_get_0'' = upd_wa_get_0\\<rbrakk>\n    \\<Longrightarrow> update_sem_init.corres wa_abs_typing_u wa_abs_repr (Generated.state_rel wa_abs_repr) (App (AFun ''wordarray_get_0'' []) (Var i))\n         (do x <- main_pp_inferred.wordarray_get_0' v';\n             gets (\\<lambda>s. x)\n          od)\n         \\<xi>0' \\<gamma> \\<Xi> \\<Gamma>' \\<sigma> st\"\n  apply (rule absfun_corres; simp?)\n  apply (clarsimp simp: abs_fun_rel_def; rename_tac r w)\n  apply (thin_tac \"\\<Gamma>' ! i = _\")\n  apply (rotate_tac -1)\n  apply (subst (asm) \\<Xi>_def)\n  apply (subst (asm) \\<Xi>_def)\n  apply (clarsimp simp: val_rel_simp wordarray_get_0_type_def abbreviated_type_defs)\n  apply (erule upd.u_t_recE)\n  apply (erule upd.u_t_r_consE; clarsimp)+\n  apply (erule upd.u_t_r_emptyE)\n  apply (erule upd.u_t_primE; subst (asm) lit_type.simps; clarsimp)\n  apply (erule upd.u_t_p_absE; simp)\n  apply (frule wa_abs_typing_u_elims(1); clarsimp; rename_tac len arr)\n  apply (rule conjI)\n   apply (monad_eq simp: wordarray_get_0'_def)\n   apply (clarsimp simp: state_rel_def heap_rel_def heap_rel_ptr_meta heap_rel_ptr_w32_meta)\n   apply (drule_tac p = \"t1_C.p1_C v'\" and uv = \"UAbstract (UWA (TPrim (Num U32)) len arr)\" in all_heap_rel_ptrD; \n          clarsimp simp: type_rel_simp wa_abs_repr_def val_rel_simp is_valid_simp heap_simp)\n   apply (drule not_le_imp_less)\n   apply (frule wa_abs_typing_u_elims(5))\n   apply (erule_tac x = \"t1_C.p2_C v'\" in allE; clarsimp)\n   apply (drule_tac p = \"values_C (heap_WordArray_u32_C st (t1_C.p1_C v')) +\\<^sub>p uint (t1_C.p2_C v')\" and\n                   uv = \"UPrim x\" in all_heap_rel_ptrD; simp add: type_rel_simp)\n  apply clarsimp\n  apply (rule_tac x = \\<sigma> in exI)\n  apply (rule conjI)\n   apply (clarsimp simp: upd_wa_get_0_def)\n   apply (frule wa_abs_typing_u_elims(5))\n   apply (erule_tac x = \"t1_C.p2_C v'\" in allE)\n   apply (monad_eq simp: wordarray_get_0'_def word_less_nat_alt word_le_nat_alt)\n   apply (clarsimp simp: state_rel_def heap_rel_def heap_rel_ptr_meta heap_rel_ptr_w32_meta)\n   apply (drule_tac p = \"t1_C.p1_C v'\" and uv = \"UAbstract (UWA (TPrim (Num U32)) len arr)\" in all_heap_rel_ptrD; \n          clarsimp simp: type_rel_simp wa_abs_repr_def val_rel_simp is_valid_simp heap_simp)\n   apply (drule_tac p = \"values_C (heap_WordArray_u32_C st (t1_C.p1_C v')) +\\<^sub>p uint (t1_C.p2_C v')\" and\n                   uv = \"UPrim x\" in all_heap_rel_ptrD;\n          clarsimp simp: type_rel_simp val_rel_simp)\n  apply (monad_eq simp: wordarray_get_0'_def)\n  apply blast\n  done\n\nlemmas upd_C_wordarray_get_corres = upd_C_wordarray_get_corres_gen[rotated -1, of \\<xi>0, simplified fun_eq_iff]\n\nsubsection \"Helper lemmas, definitions and abbreviations for second order abstract functions\"\n\nabbreviation \"elem_type x \\<equiv> (present_type \\<circ> (\\<lambda>xs. xs ! 0) \\<circ> rec_type_list) x\"\nabbreviation \"mk_urecord xs \\<equiv> URecord (map (\\<lambda>x. (x, upd.uval_repr x)) xs)\"\n\ndefinition \"foldmap_measure i end \\<equiv> unat end - unat i\"\ndefinition \"foldmap_bounds frm to len i e \n  \\<equiv> frm \\<le> i \\<and> e = min to len \\<and> (frm < e \\<longrightarrow> i \\<le> e) \\<and> ((\\<not>(frm < e)) \\<longrightarrow> frm = i)\"\ndefinition \"foldmap_inv foldmap \\<xi>' \\<sigma> p frm i f acc obsv r \\<sigma>' res s' res'\n  \\<equiv> foldmap \\<xi>' \\<sigma> p frm i f acc obsv r (\\<sigma>', res) \\<and> val_rel res res' \\<and> (\\<sigma>', s') \\<in> state_rel\"\ndefinition \"foldmap_inv_stat obsv obsv' \\<equiv> val_rel obsv obsv'\"\n\nlemma whileLoop_add_invI:\n  assumes \"\\<lbrace> P \\<rbrace> whileLoop_inv c b init I (measure M) \\<lbrace> Q \\<rbrace>!\"\n  shows \"\\<lbrace> P \\<rbrace> whileLoop c b init \\<lbrace> Q \\<rbrace>!\"\n  by (metis assms whileLoop_inv_def)\n\nlemma validNF_select_UNIV:\n  \"\\<lbrace>\\<lambda>s. \\<forall>x. Q x s\\<rbrace> select UNIV \\<lbrace>Q\\<rbrace>!\"\n  apply (subst select_UNIV_unknown)\n  apply (rule validNF_unknown)\n  done\n\nsubsection \"wordarray_fold_no_break\"\n\nlemma \\<Xi>_wordarray_fold_no_break_0:\n  \"\\<Xi> ''wordarray_fold_no_break_0'' = wordarray_fold_no_break_0_type\"\n  by (clarsimp simp: \\<Xi>_def)\n\nlemma fold_dispatch_wp:\n  \"\\<lbrakk>proc_ctx_wellformed \\<Xi>; upd.proc_env_matches_ptrs \\<xi>0' \\<Xi>;\n    wa_abs_typing_u (UWA (TPrim (Num num)) len arr) ''WordArray'' [TPrim (Num num)] (Boxed ReadOnly ptrl) r w \\<sigma>;\n    \\<sigma> p = option.Some (UAbstract (UWA (TPrim (Num num)) len arr));\n    upd.uval_typing \\<Xi> \\<sigma> acc (foldmap_acc_type ''wordarray_fold_no_break_0'') ra wa;\n    upd.uval_typing \\<Xi> \\<sigma> obsv (foldmap_obsv_type ''wordarray_fold_no_break_0'') ro {};\n    wa \\<inter> r = {}; wa \\<inter> ro = {}; p \\<notin> wa;\n    (\\<Xi>, [], [option.Some (foldmap_funarg_type ''wordarray_fold_no_break_0'')] \\<turnstile> \n    (App f (Var 0)) : (foldmap_funret_type ''wordarray_fold_no_break_0''));\n    \\<forall>x x' \\<sigma> s. val_rel x x' \\<longrightarrow>\n      update_sem_init.corres wa_abs_typing_u wa_abs_repr (Generated.state_rel wa_abs_repr) \n        (App f (Var 0)) (do ret <- dispatch f_num x'; gets (\\<lambda>s. ret) od) \n        \\<xi>0' [x] \\<Xi> [option.Some (foldmap_funarg_type ''wordarray_fold_no_break_0'')] \\<sigma> s;\n    elem_type (foldmap_funarg_type ''wordarray_fold_no_break_0'') = TPrim (Num num)\\<rbrakk> \\<Longrightarrow>\n    \\<lbrace>\\<lambda>sa. (a', n') = (a, n) \\<and> n < e \\<and>\n      (\\<exists>\\<sigma>' res x v. args = t3_C.elem_C_update (\\<lambda>_. v) a \\<and>\n        \\<sigma>' (arr + size_of_num_type num * n) = option.Some x \\<and> val_rel x v \\<and>\n      foldmap_inv upd_wa_foldnb_bod \\<xi>0' \\<sigma> p frm n f acc obsv (ra \\<union> ro) \\<sigma>' res sa (t3_C.acc_C args)) \\<and>\n      foldmap_bounds frm to len n e \\<and> foldmap_inv_stat obsv (t3_C.obsv_C args)\\<rbrace>\n      dispatch f_num args \n    \\<lbrace>\\<lambda>ret sb. (\\<exists>\\<sigma>' res.\n        foldmap_inv upd_wa_foldnb_bod \\<xi>0' \\<sigma> p frm (n + 1) f acc obsv (ra \\<union> ro) \\<sigma>' res sb ret) \\<and>\n      foldmap_inv_stat obsv (t3_C.obsv_C args) \\<and> foldmap_bounds frm to len (n + 1) e \\<and> \n      foldmap_measure (n + 1) to < foldmap_measure n' to\\<rbrace>!\"\n  apply (subst validNF_def)\n  apply (clarsimp simp: \\<Xi>_wordarray_fold_no_break_0 wordarray_fold_no_break_0_type_def abbreviated_type_defs)\n  apply (subst valid_def)\n  apply (subst no_fail_def)\n  apply clarsimp\n  apply (subst all_imp_conj_distrib[symmetric])\n  apply (clarsimp simp: foldmap_inv_def)\n  apply (rename_tac sa \\<sigma>' res x v)\n  apply (erule_tac x = \"mk_urecord [x, res, obsv]\" in allE)\n  apply (erule_tac x = args in allE)\n  apply (erule impE)\n   apply (subst val_rel_simp; simp add: foldmap_inv_stat_def)\n  apply (erule_tac x = \\<sigma>' in allE)\n  apply (erule_tac x = sa in allE)\n  apply (clarsimp simp: corres_def)\n  apply (frule_tac t = \"TPrim (Num num)\" in upd_wa_foldnb_bod_preservation[rotated 2]; simp?; clarsimp?)\n  apply (rename_tac r' w')\n  apply (subgoal_tac \"upd.matches_ptrs \\<Xi> \\<sigma>' [(mk_urecord [x, res, obsv])]\n      [option.Some (foldmap_funarg_type ''wordarray_fold_no_break_0'')] (r' \\<union> ro) w'\")\n   apply (clarsimp simp: \\<Xi>_wordarray_fold_no_break_0 wordarray_fold_no_break_0_type_def abbreviated_type_defs)\n    apply (erule impE, blast)\n   apply clarsimp\n   apply (rename_tac ret sb)\n   apply (erule_tac x = ret in allE)\n   apply (erule_tac x = sb in allE)\n   apply clarsimp\n   apply (drule upd.preservation[where \\<tau>s = \"[]\" and K = \"[]\", simplified]; simp?)\n   apply clarsimp\n   apply (rename_tac \\<sigma>'' res' rb wb)\n   apply (clarsimp simp: foldmap_bounds_def)\n   apply (case_tac \"frm < to \\<and> frm < len\"; clarsimp)\n   apply (frule wa_abs_typing_u_elims(5))\n   apply (erule_tac x = n in allE; clarsimp)\n   apply (frule_tac p = \"arr + (size_of_num_type num) * n\" in valid_ptr_not_in_frame_same; simp?)\n    apply (drule_tac x = \"arr + 4 * n\" and S' = r in orthD2; simp?)\n    apply (drule_tac wa_abs_typing_u_elims(2)[where \\<tau>s = \"[_]\", simplified]; simp)\n    apply blast\n   apply clarsimp\n   apply (drule_tac t = num and arr = arr and len = len and r' = res' \n      in upd_wa_foldnb_bod_step; simp?; clarsimp?)\n    apply (rule conjI)\n     apply (drule_tac p = p in readonly_not_in_frame; simp?)\n    apply (subst Int_Un_distrib2)+\n    apply clarsimp\n    apply (rule conjI)\n     apply (rule disjointI)\n     apply (frule_tac p = x and r = ra and w = wa in upd.uval_typing_valid(1)[rotated 1]; simp?)\n     apply clarsimp\n     apply (drule_tac p = y in readonly_not_in_frame; simp?)\n     apply (drule upd.uval_typing_pointers_noalias; blast)\n    apply (rule conjI)\n     apply (rule disjointI)\n     apply (frule_tac p = x and r = ro and w = \"{}\" in upd.uval_typing_valid(1)[rotated 1]; simp?)\n     apply clarsimp\n     apply (drule_tac p = y in readonly_not_in_frame; simp?)\n     apply blast\n    apply (rule disjointI)\n    apply (frule wa_abs_typing_u_elims(5))\n    apply clarsimp\n    apply (erule_tac x = i in allE; clarsimp)\n    apply (drule_tac p = \"arr + (size_of_num_type num) * i\" in readonly_not_in_frame; simp?)\n    apply (drule wa_abs_typing_u_elims(2); clarsimp)\n    apply blast\n   apply (rule conjI)\n    apply (rule_tac x = \\<sigma>'' in exI)\n    apply (rule_tac x = res' in exI; simp)\n   apply (frule_tac a = n and k = to in less_is_non_zero_p1)\n   apply (drule unatSuc2; clarsimp simp: word_less_nat_alt word_le_nat_alt foldmap_measure_def)\n   apply linarith\n  apply (clarsimp simp: \\<Xi>_wordarray_fold_no_break_0 wordarray_fold_no_break_0_type_def abbreviated_type_defs)\n  apply (rule upd.matches_ptrs_some[where r' = \"{}\" and w' = \"{}\", simplified])\n   apply (rule upd.u_t_struct; simp?)\n   apply (rule upd.u_t_r_cons1[where r = \"{}\" and w = \"{}\", simplified]; simp?)\n     apply (subst (asm) val_rel_word; clarsimp)\n     apply (rule upd.u_t_prim'; clarsimp)\n    apply (rule upd.u_t_r_cons1[where r' = ro and w' = \"{}\", simplified]; simp?)\n      apply (drule_tac u = obsv in upd.uval_typing_frame(1); simp?)\n       apply blast\n      apply (rule upd.u_t_r_cons1[where r' = \"{}\" and w' = \"{}\", simplified]; simp?)\n       apply (rule upd.u_t_r_empty)\n      apply (drule_tac v = obsv in upd.type_repr_uval_repr(1); simp)\n     apply (rule disjointI)\n     apply (frule_tac p = y and r = ro in upd.uval_typing_valid(1)[where w = \"{}\", simplified]; simp?)\n     apply clarsimp\n     apply (drule_tac p = y in readonly_not_in_frame; simp?)\n     apply (drule_tac x = y and S' = ro in orthD2; simp?)\n    apply (drule_tac v = res in upd.type_repr_uval_repr(1); simp)\n  apply (subst (asm) val_rel_word; clarsimp)\n  apply (rule upd.matches_ptrs_empty[where \\<tau>s = \"[]\", simplified])\n  done\n\nlemma upd_C_wordarray_fold_no_break_corres_gen:\n  \"\\<lbrakk>upd.proc_env_matches_ptrs \\<xi>0' \\<Xi>; i < length \\<gamma>; val_rel (\\<gamma> ! i) v'; \n    \\<Gamma>' ! i = option.Some (prod.fst (prod.snd (\\<Xi> ''wordarray_fold_no_break_0'')));\n    D \\<in> k \\<or> S \\<in> k; K' \\<turnstile> (foldmap_obsv_type ''wordarray_fold_no_break_0'') :\\<kappa> k;\n    \\<gamma> ! i = URecord fs; f = prod.fst (fs ! 3);  \n    (\\<Xi>, [], [option.Some (foldmap_funarg_type ''wordarray_fold_no_break_0'')] \\<turnstile> \n    (App (uvalfun_to_exprfun f) (Var 0)) : (foldmap_funret_type ''wordarray_fold_no_break_0''));\n    \\<forall>x x' \\<sigma> s. val_rel x x' \\<longrightarrow> update_sem_init.corres wa_abs_typing_u wa_abs_repr (Generated.state_rel wa_abs_repr) \n      (App (uvalfun_to_exprfun f) (Var 0)) (do ret <- dispatch_t4' (t5_C.f_C v') x'; gets (\\<lambda>s. ret) od) \n      \\<xi>0' [x] \\<Xi> [option.Some (foldmap_funarg_type ''wordarray_fold_no_break_0'')] \\<sigma> s;\n    \\<xi>1' ''wordarray_fold_no_break_0'' = upd_wa_foldnb \\<Xi> \\<xi>0' (foldmap_funarg_type ''wordarray_fold_no_break_0'');\n    elem_type (foldmap_funarg_type ''wordarray_fold_no_break_0'') = TPrim (Num num)\\<rbrakk>\n    \\<Longrightarrow> update_sem_init.corres wa_abs_typing_u wa_abs_repr (Generated.state_rel wa_abs_repr)\n         (App (AFun ''wordarray_fold_no_break_0'' []) (Var i)) (do x <- main_pp_inferred.wordarray_fold_no_break_0' v';\ngets (\\<lambda>s. x)\n                                                                od)\n         \\<xi>1' \\<gamma> \\<Xi>  \\<Gamma>' \\<sigma> s\"\n  apply (rule absfun_corres; simp)\n  apply (clarsimp simp: abs_fun_rel_def'; rename_tac r w)\n  apply (thin_tac \"\\<Gamma>' ! i = _\")\n  apply (subst (asm) val_rel_simp; clarsimp)\n  apply (subst (asm) val_rel_ptr_def; clarsimp)\n  apply (subst (asm) val_rel_fun_tag)\n  apply (subst (asm) val_rel_word)\n  apply (subst (asm) val_rel_word)\n  apply (clarsimp simp: upd_wa_foldnb_def wordarray_fold_no_break_0'_def)\n  apply (rename_tac pwa_rep frm_rep to_rep f_rep acc a_rep obsv o_rep wa_rep)\n  apply (erule upd.u_t_recE; clarsimp)\n  apply (clarsimp simp: \\<Xi>_wordarray_fold_no_break_0 wordarray_fold_no_break_0_type_def abbreviated_type_defs)\n  apply (erule upd.u_t_r_consE; clarsimp)\n  apply (erule upd.u_t_p_absE; clarsimp)\n  apply (frule wa_abs_typing_u_elims(1); clarsimp)\n  apply (rename_tac r len arr)\n  apply (erule upd.u_t_r_consE; simp)\n  apply (erule upd.u_t_r_consE; simp)\n  apply (erule conjE)+\n  apply (drule_tac t = \"type_repr _\" in sym)+\n  apply clarsimp\n  apply (erule upd.u_t_primE)+\n  apply (drule_tac t = \"lit_type _\" in sym)+\n  apply clarsimp\n  apply (erule upd.u_t_r_consE; clarsimp)+\n  apply (erule upd.u_t_r_emptyE; clarsimp)\n  apply (frule upd.tfun_no_pointers(1))\n  apply (frule upd.tfun_no_pointers(2))\n  apply clarsimp\n  apply (rename_tac acc ra wa obsv ro wo)\n  apply (drule upd.discardable_or_shareable_not_writeable; simp?)\n  apply clarsimp\n  apply (subst unknown_bind_ignore)+\n  apply (clarsimp simp: join_guards)\n  apply wp\n      apply (clarsimp simp: unknown_bind_ignore split: prod.split)\n      apply (rename_tac var e)\n      apply (rule_tac M = \"\\<lambda>((_, i), _). foldmap_measure i (t5_C.to_C v')\" and \n      I = \"\\<lambda>(a, b) s. (\\<exists>\\<sigma>' res. foldmap_inv upd_wa_foldnb_bod \\<xi>0' \\<sigma> (ptr_val (t5_C.arr_C v'))\n          (t5_C.frm_C v') b (uvalfun_to_exprfun f) acc obsv (ra \\<union> ro) \\<sigma>' res s (t3_C.acc_C a)) \\<and>\n          foldmap_inv_stat obsv (t3_C.obsv_C a) \\<and>\n          foldmap_bounds (t5_C.frm_C v') (t5_C.to_C v') len b e\" in whileLoop_add_invI; simp?)\n      apply (wp; clarsimp simp: unknown_bind_ignore split: prod.splits)\n          apply (rename_tac sa a n args a' n')\n          apply (rule_tac a = a and wa = wa and ra = ra and ro = ro and w = \"{}\" and r = r and\n            ptrl = undefined in fold_dispatch_wp[rotated 2]; simp?)\n             apply (clarsimp simp: \\<Xi>_wordarray_fold_no_break_0 wordarray_fold_no_break_0_type_def abbreviated_type_defs)+\n         apply wp\n        apply wp\n       apply clarsimp\n       apply (rename_tac args j \\<sigma>' res)\n       apply (clarsimp simp: foldmap_bounds_def foldmap_inv_def)\n       apply (frule wa_abs_typing_u_elims(5))\n       apply (erule_tac x = j in allE; clarsimp)\n       apply (drule_tac acc = acc and obsv = obsv and rb = ra and wb = wa and rc = ro\n          in upd_wa_foldnb_bod_preservation; simp?; clarsimp?)\n       apply (frule_tac p = \"ptr_val (t5_C.arr_C v')\" in valid_ptr_not_in_frame_same; simp?)\n       apply (drule_tac p = \"arr + (size_of_num_type num) * j\" in valid_ptr_not_in_frame_same; simp?)\n        apply (drule_tac x = \"arr + (size_of_num_type num) * j\" and S = wa and S' = r in orthD2; simp?)\n        apply (drule wa_abs_typing_u_elims(2); clarsimp)\n        apply blast\n       apply (thin_tac \"_ \\<in> state_rel\")\n       apply (rule conjI)\n        apply (rule_tac x = \\<sigma>' in exI)\n        apply (rule_tac x = res in exI)\n        apply (rule_tac x = \"UPrim x\" in exI)\n        apply clarsimp\n        apply (clarsimp simp: state_rel_def heap_rel_def heap_rel_ptr_w32_meta heap_rel_ptr_meta)\n        apply (rotate_tac -1)\n        apply (drule_tac p = \"Ptr(arr + (size_of_num_type num) * j)\" in all_heap_rel_ptrD; simp?)\n         apply (clarsimp simp: type_rel_simp)\n        apply (rule_tac x = \"heap_w32 s (PTR(32 word) (arr + (size_of_num_type num) * j))\" in exI)\n        apply (drule_tac p = \"t5_C.arr_C v'\" in all_heap_rel_ptrD; simp?)\n         apply (clarsimp simp: type_rel_simp wa_abs_repr_def)\n        apply (clarsimp simp: val_rel_WordArray_u32_C_def ptr_add_def heap_simp mult.commute)\n       apply (clarsimp simp: state_rel_def heap_rel_def heap_rel_ptr_w32_meta heap_rel_ptr_meta)\n       apply (rotate_tac -1)\n       apply (drule_tac p = \"Ptr(arr + (size_of_num_type num) * j)\" in all_heap_rel_ptrD; simp?)\n        apply (clarsimp simp: type_rel_simp)\n       apply (drule_tac p = \"t5_C.arr_C v'\" in all_heap_rel_ptrD; simp?)\n        apply (clarsimp simp: type_rel_simp wa_abs_repr_def)\n       apply (clarsimp simp: is_valid_simp heap_simp val_rel_WordArray_u32_C_def ptr_add_def mult.commute)\n      apply (rule conjI)\n       apply (erule u_t_primtE; clarsimp)\n      apply (rule conjI)\n       apply (drule_tac v = obsv in upd.type_repr_uval_repr(1); simp?)\n      apply (rule conjI)\n       apply (drule wa_abs_typing_u_elims(5); simp)\n      apply (rule conjI)\n       apply (erule u_t_funafuntE; clarsimp)\n      apply (rename_tac x' j \\<sigma>' res)\n      apply (rule_tac x = \\<sigma>' in exI)\n      apply (rule_tac x = res in exI)\n      apply (clarsimp simp: foldmap_inv_def)\n      apply (rule_tac x = \"foldmap_acc_type ''wordarray_fold_no_break_0''\" in exI)\n      apply (rule_tac x = \"foldmap_obsv_type ''wordarray_fold_no_break_0''\" in exI)\n      apply (rule_tac x = \"''elem''\" in exI)\n      apply (rule_tac x = \"''acc''\" in exI)\n      apply (rule_tac x = \"''obsv''\" in exI)\n      apply (clarsimp simp: \\<Xi>_wordarray_fold_no_break_0 wordarray_fold_no_break_0_type_def abbreviated_type_defs)\n      apply (rule_tac x = ra in exI)\n      apply (rule conjI)\n       apply (intro exI, assumption)\n      apply (rule_tac x = ro in exI)\n      apply (rule conjI, simp)\n      apply (unfold foldmap_bounds_def)\n      apply (erule conjE)+\n      apply (case_tac \"t5_C.frm_C v' < e\")\n       apply (erule impE, assumption)\n       apply (thin_tac \"_ \\<longrightarrow> _\")\n       apply clarsimp\n       apply (case_tac \"j < t5_C.to_C v'\"; clarsimp)\n       apply (rule upd_wa_foldnb_bod_to_geq_len; simp?)\n      apply (erule impE, assumption)\n      apply (thin_tac \"_ \\<longrightarrow> _\")\n      apply clarsimp\n      apply (erule upd_wa_foldnb_bod.elims; clarsimp)\n      apply (case_tac \"t5_C.frm_C v' < t5_C.to_C v'\"; subst upd_wa_foldnb_bod.simps; clarsimp)\n     apply wp\n    apply wp\n   apply (rule validNF_select_UNIV)\n  apply (clarsimp simp: foldmap_inv_stat_def)\n  apply (clarsimp simp: order.strict_implies_order)\n  apply (clarsimp simp: foldmap_inv_def state_rel_def heap_rel_def heap_rel_ptr_meta)\n  apply (frule_tac p = \"t5_C.arr_C v'\" in all_heap_rel_ptrD; simp?)\n   apply (clarsimp simp: type_rel_simp wa_abs_repr_def)\n  apply (clarsimp simp: is_valid_simp val_rel_WordArray_u32_C_def heap_simp)\n  apply (rule conjI; clarsimp)\n   apply (rule conjI)\n    apply (rule_tac x = \\<sigma> in exI)\n    apply (rule_tac x = acc in exI)\n    apply clarsimp\n    apply (drule wa_abs_typing_u_elims(5))\n    apply (subst upd_wa_foldnb_bod.simps; clarsimp)\n    apply (rule conjI; clarsimp)\n    apply (rename_tac j)\n    apply (erule_tac x = j in allE; clarsimp)\n   apply (subst min_def)\n   apply (subst (asm) not_le[symmetric])+\n   apply (subst if_not_P; simp?)\n  apply (rule conjI)\n   apply (rule_tac x = \\<sigma> in exI)\n   apply (rule_tac x = acc in exI)\n   apply clarsimp\n   apply (drule wa_abs_typing_u_elims(5))\n   apply (subst upd_wa_foldnb_bod.simps; clarsimp)\n   apply (rule conjI; clarsimp)\n   apply (rename_tac j)\n   apply (erule_tac x = j in allE; clarsimp)\n  apply (subst min_def)\n  apply (clarsimp simp: not_le)\n  done\n\nsubsection \"wordarray_map_no_break\"\n\nlemma \\<Xi>_wordarray_map_no_break_0:\n  \"\\<Xi> ''wordarray_map_no_break_0'' = wordarray_map_no_break_0_type\"\n  by (clarsimp simp: \\<Xi>_def)\n\nlemma map_dispatch_wp:\n  \"\\<lbrakk>proc_ctx_wellformed \\<Xi>; upd.proc_env_matches_ptrs \\<xi>0' \\<Xi>;\n    wa_abs_typing_u (UWA (TPrim (Num num)) len arr) ''WordArray'' [TPrim (Num num)] (Boxed Writable ptrl) r w \\<sigma>;\n    \\<sigma> p = option.Some (UAbstract (UWA (TPrim (Num num)) len arr));\n    upd.uval_typing \\<Xi> \\<sigma> acc (foldmap_acc_type ''wordarray_map_no_break_0'') ra wa;\n    upd.uval_typing \\<Xi> \\<sigma> obsv (foldmap_obsv_type ''wordarray_map_no_break_0'') ro {}; wa \\<inter> r = {}; p \\<notin> w;\n    p \\<notin> r; w \\<inter> wa = {}; w \\<inter> (ra \\<union> ro) = {}; wa \\<inter> ro = {}; p \\<notin> wa; p \\<notin> ra; p \\<notin> ro; p = ptr_val p';\n    (\\<Xi>, [], [option.Some (foldmap_funarg_type ''wordarray_map_no_break_0'')] \\<turnstile> \n    (App f (Var 0)) : (foldmap_funret_type ''wordarray_map_no_break_0''));\n    \\<forall>x x' \\<sigma> s. val_rel x x' \\<longrightarrow>\n      update_sem_init.corres wa_abs_typing_u wa_abs_repr (Generated.state_rel wa_abs_repr) \n        (App f (Var 0)) (do ret <- dispatch f_num x'; gets (\\<lambda>s. ret) od) \n        \\<xi>0' [x] \\<Xi> [option.Some (foldmap_funarg_type ''wordarray_map_no_break_0'')] \\<sigma> s;\n     elem_type (foldmap_funarg_type ''wordarray_map_no_break_0'') = TPrim (Num num)\\<rbrakk> \\<Longrightarrow>\n    \\<lbrace>\\<lambda>sa. (a', n') = (a, n) \\<and> n < e \\<and>\n      (\\<exists>\\<sigma>' res x v. args = t6_C.elem_C_update (\\<lambda>_. v) a \\<and>\n        \\<sigma>' (arr + size_of_num_type U32 * n) = option.Some x \\<and> val_rel x v \\<and>\n      foldmap_inv upd_wa_mapAccumnb_bod \\<xi>0' \\<sigma> p frm n f acc obsv (ra \\<union> ro) \\<sigma>' res sa (t10_C p' (t6_C.acc_C args))) \\<and>\n      foldmap_bounds frm to len n e \\<and> foldmap_inv_stat obsv (t6_C.obsv_C args)\\<rbrace>\n      dispatch f_num args \n     \\<lbrace>\\<lambda>ret sb. (\\<exists>\\<sigma>' res. \n        foldmap_inv upd_wa_mapAccumnb_bod \\<xi>0' \\<sigma> p frm (n + 1) f acc obsv (ra \\<union> ro) \\<sigma>' res \n          (heap_w32_update (\\<lambda>x a. if a = values_C (heap_WordArray_u32_C sb p') +\\<^sub>p uint n \n            then t7_C.p1_C ret else x a) sb) (t10_C p' (t7_C.p2_C ret))) \\<and>\n        foldmap_inv_stat obsv (t6_C.obsv_C args) \\<and>\n        foldmap_bounds frm to len (n + 1) e \\<and>\n        foldmap_measure (n + 1) to < foldmap_measure n' to \\<and>\n        is_valid_WordArray_u32_C sb p' \\<and>\n        is_valid_w32 sb (values_C (heap_WordArray_u32_C sb p') +\\<^sub>p uint n)\\<rbrace>!\"\n  apply (subst validNF_def)\n  apply (clarsimp simp: \\<Xi>_wordarray_map_no_break_0 wordarray_map_no_break_0_type_def abbreviated_type_defs)\n  apply (subst valid_def)\n  apply (subst no_fail_def)\n  apply clarsimp\n  apply (subst all_imp_conj_distrib[symmetric])\n  apply (clarsimp simp: foldmap_inv_def)\n  apply (rename_tac sa \\<sigma>' res x v)\n  apply (frule upd_wa_mapAccumnb_bod_preservation'; simp?)\n  apply clarsimp\n  apply (rename_tac racc)\n  apply (erule_tac x = \"mk_urecord [x, racc, obsv]\" in allE)\n  apply (erule_tac x = args in allE)\n  apply clarsimp\n  apply (erule impE)\n   apply (clarsimp simp: val_rel_simp foldmap_inv_stat_def)\n  apply (erule_tac x = \\<sigma>' in allE)\n  apply (erule_tac x = sa in allE)\n  apply (clarsimp simp: corres_def)\n  apply (frule_tac t = \"TPrim (Num num)\" in upd_wa_mapAccumnb_bod_preservation; simp?; clarsimp?)\n    apply (subst Int_Un_distrib2; clarsimp)\n    apply (subst (asm) Int_Un_distrib; clarsimp)\n   apply (subst (asm) Int_Un_distrib; clarsimp)\n  apply (rename_tac r' w')\n  apply (erule upd.u_t_recE; clarsimp)\n  apply (erule upd.u_t_r_consE; simp)\n  apply (erule conjE)+\n  apply (drule_tac t = \"type_repr _\" in sym; clarsimp)\n  apply (erule upd.u_t_r_consE; clarsimp)\n  apply (erule upd.u_t_r_emptyE; clarsimp)\n  apply (rename_tac w' rb wb racc rc wc)\n  apply (erule upd.u_t_p_con_wrE)\n  apply (drule_tac t = \"RCon _ _\" in sym; clarsimp)\n  apply (frule_tac p = p in valid_ptr_not_in_frame_same; simp?)\n  apply clarsimp\n  apply (frule_tac p = p in readonly_not_in_frame; simp?)\n  apply (subst (asm) insert_ident; clarsimp)\n  apply (rename_tac wb)\n  apply (subgoal_tac \"upd.matches_ptrs \\<Xi> \\<sigma>' [(mk_urecord [x, racc, obsv])]\n      [option.Some (foldmap_funarg_type ''wordarray_map_no_break_0'')] (rc \\<union> ro) wc\")\n   apply (clarsimp simp: \\<Xi>_wordarray_map_no_break_0 wordarray_map_no_break_0_type_def abbreviated_type_defs)\n   apply (erule impE, blast)\n   apply clarsimp\n   apply (rename_tac ret sb)\n   apply (erule_tac x = ret in allE)\n   apply (erule_tac x = sb in allE)\n   apply clarsimp\n   apply (drule upd.preservation[where \\<tau>s = \"[]\" and K = \"[]\", simplified]; simp?)\n   apply clarsimp\n   apply (rename_tac \\<sigma>'' res' r' w')\n   apply (erule u_t_rectE; clarsimp)\n   apply (erule u_t_r_contE; clarsimp)\n   apply (erule u_t_r_contE; clarsimp)\n   apply (erule u_t_r_contE; clarsimp)\n   apply (rename_tac x' rd wd racc' r' w')\n   apply (frule_tac v = x' in upd.tprim_no_pointers(1); clarsimp)\n   apply (frule_tac v = x' in upd.tprim_no_pointers(2); clarsimp)\n   apply (clarsimp simp: foldmap_bounds_def)\n   apply (case_tac \"frm < to \\<and> frm < len\"; clarsimp)\n   apply (thin_tac \"wa_abs_typing_u _ _ _ _ _ _ _\")\n   apply (drule_tac t = num and arr = arr and len = len and v' = x' and r' = racc'\n      in upd_wa_mapAccumnb_bod_step; simp?; clarsimp?)\n      apply (drule wa_abs_typing_u_elims(6); simp?)\n     apply (subst Int_Un_distrib2)+\n     apply clarsimp\n     apply (rule conjI)\n      apply (rule disjointI)\n      apply (rename_tac y y')\n      apply (frule_tac p = y and r = ra and w = wa in upd.uval_typing_valid(1)[rotated 1]; simp?)\n      apply clarsimp\n      apply (drule_tac p = y' in readonly_not_in_frame; simp?)\n      apply (drule_tac x = y' and S' = \"ra \\<union> ro\" in orthD2; simp?)\n      apply (drule upd.uval_typing_pointers_noalias)\n      apply (drule_tac x = y' and S = ra and S' = wa in orthD1; simp?)\n     apply (rule conjI)\n      apply (rule disjointI)\n      apply (rename_tac y y')\n      apply (frule_tac p = y and r = ro and w = \"{}\" in upd.uval_typing_valid(1)[rotated 1]; simp?)\n      apply clarsimp\n      apply (drule_tac p = y' in readonly_not_in_frame; simp?)\n      apply blast\n     apply (drule wa_abs_typing_u_elims(3); clarsimp)\n    apply (drule_tac v = x' in upd.type_repr_uval_repr(1); simp)\n    apply (drule_tac v = racc' in upd.type_repr_uval_repr(1); simp)\n   apply (thin_tac \"_ \\<in> state_rel\")\n   apply (clarsimp simp: state_rel_def heap_rel_def heap_rel_ptr_meta heap_rel_ptr_w32_meta)\n   apply (frule_tac p = p and \\<sigma> = \\<sigma>' in valid_ptr_not_in_frame_same; simp?)\n   apply (drule_tac p = \"arr + (size_of_num_type num) * n\" and \\<sigma> = \\<sigma>' in valid_ptr_not_in_frame_same; simp?)\n    apply (drule_tac x = \"arr + (size_of_num_type num) * n\" and S' = wc in orthD1; simp?)\n    apply (drule wa_abs_typing_u_elims(3); clarsimp)\n    apply (rule_tac x = n in exI; clarsimp)\n   apply (frule_tac p = p' in all_heap_rel_ptrD; simp?)\n    apply (clarsimp simp: type_rel_simp wa_abs_repr_def)\n   apply (frule_tac p = \"values_C (heap_WordArray_u32_C sb p') +\\<^sub>p uint n\" and uv = x in all_heap_rel_ptrD; simp?)\n     apply (clarsimp simp: val_rel_simp heap_simp)\n    apply (clarsimp simp: type_rel_simp val_rel_simp)\n   apply (rule conjI)\n    apply (rule_tac x = \"\\<sigma>''(arr + (size_of_num_type num) * n \\<mapsto> x')\" in exI)\n    apply (rule_tac x = \"mk_urecord [UPtr (ptr_val p') (RCon ''WordArray'' [RPrim (Num U32)]), racc']\" in exI)\n    apply clarsimp\n    apply (rule conjI)\n     apply (clarsimp simp: val_rel_simp)\n    apply (clarsimp simp: heap_simp is_valid_simp)\n    apply (drule_tac upd_h = \"(heap_w32_update \n      (\\<lambda>x a. if a = values_C (heap_WordArray_u32_C sb p') +\\<^sub>p uint n then t7_C.p1_C ret else x a) sb)\" and\n      uv = x and uv' = x' and x = \"values_C (heap_WordArray_u32_C sb p') +\\<^sub>p uint n\"\n      in all_heap_rel_updE; simp?; clarsimp?)\n       apply (clarsimp simp: val_rel_simp)\n      apply (drule_tac v = x' in upd.type_repr_uval_repr(1); simp add: val_rel_simp)\n     apply (clarsimp simp: val_rel_simp type_rel_simp)\n    apply (drule_tac upd_h = \"(heap_w32_update \n      (\\<lambda>x a. if a = values_C (heap_WordArray_u32_C sb p') +\\<^sub>p uint n then t7_C.p1_C ret else x a) sb)\" and\n      uv = x and uv' = x' and x = \"values_C (heap_WordArray_u32_C sb p') +\\<^sub>p uint n\"\n      in all_heap_rel_updE; simp?; clarsimp?)\n       apply (clarsimp simp: val_rel_simp)\n      apply (drule_tac v = x' in upd.type_repr_uval_repr(1); simp add: val_rel_simp)\n     apply (rule conjI)\n      apply (clarsimp simp: val_rel_simp)\n     apply (cut_tac p = pa and q = \"values_C (heap_WordArray_u32_C sb p') +\\<^sub>p uint n\" in ptr_val_inj)\n     apply clarsimp\n    apply (clarsimp simp: ptr_add_def mult.commute val_rel_simp)\n   apply (clarsimp simp: is_valid_simp)\n   apply (frule_tac a = n and k = to in less_is_non_zero_p1)\n   apply (drule unatSuc2; clarsimp simp: word_less_nat_alt word_le_nat_alt foldmap_measure_def)\n   apply linarith\n  apply (clarsimp simp: \\<Xi>_wordarray_map_no_break_0 wordarray_map_no_break_0_type_def abbreviated_type_defs)\n  apply (rule upd.matches_ptrs_some[where r' = \"{}\" and w' = \"{}\", simplified])\n   apply (rule upd.u_t_struct; simp?)\n   apply (rule upd.u_t_r_cons1[where r = \"{}\" and w = \"{}\", simplified]; simp?)\n     apply (subst (asm) val_rel_word; clarsimp)\n     apply (rule upd.u_t_prim'; clarsimp)\n    apply (rule upd.u_t_r_cons1[where r' = ro and w' = \"{}\", simplified]; simp?)\n     apply (drule_tac u = obsv in upd.uval_typing_frame(1); simp?)\n      apply blast\n     apply (rule upd.u_t_r_cons1[where r' = \"{}\" and w' = \"{}\", simplified]; simp?)\n      apply (rule upd.u_t_r_empty)\n     apply (drule_tac v = obsv in upd.type_repr_uval_repr(1); simp)\n    apply (rule disjointI)\n    apply (frule_tac p = y and r = ro in upd.uval_typing_valid(1)[where w = \"{}\", simplified]; simp?)\n    apply clarsimp\n    apply (drule_tac p = y in readonly_not_in_frame; simp?)\n    apply (drule_tac x = y and S' = ro in orthD2; simp?)\n    apply (drule_tac x = y and S' = \"ra \\<union> ro\" in orthD2; simp?)\n   apply (subst (asm) val_rel_word; clarsimp)\n  apply (rule upd.matches_ptrs_empty[where \\<tau>s = \"[]\", simplified])\n  done\n\nlemma upd_C_wordarray_map_no_break_corres_gen:\n  \"\\<lbrakk>upd.proc_env_matches_ptrs \\<xi>0' \\<Xi>; i < length \\<gamma>; val_rel (\\<gamma> ! i) v';\n    \\<Gamma>' ! i = option.Some (prod.fst (prod.snd (\\<Xi> ''wordarray_map_no_break_0'')));\n     D \\<in> k \\<or> S \\<in> k; K' \\<turnstile> (foldmap_obsv_type ''wordarray_map_no_break_0'') :\\<kappa> k;\n    \\<gamma> ! i = URecord fs; f = prod.fst (fs ! 3);\n    (\\<Xi>, [], [option.Some (foldmap_funarg_type ''wordarray_map_no_break_0'')] \\<turnstile> \n    (App (uvalfun_to_exprfun f) (Var 0)) : (foldmap_funret_type ''wordarray_map_no_break_0''));\n    \\<forall>x x' \\<sigma> s. val_rel x x' \\<longrightarrow> update_sem_init.corres wa_abs_typing_u wa_abs_repr (Generated.state_rel wa_abs_repr) \n      (App (uvalfun_to_exprfun f) (Var 0)) (do ret <- dispatch_t8' (t9_C.f_C v') x'; gets (\\<lambda>s. ret) od) \n      \\<xi>0' [x] \\<Xi> [option.Some (foldmap_funarg_type ''wordarray_map_no_break_0'')] \\<sigma> s;\n    \\<xi>1' ''wordarray_map_no_break_0'' = upd_wa_mapAccumnb \\<Xi> \\<xi>0' \n      (foldmap_funarg_type ''wordarray_map_no_break_0'') (foldmap_funret_type ''wordarray_map_no_break_0'');\n    elem_type (foldmap_funarg_type ''wordarray_map_no_break_0'') = TPrim (Num num)\\<rbrakk>\n    \\<Longrightarrow> update_sem_init.corres wa_abs_typing_u wa_abs_repr (Generated.state_rel wa_abs_repr)\n         (App (AFun ''wordarray_map_no_break_0'' []) (Var i)) (do x <- main_pp_inferred.wordarray_map_no_break_0' v';\ngets (\\<lambda>s. x)\n                                                                od)\n         \\<xi>1' \\<gamma> \\<Xi>  \\<Gamma>' \\<sigma> s\"\n  apply (rule absfun_corres; simp)\n  apply (clarsimp simp: abs_fun_rel_def'; rename_tac r w)\n  apply (thin_tac \"\\<Gamma>' ! i = _\")\n  apply (subst (asm) val_rel_simp; clarsimp)\n  apply (subst (asm) val_rel_ptr_def; clarsimp)\n  apply (subst (asm) val_rel_fun_tag)\n  apply (subst (asm) val_rel_word)\n  apply (subst (asm) val_rel_word)\n  apply (clarsimp simp: upd_wa_mapAccumnb_def wordarray_map_no_break_0'_def)\n  apply (rename_tac pwa_rep frm_rep to_rep f_rep acc a_rep o_rep wa_rep)\n  apply (erule upd.u_t_recE; clarsimp)\n  apply (clarsimp simp: \\<Xi>_wordarray_map_no_break_0 wordarray_map_no_break_0_type_def abbreviated_type_defs)\n  apply (erule upd.u_t_r_consE; clarsimp)\n  apply (rename_tac r w r' w')\n  apply (erule upd.u_t_p_absE; clarsimp)\n  apply (rename_tac w)\n  apply (frule wa_abs_typing_u_elims(1); clarsimp)\n  apply (rename_tac len arr)\n  apply (erule upd.u_t_r_consE; simp)\n  apply (erule upd.u_t_r_consE; simp)\n  apply (erule conjE)+\n  apply (drule_tac t = \"type_repr _\" in sym)+\n  apply clarsimp\n  apply (erule upd.u_t_primE)+\n  apply (drule_tac t = \"lit_type _\" in sym)+\n  apply clarsimp\n  apply (erule upd.u_t_r_consE; clarsimp)+\n  apply (erule upd.u_t_r_emptyE; clarsimp)\n  apply (frule upd.tfun_no_pointers(1))\n  apply (frule upd.tfun_no_pointers(2))\n  apply clarsimp\n  apply (rename_tac acc ra wa obsv ro wo)\n  apply (drule_tac v = obsv in upd.discardable_or_shareable_not_writeable(1); simp?)\n  apply (subst unknown_bind_ignore)+\n  apply (clarsimp simp: join_guards) \n  apply wp\n      apply (clarsimp simp: unknown_bind_ignore split: prod.split)\n       apply (rename_tac var e)\n       apply (rule_tac M = \"\\<lambda>((_, i), _). foldmap_measure i (t9_C.to_C v')\" and \n      I = \"\\<lambda>(a, b) s. (\\<exists>\\<sigma>' res. foldmap_inv upd_wa_mapAccumnb_bod \\<xi>0' \\<sigma> (ptr_val (t9_C.arr_C v'))\n          (t9_C.frm_C v') b (uvalfun_to_exprfun f) acc obsv (ra \\<union> ro) \\<sigma>' res s (t10_C (t9_C.arr_C v') (t6_C.acc_C a))) \\<and>\n          foldmap_inv_stat obsv (t6_C.obsv_C a) \\<and>\n          foldmap_bounds (t9_C.frm_C v') (t9_C.to_C v') len b e\" in whileLoop_add_invI; simp?)\n       apply (wp; clarsimp simp: unknown_bind_ignore split: prod.splits)\n           apply (rename_tac sa a n args a' n')\n           apply (clarsimp simp: conj_left_commute[of \"is_valid_w32 _ _\", simplified])\n           apply (clarsimp simp: conj_commute[of \"is_valid_w32 _ _\", simplified])\n           apply (rule_tac a = a and wa = wa and ra = ra and ro = ro and w = w and r = r and\n              ptrl = undefined in map_dispatch_wp; simp?)\n              apply (clarsimp simp: \\<Xi>_wordarray_map_no_break_0 wordarray_map_no_break_0_type_def abbreviated_type_defs)+\n          apply wp\n         apply wp\n        apply clarsimp\n        apply (rename_tac args j \\<sigma>' res)\n        apply (clarsimp simp: foldmap_inv_def foldmap_bounds_def)\n        apply (drule upd_wa_mapAccumnb_bod_preservation; simp?; clarsimp?)\n          apply (subst Int_Un_distrib2; clarsimp)\n          apply (cut_tac A = w and B = ra and C = ro in Int_Un_distrib; clarsimp)\n         apply (cut_tac A = w and B = ra and C = ro in Int_Un_distrib; clarsimp)\n        apply (frule_tac p = \"ptr_val (t9_C.arr_C v')\" in valid_ptr_not_in_frame_same; simp?)\n        apply (thin_tac \"_ \\<in> state_rel\")\n        apply (frule_tac upd_wa_mapAccumnb_bod_preservation'; simp?)\n        apply clarsimp\n        apply (erule upd.u_t_recE; clarsimp)\n        apply (erule upd.u_t_r_consE; simp)\n        apply (erule conjE)+\n        apply (drule_tac t = \"type_repr _\" in sym; clarsimp)\n        apply (erule upd.u_t_p_con_wrE)\n        apply (drule_tac t = \"RCon _ _\" in sym; clarsimp)\n        apply (thin_tac \"wa_abs_typing_u _ _ _ _ _ _ _\")\n        apply (drule wa_abs_typing_u_elims(5))\n        apply (erule_tac x = j in allE; clarsimp)\n        apply (clarsimp simp: state_rel_def heap_rel_def heap_rel_ptr_meta heap_rel_ptr_w32_meta)\n        apply (frule_tac p = \"t9_C.arr_C v'\" in all_heap_rel_ptrD; simp?)\n         apply (clarsimp simp: type_rel_simp wa_abs_repr_def)\n        apply (rotate_tac -2)\n         apply (frule_tac p = \"Ptr(arr + (size_of_num_type num) * j)\" in all_heap_rel_ptrD; simp?)\n         apply (clarsimp simp: type_rel_simp)\n        apply (rule conjI)\n         apply (rule_tac x = \\<sigma>' in exI)\n         apply (rule_tac x = \"mk_urecord [UPtr (ptr_val (t9_C.arr_C v'))\n          (RCon ''WordArray'' [RPrim (Num num)]), racc]\" in exI)\n         apply (rule_tac x = \"UPrim x\" in exI)\n         apply (rule_tac x = \"heap_w32 s (PTR(32 word) (arr + (size_of_num_type num) * j))\" in exI)\n         apply (clarsimp simp: val_rel_WordArray_u32_C_def ptr_add_def heap_simp mult.commute)\n        apply (clarsimp simp: val_rel_WordArray_u32_C_def ptr_add_def is_valid_simp heap_simp mult.commute)\n       apply (rule conjI)\n        apply (drule_tac v = acc in upd.type_repr_uval_repr(1); simp)\n       apply (rule conjI)\n        apply (drule_tac v = obsv in upd.type_repr_uval_repr(1); simp)\n       apply (rule conjI)\n        apply (drule wa_abs_typing_u_elims(5); simp)\n       apply (rule conjI)\n        apply (erule u_t_funafuntE; clarsimp)\n       apply (rule_tac x = \\<sigma>' in exI)\n       apply (rule_tac x = res in exI)\n       apply (clarsimp simp: foldmap_inv_def)\n       apply (rule conjI)\n        apply (rule_tac x = \"foldmap_acc_type ''wordarray_map_no_break_0''\" in exI)\n        apply (rule_tac x = \"foldmap_obsv_type ''wordarray_map_no_break_0''\" in exI)\n        apply (rule_tac x = \"''elem''\" in exI)\n        apply (rule_tac x = \"''acc''\" in exI)\n        apply (rule_tac x = \"''obsv''\" in exI)\n        apply (rule_tac x = \"''p1''\" in exI)\n        apply (rule_tac x = \"''p2''\" in exI)\n        apply (rule_tac x = ra in exI)\n        apply (clarsimp simp: \\<Xi>_wordarray_map_no_break_0 wordarray_map_no_break_0_type_def abbreviated_type_defs)\n        apply (rule conjI)\n         apply (intro exI, assumption)\n        apply (rule_tac x = ro in exI)\n        apply clarsimp\n        apply (rename_tac j \\<sigma>' res)\n        apply (unfold foldmap_bounds_def)\n        apply (erule conjE)+\n        apply (case_tac \"t9_C.frm_C v' < e\")\n         apply (erule impE, assumption)\n         apply (thin_tac \"_ \\<longrightarrow> _\")\n         apply clarsimp\n         apply (case_tac \"j < t9_C.to_C v'\"; clarsimp)\n         apply (rule upd_wa_mapAccumnb_bod_to_geq_len; simp?)\n        apply (erule impE, assumption)\n        apply (thin_tac \"_ \\<longrightarrow> _\")\n        apply clarsimp\n        apply (erule upd_wa_mapAccumnb_bod.elims; clarsimp)\n        apply (case_tac \"t9_C.frm_C v' < t9_C.to_C v'\"; subst upd_wa_mapAccumnb_bod.simps; clarsimp)\n       apply (clarsimp simp: val_rel_simp)\n      apply wp\n     apply wp\n    apply (rule validNF_select_UNIV)\n   apply (rule validNF_select_UNIV)\n  apply (clarsimp simp: foldmap_inv_stat_def)\n  apply (clarsimp simp: order.strict_implies_order)\n  apply (clarsimp simp: foldmap_inv_def state_rel_def heap_rel_def heap_rel_ptr_meta)\n  apply (frule_tac p = \"t9_C.arr_C v'\" in all_heap_rel_ptrD; simp?)\n   apply (clarsimp simp: type_rel_simp wa_abs_repr_def)\n  apply (clarsimp simp: is_valid_simp val_rel_WordArray_u32_C_def heap_simp)\n  apply (rule conjI; clarsimp)\n   apply (rule conjI)\n    apply (rule_tac x = \\<sigma> in exI)\n    apply (rule_tac x = \"mk_urecord [UPtr (ptr_val (t9_C.arr_C v'))\n      (RCon ''WordArray'' [RPrim (Num num)]), acc]\" in exI)\n    apply (subst upd_wa_mapAccumnb_bod.simps; clarsimp)\n    apply (rule conjI)\n     apply (drule wa_abs_typing_u_elims(5); clarsimp)\n     apply (rename_tac j)\n     apply (erule_tac x = j in allE; clarsimp)\n    apply (rule conjI)\n     apply (drule wa_abs_typing_u_elims(3); clarsimp)\n    apply (rule conjI)\n     apply (clarsimp simp: val_rel_simp)\n    apply (rule conjI; clarsimp)\n   apply (subst min_def)\n   apply (subst (asm) not_le[symmetric])+\n   apply (subst if_not_P; simp?)\n  apply (rule conjI)\n   apply (rule_tac x = \\<sigma> in exI)\n   apply (rule_tac x = \"mk_urecord [UPtr (ptr_val (t9_C.arr_C v'))\n      (RCon ''WordArray'' [RPrim (Num num)]), acc]\" in exI)\n   apply (subst upd_wa_mapAccumnb_bod.simps; clarsimp)\n   apply (rule conjI)\n    apply (drule wa_abs_typing_u_elims(5); clarsimp)\n    apply (rename_tac j)\n    apply (erule_tac x = j in allE; clarsimp)\n   apply (rule conjI)\n    apply (drule wa_abs_typing_u_elims(3); clarsimp)\n   apply (rule conjI)\n    apply (clarsimp simp: val_rel_simp)\n   apply (rule conjI; clarsimp)\n  apply (subst min_def)\n  apply (clarsimp simp: not_le)\n  done\n\nend (* of context *)\nend", "meta": {"author": "amblafont", "repo": "dargent-examples", "sha": "dbcfdd6573c088f65d4dade1b351b3bb2bc073e7", "save_path": "github-repos/isabelle/amblafont-dargent-examples", "path": "github-repos/isabelle/amblafont-dargent-examples/dargent-examples-dbcfdd6573c088f65d4dade1b351b3bb2bc073e7/sum-random/manual/SumRandom_UpdCCorres.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5389832206876841, "lm_q2_score": 0.4649015713733885, "lm_q1q2_score": 0.2505741462415942}}
{"text": "theory InferRange\n  imports InferDef\nbegin\n  \n    (* ##### random mechnical lemmas *)\n  \nlemma trip_convert: \"as_aff (as_perm a) = a\"    \n  apply (case_tac a)\n    apply (auto)\n  done  \n    \nlemma infer_x_subset_ih: \"\\<lbrakk> infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; x \\<in> ds \\<rbrakk> \\<Longrightarrow> x \\<in> ds'\"    \n  apply (induct e arbitrary: env_v ds tau_v r_sv r_xv r_mv c_list ds')\n        apply (auto)\n  apply (case_tac xa)\n              apply (auto)\n  done\n    \nlemma infer_x_subset: \"\\<lbrakk> infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds' \\<rbrakk> \\<Longrightarrow> ds \\<subseteq> ds'\"    \n  apply (auto)\n  apply (rule_tac infer_x_subset_ih)\n   apply (auto)\n  done  \n  \n    (*  ##### direct type substitution composition *)\n  \ndefinition dir_add_env where\n  \"dir_add_env t_sub a tau = (\\<lambda> a'. if a' = a then Some tau else t_sub a')\"  \n  \nfun dir_list_add_env where\n  \"dir_list_add_env t_sub [] = t_sub\"  \n| \"dir_list_add_env t_sub ((a, tau) # a_t) = dir_add_env (dir_list_add_env t_sub a_t) a tau\"\n  \n  \n    (* #### domain / range based lemmas *)\n\ndefinition sub_range where\n  \"sub_range env_v ds = (\\<forall> x. case env_v x of\n    None \\<Rightarrow> True\n    | Some a \\<Rightarrow> a \\<in> ds\n  )\"  \n  \ndefinition tsub_dom where\n  \"tsub_dom t_sub ds = (\\<forall> a. t_sub a \\<noteq> None \\<longrightarrow> a \\<in> ds)\"\n\ndefinition psub_dom where\n  \"psub_dom p_sub ds = (\\<forall> a. p_sub a \\<noteq> NoPerm \\<longrightarrow> a \\<in> ds)\"\n  \ndefinition set_diff :: \"'a set \\<Rightarrow> 'a set \\<Rightarrow> 'a set\" where\n  \"set_diff s1 s2 = s1 - s2\"  \n  \nfun dom_list where\n  \"dom_list [] = []\"  \n| \"dom_list ((x, v) # t) = x # (dom_list t)\"  \n  \nfun dom_list_set where\n  \"dom_list_set [] = {}\"  \n| \"dom_list_set ((x, v) # t) = ({x} \\<union> dom_list_set t)\"    \n  \nlemma dir_add_eq_env: \"\\<lbrakk> dir_subst_tenv t_sub env_v = env; sub_range env_v ds; a \\<notin> ds \\<rbrakk> \\<Longrightarrow>\n  dir_subst_tenv (dir_add_env t_sub a tau) env_v = env\"    \n  apply (auto)\n  apply (case_tac \"\\<forall> x. dir_subst_tenv (dir_add_env t_sub a tau) env_v x = env x\")\n   apply (auto)\n  apply (simp add: dir_subst_tenv_def)\n  apply (simp add: sub_range_def)\n  apply (erule_tac x=\"x\" in allE)\n  apply (case_tac \"env_v x\")\n   apply (auto)\n  apply (simp add: dir_add_env_def)\n  apply (case_tac \"a = aa\")\n   apply (auto)\n  done  \n    \nlemma dir_list_append_eq_env_ih: \"dir_subst_tenv (dir_list_add_env t_sub (l @ la)) env_v x = dir_subst_tenv (dir_list_add_env (dir_list_add_env t_sub la) l) env_v x\"    \n  apply (induct l)\n   apply (auto)\n  apply (simp add: dir_subst_tenv_def)\n  apply (case_tac \"env_v x\")\n   apply (auto)\n  apply (simp add: dir_add_env_def)\n  done\n  \nlemma dir_list_append_eq_env: \"dir_subst_tenv (dir_list_add_env t_sub (l @ la)) env_v = dir_subst_tenv (dir_list_add_env (dir_list_add_env t_sub la) l) env_v\"\n  apply (case_tac \"\\<forall> x. dir_subst_tenv (dir_list_add_env t_sub (l @ la)) env_v x = dir_subst_tenv (dir_list_add_env (dir_list_add_env t_sub la) l) env_v x\")\n   apply (auto)\n  apply (cut_tac t_sub=\"t_sub\" and x=\"x\" in dir_list_append_eq_env_ih)\n  apply (auto)\n  done\n\nlemma dir_list_dist_add_eq_env_ih: \"\\<lbrakk> dir_subst_tenv t_sub env_v x = dir_subst_tenv t_sub' env_v x \\<rbrakk> \\<Longrightarrow>\n  dir_subst_tenv (dir_list_add_env t_sub l) env_v x = dir_subst_tenv (dir_list_add_env t_sub' l) env_v x\"\n  apply (induct l)\n   apply (auto)\n  apply (simp add: dir_subst_tenv_def)\n  apply (case_tac \"env_v x\")\n   apply (auto)\n  apply (simp add: dir_add_env_def)\n  done\n    \nlemma dir_list_dist_add_eq_env: \"\\<lbrakk> dir_subst_tenv t_sub env_v = dir_subst_tenv t_sub' env_v \\<rbrakk> \\<Longrightarrow>\n  dir_subst_tenv (dir_list_add_env t_sub l) env_v = dir_subst_tenv (dir_list_add_env t_sub' l) env_v\"\n  apply (case_tac \"\\<forall> x. dir_subst_tenv (dir_list_add_env t_sub l) env_v x = dir_subst_tenv (dir_list_add_env t_sub' l) env_v x\")\n   apply (auto)\n  apply (cut_tac t_sub=\"t_sub\" and x=\"x\" and t_sub'=\"t_sub'\" in dir_list_dist_add_eq_env_ih)\n   apply (auto)\n  done\n    \nlemma dir_list_cancel_add_eq_env_ih: \"\\<lbrakk> sub_range env_v ds; fresh_list ds (dom_list l) \\<rbrakk> \\<Longrightarrow>\n  dir_subst_tenv (dir_list_add_env t_sub l) env_v x = dir_subst_tenv t_sub env_v x\"      \n  apply (induct l)\n   apply (auto)\n  apply (simp add: dir_subst_tenv_def)\n  apply (case_tac \"env_v x\")\n   apply (auto)\n  apply (simp add: dir_add_env_def)\n  apply (auto)\n   apply (simp add: sub_range_def)\n   apply (erule_tac x=\"x\" in allE)\n   apply (auto)\n   apply (simp add: fresh_list_def)\n   apply (auto)\n  apply (case_tac \"\\<not> fresh_list ds (dom_list l)\")\n   apply (auto)\n  apply (simp add: fresh_list_def)\n  done\n    \nlemma dir_list_cancel_add_eq_env: \"\\<lbrakk> sub_range env_v ds; fresh_list ds (dom_list l) \\<rbrakk> \\<Longrightarrow>\n  dir_subst_tenv (dir_list_add_env t_sub l) env_v = dir_subst_tenv t_sub env_v\"    \n  apply (case_tac \"\\<forall> x. dir_subst_tenv (dir_list_add_env t_sub l) env_v x = dir_subst_tenv t_sub env_v x\")\n   apply (auto)\n  apply (cut_tac t_sub=\"t_sub\" and x=\"x\" in dir_list_cancel_add_eq_env_ih)\n    apply (auto)\n  done\n    \n  \nlemma subset_tsub_dom: \"\\<lbrakk> tsub_dom t_sub ds; ds \\<subseteq> ds' \\<rbrakk> \\<Longrightarrow> tsub_dom t_sub ds'\"    \n  apply (simp add: tsub_dom_def)\n  apply (auto)\n  done\n  \nlemma add_tsub_dom: \"\\<lbrakk> tsub_dom t_sub ds; x \\<in> ds \\<rbrakk> \\<Longrightarrow> tsub_dom (dir_add_env t_sub x tau) ds\"        \n  apply (simp add: tsub_dom_def)\n  apply (simp add: dir_add_env_def)\n  done\n\nlemma add_tsub_dom_rev: \"\\<lbrakk> tsub_dom (dir_add_env t_sub x tau) ds \\<rbrakk> \\<Longrightarrow> tsub_dom t_sub ds\"        \n  apply (simp add: tsub_dom_def)\n  apply (simp add: dir_add_env_def)\n  done    \n    \nlemma list_add_tsub_dom: \"\\<lbrakk> tsub_dom t_sub ds; ds \\<subseteq> ds'; dom_list_set l \\<subseteq> ds' \\<rbrakk> \\<Longrightarrow> tsub_dom (dir_list_add_env t_sub l) ds'\"    \n  apply (induct l)\n   apply (auto)\n   apply (simp add: subset_tsub_dom)\n  apply (rule_tac add_tsub_dom)\n   apply (auto)\n  done\n \nlemma list_add_tsub_dom_rev: \"\\<lbrakk> tsub_dom (dir_list_add_env t_sub l) ds \\<rbrakk> \\<Longrightarrow> tsub_dom t_sub ds\"       \n  apply (induct l)\n   apply (auto)\n  apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and x=\"a\" in add_tsub_dom_rev)\n   apply (auto)\n  done\n  \nlemma append_tsub_dom: \"\\<lbrakk> tsub_dom (dir_list_add_env t_sub l2) ds; dom_list_set l1 \\<subseteq> ds \\<rbrakk> \\<Longrightarrow> tsub_dom (dir_list_add_env t_sub (l1 @ l2)) ds\"     \n  apply (induct l1)\n   apply (auto)\n  apply (rule_tac add_tsub_dom)\n   apply (auto)\n  done\n  \nlemma subset_psub_dom: \"\\<lbrakk> psub_dom p_sub ds; ds \\<subseteq> ds' \\<rbrakk> \\<Longrightarrow> psub_dom p_sub ds'\"    \n  apply (simp add: psub_dom_def)\n  apply (auto)\n  done\n  \nlemma empty_psub_dom: \"psub_dom empty_use_env ds\"       \n  apply (simp add: psub_dom_def)\n  apply (simp add: empty_use_env_def)\n  done\n    \nlemma add_psub_dom: \"\\<lbrakk> psub_dom p_sub ds; x \\<in> ds \\<rbrakk> \\<Longrightarrow> psub_dom (add_use_env p_sub x p) ds\"        \n  apply (simp add: psub_dom_def)\n  apply (simp add: add_use_env_def)\n  done    \n \nlemma comp_psub_dom: \"\\<lbrakk> psub_dom p_sub1 ds; psub_dom p_sub2 ds \\<rbrakk> \\<Longrightarrow> psub_dom (comp_use_env p_sub1 p_sub2) ds\"        \n  apply (simp add: psub_dom_def)\n  apply (auto)\n  apply (simp add: comp_use_env_def)\n  apply (case_tac \"p_sub1 a = NoPerm\")\n   apply (auto)\n  apply (case_tac \"p_sub2 a = NoPerm\")\n   apply (auto)\n  done        \n    \nlemma subset_sub_range: \"\\<lbrakk> sub_range env_v ds; ds \\<subseteq> ds' \\<rbrakk> \\<Longrightarrow> sub_range env_v ds'\"    \n  apply (simp add: sub_range_def)\n  apply (auto)\n  apply (case_tac \"env_v x\")\n   apply (auto)\n  apply (erule_tac x=\"x\" in allE)\n  apply (auto)\n  done\n    \nlemma list_add_dls: \"\\<lbrakk> tsub_dom (dir_list_add_env t_sub l) ds \\<rbrakk> \\<Longrightarrow> dom_list_set l \\<subseteq> ds\"      \n  apply (induct l)\n   apply (auto)\n   apply (simp add: tsub_dom_def)\n   apply (simp add: dir_add_env_def)\n  apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and x=\"a\" in add_tsub_dom_rev)\n   apply (auto)\n  done    \n    \n  \n    (* #### p_exp range *)\n    \nfun pvar_set_perm where\n  \"pvar_set_perm (SPerm p) = {}\"\n| \"pvar_set_perm (SVar x) = {x}\" \n  \nfun pvar_set where\n  \"pvar_set (XPerm p) = pvar_set_perm p\"\n| \"pvar_set (XType a) = {}\"\n| \"pvar_set (XComp px qx) = (pvar_set px \\<union> pvar_set qx)\"\n| \"pvar_set (XLift px q) = (pvar_set px \\<union> pvar_set_perm q)\"    \n| \"pvar_set (XIfZero px qx) = (pvar_set px \\<union> pvar_set qx)\"  \n  \ndefinition pvar_range where\n  \"pvar_range r_sv ds = (\\<forall> a. pvar_set (r_sv a) \\<subseteq> ds)\"  \n  \nlemma empty_pvar_range: \"pvar_range empty_var_env ds\"  \n  apply (simp add: pvar_range_def)\n  apply (simp add: empty_var_env_def)\n  done\n    \nlemma comp_pvar_range: \"\\<lbrakk> pvar_range r_sv ds; pvar_range r_xv ds \\<rbrakk> \\<Longrightarrow> pvar_range (comp_var_env r_sv r_xv) ds\"    \n  apply (simp add: pvar_range_def)\n  apply (simp add: comp_var_env_def)\n  done\n    \nlemma lift_pvar_range: \"\\<lbrakk> pvar_range r_sv ds; pvar_set_perm p \\<subseteq> ds \\<rbrakk> \\<Longrightarrow> pvar_range (lift_var_env r_sv p) ds\"    \n  apply (simp add: pvar_range_def)\n  apply (simp add: lift_var_env_def)\n  done\n\nfun tvar_set where\n  \"tvar_set (XPerm p) = {}\"\n| \"tvar_set (XType a) = {a}\"\n| \"tvar_set (XComp px qx) = (tvar_set px \\<union> tvar_set qx)\"\n| \"tvar_set (XLift px q) = (tvar_set px)\"    \n| \"tvar_set (XIfZero px qx) = (tvar_set px \\<union> tvar_set qx)\"  \n  \ndefinition tvar_range where\n  \"tvar_range r_sv ds = (\\<forall> a. tvar_set (r_sv a) \\<subseteq> ds)\"      \n \nlemma empty_tvar_range: \"tvar_range empty_var_env ds\"  \n  apply (simp add: tvar_range_def)\n  apply (simp add: empty_var_env_def)\n  done\n    \nlemma comp_tvar_range: \"\\<lbrakk> tvar_range r_sv ds; tvar_range r_xv ds \\<rbrakk> \\<Longrightarrow> tvar_range (comp_var_env r_sv r_xv) ds\"    \n  apply (simp add: tvar_range_def)\n  apply (simp add: comp_var_env_def)\n  done\n    \nlemma lift_tvar_range: \"\\<lbrakk> tvar_range r_sv ds; tvar_set_perm p \\<subseteq> ds \\<rbrakk> \\<Longrightarrow> tvar_range (lift_var_env r_sv p) ds\"    \n  apply (simp add: tvar_range_def)\n  apply (simp add: lift_var_env_def)\n  done    \n  \nlemma subset_pvar_range: \"\\<lbrakk> pvar_range p_sub ds; ds \\<subseteq> ds' \\<rbrakk> \\<Longrightarrow> pvar_range p_sub ds'\"  \n  apply (simp add: pvar_range_def)\n  apply (auto)\n  done  \n  \nlemma set_diff_subset: \"\\<lbrakk> ds3 \\<subseteq> ds4; ds \\<subseteq> ds2 \\<rbrakk> \\<Longrightarrow> set_diff ds3 ds2 \\<subseteq> set_diff ds4 ds\"    \n  apply (simp add: set_diff_def)\n  apply (auto)\n  done\n    \nlemma ifz_pvar_range: \"\\<lbrakk> pvar_range r_sv ds; pvar_set px \\<subseteq> ds \\<rbrakk> \\<Longrightarrow> pvar_range (ifz_var_env px r_sv) ds\"    \n  apply (simp add: pvar_range_def)\n  apply (simp add: ifz_var_env_def)\n  done      \n\nlemma rem_pvar_range: \"\\<lbrakk> pvar_range r_sv ds \\<rbrakk> \\<Longrightarrow> pvar_range (rem_var_env r_sv x) ds\"    \n  apply (simp add: pvar_range_def)\n  apply (simp add: rem_var_env_def)\n  done     \n    \nlemma comp_pvar_range_rev1: \"\\<lbrakk> pvar_range (comp_var_env r_sv r_xv) ds \\<rbrakk> \\<Longrightarrow> pvar_range r_sv ds\"    \n  apply (simp add: pvar_range_def)\n  apply (simp add: comp_var_env_def)\n  apply (auto)\n  apply (erule_tac x=\"a\" in allE)\n  apply (case_tac \"r_sv a = XPerm (SPerm NoPerm) \\<and> r_xv a = XPerm (SPerm NoPerm)\")\n   apply (auto)\n  done\n\nlemma comp_pvar_range_rev2: \"\\<lbrakk> pvar_range (comp_var_env r_sv r_xv) ds \\<rbrakk> \\<Longrightarrow> pvar_range r_xv ds\"    \n  apply (simp add: pvar_range_def)\n  apply (simp add: comp_var_env_def)\n  apply (auto)\n  apply (erule_tac x=\"a\" in allE)\n  apply (case_tac \"r_sv a = XPerm (SPerm NoPerm) \\<and> r_xv a = XPerm (SPerm NoPerm)\")\n   apply (auto)\n  done\n    \nlemma dir_add_eq_permx: \"\\<lbrakk> tvar_set px \\<subseteq> ds; a \\<notin> ds \\<rbrakk> \\<Longrightarrow>\n  dir_subst_permx (dir_add_env t_sub a tau) p_sub px = dir_subst_permx t_sub p_sub px\"    \n  apply (induct px)\n      apply (auto)\n  apply (case_tac \"t_sub x\")\n   apply (auto)\n   apply (simp_all add: dir_add_env_def)\n   apply (auto)\n  done\n    \nlemma dir_add_cancel_use_env_ih: \"\\<lbrakk> tvar_range r_sv ds; a \\<notin> ds \\<rbrakk> \\<Longrightarrow>\n  dir_subst_penv (dir_add_env t_sub a tau) p_sub r_sv x = dir_subst_penv t_sub p_sub r_sv x\"       \n  apply (simp add: dir_subst_penv_def)\n  apply (cut_tac t_sub=\"t_sub\" and a=\"a\" and ds=\"ds\" and px=\"r_sv x\" in dir_add_eq_permx)\n    apply (simp add: tvar_range_def)\n   apply (simp_all)\n  done\n    \nlemma dir_list_add_cancel_use_env_ih: \"\\<lbrakk> tvar_range r_sv ds; fresh_list ds (dom_list l) \\<rbrakk> \\<Longrightarrow>\n  dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv x = dir_subst_penv t_sub p_sub r_sv x\"       \n  apply (induct l)\n   apply (auto)\n  apply (simp add: dir_subst_penv_def)\n  apply (cut_tac t_sub=\"dir_list_add_env t_sub l\" and p_sub=\"p_sub\" and a=\"a\" and tau=\"b\" and x=\"x\" and ds=\"ds\" in dir_add_cancel_use_env_ih)\n    apply (auto)\n   apply (simp add: fresh_list_def)\n   apply (auto)\n  apply (simp add: dir_subst_penv_def)\n  apply (simp add: fresh_list_def)\n  done\n    \nlemma dir_list_add_cancel_use_env: \"\\<lbrakk> tvar_range r_sv ds; fresh_list ds (dom_list l) \\<rbrakk> \\<Longrightarrow>\n  dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv = dir_subst_penv t_sub p_sub r_sv\"    \n  apply (case_tac \"\\<forall> x. dir_subst_penv (dir_list_add_env t_sub l) p_sub r_sv x = dir_subst_penv t_sub p_sub r_sv x\")\n   apply (auto)\n  apply (cut_tac t_sub=\"t_sub\" and x=\"x\" in dir_list_add_cancel_use_env_ih)\n    apply (auto)\n  done    \n    \nlemma ifz_tvar_range: \"\\<lbrakk> tvar_range r_sv ds; tvar_set px \\<subseteq> ds \\<rbrakk> \\<Longrightarrow> tvar_range (ifz_var_env px r_sv) ds\"    \n  apply (simp add: tvar_range_def)\n  apply (simp add: ifz_var_env_def)\n  done         \n    \nlemma infer_s_sub_range: \"\\<lbrakk> infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds' \\<rbrakk> \\<Longrightarrow> pvar_range r_sv (set_diff ds' ds) \\<and> pvar_range r_xv (set_diff ds' ds)\"    \n  apply (induct e arbitrary: env_v ds tau_v r_sv r_xv r_mv c_list ds')\n        apply (auto)\n    (* const + op + var cases *)\n             apply (rule_tac empty_pvar_range)\n            apply (rule_tac empty_pvar_range)\n           apply (simp add: pvar_range_def)\n           apply (simp add: one_var_env_def)\n          apply (simp add: pvar_range_def)\n          apply (simp add: one_var_env_def)\n    (* pair case *)\n         apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n          apply (auto)\n         apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n          apply (auto)\n         apply (rule_tac comp_pvar_range)\n          apply (rule_tac comp_pvar_range)\n           apply (rule_tac ds=\"set_diff ds2 ds\" in subset_pvar_range)\n            apply (simp)\n           apply (simp add: set_diff_def)\n           apply (auto)\n          apply (rule_tac lift_pvar_range)\n           apply (rule_tac ds=\"set_diff ds2 ds\" in subset_pvar_range)\n            apply (simp)\n           apply (simp add: set_diff_def)\n           apply (auto)\n          apply (simp add: set_diff_def)\n          apply (auto)\n          apply (rule_tac comp_pvar_range)\n          apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n           apply (simp)\n          apply (simp add: set_diff_def)\n          apply (auto)\n         apply (rule_tac lift_pvar_range)\n          apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n           apply (simp)\n          apply (simp add: set_diff_def)\n          apply (auto)\n         apply (simp add: set_diff_def)\n         apply (auto)\n        apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n         apply (auto)\n        apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n         apply (auto)\n        apply (rule_tac ifz_pvar_range)\n         apply (rule_tac comp_pvar_range)\n          apply (rule_tac lift_pvar_range)\n           apply (rule_tac ds=\"set_diff ds2 ds\" in subset_pvar_range)\n            apply (auto)\n           apply (simp add: set_diff_def)\n           apply (auto)\n          apply (simp add: set_diff_def)\n          apply (auto)\n         apply (rule_tac lift_pvar_range)\n          apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n           apply (auto)\n          apply (simp add: set_diff_def)\n          apply (auto)\n         apply (simp add: set_diff_def)\n         apply (auto)\n        apply (simp add: set_diff_def)\n        apply (auto)\n    (* if case *)\n       apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n        apply (auto)\n       apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n        apply (auto)\n       apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n        apply (auto)\n       apply (rule_tac comp_pvar_range)\n        apply (rule_tac ds=\"set_diff ds2 ds\" in subset_pvar_range)\n         apply (simp)\n        apply (simp add: set_diff_def)\n        apply (auto)\n       apply (rule_tac comp_pvar_range)\n        apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n         apply (simp)\n        apply (simp add: set_diff_def)\n        apply (auto)\n       apply (rule_tac ds=\"set_diff ds' ds3\" in subset_pvar_range)\n        apply (simp)\n       apply (simp add: set_diff_def)\n       apply (auto)\n      apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n       apply (auto)\n      apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n       apply (auto)\n      apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n       apply (auto)\n      apply (rule_tac comp_pvar_range)\n       apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n        apply (auto)\n       apply (simp add: set_diff_def)\n       apply (auto)\n      apply (rule_tac ds=\"set_diff ds' ds3\" in subset_pvar_range)\n       apply (auto)\n      apply (simp add: set_diff_def)\n      apply (auto)\n    (* lam case *)\n     apply (cut_tac ds=\"insert a ds\" and ds'=\"ds2\" in infer_x_subset)\n      apply (auto)\n     apply (rule_tac rem_pvar_range)\n     apply (rule_tac ds=\"set_diff ds2 (insert a ds)\" in subset_pvar_range)\n      apply (simp)\n     apply (simp add: set_diff_def)\n    apply (auto)\n    apply (cut_tac ds=\"insert a ds\" and ds'=\"ds2\" in infer_x_subset)\n     apply (auto)\n    apply (rule_tac rem_pvar_range)\n    apply (rule_tac ds=\"set_diff ds2 (insert a ds)\" in subset_pvar_range)\n     apply (simp)\n    apply (simp add: set_diff_def)\n    apply (auto)\n    (* app case *)\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n    apply (auto)\n   apply (rule_tac comp_pvar_range)\n    apply (rule_tac comp_pvar_range)\n     apply (rule_tac ds=\"set_diff ds2 ds\" in subset_pvar_range)\n      apply (simp)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (rule_tac ds=\"set_diff ds2 ds\" in subset_pvar_range)\n     apply (simp)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (rule_tac comp_pvar_range)\n    apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n     apply (simp)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (rule_tac lift_pvar_range)\n    apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n     apply (simp)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (simp add: set_diff_def)\n   apply (auto)\n   apply (case_tac \"p \\<in> ds3\")\n    apply (simp add: fresh_list_def)\n    apply (auto)\n  apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n   apply (auto)\n  apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n   apply (auto)\n  apply (rule_tac ifz_pvar_range)\n   apply (rule_tac comp_pvar_range)\n    apply (rule_tac ds=\"set_diff ds2 ds\" in subset_pvar_range)\n     apply (auto)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (rule_tac lift_pvar_range)\n    apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n     apply (auto)\n    apply (simp add: set_diff_def)\n    apply (auto)\n   apply (simp add: set_diff_def)\n   apply (auto)\n   apply (case_tac \"p \\<in> ds3\")\n    apply (simp add: fresh_list_def)\n    apply (auto)(*\n  apply (simp add: set_diff_def)\n  apply (case_tac \"p_a \\<in> ds3\")\n   apply (simp add: fresh_list_def)\n   apply (auto)*)\n  done\n\nlemma add_sub_range: \"\\<lbrakk> sub_range env_v ds \\<rbrakk> \\<Longrightarrow> sub_range (add_env env_v x a) (insert a ds)\"      \n  apply (simp add: sub_range_def)\n  apply (simp add: add_env_def)\n  apply (auto)\n  apply (erule_tac x=\"xa\" in allE)\n  apply (case_tac \"env_v xa\")\n   apply (auto)\n  done\n    \nlemma infer_m_sub_range: \"\\<lbrakk> infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds' \\<rbrakk> \\<Longrightarrow> pvar_range r_mv (set_diff ds' ds)\"    \n  apply (induct e arbitrary: env_v ds tau_v r_sv r_xv r_mv c_list ds')\n        apply (auto)\n    (* const + op + var cases *)\n        apply (rule_tac empty_pvar_range)\n       apply (rule_tac empty_pvar_range)\n      apply (simp add: pvar_range_def)\n      apply (simp add: one_var_env_def)\n    (* pair case *)\n     apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n      apply (auto)\n     apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n      apply (auto)\n     apply (rule_tac comp_pvar_range)\n      apply (rule_tac ds=\"set_diff ds2 ds\" in subset_pvar_range)\n       apply (simp)\n      apply (simp add: set_diff_def)\n      apply (auto)\n     apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n      apply (simp)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    (* if case *)\n    apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n     apply (auto)\n    apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n     apply (auto)\n    apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n     apply (auto)\n    apply (rule_tac comp_pvar_range)\n     apply (rule_tac ds=\"set_diff ds2 ds\" in subset_pvar_range)\n      apply (auto)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (rule_tac comp_pvar_range)\n     apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n      apply (auto)\n     apply (simp add: set_diff_def)\n     apply (auto)\n    apply (rule_tac ds=\"set_diff ds' ds3\" in subset_pvar_range)\n     apply (auto)\n    apply (simp add: set_diff_def)\n    apply (auto)\n    (* lam case *)\n   apply (rule_tac empty_pvar_range)\n    (* app case *)\n  apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n   apply (auto)\n  apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n   apply (auto)\n  apply (rule_tac comp_pvar_range)\n   apply (rule_tac ds=\"set_diff ds2 ds\" in subset_pvar_range)\n    apply (rule_tac comp_pvar_range)\n     apply (auto)\n    apply (cut_tac env_v=\"env_v\" and r_xv=\"r_x1\" and ds'=\"ds2\" in infer_s_sub_range)\n     apply (auto)\n   apply (simp add: set_diff_def)\n   apply (auto)\n  apply (rule_tac comp_pvar_range)\n   apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n    apply (auto)\n   apply (simp add: set_diff_def)\n   apply (auto)\n  apply (rule_tac lift_pvar_range)\n   apply (rule_tac ds=\"set_diff ds3 ds2\" in subset_pvar_range)\n    apply (auto)\n    apply (cut_tac env_v=\"env_v\" and r_xv=\"r_x2\" and ds'=\"ds3\" in infer_s_sub_range)\n     apply (auto)\n   apply (simp add: set_diff_def)\n   apply (auto)\n  apply (case_tac \"p \\<in> ds3\")\n   apply (simp add: fresh_list_def)\n   apply (auto)\n  apply (simp add: set_diff_def)\n  apply (auto)\n  done\n    \nlemma rem_tvar_range: \"\\<lbrakk> tvar_range r_sv ds \\<rbrakk> \\<Longrightarrow> tvar_range (rem_var_env r_sv x) ds\"    \n  apply (simp add: tvar_range_def)\n  apply (simp add: rem_var_env_def)\n  done      \n    \nlemma subset_tvar_range: \"\\<lbrakk> tvar_range r_sv ds; ds \\<subseteq> ds' \\<rbrakk> \\<Longrightarrow> tvar_range r_sv ds'\"\n  apply (simp add: tvar_range_def)\n  apply (auto)\n  done\n    \nlemma infer_tvar_range: \"\\<lbrakk> infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; sub_range env_v ds \\<rbrakk> \\<Longrightarrow>\n    tvar_range r_sv ds' \\<and> tvar_range r_xv ds'\" \n  apply (induct e arbitrary: env_v ds tau_v r_sv r_xv r_mv c_list ds')\n        apply (auto)\n    (* const + op + var cases *)\n             apply (rule_tac empty_tvar_range)\n            apply (rule_tac empty_tvar_range)\n           apply (simp add: tvar_range_def)\n           apply (simp add: one_var_env_def)\n           apply (simp add: sub_range_def)\n           apply (erule_tac x=\"owner_name x\" in allE)\n           apply (auto)\n          apply (simp add: tvar_range_def)\n          apply (simp add: one_var_env_def)\n          apply (simp add: sub_range_def)\n          apply (erule_tac x=\"owner_name x\" in allE)\n          apply (auto)\n    (* pair case *)\n         apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n          apply (auto)\n         apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n          apply (auto)\n         apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n           apply (auto)\n         apply (rule_tac comp_tvar_range)\n          apply (rule_tac ds=\"ds2\" in subset_tvar_range)\n           apply (auto)\n          apply (rule_tac comp_tvar_range)\n           apply (simp)\n          apply (rule_tac lift_tvar_range)\n           apply (auto)\n         apply (rule_tac ds=\"ds3\" in subset_tvar_range)\n          apply (auto)\n         apply (rule_tac comp_tvar_range)\n          apply (simp)\n         apply (rule_tac lift_tvar_range)\n          apply (auto)\n        apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n         apply (auto)\n        apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n         apply (auto)\n        apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n          apply (auto)\n        apply (rule_tac ifz_tvar_range)\n         apply (rule_tac comp_tvar_range)\n          apply (rule_tac lift_tvar_range)\n           apply (rule_tac ds=\"ds2\" in subset_tvar_range)\n            apply (auto)\n        apply (rule_tac lift_tvar_range)\n         apply (auto)\n        apply (rule_tac ds=\"ds3\" in subset_tvar_range)\n         apply (auto)\n    (* if case *)\n       apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n        apply (auto)\n       apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n        apply (auto)\n       apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n        apply (auto)\n       apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n         apply (auto)\n       apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and ds'=\"ds3\" in subset_sub_range)\n         apply (auto)\n       apply (rule_tac comp_tvar_range)\n        apply (rule_tac ds=\"ds2\" in subset_tvar_range)\n         apply (auto)\n       apply (rule_tac comp_tvar_range)\n        apply (auto)\n       apply (rule_tac ds=\"ds3\" in subset_tvar_range)\n        apply (auto)\n      apply (rule_tac ds=\"ds'\" in subset_tvar_range)\n       apply (auto)\n      apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n       apply (auto)\n      apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n       apply (auto)\n      apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n       apply (auto)\n      apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n        apply (auto)\n      apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and ds'=\"ds3\" in subset_sub_range)\n        apply (auto)\n      apply (rule_tac comp_tvar_range)\n       apply (auto)\n      apply (rule_tac ds=\"ds3\" in subset_tvar_range)\n       apply (auto)\n    (* lam case *)\n     apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and x=\"Var x1a\" and a=\"a\" in add_sub_range)\n      apply (auto)\n     apply (rule_tac rem_tvar_range)\n     apply (rule_tac ds=\"ds2\" in subset_tvar_range)\n      apply (auto)\n    apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and x=\"Var x1a\" and a=\"a\" in add_sub_range)\n     apply (auto)\n    apply (rule_tac rem_tvar_range)\n    apply (rule_tac ds=\"ds2\" in subset_tvar_range)\n     apply (auto)\n    (* app case *)\n   apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n    apply (auto)\n   apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n     apply (auto)\n   apply (rule_tac comp_tvar_range)\n    apply (rule_tac ds=\"ds2\" in subset_tvar_range)\n     apply (auto)\n    apply (rule_tac comp_tvar_range)\n     apply (auto)\n   apply (rule_tac ds=\"ds3\" in subset_tvar_range)\n    apply (auto)\n   apply (rule_tac comp_tvar_range)\n    apply (auto)\n   apply (rule_tac lift_tvar_range)\n    apply (auto)\n  apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n   apply (auto)\n  apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n   apply (auto)\n  apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n    apply (auto)\n  apply (rule_tac ifz_tvar_range)\n   apply (rule_tac comp_tvar_range)\n    apply (rule_tac ds=\"ds2\" in subset_tvar_range)\n     apply (auto)\n  apply (rule_tac lift_tvar_range)\n   apply (rule_tac ds=\"ds3\" in subset_tvar_range)\n    apply (auto)\n  done  \n\nlemma infer_m_tvar_range: \"\\<lbrakk> infer_type env_v ds e tau_v r_sv r_xv r_mv c_list ds'; sub_range env_v ds \\<rbrakk> \\<Longrightarrow> tvar_range r_mv ds'\"    \n  apply (induct e arbitrary: env_v ds tau_v r_sv r_xv r_mv c_list ds')\n        apply (auto)\n    (* const + op + var cases *)\n        apply (rule_tac empty_tvar_range)\n       apply (rule_tac empty_tvar_range)\n      apply (simp add: tvar_range_def)\n      apply (simp add: one_var_env_def)\n      apply (simp add: sub_range_def)\n      apply (erule_tac x=\"owner_name x\" in allE)\n      apply (auto)\n    (* pair case *)\n     apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n      apply (auto)\n     apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n      apply (auto)\n     apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n       apply (auto)\n     apply (rule_tac comp_tvar_range)\n      apply (rule_tac ds=\"ds2\" in subset_tvar_range)\n       apply (auto)\n     apply (rule_tac ds=\"ds3\" in subset_tvar_range)\n      apply (auto)\n    (* if case *)\n    apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n     apply (auto)\n    apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n     apply (auto)\n    apply (cut_tac ds=\"ds3\" and ds'=\"ds'\" in infer_x_subset)\n     apply (auto)\n    apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n      apply (auto)\n    apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and ds'=\"ds3\" in subset_sub_range)\n      apply (auto)\n    apply (rule_tac comp_tvar_range)\n     apply (rule_tac ds=\"ds2\" in subset_tvar_range)\n      apply (auto)\n    apply (rule_tac comp_tvar_range)\n     apply (rule_tac ds=\"ds3\" in subset_tvar_range)\n      apply (auto)\n    (* lam case *)\n  apply (rule_tac empty_tvar_range)\n    (* app case *)\n  apply (cut_tac ds=\"ds\" and ds'=\"ds2\" in infer_x_subset)\n   apply (auto)\n  apply (cut_tac ds=\"ds2\" and ds'=\"ds3\" in infer_x_subset)\n   apply (auto)\n  apply (cut_tac env_v=\"env_v\" and ds=\"ds\" and ds'=\"ds2\" in subset_sub_range)\n    apply (auto)\n  apply (rule_tac comp_tvar_range)\n   apply (rule_tac ds=\"ds2\" in subset_tvar_range)\n    apply (rule_tac comp_tvar_range)\n     apply (auto)\n   apply (cut_tac env_v=\"env_v\" and r_xv=\"r_x1\" and ds'=\"ds2\" in infer_tvar_range)\n     apply (auto)\n  apply (rule_tac comp_tvar_range)\n   apply (rule_tac ds=\"ds3\" in subset_tvar_range)\n    apply (auto)\n  apply (rule_tac lift_tvar_range)\n   apply (rule_tac ds=\"ds3\" in subset_tvar_range)\n    apply (auto)\n  apply (cut_tac env_v=\"env_v\" and ds=\"ds2\" and r_xv=\"r_x2\" and ds'=\"ds3\" in infer_tvar_range)\n    apply (auto)\n  done    \n    \nfun tvar_type where\n  \"tvar_type IntScheme = {}\"\n  | \"tvar_type BoolScheme = {}\"\n  | \"tvar_type UnitScheme = {}\"\n  | \"tvar_type (VarScheme a) = {a}\"\n  | \"tvar_type (ArrayScheme tau) = tvar_type tau\"\n  | \"tvar_type (PairScheme t1 t2 p) = tvar_type t1 \\<union> tvar_type t2\"\n  | \"tvar_type (FunScheme t1 t2 p a) = tvar_type t1 \\<union> tvar_type t2\"\n  | \"tvar_type (ChanScheme tau c_end) = tvar_type tau\"     \n    \nend\n", "meta": {"author": "anon-ef", "repo": "perm_lang_ef2", "sha": "0fcb6e4c175193cc7b94f297a8aaa605f502d711", "save_path": "github-repos/isabelle/anon-ef-perm_lang_ef2", "path": "github-repos/isabelle/anon-ef-perm_lang_ef2/perm_lang_ef2-0fcb6e4c175193cc7b94f297a8aaa605f502d711/perm_ref/InferRange.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.538983220687684, "lm_q2_score": 0.4649015713733885, "lm_q1q2_score": 0.25057414624159413}}
{"text": "(*  Title:      HOL/Auth/CertifiedEmail.thy\n    Author:     Giampaolo Bella, Christiano Longo and Lawrence C Paulson\n*)\n\nsection\\<open>The Certified Electronic Mail Protocol by Abadi et al.\\<close>\n\ntheory CertifiedEmail imports Public begin\n\nabbreviation\n  TTP :: agent where\n  \"TTP == Server\"\n\nabbreviation\n  RPwd :: \"agent => key\" where\n  \"RPwd == shrK\"\n\n \n(*FIXME: the four options should be represented by pairs of 0 or 1.\n  Right now only BothAuth is modelled.*)\nconsts\n  NoAuth   :: nat\n  TTPAuth  :: nat\n  SAuth    :: nat\n  BothAuth :: nat\n\ntext\\<open>We formalize a fixed way of computing responses.  Could be better.\\<close>\ndefinition \"response\" :: \"agent => agent => nat => msg\" where\n   \"response S R q == Hash \\<lbrace>Agent S, Key (shrK R), Nonce q\\<rbrace>\"\n\n\ninductive_set certified_mail :: \"event list set\"\n  where\n\n  Nil: \\<comment>\\<open>The empty trace\\<close>\n     \"[] \\<in> certified_mail\"\n\n| Fake: \\<comment>\\<open>The Spy may say anything he can say.  The sender field is correct,\n          but agents don't use that information.\\<close>\n      \"[| evsf \\<in> certified_mail; X \\<in> synth(analz(spies evsf))|] \n       ==> Says Spy B X # evsf \\<in> certified_mail\"\n\n| FakeSSL: \\<comment>\\<open>The Spy may open SSL sessions with TTP, who is the only agent\n    equipped with the necessary credentials to serve as an SSL server.\\<close>\n         \"[| evsfssl \\<in> certified_mail; X \\<in> synth(analz(spies evsfssl))|]\n          ==> Notes TTP \\<lbrace>Agent Spy, Agent TTP, X\\<rbrace> # evsfssl \\<in> certified_mail\"\n\n| CM1: \\<comment>\\<open>The sender approaches the recipient.  The message is a number.\\<close>\n \"[|evs1 \\<in> certified_mail;\n    Key K \\<notin> used evs1;\n    K \\<in> symKeys;\n    Nonce q \\<notin> used evs1;\n    hs = Hash\\<lbrace>Number cleartext, Nonce q, response S R q, Crypt K (Number m)\\<rbrace>;\n    S2TTP = Crypt(pubEK TTP) \\<lbrace>Agent S, Number BothAuth, Key K, Agent R, hs\\<rbrace>|]\n  ==> Says S R \\<lbrace>Agent S, Agent TTP, Crypt K (Number m), Number BothAuth, \n                 Number cleartext, Nonce q, S2TTP\\<rbrace> # evs1 \n        \\<in> certified_mail\"\n\n| CM2: \\<comment>\\<open>The recipient records @{term S2TTP} while transmitting it and her\n     password to @{term TTP} over an SSL channel.\\<close>\n \"[|evs2 \\<in> certified_mail;\n    Gets R \\<lbrace>Agent S, Agent TTP, em, Number BothAuth, Number cleartext, \n             Nonce q, S2TTP\\<rbrace> \\<in> set evs2;\n    TTP \\<noteq> R;  \n    hr = Hash \\<lbrace>Number cleartext, Nonce q, response S R q, em\\<rbrace> |]\n  ==> \n   Notes TTP \\<lbrace>Agent R, Agent TTP, S2TTP, Key(RPwd R), hr\\<rbrace> # evs2\n      \\<in> certified_mail\"\n\n| CM3: \\<comment>\\<open>@{term TTP} simultaneously reveals the key to the recipient and gives\n         a receipt to the sender.  The SSL channel does not authenticate \n         the client (@{term R}), but @{term TTP} accepts the message only \n         if the given password is that of the claimed sender, @{term R}.\n         He replies over the established SSL channel.\\<close>\n \"[|evs3 \\<in> certified_mail;\n    Notes TTP \\<lbrace>Agent R, Agent TTP, S2TTP, Key(RPwd R), hr\\<rbrace> \\<in> set evs3;\n    S2TTP = Crypt (pubEK TTP) \n                     \\<lbrace>Agent S, Number BothAuth, Key k, Agent R, hs\\<rbrace>;\n    TTP \\<noteq> R;  hs = hr;  k \\<in> symKeys|]\n  ==> \n   Notes R \\<lbrace>Agent TTP, Agent R, Key k, hr\\<rbrace> # \n   Gets S (Crypt (priSK TTP) S2TTP) # \n   Says TTP S (Crypt (priSK TTP) S2TTP) # evs3 \\<in> certified_mail\"\n\n| Reception:\n \"[|evsr \\<in> certified_mail; Says A B X \\<in> set evsr|]\n  ==> Gets B X#evsr \\<in> certified_mail\"\n\n\ndeclare Says_imp_knows_Spy [THEN analz.Inj, dest]\ndeclare analz_into_parts [dest]\n\n(*A \"possibility property\": there are traces that reach the end*)\nlemma \"[| Key K \\<notin> used []; K \\<in> symKeys |] ==> \n       \\<exists>S2TTP. \\<exists>evs \\<in> certified_mail.\n           Says TTP S (Crypt (priSK TTP) S2TTP) \\<in> set evs\"\napply (intro exI bexI)\napply (rule_tac [2] certified_mail.Nil\n                    [THEN certified_mail.CM1, THEN certified_mail.Reception,\n                     THEN certified_mail.CM2, \n                     THEN certified_mail.CM3]) \napply (possibility, auto) \ndone\n\n\nlemma Gets_imp_Says:\n \"[| Gets B X \\<in> set evs; evs \\<in> certified_mail |] ==> \\<exists>A. Says A B X \\<in> set evs\"\napply (erule rev_mp)\napply (erule certified_mail.induct, auto)\ndone\n\n\nlemma Gets_imp_parts_knows_Spy:\n     \"[|Gets A X \\<in> set evs; evs \\<in> certified_mail|] ==> X \\<in> parts(spies evs)\"\napply (drule Gets_imp_Says, simp)\napply (blast dest: Says_imp_knows_Spy parts.Inj) \ndone\n\nlemma CM2_S2TTP_analz_knows_Spy:\n \"[|Gets R \\<lbrace>Agent A, Agent B, em, Number AO, Number cleartext, \n              Nonce q, S2TTP\\<rbrace> \\<in> set evs;\n    evs \\<in> certified_mail|] \n  ==> S2TTP \\<in> analz(spies evs)\"\napply (drule Gets_imp_Says, simp) \napply (blast dest: Says_imp_knows_Spy analz.Inj) \ndone\n\nlemmas CM2_S2TTP_parts_knows_Spy = \n    CM2_S2TTP_analz_knows_Spy [THEN analz_subset_parts [THEN subsetD]]\n\nlemma hr_form_lemma [rule_format]:\n \"evs \\<in> certified_mail\n  ==> hr \\<notin> synth (analz (spies evs)) --> \n      (\\<forall>S2TTP. Notes TTP \\<lbrace>Agent R, Agent TTP, S2TTP, pwd, hr\\<rbrace>\n          \\<in> set evs --> \n      (\\<exists>clt q S em. hr = Hash \\<lbrace>Number clt, Nonce q, response S R q, em\\<rbrace>))\"\napply (erule certified_mail.induct)\napply (synth_analz_mono_contra, simp_all, blast+)\ndone \n\ntext\\<open>Cannot strengthen the first disjunct to @{term \"R\\<noteq>Spy\"} because\nthe fakessl rule allows Spy to spoof the sender's name.  Maybe can\nstrengthen the second disjunct with @{term \"R\\<noteq>Spy\"}.\\<close>\nlemma hr_form:\n \"[|Notes TTP \\<lbrace>Agent R, Agent TTP, S2TTP, pwd, hr\\<rbrace> \\<in> set evs;\n    evs \\<in> certified_mail|]\n  ==> hr \\<in> synth (analz (spies evs)) | \n      (\\<exists>clt q S em. hr = Hash \\<lbrace>Number clt, Nonce q, response S R q, em\\<rbrace>)\"\nby (blast intro: hr_form_lemma) \n\nlemma Spy_dont_know_private_keys [dest!]:\n    \"[|Key (privateKey b A) \\<in> parts (spies evs); evs \\<in> certified_mail|]\n     ==> A \\<in> bad\"\napply (erule rev_mp) \napply (erule certified_mail.induct, simp_all)\ntxt\\<open>Fake\\<close>\napply (blast dest: Fake_parts_insert_in_Un) \ntxt\\<open>Message 1\\<close>\napply blast  \ntxt\\<open>Message 3\\<close>\napply (frule_tac hr_form, assumption)\napply (elim disjE exE) \napply (simp_all add: parts_insert2) \n apply (force dest!: parts_insert_subset_Un [THEN [2] rev_subsetD] \n                     analz_subset_parts [THEN subsetD], blast) \ndone\n\nlemma Spy_know_private_keys_iff [simp]:\n    \"evs \\<in> certified_mail\n     ==> (Key (privateKey b A) \\<in> parts (spies evs)) = (A \\<in> bad)\"\nby blast \n\nlemma Spy_dont_know_TTPKey_parts [simp]:\n     \"evs \\<in> certified_mail ==> Key (privateKey b TTP) \\<notin> parts(spies evs)\" \nby simp\n\nlemma Spy_dont_know_TTPKey_analz [simp]:\n     \"evs \\<in> certified_mail ==> Key (privateKey b TTP) \\<notin> analz(spies evs)\"\nby auto\n\ntext\\<open>Thus, prove any goal that assumes that @{term Spy} knows a private key\nbelonging to @{term TTP}\\<close>\ndeclare Spy_dont_know_TTPKey_parts [THEN [2] rev_notE, elim!]\n\n\nlemma CM3_k_parts_knows_Spy:\n \"[| evs \\<in> certified_mail;\n     Notes TTP \\<lbrace>Agent A, Agent TTP,\n                 Crypt (pubEK TTP) \\<lbrace>Agent S, Number AO, Key K, \n                 Agent R, hs\\<rbrace>, Key (RPwd R), hs\\<rbrace> \\<in> set evs|]\n  ==> Key K \\<in> parts(spies evs)\"\napply (rotate_tac 1)\napply (erule rev_mp)\napply (erule certified_mail.induct, simp_all)\n   apply (blast  intro:parts_insertI)\ntxt\\<open>Fake SSL\\<close>\napply (blast dest: parts.Body) \ntxt\\<open>Message 2\\<close>\napply (blast dest!: Gets_imp_Says elim!: knows_Spy_partsEs)\ntxt\\<open>Message 3\\<close>\napply (metis parts_insertI)\ndone\n\nlemma Spy_dont_know_RPwd [rule_format]:\n    \"evs \\<in> certified_mail ==> Key (RPwd A) \\<in> parts(spies evs) --> A \\<in> bad\"\napply (erule certified_mail.induct, simp_all) \ntxt\\<open>Fake\\<close>\napply (blast dest: Fake_parts_insert_in_Un) \ntxt\\<open>Message 1\\<close>\napply blast  \ntxt\\<open>Message 3\\<close>\napply (frule CM3_k_parts_knows_Spy, assumption)\napply (frule_tac hr_form, assumption)\napply (elim disjE exE) \napply (simp_all add: parts_insert2) \napply (force dest!: parts_insert_subset_Un [THEN [2] rev_subsetD]\n                    analz_subset_parts [THEN subsetD])\ndone\n\n\nlemma Spy_know_RPwd_iff [simp]:\n    \"evs \\<in> certified_mail ==> (Key (RPwd A) \\<in> parts(spies evs)) = (A\\<in>bad)\"\nby (auto simp add: Spy_dont_know_RPwd) \n\nlemma Spy_analz_RPwd_iff [simp]:\n    \"evs \\<in> certified_mail ==> (Key (RPwd A) \\<in> analz(spies evs)) = (A\\<in>bad)\"\nby (metis Spy_know_RPwd_iff Spy_spies_bad_shrK analz.Inj analz_into_parts)\n\ntext\\<open>Unused, but a guarantee of sorts\\<close>\ntheorem CertAutenticity:\n     \"[|Crypt (priSK TTP) X \\<in> parts (spies evs); evs \\<in> certified_mail|] \n      ==> \\<exists>A. Says TTP A (Crypt (priSK TTP) X) \\<in> set evs\"\napply (erule rev_mp)\napply (erule certified_mail.induct, simp_all) \ntxt\\<open>Fake\\<close>\napply (blast dest: Spy_dont_know_private_keys Fake_parts_insert_in_Un)\ntxt\\<open>Message 1\\<close>\napply blast \ntxt\\<open>Message 3\\<close>\napply (frule_tac hr_form, assumption)\napply (elim disjE exE) \napply (simp_all add: parts_insert2 parts_insert_knows_A) \n apply (blast dest!: Fake_parts_sing_imp_Un, blast)\ndone\n\n\nsubsection\\<open>Proving Confidentiality Results\\<close>\n\nlemma analz_image_freshK [rule_format]:\n \"evs \\<in> certified_mail ==>\n   \\<forall>K KK. invKey (pubEK TTP) \\<notin> KK -->\n          (Key K \\<in> analz (Key`KK Un (spies evs))) =\n          (K \\<in> KK | Key K \\<in> analz (spies evs))\"\napply (erule certified_mail.induct)\napply (drule_tac [6] A=TTP in symKey_neq_priEK) \napply (erule_tac [6] disjE [OF hr_form]) \napply (drule_tac [5] CM2_S2TTP_analz_knows_Spy) \nprefer 9\napply (elim exE)\napply (simp_all add: synth_analz_insert_eq\n                     subset_trans [OF _ subset_insertI]\n                     subset_trans [OF _ Un_upper2] \n                del: image_insert image_Un add: analz_image_freshK_simps)\ndone\n\n\nlemma analz_insert_freshK:\n  \"[| evs \\<in> certified_mail;  KAB \\<noteq> invKey (pubEK TTP) |] ==>\n      (Key K \\<in> analz (insert (Key KAB) (spies evs))) =\n      (K = KAB | Key K \\<in> analz (spies evs))\"\nby (simp only: analz_image_freshK analz_image_freshK_simps)\n\ntext\\<open>@{term S2TTP} must have originated from a valid sender\n    provided @{term K} is secure.  Proof is surprisingly hard.\\<close>\n\nlemma Notes_SSL_imp_used:\n     \"[|Notes B \\<lbrace>Agent A, Agent B, X\\<rbrace> \\<in> set evs|] ==> X \\<in> used evs\"\nby (blast dest!: Notes_imp_used)\n\n\n(*The weaker version, replacing \"used evs\" by \"parts (spies evs)\", \n   isn't inductive: message 3 case can't be proved *)\nlemma S2TTP_sender_lemma [rule_format]:\n \"evs \\<in> certified_mail ==>\n    Key K \\<notin> analz (spies evs) -->\n    (\\<forall>AO. Crypt (pubEK TTP)\n           \\<lbrace>Agent S, Number AO, Key K, Agent R, hs\\<rbrace> \\<in> used evs -->\n    (\\<exists>m ctxt q. \n        hs = Hash\\<lbrace>Number ctxt, Nonce q, response S R q, Crypt K (Number m)\\<rbrace> &\n        Says S R\n           \\<lbrace>Agent S, Agent TTP, Crypt K (Number m), Number AO,\n             Number ctxt, Nonce q,\n             Crypt (pubEK TTP)\n              \\<lbrace>Agent S, Number AO, Key K, Agent R, hs \\<rbrace>\\<rbrace> \\<in> set evs))\" \napply (erule certified_mail.induct, analz_mono_contra)\napply (drule_tac [5] CM2_S2TTP_parts_knows_Spy, simp)\napply (simp add: used_Nil Crypt_notin_initState, simp_all)\ntxt\\<open>Fake\\<close>\napply (blast dest: Fake_parts_sing [THEN subsetD]\n             dest!: analz_subset_parts [THEN subsetD])  \ntxt\\<open>Fake SSL\\<close>\napply (blast dest: Fake_parts_sing [THEN subsetD]\n             dest: analz_subset_parts [THEN subsetD])  \ntxt\\<open>Message 1\\<close>\napply (clarsimp, blast)\ntxt\\<open>Message 2\\<close>\napply (simp add: parts_insert2, clarify) \napply (metis parts_cut Un_empty_left usedI)\ntxt\\<open>Message 3\\<close> \napply (blast dest: Notes_SSL_imp_used used_parts_subset_parts) \ndone \n\nlemma S2TTP_sender:\n \"[|Crypt (pubEK TTP) \\<lbrace>Agent S, Number AO, Key K, Agent R, hs\\<rbrace> \\<in> used evs;\n    Key K \\<notin> analz (spies evs);\n    evs \\<in> certified_mail|]\n  ==> \\<exists>m ctxt q. \n        hs = Hash\\<lbrace>Number ctxt, Nonce q, response S R q, Crypt K (Number m)\\<rbrace> &\n        Says S R\n           \\<lbrace>Agent S, Agent TTP, Crypt K (Number m), Number AO,\n             Number ctxt, Nonce q,\n             Crypt (pubEK TTP)\n              \\<lbrace>Agent S, Number AO, Key K, Agent R, hs\\<rbrace>\\<rbrace> \\<in> set evs\" \nby (blast intro: S2TTP_sender_lemma) \n\n\ntext\\<open>Nobody can have used non-existent keys!\\<close>\nlemma new_keys_not_used [simp]:\n    \"[|Key K \\<notin> used evs; K \\<in> symKeys; evs \\<in> certified_mail|]\n     ==> K \\<notin> keysFor (parts (spies evs))\"\napply (erule rev_mp) \napply (erule certified_mail.induct, simp_all) \ntxt\\<open>Fake\\<close>\napply (force dest!: keysFor_parts_insert) \ntxt\\<open>Message 1\\<close>\napply blast \ntxt\\<open>Message 3\\<close>\napply (frule CM3_k_parts_knows_Spy, assumption)\napply (frule_tac hr_form, assumption) \napply (force dest!: keysFor_parts_insert)\ndone\n\n\ntext\\<open>Less easy to prove @{term \"m'=m\"}.  Maybe needs a separate unicity\ntheorem for ciphertexts of the form @{term \"Crypt K (Number m)\"}, \nwhere @{term K} is secure.\\<close>\nlemma Key_unique_lemma [rule_format]:\n     \"evs \\<in> certified_mail ==>\n       Key K \\<notin> analz (spies evs) -->\n       (\\<forall>m cleartext q hs.\n        Says S R\n           \\<lbrace>Agent S, Agent TTP, Crypt K (Number m), Number AO,\n             Number cleartext, Nonce q,\n             Crypt (pubEK TTP) \\<lbrace>Agent S, Number AO, Key K, Agent R, hs\\<rbrace>\\<rbrace>\n          \\<in> set evs -->\n       (\\<forall>m' cleartext' q' hs'.\n       Says S' R'\n           \\<lbrace>Agent S', Agent TTP, Crypt K (Number m'), Number AO',\n             Number cleartext', Nonce q',\n             Crypt (pubEK TTP) \\<lbrace>Agent S', Number AO', Key K, Agent R', hs'\\<rbrace>\\<rbrace>\n          \\<in> set evs --> R' = R & S' = S & AO' = AO & hs' = hs))\" \napply (erule certified_mail.induct, analz_mono_contra, simp_all)\n prefer 2\n txt\\<open>Message 1\\<close>\n apply (blast dest!: Says_imp_knows_Spy [THEN parts.Inj] new_keys_not_used Crypt_imp_keysFor)\ntxt\\<open>Fake\\<close>\napply (auto dest!: usedI S2TTP_sender analz_subset_parts [THEN subsetD]) \ndone\n\ntext\\<open>The key determines the sender, recipient and protocol options.\\<close>\nlemma Key_unique:\n      \"[|Says S R\n           \\<lbrace>Agent S, Agent TTP, Crypt K (Number m), Number AO,\n             Number cleartext, Nonce q,\n             Crypt (pubEK TTP) \\<lbrace>Agent S, Number AO, Key K, Agent R, hs\\<rbrace>\\<rbrace>\n          \\<in> set evs;\n         Says S' R'\n           \\<lbrace>Agent S', Agent TTP, Crypt K (Number m'), Number AO',\n             Number cleartext', Nonce q',\n             Crypt (pubEK TTP) \\<lbrace>Agent S', Number AO', Key K, Agent R', hs'\\<rbrace>\\<rbrace>\n          \\<in> set evs;\n         Key K \\<notin> analz (spies evs);\n         evs \\<in> certified_mail|]\n       ==> R' = R & S' = S & AO' = AO & hs' = hs\"\nby (rule Key_unique_lemma, assumption+)\n\n\nsubsection\\<open>The Guarantees for Sender and Recipient\\<close>\n\ntext\\<open>A Sender's guarantee:\n      If Spy gets the key then @{term R} is bad and @{term S} moreover\n      gets his return receipt (and therefore has no grounds for complaint).\\<close>\ntheorem S_fairness_bad_R:\n      \"[|Says S R \\<lbrace>Agent S, Agent TTP, Crypt K (Number m), Number AO, \n                     Number cleartext, Nonce q, S2TTP\\<rbrace> \\<in> set evs;\n         S2TTP = Crypt (pubEK TTP) \\<lbrace>Agent S, Number AO, Key K, Agent R, hs\\<rbrace>;\n         Key K \\<in> analz (spies evs);\n         evs \\<in> certified_mail;\n         S\\<noteq>Spy|]\n      ==> R \\<in> bad & Gets S (Crypt (priSK TTP) S2TTP) \\<in> set evs\"\napply (erule rev_mp)\napply (erule ssubst)\napply (erule rev_mp)\napply (erule certified_mail.induct, simp_all)\ntxt\\<open>Fake\\<close>\napply spy_analz\ntxt\\<open>Fake SSL\\<close>\napply spy_analz\ntxt\\<open>Message 3\\<close>\napply (frule_tac hr_form, assumption)\napply (elim disjE exE) \napply (simp_all add: synth_analz_insert_eq  \n                     subset_trans [OF _ subset_insertI]\n                     subset_trans [OF _ Un_upper2] \n                del: image_insert image_Un add: analz_image_freshK_simps) \napply (simp_all add: symKey_neq_priEK analz_insert_freshK)\napply (blast dest: Notes_SSL_imp_used S2TTP_sender Key_unique)+\ndone\n\ntext\\<open>Confidentially for the symmetric key\\<close>\ntheorem Spy_not_see_encrypted_key:\n      \"[|Says S R \\<lbrace>Agent S, Agent TTP, Crypt K (Number m), Number AO, \n                     Number cleartext, Nonce q, S2TTP\\<rbrace> \\<in> set evs;\n         S2TTP = Crypt (pubEK TTP) \\<lbrace>Agent S, Number AO, Key K, Agent R, hs\\<rbrace>;\n         evs \\<in> certified_mail;\n         S\\<noteq>Spy; R \\<notin> bad|]\n      ==> Key K \\<notin> analz(spies evs)\"\nby (blast dest: S_fairness_bad_R) \n\n\ntext\\<open>Agent @{term R}, who may be the Spy, doesn't receive the key\n until @{term S} has access to the return receipt.\\<close> \ntheorem S_guarantee:\n     \"[|Says S R \\<lbrace>Agent S, Agent TTP, Crypt K (Number m), Number AO, \n                    Number cleartext, Nonce q, S2TTP\\<rbrace> \\<in> set evs;\n        S2TTP = Crypt (pubEK TTP) \\<lbrace>Agent S, Number AO, Key K, Agent R, hs\\<rbrace>;\n        Notes R \\<lbrace>Agent TTP, Agent R, Key K, hs\\<rbrace> \\<in> set evs;\n        S\\<noteq>Spy;  evs \\<in> certified_mail|]\n     ==> Gets S (Crypt (priSK TTP) S2TTP) \\<in> set evs\"\napply (erule rev_mp)\napply (erule ssubst)\napply (erule rev_mp)\napply (erule certified_mail.induct, simp_all)\ntxt\\<open>Message 1\\<close>\napply (blast dest: Notes_imp_used) \ntxt\\<open>Message 3\\<close>\napply (blast dest: Notes_SSL_imp_used S2TTP_sender Key_unique S_fairness_bad_R) \ndone\n\n\ntext\\<open>If @{term R} sends message 2, and a delivery certificate exists, \n then @{term R} receives the necessary key.  This result is also important\n to @{term S}, as it confirms the validity of the return receipt.\\<close>\ntheorem RR_validity:\n  \"[|Crypt (priSK TTP) S2TTP \\<in> used evs;\n     S2TTP = Crypt (pubEK TTP)\n               \\<lbrace>Agent S, Number AO, Key K, Agent R, \n                 Hash \\<lbrace>Number cleartext, Nonce q, r, em\\<rbrace>\\<rbrace>;\n     hr = Hash \\<lbrace>Number cleartext, Nonce q, r, em\\<rbrace>;\n     R\\<noteq>Spy;  evs \\<in> certified_mail|]\n  ==> Notes R \\<lbrace>Agent TTP, Agent R, Key K, hr\\<rbrace> \\<in> set evs\"\napply (erule rev_mp)\napply (erule ssubst)\napply (erule ssubst)\napply (erule certified_mail.induct, simp_all)\ntxt\\<open>Fake\\<close> \napply (blast dest: Fake_parts_sing [THEN subsetD]\n             dest!: analz_subset_parts [THEN subsetD])  \ntxt\\<open>Fake SSL\\<close>\napply (blast dest: Fake_parts_sing [THEN subsetD]\n            dest!: analz_subset_parts [THEN subsetD])  \ntxt\\<open>Message 2\\<close>\napply (drule CM2_S2TTP_parts_knows_Spy, assumption)\napply (force dest: parts_cut)\ntxt\\<open>Message 3\\<close>\napply (frule_tac hr_form, assumption)\napply (elim disjE exE, simp_all) \napply (blast dest: Fake_parts_sing [THEN subsetD]\n             dest!: analz_subset_parts [THEN subsetD]) \ndone\n\nend\n", "meta": {"author": "SEL4PROJ", "repo": "jormungand", "sha": "bad97f9817b4034cd705cd295a1f86af880a7631", "save_path": "github-repos/isabelle/SEL4PROJ-jormungand", "path": "github-repos/isabelle/SEL4PROJ-jormungand/jormungand-bad97f9817b4034cd705cd295a1f86af880a7631/case_study/isabelle/src/HOL/Auth/CertifiedEmail.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.603931819468636, "lm_q2_score": 0.41489884579676883, "lm_q1q2_score": 0.25057061483747967}}
{"text": "(*  Title:      HOL/Auth/n_mutualEx_on_ini.thy\n    Author:     Yongjian Li and Kaiqiang Duan, State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n    Copyright    2016 State Key Lab of Computer Science, Institute of Software, Chinese Academy of Sciences\n*)\n\nheader{*The n_mutualEx Protocol Case Study*} \n\ntheory n_mutualEx_on_ini imports n_mutualEx_base\nbegin\nlemma iniImply_inv__1:\nassumes a1: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__1  p__Inv3 p__Inv4)\"\nand a2: \"formEval (andList (allInitSpecs N)) s\"\nshows \"formEval f s\"\nusing a1 a2 by auto\n\nlemma iniImply_inv__2:\nassumes a1: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__2  p__Inv4)\"\nand a2: \"formEval (andList (allInitSpecs N)) s\"\nshows \"formEval f s\"\nusing a1 a2 by auto\n\nlemma iniImply_inv__3:\nassumes a1: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__3  p__Inv3 p__Inv4)\"\nand a2: \"formEval (andList (allInitSpecs N)) s\"\nshows \"formEval f s\"\nusing a1 a2 by auto\n\nlemma iniImply_inv__4:\nassumes a1: \"(\\<exists> p__Inv4. p__Inv4\\<le>N\\<and>f=inv__4  p__Inv4)\"\nand a2: \"formEval (andList (allInitSpecs N)) s\"\nshows \"formEval f s\"\nusing a1 a2 by auto\n\nlemma iniImply_inv__5:\nassumes a1: \"(\\<exists> p__Inv3 p__Inv4. p__Inv3\\<le>N\\<and>p__Inv4\\<le>N\\<and>p__Inv3~=p__Inv4\\<and>f=inv__5  p__Inv3 p__Inv4)\"\nand a2: \"formEval (andList (allInitSpecs N)) s\"\nshows \"formEval f s\"\nusing a1 a2 by auto\nend\n", "meta": {"author": "paraVerifier", "repo": "paraVerifier", "sha": "5de62b433a160bf8d714e0a5085a38b9dd8899f0", "save_path": "github-repos/isabelle/paraVerifier-paraVerifier", "path": "github-repos/isabelle/paraVerifier-paraVerifier/paraVerifier-5de62b433a160bf8d714e0a5085a38b9dd8899f0/proof_scripts/mutualEx/n_mutualEx_on_ini.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621765155565326, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.25046624158606906}}
{"text": "(*  Title:      JinjaThreads/Compiler/Correctness1.thy\n    Author:     Andreas Lochbihler, Tobias Nipkow\n\n    reminiscent of the Jinja theory Compiler/Correctness1\n*)\n\nheader {* \\isaheader{Semantic Correctness of Stage 1} *}\n\ntheory Correctness1 imports\n  J0J1Bisim\n  \"../J/DefAssPreservation\"\nbegin\n\nlemma finals_map_Val [simp]: \"finals (map Val vs)\"\nby(simp add: finals_iff)\n\ncontext J_heap_base begin\n\nlemma \\<tau>red0r_preserves_defass:\n  assumes wf: \"wf_J_prog P\"\n  shows \"\\<lbrakk> \\<tau>red0r extTA P t h (e, xs) (e', xs'); \\<D> e \\<lfloor>dom xs\\<rfloor> \\<rbrakk> \\<Longrightarrow> \\<D> e' \\<lfloor>dom xs'\\<rfloor>\"\nby(induct rule: rtranclp_induct2)(auto dest: red_preserves_defass[OF wf])\n\nlemma \\<tau>red0t_preserves_defass:\n  assumes wf: \"wf_J_prog P\"\n  shows \"\\<lbrakk> \\<tau>red0t extTA P t h (e, xs) (e', xs'); \\<D> e \\<lfloor>dom xs\\<rfloor> \\<rbrakk> \\<Longrightarrow> \\<D> e' \\<lfloor>dom xs'\\<rfloor>\"\nby(rule \\<tau>red0r_preserves_defass[OF wf])(rule tranclp_into_rtranclp)\n\nend\n\nlemma LAss_lem:\n  \"\\<lbrakk>x \\<in> set xs; size xs \\<le> size ys \\<rbrakk>\n  \\<Longrightarrow> m1 \\<subseteq>\\<^sub>m m2(xs[\\<mapsto>]ys) \\<Longrightarrow> m1(x\\<mapsto>y) \\<subseteq>\\<^sub>m m2(xs[\\<mapsto>]ys[index xs x := y])\"\napply(simp add:map_le_def)\napply(simp add:fun_upds_apply index_less_aux eq_sym_conv)\ndone\n\nlemma Block_lem:\nfixes l :: \"'a \\<rightharpoonup> 'b\"\nassumes 0: \"l \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] ls]\"\n    and 1: \"l' \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] ls', V\\<mapsto>v]\"\n    and hidden: \"V \\<in> set Vs \\<Longrightarrow> ls ! index Vs V = ls' ! index Vs V\"\n    and size: \"size ls = size ls'\"    \"size Vs < size ls'\"\nshows \"l'(V := l V) \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] ls']\"\nproof -\n  have \"l'(V := l V) \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] ls', V\\<mapsto>v](V := l V)\"\n    using 1 by(rule map_le_upd)\n  also have \"\\<dots> = [Vs [\\<mapsto>] ls'](V := l V)\" by simp\n  also have \"\\<dots> \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] ls']\"\n  proof (cases \"l V\")\n    case None thus ?thesis by simp\n  next\n    case (Some w)\n    hence \"[Vs [\\<mapsto>] ls] V = Some w\"\n      using 0 by(force simp add: map_le_def split:if_splits)\n    hence VinVs: \"V \\<in> set Vs\" and w: \"w = ls ! index Vs V\"\n      using size by(auto simp add:fun_upds_apply split:if_splits)\n    hence \"w = ls' ! index Vs V\" using hidden[OF VinVs] by simp\n    hence \"[Vs [\\<mapsto>] ls'](V := l V) = [Vs [\\<mapsto>] ls']\"\n      using Some size VinVs by(simp add:index_less_aux map_upds_upd_conv_index)\n    thus ?thesis by simp\n  qed\n  finally show ?thesis .\nqed\n\nsubsection {* Correctness proof *}\n\nlocale J0_J1_heap_base =\n  J: J_heap_base +\n  J1: J1_heap_base + \n  constrains addr2thread_id :: \"('addr :: addr) \\<Rightarrow> 'thread_id\"\n  and thread_id2addr :: \"'thread_id \\<Rightarrow> 'addr\"\n  and empty_heap :: \"'heap\"\n  and allocate :: \"'heap \\<Rightarrow> htype \\<Rightarrow> ('heap \\<times> 'addr) set\"\n  and typeof_addr :: \"'heap \\<Rightarrow> 'addr \\<rightharpoonup> htype\"\n  and heap_read :: \"'heap \\<Rightarrow> 'addr \\<Rightarrow> addr_loc \\<Rightarrow> 'addr val \\<Rightarrow> bool\"\n  and heap_write :: \"'heap \\<Rightarrow> 'addr \\<Rightarrow> addr_loc \\<Rightarrow> 'addr val \\<Rightarrow> 'heap \\<Rightarrow> bool\"\nbegin\n\nlemma ta_bisim01_extTA2J0_extTA2J1:\n  assumes wf: \"wf_J_prog P\"\n  and nt: \"\\<And>n T C M a h. \\<lbrakk> n < length \\<lbrace>ta\\<rbrace>\\<^bsub>t\\<^esub>; \\<lbrace>ta\\<rbrace>\\<^bsub>t\\<^esub> ! n = NewThread T (C, M, a) h \\<rbrakk>\n           \\<Longrightarrow> typeof_addr h a = \\<lfloor>Class_type C\\<rfloor> \\<and> (\\<exists>T meth D. P \\<turnstile> C sees M:[]\\<rightarrow>T =\\<lfloor>meth\\<rfloor> in D)\"\n  shows \"ta_bisim01 (extTA2J0 P ta) (extTA2J1 (compP1 P) ta)\"\napply(simp add: ta_bisim_def ta_upd_simps)\napply(auto intro!: list_all2_all_nthI)\napply(case_tac \"\\<lbrace>ta\\<rbrace>\\<^bsub>t\\<^esub> ! n\")\n  apply(auto simp add: bisim_red0_Red1_def)\napply(drule (1) nt)\napply(clarify)\napply(erule bisim_list_extTA2J0_extTA2J1[OF wf, simplified])\ndone\n\nlemma red_external_ta_bisim01: \n  \"\\<lbrakk> wf_J_prog P; P,t \\<turnstile> \\<langle>a\\<bullet>M(vs), h\\<rangle> -ta\\<rightarrow>ext \\<langle>va, h'\\<rangle> \\<rbrakk> \\<Longrightarrow> ta_bisim01 (extTA2J0 P ta) (extTA2J1 (compP1 P) ta)\"\napply(rule ta_bisim01_extTA2J0_extTA2J1, assumption)\napply(drule (1) red_external_new_thread_sees, auto simp add: in_set_conv_nth)\napply(drule red_ext_new_thread_heap, auto simp add: in_set_conv_nth)\ndone\n\nlemmas \\<tau>red1t_expr =\n  NewArray_\\<tau>red1t_xt Cast_\\<tau>red1t_xt InstanceOf_\\<tau>red1t_xt BinOp_\\<tau>red1t_xt1 BinOp_\\<tau>red1t_xt2 LAss_\\<tau>red1t\n  AAcc_\\<tau>red1t_xt1 AAcc_\\<tau>red1t_xt2 AAss_\\<tau>red1t_xt1 AAss_\\<tau>red1t_xt2 AAss_\\<tau>red1t_xt3\n  ALength_\\<tau>red1t_xt FAcc_\\<tau>red1t_xt FAss_\\<tau>red1t_xt1 FAss_\\<tau>red1t_xt2 Call_\\<tau>red1t_obj\n  Call_\\<tau>red1t_param Block_None_\\<tau>red1t_xt Block_\\<tau>red1t_Some Sync_\\<tau>red1t_xt InSync_\\<tau>red1t_xt\n  Seq_\\<tau>red1t_xt Cond_\\<tau>red1t_xt Throw_\\<tau>red1t_xt Try_\\<tau>red1t_xt\n\nlemmas \\<tau>red1r_expr =\n  NewArray_\\<tau>red1r_xt Cast_\\<tau>red1r_xt InstanceOf_\\<tau>red1r_xt BinOp_\\<tau>red1r_xt1 BinOp_\\<tau>red1r_xt2 LAss_\\<tau>red1r\n  AAcc_\\<tau>red1r_xt1 AAcc_\\<tau>red1r_xt2 AAss_\\<tau>red1r_xt1 AAss_\\<tau>red1r_xt2 AAss_\\<tau>red1r_xt3\n  ALength_\\<tau>red1r_xt FAcc_\\<tau>red1r_xt FAss_\\<tau>red1r_xt1 FAss_\\<tau>red1r_xt2 Call_\\<tau>red1r_obj\n  Call_\\<tau>red1r_param Block_None_\\<tau>red1r_xt Block_\\<tau>red1r_Some Sync_\\<tau>red1r_xt InSync_\\<tau>red1r_xt\n  Seq_\\<tau>red1r_xt Cond_\\<tau>red1r_xt Throw_\\<tau>red1r_xt Try_\\<tau>red1r_xt\n\ndefinition sim_move01 :: \n  \"'addr J1_prog \\<Rightarrow> 'thread_id \\<Rightarrow> ('addr, 'thread_id, 'heap) J0_thread_action \\<Rightarrow> 'addr expr \\<Rightarrow> 'addr expr1 \\<Rightarrow> 'heap\n  \\<Rightarrow> 'addr locals1 \\<Rightarrow> ('addr, 'thread_id, 'heap) external_thread_action \\<Rightarrow> 'addr expr1 \\<Rightarrow> 'heap \\<Rightarrow> 'addr locals1 \\<Rightarrow> bool\"\nwhere\n  \"sim_move01 P t ta0 e0 e h xs ta e' h' xs' \\<longleftrightarrow> \\<not> final e0 \\<and>\n  (if \\<tau>move0 P h e0 then h' = h \\<and> ta0 = \\<epsilon> \\<and> ta = \\<epsilon> \\<and> \\<tau>red1't P t h (e, xs) (e', xs')\n   else ta_bisim01 ta0 (extTA2J1 P ta) \\<and>\n     (if call e0 = None \\<or> call1 e = None\n      then (\\<exists>e'' xs''. \\<tau>red1'r P t h (e, xs) (e'', xs'') \\<and> False,P,t \\<turnstile>1 \\<langle>e'', (h, xs'')\\<rangle> -ta\\<rightarrow> \\<langle>e', (h', xs')\\<rangle> \\<and>\n                       \\<not> \\<tau>move1 P h e'')\n      else False,P,t \\<turnstile>1 \\<langle>e, (h, xs)\\<rangle> -ta\\<rightarrow> \\<langle>e', (h', xs')\\<rangle> \\<and> \\<not> \\<tau>move1 P h e))\"\n\ndefinition sim_moves01 :: \n  \"'addr J1_prog \\<Rightarrow> 'thread_id \\<Rightarrow> ('addr, 'thread_id, 'heap) J0_thread_action \\<Rightarrow> 'addr expr list \\<Rightarrow> 'addr expr1 list \\<Rightarrow> 'heap\n  \\<Rightarrow> 'addr locals1 \\<Rightarrow> ('addr, 'thread_id, 'heap) external_thread_action \\<Rightarrow> 'addr expr1 list \\<Rightarrow> 'heap \\<Rightarrow> 'addr locals1 \\<Rightarrow> bool\"\nwhere\n  \"sim_moves01 P t ta0 es0 es h xs ta es' h' xs' \\<longleftrightarrow> \\<not> finals es0 \\<and>\n  (if \\<tau>moves0 P h es0 then h' = h \\<and> ta0 = \\<epsilon> \\<and> ta = \\<epsilon> \\<and> \\<tau>reds1't P t h (es, xs) (es', xs')\n   else ta_bisim01 ta0 (extTA2J1 P ta) \\<and>\n     (if calls es0 = None \\<or> calls1 es = None\n      then (\\<exists>es'' xs''. \\<tau>reds1'r P t h (es, xs) (es'', xs'') \\<and> False,P,t \\<turnstile>1 \\<langle>es'', (h, xs'')\\<rangle> [-ta\\<rightarrow>] \\<langle>es', (h', xs')\\<rangle> \\<and> \n                        \\<not> \\<tau>moves1 P h es'')\n      else False,P,t \\<turnstile>1 \\<langle>es, (h, xs)\\<rangle> [-ta\\<rightarrow>] \\<langle>es', (h', xs')\\<rangle> \\<and> \\<not> \\<tau>moves1 P h es))\"\n\ndeclare \\<tau>red1t_expr [elim!] \\<tau>red1r_expr[elim!]\n\nlemma sim_move01_expr:\n  assumes \"sim_move01 P t ta0 e0 e h xs ta e' h' xs'\"\n  shows\n  \"sim_move01 P t ta0 (newA T\\<lfloor>e0\\<rceil>) (newA T\\<lfloor>e\\<rceil>) h xs ta (newA T\\<lfloor>e'\\<rceil>) h' xs'\"\n  \"sim_move01 P t ta0 (Cast T e0) (Cast T e) h xs ta (Cast T e') h' xs'\"\n  \"sim_move01 P t ta0 (e0 instanceof T) (e instanceof T) h xs ta (e' instanceof T) h' xs'\"\n  \"sim_move01 P t ta0 (e0 \\<guillemotleft>bop\\<guillemotright> e2) (e \\<guillemotleft>bop\\<guillemotright> e2') h xs ta (e' \\<guillemotleft>bop\\<guillemotright> e2') h' xs'\"\n  \"sim_move01 P t ta0 (Val v \\<guillemotleft>bop\\<guillemotright> e0) (Val v \\<guillemotleft>bop\\<guillemotright> e) h xs ta (Val v \\<guillemotleft>bop\\<guillemotright> e') h' xs'\"\n  \"sim_move01 P t ta0 (V := e0) (V' := e) h xs ta (V' := e') h' xs'\"\n  \"sim_move01 P t ta0 (e0\\<lfloor>e2\\<rceil>) (e\\<lfloor>e2'\\<rceil>) h xs ta (e'\\<lfloor>e2'\\<rceil>) h' xs'\"\n  \"sim_move01 P t ta0 (Val v\\<lfloor>e0\\<rceil>) (Val v\\<lfloor>e\\<rceil>) h xs ta (Val v\\<lfloor>e'\\<rceil>) h' xs'\"\n  \"sim_move01 P t ta0 (e0\\<lfloor>e2\\<rceil> := e3) (e\\<lfloor>e2'\\<rceil> := e3') h xs ta (e'\\<lfloor>e2'\\<rceil> := e3') h' xs'\"\n  \"sim_move01 P t ta0 (Val v\\<lfloor>e0\\<rceil> := e3) (Val v\\<lfloor>e\\<rceil> := e3') h xs ta (Val v\\<lfloor>e'\\<rceil> := e3') h' xs'\"\n  \"sim_move01 P t ta0 (AAss (Val v) (Val v') e0) (AAss (Val v) (Val v') e) h xs ta (AAss (Val v) (Val v') e') h' xs'\"\n  \"sim_move01 P t ta0 (e0\\<bullet>length) (e\\<bullet>length) h xs ta (e'\\<bullet>length) h' xs'\"\n  \"sim_move01 P t ta0 (e0\\<bullet>F{D}) (e\\<bullet>F'{D'}) h xs ta (e'\\<bullet>F'{D'}) h' xs'\"\n  \"sim_move01 P t ta0 (FAss e0 F D e2) (FAss e F' D' e2') h xs ta (FAss e' F' D' e2') h' xs'\"\n  \"sim_move01 P t ta0 (FAss (Val v) F D e0) (FAss (Val v) F' D' e) h xs ta (FAss (Val v) F' D' e') h' xs'\"\n  \"sim_move01 P t ta0 (e0\\<bullet>M(es)) (e\\<bullet>M(es')) h xs ta (e'\\<bullet>M(es')) h' xs'\"\n  \"sim_move01 P t ta0 ({V:T=vo; e0}) ({V':T=None; e}) h xs ta ({V':T=None; e'}) h' xs'\"\n  \"sim_move01 P t ta0 (sync(e0) e2) (sync\\<^bsub>V'\\<^esub>(e) e2') h xs ta (sync\\<^bsub>V'\\<^esub>(e') e2') h' xs'\"\n  \"sim_move01 P t ta0 (insync(a) e0) (insync\\<^bsub>V'\\<^esub>(a') e) h xs ta (insync\\<^bsub>V'\\<^esub>(a') e') h' xs'\"\n  \"sim_move01 P t ta0 (e0;;e2) (e;;e2') h xs ta (e';;e2') h' xs'\"\n  \"sim_move01 P t ta0 (if (e0) e2 else e3) (if (e) e2' else e3') h xs ta (if (e') e2' else e3') h' xs'\"\n  \"sim_move01 P t ta0 (throw e0) (throw e) h xs ta (throw e') h' xs'\"\n  \"sim_move01 P t ta0 (try e0 catch(C V) e2) (try e catch(C' V') e2') h xs ta (try e' catch(C' V') e2') h' xs'\"\nusing assms\napply(simp_all add: sim_move01_def final_iff \\<tau>red1r_Val \\<tau>red1t_Val split: split_if_asm split del: split_if)\napply(fastforce simp add: final_iff \\<tau>red1r_Val \\<tau>red1t_Val intro: red1_reds1.intros)+\ndone\n\nlemma sim_moves01_expr:\n  \"sim_move01 P t ta0 e0 e h xs ta e' h' xs' \\<Longrightarrow> sim_moves01 P t ta0 (e0 # es2) (e # es2') h xs ta (e' # es2') h' xs'\"\n  \"sim_moves01 P t ta0 es0 es h xs ta es' h' xs' \\<Longrightarrow> sim_moves01 P t ta0 (Val v # es0) (Val v # es) h xs ta (Val v # es') h' xs'\"\napply(simp_all add: sim_move01_def sim_moves01_def final_iff finals_iff Cons_eq_append_conv \\<tau>red1t_Val \\<tau>red1r_Val split: split_if_asm split del: split_if)\napply(auto simp add: Cons_eq_append_conv \\<tau>red1t_Val \\<tau>red1r_Val split: split_if_asm intro: List1Red1 List1Red2 \\<tau>red1t_inj_\\<tau>reds1t \\<tau>red1r_inj_\\<tau>reds1r \\<tau>reds1t_cons_\\<tau>reds1t \\<tau>reds1r_cons_\\<tau>reds1r)\napply(force elim!: \\<tau>red1r_inj_\\<tau>reds1r List1Red1)\napply(force elim!: \\<tau>red1r_inj_\\<tau>reds1r List1Red1)\napply(force elim!: \\<tau>red1r_inj_\\<tau>reds1r List1Red1)\napply(force elim!: \\<tau>red1r_inj_\\<tau>reds1r List1Red1)\napply(force elim!: \\<tau>reds1r_cons_\\<tau>reds1r intro!: List1Red2)\napply(force elim!: \\<tau>reds1r_cons_\\<tau>reds1r intro!: List1Red2)\ndone\n\nlemma sim_move01_CallParams:\n  \"sim_moves01 P t ta0 es0 es h xs ta es' h' xs'\n  \\<Longrightarrow> sim_move01 P t ta0 (Val v\\<bullet>M(es0)) (Val v\\<bullet>M(es)) h xs ta (Val v\\<bullet>M(es')) h' xs'\"\napply(clarsimp simp add: sim_move01_def sim_moves01_def \\<tau>reds1r_map_Val \\<tau>reds1t_map_Val is_vals_conv split: split_if_asm split del: split_if)\n  apply(fastforce simp add: sim_move01_def sim_moves01_def \\<tau>reds1r_map_Val \\<tau>reds1t_map_Val intro: Call_\\<tau>red1r_param Call1Params)\n apply(rule conjI, fastforce)\n apply(split split_if)\n apply(rule conjI)\n  apply(clarsimp simp add: finals_iff)\n apply(clarify)\n apply(split split_if)\n apply(rule conjI)\n  apply(simp del: call.simps calls.simps call1.simps calls1.simps)\n  apply(fastforce simp add: sim_move01_def sim_moves01_def \\<tau>red1r_Val \\<tau>red1t_Val \\<tau>reds1r_map_Val_Throw intro: Call_\\<tau>red1r_param Call1Params split: split_if_asm)\n apply(fastforce split: split_if_asm simp add: is_vals_conv \\<tau>reds1r_map_Val \\<tau>reds1r_map_Val_Throw)\napply(rule conjI, fastforce)\napply(fastforce simp add: sim_move01_def sim_moves01_def \\<tau>red1r_Val \\<tau>red1t_Val \\<tau>reds1t_map_Val \\<tau>reds1r_map_Val is_vals_conv intro: Call_\\<tau>red1r_param Call1Params split: split_if_asm)\ndone\n\nlemma sim_move01_reds:\n  \"\\<lbrakk> (h', a) \\<in> allocate h (Class_type C); ta0 = \\<lbrace>NewHeapElem a (Class_type C)\\<rbrace>; ta = \\<lbrace>NewHeapElem a (Class_type C)\\<rbrace> \\<rbrakk>\n  \\<Longrightarrow> sim_move01 P t ta0 (new C) (new C) h xs ta (addr a) h' xs\"\n  \"allocate h (Class_type C) = {} \\<Longrightarrow> sim_move01 P t \\<epsilon> (new C) (new C) h xs \\<epsilon> (THROW OutOfMemory) h xs\"\n  \"\\<lbrakk> (h', a) \\<in> allocate h (Array_type T (nat (sint i))); 0 <=s i;\n     ta0 = \\<lbrace>NewHeapElem a (Array_type T (nat (sint i)))\\<rbrace>; ta = \\<lbrace>NewHeapElem a (Array_type T (nat (sint i)))\\<rbrace> \\<rbrakk>\n  \\<Longrightarrow> sim_move01 P t ta0 (newA T\\<lfloor>Val (Intg i)\\<rceil>) (newA T\\<lfloor>Val (Intg i)\\<rceil>) h xs ta (addr a) h' xs\"\n  \"i <s 0 \\<Longrightarrow> sim_move01 P t \\<epsilon> (newA T\\<lfloor>Val (Intg i)\\<rceil>) (newA T\\<lfloor>Val (Intg i)\\<rceil>) h xs \\<epsilon> (THROW NegativeArraySize) h xs\"\n  \"\\<lbrakk> allocate h (Array_type T (nat (sint i))) = {}; 0 <=s i \\<rbrakk>\n  \\<Longrightarrow> sim_move01 P t \\<epsilon> (newA T\\<lfloor>Val (Intg i)\\<rceil>) (newA T\\<lfloor>Val (Intg i)\\<rceil>) h xs \\<epsilon> (THROW OutOfMemory) h xs\"\n  \"\\<lbrakk> typeof\\<^bsub>h\\<^esub> v = \\<lfloor>U\\<rfloor>; P \\<turnstile> U \\<le> T \\<rbrakk>\n  \\<Longrightarrow> sim_move01 P t \\<epsilon> (Cast T (Val v)) (Cast T (Val v)) h xs \\<epsilon> (Val v) h xs\"\n  \"\\<lbrakk> typeof\\<^bsub>h\\<^esub> v = \\<lfloor>U\\<rfloor>; \\<not> P \\<turnstile> U \\<le> T \\<rbrakk>\n  \\<Longrightarrow> sim_move01 P t \\<epsilon> (Cast T (Val v)) (Cast T (Val v)) h xs \\<epsilon> (THROW ClassCast) h xs\"\n  \"\\<lbrakk> typeof\\<^bsub>h\\<^esub> v = \\<lfloor>U\\<rfloor>; b \\<longleftrightarrow> v \\<noteq> Null \\<and> P \\<turnstile> U \\<le> T \\<rbrakk>\n  \\<Longrightarrow> sim_move01 P t \\<epsilon> ((Val v) instanceof T) ((Val v) instanceof T) h xs \\<epsilon> (Val (Bool b)) h xs\"\n  \"binop bop v1 v2 = Some (Inl v) \\<Longrightarrow> sim_move01 P t \\<epsilon> ((Val v1) \\<guillemotleft>bop\\<guillemotright> (Val v2)) (Val v1 \\<guillemotleft>bop\\<guillemotright> Val v2) h xs \\<epsilon> (Val v) h xs\"\n  \"binop bop v1 v2 = Some (Inr a) \\<Longrightarrow> sim_move01 P t \\<epsilon> ((Val v1) \\<guillemotleft>bop\\<guillemotright> (Val v2)) (Val v1 \\<guillemotleft>bop\\<guillemotright> Val v2) h xs \\<epsilon> (Throw a) h xs\"\n  \"\\<lbrakk> xs!V = v; V < size xs \\<rbrakk> \\<Longrightarrow> sim_move01 P t \\<epsilon> (Var V') (Var V) h xs \\<epsilon> (Val v) h xs\"\n  \"V < length xs \\<Longrightarrow> sim_move01 P t \\<epsilon> (V' := Val v) (V := Val v) h xs \\<epsilon> unit h (xs[V := v])\"\n  \"sim_move01 P t \\<epsilon> (null\\<lfloor>Val v\\<rceil>) (null\\<lfloor>Val v\\<rceil>) h xs \\<epsilon> (THROW NullPointer) h xs\"\n  \"\\<lbrakk> typeof_addr h a = \\<lfloor>Array_type T n\\<rfloor>; i <s 0 \\<or> sint i \\<ge> int n \\<rbrakk>\n  \\<Longrightarrow> sim_move01 P t \\<epsilon> (addr a\\<lfloor>Val (Intg i)\\<rceil>) ((addr a)\\<lfloor>Val (Intg i)\\<rceil>) h xs \\<epsilon> (THROW ArrayIndexOutOfBounds) h xs\"\n  \"\\<lbrakk> typeof_addr h a = \\<lfloor>Array_type T n\\<rfloor>; 0 <=s i; sint i < int n;\n     heap_read h a (ACell (nat (sint i))) v;\n     ta0 = \\<lbrace>ReadMem a (ACell (nat (sint i))) v\\<rbrace>; \n     ta = \\<lbrace>ReadMem a (ACell (nat (sint i))) v\\<rbrace> \\<rbrakk>\n  \\<Longrightarrow> sim_move01 P t ta0 (addr a\\<lfloor>Val (Intg i)\\<rceil>) ((addr a)\\<lfloor>Val (Intg i)\\<rceil>) h xs ta (Val v) h xs\"\n  \"sim_move01 P t \\<epsilon> (null\\<lfloor>Val v\\<rceil> := Val v') (null\\<lfloor>Val v\\<rceil> := Val v') h xs \\<epsilon> (THROW NullPointer) h xs\"\n  \"\\<lbrakk> typeof_addr h a = \\<lfloor>Array_type T n\\<rfloor>; i <s 0 \\<or> sint i \\<ge> int n \\<rbrakk>\n  \\<Longrightarrow> sim_move01 P t \\<epsilon> (AAss (addr a) (Val (Intg i)) (Val v)) (AAss (addr a) (Val (Intg i)) (Val v)) h xs \\<epsilon> (THROW ArrayIndexOutOfBounds) h xs\"\n \"\\<lbrakk> typeof_addr h a = \\<lfloor>Array_type T n\\<rfloor>; 0 <=s i; sint i < int n; typeof\\<^bsub>h\\<^esub> v = \\<lfloor>U\\<rfloor>; \\<not> (P \\<turnstile> U \\<le> T) \\<rbrakk>\n  \\<Longrightarrow> sim_move01 P t \\<epsilon> (AAss (addr a) (Val (Intg i)) (Val v)) (AAss (addr a) (Val (Intg i)) (Val v)) h xs \\<epsilon> (THROW ArrayStore) h xs\"\n  \"\\<lbrakk> typeof_addr h a = \\<lfloor>Array_type T n\\<rfloor>; 0 <=s i; sint i < int n; typeof\\<^bsub>h\\<^esub> v = Some U; P \\<turnstile> U \\<le> T;\n     heap_write h a (ACell (nat (sint i))) v h'; \n     ta0 = \\<lbrace>WriteMem a (ACell (nat (sint i))) v\\<rbrace>; ta = \\<lbrace>WriteMem a (ACell (nat (sint i))) v \\<rbrace> \\<rbrakk>\n  \\<Longrightarrow> sim_move01 P t ta0 (AAss (addr a) (Val (Intg i)) (Val v)) (AAss (addr a) (Val (Intg i)) (Val v)) h xs ta unit h' xs\"\n  \"typeof_addr h a = \\<lfloor>Array_type T n\\<rfloor> \\<Longrightarrow> sim_move01 P t \\<epsilon> (addr a\\<bullet>length) (addr a\\<bullet>length) h xs \\<epsilon> (Val (Intg (word_of_int (int n)))) h xs\"\n  \"sim_move01 P t \\<epsilon> (null\\<bullet>length) (null\\<bullet>length) h xs \\<epsilon> (THROW NullPointer) h xs\"\n\n  \"\\<lbrakk> heap_read h a (CField D F) v; ta0 = \\<lbrace>ReadMem a (CField D F) v\\<rbrace>; ta = \\<lbrace>ReadMem a (CField D F) v\\<rbrace> \\<rbrakk>\n  \\<Longrightarrow> sim_move01 P t ta0 (addr a\\<bullet>F{D}) (addr a\\<bullet>F{D}) h xs ta (Val v) h xs\"\n  \"sim_move01 P t \\<epsilon> (null\\<bullet>F{D}) (null\\<bullet>F{D}) h xs \\<epsilon> (THROW NullPointer) h xs\"\n  \"\\<lbrakk> heap_write h a (CField D F) v h'; ta0 = \\<lbrace>WriteMem a (CField D F) v\\<rbrace>; ta = \\<lbrace>WriteMem a (CField D F) v\\<rbrace> \\<rbrakk>\n  \\<Longrightarrow> sim_move01 P t ta0 (addr a\\<bullet>F{D} := Val v) (addr a\\<bullet>F{D} := Val v) h xs ta unit h' xs\"\n  \"sim_move01 P t \\<epsilon> (null\\<bullet>F{D} := Val v) (null\\<bullet>F{D} := Val v) h xs \\<epsilon> (THROW NullPointer) h xs\"\n  \"sim_move01 P t \\<epsilon> ({V':T=vo; Val u}) ({V:T=None; Val u}) h xs \\<epsilon> (Val u) h xs\"\n  \"V < length xs \\<Longrightarrow> sim_move01 P t \\<epsilon> (sync(null) e0) (sync\\<^bsub>V\\<^esub> (null) e1) h xs \\<epsilon> (THROW NullPointer) h (xs[V := Null])\"\n  \"sim_move01 P t \\<epsilon> (Val v;;e0) (Val v;; e1) h xs \\<epsilon> e1 h xs\"\n  \"sim_move01 P t \\<epsilon> (if (true) e0 else e0') (if (true) e1 else e1') h xs \\<epsilon> e1 h xs\"\n  \"sim_move01 P t \\<epsilon> (if (false) e0 else e0') (if (false) e1 else e1') h xs \\<epsilon> e1' h xs\"\n  \"sim_move01 P t \\<epsilon> (throw null) (throw null) h xs \\<epsilon> (THROW NullPointer) h xs\"\n  \"sim_move01 P t \\<epsilon> (try (Val v) catch(C V') e0) (try (Val v) catch(C V) e1) h xs \\<epsilon> (Val v) h xs\"\n  \"\\<lbrakk> typeof_addr h a = \\<lfloor>Class_type D\\<rfloor>; P \\<turnstile> D \\<preceq>\\<^sup>* C; V < length xs \\<rbrakk>\n  \\<Longrightarrow> sim_move01 P t \\<epsilon> (try (Throw a) catch(C V') e0) (try (Throw a) catch(C V) e1) h xs \\<epsilon> ({V:Class C=None; e1}) h (xs[V := Addr a])\"\n  \"sim_move01 P t \\<epsilon> (newA T\\<lfloor>Throw a\\<rceil>) (newA T\\<lfloor>Throw a\\<rceil>) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move01 P t \\<epsilon> (Cast T (Throw a)) (Cast T (Throw a)) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move01 P t \\<epsilon> ((Throw a) instanceof T) ((Throw a) instanceof T) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move01 P t \\<epsilon> ((Throw a) \\<guillemotleft>bop\\<guillemotright> e0) ((Throw a) \\<guillemotleft>bop\\<guillemotright> e1) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move01 P t \\<epsilon> (Val v \\<guillemotleft>bop\\<guillemotright> (Throw a)) (Val v \\<guillemotleft>bop\\<guillemotright> (Throw a)) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move01 P t \\<epsilon> (V' := Throw a) (V := Throw a) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move01 P t \\<epsilon> (Throw a\\<lfloor>e0\\<rceil>) (Throw a\\<lfloor>e1\\<rceil>) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move01 P t \\<epsilon> (Val v\\<lfloor>Throw a\\<rceil>) (Val v\\<lfloor>Throw a\\<rceil>) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move01 P t \\<epsilon> (Throw a\\<lfloor>e0\\<rceil> := e0') (Throw a\\<lfloor>e1\\<rceil> := e1') h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move01 P t \\<epsilon> (Val v\\<lfloor>Throw a\\<rceil> := e0) (Val v\\<lfloor>Throw a\\<rceil> := e1) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move01 P t \\<epsilon> (Val v\\<lfloor>Val v'\\<rceil> := Throw a) (Val v\\<lfloor>Val v'\\<rceil> := Throw a) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move01 P t \\<epsilon> (Throw a\\<bullet>length) (Throw a\\<bullet>length) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move01 P t \\<epsilon> (Throw a\\<bullet>F{D}) (Throw a\\<bullet>F{D}) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move01 P t \\<epsilon> (Throw a\\<bullet>F{D} := e0) (Throw a\\<bullet>F{D} := e1) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move01 P t \\<epsilon> (Val v\\<bullet>F{D} := Throw a) (Val v\\<bullet>F{D} := Throw a) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move01 P t \\<epsilon> (Throw a\\<bullet>M(es0)) (Throw a\\<bullet>M(es1)) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move01 P t \\<epsilon> ({V':T=vo; Throw a}) ({V:T=None; Throw a}) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move01 P t \\<epsilon> (sync(Throw a) e0) (sync\\<^bsub>V\\<^esub>(Throw a) e1) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move01 P t \\<epsilon> (Throw a;;e0) (Throw a;;e1) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move01 P t \\<epsilon> (if (Throw a) e0 else e0') (if (Throw a) e1 else e1') h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move01 P t \\<epsilon> (throw (Throw a)) (throw (Throw a)) h xs \\<epsilon> (Throw a) h xs\"\napply(simp_all add: sim_move01_def ta_bisim_def split: split_if_asm split del: split_if)\napply(fastforce intro: red1_reds1.intros)+\ndone\n\nlemma sim_move01_ThrowParams:\n  \"sim_move01 P t \\<epsilon> (Val v\\<bullet>M(map Val vs @ Throw a # es0)) (Val v\\<bullet>M(map Val vs @ Throw a # es1)) h xs \\<epsilon> (Throw a) h xs\"\napply(simp add: sim_move01_def split del: split_if)\napply(rule conjI, fastforce)\napply(split split_if)\napply(rule conjI)\n apply(fastforce intro: red1_reds1.intros)\napply(fastforce simp add: sim_move01_def intro: red1_reds1.intros)\ndone\n\nlemma sim_move01_CallNull:\n  \"sim_move01 P t \\<epsilon> (null\\<bullet>M(map Val vs)) (null\\<bullet>M(map Val vs)) h xs \\<epsilon> (THROW NullPointer) h xs\"\nby(fastforce simp add: sim_move01_def map_eq_append_conv intro: red1_reds1.intros)\n\nlemma sim_move01_SyncLocks:\n  \"\\<lbrakk> V < length xs; ta0 = \\<lbrace>Lock\\<rightarrow>a, SyncLock a\\<rbrace>; ta = \\<lbrace>Lock\\<rightarrow>a, SyncLock a\\<rbrace> \\<rbrakk>\n   \\<Longrightarrow> sim_move01 P t ta0 (sync(addr a) e0) (sync\\<^bsub>V\\<^esub> (addr a) e1) h xs ta (insync\\<^bsub>V\\<^esub> (a) e1) h (xs[V := Addr a])\"\n  \"\\<lbrakk> xs ! V = Addr a'; V < length xs; ta0 = \\<lbrace>Unlock\\<rightarrow>a', SyncUnlock a'\\<rbrace>; ta = \\<lbrace>Unlock\\<rightarrow>a', SyncUnlock a'\\<rbrace> \\<rbrakk>\n  \\<Longrightarrow> sim_move01 P t ta0 (insync(a') (Val v)) (insync\\<^bsub>V\\<^esub> (a) (Val v)) h xs ta (Val v) h xs\"\n  \"\\<lbrakk> xs ! V = Addr a'; V < length xs; ta0 = \\<lbrace>Unlock\\<rightarrow>a', SyncUnlock a'\\<rbrace>; ta = \\<lbrace>Unlock\\<rightarrow>a', SyncUnlock a'\\<rbrace> \\<rbrakk>\n  \\<Longrightarrow> sim_move01 P t ta0 (insync(a') (Throw a'')) (insync\\<^bsub>V\\<^esub> (a) (Throw a'')) h xs ta (Throw a'') h xs\"\nby(fastforce simp add: sim_move01_def ta_bisim_def expand_finfun_eq fun_eq_iff finfun_upd_apply ta_upd_simps  intro: red1_reds1.intros[simplified] split: split_if_asm)+\n\nlemma sim_move01_TryFail:\n  \"\\<lbrakk> typeof_addr h a = \\<lfloor>Class_type D\\<rfloor>; \\<not> P \\<turnstile> D \\<preceq>\\<^sup>* C \\<rbrakk>\n  \\<Longrightarrow> sim_move01 P t \\<epsilon> (try (Throw a) catch(C V') e0) (try (Throw a) catch(C V) e1) h xs \\<epsilon> (Throw a) h xs\"\nby(auto simp add: sim_move01_def intro!: Red1TryFail)\n\nlemma sim_move01_BlockSome:\n  \"\\<lbrakk> sim_move01 P t ta0 e0 e h (xs[V := v]) ta e' h' xs'; V < length xs \\<rbrakk>\n  \\<Longrightarrow> sim_move01 P t ta0 ({V':T=\\<lfloor>v\\<rfloor>; e0}) ({V:T=\\<lfloor>v\\<rfloor>; e}) h xs ta ({V:T=None; e'}) h' xs'\"\n  \"V < length xs \\<Longrightarrow> sim_move01 P t \\<epsilon> ({V':T=\\<lfloor>v\\<rfloor>; Val u}) ({V:T=\\<lfloor>v\\<rfloor>; Val u}) h xs \\<epsilon> (Val u) h (xs[V := v])\"\n  \"V < length xs \\<Longrightarrow> sim_move01 P t \\<epsilon> ({V':T=\\<lfloor>v\\<rfloor>; Throw a}) ({V:T=\\<lfloor>v\\<rfloor>; Throw a}) h xs \\<epsilon> (Throw a) h (xs[V := v])\"\napply(auto simp add: sim_move01_def)\napply(split split_if_asm)\n apply(fastforce intro: intro: converse_rtranclp_into_rtranclp Block1Some Block1Red Block_\\<tau>red1r_Some)\napply(fastforce intro: intro: converse_rtranclp_into_rtranclp Block1Some Block1Red Block_\\<tau>red1r_Some)\napply(fastforce simp add: sim_move01_def intro!: \\<tau>red1t_2step[OF Block1Some] \\<tau>red1r_1step[OF Block1Some] Red1Block Block1Throw)+\ndone\n\nlemmas sim_move01_intros =\n  sim_move01_expr sim_move01_reds sim_move01_ThrowParams sim_move01_CallNull sim_move01_TryFail\n  sim_move01_BlockSome sim_move01_CallParams\n\ndeclare sim_move01_intros[intro]\n\nlemma sim_move01_preserves_len: \"sim_move01 P t ta0 e0 e h xs ta e' h' xs' \\<Longrightarrow> length xs' = length xs\"\nby(fastforce simp add: sim_move01_def split: split_if_asm dest: \\<tau>red1r_preserves_len \\<tau>red1t_preserves_len red1_preserves_len)\n\nlemma sim_move01_preserves_unmod:\n  \"\\<lbrakk> sim_move01 P t ta0 e0 e h xs ta e' h' xs'; unmod e i; i < length xs \\<rbrakk> \\<Longrightarrow> xs' ! i = xs ! i\"\napply(auto simp add: sim_move01_def split: split_if_asm dest: \\<tau>red1t_preserves_unmod)\napply(frule (2) \\<tau>red1'r_preserves_unmod)\napply(frule (1) \\<tau>red1r_unmod_preserved)\napply(frule \\<tau>red1r_preserves_len)\napply(auto dest: red1_preserves_unmod)\napply(frule (2) \\<tau>red1'r_preserves_unmod)\napply(frule (1) \\<tau>red1r_unmod_preserved)\napply(frule \\<tau>red1r_preserves_len)\napply(auto dest: red1_preserves_unmod)\ndone\n\nlemma assumes wf: \"wf_J_prog P\"\n  shows red1_simulates_red_aux:\n  \"\\<lbrakk> extTA2J0 P,P,t \\<turnstile> \\<langle>e1, S\\<rangle> -TA\\<rightarrow> \\<langle>e1', S'\\<rangle>; bisim vs e1 e2 XS; fv e1 \\<subseteq> set vs;\n     lcl S \\<subseteq>\\<^sub>m [vs [\\<mapsto>] XS]; length vs + max_vars e1 \\<le> length XS;\n     \\<forall>aMvs. call e1 = \\<lfloor>aMvs\\<rfloor> \\<longrightarrow> synthesized_call P (hp S) aMvs \\<rbrakk>\n  \\<Longrightarrow> \\<exists>ta e2' XS'. sim_move01 (compP1 P) t TA e1 e2 (hp S) XS ta e2' (hp S') XS' \\<and> bisim vs e1' e2' XS' \\<and> lcl S' \\<subseteq>\\<^sub>m [vs [\\<mapsto>] XS']\"\n  (is \"\\<lbrakk> _; _; _; _; _; ?synth e1 S \\<rbrakk> \\<Longrightarrow> ?concl e1 e2 S XS e1' S' TA vs\")\n\n  and reds1_simulates_reds_aux:\n  \"\\<lbrakk> extTA2J0 P,P,t \\<turnstile> \\<langle>es1, S\\<rangle> [-TA\\<rightarrow>] \\<langle>es1', S'\\<rangle>; bisims vs es1 es2 XS; fvs es1 \\<subseteq> set vs;\n    lcl S \\<subseteq>\\<^sub>m [vs [\\<mapsto>] XS]; length vs + max_varss es1 \\<le> length XS;\n    \\<forall>aMvs. calls es1 = \\<lfloor>aMvs\\<rfloor> \\<longrightarrow> synthesized_call P (hp S) aMvs \\<rbrakk>\n  \\<Longrightarrow> \\<exists>ta es2' xs'. sim_moves01 (compP1 P) t TA es1 es2 (hp S) XS ta es2' (hp S') xs' \\<and> bisims vs es1' es2' xs' \\<and> lcl S' \\<subseteq>\\<^sub>m [vs [\\<mapsto>] xs']\"\n  (is \"\\<lbrakk> _; _; _; _; _; ?synths es1 S \\<rbrakk> \\<Longrightarrow> ?concls es1 es2 S XS es1' S' TA vs\")\nproof(induct arbitrary: vs e2 XS and vs es2 XS rule: red_reds.inducts)\n  case (BinOpRed1 e s ta e' s' bop e2 Vs E2 xs)\n  note IH = `\\<And>vs e2 XS. \\<lbrakk>bisim vs e e2 XS; fv e \\<subseteq> set vs; lcl s \\<subseteq>\\<^sub>m [vs [\\<mapsto>] XS]; length vs + max_vars e \\<le> length XS;\n            ?synth e s \\<rbrakk> \\<Longrightarrow> ?concl e e2 s XS e' s' ta vs`\n  from `extTA2J0 P,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>` have \"\\<not> is_val e\" by auto\n  with `bisim Vs (e \\<guillemotleft>bop\\<guillemotright> e2) E2 xs` obtain E\n    where \"E2 = E \\<guillemotleft>bop\\<guillemotright> compE1 Vs e2\" and \"bisim Vs e E xs\" and \"\\<not> contains_insync e2\" by auto\n  with IH[of Vs E xs] `fv (e \\<guillemotleft>bop\\<guillemotright> e2) \\<subseteq> set Vs` `lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]` `\\<not> is_val e`\n    `length Vs + max_vars (e \\<guillemotleft>bop\\<guillemotright> e2) \\<le> length xs` `?synth (e \\<guillemotleft>bop\\<guillemotright> e2) s` `extTA2J0 P,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>`\n  show ?case by(cases \"is_val e'\")(fastforce elim!: sim_move01_expr)+\nnext\n  case (BinOpRed2 e s ta e' s' v bop Vs E2 xs)\n  note IH = `\\<And>vs e2 XS. \\<lbrakk>bisim vs e e2 XS; fv e \\<subseteq> set vs; lcl s \\<subseteq>\\<^sub>m [vs [\\<mapsto>] XS]; length vs + max_vars e \\<le> length XS;\n            ?synth e s \\<rbrakk> \\<Longrightarrow> ?concl e e2 s XS e' s' ta vs`\n  from `bisim Vs (Val v \\<guillemotleft>bop\\<guillemotright> e) E2 xs` obtain E\n    where \"E2 = Val v \\<guillemotleft>bop\\<guillemotright> E\" and \"bisim Vs e E xs\" by auto\n  with IH[of Vs E xs] `fv (Val v \\<guillemotleft>bop\\<guillemotright> e) \\<subseteq> set Vs` `lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]`\n    `length Vs + max_vars (Val v \\<guillemotleft>bop\\<guillemotright> e) \\<le> length xs` `?synth (Val v \\<guillemotleft>bop\\<guillemotright> e) s` `extTA2J0 P,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>`\n  show ?case by(fastforce elim!: sim_move01_expr)\nnext\n  case RedVar thus ?case\n    by(fastforce simp add: index_less_aux map_le_def fun_upds_apply intro!: exI dest: bspec)\nnext\n  case RedLAss thus ?case\n    by(fastforce intro: index_less_aux LAss_lem intro!: exI simp del: fun_upd_apply)\nnext\n  case (AAccRed1 a s ta a' s' i Vs E2 xs)\n  note IH = `\\<And>vs e2 XS. \\<lbrakk>bisim vs a e2 XS; fv a \\<subseteq> set vs; lcl s \\<subseteq>\\<^sub>m [vs [\\<mapsto>] XS]; length vs + max_vars a \\<le> length XS;\n            ?synth a s \\<rbrakk> \\<Longrightarrow> ?concl a e2 s XS a' s' ta vs`\n  from `extTA2J0 P,P,t \\<turnstile> \\<langle>a,s\\<rangle> -ta\\<rightarrow> \\<langle>a',s'\\<rangle>` have \"\\<not> is_val a\" by auto\n  with `bisim Vs (a\\<lfloor>i\\<rceil>) E2 xs` obtain E\n    where \"E2 = E\\<lfloor>compE1 Vs i\\<rceil>\" and \"bisim Vs a E xs\" and \"\\<not> contains_insync i\" by auto\n  with IH[of Vs E xs] `fv (a\\<lfloor>i\\<rceil>) \\<subseteq> set Vs` `lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]` `\\<not> is_val a`\n    `length Vs + max_vars (a\\<lfloor>i\\<rceil>) \\<le> length xs` `?synth (a\\<lfloor>i\\<rceil>) s` `extTA2J0 P,P,t \\<turnstile> \\<langle>a,s\\<rangle> -ta\\<rightarrow> \\<langle>a',s'\\<rangle>`\n  show ?case by(cases \"is_val a'\")(fastforce elim!: sim_move01_expr)+\nnext\n  case (AAccRed2 i s ta i' s' a Vs E2 xs)\n  note IH = `\\<And>vs e2 XS. \\<lbrakk>bisim vs i e2 XS; fv i \\<subseteq> set vs; lcl s \\<subseteq>\\<^sub>m [vs [\\<mapsto>] XS]; length vs + max_vars i \\<le> length XS;\n            ?synth i s \\<rbrakk> \\<Longrightarrow> ?concl i e2 s XS i' s' ta vs`\n  from `bisim Vs (Val a\\<lfloor>i\\<rceil>) E2 xs` obtain E\n    where \"E2 = Val a\\<lfloor>E\\<rceil>\" and \"bisim Vs i E xs\" by auto\n  with IH[of Vs E xs] `fv (Val a\\<lfloor>i\\<rceil>) \\<subseteq> set Vs` `lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]`\n    `length Vs + max_vars (Val a\\<lfloor>i\\<rceil>) \\<le> length xs` `?synth (Val a\\<lfloor>i\\<rceil>) s` `extTA2J0 P,P,t \\<turnstile> \\<langle>i,s\\<rangle> -ta\\<rightarrow> \\<langle>i',s'\\<rangle>`\n  show ?case by(fastforce elim!: sim_move01_expr)\nnext\n  case RedAAcc thus ?case by(auto simp del: split_paired_Ex)\nnext\n  case (AAssRed1 a s ta a' s' i e Vs E2 xs)\n  note IH = `\\<And>vs e2 XS. \\<lbrakk>bisim vs a e2 XS; fv a \\<subseteq> set vs; lcl s \\<subseteq>\\<^sub>m [vs [\\<mapsto>] XS]; length vs + max_vars a \\<le> length XS;\n            ?synth a s \\<rbrakk> \\<Longrightarrow> ?concl a e2 s XS a' s' ta vs`\n  from `extTA2J0 P,P,t \\<turnstile> \\<langle>a,s\\<rangle> -ta\\<rightarrow> \\<langle>a',s'\\<rangle>` have \"\\<not> is_val a\" by auto\n  with `bisim Vs (a\\<lfloor>i\\<rceil>:=e) E2 xs` obtain E\n    where E2: \"E2 = E\\<lfloor>compE1 Vs i\\<rceil>:=compE1 Vs e\" and \"bisim Vs a E xs\"\n    and sync: \"\\<not> contains_insync i\" \"\\<not> contains_insync e\" by auto\n  with IH[of Vs E xs] `fv (a\\<lfloor>i\\<rceil>:=e) \\<subseteq> set Vs` `lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]` `\\<not> is_val a` `extTA2J0 P,P,t \\<turnstile> \\<langle>a,s\\<rangle> -ta\\<rightarrow> \\<langle>a',s'\\<rangle>`\n    `length Vs + max_vars (a\\<lfloor>i\\<rceil>:=e) \\<le> length xs` `?synth (a\\<lfloor>i\\<rceil>:=e) s`\n  obtain ta' e2' xs'\n    where IH': \"sim_move01 (compP1 P) t ta a E (hp s) xs ta' e2' (hp s') xs'\"\n    \"bisim Vs a' e2' xs'\" \"lcl s' \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs']\"\n    by auto\n  show ?case\n  proof(cases \"is_val a'\")\n    case True\n    from `fv (a\\<lfloor>i\\<rceil>:=e) \\<subseteq> set Vs` sync\n    have \"bisim Vs i (compE1 Vs i) xs'\" \"bisim Vs e (compE1 Vs e) xs'\" by auto\n    with IH' E2 True sync  `\\<not> is_val a` `extTA2J0 P,P,t \\<turnstile> \\<langle>a,s\\<rangle> -ta\\<rightarrow> \\<langle>a',s'\\<rangle>` show ?thesis\n      by(cases \"is_val i\")(fastforce elim!: sim_move01_expr)+\n  next\n    case False with IH' E2 sync `\\<not> is_val a` `extTA2J0 P,P,t \\<turnstile> \\<langle>a,s\\<rangle> -ta\\<rightarrow> \\<langle>a',s'\\<rangle>`\n    show ?thesis by(fastforce elim!: sim_move01_expr)\n  qed\nnext\n  case (AAssRed2 i s ta i' s' a e Vs E2 xs)\n  note IH = `\\<And>vs e2 XS. \\<lbrakk>bisim vs i e2 XS; fv i \\<subseteq> set vs; lcl s \\<subseteq>\\<^sub>m [vs [\\<mapsto>] XS]; length vs + max_vars i \\<le> length XS;\n            ?synth i s \\<rbrakk> \\<Longrightarrow> ?concl i e2 s XS i' s' ta vs`\n  from `extTA2J0 P,P,t \\<turnstile> \\<langle>i,s\\<rangle> -ta\\<rightarrow> \\<langle>i',s'\\<rangle>` have \"\\<not> is_val i\" by auto\n  with `bisim Vs (Val a\\<lfloor>i\\<rceil> := e) E2 xs` obtain E\n    where \"E2 = Val a\\<lfloor>E\\<rceil>:=compE1 Vs e\" and \"bisim Vs i E xs\" and \"\\<not> contains_insync e\" by auto\n  with IH[of Vs E xs] `fv (Val a\\<lfloor>i\\<rceil>:=e) \\<subseteq> set Vs` `lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]` `\\<not> is_val i` `extTA2J0 P,P,t \\<turnstile> \\<langle>i,s\\<rangle> -ta\\<rightarrow> \\<langle>i',s'\\<rangle>`\n    `length Vs + max_vars (Val a\\<lfloor>i\\<rceil>:=e) \\<le> length xs` `?synth (Val a\\<lfloor>i\\<rceil>:=e) s`\n  show ?case by(cases \"is_val i'\")(fastforce elim!: sim_move01_expr)+\nnext\n  case (AAssRed3 e s ta e' s' a i Vs E2 xs)\n  note IH = `\\<And>vs e2 XS. \\<lbrakk>bisim vs e e2 XS; fv e \\<subseteq> set vs; lcl s \\<subseteq>\\<^sub>m [vs [\\<mapsto>] XS]; length vs + max_vars e \\<le> length XS;\n            ?synth e s \\<rbrakk> \\<Longrightarrow> ?concl e e2 s XS e' s' ta vs`\n  from `bisim Vs (Val a\\<lfloor>Val i\\<rceil> := e) E2 xs` obtain E\n    where \"E2 = Val a\\<lfloor>Val i\\<rceil>:=E\" and \"bisim Vs e E xs\" by auto\n  with IH[of Vs E xs] `fv (Val a\\<lfloor>Val i\\<rceil>:=e) \\<subseteq> set Vs` `lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]` `extTA2J0 P,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>`\n    `length Vs + max_vars (Val a\\<lfloor>Val i\\<rceil>:=e) \\<le> length xs` `?synth (Val a\\<lfloor>Val i\\<rceil>:=e) s`\n  show ?case by(fastforce elim!: sim_move01_expr)\nnext\n  case RedAAssStore thus ?case by(auto intro!: exI)\nnext\n  case (FAssRed1 e s ta e' s' F D e2 Vs E2 xs)\n  note IH = `\\<And>vs e2 XS. \\<lbrakk>bisim vs e e2 XS; fv e \\<subseteq> set vs; lcl s \\<subseteq>\\<^sub>m [vs [\\<mapsto>] XS]; length vs + max_vars e \\<le> length XS;\n            ?synth e s \\<rbrakk> \\<Longrightarrow> ?concl e e2 s XS e' s' ta vs`\n  from `extTA2J0 P,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>` have \"\\<not> is_val e\" by auto\n  with `bisim Vs (e\\<bullet>F{D} := e2) E2 xs` obtain E\n    where \"E2 = E\\<bullet>F{D} := compE1 Vs e2\" and \"bisim Vs e E xs\" and \"\\<not> contains_insync e2\" by auto\n  with IH[of Vs E xs] `fv (e\\<bullet>F{D} := e2) \\<subseteq> set Vs` `lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]` `\\<not> is_val e` `extTA2J0 P,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>`\n    `length Vs + max_vars (e\\<bullet>F{D} := e2) \\<le> length xs` `?synth (e\\<bullet>F{D} := e2) s`\n  show ?case by(cases \"is_val e'\")(fastforce elim!: sim_move01_expr)+\nnext\n  case (FAssRed2 e s ta e' s' v F D Vs E2 xs)\n  note IH = `\\<And>vs e2 XS. \\<lbrakk>bisim vs e e2 XS; fv e \\<subseteq> set vs; lcl s \\<subseteq>\\<^sub>m [vs [\\<mapsto>] XS]; length vs + max_vars e \\<le> length XS;\n            ?synth e s \\<rbrakk> \\<Longrightarrow> ?concl e e2 s XS e' s' ta vs`\n  from `bisim Vs (Val v\\<bullet>F{D} := e) E2 xs` obtain E\n    where \"E2 = Val v\\<bullet>F{D} := E\" and \"bisim Vs e E xs\" by auto\n  with IH[of Vs E xs] `fv (Val v\\<bullet>F{D} := e) \\<subseteq> set Vs` `lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]` `extTA2J0 P,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>`\n    `length Vs + max_vars (Val v\\<bullet>F{D} := e) \\<le> length xs` `?synth (Val v\\<bullet>F{D} := e) s`\n  show ?case by(fastforce elim!: sim_move01_expr)\nnext\n  case (CallObj e s ta e' s' M es Vs E2 xs)\n  note IH = `\\<And>vs e2 XS. \\<lbrakk>bisim vs e e2 XS; fv e \\<subseteq> set vs; lcl s \\<subseteq>\\<^sub>m [vs [\\<mapsto>] XS]; length vs + max_vars e \\<le> length XS;\n            ?synth e s \\<rbrakk> \\<Longrightarrow> ?concl e e2 s XS e' s' ta vs`\n  from `extTA2J0 P,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>` have \"\\<not> is_val e\" by auto\n  with `bisim Vs (e\\<bullet>M(es)) E2 xs` obtain E\n    where \"E2 = E\\<bullet>M(compEs1 Vs es)\" and \"bisim Vs e E xs\" and \"\\<not> contains_insyncs es\"\n    by(auto simp add: compEs1_conv_map)\n  with IH[of Vs E xs] `fv (e\\<bullet>M(es)) \\<subseteq> set Vs` `lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]`\n    `length Vs + max_vars (e\\<bullet>M(es)) \\<le> length xs` `?synth (e\\<bullet>M(es)) s`\n  show ?case by(cases \"is_val e'\")(fastforce elim!: sim_move01_expr split: split_if_asm)+\nnext\n  case (CallParams es s ta es' s' v M Vs E2 xs)\n  note IH = `\\<And>vs es2 XS. \\<lbrakk>bisims vs es es2 XS; fvs es \\<subseteq> set vs; lcl s \\<subseteq>\\<^sub>m [vs [\\<mapsto>] XS]; length vs + max_varss es \\<le> length XS;\n            ?synths es s \\<rbrakk> \\<Longrightarrow> ?concls es es2 s XS es' s' ta vs`\n  from `bisim Vs (Val v\\<bullet>M(es)) E2 xs` obtain Es \n    where \"E2 = Val v\\<bullet>M(Es)\" and \"bisims Vs es Es xs\" by auto\n  moreover from `extTA2J0 P,P,t \\<turnstile> \\<langle>es,s\\<rangle> [-ta\\<rightarrow>] \\<langle>es',s'\\<rangle>` have \"\\<not> is_vals es\" by auto\n  with `?synth (Val v\\<bullet>M(es)) s` have \"?synths es s\" by(auto)\n  moreover note IH[of Vs Es xs] `fv (Val v\\<bullet>M(es)) \\<subseteq> set Vs` `lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]` \n    `length Vs + max_vars (Val v\\<bullet>M(es)) \\<le> length xs`\n  ultimately show ?case by(fastforce elim!: sim_move01_CallParams)\nnext\n  case (RedCall s a U M Ts T pns body D vs Vs E2 xs)\n  from `typeof_addr (hp s) a = \\<lfloor>U\\<rfloor>`\n  have \"call (addr a\\<bullet>M(map Val vs)) = \\<lfloor>(a, M, vs)\\<rfloor>\" by auto\n  with `?synth (addr a\\<bullet>M(map Val vs)) s` have \"synthesized_call P (hp s) (a, M, vs)\" by auto\n  with `typeof_addr (hp s) a = \\<lfloor>U\\<rfloor>` `P \\<turnstile> class_type_of U sees M: Ts\\<rightarrow>T = \\<lfloor>(pns, body)\\<rfloor> in D`\n  have False by(auto simp add: synthesized_call_conv dest: sees_method_fun)\n  thus ?case ..\nnext\n  case (RedCallExternal s a T M Ts Tr D vs ta va h' ta' e' s' Vs E2 xs)\n  from `bisim Vs (addr a\\<bullet>M(map Val vs)) E2 xs` have \"E2 = addr a\\<bullet>M(map Val vs)\" by auto\n  moreover note `P \\<turnstile> class_type_of T sees M: Ts\\<rightarrow>Tr = Native in D` `typeof_addr (hp s) a = \\<lfloor>T\\<rfloor>` `ta' = extTA2J0 P ta`\n    `e' = extRet2J (addr a\\<bullet>M(map Val vs)) va` `s' = (h', lcl s)` `P,t \\<turnstile> \\<langle>a\\<bullet>M(vs),hp s\\<rangle> -ta\\<rightarrow>ext \\<langle>va,h'\\<rangle>`\n    `lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]`\n  moreover from wf `P,t \\<turnstile> \\<langle>a\\<bullet>M(vs),hp s\\<rangle> -ta\\<rightarrow>ext \\<langle>va,h'\\<rangle>`\n  have \"ta_bisim01 (extTA2J0 P ta) (extTA2J1 (compP1 P) ta)\" by(rule red_external_ta_bisim01)\n  moreover from `P,t \\<turnstile> \\<langle>a\\<bullet>M(vs),hp s\\<rangle> -ta\\<rightarrow>ext \\<langle>va,h'\\<rangle>` `typeof_addr (hp s) a = \\<lfloor>T\\<rfloor>`\n    `P \\<turnstile> class_type_of T sees M: Ts\\<rightarrow>Tr = Native in D`\n  have \"\\<tau>external_defs D M \\<Longrightarrow> h' = hp s \\<and> ta = \\<epsilon>\"\n    by(fastforce dest: \\<tau>external'_red_external_heap_unchanged \\<tau>external'_red_external_TA_empty simp add: \\<tau>external'_def \\<tau>external_def)\n  ultimately show ?case \n    by(cases va)(fastforce intro!: exI[where x=ta] intro: Red1CallExternal simp add: map_eq_append_conv sim_move01_def dest: sees_method_fun simp del: split_paired_Ex)+\nnext\n  case (BlockRed e h x V vo ta e' h' x' T Vs E2 xs)\n  note IH = `\\<And>vs e2 XS. \\<lbrakk>bisim vs e e2 XS; fv e \\<subseteq> set vs; lcl (h, x(V := vo)) \\<subseteq>\\<^sub>m [vs [\\<mapsto>] XS];\n                         length vs + max_vars e \\<le> length XS; ?synth e (h, (x(V := vo)))\\<rbrakk>\n            \\<Longrightarrow> ?concl e e2 (h, x(V := vo)) XS e' (h', x') ta vs`\n  note red = `extTA2J0 P,P,t \\<turnstile> \\<langle>e,(h, x(V := vo))\\<rangle> -ta\\<rightarrow> \\<langle>e',(h', x')\\<rangle>`\n  note len = `length Vs + max_vars {V:T=vo; e} \\<le> length xs`\n  from `fv {V:T=vo; e} \\<subseteq> set Vs` have fv: \"fv e \\<subseteq> set (Vs@[V])\" by auto\n  from `bisim Vs {V:T=vo; e} E2 xs` show ?case\n  proof(cases rule: bisim_cases(6)[consumes 1, case_names BlockNone BlockSome BlockSomeNone])\n    case (BlockNone E')\n    with red IH[of \"Vs@[V]\" E' xs] fv `lcl (h, x) \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]`\n      `length Vs + max_vars {V:T=vo; e} \\<le> length xs` `?synth {V:T=vo; e} (h, x)`\n    obtain TA' e2' xs' where red': \"sim_move01 (compP1 P) t ta e E' h xs TA' e2' h' xs'\"\n      and bisim': \"bisim (Vs @ [V]) e' e2' xs'\" \"x' \\<subseteq>\\<^sub>m [Vs @ [V] [\\<mapsto>] xs']\" by auto \n    from red' `length Vs + max_vars {V:T=vo; e} \\<le> length xs`\n    have \"length (Vs@[V]) + max_vars e \\<le> length xs'\"\n      by(fastforce simp add: sim_move01_def dest: red1_preserves_len \\<tau>red1t_preserves_len \\<tau>red1r_preserves_len split: split_if_asm)\n    with `x' \\<subseteq>\\<^sub>m [Vs @ [V] [\\<mapsto>] xs']` have \"x' \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs', V \\<mapsto> xs' ! length Vs]\" by(simp)\n    moreover \n    { assume \"V \\<in> set Vs\"\n      hence \"hidden (Vs @ [V]) (index Vs V)\" by(rule hidden_index)\n      with `bisim (Vs @ [V]) e E' xs` have \"unmod E' (index Vs V)\"\n        by -(rule hidden_bisim_unmod)\n      moreover from `length Vs + max_vars {V:T=vo; e} \\<le> length xs` `V \\<in> set Vs`\n      have \"index Vs V < length xs\" by(auto intro: index_less_aux)\n      ultimately have \"xs ! index Vs V = xs' ! index Vs V\"\n        using sim_move01_preserves_unmod[OF red'] by(simp) }\n    moreover from red' have \"length xs = length xs'\" by(rule sim_move01_preserves_len[symmetric])\n    ultimately have rel: \"x'(V := x V) \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs']\"\n      using `lcl (h, x) \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]` `length Vs + max_vars {V:T=vo; e} \\<le> length xs`\n      by(auto intro: Block_lem)\n    show ?thesis\n    proof(cases \"x' V\")\n      case None\n      with red' bisim' BlockNone len\n      show ?thesis by(fastforce simp del: split_paired_Ex fun_upd_apply intro: rel)\n    next\n      case (Some v)\n      moreover\n      with `x' \\<subseteq>\\<^sub>m [Vs @ [V] [\\<mapsto>] xs']` have \"[Vs @ [V] [\\<mapsto>] xs'] V = \\<lfloor>v\\<rfloor>\"\n        by(auto simp add: map_le_def dest: bspec)\n      moreover\n      from `length Vs + max_vars {V:T=vo; e} \\<le> length xs` have \"length Vs < length xs\" by auto\n      ultimately have \"xs' ! length Vs = v\" using `length xs = length xs'` by(simp)\n      with red' bisim' BlockNone Some len\n      show ?thesis by(fastforce simp del: fun_upd_apply intro: rel)\n    qed\n  next\n    case (BlockSome E' v)\n    with red IH[of \"Vs@[V]\" E' \"xs[length Vs := v]\"] fv `lcl (h, x) \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]`\n      `length Vs + max_vars {V:T=vo; e} \\<le> length xs` `?synth {V:T=vo; e} (h, x)`\n    obtain TA' e2' xs' where red': \"sim_move01 (compP1 P) t ta e E' h (xs[length Vs := v]) TA' e2' h' xs'\"\n      and bisim': \"bisim (Vs @ [V]) e' e2' xs'\" \"x' \\<subseteq>\\<^sub>m [Vs @ [V] [\\<mapsto>] xs']\" by auto\n    from red' `length Vs + max_vars {V:T=vo; e} \\<le> length xs`\n    have \"length (Vs@[V]) + max_vars e \\<le> length xs'\" by(auto dest: sim_move01_preserves_len)\n    with `x' \\<subseteq>\\<^sub>m [Vs @ [V] [\\<mapsto>] xs']` have \"x' \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs', V \\<mapsto> xs' ! length Vs]\" by(simp)\n    moreover \n    { assume \"V \\<in> set Vs\"\n      hence \"hidden (Vs @ [V]) (index Vs V)\" by(rule hidden_index)\n      with `bisim (Vs @ [V]) e E' (xs[length Vs := v])` have \"unmod E' (index Vs V)\"\n        by -(rule hidden_bisim_unmod)\n      moreover from `length Vs + max_vars {V:T=vo; e} \\<le> length xs` `V \\<in> set Vs`\n      have \"index Vs V < length xs\" by(auto intro: index_less_aux)\n      moreover from `length Vs + max_vars {V:T=vo; e} \\<le> length xs` `V \\<in> set Vs`\n      have \"(xs[length Vs := v]) ! index Vs V = xs ! index Vs V\" by(simp)\n      ultimately have \"xs ! index Vs V = xs' ! index Vs V\"\n        using sim_move01_preserves_unmod[OF red', of \"index Vs V\"] by(simp) }\n    moreover from red' have \"length xs = length xs'\" by(auto dest: sim_move01_preserves_len)\n    ultimately have rel: \"x'(V := x V) \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs']\"\n      using `lcl (h, x) \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]` `length Vs + max_vars {V:T=vo; e} \\<le> length xs`\n      by(auto intro: Block_lem)\n    from BlockSome red obtain v' where Some: \"x' V = \\<lfloor>v'\\<rfloor>\" by(auto dest!: red_lcl_incr)\n    with `x' \\<subseteq>\\<^sub>m [Vs @ [V] [\\<mapsto>] xs']` have \"[Vs @ [V] [\\<mapsto>] xs'] V = \\<lfloor>v'\\<rfloor>\"\n      by(auto simp add: map_le_def dest: bspec)\n    moreover\n    from `length Vs + max_vars {V:T=vo; e} \\<le> length xs` have \"length Vs < length xs\" by auto\n    ultimately have \"xs' ! length Vs = v'\" using `length xs = length xs'` by(simp)\n    with red' bisim' BlockSome Some `length Vs < length xs`\n    show ?thesis by(fastforce simp del: fun_upd_apply intro: rel)\n  next \n    case (BlockSomeNone E')\n    with red IH[of \"Vs@[V]\" E' xs] fv `lcl (h, x) \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]`\n      `length Vs + max_vars {V:T=vo; e} \\<le> length xs` `?synth {V:T=vo; e} (h, x)`\n    obtain TA' e2' xs' where red': \"sim_move01 (compP1 P) t ta e E' h xs TA' e2' h' xs'\"\n      and IH': \"bisim (Vs @ [V]) e' e2' xs'\" \"x' \\<subseteq>\\<^sub>m [Vs @ [V] [\\<mapsto>] xs']\" by auto\n    from red' `length Vs + max_vars {V:T=vo; e} \\<le> length xs`\n    have \"length (Vs@[V]) + max_vars e \\<le> length xs'\" by(auto dest: sim_move01_preserves_len)\n    with `x' \\<subseteq>\\<^sub>m [Vs @ [V] [\\<mapsto>] xs']` have \"x' \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs', V \\<mapsto> xs' ! length Vs]\" by(simp)\n    moreover \n    { assume \"V \\<in> set Vs\"\n      hence \"hidden (Vs @ [V]) (index Vs V)\" by(rule hidden_index)\n      with `bisim (Vs @ [V]) e E' xs` have \"unmod E' (index Vs V)\"\n        by -(rule hidden_bisim_unmod)\n      moreover from `length Vs + max_vars {V:T=vo; e} \\<le> length xs` `V \\<in> set Vs`\n      have \"index Vs V < length xs\" by(auto intro: index_less_aux)\n      moreover from `length Vs + max_vars {V:T=vo; e} \\<le> length xs` `V \\<in> set Vs`\n      have \"(xs[length Vs := v]) ! index Vs V = xs ! index Vs V\" by(simp)\n      ultimately have \"xs ! index Vs V = xs' ! index Vs V\"\n        using sim_move01_preserves_unmod[OF red', of \"index Vs V\"] by(simp) }\n    moreover from red' have \"length xs = length xs'\" by(auto dest: sim_move01_preserves_len)\n    ultimately have rel: \"x'(V := x V) \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs']\"\n      using `lcl (h, x) \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]` `length Vs + max_vars {V:T=vo; e} \\<le> length xs`\n      by(auto intro: Block_lem)\n    from BlockSomeNone red obtain v' where Some: \"x' V = \\<lfloor>v'\\<rfloor>\" by(auto dest!: red_lcl_incr)\n    with `x' \\<subseteq>\\<^sub>m [Vs @ [V] [\\<mapsto>] xs']` have \"[Vs @ [V] [\\<mapsto>] xs'] V = \\<lfloor>v'\\<rfloor>\"\n      by(auto simp add: map_le_def dest: bspec)\n    moreover\n    from `length Vs + max_vars {V:T=vo; e} \\<le> length xs` have \"length Vs < length xs\" by auto\n    ultimately have \"xs' ! length Vs = v'\" using `length xs = length xs'` by(simp)\n    with red' IH' BlockSomeNone Some `length Vs < length xs`\n    show ?thesis by(fastforce simp del: fun_upd_apply intro: rel)\n  qed\nnext\n  case (RedBlock V T vo u s Vs E2 xs)\n  from `bisim Vs {V:T=vo; Val u} E2 xs` obtain vo'\n    where [simp]: \"E2 = {length Vs:T=vo'; Val u}\" by auto\n  from RedBlock show ?case\n  proof(cases vo)\n    case (Some v)\n    with `bisim Vs {V:T=vo; Val u} E2 xs`\n    have vo': \"case vo' of None \\<Rightarrow> xs ! length Vs = v | Some v' \\<Rightarrow> v = v'\" by auto\n    have \"sim_move01 (compP1 P) t \\<epsilon> {V:T=vo; Val u} E2 (hp s) xs \\<epsilon> (Val u) (hp s) (xs[length Vs := v])\"\n    proof(cases vo')\n      case None with vo'\n      have \"xs[length Vs := v] = xs\" by auto\n      thus ?thesis using Some None by auto\n    next\n      case Some\n      from `length Vs + max_vars {V:T=vo; Val u} \\<le> length xs` have \"length Vs < length xs\" by simp\n      with vo' Some show ?thesis using `vo = Some v` by auto\n    qed\n    thus ?thesis using RedBlock by fastforce\n  qed fastforce\nnext\n  case SynchronizedNull thus ?case by fastforce\nnext\n  case (LockSynchronized a e s Vs E2 xs)\n  from `bisim Vs (sync(addr a) e) E2 xs`\n  have E2: \"E2 = sync\\<^bsub>length Vs\\<^esub> (addr a) (compE1 (Vs@[fresh_var Vs]) e)\" \n    and sync: \"\\<not> contains_insync e\" by auto\n  moreover have \"fresh_var Vs \\<notin> set Vs\" by(rule fresh_var_fresh)\n  with `fv (sync(addr a) e) \\<subseteq> set Vs` have \"fresh_var Vs \\<notin> fv e\" by auto\n  from E2 `fv (sync(addr a) e) \\<subseteq> set Vs` sync\n  have \"bisim (Vs@[fresh_var Vs]) e (compE1 (Vs@[fresh_var Vs]) e) (xs[length Vs := Addr a])\"\n    by(auto intro!: compE1_bisim)\n  hence \"bisim Vs (insync(a) e) (insync\\<^bsub>length Vs\\<^esub> (a) (compE1 (Vs@[fresh_var Vs]) e)) (xs[length Vs := Addr a])\"\n    using `fresh_var Vs \\<notin> fv e` `length Vs + max_vars (sync(addr a) e) \\<le> length xs` by auto\n  moreover from `length Vs + max_vars (sync(addr a) e) \\<le> length xs`\n  have \"False,compP1 P,t \\<turnstile>1 \\<langle>sync\\<^bsub>length Vs\\<^esub> (addr a) (compE1 (Vs@[fresh_var Vs]) e), (hp s, xs)\\<rangle>\n        -\\<lbrace>Lock\\<rightarrow>a, SyncLock a\\<rbrace>\\<rightarrow>\n        \\<langle>insync\\<^bsub>length Vs\\<^esub> (a) (compE1 (Vs@[fresh_var Vs]) e), (hp s, xs[length Vs := Addr a])\\<rangle>\"\n    by -(rule Lock1Synchronized, auto)\n  hence \"sim_move01 (compP1 P) t \\<lbrace>Lock\\<rightarrow>a, SyncLock a\\<rbrace> (sync(addr a) e) E2 (hp s) xs \\<lbrace>Lock\\<rightarrow>a, SyncLock a\\<rbrace> (insync\\<^bsub>length Vs\\<^esub> (a) (compE1 (Vs@[fresh_var Vs]) e)) (hp s) (xs[length Vs := Addr a])\"\n    using E2 by(fastforce simp add: sim_move01_def ta_bisim_def)\n  moreover have \"zip Vs (xs[length Vs := Addr a]) = (zip Vs xs)[length Vs := (arbitrary, Addr a)]\"\n    by(rule sym)(simp add: update_zip)\n  hence \"zip Vs (xs[length Vs := Addr a]) = zip Vs xs\" by simp\n  with `lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]` have \"lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs[length Vs := Addr a]]\"\n    by(auto simp add: map_le_def map_upds_def)\n  ultimately show ?case using `lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]` by fastforce\nnext\n  case (SynchronizedRed2 e s ta e' s' a Vs E2 xs)\n  note IH = `\\<And>vs e2 XS. \\<lbrakk>bisim vs e e2 XS; fv e \\<subseteq> set vs; lcl s \\<subseteq>\\<^sub>m [vs [\\<mapsto>] XS]; length vs + max_vars e \\<le> length XS;\n            ?synth e s \\<rbrakk> \\<Longrightarrow> ?concl e e2 s XS e' s' ta vs`\n  from `bisim Vs (insync(a) e) E2 xs` obtain E\n    where E2: \"E2 = insync\\<^bsub>length Vs\\<^esub> (a) E\" and bisim: \"bisim (Vs@[fresh_var Vs]) e E xs\"\n    and xsa: \"xs ! length Vs = Addr a\" by auto\n  from `fv (insync(a) e) \\<subseteq> set Vs` fresh_var_fresh[of Vs] have fv: \"fresh_var Vs \\<notin> fv e\" by auto\n  from `length Vs + max_vars (insync(a) e) \\<le> length xs` have \"length Vs < length xs\" by simp\n  { assume \"lcl s (fresh_var Vs) \\<noteq> None\"\n    then obtain v where \"lcl s (fresh_var Vs) = \\<lfloor>v\\<rfloor>\" by auto\n    with `lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]` have \"[Vs [\\<mapsto>] xs] (fresh_var Vs) = \\<lfloor>v\\<rfloor>\" \n      by(auto simp add: map_le_def dest: bspec)\n    hence \"fresh_var Vs \\<in> set Vs\" \n      by(auto simp add: map_upds_def set_zip dest!: map_of_SomeD )\n    moreover have \"fresh_var Vs \\<notin> set Vs\" by(rule fresh_var_fresh)\n    ultimately have False by contradiction }\n  hence \"lcl s (fresh_var Vs) = None\" by(cases \"lcl s (fresh_var Vs)\", auto)\n  hence \"(lcl s)(fresh_var Vs := None) = lcl s\" by(auto intro: ext)\n  moreover from `lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]`\n  have \"(lcl s)(fresh_var Vs := None) \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs, fresh_var Vs \\<mapsto> xs ! length Vs]\" by(simp)\n  ultimately have \"lcl s \\<subseteq>\\<^sub>m [Vs @ [fresh_var Vs] [\\<mapsto>] xs]\"\n    using `length Vs < length xs` by(auto)\n  with IH[of \"Vs@[fresh_var Vs]\" E xs] `fv (insync(a) e) \\<subseteq> set Vs` bisim\n    `length Vs + max_vars (insync(a) e) \\<le> length xs` `?synth (insync(a) e) s` \n  obtain TA' e2' xs' where IH': \"sim_move01 (compP1 P) t ta e E (hp s) xs TA' e2' (hp s') xs'\"\n    \"bisim (Vs @ [fresh_var Vs]) e' e2' xs'\" \"lcl s' \\<subseteq>\\<^sub>m [Vs @ [fresh_var Vs] [\\<mapsto>] xs']\" by auto\n  from `extTA2J0 P,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>` have \"dom (lcl s') \\<subseteq> dom (lcl s) \\<union> fv e\" by(auto dest: red_dom_lcl)\n  with fv `lcl s (fresh_var Vs) = None` have \"(fresh_var Vs) \\<notin> dom (lcl s')\" by auto\n  hence \"lcl s' (fresh_var Vs) = None\" by auto\n  moreover from IH' have \"length xs = length xs'\" by(auto dest: sim_move01_preserves_len)\n  moreover note `lcl s' \\<subseteq>\\<^sub>m [Vs @ [fresh_var Vs] [\\<mapsto>] xs']` `length Vs < length xs`\n  ultimately have \"lcl s' \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs']\" by(auto simp add: map_le_def dest: bspec)\n  moreover from bisim fv have \"unmod E (length Vs)\" by(auto intro: bisim_fv_unmod)\n  with IH' `length Vs < length xs` have \"xs ! length Vs = xs' ! length Vs\"\n    by(auto dest!: sim_move01_preserves_unmod)\n  with xsa have \"xs' ! length Vs = Addr a\" by simp\n  ultimately show ?case using IH' E2 by(fastforce)\nnext\n  case (UnlockSynchronized a v s Vs E2 xs)\n  from `bisim Vs (insync(a) Val v) E2 xs` have E2: \"E2 = insync\\<^bsub>length Vs\\<^esub> (a) Val v\" \n    and xsa: \"xs ! length Vs = Addr a\" by auto\n  moreover from `length Vs + max_vars (insync(a) Val v) \\<le> length xs` xsa\n  have \"False,compP1 P,t \\<turnstile>1 \\<langle>insync\\<^bsub>length Vs\\<^esub> (a) (Val v), (hp s, xs)\\<rangle> -\\<lbrace>Unlock\\<rightarrow>a, SyncUnlock a\\<rbrace>\\<rightarrow> \\<langle>Val v, (hp s, xs)\\<rangle>\"\n    by-(rule Unlock1Synchronized, auto)\n  hence \"sim_move01 (compP1 P) t \\<lbrace>Unlock\\<rightarrow>a, SyncUnlock a\\<rbrace> (insync(a) Val v) (insync\\<^bsub>length Vs\\<^esub> (a) Val v) (hp s) xs \\<lbrace>Unlock\\<rightarrow>a, SyncUnlock a\\<rbrace> (Val v) (hp s) xs\"\n    by(fastforce simp add: sim_move01_def ta_bisim_def)\n  ultimately show ?case using `lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]` by fastforce\nnext\n  case (RedWhile b c s Vs E2 xs)\n  from `bisim Vs (while (b) c) E2 xs` have \"E2 = while (compE1 Vs b) (compE1 Vs c)\"\n    and sync: \"\\<not> contains_insync b\" \"\\<not> contains_insync c\" by auto\n  moreover have \"False,compP1 P,t \\<turnstile>1 \\<langle>while(compE1 Vs b) (compE1 Vs c), (hp s, xs)\\<rangle> \n                 -\\<epsilon>\\<rightarrow> \\<langle>if (compE1 Vs b) (compE1 Vs c;;while(compE1 Vs b) (compE1 Vs c)) else unit, (hp s, xs)\\<rangle>\"\n    by(rule Red1While)\n  hence \"sim_move01 (compP1 P) t \\<epsilon> (while (b) c) (while (compE1 Vs b) (compE1 Vs c)) (hp s) xs \\<epsilon> (if (compE1 Vs b) (compE1 Vs c;;while(compE1 Vs b) (compE1 Vs c)) else unit) (hp s) xs\"\n    by(auto simp add: sim_move01_def)\n  moreover from `fv (while (b) c) \\<subseteq> set Vs` sync\n  have \"bisim Vs (if (b) (c;; while (b) c) else unit)\n                 (if (compE1 Vs b) (compE1 Vs (c;; while(b) c)) else (compE1 Vs unit)) xs\"\n    by -(rule bisimCond, auto)\n  ultimately show ?case using `lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]`\n    by(simp)((rule exI)+, erule conjI, auto)\nnext\n  case (RedTryCatch s a D C V e2 Vs E2 xs)\n  thus ?case by(auto intro!: exI)(auto intro!: compE1_bisim)\nnext\n  case RedTryFail thus ?case by(auto intro!: exI)\nnext\n  case (ListRed1 e s ta e' s' es Vs ES2 xs)\n  note IH = `\\<And>vs e2 XS. \\<lbrakk>bisim vs e e2 XS; fv e \\<subseteq> set vs; lcl s \\<subseteq>\\<^sub>m [vs [\\<mapsto>] XS]; length vs + max_vars e \\<le> length XS;\n                         ?synth e s\\<rbrakk> \\<Longrightarrow> ?concl e e2 s XS e' s' ta vs`\n  from `extTA2J0 P,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>` have \"\\<not> is_val e\" by auto\n  with `bisims Vs (e # es) ES2 xs` obtain E' \n    where \"bisim Vs e E' xs\" and ES2: \"ES2 = E' # compEs1 Vs es\" \n    and sync: \"\\<not> contains_insyncs es\" by(auto simp add: compEs1_conv_map)\n  with IH[of Vs E' xs] `fvs (e # es) \\<subseteq> set Vs` `lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]` `extTA2J0 P,P,t \\<turnstile> \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>`\n    `length Vs + max_varss (e # es) \\<le> length xs` `?synths (e # es) s` `\\<not> is_val e`\n  show ?case by(cases \"is_val e'\")(fastforce elim!: sim_moves01_expr split: split_if_asm)+\nnext\n  case (ListRed2 es s ta es' s' v Vs ES2 xs)\n  thus ?case by(fastforce elim!: bisims_cases elim!: sim_moves01_expr)\nnext\n  case CallThrowParams thus ?case\n    by(fastforce elim!:bisim_cases simp add: bisims_map_Val_Throw)\nnext\n  case (BlockThrow V T vo a s Vs e2 xs) thus ?case\n    by(cases vo)(fastforce elim!: bisim_cases)+\nnext    \n  case (SynchronizedThrow2 a ad s Vs E2 xs)\n  from `bisim Vs (insync(a) Throw ad) E2 xs` have \"xs ! length Vs = Addr a\" by auto\n  with `length Vs + max_vars (insync(a) Throw ad) \\<le> length xs`\n  have \"False,compP1 P,t \\<turnstile>1 \\<langle>insync\\<^bsub>length Vs\\<^esub> (a) Throw ad, (hp s, xs)\\<rangle> -\\<lbrace>Unlock\\<rightarrow>a, SyncUnlock a\\<rbrace>\\<rightarrow> \\<langle>Throw ad, (hp s, xs)\\<rangle>\"\n    by-(rule Synchronized1Throw2, auto)\n  hence \"sim_move01 (compP1 P) t \\<lbrace>Unlock\\<rightarrow>a, SyncUnlock a\\<rbrace> (insync(a) Throw ad) (insync\\<^bsub>length Vs\\<^esub> (a) Throw ad) (hp s) xs \\<lbrace>Unlock\\<rightarrow>a, SyncUnlock a\\<rbrace> (Throw ad) (hp s) xs\"\n    by(fastforce simp add: sim_move01_def ta_bisim_def fun_eq_iff expand_finfun_eq finfun_upd_apply ta_upd_simps split: split_if_asm)\n  moreover note `lcl s \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs]` `bisim Vs (insync(a) Throw ad) E2 xs`\n  ultimately show ?case by(fastforce)\nnext\n  case InstanceOfRed thus ?case by(fastforce)\nnext\n  case RedInstanceOf thus ?case by(auto intro!: exI)\nnext\n  case InstanceOfThrow thus ?case by fastforce\nqed(fastforce simp del: fun_upd_apply split: split_if_asm)+\n\nend\n\ndeclare max_dest [iff del]\n\ndeclare split_paired_Ex [simp del]\n\nprimrec countInitBlock :: \"('a, 'b, 'addr) exp \\<Rightarrow> nat\"\n  and countInitBlocks :: \"('a, 'b, 'addr) exp list \\<Rightarrow> nat\"\nwhere \n  \"countInitBlock (new C) = 0\"\n| \"countInitBlock (newA T\\<lfloor>e\\<rceil>) = countInitBlock e\"\n| \"countInitBlock (Cast T e) = countInitBlock e\"\n| \"countInitBlock (e instanceof T) = countInitBlock e\"\n| \"countInitBlock (Val v) = 0\"\n| \"countInitBlock (Var V) = 0\"\n| \"countInitBlock (V := e) = countInitBlock e\"\n| \"countInitBlock (e \\<guillemotleft>bop\\<guillemotright> e') = countInitBlock e + countInitBlock e'\"\n| \"countInitBlock (a\\<lfloor>i\\<rceil>) = countInitBlock a + countInitBlock i\"\n| \"countInitBlock (AAss a i e) = countInitBlock a + countInitBlock i + countInitBlock e\"\n| \"countInitBlock (a\\<bullet>length) = countInitBlock a\"\n| \"countInitBlock (e\\<bullet>F{D}) = countInitBlock e\"\n| \"countInitBlock (FAss e F D e') = countInitBlock e + countInitBlock e'\"\n| \"countInitBlock (e\\<bullet>M(es)) = countInitBlock e + countInitBlocks es\"\n| \"countInitBlock ({V:T=vo; e}) = (case vo of None \\<Rightarrow> 0 | Some v \\<Rightarrow> 1) + countInitBlock e\"\n| \"countInitBlock (sync\\<^bsub>V'\\<^esub> (e) e') = countInitBlock e + countInitBlock e'\"\n| \"countInitBlock (insync\\<^bsub>V'\\<^esub> (ad) e) = countInitBlock e\"\n| \"countInitBlock (e;;e') = countInitBlock e + countInitBlock e'\"\n| \"countInitBlock (if (e) e1 else e2) = countInitBlock e + countInitBlock e1 + countInitBlock e2\"\n| \"countInitBlock (while(b) e) = countInitBlock b + countInitBlock e\"\n| \"countInitBlock (throw e) = countInitBlock e\"\n| \"countInitBlock (try e catch(C V) e') = countInitBlock e + countInitBlock e'\"\n\n| \"countInitBlocks [] = 0\"\n| \"countInitBlocks (e # es) = countInitBlock e + countInitBlocks es\"\n\ncontext J0_J1_heap_base begin\n\nlemmas \\<tau>red0r_expr =\n  NewArray_\\<tau>red0r_xt Cast_\\<tau>red0r_xt InstanceOf_\\<tau>red0r_xt BinOp_\\<tau>red0r_xt1 BinOp_\\<tau>red0r_xt2 LAss_\\<tau>red0r\n  AAcc_\\<tau>red0r_xt1 AAcc_\\<tau>red0r_xt2 AAss_\\<tau>red0r_xt1 AAss_\\<tau>red0r_xt2 AAss_\\<tau>red0r_xt3\n  ALength_\\<tau>red0r_xt FAcc_\\<tau>red0r_xt FAss_\\<tau>red0r_xt1 FAss_\\<tau>red0r_xt2 Call_\\<tau>red0r_obj\n  Call_\\<tau>red0r_param Block_\\<tau>red0r_xt Sync_\\<tau>red0r_xt InSync_\\<tau>red0r_xt\n  Seq_\\<tau>red0r_xt Cond_\\<tau>red0r_xt Throw_\\<tau>red0r_xt Try_\\<tau>red0r_xt\n\nlemmas \\<tau>red0t_expr =\n  NewArray_\\<tau>red0t_xt Cast_\\<tau>red0t_xt InstanceOf_\\<tau>red0t_xt BinOp_\\<tau>red0t_xt1 BinOp_\\<tau>red0t_xt2 LAss_\\<tau>red0t\n  AAcc_\\<tau>red0t_xt1 AAcc_\\<tau>red0t_xt2 AAss_\\<tau>red0t_xt1 AAss_\\<tau>red0t_xt2 AAss_\\<tau>red0t_xt3\n  ALength_\\<tau>red0t_xt FAcc_\\<tau>red0t_xt FAss_\\<tau>red0t_xt1 FAss_\\<tau>red0t_xt2 Call_\\<tau>red0t_obj\n  Call_\\<tau>red0t_param Block_\\<tau>red0t_xt Sync_\\<tau>red0t_xt InSync_\\<tau>red0t_xt\n  Seq_\\<tau>red0t_xt Cond_\\<tau>red0t_xt Throw_\\<tau>red0t_xt Try_\\<tau>red0t_xt\n\ndeclare \\<tau>red0r_expr [elim!]\ndeclare \\<tau>red0t_expr [elim!]\n\ndefinition sim_move10 :: \n  \"'addr J_prog \\<Rightarrow> 'thread_id \\<Rightarrow> ('addr, 'thread_id, 'heap) external_thread_action \\<Rightarrow> 'addr expr1 \\<Rightarrow> 'addr expr1 \\<Rightarrow> 'addr expr\n  \\<Rightarrow> 'heap \\<Rightarrow> 'addr locals \\<Rightarrow> ('addr, 'thread_id, 'heap) J0_thread_action \\<Rightarrow> 'addr expr \\<Rightarrow> 'heap \\<Rightarrow> 'addr locals \\<Rightarrow> bool\"\nwhere\n  \"sim_move10 P t ta1 e1 e1' e h xs ta e' h' xs' \\<longleftrightarrow> \\<not> final e1 \\<and>\n  (if \\<tau>move1 P h e1 then (\\<tau>red0t (extTA2J0 P) P t h (e, xs) (e', xs') \\<or> countInitBlock e1' < countInitBlock e1 \\<and> e' = e \\<and> xs' = xs) \\<and> h' = h \\<and> ta1 = \\<epsilon> \\<and> ta = \\<epsilon>\n   else ta_bisim01 ta (extTA2J1 (compP1 P) ta1) \\<and>\n     (if call e = None \\<or> call1 e1 = None \n      then (\\<exists>e'' xs''. \\<tau>red0r (extTA2J0 P) P t h (e, xs) (e'', xs'') \\<and> extTA2J0 P,P,t \\<turnstile> \\<langle>e'', (h, xs'')\\<rangle> -ta\\<rightarrow> \\<langle>e', (h', xs')\\<rangle> \\<and> no_call P h e'' \\<and> \\<not> \\<tau>move0 P h e'')\n      else extTA2J0 P,P,t \\<turnstile> \\<langle>e, (h, xs)\\<rangle> -ta\\<rightarrow> \\<langle>e', (h', xs')\\<rangle> \\<and> no_call P h e \\<and> \\<not> \\<tau>move0 P h e))\"\n\ndefinition sim_moves10 :: \n  \"'addr J_prog \\<Rightarrow> 'thread_id \\<Rightarrow> ('addr, 'thread_id, 'heap) external_thread_action \\<Rightarrow> 'addr expr1 list \\<Rightarrow> 'addr expr1 list\n  \\<Rightarrow> 'addr expr list \\<Rightarrow> 'heap \\<Rightarrow> 'addr locals \\<Rightarrow> ('addr, 'thread_id, 'heap) J0_thread_action \\<Rightarrow> 'addr expr list \\<Rightarrow> 'heap \n  \\<Rightarrow> 'addr locals \\<Rightarrow> bool\"\nwhere\n  \"sim_moves10 P t ta1 es1 es1' es h xs ta es' h' xs' \\<longleftrightarrow> \\<not> finals es1 \\<and>\n  (if \\<tau>moves1 P h es1 then (\\<tau>reds0t (extTA2J0 P) P t h (es, xs) (es', xs') \\<or> countInitBlocks es1' < countInitBlocks es1 \\<and> es' = es \\<and> xs' = xs) \\<and> h' = h \\<and> ta1 = \\<epsilon> \\<and> ta = \\<epsilon>\n   else ta_bisim01 ta (extTA2J1 (compP1 P) ta1) \\<and>\n     (if calls es = None \\<or> calls1 es1 = None\n      then (\\<exists>es'' xs''. \\<tau>reds0r (extTA2J0 P) P t h (es, xs) (es'', xs'') \\<and> extTA2J0 P,P,t \\<turnstile> \\<langle>es'', (h, xs'')\\<rangle> [-ta\\<rightarrow>] \\<langle>es', (h', xs')\\<rangle> \\<and> no_calls P h es'' \\<and> \\<not> \\<tau>moves0 P h es'')\n      else extTA2J0 P,P,t \\<turnstile> \\<langle>es, (h, xs)\\<rangle> [-ta\\<rightarrow>] \\<langle>es', (h', xs')\\<rangle> \\<and> no_calls P h es \\<and> \\<not> \\<tau>moves0 P h es))\"\n\nlemma sim_move10_expr:\n  assumes \"sim_move10 P t ta1 e1 e1' e h xs ta e' h' xs'\"\n  shows\n  \"sim_move10 P t ta1 (newA T\\<lfloor>e1\\<rceil>) (newA T\\<lfloor>e1'\\<rceil>) (newA T\\<lfloor>e\\<rceil>) h xs ta (newA T\\<lfloor>e'\\<rceil>) h' xs'\"\n  \"sim_move10 P t ta1 (Cast T e1) (Cast T e1') (Cast T e) h xs ta (Cast T e') h' xs'\"\n  \"sim_move10 P t ta1 (e1 instanceof T) (e1' instanceof T) (e instanceof T) h xs ta (e' instanceof T) h' xs'\"\n  \"sim_move10 P t ta1 (e1 \\<guillemotleft>bop\\<guillemotright> e2) (e1' \\<guillemotleft>bop\\<guillemotright> e2) (e \\<guillemotleft>bop\\<guillemotright> e2') h xs ta (e' \\<guillemotleft>bop\\<guillemotright> e2') h' xs'\"\n  \"sim_move10 P t ta1 (Val v \\<guillemotleft>bop\\<guillemotright> e1) (Val v \\<guillemotleft>bop\\<guillemotright> e1') (Val v \\<guillemotleft>bop\\<guillemotright> e) h xs ta (Val v \\<guillemotleft>bop\\<guillemotright> e') h' xs'\"\n  \"sim_move10 P t ta1 (V := e1) (V := e1') (V' := e) h xs ta (V' := e') h' xs'\"\n  \"sim_move10 P t ta1 (e1\\<lfloor>e2\\<rceil>) (e1'\\<lfloor>e2\\<rceil>) (e\\<lfloor>e2'\\<rceil>) h xs ta (e'\\<lfloor>e2'\\<rceil>) h' xs'\"\n  \"sim_move10 P t ta1 (Val v\\<lfloor>e1\\<rceil>) (Val v\\<lfloor>e1'\\<rceil>) (Val v\\<lfloor>e\\<rceil>) h xs ta (Val v\\<lfloor>e'\\<rceil>) h' xs'\"\n  \"sim_move10 P t ta1 (e1\\<lfloor>e2\\<rceil> := e3) (e1'\\<lfloor>e2\\<rceil> := e3) (e\\<lfloor>e2'\\<rceil> := e3') h xs ta (e'\\<lfloor>e2'\\<rceil> := e3') h' xs'\"\n  \"sim_move10 P t ta1 (Val v\\<lfloor>e1\\<rceil> := e3) (Val v\\<lfloor>e1'\\<rceil> := e3) (Val v\\<lfloor>e\\<rceil> := e3') h xs ta (Val v\\<lfloor>e'\\<rceil> := e3') h' xs'\"\n  \"sim_move10 P t ta1 (AAss (Val v) (Val v') e1) (AAss (Val v) (Val v') e1') (AAss (Val v) (Val v') e) h xs ta (AAss (Val v) (Val v') e') h' xs'\"\n  \"sim_move10 P t ta1 (e1\\<bullet>length) (e1'\\<bullet>length) (e\\<bullet>length) h xs ta (e'\\<bullet>length) h' xs'\"\n  \"sim_move10 P t ta1 (e1\\<bullet>F{D}) (e1'\\<bullet>F{D}) (e\\<bullet>F'{D'}) h xs ta (e'\\<bullet>F'{D'}) h' xs'\"\n  \"sim_move10 P t ta1 (FAss e1 F D e2) (FAss e1' F D e2) (FAss e F' D' e2') h xs ta (FAss e' F' D' e2') h' xs'\"\n  \"sim_move10 P t ta1 (FAss (Val v) F D e1) (FAss (Val v) F D e1') (FAss (Val v) F' D' e) h xs ta (FAss (Val v) F' D' e') h' xs'\"\n  \"sim_move10 P t ta1 (e1\\<bullet>M(es)) (e1'\\<bullet>M(es)) (e\\<bullet>M(es')) h xs ta (e'\\<bullet>M(es')) h' xs'\"\n  \"sim_move10 P t ta1 (sync\\<^bsub>V\\<^esub>(e1) e2) (sync\\<^bsub>V\\<^esub>(e1') e2) (sync(e) e2') h xs ta (sync(e') e2') h' xs'\"\n  \"sim_move10 P t ta1 (insync\\<^bsub>V\\<^esub>(a) e1) (insync\\<^bsub>V\\<^esub>(a) e1') (insync(a') e) h xs ta (insync(a') e') h' xs'\"\n  \"sim_move10 P t ta1 (e1;;e2) (e1';;e2) (e;;e2') h xs ta (e';;e2') h' xs'\"\n  \"sim_move10 P t ta1 (if (e1) e2 else e3) (if (e1') e2 else e3) (if (e) e2' else e3') h xs ta (if (e') e2' else e3') h' xs'\"\n  \"sim_move10 P t ta1 (throw e1) (throw e1') (throw e) h xs ta (throw e') h' xs'\"\n  \"sim_move10 P t ta1 (try e1 catch(C V) e2) (try e1' catch(C V) e2) (try e catch(C' V') e2') h xs ta (try e' catch(C' V') e2') h' xs'\"\nusing assms\napply(simp_all add: sim_move10_def final_iff split del: split_if split add: split_if_asm)\napply(fastforce simp add: \\<tau>red0t_Val \\<tau>red0r_Val intro: red_reds.intros)+\ndone\n\nlemma sim_moves10_expr:\n  \"sim_move10 P t ta1 e1 e1' e h xs ta e' h' xs' \\<Longrightarrow> sim_moves10 P t ta1 (e1 # es2) (e1' # es2) (e # es2') h xs ta (e' # es2') h' xs'\"\n  \"sim_moves10 P t ta1 es1 es1' es h xs ta es' h' xs' \\<Longrightarrow> sim_moves10 P t ta1 (Val v # es1) (Val v # es1') (Val v # es) h xs ta (Val v # es') h' xs'\"\nunfolding sim_moves10_def sim_move10_def final_iff finals_iff\napply(simp_all add: Cons_eq_append_conv split del: split_if split: split_if_asm)\napply(safe intro!: if_split)\napply(fastforce simp add: is_vals_conv \\<tau>reds0t_map_Val \\<tau>reds0r_map_Val \\<tau>red0t_Val \\<tau>red0r_Val intro!: \\<tau>red0r_inj_\\<tau>reds0r \\<tau>reds0r_cons_\\<tau>reds0r \\<tau>red0t_inj_\\<tau>reds0t \\<tau>reds0t_cons_\\<tau>reds0t ListRed1 ListRed2 split: split_if_asm)+\ndone\n\nlemma sim_move10_CallParams:\n  \"sim_moves10 P t ta1 es1 es1' es h xs ta es' h' xs'\n  \\<Longrightarrow> sim_move10 P t ta1 (Val v\\<bullet>M(es1)) (Val v\\<bullet>M(es1')) (Val v\\<bullet>M(es)) h xs ta (Val v\\<bullet>M(es')) h' xs'\"\nunfolding sim_move10_def sim_moves10_def\napply(simp split: split_if_asm split del: split_if add: is_vals_conv)\n  apply(fastforce simp add: \\<tau>red0t_Val \\<tau>red0r_Val \\<tau>reds0t_map_Val \\<tau>reds0r_map_Val intro: Call_\\<tau>red0r_param Call_\\<tau>red0t_param CallParams split: split_if_asm split del: split_if intro!: if_split)\n apply(rule conjI)\n  apply fastforce\n apply(rule if_split)\n  apply fastforce\n apply(clarsimp split del: split_if)\n apply(rule if_split)\n  apply(clarsimp split: split_if_asm simp add: is_vals_conv)\n   apply(erule disjE)\n    apply clarsimp\n    apply(rule exI conjI)+\n     apply(erule Call_\\<tau>red0r_param)\n    apply(fastforce intro: CallParams)\n   apply(fastforce simp add: \\<tau>reds0r_map_Val)\n  apply(rule exI conjI)+\n   apply(erule Call_\\<tau>red0r_param)\n  apply(fastforce intro!: CallParams)\n apply(clarsimp split del: split_if split: split_if_asm simp add: is_vals_conv \\<tau>reds0r_map_Val)\n apply fastforce\napply(rule conjI)\n apply fastforce\napply(rule if_split)\n apply fastforce\napply(rule conjI)\n apply fastforce\napply(rule if_split)\n apply(clarsimp split: split_if_asm)\napply(clarsimp split: split_if_asm split del: split_if simp add: is_vals_conv)\napply(fastforce intro: CallParams)\ndone\n\nlemma sim_move10_Block:\n  \"sim_move10 P t ta1 e1 e1' e h (xs(V' := vo)) ta e' h' xs'\n  \\<Longrightarrow> sim_move10 P t ta1 ({V:T=None; e1}) ({V:T=None; e1'}) ({V':T=vo; e}) h xs ta ({V':T=xs' V'; e'}) h' (xs'(V' := xs V'))\"\nproof -\n  assume \"sim_move10 P t ta1 e1 e1' e h (xs(V' := vo)) ta e' h' xs'\"\n  moreover {\n    fix e'' xs''\n    assume \"extTA2J0 P,P,t \\<turnstile> \\<langle>e'',(h, xs'')\\<rangle> -ta\\<rightarrow> \\<langle>e',(h', xs')\\<rangle>\"\n    hence \"extTA2J0 P,P,t \\<turnstile> \\<langle>e'',(h, xs''(V' := xs V', V' := xs'' V'))\\<rangle> -ta\\<rightarrow> \\<langle>e',(h', xs')\\<rangle>\" by simp\n    from BlockRed[OF this, of T]\n    have \"extTA2J0 P,P,t \\<turnstile> \\<langle>{V':T=xs'' V'; e''},(h, xs''(V' := xs V'))\\<rangle> -ta\\<rightarrow> \\<langle>{V':T=xs' V'; e'},(h', xs'(V' := xs V'))\\<rangle>\"\n      by simp }\n  ultimately show ?thesis\n    by(fastforce simp add: sim_move10_def final_iff split: split_if_asm)\nqed\n\nlemma sim_move10_reds:\n  \"\\<lbrakk> (h', a) \\<in> allocate h (Class_type C); ta1 = \\<lbrace>NewHeapElem a (Class_type C)\\<rbrace>; ta = \\<lbrace>NewHeapElem a (Class_type C)\\<rbrace> \\<rbrakk>\n  \\<Longrightarrow> sim_move10 P t ta1 (new C) e1' (new C) h xs ta (addr a) h' xs\"\n  \"allocate h (Class_type C) = {} \\<Longrightarrow> sim_move10 P t \\<epsilon> (new C) e1' (new C) h xs \\<epsilon> (THROW OutOfMemory) h xs\"\n  \"\\<lbrakk> (h', a) \\<in> allocate h (Array_type T (nat (sint i))); 0 <=s i;\n     ta1 = \\<lbrace>NewHeapElem a (Array_type T (nat (sint i)))\\<rbrace>; ta = \\<lbrace>NewHeapElem a (Array_type T (nat (sint i)))\\<rbrace> \\<rbrakk>\n  \\<Longrightarrow> sim_move10 P t ta1 (newA T\\<lfloor>Val (Intg i)\\<rceil>) e1' (newA T\\<lfloor>Val (Intg i)\\<rceil>) h xs ta (addr a) h' xs\"\n  \"i <s 0 \\<Longrightarrow> sim_move10 P t \\<epsilon> (newA T\\<lfloor>Val (Intg i)\\<rceil>) e1' (newA T\\<lfloor>Val (Intg i)\\<rceil>) h xs \\<epsilon> (THROW NegativeArraySize) h xs\"\n  \"\\<lbrakk> allocate h (Array_type T (nat (sint i))) = {}; 0 <=s i \\<rbrakk>\n  \\<Longrightarrow> sim_move10 P t \\<epsilon> (newA T\\<lfloor>Val (Intg i)\\<rceil>) e1' (newA T\\<lfloor>Val (Intg i)\\<rceil>) h xs \\<epsilon> (THROW OutOfMemory) h xs\"\n  \"\\<lbrakk> typeof\\<^bsub>h\\<^esub> v = \\<lfloor>U\\<rfloor>; P \\<turnstile> U \\<le> T \\<rbrakk>\n  \\<Longrightarrow> sim_move10 P t \\<epsilon> (Cast T (Val v)) e1' (Cast T (Val v)) h xs \\<epsilon> (Val v) h xs\"\n  \"\\<lbrakk> typeof\\<^bsub>h\\<^esub> v = \\<lfloor>U\\<rfloor>; \\<not> P \\<turnstile> U \\<le> T \\<rbrakk>\n  \\<Longrightarrow> sim_move10 P t \\<epsilon> (Cast T (Val v)) e1' (Cast T (Val v)) h xs \\<epsilon> (THROW ClassCast) h xs\"\n  \"\\<lbrakk> typeof\\<^bsub>h\\<^esub> v = \\<lfloor>U\\<rfloor>; b \\<longleftrightarrow> v \\<noteq> Null \\<and> P \\<turnstile> U \\<le> T \\<rbrakk>\n  \\<Longrightarrow> sim_move10 P t \\<epsilon> ((Val v) instanceof T) e1' ((Val v) instanceof T) h xs \\<epsilon> (Val (Bool b)) h xs\"\n  \"binop bop v1 v2 = Some (Inl v) \\<Longrightarrow> sim_move10 P t \\<epsilon> ((Val v1) \\<guillemotleft>bop\\<guillemotright> (Val v2)) e1' (Val v1 \\<guillemotleft>bop\\<guillemotright> Val v2) h xs \\<epsilon> (Val v) h xs\"\n  \"binop bop v1 v2 = Some (Inr a) \\<Longrightarrow> sim_move10 P t \\<epsilon> ((Val v1) \\<guillemotleft>bop\\<guillemotright> (Val v2)) e1' (Val v1 \\<guillemotleft>bop\\<guillemotright> Val v2) h xs \\<epsilon> (Throw a) h xs\"\n  \"xs V = \\<lfloor>v\\<rfloor> \\<Longrightarrow> sim_move10 P t \\<epsilon> (Var V') e1' (Var V) h xs \\<epsilon> (Val v) h xs\"\n  \"sim_move10 P t \\<epsilon> (V' := Val v) e1' (V := Val v) h xs \\<epsilon> unit h (xs(V \\<mapsto> v))\"\n  \"sim_move10 P t \\<epsilon> (null\\<lfloor>Val v\\<rceil>) e1' (null\\<lfloor>Val v\\<rceil>) h xs \\<epsilon> (THROW NullPointer) h xs\"\n  \"\\<lbrakk> typeof_addr h a = \\<lfloor>Array_type T n\\<rfloor>; i <s 0 \\<or> sint i \\<ge> int n \\<rbrakk>\n  \\<Longrightarrow> sim_move10 P t \\<epsilon> (addr a\\<lfloor>Val (Intg i)\\<rceil>) e1' ((addr a)\\<lfloor>Val (Intg i)\\<rceil>) h xs \\<epsilon> (THROW ArrayIndexOutOfBounds) h xs\"\n  \"\\<lbrakk> typeof_addr h a = \\<lfloor>Array_type T n\\<rfloor>; 0 <=s i; sint i < int n;\n     heap_read h a (ACell (nat (sint i))) v;\n     ta1 = \\<lbrace>ReadMem a (ACell (nat (sint i))) v\\<rbrace>; ta = \\<lbrace>ReadMem a (ACell (nat (sint i))) v\\<rbrace> \\<rbrakk>\n  \\<Longrightarrow> sim_move10 P t ta1 (addr a\\<lfloor>Val (Intg i)\\<rceil>) e1' ((addr a)\\<lfloor>Val (Intg i)\\<rceil>) h xs ta (Val v) h xs\"\n  \"sim_move10 P t \\<epsilon> (null\\<lfloor>Val v\\<rceil> := Val v') e1' (null\\<lfloor>Val v\\<rceil> := Val v') h xs \\<epsilon> (THROW NullPointer) h xs\"\n  \"\\<lbrakk> typeof_addr h a = \\<lfloor>Array_type T n\\<rfloor>; i <s 0 \\<or> sint i \\<ge> int n \\<rbrakk>\n  \\<Longrightarrow> sim_move10 P t \\<epsilon> (AAss (addr a) (Val (Intg i)) (Val v)) e1' (AAss (addr a) (Val (Intg i)) (Val v)) h xs \\<epsilon> (THROW ArrayIndexOutOfBounds) h xs\"\n \"\\<lbrakk> typeof_addr h a = \\<lfloor>Array_type T n\\<rfloor>; 0 <=s i; sint i < int n; typeof\\<^bsub>h\\<^esub> v = \\<lfloor>U\\<rfloor>; \\<not> (P \\<turnstile> U \\<le> T) \\<rbrakk>\n  \\<Longrightarrow> sim_move10 P t \\<epsilon> (AAss (addr a) (Val (Intg i)) (Val v)) e1' (AAss (addr a) (Val (Intg i)) (Val v)) h xs \\<epsilon> (THROW ArrayStore) h xs\"\n  \"\\<lbrakk> typeof_addr h a = \\<lfloor>Array_type T n\\<rfloor>; 0 <=s i; sint i < int n; typeof\\<^bsub>h\\<^esub> v = Some U; P \\<turnstile> U \\<le> T;\n     heap_write h a (ACell (nat (sint i))) v h';\n     ta1 = \\<lbrace>WriteMem a (ACell (nat (sint i))) v\\<rbrace>; ta = \\<lbrace>WriteMem a (ACell (nat (sint i))) v\\<rbrace> \\<rbrakk>\n  \\<Longrightarrow> sim_move10 P t ta1 (AAss (addr a) (Val (Intg i)) (Val v)) e1' (AAss (addr a) (Val (Intg i)) (Val v)) h xs ta unit h' xs\"\n  \"typeof_addr h a = \\<lfloor>Array_type T n\\<rfloor> \\<Longrightarrow> sim_move10 P t \\<epsilon> (addr a\\<bullet>length) e1' (addr a\\<bullet>length) h xs \\<epsilon> (Val (Intg (word_of_int (int n)))) h xs\"\n  \"sim_move10 P t \\<epsilon> (null\\<bullet>length) e1' (null\\<bullet>length) h xs \\<epsilon> (THROW NullPointer) h xs\"\n  \"\\<lbrakk> heap_read h a (CField D F) v; ta1 = \\<lbrace>ReadMem a (CField D F) v\\<rbrace>; ta = \\<lbrace>ReadMem a (CField D F) v\\<rbrace> \\<rbrakk>\n  \\<Longrightarrow> sim_move10 P t ta1 (addr a\\<bullet>F{D}) e1' (addr a\\<bullet>F{D}) h xs ta (Val v) h xs\"\n  \"sim_move10 P t \\<epsilon> (null\\<bullet>F{D}) e1' (null\\<bullet>F{D}) h xs \\<epsilon> (THROW NullPointer) h xs\"\n  \"\\<lbrakk> heap_write h a (CField D F) v h'; ta1 = \\<lbrace>WriteMem a (CField D F) v\\<rbrace>; ta = \\<lbrace>WriteMem a (CField D F) v\\<rbrace> \\<rbrakk>\n  \\<Longrightarrow> sim_move10 P t ta1 (addr a\\<bullet>F{D} := Val v) e1' (addr a\\<bullet>F{D} := Val v) h xs ta unit h' xs\"\n\n  \"sim_move10 P t \\<epsilon> (null\\<bullet>F{D} := Val v) e1' (null\\<bullet>F{D} := Val v) h xs \\<epsilon> (THROW NullPointer) h xs\"\n  \"sim_move10 P t \\<epsilon> ({V':T=None; Val u}) e1' ({V:T=vo; Val u}) h xs \\<epsilon> (Val u) h xs\"\n  \"sim_move10 P t \\<epsilon> ({V':T=\\<lfloor>v\\<rfloor>; e}) ({V':T=None; e}) ({V:T=vo; e'}) h xs \\<epsilon> ({V:T=vo; e'}) h xs\"\n  \"sim_move10 P t \\<epsilon> (sync\\<^bsub>V'\\<^esub>(null) e0) e1' (sync(null) e1) h xs \\<epsilon> (THROW NullPointer) h xs\"\n  \"sim_move10 P t \\<epsilon> (Val v;;e0) e1' (Val v;; e1) h xs \\<epsilon> e1 h xs\"\n  \"sim_move10 P t \\<epsilon> (if (true) e0 else e0') e1' (if (true) e1 else e2) h xs \\<epsilon> e1 h xs\"\n  \"sim_move10 P t \\<epsilon> (if (false) e0 else e0') e1' (if (false) e1 else e2) h xs \\<epsilon> e2 h xs\"\n  \"sim_move10 P t \\<epsilon> (throw null) e1' (throw null) h xs \\<epsilon> (THROW NullPointer) h xs\"\n  \"sim_move10 P t \\<epsilon> (try (Val v) catch(C V') e0) e1' (try (Val v) catch(C V) e1) h xs \\<epsilon> (Val v) h xs\"\n  \"\\<lbrakk> typeof_addr h a = \\<lfloor>Class_type D\\<rfloor>; P \\<turnstile> D \\<preceq>\\<^sup>* C \\<rbrakk>\n  \\<Longrightarrow> sim_move10 P t \\<epsilon> (try (Throw a) catch(C V') e0) e1' (try (Throw a) catch(C V) e1) h xs \\<epsilon> ({V:Class C=\\<lfloor>Addr a\\<rfloor>; e1}) h xs\"\n  \"sim_move10 P t \\<epsilon> (newA T\\<lfloor>Throw a\\<rceil>) e1' (newA T\\<lfloor>Throw a\\<rceil>) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> (Cast T (Throw a)) e1' (Cast T (Throw a)) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> ((Throw a) instanceof T) e1' ((Throw a) instanceof T) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> ((Throw a) \\<guillemotleft>bop\\<guillemotright> e0) e1' ((Throw a) \\<guillemotleft>bop\\<guillemotright> e1) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> (Val v \\<guillemotleft>bop\\<guillemotright> (Throw a)) e1' (Val v \\<guillemotleft>bop\\<guillemotright> (Throw a)) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> (V' := Throw a) e1' (V := Throw a) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> (Throw a\\<lfloor>e0\\<rceil>) e1' (Throw a\\<lfloor>e1\\<rceil>) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> (Val v\\<lfloor>Throw a\\<rceil>) e1' (Val v\\<lfloor>Throw a\\<rceil>) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> (Throw a\\<lfloor>e0\\<rceil> := e0') e1' (Throw a\\<lfloor>e1\\<rceil> := e2) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> (Val v\\<lfloor>Throw a\\<rceil> := e0) e1' (Val v\\<lfloor>Throw a\\<rceil> := e1) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> (Val v\\<lfloor>Val v'\\<rceil> := Throw a) e1' (Val v\\<lfloor>Val v'\\<rceil> := Throw a) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> (Throw a\\<bullet>length) e1' (Throw a\\<bullet>length) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> (Throw a\\<bullet>F{D}) e1' (Throw a\\<bullet>F{D}) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> (Throw a\\<bullet>F{D} := e0) e1' (Throw a\\<bullet>F{D} := e1) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> (Val v\\<bullet>F{D} := Throw a) e1' (Val v\\<bullet>F{D} := Throw a) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> (Throw a\\<bullet>M(es0)) e1' (Throw a\\<bullet>M(es1)) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> (Val v\\<bullet>M(map Val vs @ Throw a # es0)) e1' (Val v\\<bullet>M(map Val vs @ Throw a # es1)) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> ({V':T=None; Throw a}) e1' ({V:T=vo; Throw a}) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> (sync\\<^bsub>V'\\<^esub>(Throw a) e0) e1' (sync(Throw a) e1) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> (Throw a;;e0) e1' (Throw a;;e1) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> (if (Throw a) e0 else e0') e1' (if (Throw a) e1 else e2) h xs \\<epsilon> (Throw a) h xs\"\n  \"sim_move10 P t \\<epsilon> (throw (Throw a)) e1' (throw (Throw a)) h xs \\<epsilon> (Throw a) h xs\"\napply(fastforce simp add: sim_move10_def no_calls_def no_call_def ta_bisim_def intro: red_reds.intros)+\ndone\n\nlemma sim_move10_CallNull:\n  \"sim_move10 P t \\<epsilon> (null\\<bullet>M(map Val vs)) e1' (null\\<bullet>M(map Val vs)) h xs \\<epsilon> (THROW NullPointer) h xs\"\nby(fastforce simp add: sim_move10_def map_eq_append_conv intro: RedCallNull)\n\nlemma sim_move10_SyncLocks:\n  \"\\<lbrakk> ta1 = \\<lbrace>Lock\\<rightarrow>a, SyncLock a\\<rbrace>; ta = \\<lbrace>Lock\\<rightarrow>a, SyncLock a\\<rbrace> \\<rbrakk>\n   \\<Longrightarrow> sim_move10 P t ta1 (sync\\<^bsub>V\\<^esub>(addr a) e0) e1' (sync(addr a) e1) h xs ta (insync(a) e1) h xs\"\n  \"\\<lbrakk> ta1 = \\<lbrace>Unlock\\<rightarrow>a, SyncUnlock a\\<rbrace>; ta = \\<lbrace>Unlock\\<rightarrow>a, SyncUnlock a\\<rbrace> \\<rbrakk>\n  \\<Longrightarrow> sim_move10 P t ta1 (insync\\<^bsub>V\\<^esub>(a') (Val v)) e1' (insync(a) (Val v)) h xs ta (Val v) h xs\"\n  \"\\<lbrakk> ta1 = \\<lbrace>Unlock\\<rightarrow>a, SyncUnlock a\\<rbrace>; ta = \\<lbrace>Unlock\\<rightarrow>a, SyncUnlock a\\<rbrace> \\<rbrakk>\n  \\<Longrightarrow> sim_move10 P t ta1 (insync\\<^bsub>V\\<^esub>(a') (Throw a'')) e1' (insync(a) (Throw a'')) h xs ta (Throw a'') h xs\"\nby(fastforce simp add: sim_move10_def ta_bisim_def ta_upd_simps intro: red_reds.intros[simplified])+\n\nlemma sim_move10_TryFail:\n  \"\\<lbrakk> typeof_addr h a = \\<lfloor>Class_type D\\<rfloor>; \\<not> P \\<turnstile> D \\<preceq>\\<^sup>* C \\<rbrakk>\n  \\<Longrightarrow> sim_move10 P t \\<epsilon> (try (Throw a) catch(C V') e0) e1' (try (Throw a) catch(C V) e1) h xs \\<epsilon> (Throw a) h xs\"\nby(auto simp add: sim_move10_def intro!: RedTryFail)\n\nlemmas sim_move10_intros =\n  sim_move10_expr sim_move10_reds sim_move10_CallNull sim_move10_TryFail sim_move10_Block sim_move10_CallParams\n\nlemma sim_move10_preserves_defass:\n  assumes wf: \"wf_J_prog P\"\n  shows \"\\<lbrakk> sim_move10 P t ta1 e1 e1' e h xs ta e' h' xs'; \\<D> e \\<lfloor>dom xs\\<rfloor> \\<rbrakk> \\<Longrightarrow> \\<D> e' \\<lfloor>dom xs'\\<rfloor>\"\nby(auto simp add: sim_move10_def split: split_if_asm dest!: \\<tau>red0r_preserves_defass[OF wf] \\<tau>red0t_preserves_defass[OF wf] red_preserves_defass[OF wf])\n\ndeclare sim_move10_intros[intro]\n\nlemma assumes wf: \"wf_J_prog P\"\n  shows red_simulates_red1_aux:\n  \"\\<lbrakk> False,compP1 P,t \\<turnstile>1 \\<langle>e1, S\\<rangle> -TA\\<rightarrow> \\<langle>e1', S'\\<rangle>; bisim vs e2 e1 (lcl S); fv e2 \\<subseteq> set vs;\n     x \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl S]; length vs + max_vars e1 \\<le> length (lcl S);\n     \\<D> e2 \\<lfloor>dom x\\<rfloor> \\<rbrakk>\n  \\<Longrightarrow> \\<exists>ta e2' x'. sim_move10 P t TA e1 e1' e2 (hp S) x ta e2' (hp S') x' \\<and> bisim vs e2' e1' (lcl S') \\<and> x' \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl S']\"\n  (is \"\\<lbrakk> _; _; _; _; _; _ \\<rbrakk> \\<Longrightarrow> ?concl e1 e1' e2 S x TA S' e1' vs\")\n\n  and reds_simulates_reds1_aux:\n  \"\\<lbrakk> False,compP1 P,t \\<turnstile>1 \\<langle>es1, S\\<rangle> [-TA\\<rightarrow>] \\<langle>es1', S'\\<rangle>; bisims vs es2 es1 (lcl S); fvs es2 \\<subseteq> set vs;\n     x \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl S]; length vs + max_varss es1 \\<le> length (lcl S);\n     \\<D>s es2 \\<lfloor>dom x\\<rfloor> \\<rbrakk>\n  \\<Longrightarrow> \\<exists>ta es2' x'. sim_moves10 P t TA es1 es1' es2 (hp S) x ta es2' (hp S') x' \\<and> bisims vs es2' es1' (lcl S') \\<and> x' \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl S']\"\n  (is \"\\<lbrakk> _; _; _; _; _; _ \\<rbrakk> \\<Longrightarrow> ?concls es1 es1' es2 S x TA S' es1' vs\")\nproof(induct arbitrary: vs e2 x and vs es2 x rule: red1_reds1.inducts)\n  case (Bin1OpRed1 e s ta e' s' bop e2 Vs E2 X)\n  note IH = `\\<And>vs e2 x. \\<lbrakk> bisim vs e2 e (lcl s); fv e2 \\<subseteq> set vs;\n             x \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl s]; length vs + max_vars e \\<le> length (lcl s); \\<D> e2 \\<lfloor>dom x\\<rfloor>\\<rbrakk>\n             \\<Longrightarrow> ?concl e e' e2 s x ta s' e' vs`\n  from `False,compP1 P,t \\<turnstile>1 \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>` have \"\\<not> is_val e\" by auto\n  with `bisim Vs E2 (e \\<guillemotleft>bop\\<guillemotright> e2) (lcl s)` obtain E E2'\n    where E2: \"E2 = E \\<guillemotleft>bop\\<guillemotright> E2'\" \"e2 = compE1 Vs E2'\" and \"bisim Vs E e (lcl s)\"\n    and sync: \"\\<not> contains_insync E2'\"\n    by(auto elim!: bisim_cases)\n  moreover note IH[of Vs E X] `fv E2 \\<subseteq> set Vs` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]`\n    `length Vs + max_vars (e \\<guillemotleft>bop\\<guillemotright> e2) \\<le> length (lcl s)` `\\<D> E2 \\<lfloor>dom X\\<rfloor>`\n  ultimately obtain TA' e2' x' where \"sim_move10 P t ta e e' E (hp s) X TA' e2' (hp s') x'\"\n    \"bisim Vs e2' e' (lcl s')\" \"x' \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s']\" by(auto)\n  with E2 `fv E2 \\<subseteq> set Vs` sync show ?case by(cases \"is_val e2'\")(auto intro: BinOpRed1)\nnext\n  case (Bin1OpRed2 e s ta e' s' v bop Vs E2 X)\n  note IH = `\\<And>vs e2 x. \\<lbrakk> bisim vs e2 e (lcl s); fv e2 \\<subseteq> set vs;\n             x \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl s]; length vs + max_vars e \\<le> length (lcl s); \\<D> e2 \\<lfloor>dom x\\<rfloor>\\<rbrakk>\n              \\<Longrightarrow> ?concl e e' e2 s x ta s' e' vs`\n  from `bisim Vs E2 (Val v \\<guillemotleft>bop\\<guillemotright> e) (lcl s)` obtain E \n    where E2: \"E2 = Val v \\<guillemotleft>bop\\<guillemotright> E\" and \"bisim Vs E e (lcl s)\" by(auto)\n  moreover note IH[of Vs E X] `fv E2 \\<subseteq> set Vs` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]`\n    `length Vs + max_vars (Val v \\<guillemotleft>bop\\<guillemotright> e) \\<le> length (lcl s)` `\\<D> E2 \\<lfloor>dom X\\<rfloor>` E2\n  ultimately show ?case by(auto intro: BinOpRed2)\nnext\n  case (Red1Var s V v Vs E2 X)\n  from `bisim Vs E2 (Var V) (lcl s)` `fv E2 \\<subseteq> set Vs`\n  obtain V' where \"E2 = Var V'\" \"V' = Vs ! V\" \"V = index Vs V'\" by(clarify, simp)\n  from `E2 = Var V'` `\\<D> E2 \\<lfloor>dom X\\<rfloor>`\n  obtain v' where \"X V' = \\<lfloor>v'\\<rfloor>\" by(auto simp add: hyperset_defs)\n  with `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]` have \"[Vs [\\<mapsto>] lcl s] V' = \\<lfloor>v'\\<rfloor>\" by(rule map_le_SomeD)\n  with `length Vs + max_vars (Var V) \\<le> length (lcl s)`\n  have \"lcl s ! (index Vs V') = v'\" by(auto intro: map_upds_Some_eq_nth_index)\n  with `V = index Vs V'` `lcl s ! V = v` have \"v = v'\" by simp\n  with `X V' = \\<lfloor>v'\\<rfloor>` `E2 = Var V'` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]`\n  show ?case by(fastforce intro: RedVar)\nnext\n  case (LAss1Red e s ta e' s' V Vs E2 X)\n  note IH = `\\<And>vs e2 x. \\<lbrakk> bisim vs e2 e (lcl s); fv e2 \\<subseteq> set vs;\n             x \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl s]; length vs + max_vars e \\<le> length (lcl s); \\<D> e2 \\<lfloor>dom x\\<rfloor>\\<rbrakk>\n            \\<Longrightarrow> ?concl e e' e2 s x ta s' e' vs`\n  from `bisim Vs E2 (V:=e) (lcl s)` obtain E V'\n    where E2: \"E2 = (V':=E)\" \"V = index Vs V'\" and \"bisim Vs E e (lcl s)\" by auto\n  with IH[of Vs E X] `fv E2 \\<subseteq> set Vs` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]`\n    `length Vs + max_vars (V:=e) \\<le> length (lcl s)` `\\<D> E2 \\<lfloor>dom X\\<rfloor>`\n    E2 show ?case by(auto intro: LAssRed)\nnext\n  case (Red1LAss V l v h Vs E2 X)\n  from `bisim Vs E2 (V:=Val v) (lcl (h, l))` obtain V' where \"E2 = (V' := Val v)\" \"V = index Vs V'\" by(auto)\n  moreover with `fv E2 \\<subseteq> set Vs` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl (h, l)]` `length Vs + max_vars (V:=Val v) \\<le> length (lcl (h, l))`\n  have \"X(V' \\<mapsto> v) \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] l[index Vs V' := v]]\" by(auto intro: LAss_lem)\n  ultimately show ?case by(auto intro: RedLAss simp del: fun_upd_apply)\nnext\n  case (AAcc1Red1 a s ta a' s' i Vs E2 X)\n  note IH = `\\<And>vs e2 x. \\<lbrakk> bisim vs e2 a (lcl s); fv e2 \\<subseteq> set vs;\n             x \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl s]; length vs + max_vars a \\<le> length (lcl s); \\<D> e2 \\<lfloor>dom x\\<rfloor>\\<rbrakk>\n             \\<Longrightarrow> ?concl a a' e2 s x ta s' a' vs`\n  from `False,compP1 P,t \\<turnstile>1 \\<langle>a,s\\<rangle> -ta\\<rightarrow> \\<langle>a',s'\\<rangle>` have \"\\<not> is_val a\" by auto\n  with `bisim Vs E2 (a\\<lfloor>i\\<rceil>) (lcl s)` obtain E E2'\n    where E2: \"E2 = E\\<lfloor>E2'\\<rceil>\" \"i = compE1 Vs E2'\" and \"bisim Vs E a (lcl s)\"\n    and sync: \"\\<not> contains_insync E2'\" by(fastforce)\n  moreover note IH[of Vs E X] `fv E2 \\<subseteq> set Vs` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]`\n    `length Vs + max_vars (a\\<lfloor>i\\<rceil>) \\<le> length (lcl s)` `\\<D> E2 \\<lfloor>dom X\\<rfloor>`\n  ultimately obtain TA' e2' x' where \"sim_move10 P t ta a a' E (hp s) X TA' e2' (hp s') x'\"\n    \"bisim Vs e2' a' (lcl s')\" \"x' \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s']\" by(auto)\n  with E2 `fv E2 \\<subseteq> set Vs` sync show ?case\n    by(cases \"is_val e2'\")(auto intro: AAccRed1)\nnext\n  case (AAcc1Red2 i s ta i' s' a Vs E2 X)\n  note IH = `\\<And>vs e2 x. \\<lbrakk> bisim vs e2 i (lcl s); fv e2 \\<subseteq> set vs;\n             x \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl s]; length vs + max_vars i \\<le> length (lcl s); \\<D> e2 \\<lfloor>dom x\\<rfloor>\\<rbrakk>\n            \\<Longrightarrow> ?concl i i' e2 s x ta s' i' vs`\n  from `bisim Vs E2 (Val a\\<lfloor>i\\<rceil>) (lcl s)` obtain E \n    where E2: \"E2 = Val a\\<lfloor>E\\<rceil>\" and \"bisim Vs E i (lcl s)\" by(auto)\n  moreover note IH[of Vs E X] `fv E2 \\<subseteq> set Vs` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]` E2\n    `length Vs + max_vars (Val a\\<lfloor>i\\<rceil>) \\<le> length (lcl s)` `\\<D> E2 \\<lfloor>dom X\\<rfloor>`\n  ultimately show ?case by(auto intro: AAccRed2)\nnext\n  case Red1AAcc thus ?case by(fastforce intro: RedAAcc simp del: fun_upd_apply)\nnext\n  case (AAss1Red1 a s ta a' s' i e Vs E2 X)\n  note IH = `\\<And>vs e2 x. \\<lbrakk> bisim vs e2 a (lcl s); fv e2 \\<subseteq> set vs;\n             x \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl s]; length vs + max_vars a \\<le> length (lcl s); \\<D> e2 \\<lfloor>dom x\\<rfloor> \\<rbrakk>\n             \\<Longrightarrow> ?concl a a' e2 s x ta s' a' vs`\n  from `False,compP1 P,t \\<turnstile>1 \\<langle>a,s\\<rangle> -ta\\<rightarrow> \\<langle>a',s'\\<rangle>` have \"\\<not> is_val a\" by auto\n  with `bisim Vs E2 (a\\<lfloor>i\\<rceil>:=e) (lcl s)` obtain E E2' E2''\n    where E2: \"E2 = E\\<lfloor>E2'\\<rceil>:=E2''\" \"i = compE1 Vs E2'\" \"e = compE1 Vs E2''\" and \"bisim Vs E a (lcl s)\"\n    and sync: \"\\<not> contains_insync E2'\" \"\\<not> contains_insync E2''\" by(fastforce)\n  moreover note IH[of Vs E X] `fv E2 \\<subseteq> set Vs` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]`\n    `length Vs + max_vars (a\\<lfloor>i\\<rceil>:=e) \\<le> length (lcl s)` `\\<D> E2 \\<lfloor>dom X\\<rfloor>`\n  ultimately obtain TA' e2' x' where IH': \"sim_move10 P t ta a a' E (hp s) X TA' e2' (hp s') x'\"\n    \"bisim Vs e2' a' (lcl s')\" \"x' \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s']\" by(auto)\n  show ?case\n  proof(cases \"is_val e2'\")\n    case True\n    from E2 `fv E2 \\<subseteq> set Vs` sync have \"bisim Vs E2' i (lcl s')\" \"bisim Vs E2'' e (lcl s')\" by auto\n    with IH' E2 True sync show ?thesis\n      by(cases \"is_val E2'\")(fastforce intro: AAssRed1)+\n  next\n    case False with IH' E2 sync show ?thesis by(fastforce intro: AAssRed1)\n  qed\nnext\n  case (AAss1Red2 i s ta i' s' a e Vs E2 X)\n  note IH = `\\<And>vs e2 x. \\<lbrakk> bisim vs e2 i (lcl s); fv e2 \\<subseteq> set vs;\n             x \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl s]; length vs + max_vars i \\<le> length (lcl s); \\<D> e2 \\<lfloor>dom x\\<rfloor>\\<rbrakk>\n            \\<Longrightarrow> ?concl i i' e2 s x ta s' i' vs`\n  from `False,compP1 P,t \\<turnstile>1 \\<langle>i,s\\<rangle> -ta\\<rightarrow> \\<langle>i',s'\\<rangle>` have \"\\<not> is_val i\" by auto\n  with `bisim Vs E2 (Val a\\<lfloor>i\\<rceil>:=e) (lcl s)` obtain E E2'\n    where E2: \"E2 = Val a\\<lfloor>E\\<rceil>:=E2'\" \"e = compE1 Vs E2'\" and \"bisim Vs E i (lcl s)\"\n    and sync: \"\\<not> contains_insync E2'\" by(fastforce)\n  moreover note IH[of Vs E X] `fv E2 \\<subseteq> set Vs` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]`\n    `length Vs + max_vars (Val a\\<lfloor>i\\<rceil>:=e) \\<le> length (lcl s)` `\\<D> E2 \\<lfloor>dom X\\<rfloor>`\n  ultimately obtain TA' e2' x' where \"sim_move10 P t ta i i' E (hp s) X TA' e2' (hp s') x'\"\n    \"bisim Vs e2' i' (lcl s')\" \"x' \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s']\" by(auto)\n  with E2 `fv E2 \\<subseteq> set Vs` sync show ?case\n    by(cases \"is_val e2'\")(fastforce intro: AAssRed2)+\nnext\n  case (AAss1Red3 e s ta e' s' a i Vs E2 X)\n  note IH = `\\<And>vs e2 x. \\<lbrakk> bisim vs e2 e (lcl s); fv e2 \\<subseteq> set vs;\n             x \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl s]; length vs + max_vars e \\<le> length (lcl s); \\<D> e2 \\<lfloor>dom x\\<rfloor>\\<rbrakk>\n            \\<Longrightarrow> ?concl e e' e2 s x ta s' e' vs`\n  from `bisim Vs E2 (Val a\\<lfloor>Val i\\<rceil>:=e) (lcl s)` obtain E\n    where E2: \"E2 = Val a\\<lfloor>Val i\\<rceil>:=E\" and \"bisim Vs E e (lcl s)\" by(fastforce)\n  moreover note IH[of Vs E X] `fv E2 \\<subseteq> set Vs` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]` E2\n    `length Vs + max_vars (Val a\\<lfloor>Val i\\<rceil>:=e) \\<le> length (lcl s)` `\\<D> E2 \\<lfloor>dom X\\<rfloor>`\n  ultimately show ?case by(fastforce intro: AAssRed3)\nnext\n  case Red1AAssStore thus ?case by(auto)((rule exI conjI)+, auto)\nnext\n  case Red1AAss thus ?case \n    by(fastforce simp del: fun_upd_apply)\nnext \n  case (FAss1Red1 e s ta e' s' F D e2 Vs E2 X)\n  note IH = `\\<And>vs e2 x. \\<lbrakk> bisim vs e2 e (lcl s); fv e2 \\<subseteq> set vs;\n             x \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl s]; length vs + max_vars e \\<le> length (lcl s); \\<D> e2 \\<lfloor>dom x\\<rfloor>\\<rbrakk>\n             \\<Longrightarrow> ?concl e e' e2 s x ta s' e' vs`\n  from `False,compP1 P,t \\<turnstile>1 \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>` have \"\\<not> is_val e\" by auto\n  with `bisim Vs E2 (e\\<bullet>F{D}:=e2) (lcl s)` obtain E E2'\n    where E2: \"E2 = E\\<bullet>F{D}:=E2'\" \"e2 = compE1 Vs E2'\" and \"bisim Vs E e (lcl s)\" \n    and sync: \"\\<not> contains_insync E2'\" by(fastforce)\n  with IH[of Vs E X] `fv E2 \\<subseteq> set Vs` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]`\n    `length Vs + max_vars (e\\<bullet>F{D}:=e2) \\<le> length (lcl s)` `\\<D> E2 \\<lfloor>dom X\\<rfloor>`\n  obtain TA' e2' x' where \"sim_move10 P t ta e e' E (hp s) X TA' e2' (hp s') x'\"\n    \"bisim Vs e2' e' (lcl s')\" \"x' \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s']\" by(fastforce)\n  with E2 `fv E2 \\<subseteq> set Vs` sync show ?case by(cases \"is_val e2'\")(auto intro: FAssRed1)\nnext \n  case (FAss1Red2 e s ta e' s' v F D Vs E2 X)\n  note IH = `\\<And>vs e2 x. \\<lbrakk> bisim vs e2 e (lcl s); fv e2 \\<subseteq> set vs;\n             x \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl s]; length vs + max_vars e \\<le> length (lcl s); \\<D> e2 \\<lfloor>dom x\\<rfloor>\\<rbrakk>\n            \\<Longrightarrow> ?concl e e' e2 s x ta s' e' vs`\n  from `bisim Vs E2 (Val v\\<bullet>F{D}:=e) (lcl s)` obtain E\n    where E2: \"E2 = (Val v\\<bullet>F{D}:=E)\" and \"bisim Vs E e (lcl s)\" by(fastforce)\n  with IH[of Vs E X] `fv E2 \\<subseteq> set Vs` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]`\n    `length Vs + max_vars (Val v\\<bullet>F{D}:=e) \\<le> length (lcl s)` `\\<D> E2 \\<lfloor>dom X\\<rfloor>`\n    E2 show ?case by(fastforce intro: FAssRed2)\nnext\n  case (Call1Obj e s ta e' s' M es Vs E2 X)\n  note IH = `\\<And>vs e2 x. \\<lbrakk> bisim vs e2 e (lcl s); fv e2 \\<subseteq> set vs;\n            x \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl s]; length vs + max_vars e \\<le> length (lcl s);\n            \\<D> e2 \\<lfloor>dom x\\<rfloor> \\<rbrakk> \\<Longrightarrow> ?concl e e' e2 s x ta s' e' vs` \n  from `False,compP1 P,t \\<turnstile>1 \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>` `bisim Vs E2 (e\\<bullet>M(es)) (lcl s)`\n  obtain E es' where E2: \"E2 = E\\<bullet>M(es')\" \"es = compEs1 Vs es'\" and \"bisim Vs E e (lcl s)\"\n    and sync: \"\\<not> contains_insyncs es'\" by(auto elim!: bisim_cases simp add: compEs1_conv_map)\n  with IH[of Vs E X] `fv E2 \\<subseteq> set Vs` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]`\n    `length Vs + max_vars (e\\<bullet>M(es)) \\<le> length (lcl s)` `\\<D> E2 \\<lfloor>dom X\\<rfloor>`\n  obtain TA' e2' x' where IH': \"sim_move10 P t ta e e' E (hp s) X TA' e2' (hp s') x'\"\n    \"bisim Vs e2' e' (lcl s')\" \"x' \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s']\" by(fastforce)\n  with E2 `fv E2 \\<subseteq> set Vs` `E2 = E\\<bullet>M(es')` sync show ?case\n    by(cases \"is_val e2'\")(auto intro: CallObj)\nnext\n  case (Call1Params es s ta es' s' v M Vs E2 X)\n  note IH = `\\<And>vs es2 x. \\<lbrakk> bisims vs es2 es (lcl s); fvs es2 \\<subseteq> set vs;\n            x \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl s]; length vs + max_varss es \\<le> length (lcl s); \\<D>s es2 \\<lfloor>dom x\\<rfloor>\\<rbrakk> \n           \\<Longrightarrow> ?concls es es' es2 s x ta s' es' vs`\n  from `bisim Vs E2 (Val v\\<bullet>M(es)) (lcl s)` obtain Es\n    where \"E2 = Val v \\<bullet>M(Es)\" \"bisims Vs Es es (lcl s)\" by(auto)\n  with IH[of Vs Es X] `fv E2 \\<subseteq> set Vs` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]`\n    `length Vs + max_vars (Val v\\<bullet>M(es)) \\<le> length (lcl s)` `\\<D> E2 \\<lfloor>dom X\\<rfloor>`\n    `E2 = Val v \\<bullet>M(Es)` show ?case by(fastforce intro: CallParams)\nnext\n  case (Red1CallExternal s a T M Ts Tr D vs ta va h' e' s' Vs E2 X)\n  from `bisim Vs E2 (addr a\\<bullet>M(map Val vs)) (lcl s)` have E2: \"E2 = addr a\\<bullet>M(map Val vs)\" by auto\n  moreover from `compP1 P \\<turnstile> class_type_of T sees M: Ts\\<rightarrow>Tr = Native in D`\n  have \"P \\<turnstile> class_type_of T sees M: Ts\\<rightarrow>Tr = Native in D\" by simp\n  moreover from `compP1 P,t \\<turnstile> \\<langle>a\\<bullet>M(vs),hp s\\<rangle> -ta\\<rightarrow>ext \\<langle>va,h'\\<rangle>`\n  have \"P,t \\<turnstile> \\<langle>a\\<bullet>M(vs),hp s\\<rangle> -ta\\<rightarrow>ext \\<langle>va,h'\\<rangle>\" by simp\n  moreover from wf `P,t \\<turnstile> \\<langle>a\\<bullet>M(vs),hp s\\<rangle> -ta\\<rightarrow>ext \\<langle>va,h'\\<rangle>`\n  have \"ta_bisim01 (extTA2J0 P ta) (extTA2J1 (compP1 P) ta)\"\n    by(rule red_external_ta_bisim01)\n  moreover note `typeof_addr (hp s) a = \\<lfloor>T\\<rfloor>` `e' = extRet2J1 (addr a\\<bullet>M(map Val vs)) va` `s' = (h', lcl s)`\n  moreover from `typeof_addr (hp s) a = \\<lfloor>T\\<rfloor>` `P,t \\<turnstile> \\<langle>a\\<bullet>M(vs),hp s\\<rangle> -ta\\<rightarrow>ext \\<langle>va,h'\\<rangle>`\n    `P \\<turnstile> class_type_of T sees M: Ts\\<rightarrow>Tr = Native in D`\n  have \"\\<tau>external_defs D M \\<Longrightarrow> ta = \\<epsilon> \\<and> h' = hp s\"\n    by(fastforce dest: \\<tau>external'_red_external_heap_unchanged \\<tau>external'_red_external_TA_empty simp add: \\<tau>external'_def \\<tau>external_def)\n  ultimately show ?case using `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]`\n    by(fastforce intro!: exI[where x=\"extTA2J0 P ta\"] intro: RedCallExternal simp add: map_eq_append_conv sim_move10_def synthesized_call_def dest: sees_method_fun del: disjCI intro: disjI1 disjI2)\nnext\n  case (Block1Red e h x ta e' h' x' V T Vs E2 X)\n  note IH = `\\<And>vs e2 xa. \\<lbrakk> bisim vs e2 e (lcl (h, x)); fv e2 \\<subseteq> set vs; xa \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl (h, x)];\n                       length vs + max_vars e \\<le> length (lcl (h, x)); \\<D> e2 \\<lfloor>dom xa\\<rfloor>\\<rbrakk>\n             \\<Longrightarrow> ?concl e e' e2 (h, x) xa ta (h', x') e' vs` \n  from `False,compP1 P,t \\<turnstile>1 \\<langle>e,(h, x)\\<rangle> -ta\\<rightarrow> \\<langle>e',(h', x')\\<rangle>`\n  have \"length x = length x'\" by(auto dest: red1_preserves_len)\n  with `length Vs + max_vars {V:T=None; e} \\<le> length (lcl (h, x))`\n  have \"length Vs < length x'\" by simp\n  from `bisim Vs E2 {V:T=None; e} (lcl (h, x))`\n  show ?case\n  proof(cases rule: bisim_cases(12)[consumes 1, case_names BlockNone BlockSome BlockSomeNone])\n    case (BlockNone V' E)\n    with `fv E2 \\<subseteq> set Vs` have \"fv E \\<subseteq> set (Vs@[V'])\" by auto\n    with IH[of \"Vs@[V']\" E \"X(V' := None)\"] BlockNone `fv E2 \\<subseteq> set Vs` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl (h, x)]`\n      `length Vs + max_vars {V:T=None; e} \\<le> length (lcl (h, x))` `\\<D> E2 \\<lfloor>dom X\\<rfloor>`\n    obtain TA' e2' X' where IH': \"sim_move10 P t ta e e' E h (X(V' := None)) TA' e2' h' X'\"\n      \"bisim (Vs @ [V']) e2' e' x'\" \"X' \\<subseteq>\\<^sub>m [Vs @ [V'] [\\<mapsto>] x']\"\n      by(fastforce simp del: fun_upd_apply)\n    { assume \"V' \\<in> set Vs\"\n      hence \"hidden (Vs @ [V']) (index Vs V')\" by(rule hidden_index)\n      with `bisim (Vs @ [V']) E e (lcl (h, x))` have \"unmod e (index Vs V')\"\n        by(auto intro: hidden_bisim_unmod)\n      moreover from `length Vs + max_vars {V:T=None; e} \\<le> length (lcl (h, x))` `V' \\<in> set Vs`\n      have \"index Vs V' < length x\" by(auto intro: index_less_aux)\n      ultimately have \"x ! index Vs V' = x' ! index Vs V'\"\n        using red1_preserves_unmod[OF `False,compP1 P,t \\<turnstile>1 \\<langle>e,(h, x)\\<rangle> -ta\\<rightarrow> \\<langle>e',(h', x')\\<rangle>`]\n        by(simp) }\n    with `length Vs + max_vars {V:T=None; e} \\<le> length (lcl (h, x))` \n      `X' \\<subseteq>\\<^sub>m [Vs @ [V'] [\\<mapsto>] x']` `length x = length x'` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl (h, x)]`\n    have rel: \"X'(V' := X V') \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] x']\" by(auto intro: Block_lem)\n\n    show ?thesis\n    proof(cases \"X' V'\")\n      case None\n      with BlockNone IH' rel show ?thesis by(fastforce intro: BlockRed)\n    next\n      case (Some v)\n      with `X' \\<subseteq>\\<^sub>m [Vs @ [V'] [\\<mapsto>] x']` `length Vs < length x'`\n      have \"x' ! length Vs = v\" by(auto dest: map_le_SomeD)\n      with BlockNone IH' rel Some show ?thesis by(fastforce intro: BlockRed)\n    qed\n  next\n    case BlockSome thus ?thesis by simp\n  next\n    case (BlockSomeNone V' E)\n    with `fv E2 \\<subseteq> set Vs` have \"fv E \\<subseteq> set (Vs@[V'])\" by auto\n    with IH[of \"Vs@[V']\" E \"X(V' \\<mapsto> x ! length Vs)\"] BlockSomeNone `fv E2 \\<subseteq> set Vs` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl (h, x)]`\n      `length Vs + max_vars {V:T=None; e} \\<le> length (lcl (h, x))` `\\<D> E2 \\<lfloor>dom X\\<rfloor>`\n    obtain TA' e2' X' where IH': \"sim_move10 P t ta e e' E h (X(V' \\<mapsto> x ! length Vs)) TA' e2' h' X'\"\n      \"bisim (Vs @ [V']) e2' e' x'\" \"X' \\<subseteq>\\<^sub>m [Vs @ [V'] [\\<mapsto>] x']\"\n      by(fastforce simp del: fun_upd_apply)\n    { assume \"V' \\<in> set Vs\"\n      hence \"hidden (Vs @ [V']) (index Vs V')\" by(rule hidden_index)\n      with `bisim (Vs @ [V']) E e (lcl (h, x))` have \"unmod e (index Vs V')\"\n        by(auto intro: hidden_bisim_unmod)\n      moreover from `length Vs + max_vars {V:T=None; e} \\<le> length (lcl (h, x))` `V' \\<in> set Vs`\n      have \"index Vs V' < length x\" by(auto intro: index_less_aux)\n      ultimately have \"x ! index Vs V' = x' ! index Vs V'\"\n        using red1_preserves_unmod[OF `False,compP1 P,t \\<turnstile>1 \\<langle>e,(h, x)\\<rangle> -ta\\<rightarrow> \\<langle>e',(h', x')\\<rangle>`]\n        by(simp) }\n    with `length Vs + max_vars {V:T=None; e} \\<le> length (lcl (h, x))` \n      `X' \\<subseteq>\\<^sub>m [Vs @ [V'] [\\<mapsto>] x']` `length x = length x'` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl (h, x)]`\n    have rel: \"X'(V' := X V') \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] x']\" by(auto intro: Block_lem)\n    from `sim_move10 P t ta e e' E h (X(V' \\<mapsto> x ! length Vs)) TA' e2' h' X'`\n    obtain v' where \"X' V' = \\<lfloor>v'\\<rfloor>\"\n      by(auto simp: sim_move10_def split: split_if_asm dest!: \\<tau>red0t_lcl_incr \\<tau>red0r_lcl_incr red_lcl_incr subsetD)\n    with `X' \\<subseteq>\\<^sub>m [Vs @ [V'] [\\<mapsto>] x']` `length Vs < length x'`\n    have \"x' ! length Vs = v'\" by(auto dest: map_le_SomeD)\n    with BlockSomeNone IH' rel `X' V' = \\<lfloor>v'\\<rfloor>`\n    show ?thesis by(fastforce intro: BlockRed)\n  qed\nnext\n  case(Block1Some V xs T v e h)\n  from `bisim vs e2 {V:T=\\<lfloor>v\\<rfloor>; e} (lcl (h, xs))` obtain e' V' where \"e2 = {V':T=\\<lfloor>v\\<rfloor>; e'}\"\n    and \"V = length vs\" \"bisim (vs @ [V']) e' e (xs[length vs := v])\" by(fastforce)\n  moreover have \"sim_move10 P t \\<epsilon> {length vs:T=\\<lfloor>v\\<rfloor>; e} {length vs:T=None; e} {V':T=\\<lfloor>v\\<rfloor>; e'} h x \\<epsilon> {V':T=\\<lfloor>v\\<rfloor>; e'} h x\"\n    by(auto)\n  moreover from `bisim (vs @ [V']) e' e (xs[length vs := v])`\n    `length vs + max_vars {V:T=\\<lfloor>v\\<rfloor>; e} \\<le> length (lcl (h, xs))`\n  have \"bisim vs {V':T=\\<lfloor>v\\<rfloor>; e'} {length vs:T=None; e} (xs[length vs := v])\" by auto\n  moreover from `x \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl (h, xs)]` `length vs + max_vars {V:T=\\<lfloor>v\\<rfloor>; e} \\<le> length (lcl (h, xs))`\n  have \"x \\<subseteq>\\<^sub>m [vs [\\<mapsto>] xs[length vs := v]]\" by auto\n  ultimately show ?case by auto\nnext\n  case (Lock1Synchronized V xs a e h Vs E2 X)\n  note len = `length Vs + max_vars (sync\\<^bsub>V\\<^esub> (addr a) e) \\<le> length (lcl (h, xs))`\n  from `bisim Vs E2 (sync\\<^bsub>V\\<^esub> (addr a) e) (lcl (h, xs))` obtain E\n    where E2: \"E2 = sync(addr a) E\" \"e = compE1 (Vs@[fresh_var Vs]) E\" \n    and sync: \"\\<not> contains_insync E\" and [simp]: \"V = length Vs\" by auto\n  moreover\n  have \"extTA2J0 P,P,t \\<turnstile> \\<langle>sync(addr a) E, (h, X)\\<rangle> -\\<lbrace>Lock\\<rightarrow>a, SyncLock a\\<rbrace>\\<rightarrow> \\<langle>insync(a) E, (h, X)\\<rangle>\"\n    by(rule LockSynchronized)\n  moreover from `fv E2 \\<subseteq> set Vs` fresh_var_fresh[of Vs] sync len\n  have \"bisim Vs (insync(a) E) (insync\\<^bsub>length Vs\\<^esub> (a) e) (xs[length Vs := Addr a])\"\n    unfolding `e = compE1 (Vs@[fresh_var Vs]) E` `E2 = sync(addr a) E`\n    by -(rule bisimInSynchronized,rule compE1_bisim, auto)\n  moreover have \"zip Vs (xs[length Vs := Addr a]) = (zip Vs xs)[length Vs := (arbitrary, Addr a)]\"\n    by(rule sym)(simp add: update_zip)\n  hence \"zip Vs (xs[length Vs := Addr a]) = zip Vs xs\" by simp\n  with `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] (lcl (h, xs))]` have \"X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] xs[length Vs := Addr a]]\"\n    by(auto simp add: map_le_def map_upds_def)\n  ultimately show ?case by(fastforce intro: sim_move10_SyncLocks)\nnext\n  case (Synchronized1Red2 e s ta e' s' V a Vs E2 X)\n  note IH = `\\<And>vs e2 x. \\<lbrakk> bisim vs e2 e (lcl s); fv e2 \\<subseteq> set vs;\n            x \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl s]; length vs + max_vars e \\<le> length (lcl s);\n            \\<D> e2 \\<lfloor>dom x\\<rfloor> \\<rbrakk> \\<Longrightarrow> ?concl e e' e2 s x ta s' e' vs` \n  from `bisim Vs E2 (insync\\<^bsub>V\\<^esub> (a) e) (lcl s)` obtain E\n    where E2: \"E2 = insync(a) E\" and bisim: \"bisim (Vs@[fresh_var Vs]) E e (lcl s)\"\n    and xsa: \"lcl s ! length Vs = Addr a\" and [simp]: \"V = length Vs\" by auto\n  with `fv E2 \\<subseteq> set Vs` fresh_var_fresh[of Vs] have fv: \"(fresh_var Vs) \\<notin> fv E\" by auto\n  from `length Vs + max_vars (insync\\<^bsub>V\\<^esub> (a) e) \\<le> length (lcl s)` have \"length Vs < length (lcl s)\" by simp\n  { assume \"X (fresh_var Vs) \\<noteq> None\"\n    then obtain v where \"X (fresh_var Vs) = \\<lfloor>v\\<rfloor>\" by auto\n    with `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]` have \"[Vs [\\<mapsto>] lcl s] (fresh_var Vs) = \\<lfloor>v\\<rfloor>\" \n      by(auto simp add: map_le_def dest: bspec)\n    hence \"(fresh_var Vs) \\<in> set Vs\" \n      by(auto simp add: map_upds_def set_zip dest!: map_of_SomeD )\n    moreover have \"(fresh_var Vs) \\<notin> set Vs\" by(rule fresh_var_fresh)\n    ultimately have False by contradiction }\n  hence \"X (fresh_var Vs) = None\" by(cases \"X (fresh_var Vs)\", auto)\n  hence \"X(fresh_var Vs := None) = X\" by(auto intro: ext)\n  moreover from `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]`\n  have \"X(fresh_var Vs := None) \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s, (fresh_var Vs) \\<mapsto> (lcl s) ! length Vs]\" by(simp)\n  ultimately have \"X \\<subseteq>\\<^sub>m [Vs @ [fresh_var Vs] [\\<mapsto>] lcl s]\"\n    using `length Vs < length (lcl s)` by(auto)\n  moreover note IH[of \"Vs@[fresh_var Vs]\" E X] bisim E2 `fv E2 \\<subseteq> set Vs` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]` \n    `length Vs + max_vars (insync\\<^bsub>V\\<^esub> (a) e) \\<le> length (lcl s)` `\\<D> E2 \\<lfloor>dom X\\<rfloor>`\n  ultimately obtain TA' e2' x' where IH': \"sim_move10 P t ta e e' E (hp s) X TA' e2' (hp s') x'\"\n    \"bisim (Vs @ [fresh_var Vs]) e2' e' (lcl s')\" \"x' \\<subseteq>\\<^sub>m [Vs @ [fresh_var Vs] [\\<mapsto>] lcl s']\" by auto\n  hence \"dom x' \\<subseteq> dom X \\<union> fv E\"\n    by(fastforce iff del: domIff simp add: sim_move10_def dest: red_dom_lcl \\<tau>red0r_dom_lcl[OF wf_prog_wwf_prog[OF wf]] \\<tau>red0t_dom_lcl[OF wf_prog_wwf_prog[OF wf]] \\<tau>red0r_fv_subset[OF wf_prog_wwf_prog[OF wf]] split: split_if_asm)\n  with fv `X (fresh_var Vs) = None` have \"(fresh_var Vs) \\<notin> dom x'\" by auto\n  hence \"x' (fresh_var Vs) = None\" by auto\n  moreover from `False,compP1 P,t \\<turnstile>1 \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>`\n  have \"length (lcl s) = length (lcl s')\" by(auto dest: red1_preserves_len)\n  moreover note `x' \\<subseteq>\\<^sub>m [Vs @ [fresh_var Vs] [\\<mapsto>] lcl s']` `length Vs < length (lcl s)`\n  ultimately have \"x' \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s']\" by(auto simp add: map_le_def dest: bspec)\n  moreover from bisim fv have \"unmod e (length Vs)\" by(auto intro: bisim_fv_unmod)\n  with `False,compP1 P,t \\<turnstile>1 \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>` `length Vs < length (lcl s)`\n  have \"lcl s ! length Vs = lcl s' ! length Vs\"\n    by(auto dest!: red1_preserves_unmod)\n  with xsa have \"lcl s' ! length Vs = Addr a\" by simp\n  ultimately show ?case using IH' E2 by(auto intro: SynchronizedRed2)\nnext\n  case (Unlock1Synchronized xs V a' a v h Vs E2 X)\n  from `bisim Vs E2 (insync\\<^bsub>V\\<^esub> (a) Val v) (lcl (h, xs))`\n  have E2: \"E2 = insync(a) Val v\" \"V = length Vs\" \"xs ! length Vs = Addr a\" by auto\n  moreover with `xs ! V = Addr a'` have [simp]: \"a' = a\" by simp\n  have \"extTA2J0 P,P,t \\<turnstile> \\<langle>insync(a) (Val v), (h, X)\\<rangle> -\\<lbrace>Unlock\\<rightarrow>a, SyncUnlock a\\<rbrace>\\<rightarrow> \\<langle>Val v, (h, X)\\<rangle>\"\n    by(rule UnlockSynchronized)\n  ultimately show ?case using `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl (h, xs)]` by(fastforce intro: sim_move10_SyncLocks)\nnext\n  case (Unlock1SynchronizedNull xs V a v h Vs E2 X)\n  from `bisim Vs E2 (insync\\<^bsub>V\\<^esub> (a) Val v) (lcl (h, xs))`\n  have \"V = length Vs\" \"xs ! length Vs = Addr a\" by(auto)\n  with `xs ! V = Null` have False by simp\n  thus ?case ..\nnext\n  case (Unlock1SynchronizedFail xs V A' a' v h Vs E2 X)\n  from `False` show ?case ..\nnext\n  case (Red1While b c s Vs E2 X)\n  from `bisim Vs E2 (while (b) c) (lcl s)` obtain B C\n    where E2: \"E2 = while (B) C\" \"b = compE1 Vs B\" \"c = compE1 Vs C\" \n    and sync: \"\\<not> contains_insync B\" \"\\<not> contains_insync C\" by auto\n  moreover have \"extTA2J0 P,P,t \\<turnstile> \\<langle>while (B) C, (hp s, X)\\<rangle> -\\<epsilon>\\<rightarrow> \\<langle>if (B) (C;;while (B) C) else unit, (hp s, X)\\<rangle>\"\n    by(rule RedWhile)\n  hence \"sim_move10 P t \\<epsilon> (while (compE1 Vs B) (compE1 Vs C)) (if (compE1 Vs B) (compE1 Vs C;;while (compE1 Vs B) (compE1 Vs C)) else unit) (while (B) C) (hp s) X \\<epsilon> (if (B) (C;;while (B) C) else unit) (hp s) X\"\n    by(auto simp add: sim_move10_def)\n  moreover from `fv E2 \\<subseteq> set Vs` E2 sync\n  have \"bisim Vs (if (B) (C;; while (B) C) else unit)\n                 (if (compE1 Vs B) (compE1 Vs (C;; while(B) C)) else (compE1 Vs unit)) (lcl s)\"\n    by -(rule bisimCond, auto)\n  ultimately show ?case using `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]`\n    by(simp)(rule exI, rule exI, rule exI, erule conjI, auto)\nnext\n  case (Red1TryCatch h a D C V x e2 Vs E2 X)\n  from `bisim Vs E2 (try Throw a catch(C V) e2) (lcl (h, x))`\n  obtain E2' V' where \"E2 = try Throw a catch(C V') E2'\" \"V = length Vs\" \"e2 = compE1 (Vs @ [V']) E2'\"\n    and sync: \"\\<not> contains_insync E2'\" by(auto)\n  with `fv E2 \\<subseteq> set Vs` have \"fv E2' \\<subseteq> set (Vs @[V'])\" by auto\n  with `e2 = compE1 (Vs @ [V']) E2'`  sync have \"bisim (Vs @[V']) E2' e2 (x[V := Addr a])\"\n    by(auto intro!: compE1_bisim)\n  with `V = length Vs` `length Vs + max_vars (try Throw a catch(C V) e2) \\<le> length (lcl (h, x))`\n  have \"bisim Vs {V':Class C=\\<lfloor>Addr a\\<rfloor>; E2'} {length Vs:Class C=None; e2} (x[V := Addr a])\"\n    by(auto intro: bisimBlockSomeNone)\n  moreover from `length Vs + max_vars (try Throw a catch(C V) e2) \\<le> length (lcl (h, x))`\n  have \"[Vs [\\<mapsto>] x[length Vs := Addr a]] = [Vs [\\<mapsto>] x]\" by simp\n  with `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl (h, x)]` have \"X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] x[length Vs := Addr a]]\" by simp\n  moreover note `e2 = compE1 (Vs @ [V']) E2'` `E2 = try Throw a catch(C V') E2'`\n    `typeof_addr h a = \\<lfloor>Class_type D\\<rfloor>` `compP1 P \\<turnstile> D \\<preceq>\\<^sup>* C` `V = length Vs`\n  ultimately show ?case by(auto intro!: exI)\nnext\n  case Red1TryFail thus ?case by(auto intro!: exI sim_move10_TryFail)\nnext\n  case (List1Red1 e s ta e' s' es Vs ES2 X)\n  note IH = `\\<And>vs e2 x. \\<lbrakk> bisim vs e2 e (lcl s); fv e2 \\<subseteq> set vs;\n            x \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl s]; length vs + max_vars e \\<le> length (lcl s); \\<D> e2 \\<lfloor>dom x\\<rfloor>\\<rbrakk>\n           \\<Longrightarrow> \\<exists>TA' e2' x'. sim_move10 P t ta e e' e2 (hp s) x TA' e2' (hp s') x' \\<and> \n                 bisim vs e2' e' (lcl s') \\<and> x' \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl s']`\n  from `bisims Vs ES2 (e # es) (lcl s)` `False,compP1 P,t \\<turnstile>1 \\<langle>e,s\\<rangle> -ta\\<rightarrow> \\<langle>e',s'\\<rangle>`\n  obtain E ES where \"ES2 = E # ES\" \"\\<not> is_val E\" \"es = compEs1 Vs ES\" \"bisim Vs E e (lcl s)\"\n    and sync: \"\\<not> contains_insyncs ES\" by(auto elim!: bisims_cases simp add: compEs1_conv_map)\n  with IH[of Vs E X] `fvs ES2 \\<subseteq> set Vs` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]`\n    `length Vs + max_varss (e # es) \\<le> length (lcl s)` `\\<D>s ES2 \\<lfloor>dom X\\<rfloor>`\n  obtain TA' e2' x' where IH': \"sim_move10 P t ta e e' E (hp s) X TA' e2' (hp s') x'\"\n    \"bisim Vs e2' e' (lcl s')\" \"x' \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s']\" by fastforce\n  show ?case\n  proof(cases \"is_val e2'\")\n    case False\n    with IH' `ES2 = E # ES` `es = compEs1 Vs ES` sync show ?thesis by(auto intro: sim_moves10_expr)\n  next\n    case True\n    from `fvs ES2 \\<subseteq> set Vs` `ES2 = E # ES` `es = compEs1 Vs ES` sync\n    have \"bisims Vs ES es (lcl s')\" by(auto intro: compEs1_bisims)\n    with IH' True `ES2 = E # ES` `es = compEs1 Vs ES` show ?thesis by(auto intro: sim_moves10_expr)\n  qed\nnext\n  case (List1Red2 es s ta es' s' v Vs ES2 X)\n  note IH = `\\<And>vs es2 x. \\<lbrakk>bisims vs es2 es (lcl s); fvs es2 \\<subseteq> set vs;\n            x \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl s]; length vs + max_varss es \\<le> length (lcl s); \\<D>s es2 \\<lfloor>dom x\\<rfloor>\\<rbrakk>\n           \\<Longrightarrow> \\<exists>TA' es2' x'. sim_moves10 P t ta es es' es2 (hp s) x TA' es2' (hp s') x' \\<and> bisims vs es2' es' (lcl s') \\<and> x' \\<subseteq>\\<^sub>m [vs [\\<mapsto>] lcl s']`\n  from `bisims Vs ES2 (Val v # es) (lcl s)` obtain ES where \"ES2 = Val v # ES\" \"bisims Vs ES es (lcl s)\"\n    by(auto elim!: bisims_cases)\n  with IH[of Vs ES X] `fvs ES2 \\<subseteq> set Vs` `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl s]`\n    `length Vs + max_varss (Val v # es) \\<le> length (lcl s)` `\\<D>s ES2 \\<lfloor>dom X\\<rfloor>`\n    `ES2 = Val v # ES` show ?case by(fastforce intro: sim_moves10_expr)\nnext\n  case Call1ThrowParams\n  thus ?case by(fastforce intro: CallThrowParams elim!: bisim_cases simp add: bisims_map_Val_Throw2)\nnext\n  case (Synchronized1Throw2 xs V a' a ad h Vs E2 X)\n  from `bisim Vs E2 (insync\\<^bsub>V\\<^esub> (a) Throw ad) (lcl (h, xs))`\n  have \"xs ! length Vs = Addr a\" and \"V = length Vs\" by auto\n  with `xs ! V = Addr a'` have [simp]: \"a' = a\" by simp\n  have \"extTA2J0 P,P,t \\<turnstile> \\<langle>insync(a) Throw ad, (h, X)\\<rangle> -\\<lbrace>Unlock\\<rightarrow>a, SyncUnlock a\\<rbrace>\\<rightarrow> \\<langle>Throw ad, (h, X)\\<rangle>\"\n    by(rule SynchronizedThrow2)\n  with `X \\<subseteq>\\<^sub>m [Vs [\\<mapsto>] lcl (h, xs)]` `bisim Vs E2 (insync\\<^bsub>V\\<^esub> (a) Throw ad) (lcl (h, xs))`\n  show ?case by(auto intro: sim_move10_SyncLocks intro!: exI)\nnext\n  case (Synchronized1Throw2Null xs V a a' h Vs E2 X)\n  from `bisim Vs E2 (insync\\<^bsub>V\\<^esub> (a) Throw a') (lcl (h, xs))`\n  have \"V = length Vs\" \"xs ! length Vs = Addr a\" by(auto)\n  with `xs ! V = Null` have False by simp\n  thus ?case ..\nnext\n  case (Synchronized1Throw2Fail xs V A' a' a h Vs E2 X)\n  from `False` show ?case ..\nnext\n  case InstanceOf1Red thus ?case by auto(blast)\nnext\n  case Red1InstanceOf thus ?case by hypsubst_thin auto\nnext\n  case InstanceOf1Throw thus ?case by auto\nqed(simp_all del: fun_upd_apply, (fastforce intro: red_reds.intros simp del: fun_upd_apply simp add: finfun_upd_apply)+)\n\nlemma bisim_call_Some_call1:\n  \"\\<lbrakk> bisim Vs e e' xs; call e = \\<lfloor>aMvs\\<rfloor>; length Vs + max_vars e' \\<le> length xs \\<rbrakk>\n  \\<Longrightarrow> \\<exists>e'' xs'. \\<tau>red1'r P t h (e', xs) (e'', xs') \\<and> call1 e'' = \\<lfloor>aMvs\\<rfloor> \\<and> \n               bisim Vs e e'' xs' \\<and> take (length Vs) xs = take (length Vs) xs'\"\n\n  and bisims_calls_Some_calls1:\n  \"\\<lbrakk> bisims Vs es es' xs; calls es = \\<lfloor>aMvs\\<rfloor>; length Vs + max_varss es' \\<le> length xs \\<rbrakk> \n  \\<Longrightarrow> \\<exists>es'' xs'. \\<tau>reds1'r P t h (es', xs) (es'', xs') \\<and> calls1 es'' = \\<lfloor>aMvs\\<rfloor> \\<and> \n                bisims Vs es es'' xs' \\<and> take (length Vs) xs = take (length Vs) xs'\"\nproof(induct rule: bisim_bisims.inducts)\n  case bisimCallParams thus ?case\n    by(fastforce simp add: is_vals_conv split: split_if_asm)\nnext\n  case bisimBlockNone thus ?case by(fastforce intro: take_eq_take_le_eq)\nnext\n  case (bisimBlockSome Vs V e e' xs v T)\n  from `length Vs + max_vars {length Vs:T=\\<lfloor>v\\<rfloor>; e'} \\<le> length xs`\n  have \"\\<tau>red1'r P t h ({length Vs:T=\\<lfloor>v\\<rfloor>; e'}, xs) ({length Vs:T=None; e'}, xs[length Vs := v])\"\n    by(auto intro!: \\<tau>red1r_1step Block1Some)\n  also from bisimBlockSome obtain e'' xs'\n    where \"\\<tau>red1'r P t h (e', xs[length Vs := v]) (e'', xs')\"\n    and \"call1 e'' = \\<lfloor>aMvs\\<rfloor>\" \"bisim (Vs @ [V]) e e'' xs'\" \n    and \"take (length (Vs @ [V])) (xs[length Vs := v]) = take (length (Vs @ [V])) xs'\" by auto\n  hence \"\\<tau>red1'r P t h ({length Vs:T=None; e'}, xs[length Vs := v]) ({length Vs:T=None; e''}, xs')\" by auto\n  also from `call1 e'' = \\<lfloor>aMvs\\<rfloor>` have \"call1 {length Vs:T=None; e''} = \\<lfloor>aMvs\\<rfloor>\" by simp\n  moreover from `take (length (Vs @ [V])) (xs[length Vs := v]) = take (length (Vs @ [V])) xs'`\n  have \"take (length Vs) xs = take (length Vs) xs'\"\n    by(auto dest: take_eq_take_le_eq[where m=\"length Vs\"] simp add: take_list_update_beyond)\n  moreover {\n    have \"xs' ! length Vs = take (length (Vs @ [V])) xs' ! length Vs\" by simp\n    also note `take (length (Vs @ [V])) (xs[length Vs := v]) = take (length (Vs @ [V])) xs'`[symmetric]\n    also have \"take (length (Vs @ [V])) (xs[length Vs := v]) ! length Vs = v\"\n      using `length Vs + max_vars {length Vs:T=\\<lfloor>v\\<rfloor>; e'} \\<le> length xs` by simp\n    finally have \"bisim Vs {V:T=\\<lfloor>v\\<rfloor>; e} {length Vs:T=None; e''} xs'\"\n      using `bisim (Vs @ [V]) e e'' xs'` by auto }\n  ultimately show ?case by blast\nnext\n  case (bisimBlockSomeNone Vs V e e' xs v T)\n  then obtain e'' xs' where \"\\<tau>red1'r P t h (e', xs) (e'', xs')\" \"call1 e'' = \\<lfloor>aMvs\\<rfloor>\" \"bisim (Vs @ [V]) e e'' xs'\"\n    and \"take (length (Vs @ [V])) xs = take (length (Vs @ [V])) xs'\" by auto\n  hence \"\\<tau>red1'r P t h ({length Vs:T=None; e'}, xs) ({length Vs:T=None; e''}, xs')\" by auto\n  moreover from `call1 e'' = \\<lfloor>aMvs\\<rfloor>` have \"call1 ({length Vs:T=None; e''}) = \\<lfloor>aMvs\\<rfloor>\" by simp\n  moreover from `take (length (Vs @ [V])) xs = take (length (Vs @ [V])) xs'`\n  have \"take (length Vs) xs = take (length Vs) xs'\" by(auto intro: take_eq_take_le_eq)\n  moreover {\n    have \"xs' ! length Vs = take (length (Vs @ [V])) xs' ! length Vs\" by simp\n    also note `take (length (Vs @ [V])) xs = take (length (Vs @ [V])) xs'`[symmetric]\n    also have \"take (length (Vs @ [V])) xs ! length Vs = v\" using `xs ! length Vs = v` by simp\n    finally have \"bisim Vs {V:T=\\<lfloor>v\\<rfloor>; e} {length Vs:T=None; e''} xs'\"\n      using `bisim (Vs @ [V]) e e'' xs'` by auto }\n  ultimately show ?case by blast\nnext\n  case (bisimInSynchronized Vs e e' xs a)\n  then obtain e'' xs' where \"\\<tau>red1'r P t h (e', xs) (e'', xs')\" \"call1 e'' = \\<lfloor>aMvs\\<rfloor>\" \"bisim (Vs @ [fresh_var Vs]) e e'' xs'\"\n    and \"take (Suc (length Vs)) xs = take (Suc (length Vs)) xs'\" by auto\n  hence \"\\<tau>red1'r P t h (insync\\<^bsub>length Vs\\<^esub> (a) e', xs) (insync\\<^bsub>length Vs\\<^esub> (a) e'', xs')\" by auto\n  moreover from `call1 e'' = \\<lfloor>aMvs\\<rfloor>` have \"call1 (insync\\<^bsub>length Vs\\<^esub> (a) e'') = \\<lfloor>aMvs\\<rfloor>\" by simp\n  moreover from `take (Suc (length Vs)) xs = take (Suc (length Vs)) xs'`\n  have \"take (length Vs) xs = take (length Vs) xs'\" by(auto intro: take_eq_take_le_eq)\n  moreover {\n    have \"xs' ! length Vs = take (Suc (length Vs)) xs' ! length Vs\" by simp\n    also note `take (Suc (length Vs)) xs = take (Suc (length Vs)) xs'`[symmetric]\n    also have \"take (Suc (length Vs)) xs ! length Vs = Addr a\"\n      using `xs ! length Vs = Addr a` by simp\n    finally have \"bisim Vs (insync(a) e) (insync\\<^bsub>length Vs\\<^esub> (a) e'') xs'\"\n      using `bisim (Vs @ [fresh_var Vs]) e e'' xs'` by auto }\n  ultimately show ?case by blast\nnext\n  case bisimsCons1 thus ?case by(fastforce intro!: \\<tau>red1r_inj_\\<tau>reds1r)\nnext\n  case bisimsCons2 thus ?case by(fastforce intro!: \\<tau>reds1r_cons_\\<tau>reds1r)\nqed fastforce+\n\nlemma sim_move01_into_Red1:\n  \"sim_move01 P t ta e E' h xs ta' e2' h' xs'\n  \\<Longrightarrow> if \\<tau>Move0 P h (e, es1)\n      then \\<tau>Red1't P t h ((E', xs), exs2) ((e2', xs'), exs2) \\<and> ta = \\<epsilon> \\<and> h = h'\n      else \\<exists>ex2' exs2' ta'. \\<tau>Red1'r P t h ((E', xs), exs2) (ex2', exs2') \\<and>\n                           (call e = None \\<or> call1 E' = None \\<or> ex2' = (E', xs) \\<and> exs2' = exs2) \\<and>\n                           False,P,t \\<turnstile>1 \\<langle>ex2'/exs2',h\\<rangle> -ta'\\<rightarrow> \\<langle>(e2', xs')/exs2,h'\\<rangle> \\<and>\n                           \\<not> \\<tau>Move1 P h (ex2', exs2') \\<and> ta_bisim01 ta ta'\"\napply(auto simp add: sim_move01_def intro: \\<tau>red1t_into_\\<tau>Red1t \\<tau>red1r_into_\\<tau>Red1r red1Red split: split_if_asm)\napply(fastforce intro: red1Red intro!: \\<tau>red1r_into_\\<tau>Red1r)+\ndone\n\nlemma sim_move01_max_vars_decr:\n  \"sim_move01 P t ta e0 e h xs ta' e' h' xs' \\<Longrightarrow> max_vars e' \\<le> max_vars e\"\nby(fastforce simp add: sim_move01_def split: split_if_asm dest: \\<tau>red1t_max_vars red1_max_vars_decr \\<tau>red1r_max_vars)\n\nlemma Red1_simulates_red0:\n  assumes wf: \"wf_J_prog P\"\n  and red: \"P,t \\<turnstile>0 \\<langle>e1/es1, h\\<rangle> -ta\\<rightarrow> \\<langle>e1'/es1', h'\\<rangle>\"\n  and bisiml: \"bisim_list1 (e1, es1) (ex2, exs2)\"\n  shows \"\\<exists>ex2'' exs2''. bisim_list1 (e1', es1') (ex2'', exs2'') \\<and>\n        (if \\<tau>Move0 P h (e1, es1)\n         then \\<tau>Red1't (compP1 P) t h (ex2, exs2) (ex2'', exs2'') \\<and> ta = \\<epsilon> \\<and> h = h'\n         else \\<exists>ex2' exs2' ta'. \\<tau>Red1'r (compP1 P) t h (ex2, exs2) (ex2', exs2') \\<and> \n                               (call e1 = None \\<or> call1 (fst ex2) = None \\<or> ex2' = ex2 \\<and> exs2' = exs2) \\<and>\n                               False,compP1 P,t \\<turnstile>1 \\<langle>ex2'/exs2', h\\<rangle> -ta'\\<rightarrow> \\<langle>ex2''/exs2'', h'\\<rangle> \\<and>\n                               \\<not> \\<tau>Move1 P h (ex2', exs2') \\<and> ta_bisim01 ta ta')\"\n  (is \"\\<exists>ex2'' exs2'' . _ \\<and> ?red ex2'' exs2''\")\nusing red\nproof(cases)\n  case (red0Red XS')\n  note [simp] = `es1' = es1`\n    and red = `extTA2J0 P,P,t \\<turnstile> \\<langle>e1,(h, empty)\\<rangle> -ta\\<rightarrow> \\<langle>e1',(h', XS')\\<rangle>`\n    and notsynth = `\\<forall>aMvs. call e1 = \\<lfloor>aMvs\\<rfloor> \\<longrightarrow> synthesized_call P h aMvs`\n  from bisiml obtain E xs where ex2: \"ex2 = (E, xs)\"\n    and bisim: \"bisim [] e1 E xs\" and fv: \"fv e1 = {}\" \n    and length: \"max_vars E \\<le> length xs\" and bsl: \"bisim_list es1 exs2\"\n    and D: \"\\<D> e1 \\<lfloor>{}\\<rfloor>\" by(auto elim!: bisim_list1_elim)\n  from bisim_max_vars[OF bisim] length red1_simulates_red_aux[OF wf red bisim] fv notsynth\n  obtain ta' e2' xs' where sim: \"sim_move01 (compP1 P) t ta e1 E h xs ta' e2' h' xs'\"\n    and bisim': \"bisim [] e1' e2' xs'\" and XS': \"XS' \\<subseteq>\\<^sub>m empty\" by auto\n  from sim_move01_into_Red1[OF sim, of es1 exs2]\n  have \"?red (e2', xs') exs2\" unfolding ex2 by auto\n  moreover {\n    note bsl bisim' moreover\n    from fv red_fv_subset[OF wf_prog_wwf_prog[OF wf] red]\n    have \"fv e1' = {}\" by simp\n    moreover from red D have \"\\<D> e1' \\<lfloor>dom XS'\\<rfloor>\"\n      by(auto dest: red_preserves_defass[OF wf] split: split_if_asm)\n    with red_dom_lcl[OF red] `fv e1 = {}` have \"\\<D> e1' \\<lfloor>{}\\<rfloor>\"\n      by(auto elim!: D_mono' simp add: hyperset_defs)\n    moreover from sim have \"length xs = length xs'\" \"max_vars e2' \\<le> max_vars E\"\n      by(auto dest: sim_move01_preserves_len sim_move01_max_vars_decr)\n    with length have length': \"max_vars e2' \\<le> length xs'\" by(auto)\n    ultimately have \"bisim_list1 (e1', es1) ((e2', xs'), exs2)\" by(rule bisim_list1I) }\n  ultimately show ?thesis using ex2 by(simp split del: split_if)(rule exI conjI|assumption)+\nnext\n  case (red0Call a M vs U Ts T pns body D)\n  note [simp] = `ta = \\<epsilon>` `h' = h`\n    and es1' = `es1' = e1 # es1`\n    and e1' = `e1' = blocks (this # pns) (Class D # Ts) (Addr a # vs) body`\n    and call = `call e1 = \\<lfloor>(a, M, vs)\\<rfloor>`\n    and ha = `typeof_addr h a = \\<lfloor>U\\<rfloor>`\n    and sees = `P \\<turnstile> class_type_of U sees M: Ts\\<rightarrow>T = \\<lfloor>(pns, body)\\<rfloor> in D`\n    and len = `length vs = length pns` `length Ts = length pns`\n  from bisiml obtain E xs where ex2: \"ex2 = (E, xs)\"\n    and bisim: \"bisim [] e1 E xs\" and fv: \"fv e1 = {}\" \n    and length: \"max_vars E \\<le> length xs\" and bsl: \"bisim_list es1 exs2\"\n    and D: \"\\<D> e1 \\<lfloor>{}\\<rfloor>\" by(auto elim!: bisim_list1_elim)\n  \n  from bisim_call_Some_call1[OF bisim call, of \"compP1 P\" t h] length\n  obtain e' xs' where red: \"\\<tau>red1'r (compP1 P) t h (E, xs) (e', xs')\"\n    and \"call1 e' = \\<lfloor>(a, M, vs)\\<rfloor>\" \"bisim [] e1 e' xs'\" \n    and \"take 0 xs = take 0 xs'\" by auto\n    \n  let ?e1' = \"blocks (this # pns) (Class D # Ts) (Addr a # vs) body\"\n  let ?e2' = \"blocks1 0 (Class D#Ts) (compE1 (this # pns) body)\"\n  let ?xs2' = \"Addr a # vs @ replicate (max_vars (compE1 (this # pns) body)) undefined_value\"\n  let ?exs2' = \"(e', xs') # exs2\"\n\n  have \"\\<tau>Red1'r (compP1 P) t h ((E, xs), exs2) ((e', xs'), exs2)\"\n    using red by(rule \\<tau>red1r_into_\\<tau>Red1r)\n  moreover {\n    note `call1 e' = \\<lfloor>(a, M, vs)\\<rfloor>` \n    moreover note ha\n    moreover have \"compP1 P \\<turnstile> class_type_of U sees M:Ts \\<rightarrow> T = map_option (\\<lambda>(pns, body). compE1 (this # pns) body) \\<lfloor>(pns, body)\\<rfloor> in D\"\n      using sees unfolding compP1_def by(rule sees_method_compP)\n    hence sees': \"compP1 P \\<turnstile> class_type_of U sees M:Ts \\<rightarrow> T = \\<lfloor>compE1 (this # pns) body\\<rfloor> in D\" by simp\n    moreover from len have \"length vs = length Ts\" by simp\n    ultimately have \"False,compP1 P,t \\<turnstile>1 \\<langle>(e', xs')/exs2,h\\<rangle> -\\<epsilon>\\<rightarrow> \\<langle>(?e2', ?xs2')/?exs2', h\\<rangle>\" by(rule red1Call) \n    moreover have \"\\<tau>Move1 P h ((e', xs'), exs2)\" using `call1 e' = \\<lfloor>(a, M, vs)\\<rfloor>` ha sees\n      by(auto simp add: synthesized_call_def \\<tau>external'_def dest: sees_method_fun dest!: \\<tau>move1_not_call1[where P=P and h=h])\n    ultimately have \"\\<tau>Red1' (compP1 P) t h ((e', xs'), exs2) ((?e2', ?xs2'), ?exs2')\" by auto }\n  ultimately have \"\\<tau>Red1't (compP1 P) t h ((E, xs), exs2) ((?e2', ?xs2'), ?exs2')\" by(rule rtranclp_into_tranclp1)\n  moreover\n  { from red have \"length xs' = length xs\" by(rule \\<tau>red1r_preserves_len)\n    moreover from red have \"max_vars e' \\<le> max_vars E\" by(rule \\<tau>red1r_max_vars)\n    ultimately have \"max_vars e' \\<le> length xs'\" using length by simp }\n  with bsl `bisim [] e1 e' xs'` fv D have \"bisim_list (e1 # es1) ?exs2'\"\n    using `call e1 = \\<lfloor>(a, M, vs)\\<rfloor>` `call1 e' = \\<lfloor>(a, M, vs)\\<rfloor>` by(rule bisim_listCons)\n  hence \"bisim_list1 (e1', es1') ((?e2', ?xs2'), ?exs2')\"\n    unfolding e1' es1'\n  proof(rule bisim_list1I)\n    from wf_prog_wwf_prog[OF wf] sees\n    have \"wf_mdecl wwf_J_mdecl P D (M,Ts,T,\\<lfloor>(pns,body)\\<rfloor>)\" by(rule sees_wf_mdecl)\n    hence fv': \"fv body \\<subseteq> set pns \\<union> {this}\" by(auto simp add: wf_mdecl_def)\n    moreover from `P \\<turnstile> class_type_of U sees M: Ts\\<rightarrow>T = \\<lfloor>(pns, body)\\<rfloor> in D` have \"\\<not> contains_insync body\"\n      by(auto dest!: sees_wf_mdecl[OF wf] WT_expr_locks simp add: wf_mdecl_def contains_insync_conv)\n    ultimately have \"bisim ([this] @ pns) body (compE1 ([this] @ pns) body) ?xs2'\"\n      by -(rule compE1_bisim, auto)\n    with `length vs = length pns` `length Ts = length pns`\n    have \"bisim ([] @ [this]) (blocks pns Ts vs body) (blocks1 (Suc 0) Ts (compE1 (this # pns) body)) ?xs2'\"\n      by -(drule blocks_bisim,auto simp add: nth_append)\n    from bisimBlockSomeNone[OF this, of \"Addr a\" \"Class D\"]\n    show \"bisim [] ?e1' ?e2' ?xs2'\" by simp\n    from fv' len show \"fv ?e1' = {}\" by auto\n\n    from wf sees\n    have \"wf_mdecl wf_J_mdecl P D (M,Ts,T,\\<lfloor>(pns,body)\\<rfloor>)\" by(rule sees_wf_mdecl)\n    hence \"\\<D> body \\<lfloor>set pns \\<union> {this}\\<rfloor>\" by(auto simp add: wf_mdecl_def)\n    with `length vs = length pns` `length Ts = length pns`\n    have \"\\<D> (blocks pns Ts vs body) \\<lfloor>dom [this \\<mapsto> Addr a]\\<rfloor>\" by(auto)\n    thus \"\\<D> ?e1' \\<lfloor>{}\\<rfloor>\" by auto\n    \n    from len show \"max_vars ?e2' \\<le> length ?xs2'\" by(auto simp add: blocks1_max_vars)\n  qed\n  moreover have \"\\<tau>Move0 P h (e1, es1)\" using call ha sees\n    by(fastforce simp add: synthesized_call_def  \\<tau>external'_def dest: sees_method_fun \\<tau>move0_callD[where P=P and h=h])\n  ultimately show ?thesis using ex2 `call e1 = \\<lfloor>(a, M, vs)\\<rfloor>` \n    by(simp del: \\<tau>Move1.simps)(rule exI conjI|assumption)+\nnext\n  case (red0Return e)\n  note es1 = `es1 = e # es1'` and e1' = `e1' = inline_call e1 e`\n    and [simp] = `ta = \\<epsilon>` `h' = h`\n    and fin = `final e1`\n  from bisiml es1 obtain E' xs' E xs exs' aMvs where ex2: \"ex2 = (E', xs')\" and exs2: \"exs2 = (E, xs) # exs'\"\n    and bisim': \"bisim [] e1 E' xs'\"\n    and bisim: \"bisim [] e E xs\"\n    and fv: \"fv e = {}\"\n    and length: \"max_vars E \\<le> length xs\"\n    and bisiml: \"bisim_list es1' exs'\"\n    and D: \"\\<D> e \\<lfloor>{}\\<rfloor>\"\n    and call: \"call e = \\<lfloor>aMvs\\<rfloor>\"\n    and call1: \"call1 E = \\<lfloor>aMvs\\<rfloor>\"\n    by(fastforce elim: bisim_list1_elim)\n  let ?e2' = \"inline_call E' E\"\n\n  from `final e1` bisim' have \"final E'\" by(auto)\n  hence red': \"False,compP1 P,t \\<turnstile>1 \\<langle>ex2/exs2, h\\<rangle> -\\<epsilon>\\<rightarrow> \\<langle>(?e2', xs)/exs', h\\<rangle>\"\n    unfolding ex2 exs2 by(rule red1Return)\n  moreover have \"\\<tau>Move0 P h (e1, es1) = \\<tau>Move1 P h ((E', xs'), exs2)\"\n    using `final e1` `final E'` by auto\n  moreover {\n    note bisiml\n    moreover\n    from bisim' fin bisim\n    have \"bisim [] (inline_call e1 e) (inline_call E' E) xs\"\n      using call by(rule bisim_inline_call)(simp add: fv)\n    moreover from fv_inline_call[of e1 e] fv fin \n    have \"fv (inline_call e1 e) = {}\" by auto\n    moreover from fin have \"\\<D> (inline_call e1 e) \\<lfloor>{}\\<rfloor>\"\n      using call D by(rule defass_inline_call)\n    moreover have \"max_vars ?e2' \\<le> max_vars E + max_vars E'\" by(rule inline_call_max_vars1)\n    with `final E'` length have \"max_vars ?e2' \\<le> length xs\" by(auto elim!: final.cases)\n    ultimately have \"bisim_list1 (inline_call e1 e, es1') ((?e2', xs), exs')\"\n      by(rule bisim_list1I) }\n  ultimately show ?thesis using e1' `final e1` `final E'` ex2 \n    apply(simp del: \\<tau>Move0.simps \\<tau>Move1.simps)\n    apply(rule exI conjI impI|assumption)+\n     apply(rule tranclp.r_into_trancl, simp)\n    apply blast\n    done\nqed\n\nlemma sim_move10_into_red0:\n  assumes wwf: \"wwf_J_prog P\"\n  and sim: \"sim_move10 P t ta e2 e2' e h empty ta' e' h' x'\"\n  and fv: \"fv e = {}\"\n  shows \"if \\<tau>move1 P h e2\n         then (\\<tau>Red0t P t h (e, es) (e', es) \\<or> countInitBlock e2' < countInitBlock e2 \\<and> e' = e \\<and> x' = empty) \\<and> ta = \\<epsilon> \\<and> h = h'\n         else \\<exists>e'' ta'. \\<tau>Red0r P t h (e, es) (e'', es) \\<and>\n                        (call1 e2 = None \\<or> call e = None \\<or> e'' = e) \\<and>\n                        P,t \\<turnstile>0 \\<langle>e''/es,h\\<rangle> -ta'\\<rightarrow> \\<langle>e'/es,h'\\<rangle> \\<and>\n                        \\<not> \\<tau>Move0 P h (e'', es) \\<and> ta_bisim01 ta' (extTA2J1 (compP1 P) ta)\"\nproof(cases \"\\<tau>move1 P h e2\")\n  case True\n  with sim have \"\\<not> final e2\"\n    and red: \"\\<tau>red0t (extTA2J0 P) P t h (e, empty) (e', x') \\<or>\n              countInitBlock e2' < countInitBlock e2 \\<and> e' = e \\<and> x' = empty\"\n    and [simp]: \"h' = h\" \"ta = \\<epsilon>\" \"ta' = \\<epsilon>\" by(simp_all add: sim_move10_def)\n  from red have \"\\<tau>Red0t P t h (e, es) (e', es) \\<or>\n                 countInitBlock e2' < countInitBlock e2 \\<and> e' = e \\<and> x' = empty\"\n  proof\n    assume red: \"\\<tau>red0t (extTA2J0 P) P t h (e, empty) (e', x')\"\n    from \\<tau>red0t_fv_subset[OF wwf red] \\<tau>red0t_dom_lcl[OF wwf red] fv\n    have \"dom x' \\<subseteq> {}\" by(auto split: split_if_asm)\n    hence \"x' = empty\" by auto\n    with red have \"\\<tau>red0t (extTA2J0 P) P t h (e, empty) (e', empty)\" by simp\n    with wwf have \"\\<tau>Red0t P t h (e, es) (e', es)\"\n      using fv by(rule \\<tau>red0t_into_\\<tau>Red0t)\n    thus ?thesis ..\n  qed simp\n  with True show ?thesis by simp\nnext\n  case False\n  with sim obtain e'' xs'' where \"\\<not> final e2\"\n    and \\<tau>red: \"\\<tau>red0r (extTA2J0 P) P t h (e, empty) (e'', xs'')\"\n    and red: \"extTA2J0 P,P,t \\<turnstile> \\<langle>e'',(h, xs'')\\<rangle> -ta'\\<rightarrow> \\<langle>e',(h', x')\\<rangle>\"\n    and call: \"call1 e2 = None \\<or> call e = None \\<or> e'' = e\"\n    and \"\\<not> \\<tau>move0 P h e''\" \"ta_bisim01 ta' (extTA2J1 (compP1 P) ta)\" \"no_call P h e''\"\n    by(auto simp add: sim_move10_def split: split_if_asm)\n  from \\<tau>red0r_fv_subset[OF wwf \\<tau>red] \\<tau>red0r_dom_lcl[OF wwf \\<tau>red] fv\n  have \"dom xs'' \\<subseteq> {}\" by(auto)\n  hence \"xs'' = empty\" by(auto)\n  with \\<tau>red have \"\\<tau>red0r (extTA2J0 P) P t h (e, empty) (e'', empty)\" by simp\n  with wwf have \"\\<tau>Red0r P t h (e, es) (e'', es)\"\n    using fv by(rule \\<tau>red0r_into_\\<tau>Red0r)\n  moreover from red `xs'' = empty`\n  have \"extTA2J0 P,P,t \\<turnstile> \\<langle>e'',(h, empty)\\<rangle> -ta'\\<rightarrow> \\<langle>e',(h', x')\\<rangle>\" by simp\n  from red0Red[OF this] `no_call P h e''` \n  have \"P,t \\<turnstile>0 \\<langle>e''/es,h\\<rangle> -ta'\\<rightarrow> \\<langle>e'/es,h'\\<rangle>\" by(simp add: no_call_def)\n  moreover from `\\<not> \\<tau>move0 P h e''` red\n  have \"\\<not> \\<tau>Move0 P h (e'', es)\" by auto\n  ultimately show ?thesis using False `ta_bisim01 ta' (extTA2J1 (compP1 P) ta)` call\n    by(simp del: \\<tau>Move0.simps) blast\nqed\n\nlemma red0_simulates_Red1:\n  assumes wf: \"wf_J_prog P\"\n  and red: \"False,compP1 P,t \\<turnstile>1 \\<langle>ex2/exs2, h\\<rangle> -ta\\<rightarrow> \\<langle>ex2'/exs2', h'\\<rangle>\"\n  and bisiml: \"bisim_list1 (e, es) (ex2, exs2)\"\n  shows \"\\<exists>e' es'. bisim_list1 (e', es') (ex2', exs2') \\<and>\n                 (if \\<tau>Move1 P h (ex2, exs2)\n                  then (\\<tau>Red0t P t h (e, es) (e', es') \\<or> countInitBlock (fst ex2') < countInitBlock (fst ex2) \\<and> exs2' = exs2 \\<and> e' = e \\<and> es' = es) \\<and>\n                        ta = \\<epsilon> \\<and> h = h'\n                  else \\<exists>e'' es'' ta'. \\<tau>Red0r P t h (e, es) (e'', es'') \\<and>\n                                      (call1 (fst ex2) = None \\<or> call e = None \\<or> e'' = e \\<and> es'' = es) \\<and>\n                                      P,t \\<turnstile>0 \\<langle>e''/es'', h\\<rangle> -ta'\\<rightarrow> \\<langle>e'/es', h'\\<rangle> \\<and>\n                                      \\<not> \\<tau>Move0 P h (e'', es'') \\<and> ta_bisim01 ta' ta)\"\n  (is \"\\<exists>e' es' . _ \\<and> ?red e' es'\")\nusing red\nproof(cases)\n  case (red1Red E xs TA E' xs')\n  note red = `False,compP1 P,t \\<turnstile>1 \\<langle>E,(h, xs)\\<rangle> -TA\\<rightarrow> \\<langle>E',(h', xs')\\<rangle>`\n    and ex2 = `ex2 = (E, xs)`\n    and ex2' = `ex2' = (E', xs')`\n    and [simp] = `ta = extTA2J1 (compP1 P) TA` `exs2' = exs2`\n  from bisiml ex2 have bisim: \"bisim [] e E xs\" and fv: \"fv e = {}\"\n    and length: \"max_vars E \\<le> length xs\" and bsl: \"bisim_list es exs2\"\n    and D: \"\\<D> e \\<lfloor>{}\\<rfloor>\" by(auto elim: bisim_list1_elim)\n  from red_simulates_red1_aux[OF wf red, simplified, OF bisim, of empty] fv length D\n  obtain TA' e2' x' where red': \"sim_move10 P t TA E E' e h empty TA' e2' h' x'\"\n    and bisim'': \"bisim [] e2' E' xs'\" and lcl': \"x' \\<subseteq>\\<^sub>m empty\" by auto\n  from red have \"\\<not> final E\" by auto\n  with sim_move10_into_red0[OF wf_prog_wwf_prog[OF wf] red', of es] fv ex2 ex2'\n  have red'': \"?red e2' es\" by fastforce\n  moreover {\n    note bsl bisim''\n    moreover from red' fv have \"fv e2' = {}\"\n      by(fastforce simp add: sim_move10_def split: split_if_asm dest: \\<tau>red0r_fv_subset[OF wf_prog_wwf_prog[OF wf]] \\<tau>red0t_fv_subset[OF wf_prog_wwf_prog[OF wf]] red_fv_subset[OF wf_prog_wwf_prog[OF wf]])\n    moreover from red' have \"dom x' \\<subseteq> dom (empty) \\<union> fv e\"\n      unfolding sim_move10_def\n      apply(auto split: split_if_asm del: subsetI dest: \\<tau>red0r_dom_lcl[OF wf_prog_wwf_prog[OF wf]] \\<tau>red0t_dom_lcl[OF wf_prog_wwf_prog[OF wf]])\n      apply(frule_tac [1-2] \\<tau>red0r_fv_subset[OF wf_prog_wwf_prog[OF wf]])\n      apply(auto dest!: \\<tau>red0r_dom_lcl[OF wf_prog_wwf_prog[OF wf]] red_dom_lcl del: subsetI, blast+)\n      done\n    with fv have \"dom x' \\<subseteq> {}\" by(auto)\n    hence \"x' = empty\" by(auto)\n    with D red' have \"\\<D> e2' \\<lfloor>{}\\<rfloor>\"\n      by(auto dest!: sim_move10_preserves_defass[OF wf] split: split_if_asm)\n    moreover from red have \"length xs' = length xs\" by(auto dest: red1_preserves_len)\n    with red1_max_vars[OF red] length\n    have \"max_vars E' \\<le> length xs'\" by simp\n    ultimately have \"bisim_list1 (e2', es) ((E', xs'), exs2)\"\n      by(rule bisim_list1I) }\n  ultimately show ?thesis using ex2'\n    by(clarsimp split: split_if_asm)(rule exI conjI|assumption|simp)+\nnext\n  case (red1Call E a M vs U Ts T body D xs)\n  note [simp] = `ex2 = (E, xs)` `h' = h` `ta = \\<epsilon>`\n    and ex2' = `ex2' = (blocks1 0 (Class D#Ts) body, Addr a # vs @ replicate (max_vars body) undefined_value)`\n    and exs' = `exs2' = (E, xs) # exs2`\n    and call = `call1 E = \\<lfloor>(a, M, vs)\\<rfloor>` and ha = `typeof_addr h a = \\<lfloor>U\\<rfloor>`\n    and sees = `compP1 P \\<turnstile> class_type_of U sees M: Ts\\<rightarrow>T = \\<lfloor>body\\<rfloor> in D`\n    and len = `length vs = length Ts`\n  let ?e2' = \"blocks1 0 (Class D#Ts) body\"\n  let ?xs2' = \"Addr a # vs @ replicate (max_vars body) undefined_value\"\n  from bisiml have bisim: \"bisim [] e E xs\" and fv: \"fv e = {}\"\n    and length: \"max_vars E \\<le> length xs\" and bsl: \"bisim_list es exs2\"\n    and D: \"\\<D> e \\<lfloor>{}\\<rfloor>\" by(auto elim: bisim_list1_elim)\n\n  from bisim `call1 E = \\<lfloor>(a, M, vs)\\<rfloor>`\n  have \"call e = \\<lfloor>(a, M, vs)\\<rfloor>\" by(rule bisim_call1_Some_call)\n  moreover note ha\n  moreover from `compP1 P \\<turnstile> class_type_of U sees M: Ts\\<rightarrow>T = \\<lfloor>body\\<rfloor> in D`\n  obtain pns Jbody where sees': \"P \\<turnstile> class_type_of U sees M: Ts\\<rightarrow>T = \\<lfloor>(pns, Jbody)\\<rfloor> in D\"\n    and body: \"body = compE1 (this # pns) Jbody\"\n    by(auto dest: sees_method_compPD)\n  let ?e' = \"blocks (this # pns) (Class D # Ts) (Addr a # vs) Jbody\"\n  note sees' moreover from wf sees' have \"length Ts = length pns\"\n    by(auto dest!: sees_wf_mdecl simp add: wf_mdecl_def)\n  with len have \"length vs = length pns\" \"length Ts = length pns\" by simp_all\n  ultimately have red': \"P,t \\<turnstile>0 \\<langle>e/es, h\\<rangle> -\\<epsilon>\\<rightarrow> \\<langle>?e'/e#es, h\\<rangle>\" by(rule red0Call)\n  moreover from `call e = \\<lfloor>(a, M, vs)\\<rfloor>` ha sees'\n  have \"\\<tau>Move0 P h (e, es)\"\n    by(fastforce simp add: synthesized_call_def dest: \\<tau>move0_callD[where P=P and h=h] sees_method_fun)\n  ultimately have \"\\<tau>Red0t P t h (e, es) (?e', e#es)\" by auto\n  moreover\n  from bsl bisim fv D length `call e = \\<lfloor>(a, M, vs)\\<rfloor>` `call1 E = \\<lfloor>(a, M, vs)\\<rfloor>`\n  have \"bisim_list (e # es) ((E, xs) # exs2)\" by(rule bisim_list.intros)\n  hence \"bisim_list1 (?e', e # es) (ex2', (E, xs) # exs2)\" unfolding ex2'\n  proof(rule bisim_list1I)\n    from wf_prog_wwf_prog[OF wf] sees'\n    have \"wf_mdecl wwf_J_mdecl P D (M,Ts,T,\\<lfloor>(pns,Jbody)\\<rfloor>)\" by(rule sees_wf_mdecl)\n    hence \"fv Jbody \\<subseteq> set pns \\<union> {this}\" by(auto simp add: wf_mdecl_def)\n    moreover from sees' have \"\\<not> contains_insync Jbody\"\n      by(auto dest!: sees_wf_mdecl[OF wf] WT_expr_locks simp add: wf_mdecl_def contains_insync_conv)\n    ultimately have \"bisim ([] @ this # pns) Jbody (compE1 ([] @ this # pns) Jbody) ?xs2'\"\n      by -(rule compE1_bisim, auto)\n    with `length vs = length Ts` `length Ts = length pns` body\n    have \"bisim [] ?e' (blocks1 (length ([] :: vname list)) (Class D # Ts) body) ?xs2'\"\n      by -(rule blocks_bisim, auto simp add: nth_append nth_Cons')\n    thus \"bisim [] ?e' ?e2' ?xs2'\" by simp\n    from `length vs = length Ts` `length Ts = length pns` `fv Jbody \\<subseteq> set pns \\<union> {this}`\n    show \"fv ?e' = {}\" by auto\n    from wf sees'\n    have \"wf_mdecl wf_J_mdecl P D (M,Ts,T,\\<lfloor>(pns,Jbody)\\<rfloor>)\" by(rule sees_wf_mdecl)\n    hence \"\\<D> Jbody \\<lfloor>set pns \\<union> {this}\\<rfloor>\" by(auto simp add: wf_mdecl_def)\n    with `length vs = length Ts` `length Ts = length pns`\n    have \"\\<D> (blocks pns Ts vs Jbody) \\<lfloor>dom [this \\<mapsto> Addr a]\\<rfloor>\" by(auto)\n    thus \"\\<D> ?e' \\<lfloor>{}\\<rfloor>\" by simp\n    from len show \"max_vars ?e2' \\<le> length ?xs2'\" by(simp add: blocks1_max_vars)\n  qed\n  moreover have \"\\<tau>Move1 P h (ex2, exs2)\" using ha `call1 E = \\<lfloor>(a, M, vs)\\<rfloor>` sees'\n    by(auto simp add: synthesized_call_def \\<tau>external'_def dest!: \\<tau>move1_not_call1[where P=P and h=h] dest: sees_method_fun)\n  ultimately show ?thesis using exs'\n    by(simp del: \\<tau>Move1.simps \\<tau>Move0.simps)(rule exI conjI rtranclp.rtrancl_refl|assumption)+\nnext\n  case (red1Return E' x' E x)\n  note [simp] = `h' = h` `ta = \\<epsilon>`\n    and ex2 = `ex2 = (E', x')` and exs2 = `exs2 = (E, x) # exs2'`\n    and ex2' = `ex2' = (inline_call E' E, x)`\n    and fin = `final E'`\n  from bisiml ex2 exs2 obtain e' es' aMvs where es: \"es = e' # es'\"\n    and bsl: \"bisim_list es' exs2'\"\n    and bisim: \"bisim [] e E' x'\"\n    and bisim': \"bisim [] e' E x\"\n    and fv: \"fv e' = {}\"\n    and length: \"max_vars E \\<le> length x\"\n    and D: \"\\<D> e' \\<lfloor>{}\\<rfloor>\"\n    and call: \"call e' = \\<lfloor>aMvs\\<rfloor>\"\n    and call1: \"call1 E = \\<lfloor>aMvs\\<rfloor>\"\n    by(fastforce elim!: bisim_list1_elim)\n  \n  from `final E'` bisim have fin': \"final e\" by(auto)\n  hence \"P,t \\<turnstile>0 \\<langle>e/e' # es',h\\<rangle> -\\<epsilon>\\<rightarrow> \\<langle>inline_call e e'/es',h\\<rangle>\" by(rule red0Return)\n  moreover from bisim fin' bisim' call\n  have \"bisim [] (inline_call e e') (inline_call E' E) x\"\n    by(rule bisim_inline_call)(simp add: fv)\n  with bsl have \"bisim_list1 (inline_call e e', es') (ex2', exs2')\" unfolding ex2'\n  proof(rule bisim_list1I)\n    from fin' fv_inline_call[of e e'] fv show \"fv (inline_call e e') = {}\" by auto\n    from fin' show \"\\<D> (inline_call e e') \\<lfloor>{}\\<rfloor>\" using call D by(rule defass_inline_call)\n    \n    from call1_imp_call[OF call1]\n    have \"max_vars (inline_call E' E) \\<le> max_vars E + max_vars E'\"\n      by(rule inline_call_max_vars)\n    with fin length show \"max_vars (inline_call E' E) \\<le> length x\" by(auto elim!: final.cases)\n  qed\n  moreover have \"\\<tau>Move1 P h (ex2, exs2) = \\<tau>Move0 P h (e, es)\" using ex2 call1 call fin fin' by(auto)\n  ultimately show ?thesis using es\n    by(simp del: \\<tau>Move1.simps \\<tau>Move0.simps) blast\nqed\n\nend\n\nsublocale J0_J1_heap_base < red0_Red1'!: FWdelay_bisimulation_base\n  final_expr0\n  \"mred0 P\"\n  final_expr1\n  \"mred1' (compP1 P)\"\n  convert_RA\n  \"\\<lambda>t. bisim_red0_Red1\" \n  bisim_wait01\n  \"\\<tau>MOVE0 P\"\n  \"\\<tau>MOVE1 (compP1 P)\"\n  for P\n.\n\ncontext J0_J1_heap_base begin\n\nlemma delay_bisimulation_red0_Red1: \n  assumes wf: \"wf_J_prog P\"\n  shows \"delay_bisimulation_measure (mred0 P t) (mred1' (compP1 P) t) bisim_red0_Red1 (ta_bisim (\\<lambda>t. bisim_red0_Red1)) (\\<tau>MOVE0 P) (\\<tau>MOVE1 (compP1 P)) (\\<lambda>es es'. False) (\\<lambda>(((e', xs'), exs'), h') (((e, xs), exs), h). countInitBlock e'< countInitBlock e)\"\n  (is \"delay_bisimulation_measure _ _ _ _ _ _ ?\\<mu>1 ?\\<mu>2\")\nproof(unfold_locales)\n  fix s1 s2 s1'\n  assume \"bisim_red0_Red1 s1 s2\" \"red0_mthr.silent_move P t s1 s1'\"\n  moreover obtain ex1 exs1 h1 where s1: \"s1 = ((ex1, exs1), h1)\" by(cases s1, auto)\n  moreover obtain ex1' exs1' h1' where s1': \"s1' = ((ex1', exs1'), h1')\" by(cases s1', auto)\n  moreover obtain ex2 exs2 h2 where s2: \"s2 = ((ex2, exs2), h2)\" by(cases s2, auto)\n  ultimately have bisim: \"bisim_list1 (ex1, exs1) (ex2, exs2)\"\n    and heap: \"h1 = h2\"\n    and red: \"P,t \\<turnstile>0 \\<langle>ex1/exs1,h1\\<rangle> -\\<epsilon>\\<rightarrow> \\<langle>ex1'/exs1',h1'\\<rangle>\"\n    and \\<tau>: \"\\<tau>Move0 P h1 (ex1, exs1)\"\n    by(auto simp add: bisim_red0_Red1_def red0_mthr.silent_move_iff)\n  from Red1_simulates_red0[OF wf red bisim] \\<tau>\n  obtain ex2'' exs2'' where bisim': \"bisim_list1 (ex1', exs1') (ex2'', exs2'')\" \n    and red': \"\\<tau>Red1't (compP1 P) t h1 (ex2, exs2) (ex2'', exs2'')\"\n    and [simp]: \"h1' = h1\" by auto\n  from \\<tau>Red1't_into_Red1'_\\<tau>mthr_silent_movet[OF red'] bisim' heap\n  have \"\\<exists>s2'. Red1_mthr.silent_movet False (compP1 P) t s2 s2' \\<and> bisim_red0_Red1 s1' s2'\"\n    unfolding s2 s1' by(auto simp add: bisim_red0_Red1_def)\n  thus \"bisim_red0_Red1 s1' s2 \\<and> ?\\<mu>1^++ s1' s1 \\<or> (\\<exists>s2'. Red1_mthr.silent_movet False (compP1 P) t s2 s2' \\<and> bisim_red0_Red1 s1' s2')\" ..\nnext\n  fix s1 s2 s2'\n  assume \"bisim_red0_Red1 s1 s2\" \"Red1_mthr.silent_move False (compP1 P) t s2 s2'\"\n  moreover obtain ex1 exs1 h1 where s1: \"s1 = ((ex1, exs1), h1)\" by(cases s1, auto)\n  moreover obtain ex2 exs2 h2 where s2: \"s2 = ((ex2, exs2), h2)\" by(cases s2, auto)\n  moreover obtain ex2' exs2' h2' where s2': \"s2' = ((ex2', exs2'), h2')\" by(cases s2', auto)\n  ultimately have bisim: \"bisim_list1 (ex1, exs1) (ex2, exs2)\"\n    and heap: \"h1 = h2\"\n    and red: \"False,compP1 P,t \\<turnstile>1 \\<langle>ex2/exs2,h2\\<rangle> -\\<epsilon>\\<rightarrow> \\<langle>ex2'/exs2',h2'\\<rangle>\"\n    and \\<tau>: \"\\<tau>Move1 P h2 (ex2, exs2)\"\n    by(fastforce simp add: bisim_red0_Red1_def Red1_mthr.silent_move_iff)+\n  from red0_simulates_Red1[OF wf red bisim] \\<tau>\n  obtain e' es' where bisim': \"bisim_list1 (e', es') (ex2', exs2')\"\n    and red': \"\\<tau>Red0t P t h2 (ex1, exs1) (e', es') \\<or> \n               countInitBlock (fst ex2') < countInitBlock (fst ex2) \\<and> exs2' = exs2 \\<and> e' = ex1 \\<and> es' = exs1\"\n    and [simp]: \"h2' = h2\" by auto\n  from red'\n  show \"bisim_red0_Red1 s1 s2' \\<and> ?\\<mu>2^++ s2' s2 \\<or> (\\<exists>s1'. red0_mthr.silent_movet P t s1 s1' \\<and> bisim_red0_Red1 s1' s2')\"\n    (is \"?refl \\<or> ?step\")\n  proof\n    assume \"\\<tau>Red0t P t h2 (ex1, exs1) (e', es')\"\n    from \\<tau>Red0t_into_red0_\\<tau>mthr_silent_movet[OF this] bisim' heap\n    have ?step unfolding s1 s2' by(auto simp add: bisim_red0_Red1_def)\n    thus ?thesis ..\n  next\n    assume \"countInitBlock (fst ex2') < countInitBlock (fst ex2) \\<and> exs2' = exs2 \\<and> e' = ex1 \\<and> es' = exs1\"\n    hence ?refl using bisim' heap unfolding s1 s2' s2\n      by (auto simp add: bisim_red0_Red1_def split_beta)\n    thus ?thesis ..\n  qed\nnext\n  fix s1 s2 ta1 s1'\n  assume \"bisim_red0_Red1 s1 s2\"  and \"mred0 P t s1 ta1 s1'\" and \\<tau>: \"\\<not> \\<tau>MOVE0 P s1 ta1 s1'\"\n  moreover obtain ex1 exs1 h1 where s1: \"s1 = ((ex1, exs1), h1)\" by(cases s1, auto)\n  moreover obtain ex1' exs1' h1' where s1': \"s1' = ((ex1', exs1'), h1')\" by(cases s1', auto)\n  moreover obtain ex2 exs2 h2 where s2: \"s2 = ((ex2, exs2), h2)\" by(cases s2, auto)\n  ultimately have heap: \"h2 = h1\"\n    and bisim: \"bisim_list1 (ex1, exs1) (ex2, exs2)\"\n    and red: \"P,t \\<turnstile>0 \\<langle>ex1/exs1,h1\\<rangle> -ta1\\<rightarrow> \\<langle>ex1'/exs1',h1'\\<rangle>\"\n    by(auto simp add: bisim_red0_Red1_def)\n  from \\<tau> have \"\\<not> \\<tau>Move0 P h1 (ex1, exs1)\" unfolding s1\n    using red by(auto elim!: red0.cases dest: red_\\<tau>_taD[where extTA=\"extTA2J0 P\", OF extTA2J0_\\<epsilon>])\n  with Red1_simulates_red0[OF wf red bisim]\n  obtain ex2'' exs2'' ex2' exs2' ta'\n    where bisim': \"bisim_list1 (ex1', exs1') (ex2'', exs2'')\"\n    and red': \"\\<tau>Red1'r (compP1 P) t h1 (ex2, exs2) (ex2', exs2')\"\n    and red'': \"False,compP1 P,t \\<turnstile>1 \\<langle>ex2'/exs2',h1\\<rangle> -ta'\\<rightarrow> \\<langle>ex2''/exs2'',h1'\\<rangle>\"\n    and \\<tau>': \"\\<not> \\<tau>Move1 P h1 (ex2', exs2')\"\n    and ta: \"ta_bisim01 ta1 ta'\" by fastforce\n  from red'' have \"mred1' (compP1 P) t ((ex2', exs2'), h1) ta' ((ex2'', exs2''), h1')\" by auto\n  moreover from \\<tau>' have \"\\<not> \\<tau>MOVE1 (compP1 P) ((ex2', exs2'), h1) ta' ((ex2'', exs2''), h1')\" by simp\n  moreover from red' have \"Red1_mthr.silent_moves False (compP1 P) t s2 ((ex2', exs2'), h1)\"\n    unfolding s2 heap by(rule \\<tau>Red1'r_into_Red1'_\\<tau>mthr_silent_moves)\n  moreover from bisim' have \"bisim_red0_Red1 ((ex1', exs1'), h1') ((ex2'', exs2''), h1')\"\n    by(auto simp add: bisim_red0_Red1_def)\n  ultimately\n  show \"\\<exists>s2' s2'' ta2. Red1_mthr.silent_moves False (compP1 P) t s2 s2' \\<and> mred1' (compP1 P) t s2' ta2 s2'' \\<and>\n             \\<not> \\<tau>MOVE1 (compP1 P) s2' ta2 s2'' \\<and> bisim_red0_Red1 s1' s2'' \\<and> ta_bisim01 ta1 ta2\"\n    using ta unfolding s1' by blast\nnext\n  fix s1 s2 ta2 s2'\n  assume \"bisim_red0_Red1 s1 s2\"  and \"mred1' (compP1 P) t s2 ta2 s2'\" and \\<tau>: \"\\<not> \\<tau>MOVE1 (compP1 P) s2 ta2 s2'\"\n  moreover obtain ex1 exs1 h1 where s1: \"s1 = ((ex1, exs1), h1)\" by(cases s1, auto)\n  moreover obtain ex2 exs2 h2 where s2: \"s2 = ((ex2, exs2), h2)\" by(cases s2, auto)\n  moreover obtain ex2' exs2' h2' where s2': \"s2' = ((ex2', exs2'), h2')\" by(cases s2', auto)\n  ultimately have heap: \"h2 = h1\"\n    and bisim: \"bisim_list1 (ex1, exs1) (ex2, exs2)\"\n    and red: \"False,compP1 P,t \\<turnstile>1 \\<langle>ex2/exs2,h1\\<rangle> -ta2\\<rightarrow> \\<langle>ex2'/exs2',h2'\\<rangle>\"\n    by(auto simp add: bisim_red0_Red1_def)\n  from \\<tau> heap have \"\\<not> \\<tau>Move1 P h2 (ex2, exs2)\" unfolding s2\n    using red by(fastforce elim!: Red1.cases dest: red1_\\<tau>_taD)\n  with red0_simulates_Red1[OF wf red bisim]\n  obtain e' es' e'' es'' ta'\n    where bisim': \"bisim_list1 (e', es') (ex2', exs2')\"\n    and red': \"\\<tau>Red0r P t h1 (ex1, exs1) (e'', es'')\"\n    and red'': \"P,t \\<turnstile>0 \\<langle>e''/es'',h1\\<rangle> -ta'\\<rightarrow> \\<langle>e'/es',h2'\\<rangle>\"\n    and \\<tau>': \"\\<not> \\<tau>Move0 P h1 (e'', es'')\"\n    and ta: \"ta_bisim01 ta' ta2\" using heap by fastforce\n  from red'' have \"mred0 P t ((e'', es''), h1) ta' ((e', es'), h2')\" by auto\n  moreover from red' have \"red0_mthr.silent_moves P t ((ex1, exs1), h1) ((e'', es''), h1)\"\n    by(rule \\<tau>Red0r_into_red0_\\<tau>mthr_silent_moves)\n  moreover from \\<tau>' have \"\\<not> \\<tau>MOVE0 P ((e'', es''), h1) ta' ((e', es'), h2')\" by simp\n  moreover from bisim' have \"bisim_red0_Red1 ((e', es'), h2') ((ex2', exs2'), h2')\"\n    by(auto simp add: bisim_red0_Red1_def)\n  ultimately\n  show \"\\<exists>s1' s1'' ta1. red0_mthr.silent_moves P t s1 s1' \\<and>\n             mred0 P t s1' ta1 s1'' \\<and> \\<not> \\<tau>MOVE0 P s1' ta1 s1'' \\<and>\n             bisim_red0_Red1 s1'' s2' \\<and> ta_bisim01 ta1 ta2\"\n    using ta unfolding s1 s2' by blast\nnext\n  show \"wfP ?\\<mu>1\" by auto\nnext\n  have \"wf (measure countInitBlock)\" ..\n  hence \"wf (inv_image (measure countInitBlock) (\\<lambda>(((e', xs'), exs'), h'). e'))\" ..\n  also have \"inv_image (measure countInitBlock) (\\<lambda>(((e', xs'), exs'), h'). e') = {(s2', s2). ?\\<mu>2 s2' s2}\"\n    by(simp add: inv_image_def split_beta)\n  finally show \"wfP ?\\<mu>2\" by(simp add: wfP_def)\nqed\n\nlemma delay_bisimulation_diverge_red0_Red1: \n  assumes \"wf_J_prog P\"\n  shows \"delay_bisimulation_diverge (mred0 P t) (mred1' (compP1 P) t) bisim_red0_Red1 (ta_bisim (\\<lambda>t. bisim_red0_Red1)) (\\<tau>MOVE0 P) (\\<tau>MOVE1 (compP1 P))\"\nproof -\n  interpret delay_bisimulation_measure\n    \"mred0 P t\" \"mred1' (compP1 P) t\" \"bisim_red0_Red1\" \"ta_bisim (\\<lambda>t. bisim_red0_Red1)\" \"\\<tau>MOVE0 P\" \"\\<tau>MOVE1 (compP1 P)\"\n    \"\\<lambda>es es'. False\" \"\\<lambda>(((e', xs'), exs'), h') (((e, xs), exs), h). countInitBlock e'< countInitBlock e\"\n    using assms by(rule delay_bisimulation_red0_Red1)\n  show ?thesis by unfold_locales\nqed\n\nlemma red0_Red1'_FWweak_bisim:\n  assumes wf: \"wf_J_prog P\"\n  shows \"FWdelay_bisimulation_diverge final_expr0 (mred0 P) final_expr1 (mred1' (compP1 P))\n           (\\<lambda>t. bisim_red0_Red1) bisim_wait01 (\\<tau>MOVE0 P) (\\<tau>MOVE1 (compP1 P))\"\nproof -\n  interpret delay_bisimulation_diverge\n    \"mred0 P t\"\n    \"mred1' (compP1 P) t\" \n    bisim_red0_Red1 \n    \"ta_bisim (\\<lambda>t. bisim_red0_Red1)\" \"\\<tau>MOVE0 P\" \"\\<tau>MOVE1 (compP1 P)\"\n    for t\n    using wf by(rule delay_bisimulation_diverge_red0_Red1)\n  show ?thesis\n  proof\n    fix t and s1 and s2 :: \"(('addr expr1 \\<times> 'addr locals1) \\<times> ('addr expr1 \\<times> 'addr locals1) list) \\<times> 'heap\"\n    assume \"bisim_red0_Red1 s1 s2\" \"(\\<lambda>(x1, m). final_expr0 x1) s1\"\n    moreover hence \"(\\<lambda>(x2, m). final_expr1 x2) s2\"\n      by(cases s1)(cases s2,auto simp add: bisim_red0_Red1_def final_iff elim!: bisim_list1_elim elim: bisim_list.cases)\n    ultimately show \"\\<exists>s2'. Red1_mthr.silent_moves False (compP1 P) t s2 s2' \\<and> bisim_red0_Red1 s1 s2' \\<and> (\\<lambda>(x2, m). final_expr1 x2) s2'\"\n      by blast\n  next\n    fix t s1 and s2 :: \"(('addr expr1 \\<times> 'addr locals1) \\<times> ('addr expr1 \\<times> 'addr locals1) list) \\<times> 'heap\"\n    assume \"bisim_red0_Red1 s1 s2\" \"(\\<lambda>(x2, m). final_expr1 x2) s2\"\n    moreover hence \"(\\<lambda>(x1, m). final_expr0 x1) s1\"\n      by(cases s1)(cases s2,auto simp add: bisim_red0_Red1_def final_iff elim!: bisim_list1_elim elim: bisim_list.cases)\n    ultimately show \"\\<exists>s1'. red0_mthr.silent_moves P t s1 s1' \\<and> bisim_red0_Red1 s1' s2 \\<and> (\\<lambda>(x1, m). final_expr0 x1) s1'\"\n      by blast\n  next\n    fix t' x m1 x' m2 t x1 x2 x1' ta1 x1'' m1' x2' ta2 x2'' m2'\n    assume b: \"bisim_red0_Red1 (x, m1) (x', m2)\"\n      and bo: \"bisim_red0_Red1 (x1, m1) (x2, m2)\"\n      and \\<tau>red1: \"red0_mthr.silent_moves P t (x1, m1) (x1', m1)\"\n      and red1: \"mred0 P t (x1', m1) ta1 (x1'', m1')\"\n      and \\<tau>1: \"\\<not> \\<tau>MOVE0 P (x1', m1) ta1 (x1'', m1')\"\n      and \\<tau>red2: \"Red1_mthr.silent_moves False (compP1 P) t (x2, m2) (x2', m2)\"\n      and red2: \"mred1' (compP1 P) t (x2', m2) ta2 (x2'', m2')\"\n      and bo': \"bisim_red0_Red1 (x1'', m1') (x2'', m2')\"\n      and tb: \"ta_bisim (\\<lambda>t. bisim_red0_Red1) ta1 ta2\"\n    from b have \"m1 = m2\" by(auto simp add: bisim_red0_Red1_def split_beta)\n    moreover from bo' have \"m1' = m2'\" by(auto simp add: bisim_red0_Red1_def split_beta)\n    ultimately show \"bisim_red0_Red1 (x, m1') (x', m2')\" using b\n      by(auto simp add: bisim_red0_Red1_def split_beta)\n  next\n    fix t x1 m1 x2 m2 x1' ta1 x1'' m1' x2' ta2 x2'' m2' w\n    assume \"bisim_red0_Red1 (x1, m1) (x2, m2)\"\n      and \"red0_mthr.silent_moves P t (x1, m1) (x1', m1)\"\n      and red0: \"mred0 P t (x1', m1) ta1 (x1'', m1')\"\n      and \"\\<not> \\<tau>MOVE0 P (x1', m1) ta1 (x1'', m1')\"\n      and \"Red1_mthr.silent_moves False (compP1 P) t (x2, m2) (x2', m2)\"\n      and red1: \"mred1' (compP1 P) t (x2', m2) ta2 (x2'', m2')\"\n      and \"\\<not> \\<tau>MOVE1 (compP1 P) (x2', m2) ta2 (x2'', m2')\"\n      and \"bisim_red0_Red1 (x1'', m1') (x2'', m2')\"\n      and \"ta_bisim01 ta1 ta2\"\n      and Suspend: \"Suspend w \\<in> set \\<lbrace>ta1\\<rbrace>\\<^bsub>w\\<^esub>\" \"Suspend w \\<in> set \\<lbrace>ta2\\<rbrace>\\<^bsub>w\\<^esub>\"\n    from red0 red1 Suspend show \"bisim_wait01 x1'' x2''\"\n      by(cases x2')(cases x2'', auto dest: Red_Suspend_is_call Red1_Suspend_is_call simp add: split_beta bisim_wait01_def is_call_def)\n  next\n    fix t x1 m1 x2 m2 ta1 x1' m1'\n    assume \"bisim_red0_Red1 (x1, m1) (x2, m2)\"\n      and \"bisim_wait01 x1 x2\"\n      and \"mred0 P t (x1, m1) ta1 (x1', m1')\"\n      and wakeup: \"Notified \\<in> set \\<lbrace>ta1\\<rbrace>\\<^bsub>w\\<^esub> \\<or> WokenUp \\<in> set \\<lbrace>ta1\\<rbrace>\\<^bsub>w\\<^esub>\"\n    moreover obtain e0 es0 where [simp]: \"x1 = (e0, es0)\" by(cases x1)\n    moreover obtain e0' es0' where [simp]: \"x1' = (e0', es0')\" by(cases x1')\n    moreover obtain e1 xs1 exs1 where [simp]: \"x2 = ((e1, xs1), exs1)\" by(cases x2) auto\n    ultimately have bisim: \"bisim_list1 (e0, es0) ((e1, xs1), exs1)\"\n      and m1: \"m2 = m1\"\n      and call: \"call e0 \\<noteq> None\" \"call1 e1 \\<noteq> None\"\n      and red: \"P,t \\<turnstile>0 \\<langle>e0/es0, m1\\<rangle> -ta1\\<rightarrow> \\<langle>e0'/es0', m1'\\<rangle>\"\n      by(auto simp add: bisim_wait01_def bisim_red0_Red1_def)\n    from red wakeup have \"\\<not> \\<tau>Move0 P m1 (e0, es0)\"\n      by(auto elim!: red0.cases dest: red_\\<tau>_taD[where extTA=\"extTA2J0 P\", simplified])\n    with Red1_simulates_red0[OF wf red bisim] call m1\n    show \"\\<exists>ta2 x2' m2'. mred1' (compP1 P) t (x2, m2) ta2 (x2', m2') \\<and> bisim_red0_Red1 (x1', m1') (x2', m2') \\<and> ta_bisim01 ta1 ta2\"\n      by(auto simp add: bisim_red0_Red1_def)\n  next\n    fix t x1 m1 x2 m2 ta2 x2' m2'\n    assume \"bisim_red0_Red1 (x1, m1) (x2, m2)\"\n      and \"bisim_wait01 x1 x2\" \n      and \"mred1' (compP1 P) t (x2, m2) ta2 (x2', m2')\"\n      and wakeup: \"Notified \\<in> set \\<lbrace>ta2\\<rbrace>\\<^bsub>w\\<^esub> \\<or> WokenUp \\<in> set \\<lbrace>ta2\\<rbrace>\\<^bsub>w\\<^esub>\"\n    moreover obtain e0 es0 where [simp]: \"x1 = (e0, es0)\" by(cases x1)\n    moreover obtain e1 xs1 exs1 where [simp]: \"x2 = ((e1, xs1), exs1)\" by(cases x2) auto\n    moreover obtain e1' xs1' exs1' where [simp]: \"x2' = ((e1', xs1'), exs1')\" by(cases x2') auto\n    ultimately have bisim: \"bisim_list1 (e0, es0) ((e1, xs1), exs1)\"\n      and m1: \"m2 = m1\"\n      and call: \"call e0 \\<noteq> None\" \"call1 e1 \\<noteq> None\"\n      and red: \"False,compP1 P,t \\<turnstile>1 \\<langle>(e1, xs1)/exs1, m1\\<rangle> -ta2\\<rightarrow> \\<langle>(e1', xs1')/exs1', m2'\\<rangle>\"\n      by(auto simp add: bisim_wait01_def bisim_red0_Red1_def)\n    from red wakeup have \"\\<not> \\<tau>Move1 P m1 ((e1, xs1), exs1)\"\n      by(auto elim!: Red1.cases dest: red1_\\<tau>_taD)\n    with red0_simulates_Red1[OF wf red bisim] m1 call\n    show \"\\<exists>ta1 x1' m1'. mred0 P t (x1, m1) ta1 (x1', m1') \\<and> bisim_red0_Red1 (x1', m1') (x2', m2') \\<and> ta_bisim01 ta1 ta2\"\n      by(auto simp add: bisim_red0_Red1_def)\n  next\n    show \"(\\<exists>x. final_expr0 x) \\<longleftrightarrow> (\\<exists>x. final_expr1 x)\"\n      by(auto simp add: split_paired_Ex final_iff)\n  qed\nqed\n\nlemma bisim_J0_J1_start:\n  assumes wf: \"wf_J_prog P\"\n  and start: \"wf_start_state P C M vs\"\n  shows \"red0_Red1'.mbisim (J0_start_state P C M vs) (J1_start_state (compP1 P) C M vs)\"\nproof -\n  from start obtain Ts T pns body D\n    where sees: \"P \\<turnstile> C sees M:Ts\\<rightarrow>T=\\<lfloor>(pns,body)\\<rfloor> in D\"\n    and conf: \"P,start_heap \\<turnstile> vs [:\\<le>] Ts\"\n    by cases auto\n  from conf have vs: \"length vs = length Ts\" by(rule list_all2_lengthD)\n  from sees_wf_mdecl[OF wf_prog_wwf_prog[OF wf] sees]\n  have fvbody: \"fv body \\<subseteq> {this} \\<union> set pns\" and len: \"length pns = length Ts\"\n    by(auto simp add: wf_mdecl_def)\n  with vs have fv: \"fv (blocks pns Ts vs body) \\<subseteq> {this}\" by auto\n  have wfCM: \"wf_J_mdecl P D (M, Ts, T, pns, body)\"\n    using sees_wf_mdecl[OF wf sees] by(auto simp add: wf_mdecl_def)\n  then obtain T' where wtbody: \"P,[this # pns [\\<mapsto>] Class D # Ts] \\<turnstile> body :: T'\" by auto\n  hence elbody: \"expr_locks body = (\\<lambda>l. 0)\" by(rule WT_expr_locks)\n  hence cisbody: \"\\<not> contains_insync body\" by(auto simp add: contains_insync_conv)\n  from wfCM len vs have dabody: \"\\<D> (blocks pns Ts vs body) \\<lfloor>{this}\\<rfloor>\" by auto\n  from sees have sees1: \"compP1 P \\<turnstile> C sees M:Ts\\<rightarrow>T = \\<lfloor>compE1 (this # pns) body\\<rfloor> in D\"\n    by(auto dest: sees_method_compP[where f=\"(\\<lambda>C M Ts T (pns, body). compE1 (this # pns) body)\"])\n\n  let ?e = \"blocks1 0 (Class C#Ts) (compE1 (this # pns) body)\"\n  let ?xs = \"Null # vs @ replicate (max_vars body) undefined_value\"\n  from fvbody cisbody len vs\n  have \"bisim [] (blocks (this # pns) (Class D # Ts) (Null # vs) body) (blocks1 (length ([] :: vname list)) (Class D # Ts) (compE1 (this # pns) body)) ?xs\"\n    by-(rule blocks_bisim,(fastforce simp add: nth_Cons' nth_append)+)\n  with fv dabody len vs elbody sees sees1\n  show ?thesis unfolding start_state_def\n    by(auto intro!: red0_Red1'.mbisimI split: split_if_asm)(auto simp add: bisim_red0_Red1_def blocks1_max_vars intro!: bisim_list.intros bisim_list1I wset_thread_okI)\nqed\n\nend\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/JinjaThreads/Compiler/Correctness1.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5621764862150636, "lm_q2_score": 0.4455295350395727, "lm_q1q2_score": 0.250466228513578}}
{"text": "(*  Title:      Jinja/J/WellForm.thy\n\n    Author:     Tobias Nipkow\n    Copyright   2003 Technische Universitaet Muenchen\n*)\n\nheader {* \\isaheader{Generic Well-formedness of programs} *}\n\ntheory WellForm imports TypeRel SystemClasses begin\n\ntext {*\\noindent This theory defines global well-formedness conditions\nfor programs but does not look inside method bodies.  Hence it works\nfor both Jinja and JVM programs. Well-typing of expressions is defined\nelsewhere (in theory @{text WellType}).\n\nBecause Jinja does not have method overloading, its policy for method\noverriding is the classical one: \\emph{covariant in the result type\nbut contravariant in the argument types.} This means the result type\nof the overriding method becomes more specific, the argument types\nbecome more general.\n*}\n\ntype_synonym 'm wf_mdecl_test = \"'m prog \\<Rightarrow> cname \\<Rightarrow> 'm mdecl \\<Rightarrow> bool\"\n\ndefinition wf_fdecl :: \"'m prog \\<Rightarrow> fdecl \\<Rightarrow> bool\"\nwhere\n  \"wf_fdecl P \\<equiv> \\<lambda>(F,T). is_type P T\"\n\ndefinition wf_mdecl :: \"'m wf_mdecl_test \\<Rightarrow> 'm wf_mdecl_test\"\nwhere\n  \"wf_mdecl wf_md P C \\<equiv> \\<lambda>(M,Ts,T,mb).\n  (\\<forall>T\\<in>set Ts. is_type P T) \\<and> is_type P T \\<and> wf_md P C (M,Ts,T,mb)\"\n\ndefinition wf_cdecl :: \"'m wf_mdecl_test \\<Rightarrow> 'm prog \\<Rightarrow> 'm cdecl \\<Rightarrow> bool\"\nwhere\n  \"wf_cdecl wf_md P  \\<equiv>  \\<lambda>(C,(D,fs,ms)).\n  (\\<forall>f\\<in>set fs. wf_fdecl P f) \\<and>  distinct_fst fs \\<and>\n  (\\<forall>m\\<in>set ms. wf_mdecl wf_md P C m) \\<and>  distinct_fst ms \\<and>\n  (C \\<noteq> Object \\<longrightarrow>\n   is_class P D \\<and> \\<not> P \\<turnstile> D \\<preceq>\\<^sup>* C \\<and>\n   (\\<forall>(M,Ts,T,m)\\<in>set ms.\n      \\<forall>D' Ts' T' m'. P \\<turnstile> D sees M:Ts' \\<rightarrow> T' = m' in D' \\<longrightarrow>\n                       P \\<turnstile> Ts' [\\<le>] Ts \\<and> P \\<turnstile> T \\<le> T'))\"\n\ndefinition wf_syscls :: \"'m prog \\<Rightarrow> bool\"\nwhere\n  \"wf_syscls P  \\<equiv>  {Object} \\<union> sys_xcpts \\<subseteq> set(map fst P)\"\n\ndefinition wf_prog :: \"'m wf_mdecl_test \\<Rightarrow> 'm prog \\<Rightarrow> bool\"\nwhere\n  \"wf_prog wf_md P  \\<equiv>  wf_syscls P \\<and> (\\<forall>c \\<in> set P. wf_cdecl wf_md P c) \\<and> distinct_fst P\"\n\n\nsubsection{* Well-formedness lemmas *}\n\nlemma class_wf: \n  \"\\<lbrakk>class P C = Some c; wf_prog wf_md P\\<rbrakk> \\<Longrightarrow> wf_cdecl wf_md P (C,c)\"\n(*<*)\napply (unfold wf_prog_def class_def)\napply (fast dest: map_of_SomeD)\ndone\n(*>*)\n\n\nlemma class_Object [simp]: \n  \"wf_prog wf_md P \\<Longrightarrow> \\<exists>C fs ms. class P Object = Some (C,fs,ms)\"\n(*<*)\napply (unfold wf_prog_def wf_syscls_def class_def)\napply (auto simp: map_of_SomeI)\ndone\n(*>*)\n\n\nlemma is_class_Object [simp]:\n  \"wf_prog wf_md P \\<Longrightarrow> is_class P Object\"\n(*<*)by (simp add: is_class_def)(*>*)\n(* Unused\nlemma is_class_supclass:\nassumes wf: \"wf_prog wf_md P\" and sub: \"P \\<turnstile> C \\<preceq>\\<^sup>* D\"\nshows \"is_class P C \\<Longrightarrow> is_class P D\"\nusing sub apply(induct)\n apply assumption\napply(fastforce simp:wf_cdecl_def subcls1_def is_class_def\n               dest:class_wf[OF _ wf])\ndone\n\nThis is NOT true because P \\<turnstile> NT \\<le> Class C for any Class C\nlemma is_type_suptype: \"\\<lbrakk> wf_prog p P; is_type P T; P \\<turnstile> T \\<le> T' \\<rbrakk>\n \\<Longrightarrow> is_type P T'\"\n*)\n\nlemma is_class_xcpt:\n  \"\\<lbrakk> C \\<in> sys_xcpts; wf_prog wf_md P \\<rbrakk> \\<Longrightarrow> is_class P C\"\n(*<*)\n  apply (simp add: wf_prog_def wf_syscls_def is_class_def class_def)\n  apply (fastforce intro!: map_of_SomeI)\n  done\n(*>*)\n\n\nlemma subcls1_wfD:\n  \"\\<lbrakk> P \\<turnstile> C \\<prec>\\<^sup>1 D; wf_prog wf_md P \\<rbrakk> \\<Longrightarrow> D \\<noteq> C \\<and> (D,C) \\<notin> (subcls1 P)\\<^sup>+\"\n(*<*)\napply( frule r_into_trancl)\napply( drule subcls1D)\napply(clarify)\napply( drule (1) class_wf)\napply( unfold wf_cdecl_def)\napply(force simp add: reflcl_trancl [THEN sym] simp del: reflcl_trancl)\ndone\n(*>*)\n\n\nlemma wf_cdecl_supD: \n  \"\\<lbrakk>wf_cdecl wf_md P (C,D,r); C \\<noteq> Object\\<rbrakk> \\<Longrightarrow> is_class P D\"\n(*<*)by (auto simp: wf_cdecl_def)(*>*)\n\n\nlemma subcls_asym:\n  \"\\<lbrakk> wf_prog wf_md P; (C,D) \\<in> (subcls1 P)\\<^sup>+ \\<rbrakk> \\<Longrightarrow> (D,C) \\<notin> (subcls1 P)\\<^sup>+\"\n(*<*)\napply(erule tranclE)\napply(fast dest!: subcls1_wfD )\napply(fast dest!: subcls1_wfD intro: trancl_trans)\ndone\n(*>*)\n\n\nlemma subcls_irrefl:\n  \"\\<lbrakk> wf_prog wf_md P; (C,D) \\<in> (subcls1 P)\\<^sup>+ \\<rbrakk> \\<Longrightarrow> C \\<noteq> D\"\n(*<*)\napply (erule trancl_trans_induct)\napply  (auto dest: subcls1_wfD subcls_asym)\ndone\n(*>*)\n\n\nlemma acyclic_subcls1:\n  \"wf_prog wf_md P \\<Longrightarrow> acyclic (subcls1 P)\"\n(*<*)\napply (unfold acyclic_def)\napply (fast dest: subcls_irrefl)\ndone\n(*>*)\n\n\nlemma wf_subcls1:\n  \"wf_prog wf_md P \\<Longrightarrow> wf ((subcls1 P)\\<inverse>)\"\n(*<*)\napply (rule finite_acyclic_wf)\napply ( subst finite_converse)\napply ( rule finite_subcls1)\napply (subst acyclic_converse)\napply (erule acyclic_subcls1)\ndone\n(*>*)\n\n\nlemma single_valued_subcls1:\n  \"wf_prog wf_md G \\<Longrightarrow> single_valued (subcls1 G)\"\n(*<*)\nby(auto simp:wf_prog_def distinct_fst_def single_valued_def dest!:subcls1D)\n(*>*)\n\n\nlemma subcls_induct: \n  \"\\<lbrakk> wf_prog wf_md P; \\<And>C. \\<forall>D. (C,D) \\<in> (subcls1 P)\\<^sup>+ \\<longrightarrow> Q D \\<Longrightarrow> Q C \\<rbrakk> \\<Longrightarrow> Q C\"\n(*<*)\n  (is \"?A \\<Longrightarrow> PROP ?P \\<Longrightarrow> _\")\nproof -\n  assume p: \"PROP ?P\"\n  assume ?A thus ?thesis apply -\napply(drule wf_subcls1)\napply(drule wf_trancl)\napply(simp only: trancl_converse)\napply(erule_tac a = C in wf_induct)\napply(rule p)\napply(auto)\ndone\nqed\n(*>*)\n\n\nlemma subcls1_induct_aux:\n  \"\\<lbrakk> is_class P C; wf_prog wf_md P; Q Object;\n    \\<And>C D fs ms.\n    \\<lbrakk> C \\<noteq> Object; is_class P C; class P C = Some (D,fs,ms) \\<and>\n      wf_cdecl wf_md P (C,D,fs,ms) \\<and> P \\<turnstile> C \\<prec>\\<^sup>1 D \\<and> is_class P D \\<and> Q D\\<rbrakk> \\<Longrightarrow> Q C \\<rbrakk>\n  \\<Longrightarrow> Q C\"\n(*<*)\n  (is \"?A \\<Longrightarrow> ?B \\<Longrightarrow> ?C \\<Longrightarrow> PROP ?P \\<Longrightarrow> _\")\nproof -\n  assume p: \"PROP ?P\"\n  assume ?A ?B ?C thus ?thesis apply -\napply(unfold is_class_def)\napply( rule impE)\nprefer 2\napply(   assumption)\nprefer 2\napply(  assumption)\napply( erule thin_rl)\napply( rule subcls_induct)\napply(  assumption)\napply( rule impI)\napply( case_tac \"C = Object\")\napply(  fast)\napply safe\napply( frule (1) class_wf)\napply( frule (1) wf_cdecl_supD)\n\napply( subgoal_tac \"P \\<turnstile> C \\<prec>\\<^sup>1 a\")\napply( erule_tac [2] subcls1I)\napply(  rule p)\napply (unfold is_class_def)\napply auto\ndone\nqed\n(*>*)\n\n(* FIXME can't we prove this one directly?? *)\nlemma subcls1_induct [consumes 2, case_names Object Subcls]:\n  \"\\<lbrakk> wf_prog wf_md P; is_class P C; Q Object;\n    \\<And>C D. \\<lbrakk>C \\<noteq> Object; P \\<turnstile> C \\<prec>\\<^sup>1 D; is_class P D; Q D\\<rbrakk> \\<Longrightarrow> Q C \\<rbrakk>\n  \\<Longrightarrow> Q C\"\n(*<*)\n  apply (erule subcls1_induct_aux, assumption, assumption)\n  apply blast\n  done\n(*>*)\n\n\nlemma subcls_C_Object:\n  \"\\<lbrakk> is_class P C; wf_prog wf_md P \\<rbrakk> \\<Longrightarrow> P \\<turnstile> C \\<preceq>\\<^sup>* Object\"\n(*<*)\napply(erule (1) subcls1_induct)\n apply( fast)\napply(erule (1) converse_rtrancl_into_rtrancl)\ndone\n(*>*)\n\n\nlemma is_type_pTs:\nassumes \"wf_prog wf_md P\" and \"(C,S,fs,ms) \\<in> set P\" and \"(M,Ts,T,m) \\<in> set ms\"\nshows \"set Ts \\<subseteq> types P\"\n(*<*)\nproof\n  from assms have \"wf_mdecl wf_md P C (M,Ts,T,m)\" \n    by (unfold wf_prog_def wf_cdecl_def) auto  \n  hence \"\\<forall>t \\<in> set Ts. is_type P t\" by (unfold wf_mdecl_def) auto\n  moreover fix t assume \"t \\<in> set Ts\"\n  ultimately have \"is_type P t\" by blast\n  thus \"t \\<in> types P\" ..\nqed\n(*>*)\n\n\nsubsection{* Well-formedness and method lookup *}\n\nlemma sees_wf_mdecl:\n  \"\\<lbrakk> wf_prog wf_md P; P \\<turnstile> C sees M:Ts\\<rightarrow>T = m in D \\<rbrakk> \\<Longrightarrow> wf_mdecl wf_md P D (M,Ts,T,m)\"\n(*<*)\napply(drule visible_method_exists)\napply(fastforce simp:wf_cdecl_def dest!:class_wf dest:map_of_SomeD)\ndone\n(*>*)\n\n\nlemma sees_method_mono [rule_format (no_asm)]: \n  \"\\<lbrakk> P \\<turnstile> C' \\<preceq>\\<^sup>* C; wf_prog wf_md P \\<rbrakk> \\<Longrightarrow>\n  \\<forall>D Ts T m. P \\<turnstile> C sees M:Ts\\<rightarrow>T = m in D \\<longrightarrow>\n     (\\<exists>D' Ts' T' m'. P \\<turnstile> C' sees M:Ts'\\<rightarrow>T' = m' in D' \\<and> P \\<turnstile> Ts [\\<le>] Ts' \\<and> P \\<turnstile> T' \\<le> T)\"\n(*<*)\napply( drule rtranclD)\napply( erule disjE)\napply(  fastforce)\napply( erule conjE)\napply( erule trancl_trans_induct)\nprefer 2\napply(  clarify)\napply(  drule spec, drule spec, drule spec, drule spec, erule (1) impE)\napply clarify\napply(  fast elim: widen_trans widens_trans)\napply( clarify)\napply( drule subcls1D)\napply( clarify)\napply(clarsimp simp:Method_def)\napply(frule (2) sees_methods_rec)\napply(rule refl)\napply(case_tac \"map_of ms M\")\napply(rule_tac x = D in exI)\napply(rule_tac x = Ts in exI)\napply(rule_tac x = T in exI)\napply simp\napply(rule_tac x = m in exI)\napply(fastforce simp add:map_add_def split:option.split)\napply clarsimp\napply(rename_tac Ts' T' m')\napply( drule (1) class_wf)\napply( unfold wf_cdecl_def Method_def)\napply( frule map_of_SomeD)\napply auto\napply(drule (1) bspec, simp)\napply(erule_tac x=D in allE, erule_tac x=Ts in allE, erule_tac x=T in allE)\napply(fastforce simp:map_add_def split:option.split)\ndone\n(*>*)\n\n\nlemma sees_method_mono2:\n  \"\\<lbrakk> P \\<turnstile> C' \\<preceq>\\<^sup>* C; wf_prog wf_md P;\n     P \\<turnstile> C sees M:Ts\\<rightarrow>T = m in D; P \\<turnstile> C' sees M:Ts'\\<rightarrow>T' = m' in D' \\<rbrakk>\n  \\<Longrightarrow> P \\<turnstile> Ts [\\<le>] Ts' \\<and> P \\<turnstile> T' \\<le> T\"\n(*<*)by(blast dest:sees_method_mono sees_method_fun)(*>*)\n\n\nlemma mdecls_visible:\nassumes wf: \"wf_prog wf_md P\" and \"class\": \"is_class P C\"\nshows \"\\<And>D fs ms. class P C = Some(D,fs,ms)\n         \\<Longrightarrow> \\<exists>Mm. P \\<turnstile> C sees_methods Mm \\<and> (\\<forall>(M,Ts,T,m) \\<in> set ms. Mm M = Some((Ts,T,m),C))\"\n(*<*)\nusing wf \"class\"\nproof (induct rule:subcls1_induct)\n  case Object\n  with wf have \"distinct_fst ms\"\n    by (unfold class_def wf_prog_def wf_cdecl_def) (fastforce dest:map_of_SomeD)\n  with Object show ?case by(fastforce intro!: sees_methods_Object map_of_SomeI)\nnext\n  case Subcls\n  with wf have \"distinct_fst ms\"\n    by (unfold class_def wf_prog_def wf_cdecl_def) (fastforce dest:map_of_SomeD)\n  with Subcls show ?case\n    by(fastforce elim:sees_methods_rec dest:subcls1D map_of_SomeI\n                simp:is_class_def)\nqed\n(*>*)\n\n\nlemma mdecl_visible:\nassumes wf: \"wf_prog wf_md P\" and C: \"(C,S,fs,ms) \\<in> set P\" and  m: \"(M,Ts,T,m) \\<in> set ms\"\nshows \"P \\<turnstile> C sees M:Ts\\<rightarrow>T = m in C\"\n(*<*)\nproof -\n  from wf C have \"class\": \"class P C = Some (S,fs,ms)\"\n    by (auto simp add: wf_prog_def class_def is_class_def intro: map_of_SomeI)\n  from \"class\" have \"is_class P C\" by(auto simp:is_class_def)                   \n  with assms \"class\" show ?thesis\n    by(bestsimp simp:Method_def dest:mdecls_visible)\nqed\n(*>*)\n\n\nlemma Call_lemma:\n  \"\\<lbrakk> P \\<turnstile> C sees M:Ts\\<rightarrow>T = m in D; P \\<turnstile> C' \\<preceq>\\<^sup>* C; wf_prog wf_md P \\<rbrakk>\n  \\<Longrightarrow> \\<exists>D' Ts' T' m'.\n       P \\<turnstile> C' sees M:Ts'\\<rightarrow>T' = m' in D' \\<and> P \\<turnstile> Ts [\\<le>] Ts' \\<and> P \\<turnstile> T' \\<le> T \\<and> P \\<turnstile> C' \\<preceq>\\<^sup>* D'\n       \\<and> is_type P T' \\<and> (\\<forall>T\\<in>set Ts'. is_type P T) \\<and> wf_md P D' (M,Ts',T',m')\"\n(*<*)\napply(frule (2) sees_method_mono)\napply(fastforce intro:sees_method_decl_above dest:sees_wf_mdecl\n               simp: wf_mdecl_def)\ndone\n(*>*)\n\n\nlemma wf_prog_lift:\n  assumes wf: \"wf_prog (\\<lambda>P C bd. A P C bd) P\"\n  and rule:\n  \"\\<And>wf_md C M Ts C T m bd.\n   wf_prog wf_md P \\<Longrightarrow>\n   P \\<turnstile> C sees M:Ts\\<rightarrow>T = m in C \\<Longrightarrow>   \n   set Ts \\<subseteq>  types P \\<Longrightarrow>\n   bd = (M,Ts,T,m) \\<Longrightarrow>\n   A P C bd \\<Longrightarrow>\n   B P C bd\"\n  shows \"wf_prog (\\<lambda>P C bd. B P C bd) P\"\n(*<*)\nproof -\n  from wf show ?thesis\n    apply (unfold wf_prog_def wf_cdecl_def)\n    apply clarsimp\n    apply (drule bspec, assumption)\n    apply (unfold wf_mdecl_def)\n    apply clarsimp\n    apply (drule bspec, assumption)\n    apply clarsimp\n    apply (frule mdecl_visible [OF wf], assumption+)\n    apply (frule is_type_pTs [OF wf], assumption+)\n    apply (drule rule [OF wf], assumption+)\n    apply auto\n    done\nqed\n(*>*)\n\n\nsubsection{* Well-formedness and field lookup *}\n\nlemma wf_Fields_Ex:\n  \"\\<lbrakk> wf_prog wf_md P; is_class P C \\<rbrakk> \\<Longrightarrow> \\<exists>FDTs. P \\<turnstile> C has_fields FDTs\"\n(*<*)\napply(frule class_Object)\napply(erule (1) subcls1_induct)\n apply(blast intro:has_fields_Object)\napply(blast intro:has_fields_rec dest:subcls1D)\ndone\n(*>*)\n\n\nlemma has_fields_types:\n  \"\\<lbrakk> P \\<turnstile> C has_fields FDTs; (FD,T) \\<in> set FDTs; wf_prog wf_md P \\<rbrakk> \\<Longrightarrow> is_type P T\"\n(*<*)\napply(induct rule:Fields.induct)\n apply(fastforce dest!: class_wf simp: wf_cdecl_def wf_fdecl_def)\napply(fastforce dest!: class_wf simp: wf_cdecl_def wf_fdecl_def)\ndone\n(*>*)\n\n\nlemma sees_field_is_type:\n  \"\\<lbrakk> P \\<turnstile> C sees F:T in D; wf_prog wf_md P \\<rbrakk> \\<Longrightarrow> is_type P T\"\n(*<*)\nby(fastforce simp: sees_field_def\n            elim: has_fields_types map_of_SomeD[OF map_of_remap_SomeD])\n(*>*)\n\nlemma wf_syscls:\n  \"set SystemClasses \\<subseteq> set P \\<Longrightarrow> wf_syscls P\"\n(*<*)\napply (simp add: image_def SystemClasses_def wf_syscls_def sys_xcpts_def\n                 ObjectC_def NullPointerC_def ClassCastC_def OutOfMemoryC_def)\n apply force\ndone\n(*>*)\n\nend\n", "meta": {"author": "Josh-Tilles", "repo": "AFP", "sha": "f4bf1d502bde2a3469d482b62c531f1c3af3e881", "save_path": "github-repos/isabelle/Josh-Tilles-AFP", "path": "github-repos/isabelle/Josh-Tilles-AFP/AFP-f4bf1d502bde2a3469d482b62c531f1c3af3e881/thys/Jinja/Common/WellForm.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5926665999540698, "lm_q2_score": 0.42250463481418826, "lm_q1q2_score": 0.25040438538016085}}
{"text": "theory ARMv7A_Update_ASID_Ref\n\n\nimports  ARMv7A_Update_TTBR0_Ref\n\nbegin  \n\n\n\n\nlemma  update_asid_non_det_sat_refine:\n  \"\\<lbrakk> update_ASID a (s::'a non_det_tlb_state_scheme) = ((), s') ;  update_ASID a (t::'b sat_tlb_state_scheme) = ((), t'); \n         tlb_rel_sat (typ_non_det_tlb s) (typ_sat_tlb t) \\<rbrakk> \\<Longrightarrow> \n                  tlb_rel_sat (typ_non_det_tlb s') (typ_sat_tlb t')\"\n  apply (clarsimp simp: update_ASID_non_det_tlb_state_ext_def update_ASID_sat_tlb_state_ext_def)\n  apply (clarsimp simp: tlb_rel_sat_def saturated_def)\n  apply (cases s, cases t , clarsimp simp: state.defs pairsub_def, force)\n  done\n\n\n\nlemma asid_unequal_snp_upd_equal' [simp]:\n  \"a \\<noteq> a' \\<Longrightarrow>   snp_upd_cur' snp ist m r a' a = snp a\"\n  by (clarsimp simp: snp_upd_cur'_def)\n\n\n\nlemma saturated_global_subset_lookup_tlb_un_eq:\n  \"saturated (typ_sat_tlb s) \\<Longrightarrow> \n        lookup''(global_entries (fst(sat_tlb s)) \\<union> \n                 global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}))  a v = \n                 lookup'' (global_entries (fst(sat_tlb s))) a v\"\n  apply (rule tlb_subset_lookup_un_eq)\n  apply (subgoal_tac \"global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}) = \n                       global_entries (the ` {e \\<in> range (pt_walk (ASID s) (MEM s) (TTBR0 s)). \\<not> is_fault e})\")\n   apply (simp only:)\n   apply (clarsimp simp: saturated_def global_entries_def) apply blast\n  by (rule global_entries_ptable_same)\n\n\n\nlemma saturated_global_subset_lookup_pdc_un_eq:\n  \"saturated (typ_sat_tlb s) \\<Longrightarrow> \n        lookup_pdc (global_entries_pdc (snd(sat_tlb s)) \\<union> \n                 global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}))  a v = \n                 lookup_pdc (global_entries_pdc (snd(sat_tlb s))) a v\"\n  apply (rule pdc_subset_lookup_un_eq)\n  apply (subgoal_tac \"global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}) = \n                       global_entries_pdc (the ` {e \\<in> range (pdc_walk (ASID s) (MEM s) (TTBR0 s)). \\<not> is_fault e})\")\n   apply (simp only:)\n   apply (clarsimp simp: saturated_def global_entries_pdc_def) apply blast\n  by (rule global_entries_pdc_ptable_same)\n\n\n\nlemma  update_asid_sat_incon_refine:\n  \"\\<lbrakk> update_ASID a (s::'a sat_tlb_state_scheme) = ((), s') ;  update_ASID a (t::'b set_tlb_state_scheme) = ((), t'); \n         tlb_rel_abs (typ_sat_tlb s) (typ_set_tlb t) \\<rbrakk> \\<Longrightarrow> \n                  tlb_rel_abs (typ_sat_tlb s') (typ_set_tlb t')\"\n  apply (clarsimp simp: update_ASID_sat_tlb_state_ext_def update_ASID_set_tlb_state_ext_def Let_def)\n  apply (frule tlb_rel_absD)\n  apply (case_tac \"a = ASID s\")\n    (* to the same ASID *)\n   apply (subgoal_tac \"sat_tlb s = pairunion (sat_tlb s)\n           (the ` {e \\<in> range (pt_walk (ASID s) (MEM s) (TTBR0 s)). \\<not> is_fault e}, the ` {e \\<in> range (pdc_walk (ASID s) (MEM s) (TTBR0 s)). \\<not> is_fault e})\")\n    prefer 2\n    apply (clarsimp simp:  saturated_def) \n   apply (clarsimp simp: tlb_rel_abs_def)\n   apply (rule conjI)\n    apply (clarsimp simp: state.defs)\n   apply (rule conjI)\n    apply clarsimp\n    apply (clarsimp simp:  snp_upd_cur'_def snp_upd_cur_def )\n    apply (cases t, cases s, clarsimp) apply force\n   apply clarsimp\n   apply (clarsimp simp: lookup_from'_def snap_conv'_def snp_upd_cur'_def snp_upd_cur_def)\n    (* to new asid *)\n  apply (clarsimp simp: tlb_rel_abs_def)\n  apply (rule conjI)\n   apply (clarsimp simp: state.defs)\n  apply (rule conjI)\n   apply (clarsimp simp: saturated_def)\n  apply (thin_tac \"s' = s \\<lparr>ASID := a,    sat_tlb :=  pairunion (sat_tlb s)\n                  (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}, the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})\\<rparr>\")\n  apply (thin_tac \"t' = t\n     \\<lparr>ASID := a,\n        set_tlb := set_tlb t\n          \\<lparr>snapshot := snp_upd_cur' (snapshot (set_tlb t)) (iset (set_tlb t)) (MEM s) (TTBR0 s) (ASID s),\n             iset := fst (snapshot (set_tlb t) a) \\<union> iset (set_tlb t) \\<inter> global_set (set_tlb t) \\<union> ptable_comp (snd (snapshot (set_tlb t) a)) (pt_walk_pair a (MEM s) (TTBR0 s))\\<rparr>\\<rparr>\")\n  apply (rule conjI)\n   apply (clarsimp simp: incon_addrs_def)\n   apply (rule conjI)\n    apply (clarsimp simp: inconsistent_vaddrs_def)\n    apply (rule conjI)\n     apply (clarsimp)\n     apply (rename_tac v)\n     apply (subgoal_tac \"fst(sat_tlb s) \\<union> the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e} =  (non_global_entries (fst(sat_tlb s)) \\<union> non_global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) \\<union>  \n                          (global_entries (fst(sat_tlb s)) \\<union> global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}))\")\n      apply (simp only:)\n      apply (thin_tac \"fst(sat_tlb s) \\<union> the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e} =  (non_global_entries (fst(sat_tlb s)) \\<union> non_global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) \\<union>  \n                          (global_entries (fst(sat_tlb s)) \\<union> global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}))\")\n      apply (subgoal_tac \"lookup''   (global_entries (fst(sat_tlb s)))  a v = lookup'' (global_entries (fst(sat_tlb s)) \\<union>  global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) a v \")\n       prefer 2\n       apply (rule saturated_global_subset_lookup_tlb_un_eq[symmetric], simp)\n      apply (drule_tac t = \"non_global_entries (fst(sat_tlb s)) \\<union> non_global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})\" in union_asid_tlb_incon_cases)\n      apply (erule disjE, clarsimp)\n       apply (thin_tac \"lookup'' (global_entries (fst(sat_tlb s)) \\<union> global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}))\n                       a v =  Incon\")\n       apply (subgoal_tac \"v \\<in> iset (set_tlb t)\")\n        apply (subgoal_tac \"v \\<in> global_set (set_tlb t)\")\n         apply blast\n        apply (clarsimp simp: global_entries_def lookup_def tagged_entry_set_def entry_set_def global_range_def split: if_split_asm option.splits)\n        apply blast\n       apply (drule_tac a' = \"ASID s\" in lookup_global_incon_incon)\n       apply blast\n      apply (erule disjE, clarsimp)\n       apply (thin_tac \"lookup'' (global_entries (fst(sat_tlb s)) \\<union> global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) a v = Hit xa\") \n       apply (case_tac \"v \\<in> global_set (set_tlb t)\")\n        apply (case_tac \"v \\<in> iset (set_tlb t)\")\n         apply blast\n        apply clarsimp\n        apply (subgoal_tac \"lookup''  (fst(sat_tlb s)) (ASID s) v = Hit xa \\<or> \n                           lookup''  (fst(sat_tlb s)) (ASID s) v = Incon\")\n         apply (erule_tac P = \"lookup''  (fst(sat_tlb s)) (ASID s) v = Hit xa\" in disjE)\n          apply (case_tac \"is_fault (pt_walk (ASID s) (MEM s) (TTBR0 s) v)\")\n           apply (clarsimp simp: incoherrent_vaddrs_def)\n           apply force\n          apply (drule  lookup_asid_tlb_hit_union_cases')\n          apply (erule disjE, clarsimp)\n           apply (subgoal_tac \"asid_of (the (pt_walk a (MEM s) (TTBR0 s) v)) = None\")\n            apply (drule_tac x = a in spec, simp, drule_tac x = v in spec)\n            apply (clarsimp simp: non_global_to_global [symmetric])\n            apply (case_tac \"fst(lookup_from' (snapshot (set_tlb t)) a v)\"; clarsimp?)\n             apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n            apply (drule_tac a' = a in no_fault_pt_walk_unequal_asid')\n            apply (frule non_fault_pt_walk_full_walk)\n            apply (subgoal_tac \"the (pt_walk a (MEM s) (TTBR0 s) v) \\<noteq> x3\")\n             apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n             apply (clarsimp simp: ptable_comp_def is_fault_def entry_leq_def)\n            apply (subgoal_tac \"asid_of x3 \\<noteq> None\")\n             apply force\n            apply (drule lookup_non_global_hit_asid_of_not_none, simp)\n           apply (drule lookup_non_global_miss_non_fault)\n            apply (frule_tac a' = a in no_fault_pt_walk_unequal_asid', simp)\n           apply (rule_tac v = v and a = a and t = \"(the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})\" in lookup_global_hit_asid_of_none, simp)\n          apply (erule disjE, clarsimp)\n           apply (subgoal_tac \"xa \\<noteq> the (pt_walk (ASID t) (MEM s) (TTBR0 s) v)\")\n            apply (drule_tac b = v and x = xa in saturatd_lookup_hit_no_fault; simp?)\n           apply (subgoal_tac \"asid_of xa = None\")\n            apply (subgoal_tac \"asid_of (the (pt_walk (ASID t) (MEM s) (TTBR0 s) v)) \\<noteq> None\")\n             apply force\n            apply (subgoal_tac \"lookup'' (non_global_entries (the ` {e \\<in> range (pt_walk (ASID t) (MEM s) (TTBR0 s)). \\<not> is_fault e})) (ASID t) v = Hit \n                              (the (pt_walk (ASID t) (MEM s) (TTBR0 s) v))\")\n             apply (rule lookup_non_global_hit_asid_of_not_none, simp)\n            apply (rule_tac a = a in non_global_lookup_hit_asid, simp)\n           apply (rule lookup_global_hit_asid_of_none, simp)\n          apply (clarsimp)\n          apply (subgoal_tac \"xa \\<noteq> the (pt_walk (ASID t) (MEM s) (TTBR0 s) v)\")\n           apply (drule_tac b = v and x = xa in saturatd_lookup_hit_no_fault; simp?)\n          apply (subgoal_tac \"asid_of xa = None\")\n           apply (subgoal_tac \"asid_of (the (pt_walk (ASID t) (MEM s) (TTBR0 s) v)) \\<noteq> None\")\n            apply force\n           apply (subgoal_tac \"lookup'' (non_global_entries (the ` {e \\<in> range (pt_walk (ASID t) (MEM s) (TTBR0 s)). \\<not> is_fault e})) (ASID t) v = Hit \n                              (the (pt_walk (ASID t) (MEM s) (TTBR0 s) v))\")\n            apply (rule lookup_non_global_hit_asid_of_not_none, simp)\n           apply (rule_tac a = a in non_global_lookup_hit_asid, simp)\n          apply (rule lookup_global_hit_asid_of_none, simp)\n         apply blast\n        apply (metis (no_types, hide_lams) lookup_global_hit_order lookup_global_same_for_asids)\n       apply (subgoal_tac \"xa \\<in> global_entries (fst(sat_tlb s))\")\n        apply (subgoal_tac \"v \\<in> range_of xa\")\n         apply (clarsimp simp: global_range_def)\n         apply blast\n        apply (simp add: lookup_asid_tlb_hit_entry_range)\n  using lookup_in_asid_tlb apply auto[1]\n      apply (erule disjE, clarsimp)\n       apply (thin_tac \"lookup'' (global_entries (fst(sat_tlb s)) \\<union> global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}))\n                       a v =  Incon\")\n       apply (subgoal_tac \"v \\<in> iset (set_tlb t)\")\n        apply (subgoal_tac \"v \\<in> global_set (set_tlb t)\")\n         apply blast\n        apply (clarsimp simp: global_entries_def lookup_def tagged_entry_set_def entry_set_def global_range_def split: if_split_asm option.splits)\n        apply blast\n       apply (drule_tac a' = \"ASID s\" in lookup_global_incon_incon)\n       apply blast\n      apply (erule disjE, clarsimp)\n       apply (thin_tac \"lookup'' (global_entries (fst(sat_tlb s)) \\<union>  global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}))a v = Hit x\")\n       apply (drule union_asid_tlb_incon_cases)\n       apply (erule disjE, clarsimp simp: )\n  using non_global_lookup_range_pt_walk_not_incon apply force\n       apply (erule disjE, clarsimp simp: )\n        apply (drule_tac x = a in spec, simp, drule_tac x = v in spec)\n        apply (clarsimp simp: non_global_to_global [symmetric])\n        apply (case_tac \"fst(lookup_from' (snapshot (set_tlb t)) a v)\"; clarsimp?)\n         apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n        apply (subgoal_tac \"\\<not>is_fault (pt_walk a (MEM s) (TTBR0 s) v)\")\n         apply (subgoal_tac \"xb = the (pt_walk a (MEM s) (TTBR0 s) v)\")\n          apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n          apply (clarsimp simp: ptable_comp_def is_fault_def entry_leq_def) \n          apply (metis pt_walk_new_no_fault_pt_walk' option.inject) \n         apply (frule_tac a' = a in non_global_lookup_hit_asid, simp)\n        apply (rule non_global_hit_no_fault, simp)\n       apply (erule disjE, clarsimp simp: )\n  using non_global_lookup_range_pt_walk_not_incon apply force \n       apply (erule disjE, clarsimp simp: )\n        apply (drule_tac x = a in spec, simp, drule_tac x = v in spec)\n        apply (clarsimp simp: non_global_to_global [symmetric])\n        apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n       apply (erule disjE, clarsimp simp: )\n  using non_global_lookup_range_pt_walk_not_incon apply force\n       apply (clarsimp simp: )\n       apply (drule_tac x = a in spec, simp, drule_tac x = v in spec)\n       apply (clarsimp simp: non_global_to_global [symmetric])\n       apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n      apply (erule disjE, clarsimp)\n       apply (thin_tac \"lookup'' (global_entries (fst(sat_tlb s)) \\<union> global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}))\n                       a v =  Incon\")\n       apply (subgoal_tac \"v \\<in> iset (set_tlb t)\")\n        apply (subgoal_tac \"v \\<in> global_set (set_tlb t)\")\n         apply blast\n        apply (clarsimp simp: global_entries_def lookup_def tagged_entry_set_def entry_set_def global_range_def split: if_split_asm option.splits)\n        apply blast\n       apply (drule_tac a' = \"ASID s\" in lookup_global_incon_incon)\n       apply blast\n      apply (clarsimp)\n      apply (thin_tac \"lookup''  (global_entries (fst(sat_tlb s)) \\<union> global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) a v = Miss\")\n      apply (drule union_asid_tlb_incon_cases)\n      apply (erule disjE, clarsimp simp: )\n  using non_global_lookup_range_pt_walk_not_incon apply force\n      apply (erule disjE, clarsimp simp: )\n       apply (drule_tac x = a in spec, simp, drule_tac x = v in spec)\n       apply (clarsimp simp: non_global_to_global [symmetric])\n       apply (case_tac \"fst(lookup_from' (snapshot (set_tlb t)) a v)\"; clarsimp?)\n        apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n       apply (subgoal_tac \"\\<not>is_fault (pt_walk a (MEM s) (TTBR0 s) v)\")\n        apply (subgoal_tac \"xa = the (pt_walk a (MEM s) (TTBR0 s) v)\")\n         apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n         apply (clarsimp simp: ptable_comp_def is_fault_def entry_leq_def) \n         apply (metis pt_walk_new_no_fault_pt_walk' option.inject) \n        apply (frule_tac a' = a in non_global_lookup_hit_asid, simp)\n       apply (rule non_global_hit_no_fault, simp)\n      apply (erule disjE, clarsimp simp: )\n  using non_global_lookup_range_pt_walk_not_incon apply force\n      apply (erule disjE, clarsimp simp: )\n       apply (drule_tac x = a in spec, simp, drule_tac x = v in spec)\n       apply (clarsimp simp: non_global_to_global [symmetric])\n       apply (clarsimp simp: lookup_from'_def snap_conv'_def split:  pt_walk_typ.splits if_split_asm option.splits)\n      apply (erule disjE, clarsimp simp: )\n  using non_global_lookup_range_pt_walk_not_incon apply force\n      apply (clarsimp simp: )\n      apply (drule_tac x = a in spec, simp, drule_tac x = v in spec)\n      apply (clarsimp simp: non_global_to_global [symmetric])\n      apply (clarsimp simp: lookup_from'_def snap_conv'_def split:  pt_walk_typ.splits if_split_asm option.splits)\n     apply (rule tlb_nion_global_non_global)\n    apply (clarsimp)\n    apply (rename_tac v)\n    apply (subgoal_tac \"snd(sat_tlb s) \\<union> the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e} =  (non_global_entries_pdc (snd(sat_tlb s)) \\<union> non_global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) \\<union>  \n                          (global_entries_pdc (snd(sat_tlb s)) \\<union> global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}))\")\n     apply (simp only:)\n     apply (thin_tac \"snd(sat_tlb s) \\<union> the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e} =  (non_global_entries_pdc (snd(sat_tlb s)) \\<union> non_global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) \\<union>  \n                          (global_entries_pdc (snd(sat_tlb s)) \\<union> global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}))\")\n     apply (subgoal_tac \"lookup_pdc (global_entries_pdc (snd(sat_tlb s)))  a v = lookup_pdc (global_entries_pdc (snd(sat_tlb s)) \\<union>  global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) a v \")\n      prefer 2\n      apply (rule saturated_global_subset_lookup_pdc_un_eq[symmetric], simp)\n     apply (drule_tac t = \"non_global_entries_pdc (snd(sat_tlb s)) \\<union> non_global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})\" in union_asid_pdc_incon_cases)\n     apply (erule disjE, clarsimp)\n      apply (thin_tac \"lookup_pdc (global_entries_pdc (snd(sat_tlb s)) \\<union> global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}))\n                       a v =  Incon\")\n      apply (subgoal_tac \"v \\<in> iset (set_tlb t)\")\n       apply (subgoal_tac \"v \\<in> global_set (set_tlb t)\")\n        apply blast\n       apply (clarsimp simp: global_entries_pdc_def lookup_def asid_of_pdc_def tagged_pdc_entry_set_def entry_set_def global_range_def split: if_split_asm option.splits)\n       apply blast\n      apply (drule_tac a' = \"ASID s\" in lookup_global_incon_incon_pdc')\n      apply blast\n     apply (erule disjE, clarsimp)\n      apply (thin_tac \"lookup_pdc (global_entries_pdc (snd(sat_tlb s)) \\<union> global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) a v = Hit xa\") \n      apply (case_tac \"v \\<in> global_set (set_tlb t)\")\n       apply (case_tac \"v \\<in> iset (set_tlb t)\")\n        apply blast\n       apply clarsimp\n       apply (subgoal_tac \"lookup_pdc  (snd(sat_tlb s)) (ASID s) v = Hit xa \\<or> \n                           lookup_pdc  (snd(sat_tlb s)) (ASID s) v = Incon\")\n        apply (erule_tac P = \"lookup_pdc  (snd(sat_tlb s)) (ASID s) v = Hit xa\" in disjE)\n         apply (case_tac \"is_fault (pdc_walk (ASID s) (MEM s) (TTBR0 s) v)\")\n          apply (clarsimp simp: incoherrent_vaddrs_def)\n          apply force\n         apply (drule  lookup_asid_pdc_hit_union_cases')\n         apply (erule disjE, clarsimp)\n          apply (subgoal_tac \"asid_of_pdc (the (pdc_walk a (MEM s) (TTBR0 s) v)) = None\")\n           apply (drule_tac x = a in spec, simp, drule_tac x = v in spec)\n           apply (clarsimp simp: non_global_to_global_pdc [symmetric])\n           apply (case_tac \"snd(lookup_from' (snapshot (set_tlb t)) a v)\"; clarsimp?)\n            apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n           apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n             apply (clarsimp simp: ptable_comp_def is_fault_def entry_leq_def) \n             apply (metis option.sel option.simps(3) pt_walk_new_no_fault_pdc_walk pt_walk_new_par_fault_pdc_walk)\n            apply (clarsimp simp: ptable_comp_def is_fault_def entry_leq_def) \n            apply (metis option.sel option.simps(3) pt_walk_new_no_fault_pdc_walk )\n           apply (clarsimp simp: ptable_comp_def is_fault_def entry_leq_def) \n           apply (metis lookup_non_global_hit_asid_of_not_none_pdc option.sel pt_walk_new_no_fault_pdc_walk)\n          apply (rule_tac v = v and a = a and t = \"(the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})\" in lookup_global_hit_asid_of_none_pdc)\n          apply (subgoal_tac \"\\<not> is_fault (pdc_walk a (MEM s) (TTBR0 s) v)\")\n           apply (rule lookup_pdc_non_global_miss_non_fault, simp, simp)\n  using no_fault_pdc_walk_unequal_asid' apply blast\n         apply (erule disjE, clarsimp)\n          apply (subgoal_tac \"xa \\<noteq> the (pdc_walk (ASID t) (MEM s) (TTBR0 s) v)\")\n           apply (drule_tac b = v and x = xa in saturatd_lookup_pdc_hit_no_fault; simp?)\n          apply (subgoal_tac \"asid_of_pdc xa = None\")\n           apply (subgoal_tac \"asid_of_pdc (the (pdc_walk (ASID t) (MEM s) (TTBR0 s) v)) \\<noteq> None\")\n            apply force\n           apply (subgoal_tac \"lookup_pdc (non_global_entries_pdc (the ` {e \\<in> range (pdc_walk (ASID t) (MEM s) (TTBR0 s)). \\<not> is_fault e})) (ASID t) v = Hit \n                              (the (pdc_walk (ASID t) (MEM s) (TTBR0 s) v))\")\n            apply (rule lookup_non_global_hit_asid_of_not_none_pdc, simp)\n           apply (rule_tac a = a in non_global_lookup_pdc_hit_asid, simp)\n          apply (rule lookup_global_hit_asid_of_none_pdc, simp)\n         apply (clarsimp)\n         apply (subgoal_tac \"xa \\<noteq> the (pdc_walk (ASID t) (MEM s) (TTBR0 s) v)\")\n          apply (drule_tac b = v and x = xa in saturatd_lookup_pdc_hit_no_fault; simp?)\n         apply (subgoal_tac \"asid_of_pdc xa = None\")\n          apply (subgoal_tac \"asid_of_pdc (the (pdc_walk (ASID t) (MEM s) (TTBR0 s) v)) \\<noteq> None\")\n           apply force\n          apply (subgoal_tac \"lookup_pdc (non_global_entries_pdc (the ` {e \\<in> range (pdc_walk (ASID t) (MEM s) (TTBR0 s)). \\<not> is_fault e})) (ASID t) v = Hit \n                              (the (pdc_walk (ASID t) (MEM s) (TTBR0 s) v))\")\n           apply (rule lookup_non_global_hit_asid_of_not_none_pdc, simp)\n          apply (rule_tac a = a in non_global_lookup_pdc_hit_asid, simp)\n         apply (rule lookup_global_hit_asid_of_none_pdc, simp)\n        apply blast\n       apply (metis lookup_global_same_for_asids_pdc lookup_pdc_global_hit_order)\n      apply (subgoal_tac \"xa \\<in> global_entries_pdc (snd(sat_tlb s))\")\n       apply (subgoal_tac \"v \\<in> range_of xa\")\n        apply (clarsimp simp: global_range_def)\n        apply blast\n       apply (simp add: lookup_asid_pdc_hit_entry_range)\n  using lookup_in_asid_pdc apply auto[1]\n     apply (erule disjE, clarsimp)\n      apply (thin_tac \"lookup_pdc (global_entries_pdc (snd(sat_tlb s)) \\<union> global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}))\n                       a v =  Incon\")\n      apply (subgoal_tac \"v \\<in> iset (set_tlb t)\")\n       apply (subgoal_tac \"v \\<in> global_set (set_tlb t)\")\n        apply blast\n       apply (clarsimp simp: global_entries_pdc_def lookup_def asid_of_pdc_def tagged_pdc_entry_set_def entry_set_def global_range_def split: if_split_asm option.splits)\n       apply blast\n      apply (drule_tac a' = \"ASID s\" in lookup_global_incon_incon_pdc')\n      apply blast\n     apply (erule disjE, clarsimp)\n      apply (thin_tac \"lookup_pdc (global_entries_pdc (snd(sat_tlb s)) \\<union>  global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}))a v = Hit x\")\n      apply (drule union_asid_pdc_incon_cases)\n      apply (erule disjE, clarsimp simp: )\n  using non_global_lookup_range_pdc_walk_not_incon apply force\n      apply (erule disjE, clarsimp simp: )\n       apply (drule_tac x = a in spec, simp, drule_tac x = v in spec)\n       apply (clarsimp simp: non_global_to_global_pdc [symmetric])\n       apply (case_tac \"snd(lookup_from' (snapshot (set_tlb t)) a v)\"; clarsimp?)\n        apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n       apply (subgoal_tac \"\\<not>is_fault (pdc_walk a (MEM s) (TTBR0 s) v)\")\n        apply (subgoal_tac \"xb = the (pdc_walk a (MEM s) (TTBR0 s) v)\")\n         apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n           apply (clarsimp simp: ptable_comp_def is_fault_def entry_leq_def) \n           apply (metis option.inject pt_walk_new_no_fault_pdc_walk pt_walk_new_par_fault_pdc_walk) \n          apply (clarsimp simp: ptable_comp_def is_fault_def entry_leq_def) \n          apply (metis option.inject pt_walk_new_no_fault_pdc_walk pt_walk_new_par_fault_pdc_walk)\n         apply (clarsimp simp: ptable_comp_def is_fault_def entry_leq_def) \n         apply (metis option.inject pt_walk_new_no_fault_pdc_walk pt_walk_new_par_fault_pdc_walk) \n        apply (frule_tac a' = a in non_global_lookup_pdc_hit_asid, simp)\n       apply (rule non_global_hit_no_fault_pdc, simp)\n      apply (erule disjE, clarsimp simp: )\n  using non_global_lookup_range_pdc_walk_not_incon apply force \n      apply (erule disjE, clarsimp simp: )\n       apply (drule_tac x = a in spec, simp, drule_tac x = v in spec)\n       apply (clarsimp simp: non_global_to_global_pdc [symmetric])\n       apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n      apply (erule disjE, clarsimp simp: )\n  using non_global_lookup_range_pdc_walk_not_incon apply force\n      apply (clarsimp simp: )\n      apply (drule_tac x = a in spec, simp, drule_tac x = v in spec)\n      apply (clarsimp simp: non_global_to_global_pdc [symmetric])\n      apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n     apply (erule disjE, clarsimp)\n      apply (thin_tac \"lookup_pdc (global_entries_pdc (snd(sat_tlb s)) \\<union> global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}))\n                       a v =  Incon\")\n      apply (subgoal_tac \"v \\<in> iset (set_tlb t)\")\n       apply (subgoal_tac \"v \\<in> global_set (set_tlb t)\")\n        apply blast\n       apply (clarsimp simp: global_entries_pdc_def lookup_def asid_of_pdc_def tagged_pdc_entry_set_def entry_set_def global_range_def split: if_split_asm option.splits)\n       apply blast\n      apply (drule_tac a' = \"ASID s\" in lookup_global_incon_incon_pdc')\n      apply blast\n     apply (clarsimp)\n     apply (thin_tac \"lookup_pdc (global_entries_pdc (snd(sat_tlb s)) \\<union> global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) a v = Miss\")\n     apply (drule union_asid_pdc_incon_cases)\n     apply (erule disjE, clarsimp simp: )\n  using non_global_lookup_range_pdc_walk_not_incon apply force\n     apply (erule disjE, clarsimp simp: )\n      apply (drule_tac x = a in spec, simp, drule_tac x = v in spec)\n      apply (clarsimp simp: non_global_to_global_pdc [symmetric])\n      apply (case_tac \"snd(lookup_from' (snapshot (set_tlb t)) a v)\"; clarsimp?)\n       apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n      apply (subgoal_tac \"\\<not>is_fault (pdc_walk a (MEM s) (TTBR0 s) v)\")\n       apply (subgoal_tac \"xa = the (pdc_walk a (MEM s) (TTBR0 s) v)\")\n        apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n          apply (clarsimp simp: ptable_comp_def is_fault_def entry_leq_def) \n          apply (metis (no_types, hide_lams) non_fault_pt_walk_pair_disjI option.inject\n      option.sel pt_walk_full_no_pdc_fault pt_walk_new_par_fault_pdc_walk pt_walk_typ.inject(2) pt_walk_typ.simps(8))\n         apply (clarsimp simp: ptable_comp_def is_fault_def entry_leq_def) \n         apply (metis option.inject pt_walk_new_no_fault_pdc_walk)   \n        apply (clarsimp simp: ptable_comp_def is_fault_def entry_leq_def) \n        apply (metis option.inject pt_walk_new_no_fault_pdc_walk)\n       apply (frule_tac a' = a in non_global_lookup_pdc_hit_asid, simp)\n      apply (rule non_global_hit_no_fault_pdc, simp)\n     apply (erule disjE, clarsimp simp: )\n  using non_global_lookup_range_pdc_walk_not_incon apply force\n     apply (erule disjE, clarsimp simp: )\n      apply (drule_tac x = a in spec, simp, drule_tac x = v in spec)\n      apply (clarsimp simp: non_global_to_global_pdc [symmetric])\n      apply (clarsimp simp: lookup_from'_def snap_conv'_def split:  pt_walk_typ.splits if_split_asm option.splits)\n     apply (erule disjE, clarsimp simp: )\n  using non_global_lookup_range_pdc_walk_not_incon apply force\n     apply (clarsimp simp: )\n     apply (drule_tac x = a in spec, simp, drule_tac x = v in spec)\n     apply (clarsimp simp: non_global_to_global_pdc [symmetric])\n     apply (clarsimp simp: lookup_from'_def snap_conv'_def split:  pt_walk_typ.splits if_split_asm option.splits)\n    apply (rule pdc_non_global_non_global)\n   apply (clarsimp simp: incoherrent_vaddrs_def)\n   apply (rule conjI)\n    apply clarsimp\n    apply (rename_tac v x)\n    apply (subgoal_tac \"fst(sat_tlb s) \\<union> the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e} = \n                                             (non_global_entries (fst(sat_tlb s)) \\<union> non_global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) \\<union>  (global_entries (fst(sat_tlb s)) \\<union> global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}))\")\n     apply (simp only:)\n     apply (thin_tac \"fst(sat_tlb s) \\<union> the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e} = \n                                             (non_global_entries (fst(sat_tlb s)) \\<union> non_global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) \\<union>  (global_entries (fst(sat_tlb s)) \\<union> global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}))\")\n     apply (subgoal_tac \"lookup''   (global_entries (fst(sat_tlb s)))  a v = lookup'' (global_entries (fst(sat_tlb s)) \\<union>  global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) a v \")\n      prefer 2\n      apply (rule saturated_global_subset_lookup_tlb_un_eq[symmetric], simp)\n     apply (drule_tac t = \"non_global_entries (fst(sat_tlb s)) \\<union> non_global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})\" in  lookup_asid_tlb_hit_union_cases')\n     apply (erule disjE, clarsimp)\n      apply (thin_tac \"lookup''(global_entries (fst(sat_tlb s)) \\<union> global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) a v = Miss\")\n      apply (subgoal_tac \"lookup'' (non_global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) a v = Miss\")\n       apply (drule  lookup_asid_tlb_hit_union_cases')\n       apply (erule disjE, clarsimp)\n        apply (drule_tac x = a in spec, simp, drule_tac x = v in spec)\n        apply (clarsimp simp: non_global_to_global [symmetric])\n        apply (case_tac \"fst(lookup_from' (snapshot (set_tlb t)) a v)\"; clarsimp?)\n         apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n        apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n        apply (clarsimp simp: ptable_comp_def is_fault_def entry_leq_def) \n        apply (metis option.simps(3) pt_walk_new_no_fault_pt_walk') \n       apply (erule disjE, clarsimp)\n       apply (clarsimp)\n      apply (rule is_fault_non_global_entries_miss, simp)\n     apply (erule disjE, clarsimp)\n      apply (thin_tac \"lookup''  (global_entries (fst(sat_tlb s)) \\<union> global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) a v =  Hit x\")\n      apply (subgoal_tac \"v \\<in> global_set (set_tlb t)\")\n       apply (case_tac \"v \\<in> iset (set_tlb t)\") \n        apply blast\n       apply (subgoal_tac \" lookup''  (fst(sat_tlb s)) (ASID t) v = Hit x \\<or>\n                       lookup''  (fst(sat_tlb s)) (ASID t) v = Incon\")\n        prefer 2\n        apply (metis (no_types, hide_lams)  lookup_global_hit_order lookup_global_same_for_asids )\n       apply (erule disjE)\n        apply (clarsimp simp: ) \n  using no_fault_pt_walk_unequal_asid' apply fastforce\n       apply (clarsimp simp: inconsistent_vaddrs_def) apply force\n      apply (clarsimp simp: global_entries_def lookup_def tagged_entry_set_def entry_set_def global_range_def split: if_split_asm option.splits)\n      apply blast\n     apply (clarsimp)\n     apply (subgoal_tac \"v \\<in> global_set (set_tlb t)\")\n      apply (case_tac \"v \\<in> iset (set_tlb t)\") \n       apply blast\n      apply (subgoal_tac \" lookup''  (fst(sat_tlb s)) (ASID t) v = Hit x \\<or>\n                       lookup''  (fst(sat_tlb s)) (ASID t) v = Incon\")\n       prefer 2\n       apply (metis (no_types, hide_lams)  lookup_global_hit_order lookup_global_same_for_asids )\n      apply (erule disjE)\n       apply (clarsimp simp: ) \n  using no_fault_pt_walk_unequal_asid' apply fastforce\n      apply (clarsimp simp: inconsistent_vaddrs_def) apply force\n     apply (clarsimp simp: global_entries_def lookup_def tagged_entry_set_def entry_set_def global_range_def split: if_split_asm option.splits)\n     apply blast\n    apply (rule tlb_nion_global_non_global)\n   apply clarsimp\n   apply (rename_tac v x)\n   apply (subgoal_tac \"snd(sat_tlb s) \\<union> the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e} = \n                                             (non_global_entries_pdc (snd(sat_tlb s)) \\<union> non_global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) \\<union>  (global_entries_pdc (snd(sat_tlb s)) \\<union> global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}))\")\n    apply (simp only:)\n    apply (thin_tac \"snd(sat_tlb s) \\<union> the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e} = \n                                             (non_global_entries_pdc (snd(sat_tlb s)) \\<union> non_global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) \\<union>  (global_entries_pdc (snd(sat_tlb s)) \\<union> global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}))\")\n    apply (subgoal_tac \"lookup_pdc   (global_entries_pdc (snd(sat_tlb s)))  a v = lookup_pdc (global_entries_pdc (snd(sat_tlb s)) \\<union>  global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) a v \")\n     prefer 2\n     apply (rule saturated_global_subset_lookup_pdc_un_eq[symmetric], simp)\n    apply (drule_tac t = \"non_global_entries_pdc (snd(sat_tlb s)) \\<union> non_global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})\" in  lookup_asid_pdc_hit_union_cases')\n    apply (erule disjE, clarsimp)\n     apply (thin_tac \"lookup_pdc (global_entries_pdc (snd(sat_tlb s)) \\<union> global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) a v = Miss\")\n     apply (subgoal_tac \"lookup_pdc (non_global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) a v = Miss\")\n      apply (drule  lookup_asid_pdc_hit_union_cases')\n      apply (erule disjE, clarsimp)\n       apply (drule_tac x = a in spec, simp, drule_tac x = v in spec)\n       apply (clarsimp simp: non_global_to_global_pdc [symmetric])\n       apply (case_tac \"snd(lookup_from' (snapshot (set_tlb t)) a v)\"; clarsimp?)\n        apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n       apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n         apply (clarsimp simp: ptable_comp_def is_fault_def entry_leq_def)  \n         apply (metis is_fault_def pt_walk_full_no_pdc_fault pt_walk_partial_no_pdc_fault)\n        apply (clarsimp simp: ptable_comp_def is_fault_def entry_leq_def)  \n        apply (metis is_fault_def pt_walk_full_no_pdc_fault)\n       apply (clarsimp simp: ptable_comp_def is_fault_def entry_leq_def)  \n       apply (metis is_fault_def pt_walk_full_no_pdc_fault)\n      apply (erule disjE, clarsimp)\n      apply (clarsimp)\n     apply (rule is_fault_non_global_entries_pdc_miss,simp)\n    apply (erule disjE, clarsimp)\n     apply (thin_tac \"lookup_pdc  (global_entries_pdc (snd(sat_tlb s)) \\<union> global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) a v =  Hit x\")\n     apply (subgoal_tac \"v \\<in> global_set (set_tlb t)\")\n      apply (case_tac \"v \\<in> iset (set_tlb t)\") \n       apply blast\n      apply (subgoal_tac \" lookup_pdc  (snd(sat_tlb s)) (ASID t) v = Hit x \\<or>\n                       lookup_pdc  (snd(sat_tlb s)) (ASID t) v = Incon\")\n       prefer 2\n       apply (metis (no_types, hide_lams)  lookup_pdc_global_hit_order lookup_global_same_for_asids_pdc )\n      apply (erule disjE)\n       apply (clarsimp simp: ) \n  using no_fault_pdc_walk_unequal_asid' apply fastforce\n      apply (clarsimp simp: inconsistent_vaddrs_def) apply force\n     apply (clarsimp simp: global_entries_pdc_def lookup_def asid_of_pdc_def tagged_pdc_entry_set_def entry_set_def global_range_def split: if_split_asm option.splits)\n     apply blast\n    apply (clarsimp)\n    apply (subgoal_tac \"v \\<in> global_set (set_tlb t)\")\n     apply (case_tac \"v \\<in> iset (set_tlb t)\") \n      apply blast\n     apply (subgoal_tac \" lookup_pdc  (snd(sat_tlb s)) (ASID t) v = Hit x \\<or>\n                       lookup_pdc  (snd(sat_tlb s)) (ASID t) v = Incon\")\n      prefer 2\n      apply (metis (no_types, hide_lams)  lookup_pdc_global_hit_order lookup_global_same_for_asids_pdc )\n     apply (erule disjE)\n      apply (clarsimp simp: ) \n  using no_fault_pdc_walk_unequal_asid' apply fastforce\n     apply (clarsimp simp: inconsistent_vaddrs_def) apply force\n    apply (clarsimp simp: global_entries_pdc_def lookup_def asid_of_pdc_def tagged_pdc_entry_set_def entry_set_def global_range_def split: if_split_asm option.splits)\n    apply blast\n   apply (rule pdc_non_global_non_global)\n  apply (rule conjI)\n   apply (clarsimp simp: global_range_def)\n   apply (rule conjI)\n\n    apply (subgoal_tac \"global_entries (fst(sat_tlb s) \\<union> the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}) = \n                         global_entries (fst(sat_tlb s))\")\n     apply (simp only:)\n    apply (subgoal_tac \"global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}) \\<subseteq> \n          global_entries (fst(sat_tlb s))\" )\n     apply (clarsimp simp: global_entries_union)\n     apply blast\n    apply (subgoal_tac \"global_entries (the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}) = \n                       global_entries (the ` {e \\<in> range (pt_walk (ASID s) (MEM s) (TTBR0 s)). \\<not> is_fault e})\")\n     apply (simp only:)\n     apply (clarsimp simp: saturated_def global_entries_def) apply force\n    apply (rule global_entries_ptable_same)\n   apply (subgoal_tac \"global_entries_pdc (snd(sat_tlb s) \\<union> the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}) = \n                         global_entries_pdc (snd(sat_tlb s))\")\n    apply (simp only:)\n   apply (subgoal_tac \"global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}) \\<subseteq> \n          global_entries_pdc (snd(sat_tlb s))\" )\n    apply (clarsimp simp: global_entries_union_pdc)\n    apply blast\n\n   apply (subgoal_tac \"global_entries_pdc (the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e}) = \n                       global_entries_pdc (the ` {e \\<in> range (pdc_walk (ASID s) (MEM s) (TTBR0 s)). \\<not> is_fault e})\")\n    apply (simp only:)\n    apply (clarsimp simp: saturated_def global_entries_pdc_def) apply force\n   apply (rule global_entries_pdc_ptable_same)\n  apply (clarsimp simp: )\n  apply (rule conjI)\n   apply (subgoal_tac \"(fst(sat_tlb s) \\<union> the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e} - global_entries (fst(sat_tlb s) \\<union> the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) =\n                                                                                                non_global_entries (fst(sat_tlb s)\\<union> the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})\")\n    apply (simp only:)\n    apply (thin_tac \"(fst(sat_tlb s) \\<union> the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e} - global_entries (fst(sat_tlb s) \\<union> the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) =\n                                                                                                non_global_entries (fst(sat_tlb s) \\<union> the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})\")\n    apply (case_tac \"aa = ASID t\")\n     apply (thin_tac \" \\<forall>a. a \\<noteq> ASID s \\<longrightarrow>\n            (\\<forall>v. lookup'' (fst (sat_tlb s) - global_entries (fst (sat_tlb s))) a v \\<le> fst (lookup_from' (snapshot (set_tlb t)) a v) \\<and>\n                 lookup_pdc (snd (sat_tlb s) - global_entries_pdc (snd (sat_tlb s))) a v \\<le> snd (lookup_from' (snapshot (set_tlb t)) a v))\")\n     apply (clarsimp)\n     apply (subgoal_tac \"lookup'' (non_global_entries (fst(sat_tlb s) \\<union> the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) (ASID t) v =\n                                                              lookup'' (non_global_entries (fst(sat_tlb s))) (ASID t) v\")\n      apply (simp only:)\n      apply (thin_tac \"lookup'' (non_global_entries (fst(sat_tlb s) \\<union> the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) (ASID s) v =\n                                                              lookup'' (non_global_entries (fst(sat_tlb s))) (ASID s) v\")\n      apply (case_tac \"fst(lookup_from' (snp_upd_cur' (snapshot (set_tlb t)) (iset (set_tlb t)) (MEM s) (TTBR0 s) (ASID t)) (ASID t) v)\"; clarsimp)\n       apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n          apply (clarsimp simp: snp_upd_cur'_def snp_upd_cur_def)\n          apply (subgoal_tac \"v \\<notin> incon_addrs (typ_sat_tlb s)\")\n           apply (thin_tac \"incon_addrs (typ_sat_tlb s) \\<subseteq> iset (set_tlb t)\")\n           apply (clarsimp simp: incon_addrs_def inconsistent_vaddrs_def incoherrent_vaddrs_def is_fault_def)\n           apply (metis lookup_asid_tlb_miss_union lookup_tlb_eq_union_global_non_global lookup_type.exhaust option.simps(3) pt_walk_new_fault_pt_walk_fault')\n          apply blast\n         apply (clarsimp simp: snp_upd_cur'_def snp_upd_cur_def)\n         apply (subgoal_tac \"v \\<notin> incon_addrs (typ_sat_tlb s)\")\n          apply (thin_tac \"incon_addrs (typ_sat_tlb s) \\<subseteq> iset (set_tlb t)\")\n          apply (clarsimp simp: incon_addrs_def inconsistent_vaddrs_def incoherrent_vaddrs_def is_fault_def)\n          apply (metis lookup_asid_tlb_miss_union not_miss_incon_hit_asid_tlb option.discI pt_walk_new_par_fault_pt_walk_fault' tlb_global_non_global_union)\n         apply blast\n        apply (clarsimp simp: snp_upd_cur'_def snp_upd_cur_def)\n        apply (subgoal_tac \"v \\<notin> incon_addrs (typ_sat_tlb s)\")\n         apply (thin_tac \"incon_addrs (typ_sat_tlb s) \\<subseteq> iset (set_tlb t)\")\n         apply (clarsimp simp: incon_addrs_def inconsistent_vaddrs_def incoherrent_vaddrs_def is_fault_def)\n         apply (metis lookup_asid_tlb_miss_union not_miss_incon_hit_asid_tlb option.discI pt_walk_new_par_fault_pt_walk_fault' tlb_global_non_global_union)\n        apply blast       \n       apply (clarsimp simp: snp_upd_cur'_def snp_upd_cur_def)\n       apply (subgoal_tac \"x31 = the (pt_walk (ASID t) (MEM s) (TTBR0 s) v)\")\n        prefer 2\n        apply (simp add: pt_walk_new_no_fault_pt_walk')\n       apply (subgoal_tac \"v \\<notin> incon_addrs (typ_sat_tlb s)\") prefer 2 apply blast\n       apply (thin_tac \"incon_addrs (typ_sat_tlb s) \\<subseteq> iset (set_tlb t)\")\n       apply (clarsimp simp: incon_addrs_def inconsistent_vaddrs_def incoherrent_vaddrs_def is_fault_def)\n       apply (case_tac \"lookup'' (fst(sat_tlb s)) (ASID s) v\"; clarsimp)\n        apply (metis lookup_asid_tlb_miss_union tlb_global_non_global_union)\n       apply (subgoal_tac \"lookup'' (fst(sat_tlb s)) (ASID s) v = lookup'' (fst(sat_tlb s) \\<union> the ` {e \\<in> range (pt_walk (ASID s) (MEM s) (TTBR0 s)). \\<not> is_fault e}) (ASID t) v\")\n        prefer 2\n        apply (clarsimp simp: saturated_def)\n        apply (simp add: sup.absorb1)  \n       apply (simp only:)\n       apply (drule lookup_asid_tlb_hit_union_cases')\n       apply (thin_tac \"(\\<forall>x. lookup_pdc (snd (sat_tlb s)) (ASID s) v \\<noteq> Hit x) \\<or> (\\<exists>y. pdc_walk (ASID s) (MEM s) (TTBR0 s) v = Some y)\")\n       apply (erule disjE, clarsimp)\n        apply (subgoal_tac \"is_fault (pt_walk (ASID s) (MEM s) (TTBR0 s) v)\")\n         apply (clarsimp simp: is_fault_def)\n        apply (rule asid_tlb_lookup_miss_is_fault, simp)\n       apply (erule disjE, clarsimp)\n       apply (clarsimp)\n       apply (subgoal_tac \"x3 = y\") apply clarsimp\n        apply (subgoal_tac \"lookup'' (fst(sat_tlb s)) (ASID s) v = lookup'' (global_entries (fst(sat_tlb s)) \\<union> non_global_entries (fst(sat_tlb s))) (ASID s) v \")\n         apply (simp only:)\n         apply (thin_tac \"  lookup'' (the ` {e \\<in> range (pt_walk (ASID s) (MEM s) (TTBR0 s)). \\<not> is_fault e}) (ASID s) v = Hit y \")\n         apply (drule lookup_asid_tlb_hit_union_cases')   \n         apply (erule disjE, clarsimp)   \n         apply (erule disjE, clarsimp)  \n          apply (drule lookup_non_global_hit_asid_of_not_none, simp)\n         apply (clarsimp) \n         apply (drule lookup_non_global_hit_asid_of_not_none, simp)\n        apply (clarsimp) apply (insert tlb_global_non_global_union [of \"fst(sat_tlb s)\"])\n        apply (simp add: Un_commute)\n       apply (frule asid_tlb_lookup_range_fault_pt_walk)\n       apply (drule_tac x = v in bspec)\n  using lookup_asid_tlb_hit_entry_range apply force\n       apply simp\n      apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n      apply (clarsimp simp: snp_upd_cur'_def snp_upd_cur_def)\n      apply (subgoal_tac \"v \\<notin> incon_addrs (typ_sat_tlb s)\") prefer 2 apply blast\n      apply (thin_tac \"incon_addrs (typ_sat_tlb s) \\<subseteq> iset (set_tlb t)\")\n      apply (clarsimp simp: incon_addrs_def inconsistent_vaddrs_def incoherrent_vaddrs_def is_fault_def)\n      apply (case_tac \"lookup'' (fst(sat_tlb s)) (ASID t) v\"; clarsimp)\n       apply (simp only: non_global_to_global)\n       apply (subgoal_tac \"lookup'' (fst(sat_tlb s) - global_entries (fst(sat_tlb s))) (ASID t) v = Miss\") apply simp\n       apply (rule lookup_miss_minus_miss, simp)\n      apply (subgoal_tac \"x3a = x3\", simp)\n       apply (simp only: non_global_to_global)\n       apply (subgoal_tac \"lookup'' (fst(sat_tlb s) - global_entries (fst(sat_tlb s))) (ASID t) v = Miss \\<or>\n                 lookup'' (fst(sat_tlb s) - global_entries (fst(sat_tlb s))) (ASID t) v = Hit x3\")\n        apply force\n       apply (rule lookup_miss_minus_miss_hit, simp)\n      apply (frule_tac b = v and x = x3a in  saturatd_lookup_hit_no_fault, simp, \n      simp add: is_fault_def, simp)\n  using pt_walk_new_no_fault_pt_walk' apply force\n     apply (rule lookup_non_global_union_asid_unequal, simp)\n    apply (drule_tac x = aa in spec, simp, drule_tac x = v in spec)\n    apply (subgoal_tac \"lookup'' (non_global_entries (fst(sat_tlb s) \\<union> the ` {e \\<in> range (pt_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) aa v =\n                                         lookup'' (non_global_entries (fst(sat_tlb s))) aa v\") \n     apply (simp only: non_global_to_global)\n     apply (clarsimp simp: snp_upd_cur'_def snp_upd_cur_def)\n     apply (clarsimp simp: lookup_from'_def snap_conv'_def split: if_split_asm option.splits)\n    apply (rule lookup_non_global_union_asid_unequal', simp, simp, simp) \n  using non_global_to_global apply auto [1] \n  apply (subgoal_tac \"(snd(sat_tlb s) \\<union> the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e} - global_entries_pdc (snd(sat_tlb s) \\<union> the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) =\n                                                                                                non_global_entries_pdc (snd(sat_tlb s)\\<union> the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})\")\n   apply (simp only:)\n   apply (thin_tac \"(snd(sat_tlb s) \\<union> the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e} - global_entries_pdc (snd(sat_tlb s) \\<union> the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) =\n                                                                                                non_global_entries_pdc (snd(sat_tlb s)\\<union> the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})\")\n   apply (case_tac \"aa = ASID t\")\n    apply (thin_tac \" \\<forall>a. a \\<noteq> ASID s \\<longrightarrow>\n            (\\<forall>v. lookup'' (fst (sat_tlb s) - global_entries (fst (sat_tlb s))) a v \\<le> fst (lookup_from' (snapshot (set_tlb t)) a v) \\<and>\n                 lookup_pdc (snd (sat_tlb s) - global_entries_pdc (snd (sat_tlb s))) a v \\<le> snd (lookup_from' (snapshot (set_tlb t)) a v))\")\n    apply (clarsimp)\n    apply (subgoal_tac \"lookup_pdc (non_global_entries_pdc (snd(sat_tlb s) \\<union> the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) (ASID s) v =\n                                                              lookup_pdc (non_global_entries_pdc (snd(sat_tlb s))) (ASID s) v\")\n     apply (simp only:)\n     apply (thin_tac  \"lookup_pdc (non_global_entries_pdc (snd(sat_tlb s) \\<union> the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) (ASID s) v =\n                                                              lookup_pdc (non_global_entries_pdc (snd(sat_tlb s))) (ASID s) v\")\n     apply (case_tac \"snd(lookup_from' (snp_upd_cur' (snapshot (set_tlb t)) (iset (set_tlb t)) (MEM s) (TTBR0 s) (ASID t)) (ASID t) v)\"; clarsimp)\n      apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n        apply (clarsimp simp: snp_upd_cur'_def snp_upd_cur_def)\n        apply (subgoal_tac \"v \\<notin> incon_addrs (typ_sat_tlb s)\")\n         apply (thin_tac \"incon_addrs (typ_sat_tlb s) \\<subseteq> iset (set_tlb t)\")\n         apply (clarsimp simp: incon_addrs_def inconsistent_vaddrs_def incoherrent_vaddrs_def is_fault_def)\n         apply (metis (full_types) global_entries_pdc_def leq_Miss less_eq_lookup_type lookup_asid_pdc_miss_union lookup_eq_union_global_non_global_pdc lookup_type.exhaust lookup_type.simps(3) non_global_entries_pdc_def\n      not_Some_eq pt_walk_new_fault_pdc_walk_fault' pt_walk_pair_def typ_sat_prim_parameter typ_sat_tlb_def)\n        apply blast\n       apply (clarsimp simp: snp_upd_cur'_def snp_upd_cur_def)\n       apply (subgoal_tac \"v \\<notin> incon_addrs (typ_sat_tlb s)\")\n        apply (thin_tac \"incon_addrs (typ_sat_tlb s) \\<subseteq> iset (set_tlb t)\")\n        apply (clarsimp simp: incon_addrs_def inconsistent_vaddrs_def incoherrent_vaddrs_def is_fault_def)\n\n  subgoal\n  proof -\n    fix v :: vaddr and x2 :: pdc_entry\n    assume a1: \"saturated (typ_sat_tlb s)\"\n    assume a2: \"pt_walk_pair (ASID s) (MEM s) (TTBR0 s) v = Partial_Walk x2\"\n    assume a3: \"asid_of_pdc x2 = None\"\n    assume a4: \"lookup_pdc (snd (sat_tlb s)) (ASID s) v \\<noteq> Incon\"\n    have \"the (Some x2) = x2\"\n      by simp\n    moreover\n    { assume \"lookup_pdc (snd (sat_tlb s)) (ASID s) v = Hit x2\"\n      then have \"\\<exists>P. lookup_pdc (P \\<union> non_global_entries_pdc (snd (sat_tlb s))) (ASID s) v = Hit x2\"\n        by (metis (no_types) lookup_eq_union_global_non_global_pdc)\n      then have \"lookup_pdc (non_global_entries_pdc (snd (sat_tlb s))) (ASID s) v = Miss\"\n        using a3 lookup_asid_pdc_hit_union_cases' lookup_non_global_hit_asid_of_not_none_pdc by blast }\n    ultimately show \"lookup_pdc (non_global_entries_pdc (snd (sat_tlb s))) (ASID s) v = Miss\"\n      using a4 a2 a1 by (metis (no_types) lookup_asid_pdc_miss_union pdc_global_non_global_union pt_walk_new_par_fault_pdc_walk pt_walk_partial_no_pdc_fault saturate_no_icon_miss)\n  qed\n       apply blast\n      apply (clarsimp simp: snp_upd_cur'_def snp_upd_cur_def)\n      apply (subgoal_tac \"x32 = the (pdc_walk (ASID s) (MEM s) (TTBR0 s) v)\")\n       prefer 2\n       apply (simp add: pt_walk_new_no_fault_pdc_walk)\n      apply (subgoal_tac \"v \\<notin> incon_addrs (typ_sat_tlb s)\") prefer 2 apply blast\n      apply (thin_tac \"incon_addrs (typ_sat_tlb s) \\<subseteq> iset (set_tlb t)\")\n      apply (clarsimp simp: incon_addrs_def inconsistent_vaddrs_def incoherrent_vaddrs_def is_fault_def)\n      apply (case_tac \"lookup_pdc (snd(sat_tlb s)) (ASID s) v\"; clarsimp)\n  using pt_walk_full_no_pdc_fault sat_miss_pdc_fault apply fastforce\n      apply (subgoal_tac \"lookup_pdc (snd(sat_tlb s)) (ASID s) v = lookup_pdc (snd(sat_tlb s) \\<union> the ` {e \\<in> range (pdc_walk (ASID s) (MEM s) (TTBR0 s)). \\<not> is_fault e}) (ASID t) v\")\n       prefer 2\n       apply (clarsimp simp: saturated_def)\n       apply (simp add: sup.absorb1)  \n      apply (simp only:)\n      apply (drule lookup_asid_pdc_hit_union_cases')\n      apply (thin_tac \"(\\<forall>x. lookup'' (fst (sat_tlb s)) (ASID s) v \\<noteq> Hit x) \\<or> (\\<exists>y. pt_walk (ASID s) (MEM s) (TTBR0 s) v = Some y)\")\n      apply (erule disjE, clarsimp)\n       apply (subgoal_tac \"is_fault (pdc_walk (ASID s) (MEM s) (TTBR0 s) v)\")\n        apply (clarsimp simp: is_fault_def) \n       apply (rule lookup_pdc_miss_is_fault, simp)\n      apply (erule disjE, clarsimp)\n      apply (clarsimp)\n      apply (subgoal_tac \"x3 = y\") apply clarsimp\n       apply (subgoal_tac \"lookup_pdc (snd(sat_tlb s)) (ASID s) v = lookup_pdc (global_entries_pdc (snd(sat_tlb s)) \\<union> non_global_entries_pdc (snd(sat_tlb s))) (ASID s) v \")\n        apply (simp only:)\n        apply (thin_tac \"  lookup_pdc (the ` {e \\<in> range (pdc_walk (ASID s) (MEM s) (TTBR0 s)). \\<not> is_fault e}) (ASID s) v = Hit y \")\n        apply (drule lookup_asid_pdc_hit_union_cases')   \n        apply (erule disjE, clarsimp)   \n        apply (erule disjE, clarsimp)  \n         apply (drule lookup_non_global_hit_asid_of_not_none_pdc, simp)\n        apply (clarsimp) \n        apply (drule lookup_non_global_hit_asid_of_not_none_pdc, simp)\n       apply (clarsimp) apply (insert pdc_global_non_global_union [of \"snd(sat_tlb s)\"])\n       apply (simp add: Un_commute) \n      apply (frule lookup_pdc_range_fault_pt_walk)\n      apply (drule_tac x = v in bspec)\n  using lookup_asid_pdc_hit_entry_range apply blast\n      apply simp\n     apply (clarsimp simp: lookup_from'_def snap_conv'_def split: pt_walk_typ.splits if_split_asm option.splits)\n       apply (clarsimp simp: snp_upd_cur'_def snp_upd_cur_def)\n       apply (subgoal_tac \"v \\<notin> incon_addrs (typ_sat_tlb s)\") prefer 2 apply blast\n       apply (thin_tac \"incon_addrs (typ_sat_tlb s) \\<subseteq> iset (set_tlb t)\")\n       apply (clarsimp simp: incon_addrs_def inconsistent_vaddrs_def incoherrent_vaddrs_def is_fault_def)\n       apply (case_tac \"lookup_pdc (snd(sat_tlb s)) (ASID t) v\"; clarsimp)\n        apply (simp only: non_global_to_global_pdc)\n        apply (subgoal_tac \"lookup_pdc (snd(sat_tlb s) - global_entries_pdc (snd(sat_tlb s))) (ASID t) v = Miss\") apply simp\n        apply (rule lookup_miss_minus_miss_pdc, simp)\n       apply (subgoal_tac \"x3a = x3\", simp)\n        apply (simp only: non_global_to_global_pdc)\n        apply (subgoal_tac \"lookup_pdc (snd(sat_tlb s) - global_entries_pdc (snd(sat_tlb s))) (ASID t) v = Miss \\<or>\n                 lookup_pdc (snd(sat_tlb s) - global_entries_pdc (snd(sat_tlb s))) (ASID t) v = Hit x3\")\n         apply force\n        apply (rule lookup_miss_minus_miss_hit_pdc, simp)\n       apply (frule_tac b = v and x = x3a in  saturatd_lookup_pdc_hit_no_fault, simp, \n      simp add: is_fault_def, simp)\n       apply (simp add: pt_walk_new_par_fault_pdc_walk)\n      apply (clarsimp simp: snp_upd_cur'_def snp_upd_cur_def)\n      apply (subgoal_tac \"v \\<notin> incon_addrs (typ_sat_tlb s)\") prefer 2 apply blast\n      apply (thin_tac \"incon_addrs (typ_sat_tlb s) \\<subseteq> iset (set_tlb t)\")\n      apply (clarsimp simp: incon_addrs_def inconsistent_vaddrs_def incoherrent_vaddrs_def is_fault_def)\n      apply (case_tac \"lookup_pdc (snd(sat_tlb s)) (ASID t) v\"; clarsimp)\n       apply (simp only: non_global_to_global_pdc)\n       apply (subgoal_tac \"lookup_pdc (snd(sat_tlb s) - global_entries_pdc (snd(sat_tlb s))) (ASID t) v = Miss\") apply simp\n       apply (rule lookup_miss_minus_miss_pdc, simp)\n      apply (subgoal_tac \"x3a = x3\", simp)\n       apply (simp only: non_global_to_global_pdc)\n       apply (subgoal_tac \"lookup_pdc (snd(sat_tlb s) - global_entries_pdc (snd(sat_tlb s))) (ASID t) v = Miss \\<or>\n                 lookup_pdc (snd(sat_tlb s) - global_entries_pdc (snd(sat_tlb s))) (ASID t) v = Hit x3\")\n        apply force\n       apply (rule lookup_miss_minus_miss_hit_pdc, simp)\n      apply (frule_tac b = v and x = x3a in  saturatd_lookup_pdc_hit_no_fault, simp, \n      simp add: is_fault_def, simp)\n  using pt_walk_new_no_fault_pdc_walk apply force\n     apply (clarsimp simp: snp_upd_cur'_def snp_upd_cur_def)\n     apply (subgoal_tac \"v \\<notin> incon_addrs (typ_sat_tlb s)\") prefer 2 apply blast\n     apply (thin_tac \"incon_addrs (typ_sat_tlb s) \\<subseteq> iset (set_tlb t)\")\n     apply (clarsimp simp: incon_addrs_def inconsistent_vaddrs_def incoherrent_vaddrs_def is_fault_def)\n     apply (case_tac \"lookup_pdc (snd(sat_tlb s)) (ASID t) v\"; clarsimp)\n      apply (simp only: non_global_to_global_pdc)\n      apply (subgoal_tac \"lookup_pdc (snd(sat_tlb s) - global_entries_pdc (snd(sat_tlb s))) (ASID t) v = Miss\") apply simp\n      apply (rule lookup_miss_minus_miss_pdc, simp)\n     apply (subgoal_tac \"x3a = x3\", simp)\n      apply (simp only: non_global_to_global_pdc)\n      apply (subgoal_tac \"lookup_pdc (snd(sat_tlb s) - global_entries_pdc (snd(sat_tlb s))) (ASID t) v = Miss \\<or>\n                 lookup_pdc (snd(sat_tlb s) - global_entries_pdc (snd(sat_tlb s))) (ASID t) v = Hit x3\")\n       apply force\n      apply (rule lookup_miss_minus_miss_hit_pdc, simp)\n     apply (frule_tac b = v and x = x3a in  saturatd_lookup_pdc_hit_no_fault, simp, \n      simp add: is_fault_def, simp)\n  using pt_walk_new_no_fault_pdc_walk apply force\n    apply (rule lookup_non_global_union_asid_unequal_pdc, simp)\n   apply (drule_tac x = aa in spec, simp, drule_tac x = v in spec)\n   apply (subgoal_tac \"lookup_pdc (non_global_entries_pdc (snd(sat_tlb s) \\<union> the ` {e \\<in> range (pdc_walk a (MEM s) (TTBR0 s)). \\<not> is_fault e})) aa v =\n                                         lookup_pdc (non_global_entries_pdc (snd(sat_tlb s))) aa v\") \n    apply (simp only: non_global_to_global_pdc)\n    apply (clarsimp simp: snp_upd_cur'_def snp_upd_cur_def)\n    apply (clarsimp simp: lookup_from'_def snap_conv'_def split: if_split_asm option.splits) \n   apply (rule lookup_non_global_union_asid_unequal_pdc', simp, simp, simp) \n  using non_global_to_global_pdc by auto [1] \n\n\n\nend", "meta": {"author": "SEL4PROJ", "repo": "tlb", "sha": "88bb017dd96c3830baed93ba62e45b45050d1417", "save_path": "github-repos/isabelle/SEL4PROJ-tlb", "path": "github-repos/isabelle/SEL4PROJ-tlb/tlb-88bb017dd96c3830baed93ba62e45b45050d1417/TLB_PDC/ARMv7A_Update_ASID_Ref.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.626124191181315, "lm_q2_score": 0.399811640739795, "lm_q1q2_score": 0.25033174018307863}}
{"text": "theory Timeout\nimports Semantics PositiveAccounts QuiescentResult AssetsPreservation\nbegin\n\nfun isClosedAndEmpty :: \"TransactionOutput \\<Rightarrow> bool\" where\n\"isClosedAndEmpty (TransactionOutput txOut) = (txOutContract txOut = Close\n                                               \\<and> accounts (txOutState txOut) = [])\" |\n\"isClosedAndEmpty _ = False\"\n\nlemma max_of_ge : \"ia \\<le> i \\<Longrightarrow> max (i::int) ia = i\"\n  by linarith\n\nlemma reduceStepClose_is_Close : \"reduceContractStep env sta Close = Reduced re wa nsta ncon \\<Longrightarrow> ncon = Close\"\n  apply simp\n  apply (cases \"refundOne (accounts sta)\")\n  apply simp\n  subgoal for a\n    apply (cases \"a\")\n    subgoal for aa b\n      apply (cases \"aa\")\n      by simp\n    done\n  done\n\nlemma reductionLoopClose_is_Close : \"reductionLoop reduced env sta Close x y = ContractQuiescent newReduced re wa nsta ncon \\<Longrightarrow> ncon = Close\"\n  apply (induction reduced env sta Close x y rule:reductionLoop.induct)\n  subgoal for reduced env state warnings payments\n    apply (simp only:reductionLoop.simps)\n    apply (cases \"reduceContractStep env state Close\")\n    subgoal for x11 x12 x13 x14\n      apply (simp del:reductionLoop.simps reduceContractStep.simps add:reduceStepClose_is_Close)\n      using reduceStepClose_is_Close by fastforce\n    apply (simp del:reduceContractStep.simps)\n    apply (simp del:reduceContractStep.simps)\n    done\n  done\n\nlemma reduceClose_is_Close : \"reduceContractUntilQuiescent env sta Close = ContractQuiescent reduced re wa nsta ncon \\<Longrightarrow> ncon = Close\"\n  apply (simp del:reductionLoop.simps)\n  using reductionLoopClose_is_Close by blast\n\nlemma timedOutReduce_only_quiescent_in_close_When :\n  \"minTime sta \\<le> iniTime \\<Longrightarrow>\n   maxTimeContract (When x41 x42 x43) \\<le> iniTime \\<Longrightarrow>\n   iniTime \\<le> endTime \\<Longrightarrow>\n   reduceContractStep \\<lparr>timeInterval = (iniTime, endTime)\\<rparr> (sta\\<lparr>minTime := iniTime\\<rparr>) (When x41 x42 x43) \\<noteq> NotReduced\"\n  apply (induction x41)\n  by simp_all\n\nlemma maxTimeWhen : \"maxTimeContract (When x41 x42 x43) \\<le> iniTime \\<Longrightarrow> x42 \\<le> iniTime\"\n  apply (induction x41 arbitrary:x42 x43 iniTime)\n  by auto\n\nlemma maxTimeNotAmbiguous_reduceStep :\n   \"maxTimeContract cont \\<le> iniTime \\<Longrightarrow>\n    iniTime \\<le> endTime \\<Longrightarrow>\n    reduceContractStep \\<lparr>timeInterval = (iniTime, endTime)\\<rparr> state cont \\<noteq> AmbiguousTimeIntervalReductionError\"\n  apply (cases cont)\n  apply simp\n  apply (auto split:option.split bool.split)\n  subgoal for x21 x22 x23 x24 x25\n    apply (cases \"let moneyToPay = evalValue \\<lparr>timeInterval = (iniTime, endTime)\\<rparr> state x24 in moneyToPay \\<le> 0\")\n    apply simp\n    apply simp\n    apply (cases \"let moneyToPay = evalValue \\<lparr>timeInterval = (iniTime, endTime)\\<rparr> state x24;\n                      balance = case lookup (x21, x23) (accounts state) of None \\<Rightarrow> 0 | Some x \\<Rightarrow> x; paidMoney = min balance moneyToPay\n                  in giveMoney x21 x22 x23 paidMoney (if balance \\<le> moneyToPay then MList.delete (x21, x23) (accounts state)\n                                                      else MList.insert (x21, x23) (balance - paidMoney) (accounts state))\")\n    by (meson ReduceStepResult.distinct(3))\n  using maxTimeWhen apply blast\n  by (meson ReduceStepResult.distinct(3))\n\nlemma maxTimeOnlyDecreases_reduceStepWhen :\n  \"reduceContractStep inte state (When x41 x42 x43) = Reduced wa ef nstate ncont \\<Longrightarrow>\n   maxTimeContract ncont \\<le> maxTimeContract (When x41 x42 x43)\"\n  apply (induction x41 arbitrary: inte state x42 x43 wa ef nstate ncont)\n  apply (smt ReduceStepResult.distinct(1) ReduceStepResult.distinct(3) ReduceStepResult.inject maxTimeContract.simps(4) prod.case_eq_if reduceContractStep.simps(4))\n  by fastforce\n\nlemma maxTimeOnlyDecreases_reduceStep :\n  \"reduceContractStep inte state cont = Reduced wa ef nstate ncont \\<Longrightarrow>\n   maxTimeContract ncont \\<le> maxTimeContract cont\"\n  apply (cases cont)\n  using reduceStepClose_is_Close apply blast\n  apply (simp only:reduceContractStep.simps)\n  subgoal for x21 x22 x23 x24 x25\n    apply (cases \"let moneyToPay = evalValue inte state x24\n                  in evalValue inte state x24 \\<le> 0\")\n    apply simp\n    apply simp\n    apply (cases \"let moneyToPay = evalValue inte state x24; balance = case lookup (x21, x23) (accounts state) of None \\<Rightarrow> 0 | Some x \\<Rightarrow> x;\n                      paidMoney = min balance moneyToPay\n                  in giveMoney x21 x22 x23 paidMoney\n                               (if balance \\<le> moneyToPay then MList.delete (x21, x23) (accounts state)\n                                else MList.insert (x21, x23) (balance - paidMoney) (accounts state))\")\n    by (metis ReduceStepResult.inject eq_iff)\n    apply auto[1]\n  apply (simp add: maxTimeOnlyDecreases_reduceStepWhen)\n  apply (metis ReduceStepResult.inject eq_iff maxTimeContract.simps(6) reduceContractStep.simps(5))\n  by simp\n\nlemma maxTimeNotAmbiguous_reduceLoop : \"maxTimeContract cont \\<le> iniTime \\<Longrightarrow>\n    iniTime \\<le> endTime \\<Longrightarrow>\n    reductionLoop reduced \\<lparr>timeInterval = (iniTime, endTime)\\<rparr> sta cont x y \\<noteq> RRAmbiguousTimeIntervalError\"\n  apply (induction reduced \"\\<lparr>timeInterval = (iniTime, endTime)\\<rparr>\" sta cont x y rule:reductionLoop.induct)\n  subgoal premises facts for reduced state contract warnings payments\n    apply (cases \"reduceContractStep \\<lparr>timeInterval = (iniTime, endTime)\\<rparr> state contract\")\n      apply (simp only:reductionLoop.simps ReduceStepResult.case)\n      apply (simp only:Let_def)\n      using facts(1) facts(2) facts(3) maxTimeOnlyDecreases_reduceStep apply fastforce\n      apply auto[1]\n      by (simp add: facts(2) facts(3) maxTimeNotAmbiguous_reduceStep)\n    done\n\nlemma maxTimeNotAmbiguous : \"maxTimeContract cont \\<le> iniTime \\<Longrightarrow>\n       iniTime \\<le> endTime \\<Longrightarrow>\n       reduceContractUntilQuiescent \\<lparr>timeInterval = (iniTime, endTime)\\<rparr> (sta\\<lparr>minTime := iniTime\\<rparr>) cont \\<noteq> RRAmbiguousTimeIntervalError\"\n  using maxTimeNotAmbiguous_reduceLoop by auto\n\n\nlemma timedOutReduce_only_quiescent_in_close :\n  \"minTime sta \\<le> iniTime \\<Longrightarrow>\n   maxTimeContract c \\<le> iniTime \\<Longrightarrow>\n   iniTime \\<le> endTime \\<Longrightarrow>\n   reduceContractStep \\<lparr>timeInterval = (iniTime, endTime)\\<rparr> (sta\\<lparr>minTime := iniTime\\<rparr>) c = NotReduced \\<Longrightarrow> c = Close\"\n  apply (cases c)\n  apply blast\n  apply (metis reduceContractStep.simps(2) reduceContractStepPayIsQuiescent)\n  apply simp\n  using timedOutReduce_only_quiescent_in_close_When apply blast\n  apply (metis ReduceStepResult.distinct(1) reduceContractStep.simps(5))\n  by simp\n\nlemma timedOutReduceStep_does_not_modify_minTime :\n  \"minTime sta = iniTime \\<Longrightarrow>\n   reduceContractStep \\<lparr>timeInterval = (iniTime, endTime)\\<rparr> sta contract =\n   Reduced warning effect newState ncontract \\<Longrightarrow> minTime newState = iniTime\"\n  apply (cases contract)\n    apply simp\n    apply (cases \"refundOne (accounts sta)\")\n      apply simp\n      subgoal for a\n        apply (cases a)\n        subgoal for aa\n          apply (cases aa)\n          by auto\n        done\n      subgoal for x21 x22 x23 x24\n      apply (cases \"let moneyToPay = evalValue \\<lparr>timeInterval = (iniTime, endTime)\\<rparr> sta x24\n                    in moneyToPay \\<le> 0\")\n      apply auto[1]\n      apply simp\n      apply (cases \"giveMoney x21 x22 x23\n           (min (case lookup (x21, x23) (accounts sta) of None \\<Rightarrow> 0 | Some x \\<Rightarrow> x)\n             (evalValue \\<lparr>timeInterval = (iniTime, endTime)\\<rparr> sta x24))\n           (if (case lookup (x21, x23) (accounts sta) of None \\<Rightarrow> 0 | Some x \\<Rightarrow> x)\n               \\<le> evalValue \\<lparr>timeInterval = (iniTime, endTime)\\<rparr> sta x24\n            then MList.delete (x21, x23) (accounts sta)\n            else MList.insert (x21, x23)\n                  ((case lookup (x21, x23) (accounts sta) of None \\<Rightarrow> 0 | Some x \\<Rightarrow> x) -\n                   min (case lookup (x21, x23) (accounts sta) of None \\<Rightarrow> 0 | Some x \\<Rightarrow> x)\n                    (evalValue \\<lparr>timeInterval = (iniTime, endTime)\\<rparr> sta x24))\n                  (accounts sta))\")\n      by (auto simp:Let_def)\n      apply auto[1]\n    apply (smt ReduceStepResult.distinct(1) ReduceStepResult.distinct(3) ReduceStepResult.inject State.ext_inject State.surjective State.update_convs(4) prod.case_eq_if reduceContractStep.simps(4))\n    apply (smt ReduceStepResult.inject State.ext_inject State.surjective State.update_convs(3) State.update_convs(4) reduceContractStep.simps(5))\n    by simp\n\nlemma timedOutReduceContractLoop_closes_contract : \"minTime sta \\<le> iniTime \\<Longrightarrow>\n    maxTimeContract cont \\<le> iniTime \\<Longrightarrow>\n    iniTime \\<le> endTime \\<Longrightarrow>\n    minTime sta = iniTime \\<Longrightarrow>\n    reductionLoop reduced \\<lparr>timeInterval = (iniTime, endTime)\\<rparr> sta cont x y =\n    ContractQuiescent newReduced warning effect newState ncontract \\<Longrightarrow>\n    ncontract = Close\"\n  apply (induction reduced \"\\<lparr>timeInterval = (iniTime, endTime)\\<rparr>\" sta cont x y arbitrary: warning effect newState ncontract rule:reductionLoop.induct)\n  subgoal for reduced state contract warnings payments warning effect newState ncontract\n    apply (simp only:reductionLoop.simps[of reduced \"\\<lparr>timeInterval = (iniTime, endTime)\\<rparr>\" \"(sta\\<lparr>minTime := iniTime\\<rparr>)\" contract warnings payments])\n    apply (cases \"reduceContractStep \\<lparr>timeInterval = (iniTime, endTime)\\<rparr> state contract\")\n    subgoal for x11 x12 x13 x14\n      apply (simp only:ReduceStepResult.case Let_def)\n      subgoal premises facts\n        apply (rule facts(1)[of x11 x12 x13 x14 \"(if x11 = ReduceNoWarning then warnings else x11 # warnings)\"\n                                \"(case x12 of ReduceNoPayment \\<Rightarrow> payments | ReduceWithPayment payment \\<Rightarrow> payment # payments)\"\n                                warning effect newState ncontract])\n        apply simp\n        apply simp\n        apply simp\n        apply simp\n        using facts(3) facts(7) maxTimeOnlyDecreases_reduceStep apply fastforce\n        apply simp\n        using facts(5) facts(7) timedOutReduceStep_does_not_modify_minTime apply blast\n        by (metis (no_types, lifting) ReduceStepResult.simps(8) facts(6) facts(7) reductionLoop.simps)\n      done\n    using timedOutReduce_only_quiescent_in_close apply fastforce\n    using maxTimeNotAmbiguous_reduceStep by blast\n  done\n\nlemma timedOutReduceContractUntilQuiescent_closes_contract :\n  \"iniTime \\<ge> minTime sta\n   \\<Longrightarrow> iniTime \\<ge> maxTimeContract cont\n   \\<Longrightarrow> endTime \\<ge> iniTime\n   \\<Longrightarrow> reduceContractUntilQuiescent \\<lparr>timeInterval = (max iniTime (minTime sta), endTime)\\<rparr> (sta\\<lparr>minTime := max iniTime (minTime sta)\\<rparr>) cont\n   = ContractQuiescent reduced warning effect newState ncontract \\<Longrightarrow> ncontract = Close\"\n  apply (simp only:reduceContractUntilQuiescent.simps)\n  by (smt State.select_convs(4) State.surjective State.update_convs(4) timedOutReduceContractLoop_closes_contract)\n\nlemma timedOutReduceContractStep_empties_accounts :\n  \"validAndPositive_state sta \\<Longrightarrow>\n    minTime sta \\<le> iniTime \\<Longrightarrow>\n    maxTimeContract cont \\<le> iniTime \\<Longrightarrow>\n    iniTime \\<le> endTime \\<Longrightarrow>\n    reduceContractUntilQuiescent \\<lparr>timeInterval = (iniTime, endTime)\\<rparr> (sta\\<lparr>minTime := iniTime\\<rparr>) cont\n     = ContractQuiescent reduced warning effect newState ncontract \\<Longrightarrow> accounts newState = []\"\n  by (smt State.ext_inject State.surjective State.update_convs(4) allAccountsPositiveState.elims(3) isQuiescent.simps(1) positiveMoneyInAccountOrNoAccountImpliesAllAccountsPositive reduceContractUntilQuiecentIsQuiescent reduceContractUntilQuiescent.simps timedOutReduceContractLoop_closes_contract validAndPositiveImpliesPositive validAndPositiveImpliesValid validAndPositive_state.elims(3) valid_state.simps)\n\ntheorem timedOutTransaction_closes_contract :\n  \"validAndPositive_state sta\n   \\<Longrightarrow> iniTime \\<ge> minTime sta\n   \\<Longrightarrow> iniTime \\<ge> maxTimeContract cont\n   \\<Longrightarrow> endTime \\<ge> iniTime\n   \\<Longrightarrow> accounts sta \\<noteq> [] \\<or> cont \\<noteq> Close\n   \\<Longrightarrow> isClosedAndEmpty (computeTransaction \\<lparr> interval = (iniTime, endTime)\n                                            , inputs = [] \\<rparr> sta cont)\"\n  apply (simp del:validAndPositive_state.simps reduceContractUntilQuiescent.simps add:Let_def)\n  apply (cases \"reduceContractUntilQuiescent \\<lparr>timeInterval = (max iniTime (minTime sta), endTime)\\<rparr> (sta\\<lparr>minTime := max iniTime (minTime sta)\\<rparr>) cont\")\n  apply (simp only:ReduceResult.case list.case ApplyAllResult.case max_of_ge)\n  apply (cases \"cont = Close\")\n  apply (simp del:validAndPositive_state.simps reduceContractUntilQuiescent.simps)\n  apply (metis maxTimeContract.simps(1) reduceContractUntilQuiescent.simps reductionLoopClose_is_Close timedOutReduceContractStep_empties_accounts)\n  apply (simp del:validAndPositive_state.simps reduceContractUntilQuiescent.simps)\n  subgoal for x11 x12 x13 x14 x15\n     apply (rule mp[of x11])\n     apply (metis max.orderE timedOutReduceContractStep_empties_accounts timedOutReduceContractUntilQuiescent_closes_contract)\n    apply (rule mp[of \"x15 = Close\"])\n    apply (metis (no_types, lifting) ReduceResult.inject ReduceStepResult.exhaust ReduceStepResult.simps(8) ReduceStepResult.simps(9) maxTimeNotAmbiguous_reduceStep reduceContractUntilQuiescent.simps reductionLoop.simps reductionLoop_reduce_monotonic)\n    by (metis max.orderE timedOutReduceContractUntilQuiescent_closes_contract)     \n  apply (simp del:validAndPositive_state.simps reduceContractUntilQuiescent.simps)\n  using maxTimeNotAmbiguous by auto\n\ncorollary timeOutTransaction_does_not_fail : \n  assumes \"validAndPositive_state sta\"\n  assumes \"emptyTxAfterDeadline = \\<lparr> interval = (iniTime, endTime), inputs = [] \\<rparr>\"\n  assumes \"iniTime \\<ge> minTime sta\"\n      and \"iniTime \\<ge> maxTimeContract cont\"\n      and \"endTime \\<ge> iniTime\" \n  assumes \"accounts sta \\<noteq> [] \\<or> cont \\<noteq> Close\"\n    shows \"\\<exists>txOut. computeTransaction emptyTxAfterDeadline sta cont = TransactionOutput txOut\"\n  using assms by (meson Timeout.isClosedAndEmpty.elims(2)  timedOutTransaction_closes_contract)\n\ntheorem timeOutTransaction_closes_contract2 :\n  \"validAndPositive_state sta\n   \\<Longrightarrow> accounts sta \\<noteq> [] \\<or> cont \\<noteq> Close\n   \\<Longrightarrow> \\<exists> inp . isClosedAndEmpty (computeTransaction inp sta cont)\"\n  by (meson not_less not_less_iff_gr_or_eq timedOutTransaction_closes_contract)\n\ntheorem timedOutTransaction_preserves_assets :\n  assumes \"validAndPositive_state sta\"\n  assumes \"emptyTxAfterDeadline = \\<lparr> interval = (iniTime, endTime), inputs = [] \\<rparr>\"\n  assumes \"iniTime \\<ge> minTime sta\"\n      and \"iniTime \\<ge> maxTimeContract cont\"\n      and \"endTime \\<ge> iniTime\"\n  assumes \"accounts sta \\<noteq> [] \\<or> cont \\<noteq> Close\"\n  assumes \"computeTransaction emptyTxAfterDeadline sta cont = TransactionOutput txOut\"\n  shows \"assetsInState sta = assetsInExternalPayments (txOutPayments txOut)\"\nproof -\n  note assms\n  moreover have \"assetsInState sta + assetsInTransaction emptyTxAfterDeadline \n          = assetsInState (txOutState txOut) + assetsInExternalPayments (txOutPayments txOut)\"\n    using computeTransaction_preserves_assets calculation by presburger\n  moreover have \"accounts (txOutState txOut) = []\"\n    using calculation by (metis Timeout.isClosedAndEmpty.simps(1) timedOutTransaction_closes_contract)\n  ultimately show ?thesis by auto\nqed\n\nend\n", "meta": {"author": "input-output-hk", "repo": "marlowe", "sha": "d2f7b3108894b7c3169c71214f1a2772716544bf", "save_path": "github-repos/isabelle/input-output-hk-marlowe", "path": "github-repos/isabelle/input-output-hk-marlowe/marlowe-d2f7b3108894b7c3169c71214f1a2772716544bf/isabelle/Core/Timeout.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6261241772283035, "lm_q2_score": 0.399811640739795, "lm_q1q2_score": 0.2503317346045022}}
{"text": "(*  Title:      HOL/Library/Rewrite.thy\n    Author:     Christoph Traut, Lars Noschinski, TU Muenchen\n\nProof method \"rewrite\" with support for subterm-selection based on patterns.\n*)\n\ntheory Rewrite\nimports Main\nbegin\n\nconsts rewrite_HOLE :: \"'a::{}\"  (\"\\<hole>\")\n\nlemma eta_expand:\n  fixes f :: \"'a::{} \\<Rightarrow> 'b::{}\"\n  shows \"f \\<equiv> \\<lambda>x. f x\" .\n\nlemma rewr_imp:\n  assumes \"PROP A \\<equiv> PROP B\"\n  shows \"(PROP A \\<Longrightarrow> PROP C) \\<equiv> (PROP B \\<Longrightarrow> PROP C)\"\n  apply (rule Pure.equal_intr_rule)\n  apply (drule equal_elim_rule2[OF assms]; assumption)\n  apply (drule equal_elim_rule1[OF assms]; assumption)\n  done\n\nlemma imp_cong_eq:\n  \"(PROP A \\<Longrightarrow> (PROP B \\<Longrightarrow> PROP C) \\<equiv> (PROP B' \\<Longrightarrow> PROP C')) \\<equiv>\n    ((PROP B \\<Longrightarrow> PROP A \\<Longrightarrow> PROP C) \\<equiv> (PROP B' \\<Longrightarrow> PROP A \\<Longrightarrow> PROP C'))\"\n  apply (intro Pure.equal_intr_rule)\n     apply (drule (1) cut_rl; drule Pure.equal_elim_rule1 Pure.equal_elim_rule2; assumption)+\n   apply (drule Pure.equal_elim_rule1 Pure.equal_elim_rule2; assumption)+\n  done\n\nML_file \\<open>cconv.ML\\<close>\nML_file \\<open>rewrite.ML\\<close>\n\nend\n", "meta": {"author": "landonf", "repo": "isabelle-legacy", "sha": "e40f3ca7e9a42bb91e57fd15f969388e6e83f692", "save_path": "github-repos/isabelle/landonf-isabelle-legacy", "path": "github-repos/isabelle/landonf-isabelle-legacy/isabelle-legacy-e40f3ca7e9a42bb91e57fd15f969388e6e83f692/src/HOL/Library/Rewrite.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.542863297964157, "lm_q2_score": 0.46101677931231594, "lm_q1q2_score": 0.2502690892342978}}
{"text": "(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: BSD-2-Clause\n *)\n\n(*\n * This is a purely theoretical theory containing proofs\n * that the whileLoop rules in \"WhileLoopRules\" are complete.\n *\n * You probably don't care about this.\n *)\ntheory WhileLoopRulesCompleteness\nimports WhileLoopRules\nbegin\n\nlemma whileLoop_rule_strong_complete:\n  \"(\\<lbrace> \\<lambda>s'. s' = s \\<rbrace> whileLoop C B r \\<lbrace> \\<lambda>r s. (r, s) \\<in> fst Q \\<rbrace>\n        \\<and> (\\<forall>r'' s''. (r'', s'') \\<in> fst Q \\<longrightarrow> \\<lbrace> \\<lambda>s'. s' = s \\<rbrace> whileLoop C B r \\<exists>\\<lbrace> \\<lambda>r s. r = r'' \\<and> s = s'' \\<rbrace>)\n        \\<and> (snd Q \\<longrightarrow> snd (whileLoop C B r s))\n        \\<and> (\\<not> snd Q \\<longrightarrow> \\<lbrace> \\<lambda>s'. s' = s \\<rbrace> whileLoop C B r \\<lbrace> \\<lambda>_ _. True \\<rbrace>!))\n    = (whileLoop C B r s = Q)\"\n  apply (rule iffI)\n   apply (rule whileLoop_rule_strong, auto)[1]\n  apply (clarsimp simp: valid_def exs_valid_def validNF_alt_def)\n  apply force\n  done\n\nlemma valid_whileLoop_complete:\n  \"(\\<exists>I.\n       (\\<forall>s. P r s \\<longrightarrow> I r s )\n     \\<and> (\\<forall>r. \\<lbrace> \\<lambda>s. I r s \\<and> C r s \\<rbrace> B r \\<lbrace> I \\<rbrace>)\n     \\<and> (\\<forall>r s. ( I r s \\<and> \\<not> C r s ) \\<longrightarrow> Q r s))\n    = \\<lbrace> P r \\<rbrace> whileLoop C B r \\<lbrace> Q \\<rbrace>\"\n  apply (rule iffI)\n   apply clarsimp\n   apply (rule_tac I=I in valid_whileLoop, auto)[1]\n  apply (rule exI [where x=\"\\<lambda>r s. \\<lbrace> \\<lambda>s'. s' = s \\<rbrace> whileLoop C B r \\<lbrace> Q \\<rbrace>\"])\n  apply (intro conjI)\n    apply (clarsimp simp: valid_def)\n   apply (subst (2) valid_def)\n   apply clarsimp\n   apply (subst (asm) (2) whileLoop_unroll)\n   apply (case_tac \"C a b\")\n    apply (clarsimp simp: valid_def bind_def' Bex_def condition_def split: if_split_asm)\n    apply force\n   apply (clarsimp simp: valid_def bind_def' Bex_def condition_def split: if_split_asm)\n   apply force\n  apply (subst whileLoop_unroll)\n  apply (clarsimp simp: valid_def bind_def' condition_def return_def)\n  done\n\nlemma validNF_whileLoop_complete:\n  \"(\\<exists>I R.\n       (\\<forall>s. P r s \\<longrightarrow> I r s )\n     \\<and> (\\<forall>r s. \\<lbrace>\\<lambda>s'. I r s' \\<and> C r s' \\<and> s' = s\\<rbrace> B r \\<lbrace>\\<lambda>r' s'. I r' s' \\<and> ((r', s'), r, s) \\<in> R\\<rbrace>!)\n     \\<and> (wf R)\n     \\<and> (\\<forall>r s. ( I r s \\<and> \\<not> C r s ) \\<longrightarrow> Q r s))\n    = \\<lbrace> P r \\<rbrace> whileLoop C B r \\<lbrace> Q \\<rbrace>!\"\n  (is \"(\\<exists>I R. ?LHS I R) = ?RHS\")\nproof (rule iffI)\n  assume lhs: \"\\<exists>I R. ?LHS I R\"\n\n  obtain I R where \"?LHS I R\"\n    using lhs\n    by auto\n\n  thus ?RHS\n    by (rule_tac validNF_whileLoop [where I=I and R=R], auto)\nnext\n  assume loop: \"?RHS\"\n\n  define I where \"I \\<equiv> \\<lambda>r s. \\<lbrace> \\<lambda>s'. s' = s \\<rbrace> whileLoop C B r \\<lbrace> \\<lambda>r s. Q r s \\<rbrace>!\"\n  define R where \"R \\<equiv> {(x, y). C (fst y) (snd y) \\<and> x \\<in> fst (B (fst y) (snd y)) \\<and>\n                                whileLoop_terminates C B (fst y) (snd y)}\"\n\n  have \"wf R\"\n    using R_def whileLoop_terminates_wf\n    by auto\n\n  have start: \"\\<And>s. P r s \\<Longrightarrow> I r s\"\n    by (metis (full_types) I_def loop validNF_weaken_pre)\n\n  have fin: \"\\<And>r s. \\<lbrakk> I r s; \\<not> C r s \\<rbrakk> \\<Longrightarrow> Q r s\"\n    apply (unfold I_def)\n    apply (subst (asm) whileLoop_unroll)\n    apply (clarsimp simp: condition_def bind_def'\n                     validNF_alt_def return_def)\n    done\n\n  have step: \"\\<And>r s. \\<lbrace>\\<lambda>s'. I r s' \\<and> C r s' \\<and> s' = s\\<rbrace> B r\n                   \\<lbrace>\\<lambda>r' s'. I r' s' \\<and> ((r', s'), r, s) \\<in> R\\<rbrace>!\"\n             (is \"\\<And>r s. \\<lbrace> ?pre r s \\<rbrace> B r \\<lbrace> ?post r s \\<rbrace>!\")\n  proof -\n    have inv_step:\n        \"\\<And>r s r' s'. \\<lbrakk> I r s; C r s; (r', s') \\<in> fst (B r s) \\<rbrakk> \\<Longrightarrow> I r' s'\"\n      apply (clarsimp simp: I_def)\n      apply (subst (asm) whileLoop_unroll)\n      apply (clarsimp simp: condition_def bind_def' validNF_alt_def)\n      apply force\n      done\n\n    have R_step:\n        \"\\<And>r s r' s'. \\<lbrakk> I r s; C r s; (r', s') \\<in> fst (B r s) \\<rbrakk> \\<Longrightarrow> ((r', s'), (r, s)) \\<in> R\"\n      apply (clarsimp simp: I_def R_def)\n      apply (clarsimp simp: validNF_alt_def whileLoop_def)\n      done\n\n    show \"\\<And>r s. ?thesis r s\"\n      apply rule\n       apply (clarsimp simp: valid_def inv_step R_step)\n      apply (clarsimp simp: no_fail_def I_def validNF_alt_def)\n      apply (drule (1) snd_whileLoop_first_step)\n      apply simp\n      done\n    qed\n\n  show \"\\<exists>I' R'. ?LHS I' R'\"\n    using \\<open>wf R\\<close> start fin step\n    by blast\nqed\n\n\nlemma snd_whileLoop_complete:\n  shows \"snd (whileLoop C B r s) =\n              (\\<exists>I. I r s \\<and> C r s \\<and>\n                   (\\<forall>r. \\<lbrace> \\<lambda>s. I r s \\<and> C r s \\<and> \\<not> snd (B r s) \\<rbrace>\n                            B r \\<exists>\\<lbrace> \\<lambda>r s. C r s \\<and> I r s \\<rbrace>))\"\n  (is \"?LHS = ?RHS\")\nproof (rule iffI)\n  assume \"?LHS\"\n  thus \"?RHS\"\n    apply (clarsimp simp: whileLoop_def)\n    apply (erule disjE)\n     apply (rule exI [where x=\"\\<lambda>r s. (Some (r, s), None) \\<in> whileLoop_results C B\"])\n     apply (intro conjI)\n       apply simp\n      apply (metis Pair_inject whileLoop_results_cases_fail)\n     apply (clarsimp simp: exs_valid_def)\n     apply (erule whileLoop_results_cases_fail, fastforce)\n     apply clarsimp\n     apply (erule bexI [rotated])\n     apply clarsimp\n     apply (metis fst_conv snd_conv whileLoop_results_cases_fail)\n    apply (rule exI [where x=\"\\<lambda>r s. \\<not> whileLoop_terminates C B r s\"])\n    apply clarsimp\n    apply (rule conjI)\n     apply (subst (asm)  whileLoop_terminates_simps)\n     apply clarsimp\n    apply (clarsimp simp: exs_valid_def)\n    apply (subst (asm) (2)  whileLoop_terminates_simps)\n    apply clarsimp\n    apply (erule bexI [rotated])\n    apply clarsimp\n    apply (subst (asm) (2)  whileLoop_terminates_simps)\n    apply clarsimp\n    done\nnext\n  assume \"?RHS\"\n  thus \"?LHS\"\n    apply clarsimp\n    apply (erule (1) snd_whileLoop)\n    apply force\n    done\nqed\n\nlemma not_snd_whileLoop_complete:\n  shows \"(\\<not> snd (whileLoop C B r s)) = (\\<exists>I R . I r s \\<and> wf R \\<and>\n           (\\<forall>r s r' s'. (I r s \\<and> C r s \\<and> (r', s') \\<in> fst (B r s)) \\<longrightarrow> I r' s')\n           \\<and> (\\<forall>r s. I r s \\<and> C r s \\<longrightarrow> \\<not> snd (B r s))\n           \\<and> (\\<forall>r s r' s'. I r s \\<and> C r s \\<and> (r', s') \\<in> fst (B r s) \\<longrightarrow> ((r', s'), (r, s)) \\<in> R))\"\n   (is \"?LHS = ?RHS\")\nproof (rule iffI)\n  assume \"?RHS\"\n  thus \"?LHS\"\n    apply (clarsimp)\n    apply (erule make_pos_goal, rule not_snd_whileLoop)\n      apply assumption\n     defer\n     apply assumption\n    apply (clarsimp simp: validNF_def no_fail_def valid_def)\n    done\nnext\n  assume no_fail: \"?LHS\"\n  define I where \"I \\<equiv> \\<lambda>r s. \\<not> snd (whileLoop C B r s)\"\n  define R where \"R \\<equiv> {((r', s'), (r, s)). C r s \\<and> (r', s') \\<in> fst (B r s) \\<and>\n                                            whileLoop_terminates C B r s}\"\n\n  have \"I r s\"\n    by (clarsimp simp: I_def no_fail)\n\n  moreover have \"wf R\"\n    apply (rule wf_subset [OF whileLoop_terminates_wf [where C=C and B=B]])\n    apply (clarsimp simp: R_def)\n    done\n\n  moreover have \"\\<And>r s r' s'. \\<lbrakk> I r s; C r s; (r', s') \\<in> fst (B r s) \\<rbrakk> \\<Longrightarrow> I r' s'\"\n    apply (clarsimp simp: I_def whileLoop_def)\n    apply (rule conjI)\n     apply (metis whileLoop_results_simps)\n    apply (erule whileLoop_terminates_cases)\n     apply clarsimp\n    apply fastforce\n    done\n\n  moreover have \"\\<And>r s. \\<lbrakk> I r s; C r s \\<rbrakk> \\<Longrightarrow> \\<not> snd (B r s)\"\n    apply (clarsimp simp: I_def)\n    apply (subst (asm) whileLoop_unroll)\n    apply (clarsimp simp: condition_true bind_def)\n    done\n\n  moreover have \"\\<And>r s r' s'. \\<lbrakk> I r s; C r s; (r', s') \\<in> fst (B r s) \\<rbrakk> \\<Longrightarrow> ((r', s'), (r, s)) \\<in> R\"\n    apply (clarsimp simp: R_def)\n    apply (metis I_def snd_conv whileLoop_def)\n    done\n\n  ultimately show ?RHS\n    by (metis (mono_tags))\nqed\n\n\nfun valid_path\nwhere\n    \"valid_path C B [] = False\"\n  | \"valid_path C B [x] = (\\<not> C (fst x) (snd x))\"\n  | \"valid_path C B (x#y#xs) = ((C (fst x) (snd x) \\<and> y \\<in> fst (B (fst x) (snd x)) \\<and> valid_path C B (y#xs)))\"\n\ndefinition \"shortest_path_length C B x Q \\<equiv>\n        (LEAST n. \\<exists>l. valid_path C B l \\<and> hd l = x \\<and> Q (fst (last l)) (snd (last l)) \\<and> length l = n)\"\n\nlemma shortest_path_length_same [simp]:\n  \"\\<lbrakk> \\<not> C (fst a) (snd a); Q (fst a) (snd a) \\<rbrakk> \\<Longrightarrow> shortest_path_length C B a Q = 1\"\n  apply (clarsimp simp: shortest_path_length_def)\n  apply (rule Least_equality)\n   apply (rule exI [where x=\"[a]\"])\n   apply clarsimp\n  apply (case_tac \"y = 0\")\n   apply clarsimp\n  apply clarsimp\n  done\n\nlemma valid_path_simp:\n  \"valid_path C B l =\n        (((\\<exists>r s. l = [(r, s)] \\<and> \\<not> C r s) \\<or>\n              (\\<exists>r s r' s' xs. l = (r, s)#(r', s')#xs \\<and> C r s \\<and> (r', s') \\<in> fst (B r s) \\<and> valid_path C B ((r', s')#xs))))\"\n  apply (case_tac l)\n   apply clarsimp\n  apply (case_tac list)\n   apply clarsimp\n  apply clarsimp\n  done\n\nlemma path_exists:\n  assumes path: \"\\<lbrace> \\<lambda>s'. s' = s \\<rbrace> whileLoop C B r \\<exists>\\<lbrace> Q \\<rbrace>\"\n  shows \"\\<exists>l. valid_path C B l \\<and> hd l = (r, s) \\<and> Q (fst (last l)) (snd (last l))\"\nproof -\n  {\n    fix r' s'\n    assume x: \"(r', s') \\<in> fst (whileLoop C B r s)\"\n    assume y: \"Q r' s'\"\n    have ?thesis\n      using x y\n      apply (induct rule: in_whileLoop_induct)\n       apply (rule_tac x=\"[(r,s)]\" in exI)\n       apply clarsimp\n      apply clarsimp\n      apply (case_tac l)\n       apply clarsimp\n      apply (rule_tac x=\"(r, s)#l\" in exI)\n      apply clarsimp\n      done\n  }\n\n  thus ?thesis\n    using path\n    by (clarsimp simp: exs_valid_def)\nqed\n\nlemma shortest_path_exists:\n  \"\\<lbrakk> \\<lbrace> \\<lambda>s'. s' = s \\<rbrace> whileLoop C B r \\<exists>\\<lbrace> Q \\<rbrace> \\<rbrakk> \\<Longrightarrow>\n       \\<exists>l. valid_path C B l\n              \\<and> shortest_path_length C B (r, s) Q = length l\n              \\<and> hd l = (r, s)\n              \\<and> Q (fst (last l)) (snd (last l))\"\n  apply (frule path_exists)\n  apply (clarsimp simp: simp: shortest_path_length_def)\n  apply (rule LeastI2_ex)\n   apply force\n  apply force\n  done\n\nlemma shortest_path_is_shortest:\n  \"\\<lbrakk> valid_path C B l; Q (fst (last l)) (snd (last l)) \\<rbrakk> \\<Longrightarrow> shortest_path_length C B (hd l) Q \\<le> length l\"\n  apply (clarsimp simp: simp: shortest_path_length_def)\n  apply (rule Least_le)\n  apply force\n  done\n\nlemma valid_path_implies_exs_valid_whileLoop:\n    \"valid_path C B l \\<Longrightarrow> \\<lbrace> \\<lambda>s. s = snd (hd l) \\<rbrace> whileLoop C B (fst (hd l)) \\<exists>\\<lbrace> \\<lambda>r s. (r, s) = last l  \\<rbrace>\"\n  apply (induct l)\n   apply clarsimp\n  apply clarsimp\n  apply rule\n   apply clarsimp\n   apply (subst whileLoop_unroll)\n   apply (clarsimp simp: condition_def bind_def' exs_valid_def return_def)\n  apply clarsimp\n  apply (subst whileLoop_unroll)\n  apply (clarsimp simp: condition_def bind_def' exs_valid_def return_def)\n  apply rule\n   apply (clarsimp split: prod.splits)\n   apply (case_tac l)\n    apply clarsimp\n   apply (clarsimp split del: if_split)\n   apply (erule bexI [rotated])\n   apply clarsimp\n  apply clarsimp\n  apply (case_tac l, auto)\n  done\n\nlemma shortest_path_gets_shorter:\n  \"\\<lbrakk> \\<lbrace> \\<lambda>s'. s' = s \\<rbrace> whileLoop C B r \\<exists>\\<lbrace> Q \\<rbrace>;\n       C r s \\<rbrakk>\n     \\<Longrightarrow> \\<exists>(r', s') \\<in> fst (B r s).\n                shortest_path_length C B (r', s') Q < shortest_path_length C B (r, s) Q\n                 \\<and> \\<lbrace> \\<lambda>s. s = s' \\<rbrace> whileLoop C B r' \\<exists>\\<lbrace> Q \\<rbrace>\"\n  apply (drule shortest_path_exists)\n  apply clarsimp\n  apply (case_tac l)\n   apply clarsimp\n  apply (case_tac list)\n   apply clarsimp\n  apply (rule_tac x=\"aa\" in bexI)\n   apply clarify\n   apply (simp only: valid_path.simps, clarify)\n   apply (frule shortest_path_is_shortest [where Q=Q])\n    apply simp\n   apply clarsimp\n   apply (drule valid_path_implies_exs_valid_whileLoop)\n   apply (clarsimp simp: exs_valid_def)\n   apply (erule bexI [rotated])\n   apply (clarsimp split: if_split_asm)\n  apply clarsimp\n  done\n\nlemma exs_valid_whileLoop_complete:\n   \"(\\<exists>T R.\n         (\\<forall>s. P s \\<longrightarrow> T r s)\n         \\<and> (\\<forall>r s0. \\<lbrace> \\<lambda>s. T r s \\<and> C r s \\<and> s = s0 \\<rbrace> B r\n                            \\<exists>\\<lbrace> \\<lambda>r' s'. T r' s' \\<and> ((r', s'), (r, s0)) \\<in> R \\<rbrace>)\n         \\<and> wf R\n         \\<and> (\\<forall>r s. (T r s \\<and> \\<not> C r s) \\<longrightarrow> Q r s))\n      = (\\<lbrace> P \\<rbrace> whileLoop C B r \\<exists>\\<lbrace> Q \\<rbrace>)\"\n  (is \"(\\<exists>T R. ?LHS T R) = ?RHS\")\nproof (rule iffI)\n  assume lhs: \"\\<exists>T R. ?LHS T R\"\n  obtain T R where TR: \"?LHS T R\"\n    using lhs\n    by blast\n\n  show \"?RHS\"\n    by (rule exs_valid_whileLoop [where T=T and R=R], auto simp: TR)\nnext\n  assume rhs: \"?RHS\"\n\n  define I where \"I \\<equiv> \\<lambda>r s. \\<lbrace> \\<lambda>s'. s' = s \\<rbrace> whileLoop C B r \\<exists>\\<lbrace> Q \\<rbrace>\"\n\n  define R where \"R \\<equiv> measure (\\<lambda>(r, s). shortest_path_length C B (r, s) Q)\"\n\n  have P_s: \"\\<And>s. P s \\<Longrightarrow> I r s\"\n    using rhs\n    by (clarsimp simp: I_def exs_valid_def)\n\n  have inv_holds: \"\\<And>r s. \\<lbrakk> I r s; C r s \\<rbrakk> \\<Longrightarrow>\n              \\<exists>(r', s') \\<in> fst (B r s). I r' s' \\<and> ((r', s'), r, s) \\<in> R\"\n    apply (clarsimp simp: I_def R_def)\n    apply (frule (1) shortest_path_gets_shorter)\n    apply clarsimp\n    apply (rule bexI [rotated], assumption)\n    apply clarsimp\n    done\n\n  have wf_R: \"wf R\"\n    by (clarsimp simp: R_def)\n\n  have last_step: \"\\<And>r s. \\<lbrakk> I r s; \\<not> C r s \\<rbrakk> \\<Longrightarrow> Q r s\"\n    apply (clarsimp simp: I_def exs_valid_def)\n    apply (metis in_return whileLoop_cond_fail)\n    done\n\n  show \"\\<exists>I R. ?LHS I R\"\n    apply (rule exI [where x=I])\n    apply (rule exI [where x=R])\n    using P_s inv_holds wf_R last_step\n    apply (clarsimp simp: exs_valid_def)\n    done\nqed\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/lib/Monads/WhileLoopRulesCompleteness.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632831725052, "lm_q2_score": 0.46101677931231594, "lm_q1q2_score": 0.2502690824150981}}
{"text": "theory Simulation\n  imports Semantics\nbegin\n\ncontext env begin\n\ndefinition\n  \"simulation\" :: \"'b \\<Rightarrow> ('a, 'b, 'c) psi \\<Rightarrow>\n                   ('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set \\<Rightarrow> \n                   ('a, 'b, 'c) psi \\<Rightarrow> bool\" (\"_ \\<rhd> _ \\<leadsto>[_] _\" [80, 80, 80, 80] 80)\nwhere\n  \"\\<Psi> \\<rhd> P \\<leadsto>[Rel] Q \\<equiv> \\<forall>\\<alpha> \\<pi> Q'. \\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> Q' \\<longrightarrow> bn \\<alpha> \\<sharp>* \\<Psi> \\<longrightarrow> bn \\<alpha> \\<sharp>* P \\<longrightarrow> (\\<exists>\\<pi>' P'. \\<Psi> \\<rhd> P \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> P' \\<and> (\\<Psi>, P', Q') \\<in> Rel)\"\n\nabbreviation\n  simulation_nil_judge (\"_ \\<leadsto>[_] _\" [80, 80, 80] 80) where \"P \\<leadsto>[Rel] Q \\<equiv> S_bottom' \\<rhd> P \\<leadsto>[Rel] Q\"\n\nlemma simI[consumes 1, case_names c_sim]:\n  fixes \\<Psi>   :: 'b\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   Rel :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q   :: \"('a, 'b, 'c) psi\"\n  and   C   :: \"'d::fs_name\"\n\n  assumes Eqvt: \"eqvt Rel\"\n  and     Sim: \"\\<And>\\<pi> \\<alpha> Q'. \\<lbrakk>\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> Q'; bn \\<alpha> \\<sharp>* P; bn \\<alpha> \\<sharp>* Q; bn \\<alpha> \\<sharp>* \\<pi>; bn \\<alpha>  \\<sharp>* \\<Psi>; distinct(bn \\<alpha>);\n                         bn \\<alpha> \\<sharp>* (subject \\<alpha>); bn \\<alpha> \\<sharp>* C\\<rbrakk> \\<Longrightarrow> \\<exists>\\<pi>' P'. \\<Psi> \\<rhd> P \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> P' \\<and> (\\<Psi>, P', Q') \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> P \\<leadsto>[Rel] Q\"\nproof(auto simp add: simulation_def)\n  fix \\<pi> \\<alpha> Q'\n  assume \"\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> Q'\" and \"bn \\<alpha> \\<sharp>* \\<Psi>\" and \"bn \\<alpha> \\<sharp>* P\"\n  thus \"\\<exists>\\<pi>' P'. \\<Psi> \\<rhd> P \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> P' \\<and> (\\<Psi>, P', Q') \\<in> Rel\"\n  proof(nominal_induct \\<alpha> rule: action.strong_induct)\n    case(In M N)\n    thus ?case by(rule_tac Sim) auto\n  next\n    case(Out M xvec N)\n    moreover {\n      fix M xvec N Q'\n      assume \"(xvec::name list) \\<sharp>* \\<Psi>\" and \"xvec \\<sharp>* P\"\n      obtain p where xvec_fresh_psi: \"((p::name prm) \\<bullet> (xvec::name list)) \\<sharp>* \\<Psi>\"\n                 and xvec_freshM: \"(p \\<bullet> xvec) \\<sharp>* (M::'a)\"\n                 and xvec_freshN: \"(p \\<bullet> xvec) \\<sharp>* (N::'a)\"\n                 and xvec_freshP: \"(p \\<bullet> xvec) \\<sharp>* P\"\n                 and xvec_freshQ: \"(p \\<bullet> xvec) \\<sharp>* Q\"\n                 and xvec_fresh_pi: \"(p \\<bullet> xvec) \\<sharp>* \\<pi>\"\n                 and xvec_freshQ': \"(p \\<bullet> xvec) \\<sharp>* (Q'::('a, 'b, 'c) psi)\"\n                 and xvec_freshC: \"(p \\<bullet> xvec) \\<sharp>* C\"\n                 and xvec_freshxvec: \"(p \\<bullet> xvec) \\<sharp>* xvec\"\n                 and S: \"(set p) \\<subseteq> (set xvec) \\<times> (set(p \\<bullet> xvec))\"\n                 and dpr: \"distinct_perm p\"\n\tby(rule_tac xvec=xvec and c=\"(\\<Psi>, M, Q, N, P, Q', \\<pi>, xvec, C)\" in name_list_avoiding)\n          (auto simp add: eqvts fresh_star_prod)\n\n      from `(p \\<bullet> xvec) \\<sharp>* M` `distinct_perm p` have \"xvec \\<sharp>* (p \\<bullet> M)\"\n\tby(subst pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst, where pi=p, symmetric]) simp\n\n      assume Trans: \"\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'\"\n      with xvec_freshN xvec_freshQ' S\n      have \"\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ M\\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> (p \\<bullet> Q')\"\n\tby(simp add: bound_output_chain_alpha'' residual_inject)\n      moreover hence \"distinct(p \\<bullet> xvec)\"  by(auto dest: bound_output_distinct)\n      \n      moreover note xvec_fresh_psi xvec_freshP xvec_freshQ xvec_freshM xvec_freshC xvec_fresh_pi\n      ultimately obtain \\<pi>' P' where P_trans: \"\\<Psi> \\<rhd> P \\<longmapsto>\\<pi>' @ M\\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> P'\"\n                            and P'_rel_q': \"(\\<Psi>, P', p \\<bullet> Q') \\<in> Rel\"\n\tby(drule_tac Sim) auto\n      hence \"(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P) \\<longmapsto>(p\\<bullet>\\<pi>') @ (p \\<bullet> (M\\<lparr>\\<nu>*(p \\<bullet> xvec)\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> P'))\"\n\tby(rule_tac semantics.eqvt)\n      moreover from xvec_freshP `xvec \\<sharp>* P` P_trans\n      have \"xvec \\<sharp>* \\<pi>'\"  \"(p\\<bullet>xvec) \\<sharp>* \\<pi>'\"\n        by(auto intro: trans_fresh_provenance)\n      moreover note `xvec \\<sharp>* \\<Psi>` xvec_fresh_psi `xvec \\<sharp>* P` xvec_freshP S dpr\n      ultimately have \"\\<Psi> \\<rhd> P \\<longmapsto>\\<pi>' @ (p \\<bullet> M)\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> (p \\<bullet> P')\"\n\tby(simp add: eqvts name_set_fresh_fresh)\n      with `xvec \\<sharp>* \\<Psi>` xvec_fresh_psi `xvec \\<sharp>* P` xvec_freshP S `xvec \\<sharp>* (p \\<bullet> M)`\n      have \"\\<Psi> \\<rhd> P \\<longmapsto>\\<pi>' @ (p \\<bullet> p \\<bullet> M)\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> (p \\<bullet> P')\"\n       by(rule_tac output_perm_subject)\n         (simp add: fresh_star_def | assumption)+\n\n      with dpr have \"\\<Psi> \\<rhd> P \\<longmapsto>\\<pi>' @ M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> (p \\<bullet> P')\"\n\tby simp\n\n      moreover from P'_rel_q' Eqvt have \"(p \\<bullet> \\<Psi>, p \\<bullet> P', p \\<bullet> p \\<bullet> Q') \\<in> Rel\"\n\tapply(simp add: eqvt_def eqvts)\n\tapply(erule_tac x=\"(\\<Psi>, P', p \\<bullet> Q')\" in ballE)\n\tapply(erule_tac x=\"p\" in allE)\n\tby(auto simp add: eqvts)\n      with `xvec \\<sharp>* \\<Psi>` xvec_fresh_psi S dpr have \"(\\<Psi>, p \\<bullet> P', Q') \\<in> Rel\" by simp\n      ultimately have \"\\<exists>\\<pi>' P'. \\<Psi> \\<rhd> P \\<longmapsto> \\<pi>' @ M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> P' \\<and> (\\<Psi>, P', Q') \\<in> Rel\"\n\tby blast\n    }\n    ultimately show ?case by force\n  next\n    case Tau\n    thus ?case by(rule_tac Sim) auto\n  qed\nqed\n\nlemma simI2[case_names c_sim]:\n  fixes \\<Psi>   :: 'b\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   Rel :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q   :: \"('a, 'b, 'c) psi\"\n  and   C   :: \"'d::fs_name\"\n\n  assumes Sim: \"\\<And>\\<pi> \\<alpha> Q'. \\<lbrakk>\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> Q'; bn \\<alpha> \\<sharp>* P; bn \\<alpha>  \\<sharp>* \\<Psi>; distinct(bn \\<alpha>)\\<rbrakk> \\<Longrightarrow> \\<exists>\\<pi>' P'. \\<Psi> \\<rhd> P \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> P' \\<and> (\\<Psi>, P', Q') \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> P \\<leadsto>[Rel] Q\"\nusing assms\nby(force simp add: simulation_def dest: bound_output_distinct)\n\nlemma sim_i_chain_fresh[consumes 4, case_names c_sim]:\n  fixes \\<Psi>    :: 'b\n  and   P    :: \"('a, 'b, 'c) psi\"\n  and   Rel  :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   xvec :: \"name list\"\n  and   C    :: \"'d::fs_name\"\n\n  assumes Eqvt: \"eqvt Rel\"\n  and     \"xvec \\<sharp>* \\<Psi>\"\n  and     \"xvec \\<sharp>* P\"\n  and     \"xvec \\<sharp>* Q\"\n  and     Sim: \"\\<And>\\<pi> \\<alpha> Q'. \\<lbrakk>\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> Q'; bn \\<alpha> \\<sharp>* P; bn \\<alpha> \\<sharp>* Q; bn \\<alpha> \\<sharp>* \\<Psi>; bn \\<alpha> \\<sharp>* \\<pi>;\n                         bn \\<alpha> \\<sharp>* subject \\<alpha>; distinct(bn \\<alpha>); bn \\<alpha> \\<sharp>* C; xvec \\<sharp>* \\<alpha>; xvec \\<sharp>* \\<pi>; xvec \\<sharp>* Q'\\<rbrakk> \\<Longrightarrow>\n                         \\<exists>\\<pi>' P'. \\<Psi> \\<rhd> P \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> P' \\<and> (\\<Psi>, P', Q') \\<in> Rel\"\n  shows \"\\<Psi> \\<rhd> P \\<leadsto>[Rel] Q\"\nusing `eqvt Rel`\nproof(induct rule: simI[where C=\"(xvec, C)\"])\n  case(c_sim \\<pi> \\<alpha> Q')\n  from `xvec \\<sharp>* Q` `\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> Q'` have \"xvec \\<sharp>* \\<pi>\"\n      by(auto intro: trans_fresh_provenance)\n  from `bn \\<alpha> \\<sharp>* (xvec, C)` have \"bn \\<alpha> \\<sharp>* xvec\" and \"bn \\<alpha> \\<sharp>* C\" by(simp add: fresh_chain_sym)+ \n  obtain p::\"name prm\" where \"(p \\<bullet> xvec) \\<sharp>* \\<Psi>\" and  \"(p \\<bullet> xvec) \\<sharp>* P\" and  \"(p \\<bullet> xvec) \\<sharp>* Q\" and  \"(p \\<bullet> xvec) \\<sharp>* \\<pi>\"\n                         and  \"(p \\<bullet> xvec) \\<sharp>* \\<alpha>\" and S: \"set p \\<subseteq> set xvec \\<times> set(p \\<bullet> xvec)\"\n                         and \"distinct_perm p\"\n    by(rule_tac c=\"(\\<Psi>, P, Q, \\<pi>, \\<alpha>)\" and xvec=xvec in name_list_avoiding) auto\n  show ?case\n  proof(cases rule: action_cases[where \\<alpha>=\\<alpha>])\n    case(c_input M N)\n    from `\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> Q'` `\\<alpha>=M\\<lparr>N\\<rparr>` have \"(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> Q) \\<longmapsto>(p\\<bullet>\\<pi>) @ (p \\<bullet> (M\\<lparr>N\\<rparr> \\<prec> Q'))\"\n      by(force intro: semantics.eqvt)\n    with `xvec \\<sharp>* \\<Psi>` `(p \\<bullet> xvec) \\<sharp>* \\<Psi>` `xvec \\<sharp>* Q` `(p \\<bullet> xvec) \\<sharp>* Q` S `(p\\<bullet>xvec) \\<sharp>* \\<pi>` `xvec \\<sharp>* \\<pi>`\n    have Q_trans: \"\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ (p \\<bullet> M)\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> (p \\<bullet> Q')\"\n      by(simp add: eqvts)\n    moreover from `(p \\<bullet> xvec) \\<sharp>* \\<alpha>` have \"(p \\<bullet> (p \\<bullet> xvec)) \\<sharp>* (p \\<bullet> \\<alpha>)\"\n      by(simp only: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])  \n    with `distinct_perm p` `\\<alpha>=M\\<lparr>N\\<rparr>` have \"xvec \\<sharp>* (p \\<bullet> M)\" and \"xvec \\<sharp>* (p \\<bullet> N)\" by simp+\n    moreover with Q_trans `xvec \\<sharp>* Q` have \"xvec \\<sharp>* (p \\<bullet> Q')\" by(rule_tac input_fresh_chain_derivative)\n    ultimately have \"\\<exists>\\<pi>' P'. \\<Psi> \\<rhd> P \\<longmapsto> \\<pi>' @ (p \\<bullet> M)\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> P' \\<and> (\\<Psi>, P', (p \\<bullet> Q')) \\<in> Rel\"\n      using `xvec \\<sharp>* \\<pi>`\n      by(rule_tac Sim) (assumption | simp)+\n    then obtain \\<pi>' P' where P_trans: \"\\<Psi> \\<rhd> P \\<longmapsto> \\<pi>' @ (p \\<bullet> M)\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> P'\" and P'_rel_q': \"(\\<Psi>, P', (p \\<bullet> Q')) \\<in> Rel\"\n      by blast\n    from P_trans have \"(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P) \\<longmapsto> (p\\<bullet>\\<pi>') @ (p \\<bullet> ((p \\<bullet> M)\\<lparr>(p \\<bullet> N)\\<rparr> \\<prec> P'))\"\n      by(rule semantics.eqvt)\n    moreover from P_trans `xvec \\<sharp>* P` `(p\\<bullet>xvec) \\<sharp>* P` have \"xvec \\<sharp>* \\<pi>'\" \"(p\\<bullet>xvec) \\<sharp>* \\<pi>'\"\n      by(auto intro: trans_fresh_provenance)\n    moreover note `xvec \\<sharp>* \\<Psi>` `(p \\<bullet> xvec) \\<sharp>* \\<Psi>` `xvec \\<sharp>* P` `(p \\<bullet> xvec) \\<sharp>* P` S `distinct_perm p`\n    ultimately have \"\\<Psi> \\<rhd> P \\<longmapsto> \\<pi>' @ M\\<lparr>N\\<rparr> \\<prec> (p \\<bullet> P')\"\n      by(simp add: eqvts)\n    moreover from P'_rel_q' `eqvt Rel` have \"(p \\<bullet> \\<Psi>, p \\<bullet> P', p \\<bullet> p \\<bullet> Q') \\<in> Rel\"\n      by(auto simp add: eqvt_def)\n    with `xvec \\<sharp>* \\<Psi>` `(p \\<bullet> xvec) \\<sharp>* \\<Psi>` S `distinct_perm p`\n    have \"(\\<Psi>, p \\<bullet> P', Q') \\<in> Rel\" by simp\n    ultimately show ?thesis using `\\<alpha>=M\\<lparr>N\\<rparr>` by blast\n  next\n    case(c_output M yvec N)\n    from `distinct(bn \\<alpha>)` `bn \\<alpha> \\<sharp>* subject \\<alpha>` `\\<alpha>=M\\<lparr>\\<nu>*yvec\\<rparr>\\<langle>N\\<rangle>` have \"distinct yvec\" and \"yvec \\<sharp>* M\" by simp+\n    from `\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> Q'` `\\<alpha>=M\\<lparr>\\<nu>*yvec\\<rparr>\\<langle>N\\<rangle>` have \"(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> Q) \\<longmapsto>(p \\<bullet> \\<pi>) @ (p \\<bullet> (M\\<lparr>\\<nu>*yvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'))\"\n      by(force intro: semantics.eqvt)\n    with `xvec \\<sharp>* \\<Psi>` `(p \\<bullet> xvec) \\<sharp>* \\<Psi>` `xvec \\<sharp>* Q` `(p \\<bullet> xvec) \\<sharp>* Q` S `xvec \\<sharp>* \\<pi>` `(p\\<bullet>xvec) \\<sharp>* \\<pi>`\n    have Q_trans: \"\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ (p \\<bullet> M)\\<lparr>\\<nu>*(p \\<bullet> yvec)\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> (p \\<bullet> Q')\"\n      by(simp add: eqvts)\n    with S `bn \\<alpha> \\<sharp>* xvec` `(p \\<bullet> xvec) \\<sharp>* \\<alpha>` `\\<alpha>=M\\<lparr>\\<nu>*yvec\\<rparr>\\<langle>N\\<rangle>` have \"\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ (p \\<bullet> M)\\<lparr>\\<nu>*yvec\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> (p \\<bullet> Q')\"\n      by simp\n    moreover from `(p \\<bullet> xvec) \\<sharp>* \\<alpha>` have \"(p \\<bullet> (p \\<bullet> xvec)) \\<sharp>* (p \\<bullet> \\<alpha>)\"\n      by(simp only: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])  \n    with `distinct_perm p` `\\<alpha>=M\\<lparr>\\<nu>*yvec\\<rparr>\\<langle>N\\<rangle>` have \"xvec \\<sharp>* (p \\<bullet> M)\" and \"xvec \\<sharp>* (p \\<bullet> N)\" and \"xvec \\<sharp>* (p \\<bullet> yvec)\" by simp+\n    moreover with Q_trans `xvec \\<sharp>* Q` `distinct yvec` `yvec \\<sharp>* M` have \"xvec \\<sharp>* (p \\<bullet> Q')\"\n      by(drule_tac output_fresh_chain_derivative(2)) (auto simp add: pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst])\n    moreover from `yvec \\<sharp>* M` S `bn \\<alpha> \\<sharp>* xvec` `(p \\<bullet> xvec) \\<sharp>* \\<alpha>` `\\<alpha>=M\\<lparr>\\<nu>*yvec\\<rparr>\\<langle>N\\<rangle>` `distinct_perm p`\n    have \"yvec \\<sharp>* (p \\<bullet> M)\" by(subst pt_fresh_star_bij[OF pt_name_inst, OF at_name_inst, symmetric, where pi=p]) simp\n    ultimately have \"\\<exists>\\<pi>' P'. \\<Psi> \\<rhd> P \\<longmapsto>\\<pi>' @ (p \\<bullet> M)\\<lparr>\\<nu>*yvec\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> P' \\<and> (\\<Psi>, P', (p \\<bullet> Q')) \\<in> Rel\"\n      using `bn \\<alpha> \\<sharp>* \\<Psi>` `bn \\<alpha> \\<sharp>* P` `bn \\<alpha> \\<sharp>* Q``bn \\<alpha> \\<sharp>* xvec` `bn \\<alpha> \\<sharp>* C` `yvec \\<sharp>* M` `\\<alpha>=M\\<lparr>\\<nu>*yvec\\<rparr>\\<langle>N\\<rangle>` `distinct yvec` `bn \\<alpha> \\<sharp>* \\<pi>` `xvec \\<sharp>* \\<pi>`\n      by(rule_tac Sim) auto\n    then obtain \\<pi>' P' where P_trans: \"\\<Psi> \\<rhd> P \\<longmapsto> \\<pi>' @ (p \\<bullet> M)\\<lparr>\\<nu>*yvec\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> P'\" and P'_rel_q': \"(\\<Psi>, P', (p \\<bullet> Q')) \\<in> Rel\"\n      by blast\n    from P_trans have \"(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P) \\<longmapsto> (p\\<bullet>\\<pi>') @ (p \\<bullet> ((p \\<bullet> M)\\<lparr>\\<nu>*yvec\\<rparr>\\<langle>(p \\<bullet> N)\\<rangle> \\<prec> P'))\"\n      by(rule semantics.eqvt)\n    moreover from P_trans `xvec \\<sharp>* P` `(p\\<bullet>xvec) \\<sharp>* P` have \"xvec \\<sharp>* \\<pi>'\" \"(p\\<bullet>xvec) \\<sharp>* \\<pi>'\"\n      by(auto intro: trans_fresh_provenance)    \n    moreover note `xvec \\<sharp>* \\<Psi>` `(p \\<bullet> xvec) \\<sharp>* \\<Psi>` `xvec \\<sharp>* P` `(p \\<bullet> xvec) \\<sharp>* P` S `distinct_perm p` `bn \\<alpha> \\<sharp>* xvec` `(p \\<bullet> xvec) \\<sharp>* \\<alpha>` `\\<alpha>=M\\<lparr>\\<nu>*yvec\\<rparr>\\<langle>N\\<rangle>`\n    ultimately have \"\\<Psi> \\<rhd> P \\<longmapsto> \\<pi>' @ M\\<lparr>\\<nu>*yvec\\<rparr>\\<langle>N\\<rangle> \\<prec> (p \\<bullet> P')\" by(simp add: eqvts)\n    moreover from P'_rel_q' `eqvt Rel` have \"(p \\<bullet> \\<Psi>, p \\<bullet> P', p \\<bullet> p \\<bullet> Q') \\<in> Rel\"\n      by(auto simp add: eqvt_def)\n    with `xvec \\<sharp>* \\<Psi>` `(p \\<bullet> xvec) \\<sharp>* \\<Psi>` S `distinct_perm p`\n    have \"(\\<Psi>, p \\<bullet> P', Q') \\<in> Rel\" by simp\n    ultimately show ?thesis using `\\<alpha>=M\\<lparr>\\<nu>*yvec\\<rparr>\\<langle>N\\<rangle>` by blast\n  next\n    case c_tau\n    from `\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> Q'` `\\<alpha> = \\<tau>` `xvec \\<sharp>* Q` have \"xvec \\<sharp>* Q'\"\n      by(blast dest: tau_fresh_chain_derivative)\n    with `\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> Q'` `\\<alpha> = \\<tau>` `xvec \\<sharp>* \\<pi>`\n    show ?thesis by(drule_tac Sim) auto\n  qed\nqed\n\nlemma sim_i_fresh[consumes 4, case_names c_sim]:\n  fixes \\<Psi>   :: 'b\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   Rel :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q   :: \"('a, 'b, 'c) psi\"\n  and   x   :: name\n  and   C   :: \"'d::fs_name\"\n\n  assumes Eqvt: \"eqvt Rel\"\n  and     \"x \\<sharp> \\<Psi>\"\n  and     \"x \\<sharp> P\"\n  and     \"x \\<sharp> Q\"\n  and     \"\\<And>\\<pi> \\<alpha> Q'. \\<lbrakk>\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> Q'; bn \\<alpha> \\<sharp>* P; bn \\<alpha> \\<sharp>* Q; bn \\<alpha> \\<sharp>* \\<Psi>; bn \\<alpha> \\<sharp>* \\<pi>;\n                    bn \\<alpha> \\<sharp>* subject \\<alpha>; distinct(bn \\<alpha>); bn \\<alpha> \\<sharp>* C; x \\<sharp> \\<alpha>; x \\<sharp> Q'; x \\<sharp> \\<pi>\\<rbrakk> \\<Longrightarrow>\n                    \\<exists>\\<pi>' P'. \\<Psi> \\<rhd> P \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> P' \\<and> (\\<Psi>, P', Q') \\<in> Rel\"\n\n  shows \"\\<Psi> \\<rhd> P \\<leadsto>[Rel] Q\"\nusing assms\nby(rule_tac xvec=\"[x]\" and C=C in sim_i_chain_fresh) auto\n\nlemma simE:\n  fixes F   :: 'b\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   Rel :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q   :: \"('a, 'b, 'c) psi\"\n\n  assumes \"\\<Psi> \\<rhd> P \\<leadsto>[Rel] Q\"\n\n  shows \"\\<And>\\<pi> \\<alpha> Q'. \\<lbrakk>\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> Q'; bn \\<alpha> \\<sharp>* \\<Psi>; bn \\<alpha> \\<sharp>* P\\<rbrakk> \\<Longrightarrow> \\<exists>\\<pi> P'. \\<Psi> \\<rhd> P \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> P' \\<and> (\\<Psi>, P', Q') \\<in> Rel\"\nusing assms\nby(auto simp add: simulation_def)\n\nlemma sim_closed_aux:\n  fixes \\<Psi>   :: 'b\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   Rel :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q   :: \"('a, 'b, 'c) psi\"\n  and   p   :: \"name prm\"\n\n  assumes Eqvt_rel: \"eqvt Rel\"\n  and     P_simQ: \"\\<Psi> \\<rhd> P \\<leadsto>[Rel] Q\"\n\n  shows \"(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P) \\<leadsto>[Rel] (p \\<bullet> Q)\"\nusing Eqvt_rel\nproof(induct rule: simI[of _ _ _ _ \"(\\<Psi>, P, p)\"])\n  case(c_sim \\<pi> \\<alpha> Q')\n  from `p \\<bullet> \\<Psi> \\<rhd> p \\<bullet> Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> Q'` \n  have \"(rev p \\<bullet> p \\<bullet> \\<Psi>) \\<rhd> (rev p \\<bullet> p \\<bullet> Q) \\<longmapsto>(rev p \\<bullet> \\<pi>) @ (rev p \\<bullet> (\\<alpha> \\<prec> Q'))\"\n    by(blast dest: semantics.eqvt)\n  hence \"\\<Psi> \\<rhd> Q \\<longmapsto>(rev p \\<bullet> \\<pi>) @ (rev p \\<bullet> \\<alpha>) \\<prec> (rev p \\<bullet> Q')\"\n    by(simp add: eqvts)\n  moreover with `bn \\<alpha> \\<sharp>* (\\<Psi>, P, p)` have \"bn \\<alpha> \\<sharp>* \\<Psi>\" and \"bn \\<alpha> \\<sharp>* P\" and \"bn \\<alpha> \\<sharp>* p\" by simp+\n  ultimately obtain \\<pi>' P' where P_trans: \"\\<Psi> \\<rhd> P \\<longmapsto>\\<pi>' @ (rev p \\<bullet> \\<alpha>) \\<prec> P'\"\n                         and P'_rel_q': \"(\\<Psi>, P', rev p \\<bullet> Q') \\<in> Rel\"\n    using P_simQ\n    by(force dest!: simE fresh_chain_perm_simp simp add: eqvts)\n  from P_trans have \"(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P) \\<longmapsto>(p\\<bullet> \\<pi>') @ (p \\<bullet> ((rev p \\<bullet> \\<alpha>) \\<prec> P'))\"\n    by(rule semantics.eqvt)\n  with `bn \\<alpha> \\<sharp>* p` have \"(p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P) \\<longmapsto>(p\\<bullet>\\<pi>') @ \\<alpha> \\<prec> (p \\<bullet> P')\"\n    by(simp add: eqvts fresh_chain_perm_simp)\n  moreover from P'_rel_q' Eqvt_rel have \"(p \\<bullet> (\\<Psi>, P', rev p \\<bullet> Q')) \\<in> Rel\"\n    by(simp only: eqvt_def)\n  hence \"(p \\<bullet> \\<Psi>, p \\<bullet> P', Q') \\<in> Rel\" by simp\n  ultimately show ?case by blast\nqed\n\nlemma sim_closed:\n  fixes \\<Psi>   :: 'b\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   Rel :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q   :: \"('a, 'b, 'c) psi\"\n  and   p   :: \"name prm\"\n\n  assumes Eqvt_rel: \"eqvt Rel\"\n\n  shows \"\\<Psi> \\<rhd> P \\<leadsto>[Rel] Q \\<Longrightarrow> (p \\<bullet> \\<Psi>) \\<rhd> (p \\<bullet> P) \\<leadsto>[Rel] (p \\<bullet> Q)\"\n  and   \"P \\<leadsto>[Rel] Q \\<Longrightarrow> (p \\<bullet> P) \\<leadsto>[Rel] (p \\<bullet> Q)\"\nusing Eqvt_rel\nby(force dest: sim_closed_aux simp add: perm_bottom)+\n\nlemma reflexive:\n  fixes Rel :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   \\<Psi>   :: 'b\n  and   P   :: \"('a, 'b, 'c) psi\"\n\n  assumes \"{(\\<Psi>, P, P) | \\<Psi> P. True} \\<subseteq> Rel\"\n\n  shows \"\\<Psi> \\<rhd> P \\<leadsto>[Rel] P\"\nusing assms\nby(force simp add: simulation_def)\n(*\nlemma sim_res[consumes 11, case_names c_open c_res]:\n  fixes \\<Psi>    :: 'b\n  and   x    :: name\n  and   Q    :: \"('a, 'b, 'c) psi\"\n  and   M    :: 'a\n  and   xvec :: \"name list\"\n  and   N    :: 'a\n  and   Q'   :: \"('a, 'b, 'c) psi\"\n  and   Rel  :: \"('b \\<times> ('a, 'b, 'c) psi \\<times>  ('a, 'b, 'c) psi) set\"\n  and   C    :: \"'d::fs_name\"\n  and   \\<Psi>'   :: 'b\n\n  assumes Trans: \"\\<Psi> \\<rhd> \\<lparr>\\<nu>x\\<rparr>Q \\<longmapsto>M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'\"\n  and     \"x \\<sharp> xvec\"\n  and     \"x \\<sharp> \\<Psi>\"\n  and     \"x \\<sharp> M\"\n  and     \"x \\<sharp> \\<Psi>'\"\n  and     \"x \\<sharp> P\"\n  and     \"eqvt Rel\"\n  and     \"xvec \\<sharp>* \\<Psi>\"\n  and     \"xvec \\<sharp>* \\<Psi>'\"\n  and     \"xvec \\<sharp>* P\"\n  and     \"xvec \\<sharp>* C\"\n  and     r_open: \"\\<And>xvec1 xvec2 y N Q'. \\<lbrakk>\\<Psi> \\<rhd> Q \\<longmapsto>M\\<lparr>\\<nu>*(xvec1@xvec2)\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'; x \\<in> supp N; x \\<sharp> xvec1; x \\<sharp> xvec2; xvec1 \\<sharp>* \\<Psi>; xvec1 \\<sharp>* \\<Psi>'; xvec1 \\<sharp>* P; xvec1 \\<sharp>* C;\n                                         xvec2 \\<sharp>* \\<Psi>; xvec2 \\<sharp>* \\<Psi>'; xvec2 \\<sharp>* P; xvec2 \\<sharp>* C; x \\<noteq> y; y \\<sharp> xvec1; y \\<sharp> xvec2; y \\<sharp> \\<Psi>; y \\<sharp> P; y \\<sharp> C\\<rbrakk> \\<Longrightarrow> \n                                         \\<exists>P'. \\<Psi>' \\<rhd> P \\<longmapsto>(([(x, y)] \\<bullet> G) (xvec1@x#xvec2) N P') \\<and> (\\<Psi>', P', ([(x, y)] \\<bullet> F) Q') \\<in> Rel\"\n  and     r_scope: \"\\<And>N Q'. \\<lbrakk>\\<Psi> \\<rhd> Q \\<longmapsto> M\\<lparr>\\<nu>*xvec\\<rparr>\\<langle>N\\<rangle> \\<prec> Q'; x \\<sharp> N\\<rbrakk> \\<Longrightarrow> \\<exists>P'. \\<Psi>' \\<rhd> P \\<longmapsto>(G xvec N P') \\<and> (\\<Psi>', P', F (\\<lparr>\\<nu>x\\<rparr>Q')) \\<in> Rel\"\n  \n  shows \"\\<exists>P'. \\<Psi>' \\<rhd> P \\<longmapsto>(G xvec N P') \\<and> (\\<Psi>', P', F Q') \\<in> Rel\"\nusing Trans `x \\<sharp> xvec` `x \\<sharp> \\<Psi>` `x \\<sharp> M`\nproof(induct rule: res_casesB)\n  case(c_open xvec1 xvec2 y N Q')\n  note `\\<Psi> \\<rhd> Q \\<longmapsto>M\\<lparr>\\<nu>*(xvec1@xvec2)\\<rparr>\\<langle>([(x, y)] \\<bullet> N)\\<rangle> \\<prec> ([(x, y)] \\<bullet> Q')`\n  moreover from `y \\<in> supp N` have \"([(x, y)] \\<bullet> y) \\<in> [(x, y)] \\<bullet> (supp N)\"\n    by(simp add: pt_set_bij[OF pt_name_inst, OF at_name_inst])\n  with `x \\<noteq> y` have \"x \\<in> supp([(x, y)] \\<bullet> N)\" by(simp add: calc_atm eqvts)\n  moreover from `xvec = xvec1@y#xvec2` `xvec \\<sharp>* \\<Psi>` `xvec \\<sharp>* \\<Psi>'` `xvec \\<sharp>* P` `xvec \\<sharp>* C` `x \\<sharp> xvec`\n  have \"xvec1 \\<sharp>* \\<Psi>\" and \"xvec1 \\<sharp>* \\<Psi>'\" and  \"xvec1 \\<sharp>* P\" and  \"xvec1 \\<sharp>* C\"\n   and \"xvec2 \\<sharp>* \\<Psi>\" and \"xvec2 \\<sharp>* \\<Psi>'\"  and \"xvec2 \\<sharp>* P\" and \"xvec2 \\<sharp>* C\"\n   and \"y \\<sharp> \\<Psi>\" and \"y \\<sharp> \\<Psi>'\" and \"y \\<sharp> P\" and \"x \\<sharp> xvec1\" and \"x \\<sharp> xvec2\" and \"y \\<sharp> C\"\n    by(simp add: fresh_list_cons fresh_list_append)+ \n  ultimately obtain P' where P_trans: \"\\<Psi>' \\<rhd> P \\<longmapsto>(([(x, y)] \\<bullet> G) (xvec1@x#xvec2) ([(x, y)] \\<bullet> N) P')\"\n                         and P'_rel_q': \"(\\<Psi>', P', ([(x, y)] \\<bullet> F) ([(x, y)] \\<bullet> Q')) \\<in> Rel\"\n    using `y \\<sharp> xvec1` `y \\<sharp> xvec2` `x \\<noteq> y`\n    by(blast dest: r_open)\n  \n  from P_trans have \"([(x, y)] \\<bullet> \\<Psi>') \\<rhd> ([(x, y)] \\<bullet> P) \\<longmapsto> [(x, y)] \\<bullet> (([(x, y)] \\<bullet> G) (xvec1@x#xvec2) ([(x, y)] \\<bullet> N) P')\"\n    by(rule semantics.eqvt)\n  with `x \\<sharp> \\<Psi>'` `y \\<sharp> \\<Psi>'` `x \\<sharp> P` `y \\<sharp> P` `x \\<sharp> xvec1` `y \\<sharp> xvec1` `x \\<sharp> xvec2` `y \\<sharp> xvec2` `x \\<noteq> y` `xvec = xvec1@y#xvec2`\n  have \"\\<Psi>' \\<rhd> P \\<longmapsto>(G xvec N ([(x, y)] \\<bullet> P'))\"\n    by(simp add: pt_fun_app_eq perm_fun_def eqvts calc_atm)\n  moreover from P'_rel_q' `eqvt Rel` have \"([(x, y)] \\<bullet> \\<Psi>', [(x, y)] \\<bullet> P', ([(x, y)] \\<bullet> (([(x, y)] \\<bullet> F) ([(x, y)] \\<bullet> Q')))) \\<in> Rel\"\n    by(simp only: eqvt_def) auto\n  with `x \\<sharp> \\<Psi>'` `y \\<sharp> \\<Psi>'` `x \\<noteq> y`have \"(\\<Psi>', [(x, y)] \\<bullet> P', F Q') \\<in> Rel\"\n    by(simp add: eqvts pt_fun_app_eq[OF pt_name_inst, OF at_name_inst, of _ \"([(x, y)] \\<bullet> F)\"])\n  ultimately show ?case by blast\nnext\n  case(c_res N Q')\n  thus ?case by(blast intro: r_scope)\nqed\n*)\n\n\n  assumes P_simQ: \"\\<Psi> \\<rhd> P \\<leadsto>[Rel] Q\"\n  and     Q_simR: \"\\<Psi> \\<rhd> Q \\<leadsto>[Rel'] R\"\n  and     Eqvt: \"eqvt Rel''\"\n  and     Set: \"{(\\<Psi>, P, R) | \\<Psi> P R. \\<exists>Q. (\\<Psi>, P, Q) \\<in> Rel \\<and> (\\<Psi>, Q, R) \\<in> Rel'} \\<subseteq> Rel''\"\n\n  shows \"\\<Psi> \\<rhd> P \\<leadsto>[Rel''] R\"\nusing `eqvt Rel''`\nproof(induct rule: simI[where C=Q])\n  case(c_sim \\<pi> \\<alpha> R')\n  from Q_simR `\\<Psi> \\<rhd> R \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> R'` `(bn \\<alpha>) \\<sharp>* \\<Psi>` `(bn \\<alpha>) \\<sharp>* Q`\n  obtain \\<pi>' Q' where Q_trans: \"\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> Q'\" and Q'_rel'_r': \"(\\<Psi>, Q', R') \\<in> Rel'\"\n    by(blast dest: simE)\n  from P_simQ Q_trans `bn \\<alpha> \\<sharp>* \\<Psi>` `bn \\<alpha> \\<sharp>* P`\n  obtain \\<pi>'' P' where P_trans: \"\\<Psi> \\<rhd> P \\<longmapsto>\\<pi>'' @ \\<alpha> \\<prec> P'\" and P'_rel_q': \"(\\<Psi>, P', Q') \\<in> Rel\"\n    by(blast dest: simE)\n  with P_trans Q'_rel'_r' P'_rel_q' Set\n  show ?case by blast\nqed\n\nlemma stat_eq_sim:\n  fixes \\<Psi>   :: 'b\n  and   P   :: \"('a, 'b, 'c) psi\"\n  and   Rel :: \"('b \\<times> ('a, 'b, 'c) psi \\<times> ('a, 'b, 'c) psi) set\"\n  and   Q   :: \"('a, 'b, 'c) psi\"\n  and   \\<Psi>'  :: 'b\n\n  assumes P_simQ: \"\\<Psi> \\<rhd> P \\<leadsto>[Rel] Q\"\n  and     \"eqvt Rel'\"\n  and     \"\\<Psi> \\<simeq> \\<Psi>'\"\n  and     C1: \"\\<And>\\<Psi>'' R S \\<Psi>'''. \\<lbrakk>(\\<Psi>'', R, S) \\<in> Rel; \\<Psi>'' \\<simeq> \\<Psi>'''\\<rbrakk> \\<Longrightarrow> (\\<Psi>''', R, S) \\<in> Rel'\"\n\n  shows \"\\<Psi>' \\<rhd> P \\<leadsto>[Rel'] Q\"\nusing `eqvt Rel'`\nproof(induct rule: simI[of _ _ _ _ \\<Psi>])\n  case(c_sim \\<pi> \\<alpha> Q')\n  from `\\<Psi>' \\<rhd> Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> Q'` `\\<Psi> \\<simeq> \\<Psi>'`\n  have \"\\<Psi> \\<rhd> Q \\<longmapsto>\\<pi> @ \\<alpha> \\<prec> Q'\" by(metis stat_eq_transition Assertion_stat_eq_sym)\n  with P_simQ `bn \\<alpha> \\<sharp>* \\<Psi>` `bn \\<alpha> \\<sharp>* P`\n  obtain \\<pi>' P' where \"\\<Psi> \\<rhd> P \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> P'\" and \"(\\<Psi>, P', Q') \\<in> Rel\"\n    by(blast dest: simE)\n  \n  from `\\<Psi> \\<rhd> P \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> P'` `\\<Psi> \\<simeq> \\<Psi>'` have \"\\<Psi>' \\<rhd> P \\<longmapsto>\\<pi>' @ \\<alpha> \\<prec> P'\"\n    by(rule stat_eq_transition)\n  moreover from `(\\<Psi>, P', Q') \\<in> Rel` `\\<Psi> \\<simeq> \\<Psi>'` have \"(\\<Psi>', P', Q') \\<in> Rel'\"\n    by(rule C1)\n  ultimately show ?case by blast\nqed\n\n\n\n  assumes \"\\<Psi> \\<rhd> P \\<leadsto>[A] Q\"\n  and     \"A \\<subseteq> B\"\n\n  shows \"\\<Psi> \\<rhd> P \\<leadsto>[B] Q\"\nusing assms\nby(simp (no_asm) add: simulation_def) (force dest: simE)\n\nend\n\nend\n\n", "meta": {"author": "IlmariReissumies", "repo": "newpsi", "sha": "201517d55b6ed1632a5bff2a585367278b5bc67b", "save_path": "github-repos/isabelle/IlmariReissumies-newpsi", "path": "github-repos/isabelle/IlmariReissumies-newpsi/newpsi-201517d55b6ed1632a5bff2a585367278b5bc67b/Simulation.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.5428632683808532, "lm_q2_score": 0.4610167793123159, "lm_q1q2_score": 0.2502690755958983}}
{"text": "(*\n * Copyright 2022, Proofcraft Pty Ltd\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n * SPDX-License-Identifier: GPL-2.0-only\n *)\n\ntheory ArchArch_AI\nimports Arch_AI\nbegin\n\nunbundle l4v_word_context\n\ncontext Arch begin global_naming RISCV64\n\ndefinition\n  \"valid_aci aci \\<equiv> case aci of MakePool frame slot parent base \\<Rightarrow>\n     \\<lambda>s. cte_wp_at (\\<lambda>c. c = NullCap) slot s \\<and> real_cte_at slot s \\<and>\n         ex_cte_cap_wp_to is_cnode_cap slot s \\<and>\n         slot \\<noteq> parent \\<and>\n         cte_wp_at (\\<lambda>cap. \\<exists>idx. cap = UntypedCap False frame pageBits idx) parent s \\<and>\n         descendants_of parent (cdt s) = {} \\<and>\n         is_aligned base asid_low_bits \\<and>\n         asid_table s (asid_high_bits_of base) = None\"\n\nlemma safe_parent_strg:\n  \"cte_wp_at (\\<lambda>cap. cap = UntypedCap False frame pageBits idx) p s \\<and>\n   descendants_of p (cdt s) = {} \\<and>\n   valid_objs s\n  \\<longrightarrow>\n  cte_wp_at (safe_parent_for (cdt s) p\n             (ArchObjectCap (ASIDPoolCap frame base)))\n             p s\"\n  apply (clarsimp simp: cte_wp_at_caps_of_state safe_parent_for_def is_physical_def arch_is_physical_def)\n  apply (rule is_aligned_no_overflow)\n  apply (drule (1) caps_of_state_valid_cap)\n  apply (clarsimp simp: valid_cap_def cap_aligned_def)\n  done\n\nlemma range_cover_full:\n  \"\\<lbrakk>is_aligned ptr sz; sz<word_bits\\<rbrakk> \\<Longrightarrow> range_cover (ptr::machine_word) sz sz (Suc 0)\"\n   by (clarsimp simp:range_cover_def unat_eq_0 le_mask_iff[symmetric] word_and_le1 word_bits_def)\n\n\ndefinition\n  valid_arch_inv :: \"arch_invocation \\<Rightarrow> 'z::state_ext state \\<Rightarrow> bool\"\nwhere\n  \"valid_arch_inv ai \\<equiv> case ai of\n     InvokePageTable pti \\<Rightarrow> valid_pti pti\n   | InvokePage pgi \\<Rightarrow> valid_page_inv pgi\n   | InvokeASIDControl aci \\<Rightarrow> valid_aci aci\n   | InvokeASIDPool api \\<Rightarrow> valid_apinv api\"\n\nlemma check_vp_wpR [wp]:\n  \"\\<lbrace>\\<lambda>s. vmsz_aligned w sz \\<longrightarrow> P () s\\<rbrace>\n  check_vp_alignment sz w \\<lbrace>P\\<rbrace>, -\"\n  apply (simp add: check_vp_alignment_def unlessE_whenE cong: vmpage_size.case_cong)\n  apply (rule hoare_pre)\n   apply (wp whenE_wp|wpc)+\n  apply (simp add: vmsz_aligned_def)\n  done\n\n\nlemma check_vp_inv: \"\\<lbrace>P\\<rbrace> check_vp_alignment sz w \\<lbrace>\\<lambda>_. P\\<rbrace>\"\n  apply (simp add: check_vp_alignment_def unlessE_whenE cong: vmpage_size.case_cong)\n  apply (rule hoare_pre)\n   apply (wp whenE_wp|wpc)+\n  apply simp\n  done\n\n\nlemma p2_low_bits_max:\n  \"(2 ^ asid_low_bits - 1) = (max_word :: asid_low_index)\"\n  by (simp add: asid_low_bits_def)\n\nlemma dom_ucast_eq:\n  \"is_aligned y asid_low_bits \\<Longrightarrow>\n   (- dom (\\<lambda>a::asid_low_index. p (ucast a :: machine_word)) \\<inter> {x. ucast x + (y::RISCV64_A.asid) \\<noteq> 0} = {}) =\n   (- dom p \\<inter> {x. x \\<le> 2 ^ asid_low_bits - 1 \\<and> x + ucast y \\<noteq> 0} = {})\"\n  apply safe\n   apply clarsimp\n   apply (rule ccontr)\n   apply (erule_tac x=\"ucast x\" in in_emptyE)\n   apply (clarsimp simp: p2_low_bits_max)\n   apply (rule conjI)\n    apply (clarsimp simp: ucast_ucast_mask)\n    apply (subst (asm) less_mask_eq)\n    apply (rule word_less_sub_le [THEN iffD1])\n      apply (simp add: word_bits_def)\n     apply (simp add: asid_low_bits_def)\n    apply simp\n   apply (clarsimp simp: mask_2pm1[symmetric] ucast_ucast_mask2 is_down is_aligned_mask)\n   apply (frule and_mask_eq_iff_le_mask[THEN iffD2])\n   apply (simp add: asid_low_bits_def)\n   apply (erule notE)\n   apply (subst word_plus_and_or_coroll)\n    apply word_eqI_solve\n   apply (subst (asm) word_plus_and_or_coroll; word_bitwise, clarsimp simp: word_size)\n  apply (clarsimp simp: p2_low_bits_max)\n  apply (rule ccontr)\n  apply simp\n  apply (erule_tac x=\"ucast x\" in in_emptyE)\n  apply clarsimp\n  apply (rule conjI, blast)\n  apply (rule conjI)\n   apply (rule word_less_sub_1)\n   apply (rule order_less_le_trans)\n    apply (rule ucast_less, simp)\n   apply (simp add: asid_low_bits_def)\n  apply clarsimp\n  apply (erule notE)\n  apply (simp add: is_aligned_mask asid_low_bits_def)\n  apply (subst word_plus_and_or_coroll)\n   apply word_eqI_solve\n  apply (subst (asm) word_plus_and_or_coroll)\n   apply (word_bitwise, clarsimp simp: word_size)\n  apply (word_bitwise)\n  done\n\n\nlemma asid_high_bits_max_word:\n  \"(2 ^ asid_high_bits - 1) = (max_word :: asid_high_index)\"\n  by (simp add: asid_high_bits_def)\n\n\nlemma dom_ucast_eq_8:\n  \"(- dom (\\<lambda>a::asid_high_index. p (ucast a::machine_word)) = {}) =\n   (- dom p \\<inter> {x. x \\<le> 2 ^ asid_high_bits - 1} = {})\"\n  apply safe\n   apply clarsimp\n   apply (rule ccontr)\n   apply (erule_tac x=\"ucast x\" in in_emptyE)\n   apply (clarsimp simp: asid_high_bits_max_word)\n   apply (clarsimp simp: ucast_ucast_mask)\n   apply (subst (asm) less_mask_eq)\n   apply (rule word_less_sub_le [THEN iffD1])\n     apply (simp add: word_bits_def)\n    apply (simp add: asid_high_bits_def)\n   apply simp\n  apply (clarsimp simp: asid_high_bits_max_word)\n  apply (rule ccontr)\n  apply simp\n  apply (erule_tac x=\"ucast x\" in in_emptyE)\n  apply clarsimp\n  apply (rule conjI, blast)\n  apply (rule word_less_sub_1)\n  apply (rule order_less_le_trans)\n  apply (rule ucast_less, simp)\n  apply (simp add: asid_high_bits_def)\n  done\n\n\nlemma ucast_fst_hd_assocs:\n  assumes \"- dom (\\<lambda>x::asid_low_index. pool (ucast x)) \\<inter> {x. ucast x + (a::RISCV64_A.asid) \\<noteq> 0} \\<noteq> {}\"\n  assumes \"is_aligned a asid_low_bits\"\n  shows\n    \"fst (hd [(x, y) \\<leftarrow> assocs pool. x \\<le> 2 ^ asid_low_bits - 1 \\<and> x + ucast a \\<noteq> 0 \\<and> y = None]) +\n           (ucast a :: machine_word) =\n       ucast (UCAST(asid_low_len \\<rightarrow> asid_len)\n         (fst (hd [(x, y) \\<leftarrow> assocs (\\<lambda>a. pool (ucast a)). ucast x + a \\<noteq> 0 \\<and> y = None])) + a)\"\nproof -\n  have [unfolded word_bits_def, simplified, simp]: \"asid_low_bits < word_bits\"\n    by (simp add: asid_low_bits_def word_bits_def)\n  have [unfolded asid_low_bits_def, simplified, simp]:\n    \"x && mask asid_low_bits = x\"\n    if \"x < 2^asid_low_bits\" for x::machine_word\n    using that by (simp add: le_mask_iff_lt_2n[THEN iffD1, symmetric] word_le_mask_eq)\n  have [unfolded asid_bits_def asid_low_bits_def, simplified, simp]:\n    \"x && mask asid_bits = x\"\n    if \"x < 2^asid_low_bits\" for x::machine_word\n  proof -\n    have \"mask asid_low_bits \\<le> (mask asid_bits :: machine_word)\"\n      by (simp add: mask_def asid_low_bits_def asid_bits_def)\n    with that show ?thesis\n      by (simp add: le_mask_iff_lt_2n[THEN iffD1, symmetric] word_le_mask_eq)\n  qed\n  have [unfolded asid_bits_def asid_low_bits_def, simplified, simp]:\n    \"(x + ucast a \\<noteq> 0) = (ucast x + a \\<noteq> 0)\"\n    if \"x < 2^asid_low_bits\" for x::machine_word\n  proof -\n    from that have \"x \\<le> mask asid_low_bits\" by (simp add: le_mask_iff_lt_2n[THEN iffD1, symmetric])\n    with `is_aligned a asid_low_bits`\n    show ?thesis\n      apply (subst word_and_or_mask_aligned2; simp add: is_aligned_ucastI)\n      apply (subst word_and_or_mask_aligned2, assumption, erule ucast_le_maskI)\n      apply (simp add: asid_low_bits_def)\n      apply word_bitwise\n      apply simp\n      done\n  qed\n\n  from assms show ?thesis\n    apply (simp add: ucast_assocs[unfolded o_def])\n    apply (simp add: filter_map split_def)\n    apply (simp cong: conj_cong add: ucast_ucast_mask2 is_down)\n    apply (simp add: asid_low_bits_def minus_one_norm)\n    apply (subgoal_tac \"P\" for P)  (* cut_tac but more awesome *)\n     apply (subst hd_map, assumption)\n     apply (simp add: ucast_ucast_mask2 is_down)\n     apply (drule hd_in_set)\n     apply clarsimp\n     apply (subst ucast_add_mask_aligned; assumption?)\n      apply (rule ucast_le_maskI)\n      apply (simp add: mask_def word_le_make_less)\n     apply (simp add: ucast_ucast_mask cong: conj_cong)\n    apply (simp add: assocs_empty_dom_comp null_def split_def)\n    apply (simp add: ucast_assocs[unfolded o_def] filter_map split_def)\n    apply (simp cong: conj_cong add: ucast_ucast_mask2 is_down)\n    done\nqed\n\n\ncrunch typ_at [wp]:\n  perform_page_table_invocation, perform_page_invocation, perform_asid_pool_invocation\n  \"\\<lambda>s. P (typ_at T p s)\"\n  (wp: crunch_wps)\n\nlemmas perform_page_table_invocation_typ_ats [wp] =\n  abs_typ_at_lifts [OF perform_page_table_invocation_typ_at]\n\nlemmas perform_page_invocation_typ_ats [wp] =\n  abs_typ_at_lifts [OF perform_page_invocation_typ_at]\n\nlemmas perform_asid_pool_invocation_typ_ats [wp] =\n  abs_typ_at_lifts [OF perform_asid_pool_invocation_typ_at]\n\nlemma perform_asid_control_invocation_tcb_at:\n  \"\\<lbrace>invs and valid_aci aci and st_tcb_at active p and\n    K (\\<forall>w a b c. aci = asid_control_invocation.MakePool w a b c \\<longrightarrow> w \\<noteq> p)\\<rbrace>\n  perform_asid_control_invocation aci\n  \\<lbrace>\\<lambda>rv. tcb_at p\\<rbrace>\"\n  apply (simp add: perform_asid_control_invocation_def)\n  apply (cases aci)\n  apply clarsimp\n  apply (wp |simp)+\n    apply (wp obj_at_delete_objects retype_region_obj_at_other2  hoare_vcg_const_imp_lift|assumption)+\n  apply (intro impI conjI)\n    apply (clarsimp simp: retype_addrs_def obj_bits_api_def default_arch_object_def image_def ptr_add_def)\n   apply (clarsimp simp: st_tcb_at_tcb_at)+\n  apply (frule st_tcb_ex_cap)\n    apply fastforce\n   apply (clarsimp split: Structures_A.thread_state.splits)\n   apply auto[1]\n  apply (clarsimp simp: ex_nonz_cap_to_def valid_aci_def)\n  apply (frule invs_untyped_children)\n  apply (clarsimp simp:cte_wp_at_caps_of_state)\n  apply (erule_tac ptr=\"(aa,ba)\" in untyped_children_in_mdbE[where P=\"\\<lambda>c. t \\<in> zobj_refs c\" for t])\n      apply (simp add: cte_wp_at_caps_of_state)\n     apply simp\n    apply (simp add:cte_wp_at_caps_of_state)\n    apply fastforce\n   apply (clarsimp simp: zobj_refs_to_obj_refs)\n   apply (erule(1) in_empty_interE)\n    apply (clarsimp simp:page_bits_def)\n  apply simp\n  done\n\n\nlemma ucast_asid_high_btis_of_le [simp]:\n  \"ucast (asid_high_bits_of w) \\<le> (2 ^ asid_high_bits - 1 :: machine_word)\"\n  apply (simp add: asid_high_bits_of_def)\n  apply (rule word_less_sub_1)\n  apply (rule order_less_le_trans)\n  apply (rule ucast_less)\n   apply simp\n  apply (simp add: asid_high_bits_def)\n  done\n\n\nlemma invoke_arch_tcb:\n  \"\\<lbrace>invs and valid_arch_inv ai and st_tcb_at active tptr\\<rbrace>\n  arch_perform_invocation ai\n  \\<lbrace>\\<lambda>rv. tcb_at tptr\\<rbrace>\"\n  apply (simp add: arch_perform_invocation_def)\n  apply (cases ai; simp; (wp; clarsimp simp add: st_tcb_at_tcb_at)?)\n  apply (wp perform_asid_control_invocation_tcb_at)\n  apply (clarsimp simp add: valid_arch_inv_def)\n  apply (clarsimp simp: valid_aci_def)\n  apply (frule st_tcb_ex_cap)\n    apply fastforce\n   apply (clarsimp split: Structures_A.thread_state.splits)\n   apply auto[1]\n  apply (clarsimp simp: ex_nonz_cap_to_def)\n  apply (frule invs_untyped_children)\n  apply (clarsimp simp:cte_wp_at_caps_of_state)\n  apply (erule_tac ptr=\"(aa,ba)\" in untyped_children_in_mdbE[where P=\"\\<lambda>c. t \\<in> zobj_refs c\" for t])\n      apply (simp add: cte_wp_at_caps_of_state)+\n    apply fastforce\n   apply (clarsimp simp: zobj_refs_to_obj_refs cte_wp_at_caps_of_state)\n   apply (drule_tac p=\"(aa,ba)\" in caps_of_state_valid_cap, fastforce)\n   apply (clarsimp simp: valid_cap_def cap_aligned_def)\n   apply (drule_tac x=tptr in base_member_set, simp)\n    apply (simp add: pageBits_def field_simps del: atLeastAtMost_iff)\n   apply (metis (no_types) orthD1 x_power_minus_1)\n  apply simp\n  done\n\nend\n\n\nlocale asid_update = Arch +\n  fixes ap asid_hi s s'\n  assumes ko: \"asid_pools_of s ap = Some Map.empty\"\n  assumes empty: \"asid_table s asid_hi = None\"\n  defines \"s' \\<equiv> s\\<lparr>arch_state := arch_state s\\<lparr>riscv_asid_table := (asid_table s)(asid_hi \\<mapsto> ap)\\<rparr>\\<rparr>\"\nbegin\n\nlemma aobjs_of[simp]:\n  \"aobjs_of s' = aobjs_of s\"\n  unfolding s'_def by simp\n\nlemma vspace_for_pool_ap[simp]:\n  \"vspace_for_pool ap asid (asid_pools_of s) = None\"\n  using ko by (simp add: vspace_for_pool_def obind_def)\n\nlemma asid_hi_pool_for_asid:\n  \"asid_high_bits_of asid = asid_hi \\<Longrightarrow> pool_for_asid asid s = None\"\n  using empty by (simp add: pool_for_asid_def)\n\nlemma asid_hi_pool_for_asid':\n  \"asid_high_bits_of asid = asid_hi \\<Longrightarrow> pool_for_asid asid s' = Some ap\"\n  by (simp add: pool_for_asid_def s'_def)\n\nlemma asid_hi_vs_lookup_table:\n  \"asid_high_bits_of asid = asid_hi \\<Longrightarrow> vs_lookup_table asid_pool_level asid vref s = None\"\n  by (simp add: asid_hi_pool_for_asid vs_lookup_table_def obind_def)\n\nlemma vs_lookup_table:\n  \"vs_lookup_table level asid vref s' =\n     (if asid_high_bits_of asid = asid_hi \\<and> level = asid_pool_level\n      then Some (asid_pool_level, ap)\n      else vs_lookup_table level asid vref s)\"\n  apply clarsimp\n  apply (rule conjI; clarsimp)\n   apply (clarsimp simp: vs_lookup_table_def in_omonad asid_hi_pool_for_asid')\n  apply (clarsimp simp: vs_lookup_table_def)\n  apply (cases \"asid_high_bits_of asid = asid_hi\"; simp)\n   apply (clarsimp simp: obind_def asid_hi_pool_for_asid' asid_hi_pool_for_asid)\n  apply (rule obind_eqI)\n   apply (simp add: s'_def pool_for_asid_def)\n  apply (clarsimp simp: obind_def split: option.splits)\n  done\n\nlemma vs_lookup_slot:\n  \"vs_lookup_slot level asid vref s' =\n     (if asid_high_bits_of asid = asid_hi \\<and> level = asid_pool_level\n      then Some (asid_pool_level, ap)\n      else vs_lookup_slot level asid vref s)\"\n  apply (simp add: vs_lookup_slot_def)\n  apply (rule conjI; clarsimp)\n   apply (clarsimp simp: obind_def vs_lookup_table)\n  apply (rule obind_eqI)\n   apply (clarsimp simp: vs_lookup_table)\n  apply (clarsimp simp: obind_def split: option.splits)\n  done\n\nlemma vs_lookup_target[simp]:\n  \"vs_lookup_target level asid vref s' = vs_lookup_target level asid vref s\"\n  apply (cases \"asid_high_bits_of asid = asid_hi \\<and> level = asid_pool_level\")\n   apply (simp add: vs_lookup_target_def vs_lookup_slot_def obind_def vs_lookup_table\n                    asid_hi_vs_lookup_table\n               split: option.splits)\n  apply (clarsimp simp: vs_lookup_target_def)\n  apply (rule obind_eqI)\n   apply (clarsimp simp: vs_lookup_slot)\n  apply (clarsimp simp: obind_def split: option.splits)\n  done\n\nlemma obj_at [simp]:\n  \"obj_at P p s' = obj_at P p s\"\n  by (simp add: s'_def)\n\nlemma valid_pte[simp]:\n  \"valid_pte level pte s' = valid_pte level pte s\"\n  by (cases pte; simp add: data_at_def)\n\nlemma valid_vspace_obj[simp]:\n  \"valid_vspace_obj level ao s' = valid_vspace_obj level ao s\"\n  by (cases ao; simp)\n\nlemma vspace_objs':\n  \"valid_vspace_objs s \\<Longrightarrow> valid_vspace_objs s'\"\n  using ko\n  apply (clarsimp simp: valid_vspace_objs_def vs_lookup_table)\n  apply (clarsimp simp: in_omonad)\n  done\n\nlemma global_objs':\n  \"valid_global_objs s \\<Longrightarrow> valid_global_objs s'\"\n  by (simp add: valid_global_objs_def)\n\nlemma caps_of_state_s':\n  \"caps_of_state s' = caps_of_state s\"\n  by (rule caps_of_state_pspace, simp add: s'_def)\n\nlemma valid_vs_lookup[simp]:\n  \"valid_vs_lookup s' = valid_vs_lookup s\"\n  by (clarsimp simp: valid_vs_lookup_def caps_of_state_s')\n\nlemma valid_table_caps':\n  \"valid_table_caps s \\<Longrightarrow> valid_table_caps s'\"\n  by (simp add: valid_table_caps_def caps_of_state_s' s'_def)\n\nlemma valid_asid_pool_caps':\n  \"\\<lbrakk> valid_asid_pool_caps s;\n     \\<exists>ptr cap. caps_of_state s ptr = Some cap\n     \\<and> obj_refs cap = {ap} \\<and> vs_cap_ref cap = Some (ucast asid_hi << asid_low_bits, 0) \\<rbrakk>\n  \\<Longrightarrow> valid_asid_pool_caps s'\"\n  unfolding valid_asid_pool_caps_def by (clarsimp simp: s'_def)\n\nlemma valid_arch_caps:\n  \"\\<lbrakk> valid_arch_caps s;\n     \\<exists>ptr cap. caps_of_state s ptr = Some cap\n     \\<and> obj_refs cap = {ap} \\<and> vs_cap_ref cap = Some (ucast asid_hi << asid_low_bits, 0) \\<rbrakk>\n  \\<Longrightarrow> valid_arch_caps s'\"\n  apply (simp add: valid_arch_caps_def valid_table_caps' valid_asid_pool_caps')\n  apply (simp add: caps_of_state_s')\n  done\n\nlemma valid_asid_map':\n  \"valid_asid_map s \\<Longrightarrow> valid_asid_map s'\"\n  by (clarsimp simp: valid_asid_map_def)\n\nlemma vspace_for_asid[simp]:\n  \"vspace_for_asid asid s' = vspace_for_asid asid s\"\n  using ko empty\n  by (clarsimp simp: vspace_for_asid_def obind_def pool_for_asid_def s'_def vspace_for_pool_def\n               split: option.splits)\n\nlemma global_pt[simp]:\n  \"global_pt s' = global_pt s\"\n  by (simp add: s'_def)\n\nlemma equal_kernel_mappings:\n  \"equal_kernel_mappings s' = equal_kernel_mappings s\"\n  by (simp add: equal_kernel_mappings_def has_kernel_mappings_def)\n\nend\n\n\ncontext Arch begin global_naming RISCV64\n\nlemma valid_arch_state_strg:\n  \"valid_arch_state s \\<and> ap \\<notin> ran (asid_table s) \\<and> asid_pool_at ap s \\<longrightarrow>\n   valid_arch_state (s\\<lparr>arch_state := arch_state s\\<lparr>riscv_asid_table := riscv_asid_table (arch_state s)(asid \\<mapsto> ap)\\<rparr>\\<rparr>)\"\n  apply (clarsimp simp: valid_arch_state_def)\n  apply (clarsimp simp: valid_asid_table_def ran_def)\n  apply (fastforce intro!: inj_on_fun_updI simp: asid_pools_at_eq)\n  done\n\n\nlemma valid_vs_lookup_at_upd_strg:\n  \"valid_vs_lookup s \\<and>\n   asid_pools_of s ap = Some Map.empty \\<and>\n   asid_table s asid = None\n   \\<longrightarrow>\n   valid_vs_lookup (s\\<lparr>arch_state := arch_state s\\<lparr>riscv_asid_table := (asid_table s)(asid \\<mapsto> ap)\\<rparr>\\<rparr>)\"\n  apply clarsimp\n  apply (prop_tac \"asid_update ap asid s\", (unfold_locales; assumption))\n  apply (simp add: asid_update.valid_vs_lookup)\n  done\n\nlemma valid_asid_pool_caps_upd_strg:\n  \"valid_asid_pool_caps s \\<and>\n   asid_pools_of s ap = Some Map.empty \\<and>\n   asid_table s asid = None \\<and>\n   (\\<exists>ptr cap. caps_of_state s ptr = Some cap\n     \\<and> obj_refs cap = {ap} \\<and> vs_cap_ref cap = Some (ucast asid << asid_low_bits, 0))\n   \\<longrightarrow>\n   valid_asid_pool_caps_2 (caps_of_state s) (asid_table s(asid \\<mapsto> ap))\"\n  apply clarsimp\n  apply (prop_tac \"asid_update ap asid s\", (unfold_locales; assumption))\n  apply (fastforce dest: asid_update.valid_asid_pool_caps')\n  done\n\nlemma retype_region_ap[wp]:\n  \"\\<lbrace>\\<top>\\<rbrace>\n  retype_region ap (Suc 0) 0 (ArchObject ASIDPoolObj) dev\n  \\<lbrace>\\<lambda>_ s. asid_pools_of s ap = Some Map.empty\\<rbrace>\"\n  apply (rule hoare_post_imp)\n   prefer 2\n   apply (rule retype_region_obj_at)\n    apply simp\n   apply simp\n  apply (clarsimp simp: retype_addrs_def obj_bits_api_def default_arch_object_def)\n  apply (clarsimp simp: obj_at_def default_object_def default_arch_object_def in_omonad)\n  done\n\n\nlemma retype_region_ako[wp]:\n  \"\\<lbrace>\\<top>\\<rbrace> retype_region ap (Suc 0) 0 (ArchObject ASIDPoolObj) dev \\<lbrace>\\<lambda>_. ako_at (ASIDPool Map.empty) ap\\<rbrace>\"\n  apply (rule hoare_strengthen_post, rule retype_region_ap)\n  apply (simp add: obj_at_def in_omonad)\n  done\n\nlemma retype_region_ap':\n  \"\\<lbrace>\\<top>\\<rbrace> retype_region ap (Suc 0) 0 (ArchObject ASIDPoolObj) dev \\<lbrace>\\<lambda>rv. asid_pool_at ap\\<rbrace>\"\n  apply (rule hoare_strengthen_post, rule retype_region_ap)\n  apply (simp add: asid_pools_at_eq)\n  done\n\n\nlemma no_cap_to_obj_with_diff_ref_null_filter:\n  \"no_cap_to_obj_with_diff_ref cap S\n     = (\\<lambda>s. \\<forall>c \\<in> ran (null_filter (caps_of_state s) |` (- S)).\n             obj_refs c = obj_refs cap\n                 \\<longrightarrow> table_cap_ref c = table_cap_ref cap)\"\n  apply (simp add: no_cap_to_obj_with_diff_ref_def\n                   ball_ran_eq cte_wp_at_caps_of_state)\n  apply (simp add: Ball_def)\n  apply (intro iff_allI ext)\n  apply (simp add: restrict_map_def null_filter_def)\n  apply (auto dest!: obj_ref_none_no_asid[rule_format]\n               simp: table_cap_ref_def)\n  done\n\n\nlemma retype_region_no_cap_to_obj:\n  \"\\<lbrace>valid_pspace and valid_mdb\n             and caps_overlap_reserved {ptr..ptr + 2 ^ obj_bits_api ty us - 1}\n             and caps_no_overlap ptr sz\n             and pspace_no_overlap_range_cover ptr sz\n             and no_cap_to_obj_with_diff_ref cap S\n             and (\\<lambda>s. \\<exists>slot. cte_wp_at (\\<lambda>c. up_aligned_area ptr sz \\<subseteq> cap_range c \\<and> cap_is_device c = dev) slot s)\n             and K (ty = CapTableObject \\<longrightarrow> 0 < us)\n             and K (range_cover ptr sz (obj_bits_api ty us) 1) \\<rbrace>\n     retype_region ptr 1 us ty dev\n   \\<lbrace>\\<lambda>rv. no_cap_to_obj_with_diff_ref cap S\\<rbrace>\"\n  apply (rule hoare_gen_asm)+\n  apply (simp add: no_cap_to_obj_with_diff_ref_null_filter)\n  apply (wp retype_region_caps_of | simp)+\n  apply fastforce\n  done\n\n\nlemma valid_table_caps_asid_upd [iff]:\n  \"valid_table_caps (s\\<lparr>arch_state := (riscv_asid_table_update f (arch_state s))\\<rparr>) =\n   valid_table_caps s\"\n  by (simp add: valid_table_caps_def second_level_tables_def)\n\nlemma set_cap_reachable_pg_cap:\n  \"set_cap cap' slot \\<lbrace>\\<lambda>s. P (reachable_frame_cap cap s)\\<rbrace>\"\n  unfolding reachable_frame_cap_def reachable_target_def vs_lookup_target_def\n  apply (clarsimp simp: in_omonad vs_lookup_slot_def vs_lookup_table_def)\n  apply (wp_pre, wps, wp)\n  apply simp\n  done\n\nlemma set_cap_reachable_target[wp]:\n  \"set_cap cap slot \\<lbrace>\\<lambda>s. P (reachable_target ref p s)\\<rbrace>\"\n  apply (clarsimp simp: reachable_target_def split_def)\n  apply (wp_pre, wps, wp)\n  apply simp\n  done\n\nlemma cap_insert_simple_arch_caps_ap:\n  \"\\<lbrace>valid_arch_caps and (\\<lambda>s. cte_wp_at (safe_parent_for (cdt s) src cap) src s)\n     and no_cap_to_obj_with_diff_ref cap {dest}\n     and (\\<lambda>s. asid_table s (asid_high_bits_of asid) = None \\<and> asid_pools_of s ap = Some Map.empty)\n     and K (cap = ArchObjectCap (ASIDPoolCap ap asid) \\<and> is_aligned asid asid_low_bits) \\<rbrace>\n     cap_insert cap src dest\n   \\<lbrace>\\<lambda>rv s. valid_arch_caps (s\\<lparr>arch_state := arch_state s\n                       \\<lparr>riscv_asid_table := riscv_asid_table (arch_state s)(asid_high_bits_of asid \\<mapsto> ap)\\<rparr>\\<rparr>)\\<rbrace>\"\n  apply (simp add: cap_insert_def update_cdt_def set_cdt_def valid_arch_caps_def\n                   set_untyped_cap_as_full_def bind_assoc)\n  apply (strengthen valid_vs_lookup_at_upd_strg valid_asid_pool_caps_upd_strg)\n  apply (wp get_cap_wp set_cap_valid_vs_lookup set_cap_arch_obj\n            set_cap_valid_table_caps hoare_vcg_all_lift\n          | simp split del: if_split)+\n       apply (simp add: F)\n       apply (rule_tac P = \"cte_wp_at ((=) src_cap) src\" in set_cap_orth)\n       apply (wp hoare_vcg_imp_lift hoare_vcg_ball_lift set_free_index_final_cap hoare_vcg_all_lift\n                 hoare_vcg_disj_lift set_cap_reachable_pg_cap set_cap.vs_lookup_pages\n              | clarsimp)+\n      apply (wp set_cap_arch_obj set_cap_valid_table_caps hoare_vcg_ball_lift\n                get_cap_wp static_imp_wp)+\n  apply (clarsimp simp: cte_wp_at_caps_of_state is_cap_simps)\n  apply (rule conjI)\n   apply (clarsimp simp: vs_cap_ref_def)\n   apply (rule_tac x=\"fst dest\" in exI)\n   apply (rule_tac x=\"snd dest\" in exI)\n   apply (simp add: asid_high_bits_shl)\n  apply (rule conjI)\n   apply (simp add: unique_table_caps_def is_cap_simps)\n  apply (subst unique_table_refs_def)\n  apply (intro allI impI)\n  apply (simp split: if_split_asm)\n    apply (simp add: no_cap_to_obj_with_diff_ref_def cte_wp_at_caps_of_state)\n   apply (simp add: no_cap_to_obj_with_diff_ref_def cte_wp_at_caps_of_state)\n  apply (erule (3) unique_table_refsD)\n  done\n\nlemma valid_asid_map_asid_upd_strg:\n  \"valid_asid_map s \\<and>\n   asid_pools_of s ap = Some Map.empty \\<and>\n   asid_table s asid = None \\<longrightarrow>\n   valid_asid_map (asid_table_update asid ap s)\"\n  by (simp add: valid_asid_map_def)\n\nlemma valid_vspace_objs_asid_upd_strg:\n  \"valid_vspace_objs s \\<and>\n   asid_pools_of s ap = Some Map.empty \\<and>\n   asid_table s asid = None \\<longrightarrow>\n   valid_vspace_objs (asid_table_update asid ap s)\"\n  apply clarsimp\n  apply (prop_tac \"asid_update ap asid s\", (unfold_locales; assumption))\n  apply (erule (1) asid_update.vspace_objs')\n  done\n\nlemma valid_global_objs_asid_upd_strg:\n  \"valid_global_objs s \\<and>\n   asid_pools_of s ap = Some Map.empty \\<and>\n   asid_table s asid = None \\<longrightarrow>\n   valid_global_objs (asid_table_update asid ap s)\"\n  by (clarsimp simp: valid_global_objs_def)\n\nlemma equal_kernel_mappings_asid_upd_strg:\n  \"equal_kernel_mappings s \\<and>\n   asid_pools_of s ap = Some Map.empty \\<and>\n   asid_table s asid = None \\<longrightarrow>\n   equal_kernel_mappings (asid_table_update asid ap s)\"\n  apply clarsimp\n  apply (prop_tac \"asid_update ap asid s\", (unfold_locales; assumption))\n  apply (simp add: asid_update.equal_kernel_mappings)\n  done\n\nlemma safe_parent_cap_is_device:\n  \"safe_parent_for m p cap pcap \\<Longrightarrow> cap_is_device cap = cap_is_device pcap\"\n  by (simp add: safe_parent_for_def)\n\nlemma cap_insert_ioports_ap:\n  \"\\<lbrace>valid_ioports and (\\<lambda>s. cte_wp_at (\\<lambda>cap'. safe_ioport_insert cap cap' s) dest s) and\n        K (is_ap_cap cap)\\<rbrace>\n     cap_insert cap src dest\n   \\<lbrace>\\<lambda>rv. valid_ioports\\<rbrace>\"\n  by wpsimp\n\ncrunches cap_insert\n  for aobjs_of[wp]: \"\\<lambda>s. P (aobjs_of s)\"\n  (wp: crunch_wps)\n\nlemma cap_insert_ap_invs:\n  \"\\<lbrace>invs and valid_cap cap and tcb_cap_valid cap dest and\n    ex_cte_cap_wp_to (appropriate_cte_cap cap) dest and\n    cte_wp_at (\\<lambda>c. c = NullCap) dest and\n    no_cap_to_obj_with_diff_ref cap {dest} and\n    (\\<lambda>s. cte_wp_at (safe_parent_for (cdt s) src cap) src s) and\n    K (cap = ArchObjectCap (ASIDPoolCap ap asid)) and\n   (\\<lambda>s. \\<forall>irq \\<in> cap_irqs cap. irq_issued irq s) and\n   ko_at (ArchObj (ASIDPool Map.empty)) ap and\n   (\\<lambda>s. ap \\<notin> ran (riscv_asid_table (arch_state s)) \\<and>\n        asid_table s (asid_high_bits_of asid) = None)\\<rbrace>\n  cap_insert cap src dest\n  \\<lbrace>\\<lambda>rv s. invs (s\\<lparr>arch_state := arch_state s\n                       \\<lparr>riscv_asid_table := (riscv_asid_table \\<circ> arch_state) s(asid_high_bits_of asid \\<mapsto> ap)\\<rparr>\\<rparr>)\\<rbrace>\"\n  apply (simp add: invs_def valid_state_def valid_pspace_def)\n  apply (strengthen valid_arch_state_strg valid_vspace_objs_asid_upd_strg\n                    equal_kernel_mappings_asid_upd_strg valid_asid_map_asid_upd_strg\n                    valid_global_objs_asid_upd_strg)\n  apply (simp cong: conj_cong)\n  apply (rule hoare_pre)\n   apply (wp cap_insert_simple_mdb cap_insert_iflive\n             cap_insert_zombies cap_insert_ifunsafe cap_insert_ioports_ap\n             cap_insert_valid_global_refs cap_insert_idle\n             valid_irq_node_typ cap_insert_simple_arch_caps_ap)\n  apply (clarsimp simp: is_simple_cap_def cte_wp_at_caps_of_state is_cap_simps)\n  apply (frule safe_parent_cap_is_device)\n  apply (drule safe_parent_cap_range)\n  apply (simp add: is_simple_cap_arch_def)\n  apply (rule conjI)\n   prefer 2\n   apply (clarsimp simp: obj_at_def a_type_def in_omonad)\n   apply (clarsimp simp: valid_cap_def)\n  apply (clarsimp simp: cte_wp_at_caps_of_state)\n  apply (drule_tac p=\"(a,b)\" in caps_of_state_valid_cap, fastforce)\n  apply (auto simp: obj_at_def is_tcb_def is_cap_table_def\n                    valid_cap_def [where c=\"cap.Zombie a b x\" for a b x]\n              dest: obj_ref_is_tcb obj_ref_is_cap_table split: option.splits)\n  done\n\nlemma max_index_upd_no_cap_to:\n  \"\\<lbrace>\\<lambda>s. no_cap_to_obj_with_diff_ref cap {slot} s \\<and>\n        cte_wp_at ((=) ucap) cref s \\<and> is_untyped_cap ucap\\<rbrace>\n   set_cap (max_free_index_update ucap) cref\n   \\<lbrace>\\<lambda>rv s. no_cap_to_obj_with_diff_ref cap {slot} s \\<rbrace>\"\n  apply (clarsimp simp:no_cap_to_obj_with_diff_ref_def)\n  apply (wp hoare_vcg_ball_lift set_cap_cte_wp_at_neg)\n  apply (clarsimp simp:cte_wp_at_caps_of_state free_index_update_def is_cap_simps)\n  apply (drule_tac x = cref in bspec)\n   apply clarsimp\n  apply (clarsimp simp:table_cap_ref_def)\n  done\n\nlemma perform_asid_control_invocation_pred_tcb_at:\n  \"\\<lbrace>\\<lambda>s. pred_tcb_at proj Q t s \\<and> st_tcb_at ((Not \\<circ> inactive) and (Not \\<circ> idle)) t s\n        \\<and> ct_active s \\<and> invs s \\<and> valid_aci aci s\\<rbrace>\n   perform_asid_control_invocation aci\n   \\<lbrace>\\<lambda>_. pred_tcb_at proj Q t\\<rbrace>\"\n  supply\n    is_aligned_neg_mask_eq[simp del]\n    is_aligned_neg_mask_weaken[simp del]\n  apply (clarsimp simp: perform_asid_control_invocation_def split: asid_control_invocation.splits)\n  apply (rename_tac word1 a b aa ba word2)\n  apply (rule hoare_name_pre_state)\n  apply (subgoal_tac \"is_aligned word1 page_bits\")\n   prefer 2\n   apply (clarsimp simp: valid_aci_def cte_wp_at_caps_of_state)\n   apply (drule(1) caps_of_state_valid[rotated])+\n   apply (simp add:valid_cap_simps cap_aligned_def page_bits_def)\n  apply (subst delete_objects_rewrite)\n     apply (simp add:page_bits_def word_bits_def pageBits_def word_size_bits_def)+\n   apply (simp add:is_aligned_neg_mask_eq)\n  apply (wp hoare_vcg_const_imp_lift retype_region_st_tcb_at[where sz=page_bits] set_cap_no_overlap|simp)+\n     apply (strengthen invs_valid_objs invs_psp_aligned)\n     apply (clarsimp simp:conj_comms)\n     apply (wp max_index_upd_invs_simple get_cap_wp)+\n  apply (clarsimp simp: valid_aci_def)\n  apply (frule intvl_range_conv)\n   apply (simp add:word_bits_def page_bits_def pageBits_def)\n  apply (clarsimp simp:detype_clear_um_independent page_bits_def is_aligned_neg_mask_eq)\n  apply (rule conjI)\n  apply (clarsimp simp:cte_wp_at_caps_of_state)\n   apply (simp only: field_simps)\n   apply (rule pspace_no_overlap_detype')\n     apply (rule caps_of_state_valid_cap)\n      apply (simp add:page_bits_def)+\n    apply (simp add:invs_valid_objs invs_psp_aligned)+\n  apply (rule conjI)\n   apply (frule st_tcb_ex_cap)\n     apply clarsimp\n    apply (clarsimp split: Structures_A.thread_state.splits)\n   apply (clarsimp simp: ex_nonz_cap_to_def)\n   apply (frule invs_untyped_children)\n   apply (clarsimp simp:cte_wp_at_caps_of_state)\n   apply (erule_tac ptr=\"(aa,ba)\" in untyped_children_in_mdbE[where P=\"\\<lambda>c. t \\<in> zobj_refs c\" for t])\n       apply (simp add: cte_wp_at_caps_of_state)+\n      apply fastforce\n    apply (clarsimp simp: zobj_refs_to_obj_refs)\n    apply (fastforce simp:page_bits_def)\n   apply simp\n  apply (clarsimp simp:obj_bits_api_def arch_kobj_size_def cte_wp_at_caps_of_state\n    default_arch_object_def empty_descendants_range_in)\n  apply (frule_tac cap = \"(cap.UntypedCap False word1 pageBits idx)\"\n    in detype_invariants[rotated 3],clarsimp+)\n    apply (simp add:cte_wp_at_caps_of_state\n      empty_descendants_range_in descendants_range_def2)+\n  apply (thin_tac \"x = Some cap.NullCap\" for x)+\n  apply (drule(1) caps_of_state_valid_cap[OF _ invs_valid_objs])\n  apply (intro conjI)\n    apply (clarsimp simp:valid_cap_def cap_aligned_def range_cover_full\n     invs_psp_aligned invs_valid_objs page_bits_def)\n   apply (erule pspace_no_overlap_detype)\n  apply (auto simp:page_bits_def detype_clear_um_independent)\n  done\n\nlemma perform_asid_control_invocation_st_tcb_at:\n  \"\\<lbrace>st_tcb_at (P and (Not \\<circ> inactive) and (Not \\<circ> idle)) t\n    and ct_active and invs and valid_aci aci\\<rbrace>\n   perform_asid_control_invocation aci\n   \\<lbrace>\\<lambda>_. st_tcb_at P t\\<rbrace>\"\n  apply (wpsimp wp: perform_asid_control_invocation_pred_tcb_at)\n  apply (fastforce simp: pred_tcb_at_def obj_at_def)\n  done\n\nlemma set_cap_idx_up_aligned_area:\n  \"\\<lbrace>K (\\<exists>idx. pcap = UntypedCap dev ptr pageBits idx) and cte_wp_at ((=) pcap) slot\n      and valid_objs\\<rbrace> set_cap (max_free_index_update pcap) slot\n  \\<lbrace>\\<lambda>rv s. (\\<exists>slot. cte_wp_at (\\<lambda>c. up_aligned_area ptr pageBits \\<subseteq> cap_range c \\<and> cap_is_device c = dev) slot s)\\<rbrace>\"\n  apply (rule hoare_pre)\n  apply (wp hoare_vcg_ex_lift set_cap_cte_wp_at)\n  apply (rule_tac x = slot in exI)\n  apply clarsimp\n  apply (frule(1) cte_wp_valid_cap)\n  apply (clarsimp simp: cte_wp_at_caps_of_state p_assoc_help valid_cap_def valid_untyped_def\n                        cap_aligned_def)\n  done\n\nprimrec(nonexhaustive)\n  get_untyped_cap_idx :: \"cap \\<Rightarrow> nat\"\nwhere\n  \"get_untyped_cap_idx (UntypedCap dev ref sz idx) = idx\"\n\nlemma aci_invs':\n  assumes Q_ignores_arch[simp]: \"\\<And>f s. Q (arch_state_update f s) = Q s\"\n  assumes Q_ignore_machine_state[simp]: \"\\<And>f s. Q (machine_state_update f s) = Q s\"\n  assumes Q_detype[simp]: \"\\<And>f s. Q (detype f s) = Q s\"\n  assumes cap_insert_Q: \"\\<And>cap src dest. \\<lbrace>Q and invs and K (src \\<noteq> dest)\\<rbrace>\n                            cap_insert cap src dest\n                           \\<lbrace>\\<lambda>_.Q\\<rbrace>\"\n  assumes retype_region_Q[wp]:\"\\<And>a b c d e. \\<lbrace>Q\\<rbrace> retype_region a b c d e \\<lbrace>\\<lambda>_.Q\\<rbrace>\"\n  assumes set_cap_Q[wp]: \"\\<And>a b. \\<lbrace>Q\\<rbrace> set_cap a b \\<lbrace>\\<lambda>_.Q\\<rbrace>\"\n  shows \"\\<lbrace>invs and Q and ct_active and valid_aci aci\\<rbrace> perform_asid_control_invocation aci \\<lbrace>\\<lambda>y s. invs s \\<and> Q s\\<rbrace>\"\nproof -\n  have cap_insert_invsQ:\n       \"\\<And>cap src dest ap asid.\n        \\<lbrace>Q and (invs and valid_cap cap and tcb_cap_valid cap dest and\n         ex_cte_cap_wp_to (appropriate_cte_cap cap) dest and\n         cte_wp_at (\\<lambda>c. c = NullCap) dest and\n         no_cap_to_obj_with_diff_ref cap {dest} and\n         (\\<lambda>s. cte_wp_at (safe_parent_for (cdt s) src cap) src s) and\n         K (cap = ArchObjectCap (ASIDPoolCap ap asid)) and\n         (\\<lambda>s. \\<forall>irq\\<in>cap_irqs cap. irq_issued irq s) and\n         ko_at (ArchObj (ASIDPool Map.empty)) ap and\n         (\\<lambda>s. ap \\<notin> ran (asid_table s) \\<and> asid_table s (asid_high_bits_of asid) = None))\\<rbrace>\n         cap_insert cap src dest\n        \\<lbrace>\\<lambda>rv s.\n           invs\n             (s\\<lparr>arch_state := arch_state s\n                 \\<lparr>riscv_asid_table := (riscv_asid_table \\<circ> arch_state) s\n                    (asid_high_bits_of asid \\<mapsto> ap)\\<rparr>\\<rparr>) \\<and>\n           Q\n             (s\\<lparr>arch_state := arch_state s\n                 \\<lparr>riscv_asid_table := (riscv_asid_table \\<circ> arch_state) s\n                    (asid_high_bits_of asid \\<mapsto> ap)\\<rparr>\\<rparr>)\\<rbrace>\"\n    apply (wp cap_insert_ap_invs)\n     apply simp\n     apply (rule hoare_pre)\n      apply (rule cap_insert_Q, assumption)\n    apply (auto simp: cte_wp_at_caps_of_state)\n    done\n  show ?thesis\n    apply (clarsimp simp: perform_asid_control_invocation_def valid_aci_def\n                    split: asid_control_invocation.splits)\n    apply (rename_tac word1 a b aa ba word2)\n    apply (rule hoare_pre)\n     apply (wp hoare_vcg_const_imp_lift)\n         apply (wp cap_insert_invsQ hoare_vcg_ex_lift | simp)+\n        apply (simp add: valid_cap_def |\n               strengthen real_cte_tcb_valid safe_parent_strg\n                          invs_vobjs_strgs\n                          ex_cte_cap_to_cnode_always_appropriate_strg)+\n        apply (wp hoare_vcg_const_imp_lift set_free_index_invs\n                  retype_region_plain_invs[where sz = pageBits]\n                  retype_cte_wp_at[where sz = pageBits] hoare_vcg_ex_lift\n                  retype_region_obj_at_other3[where P=\"is_cap_table n\" and sz = pageBits for n]\n                  retype_region_ex_cte_cap_to[where sz = pageBits]\n                  retype_region_ap[simplified]\n                  retype_region_ap'[simplified]\n                  retype_region_no_cap_to_obj[where sz = pageBits,simplified]\n               | simp del: split_paired_Ex)+\n       apply (strengthen invs_valid_objs invs_psp_aligned\n              invs_mdb invs_valid_pspace\n              exI[where x=\"case aci of MakePool frame slot parent base \\<Rightarrow> parent\"]\n              exI[where x=\"case aci of MakePool frame slot parent base \\<Rightarrow> parent\",\n                simplified]\n              caps_region_kernel_window_imp[where\n                p = \"case aci of MakePool frame slot parent base \\<Rightarrow> parent\"]\n              invs_cap_refs_in_kernel_window)+\n       apply (wp set_cap_caps_no_overlap set_cap_no_overlap get_cap_wp\n                 max_index_upd_caps_overlap_reserved max_index_upd_invs_simple\n                 set_cap_cte_cap_wp_to set_cap_cte_wp_at max_index_upd_no_cap_to\n              | simp split del: if_split | wp (once) hoare_vcg_ex_lift)+\n     apply (rule_tac P = \"is_aligned word1 page_bits\" in hoare_gen_asm)\n     apply (subst delete_objects_rewrite)\n        apply (simp add:page_bits_def pageBits_def word_size_bits_def)\n       apply (simp add:page_bits_def pageBits_def word_bits_def)\n      apply (simp add: page_bits_def)\n     apply wp\n    apply (clarsimp simp: cte_wp_at_caps_of_state if_option_Some\n               split del: if_split)\n    apply (frule_tac cap = \"(cap.UntypedCap False word1 pageBits idx)\"\n                     in detype_invariants[rotated 3],clarsimp+)\n       apply (simp add:cte_wp_at_caps_of_state)+\n     apply (simp add:descendants_range_def2 empty_descendants_range_in)\n    apply (simp add:invs_mdb invs_valid_pspace invs_psp_aligned invs_valid_objs)\n    apply (clarsimp dest!:caps_of_state_cteD)\n    apply (frule(1) unsafe_protected[where p=t and p'=t for t])\n        apply (simp add:empty_descendants_range_in)+\n      apply fastforce\n     apply clarsimp\n    apply (frule_tac p = \"(aa,ba)\" in cte_wp_valid_cap)\n     apply fastforce\n    apply (clarsimp simp: detype_clear_um_independent obj_bits_api_def arch_kobj_size_def\n                          default_arch_object_def conj_comms)\n    apply (rule conjI)\n     apply (clarsimp simp:valid_cap_simps cap_aligned_def page_bits_def not_le)\n    apply (simp add:empty_descendants_range_in)\n    apply (frule valid_cap_aligned)\n    apply (clarsimp simp: cap_aligned_def)\n    apply (subst caps_no_overlap_detype[OF descendants_range_caps_no_overlapI],\n           assumption, simp,\n           simp add: empty_descendants_range_in)\n    apply (frule pspace_no_overlap_detype, clarify+)\n    apply (frule intvl_range_conv[where bits = pageBits])\n     apply (simp add:pageBits_def word_bits_def)\n    apply (clarsimp simp: page_bits_def)\n    apply (frule(1) ex_cte_cap_protects)\n        apply (simp add:empty_descendants_range_in)\n       apply fastforce\n      apply (rule subset_refl)\n     apply fastforce\n    apply (clarsimp simp: field_simps)\n    apply (intro conjI impI;\n           simp add: free_index_of_def valid_cap_simps valid_untyped_def\n                     empty_descendants_range_in range_cover_full clear_um_def max_free_index_def;\n           clarsimp simp:valid_untyped_def valid_cap_simps)\n       apply (clarsimp simp: cte_wp_at_caps_of_state)\n      apply (erule(1) cap_to_protected)\n       apply (simp add:empty_descendants_range_in descendants_range_def2)+\n     apply (drule invs_arch_state)+\n     apply (clarsimp simp: valid_arch_state_def valid_asid_table_def)\n     apply (drule (1) subsetD)+\n     apply (clarsimp simp: in_opt_map_eq)\n     apply (erule notE, erule is_aligned_no_overflow)\n    apply (clarsimp simp: no_cap_to_obj_with_diff_ref_def)\n    apply (thin_tac \"cte_wp_at ((=) cap.NullCap) p s\" for p s)\n    apply (subst(asm) eq_commute,\n           erule(1) untyped_children_in_mdbE[where cap=\"cap.UntypedCap dev p bits idx\" for dev p bits idx,\n                                             simplified, rotated])\n      apply (simp add: is_aligned_no_overflow)\n     apply simp\n    apply clarsimp\n  done\n\nqed\n\n\nlemmas aci_invs[wp] =\n  aci_invs'[where Q=\\<top>,simplified hoare_post_taut, OF refl refl refl TrueI TrueI TrueI,simplified]\n\nlemma invoke_arch_invs[wp]:\n  \"\\<lbrace>invs and ct_active and valid_arch_inv ai\\<rbrace>\n   arch_perform_invocation ai\n   \\<lbrace>\\<lambda>rv. invs\\<rbrace>\"\n  apply (cases ai, simp_all add: valid_arch_inv_def arch_perform_invocation_def)\n  apply (wp|simp)+\n  done\n\nlemma sts_aobjs_of[wp]:\n  \"set_thread_state t st \\<lbrace>\\<lambda>s. P (aobjs_of s)\\<rbrace>\"\n  unfolding set_thread_state_def\n  apply (wpsimp wp: set_object_wp)\n  apply (erule rsubst[where P=P])\n  apply (auto dest!: get_tcb_SomeD simp: opt_map_def split: option.splits)\n  done\n\ncrunches set_thread_state\n  for pool_for_asid[wp]: \"\\<lambda>s. P (pool_for_asid asid s)\"\n  (wp: assert_inv)\n\nlemma sts_vspace_for_asid[wp]:\n  \"set_thread_state t st \\<lbrace>\\<lambda>s. P (vspace_for_asid asid s)\\<rbrace>\"\n  apply (simp add: vspace_for_asid_def obind_def split: option.splits)\n  apply (rule conjI; wpsimp wp: hoare_vcg_all_lift hoare_vcg_imp_lift)\n  done\n\nlemma sts_vspace_at_asid[wp]:\n  \"set_thread_state t st \\<lbrace>vspace_at_asid asid pd\\<rbrace>\"\n  unfolding vspace_at_asid_def by wpsimp\n\nlemma sts_valid_slots_inv[wp]:\n  \"set_thread_state t st \\<lbrace>valid_slots m\\<rbrace>\"\n  unfolding valid_slots_def\n  apply (cases m)\n  apply (wpsimp wp: hoare_vcg_all_lift hoare_vcg_imp_lift' sts_typ_ats)\n  apply fastforce\n  done\n\nlemma sts_same_ref[wp]:\n  \"set_thread_state t st \\<lbrace>\\<lambda>s. P (same_ref ref cap s)\\<rbrace>\"\n  unfolding same_ref_def by (cases ref) (wpsimp simp: vs_lookup_slot_def in_omonad)\n\nlemma sts_valid_page_inv[wp]:\n  \"set_thread_state t st \\<lbrace>valid_page_inv page_invocation\\<rbrace>\"\n  unfolding valid_page_inv_def\n  apply (cases page_invocation)\n    apply (wpsimp wp: sts_typ_ats hoare_vcg_ex_lift hoare_vcg_disj_lift | wps)+\n  done\n\ncrunch global_refs_inv[wp]: set_thread_state \"\\<lambda>s. P (global_refs s)\"\n\nlemma sts_vs_lookup_slot[wp]:\n  \"set_thread_state t st \\<lbrace>\\<lambda>s. P (vs_lookup_slot level asid vref s)\\<rbrace>\"\n  by (simp add: vs_lookup_slot_def obind_def split: option.splits) wpsimp\n\nlemma sts_valid_vspace_table_inv[wp]:\n  \"set_thread_state t st \\<lbrace>valid_pti i\\<rbrace>\"\n  unfolding valid_pti_def\n  by (cases i; wpsimp wp: sts_typ_ats hoare_vcg_ex_lift hoare_vcg_all_lift\n                      simp: invalid_pte_at_def aobjs_of_ako_at_Some[symmetric])\n\nlemma sts_valid_arch_inv:\n  \"set_thread_state t st \\<lbrace>valid_arch_inv ai\\<rbrace>\"\n  apply (cases ai; simp add: valid_arch_inv_def; wp?)\n   apply (rename_tac asid_control_invocation)\n   apply (case_tac asid_control_invocation)\n   apply (clarsimp simp: valid_aci_def cte_wp_at_caps_of_state)\n   apply (rule hoare_pre, wp hoare_vcg_ex_lift cap_table_at_typ_at)\n   apply clarsimp\n  apply (clarsimp simp: valid_apinv_def split: asid_pool_invocation.splits)\n  apply (rule hoare_pre)\n   apply (wp hoare_vcg_ex_lift set_thread_state_ko)\n  apply (clarsimp simp: is_tcb_def)\n  done\n\n\ncrunch_ignore (add: select_ext find_vspace_for_asid)\n\n\ncrunch inv [wp]: arch_decode_invocation \"P\"\n  (wp: crunch_wps select_wp select_ext_weak_wp simp: crunch_simps)\n\n\ndeclare lookup_slot_for_cnode_op_cap_to [wp]\n\n\nlemma shiftr_irrelevant:\n  \"x < 2 ^ asid_low_bits \\<Longrightarrow> is_aligned (y :: machine_word) asid_low_bits \\<Longrightarrow>\n    x + y >> asid_low_bits = y >> asid_low_bits\"\n  apply (subst word_plus_and_or_coroll)\n   apply (rule word_eqI)\n   apply (clarsimp simp: is_aligned_nth)\n   apply (drule(1) nth_bounded)\n    apply (simp add: asid_low_bits_def word_bits_def)\n   apply simp\n  apply (rule word_eqI)\n  apply (simp add: nth_shiftr)\n  apply safe\n  apply (drule(1) nth_bounded)\n   apply (simp add: asid_low_bits_def word_bits_def)\n  apply simp\n  done\n\n\ndeclare mask_shift [simp]\ndeclare word_less_sub_le [simp del]\ndeclare ptrFormPAddr_addFromPPtr [simp]\n\n\nlemma le_user_vtop_less_pptr_base[simp]:\n  \"x \\<le> user_vtop \\<Longrightarrow> x < pptr_base\"\n  using dual_order.strict_trans2 by blast\n\nlemmas le_user_vtop_canonical_address = below_user_vtop_canonical[simp]\n\nlemma ptrFromPAddr_addr_from_ppn:\n  \"is_aligned pt_ptr table_size \\<Longrightarrow>\n   ptrFromPAddr (addr_from_ppn (ucast (addrFromPPtr pt_ptr >> pageBits))) = pt_ptr\"\n  apply (simp add: addr_from_ppn_def ucast_ucast_mask bit_simps)\n  apply (frule is_aligned_addrFromPPtr[simplified bit_simps])\n  apply (simp add: aligned_shiftr_mask_shiftl mask_len_id[where 'a=machine_word_len, simplified])\n  done\n\nlemma ptrFromPAddr_addr_from_ppn':\n  \"is_aligned pt_ptr pt_bits \\<Longrightarrow>\n   ptrFromPAddr (addr_from_ppn (ucast (addrFromPPtr pt_ptr >> pt_bits))) = pt_ptr\"\n  using ptrFromPAddr_addr_from_ppn by (simp add: bit_simps)\n\nlemma is_aligned_pageBitsForSize_table_size:\n  \"is_aligned p (pageBitsForSize vmpage_size) \\<Longrightarrow> is_aligned p table_size\"\n  apply (erule is_aligned_weaken)\n  apply (simp add: pbfs_atleast_pageBits[unfolded bit_simps] bit_simps)\n  done\n\nlemma vmsz_aligned_vref_for_level:\n  \"\\<lbrakk> vmsz_aligned vref sz; pt_bits_left level = pageBitsForSize sz \\<rbrakk> \\<Longrightarrow>\n   vref_for_level vref level = vref\"\n  by (simp add: vref_for_level_def vmsz_aligned_def)\n\nlemma vs_lookup_slot_pte_at:\n  \"\\<lbrakk> vs_lookup_slot level asid vref s = Some (level, pt_slot);\n     vref \\<in> user_region; level \\<le> max_pt_level; invs s \\<rbrakk> \\<Longrightarrow>\n   pte_at pt_slot s\"\n  apply (clarsimp simp: pte_at_eq vs_lookup_slot_table_unfold in_omonad)\n  apply (drule valid_vspace_objs_strongD[rotated]; clarsimp)\n  apply (clarsimp simp: ptes_of_def in_omonad)\n (* pt_slot equation does not want to substitute in clarsimp, because rhs mentions pt_slot *)\n  apply (rule subst[where P=\"\\<lambda>pt_slot. is_aligned pt_slot pte_bits\"], rule sym, assumption)\n  apply (thin_tac \"pt_slot = t\" for t)\n  apply (clarsimp simp: pt_slot_offset_def)\n  apply (rule is_aligned_add; simp add: is_aligned_shift)\n  done\n\nlemma vmpage_size_of_level_pt_bits_left:\n  \"\\<lbrakk> pt_bits_left level = pageBitsForSize vmpage_size; level \\<le> max_pt_level \\<rbrakk> \\<Longrightarrow>\n   vmpage_size_of_level level = vmpage_size\"\n  by (cases vmpage_size; simp add: vmpage_size_of_level_def pt_bits_left_def bit_simps) auto\n\nlemma is_PagePTE_make_user[simp]:\n  \"is_PagePTE (make_user_pte p attr R) \\<or> make_user_pte p attr R = InvalidPTE\"\n  by (auto simp: is_PagePTE_def make_user_pte_def)\n\nlemma decode_fr_inv_map_wf[wp]:\n  \"arch_cap = FrameCap p rights vmpage_size dev option \\<Longrightarrow>\n   \\<lbrace>invs and valid_cap (ArchObjectCap arch_cap) and\n    cte_wp_at ((=) (ArchObjectCap arch_cap)) slot and\n    (\\<lambda>s. \\<forall>x \\<in> set excaps. cte_wp_at ((=) (fst x)) (snd x) s)\\<rbrace>\n   decode_fr_inv_map label args slot arch_cap excaps\n   \\<lbrace>valid_arch_inv\\<rbrace>,-\"\n  unfolding decode_fr_inv_map_def Let_def\n  apply (wpsimp wp: check_vp_wpR split_del: if_split)\n  apply (clarsimp simp: valid_arch_inv_def valid_page_inv_def neq_Nil_conv)\n  apply (rename_tac s pt_ptr asid vref ab ba ys pt_slot level)\n  apply (prop_tac \"args!0 \\<in> user_region\")\n   apply (clarsimp simp: user_region_def not_le)\n   apply (rule user_vtop_canonical_user)\n   apply (erule aligned_add_mask_lessD)\n   apply (simp add: vmsz_aligned_def)\n  apply (clarsimp simp: cte_wp_at_caps_of_state is_arch_update_def is_cap_simps cap_master_cap_simps)\n  apply (thin_tac \"Ball S P\" for S P)\n  apply (frule (1) pt_lookup_slot_vs_lookup_slotI, clarsimp)\n  apply (clarsimp simp: valid_arch_cap_def valid_cap_def cap_aligned_def wellformed_mapdata_def)\n  apply (frule is_aligned_pageBitsForSize_table_size)\n  apply (frule (3) vs_lookup_slot_table_base)\n  apply (clarsimp simp: same_ref_def make_user_pte_def ptrFromPAddr_addr_from_ppn)\n  (* FIXME RISCV: remove duplication due to PagePTE/InvalidPTE cases: *)\n  apply (rule conjI; clarsimp)\n   apply (rule strengthen_imp_same_first_conj[OF conjI])\n    apply (rule_tac x=level in exI)\n    apply (rule_tac x=\"args!0\" in exI)\n    apply (fastforce simp: vmsz_aligned_vref_for_level)\n   apply (rule strengthen_imp_same_first_conj[OF conjI])\n    apply (clarsimp simp: valid_slots_def make_user_pte_def wellformed_pte_def\n                          ptrFromPAddr_addr_from_ppn)\n    apply (rename_tac level' asid' vref')\n    apply (frule (3) vs_lookup_slot_table_base)\n    apply (prop_tac \"level' \\<le> max_pt_level\")\n     apply (drule_tac level=level in valid_vspace_objs_strongD[rotated]; clarsimp)\n     apply (rule ccontr, clarsimp simp: not_le)\n     apply (drule vs_lookup_asid_pool; clarsimp)\n     apply (clarsimp simp: in_omonad)\n    apply (drule (1) vs_lookup_table_unique_level; clarsimp)\n    apply (simp add: vs_lookup_slot_pte_at data_at_def vmpage_size_of_level_pt_bits_left\n              split: if_split_asm)\n   apply (rule strengthen_imp_same_first_conj[OF conjI])\n    apply (clarsimp simp: wellformed_mapdata_def vspace_for_asid_def)\n   apply (clarsimp simp: parent_for_refs_def)\n   apply (frule (3) vs_lookup_slot_table_base)\n   apply (frule (2) valid_vspace_objs_strongD[rotated]; clarsimp)\n   apply (drule (1) vs_lookup_table_target)\n   apply (drule valid_vs_lookupD; clarsimp simp: vmsz_aligned_vref_for_level)\n   apply (subgoal_tac \"is_pt_cap cap\")\n    apply (force simp: is_cap_simps)\n   apply (fastforce dest: cap_to_pt_is_pt_cap intro: valid_objs_caps)\n  apply (rule strengthen_imp_same_first_conj[OF conjI])\n   apply (rule_tac x=level in exI)\n   apply (rule_tac x=\"args!0\" in exI)\n   apply (fastforce simp: vmsz_aligned_vref_for_level)\n  apply (rule strengthen_imp_same_first_conj[OF conjI])\n   apply (clarsimp simp: valid_slots_def make_user_pte_def wellformed_pte_def\n                         ptrFromPAddr_addr_from_ppn)\n   apply (rename_tac level' asid' vref')\n   apply (frule (3) vs_lookup_slot_table_base)\n   apply (prop_tac \"level' \\<le> max_pt_level\")\n    apply (drule_tac level=level in valid_vspace_objs_strongD[rotated]; clarsimp)\n    apply (rule ccontr, clarsimp simp: not_le)\n    apply (drule vs_lookup_asid_pool; clarsimp)\n    apply (clarsimp simp: in_omonad)\n   apply (drule (1) vs_lookup_table_unique_level; clarsimp)\n   apply (simp add: vs_lookup_slot_pte_at data_at_def vmpage_size_of_level_pt_bits_left\n             split: if_split_asm)\n  apply (rule strengthen_imp_same_first_conj[OF conjI])\n   apply (clarsimp simp: wellformed_mapdata_def vspace_for_asid_def)\n  apply (clarsimp simp: parent_for_refs_def)\n  apply (frule (3) vs_lookup_slot_table_base)\n  apply (frule (2) valid_vspace_objs_strongD[rotated]; clarsimp)\n  apply (drule (1) vs_lookup_table_target)\n  apply (drule valid_vs_lookupD; clarsimp simp: vmsz_aligned_vref_for_level)\n  apply (subgoal_tac \"is_pt_cap cap\")\n   apply (force simp: is_cap_simps)\n  apply (fastforce dest: cap_to_pt_is_pt_cap intro: valid_objs_caps)\n  done\n\nlemma decode_frame_invocation_wf[wp]:\n  \"arch_cap = FrameCap word rights vmpage_size dev option \\<Longrightarrow>\n   \\<lbrace>invs and valid_cap (ArchObjectCap arch_cap) and\n    cte_wp_at ((=) (ArchObjectCap arch_cap)) slot and\n    (\\<lambda>s. \\<forall>x \\<in> set excaps. cte_wp_at ((=) (fst x)) (snd x) s)\\<rbrace>\n   decode_frame_invocation label args slot arch_cap excaps\n   \\<lbrace>valid_arch_inv\\<rbrace>,-\"\n  unfolding decode_frame_invocation_def\n  by (wpsimp simp: valid_arch_inv_def valid_page_inv_def cte_wp_at_caps_of_state\n                   is_cap_simps valid_arch_cap_def valid_cap_def\n                   valid_unmap_def wellformed_mapdata_def vmsz_aligned_def\n            split: option.split)\n\nlemma neg_mask_user_region:\n  \"p \\<in> user_region \\<Longrightarrow> p && ~~mask n \\<in> user_region\"\n  apply (simp add: user_region_def canonical_user_def bit.conj_ac\n              flip: and_mask_0_iff_le_mask)\n  apply (subst bit.conj_assoc[symmetric])\n  apply simp\n  done\n\nlemma decode_pt_inv_map_wf[wp]:\n  \"arch_cap = PageTableCap pt_ptr pt_map_data \\<Longrightarrow>\n   \\<lbrace>invs and valid_cap (ArchObjectCap arch_cap) and\n    cte_wp_at ((=) (ArchObjectCap arch_cap)) slot and\n    (\\<lambda>s. \\<forall>x \\<in> set excaps. cte_wp_at ((=) (fst x)) (snd x) s)\\<rbrace>\n    decode_pt_inv_map label args slot arch_cap excaps\n   \\<lbrace>valid_arch_inv\\<rbrace>,-\"\n  unfolding decode_pt_inv_map_def Let_def\n  apply wpsimp\n  apply (clarsimp simp: valid_arch_inv_def valid_pti_def pte_at_eq invalid_pte_at_def\n                        wellformed_pte_def valid_cap_def cte_wp_at_caps_of_state)\n  apply (rename_tac p level)\n  apply (prop_tac \"args!0 \\<in> user_region\")\n   apply (simp add: wellformed_mapdata_def user_region_def user_vtop_canonical_user)\n  apply (rule conjI, clarsimp simp: valid_arch_cap_def wellformed_mapdata_def vspace_for_asid_def\n                                    neg_mask_user_region)\n  apply (rule conjI, clarsimp simp: is_arch_update_def is_cap_simps cap_master_cap_simps)\n  apply (simp add: ptrFromPAddr_addr_from_ppn cap_aligned_def)\n  apply (drule (1) pt_lookup_slot_vs_lookup_slotI)\n  apply (rule_tac x=level in exI, simp add: vm_level_not_less_zero)\n  apply (clarsimp simp: obj_at_def)\n  apply (rule conjI, clarsimp)\n  apply (drule valid_table_caps_pdD, clarsimp)\n  apply (clarsimp simp: in_omonad)\n  apply (rule_tac x=\"args!0\" in exI)\n  apply (simp add: vref_for_level_def)\n  done\n\nlemma decode_page_table_invocation_wf[wp]:\n  \"arch_cap = PageTableCap pt_ptr pt_map_data \\<Longrightarrow>\n   \\<lbrace>invs and valid_cap (ArchObjectCap arch_cap) and\n    cte_wp_at ((=) (ArchObjectCap arch_cap)) slot and real_cte_at slot and\n    (\\<lambda>s. \\<forall>x \\<in> set excaps. cte_wp_at ((=) (fst x)) (snd x) s)\\<rbrace>\n    decode_page_table_invocation label args slot arch_cap excaps\n   \\<lbrace>valid_arch_inv\\<rbrace>,-\"\n  unfolding decode_page_table_invocation_def is_final_cap_def\n  apply (wpsimp simp: valid_arch_inv_def valid_pti_def valid_arch_cap_def valid_cap_def\n                      cte_wp_at_caps_of_state is_cap_simps)\n  apply (rule conjI; clarsimp)\n  done\n\nlemma cte_wp_at_eq_simp:\n  \"cte_wp_at ((=) cap) = cte_wp_at (\\<lambda>c. c = cap)\"\n  by (force intro: arg_cong [where f=cte_wp_at])\n\nlemma asid_low_hi_cast:\n  \"is_aligned asid_hi asid_low_bits \\<Longrightarrow>\n   ucast (ucast asid_low + (asid_hi::asid)) = (asid_low :: asid_low_index)\"\n  apply (simp add: is_aligned_nth asid_low_bits_def)\n  apply (subst word_plus_and_or_coroll; word_eqI_solve)\n  done\n\nlemma decode_asid_pool_invocation_wf[wp]:\n  \"arch_cap = ASIDPoolCap ap asid \\<Longrightarrow>\n   \\<lbrace>invs and valid_cap (ArchObjectCap arch_cap) and\n    cte_wp_at ((=) (ArchObjectCap arch_cap)) slot and\n    (\\<lambda>s. \\<forall>x \\<in> set excaps. cte_wp_at ((=) (fst x)) (snd x) s) and\n    (\\<lambda>s. \\<forall>x \\<in> set excaps. s \\<turnstile> (fst x))\\<rbrace>\n   decode_asid_pool_invocation label args slot arch_cap excaps\n   \\<lbrace>valid_arch_inv\\<rbrace>, -\"\n  unfolding decode_asid_pool_invocation_def Let_def\n  apply wpsimp\n  apply (rule ccontr, erule notE[where P=\"valid_arch_inv i s\" for i s])\n  apply (clarsimp simp: valid_arch_inv_def valid_apinv_def pool_for_asid_def word_neq_0_conv\n                        cte_wp_at_caps_of_state neq_Nil_conv obj_at_def in_omonad valid_cap_def\n                        asid_low_hi_cast asid_high_bits_of_add_ucast)\n  done\n\nlemma decode_asid_control_invocation_wf[wp]:\n  \"arch_cap = ASIDControlCap \\<Longrightarrow>\n   \\<lbrace>invs and valid_cap (ArchObjectCap arch_cap) and\n    cte_wp_at ((=) (ArchObjectCap arch_cap)) slot and\n    (\\<lambda>s. \\<forall>x \\<in> set excaps. cte_wp_at ((=) (fst x)) (snd x) s) and\n    (\\<lambda>s. \\<forall>x \\<in> set excaps. s \\<turnstile> (fst x))\\<rbrace>\n   decode_asid_control_invocation label args slot ASIDControlCap excaps\n   \\<lbrace>valid_arch_inv\\<rbrace>, -\"\n  unfolding decode_asid_control_invocation_def valid_arch_inv_def\n  apply (simp add: Let_def split_def cong: if_cong split del: if_split)\n  apply ((wp whenE_throwError_wp check_vp_wpR ensure_empty_stronger\n         | wpc | simp add: valid_arch_inv_def valid_aci_def is_aligned_shiftl_self)+)[1]\n          apply (rule_tac Q'= \"\\<lambda>rv. real_cte_at rv\n                                     and ex_cte_cap_wp_to is_cnode_cap rv\n                                     and (\\<lambda>s. descendants_of (snd (excaps!0)) (cdt s) = {})\n                                     and cte_wp_at (\\<lambda>c. \\<exists>idx. c = UntypedCap False frame pageBits idx) (snd (excaps!0))\n                                     and (\\<lambda>s. riscv_asid_table (arch_state s) free = None)\"\n                  in hoare_post_imp_R)\n           apply (simp add: lookup_target_slot_def)\n           apply wp\n          apply (clarsimp simp: cte_wp_at_def)\n         apply (wpsimp wp: ensure_no_children_sp select_ext_weak_wp select_wp whenE_throwError_wp)+\n  apply (rule conjI, fastforce)\n  apply (cases excaps, simp)\n  apply (case_tac list, simp)\n  apply clarsimp\n  apply (rule conjI)\n   apply clarsimp\n   apply (simp add: ex_cte_cap_wp_to_def)\n   apply (rule_tac x=ac in exI)\n   apply (rule_tac x=ba in exI)\n   apply (clarsimp simp add: cte_wp_at_caps_of_state)\n  apply (clarsimp simp add: cte_wp_at_caps_of_state)\n  done\n\nlemma arch_decode_inv_wf[wp]:\n  \"\\<lbrace>invs and valid_cap (ArchObjectCap arch_cap) and\n    cte_wp_at ((=) (ArchObjectCap arch_cap)) slot and real_cte_at slot and\n    (\\<lambda>s. \\<forall>x \\<in> set excaps. cte_wp_at ((=) (fst x)) (snd x) s) and\n    (\\<lambda>s. \\<forall>x \\<in> set excaps. s \\<turnstile> (fst x))\\<rbrace>\n     arch_decode_invocation label args x_slot slot arch_cap excaps\n   \\<lbrace>valid_arch_inv\\<rbrace>,-\"\n  unfolding arch_decode_invocation_def by wpsimp fastforce\n\ndeclare word_less_sub_le [simp]\n\ncrunch pred_tcb_at [wp]:\n  perform_page_table_invocation, perform_page_invocation, perform_asid_pool_invocation\n  \"pred_tcb_at proj P t\"\n  (wp: crunch_wps simp: crunch_simps)\n\nlemma arch_pinv_st_tcb_at:\n  \"\\<lbrace>invs and valid_arch_inv ai and ct_active and\n    st_tcb_at (P and (Not \\<circ> inactive) and (Not \\<circ> idle)) t\\<rbrace>\n     arch_perform_invocation ai\n   \\<lbrace>\\<lambda>rv. st_tcb_at P t\\<rbrace>\"\n  apply (cases ai; simp add: arch_perform_invocation_def valid_arch_inv_def)\n  apply (wp perform_asid_control_invocation_st_tcb_at; fastforce elim!: pred_tcb_weakenE)+\n  done\n\nend\n\n\ncontext begin interpretation Arch .\n\nrequalify_consts\n  valid_arch_inv\n\nrequalify_facts\n  invoke_arch_tcb\n  invoke_arch_invs\n  sts_valid_arch_inv\n  arch_decode_inv_wf\n  arch_pinv_st_tcb_at\n\nend\n\ndeclare invoke_arch_invs[wp]\ndeclare arch_decode_inv_wf[wp]\n\nend\n", "meta": {"author": "seL4", "repo": "l4v", "sha": "9ba34e269008732d4f89fb7a7e32337ffdd09ff9", "save_path": "github-repos/isabelle/seL4-l4v", "path": "github-repos/isabelle/seL4-l4v/l4v-9ba34e269008732d4f89fb7a7e32337ffdd09ff9/proof/invariant-abstract/RISCV64/ArchArch_AI.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6893056040203135, "lm_q2_score": 0.3629692055196168, "lm_q1q2_score": 0.25019670745147277}}
{"text": "(*  Title:      HOL/Auth/TLS.thy\n    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory\n    Copyright   1997  University of Cambridge\n\nInductive relation \"tls\" for the TLS (Transport Layer Security) protocol.\nThis protocol is essentially the same as SSL 3.0.\n\nAbstracted from \"The TLS Protocol, Version 1.0\" by Tim Dierks and Christopher\nAllen, Transport Layer Security Working Group, 21 May 1997,\nINTERNET-DRAFT draft-ietf-tls-protocol-03.txt.  Section numbers below refer\nto that memo.\n\nAn RSA cryptosystem is assumed, and X.509v3 certificates are abstracted down\nto the trivial form {A, publicKey(A)}privateKey(Server), where Server is a\nglobal signing authority.\n\nA is the client and B is the server, not to be confused with the constant\nServer, who is in charge of all public keys.\n\nThe model assumes that no fraudulent certificates are present, but it does\nassume that some private keys are to the spy.\n\nREMARK.  The event \"Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace>\" appears in ClientKeyExch,\nCertVerify, ClientFinished to record that A knows M.  It is a note from A to\nherself.  Nobody else can see it.  In ClientKeyExch, the Spy can substitute\nhis own certificate for A's, but he cannot replace A's note by one for himself.\n\nThe Note event avoids a weakness in the public-key model.  Each\nagent's state is recorded as the trace of messages.  When the true client (A)\ninvents PMS, he encrypts PMS with B's public key before sending it.  The model\ndoes not distinguish the original occurrence of such a message from a replay.\nIn the shared-key model, the ability to encrypt implies the ability to\ndecrypt, so the problem does not arise.\n\nProofs would be simpler if ClientKeyExch included A's name within\nCrypt KB (Nonce PMS).  As things stand, there is much overlap between proofs\nabout that message (which B receives) and the stronger event\nNotes A \\<lbrace>Agent B, Nonce PMS\\<rbrace>.\n*)\n\nsection\\<open>The TLS Protocol: Transport Layer Security\\<close>\n\ntheory TLS imports Public \"HOL-Library.Nat_Bijection\" begin\n\ndefinition certificate :: \"[agent,key] \\<Rightarrow> msg\" where\n    \"certificate A KA == Crypt (priSK Server) \\<lbrace>Agent A, Key KA\\<rbrace>\"\n\ntext\\<open>TLS apparently does not require separate keypairs for encryption and\nsignature.  Therefore, we formalize signature as encryption using the\nprivate encryption key.\\<close>\n\ndatatype role = ClientRole | ServerRole\n\nconsts\n  (*Pseudo-random function of Section 5*)\n  PRF  :: \"nat*nat*nat \\<Rightarrow> nat\"\n\n  (*Client, server write keys are generated uniformly by function sessionK\n    to avoid duplicating their properties.  They are distinguished by a\n    tag (not a bool, to avoid the peculiarities of if-and-only-if).\n    Session keys implicitly include MAC secrets.*)\n  sessionK :: \"(nat*nat*nat) * role \\<Rightarrow> key\"\n\nabbreviation\n  clientK :: \"nat*nat*nat \\<Rightarrow> key\" where\n  \"clientK X == sessionK(X, ClientRole)\"\n\nabbreviation\n  serverK :: \"nat*nat*nat \\<Rightarrow> key\" where\n  \"serverK X == sessionK(X, ServerRole)\"\n\n\nspecification (PRF)\n  inj_PRF: \"inj PRF\"\n  \\<comment> \\<open>the pseudo-random function is collision-free\\<close>\n   apply (rule exI [of _ \"\\<lambda>(x,y,z). prod_encode(x, prod_encode(y,z))\"])\n   apply (simp add: inj_on_def prod_encode_eq)\n   done\n\nspecification (sessionK)\n  inj_sessionK: \"inj sessionK\"\n  \\<comment> \\<open>sessionK is collision-free; also, no clientK clashes with any serverK.\\<close>\n   apply (rule exI [of _ \n         \"\\<lambda>((x,y,z), r). prod_encode(case_role 0 1 r, \n                           prod_encode(x, prod_encode(y,z)))\"])\n   apply (simp add: inj_on_def prod_encode_eq split: role.split) \n   done\n\naxiomatization where\n  \\<comment> \\<open>sessionK makes symmetric keys\\<close>\n  isSym_sessionK: \"sessionK nonces \\<in> symKeys\" and\n\n  \\<comment> \\<open>sessionK never clashes with a long-term symmetric key  \n     (they don't exist in TLS anyway)\\<close>\n  sessionK_neq_shrK [iff]: \"sessionK nonces \\<noteq> shrK A\"\n\n\ninductive_set tls :: \"event list set\"\n  where\n   Nil:  \\<comment> \\<open>The initial, empty trace\\<close>\n         \"[] \\<in> tls\"\n\n | Fake: \\<comment> \\<open>The Spy may say anything he can say.  The sender field is correct,\n          but agents don't use that information.\\<close>\n         \"\\<lbrakk>evsf \\<in> tls;  X \\<in> synth (analz (spies evsf))\\<rbrakk>\n          \\<Longrightarrow> Says Spy B X # evsf \\<in> tls\"\n\n | SpyKeys: \\<comment> \\<open>The spy may apply \\<^term>\\<open>PRF\\<close> and \\<^term>\\<open>sessionK\\<close>\n                to available nonces\\<close>\n         \"\\<lbrakk>evsSK \\<in> tls;\n             {Nonce NA, Nonce NB, Nonce M} \\<subseteq> analz (spies evsSK)\\<rbrakk>\n          \\<Longrightarrow> Notes Spy \\<lbrace> Nonce (PRF(M,NA,NB)),\n                           Key (sessionK((NA,NB,M),role))\\<rbrace> # evsSK \\<in> tls\"\n\n | ClientHello:\n         \\<comment> \\<open>(7.4.1.2)\n           PA represents \\<open>CLIENT_VERSION\\<close>, \\<open>CIPHER_SUITES\\<close> and \\<open>COMPRESSION_METHODS\\<close>.\n           It is uninterpreted but will be confirmed in the FINISHED messages.\n           NA is CLIENT RANDOM, while SID is \\<open>SESSION_ID\\<close>.\n           UNIX TIME is omitted because the protocol doesn't use it.\n           May assume \\<^term>\\<open>NA \\<notin> range PRF\\<close> because CLIENT RANDOM is \n           28 bytes while MASTER SECRET is 48 bytes\\<close>\n         \"\\<lbrakk>evsCH \\<in> tls;  Nonce NA \\<notin> used evsCH;  NA \\<notin> range PRF\\<rbrakk>\n          \\<Longrightarrow> Says A B \\<lbrace>Agent A, Nonce NA, Number SID, Number PA\\<rbrace>\n                # evsCH  \\<in>  tls\"\n\n | ServerHello:\n         \\<comment> \\<open>7.4.1.3 of the TLS Internet-Draft\n           PB represents \\<open>CLIENT_VERSION\\<close>, \\<open>CIPHER_SUITE\\<close> and \\<open>COMPRESSION_METHOD\\<close>.\n           SERVER CERTIFICATE (7.4.2) is always present.\n           \\<open>CERTIFICATE_REQUEST\\<close> (7.4.4) is implied.\\<close>\n         \"\\<lbrakk>evsSH \\<in> tls;  Nonce NB \\<notin> used evsSH;  NB \\<notin> range PRF;\n             Says A' B \\<lbrace>Agent A, Nonce NA, Number SID, Number PA\\<rbrace>\n               \\<in> set evsSH\\<rbrakk>\n          \\<Longrightarrow> Says B A \\<lbrace>Nonce NB, Number SID, Number PB\\<rbrace> # evsSH  \\<in>  tls\"\n\n | Certificate:\n         \\<comment> \\<open>SERVER (7.4.2) or CLIENT (7.4.6) CERTIFICATE.\\<close>\n         \"evsC \\<in> tls \\<Longrightarrow> Says B A (certificate B (pubK B)) # evsC  \\<in>  tls\"\n\n | ClientKeyExch:\n         \\<comment> \\<open>CLIENT KEY EXCHANGE (7.4.7).\n           The client, A, chooses PMS, the PREMASTER SECRET.\n           She encrypts PMS using the supplied KB, which ought to be pubK B.\n           We assume \\<^term>\\<open>PMS \\<notin> range PRF\\<close> because a clash betweem the PMS\n           and another MASTER SECRET is highly unlikely (even though\n           both items have the same length, 48 bytes).\n           The Note event records in the trace that she knows PMS\n               (see REMARK at top).\\<close>\n         \"\\<lbrakk>evsCX \\<in> tls;  Nonce PMS \\<notin> used evsCX;  PMS \\<notin> range PRF;\n             Says B' A (certificate B KB) \\<in> set evsCX\\<rbrakk>\n          \\<Longrightarrow> Says A B (Crypt KB (Nonce PMS))\n              # Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace>\n              # evsCX  \\<in>  tls\"\n\n | CertVerify:\n        \\<comment> \\<open>The optional Certificate Verify (7.4.8) message contains the\n          specific components listed in the security analysis, F.1.1.2.\n          It adds the pre-master-secret, which is also essential!\n          Checking the signature, which is the only use of A's certificate,\n          assures B of A's presence\\<close>\n         \"\\<lbrakk>evsCV \\<in> tls;\n             Says B' A \\<lbrace>Nonce NB, Number SID, Number PB\\<rbrace> \\<in> set evsCV;\n             Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evsCV\\<rbrakk>\n          \\<Longrightarrow> Says A B (Crypt (priK A) (Hash\\<lbrace>Nonce NB, Agent B, Nonce PMS\\<rbrace>))\n              # evsCV  \\<in>  tls\"\n\n        \\<comment> \\<open>Finally come the FINISHED messages (7.4.8), confirming PA and PB\n          among other things.  The master-secret is PRF(PMS,NA,NB).\n          Either party may send its message first.\\<close>\n\n | ClientFinished:\n        \\<comment> \\<open>The occurrence of \\<open>Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace>\\<close> stops the\n          rule's applying when the Spy has satisfied the \\<open>Says A B\\<close> by\n          repaying messages sent by the true client; in that case, the\n          Spy does not know PMS and could not send ClientFinished.  One\n          could simply put \\<^term>\\<open>A\\<noteq>Spy\\<close> into the rule, but one should not\n          expect the spy to be well-behaved.\\<close>\n         \"\\<lbrakk>evsCF \\<in> tls;\n             Says A  B \\<lbrace>Agent A, Nonce NA, Number SID, Number PA\\<rbrace>\n               \\<in> set evsCF;\n             Says B' A \\<lbrace>Nonce NB, Number SID, Number PB\\<rbrace> \\<in> set evsCF;\n             Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evsCF;\n             M = PRF(PMS,NA,NB)\\<rbrakk>\n          \\<Longrightarrow> Says A B (Crypt (clientK(NA,NB,M))\n                        (Hash\\<lbrace>Number SID, Nonce M,\n                               Nonce NA, Number PA, Agent A,\n                               Nonce NB, Number PB, Agent B\\<rbrace>))\n              # evsCF  \\<in>  tls\"\n\n | ServerFinished:\n        \\<comment> \\<open>Keeping A' and A'' distinct means B cannot even check that the\n          two messages originate from the same source.\\<close>\n         \"\\<lbrakk>evsSF \\<in> tls;\n             Says A' B  \\<lbrace>Agent A, Nonce NA, Number SID, Number PA\\<rbrace>\n               \\<in> set evsSF;\n             Says B  A  \\<lbrace>Nonce NB, Number SID, Number PB\\<rbrace> \\<in> set evsSF;\n             Says A'' B (Crypt (pubK B) (Nonce PMS)) \\<in> set evsSF;\n             M = PRF(PMS,NA,NB)\\<rbrakk>\n          \\<Longrightarrow> Says B A (Crypt (serverK(NA,NB,M))\n                        (Hash\\<lbrace>Number SID, Nonce M,\n                               Nonce NA, Number PA, Agent A,\n                               Nonce NB, Number PB, Agent B\\<rbrace>))\n              # evsSF  \\<in>  tls\"\n\n | ClientAccepts:\n        \\<comment> \\<open>Having transmitted ClientFinished and received an identical\n          message encrypted with serverK, the client stores the parameters\n          needed to resume this session.  The \"Notes A ...\" premise is\n          used to prove \\<open>Notes_master_imp_Crypt_PMS\\<close>.\\<close>\n         \"\\<lbrakk>evsCA \\<in> tls;\n             Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evsCA;\n             M = PRF(PMS,NA,NB);\n             X = Hash\\<lbrace>Number SID, Nonce M,\n                       Nonce NA, Number PA, Agent A,\n                       Nonce NB, Number PB, Agent B\\<rbrace>;\n             Says A  B (Crypt (clientK(NA,NB,M)) X) \\<in> set evsCA;\n             Says B' A (Crypt (serverK(NA,NB,M)) X) \\<in> set evsCA\\<rbrakk>\n          \\<Longrightarrow>\n             Notes A \\<lbrace>Number SID, Agent A, Agent B, Nonce M\\<rbrace> # evsCA  \\<in>  tls\"\n\n | ServerAccepts:\n        \\<comment> \\<open>Having transmitted ServerFinished and received an identical\n          message encrypted with clientK, the server stores the parameters\n          needed to resume this session.  The \"Says A'' B ...\" premise is\n          used to prove \\<open>Notes_master_imp_Crypt_PMS\\<close>.\\<close>\n         \"\\<lbrakk>evsSA \\<in> tls;\n             A \\<noteq> B;\n             Says A'' B (Crypt (pubK B) (Nonce PMS)) \\<in> set evsSA;\n             M = PRF(PMS,NA,NB);\n             X = Hash\\<lbrace>Number SID, Nonce M,\n                       Nonce NA, Number PA, Agent A,\n                       Nonce NB, Number PB, Agent B\\<rbrace>;\n             Says B  A (Crypt (serverK(NA,NB,M)) X) \\<in> set evsSA;\n             Says A' B (Crypt (clientK(NA,NB,M)) X) \\<in> set evsSA\\<rbrakk>\n          \\<Longrightarrow>\n             Notes B \\<lbrace>Number SID, Agent A, Agent B, Nonce M\\<rbrace> # evsSA  \\<in>  tls\"\n\n | ClientResume:\n         \\<comment> \\<open>If A recalls the \\<open>SESSION_ID\\<close>, then she sends a FINISHED\n             message using the new nonces and stored MASTER SECRET.\\<close>\n         \"\\<lbrakk>evsCR \\<in> tls;\n             Says A  B \\<lbrace>Agent A, Nonce NA, Number SID, Number PA\\<rbrace> \\<in> set evsCR;\n             Says B' A \\<lbrace>Nonce NB, Number SID, Number PB\\<rbrace> \\<in> set evsCR;\n             Notes A \\<lbrace>Number SID, Agent A, Agent B, Nonce M\\<rbrace> \\<in> set evsCR\\<rbrakk>\n          \\<Longrightarrow> Says A B (Crypt (clientK(NA,NB,M))\n                        (Hash\\<lbrace>Number SID, Nonce M,\n                               Nonce NA, Number PA, Agent A,\n                               Nonce NB, Number PB, Agent B\\<rbrace>))\n              # evsCR  \\<in>  tls\"\n\n | ServerResume:\n         \\<comment> \\<open>Resumption (7.3):  If B finds the \\<open>SESSION_ID\\<close> then he can \n             send a FINISHED message using the recovered MASTER SECRET\\<close>\n         \"\\<lbrakk>evsSR \\<in> tls;\n             Says A' B \\<lbrace>Agent A, Nonce NA, Number SID, Number PA\\<rbrace> \\<in> set evsSR;\n             Says B  A \\<lbrace>Nonce NB, Number SID, Number PB\\<rbrace> \\<in> set evsSR;\n             Notes B \\<lbrace>Number SID, Agent A, Agent B, Nonce M\\<rbrace> \\<in> set evsSR\\<rbrakk>\n          \\<Longrightarrow> Says B A (Crypt (serverK(NA,NB,M))\n                        (Hash\\<lbrace>Number SID, Nonce M,\n                               Nonce NA, Number PA, Agent A,\n                               Nonce NB, Number PB, Agent B\\<rbrace>)) # evsSR\n                \\<in>  tls\"\n\n | Oops:\n         \\<comment> \\<open>The most plausible compromise is of an old session key.  Losing\n           the MASTER SECRET or PREMASTER SECRET is more serious but\n           rather unlikely.  The assumption \\<^term>\\<open>A\\<noteq>Spy\\<close> is essential: \n           otherwise the Spy could learn session keys merely by \n           replaying messages!\\<close>\n         \"\\<lbrakk>evso \\<in> tls;  A \\<noteq> Spy;\n             Says A B (Crypt (sessionK((NA,NB,M),role)) X) \\<in> set evso\\<rbrakk>\n          \\<Longrightarrow> Says A Spy (Key (sessionK((NA,NB,M),role))) # evso  \\<in>  tls\"\n\n(*\nProtocol goals:\n* M, serverK(NA,NB,M) and clientK(NA,NB,M) will be known only to the two\n     parties (though A is not necessarily authenticated).\n\n* B upon receiving CertVerify knows that A is present (But this\n    message is optional!)\n\n* A upon receiving ServerFinished knows that B is present\n\n* Each party who has received a FINISHED message can trust that the other\n  party agrees on all message components, including PA and PB (thus foiling\n  rollback attacks).\n*)\n\ndeclare Says_imp_knows_Spy [THEN analz.Inj, dest]\ndeclare parts.Body  [dest]\ndeclare analz_into_parts [dest]\ndeclare Fake_parts_insert_in_Un  [dest]\n\n\ntext\\<open>Automatically unfold the definition of \"certificate\"\\<close>\ndeclare certificate_def [simp]\n\ntext\\<open>Injectiveness of key-generating functions\\<close>\ndeclare inj_PRF [THEN inj_eq, iff]\ndeclare inj_sessionK [THEN inj_eq, iff]\ndeclare isSym_sessionK [simp]\n\n\n(*** clientK and serverK make symmetric keys; no clashes with pubK or priK ***)\n\nlemma pubK_neq_sessionK [iff]: \"publicKey b A \\<noteq> sessionK arg\"\nby (simp add: symKeys_neq_imp_neq)\n\ndeclare pubK_neq_sessionK [THEN not_sym, iff]\n\nlemma priK_neq_sessionK [iff]: \"invKey (publicKey b A) \\<noteq> sessionK arg\"\nby (simp add: symKeys_neq_imp_neq)\n\ndeclare priK_neq_sessionK [THEN not_sym, iff]\n\nlemmas keys_distinct = pubK_neq_sessionK priK_neq_sessionK\n\n\nsubsection\\<open>Protocol Proofs\\<close>\n\ntext\\<open>Possibility properties state that some traces run the protocol to the\nend.  Four paths and 12 rules are considered.\\<close>\n\n\n(** These proofs assume that the Nonce_supply nonces\n        (which have the form  @ N. Nonce N \\<notin> used evs)\n    lie outside the range of PRF.  It seems reasonable, but as it is needed\n    only for the possibility theorems, it is not taken as an axiom.\n**)\n\n\ntext\\<open>Possibility property ending with ClientAccepts.\\<close>\nlemma \"\\<lbrakk>\\<forall>evs. (SOME N. Nonce N \\<notin> used evs) \\<notin> range PRF;  A \\<noteq> B\\<rbrakk>\n      \\<Longrightarrow> \\<exists>SID M. \\<exists>evs \\<in> tls.\n            Notes A \\<lbrace>Number SID, Agent A, Agent B, Nonce M\\<rbrace> \\<in> set evs\"\napply (intro exI bexI)\napply (rule_tac [2] tls.Nil\n                    [THEN tls.ClientHello, THEN tls.ServerHello,\n                     THEN tls.Certificate, THEN tls.ClientKeyExch,\n                     THEN tls.ClientFinished, THEN tls.ServerFinished,\n                     THEN tls.ClientAccepts], possibility, blast+)\ndone\n\n\ntext\\<open>And one for ServerAccepts.  Either FINISHED message may come first.\\<close>\nlemma \"\\<lbrakk>\\<forall>evs. (SOME N. Nonce N \\<notin> used evs) \\<notin> range PRF; A \\<noteq> B\\<rbrakk>\n      \\<Longrightarrow> \\<exists>SID NA PA NB PB M. \\<exists>evs \\<in> tls.\n           Notes B \\<lbrace>Number SID, Agent A, Agent B, Nonce M\\<rbrace> \\<in> set evs\"\napply (intro exI bexI)\napply (rule_tac [2] tls.Nil\n                    [THEN tls.ClientHello, THEN tls.ServerHello,\n                     THEN tls.Certificate, THEN tls.ClientKeyExch,\n                     THEN tls.ServerFinished, THEN tls.ClientFinished, \n                     THEN tls.ServerAccepts], possibility, blast+)\ndone\n\n\ntext\\<open>Another one, for CertVerify (which is optional)\\<close>\nlemma \"\\<lbrakk>\\<forall>evs. (SOME N. Nonce N \\<notin> used evs) \\<notin> range PRF;  A \\<noteq> B\\<rbrakk>\n       \\<Longrightarrow> \\<exists>NB PMS. \\<exists>evs \\<in> tls.\n              Says A B (Crypt (priK A) (Hash\\<lbrace>Nonce NB, Agent B, Nonce PMS\\<rbrace>)) \n                \\<in> set evs\"\napply (intro exI bexI)\napply (rule_tac [2] tls.Nil\n                    [THEN tls.ClientHello, THEN tls.ServerHello,\n                     THEN tls.Certificate, THEN tls.ClientKeyExch,\n                     THEN tls.CertVerify], possibility, blast+)\ndone\n\n\ntext\\<open>Another one, for session resumption (both ServerResume and ClientResume).\n  NO tls.Nil here: we refer to a previous session, not the empty trace.\\<close>\nlemma \"\\<lbrakk>evs0 \\<in> tls;\n          Notes A \\<lbrace>Number SID, Agent A, Agent B, Nonce M\\<rbrace> \\<in> set evs0;\n          Notes B \\<lbrace>Number SID, Agent A, Agent B, Nonce M\\<rbrace> \\<in> set evs0;\n          \\<forall>evs. (SOME N. Nonce N \\<notin> used evs) \\<notin> range PRF;\n          A \\<noteq> B\\<rbrakk>\n      \\<Longrightarrow> \\<exists>NA PA NB PB X. \\<exists>evs \\<in> tls.\n                X = Hash\\<lbrace>Number SID, Nonce M,\n                          Nonce NA, Number PA, Agent A,\n                          Nonce NB, Number PB, Agent B\\<rbrace>  \\<and>\n                Says A B (Crypt (clientK(NA,NB,M)) X) \\<in> set evs  \\<and>\n                Says B A (Crypt (serverK(NA,NB,M)) X) \\<in> set evs\"\napply (intro exI bexI)\napply (rule_tac [2] tls.ClientHello\n                    [THEN tls.ServerHello,\n                     THEN tls.ServerResume, THEN tls.ClientResume], possibility, blast+)\ndone\n\n\nsubsection\\<open>Inductive proofs about tls\\<close>\n\n\n(** Theorems of the form X \\<notin> parts (spies evs) imply that NOBODY\n    sends messages containing X! **)\n\ntext\\<open>Spy never sees a good agent's private key!\\<close>\nlemma Spy_see_priK [simp]:\n     \"evs \\<in> tls \\<Longrightarrow> (Key (privateKey b A) \\<in> parts (spies evs)) = (A \\<in> bad)\"\nby (erule tls.induct, force, simp_all, blast)\n\nlemma Spy_analz_priK [simp]:\n     \"evs \\<in> tls \\<Longrightarrow> (Key (privateKey b A) \\<in> analz (spies evs)) = (A \\<in> bad)\"\nby auto\n\nlemma Spy_see_priK_D [dest!]:\n    \"\\<lbrakk>Key (privateKey b A) \\<in> parts (knows Spy evs);  evs \\<in> tls\\<rbrakk> \\<Longrightarrow> A \\<in> bad\"\nby (blast dest: Spy_see_priK)\n\n\ntext\\<open>This lemma says that no false certificates exist.  One might extend the\n  model to include bogus certificates for the agents, but there seems\n  little point in doing so: the loss of their private keys is a worse\n  breach of security.\\<close>\nlemma certificate_valid:\n    \"\\<lbrakk>certificate B KB \\<in> parts (spies evs);  evs \\<in> tls\\<rbrakk> \\<Longrightarrow> KB = pubK B\"\napply (erule rev_mp)\napply (erule tls.induct, force, simp_all, blast) \ndone\n\nlemmas CX_KB_is_pubKB = Says_imp_spies [THEN parts.Inj, THEN certificate_valid]\n\n\nsubsubsection\\<open>Properties of items found in Notes\\<close>\n\nlemma Notes_Crypt_parts_spies:\n     \"\\<lbrakk>Notes A \\<lbrace>Agent B, X\\<rbrace> \\<in> set evs;  evs \\<in> tls\\<rbrakk>\n      \\<Longrightarrow> Crypt (pubK B) X \\<in> parts (spies evs)\"\napply (erule rev_mp)\napply (erule tls.induct, \n       frule_tac [7] CX_KB_is_pubKB, force, simp_all)\napply (blast intro: parts_insertI)\ndone\n\ntext\\<open>C may be either A or B\\<close>\nlemma Notes_master_imp_Crypt_PMS:\n     \"\\<lbrakk>Notes C \\<lbrace>s, Agent A, Agent B, Nonce(PRF(PMS,NA,NB))\\<rbrace> \\<in> set evs;\n         evs \\<in> tls\\<rbrakk>\n      \\<Longrightarrow> Crypt (pubK B) (Nonce PMS) \\<in> parts (spies evs)\"\napply (erule rev_mp)\napply (erule tls.induct, force, simp_all)\ntxt\\<open>Fake\\<close>\napply (blast intro: parts_insertI)\ntxt\\<open>Client, Server Accept\\<close>\napply (blast dest!: Notes_Crypt_parts_spies)+\ndone\n\ntext\\<open>Compared with the theorem above, both premise and conclusion are stronger\\<close>\nlemma Notes_master_imp_Notes_PMS:\n     \"\\<lbrakk>Notes A \\<lbrace>s, Agent A, Agent B, Nonce(PRF(PMS,NA,NB))\\<rbrace> \\<in> set evs;\n         evs \\<in> tls\\<rbrakk>\n      \\<Longrightarrow> Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs\"\napply (erule rev_mp)\napply (erule tls.induct, force, simp_all)\ntxt\\<open>ServerAccepts\\<close>\napply blast\ndone\n\n\nsubsubsection\\<open>Protocol goal: if B receives CertVerify, then A sent it\\<close>\n\ntext\\<open>B can check A's signature if he has received A's certificate.\\<close>\nlemma TrustCertVerify_lemma:\n     \"\\<lbrakk>X \\<in> parts (spies evs);\n         X = Crypt (priK A) (Hash\\<lbrace>nb, Agent B, pms\\<rbrace>);\n         evs \\<in> tls;  A \\<notin> bad\\<rbrakk>\n      \\<Longrightarrow> Says A B X \\<in> set evs\"\napply (erule rev_mp, erule ssubst)\napply (erule tls.induct, force, simp_all, blast)\ndone\n\ntext\\<open>Final version: B checks X using the distributed KA instead of priK A\\<close>\nlemma TrustCertVerify:\n     \"\\<lbrakk>X \\<in> parts (spies evs);\n         X = Crypt (invKey KA) (Hash\\<lbrace>nb, Agent B, pms\\<rbrace>);\n         certificate A KA \\<in> parts (spies evs);\n         evs \\<in> tls;  A \\<notin> bad\\<rbrakk>\n      \\<Longrightarrow> Says A B X \\<in> set evs\"\nby (blast dest!: certificate_valid intro!: TrustCertVerify_lemma)\n\n\ntext\\<open>If CertVerify is present then A has chosen PMS.\\<close>\nlemma UseCertVerify_lemma:\n     \"\\<lbrakk>Crypt (priK A) (Hash\\<lbrace>nb, Agent B, Nonce PMS\\<rbrace>) \\<in> parts (spies evs);\n         evs \\<in> tls;  A \\<notin> bad\\<rbrakk>\n      \\<Longrightarrow> Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs\"\napply (erule rev_mp)\napply (erule tls.induct, force, simp_all, blast)\ndone\n\ntext\\<open>Final version using the distributed KA instead of priK A\\<close>\nlemma UseCertVerify:\n     \"\\<lbrakk>Crypt (invKey KA) (Hash\\<lbrace>nb, Agent B, Nonce PMS\\<rbrace>)\n           \\<in> parts (spies evs);\n         certificate A KA \\<in> parts (spies evs);\n         evs \\<in> tls;  A \\<notin> bad\\<rbrakk>\n      \\<Longrightarrow> Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs\"\nby (blast dest!: certificate_valid intro!: UseCertVerify_lemma)\n\n\nlemma no_Notes_A_PRF [simp]:\n     \"evs \\<in> tls \\<Longrightarrow> Notes A \\<lbrace>Agent B, Nonce (PRF x)\\<rbrace> \\<notin> set evs\"\napply (erule tls.induct, force, simp_all)\ntxt\\<open>ClientKeyExch: PMS is assumed to differ from any PRF.\\<close>\napply blast\ndone\n\n\nlemma MS_imp_PMS [dest!]:\n     \"\\<lbrakk>Nonce (PRF (PMS,NA,NB)) \\<in> parts (spies evs);  evs \\<in> tls\\<rbrakk>\n      \\<Longrightarrow> Nonce PMS \\<in> parts (spies evs)\"\napply (erule rev_mp)\napply (erule tls.induct, force, simp_all)\ntxt\\<open>Fake\\<close>\napply (blast intro: parts_insertI)\ntxt\\<open>Easy, e.g. by freshness\\<close>\napply (blast dest: Notes_Crypt_parts_spies)+\ndone\n\n\n\n\nsubsubsection\\<open>Unicity results for PMS, the pre-master-secret\\<close>\n\ntext\\<open>PMS determines B.\\<close>\nlemma Crypt_unique_PMS:\n     \"\\<lbrakk>Crypt(pubK B)  (Nonce PMS) \\<in> parts (spies evs);\n         Crypt(pubK B') (Nonce PMS) \\<in> parts (spies evs);\n         Nonce PMS \\<notin> analz (spies evs);\n         evs \\<in> tls\\<rbrakk>\n      \\<Longrightarrow> B=B'\"\napply (erule rev_mp, erule rev_mp, erule rev_mp)\napply (erule tls.induct, analz_mono_contra, force, simp_all (no_asm_simp))\ntxt\\<open>Fake, ClientKeyExch\\<close>\napply blast+\ndone\n\n\n(** It is frustrating that we need two versions of the unicity results.\n    But Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> determines both A and B.  Sometimes\n    we have only the weaker assertion Crypt(pubK B) (Nonce PMS), which\n    determines B alone, and only if PMS is secret.\n**)\n\ntext\\<open>In A's internal Note, PMS determines A and B.\\<close>\nlemma Notes_unique_PMS:\n     \"\\<lbrakk>Notes A  \\<lbrace>Agent B,  Nonce PMS\\<rbrace> \\<in> set evs;\n         Notes A' \\<lbrace>Agent B', Nonce PMS\\<rbrace> \\<in> set evs;\n         evs \\<in> tls\\<rbrakk>\n      \\<Longrightarrow> A=A' \\<and> B=B'\"\napply (erule rev_mp, erule rev_mp)\napply (erule tls.induct, force, simp_all)\ntxt\\<open>ClientKeyExch\\<close>\napply (blast dest!: Notes_Crypt_parts_spies)\ndone\n\n\nsubsection\\<open>Secrecy Theorems\\<close>\n\ntext\\<open>Key compromise lemma needed to prove \\<^term>\\<open>analz_image_keys\\<close>.\n  No collection of keys can help the spy get new private keys.\\<close>\nlemma analz_image_priK [rule_format]:\n     \"evs \\<in> tls\n      \\<Longrightarrow> \\<forall>KK. (Key(priK B) \\<in> analz (Key`KK \\<union> (spies evs))) =\n          (priK B \\<in> KK | B \\<in> bad)\"\napply (erule tls.induct)\napply (simp_all (no_asm_simp)\n                del: image_insert\n                add: image_Un [THEN sym]\n                     insert_Key_image Un_assoc [THEN sym])\ntxt\\<open>Fake\\<close>\napply spy_analz\ndone\n\n\ntext\\<open>slightly speeds up the big simplification below\\<close>\nlemma range_sessionkeys_not_priK:\n     \"KK \\<subseteq> range sessionK \\<Longrightarrow> priK B \\<notin> KK\"\nby blast\n\n\ntext\\<open>Lemma for the trivial direction of the if-and-only-if\\<close>\nlemma analz_image_keys_lemma:\n     \"(X \\<in> analz (G \\<union> H)) \\<longrightarrow> (X \\<in> analz H)  \\<Longrightarrow>\n      (X \\<in> analz (G \\<union> H))  =  (X \\<in> analz H)\"\nby (blast intro: analz_mono [THEN subsetD])\n\n(** Strangely, the following version doesn't work:\n\\<forall>Z. (Nonce N \\<in> analz (Key`(sessionK`Z) \\<union> (spies evs))) =\n    (Nonce N \\<in> analz (spies evs))\"\n**)\n\nlemma analz_image_keys [rule_format]:\n     \"evs \\<in> tls \\<Longrightarrow>\n      \\<forall>KK. KK \\<subseteq> range sessionK \\<longrightarrow>\n              (Nonce N \\<in> analz (Key`KK \\<union> (spies evs))) =\n              (Nonce N \\<in> analz (spies evs))\"\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (safe del: iffI)\napply (safe del: impI iffI intro!: analz_image_keys_lemma)\napply (simp_all (no_asm_simp)               (*faster*)\n                del: image_insert imp_disjL (*reduces blow-up*)\n                add: image_Un [THEN sym]  Un_assoc [THEN sym]\n                     insert_Key_singleton\n                     range_sessionkeys_not_priK analz_image_priK)\napply (simp_all add: insert_absorb)\ntxt\\<open>Fake\\<close>\napply spy_analz\ndone\n\ntext\\<open>Knowing some session keys is no help in getting new nonces\\<close>\nlemma analz_insert_key [simp]:\n     \"evs \\<in> tls \\<Longrightarrow>\n      (Nonce N \\<in> analz (insert (Key (sessionK z)) (spies evs))) =\n      (Nonce N \\<in> analz (spies evs))\"\nby (simp del: image_insert\n         add: insert_Key_singleton analz_image_keys)\n\n\nsubsubsection\\<open>Protocol goal: serverK(Na,Nb,M) and clientK(Na,Nb,M) remain secure\\<close>\n\n(** Some lemmas about session keys, comprising clientK and serverK **)\n\n\ntext\\<open>Lemma: session keys are never used if PMS is fresh.\n  Nonces don't have to agree, allowing session resumption.\n  Converse doesn't hold; revealing PMS doesn't force the keys to be sent.\n  THEY ARE NOT SUITABLE AS SAFE ELIM RULES.\\<close>\nlemma PMS_lemma:\n     \"\\<lbrakk>Nonce PMS \\<notin> parts (spies evs);\n         K = sessionK((Na, Nb, PRF(PMS,NA,NB)), role);\n         evs \\<in> tls\\<rbrakk>\n   \\<Longrightarrow> Key K \\<notin> parts (spies evs) \\<and> (\\<forall>Y. Crypt K Y \\<notin> parts (spies evs))\"\napply (erule rev_mp, erule ssubst)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB) \napply (force, simp_all (no_asm_simp))\ntxt\\<open>Fake\\<close>\napply (blast intro: parts_insertI)\ntxt\\<open>SpyKeys\\<close>\napply blast\ntxt\\<open>Many others\\<close>\napply (force dest!: Notes_Crypt_parts_spies Notes_master_imp_Crypt_PMS)+\ndone\n\nlemma PMS_sessionK_not_spied:\n     \"\\<lbrakk>Key (sessionK((Na, Nb, PRF(PMS,NA,NB)), role)) \\<in> parts (spies evs);\n         evs \\<in> tls\\<rbrakk>\n      \\<Longrightarrow> Nonce PMS \\<in> parts (spies evs)\"\nby (blast dest: PMS_lemma)\n\nlemma PMS_Crypt_sessionK_not_spied:\n     \"\\<lbrakk>Crypt (sessionK((Na, Nb, PRF(PMS,NA,NB)), role)) Y\n           \\<in> parts (spies evs);  evs \\<in> tls\\<rbrakk>\n      \\<Longrightarrow> Nonce PMS \\<in> parts (spies evs)\"\nby (blast dest: PMS_lemma)\n\ntext\\<open>Write keys are never sent if M (MASTER SECRET) is secure.\n  Converse fails; betraying M doesn't force the keys to be sent!\n  The strong Oops condition can be weakened later by unicity reasoning,\n  with some effort.\n  NO LONGER USED: see \\<open>clientK_not_spied\\<close> and \\<open>serverK_not_spied\\<close>\\<close>\nlemma sessionK_not_spied:\n     \"\\<lbrakk>\\<forall>A. Says A Spy (Key (sessionK((NA,NB,M),role))) \\<notin> set evs;\n         Nonce M \\<notin> analz (spies evs);  evs \\<in> tls\\<rbrakk>\n      \\<Longrightarrow> Key (sessionK((NA,NB,M),role)) \\<notin> parts (spies evs)\"\napply (erule rev_mp, erule rev_mp)\napply (erule tls.induct, analz_mono_contra)\napply (force, simp_all (no_asm_simp))\ntxt\\<open>Fake, SpyKeys\\<close>\napply blast+\ndone\n\n\ntext\\<open>If A sends ClientKeyExch to an honest B, then the PMS will stay secret.\\<close>\nlemma Spy_not_see_PMS:\n     \"\\<lbrakk>Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs;\n         evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad\\<rbrakk>\n      \\<Longrightarrow> Nonce PMS \\<notin> analz (spies evs)\"\napply (erule rev_mp, erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp))\ntxt\\<open>Fake\\<close>\napply spy_analz\ntxt\\<open>SpyKeys\\<close>\napply force\napply (simp_all add: insert_absorb) \ntxt\\<open>ClientHello, ServerHello, ClientKeyExch: mostly freshness reasoning\\<close>\napply (blast dest: Notes_Crypt_parts_spies)\napply (blast dest: Notes_Crypt_parts_spies)\napply (blast dest: Notes_Crypt_parts_spies)\ntxt\\<open>ClientAccepts and ServerAccepts: because \\<^term>\\<open>PMS \\<notin> range PRF\\<close>\\<close>\napply force+\ndone\n\n\ntext\\<open>If A sends ClientKeyExch to an honest B, then the MASTER SECRET\n  will stay secret.\\<close>\nlemma Spy_not_see_MS:\n     \"\\<lbrakk>Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs;\n         evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad\\<rbrakk>\n      \\<Longrightarrow> Nonce (PRF(PMS,NA,NB)) \\<notin> analz (spies evs)\"\napply (erule rev_mp, erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp))\ntxt\\<open>Fake\\<close>\napply spy_analz\ntxt\\<open>SpyKeys: by secrecy of the PMS, Spy cannot make the MS\\<close>\napply (blast dest!: Spy_not_see_PMS)\napply (simp_all add: insert_absorb)\ntxt\\<open>ClientAccepts and ServerAccepts: because PMS was already visible;\n  others, freshness etc.\\<close>\napply (blast dest: Notes_Crypt_parts_spies Spy_not_see_PMS \n                   Notes_imp_knows_Spy [THEN analz.Inj])+\ndone\n\n\n\nsubsubsection\\<open>Weakening the Oops conditions for leakage of clientK\\<close>\n\ntext\\<open>If A created PMS then nobody else (except the Spy in replays)\n  would send a message using a clientK generated from that PMS.\\<close>\nlemma Says_clientK_unique:\n     \"\\<lbrakk>Says A' B' (Crypt (clientK(Na,Nb,PRF(PMS,NA,NB))) Y) \\<in> set evs;\n         Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs;\n         evs \\<in> tls;  A' \\<noteq> Spy\\<rbrakk>\n      \\<Longrightarrow> A = A'\"\napply (erule rev_mp, erule rev_mp)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all)\ntxt\\<open>ClientKeyExch\\<close>\napply (blast dest!: PMS_Crypt_sessionK_not_spied)\ntxt\\<open>ClientFinished, ClientResume: by unicity of PMS\\<close>\napply (blast dest!: Notes_master_imp_Notes_PMS \n             intro: Notes_unique_PMS [THEN conjunct1])+\ndone\n\n\ntext\\<open>If A created PMS and has not leaked her clientK to the Spy,\n  then it is completely secure: not even in parts!\\<close>\nlemma clientK_not_spied:\n     \"\\<lbrakk>Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs;\n         Says A Spy (Key (clientK(Na,Nb,PRF(PMS,NA,NB)))) \\<notin> set evs;\n         A \\<notin> bad;  B \\<notin> bad;\n         evs \\<in> tls\\<rbrakk>\n      \\<Longrightarrow> Key (clientK(Na,Nb,PRF(PMS,NA,NB))) \\<notin> parts (spies evs)\"\napply (erule rev_mp, erule rev_mp)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp))\ntxt\\<open>ClientKeyExch\\<close>\napply blast \ntxt\\<open>SpyKeys\\<close>\napply (blast dest!: Spy_not_see_MS)\ntxt\\<open>ClientKeyExch\\<close>\napply (blast dest!: PMS_sessionK_not_spied)\ntxt\\<open>Oops\\<close>\napply (blast intro: Says_clientK_unique)\ndone\n\n\nsubsubsection\\<open>Weakening the Oops conditions for leakage of serverK\\<close>\n\ntext\\<open>If A created PMS for B, then nobody other than B or the Spy would\n  send a message using a serverK generated from that PMS.\\<close>\nlemma Says_serverK_unique:\n     \"\\<lbrakk>Says B' A' (Crypt (serverK(Na,Nb,PRF(PMS,NA,NB))) Y) \\<in> set evs;\n         Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs;\n         evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad;  B' \\<noteq> Spy\\<rbrakk>\n      \\<Longrightarrow> B = B'\"\napply (erule rev_mp, erule rev_mp)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all)\ntxt\\<open>ClientKeyExch\\<close>\napply (blast dest!: PMS_Crypt_sessionK_not_spied)\ntxt\\<open>ServerResume, ServerFinished: by unicity of PMS\\<close>\napply (blast dest!: Notes_master_imp_Crypt_PMS \n             dest: Spy_not_see_PMS Notes_Crypt_parts_spies Crypt_unique_PMS)+\ndone\n\n\ntext\\<open>If A created PMS for B, and B has not leaked his serverK to the Spy,\n  then it is completely secure: not even in parts!\\<close>\nlemma serverK_not_spied:\n     \"\\<lbrakk>Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs;\n         Says B Spy (Key(serverK(Na,Nb,PRF(PMS,NA,NB)))) \\<notin> set evs;\n         A \\<notin> bad;  B \\<notin> bad;  evs \\<in> tls\\<rbrakk>\n      \\<Longrightarrow> Key (serverK(Na,Nb,PRF(PMS,NA,NB))) \\<notin> parts (spies evs)\"\napply (erule rev_mp, erule rev_mp)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp))\ntxt\\<open>Fake\\<close>\napply blast \ntxt\\<open>SpyKeys\\<close>\napply (blast dest!: Spy_not_see_MS)\ntxt\\<open>ClientKeyExch\\<close>\napply (blast dest!: PMS_sessionK_not_spied)\ntxt\\<open>Oops\\<close>\napply (blast intro: Says_serverK_unique)\ndone\n\n\nsubsubsection\\<open>Protocol goals: if A receives ServerFinished, then B is present\n     and has used the quoted values PA, PB, etc.  Note that it is up to A\n     to compare PA with what she originally sent.\\<close>\n\ntext\\<open>The mention of her name (A) in X assures A that B knows who she is.\\<close>\nlemma TrustServerFinished [rule_format]:\n     \"\\<lbrakk>X = Crypt (serverK(Na,Nb,M))\n               (Hash\\<lbrace>Number SID, Nonce M,\n                      Nonce Na, Number PA, Agent A,\n                      Nonce Nb, Number PB, Agent B\\<rbrace>);\n         M = PRF(PMS,NA,NB);\n         evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad\\<rbrakk>\n      \\<Longrightarrow> Says B Spy (Key(serverK(Na,Nb,M))) \\<notin> set evs \\<longrightarrow>\n          Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs \\<longrightarrow>\n          X \\<in> parts (spies evs) \\<longrightarrow> Says B A X \\<in> set evs\"\napply (erule ssubst)+\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp))\ntxt\\<open>Fake: the Spy doesn't have the critical session key!\\<close>\napply (blast dest: serverK_not_spied)\ntxt\\<open>ClientKeyExch\\<close>\napply (blast dest!: PMS_Crypt_sessionK_not_spied)\ndone\n\ntext\\<open>This version refers not to ServerFinished but to any message from B.\n  We don't assume B has received CertVerify, and an intruder could\n  have changed A's identity in all other messages, so we can't be sure\n  that B sends his message to A.  If CLIENT KEY EXCHANGE were augmented\n  to bind A's identity with PMS, then we could replace A' by A below.\\<close>\nlemma TrustServerMsg [rule_format]:\n     \"\\<lbrakk>M = PRF(PMS,NA,NB);  evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad\\<rbrakk>\n      \\<Longrightarrow> Says B Spy (Key(serverK(Na,Nb,M))) \\<notin> set evs \\<longrightarrow>\n          Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs \\<longrightarrow>\n          Crypt (serverK(Na,Nb,M)) Y \\<in> parts (spies evs)  \\<longrightarrow>\n          (\\<exists>A'. Says B A' (Crypt (serverK(Na,Nb,M)) Y) \\<in> set evs)\"\napply (erule ssubst)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp) add: ex_disj_distrib)\ntxt\\<open>Fake: the Spy doesn't have the critical session key!\\<close>\napply (blast dest: serverK_not_spied)\ntxt\\<open>ClientKeyExch\\<close>\napply (clarify, blast dest!: PMS_Crypt_sessionK_not_spied)\ntxt\\<open>ServerResume, ServerFinished: by unicity of PMS\\<close>\napply (blast dest!: Notes_master_imp_Crypt_PMS \n             dest: Spy_not_see_PMS Notes_Crypt_parts_spies Crypt_unique_PMS)+\ndone\n\n\nsubsubsection\\<open>Protocol goal: if B receives any message encrypted with clientK\n      then A has sent it\\<close>\n\ntext\\<open>ASSUMING that A chose PMS.  Authentication is\n     assumed here; B cannot verify it.  But if the message is\n     ClientFinished, then B can then check the quoted values PA, PB, etc.\\<close>\n\nlemma TrustClientMsg [rule_format]:\n     \"\\<lbrakk>M = PRF(PMS,NA,NB);  evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad\\<rbrakk>\n      \\<Longrightarrow> Says A Spy (Key(clientK(Na,Nb,M))) \\<notin> set evs \\<longrightarrow>\n          Notes A \\<lbrace>Agent B, Nonce PMS\\<rbrace> \\<in> set evs \\<longrightarrow>\n          Crypt (clientK(Na,Nb,M)) Y \\<in> parts (spies evs) \\<longrightarrow>\n          Says A B (Crypt (clientK(Na,Nb,M)) Y) \\<in> set evs\"\napply (erule ssubst)\napply (erule tls.induct, frule_tac [7] CX_KB_is_pubKB)\napply (force, simp_all (no_asm_simp))\ntxt\\<open>Fake: the Spy doesn't have the critical session key!\\<close>\napply (blast dest: clientK_not_spied)\ntxt\\<open>ClientKeyExch\\<close>\napply (blast dest!: PMS_Crypt_sessionK_not_spied)\ntxt\\<open>ClientFinished, ClientResume: by unicity of PMS\\<close>\napply (blast dest!: Notes_master_imp_Notes_PMS dest: Notes_unique_PMS)+\ndone\n\n\nsubsubsection\\<open>Protocol goal: if B receives ClientFinished, and if B is able to\n     check a CertVerify from A, then A has used the quoted\n     values PA, PB, etc.  Even this one requires A to be uncompromised.\\<close>\nlemma AuthClientFinished:\n     \"\\<lbrakk>M = PRF(PMS,NA,NB);\n         Says A Spy (Key(clientK(Na,Nb,M))) \\<notin> set evs;\n         Says A' B (Crypt (clientK(Na,Nb,M)) Y) \\<in> set evs;\n         certificate A KA \\<in> parts (spies evs);\n         Says A'' B (Crypt (invKey KA) (Hash\\<lbrace>nb, Agent B, Nonce PMS\\<rbrace>))\n           \\<in> set evs;\n         evs \\<in> tls;  A \\<notin> bad;  B \\<notin> bad\\<rbrakk>\n      \\<Longrightarrow> Says A B (Crypt (clientK(Na,Nb,M)) Y) \\<in> set evs\"\nby (blast intro!: TrustClientMsg UseCertVerify)\n\n(*22/9/97: loads in 622s, which is 10 minutes 22 seconds*)\n(*24/9/97: loads in 672s, which is 11 minutes 12 seconds [stronger theorems]*)\n(*29/9/97: loads in 481s, after removing Certificate from ClientKeyExch*)\n(*30/9/97: loads in 476s, after removing unused theorems*)\n(*30/9/97: loads in 448s, after fixing ServerResume*)\n\n(*08/9/97: loads in 189s (pike), after much reorganization,\n           back to 621s on albatross?*)\n\n(*10/2/99: loads in 139s (pike)\n           down to 433s on albatross*)\n\n(*5/5/01: conversion to Isar script\n          loads in 137s (perch)\n          the last ML version loaded in 122s on perch, a 600MHz machine:\n                twice as fast as pike.  No idea why it's so much slower!\n          The Isar script is slower still, perhaps because simp_all simplifies\n          the assumptions be default.\n*)\n\n(*20/11/11: loads in 5.8s elapses time, 9.3s CPU time on dual-core laptop*)\n\nend\n", "meta": {"author": "seL4", "repo": "isabelle", "sha": "e1ab32a3bb41728cd19541063283e37919978a4c", "save_path": "github-repos/isabelle/seL4-isabelle", "path": "github-repos/isabelle/seL4-isabelle/isabelle-e1ab32a3bb41728cd19541063283e37919978a4c/src/HOL/Auth/TLS.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO\n\n", "lm_q1_score": 0.6959583250334526, "lm_q2_score": 0.35936414516010196, "lm_q1q2_score": 0.25010246854270307}}
{"text": "theory flash80Rev imports flashPub\nbegin\nsection{*Main defintions*}\nlemma NI_FAckVsInv80:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv80 ) (NI_FAck ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_InvVsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Inv  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1VsInv80:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_InvAck_1  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_1_HomeVsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_InvAck_1_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_InvAck_2VsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_InvAck_2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_GetXVsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_GetX_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_Nak1VsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_GetX_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_Nak2VsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_GetX_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_Nak3VsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_GetX_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_GetX_PutX1VsInv80:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_GetX_PutX1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX2VsInv80:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_GetX_PutX2 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX3VsInv80:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_GetX_PutX3 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX4VsInv80:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_GetX_PutX4 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX5VsInv80:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_GetX_PutX5 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX6VsInv80:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_GetX_PutX6 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX7VsInv80:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_GetX_PutX7 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX8VsInv80:  \n  (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_GetX_PutX8 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX8_homeVsInv80:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_GetX_PutX8_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX9VsInv80:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_GetX_PutX9 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX10VsInv80:  \n  (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_GetX_PutX10 N  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1  a2  a3 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX10_homeVsInv80:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_GetX_PutX10_home N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_GetX_PutX11VsInv80:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_GetX_PutX11 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P1 s\"\n         \n        apply(cut_tac  a1 , auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma NI_Local_Get_GetVsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_Get_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Nak1VsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Nak2VsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_Get_Nak2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Nak3VsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_Get_Nak3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Put1VsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_Get_Put1 N  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Put2VsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_Get_Put2  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Local_Get_Put3VsInv80:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_Get_Put3  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''WbMsg_Cmd'') )  ( Const WB_Wb ))    ( eqn ( IVar ( Global ''Dir_local'') )  ( Const true ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma NI_Local_PutVsInv80:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P3 s\"\n\n         \n        apply(    simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''WbMsg_Cmd'') )  ( Const WB_Wb ))    ( eqn ( IVar ( Para ''UniMsg_Cmd'' Home) )  ( Const UNI_Put ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma NI_Local_PutXAcksDoneVsInv80:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv80 ) (NI_Local_PutXAcksDone ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_NakVsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Nak  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Nak_ClearVsInv80:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv80 ) (NI_Nak_Clear ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_Nak_HomeVsInv80:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv80 ) (NI_Nak_Home ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_Remote_GetX_NakVsInv80:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Remote_GetX_Nak  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_Nak_HomeVsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Remote_GetX_Nak_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_PutXVsInv80:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Remote_GetX_PutX  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_GetX_PutX_HomeVsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Remote_GetX_PutX_Home  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Nak1VsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Remote_Get_Nak1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Nak2VsInv80:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Remote_Get_Nak2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Put1VsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Remote_Get_Put1  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_Get_Put2VsInv80:  \n    (*Rule2VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" and  a2:\"iRule2 \\<le> N\" and  a3:\"iRule1~=iRule2  \" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Remote_Get_Put2  iRule1  iRule2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1 a2 a3,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_PutVsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Remote_Put  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_Remote_PutXVsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceVsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ReplaceHomeVsInv80:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv80 ) (NI_ReplaceHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_ReplaceHomeShrVldVsInv80:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv80 ) (NI_ReplaceHomeShrVld ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma NI_ReplaceShrVldVsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (NI_ReplaceShrVld  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma NI_ShWbVsInv80:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv80 ) (NI_ShWb N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P3 s\"\n\n         \n        apply(    simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''WbMsg_Cmd'') )  ( Const WB_Wb ))    ( eqn ( IVar ( Global ''ShWbMsg_Cmd'') )  ( Const SHWB_ShWb ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma NI_WbVsInv80:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv80 ) (NI_Wb ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_GetX1VsInv80:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv80 ) (PI_Local_GetX_GetX1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_GetX_GetX2VsInv80:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv80 ) (PI_Local_GetX_GetX2 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_GetX_PutX1VsInv80:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv80 ) (PI_Local_GetX_PutX1 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX2VsInv80:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv80 ) (PI_Local_GetX_PutX2 N ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX3VsInv80:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv80 ) (PI_Local_GetX_PutX3 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_GetX_PutX4VsInv80:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv80 ) (PI_Local_GetX_PutX4 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P1 s\"\n         \n        apply( auto)\n\n         \n        done\n\n        then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n       by blast\n\n  \n\n\n qed\nlemma PI_Local_Get_GetVsInv80:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv80 ) (PI_Local_Get_Get ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_Get_PutVsInv80:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv80 ) (PI_Local_Get_Put ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Local_PutXVsInv80:  \n  (*Rule0VsPInv0*)\n  shows  \"invHoldForRule' s (inv80 ) (PI_Local_PutX ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof -\n\n  \n      have \"?P3 s\"\n\n         \n        apply(    simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Global ''WbMsg_Cmd'') )  ( Const WB_Wb ))    ( eqn ( IVar ( Para ''CacheState'' Home) )  ( Const CACHE_E ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma PI_Local_ReplaceVsInv80:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv80 ) (PI_Local_Replace ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  lemma PI_Remote_GetVsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (PI_Remote_Get  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_GetXVsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (PI_Remote_GetX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma PI_Remote_PutXVsInv80:  \n  (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (PI_Remote_PutX  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n  \n      have \"?P3 s\"\n\n         \n        apply(   cut_tac  a1 , simp)\n\n        apply(rule_tac x=\" (neg ( andForm ( eqn ( IVar ( Para ''CacheState'' iRule1) )  ( Const CACHE_E ))    ( eqn ( IVar ( Global ''Dir_Dirty'') )  ( Const false ))  ) ) \" in exI,auto)\n \n        \n        done\n\n       \n       then  show \"?P1 s\\<or> ?P2 s\\<or> ?P3 s\"\n\n        by blast\n\n  \n\n\n qed\nlemma PI_Remote_ReplaceVsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (PI_Remote_Replace  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma StoreVsInv80:  \n    (*Rule1VsPInv0*)\n  assumes   a1:\"iRule1 \\<le> N\" \n\n  shows  \"invHoldForRule' s (inv80 ) (Store  iRule1 ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n  proof - \n \n\n     have \"?P2 s\" \n\n     by (cut_tac a1,auto  )\n   then show \"?P1 s\\<or>?P2 s\\<or>?P3 s\"\n      by auto\n qed\n  lemma StoreHomeVsInv80:  \n    (*Rule0VsPInv0*)\n  \n  shows  \"invHoldForRule' s (inv80 ) (StoreHome ) (invariants   N)\" (is \" ?P1 s\\<or>?P2 s\\<or>?P3 s\")  \n\n   \n      by( auto)\n \n  end\n", "meta": {"author": "lyj238Gmail", "repo": "IsabelleCourse", "sha": "cd49d944d3504328ad8210fbd987abebdf192ed8", "save_path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse", "path": "github-repos/isabelle/lyj238Gmail-IsabelleCourse/IsabelleCourse-cd49d944d3504328ad8210fbd987abebdf192ed8/flash/flash80Rev.thy", "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. NO", "lm_q1_score": 0.5813030906443133, "lm_q2_score": 0.43014734858584286, "lm_q1q2_score": 0.2500459831654072}}
